xref: /dflybsd-src/sys/dev/drm/amd/display/dc/dce/dce_transform.c (revision b843c749addef9340ee7d4e250b09fdd492602a1)
1*b843c749SSergey Zigachev /*
2*b843c749SSergey Zigachev  * Copyright 2012-16 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 "dce_transform.h"
27*b843c749SSergey Zigachev #include "reg_helper.h"
28*b843c749SSergey Zigachev #include "opp.h"
29*b843c749SSergey Zigachev #include "basics/conversion.h"
30*b843c749SSergey Zigachev #include "dc.h"
31*b843c749SSergey Zigachev 
32*b843c749SSergey Zigachev #define REG(reg) \
33*b843c749SSergey Zigachev 	(xfm_dce->regs->reg)
34*b843c749SSergey Zigachev 
35*b843c749SSergey Zigachev #undef FN
36*b843c749SSergey Zigachev #define FN(reg_name, field_name) \
37*b843c749SSergey Zigachev 	xfm_dce->xfm_shift->field_name, xfm_dce->xfm_mask->field_name
38*b843c749SSergey Zigachev 
39*b843c749SSergey Zigachev #define CTX \
40*b843c749SSergey Zigachev 	xfm_dce->base.ctx
41*b843c749SSergey Zigachev #define DC_LOGGER \
42*b843c749SSergey Zigachev 	xfm_dce->base.ctx->logger
43*b843c749SSergey Zigachev 
44*b843c749SSergey Zigachev #define IDENTITY_RATIO(ratio) (dc_fixpt_u2d19(ratio) == (1 << 19))
45*b843c749SSergey Zigachev #define GAMUT_MATRIX_SIZE 12
46*b843c749SSergey Zigachev #define SCL_PHASES 16
47*b843c749SSergey Zigachev 
48*b843c749SSergey Zigachev enum dcp_out_trunc_round_mode {
49*b843c749SSergey Zigachev 	DCP_OUT_TRUNC_ROUND_MODE_TRUNCATE,
50*b843c749SSergey Zigachev 	DCP_OUT_TRUNC_ROUND_MODE_ROUND
51*b843c749SSergey Zigachev };
52*b843c749SSergey Zigachev 
53*b843c749SSergey Zigachev enum dcp_out_trunc_round_depth {
54*b843c749SSergey Zigachev 	DCP_OUT_TRUNC_ROUND_DEPTH_14BIT,
55*b843c749SSergey Zigachev 	DCP_OUT_TRUNC_ROUND_DEPTH_13BIT,
56*b843c749SSergey Zigachev 	DCP_OUT_TRUNC_ROUND_DEPTH_12BIT,
57*b843c749SSergey Zigachev 	DCP_OUT_TRUNC_ROUND_DEPTH_11BIT,
58*b843c749SSergey Zigachev 	DCP_OUT_TRUNC_ROUND_DEPTH_10BIT,
59*b843c749SSergey Zigachev 	DCP_OUT_TRUNC_ROUND_DEPTH_9BIT,
60*b843c749SSergey Zigachev 	DCP_OUT_TRUNC_ROUND_DEPTH_8BIT
61*b843c749SSergey Zigachev };
62*b843c749SSergey Zigachev 
63*b843c749SSergey Zigachev /*  defines the various methods of bit reduction available for use */
64*b843c749SSergey Zigachev enum dcp_bit_depth_reduction_mode {
65*b843c749SSergey Zigachev 	DCP_BIT_DEPTH_REDUCTION_MODE_DITHER,
66*b843c749SSergey Zigachev 	DCP_BIT_DEPTH_REDUCTION_MODE_ROUND,
67*b843c749SSergey Zigachev 	DCP_BIT_DEPTH_REDUCTION_MODE_TRUNCATE,
68*b843c749SSergey Zigachev 	DCP_BIT_DEPTH_REDUCTION_MODE_DISABLED,
69*b843c749SSergey Zigachev 	DCP_BIT_DEPTH_REDUCTION_MODE_INVALID
70*b843c749SSergey Zigachev };
71*b843c749SSergey Zigachev 
72*b843c749SSergey Zigachev enum dcp_spatial_dither_mode {
73*b843c749SSergey Zigachev 	DCP_SPATIAL_DITHER_MODE_AAAA,
74*b843c749SSergey Zigachev 	DCP_SPATIAL_DITHER_MODE_A_AA_A,
75*b843c749SSergey Zigachev 	DCP_SPATIAL_DITHER_MODE_AABBAABB,
76*b843c749SSergey Zigachev 	DCP_SPATIAL_DITHER_MODE_AABBCCAABBCC,
77*b843c749SSergey Zigachev 	DCP_SPATIAL_DITHER_MODE_INVALID
78*b843c749SSergey Zigachev };
79*b843c749SSergey Zigachev 
80*b843c749SSergey Zigachev enum dcp_spatial_dither_depth {
81*b843c749SSergey Zigachev 	DCP_SPATIAL_DITHER_DEPTH_30BPP,
82*b843c749SSergey Zigachev 	DCP_SPATIAL_DITHER_DEPTH_24BPP
83*b843c749SSergey Zigachev };
84*b843c749SSergey Zigachev 
85*b843c749SSergey Zigachev enum csc_color_mode {
86*b843c749SSergey Zigachev 	/* 00 - BITS2:0 Bypass */
87*b843c749SSergey Zigachev 	CSC_COLOR_MODE_GRAPHICS_BYPASS,
88*b843c749SSergey Zigachev 	/* 01 - hard coded coefficient TV RGB */
89*b843c749SSergey Zigachev 	CSC_COLOR_MODE_GRAPHICS_PREDEFINED,
90*b843c749SSergey Zigachev 	/* 04 - programmable OUTPUT CSC coefficient */
91*b843c749SSergey Zigachev 	CSC_COLOR_MODE_GRAPHICS_OUTPUT_CSC,
92*b843c749SSergey Zigachev };
93*b843c749SSergey Zigachev 
94*b843c749SSergey Zigachev enum grph_color_adjust_option {
95*b843c749SSergey Zigachev 	GRPH_COLOR_MATRIX_HW_DEFAULT = 1,
96*b843c749SSergey Zigachev 	GRPH_COLOR_MATRIX_SW
97*b843c749SSergey Zigachev };
98*b843c749SSergey Zigachev 
99*b843c749SSergey Zigachev static const struct out_csc_color_matrix global_color_matrix[] = {
100*b843c749SSergey Zigachev { COLOR_SPACE_SRGB,
101*b843c749SSergey Zigachev 	{ 0x2000, 0, 0, 0, 0, 0x2000, 0, 0, 0, 0, 0x2000, 0} },
102*b843c749SSergey Zigachev { COLOR_SPACE_SRGB_LIMITED,
103*b843c749SSergey Zigachev 	{ 0x1B60, 0, 0, 0x200, 0, 0x1B60, 0, 0x200, 0, 0, 0x1B60, 0x200} },
104*b843c749SSergey Zigachev { COLOR_SPACE_YCBCR601,
105*b843c749SSergey Zigachev 	{ 0xE00, 0xF447, 0xFDB9, 0x1000, 0x82F, 0x1012, 0x31F, 0x200, 0xFB47,
106*b843c749SSergey Zigachev 		0xF6B9, 0xE00, 0x1000} },
107*b843c749SSergey Zigachev { COLOR_SPACE_YCBCR709, { 0xE00, 0xF349, 0xFEB7, 0x1000, 0x5D2, 0x1394, 0x1FA,
108*b843c749SSergey Zigachev 	0x200, 0xFCCB, 0xF535, 0xE00, 0x1000} },
109*b843c749SSergey Zigachev /* TODO: correct values below */
110*b843c749SSergey Zigachev { COLOR_SPACE_YCBCR601_LIMITED, { 0xE00, 0xF447, 0xFDB9, 0x1000, 0x991,
111*b843c749SSergey Zigachev 	0x12C9, 0x3A6, 0x200, 0xFB47, 0xF6B9, 0xE00, 0x1000} },
112*b843c749SSergey Zigachev { COLOR_SPACE_YCBCR709_LIMITED, { 0xE00, 0xF349, 0xFEB7, 0x1000, 0x6CE, 0x16E3,
113*b843c749SSergey Zigachev 	0x24F, 0x200, 0xFCCB, 0xF535, 0xE00, 0x1000} }
114*b843c749SSergey Zigachev };
115*b843c749SSergey Zigachev 
setup_scaling_configuration(struct dce_transform * xfm_dce,const struct scaler_data * data)116*b843c749SSergey Zigachev static bool setup_scaling_configuration(
117*b843c749SSergey Zigachev 	struct dce_transform *xfm_dce,
118*b843c749SSergey Zigachev 	const struct scaler_data *data)
119*b843c749SSergey Zigachev {
120*b843c749SSergey Zigachev 	REG_SET(SCL_BYPASS_CONTROL, 0, SCL_BYPASS_MODE, 0);
121*b843c749SSergey Zigachev 
122*b843c749SSergey Zigachev 	if (data->taps.h_taps + data->taps.v_taps <= 2) {
123*b843c749SSergey Zigachev 		/* Set bypass */
124*b843c749SSergey Zigachev 		if (xfm_dce->xfm_mask->SCL_PSCL_EN != 0)
125*b843c749SSergey Zigachev 			REG_UPDATE_2(SCL_MODE, SCL_MODE, 0, SCL_PSCL_EN, 0);
126*b843c749SSergey Zigachev 		else
127*b843c749SSergey Zigachev 			REG_UPDATE(SCL_MODE, SCL_MODE, 0);
128*b843c749SSergey Zigachev 		return false;
129*b843c749SSergey Zigachev 	}
130*b843c749SSergey Zigachev 
131*b843c749SSergey Zigachev 	REG_SET_2(SCL_TAP_CONTROL, 0,
132*b843c749SSergey Zigachev 			SCL_H_NUM_OF_TAPS, data->taps.h_taps - 1,
133*b843c749SSergey Zigachev 			SCL_V_NUM_OF_TAPS, data->taps.v_taps - 1);
134*b843c749SSergey Zigachev 
135*b843c749SSergey Zigachev 	if (data->format <= PIXEL_FORMAT_GRPH_END)
136*b843c749SSergey Zigachev 		REG_UPDATE(SCL_MODE, SCL_MODE, 1);
137*b843c749SSergey Zigachev 	else
138*b843c749SSergey Zigachev 		REG_UPDATE(SCL_MODE, SCL_MODE, 2);
139*b843c749SSergey Zigachev 
140*b843c749SSergey Zigachev 	if (xfm_dce->xfm_mask->SCL_PSCL_EN != 0)
141*b843c749SSergey Zigachev 		REG_UPDATE(SCL_MODE, SCL_PSCL_EN, 1);
142*b843c749SSergey Zigachev 
143*b843c749SSergey Zigachev 	/* 1 - Replace out of bound pixels with edge */
144*b843c749SSergey Zigachev 	REG_SET(SCL_CONTROL, 0, SCL_BOUNDARY_MODE, 1);
145*b843c749SSergey Zigachev 
146*b843c749SSergey Zigachev 	return true;
147*b843c749SSergey Zigachev }
148*b843c749SSergey Zigachev 
program_overscan(struct dce_transform * xfm_dce,const struct scaler_data * data)149*b843c749SSergey Zigachev static void program_overscan(
150*b843c749SSergey Zigachev 		struct dce_transform *xfm_dce,
151*b843c749SSergey Zigachev 		const struct scaler_data *data)
152*b843c749SSergey Zigachev {
153*b843c749SSergey Zigachev 	int overscan_right = data->h_active
154*b843c749SSergey Zigachev 			- data->recout.x - data->recout.width;
155*b843c749SSergey Zigachev 	int overscan_bottom = data->v_active
156*b843c749SSergey Zigachev 			- data->recout.y - data->recout.height;
157*b843c749SSergey Zigachev 
158*b843c749SSergey Zigachev 	if (xfm_dce->base.ctx->dc->debug.visual_confirm != VISUAL_CONFIRM_DISABLE) {
159*b843c749SSergey Zigachev 		overscan_bottom += 2;
160*b843c749SSergey Zigachev 		overscan_right += 2;
161*b843c749SSergey Zigachev 	}
162*b843c749SSergey Zigachev 
163*b843c749SSergey Zigachev 	if (overscan_right < 0) {
164*b843c749SSergey Zigachev 		BREAK_TO_DEBUGGER();
165*b843c749SSergey Zigachev 		overscan_right = 0;
166*b843c749SSergey Zigachev 	}
167*b843c749SSergey Zigachev 	if (overscan_bottom < 0) {
168*b843c749SSergey Zigachev 		BREAK_TO_DEBUGGER();
169*b843c749SSergey Zigachev 		overscan_bottom = 0;
170*b843c749SSergey Zigachev 	}
171*b843c749SSergey Zigachev 
172*b843c749SSergey Zigachev 	REG_SET_2(EXT_OVERSCAN_LEFT_RIGHT, 0,
173*b843c749SSergey Zigachev 			EXT_OVERSCAN_LEFT, data->recout.x,
174*b843c749SSergey Zigachev 			EXT_OVERSCAN_RIGHT, overscan_right);
175*b843c749SSergey Zigachev 	REG_SET_2(EXT_OVERSCAN_TOP_BOTTOM, 0,
176*b843c749SSergey Zigachev 			EXT_OVERSCAN_TOP, data->recout.y,
177*b843c749SSergey Zigachev 			EXT_OVERSCAN_BOTTOM, overscan_bottom);
178*b843c749SSergey Zigachev }
179*b843c749SSergey Zigachev 
program_multi_taps_filter(struct dce_transform * xfm_dce,int taps,const uint16_t * coeffs,enum ram_filter_type filter_type)180*b843c749SSergey Zigachev static void program_multi_taps_filter(
181*b843c749SSergey Zigachev 	struct dce_transform *xfm_dce,
182*b843c749SSergey Zigachev 	int taps,
183*b843c749SSergey Zigachev 	const uint16_t *coeffs,
184*b843c749SSergey Zigachev 	enum ram_filter_type filter_type)
185*b843c749SSergey Zigachev {
186*b843c749SSergey Zigachev 	int phase, pair;
187*b843c749SSergey Zigachev 	int array_idx = 0;
188*b843c749SSergey Zigachev 	int taps_pairs = (taps + 1) / 2;
189*b843c749SSergey Zigachev 	int phases_to_program = SCL_PHASES / 2 + 1;
190*b843c749SSergey Zigachev 
191*b843c749SSergey Zigachev 	uint32_t power_ctl = 0;
192*b843c749SSergey Zigachev 
193*b843c749SSergey Zigachev 	if (!coeffs)
194*b843c749SSergey Zigachev 		return;
195*b843c749SSergey Zigachev 
196*b843c749SSergey Zigachev 	/*We need to disable power gating on coeff memory to do programming*/
197*b843c749SSergey Zigachev 	if (REG(DCFE_MEM_PWR_CTRL)) {
198*b843c749SSergey Zigachev 		power_ctl = REG_READ(DCFE_MEM_PWR_CTRL);
199*b843c749SSergey Zigachev 		REG_SET(DCFE_MEM_PWR_CTRL, power_ctl, SCL_COEFF_MEM_PWR_DIS, 1);
200*b843c749SSergey Zigachev 
201*b843c749SSergey Zigachev 		REG_WAIT(DCFE_MEM_PWR_STATUS, SCL_COEFF_MEM_PWR_STATE, 0, 1, 10);
202*b843c749SSergey Zigachev 	}
203*b843c749SSergey Zigachev 	for (phase = 0; phase < phases_to_program; phase++) {
204*b843c749SSergey Zigachev 		/*we always program N/2 + 1 phases, total phases N, but N/2-1 are just mirror
205*b843c749SSergey Zigachev 		phase 0 is unique and phase N/2 is unique if N is even*/
206*b843c749SSergey Zigachev 		for (pair = 0; pair < taps_pairs; pair++) {
207*b843c749SSergey Zigachev 			uint16_t odd_coeff = 0;
208*b843c749SSergey Zigachev 			uint16_t even_coeff = coeffs[array_idx];
209*b843c749SSergey Zigachev 
210*b843c749SSergey Zigachev 			REG_SET_3(SCL_COEF_RAM_SELECT, 0,
211*b843c749SSergey Zigachev 					SCL_C_RAM_FILTER_TYPE, filter_type,
212*b843c749SSergey Zigachev 					SCL_C_RAM_PHASE, phase,
213*b843c749SSergey Zigachev 					SCL_C_RAM_TAP_PAIR_IDX, pair);
214*b843c749SSergey Zigachev 
215*b843c749SSergey Zigachev 			if (taps % 2 && pair == taps_pairs - 1)
216*b843c749SSergey Zigachev 				array_idx++;
217*b843c749SSergey Zigachev 			else {
218*b843c749SSergey Zigachev 				odd_coeff = coeffs[array_idx + 1];
219*b843c749SSergey Zigachev 				array_idx += 2;
220*b843c749SSergey Zigachev 			}
221*b843c749SSergey Zigachev 
222*b843c749SSergey Zigachev 			REG_SET_4(SCL_COEF_RAM_TAP_DATA, 0,
223*b843c749SSergey Zigachev 					SCL_C_RAM_EVEN_TAP_COEF_EN, 1,
224*b843c749SSergey Zigachev 					SCL_C_RAM_EVEN_TAP_COEF, even_coeff,
225*b843c749SSergey Zigachev 					SCL_C_RAM_ODD_TAP_COEF_EN, 1,
226*b843c749SSergey Zigachev 					SCL_C_RAM_ODD_TAP_COEF, odd_coeff);
227*b843c749SSergey Zigachev 		}
228*b843c749SSergey Zigachev 	}
229*b843c749SSergey Zigachev 
230*b843c749SSergey Zigachev 	/*We need to restore power gating on coeff memory to initial state*/
231*b843c749SSergey Zigachev 	if (REG(DCFE_MEM_PWR_CTRL))
232*b843c749SSergey Zigachev 		REG_WRITE(DCFE_MEM_PWR_CTRL, power_ctl);
233*b843c749SSergey Zigachev }
234*b843c749SSergey Zigachev 
program_viewport(struct dce_transform * xfm_dce,const struct rect * view_port)235*b843c749SSergey Zigachev static void program_viewport(
236*b843c749SSergey Zigachev 	struct dce_transform *xfm_dce,
237*b843c749SSergey Zigachev 	const struct rect *view_port)
238*b843c749SSergey Zigachev {
239*b843c749SSergey Zigachev 	REG_SET_2(VIEWPORT_START, 0,
240*b843c749SSergey Zigachev 			VIEWPORT_X_START, view_port->x,
241*b843c749SSergey Zigachev 			VIEWPORT_Y_START, view_port->y);
242*b843c749SSergey Zigachev 
243*b843c749SSergey Zigachev 	REG_SET_2(VIEWPORT_SIZE, 0,
244*b843c749SSergey Zigachev 			VIEWPORT_HEIGHT, view_port->height,
245*b843c749SSergey Zigachev 			VIEWPORT_WIDTH, view_port->width);
246*b843c749SSergey Zigachev 
247*b843c749SSergey Zigachev 	/* TODO: add stereo support */
248*b843c749SSergey Zigachev }
249*b843c749SSergey Zigachev 
calculate_inits(struct dce_transform * xfm_dce,const struct scaler_data * data,struct scl_ratios_inits * inits)250*b843c749SSergey Zigachev static void calculate_inits(
251*b843c749SSergey Zigachev 	struct dce_transform *xfm_dce,
252*b843c749SSergey Zigachev 	const struct scaler_data *data,
253*b843c749SSergey Zigachev 	struct scl_ratios_inits *inits)
254*b843c749SSergey Zigachev {
255*b843c749SSergey Zigachev 	struct fixed31_32 h_init;
256*b843c749SSergey Zigachev 	struct fixed31_32 v_init;
257*b843c749SSergey Zigachev 
258*b843c749SSergey Zigachev 	inits->h_int_scale_ratio =
259*b843c749SSergey Zigachev 		dc_fixpt_u2d19(data->ratios.horz) << 5;
260*b843c749SSergey Zigachev 	inits->v_int_scale_ratio =
261*b843c749SSergey Zigachev 		dc_fixpt_u2d19(data->ratios.vert) << 5;
262*b843c749SSergey Zigachev 
263*b843c749SSergey Zigachev 	h_init =
264*b843c749SSergey Zigachev 		dc_fixpt_div_int(
265*b843c749SSergey Zigachev 			dc_fixpt_add(
266*b843c749SSergey Zigachev 				data->ratios.horz,
267*b843c749SSergey Zigachev 				dc_fixpt_from_int(data->taps.h_taps + 1)),
268*b843c749SSergey Zigachev 				2);
269*b843c749SSergey Zigachev 	inits->h_init.integer = dc_fixpt_floor(h_init);
270*b843c749SSergey Zigachev 	inits->h_init.fraction = dc_fixpt_u0d19(h_init) << 5;
271*b843c749SSergey Zigachev 
272*b843c749SSergey Zigachev 	v_init =
273*b843c749SSergey Zigachev 		dc_fixpt_div_int(
274*b843c749SSergey Zigachev 			dc_fixpt_add(
275*b843c749SSergey Zigachev 				data->ratios.vert,
276*b843c749SSergey Zigachev 				dc_fixpt_from_int(data->taps.v_taps + 1)),
277*b843c749SSergey Zigachev 				2);
278*b843c749SSergey Zigachev 	inits->v_init.integer = dc_fixpt_floor(v_init);
279*b843c749SSergey Zigachev 	inits->v_init.fraction = dc_fixpt_u0d19(v_init) << 5;
280*b843c749SSergey Zigachev }
281*b843c749SSergey Zigachev 
program_scl_ratios_inits(struct dce_transform * xfm_dce,struct scl_ratios_inits * inits)282*b843c749SSergey Zigachev static void program_scl_ratios_inits(
283*b843c749SSergey Zigachev 	struct dce_transform *xfm_dce,
284*b843c749SSergey Zigachev 	struct scl_ratios_inits *inits)
285*b843c749SSergey Zigachev {
286*b843c749SSergey Zigachev 
287*b843c749SSergey Zigachev 	REG_SET(SCL_HORZ_FILTER_SCALE_RATIO, 0,
288*b843c749SSergey Zigachev 			SCL_H_SCALE_RATIO, inits->h_int_scale_ratio);
289*b843c749SSergey Zigachev 
290*b843c749SSergey Zigachev 	REG_SET(SCL_VERT_FILTER_SCALE_RATIO, 0,
291*b843c749SSergey Zigachev 			SCL_V_SCALE_RATIO, inits->v_int_scale_ratio);
292*b843c749SSergey Zigachev 
293*b843c749SSergey Zigachev 	REG_SET_2(SCL_HORZ_FILTER_INIT, 0,
294*b843c749SSergey Zigachev 			SCL_H_INIT_INT, inits->h_init.integer,
295*b843c749SSergey Zigachev 			SCL_H_INIT_FRAC, inits->h_init.fraction);
296*b843c749SSergey Zigachev 
297*b843c749SSergey Zigachev 	REG_SET_2(SCL_VERT_FILTER_INIT, 0,
298*b843c749SSergey Zigachev 			SCL_V_INIT_INT, inits->v_init.integer,
299*b843c749SSergey Zigachev 			SCL_V_INIT_FRAC, inits->v_init.fraction);
300*b843c749SSergey Zigachev 
301*b843c749SSergey Zigachev 	REG_WRITE(SCL_AUTOMATIC_MODE_CONTROL, 0);
302*b843c749SSergey Zigachev }
303*b843c749SSergey Zigachev 
get_filter_coeffs_16p(int taps,struct fixed31_32 ratio)304*b843c749SSergey Zigachev static const uint16_t *get_filter_coeffs_16p(int taps, struct fixed31_32 ratio)
305*b843c749SSergey Zigachev {
306*b843c749SSergey Zigachev 	if (taps == 4)
307*b843c749SSergey Zigachev 		return get_filter_4tap_16p(ratio);
308*b843c749SSergey Zigachev 	else if (taps == 3)
309*b843c749SSergey Zigachev 		return get_filter_3tap_16p(ratio);
310*b843c749SSergey Zigachev 	else if (taps == 2)
311*b843c749SSergey Zigachev 		return get_filter_2tap_16p();
312*b843c749SSergey Zigachev 	else if (taps == 1)
313*b843c749SSergey Zigachev 		return NULL;
314*b843c749SSergey Zigachev 	else {
315*b843c749SSergey Zigachev 		/* should never happen, bug */
316*b843c749SSergey Zigachev 		BREAK_TO_DEBUGGER();
317*b843c749SSergey Zigachev 		return NULL;
318*b843c749SSergey Zigachev 	}
319*b843c749SSergey Zigachev }
320*b843c749SSergey Zigachev 
dce_transform_set_scaler(struct transform * xfm,const struct scaler_data * data)321*b843c749SSergey Zigachev static void dce_transform_set_scaler(
322*b843c749SSergey Zigachev 	struct transform *xfm,
323*b843c749SSergey Zigachev 	const struct scaler_data *data)
324*b843c749SSergey Zigachev {
325*b843c749SSergey Zigachev 	struct dce_transform *xfm_dce = TO_DCE_TRANSFORM(xfm);
326*b843c749SSergey Zigachev 	bool is_scaling_required;
327*b843c749SSergey Zigachev 	bool filter_updated = false;
328*b843c749SSergey Zigachev 	const uint16_t *coeffs_v, *coeffs_h;
329*b843c749SSergey Zigachev 
330*b843c749SSergey Zigachev 	/*Use all three pieces of memory always*/
331*b843c749SSergey Zigachev 	REG_SET_2(LB_MEMORY_CTRL, 0,
332*b843c749SSergey Zigachev 			LB_MEMORY_CONFIG, 0,
333*b843c749SSergey Zigachev 			LB_MEMORY_SIZE, xfm_dce->lb_memory_size);
334*b843c749SSergey Zigachev 
335*b843c749SSergey Zigachev 	/* Clear SCL_F_SHARP_CONTROL value to 0 */
336*b843c749SSergey Zigachev 	REG_WRITE(SCL_F_SHARP_CONTROL, 0);
337*b843c749SSergey Zigachev 
338*b843c749SSergey Zigachev 	/* 1. Program overscan */
339*b843c749SSergey Zigachev 	program_overscan(xfm_dce, data);
340*b843c749SSergey Zigachev 
341*b843c749SSergey Zigachev 	/* 2. Program taps and configuration */
342*b843c749SSergey Zigachev 	is_scaling_required = setup_scaling_configuration(xfm_dce, data);
343*b843c749SSergey Zigachev 
344*b843c749SSergey Zigachev 	if (is_scaling_required) {
345*b843c749SSergey Zigachev 		/* 3. Calculate and program ratio, filter initialization */
346*b843c749SSergey Zigachev 		struct scl_ratios_inits inits = { 0 };
347*b843c749SSergey Zigachev 
348*b843c749SSergey Zigachev 		calculate_inits(xfm_dce, data, &inits);
349*b843c749SSergey Zigachev 
350*b843c749SSergey Zigachev 		program_scl_ratios_inits(xfm_dce, &inits);
351*b843c749SSergey Zigachev 
352*b843c749SSergey Zigachev 		coeffs_v = get_filter_coeffs_16p(data->taps.v_taps, data->ratios.vert);
353*b843c749SSergey Zigachev 		coeffs_h = get_filter_coeffs_16p(data->taps.h_taps, data->ratios.horz);
354*b843c749SSergey Zigachev 
355*b843c749SSergey Zigachev 		if (coeffs_v != xfm_dce->filter_v || coeffs_h != xfm_dce->filter_h) {
356*b843c749SSergey Zigachev 			/* 4. Program vertical filters */
357*b843c749SSergey Zigachev 			if (xfm_dce->filter_v == NULL)
358*b843c749SSergey Zigachev 				REG_SET(SCL_VERT_FILTER_CONTROL, 0,
359*b843c749SSergey Zigachev 						SCL_V_2TAP_HARDCODE_COEF_EN, 0);
360*b843c749SSergey Zigachev 			program_multi_taps_filter(
361*b843c749SSergey Zigachev 					xfm_dce,
362*b843c749SSergey Zigachev 					data->taps.v_taps,
363*b843c749SSergey Zigachev 					coeffs_v,
364*b843c749SSergey Zigachev 					FILTER_TYPE_RGB_Y_VERTICAL);
365*b843c749SSergey Zigachev 			program_multi_taps_filter(
366*b843c749SSergey Zigachev 					xfm_dce,
367*b843c749SSergey Zigachev 					data->taps.v_taps,
368*b843c749SSergey Zigachev 					coeffs_v,
369*b843c749SSergey Zigachev 					FILTER_TYPE_ALPHA_VERTICAL);
370*b843c749SSergey Zigachev 
371*b843c749SSergey Zigachev 			/* 5. Program horizontal filters */
372*b843c749SSergey Zigachev 			if (xfm_dce->filter_h == NULL)
373*b843c749SSergey Zigachev 				REG_SET(SCL_HORZ_FILTER_CONTROL, 0,
374*b843c749SSergey Zigachev 						SCL_H_2TAP_HARDCODE_COEF_EN, 0);
375*b843c749SSergey Zigachev 			program_multi_taps_filter(
376*b843c749SSergey Zigachev 					xfm_dce,
377*b843c749SSergey Zigachev 					data->taps.h_taps,
378*b843c749SSergey Zigachev 					coeffs_h,
379*b843c749SSergey Zigachev 					FILTER_TYPE_RGB_Y_HORIZONTAL);
380*b843c749SSergey Zigachev 			program_multi_taps_filter(
381*b843c749SSergey Zigachev 					xfm_dce,
382*b843c749SSergey Zigachev 					data->taps.h_taps,
383*b843c749SSergey Zigachev 					coeffs_h,
384*b843c749SSergey Zigachev 					FILTER_TYPE_ALPHA_HORIZONTAL);
385*b843c749SSergey Zigachev 
386*b843c749SSergey Zigachev 			xfm_dce->filter_v = coeffs_v;
387*b843c749SSergey Zigachev 			xfm_dce->filter_h = coeffs_h;
388*b843c749SSergey Zigachev 			filter_updated = true;
389*b843c749SSergey Zigachev 		}
390*b843c749SSergey Zigachev 	}
391*b843c749SSergey Zigachev 
392*b843c749SSergey Zigachev 	/* 6. Program the viewport */
393*b843c749SSergey Zigachev 	program_viewport(xfm_dce, &data->viewport);
394*b843c749SSergey Zigachev 
395*b843c749SSergey Zigachev 	/* 7. Set bit to flip to new coefficient memory */
396*b843c749SSergey Zigachev 	if (filter_updated)
397*b843c749SSergey Zigachev 		REG_UPDATE(SCL_UPDATE, SCL_COEF_UPDATE_COMPLETE, 1);
398*b843c749SSergey Zigachev 
399*b843c749SSergey Zigachev 	REG_UPDATE(LB_DATA_FORMAT, ALPHA_EN, data->lb_params.alpha_en);
400*b843c749SSergey Zigachev }
401*b843c749SSergey Zigachev 
402*b843c749SSergey Zigachev /*****************************************************************************
403*b843c749SSergey Zigachev  * set_clamp
404*b843c749SSergey Zigachev  *
405*b843c749SSergey Zigachev  * @param depth : bit depth to set the clamp to (should match denorm)
406*b843c749SSergey Zigachev  *
407*b843c749SSergey Zigachev  * @brief
408*b843c749SSergey Zigachev  *     Programs clamp according to panel bit depth.
409*b843c749SSergey Zigachev  *
410*b843c749SSergey Zigachev  *******************************************************************************/
set_clamp(struct dce_transform * xfm_dce,enum dc_color_depth depth)411*b843c749SSergey Zigachev static void set_clamp(
412*b843c749SSergey Zigachev 	struct dce_transform *xfm_dce,
413*b843c749SSergey Zigachev 	enum dc_color_depth depth)
414*b843c749SSergey Zigachev {
415*b843c749SSergey Zigachev 	int clamp_max = 0;
416*b843c749SSergey Zigachev 
417*b843c749SSergey Zigachev 	/* At the clamp block the data will be MSB aligned, so we set the max
418*b843c749SSergey Zigachev 	 * clamp accordingly.
419*b843c749SSergey Zigachev 	 * For example, the max value for 6 bits MSB aligned (14 bit bus) would
420*b843c749SSergey Zigachev 	 * be "11 1111 0000 0000" in binary, so 0x3F00.
421*b843c749SSergey Zigachev 	 */
422*b843c749SSergey Zigachev 	switch (depth) {
423*b843c749SSergey Zigachev 	case COLOR_DEPTH_666:
424*b843c749SSergey Zigachev 		/* 6bit MSB aligned on 14 bit bus '11 1111 0000 0000' */
425*b843c749SSergey Zigachev 		clamp_max = 0x3F00;
426*b843c749SSergey Zigachev 		break;
427*b843c749SSergey Zigachev 	case COLOR_DEPTH_888:
428*b843c749SSergey Zigachev 		/* 8bit MSB aligned on 14 bit bus '11 1111 1100 0000' */
429*b843c749SSergey Zigachev 		clamp_max = 0x3FC0;
430*b843c749SSergey Zigachev 		break;
431*b843c749SSergey Zigachev 	case COLOR_DEPTH_101010:
432*b843c749SSergey Zigachev 		/* 10bit MSB aligned on 14 bit bus '11 1111 1111 0000' */
433*b843c749SSergey Zigachev 		clamp_max = 0x3FF0;
434*b843c749SSergey Zigachev 		break;
435*b843c749SSergey Zigachev 	case COLOR_DEPTH_121212:
436*b843c749SSergey Zigachev 		/* 12bit MSB aligned on 14 bit bus '11 1111 1111 1100' */
437*b843c749SSergey Zigachev 		clamp_max = 0x3FFC;
438*b843c749SSergey Zigachev 		break;
439*b843c749SSergey Zigachev 	default:
440*b843c749SSergey Zigachev 		clamp_max = 0x3FC0;
441*b843c749SSergey Zigachev 		BREAK_TO_DEBUGGER(); /* Invalid clamp bit depth */
442*b843c749SSergey Zigachev 	}
443*b843c749SSergey Zigachev 	REG_SET_2(OUT_CLAMP_CONTROL_B_CB, 0,
444*b843c749SSergey Zigachev 			OUT_CLAMP_MIN_B_CB, 0,
445*b843c749SSergey Zigachev 			OUT_CLAMP_MAX_B_CB, clamp_max);
446*b843c749SSergey Zigachev 
447*b843c749SSergey Zigachev 	REG_SET_2(OUT_CLAMP_CONTROL_G_Y, 0,
448*b843c749SSergey Zigachev 			OUT_CLAMP_MIN_G_Y, 0,
449*b843c749SSergey Zigachev 			OUT_CLAMP_MAX_G_Y, clamp_max);
450*b843c749SSergey Zigachev 
451*b843c749SSergey Zigachev 	REG_SET_2(OUT_CLAMP_CONTROL_R_CR, 0,
452*b843c749SSergey Zigachev 			OUT_CLAMP_MIN_R_CR, 0,
453*b843c749SSergey Zigachev 			OUT_CLAMP_MAX_R_CR, clamp_max);
454*b843c749SSergey Zigachev }
455*b843c749SSergey Zigachev 
456*b843c749SSergey Zigachev /*******************************************************************************
457*b843c749SSergey Zigachev  * set_round
458*b843c749SSergey Zigachev  *
459*b843c749SSergey Zigachev  * @brief
460*b843c749SSergey Zigachev  *     Programs Round/Truncate
461*b843c749SSergey Zigachev  *
462*b843c749SSergey Zigachev  * @param [in] mode  :round or truncate
463*b843c749SSergey Zigachev  * @param [in] depth :bit depth to round/truncate to
464*b843c749SSergey Zigachev  OUT_ROUND_TRUNC_MODE 3:0 0xA Output data round or truncate mode
465*b843c749SSergey Zigachev  POSSIBLE VALUES:
466*b843c749SSergey Zigachev       00 - truncate to u0.12
467*b843c749SSergey Zigachev       01 - truncate to u0.11
468*b843c749SSergey Zigachev       02 - truncate to u0.10
469*b843c749SSergey Zigachev       03 - truncate to u0.9
470*b843c749SSergey Zigachev       04 - truncate to u0.8
471*b843c749SSergey Zigachev       05 - reserved
472*b843c749SSergey Zigachev       06 - truncate to u0.14
473*b843c749SSergey Zigachev       07 - truncate to u0.13		set_reg_field_value(
474*b843c749SSergey Zigachev 			value,
475*b843c749SSergey Zigachev 			clamp_max,
476*b843c749SSergey Zigachev 			OUT_CLAMP_CONTROL_R_CR,
477*b843c749SSergey Zigachev 			OUT_CLAMP_MAX_R_CR);
478*b843c749SSergey Zigachev       08 - round to u0.12
479*b843c749SSergey Zigachev       09 - round to u0.11
480*b843c749SSergey Zigachev       10 - round to u0.10
481*b843c749SSergey Zigachev       11 - round to u0.9
482*b843c749SSergey Zigachev       12 - round to u0.8
483*b843c749SSergey Zigachev       13 - reserved
484*b843c749SSergey Zigachev       14 - round to u0.14
485*b843c749SSergey Zigachev       15 - round to u0.13
486*b843c749SSergey Zigachev 
487*b843c749SSergey Zigachev  ******************************************************************************/
set_round(struct dce_transform * xfm_dce,enum dcp_out_trunc_round_mode mode,enum dcp_out_trunc_round_depth depth)488*b843c749SSergey Zigachev static void set_round(
489*b843c749SSergey Zigachev 	struct dce_transform *xfm_dce,
490*b843c749SSergey Zigachev 	enum dcp_out_trunc_round_mode mode,
491*b843c749SSergey Zigachev 	enum dcp_out_trunc_round_depth depth)
492*b843c749SSergey Zigachev {
493*b843c749SSergey Zigachev 	int depth_bits = 0;
494*b843c749SSergey Zigachev 	int mode_bit = 0;
495*b843c749SSergey Zigachev 
496*b843c749SSergey Zigachev 	/*  set up bit depth */
497*b843c749SSergey Zigachev 	switch (depth) {
498*b843c749SSergey Zigachev 	case DCP_OUT_TRUNC_ROUND_DEPTH_14BIT:
499*b843c749SSergey Zigachev 		depth_bits = 6;
500*b843c749SSergey Zigachev 		break;
501*b843c749SSergey Zigachev 	case DCP_OUT_TRUNC_ROUND_DEPTH_13BIT:
502*b843c749SSergey Zigachev 		depth_bits = 7;
503*b843c749SSergey Zigachev 		break;
504*b843c749SSergey Zigachev 	case DCP_OUT_TRUNC_ROUND_DEPTH_12BIT:
505*b843c749SSergey Zigachev 		depth_bits = 0;
506*b843c749SSergey Zigachev 		break;
507*b843c749SSergey Zigachev 	case DCP_OUT_TRUNC_ROUND_DEPTH_11BIT:
508*b843c749SSergey Zigachev 		depth_bits = 1;
509*b843c749SSergey Zigachev 		break;
510*b843c749SSergey Zigachev 	case DCP_OUT_TRUNC_ROUND_DEPTH_10BIT:
511*b843c749SSergey Zigachev 		depth_bits = 2;
512*b843c749SSergey Zigachev 		break;
513*b843c749SSergey Zigachev 	case DCP_OUT_TRUNC_ROUND_DEPTH_9BIT:
514*b843c749SSergey Zigachev 		depth_bits = 3;
515*b843c749SSergey Zigachev 		break;
516*b843c749SSergey Zigachev 	case DCP_OUT_TRUNC_ROUND_DEPTH_8BIT:
517*b843c749SSergey Zigachev 		depth_bits = 4;
518*b843c749SSergey Zigachev 		break;
519*b843c749SSergey Zigachev 	default:
520*b843c749SSergey Zigachev 		depth_bits = 4;
521*b843c749SSergey Zigachev 		BREAK_TO_DEBUGGER(); /* Invalid dcp_out_trunc_round_depth */
522*b843c749SSergey Zigachev 	}
523*b843c749SSergey Zigachev 
524*b843c749SSergey Zigachev 	/*  set up round or truncate */
525*b843c749SSergey Zigachev 	switch (mode) {
526*b843c749SSergey Zigachev 	case DCP_OUT_TRUNC_ROUND_MODE_TRUNCATE:
527*b843c749SSergey Zigachev 		mode_bit = 0;
528*b843c749SSergey Zigachev 		break;
529*b843c749SSergey Zigachev 	case DCP_OUT_TRUNC_ROUND_MODE_ROUND:
530*b843c749SSergey Zigachev 		mode_bit = 1;
531*b843c749SSergey Zigachev 		break;
532*b843c749SSergey Zigachev 	default:
533*b843c749SSergey Zigachev 		BREAK_TO_DEBUGGER(); /* Invalid dcp_out_trunc_round_mode */
534*b843c749SSergey Zigachev 	}
535*b843c749SSergey Zigachev 
536*b843c749SSergey Zigachev 	depth_bits |= mode_bit << 3;
537*b843c749SSergey Zigachev 
538*b843c749SSergey Zigachev 	REG_SET(OUT_ROUND_CONTROL, 0, OUT_ROUND_TRUNC_MODE, depth_bits);
539*b843c749SSergey Zigachev }
540*b843c749SSergey Zigachev 
541*b843c749SSergey Zigachev /*****************************************************************************
542*b843c749SSergey Zigachev  * set_dither
543*b843c749SSergey Zigachev  *
544*b843c749SSergey Zigachev  * @brief
545*b843c749SSergey Zigachev  *     Programs Dither
546*b843c749SSergey Zigachev  *
547*b843c749SSergey Zigachev  * @param [in] dither_enable        : enable dither
548*b843c749SSergey Zigachev  * @param [in] dither_mode           : dither mode to set
549*b843c749SSergey Zigachev  * @param [in] dither_depth          : bit depth to dither to
550*b843c749SSergey Zigachev  * @param [in] frame_random_enable    : enable frame random
551*b843c749SSergey Zigachev  * @param [in] rgb_random_enable      : enable rgb random
552*b843c749SSergey Zigachev  * @param [in] highpass_random_enable : enable highpass random
553*b843c749SSergey Zigachev  *
554*b843c749SSergey Zigachev  ******************************************************************************/
555*b843c749SSergey Zigachev 
set_dither(struct dce_transform * xfm_dce,bool dither_enable,enum dcp_spatial_dither_mode dither_mode,enum dcp_spatial_dither_depth dither_depth,bool frame_random_enable,bool rgb_random_enable,bool highpass_random_enable)556*b843c749SSergey Zigachev static void set_dither(
557*b843c749SSergey Zigachev 	struct dce_transform *xfm_dce,
558*b843c749SSergey Zigachev 	bool dither_enable,
559*b843c749SSergey Zigachev 	enum dcp_spatial_dither_mode dither_mode,
560*b843c749SSergey Zigachev 	enum dcp_spatial_dither_depth dither_depth,
561*b843c749SSergey Zigachev 	bool frame_random_enable,
562*b843c749SSergey Zigachev 	bool rgb_random_enable,
563*b843c749SSergey Zigachev 	bool highpass_random_enable)
564*b843c749SSergey Zigachev {
565*b843c749SSergey Zigachev 	int dither_depth_bits = 0;
566*b843c749SSergey Zigachev 	int dither_mode_bits = 0;
567*b843c749SSergey Zigachev 
568*b843c749SSergey Zigachev 	switch (dither_mode) {
569*b843c749SSergey Zigachev 	case DCP_SPATIAL_DITHER_MODE_AAAA:
570*b843c749SSergey Zigachev 		dither_mode_bits = 0;
571*b843c749SSergey Zigachev 		break;
572*b843c749SSergey Zigachev 	case DCP_SPATIAL_DITHER_MODE_A_AA_A:
573*b843c749SSergey Zigachev 		dither_mode_bits = 1;
574*b843c749SSergey Zigachev 		break;
575*b843c749SSergey Zigachev 	case DCP_SPATIAL_DITHER_MODE_AABBAABB:
576*b843c749SSergey Zigachev 		dither_mode_bits = 2;
577*b843c749SSergey Zigachev 		break;
578*b843c749SSergey Zigachev 	case DCP_SPATIAL_DITHER_MODE_AABBCCAABBCC:
579*b843c749SSergey Zigachev 		dither_mode_bits = 3;
580*b843c749SSergey Zigachev 		break;
581*b843c749SSergey Zigachev 	default:
582*b843c749SSergey Zigachev 		/* Invalid dcp_spatial_dither_mode */
583*b843c749SSergey Zigachev 		BREAK_TO_DEBUGGER();
584*b843c749SSergey Zigachev 	}
585*b843c749SSergey Zigachev 
586*b843c749SSergey Zigachev 	switch (dither_depth) {
587*b843c749SSergey Zigachev 	case DCP_SPATIAL_DITHER_DEPTH_30BPP:
588*b843c749SSergey Zigachev 		dither_depth_bits = 0;
589*b843c749SSergey Zigachev 		break;
590*b843c749SSergey Zigachev 	case DCP_SPATIAL_DITHER_DEPTH_24BPP:
591*b843c749SSergey Zigachev 		dither_depth_bits = 1;
592*b843c749SSergey Zigachev 		break;
593*b843c749SSergey Zigachev 	default:
594*b843c749SSergey Zigachev 		/* Invalid dcp_spatial_dither_depth */
595*b843c749SSergey Zigachev 		BREAK_TO_DEBUGGER();
596*b843c749SSergey Zigachev 	}
597*b843c749SSergey Zigachev 
598*b843c749SSergey Zigachev 	/*  write the register */
599*b843c749SSergey Zigachev 	REG_SET_6(DCP_SPATIAL_DITHER_CNTL, 0,
600*b843c749SSergey Zigachev 			DCP_SPATIAL_DITHER_EN, dither_enable,
601*b843c749SSergey Zigachev 			DCP_SPATIAL_DITHER_MODE, dither_mode_bits,
602*b843c749SSergey Zigachev 			DCP_SPATIAL_DITHER_DEPTH, dither_depth_bits,
603*b843c749SSergey Zigachev 			DCP_FRAME_RANDOM_ENABLE, frame_random_enable,
604*b843c749SSergey Zigachev 			DCP_RGB_RANDOM_ENABLE, rgb_random_enable,
605*b843c749SSergey Zigachev 			DCP_HIGHPASS_RANDOM_ENABLE, highpass_random_enable);
606*b843c749SSergey Zigachev }
607*b843c749SSergey Zigachev 
608*b843c749SSergey Zigachev /*****************************************************************************
609*b843c749SSergey Zigachev  * dce_transform_bit_depth_reduction_program
610*b843c749SSergey Zigachev  *
611*b843c749SSergey Zigachev  * @brief
612*b843c749SSergey Zigachev  *     Programs the DCP bit depth reduction registers (Clamp, Round/Truncate,
613*b843c749SSergey Zigachev  *      Dither) for dce
614*b843c749SSergey Zigachev  *
615*b843c749SSergey Zigachev  * @param depth : bit depth to set the clamp to (should match denorm)
616*b843c749SSergey Zigachev  *
617*b843c749SSergey Zigachev  ******************************************************************************/
program_bit_depth_reduction(struct dce_transform * xfm_dce,enum dc_color_depth depth,const struct bit_depth_reduction_params * bit_depth_params)618*b843c749SSergey Zigachev static void program_bit_depth_reduction(
619*b843c749SSergey Zigachev 	struct dce_transform *xfm_dce,
620*b843c749SSergey Zigachev 	enum dc_color_depth depth,
621*b843c749SSergey Zigachev 	const struct bit_depth_reduction_params *bit_depth_params)
622*b843c749SSergey Zigachev {
623*b843c749SSergey Zigachev 	enum dcp_out_trunc_round_depth trunc_round_depth;
624*b843c749SSergey Zigachev 	enum dcp_out_trunc_round_mode trunc_mode;
625*b843c749SSergey Zigachev 	bool spatial_dither_enable;
626*b843c749SSergey Zigachev 
627*b843c749SSergey Zigachev 	ASSERT(depth < COLOR_DEPTH_121212); /* Invalid clamp bit depth */
628*b843c749SSergey Zigachev 
629*b843c749SSergey Zigachev 	spatial_dither_enable = bit_depth_params->flags.SPATIAL_DITHER_ENABLED;
630*b843c749SSergey Zigachev 	/* Default to 12 bit truncation without rounding */
631*b843c749SSergey Zigachev 	trunc_round_depth = DCP_OUT_TRUNC_ROUND_DEPTH_12BIT;
632*b843c749SSergey Zigachev 	trunc_mode = DCP_OUT_TRUNC_ROUND_MODE_TRUNCATE;
633*b843c749SSergey Zigachev 
634*b843c749SSergey Zigachev 	if (bit_depth_params->flags.TRUNCATE_ENABLED) {
635*b843c749SSergey Zigachev 		/* Don't enable dithering if truncation is enabled */
636*b843c749SSergey Zigachev 		spatial_dither_enable = false;
637*b843c749SSergey Zigachev 		trunc_mode = bit_depth_params->flags.TRUNCATE_MODE ?
638*b843c749SSergey Zigachev 			     DCP_OUT_TRUNC_ROUND_MODE_ROUND :
639*b843c749SSergey Zigachev 			     DCP_OUT_TRUNC_ROUND_MODE_TRUNCATE;
640*b843c749SSergey Zigachev 
641*b843c749SSergey Zigachev 		if (bit_depth_params->flags.TRUNCATE_DEPTH == 0 ||
642*b843c749SSergey Zigachev 		    bit_depth_params->flags.TRUNCATE_DEPTH == 1)
643*b843c749SSergey Zigachev 			trunc_round_depth = DCP_OUT_TRUNC_ROUND_DEPTH_8BIT;
644*b843c749SSergey Zigachev 		else if (bit_depth_params->flags.TRUNCATE_DEPTH == 2)
645*b843c749SSergey Zigachev 			trunc_round_depth = DCP_OUT_TRUNC_ROUND_DEPTH_10BIT;
646*b843c749SSergey Zigachev 		else {
647*b843c749SSergey Zigachev 			/*
648*b843c749SSergey Zigachev 			 * Invalid truncate/round depth. Setting here to 12bit
649*b843c749SSergey Zigachev 			 * to prevent use-before-initialize errors.
650*b843c749SSergey Zigachev 			 */
651*b843c749SSergey Zigachev 			trunc_round_depth = DCP_OUT_TRUNC_ROUND_DEPTH_12BIT;
652*b843c749SSergey Zigachev 			BREAK_TO_DEBUGGER();
653*b843c749SSergey Zigachev 		}
654*b843c749SSergey Zigachev 	}
655*b843c749SSergey Zigachev 
656*b843c749SSergey Zigachev 	set_clamp(xfm_dce, depth);
657*b843c749SSergey Zigachev 	set_round(xfm_dce, trunc_mode, trunc_round_depth);
658*b843c749SSergey Zigachev 	set_dither(xfm_dce,
659*b843c749SSergey Zigachev 		   spatial_dither_enable,
660*b843c749SSergey Zigachev 		   DCP_SPATIAL_DITHER_MODE_A_AA_A,
661*b843c749SSergey Zigachev 		   DCP_SPATIAL_DITHER_DEPTH_30BPP,
662*b843c749SSergey Zigachev 		   bit_depth_params->flags.FRAME_RANDOM,
663*b843c749SSergey Zigachev 		   bit_depth_params->flags.RGB_RANDOM,
664*b843c749SSergey Zigachev 		   bit_depth_params->flags.HIGHPASS_RANDOM);
665*b843c749SSergey Zigachev }
666*b843c749SSergey Zigachev 
dce_transform_get_max_num_of_supported_lines(struct dce_transform * xfm_dce,enum lb_pixel_depth depth,int pixel_width)667*b843c749SSergey Zigachev static int dce_transform_get_max_num_of_supported_lines(
668*b843c749SSergey Zigachev 	struct dce_transform *xfm_dce,
669*b843c749SSergey Zigachev 	enum lb_pixel_depth depth,
670*b843c749SSergey Zigachev 	int pixel_width)
671*b843c749SSergey Zigachev {
672*b843c749SSergey Zigachev 	int pixels_per_entries = 0;
673*b843c749SSergey Zigachev 	int max_pixels_supports = 0;
674*b843c749SSergey Zigachev 
675*b843c749SSergey Zigachev 	ASSERT(pixel_width);
676*b843c749SSergey Zigachev 
677*b843c749SSergey Zigachev 	/* Find number of pixels that can fit into a single LB entry and
678*b843c749SSergey Zigachev 	 * take floor of the value since we cannot store a single pixel
679*b843c749SSergey Zigachev 	 * across multiple entries. */
680*b843c749SSergey Zigachev 	switch (depth) {
681*b843c749SSergey Zigachev 	case LB_PIXEL_DEPTH_18BPP:
682*b843c749SSergey Zigachev 		pixels_per_entries = xfm_dce->lb_bits_per_entry / 18;
683*b843c749SSergey Zigachev 		break;
684*b843c749SSergey Zigachev 
685*b843c749SSergey Zigachev 	case LB_PIXEL_DEPTH_24BPP:
686*b843c749SSergey Zigachev 		pixels_per_entries = xfm_dce->lb_bits_per_entry / 24;
687*b843c749SSergey Zigachev 		break;
688*b843c749SSergey Zigachev 
689*b843c749SSergey Zigachev 	case LB_PIXEL_DEPTH_30BPP:
690*b843c749SSergey Zigachev 		pixels_per_entries = xfm_dce->lb_bits_per_entry / 30;
691*b843c749SSergey Zigachev 		break;
692*b843c749SSergey Zigachev 
693*b843c749SSergey Zigachev 	case LB_PIXEL_DEPTH_36BPP:
694*b843c749SSergey Zigachev 		pixels_per_entries = xfm_dce->lb_bits_per_entry / 36;
695*b843c749SSergey Zigachev 		break;
696*b843c749SSergey Zigachev 
697*b843c749SSergey Zigachev 	default:
698*b843c749SSergey Zigachev 		DC_LOG_WARNING("%s: Invalid LB pixel depth",
699*b843c749SSergey Zigachev 			__func__);
700*b843c749SSergey Zigachev 		BREAK_TO_DEBUGGER();
701*b843c749SSergey Zigachev 		break;
702*b843c749SSergey Zigachev 	}
703*b843c749SSergey Zigachev 
704*b843c749SSergey Zigachev 	ASSERT(pixels_per_entries);
705*b843c749SSergey Zigachev 
706*b843c749SSergey Zigachev 	max_pixels_supports =
707*b843c749SSergey Zigachev 			pixels_per_entries *
708*b843c749SSergey Zigachev 			xfm_dce->lb_memory_size;
709*b843c749SSergey Zigachev 
710*b843c749SSergey Zigachev 	return (max_pixels_supports / pixel_width);
711*b843c749SSergey Zigachev }
712*b843c749SSergey Zigachev 
set_denormalization(struct dce_transform * xfm_dce,enum dc_color_depth depth)713*b843c749SSergey Zigachev static void set_denormalization(
714*b843c749SSergey Zigachev 	struct dce_transform *xfm_dce,
715*b843c749SSergey Zigachev 	enum dc_color_depth depth)
716*b843c749SSergey Zigachev {
717*b843c749SSergey Zigachev 	int denorm_mode = 0;
718*b843c749SSergey Zigachev 
719*b843c749SSergey Zigachev 	switch (depth) {
720*b843c749SSergey Zigachev 	case COLOR_DEPTH_666:
721*b843c749SSergey Zigachev 		/* 63/64 for 6 bit output color depth */
722*b843c749SSergey Zigachev 		denorm_mode = 1;
723*b843c749SSergey Zigachev 		break;
724*b843c749SSergey Zigachev 	case COLOR_DEPTH_888:
725*b843c749SSergey Zigachev 		/* Unity for 8 bit output color depth
726*b843c749SSergey Zigachev 		 * because prescale is disabled by default */
727*b843c749SSergey Zigachev 		denorm_mode = 0;
728*b843c749SSergey Zigachev 		break;
729*b843c749SSergey Zigachev 	case COLOR_DEPTH_101010:
730*b843c749SSergey Zigachev 		/* 1023/1024 for 10 bit output color depth */
731*b843c749SSergey Zigachev 		denorm_mode = 3;
732*b843c749SSergey Zigachev 		break;
733*b843c749SSergey Zigachev 	case COLOR_DEPTH_121212:
734*b843c749SSergey Zigachev 		/* 4095/4096 for 12 bit output color depth */
735*b843c749SSergey Zigachev 		denorm_mode = 5;
736*b843c749SSergey Zigachev 		break;
737*b843c749SSergey Zigachev 	case COLOR_DEPTH_141414:
738*b843c749SSergey Zigachev 	case COLOR_DEPTH_161616:
739*b843c749SSergey Zigachev 	default:
740*b843c749SSergey Zigachev 		/* not valid used case! */
741*b843c749SSergey Zigachev 		break;
742*b843c749SSergey Zigachev 	}
743*b843c749SSergey Zigachev 
744*b843c749SSergey Zigachev 	REG_SET(DENORM_CONTROL, 0, DENORM_MODE, denorm_mode);
745*b843c749SSergey Zigachev }
746*b843c749SSergey Zigachev 
dce_transform_set_pixel_storage_depth(struct transform * xfm,enum lb_pixel_depth depth,const struct bit_depth_reduction_params * bit_depth_params)747*b843c749SSergey Zigachev static void dce_transform_set_pixel_storage_depth(
748*b843c749SSergey Zigachev 	struct transform *xfm,
749*b843c749SSergey Zigachev 	enum lb_pixel_depth depth,
750*b843c749SSergey Zigachev 	const struct bit_depth_reduction_params *bit_depth_params)
751*b843c749SSergey Zigachev {
752*b843c749SSergey Zigachev 	struct dce_transform *xfm_dce = TO_DCE_TRANSFORM(xfm);
753*b843c749SSergey Zigachev 	int pixel_depth, expan_mode;
754*b843c749SSergey Zigachev 	enum dc_color_depth color_depth;
755*b843c749SSergey Zigachev 
756*b843c749SSergey Zigachev 	switch (depth) {
757*b843c749SSergey Zigachev 	case LB_PIXEL_DEPTH_18BPP:
758*b843c749SSergey Zigachev 		color_depth = COLOR_DEPTH_666;
759*b843c749SSergey Zigachev 		pixel_depth = 2;
760*b843c749SSergey Zigachev 		expan_mode  = 1;
761*b843c749SSergey Zigachev 		break;
762*b843c749SSergey Zigachev 	case LB_PIXEL_DEPTH_24BPP:
763*b843c749SSergey Zigachev 		color_depth = COLOR_DEPTH_888;
764*b843c749SSergey Zigachev 		pixel_depth = 1;
765*b843c749SSergey Zigachev 		expan_mode  = 1;
766*b843c749SSergey Zigachev 		break;
767*b843c749SSergey Zigachev 	case LB_PIXEL_DEPTH_30BPP:
768*b843c749SSergey Zigachev 		color_depth = COLOR_DEPTH_101010;
769*b843c749SSergey Zigachev 		pixel_depth = 0;
770*b843c749SSergey Zigachev 		expan_mode  = 1;
771*b843c749SSergey Zigachev 		break;
772*b843c749SSergey Zigachev 	case LB_PIXEL_DEPTH_36BPP:
773*b843c749SSergey Zigachev 		color_depth = COLOR_DEPTH_121212;
774*b843c749SSergey Zigachev 		pixel_depth = 3;
775*b843c749SSergey Zigachev 		expan_mode  = 0;
776*b843c749SSergey Zigachev 		break;
777*b843c749SSergey Zigachev 	default:
778*b843c749SSergey Zigachev 		color_depth = COLOR_DEPTH_101010;
779*b843c749SSergey Zigachev 		pixel_depth = 0;
780*b843c749SSergey Zigachev 		expan_mode  = 1;
781*b843c749SSergey Zigachev 		BREAK_TO_DEBUGGER();
782*b843c749SSergey Zigachev 		break;
783*b843c749SSergey Zigachev 	}
784*b843c749SSergey Zigachev 
785*b843c749SSergey Zigachev 	set_denormalization(xfm_dce, color_depth);
786*b843c749SSergey Zigachev 	program_bit_depth_reduction(xfm_dce, color_depth, bit_depth_params);
787*b843c749SSergey Zigachev 
788*b843c749SSergey Zigachev 	REG_UPDATE_2(LB_DATA_FORMAT,
789*b843c749SSergey Zigachev 			PIXEL_DEPTH, pixel_depth,
790*b843c749SSergey Zigachev 			PIXEL_EXPAN_MODE, expan_mode);
791*b843c749SSergey Zigachev 
792*b843c749SSergey Zigachev 	if (!(xfm_dce->lb_pixel_depth_supported & depth)) {
793*b843c749SSergey Zigachev 		/*we should use unsupported capabilities
794*b843c749SSergey Zigachev 		 *  unless it is required by w/a*/
795*b843c749SSergey Zigachev 		DC_LOG_WARNING("%s: Capability not supported",
796*b843c749SSergey Zigachev 			__func__);
797*b843c749SSergey Zigachev 	}
798*b843c749SSergey Zigachev }
799*b843c749SSergey Zigachev 
program_gamut_remap(struct dce_transform * xfm_dce,const uint16_t * reg_val)800*b843c749SSergey Zigachev static void program_gamut_remap(
801*b843c749SSergey Zigachev 	struct dce_transform *xfm_dce,
802*b843c749SSergey Zigachev 	const uint16_t *reg_val)
803*b843c749SSergey Zigachev {
804*b843c749SSergey Zigachev 	if (reg_val) {
805*b843c749SSergey Zigachev 		REG_SET_2(GAMUT_REMAP_C11_C12, 0,
806*b843c749SSergey Zigachev 				GAMUT_REMAP_C11, reg_val[0],
807*b843c749SSergey Zigachev 				GAMUT_REMAP_C12, reg_val[1]);
808*b843c749SSergey Zigachev 		REG_SET_2(GAMUT_REMAP_C13_C14, 0,
809*b843c749SSergey Zigachev 				GAMUT_REMAP_C13, reg_val[2],
810*b843c749SSergey Zigachev 				GAMUT_REMAP_C14, reg_val[3]);
811*b843c749SSergey Zigachev 		REG_SET_2(GAMUT_REMAP_C21_C22, 0,
812*b843c749SSergey Zigachev 				GAMUT_REMAP_C21, reg_val[4],
813*b843c749SSergey Zigachev 				GAMUT_REMAP_C22, reg_val[5]);
814*b843c749SSergey Zigachev 		REG_SET_2(GAMUT_REMAP_C23_C24, 0,
815*b843c749SSergey Zigachev 				GAMUT_REMAP_C23, reg_val[6],
816*b843c749SSergey Zigachev 				GAMUT_REMAP_C24, reg_val[7]);
817*b843c749SSergey Zigachev 		REG_SET_2(GAMUT_REMAP_C31_C32, 0,
818*b843c749SSergey Zigachev 				GAMUT_REMAP_C31, reg_val[8],
819*b843c749SSergey Zigachev 				GAMUT_REMAP_C32, reg_val[9]);
820*b843c749SSergey Zigachev 		REG_SET_2(GAMUT_REMAP_C33_C34, 0,
821*b843c749SSergey Zigachev 				GAMUT_REMAP_C33, reg_val[10],
822*b843c749SSergey Zigachev 				GAMUT_REMAP_C34, reg_val[11]);
823*b843c749SSergey Zigachev 
824*b843c749SSergey Zigachev 		REG_SET(GAMUT_REMAP_CONTROL, 0, GRPH_GAMUT_REMAP_MODE, 1);
825*b843c749SSergey Zigachev 	} else
826*b843c749SSergey Zigachev 		REG_SET(GAMUT_REMAP_CONTROL, 0, GRPH_GAMUT_REMAP_MODE, 0);
827*b843c749SSergey Zigachev 
828*b843c749SSergey Zigachev }
829*b843c749SSergey Zigachev 
830*b843c749SSergey Zigachev /**
831*b843c749SSergey Zigachev  *****************************************************************************
832*b843c749SSergey Zigachev  *  Function: dal_transform_wide_gamut_set_gamut_remap
833*b843c749SSergey Zigachev  *
834*b843c749SSergey Zigachev  *  @param [in] const struct xfm_grph_csc_adjustment *adjust
835*b843c749SSergey Zigachev  *
836*b843c749SSergey Zigachev  *  @return
837*b843c749SSergey Zigachev  *     void
838*b843c749SSergey Zigachev  *
839*b843c749SSergey Zigachev  *  @note calculate and apply color temperature adjustment to in Rgb color space
840*b843c749SSergey Zigachev  *
841*b843c749SSergey Zigachev  *  @see
842*b843c749SSergey Zigachev  *
843*b843c749SSergey Zigachev  *****************************************************************************
844*b843c749SSergey Zigachev  */
dce_transform_set_gamut_remap(struct transform * xfm,const struct xfm_grph_csc_adjustment * adjust)845*b843c749SSergey Zigachev static void dce_transform_set_gamut_remap(
846*b843c749SSergey Zigachev 	struct transform *xfm,
847*b843c749SSergey Zigachev 	const struct xfm_grph_csc_adjustment *adjust)
848*b843c749SSergey Zigachev {
849*b843c749SSergey Zigachev 	struct dce_transform *xfm_dce = TO_DCE_TRANSFORM(xfm);
850*b843c749SSergey Zigachev 	int i = 0;
851*b843c749SSergey Zigachev 
852*b843c749SSergey Zigachev 	if (adjust->gamut_adjust_type != GRAPHICS_GAMUT_ADJUST_TYPE_SW)
853*b843c749SSergey Zigachev 		/* Bypass if type is bypass or hw */
854*b843c749SSergey Zigachev 		program_gamut_remap(xfm_dce, NULL);
855*b843c749SSergey Zigachev 	else {
856*b843c749SSergey Zigachev 		struct fixed31_32 arr_matrix[GAMUT_MATRIX_SIZE];
857*b843c749SSergey Zigachev 		uint16_t arr_reg_val[GAMUT_MATRIX_SIZE];
858*b843c749SSergey Zigachev 
859*b843c749SSergey Zigachev 		for (i = 0; i < GAMUT_MATRIX_SIZE; i++)
860*b843c749SSergey Zigachev 			arr_matrix[i] = adjust->temperature_matrix[i];
861*b843c749SSergey Zigachev 
862*b843c749SSergey Zigachev 		convert_float_matrix(
863*b843c749SSergey Zigachev 			arr_reg_val, arr_matrix, GAMUT_MATRIX_SIZE);
864*b843c749SSergey Zigachev 
865*b843c749SSergey Zigachev 		program_gamut_remap(xfm_dce, arr_reg_val);
866*b843c749SSergey Zigachev 	}
867*b843c749SSergey Zigachev }
868*b843c749SSergey Zigachev 
decide_taps(struct fixed31_32 ratio,uint32_t in_taps,bool chroma)869*b843c749SSergey Zigachev static uint32_t decide_taps(struct fixed31_32 ratio, uint32_t in_taps, bool chroma)
870*b843c749SSergey Zigachev {
871*b843c749SSergey Zigachev 	uint32_t taps;
872*b843c749SSergey Zigachev 
873*b843c749SSergey Zigachev 	if (IDENTITY_RATIO(ratio)) {
874*b843c749SSergey Zigachev 		return 1;
875*b843c749SSergey Zigachev 	} else if (in_taps != 0) {
876*b843c749SSergey Zigachev 		taps = in_taps;
877*b843c749SSergey Zigachev 	} else {
878*b843c749SSergey Zigachev 		taps = 4;
879*b843c749SSergey Zigachev 	}
880*b843c749SSergey Zigachev 
881*b843c749SSergey Zigachev 	if (chroma) {
882*b843c749SSergey Zigachev 		taps /= 2;
883*b843c749SSergey Zigachev 		if (taps < 2)
884*b843c749SSergey Zigachev 			taps = 2;
885*b843c749SSergey Zigachev 	}
886*b843c749SSergey Zigachev 
887*b843c749SSergey Zigachev 	return taps;
888*b843c749SSergey Zigachev }
889*b843c749SSergey Zigachev 
890*b843c749SSergey Zigachev 
dce_transform_get_optimal_number_of_taps(struct transform * xfm,struct scaler_data * scl_data,const struct scaling_taps * in_taps)891*b843c749SSergey Zigachev bool dce_transform_get_optimal_number_of_taps(
892*b843c749SSergey Zigachev 	struct transform *xfm,
893*b843c749SSergey Zigachev 	struct scaler_data *scl_data,
894*b843c749SSergey Zigachev 	const struct scaling_taps *in_taps)
895*b843c749SSergey Zigachev {
896*b843c749SSergey Zigachev 	struct dce_transform *xfm_dce = TO_DCE_TRANSFORM(xfm);
897*b843c749SSergey Zigachev 	int pixel_width = scl_data->viewport.width;
898*b843c749SSergey Zigachev 	int max_num_of_lines;
899*b843c749SSergey Zigachev 
900*b843c749SSergey Zigachev 	if (xfm_dce->prescaler_on &&
901*b843c749SSergey Zigachev 			(scl_data->viewport.width > scl_data->recout.width))
902*b843c749SSergey Zigachev 		pixel_width = scl_data->recout.width;
903*b843c749SSergey Zigachev 
904*b843c749SSergey Zigachev 	max_num_of_lines = dce_transform_get_max_num_of_supported_lines(
905*b843c749SSergey Zigachev 		xfm_dce,
906*b843c749SSergey Zigachev 		scl_data->lb_params.depth,
907*b843c749SSergey Zigachev 		pixel_width);
908*b843c749SSergey Zigachev 
909*b843c749SSergey Zigachev 	/* Fail if in_taps are impossible */
910*b843c749SSergey Zigachev 	if (in_taps->v_taps >= max_num_of_lines)
911*b843c749SSergey Zigachev 		return false;
912*b843c749SSergey Zigachev 
913*b843c749SSergey Zigachev 	/*
914*b843c749SSergey Zigachev 	 * Set taps according to this policy (in this order)
915*b843c749SSergey Zigachev 	 * - Use 1 for no scaling
916*b843c749SSergey Zigachev 	 * - Use input taps
917*b843c749SSergey Zigachev 	 * - Use 4 and reduce as required by line buffer size
918*b843c749SSergey Zigachev 	 * - Decide chroma taps if chroma is scaled
919*b843c749SSergey Zigachev 	 *
920*b843c749SSergey Zigachev 	 * Ignore input chroma taps. Decide based on non-chroma
921*b843c749SSergey Zigachev 	 */
922*b843c749SSergey Zigachev 	scl_data->taps.h_taps = decide_taps(scl_data->ratios.horz, in_taps->h_taps, false);
923*b843c749SSergey Zigachev 	scl_data->taps.v_taps = decide_taps(scl_data->ratios.vert, in_taps->v_taps, false);
924*b843c749SSergey Zigachev 	scl_data->taps.h_taps_c = decide_taps(scl_data->ratios.horz_c, in_taps->h_taps, true);
925*b843c749SSergey Zigachev 	scl_data->taps.v_taps_c = decide_taps(scl_data->ratios.vert_c, in_taps->v_taps, true);
926*b843c749SSergey Zigachev 
927*b843c749SSergey Zigachev 	if (!IDENTITY_RATIO(scl_data->ratios.vert)) {
928*b843c749SSergey Zigachev 		/* reduce v_taps if needed but ensure we have at least two */
929*b843c749SSergey Zigachev 		if (in_taps->v_taps == 0
930*b843c749SSergey Zigachev 				&& max_num_of_lines <= scl_data->taps.v_taps
931*b843c749SSergey Zigachev 				&& scl_data->taps.v_taps > 1) {
932*b843c749SSergey Zigachev 			scl_data->taps.v_taps = max_num_of_lines - 1;
933*b843c749SSergey Zigachev 		}
934*b843c749SSergey Zigachev 
935*b843c749SSergey Zigachev 		if (scl_data->taps.v_taps <= 1)
936*b843c749SSergey Zigachev 			return false;
937*b843c749SSergey Zigachev 	}
938*b843c749SSergey Zigachev 
939*b843c749SSergey Zigachev 	if (!IDENTITY_RATIO(scl_data->ratios.vert_c)) {
940*b843c749SSergey Zigachev 		/* reduce chroma v_taps if needed but ensure we have at least two */
941*b843c749SSergey Zigachev 		if (max_num_of_lines <= scl_data->taps.v_taps_c && scl_data->taps.v_taps_c > 1) {
942*b843c749SSergey Zigachev 			scl_data->taps.v_taps_c = max_num_of_lines - 1;
943*b843c749SSergey Zigachev 		}
944*b843c749SSergey Zigachev 
945*b843c749SSergey Zigachev 		if (scl_data->taps.v_taps_c <= 1)
946*b843c749SSergey Zigachev 			return false;
947*b843c749SSergey Zigachev 	}
948*b843c749SSergey Zigachev 
949*b843c749SSergey Zigachev 	/* we've got valid taps */
950*b843c749SSergey Zigachev 	return true;
951*b843c749SSergey Zigachev }
952*b843c749SSergey Zigachev 
dce_transform_reset(struct transform * xfm)953*b843c749SSergey Zigachev static void dce_transform_reset(struct transform *xfm)
954*b843c749SSergey Zigachev {
955*b843c749SSergey Zigachev 	struct dce_transform *xfm_dce = TO_DCE_TRANSFORM(xfm);
956*b843c749SSergey Zigachev 
957*b843c749SSergey Zigachev 	xfm_dce->filter_h = NULL;
958*b843c749SSergey Zigachev 	xfm_dce->filter_v = NULL;
959*b843c749SSergey Zigachev }
960*b843c749SSergey Zigachev 
program_color_matrix(struct dce_transform * xfm_dce,const struct out_csc_color_matrix * tbl_entry,enum grph_color_adjust_option options)961*b843c749SSergey Zigachev static void program_color_matrix(
962*b843c749SSergey Zigachev 	struct dce_transform *xfm_dce,
963*b843c749SSergey Zigachev 	const struct out_csc_color_matrix *tbl_entry,
964*b843c749SSergey Zigachev 	enum grph_color_adjust_option options)
965*b843c749SSergey Zigachev {
966*b843c749SSergey Zigachev 	{
967*b843c749SSergey Zigachev 		REG_SET_2(OUTPUT_CSC_C11_C12, 0,
968*b843c749SSergey Zigachev 			OUTPUT_CSC_C11, tbl_entry->regval[0],
969*b843c749SSergey Zigachev 			OUTPUT_CSC_C12, tbl_entry->regval[1]);
970*b843c749SSergey Zigachev 	}
971*b843c749SSergey Zigachev 	{
972*b843c749SSergey Zigachev 		REG_SET_2(OUTPUT_CSC_C13_C14, 0,
973*b843c749SSergey Zigachev 			OUTPUT_CSC_C11, tbl_entry->regval[2],
974*b843c749SSergey Zigachev 			OUTPUT_CSC_C12, tbl_entry->regval[3]);
975*b843c749SSergey Zigachev 	}
976*b843c749SSergey Zigachev 	{
977*b843c749SSergey Zigachev 		REG_SET_2(OUTPUT_CSC_C21_C22, 0,
978*b843c749SSergey Zigachev 			OUTPUT_CSC_C11, tbl_entry->regval[4],
979*b843c749SSergey Zigachev 			OUTPUT_CSC_C12, tbl_entry->regval[5]);
980*b843c749SSergey Zigachev 	}
981*b843c749SSergey Zigachev 	{
982*b843c749SSergey Zigachev 		REG_SET_2(OUTPUT_CSC_C23_C24, 0,
983*b843c749SSergey Zigachev 			OUTPUT_CSC_C11, tbl_entry->regval[6],
984*b843c749SSergey Zigachev 			OUTPUT_CSC_C12, tbl_entry->regval[7]);
985*b843c749SSergey Zigachev 	}
986*b843c749SSergey Zigachev 	{
987*b843c749SSergey Zigachev 		REG_SET_2(OUTPUT_CSC_C31_C32, 0,
988*b843c749SSergey Zigachev 			OUTPUT_CSC_C11, tbl_entry->regval[8],
989*b843c749SSergey Zigachev 			OUTPUT_CSC_C12, tbl_entry->regval[9]);
990*b843c749SSergey Zigachev 	}
991*b843c749SSergey Zigachev 	{
992*b843c749SSergey Zigachev 		REG_SET_2(OUTPUT_CSC_C33_C34, 0,
993*b843c749SSergey Zigachev 			OUTPUT_CSC_C11, tbl_entry->regval[10],
994*b843c749SSergey Zigachev 			OUTPUT_CSC_C12, tbl_entry->regval[11]);
995*b843c749SSergey Zigachev 	}
996*b843c749SSergey Zigachev }
997*b843c749SSergey Zigachev 
configure_graphics_mode(struct dce_transform * xfm_dce,enum csc_color_mode config,enum graphics_csc_adjust_type csc_adjust_type,enum dc_color_space color_space)998*b843c749SSergey Zigachev static bool configure_graphics_mode(
999*b843c749SSergey Zigachev 	struct dce_transform *xfm_dce,
1000*b843c749SSergey Zigachev 	enum csc_color_mode config,
1001*b843c749SSergey Zigachev 	enum graphics_csc_adjust_type csc_adjust_type,
1002*b843c749SSergey Zigachev 	enum dc_color_space color_space)
1003*b843c749SSergey Zigachev {
1004*b843c749SSergey Zigachev 	REG_SET(OUTPUT_CSC_CONTROL, 0,
1005*b843c749SSergey Zigachev 		OUTPUT_CSC_GRPH_MODE, 0);
1006*b843c749SSergey Zigachev 
1007*b843c749SSergey Zigachev 	if (csc_adjust_type == GRAPHICS_CSC_ADJUST_TYPE_SW) {
1008*b843c749SSergey Zigachev 		if (config == CSC_COLOR_MODE_GRAPHICS_OUTPUT_CSC) {
1009*b843c749SSergey Zigachev 			REG_SET(OUTPUT_CSC_CONTROL, 0,
1010*b843c749SSergey Zigachev 				OUTPUT_CSC_GRPH_MODE, 4);
1011*b843c749SSergey Zigachev 		} else {
1012*b843c749SSergey Zigachev 
1013*b843c749SSergey Zigachev 			switch (color_space) {
1014*b843c749SSergey Zigachev 			case COLOR_SPACE_SRGB:
1015*b843c749SSergey Zigachev 				/* by pass */
1016*b843c749SSergey Zigachev 				REG_SET(OUTPUT_CSC_CONTROL, 0,
1017*b843c749SSergey Zigachev 					OUTPUT_CSC_GRPH_MODE, 0);
1018*b843c749SSergey Zigachev 				break;
1019*b843c749SSergey Zigachev 			case COLOR_SPACE_SRGB_LIMITED:
1020*b843c749SSergey Zigachev 				/* TV RGB */
1021*b843c749SSergey Zigachev 				REG_SET(OUTPUT_CSC_CONTROL, 0,
1022*b843c749SSergey Zigachev 					OUTPUT_CSC_GRPH_MODE, 1);
1023*b843c749SSergey Zigachev 				break;
1024*b843c749SSergey Zigachev 			case COLOR_SPACE_YCBCR601:
1025*b843c749SSergey Zigachev 			case COLOR_SPACE_YCBCR601_LIMITED:
1026*b843c749SSergey Zigachev 				/* YCbCr601 */
1027*b843c749SSergey Zigachev 				REG_SET(OUTPUT_CSC_CONTROL, 0,
1028*b843c749SSergey Zigachev 					OUTPUT_CSC_GRPH_MODE, 2);
1029*b843c749SSergey Zigachev 				break;
1030*b843c749SSergey Zigachev 			case COLOR_SPACE_YCBCR709:
1031*b843c749SSergey Zigachev 			case COLOR_SPACE_YCBCR709_LIMITED:
1032*b843c749SSergey Zigachev 				/* YCbCr709 */
1033*b843c749SSergey Zigachev 				REG_SET(OUTPUT_CSC_CONTROL, 0,
1034*b843c749SSergey Zigachev 					OUTPUT_CSC_GRPH_MODE, 3);
1035*b843c749SSergey Zigachev 				break;
1036*b843c749SSergey Zigachev 			default:
1037*b843c749SSergey Zigachev 				return false;
1038*b843c749SSergey Zigachev 			}
1039*b843c749SSergey Zigachev 		}
1040*b843c749SSergey Zigachev 	} else if (csc_adjust_type == GRAPHICS_CSC_ADJUST_TYPE_HW) {
1041*b843c749SSergey Zigachev 		switch (color_space) {
1042*b843c749SSergey Zigachev 		case COLOR_SPACE_SRGB:
1043*b843c749SSergey Zigachev 			/* by pass */
1044*b843c749SSergey Zigachev 			REG_SET(OUTPUT_CSC_CONTROL, 0,
1045*b843c749SSergey Zigachev 				OUTPUT_CSC_GRPH_MODE, 0);
1046*b843c749SSergey Zigachev 			break;
1047*b843c749SSergey Zigachev 			break;
1048*b843c749SSergey Zigachev 		case COLOR_SPACE_SRGB_LIMITED:
1049*b843c749SSergey Zigachev 			/* TV RGB */
1050*b843c749SSergey Zigachev 			REG_SET(OUTPUT_CSC_CONTROL, 0,
1051*b843c749SSergey Zigachev 				OUTPUT_CSC_GRPH_MODE, 1);
1052*b843c749SSergey Zigachev 			break;
1053*b843c749SSergey Zigachev 		case COLOR_SPACE_YCBCR601:
1054*b843c749SSergey Zigachev 		case COLOR_SPACE_YCBCR601_LIMITED:
1055*b843c749SSergey Zigachev 			/* YCbCr601 */
1056*b843c749SSergey Zigachev 			REG_SET(OUTPUT_CSC_CONTROL, 0,
1057*b843c749SSergey Zigachev 				OUTPUT_CSC_GRPH_MODE, 2);
1058*b843c749SSergey Zigachev 			break;
1059*b843c749SSergey Zigachev 		case COLOR_SPACE_YCBCR709:
1060*b843c749SSergey Zigachev 		case COLOR_SPACE_YCBCR709_LIMITED:
1061*b843c749SSergey Zigachev 			 /* YCbCr709 */
1062*b843c749SSergey Zigachev 			REG_SET(OUTPUT_CSC_CONTROL, 0,
1063*b843c749SSergey Zigachev 				OUTPUT_CSC_GRPH_MODE, 3);
1064*b843c749SSergey Zigachev 			break;
1065*b843c749SSergey Zigachev 		default:
1066*b843c749SSergey Zigachev 			return false;
1067*b843c749SSergey Zigachev 		}
1068*b843c749SSergey Zigachev 
1069*b843c749SSergey Zigachev 	} else
1070*b843c749SSergey Zigachev 		/* by pass */
1071*b843c749SSergey Zigachev 		REG_SET(OUTPUT_CSC_CONTROL, 0,
1072*b843c749SSergey Zigachev 			OUTPUT_CSC_GRPH_MODE, 0);
1073*b843c749SSergey Zigachev 
1074*b843c749SSergey Zigachev 	return true;
1075*b843c749SSergey Zigachev }
1076*b843c749SSergey Zigachev 
dce110_opp_set_csc_adjustment(struct transform * xfm,const struct out_csc_color_matrix * tbl_entry)1077*b843c749SSergey Zigachev void dce110_opp_set_csc_adjustment(
1078*b843c749SSergey Zigachev 	struct transform *xfm,
1079*b843c749SSergey Zigachev 	const struct out_csc_color_matrix *tbl_entry)
1080*b843c749SSergey Zigachev {
1081*b843c749SSergey Zigachev 	struct dce_transform *xfm_dce = TO_DCE_TRANSFORM(xfm);
1082*b843c749SSergey Zigachev 	enum csc_color_mode config =
1083*b843c749SSergey Zigachev 			CSC_COLOR_MODE_GRAPHICS_OUTPUT_CSC;
1084*b843c749SSergey Zigachev 
1085*b843c749SSergey Zigachev 	program_color_matrix(
1086*b843c749SSergey Zigachev 			xfm_dce, tbl_entry, GRPH_COLOR_MATRIX_SW);
1087*b843c749SSergey Zigachev 
1088*b843c749SSergey Zigachev 	/*  We did everything ,now program DxOUTPUT_CSC_CONTROL */
1089*b843c749SSergey Zigachev 	configure_graphics_mode(xfm_dce, config, GRAPHICS_CSC_ADJUST_TYPE_SW,
1090*b843c749SSergey Zigachev 			tbl_entry->color_space);
1091*b843c749SSergey Zigachev }
1092*b843c749SSergey Zigachev 
dce110_opp_set_csc_default(struct transform * xfm,const struct default_adjustment * default_adjust)1093*b843c749SSergey Zigachev void dce110_opp_set_csc_default(
1094*b843c749SSergey Zigachev 	struct transform *xfm,
1095*b843c749SSergey Zigachev 	const struct default_adjustment *default_adjust)
1096*b843c749SSergey Zigachev {
1097*b843c749SSergey Zigachev 	struct dce_transform *xfm_dce = TO_DCE_TRANSFORM(xfm);
1098*b843c749SSergey Zigachev 	enum csc_color_mode config =
1099*b843c749SSergey Zigachev 			CSC_COLOR_MODE_GRAPHICS_PREDEFINED;
1100*b843c749SSergey Zigachev 
1101*b843c749SSergey Zigachev 	if (default_adjust->force_hw_default == false) {
1102*b843c749SSergey Zigachev 		const struct out_csc_color_matrix *elm;
1103*b843c749SSergey Zigachev 		/* currently parameter not in use */
1104*b843c749SSergey Zigachev 		enum grph_color_adjust_option option =
1105*b843c749SSergey Zigachev 			GRPH_COLOR_MATRIX_HW_DEFAULT;
1106*b843c749SSergey Zigachev 		uint32_t i;
1107*b843c749SSergey Zigachev 		/*
1108*b843c749SSergey Zigachev 		 * HW default false we program locally defined matrix
1109*b843c749SSergey Zigachev 		 * HW default true  we use predefined hw matrix and we
1110*b843c749SSergey Zigachev 		 * do not need to program matrix
1111*b843c749SSergey Zigachev 		 * OEM wants the HW default via runtime parameter.
1112*b843c749SSergey Zigachev 		 */
1113*b843c749SSergey Zigachev 		option = GRPH_COLOR_MATRIX_SW;
1114*b843c749SSergey Zigachev 
1115*b843c749SSergey Zigachev 		for (i = 0; i < ARRAY_SIZE(global_color_matrix); ++i) {
1116*b843c749SSergey Zigachev 			elm = &global_color_matrix[i];
1117*b843c749SSergey Zigachev 			if (elm->color_space != default_adjust->out_color_space)
1118*b843c749SSergey Zigachev 				continue;
1119*b843c749SSergey Zigachev 			/* program the matrix with default values from this
1120*b843c749SSergey Zigachev 			 * file */
1121*b843c749SSergey Zigachev 			program_color_matrix(xfm_dce, elm, option);
1122*b843c749SSergey Zigachev 			config = CSC_COLOR_MODE_GRAPHICS_OUTPUT_CSC;
1123*b843c749SSergey Zigachev 			break;
1124*b843c749SSergey Zigachev 		}
1125*b843c749SSergey Zigachev 	}
1126*b843c749SSergey Zigachev 
1127*b843c749SSergey Zigachev 	/* configure the what we programmed :
1128*b843c749SSergey Zigachev 	 * 1. Default values from this file
1129*b843c749SSergey Zigachev 	 * 2. Use hardware default from ROM_A and we do not need to program
1130*b843c749SSergey Zigachev 	 * matrix */
1131*b843c749SSergey Zigachev 
1132*b843c749SSergey Zigachev 	configure_graphics_mode(xfm_dce, config,
1133*b843c749SSergey Zigachev 		default_adjust->csc_adjust_type,
1134*b843c749SSergey Zigachev 		default_adjust->out_color_space);
1135*b843c749SSergey Zigachev }
1136*b843c749SSergey Zigachev 
program_pwl(struct dce_transform * xfm_dce,const struct pwl_params * params)1137*b843c749SSergey Zigachev static void program_pwl(struct dce_transform *xfm_dce,
1138*b843c749SSergey Zigachev 			const struct pwl_params *params)
1139*b843c749SSergey Zigachev {
1140*b843c749SSergey Zigachev 	int retval;
1141*b843c749SSergey Zigachev 	uint8_t max_tries = 10;
1142*b843c749SSergey Zigachev 	uint8_t counter = 0;
1143*b843c749SSergey Zigachev 	uint32_t i = 0;
1144*b843c749SSergey Zigachev 	const struct pwl_result_data *rgb = params->rgb_resulted;
1145*b843c749SSergey Zigachev 
1146*b843c749SSergey Zigachev 	/* Power on LUT memory */
1147*b843c749SSergey Zigachev 	if (REG(DCFE_MEM_PWR_CTRL))
1148*b843c749SSergey Zigachev 		REG_UPDATE(DCFE_MEM_PWR_CTRL,
1149*b843c749SSergey Zigachev 			   DCP_REGAMMA_MEM_PWR_DIS, 1);
1150*b843c749SSergey Zigachev 	else
1151*b843c749SSergey Zigachev 		REG_UPDATE(DCFE_MEM_LIGHT_SLEEP_CNTL,
1152*b843c749SSergey Zigachev 			   REGAMMA_LUT_LIGHT_SLEEP_DIS, 1);
1153*b843c749SSergey Zigachev 
1154*b843c749SSergey Zigachev 	while (counter < max_tries) {
1155*b843c749SSergey Zigachev 		if (REG(DCFE_MEM_PWR_STATUS)) {
1156*b843c749SSergey Zigachev 			REG_GET(DCFE_MEM_PWR_STATUS,
1157*b843c749SSergey Zigachev 				DCP_REGAMMA_MEM_PWR_STATE,
1158*b843c749SSergey Zigachev 				&retval);
1159*b843c749SSergey Zigachev 
1160*b843c749SSergey Zigachev 			if (retval == 0)
1161*b843c749SSergey Zigachev 				break;
1162*b843c749SSergey Zigachev 			++counter;
1163*b843c749SSergey Zigachev 		} else {
1164*b843c749SSergey Zigachev 			REG_GET(DCFE_MEM_LIGHT_SLEEP_CNTL,
1165*b843c749SSergey Zigachev 				REGAMMA_LUT_MEM_PWR_STATE,
1166*b843c749SSergey Zigachev 				&retval);
1167*b843c749SSergey Zigachev 
1168*b843c749SSergey Zigachev 			if (retval == 0)
1169*b843c749SSergey Zigachev 				break;
1170*b843c749SSergey Zigachev 			++counter;
1171*b843c749SSergey Zigachev 		}
1172*b843c749SSergey Zigachev 	}
1173*b843c749SSergey Zigachev 
1174*b843c749SSergey Zigachev 	if (counter == max_tries) {
1175*b843c749SSergey Zigachev 		DC_LOG_WARNING("%s: regamma lut was not powered on "
1176*b843c749SSergey Zigachev 				"in a timely manner,"
1177*b843c749SSergey Zigachev 				" programming still proceeds\n",
1178*b843c749SSergey Zigachev 				__func__);
1179*b843c749SSergey Zigachev 	}
1180*b843c749SSergey Zigachev 
1181*b843c749SSergey Zigachev 	REG_UPDATE(REGAMMA_LUT_WRITE_EN_MASK,
1182*b843c749SSergey Zigachev 		   REGAMMA_LUT_WRITE_EN_MASK, 7);
1183*b843c749SSergey Zigachev 
1184*b843c749SSergey Zigachev 	REG_WRITE(REGAMMA_LUT_INDEX, 0);
1185*b843c749SSergey Zigachev 
1186*b843c749SSergey Zigachev 	/* Program REGAMMA_LUT_DATA */
1187*b843c749SSergey Zigachev 	while (i != params->hw_points_num) {
1188*b843c749SSergey Zigachev 
1189*b843c749SSergey Zigachev 		REG_WRITE(REGAMMA_LUT_DATA, rgb->red_reg);
1190*b843c749SSergey Zigachev 		REG_WRITE(REGAMMA_LUT_DATA, rgb->green_reg);
1191*b843c749SSergey Zigachev 		REG_WRITE(REGAMMA_LUT_DATA, rgb->blue_reg);
1192*b843c749SSergey Zigachev 		REG_WRITE(REGAMMA_LUT_DATA, rgb->delta_red_reg);
1193*b843c749SSergey Zigachev 		REG_WRITE(REGAMMA_LUT_DATA, rgb->delta_green_reg);
1194*b843c749SSergey Zigachev 		REG_WRITE(REGAMMA_LUT_DATA, rgb->delta_blue_reg);
1195*b843c749SSergey Zigachev 
1196*b843c749SSergey Zigachev 		++rgb;
1197*b843c749SSergey Zigachev 		++i;
1198*b843c749SSergey Zigachev 	}
1199*b843c749SSergey Zigachev 
1200*b843c749SSergey Zigachev 	/*  we are done with DCP LUT memory; re-enable low power mode */
1201*b843c749SSergey Zigachev 	if (REG(DCFE_MEM_PWR_CTRL))
1202*b843c749SSergey Zigachev 		REG_UPDATE(DCFE_MEM_PWR_CTRL,
1203*b843c749SSergey Zigachev 			   DCP_REGAMMA_MEM_PWR_DIS, 0);
1204*b843c749SSergey Zigachev 	else
1205*b843c749SSergey Zigachev 		REG_UPDATE(DCFE_MEM_LIGHT_SLEEP_CNTL,
1206*b843c749SSergey Zigachev 			   REGAMMA_LUT_LIGHT_SLEEP_DIS, 0);
1207*b843c749SSergey Zigachev }
1208*b843c749SSergey Zigachev 
regamma_config_regions_and_segments(struct dce_transform * xfm_dce,const struct pwl_params * params)1209*b843c749SSergey Zigachev static void regamma_config_regions_and_segments(struct dce_transform *xfm_dce,
1210*b843c749SSergey Zigachev 						const struct pwl_params *params)
1211*b843c749SSergey Zigachev {
1212*b843c749SSergey Zigachev 	const struct gamma_curve *curve;
1213*b843c749SSergey Zigachev 
1214*b843c749SSergey Zigachev 	REG_SET_2(REGAMMA_CNTLA_START_CNTL, 0,
1215*b843c749SSergey Zigachev 		  REGAMMA_CNTLA_EXP_REGION_START, params->arr_points[0].custom_float_x,
1216*b843c749SSergey Zigachev 		  REGAMMA_CNTLA_EXP_REGION_START_SEGMENT, 0);
1217*b843c749SSergey Zigachev 
1218*b843c749SSergey Zigachev 	REG_SET(REGAMMA_CNTLA_SLOPE_CNTL, 0,
1219*b843c749SSergey Zigachev 		REGAMMA_CNTLA_EXP_REGION_LINEAR_SLOPE, params->arr_points[0].custom_float_slope);
1220*b843c749SSergey Zigachev 
1221*b843c749SSergey Zigachev 	REG_SET(REGAMMA_CNTLA_END_CNTL1, 0,
1222*b843c749SSergey Zigachev 		REGAMMA_CNTLA_EXP_REGION_END, params->arr_points[1].custom_float_x);
1223*b843c749SSergey Zigachev 
1224*b843c749SSergey Zigachev 	REG_SET_2(REGAMMA_CNTLA_END_CNTL2, 0,
1225*b843c749SSergey Zigachev 		  REGAMMA_CNTLA_EXP_REGION_END_BASE, params->arr_points[1].custom_float_y,
1226*b843c749SSergey Zigachev 		  REGAMMA_CNTLA_EXP_REGION_END_SLOPE, params->arr_points[1].custom_float_slope);
1227*b843c749SSergey Zigachev 
1228*b843c749SSergey Zigachev 	curve = params->arr_curve_points;
1229*b843c749SSergey Zigachev 
1230*b843c749SSergey Zigachev 	REG_SET_4(REGAMMA_CNTLA_REGION_0_1, 0,
1231*b843c749SSergey Zigachev 		  REGAMMA_CNTLA_EXP_REGION0_LUT_OFFSET, curve[0].offset,
1232*b843c749SSergey Zigachev 		  REGAMMA_CNTLA_EXP_REGION0_NUM_SEGMENTS, curve[0].segments_num,
1233*b843c749SSergey Zigachev 		  REGAMMA_CNTLA_EXP_REGION1_LUT_OFFSET, curve[1].offset,
1234*b843c749SSergey Zigachev 		  REGAMMA_CNTLA_EXP_REGION1_NUM_SEGMENTS, curve[1].segments_num);
1235*b843c749SSergey Zigachev 	curve += 2;
1236*b843c749SSergey Zigachev 
1237*b843c749SSergey Zigachev 	REG_SET_4(REGAMMA_CNTLA_REGION_2_3, 0,
1238*b843c749SSergey Zigachev 		  REGAMMA_CNTLA_EXP_REGION0_LUT_OFFSET, curve[0].offset,
1239*b843c749SSergey Zigachev 		  REGAMMA_CNTLA_EXP_REGION0_NUM_SEGMENTS, curve[0].segments_num,
1240*b843c749SSergey Zigachev 		  REGAMMA_CNTLA_EXP_REGION1_LUT_OFFSET, curve[1].offset,
1241*b843c749SSergey Zigachev 		  REGAMMA_CNTLA_EXP_REGION1_NUM_SEGMENTS, curve[1].segments_num);
1242*b843c749SSergey Zigachev 	curve += 2;
1243*b843c749SSergey Zigachev 
1244*b843c749SSergey Zigachev 	REG_SET_4(REGAMMA_CNTLA_REGION_4_5, 0,
1245*b843c749SSergey Zigachev 		  REGAMMA_CNTLA_EXP_REGION0_LUT_OFFSET, curve[0].offset,
1246*b843c749SSergey Zigachev 		  REGAMMA_CNTLA_EXP_REGION0_NUM_SEGMENTS, curve[0].segments_num,
1247*b843c749SSergey Zigachev 		  REGAMMA_CNTLA_EXP_REGION1_LUT_OFFSET, curve[1].offset,
1248*b843c749SSergey Zigachev 		  REGAMMA_CNTLA_EXP_REGION1_NUM_SEGMENTS, curve[1].segments_num);
1249*b843c749SSergey Zigachev 	curve += 2;
1250*b843c749SSergey Zigachev 
1251*b843c749SSergey Zigachev 	REG_SET_4(REGAMMA_CNTLA_REGION_6_7, 0,
1252*b843c749SSergey Zigachev 		  REGAMMA_CNTLA_EXP_REGION0_LUT_OFFSET, curve[0].offset,
1253*b843c749SSergey Zigachev 		  REGAMMA_CNTLA_EXP_REGION0_NUM_SEGMENTS, curve[0].segments_num,
1254*b843c749SSergey Zigachev 		  REGAMMA_CNTLA_EXP_REGION1_LUT_OFFSET, curve[1].offset,
1255*b843c749SSergey Zigachev 		  REGAMMA_CNTLA_EXP_REGION1_NUM_SEGMENTS, curve[1].segments_num);
1256*b843c749SSergey Zigachev 	curve += 2;
1257*b843c749SSergey Zigachev 
1258*b843c749SSergey Zigachev 	REG_SET_4(REGAMMA_CNTLA_REGION_8_9, 0,
1259*b843c749SSergey Zigachev 		  REGAMMA_CNTLA_EXP_REGION0_LUT_OFFSET, curve[0].offset,
1260*b843c749SSergey Zigachev 		  REGAMMA_CNTLA_EXP_REGION0_NUM_SEGMENTS, curve[0].segments_num,
1261*b843c749SSergey Zigachev 		  REGAMMA_CNTLA_EXP_REGION1_LUT_OFFSET, curve[1].offset,
1262*b843c749SSergey Zigachev 		  REGAMMA_CNTLA_EXP_REGION1_NUM_SEGMENTS, curve[1].segments_num);
1263*b843c749SSergey Zigachev 	curve += 2;
1264*b843c749SSergey Zigachev 
1265*b843c749SSergey Zigachev 	REG_SET_4(REGAMMA_CNTLA_REGION_10_11, 0,
1266*b843c749SSergey Zigachev 		  REGAMMA_CNTLA_EXP_REGION0_LUT_OFFSET, curve[0].offset,
1267*b843c749SSergey Zigachev 		  REGAMMA_CNTLA_EXP_REGION0_NUM_SEGMENTS, curve[0].segments_num,
1268*b843c749SSergey Zigachev 		  REGAMMA_CNTLA_EXP_REGION1_LUT_OFFSET, curve[1].offset,
1269*b843c749SSergey Zigachev 		  REGAMMA_CNTLA_EXP_REGION1_NUM_SEGMENTS, curve[1].segments_num);
1270*b843c749SSergey Zigachev 	curve += 2;
1271*b843c749SSergey Zigachev 
1272*b843c749SSergey Zigachev 	REG_SET_4(REGAMMA_CNTLA_REGION_12_13, 0,
1273*b843c749SSergey Zigachev 		  REGAMMA_CNTLA_EXP_REGION0_LUT_OFFSET, curve[0].offset,
1274*b843c749SSergey Zigachev 		  REGAMMA_CNTLA_EXP_REGION0_NUM_SEGMENTS, curve[0].segments_num,
1275*b843c749SSergey Zigachev 		  REGAMMA_CNTLA_EXP_REGION1_LUT_OFFSET, curve[1].offset,
1276*b843c749SSergey Zigachev 		  REGAMMA_CNTLA_EXP_REGION1_NUM_SEGMENTS, curve[1].segments_num);
1277*b843c749SSergey Zigachev 	curve += 2;
1278*b843c749SSergey Zigachev 
1279*b843c749SSergey Zigachev 	REG_SET_4(REGAMMA_CNTLA_REGION_14_15, 0,
1280*b843c749SSergey Zigachev 		  REGAMMA_CNTLA_EXP_REGION0_LUT_OFFSET, curve[0].offset,
1281*b843c749SSergey Zigachev 		  REGAMMA_CNTLA_EXP_REGION0_NUM_SEGMENTS, curve[0].segments_num,
1282*b843c749SSergey Zigachev 		  REGAMMA_CNTLA_EXP_REGION1_LUT_OFFSET, curve[1].offset,
1283*b843c749SSergey Zigachev 		  REGAMMA_CNTLA_EXP_REGION1_NUM_SEGMENTS, curve[1].segments_num);
1284*b843c749SSergey Zigachev }
1285*b843c749SSergey Zigachev 
1286*b843c749SSergey Zigachev 
1287*b843c749SSergey Zigachev 
dce110_opp_program_regamma_pwl(struct transform * xfm,const struct pwl_params * params)1288*b843c749SSergey Zigachev void dce110_opp_program_regamma_pwl(struct transform *xfm,
1289*b843c749SSergey Zigachev 				    const struct pwl_params *params)
1290*b843c749SSergey Zigachev {
1291*b843c749SSergey Zigachev 	struct dce_transform *xfm_dce = TO_DCE_TRANSFORM(xfm);
1292*b843c749SSergey Zigachev 
1293*b843c749SSergey Zigachev 	/* Setup regions */
1294*b843c749SSergey Zigachev 	regamma_config_regions_and_segments(xfm_dce, params);
1295*b843c749SSergey Zigachev 
1296*b843c749SSergey Zigachev 	/* Program PWL */
1297*b843c749SSergey Zigachev 	program_pwl(xfm_dce, params);
1298*b843c749SSergey Zigachev }
1299*b843c749SSergey Zigachev 
dce110_opp_power_on_regamma_lut(struct transform * xfm,bool power_on)1300*b843c749SSergey Zigachev void dce110_opp_power_on_regamma_lut(struct transform *xfm,
1301*b843c749SSergey Zigachev 				     bool power_on)
1302*b843c749SSergey Zigachev {
1303*b843c749SSergey Zigachev 	struct dce_transform *xfm_dce = TO_DCE_TRANSFORM(xfm);
1304*b843c749SSergey Zigachev 
1305*b843c749SSergey Zigachev 	if (REG(DCFE_MEM_PWR_CTRL))
1306*b843c749SSergey Zigachev 		REG_UPDATE_2(DCFE_MEM_PWR_CTRL,
1307*b843c749SSergey Zigachev 			     DCP_REGAMMA_MEM_PWR_DIS, power_on,
1308*b843c749SSergey Zigachev 			     DCP_LUT_MEM_PWR_DIS, power_on);
1309*b843c749SSergey Zigachev 	else
1310*b843c749SSergey Zigachev 		REG_UPDATE_2(DCFE_MEM_LIGHT_SLEEP_CNTL,
1311*b843c749SSergey Zigachev 			    REGAMMA_LUT_LIGHT_SLEEP_DIS, power_on,
1312*b843c749SSergey Zigachev 			    DCP_LUT_LIGHT_SLEEP_DIS, power_on);
1313*b843c749SSergey Zigachev 
1314*b843c749SSergey Zigachev }
1315*b843c749SSergey Zigachev 
dce110_opp_set_regamma_mode(struct transform * xfm,enum opp_regamma mode)1316*b843c749SSergey Zigachev void dce110_opp_set_regamma_mode(struct transform *xfm,
1317*b843c749SSergey Zigachev 				 enum opp_regamma mode)
1318*b843c749SSergey Zigachev {
1319*b843c749SSergey Zigachev 	struct dce_transform *xfm_dce = TO_DCE_TRANSFORM(xfm);
1320*b843c749SSergey Zigachev 
1321*b843c749SSergey Zigachev 	REG_SET(REGAMMA_CONTROL, 0,
1322*b843c749SSergey Zigachev 		GRPH_REGAMMA_MODE, mode);
1323*b843c749SSergey Zigachev }
1324*b843c749SSergey Zigachev 
1325*b843c749SSergey Zigachev static const struct transform_funcs dce_transform_funcs = {
1326*b843c749SSergey Zigachev 	.transform_reset = dce_transform_reset,
1327*b843c749SSergey Zigachev 	.transform_set_scaler = dce_transform_set_scaler,
1328*b843c749SSergey Zigachev 	.transform_set_gamut_remap = dce_transform_set_gamut_remap,
1329*b843c749SSergey Zigachev 	.opp_set_csc_adjustment = dce110_opp_set_csc_adjustment,
1330*b843c749SSergey Zigachev 	.opp_set_csc_default = dce110_opp_set_csc_default,
1331*b843c749SSergey Zigachev 	.opp_power_on_regamma_lut = dce110_opp_power_on_regamma_lut,
1332*b843c749SSergey Zigachev 	.opp_program_regamma_pwl = dce110_opp_program_regamma_pwl,
1333*b843c749SSergey Zigachev 	.opp_set_regamma_mode = dce110_opp_set_regamma_mode,
1334*b843c749SSergey Zigachev 	.transform_set_pixel_storage_depth = dce_transform_set_pixel_storage_depth,
1335*b843c749SSergey Zigachev 	.transform_get_optimal_number_of_taps = dce_transform_get_optimal_number_of_taps
1336*b843c749SSergey Zigachev };
1337*b843c749SSergey Zigachev 
1338*b843c749SSergey Zigachev /*****************************************/
1339*b843c749SSergey Zigachev /* Constructor, Destructor               */
1340*b843c749SSergey Zigachev /*****************************************/
1341*b843c749SSergey Zigachev 
dce_transform_construct(struct dce_transform * xfm_dce,struct dc_context * ctx,uint32_t inst,const struct dce_transform_registers * regs,const struct dce_transform_shift * xfm_shift,const struct dce_transform_mask * xfm_mask)1342*b843c749SSergey Zigachev void dce_transform_construct(
1343*b843c749SSergey Zigachev 	struct dce_transform *xfm_dce,
1344*b843c749SSergey Zigachev 	struct dc_context *ctx,
1345*b843c749SSergey Zigachev 	uint32_t inst,
1346*b843c749SSergey Zigachev 	const struct dce_transform_registers *regs,
1347*b843c749SSergey Zigachev 	const struct dce_transform_shift *xfm_shift,
1348*b843c749SSergey Zigachev 	const struct dce_transform_mask *xfm_mask)
1349*b843c749SSergey Zigachev {
1350*b843c749SSergey Zigachev 	xfm_dce->base.ctx = ctx;
1351*b843c749SSergey Zigachev 
1352*b843c749SSergey Zigachev 	xfm_dce->base.inst = inst;
1353*b843c749SSergey Zigachev 	xfm_dce->base.funcs = &dce_transform_funcs;
1354*b843c749SSergey Zigachev 
1355*b843c749SSergey Zigachev 	xfm_dce->regs = regs;
1356*b843c749SSergey Zigachev 	xfm_dce->xfm_shift = xfm_shift;
1357*b843c749SSergey Zigachev 	xfm_dce->xfm_mask = xfm_mask;
1358*b843c749SSergey Zigachev 
1359*b843c749SSergey Zigachev 	xfm_dce->prescaler_on = true;
1360*b843c749SSergey Zigachev 	xfm_dce->lb_pixel_depth_supported =
1361*b843c749SSergey Zigachev 			LB_PIXEL_DEPTH_18BPP |
1362*b843c749SSergey Zigachev 			LB_PIXEL_DEPTH_24BPP |
1363*b843c749SSergey Zigachev 			LB_PIXEL_DEPTH_30BPP;
1364*b843c749SSergey Zigachev 
1365*b843c749SSergey Zigachev 	xfm_dce->lb_bits_per_entry = LB_BITS_PER_ENTRY;
1366*b843c749SSergey Zigachev 	xfm_dce->lb_memory_size = LB_TOTAL_NUMBER_OF_ENTRIES; /*0x6B0*/
1367*b843c749SSergey Zigachev }
1368