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 "dm_services.h"
28 #include "dm_helpers.h"
30 #include "grph_object_id.h"
31 #include "gpio_service_interface.h"
32 #include "core_status.h"
33 #include "dc_link_dp.h"
34 #include "dc_link_ddc.h"
35 #include "link_hwss.h"
37 #include "link_encoder.h"
38 #include "hw_sequencer.h"
41 #include "fixed31_32.h"
42 #include "dpcd_defs.h"
45 #include "dce/dce_11_0_d.h"
46 #include "dce/dce_11_0_enum.h"
47 #include "dce/dce_11_0_sh_mask.h"
49 #define LINK_INFO(...) \
50 dm_logger_write(dc_ctx->logger, LOG_HW_HOTPLUG, \
53 /*******************************************************************************
55 ******************************************************************************/
58 LINK_RATE_REF_FREQ_IN_MHZ
= 27,
59 PEAK_FACTOR_X1000
= 1006
62 /*******************************************************************************
64 ******************************************************************************/
65 static void destruct(struct dc_link
*link
)
70 dal_ddc_service_destroy(&link
->ddc
);
73 link
->link_enc
->funcs
->destroy(&link
->link_enc
);
76 dc_sink_release(link
->local_sink
);
78 for (i
= 0; i
< link
->sink_count
; ++i
)
79 dc_sink_release(link
->remote_sinks
[i
]);
82 struct gpio
*get_hpd_gpio(struct dc_bios
*dcb
,
83 struct graphics_object_id link_id
,
84 struct gpio_service
*gpio_service
)
86 enum bp_result bp_result
;
87 struct graphics_object_hpd_info hpd_info
;
88 struct gpio_pin_info pin_info
;
90 if (dcb
->funcs
->get_hpd_info(dcb
, link_id
, &hpd_info
) != BP_RESULT_OK
)
93 bp_result
= dcb
->funcs
->get_gpio_pin_info(dcb
,
94 hpd_info
.hpd_int_gpio_uid
, &pin_info
);
96 if (bp_result
!= BP_RESULT_OK
) {
97 ASSERT(bp_result
== BP_RESULT_NORECORD
);
101 return dal_gpio_service_create_irq(
108 * Function: program_hpd_filter
111 * Programs HPD filter on associated HPD line
113 * @param [in] delay_on_connect_in_ms: Connect filter timeout
114 * @param [in] delay_on_disconnect_in_ms: Disconnect filter timeout
117 * true on success, false otherwise
119 static bool program_hpd_filter(
120 const struct dc_link
*link
)
126 int delay_on_connect_in_ms
= 0;
127 int delay_on_disconnect_in_ms
= 0;
129 /* Verify feature is supported */
130 switch (link
->connector_signal
) {
131 case SIGNAL_TYPE_DVI_SINGLE_LINK
:
132 case SIGNAL_TYPE_DVI_DUAL_LINK
:
133 case SIGNAL_TYPE_HDMI_TYPE_A
:
134 /* Program hpd filter */
135 delay_on_connect_in_ms
= 500;
136 delay_on_disconnect_in_ms
= 100;
138 case SIGNAL_TYPE_DISPLAY_PORT
:
139 case SIGNAL_TYPE_DISPLAY_PORT_MST
:
140 /* Program hpd filter to allow DP signal to settle */
141 /* 500: not able to detect MST <-> SST switch as HPD is low for
142 * only 100ms on DELL U2413
143 * 0: some passive dongle still show aux mode instead of i2c
144 * 20-50:not enough to hide bouncing HPD with passive dongle.
145 * also see intermittent i2c read issues.
147 delay_on_connect_in_ms
= 80;
148 delay_on_disconnect_in_ms
= 0;
150 case SIGNAL_TYPE_LVDS
:
151 case SIGNAL_TYPE_EDP
:
153 /* Don't program hpd filter */
157 /* Obtain HPD handle */
158 hpd
= get_hpd_gpio(link
->ctx
->dc_bios
, link
->link_id
, link
->ctx
->gpio_service
);
163 /* Setup HPD filtering */
164 if (dal_gpio_open(hpd
, GPIO_MODE_INTERRUPT
) == GPIO_RESULT_OK
) {
165 struct gpio_hpd_config config
;
167 config
.delay_on_connect
= delay_on_connect_in_ms
;
168 config
.delay_on_disconnect
= delay_on_disconnect_in_ms
;
170 dal_irq_setup_hpd_filter(hpd
, &config
);
176 ASSERT_CRITICAL(false);
179 /* Release HPD handle */
180 dal_gpio_destroy_irq(&hpd
);
185 static bool detect_sink(struct dc_link
*link
, enum dc_connection_type
*type
)
187 uint32_t is_hpd_high
= 0;
188 struct gpio
*hpd_pin
;
190 /* todo: may need to lock gpio access */
191 hpd_pin
= get_hpd_gpio(link
->ctx
->dc_bios
, link
->link_id
, link
->ctx
->gpio_service
);
193 goto hpd_gpio_failure
;
195 dal_gpio_open(hpd_pin
, GPIO_MODE_INTERRUPT
);
196 dal_gpio_get_value(hpd_pin
, &is_hpd_high
);
197 dal_gpio_close(hpd_pin
);
198 dal_gpio_destroy_irq(&hpd_pin
);
201 *type
= dc_connection_single
;
202 /* TODO: need to do the actual detection */
204 *type
= dc_connection_none
;
213 static enum ddc_transaction_type
get_ddc_transaction_type(
214 enum signal_type sink_signal
)
216 enum ddc_transaction_type transaction_type
= DDC_TRANSACTION_TYPE_NONE
;
218 switch (sink_signal
) {
219 case SIGNAL_TYPE_DVI_SINGLE_LINK
:
220 case SIGNAL_TYPE_DVI_DUAL_LINK
:
221 case SIGNAL_TYPE_HDMI_TYPE_A
:
222 case SIGNAL_TYPE_LVDS
:
223 case SIGNAL_TYPE_RGB
:
224 transaction_type
= DDC_TRANSACTION_TYPE_I2C
;
227 case SIGNAL_TYPE_DISPLAY_PORT
:
228 case SIGNAL_TYPE_EDP
:
229 transaction_type
= DDC_TRANSACTION_TYPE_I2C_OVER_AUX
;
232 case SIGNAL_TYPE_DISPLAY_PORT_MST
:
233 /* MST does not use I2COverAux, but there is the
234 * SPECIAL use case for "immediate dwnstrm device
235 * access" (EPR#370830). */
236 transaction_type
= DDC_TRANSACTION_TYPE_I2C_OVER_AUX
;
243 return transaction_type
;
246 static enum signal_type
get_basic_signal_type(
247 struct graphics_object_id encoder
,
248 struct graphics_object_id downstream
)
250 if (downstream
.type
== OBJECT_TYPE_CONNECTOR
) {
251 switch (downstream
.id
) {
252 case CONNECTOR_ID_SINGLE_LINK_DVII
:
253 switch (encoder
.id
) {
254 case ENCODER_ID_INTERNAL_DAC1
:
255 case ENCODER_ID_INTERNAL_KLDSCP_DAC1
:
256 case ENCODER_ID_INTERNAL_DAC2
:
257 case ENCODER_ID_INTERNAL_KLDSCP_DAC2
:
258 return SIGNAL_TYPE_RGB
;
260 return SIGNAL_TYPE_DVI_SINGLE_LINK
;
263 case CONNECTOR_ID_DUAL_LINK_DVII
:
265 switch (encoder
.id
) {
266 case ENCODER_ID_INTERNAL_DAC1
:
267 case ENCODER_ID_INTERNAL_KLDSCP_DAC1
:
268 case ENCODER_ID_INTERNAL_DAC2
:
269 case ENCODER_ID_INTERNAL_KLDSCP_DAC2
:
270 return SIGNAL_TYPE_RGB
;
272 return SIGNAL_TYPE_DVI_DUAL_LINK
;
276 case CONNECTOR_ID_SINGLE_LINK_DVID
:
277 return SIGNAL_TYPE_DVI_SINGLE_LINK
;
278 case CONNECTOR_ID_DUAL_LINK_DVID
:
279 return SIGNAL_TYPE_DVI_DUAL_LINK
;
280 case CONNECTOR_ID_VGA
:
281 return SIGNAL_TYPE_RGB
;
282 case CONNECTOR_ID_HDMI_TYPE_A
:
283 return SIGNAL_TYPE_HDMI_TYPE_A
;
284 case CONNECTOR_ID_LVDS
:
285 return SIGNAL_TYPE_LVDS
;
286 case CONNECTOR_ID_DISPLAY_PORT
:
287 return SIGNAL_TYPE_DISPLAY_PORT
;
288 case CONNECTOR_ID_EDP
:
289 return SIGNAL_TYPE_EDP
;
291 return SIGNAL_TYPE_NONE
;
293 } else if (downstream
.type
== OBJECT_TYPE_ENCODER
) {
294 switch (downstream
.id
) {
295 case ENCODER_ID_EXTERNAL_NUTMEG
:
296 case ENCODER_ID_EXTERNAL_TRAVIS
:
297 return SIGNAL_TYPE_DISPLAY_PORT
;
299 return SIGNAL_TYPE_NONE
;
303 return SIGNAL_TYPE_NONE
;
308 * Check whether there is a dongle on DP connector
310 static bool is_dp_sink_present(struct dc_link
*link
)
312 enum gpio_result gpio_result
;
313 uint32_t clock_pin
= 0;
317 enum connector_id connector_id
=
318 dal_graphics_object_id_get_connector_id(link
->link_id
);
321 ((connector_id
== CONNECTOR_ID_DISPLAY_PORT
) ||
322 (connector_id
== CONNECTOR_ID_EDP
));
324 ddc
= dal_ddc_service_get_ddc_pin(link
->ddc
);
331 /* Open GPIO and set it to I2C mode */
332 /* Note: this GpioMode_Input will be converted
333 * to GpioConfigType_I2cAuxDualMode in GPIO component,
334 * which indicates we need additional delay */
336 if (GPIO_RESULT_OK
!= dal_ddc_open(
337 ddc
, GPIO_MODE_INPUT
, GPIO_DDC_CONFIG_TYPE_MODE_I2C
)) {
338 dal_gpio_destroy_ddc(&ddc
);
343 /* Read GPIO: DP sink is present if both clock and data pins are zero */
344 /* [anaumov] in DAL2, there was no check for GPIO failure */
346 gpio_result
= dal_gpio_get_value(ddc
->pin_clock
, &clock_pin
);
347 ASSERT(gpio_result
== GPIO_RESULT_OK
);
349 present
= (gpio_result
== GPIO_RESULT_OK
) && !clock_pin
;
358 * Detect output sink type
360 static enum signal_type
link_detect_sink(
361 struct dc_link
*link
,
362 enum dc_detect_reason reason
)
364 enum signal_type result
= get_basic_signal_type(
365 link
->link_enc
->id
, link
->link_id
);
367 /* Internal digital encoder will detect only dongles
368 * that require digital signal */
370 /* Detection mechanism is different
371 * for different native connectors.
372 * LVDS connector supports only LVDS signal;
373 * PCIE is a bus slot, the actual connector needs to be detected first;
374 * eDP connector supports only eDP signal;
375 * HDMI should check straps for audio */
377 /* PCIE detects the actual connector on add-on board */
379 if (link
->link_id
.id
== CONNECTOR_ID_PCIE
) {
380 /* ZAZTODO implement PCIE add-on card detection */
383 switch (link
->link_id
.id
) {
384 case CONNECTOR_ID_HDMI_TYPE_A
: {
385 /* check audio support:
386 * if native HDMI is not supported, switch to DVI */
387 struct audio_support
*aud_support
= &link
->dc
->res_pool
->audio_support
;
389 if (!aud_support
->hdmi_audio_native
)
390 if (link
->link_id
.id
== CONNECTOR_ID_HDMI_TYPE_A
)
391 result
= SIGNAL_TYPE_DVI_SINGLE_LINK
;
394 case CONNECTOR_ID_DISPLAY_PORT
: {
395 /* DP HPD short pulse. Passive DP dongle will not
398 if (reason
!= DETECT_REASON_HPDRX
) {
399 /* Check whether DP signal detected: if not -
400 * we assume signal is DVI; it could be corrected
401 * to HDMI after dongle detection
403 if (!is_dp_sink_present(link
))
404 result
= SIGNAL_TYPE_DVI_SINGLE_LINK
;
415 static enum signal_type
decide_signal_from_strap_and_dongle_type(
416 enum display_dongle_type dongle_type
,
417 struct audio_support
*audio_support
)
419 enum signal_type signal
= SIGNAL_TYPE_NONE
;
421 switch (dongle_type
) {
422 case DISPLAY_DONGLE_DP_HDMI_DONGLE
:
423 if (audio_support
->hdmi_audio_on_dongle
)
424 signal
= SIGNAL_TYPE_HDMI_TYPE_A
;
426 signal
= SIGNAL_TYPE_DVI_SINGLE_LINK
;
428 case DISPLAY_DONGLE_DP_DVI_DONGLE
:
429 signal
= SIGNAL_TYPE_DVI_SINGLE_LINK
;
431 case DISPLAY_DONGLE_DP_HDMI_MISMATCHED_DONGLE
:
432 if (audio_support
->hdmi_audio_native
)
433 signal
= SIGNAL_TYPE_HDMI_TYPE_A
;
435 signal
= SIGNAL_TYPE_DVI_SINGLE_LINK
;
438 signal
= SIGNAL_TYPE_NONE
;
445 static enum signal_type
dp_passive_dongle_detection(
446 struct ddc_service
*ddc
,
447 struct display_sink_capability
*sink_cap
,
448 struct audio_support
*audio_support
)
450 dal_ddc_service_i2c_query_dp_dual_mode_adaptor(
452 return decide_signal_from_strap_and_dongle_type(
453 sink_cap
->dongle_type
,
457 static void link_disconnect_sink(struct dc_link
*link
)
459 if (link
->local_sink
) {
460 dc_sink_release(link
->local_sink
);
461 link
->local_sink
= NULL
;
464 link
->dpcd_sink_count
= 0;
467 static void detect_dp(
468 struct dc_link
*link
,
469 struct display_sink_capability
*sink_caps
,
470 bool *converter_disable_audio
,
471 struct audio_support
*audio_support
,
472 enum dc_detect_reason reason
)
475 sink_caps
->signal
= link_detect_sink(link
, reason
);
476 sink_caps
->transaction_type
=
477 get_ddc_transaction_type(sink_caps
->signal
);
479 if (sink_caps
->transaction_type
== DDC_TRANSACTION_TYPE_I2C_OVER_AUX
) {
480 sink_caps
->signal
= SIGNAL_TYPE_DISPLAY_PORT
;
481 detect_dp_sink_caps(link
);
483 /* DP active dongles */
484 if (is_dp_active_dongle(link
)) {
485 link
->type
= dc_connection_active_dongle
;
486 if (!link
->dpcd_caps
.sink_count
.bits
.SINK_COUNT
) {
488 * active dongle unplug processing for short irq
490 link_disconnect_sink(link
);
494 if (link
->dpcd_caps
.dongle_type
!=
495 DISPLAY_DONGLE_DP_HDMI_CONVERTER
) {
496 *converter_disable_audio
= true;
499 if (is_mst_supported(link
)) {
500 sink_caps
->signal
= SIGNAL_TYPE_DISPLAY_PORT_MST
;
501 link
->type
= dc_connection_mst_branch
;
504 * This call will initiate MST topology discovery. Which
505 * will detect MST ports and add new DRM connector DRM
506 * framework. Then read EDID via remote i2c over aux. In
507 * the end, will notify DRM detect result and save EDID
508 * into DRM framework.
510 * .detect is called by .fill_modes.
511 * .fill_modes is called by user mode ioctl
512 * DRM_IOCTL_MODE_GETCONNECTOR.
514 * .get_modes is called by .fill_modes.
516 * call .get_modes, AMDGPU DM implementation will create
517 * new dc_sink and add to dc_link. For long HPD plug
518 * in/out, MST has its own handle.
520 * Therefore, just after dc_create, link->sink is not
521 * created for MST until user mode app calls
522 * DRM_IOCTL_MODE_GETCONNECTOR.
524 * Need check ->sink usages in case ->sink = NULL
525 * TODO: s3 resume check
527 if (reason
== DETECT_REASON_BOOT
)
530 if (!dm_helpers_dp_mst_start_top_mgr(
533 /* MST not supported */
534 link
->type
= dc_connection_single
;
535 sink_caps
->signal
= SIGNAL_TYPE_DISPLAY_PORT
;
539 /* DP passive dongles */
540 sink_caps
->signal
= dp_passive_dongle_detection(link
->ddc
,
546 bool dc_link_detect(struct dc_link
*link
, enum dc_detect_reason reason
)
548 struct dc_sink_init_data sink_init_data
= { 0 };
549 struct display_sink_capability sink_caps
= { 0 };
551 bool converter_disable_audio
= false;
552 struct audio_support
*aud_support
= &link
->dc
->res_pool
->audio_support
;
553 enum dc_edid_status edid_status
;
554 struct dc_context
*dc_ctx
= link
->ctx
;
555 struct dc_sink
*sink
= NULL
;
556 enum dc_connection_type new_connection_type
= dc_connection_none
;
558 if (link
->connector_signal
== SIGNAL_TYPE_VIRTUAL
)
561 if (false == detect_sink(link
, &new_connection_type
)) {
566 if (link
->connector_signal
== SIGNAL_TYPE_EDP
&&
570 link_disconnect_sink(link
);
572 if (new_connection_type
!= dc_connection_none
) {
573 link
->type
= new_connection_type
;
575 /* From Disconnected-to-Connected. */
576 switch (link
->connector_signal
) {
577 case SIGNAL_TYPE_HDMI_TYPE_A
: {
578 sink_caps
.transaction_type
= DDC_TRANSACTION_TYPE_I2C
;
579 if (aud_support
->hdmi_audio_native
)
580 sink_caps
.signal
= SIGNAL_TYPE_HDMI_TYPE_A
;
582 sink_caps
.signal
= SIGNAL_TYPE_DVI_SINGLE_LINK
;
586 case SIGNAL_TYPE_DVI_SINGLE_LINK
: {
587 sink_caps
.transaction_type
= DDC_TRANSACTION_TYPE_I2C
;
588 sink_caps
.signal
= SIGNAL_TYPE_DVI_SINGLE_LINK
;
592 case SIGNAL_TYPE_DVI_DUAL_LINK
: {
593 sink_caps
.transaction_type
= DDC_TRANSACTION_TYPE_I2C
;
594 sink_caps
.signal
= SIGNAL_TYPE_DVI_DUAL_LINK
;
598 case SIGNAL_TYPE_EDP
: {
599 detect_edp_sink_caps(link
);
600 sink_caps
.transaction_type
=
601 DDC_TRANSACTION_TYPE_I2C_OVER_AUX
;
602 sink_caps
.signal
= SIGNAL_TYPE_EDP
;
606 case SIGNAL_TYPE_DISPLAY_PORT
: {
610 &converter_disable_audio
,
611 aud_support
, reason
);
613 /* Active dongle downstream unplug */
614 if (link
->type
== dc_connection_active_dongle
615 && link
->dpcd_caps
.sink_count
.
616 bits
.SINK_COUNT
== 0)
619 if (link
->type
== dc_connection_mst_branch
) {
620 LINK_INFO("link=%d, mst branch is now Connected\n",
622 /* Need to setup mst link_cap struct here
623 * otherwise dc_link_detect() will leave mst link_cap
624 * empty which leads to allocate_mst_payload() has "0"
625 * pbn_per_slot value leading to exception on dal_fixed31_32_div()
627 link
->verified_link_cap
= link
->reported_link_cap
;
635 DC_ERROR("Invalid connector type! signal:%d\n",
636 link
->connector_signal
);
640 if (link
->dpcd_caps
.sink_count
.bits
.SINK_COUNT
)
641 link
->dpcd_sink_count
= link
->dpcd_caps
.sink_count
.
644 link
->dpcd_sink_count
= 1;
646 dal_ddc_service_set_transaction_type(
648 sink_caps
.transaction_type
);
650 link
->aux_mode
= dal_ddc_service_is_in_aux_transaction_mode(
653 sink_init_data
.link
= link
;
654 sink_init_data
.sink_signal
= sink_caps
.signal
;
656 sink
= dc_sink_create(&sink_init_data
);
658 DC_ERROR("Failed to create sink!\n");
662 sink
->dongle_max_pix_clk
= sink_caps
.max_hdmi_pixel_clock
;
663 sink
->converter_disable_audio
= converter_disable_audio
;
665 link
->local_sink
= sink
;
667 edid_status
= dm_helpers_read_local_edid(
672 switch (edid_status
) {
673 case EDID_BAD_CHECKSUM
:
674 dm_logger_write(link
->ctx
->logger
, LOG_ERROR
,
675 "EDID checksum invalid.\n");
677 case EDID_NO_RESPONSE
:
678 dm_logger_write(link
->ctx
->logger
, LOG_ERROR
,
686 if (link
->connector_signal
== SIGNAL_TYPE_DISPLAY_PORT
&&
687 sink_caps
.transaction_type
==
688 DDC_TRANSACTION_TYPE_I2C_OVER_AUX
) {
690 * TODO debug why Dell 2413 doesn't like
694 /* deal with non-mst cases */
695 dp_hbr_verify_link_cap(link
, &link
->reported_link_cap
);
698 /* HDMI-DVI Dongle */
699 if (sink
->sink_signal
== SIGNAL_TYPE_HDMI_TYPE_A
&&
700 !sink
->edid_caps
.edid_hdmi
)
701 sink
->sink_signal
= SIGNAL_TYPE_DVI_SINGLE_LINK
;
703 /* Connectivity log: detection */
704 for (i
= 0; i
< sink
->dc_edid
.length
/ EDID_BLOCK_SIZE
; i
++) {
705 CONN_DATA_DETECT(link
,
706 &sink
->dc_edid
.raw_edid
[i
* EDID_BLOCK_SIZE
],
708 "%s: [Block %d] ", sink
->edid_caps
.display_name
, i
);
711 dm_logger_write(link
->ctx
->logger
, LOG_DETECTION_EDID_PARSER
,
713 "manufacturer_id = %X, "
715 "serial_number = %X, "
716 "manufacture_week = %d, "
717 "manufacture_year = %d, "
718 "display_name = %s, "
719 "speaker_flag = %d, "
720 "audio_mode_count = %d\n",
722 sink
->edid_caps
.manufacturer_id
,
723 sink
->edid_caps
.product_id
,
724 sink
->edid_caps
.serial_number
,
725 sink
->edid_caps
.manufacture_week
,
726 sink
->edid_caps
.manufacture_year
,
727 sink
->edid_caps
.display_name
,
728 sink
->edid_caps
.speaker_flags
,
729 sink
->edid_caps
.audio_mode_count
);
731 for (i
= 0; i
< sink
->edid_caps
.audio_mode_count
; i
++) {
732 dm_logger_write(link
->ctx
->logger
, LOG_DETECTION_EDID_PARSER
,
733 "%s: mode number = %d, "
735 "channel_count = %d, "
737 "sample_size = %d\n",
740 sink
->edid_caps
.audio_modes
[i
].format_code
,
741 sink
->edid_caps
.audio_modes
[i
].channel_count
,
742 sink
->edid_caps
.audio_modes
[i
].sample_rate
,
743 sink
->edid_caps
.audio_modes
[i
].sample_size
);
747 /* From Connected-to-Disconnected. */
748 if (link
->type
== dc_connection_mst_branch
) {
749 LINK_INFO("link=%d, mst branch is now Disconnected\n",
752 dm_helpers_dp_mst_stop_top_mgr(link
->ctx
, link
);
754 link
->mst_stream_alloc_table
.stream_count
= 0;
755 memset(link
->mst_stream_alloc_table
.stream_allocations
, 0, sizeof(link
->mst_stream_alloc_table
.stream_allocations
));
758 link
->type
= dc_connection_none
;
759 sink_caps
.signal
= SIGNAL_TYPE_NONE
;
762 LINK_INFO("link=%d, dc_sink_in=%p is now %s\n",
763 link
->link_index
, sink
,
764 (sink_caps
.signal
== SIGNAL_TYPE_NONE
?
765 "Disconnected":"Connected"));
770 static enum hpd_source_id
get_hpd_line(
771 struct dc_link
*link
)
774 enum hpd_source_id hpd_id
= HPD_SOURCEID_UNKNOWN
;
776 hpd
= get_hpd_gpio(link
->ctx
->dc_bios
, link
->link_id
, link
->ctx
->gpio_service
);
779 switch (dal_irq_get_source(hpd
)) {
780 case DC_IRQ_SOURCE_HPD1
:
781 hpd_id
= HPD_SOURCEID1
;
783 case DC_IRQ_SOURCE_HPD2
:
784 hpd_id
= HPD_SOURCEID2
;
786 case DC_IRQ_SOURCE_HPD3
:
787 hpd_id
= HPD_SOURCEID3
;
789 case DC_IRQ_SOURCE_HPD4
:
790 hpd_id
= HPD_SOURCEID4
;
792 case DC_IRQ_SOURCE_HPD5
:
793 hpd_id
= HPD_SOURCEID5
;
795 case DC_IRQ_SOURCE_HPD6
:
796 hpd_id
= HPD_SOURCEID6
;
803 dal_gpio_destroy_irq(&hpd
);
809 static enum channel_id
get_ddc_line(struct dc_link
*link
)
812 enum channel_id channel
= CHANNEL_ID_UNKNOWN
;
814 ddc
= dal_ddc_service_get_ddc_pin(link
->ddc
);
817 switch (dal_ddc_get_line(ddc
)) {
818 case GPIO_DDC_LINE_DDC1
:
819 channel
= CHANNEL_ID_DDC1
;
821 case GPIO_DDC_LINE_DDC2
:
822 channel
= CHANNEL_ID_DDC2
;
824 case GPIO_DDC_LINE_DDC3
:
825 channel
= CHANNEL_ID_DDC3
;
827 case GPIO_DDC_LINE_DDC4
:
828 channel
= CHANNEL_ID_DDC4
;
830 case GPIO_DDC_LINE_DDC5
:
831 channel
= CHANNEL_ID_DDC5
;
833 case GPIO_DDC_LINE_DDC6
:
834 channel
= CHANNEL_ID_DDC6
;
836 case GPIO_DDC_LINE_DDC_VGA
:
837 channel
= CHANNEL_ID_DDC_VGA
;
839 case GPIO_DDC_LINE_I2C_PAD
:
840 channel
= CHANNEL_ID_I2C_PAD
;
851 static enum transmitter
translate_encoder_to_transmitter(
852 struct graphics_object_id encoder
)
854 switch (encoder
.id
) {
855 case ENCODER_ID_INTERNAL_UNIPHY
:
856 switch (encoder
.enum_id
) {
858 return TRANSMITTER_UNIPHY_A
;
860 return TRANSMITTER_UNIPHY_B
;
862 return TRANSMITTER_UNKNOWN
;
865 case ENCODER_ID_INTERNAL_UNIPHY1
:
866 switch (encoder
.enum_id
) {
868 return TRANSMITTER_UNIPHY_C
;
870 return TRANSMITTER_UNIPHY_D
;
872 return TRANSMITTER_UNKNOWN
;
875 case ENCODER_ID_INTERNAL_UNIPHY2
:
876 switch (encoder
.enum_id
) {
878 return TRANSMITTER_UNIPHY_E
;
880 return TRANSMITTER_UNIPHY_F
;
882 return TRANSMITTER_UNKNOWN
;
885 case ENCODER_ID_INTERNAL_UNIPHY3
:
886 switch (encoder
.enum_id
) {
888 return TRANSMITTER_UNIPHY_G
;
890 return TRANSMITTER_UNKNOWN
;
893 case ENCODER_ID_EXTERNAL_NUTMEG
:
894 switch (encoder
.enum_id
) {
896 return TRANSMITTER_NUTMEG_CRT
;
898 return TRANSMITTER_UNKNOWN
;
901 case ENCODER_ID_EXTERNAL_TRAVIS
:
902 switch (encoder
.enum_id
) {
904 return TRANSMITTER_TRAVIS_CRT
;
906 return TRANSMITTER_TRAVIS_LCD
;
908 return TRANSMITTER_UNKNOWN
;
912 return TRANSMITTER_UNKNOWN
;
916 static bool construct(
917 struct dc_link
*link
,
918 const struct link_init_data
*init_params
)
921 struct gpio
*hpd_gpio
= NULL
;
922 struct ddc_service_init_data ddc_service_init_data
= { { 0 } };
923 struct dc_context
*dc_ctx
= init_params
->ctx
;
924 struct encoder_init_data enc_init_data
= { 0 };
925 struct integrated_info info
= {{{ 0 }}};
926 struct dc_bios
*bios
= init_params
->dc
->ctx
->dc_bios
;
927 const struct dc_vbios_funcs
*bp_funcs
= bios
->funcs
;
929 link
->irq_source_hpd
= DC_IRQ_SOURCE_INVALID
;
930 link
->irq_source_hpd_rx
= DC_IRQ_SOURCE_INVALID
;
932 link
->link_status
.dpcd_caps
= &link
->dpcd_caps
;
934 link
->dc
= init_params
->dc
;
936 link
->link_index
= init_params
->link_index
;
938 link
->link_id
= bios
->funcs
->get_connector_id(bios
, init_params
->connector_index
);
940 if (link
->link_id
.type
!= OBJECT_TYPE_CONNECTOR
) {
941 dm_error("%s: Invalid Connector ObjectID from Adapter Service for connector index:%d!\n",
942 __func__
, init_params
->connector_index
);
946 hpd_gpio
= get_hpd_gpio(link
->ctx
->dc_bios
, link
->link_id
, link
->ctx
->gpio_service
);
948 if (hpd_gpio
!= NULL
)
949 link
->irq_source_hpd
= dal_irq_get_source(hpd_gpio
);
951 switch (link
->link_id
.id
) {
952 case CONNECTOR_ID_HDMI_TYPE_A
:
953 link
->connector_signal
= SIGNAL_TYPE_HDMI_TYPE_A
;
956 case CONNECTOR_ID_SINGLE_LINK_DVID
:
957 case CONNECTOR_ID_SINGLE_LINK_DVII
:
958 link
->connector_signal
= SIGNAL_TYPE_DVI_SINGLE_LINK
;
960 case CONNECTOR_ID_DUAL_LINK_DVID
:
961 case CONNECTOR_ID_DUAL_LINK_DVII
:
962 link
->connector_signal
= SIGNAL_TYPE_DVI_DUAL_LINK
;
964 case CONNECTOR_ID_DISPLAY_PORT
:
965 link
->connector_signal
= SIGNAL_TYPE_DISPLAY_PORT
;
967 if (hpd_gpio
!= NULL
)
968 link
->irq_source_hpd_rx
=
969 dal_irq_get_rx_source(hpd_gpio
);
972 case CONNECTOR_ID_EDP
:
973 link
->connector_signal
= SIGNAL_TYPE_EDP
;
975 if (hpd_gpio
!= NULL
) {
976 link
->irq_source_hpd
= DC_IRQ_SOURCE_INVALID
;
977 link
->irq_source_hpd_rx
=
978 dal_irq_get_rx_source(hpd_gpio
);
982 dm_logger_write(dc_ctx
->logger
, LOG_WARNING
,
983 "Unsupported Connector type:%d!\n", link
->link_id
.id
);
987 if (hpd_gpio
!= NULL
) {
988 dal_gpio_destroy_irq(&hpd_gpio
);
992 /* TODO: #DAL3 Implement id to str function.*/
993 LINK_INFO("Connector[%d] description:"
995 init_params
->connector_index
,
996 link
->connector_signal
);
998 ddc_service_init_data
.ctx
= link
->ctx
;
999 ddc_service_init_data
.id
= link
->link_id
;
1000 ddc_service_init_data
.link
= link
;
1001 link
->ddc
= dal_ddc_service_create(&ddc_service_init_data
);
1003 if (link
->ddc
== NULL
) {
1004 DC_ERROR("Failed to create ddc_service!\n");
1005 goto ddc_create_fail
;
1010 dal_ddc_service_get_ddc_pin(link
->ddc
));
1012 enc_init_data
.ctx
= dc_ctx
;
1013 bp_funcs
->get_src_obj(dc_ctx
->dc_bios
, link
->link_id
, 0, &enc_init_data
.encoder
);
1014 enc_init_data
.connector
= link
->link_id
;
1015 enc_init_data
.channel
= get_ddc_line(link
);
1016 enc_init_data
.hpd_source
= get_hpd_line(link
);
1018 link
->hpd_src
= enc_init_data
.hpd_source
;
1020 enc_init_data
.transmitter
=
1021 translate_encoder_to_transmitter(enc_init_data
.encoder
);
1022 link
->link_enc
= link
->dc
->res_pool
->funcs
->link_enc_create(
1025 if( link
->link_enc
== NULL
) {
1026 DC_ERROR("Failed to create link encoder!\n");
1027 goto link_enc_create_fail
;
1030 link
->link_enc_hw_inst
= link
->link_enc
->transmitter
;
1032 for (i
= 0; i
< 4; i
++) {
1034 bp_funcs
->get_device_tag(dc_ctx
->dc_bios
, link
->link_id
, i
, &link
->device_tag
)) {
1035 DC_ERROR("Failed to find device tag!\n");
1036 goto device_tag_fail
;
1039 /* Look for device tag that matches connector signal,
1040 * CRT for rgb, LCD for other supported signal tyes
1042 if (!bp_funcs
->is_device_id_supported(dc_ctx
->dc_bios
, link
->device_tag
.dev_id
))
1044 if (link
->device_tag
.dev_id
.device_type
== DEVICE_TYPE_CRT
1045 && link
->connector_signal
!= SIGNAL_TYPE_RGB
)
1047 if (link
->device_tag
.dev_id
.device_type
== DEVICE_TYPE_LCD
1048 && link
->connector_signal
== SIGNAL_TYPE_RGB
)
1053 if (bios
->integrated_info
)
1054 info
= *bios
->integrated_info
;
1056 /* Look for channel mapping corresponding to connector and device tag */
1057 for (i
= 0; i
< MAX_NUMBER_OF_EXT_DISPLAY_PATH
; i
++) {
1058 struct external_display_path
*path
=
1059 &info
.ext_disp_conn_info
.path
[i
];
1060 if (path
->device_connector_id
.enum_id
== link
->link_id
.enum_id
1061 && path
->device_connector_id
.id
== link
->link_id
.id
1062 && path
->device_connector_id
.type
== link
->link_id
.type
) {
1064 if (link
->device_tag
.acpi_device
!= 0
1065 && path
->device_acpi_enum
== link
->device_tag
.acpi_device
) {
1066 link
->ddi_channel_mapping
= path
->channel_mapping
;
1067 link
->chip_caps
= path
->caps
;
1068 } else if (path
->device_tag
==
1069 link
->device_tag
.dev_id
.raw_device_tag
) {
1070 link
->ddi_channel_mapping
= path
->channel_mapping
;
1071 link
->chip_caps
= path
->caps
;
1078 * TODO check if GPIO programmed correctly
1080 * If GPIO isn't programmed correctly HPD might not rise or drain
1081 * fast enough, leading to bounces.
1083 program_hpd_filter(link
);
1087 link
->link_enc
->funcs
->destroy(&link
->link_enc
);
1088 link_enc_create_fail
:
1089 dal_ddc_service_destroy(&link
->ddc
);
1093 if (hpd_gpio
!= NULL
) {
1094 dal_gpio_destroy_irq(&hpd_gpio
);
1100 /*******************************************************************************
1102 ******************************************************************************/
1103 struct dc_link
*link_create(const struct link_init_data
*init_params
)
1105 struct dc_link
*link
=
1106 kzalloc(sizeof(*link
), GFP_KERNEL
);
1111 if (false == construct(link
, init_params
))
1112 goto construct_fail
;
1123 void link_destroy(struct dc_link
**link
)
1130 static void dpcd_configure_panel_mode(
1131 struct dc_link
*link
,
1132 enum dp_panel_mode panel_mode
)
1134 union dpcd_edp_config edp_config_set
;
1135 bool panel_mode_edp
= false;
1137 memset(&edp_config_set
, '\0', sizeof(union dpcd_edp_config
));
1139 if (DP_PANEL_MODE_DEFAULT
!= panel_mode
) {
1141 switch (panel_mode
) {
1142 case DP_PANEL_MODE_EDP
:
1143 case DP_PANEL_MODE_SPECIAL
:
1144 panel_mode_edp
= true;
1151 /*set edp panel mode in receiver*/
1152 core_link_read_dpcd(
1154 DP_EDP_CONFIGURATION_SET
,
1155 &edp_config_set
.raw
,
1156 sizeof(edp_config_set
.raw
));
1158 if (edp_config_set
.bits
.PANEL_MODE_EDP
1159 != panel_mode_edp
) {
1160 enum ddc_result result
= DDC_RESULT_UNKNOWN
;
1162 edp_config_set
.bits
.PANEL_MODE_EDP
=
1164 result
= core_link_write_dpcd(
1166 DP_EDP_CONFIGURATION_SET
,
1167 &edp_config_set
.raw
,
1168 sizeof(edp_config_set
.raw
));
1170 ASSERT(result
== DDC_RESULT_SUCESSFULL
);
1173 dm_logger_write(link
->ctx
->logger
, LOG_DETECTION_DP_CAPS
,
1174 "Link: %d eDP panel mode supported: %d "
1175 "eDP panel mode enabled: %d \n",
1177 link
->dpcd_caps
.panel_mode_edp
,
1181 static void enable_stream_features(struct pipe_ctx
*pipe_ctx
)
1183 struct dc_stream_state
*stream
= pipe_ctx
->stream
;
1184 struct dc_link
*link
= stream
->sink
->link
;
1185 union down_spread_ctrl downspread
;
1187 core_link_read_dpcd(link
, DP_DOWNSPREAD_CTRL
,
1188 &downspread
.raw
, sizeof(downspread
));
1190 downspread
.bits
.IGNORE_MSA_TIMING_PARAM
=
1191 (stream
->ignore_msa_timing_param
) ? 1 : 0;
1193 core_link_write_dpcd(link
, DP_DOWNSPREAD_CTRL
,
1194 &downspread
.raw
, sizeof(downspread
));
1197 static enum dc_status
enable_link_dp(
1198 struct dc_state
*state
,
1199 struct pipe_ctx
*pipe_ctx
)
1201 struct dc_stream_state
*stream
= pipe_ctx
->stream
;
1202 enum dc_status status
;
1203 bool skip_video_pattern
;
1204 struct dc_link
*link
= stream
->sink
->link
;
1205 struct dc_link_settings link_settings
= {0};
1206 enum dp_panel_mode panel_mode
;
1207 enum dc_link_rate max_link_rate
= LINK_RATE_HIGH2
;
1209 /* get link settings for video mode timing */
1210 decide_link_settings(stream
, &link_settings
);
1212 /* raise clock state for HBR3 if required. Confirmed with HW DCE/DPCS
1213 * logic for HBR3 still needs Nominal (0.8V) on VDDC rail
1215 if (link
->link_enc
->features
.flags
.bits
.IS_HBR3_CAPABLE
)
1216 max_link_rate
= LINK_RATE_HIGH3
;
1218 if (link_settings
.link_rate
== max_link_rate
) {
1219 if (state
->dis_clk
->funcs
->set_min_clocks_state
) {
1220 if (state
->dis_clk
->cur_min_clks_state
< DM_PP_CLOCKS_STATE_NOMINAL
)
1221 state
->dis_clk
->funcs
->set_min_clocks_state(
1222 state
->dis_clk
, DM_PP_CLOCKS_STATE_NOMINAL
);
1224 uint32_t dp_phyclk_in_khz
;
1225 const struct clocks_value clocks_value
=
1226 state
->dis_clk
->cur_clocks_value
;
1228 /* 27mhz = 27000000hz= 27000khz */
1229 dp_phyclk_in_khz
= link_settings
.link_rate
* 27000;
1231 if (((clocks_value
.max_non_dp_phyclk_in_khz
!= 0) &&
1232 (dp_phyclk_in_khz
> clocks_value
.max_non_dp_phyclk_in_khz
)) ||
1233 (dp_phyclk_in_khz
> clocks_value
.max_dp_phyclk_in_khz
)) {
1234 state
->dis_clk
->funcs
->apply_clock_voltage_request(
1236 DM_PP_CLOCK_TYPE_DISPLAYPHYCLK
,
1246 pipe_ctx
->stream
->signal
,
1247 pipe_ctx
->clock_source
->id
,
1250 panel_mode
= dp_get_panel_mode(link
);
1251 dpcd_configure_panel_mode(link
, panel_mode
);
1253 skip_video_pattern
= true;
1255 if (link_settings
.link_rate
== LINK_RATE_LOW
)
1256 skip_video_pattern
= false;
1258 if (perform_link_training_with_retries(
1262 LINK_TRAINING_ATTEMPTS
)) {
1263 link
->cur_link_settings
= link_settings
;
1267 status
= DC_FAIL_DP_LINK_TRAINING
;
1269 enable_stream_features(pipe_ctx
);
1274 static enum dc_status
enable_link_dp_mst(
1275 struct dc_state
*state
,
1276 struct pipe_ctx
*pipe_ctx
)
1278 struct dc_link
*link
= pipe_ctx
->stream
->sink
->link
;
1280 /* sink signal type after MST branch is MST. Multiple MST sinks
1281 * share one link. Link DP PHY is enable or training only once.
1283 if (link
->cur_link_settings
.lane_count
!= LANE_COUNT_UNKNOWN
)
1286 /* set the sink to MST mode before enabling the link */
1287 dp_enable_mst_on_sink(link
, true);
1289 return enable_link_dp(state
, pipe_ctx
);
1292 static bool get_ext_hdmi_settings(struct pipe_ctx
*pipe_ctx
,
1293 enum engine_id eng_id
,
1294 struct ext_hdmi_settings
*settings
)
1296 bool result
= false;
1298 struct integrated_info
*integrated_info
=
1299 pipe_ctx
->stream
->ctx
->dc_bios
->integrated_info
;
1301 if (integrated_info
== NULL
)
1305 * Get retimer settings from sbios for passing SI eye test for DCE11
1306 * The setting values are varied based on board revision and port id
1307 * Therefore the setting values of each ports is passed by sbios.
1310 // Check if current bios contains ext Hdmi settings
1311 if (integrated_info
->gpu_cap_info
& 0x20) {
1313 case ENGINE_ID_DIGA
:
1314 settings
->slv_addr
= integrated_info
->dp0_ext_hdmi_slv_addr
;
1315 settings
->reg_num
= integrated_info
->dp0_ext_hdmi_6g_reg_num
;
1316 settings
->reg_num_6g
= integrated_info
->dp0_ext_hdmi_6g_reg_num
;
1317 memmove(settings
->reg_settings
,
1318 integrated_info
->dp0_ext_hdmi_reg_settings
,
1319 sizeof(integrated_info
->dp0_ext_hdmi_reg_settings
));
1320 memmove(settings
->reg_settings_6g
,
1321 integrated_info
->dp0_ext_hdmi_6g_reg_settings
,
1322 sizeof(integrated_info
->dp0_ext_hdmi_6g_reg_settings
));
1325 case ENGINE_ID_DIGB
:
1326 settings
->slv_addr
= integrated_info
->dp1_ext_hdmi_slv_addr
;
1327 settings
->reg_num
= integrated_info
->dp1_ext_hdmi_6g_reg_num
;
1328 settings
->reg_num_6g
= integrated_info
->dp1_ext_hdmi_6g_reg_num
;
1329 memmove(settings
->reg_settings
,
1330 integrated_info
->dp1_ext_hdmi_reg_settings
,
1331 sizeof(integrated_info
->dp1_ext_hdmi_reg_settings
));
1332 memmove(settings
->reg_settings_6g
,
1333 integrated_info
->dp1_ext_hdmi_6g_reg_settings
,
1334 sizeof(integrated_info
->dp1_ext_hdmi_6g_reg_settings
));
1337 case ENGINE_ID_DIGC
:
1338 settings
->slv_addr
= integrated_info
->dp2_ext_hdmi_slv_addr
;
1339 settings
->reg_num
= integrated_info
->dp2_ext_hdmi_6g_reg_num
;
1340 settings
->reg_num_6g
= integrated_info
->dp2_ext_hdmi_6g_reg_num
;
1341 memmove(settings
->reg_settings
,
1342 integrated_info
->dp2_ext_hdmi_reg_settings
,
1343 sizeof(integrated_info
->dp2_ext_hdmi_reg_settings
));
1344 memmove(settings
->reg_settings_6g
,
1345 integrated_info
->dp2_ext_hdmi_6g_reg_settings
,
1346 sizeof(integrated_info
->dp2_ext_hdmi_6g_reg_settings
));
1349 case ENGINE_ID_DIGD
:
1350 settings
->slv_addr
= integrated_info
->dp3_ext_hdmi_slv_addr
;
1351 settings
->reg_num
= integrated_info
->dp3_ext_hdmi_6g_reg_num
;
1352 settings
->reg_num_6g
= integrated_info
->dp3_ext_hdmi_6g_reg_num
;
1353 memmove(settings
->reg_settings
,
1354 integrated_info
->dp3_ext_hdmi_reg_settings
,
1355 sizeof(integrated_info
->dp3_ext_hdmi_reg_settings
));
1356 memmove(settings
->reg_settings_6g
,
1357 integrated_info
->dp3_ext_hdmi_6g_reg_settings
,
1358 sizeof(integrated_info
->dp3_ext_hdmi_6g_reg_settings
));
1365 if (result
== true) {
1366 // Validate settings from bios integrated info table
1367 if (settings
->slv_addr
== 0)
1369 if (settings
->reg_num
> 9)
1371 if (settings
->reg_num_6g
> 3)
1374 for (i
= 0; i
< settings
->reg_num
; i
++) {
1375 if (settings
->reg_settings
[i
].i2c_reg_index
> 0x20)
1379 for (i
= 0; i
< settings
->reg_num_6g
; i
++) {
1380 if (settings
->reg_settings_6g
[i
].i2c_reg_index
> 0x20)
1389 static bool i2c_write(struct pipe_ctx
*pipe_ctx
,
1390 uint8_t address
, uint8_t *buffer
, uint32_t length
)
1392 struct i2c_command cmd
= {0};
1393 struct i2c_payload payload
= {0};
1395 memset(&payload
, 0, sizeof(payload
));
1396 memset(&cmd
, 0, sizeof(cmd
));
1398 cmd
.number_of_payloads
= 1;
1399 cmd
.engine
= I2C_COMMAND_ENGINE_DEFAULT
;
1400 cmd
.speed
= pipe_ctx
->stream
->ctx
->dc
->caps
.i2c_speed_in_khz
;
1402 payload
.address
= address
;
1403 payload
.data
= buffer
;
1404 payload
.length
= length
;
1405 payload
.write
= true;
1406 cmd
.payloads
= &payload
;
1408 if (dc_submit_i2c(pipe_ctx
->stream
->ctx
->dc
,
1409 pipe_ctx
->stream
->sink
->link
->link_index
, &cmd
))
1415 static void write_i2c_retimer_setting(
1416 struct pipe_ctx
*pipe_ctx
,
1418 bool is_over_340mhz
,
1419 struct ext_hdmi_settings
*settings
)
1421 uint8_t slave_address
= (settings
->slv_addr
>> 1);
1423 const uint8_t apply_rx_tx_change
= 0x4;
1424 uint8_t offset
= 0xA;
1427 bool i2c_success
= false;
1429 memset(&buffer
, 0, sizeof(buffer
));
1431 /* Start Ext-Hdmi programming*/
1433 for (i
= 0; i
< settings
->reg_num
; i
++) {
1434 /* Apply 3G settings */
1435 if (settings
->reg_settings
[i
].i2c_reg_index
<= 0x20) {
1437 buffer
[0] = settings
->reg_settings
[i
].i2c_reg_index
;
1438 buffer
[1] = settings
->reg_settings
[i
].i2c_reg_val
;
1439 i2c_success
= i2c_write(pipe_ctx
, slave_address
,
1440 buffer
, sizeof(buffer
));
1444 ASSERT(i2c_success
);
1446 /* Based on DP159 specs, APPLY_RX_TX_CHANGE bit in 0x0A
1447 * needs to be set to 1 on every 0xA-0xC write.
1449 if (settings
->reg_settings
[i
].i2c_reg_index
== 0xA ||
1450 settings
->reg_settings
[i
].i2c_reg_index
== 0xB ||
1451 settings
->reg_settings
[i
].i2c_reg_index
== 0xC) {
1453 /* Query current value from offset 0xA */
1454 if (settings
->reg_settings
[i
].i2c_reg_index
== 0xA)
1455 value
= settings
->reg_settings
[i
].i2c_reg_val
;
1458 dal_ddc_service_query_ddc_data(
1459 pipe_ctx
->stream
->sink
->link
->ddc
,
1460 slave_address
, &offset
, 1, &value
, 1);
1463 ASSERT(i2c_success
);
1467 /* Set APPLY_RX_TX_CHANGE bit to 1 */
1468 buffer
[1] = value
| apply_rx_tx_change
;
1469 i2c_success
= i2c_write(pipe_ctx
, slave_address
,
1470 buffer
, sizeof(buffer
));
1473 ASSERT(i2c_success
);
1478 /* Apply 3G settings */
1479 if (is_over_340mhz
) {
1480 for (i
= 0; i
< settings
->reg_num_6g
; i
++) {
1481 /* Apply 3G settings */
1482 if (settings
->reg_settings
[i
].i2c_reg_index
<= 0x20) {
1484 buffer
[0] = settings
->reg_settings_6g
[i
].i2c_reg_index
;
1485 buffer
[1] = settings
->reg_settings_6g
[i
].i2c_reg_val
;
1486 i2c_success
= i2c_write(pipe_ctx
, slave_address
,
1487 buffer
, sizeof(buffer
));
1491 ASSERT(i2c_success
);
1493 /* Based on DP159 specs, APPLY_RX_TX_CHANGE bit in 0x0A
1494 * needs to be set to 1 on every 0xA-0xC write.
1496 if (settings
->reg_settings_6g
[i
].i2c_reg_index
== 0xA ||
1497 settings
->reg_settings_6g
[i
].i2c_reg_index
== 0xB ||
1498 settings
->reg_settings_6g
[i
].i2c_reg_index
== 0xC) {
1500 /* Query current value from offset 0xA */
1501 if (settings
->reg_settings_6g
[i
].i2c_reg_index
== 0xA)
1502 value
= settings
->reg_settings_6g
[i
].i2c_reg_val
;
1505 dal_ddc_service_query_ddc_data(
1506 pipe_ctx
->stream
->sink
->link
->ddc
,
1507 slave_address
, &offset
, 1, &value
, 1);
1510 ASSERT(i2c_success
);
1514 /* Set APPLY_RX_TX_CHANGE bit to 1 */
1515 buffer
[1] = value
| apply_rx_tx_change
;
1516 i2c_success
= i2c_write(pipe_ctx
, slave_address
,
1517 buffer
, sizeof(buffer
));
1520 ASSERT(i2c_success
);
1527 /* Program additional settings if using 640x480 resolution */
1529 /* Write offset 0xFF to 0x01 */
1532 i2c_success
= i2c_write(pipe_ctx
, slave_address
,
1533 buffer
, sizeof(buffer
));
1536 ASSERT(i2c_success
);
1538 /* Write offset 0x00 to 0x23 */
1541 i2c_success
= i2c_write(pipe_ctx
, slave_address
,
1542 buffer
, sizeof(buffer
));
1545 ASSERT(i2c_success
);
1547 /* Write offset 0xff to 0x00 */
1550 i2c_success
= i2c_write(pipe_ctx
, slave_address
,
1551 buffer
, sizeof(buffer
));
1554 ASSERT(i2c_success
);
1559 static void write_i2c_default_retimer_setting(
1560 struct pipe_ctx
*pipe_ctx
,
1562 bool is_over_340mhz
)
1564 uint8_t slave_address
= (0xBA >> 1);
1566 bool i2c_success
= false;
1568 memset(&buffer
, 0, sizeof(buffer
));
1570 /* Program Slave Address for tuning single integrity */
1571 /* Write offset 0x0A to 0x13 */
1574 i2c_success
= i2c_write(pipe_ctx
, slave_address
,
1575 buffer
, sizeof(buffer
));
1578 ASSERT(i2c_success
);
1580 /* Write offset 0x0A to 0x17 */
1583 i2c_success
= i2c_write(pipe_ctx
, slave_address
,
1584 buffer
, sizeof(buffer
));
1587 ASSERT(i2c_success
);
1589 /* Write offset 0x0B to 0xDA or 0xD8 */
1591 buffer
[1] = is_over_340mhz
? 0xDA : 0xD8;
1592 i2c_success
= i2c_write(pipe_ctx
, slave_address
,
1593 buffer
, sizeof(buffer
));
1596 ASSERT(i2c_success
);
1598 /* Write offset 0x0A to 0x17 */
1601 i2c_success
= i2c_write(pipe_ctx
, slave_address
,
1602 buffer
, sizeof(buffer
));
1605 ASSERT(i2c_success
);
1607 /* Write offset 0x0C to 0x1D or 0x91 */
1609 buffer
[1] = is_over_340mhz
? 0x1D : 0x91;
1610 i2c_success
= i2c_write(pipe_ctx
, slave_address
,
1611 buffer
, sizeof(buffer
));
1614 ASSERT(i2c_success
);
1616 /* Write offset 0x0A to 0x17 */
1619 i2c_success
= i2c_write(pipe_ctx
, slave_address
,
1620 buffer
, sizeof(buffer
));
1623 ASSERT(i2c_success
);
1627 /* Program additional settings if using 640x480 resolution */
1629 /* Write offset 0xFF to 0x01 */
1632 i2c_success
= i2c_write(pipe_ctx
, slave_address
,
1633 buffer
, sizeof(buffer
));
1636 ASSERT(i2c_success
);
1638 /* Write offset 0x00 to 0x23 */
1641 i2c_success
= i2c_write(pipe_ctx
, slave_address
,
1642 buffer
, sizeof(buffer
));
1645 ASSERT(i2c_success
);
1647 /* Write offset 0xff to 0x00 */
1650 i2c_success
= i2c_write(pipe_ctx
, slave_address
,
1651 buffer
, sizeof(buffer
));
1654 ASSERT(i2c_success
);
1658 static void write_i2c_redriver_setting(
1659 struct pipe_ctx
*pipe_ctx
,
1660 bool is_over_340mhz
)
1662 uint8_t slave_address
= (0xF0 >> 1);
1664 bool i2c_success
= false;
1666 memset(&buffer
, 0, sizeof(buffer
));
1668 // Program Slave Address for tuning single integrity
1672 buffer
[6] = is_over_340mhz
? 0x4E : 0x4A;
1674 i2c_success
= i2c_write(pipe_ctx
, slave_address
,
1675 buffer
, sizeof(buffer
));
1679 ASSERT(i2c_success
);
1682 static void enable_link_hdmi(struct pipe_ctx
*pipe_ctx
)
1684 struct dc_stream_state
*stream
= pipe_ctx
->stream
;
1685 struct dc_link
*link
= stream
->sink
->link
;
1686 enum dc_color_depth display_color_depth
;
1687 enum engine_id eng_id
;
1688 struct ext_hdmi_settings settings
= {0};
1689 bool is_over_340mhz
= false;
1690 bool is_vga_mode
= (stream
->timing
.h_addressable
== 640)
1691 && (stream
->timing
.v_addressable
== 480);
1693 if (stream
->phy_pix_clk
> 340000)
1694 is_over_340mhz
= true;
1696 if (dc_is_hdmi_signal(pipe_ctx
->stream
->signal
)) {
1697 unsigned short masked_chip_caps
= pipe_ctx
->stream
->sink
->link
->chip_caps
&
1698 EXT_DISPLAY_PATH_CAPS__EXT_CHIP_MASK
;
1699 if (masked_chip_caps
== EXT_DISPLAY_PATH_CAPS__HDMI20_TISN65DP159RSBT
) {
1700 /* DP159, Retimer settings */
1701 eng_id
= pipe_ctx
->stream_res
.stream_enc
->id
;
1703 if (get_ext_hdmi_settings(pipe_ctx
, eng_id
, &settings
)) {
1704 write_i2c_retimer_setting(pipe_ctx
,
1705 is_vga_mode
, is_over_340mhz
, &settings
);
1707 write_i2c_default_retimer_setting(pipe_ctx
,
1708 is_vga_mode
, is_over_340mhz
);
1710 } else if (masked_chip_caps
== EXT_DISPLAY_PATH_CAPS__HDMI20_PI3EQX1204
) {
1711 /* PI3EQX1204, Redriver settings */
1712 write_i2c_redriver_setting(pipe_ctx
, is_over_340mhz
);
1716 if (dc_is_hdmi_signal(pipe_ctx
->stream
->signal
))
1717 dal_ddc_service_write_scdc_data(
1718 stream
->sink
->link
->ddc
,
1719 stream
->phy_pix_clk
,
1720 stream
->timing
.flags
.LTE_340MCSC_SCRAMBLE
);
1722 memset(&stream
->sink
->link
->cur_link_settings
, 0,
1723 sizeof(struct dc_link_settings
));
1725 display_color_depth
= stream
->timing
.display_color_depth
;
1726 if (stream
->timing
.pixel_encoding
== PIXEL_ENCODING_YCBCR422
)
1727 display_color_depth
= COLOR_DEPTH_888
;
1729 link
->link_enc
->funcs
->enable_tmds_output(
1731 pipe_ctx
->clock_source
->id
,
1732 display_color_depth
,
1733 pipe_ctx
->stream
->signal
== SIGNAL_TYPE_HDMI_TYPE_A
,
1734 pipe_ctx
->stream
->signal
== SIGNAL_TYPE_DVI_DUAL_LINK
,
1735 stream
->phy_pix_clk
);
1737 if (pipe_ctx
->stream
->signal
== SIGNAL_TYPE_HDMI_TYPE_A
)
1738 dal_ddc_service_read_scdc_data(link
->ddc
);
1741 /****************************enable_link***********************************/
1742 static enum dc_status
enable_link(
1743 struct dc_state
*state
,
1744 struct pipe_ctx
*pipe_ctx
)
1746 enum dc_status status
= DC_ERROR_UNEXPECTED
;
1747 switch (pipe_ctx
->stream
->signal
) {
1748 case SIGNAL_TYPE_DISPLAY_PORT
:
1749 case SIGNAL_TYPE_EDP
:
1750 status
= enable_link_dp(state
, pipe_ctx
);
1752 case SIGNAL_TYPE_DISPLAY_PORT_MST
:
1753 status
= enable_link_dp_mst(state
, pipe_ctx
);
1756 case SIGNAL_TYPE_DVI_SINGLE_LINK
:
1757 case SIGNAL_TYPE_DVI_DUAL_LINK
:
1758 case SIGNAL_TYPE_HDMI_TYPE_A
:
1759 enable_link_hdmi(pipe_ctx
);
1762 case SIGNAL_TYPE_VIRTUAL
:
1769 if (pipe_ctx
->stream_res
.audio
&& status
== DC_OK
) {
1770 /* notify audio driver for audio modes of monitor */
1771 pipe_ctx
->stream_res
.audio
->funcs
->az_enable(pipe_ctx
->stream_res
.audio
);
1774 /* TODO: audio should be per stream rather than per link */
1775 pipe_ctx
->stream_res
.stream_enc
->funcs
->audio_mute_control(
1776 pipe_ctx
->stream_res
.stream_enc
, false);
1782 static void disable_link(struct dc_link
*link
, enum signal_type signal
)
1785 * TODO: implement call for dp_set_hw_test_pattern
1786 * it is needed for compliance testing
1789 /* here we need to specify that encoder output settings
1790 * need to be calculated as for the set mode,
1791 * it will lead to querying dynamic link capabilities
1792 * which should be done before enable output */
1794 if (dc_is_dp_signal(signal
)) {
1796 if (dc_is_dp_sst_signal(signal
))
1797 dp_disable_link_phy(link
, signal
);
1799 dp_disable_link_phy_mst(link
, signal
);
1801 link
->link_enc
->funcs
->disable_output(link
->link_enc
, signal
, link
);
1804 enum dc_status
dc_link_validate_mode_timing(
1805 const struct dc_stream_state
*stream
,
1806 struct dc_link
*link
,
1807 const struct dc_crtc_timing
*timing
)
1809 uint32_t max_pix_clk
= stream
->sink
->dongle_max_pix_clk
;
1811 /* A hack to avoid failing any modes for EDID override feature on
1812 * topology change such as lower quality cable for DP or different dongle
1814 if (link
->remote_sinks
[0])
1817 if (0 != max_pix_clk
&& timing
->pix_clk_khz
> max_pix_clk
)
1818 return DC_EXCEED_DONGLE_MAX_CLK
;
1820 switch (stream
->signal
) {
1821 case SIGNAL_TYPE_EDP
:
1822 case SIGNAL_TYPE_DISPLAY_PORT
:
1823 if (!dp_validate_mode_timing(
1826 return DC_NO_DP_LINK_BANDWIDTH
;
1837 bool dc_link_set_backlight_level(const struct dc_link
*link
, uint32_t level
,
1838 uint32_t frame_ramp
, const struct dc_stream_state
*stream
)
1840 struct dc
*core_dc
= link
->ctx
->dc
;
1841 struct abm
*abm
= core_dc
->res_pool
->abm
;
1842 unsigned int controller_id
= 0;
1845 if ((abm
== NULL
) || (abm
->funcs
->set_backlight_level
== NULL
))
1848 dm_logger_write(link
->ctx
->logger
, LOG_BACKLIGHT
,
1849 "New Backlight level: %d (0x%X)\n", level
, level
);
1851 if (dc_is_embedded_signal(link
->connector_signal
)) {
1852 if (stream
!= NULL
) {
1853 for (i
= 0; i
< MAX_PIPES
; i
++) {
1854 if (core_dc
->current_state
->res_ctx
.
1857 /* DMCU -1 for all controller id values,
1861 core_dc
->current_state
->
1862 res_ctx
.pipe_ctx
[i
].stream_res
.tg
->inst
+
1866 abm
->funcs
->set_backlight_level(
1876 bool dc_link_set_psr_enable(const struct dc_link
*link
, bool enable
, bool wait
)
1878 struct dc
*core_dc
= link
->ctx
->dc
;
1879 struct dmcu
*dmcu
= core_dc
->res_pool
->dmcu
;
1881 if (dmcu
!= NULL
&& link
->psr_enabled
)
1882 dmcu
->funcs
->set_psr_enable(dmcu
, enable
, wait
);
1887 bool dc_link_get_psr_state(const struct dc_link
*link
, uint32_t *psr_state
)
1889 struct dc
*core_dc
= link
->ctx
->dc
;
1890 struct dmcu
*dmcu
= core_dc
->res_pool
->dmcu
;
1892 if (dmcu
!= NULL
&& link
->psr_enabled
)
1893 dmcu
->funcs
->get_psr_state(dmcu
, psr_state
);
1898 bool dc_link_setup_psr(struct dc_link
*link
,
1899 const struct dc_stream_state
*stream
, struct psr_config
*psr_config
,
1900 struct psr_context
*psr_context
)
1902 struct dc
*core_dc
= link
->ctx
->dc
;
1903 struct dmcu
*dmcu
= core_dc
->res_pool
->dmcu
;
1906 psr_context
->controllerId
= CONTROLLER_ID_UNDEFINED
;
1910 /* updateSinkPsrDpcdConfig*/
1911 union dpcd_psr_configuration psr_configuration
;
1913 memset(&psr_configuration
, 0, sizeof(psr_configuration
));
1915 psr_configuration
.bits
.ENABLE
= 1;
1916 psr_configuration
.bits
.CRC_VERIFICATION
= 1;
1917 psr_configuration
.bits
.FRAME_CAPTURE_INDICATION
=
1918 psr_config
->psr_frame_capture_indication_req
;
1920 /* Check for PSR v2*/
1921 if (psr_config
->psr_version
== 0x2) {
1922 /* For PSR v2 selective update.
1923 * Indicates whether sink should start capturing
1924 * immediately following active scan line,
1925 * or starting with the 2nd active scan line.
1927 psr_configuration
.bits
.LINE_CAPTURE_INDICATION
= 0;
1928 /*For PSR v2, determines whether Sink should generate
1929 * IRQ_HPD when CRC mismatch is detected.
1931 psr_configuration
.bits
.IRQ_HPD_WITH_CRC_ERROR
= 1;
1934 dm_helpers_dp_write_dpcd(
1938 &psr_configuration
.raw
,
1939 sizeof(psr_configuration
.raw
));
1941 psr_context
->channel
= link
->ddc
->ddc_pin
->hw_info
.ddc_channel
;
1942 psr_context
->transmitterId
= link
->link_enc
->transmitter
;
1943 psr_context
->engineId
= link
->link_enc
->preferred_engine
;
1945 for (i
= 0; i
< MAX_PIPES
; i
++) {
1946 if (core_dc
->current_state
->res_ctx
.pipe_ctx
[i
].stream
1948 /* dmcu -1 for all controller id values,
1951 psr_context
->controllerId
=
1952 core_dc
->current_state
->res_ctx
.
1953 pipe_ctx
[i
].stream_res
.tg
->inst
+ 1;
1958 /* Hardcoded for now. Can be Pcie or Uniphy (or Unknown)*/
1959 psr_context
->phyType
= PHY_TYPE_UNIPHY
;
1960 /*PhyId is associated with the transmitter id*/
1961 psr_context
->smuPhyId
= link
->link_enc
->transmitter
;
1963 psr_context
->crtcTimingVerticalTotal
= stream
->timing
.v_total
;
1964 psr_context
->vsyncRateHz
= div64_u64(div64_u64((stream
->
1965 timing
.pix_clk_khz
* 1000),
1966 stream
->timing
.v_total
),
1967 stream
->timing
.h_total
);
1969 psr_context
->psrSupportedDisplayConfig
= true;
1970 psr_context
->psrExitLinkTrainingRequired
=
1971 psr_config
->psr_exit_link_training_required
;
1972 psr_context
->sdpTransmitLineNumDeadline
=
1973 psr_config
->psr_sdp_transmit_line_num_deadline
;
1974 psr_context
->psrFrameCaptureIndicationReq
=
1975 psr_config
->psr_frame_capture_indication_req
;
1977 psr_context
->skipPsrWaitForPllLock
= 0; /* only = 1 in KV */
1979 psr_context
->numberOfControllers
=
1980 link
->dc
->res_pool
->res_cap
->num_timing_generator
;
1982 psr_context
->rfb_update_auto_en
= true;
1984 /* 2 frames before enter PSR. */
1985 psr_context
->timehyst_frames
= 2;
1987 * (units in 100 lines, i.e. a value of 1 represents 100 lines)
1989 psr_context
->hyst_lines
= stream
->timing
.v_total
/ 2 / 100;
1990 psr_context
->aux_repeats
= 10;
1992 psr_context
->psr_level
.u32all
= 0;
1994 #if defined(CONFIG_DRM_AMD_DC_DCN1_0)
1995 /*skip power down the single pipe since it blocks the cstate*/
1996 if (ASIC_REV_IS_RAVEN(link
->ctx
->asic_id
.hw_internal_rev
))
1997 psr_context
->psr_level
.bits
.SKIP_CRTC_DISABLE
= true;
2000 /* SMU will perform additional powerdown sequence.
2001 * For unsupported ASICs, set psr_level flag to skip PSR
2002 * static screen notification to SMU.
2003 * (Always set for DAL2, did not check ASIC)
2005 psr_context
->psr_level
.bits
.SKIP_SMU_NOTIFICATION
= 1;
2007 /* Complete PSR entry before aborting to prevent intermittent
2008 * freezes on certain eDPs
2010 psr_context
->psr_level
.bits
.DISABLE_PSR_ENTRY_ABORT
= 1;
2012 /* Controls additional delay after remote frame capture before
2013 * continuing power down, default = 0
2015 psr_context
->frame_delay
= 0;
2017 link
->psr_enabled
= true;
2018 dmcu
->funcs
->setup_psr(dmcu
, link
, psr_context
);
2025 const struct dc_link_status
*dc_link_get_status(const struct dc_link
*link
)
2027 return &link
->link_status
;
2030 void core_link_resume(struct dc_link
*link
)
2032 if (link
->connector_signal
!= SIGNAL_TYPE_VIRTUAL
)
2033 program_hpd_filter(link
);
2036 static struct fixed31_32
get_pbn_per_slot(struct dc_stream_state
*stream
)
2038 struct dc_link_settings
*link_settings
=
2039 &stream
->sink
->link
->cur_link_settings
;
2040 uint32_t link_rate_in_mbps
=
2041 link_settings
->link_rate
* LINK_RATE_REF_FREQ_IN_MHZ
;
2042 struct fixed31_32 mbps
= dal_fixed31_32_from_int(
2043 link_rate_in_mbps
* link_settings
->lane_count
);
2045 return dal_fixed31_32_div_int(mbps
, 54);
2048 static int get_color_depth(enum dc_color_depth color_depth
)
2050 switch (color_depth
) {
2051 case COLOR_DEPTH_666
: return 6;
2052 case COLOR_DEPTH_888
: return 8;
2053 case COLOR_DEPTH_101010
: return 10;
2054 case COLOR_DEPTH_121212
: return 12;
2055 case COLOR_DEPTH_141414
: return 14;
2056 case COLOR_DEPTH_161616
: return 16;
2061 static struct fixed31_32
get_pbn_from_timing(struct pipe_ctx
*pipe_ctx
)
2065 struct fixed31_32 peak_kbps
;
2067 uint32_t denominator
;
2069 bpc
= get_color_depth(pipe_ctx
->stream_res
.pix_clk_params
.color_depth
);
2070 kbps
= pipe_ctx
->stream_res
.pix_clk_params
.requested_pix_clk
* bpc
* 3;
2073 * margin 5300ppm + 300ppm ~ 0.6% as per spec, factor is 1.006
2074 * The unit of 54/64Mbytes/sec is an arbitrary unit chosen based on
2075 * common multiplier to render an integer PBN for all link rate/lane
2076 * counts combinations
2078 * peak_kbps *= (1006/1000)
2079 * peak_kbps *= (64/54)
2080 * peak_kbps *= 8 convert to bytes
2083 numerator
= 64 * PEAK_FACTOR_X1000
;
2084 denominator
= 54 * 8 * 1000 * 1000;
2086 peak_kbps
= dal_fixed31_32_from_fraction(kbps
, denominator
);
2091 static void update_mst_stream_alloc_table(
2092 struct dc_link
*link
,
2093 struct stream_encoder
*stream_enc
,
2094 const struct dp_mst_stream_allocation_table
*proposed_table
)
2096 struct link_mst_stream_allocation work_table
[MAX_CONTROLLER_NUM
] = {
2098 struct link_mst_stream_allocation
*dc_alloc
;
2103 /* if DRM proposed_table has more than one new payload */
2104 ASSERT(proposed_table
->stream_count
-
2105 link
->mst_stream_alloc_table
.stream_count
< 2);
2107 /* copy proposed_table to link, add stream encoder */
2108 for (i
= 0; i
< proposed_table
->stream_count
; i
++) {
2110 for (j
= 0; j
< link
->mst_stream_alloc_table
.stream_count
; j
++) {
2112 &link
->mst_stream_alloc_table
.stream_allocations
[j
];
2114 if (dc_alloc
->vcp_id
==
2115 proposed_table
->stream_allocations
[i
].vcp_id
) {
2117 work_table
[i
] = *dc_alloc
;
2118 break; /* exit j loop */
2123 if (j
== link
->mst_stream_alloc_table
.stream_count
) {
2124 work_table
[i
].vcp_id
=
2125 proposed_table
->stream_allocations
[i
].vcp_id
;
2126 work_table
[i
].slot_count
=
2127 proposed_table
->stream_allocations
[i
].slot_count
;
2128 work_table
[i
].stream_enc
= stream_enc
;
2132 /* update link->mst_stream_alloc_table with work_table */
2133 link
->mst_stream_alloc_table
.stream_count
=
2134 proposed_table
->stream_count
;
2135 for (i
= 0; i
< MAX_CONTROLLER_NUM
; i
++)
2136 link
->mst_stream_alloc_table
.stream_allocations
[i
] =
2140 /* convert link_mst_stream_alloc_table to dm dp_mst_stream_alloc_table
2141 * because stream_encoder is not exposed to dm
2143 static enum dc_status
allocate_mst_payload(struct pipe_ctx
*pipe_ctx
)
2145 struct dc_stream_state
*stream
= pipe_ctx
->stream
;
2146 struct dc_link
*link
= stream
->sink
->link
;
2147 struct link_encoder
*link_encoder
= link
->link_enc
;
2148 struct stream_encoder
*stream_encoder
= pipe_ctx
->stream_res
.stream_enc
;
2149 struct dp_mst_stream_allocation_table proposed_table
= {0};
2150 struct fixed31_32 avg_time_slots_per_mtp
;
2151 struct fixed31_32 pbn
;
2152 struct fixed31_32 pbn_per_slot
;
2155 /* enable_link_dp_mst already check link->enabled_stream_count
2156 * and stream is in link->stream[]. This is called during set mode,
2157 * stream_enc is available.
2160 /* get calculate VC payload for stream: stream_alloc */
2161 if (dm_helpers_dp_mst_write_payload_allocation_table(
2166 update_mst_stream_alloc_table(
2167 link
, pipe_ctx
->stream_res
.stream_enc
, &proposed_table
);
2170 dm_logger_write(link
->ctx
->logger
, LOG_WARNING
,
2172 "MST allocation table for"
2174 pipe_ctx
->pipe_idx
);
2176 dm_logger_write(link
->ctx
->logger
, LOG_MST
,
2178 "stream_count: %d: \n ",
2180 link
->mst_stream_alloc_table
.stream_count
);
2182 for (i
= 0; i
< MAX_CONTROLLER_NUM
; i
++) {
2183 dm_logger_write(link
->ctx
->logger
, LOG_MST
,
2184 "stream_enc[%d]: 0x%x "
2185 "stream[%d].vcp_id: %d "
2186 "stream[%d].slot_count: %d\n",
2188 link
->mst_stream_alloc_table
.stream_allocations
[i
].stream_enc
,
2190 link
->mst_stream_alloc_table
.stream_allocations
[i
].vcp_id
,
2192 link
->mst_stream_alloc_table
.stream_allocations
[i
].slot_count
);
2195 ASSERT(proposed_table
.stream_count
> 0);
2197 /* program DP source TX for payload */
2198 link_encoder
->funcs
->update_mst_stream_allocation_table(
2200 &link
->mst_stream_alloc_table
);
2202 /* send down message */
2203 dm_helpers_dp_mst_poll_for_allocation_change_trigger(
2207 dm_helpers_dp_mst_send_payload_allocation(
2212 /* slot X.Y for only current stream */
2213 pbn_per_slot
= get_pbn_per_slot(stream
);
2214 pbn
= get_pbn_from_timing(pipe_ctx
);
2215 avg_time_slots_per_mtp
= dal_fixed31_32_div(pbn
, pbn_per_slot
);
2217 stream_encoder
->funcs
->set_mst_bandwidth(
2219 avg_time_slots_per_mtp
);
2225 static enum dc_status
deallocate_mst_payload(struct pipe_ctx
*pipe_ctx
)
2227 struct dc_stream_state
*stream
= pipe_ctx
->stream
;
2228 struct dc_link
*link
= stream
->sink
->link
;
2229 struct link_encoder
*link_encoder
= link
->link_enc
;
2230 struct stream_encoder
*stream_encoder
= pipe_ctx
->stream_res
.stream_enc
;
2231 struct dp_mst_stream_allocation_table proposed_table
= {0};
2232 struct fixed31_32 avg_time_slots_per_mtp
= dal_fixed31_32_from_int(0);
2234 bool mst_mode
= (link
->type
== dc_connection_mst_branch
);
2236 /* deallocate_mst_payload is called before disable link. When mode or
2237 * disable/enable monitor, new stream is created which is not in link
2238 * stream[] yet. For this, payload is not allocated yet, so de-alloc
2239 * should not done. For new mode set, map_resources will get engine
2240 * for new stream, so stream_enc->id should be validated until here.
2244 stream_encoder
->funcs
->set_mst_bandwidth(
2246 avg_time_slots_per_mtp
);
2248 /* TODO: which component is responsible for remove payload table? */
2250 if (dm_helpers_dp_mst_write_payload_allocation_table(
2256 update_mst_stream_alloc_table(
2257 link
, pipe_ctx
->stream_res
.stream_enc
, &proposed_table
);
2260 dm_logger_write(link
->ctx
->logger
, LOG_WARNING
,
2262 "MST allocation table for"
2264 pipe_ctx
->pipe_idx
);
2268 dm_logger_write(link
->ctx
->logger
, LOG_MST
,
2270 "stream_count: %d: ",
2272 link
->mst_stream_alloc_table
.stream_count
);
2274 for (i
= 0; i
< MAX_CONTROLLER_NUM
; i
++) {
2275 dm_logger_write(link
->ctx
->logger
, LOG_MST
,
2276 "stream_enc[%d]: 0x%x "
2277 "stream[%d].vcp_id: %d "
2278 "stream[%d].slot_count: %d\n",
2280 link
->mst_stream_alloc_table
.stream_allocations
[i
].stream_enc
,
2282 link
->mst_stream_alloc_table
.stream_allocations
[i
].vcp_id
,
2284 link
->mst_stream_alloc_table
.stream_allocations
[i
].slot_count
);
2287 link_encoder
->funcs
->update_mst_stream_allocation_table(
2289 &link
->mst_stream_alloc_table
);
2292 dm_helpers_dp_mst_poll_for_allocation_change_trigger(
2296 dm_helpers_dp_mst_send_payload_allocation(
2305 void core_link_enable_stream(
2306 struct dc_state
*state
,
2307 struct pipe_ctx
*pipe_ctx
)
2309 struct dc
*core_dc
= pipe_ctx
->stream
->ctx
->dc
;
2311 enum dc_status status
= enable_link(state
, pipe_ctx
);
2313 if (status
!= DC_OK
) {
2314 dm_logger_write(pipe_ctx
->stream
->ctx
->logger
,
2315 LOG_WARNING
, "enabling link %u failed: %d\n",
2316 pipe_ctx
->stream
->sink
->link
->link_index
,
2319 /* Abort stream enable *unless* the failure was due to
2320 * DP link training - some DP monitors will recover and
2321 * show the stream anyway. But MST displays can't proceed
2322 * without link training.
2324 if (status
!= DC_FAIL_DP_LINK_TRAINING
||
2325 pipe_ctx
->stream
->signal
== SIGNAL_TYPE_DISPLAY_PORT_MST
) {
2326 BREAK_TO_DEBUGGER();
2331 /* turn off otg test pattern if enable */
2332 pipe_ctx
->stream_res
.tg
->funcs
->set_test_pattern(pipe_ctx
->stream_res
.tg
,
2333 CONTROLLER_DP_TEST_PATTERN_VIDEOMODE
,
2334 COLOR_DEPTH_UNDEFINED
);
2336 core_dc
->hwss
.enable_stream(pipe_ctx
);
2338 if (pipe_ctx
->stream
->signal
== SIGNAL_TYPE_DISPLAY_PORT_MST
)
2339 allocate_mst_payload(pipe_ctx
);
2341 if (dc_is_dp_signal(pipe_ctx
->stream
->signal
))
2342 core_dc
->hwss
.unblank_stream(pipe_ctx
,
2343 &pipe_ctx
->stream
->sink
->link
->cur_link_settings
);
2346 void core_link_disable_stream(struct pipe_ctx
*pipe_ctx
, int option
)
2348 struct dc
*core_dc
= pipe_ctx
->stream
->ctx
->dc
;
2350 if (pipe_ctx
->stream
->signal
== SIGNAL_TYPE_DISPLAY_PORT_MST
)
2351 deallocate_mst_payload(pipe_ctx
);
2353 core_dc
->hwss
.disable_stream(pipe_ctx
, option
);
2355 disable_link(pipe_ctx
->stream
->sink
->link
, pipe_ctx
->stream
->signal
);
2358 void core_link_set_avmute(struct pipe_ctx
*pipe_ctx
, bool enable
)
2360 struct dc
*core_dc
= pipe_ctx
->stream
->ctx
->dc
;
2362 if (pipe_ctx
->stream
->signal
!= SIGNAL_TYPE_HDMI_TYPE_A
)
2365 core_dc
->hwss
.set_avmute(pipe_ctx
, enable
);