|
22 | 22 | #define GAMMA_RELAY_MODE BIT(0)
|
23 | 23 | #define GAMMA_LUT_EN BIT(1)
|
24 | 24 | #define GAMMA_DITHERING BIT(2)
|
| 25 | +#define GAMMA_LUT_TYPE BIT(2) |
25 | 26 | #define DISP_GAMMA_SIZE 0x0030
|
26 | 27 | #define DISP_GAMMA_SIZE_HSIZE GENMASK(28, 16)
|
27 | 28 | #define DISP_GAMMA_SIZE_VSIZE GENMASK(12, 0)
|
@@ -82,6 +83,17 @@ unsigned int mtk_gamma_get_lut_size(struct device *dev)
|
82 | 83 | return 0;
|
83 | 84 | }
|
84 | 85 |
|
| 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 | + |
85 | 97 | /*
|
86 | 98 | * SoCs supporting 12-bits LUTs are using a new register layout that does
|
87 | 99 | * 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)
|
173 | 185 |
|
174 | 186 | cfg_val = readl(gamma->regs + DISP_GAMMA_CFG);
|
175 | 187 |
|
| 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 | + |
176 | 196 | /* Enable the gamma table */
|
177 | 197 | cfg_val |= FIELD_PREP(GAMMA_LUT_EN, 1);
|
178 | 198 |
|
|
0 commit comments