Skip to content

Commit d243907

Browse files
AngeloGioacchino Del RegnoChun-Kuang Hu
authored andcommitted
drm/mediatek: gamma: Support SoC specific LUT size
Newer SoCs support a bigger Gamma LUT table: wire up a callback to retrieve the correct LUT size for each different Gamma IP. Co-developed-by: Jason-JH.Lin <[email protected]> Signed-off-by: Jason-JH.Lin <[email protected]> [Angelo: Rewritten commit message/description + porting] 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 aa5fb24 commit d243907

File tree

7 files changed

+54
-7
lines changed

7 files changed

+54
-7
lines changed

drivers/gpu/drm/mediatek/mtk_disp_aal.c

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
#define AAL_EN BIT(0)
2020
#define DISP_AAL_SIZE 0x0030
2121
#define DISP_AAL_OUTPUT_SIZE 0x04d8
22-
22+
#define DISP_AAL_LUT_SIZE 512
2323

2424
struct mtk_disp_aal_data {
2525
bool has_gamma;
@@ -56,6 +56,21 @@ void mtk_aal_config(struct device *dev, unsigned int w,
5656
mtk_ddp_write(cmdq_pkt, w << 16 | h, &aal->cmdq_reg, aal->regs, DISP_AAL_OUTPUT_SIZE);
5757
}
5858

59+
/**
60+
* mtk_aal_gamma_get_lut_size() - Get gamma LUT size for AAL
61+
* @dev: Pointer to struct device
62+
*
63+
* Return: 0 if gamma control not supported in AAL or gamma LUT size
64+
*/
65+
unsigned int mtk_aal_gamma_get_lut_size(struct device *dev)
66+
{
67+
struct mtk_disp_aal *aal = dev_get_drvdata(dev);
68+
69+
if (aal->data && aal->data->has_gamma)
70+
return DISP_AAL_LUT_SIZE;
71+
return 0;
72+
}
73+
5974
void mtk_aal_gamma_set(struct device *dev, struct drm_crtc_state *state)
6075
{
6176
struct mtk_disp_aal *aal = dev_get_drvdata(dev);

drivers/gpu/drm/mediatek/mtk_disp_drv.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ void mtk_aal_clk_disable(struct device *dev);
1717
void mtk_aal_config(struct device *dev, unsigned int w,
1818
unsigned int h, unsigned int vrefresh,
1919
unsigned int bpc, struct cmdq_pkt *cmdq_pkt);
20+
unsigned int mtk_aal_gamma_get_lut_size(struct device *dev);
2021
void mtk_aal_gamma_set(struct device *dev, struct drm_crtc_state *state);
2122
void mtk_aal_start(struct device *dev);
2223
void mtk_aal_stop(struct device *dev);
@@ -55,6 +56,7 @@ void mtk_gamma_clk_disable(struct device *dev);
5556
void mtk_gamma_config(struct device *dev, unsigned int w,
5657
unsigned int h, unsigned int vrefresh,
5758
unsigned int bpc, struct cmdq_pkt *cmdq_pkt);
59+
unsigned int mtk_gamma_get_lut_size(struct device *dev);
5860
void mtk_gamma_set(struct device *dev, struct drm_crtc_state *state);
5961
void mtk_gamma_set_common(struct device *dev, void __iomem *regs, struct drm_crtc_state *state);
6062
void mtk_gamma_start(struct device *dev);

drivers/gpu/drm/mediatek/mtk_disp_gamma.c

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
struct mtk_disp_gamma_data {
2929
bool has_dither;
3030
bool lut_diff;
31+
u16 lut_size;
3132
};
3233

3334
/*
@@ -54,13 +55,23 @@ void mtk_gamma_clk_disable(struct device *dev)
5455
clk_disable_unprepare(gamma->clk);
5556
}
5657

58+
unsigned int mtk_gamma_get_lut_size(struct device *dev)
59+
{
60+
struct mtk_disp_gamma *gamma = dev_get_drvdata(dev);
61+
62+
if (gamma && gamma->data)
63+
return gamma->data->lut_size;
64+
return 0;
65+
}
66+
5767
void mtk_gamma_set_common(struct device *dev, void __iomem *regs, struct drm_crtc_state *state)
5868
{
5969
struct mtk_disp_gamma *gamma;
6070
unsigned int i, reg;
6171
struct drm_color_lut *lut;
6272
void __iomem *lut_base;
6373
bool lut_diff;
74+
u16 lut_size;
6475
u32 word;
6576
u32 diff[3] = {0};
6677

@@ -71,17 +82,20 @@ void mtk_gamma_set_common(struct device *dev, void __iomem *regs, struct drm_crt
7182
/* If we're called from AAL, dev is NULL */
7283
gamma = dev ? dev_get_drvdata(dev) : NULL;
7384

74-
if (gamma && gamma->data)
85+
if (gamma && gamma->data) {
7586
lut_diff = gamma->data->lut_diff;
76-
else
87+
lut_size = gamma->data->lut_size;
88+
} else {
7789
lut_diff = false;
90+
lut_size = 512;
91+
}
7892

7993
reg = readl(regs + DISP_GAMMA_CFG);
8094
reg = reg | GAMMA_LUT_EN;
8195
writel(reg, regs + DISP_GAMMA_CFG);
8296
lut_base = regs + DISP_GAMMA_LUT;
8397
lut = (struct drm_color_lut *)state->gamma_lut->data;
84-
for (i = 0; i < MTK_LUT_SIZE; i++) {
98+
for (i = 0; i < lut_size; i++) {
8599
if (!lut_diff || (i % 2 == 0)) {
86100
word = (((lut[i].red >> 6) & LUT_10BIT_MASK) << 20) +
87101
(((lut[i].green >> 6) & LUT_10BIT_MASK) << 10) +
@@ -196,10 +210,12 @@ static void mtk_disp_gamma_remove(struct platform_device *pdev)
196210

197211
static const struct mtk_disp_gamma_data mt8173_gamma_driver_data = {
198212
.has_dither = true,
213+
.lut_size = 512,
199214
};
200215

201216
static const struct mtk_disp_gamma_data mt8183_gamma_driver_data = {
202217
.lut_diff = true,
218+
.lut_size = 512,
203219
};
204220

205221
static const struct of_device_id mtk_disp_gamma_driver_dt_match[] = {

drivers/gpu/drm/mediatek/mtk_drm_crtc.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1002,8 +1002,12 @@ int mtk_drm_crtc_create(struct drm_device *drm_dev,
10021002
mtk_crtc->ddp_comp[i] = comp;
10031003

10041004
if (comp->funcs) {
1005-
if (comp->funcs->gamma_set)
1006-
gamma_lut_size = MTK_LUT_SIZE;
1005+
if (comp->funcs->gamma_set && comp->funcs->gamma_get_lut_size) {
1006+
unsigned int lut_sz = mtk_ddp_gamma_get_lut_size(comp);
1007+
1008+
if (lut_sz)
1009+
gamma_lut_size = lut_sz;
1010+
}
10071011

10081012
if (comp->funcs->ctm_set)
10091013
has_ctm = true;

drivers/gpu/drm/mediatek/mtk_drm_crtc.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
#include "mtk_drm_drv.h"
1212
#include "mtk_drm_plane.h"
1313

14-
#define MTK_LUT_SIZE 512
1514
#define MTK_MAX_BPC 10
1615
#define MTK_MIN_BPC 3
1716

drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,7 @@ static void mtk_ufoe_start(struct device *dev)
271271
static const struct mtk_ddp_comp_funcs ddp_aal = {
272272
.clk_enable = mtk_aal_clk_enable,
273273
.clk_disable = mtk_aal_clk_disable,
274+
.gamma_get_lut_size = mtk_aal_gamma_get_lut_size,
274275
.gamma_set = mtk_aal_gamma_set,
275276
.config = mtk_aal_config,
276277
.start = mtk_aal_start,
@@ -324,6 +325,7 @@ static const struct mtk_ddp_comp_funcs ddp_dsi = {
324325
static const struct mtk_ddp_comp_funcs ddp_gamma = {
325326
.clk_enable = mtk_gamma_clk_enable,
326327
.clk_disable = mtk_gamma_clk_disable,
328+
.gamma_get_lut_size = mtk_gamma_get_lut_size,
327329
.gamma_set = mtk_gamma_set,
328330
.config = mtk_gamma_config,
329331
.start = mtk_gamma_start,

drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ struct mtk_ddp_comp_funcs {
6767
void (*layer_config)(struct device *dev, unsigned int idx,
6868
struct mtk_plane_state *state,
6969
struct cmdq_pkt *cmdq_pkt);
70+
unsigned int (*gamma_get_lut_size)(struct device *dev);
7071
void (*gamma_set)(struct device *dev,
7172
struct drm_crtc_state *state);
7273
void (*bgclr_in_on)(struct device *dev);
@@ -188,6 +189,14 @@ static inline void mtk_ddp_comp_layer_config(struct mtk_ddp_comp *comp,
188189
comp->funcs->layer_config(comp->dev, idx, state, cmdq_pkt);
189190
}
190191

192+
static inline unsigned int mtk_ddp_gamma_get_lut_size(struct mtk_ddp_comp *comp)
193+
{
194+
if (comp->funcs && comp->funcs->gamma_get_lut_size)
195+
return comp->funcs->gamma_get_lut_size(comp->dev);
196+
197+
return 0;
198+
}
199+
191200
static inline void mtk_ddp_gamma_set(struct mtk_ddp_comp *comp,
192201
struct drm_crtc_state *state)
193202
{

0 commit comments

Comments
 (0)