3
3
* Copyright (c) 2021 MediaTek Inc.
4
4
*/
5
5
6
+ #include <linux/bitfield.h>
6
7
#include <linux/clk.h>
7
8
#include <linux/component.h>
8
9
#include <linux/module.h>
21
22
#define GAMMA_LUT_EN BIT(1)
22
23
#define GAMMA_DITHERING BIT(2)
23
24
#define DISP_GAMMA_SIZE 0x0030
25
+ #define DISP_GAMMA_SIZE_HSIZE GENMASK(28, 16)
26
+ #define DISP_GAMMA_SIZE_VSIZE GENMASK(12, 0)
24
27
#define DISP_GAMMA_LUT 0x0700
25
28
29
+ #define DISP_GAMMA_LUT_10BIT_R GENMASK(29, 20)
30
+ #define DISP_GAMMA_LUT_10BIT_G GENMASK(19, 10)
31
+ #define DISP_GAMMA_LUT_10BIT_B GENMASK(9, 0)
32
+
26
33
struct mtk_disp_gamma_data {
27
34
bool has_dither ;
28
35
bool lut_diff ;
@@ -97,9 +104,9 @@ void mtk_gamma_set_common(struct device *dev, void __iomem *regs, struct drm_crt
97
104
hwlut .blue = drm_color_lut_extract (lut [i ].blue , 10 );
98
105
99
106
if (!lut_diff || (i % 2 == 0 )) {
100
- word = ( hwlut .red << 20 ) +
101
- ( hwlut .green << 10 ) +
102
- hwlut .red ;
107
+ word = FIELD_PREP ( DISP_GAMMA_LUT_10BIT_R , hwlut .red );
108
+ word |= FIELD_PREP ( DISP_GAMMA_LUT_10BIT_G , hwlut .green );
109
+ word |= FIELD_PREP ( DISP_GAMMA_LUT_10BIT_B , hwlut .blue ) ;
103
110
} else {
104
111
diff .red = lut [i ].red - lut [i - 1 ].red ;
105
112
diff .red = drm_color_lut_extract (diff .red , 10 );
@@ -110,17 +117,17 @@ void mtk_gamma_set_common(struct device *dev, void __iomem *regs, struct drm_crt
110
117
diff .blue = lut [i ].blue - lut [i - 1 ].blue ;
111
118
diff .blue = drm_color_lut_extract (diff .blue , 10 );
112
119
113
- word = ( diff .blue << 20 ) +
114
- ( diff .green << 10 ) +
115
- diff .red ;
120
+ word = FIELD_PREP ( DISP_GAMMA_LUT_10BIT_R , diff .red );
121
+ word |= FIELD_PREP ( DISP_GAMMA_LUT_10BIT_G , diff .green );
122
+ word |= FIELD_PREP ( DISP_GAMMA_LUT_10BIT_B , diff .blue ) ;
116
123
}
117
124
writel (word , lut_base + i * 4 );
118
125
}
119
126
120
127
cfg_val = readl (regs + DISP_GAMMA_CFG );
121
128
122
129
/* Enable the gamma table */
123
- cfg_val |= GAMMA_LUT_EN ;
130
+ cfg_val |= FIELD_PREP ( GAMMA_LUT_EN , 1 ) ;
124
131
125
132
writel (cfg_val , regs + DISP_GAMMA_CFG );
126
133
}
@@ -137,9 +144,12 @@ void mtk_gamma_config(struct device *dev, unsigned int w,
137
144
unsigned int bpc , struct cmdq_pkt * cmdq_pkt )
138
145
{
139
146
struct mtk_disp_gamma * gamma = dev_get_drvdata (dev );
147
+ u32 sz ;
148
+
149
+ sz = FIELD_PREP (DISP_GAMMA_SIZE_HSIZE , w );
150
+ sz |= FIELD_PREP (DISP_GAMMA_SIZE_VSIZE , h );
140
151
141
- mtk_ddp_write (cmdq_pkt , h << 16 | w , & gamma -> cmdq_reg , gamma -> regs ,
142
- DISP_GAMMA_SIZE );
152
+ mtk_ddp_write (cmdq_pkt , sz , & gamma -> cmdq_reg , gamma -> regs , DISP_GAMMA_SIZE );
143
153
if (gamma -> data && gamma -> data -> has_dither )
144
154
mtk_dither_set_common (gamma -> regs , & gamma -> cmdq_reg , bpc ,
145
155
DISP_GAMMA_CFG , GAMMA_DITHERING , cmdq_pkt );
0 commit comments