Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

drm/mediatek: Add lut diff flag for new gamma hardware support

mt8183 gamma module usage is different with before soc,
gamma odd(index start from 0) lut value set to hardware
register should be
the difference of current lut value with last lut value.

for example, chrome os user space set lut
like this(only r chanel for example):
2 4 6 8 10 12.
1) mt8183 gamma driver should set the gamma lut to hardware
register like this:
2 [2] 6 [2] 10 [2]
the value with [] is the difference value
2)gamma hardware process display data with original lut

Link: https://patchwork.kernel.org/project/linux-mediatek/patch/20220428085829.15855-2-yongqiang.niu@mediatek.com/
Signed-off-by: Yongqiang Niu <yongqiang.niu@mediatek.com>
Signed-off-by: Yongqiang Niu <yongqiang.niu@mediatek.corp-partner.google.com>
Reviewed-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
Signed-off-by: Chun-Kuang Hu <chunkuang.hu@kernel.org>

authored by

Yongqiang Niu and committed by
Chun-Kuang Hu
ba99d08d 7112e0b0

+30 -8
+1 -1
drivers/gpu/drm/mediatek/mtk_disp_aal.c
··· 66 66 struct mtk_disp_aal *aal = dev_get_drvdata(dev); 67 67 68 68 if (aal->data && aal->data->has_gamma) 69 - mtk_gamma_set_common(aal->regs, state); 69 + mtk_gamma_set_common(aal->regs, state, false); 70 70 } 71 71 72 72 void mtk_aal_start(struct device *dev)
+1 -1
drivers/gpu/drm/mediatek/mtk_disp_drv.h
··· 51 51 unsigned int h, unsigned int vrefresh, 52 52 unsigned int bpc, struct cmdq_pkt *cmdq_pkt); 53 53 void mtk_gamma_set(struct device *dev, struct drm_crtc_state *state); 54 - void mtk_gamma_set_common(void __iomem *regs, struct drm_crtc_state *state); 54 + void mtk_gamma_set_common(void __iomem *regs, struct drm_crtc_state *state, bool lut_diff); 55 55 void mtk_gamma_start(struct device *dev); 56 56 void mtk_gamma_stop(struct device *dev); 57 57
+28 -6
drivers/gpu/drm/mediatek/mtk_disp_gamma.c
··· 27 27 28 28 struct mtk_disp_gamma_data { 29 29 bool has_dither; 30 + bool lut_diff; 30 31 }; 31 32 32 33 /* ··· 54 53 clk_disable_unprepare(gamma->clk); 55 54 } 56 55 57 - void mtk_gamma_set_common(void __iomem *regs, struct drm_crtc_state *state) 56 + void mtk_gamma_set_common(void __iomem *regs, struct drm_crtc_state *state, bool lut_diff) 58 57 { 59 58 unsigned int i, reg; 60 59 struct drm_color_lut *lut; 61 60 void __iomem *lut_base; 62 61 u32 word; 62 + u32 diff[3] = {0}; 63 63 64 64 if (state->gamma_lut) { 65 65 reg = readl(regs + DISP_GAMMA_CFG); ··· 69 67 lut_base = regs + DISP_GAMMA_LUT; 70 68 lut = (struct drm_color_lut *)state->gamma_lut->data; 71 69 for (i = 0; i < MTK_LUT_SIZE; i++) { 72 - word = (((lut[i].red >> 6) & LUT_10BIT_MASK) << 20) + 73 - (((lut[i].green >> 6) & LUT_10BIT_MASK) << 10) + 74 - ((lut[i].blue >> 6) & LUT_10BIT_MASK); 70 + 71 + if (!lut_diff || (i % 2 == 0)) { 72 + word = (((lut[i].red >> 6) & LUT_10BIT_MASK) << 20) + 73 + (((lut[i].green >> 6) & LUT_10BIT_MASK) << 10) + 74 + ((lut[i].blue >> 6) & LUT_10BIT_MASK); 75 + } else { 76 + diff[0] = (lut[i].red >> 6) - (lut[i - 1].red >> 6); 77 + diff[1] = (lut[i].green >> 6) - (lut[i - 1].green >> 6); 78 + diff[2] = (lut[i].blue >> 6) - (lut[i - 1].blue >> 6); 79 + 80 + word = ((diff[0] & LUT_10BIT_MASK) << 20) + 81 + ((diff[1] & LUT_10BIT_MASK) << 10) + 82 + (diff[2] & LUT_10BIT_MASK); 83 + } 75 84 writel(word, (lut_base + i * 4)); 76 85 } 77 86 } ··· 91 78 void mtk_gamma_set(struct device *dev, struct drm_crtc_state *state) 92 79 { 93 80 struct mtk_disp_gamma *gamma = dev_get_drvdata(dev); 81 + bool lut_diff = false; 94 82 95 - mtk_gamma_set_common(gamma->regs, state); 83 + if (gamma->data) 84 + lut_diff = gamma->data->lut_diff; 85 + 86 + mtk_gamma_set_common(gamma->regs, state, lut_diff); 96 87 } 97 88 98 89 void mtk_gamma_config(struct device *dev, unsigned int w, ··· 193 176 .has_dither = true, 194 177 }; 195 178 179 + static const struct mtk_disp_gamma_data mt8183_gamma_driver_data = { 180 + .lut_diff = true, 181 + }; 182 + 196 183 static const struct of_device_id mtk_disp_gamma_driver_dt_match[] = { 197 184 { .compatible = "mediatek,mt8173-disp-gamma", 198 185 .data = &mt8173_gamma_driver_data}, 199 - { .compatible = "mediatek,mt8183-disp-gamma"}, 186 + { .compatible = "mediatek,mt8183-disp-gamma", 187 + .data = &mt8183_gamma_driver_data}, 200 188 {}, 201 189 }; 202 190 MODULE_DEVICE_TABLE(of, mtk_disp_gamma_driver_dt_match);