Skip to content

Commit 4708b01

Browse files
AngeloGioacchino Del RegnoChun-Kuang Hu
authored andcommitted
drm/mediatek: gamma: Support multi-bank gamma LUT
Newer Gamma IP have got multiple LUT banks: support specifying the size of the LUT banks and handle bank-switching before programming the LUT in mtk_gamma_set_common() in preparation for adding support for MT8195 and newer SoCs. Suggested-by: Jason-JH.Lin <[email protected]> [Angelo: Refactored original commit] 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 a6b39cd commit 4708b01

File tree

3 files changed

+83
-29
lines changed

3 files changed

+83
-29
lines changed

drivers/gpu/drm/mediatek/mtk_disp_aal.c

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,17 @@
1717

1818
#define DISP_AAL_EN 0x0000
1919
#define AAL_EN BIT(0)
20+
#define DISP_AAL_CFG 0x0020
21+
#define AAL_GAMMA_LUT_EN BIT(1)
2022
#define DISP_AAL_SIZE 0x0030
2123
#define DISP_AAL_SIZE_HSIZE GENMASK(28, 16)
2224
#define DISP_AAL_SIZE_VSIZE GENMASK(12, 0)
2325
#define DISP_AAL_OUTPUT_SIZE 0x04d8
26+
#define DISP_AAL_GAMMA_LUT 0x0700
27+
#define DISP_AAL_GAMMA_LUT_R GENMASK(29, 20)
28+
#define DISP_AAL_GAMMA_LUT_G GENMASK(19, 10)
29+
#define DISP_AAL_GAMMA_LUT_B GENMASK(9, 0)
30+
#define DISP_AAL_LUT_BITS 10
2431
#define DISP_AAL_LUT_SIZE 512
2532

