2 * Copyright 2012-15 Advanced Micro Devices, Inc.
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 * OTHER DEALINGS IN THE SOFTWARE.
26 #include "dm_services.h"
27 #include "basics/conversion.h"
31 #include "reg_helper.h"
37 #define FN(reg_name, field_name) \
38 opp110->opp_shift->field_name, opp110->opp_mask->field_name
45 MAX_REGIONS_NUMBER
= 16
50 MAX_NUMBER_OF_ENTRIES
= 256
55 OUTPUT_CSC_MATRIX_SIZE
= 12
80 *****************************************************************************
81 * Function: regamma_config_regions_and_segments
83 * build regamma curve by using predefined hw points
84 * uses interface parameters ,like EDID coeff.
86 * @param : parameters interface parameters
93 *****************************************************************************
100 * 1) set truncation depth: 0 for 18 bpp or 1 for 24 bpp
101 * 2) enable truncation
102 * 3) HW remove 12bit FMT support for DCE11 power saving reason.
104 static void set_truncation(
105 struct dce110_opp
*opp110
,
106 const struct bit_depth_reduction_params
*params
)
108 /*Disable truncation*/
109 REG_UPDATE_3(FMT_BIT_DEPTH_CONTROL
,
111 FMT_TRUNCATE_DEPTH
, 0,
112 FMT_TRUNCATE_MODE
, 0);
115 if (params
->pixel_encoding
== PIXEL_ENCODING_YCBCR422
) {
116 /* 8bpc trunc on YCbCr422*/
117 if (params
->flags
.TRUNCATE_DEPTH
== 1)
118 REG_UPDATE_3(FMT_BIT_DEPTH_CONTROL
,
120 FMT_TRUNCATE_DEPTH
, 1,
121 FMT_TRUNCATE_MODE
, 0);
122 else if (params
->flags
.TRUNCATE_DEPTH
== 2)
123 /* 10bpc trunc on YCbCr422*/
124 REG_UPDATE_3(FMT_BIT_DEPTH_CONTROL
,
126 FMT_TRUNCATE_DEPTH
, 2,
127 FMT_TRUNCATE_MODE
, 0);
130 /* on other format-to do */
131 if (params
->flags
.TRUNCATE_ENABLED
== 0 ||
132 params
->flags
.TRUNCATE_DEPTH
== 2)
134 /*Set truncation depth and Enable truncation*/
135 REG_UPDATE_3(FMT_BIT_DEPTH_CONTROL
,
138 params
->flags
.TRUNCATE_MODE
,
140 params
->flags
.TRUNCATE_DEPTH
);
146 * 1) set spatial dithering mode: pattern of seed
147 * 2) set spatical dithering depth: 0 for 18bpp or 1 for 24bpp
150 * lfsr is reset every frame or not reset
151 * RGB dithering method
152 * 0: RGB data are all dithered with x^28+x^3+1
153 * 1: R data is dithered with x^28+x^3+1
154 * G data is dithered with x^28+X^9+1
155 * B data is dithered with x^28+x^13+1
156 * enable high pass filter or not
157 * 5) enable spatical dithering
159 static void set_spatial_dither(
160 struct dce110_opp
*opp110
,
161 const struct bit_depth_reduction_params
*params
)
163 /*Disable spatial (random) dithering*/
164 REG_UPDATE_3(FMT_BIT_DEPTH_CONTROL
,
165 FMT_SPATIAL_DITHER_EN
, 0,
166 FMT_SPATIAL_DITHER_DEPTH
, 0,
167 FMT_SPATIAL_DITHER_MODE
, 0);
169 REG_UPDATE_3(FMT_BIT_DEPTH_CONTROL
,
170 FMT_HIGHPASS_RANDOM_ENABLE
, 0,
171 FMT_FRAME_RANDOM_ENABLE
, 0,
172 FMT_RGB_RANDOM_ENABLE
, 0);
174 REG_UPDATE(FMT_BIT_DEPTH_CONTROL
,
175 FMT_TEMPORAL_DITHER_EN
, 0);
177 /* no 10bpc on DCE11*/
178 if (params
->flags
.SPATIAL_DITHER_ENABLED
== 0 ||
179 params
->flags
.SPATIAL_DITHER_DEPTH
== 2)
182 /* only use FRAME_COUNTER_MAX if frameRandom == 1*/
184 if (opp110
->opp_mask
->FMT_SPATIAL_DITHER_FRAME_COUNTER_MAX
&&
185 opp110
->opp_mask
->FMT_SPATIAL_DITHER_FRAME_COUNTER_BIT_SWAP
) {
186 if (params
->flags
.FRAME_RANDOM
== 1) {
187 if (params
->flags
.SPATIAL_DITHER_DEPTH
== 0 ||
188 params
->flags
.SPATIAL_DITHER_DEPTH
== 1) {
189 REG_UPDATE_2(FMT_CONTROL
,
190 FMT_SPATIAL_DITHER_FRAME_COUNTER_MAX
, 15,
191 FMT_SPATIAL_DITHER_FRAME_COUNTER_BIT_SWAP
, 2);
192 } else if (params
->flags
.SPATIAL_DITHER_DEPTH
== 2) {
193 REG_UPDATE_2(FMT_CONTROL
,
194 FMT_SPATIAL_DITHER_FRAME_COUNTER_MAX
, 3,
195 FMT_SPATIAL_DITHER_FRAME_COUNTER_BIT_SWAP
, 1);
199 REG_UPDATE_2(FMT_CONTROL
,
200 FMT_SPATIAL_DITHER_FRAME_COUNTER_MAX
, 0,
201 FMT_SPATIAL_DITHER_FRAME_COUNTER_BIT_SWAP
, 0);
204 /* Set seed for random values for
205 * spatial dithering for R,G,B channels
207 REG_UPDATE(FMT_DITHER_RAND_R_SEED
,
208 FMT_RAND_R_SEED
, params
->r_seed_value
);
210 REG_UPDATE(FMT_DITHER_RAND_G_SEED
,
211 FMT_RAND_G_SEED
, params
->g_seed_value
);
213 REG_UPDATE(FMT_DITHER_RAND_B_SEED
,
214 FMT_RAND_B_SEED
, params
->b_seed_value
);
216 /* FMT_OFFSET_R_Cr 31:16 0x0 Setting the zero
217 * offset for the R/Cr channel, lower 4LSB
218 * is forced to zeros. Typically set to 0
219 * RGB and 0x80000 YCbCr.
221 /* FMT_OFFSET_G_Y 31:16 0x0 Setting the zero
222 * offset for the G/Y channel, lower 4LSB is
223 * forced to zeros. Typically set to 0 RGB
226 /* FMT_OFFSET_B_Cb 31:16 0x0 Setting the zero
227 * offset for the B/Cb channel, lower 4LSB is
228 * forced to zeros. Typically set to 0 RGB and
232 /* Disable High pass filter
233 * Reset only at startup
234 * Set RGB data dithered with x^28+x^3+1
236 REG_UPDATE_3(FMT_BIT_DEPTH_CONTROL
,
237 FMT_HIGHPASS_RANDOM_ENABLE
, params
->flags
.HIGHPASS_RANDOM
,
238 FMT_FRAME_RANDOM_ENABLE
, params
->flags
.FRAME_RANDOM
,
239 FMT_RGB_RANDOM_ENABLE
, params
->flags
.RGB_RANDOM
);
241 /* Set spatial dithering bit depth
242 * Set spatial dithering mode
243 * (default is Seed patterrn AAAA...)
244 * Enable spatial dithering
246 REG_UPDATE_3(FMT_BIT_DEPTH_CONTROL
,
247 FMT_SPATIAL_DITHER_DEPTH
, params
->flags
.SPATIAL_DITHER_DEPTH
,
248 FMT_SPATIAL_DITHER_MODE
, params
->flags
.SPATIAL_DITHER_MODE
,
249 FMT_SPATIAL_DITHER_EN
, 1);
253 * SetTemporalDither (Frame Modulation)
254 * 1) set temporal dither depth
255 * 2) select pattern: from hard-coded pattern or programmable pattern
256 * 3) select optimized strips for BGR or RGB LCD sub-pixel
259 * 6) set grey level for 0.25, 0.5, 0.75
260 * 7) enable temporal dithering
263 static void set_temporal_dither(
264 struct dce110_opp
*opp110
,
265 const struct bit_depth_reduction_params
*params
)
267 /*Disable temporal (frame modulation) dithering first*/
268 REG_UPDATE_3(FMT_BIT_DEPTH_CONTROL
,
269 FMT_TEMPORAL_DITHER_EN
, 0,
270 FMT_TEMPORAL_DITHER_RESET
, 0,
271 FMT_TEMPORAL_DITHER_OFFSET
, 0);
273 REG_UPDATE_2(FMT_BIT_DEPTH_CONTROL
,
274 FMT_TEMPORAL_DITHER_DEPTH
, 0,
275 FMT_TEMPORAL_LEVEL
, 0);
277 REG_UPDATE_3(FMT_BIT_DEPTH_CONTROL
,
282 /* no 10bpc dither on DCE11*/
283 if (params
->flags
.FRAME_MODULATION_ENABLED
== 0 ||
284 params
->flags
.FRAME_MODULATION_DEPTH
== 2)
287 /* Set temporal dithering depth*/
288 REG_UPDATE_3(FMT_BIT_DEPTH_CONTROL
,
289 FMT_TEMPORAL_DITHER_DEPTH
, params
->flags
.FRAME_MODULATION_DEPTH
,
290 FMT_TEMPORAL_DITHER_RESET
, 0,
291 FMT_TEMPORAL_DITHER_OFFSET
, 0);
293 /*Select legacy pattern based on FRC and Temporal level*/
294 if (REG(FMT_TEMPORAL_DITHER_PATTERN_CONTROL
)) {
295 REG_WRITE(FMT_TEMPORAL_DITHER_PATTERN_CONTROL
, 0);
297 REG_WRITE(FMT_TEMPORAL_DITHER_PROGRAMMABLE_PATTERN_S_MATRIX
, 0);
299 REG_WRITE(FMT_TEMPORAL_DITHER_PROGRAMMABLE_PATTERN_T_MATRIX
, 0);
302 /*Select patterns for 0.25, 0.5 and 0.75 grey level*/
303 REG_UPDATE(FMT_BIT_DEPTH_CONTROL
,
304 FMT_TEMPORAL_LEVEL
, params
->flags
.TEMPORAL_LEVEL
);
306 REG_UPDATE_3(FMT_BIT_DEPTH_CONTROL
,
307 FMT_25FRC_SEL
, params
->flags
.FRC25
,
308 FMT_50FRC_SEL
, params
->flags
.FRC50
,
309 FMT_75FRC_SEL
, params
->flags
.FRC75
);
311 /*Enable bit reduction by temporal (frame modulation) dithering*/
312 REG_UPDATE(FMT_BIT_DEPTH_CONTROL
,
313 FMT_TEMPORAL_DITHER_EN
, 1);
318 * 1) Set clamping format based on bpc - 0 for 6bpc (No clamping)
323 * 2) Enable clamp if Limited range requested
325 void dce110_opp_set_clamping(
326 struct dce110_opp
*opp110
,
327 const struct clamping_and_pixel_encoding_params
*params
)
329 REG_SET_2(FMT_CLAMP_CNTL
, 0,
330 FMT_CLAMP_DATA_EN
, 0,
331 FMT_CLAMP_COLOR_FORMAT
, 0);
333 switch (params
->clamping_level
) {
334 case CLAMPING_FULL_RANGE
:
336 case CLAMPING_LIMITED_RANGE_8BPC
:
337 REG_SET_2(FMT_CLAMP_CNTL
, 0,
338 FMT_CLAMP_DATA_EN
, 1,
339 FMT_CLAMP_COLOR_FORMAT
, 1);
341 case CLAMPING_LIMITED_RANGE_10BPC
:
342 REG_SET_2(FMT_CLAMP_CNTL
, 0,
343 FMT_CLAMP_DATA_EN
, 1,
344 FMT_CLAMP_COLOR_FORMAT
, 2);
346 case CLAMPING_LIMITED_RANGE_12BPC
:
347 REG_SET_2(FMT_CLAMP_CNTL
, 0,
348 FMT_CLAMP_DATA_EN
, 1,
349 FMT_CLAMP_COLOR_FORMAT
, 3);
351 case CLAMPING_LIMITED_RANGE_PROGRAMMABLE
:
352 /*Set clamp control*/
353 REG_SET_2(FMT_CLAMP_CNTL
, 0,
354 FMT_CLAMP_DATA_EN
, 1,
355 FMT_CLAMP_COLOR_FORMAT
, 7);
358 REG_SET_2(FMT_CLAMP_COMPONENT_R
, 0,
359 FMT_CLAMP_LOWER_R
, 0x10,
360 FMT_CLAMP_UPPER_R
, 0xFEF);
362 REG_SET_2(FMT_CLAMP_COMPONENT_G
, 0,
363 FMT_CLAMP_LOWER_G
, 0x10,
364 FMT_CLAMP_UPPER_G
, 0xFEF);
366 REG_SET_2(FMT_CLAMP_COMPONENT_B
, 0,
367 FMT_CLAMP_LOWER_B
, 0x10,
368 FMT_CLAMP_UPPER_B
, 0xFEF);
379 * 0: RGB 4:4:4 or YCbCr 4:4:4 or YOnly
382 static void set_pixel_encoding(
383 struct dce110_opp
*opp110
,
384 const struct clamping_and_pixel_encoding_params
*params
)
386 if (opp110
->opp_mask
->FMT_CBCR_BIT_REDUCTION_BYPASS
)
387 REG_UPDATE_3(FMT_CONTROL
,
388 FMT_PIXEL_ENCODING
, 0,
389 FMT_SUBSAMPLING_MODE
, 0,
390 FMT_CBCR_BIT_REDUCTION_BYPASS
, 0);
392 REG_UPDATE_2(FMT_CONTROL
,
393 FMT_PIXEL_ENCODING
, 0,
394 FMT_SUBSAMPLING_MODE
, 0);
396 if (params
->pixel_encoding
== PIXEL_ENCODING_YCBCR422
) {
397 REG_UPDATE_2(FMT_CONTROL
,
398 FMT_PIXEL_ENCODING
, 1,
399 FMT_SUBSAMPLING_ORDER
, 0);
401 if (params
->pixel_encoding
== PIXEL_ENCODING_YCBCR420
) {
402 REG_UPDATE_3(FMT_CONTROL
,
403 FMT_PIXEL_ENCODING
, 2,
404 FMT_SUBSAMPLING_MODE
, 2,
405 FMT_CBCR_BIT_REDUCTION_BYPASS
, 1);
410 void dce110_opp_program_bit_depth_reduction(
411 struct output_pixel_processor
*opp
,
412 const struct bit_depth_reduction_params
*params
)
414 struct dce110_opp
*opp110
= TO_DCE110_OPP(opp
);
416 set_truncation(opp110
, params
);
417 set_spatial_dither(opp110
, params
);
418 set_temporal_dither(opp110
, params
);
421 void dce110_opp_program_clamping_and_pixel_encoding(
422 struct output_pixel_processor
*opp
,
423 const struct clamping_and_pixel_encoding_params
*params
)
425 struct dce110_opp
*opp110
= TO_DCE110_OPP(opp
);
427 dce110_opp_set_clamping(opp110
, params
);
428 set_pixel_encoding(opp110
, params
);
431 static void program_formatter_420_memory(struct output_pixel_processor
*opp
)
433 struct dce110_opp
*opp110
= TO_DCE110_OPP(opp
);
434 uint32_t fmt_mem_cntl_value
;
436 /* Program source select*/
437 /* Use HW default source select for FMT_MEMORYx_CONTROL */
438 /* Use that value for FMT_SRC_SELECT as well*/
440 FMT420_MEM0_SOURCE_SEL
, &fmt_mem_cntl_value
);
442 REG_UPDATE(FMT_CONTROL
,
443 FMT_SRC_SELECT
, fmt_mem_cntl_value
);
445 /* Turn on the memory */
447 FMT420_MEM0_PWR_FORCE
, 0);
450 void dce110_opp_set_dyn_expansion(
451 struct output_pixel_processor
*opp
,
452 enum dc_color_space color_sp
,
453 enum dc_color_depth color_dpth
,
454 enum signal_type signal
)
456 struct dce110_opp
*opp110
= TO_DCE110_OPP(opp
);
458 REG_UPDATE_2(FMT_DYNAMIC_EXP_CNTL
,
459 FMT_DYNAMIC_EXP_EN
, 0,
460 FMT_DYNAMIC_EXP_MODE
, 0);
462 /*00 - 10-bit -> 12-bit dynamic expansion*/
463 /*01 - 8-bit -> 12-bit dynamic expansion*/
464 if (signal
== SIGNAL_TYPE_HDMI_TYPE_A
||
465 signal
== SIGNAL_TYPE_DISPLAY_PORT
||
466 signal
== SIGNAL_TYPE_DISPLAY_PORT_MST
) {
467 switch (color_dpth
) {
468 case COLOR_DEPTH_888
:
469 REG_UPDATE_2(FMT_DYNAMIC_EXP_CNTL
,
470 FMT_DYNAMIC_EXP_EN
, 1,
471 FMT_DYNAMIC_EXP_MODE
, 1);
473 case COLOR_DEPTH_101010
:
474 REG_UPDATE_2(FMT_DYNAMIC_EXP_CNTL
,
475 FMT_DYNAMIC_EXP_EN
, 1,
476 FMT_DYNAMIC_EXP_MODE
, 0);
478 case COLOR_DEPTH_121212
:
480 FMT_DYNAMIC_EXP_CNTL
,
481 FMT_DYNAMIC_EXP_EN
, 1,/*otherwise last two bits are zero*/
482 FMT_DYNAMIC_EXP_MODE
, 0);
490 static void program_formatter_reset_dig_resync_fifo(struct output_pixel_processor
*opp
)
492 struct dce110_opp
*opp110
= TO_DCE110_OPP(opp
);
494 /* clear previous phase lock status*/
495 REG_UPDATE(FMT_CONTROL
,
496 FMT_420_PIXEL_PHASE_LOCKED_CLEAR
, 1);
498 /* poll until FMT_420_PIXEL_PHASE_LOCKED become 1*/
499 REG_WAIT(FMT_CONTROL
, FMT_420_PIXEL_PHASE_LOCKED
, 1, 10, 10);
503 void dce110_opp_program_fmt(
504 struct output_pixel_processor
*opp
,
505 struct bit_depth_reduction_params
*fmt_bit_depth
,
506 struct clamping_and_pixel_encoding_params
*clamping
)
508 /* dithering is affected by <CrtcSourceSelect>, hence should be
509 * programmed afterwards */
511 if (clamping
->pixel_encoding
== PIXEL_ENCODING_YCBCR420
)
512 program_formatter_420_memory(opp
);
514 dce110_opp_program_bit_depth_reduction(
518 dce110_opp_program_clamping_and_pixel_encoding(
522 if (clamping
->pixel_encoding
== PIXEL_ENCODING_YCBCR420
)
523 program_formatter_reset_dig_resync_fifo(opp
);
532 /*****************************************/
533 /* Constructor, Destructor */
534 /*****************************************/
536 static const struct opp_funcs funcs
= {
537 .opp_set_dyn_expansion
= dce110_opp_set_dyn_expansion
,
538 .opp_destroy
= dce110_opp_destroy
,
539 .opp_program_fmt
= dce110_opp_program_fmt
,
540 .opp_program_bit_depth_reduction
= dce110_opp_program_bit_depth_reduction
543 void dce110_opp_construct(struct dce110_opp
*opp110
,
544 struct dc_context
*ctx
,
546 const struct dce_opp_registers
*regs
,
547 const struct dce_opp_shift
*opp_shift
,
548 const struct dce_opp_mask
*opp_mask
)
550 opp110
->base
.funcs
= &funcs
;
552 opp110
->base
.ctx
= ctx
;
554 opp110
->base
.inst
= inst
;
557 opp110
->opp_shift
= opp_shift
;
558 opp110
->opp_mask
= opp_mask
;
561 void dce110_opp_destroy(struct output_pixel_processor
**opp
)
564 kfree(FROM_DCE11_OPP(*opp
));