2 * Copyright 2012-15 Advanced Micro Devices, Inc.
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:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
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.
27 #include "reg_helper.h"
28 #include "dcn10_optc.h"
38 #define FN(reg_name, field_name) \
39 optc1->tg_shift->field_name, optc1->tg_mask->field_name
41 #define STATIC_SCREEN_EVENT_MASK_RANGETIMING_DOUBLE_BUFFER_UPDATE_EN 0x100
44 * apply_front_porch_workaround TODO FPGA still need?
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.
49 static void apply_front_porch_workaround(struct dc_crtc_timing *timing)
51 if (timing->flags.INTERLACE == 1) {
52 if (timing->v_front_porch < 2)
53 timing->v_front_porch = 2;
55 if (timing->v_front_porch < 1)
56 timing->v_front_porch = 1;
60 void optc1_program_global_sync(
61 struct timing_generator *optc,
67 struct optc *optc1 = DCN10TG_FROM_TG(optc);
69 optc1->vready_offset = vready_offset;
70 optc1->vstartup_start = vstartup_start;
71 optc1->vupdate_offset = vupdate_offset;
72 optc1->vupdate_width = vupdate_width;
74 if (optc1->vstartup_start == 0) {
79 REG_SET(OTG_VSTARTUP_PARAM, 0,
80 VSTARTUP_START, optc1->vstartup_start);
82 REG_SET_2(OTG_VUPDATE_PARAM, 0,
83 VUPDATE_OFFSET, optc1->vupdate_offset,
84 VUPDATE_WIDTH, optc1->vupdate_width);
86 REG_SET(OTG_VREADY_PARAM, 0,
87 VREADY_OFFSET, optc1->vready_offset);
90 static void optc1_disable_stereo(struct timing_generator *optc)
92 struct optc *optc1 = DCN10TG_FROM_TG(optc);
94 REG_SET(OTG_STEREO_CONTROL, 0,
97 REG_SET_2(OTG_3D_STRUCTURE_CONTROL, 0,
98 OTG_3D_STRUCTURE_EN, 0,
99 OTG_3D_STRUCTURE_STEREO_SEL_OVR, 0);
102 void optc1_setup_vertical_interrupt0(
103 struct timing_generator *optc,
107 struct optc *optc1 = DCN10TG_FROM_TG(optc);
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);
114 void optc1_setup_vertical_interrupt1(
115 struct timing_generator *optc,
118 struct optc *optc1 = DCN10TG_FROM_TG(optc);
120 REG_SET(OTG_VERTICAL_INTERRUPT1_POSITION, 0,
121 OTG_VERTICAL_INTERRUPT1_LINE_START, start_line);
124 void optc1_setup_vertical_interrupt2(
125 struct timing_generator *optc,
128 struct optc *optc1 = DCN10TG_FROM_TG(optc);
130 REG_SET(OTG_VERTICAL_INTERRUPT2_POSITION, 0,
131 OTG_VERTICAL_INTERRUPT2_LINE_START, start_line);
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.
139 void optc1_program_timing(
140 struct timing_generator *optc,
141 const struct dc_crtc_timing *dc_crtc_timing,
146 const enum signal_type signal,
149 struct dc_crtc_timing patched_crtc_timing;
150 uint32_t asic_blank_end;
151 uint32_t asic_blank_start;
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;
159 struct optc *optc1 = DCN10TG_FROM_TG(optc);
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 optc1->orginal_patched_timing = patched_crtc_timing;
170 /* Load horizontal timing */
172 /* CRTC_H_TOTAL = vesa.h_total - 1 */
173 REG_SET(OTG_H_TOTAL, 0,
174 OTG_H_TOTAL, patched_crtc_timing.h_total - 1);
176 /* h_sync_start = 0, h_sync_end = vesa.h_sync_width */
177 REG_UPDATE_2(OTG_H_SYNC_A,
178 OTG_H_SYNC_A_START, 0,
179 OTG_H_SYNC_A_END, patched_crtc_timing.h_sync_width);
181 /* blank_start = line end - front porch */
182 asic_blank_start = patched_crtc_timing.h_total -
183 patched_crtc_timing.h_front_porch;
185 /* blank_end = blank_start - active */
186 asic_blank_end = asic_blank_start -
187 patched_crtc_timing.h_border_right -
188 patched_crtc_timing.h_addressable -
189 patched_crtc_timing.h_border_left;
191 REG_UPDATE_2(OTG_H_BLANK_START_END,
192 OTG_H_BLANK_START, asic_blank_start,
193 OTG_H_BLANK_END, asic_blank_end);
195 /* h_sync polarity */
196 h_sync_polarity = patched_crtc_timing.flags.HSYNC_POSITIVE_POLARITY ?
199 REG_UPDATE(OTG_H_SYNC_A_CNTL,
200 OTG_H_SYNC_A_POL, h_sync_polarity);
202 v_total = patched_crtc_timing.v_total - 1;
204 REG_SET(OTG_V_TOTAL, 0,
205 OTG_V_TOTAL, v_total);
207 /* In case of V_TOTAL_CONTROL is on, make sure OTG_V_TOTAL_MAX and
208 * OTG_V_TOTAL_MIN are equal to V_TOTAL.
210 REG_SET(OTG_V_TOTAL_MAX, 0,
211 OTG_V_TOTAL_MAX, v_total);
212 REG_SET(OTG_V_TOTAL_MIN, 0,
213 OTG_V_TOTAL_MIN, v_total);
215 /* v_sync_start = 0, v_sync_end = v_sync_width */
216 v_sync_end = patched_crtc_timing.v_sync_width;
218 REG_UPDATE_2(OTG_V_SYNC_A,
219 OTG_V_SYNC_A_START, 0,
220 OTG_V_SYNC_A_END, v_sync_end);
222 /* blank_start = frame end - front porch */
223 asic_blank_start = patched_crtc_timing.v_total -
224 patched_crtc_timing.v_front_porch;
226 /* blank_end = blank_start - active */
227 asic_blank_end = asic_blank_start -
228 patched_crtc_timing.v_border_bottom -
229 patched_crtc_timing.v_addressable -
230 patched_crtc_timing.v_border_top;
232 REG_UPDATE_2(OTG_V_BLANK_START_END,
233 OTG_V_BLANK_START, asic_blank_start,
234 OTG_V_BLANK_END, asic_blank_end);
236 /* v_sync polarity */
237 v_sync_polarity = patched_crtc_timing.flags.VSYNC_POSITIVE_POLARITY ?
240 REG_UPDATE(OTG_V_SYNC_A_CNTL,
241 OTG_V_SYNC_A_POL, v_sync_polarity);
243 if (optc1->signal == SIGNAL_TYPE_DISPLAY_PORT ||
244 optc1->signal == SIGNAL_TYPE_DISPLAY_PORT_MST ||
245 optc1->signal == SIGNAL_TYPE_EDP) {
247 if (patched_crtc_timing.flags.INTERLACE == 1)
252 if (REG(OTG_INTERLACE_CONTROL)) {
253 if (patched_crtc_timing.flags.INTERLACE == 1)
254 REG_UPDATE(OTG_INTERLACE_CONTROL,
255 OTG_INTERLACE_ENABLE, 1);
257 REG_UPDATE(OTG_INTERLACE_CONTROL,
258 OTG_INTERLACE_ENABLE, 0);
261 /* VTG enable set to 0 first VInit */
265 /* original code is using VTG offset to address OTG reg, seems wrong */
266 REG_UPDATE_2(OTG_CONTROL,
267 OTG_START_POINT_CNTL, start_point,
268 OTG_FIELD_NUMBER_CNTL, field_num);
270 optc->funcs->program_global_sync(optc,
276 optc->funcs->set_vtg_params(optc, dc_crtc_timing, true);
279 * patched_crtc_timing.flags.HORZ_COUNT_BY_TWO == 1
280 * program_horz_count_by_2
281 * for DVI 30bpp mode, 0 otherwise
282 * program_horz_count_by_2(optc, &patched_crtc_timing);
285 /* Enable stereo - only when we need to pack 3D frame. Other types
286 * of stereo handled in explicit call
289 if (optc1_is_two_pixels_per_containter(&patched_crtc_timing) || optc1->opp_count == 2)
290 h_div = H_TIMING_DIV_BY2;
292 if (REG(OPTC_DATA_FORMAT_CONTROL) && optc1->tg_mask->OPTC_DATA_FORMAT != 0) {
293 uint32_t data_fmt = 0;
295 if (patched_crtc_timing.pixel_encoding == PIXEL_ENCODING_YCBCR422)
297 else if (patched_crtc_timing.pixel_encoding == PIXEL_ENCODING_YCBCR420)
300 REG_UPDATE(OPTC_DATA_FORMAT_CONTROL, OPTC_DATA_FORMAT, data_fmt);
303 if (optc1->tg_mask->OTG_H_TIMING_DIV_MODE != 0) {
304 if (optc1->opp_count == 4)
305 h_div = H_TIMING_DIV_BY4;
307 REG_UPDATE(OTG_H_TIMING_CNTL,
308 OTG_H_TIMING_DIV_MODE, h_div);
310 REG_UPDATE(OTG_H_TIMING_CNTL,
311 OTG_H_TIMING_DIV_BY2, h_div);
315 void optc1_set_vtg_params(struct timing_generator *optc,
316 const struct dc_crtc_timing *dc_crtc_timing, bool program_fp2)
318 struct dc_crtc_timing patched_crtc_timing;
319 uint32_t asic_blank_end;
322 int32_t vertical_line_start;
324 struct optc *optc1 = DCN10TG_FROM_TG(optc);
326 patched_crtc_timing = *dc_crtc_timing;
327 apply_front_porch_workaround(&patched_crtc_timing);
329 /* VCOUNT_INIT is the start of blank */
330 v_init = patched_crtc_timing.v_total - patched_crtc_timing.v_front_porch;
332 /* end of blank = v_init - active */
333 asic_blank_end = v_init -
334 patched_crtc_timing.v_border_bottom -
335 patched_crtc_timing.v_addressable -
336 patched_crtc_timing.v_border_top;
338 /* if VSTARTUP is before VSYNC, FP2 is the offset, otherwise 0 */
339 vertical_line_start = asic_blank_end - optc1->vstartup_start + 1;
340 if (vertical_line_start < 0)
341 v_fp2 = -vertical_line_start;
344 if (REG(OTG_INTERLACE_CONTROL)) {
345 if (patched_crtc_timing.flags.INTERLACE == 1) {
347 if ((optc1->vstartup_start/2)*2 > asic_blank_end)
353 REG_UPDATE_2(CONTROL,
355 VTG0_VCOUNT_INIT, v_init);
357 REG_UPDATE(CONTROL, VTG0_VCOUNT_INIT, v_init);
360 void optc1_set_blank_data_double_buffer(struct timing_generator *optc, bool enable)
362 struct optc *optc1 = DCN10TG_FROM_TG(optc);
364 uint32_t blank_data_double_buffer_enable = enable ? 1 : 0;
366 REG_UPDATE(OTG_DOUBLE_BUFFER_CONTROL,
367 OTG_BLANK_DATA_DOUBLE_BUFFER_EN, blank_data_double_buffer_enable);
371 * optc1_set_timing_double_buffer() - DRR double buffering control
373 * Sets double buffer point for V_TOTAL, H_TOTAL, VTOTAL_MIN,
374 * VTOTAL_MAX, VTOTAL_MIN_SEL and VTOTAL_MAX_SEL registers.
376 * Options: any time, start of frame, dp start of frame (range timing)
378 void optc1_set_timing_double_buffer(struct timing_generator *optc, bool enable)
380 struct optc *optc1 = DCN10TG_FROM_TG(optc);
381 uint32_t mode = enable ? 2 : 0;
383 REG_UPDATE(OTG_DOUBLE_BUFFER_CONTROL,
384 OTG_RANGE_TIMING_DBUF_UPDATE_MODE, mode);
389 * Call ASIC Control Object to UnBlank CRTC.
391 static void optc1_unblank_crtc(struct timing_generator *optc)
393 struct optc *optc1 = DCN10TG_FROM_TG(optc);
395 REG_UPDATE_2(OTG_BLANK_CONTROL,
396 OTG_BLANK_DATA_EN, 0,
397 OTG_BLANK_DE_MODE, 0);
399 /* W/A for automated testing
400 * Automated testing will fail underflow test as there
401 * sporadic underflows which occur during the optc blank
402 * sequence. As a w/a, clear underflow on unblank.
403 * This prevents the failure, but will not mask actual
404 * underflow that affect real use cases.
406 optc1_clear_optc_underflow(optc);
411 * Call ASIC Control Object to Blank CRTC.
414 static void optc1_blank_crtc(struct timing_generator *optc)
416 struct optc *optc1 = DCN10TG_FROM_TG(optc);
418 REG_UPDATE_2(OTG_BLANK_CONTROL,
419 OTG_BLANK_DATA_EN, 1,
420 OTG_BLANK_DE_MODE, 0);
422 optc1_set_blank_data_double_buffer(optc, false);
425 void optc1_set_blank(struct timing_generator *optc,
426 bool enable_blanking)
429 optc1_blank_crtc(optc);
431 optc1_unblank_crtc(optc);
434 bool optc1_is_blanked(struct timing_generator *optc)
436 struct optc *optc1 = DCN10TG_FROM_TG(optc);
438 uint32_t blank_state;
440 REG_GET_2(OTG_BLANK_CONTROL,
441 OTG_BLANK_DATA_EN, &blank_en,
442 OTG_CURRENT_BLANK_STATE, &blank_state);
444 return blank_en && blank_state;
447 void optc1_enable_optc_clock(struct timing_generator *optc, bool enable)
449 struct optc *optc1 = DCN10TG_FROM_TG(optc);
452 REG_UPDATE_2(OPTC_INPUT_CLOCK_CONTROL,
453 OPTC_INPUT_CLK_EN, 1,
454 OPTC_INPUT_CLK_GATE_DIS, 1);
456 REG_WAIT(OPTC_INPUT_CLOCK_CONTROL,
457 OPTC_INPUT_CLK_ON, 1,
461 REG_UPDATE_2(OTG_CLOCK_CONTROL,
463 OTG_CLOCK_GATE_DIS, 1);
464 REG_WAIT(OTG_CLOCK_CONTROL,
469 //last chance to clear underflow, otherwise, it will always there due to clock is off.
470 if (optc->funcs->is_optc_underflow_occurred(optc) == true)
471 optc->funcs->clear_optc_underflow(optc);
473 REG_UPDATE_2(OTG_CLOCK_CONTROL,
474 OTG_CLOCK_GATE_DIS, 0,
477 REG_UPDATE_2(OPTC_INPUT_CLOCK_CONTROL,
478 OPTC_INPUT_CLK_GATE_DIS, 0,
479 OPTC_INPUT_CLK_EN, 0);
485 * Enable CRTC - call ASIC Control Object to enable Timing generator.
487 static bool optc1_enable_crtc(struct timing_generator *optc)
489 /* TODO FPGA wait for answer
490 * OTG_MASTER_UPDATE_MODE != CRTC_MASTER_UPDATE_MODE
491 * OTG_MASTER_UPDATE_LOCK != CRTC_MASTER_UPDATE_LOCK
493 struct optc *optc1 = DCN10TG_FROM_TG(optc);
495 /* opp instance for OTG. For DCN1.0, ODM is remoed.
496 * OPP and OPTC should 1:1 mapping
498 REG_UPDATE(OPTC_DATA_SOURCE_SELECT,
499 OPTC_SRC_SEL, optc->inst);
501 /* VTG enable first is for HW workaround */
508 REG_UPDATE_2(OTG_CONTROL,
509 OTG_DISABLE_POINT_CNTL, 3,
518 /* disable_crtc - call ASIC Control Object to disable Timing generator. */
519 bool optc1_disable_crtc(struct timing_generator *optc)
521 struct optc *optc1 = DCN10TG_FROM_TG(optc);
523 /* disable otg request until end of the first line
524 * in the vertical blank region
526 REG_UPDATE_2(OTG_CONTROL,
527 OTG_DISABLE_POINT_CNTL, 3,
533 /* CRTC disabled, so disable clock. */
534 REG_WAIT(OTG_CLOCK_CONTROL,
542 void optc1_program_blank_color(
543 struct timing_generator *optc,
544 const struct tg_color *black_color)
546 struct optc *optc1 = DCN10TG_FROM_TG(optc);
548 REG_SET_3(OTG_BLACK_COLOR, 0,
549 OTG_BLACK_COLOR_B_CB, black_color->color_b_cb,
550 OTG_BLACK_COLOR_G_Y, black_color->color_g_y,
551 OTG_BLACK_COLOR_R_CR, black_color->color_r_cr);
554 bool optc1_validate_timing(
555 struct timing_generator *optc,
556 const struct dc_crtc_timing *timing)
560 uint32_t min_v_blank;
561 struct optc *optc1 = DCN10TG_FROM_TG(optc);
563 ASSERT(timing != NULL);
565 v_blank = (timing->v_total - timing->v_addressable -
566 timing->v_border_top - timing->v_border_bottom);
568 h_blank = (timing->h_total - timing->h_addressable -
569 timing->h_border_right -
570 timing->h_border_left);
572 if (timing->timing_3d_format != TIMING_3D_FORMAT_NONE &&
573 timing->timing_3d_format != TIMING_3D_FORMAT_HW_FRAME_PACKING &&
574 timing->timing_3d_format != TIMING_3D_FORMAT_TOP_AND_BOTTOM &&
575 timing->timing_3d_format != TIMING_3D_FORMAT_SIDE_BY_SIDE &&
576 timing->timing_3d_format != TIMING_3D_FORMAT_FRAME_ALTERNATE &&
577 timing->timing_3d_format != TIMING_3D_FORMAT_INBAND_FA)
580 /* Temporarily blocking interlacing mode until it's supported */
581 if (timing->flags.INTERLACE == 1)
584 /* Check maximum number of pixels supported by Timing Generator
585 * (Currently will never fail, in order to fail needs display which
586 * needs more than 8192 horizontal and
587 * more than 8192 vertical total pixels)
589 if (timing->h_total > optc1->max_h_total ||
590 timing->v_total > optc1->max_v_total)
594 if (h_blank < optc1->min_h_blank)
597 if (timing->h_sync_width < optc1->min_h_sync_width ||
598 timing->v_sync_width < optc1->min_v_sync_width)
601 min_v_blank = timing->flags.INTERLACE?optc1->min_v_blank_interlace:optc1->min_v_blank;
603 if (v_blank < min_v_blank)
614 * Get counter for vertical blanks. use register CRTC_STATUS_FRAME_COUNT which
615 * holds the counter of frames.
618 * struct timing_generator *optc - [in] timing generator which controls the
622 * Counter of frames, which should equal to number of vblanks.
624 uint32_t optc1_get_vblank_counter(struct timing_generator *optc)
626 struct optc *optc1 = DCN10TG_FROM_TG(optc);
627 uint32_t frame_count;
629 REG_GET(OTG_STATUS_FRAME_COUNT,
630 OTG_FRAME_COUNT, &frame_count);
635 void optc1_lock(struct timing_generator *optc)
637 struct optc *optc1 = DCN10TG_FROM_TG(optc);
640 regval = REG_READ(OTG_CONTROL);
642 /* otg is not running, do not need to be locked */
643 if ((regval & 0x1) == 0x0)
646 REG_SET(OTG_GLOBAL_CONTROL0, 0,
647 OTG_MASTER_UPDATE_LOCK_SEL, optc->inst);
648 REG_SET(OTG_MASTER_UPDATE_LOCK, 0,
649 OTG_MASTER_UPDATE_LOCK, 1);
651 /* Should be fast, status does not update on maximus */
652 if (optc->ctx->dce_environment != DCE_ENV_FPGA_MAXIMUS) {
654 REG_WAIT(OTG_MASTER_UPDATE_LOCK,
655 UPDATE_LOCK_STATUS, 1,
660 void optc1_unlock(struct timing_generator *optc)
662 struct optc *optc1 = DCN10TG_FROM_TG(optc);
664 REG_SET(OTG_MASTER_UPDATE_LOCK, 0,
665 OTG_MASTER_UPDATE_LOCK, 0);
668 bool optc1_is_locked(struct timing_generator *optc)
670 struct optc *optc1 = DCN10TG_FROM_TG(optc);
673 REG_GET(OTG_MASTER_UPDATE_LOCK, UPDATE_LOCK_STATUS, &locked);
675 return (locked == 1);
678 void optc1_get_position(struct timing_generator *optc,
679 struct crtc_position *position)
681 struct optc *optc1 = DCN10TG_FROM_TG(optc);
683 REG_GET_2(OTG_STATUS_POSITION,
684 OTG_HORZ_COUNT, &position->horizontal_count,
685 OTG_VERT_COUNT, &position->vertical_count);
687 REG_GET(OTG_NOM_VERT_POSITION,
688 OTG_VERT_COUNT_NOM, &position->nominal_vcount);
691 bool optc1_is_counter_moving(struct timing_generator *optc)
693 struct crtc_position position1, position2;
695 optc->funcs->get_position(optc, &position1);
696 optc->funcs->get_position(optc, &position2);
698 if (position1.horizontal_count == position2.horizontal_count &&
699 position1.vertical_count == position2.vertical_count)
705 bool optc1_did_triggered_reset_occur(
706 struct timing_generator *optc)
708 struct optc *optc1 = DCN10TG_FROM_TG(optc);
709 uint32_t occurred_force, occurred_vsync;
711 REG_GET(OTG_FORCE_COUNT_NOW_CNTL,
712 OTG_FORCE_COUNT_NOW_OCCURRED, &occurred_force);
714 REG_GET(OTG_VERT_SYNC_CONTROL,
715 OTG_FORCE_VSYNC_NEXT_LINE_OCCURRED, &occurred_vsync);
717 return occurred_vsync != 0 || occurred_force != 0;
720 void optc1_disable_reset_trigger(struct timing_generator *optc)
722 struct optc *optc1 = DCN10TG_FROM_TG(optc);
724 REG_WRITE(OTG_TRIGA_CNTL, 0);
726 REG_SET(OTG_FORCE_COUNT_NOW_CNTL, 0,
727 OTG_FORCE_COUNT_NOW_CLEAR, 1);
729 REG_SET(OTG_VERT_SYNC_CONTROL, 0,
730 OTG_FORCE_VSYNC_NEXT_LINE_CLEAR, 1);
733 void optc1_enable_reset_trigger(struct timing_generator *optc, int source_tg_inst)
735 struct optc *optc1 = DCN10TG_FROM_TG(optc);
736 uint32_t falling_edge;
738 REG_GET(OTG_V_SYNC_A_CNTL,
739 OTG_V_SYNC_A_POL, &falling_edge);
742 REG_SET_3(OTG_TRIGA_CNTL, 0,
743 /* vsync signal from selected OTG pipe based
744 * on OTG_TRIG_SOURCE_PIPE_SELECT setting
746 OTG_TRIGA_SOURCE_SELECT, 20,
747 OTG_TRIGA_SOURCE_PIPE_SELECT, source_tg_inst,
748 /* always detect falling edge */
749 OTG_TRIGA_FALLING_EDGE_DETECT_CNTL, 1);
751 REG_SET_3(OTG_TRIGA_CNTL, 0,
752 /* vsync signal from selected OTG pipe based
753 * on OTG_TRIG_SOURCE_PIPE_SELECT setting
755 OTG_TRIGA_SOURCE_SELECT, 20,
756 OTG_TRIGA_SOURCE_PIPE_SELECT, source_tg_inst,
757 /* always detect rising edge */
758 OTG_TRIGA_RISING_EDGE_DETECT_CNTL, 1);
760 REG_SET(OTG_FORCE_COUNT_NOW_CNTL, 0,
761 /* force H count to H_TOTAL and V count to V_TOTAL in
762 * progressive mode and V_TOTAL-1 in interlaced mode
764 OTG_FORCE_COUNT_NOW_MODE, 2);
767 void optc1_enable_crtc_reset(
768 struct timing_generator *optc,
770 struct crtc_trigger_info *crtc_tp)
772 struct optc *optc1 = DCN10TG_FROM_TG(optc);
773 uint32_t falling_edge = 0;
774 uint32_t rising_edge = 0;
776 switch (crtc_tp->event) {
778 case CRTC_EVENT_VSYNC_RISING:
782 case CRTC_EVENT_VSYNC_FALLING:
787 REG_SET_4(OTG_TRIGA_CNTL, 0,
788 /* vsync signal from selected OTG pipe based
789 * on OTG_TRIG_SOURCE_PIPE_SELECT setting
791 OTG_TRIGA_SOURCE_SELECT, 20,
792 OTG_TRIGA_SOURCE_PIPE_SELECT, source_tg_inst,
793 /* always detect falling edge */
794 OTG_TRIGA_RISING_EDGE_DETECT_CNTL, rising_edge,
795 OTG_TRIGA_FALLING_EDGE_DETECT_CNTL, falling_edge);
797 switch (crtc_tp->delay) {
798 case TRIGGER_DELAY_NEXT_LINE:
799 REG_SET(OTG_VERT_SYNC_CONTROL, 0,
800 OTG_AUTO_FORCE_VSYNC_MODE, 1);
802 case TRIGGER_DELAY_NEXT_PIXEL:
803 REG_SET(OTG_FORCE_COUNT_NOW_CNTL, 0,
804 /* force H count to H_TOTAL and V count to V_TOTAL in
805 * progressive mode and V_TOTAL-1 in interlaced mode
807 OTG_FORCE_COUNT_NOW_MODE, 2);
812 void optc1_wait_for_state(struct timing_generator *optc,
813 enum crtc_state state)
815 struct optc *optc1 = DCN10TG_FROM_TG(optc);
818 case CRTC_STATE_VBLANK:
821 1, 100000); /* 1 vupdate at 10hz */
824 case CRTC_STATE_VACTIVE:
826 OTG_V_ACTIVE_DISP, 1,
827 1, 100000); /* 1 vupdate at 10hz */
835 void optc1_set_early_control(
836 struct timing_generator *optc,
839 /* asic design change, do not need this control
840 * empty for share caller logic
845 void optc1_set_static_screen_control(
846 struct timing_generator *optc,
847 uint32_t event_triggers,
850 struct optc *optc1 = DCN10TG_FROM_TG(optc);
852 // By register spec, it only takes 8 bit value
853 if (num_frames > 0xFF)
856 /* Bit 8 is no longer applicable in RV for PSR case,
857 * set bit 8 to 0 if given
859 if ((event_triggers & STATIC_SCREEN_EVENT_MASK_RANGETIMING_DOUBLE_BUFFER_UPDATE_EN)
861 event_triggers = event_triggers &
862 ~STATIC_SCREEN_EVENT_MASK_RANGETIMING_DOUBLE_BUFFER_UPDATE_EN;
864 REG_SET_2(OTG_STATIC_SCREEN_CONTROL, 0,
865 OTG_STATIC_SCREEN_EVENT_MASK, event_triggers,
866 OTG_STATIC_SCREEN_FRAME_COUNT, num_frames);
869 static void optc1_setup_manual_trigger(struct timing_generator *optc)
871 struct optc *optc1 = DCN10TG_FROM_TG(optc);
873 REG_SET(OTG_GLOBAL_CONTROL2, 0,
874 MANUAL_FLOW_CONTROL_SEL, optc->inst);
876 REG_SET_8(OTG_TRIGA_CNTL, 0,
877 OTG_TRIGA_SOURCE_SELECT, 22,
878 OTG_TRIGA_SOURCE_PIPE_SELECT, optc->inst,
879 OTG_TRIGA_RISING_EDGE_DETECT_CNTL, 1,
880 OTG_TRIGA_FALLING_EDGE_DETECT_CNTL, 0,
881 OTG_TRIGA_POLARITY_SELECT, 0,
882 OTG_TRIGA_FREQUENCY_SELECT, 0,
887 static void optc1_program_manual_trigger(struct timing_generator *optc)
889 struct optc *optc1 = DCN10TG_FROM_TG(optc);
891 REG_SET(OTG_MANUAL_FLOW_CONTROL, 0,
892 MANUAL_FLOW_CONTROL, 1);
894 REG_SET(OTG_MANUAL_FLOW_CONTROL, 0,
895 MANUAL_FLOW_CONTROL, 0);
900 *****************************************************************************
904 * Program dynamic refresh rate registers m_OTGx_OTG_V_TOTAL_*.
906 *****************************************************************************
909 struct timing_generator *optc,
910 const struct drr_params *params)
912 struct optc *optc1 = DCN10TG_FROM_TG(optc);
914 if (params != NULL &&
915 params->vertical_total_max > 0 &&
916 params->vertical_total_min > 0) {
918 if (params->vertical_total_mid != 0) {
920 REG_SET(OTG_V_TOTAL_MID, 0,
921 OTG_V_TOTAL_MID, params->vertical_total_mid - 1);
923 REG_UPDATE_2(OTG_V_TOTAL_CONTROL,
924 OTG_VTOTAL_MID_REPLACING_MAX_EN, 1,
925 OTG_VTOTAL_MID_FRAME_NUM,
926 (uint8_t)params->vertical_total_mid_frame_num);
930 REG_SET(OTG_V_TOTAL_MAX, 0,
931 OTG_V_TOTAL_MAX, params->vertical_total_max - 1);
933 REG_SET(OTG_V_TOTAL_MIN, 0,
934 OTG_V_TOTAL_MIN, params->vertical_total_min - 1);
936 REG_UPDATE_5(OTG_V_TOTAL_CONTROL,
937 OTG_V_TOTAL_MIN_SEL, 1,
938 OTG_V_TOTAL_MAX_SEL, 1,
939 OTG_FORCE_LOCK_ON_EVENT, 0,
940 OTG_SET_V_TOTAL_MIN_MASK_EN, 0,
941 OTG_SET_V_TOTAL_MIN_MASK, 0);
943 // Setup manual flow control for EOF via TRIG_A
944 optc->funcs->setup_manual_trigger(optc);
947 REG_UPDATE_4(OTG_V_TOTAL_CONTROL,
948 OTG_SET_V_TOTAL_MIN_MASK, 0,
949 OTG_V_TOTAL_MIN_SEL, 0,
950 OTG_V_TOTAL_MAX_SEL, 0,
951 OTG_FORCE_LOCK_ON_EVENT, 0);
953 REG_SET(OTG_V_TOTAL_MIN, 0,
956 REG_SET(OTG_V_TOTAL_MAX, 0,
961 void optc1_set_vtotal_min_max(struct timing_generator *optc, int vtotal_min, int vtotal_max)
963 struct optc *optc1 = DCN10TG_FROM_TG(optc);
965 REG_SET(OTG_V_TOTAL_MAX, 0,
966 OTG_V_TOTAL_MAX, vtotal_max);
968 REG_SET(OTG_V_TOTAL_MIN, 0,
969 OTG_V_TOTAL_MIN, vtotal_min);
972 static void optc1_set_test_pattern(
973 struct timing_generator *optc,
974 /* TODO: replace 'controller_dp_test_pattern' by 'test_pattern_mode'
975 * because this is not DP-specific (which is probably somewhere in DP
977 enum controller_dp_test_pattern test_pattern,
978 enum dc_color_depth color_depth)
980 struct optc *optc1 = DCN10TG_FROM_TG(optc);
981 enum test_pattern_color_format bit_depth;
982 enum test_pattern_dyn_range dyn_range;
983 enum test_pattern_mode mode;
984 uint32_t pattern_mask;
985 uint32_t pattern_data;
986 /* color ramp generator mixes 16-bits color */
987 uint32_t src_bpc = 16;
991 /* RGB values of the color bars.
992 * Produce two RGB colors: RGB0 - white (all Fs)
993 * and RGB1 - black (all 0s)
994 * (three RGB components for two colors)
996 uint16_t src_color[6] = {0xFFFF, 0xFFFF, 0xFFFF, 0x0000,
998 /* dest color (converted to the specified color format) */
999 uint16_t dst_color[6];
1002 /* translate to bit depth */
1003 switch (color_depth) {
1004 case COLOR_DEPTH_666:
1005 bit_depth = TEST_PATTERN_COLOR_FORMAT_BPC_6;
1007 case COLOR_DEPTH_888:
1008 bit_depth = TEST_PATTERN_COLOR_FORMAT_BPC_8;
1010 case COLOR_DEPTH_101010:
1011 bit_depth = TEST_PATTERN_COLOR_FORMAT_BPC_10;
1013 case COLOR_DEPTH_121212:
1014 bit_depth = TEST_PATTERN_COLOR_FORMAT_BPC_12;
1017 bit_depth = TEST_PATTERN_COLOR_FORMAT_BPC_8;
1021 switch (test_pattern) {
1022 case CONTROLLER_DP_TEST_PATTERN_COLORSQUARES:
1023 case CONTROLLER_DP_TEST_PATTERN_COLORSQUARES_CEA:
1025 dyn_range = (test_pattern ==
1026 CONTROLLER_DP_TEST_PATTERN_COLORSQUARES_CEA ?
1027 TEST_PATTERN_DYN_RANGE_CEA :
1028 TEST_PATTERN_DYN_RANGE_VESA);
1029 mode = TEST_PATTERN_MODE_COLORSQUARES_RGB;
1031 REG_UPDATE_2(OTG_TEST_PATTERN_PARAMETERS,
1032 OTG_TEST_PATTERN_VRES, 6,
1033 OTG_TEST_PATTERN_HRES, 6);
1035 REG_UPDATE_4(OTG_TEST_PATTERN_CONTROL,
1036 OTG_TEST_PATTERN_EN, 1,
1037 OTG_TEST_PATTERN_MODE, mode,
1038 OTG_TEST_PATTERN_DYNAMIC_RANGE, dyn_range,
1039 OTG_TEST_PATTERN_COLOR_FORMAT, bit_depth);
1043 case CONTROLLER_DP_TEST_PATTERN_VERTICALBARS:
1044 case CONTROLLER_DP_TEST_PATTERN_HORIZONTALBARS:
1046 mode = (test_pattern ==
1047 CONTROLLER_DP_TEST_PATTERN_VERTICALBARS ?
1048 TEST_PATTERN_MODE_VERTICALBARS :
1049 TEST_PATTERN_MODE_HORIZONTALBARS);
1051 switch (bit_depth) {
1052 case TEST_PATTERN_COLOR_FORMAT_BPC_6:
1055 case TEST_PATTERN_COLOR_FORMAT_BPC_8:
1058 case TEST_PATTERN_COLOR_FORMAT_BPC_10:
1066 /* adjust color to the required colorFormat */
1067 for (index = 0; index < 6; index++) {
1068 /* dst = 2^dstBpc * src / 2^srcBpc = src >>
1069 * (srcBpc - dstBpc);
1072 src_color[index] >> (src_bpc - dst_bpc);
1073 /* CRTC_TEST_PATTERN_DATA has 16 bits,
1074 * lowest 6 are hardwired to ZERO
1075 * color bits should be left aligned aligned to MSB
1076 * XXXXXXXXXX000000 for 10 bit,
1077 * XXXXXXXX00000000 for 8 bit and XXXXXX0000000000 for 6
1079 dst_color[index] <<= (16 - dst_bpc);
1082 REG_WRITE(OTG_TEST_PATTERN_PARAMETERS, 0);
1084 /* We have to write the mask before data, similar to pipeline.
1085 * For example, for 8 bpc, if we want RGB0 to be magenta,
1086 * and RGB1 to be cyan,
1087 * we need to make 7 writes:
1089 * 000001 00000000 00000000 set mask to R0
1090 * 000010 11111111 00000000 R0 255, 0xFF00, set mask to G0
1091 * 000100 00000000 00000000 G0 0, 0x0000, set mask to B0
1092 * 001000 11111111 00000000 B0 255, 0xFF00, set mask to R1
1093 * 010000 00000000 00000000 R1 0, 0x0000, set mask to G1
1094 * 100000 11111111 00000000 G1 255, 0xFF00, set mask to B1
1095 * 100000 11111111 00000000 B1 255, 0xFF00
1097 * we will make a loop of 6 in which we prepare the mask,
1098 * then write, then prepare the color for next write.
1099 * first iteration will write mask only,
1100 * but each next iteration color prepared in
1101 * previous iteration will be written within new mask,
1102 * the last component will written separately,
1103 * mask is not changing between 6th and 7th write
1104 * and color will be prepared by last iteration
1107 /* write color, color values mask in CRTC_TEST_PATTERN_MASK
1108 * is B1, G1, R1, B0, G0, R0
1111 for (index = 0; index < 6; index++) {
1112 /* prepare color mask, first write PATTERN_DATA
1113 * will have all zeros
1115 pattern_mask = (1 << index);
1117 /* write color component */
1118 REG_SET_2(OTG_TEST_PATTERN_COLOR, 0,
1119 OTG_TEST_PATTERN_MASK, pattern_mask,
1120 OTG_TEST_PATTERN_DATA, pattern_data);
1122 /* prepare next color component,
1123 * will be written in the next iteration
1125 pattern_data = dst_color[index];
1127 /* write last color component,
1128 * it's been already prepared in the loop
1130 REG_SET_2(OTG_TEST_PATTERN_COLOR, 0,
1131 OTG_TEST_PATTERN_MASK, pattern_mask,
1132 OTG_TEST_PATTERN_DATA, pattern_data);
1134 /* enable test pattern */
1135 REG_UPDATE_4(OTG_TEST_PATTERN_CONTROL,
1136 OTG_TEST_PATTERN_EN, 1,
1137 OTG_TEST_PATTERN_MODE, mode,
1138 OTG_TEST_PATTERN_DYNAMIC_RANGE, 0,
1139 OTG_TEST_PATTERN_COLOR_FORMAT, bit_depth);
1143 case CONTROLLER_DP_TEST_PATTERN_COLORRAMP:
1145 mode = (bit_depth ==
1146 TEST_PATTERN_COLOR_FORMAT_BPC_10 ?
1147 TEST_PATTERN_MODE_DUALRAMP_RGB :
1148 TEST_PATTERN_MODE_SINGLERAMP_RGB);
1150 switch (bit_depth) {
1151 case TEST_PATTERN_COLOR_FORMAT_BPC_6:
1154 case TEST_PATTERN_COLOR_FORMAT_BPC_8:
1157 case TEST_PATTERN_COLOR_FORMAT_BPC_10:
1165 /* increment for the first ramp for one color gradation
1166 * 1 gradation for 6-bit color is 2^10
1167 * gradations in 16-bit color
1169 inc_base = (src_bpc - dst_bpc);
1171 switch (bit_depth) {
1172 case TEST_PATTERN_COLOR_FORMAT_BPC_6:
1174 REG_UPDATE_5(OTG_TEST_PATTERN_PARAMETERS,
1175 OTG_TEST_PATTERN_INC0, inc_base,
1176 OTG_TEST_PATTERN_INC1, 0,
1177 OTG_TEST_PATTERN_HRES, 6,
1178 OTG_TEST_PATTERN_VRES, 6,
1179 OTG_TEST_PATTERN_RAMP0_OFFSET, 0);
1182 case TEST_PATTERN_COLOR_FORMAT_BPC_8:
1184 REG_UPDATE_5(OTG_TEST_PATTERN_PARAMETERS,
1185 OTG_TEST_PATTERN_INC0, inc_base,
1186 OTG_TEST_PATTERN_INC1, 0,
1187 OTG_TEST_PATTERN_HRES, 8,
1188 OTG_TEST_PATTERN_VRES, 6,
1189 OTG_TEST_PATTERN_RAMP0_OFFSET, 0);
1192 case TEST_PATTERN_COLOR_FORMAT_BPC_10:
1194 REG_UPDATE_5(OTG_TEST_PATTERN_PARAMETERS,
1195 OTG_TEST_PATTERN_INC0, inc_base,
1196 OTG_TEST_PATTERN_INC1, inc_base + 2,
1197 OTG_TEST_PATTERN_HRES, 8,
1198 OTG_TEST_PATTERN_VRES, 5,
1199 OTG_TEST_PATTERN_RAMP0_OFFSET, 384 << 6);
1206 REG_WRITE(OTG_TEST_PATTERN_COLOR, 0);
1208 /* enable test pattern */
1209 REG_WRITE(OTG_TEST_PATTERN_CONTROL, 0);
1211 REG_SET_4(OTG_TEST_PATTERN_CONTROL, 0,
1212 OTG_TEST_PATTERN_EN, 1,
1213 OTG_TEST_PATTERN_MODE, mode,
1214 OTG_TEST_PATTERN_DYNAMIC_RANGE, 0,
1215 OTG_TEST_PATTERN_COLOR_FORMAT, bit_depth);
1218 case CONTROLLER_DP_TEST_PATTERN_VIDEOMODE:
1220 REG_WRITE(OTG_TEST_PATTERN_CONTROL, 0);
1221 REG_WRITE(OTG_TEST_PATTERN_COLOR, 0);
1222 REG_WRITE(OTG_TEST_PATTERN_PARAMETERS, 0);
1231 void optc1_get_crtc_scanoutpos(
1232 struct timing_generator *optc,
1233 uint32_t *v_blank_start,
1234 uint32_t *v_blank_end,
1235 uint32_t *h_position,
1236 uint32_t *v_position)
1238 struct optc *optc1 = DCN10TG_FROM_TG(optc);
1239 struct crtc_position position;
1241 REG_GET_2(OTG_V_BLANK_START_END,
1242 OTG_V_BLANK_START, v_blank_start,
1243 OTG_V_BLANK_END, v_blank_end);
1245 optc1_get_position(optc, &position);
1247 *h_position = position.horizontal_count;
1248 *v_position = position.vertical_count;
1251 static void optc1_enable_stereo(struct timing_generator *optc,
1252 const struct dc_crtc_timing *timing, struct crtc_stereo_flags *flags)
1254 struct optc *optc1 = DCN10TG_FROM_TG(optc);
1258 stereo_en = flags->FRAME_PACKED == 0 ? 1 : 0;
1260 if (flags->PROGRAM_STEREO)
1261 REG_UPDATE_3(OTG_STEREO_CONTROL,
1262 OTG_STEREO_EN, stereo_en,
1263 OTG_STEREO_SYNC_OUTPUT_LINE_NUM, 0,
1264 OTG_STEREO_SYNC_OUTPUT_POLARITY, flags->RIGHT_EYE_POLARITY == 0 ? 0 : 1);
1266 if (flags->PROGRAM_POLARITY)
1267 REG_UPDATE(OTG_STEREO_CONTROL,
1268 OTG_STEREO_EYE_FLAG_POLARITY,
1269 flags->RIGHT_EYE_POLARITY == 0 ? 0 : 1);
1271 if (flags->DISABLE_STEREO_DP_SYNC)
1272 REG_UPDATE(OTG_STEREO_CONTROL,
1273 OTG_DISABLE_STEREOSYNC_OUTPUT_FOR_DP, 1);
1275 if (flags->PROGRAM_STEREO)
1276 REG_UPDATE_2(OTG_3D_STRUCTURE_CONTROL,
1277 OTG_3D_STRUCTURE_EN, flags->FRAME_PACKED,
1278 OTG_3D_STRUCTURE_STEREO_SEL_OVR, flags->FRAME_PACKED);
1283 void optc1_program_stereo(struct timing_generator *optc,
1284 const struct dc_crtc_timing *timing, struct crtc_stereo_flags *flags)
1286 if (flags->PROGRAM_STEREO)
1287 optc1_enable_stereo(optc, timing, flags);
1289 optc1_disable_stereo(optc);
1293 bool optc1_is_stereo_left_eye(struct timing_generator *optc)
1296 uint32_t left_eye = 0;
1297 struct optc *optc1 = DCN10TG_FROM_TG(optc);
1299 REG_GET(OTG_STEREO_STATUS,
1300 OTG_STEREO_CURRENT_EYE, &left_eye);
1309 bool optc1_get_hw_timing(struct timing_generator *tg,
1310 struct dc_crtc_timing *hw_crtc_timing)
1312 struct dcn_otg_state s = {0};
1314 if (tg == NULL || hw_crtc_timing == NULL)
1317 optc1_read_otg_state(DCN10TG_FROM_TG(tg), &s);
1319 hw_crtc_timing->h_total = s.h_total + 1;
1320 hw_crtc_timing->h_addressable = s.h_total - ((s.h_total - s.h_blank_start) + s.h_blank_end);
1321 hw_crtc_timing->h_front_porch = s.h_total + 1 - s.h_blank_start;
1322 hw_crtc_timing->h_sync_width = s.h_sync_a_end - s.h_sync_a_start;
1324 hw_crtc_timing->v_total = s.v_total + 1;
1325 hw_crtc_timing->v_addressable = s.v_total - ((s.v_total - s.v_blank_start) + s.v_blank_end);
1326 hw_crtc_timing->v_front_porch = s.v_total + 1 - s.v_blank_start;
1327 hw_crtc_timing->v_sync_width = s.v_sync_a_end - s.v_sync_a_start;
1333 void optc1_read_otg_state(struct optc *optc1,
1334 struct dcn_otg_state *s)
1336 REG_GET(OTG_CONTROL,
1337 OTG_MASTER_EN, &s->otg_enabled);
1339 REG_GET_2(OTG_V_BLANK_START_END,
1340 OTG_V_BLANK_START, &s->v_blank_start,
1341 OTG_V_BLANK_END, &s->v_blank_end);
1343 REG_GET(OTG_V_SYNC_A_CNTL,
1344 OTG_V_SYNC_A_POL, &s->v_sync_a_pol);
1346 REG_GET(OTG_V_TOTAL,
1347 OTG_V_TOTAL, &s->v_total);
1349 REG_GET(OTG_V_TOTAL_MAX,
1350 OTG_V_TOTAL_MAX, &s->v_total_max);
1352 REG_GET(OTG_V_TOTAL_MIN,
1353 OTG_V_TOTAL_MIN, &s->v_total_min);
1355 REG_GET(OTG_V_TOTAL_CONTROL,
1356 OTG_V_TOTAL_MAX_SEL, &s->v_total_max_sel);
1358 REG_GET(OTG_V_TOTAL_CONTROL,
1359 OTG_V_TOTAL_MIN_SEL, &s->v_total_min_sel);
1361 REG_GET_2(OTG_V_SYNC_A,
1362 OTG_V_SYNC_A_START, &s->v_sync_a_start,
1363 OTG_V_SYNC_A_END, &s->v_sync_a_end);
1365 REG_GET_2(OTG_H_BLANK_START_END,
1366 OTG_H_BLANK_START, &s->h_blank_start,
1367 OTG_H_BLANK_END, &s->h_blank_end);
1369 REG_GET_2(OTG_H_SYNC_A,
1370 OTG_H_SYNC_A_START, &s->h_sync_a_start,
1371 OTG_H_SYNC_A_END, &s->h_sync_a_end);
1373 REG_GET(OTG_H_SYNC_A_CNTL,
1374 OTG_H_SYNC_A_POL, &s->h_sync_a_pol);
1376 REG_GET(OTG_H_TOTAL,
1377 OTG_H_TOTAL, &s->h_total);
1379 REG_GET(OPTC_INPUT_GLOBAL_CONTROL,
1380 OPTC_UNDERFLOW_OCCURRED_STATUS, &s->underflow_occurred_status);
1382 REG_GET(OTG_VERTICAL_INTERRUPT2_CONTROL,
1383 OTG_VERTICAL_INTERRUPT2_INT_ENABLE, &s->vertical_interrupt2_en);
1385 REG_GET(OTG_VERTICAL_INTERRUPT2_POSITION,
1386 OTG_VERTICAL_INTERRUPT2_LINE_START, &s->vertical_interrupt2_line);
1389 bool optc1_get_otg_active_size(struct timing_generator *optc,
1390 uint32_t *otg_active_width,
1391 uint32_t *otg_active_height)
1393 uint32_t otg_enabled;
1394 uint32_t v_blank_start;
1395 uint32_t v_blank_end;
1396 uint32_t h_blank_start;
1397 uint32_t h_blank_end;
1398 struct optc *optc1 = DCN10TG_FROM_TG(optc);
1401 REG_GET(OTG_CONTROL,
1402 OTG_MASTER_EN, &otg_enabled);
1404 if (otg_enabled == 0)
1407 REG_GET_2(OTG_V_BLANK_START_END,
1408 OTG_V_BLANK_START, &v_blank_start,
1409 OTG_V_BLANK_END, &v_blank_end);
1411 REG_GET_2(OTG_H_BLANK_START_END,
1412 OTG_H_BLANK_START, &h_blank_start,
1413 OTG_H_BLANK_END, &h_blank_end);
1415 *otg_active_width = v_blank_start - v_blank_end;
1416 *otg_active_height = h_blank_start - h_blank_end;
1420 void optc1_clear_optc_underflow(struct timing_generator *optc)
1422 struct optc *optc1 = DCN10TG_FROM_TG(optc);
1424 REG_UPDATE(OPTC_INPUT_GLOBAL_CONTROL, OPTC_UNDERFLOW_CLEAR, 1);
1427 void optc1_tg_init(struct timing_generator *optc)
1429 optc1_set_blank_data_double_buffer(optc, true);
1430 optc1_set_timing_double_buffer(optc, true);
1431 optc1_clear_optc_underflow(optc);
1434 bool optc1_is_tg_enabled(struct timing_generator *optc)
1436 struct optc *optc1 = DCN10TG_FROM_TG(optc);
1437 uint32_t otg_enabled = 0;
1439 REG_GET(OTG_CONTROL, OTG_MASTER_EN, &otg_enabled);
1441 return (otg_enabled != 0);
1445 bool optc1_is_optc_underflow_occurred(struct timing_generator *optc)
1447 struct optc *optc1 = DCN10TG_FROM_TG(optc);
1448 uint32_t underflow_occurred = 0;
1450 REG_GET(OPTC_INPUT_GLOBAL_CONTROL,
1451 OPTC_UNDERFLOW_OCCURRED_STATUS,
1452 &underflow_occurred);
1454 return (underflow_occurred == 1);
1457 bool optc1_configure_crc(struct timing_generator *optc,
1458 const struct crc_params *params)
1460 struct optc *optc1 = DCN10TG_FROM_TG(optc);
1462 /* Cannot configure crc on a CRTC that is disabled */
1463 if (!optc1_is_tg_enabled(optc))
1466 REG_WRITE(OTG_CRC_CNTL, 0);
1468 if (!params->enable)
1471 /* Program frame boundaries */
1472 /* Window A x axis start and end. */
1473 REG_UPDATE_2(OTG_CRC0_WINDOWA_X_CONTROL,
1474 OTG_CRC0_WINDOWA_X_START, params->windowa_x_start,
1475 OTG_CRC0_WINDOWA_X_END, params->windowa_x_end);
1477 /* Window A y axis start and end. */
1478 REG_UPDATE_2(OTG_CRC0_WINDOWA_Y_CONTROL,
1479 OTG_CRC0_WINDOWA_Y_START, params->windowa_y_start,
1480 OTG_CRC0_WINDOWA_Y_END, params->windowa_y_end);
1482 /* Window B x axis start and end. */
1483 REG_UPDATE_2(OTG_CRC0_WINDOWB_X_CONTROL,
1484 OTG_CRC0_WINDOWB_X_START, params->windowb_x_start,
1485 OTG_CRC0_WINDOWB_X_END, params->windowb_x_end);
1487 /* Window B y axis start and end. */
1488 REG_UPDATE_2(OTG_CRC0_WINDOWB_Y_CONTROL,
1489 OTG_CRC0_WINDOWB_Y_START, params->windowb_y_start,
1490 OTG_CRC0_WINDOWB_Y_END, params->windowb_y_end);
1492 /* Set crc mode and selection, and enable. Only using CRC0*/
1493 REG_UPDATE_3(OTG_CRC_CNTL,
1494 OTG_CRC_CONT_EN, params->continuous_mode ? 1 : 0,
1495 OTG_CRC0_SELECT, params->selection,
1501 bool optc1_get_crc(struct timing_generator *optc,
1502 uint32_t *r_cr, uint32_t *g_y, uint32_t *b_cb)
1505 struct optc *optc1 = DCN10TG_FROM_TG(optc);
1507 REG_GET(OTG_CRC_CNTL, OTG_CRC_EN, &field);
1509 /* Early return if CRC is not enabled for this CRTC */
1513 REG_GET_2(OTG_CRC0_DATA_RG,
1517 REG_GET(OTG_CRC0_DATA_B,
1523 static const struct timing_generator_funcs dcn10_tg_funcs = {
1524 .validate_timing = optc1_validate_timing,
1525 .program_timing = optc1_program_timing,
1526 .setup_vertical_interrupt0 = optc1_setup_vertical_interrupt0,
1527 .setup_vertical_interrupt1 = optc1_setup_vertical_interrupt1,
1528 .setup_vertical_interrupt2 = optc1_setup_vertical_interrupt2,
1529 .program_global_sync = optc1_program_global_sync,
1530 .enable_crtc = optc1_enable_crtc,
1531 .disable_crtc = optc1_disable_crtc,
1532 /* used by enable_timing_synchronization. Not need for FPGA */
1533 .is_counter_moving = optc1_is_counter_moving,
1534 .get_position = optc1_get_position,
1535 .get_frame_count = optc1_get_vblank_counter,
1536 .get_scanoutpos = optc1_get_crtc_scanoutpos,
1537 .get_otg_active_size = optc1_get_otg_active_size,
1538 .set_early_control = optc1_set_early_control,
1539 /* used by enable_timing_synchronization. Not need for FPGA */
1540 .wait_for_state = optc1_wait_for_state,
1541 .set_blank = optc1_set_blank,
1542 .is_blanked = optc1_is_blanked,
1543 .set_blank_color = optc1_program_blank_color,
1544 .did_triggered_reset_occur = optc1_did_triggered_reset_occur,
1545 .enable_reset_trigger = optc1_enable_reset_trigger,
1546 .enable_crtc_reset = optc1_enable_crtc_reset,
1547 .disable_reset_trigger = optc1_disable_reset_trigger,
1549 .is_locked = optc1_is_locked,
1550 .unlock = optc1_unlock,
1551 .enable_optc_clock = optc1_enable_optc_clock,
1552 .set_drr = optc1_set_drr,
1553 .get_last_used_drr_vtotal = NULL,
1554 .set_static_screen_control = optc1_set_static_screen_control,
1555 .set_test_pattern = optc1_set_test_pattern,
1556 .program_stereo = optc1_program_stereo,
1557 .is_stereo_left_eye = optc1_is_stereo_left_eye,
1558 .set_blank_data_double_buffer = optc1_set_blank_data_double_buffer,
1559 .tg_init = optc1_tg_init,
1560 .is_tg_enabled = optc1_is_tg_enabled,
1561 .is_optc_underflow_occurred = optc1_is_optc_underflow_occurred,
1562 .clear_optc_underflow = optc1_clear_optc_underflow,
1563 .get_crc = optc1_get_crc,
1564 .configure_crc = optc1_configure_crc,
1565 .set_vtg_params = optc1_set_vtg_params,
1566 .program_manual_trigger = optc1_program_manual_trigger,
1567 .setup_manual_trigger = optc1_setup_manual_trigger,
1568 .get_hw_timing = optc1_get_hw_timing,
1571 void dcn10_timing_generator_init(struct optc *optc1)
1573 optc1->base.funcs = &dcn10_tg_funcs;
1575 optc1->max_h_total = optc1->tg_mask->OTG_H_TOTAL + 1;
1576 optc1->max_v_total = optc1->tg_mask->OTG_V_TOTAL + 1;
1578 optc1->min_h_blank = 32;
1579 optc1->min_v_blank = 3;
1580 optc1->min_v_blank_interlace = 5;
1581 optc1->min_h_sync_width = 4;
1582 optc1->min_v_sync_width = 1;
1585 /* "Containter" vs. "pixel" is a concept within HW blocks, mostly those closer to the back-end. It works like this:
1587 * - 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
1590 * - In 4:2:0 (DSC or uncompressed) there are two pixels per container, hence the target container rate has to be
1591 * halved to maintain the correct pixel rate.
1593 * - Unlike 4:2:2 uncompressed, DSC 4:2:2 Native also has two pixels per container (this happens when DSC is applied
1594 * 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.
1597 bool optc1_is_two_pixels_per_containter(const struct dc_crtc_timing *timing)
1599 bool two_pix = timing->pixel_encoding == PIXEL_ENCODING_YCBCR420;
1601 two_pix = two_pix || (timing->flags.DSC && timing->pixel_encoding == PIXEL_ENCODING_YCBCR422
1602 && !timing->dsc_cfg.ycbcr422_simple);