Commit 6fc376f0 authored by Dave Airlie's avatar Dave Airlie

Merge tag 'mediatek-drm-next-5.6' of https://github.com/ckhu-mediatek/linux.git-tags into drm-next

Mediatek DRM Next for Linux 5.6

This fix non-smooth cursor problem, add cmdq support, add ctm property
support and some refinement.
Signed-off-by: default avatarDave Airlie <airlied@redhat.com>

From: CK Hu <ck.hu@mediatek.com>
Link: https://patchwork.freedesktop.org/patch/msgid/1578972526.14594.8.camel@mtksdaap41
parents fd7226fb d04a07a8
...@@ -20,7 +20,7 @@ obj-$(CONFIG_DRM_MEDIATEK) += mediatek-drm.o ...@@ -20,7 +20,7 @@ obj-$(CONFIG_DRM_MEDIATEK) += mediatek-drm.o
mediatek-drm-hdmi-objs := mtk_cec.o \ mediatek-drm-hdmi-objs := mtk_cec.o \
mtk_hdmi.o \ mtk_hdmi.o \
mtk_hdmi_ddc.o \ mtk_hdmi_ddc.o \
mtk_mt2701_hdmi_phy.o \ mtk_mt2701_hdmi_phy.o \
mtk_mt8173_hdmi_phy.o \ mtk_mt8173_hdmi_phy.o \
mtk_hdmi_phy.o mtk_hdmi_phy.o
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include <linux/of_device.h> #include <linux/of_device.h>
#include <linux/of_irq.h> #include <linux/of_irq.h>
#include <linux/platform_device.h> #include <linux/platform_device.h>
#include <linux/soc/mediatek/mtk-cmdq.h>
#include "mtk_drm_crtc.h" #include "mtk_drm_crtc.h"
#include "mtk_drm_ddp_comp.h" #include "mtk_drm_ddp_comp.h"
...@@ -45,12 +46,12 @@ static inline struct mtk_disp_color *comp_to_color(struct mtk_ddp_comp *comp) ...@@ -45,12 +46,12 @@ static inline struct mtk_disp_color *comp_to_color(struct mtk_ddp_comp *comp)
static void mtk_color_config(struct mtk_ddp_comp *comp, unsigned int w, static void mtk_color_config(struct mtk_ddp_comp *comp, unsigned int w,
unsigned int h, unsigned int vrefresh, unsigned int h, unsigned int vrefresh,
unsigned int bpc) unsigned int bpc, struct cmdq_pkt *cmdq_pkt)
{ {
struct mtk_disp_color *color = comp_to_color(comp); struct mtk_disp_color *color = comp_to_color(comp);
writel(w, comp->regs + DISP_COLOR_WIDTH(color)); mtk_ddp_write(cmdq_pkt, w, comp, DISP_COLOR_WIDTH(color));
writel(h, comp->regs + DISP_COLOR_HEIGHT(color)); mtk_ddp_write(cmdq_pkt, h, comp, DISP_COLOR_HEIGHT(color));
} }
static void mtk_color_start(struct mtk_ddp_comp *comp) static void mtk_color_start(struct mtk_ddp_comp *comp)
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include <linux/of_device.h> #include <linux/of_device.h>
#include <linux/of_irq.h> #include <linux/of_irq.h>
#include <linux/platform_device.h> #include <linux/platform_device.h>
#include <linux/soc/mediatek/mtk-cmdq.h>
#include "mtk_drm_crtc.h" #include "mtk_drm_crtc.h"
#include "mtk_drm_ddp_comp.h" #include "mtk_drm_ddp_comp.h"
...@@ -124,14 +125,15 @@ static void mtk_ovl_stop(struct mtk_ddp_comp *comp) ...@@ -124,14 +125,15 @@ static void mtk_ovl_stop(struct mtk_ddp_comp *comp)
static void mtk_ovl_config(struct mtk_ddp_comp *comp, unsigned int w, static void mtk_ovl_config(struct mtk_ddp_comp *comp, unsigned int w,
unsigned int h, unsigned int vrefresh, unsigned int h, unsigned int vrefresh,
unsigned int bpc) unsigned int bpc, struct cmdq_pkt *cmdq_pkt)
{ {
if (w != 0 && h != 0) if (w != 0 && h != 0)
writel_relaxed(h << 16 | w, comp->regs + DISP_REG_OVL_ROI_SIZE); mtk_ddp_write_relaxed(cmdq_pkt, h << 16 | w, comp,
writel_relaxed(0x0, comp->regs + DISP_REG_OVL_ROI_BGCLR); DISP_REG_OVL_ROI_SIZE);
mtk_ddp_write_relaxed(cmdq_pkt, 0x0, comp, DISP_REG_OVL_ROI_BGCLR);
writel(0x1, comp->regs + DISP_REG_OVL_RST); mtk_ddp_write(cmdq_pkt, 0x1, comp, DISP_REG_OVL_RST);
writel(0x0, comp->regs + DISP_REG_OVL_RST); mtk_ddp_write(cmdq_pkt, 0x0, comp, DISP_REG_OVL_RST);
} }
static unsigned int mtk_ovl_layer_nr(struct mtk_ddp_comp *comp) static unsigned int mtk_ovl_layer_nr(struct mtk_ddp_comp *comp)
...@@ -175,16 +177,16 @@ static int mtk_ovl_layer_check(struct mtk_ddp_comp *comp, unsigned int idx, ...@@ -175,16 +177,16 @@ static int mtk_ovl_layer_check(struct mtk_ddp_comp *comp, unsigned int idx,
return 0; return 0;
} }
static void mtk_ovl_layer_on(struct mtk_ddp_comp *comp, unsigned int idx) static void mtk_ovl_layer_on(struct mtk_ddp_comp *comp, unsigned int idx,
struct cmdq_pkt *cmdq_pkt)
{ {
unsigned int reg;
unsigned int gmc_thrshd_l; unsigned int gmc_thrshd_l;
unsigned int gmc_thrshd_h; unsigned int gmc_thrshd_h;
unsigned int gmc_value; unsigned int gmc_value;
struct mtk_disp_ovl *ovl = comp_to_ovl(comp); struct mtk_disp_ovl *ovl = comp_to_ovl(comp);
writel(0x1, comp->regs + DISP_REG_OVL_RDMA_CTRL(idx)); mtk_ddp_write(cmdq_pkt, 0x1, comp,
DISP_REG_OVL_RDMA_CTRL(idx));
gmc_thrshd_l = GMC_THRESHOLD_LOW >> gmc_thrshd_l = GMC_THRESHOLD_LOW >>
(GMC_THRESHOLD_BITS - ovl->data->gmc_bits); (GMC_THRESHOLD_BITS - ovl->data->gmc_bits);
gmc_thrshd_h = GMC_THRESHOLD_HIGH >> gmc_thrshd_h = GMC_THRESHOLD_HIGH >>
...@@ -194,22 +196,19 @@ static void mtk_ovl_layer_on(struct mtk_ddp_comp *comp, unsigned int idx) ...@@ -194,22 +196,19 @@ static void mtk_ovl_layer_on(struct mtk_ddp_comp *comp, unsigned int idx)
else else
gmc_value = gmc_thrshd_l | gmc_thrshd_l << 8 | gmc_value = gmc_thrshd_l | gmc_thrshd_l << 8 |
gmc_thrshd_h << 16 | gmc_thrshd_h << 24; gmc_thrshd_h << 16 | gmc_thrshd_h << 24;
writel(gmc_value, comp->regs + DISP_REG_OVL_RDMA_GMC(idx)); mtk_ddp_write(cmdq_pkt, gmc_value,
comp, DISP_REG_OVL_RDMA_GMC(idx));
reg = readl(comp->regs + DISP_REG_OVL_SRC_CON); mtk_ddp_write_mask(cmdq_pkt, BIT(idx), comp,
reg = reg | BIT(idx); DISP_REG_OVL_SRC_CON, BIT(idx));
writel(reg, comp->regs + DISP_REG_OVL_SRC_CON);
} }
static void mtk_ovl_layer_off(struct mtk_ddp_comp *comp, unsigned int idx) static void mtk_ovl_layer_off(struct mtk_ddp_comp *comp, unsigned int idx,
struct cmdq_pkt *cmdq_pkt)
{ {
unsigned int reg; mtk_ddp_write_mask(cmdq_pkt, 0, comp,
DISP_REG_OVL_SRC_CON, BIT(idx));
reg = readl(comp->regs + DISP_REG_OVL_SRC_CON); mtk_ddp_write(cmdq_pkt, 0, comp,
reg = reg & ~BIT(idx); DISP_REG_OVL_RDMA_CTRL(idx));
writel(reg, comp->regs + DISP_REG_OVL_SRC_CON);
writel(0x0, comp->regs + DISP_REG_OVL_RDMA_CTRL(idx));
} }
static unsigned int ovl_fmt_convert(struct mtk_disp_ovl *ovl, unsigned int fmt) static unsigned int ovl_fmt_convert(struct mtk_disp_ovl *ovl, unsigned int fmt)
...@@ -249,7 +248,8 @@ static unsigned int ovl_fmt_convert(struct mtk_disp_ovl *ovl, unsigned int fmt) ...@@ -249,7 +248,8 @@ static unsigned int ovl_fmt_convert(struct mtk_disp_ovl *ovl, unsigned int fmt)
} }
static void mtk_ovl_layer_config(struct mtk_ddp_comp *comp, unsigned int idx, static void mtk_ovl_layer_config(struct mtk_ddp_comp *comp, unsigned int idx,
struct mtk_plane_state *state) struct mtk_plane_state *state,
struct cmdq_pkt *cmdq_pkt)
{ {
struct mtk_disp_ovl *ovl = comp_to_ovl(comp); struct mtk_disp_ovl *ovl = comp_to_ovl(comp);
struct mtk_plane_pending_state *pending = &state->pending; struct mtk_plane_pending_state *pending = &state->pending;
...@@ -260,11 +260,13 @@ static void mtk_ovl_layer_config(struct mtk_ddp_comp *comp, unsigned int idx, ...@@ -260,11 +260,13 @@ static void mtk_ovl_layer_config(struct mtk_ddp_comp *comp, unsigned int idx,
unsigned int src_size = (pending->height << 16) | pending->width; unsigned int src_size = (pending->height << 16) | pending->width;
unsigned int con; unsigned int con;
if (!pending->enable) if (!pending->enable) {
mtk_ovl_layer_off(comp, idx); mtk_ovl_layer_off(comp, idx, cmdq_pkt);
return;
}
con = ovl_fmt_convert(ovl, fmt); con = ovl_fmt_convert(ovl, fmt);
if (idx != 0) if (state->base.fb->format->has_alpha)
con |= OVL_CON_AEN | OVL_CON_ALPHA; con |= OVL_CON_AEN | OVL_CON_ALPHA;
if (pending->rotation & DRM_MODE_REFLECT_Y) { if (pending->rotation & DRM_MODE_REFLECT_Y) {
...@@ -277,14 +279,18 @@ static void mtk_ovl_layer_config(struct mtk_ddp_comp *comp, unsigned int idx, ...@@ -277,14 +279,18 @@ static void mtk_ovl_layer_config(struct mtk_ddp_comp *comp, unsigned int idx,
addr += pending->pitch - 1; addr += pending->pitch - 1;
} }
writel_relaxed(con, comp->regs + DISP_REG_OVL_CON(idx)); mtk_ddp_write_relaxed(cmdq_pkt, con, comp,
writel_relaxed(pitch, comp->regs + DISP_REG_OVL_PITCH(idx)); DISP_REG_OVL_CON(idx));
writel_relaxed(src_size, comp->regs + DISP_REG_OVL_SRC_SIZE(idx)); mtk_ddp_write_relaxed(cmdq_pkt, pitch, comp,
writel_relaxed(offset, comp->regs + DISP_REG_OVL_OFFSET(idx)); DISP_REG_OVL_PITCH(idx));
writel_relaxed(addr, comp->regs + DISP_REG_OVL_ADDR(ovl, idx)); mtk_ddp_write_relaxed(cmdq_pkt, src_size, comp,
DISP_REG_OVL_SRC_SIZE(idx));
if (pending->enable) mtk_ddp_write_relaxed(cmdq_pkt, offset, comp,
mtk_ovl_layer_on(comp, idx); DISP_REG_OVL_OFFSET(idx));
mtk_ddp_write_relaxed(cmdq_pkt, addr, comp,
DISP_REG_OVL_ADDR(ovl, idx));
mtk_ovl_layer_on(comp, idx, cmdq_pkt);
} }
static void mtk_ovl_bgclr_in_on(struct mtk_ddp_comp *comp) static void mtk_ovl_bgclr_in_on(struct mtk_ddp_comp *comp)
...@@ -313,8 +319,6 @@ static const struct mtk_ddp_comp_funcs mtk_disp_ovl_funcs = { ...@@ -313,8 +319,6 @@ static const struct mtk_ddp_comp_funcs mtk_disp_ovl_funcs = {
.disable_vblank = mtk_ovl_disable_vblank, .disable_vblank = mtk_ovl_disable_vblank,
.supported_rotations = mtk_ovl_supported_rotations, .supported_rotations = mtk_ovl_supported_rotations,
.layer_nr = mtk_ovl_layer_nr, .layer_nr = mtk_ovl_layer_nr,
.layer_on = mtk_ovl_layer_on,
.layer_off = mtk_ovl_layer_off,
.layer_check = mtk_ovl_layer_check, .layer_check = mtk_ovl_layer_check,
.layer_config = mtk_ovl_layer_config, .layer_config = mtk_ovl_layer_config,
.bgclr_in_on = mtk_ovl_bgclr_in_on, .bgclr_in_on = mtk_ovl_bgclr_in_on,
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include <linux/of_device.h> #include <linux/of_device.h>
#include <linux/of_irq.h> #include <linux/of_irq.h>
#include <linux/platform_device.h> #include <linux/platform_device.h>
#include <linux/soc/mediatek/mtk-cmdq.h>
#include "mtk_drm_crtc.h" #include "mtk_drm_crtc.h"
#include "mtk_drm_ddp_comp.h" #include "mtk_drm_ddp_comp.h"
...@@ -125,14 +126,16 @@ static void mtk_rdma_stop(struct mtk_ddp_comp *comp) ...@@ -125,14 +126,16 @@ static void mtk_rdma_stop(struct mtk_ddp_comp *comp)
static void mtk_rdma_config(struct mtk_ddp_comp *comp, unsigned int width, static void mtk_rdma_config(struct mtk_ddp_comp *comp, unsigned int width,
unsigned int height, unsigned int vrefresh, unsigned int height, unsigned int vrefresh,
unsigned int bpc) unsigned int bpc, struct cmdq_pkt *cmdq_pkt)
{ {
unsigned int threshold; unsigned int threshold;
unsigned int reg; unsigned int reg;
struct mtk_disp_rdma *rdma = comp_to_rdma(comp); struct mtk_disp_rdma *rdma = comp_to_rdma(comp);
rdma_update_bits(comp, DISP_REG_RDMA_SIZE_CON_0, 0xfff, width); mtk_ddp_write_mask(cmdq_pkt, width, comp,
rdma_update_bits(comp, DISP_REG_RDMA_SIZE_CON_1, 0xfffff, height); DISP_REG_RDMA_SIZE_CON_0, 0xfff);
mtk_ddp_write_mask(cmdq_pkt, height, comp,
DISP_REG_RDMA_SIZE_CON_1, 0xfffff);
/* /*
* Enable FIFO underflow since DSI and DPI can't be blocked. * Enable FIFO underflow since DSI and DPI can't be blocked.
...@@ -144,7 +147,7 @@ static void mtk_rdma_config(struct mtk_ddp_comp *comp, unsigned int width, ...@@ -144,7 +147,7 @@ static void mtk_rdma_config(struct mtk_ddp_comp *comp, unsigned int width,
reg = RDMA_FIFO_UNDERFLOW_EN | reg = RDMA_FIFO_UNDERFLOW_EN |
RDMA_FIFO_PSEUDO_SIZE(RDMA_FIFO_SIZE(rdma)) | RDMA_FIFO_PSEUDO_SIZE(RDMA_FIFO_SIZE(rdma)) |
RDMA_OUTPUT_VALID_FIFO_THRESHOLD(threshold); RDMA_OUTPUT_VALID_FIFO_THRESHOLD(threshold);
writel(reg, comp->regs + DISP_REG_RDMA_FIFO_CON); mtk_ddp_write(cmdq_pkt, reg, comp, DISP_REG_RDMA_FIFO_CON);
} }
static unsigned int rdma_fmt_convert(struct mtk_disp_rdma *rdma, static unsigned int rdma_fmt_convert(struct mtk_disp_rdma *rdma,
...@@ -190,7 +193,8 @@ static unsigned int mtk_rdma_layer_nr(struct mtk_ddp_comp *comp) ...@@ -190,7 +193,8 @@ static unsigned int mtk_rdma_layer_nr(struct mtk_ddp_comp *comp)
} }
static void mtk_rdma_layer_config(struct mtk_ddp_comp *comp, unsigned int idx, static void mtk_rdma_layer_config(struct mtk_ddp_comp *comp, unsigned int idx,
struct mtk_plane_state *state) struct mtk_plane_state *state,
struct cmdq_pkt *cmdq_pkt)
{ {
struct mtk_disp_rdma *rdma = comp_to_rdma(comp); struct mtk_disp_rdma *rdma = comp_to_rdma(comp);
struct mtk_plane_pending_state *pending = &state->pending; struct mtk_plane_pending_state *pending = &state->pending;
...@@ -200,24 +204,27 @@ static void mtk_rdma_layer_config(struct mtk_ddp_comp *comp, unsigned int idx, ...@@ -200,24 +204,27 @@ static void mtk_rdma_layer_config(struct mtk_ddp_comp *comp, unsigned int idx,
unsigned int con; unsigned int con;
con = rdma_fmt_convert(rdma, fmt); con = rdma_fmt_convert(rdma, fmt);
writel_relaxed(con, comp->regs + DISP_RDMA_MEM_CON); mtk_ddp_write_relaxed(cmdq_pkt, con, comp, DISP_RDMA_MEM_CON);
if (fmt == DRM_FORMAT_UYVY || fmt == DRM_FORMAT_YUYV) { if (fmt == DRM_FORMAT_UYVY || fmt == DRM_FORMAT_YUYV) {
rdma_update_bits(comp, DISP_REG_RDMA_SIZE_CON_0, mtk_ddp_write_mask(cmdq_pkt, RDMA_MATRIX_ENABLE, comp,
RDMA_MATRIX_ENABLE, RDMA_MATRIX_ENABLE); DISP_REG_RDMA_SIZE_CON_0,
rdma_update_bits(comp, DISP_REG_RDMA_SIZE_CON_0, RDMA_MATRIX_ENABLE);
RDMA_MATRIX_INT_MTX_SEL, mtk_ddp_write_mask(cmdq_pkt, RDMA_MATRIX_INT_MTX_BT601_to_RGB,
RDMA_MATRIX_INT_MTX_BT601_to_RGB); comp, DISP_REG_RDMA_SIZE_CON_0,
RDMA_MATRIX_INT_MTX_SEL);
} else { } else {
rdma_update_bits(comp, DISP_REG_RDMA_SIZE_CON_0, mtk_ddp_write_mask(cmdq_pkt, 0, comp,
RDMA_MATRIX_ENABLE, 0); DISP_REG_RDMA_SIZE_CON_0,
RDMA_MATRIX_ENABLE);
} }
mtk_ddp_write_relaxed(cmdq_pkt, addr, comp, DISP_RDMA_MEM_START_ADDR);
mtk_ddp_write_relaxed(cmdq_pkt, pitch, comp, DISP_RDMA_MEM_SRC_PITCH);
mtk_ddp_write(cmdq_pkt, RDMA_MEM_GMC, comp,
DISP_RDMA_MEM_GMC_SETTING_0);
mtk_ddp_write_mask(cmdq_pkt, RDMA_MODE_MEMORY, comp,
DISP_REG_RDMA_GLOBAL_CON, RDMA_MODE_MEMORY);
writel_relaxed(addr, comp->regs + DISP_RDMA_MEM_START_ADDR);
writel_relaxed(pitch, comp->regs + DISP_RDMA_MEM_SRC_PITCH);
writel(RDMA_MEM_GMC, comp->regs + DISP_RDMA_MEM_GMC_SETTING_0);
rdma_update_bits(comp, DISP_REG_RDMA_GLOBAL_CON,
RDMA_MODE_MEMORY, RDMA_MODE_MEMORY);
} }
static const struct mtk_ddp_comp_funcs mtk_disp_rdma_funcs = { static const struct mtk_ddp_comp_funcs mtk_disp_rdma_funcs = {
......
This diff is collapsed.
...@@ -21,5 +21,7 @@ int mtk_drm_crtc_create(struct drm_device *drm_dev, ...@@ -21,5 +21,7 @@ int mtk_drm_crtc_create(struct drm_device *drm_dev,
unsigned int path_len); unsigned int path_len);
int mtk_drm_crtc_plane_check(struct drm_crtc *crtc, struct drm_plane *plane, int mtk_drm_crtc_plane_check(struct drm_crtc *crtc, struct drm_plane *plane,
struct mtk_plane_state *state); struct mtk_plane_state *state);
void mtk_drm_crtc_async_update(struct drm_crtc *crtc, struct drm_plane *plane,
struct drm_plane_state *plane_state);
#endif /* MTK_DRM_CRTC_H */ #endif /* MTK_DRM_CRTC_H */
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
#include <linux/of_irq.h> #include <linux/of_irq.h>
#include <linux/of_platform.h> #include <linux/of_platform.h>
#include <linux/platform_device.h> #include <linux/platform_device.h>
#include <linux/soc/mediatek/mtk-cmdq.h>
#include "mtk_drm_drv.h" #include "mtk_drm_drv.h"
#include "mtk_drm_plane.h" #include "mtk_drm_plane.h"
#include "mtk_drm_ddp_comp.h" #include "mtk_drm_ddp_comp.h"
...@@ -37,7 +37,15 @@ ...@@ -37,7 +37,15 @@
#define CCORR_EN BIT(0) #define CCORR_EN BIT(0)
#define DISP_CCORR_CFG 0x0020 #define DISP_CCORR_CFG 0x0020
#define CCORR_RELAY_MODE BIT(0) #define CCORR_RELAY_MODE BIT(0)
#define CCORR_ENGINE_EN BIT(1)
#define CCORR_GAMMA_OFF BIT(2)
#define CCORR_WGAMUT_SRC_CLIP BIT(3)
#define DISP_CCORR_SIZE 0x0030 #define DISP_CCORR_SIZE 0x0030
#define DISP_CCORR_COEF_0 0x0080
#define DISP_CCORR_COEF_1 0x0084
#define DISP_CCORR_COEF_2 0x0088
#define DISP_CCORR_COEF_3 0x008C
#define DISP_CCORR_COEF_4 0x0090
#define DISP_DITHER_EN 0x0000 #define DISP_DITHER_EN 0x0000
#define DITHER_EN BIT(0) #define DITHER_EN BIT(0)
...@@ -76,36 +84,84 @@ ...@@ -76,36 +84,84 @@
#define DITHER_ADD_LSHIFT_G(x) (((x) & 0x7) << 4) #define DITHER_ADD_LSHIFT_G(x) (((x) & 0x7) << 4)
#define DITHER_ADD_RSHIFT_G(x) (((x) & 0x7) << 0) #define DITHER_ADD_RSHIFT_G(x) (((x) & 0x7) << 0)
void mtk_ddp_write(struct cmdq_pkt *cmdq_pkt, unsigned int value,
struct mtk_ddp_comp *comp, unsigned int offset)
{
#if IS_REACHABLE(CONFIG_MTK_CMDQ)
if (cmdq_pkt)
cmdq_pkt_write(cmdq_pkt, comp->subsys,
comp->regs_pa + offset, value);
else
#endif
writel(value, comp->regs + offset);
}
void mtk_ddp_write_relaxed(struct cmdq_pkt *cmdq_pkt, unsigned int value,
struct mtk_ddp_comp *comp,
unsigned int offset)
{
#if IS_REACHABLE(CONFIG_MTK_CMDQ)
if (cmdq_pkt)
cmdq_pkt_write(cmdq_pkt, comp->subsys,
comp->regs_pa + offset, value);
else
#endif
writel_relaxed(value, comp->regs + offset);
}
void mtk_ddp_write_mask(struct cmdq_pkt *cmdq_pkt,
unsigned int value,
struct mtk_ddp_comp *comp,
unsigned int offset,
unsigned int mask)
{
#if IS_REACHABLE(CONFIG_MTK_CMDQ)
if (cmdq_pkt) {
cmdq_pkt_write_mask(cmdq_pkt, comp->subsys,
comp->regs_pa + offset, value, mask);
} else {
#endif
u32 tmp = readl(comp->regs + offset);
tmp = (tmp & ~mask) | (value & mask);
writel(tmp, comp->regs + offset);
#if IS_REACHABLE(CONFIG_MTK_CMDQ)
}
#endif
}
void mtk_dither_set(struct mtk_ddp_comp *comp, unsigned int bpc, void mtk_dither_set(struct mtk_ddp_comp *comp, unsigned int bpc,
unsigned int CFG) unsigned int CFG, struct cmdq_pkt *cmdq_pkt)
{ {
/* If bpc equal to 0, the dithering function didn't be enabled */ /* If bpc equal to 0, the dithering function didn't be enabled */
if (bpc == 0) if (bpc == 0)
return; return;
if (bpc >= MTK_MIN_BPC) { if (bpc >= MTK_MIN_BPC) {
writel(0, comp->regs + DISP_DITHER_5); mtk_ddp_write(cmdq_pkt, 0, comp, DISP_DITHER_5);
writel(0, comp->regs + DISP_DITHER_7); mtk_ddp_write(cmdq_pkt, 0, comp, DISP_DITHER_7);
writel(DITHER_LSB_ERR_SHIFT_R(MTK_MAX_BPC - bpc) | mtk_ddp_write(cmdq_pkt,
DITHER_ADD_LSHIFT_R(MTK_MAX_BPC - bpc) | DITHER_LSB_ERR_SHIFT_R(MTK_MAX_BPC - bpc) |
DITHER_NEW_BIT_MODE, DITHER_ADD_LSHIFT_R(MTK_MAX_BPC - bpc) |
comp->regs + DISP_DITHER_15); DITHER_NEW_BIT_MODE,
writel(DITHER_LSB_ERR_SHIFT_B(MTK_MAX_BPC - bpc) | comp, DISP_DITHER_15);
DITHER_ADD_LSHIFT_B(MTK_MAX_BPC - bpc) | mtk_ddp_write(cmdq_pkt,
DITHER_LSB_ERR_SHIFT_G(MTK_MAX_BPC - bpc) | DITHER_LSB_ERR_SHIFT_B(MTK_MAX_BPC - bpc) |
DITHER_ADD_LSHIFT_G(MTK_MAX_BPC - bpc), DITHER_ADD_LSHIFT_B(MTK_MAX_BPC - bpc) |
comp->regs + DISP_DITHER_16); DITHER_LSB_ERR_SHIFT_G(MTK_MAX_BPC - bpc) |
writel(DISP_DITHERING, comp->regs + CFG); DITHER_ADD_LSHIFT_G(MTK_MAX_BPC - bpc),
comp, DISP_DITHER_16);
mtk_ddp_write(cmdq_pkt, DISP_DITHERING, comp, CFG);
} }
} }
static void mtk_od_config(struct mtk_ddp_comp *comp, unsigned int w, static void mtk_od_config(struct mtk_ddp_comp *comp, unsigned int w,
unsigned int h, unsigned int vrefresh, unsigned int h, unsigned int vrefresh,
unsigned int bpc) unsigned int bpc, struct cmdq_pkt *cmdq_pkt)
{ {
writel(w << 16 | h, comp->regs + DISP_OD_SIZE); mtk_ddp_write(cmdq_pkt, w << 16 | h, comp, DISP_OD_SIZE);
writel(OD_RELAYMODE, comp->regs + DISP_OD_CFG); mtk_ddp_write(cmdq_pkt, OD_RELAYMODE, comp, DISP_OD_CFG);
mtk_dither_set(comp, bpc, DISP_OD_CFG); mtk_dither_set(comp, bpc, DISP_OD_CFG, cmdq_pkt);
} }
static void mtk_od_start(struct mtk_ddp_comp *comp) static void mtk_od_start(struct mtk_ddp_comp *comp)
...@@ -120,9 +176,9 @@ static void mtk_ufoe_start(struct mtk_ddp_comp *comp) ...@@ -120,9 +176,9 @@ static void mtk_ufoe_start(struct mtk_ddp_comp *comp)
static void mtk_aal_config(struct mtk_ddp_comp *comp, unsigned int w, static void mtk_aal_config(struct mtk_ddp_comp *comp, unsigned int w,
unsigned int h, unsigned int vrefresh, unsigned int h, unsigned int vrefresh,
unsigned int bpc) unsigned int bpc, struct cmdq_pkt *cmdq_pkt)
{ {
writel(h << 16 | w, comp->regs + DISP_AAL_SIZE); mtk_ddp_write(cmdq_pkt, h << 16 | w, comp, DISP_AAL_SIZE);
} }
static void mtk_aal_start(struct mtk_ddp_comp *comp) static void mtk_aal_start(struct mtk_ddp_comp *comp)
...@@ -137,10 +193,10 @@ static void mtk_aal_stop(struct mtk_ddp_comp *comp) ...@@ -137,10 +193,10 @@ static void mtk_aal_stop(struct mtk_ddp_comp *comp)
static void mtk_ccorr_config(struct mtk_ddp_comp *comp, unsigned int w, static void mtk_ccorr_config(struct mtk_ddp_comp *comp, unsigned int w,
unsigned int h, unsigned int vrefresh, unsigned int h, unsigned int vrefresh,
unsigned int bpc) unsigned int bpc, struct cmdq_pkt *cmdq_pkt)
{ {
writel(h << 16 | w, comp->regs + DISP_CCORR_SIZE); mtk_ddp_write(cmdq_pkt, h << 16 | w, comp, DISP_CCORR_SIZE);
writel(CCORR_RELAY_MODE, comp->regs + DISP_CCORR_CFG); mtk_ddp_write(cmdq_pkt, CCORR_ENGINE_EN, comp, DISP_CCORR_CFG);
} }
static void mtk_ccorr_start(struct mtk_ddp_comp *comp) static void mtk_ccorr_start(struct mtk_ddp_comp *comp)
...@@ -153,12 +209,63 @@ static void mtk_ccorr_stop(struct mtk_ddp_comp *comp) ...@@ -153,12 +209,63 @@ static void mtk_ccorr_stop(struct mtk_ddp_comp *comp)
writel_relaxed(0x0, comp->regs + DISP_CCORR_EN); writel_relaxed(0x0, comp->regs + DISP_CCORR_EN);
} }
/* Converts a DRM S31.32 value to the HW S1.10 format. */
static u16 mtk_ctm_s31_32_to_s1_10(u64 in)
{
u16 r;
/* Sign bit. */
r = in & BIT_ULL(63) ? BIT(11) : 0;
if ((in & GENMASK_ULL(62, 33)) > 0) {
/* identity value 0x100000000 -> 0x400, */
/* if bigger this, set it to max 0x7ff. */
r |= GENMASK(10, 0);
} else {
/* take the 11 most important bits. */
r |= (in >> 22) & GENMASK(10, 0);
}
return r;
}
static void mtk_ccorr_ctm_set(struct mtk_ddp_comp *comp,
struct drm_crtc_state *state)
{
struct drm_property_blob *blob = state->ctm;
struct drm_color_ctm *ctm;
const u64 *input;
uint16_t coeffs[9] = { 0 };
int i;
struct cmdq_pkt *cmdq_pkt = NULL;
if (!blob)
return;
ctm = (struct drm_color_ctm *)blob->data;
input = ctm->matrix;
for (i = 0; i < ARRAY_SIZE(coeffs); i++)
coeffs[i] = mtk_ctm_s31_32_to_s1_10(input[i]);
mtk_ddp_write(cmdq_pkt, coeffs[0] << 16 | coeffs[1],
comp, DISP_CCORR_COEF_0);
mtk_ddp_write(cmdq_pkt, coeffs[2] << 16 | coeffs[3],
comp, DISP_CCORR_COEF_1);
mtk_ddp_write(cmdq_pkt, coeffs[4] << 16 | coeffs[5],
comp, DISP_CCORR_COEF_2);
mtk_ddp_write(cmdq_pkt, coeffs[6] << 16 | coeffs[7],
comp, DISP_CCORR_COEF_3);
mtk_ddp_write(cmdq_pkt, coeffs[8] << 16,
comp, DISP_CCORR_COEF_4);
}
static void mtk_dither_config(struct mtk_ddp_comp *comp, unsigned int w, static void mtk_dither_config(struct mtk_ddp_comp *comp, unsigned int w,
unsigned int h, unsigned int vrefresh, unsigned int h, unsigned int vrefresh,
unsigned int bpc) unsigned int bpc, struct cmdq_pkt *cmdq_pkt)
{ {
writel(h << 16 | w, comp->regs + DISP_DITHER_SIZE); mtk_ddp_write(cmdq_pkt, h << 16 | w, comp, DISP_DITHER_SIZE);
writel(DITHER_RELAY_MODE, comp->regs + DISP_DITHER_CFG); mtk_ddp_write(cmdq_pkt, DITHER_RELAY_MODE, comp, DISP_DITHER_CFG);
} }
static void mtk_dither_start(struct mtk_ddp_comp *comp) static void mtk_dither_start(struct mtk_ddp_comp *comp)
...@@ -173,10 +280,10 @@ static void mtk_dither_stop(struct mtk_ddp_comp *comp) ...@@ -173,10 +280,10 @@ static void mtk_dither_stop(struct mtk_ddp_comp *comp)
static void mtk_gamma_config(struct mtk_ddp_comp *comp, unsigned int w, static void mtk_gamma_config(struct mtk_ddp_comp *comp, unsigned int w,
unsigned int h, unsigned int vrefresh, unsigned int h, unsigned int vrefresh,
unsigned int bpc) unsigned int bpc, struct cmdq_pkt *cmdq_pkt)
{ {
writel(h << 16 | w, comp->regs + DISP_GAMMA_SIZE); mtk_ddp_write(cmdq_pkt, h << 16 | w, comp, DISP_GAMMA_SIZE);
mtk_dither_set(comp, bpc, DISP_GAMMA_CFG); mtk_dither_set(comp, bpc, DISP_GAMMA_CFG, cmdq_pkt);
} }
static void mtk_gamma_start(struct mtk_ddp_comp *comp) static void mtk_gamma_start(struct mtk_ddp_comp *comp)
...@@ -223,6 +330,7 @@ static const struct mtk_ddp_comp_funcs ddp_ccorr = { ...@@ -223,6 +330,7 @@ static const struct mtk_ddp_comp_funcs ddp_ccorr = {
.config = mtk_ccorr_config, .config = mtk_ccorr_config,
.start = mtk_ccorr_start, .start = mtk_ccorr_start,
.stop = mtk_ccorr_stop, .stop = mtk_ccorr_stop,
.ctm_set = mtk_ccorr_ctm_set,
}; };
static const struct mtk_ddp_comp_funcs ddp_dither = { static const struct mtk_ddp_comp_funcs ddp_dither = {
...@@ -326,6 +434,11 @@ int mtk_ddp_comp_init(struct device *dev, struct device_node *node, ...@@ -326,6 +434,11 @@ int mtk_ddp_comp_init(struct device *dev, struct device_node *node,
enum mtk_ddp_comp_type type; enum mtk_ddp_comp_type type;
struct device_node *larb_node; struct device_node *larb_node;
struct platform_device *larb_pdev; struct platform_device *larb_pdev;
#if IS_REACHABLE(CONFIG_MTK_CMDQ)
struct resource res;
struct cmdq_client_reg cmdq_reg;
int ret;
#endif
if (comp_id < 0 || comp_id >= DDP_COMPONENT_ID_MAX) if (comp_id < 0 || comp_id >= DDP_COMPONENT_ID_MAX)
return -EINVAL; return -EINVAL;
...@@ -379,6 +492,19 @@ int mtk_ddp_comp_init(struct device *dev, struct device_node *node, ...@@ -379,6 +492,19 @@ int mtk_ddp_comp_init(struct device *dev, struct device_node *node,
comp->larb_dev = &larb_pdev->dev; comp->larb_dev = &larb_pdev->dev;
#if IS_REACHABLE(CONFIG_MTK_CMDQ)
if (of_address_to_resource(node, 0, &res) != 0) {
dev_err(dev, "Missing reg in %s node\n", node->full_name);
return -EINVAL;
}
comp->regs_pa = res.start;
ret = cmdq_dev_get_client_reg(dev, &cmdq_reg, 0);
if (ret)
dev_dbg(dev, "get mediatek,gce-client-reg fail!\n");
else
comp->subsys = cmdq_reg.subsys;
#endif
return 0; return 0;
} }
......
...@@ -69,27 +69,29 @@ enum mtk_ddp_comp_id { ...@@ -69,27 +69,29 @@ enum mtk_ddp_comp_id {
}; };
struct mtk_ddp_comp; struct mtk_ddp_comp;
struct cmdq_pkt;
struct mtk_ddp_comp_funcs { struct mtk_ddp_comp_funcs {
void (*config)(struct mtk_ddp_comp *comp, unsigned int w, void (*config)(struct mtk_ddp_comp *comp, unsigned int w,
unsigned int h, unsigned int vrefresh, unsigned int bpc); unsigned int h, unsigned int vrefresh,
unsigned int bpc, struct cmdq_pkt *cmdq_pkt);
void (*start)(struct mtk_ddp_comp *comp); void (*start)(struct mtk_ddp_comp *comp);
void (*stop)(struct mtk_ddp_comp *comp); void (*stop)(struct mtk_ddp_comp *comp);
void (*enable_vblank)(struct mtk_ddp_comp *comp, struct drm_crtc *crtc); void (*enable_vblank)(struct mtk_ddp_comp *comp, struct drm_crtc *crtc);
void (*disable_vblank)(struct mtk_ddp_comp *comp); void (*disable_vblank)(struct mtk_ddp_comp *comp);
unsigned int (*supported_rotations)(struct mtk_ddp_comp *comp); unsigned int (*supported_rotations)(struct mtk_ddp_comp *comp);
unsigned int (*layer_nr)(struct mtk_ddp_comp *comp); unsigned int (*layer_nr)(struct mtk_ddp_comp *comp);
void (*layer_on)(struct mtk_ddp_comp *comp, unsigned int idx);
void (*layer_off)(struct mtk_ddp_comp *comp, unsigned int idx);
int (*layer_check)(struct mtk_ddp_comp *comp, int (*layer_check)(struct mtk_ddp_comp *comp,
unsigned int idx, unsigned int idx,
struct mtk_plane_state *state); struct mtk_plane_state *state);
void (*layer_config)(struct mtk_ddp_comp *comp, unsigned int idx, void (*layer_config)(struct mtk_ddp_comp *comp, unsigned int idx,
struct mtk_plane_state *state); struct mtk_plane_state *state,
struct cmdq_pkt *cmdq_pkt);
void (*gamma_set)(struct mtk_ddp_comp *comp, void (*gamma_set)(struct mtk_ddp_comp *comp,
struct drm_crtc_state *state); struct drm_crtc_state *state);
void (*bgclr_in_on)(struct mtk_ddp_comp *comp); void (*bgclr_in_on)(struct mtk_ddp_comp *comp);
void (*bgclr_in_off)(struct mtk_ddp_comp *comp); void (*bgclr_in_off)(struct mtk_ddp_comp *comp);
void (*ctm_set)(struct mtk_ddp_comp *comp,
struct drm_crtc_state *state);
}; };
struct mtk_ddp_comp { struct mtk_ddp_comp {
...@@ -99,14 +101,17 @@ struct mtk_ddp_comp { ...@@ -99,14 +101,17 @@ struct mtk_ddp_comp {
struct device *larb_dev; struct device *larb_dev;
enum mtk_ddp_comp_id id; enum mtk_ddp_comp_id id;
const struct mtk_ddp_comp_funcs *funcs; const struct mtk_ddp_comp_funcs *funcs;
resource_size_t regs_pa;
u8 subsys;
}; };
static inline void mtk_ddp_comp_config(struct mtk_ddp_comp *comp, static inline void mtk_ddp_comp_config(struct mtk_ddp_comp *comp,
unsigned int w, unsigned int h, unsigned int w, unsigned int h,
unsigned int vrefresh, unsigned int bpc) unsigned int vrefresh, unsigned int bpc,
struct cmdq_pkt *cmdq_pkt)
{ {
if (comp->funcs && comp->funcs->config) if (comp->funcs && comp->funcs->config)
comp->funcs->config(comp, w, h, vrefresh, bpc); comp->funcs->config(comp, w, h, vrefresh, bpc, cmdq_pkt);
} }
static inline void mtk_ddp_comp_start(struct mtk_ddp_comp *comp) static inline void mtk_ddp_comp_start(struct mtk_ddp_comp *comp)
...@@ -151,20 +156,6 @@ static inline unsigned int mtk_ddp_comp_layer_nr(struct mtk_ddp_comp *comp) ...@@ -151,20 +156,6 @@ static inline unsigned int mtk_ddp_comp_layer_nr(struct mtk_ddp_comp *comp)
return 0; return 0;
} }
static inline void mtk_ddp_comp_layer_on(struct mtk_ddp_comp *comp,
unsigned int idx)
{
if (comp->funcs && comp->funcs->layer_on)
comp->funcs->layer_on(comp, idx);
}
static inline void mtk_ddp_comp_layer_off(struct mtk_ddp_comp *comp,
unsigned int idx)
{
if (comp->funcs && comp->funcs->layer_off)
comp->funcs->layer_off(comp, idx);
}
static inline int mtk_ddp_comp_layer_check(struct mtk_ddp_comp *comp, static inline int mtk_ddp_comp_layer_check(struct mtk_ddp_comp *comp,
unsigned int idx, unsigned int idx,
struct mtk_plane_state *state) struct mtk_plane_state *state)
...@@ -176,10 +167,11 @@ static inline int mtk_ddp_comp_layer_check(struct mtk_ddp_comp *comp, ...@@ -176,10 +167,11 @@ static inline int mtk_ddp_comp_layer_check(struct mtk_ddp_comp *comp,
static inline void mtk_ddp_comp_layer_config(struct mtk_ddp_comp *comp, static inline void mtk_ddp_comp_layer_config(struct mtk_ddp_comp *comp,
unsigned int idx, unsigned int idx,
struct mtk_plane_state *state) struct mtk_plane_state *state,
struct cmdq_pkt *cmdq_pkt)
{ {
if (comp->funcs && comp->funcs->layer_config) if (comp->funcs && comp->funcs->layer_config)
comp->funcs->layer_config(comp, idx, state); comp->funcs->layer_config(comp, idx, state, cmdq_pkt);
} }
static inline void mtk_ddp_gamma_set(struct mtk_ddp_comp *comp, static inline void mtk_ddp_gamma_set(struct mtk_ddp_comp *comp,
...@@ -201,6 +193,13 @@ static inline void mtk_ddp_comp_bgclr_in_off(struct mtk_ddp_comp *comp) ...@@ -201,6 +193,13 @@ static inline void mtk_ddp_comp_bgclr_in_off(struct mtk_ddp_comp *comp)
comp->funcs->bgclr_in_off(comp); comp->funcs->bgclr_in_off(comp);
} }
static inline void mtk_ddp_ctm_set(struct mtk_ddp_comp *comp,
struct drm_crtc_state *state)
{
if (comp->funcs && comp->funcs->ctm_set)
comp->funcs->ctm_set(comp, state);
}
int mtk_ddp_comp_get_id(struct device_node *node, int mtk_ddp_comp_get_id(struct device_node *node,
enum mtk_ddp_comp_type comp_type); enum mtk_ddp_comp_type comp_type);
int mtk_ddp_comp_init(struct device *dev, struct device_node *comp_node, int mtk_ddp_comp_init(struct device *dev, struct device_node *comp_node,
...@@ -209,6 +208,13 @@ int mtk_ddp_comp_init(struct device *dev, struct device_node *comp_node, ...@@ -209,6 +208,13 @@ int mtk_ddp_comp_init(struct device *dev, struct device_node *comp_node,
int mtk_ddp_comp_register(struct drm_device *drm, struct mtk_ddp_comp *comp); int mtk_ddp_comp_register(struct drm_device *drm, struct mtk_ddp_comp *comp);
void mtk_ddp_comp_unregister(struct drm_device *drm, struct mtk_ddp_comp *comp); void mtk_ddp_comp_unregister(struct drm_device *drm, struct mtk_ddp_comp *comp);
void mtk_dither_set(struct mtk_ddp_comp *comp, unsigned int bpc, void mtk_dither_set(struct mtk_ddp_comp *comp, unsigned int bpc,
unsigned int CFG); unsigned int CFG, struct cmdq_pkt *cmdq_pkt);
enum mtk_ddp_comp_type mtk_ddp_comp_get_type(enum mtk_ddp_comp_id comp_id);
void mtk_ddp_write(struct cmdq_pkt *cmdq_pkt, unsigned int value,
struct mtk_ddp_comp *comp, unsigned int offset);
void mtk_ddp_write_relaxed(struct cmdq_pkt *cmdq_pkt, unsigned int value,
struct mtk_ddp_comp *comp, unsigned int offset);
void mtk_ddp_write_mask(struct cmdq_pkt *cmdq_pkt, unsigned int value,
struct mtk_ddp_comp *comp, unsigned int offset,
unsigned int mask);
#endif /* MTK_DRM_DDP_COMP_H */ #endif /* MTK_DRM_DDP_COMP_H */
...@@ -37,84 +37,9 @@ ...@@ -37,84 +37,9 @@
#define DRIVER_MAJOR 1 #define DRIVER_MAJOR 1
#define DRIVER_MINOR 0 #define DRIVER_MINOR 0
static void mtk_atomic_schedule(struct mtk_drm_private *private, static const struct drm_mode_config_helper_funcs mtk_drm_mode_config_helpers = {
struct drm_atomic_state *state) .atomic_commit_tail = drm_atomic_helper_commit_tail_rpm,
{ };
private->commit.state = state;
schedule_work(&private->commit.work);
}
static void mtk_atomic_complete(struct mtk_drm_private *private,
struct drm_atomic_state *state)
{
struct drm_device *drm = private->drm;
drm_atomic_helper_wait_for_fences(drm, state, false);
/*
* Mediatek drm supports runtime PM, so plane registers cannot be
* written when their crtc is disabled.
*
* The comment for drm_atomic_helper_commit states:
* For drivers supporting runtime PM the recommended sequence is
*
* drm_atomic_helper_commit_modeset_disables(dev, state);
* drm_atomic_helper_commit_modeset_enables(dev, state);
* drm_atomic_helper_commit_planes(dev, state,
* DRM_PLANE_COMMIT_ACTIVE_ONLY);
*
* See the kerneldoc entries for these three functions for more details.
*/
drm_atomic_helper_commit_modeset_disables(drm, state);
drm_atomic_helper_commit_modeset_enables(drm, state);
drm_atomic_helper_commit_planes(drm, state,
DRM_PLANE_COMMIT_ACTIVE_ONLY);
drm_atomic_helper_wait_for_vblanks(drm, state);
drm_atomic_helper_cleanup_planes(drm, state);
drm_atomic_state_put(state);
}
static void mtk_atomic_work(struct work_struct *work)
{
struct mtk_drm_private *private = container_of(work,
struct mtk_drm_private, commit.work);
mtk_atomic_complete(private, private->commit.state);
}
static int mtk_atomic_commit(struct drm_device *drm,
struct drm_atomic_state *state,
bool async)
{
struct mtk_drm_private *private = drm->dev_private;
int ret;
ret = drm_atomic_helper_prepare_planes(drm, state);
if (ret)
return ret;
mutex_lock(&private->commit.lock);
flush_work(&private->commit.work);
ret = drm_atomic_helper_swap_state(state, true);
if (ret) {
mutex_unlock(&private->commit.lock);
drm_atomic_helper_cleanup_planes(drm, state);
return ret;
}
drm_atomic_state_get(state);
if (async)
mtk_atomic_schedule(private, state);
else
mtk_atomic_complete(private, state);
mutex_unlock(&private->commit.lock);
return 0;
}
static struct drm_framebuffer * static struct drm_framebuffer *
mtk_drm_mode_fb_create(struct drm_device *dev, mtk_drm_mode_fb_create(struct drm_device *dev,
...@@ -132,7 +57,7 @@ mtk_drm_mode_fb_create(struct drm_device *dev, ...@@ -132,7 +57,7 @@ mtk_drm_mode_fb_create(struct drm_device *dev,
static const struct drm_mode_config_funcs mtk_drm_mode_config_funcs = { static const struct drm_mode_config_funcs mtk_drm_mode_config_funcs = {
.fb_create = mtk_drm_mode_fb_create, .fb_create = mtk_drm_mode_fb_create,
.atomic_check = drm_atomic_helper_check, .atomic_check = drm_atomic_helper_check,
.atomic_commit = mtk_atomic_commit, .atomic_commit = drm_atomic_helper_commit,
}; };
static const enum mtk_ddp_comp_id mt2701_mtk_ddp_main[] = { static const enum mtk_ddp_comp_id mt2701_mtk_ddp_main[] = {
...@@ -250,6 +175,7 @@ static int mtk_drm_kms_init(struct drm_device *drm) ...@@ -250,6 +175,7 @@ static int mtk_drm_kms_init(struct drm_device *drm)
drm->mode_config.max_width = 4096; drm->mode_config.max_width = 4096;
drm->mode_config.max_height = 4096; drm->mode_config.max_height = 4096;
drm->mode_config.funcs = &mtk_drm_mode_config_funcs; drm->mode_config.funcs = &mtk_drm_mode_config_funcs;
drm->mode_config.helper_private = &mtk_drm_mode_config_helpers;
ret = component_bind_all(drm->dev, drm); ret = component_bind_all(drm->dev, drm);
if (ret) if (ret)
...@@ -509,8 +435,6 @@ static int mtk_drm_probe(struct platform_device *pdev) ...@@ -509,8 +435,6 @@ static int mtk_drm_probe(struct platform_device *pdev)
if (!private) if (!private)
return -ENOMEM; return -ENOMEM;
mutex_init(&private->commit.lock);
INIT_WORK(&private->commit.work, mtk_atomic_work);
private->data = of_device_get_match_data(dev); private->data = of_device_get_match_data(dev);
mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
......
...@@ -43,13 +43,6 @@ struct mtk_drm_private { ...@@ -43,13 +43,6 @@ struct mtk_drm_private {
struct device_node *comp_node[DDP_COMPONENT_ID_MAX]; struct device_node *comp_node[DDP_COMPONENT_ID_MAX];
struct mtk_ddp_comp *ddp_comp[DDP_COMPONENT_ID_MAX]; struct mtk_ddp_comp *ddp_comp[DDP_COMPONENT_ID_MAX];
const struct mtk_mmsys_driver_data *data; const struct mtk_mmsys_driver_data *data;
struct {
struct drm_atomic_state *state;
struct work_struct work;
struct mutex lock;
} commit;
struct drm_atomic_state *suspend_state; struct drm_atomic_state *suspend_state;
bool dma_parms_allocated; bool dma_parms_allocated;
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include <drm/drm_atomic.h> #include <drm/drm_atomic.h>
#include <drm/drm_atomic_helper.h> #include <drm/drm_atomic_helper.h>
#include <drm/drm_fourcc.h> #include <drm/drm_fourcc.h>
#include <drm/drm_atomic_uapi.h>
#include <drm/drm_plane_helper.h> #include <drm/drm_plane_helper.h>
#include <drm/drm_gem_framebuffer_helper.h> #include <drm/drm_gem_framebuffer_helper.h>
...@@ -75,6 +76,50 @@ static void mtk_drm_plane_destroy_state(struct drm_plane *plane, ...@@ -75,6 +76,50 @@ static void mtk_drm_plane_destroy_state(struct drm_plane *plane,
kfree(to_mtk_plane_state(state)); kfree(to_mtk_plane_state(state));
} }
static int mtk_plane_atomic_async_check(struct drm_plane *plane,
struct drm_plane_state *state)
{
struct drm_crtc_state *crtc_state;
if (plane != state->crtc->cursor)
return -EINVAL;
if (!plane->state)
return -EINVAL;
if (!plane->state->fb)
return -EINVAL;
if (state->state)
crtc_state = drm_atomic_get_existing_crtc_state(state->state,
state->crtc);
else /* Special case for asynchronous cursor updates. */
crtc_state = state->crtc->state;
return drm_atomic_helper_check_plane_state(plane->state, crtc_state,
DRM_PLANE_HELPER_NO_SCALING,
DRM_PLANE_HELPER_NO_SCALING,
true, true);
}
static void mtk_plane_atomic_async_update(struct drm_plane *plane,
struct drm_plane_state *new_state)
{
struct mtk_plane_state *state = to_mtk_plane_state(plane->state);
plane->state->crtc_x = new_state->crtc_x;
plane->state->crtc_y = new_state->crtc_y;
plane->state->crtc_h = new_state->crtc_h;
plane->state->crtc_w = new_state->crtc_w;
plane->state->src_x = new_state->src_x;
plane->state->src_y = new_state->src_y;
plane->state->src_h = new_state->src_h;
plane->state->src_w = new_state->src_w;
state->pending.async_dirty = true;
mtk_drm_crtc_async_update(new_state->crtc, plane, new_state);
}
static const struct drm_plane_funcs mtk_plane_funcs = { static const struct drm_plane_funcs mtk_plane_funcs = {
.update_plane = drm_atomic_helper_update_plane, .update_plane = drm_atomic_helper_update_plane,
.disable_plane = drm_atomic_helper_disable_plane, .disable_plane = drm_atomic_helper_disable_plane,
...@@ -163,6 +208,8 @@ static const struct drm_plane_helper_funcs mtk_plane_helper_funcs = { ...@@ -163,6 +208,8 @@ static const struct drm_plane_helper_funcs mtk_plane_helper_funcs = {
.atomic_check = mtk_plane_atomic_check, .atomic_check = mtk_plane_atomic_check,
.atomic_update = mtk_plane_atomic_update, .atomic_update = mtk_plane_atomic_update,
.atomic_disable = mtk_plane_atomic_disable, .atomic_disable = mtk_plane_atomic_disable,
.atomic_async_update = mtk_plane_atomic_async_update,
.atomic_async_check = mtk_plane_atomic_async_check,
}; };
int mtk_plane_init(struct drm_device *dev, struct drm_plane *plane, int mtk_plane_init(struct drm_device *dev, struct drm_plane *plane,
......
...@@ -22,6 +22,8 @@ struct mtk_plane_pending_state { ...@@ -22,6 +22,8 @@ struct mtk_plane_pending_state {
unsigned int height; unsigned int height;
unsigned int rotation; unsigned int rotation;
bool dirty; bool dirty;
bool async_dirty;
bool async_config;
}; };
struct mtk_plane_state { struct mtk_plane_state {
......
...@@ -9,12 +9,54 @@ ...@@ -9,12 +9,54 @@
#include <linux/mailbox_controller.h> #include <linux/mailbox_controller.h>
#include <linux/soc/mediatek/mtk-cmdq.h> #include <linux/soc/mediatek/mtk-cmdq.h>
#define CMDQ_ARG_A_WRITE_MASK 0xffff
#define CMDQ_WRITE_ENABLE_MASK BIT(0) #define CMDQ_WRITE_ENABLE_MASK BIT(0)
#define CMDQ_POLL_ENABLE_MASK BIT(0)
#define CMDQ_EOC_IRQ_EN BIT(0) #define CMDQ_EOC_IRQ_EN BIT(0)
#define CMDQ_EOC_CMD ((u64)((CMDQ_CODE_EOC << CMDQ_OP_CODE_SHIFT)) \ #define CMDQ_EOC_CMD ((u64)((CMDQ_CODE_EOC << CMDQ_OP_CODE_SHIFT)) \
<< 32 | CMDQ_EOC_IRQ_EN) << 32 | CMDQ_EOC_IRQ_EN)
struct cmdq_instruction {
union {
u32 value;
u32 mask;
};
union {
u16 offset;
u16 event;
};
u8 subsys;
u8 op;
};
int cmdq_dev_get_client_reg(struct device *dev,
struct cmdq_client_reg *client_reg, int idx)
{
struct of_phandle_args spec;
int err;
if (!client_reg)
return -ENOENT;
err = of_parse_phandle_with_fixed_args(dev->of_node,
"mediatek,gce-client-reg",
3, idx, &spec);
if (err < 0) {
dev_err(dev,
"error %d can't parse gce-client-reg property (%d)",
err, idx);
return err;
}
client_reg->subsys = (u8)spec.args[0];
client_reg->offset = (u16)spec.args[1];
client_reg->size = (u16)spec.args[2];
of_node_put(spec.np);
return 0;
}
EXPORT_SYMBOL(cmdq_dev_get_client_reg);
static void cmdq_client_timeout(struct timer_list *t) static void cmdq_client_timeout(struct timer_list *t)
{ {
struct cmdq_client *client = from_timer(client, t, timer); struct cmdq_client *client = from_timer(client, t, timer);
...@@ -110,10 +152,10 @@ void cmdq_pkt_destroy(struct cmdq_pkt *pkt) ...@@ -110,10 +152,10 @@ void cmdq_pkt_destroy(struct cmdq_pkt *pkt)
} }
EXPORT_SYMBOL(cmdq_pkt_destroy); EXPORT_SYMBOL(cmdq_pkt_destroy);
static int cmdq_pkt_append_command(struct cmdq_pkt *pkt, enum cmdq_code code, static int cmdq_pkt_append_command(struct cmdq_pkt *pkt,
u32 arg_a, u32 arg_b) struct cmdq_instruction inst)
{ {
u64 *cmd_ptr; struct cmdq_instruction *cmd_ptr;
if (unlikely(pkt->cmd_buf_size + CMDQ_INST_SIZE > pkt->buf_size)) { if (unlikely(pkt->cmd_buf_size + CMDQ_INST_SIZE > pkt->buf_size)) {
/* /*
...@@ -129,8 +171,9 @@ static int cmdq_pkt_append_command(struct cmdq_pkt *pkt, enum cmdq_code code, ...@@ -129,8 +171,9 @@ static int cmdq_pkt_append_command(struct cmdq_pkt *pkt, enum cmdq_code code,
__func__, (u32)pkt->buf_size); __func__, (u32)pkt->buf_size);
return -ENOMEM; return -ENOMEM;
} }
cmd_ptr = pkt->va_base + pkt->cmd_buf_size; cmd_ptr = pkt->va_base + pkt->cmd_buf_size;
(*cmd_ptr) = (u64)((code << CMDQ_OP_CODE_SHIFT) | arg_a) << 32 | arg_b; *cmd_ptr = inst;
pkt->cmd_buf_size += CMDQ_INST_SIZE; pkt->cmd_buf_size += CMDQ_INST_SIZE;
return 0; return 0;
...@@ -138,24 +181,34 @@ static int cmdq_pkt_append_command(struct cmdq_pkt *pkt, enum cmdq_code code, ...@@ -138,24 +181,34 @@ static int cmdq_pkt_append_command(struct cmdq_pkt *pkt, enum cmdq_code code,
int cmdq_pkt_write(struct cmdq_pkt *pkt, u8 subsys, u16 offset, u32 value) int cmdq_pkt_write(struct cmdq_pkt *pkt, u8 subsys, u16 offset, u32 value)
{ {
u32 arg_a = (offset & CMDQ_ARG_A_WRITE_MASK) | struct cmdq_instruction inst;
(subsys << CMDQ_SUBSYS_SHIFT);
return cmdq_pkt_append_command(pkt, CMDQ_CODE_WRITE, arg_a, value); inst.op = CMDQ_CODE_WRITE;
inst.value = value;
inst.offset = offset;
inst.subsys = subsys;
return cmdq_pkt_append_command(pkt, inst);
} }
EXPORT_SYMBOL(cmdq_pkt_write); EXPORT_SYMBOL(cmdq_pkt_write);
int cmdq_pkt_write_mask(struct cmdq_pkt *pkt, u8 subsys, int cmdq_pkt_write_mask(struct cmdq_pkt *pkt, u8 subsys,
u16 offset, u32 value, u32 mask) u16 offset, u32 value, u32 mask)
{ {
u32 offset_mask = offset; struct cmdq_instruction inst = { {0} };
int err = 0; u16 offset_mask = offset;
int err;
if (mask != 0xffffffff) { if (mask != 0xffffffff) {
err = cmdq_pkt_append_command(pkt, CMDQ_CODE_MASK, 0, ~mask); inst.op = CMDQ_CODE_MASK;
inst.mask = ~mask;
err = cmdq_pkt_append_command(pkt, inst);
if (err < 0)
return err;
offset_mask |= CMDQ_WRITE_ENABLE_MASK; offset_mask |= CMDQ_WRITE_ENABLE_MASK;
} }
err |= cmdq_pkt_write(pkt, subsys, offset_mask, value); err = cmdq_pkt_write(pkt, subsys, offset_mask, value);
return err; return err;
} }
...@@ -163,43 +216,85 @@ EXPORT_SYMBOL(cmdq_pkt_write_mask); ...@@ -163,43 +216,85 @@ EXPORT_SYMBOL(cmdq_pkt_write_mask);
int cmdq_pkt_wfe(struct cmdq_pkt *pkt, u16 event) int cmdq_pkt_wfe(struct cmdq_pkt *pkt, u16 event)
{ {
u32 arg_b; struct cmdq_instruction inst = { {0} };
if (event >= CMDQ_MAX_EVENT) if (event >= CMDQ_MAX_EVENT)
return -EINVAL; return -EINVAL;
/* inst.op = CMDQ_CODE_WFE;
* WFE arg_b inst.value = CMDQ_WFE_OPTION;
* bit 0-11: wait value inst.event = event;
* bit 15: 1 - wait, 0 - no wait
* bit 16-27: update value
* bit 31: 1 - update, 0 - no update
*/
arg_b = CMDQ_WFE_UPDATE | CMDQ_WFE_WAIT | CMDQ_WFE_WAIT_VALUE;
return cmdq_pkt_append_command(pkt, CMDQ_CODE_WFE, event, arg_b); return cmdq_pkt_append_command(pkt, inst);
} }
EXPORT_SYMBOL(cmdq_pkt_wfe); EXPORT_SYMBOL(cmdq_pkt_wfe);
int cmdq_pkt_clear_event(struct cmdq_pkt *pkt, u16 event) int cmdq_pkt_clear_event(struct cmdq_pkt *pkt, u16 event)
{ {
struct cmdq_instruction inst = { {0} };
if (event >= CMDQ_MAX_EVENT) if (event >= CMDQ_MAX_EVENT)
return -EINVAL; return -EINVAL;
return cmdq_pkt_append_command(pkt, CMDQ_CODE_WFE, event, inst.op = CMDQ_CODE_WFE;
CMDQ_WFE_UPDATE); inst.value = CMDQ_WFE_UPDATE;
inst.event = event;
return cmdq_pkt_append_command(pkt, inst);
} }
EXPORT_SYMBOL(cmdq_pkt_clear_event); EXPORT_SYMBOL(cmdq_pkt_clear_event);
int cmdq_pkt_poll(struct cmdq_pkt *pkt, u8 subsys,
u16 offset, u32 value)
{
struct cmdq_instruction inst = { {0} };
int err;
inst.op = CMDQ_CODE_POLL;
inst.value = value;
inst.offset = offset;
inst.subsys = subsys;
err = cmdq_pkt_append_command(pkt, inst);
return err;
}
EXPORT_SYMBOL(cmdq_pkt_poll);
int cmdq_pkt_poll_mask(struct cmdq_pkt *pkt, u8 subsys,
u16 offset, u32 value, u32 mask)
{
struct cmdq_instruction inst = { {0} };
int err;
inst.op = CMDQ_CODE_MASK;
inst.mask = ~mask;
err = cmdq_pkt_append_command(pkt, inst);
if (err < 0)
return err;
offset = offset | CMDQ_POLL_ENABLE_MASK;
err = cmdq_pkt_poll(pkt, subsys, offset, value);
return err;
}
EXPORT_SYMBOL(cmdq_pkt_poll_mask);
static int cmdq_pkt_finalize(struct cmdq_pkt *pkt) static int cmdq_pkt_finalize(struct cmdq_pkt *pkt)
{ {
struct cmdq_instruction inst = { {0} };
int err; int err;
/* insert EOC and generate IRQ for each command iteration */ /* insert EOC and generate IRQ for each command iteration */
err = cmdq_pkt_append_command(pkt, CMDQ_CODE_EOC, 0, CMDQ_EOC_IRQ_EN); inst.op = CMDQ_CODE_EOC;
inst.value = CMDQ_EOC_IRQ_EN;
err = cmdq_pkt_append_command(pkt, inst);
if (err < 0)
return err;
/* JUMP to end */ /* JUMP to end */
err |= cmdq_pkt_append_command(pkt, CMDQ_CODE_JUMP, 0, CMDQ_JUMP_PASS); inst.op = CMDQ_CODE_JUMP;
inst.value = CMDQ_JUMP_PASS;
err = cmdq_pkt_append_command(pkt, inst);
return err; return err;
} }
......
...@@ -20,6 +20,16 @@ ...@@ -20,6 +20,16 @@
#define CMDQ_WFE_WAIT BIT(15) #define CMDQ_WFE_WAIT BIT(15)
#define CMDQ_WFE_WAIT_VALUE 0x1 #define CMDQ_WFE_WAIT_VALUE 0x1
/*
* WFE arg_b
* bit 0-11: wait value
* bit 15: 1 - wait, 0 - no wait
* bit 16-27: update value
* bit 31: 1 - update, 0 - no update
*/
#define CMDQ_WFE_OPTION (CMDQ_WFE_UPDATE | CMDQ_WFE_WAIT | \
CMDQ_WFE_WAIT_VALUE)
/** cmdq event maximum */ /** cmdq event maximum */
#define CMDQ_MAX_EVENT 0x3ff #define CMDQ_MAX_EVENT 0x3ff
...@@ -45,6 +55,7 @@ ...@@ -45,6 +55,7 @@
enum cmdq_code { enum cmdq_code {
CMDQ_CODE_MASK = 0x02, CMDQ_CODE_MASK = 0x02,
CMDQ_CODE_WRITE = 0x04, CMDQ_CODE_WRITE = 0x04,
CMDQ_CODE_POLL = 0x08,
CMDQ_CODE_JUMP = 0x10, CMDQ_CODE_JUMP = 0x10,
CMDQ_CODE_WFE = 0x20, CMDQ_CODE_WFE = 0x20,
CMDQ_CODE_EOC = 0x40, CMDQ_CODE_EOC = 0x40,
......
...@@ -15,6 +15,12 @@ ...@@ -15,6 +15,12 @@
struct cmdq_pkt; struct cmdq_pkt;
struct cmdq_client_reg {
u8 subsys;
u16 offset;
u16 size;
};
struct cmdq_client { struct cmdq_client {
spinlock_t lock; spinlock_t lock;
u32 pkt_cnt; u32 pkt_cnt;
...@@ -24,6 +30,21 @@ struct cmdq_client { ...@@ -24,6 +30,21 @@ struct cmdq_client {
u32 timeout_ms; /* in unit of microsecond */ u32 timeout_ms; /* in unit of microsecond */
}; };
/**
* cmdq_dev_get_client_reg() - parse cmdq client reg from the device
* node of CMDQ client
* @dev: device of CMDQ mailbox client
* @client_reg: CMDQ client reg pointer
* @idx: the index of desired reg
*
* Return: 0 for success; else the error code is returned
*
* Help CMDQ client parsing the cmdq client reg
* from the device node of CMDQ client.
*/
int cmdq_dev_get_client_reg(struct device *dev,
struct cmdq_client_reg *client_reg, int idx);
/** /**
* cmdq_mbox_create() - create CMDQ mailbox client and channel * cmdq_mbox_create() - create CMDQ mailbox client and channel
* @dev: device of CMDQ mailbox client * @dev: device of CMDQ mailbox client
...@@ -99,6 +120,38 @@ int cmdq_pkt_wfe(struct cmdq_pkt *pkt, u16 event); ...@@ -99,6 +120,38 @@ int cmdq_pkt_wfe(struct cmdq_pkt *pkt, u16 event);
*/ */
int cmdq_pkt_clear_event(struct cmdq_pkt *pkt, u16 event); int cmdq_pkt_clear_event(struct cmdq_pkt *pkt, u16 event);
/**
* cmdq_pkt_poll() - Append polling command to the CMDQ packet, ask GCE to
* execute an instruction that wait for a specified
* hardware register to check for the value w/o mask.
* All GCE hardware threads will be blocked by this
* instruction.
* @pkt: the CMDQ packet
* @subsys: the CMDQ sub system code
* @offset: register offset from CMDQ sub system
* @value: the specified target register value
*
* Return: 0 for success; else the error code is returned
*/
int cmdq_pkt_poll(struct cmdq_pkt *pkt, u8 subsys,
u16 offset, u32 value);
/**
* cmdq_pkt_poll_mask() - Append polling command to the CMDQ packet, ask GCE to
* execute an instruction that wait for a specified
* hardware register to check for the value w/ mask.
* All GCE hardware threads will be blocked by this
* instruction.
* @pkt: the CMDQ packet
* @subsys: the CMDQ sub system code
* @offset: register offset from CMDQ sub system
* @value: the specified target register value
* @mask: the specified target register mask
*
* Return: 0 for success; else the error code is returned
*/
int cmdq_pkt_poll_mask(struct cmdq_pkt *pkt, u8 subsys,
u16 offset, u32 value, u32 mask);
/** /**
* cmdq_pkt_flush_async() - trigger CMDQ to asynchronously execute the CMDQ * cmdq_pkt_flush_async() - trigger CMDQ to asynchronously execute the CMDQ
* packet and call back at the end of done packet * packet and call back at the end of done packet
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment