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
);
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
, true);
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 if (optc1_is_two_pixels_per_containter(&patched_crtc_timing
) || optc1
->opp_count
== 2)
289 h_div
= H_TIMING_DIV_BY2
;
291 if (REG(OPTC_DATA_FORMAT_CONTROL
)) {
292 uint32_t data_fmt
= 0;
294 if (patched_crtc_timing
.pixel_encoding
== PIXEL_ENCODING_YCBCR422
)
296 else if (patched_crtc_timing
.pixel_encoding
== PIXEL_ENCODING_YCBCR420
)
299 REG_UPDATE(OPTC_DATA_FORMAT_CONTROL
, OPTC_DATA_FORMAT
, data_fmt
);
302 if (optc1
->tg_mask
->OTG_H_TIMING_DIV_MODE
!= 0) {
303 if (optc1
->opp_count
== 4)
304 h_div
= H_TIMING_DIV_BY4
;
306 REG_UPDATE(OTG_H_TIMING_CNTL
,
307 OTG_H_TIMING_DIV_MODE
, h_div
);
309 REG_UPDATE(OTG_H_TIMING_CNTL
,
310 OTG_H_TIMING_DIV_BY2
, h_div
);
314 void optc1_set_vtg_params(struct timing_generator
*optc
,
315 const struct dc_crtc_timing
*dc_crtc_timing
, bool program_fp2
)
317 struct dc_crtc_timing patched_crtc_timing
;
318 uint32_t asic_blank_end
;
321 int32_t vertical_line_start
;
323 struct optc
*optc1
= DCN10TG_FROM_TG(optc
);
325 patched_crtc_timing
= *dc_crtc_timing
;
326 apply_front_porch_workaround(&patched_crtc_timing
);
328 /* VCOUNT_INIT is the start of blank */
329 v_init
= patched_crtc_timing
.v_total
- patched_crtc_timing
.v_front_porch
;
331 /* end of blank = v_init - active */
332 asic_blank_end
= v_init
-
333 patched_crtc_timing
.v_border_bottom
-
334 patched_crtc_timing
.v_addressable
-
335 patched_crtc_timing
.v_border_top
;
337 /* if VSTARTUP is before VSYNC, FP2 is the offset, otherwise 0 */
338 vertical_line_start
= asic_blank_end
- optc1
->vstartup_start
+ 1;
339 if (vertical_line_start
< 0)
340 v_fp2
= -vertical_line_start
;
343 if (REG(OTG_INTERLACE_CONTROL
)) {
344 if (patched_crtc_timing
.flags
.INTERLACE
== 1) {
346 if ((optc1
->vstartup_start
/2)*2 > asic_blank_end
)
352 REG_UPDATE_2(CONTROL
,
354 VTG0_VCOUNT_INIT
, v_init
);
356 REG_UPDATE(CONTROL
, VTG0_VCOUNT_INIT
, v_init
);
359 void optc1_set_blank_data_double_buffer(struct timing_generator
*optc
, bool enable
)
361 struct optc
*optc1
= DCN10TG_FROM_TG(optc
);
363 uint32_t blank_data_double_buffer_enable
= enable
? 1 : 0;
365 REG_UPDATE(OTG_DOUBLE_BUFFER_CONTROL
,
366 OTG_BLANK_DATA_DOUBLE_BUFFER_EN
, blank_data_double_buffer_enable
);
370 * optc1_set_timing_double_buffer() - DRR double buffering control
372 * Sets double buffer point for V_TOTAL, H_TOTAL, VTOTAL_MIN,
373 * VTOTAL_MAX, VTOTAL_MIN_SEL and VTOTAL_MAX_SEL registers.
375 * Options: any time, start of frame, dp start of frame (range timing)
377 void optc1_set_timing_double_buffer(struct timing_generator
*optc
, bool enable
)
379 struct optc
*optc1
= DCN10TG_FROM_TG(optc
);
380 uint32_t mode
= enable
? 2 : 0;
382 REG_UPDATE(OTG_DOUBLE_BUFFER_CONTROL
,
383 OTG_RANGE_TIMING_DBUF_UPDATE_MODE
, mode
);
388 * Call ASIC Control Object to UnBlank CRTC.
390 static void optc1_unblank_crtc(struct timing_generator
*optc
)
392 struct optc
*optc1
= DCN10TG_FROM_TG(optc
);
394 REG_UPDATE_2(OTG_BLANK_CONTROL
,
395 OTG_BLANK_DATA_EN
, 0,
396 OTG_BLANK_DE_MODE
, 0);
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.
405 optc1_clear_optc_underflow(optc
);
410 * Call ASIC Control Object to Blank CRTC.
413 static void optc1_blank_crtc(struct timing_generator
*optc
)
415 struct optc
*optc1
= DCN10TG_FROM_TG(optc
);
417 REG_UPDATE_2(OTG_BLANK_CONTROL
,
418 OTG_BLANK_DATA_EN
, 1,
419 OTG_BLANK_DE_MODE
, 0);
421 optc1_set_blank_data_double_buffer(optc
, false);
424 void optc1_set_blank(struct timing_generator
*optc
,
425 bool enable_blanking
)
428 optc1_blank_crtc(optc
);
430 optc1_unblank_crtc(optc
);
433 bool optc1_is_blanked(struct timing_generator
*optc
)
435 struct optc
*optc1
= DCN10TG_FROM_TG(optc
);
437 uint32_t blank_state
;
439 REG_GET_2(OTG_BLANK_CONTROL
,
440 OTG_BLANK_DATA_EN
, &blank_en
,
441 OTG_CURRENT_BLANK_STATE
, &blank_state
);
443 return blank_en
&& blank_state
;
446 void optc1_enable_optc_clock(struct timing_generator
*optc
, bool enable
)
448 struct optc
*optc1
= DCN10TG_FROM_TG(optc
);
451 REG_UPDATE_2(OPTC_INPUT_CLOCK_CONTROL
,
452 OPTC_INPUT_CLK_EN
, 1,
453 OPTC_INPUT_CLK_GATE_DIS
, 1);
455 REG_WAIT(OPTC_INPUT_CLOCK_CONTROL
,
456 OPTC_INPUT_CLK_ON
, 1,
460 REG_UPDATE_2(OTG_CLOCK_CONTROL
,
462 OTG_CLOCK_GATE_DIS
, 1);
463 REG_WAIT(OTG_CLOCK_CONTROL
,
467 REG_UPDATE_2(OTG_CLOCK_CONTROL
,
468 OTG_CLOCK_GATE_DIS
, 0,
471 REG_UPDATE_2(OPTC_INPUT_CLOCK_CONTROL
,
472 OPTC_INPUT_CLK_GATE_DIS
, 0,
473 OPTC_INPUT_CLK_EN
, 0);
479 * Enable CRTC - call ASIC Control Object to enable Timing generator.
481 static bool optc1_enable_crtc(struct timing_generator
*optc
)
483 /* TODO FPGA wait for answer
484 * OTG_MASTER_UPDATE_MODE != CRTC_MASTER_UPDATE_MODE
485 * OTG_MASTER_UPDATE_LOCK != CRTC_MASTER_UPDATE_LOCK
487 struct optc
*optc1
= DCN10TG_FROM_TG(optc
);
489 /* opp instance for OTG. For DCN1.0, ODM is remoed.
490 * OPP and OPTC should 1:1 mapping
492 REG_UPDATE(OPTC_DATA_SOURCE_SELECT
,
493 OPTC_SRC_SEL
, optc
->inst
);
495 /* VTG enable first is for HW workaround */
502 REG_UPDATE_2(OTG_CONTROL
,
503 OTG_DISABLE_POINT_CNTL
, 3,
512 /* disable_crtc - call ASIC Control Object to disable Timing generator. */
513 bool optc1_disable_crtc(struct timing_generator
*optc
)
515 struct optc
*optc1
= DCN10TG_FROM_TG(optc
);
517 /* disable otg request until end of the first line
518 * in the vertical blank region
520 REG_UPDATE_2(OTG_CONTROL
,
521 OTG_DISABLE_POINT_CNTL
, 3,
527 /* CRTC disabled, so disable clock. */
528 REG_WAIT(OTG_CLOCK_CONTROL
,
536 void optc1_program_blank_color(
537 struct timing_generator
*optc
,
538 const struct tg_color
*black_color
)
540 struct optc
*optc1
= DCN10TG_FROM_TG(optc
);
542 REG_SET_3(OTG_BLACK_COLOR
, 0,
543 OTG_BLACK_COLOR_B_CB
, black_color
->color_b_cb
,
544 OTG_BLACK_COLOR_G_Y
, black_color
->color_g_y
,
545 OTG_BLACK_COLOR_R_CR
, black_color
->color_r_cr
);
548 bool optc1_validate_timing(
549 struct timing_generator
*optc
,
550 const struct dc_crtc_timing
*timing
)
554 uint32_t min_v_blank
;
555 struct optc
*optc1
= DCN10TG_FROM_TG(optc
);
557 ASSERT(timing
!= NULL
);
559 v_blank
= (timing
->v_total
- timing
->v_addressable
-
560 timing
->v_border_top
- timing
->v_border_bottom
);
562 h_blank
= (timing
->h_total
- timing
->h_addressable
-
563 timing
->h_border_right
-
564 timing
->h_border_left
);
566 if (timing
->timing_3d_format
!= TIMING_3D_FORMAT_NONE
&&
567 timing
->timing_3d_format
!= TIMING_3D_FORMAT_HW_FRAME_PACKING
&&
568 timing
->timing_3d_format
!= TIMING_3D_FORMAT_TOP_AND_BOTTOM
&&
569 timing
->timing_3d_format
!= TIMING_3D_FORMAT_SIDE_BY_SIDE
&&
570 timing
->timing_3d_format
!= TIMING_3D_FORMAT_FRAME_ALTERNATE
&&
571 timing
->timing_3d_format
!= TIMING_3D_FORMAT_INBAND_FA
)
574 /* Temporarily blocking interlacing mode until it's supported */
575 if (timing
->flags
.INTERLACE
== 1)
578 /* Check maximum number of pixels supported by Timing Generator
579 * (Currently will never fail, in order to fail needs display which
580 * needs more than 8192 horizontal and
581 * more than 8192 vertical total pixels)
583 if (timing
->h_total
> optc1
->max_h_total
||
584 timing
->v_total
> optc1
->max_v_total
)
588 if (h_blank
< optc1
->min_h_blank
)
591 if (timing
->h_sync_width
< optc1
->min_h_sync_width
||
592 timing
->v_sync_width
< optc1
->min_v_sync_width
)
595 min_v_blank
= timing
->flags
.INTERLACE
?optc1
->min_v_blank_interlace
:optc1
->min_v_blank
;
597 if (v_blank
< min_v_blank
)
608 * Get counter for vertical blanks. use register CRTC_STATUS_FRAME_COUNT which
609 * holds the counter of frames.
612 * struct timing_generator *optc - [in] timing generator which controls the
616 * Counter of frames, which should equal to number of vblanks.
618 uint32_t optc1_get_vblank_counter(struct timing_generator
*optc
)
620 struct optc
*optc1
= DCN10TG_FROM_TG(optc
);
621 uint32_t frame_count
;
623 REG_GET(OTG_STATUS_FRAME_COUNT
,
624 OTG_FRAME_COUNT
, &frame_count
);
629 void optc1_lock(struct timing_generator
*optc
)
631 struct optc
*optc1
= DCN10TG_FROM_TG(optc
);
634 regval
= REG_READ(OTG_CONTROL
);
636 /* otg is not running, do not need to be locked */
637 if ((regval
& 0x1) == 0x0)
640 REG_SET(OTG_GLOBAL_CONTROL0
, 0,
641 OTG_MASTER_UPDATE_LOCK_SEL
, optc
->inst
);
642 REG_SET(OTG_MASTER_UPDATE_LOCK
, 0,
643 OTG_MASTER_UPDATE_LOCK
, 1);
645 /* Should be fast, status does not update on maximus */
646 if (optc
->ctx
->dce_environment
!= DCE_ENV_FPGA_MAXIMUS
) {
648 REG_WAIT(OTG_MASTER_UPDATE_LOCK
,
649 UPDATE_LOCK_STATUS
, 1,
654 void optc1_unlock(struct timing_generator
*optc
)
656 struct optc
*optc1
= DCN10TG_FROM_TG(optc
);
658 REG_SET(OTG_MASTER_UPDATE_LOCK
, 0,
659 OTG_MASTER_UPDATE_LOCK
, 0);
662 void optc1_get_position(struct timing_generator
*optc
,
663 struct crtc_position
*position
)
665 struct optc
*optc1
= DCN10TG_FROM_TG(optc
);
667 REG_GET_2(OTG_STATUS_POSITION
,
668 OTG_HORZ_COUNT
, &position
->horizontal_count
,
669 OTG_VERT_COUNT
, &position
->vertical_count
);
671 REG_GET(OTG_NOM_VERT_POSITION
,
672 OTG_VERT_COUNT_NOM
, &position
->nominal_vcount
);
675 bool optc1_is_counter_moving(struct timing_generator
*optc
)
677 struct crtc_position position1
, position2
;
679 optc
->funcs
->get_position(optc
, &position1
);
680 optc
->funcs
->get_position(optc
, &position2
);
682 if (position1
.horizontal_count
== position2
.horizontal_count
&&
683 position1
.vertical_count
== position2
.vertical_count
)
689 bool optc1_did_triggered_reset_occur(
690 struct timing_generator
*optc
)
692 struct optc
*optc1
= DCN10TG_FROM_TG(optc
);
693 uint32_t occurred_force
, occurred_vsync
;
695 REG_GET(OTG_FORCE_COUNT_NOW_CNTL
,
696 OTG_FORCE_COUNT_NOW_OCCURRED
, &occurred_force
);
698 REG_GET(OTG_VERT_SYNC_CONTROL
,
699 OTG_FORCE_VSYNC_NEXT_LINE_OCCURRED
, &occurred_vsync
);
701 return occurred_vsync
!= 0 || occurred_force
!= 0;
704 void optc1_disable_reset_trigger(struct timing_generator
*optc
)
706 struct optc
*optc1
= DCN10TG_FROM_TG(optc
);
708 REG_WRITE(OTG_TRIGA_CNTL
, 0);
710 REG_SET(OTG_FORCE_COUNT_NOW_CNTL
, 0,
711 OTG_FORCE_COUNT_NOW_CLEAR
, 1);
713 REG_SET(OTG_VERT_SYNC_CONTROL
, 0,
714 OTG_FORCE_VSYNC_NEXT_LINE_CLEAR
, 1);
717 void optc1_enable_reset_trigger(struct timing_generator
*optc
, int source_tg_inst
)
719 struct optc
*optc1
= DCN10TG_FROM_TG(optc
);
720 uint32_t falling_edge
;
722 REG_GET(OTG_V_SYNC_A_CNTL
,
723 OTG_V_SYNC_A_POL
, &falling_edge
);
726 REG_SET_3(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_FALLING_EDGE_DETECT_CNTL
, 1);
735 REG_SET_3(OTG_TRIGA_CNTL
, 0,
736 /* vsync signal from selected OTG pipe based
737 * on OTG_TRIG_SOURCE_PIPE_SELECT setting
739 OTG_TRIGA_SOURCE_SELECT
, 20,
740 OTG_TRIGA_SOURCE_PIPE_SELECT
, source_tg_inst
,
741 /* always detect rising edge */
742 OTG_TRIGA_RISING_EDGE_DETECT_CNTL
, 1);
744 REG_SET(OTG_FORCE_COUNT_NOW_CNTL
, 0,
745 /* force H count to H_TOTAL and V count to V_TOTAL in
746 * progressive mode and V_TOTAL-1 in interlaced mode
748 OTG_FORCE_COUNT_NOW_MODE
, 2);
751 void optc1_enable_crtc_reset(
752 struct timing_generator
*optc
,
754 struct crtc_trigger_info
*crtc_tp
)
756 struct optc
*optc1
= DCN10TG_FROM_TG(optc
);
757 uint32_t falling_edge
= 0;
758 uint32_t rising_edge
= 0;
760 switch (crtc_tp
->event
) {
762 case CRTC_EVENT_VSYNC_RISING
:
766 case CRTC_EVENT_VSYNC_FALLING
:
771 REG_SET_4(OTG_TRIGA_CNTL
, 0,
772 /* vsync signal from selected OTG pipe based
773 * on OTG_TRIG_SOURCE_PIPE_SELECT setting
775 OTG_TRIGA_SOURCE_SELECT
, 20,
776 OTG_TRIGA_SOURCE_PIPE_SELECT
, source_tg_inst
,
777 /* always detect falling edge */
778 OTG_TRIGA_RISING_EDGE_DETECT_CNTL
, rising_edge
,
779 OTG_TRIGA_FALLING_EDGE_DETECT_CNTL
, falling_edge
);
781 switch (crtc_tp
->delay
) {
782 case TRIGGER_DELAY_NEXT_LINE
:
783 REG_SET(OTG_VERT_SYNC_CONTROL
, 0,
784 OTG_AUTO_FORCE_VSYNC_MODE
, 1);
786 case TRIGGER_DELAY_NEXT_PIXEL
:
787 REG_SET(OTG_FORCE_COUNT_NOW_CNTL
, 0,
788 /* force H count to H_TOTAL and V count to V_TOTAL in
789 * progressive mode and V_TOTAL-1 in interlaced mode
791 OTG_FORCE_COUNT_NOW_MODE
, 2);
796 void optc1_wait_for_state(struct timing_generator
*optc
,
797 enum crtc_state state
)
799 struct optc
*optc1
= DCN10TG_FROM_TG(optc
);
802 case CRTC_STATE_VBLANK
:
805 1, 100000); /* 1 vupdate at 10hz */
808 case CRTC_STATE_VACTIVE
:
810 OTG_V_ACTIVE_DISP
, 1,
811 1, 100000); /* 1 vupdate at 10hz */
819 void optc1_set_early_control(
820 struct timing_generator
*optc
,
823 /* asic design change, do not need this control
824 * empty for share caller logic
829 void optc1_set_static_screen_control(
830 struct timing_generator
*optc
,
831 uint32_t event_triggers
,
834 struct optc
*optc1
= DCN10TG_FROM_TG(optc
);
836 // By register spec, it only takes 8 bit value
837 if (num_frames
> 0xFF)
840 /* Bit 8 is no longer applicable in RV for PSR case,
841 * set bit 8 to 0 if given
843 if ((event_triggers
& STATIC_SCREEN_EVENT_MASK_RANGETIMING_DOUBLE_BUFFER_UPDATE_EN
)
845 event_triggers
= event_triggers
&
846 ~STATIC_SCREEN_EVENT_MASK_RANGETIMING_DOUBLE_BUFFER_UPDATE_EN
;
848 REG_SET_2(OTG_STATIC_SCREEN_CONTROL
, 0,
849 OTG_STATIC_SCREEN_EVENT_MASK
, event_triggers
,
850 OTG_STATIC_SCREEN_FRAME_COUNT
, num_frames
);
853 void optc1_setup_manual_trigger(struct timing_generator
*optc
)
855 struct optc
*optc1
= DCN10TG_FROM_TG(optc
);
857 REG_SET(OTG_GLOBAL_CONTROL2
, 0,
858 MANUAL_FLOW_CONTROL_SEL
, optc
->inst
);
860 REG_SET_8(OTG_TRIGA_CNTL
, 0,
861 OTG_TRIGA_SOURCE_SELECT
, 22,
862 OTG_TRIGA_SOURCE_PIPE_SELECT
, optc
->inst
,
863 OTG_TRIGA_RISING_EDGE_DETECT_CNTL
, 1,
864 OTG_TRIGA_FALLING_EDGE_DETECT_CNTL
, 0,
865 OTG_TRIGA_POLARITY_SELECT
, 0,
866 OTG_TRIGA_FREQUENCY_SELECT
, 0,
871 void optc1_program_manual_trigger(struct timing_generator
*optc
)
873 struct optc
*optc1
= DCN10TG_FROM_TG(optc
);
875 REG_SET(OTG_MANUAL_FLOW_CONTROL
, 0,
876 MANUAL_FLOW_CONTROL
, 1);
878 REG_SET(OTG_MANUAL_FLOW_CONTROL
, 0,
879 MANUAL_FLOW_CONTROL
, 0);
884 *****************************************************************************
888 * Program dynamic refresh rate registers m_OTGx_OTG_V_TOTAL_*.
890 *****************************************************************************
893 struct timing_generator
*optc
,
894 const struct drr_params
*params
)
896 struct optc
*optc1
= DCN10TG_FROM_TG(optc
);
898 if (params
!= NULL
&&
899 params
->vertical_total_max
> 0 &&
900 params
->vertical_total_min
> 0) {
902 if (params
->vertical_total_mid
!= 0) {
904 REG_SET(OTG_V_TOTAL_MID
, 0,
905 OTG_V_TOTAL_MID
, params
->vertical_total_mid
- 1);
907 REG_UPDATE_2(OTG_V_TOTAL_CONTROL
,
908 OTG_VTOTAL_MID_REPLACING_MAX_EN
, 1,
909 OTG_VTOTAL_MID_FRAME_NUM
,
910 (uint8_t)params
->vertical_total_mid_frame_num
);
914 REG_SET(OTG_V_TOTAL_MAX
, 0,
915 OTG_V_TOTAL_MAX
, params
->vertical_total_max
- 1);
917 REG_SET(OTG_V_TOTAL_MIN
, 0,
918 OTG_V_TOTAL_MIN
, params
->vertical_total_min
- 1);
920 REG_UPDATE_5(OTG_V_TOTAL_CONTROL
,
921 OTG_V_TOTAL_MIN_SEL
, 1,
922 OTG_V_TOTAL_MAX_SEL
, 1,
923 OTG_FORCE_LOCK_ON_EVENT
, 0,
924 OTG_SET_V_TOTAL_MIN_MASK_EN
, 0,
925 OTG_SET_V_TOTAL_MIN_MASK
, 0);
927 // Setup manual flow control for EOF via TRIG_A
928 optc
->funcs
->setup_manual_trigger(optc
);
931 REG_UPDATE_4(OTG_V_TOTAL_CONTROL
,
932 OTG_SET_V_TOTAL_MIN_MASK
, 0,
933 OTG_V_TOTAL_MIN_SEL
, 0,
934 OTG_V_TOTAL_MAX_SEL
, 0,
935 OTG_FORCE_LOCK_ON_EVENT
, 0);
937 REG_SET(OTG_V_TOTAL_MIN
, 0,
940 REG_SET(OTG_V_TOTAL_MAX
, 0,
945 static void optc1_set_test_pattern(
946 struct timing_generator
*optc
,
947 /* TODO: replace 'controller_dp_test_pattern' by 'test_pattern_mode'
948 * because this is not DP-specific (which is probably somewhere in DP
950 enum controller_dp_test_pattern test_pattern
,
951 enum dc_color_depth color_depth
)
953 struct optc
*optc1
= DCN10TG_FROM_TG(optc
);
954 enum test_pattern_color_format bit_depth
;
955 enum test_pattern_dyn_range dyn_range
;
956 enum test_pattern_mode mode
;
957 uint32_t pattern_mask
;
958 uint32_t pattern_data
;
959 /* color ramp generator mixes 16-bits color */
960 uint32_t src_bpc
= 16;
964 /* RGB values of the color bars.
965 * Produce two RGB colors: RGB0 - white (all Fs)
966 * and RGB1 - black (all 0s)
967 * (three RGB components for two colors)
969 uint16_t src_color
[6] = {0xFFFF, 0xFFFF, 0xFFFF, 0x0000,
971 /* dest color (converted to the specified color format) */
972 uint16_t dst_color
[6];
975 /* translate to bit depth */
976 switch (color_depth
) {
977 case COLOR_DEPTH_666
:
978 bit_depth
= TEST_PATTERN_COLOR_FORMAT_BPC_6
;
980 case COLOR_DEPTH_888
:
981 bit_depth
= TEST_PATTERN_COLOR_FORMAT_BPC_8
;
983 case COLOR_DEPTH_101010
:
984 bit_depth
= TEST_PATTERN_COLOR_FORMAT_BPC_10
;
986 case COLOR_DEPTH_121212
:
987 bit_depth
= TEST_PATTERN_COLOR_FORMAT_BPC_12
;
990 bit_depth
= TEST_PATTERN_COLOR_FORMAT_BPC_8
;
994 switch (test_pattern
) {
995 case CONTROLLER_DP_TEST_PATTERN_COLORSQUARES
:
996 case CONTROLLER_DP_TEST_PATTERN_COLORSQUARES_CEA
:
998 dyn_range
= (test_pattern
==
999 CONTROLLER_DP_TEST_PATTERN_COLORSQUARES_CEA
?
1000 TEST_PATTERN_DYN_RANGE_CEA
:
1001 TEST_PATTERN_DYN_RANGE_VESA
);
1002 mode
= TEST_PATTERN_MODE_COLORSQUARES_RGB
;
1004 REG_UPDATE_2(OTG_TEST_PATTERN_PARAMETERS
,
1005 OTG_TEST_PATTERN_VRES
, 6,
1006 OTG_TEST_PATTERN_HRES
, 6);
1008 REG_UPDATE_4(OTG_TEST_PATTERN_CONTROL
,
1009 OTG_TEST_PATTERN_EN
, 1,
1010 OTG_TEST_PATTERN_MODE
, mode
,
1011 OTG_TEST_PATTERN_DYNAMIC_RANGE
, dyn_range
,
1012 OTG_TEST_PATTERN_COLOR_FORMAT
, bit_depth
);
1016 case CONTROLLER_DP_TEST_PATTERN_VERTICALBARS
:
1017 case CONTROLLER_DP_TEST_PATTERN_HORIZONTALBARS
:
1019 mode
= (test_pattern
==
1020 CONTROLLER_DP_TEST_PATTERN_VERTICALBARS
?
1021 TEST_PATTERN_MODE_VERTICALBARS
:
1022 TEST_PATTERN_MODE_HORIZONTALBARS
);
1024 switch (bit_depth
) {
1025 case TEST_PATTERN_COLOR_FORMAT_BPC_6
:
1028 case TEST_PATTERN_COLOR_FORMAT_BPC_8
:
1031 case TEST_PATTERN_COLOR_FORMAT_BPC_10
:
1039 /* adjust color to the required colorFormat */
1040 for (index
= 0; index
< 6; index
++) {
1041 /* dst = 2^dstBpc * src / 2^srcBpc = src >>
1042 * (srcBpc - dstBpc);
1045 src_color
[index
] >> (src_bpc
- dst_bpc
);
1046 /* CRTC_TEST_PATTERN_DATA has 16 bits,
1047 * lowest 6 are hardwired to ZERO
1048 * color bits should be left aligned aligned to MSB
1049 * XXXXXXXXXX000000 for 10 bit,
1050 * XXXXXXXX00000000 for 8 bit and XXXXXX0000000000 for 6
1052 dst_color
[index
] <<= (16 - dst_bpc
);
1055 REG_WRITE(OTG_TEST_PATTERN_PARAMETERS
, 0);
1057 /* We have to write the mask before data, similar to pipeline.
1058 * For example, for 8 bpc, if we want RGB0 to be magenta,
1059 * and RGB1 to be cyan,
1060 * we need to make 7 writes:
1062 * 000001 00000000 00000000 set mask to R0
1063 * 000010 11111111 00000000 R0 255, 0xFF00, set mask to G0
1064 * 000100 00000000 00000000 G0 0, 0x0000, set mask to B0
1065 * 001000 11111111 00000000 B0 255, 0xFF00, set mask to R1
1066 * 010000 00000000 00000000 R1 0, 0x0000, set mask to G1
1067 * 100000 11111111 00000000 G1 255, 0xFF00, set mask to B1
1068 * 100000 11111111 00000000 B1 255, 0xFF00
1070 * we will make a loop of 6 in which we prepare the mask,
1071 * then write, then prepare the color for next write.
1072 * first iteration will write mask only,
1073 * but each next iteration color prepared in
1074 * previous iteration will be written within new mask,
1075 * the last component will written separately,
1076 * mask is not changing between 6th and 7th write
1077 * and color will be prepared by last iteration
1080 /* write color, color values mask in CRTC_TEST_PATTERN_MASK
1081 * is B1, G1, R1, B0, G0, R0
1084 for (index
= 0; index
< 6; index
++) {
1085 /* prepare color mask, first write PATTERN_DATA
1086 * will have all zeros
1088 pattern_mask
= (1 << index
);
1090 /* write color component */
1091 REG_SET_2(OTG_TEST_PATTERN_COLOR
, 0,
1092 OTG_TEST_PATTERN_MASK
, pattern_mask
,
1093 OTG_TEST_PATTERN_DATA
, pattern_data
);
1095 /* prepare next color component,
1096 * will be written in the next iteration
1098 pattern_data
= dst_color
[index
];
1100 /* write last color component,
1101 * it's been already prepared in the loop
1103 REG_SET_2(OTG_TEST_PATTERN_COLOR
, 0,
1104 OTG_TEST_PATTERN_MASK
, pattern_mask
,
1105 OTG_TEST_PATTERN_DATA
, pattern_data
);
1107 /* enable test pattern */
1108 REG_UPDATE_4(OTG_TEST_PATTERN_CONTROL
,
1109 OTG_TEST_PATTERN_EN
, 1,
1110 OTG_TEST_PATTERN_MODE
, mode
,
1111 OTG_TEST_PATTERN_DYNAMIC_RANGE
, 0,
1112 OTG_TEST_PATTERN_COLOR_FORMAT
, bit_depth
);
1116 case CONTROLLER_DP_TEST_PATTERN_COLORRAMP
:
1118 mode
= (bit_depth
==
1119 TEST_PATTERN_COLOR_FORMAT_BPC_10
?
1120 TEST_PATTERN_MODE_DUALRAMP_RGB
:
1121 TEST_PATTERN_MODE_SINGLERAMP_RGB
);
1123 switch (bit_depth
) {
1124 case TEST_PATTERN_COLOR_FORMAT_BPC_6
:
1127 case TEST_PATTERN_COLOR_FORMAT_BPC_8
:
1130 case TEST_PATTERN_COLOR_FORMAT_BPC_10
:
1138 /* increment for the first ramp for one color gradation
1139 * 1 gradation for 6-bit color is 2^10
1140 * gradations in 16-bit color
1142 inc_base
= (src_bpc
- dst_bpc
);
1144 switch (bit_depth
) {
1145 case TEST_PATTERN_COLOR_FORMAT_BPC_6
:
1147 REG_UPDATE_5(OTG_TEST_PATTERN_PARAMETERS
,
1148 OTG_TEST_PATTERN_INC0
, inc_base
,
1149 OTG_TEST_PATTERN_INC1
, 0,
1150 OTG_TEST_PATTERN_HRES
, 6,
1151 OTG_TEST_PATTERN_VRES
, 6,
1152 OTG_TEST_PATTERN_RAMP0_OFFSET
, 0);
1155 case TEST_PATTERN_COLOR_FORMAT_BPC_8
:
1157 REG_UPDATE_5(OTG_TEST_PATTERN_PARAMETERS
,
1158 OTG_TEST_PATTERN_INC0
, inc_base
,
1159 OTG_TEST_PATTERN_INC1
, 0,
1160 OTG_TEST_PATTERN_HRES
, 8,
1161 OTG_TEST_PATTERN_VRES
, 6,
1162 OTG_TEST_PATTERN_RAMP0_OFFSET
, 0);
1165 case TEST_PATTERN_COLOR_FORMAT_BPC_10
:
1167 REG_UPDATE_5(OTG_TEST_PATTERN_PARAMETERS
,
1168 OTG_TEST_PATTERN_INC0
, inc_base
,
1169 OTG_TEST_PATTERN_INC1
, inc_base
+ 2,
1170 OTG_TEST_PATTERN_HRES
, 8,
1171 OTG_TEST_PATTERN_VRES
, 5,
1172 OTG_TEST_PATTERN_RAMP0_OFFSET
, 384 << 6);
1179 REG_WRITE(OTG_TEST_PATTERN_COLOR
, 0);
1181 /* enable test pattern */
1182 REG_WRITE(OTG_TEST_PATTERN_CONTROL
, 0);
1184 REG_SET_4(OTG_TEST_PATTERN_CONTROL
, 0,
1185 OTG_TEST_PATTERN_EN
, 1,
1186 OTG_TEST_PATTERN_MODE
, mode
,
1187 OTG_TEST_PATTERN_DYNAMIC_RANGE
, 0,
1188 OTG_TEST_PATTERN_COLOR_FORMAT
, bit_depth
);
1191 case CONTROLLER_DP_TEST_PATTERN_VIDEOMODE
:
1193 REG_WRITE(OTG_TEST_PATTERN_CONTROL
, 0);
1194 REG_WRITE(OTG_TEST_PATTERN_COLOR
, 0);
1195 REG_WRITE(OTG_TEST_PATTERN_PARAMETERS
, 0);
1204 void optc1_get_crtc_scanoutpos(
1205 struct timing_generator
*optc
,
1206 uint32_t *v_blank_start
,
1207 uint32_t *v_blank_end
,
1208 uint32_t *h_position
,
1209 uint32_t *v_position
)
1211 struct optc
*optc1
= DCN10TG_FROM_TG(optc
);
1212 struct crtc_position position
;
1214 REG_GET_2(OTG_V_BLANK_START_END
,
1215 OTG_V_BLANK_START
, v_blank_start
,
1216 OTG_V_BLANK_END
, v_blank_end
);
1218 optc1_get_position(optc
, &position
);
1220 *h_position
= position
.horizontal_count
;
1221 *v_position
= position
.vertical_count
;
1224 static void optc1_enable_stereo(struct timing_generator
*optc
,
1225 const struct dc_crtc_timing
*timing
, struct crtc_stereo_flags
*flags
)
1227 struct optc
*optc1
= DCN10TG_FROM_TG(optc
);
1231 stereo_en
= flags
->FRAME_PACKED
== 0 ? 1 : 0;
1233 if (flags
->PROGRAM_STEREO
)
1234 REG_UPDATE_3(OTG_STEREO_CONTROL
,
1235 OTG_STEREO_EN
, stereo_en
,
1236 OTG_STEREO_SYNC_OUTPUT_LINE_NUM
, 0,
1237 OTG_STEREO_SYNC_OUTPUT_POLARITY
, flags
->RIGHT_EYE_POLARITY
== 0 ? 0 : 1);
1239 if (flags
->PROGRAM_POLARITY
)
1240 REG_UPDATE(OTG_STEREO_CONTROL
,
1241 OTG_STEREO_EYE_FLAG_POLARITY
,
1242 flags
->RIGHT_EYE_POLARITY
== 0 ? 0 : 1);
1244 if (flags
->DISABLE_STEREO_DP_SYNC
)
1245 REG_UPDATE(OTG_STEREO_CONTROL
,
1246 OTG_DISABLE_STEREOSYNC_OUTPUT_FOR_DP
, 1);
1248 if (flags
->PROGRAM_STEREO
)
1249 REG_UPDATE_2(OTG_3D_STRUCTURE_CONTROL
,
1250 OTG_3D_STRUCTURE_EN
, flags
->FRAME_PACKED
,
1251 OTG_3D_STRUCTURE_STEREO_SEL_OVR
, flags
->FRAME_PACKED
);
1256 void optc1_program_stereo(struct timing_generator
*optc
,
1257 const struct dc_crtc_timing
*timing
, struct crtc_stereo_flags
*flags
)
1259 if (flags
->PROGRAM_STEREO
)
1260 optc1_enable_stereo(optc
, timing
, flags
);
1262 optc1_disable_stereo(optc
);
1266 bool optc1_is_stereo_left_eye(struct timing_generator
*optc
)
1269 uint32_t left_eye
= 0;
1270 struct optc
*optc1
= DCN10TG_FROM_TG(optc
);
1272 REG_GET(OTG_STEREO_STATUS
,
1273 OTG_STEREO_CURRENT_EYE
, &left_eye
);
1282 bool optc1_get_hw_timing(struct timing_generator
*tg
,
1283 struct dc_crtc_timing
*hw_crtc_timing
)
1285 struct dcn_otg_state s
= {0};
1287 if (tg
== NULL
|| hw_crtc_timing
== NULL
)
1290 optc1_read_otg_state(DCN10TG_FROM_TG(tg
), &s
);
1292 hw_crtc_timing
->h_total
= s
.h_total
+ 1;
1293 hw_crtc_timing
->h_addressable
= s
.h_total
- ((s
.h_total
- s
.h_blank_start
) + s
.h_blank_end
);
1294 hw_crtc_timing
->h_front_porch
= s
.h_total
+ 1 - s
.h_blank_start
;
1295 hw_crtc_timing
->h_sync_width
= s
.h_sync_a_end
- s
.h_sync_a_start
;
1297 hw_crtc_timing
->v_total
= s
.v_total
+ 1;
1298 hw_crtc_timing
->v_addressable
= s
.v_total
- ((s
.v_total
- s
.v_blank_start
) + s
.v_blank_end
);
1299 hw_crtc_timing
->v_front_porch
= s
.v_total
+ 1 - s
.v_blank_start
;
1300 hw_crtc_timing
->v_sync_width
= s
.v_sync_a_end
- s
.v_sync_a_start
;
1306 void optc1_read_otg_state(struct optc
*optc1
,
1307 struct dcn_otg_state
*s
)
1309 REG_GET(OTG_CONTROL
,
1310 OTG_MASTER_EN
, &s
->otg_enabled
);
1312 REG_GET_2(OTG_V_BLANK_START_END
,
1313 OTG_V_BLANK_START
, &s
->v_blank_start
,
1314 OTG_V_BLANK_END
, &s
->v_blank_end
);
1316 REG_GET(OTG_V_SYNC_A_CNTL
,
1317 OTG_V_SYNC_A_POL
, &s
->v_sync_a_pol
);
1319 REG_GET(OTG_V_TOTAL
,
1320 OTG_V_TOTAL
, &s
->v_total
);
1322 REG_GET(OTG_V_TOTAL_MAX
,
1323 OTG_V_TOTAL_MAX
, &s
->v_total_max
);
1325 REG_GET(OTG_V_TOTAL_MIN
,
1326 OTG_V_TOTAL_MIN
, &s
->v_total_min
);
1328 REG_GET(OTG_V_TOTAL_CONTROL
,
1329 OTG_V_TOTAL_MAX_SEL
, &s
->v_total_max_sel
);
1331 REG_GET(OTG_V_TOTAL_CONTROL
,
1332 OTG_V_TOTAL_MIN_SEL
, &s
->v_total_min_sel
);
1334 REG_GET_2(OTG_V_SYNC_A
,
1335 OTG_V_SYNC_A_START
, &s
->v_sync_a_start
,
1336 OTG_V_SYNC_A_END
, &s
->v_sync_a_end
);
1338 REG_GET_2(OTG_H_BLANK_START_END
,
1339 OTG_H_BLANK_START
, &s
->h_blank_start
,
1340 OTG_H_BLANK_END
, &s
->h_blank_end
);
1342 REG_GET_2(OTG_H_SYNC_A
,
1343 OTG_H_SYNC_A_START
, &s
->h_sync_a_start
,
1344 OTG_H_SYNC_A_END
, &s
->h_sync_a_end
);
1346 REG_GET(OTG_H_SYNC_A_CNTL
,
1347 OTG_H_SYNC_A_POL
, &s
->h_sync_a_pol
);
1349 REG_GET(OTG_H_TOTAL
,
1350 OTG_H_TOTAL
, &s
->h_total
);
1352 REG_GET(OPTC_INPUT_GLOBAL_CONTROL
,
1353 OPTC_UNDERFLOW_OCCURRED_STATUS
, &s
->underflow_occurred_status
);
1356 bool optc1_get_otg_active_size(struct timing_generator
*optc
,
1357 uint32_t *otg_active_width
,
1358 uint32_t *otg_active_height
)
1360 uint32_t otg_enabled
;
1361 uint32_t v_blank_start
;
1362 uint32_t v_blank_end
;
1363 uint32_t h_blank_start
;
1364 uint32_t h_blank_end
;
1365 struct optc
*optc1
= DCN10TG_FROM_TG(optc
);
1368 REG_GET(OTG_CONTROL
,
1369 OTG_MASTER_EN
, &otg_enabled
);
1371 if (otg_enabled
== 0)
1374 REG_GET_2(OTG_V_BLANK_START_END
,
1375 OTG_V_BLANK_START
, &v_blank_start
,
1376 OTG_V_BLANK_END
, &v_blank_end
);
1378 REG_GET_2(OTG_H_BLANK_START_END
,
1379 OTG_H_BLANK_START
, &h_blank_start
,
1380 OTG_H_BLANK_END
, &h_blank_end
);
1382 *otg_active_width
= v_blank_start
- v_blank_end
;
1383 *otg_active_height
= h_blank_start
- h_blank_end
;
1387 void optc1_clear_optc_underflow(struct timing_generator
*optc
)
1389 struct optc
*optc1
= DCN10TG_FROM_TG(optc
);
1391 REG_UPDATE(OPTC_INPUT_GLOBAL_CONTROL
, OPTC_UNDERFLOW_CLEAR
, 1);
1394 void optc1_tg_init(struct timing_generator
*optc
)
1396 optc1_set_blank_data_double_buffer(optc
, true);
1397 optc1_set_timing_double_buffer(optc
, true);
1398 optc1_clear_optc_underflow(optc
);
1401 bool optc1_is_tg_enabled(struct timing_generator
*optc
)
1403 struct optc
*optc1
= DCN10TG_FROM_TG(optc
);
1404 uint32_t otg_enabled
= 0;
1406 REG_GET(OTG_CONTROL
, OTG_MASTER_EN
, &otg_enabled
);
1408 return (otg_enabled
!= 0);
1412 bool optc1_is_optc_underflow_occurred(struct timing_generator
*optc
)
1414 struct optc
*optc1
= DCN10TG_FROM_TG(optc
);
1415 uint32_t underflow_occurred
= 0;
1417 REG_GET(OPTC_INPUT_GLOBAL_CONTROL
,
1418 OPTC_UNDERFLOW_OCCURRED_STATUS
,
1419 &underflow_occurred
);
1421 return (underflow_occurred
== 1);
1424 bool optc1_configure_crc(struct timing_generator
*optc
,
1425 const struct crc_params
*params
)
1427 struct optc
*optc1
= DCN10TG_FROM_TG(optc
);
1429 /* Cannot configure crc on a CRTC that is disabled */
1430 if (!optc1_is_tg_enabled(optc
))
1433 REG_WRITE(OTG_CRC_CNTL
, 0);
1435 if (!params
->enable
)
1438 /* Program frame boundaries */
1439 /* Window A x axis start and end. */
1440 REG_UPDATE_2(OTG_CRC0_WINDOWA_X_CONTROL
,
1441 OTG_CRC0_WINDOWA_X_START
, params
->windowa_x_start
,
1442 OTG_CRC0_WINDOWA_X_END
, params
->windowa_x_end
);
1444 /* Window A y axis start and end. */
1445 REG_UPDATE_2(OTG_CRC0_WINDOWA_Y_CONTROL
,
1446 OTG_CRC0_WINDOWA_Y_START
, params
->windowa_y_start
,
1447 OTG_CRC0_WINDOWA_Y_END
, params
->windowa_y_end
);
1449 /* Window B x axis start and end. */
1450 REG_UPDATE_2(OTG_CRC0_WINDOWB_X_CONTROL
,
1451 OTG_CRC0_WINDOWB_X_START
, params
->windowb_x_start
,
1452 OTG_CRC0_WINDOWB_X_END
, params
->windowb_x_end
);
1454 /* Window B y axis start and end. */
1455 REG_UPDATE_2(OTG_CRC0_WINDOWB_Y_CONTROL
,
1456 OTG_CRC0_WINDOWB_Y_START
, params
->windowb_y_start
,
1457 OTG_CRC0_WINDOWB_Y_END
, params
->windowb_y_end
);
1459 /* Set crc mode and selection, and enable. Only using CRC0*/
1460 REG_UPDATE_3(OTG_CRC_CNTL
,
1461 OTG_CRC_CONT_EN
, params
->continuous_mode
? 1 : 0,
1462 OTG_CRC0_SELECT
, params
->selection
,
1468 bool optc1_get_crc(struct timing_generator
*optc
,
1469 uint32_t *r_cr
, uint32_t *g_y
, uint32_t *b_cb
)
1472 struct optc
*optc1
= DCN10TG_FROM_TG(optc
);
1474 REG_GET(OTG_CRC_CNTL
, OTG_CRC_EN
, &field
);
1476 /* Early return if CRC is not enabled for this CRTC */
1480 REG_GET_2(OTG_CRC0_DATA_RG
,
1484 REG_GET(OTG_CRC0_DATA_B
,
1490 static const struct timing_generator_funcs dcn10_tg_funcs
= {
1491 .validate_timing
= optc1_validate_timing
,
1492 .program_timing
= optc1_program_timing
,
1493 .setup_vertical_interrupt0
= optc1_setup_vertical_interrupt0
,
1494 .setup_vertical_interrupt1
= optc1_setup_vertical_interrupt1
,
1495 .setup_vertical_interrupt2
= optc1_setup_vertical_interrupt2
,
1496 .program_global_sync
= optc1_program_global_sync
,
1497 .enable_crtc
= optc1_enable_crtc
,
1498 .disable_crtc
= optc1_disable_crtc
,
1499 /* used by enable_timing_synchronization. Not need for FPGA */
1500 .is_counter_moving
= optc1_is_counter_moving
,
1501 .get_position
= optc1_get_position
,
1502 .get_frame_count
= optc1_get_vblank_counter
,
1503 .get_scanoutpos
= optc1_get_crtc_scanoutpos
,
1504 .get_otg_active_size
= optc1_get_otg_active_size
,
1505 .set_early_control
= optc1_set_early_control
,
1506 /* used by enable_timing_synchronization. Not need for FPGA */
1507 .wait_for_state
= optc1_wait_for_state
,
1508 .set_blank
= optc1_set_blank
,
1509 .is_blanked
= optc1_is_blanked
,
1510 .set_blank_color
= optc1_program_blank_color
,
1511 .did_triggered_reset_occur
= optc1_did_triggered_reset_occur
,
1512 .enable_reset_trigger
= optc1_enable_reset_trigger
,
1513 .enable_crtc_reset
= optc1_enable_crtc_reset
,
1514 .disable_reset_trigger
= optc1_disable_reset_trigger
,
1516 .unlock
= optc1_unlock
,
1517 .enable_optc_clock
= optc1_enable_optc_clock
,
1518 .set_drr
= optc1_set_drr
,
1519 .set_static_screen_control
= optc1_set_static_screen_control
,
1520 .set_test_pattern
= optc1_set_test_pattern
,
1521 .program_stereo
= optc1_program_stereo
,
1522 .is_stereo_left_eye
= optc1_is_stereo_left_eye
,
1523 .set_blank_data_double_buffer
= optc1_set_blank_data_double_buffer
,
1524 .tg_init
= optc1_tg_init
,
1525 .is_tg_enabled
= optc1_is_tg_enabled
,
1526 .is_optc_underflow_occurred
= optc1_is_optc_underflow_occurred
,
1527 .clear_optc_underflow
= optc1_clear_optc_underflow
,
1528 .get_crc
= optc1_get_crc
,
1529 .configure_crc
= optc1_configure_crc
,
1530 .set_vtg_params
= optc1_set_vtg_params
,
1531 .program_manual_trigger
= optc1_program_manual_trigger
,
1532 .setup_manual_trigger
= optc1_setup_manual_trigger
,
1533 .get_hw_timing
= optc1_get_hw_timing
,
1536 void dcn10_timing_generator_init(struct optc
*optc1
)
1538 optc1
->base
.funcs
= &dcn10_tg_funcs
;
1540 optc1
->max_h_total
= optc1
->tg_mask
->OTG_H_TOTAL
+ 1;
1541 optc1
->max_v_total
= optc1
->tg_mask
->OTG_V_TOTAL
+ 1;
1543 optc1
->min_h_blank
= 32;
1544 optc1
->min_v_blank
= 3;
1545 optc1
->min_v_blank_interlace
= 5;
1546 optc1
->min_h_sync_width
= 4;
1547 optc1
->min_v_sync_width
= 1;
1550 /* "Containter" vs. "pixel" is a concept within HW blocks, mostly those closer to the back-end. It works like this:
1552 * - 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
1555 * - In 4:2:0 (DSC or uncompressed) there are two pixels per container, hence the target container rate has to be
1556 * halved to maintain the correct pixel rate.
1558 * - Unlike 4:2:2 uncompressed, DSC 4:2:2 Native also has two pixels per container (this happens when DSC is applied
1559 * 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.
1562 bool optc1_is_two_pixels_per_containter(const struct dc_crtc_timing
*timing
)
1564 bool two_pix
= timing
->pixel_encoding
== PIXEL_ENCODING_YCBCR420
;
1566 two_pix
= two_pix
|| (timing
->flags
.DSC
&& timing
->pixel_encoding
== PIXEL_ENCODING_YCBCR422
1567 && !timing
->dsc_cfg
.ycbcr422_simple
);