xref: /linux/drivers/gpu/drm/amd/display/dc/opp/dcn20/dcn20_opp.c (revision f60881ca126cf825b89b4118e93dbd82ea9bcf33)
1eb7a74a3SHarry Wentland /*
2eb7a74a3SHarry Wentland  * Copyright 2012-15 Advanced Micro Devices, Inc.
3eb7a74a3SHarry Wentland  *
4eb7a74a3SHarry Wentland  * Permission is hereby granted, free of charge, to any person obtaining a
5eb7a74a3SHarry Wentland  * copy of this software and associated documentation files (the "Software"),
6eb7a74a3SHarry Wentland  * to deal in the Software without restriction, including without limitation
7eb7a74a3SHarry Wentland  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8eb7a74a3SHarry Wentland  * and/or sell copies of the Software, and to permit persons to whom the
9eb7a74a3SHarry Wentland  * Software is furnished to do so, subject to the following conditions:
10eb7a74a3SHarry Wentland  *
11eb7a74a3SHarry Wentland  * The above copyright notice and this permission notice shall be included in
12eb7a74a3SHarry Wentland  * all copies or substantial portions of the Software.
13eb7a74a3SHarry Wentland  *
14eb7a74a3SHarry Wentland  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15eb7a74a3SHarry Wentland  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16eb7a74a3SHarry Wentland  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
17eb7a74a3SHarry Wentland  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18eb7a74a3SHarry Wentland  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19eb7a74a3SHarry Wentland  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20eb7a74a3SHarry Wentland  * OTHER DEALINGS IN THE SOFTWARE.
21eb7a74a3SHarry Wentland  *
22eb7a74a3SHarry Wentland  * Authors: AMD
23eb7a74a3SHarry Wentland  *
24eb7a74a3SHarry Wentland  */
25eb7a74a3SHarry Wentland 
26*f9d48a88SWenjing Liu #include "core_types.h"
27eb7a74a3SHarry Wentland #include "dm_services.h"
28eb7a74a3SHarry Wentland #include "dcn20_opp.h"
29eb7a74a3SHarry Wentland #include "reg_helper.h"
30eb7a74a3SHarry Wentland 
31eb7a74a3SHarry Wentland #define REG(reg) \
32eb7a74a3SHarry Wentland 	(oppn20->regs->reg)
33eb7a74a3SHarry Wentland 
34eb7a74a3SHarry Wentland #undef FN
35eb7a74a3SHarry Wentland #define FN(reg_name, field_name) \
36eb7a74a3SHarry Wentland 	oppn20->opp_shift->field_name, oppn20->opp_mask->field_name
37eb7a74a3SHarry Wentland 
38eb7a74a3SHarry Wentland #define CTX \
39eb7a74a3SHarry Wentland 	oppn20->base.ctx
40eb7a74a3SHarry Wentland 
41eb7a74a3SHarry Wentland 
opp2_set_disp_pattern_generator(struct output_pixel_processor * opp,enum controller_dp_test_pattern test_pattern,enum controller_dp_color_space color_space,enum dc_color_depth color_depth,const struct tg_color * solid_color,int width,int height,int offset)42eb7a74a3SHarry Wentland void opp2_set_disp_pattern_generator(
43eb7a74a3SHarry Wentland 		struct output_pixel_processor *opp,
44eb7a74a3SHarry Wentland 		enum controller_dp_test_pattern test_pattern,
452057b7e1SWenjing Liu 		enum controller_dp_color_space color_space,
46eb7a74a3SHarry Wentland 		enum dc_color_depth color_depth,
47eb7a74a3SHarry Wentland 		const struct tg_color *solid_color,
48eb7a74a3SHarry Wentland 		int width,
4910b4e64eSWenjing Liu 		int height,
5010b4e64eSWenjing Liu 		int offset)
51eb7a74a3SHarry Wentland {
52eb7a74a3SHarry Wentland 	struct dcn20_opp *oppn20 = TO_DCN20_OPP(opp);
53eb7a74a3SHarry Wentland 	enum test_pattern_color_format bit_depth;
54eb7a74a3SHarry Wentland 	enum test_pattern_dyn_range dyn_range;
55eb7a74a3SHarry Wentland 	enum test_pattern_mode mode;
56eb7a74a3SHarry Wentland 
57eb7a74a3SHarry Wentland 	/* color ramp generator mixes 16-bits color */
58eb7a74a3SHarry Wentland 	uint32_t src_bpc = 16;
59eb7a74a3SHarry Wentland 	/* requested bpc */
60eb7a74a3SHarry Wentland 	uint32_t dst_bpc;
61eb7a74a3SHarry Wentland 	uint32_t index;
62eb7a74a3SHarry Wentland 	/* RGB values of the color bars.
63eb7a74a3SHarry Wentland 	 * Produce two RGB colors: RGB0 - white (all Fs)
64eb7a74a3SHarry Wentland 	 * and RGB1 - black (all 0s)
65eb7a74a3SHarry Wentland 	 * (three RGB components for two colors)
66eb7a74a3SHarry Wentland 	 */
67eb7a74a3SHarry Wentland 	uint16_t src_color[6] = {0xFFFF, 0xFFFF, 0xFFFF, 0x0000,
68eb7a74a3SHarry Wentland 						0x0000, 0x0000};
69eb7a74a3SHarry Wentland 	/* dest color (converted to the specified color format) */
70eb7a74a3SHarry Wentland 	uint16_t dst_color[6];
71eb7a74a3SHarry Wentland 	uint32_t inc_base;
72eb7a74a3SHarry Wentland 
73eb7a74a3SHarry Wentland 	/* translate to bit depth */
74eb7a74a3SHarry Wentland 	switch (color_depth) {
75eb7a74a3SHarry Wentland 	case COLOR_DEPTH_666:
76eb7a74a3SHarry Wentland 		bit_depth = TEST_PATTERN_COLOR_FORMAT_BPC_6;
77eb7a74a3SHarry Wentland 	break;
78eb7a74a3SHarry Wentland 	case COLOR_DEPTH_888:
79eb7a74a3SHarry Wentland 		bit_depth = TEST_PATTERN_COLOR_FORMAT_BPC_8;
80eb7a74a3SHarry Wentland 	break;
81eb7a74a3SHarry Wentland 	case COLOR_DEPTH_101010:
82eb7a74a3SHarry Wentland 		bit_depth = TEST_PATTERN_COLOR_FORMAT_BPC_10;
83eb7a74a3SHarry Wentland 	break;
84eb7a74a3SHarry Wentland 	case COLOR_DEPTH_121212:
85eb7a74a3SHarry Wentland 		bit_depth = TEST_PATTERN_COLOR_FORMAT_BPC_12;
86eb7a74a3SHarry Wentland 	break;
87eb7a74a3SHarry Wentland 	default:
88eb7a74a3SHarry Wentland 		bit_depth = TEST_PATTERN_COLOR_FORMAT_BPC_8;
89eb7a74a3SHarry Wentland 	break;
90eb7a74a3SHarry Wentland 	}
91eb7a74a3SHarry Wentland 
92eb7a74a3SHarry Wentland 	/* set DPG dimentions */
93eb7a74a3SHarry Wentland 	REG_SET_2(DPG_DIMENSIONS, 0,
94eb7a74a3SHarry Wentland 		DPG_ACTIVE_WIDTH, width,
95eb7a74a3SHarry Wentland 		DPG_ACTIVE_HEIGHT, height);
96eb7a74a3SHarry Wentland 
9710b4e64eSWenjing Liu 	/* set DPG offset */
9810b4e64eSWenjing Liu 	REG_SET_2(DPG_OFFSET_SEGMENT, 0,
9910b4e64eSWenjing Liu 		DPG_X_OFFSET, offset,
10010b4e64eSWenjing Liu 		DPG_SEGMENT_WIDTH, 0);
10110b4e64eSWenjing Liu 
102eb7a74a3SHarry Wentland 	switch (test_pattern) {
103eb7a74a3SHarry Wentland 	case CONTROLLER_DP_TEST_PATTERN_COLORSQUARES:
104eb7a74a3SHarry Wentland 	case CONTROLLER_DP_TEST_PATTERN_COLORSQUARES_CEA:
105eb7a74a3SHarry Wentland 	{
106eb7a74a3SHarry Wentland 		dyn_range = (test_pattern ==
107eb7a74a3SHarry Wentland 				CONTROLLER_DP_TEST_PATTERN_COLORSQUARES_CEA ?
108eb7a74a3SHarry Wentland 				TEST_PATTERN_DYN_RANGE_CEA :
109eb7a74a3SHarry Wentland 				TEST_PATTERN_DYN_RANGE_VESA);
110eb7a74a3SHarry Wentland 
1112057b7e1SWenjing Liu 		switch (color_space) {
1122057b7e1SWenjing Liu 		case CONTROLLER_DP_COLOR_SPACE_YCBCR601:
1132057b7e1SWenjing Liu 			mode = TEST_PATTERN_MODE_COLORSQUARES_YCBCR601;
1142057b7e1SWenjing Liu 		break;
1152057b7e1SWenjing Liu 		case CONTROLLER_DP_COLOR_SPACE_YCBCR709:
1162057b7e1SWenjing Liu 			mode = TEST_PATTERN_MODE_COLORSQUARES_YCBCR709;
1172057b7e1SWenjing Liu 		break;
1182057b7e1SWenjing Liu 		case CONTROLLER_DP_COLOR_SPACE_RGB:
1192057b7e1SWenjing Liu 		default:
1202057b7e1SWenjing Liu 			mode = TEST_PATTERN_MODE_COLORSQUARES_RGB;
1212057b7e1SWenjing Liu 		break;
1222057b7e1SWenjing Liu 		}
1232057b7e1SWenjing Liu 
124eb7a74a3SHarry Wentland 		REG_UPDATE_6(DPG_CONTROL,
125eb7a74a3SHarry Wentland 			DPG_EN, 1,
1262057b7e1SWenjing Liu 			DPG_MODE, mode,
127eb7a74a3SHarry Wentland 			DPG_DYNAMIC_RANGE, dyn_range,
128eb7a74a3SHarry Wentland 			DPG_BIT_DEPTH, bit_depth,
129eb7a74a3SHarry Wentland 			DPG_VRES, 6,
130eb7a74a3SHarry Wentland 			DPG_HRES, 6);
131eb7a74a3SHarry Wentland 	}
132eb7a74a3SHarry Wentland 	break;
133eb7a74a3SHarry Wentland 
134eb7a74a3SHarry Wentland 	case CONTROLLER_DP_TEST_PATTERN_VERTICALBARS:
135eb7a74a3SHarry Wentland 	case CONTROLLER_DP_TEST_PATTERN_HORIZONTALBARS:
136eb7a74a3SHarry Wentland 	{
137eb7a74a3SHarry Wentland 		mode = (test_pattern ==
138eb7a74a3SHarry Wentland 			CONTROLLER_DP_TEST_PATTERN_VERTICALBARS ?
139eb7a74a3SHarry Wentland 			TEST_PATTERN_MODE_VERTICALBARS :
140eb7a74a3SHarry Wentland 			TEST_PATTERN_MODE_HORIZONTALBARS);
141eb7a74a3SHarry Wentland 
142eb7a74a3SHarry Wentland 		switch (bit_depth) {
143eb7a74a3SHarry Wentland 		case TEST_PATTERN_COLOR_FORMAT_BPC_6:
144eb7a74a3SHarry Wentland 			dst_bpc = 6;
145eb7a74a3SHarry Wentland 		break;
146eb7a74a3SHarry Wentland 		case TEST_PATTERN_COLOR_FORMAT_BPC_8:
147eb7a74a3SHarry Wentland 			dst_bpc = 8;
148eb7a74a3SHarry Wentland 		break;
149eb7a74a3SHarry Wentland 		case TEST_PATTERN_COLOR_FORMAT_BPC_10:
150eb7a74a3SHarry Wentland 			dst_bpc = 10;
151eb7a74a3SHarry Wentland 		break;
152eb7a74a3SHarry Wentland 		default:
153eb7a74a3SHarry Wentland 			dst_bpc = 8;
154eb7a74a3SHarry Wentland 		break;
155eb7a74a3SHarry Wentland 		}
156eb7a74a3SHarry Wentland 
157eb7a74a3SHarry Wentland 		/* adjust color to the required colorFormat */
158eb7a74a3SHarry Wentland 		for (index = 0; index < 6; index++) {
159eb7a74a3SHarry Wentland 			/* dst = 2^dstBpc * src / 2^srcBpc = src >>
160eb7a74a3SHarry Wentland 			 * (srcBpc - dstBpc);
161eb7a74a3SHarry Wentland 			 */
162eb7a74a3SHarry Wentland 			dst_color[index] =
163eb7a74a3SHarry Wentland 				src_color[index] >> (src_bpc - dst_bpc);
164eb7a74a3SHarry Wentland 		/* DPG_COLOUR registers are 16-bit MSB aligned value with bits 3:0 hardwired to ZERO.
165eb7a74a3SHarry Wentland 		 * XXXXXXXXXX000000 for 10 bit,
166eb7a74a3SHarry Wentland 		 * XXXXXXXX00000000 for 8 bit,
167eb7a74a3SHarry Wentland 		 * XXXXXX0000000000 for 6 bits
168eb7a74a3SHarry Wentland 		 */
169eb7a74a3SHarry Wentland 			dst_color[index] <<= (16 - dst_bpc);
170eb7a74a3SHarry Wentland 		}
171eb7a74a3SHarry Wentland 
172eb7a74a3SHarry Wentland 		REG_SET_2(DPG_COLOUR_R_CR, 0,
173eb7a74a3SHarry Wentland 				DPG_COLOUR1_R_CR, dst_color[0],
174eb7a74a3SHarry Wentland 				DPG_COLOUR0_R_CR, dst_color[3]);
175eb7a74a3SHarry Wentland 		REG_SET_2(DPG_COLOUR_G_Y, 0,
176eb7a74a3SHarry Wentland 				DPG_COLOUR1_G_Y, dst_color[1],
177eb7a74a3SHarry Wentland 				DPG_COLOUR0_G_Y, dst_color[4]);
178eb7a74a3SHarry Wentland 		REG_SET_2(DPG_COLOUR_B_CB, 0,
179eb7a74a3SHarry Wentland 				DPG_COLOUR1_B_CB, dst_color[2],
180eb7a74a3SHarry Wentland 				DPG_COLOUR0_B_CB, dst_color[5]);
181eb7a74a3SHarry Wentland 
182eb7a74a3SHarry Wentland 		/* enable test pattern */
183eb7a74a3SHarry Wentland 		REG_UPDATE_6(DPG_CONTROL,
184eb7a74a3SHarry Wentland 			DPG_EN, 1,
185eb7a74a3SHarry Wentland 			DPG_MODE, mode,
186eb7a74a3SHarry Wentland 			DPG_DYNAMIC_RANGE, 0,
187eb7a74a3SHarry Wentland 			DPG_BIT_DEPTH, bit_depth,
188eb7a74a3SHarry Wentland 			DPG_VRES, 0,
189eb7a74a3SHarry Wentland 			DPG_HRES, 0);
190eb7a74a3SHarry Wentland 	}
191eb7a74a3SHarry Wentland 	break;
192eb7a74a3SHarry Wentland 
193eb7a74a3SHarry Wentland 	case CONTROLLER_DP_TEST_PATTERN_COLORRAMP:
194eb7a74a3SHarry Wentland 	{
195eb7a74a3SHarry Wentland 		mode = (bit_depth ==
196eb7a74a3SHarry Wentland 			TEST_PATTERN_COLOR_FORMAT_BPC_10 ?
197eb7a74a3SHarry Wentland 			TEST_PATTERN_MODE_DUALRAMP_RGB :
198eb7a74a3SHarry Wentland 			TEST_PATTERN_MODE_SINGLERAMP_RGB);
199eb7a74a3SHarry Wentland 
200eb7a74a3SHarry Wentland 		switch (bit_depth) {
201eb7a74a3SHarry Wentland 		case TEST_PATTERN_COLOR_FORMAT_BPC_6:
202eb7a74a3SHarry Wentland 			dst_bpc = 6;
203eb7a74a3SHarry Wentland 		break;
204eb7a74a3SHarry Wentland 		case TEST_PATTERN_COLOR_FORMAT_BPC_8:
205eb7a74a3SHarry Wentland 			dst_bpc = 8;
206eb7a74a3SHarry Wentland 		break;
207eb7a74a3SHarry Wentland 		case TEST_PATTERN_COLOR_FORMAT_BPC_10:
208eb7a74a3SHarry Wentland 			dst_bpc = 10;
209eb7a74a3SHarry Wentland 		break;
210eb7a74a3SHarry Wentland 		default:
211eb7a74a3SHarry Wentland 			dst_bpc = 8;
212eb7a74a3SHarry Wentland 		break;
213eb7a74a3SHarry Wentland 		}
214eb7a74a3SHarry Wentland 
215eb7a74a3SHarry Wentland 		/* increment for the first ramp for one color gradation
216eb7a74a3SHarry Wentland 		 * 1 gradation for 6-bit color is 2^10
217eb7a74a3SHarry Wentland 		 * gradations in 16-bit color
218eb7a74a3SHarry Wentland 		 */
219eb7a74a3SHarry Wentland 		inc_base = (src_bpc - dst_bpc);
220eb7a74a3SHarry Wentland 
221eb7a74a3SHarry Wentland 		switch (bit_depth) {
222eb7a74a3SHarry Wentland 		case TEST_PATTERN_COLOR_FORMAT_BPC_6:
223eb7a74a3SHarry Wentland 		{
224eb7a74a3SHarry Wentland 			REG_SET_3(DPG_RAMP_CONTROL, 0,
225eb7a74a3SHarry Wentland 				DPG_RAMP0_OFFSET, 0,
226eb7a74a3SHarry Wentland 				DPG_INC0, inc_base,
227eb7a74a3SHarry Wentland 				DPG_INC1, 0);
228eb7a74a3SHarry Wentland 			REG_UPDATE_2(DPG_CONTROL,
229eb7a74a3SHarry Wentland 				DPG_VRES, 6,
230eb7a74a3SHarry Wentland 				DPG_HRES, 6);
231eb7a74a3SHarry Wentland 		}
232eb7a74a3SHarry Wentland 		break;
233eb7a74a3SHarry Wentland 		case TEST_PATTERN_COLOR_FORMAT_BPC_8:
234eb7a74a3SHarry Wentland 		{
235eb7a74a3SHarry Wentland 			REG_SET_3(DPG_RAMP_CONTROL, 0,
236eb7a74a3SHarry Wentland 				DPG_RAMP0_OFFSET, 0,
237eb7a74a3SHarry Wentland 				DPG_INC0, inc_base,
238eb7a74a3SHarry Wentland 				DPG_INC1, 0);
239eb7a74a3SHarry Wentland 			REG_UPDATE_2(DPG_CONTROL,
240eb7a74a3SHarry Wentland 				DPG_VRES, 6,
241eb7a74a3SHarry Wentland 				DPG_HRES, 8);
242eb7a74a3SHarry Wentland 		}
243eb7a74a3SHarry Wentland 		break;
244eb7a74a3SHarry Wentland 		case TEST_PATTERN_COLOR_FORMAT_BPC_10:
245eb7a74a3SHarry Wentland 		{
246eb7a74a3SHarry Wentland 			REG_SET_3(DPG_RAMP_CONTROL, 0,
247eb7a74a3SHarry Wentland 				DPG_RAMP0_OFFSET, 384 << 6,
248eb7a74a3SHarry Wentland 				DPG_INC0, inc_base,
249eb7a74a3SHarry Wentland 				DPG_INC1, inc_base + 2);
250eb7a74a3SHarry Wentland 			REG_UPDATE_2(DPG_CONTROL,
251eb7a74a3SHarry Wentland 				DPG_VRES, 5,
252eb7a74a3SHarry Wentland 				DPG_HRES, 8);
253eb7a74a3SHarry Wentland 		}
254eb7a74a3SHarry Wentland 		break;
255eb7a74a3SHarry Wentland 		default:
256eb7a74a3SHarry Wentland 		break;
257eb7a74a3SHarry Wentland 		}
258eb7a74a3SHarry Wentland 
259eb7a74a3SHarry Wentland 		/* enable test pattern */
260eb7a74a3SHarry Wentland 		REG_UPDATE_4(DPG_CONTROL,
261eb7a74a3SHarry Wentland 			DPG_EN, 1,
262eb7a74a3SHarry Wentland 			DPG_MODE, mode,
263eb7a74a3SHarry Wentland 			DPG_DYNAMIC_RANGE, 0,
264eb7a74a3SHarry Wentland 			DPG_BIT_DEPTH, bit_depth);
265eb7a74a3SHarry Wentland 	}
266eb7a74a3SHarry Wentland 	break;
267eb7a74a3SHarry Wentland 	case CONTROLLER_DP_TEST_PATTERN_VIDEOMODE:
268eb7a74a3SHarry Wentland 	{
269eb7a74a3SHarry Wentland 		REG_WRITE(DPG_CONTROL, 0);
270eb7a74a3SHarry Wentland 		REG_WRITE(DPG_COLOUR_R_CR, 0);
271eb7a74a3SHarry Wentland 		REG_WRITE(DPG_COLOUR_G_Y, 0);
272eb7a74a3SHarry Wentland 		REG_WRITE(DPG_COLOUR_B_CB, 0);
273eb7a74a3SHarry Wentland 		REG_WRITE(DPG_RAMP_CONTROL, 0);
274eb7a74a3SHarry Wentland 	}
275eb7a74a3SHarry Wentland 	break;
276eb7a74a3SHarry Wentland 	case CONTROLLER_DP_TEST_PATTERN_SOLID_COLOR:
277eb7a74a3SHarry Wentland 	{
278eb7a74a3SHarry Wentland 		opp2_dpg_set_blank_color(opp, solid_color);
279eb7a74a3SHarry Wentland 		REG_UPDATE_2(DPG_CONTROL,
280eb7a74a3SHarry Wentland 				DPG_EN, 1,
281eb7a74a3SHarry Wentland 				DPG_MODE, TEST_PATTERN_MODE_HORIZONTALBARS);
282eb7a74a3SHarry Wentland 
283eb7a74a3SHarry Wentland 		REG_SET_2(DPG_DIMENSIONS, 0,
284eb7a74a3SHarry Wentland 				DPG_ACTIVE_WIDTH, width,
285eb7a74a3SHarry Wentland 				DPG_ACTIVE_HEIGHT, height);
286eb7a74a3SHarry Wentland 	}
287eb7a74a3SHarry Wentland 	break;
288eb7a74a3SHarry Wentland 	default:
289eb7a74a3SHarry Wentland 		break;
290eb7a74a3SHarry Wentland 
291eb7a74a3SHarry Wentland 	}
292eb7a74a3SHarry Wentland }
293eb7a74a3SHarry Wentland 
opp2_program_dpg_dimensions(struct output_pixel_processor * opp,int width,int height)294a47cc3abSTaimur Hassan void opp2_program_dpg_dimensions(
295a47cc3abSTaimur Hassan 		struct output_pixel_processor *opp,
296a47cc3abSTaimur Hassan 		int width, int height)
297a47cc3abSTaimur Hassan {
298a47cc3abSTaimur Hassan 	struct dcn20_opp *oppn20 = TO_DCN20_OPP(opp);
299a47cc3abSTaimur Hassan 
300a47cc3abSTaimur Hassan 	REG_SET_2(DPG_DIMENSIONS, 0,
301a47cc3abSTaimur Hassan 		DPG_ACTIVE_WIDTH, width,
302a47cc3abSTaimur Hassan 		DPG_ACTIVE_HEIGHT, height);
303a47cc3abSTaimur Hassan }
304a47cc3abSTaimur Hassan 
opp2_dpg_set_blank_color(struct output_pixel_processor * opp,const struct tg_color * color)305eb7a74a3SHarry Wentland void opp2_dpg_set_blank_color(
306eb7a74a3SHarry Wentland 		struct output_pixel_processor *opp,
307eb7a74a3SHarry Wentland 		const struct tg_color *color)
308eb7a74a3SHarry Wentland {
309eb7a74a3SHarry Wentland 	struct dcn20_opp *oppn20 = TO_DCN20_OPP(opp);
310eb7a74a3SHarry Wentland 
311eb7a74a3SHarry Wentland 	/* 16-bit MSB aligned value. Bits 3:0 of this field are hardwired to ZERO */
312eb7a74a3SHarry Wentland 	ASSERT(color);
313eb7a74a3SHarry Wentland 	REG_SET_2(DPG_COLOUR_B_CB, 0,
314eb7a74a3SHarry Wentland 			DPG_COLOUR1_B_CB, color->color_b_cb << 6,
315eb7a74a3SHarry Wentland 			DPG_COLOUR0_B_CB, color->color_b_cb << 6);
316eb7a74a3SHarry Wentland 	REG_SET_2(DPG_COLOUR_G_Y, 0,
317eb7a74a3SHarry Wentland 			DPG_COLOUR1_G_Y, color->color_g_y << 6,
318eb7a74a3SHarry Wentland 			DPG_COLOUR0_G_Y, color->color_g_y << 6);
319eb7a74a3SHarry Wentland 	REG_SET_2(DPG_COLOUR_R_CR, 0,
320eb7a74a3SHarry Wentland 			DPG_COLOUR1_R_CR, color->color_r_cr << 6,
321eb7a74a3SHarry Wentland 			DPG_COLOUR0_R_CR, color->color_r_cr << 6);
322eb7a74a3SHarry Wentland }
323eb7a74a3SHarry Wentland 
opp2_dpg_is_blanked(struct output_pixel_processor * opp)324eb7a74a3SHarry Wentland bool opp2_dpg_is_blanked(struct output_pixel_processor *opp)
325eb7a74a3SHarry Wentland {
326eb7a74a3SHarry Wentland 	struct dcn20_opp *oppn20 = TO_DCN20_OPP(opp);
327eb7a74a3SHarry Wentland 	uint32_t dpg_en, dpg_mode;
328eb7a74a3SHarry Wentland 	uint32_t double_buffer_pending;
329eb7a74a3SHarry Wentland 
330eb7a74a3SHarry Wentland 	REG_GET_2(DPG_CONTROL,
331eb7a74a3SHarry Wentland 			DPG_EN, &dpg_en,
332eb7a74a3SHarry Wentland 			DPG_MODE, &dpg_mode);
333eb7a74a3SHarry Wentland 
334eb7a74a3SHarry Wentland 	REG_GET(DPG_STATUS,
335eb7a74a3SHarry Wentland 			DPG_DOUBLE_BUFFER_PENDING, &double_buffer_pending);
336eb7a74a3SHarry Wentland 
337eb7a74a3SHarry Wentland 	return (dpg_en == 1) &&
338eb7a74a3SHarry Wentland 		(double_buffer_pending == 0);
339eb7a74a3SHarry Wentland }
340eb7a74a3SHarry Wentland 
opp2_dpg_is_pending(struct output_pixel_processor * opp)3412d7f3d1aSWenjing Liu bool opp2_dpg_is_pending(struct output_pixel_processor *opp)
3422d7f3d1aSWenjing Liu {
3432d7f3d1aSWenjing Liu 	struct dcn20_opp *oppn20 = TO_DCN20_OPP(opp);
3442d7f3d1aSWenjing Liu 	uint32_t double_buffer_pending;
3452d7f3d1aSWenjing Liu 	uint32_t dpg_en;
3462d7f3d1aSWenjing Liu 
3472d7f3d1aSWenjing Liu 	REG_GET(DPG_CONTROL, DPG_EN, &dpg_en);
3482d7f3d1aSWenjing Liu 
3492d7f3d1aSWenjing Liu 	REG_GET(DPG_STATUS, DPG_DOUBLE_BUFFER_PENDING, &double_buffer_pending);
3502d7f3d1aSWenjing Liu 
3512d7f3d1aSWenjing Liu 	return (dpg_en == 1 && double_buffer_pending == 1);
3522d7f3d1aSWenjing Liu }
3532d7f3d1aSWenjing Liu 
opp2_program_left_edge_extra_pixel(struct output_pixel_processor * opp,enum dc_pixel_encoding pixel_encoding,bool is_primary)354eb7a74a3SHarry Wentland void opp2_program_left_edge_extra_pixel(
355eb7a74a3SHarry Wentland 		struct output_pixel_processor *opp,
356*f9d48a88SWenjing Liu 		enum dc_pixel_encoding pixel_encoding,
357*f9d48a88SWenjing Liu 		bool is_primary)
358eb7a74a3SHarry Wentland {
359eb7a74a3SHarry Wentland 	struct dcn20_opp *oppn20 = TO_DCN20_OPP(opp);
360*f9d48a88SWenjing Liu 	uint32_t count = opp2_get_left_edge_extra_pixel_count(opp, pixel_encoding, is_primary);
361eb7a74a3SHarry Wentland 
362*f9d48a88SWenjing Liu 	/*
363*f9d48a88SWenjing Liu 	 * Specifies the number of extra left edge pixels that are supplied to
364eb7a74a3SHarry Wentland 	 * the 422 horizontal chroma sub-sample filter.
365*f9d48a88SWenjing Liu 	 */
366eb7a74a3SHarry Wentland 	REG_UPDATE(FMT_422_CONTROL, FMT_LEFT_EDGE_EXTRA_PIXEL_COUNT, count);
367eb7a74a3SHarry Wentland }
368eb7a74a3SHarry Wentland 
opp2_get_left_edge_extra_pixel_count(struct output_pixel_processor * opp,enum dc_pixel_encoding pixel_encoding,bool is_primary)369*f9d48a88SWenjing Liu uint32_t opp2_get_left_edge_extra_pixel_count(struct output_pixel_processor *opp,
370*f9d48a88SWenjing Liu 		enum dc_pixel_encoding pixel_encoding, bool is_primary)
371*f9d48a88SWenjing Liu {
372*f9d48a88SWenjing Liu 	if ((pixel_encoding == PIXEL_ENCODING_YCBCR422 || pixel_encoding == PIXEL_ENCODING_YCBCR420) &&
373*f9d48a88SWenjing Liu 			!opp->ctx->dc->debug.force_chroma_subsampling_1tap &&
374*f9d48a88SWenjing Liu 			!is_primary)
375*f9d48a88SWenjing Liu 		return 1;
376*f9d48a88SWenjing Liu 	else
377*f9d48a88SWenjing Liu 		return 0;
378*f9d48a88SWenjing Liu }
379*f9d48a88SWenjing Liu 
380eb7a74a3SHarry Wentland /*****************************************/
381eb7a74a3SHarry Wentland /* Constructor, Destructor               */
382eb7a74a3SHarry Wentland /*****************************************/
383eb7a74a3SHarry Wentland 
384eb7a74a3SHarry Wentland static struct opp_funcs dcn20_opp_funcs = {
385eb7a74a3SHarry Wentland 		.opp_set_dyn_expansion = opp1_set_dyn_expansion,
386eb7a74a3SHarry Wentland 		.opp_program_fmt = opp1_program_fmt,
387eb7a74a3SHarry Wentland 		.opp_program_bit_depth_reduction = opp1_program_bit_depth_reduction,
388eb7a74a3SHarry Wentland 		.opp_program_stereo = opp1_program_stereo,
389eb7a74a3SHarry Wentland 		.opp_pipe_clock_control = opp1_pipe_clock_control,
390eb7a74a3SHarry Wentland 		.opp_set_disp_pattern_generator = opp2_set_disp_pattern_generator,
391a47cc3abSTaimur Hassan 		.opp_program_dpg_dimensions = opp2_program_dpg_dimensions,
392eb7a74a3SHarry Wentland 		.dpg_is_blanked = opp2_dpg_is_blanked,
3932d7f3d1aSWenjing Liu 		.dpg_is_pending = opp2_dpg_is_pending,
394eb7a74a3SHarry Wentland 		.opp_dpg_set_blank_color = opp2_dpg_set_blank_color,
395eb7a74a3SHarry Wentland 		.opp_destroy = opp1_destroy,
396eb7a74a3SHarry Wentland 		.opp_program_left_edge_extra_pixel = opp2_program_left_edge_extra_pixel,
397*f9d48a88SWenjing Liu 		.opp_get_left_edge_extra_pixel_count = opp2_get_left_edge_extra_pixel_count,
398eb7a74a3SHarry Wentland };
399eb7a74a3SHarry Wentland 
dcn20_opp_construct(struct dcn20_opp * oppn20,struct dc_context * ctx,uint32_t inst,const struct dcn20_opp_registers * regs,const struct dcn20_opp_shift * opp_shift,const struct dcn20_opp_mask * opp_mask)400eb7a74a3SHarry Wentland void dcn20_opp_construct(struct dcn20_opp *oppn20,
401eb7a74a3SHarry Wentland 	struct dc_context *ctx,
402eb7a74a3SHarry Wentland 	uint32_t inst,
403eb7a74a3SHarry Wentland 	const struct dcn20_opp_registers *regs,
404eb7a74a3SHarry Wentland 	const struct dcn20_opp_shift *opp_shift,
405eb7a74a3SHarry Wentland 	const struct dcn20_opp_mask *opp_mask)
406eb7a74a3SHarry Wentland {
407eb7a74a3SHarry Wentland 	oppn20->base.ctx = ctx;
408eb7a74a3SHarry Wentland 	oppn20->base.inst = inst;
409eb7a74a3SHarry Wentland 	oppn20->base.funcs = &dcn20_opp_funcs;
410eb7a74a3SHarry Wentland 
411eb7a74a3SHarry Wentland 	oppn20->regs = regs;
412eb7a74a3SHarry Wentland 	oppn20->opp_shift = opp_shift;
413eb7a74a3SHarry Wentland 	oppn20->opp_mask = opp_mask;
414eb7a74a3SHarry Wentland }
415eb7a74a3SHarry Wentland 
416