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;
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);
169 /* Load horizontal timing */
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);
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);
180 /* blank_start = line end - front porch */
181 asic_blank_start = patched_crtc_timing.h_total -
182 patched_crtc_timing.h_front_porch;
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;
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);
194 /* h_sync polarity */
195 h_sync_polarity = patched_crtc_timing.flags.HSYNC_POSITIVE_POLARITY ?
198 REG_UPDATE(OTG_H_SYNC_A_CNTL,
199 OTG_H_SYNC_A_POL, h_sync_polarity);
201 v_total = patched_crtc_timing.v_total - 1;
203 REG_SET(OTG_V_TOTAL, 0,
204 OTG_V_TOTAL, v_total);
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.
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);
214 /* v_sync_start = 0, v_sync_end = v_sync_width */
215 v_sync_end = patched_crtc_timing.v_sync_width;
217 REG_UPDATE_2(OTG_V_SYNC_A,
218 OTG_V_SYNC_A_START, 0,
219 OTG_V_SYNC_A_END, v_sync_end);
221 /* blank_start = frame end - front porch */
222 asic_blank_start = patched_crtc_timing.v_total -
223 patched_crtc_timing.v_front_porch;
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;
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);
235 /* v_sync polarity */
236 v_sync_polarity = patched_crtc_timing.flags.VSYNC_POSITIVE_POLARITY ?
239 REG_UPDATE(OTG_V_SYNC_A_CNTL,
240 OTG_V_SYNC_A_POL, v_sync_polarity);
242 if (optc1->signal == SIGNAL_TYPE_DISPLAY_PORT ||
243 optc1->signal == SIGNAL_TYPE_DISPLAY_PORT_MST ||
244 optc1->signal == SIGNAL_TYPE_EDP) {
246 if (patched_crtc_timing.flags.INTERLACE == 1)
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);
256 REG_UPDATE(OTG_INTERLACE_CONTROL,
257 OTG_INTERLACE_ENABLE, 0);
260 /* VTG enable set to 0 first VInit */
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);
269 optc->funcs->program_global_sync(optc,
275 optc->funcs->set_vtg_params(optc, dc_crtc_timing);
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);
284 /* Enable stereo - only when we need to pack 3D frame. Other types
285 * of stereo handled in explicit call
288 h_div_2 = optc1_is_two_pixels_per_containter(&patched_crtc_timing);
289 REG_UPDATE(OTG_H_TIMING_CNTL,
290 OTG_H_TIMING_DIV_BY2, h_div_2 || optc1->comb_opp_id != 0xf);
294 void optc1_set_vtg_params(struct timing_generator *optc,
295 const struct dc_crtc_timing *dc_crtc_timing)
297 struct dc_crtc_timing patched_crtc_timing;
298 uint32_t asic_blank_end;
301 int32_t vertical_line_start;
303 struct optc *optc1 = DCN10TG_FROM_TG(optc);
305 patched_crtc_timing = *dc_crtc_timing;
306 apply_front_porch_workaround(&patched_crtc_timing);
308 /* VCOUNT_INIT is the start of blank */
309 v_init = patched_crtc_timing.v_total - patched_crtc_timing.v_front_porch;
311 /* end of blank = v_init - active */
312 asic_blank_end = v_init -
313 patched_crtc_timing.v_border_bottom -
314 patched_crtc_timing.v_addressable -
315 patched_crtc_timing.v_border_top;
317 /* if VSTARTUP is before VSYNC, FP2 is the offset, otherwise 0 */
318 vertical_line_start = asic_blank_end - optc1->vstartup_start + 1;
319 if (vertical_line_start < 0)
320 v_fp2 = -vertical_line_start;
323 if (REG(OTG_INTERLACE_CONTROL)) {
324 if (patched_crtc_timing.flags.INTERLACE == 1) {
326 if ((optc1->vstartup_start/2)*2 > asic_blank_end)
331 REG_UPDATE_2(CONTROL,
333 VTG0_VCOUNT_INIT, v_init);
336 void optc1_set_blank_data_double_buffer(struct timing_generator *optc, bool enable)
338 struct optc *optc1 = DCN10TG_FROM_TG(optc);
340 uint32_t blank_data_double_buffer_enable = enable ? 1 : 0;
342 REG_UPDATE(OTG_DOUBLE_BUFFER_CONTROL,
343 OTG_BLANK_DATA_DOUBLE_BUFFER_EN, blank_data_double_buffer_enable);
348 * Call ASIC Control Object to UnBlank CRTC.
350 static void optc1_unblank_crtc(struct timing_generator *optc)
352 struct optc *optc1 = DCN10TG_FROM_TG(optc);
354 REG_UPDATE_2(OTG_BLANK_CONTROL,
355 OTG_BLANK_DATA_EN, 0,
356 OTG_BLANK_DE_MODE, 0);
358 /* W/A for automated testing
359 * Automated testing will fail underflow test as there
360 * sporadic underflows which occur during the optc blank
361 * sequence. As a w/a, clear underflow on unblank.
362 * This prevents the failure, but will not mask actual
363 * underflow that affect real use cases.
365 optc1_clear_optc_underflow(optc);
370 * Call ASIC Control Object to Blank CRTC.
373 static void optc1_blank_crtc(struct timing_generator *optc)
375 struct optc *optc1 = DCN10TG_FROM_TG(optc);
377 REG_UPDATE_2(OTG_BLANK_CONTROL,
378 OTG_BLANK_DATA_EN, 1,
379 OTG_BLANK_DE_MODE, 0);
381 optc1_set_blank_data_double_buffer(optc, false);
384 void optc1_set_blank(struct timing_generator *optc,
385 bool enable_blanking)
388 optc1_blank_crtc(optc);
390 optc1_unblank_crtc(optc);
393 bool optc1_is_blanked(struct timing_generator *optc)
395 struct optc *optc1 = DCN10TG_FROM_TG(optc);
397 uint32_t blank_state;
399 REG_GET_2(OTG_BLANK_CONTROL,
400 OTG_BLANK_DATA_EN, &blank_en,
401 OTG_CURRENT_BLANK_STATE, &blank_state);
403 return blank_en && blank_state;
406 void optc1_enable_optc_clock(struct timing_generator *optc, bool enable)
408 struct optc *optc1 = DCN10TG_FROM_TG(optc);
411 REG_UPDATE_2(OPTC_INPUT_CLOCK_CONTROL,
412 OPTC_INPUT_CLK_EN, 1,
413 OPTC_INPUT_CLK_GATE_DIS, 1);
415 REG_WAIT(OPTC_INPUT_CLOCK_CONTROL,
416 OPTC_INPUT_CLK_ON, 1,
420 REG_UPDATE_2(OTG_CLOCK_CONTROL,
422 OTG_CLOCK_GATE_DIS, 1);
423 REG_WAIT(OTG_CLOCK_CONTROL,
427 REG_UPDATE_2(OTG_CLOCK_CONTROL,
428 OTG_CLOCK_GATE_DIS, 0,
431 REG_UPDATE_2(OPTC_INPUT_CLOCK_CONTROL,
432 OPTC_INPUT_CLK_GATE_DIS, 0,
433 OPTC_INPUT_CLK_EN, 0);
439 * Enable CRTC - call ASIC Control Object to enable Timing generator.
441 static bool optc1_enable_crtc(struct timing_generator *optc)
443 /* TODO FPGA wait for answer
444 * OTG_MASTER_UPDATE_MODE != CRTC_MASTER_UPDATE_MODE
445 * OTG_MASTER_UPDATE_LOCK != CRTC_MASTER_UPDATE_LOCK
447 struct optc *optc1 = DCN10TG_FROM_TG(optc);
449 /* opp instance for OTG. For DCN1.0, ODM is remoed.
450 * OPP and OPTC should 1:1 mapping
452 REG_UPDATE(OPTC_DATA_SOURCE_SELECT,
453 OPTC_SRC_SEL, optc->inst);
455 /* VTG enable first is for HW workaround */
460 REG_UPDATE_2(OTG_CONTROL,
461 OTG_DISABLE_POINT_CNTL, 3,
467 /* disable_crtc - call ASIC Control Object to disable Timing generator. */
468 bool optc1_disable_crtc(struct timing_generator *optc)
470 struct optc *optc1 = DCN10TG_FROM_TG(optc);
472 /* disable otg request until end of the first line
473 * in the vertical blank region
475 REG_UPDATE_2(OTG_CONTROL,
476 OTG_DISABLE_POINT_CNTL, 3,
482 /* CRTC disabled, so disable clock. */
483 REG_WAIT(OTG_CLOCK_CONTROL,
491 void optc1_program_blank_color(
492 struct timing_generator *optc,
493 const struct tg_color *black_color)
495 struct optc *optc1 = DCN10TG_FROM_TG(optc);
497 REG_SET_3(OTG_BLACK_COLOR, 0,
498 OTG_BLACK_COLOR_B_CB, black_color->color_b_cb,
499 OTG_BLACK_COLOR_G_Y, black_color->color_g_y,
500 OTG_BLACK_COLOR_R_CR, black_color->color_r_cr);
503 bool optc1_validate_timing(
504 struct timing_generator *optc,
505 const struct dc_crtc_timing *timing)
509 uint32_t min_v_blank;
510 struct optc *optc1 = DCN10TG_FROM_TG(optc);
512 ASSERT(timing != NULL);
514 v_blank = (timing->v_total - timing->v_addressable -
515 timing->v_border_top - timing->v_border_bottom);
517 h_blank = (timing->h_total - timing->h_addressable -
518 timing->h_border_right -
519 timing->h_border_left);
521 if (timing->timing_3d_format != TIMING_3D_FORMAT_NONE &&
522 timing->timing_3d_format != TIMING_3D_FORMAT_HW_FRAME_PACKING &&
523 timing->timing_3d_format != TIMING_3D_FORMAT_TOP_AND_BOTTOM &&
524 timing->timing_3d_format != TIMING_3D_FORMAT_SIDE_BY_SIDE &&
525 timing->timing_3d_format != TIMING_3D_FORMAT_FRAME_ALTERNATE &&
526 timing->timing_3d_format != TIMING_3D_FORMAT_INBAND_FA)
529 /* Temporarily blocking interlacing mode until it's supported */
530 if (timing->flags.INTERLACE == 1)
533 /* Check maximum number of pixels supported by Timing Generator
534 * (Currently will never fail, in order to fail needs display which
535 * needs more than 8192 horizontal and
536 * more than 8192 vertical total pixels)
538 if (timing->h_total > optc1->max_h_total ||
539 timing->v_total > optc1->max_v_total)
543 if (h_blank < optc1->min_h_blank)
546 if (timing->h_sync_width < optc1->min_h_sync_width ||
547 timing->v_sync_width < optc1->min_v_sync_width)
550 min_v_blank = timing->flags.INTERLACE?optc1->min_v_blank_interlace:optc1->min_v_blank;
552 if (v_blank < min_v_blank)
563 * Get counter for vertical blanks. use register CRTC_STATUS_FRAME_COUNT which
564 * holds the counter of frames.
567 * struct timing_generator *optc - [in] timing generator which controls the
571 * Counter of frames, which should equal to number of vblanks.
573 uint32_t optc1_get_vblank_counter(struct timing_generator *optc)
575 struct optc *optc1 = DCN10TG_FROM_TG(optc);
576 uint32_t frame_count;
578 REG_GET(OTG_STATUS_FRAME_COUNT,
579 OTG_FRAME_COUNT, &frame_count);
584 void optc1_lock(struct timing_generator *optc)
586 struct optc *optc1 = DCN10TG_FROM_TG(optc);
589 regval = REG_READ(OTG_CONTROL);
591 /* otg is not running, do not need to be locked */
592 if ((regval & 0x1) == 0x0)
595 REG_SET(OTG_GLOBAL_CONTROL0, 0,
596 OTG_MASTER_UPDATE_LOCK_SEL, optc->inst);
597 REG_SET(OTG_MASTER_UPDATE_LOCK, 0,
598 OTG_MASTER_UPDATE_LOCK, 1);
600 /* Should be fast, status does not update on maximus */
601 if (optc->ctx->dce_environment != DCE_ENV_FPGA_MAXIMUS) {
603 REG_WAIT(OTG_MASTER_UPDATE_LOCK,
604 UPDATE_LOCK_STATUS, 1,
609 void optc1_unlock(struct timing_generator *optc)
611 struct optc *optc1 = DCN10TG_FROM_TG(optc);
613 REG_SET(OTG_MASTER_UPDATE_LOCK, 0,
614 OTG_MASTER_UPDATE_LOCK, 0);
617 void optc1_get_position(struct timing_generator *optc,
618 struct crtc_position *position)
620 struct optc *optc1 = DCN10TG_FROM_TG(optc);
622 REG_GET_2(OTG_STATUS_POSITION,
623 OTG_HORZ_COUNT, &position->horizontal_count,
624 OTG_VERT_COUNT, &position->vertical_count);
626 REG_GET(OTG_NOM_VERT_POSITION,
627 OTG_VERT_COUNT_NOM, &position->nominal_vcount);
630 bool optc1_is_counter_moving(struct timing_generator *optc)
632 struct crtc_position position1, position2;
634 optc->funcs->get_position(optc, &position1);
635 optc->funcs->get_position(optc, &position2);
637 if (position1.horizontal_count == position2.horizontal_count &&
638 position1.vertical_count == position2.vertical_count)
644 bool optc1_did_triggered_reset_occur(
645 struct timing_generator *optc)
647 struct optc *optc1 = DCN10TG_FROM_TG(optc);
648 uint32_t occurred_force, occurred_vsync;
650 REG_GET(OTG_FORCE_COUNT_NOW_CNTL,
651 OTG_FORCE_COUNT_NOW_OCCURRED, &occurred_force);
653 REG_GET(OTG_VERT_SYNC_CONTROL,
654 OTG_FORCE_VSYNC_NEXT_LINE_OCCURRED, &occurred_vsync);
656 return occurred_vsync != 0 || occurred_force != 0;
659 void optc1_disable_reset_trigger(struct timing_generator *optc)
661 struct optc *optc1 = DCN10TG_FROM_TG(optc);
663 REG_WRITE(OTG_TRIGA_CNTL, 0);
665 REG_SET(OTG_FORCE_COUNT_NOW_CNTL, 0,
666 OTG_FORCE_COUNT_NOW_CLEAR, 1);
668 REG_SET(OTG_VERT_SYNC_CONTROL, 0,
669 OTG_FORCE_VSYNC_NEXT_LINE_CLEAR, 1);
672 void optc1_enable_reset_trigger(struct timing_generator *optc, int source_tg_inst)
674 struct optc *optc1 = DCN10TG_FROM_TG(optc);
675 uint32_t falling_edge;
677 REG_GET(OTG_V_SYNC_A_CNTL,
678 OTG_V_SYNC_A_POL, &falling_edge);
681 REG_SET_3(OTG_TRIGA_CNTL, 0,
682 /* vsync signal from selected OTG pipe based
683 * on OTG_TRIG_SOURCE_PIPE_SELECT setting
685 OTG_TRIGA_SOURCE_SELECT, 20,
686 OTG_TRIGA_SOURCE_PIPE_SELECT, source_tg_inst,
687 /* always detect falling edge */
688 OTG_TRIGA_FALLING_EDGE_DETECT_CNTL, 1);
690 REG_SET_3(OTG_TRIGA_CNTL, 0,
691 /* vsync signal from selected OTG pipe based
692 * on OTG_TRIG_SOURCE_PIPE_SELECT setting
694 OTG_TRIGA_SOURCE_SELECT, 20,
695 OTG_TRIGA_SOURCE_PIPE_SELECT, source_tg_inst,
696 /* always detect rising edge */
697 OTG_TRIGA_RISING_EDGE_DETECT_CNTL, 1);
699 REG_SET(OTG_FORCE_COUNT_NOW_CNTL, 0,
700 /* force H count to H_TOTAL and V count to V_TOTAL in
701 * progressive mode and V_TOTAL-1 in interlaced mode
703 OTG_FORCE_COUNT_NOW_MODE, 2);
706 void optc1_enable_crtc_reset(
707 struct timing_generator *optc,
709 struct crtc_trigger_info *crtc_tp)
711 struct optc *optc1 = DCN10TG_FROM_TG(optc);
712 uint32_t falling_edge = 0;
713 uint32_t rising_edge = 0;
715 switch (crtc_tp->event) {
717 case CRTC_EVENT_VSYNC_RISING:
721 case CRTC_EVENT_VSYNC_FALLING:
726 REG_SET_4(OTG_TRIGA_CNTL, 0,
727 /* vsync signal from selected OTG pipe based
728 * on OTG_TRIG_SOURCE_PIPE_SELECT setting
730 OTG_TRIGA_SOURCE_SELECT, 20,
731 OTG_TRIGA_SOURCE_PIPE_SELECT, source_tg_inst,
732 /* always detect falling edge */
733 OTG_TRIGA_RISING_EDGE_DETECT_CNTL, rising_edge,
734 OTG_TRIGA_FALLING_EDGE_DETECT_CNTL, falling_edge);
736 switch (crtc_tp->delay) {
737 case TRIGGER_DELAY_NEXT_LINE:
738 REG_SET(OTG_VERT_SYNC_CONTROL, 0,
739 OTG_AUTO_FORCE_VSYNC_MODE, 1);
741 case TRIGGER_DELAY_NEXT_PIXEL:
742 REG_SET(OTG_FORCE_COUNT_NOW_CNTL, 0,
743 /* force H count to H_TOTAL and V count to V_TOTAL in
744 * progressive mode and V_TOTAL-1 in interlaced mode
746 OTG_FORCE_COUNT_NOW_MODE, 2);
751 void optc1_wait_for_state(struct timing_generator *optc,
752 enum crtc_state state)
754 struct optc *optc1 = DCN10TG_FROM_TG(optc);
757 case CRTC_STATE_VBLANK:
760 1, 100000); /* 1 vupdate at 10hz */
763 case CRTC_STATE_VACTIVE:
765 OTG_V_ACTIVE_DISP, 1,
766 1, 100000); /* 1 vupdate at 10hz */
774 void optc1_set_early_control(
775 struct timing_generator *optc,
778 /* asic design change, do not need this control
779 * empty for share caller logic
784 void optc1_set_static_screen_control(
785 struct timing_generator *optc,
788 struct optc *optc1 = DCN10TG_FROM_TG(optc);
790 /* Bit 8 is no longer applicable in RV for PSR case,
791 * set bit 8 to 0 if given
793 if ((value & STATIC_SCREEN_EVENT_MASK_RANGETIMING_DOUBLE_BUFFER_UPDATE_EN)
796 ~STATIC_SCREEN_EVENT_MASK_RANGETIMING_DOUBLE_BUFFER_UPDATE_EN;
798 REG_SET_2(OTG_STATIC_SCREEN_CONTROL, 0,
799 OTG_STATIC_SCREEN_EVENT_MASK, value,
800 OTG_STATIC_SCREEN_FRAME_COUNT, 2);
803 void optc1_setup_manual_trigger(struct timing_generator *optc)
805 struct optc *optc1 = DCN10TG_FROM_TG(optc);
807 REG_SET(OTG_GLOBAL_CONTROL2, 0,
808 MANUAL_FLOW_CONTROL_SEL, optc->inst);
810 REG_SET_8(OTG_TRIGA_CNTL, 0,
811 OTG_TRIGA_SOURCE_SELECT, 22,
812 OTG_TRIGA_SOURCE_PIPE_SELECT, optc->inst,
813 OTG_TRIGA_RISING_EDGE_DETECT_CNTL, 1,
814 OTG_TRIGA_FALLING_EDGE_DETECT_CNTL, 0,
815 OTG_TRIGA_POLARITY_SELECT, 0,
816 OTG_TRIGA_FREQUENCY_SELECT, 0,
821 void optc1_program_manual_trigger(struct timing_generator *optc)
823 struct optc *optc1 = DCN10TG_FROM_TG(optc);
825 REG_SET(OTG_MANUAL_FLOW_CONTROL, 0,
826 MANUAL_FLOW_CONTROL, 1);
828 REG_SET(OTG_MANUAL_FLOW_CONTROL, 0,
829 MANUAL_FLOW_CONTROL, 0);
834 *****************************************************************************
838 * Program dynamic refresh rate registers m_OTGx_OTG_V_TOTAL_*.
840 *****************************************************************************
843 struct timing_generator *optc,
844 const struct drr_params *params)
846 struct optc *optc1 = DCN10TG_FROM_TG(optc);
848 if (params != NULL &&
849 params->vertical_total_max > 0 &&
850 params->vertical_total_min > 0) {
852 REG_SET(OTG_V_TOTAL_MAX, 0,
853 OTG_V_TOTAL_MAX, params->vertical_total_max - 1);
855 REG_SET(OTG_V_TOTAL_MIN, 0,
856 OTG_V_TOTAL_MIN, params->vertical_total_min - 1);
858 REG_UPDATE_5(OTG_V_TOTAL_CONTROL,
859 OTG_V_TOTAL_MIN_SEL, 1,
860 OTG_V_TOTAL_MAX_SEL, 1,
861 OTG_FORCE_LOCK_ON_EVENT, 0,
862 OTG_SET_V_TOTAL_MIN_MASK_EN, 0,
863 OTG_SET_V_TOTAL_MIN_MASK, 0);
865 // Setup manual flow control for EOF via TRIG_A
866 optc->funcs->setup_manual_trigger(optc);
869 REG_UPDATE_4(OTG_V_TOTAL_CONTROL,
870 OTG_SET_V_TOTAL_MIN_MASK, 0,
871 OTG_V_TOTAL_MIN_SEL, 0,
872 OTG_V_TOTAL_MAX_SEL, 0,
873 OTG_FORCE_LOCK_ON_EVENT, 0);
875 REG_SET(OTG_V_TOTAL_MIN, 0,
878 REG_SET(OTG_V_TOTAL_MAX, 0,
883 static void optc1_set_test_pattern(
884 struct timing_generator *optc,
885 /* TODO: replace 'controller_dp_test_pattern' by 'test_pattern_mode'
886 * because this is not DP-specific (which is probably somewhere in DP
888 enum controller_dp_test_pattern test_pattern,
889 enum dc_color_depth color_depth)
891 struct optc *optc1 = DCN10TG_FROM_TG(optc);
892 enum test_pattern_color_format bit_depth;
893 enum test_pattern_dyn_range dyn_range;
894 enum test_pattern_mode mode;
895 uint32_t pattern_mask;
896 uint32_t pattern_data;
897 /* color ramp generator mixes 16-bits color */
898 uint32_t src_bpc = 16;
902 /* RGB values of the color bars.
903 * Produce two RGB colors: RGB0 - white (all Fs)
904 * and RGB1 - black (all 0s)
905 * (three RGB components for two colors)
907 uint16_t src_color[6] = {0xFFFF, 0xFFFF, 0xFFFF, 0x0000,
909 /* dest color (converted to the specified color format) */
910 uint16_t dst_color[6];
913 /* translate to bit depth */
914 switch (color_depth) {
915 case COLOR_DEPTH_666:
916 bit_depth = TEST_PATTERN_COLOR_FORMAT_BPC_6;
918 case COLOR_DEPTH_888:
919 bit_depth = TEST_PATTERN_COLOR_FORMAT_BPC_8;
921 case COLOR_DEPTH_101010:
922 bit_depth = TEST_PATTERN_COLOR_FORMAT_BPC_10;
924 case COLOR_DEPTH_121212:
925 bit_depth = TEST_PATTERN_COLOR_FORMAT_BPC_12;
928 bit_depth = TEST_PATTERN_COLOR_FORMAT_BPC_8;
932 switch (test_pattern) {
933 case CONTROLLER_DP_TEST_PATTERN_COLORSQUARES:
934 case CONTROLLER_DP_TEST_PATTERN_COLORSQUARES_CEA:
936 dyn_range = (test_pattern ==
937 CONTROLLER_DP_TEST_PATTERN_COLORSQUARES_CEA ?
938 TEST_PATTERN_DYN_RANGE_CEA :
939 TEST_PATTERN_DYN_RANGE_VESA);
940 mode = TEST_PATTERN_MODE_COLORSQUARES_RGB;
942 REG_UPDATE_2(OTG_TEST_PATTERN_PARAMETERS,
943 OTG_TEST_PATTERN_VRES, 6,
944 OTG_TEST_PATTERN_HRES, 6);
946 REG_UPDATE_4(OTG_TEST_PATTERN_CONTROL,
947 OTG_TEST_PATTERN_EN, 1,
948 OTG_TEST_PATTERN_MODE, mode,
949 OTG_TEST_PATTERN_DYNAMIC_RANGE, dyn_range,
950 OTG_TEST_PATTERN_COLOR_FORMAT, bit_depth);
954 case CONTROLLER_DP_TEST_PATTERN_VERTICALBARS:
955 case CONTROLLER_DP_TEST_PATTERN_HORIZONTALBARS:
957 mode = (test_pattern ==
958 CONTROLLER_DP_TEST_PATTERN_VERTICALBARS ?
959 TEST_PATTERN_MODE_VERTICALBARS :
960 TEST_PATTERN_MODE_HORIZONTALBARS);
963 case TEST_PATTERN_COLOR_FORMAT_BPC_6:
966 case TEST_PATTERN_COLOR_FORMAT_BPC_8:
969 case TEST_PATTERN_COLOR_FORMAT_BPC_10:
977 /* adjust color to the required colorFormat */
978 for (index = 0; index < 6; index++) {
979 /* dst = 2^dstBpc * src / 2^srcBpc = src >>
983 src_color[index] >> (src_bpc - dst_bpc);
984 /* CRTC_TEST_PATTERN_DATA has 16 bits,
985 * lowest 6 are hardwired to ZERO
986 * color bits should be left aligned aligned to MSB
987 * XXXXXXXXXX000000 for 10 bit,
988 * XXXXXXXX00000000 for 8 bit and XXXXXX0000000000 for 6
990 dst_color[index] <<= (16 - dst_bpc);
993 REG_WRITE(OTG_TEST_PATTERN_PARAMETERS, 0);
995 /* We have to write the mask before data, similar to pipeline.
996 * For example, for 8 bpc, if we want RGB0 to be magenta,
997 * and RGB1 to be cyan,
998 * we need to make 7 writes:
1000 * 000001 00000000 00000000 set mask to R0
1001 * 000010 11111111 00000000 R0 255, 0xFF00, set mask to G0
1002 * 000100 00000000 00000000 G0 0, 0x0000, set mask to B0
1003 * 001000 11111111 00000000 B0 255, 0xFF00, set mask to R1
1004 * 010000 00000000 00000000 R1 0, 0x0000, set mask to G1
1005 * 100000 11111111 00000000 G1 255, 0xFF00, set mask to B1
1006 * 100000 11111111 00000000 B1 255, 0xFF00
1008 * we will make a loop of 6 in which we prepare the mask,
1009 * then write, then prepare the color for next write.
1010 * first iteration will write mask only,
1011 * but each next iteration color prepared in
1012 * previous iteration will be written within new mask,
1013 * the last component will written separately,
1014 * mask is not changing between 6th and 7th write
1015 * and color will be prepared by last iteration
1018 /* write color, color values mask in CRTC_TEST_PATTERN_MASK
1019 * is B1, G1, R1, B0, G0, R0
1022 for (index = 0; index < 6; index++) {
1023 /* prepare color mask, first write PATTERN_DATA
1024 * will have all zeros
1026 pattern_mask = (1 << index);
1028 /* write color component */
1029 REG_SET_2(OTG_TEST_PATTERN_COLOR, 0,
1030 OTG_TEST_PATTERN_MASK, pattern_mask,
1031 OTG_TEST_PATTERN_DATA, pattern_data);
1033 /* prepare next color component,
1034 * will be written in the next iteration
1036 pattern_data = dst_color[index];
1038 /* write last color component,
1039 * it's been already prepared in the loop
1041 REG_SET_2(OTG_TEST_PATTERN_COLOR, 0,
1042 OTG_TEST_PATTERN_MASK, pattern_mask,
1043 OTG_TEST_PATTERN_DATA, pattern_data);
1045 /* enable test pattern */
1046 REG_UPDATE_4(OTG_TEST_PATTERN_CONTROL,
1047 OTG_TEST_PATTERN_EN, 1,
1048 OTG_TEST_PATTERN_MODE, mode,
1049 OTG_TEST_PATTERN_DYNAMIC_RANGE, 0,
1050 OTG_TEST_PATTERN_COLOR_FORMAT, bit_depth);
1054 case CONTROLLER_DP_TEST_PATTERN_COLORRAMP:
1056 mode = (bit_depth ==
1057 TEST_PATTERN_COLOR_FORMAT_BPC_10 ?
1058 TEST_PATTERN_MODE_DUALRAMP_RGB :
1059 TEST_PATTERN_MODE_SINGLERAMP_RGB);
1061 switch (bit_depth) {
1062 case TEST_PATTERN_COLOR_FORMAT_BPC_6:
1065 case TEST_PATTERN_COLOR_FORMAT_BPC_8:
1068 case TEST_PATTERN_COLOR_FORMAT_BPC_10:
1076 /* increment for the first ramp for one color gradation
1077 * 1 gradation for 6-bit color is 2^10
1078 * gradations in 16-bit color
1080 inc_base = (src_bpc - dst_bpc);
1082 switch (bit_depth) {
1083 case TEST_PATTERN_COLOR_FORMAT_BPC_6:
1085 REG_UPDATE_5(OTG_TEST_PATTERN_PARAMETERS,
1086 OTG_TEST_PATTERN_INC0, inc_base,
1087 OTG_TEST_PATTERN_INC1, 0,
1088 OTG_TEST_PATTERN_HRES, 6,
1089 OTG_TEST_PATTERN_VRES, 6,
1090 OTG_TEST_PATTERN_RAMP0_OFFSET, 0);
1093 case TEST_PATTERN_COLOR_FORMAT_BPC_8:
1095 REG_UPDATE_5(OTG_TEST_PATTERN_PARAMETERS,
1096 OTG_TEST_PATTERN_INC0, inc_base,
1097 OTG_TEST_PATTERN_INC1, 0,
1098 OTG_TEST_PATTERN_HRES, 8,
1099 OTG_TEST_PATTERN_VRES, 6,
1100 OTG_TEST_PATTERN_RAMP0_OFFSET, 0);
1103 case TEST_PATTERN_COLOR_FORMAT_BPC_10:
1105 REG_UPDATE_5(OTG_TEST_PATTERN_PARAMETERS,
1106 OTG_TEST_PATTERN_INC0, inc_base,
1107 OTG_TEST_PATTERN_INC1, inc_base + 2,
1108 OTG_TEST_PATTERN_HRES, 8,
1109 OTG_TEST_PATTERN_VRES, 5,
1110 OTG_TEST_PATTERN_RAMP0_OFFSET, 384 << 6);
1117 REG_WRITE(OTG_TEST_PATTERN_COLOR, 0);
1119 /* enable test pattern */
1120 REG_WRITE(OTG_TEST_PATTERN_CONTROL, 0);
1122 REG_SET_4(OTG_TEST_PATTERN_CONTROL, 0,
1123 OTG_TEST_PATTERN_EN, 1,
1124 OTG_TEST_PATTERN_MODE, mode,
1125 OTG_TEST_PATTERN_DYNAMIC_RANGE, 0,
1126 OTG_TEST_PATTERN_COLOR_FORMAT, bit_depth);
1129 case CONTROLLER_DP_TEST_PATTERN_VIDEOMODE:
1131 REG_WRITE(OTG_TEST_PATTERN_CONTROL, 0);
1132 REG_WRITE(OTG_TEST_PATTERN_COLOR, 0);
1133 REG_WRITE(OTG_TEST_PATTERN_PARAMETERS, 0);
1142 void optc1_get_crtc_scanoutpos(
1143 struct timing_generator *optc,
1144 uint32_t *v_blank_start,
1145 uint32_t *v_blank_end,
1146 uint32_t *h_position,
1147 uint32_t *v_position)
1149 struct optc *optc1 = DCN10TG_FROM_TG(optc);
1150 struct crtc_position position;
1152 REG_GET_2(OTG_V_BLANK_START_END,
1153 OTG_V_BLANK_START, v_blank_start,
1154 OTG_V_BLANK_END, v_blank_end);
1156 optc1_get_position(optc, &position);
1158 *h_position = position.horizontal_count;
1159 *v_position = position.vertical_count;
1162 static void optc1_enable_stereo(struct timing_generator *optc,
1163 const struct dc_crtc_timing *timing, struct crtc_stereo_flags *flags)
1165 struct optc *optc1 = DCN10TG_FROM_TG(optc);
1169 stereo_en = flags->FRAME_PACKED == 0 ? 1 : 0;
1171 if (flags->PROGRAM_STEREO)
1172 REG_UPDATE_3(OTG_STEREO_CONTROL,
1173 OTG_STEREO_EN, stereo_en,
1174 OTG_STEREO_SYNC_OUTPUT_LINE_NUM, 0,
1175 OTG_STEREO_SYNC_OUTPUT_POLARITY, 0);
1177 if (flags->PROGRAM_POLARITY)
1178 REG_UPDATE(OTG_STEREO_CONTROL,
1179 OTG_STEREO_EYE_FLAG_POLARITY,
1180 flags->RIGHT_EYE_POLARITY == 0 ? 0 : 1);
1182 if (flags->DISABLE_STEREO_DP_SYNC)
1183 REG_UPDATE(OTG_STEREO_CONTROL,
1184 OTG_DISABLE_STEREOSYNC_OUTPUT_FOR_DP, 1);
1186 if (flags->PROGRAM_STEREO)
1187 REG_UPDATE_2(OTG_3D_STRUCTURE_CONTROL,
1188 OTG_3D_STRUCTURE_EN, flags->FRAME_PACKED,
1189 OTG_3D_STRUCTURE_STEREO_SEL_OVR, flags->FRAME_PACKED);
1194 void optc1_program_stereo(struct timing_generator *optc,
1195 const struct dc_crtc_timing *timing, struct crtc_stereo_flags *flags)
1197 if (flags->PROGRAM_STEREO)
1198 optc1_enable_stereo(optc, timing, flags);
1200 optc1_disable_stereo(optc);
1204 bool optc1_is_stereo_left_eye(struct timing_generator *optc)
1207 uint32_t left_eye = 0;
1208 struct optc *optc1 = DCN10TG_FROM_TG(optc);
1210 REG_GET(OTG_STEREO_STATUS,
1211 OTG_STEREO_CURRENT_EYE, &left_eye);
1220 bool optc1_is_matching_timing(struct timing_generator *tg,
1221 const struct dc_crtc_timing *otg_timing)
1223 struct dc_crtc_timing hw_crtc_timing = {0};
1224 struct dcn_otg_state s = {0};
1226 if (tg == NULL || otg_timing == NULL)
1229 optc1_read_otg_state(DCN10TG_FROM_TG(tg), &s);
1231 hw_crtc_timing.h_total = s.h_total + 1;
1232 hw_crtc_timing.h_addressable = s.h_total - ((s.h_total - s.h_blank_start) + s.h_blank_end);
1233 hw_crtc_timing.h_front_porch = s.h_total + 1 - s.h_blank_start;
1234 hw_crtc_timing.h_sync_width = s.h_sync_a_end - s.h_sync_a_start;
1236 hw_crtc_timing.v_total = s.v_total + 1;
1237 hw_crtc_timing.v_addressable = s.v_total - ((s.v_total - s.v_blank_start) + s.v_blank_end);
1238 hw_crtc_timing.v_front_porch = s.v_total + 1 - s.v_blank_start;
1239 hw_crtc_timing.v_sync_width = s.v_sync_a_end - s.v_sync_a_start;
1241 if (otg_timing->h_total != hw_crtc_timing.h_total)
1244 if (otg_timing->h_border_left != hw_crtc_timing.h_border_left)
1247 if (otg_timing->h_addressable != hw_crtc_timing.h_addressable)
1250 if (otg_timing->h_border_right != hw_crtc_timing.h_border_right)
1253 if (otg_timing->h_front_porch != hw_crtc_timing.h_front_porch)
1256 if (otg_timing->h_sync_width != hw_crtc_timing.h_sync_width)
1259 if (otg_timing->v_total != hw_crtc_timing.v_total)
1262 if (otg_timing->v_border_top != hw_crtc_timing.v_border_top)
1265 if (otg_timing->v_addressable != hw_crtc_timing.v_addressable)
1268 if (otg_timing->v_border_bottom != hw_crtc_timing.v_border_bottom)
1271 if (otg_timing->v_sync_width != hw_crtc_timing.v_sync_width)
1278 void optc1_read_otg_state(struct optc *optc1,
1279 struct dcn_otg_state *s)
1281 REG_GET(OTG_CONTROL,
1282 OTG_MASTER_EN, &s->otg_enabled);
1284 REG_GET_2(OTG_V_BLANK_START_END,
1285 OTG_V_BLANK_START, &s->v_blank_start,
1286 OTG_V_BLANK_END, &s->v_blank_end);
1288 REG_GET(OTG_V_SYNC_A_CNTL,
1289 OTG_V_SYNC_A_POL, &s->v_sync_a_pol);
1291 REG_GET(OTG_V_TOTAL,
1292 OTG_V_TOTAL, &s->v_total);
1294 REG_GET(OTG_V_TOTAL_MAX,
1295 OTG_V_TOTAL_MAX, &s->v_total_max);
1297 REG_GET(OTG_V_TOTAL_MIN,
1298 OTG_V_TOTAL_MIN, &s->v_total_min);
1300 REG_GET(OTG_V_TOTAL_CONTROL,
1301 OTG_V_TOTAL_MAX_SEL, &s->v_total_max_sel);
1303 REG_GET(OTG_V_TOTAL_CONTROL,
1304 OTG_V_TOTAL_MIN_SEL, &s->v_total_min_sel);
1306 REG_GET_2(OTG_V_SYNC_A,
1307 OTG_V_SYNC_A_START, &s->v_sync_a_start,
1308 OTG_V_SYNC_A_END, &s->v_sync_a_end);
1310 REG_GET_2(OTG_H_BLANK_START_END,
1311 OTG_H_BLANK_START, &s->h_blank_start,
1312 OTG_H_BLANK_END, &s->h_blank_end);
1314 REG_GET_2(OTG_H_SYNC_A,
1315 OTG_H_SYNC_A_START, &s->h_sync_a_start,
1316 OTG_H_SYNC_A_END, &s->h_sync_a_end);
1318 REG_GET(OTG_H_SYNC_A_CNTL,
1319 OTG_H_SYNC_A_POL, &s->h_sync_a_pol);
1321 REG_GET(OTG_H_TOTAL,
1322 OTG_H_TOTAL, &s->h_total);
1324 REG_GET(OPTC_INPUT_GLOBAL_CONTROL,
1325 OPTC_UNDERFLOW_OCCURRED_STATUS, &s->underflow_occurred_status);
1328 bool optc1_get_otg_active_size(struct timing_generator *optc,
1329 uint32_t *otg_active_width,
1330 uint32_t *otg_active_height)
1332 uint32_t otg_enabled;
1333 uint32_t v_blank_start;
1334 uint32_t v_blank_end;
1335 uint32_t h_blank_start;
1336 uint32_t h_blank_end;
1337 struct optc *optc1 = DCN10TG_FROM_TG(optc);
1340 REG_GET(OTG_CONTROL,
1341 OTG_MASTER_EN, &otg_enabled);
1343 if (otg_enabled == 0)
1346 REG_GET_2(OTG_V_BLANK_START_END,
1347 OTG_V_BLANK_START, &v_blank_start,
1348 OTG_V_BLANK_END, &v_blank_end);
1350 REG_GET_2(OTG_H_BLANK_START_END,
1351 OTG_H_BLANK_START, &h_blank_start,
1352 OTG_H_BLANK_END, &h_blank_end);
1354 *otg_active_width = v_blank_start - v_blank_end;
1355 *otg_active_height = h_blank_start - h_blank_end;
1359 void optc1_clear_optc_underflow(struct timing_generator *optc)
1361 struct optc *optc1 = DCN10TG_FROM_TG(optc);
1363 REG_UPDATE(OPTC_INPUT_GLOBAL_CONTROL, OPTC_UNDERFLOW_CLEAR, 1);
1366 void optc1_tg_init(struct timing_generator *optc)
1368 optc1_set_blank_data_double_buffer(optc, true);
1369 optc1_clear_optc_underflow(optc);
1372 bool optc1_is_tg_enabled(struct timing_generator *optc)
1374 struct optc *optc1 = DCN10TG_FROM_TG(optc);
1375 uint32_t otg_enabled = 0;
1377 REG_GET(OTG_CONTROL, OTG_MASTER_EN, &otg_enabled);
1379 return (otg_enabled != 0);
1383 bool optc1_is_optc_underflow_occurred(struct timing_generator *optc)
1385 struct optc *optc1 = DCN10TG_FROM_TG(optc);
1386 uint32_t underflow_occurred = 0;
1388 REG_GET(OPTC_INPUT_GLOBAL_CONTROL,
1389 OPTC_UNDERFLOW_OCCURRED_STATUS,
1390 &underflow_occurred);
1392 return (underflow_occurred == 1);
1395 bool optc1_configure_crc(struct timing_generator *optc,
1396 const struct crc_params *params)
1398 struct optc *optc1 = DCN10TG_FROM_TG(optc);
1400 /* Cannot configure crc on a CRTC that is disabled */
1401 if (!optc1_is_tg_enabled(optc))
1404 REG_WRITE(OTG_CRC_CNTL, 0);
1406 if (!params->enable)
1409 /* Program frame boundaries */
1410 /* Window A x axis start and end. */
1411 REG_UPDATE_2(OTG_CRC0_WINDOWA_X_CONTROL,
1412 OTG_CRC0_WINDOWA_X_START, params->windowa_x_start,
1413 OTG_CRC0_WINDOWA_X_END, params->windowa_x_end);
1415 /* Window A y axis start and end. */
1416 REG_UPDATE_2(OTG_CRC0_WINDOWA_Y_CONTROL,
1417 OTG_CRC0_WINDOWA_Y_START, params->windowa_y_start,
1418 OTG_CRC0_WINDOWA_Y_END, params->windowa_y_end);
1420 /* Window B x axis start and end. */
1421 REG_UPDATE_2(OTG_CRC0_WINDOWB_X_CONTROL,
1422 OTG_CRC0_WINDOWB_X_START, params->windowb_x_start,
1423 OTG_CRC0_WINDOWB_X_END, params->windowb_x_end);
1425 /* Window B y axis start and end. */
1426 REG_UPDATE_2(OTG_CRC0_WINDOWB_Y_CONTROL,
1427 OTG_CRC0_WINDOWB_Y_START, params->windowb_y_start,
1428 OTG_CRC0_WINDOWB_Y_END, params->windowb_y_end);
1430 /* Set crc mode and selection, and enable. Only using CRC0*/
1431 REG_UPDATE_3(OTG_CRC_CNTL,
1432 OTG_CRC_CONT_EN, params->continuous_mode ? 1 : 0,
1433 OTG_CRC0_SELECT, params->selection,
1439 bool optc1_get_crc(struct timing_generator *optc,
1440 uint32_t *r_cr, uint32_t *g_y, uint32_t *b_cb)
1443 struct optc *optc1 = DCN10TG_FROM_TG(optc);
1445 REG_GET(OTG_CRC_CNTL, OTG_CRC_EN, &field);
1447 /* Early return if CRC is not enabled for this CRTC */
1451 REG_GET_2(OTG_CRC0_DATA_RG,
1455 REG_GET(OTG_CRC0_DATA_B,
1461 static const struct timing_generator_funcs dcn10_tg_funcs = {
1462 .validate_timing = optc1_validate_timing,
1463 .program_timing = optc1_program_timing,
1464 .setup_vertical_interrupt0 = optc1_setup_vertical_interrupt0,
1465 .setup_vertical_interrupt1 = optc1_setup_vertical_interrupt1,
1466 .setup_vertical_interrupt2 = optc1_setup_vertical_interrupt2,
1467 .program_global_sync = optc1_program_global_sync,
1468 .enable_crtc = optc1_enable_crtc,
1469 .disable_crtc = optc1_disable_crtc,
1470 /* used by enable_timing_synchronization. Not need for FPGA */
1471 .is_counter_moving = optc1_is_counter_moving,
1472 .get_position = optc1_get_position,
1473 .get_frame_count = optc1_get_vblank_counter,
1474 .get_scanoutpos = optc1_get_crtc_scanoutpos,
1475 .get_otg_active_size = optc1_get_otg_active_size,
1476 .is_matching_timing = optc1_is_matching_timing,
1477 .set_early_control = optc1_set_early_control,
1478 /* used by enable_timing_synchronization. Not need for FPGA */
1479 .wait_for_state = optc1_wait_for_state,
1480 .set_blank = optc1_set_blank,
1481 .is_blanked = optc1_is_blanked,
1482 .set_blank_color = optc1_program_blank_color,
1483 .did_triggered_reset_occur = optc1_did_triggered_reset_occur,
1484 .enable_reset_trigger = optc1_enable_reset_trigger,
1485 .enable_crtc_reset = optc1_enable_crtc_reset,
1486 .disable_reset_trigger = optc1_disable_reset_trigger,
1488 .unlock = optc1_unlock,
1489 .enable_optc_clock = optc1_enable_optc_clock,
1490 .set_drr = optc1_set_drr,
1491 .set_static_screen_control = optc1_set_static_screen_control,
1492 .set_test_pattern = optc1_set_test_pattern,
1493 .program_stereo = optc1_program_stereo,
1494 .is_stereo_left_eye = optc1_is_stereo_left_eye,
1495 .set_blank_data_double_buffer = optc1_set_blank_data_double_buffer,
1496 .tg_init = optc1_tg_init,
1497 .is_tg_enabled = optc1_is_tg_enabled,
1498 .is_optc_underflow_occurred = optc1_is_optc_underflow_occurred,
1499 .clear_optc_underflow = optc1_clear_optc_underflow,
1500 .get_crc = optc1_get_crc,
1501 .configure_crc = optc1_configure_crc,
1502 .set_vtg_params = optc1_set_vtg_params,
1503 .program_manual_trigger = optc1_program_manual_trigger,
1504 .setup_manual_trigger = optc1_setup_manual_trigger
1507 void dcn10_timing_generator_init(struct optc *optc1)
1509 optc1->base.funcs = &dcn10_tg_funcs;
1511 optc1->max_h_total = optc1->tg_mask->OTG_H_TOTAL + 1;
1512 optc1->max_v_total = optc1->tg_mask->OTG_V_TOTAL + 1;
1514 optc1->min_h_blank = 32;
1515 optc1->min_v_blank = 3;
1516 optc1->min_v_blank_interlace = 5;
1517 optc1->min_h_sync_width = 8;
1518 optc1->min_v_sync_width = 1;
1519 optc1->comb_opp_id = 0xf;
1522 #ifdef CONFIG_DRM_AMD_DC_DSC_SUPPORT
1523 /* "Containter" vs. "pixel" is a concept within HW blocks, mostly those closer to the back-end. It works like this:
1525 * - 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
1528 * - In 4:2:0 (DSC or uncompressed) there are two pixels per container, hence the target container rate has to be
1529 * halved to maintain the correct pixel rate.
1531 * - Unlike 4:2:2 uncompressed, DSC 4:2:2 Native also has two pixels per container (this happens when DSC is applied
1532 * 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.
1536 bool optc1_is_two_pixels_per_containter(const struct dc_crtc_timing *timing)
1538 bool two_pix = timing->pixel_encoding == PIXEL_ENCODING_YCBCR420;
1540 #ifdef CONFIG_DRM_AMD_DC_DSC_SUPPORT
1541 two_pix = two_pix || (timing->flags.DSC && timing->pixel_encoding == PIXEL_ENCODING_YCBCR422
1542 && !timing->dsc_cfg.ycbcr422_simple);