37
37
#define CCORR_EN BIT(0)
38
38
#define DISP_CCORR_CFG 0x0020
39
39
#define CCORR_RELAY_MODE BIT(0)
40
+ #define CCORR_ENGINE_EN BIT(1)
41
+ #define CCORR_GAMMA_OFF BIT(2)
42
+ #define CCORR_WGAMUT_SRC_CLIP BIT(3)
40
43
#define DISP_CCORR_SIZE 0x0030
44
+ #define DISP_CCORR_COEF_0 0x0080
45
+ #define DISP_CCORR_COEF_1 0x0084
46
+ #define DISP_CCORR_COEF_2 0x0088
47
+ #define DISP_CCORR_COEF_3 0x008C
48
+ #define DISP_CCORR_COEF_4 0x0090
41
49
42
50
#define DISP_DITHER_EN 0x0000
43
51
#define DITHER_EN BIT(0)
@@ -188,7 +196,7 @@ static void mtk_ccorr_config(struct mtk_ddp_comp *comp, unsigned int w,
188
196
unsigned int bpc , struct cmdq_pkt * cmdq_pkt )
189
197
{
190
198
mtk_ddp_write (cmdq_pkt , h << 16 | w , comp , DISP_CCORR_SIZE );
191
- mtk_ddp_write (cmdq_pkt , CCORR_RELAY_MODE , comp , DISP_CCORR_CFG );
199
+ mtk_ddp_write (cmdq_pkt , CCORR_ENGINE_EN , comp , DISP_CCORR_CFG );
192
200
}
193
201
194
202
static void mtk_ccorr_start (struct mtk_ddp_comp * comp )
@@ -201,6 +209,57 @@ static void mtk_ccorr_stop(struct mtk_ddp_comp *comp)
201
209
writel_relaxed (0x0 , comp -> regs + DISP_CCORR_EN );
202
210
}
203
211
212
+ /* Converts a DRM S31.32 value to the HW S1.10 format. */
213
+ static u16 mtk_ctm_s31_32_to_s1_10 (u64 in )
214
+ {
215
+ u16 r ;
216
+
217
+ /* Sign bit. */
218
+ r = in & BIT_ULL (63 ) ? BIT (11 ) : 0 ;
219
+
220
+ if ((in & GENMASK_ULL (62 , 33 )) > 0 ) {
221
+ /* identity value 0x100000000 -> 0x400, */
222
+ /* if bigger this, set it to max 0x7ff. */
223
+ r |= GENMASK (10 , 0 );
224
+ } else {
225
+ /* take the 11 most important bits. */
226
+ r |= (in >> 22 ) & GENMASK (10 , 0 );
227
+ }
228
+
229
+ return r ;
230
+ }
231
+
232
+ static void mtk_ccorr_ctm_set (struct mtk_ddp_comp * comp ,
233
+ struct drm_crtc_state * state )
234
+ {
235
+ struct drm_property_blob * blob = state -> ctm ;
236
+ struct drm_color_ctm * ctm ;
237
+ const u64 * input ;
238
+ uint16_t coeffs [9 ] = { 0 };
239
+ int i ;
240
+ struct cmdq_pkt * cmdq_pkt = NULL ;
241
+
242
+ if (!blob )
243
+ return ;
244
+
245
+ ctm = (struct drm_color_ctm * )blob -> data ;
246
+ input = ctm -> matrix ;
247
+
248
+ for (i = 0 ; i < ARRAY_SIZE (coeffs ); i ++ )
249
+ coeffs [i ] = mtk_ctm_s31_32_to_s1_10 (input [i ]);
250
+
251
+ mtk_ddp_write (cmdq_pkt , coeffs [0 ] << 16 | coeffs [1 ],
252
+ comp , DISP_CCORR_COEF_0 );
253
+ mtk_ddp_write (cmdq_pkt , coeffs [2 ] << 16 | coeffs [3 ],
254
+ comp , DISP_CCORR_COEF_1 );
255
+ mtk_ddp_write (cmdq_pkt , coeffs [4 ] << 16 | coeffs [5 ],
256
+ comp , DISP_CCORR_COEF_2 );
257
+ mtk_ddp_write (cmdq_pkt , coeffs [6 ] << 16 | coeffs [7 ],
258
+ comp , DISP_CCORR_COEF_3 );
259
+ mtk_ddp_write (cmdq_pkt , coeffs [8 ] << 16 ,
260
+ comp , DISP_CCORR_COEF_4 );
261
+ }
262
+
204
263
static void mtk_dither_config (struct mtk_ddp_comp * comp , unsigned int w ,
205
264
unsigned int h , unsigned int vrefresh ,
206
265
unsigned int bpc , struct cmdq_pkt * cmdq_pkt )
@@ -271,6 +330,7 @@ static const struct mtk_ddp_comp_funcs ddp_ccorr = {
271
330
.config = mtk_ccorr_config ,
272
331
.start = mtk_ccorr_start ,
273
332
.stop = mtk_ccorr_stop ,
333
+ .ctm_set = mtk_ccorr_ctm_set ,
274
334
};
275
335
276
336
static const struct mtk_ddp_comp_funcs ddp_dither = {
0 commit comments