xref: /dflybsd-src/sys/dev/drm/amd/display/dc/dce/dce_opp.c (revision b843c749addef9340ee7d4e250b09fdd492602a1)
1*b843c749SSergey Zigachev /*
2*b843c749SSergey Zigachev  * Copyright 2012-15 Advanced Micro Devices, Inc.
3*b843c749SSergey Zigachev  *
4*b843c749SSergey Zigachev  * Permission is hereby granted, free of charge, to any person obtaining a
5*b843c749SSergey Zigachev  * copy of this software and associated documentation files (the "Software"),
6*b843c749SSergey Zigachev  * to deal in the Software without restriction, including without limitation
7*b843c749SSergey Zigachev  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8*b843c749SSergey Zigachev  * and/or sell copies of the Software, and to permit persons to whom the
9*b843c749SSergey Zigachev  * Software is furnished to do so, subject to the following conditions:
10*b843c749SSergey Zigachev  *
11*b843c749SSergey Zigachev  * The above copyright notice and this permission notice shall be included in
12*b843c749SSergey Zigachev  * all copies or substantial portions of the Software.
13*b843c749SSergey Zigachev  *
14*b843c749SSergey Zigachev  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15*b843c749SSergey Zigachev  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16*b843c749SSergey Zigachev  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
17*b843c749SSergey Zigachev  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18*b843c749SSergey Zigachev  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19*b843c749SSergey Zigachev  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20*b843c749SSergey Zigachev  * OTHER DEALINGS IN THE SOFTWARE.
21*b843c749SSergey Zigachev  *
22*b843c749SSergey Zigachev  * Authors: AMD
23*b843c749SSergey Zigachev  *
24*b843c749SSergey Zigachev  */
25*b843c749SSergey Zigachev 
26*b843c749SSergey Zigachev #include "dm_services.h"
27*b843c749SSergey Zigachev #include "basics/conversion.h"
28*b843c749SSergey Zigachev 
29*b843c749SSergey Zigachev #include "dce_opp.h"
30*b843c749SSergey Zigachev 
31*b843c749SSergey Zigachev #include "reg_helper.h"
32*b843c749SSergey Zigachev 
33*b843c749SSergey Zigachev #define REG(reg)\
34*b843c749SSergey Zigachev 	(opp110->regs->reg)
35*b843c749SSergey Zigachev 
36*b843c749SSergey Zigachev #undef FN
37*b843c749SSergey Zigachev #define FN(reg_name, field_name) \
38*b843c749SSergey Zigachev 	opp110->opp_shift->field_name, opp110->opp_mask->field_name
39*b843c749SSergey Zigachev 
40*b843c749SSergey Zigachev #define CTX \
41*b843c749SSergey Zigachev 	opp110->base.ctx
42*b843c749SSergey Zigachev 
43*b843c749SSergey Zigachev enum {
44*b843c749SSergey Zigachev 	MAX_PWL_ENTRY = 128,
45*b843c749SSergey Zigachev 	MAX_REGIONS_NUMBER = 16
46*b843c749SSergey Zigachev };
47*b843c749SSergey Zigachev 
48*b843c749SSergey Zigachev enum {
49*b843c749SSergey Zigachev 	MAX_LUT_ENTRY = 256,
50*b843c749SSergey Zigachev 	MAX_NUMBER_OF_ENTRIES = 256
51*b843c749SSergey Zigachev };
52*b843c749SSergey Zigachev 
53*b843c749SSergey Zigachev 
54*b843c749SSergey Zigachev enum {
55*b843c749SSergey Zigachev 	OUTPUT_CSC_MATRIX_SIZE = 12
56*b843c749SSergey Zigachev };
57*b843c749SSergey Zigachev 
58*b843c749SSergey Zigachev 
59*b843c749SSergey Zigachev 
60*b843c749SSergey Zigachev 
61*b843c749SSergey Zigachev 
62*b843c749SSergey Zigachev 
63*b843c749SSergey Zigachev 
64*b843c749SSergey Zigachev 
65*b843c749SSergey Zigachev 
66*b843c749SSergey Zigachev 
67*b843c749SSergey Zigachev 
68*b843c749SSergey Zigachev 
69*b843c749SSergey Zigachev 
70*b843c749SSergey Zigachev 
71*b843c749SSergey Zigachev 
72*b843c749SSergey Zigachev 
73*b843c749SSergey Zigachev 
74*b843c749SSergey Zigachev 
75*b843c749SSergey Zigachev 
76*b843c749SSergey Zigachev 
77*b843c749SSergey Zigachev 
78*b843c749SSergey Zigachev 
79*b843c749SSergey Zigachev /*
80*b843c749SSergey Zigachev  *****************************************************************************
81*b843c749SSergey Zigachev  *  Function: regamma_config_regions_and_segments
82*b843c749SSergey Zigachev  *
83*b843c749SSergey Zigachev  *     build regamma curve by using predefined hw points
84*b843c749SSergey Zigachev  *     uses interface parameters ,like EDID coeff.
85*b843c749SSergey Zigachev  *
86*b843c749SSergey Zigachev  * @param   : parameters   interface parameters
87*b843c749SSergey Zigachev  *  @return void
88*b843c749SSergey Zigachev  *
89*b843c749SSergey Zigachev  *  @note
90*b843c749SSergey Zigachev  *
91*b843c749SSergey Zigachev  *  @see
92*b843c749SSergey Zigachev  *
93*b843c749SSergey Zigachev  *****************************************************************************
94*b843c749SSergey Zigachev  */
95*b843c749SSergey Zigachev 
96*b843c749SSergey Zigachev 
97*b843c749SSergey Zigachev 
98*b843c749SSergey Zigachev /**
99*b843c749SSergey Zigachev  *	set_truncation
100*b843c749SSergey Zigachev  *	1) set truncation depth: 0 for 18 bpp or 1 for 24 bpp
101*b843c749SSergey Zigachev  *	2) enable truncation
102*b843c749SSergey Zigachev  *	3) HW remove 12bit FMT support for DCE11 power saving reason.
103*b843c749SSergey Zigachev  */
set_truncation(struct dce110_opp * opp110,const struct bit_depth_reduction_params * params)104*b843c749SSergey Zigachev static void set_truncation(
105*b843c749SSergey Zigachev 		struct dce110_opp *opp110,
106*b843c749SSergey Zigachev 		const struct bit_depth_reduction_params *params)
107*b843c749SSergey Zigachev {
108*b843c749SSergey Zigachev 	/*Disable truncation*/
109*b843c749SSergey Zigachev 	REG_UPDATE_3(FMT_BIT_DEPTH_CONTROL,
110*b843c749SSergey Zigachev 			FMT_TRUNCATE_EN, 0,
111*b843c749SSergey Zigachev 			FMT_TRUNCATE_DEPTH, 0,
112*b843c749SSergey Zigachev 			FMT_TRUNCATE_MODE, 0);
113*b843c749SSergey Zigachev 
114*b843c749SSergey Zigachev 
115*b843c749SSergey Zigachev 	if (params->pixel_encoding == PIXEL_ENCODING_YCBCR422) {
116*b843c749SSergey Zigachev 		/*  8bpc trunc on YCbCr422*/
117*b843c749SSergey Zigachev 		if (params->flags.TRUNCATE_DEPTH == 1)
118*b843c749SSergey Zigachev 			REG_UPDATE_3(FMT_BIT_DEPTH_CONTROL,
119*b843c749SSergey Zigachev 					FMT_TRUNCATE_EN, 1,
120*b843c749SSergey Zigachev 					FMT_TRUNCATE_DEPTH, 1,
121*b843c749SSergey Zigachev 					FMT_TRUNCATE_MODE, 0);
122*b843c749SSergey Zigachev 		else if (params->flags.TRUNCATE_DEPTH == 2)
123*b843c749SSergey Zigachev 			/*  10bpc trunc on YCbCr422*/
124*b843c749SSergey Zigachev 			REG_UPDATE_3(FMT_BIT_DEPTH_CONTROL,
125*b843c749SSergey Zigachev 					FMT_TRUNCATE_EN, 1,
126*b843c749SSergey Zigachev 					FMT_TRUNCATE_DEPTH, 2,
127*b843c749SSergey Zigachev 					FMT_TRUNCATE_MODE, 0);
128*b843c749SSergey Zigachev 		return;
129*b843c749SSergey Zigachev 	}
130*b843c749SSergey Zigachev 	/* on other format-to do */
131*b843c749SSergey Zigachev 	if (params->flags.TRUNCATE_ENABLED == 0)
132*b843c749SSergey Zigachev 		return;
133*b843c749SSergey Zigachev 	/*Set truncation depth and Enable truncation*/
134*b843c749SSergey Zigachev 	REG_UPDATE_3(FMT_BIT_DEPTH_CONTROL,
135*b843c749SSergey Zigachev 				FMT_TRUNCATE_EN, 1,
136*b843c749SSergey Zigachev 				FMT_TRUNCATE_DEPTH,
137*b843c749SSergey Zigachev 				params->flags.TRUNCATE_DEPTH,
138*b843c749SSergey Zigachev 				FMT_TRUNCATE_MODE,
139*b843c749SSergey Zigachev 				params->flags.TRUNCATE_MODE);
140*b843c749SSergey Zigachev }
141*b843c749SSergey Zigachev 
142*b843c749SSergey Zigachev 
143*b843c749SSergey Zigachev /**
144*b843c749SSergey Zigachev  *	set_spatial_dither
145*b843c749SSergey Zigachev  *	1) set spatial dithering mode: pattern of seed
146*b843c749SSergey Zigachev  *	2) set spatial dithering depth: 0 for 18bpp or 1 for 24bpp
147*b843c749SSergey Zigachev  *	3) set random seed
148*b843c749SSergey Zigachev  *	4) set random mode
149*b843c749SSergey Zigachev  *		lfsr is reset every frame or not reset
150*b843c749SSergey Zigachev  *		RGB dithering method
151*b843c749SSergey Zigachev  *		0: RGB data are all dithered with x^28+x^3+1
152*b843c749SSergey Zigachev  *		1: R data is dithered with x^28+x^3+1
153*b843c749SSergey Zigachev  *		G data is dithered with x^28+X^9+1
154*b843c749SSergey Zigachev  *		B data is dithered with x^28+x^13+1
155*b843c749SSergey Zigachev  *		enable high pass filter or not
156*b843c749SSergey Zigachev  *	5) enable spatical dithering
157*b843c749SSergey Zigachev  */
set_spatial_dither(struct dce110_opp * opp110,const struct bit_depth_reduction_params * params)158*b843c749SSergey Zigachev static void set_spatial_dither(
159*b843c749SSergey Zigachev 	struct dce110_opp *opp110,
160*b843c749SSergey Zigachev 	const struct bit_depth_reduction_params *params)
161*b843c749SSergey Zigachev {
162*b843c749SSergey Zigachev 	/*Disable spatial (random) dithering*/
163*b843c749SSergey Zigachev 	REG_UPDATE_3(FMT_BIT_DEPTH_CONTROL,
164*b843c749SSergey Zigachev 		FMT_SPATIAL_DITHER_EN, 0,
165*b843c749SSergey Zigachev 		FMT_SPATIAL_DITHER_DEPTH, 0,
166*b843c749SSergey Zigachev 		FMT_SPATIAL_DITHER_MODE, 0);
167*b843c749SSergey Zigachev 
168*b843c749SSergey Zigachev 	REG_UPDATE_3(FMT_BIT_DEPTH_CONTROL,
169*b843c749SSergey Zigachev 		FMT_HIGHPASS_RANDOM_ENABLE, 0,
170*b843c749SSergey Zigachev 		FMT_FRAME_RANDOM_ENABLE, 0,
171*b843c749SSergey Zigachev 		FMT_RGB_RANDOM_ENABLE, 0);
172*b843c749SSergey Zigachev 
173*b843c749SSergey Zigachev 	REG_UPDATE(FMT_BIT_DEPTH_CONTROL,
174*b843c749SSergey Zigachev 		FMT_TEMPORAL_DITHER_EN, 0);
175*b843c749SSergey Zigachev 
176*b843c749SSergey Zigachev 	/* no 10bpc on DCE11*/
177*b843c749SSergey Zigachev 	if (params->flags.SPATIAL_DITHER_ENABLED == 0 ||
178*b843c749SSergey Zigachev 		params->flags.SPATIAL_DITHER_DEPTH == 2)
179*b843c749SSergey Zigachev 		return;
180*b843c749SSergey Zigachev 
181*b843c749SSergey Zigachev 	/* only use FRAME_COUNTER_MAX if frameRandom == 1*/
182*b843c749SSergey Zigachev 
183*b843c749SSergey Zigachev 	if (opp110->opp_mask->FMT_SPATIAL_DITHER_FRAME_COUNTER_MAX &&
184*b843c749SSergey Zigachev 			opp110->opp_mask->FMT_SPATIAL_DITHER_FRAME_COUNTER_BIT_SWAP) {
185*b843c749SSergey Zigachev 		if (params->flags.FRAME_RANDOM == 1) {
186*b843c749SSergey Zigachev 			if (params->flags.SPATIAL_DITHER_DEPTH == 0 ||
187*b843c749SSergey Zigachev 			params->flags.SPATIAL_DITHER_DEPTH == 1) {
188*b843c749SSergey Zigachev 				REG_UPDATE_2(FMT_CONTROL,
189*b843c749SSergey Zigachev 					FMT_SPATIAL_DITHER_FRAME_COUNTER_MAX, 15,
190*b843c749SSergey Zigachev 					FMT_SPATIAL_DITHER_FRAME_COUNTER_BIT_SWAP, 2);
191*b843c749SSergey Zigachev 			} else if (params->flags.SPATIAL_DITHER_DEPTH == 2) {
192*b843c749SSergey Zigachev 				REG_UPDATE_2(FMT_CONTROL,
193*b843c749SSergey Zigachev 					FMT_SPATIAL_DITHER_FRAME_COUNTER_MAX, 3,
194*b843c749SSergey Zigachev 					FMT_SPATIAL_DITHER_FRAME_COUNTER_BIT_SWAP, 1);
195*b843c749SSergey Zigachev 			} else
196*b843c749SSergey Zigachev 				return;
197*b843c749SSergey Zigachev 		} else {
198*b843c749SSergey Zigachev 			REG_UPDATE_2(FMT_CONTROL,
199*b843c749SSergey Zigachev 					FMT_SPATIAL_DITHER_FRAME_COUNTER_MAX, 0,
200*b843c749SSergey Zigachev 					FMT_SPATIAL_DITHER_FRAME_COUNTER_BIT_SWAP, 0);
201*b843c749SSergey Zigachev 		}
202*b843c749SSergey Zigachev 	}
203*b843c749SSergey Zigachev 	/* Set seed for random values for
204*b843c749SSergey Zigachev 	 * spatial dithering for R,G,B channels
205*b843c749SSergey Zigachev 	 */
206*b843c749SSergey Zigachev 	REG_UPDATE(FMT_DITHER_RAND_R_SEED,
207*b843c749SSergey Zigachev 			FMT_RAND_R_SEED, params->r_seed_value);
208*b843c749SSergey Zigachev 
209*b843c749SSergey Zigachev 	REG_UPDATE(FMT_DITHER_RAND_G_SEED,
210*b843c749SSergey Zigachev 			FMT_RAND_G_SEED, params->g_seed_value);
211*b843c749SSergey Zigachev 
212*b843c749SSergey Zigachev 	REG_UPDATE(FMT_DITHER_RAND_B_SEED,
213*b843c749SSergey Zigachev 			FMT_RAND_B_SEED, params->b_seed_value);
214*b843c749SSergey Zigachev 
215*b843c749SSergey Zigachev 	/* FMT_OFFSET_R_Cr  31:16 0x0 Setting the zero
216*b843c749SSergey Zigachev 	 * offset for the R/Cr channel, lower 4LSB
217*b843c749SSergey Zigachev 	 * is forced to zeros. Typically set to 0
218*b843c749SSergey Zigachev 	 * RGB and 0x80000 YCbCr.
219*b843c749SSergey Zigachev 	 */
220*b843c749SSergey Zigachev 	/* FMT_OFFSET_G_Y   31:16 0x0 Setting the zero
221*b843c749SSergey Zigachev 	 * offset for the G/Y  channel, lower 4LSB is
222*b843c749SSergey Zigachev 	 * forced to zeros. Typically set to 0 RGB
223*b843c749SSergey Zigachev 	 * and 0x80000 YCbCr.
224*b843c749SSergey Zigachev 	 */
225*b843c749SSergey Zigachev 	/* FMT_OFFSET_B_Cb  31:16 0x0 Setting the zero
226*b843c749SSergey Zigachev 	 * offset for the B/Cb channel, lower 4LSB is
227*b843c749SSergey Zigachev 	 * forced to zeros. Typically set to 0 RGB and
228*b843c749SSergey Zigachev 	 * 0x80000 YCbCr.
229*b843c749SSergey Zigachev 	 */
230*b843c749SSergey Zigachev 
231*b843c749SSergey Zigachev 	/* Disable High pass filter
232*b843c749SSergey Zigachev 	 * Reset only at startup
233*b843c749SSergey Zigachev 	 * Set RGB data dithered with x^28+x^3+1
234*b843c749SSergey Zigachev 	 */
235*b843c749SSergey Zigachev 	REG_UPDATE_3(FMT_BIT_DEPTH_CONTROL,
236*b843c749SSergey Zigachev 		FMT_HIGHPASS_RANDOM_ENABLE, params->flags.HIGHPASS_RANDOM,
237*b843c749SSergey Zigachev 		FMT_FRAME_RANDOM_ENABLE, params->flags.FRAME_RANDOM,
238*b843c749SSergey Zigachev 		FMT_RGB_RANDOM_ENABLE, params->flags.RGB_RANDOM);
239*b843c749SSergey Zigachev 
240*b843c749SSergey Zigachev 	/* Set spatial dithering bit depth
241*b843c749SSergey Zigachev 	 * Set spatial dithering mode
242*b843c749SSergey Zigachev 	 * (default is Seed patterrn AAAA...)
243*b843c749SSergey Zigachev 	 * Enable spatial dithering
244*b843c749SSergey Zigachev 	 */
245*b843c749SSergey Zigachev 	REG_UPDATE_3(FMT_BIT_DEPTH_CONTROL,
246*b843c749SSergey Zigachev 		FMT_SPATIAL_DITHER_DEPTH, params->flags.SPATIAL_DITHER_DEPTH,
247*b843c749SSergey Zigachev 		FMT_SPATIAL_DITHER_MODE, params->flags.SPATIAL_DITHER_MODE,
248*b843c749SSergey Zigachev 		FMT_SPATIAL_DITHER_EN, 1);
249*b843c749SSergey Zigachev }
250*b843c749SSergey Zigachev 
251*b843c749SSergey Zigachev /**
252*b843c749SSergey Zigachev  *	SetTemporalDither (Frame Modulation)
253*b843c749SSergey Zigachev  *	1) set temporal dither depth
254*b843c749SSergey Zigachev  *	2) select pattern: from hard-coded pattern or programmable pattern
255*b843c749SSergey Zigachev  *	3) select optimized strips for BGR or RGB LCD sub-pixel
256*b843c749SSergey Zigachev  *	4) set s matrix
257*b843c749SSergey Zigachev  *	5) set t matrix
258*b843c749SSergey Zigachev  *	6) set grey level for 0.25, 0.5, 0.75
259*b843c749SSergey Zigachev  *	7) enable temporal dithering
260*b843c749SSergey Zigachev  */
261*b843c749SSergey Zigachev 
set_temporal_dither(struct dce110_opp * opp110,const struct bit_depth_reduction_params * params)262*b843c749SSergey Zigachev static void set_temporal_dither(
263*b843c749SSergey Zigachev 	struct dce110_opp *opp110,
264*b843c749SSergey Zigachev 	const struct bit_depth_reduction_params *params)
265*b843c749SSergey Zigachev {
266*b843c749SSergey Zigachev 	/*Disable temporal (frame modulation) dithering first*/
267*b843c749SSergey Zigachev 	REG_UPDATE_3(FMT_BIT_DEPTH_CONTROL,
268*b843c749SSergey Zigachev 		FMT_TEMPORAL_DITHER_EN, 0,
269*b843c749SSergey Zigachev 		FMT_TEMPORAL_DITHER_RESET, 0,
270*b843c749SSergey Zigachev 		FMT_TEMPORAL_DITHER_OFFSET, 0);
271*b843c749SSergey Zigachev 
272*b843c749SSergey Zigachev 	REG_UPDATE_2(FMT_BIT_DEPTH_CONTROL,
273*b843c749SSergey Zigachev 		FMT_TEMPORAL_DITHER_DEPTH, 0,
274*b843c749SSergey Zigachev 		FMT_TEMPORAL_LEVEL, 0);
275*b843c749SSergey Zigachev 
276*b843c749SSergey Zigachev 	REG_UPDATE_3(FMT_BIT_DEPTH_CONTROL,
277*b843c749SSergey Zigachev 		FMT_25FRC_SEL, 0,
278*b843c749SSergey Zigachev 		FMT_50FRC_SEL, 0,
279*b843c749SSergey Zigachev 		FMT_75FRC_SEL, 0);
280*b843c749SSergey Zigachev 
281*b843c749SSergey Zigachev 	/* no 10bpc dither on DCE11*/
282*b843c749SSergey Zigachev 	if (params->flags.FRAME_MODULATION_ENABLED == 0 ||
283*b843c749SSergey Zigachev 		params->flags.FRAME_MODULATION_DEPTH == 2)
284*b843c749SSergey Zigachev 		return;
285*b843c749SSergey Zigachev 
286*b843c749SSergey Zigachev 	/* Set temporal dithering depth*/
287*b843c749SSergey Zigachev 	REG_UPDATE_3(FMT_BIT_DEPTH_CONTROL,
288*b843c749SSergey Zigachev 		FMT_TEMPORAL_DITHER_DEPTH, params->flags.FRAME_MODULATION_DEPTH,
289*b843c749SSergey Zigachev 		FMT_TEMPORAL_DITHER_RESET, 0,
290*b843c749SSergey Zigachev 		FMT_TEMPORAL_DITHER_OFFSET, 0);
291*b843c749SSergey Zigachev 
292*b843c749SSergey Zigachev 	/*Select legacy pattern based on FRC and Temporal level*/
293*b843c749SSergey Zigachev 	if (REG(FMT_TEMPORAL_DITHER_PATTERN_CONTROL)) {
294*b843c749SSergey Zigachev 		REG_WRITE(FMT_TEMPORAL_DITHER_PATTERN_CONTROL, 0);
295*b843c749SSergey Zigachev 		/*Set s matrix*/
296*b843c749SSergey Zigachev 		REG_WRITE(FMT_TEMPORAL_DITHER_PROGRAMMABLE_PATTERN_S_MATRIX, 0);
297*b843c749SSergey Zigachev 		/*Set t matrix*/
298*b843c749SSergey Zigachev 		REG_WRITE(FMT_TEMPORAL_DITHER_PROGRAMMABLE_PATTERN_T_MATRIX, 0);
299*b843c749SSergey Zigachev 	}
300*b843c749SSergey Zigachev 
301*b843c749SSergey Zigachev 	/*Select patterns for 0.25, 0.5 and 0.75 grey level*/
302*b843c749SSergey Zigachev 	REG_UPDATE(FMT_BIT_DEPTH_CONTROL,
303*b843c749SSergey Zigachev 		FMT_TEMPORAL_LEVEL, params->flags.TEMPORAL_LEVEL);
304*b843c749SSergey Zigachev 
305*b843c749SSergey Zigachev 	REG_UPDATE_3(FMT_BIT_DEPTH_CONTROL,
306*b843c749SSergey Zigachev 		FMT_25FRC_SEL, params->flags.FRC25,
307*b843c749SSergey Zigachev 		FMT_50FRC_SEL, params->flags.FRC50,
308*b843c749SSergey Zigachev 		FMT_75FRC_SEL, params->flags.FRC75);
309*b843c749SSergey Zigachev 
310*b843c749SSergey Zigachev 	/*Enable bit reduction by temporal (frame modulation) dithering*/
311*b843c749SSergey Zigachev 	REG_UPDATE(FMT_BIT_DEPTH_CONTROL,
312*b843c749SSergey Zigachev 		FMT_TEMPORAL_DITHER_EN, 1);
313*b843c749SSergey Zigachev }
314*b843c749SSergey Zigachev 
315*b843c749SSergey Zigachev /**
316*b843c749SSergey Zigachev  *	Set Clamping
317*b843c749SSergey Zigachev  *	1) Set clamping format based on bpc - 0 for 6bpc (No clamping)
318*b843c749SSergey Zigachev  *		1 for 8 bpc
319*b843c749SSergey Zigachev  *		2 for 10 bpc
320*b843c749SSergey Zigachev  *		3 for 12 bpc
321*b843c749SSergey Zigachev  *		7 for programable
322*b843c749SSergey Zigachev  *	2) Enable clamp if Limited range requested
323*b843c749SSergey Zigachev  */
dce110_opp_set_clamping(struct dce110_opp * opp110,const struct clamping_and_pixel_encoding_params * params)324*b843c749SSergey Zigachev void dce110_opp_set_clamping(
325*b843c749SSergey Zigachev 	struct dce110_opp *opp110,
326*b843c749SSergey Zigachev 	const struct clamping_and_pixel_encoding_params *params)
327*b843c749SSergey Zigachev {
328*b843c749SSergey Zigachev 	REG_SET_2(FMT_CLAMP_CNTL, 0,
329*b843c749SSergey Zigachev 		FMT_CLAMP_DATA_EN, 0,
330*b843c749SSergey Zigachev 		FMT_CLAMP_COLOR_FORMAT, 0);
331*b843c749SSergey Zigachev 
332*b843c749SSergey Zigachev 	switch (params->clamping_level) {
333*b843c749SSergey Zigachev 	case CLAMPING_FULL_RANGE:
334*b843c749SSergey Zigachev 		break;
335*b843c749SSergey Zigachev 	case CLAMPING_LIMITED_RANGE_8BPC:
336*b843c749SSergey Zigachev 		REG_SET_2(FMT_CLAMP_CNTL, 0,
337*b843c749SSergey Zigachev 			FMT_CLAMP_DATA_EN, 1,
338*b843c749SSergey Zigachev 			FMT_CLAMP_COLOR_FORMAT, 1);
339*b843c749SSergey Zigachev 		break;
340*b843c749SSergey Zigachev 	case CLAMPING_LIMITED_RANGE_10BPC:
341*b843c749SSergey Zigachev 		REG_SET_2(FMT_CLAMP_CNTL, 0,
342*b843c749SSergey Zigachev 			FMT_CLAMP_DATA_EN, 1,
343*b843c749SSergey Zigachev 			FMT_CLAMP_COLOR_FORMAT, 2);
344*b843c749SSergey Zigachev 		break;
345*b843c749SSergey Zigachev 	case CLAMPING_LIMITED_RANGE_12BPC:
346*b843c749SSergey Zigachev 		REG_SET_2(FMT_CLAMP_CNTL, 0,
347*b843c749SSergey Zigachev 			FMT_CLAMP_DATA_EN, 1,
348*b843c749SSergey Zigachev 			FMT_CLAMP_COLOR_FORMAT, 3);
349*b843c749SSergey Zigachev 		break;
350*b843c749SSergey Zigachev 	case CLAMPING_LIMITED_RANGE_PROGRAMMABLE:
351*b843c749SSergey Zigachev 		/*Set clamp control*/
352*b843c749SSergey Zigachev 		REG_SET_2(FMT_CLAMP_CNTL, 0,
353*b843c749SSergey Zigachev 			FMT_CLAMP_DATA_EN, 1,
354*b843c749SSergey Zigachev 			FMT_CLAMP_COLOR_FORMAT, 7);
355*b843c749SSergey Zigachev 
356*b843c749SSergey Zigachev 		/*set the defaults*/
357*b843c749SSergey Zigachev 		REG_SET_2(FMT_CLAMP_COMPONENT_R, 0,
358*b843c749SSergey Zigachev 			FMT_CLAMP_LOWER_R, 0x10,
359*b843c749SSergey Zigachev 			FMT_CLAMP_UPPER_R, 0xFEF);
360*b843c749SSergey Zigachev 
361*b843c749SSergey Zigachev 		REG_SET_2(FMT_CLAMP_COMPONENT_G, 0,
362*b843c749SSergey Zigachev 			FMT_CLAMP_LOWER_G, 0x10,
363*b843c749SSergey Zigachev 			FMT_CLAMP_UPPER_G, 0xFEF);
364*b843c749SSergey Zigachev 
365*b843c749SSergey Zigachev 		REG_SET_2(FMT_CLAMP_COMPONENT_B, 0,
366*b843c749SSergey Zigachev 			FMT_CLAMP_LOWER_B, 0x10,
367*b843c749SSergey Zigachev 			FMT_CLAMP_UPPER_B, 0xFEF);
368*b843c749SSergey Zigachev 		break;
369*b843c749SSergey Zigachev 	default:
370*b843c749SSergey Zigachev 		break;
371*b843c749SSergey Zigachev 	}
372*b843c749SSergey Zigachev }
373*b843c749SSergey Zigachev 
374*b843c749SSergey Zigachev /**
375*b843c749SSergey Zigachev  *	set_pixel_encoding
376*b843c749SSergey Zigachev  *
377*b843c749SSergey Zigachev  *	Set Pixel Encoding
378*b843c749SSergey Zigachev  *		0: RGB 4:4:4 or YCbCr 4:4:4 or YOnly
379*b843c749SSergey Zigachev  *		1: YCbCr 4:2:2
380*b843c749SSergey Zigachev  */
set_pixel_encoding(struct dce110_opp * opp110,const struct clamping_and_pixel_encoding_params * params)381*b843c749SSergey Zigachev static void set_pixel_encoding(
382*b843c749SSergey Zigachev 	struct dce110_opp *opp110,
383*b843c749SSergey Zigachev 	const struct clamping_and_pixel_encoding_params *params)
384*b843c749SSergey Zigachev {
385*b843c749SSergey Zigachev 	if (opp110->opp_mask->FMT_CBCR_BIT_REDUCTION_BYPASS)
386*b843c749SSergey Zigachev 		REG_UPDATE_3(FMT_CONTROL,
387*b843c749SSergey Zigachev 				FMT_PIXEL_ENCODING, 0,
388*b843c749SSergey Zigachev 				FMT_SUBSAMPLING_MODE, 0,
389*b843c749SSergey Zigachev 				FMT_CBCR_BIT_REDUCTION_BYPASS, 0);
390*b843c749SSergey Zigachev 	else
391*b843c749SSergey Zigachev 		REG_UPDATE_2(FMT_CONTROL,
392*b843c749SSergey Zigachev 				FMT_PIXEL_ENCODING, 0,
393*b843c749SSergey Zigachev 				FMT_SUBSAMPLING_MODE, 0);
394*b843c749SSergey Zigachev 
395*b843c749SSergey Zigachev 	if (params->pixel_encoding == PIXEL_ENCODING_YCBCR422) {
396*b843c749SSergey Zigachev 		REG_UPDATE_2(FMT_CONTROL,
397*b843c749SSergey Zigachev 				FMT_PIXEL_ENCODING, 1,
398*b843c749SSergey Zigachev 				FMT_SUBSAMPLING_ORDER, 0);
399*b843c749SSergey Zigachev 	}
400*b843c749SSergey Zigachev 	if (params->pixel_encoding == PIXEL_ENCODING_YCBCR420) {
401*b843c749SSergey Zigachev 		REG_UPDATE_3(FMT_CONTROL,
402*b843c749SSergey Zigachev 				FMT_PIXEL_ENCODING, 2,
403*b843c749SSergey Zigachev 				FMT_SUBSAMPLING_MODE, 2,
404*b843c749SSergey Zigachev 				FMT_CBCR_BIT_REDUCTION_BYPASS, 1);
405*b843c749SSergey Zigachev 	}
406*b843c749SSergey Zigachev 
407*b843c749SSergey Zigachev }
408*b843c749SSergey Zigachev 
dce110_opp_program_bit_depth_reduction(struct output_pixel_processor * opp,const struct bit_depth_reduction_params * params)409*b843c749SSergey Zigachev void dce110_opp_program_bit_depth_reduction(
410*b843c749SSergey Zigachev 	struct output_pixel_processor *opp,
411*b843c749SSergey Zigachev 	const struct bit_depth_reduction_params *params)
412*b843c749SSergey Zigachev {
413*b843c749SSergey Zigachev 	struct dce110_opp *opp110 = TO_DCE110_OPP(opp);
414*b843c749SSergey Zigachev 
415*b843c749SSergey Zigachev 	set_truncation(opp110, params);
416*b843c749SSergey Zigachev 	set_spatial_dither(opp110, params);
417*b843c749SSergey Zigachev 	set_temporal_dither(opp110, params);
418*b843c749SSergey Zigachev }
419*b843c749SSergey Zigachev 
dce110_opp_program_clamping_and_pixel_encoding(struct output_pixel_processor * opp,const struct clamping_and_pixel_encoding_params * params)420*b843c749SSergey Zigachev void dce110_opp_program_clamping_and_pixel_encoding(
421*b843c749SSergey Zigachev 	struct output_pixel_processor *opp,
422*b843c749SSergey Zigachev 	const struct clamping_and_pixel_encoding_params *params)
423*b843c749SSergey Zigachev {
424*b843c749SSergey Zigachev 	struct dce110_opp *opp110 = TO_DCE110_OPP(opp);
425*b843c749SSergey Zigachev 
426*b843c749SSergey Zigachev 	dce110_opp_set_clamping(opp110, params);
427*b843c749SSergey Zigachev 	set_pixel_encoding(opp110, params);
428*b843c749SSergey Zigachev }
429*b843c749SSergey Zigachev 
program_formatter_420_memory(struct output_pixel_processor * opp)430*b843c749SSergey Zigachev static void program_formatter_420_memory(struct output_pixel_processor *opp)
431*b843c749SSergey Zigachev {
432*b843c749SSergey Zigachev 	struct dce110_opp *opp110 = TO_DCE110_OPP(opp);
433*b843c749SSergey Zigachev 	uint32_t fmt_mem_cntl_value;
434*b843c749SSergey Zigachev 
435*b843c749SSergey Zigachev 	/* Program source select*/
436*b843c749SSergey Zigachev 	/* Use HW default source select for FMT_MEMORYx_CONTROL */
437*b843c749SSergey Zigachev 	/* Use that value for FMT_SRC_SELECT as well*/
438*b843c749SSergey Zigachev 	REG_GET(CONTROL,
439*b843c749SSergey Zigachev 			FMT420_MEM0_SOURCE_SEL, &fmt_mem_cntl_value);
440*b843c749SSergey Zigachev 
441*b843c749SSergey Zigachev 	REG_UPDATE(FMT_CONTROL,
442*b843c749SSergey Zigachev 			FMT_SRC_SELECT, fmt_mem_cntl_value);
443*b843c749SSergey Zigachev 
444*b843c749SSergey Zigachev 	/* Turn on the memory */
445*b843c749SSergey Zigachev 	REG_UPDATE(CONTROL,
446*b843c749SSergey Zigachev 			FMT420_MEM0_PWR_FORCE, 0);
447*b843c749SSergey Zigachev }
448*b843c749SSergey Zigachev 
dce110_opp_set_dyn_expansion(struct output_pixel_processor * opp,enum dc_color_space color_sp,enum dc_color_depth color_dpth,enum signal_type signal)449*b843c749SSergey Zigachev void dce110_opp_set_dyn_expansion(
450*b843c749SSergey Zigachev 	struct output_pixel_processor *opp,
451*b843c749SSergey Zigachev 	enum dc_color_space color_sp,
452*b843c749SSergey Zigachev 	enum dc_color_depth color_dpth,
453*b843c749SSergey Zigachev 	enum signal_type signal)
454*b843c749SSergey Zigachev {
455*b843c749SSergey Zigachev 	struct dce110_opp *opp110 = TO_DCE110_OPP(opp);
456*b843c749SSergey Zigachev 
457*b843c749SSergey Zigachev 	REG_UPDATE_2(FMT_DYNAMIC_EXP_CNTL,
458*b843c749SSergey Zigachev 			FMT_DYNAMIC_EXP_EN, 0,
459*b843c749SSergey Zigachev 			FMT_DYNAMIC_EXP_MODE, 0);
460*b843c749SSergey Zigachev 
461*b843c749SSergey Zigachev 	/*00 - 10-bit -> 12-bit dynamic expansion*/
462*b843c749SSergey Zigachev 	/*01 - 8-bit  -> 12-bit dynamic expansion*/
463*b843c749SSergey Zigachev 	if (signal == SIGNAL_TYPE_HDMI_TYPE_A ||
464*b843c749SSergey Zigachev 		signal == SIGNAL_TYPE_DISPLAY_PORT ||
465*b843c749SSergey Zigachev 		signal == SIGNAL_TYPE_DISPLAY_PORT_MST) {
466*b843c749SSergey Zigachev 		switch (color_dpth) {
467*b843c749SSergey Zigachev 		case COLOR_DEPTH_888:
468*b843c749SSergey Zigachev 			REG_UPDATE_2(FMT_DYNAMIC_EXP_CNTL,
469*b843c749SSergey Zigachev 				FMT_DYNAMIC_EXP_EN, 1,
470*b843c749SSergey Zigachev 				FMT_DYNAMIC_EXP_MODE, 1);
471*b843c749SSergey Zigachev 			break;
472*b843c749SSergey Zigachev 		case COLOR_DEPTH_101010:
473*b843c749SSergey Zigachev 			REG_UPDATE_2(FMT_DYNAMIC_EXP_CNTL,
474*b843c749SSergey Zigachev 				FMT_DYNAMIC_EXP_EN, 1,
475*b843c749SSergey Zigachev 				FMT_DYNAMIC_EXP_MODE, 0);
476*b843c749SSergey Zigachev 			break;
477*b843c749SSergey Zigachev 		case COLOR_DEPTH_121212:
478*b843c749SSergey Zigachev 			REG_UPDATE_2(
479*b843c749SSergey Zigachev 				FMT_DYNAMIC_EXP_CNTL,
480*b843c749SSergey Zigachev 				FMT_DYNAMIC_EXP_EN, 1,/*otherwise last two bits are zero*/
481*b843c749SSergey Zigachev 				FMT_DYNAMIC_EXP_MODE, 0);
482*b843c749SSergey Zigachev 			break;
483*b843c749SSergey Zigachev 		default:
484*b843c749SSergey Zigachev 			break;
485*b843c749SSergey Zigachev 		}
486*b843c749SSergey Zigachev 	}
487*b843c749SSergey Zigachev }
488*b843c749SSergey Zigachev 
program_formatter_reset_dig_resync_fifo(struct output_pixel_processor * opp)489*b843c749SSergey Zigachev static void program_formatter_reset_dig_resync_fifo(struct output_pixel_processor *opp)
490*b843c749SSergey Zigachev {
491*b843c749SSergey Zigachev 	struct dce110_opp *opp110 = TO_DCE110_OPP(opp);
492*b843c749SSergey Zigachev 
493*b843c749SSergey Zigachev 	/* clear previous phase lock status*/
494*b843c749SSergey Zigachev 	REG_UPDATE(FMT_CONTROL,
495*b843c749SSergey Zigachev 			FMT_420_PIXEL_PHASE_LOCKED_CLEAR, 1);
496*b843c749SSergey Zigachev 
497*b843c749SSergey Zigachev 	/* poll until FMT_420_PIXEL_PHASE_LOCKED become 1*/
498*b843c749SSergey Zigachev 	REG_WAIT(FMT_CONTROL, FMT_420_PIXEL_PHASE_LOCKED, 1, 10, 10);
499*b843c749SSergey Zigachev 
500*b843c749SSergey Zigachev }
501*b843c749SSergey Zigachev 
dce110_opp_program_fmt(struct output_pixel_processor * opp,struct bit_depth_reduction_params * fmt_bit_depth,struct clamping_and_pixel_encoding_params * clamping)502*b843c749SSergey Zigachev void dce110_opp_program_fmt(
503*b843c749SSergey Zigachev 	struct output_pixel_processor *opp,
504*b843c749SSergey Zigachev 	struct bit_depth_reduction_params *fmt_bit_depth,
505*b843c749SSergey Zigachev 	struct clamping_and_pixel_encoding_params *clamping)
506*b843c749SSergey Zigachev {
507*b843c749SSergey Zigachev 	/* dithering is affected by <CrtcSourceSelect>, hence should be
508*b843c749SSergey Zigachev 	 * programmed afterwards */
509*b843c749SSergey Zigachev 
510*b843c749SSergey Zigachev 	if (clamping->pixel_encoding == PIXEL_ENCODING_YCBCR420)
511*b843c749SSergey Zigachev 		program_formatter_420_memory(opp);
512*b843c749SSergey Zigachev 
513*b843c749SSergey Zigachev 	dce110_opp_program_bit_depth_reduction(
514*b843c749SSergey Zigachev 		opp,
515*b843c749SSergey Zigachev 		fmt_bit_depth);
516*b843c749SSergey Zigachev 
517*b843c749SSergey Zigachev 	dce110_opp_program_clamping_and_pixel_encoding(
518*b843c749SSergey Zigachev 		opp,
519*b843c749SSergey Zigachev 		clamping);
520*b843c749SSergey Zigachev 
521*b843c749SSergey Zigachev 	if (clamping->pixel_encoding == PIXEL_ENCODING_YCBCR420)
522*b843c749SSergey Zigachev 		program_formatter_reset_dig_resync_fifo(opp);
523*b843c749SSergey Zigachev 
524*b843c749SSergey Zigachev 	return;
525*b843c749SSergey Zigachev }
526*b843c749SSergey Zigachev 
527*b843c749SSergey Zigachev 
528*b843c749SSergey Zigachev 
529*b843c749SSergey Zigachev 
530*b843c749SSergey Zigachev 
531*b843c749SSergey Zigachev /*****************************************/
532*b843c749SSergey Zigachev /* Constructor, Destructor               */
533*b843c749SSergey Zigachev /*****************************************/
534*b843c749SSergey Zigachev 
535*b843c749SSergey Zigachev static const struct opp_funcs funcs = {
536*b843c749SSergey Zigachev 	.opp_set_dyn_expansion = dce110_opp_set_dyn_expansion,
537*b843c749SSergey Zigachev 	.opp_destroy = dce110_opp_destroy,
538*b843c749SSergey Zigachev 	.opp_program_fmt = dce110_opp_program_fmt,
539*b843c749SSergey Zigachev 	.opp_program_bit_depth_reduction = dce110_opp_program_bit_depth_reduction
540*b843c749SSergey Zigachev };
541*b843c749SSergey Zigachev 
dce110_opp_construct(struct dce110_opp * opp110,struct dc_context * ctx,uint32_t inst,const struct dce_opp_registers * regs,const struct dce_opp_shift * opp_shift,const struct dce_opp_mask * opp_mask)542*b843c749SSergey Zigachev void dce110_opp_construct(struct dce110_opp *opp110,
543*b843c749SSergey Zigachev 	struct dc_context *ctx,
544*b843c749SSergey Zigachev 	uint32_t inst,
545*b843c749SSergey Zigachev 	const struct dce_opp_registers *regs,
546*b843c749SSergey Zigachev 	const struct dce_opp_shift *opp_shift,
547*b843c749SSergey Zigachev 	const struct dce_opp_mask *opp_mask)
548*b843c749SSergey Zigachev {
549*b843c749SSergey Zigachev 	opp110->base.funcs = &funcs;
550*b843c749SSergey Zigachev 
551*b843c749SSergey Zigachev 	opp110->base.ctx = ctx;
552*b843c749SSergey Zigachev 
553*b843c749SSergey Zigachev 	opp110->base.inst = inst;
554*b843c749SSergey Zigachev 
555*b843c749SSergey Zigachev 	opp110->regs = regs;
556*b843c749SSergey Zigachev 	opp110->opp_shift = opp_shift;
557*b843c749SSergey Zigachev 	opp110->opp_mask = opp_mask;
558*b843c749SSergey Zigachev }
559*b843c749SSergey Zigachev 
dce110_opp_destroy(struct output_pixel_processor ** opp)560*b843c749SSergey Zigachev void dce110_opp_destroy(struct output_pixel_processor **opp)
561*b843c749SSergey Zigachev {
562*b843c749SSergey Zigachev 	if (*opp)
563*b843c749SSergey Zigachev 		kfree(FROM_DCE11_OPP(*opp));
564*b843c749SSergey Zigachev 	*opp = NULL;
565*b843c749SSergey Zigachev }
566*b843c749SSergey Zigachev 
567