Skip to content

Commit 692e1a0

Browse files
AngeloGioacchino Del RegnoChun-Kuang Hu
authored andcommitted
drm/mediatek: gamma: Program gamma LUT type for descending or rising
All of the SoCs that don't have dithering control in the gamma IP have got a GAMMA_LUT_TYPE bit that tells to the IP if the LUT is "descending" (bit set) or "rising" (bit cleared): make sure to set it correctly after programming the LUT. Reviewed-by: Jason-JH.Lin <[email protected]> Reviewed-by: Alexandre Mergnat <[email protected]> Reviewed-by: CK Hu <[email protected]> Signed-off-by: AngeloGioacchino Del Regno <[email protected]> Link: https://patchwork.kernel.org/project/dri-devel/patch/[email protected]/ Signed-off-by: Chun-Kuang Hu <[email protected]>
1 parent 921e902 commit 692e1a0

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

drivers/gpu/drm/mediatek/mtk_disp_gamma.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#define GAMMA_RELAY_MODE BIT(0)
2323
#define GAMMA_LUT_EN BIT(1)
2424
#define GAMMA_DITHERING BIT(2)
25+
#define GAMMA_LUT_TYPE BIT(2)
2526
#define DISP_GAMMA_SIZE 0x0030
2627
#define DISP_GAMMA_SIZE_HSIZE GENMASK(28, 16)
2728
#define DISP_GAMMA_SIZE_VSIZE GENMASK(12, 0)
@@ -82,6 +83,17 @@ unsigned int mtk_gamma_get_lut_size(struct device *dev)
8283
return 0;
8384
}
8485

86+
static bool mtk_gamma_lut_is_descending(struct drm_color_lut *lut, u32 lut_size)
87+
{
88+
u64 first, last;
89+
int last_entry = lut_size - 1;
90+
91+
first = lut[0].red + lut[0].green + lut[0].blue;
92+
last = lut[last_entry].red + lut[last_entry].green + lut[last_entry].blue;
93+
94+
return !!(first > last);
95+
}
96+
8597
/*
8698
* SoCs supporting 12-bits LUTs are using a new register layout that does
8799
* always support (by HW) both 12-bits and 10-bits LUT but, on those, we
@@ -173,6 +185,14 @@ void mtk_gamma_set(struct device *dev, struct drm_crtc_state *state)
173185

174186
cfg_val = readl(gamma->regs + DISP_GAMMA_CFG);
175187

188+
if (!gamma->data->has_dither) {
189+
/* Descending or Rising LUT */
190+
if (mtk_gamma_lut_is_descending(lut, gamma->data->lut_size - 1))
191+
cfg_val |= FIELD_PREP(GAMMA_LUT_TYPE, 1);
192+
else
193+
cfg_val &= ~GAMMA_LUT_TYPE;
194+
}
195+
176196
/* Enable the gamma table */
177197
cfg_val |= FIELD_PREP(GAMMA_LUT_EN, 1);
178198

0 commit comments

Comments
 (0)