Mediatek DRM Next for Linux 5.6
-----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iQIcBAABAgAGBQJeHS14AAoJEOHKc6PJWU4k9RkQAJHWLafLl1EEdViWY3YeK/E0 kKUGv+RcuG/HL8NG+rTN7MAT4zbxCF+r0JJIT6+BKlMTUqt4+sxEPhDRPEz1z++4 GOEniw9ogQGicQTvFVlAr4rDnGpvRaAQ8BH3C9/lg67cOe6mrNQOI0AKl99DuXMg dPRbgs1zpajjw/qN60CSMrCtYa+O8IadSx6/TMBhdzk9K4WRPc78UKtiCw5rkLa8 TJAHOEhImWVV1LDoNK9hTmV7huPqQw6L8ZcpJzjgVJRwtrO01LGG5rBOOdnu2Cc4 XiS81whsPXF+GdZPg9frWXJCG41CG03vEykX3y+2rXMdhDsdfBZo2DXKAkpYvGlN WICjf1aq9BlcjFfNUFqeGgh0ZxNLmItyCfptjRMpclmlj25X7isXPz6iKN/nnucr JApacibMeIrchsk//pykhp9LIcn42sMP+ULOSvwFxtOu4o947+xCAlTEbUwN5Mkc Oxeo/TZoBQAmpTHPh7CuuiENqvJuOGpL1Couzqse0NjFWuDuPmDVO6DwKx7X1U98 hNf28sur0XGrQvuGgV0dcytqPxBCTF2/qDXhbC6O4mhzGvWTWbBY1AzLQEekQS4Z oO4s3JTcGkzv24fXfBVD/Rf9fa6VlnfVuH9vCe7LgX1cG72AaMc0sho3m3gTWJCb qeZXngpzlBw8zal3dNN2 =BXQH -----END PGP SIGNATURE----- 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: Dave Airlie <airlied@redhat.com> From: CK Hu <ck.hu@mediatek.com> Link: https://patchwork.freedesktop.org/patch/msgid/1578972526.14594.8.camel@mtksdaap41
This commit is contained in:
commit
6fc376f026
|
@ -20,7 +20,7 @@ obj-$(CONFIG_DRM_MEDIATEK) += mediatek-drm.o
|
|||
mediatek-drm-hdmi-objs := mtk_cec.o \
|
||||
mtk_hdmi.o \
|
||||
mtk_hdmi_ddc.o \
|
||||
mtk_mt2701_hdmi_phy.o \
|
||||
mtk_mt2701_hdmi_phy.o \
|
||||
mtk_mt8173_hdmi_phy.o \
|
||||
mtk_hdmi_phy.o
|
||||
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
#include <linux/of_device.h>
|
||||
#include <linux/of_irq.h>
|
||||
#include <linux/platform_device.h>
|
||||
#include <linux/soc/mediatek/mtk-cmdq.h>
|
||||
|
||||
#include "mtk_drm_crtc.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)
|
|||
|
||||
static void mtk_color_config(struct mtk_ddp_comp *comp, unsigned int w,
|
||||
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);
|
||||
|
||||
writel(w, comp->regs + DISP_COLOR_WIDTH(color));
|
||||
writel(h, comp->regs + DISP_COLOR_HEIGHT(color));
|
||||
mtk_ddp_write(cmdq_pkt, w, comp, DISP_COLOR_WIDTH(color));
|
||||
mtk_ddp_write(cmdq_pkt, h, comp, DISP_COLOR_HEIGHT(color));
|
||||
}
|
||||
|
||||
static void mtk_color_start(struct mtk_ddp_comp *comp)
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
#include <linux/of_device.h>
|
||||
#include <linux/of_irq.h>
|
||||
#include <linux/platform_device.h>
|
||||
#include <linux/soc/mediatek/mtk-cmdq.h>
|
||||
|
||||
#include "mtk_drm_crtc.h"
|
||||
#include "mtk_drm_ddp_comp.h"
|
||||
|
@ -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,
|
||||
unsigned int h, unsigned int vrefresh,
|
||||
unsigned int bpc)
|
||||
unsigned int bpc, struct cmdq_pkt *cmdq_pkt)
|
||||
{
|
||||
if (w != 0 && h != 0)
|
||||
writel_relaxed(h << 16 | w, comp->regs + DISP_REG_OVL_ROI_SIZE);
|
||||
writel_relaxed(0x0, comp->regs + DISP_REG_OVL_ROI_BGCLR);
|
||||
mtk_ddp_write_relaxed(cmdq_pkt, h << 16 | w, comp,
|
||||
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);
|
||||
writel(0x0, comp->regs + DISP_REG_OVL_RST);
|
||||
mtk_ddp_write(cmdq_pkt, 0x1, comp, 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)
|
||||
|
@ -175,16 +177,16 @@ static int mtk_ovl_layer_check(struct mtk_ddp_comp *comp, unsigned int idx,
|
|||
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_h;
|
||||
unsigned int gmc_value;
|
||||
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_THRESHOLD_BITS - ovl->data->gmc_bits);
|
||||
gmc_thrshd_h = GMC_THRESHOLD_HIGH >>
|
||||
|
@ -194,22 +196,19 @@ static void mtk_ovl_layer_on(struct mtk_ddp_comp *comp, unsigned int idx)
|
|||
else
|
||||
gmc_value = gmc_thrshd_l | gmc_thrshd_l << 8 |
|
||||
gmc_thrshd_h << 16 | gmc_thrshd_h << 24;
|
||||
writel(gmc_value, comp->regs + DISP_REG_OVL_RDMA_GMC(idx));
|
||||
|
||||
reg = readl(comp->regs + DISP_REG_OVL_SRC_CON);
|
||||
reg = reg | BIT(idx);
|
||||
writel(reg, comp->regs + DISP_REG_OVL_SRC_CON);
|
||||
mtk_ddp_write(cmdq_pkt, gmc_value,
|
||||
comp, DISP_REG_OVL_RDMA_GMC(idx));
|
||||
mtk_ddp_write_mask(cmdq_pkt, BIT(idx), comp,
|
||||
DISP_REG_OVL_SRC_CON, BIT(idx));
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
reg = readl(comp->regs + DISP_REG_OVL_SRC_CON);
|
||||
reg = reg & ~BIT(idx);
|
||||
writel(reg, comp->regs + DISP_REG_OVL_SRC_CON);
|
||||
|
||||
writel(0x0, comp->regs + DISP_REG_OVL_RDMA_CTRL(idx));
|
||||
mtk_ddp_write_mask(cmdq_pkt, 0, comp,
|
||||
DISP_REG_OVL_SRC_CON, BIT(idx));
|
||||
mtk_ddp_write(cmdq_pkt, 0, comp,
|
||||
DISP_REG_OVL_RDMA_CTRL(idx));
|
||||
}
|
||||
|
||||
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,
|
||||
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_plane_pending_state *pending = &state->pending;
|
||||
|
@ -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 con;
|
||||
|
||||
if (!pending->enable)
|
||||
mtk_ovl_layer_off(comp, idx);
|
||||
if (!pending->enable) {
|
||||
mtk_ovl_layer_off(comp, idx, cmdq_pkt);
|
||||
return;
|
||||
}
|
||||
|
||||
con = ovl_fmt_convert(ovl, fmt);
|
||||
if (idx != 0)
|
||||
if (state->base.fb->format->has_alpha)
|
||||
con |= OVL_CON_AEN | OVL_CON_ALPHA;
|
||||
|
||||
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,
|
|||
addr += pending->pitch - 1;
|
||||
}
|
||||
|
||||
writel_relaxed(con, comp->regs + DISP_REG_OVL_CON(idx));
|
||||
writel_relaxed(pitch, comp->regs + DISP_REG_OVL_PITCH(idx));
|
||||
writel_relaxed(src_size, comp->regs + DISP_REG_OVL_SRC_SIZE(idx));
|
||||
writel_relaxed(offset, comp->regs + DISP_REG_OVL_OFFSET(idx));
|
||||
writel_relaxed(addr, comp->regs + DISP_REG_OVL_ADDR(ovl, idx));
|
||||
mtk_ddp_write_relaxed(cmdq_pkt, con, comp,
|
||||
DISP_REG_OVL_CON(idx));
|
||||
mtk_ddp_write_relaxed(cmdq_pkt, pitch, comp,
|
||||
DISP_REG_OVL_PITCH(idx));
|
||||
mtk_ddp_write_relaxed(cmdq_pkt, src_size, comp,
|
||||
DISP_REG_OVL_SRC_SIZE(idx));
|
||||
mtk_ddp_write_relaxed(cmdq_pkt, offset, comp,
|
||||
DISP_REG_OVL_OFFSET(idx));
|
||||
mtk_ddp_write_relaxed(cmdq_pkt, addr, comp,
|
||||
DISP_REG_OVL_ADDR(ovl, idx));
|
||||
|
||||
if (pending->enable)
|
||||
mtk_ovl_layer_on(comp, idx);
|
||||
mtk_ovl_layer_on(comp, idx, cmdq_pkt);
|
||||
}
|
||||
|
||||
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 = {
|
|||
.disable_vblank = mtk_ovl_disable_vblank,
|
||||
.supported_rotations = mtk_ovl_supported_rotations,
|
||||
.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_config = mtk_ovl_layer_config,
|
||||
.bgclr_in_on = mtk_ovl_bgclr_in_on,
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
#include <linux/of_device.h>
|
||||
#include <linux/of_irq.h>
|
||||
#include <linux/platform_device.h>
|
||||
#include <linux/soc/mediatek/mtk-cmdq.h>
|
||||
|
||||
#include "mtk_drm_crtc.h"
|
||||
#include "mtk_drm_ddp_comp.h"
|
||||
|
@ -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,
|
||||
unsigned int height, unsigned int vrefresh,
|
||||
unsigned int bpc)
|
||||
unsigned int bpc, struct cmdq_pkt *cmdq_pkt)
|
||||
{
|
||||
unsigned int threshold;
|
||||
unsigned int reg;
|
||||
struct mtk_disp_rdma *rdma = comp_to_rdma(comp);
|
||||
|
||||
rdma_update_bits(comp, DISP_REG_RDMA_SIZE_CON_0, 0xfff, width);
|
||||
rdma_update_bits(comp, DISP_REG_RDMA_SIZE_CON_1, 0xfffff, height);
|
||||
mtk_ddp_write_mask(cmdq_pkt, width, comp,
|
||||
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.
|
||||
|
@ -144,7 +147,7 @@ static void mtk_rdma_config(struct mtk_ddp_comp *comp, unsigned int width,
|
|||
reg = RDMA_FIFO_UNDERFLOW_EN |
|
||||
RDMA_FIFO_PSEUDO_SIZE(RDMA_FIFO_SIZE(rdma)) |
|
||||
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,
|
||||
|
@ -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,
|
||||
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_plane_pending_state *pending = &state->pending;
|
||||
|
@ -200,24 +204,27 @@ static void mtk_rdma_layer_config(struct mtk_ddp_comp *comp, unsigned int idx,
|
|||
unsigned int con;
|
||||
|
||||
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) {
|
||||
rdma_update_bits(comp, DISP_REG_RDMA_SIZE_CON_0,
|
||||
RDMA_MATRIX_ENABLE, RDMA_MATRIX_ENABLE);
|
||||
rdma_update_bits(comp, DISP_REG_RDMA_SIZE_CON_0,
|
||||
RDMA_MATRIX_INT_MTX_SEL,
|
||||
RDMA_MATRIX_INT_MTX_BT601_to_RGB);
|
||||
mtk_ddp_write_mask(cmdq_pkt, RDMA_MATRIX_ENABLE, comp,
|
||||
DISP_REG_RDMA_SIZE_CON_0,
|
||||
RDMA_MATRIX_ENABLE);
|
||||
mtk_ddp_write_mask(cmdq_pkt, RDMA_MATRIX_INT_MTX_BT601_to_RGB,
|
||||
comp, DISP_REG_RDMA_SIZE_CON_0,
|
||||
RDMA_MATRIX_INT_MTX_SEL);
|
||||
} else {
|
||||
rdma_update_bits(comp, DISP_REG_RDMA_SIZE_CON_0,
|
||||
RDMA_MATRIX_ENABLE, 0);
|
||||
mtk_ddp_write_mask(cmdq_pkt, 0, comp,
|
||||
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 = {
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
|
||||
#include <linux/clk.h>
|
||||
#include <linux/pm_runtime.h>
|
||||
#include <linux/soc/mediatek/mtk-cmdq.h>
|
||||
|
||||
#include <asm/barrier.h>
|
||||
#include <soc/mediatek/smi.h>
|
||||
|
@ -42,11 +43,20 @@ struct mtk_drm_crtc {
|
|||
struct drm_plane *planes;
|
||||
unsigned int layer_nr;
|
||||
bool pending_planes;
|
||||
bool pending_async_planes;
|
||||
|
||||
#if IS_REACHABLE(CONFIG_MTK_CMDQ)
|
||||
struct cmdq_client *cmdq_client;
|
||||
u32 cmdq_event;
|
||||
#endif
|
||||
|
||||
void __iomem *config_regs;
|
||||
struct mtk_disp_mutex *mutex;
|
||||
unsigned int ddp_comp_nr;
|
||||
struct mtk_ddp_comp **ddp_comp;
|
||||
|
||||
/* lock for display hardware access */
|
||||
struct mutex hw_lock;
|
||||
};
|
||||
|
||||
struct mtk_crtc_state {
|
||||
|
@ -215,11 +225,12 @@ struct mtk_ddp_comp *mtk_drm_ddp_comp_for_plane(struct drm_crtc *crtc,
|
|||
struct mtk_drm_crtc *mtk_crtc = to_mtk_crtc(crtc);
|
||||
struct mtk_ddp_comp *comp;
|
||||
int i, count = 0;
|
||||
unsigned int local_index = plane - mtk_crtc->planes;
|
||||
|
||||
for (i = 0; i < mtk_crtc->ddp_comp_nr; i++) {
|
||||
comp = mtk_crtc->ddp_comp[i];
|
||||
if (plane->index < (count + mtk_ddp_comp_layer_nr(comp))) {
|
||||
*local_layer = plane->index - count;
|
||||
if (local_index < (count + mtk_ddp_comp_layer_nr(comp))) {
|
||||
*local_layer = local_index - count;
|
||||
return comp;
|
||||
}
|
||||
count += mtk_ddp_comp_layer_nr(comp);
|
||||
|
@ -229,6 +240,13 @@ struct mtk_ddp_comp *mtk_drm_ddp_comp_for_plane(struct drm_crtc *crtc,
|
|||
return NULL;
|
||||
}
|
||||
|
||||
#if IS_REACHABLE(CONFIG_MTK_CMDQ)
|
||||
static void ddp_cmdq_cb(struct cmdq_cb_data data)
|
||||
{
|
||||
cmdq_pkt_destroy(data.data);
|
||||
}
|
||||
#endif
|
||||
|
||||
static int mtk_crtc_ddp_hw_init(struct mtk_drm_crtc *mtk_crtc)
|
||||
{
|
||||
struct drm_crtc *crtc = &mtk_crtc->base;
|
||||
|
@ -297,7 +315,7 @@ static int mtk_crtc_ddp_hw_init(struct mtk_drm_crtc *mtk_crtc)
|
|||
if (i == 1)
|
||||
mtk_ddp_comp_bgclr_in_on(comp);
|
||||
|
||||
mtk_ddp_comp_config(comp, width, height, vrefresh, bpc);
|
||||
mtk_ddp_comp_config(comp, width, height, vrefresh, bpc, NULL);
|
||||
mtk_ddp_comp_start(comp);
|
||||
}
|
||||
|
||||
|
@ -310,7 +328,9 @@ static int mtk_crtc_ddp_hw_init(struct mtk_drm_crtc *mtk_crtc)
|
|||
|
||||
plane_state = to_mtk_plane_state(plane->state);
|
||||
comp = mtk_drm_ddp_comp_for_plane(crtc, plane, &local_layer);
|
||||
mtk_ddp_comp_layer_config(comp, local_layer, plane_state);
|
||||
if (comp)
|
||||
mtk_ddp_comp_layer_config(comp, local_layer,
|
||||
plane_state, NULL);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
@ -325,6 +345,7 @@ err_pm_runtime_put:
|
|||
static void mtk_crtc_ddp_hw_fini(struct mtk_drm_crtc *mtk_crtc)
|
||||
{
|
||||
struct drm_device *drm = mtk_crtc->base.dev;
|
||||
struct drm_crtc *crtc = &mtk_crtc->base;
|
||||
int i;
|
||||
|
||||
DRM_DEBUG_DRIVER("%s\n", __func__);
|
||||
|
@ -350,9 +371,17 @@ static void mtk_crtc_ddp_hw_fini(struct mtk_drm_crtc *mtk_crtc)
|
|||
mtk_disp_mutex_unprepare(mtk_crtc->mutex);
|
||||
|
||||
pm_runtime_put(drm->dev);
|
||||
|
||||
if (crtc->state->event && !crtc->state->active) {
|
||||
spin_lock_irq(&crtc->dev->event_lock);
|
||||
drm_crtc_send_vblank_event(crtc, crtc->state->event);
|
||||
crtc->state->event = NULL;
|
||||
spin_unlock_irq(&crtc->dev->event_lock);
|
||||
}
|
||||
}
|
||||
|
||||
static void mtk_crtc_ddp_config(struct drm_crtc *crtc)
|
||||
static void mtk_crtc_ddp_config(struct drm_crtc *crtc,
|
||||
struct cmdq_pkt *cmdq_handle)
|
||||
{
|
||||
struct mtk_drm_crtc *mtk_crtc = to_mtk_crtc(crtc);
|
||||
struct mtk_crtc_state *state = to_mtk_crtc_state(mtk_crtc->base.state);
|
||||
|
@ -368,7 +397,8 @@ static void mtk_crtc_ddp_config(struct drm_crtc *crtc)
|
|||
if (state->pending_config) {
|
||||
mtk_ddp_comp_config(comp, state->pending_width,
|
||||
state->pending_height,
|
||||
state->pending_vrefresh, 0);
|
||||
state->pending_vrefresh, 0,
|
||||
cmdq_handle);
|
||||
|
||||
state->pending_config = false;
|
||||
}
|
||||
|
@ -386,12 +416,84 @@ static void mtk_crtc_ddp_config(struct drm_crtc *crtc)
|
|||
comp = mtk_drm_ddp_comp_for_plane(crtc, plane,
|
||||
&local_layer);
|
||||
|
||||
mtk_ddp_comp_layer_config(comp, local_layer,
|
||||
plane_state);
|
||||
if (comp)
|
||||
mtk_ddp_comp_layer_config(comp, local_layer,
|
||||
plane_state,
|
||||
cmdq_handle);
|
||||
plane_state->pending.config = false;
|
||||
}
|
||||
mtk_crtc->pending_planes = false;
|
||||
}
|
||||
|
||||
if (mtk_crtc->pending_async_planes) {
|
||||
for (i = 0; i < mtk_crtc->layer_nr; i++) {
|
||||
struct drm_plane *plane = &mtk_crtc->planes[i];
|
||||
struct mtk_plane_state *plane_state;
|
||||
|
||||
plane_state = to_mtk_plane_state(plane->state);
|
||||
|
||||
if (!plane_state->pending.async_config)
|
||||
continue;
|
||||
|
||||
comp = mtk_drm_ddp_comp_for_plane(crtc, plane,
|
||||
&local_layer);
|
||||
|
||||
if (comp)
|
||||
mtk_ddp_comp_layer_config(comp, local_layer,
|
||||
plane_state,
|
||||
cmdq_handle);
|
||||
plane_state->pending.async_config = false;
|
||||
}
|
||||
mtk_crtc->pending_async_planes = false;
|
||||
}
|
||||
}
|
||||
|
||||
static void mtk_drm_crtc_hw_config(struct mtk_drm_crtc *mtk_crtc)
|
||||
{
|
||||
#if IS_REACHABLE(CONFIG_MTK_CMDQ)
|
||||
struct cmdq_pkt *cmdq_handle;
|
||||
#endif
|
||||
struct drm_crtc *crtc = &mtk_crtc->base;
|
||||
struct mtk_drm_private *priv = crtc->dev->dev_private;
|
||||
unsigned int pending_planes = 0, pending_async_planes = 0;
|
||||
int i;
|
||||
|
||||
mutex_lock(&mtk_crtc->hw_lock);
|
||||
for (i = 0; i < mtk_crtc->layer_nr; i++) {
|
||||
struct drm_plane *plane = &mtk_crtc->planes[i];
|
||||
struct mtk_plane_state *plane_state;
|
||||
|
||||
plane_state = to_mtk_plane_state(plane->state);
|
||||
if (plane_state->pending.dirty) {
|
||||
plane_state->pending.config = true;
|
||||
plane_state->pending.dirty = false;
|
||||
pending_planes |= BIT(i);
|
||||
} else if (plane_state->pending.async_dirty) {
|
||||
plane_state->pending.async_config = true;
|
||||
plane_state->pending.async_dirty = false;
|
||||
pending_async_planes |= BIT(i);
|
||||
}
|
||||
}
|
||||
if (pending_planes)
|
||||
mtk_crtc->pending_planes = true;
|
||||
if (pending_async_planes)
|
||||
mtk_crtc->pending_async_planes = true;
|
||||
|
||||
if (priv->data->shadow_register) {
|
||||
mtk_disp_mutex_acquire(mtk_crtc->mutex);
|
||||
mtk_crtc_ddp_config(crtc, NULL);
|
||||
mtk_disp_mutex_release(mtk_crtc->mutex);
|
||||
}
|
||||
#if IS_REACHABLE(CONFIG_MTK_CMDQ)
|
||||
if (mtk_crtc->cmdq_client) {
|
||||
cmdq_handle = cmdq_pkt_create(mtk_crtc->cmdq_client, PAGE_SIZE);
|
||||
cmdq_pkt_clear_event(cmdq_handle, mtk_crtc->cmdq_event);
|
||||
cmdq_pkt_wfe(cmdq_handle, mtk_crtc->cmdq_event);
|
||||
mtk_crtc_ddp_config(crtc, cmdq_handle);
|
||||
cmdq_pkt_flush_async(cmdq_handle, ddp_cmdq_cb, cmdq_handle);
|
||||
}
|
||||
#endif
|
||||
mutex_unlock(&mtk_crtc->hw_lock);
|
||||
}
|
||||
|
||||
int mtk_drm_crtc_plane_check(struct drm_crtc *crtc, struct drm_plane *plane,
|
||||
|
@ -401,7 +503,23 @@ int mtk_drm_crtc_plane_check(struct drm_crtc *crtc, struct drm_plane *plane,
|
|||
struct mtk_ddp_comp *comp;
|
||||
|
||||
comp = mtk_drm_ddp_comp_for_plane(crtc, plane, &local_layer);
|
||||
return mtk_ddp_comp_layer_check(comp, local_layer, state);
|
||||
if (comp)
|
||||
return mtk_ddp_comp_layer_check(comp, local_layer, state);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void mtk_drm_crtc_async_update(struct drm_crtc *crtc, struct drm_plane *plane,
|
||||
struct drm_plane_state *new_state)
|
||||
{
|
||||
struct mtk_drm_crtc *mtk_crtc = to_mtk_crtc(crtc);
|
||||
const struct drm_plane_helper_funcs *plane_helper_funcs =
|
||||
plane->helper_private;
|
||||
|
||||
if (!mtk_crtc->enabled)
|
||||
return;
|
||||
|
||||
plane_helper_funcs->atomic_update(plane, new_state);
|
||||
mtk_drm_crtc_hw_config(mtk_crtc);
|
||||
}
|
||||
|
||||
static void mtk_drm_crtc_atomic_enable(struct drm_crtc *crtc,
|
||||
|
@ -451,6 +569,7 @@ static void mtk_drm_crtc_atomic_disable(struct drm_crtc *crtc,
|
|||
}
|
||||
mtk_crtc->pending_planes = true;
|
||||
|
||||
mtk_drm_crtc_hw_config(mtk_crtc);
|
||||
/* Wait for planes to be disabled */
|
||||
drm_crtc_wait_one_vblank(crtc);
|
||||
|
||||
|
@ -482,34 +601,16 @@ static void mtk_drm_crtc_atomic_flush(struct drm_crtc *crtc,
|
|||
struct drm_crtc_state *old_crtc_state)
|
||||
{
|
||||
struct mtk_drm_crtc *mtk_crtc = to_mtk_crtc(crtc);
|
||||
struct mtk_drm_private *priv = crtc->dev->dev_private;
|
||||
unsigned int pending_planes = 0;
|
||||
int i;
|
||||
|
||||
if (mtk_crtc->event)
|
||||
mtk_crtc->pending_needs_vblank = true;
|
||||
for (i = 0; i < mtk_crtc->layer_nr; i++) {
|
||||
struct drm_plane *plane = &mtk_crtc->planes[i];
|
||||
struct mtk_plane_state *plane_state;
|
||||
|
||||
plane_state = to_mtk_plane_state(plane->state);
|
||||
if (plane_state->pending.dirty) {
|
||||
plane_state->pending.config = true;
|
||||
plane_state->pending.dirty = false;
|
||||
pending_planes |= BIT(i);
|
||||
}
|
||||
}
|
||||
if (pending_planes)
|
||||
mtk_crtc->pending_planes = true;
|
||||
if (crtc->state->color_mgmt_changed)
|
||||
for (i = 0; i < mtk_crtc->ddp_comp_nr; i++)
|
||||
for (i = 0; i < mtk_crtc->ddp_comp_nr; i++) {
|
||||
mtk_ddp_gamma_set(mtk_crtc->ddp_comp[i], crtc->state);
|
||||
|
||||
if (priv->data->shadow_register) {
|
||||
mtk_disp_mutex_acquire(mtk_crtc->mutex);
|
||||
mtk_crtc_ddp_config(crtc);
|
||||
mtk_disp_mutex_release(mtk_crtc->mutex);
|
||||
}
|
||||
mtk_ddp_ctm_set(mtk_crtc->ddp_comp[i], crtc->state);
|
||||
}
|
||||
mtk_drm_crtc_hw_config(mtk_crtc);
|
||||
}
|
||||
|
||||
static const struct drm_crtc_funcs mtk_crtc_funcs = {
|
||||
|
@ -559,8 +660,12 @@ void mtk_crtc_ddp_irq(struct drm_crtc *crtc, struct mtk_ddp_comp *comp)
|
|||
struct mtk_drm_crtc *mtk_crtc = to_mtk_crtc(crtc);
|
||||
struct mtk_drm_private *priv = crtc->dev->dev_private;
|
||||
|
||||
#if IS_REACHABLE(CONFIG_MTK_CMDQ)
|
||||
if (!priv->data->shadow_register && !mtk_crtc->cmdq_client)
|
||||
#else
|
||||
if (!priv->data->shadow_register)
|
||||
mtk_crtc_ddp_config(crtc);
|
||||
#endif
|
||||
mtk_crtc_ddp_config(crtc, NULL);
|
||||
|
||||
mtk_drm_finish_page_flip(mtk_crtc);
|
||||
}
|
||||
|
@ -627,6 +732,8 @@ int mtk_drm_crtc_create(struct drm_device *drm_dev,
|
|||
int pipe = priv->num_pipes;
|
||||
int ret;
|
||||
int i;
|
||||
bool has_ctm = false;
|
||||
uint gamma_lut_size = 0;
|
||||
|
||||
if (!path)
|
||||
return 0;
|
||||
|
@ -677,6 +784,14 @@ int mtk_drm_crtc_create(struct drm_device *drm_dev,
|
|||
}
|
||||
|
||||
mtk_crtc->ddp_comp[i] = comp;
|
||||
|
||||
if (comp->funcs) {
|
||||
if (comp->funcs->gamma_set)
|
||||
gamma_lut_size = MTK_LUT_SIZE;
|
||||
|
||||
if (comp->funcs->ctm_set)
|
||||
has_ctm = true;
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; i < mtk_crtc->ddp_comp_nr; i++)
|
||||
|
@ -697,9 +812,28 @@ int mtk_drm_crtc_create(struct drm_device *drm_dev,
|
|||
NULL, pipe);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
drm_mode_crtc_set_gamma_size(&mtk_crtc->base, MTK_LUT_SIZE);
|
||||
drm_crtc_enable_color_mgmt(&mtk_crtc->base, 0, false, MTK_LUT_SIZE);
|
||||
priv->num_pipes++;
|
||||
|
||||
if (gamma_lut_size)
|
||||
drm_mode_crtc_set_gamma_size(&mtk_crtc->base, gamma_lut_size);
|
||||
drm_crtc_enable_color_mgmt(&mtk_crtc->base, 0, has_ctm, gamma_lut_size);
|
||||
priv->num_pipes++;
|
||||
mutex_init(&mtk_crtc->hw_lock);
|
||||
|
||||
#if IS_REACHABLE(CONFIG_MTK_CMDQ)
|
||||
mtk_crtc->cmdq_client =
|
||||
cmdq_mbox_create(dev, drm_crtc_index(&mtk_crtc->base),
|
||||
2000);
|
||||
if (IS_ERR(mtk_crtc->cmdq_client)) {
|
||||
dev_dbg(dev, "mtk_crtc %d failed to create mailbox client, writing register by CPU now\n",
|
||||
drm_crtc_index(&mtk_crtc->base));
|
||||
mtk_crtc->cmdq_client = NULL;
|
||||
}
|
||||
ret = of_property_read_u32_index(dev->of_node, "mediatek,gce-events",
|
||||
drm_crtc_index(&mtk_crtc->base),
|
||||
&mtk_crtc->cmdq_event);
|
||||
if (ret)
|
||||
dev_dbg(dev, "mtk_crtc %d failed to get mediatek,gce-events property\n",
|
||||
drm_crtc_index(&mtk_crtc->base));
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -21,5 +21,7 @@ int mtk_drm_crtc_create(struct drm_device *drm_dev,
|
|||
unsigned int path_len);
|
||||
int mtk_drm_crtc_plane_check(struct drm_crtc *crtc, struct drm_plane *plane,
|
||||
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 */
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
#include <linux/of_irq.h>
|
||||
#include <linux/of_platform.h>
|
||||
#include <linux/platform_device.h>
|
||||
|
||||
#include <linux/soc/mediatek/mtk-cmdq.h>
|
||||
#include "mtk_drm_drv.h"
|
||||
#include "mtk_drm_plane.h"
|
||||
#include "mtk_drm_ddp_comp.h"
|
||||
|
@ -37,7 +37,15 @@
|
|||
#define CCORR_EN BIT(0)
|
||||
#define DISP_CCORR_CFG 0x0020
|
||||
#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_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 DITHER_EN BIT(0)
|
||||
|
@ -76,36 +84,84 @@
|
|||
#define DITHER_ADD_LSHIFT_G(x) (((x) & 0x7) << 4)
|
||||
#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,
|
||||
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 == 0)
|
||||
return;
|
||||
|
||||
if (bpc >= MTK_MIN_BPC) {
|
||||
writel(0, comp->regs + DISP_DITHER_5);
|
||||
writel(0, comp->regs + DISP_DITHER_7);
|
||||
writel(DITHER_LSB_ERR_SHIFT_R(MTK_MAX_BPC - bpc) |
|
||||
DITHER_ADD_LSHIFT_R(MTK_MAX_BPC - bpc) |
|
||||
DITHER_NEW_BIT_MODE,
|
||||
comp->regs + DISP_DITHER_15);
|
||||
writel(DITHER_LSB_ERR_SHIFT_B(MTK_MAX_BPC - bpc) |
|
||||
DITHER_ADD_LSHIFT_B(MTK_MAX_BPC - bpc) |
|
||||
DITHER_LSB_ERR_SHIFT_G(MTK_MAX_BPC - bpc) |
|
||||
DITHER_ADD_LSHIFT_G(MTK_MAX_BPC - bpc),
|
||||
comp->regs + DISP_DITHER_16);
|
||||
writel(DISP_DITHERING, comp->regs + CFG);
|
||||
mtk_ddp_write(cmdq_pkt, 0, comp, DISP_DITHER_5);
|
||||
mtk_ddp_write(cmdq_pkt, 0, comp, DISP_DITHER_7);
|
||||
mtk_ddp_write(cmdq_pkt,
|
||||
DITHER_LSB_ERR_SHIFT_R(MTK_MAX_BPC - bpc) |
|
||||
DITHER_ADD_LSHIFT_R(MTK_MAX_BPC - bpc) |
|
||||
DITHER_NEW_BIT_MODE,
|
||||
comp, DISP_DITHER_15);
|
||||
mtk_ddp_write(cmdq_pkt,
|
||||
DITHER_LSB_ERR_SHIFT_B(MTK_MAX_BPC - bpc) |
|
||||
DITHER_ADD_LSHIFT_B(MTK_MAX_BPC - bpc) |
|
||||
DITHER_LSB_ERR_SHIFT_G(MTK_MAX_BPC - bpc) |
|
||||
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,
|
||||
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);
|
||||
writel(OD_RELAYMODE, comp->regs + DISP_OD_CFG);
|
||||
mtk_dither_set(comp, bpc, DISP_OD_CFG);
|
||||
mtk_ddp_write(cmdq_pkt, w << 16 | h, comp, DISP_OD_SIZE);
|
||||
mtk_ddp_write(cmdq_pkt, OD_RELAYMODE, comp, DISP_OD_CFG);
|
||||
mtk_dither_set(comp, bpc, DISP_OD_CFG, cmdq_pkt);
|
||||
}
|
||||
|
||||
static void mtk_od_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,
|
||||
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)
|
||||
|
@ -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,
|
||||
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);
|
||||
writel(CCORR_RELAY_MODE, comp->regs + DISP_CCORR_CFG);
|
||||
mtk_ddp_write(cmdq_pkt, h << 16 | w, comp, DISP_CCORR_SIZE);
|
||||
mtk_ddp_write(cmdq_pkt, CCORR_ENGINE_EN, comp, DISP_CCORR_CFG);
|
||||
}
|
||||
|
||||
static void mtk_ccorr_start(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);
|
||||
}
|
||||
|
||||
/* 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,
|
||||
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);
|
||||
writel(DITHER_RELAY_MODE, comp->regs + DISP_DITHER_CFG);
|
||||
mtk_ddp_write(cmdq_pkt, h << 16 | w, comp, DISP_DITHER_SIZE);
|
||||
mtk_ddp_write(cmdq_pkt, DITHER_RELAY_MODE, comp, DISP_DITHER_CFG);
|
||||
}
|
||||
|
||||
static void mtk_dither_start(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,
|
||||
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_dither_set(comp, bpc, DISP_GAMMA_CFG);
|
||||
mtk_ddp_write(cmdq_pkt, h << 16 | w, comp, DISP_GAMMA_SIZE);
|
||||
mtk_dither_set(comp, bpc, DISP_GAMMA_CFG, cmdq_pkt);
|
||||
}
|
||||
|
||||
static void mtk_gamma_start(struct mtk_ddp_comp *comp)
|
||||
|
@ -223,6 +330,7 @@ static const struct mtk_ddp_comp_funcs ddp_ccorr = {
|
|||
.config = mtk_ccorr_config,
|
||||
.start = mtk_ccorr_start,
|
||||
.stop = mtk_ccorr_stop,
|
||||
.ctm_set = mtk_ccorr_ctm_set,
|
||||
};
|
||||
|
||||
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,
|
|||
enum mtk_ddp_comp_type type;
|
||||
struct device_node *larb_node;
|
||||
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)
|
||||
return -EINVAL;
|
||||
|
@ -379,6 +492,19 @@ int mtk_ddp_comp_init(struct device *dev, struct device_node *node,
|
|||
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
|
@ -69,27 +69,29 @@ enum mtk_ddp_comp_id {
|
|||
};
|
||||
|
||||
struct mtk_ddp_comp;
|
||||
|
||||
struct cmdq_pkt;
|
||||
struct mtk_ddp_comp_funcs {
|
||||
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 (*stop)(struct mtk_ddp_comp *comp);
|
||||
void (*enable_vblank)(struct mtk_ddp_comp *comp, struct drm_crtc *crtc);
|
||||
void (*disable_vblank)(struct mtk_ddp_comp *comp);
|
||||
unsigned int (*supported_rotations)(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,
|
||||
unsigned int idx,
|
||||
struct mtk_plane_state *state);
|
||||
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,
|
||||
struct drm_crtc_state *state);
|
||||
void (*bgclr_in_on)(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 {
|
||||
|
@ -99,14 +101,17 @@ struct mtk_ddp_comp {
|
|||
struct device *larb_dev;
|
||||
enum mtk_ddp_comp_id id;
|
||||
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,
|
||||
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)
|
||||
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)
|
||||
|
@ -151,20 +156,6 @@ static inline unsigned int mtk_ddp_comp_layer_nr(struct mtk_ddp_comp *comp)
|
|||
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,
|
||||
unsigned int idx,
|
||||
struct mtk_plane_state *state)
|
||||
|
@ -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,
|
||||
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)
|
||||
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,
|
||||
|
@ -201,6 +193,13 @@ static inline void mtk_ddp_comp_bgclr_in_off(struct mtk_ddp_comp *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,
|
||||
enum mtk_ddp_comp_type comp_type);
|
||||
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);
|
||||
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,
|
||||
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 */
|
||||
|
|
|
@ -37,84 +37,9 @@
|
|||
#define DRIVER_MAJOR 1
|
||||
#define DRIVER_MINOR 0
|
||||
|
||||
static void mtk_atomic_schedule(struct mtk_drm_private *private,
|
||||
struct drm_atomic_state *state)
|
||||
{
|
||||
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 const struct drm_mode_config_helper_funcs mtk_drm_mode_config_helpers = {
|
||||
.atomic_commit_tail = drm_atomic_helper_commit_tail_rpm,
|
||||
};
|
||||
|
||||
static struct drm_framebuffer *
|
||||
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 = {
|
||||
.fb_create = mtk_drm_mode_fb_create,
|
||||
.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[] = {
|
||||
|
@ -250,6 +175,7 @@ static int mtk_drm_kms_init(struct drm_device *drm)
|
|||
drm->mode_config.max_width = 4096;
|
||||
drm->mode_config.max_height = 4096;
|
||||
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);
|
||||
if (ret)
|
||||
|
@ -509,8 +435,6 @@ static int mtk_drm_probe(struct platform_device *pdev)
|
|||
if (!private)
|
||||
return -ENOMEM;
|
||||
|
||||
mutex_init(&private->commit.lock);
|
||||
INIT_WORK(&private->commit.work, mtk_atomic_work);
|
||||
private->data = of_device_get_match_data(dev);
|
||||
|
||||
mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
|
||||
|
|
|
@ -43,13 +43,6 @@ struct mtk_drm_private {
|
|||
struct device_node *comp_node[DDP_COMPONENT_ID_MAX];
|
||||
struct mtk_ddp_comp *ddp_comp[DDP_COMPONENT_ID_MAX];
|
||||
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;
|
||||
|
||||
bool dma_parms_allocated;
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
#include <drm/drm_atomic.h>
|
||||
#include <drm/drm_atomic_helper.h>
|
||||
#include <drm/drm_fourcc.h>
|
||||
#include <drm/drm_atomic_uapi.h>
|
||||
#include <drm/drm_plane_helper.h>
|
||||
#include <drm/drm_gem_framebuffer_helper.h>
|
||||
|
||||
|
@ -75,6 +76,50 @@ static void mtk_drm_plane_destroy_state(struct drm_plane *plane,
|
|||
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 = {
|
||||
.update_plane = drm_atomic_helper_update_plane,
|
||||
.disable_plane = drm_atomic_helper_disable_plane,
|
||||
|
@ -163,6 +208,8 @@ static const struct drm_plane_helper_funcs mtk_plane_helper_funcs = {
|
|||
.atomic_check = mtk_plane_atomic_check,
|
||||
.atomic_update = mtk_plane_atomic_update,
|
||||
.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,
|
||||
|
|
|
@ -22,6 +22,8 @@ struct mtk_plane_pending_state {
|
|||
unsigned int height;
|
||||
unsigned int rotation;
|
||||
bool dirty;
|
||||
bool async_dirty;
|
||||
bool async_config;
|
||||
};
|
||||
|
||||
struct mtk_plane_state {
|
||||
|
|
|
@ -9,12 +9,54 @@
|
|||
#include <linux/mailbox_controller.h>
|
||||
#include <linux/soc/mediatek/mtk-cmdq.h>
|
||||
|
||||
#define CMDQ_ARG_A_WRITE_MASK 0xffff
|
||||
#define CMDQ_WRITE_ENABLE_MASK BIT(0)
|
||||
#define CMDQ_POLL_ENABLE_MASK BIT(0)
|
||||
#define CMDQ_EOC_IRQ_EN BIT(0)
|
||||
#define CMDQ_EOC_CMD ((u64)((CMDQ_CODE_EOC << CMDQ_OP_CODE_SHIFT)) \
|
||||
<< 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)
|
||||
{
|
||||
struct cmdq_client *client = from_timer(client, t, timer);
|
||||
|
@ -110,10 +152,10 @@ void cmdq_pkt_destroy(struct cmdq_pkt *pkt)
|
|||
}
|
||||
EXPORT_SYMBOL(cmdq_pkt_destroy);
|
||||
|
||||
static int cmdq_pkt_append_command(struct cmdq_pkt *pkt, enum cmdq_code code,
|
||||
u32 arg_a, u32 arg_b)
|
||||
static int cmdq_pkt_append_command(struct cmdq_pkt *pkt,
|
||||
struct cmdq_instruction inst)
|
||||
{
|
||||
u64 *cmd_ptr;
|
||||
struct cmdq_instruction *cmd_ptr;
|
||||
|
||||
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,
|
|||
__func__, (u32)pkt->buf_size);
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
return 0;
|
||||
|
@ -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)
|
||||
{
|
||||
u32 arg_a = (offset & CMDQ_ARG_A_WRITE_MASK) |
|
||||
(subsys << CMDQ_SUBSYS_SHIFT);
|
||||
struct cmdq_instruction inst;
|
||||
|
||||
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);
|
||||
|
||||
int cmdq_pkt_write_mask(struct cmdq_pkt *pkt, u8 subsys,
|
||||
u16 offset, u32 value, u32 mask)
|
||||
{
|
||||
u32 offset_mask = offset;
|
||||
int err = 0;
|
||||
struct cmdq_instruction inst = { {0} };
|
||||
u16 offset_mask = offset;
|
||||
int err;
|
||||
|
||||
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;
|
||||
}
|
||||
err |= cmdq_pkt_write(pkt, subsys, offset_mask, value);
|
||||
err = cmdq_pkt_write(pkt, subsys, offset_mask, value);
|
||||
|
||||
return err;
|
||||
}
|
||||
|
@ -163,43 +216,85 @@ EXPORT_SYMBOL(cmdq_pkt_write_mask);
|
|||
|
||||
int cmdq_pkt_wfe(struct cmdq_pkt *pkt, u16 event)
|
||||
{
|
||||
u32 arg_b;
|
||||
struct cmdq_instruction inst = { {0} };
|
||||
|
||||
if (event >= CMDQ_MAX_EVENT)
|
||||
return -EINVAL;
|
||||
|
||||
/*
|
||||
* 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
|
||||
*/
|
||||
arg_b = CMDQ_WFE_UPDATE | CMDQ_WFE_WAIT | CMDQ_WFE_WAIT_VALUE;
|
||||
inst.op = CMDQ_CODE_WFE;
|
||||
inst.value = CMDQ_WFE_OPTION;
|
||||
inst.event = event;
|
||||
|
||||
return cmdq_pkt_append_command(pkt, CMDQ_CODE_WFE, event, arg_b);
|
||||
return cmdq_pkt_append_command(pkt, inst);
|
||||
}
|
||||
EXPORT_SYMBOL(cmdq_pkt_wfe);
|
||||
|
||||
int cmdq_pkt_clear_event(struct cmdq_pkt *pkt, u16 event)
|
||||
{
|
||||
struct cmdq_instruction inst = { {0} };
|
||||
|
||||
if (event >= CMDQ_MAX_EVENT)
|
||||
return -EINVAL;
|
||||
|
||||
return cmdq_pkt_append_command(pkt, CMDQ_CODE_WFE, event,
|
||||
CMDQ_WFE_UPDATE);
|
||||
inst.op = CMDQ_CODE_WFE;
|
||||
inst.value = CMDQ_WFE_UPDATE;
|
||||
inst.event = event;
|
||||
|
||||
return cmdq_pkt_append_command(pkt, inst);
|
||||
}
|
||||
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)
|
||||
{
|
||||
struct cmdq_instruction inst = { {0} };
|
||||
int err;
|
||||
|
||||
/* 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 */
|
||||
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;
|
||||
}
|
||||
|
|
|
@ -20,6 +20,16 @@
|
|||
#define CMDQ_WFE_WAIT BIT(15)
|
||||
#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 */
|
||||
#define CMDQ_MAX_EVENT 0x3ff
|
||||
|
||||
|
@ -45,6 +55,7 @@
|
|||
enum cmdq_code {
|
||||
CMDQ_CODE_MASK = 0x02,
|
||||
CMDQ_CODE_WRITE = 0x04,
|
||||
CMDQ_CODE_POLL = 0x08,
|
||||
CMDQ_CODE_JUMP = 0x10,
|
||||
CMDQ_CODE_WFE = 0x20,
|
||||
CMDQ_CODE_EOC = 0x40,
|
||||
|
|
|
@ -15,6 +15,12 @@
|
|||
|
||||
struct cmdq_pkt;
|
||||
|
||||
struct cmdq_client_reg {
|
||||
u8 subsys;
|
||||
u16 offset;
|
||||
u16 size;
|
||||
};
|
||||
|
||||
struct cmdq_client {
|
||||
spinlock_t lock;
|
||||
u32 pkt_cnt;
|
||||
|
@ -24,6 +30,21 @@ struct cmdq_client {
|
|||
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
|
||||
* @dev: device of CMDQ mailbox client
|
||||
|
@ -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);
|
||||
|
||||
/**
|
||||
* 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
|
||||
* packet and call back at the end of done packet
|
||||
|
|
Loading…
Reference in New Issue