1b843c749SSergey Zigachev /*
2b843c749SSergey Zigachev  * Copyright 2016 Advanced Micro Devices, Inc.
3b843c749SSergey Zigachev  *
4b843c749SSergey Zigachev  * Permission is hereby granted, free of charge, to any person obtaining a
5b843c749SSergey Zigachev  * copy of this software and associated documentation files (the "Software"),
6b843c749SSergey Zigachev  * to deal in the Software without restriction, including without limitation
7b843c749SSergey Zigachev  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8b843c749SSergey Zigachev  * and/or sell copies of the Software, and to permit persons to whom the
9b843c749SSergey Zigachev  * Software is furnished to do so, subject to the following conditions:
10b843c749SSergey Zigachev  *
11b843c749SSergey Zigachev  * The above copyright notice and this permission notice shall be included in
12b843c749SSergey Zigachev  * all copies or substantial portions of the Software.
13b843c749SSergey Zigachev  *
14b843c749SSergey Zigachev  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15b843c749SSergey Zigachev  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16b843c749SSergey Zigachev  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
17b843c749SSergey Zigachev  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18b843c749SSergey Zigachev  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19b843c749SSergey Zigachev  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20b843c749SSergey Zigachev  * OTHER DEALINGS IN THE SOFTWARE.
21b843c749SSergey Zigachev  *
22b843c749SSergey Zigachev  * Authors: AMD
23b843c749SSergey Zigachev  *
24b843c749SSergey Zigachev  */
25b843c749SSergey Zigachev 
26b843c749SSergey Zigachev #include "dm_services.h"
27b843c749SSergey Zigachev 
28b843c749SSergey Zigachev #include "core_types.h"
29b843c749SSergey Zigachev 
30b843c749SSergey Zigachev #include "reg_helper.h"
31b843c749SSergey Zigachev #include "dcn10_dpp.h"
32b843c749SSergey Zigachev #include "basics/conversion.h"
33b843c749SSergey Zigachev 
34b843c749SSergey Zigachev 
35b843c749SSergey Zigachev #define NUM_PHASES    64
36b843c749SSergey Zigachev #define HORZ_MAX_TAPS 8
37b843c749SSergey Zigachev #define VERT_MAX_TAPS 8
38b843c749SSergey Zigachev 
39b843c749SSergey Zigachev #define BLACK_OFFSET_RGB_Y 0x0
40b843c749SSergey Zigachev #define BLACK_OFFSET_CBCR  0x8000
41b843c749SSergey Zigachev 
42b843c749SSergey Zigachev #define REG(reg)\
43b843c749SSergey Zigachev 	dpp->tf_regs->reg
44b843c749SSergey Zigachev 
45b843c749SSergey Zigachev #define CTX \
46b843c749SSergey Zigachev 	dpp->base.ctx
47b843c749SSergey Zigachev 
48b843c749SSergey Zigachev #undef FN
49b843c749SSergey Zigachev #define FN(reg_name, field_name) \
50b843c749SSergey Zigachev 	dpp->tf_shift->field_name, dpp->tf_mask->field_name
51b843c749SSergey Zigachev 
52b843c749SSergey Zigachev enum dcn10_coef_filter_type_sel {
53b843c749SSergey Zigachev 	SCL_COEF_LUMA_VERT_FILTER = 0,
54b843c749SSergey Zigachev 	SCL_COEF_LUMA_HORZ_FILTER = 1,
55b843c749SSergey Zigachev 	SCL_COEF_CHROMA_VERT_FILTER = 2,
56b843c749SSergey Zigachev 	SCL_COEF_CHROMA_HORZ_FILTER = 3,
57b843c749SSergey Zigachev 	SCL_COEF_ALPHA_VERT_FILTER = 4,
58b843c749SSergey Zigachev 	SCL_COEF_ALPHA_HORZ_FILTER = 5
59b843c749SSergey Zigachev };
60b843c749SSergey Zigachev 
61b843c749SSergey Zigachev enum dscl_autocal_mode {
62b843c749SSergey Zigachev 	AUTOCAL_MODE_OFF = 0,
63b843c749SSergey Zigachev 
64b843c749SSergey Zigachev 	/* Autocal calculate the scaling ratio and initial phase and the
65b843c749SSergey Zigachev 	 * DSCL_MODE_SEL must be set to 1
66b843c749SSergey Zigachev 	 */
67b843c749SSergey Zigachev 	AUTOCAL_MODE_AUTOSCALE = 1,
68b843c749SSergey Zigachev 	/* Autocal perform auto centering without replication and the
69b843c749SSergey Zigachev 	 * DSCL_MODE_SEL must be set to 0
70b843c749SSergey Zigachev 	 */
71b843c749SSergey Zigachev 	AUTOCAL_MODE_AUTOCENTER = 2,
72b843c749SSergey Zigachev 	/* Autocal perform auto centering and auto replication and the
73b843c749SSergey Zigachev 	 * DSCL_MODE_SEL must be set to 0
74b843c749SSergey Zigachev 	 */
75b843c749SSergey Zigachev 	AUTOCAL_MODE_AUTOREPLICATE = 3
76b843c749SSergey Zigachev };
77b843c749SSergey Zigachev 
78b843c749SSergey Zigachev enum dscl_mode_sel {
79b843c749SSergey Zigachev 	DSCL_MODE_SCALING_444_BYPASS = 0,
80b843c749SSergey Zigachev 	DSCL_MODE_SCALING_444_RGB_ENABLE = 1,
81b843c749SSergey Zigachev 	DSCL_MODE_SCALING_444_YCBCR_ENABLE = 2,
82b843c749SSergey Zigachev 	DSCL_MODE_SCALING_420_YCBCR_ENABLE = 3,
83b843c749SSergey Zigachev 	DSCL_MODE_SCALING_420_LUMA_BYPASS = 4,
84b843c749SSergey Zigachev 	DSCL_MODE_SCALING_420_CHROMA_BYPASS = 5,
85b843c749SSergey Zigachev 	DSCL_MODE_DSCL_BYPASS = 6
86b843c749SSergey Zigachev };
87b843c749SSergey Zigachev 
88*78973132SSergey Zigachev #if 0
89b843c749SSergey Zigachev static void dpp1_dscl_set_overscan(
90b843c749SSergey Zigachev 	struct dcn10_dpp *dpp,
91b843c749SSergey Zigachev 	const struct scaler_data *data)
92b843c749SSergey Zigachev {
93b843c749SSergey Zigachev 	uint32_t left = data->recout.x;
94b843c749SSergey Zigachev 	uint32_t top = data->recout.y;
95b843c749SSergey Zigachev 
96b843c749SSergey Zigachev 	int right = data->h_active - data->recout.x - data->recout.width;
97b843c749SSergey Zigachev 	int bottom = data->v_active - data->recout.y - data->recout.height;
98b843c749SSergey Zigachev 
99b843c749SSergey Zigachev 	if (right < 0) {
100b843c749SSergey Zigachev 		BREAK_TO_DEBUGGER();
101b843c749SSergey Zigachev 		right = 0;
102b843c749SSergey Zigachev 	}
103b843c749SSergey Zigachev 	if (bottom < 0) {
104b843c749SSergey Zigachev 		BREAK_TO_DEBUGGER();
105b843c749SSergey Zigachev 		bottom = 0;
106b843c749SSergey Zigachev 	}
107b843c749SSergey Zigachev 
108b843c749SSergey Zigachev 	REG_SET_2(DSCL_EXT_OVERSCAN_LEFT_RIGHT, 0,
109b843c749SSergey Zigachev 		EXT_OVERSCAN_LEFT, left,
110b843c749SSergey Zigachev 		EXT_OVERSCAN_RIGHT, right);
111b843c749SSergey Zigachev 
112b843c749SSergey Zigachev 	REG_SET_2(DSCL_EXT_OVERSCAN_TOP_BOTTOM, 0,
113b843c749SSergey Zigachev 		EXT_OVERSCAN_BOTTOM, bottom,
114b843c749SSergey Zigachev 		EXT_OVERSCAN_TOP, top);
115b843c749SSergey Zigachev }
116b843c749SSergey Zigachev 
117b843c749SSergey Zigachev static void dpp1_dscl_set_otg_blank(
118b843c749SSergey Zigachev 		struct dcn10_dpp *dpp, const struct scaler_data *data)
119b843c749SSergey Zigachev {
120b843c749SSergey Zigachev 	uint32_t h_blank_start = data->h_active;
121b843c749SSergey Zigachev 	uint32_t h_blank_end = 0;
122b843c749SSergey Zigachev 	uint32_t v_blank_start = data->v_active;
123b843c749SSergey Zigachev 	uint32_t v_blank_end = 0;
124b843c749SSergey Zigachev 
125b843c749SSergey Zigachev 	REG_SET_2(OTG_H_BLANK, 0,
126b843c749SSergey Zigachev 			OTG_H_BLANK_START, h_blank_start,
127b843c749SSergey Zigachev 			OTG_H_BLANK_END, h_blank_end);
128b843c749SSergey Zigachev 
129b843c749SSergey Zigachev 	REG_SET_2(OTG_V_BLANK, 0,
130b843c749SSergey Zigachev 			OTG_V_BLANK_START, v_blank_start,
131b843c749SSergey Zigachev 			OTG_V_BLANK_END, v_blank_end);
132b843c749SSergey Zigachev }
133*78973132SSergey Zigachev #endif
134b843c749SSergey Zigachev 
dpp1_dscl_get_pixel_depth_val(enum lb_pixel_depth depth)135b843c749SSergey Zigachev static int dpp1_dscl_get_pixel_depth_val(enum lb_pixel_depth depth)
136b843c749SSergey Zigachev {
137b843c749SSergey Zigachev 	if (depth == LB_PIXEL_DEPTH_30BPP)
138b843c749SSergey Zigachev 		return 0; /* 10 bpc */
139b843c749SSergey Zigachev 	else if (depth == LB_PIXEL_DEPTH_24BPP)
140b843c749SSergey Zigachev 		return 1; /* 8 bpc */
141b843c749SSergey Zigachev 	else if (depth == LB_PIXEL_DEPTH_18BPP)
142b843c749SSergey Zigachev 		return 2; /* 6 bpc */
143b843c749SSergey Zigachev 	else if (depth == LB_PIXEL_DEPTH_36BPP)
144b843c749SSergey Zigachev 		return 3; /* 12 bpc */
145b843c749SSergey Zigachev 	else {
146b843c749SSergey Zigachev 		ASSERT(0);
147b843c749SSergey Zigachev 		return -1; /* Unsupported */
148b843c749SSergey Zigachev 	}
149b843c749SSergey Zigachev }
150b843c749SSergey Zigachev 
dpp1_dscl_is_video_format(enum pixel_format format)151b843c749SSergey Zigachev static bool dpp1_dscl_is_video_format(enum pixel_format format)
152b843c749SSergey Zigachev {
153b843c749SSergey Zigachev 	if (format >= PIXEL_FORMAT_VIDEO_BEGIN
154b843c749SSergey Zigachev 			&& format <= PIXEL_FORMAT_VIDEO_END)
155b843c749SSergey Zigachev 		return true;
156b843c749SSergey Zigachev 	else
157b843c749SSergey Zigachev 		return false;
158b843c749SSergey Zigachev }
159b843c749SSergey Zigachev 
dpp1_dscl_is_420_format(enum pixel_format format)160b843c749SSergey Zigachev static bool dpp1_dscl_is_420_format(enum pixel_format format)
161b843c749SSergey Zigachev {
162b843c749SSergey Zigachev 	if (format == PIXEL_FORMAT_420BPP8 ||
163b843c749SSergey Zigachev 			format == PIXEL_FORMAT_420BPP10)
164b843c749SSergey Zigachev 		return true;
165b843c749SSergey Zigachev 	else
166b843c749SSergey Zigachev 		return false;
167b843c749SSergey Zigachev }
168b843c749SSergey Zigachev 
dpp1_dscl_get_dscl_mode(struct dpp * dpp_base,const struct scaler_data * data,bool dbg_always_scale)169b843c749SSergey Zigachev static enum dscl_mode_sel dpp1_dscl_get_dscl_mode(
170b843c749SSergey Zigachev 		struct dpp *dpp_base,
171b843c749SSergey Zigachev 		const struct scaler_data *data,
172b843c749SSergey Zigachev 		bool dbg_always_scale)
173b843c749SSergey Zigachev {
174b843c749SSergey Zigachev 	const long long one = dc_fixpt_one.value;
175b843c749SSergey Zigachev 
176b843c749SSergey Zigachev 	if (dpp_base->caps->dscl_data_proc_format == DSCL_DATA_PRCESSING_FIXED_FORMAT) {
177b843c749SSergey Zigachev 		/* DSCL is processing data in fixed format */
178b843c749SSergey Zigachev 		if (data->format == PIXEL_FORMAT_FP16)
179b843c749SSergey Zigachev 			return DSCL_MODE_DSCL_BYPASS;
180b843c749SSergey Zigachev 	}
181b843c749SSergey Zigachev 
182b843c749SSergey Zigachev 	if (data->ratios.horz.value == one
183b843c749SSergey Zigachev 			&& data->ratios.vert.value == one
184b843c749SSergey Zigachev 			&& data->ratios.horz_c.value == one
185b843c749SSergey Zigachev 			&& data->ratios.vert_c.value == one
186b843c749SSergey Zigachev 			&& !dbg_always_scale)
187b843c749SSergey Zigachev 		return DSCL_MODE_SCALING_444_BYPASS;
188b843c749SSergey Zigachev 
189b843c749SSergey Zigachev 	if (!dpp1_dscl_is_420_format(data->format)) {
190b843c749SSergey Zigachev 		if (dpp1_dscl_is_video_format(data->format))
191b843c749SSergey Zigachev 			return DSCL_MODE_SCALING_444_YCBCR_ENABLE;
192b843c749SSergey Zigachev 		else
193b843c749SSergey Zigachev 			return DSCL_MODE_SCALING_444_RGB_ENABLE;
194b843c749SSergey Zigachev 	}
195b843c749SSergey Zigachev 	if (data->ratios.horz.value == one && data->ratios.vert.value == one)
196b843c749SSergey Zigachev 		return DSCL_MODE_SCALING_420_LUMA_BYPASS;
197b843c749SSergey Zigachev 	if (data->ratios.horz_c.value == one && data->ratios.vert_c.value == one)
198b843c749SSergey Zigachev 		return DSCL_MODE_SCALING_420_CHROMA_BYPASS;
199b843c749SSergey Zigachev 
200b843c749SSergey Zigachev 	return DSCL_MODE_SCALING_420_YCBCR_ENABLE;
201b843c749SSergey Zigachev }
202b843c749SSergey Zigachev 
dpp1_dscl_set_lb(struct dcn10_dpp * dpp,const struct line_buffer_params * lb_params,enum lb_memory_config mem_size_config)203b843c749SSergey Zigachev static void dpp1_dscl_set_lb(
204b843c749SSergey Zigachev 	struct dcn10_dpp *dpp,
205b843c749SSergey Zigachev 	const struct line_buffer_params *lb_params,
206b843c749SSergey Zigachev 	enum lb_memory_config mem_size_config)
207b843c749SSergey Zigachev {
208b843c749SSergey Zigachev 	/* LB */
209b843c749SSergey Zigachev 	if (dpp->base.caps->dscl_data_proc_format == DSCL_DATA_PRCESSING_FIXED_FORMAT) {
210b843c749SSergey Zigachev 		/* DSCL caps: pixel data processed in fixed format */
211b843c749SSergey Zigachev 		uint32_t pixel_depth = dpp1_dscl_get_pixel_depth_val(lb_params->depth);
212b843c749SSergey Zigachev 		uint32_t dyn_pix_depth = lb_params->dynamic_pixel_depth;
213b843c749SSergey Zigachev 
214b843c749SSergey Zigachev 		REG_SET_7(LB_DATA_FORMAT, 0,
215b843c749SSergey Zigachev 			PIXEL_DEPTH, pixel_depth, /* Pixel depth stored in LB */
216b843c749SSergey Zigachev 			PIXEL_EXPAN_MODE, lb_params->pixel_expan_mode, /* Pixel expansion mode */
217b843c749SSergey Zigachev 			PIXEL_REDUCE_MODE, 1, /* Pixel reduction mode: Rounding */
218b843c749SSergey Zigachev 			DYNAMIC_PIXEL_DEPTH, dyn_pix_depth, /* Dynamic expansion pixel depth */
219b843c749SSergey Zigachev 			DITHER_EN, 0, /* Dithering enable: Disabled */
220b843c749SSergey Zigachev 			INTERLEAVE_EN, lb_params->interleave_en, /* Interleave source enable */
221b843c749SSergey Zigachev 			LB_DATA_FORMAT__ALPHA_EN, lb_params->alpha_en); /* Alpha enable */
222b843c749SSergey Zigachev 	}
223b843c749SSergey Zigachev 
224b843c749SSergey Zigachev 	REG_SET_2(LB_MEMORY_CTRL, 0,
225b843c749SSergey Zigachev 		MEMORY_CONFIG, mem_size_config,
226b843c749SSergey Zigachev 		LB_MAX_PARTITIONS, 63);
227b843c749SSergey Zigachev }
228b843c749SSergey Zigachev 
dpp1_dscl_get_filter_coeffs_64p(int taps,struct fixed31_32 ratio)229b843c749SSergey Zigachev static const uint16_t *dpp1_dscl_get_filter_coeffs_64p(int taps, struct fixed31_32 ratio)
230b843c749SSergey Zigachev {
231b843c749SSergey Zigachev 	if (taps == 8)
232b843c749SSergey Zigachev 		return get_filter_8tap_64p(ratio);
233b843c749SSergey Zigachev 	else if (taps == 7)
234b843c749SSergey Zigachev 		return get_filter_7tap_64p(ratio);
235b843c749SSergey Zigachev 	else if (taps == 6)
236b843c749SSergey Zigachev 		return get_filter_6tap_64p(ratio);
237b843c749SSergey Zigachev 	else if (taps == 5)
238b843c749SSergey Zigachev 		return get_filter_5tap_64p(ratio);
239b843c749SSergey Zigachev 	else if (taps == 4)
240b843c749SSergey Zigachev 		return get_filter_4tap_64p(ratio);
241b843c749SSergey Zigachev 	else if (taps == 3)
242b843c749SSergey Zigachev 		return get_filter_3tap_64p(ratio);
243b843c749SSergey Zigachev 	else if (taps == 2)
244b843c749SSergey Zigachev 		return get_filter_2tap_64p();
245b843c749SSergey Zigachev 	else if (taps == 1)
246b843c749SSergey Zigachev 		return NULL;
247b843c749SSergey Zigachev 	else {
248b843c749SSergey Zigachev 		/* should never happen, bug */
249b843c749SSergey Zigachev 		BREAK_TO_DEBUGGER();
250b843c749SSergey Zigachev 		return NULL;
251b843c749SSergey Zigachev 	}
252b843c749SSergey Zigachev }
253b843c749SSergey Zigachev 
dpp1_dscl_set_scaler_filter(struct dcn10_dpp * dpp,uint32_t taps,enum dcn10_coef_filter_type_sel filter_type,const uint16_t * filter)254b843c749SSergey Zigachev static void dpp1_dscl_set_scaler_filter(
255b843c749SSergey Zigachev 		struct dcn10_dpp *dpp,
256b843c749SSergey Zigachev 		uint32_t taps,
257b843c749SSergey Zigachev 		enum dcn10_coef_filter_type_sel filter_type,
258b843c749SSergey Zigachev 		const uint16_t *filter)
259b843c749SSergey Zigachev {
260b843c749SSergey Zigachev 	const int tap_pairs = (taps + 1) / 2;
261b843c749SSergey Zigachev 	int phase;
262b843c749SSergey Zigachev 	int pair;
263b843c749SSergey Zigachev 	uint16_t odd_coef, even_coef;
264b843c749SSergey Zigachev 
265b843c749SSergey Zigachev 	REG_SET_3(SCL_COEF_RAM_TAP_SELECT, 0,
266b843c749SSergey Zigachev 		SCL_COEF_RAM_TAP_PAIR_IDX, 0,
267b843c749SSergey Zigachev 		SCL_COEF_RAM_PHASE, 0,
268b843c749SSergey Zigachev 		SCL_COEF_RAM_FILTER_TYPE, filter_type);
269b843c749SSergey Zigachev 
270b843c749SSergey Zigachev 	for (phase = 0; phase < (NUM_PHASES / 2 + 1); phase++) {
271b843c749SSergey Zigachev 		for (pair = 0; pair < tap_pairs; pair++) {
272b843c749SSergey Zigachev 			even_coef = filter[phase * taps + 2 * pair];
273b843c749SSergey Zigachev 			if ((pair * 2 + 1) < taps)
274b843c749SSergey Zigachev 				odd_coef = filter[phase * taps + 2 * pair + 1];
275b843c749SSergey Zigachev 			else
276b843c749SSergey Zigachev 				odd_coef = 0;
277b843c749SSergey Zigachev 
278b843c749SSergey Zigachev 			REG_SET_4(SCL_COEF_RAM_TAP_DATA, 0,
279b843c749SSergey Zigachev 				/* Even tap coefficient (bits 1:0 fixed to 0) */
280b843c749SSergey Zigachev 				SCL_COEF_RAM_EVEN_TAP_COEF, even_coef,
281b843c749SSergey Zigachev 				/* Write/read control for even coefficient */
282b843c749SSergey Zigachev 				SCL_COEF_RAM_EVEN_TAP_COEF_EN, 1,
283b843c749SSergey Zigachev 				/* Odd tap coefficient (bits 1:0 fixed to 0) */
284b843c749SSergey Zigachev 				SCL_COEF_RAM_ODD_TAP_COEF, odd_coef,
285b843c749SSergey Zigachev 				/* Write/read control for odd coefficient */
286b843c749SSergey Zigachev 				SCL_COEF_RAM_ODD_TAP_COEF_EN, 1);
287b843c749SSergey Zigachev 		}
288b843c749SSergey Zigachev 	}
289b843c749SSergey Zigachev 
290b843c749SSergey Zigachev }
291b843c749SSergey Zigachev 
dpp1_dscl_set_scl_filter(struct dcn10_dpp * dpp,const struct scaler_data * scl_data,bool chroma_coef_mode)292b843c749SSergey Zigachev static void dpp1_dscl_set_scl_filter(
293b843c749SSergey Zigachev 		struct dcn10_dpp *dpp,
294b843c749SSergey Zigachev 		const struct scaler_data *scl_data,
295b843c749SSergey Zigachev 		bool chroma_coef_mode)
296b843c749SSergey Zigachev {
297b843c749SSergey Zigachev 	bool h_2tap_hardcode_coef_en = false;
298b843c749SSergey Zigachev 	bool v_2tap_hardcode_coef_en = false;
299b843c749SSergey Zigachev 	bool h_2tap_sharp_en = false;
300b843c749SSergey Zigachev 	bool v_2tap_sharp_en = false;
301b843c749SSergey Zigachev 	uint32_t h_2tap_sharp_factor = scl_data->sharpness.horz;
302b843c749SSergey Zigachev 	uint32_t v_2tap_sharp_factor = scl_data->sharpness.vert;
303b843c749SSergey Zigachev 	bool coef_ram_current;
304b843c749SSergey Zigachev 	const uint16_t *filter_h = NULL;
305b843c749SSergey Zigachev 	const uint16_t *filter_v = NULL;
306b843c749SSergey Zigachev 	const uint16_t *filter_h_c = NULL;
307b843c749SSergey Zigachev 	const uint16_t *filter_v_c = NULL;
308b843c749SSergey Zigachev 
309b843c749SSergey Zigachev 	h_2tap_hardcode_coef_en = scl_data->taps.h_taps < 3
310b843c749SSergey Zigachev 					&& scl_data->taps.h_taps_c < 3
311b843c749SSergey Zigachev 		&& (scl_data->taps.h_taps > 1 && scl_data->taps.h_taps_c > 1);
312b843c749SSergey Zigachev 	v_2tap_hardcode_coef_en = scl_data->taps.v_taps < 3
313b843c749SSergey Zigachev 					&& scl_data->taps.v_taps_c < 3
314b843c749SSergey Zigachev 		&& (scl_data->taps.v_taps > 1 && scl_data->taps.v_taps_c > 1);
315b843c749SSergey Zigachev 
316b843c749SSergey Zigachev 	h_2tap_sharp_en = h_2tap_hardcode_coef_en && h_2tap_sharp_factor != 0;
317b843c749SSergey Zigachev 	v_2tap_sharp_en = v_2tap_hardcode_coef_en && v_2tap_sharp_factor != 0;
318b843c749SSergey Zigachev 
319b843c749SSergey Zigachev 	REG_UPDATE_6(DSCL_2TAP_CONTROL,
320b843c749SSergey Zigachev 		SCL_H_2TAP_HARDCODE_COEF_EN, h_2tap_hardcode_coef_en,
321b843c749SSergey Zigachev 		SCL_H_2TAP_SHARP_EN, h_2tap_sharp_en,
322b843c749SSergey Zigachev 		SCL_H_2TAP_SHARP_FACTOR, h_2tap_sharp_factor,
323b843c749SSergey Zigachev 		SCL_V_2TAP_HARDCODE_COEF_EN, v_2tap_hardcode_coef_en,
324b843c749SSergey Zigachev 		SCL_V_2TAP_SHARP_EN, v_2tap_sharp_en,
325b843c749SSergey Zigachev 		SCL_V_2TAP_SHARP_FACTOR, v_2tap_sharp_factor);
326b843c749SSergey Zigachev 
327b843c749SSergey Zigachev 	if (!v_2tap_hardcode_coef_en || !h_2tap_hardcode_coef_en) {
328b843c749SSergey Zigachev 		bool filter_updated = false;
329b843c749SSergey Zigachev 
330b843c749SSergey Zigachev 		filter_h = dpp1_dscl_get_filter_coeffs_64p(
331b843c749SSergey Zigachev 				scl_data->taps.h_taps, scl_data->ratios.horz);
332b843c749SSergey Zigachev 		filter_v = dpp1_dscl_get_filter_coeffs_64p(
333b843c749SSergey Zigachev 				scl_data->taps.v_taps, scl_data->ratios.vert);
334b843c749SSergey Zigachev 
335b843c749SSergey Zigachev 		filter_updated = (filter_h && (filter_h != dpp->filter_h))
336b843c749SSergey Zigachev 				|| (filter_v && (filter_v != dpp->filter_v));
337b843c749SSergey Zigachev 
338b843c749SSergey Zigachev 		if (chroma_coef_mode) {
339b843c749SSergey Zigachev 			filter_h_c = dpp1_dscl_get_filter_coeffs_64p(
340b843c749SSergey Zigachev 					scl_data->taps.h_taps_c, scl_data->ratios.horz_c);
341b843c749SSergey Zigachev 			filter_v_c = dpp1_dscl_get_filter_coeffs_64p(
342b843c749SSergey Zigachev 					scl_data->taps.v_taps_c, scl_data->ratios.vert_c);
343b843c749SSergey Zigachev 			filter_updated = filter_updated || (filter_h_c && (filter_h_c != dpp->filter_h_c))
344b843c749SSergey Zigachev 							|| (filter_v_c && (filter_v_c != dpp->filter_v_c));
345b843c749SSergey Zigachev 		}
346b843c749SSergey Zigachev 
347b843c749SSergey Zigachev 		if (filter_updated) {
348b843c749SSergey Zigachev 			uint32_t scl_mode = REG_READ(SCL_MODE);
349b843c749SSergey Zigachev 
350b843c749SSergey Zigachev 			if (!h_2tap_hardcode_coef_en && filter_h) {
351b843c749SSergey Zigachev 				dpp1_dscl_set_scaler_filter(
352b843c749SSergey Zigachev 					dpp, scl_data->taps.h_taps,
353b843c749SSergey Zigachev 					SCL_COEF_LUMA_HORZ_FILTER, filter_h);
354b843c749SSergey Zigachev 			}
355b843c749SSergey Zigachev 			dpp->filter_h = filter_h;
356b843c749SSergey Zigachev 			if (!v_2tap_hardcode_coef_en && filter_v) {
357b843c749SSergey Zigachev 				dpp1_dscl_set_scaler_filter(
358b843c749SSergey Zigachev 					dpp, scl_data->taps.v_taps,
359b843c749SSergey Zigachev 					SCL_COEF_LUMA_VERT_FILTER, filter_v);
360b843c749SSergey Zigachev 			}
361b843c749SSergey Zigachev 			dpp->filter_v = filter_v;
362b843c749SSergey Zigachev 			if (chroma_coef_mode) {
363b843c749SSergey Zigachev 				if (!h_2tap_hardcode_coef_en && filter_h_c) {
364b843c749SSergey Zigachev 					dpp1_dscl_set_scaler_filter(
365b843c749SSergey Zigachev 						dpp, scl_data->taps.h_taps_c,
366b843c749SSergey Zigachev 						SCL_COEF_CHROMA_HORZ_FILTER, filter_h_c);
367b843c749SSergey Zigachev 				}
368b843c749SSergey Zigachev 				if (!v_2tap_hardcode_coef_en && filter_v_c) {
369b843c749SSergey Zigachev 					dpp1_dscl_set_scaler_filter(
370b843c749SSergey Zigachev 						dpp, scl_data->taps.v_taps_c,
371b843c749SSergey Zigachev 						SCL_COEF_CHROMA_VERT_FILTER, filter_v_c);
372b843c749SSergey Zigachev 				}
373b843c749SSergey Zigachev 			}
374b843c749SSergey Zigachev 			dpp->filter_h_c = filter_h_c;
375b843c749SSergey Zigachev 			dpp->filter_v_c = filter_v_c;
376b843c749SSergey Zigachev 
377b843c749SSergey Zigachev 			coef_ram_current = get_reg_field_value_ex(
378b843c749SSergey Zigachev 				scl_mode, dpp->tf_mask->SCL_COEF_RAM_SELECT_CURRENT,
379b843c749SSergey Zigachev 				dpp->tf_shift->SCL_COEF_RAM_SELECT_CURRENT);
380b843c749SSergey Zigachev 
381b843c749SSergey Zigachev 			/* Swap coefficient RAM and set chroma coefficient mode */
382b843c749SSergey Zigachev 			REG_SET_2(SCL_MODE, scl_mode,
383b843c749SSergey Zigachev 					SCL_COEF_RAM_SELECT, !coef_ram_current,
384b843c749SSergey Zigachev 					SCL_CHROMA_COEF_MODE, chroma_coef_mode);
385b843c749SSergey Zigachev 		}
386b843c749SSergey Zigachev 	}
387b843c749SSergey Zigachev }
388b843c749SSergey Zigachev 
dpp1_dscl_get_lb_depth_bpc(enum lb_pixel_depth depth)389b843c749SSergey Zigachev static int dpp1_dscl_get_lb_depth_bpc(enum lb_pixel_depth depth)
390b843c749SSergey Zigachev {
391b843c749SSergey Zigachev 	if (depth == LB_PIXEL_DEPTH_30BPP)
392b843c749SSergey Zigachev 		return 10;
393b843c749SSergey Zigachev 	else if (depth == LB_PIXEL_DEPTH_24BPP)
394b843c749SSergey Zigachev 		return 8;
395b843c749SSergey Zigachev 	else if (depth == LB_PIXEL_DEPTH_18BPP)
396b843c749SSergey Zigachev 		return 6;
397b843c749SSergey Zigachev 	else if (depth == LB_PIXEL_DEPTH_36BPP)
398b843c749SSergey Zigachev 		return 12;
399b843c749SSergey Zigachev 	else {
400b843c749SSergey Zigachev 		BREAK_TO_DEBUGGER();
401b843c749SSergey Zigachev 		return -1; /* Unsupported */
402b843c749SSergey Zigachev 	}
403b843c749SSergey Zigachev }
404b843c749SSergey Zigachev 
dpp1_dscl_calc_lb_num_partitions(const struct scaler_data * scl_data,enum lb_memory_config lb_config,int * num_part_y,int * num_part_c)405b843c749SSergey Zigachev void dpp1_dscl_calc_lb_num_partitions(
406b843c749SSergey Zigachev 		const struct scaler_data *scl_data,
407b843c749SSergey Zigachev 		enum lb_memory_config lb_config,
408b843c749SSergey Zigachev 		int *num_part_y,
409b843c749SSergey Zigachev 		int *num_part_c)
410b843c749SSergey Zigachev {
411b843c749SSergey Zigachev 	int lb_memory_size, lb_memory_size_c, lb_memory_size_a, num_partitions_a,
412b843c749SSergey Zigachev 	lb_bpc, memory_line_size_y, memory_line_size_c, memory_line_size_a;
413b843c749SSergey Zigachev 
414b843c749SSergey Zigachev 	int line_size = scl_data->viewport.width < scl_data->recout.width ?
415b843c749SSergey Zigachev 			scl_data->viewport.width : scl_data->recout.width;
416b843c749SSergey Zigachev 	int line_size_c = scl_data->viewport_c.width < scl_data->recout.width ?
417b843c749SSergey Zigachev 			scl_data->viewport_c.width : scl_data->recout.width;
418b843c749SSergey Zigachev 
419b843c749SSergey Zigachev 	if (line_size == 0)
420b843c749SSergey Zigachev 		line_size = 1;
421b843c749SSergey Zigachev 
422b843c749SSergey Zigachev 	if (line_size_c == 0)
423b843c749SSergey Zigachev 		line_size_c = 1;
424b843c749SSergey Zigachev 
425b843c749SSergey Zigachev 
426b843c749SSergey Zigachev 	lb_bpc = dpp1_dscl_get_lb_depth_bpc(scl_data->lb_params.depth);
427b843c749SSergey Zigachev 	memory_line_size_y = (line_size * lb_bpc + 71) / 72; /* +71 to ceil */
428b843c749SSergey Zigachev 	memory_line_size_c = (line_size_c * lb_bpc + 71) / 72; /* +71 to ceil */
429b843c749SSergey Zigachev 	memory_line_size_a = (line_size + 5) / 6; /* +5 to ceil */
430b843c749SSergey Zigachev 
431b843c749SSergey Zigachev 	if (lb_config == LB_MEMORY_CONFIG_1) {
432b843c749SSergey Zigachev 		lb_memory_size = 816;
433b843c749SSergey Zigachev 		lb_memory_size_c = 816;
434b843c749SSergey Zigachev 		lb_memory_size_a = 984;
435b843c749SSergey Zigachev 	} else if (lb_config == LB_MEMORY_CONFIG_2) {
436b843c749SSergey Zigachev 		lb_memory_size = 1088;
437b843c749SSergey Zigachev 		lb_memory_size_c = 1088;
438b843c749SSergey Zigachev 		lb_memory_size_a = 1312;
439b843c749SSergey Zigachev 	} else if (lb_config == LB_MEMORY_CONFIG_3) {
440b843c749SSergey Zigachev 		/* 420 mode: using 3rd mem from Y, Cr and Cb */
441b843c749SSergey Zigachev 		lb_memory_size = 816 + 1088 + 848 + 848 + 848;
442b843c749SSergey Zigachev 		lb_memory_size_c = 816 + 1088;
443b843c749SSergey Zigachev 		lb_memory_size_a = 984 + 1312 + 456;
444b843c749SSergey Zigachev 	} else {
445b843c749SSergey Zigachev 		lb_memory_size = 816 + 1088 + 848;
446b843c749SSergey Zigachev 		lb_memory_size_c = 816 + 1088 + 848;
447b843c749SSergey Zigachev 		lb_memory_size_a = 984 + 1312 + 456;
448b843c749SSergey Zigachev 	}
449b843c749SSergey Zigachev 	*num_part_y = lb_memory_size / memory_line_size_y;
450b843c749SSergey Zigachev 	*num_part_c = lb_memory_size_c / memory_line_size_c;
451b843c749SSergey Zigachev 	num_partitions_a = lb_memory_size_a / memory_line_size_a;
452b843c749SSergey Zigachev 
453b843c749SSergey Zigachev 	if (scl_data->lb_params.alpha_en
454b843c749SSergey Zigachev 			&& (num_partitions_a < *num_part_y))
455b843c749SSergey Zigachev 		*num_part_y = num_partitions_a;
456b843c749SSergey Zigachev 
457b843c749SSergey Zigachev 	if (*num_part_y > 64)
458b843c749SSergey Zigachev 		*num_part_y = 64;
459b843c749SSergey Zigachev 	if (*num_part_c > 64)
460b843c749SSergey Zigachev 		*num_part_c = 64;
461b843c749SSergey Zigachev 
462b843c749SSergey Zigachev }
463b843c749SSergey Zigachev 
dpp1_dscl_is_lb_conf_valid(int ceil_vratio,int num_partitions,int vtaps)464b843c749SSergey Zigachev bool dpp1_dscl_is_lb_conf_valid(int ceil_vratio, int num_partitions, int vtaps)
465b843c749SSergey Zigachev {
466b843c749SSergey Zigachev 	if (ceil_vratio > 2)
467b843c749SSergey Zigachev 		return vtaps <= (num_partitions - ceil_vratio + 2);
468b843c749SSergey Zigachev 	else
469b843c749SSergey Zigachev 		return vtaps <= num_partitions;
470b843c749SSergey Zigachev }
471b843c749SSergey Zigachev 
472b843c749SSergey Zigachev /*find first match configuration which meets the min required lb size*/
dpp1_dscl_find_lb_memory_config(struct dcn10_dpp * dpp,const struct scaler_data * scl_data)473b843c749SSergey Zigachev static enum lb_memory_config dpp1_dscl_find_lb_memory_config(struct dcn10_dpp *dpp,
474b843c749SSergey Zigachev 		const struct scaler_data *scl_data)
475b843c749SSergey Zigachev {
476b843c749SSergey Zigachev 	int num_part_y, num_part_c;
477b843c749SSergey Zigachev 	int vtaps = scl_data->taps.v_taps;
478b843c749SSergey Zigachev 	int vtaps_c = scl_data->taps.v_taps_c;
479b843c749SSergey Zigachev 	int ceil_vratio = dc_fixpt_ceil(scl_data->ratios.vert);
480b843c749SSergey Zigachev 	int ceil_vratio_c = dc_fixpt_ceil(scl_data->ratios.vert_c);
481b843c749SSergey Zigachev 
482b843c749SSergey Zigachev 	if (dpp->base.ctx->dc->debug.use_max_lb) {
483b843c749SSergey Zigachev 		if (scl_data->format == PIXEL_FORMAT_420BPP8
484b843c749SSergey Zigachev 				|| scl_data->format == PIXEL_FORMAT_420BPP10)
485b843c749SSergey Zigachev 			return LB_MEMORY_CONFIG_3;
486b843c749SSergey Zigachev 		return LB_MEMORY_CONFIG_0;
487b843c749SSergey Zigachev 	}
488b843c749SSergey Zigachev 
489b843c749SSergey Zigachev 	dpp->base.caps->dscl_calc_lb_num_partitions(
490b843c749SSergey Zigachev 			scl_data, LB_MEMORY_CONFIG_1, &num_part_y, &num_part_c);
491b843c749SSergey Zigachev 
492b843c749SSergey Zigachev 	if (dpp1_dscl_is_lb_conf_valid(ceil_vratio, num_part_y, vtaps)
493b843c749SSergey Zigachev 			&& dpp1_dscl_is_lb_conf_valid(ceil_vratio_c, num_part_c, vtaps_c))
494b843c749SSergey Zigachev 		return LB_MEMORY_CONFIG_1;
495b843c749SSergey Zigachev 
496b843c749SSergey Zigachev 	dpp->base.caps->dscl_calc_lb_num_partitions(
497b843c749SSergey Zigachev 			scl_data, LB_MEMORY_CONFIG_2, &num_part_y, &num_part_c);
498b843c749SSergey Zigachev 
499b843c749SSergey Zigachev 	if (dpp1_dscl_is_lb_conf_valid(ceil_vratio, num_part_y, vtaps)
500b843c749SSergey Zigachev 			&& dpp1_dscl_is_lb_conf_valid(ceil_vratio_c, num_part_c, vtaps_c))
501b843c749SSergey Zigachev 		return LB_MEMORY_CONFIG_2;
502b843c749SSergey Zigachev 
503b843c749SSergey Zigachev 	if (scl_data->format == PIXEL_FORMAT_420BPP8
504b843c749SSergey Zigachev 			|| scl_data->format == PIXEL_FORMAT_420BPP10) {
505b843c749SSergey Zigachev 		dpp->base.caps->dscl_calc_lb_num_partitions(
506b843c749SSergey Zigachev 				scl_data, LB_MEMORY_CONFIG_3, &num_part_y, &num_part_c);
507b843c749SSergey Zigachev 
508b843c749SSergey Zigachev 		if (dpp1_dscl_is_lb_conf_valid(ceil_vratio, num_part_y, vtaps)
509b843c749SSergey Zigachev 				&& dpp1_dscl_is_lb_conf_valid(ceil_vratio_c, num_part_c, vtaps_c))
510b843c749SSergey Zigachev 			return LB_MEMORY_CONFIG_3;
511b843c749SSergey Zigachev 	}
512b843c749SSergey Zigachev 
513b843c749SSergey Zigachev 	dpp->base.caps->dscl_calc_lb_num_partitions(
514b843c749SSergey Zigachev 			scl_data, LB_MEMORY_CONFIG_0, &num_part_y, &num_part_c);
515b843c749SSergey Zigachev 
516b843c749SSergey Zigachev 	/*Ensure we can support the requested number of vtaps*/
517b843c749SSergey Zigachev 	ASSERT(dpp1_dscl_is_lb_conf_valid(ceil_vratio, num_part_y, vtaps)
518b843c749SSergey Zigachev 			&& dpp1_dscl_is_lb_conf_valid(ceil_vratio_c, num_part_c, vtaps_c));
519b843c749SSergey Zigachev 
520b843c749SSergey Zigachev 	return LB_MEMORY_CONFIG_0;
521b843c749SSergey Zigachev }
522b843c749SSergey Zigachev 
523*78973132SSergey Zigachev #if 0
524b843c749SSergey Zigachev void dpp1_dscl_set_scaler_auto_scale(
525b843c749SSergey Zigachev 	struct dpp *dpp_base,
526b843c749SSergey Zigachev 	const struct scaler_data *scl_data)
527b843c749SSergey Zigachev {
528b843c749SSergey Zigachev 	enum lb_memory_config lb_config;
529b843c749SSergey Zigachev 	struct dcn10_dpp *dpp = TO_DCN10_DPP(dpp_base);
530b843c749SSergey Zigachev 	enum dscl_mode_sel dscl_mode = dpp1_dscl_get_dscl_mode(
531b843c749SSergey Zigachev 			dpp_base, scl_data, dpp_base->ctx->dc->debug.always_scale);
532b843c749SSergey Zigachev 	bool ycbcr = scl_data->format >= PIXEL_FORMAT_VIDEO_BEGIN
533b843c749SSergey Zigachev 				&& scl_data->format <= PIXEL_FORMAT_VIDEO_END;
534b843c749SSergey Zigachev 
535b843c749SSergey Zigachev 	dpp1_dscl_set_overscan(dpp, scl_data);
536b843c749SSergey Zigachev 
537b843c749SSergey Zigachev 	dpp1_dscl_set_otg_blank(dpp, scl_data);
538b843c749SSergey Zigachev 
539b843c749SSergey Zigachev 	REG_UPDATE(SCL_MODE, DSCL_MODE, dscl_mode);
540b843c749SSergey Zigachev 
541b843c749SSergey Zigachev 	if (dscl_mode == DSCL_MODE_DSCL_BYPASS)
542b843c749SSergey Zigachev 		return;
543b843c749SSergey Zigachev 
544b843c749SSergey Zigachev 	lb_config =  dpp1_dscl_find_lb_memory_config(dpp, scl_data);
545b843c749SSergey Zigachev 	dpp1_dscl_set_lb(dpp, &scl_data->lb_params, lb_config);
546b843c749SSergey Zigachev 
547b843c749SSergey Zigachev 	if (dscl_mode == DSCL_MODE_SCALING_444_BYPASS)
548b843c749SSergey Zigachev 		return;
549b843c749SSergey Zigachev 
550b843c749SSergey Zigachev 	/* TODO: v_min */
551b843c749SSergey Zigachev 	REG_SET_3(DSCL_AUTOCAL, 0,
552b843c749SSergey Zigachev 		AUTOCAL_MODE, AUTOCAL_MODE_AUTOSCALE,
553b843c749SSergey Zigachev 		AUTOCAL_NUM_PIPE, 0,
554b843c749SSergey Zigachev 		AUTOCAL_PIPE_ID, 0);
555b843c749SSergey Zigachev 
556b843c749SSergey Zigachev 	/* Black offsets */
557b843c749SSergey Zigachev 	if (ycbcr)
558b843c749SSergey Zigachev 		REG_SET_2(SCL_BLACK_OFFSET, 0,
559b843c749SSergey Zigachev 				SCL_BLACK_OFFSET_RGB_Y, BLACK_OFFSET_RGB_Y,
560b843c749SSergey Zigachev 				SCL_BLACK_OFFSET_CBCR, BLACK_OFFSET_CBCR);
561b843c749SSergey Zigachev 	else
562b843c749SSergey Zigachev 
563b843c749SSergey Zigachev 		REG_SET_2(SCL_BLACK_OFFSET, 0,
564b843c749SSergey Zigachev 				SCL_BLACK_OFFSET_RGB_Y, BLACK_OFFSET_RGB_Y,
565b843c749SSergey Zigachev 				SCL_BLACK_OFFSET_CBCR, BLACK_OFFSET_RGB_Y);
566b843c749SSergey Zigachev 
567b843c749SSergey Zigachev 	REG_SET_4(SCL_TAP_CONTROL, 0,
568b843c749SSergey Zigachev 		SCL_V_NUM_TAPS, scl_data->taps.v_taps - 1,
569b843c749SSergey Zigachev 		SCL_H_NUM_TAPS, scl_data->taps.h_taps - 1,
570b843c749SSergey Zigachev 		SCL_V_NUM_TAPS_C, scl_data->taps.v_taps_c - 1,
571b843c749SSergey Zigachev 		SCL_H_NUM_TAPS_C, scl_data->taps.h_taps_c - 1);
572b843c749SSergey Zigachev 
573b843c749SSergey Zigachev 	dpp1_dscl_set_scl_filter(dpp, scl_data, ycbcr);
574b843c749SSergey Zigachev }
575*78973132SSergey Zigachev #endif
576b843c749SSergey Zigachev 
577b843c749SSergey Zigachev 
dpp1_dscl_set_manual_ratio_init(struct dcn10_dpp * dpp,const struct scaler_data * data)578b843c749SSergey Zigachev static void dpp1_dscl_set_manual_ratio_init(
579b843c749SSergey Zigachev 		struct dcn10_dpp *dpp, const struct scaler_data *data)
580b843c749SSergey Zigachev {
581b843c749SSergey Zigachev 	uint32_t init_frac = 0;
582b843c749SSergey Zigachev 	uint32_t init_int = 0;
583b843c749SSergey Zigachev 
584b843c749SSergey Zigachev 	REG_SET(SCL_HORZ_FILTER_SCALE_RATIO, 0,
585b843c749SSergey Zigachev 			SCL_H_SCALE_RATIO, dc_fixpt_u3d19(data->ratios.horz) << 5);
586b843c749SSergey Zigachev 
587b843c749SSergey Zigachev 	REG_SET(SCL_VERT_FILTER_SCALE_RATIO, 0,
588b843c749SSergey Zigachev 			SCL_V_SCALE_RATIO, dc_fixpt_u3d19(data->ratios.vert) << 5);
589b843c749SSergey Zigachev 
590b843c749SSergey Zigachev 	REG_SET(SCL_HORZ_FILTER_SCALE_RATIO_C, 0,
591b843c749SSergey Zigachev 			SCL_H_SCALE_RATIO_C, dc_fixpt_u3d19(data->ratios.horz_c) << 5);
592b843c749SSergey Zigachev 
593b843c749SSergey Zigachev 	REG_SET(SCL_VERT_FILTER_SCALE_RATIO_C, 0,
594b843c749SSergey Zigachev 			SCL_V_SCALE_RATIO_C, dc_fixpt_u3d19(data->ratios.vert_c) << 5);
595b843c749SSergey Zigachev 
596b843c749SSergey Zigachev 	/*
597b843c749SSergey Zigachev 	 * 0.24 format for fraction, first five bits zeroed
598b843c749SSergey Zigachev 	 */
599b843c749SSergey Zigachev 	init_frac = dc_fixpt_u0d19(data->inits.h) << 5;
600b843c749SSergey Zigachev 	init_int = dc_fixpt_floor(data->inits.h);
601b843c749SSergey Zigachev 	REG_SET_2(SCL_HORZ_FILTER_INIT, 0,
602b843c749SSergey Zigachev 		SCL_H_INIT_FRAC, init_frac,
603b843c749SSergey Zigachev 		SCL_H_INIT_INT, init_int);
604b843c749SSergey Zigachev 
605b843c749SSergey Zigachev 	init_frac = dc_fixpt_u0d19(data->inits.h_c) << 5;
606b843c749SSergey Zigachev 	init_int = dc_fixpt_floor(data->inits.h_c);
607b843c749SSergey Zigachev 	REG_SET_2(SCL_HORZ_FILTER_INIT_C, 0,
608b843c749SSergey Zigachev 		SCL_H_INIT_FRAC_C, init_frac,
609b843c749SSergey Zigachev 		SCL_H_INIT_INT_C, init_int);
610b843c749SSergey Zigachev 
611b843c749SSergey Zigachev 	init_frac = dc_fixpt_u0d19(data->inits.v) << 5;
612b843c749SSergey Zigachev 	init_int = dc_fixpt_floor(data->inits.v);
613b843c749SSergey Zigachev 	REG_SET_2(SCL_VERT_FILTER_INIT, 0,
614b843c749SSergey Zigachev 		SCL_V_INIT_FRAC, init_frac,
615b843c749SSergey Zigachev 		SCL_V_INIT_INT, init_int);
616b843c749SSergey Zigachev 
617b843c749SSergey Zigachev 	init_frac = dc_fixpt_u0d19(data->inits.v_bot) << 5;
618b843c749SSergey Zigachev 	init_int = dc_fixpt_floor(data->inits.v_bot);
619b843c749SSergey Zigachev 	REG_SET_2(SCL_VERT_FILTER_INIT_BOT, 0,
620b843c749SSergey Zigachev 		SCL_V_INIT_FRAC_BOT, init_frac,
621b843c749SSergey Zigachev 		SCL_V_INIT_INT_BOT, init_int);
622b843c749SSergey Zigachev 
623b843c749SSergey Zigachev 	init_frac = dc_fixpt_u0d19(data->inits.v_c) << 5;
624b843c749SSergey Zigachev 	init_int = dc_fixpt_floor(data->inits.v_c);
625b843c749SSergey Zigachev 	REG_SET_2(SCL_VERT_FILTER_INIT_C, 0,
626b843c749SSergey Zigachev 		SCL_V_INIT_FRAC_C, init_frac,
627b843c749SSergey Zigachev 		SCL_V_INIT_INT_C, init_int);
628b843c749SSergey Zigachev 
629b843c749SSergey Zigachev 	init_frac = dc_fixpt_u0d19(data->inits.v_c_bot) << 5;
630b843c749SSergey Zigachev 	init_int = dc_fixpt_floor(data->inits.v_c_bot);
631b843c749SSergey Zigachev 	REG_SET_2(SCL_VERT_FILTER_INIT_BOT_C, 0,
632b843c749SSergey Zigachev 		SCL_V_INIT_FRAC_BOT_C, init_frac,
633b843c749SSergey Zigachev 		SCL_V_INIT_INT_BOT_C, init_int);
634b843c749SSergey Zigachev }
635b843c749SSergey Zigachev 
636b843c749SSergey Zigachev 
637b843c749SSergey Zigachev 
dpp1_dscl_set_recout(struct dcn10_dpp * dpp,const struct rect * recout)638b843c749SSergey Zigachev static void dpp1_dscl_set_recout(
639b843c749SSergey Zigachev 			struct dcn10_dpp *dpp, const struct rect *recout)
640b843c749SSergey Zigachev {
641b843c749SSergey Zigachev 	int visual_confirm_on = 0;
642b843c749SSergey Zigachev 	if (dpp->base.ctx->dc->debug.visual_confirm != VISUAL_CONFIRM_DISABLE)
643b843c749SSergey Zigachev 		visual_confirm_on = 1;
644b843c749SSergey Zigachev 
645b843c749SSergey Zigachev 	REG_SET_2(RECOUT_START, 0,
646b843c749SSergey Zigachev 		/* First pixel of RECOUT */
647b843c749SSergey Zigachev 			 RECOUT_START_X, recout->x,
648b843c749SSergey Zigachev 		/* First line of RECOUT */
649b843c749SSergey Zigachev 			 RECOUT_START_Y, recout->y);
650b843c749SSergey Zigachev 
651b843c749SSergey Zigachev 	REG_SET_2(RECOUT_SIZE, 0,
652b843c749SSergey Zigachev 		/* Number of RECOUT horizontal pixels */
653b843c749SSergey Zigachev 			 RECOUT_WIDTH, recout->width,
654b843c749SSergey Zigachev 		/* Number of RECOUT vertical lines */
655b843c749SSergey Zigachev 			 RECOUT_HEIGHT, recout->height
656b843c749SSergey Zigachev 			 - visual_confirm_on * 4 * (dpp->base.inst + 1));
657b843c749SSergey Zigachev }
658b843c749SSergey Zigachev 
659b843c749SSergey Zigachev /* Main function to program scaler and line buffer in manual scaling mode */
dpp1_dscl_set_scaler_manual_scale(struct dpp * dpp_base,const struct scaler_data * scl_data)660b843c749SSergey Zigachev void dpp1_dscl_set_scaler_manual_scale(
661b843c749SSergey Zigachev 	struct dpp *dpp_base,
662b843c749SSergey Zigachev 	const struct scaler_data *scl_data)
663b843c749SSergey Zigachev {
664b843c749SSergey Zigachev 	enum lb_memory_config lb_config;
665b843c749SSergey Zigachev 	struct dcn10_dpp *dpp = TO_DCN10_DPP(dpp_base);
666b843c749SSergey Zigachev 	enum dscl_mode_sel dscl_mode = dpp1_dscl_get_dscl_mode(
667b843c749SSergey Zigachev 			dpp_base, scl_data, dpp_base->ctx->dc->debug.always_scale);
668b843c749SSergey Zigachev 	bool ycbcr = scl_data->format >= PIXEL_FORMAT_VIDEO_BEGIN
669b843c749SSergey Zigachev 				&& scl_data->format <= PIXEL_FORMAT_VIDEO_END;
670b843c749SSergey Zigachev 
671b843c749SSergey Zigachev 	if (memcmp(&dpp->scl_data, scl_data, sizeof(*scl_data)) == 0)
672b843c749SSergey Zigachev 		return;
673b843c749SSergey Zigachev 
674b843c749SSergey Zigachev 	PERF_TRACE();
675b843c749SSergey Zigachev 
676b843c749SSergey Zigachev 	dpp->scl_data = *scl_data;
677b843c749SSergey Zigachev 
678b843c749SSergey Zigachev 	/* Autocal off */
679b843c749SSergey Zigachev 	REG_SET_3(DSCL_AUTOCAL, 0,
680b843c749SSergey Zigachev 		AUTOCAL_MODE, AUTOCAL_MODE_OFF,
681b843c749SSergey Zigachev 		AUTOCAL_NUM_PIPE, 0,
682b843c749SSergey Zigachev 		AUTOCAL_PIPE_ID, 0);
683b843c749SSergey Zigachev 
684b843c749SSergey Zigachev 	/* Recout */
685b843c749SSergey Zigachev 	dpp1_dscl_set_recout(dpp, &scl_data->recout);
686b843c749SSergey Zigachev 
687b843c749SSergey Zigachev 	/* MPC Size */
688b843c749SSergey Zigachev 	REG_SET_2(MPC_SIZE, 0,
689b843c749SSergey Zigachev 		/* Number of horizontal pixels of MPC */
690b843c749SSergey Zigachev 			 MPC_WIDTH, scl_data->h_active,
691b843c749SSergey Zigachev 		/* Number of vertical lines of MPC */
692b843c749SSergey Zigachev 			 MPC_HEIGHT, scl_data->v_active);
693b843c749SSergey Zigachev 
694b843c749SSergey Zigachev 	/* SCL mode */
695b843c749SSergey Zigachev 	REG_UPDATE(SCL_MODE, DSCL_MODE, dscl_mode);
696b843c749SSergey Zigachev 
697b843c749SSergey Zigachev 	if (dscl_mode == DSCL_MODE_DSCL_BYPASS)
698b843c749SSergey Zigachev 		return;
699b843c749SSergey Zigachev 
700b843c749SSergey Zigachev 	/* LB */
701b843c749SSergey Zigachev 	lb_config =  dpp1_dscl_find_lb_memory_config(dpp, scl_data);
702b843c749SSergey Zigachev 	dpp1_dscl_set_lb(dpp, &scl_data->lb_params, lb_config);
703b843c749SSergey Zigachev 
704b843c749SSergey Zigachev 	if (dscl_mode == DSCL_MODE_SCALING_444_BYPASS)
705b843c749SSergey Zigachev 		return;
706b843c749SSergey Zigachev 
707b843c749SSergey Zigachev 	/* Black offsets */
708b843c749SSergey Zigachev 	if (ycbcr)
709b843c749SSergey Zigachev 		REG_SET_2(SCL_BLACK_OFFSET, 0,
710b843c749SSergey Zigachev 				SCL_BLACK_OFFSET_RGB_Y, BLACK_OFFSET_RGB_Y,
711b843c749SSergey Zigachev 				SCL_BLACK_OFFSET_CBCR, BLACK_OFFSET_CBCR);
712b843c749SSergey Zigachev 	else
713b843c749SSergey Zigachev 
714b843c749SSergey Zigachev 		REG_SET_2(SCL_BLACK_OFFSET, 0,
715b843c749SSergey Zigachev 				SCL_BLACK_OFFSET_RGB_Y, BLACK_OFFSET_RGB_Y,
716b843c749SSergey Zigachev 				SCL_BLACK_OFFSET_CBCR, BLACK_OFFSET_RGB_Y);
717b843c749SSergey Zigachev 
718b843c749SSergey Zigachev 	/* Manually calculate scale ratio and init values */
719b843c749SSergey Zigachev 	dpp1_dscl_set_manual_ratio_init(dpp, scl_data);
720b843c749SSergey Zigachev 
721b843c749SSergey Zigachev 	/* HTaps/VTaps */
722b843c749SSergey Zigachev 	REG_SET_4(SCL_TAP_CONTROL, 0,
723b843c749SSergey Zigachev 		SCL_V_NUM_TAPS, scl_data->taps.v_taps - 1,
724b843c749SSergey Zigachev 		SCL_H_NUM_TAPS, scl_data->taps.h_taps - 1,
725b843c749SSergey Zigachev 		SCL_V_NUM_TAPS_C, scl_data->taps.v_taps_c - 1,
726b843c749SSergey Zigachev 		SCL_H_NUM_TAPS_C, scl_data->taps.h_taps_c - 1);
727b843c749SSergey Zigachev 
728b843c749SSergey Zigachev 	dpp1_dscl_set_scl_filter(dpp, scl_data, ycbcr);
729b843c749SSergey Zigachev 	PERF_TRACE();
730b843c749SSergey Zigachev }
731