• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2012-15 Advanced Micro Devices, Inc.
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a
5  * copy of this software and associated documentation files (the "Software"),
6  * to deal in the Software without restriction, including without limitation
7  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8  * and/or sell copies of the Software, and to permit persons to whom the
9  * Software is furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included in
12  * all copies or substantial portions of the Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
17  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20  * OTHER DEALINGS IN THE SOFTWARE.
21  *
22  * Authors: AMD
23  *
24  */
25 
26 
27 #include "reg_helper.h"
28 #include "dcn10_optc.h"
29 #include "dc.h"
30 
31 #define REG(reg)\
32 	optc1->tg_regs->reg
33 
34 #define CTX \
35 	optc1->base.ctx
36 
37 #undef FN
38 #define FN(reg_name, field_name) \
39 	optc1->tg_shift->field_name, optc1->tg_mask->field_name
40 
41 #define STATIC_SCREEN_EVENT_MASK_RANGETIMING_DOUBLE_BUFFER_UPDATE_EN 0x100
42 
43 /**
44 * apply_front_porch_workaround  TODO FPGA still need?
45 *
46 * This is a workaround for a bug that has existed since R5xx and has not been
47 * fixed keep Front porch at minimum 2 for Interlaced mode or 1 for progressive.
48 */
apply_front_porch_workaround(struct dc_crtc_timing * timing)49 static void apply_front_porch_workaround(struct dc_crtc_timing *timing)
50 {
51 	if (timing->flags.INTERLACE == 1) {
52 		if (timing->v_front_porch < 2)
53 			timing->v_front_porch = 2;
54 	} else {
55 		if (timing->v_front_porch < 1)
56 			timing->v_front_porch = 1;
57 	}
58 }
59 
optc1_program_global_sync(struct timing_generator * optc,int vready_offset,int vstartup_start,int vupdate_offset,int vupdate_width)60 void optc1_program_global_sync(
61 		struct timing_generator *optc,
62 		int vready_offset,
63 		int vstartup_start,
64 		int vupdate_offset,
65 		int vupdate_width)
66 {
67 	struct optc *optc1 = DCN10TG_FROM_TG(optc);
68 
69 	optc1->vready_offset = vready_offset;
70 	optc1->vstartup_start = vstartup_start;
71 	optc1->vupdate_offset = vupdate_offset;
72 	optc1->vupdate_width = vupdate_width;
73 
74 	if (optc1->vstartup_start == 0) {
75 		BREAK_TO_DEBUGGER();
76 		return;
77 	}
78 
79 	REG_SET(OTG_VSTARTUP_PARAM, 0,
80 		VSTARTUP_START, optc1->vstartup_start);
81 
82 	REG_SET_2(OTG_VUPDATE_PARAM, 0,
83 			VUPDATE_OFFSET, optc1->vupdate_offset,
84 			VUPDATE_WIDTH, optc1->vupdate_width);
85 
86 	REG_SET(OTG_VREADY_PARAM, 0,
87 			VREADY_OFFSET, optc1->vready_offset);
88 }
89 
optc1_disable_stereo(struct timing_generator * optc)90 static void optc1_disable_stereo(struct timing_generator *optc)
91 {
92 	struct optc *optc1 = DCN10TG_FROM_TG(optc);
93 
94 	REG_SET(OTG_STEREO_CONTROL, 0,
95 		OTG_STEREO_EN, 0);
96 
97 	REG_SET_2(OTG_3D_STRUCTURE_CONTROL, 0,
98 		OTG_3D_STRUCTURE_EN, 0,
99 		OTG_3D_STRUCTURE_STEREO_SEL_OVR, 0);
100 }
101 
optc1_setup_vertical_interrupt0(struct timing_generator * optc,uint32_t start_line,uint32_t end_line)102 void optc1_setup_vertical_interrupt0(
103 		struct timing_generator *optc,
104 		uint32_t start_line,
105 		uint32_t end_line)
106 {
107 	struct optc *optc1 = DCN10TG_FROM_TG(optc);
108 
109 	REG_SET_2(OTG_VERTICAL_INTERRUPT0_POSITION, 0,
110 			OTG_VERTICAL_INTERRUPT0_LINE_START, start_line,
111 			OTG_VERTICAL_INTERRUPT0_LINE_END, end_line);
112 }
113 
optc1_setup_vertical_interrupt1(struct timing_generator * optc,uint32_t start_line)114 void optc1_setup_vertical_interrupt1(
115 		struct timing_generator *optc,
116 		uint32_t start_line)
117 {
118 	struct optc *optc1 = DCN10TG_FROM_TG(optc);
119 
120 	REG_SET(OTG_VERTICAL_INTERRUPT1_POSITION, 0,
121 				OTG_VERTICAL_INTERRUPT1_LINE_START, start_line);
122 }
123 
optc1_setup_vertical_interrupt2(struct timing_generator * optc,uint32_t start_line)124 void optc1_setup_vertical_interrupt2(
125 		struct timing_generator *optc,
126 		uint32_t start_line)
127 {
128 	struct optc *optc1 = DCN10TG_FROM_TG(optc);
129 
130 	REG_SET(OTG_VERTICAL_INTERRUPT2_POSITION, 0,
131 			OTG_VERTICAL_INTERRUPT2_LINE_START, start_line);
132 }
133 
134 /**
135  * Vupdate keepout can be set to a window to block the update lock for that pipe from changing.
136  * Start offset begins with vstartup and goes for x number of clocks,
137  * end offset starts from end of vupdate to x number of clocks.
138  */
optc1_set_vupdate_keepout(struct timing_generator * optc,struct vupdate_keepout_params * params)139 void optc1_set_vupdate_keepout(struct timing_generator *optc,
140 			       struct vupdate_keepout_params *params)
141 {
142 	struct optc *optc1 = DCN10TG_FROM_TG(optc);
143 
144 	REG_SET_3(OTG_VUPDATE_KEEPOUT, 0,
145 		  MASTER_UPDATE_LOCK_VUPDATE_KEEPOUT_START_OFFSET, params->start_offset,
146 		  MASTER_UPDATE_LOCK_VUPDATE_KEEPOUT_END_OFFSET, params->end_offset,
147 		  OTG_MASTER_UPDATE_LOCK_VUPDATE_KEEPOUT_EN, params->enable);
148 }
149 
150 /**
151  * program_timing_generator   used by mode timing set
152  * Program CRTC Timing Registers - OTG_H_*, OTG_V_*, Pixel repetition.
153  * Including SYNC. Call BIOS command table to program Timings.
154  */
optc1_program_timing(struct timing_generator * optc,const struct dc_crtc_timing * dc_crtc_timing,int vready_offset,int vstartup_start,int vupdate_offset,int vupdate_width,const enum signal_type signal,bool use_vbios)155 void optc1_program_timing(
156 	struct timing_generator *optc,
157 	const struct dc_crtc_timing *dc_crtc_timing,
158 	int vready_offset,
159 	int vstartup_start,
160 	int vupdate_offset,
161 	int vupdate_width,
162 	const enum signal_type signal,
163 	bool use_vbios)
164 {
165 	struct dc_crtc_timing patched_crtc_timing;
166 	uint32_t asic_blank_end;
167 	uint32_t asic_blank_start;
168 	uint32_t v_total;
169 	uint32_t v_sync_end;
170 	uint32_t h_sync_polarity, v_sync_polarity;
171 	uint32_t start_point = 0;
172 	uint32_t field_num = 0;
173 	enum h_timing_div_mode h_div = H_TIMING_NO_DIV;
174 
175 	struct optc *optc1 = DCN10TG_FROM_TG(optc);
176 
177 	optc1->signal = signal;
178 	optc1->vready_offset = vready_offset;
179 	optc1->vstartup_start = vstartup_start;
180 	optc1->vupdate_offset = vupdate_offset;
181 	optc1->vupdate_width = vupdate_width;
182 	patched_crtc_timing = *dc_crtc_timing;
183 	apply_front_porch_workaround(&patched_crtc_timing);
184 
185 	/* Load horizontal timing */
186 
187 	/* CRTC_H_TOTAL = vesa.h_total - 1 */
188 	REG_SET(OTG_H_TOTAL, 0,
189 			OTG_H_TOTAL,  patched_crtc_timing.h_total - 1);
190 
191 	/* h_sync_start = 0, h_sync_end = vesa.h_sync_width */
192 	REG_UPDATE_2(OTG_H_SYNC_A,
193 			OTG_H_SYNC_A_START, 0,
194 			OTG_H_SYNC_A_END, patched_crtc_timing.h_sync_width);
195 
196 	/* blank_start = line end - front porch */
197 	asic_blank_start = patched_crtc_timing.h_total -
198 			patched_crtc_timing.h_front_porch;
199 
200 	/* blank_end = blank_start - active */
201 	asic_blank_end = asic_blank_start -
202 			patched_crtc_timing.h_border_right -
203 			patched_crtc_timing.h_addressable -
204 			patched_crtc_timing.h_border_left;
205 
206 	REG_UPDATE_2(OTG_H_BLANK_START_END,
207 			OTG_H_BLANK_START, asic_blank_start,
208 			OTG_H_BLANK_END, asic_blank_end);
209 
210 	/* h_sync polarity */
211 	h_sync_polarity = patched_crtc_timing.flags.HSYNC_POSITIVE_POLARITY ?
212 			0 : 1;
213 
214 	REG_UPDATE(OTG_H_SYNC_A_CNTL,
215 			OTG_H_SYNC_A_POL, h_sync_polarity);
216 
217 	v_total = patched_crtc_timing.v_total - 1;
218 
219 	REG_SET(OTG_V_TOTAL, 0,
220 			OTG_V_TOTAL, v_total);
221 
222 	/* In case of V_TOTAL_CONTROL is on, make sure OTG_V_TOTAL_MAX and
223 	 * OTG_V_TOTAL_MIN are equal to V_TOTAL.
224 	 */
225 	REG_SET(OTG_V_TOTAL_MAX, 0,
226 		OTG_V_TOTAL_MAX, v_total);
227 	REG_SET(OTG_V_TOTAL_MIN, 0,
228 		OTG_V_TOTAL_MIN, v_total);
229 
230 	/* v_sync_start = 0, v_sync_end = v_sync_width */
231 	v_sync_end = patched_crtc_timing.v_sync_width;
232 
233 	REG_UPDATE_2(OTG_V_SYNC_A,
234 			OTG_V_SYNC_A_START, 0,
235 			OTG_V_SYNC_A_END, v_sync_end);
236 
237 	/* blank_start = frame end - front porch */
238 	asic_blank_start = patched_crtc_timing.v_total -
239 			patched_crtc_timing.v_front_porch;
240 
241 	/* blank_end = blank_start - active */
242 	asic_blank_end = asic_blank_start -
243 			patched_crtc_timing.v_border_bottom -
244 			patched_crtc_timing.v_addressable -
245 			patched_crtc_timing.v_border_top;
246 
247 	REG_UPDATE_2(OTG_V_BLANK_START_END,
248 			OTG_V_BLANK_START, asic_blank_start,
249 			OTG_V_BLANK_END, asic_blank_end);
250 
251 	/* v_sync polarity */
252 	v_sync_polarity = patched_crtc_timing.flags.VSYNC_POSITIVE_POLARITY ?
253 			0 : 1;
254 
255 	REG_UPDATE(OTG_V_SYNC_A_CNTL,
256 		OTG_V_SYNC_A_POL, v_sync_polarity);
257 
258 	if (optc1->signal == SIGNAL_TYPE_DISPLAY_PORT ||
259 			optc1->signal == SIGNAL_TYPE_DISPLAY_PORT_MST ||
260 			optc1->signal == SIGNAL_TYPE_EDP) {
261 		start_point = 1;
262 		if (patched_crtc_timing.flags.INTERLACE == 1)
263 			field_num = 1;
264 	}
265 
266 	/* Interlace */
267 	if (REG(OTG_INTERLACE_CONTROL)) {
268 		if (patched_crtc_timing.flags.INTERLACE == 1)
269 			REG_UPDATE(OTG_INTERLACE_CONTROL,
270 					OTG_INTERLACE_ENABLE, 1);
271 		else
272 			REG_UPDATE(OTG_INTERLACE_CONTROL,
273 					OTG_INTERLACE_ENABLE, 0);
274 	}
275 
276 	/* VTG enable set to 0 first VInit */
277 	REG_UPDATE(CONTROL,
278 			VTG0_ENABLE, 0);
279 
280 	/* original code is using VTG offset to address OTG reg, seems wrong */
281 	REG_UPDATE_2(OTG_CONTROL,
282 			OTG_START_POINT_CNTL, start_point,
283 			OTG_FIELD_NUMBER_CNTL, field_num);
284 
285 	optc->funcs->program_global_sync(optc,
286 			vready_offset,
287 			vstartup_start,
288 			vupdate_offset,
289 			vupdate_width);
290 
291 	optc->funcs->set_vtg_params(optc, dc_crtc_timing, true);
292 
293 	/* TODO
294 	 * patched_crtc_timing.flags.HORZ_COUNT_BY_TWO == 1
295 	 * program_horz_count_by_2
296 	 * for DVI 30bpp mode, 0 otherwise
297 	 * program_horz_count_by_2(optc, &patched_crtc_timing);
298 	 */
299 
300 	/* Enable stereo - only when we need to pack 3D frame. Other types
301 	 * of stereo handled in explicit call
302 	 */
303 
304 	if (optc1_is_two_pixels_per_containter(&patched_crtc_timing) || optc1->opp_count == 2)
305 		h_div = H_TIMING_DIV_BY2;
306 
307 	if (REG(OPTC_DATA_FORMAT_CONTROL)) {
308 		uint32_t data_fmt = 0;
309 
310 		if (patched_crtc_timing.pixel_encoding == PIXEL_ENCODING_YCBCR422)
311 			data_fmt = 1;
312 		else if (patched_crtc_timing.pixel_encoding == PIXEL_ENCODING_YCBCR420)
313 			data_fmt = 2;
314 
315 		REG_UPDATE(OPTC_DATA_FORMAT_CONTROL, OPTC_DATA_FORMAT, data_fmt);
316 	}
317 
318 	if (optc1->tg_mask->OTG_H_TIMING_DIV_MODE != 0) {
319 		if (optc1->opp_count == 4)
320 			h_div = H_TIMING_DIV_BY4;
321 
322 		REG_UPDATE(OTG_H_TIMING_CNTL,
323 		OTG_H_TIMING_DIV_MODE, h_div);
324 	} else {
325 		REG_UPDATE(OTG_H_TIMING_CNTL,
326 		OTG_H_TIMING_DIV_BY2, h_div);
327 	}
328 }
329 
optc1_set_vtg_params(struct timing_generator * optc,const struct dc_crtc_timing * dc_crtc_timing,bool program_fp2)330 void optc1_set_vtg_params(struct timing_generator *optc,
331 		const struct dc_crtc_timing *dc_crtc_timing, bool program_fp2)
332 {
333 	struct dc_crtc_timing patched_crtc_timing;
334 	uint32_t asic_blank_end;
335 	uint32_t v_init;
336 	uint32_t v_fp2 = 0;
337 	int32_t vertical_line_start;
338 
339 	struct optc *optc1 = DCN10TG_FROM_TG(optc);
340 
341 	patched_crtc_timing = *dc_crtc_timing;
342 	apply_front_porch_workaround(&patched_crtc_timing);
343 
344 	/* VCOUNT_INIT is the start of blank */
345 	v_init = patched_crtc_timing.v_total - patched_crtc_timing.v_front_porch;
346 
347 	/* end of blank = v_init - active */
348 	asic_blank_end = v_init -
349 			patched_crtc_timing.v_border_bottom -
350 			patched_crtc_timing.v_addressable -
351 			patched_crtc_timing.v_border_top;
352 
353 	/* if VSTARTUP is before VSYNC, FP2 is the offset, otherwise 0 */
354 	vertical_line_start = asic_blank_end - optc1->vstartup_start + 1;
355 	if (vertical_line_start < 0)
356 		v_fp2 = -vertical_line_start;
357 
358 	/* Interlace */
359 	if (REG(OTG_INTERLACE_CONTROL)) {
360 		if (patched_crtc_timing.flags.INTERLACE == 1) {
361 			v_init = v_init / 2;
362 			if ((optc1->vstartup_start/2)*2 > asic_blank_end)
363 				v_fp2 = v_fp2 / 2;
364 		}
365 	}
366 
367 	if (program_fp2)
368 		REG_UPDATE_2(CONTROL,
369 				VTG0_FP2, v_fp2,
370 				VTG0_VCOUNT_INIT, v_init);
371 	else
372 		REG_UPDATE(CONTROL, VTG0_VCOUNT_INIT, v_init);
373 }
374 
optc1_set_blank_data_double_buffer(struct timing_generator * optc,bool enable)375 void optc1_set_blank_data_double_buffer(struct timing_generator *optc, bool enable)
376 {
377 	struct optc *optc1 = DCN10TG_FROM_TG(optc);
378 
379 	uint32_t blank_data_double_buffer_enable = enable ? 1 : 0;
380 
381 	REG_UPDATE(OTG_DOUBLE_BUFFER_CONTROL,
382 			OTG_BLANK_DATA_DOUBLE_BUFFER_EN, blank_data_double_buffer_enable);
383 }
384 
385 /**
386  * optc1_set_timing_double_buffer() - DRR double buffering control
387  *
388  * Sets double buffer point for V_TOTAL, H_TOTAL, VTOTAL_MIN,
389  * VTOTAL_MAX, VTOTAL_MIN_SEL and VTOTAL_MAX_SEL registers.
390  *
391  * Options: any time,  start of frame, dp start of frame (range timing)
392  */
optc1_set_timing_double_buffer(struct timing_generator * optc,bool enable)393 void optc1_set_timing_double_buffer(struct timing_generator *optc, bool enable)
394 {
395 	struct optc *optc1 = DCN10TG_FROM_TG(optc);
396 	uint32_t mode = enable ? 2 : 0;
397 
398 	REG_UPDATE(OTG_DOUBLE_BUFFER_CONTROL,
399 		   OTG_RANGE_TIMING_DBUF_UPDATE_MODE, mode);
400 }
401 
402 /**
403  * unblank_crtc
404  * Call ASIC Control Object to UnBlank CRTC.
405  */
optc1_unblank_crtc(struct timing_generator * optc)406 static void optc1_unblank_crtc(struct timing_generator *optc)
407 {
408 	struct optc *optc1 = DCN10TG_FROM_TG(optc);
409 
410 	REG_UPDATE_2(OTG_BLANK_CONTROL,
411 			OTG_BLANK_DATA_EN, 0,
412 			OTG_BLANK_DE_MODE, 0);
413 
414 	/* W/A for automated testing
415 	 * Automated testing will fail underflow test as there
416 	 * sporadic underflows which occur during the optc blank
417 	 * sequence.  As a w/a, clear underflow on unblank.
418 	 * This prevents the failure, but will not mask actual
419 	 * underflow that affect real use cases.
420 	 */
421 	optc1_clear_optc_underflow(optc);
422 }
423 
424 /**
425  * blank_crtc
426  * Call ASIC Control Object to Blank CRTC.
427  */
428 
optc1_blank_crtc(struct timing_generator * optc)429 static void optc1_blank_crtc(struct timing_generator *optc)
430 {
431 	struct optc *optc1 = DCN10TG_FROM_TG(optc);
432 
433 	REG_UPDATE_2(OTG_BLANK_CONTROL,
434 			OTG_BLANK_DATA_EN, 1,
435 			OTG_BLANK_DE_MODE, 0);
436 
437 	optc1_set_blank_data_double_buffer(optc, false);
438 }
439 
optc1_set_blank(struct timing_generator * optc,bool enable_blanking)440 void optc1_set_blank(struct timing_generator *optc,
441 		bool enable_blanking)
442 {
443 	if (enable_blanking)
444 		optc1_blank_crtc(optc);
445 	else
446 		optc1_unblank_crtc(optc);
447 }
448 
optc1_is_blanked(struct timing_generator * optc)449 bool optc1_is_blanked(struct timing_generator *optc)
450 {
451 	struct optc *optc1 = DCN10TG_FROM_TG(optc);
452 	uint32_t blank_en;
453 	uint32_t blank_state;
454 
455 	REG_GET_2(OTG_BLANK_CONTROL,
456 			OTG_BLANK_DATA_EN, &blank_en,
457 			OTG_CURRENT_BLANK_STATE, &blank_state);
458 
459 	return blank_en && blank_state;
460 }
461 
optc1_enable_optc_clock(struct timing_generator * optc,bool enable)462 void optc1_enable_optc_clock(struct timing_generator *optc, bool enable)
463 {
464 	struct optc *optc1 = DCN10TG_FROM_TG(optc);
465 
466 	if (enable) {
467 		REG_UPDATE_2(OPTC_INPUT_CLOCK_CONTROL,
468 				OPTC_INPUT_CLK_EN, 1,
469 				OPTC_INPUT_CLK_GATE_DIS, 1);
470 
471 		REG_WAIT(OPTC_INPUT_CLOCK_CONTROL,
472 				OPTC_INPUT_CLK_ON, 1,
473 				1, 1000);
474 
475 		/* Enable clock */
476 		REG_UPDATE_2(OTG_CLOCK_CONTROL,
477 				OTG_CLOCK_EN, 1,
478 				OTG_CLOCK_GATE_DIS, 1);
479 		REG_WAIT(OTG_CLOCK_CONTROL,
480 				OTG_CLOCK_ON, 1,
481 				1, 1000);
482 	} else  {
483 
484 		//last chance to clear underflow, otherwise, it will always there due to clock is off.
485 		if (optc->funcs->is_optc_underflow_occurred(optc) == true)
486 			optc->funcs->clear_optc_underflow(optc);
487 
488 		REG_UPDATE_2(OTG_CLOCK_CONTROL,
489 				OTG_CLOCK_GATE_DIS, 0,
490 				OTG_CLOCK_EN, 0);
491 
492 		REG_UPDATE_2(OPTC_INPUT_CLOCK_CONTROL,
493 				OPTC_INPUT_CLK_GATE_DIS, 0,
494 				OPTC_INPUT_CLK_EN, 0);
495 	}
496 }
497 
498 /**
499  * Enable CRTC
500  * Enable CRTC - call ASIC Control Object to enable Timing generator.
501  */
optc1_enable_crtc(struct timing_generator * optc)502 static bool optc1_enable_crtc(struct timing_generator *optc)
503 {
504 	/* TODO FPGA wait for answer
505 	 * OTG_MASTER_UPDATE_MODE != CRTC_MASTER_UPDATE_MODE
506 	 * OTG_MASTER_UPDATE_LOCK != CRTC_MASTER_UPDATE_LOCK
507 	 */
508 	struct optc *optc1 = DCN10TG_FROM_TG(optc);
509 
510 	/* opp instance for OTG. For DCN1.0, ODM is remoed.
511 	 * OPP and OPTC should 1:1 mapping
512 	 */
513 	REG_UPDATE(OPTC_DATA_SOURCE_SELECT,
514 			OPTC_SRC_SEL, optc->inst);
515 
516 	/* VTG enable first is for HW workaround */
517 	REG_UPDATE(CONTROL,
518 			VTG0_ENABLE, 1);
519 
520 	REG_SEQ_START();
521 
522 	/* Enable CRTC */
523 	REG_UPDATE_2(OTG_CONTROL,
524 			OTG_DISABLE_POINT_CNTL, 3,
525 			OTG_MASTER_EN, 1);
526 
527 	REG_SEQ_SUBMIT();
528 	REG_SEQ_WAIT_DONE();
529 
530 	return true;
531 }
532 
533 /* disable_crtc - call ASIC Control Object to disable Timing generator. */
optc1_disable_crtc(struct timing_generator * optc)534 bool optc1_disable_crtc(struct timing_generator *optc)
535 {
536 	struct optc *optc1 = DCN10TG_FROM_TG(optc);
537 
538 	/* disable otg request until end of the first line
539 	 * in the vertical blank region
540 	 */
541 	REG_UPDATE_2(OTG_CONTROL,
542 			OTG_DISABLE_POINT_CNTL, 3,
543 			OTG_MASTER_EN, 0);
544 
545 	REG_UPDATE(CONTROL,
546 			VTG0_ENABLE, 0);
547 
548 	/* CRTC disabled, so disable  clock. */
549 	REG_WAIT(OTG_CLOCK_CONTROL,
550 			OTG_BUSY, 0,
551 			1, 100000);
552 
553 	return true;
554 }
555 
556 
optc1_program_blank_color(struct timing_generator * optc,const struct tg_color * black_color)557 void optc1_program_blank_color(
558 		struct timing_generator *optc,
559 		const struct tg_color *black_color)
560 {
561 	struct optc *optc1 = DCN10TG_FROM_TG(optc);
562 
563 	REG_SET_3(OTG_BLACK_COLOR, 0,
564 			OTG_BLACK_COLOR_B_CB, black_color->color_b_cb,
565 			OTG_BLACK_COLOR_G_Y, black_color->color_g_y,
566 			OTG_BLACK_COLOR_R_CR, black_color->color_r_cr);
567 }
568 
optc1_validate_timing(struct timing_generator * optc,const struct dc_crtc_timing * timing)569 bool optc1_validate_timing(
570 	struct timing_generator *optc,
571 	const struct dc_crtc_timing *timing)
572 {
573 	uint32_t v_blank;
574 	uint32_t h_blank;
575 	uint32_t min_v_blank;
576 	struct optc *optc1 = DCN10TG_FROM_TG(optc);
577 
578 	ASSERT(timing != NULL);
579 
580 	v_blank = (timing->v_total - timing->v_addressable -
581 					timing->v_border_top - timing->v_border_bottom);
582 
583 	h_blank = (timing->h_total - timing->h_addressable -
584 		timing->h_border_right -
585 		timing->h_border_left);
586 
587 	if (timing->timing_3d_format != TIMING_3D_FORMAT_NONE &&
588 		timing->timing_3d_format != TIMING_3D_FORMAT_HW_FRAME_PACKING &&
589 		timing->timing_3d_format != TIMING_3D_FORMAT_TOP_AND_BOTTOM &&
590 		timing->timing_3d_format != TIMING_3D_FORMAT_SIDE_BY_SIDE &&
591 		timing->timing_3d_format != TIMING_3D_FORMAT_FRAME_ALTERNATE &&
592 		timing->timing_3d_format != TIMING_3D_FORMAT_INBAND_FA)
593 		return false;
594 
595 	/* Temporarily blocking interlacing mode until it's supported */
596 	if (timing->flags.INTERLACE == 1)
597 		return false;
598 
599 	/* Check maximum number of pixels supported by Timing Generator
600 	 * (Currently will never fail, in order to fail needs display which
601 	 * needs more than 8192 horizontal and
602 	 * more than 8192 vertical total pixels)
603 	 */
604 	if (timing->h_total > optc1->max_h_total ||
605 		timing->v_total > optc1->max_v_total)
606 		return false;
607 
608 
609 	if (h_blank < optc1->min_h_blank)
610 		return false;
611 
612 	if (timing->h_sync_width  < optc1->min_h_sync_width ||
613 		 timing->v_sync_width  < optc1->min_v_sync_width)
614 		return false;
615 
616 	min_v_blank = timing->flags.INTERLACE?optc1->min_v_blank_interlace:optc1->min_v_blank;
617 
618 	if (v_blank < min_v_blank)
619 		return false;
620 
621 	return true;
622 
623 }
624 
625 /*
626  * get_vblank_counter
627  *
628  * @brief
629  * Get counter for vertical blanks. use register CRTC_STATUS_FRAME_COUNT which
630  * holds the counter of frames.
631  *
632  * @param
633  * struct timing_generator *optc - [in] timing generator which controls the
634  * desired CRTC
635  *
636  * @return
637  * Counter of frames, which should equal to number of vblanks.
638  */
optc1_get_vblank_counter(struct timing_generator * optc)639 uint32_t optc1_get_vblank_counter(struct timing_generator *optc)
640 {
641 	struct optc *optc1 = DCN10TG_FROM_TG(optc);
642 	uint32_t frame_count;
643 
644 	REG_GET(OTG_STATUS_FRAME_COUNT,
645 		OTG_FRAME_COUNT, &frame_count);
646 
647 	return frame_count;
648 }
649 
optc1_lock(struct timing_generator * optc)650 void optc1_lock(struct timing_generator *optc)
651 {
652 	struct optc *optc1 = DCN10TG_FROM_TG(optc);
653 	uint32_t regval = 0;
654 
655 	regval = REG_READ(OTG_CONTROL);
656 
657 	/* otg is not running, do not need to be locked */
658 	if ((regval & 0x1) == 0x0)
659 		return;
660 
661 	REG_SET(OTG_GLOBAL_CONTROL0, 0,
662 			OTG_MASTER_UPDATE_LOCK_SEL, optc->inst);
663 	REG_SET(OTG_MASTER_UPDATE_LOCK, 0,
664 			OTG_MASTER_UPDATE_LOCK, 1);
665 
666 	/* Should be fast, status does not update on maximus */
667 	if (optc->ctx->dce_environment != DCE_ENV_FPGA_MAXIMUS) {
668 
669 		REG_WAIT(OTG_MASTER_UPDATE_LOCK,
670 				UPDATE_LOCK_STATUS, 1,
671 				1, 10);
672 	}
673 }
674 
optc1_unlock(struct timing_generator * optc)675 void optc1_unlock(struct timing_generator *optc)
676 {
677 	struct optc *optc1 = DCN10TG_FROM_TG(optc);
678 
679 	REG_SET(OTG_MASTER_UPDATE_LOCK, 0,
680 			OTG_MASTER_UPDATE_LOCK, 0);
681 }
682 
optc1_is_locked(struct timing_generator * optc)683 bool optc1_is_locked(struct timing_generator *optc)
684 {
685 	struct optc *optc1 = DCN10TG_FROM_TG(optc);
686 	uint32_t locked;
687 
688 	REG_GET(OTG_MASTER_UPDATE_LOCK, UPDATE_LOCK_STATUS, &locked);
689 
690 	return (locked == 1);
691 }
692 
optc1_get_position(struct timing_generator * optc,struct crtc_position * position)693 void optc1_get_position(struct timing_generator *optc,
694 		struct crtc_position *position)
695 {
696 	struct optc *optc1 = DCN10TG_FROM_TG(optc);
697 
698 	REG_GET_2(OTG_STATUS_POSITION,
699 			OTG_HORZ_COUNT, &position->horizontal_count,
700 			OTG_VERT_COUNT, &position->vertical_count);
701 
702 	REG_GET(OTG_NOM_VERT_POSITION,
703 			OTG_VERT_COUNT_NOM, &position->nominal_vcount);
704 }
705 
optc1_is_counter_moving(struct timing_generator * optc)706 bool optc1_is_counter_moving(struct timing_generator *optc)
707 {
708 	struct crtc_position position1, position2;
709 
710 	optc->funcs->get_position(optc, &position1);
711 	optc->funcs->get_position(optc, &position2);
712 
713 	if (position1.horizontal_count == position2.horizontal_count &&
714 		position1.vertical_count == position2.vertical_count)
715 		return false;
716 	else
717 		return true;
718 }
719 
optc1_did_triggered_reset_occur(struct timing_generator * optc)720 bool optc1_did_triggered_reset_occur(
721 	struct timing_generator *optc)
722 {
723 	struct optc *optc1 = DCN10TG_FROM_TG(optc);
724 	uint32_t occurred_force, occurred_vsync;
725 
726 	REG_GET(OTG_FORCE_COUNT_NOW_CNTL,
727 		OTG_FORCE_COUNT_NOW_OCCURRED, &occurred_force);
728 
729 	REG_GET(OTG_VERT_SYNC_CONTROL,
730 		OTG_FORCE_VSYNC_NEXT_LINE_OCCURRED, &occurred_vsync);
731 
732 	return occurred_vsync != 0 || occurred_force != 0;
733 }
734 
optc1_disable_reset_trigger(struct timing_generator * optc)735 void optc1_disable_reset_trigger(struct timing_generator *optc)
736 {
737 	struct optc *optc1 = DCN10TG_FROM_TG(optc);
738 
739 	REG_WRITE(OTG_TRIGA_CNTL, 0);
740 
741 	REG_SET(OTG_FORCE_COUNT_NOW_CNTL, 0,
742 		OTG_FORCE_COUNT_NOW_CLEAR, 1);
743 
744 	REG_SET(OTG_VERT_SYNC_CONTROL, 0,
745 		OTG_FORCE_VSYNC_NEXT_LINE_CLEAR, 1);
746 }
747 
optc1_enable_reset_trigger(struct timing_generator * optc,int source_tg_inst)748 void optc1_enable_reset_trigger(struct timing_generator *optc, int source_tg_inst)
749 {
750 	struct optc *optc1 = DCN10TG_FROM_TG(optc);
751 	uint32_t falling_edge;
752 
753 	REG_GET(OTG_V_SYNC_A_CNTL,
754 			OTG_V_SYNC_A_POL, &falling_edge);
755 
756 	if (falling_edge)
757 		REG_SET_3(OTG_TRIGA_CNTL, 0,
758 				/* vsync signal from selected OTG pipe based
759 				 * on OTG_TRIG_SOURCE_PIPE_SELECT setting
760 				 */
761 				OTG_TRIGA_SOURCE_SELECT, 20,
762 				OTG_TRIGA_SOURCE_PIPE_SELECT, source_tg_inst,
763 				/* always detect falling edge */
764 				OTG_TRIGA_FALLING_EDGE_DETECT_CNTL, 1);
765 	else
766 		REG_SET_3(OTG_TRIGA_CNTL, 0,
767 				/* vsync signal from selected OTG pipe based
768 				 * on OTG_TRIG_SOURCE_PIPE_SELECT setting
769 				 */
770 				OTG_TRIGA_SOURCE_SELECT, 20,
771 				OTG_TRIGA_SOURCE_PIPE_SELECT, source_tg_inst,
772 				/* always detect rising edge */
773 				OTG_TRIGA_RISING_EDGE_DETECT_CNTL, 1);
774 
775 	REG_SET(OTG_FORCE_COUNT_NOW_CNTL, 0,
776 			/* force H count to H_TOTAL and V count to V_TOTAL in
777 			 * progressive mode and V_TOTAL-1 in interlaced mode
778 			 */
779 			OTG_FORCE_COUNT_NOW_MODE, 2);
780 }
781 
optc1_enable_crtc_reset(struct timing_generator * optc,int source_tg_inst,struct crtc_trigger_info * crtc_tp)782 void optc1_enable_crtc_reset(
783 		struct timing_generator *optc,
784 		int source_tg_inst,
785 		struct crtc_trigger_info *crtc_tp)
786 {
787 	struct optc *optc1 = DCN10TG_FROM_TG(optc);
788 	uint32_t falling_edge = 0;
789 	uint32_t rising_edge = 0;
790 
791 	switch (crtc_tp->event) {
792 
793 	case CRTC_EVENT_VSYNC_RISING:
794 		rising_edge = 1;
795 		break;
796 
797 	case CRTC_EVENT_VSYNC_FALLING:
798 		falling_edge = 1;
799 		break;
800 	}
801 
802 	REG_SET_4(OTG_TRIGA_CNTL, 0,
803 		 /* vsync signal from selected OTG pipe based
804 		  * on OTG_TRIG_SOURCE_PIPE_SELECT setting
805 		  */
806 		  OTG_TRIGA_SOURCE_SELECT, 20,
807 		  OTG_TRIGA_SOURCE_PIPE_SELECT, source_tg_inst,
808 		  /* always detect falling edge */
809 		  OTG_TRIGA_RISING_EDGE_DETECT_CNTL, rising_edge,
810 		  OTG_TRIGA_FALLING_EDGE_DETECT_CNTL, falling_edge);
811 
812 	switch (crtc_tp->delay) {
813 	case TRIGGER_DELAY_NEXT_LINE:
814 		REG_SET(OTG_VERT_SYNC_CONTROL, 0,
815 				OTG_AUTO_FORCE_VSYNC_MODE, 1);
816 		break;
817 	case TRIGGER_DELAY_NEXT_PIXEL:
818 		REG_SET(OTG_FORCE_COUNT_NOW_CNTL, 0,
819 			/* force H count to H_TOTAL and V count to V_TOTAL in
820 			 * progressive mode and V_TOTAL-1 in interlaced mode
821 			 */
822 			OTG_FORCE_COUNT_NOW_MODE, 2);
823 		break;
824 	}
825 }
826 
optc1_wait_for_state(struct timing_generator * optc,enum crtc_state state)827 void optc1_wait_for_state(struct timing_generator *optc,
828 		enum crtc_state state)
829 {
830 	struct optc *optc1 = DCN10TG_FROM_TG(optc);
831 
832 	switch (state) {
833 	case CRTC_STATE_VBLANK:
834 		REG_WAIT(OTG_STATUS,
835 				OTG_V_BLANK, 1,
836 				1, 100000); /* 1 vupdate at 10hz */
837 		break;
838 
839 	case CRTC_STATE_VACTIVE:
840 		REG_WAIT(OTG_STATUS,
841 				OTG_V_ACTIVE_DISP, 1,
842 				1, 100000); /* 1 vupdate at 10hz */
843 		break;
844 
845 	default:
846 		break;
847 	}
848 }
849 
optc1_set_early_control(struct timing_generator * optc,uint32_t early_cntl)850 void optc1_set_early_control(
851 	struct timing_generator *optc,
852 	uint32_t early_cntl)
853 {
854 	/* asic design change, do not need this control
855 	 * empty for share caller logic
856 	 */
857 }
858 
859 
optc1_set_static_screen_control(struct timing_generator * optc,uint32_t event_triggers,uint32_t num_frames)860 void optc1_set_static_screen_control(
861 	struct timing_generator *optc,
862 	uint32_t event_triggers,
863 	uint32_t num_frames)
864 {
865 	struct optc *optc1 = DCN10TG_FROM_TG(optc);
866 
867 	// By register spec, it only takes 8 bit value
868 	if (num_frames > 0xFF)
869 		num_frames = 0xFF;
870 
871 	/* Bit 8 is no longer applicable in RV for PSR case,
872 	 * set bit 8 to 0 if given
873 	 */
874 	if ((event_triggers & STATIC_SCREEN_EVENT_MASK_RANGETIMING_DOUBLE_BUFFER_UPDATE_EN)
875 			!= 0)
876 		event_triggers = event_triggers &
877 		~STATIC_SCREEN_EVENT_MASK_RANGETIMING_DOUBLE_BUFFER_UPDATE_EN;
878 
879 	REG_SET_2(OTG_STATIC_SCREEN_CONTROL, 0,
880 			OTG_STATIC_SCREEN_EVENT_MASK, event_triggers,
881 			OTG_STATIC_SCREEN_FRAME_COUNT, num_frames);
882 }
883 
optc1_setup_manual_trigger(struct timing_generator * optc)884 void optc1_setup_manual_trigger(struct timing_generator *optc)
885 {
886 	struct optc *optc1 = DCN10TG_FROM_TG(optc);
887 
888 	REG_SET(OTG_GLOBAL_CONTROL2, 0,
889 			MANUAL_FLOW_CONTROL_SEL, optc->inst);
890 
891 	REG_SET_8(OTG_TRIGA_CNTL, 0,
892 			OTG_TRIGA_SOURCE_SELECT, 22,
893 			OTG_TRIGA_SOURCE_PIPE_SELECT, optc->inst,
894 			OTG_TRIGA_RISING_EDGE_DETECT_CNTL, 1,
895 			OTG_TRIGA_FALLING_EDGE_DETECT_CNTL, 0,
896 			OTG_TRIGA_POLARITY_SELECT, 0,
897 			OTG_TRIGA_FREQUENCY_SELECT, 0,
898 			OTG_TRIGA_DELAY, 0,
899 			OTG_TRIGA_CLEAR, 1);
900 }
901 
optc1_program_manual_trigger(struct timing_generator * optc)902 void optc1_program_manual_trigger(struct timing_generator *optc)
903 {
904 	struct optc *optc1 = DCN10TG_FROM_TG(optc);
905 
906 	REG_SET(OTG_MANUAL_FLOW_CONTROL, 0,
907 			MANUAL_FLOW_CONTROL, 1);
908 
909 	REG_SET(OTG_MANUAL_FLOW_CONTROL, 0,
910 			MANUAL_FLOW_CONTROL, 0);
911 }
912 
913 
914 /**
915  *****************************************************************************
916  *  Function: set_drr
917  *
918  *  @brief
919  *     Program dynamic refresh rate registers m_OTGx_OTG_V_TOTAL_*.
920  *
921  *****************************************************************************
922  */
optc1_set_drr(struct timing_generator * optc,const struct drr_params * params)923 void optc1_set_drr(
924 	struct timing_generator *optc,
925 	const struct drr_params *params)
926 {
927 	struct optc *optc1 = DCN10TG_FROM_TG(optc);
928 
929 	if (params != NULL &&
930 		params->vertical_total_max > 0 &&
931 		params->vertical_total_min > 0) {
932 
933 		if (params->vertical_total_mid != 0) {
934 
935 			REG_SET(OTG_V_TOTAL_MID, 0,
936 				OTG_V_TOTAL_MID, params->vertical_total_mid - 1);
937 
938 			REG_UPDATE_2(OTG_V_TOTAL_CONTROL,
939 					OTG_VTOTAL_MID_REPLACING_MAX_EN, 1,
940 					OTG_VTOTAL_MID_FRAME_NUM,
941 					(uint8_t)params->vertical_total_mid_frame_num);
942 
943 		}
944 
945 		REG_SET(OTG_V_TOTAL_MAX, 0,
946 			OTG_V_TOTAL_MAX, params->vertical_total_max - 1);
947 
948 		REG_SET(OTG_V_TOTAL_MIN, 0,
949 			OTG_V_TOTAL_MIN, params->vertical_total_min - 1);
950 
951 		REG_UPDATE_5(OTG_V_TOTAL_CONTROL,
952 				OTG_V_TOTAL_MIN_SEL, 1,
953 				OTG_V_TOTAL_MAX_SEL, 1,
954 				OTG_FORCE_LOCK_ON_EVENT, 0,
955 				OTG_SET_V_TOTAL_MIN_MASK_EN, 0,
956 				OTG_SET_V_TOTAL_MIN_MASK, 0);
957 
958 		// Setup manual flow control for EOF via TRIG_A
959 		optc->funcs->setup_manual_trigger(optc);
960 
961 	} else {
962 		REG_UPDATE_4(OTG_V_TOTAL_CONTROL,
963 				OTG_SET_V_TOTAL_MIN_MASK, 0,
964 				OTG_V_TOTAL_MIN_SEL, 0,
965 				OTG_V_TOTAL_MAX_SEL, 0,
966 				OTG_FORCE_LOCK_ON_EVENT, 0);
967 
968 		REG_SET(OTG_V_TOTAL_MIN, 0,
969 			OTG_V_TOTAL_MIN, 0);
970 
971 		REG_SET(OTG_V_TOTAL_MAX, 0,
972 			OTG_V_TOTAL_MAX, 0);
973 	}
974 }
975 
optc1_set_vtotal_min_max(struct timing_generator * optc,int vtotal_min,int vtotal_max)976 void optc1_set_vtotal_min_max(struct timing_generator *optc, int vtotal_min, int vtotal_max)
977 {
978 	struct optc *optc1 = DCN10TG_FROM_TG(optc);
979 
980 	REG_SET(OTG_V_TOTAL_MAX, 0,
981 		OTG_V_TOTAL_MAX, vtotal_max);
982 
983 	REG_SET(OTG_V_TOTAL_MIN, 0,
984 		OTG_V_TOTAL_MIN, vtotal_min);
985 }
986 
optc1_set_test_pattern(struct timing_generator * optc,enum controller_dp_test_pattern test_pattern,enum dc_color_depth color_depth)987 static void optc1_set_test_pattern(
988 	struct timing_generator *optc,
989 	/* TODO: replace 'controller_dp_test_pattern' by 'test_pattern_mode'
990 	 * because this is not DP-specific (which is probably somewhere in DP
991 	 * encoder) */
992 	enum controller_dp_test_pattern test_pattern,
993 	enum dc_color_depth color_depth)
994 {
995 	struct optc *optc1 = DCN10TG_FROM_TG(optc);
996 	enum test_pattern_color_format bit_depth;
997 	enum test_pattern_dyn_range dyn_range;
998 	enum test_pattern_mode mode;
999 	uint32_t pattern_mask;
1000 	uint32_t pattern_data;
1001 	/* color ramp generator mixes 16-bits color */
1002 	uint32_t src_bpc = 16;
1003 	/* requested bpc */
1004 	uint32_t dst_bpc;
1005 	uint32_t index;
1006 	/* RGB values of the color bars.
1007 	 * Produce two RGB colors: RGB0 - white (all Fs)
1008 	 * and RGB1 - black (all 0s)
1009 	 * (three RGB components for two colors)
1010 	 */
1011 	uint16_t src_color[6] = {0xFFFF, 0xFFFF, 0xFFFF, 0x0000,
1012 						0x0000, 0x0000};
1013 	/* dest color (converted to the specified color format) */
1014 	uint16_t dst_color[6];
1015 	uint32_t inc_base;
1016 
1017 	/* translate to bit depth */
1018 	switch (color_depth) {
1019 	case COLOR_DEPTH_666:
1020 		bit_depth = TEST_PATTERN_COLOR_FORMAT_BPC_6;
1021 	break;
1022 	case COLOR_DEPTH_888:
1023 		bit_depth = TEST_PATTERN_COLOR_FORMAT_BPC_8;
1024 	break;
1025 	case COLOR_DEPTH_101010:
1026 		bit_depth = TEST_PATTERN_COLOR_FORMAT_BPC_10;
1027 	break;
1028 	case COLOR_DEPTH_121212:
1029 		bit_depth = TEST_PATTERN_COLOR_FORMAT_BPC_12;
1030 	break;
1031 	default:
1032 		bit_depth = TEST_PATTERN_COLOR_FORMAT_BPC_8;
1033 	break;
1034 	}
1035 
1036 	switch (test_pattern) {
1037 	case CONTROLLER_DP_TEST_PATTERN_COLORSQUARES:
1038 	case CONTROLLER_DP_TEST_PATTERN_COLORSQUARES_CEA:
1039 	{
1040 		dyn_range = (test_pattern ==
1041 				CONTROLLER_DP_TEST_PATTERN_COLORSQUARES_CEA ?
1042 				TEST_PATTERN_DYN_RANGE_CEA :
1043 				TEST_PATTERN_DYN_RANGE_VESA);
1044 		mode = TEST_PATTERN_MODE_COLORSQUARES_RGB;
1045 
1046 		REG_UPDATE_2(OTG_TEST_PATTERN_PARAMETERS,
1047 				OTG_TEST_PATTERN_VRES, 6,
1048 				OTG_TEST_PATTERN_HRES, 6);
1049 
1050 		REG_UPDATE_4(OTG_TEST_PATTERN_CONTROL,
1051 				OTG_TEST_PATTERN_EN, 1,
1052 				OTG_TEST_PATTERN_MODE, mode,
1053 				OTG_TEST_PATTERN_DYNAMIC_RANGE, dyn_range,
1054 				OTG_TEST_PATTERN_COLOR_FORMAT, bit_depth);
1055 	}
1056 	break;
1057 
1058 	case CONTROLLER_DP_TEST_PATTERN_VERTICALBARS:
1059 	case CONTROLLER_DP_TEST_PATTERN_HORIZONTALBARS:
1060 	{
1061 		mode = (test_pattern ==
1062 			CONTROLLER_DP_TEST_PATTERN_VERTICALBARS ?
1063 			TEST_PATTERN_MODE_VERTICALBARS :
1064 			TEST_PATTERN_MODE_HORIZONTALBARS);
1065 
1066 		switch (bit_depth) {
1067 		case TEST_PATTERN_COLOR_FORMAT_BPC_6:
1068 			dst_bpc = 6;
1069 		break;
1070 		case TEST_PATTERN_COLOR_FORMAT_BPC_8:
1071 			dst_bpc = 8;
1072 		break;
1073 		case TEST_PATTERN_COLOR_FORMAT_BPC_10:
1074 			dst_bpc = 10;
1075 		break;
1076 		default:
1077 			dst_bpc = 8;
1078 		break;
1079 		}
1080 
1081 		/* adjust color to the required colorFormat */
1082 		for (index = 0; index < 6; index++) {
1083 			/* dst = 2^dstBpc * src / 2^srcBpc = src >>
1084 			 * (srcBpc - dstBpc);
1085 			 */
1086 			dst_color[index] =
1087 				src_color[index] >> (src_bpc - dst_bpc);
1088 		/* CRTC_TEST_PATTERN_DATA has 16 bits,
1089 		 * lowest 6 are hardwired to ZERO
1090 		 * color bits should be left aligned aligned to MSB
1091 		 * XXXXXXXXXX000000 for 10 bit,
1092 		 * XXXXXXXX00000000 for 8 bit and XXXXXX0000000000 for 6
1093 		 */
1094 			dst_color[index] <<= (16 - dst_bpc);
1095 		}
1096 
1097 		REG_WRITE(OTG_TEST_PATTERN_PARAMETERS, 0);
1098 
1099 		/* We have to write the mask before data, similar to pipeline.
1100 		 * For example, for 8 bpc, if we want RGB0 to be magenta,
1101 		 * and RGB1 to be cyan,
1102 		 * we need to make 7 writes:
1103 		 * MASK   DATA
1104 		 * 000001 00000000 00000000                     set mask to R0
1105 		 * 000010 11111111 00000000     R0 255, 0xFF00, set mask to G0
1106 		 * 000100 00000000 00000000     G0 0,   0x0000, set mask to B0
1107 		 * 001000 11111111 00000000     B0 255, 0xFF00, set mask to R1
1108 		 * 010000 00000000 00000000     R1 0,   0x0000, set mask to G1
1109 		 * 100000 11111111 00000000     G1 255, 0xFF00, set mask to B1
1110 		 * 100000 11111111 00000000     B1 255, 0xFF00
1111 		 *
1112 		 * we will make a loop of 6 in which we prepare the mask,
1113 		 * then write, then prepare the color for next write.
1114 		 * first iteration will write mask only,
1115 		 * but each next iteration color prepared in
1116 		 * previous iteration will be written within new mask,
1117 		 * the last component will written separately,
1118 		 * mask is not changing between 6th and 7th write
1119 		 * and color will be prepared by last iteration
1120 		 */
1121 
1122 		/* write color, color values mask in CRTC_TEST_PATTERN_MASK
1123 		 * is B1, G1, R1, B0, G0, R0
1124 		 */
1125 		pattern_data = 0;
1126 		for (index = 0; index < 6; index++) {
1127 			/* prepare color mask, first write PATTERN_DATA
1128 			 * will have all zeros
1129 			 */
1130 			pattern_mask = (1 << index);
1131 
1132 			/* write color component */
1133 			REG_SET_2(OTG_TEST_PATTERN_COLOR, 0,
1134 					OTG_TEST_PATTERN_MASK, pattern_mask,
1135 					OTG_TEST_PATTERN_DATA, pattern_data);
1136 
1137 			/* prepare next color component,
1138 			 * will be written in the next iteration
1139 			 */
1140 			pattern_data = dst_color[index];
1141 		}
1142 		/* write last color component,
1143 		 * it's been already prepared in the loop
1144 		 */
1145 		REG_SET_2(OTG_TEST_PATTERN_COLOR, 0,
1146 				OTG_TEST_PATTERN_MASK, pattern_mask,
1147 				OTG_TEST_PATTERN_DATA, pattern_data);
1148 
1149 		/* enable test pattern */
1150 		REG_UPDATE_4(OTG_TEST_PATTERN_CONTROL,
1151 				OTG_TEST_PATTERN_EN, 1,
1152 				OTG_TEST_PATTERN_MODE, mode,
1153 				OTG_TEST_PATTERN_DYNAMIC_RANGE, 0,
1154 				OTG_TEST_PATTERN_COLOR_FORMAT, bit_depth);
1155 	}
1156 	break;
1157 
1158 	case CONTROLLER_DP_TEST_PATTERN_COLORRAMP:
1159 	{
1160 		mode = (bit_depth ==
1161 			TEST_PATTERN_COLOR_FORMAT_BPC_10 ?
1162 			TEST_PATTERN_MODE_DUALRAMP_RGB :
1163 			TEST_PATTERN_MODE_SINGLERAMP_RGB);
1164 
1165 		switch (bit_depth) {
1166 		case TEST_PATTERN_COLOR_FORMAT_BPC_6:
1167 			dst_bpc = 6;
1168 		break;
1169 		case TEST_PATTERN_COLOR_FORMAT_BPC_8:
1170 			dst_bpc = 8;
1171 		break;
1172 		case TEST_PATTERN_COLOR_FORMAT_BPC_10:
1173 			dst_bpc = 10;
1174 		break;
1175 		default:
1176 			dst_bpc = 8;
1177 		break;
1178 		}
1179 
1180 		/* increment for the first ramp for one color gradation
1181 		 * 1 gradation for 6-bit color is 2^10
1182 		 * gradations in 16-bit color
1183 		 */
1184 		inc_base = (src_bpc - dst_bpc);
1185 
1186 		switch (bit_depth) {
1187 		case TEST_PATTERN_COLOR_FORMAT_BPC_6:
1188 		{
1189 			REG_UPDATE_5(OTG_TEST_PATTERN_PARAMETERS,
1190 					OTG_TEST_PATTERN_INC0, inc_base,
1191 					OTG_TEST_PATTERN_INC1, 0,
1192 					OTG_TEST_PATTERN_HRES, 6,
1193 					OTG_TEST_PATTERN_VRES, 6,
1194 					OTG_TEST_PATTERN_RAMP0_OFFSET, 0);
1195 		}
1196 		break;
1197 		case TEST_PATTERN_COLOR_FORMAT_BPC_8:
1198 		{
1199 			REG_UPDATE_5(OTG_TEST_PATTERN_PARAMETERS,
1200 					OTG_TEST_PATTERN_INC0, inc_base,
1201 					OTG_TEST_PATTERN_INC1, 0,
1202 					OTG_TEST_PATTERN_HRES, 8,
1203 					OTG_TEST_PATTERN_VRES, 6,
1204 					OTG_TEST_PATTERN_RAMP0_OFFSET, 0);
1205 		}
1206 		break;
1207 		case TEST_PATTERN_COLOR_FORMAT_BPC_10:
1208 		{
1209 			REG_UPDATE_5(OTG_TEST_PATTERN_PARAMETERS,
1210 					OTG_TEST_PATTERN_INC0, inc_base,
1211 					OTG_TEST_PATTERN_INC1, inc_base + 2,
1212 					OTG_TEST_PATTERN_HRES, 8,
1213 					OTG_TEST_PATTERN_VRES, 5,
1214 					OTG_TEST_PATTERN_RAMP0_OFFSET, 384 << 6);
1215 		}
1216 		break;
1217 		default:
1218 		break;
1219 		}
1220 
1221 		REG_WRITE(OTG_TEST_PATTERN_COLOR, 0);
1222 
1223 		/* enable test pattern */
1224 		REG_WRITE(OTG_TEST_PATTERN_CONTROL, 0);
1225 
1226 		REG_SET_4(OTG_TEST_PATTERN_CONTROL, 0,
1227 				OTG_TEST_PATTERN_EN, 1,
1228 				OTG_TEST_PATTERN_MODE, mode,
1229 				OTG_TEST_PATTERN_DYNAMIC_RANGE, 0,
1230 				OTG_TEST_PATTERN_COLOR_FORMAT, bit_depth);
1231 	}
1232 	break;
1233 	case CONTROLLER_DP_TEST_PATTERN_VIDEOMODE:
1234 	{
1235 		REG_WRITE(OTG_TEST_PATTERN_CONTROL, 0);
1236 		REG_WRITE(OTG_TEST_PATTERN_COLOR, 0);
1237 		REG_WRITE(OTG_TEST_PATTERN_PARAMETERS, 0);
1238 	}
1239 	break;
1240 	default:
1241 		break;
1242 
1243 	}
1244 }
1245 
optc1_get_crtc_scanoutpos(struct timing_generator * optc,uint32_t * v_blank_start,uint32_t * v_blank_end,uint32_t * h_position,uint32_t * v_position)1246 void optc1_get_crtc_scanoutpos(
1247 	struct timing_generator *optc,
1248 	uint32_t *v_blank_start,
1249 	uint32_t *v_blank_end,
1250 	uint32_t *h_position,
1251 	uint32_t *v_position)
1252 {
1253 	struct optc *optc1 = DCN10TG_FROM_TG(optc);
1254 	struct crtc_position position;
1255 
1256 	REG_GET_2(OTG_V_BLANK_START_END,
1257 			OTG_V_BLANK_START, v_blank_start,
1258 			OTG_V_BLANK_END, v_blank_end);
1259 
1260 	optc1_get_position(optc, &position);
1261 
1262 	*h_position = position.horizontal_count;
1263 	*v_position = position.vertical_count;
1264 }
1265 
optc1_enable_stereo(struct timing_generator * optc,const struct dc_crtc_timing * timing,struct crtc_stereo_flags * flags)1266 static void optc1_enable_stereo(struct timing_generator *optc,
1267 	const struct dc_crtc_timing *timing, struct crtc_stereo_flags *flags)
1268 {
1269 	struct optc *optc1 = DCN10TG_FROM_TG(optc);
1270 
1271 	if (flags) {
1272 		uint32_t stereo_en;
1273 		stereo_en = flags->FRAME_PACKED == 0 ? 1 : 0;
1274 
1275 		if (flags->PROGRAM_STEREO)
1276 			REG_UPDATE_3(OTG_STEREO_CONTROL,
1277 				OTG_STEREO_EN, stereo_en,
1278 				OTG_STEREO_SYNC_OUTPUT_LINE_NUM, 0,
1279 				OTG_STEREO_SYNC_OUTPUT_POLARITY, flags->RIGHT_EYE_POLARITY == 0 ? 0 : 1);
1280 
1281 		if (flags->PROGRAM_POLARITY)
1282 			REG_UPDATE(OTG_STEREO_CONTROL,
1283 				OTG_STEREO_EYE_FLAG_POLARITY,
1284 				flags->RIGHT_EYE_POLARITY == 0 ? 0 : 1);
1285 
1286 		if (flags->DISABLE_STEREO_DP_SYNC)
1287 			REG_UPDATE(OTG_STEREO_CONTROL,
1288 				OTG_DISABLE_STEREOSYNC_OUTPUT_FOR_DP, 1);
1289 
1290 		if (flags->PROGRAM_STEREO)
1291 			REG_UPDATE_2(OTG_3D_STRUCTURE_CONTROL,
1292 				OTG_3D_STRUCTURE_EN, flags->FRAME_PACKED,
1293 				OTG_3D_STRUCTURE_STEREO_SEL_OVR, flags->FRAME_PACKED);
1294 
1295 	}
1296 }
1297 
optc1_program_stereo(struct timing_generator * optc,const struct dc_crtc_timing * timing,struct crtc_stereo_flags * flags)1298 void optc1_program_stereo(struct timing_generator *optc,
1299 	const struct dc_crtc_timing *timing, struct crtc_stereo_flags *flags)
1300 {
1301 	if (flags->PROGRAM_STEREO)
1302 		optc1_enable_stereo(optc, timing, flags);
1303 	else
1304 		optc1_disable_stereo(optc);
1305 }
1306 
1307 
optc1_is_stereo_left_eye(struct timing_generator * optc)1308 bool optc1_is_stereo_left_eye(struct timing_generator *optc)
1309 {
1310 	bool ret = false;
1311 	uint32_t left_eye = 0;
1312 	struct optc *optc1 = DCN10TG_FROM_TG(optc);
1313 
1314 	REG_GET(OTG_STEREO_STATUS,
1315 		OTG_STEREO_CURRENT_EYE, &left_eye);
1316 	if (left_eye == 1)
1317 		ret = true;
1318 	else
1319 		ret = false;
1320 
1321 	return ret;
1322 }
1323 
optc1_get_hw_timing(struct timing_generator * tg,struct dc_crtc_timing * hw_crtc_timing)1324 bool optc1_get_hw_timing(struct timing_generator *tg,
1325 		struct dc_crtc_timing *hw_crtc_timing)
1326 {
1327 	struct dcn_otg_state s = {0};
1328 
1329 	if (tg == NULL || hw_crtc_timing == NULL)
1330 		return false;
1331 
1332 	optc1_read_otg_state(DCN10TG_FROM_TG(tg), &s);
1333 
1334 	hw_crtc_timing->h_total = s.h_total + 1;
1335 	hw_crtc_timing->h_addressable = s.h_total - ((s.h_total - s.h_blank_start) + s.h_blank_end);
1336 	hw_crtc_timing->h_front_porch = s.h_total + 1 - s.h_blank_start;
1337 	hw_crtc_timing->h_sync_width = s.h_sync_a_end - s.h_sync_a_start;
1338 
1339 	hw_crtc_timing->v_total = s.v_total + 1;
1340 	hw_crtc_timing->v_addressable = s.v_total - ((s.v_total - s.v_blank_start) + s.v_blank_end);
1341 	hw_crtc_timing->v_front_porch = s.v_total + 1 - s.v_blank_start;
1342 	hw_crtc_timing->v_sync_width = s.v_sync_a_end - s.v_sync_a_start;
1343 
1344 	return true;
1345 }
1346 
1347 
optc1_read_otg_state(struct optc * optc1,struct dcn_otg_state * s)1348 void optc1_read_otg_state(struct optc *optc1,
1349 		struct dcn_otg_state *s)
1350 {
1351 	REG_GET(OTG_CONTROL,
1352 			OTG_MASTER_EN, &s->otg_enabled);
1353 
1354 	REG_GET_2(OTG_V_BLANK_START_END,
1355 			OTG_V_BLANK_START, &s->v_blank_start,
1356 			OTG_V_BLANK_END, &s->v_blank_end);
1357 
1358 	REG_GET(OTG_V_SYNC_A_CNTL,
1359 			OTG_V_SYNC_A_POL, &s->v_sync_a_pol);
1360 
1361 	REG_GET(OTG_V_TOTAL,
1362 			OTG_V_TOTAL, &s->v_total);
1363 
1364 	REG_GET(OTG_V_TOTAL_MAX,
1365 			OTG_V_TOTAL_MAX, &s->v_total_max);
1366 
1367 	REG_GET(OTG_V_TOTAL_MIN,
1368 			OTG_V_TOTAL_MIN, &s->v_total_min);
1369 
1370 	REG_GET(OTG_V_TOTAL_CONTROL,
1371 			OTG_V_TOTAL_MAX_SEL, &s->v_total_max_sel);
1372 
1373 	REG_GET(OTG_V_TOTAL_CONTROL,
1374 			OTG_V_TOTAL_MIN_SEL, &s->v_total_min_sel);
1375 
1376 	REG_GET_2(OTG_V_SYNC_A,
1377 			OTG_V_SYNC_A_START, &s->v_sync_a_start,
1378 			OTG_V_SYNC_A_END, &s->v_sync_a_end);
1379 
1380 	REG_GET_2(OTG_H_BLANK_START_END,
1381 			OTG_H_BLANK_START, &s->h_blank_start,
1382 			OTG_H_BLANK_END, &s->h_blank_end);
1383 
1384 	REG_GET_2(OTG_H_SYNC_A,
1385 			OTG_H_SYNC_A_START, &s->h_sync_a_start,
1386 			OTG_H_SYNC_A_END, &s->h_sync_a_end);
1387 
1388 	REG_GET(OTG_H_SYNC_A_CNTL,
1389 			OTG_H_SYNC_A_POL, &s->h_sync_a_pol);
1390 
1391 	REG_GET(OTG_H_TOTAL,
1392 			OTG_H_TOTAL, &s->h_total);
1393 
1394 	REG_GET(OPTC_INPUT_GLOBAL_CONTROL,
1395 			OPTC_UNDERFLOW_OCCURRED_STATUS, &s->underflow_occurred_status);
1396 
1397 	REG_GET(OTG_VERTICAL_INTERRUPT2_CONTROL,
1398 			OTG_VERTICAL_INTERRUPT2_INT_ENABLE, &s->vertical_interrupt2_en);
1399 
1400 	REG_GET(OTG_VERTICAL_INTERRUPT2_POSITION,
1401 			OTG_VERTICAL_INTERRUPT2_LINE_START, &s->vertical_interrupt2_line);
1402 }
1403 
optc1_get_otg_active_size(struct timing_generator * optc,uint32_t * otg_active_width,uint32_t * otg_active_height)1404 bool optc1_get_otg_active_size(struct timing_generator *optc,
1405 		uint32_t *otg_active_width,
1406 		uint32_t *otg_active_height)
1407 {
1408 	uint32_t otg_enabled;
1409 	uint32_t v_blank_start;
1410 	uint32_t v_blank_end;
1411 	uint32_t h_blank_start;
1412 	uint32_t h_blank_end;
1413 	struct optc *optc1 = DCN10TG_FROM_TG(optc);
1414 
1415 
1416 	REG_GET(OTG_CONTROL,
1417 			OTG_MASTER_EN, &otg_enabled);
1418 
1419 	if (otg_enabled == 0)
1420 		return false;
1421 
1422 	REG_GET_2(OTG_V_BLANK_START_END,
1423 			OTG_V_BLANK_START, &v_blank_start,
1424 			OTG_V_BLANK_END, &v_blank_end);
1425 
1426 	REG_GET_2(OTG_H_BLANK_START_END,
1427 			OTG_H_BLANK_START, &h_blank_start,
1428 			OTG_H_BLANK_END, &h_blank_end);
1429 
1430 	*otg_active_width = v_blank_start - v_blank_end;
1431 	*otg_active_height = h_blank_start - h_blank_end;
1432 	return true;
1433 }
1434 
optc1_clear_optc_underflow(struct timing_generator * optc)1435 void optc1_clear_optc_underflow(struct timing_generator *optc)
1436 {
1437 	struct optc *optc1 = DCN10TG_FROM_TG(optc);
1438 
1439 	REG_UPDATE(OPTC_INPUT_GLOBAL_CONTROL, OPTC_UNDERFLOW_CLEAR, 1);
1440 }
1441 
optc1_tg_init(struct timing_generator * optc)1442 void optc1_tg_init(struct timing_generator *optc)
1443 {
1444 	optc1_set_blank_data_double_buffer(optc, true);
1445 	optc1_set_timing_double_buffer(optc, true);
1446 	optc1_clear_optc_underflow(optc);
1447 }
1448 
optc1_is_tg_enabled(struct timing_generator * optc)1449 bool optc1_is_tg_enabled(struct timing_generator *optc)
1450 {
1451 	struct optc *optc1 = DCN10TG_FROM_TG(optc);
1452 	uint32_t otg_enabled = 0;
1453 
1454 	REG_GET(OTG_CONTROL, OTG_MASTER_EN, &otg_enabled);
1455 
1456 	return (otg_enabled != 0);
1457 
1458 }
1459 
optc1_is_optc_underflow_occurred(struct timing_generator * optc)1460 bool optc1_is_optc_underflow_occurred(struct timing_generator *optc)
1461 {
1462 	struct optc *optc1 = DCN10TG_FROM_TG(optc);
1463 	uint32_t underflow_occurred = 0;
1464 
1465 	REG_GET(OPTC_INPUT_GLOBAL_CONTROL,
1466 			OPTC_UNDERFLOW_OCCURRED_STATUS,
1467 			&underflow_occurred);
1468 
1469 	return (underflow_occurred == 1);
1470 }
1471 
optc1_configure_crc(struct timing_generator * optc,const struct crc_params * params)1472 bool optc1_configure_crc(struct timing_generator *optc,
1473 			  const struct crc_params *params)
1474 {
1475 	struct optc *optc1 = DCN10TG_FROM_TG(optc);
1476 
1477 	/* Cannot configure crc on a CRTC that is disabled */
1478 	if (!optc1_is_tg_enabled(optc))
1479 		return false;
1480 
1481 	REG_WRITE(OTG_CRC_CNTL, 0);
1482 
1483 	if (!params->enable)
1484 		return true;
1485 
1486 	/* Program frame boundaries */
1487 	/* Window A x axis start and end. */
1488 	REG_UPDATE_2(OTG_CRC0_WINDOWA_X_CONTROL,
1489 			OTG_CRC0_WINDOWA_X_START, params->windowa_x_start,
1490 			OTG_CRC0_WINDOWA_X_END, params->windowa_x_end);
1491 
1492 	/* Window A y axis start and end. */
1493 	REG_UPDATE_2(OTG_CRC0_WINDOWA_Y_CONTROL,
1494 			OTG_CRC0_WINDOWA_Y_START, params->windowa_y_start,
1495 			OTG_CRC0_WINDOWA_Y_END, params->windowa_y_end);
1496 
1497 	/* Window B x axis start and end. */
1498 	REG_UPDATE_2(OTG_CRC0_WINDOWB_X_CONTROL,
1499 			OTG_CRC0_WINDOWB_X_START, params->windowb_x_start,
1500 			OTG_CRC0_WINDOWB_X_END, params->windowb_x_end);
1501 
1502 	/* Window B y axis start and end. */
1503 	REG_UPDATE_2(OTG_CRC0_WINDOWB_Y_CONTROL,
1504 			OTG_CRC0_WINDOWB_Y_START, params->windowb_y_start,
1505 			OTG_CRC0_WINDOWB_Y_END, params->windowb_y_end);
1506 
1507 	/* Set crc mode and selection, and enable. Only using CRC0*/
1508 	REG_UPDATE_3(OTG_CRC_CNTL,
1509 			OTG_CRC_CONT_EN, params->continuous_mode ? 1 : 0,
1510 			OTG_CRC0_SELECT, params->selection,
1511 			OTG_CRC_EN, 1);
1512 
1513 	return true;
1514 }
1515 
optc1_get_crc(struct timing_generator * optc,uint32_t * r_cr,uint32_t * g_y,uint32_t * b_cb)1516 bool optc1_get_crc(struct timing_generator *optc,
1517 		    uint32_t *r_cr, uint32_t *g_y, uint32_t *b_cb)
1518 {
1519 	uint32_t field = 0;
1520 	struct optc *optc1 = DCN10TG_FROM_TG(optc);
1521 
1522 	REG_GET(OTG_CRC_CNTL, OTG_CRC_EN, &field);
1523 
1524 	/* Early return if CRC is not enabled for this CRTC */
1525 	if (!field)
1526 		return false;
1527 
1528 	REG_GET_2(OTG_CRC0_DATA_RG,
1529 			CRC0_R_CR, r_cr,
1530 			CRC0_G_Y, g_y);
1531 
1532 	REG_GET(OTG_CRC0_DATA_B,
1533 			CRC0_B_CB, b_cb);
1534 
1535 	return true;
1536 }
1537 
1538 static const struct timing_generator_funcs dcn10_tg_funcs = {
1539 		.validate_timing = optc1_validate_timing,
1540 		.program_timing = optc1_program_timing,
1541 		.setup_vertical_interrupt0 = optc1_setup_vertical_interrupt0,
1542 		.setup_vertical_interrupt1 = optc1_setup_vertical_interrupt1,
1543 		.setup_vertical_interrupt2 = optc1_setup_vertical_interrupt2,
1544 		.program_global_sync = optc1_program_global_sync,
1545 		.enable_crtc = optc1_enable_crtc,
1546 		.disable_crtc = optc1_disable_crtc,
1547 		/* used by enable_timing_synchronization. Not need for FPGA */
1548 		.is_counter_moving = optc1_is_counter_moving,
1549 		.get_position = optc1_get_position,
1550 		.get_frame_count = optc1_get_vblank_counter,
1551 		.get_scanoutpos = optc1_get_crtc_scanoutpos,
1552 		.get_otg_active_size = optc1_get_otg_active_size,
1553 		.set_early_control = optc1_set_early_control,
1554 		/* used by enable_timing_synchronization. Not need for FPGA */
1555 		.wait_for_state = optc1_wait_for_state,
1556 		.set_blank = optc1_set_blank,
1557 		.is_blanked = optc1_is_blanked,
1558 		.set_blank_color = optc1_program_blank_color,
1559 		.did_triggered_reset_occur = optc1_did_triggered_reset_occur,
1560 		.enable_reset_trigger = optc1_enable_reset_trigger,
1561 		.enable_crtc_reset = optc1_enable_crtc_reset,
1562 		.disable_reset_trigger = optc1_disable_reset_trigger,
1563 		.lock = optc1_lock,
1564 		.is_locked = optc1_is_locked,
1565 		.unlock = optc1_unlock,
1566 		.enable_optc_clock = optc1_enable_optc_clock,
1567 		.set_drr = optc1_set_drr,
1568 		.get_last_used_drr_vtotal = NULL,
1569 		.set_static_screen_control = optc1_set_static_screen_control,
1570 		.set_test_pattern = optc1_set_test_pattern,
1571 		.program_stereo = optc1_program_stereo,
1572 		.is_stereo_left_eye = optc1_is_stereo_left_eye,
1573 		.set_blank_data_double_buffer = optc1_set_blank_data_double_buffer,
1574 		.tg_init = optc1_tg_init,
1575 		.is_tg_enabled = optc1_is_tg_enabled,
1576 		.is_optc_underflow_occurred = optc1_is_optc_underflow_occurred,
1577 		.clear_optc_underflow = optc1_clear_optc_underflow,
1578 		.get_crc = optc1_get_crc,
1579 		.configure_crc = optc1_configure_crc,
1580 		.set_vtg_params = optc1_set_vtg_params,
1581 		.program_manual_trigger = optc1_program_manual_trigger,
1582 		.setup_manual_trigger = optc1_setup_manual_trigger,
1583 		.get_hw_timing = optc1_get_hw_timing,
1584 };
1585 
dcn10_timing_generator_init(struct optc * optc1)1586 void dcn10_timing_generator_init(struct optc *optc1)
1587 {
1588 	optc1->base.funcs = &dcn10_tg_funcs;
1589 
1590 	optc1->max_h_total = optc1->tg_mask->OTG_H_TOTAL + 1;
1591 	optc1->max_v_total = optc1->tg_mask->OTG_V_TOTAL + 1;
1592 
1593 	optc1->min_h_blank = 32;
1594 	optc1->min_v_blank = 3;
1595 	optc1->min_v_blank_interlace = 5;
1596 	optc1->min_h_sync_width = 4;
1597 	optc1->min_v_sync_width = 1;
1598 }
1599 
1600 /* "Containter" vs. "pixel" is a concept within HW blocks, mostly those closer to the back-end. It works like this:
1601  *
1602  * - In most of the formats (RGB or YCbCr 4:4:4, 4:2:2 uncompressed and DSC 4:2:2 Simple) pixel rate is the same as
1603  *   containter rate.
1604  *
1605  * - In 4:2:0 (DSC or uncompressed) there are two pixels per container, hence the target container rate has to be
1606  *   halved to maintain the correct pixel rate.
1607  *
1608  * - Unlike 4:2:2 uncompressed, DSC 4:2:2 Native also has two pixels per container (this happens when DSC is applied
1609  *   to it) and has to be treated the same as 4:2:0, i.e. target containter rate has to be halved in this case as well.
1610  *
1611  */
optc1_is_two_pixels_per_containter(const struct dc_crtc_timing * timing)1612 bool optc1_is_two_pixels_per_containter(const struct dc_crtc_timing *timing)
1613 {
1614 	bool two_pix = timing->pixel_encoding == PIXEL_ENCODING_YCBCR420;
1615 
1616 	two_pix = two_pix || (timing->flags.DSC && timing->pixel_encoding == PIXEL_ENCODING_YCBCR422
1617 			&& !timing->dsc_cfg.ycbcr422_simple);
1618 	return two_pix;
1619 }
1620 
1621