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"
38 #include "link_encoder.h"
39 #include "hw_sequencer.h"
42 #include "fixed31_32.h"
43 #include "dpcd_defs.h"
46 #include "dce/dce_11_0_d.h"
47 #include "dce/dce_11_0_enum.h"
48 #include "dce/dce_11_0_sh_mask.h"
50 #define DC_LOGGER_INIT(logger)
53 #define LINK_INFO(...) \
57 #define RETIMER_REDRIVER_INFO(...) \
58 DC_LOG_RETIMER_REDRIVER( \
60 /*******************************************************************************
62 ******************************************************************************/
65 LINK_RATE_REF_FREQ_IN_MHZ = 27,
66 PEAK_FACTOR_X1000 = 1006,
68 * Some receivers fail to train on first try and are good
69 * on subsequent tries. 2 retries should be plenty. If we
70 * don't have a successful training then we don't expect to
73 LINK_TRAINING_MAX_VERIFY_RETRY = 2
76 /*******************************************************************************
78 ******************************************************************************/
79 static void destruct(struct dc_link *link)
84 dal_ddc_service_destroy(&link->ddc);
87 link->link_enc->funcs->destroy(&link->link_enc);
90 dc_sink_release(link->local_sink);
92 for (i = 0; i < link->sink_count; ++i)
93 dc_sink_release(link->remote_sinks[i]);
96 struct gpio *get_hpd_gpio(struct dc_bios *dcb,
97 struct graphics_object_id link_id,
98 struct gpio_service *gpio_service)
100 enum bp_result bp_result;
101 struct graphics_object_hpd_info hpd_info;
102 struct gpio_pin_info pin_info;
104 if (dcb->funcs->get_hpd_info(dcb, link_id, &hpd_info) != BP_RESULT_OK)
107 bp_result = dcb->funcs->get_gpio_pin_info(dcb,
108 hpd_info.hpd_int_gpio_uid, &pin_info);
110 if (bp_result != BP_RESULT_OK) {
111 ASSERT(bp_result == BP_RESULT_NORECORD);
115 return dal_gpio_service_create_irq(
122 * Function: program_hpd_filter
125 * Programs HPD filter on associated HPD line
127 * @param [in] delay_on_connect_in_ms: Connect filter timeout
128 * @param [in] delay_on_disconnect_in_ms: Disconnect filter timeout
131 * true on success, false otherwise
133 static bool program_hpd_filter(
134 const struct dc_link *link)
140 int delay_on_connect_in_ms = 0;
141 int delay_on_disconnect_in_ms = 0;
143 if (link->is_hpd_filter_disabled)
145 /* Verify feature is supported */
146 switch (link->connector_signal) {
147 case SIGNAL_TYPE_DVI_SINGLE_LINK:
148 case SIGNAL_TYPE_DVI_DUAL_LINK:
149 case SIGNAL_TYPE_HDMI_TYPE_A:
150 /* Program hpd filter */
151 delay_on_connect_in_ms = 500;
152 delay_on_disconnect_in_ms = 100;
154 case SIGNAL_TYPE_DISPLAY_PORT:
155 case SIGNAL_TYPE_DISPLAY_PORT_MST:
156 /* Program hpd filter to allow DP signal to settle */
157 /* 500: not able to detect MST <-> SST switch as HPD is low for
158 * only 100ms on DELL U2413
159 * 0: some passive dongle still show aux mode instead of i2c
160 * 20-50:not enough to hide bouncing HPD with passive dongle.
161 * also see intermittent i2c read issues.
163 delay_on_connect_in_ms = 80;
164 delay_on_disconnect_in_ms = 0;
166 case SIGNAL_TYPE_LVDS:
167 case SIGNAL_TYPE_EDP:
169 /* Don't program hpd filter */
173 /* Obtain HPD handle */
174 hpd = get_hpd_gpio(link->ctx->dc_bios, link->link_id, link->ctx->gpio_service);
179 /* Setup HPD filtering */
180 if (dal_gpio_open(hpd, GPIO_MODE_INTERRUPT) == GPIO_RESULT_OK) {
181 struct gpio_hpd_config config;
183 config.delay_on_connect = delay_on_connect_in_ms;
184 config.delay_on_disconnect = delay_on_disconnect_in_ms;
186 dal_irq_setup_hpd_filter(hpd, &config);
192 ASSERT_CRITICAL(false);
195 /* Release HPD handle */
196 dal_gpio_destroy_irq(&hpd);
201 bool dc_link_detect_sink(struct dc_link *link, enum dc_connection_type *type)
203 uint32_t is_hpd_high = 0;
204 struct gpio *hpd_pin;
206 if (link->connector_signal == SIGNAL_TYPE_LVDS) {
207 *type = dc_connection_single;
211 /* todo: may need to lock gpio access */
212 hpd_pin = get_hpd_gpio(link->ctx->dc_bios, link->link_id, link->ctx->gpio_service);
214 goto hpd_gpio_failure;
216 dal_gpio_open(hpd_pin, GPIO_MODE_INTERRUPT);
217 dal_gpio_get_value(hpd_pin, &is_hpd_high);
218 dal_gpio_close(hpd_pin);
219 dal_gpio_destroy_irq(&hpd_pin);
222 *type = dc_connection_single;
223 /* TODO: need to do the actual detection */
225 *type = dc_connection_none;
234 static enum ddc_transaction_type get_ddc_transaction_type(
235 enum signal_type sink_signal)
237 enum ddc_transaction_type transaction_type = DDC_TRANSACTION_TYPE_NONE;
239 switch (sink_signal) {
240 case SIGNAL_TYPE_DVI_SINGLE_LINK:
241 case SIGNAL_TYPE_DVI_DUAL_LINK:
242 case SIGNAL_TYPE_HDMI_TYPE_A:
243 case SIGNAL_TYPE_LVDS:
244 case SIGNAL_TYPE_RGB:
245 transaction_type = DDC_TRANSACTION_TYPE_I2C;
248 case SIGNAL_TYPE_DISPLAY_PORT:
249 case SIGNAL_TYPE_EDP:
250 transaction_type = DDC_TRANSACTION_TYPE_I2C_OVER_AUX;
253 case SIGNAL_TYPE_DISPLAY_PORT_MST:
254 /* MST does not use I2COverAux, but there is the
255 * SPECIAL use case for "immediate dwnstrm device
256 * access" (EPR#370830). */
257 transaction_type = DDC_TRANSACTION_TYPE_I2C_OVER_AUX;
264 return transaction_type;
267 static enum signal_type get_basic_signal_type(
268 struct graphics_object_id encoder,
269 struct graphics_object_id downstream)
271 if (downstream.type == OBJECT_TYPE_CONNECTOR) {
272 switch (downstream.id) {
273 case CONNECTOR_ID_SINGLE_LINK_DVII:
274 switch (encoder.id) {
275 case ENCODER_ID_INTERNAL_DAC1:
276 case ENCODER_ID_INTERNAL_KLDSCP_DAC1:
277 case ENCODER_ID_INTERNAL_DAC2:
278 case ENCODER_ID_INTERNAL_KLDSCP_DAC2:
279 return SIGNAL_TYPE_RGB;
281 return SIGNAL_TYPE_DVI_SINGLE_LINK;
284 case CONNECTOR_ID_DUAL_LINK_DVII:
286 switch (encoder.id) {
287 case ENCODER_ID_INTERNAL_DAC1:
288 case ENCODER_ID_INTERNAL_KLDSCP_DAC1:
289 case ENCODER_ID_INTERNAL_DAC2:
290 case ENCODER_ID_INTERNAL_KLDSCP_DAC2:
291 return SIGNAL_TYPE_RGB;
293 return SIGNAL_TYPE_DVI_DUAL_LINK;
297 case CONNECTOR_ID_SINGLE_LINK_DVID:
298 return SIGNAL_TYPE_DVI_SINGLE_LINK;
299 case CONNECTOR_ID_DUAL_LINK_DVID:
300 return SIGNAL_TYPE_DVI_DUAL_LINK;
301 case CONNECTOR_ID_VGA:
302 return SIGNAL_TYPE_RGB;
303 case CONNECTOR_ID_HDMI_TYPE_A:
304 return SIGNAL_TYPE_HDMI_TYPE_A;
305 case CONNECTOR_ID_LVDS:
306 return SIGNAL_TYPE_LVDS;
307 case CONNECTOR_ID_DISPLAY_PORT:
308 return SIGNAL_TYPE_DISPLAY_PORT;
309 case CONNECTOR_ID_EDP:
310 return SIGNAL_TYPE_EDP;
312 return SIGNAL_TYPE_NONE;
314 } else if (downstream.type == OBJECT_TYPE_ENCODER) {
315 switch (downstream.id) {
316 case ENCODER_ID_EXTERNAL_NUTMEG:
317 case ENCODER_ID_EXTERNAL_TRAVIS:
318 return SIGNAL_TYPE_DISPLAY_PORT;
320 return SIGNAL_TYPE_NONE;
324 return SIGNAL_TYPE_NONE;
329 * Check whether there is a dongle on DP connector
331 bool dc_link_is_dp_sink_present(struct dc_link *link)
333 enum gpio_result gpio_result;
334 uint32_t clock_pin = 0;
338 enum connector_id connector_id =
339 dal_graphics_object_id_get_connector_id(link->link_id);
342 ((connector_id == CONNECTOR_ID_DISPLAY_PORT) ||
343 (connector_id == CONNECTOR_ID_EDP));
345 ddc = dal_ddc_service_get_ddc_pin(link->ddc);
352 /* Open GPIO and set it to I2C mode */
353 /* Note: this GpioMode_Input will be converted
354 * to GpioConfigType_I2cAuxDualMode in GPIO component,
355 * which indicates we need additional delay */
357 if (GPIO_RESULT_OK != dal_ddc_open(
358 ddc, GPIO_MODE_INPUT, GPIO_DDC_CONFIG_TYPE_MODE_I2C)) {
359 dal_gpio_destroy_ddc(&ddc);
364 /* Read GPIO: DP sink is present if both clock and data pins are zero */
365 /* [anaumov] in DAL2, there was no check for GPIO failure */
367 gpio_result = dal_gpio_get_value(ddc->pin_clock, &clock_pin);
368 ASSERT(gpio_result == GPIO_RESULT_OK);
370 present = (gpio_result == GPIO_RESULT_OK) && !clock_pin;
379 * Detect output sink type
381 static enum signal_type link_detect_sink(
382 struct dc_link *link,
383 enum dc_detect_reason reason)
385 enum signal_type result = get_basic_signal_type(
386 link->link_enc->id, link->link_id);
388 /* Internal digital encoder will detect only dongles
389 * that require digital signal */
391 /* Detection mechanism is different
392 * for different native connectors.
393 * LVDS connector supports only LVDS signal;
394 * PCIE is a bus slot, the actual connector needs to be detected first;
395 * eDP connector supports only eDP signal;
396 * HDMI should check straps for audio */
398 /* PCIE detects the actual connector on add-on board */
400 if (link->link_id.id == CONNECTOR_ID_PCIE) {
401 /* ZAZTODO implement PCIE add-on card detection */
404 switch (link->link_id.id) {
405 case CONNECTOR_ID_HDMI_TYPE_A: {
406 /* check audio support:
407 * if native HDMI is not supported, switch to DVI */
408 struct audio_support *aud_support = &link->dc->res_pool->audio_support;
410 if (!aud_support->hdmi_audio_native)
411 if (link->link_id.id == CONNECTOR_ID_HDMI_TYPE_A)
412 result = SIGNAL_TYPE_DVI_SINGLE_LINK;
415 case CONNECTOR_ID_DISPLAY_PORT: {
416 /* DP HPD short pulse. Passive DP dongle will not
419 if (reason != DETECT_REASON_HPDRX) {
420 /* Check whether DP signal detected: if not -
421 * we assume signal is DVI; it could be corrected
422 * to HDMI after dongle detection
424 if (!dm_helpers_is_dp_sink_present(link))
425 result = SIGNAL_TYPE_DVI_SINGLE_LINK;
436 static enum signal_type decide_signal_from_strap_and_dongle_type(
437 enum display_dongle_type dongle_type,
438 struct audio_support *audio_support)
440 enum signal_type signal = SIGNAL_TYPE_NONE;
442 switch (dongle_type) {
443 case DISPLAY_DONGLE_DP_HDMI_DONGLE:
444 if (audio_support->hdmi_audio_on_dongle)
445 signal = SIGNAL_TYPE_HDMI_TYPE_A;
447 signal = SIGNAL_TYPE_DVI_SINGLE_LINK;
449 case DISPLAY_DONGLE_DP_DVI_DONGLE:
450 signal = SIGNAL_TYPE_DVI_SINGLE_LINK;
452 case DISPLAY_DONGLE_DP_HDMI_MISMATCHED_DONGLE:
453 if (audio_support->hdmi_audio_native)
454 signal = SIGNAL_TYPE_HDMI_TYPE_A;
456 signal = SIGNAL_TYPE_DVI_SINGLE_LINK;
459 signal = SIGNAL_TYPE_NONE;
466 static enum signal_type dp_passive_dongle_detection(
467 struct ddc_service *ddc,
468 struct display_sink_capability *sink_cap,
469 struct audio_support *audio_support)
471 dal_ddc_service_i2c_query_dp_dual_mode_adaptor(
473 return decide_signal_from_strap_and_dongle_type(
474 sink_cap->dongle_type,
478 static void link_disconnect_sink(struct dc_link *link)
480 if (link->local_sink) {
481 dc_sink_release(link->local_sink);
482 link->local_sink = NULL;
485 link->dpcd_sink_count = 0;
488 static void link_disconnect_remap(struct dc_sink *prev_sink, struct dc_link *link)
490 dc_sink_release(link->local_sink);
491 link->local_sink = prev_sink;
495 static bool detect_dp(
496 struct dc_link *link,
497 struct display_sink_capability *sink_caps,
498 bool *converter_disable_audio,
499 struct audio_support *audio_support,
500 enum dc_detect_reason reason)
503 sink_caps->signal = link_detect_sink(link, reason);
504 sink_caps->transaction_type =
505 get_ddc_transaction_type(sink_caps->signal);
507 if (sink_caps->transaction_type == DDC_TRANSACTION_TYPE_I2C_OVER_AUX) {
508 sink_caps->signal = SIGNAL_TYPE_DISPLAY_PORT;
509 if (!detect_dp_sink_caps(link))
512 if (is_mst_supported(link)) {
513 sink_caps->signal = SIGNAL_TYPE_DISPLAY_PORT_MST;
514 link->type = dc_connection_mst_branch;
516 dal_ddc_service_set_transaction_type(
518 sink_caps->transaction_type);
521 * This call will initiate MST topology discovery. Which
522 * will detect MST ports and add new DRM connector DRM
523 * framework. Then read EDID via remote i2c over aux. In
524 * the end, will notify DRM detect result and save EDID
525 * into DRM framework.
527 * .detect is called by .fill_modes.
528 * .fill_modes is called by user mode ioctl
529 * DRM_IOCTL_MODE_GETCONNECTOR.
531 * .get_modes is called by .fill_modes.
533 * call .get_modes, AMDGPU DM implementation will create
534 * new dc_sink and add to dc_link. For long HPD plug
535 * in/out, MST has its own handle.
537 * Therefore, just after dc_create, link->sink is not
538 * created for MST until user mode app calls
539 * DRM_IOCTL_MODE_GETCONNECTOR.
541 * Need check ->sink usages in case ->sink = NULL
542 * TODO: s3 resume check
544 if (reason == DETECT_REASON_BOOT)
547 dm_helpers_dp_update_branch_info(
551 if (!dm_helpers_dp_mst_start_top_mgr(
554 /* MST not supported */
555 link->type = dc_connection_single;
556 sink_caps->signal = SIGNAL_TYPE_DISPLAY_PORT;
560 if (link->type != dc_connection_mst_branch &&
561 is_dp_active_dongle(link)) {
562 /* DP active dongles */
563 link->type = dc_connection_active_dongle;
564 if (!link->dpcd_caps.sink_count.bits.SINK_COUNT) {
566 * active dongle unplug processing for short irq
568 link_disconnect_sink(link);
572 if (link->dpcd_caps.dongle_type != DISPLAY_DONGLE_DP_HDMI_CONVERTER)
573 *converter_disable_audio = true;
576 /* DP passive dongles */
577 sink_caps->signal = dp_passive_dongle_detection(link->ddc,
585 static bool is_same_edid(struct dc_edid *old_edid, struct dc_edid *new_edid)
587 if (old_edid->length != new_edid->length)
590 if (new_edid->length == 0)
593 return (memcmp(old_edid->raw_edid, new_edid->raw_edid, new_edid->length) == 0);
596 bool dc_link_detect(struct dc_link *link, enum dc_detect_reason reason)
598 struct dc_sink_init_data sink_init_data = { 0 };
599 struct display_sink_capability sink_caps = { 0 };
601 bool converter_disable_audio = false;
602 struct audio_support *aud_support = &link->dc->res_pool->audio_support;
603 bool same_edid = false;
604 enum dc_edid_status edid_status;
605 struct dc_context *dc_ctx = link->ctx;
606 struct dc_sink *sink = NULL;
607 struct dc_sink *prev_sink = NULL;
608 struct dpcd_caps prev_dpcd_caps;
609 bool same_dpcd = true;
610 enum dc_connection_type new_connection_type = dc_connection_none;
611 DC_LOGGER_INIT(link->ctx->logger);
612 if (link->connector_signal == SIGNAL_TYPE_VIRTUAL)
615 if (false == dc_link_detect_sink(link, &new_connection_type)) {
620 if (link->connector_signal == SIGNAL_TYPE_EDP &&
624 if (link->connector_signal == SIGNAL_TYPE_LVDS &&
628 prev_sink = link->local_sink;
629 if (prev_sink != NULL) {
630 dc_sink_retain(prev_sink);
631 memcpy(&prev_dpcd_caps, &link->dpcd_caps, sizeof(struct dpcd_caps));
633 link_disconnect_sink(link);
635 if (new_connection_type != dc_connection_none) {
636 link->type = new_connection_type;
638 /* From Disconnected-to-Connected. */
639 switch (link->connector_signal) {
640 case SIGNAL_TYPE_HDMI_TYPE_A: {
641 sink_caps.transaction_type = DDC_TRANSACTION_TYPE_I2C;
642 if (aud_support->hdmi_audio_native)
643 sink_caps.signal = SIGNAL_TYPE_HDMI_TYPE_A;
645 sink_caps.signal = SIGNAL_TYPE_DVI_SINGLE_LINK;
649 case SIGNAL_TYPE_DVI_SINGLE_LINK: {
650 sink_caps.transaction_type = DDC_TRANSACTION_TYPE_I2C;
651 sink_caps.signal = SIGNAL_TYPE_DVI_SINGLE_LINK;
655 case SIGNAL_TYPE_DVI_DUAL_LINK: {
656 sink_caps.transaction_type = DDC_TRANSACTION_TYPE_I2C;
657 sink_caps.signal = SIGNAL_TYPE_DVI_DUAL_LINK;
661 case SIGNAL_TYPE_LVDS: {
662 sink_caps.transaction_type = DDC_TRANSACTION_TYPE_I2C;
663 sink_caps.signal = SIGNAL_TYPE_LVDS;
667 case SIGNAL_TYPE_EDP: {
668 detect_edp_sink_caps(link);
669 sink_caps.transaction_type =
670 DDC_TRANSACTION_TYPE_I2C_OVER_AUX;
671 sink_caps.signal = SIGNAL_TYPE_EDP;
675 case SIGNAL_TYPE_DISPLAY_PORT: {
679 &converter_disable_audio,
680 aud_support, reason)) {
681 if (prev_sink != NULL)
682 dc_sink_release(prev_sink);
686 // Check if dpcp block is the same
687 if (prev_sink != NULL) {
688 if (memcmp(&link->dpcd_caps, &prev_dpcd_caps, sizeof(struct dpcd_caps)))
691 /* Active dongle downstream unplug */
692 if (link->type == dc_connection_active_dongle
693 && link->dpcd_caps.sink_count.
694 bits.SINK_COUNT == 0) {
695 if (prev_sink != NULL)
696 dc_sink_release(prev_sink);
700 if (link->type == dc_connection_mst_branch) {
701 LINK_INFO("link=%d, mst branch is now Connected\n",
703 /* Need to setup mst link_cap struct here
704 * otherwise dc_link_detect() will leave mst link_cap
705 * empty which leads to allocate_mst_payload() has "0"
706 * pbn_per_slot value leading to exception on dc_fixpt_div()
708 link->verified_link_cap = link->reported_link_cap;
709 if (prev_sink != NULL)
710 dc_sink_release(prev_sink);
718 DC_ERROR("Invalid connector type! signal:%d\n",
719 link->connector_signal);
720 if (prev_sink != NULL)
721 dc_sink_release(prev_sink);
725 if (link->dpcd_caps.sink_count.bits.SINK_COUNT)
726 link->dpcd_sink_count = link->dpcd_caps.sink_count.
729 link->dpcd_sink_count = 1;
731 dal_ddc_service_set_transaction_type(
733 sink_caps.transaction_type);
735 link->aux_mode = dal_ddc_service_is_in_aux_transaction_mode(
738 sink_init_data.link = link;
739 sink_init_data.sink_signal = sink_caps.signal;
741 sink = dc_sink_create(&sink_init_data);
743 DC_ERROR("Failed to create sink!\n");
744 if (prev_sink != NULL)
745 dc_sink_release(prev_sink);
749 sink->dongle_max_pix_clk = sink_caps.max_hdmi_pixel_clock;
750 sink->converter_disable_audio = converter_disable_audio;
752 link->local_sink = sink;
754 edid_status = dm_helpers_read_local_edid(
759 switch (edid_status) {
760 case EDID_BAD_CHECKSUM:
761 DC_LOG_ERROR("EDID checksum invalid.\n");
763 case EDID_NO_RESPONSE:
764 DC_LOG_ERROR("No EDID read.\n");
767 * Abort detection for non-DP connectors if we have
770 * DP needs to report as connected if HDP is high
771 * even if we have no EDID in order to go to
774 if (dc_is_hdmi_signal(link->connector_signal) ||
775 dc_is_dvi_signal(link->connector_signal)) {
776 if (prev_sink != NULL)
777 dc_sink_release(prev_sink);
785 // Check if edid is the same
786 if ((prev_sink != NULL) && ((edid_status == EDID_THE_SAME) || (edid_status == EDID_OK)))
787 same_edid = is_same_edid(&prev_sink->dc_edid, &sink->dc_edid);
789 if (link->connector_signal == SIGNAL_TYPE_DISPLAY_PORT &&
790 sink_caps.transaction_type == DDC_TRANSACTION_TYPE_I2C_OVER_AUX &&
791 reason != DETECT_REASON_HPDRX) {
793 * TODO debug why Dell 2413 doesn't like
797 /* deal with non-mst cases */
798 for (i = 0; i < LINK_TRAINING_MAX_VERIFY_RETRY; i++) {
801 dp_verify_link_cap(link,
802 &link->reported_link_cap,
810 // If edid is the same, then discard new sink and revert back to original sink
812 link_disconnect_remap(prev_sink, link);
819 /* HDMI-DVI Dongle */
820 if (sink->sink_signal == SIGNAL_TYPE_HDMI_TYPE_A &&
821 !sink->edid_caps.edid_hdmi)
822 sink->sink_signal = SIGNAL_TYPE_DVI_SINGLE_LINK;
824 /* Connectivity log: detection */
825 for (i = 0; i < sink->dc_edid.length / EDID_BLOCK_SIZE; i++) {
826 CONN_DATA_DETECT(link,
827 &sink->dc_edid.raw_edid[i * EDID_BLOCK_SIZE],
829 "%s: [Block %d] ", sink->edid_caps.display_name, i);
832 DC_LOG_DETECTION_EDID_PARSER("%s: "
833 "manufacturer_id = %X, "
835 "serial_number = %X, "
836 "manufacture_week = %d, "
837 "manufacture_year = %d, "
838 "display_name = %s, "
839 "speaker_flag = %d, "
840 "audio_mode_count = %d\n",
842 sink->edid_caps.manufacturer_id,
843 sink->edid_caps.product_id,
844 sink->edid_caps.serial_number,
845 sink->edid_caps.manufacture_week,
846 sink->edid_caps.manufacture_year,
847 sink->edid_caps.display_name,
848 sink->edid_caps.speaker_flags,
849 sink->edid_caps.audio_mode_count);
851 for (i = 0; i < sink->edid_caps.audio_mode_count; i++) {
852 DC_LOG_DETECTION_EDID_PARSER("%s: mode number = %d, "
854 "channel_count = %d, "
856 "sample_size = %d\n",
859 sink->edid_caps.audio_modes[i].format_code,
860 sink->edid_caps.audio_modes[i].channel_count,
861 sink->edid_caps.audio_modes[i].sample_rate,
862 sink->edid_caps.audio_modes[i].sample_size);
866 /* From Connected-to-Disconnected. */
867 if (link->type == dc_connection_mst_branch) {
868 LINK_INFO("link=%d, mst branch is now Disconnected\n",
871 dm_helpers_dp_mst_stop_top_mgr(link->ctx, link);
873 link->mst_stream_alloc_table.stream_count = 0;
874 memset(link->mst_stream_alloc_table.stream_allocations, 0, sizeof(link->mst_stream_alloc_table.stream_allocations));
877 link->type = dc_connection_none;
878 sink_caps.signal = SIGNAL_TYPE_NONE;
881 LINK_INFO("link=%d, dc_sink_in=%p is now %s prev_sink=%p dpcd same=%d edid same=%d\n",
882 link->link_index, sink,
883 (sink_caps.signal == SIGNAL_TYPE_NONE ?
884 "Disconnected":"Connected"), prev_sink,
885 same_dpcd, same_edid);
887 if (prev_sink != NULL)
888 dc_sink_release(prev_sink);
893 bool dc_link_get_hpd_state(struct dc_link *dc_link)
895 struct gpio *hpd_pin;
898 hpd_pin = get_hpd_gpio(dc_link->ctx->dc_bios,
899 dc_link->link_id, dc_link->ctx->gpio_service);
903 dal_gpio_open(hpd_pin, GPIO_MODE_INTERRUPT);
904 dal_gpio_get_value(hpd_pin, &state);
905 dal_gpio_close(hpd_pin);
906 dal_gpio_destroy_irq(&hpd_pin);
911 static enum hpd_source_id get_hpd_line(
912 struct dc_link *link)
915 enum hpd_source_id hpd_id = HPD_SOURCEID_UNKNOWN;
917 hpd = get_hpd_gpio(link->ctx->dc_bios, link->link_id, link->ctx->gpio_service);
920 switch (dal_irq_get_source(hpd)) {
921 case DC_IRQ_SOURCE_HPD1:
922 hpd_id = HPD_SOURCEID1;
924 case DC_IRQ_SOURCE_HPD2:
925 hpd_id = HPD_SOURCEID2;
927 case DC_IRQ_SOURCE_HPD3:
928 hpd_id = HPD_SOURCEID3;
930 case DC_IRQ_SOURCE_HPD4:
931 hpd_id = HPD_SOURCEID4;
933 case DC_IRQ_SOURCE_HPD5:
934 hpd_id = HPD_SOURCEID5;
936 case DC_IRQ_SOURCE_HPD6:
937 hpd_id = HPD_SOURCEID6;
944 dal_gpio_destroy_irq(&hpd);
950 static enum channel_id get_ddc_line(struct dc_link *link)
953 enum channel_id channel = CHANNEL_ID_UNKNOWN;
955 ddc = dal_ddc_service_get_ddc_pin(link->ddc);
958 switch (dal_ddc_get_line(ddc)) {
959 case GPIO_DDC_LINE_DDC1:
960 channel = CHANNEL_ID_DDC1;
962 case GPIO_DDC_LINE_DDC2:
963 channel = CHANNEL_ID_DDC2;
965 case GPIO_DDC_LINE_DDC3:
966 channel = CHANNEL_ID_DDC3;
968 case GPIO_DDC_LINE_DDC4:
969 channel = CHANNEL_ID_DDC4;
971 case GPIO_DDC_LINE_DDC5:
972 channel = CHANNEL_ID_DDC5;
974 case GPIO_DDC_LINE_DDC6:
975 channel = CHANNEL_ID_DDC6;
977 case GPIO_DDC_LINE_DDC_VGA:
978 channel = CHANNEL_ID_DDC_VGA;
980 case GPIO_DDC_LINE_I2C_PAD:
981 channel = CHANNEL_ID_I2C_PAD;
992 static enum transmitter translate_encoder_to_transmitter(
993 struct graphics_object_id encoder)
995 switch (encoder.id) {
996 case ENCODER_ID_INTERNAL_UNIPHY:
997 switch (encoder.enum_id) {
999 return TRANSMITTER_UNIPHY_A;
1001 return TRANSMITTER_UNIPHY_B;
1003 return TRANSMITTER_UNKNOWN;
1006 case ENCODER_ID_INTERNAL_UNIPHY1:
1007 switch (encoder.enum_id) {
1009 return TRANSMITTER_UNIPHY_C;
1011 return TRANSMITTER_UNIPHY_D;
1013 return TRANSMITTER_UNKNOWN;
1016 case ENCODER_ID_INTERNAL_UNIPHY2:
1017 switch (encoder.enum_id) {
1019 return TRANSMITTER_UNIPHY_E;
1021 return TRANSMITTER_UNIPHY_F;
1023 return TRANSMITTER_UNKNOWN;
1026 case ENCODER_ID_INTERNAL_UNIPHY3:
1027 switch (encoder.enum_id) {
1029 return TRANSMITTER_UNIPHY_G;
1031 return TRANSMITTER_UNKNOWN;
1034 case ENCODER_ID_EXTERNAL_NUTMEG:
1035 switch (encoder.enum_id) {
1037 return TRANSMITTER_NUTMEG_CRT;
1039 return TRANSMITTER_UNKNOWN;
1042 case ENCODER_ID_EXTERNAL_TRAVIS:
1043 switch (encoder.enum_id) {
1045 return TRANSMITTER_TRAVIS_CRT;
1047 return TRANSMITTER_TRAVIS_LCD;
1049 return TRANSMITTER_UNKNOWN;
1053 return TRANSMITTER_UNKNOWN;
1057 static bool construct(
1058 struct dc_link *link,
1059 const struct link_init_data *init_params)
1062 struct gpio *hpd_gpio = NULL;
1063 struct ddc_service_init_data ddc_service_init_data = { { 0 } };
1064 struct dc_context *dc_ctx = init_params->ctx;
1065 struct encoder_init_data enc_init_data = { 0 };
1066 struct integrated_info info = {{{ 0 }}};
1067 struct dc_bios *bios = init_params->dc->ctx->dc_bios;
1068 const struct dc_vbios_funcs *bp_funcs = bios->funcs;
1069 DC_LOGGER_INIT(dc_ctx->logger);
1071 link->irq_source_hpd = DC_IRQ_SOURCE_INVALID;
1072 link->irq_source_hpd_rx = DC_IRQ_SOURCE_INVALID;
1074 link->link_status.dpcd_caps = &link->dpcd_caps;
1076 link->dc = init_params->dc;
1078 link->link_index = init_params->link_index;
1080 link->link_id = bios->funcs->get_connector_id(bios, init_params->connector_index);
1082 if (link->link_id.type != OBJECT_TYPE_CONNECTOR) {
1083 dm_error("%s: Invalid Connector ObjectID from Adapter Service for connector index:%d! type %d expected %d\n",
1084 __func__, init_params->connector_index,
1085 link->link_id.type, OBJECT_TYPE_CONNECTOR);
1089 if (link->dc->res_pool->funcs->link_init)
1090 link->dc->res_pool->funcs->link_init(link);
1092 hpd_gpio = get_hpd_gpio(link->ctx->dc_bios, link->link_id, link->ctx->gpio_service);
1094 if (hpd_gpio != NULL)
1095 link->irq_source_hpd = dal_irq_get_source(hpd_gpio);
1097 switch (link->link_id.id) {
1098 case CONNECTOR_ID_HDMI_TYPE_A:
1099 link->connector_signal = SIGNAL_TYPE_HDMI_TYPE_A;
1102 case CONNECTOR_ID_SINGLE_LINK_DVID:
1103 case CONNECTOR_ID_SINGLE_LINK_DVII:
1104 link->connector_signal = SIGNAL_TYPE_DVI_SINGLE_LINK;
1106 case CONNECTOR_ID_DUAL_LINK_DVID:
1107 case CONNECTOR_ID_DUAL_LINK_DVII:
1108 link->connector_signal = SIGNAL_TYPE_DVI_DUAL_LINK;
1110 case CONNECTOR_ID_DISPLAY_PORT:
1111 link->connector_signal = SIGNAL_TYPE_DISPLAY_PORT;
1113 if (hpd_gpio != NULL)
1114 link->irq_source_hpd_rx =
1115 dal_irq_get_rx_source(hpd_gpio);
1118 case CONNECTOR_ID_EDP:
1119 link->connector_signal = SIGNAL_TYPE_EDP;
1121 if (hpd_gpio != NULL) {
1122 link->irq_source_hpd = DC_IRQ_SOURCE_INVALID;
1123 link->irq_source_hpd_rx =
1124 dal_irq_get_rx_source(hpd_gpio);
1127 case CONNECTOR_ID_LVDS:
1128 link->connector_signal = SIGNAL_TYPE_LVDS;
1131 DC_LOG_WARNING("Unsupported Connector type:%d!\n", link->link_id.id);
1135 if (hpd_gpio != NULL) {
1136 dal_gpio_destroy_irq(&hpd_gpio);
1140 /* TODO: #DAL3 Implement id to str function.*/
1141 LINK_INFO("Connector[%d] description:"
1143 init_params->connector_index,
1144 link->connector_signal);
1146 ddc_service_init_data.ctx = link->ctx;
1147 ddc_service_init_data.id = link->link_id;
1148 ddc_service_init_data.link = link;
1149 link->ddc = dal_ddc_service_create(&ddc_service_init_data);
1151 if (link->ddc == NULL) {
1152 DC_ERROR("Failed to create ddc_service!\n");
1153 goto ddc_create_fail;
1158 dal_ddc_service_get_ddc_pin(link->ddc));
1160 enc_init_data.ctx = dc_ctx;
1161 bp_funcs->get_src_obj(dc_ctx->dc_bios, link->link_id, 0, &enc_init_data.encoder);
1162 enc_init_data.connector = link->link_id;
1163 enc_init_data.channel = get_ddc_line(link);
1164 enc_init_data.hpd_source = get_hpd_line(link);
1166 link->hpd_src = enc_init_data.hpd_source;
1168 enc_init_data.transmitter =
1169 translate_encoder_to_transmitter(enc_init_data.encoder);
1170 link->link_enc = link->dc->res_pool->funcs->link_enc_create(
1173 if( link->link_enc == NULL) {
1174 DC_ERROR("Failed to create link encoder!\n");
1175 goto link_enc_create_fail;
1178 link->link_enc_hw_inst = link->link_enc->transmitter;
1180 for (i = 0; i < 4; i++) {
1182 bp_funcs->get_device_tag(dc_ctx->dc_bios, link->link_id, i, &link->device_tag)) {
1183 DC_ERROR("Failed to find device tag!\n");
1184 goto device_tag_fail;
1187 /* Look for device tag that matches connector signal,
1188 * CRT for rgb, LCD for other supported signal tyes
1190 if (!bp_funcs->is_device_id_supported(dc_ctx->dc_bios, link->device_tag.dev_id))
1192 if (link->device_tag.dev_id.device_type == DEVICE_TYPE_CRT
1193 && link->connector_signal != SIGNAL_TYPE_RGB)
1195 if (link->device_tag.dev_id.device_type == DEVICE_TYPE_LCD
1196 && link->connector_signal == SIGNAL_TYPE_RGB)
1201 if (bios->integrated_info)
1202 info = *bios->integrated_info;
1204 /* Look for channel mapping corresponding to connector and device tag */
1205 for (i = 0; i < MAX_NUMBER_OF_EXT_DISPLAY_PATH; i++) {
1206 struct external_display_path *path =
1207 &info.ext_disp_conn_info.path[i];
1208 if (path->device_connector_id.enum_id == link->link_id.enum_id
1209 && path->device_connector_id.id == link->link_id.id
1210 && path->device_connector_id.type == link->link_id.type) {
1212 if (link->device_tag.acpi_device != 0
1213 && path->device_acpi_enum == link->device_tag.acpi_device) {
1214 link->ddi_channel_mapping = path->channel_mapping;
1215 link->chip_caps = path->caps;
1216 } else if (path->device_tag ==
1217 link->device_tag.dev_id.raw_device_tag) {
1218 link->ddi_channel_mapping = path->channel_mapping;
1219 link->chip_caps = path->caps;
1226 * TODO check if GPIO programmed correctly
1228 * If GPIO isn't programmed correctly HPD might not rise or drain
1229 * fast enough, leading to bounces.
1231 program_hpd_filter(link);
1235 link->link_enc->funcs->destroy(&link->link_enc);
1236 link_enc_create_fail:
1237 dal_ddc_service_destroy(&link->ddc);
1241 if (hpd_gpio != NULL) {
1242 dal_gpio_destroy_irq(&hpd_gpio);
1248 /*******************************************************************************
1250 ******************************************************************************/
1251 struct dc_link *link_create(const struct link_init_data *init_params)
1253 struct dc_link *link =
1254 kzalloc(sizeof(*link), GFP_KERNEL);
1259 if (false == construct(link, init_params))
1260 goto construct_fail;
1271 void link_destroy(struct dc_link **link)
1278 static void dpcd_configure_panel_mode(
1279 struct dc_link *link,
1280 enum dp_panel_mode panel_mode)
1282 union dpcd_edp_config edp_config_set;
1283 bool panel_mode_edp = false;
1284 DC_LOGGER_INIT(link->ctx->logger);
1286 memset(&edp_config_set, '\0', sizeof(union dpcd_edp_config));
1288 if (DP_PANEL_MODE_DEFAULT != panel_mode) {
1290 switch (panel_mode) {
1291 case DP_PANEL_MODE_EDP:
1292 case DP_PANEL_MODE_SPECIAL:
1293 panel_mode_edp = true;
1300 /*set edp panel mode in receiver*/
1301 core_link_read_dpcd(
1303 DP_EDP_CONFIGURATION_SET,
1304 &edp_config_set.raw,
1305 sizeof(edp_config_set.raw));
1307 if (edp_config_set.bits.PANEL_MODE_EDP
1308 != panel_mode_edp) {
1309 enum ddc_result result = DDC_RESULT_UNKNOWN;
1311 edp_config_set.bits.PANEL_MODE_EDP =
1313 result = core_link_write_dpcd(
1315 DP_EDP_CONFIGURATION_SET,
1316 &edp_config_set.raw,
1317 sizeof(edp_config_set.raw));
1319 ASSERT(result == DDC_RESULT_SUCESSFULL);
1322 DC_LOG_DETECTION_DP_CAPS("Link: %d eDP panel mode supported: %d "
1323 "eDP panel mode enabled: %d \n",
1325 link->dpcd_caps.panel_mode_edp,
1329 static void enable_stream_features(struct pipe_ctx *pipe_ctx)
1331 struct dc_stream_state *stream = pipe_ctx->stream;
1332 struct dc_link *link = stream->sink->link;
1333 union down_spread_ctrl old_downspread;
1334 union down_spread_ctrl new_downspread;
1336 core_link_read_dpcd(link, DP_DOWNSPREAD_CTRL,
1337 &old_downspread.raw, sizeof(old_downspread));
1339 new_downspread.raw = old_downspread.raw;
1341 new_downspread.bits.IGNORE_MSA_TIMING_PARAM =
1342 (stream->ignore_msa_timing_param) ? 1 : 0;
1344 if (new_downspread.raw != old_downspread.raw) {
1345 core_link_write_dpcd(link, DP_DOWNSPREAD_CTRL,
1346 &new_downspread.raw, sizeof(new_downspread));
1350 static enum dc_status enable_link_dp(
1351 struct dc_state *state,
1352 struct pipe_ctx *pipe_ctx)
1354 struct dc_stream_state *stream = pipe_ctx->stream;
1355 enum dc_status status;
1356 bool skip_video_pattern;
1357 struct dc_link *link = stream->sink->link;
1358 struct dc_link_settings link_settings = {0};
1359 enum dp_panel_mode panel_mode;
1360 enum dc_link_rate max_link_rate = LINK_RATE_HIGH2;
1362 /* get link settings for video mode timing */
1363 decide_link_settings(stream, &link_settings);
1365 /* raise clock state for HBR3 if required. Confirmed with HW DCE/DPCS
1366 * logic for HBR3 still needs Nominal (0.8V) on VDDC rail
1368 if (link->link_enc->features.flags.bits.IS_HBR3_CAPABLE)
1369 max_link_rate = LINK_RATE_HIGH3;
1371 if (link_settings.link_rate == max_link_rate) {
1372 struct dc_clocks clocks = state->bw.dcn.clk;
1374 /* dce/dcn compat, do not update dispclk */
1375 clocks.dispclk_khz = 0;
1376 /* 27mhz = 27000000hz= 27000khz */
1377 clocks.phyclk_khz = link_settings.link_rate * 27000;
1379 state->dis_clk->funcs->update_clocks(
1380 state->dis_clk, &clocks, false);
1385 pipe_ctx->stream->signal,
1386 pipe_ctx->clock_source->id,
1389 if (stream->sink->edid_caps.panel_patch.dppowerup_delay > 0) {
1390 int delay_dp_power_up_in_ms = stream->sink->edid_caps.panel_patch.dppowerup_delay;
1392 msleep(delay_dp_power_up_in_ms);
1395 panel_mode = dp_get_panel_mode(link);
1396 dpcd_configure_panel_mode(link, panel_mode);
1398 skip_video_pattern = true;
1400 if (link_settings.link_rate == LINK_RATE_LOW)
1401 skip_video_pattern = false;
1403 if (perform_link_training_with_retries(
1407 LINK_TRAINING_ATTEMPTS)) {
1408 link->cur_link_settings = link_settings;
1412 status = DC_FAIL_DP_LINK_TRAINING;
1414 enable_stream_features(pipe_ctx);
1419 static enum dc_status enable_link_edp(
1420 struct dc_state *state,
1421 struct pipe_ctx *pipe_ctx)
1423 enum dc_status status;
1424 struct dc_stream_state *stream = pipe_ctx->stream;
1425 struct dc_link *link = stream->sink->link;
1426 /*in case it is not on*/
1427 link->dc->hwss.edp_power_control(link, true);
1428 link->dc->hwss.edp_wait_for_hpd_ready(link, true);
1430 status = enable_link_dp(state, pipe_ctx);
1436 static enum dc_status enable_link_dp_mst(
1437 struct dc_state *state,
1438 struct pipe_ctx *pipe_ctx)
1440 struct dc_link *link = pipe_ctx->stream->sink->link;
1442 /* sink signal type after MST branch is MST. Multiple MST sinks
1443 * share one link. Link DP PHY is enable or training only once.
1445 if (link->cur_link_settings.lane_count != LANE_COUNT_UNKNOWN)
1448 /* clear payload table */
1449 dm_helpers_dp_mst_clear_payload_allocation_table(link->ctx, link);
1451 /* set the sink to MST mode before enabling the link */
1452 dp_enable_mst_on_sink(link, true);
1454 return enable_link_dp(state, pipe_ctx);
1457 static bool get_ext_hdmi_settings(struct pipe_ctx *pipe_ctx,
1458 enum engine_id eng_id,
1459 struct ext_hdmi_settings *settings)
1461 bool result = false;
1463 struct integrated_info *integrated_info =
1464 pipe_ctx->stream->ctx->dc_bios->integrated_info;
1466 if (integrated_info == NULL)
1470 * Get retimer settings from sbios for passing SI eye test for DCE11
1471 * The setting values are varied based on board revision and port id
1472 * Therefore the setting values of each ports is passed by sbios.
1475 // Check if current bios contains ext Hdmi settings
1476 if (integrated_info->gpu_cap_info & 0x20) {
1478 case ENGINE_ID_DIGA:
1479 settings->slv_addr = integrated_info->dp0_ext_hdmi_slv_addr;
1480 settings->reg_num = integrated_info->dp0_ext_hdmi_6g_reg_num;
1481 settings->reg_num_6g = integrated_info->dp0_ext_hdmi_6g_reg_num;
1482 memmove(settings->reg_settings,
1483 integrated_info->dp0_ext_hdmi_reg_settings,
1484 sizeof(integrated_info->dp0_ext_hdmi_reg_settings));
1485 memmove(settings->reg_settings_6g,
1486 integrated_info->dp0_ext_hdmi_6g_reg_settings,
1487 sizeof(integrated_info->dp0_ext_hdmi_6g_reg_settings));
1490 case ENGINE_ID_DIGB:
1491 settings->slv_addr = integrated_info->dp1_ext_hdmi_slv_addr;
1492 settings->reg_num = integrated_info->dp1_ext_hdmi_6g_reg_num;
1493 settings->reg_num_6g = integrated_info->dp1_ext_hdmi_6g_reg_num;
1494 memmove(settings->reg_settings,
1495 integrated_info->dp1_ext_hdmi_reg_settings,
1496 sizeof(integrated_info->dp1_ext_hdmi_reg_settings));
1497 memmove(settings->reg_settings_6g,
1498 integrated_info->dp1_ext_hdmi_6g_reg_settings,
1499 sizeof(integrated_info->dp1_ext_hdmi_6g_reg_settings));
1502 case ENGINE_ID_DIGC:
1503 settings->slv_addr = integrated_info->dp2_ext_hdmi_slv_addr;
1504 settings->reg_num = integrated_info->dp2_ext_hdmi_6g_reg_num;
1505 settings->reg_num_6g = integrated_info->dp2_ext_hdmi_6g_reg_num;
1506 memmove(settings->reg_settings,
1507 integrated_info->dp2_ext_hdmi_reg_settings,
1508 sizeof(integrated_info->dp2_ext_hdmi_reg_settings));
1509 memmove(settings->reg_settings_6g,
1510 integrated_info->dp2_ext_hdmi_6g_reg_settings,
1511 sizeof(integrated_info->dp2_ext_hdmi_6g_reg_settings));
1514 case ENGINE_ID_DIGD:
1515 settings->slv_addr = integrated_info->dp3_ext_hdmi_slv_addr;
1516 settings->reg_num = integrated_info->dp3_ext_hdmi_6g_reg_num;
1517 settings->reg_num_6g = integrated_info->dp3_ext_hdmi_6g_reg_num;
1518 memmove(settings->reg_settings,
1519 integrated_info->dp3_ext_hdmi_reg_settings,
1520 sizeof(integrated_info->dp3_ext_hdmi_reg_settings));
1521 memmove(settings->reg_settings_6g,
1522 integrated_info->dp3_ext_hdmi_6g_reg_settings,
1523 sizeof(integrated_info->dp3_ext_hdmi_6g_reg_settings));
1530 if (result == true) {
1531 // Validate settings from bios integrated info table
1532 if (settings->slv_addr == 0)
1534 if (settings->reg_num > 9)
1536 if (settings->reg_num_6g > 3)
1539 for (i = 0; i < settings->reg_num; i++) {
1540 if (settings->reg_settings[i].i2c_reg_index > 0x20)
1544 for (i = 0; i < settings->reg_num_6g; i++) {
1545 if (settings->reg_settings_6g[i].i2c_reg_index > 0x20)
1554 static bool i2c_write(struct pipe_ctx *pipe_ctx,
1555 uint8_t address, uint8_t *buffer, uint32_t length)
1557 struct i2c_command cmd = {0};
1558 struct i2c_payload payload = {0};
1560 memset(&payload, 0, sizeof(payload));
1561 memset(&cmd, 0, sizeof(cmd));
1563 cmd.number_of_payloads = 1;
1564 cmd.engine = I2C_COMMAND_ENGINE_DEFAULT;
1565 cmd.speed = pipe_ctx->stream->ctx->dc->caps.i2c_speed_in_khz;
1567 payload.address = address;
1568 payload.data = buffer;
1569 payload.length = length;
1570 payload.write = true;
1571 cmd.payloads = &payload;
1573 if (dm_helpers_submit_i2c(pipe_ctx->stream->ctx,
1574 pipe_ctx->stream->sink->link, &cmd))
1580 static void write_i2c_retimer_setting(
1581 struct pipe_ctx *pipe_ctx,
1583 bool is_over_340mhz,
1584 struct ext_hdmi_settings *settings)
1586 uint8_t slave_address = (settings->slv_addr >> 1);
1588 const uint8_t apply_rx_tx_change = 0x4;
1589 uint8_t offset = 0xA;
1592 bool i2c_success = false;
1593 DC_LOGGER_INIT(pipe_ctx->stream->ctx->logger);
1595 memset(&buffer, 0, sizeof(buffer));
1597 /* Start Ext-Hdmi programming*/
1599 for (i = 0; i < settings->reg_num; i++) {
1600 /* Apply 3G settings */
1601 if (settings->reg_settings[i].i2c_reg_index <= 0x20) {
1603 buffer[0] = settings->reg_settings[i].i2c_reg_index;
1604 buffer[1] = settings->reg_settings[i].i2c_reg_val;
1605 i2c_success = i2c_write(pipe_ctx, slave_address,
1606 buffer, sizeof(buffer));
1607 RETIMER_REDRIVER_INFO("retimer write to slave_address = 0x%x,\
1608 offset = 0x%x, reg_val= 0x%x, i2c_success = %d\n",
1609 slave_address, buffer[0], buffer[1], i2c_success?1:0);
1613 ASSERT(i2c_success);
1615 /* Based on DP159 specs, APPLY_RX_TX_CHANGE bit in 0x0A
1616 * needs to be set to 1 on every 0xA-0xC write.
1618 if (settings->reg_settings[i].i2c_reg_index == 0xA ||
1619 settings->reg_settings[i].i2c_reg_index == 0xB ||
1620 settings->reg_settings[i].i2c_reg_index == 0xC) {
1622 /* Query current value from offset 0xA */
1623 if (settings->reg_settings[i].i2c_reg_index == 0xA)
1624 value = settings->reg_settings[i].i2c_reg_val;
1627 dal_ddc_service_query_ddc_data(
1628 pipe_ctx->stream->sink->link->ddc,
1629 slave_address, &offset, 1, &value, 1);
1632 ASSERT(i2c_success);
1636 /* Set APPLY_RX_TX_CHANGE bit to 1 */
1637 buffer[1] = value | apply_rx_tx_change;
1638 i2c_success = i2c_write(pipe_ctx, slave_address,
1639 buffer, sizeof(buffer));
1640 RETIMER_REDRIVER_INFO("retimer write to slave_address = 0x%x,\
1641 offset = 0x%x, reg_val = 0x%x, i2c_success = %d\n",
1642 slave_address, buffer[0], buffer[1], i2c_success?1:0);
1645 ASSERT(i2c_success);
1650 /* Apply 3G settings */
1651 if (is_over_340mhz) {
1652 for (i = 0; i < settings->reg_num_6g; i++) {
1653 /* Apply 3G settings */
1654 if (settings->reg_settings[i].i2c_reg_index <= 0x20) {
1656 buffer[0] = settings->reg_settings_6g[i].i2c_reg_index;
1657 buffer[1] = settings->reg_settings_6g[i].i2c_reg_val;
1658 i2c_success = i2c_write(pipe_ctx, slave_address,
1659 buffer, sizeof(buffer));
1660 RETIMER_REDRIVER_INFO("above 340Mhz: retimer write to slave_address = 0x%x,\
1661 offset = 0x%x, reg_val = 0x%x, i2c_success = %d\n",
1662 slave_address, buffer[0], buffer[1], i2c_success?1:0);
1666 ASSERT(i2c_success);
1668 /* Based on DP159 specs, APPLY_RX_TX_CHANGE bit in 0x0A
1669 * needs to be set to 1 on every 0xA-0xC write.
1671 if (settings->reg_settings_6g[i].i2c_reg_index == 0xA ||
1672 settings->reg_settings_6g[i].i2c_reg_index == 0xB ||
1673 settings->reg_settings_6g[i].i2c_reg_index == 0xC) {
1675 /* Query current value from offset 0xA */
1676 if (settings->reg_settings_6g[i].i2c_reg_index == 0xA)
1677 value = settings->reg_settings_6g[i].i2c_reg_val;
1680 dal_ddc_service_query_ddc_data(
1681 pipe_ctx->stream->sink->link->ddc,
1682 slave_address, &offset, 1, &value, 1);
1685 ASSERT(i2c_success);
1689 /* Set APPLY_RX_TX_CHANGE bit to 1 */
1690 buffer[1] = value | apply_rx_tx_change;
1691 i2c_success = i2c_write(pipe_ctx, slave_address,
1692 buffer, sizeof(buffer));
1693 RETIMER_REDRIVER_INFO("retimer write to slave_address = 0x%x,\
1694 offset = 0x%x, reg_val = 0x%x, i2c_success = %d\n",
1695 slave_address, buffer[0], buffer[1], i2c_success?1:0);
1698 ASSERT(i2c_success);
1705 /* Program additional settings if using 640x480 resolution */
1707 /* Write offset 0xFF to 0x01 */
1710 i2c_success = i2c_write(pipe_ctx, slave_address,
1711 buffer, sizeof(buffer));
1712 RETIMER_REDRIVER_INFO("retimer write to slave_address = 0x%x,\
1713 offset = 0x%x, reg_val = 0x%x, i2c_success = %d\n",
1714 slave_address, buffer[0], buffer[1], i2c_success?1:0);
1717 ASSERT(i2c_success);
1719 /* Write offset 0x00 to 0x23 */
1722 i2c_success = i2c_write(pipe_ctx, slave_address,
1723 buffer, sizeof(buffer));
1724 RETIMER_REDRIVER_INFO("retimer write to slave_address = 0x%x,\
1725 offset = 0x%x, reg_val = 0x%x, i2c_success = %d\n",
1726 slave_address, buffer[0], buffer[1], i2c_success?1:0);
1729 ASSERT(i2c_success);
1731 /* Write offset 0xff to 0x00 */
1734 i2c_success = i2c_write(pipe_ctx, slave_address,
1735 buffer, sizeof(buffer));
1736 RETIMER_REDRIVER_INFO("retimer write to slave_address = 0x%x,\
1737 offset = 0x%x, reg_val = 0x%x, i2c_success = %d\n",
1738 slave_address, buffer[0], buffer[1], i2c_success?1:0);
1741 ASSERT(i2c_success);
1746 static void write_i2c_default_retimer_setting(
1747 struct pipe_ctx *pipe_ctx,
1749 bool is_over_340mhz)
1751 uint8_t slave_address = (0xBA >> 1);
1753 bool i2c_success = false;
1754 DC_LOGGER_INIT(pipe_ctx->stream->ctx->logger);
1756 memset(&buffer, 0, sizeof(buffer));
1758 /* Program Slave Address for tuning single integrity */
1759 /* Write offset 0x0A to 0x13 */
1762 i2c_success = i2c_write(pipe_ctx, slave_address,
1763 buffer, sizeof(buffer));
1764 RETIMER_REDRIVER_INFO("retimer writes default setting to slave_address = 0x%x,\
1765 offset = 0x%x, reg_val = 0x%x, i2c_success = %d\n",
1766 slave_address, buffer[0], buffer[1], i2c_success?1:0);
1769 ASSERT(i2c_success);
1771 /* Write offset 0x0A to 0x17 */
1774 i2c_success = i2c_write(pipe_ctx, slave_address,
1775 buffer, sizeof(buffer));
1776 RETIMER_REDRIVER_INFO("retimer write to slave_addr = 0x%x,\
1777 offset = 0x%x, reg_val = 0x%x, i2c_success = %d\n",
1778 slave_address, buffer[0], buffer[1], i2c_success?1:0);
1781 ASSERT(i2c_success);
1783 /* Write offset 0x0B to 0xDA or 0xD8 */
1785 buffer[1] = is_over_340mhz ? 0xDA : 0xD8;
1786 i2c_success = i2c_write(pipe_ctx, slave_address,
1787 buffer, sizeof(buffer));
1788 RETIMER_REDRIVER_INFO("retimer write to slave_addr = 0x%x,\
1789 offset = 0x%x, reg_val = 0x%x, i2c_success = %d\n",
1790 slave_address, buffer[0], buffer[1], i2c_success?1:0);
1793 ASSERT(i2c_success);
1795 /* Write offset 0x0A to 0x17 */
1798 i2c_success = i2c_write(pipe_ctx, slave_address,
1799 buffer, sizeof(buffer));
1800 RETIMER_REDRIVER_INFO("retimer write to slave_addr = 0x%x,\
1801 offset = 0x%x, reg_val= 0x%x, i2c_success = %d\n",
1802 slave_address, buffer[0], buffer[1], i2c_success?1:0);
1805 ASSERT(i2c_success);
1807 /* Write offset 0x0C to 0x1D or 0x91 */
1809 buffer[1] = is_over_340mhz ? 0x1D : 0x91;
1810 i2c_success = i2c_write(pipe_ctx, slave_address,
1811 buffer, sizeof(buffer));
1812 RETIMER_REDRIVER_INFO("retimer write to slave_addr = 0x%x,\
1813 offset = 0x%x, reg_val = 0x%x, i2c_success = %d\n",
1814 slave_address, buffer[0], buffer[1], i2c_success?1:0);
1817 ASSERT(i2c_success);
1819 /* Write offset 0x0A to 0x17 */
1822 i2c_success = i2c_write(pipe_ctx, slave_address,
1823 buffer, sizeof(buffer));
1824 RETIMER_REDRIVER_INFO("retimer write to slave_addr = 0x%x,\
1825 offset = 0x%x, reg_val = 0x%x, i2c_success = %d\n",
1826 slave_address, buffer[0], buffer[1], i2c_success?1:0);
1829 ASSERT(i2c_success);
1833 /* Program additional settings if using 640x480 resolution */
1835 /* Write offset 0xFF to 0x01 */
1838 i2c_success = i2c_write(pipe_ctx, slave_address,
1839 buffer, sizeof(buffer));
1840 RETIMER_REDRIVER_INFO("retimer write to slave_addr = 0x%x,\
1841 offset = 0x%x, reg_val = 0x%x, i2c_success = %d\n",
1842 slave_address, buffer[0], buffer[1], i2c_success?1:0);
1845 ASSERT(i2c_success);
1847 /* Write offset 0x00 to 0x23 */
1850 i2c_success = i2c_write(pipe_ctx, slave_address,
1851 buffer, sizeof(buffer));
1852 RETIMER_REDRIVER_INFO("retimer write to slave_addr = 0x%x,\
1853 offset = 0x%x, reg_val= 0x%x, i2c_success = %d\n",
1854 slave_address, buffer[0], buffer[1], i2c_success?1:0);
1857 ASSERT(i2c_success);
1859 /* Write offset 0xff to 0x00 */
1862 i2c_success = i2c_write(pipe_ctx, slave_address,
1863 buffer, sizeof(buffer));
1864 RETIMER_REDRIVER_INFO("retimer write default setting to slave_addr = 0x%x,\
1865 offset = 0x%x, reg_val= 0x%x, i2c_success = %d end here\n",
1866 slave_address, buffer[0], buffer[1], i2c_success?1:0);
1869 ASSERT(i2c_success);
1873 static void write_i2c_redriver_setting(
1874 struct pipe_ctx *pipe_ctx,
1875 bool is_over_340mhz)
1877 uint8_t slave_address = (0xF0 >> 1);
1879 bool i2c_success = false;
1880 DC_LOGGER_INIT(pipe_ctx->stream->ctx->logger);
1882 memset(&buffer, 0, sizeof(buffer));
1884 // Program Slave Address for tuning single integrity
1888 buffer[6] = is_over_340mhz ? 0x4E : 0x4A;
1890 i2c_success = i2c_write(pipe_ctx, slave_address,
1891 buffer, sizeof(buffer));
1892 RETIMER_REDRIVER_INFO("redriver write 0 to all 16 reg offset expect following:\n\
1893 \t slave_addr = 0x%x, offset[3] = 0x%x, offset[4] = 0x%x,\
1894 offset[5] = 0x%x,offset[6] is_over_340mhz = 0x%x,\
1895 i2c_success = %d\n",
1896 slave_address, buffer[3], buffer[4], buffer[5], buffer[6], i2c_success?1:0);
1900 ASSERT(i2c_success);
1903 static void enable_link_hdmi(struct pipe_ctx *pipe_ctx)
1905 struct dc_stream_state *stream = pipe_ctx->stream;
1906 struct dc_link *link = stream->sink->link;
1907 enum dc_color_depth display_color_depth;
1908 enum engine_id eng_id;
1909 struct ext_hdmi_settings settings = {0};
1910 bool is_over_340mhz = false;
1911 bool is_vga_mode = (stream->timing.h_addressable == 640)
1912 && (stream->timing.v_addressable == 480);
1914 if (stream->phy_pix_clk == 0)
1915 stream->phy_pix_clk = stream->timing.pix_clk_khz;
1916 if (stream->phy_pix_clk > 340000)
1917 is_over_340mhz = true;
1919 if (dc_is_hdmi_signal(pipe_ctx->stream->signal)) {
1920 unsigned short masked_chip_caps = pipe_ctx->stream->sink->link->chip_caps &
1921 EXT_DISPLAY_PATH_CAPS__EXT_CHIP_MASK;
1922 if (masked_chip_caps == EXT_DISPLAY_PATH_CAPS__HDMI20_TISN65DP159RSBT) {
1923 /* DP159, Retimer settings */
1924 eng_id = pipe_ctx->stream_res.stream_enc->id;
1926 if (get_ext_hdmi_settings(pipe_ctx, eng_id, &settings)) {
1927 write_i2c_retimer_setting(pipe_ctx,
1928 is_vga_mode, is_over_340mhz, &settings);
1930 write_i2c_default_retimer_setting(pipe_ctx,
1931 is_vga_mode, is_over_340mhz);
1933 } else if (masked_chip_caps == EXT_DISPLAY_PATH_CAPS__HDMI20_PI3EQX1204) {
1934 /* PI3EQX1204, Redriver settings */
1935 write_i2c_redriver_setting(pipe_ctx, is_over_340mhz);
1939 if (dc_is_hdmi_signal(pipe_ctx->stream->signal))
1940 dal_ddc_service_write_scdc_data(
1941 stream->sink->link->ddc,
1942 stream->phy_pix_clk,
1943 stream->timing.flags.LTE_340MCSC_SCRAMBLE);
1945 memset(&stream->sink->link->cur_link_settings, 0,
1946 sizeof(struct dc_link_settings));
1948 display_color_depth = stream->timing.display_color_depth;
1949 if (stream->timing.pixel_encoding == PIXEL_ENCODING_YCBCR422)
1950 display_color_depth = COLOR_DEPTH_888;
1952 link->link_enc->funcs->enable_tmds_output(
1954 pipe_ctx->clock_source->id,
1955 display_color_depth,
1956 pipe_ctx->stream->signal,
1957 stream->phy_pix_clk);
1959 if (pipe_ctx->stream->signal == SIGNAL_TYPE_HDMI_TYPE_A)
1960 dal_ddc_service_read_scdc_data(link->ddc);
1963 static void enable_link_lvds(struct pipe_ctx *pipe_ctx)
1965 struct dc_stream_state *stream = pipe_ctx->stream;
1966 struct dc_link *link = stream->sink->link;
1968 if (stream->phy_pix_clk == 0)
1969 stream->phy_pix_clk = stream->timing.pix_clk_khz;
1971 memset(&stream->sink->link->cur_link_settings, 0,
1972 sizeof(struct dc_link_settings));
1974 link->link_enc->funcs->enable_lvds_output(
1976 pipe_ctx->clock_source->id,
1977 stream->phy_pix_clk);
1981 /****************************enable_link***********************************/
1982 static enum dc_status enable_link(
1983 struct dc_state *state,
1984 struct pipe_ctx *pipe_ctx)
1986 enum dc_status status = DC_ERROR_UNEXPECTED;
1987 switch (pipe_ctx->stream->signal) {
1988 case SIGNAL_TYPE_DISPLAY_PORT:
1989 status = enable_link_dp(state, pipe_ctx);
1991 case SIGNAL_TYPE_EDP:
1992 status = enable_link_edp(state, pipe_ctx);
1994 case SIGNAL_TYPE_DISPLAY_PORT_MST:
1995 status = enable_link_dp_mst(state, pipe_ctx);
1998 case SIGNAL_TYPE_DVI_SINGLE_LINK:
1999 case SIGNAL_TYPE_DVI_DUAL_LINK:
2000 case SIGNAL_TYPE_HDMI_TYPE_A:
2001 enable_link_hdmi(pipe_ctx);
2004 case SIGNAL_TYPE_LVDS:
2005 enable_link_lvds(pipe_ctx);
2008 case SIGNAL_TYPE_VIRTUAL:
2018 static void disable_link(struct dc_link *link, enum signal_type signal)
2021 * TODO: implement call for dp_set_hw_test_pattern
2022 * it is needed for compliance testing
2025 /* here we need to specify that encoder output settings
2026 * need to be calculated as for the set mode,
2027 * it will lead to querying dynamic link capabilities
2028 * which should be done before enable output */
2030 if (dc_is_dp_signal(signal)) {
2032 if (dc_is_dp_sst_signal(signal))
2033 dp_disable_link_phy(link, signal);
2035 dp_disable_link_phy_mst(link, signal);
2037 link->link_enc->funcs->disable_output(link->link_enc, signal);
2040 static bool dp_active_dongle_validate_timing(
2041 const struct dc_crtc_timing *timing,
2042 const struct dpcd_caps *dpcd_caps)
2044 unsigned int required_pix_clk = timing->pix_clk_khz;
2045 const struct dc_dongle_caps *dongle_caps = &dpcd_caps->dongle_caps;
2047 switch (dpcd_caps->dongle_type) {
2048 case DISPLAY_DONGLE_DP_VGA_CONVERTER:
2049 case DISPLAY_DONGLE_DP_DVI_CONVERTER:
2050 case DISPLAY_DONGLE_DP_DVI_DONGLE:
2051 if (timing->pixel_encoding == PIXEL_ENCODING_RGB)
2059 if (dongle_caps->dongle_type != DISPLAY_DONGLE_DP_HDMI_CONVERTER ||
2060 dongle_caps->extendedCapValid == false)
2063 /* Check Pixel Encoding */
2064 switch (timing->pixel_encoding) {
2065 case PIXEL_ENCODING_RGB:
2066 case PIXEL_ENCODING_YCBCR444:
2068 case PIXEL_ENCODING_YCBCR422:
2069 if (!dongle_caps->is_dp_hdmi_ycbcr422_pass_through)
2072 case PIXEL_ENCODING_YCBCR420:
2073 if (!dongle_caps->is_dp_hdmi_ycbcr420_pass_through)
2077 /* Invalid Pixel Encoding*/
2082 /* Check Color Depth and Pixel Clock */
2083 if (timing->pixel_encoding == PIXEL_ENCODING_YCBCR420)
2084 required_pix_clk /= 2;
2085 else if (timing->pixel_encoding == PIXEL_ENCODING_YCBCR422)
2086 required_pix_clk = required_pix_clk * 2 / 3;
2088 switch (timing->display_color_depth) {
2089 case COLOR_DEPTH_666:
2090 case COLOR_DEPTH_888:
2091 /*888 and 666 should always be supported*/
2093 case COLOR_DEPTH_101010:
2094 if (dongle_caps->dp_hdmi_max_bpc < 10)
2096 required_pix_clk = required_pix_clk * 10 / 8;
2098 case COLOR_DEPTH_121212:
2099 if (dongle_caps->dp_hdmi_max_bpc < 12)
2101 required_pix_clk = required_pix_clk * 12 / 8;
2104 case COLOR_DEPTH_141414:
2105 case COLOR_DEPTH_161616:
2107 /* These color depths are currently not supported */
2111 if (required_pix_clk > dongle_caps->dp_hdmi_max_pixel_clk)
2117 enum dc_status dc_link_validate_mode_timing(
2118 const struct dc_stream_state *stream,
2119 struct dc_link *link,
2120 const struct dc_crtc_timing *timing)
2122 uint32_t max_pix_clk = stream->sink->dongle_max_pix_clk;
2123 struct dpcd_caps *dpcd_caps = &link->dpcd_caps;
2125 /* A hack to avoid failing any modes for EDID override feature on
2126 * topology change such as lower quality cable for DP or different dongle
2128 if (link->remote_sinks[0])
2131 /* Passive Dongle */
2132 if (0 != max_pix_clk && timing->pix_clk_khz > max_pix_clk)
2133 return DC_EXCEED_DONGLE_CAP;
2136 if (!dp_active_dongle_validate_timing(timing, dpcd_caps))
2137 return DC_EXCEED_DONGLE_CAP;
2139 switch (stream->signal) {
2140 case SIGNAL_TYPE_EDP:
2141 case SIGNAL_TYPE_DISPLAY_PORT:
2142 if (!dp_validate_mode_timing(
2145 return DC_NO_DP_LINK_BANDWIDTH;
2155 int dc_link_get_backlight_level(const struct dc_link *link)
2157 struct abm *abm = link->ctx->dc->res_pool->abm;
2159 if (abm == NULL || abm->funcs->get_current_backlight_8_bit == NULL)
2160 return DC_ERROR_UNEXPECTED;
2162 return (int) abm->funcs->get_current_backlight_8_bit(abm);
2165 bool dc_link_set_backlight_level(const struct dc_link *link, uint32_t level,
2166 uint32_t frame_ramp, const struct dc_stream_state *stream)
2168 struct dc *core_dc = link->ctx->dc;
2169 struct abm *abm = core_dc->res_pool->abm;
2170 struct dmcu *dmcu = core_dc->res_pool->dmcu;
2171 unsigned int controller_id = 0;
2172 bool use_smooth_brightness = true;
2174 DC_LOGGER_INIT(link->ctx->logger);
2176 if ((dmcu == NULL) ||
2178 (abm->funcs->set_backlight_level == NULL))
2182 if (stream->bl_pwm_level == EDP_BACKLIGHT_RAMP_DISABLE_LEVEL)
2185 ((struct dc_stream_state *)stream)->bl_pwm_level = level;
2188 use_smooth_brightness = dmcu->funcs->is_dmcu_initialized(dmcu);
2190 DC_LOG_BACKLIGHT("New Backlight level: %d (0x%X)\n", level, level);
2192 if (dc_is_embedded_signal(link->connector_signal)) {
2193 if (stream != NULL) {
2194 for (i = 0; i < MAX_PIPES; i++) {
2195 if (core_dc->current_state->res_ctx.
2198 /* DMCU -1 for all controller id values,
2202 core_dc->current_state->
2203 res_ctx.pipe_ctx[i].stream_res.tg->inst +
2207 abm->funcs->set_backlight_level(
2212 use_smooth_brightness);
2218 bool dc_link_set_abm_disable(const struct dc_link *link)
2220 struct dc *core_dc = link->ctx->dc;
2221 struct abm *abm = core_dc->res_pool->abm;
2223 if ((abm == NULL) || (abm->funcs->set_backlight_level == NULL))
2226 abm->funcs->set_abm_immediate_disable(abm);
2231 bool dc_link_set_psr_enable(const struct dc_link *link, bool enable, bool wait)
2233 struct dc *core_dc = link->ctx->dc;
2234 struct dmcu *dmcu = core_dc->res_pool->dmcu;
2236 if (dmcu != NULL && link->psr_enabled)
2237 dmcu->funcs->set_psr_enable(dmcu, enable, wait);
2242 const struct dc_link_status *dc_link_get_status(const struct dc_link *link)
2244 return &link->link_status;
2247 void core_link_resume(struct dc_link *link)
2249 if (link->connector_signal != SIGNAL_TYPE_VIRTUAL)
2250 program_hpd_filter(link);
2253 static struct fixed31_32 get_pbn_per_slot(struct dc_stream_state *stream)
2255 struct dc_link_settings *link_settings =
2256 &stream->sink->link->cur_link_settings;
2257 uint32_t link_rate_in_mbps =
2258 link_settings->link_rate * LINK_RATE_REF_FREQ_IN_MHZ;
2259 struct fixed31_32 mbps = dc_fixpt_from_int(
2260 link_rate_in_mbps * link_settings->lane_count);
2262 return dc_fixpt_div_int(mbps, 54);
2265 static int get_color_depth(enum dc_color_depth color_depth)
2267 switch (color_depth) {
2268 case COLOR_DEPTH_666: return 6;
2269 case COLOR_DEPTH_888: return 8;
2270 case COLOR_DEPTH_101010: return 10;
2271 case COLOR_DEPTH_121212: return 12;
2272 case COLOR_DEPTH_141414: return 14;
2273 case COLOR_DEPTH_161616: return 16;
2278 static struct fixed31_32 get_pbn_from_timing(struct pipe_ctx *pipe_ctx)
2282 struct fixed31_32 peak_kbps;
2284 uint32_t denominator;
2286 bpc = get_color_depth(pipe_ctx->stream_res.pix_clk_params.color_depth);
2287 kbps = pipe_ctx->stream_res.pix_clk_params.requested_pix_clk * bpc * 3;
2290 * margin 5300ppm + 300ppm ~ 0.6% as per spec, factor is 1.006
2291 * The unit of 54/64Mbytes/sec is an arbitrary unit chosen based on
2292 * common multiplier to render an integer PBN for all link rate/lane
2293 * counts combinations
2295 * peak_kbps *= (1006/1000)
2296 * peak_kbps *= (64/54)
2297 * peak_kbps *= 8 convert to bytes
2300 numerator = 64 * PEAK_FACTOR_X1000;
2301 denominator = 54 * 8 * 1000 * 1000;
2303 peak_kbps = dc_fixpt_from_fraction(kbps, denominator);
2308 static void update_mst_stream_alloc_table(
2309 struct dc_link *link,
2310 struct stream_encoder *stream_enc,
2311 const struct dp_mst_stream_allocation_table *proposed_table)
2313 struct link_mst_stream_allocation work_table[MAX_CONTROLLER_NUM] = {
2315 struct link_mst_stream_allocation *dc_alloc;
2320 /* if DRM proposed_table has more than one new payload */
2321 ASSERT(proposed_table->stream_count -
2322 link->mst_stream_alloc_table.stream_count < 2);
2324 /* copy proposed_table to link, add stream encoder */
2325 for (i = 0; i < proposed_table->stream_count; i++) {
2327 for (j = 0; j < link->mst_stream_alloc_table.stream_count; j++) {
2329 &link->mst_stream_alloc_table.stream_allocations[j];
2331 if (dc_alloc->vcp_id ==
2332 proposed_table->stream_allocations[i].vcp_id) {
2334 work_table[i] = *dc_alloc;
2335 break; /* exit j loop */
2340 if (j == link->mst_stream_alloc_table.stream_count) {
2341 work_table[i].vcp_id =
2342 proposed_table->stream_allocations[i].vcp_id;
2343 work_table[i].slot_count =
2344 proposed_table->stream_allocations[i].slot_count;
2345 work_table[i].stream_enc = stream_enc;
2349 /* update link->mst_stream_alloc_table with work_table */
2350 link->mst_stream_alloc_table.stream_count =
2351 proposed_table->stream_count;
2352 for (i = 0; i < MAX_CONTROLLER_NUM; i++)
2353 link->mst_stream_alloc_table.stream_allocations[i] =
2357 /* convert link_mst_stream_alloc_table to dm dp_mst_stream_alloc_table
2358 * because stream_encoder is not exposed to dm
2360 static enum dc_status allocate_mst_payload(struct pipe_ctx *pipe_ctx)
2362 struct dc_stream_state *stream = pipe_ctx->stream;
2363 struct dc_link *link = stream->sink->link;
2364 struct link_encoder *link_encoder = link->link_enc;
2365 struct stream_encoder *stream_encoder = pipe_ctx->stream_res.stream_enc;
2366 struct dp_mst_stream_allocation_table proposed_table = {0};
2367 struct fixed31_32 avg_time_slots_per_mtp;
2368 struct fixed31_32 pbn;
2369 struct fixed31_32 pbn_per_slot;
2371 DC_LOGGER_INIT(link->ctx->logger);
2373 /* enable_link_dp_mst already check link->enabled_stream_count
2374 * and stream is in link->stream[]. This is called during set mode,
2375 * stream_enc is available.
2378 /* get calculate VC payload for stream: stream_alloc */
2379 if (dm_helpers_dp_mst_write_payload_allocation_table(
2384 update_mst_stream_alloc_table(
2385 link, pipe_ctx->stream_res.stream_enc, &proposed_table);
2388 DC_LOG_WARNING("Failed to update"
2389 "MST allocation table for"
2391 pipe_ctx->pipe_idx);
2394 "stream_count: %d: \n ",
2396 link->mst_stream_alloc_table.stream_count);
2398 for (i = 0; i < MAX_CONTROLLER_NUM; i++) {
2399 DC_LOG_MST("stream_enc[%d]: %p "
2400 "stream[%d].vcp_id: %d "
2401 "stream[%d].slot_count: %d\n",
2403 (void *) link->mst_stream_alloc_table.stream_allocations[i].stream_enc,
2405 link->mst_stream_alloc_table.stream_allocations[i].vcp_id,
2407 link->mst_stream_alloc_table.stream_allocations[i].slot_count);
2410 ASSERT(proposed_table.stream_count > 0);
2412 /* program DP source TX for payload */
2413 link_encoder->funcs->update_mst_stream_allocation_table(
2415 &link->mst_stream_alloc_table);
2417 /* send down message */
2418 dm_helpers_dp_mst_poll_for_allocation_change_trigger(
2422 dm_helpers_dp_mst_send_payload_allocation(
2427 /* slot X.Y for only current stream */
2428 pbn_per_slot = get_pbn_per_slot(stream);
2429 pbn = get_pbn_from_timing(pipe_ctx);
2430 avg_time_slots_per_mtp = dc_fixpt_div(pbn, pbn_per_slot);
2432 stream_encoder->funcs->set_mst_bandwidth(
2434 avg_time_slots_per_mtp);
2440 static enum dc_status deallocate_mst_payload(struct pipe_ctx *pipe_ctx)
2442 struct dc_stream_state *stream = pipe_ctx->stream;
2443 struct dc_link *link = stream->sink->link;
2444 struct link_encoder *link_encoder = link->link_enc;
2445 struct stream_encoder *stream_encoder = pipe_ctx->stream_res.stream_enc;
2446 struct dp_mst_stream_allocation_table proposed_table = {0};
2447 struct fixed31_32 avg_time_slots_per_mtp = dc_fixpt_from_int(0);
2449 bool mst_mode = (link->type == dc_connection_mst_branch);
2450 DC_LOGGER_INIT(link->ctx->logger);
2452 /* deallocate_mst_payload is called before disable link. When mode or
2453 * disable/enable monitor, new stream is created which is not in link
2454 * stream[] yet. For this, payload is not allocated yet, so de-alloc
2455 * should not done. For new mode set, map_resources will get engine
2456 * for new stream, so stream_enc->id should be validated until here.
2460 stream_encoder->funcs->set_mst_bandwidth(
2462 avg_time_slots_per_mtp);
2464 /* TODO: which component is responsible for remove payload table? */
2466 if (dm_helpers_dp_mst_write_payload_allocation_table(
2472 update_mst_stream_alloc_table(
2473 link, pipe_ctx->stream_res.stream_enc, &proposed_table);
2476 DC_LOG_WARNING("Failed to update"
2477 "MST allocation table for"
2479 pipe_ctx->pipe_idx);
2484 "stream_count: %d: ",
2486 link->mst_stream_alloc_table.stream_count);
2488 for (i = 0; i < MAX_CONTROLLER_NUM; i++) {
2489 DC_LOG_MST("stream_enc[%d]: %p "
2490 "stream[%d].vcp_id: %d "
2491 "stream[%d].slot_count: %d\n",
2493 (void *) link->mst_stream_alloc_table.stream_allocations[i].stream_enc,
2495 link->mst_stream_alloc_table.stream_allocations[i].vcp_id,
2497 link->mst_stream_alloc_table.stream_allocations[i].slot_count);
2500 link_encoder->funcs->update_mst_stream_allocation_table(
2502 &link->mst_stream_alloc_table);
2505 dm_helpers_dp_mst_poll_for_allocation_change_trigger(
2509 dm_helpers_dp_mst_send_payload_allocation(
2518 void core_link_enable_stream(
2519 struct dc_state *state,
2520 struct pipe_ctx *pipe_ctx)
2522 struct dc *core_dc = pipe_ctx->stream->ctx->dc;
2523 struct dc_stream_state *stream = pipe_ctx->stream;
2524 enum dc_status status;
2525 DC_LOGGER_INIT(pipe_ctx->stream->ctx->logger);
2527 if (pipe_ctx->stream->signal != SIGNAL_TYPE_VIRTUAL) {
2528 stream->sink->link->link_enc->funcs->setup(
2529 stream->sink->link->link_enc,
2530 pipe_ctx->stream->signal);
2531 pipe_ctx->stream_res.stream_enc->funcs->setup_stereo_sync(
2532 pipe_ctx->stream_res.stream_enc,
2533 pipe_ctx->stream_res.tg->inst,
2534 stream->timing.timing_3d_format != TIMING_3D_FORMAT_NONE);
2537 if (dc_is_dp_signal(pipe_ctx->stream->signal))
2538 pipe_ctx->stream_res.stream_enc->funcs->dp_set_stream_attribute(
2539 pipe_ctx->stream_res.stream_enc,
2541 stream->output_color_space);
2543 if (dc_is_hdmi_signal(pipe_ctx->stream->signal))
2544 pipe_ctx->stream_res.stream_enc->funcs->hdmi_set_stream_attribute(
2545 pipe_ctx->stream_res.stream_enc,
2547 stream->phy_pix_clk,
2548 pipe_ctx->stream_res.audio != NULL);
2550 if (dc_is_dvi_signal(pipe_ctx->stream->signal))
2551 pipe_ctx->stream_res.stream_enc->funcs->dvi_set_stream_attribute(
2552 pipe_ctx->stream_res.stream_enc,
2554 (pipe_ctx->stream->signal == SIGNAL_TYPE_DVI_DUAL_LINK) ?
2557 if (dc_is_lvds_signal(pipe_ctx->stream->signal))
2558 pipe_ctx->stream_res.stream_enc->funcs->lvds_set_stream_attribute(
2559 pipe_ctx->stream_res.stream_enc,
2562 if (!IS_FPGA_MAXIMUS_DC(core_dc->ctx->dce_environment)) {
2563 resource_build_info_frame(pipe_ctx);
2564 core_dc->hwss.update_info_frame(pipe_ctx);
2566 /* eDP lit up by bios already, no need to enable again. */
2567 if (pipe_ctx->stream->signal == SIGNAL_TYPE_EDP &&
2568 pipe_ctx->stream->apply_edp_fast_boot_optimization) {
2569 pipe_ctx->stream->apply_edp_fast_boot_optimization = false;
2570 pipe_ctx->stream->dpms_off = false;
2574 if (pipe_ctx->stream->dpms_off)
2577 status = enable_link(state, pipe_ctx);
2579 if (status != DC_OK) {
2580 DC_LOG_WARNING("enabling link %u failed: %d\n",
2581 pipe_ctx->stream->sink->link->link_index,
2584 /* Abort stream enable *unless* the failure was due to
2585 * DP link training - some DP monitors will recover and
2586 * show the stream anyway. But MST displays can't proceed
2587 * without link training.
2589 if (status != DC_FAIL_DP_LINK_TRAINING ||
2590 pipe_ctx->stream->signal == SIGNAL_TYPE_DISPLAY_PORT_MST) {
2591 BREAK_TO_DEBUGGER();
2596 core_dc->hwss.enable_audio_stream(pipe_ctx);
2598 /* turn off otg test pattern if enable */
2599 if (pipe_ctx->stream_res.tg->funcs->set_test_pattern)
2600 pipe_ctx->stream_res.tg->funcs->set_test_pattern(pipe_ctx->stream_res.tg,
2601 CONTROLLER_DP_TEST_PATTERN_VIDEOMODE,
2602 COLOR_DEPTH_UNDEFINED);
2604 core_dc->hwss.enable_stream(pipe_ctx);
2606 if (pipe_ctx->stream->signal == SIGNAL_TYPE_DISPLAY_PORT_MST)
2607 allocate_mst_payload(pipe_ctx);
2609 core_dc->hwss.unblank_stream(pipe_ctx,
2610 &pipe_ctx->stream->sink->link->cur_link_settings);
2616 void core_link_disable_stream(struct pipe_ctx *pipe_ctx, int option)
2618 struct dc *core_dc = pipe_ctx->stream->ctx->dc;
2620 if (pipe_ctx->stream->signal == SIGNAL_TYPE_DISPLAY_PORT_MST)
2621 deallocate_mst_payload(pipe_ctx);
2623 core_dc->hwss.blank_stream(pipe_ctx);
2625 core_dc->hwss.disable_stream(pipe_ctx, option);
2627 disable_link(pipe_ctx->stream->sink->link, pipe_ctx->stream->signal);
2630 void core_link_set_avmute(struct pipe_ctx *pipe_ctx, bool enable)
2632 struct dc *core_dc = pipe_ctx->stream->ctx->dc;
2634 if (pipe_ctx->stream->signal != SIGNAL_TYPE_HDMI_TYPE_A)
2637 core_dc->hwss.set_avmute(pipe_ctx, enable);
2641 *****************************************************************************
2642 * Function: dc_link_enable_hpd_filter
2645 * If enable is true, programs HPD filter on associated HPD line using
2646 * delay_on_disconnect/delay_on_connect values dependent on
2647 * link->connector_signal
2649 * If enable is false, programs HPD filter on associated HPD line with no
2650 * delays on connect or disconnect
2652 * @param [in] link: pointer to the dc link
2653 * @param [in] enable: boolean specifying whether to enable hbd
2654 *****************************************************************************
2656 void dc_link_enable_hpd_filter(struct dc_link *link, bool enable)
2661 link->is_hpd_filter_disabled = false;
2662 program_hpd_filter(link);
2664 link->is_hpd_filter_disabled = true;
2665 /* Obtain HPD handle */
2666 hpd = get_hpd_gpio(link->ctx->dc_bios, link->link_id, link->ctx->gpio_service);
2671 /* Setup HPD filtering */
2672 if (dal_gpio_open(hpd, GPIO_MODE_INTERRUPT) == GPIO_RESULT_OK) {
2673 struct gpio_hpd_config config;
2675 config.delay_on_connect = 0;
2676 config.delay_on_disconnect = 0;
2678 dal_irq_setup_hpd_filter(hpd, &config);
2680 dal_gpio_close(hpd);
2682 ASSERT_CRITICAL(false);
2684 /* Release HPD handle */
2685 dal_gpio_destroy_irq(&hpd);