2633
struct mtk_disp_aal_data {
@@ -80,9 +87,39 @@ unsigned int mtk_aal_gamma_get_lut_size(struct device *dev)
8087
void mtk_aal_gamma_set(struct device *dev, struct drm_crtc_state *state)
8188
{
8289
struct mtk_disp_aal *aal = dev_get_drvdata(dev);
90+
struct drm_color_lut *lut;
91+
unsigned int i;
92+
u32 cfg_val;
93+
94+
/* If gamma is not supported in AAL, go out immediately */
95+
if (!(aal->data && aal->data->has_gamma))
96+
return;
97+
98+
/* Also, if there's no gamma lut there's nothing to do here. */
99+
if (!state->gamma_lut)
100+
return;
101+
102+
lut = (struct drm_color_lut *)state->gamma_lut->data;
103+
for (i = 0; i < DISP_AAL_LUT_SIZE; i++) {
104+
struct drm_color_lut hwlut = {
105+
.red = drm_color_lut_extract(lut[i].red, DISP_AAL_LUT_BITS),
106+
.green = drm_color_lut_extract(lut[i].green, DISP_AAL_LUT_BITS),
107+
.blue = drm_color_lut_extract(lut[i].blue, DISP_AAL_LUT_BITS)
108+
};
109+
u32 word;
110+
111+
word = FIELD_PREP(DISP_AAL_GAMMA_LUT_R, hwlut.red);
112+
word |= FIELD_PREP(DISP_AAL_GAMMA_LUT_G, hwlut.green);
113+
word |= FIELD_PREP(DISP_AAL_GAMMA_LUT_B, hwlut.blue);
114+
writel(word, aal->regs + DISP_AAL_GAMMA_LUT + i * 4);
115+
}
83116

84-
if (aal->data && aal->data->has_gamma)
85-
mtk_gamma_set_common(NULL, aal->regs, state);
117+
cfg_val = readl(aal->regs + DISP_AAL_CFG);
118+
119+
/* Enable the gamma table */
120+
cfg_val |= FIELD_PREP(AAL_GAMMA_LUT_EN, 1);
121+
122+
writel(cfg_val, aal->regs + DISP_AAL_CFG);
86123
}
87124

88125
void mtk_aal_start(struct device *dev)

drivers/gpu/drm/mediatek/mtk_disp_drv.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ void mtk_gamma_config(struct device *dev, unsigned int w,
5858
unsigned int bpc, struct cmdq_pkt *cmdq_pkt);
5959
unsigned int mtk_gamma_get_lut_size(struct device *dev);
6060
void mtk_gamma_set(struct device *dev, struct drm_crtc_state *state);
61-
void mtk_gamma_set_common(struct device *dev, void __iomem *regs, struct drm_crtc_state *state);
6261
void mtk_gamma_start(struct device *dev);
6362
void mtk_gamma_stop(struct device *dev);
6463

drivers/gpu/drm/mediatek/mtk_disp_gamma.c

Lines changed: 44 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
#define DISP_GAMMA_SIZE 0x0030
2525
#define DISP_GAMMA_SIZE_HSIZE GENMASK(28, 16)
2626
#define DISP_GAMMA_SIZE_VSIZE GENMASK(12, 0)
27+
#define DISP_GAMMA_BANK 0x0100
28+
#define DISP_GAMMA_BANK_BANK GENMASK(1, 0)
2729
#define DISP_GAMMA_LUT 0x0700
2830

2931
#define DISP_GAMMA_LUT_10BIT_R GENMASK(29, 20)
@@ -33,6 +35,7 @@
3335
struct mtk_disp_gamma_data {
3436
bool has_dither;
3537
bool lut_diff;
38+
u16 lut_bank_size;
3639
u16 lut_size;
3740
};
3841

@@ -75,40 +78,53 @@ void mtk_gamma_set(struct device *dev, struct drm_crtc_state *state)
7578
unsigned int i;
7679
struct drm_color_lut *lut;
7780
void __iomem *lut_base;
78-
u32 cfg_val, word;
81+
u32 cfg_val, lbank_val, word;
82+
int cur_bank, num_lut_banks;
7983

8084
/* If there's no gamma lut there's nothing to do here. */
8185
if (!state->gamma_lut)
8286
return;
8387

88+
num_lut_banks = gamma->data->lut_size / gamma->data->lut_bank_size;
8489
lut_base = gamma->regs + DISP_GAMMA_LUT;
8590
lut = (struct drm_color_lut *)state->gamma_lut->data;
86-
for (i = 0; i < gamma->data->lut_size; i++) {
87-
struct drm_color_lut diff, hwlut;
88-
89-
hwlut.red = drm_color_lut_extract(lut[i].red, 10);
90-
hwlut.green = drm_color_lut_extract(lut[i].green, 10);
91-
hwlut.blue = drm_color_lut_extract(lut[i].blue, 10);
92-
93-
if (!gamma->data->lut_diff || (i % 2 == 0)) {
94-
word = FIELD_PREP(DISP_GAMMA_LUT_10BIT_R, hwlut.red);
95-
word |= FIELD_PREP(DISP_GAMMA_LUT_10BIT_G, hwlut.green);
96-
word |= FIELD_PREP(DISP_GAMMA_LUT_10BIT_B, hwlut.blue);
97-
} else {
98-
diff.red = lut[i].red - lut[i - 1].red;
99-
diff.red = drm_color_lut_extract(diff.red, 10);
100-
101-
diff.green = lut[i].green - lut[i - 1].green;
102-
diff.green = drm_color_lut_extract(diff.green, 10);
103-
104-
diff.blue = lut[i].blue - lut[i - 1].blue;
105-
diff.blue = drm_color_lut_extract(diff.blue, 10);
106-
107-
word = FIELD_PREP(DISP_GAMMA_LUT_10BIT_R, diff.red);
108-
word |= FIELD_PREP(DISP_GAMMA_LUT_10BIT_G, diff.green);
109-
word |= FIELD_PREP(DISP_GAMMA_LUT_10BIT_B, diff.blue);
91+
92+
for (cur_bank = 0; cur_bank < num_lut_banks; cur_bank++) {
93+
94+
/* Switch gamma bank and set data mode before writing LUT */
95+
if (num_lut_banks > 1) {
96+
lbank_val = FIELD_PREP(DISP_GAMMA_BANK_BANK, cur_bank);
97+
writel(lbank_val, gamma->regs + DISP_GAMMA_BANK);
98+
}
99+
100+
for (i = 0; i < gamma->data->lut_bank_size; i++) {
101+
int n = cur_bank * gamma->data->lut_bank_size + i;
102+
struct drm_color_lut diff, hwlut;
103+
104+
hwlut.red = drm_color_lut_extract(lut[n].red, 10);
105+
hwlut.green = drm_color_lut_extract(lut[n].green, 10);
106+
hwlut.blue = drm_color_lut_extract(lut[n].blue, 10);
107+
108+
if (!gamma->data->lut_diff || (i % 2 == 0)) {
109+
word = FIELD_PREP(DISP_GAMMA_LUT_10BIT_R, hwlut.red);
110+
word |= FIELD_PREP(DISP_GAMMA_LUT_10BIT_G, hwlut.green);
111+
word |= FIELD_PREP(DISP_GAMMA_LUT_10BIT_B, hwlut.blue);
112+
} else {
113+
diff.red = lut[n].red - lut[n - 1].red;
114+
diff.red = drm_color_lut_extract(diff.red, 10);
115+
116+
diff.green = lut[n].green - lut[n - 1].green;
117+
diff.green = drm_color_lut_extract(diff.green, 10);
118+
119+
diff.blue = lut[n].blue - lut[n - 1].blue;
120+
diff.blue = drm_color_lut_extract(diff.blue, 10);
121+
122+
word = FIELD_PREP(DISP_GAMMA_LUT_10BIT_R, diff.red);
123+
word |= FIELD_PREP(DISP_GAMMA_LUT_10BIT_G, diff.green);
124+
word |= FIELD_PREP(DISP_GAMMA_LUT_10BIT_B, diff.blue);
125+
}
126+
writel(word, lut_base + i * 4);
110127
}
111-
writel(word, lut_base + i * 4);
112128
}
113129

114130
cfg_val = readl(gamma->regs + DISP_GAMMA_CFG);
@@ -212,10 +228,12 @@ static void mtk_disp_gamma_remove(struct platform_device *pdev)
212228

213229
static const struct mtk_disp_gamma_data mt8173_gamma_driver_data = {
214230
.has_dither = true,
231+
.lut_bank_size = 512,
215232
.lut_size = 512,
216233
};
217234

218235
static const struct mtk_disp_gamma_data mt8183_gamma_driver_data = {
236+
.lut_bank_size = 512,
219237
.lut_diff = true,
220238
.lut_size = 512,
221239
};

0 commit comments

Comments
 (0)