Skip to content

Commit c18119d

Browse files
AngeloGioacchino Del RegnoChun-Kuang Hu
authored andcommitted
drm/mediatek: gamma: Improve and simplify HW LUT calculation
Use drm_color_lut_extract() to avoid open-coding the bits reduction calculations for each color channel and use a struct drm_color_lut to temporarily store the information instead of an array of u32. Also, slightly improve the precision of the HW LUT calculation in the LUT DIFF case by performing the subtractions on the 16-bits values and doing the 10 bits conversion later. 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 d243907 commit c18119d

File tree

1 file changed

+21
-13
lines changed

1 file changed

+21
-13
lines changed

drivers/gpu/drm/mediatek/mtk_disp_gamma.c

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@
2323
#define DISP_GAMMA_SIZE 0x0030
2424
#define DISP_GAMMA_LUT 0x0700
2525

26-
#define LUT_10BIT_MASK 0x03ff
27-
2826
struct mtk_disp_gamma_data {
2927
bool has_dither;
3028
bool lut_diff;
@@ -73,7 +71,6 @@ void mtk_gamma_set_common(struct device *dev, void __iomem *regs, struct drm_crt
7371
bool lut_diff;
7472
u16 lut_size;
7573
u32 word;
76-
u32 diff[3] = {0};
7774

7875
/* If there's no gamma lut there's nothing to do here. */
7976
if (!state->gamma_lut)
@@ -96,20 +93,31 @@ void mtk_gamma_set_common(struct device *dev, void __iomem *regs, struct drm_crt
9693
lut_base = regs + DISP_GAMMA_LUT;
9794
lut = (struct drm_color_lut *)state->gamma_lut->data;
9895
for (i = 0; i < lut_size; i++) {
96+
struct drm_color_lut diff, hwlut;
97+
98+
hwlut.red = drm_color_lut_extract(lut[i].red, 10);
99+
hwlut.green = drm_color_lut_extract(lut[i].green, 10);
100+
hwlut.blue = drm_color_lut_extract(lut[i].blue, 10);
101+
99102
if (!lut_diff || (i % 2 == 0)) {
100-
word = (((lut[i].red >> 6) & LUT_10BIT_MASK) << 20) +
101-
(((lut[i].green >> 6) & LUT_10BIT_MASK) << 10) +
102-
((lut[i].blue >> 6) & LUT_10BIT_MASK);
103+
word = (hwlut.red << 20) +
104+
(hwlut.green << 10) +
105+
hwlut.red;
103106
} else {
104-
diff[0] = (lut[i].red >> 6) - (lut[i - 1].red >> 6);
105-
diff[1] = (lut[i].green >> 6) - (lut[i - 1].green >> 6);
106-
diff[2] = (lut[i].blue >> 6) - (lut[i - 1].blue >> 6);
107+
diff.red = lut[i].red - lut[i - 1].red;
108+
diff.red = drm_color_lut_extract(diff.red, 10);
109+
110+
diff.green = lut[i].green - lut[i - 1].green;
111+
diff.green = drm_color_lut_extract(diff.green, 10);
112+
113+
diff.blue = lut[i].blue - lut[i - 1].blue;
114+
diff.blue = drm_color_lut_extract(diff.blue, 10);
107115

108-
word = ((diff[0] & LUT_10BIT_MASK) << 20) +
109-
((diff[1] & LUT_10BIT_MASK) << 10) +
110-
(diff[2] & LUT_10BIT_MASK);
116+
word = (diff.blue << 20) +
117+
(diff.green << 10) +
118+
diff.red;
111119
}
112-
writel(word, (lut_base + i * 4));
120+
writel(word, lut_base + i * 4);
113121
}
114122
}
115123

0 commit comments

Comments
 (0)