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