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.
26 #include <linux/delay.h>
27 #include <linux/slab.h>
29 #include "reg_helper.h"
31 #include "core_types.h"
32 #include "link_encoder.h"
33 #include "dcn10_link_encoder.h"
34 #include "stream_encoder.h"
35 #include "i2caux_interface.h"
36 #include "dc_bios_types.h"
38 #include "gpio_service_interface.h"
43 enc10->base.ctx->logger
46 (enc10->link_regs->reg)
49 #define FN(reg_name, field_name) \
50 enc10->link_shift->field_name, enc10->link_mask->field_name
55 * Trigger Source Select
56 * ASIC-dependent, actual values for register programming
58 #define DCN10_DIG_FE_SOURCE_SELECT_INVALID 0x0
59 #define DCN10_DIG_FE_SOURCE_SELECT_DIGA 0x1
60 #define DCN10_DIG_FE_SOURCE_SELECT_DIGB 0x2
61 #define DCN10_DIG_FE_SOURCE_SELECT_DIGC 0x4
62 #define DCN10_DIG_FE_SOURCE_SELECT_DIGD 0x08
63 #define DCN10_DIG_FE_SOURCE_SELECT_DIGE 0x10
64 #define DCN10_DIG_FE_SOURCE_SELECT_DIGF 0x20
65 #define DCN10_DIG_FE_SOURCE_SELECT_DIGG 0x40
68 DP_MST_UPDATE_MAX_RETRY = 50
71 static const struct link_encoder_funcs dcn10_lnk_enc_funcs = {
72 .validate_output_with_stream =
73 dcn10_link_encoder_validate_output_with_stream,
74 .hw_init = dcn10_link_encoder_hw_init,
75 .setup = dcn10_link_encoder_setup,
76 .enable_tmds_output = dcn10_link_encoder_enable_tmds_output,
77 .enable_dp_output = dcn10_link_encoder_enable_dp_output,
78 .enable_dp_mst_output = dcn10_link_encoder_enable_dp_mst_output,
79 .disable_output = dcn10_link_encoder_disable_output,
80 .dp_set_lane_settings = dcn10_link_encoder_dp_set_lane_settings,
81 .dp_set_phy_pattern = dcn10_link_encoder_dp_set_phy_pattern,
82 .update_mst_stream_allocation_table =
83 dcn10_link_encoder_update_mst_stream_allocation_table,
84 .psr_program_dp_dphy_fast_training =
85 dcn10_psr_program_dp_dphy_fast_training,
86 .psr_program_secondary_packet = dcn10_psr_program_secondary_packet,
87 .connect_dig_be_to_fe = dcn10_link_encoder_connect_dig_be_to_fe,
88 .enable_hpd = dcn10_link_encoder_enable_hpd,
89 .disable_hpd = dcn10_link_encoder_disable_hpd,
90 .is_dig_enabled = dcn10_is_dig_enabled,
91 .get_dig_frontend = dcn10_get_dig_frontend,
92 .destroy = dcn10_link_encoder_destroy
95 static enum bp_result link_transmitter_control(
96 struct dcn10_link_encoder *enc10,
97 struct bp_transmitter_control *cntl)
99 enum bp_result result;
100 struct dc_bios *bp = enc10->base.ctx->dc_bios;
102 result = bp->funcs->transmitter_control(bp, cntl);
107 static void enable_phy_bypass_mode(
108 struct dcn10_link_encoder *enc10,
111 /* This register resides in DP back end block;
112 * transmitter is used for the offset
114 REG_UPDATE(DP_DPHY_CNTL, DPHY_BYPASS, enable);
118 static void disable_prbs_symbols(
119 struct dcn10_link_encoder *enc10,
122 /* This register resides in DP back end block;
123 * transmitter is used for the offset
125 REG_UPDATE_4(DP_DPHY_CNTL,
126 DPHY_ATEST_SEL_LANE0, disable,
127 DPHY_ATEST_SEL_LANE1, disable,
128 DPHY_ATEST_SEL_LANE2, disable,
129 DPHY_ATEST_SEL_LANE3, disable);
132 static void disable_prbs_mode(
133 struct dcn10_link_encoder *enc10)
135 REG_UPDATE(DP_DPHY_PRBS_CNTL, DPHY_PRBS_EN, 0);
138 static void program_pattern_symbols(
139 struct dcn10_link_encoder *enc10,
140 uint16_t pattern_symbols[8])
142 /* This register resides in DP back end block;
143 * transmitter is used for the offset
145 REG_SET_3(DP_DPHY_SYM0, 0,
146 DPHY_SYM1, pattern_symbols[0],
147 DPHY_SYM2, pattern_symbols[1],
148 DPHY_SYM3, pattern_symbols[2]);
150 /* This register resides in DP back end block;
151 * transmitter is used for the offset
153 REG_SET_3(DP_DPHY_SYM1, 0,
154 DPHY_SYM4, pattern_symbols[3],
155 DPHY_SYM5, pattern_symbols[4],
156 DPHY_SYM6, pattern_symbols[5]);
158 /* This register resides in DP back end block;
159 * transmitter is used for the offset
161 REG_SET_2(DP_DPHY_SYM2, 0,
162 DPHY_SYM7, pattern_symbols[6],
163 DPHY_SYM8, pattern_symbols[7]);
166 static void set_dp_phy_pattern_d102(
167 struct dcn10_link_encoder *enc10)
169 /* Disable PHY Bypass mode to setup the test pattern */
170 enable_phy_bypass_mode(enc10, false);
172 /* For 10-bit PRBS or debug symbols
173 * please use the following sequence:
175 * Enable debug symbols on the lanes
177 disable_prbs_symbols(enc10, true);
179 /* Disable PRBS mode */
180 disable_prbs_mode(enc10);
182 /* Program debug symbols to be output */
184 uint16_t pattern_symbols[8] = {
185 0x2AA, 0x2AA, 0x2AA, 0x2AA,
186 0x2AA, 0x2AA, 0x2AA, 0x2AA
189 program_pattern_symbols(enc10, pattern_symbols);
192 /* Enable phy bypass mode to enable the test pattern */
194 enable_phy_bypass_mode(enc10, true);
197 static void set_link_training_complete(
198 struct dcn10_link_encoder *enc10,
201 /* This register resides in DP back end block;
202 * transmitter is used for the offset
204 REG_UPDATE(DP_LINK_CNTL, DP_LINK_TRAINING_COMPLETE, complete);
208 void dcn10_link_encoder_set_dp_phy_pattern_training_pattern(
209 struct link_encoder *enc,
212 struct dcn10_link_encoder *enc10 = TO_DCN10_LINK_ENC(enc);
213 /* Write Training Pattern */
215 REG_WRITE(DP_DPHY_TRAINING_PATTERN_SEL, index);
217 /* Set HW Register Training Complete to false */
219 set_link_training_complete(enc10, false);
221 /* Disable PHY Bypass mode to output Training Pattern */
223 enable_phy_bypass_mode(enc10, false);
225 /* Disable PRBS mode */
226 disable_prbs_mode(enc10);
229 static void setup_panel_mode(
230 struct dcn10_link_encoder *enc10,
231 enum dp_panel_mode panel_mode)
235 if (!REG(DP_DPHY_INTERNAL_CTRL))
238 value = REG_READ(DP_DPHY_INTERNAL_CTRL);
240 switch (panel_mode) {
241 case DP_PANEL_MODE_EDP:
244 case DP_PANEL_MODE_SPECIAL:
252 REG_WRITE(DP_DPHY_INTERNAL_CTRL, value);
255 static void set_dp_phy_pattern_symbol_error(
256 struct dcn10_link_encoder *enc10)
258 /* Disable PHY Bypass mode to setup the test pattern */
259 enable_phy_bypass_mode(enc10, false);
261 /* program correct panel mode*/
262 setup_panel_mode(enc10, DP_PANEL_MODE_DEFAULT);
264 /* A PRBS23 pattern is used for most DP electrical measurements. */
266 /* Enable PRBS symbols on the lanes */
267 disable_prbs_symbols(enc10, false);
269 /* For PRBS23 Set bit DPHY_PRBS_SEL=1 and Set bit DPHY_PRBS_EN=1 */
270 REG_UPDATE_2(DP_DPHY_PRBS_CNTL,
274 /* Enable phy bypass mode to enable the test pattern */
275 enable_phy_bypass_mode(enc10, true);
278 static void set_dp_phy_pattern_prbs7(
279 struct dcn10_link_encoder *enc10)
281 /* Disable PHY Bypass mode to setup the test pattern */
282 enable_phy_bypass_mode(enc10, false);
284 /* A PRBS7 pattern is used for most DP electrical measurements. */
286 /* Enable PRBS symbols on the lanes */
287 disable_prbs_symbols(enc10, false);
289 /* For PRBS7 Set bit DPHY_PRBS_SEL=0 and Set bit DPHY_PRBS_EN=1 */
290 REG_UPDATE_2(DP_DPHY_PRBS_CNTL,
294 /* Enable phy bypass mode to enable the test pattern */
295 enable_phy_bypass_mode(enc10, true);
298 static void set_dp_phy_pattern_80bit_custom(
299 struct dcn10_link_encoder *enc10,
300 const uint8_t *pattern)
302 /* Disable PHY Bypass mode to setup the test pattern */
303 enable_phy_bypass_mode(enc10, false);
305 /* Enable debug symbols on the lanes */
307 disable_prbs_symbols(enc10, true);
309 /* Enable PHY bypass mode to enable the test pattern */
310 /* TODO is it really needed ? */
312 enable_phy_bypass_mode(enc10, true);
314 /* Program 80 bit custom pattern */
316 uint16_t pattern_symbols[8];
319 ((pattern[1] & 0x03) << 8) | pattern[0];
321 ((pattern[2] & 0x0f) << 6) | ((pattern[1] >> 2) & 0x3f);
323 ((pattern[3] & 0x3f) << 4) | ((pattern[2] >> 4) & 0x0f);
325 (pattern[4] << 2) | ((pattern[3] >> 6) & 0x03);
327 ((pattern[6] & 0x03) << 8) | pattern[5];
329 ((pattern[7] & 0x0f) << 6) | ((pattern[6] >> 2) & 0x3f);
331 ((pattern[8] & 0x3f) << 4) | ((pattern[7] >> 4) & 0x0f);
333 (pattern[9] << 2) | ((pattern[8] >> 6) & 0x03);
335 program_pattern_symbols(enc10, pattern_symbols);
338 /* Enable phy bypass mode to enable the test pattern */
340 enable_phy_bypass_mode(enc10, true);
343 static void set_dp_phy_pattern_hbr2_compliance_cp2520_2(
344 struct dcn10_link_encoder *enc10,
345 unsigned int cp2520_pattern)
348 /* previously there is a register DP_HBR2_EYE_PATTERN
349 * that is enabled to get the pattern.
350 * But it does not work with the latest spec change,
351 * so we are programming the following registers manually.
353 * The following settings have been confirmed
354 * by Nick Chorney and Sandra Liu
357 /* Disable PHY Bypass mode to setup the test pattern */
359 enable_phy_bypass_mode(enc10, false);
361 /* Setup DIG encoder in DP SST mode */
362 enc10->base.funcs->setup(&enc10->base, SIGNAL_TYPE_DISPLAY_PORT);
364 /* ensure normal panel mode. */
365 setup_panel_mode(enc10, DP_PANEL_MODE_DEFAULT);
367 /* no vbid after BS (SR)
368 * DP_LINK_FRAMING_CNTL changed history Sandra Liu
369 * 11000260 / 11000104 / 110000FC
371 REG_UPDATE_3(DP_LINK_FRAMING_CNTL,
372 DP_IDLE_BS_INTERVAL, 0xFC,
374 DP_VID_ENHANCED_FRAME_MODE, 1);
376 /* swap every BS with SR */
377 REG_UPDATE(DP_DPHY_SCRAM_CNTL, DPHY_SCRAMBLER_BS_COUNT, 0);
379 /* select cp2520 patterns */
380 if (REG(DP_DPHY_HBR2_PATTERN_CONTROL))
381 REG_UPDATE(DP_DPHY_HBR2_PATTERN_CONTROL,
382 DP_DPHY_HBR2_PATTERN_CONTROL, cp2520_pattern);
384 /* pre-DCE11 can only generate CP2520 pattern 2 */
385 ASSERT(cp2520_pattern == 2);
387 /* set link training complete */
388 set_link_training_complete(enc10, true);
390 /* disable video stream */
391 REG_UPDATE(DP_VID_STREAM_CNTL, DP_VID_STREAM_ENABLE, 0);
393 /* Disable PHY Bypass mode to setup the test pattern */
394 enable_phy_bypass_mode(enc10, false);
397 static void set_dp_phy_pattern_passthrough_mode(
398 struct dcn10_link_encoder *enc10,
399 enum dp_panel_mode panel_mode)
401 /* program correct panel mode */
402 setup_panel_mode(enc10, panel_mode);
404 /* restore LINK_FRAMING_CNTL and DPHY_SCRAMBLER_BS_COUNT
405 * in case we were doing HBR2 compliance pattern before
407 REG_UPDATE_3(DP_LINK_FRAMING_CNTL,
408 DP_IDLE_BS_INTERVAL, 0x2000,
410 DP_VID_ENHANCED_FRAME_MODE, 1);
412 REG_UPDATE(DP_DPHY_SCRAM_CNTL, DPHY_SCRAMBLER_BS_COUNT, 0x1FF);
414 /* set link training complete */
415 set_link_training_complete(enc10, true);
417 /* Disable PHY Bypass mode to setup the test pattern */
418 enable_phy_bypass_mode(enc10, false);
420 /* Disable PRBS mode */
421 disable_prbs_mode(enc10);
424 /* return value is bit-vector */
425 static uint8_t get_frontend_source(
426 enum engine_id engine)
430 return DCN10_DIG_FE_SOURCE_SELECT_DIGA;
432 return DCN10_DIG_FE_SOURCE_SELECT_DIGB;
434 return DCN10_DIG_FE_SOURCE_SELECT_DIGC;
436 return DCN10_DIG_FE_SOURCE_SELECT_DIGD;
438 return DCN10_DIG_FE_SOURCE_SELECT_DIGE;
440 return DCN10_DIG_FE_SOURCE_SELECT_DIGF;
442 return DCN10_DIG_FE_SOURCE_SELECT_DIGG;
444 ASSERT_CRITICAL(false);
445 return DCN10_DIG_FE_SOURCE_SELECT_INVALID;
449 void enc1_configure_encoder(
450 struct dcn10_link_encoder *enc10,
451 const struct dc_link_settings *link_settings)
453 /* set number of lanes */
454 REG_SET(DP_CONFIG, 0,
455 DP_UDI_LANES, link_settings->lane_count - LANE_COUNT_ONE);
457 /* setup scrambler */
458 REG_UPDATE(DP_DPHY_SCRAM_CNTL, DPHY_SCRAMBLER_ADVANCE, 1);
461 void dcn10_psr_program_dp_dphy_fast_training(struct link_encoder *enc,
462 bool exit_link_training_required)
464 struct dcn10_link_encoder *enc10 = TO_DCN10_LINK_ENC(enc);
466 if (exit_link_training_required)
467 REG_UPDATE(DP_DPHY_FAST_TRAINING,
468 DPHY_RX_FAST_TRAINING_CAPABLE, 1);
470 REG_UPDATE(DP_DPHY_FAST_TRAINING,
471 DPHY_RX_FAST_TRAINING_CAPABLE, 0);
472 /*In DCE 11, we are able to pre-program a Force SR register
473 * to be able to trigger SR symbol after 5 idle patterns
474 * transmitted. Upon PSR Exit, DMCU can trigger
475 * DPHY_LOAD_BS_COUNT_START = 1. Upon writing 1 to
476 * DPHY_LOAD_BS_COUNT_START and the internal counter
477 * reaches DPHY_LOAD_BS_COUNT, the next BS symbol will be
478 * replaced by SR symbol once.
481 REG_UPDATE(DP_DPHY_BS_SR_SWAP_CNTL, DPHY_LOAD_BS_COUNT, 0x5);
485 void dcn10_psr_program_secondary_packet(struct link_encoder *enc,
486 unsigned int sdp_transmit_line_num_deadline)
488 struct dcn10_link_encoder *enc10 = TO_DCN10_LINK_ENC(enc);
490 REG_UPDATE_2(DP_SEC_CNTL1,
491 DP_SEC_GSP0_LINE_NUM, sdp_transmit_line_num_deadline,
492 DP_SEC_GSP0_PRIORITY, 1);
495 bool dcn10_is_dig_enabled(struct link_encoder *enc)
497 struct dcn10_link_encoder *enc10 = TO_DCN10_LINK_ENC(enc);
500 REG_GET(DIG_BE_EN_CNTL, DIG_ENABLE, &value);
504 unsigned int dcn10_get_dig_frontend(struct link_encoder *enc)
506 struct dcn10_link_encoder *enc10 = TO_DCN10_LINK_ENC(enc);
509 REG_GET(DIG_BE_CNTL, DIG_FE_SOURCE_SELECT, &value);
513 static void link_encoder_disable(struct dcn10_link_encoder *enc10)
515 /* reset training pattern */
516 REG_SET(DP_DPHY_TRAINING_PATTERN_SEL, 0,
517 DPHY_TRAINING_PATTERN_SEL, 0);
519 /* reset training complete */
520 REG_UPDATE(DP_LINK_CNTL, DP_LINK_TRAINING_COMPLETE, 0);
522 /* reset panel mode */
523 setup_panel_mode(enc10, DP_PANEL_MODE_DEFAULT);
526 static void hpd_initialize(
527 struct dcn10_link_encoder *enc10)
529 /* Associate HPD with DIG_BE */
530 enum hpd_source_id hpd_source = enc10->base.hpd_source;
532 REG_UPDATE(DIG_BE_CNTL, DIG_HPD_SELECT, hpd_source);
535 bool dcn10_link_encoder_validate_dvi_output(
536 const struct dcn10_link_encoder *enc10,
537 enum signal_type connector_signal,
538 enum signal_type signal,
539 const struct dc_crtc_timing *crtc_timing)
541 uint32_t max_pixel_clock = TMDS_MAX_PIXEL_CLOCK;
543 if (signal == SIGNAL_TYPE_DVI_DUAL_LINK)
544 max_pixel_clock *= 2;
546 /* This handles the case of HDMI downgrade to DVI we don't want to
547 * we don't want to cap the pixel clock if the DDI is not DVI.
549 if (connector_signal != SIGNAL_TYPE_DVI_DUAL_LINK &&
550 connector_signal != SIGNAL_TYPE_DVI_SINGLE_LINK)
551 max_pixel_clock = enc10->base.features.max_hdmi_pixel_clock;
553 /* DVI only support RGB pixel encoding */
554 if (crtc_timing->pixel_encoding != PIXEL_ENCODING_RGB)
557 /*connect DVI via adpater's HDMI connector*/
558 if ((connector_signal == SIGNAL_TYPE_DVI_SINGLE_LINK ||
559 connector_signal == SIGNAL_TYPE_HDMI_TYPE_A) &&
560 signal != SIGNAL_TYPE_HDMI_TYPE_A &&
561 crtc_timing->pix_clk_100hz > (TMDS_MAX_PIXEL_CLOCK * 10))
563 if (crtc_timing->pix_clk_100hz < (TMDS_MIN_PIXEL_CLOCK * 10))
566 if (crtc_timing->pix_clk_100hz > (max_pixel_clock * 10))
569 /* DVI supports 6/8bpp single-link and 10/16bpp dual-link */
570 switch (crtc_timing->display_color_depth) {
571 case COLOR_DEPTH_666:
572 case COLOR_DEPTH_888:
574 case COLOR_DEPTH_101010:
575 case COLOR_DEPTH_161616:
576 if (signal != SIGNAL_TYPE_DVI_DUAL_LINK)
586 static bool dcn10_link_encoder_validate_hdmi_output(
587 const struct dcn10_link_encoder *enc10,
588 const struct dc_crtc_timing *crtc_timing,
589 int adjusted_pix_clk_100hz)
591 enum dc_color_depth max_deep_color =
592 enc10->base.features.max_hdmi_deep_color;
594 if (max_deep_color < crtc_timing->display_color_depth)
597 if (crtc_timing->display_color_depth < COLOR_DEPTH_888)
599 if (adjusted_pix_clk_100hz < (TMDS_MIN_PIXEL_CLOCK * 10))
602 if ((adjusted_pix_clk_100hz == 0) ||
603 (adjusted_pix_clk_100hz > (enc10->base.features.max_hdmi_pixel_clock * 10)))
606 /* DCE11 HW does not support 420 */
607 if (!enc10->base.features.hdmi_ycbcr420_supported &&
608 crtc_timing->pixel_encoding == PIXEL_ENCODING_YCBCR420)
611 if (!enc10->base.features.flags.bits.HDMI_6GB_EN &&
612 adjusted_pix_clk_100hz >= 3000000)
614 if (enc10->base.ctx->dc->debug.hdmi20_disable &&
615 crtc_timing->pixel_encoding == PIXEL_ENCODING_YCBCR420)
620 bool dcn10_link_encoder_validate_dp_output(
621 const struct dcn10_link_encoder *enc10,
622 const struct dc_crtc_timing *crtc_timing)
624 if (crtc_timing->pixel_encoding == PIXEL_ENCODING_YCBCR420) {
625 if (!enc10->base.features.dp_ycbcr420_supported)
632 void dcn10_link_encoder_construct(
633 struct dcn10_link_encoder *enc10,
634 const struct encoder_init_data *init_data,
635 const struct encoder_feature_support *enc_features,
636 const struct dcn10_link_enc_registers *link_regs,
637 const struct dcn10_link_enc_aux_registers *aux_regs,
638 const struct dcn10_link_enc_hpd_registers *hpd_regs,
639 const struct dcn10_link_enc_shift *link_shift,
640 const struct dcn10_link_enc_mask *link_mask)
642 struct bp_encoder_cap_info bp_cap_info = {0};
643 const struct dc_vbios_funcs *bp_funcs = init_data->ctx->dc_bios->funcs;
644 enum bp_result result = BP_RESULT_OK;
646 enc10->base.funcs = &dcn10_lnk_enc_funcs;
647 enc10->base.ctx = init_data->ctx;
648 enc10->base.id = init_data->encoder;
650 enc10->base.hpd_source = init_data->hpd_source;
651 enc10->base.connector = init_data->connector;
653 enc10->base.preferred_engine = ENGINE_ID_UNKNOWN;
655 enc10->base.features = *enc_features;
657 enc10->base.transmitter = init_data->transmitter;
659 /* set the flag to indicate whether driver poll the I2C data pin
660 * while doing the DP sink detect
663 /* if (dal_adapter_service_is_feature_supported(as,
664 FEATURE_DP_SINK_DETECT_POLL_DATA_PIN))
665 enc10->base.features.flags.bits.
666 DP_SINK_DETECT_POLL_DATA_PIN = true;*/
668 enc10->base.output_signals =
669 SIGNAL_TYPE_DVI_SINGLE_LINK |
670 SIGNAL_TYPE_DVI_DUAL_LINK |
672 SIGNAL_TYPE_DISPLAY_PORT |
673 SIGNAL_TYPE_DISPLAY_PORT_MST |
675 SIGNAL_TYPE_HDMI_TYPE_A;
677 /* For DCE 8.0 and 8.1, by design, UNIPHY is hardwired to DIG_BE.
678 * SW always assign DIG_FE 1:1 mapped to DIG_FE for non-MST UNIPHY.
679 * SW assign DIG_FE to non-MST UNIPHY first and MST last. So prefer
680 * DIG is per UNIPHY and used by SST DP, eDP, HDMI, DVI and LVDS.
681 * Prefer DIG assignment is decided by board design.
682 * For DCE 8.0, there are only max 6 UNIPHYs, we assume board design
683 * and VBIOS will filter out 7 UNIPHY for DCE 8.0.
684 * By this, adding DIGG should not hurt DCE 8.0.
685 * This will let DCE 8.1 share DCE 8.0 as much as possible
688 enc10->link_regs = link_regs;
689 enc10->aux_regs = aux_regs;
690 enc10->hpd_regs = hpd_regs;
691 enc10->link_shift = link_shift;
692 enc10->link_mask = link_mask;
694 switch (enc10->base.transmitter) {
695 case TRANSMITTER_UNIPHY_A:
696 enc10->base.preferred_engine = ENGINE_ID_DIGA;
698 case TRANSMITTER_UNIPHY_B:
699 enc10->base.preferred_engine = ENGINE_ID_DIGB;
701 case TRANSMITTER_UNIPHY_C:
702 enc10->base.preferred_engine = ENGINE_ID_DIGC;
704 case TRANSMITTER_UNIPHY_D:
705 enc10->base.preferred_engine = ENGINE_ID_DIGD;
707 case TRANSMITTER_UNIPHY_E:
708 enc10->base.preferred_engine = ENGINE_ID_DIGE;
710 case TRANSMITTER_UNIPHY_F:
711 enc10->base.preferred_engine = ENGINE_ID_DIGF;
713 case TRANSMITTER_UNIPHY_G:
714 enc10->base.preferred_engine = ENGINE_ID_DIGG;
717 ASSERT_CRITICAL(false);
718 enc10->base.preferred_engine = ENGINE_ID_UNKNOWN;
721 /* default to one to mirror Windows behavior */
722 enc10->base.features.flags.bits.HDMI_6GB_EN = 1;
724 result = bp_funcs->get_encoder_cap_info(enc10->base.ctx->dc_bios,
725 enc10->base.id, &bp_cap_info);
727 /* Override features with DCE-specific values */
728 if (result == BP_RESULT_OK) {
729 enc10->base.features.flags.bits.IS_HBR2_CAPABLE =
730 bp_cap_info.DP_HBR2_EN;
731 enc10->base.features.flags.bits.IS_HBR3_CAPABLE =
732 bp_cap_info.DP_HBR3_EN;
733 enc10->base.features.flags.bits.HDMI_6GB_EN = bp_cap_info.HDMI_6GB_EN;
734 enc10->base.features.flags.bits.DP_IS_USB_C =
735 bp_cap_info.DP_IS_USB_C;
737 DC_LOG_WARNING("%s: Failed to get encoder_cap_info from VBIOS with error code %d!\n",
741 if (enc10->base.ctx->dc->debug.hdmi20_disable) {
742 enc10->base.features.flags.bits.HDMI_6GB_EN = 0;
746 bool dcn10_link_encoder_validate_output_with_stream(
747 struct link_encoder *enc,
748 const struct dc_stream_state *stream)
750 struct dcn10_link_encoder *enc10 = TO_DCN10_LINK_ENC(enc);
753 switch (stream->signal) {
754 case SIGNAL_TYPE_DVI_SINGLE_LINK:
755 case SIGNAL_TYPE_DVI_DUAL_LINK:
756 is_valid = dcn10_link_encoder_validate_dvi_output(
758 stream->link->connector_signal,
762 case SIGNAL_TYPE_HDMI_TYPE_A:
763 is_valid = dcn10_link_encoder_validate_hdmi_output(
766 stream->phy_pix_clk * 10);
768 case SIGNAL_TYPE_DISPLAY_PORT:
769 case SIGNAL_TYPE_DISPLAY_PORT_MST:
770 is_valid = dcn10_link_encoder_validate_dp_output(
771 enc10, &stream->timing);
773 case SIGNAL_TYPE_EDP:
774 is_valid = (stream->timing.pixel_encoding == PIXEL_ENCODING_RGB) ? true : false;
776 case SIGNAL_TYPE_VIRTUAL:
787 void dcn10_link_encoder_hw_init(
788 struct link_encoder *enc)
790 struct dcn10_link_encoder *enc10 = TO_DCN10_LINK_ENC(enc);
791 struct bp_transmitter_control cntl = { 0 };
792 enum bp_result result;
794 cntl.action = TRANSMITTER_CONTROL_INIT;
795 cntl.engine_id = ENGINE_ID_UNKNOWN;
796 cntl.transmitter = enc10->base.transmitter;
797 cntl.connector_obj_id = enc10->base.connector;
798 cntl.lanes_number = LANE_COUNT_FOUR;
799 cntl.coherent = false;
800 cntl.hpd_sel = enc10->base.hpd_source;
802 if (enc10->base.connector.id == CONNECTOR_ID_EDP)
803 cntl.signal = SIGNAL_TYPE_EDP;
805 result = link_transmitter_control(enc10, &cntl);
807 if (result != BP_RESULT_OK) {
808 DC_LOG_ERROR("%s: Failed to execute VBIOS command table!\n",
814 if (enc10->base.connector.id == CONNECTOR_ID_LVDS) {
815 cntl.action = TRANSMITTER_CONTROL_BACKLIGHT_BRIGHTNESS;
817 result = link_transmitter_control(enc10, &cntl);
819 ASSERT(result == BP_RESULT_OK);
822 dcn10_aux_initialize(enc10);
825 * hpd_initialize() will pass DIG_FE id to HW context.
826 * All other routine within HW context will use fe_engine_offset
827 * as DIG_FE id even caller pass DIG_FE id.
828 * So this routine must be called first.
830 hpd_initialize(enc10);
833 void dcn10_link_encoder_destroy(struct link_encoder **enc)
835 kfree(TO_DCN10_LINK_ENC(*enc));
839 void dcn10_link_encoder_setup(
840 struct link_encoder *enc,
841 enum signal_type signal)
843 struct dcn10_link_encoder *enc10 = TO_DCN10_LINK_ENC(enc);
846 case SIGNAL_TYPE_EDP:
847 case SIGNAL_TYPE_DISPLAY_PORT:
849 REG_UPDATE(DIG_BE_CNTL, DIG_MODE, 0);
851 case SIGNAL_TYPE_LVDS:
853 REG_UPDATE(DIG_BE_CNTL, DIG_MODE, 1);
855 case SIGNAL_TYPE_DVI_SINGLE_LINK:
856 case SIGNAL_TYPE_DVI_DUAL_LINK:
858 REG_UPDATE(DIG_BE_CNTL, DIG_MODE, 2);
860 case SIGNAL_TYPE_HDMI_TYPE_A:
862 REG_UPDATE(DIG_BE_CNTL, DIG_MODE, 3);
864 case SIGNAL_TYPE_DISPLAY_PORT_MST:
866 REG_UPDATE(DIG_BE_CNTL, DIG_MODE, 5);
869 ASSERT_CRITICAL(false);
876 /* TODO: still need depth or just pass in adjusted pixel clock? */
877 void dcn10_link_encoder_enable_tmds_output(
878 struct link_encoder *enc,
879 enum clock_source_id clock_source,
880 enum dc_color_depth color_depth,
881 enum signal_type signal,
882 uint32_t pixel_clock)
884 struct dcn10_link_encoder *enc10 = TO_DCN10_LINK_ENC(enc);
885 struct bp_transmitter_control cntl = { 0 };
886 enum bp_result result;
890 cntl.action = TRANSMITTER_CONTROL_ENABLE;
891 cntl.engine_id = enc->preferred_engine;
892 cntl.transmitter = enc10->base.transmitter;
893 cntl.pll_id = clock_source;
894 cntl.signal = signal;
895 if (cntl.signal == SIGNAL_TYPE_DVI_DUAL_LINK)
896 cntl.lanes_number = 8;
898 cntl.lanes_number = 4;
900 cntl.hpd_sel = enc10->base.hpd_source;
902 cntl.pixel_clock = pixel_clock;
903 cntl.color_depth = color_depth;
905 result = link_transmitter_control(enc10, &cntl);
907 if (result != BP_RESULT_OK) {
908 DC_LOG_ERROR("%s: Failed to execute VBIOS command table!\n",
914 /* enables DP PHY output */
915 void dcn10_link_encoder_enable_dp_output(
916 struct link_encoder *enc,
917 const struct dc_link_settings *link_settings,
918 enum clock_source_id clock_source)
920 struct dcn10_link_encoder *enc10 = TO_DCN10_LINK_ENC(enc);
921 struct bp_transmitter_control cntl = { 0 };
922 enum bp_result result;
926 /* number_of_lanes is used for pixel clock adjust,
927 * but it's not passed to asic_control.
928 * We need to set number of lanes manually.
930 enc1_configure_encoder(enc10, link_settings);
932 cntl.action = TRANSMITTER_CONTROL_ENABLE;
933 cntl.engine_id = enc->preferred_engine;
934 cntl.transmitter = enc10->base.transmitter;
935 cntl.pll_id = clock_source;
936 cntl.signal = SIGNAL_TYPE_DISPLAY_PORT;
937 cntl.lanes_number = link_settings->lane_count;
938 cntl.hpd_sel = enc10->base.hpd_source;
939 cntl.pixel_clock = link_settings->link_rate
940 * LINK_RATE_REF_FREQ_IN_KHZ;
941 /* TODO: check if undefined works */
942 cntl.color_depth = COLOR_DEPTH_UNDEFINED;
944 result = link_transmitter_control(enc10, &cntl);
946 if (result != BP_RESULT_OK) {
947 DC_LOG_ERROR("%s: Failed to execute VBIOS command table!\n",
953 /* enables DP PHY output in MST mode */
954 void dcn10_link_encoder_enable_dp_mst_output(
955 struct link_encoder *enc,
956 const struct dc_link_settings *link_settings,
957 enum clock_source_id clock_source)
959 struct dcn10_link_encoder *enc10 = TO_DCN10_LINK_ENC(enc);
960 struct bp_transmitter_control cntl = { 0 };
961 enum bp_result result;
965 /* number_of_lanes is used for pixel clock adjust,
966 * but it's not passed to asic_control.
967 * We need to set number of lanes manually.
969 enc1_configure_encoder(enc10, link_settings);
971 cntl.action = TRANSMITTER_CONTROL_ENABLE;
972 cntl.engine_id = ENGINE_ID_UNKNOWN;
973 cntl.transmitter = enc10->base.transmitter;
974 cntl.pll_id = clock_source;
975 cntl.signal = SIGNAL_TYPE_DISPLAY_PORT_MST;
976 cntl.lanes_number = link_settings->lane_count;
977 cntl.hpd_sel = enc10->base.hpd_source;
978 cntl.pixel_clock = link_settings->link_rate
979 * LINK_RATE_REF_FREQ_IN_KHZ;
980 /* TODO: check if undefined works */
981 cntl.color_depth = COLOR_DEPTH_UNDEFINED;
983 result = link_transmitter_control(enc10, &cntl);
985 if (result != BP_RESULT_OK) {
986 DC_LOG_ERROR("%s: Failed to execute VBIOS command table!\n",
993 * Disable transmitter and its encoder
995 void dcn10_link_encoder_disable_output(
996 struct link_encoder *enc,
997 enum signal_type signal)
999 struct dcn10_link_encoder *enc10 = TO_DCN10_LINK_ENC(enc);
1000 struct bp_transmitter_control cntl = { 0 };
1001 enum bp_result result;
1003 if (!dcn10_is_dig_enabled(enc)) {
1004 /* OF_SKIP_POWER_DOWN_INACTIVE_ENCODER */
1005 /*in DP_Alt_No_Connect case, we turn off the dig already,
1006 after excuation the PHY w/a sequence, not allow touch PHY any more*/
1009 /* Power-down RX and disable GPU PHY should be paired.
1010 * Disabling PHY without powering down RX may cause
1011 * symbol lock loss, on which we will get DP Sink interrupt.
1014 /* There is a case for the DP active dongles
1015 * where we want to disable the PHY but keep RX powered,
1016 * for those we need to ignore DP Sink interrupt
1017 * by checking lane count that has been set
1018 * on the last do_enable_output().
1021 /* disable transmitter */
1022 cntl.action = TRANSMITTER_CONTROL_DISABLE;
1023 cntl.transmitter = enc10->base.transmitter;
1024 cntl.hpd_sel = enc10->base.hpd_source;
1025 cntl.signal = signal;
1026 cntl.connector_obj_id = enc10->base.connector;
1028 result = link_transmitter_control(enc10, &cntl);
1030 if (result != BP_RESULT_OK) {
1031 DC_LOG_ERROR("%s: Failed to execute VBIOS command table!\n",
1033 BREAK_TO_DEBUGGER();
1037 /* disable encoder */
1038 if (dc_is_dp_signal(signal))
1039 link_encoder_disable(enc10);
1042 void dcn10_link_encoder_dp_set_lane_settings(
1043 struct link_encoder *enc,
1044 const struct link_training_settings *link_settings)
1046 struct dcn10_link_encoder *enc10 = TO_DCN10_LINK_ENC(enc);
1047 union dpcd_training_lane_set training_lane_set = { { 0 } };
1049 struct bp_transmitter_control cntl = { 0 };
1051 if (!link_settings) {
1052 BREAK_TO_DEBUGGER();
1056 cntl.action = TRANSMITTER_CONTROL_SET_VOLTAGE_AND_PREEMPASIS;
1057 cntl.transmitter = enc10->base.transmitter;
1058 cntl.connector_obj_id = enc10->base.connector;
1059 cntl.lanes_number = link_settings->link_settings.lane_count;
1060 cntl.hpd_sel = enc10->base.hpd_source;
1061 cntl.pixel_clock = link_settings->link_settings.link_rate *
1062 LINK_RATE_REF_FREQ_IN_KHZ;
1064 for (lane = 0; lane < link_settings->link_settings.lane_count; lane++) {
1065 /* translate lane settings */
1067 training_lane_set.bits.VOLTAGE_SWING_SET =
1068 link_settings->lane_settings[lane].VOLTAGE_SWING;
1069 training_lane_set.bits.PRE_EMPHASIS_SET =
1070 link_settings->lane_settings[lane].PRE_EMPHASIS;
1072 /* post cursor 2 setting only applies to HBR2 link rate */
1073 if (link_settings->link_settings.link_rate == LINK_RATE_HIGH2) {
1074 /* this is passed to VBIOS
1075 * to program post cursor 2 level
1077 training_lane_set.bits.POST_CURSOR2_SET =
1078 link_settings->lane_settings[lane].POST_CURSOR2;
1081 cntl.lane_select = lane;
1082 cntl.lane_settings = training_lane_set.raw;
1084 /* call VBIOS table to set voltage swing and pre-emphasis */
1085 link_transmitter_control(enc10, &cntl);
1089 /* set DP PHY test and training patterns */
1090 void dcn10_link_encoder_dp_set_phy_pattern(
1091 struct link_encoder *enc,
1092 const struct encoder_set_dp_phy_pattern_param *param)
1094 struct dcn10_link_encoder *enc10 = TO_DCN10_LINK_ENC(enc);
1096 switch (param->dp_phy_pattern) {
1097 case DP_TEST_PATTERN_TRAINING_PATTERN1:
1098 dcn10_link_encoder_set_dp_phy_pattern_training_pattern(enc, 0);
1100 case DP_TEST_PATTERN_TRAINING_PATTERN2:
1101 dcn10_link_encoder_set_dp_phy_pattern_training_pattern(enc, 1);
1103 case DP_TEST_PATTERN_TRAINING_PATTERN3:
1104 dcn10_link_encoder_set_dp_phy_pattern_training_pattern(enc, 2);
1106 case DP_TEST_PATTERN_TRAINING_PATTERN4:
1107 dcn10_link_encoder_set_dp_phy_pattern_training_pattern(enc, 3);
1109 case DP_TEST_PATTERN_D102:
1110 set_dp_phy_pattern_d102(enc10);
1112 case DP_TEST_PATTERN_SYMBOL_ERROR:
1113 set_dp_phy_pattern_symbol_error(enc10);
1115 case DP_TEST_PATTERN_PRBS7:
1116 set_dp_phy_pattern_prbs7(enc10);
1118 case DP_TEST_PATTERN_80BIT_CUSTOM:
1119 set_dp_phy_pattern_80bit_custom(
1120 enc10, param->custom_pattern);
1122 case DP_TEST_PATTERN_CP2520_1:
1123 set_dp_phy_pattern_hbr2_compliance_cp2520_2(enc10, 1);
1125 case DP_TEST_PATTERN_CP2520_2:
1126 set_dp_phy_pattern_hbr2_compliance_cp2520_2(enc10, 2);
1128 case DP_TEST_PATTERN_CP2520_3:
1129 set_dp_phy_pattern_hbr2_compliance_cp2520_2(enc10, 3);
1131 case DP_TEST_PATTERN_VIDEO_MODE: {
1132 set_dp_phy_pattern_passthrough_mode(
1133 enc10, param->dp_panel_mode);
1138 /* invalid phy pattern */
1139 ASSERT_CRITICAL(false);
1144 static void fill_stream_allocation_row_info(
1145 const struct link_mst_stream_allocation *stream_allocation,
1149 const struct stream_encoder *stream_enc = stream_allocation->stream_enc;
1152 *src = stream_enc->id;
1153 *slots = stream_allocation->slot_count;
1160 /* programs DP MST VC payload allocation */
1161 void dcn10_link_encoder_update_mst_stream_allocation_table(
1162 struct link_encoder *enc,
1163 const struct link_mst_stream_allocation_table *table)
1165 struct dcn10_link_encoder *enc10 = TO_DCN10_LINK_ENC(enc);
1166 uint32_t value0 = 0;
1167 uint32_t value1 = 0;
1168 uint32_t value2 = 0;
1171 uint32_t retries = 0;
1173 /* For CZ, there are only 3 pipes. So Virtual channel is up 3.*/
1175 /* --- Set MSE Stream Attribute -
1176 * Setup VC Payload Table on Tx Side,
1177 * Issue allocation change trigger
1178 * to commit payload on both tx and rx side
1181 /* we should clean-up table each time */
1183 if (table->stream_count >= 1) {
1184 fill_stream_allocation_row_info(
1185 &table->stream_allocations[0],
1193 REG_UPDATE_2(DP_MSE_SAT0,
1194 DP_MSE_SAT_SRC0, src,
1195 DP_MSE_SAT_SLOT_COUNT0, slots);
1197 if (table->stream_count >= 2) {
1198 fill_stream_allocation_row_info(
1199 &table->stream_allocations[1],
1207 REG_UPDATE_2(DP_MSE_SAT0,
1208 DP_MSE_SAT_SRC1, src,
1209 DP_MSE_SAT_SLOT_COUNT1, slots);
1211 if (table->stream_count >= 3) {
1212 fill_stream_allocation_row_info(
1213 &table->stream_allocations[2],
1221 REG_UPDATE_2(DP_MSE_SAT1,
1222 DP_MSE_SAT_SRC2, src,
1223 DP_MSE_SAT_SLOT_COUNT2, slots);
1225 if (table->stream_count >= 4) {
1226 fill_stream_allocation_row_info(
1227 &table->stream_allocations[3],
1235 REG_UPDATE_2(DP_MSE_SAT1,
1236 DP_MSE_SAT_SRC3, src,
1237 DP_MSE_SAT_SLOT_COUNT3, slots);
1239 /* --- wait for transaction finish */
1241 /* send allocation change trigger (ACT) ?
1242 * this step first sends the ACT,
1243 * then double buffers the SAT into the hardware
1244 * making the new allocation active on the DP MST mode link
1247 /* DP_MSE_SAT_UPDATE:
1249 * 1 - Update SAT with trigger
1250 * 2 - Update SAT without trigger
1252 REG_UPDATE(DP_MSE_SAT_UPDATE,
1253 DP_MSE_SAT_UPDATE, 1);
1255 /* wait for update to complete
1256 * (i.e. DP_MSE_SAT_UPDATE field is reset to 0)
1257 * then wait for the transmission
1258 * of at least 16 MTP headers on immediate local link.
1259 * i.e. DP_MSE_16_MTP_KEEPOUT field (read only) is reset to 0
1260 * a value of 1 indicates that DP MST mode
1261 * is in the 16 MTP keepout region after a VC has been added.
1262 * MST stream bandwidth (VC rate) can be configured
1263 * after this bit is cleared
1268 value0 = REG_READ(DP_MSE_SAT_UPDATE);
1270 REG_GET(DP_MSE_SAT_UPDATE,
1271 DP_MSE_SAT_UPDATE, &value1);
1273 REG_GET(DP_MSE_SAT_UPDATE,
1274 DP_MSE_16_MTP_KEEPOUT, &value2);
1276 /* bit field DP_MSE_SAT_UPDATE is set to 1 already */
1277 if (!value1 && !value2)
1280 } while (retries < DP_MST_UPDATE_MAX_RETRY);
1283 void dcn10_link_encoder_connect_dig_be_to_fe(
1284 struct link_encoder *enc,
1285 enum engine_id engine,
1288 struct dcn10_link_encoder *enc10 = TO_DCN10_LINK_ENC(enc);
1291 if (engine != ENGINE_ID_UNKNOWN) {
1293 REG_GET(DIG_BE_CNTL, DIG_FE_SOURCE_SELECT, &field);
1296 field |= get_frontend_source(engine);
1298 field &= ~get_frontend_source(engine);
1300 REG_UPDATE(DIG_BE_CNTL, DIG_FE_SOURCE_SELECT, field);
1305 #define HPD_REG(reg)\
1306 (enc10->hpd_regs->reg)
1308 #define HPD_REG_READ(reg_name) \
1309 dm_read_reg(CTX, HPD_REG(reg_name))
1311 #define HPD_REG_UPDATE_N(reg_name, n, ...) \
1312 generic_reg_update_ex(CTX, \
1313 HPD_REG(reg_name), \
1316 #define HPD_REG_UPDATE(reg_name, field, val) \
1317 HPD_REG_UPDATE_N(reg_name, 1, \
1318 FN(reg_name, field), val)
1320 void dcn10_link_encoder_enable_hpd(struct link_encoder *enc)
1322 struct dcn10_link_encoder *enc10 = TO_DCN10_LINK_ENC(enc);
1324 HPD_REG_UPDATE(DC_HPD_CONTROL,
1328 void dcn10_link_encoder_disable_hpd(struct link_encoder *enc)
1330 struct dcn10_link_encoder *enc10 = TO_DCN10_LINK_ENC(enc);
1332 HPD_REG_UPDATE(DC_HPD_CONTROL,
1337 #define AUX_REG(reg)\
1338 (enc10->aux_regs->reg)
1340 #define AUX_REG_READ(reg_name) \
1341 dm_read_reg(CTX, AUX_REG(reg_name))
1343 #define AUX_REG_UPDATE_N(reg_name, n, ...) \
1344 generic_reg_update_ex(CTX, \
1345 AUX_REG(reg_name), \
1348 #define AUX_REG_UPDATE(reg_name, field, val) \
1349 AUX_REG_UPDATE_N(reg_name, 1, \
1350 FN(reg_name, field), val)
1352 #define AUX_REG_UPDATE_2(reg, f1, v1, f2, v2) \
1353 AUX_REG_UPDATE_N(reg, 2,\
1357 void dcn10_aux_initialize(struct dcn10_link_encoder *enc10)
1359 enum hpd_source_id hpd_source = enc10->base.hpd_source;
1361 AUX_REG_UPDATE_2(AUX_CONTROL,
1362 AUX_HPD_SEL, hpd_source,
1365 /* 1/4 window (the maximum allowed) */
1366 AUX_REG_UPDATE(AUX_DPHY_RX_CONTROL0,
1367 AUX_RX_RECEIVE_WINDOW, 0);