1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (c) 2011-2013, NVIDIA Corporation.
4 * Copyright 2014 Google Inc.
12 #include <video_bridge.h>
14 #include <asm/arch-tegra/dc.h>
18 #include "displayport.h"
20 #define DO_FAST_LINK_TRAINING 1
22 struct tegra_dp_plat {
27 * struct tegra_dp_priv - private displayport driver info
29 * @dc_dev: Display controller device that is sending the video feed
31 struct tegra_dp_priv {
33 struct udevice *dc_dev;
34 struct dpaux_ctlr *regs;
39 struct tegra_dp_priv dp_data;
41 static inline u32 tegra_dpaux_readl(struct tegra_dp_priv *dp, u32 reg)
43 return readl((u32 *)dp->regs + reg);
46 static inline void tegra_dpaux_writel(struct tegra_dp_priv *dp, u32 reg,
49 writel(val, (u32 *)dp->regs + reg);
52 static inline u32 tegra_dc_dpaux_poll_register(struct tegra_dp_priv *dp,
53 u32 reg, u32 mask, u32 exp_val,
58 u32 temp = timeout_us;
61 udelay(poll_interval_us);
62 reg_val = tegra_dpaux_readl(dp, reg);
63 if (timeout_us > poll_interval_us)
64 timeout_us -= poll_interval_us;
67 } while ((reg_val & mask) != exp_val);
69 if ((reg_val & mask) == exp_val)
70 return 0; /* success */
71 debug("dpaux_poll_register 0x%x: timeout: (reg_val)0x%08x & (mask)0x%08x != (exp_val)0x%08x\n",
72 reg, reg_val, mask, exp_val);
76 static inline int tegra_dpaux_wait_transaction(struct tegra_dp_priv *dp)
78 /* According to DP spec, each aux transaction needs to finish
80 if (tegra_dc_dpaux_poll_register(dp, DPAUX_DP_AUXCTL,
81 DPAUX_DP_AUXCTL_TRANSACTREQ_MASK,
82 DPAUX_DP_AUXCTL_TRANSACTREQ_DONE,
83 100, DP_AUX_TIMEOUT_MS * 1000) != 0) {
84 debug("dp: DPAUX transaction timeout\n");
90 static int tegra_dc_dpaux_write_chunk(struct tegra_dp_priv *dp, u32 cmd,
91 u32 addr, u8 *data, u32 *size,
96 u32 timeout_retries = DP_AUX_TIMEOUT_MAX_TRIES;
97 u32 defer_retries = DP_AUX_DEFER_MAX_TRIES;
100 if (*size > DP_AUX_MAX_BYTES)
101 return -1; /* only write one chunk of data */
103 /* Make sure the command is write command */
105 case DPAUX_DP_AUXCTL_CMD_I2CWR:
106 case DPAUX_DP_AUXCTL_CMD_MOTWR:
107 case DPAUX_DP_AUXCTL_CMD_AUXWR:
110 debug("dp: aux write cmd 0x%x is invalid\n", cmd);
114 tegra_dpaux_writel(dp, DPAUX_DP_AUXADDR, addr);
115 for (i = 0; i < DP_AUX_MAX_BYTES / 4; ++i) {
116 memcpy(&temp_data, data, 4);
117 tegra_dpaux_writel(dp, DPAUX_DP_AUXDATA_WRITE_W(i), temp_data);
121 reg_val = tegra_dpaux_readl(dp, DPAUX_DP_AUXCTL);
122 reg_val &= ~DPAUX_DP_AUXCTL_CMD_MASK;
124 reg_val &= ~DPAUX_DP_AUXCTL_CMDLEN_FIELD;
125 reg_val |= ((*size - 1) << DPAUX_DP_AUXCTL_CMDLEN_SHIFT);
127 while ((timeout_retries > 0) && (defer_retries > 0)) {
128 if ((timeout_retries != DP_AUX_TIMEOUT_MAX_TRIES) ||
129 (defer_retries != DP_AUX_DEFER_MAX_TRIES))
132 reg_val |= DPAUX_DP_AUXCTL_TRANSACTREQ_PENDING;
133 tegra_dpaux_writel(dp, DPAUX_DP_AUXCTL, reg_val);
135 if (tegra_dpaux_wait_transaction(dp))
136 debug("dp: aux write transaction timeout\n");
138 *aux_stat = tegra_dpaux_readl(dp, DPAUX_DP_AUXSTAT);
140 if ((*aux_stat & DPAUX_DP_AUXSTAT_TIMEOUT_ERROR_PENDING) ||
141 (*aux_stat & DPAUX_DP_AUXSTAT_RX_ERROR_PENDING) ||
142 (*aux_stat & DPAUX_DP_AUXSTAT_SINKSTAT_ERROR_PENDING) ||
143 (*aux_stat & DPAUX_DP_AUXSTAT_NO_STOP_ERROR_PENDING)) {
144 if (timeout_retries-- > 0) {
145 debug("dp: aux write retry (0x%x) -- %d\n",
146 *aux_stat, timeout_retries);
147 /* clear the error bits */
148 tegra_dpaux_writel(dp, DPAUX_DP_AUXSTAT,
152 debug("dp: aux write got error (0x%x)\n",
158 if ((*aux_stat & DPAUX_DP_AUXSTAT_REPLYTYPE_I2CDEFER) ||
159 (*aux_stat & DPAUX_DP_AUXSTAT_REPLYTYPE_DEFER)) {
160 if (defer_retries-- > 0) {
161 debug("dp: aux write defer (0x%x) -- %d\n",
162 *aux_stat, defer_retries);
163 /* clear the error bits */
164 tegra_dpaux_writel(dp, DPAUX_DP_AUXSTAT,
168 debug("dp: aux write defer exceeds max retries (0x%x)\n",
174 if ((*aux_stat & DPAUX_DP_AUXSTAT_REPLYTYPE_MASK) ==
175 DPAUX_DP_AUXSTAT_REPLYTYPE_ACK) {
176 *size = ((*aux_stat) & DPAUX_DP_AUXSTAT_REPLY_M_MASK);
179 debug("dp: aux write failed (0x%x)\n", *aux_stat);
183 /* Should never come to here */
187 static int tegra_dc_dpaux_read_chunk(struct tegra_dp_priv *dp, u32 cmd,
188 u32 addr, u8 *data, u32 *size,
192 u32 timeout_retries = DP_AUX_TIMEOUT_MAX_TRIES;
193 u32 defer_retries = DP_AUX_DEFER_MAX_TRIES;
195 if (*size > DP_AUX_MAX_BYTES) {
196 debug("only read one chunk\n");
197 return -EIO; /* only read one chunk */
200 /* Check to make sure the command is read command */
202 case DPAUX_DP_AUXCTL_CMD_I2CRD:
203 case DPAUX_DP_AUXCTL_CMD_I2CREQWSTAT:
204 case DPAUX_DP_AUXCTL_CMD_MOTRD:
205 case DPAUX_DP_AUXCTL_CMD_AUXRD:
208 debug("dp: aux read cmd 0x%x is invalid\n", cmd);
212 *aux_stat = tegra_dpaux_readl(dp, DPAUX_DP_AUXSTAT);
213 if (!(*aux_stat & DPAUX_DP_AUXSTAT_HPD_STATUS_PLUGGED)) {
214 debug("dp: HPD is not detected\n");
218 tegra_dpaux_writel(dp, DPAUX_DP_AUXADDR, addr);
220 reg_val = tegra_dpaux_readl(dp, DPAUX_DP_AUXCTL);
221 reg_val &= ~DPAUX_DP_AUXCTL_CMD_MASK;
223 reg_val &= ~DPAUX_DP_AUXCTL_CMDLEN_FIELD;
224 reg_val |= ((*size - 1) << DPAUX_DP_AUXCTL_CMDLEN_SHIFT);
225 while ((timeout_retries > 0) && (defer_retries > 0)) {
226 if ((timeout_retries != DP_AUX_TIMEOUT_MAX_TRIES) ||
227 (defer_retries != DP_AUX_DEFER_MAX_TRIES))
228 udelay(DP_DPCP_RETRY_SLEEP_NS * 2);
230 reg_val |= DPAUX_DP_AUXCTL_TRANSACTREQ_PENDING;
231 tegra_dpaux_writel(dp, DPAUX_DP_AUXCTL, reg_val);
233 if (tegra_dpaux_wait_transaction(dp))
234 debug("dp: aux read transaction timeout\n");
236 *aux_stat = tegra_dpaux_readl(dp, DPAUX_DP_AUXSTAT);
238 if ((*aux_stat & DPAUX_DP_AUXSTAT_TIMEOUT_ERROR_PENDING) ||
239 (*aux_stat & DPAUX_DP_AUXSTAT_RX_ERROR_PENDING) ||
240 (*aux_stat & DPAUX_DP_AUXSTAT_SINKSTAT_ERROR_PENDING) ||
241 (*aux_stat & DPAUX_DP_AUXSTAT_NO_STOP_ERROR_PENDING)) {
242 if (timeout_retries-- > 0) {
243 debug("dp: aux read retry (0x%x) -- %d\n",
244 *aux_stat, timeout_retries);
245 /* clear the error bits */
246 tegra_dpaux_writel(dp, DPAUX_DP_AUXSTAT,
248 continue; /* retry */
250 debug("dp: aux read got error (0x%x)\n",
256 if ((*aux_stat & DPAUX_DP_AUXSTAT_REPLYTYPE_I2CDEFER) ||
257 (*aux_stat & DPAUX_DP_AUXSTAT_REPLYTYPE_DEFER)) {
258 if (defer_retries-- > 0) {
259 debug("dp: aux read defer (0x%x) -- %d\n",
260 *aux_stat, defer_retries);
261 /* clear the error bits */
262 tegra_dpaux_writel(dp, DPAUX_DP_AUXSTAT,
266 debug("dp: aux read defer exceeds max retries (0x%x)\n",
272 if ((*aux_stat & DPAUX_DP_AUXSTAT_REPLYTYPE_MASK) ==
273 DPAUX_DP_AUXSTAT_REPLYTYPE_ACK) {
277 for (i = 0; i < DP_AUX_MAX_BYTES / 4; ++i)
278 temp_data[i] = tegra_dpaux_readl(dp,
279 DPAUX_DP_AUXDATA_READ_W(i));
281 *size = ((*aux_stat) & DPAUX_DP_AUXSTAT_REPLY_M_MASK);
282 memcpy(data, temp_data, *size);
286 debug("dp: aux read failed (0x%x\n", *aux_stat);
290 /* Should never come to here */
291 debug("%s: can't\n", __func__);
296 static int tegra_dc_dpaux_read(struct tegra_dp_priv *dp, u32 cmd, u32 addr,
297 u8 *data, u32 *size, u32 *aux_stat)
304 cur_size = *size - finished;
305 if (cur_size > DP_AUX_MAX_BYTES)
306 cur_size = DP_AUX_MAX_BYTES;
308 ret = tegra_dc_dpaux_read_chunk(dp, cmd, addr,
309 data, &cur_size, aux_stat);
313 /* cur_size should be the real size returned */
316 finished += cur_size;
318 } while (*size > finished);
324 static int tegra_dc_dp_dpcd_read(struct tegra_dp_priv *dp, u32 cmd,
331 ret = tegra_dc_dpaux_read_chunk(dp, DPAUX_DP_AUXCTL_CMD_AUXRD,
332 cmd, data_ptr, &size, &status);
334 debug("dp: Failed to read DPCD data. CMD 0x%x, Status 0x%x\n",
341 static int tegra_dc_dp_dpcd_write(struct tegra_dp_priv *dp, u32 cmd,
348 ret = tegra_dc_dpaux_write_chunk(dp, DPAUX_DP_AUXCTL_CMD_AUXWR,
349 cmd, &data, &size, &status);
351 debug("dp: Failed to write DPCD data. CMD 0x%x, Status 0x%x\n",
358 static int tegra_dc_i2c_aux_read(struct tegra_dp_priv *dp, u32 i2c_addr,
359 u8 addr, u8 *data, u32 size, u32 *aux_stat)
365 u32 cur_size = min((u32)DP_AUX_MAX_BYTES, size - finished);
368 ret = tegra_dc_dpaux_write_chunk(
369 dp, DPAUX_DP_AUXCTL_CMD_MOTWR, i2c_addr,
370 &addr, &len, aux_stat);
372 debug("%s: error sending address to read.\n",
377 ret = tegra_dc_dpaux_read_chunk(
378 dp, DPAUX_DP_AUXCTL_CMD_I2CRD, i2c_addr,
379 data, &cur_size, aux_stat);
381 debug("%s: error reading data.\n", __func__);
385 /* cur_size should be the real size returned */
388 finished += cur_size;
389 } while (size > finished);
394 static void tegra_dc_dpaux_enable(struct tegra_dp_priv *dp)
396 /* clear interrupt */
397 tegra_dpaux_writel(dp, DPAUX_INTR_AUX, 0xffffffff);
398 /* do not enable interrupt for now. Enable them when Isr in place */
399 tegra_dpaux_writel(dp, DPAUX_INTR_EN_AUX, 0x0);
401 tegra_dpaux_writel(dp, DPAUX_HYBRID_PADCTL,
402 DPAUX_HYBRID_PADCTL_AUX_DRVZ_OHM_50 |
403 DPAUX_HYBRID_PADCTL_AUX_CMH_V0_70 |
404 0x18 << DPAUX_HYBRID_PADCTL_AUX_DRVI_SHIFT |
405 DPAUX_HYBRID_PADCTL_AUX_INPUT_RCV_ENABLE);
407 tegra_dpaux_writel(dp, DPAUX_HYBRID_SPARE,
408 DPAUX_HYBRID_SPARE_PAD_PWR_POWERUP);
412 static void tegra_dc_dp_dump_link_cfg(struct tegra_dp_priv *dp,
413 const struct tegra_dp_link_config *link_cfg)
415 debug("DP config: cfg_name cfg_value\n");
416 debug(" Lane Count %d\n",
417 link_cfg->max_lane_count);
418 debug(" SupportEnhancedFraming %s\n",
419 link_cfg->support_enhanced_framing ? "Y" : "N");
420 debug(" Bandwidth %d\n",
421 link_cfg->max_link_bw);
423 link_cfg->bits_per_pixel);
424 debug(" EnhancedFraming %s\n",
425 link_cfg->enhanced_framing ? "Y" : "N");
426 debug(" Scramble_enabled %s\n",
427 link_cfg->scramble_ena ? "Y" : "N");
428 debug(" LinkBW %d\n",
430 debug(" lane_count %d\n",
431 link_cfg->lane_count);
432 debug(" activespolarity %d\n",
433 link_cfg->activepolarity);
434 debug(" active_count %d\n",
435 link_cfg->active_count);
436 debug(" tu_size %d\n",
438 debug(" active_frac %d\n",
439 link_cfg->active_frac);
440 debug(" watermark %d\n",
441 link_cfg->watermark);
442 debug(" hblank_sym %d\n",
443 link_cfg->hblank_sym);
444 debug(" vblank_sym %d\n",
445 link_cfg->vblank_sym);
449 static int _tegra_dp_lower_link_config(struct tegra_dp_priv *dp,
450 struct tegra_dp_link_config *cfg)
452 switch (cfg->link_bw) {
453 case SOR_LINK_SPEED_G1_62:
454 if (cfg->max_link_bw > SOR_LINK_SPEED_G1_62)
455 cfg->link_bw = SOR_LINK_SPEED_G2_7;
456 cfg->lane_count /= 2;
458 case SOR_LINK_SPEED_G2_7:
459 cfg->link_bw = SOR_LINK_SPEED_G1_62;
461 case SOR_LINK_SPEED_G5_4:
462 if (cfg->lane_count == 1) {
463 cfg->link_bw = SOR_LINK_SPEED_G2_7;
464 cfg->lane_count = cfg->max_lane_count;
466 cfg->lane_count /= 2;
470 debug("dp: Error link rate %d\n", cfg->link_bw);
474 return (cfg->lane_count > 0) ? 0 : -ENOLINK;
478 * Calcuate if given cfg can meet the mode request.
479 * Return 0 if mode is possible, -1 otherwise
481 static int tegra_dc_dp_calc_config(struct tegra_dp_priv *dp,
482 const struct display_timing *timing,
483 struct tegra_dp_link_config *link_cfg)
485 const u32 link_rate = 27 * link_cfg->link_bw * 1000 * 1000;
486 const u64 f = 100000; /* precision factor */
487 u32 num_linkclk_line; /* Number of link clocks per line */
488 u64 ratio_f; /* Ratio of incoming to outgoing data rate */
490 u64 activesym_f; /* Activesym per TU */
496 u64 accumulated_error_f = 0;
497 u32 lowest_neg_activecount = 0;
498 u32 lowest_neg_activepolarity = 0;
499 u32 lowest_neg_tusize = 64;
500 u32 num_symbols_per_line;
501 u64 lowest_neg_activefrac = 0;
502 u64 lowest_neg_error_f = 64 * f;
507 if (!link_rate || !link_cfg->lane_count || !timing->pixelclock.typ ||
508 !link_cfg->bits_per_pixel)
511 if ((u64)timing->pixelclock.typ * link_cfg->bits_per_pixel >=
512 (u64)link_rate * 8 * link_cfg->lane_count)
515 num_linkclk_line = (u32)(lldiv(link_rate * timing->hactive.typ,
516 timing->pixelclock.typ));
518 ratio_f = (u64)timing->pixelclock.typ * link_cfg->bits_per_pixel * f;
520 do_div(ratio_f, link_rate * link_cfg->lane_count);
522 for (i = 64; i >= 32; --i) {
523 activesym_f = ratio_f * i;
524 activecount_f = lldiv(activesym_f, (u32)f) * f;
525 frac_f = activesym_f - activecount_f;
526 activecount = (u32)(lldiv(activecount_f, (u32)f));
528 if (frac_f < (lldiv(f, 2))) /* fraction < 0.5 */
536 /* warning: frac_f should be 64-bit */
537 frac_f = lldiv(f * f, frac_f); /* 1 / fraction */
538 if (frac_f > (15 * f))
539 activefrac = activepolarity ? 1 : 15;
541 activefrac = activepolarity ?
542 (u32)lldiv(frac_f, (u32)f) + 1 :
543 (u32)lldiv(frac_f, (u32)f);
549 if (activepolarity == 1)
550 approx_value_f = activefrac ? lldiv(
551 (activecount_f + (activefrac * f - f) * f),
555 approx_value_f = activefrac ?
556 activecount_f + lldiv(f, activefrac) :
559 if (activesym_f < approx_value_f) {
560 accumulated_error_f = num_linkclk_line *
561 lldiv(approx_value_f - activesym_f, i);
564 accumulated_error_f = num_linkclk_line *
565 lldiv(activesym_f - approx_value_f, i);
569 if ((neg && (lowest_neg_error_f > accumulated_error_f)) ||
570 (accumulated_error_f == 0)) {
571 lowest_neg_error_f = accumulated_error_f;
572 lowest_neg_tusize = i;
573 lowest_neg_activecount = activecount;
574 lowest_neg_activepolarity = activepolarity;
575 lowest_neg_activefrac = activefrac;
577 if (accumulated_error_f == 0)
582 if (lowest_neg_activefrac == 0) {
583 link_cfg->activepolarity = 0;
584 link_cfg->active_count = lowest_neg_activepolarity ?
585 lowest_neg_activecount : lowest_neg_activecount - 1;
586 link_cfg->tu_size = lowest_neg_tusize;
587 link_cfg->active_frac = 1;
589 link_cfg->activepolarity = lowest_neg_activepolarity;
590 link_cfg->active_count = (u32)lowest_neg_activecount;
591 link_cfg->tu_size = lowest_neg_tusize;
592 link_cfg->active_frac = (u32)lowest_neg_activefrac;
595 watermark_f = lldiv(ratio_f * link_cfg->tu_size * (f - ratio_f), f);
596 link_cfg->watermark = (u32)(lldiv(watermark_f + lowest_neg_error_f,
597 f)) + link_cfg->bits_per_pixel / 4 - 1;
598 num_symbols_per_line = (timing->hactive.typ *
599 link_cfg->bits_per_pixel) /
600 (8 * link_cfg->lane_count);
602 if (link_cfg->watermark > 30) {
603 debug("dp: sor setting: unable to get a good tusize, force watermark to 30\n");
604 link_cfg->watermark = 30;
606 } else if (link_cfg->watermark > num_symbols_per_line) {
607 debug("dp: sor setting: force watermark to the number of symbols in the line\n");
608 link_cfg->watermark = num_symbols_per_line;
613 * Refer to dev_disp.ref for more information.
614 * # symbols/hblank = ((SetRasterBlankEnd.X + SetRasterSize.Width -
615 * SetRasterBlankStart.X - 7) * link_clk / pclk)
616 * - 3 * enhanced_framing - Y
617 * where Y = (# lanes == 4) 3 : (# lanes == 2) ? 6 : 12
619 link_cfg->hblank_sym = (int)lldiv(((uint64_t)timing->hback_porch.typ +
620 timing->hfront_porch.typ + timing->hsync_len.typ - 7) *
621 link_rate, timing->pixelclock.typ) -
622 3 * link_cfg->enhanced_framing -
623 (12 / link_cfg->lane_count);
625 if (link_cfg->hblank_sym < 0)
626 link_cfg->hblank_sym = 0;
630 * Refer to dev_disp.ref for more information.
631 * # symbols/vblank = ((SetRasterBlankStart.X -
632 * SetRasterBlankEen.X - 25) * link_clk / pclk)
634 * where Y = (# lanes == 4) 12 : (# lanes == 2) ? 21 : 39
636 link_cfg->vblank_sym = (int)lldiv(((uint64_t)timing->hactive.typ - 25)
637 * link_rate, timing->pixelclock.typ) - (36 /
638 link_cfg->lane_count) - 4;
640 if (link_cfg->vblank_sym < 0)
641 link_cfg->vblank_sym = 0;
643 link_cfg->is_valid = 1;
645 tegra_dc_dp_dump_link_cfg(dp, link_cfg);
651 static int tegra_dc_dp_init_max_link_cfg(
652 const struct display_timing *timing,
653 struct tegra_dp_priv *dp,
654 struct tegra_dp_link_config *link_cfg)
656 const int drive_current = 0x40404040;
657 const int preemphasis = 0x0f0f0f0f;
658 const int postcursor = 0;
662 ret = tegra_dc_dp_dpcd_read(dp, DP_MAX_LANE_COUNT, &dpcd_data);
665 link_cfg->max_lane_count = dpcd_data & DP_MAX_LANE_COUNT_MASK;
666 link_cfg->tps3_supported = (dpcd_data &
667 DP_MAX_LANE_COUNT_TPS3_SUPPORTED_YES) ? 1 : 0;
669 link_cfg->support_enhanced_framing =
670 (dpcd_data & DP_MAX_LANE_COUNT_ENHANCED_FRAMING_YES) ?
673 ret = tegra_dc_dp_dpcd_read(dp, DP_MAX_DOWNSPREAD, &dpcd_data);
676 link_cfg->downspread = (dpcd_data & DP_MAX_DOWNSPREAD_VAL_0_5_PCT) ?
679 ret = tegra_dc_dp_dpcd_read(dp, NV_DPCD_TRAINING_AUX_RD_INTERVAL,
680 &link_cfg->aux_rd_interval);
683 ret = tegra_dc_dp_dpcd_read(dp, DP_MAX_LINK_RATE,
684 &link_cfg->max_link_bw);
689 * Set to a high value for link training and attach.
690 * Will be re-programmed when dp is enabled.
692 link_cfg->drive_current = drive_current;
693 link_cfg->preemphasis = preemphasis;
694 link_cfg->postcursor = postcursor;
696 ret = tegra_dc_dp_dpcd_read(dp, DP_EDP_CONFIGURATION_CAP, &dpcd_data);
700 link_cfg->alt_scramber_reset_cap =
701 (dpcd_data & DP_EDP_CONFIGURATION_CAP_ASC_RESET_YES) ?
703 link_cfg->only_enhanced_framing =
704 (dpcd_data & DP_EDP_CONFIGURATION_CAP_FRAMING_CHANGE_YES) ?
707 link_cfg->lane_count = link_cfg->max_lane_count;
708 link_cfg->link_bw = link_cfg->max_link_bw;
709 link_cfg->enhanced_framing = link_cfg->support_enhanced_framing;
710 link_cfg->frame_in_ms = (1000 / 60) + 1;
712 tegra_dc_dp_calc_config(dp, timing, link_cfg);
716 static int tegra_dc_dp_set_assr(struct tegra_dp_priv *priv,
717 struct udevice *sor, int ena)
722 DP_MAIN_LINK_CHANNEL_CODING_SET_ASC_RESET_ENABLE :
723 DP_MAIN_LINK_CHANNEL_CODING_SET_ASC_RESET_DISABLE;
725 ret = tegra_dc_dp_dpcd_write(priv, DP_EDP_CONFIGURATION_SET,
730 /* Also reset the scrambler to 0xfffe */
731 tegra_dc_sor_set_internal_panel(sor, ena);
735 static int tegra_dp_set_link_bandwidth(struct tegra_dp_priv *dp,
739 tegra_dc_sor_set_link_bandwidth(sor, link_bw);
742 return tegra_dc_dp_dpcd_write(dp, DP_LINK_BW_SET, link_bw);
745 static int tegra_dp_set_lane_count(struct tegra_dp_priv *dp,
746 const struct tegra_dp_link_config *link_cfg,
752 /* check if panel support enhanched_framing */
753 dpcd_data = link_cfg->lane_count;
754 if (link_cfg->enhanced_framing)
755 dpcd_data |= DP_LANE_COUNT_SET_ENHANCEDFRAMING_T;
756 ret = tegra_dc_dp_dpcd_write(dp, DP_LANE_COUNT_SET, dpcd_data);
760 tegra_dc_sor_set_lane_count(sor, link_cfg->lane_count);
762 /* Also power down lanes that will not be used */
766 static int tegra_dc_dp_link_trained(struct tegra_dp_priv *dp,
767 const struct tegra_dp_link_config *cfg)
774 for (lane = 0; lane < cfg->lane_count; ++lane) {
775 ret = tegra_dc_dp_dpcd_read(dp, (lane / 2) ?
776 DP_LANE2_3_STATUS : DP_LANE0_1_STATUS,
781 NV_DPCD_STATUS_LANEXPLUS1_CR_DONE_YES |
782 NV_DPCD_STATUS_LANEXPLUS1_CHN_EQ_DONE_YES |
783 NV_DPCD_STATUS_LANEXPLUS1_SYMBOL_LOCKED_YES :
785 DP_LANE_CHANNEL_EQ_DONE |
786 DP_LANE_SYMBOL_LOCKED;
787 if ((data & mask) != mask)
793 static int tegra_dp_channel_eq_status(struct tegra_dp_priv *dp,
794 const struct tegra_dp_link_config *cfg)
797 u32 n_lanes = cfg->lane_count;
802 for (cnt = 0; cnt < n_lanes / 2; cnt++) {
803 ret = tegra_dc_dp_dpcd_read(dp, DP_LANE0_1_STATUS + cnt, &data);
808 ce_done = (data & (0x1 <<
809 NV_DPCD_STATUS_LANEX_CHN_EQ_DONE_SHIFT)) &&
811 NV_DPCD_STATUS_LANEX_SYMBOL_LOCKED_SHFIT));
813 } else if (!(data & (0x1 <<
814 NV_DPCD_STATUS_LANEX_CHN_EQ_DONE_SHIFT)) ||
816 NV_DPCD_STATUS_LANEX_SYMBOL_LOCKED_SHFIT)) ||
818 NV_DPCD_STATUS_LANEXPLUS1_CHN_EQ_DONE_SHIFT)) ||
820 NV_DPCD_STATUS_LANEXPLUS1_SYMBOL_LOCKED_SHIFT)))
825 ret = tegra_dc_dp_dpcd_read(dp,
826 DP_LANE_ALIGN_STATUS_UPDATED,
830 if (!(data & NV_DPCD_LANE_ALIGN_STATUS_UPDATED_DONE_YES))
834 return ce_done ? 0 : -EIO;
837 static int tegra_dp_clock_recovery_status(struct tegra_dp_priv *dp,
838 const struct tegra_dp_link_config *cfg)
841 u32 n_lanes = cfg->lane_count;
845 for (cnt = 0; cnt < n_lanes / 2; cnt++) {
846 ret = tegra_dc_dp_dpcd_read(dp, (DP_LANE0_1_STATUS + cnt),
852 return (data_ptr & NV_DPCD_STATUS_LANEX_CR_DONE_YES) ?
854 else if (!(data_ptr & NV_DPCD_STATUS_LANEX_CR_DONE_YES) ||
855 !(data_ptr & (NV_DPCD_STATUS_LANEXPLUS1_CR_DONE_YES)))
862 static int tegra_dp_lt_adjust(struct tegra_dp_priv *dp, u32 pe[4], u32 vs[4],
863 u32 pc[4], u8 pc_supported,
864 const struct tegra_dp_link_config *cfg)
868 u32 n_lanes = cfg->lane_count;
871 for (cnt = 0; cnt < n_lanes / 2; cnt++) {
872 ret = tegra_dc_dp_dpcd_read(dp, DP_ADJUST_REQUEST_LANE0_1 + cnt,
876 pe[2 * cnt] = (data_ptr & NV_DPCD_ADJUST_REQ_LANEX_PE_MASK) >>
877 NV_DPCD_ADJUST_REQ_LANEX_PE_SHIFT;
878 vs[2 * cnt] = (data_ptr & NV_DPCD_ADJUST_REQ_LANEX_DC_MASK) >>
879 NV_DPCD_ADJUST_REQ_LANEX_DC_SHIFT;
881 (data_ptr & NV_DPCD_ADJUST_REQ_LANEXPLUS1_PE_MASK) >>
882 NV_DPCD_ADJUST_REQ_LANEXPLUS1_PE_SHIFT;
884 (data_ptr & NV_DPCD_ADJUST_REQ_LANEXPLUS1_DC_MASK) >>
885 NV_DPCD_ADJUST_REQ_LANEXPLUS1_DC_SHIFT;
888 ret = tegra_dc_dp_dpcd_read(dp, NV_DPCD_ADJUST_REQ_POST_CURSOR2,
892 for (cnt = 0; cnt < n_lanes; cnt++) {
893 pc[cnt] = (data_ptr >>
894 NV_DPCD_ADJUST_REQ_POST_CURSOR2_LANE_SHIFT(cnt)) &
895 NV_DPCD_ADJUST_REQ_POST_CURSOR2_LANE_MASK;
902 static void tegra_dp_wait_aux_training(struct tegra_dp_priv *dp,
903 bool is_clk_recovery,
904 const struct tegra_dp_link_config *cfg)
906 if (!cfg->aux_rd_interval)
907 udelay(is_clk_recovery ? 200 : 500);
909 mdelay(cfg->aux_rd_interval * 4);
912 static void tegra_dp_tpg(struct tegra_dp_priv *dp, u32 tp, u32 n_lanes,
913 const struct tegra_dp_link_config *cfg)
915 u8 data = (tp == training_pattern_disabled)
916 ? (tp | NV_DPCD_TRAINING_PATTERN_SET_SC_DISABLED_F)
917 : (tp | NV_DPCD_TRAINING_PATTERN_SET_SC_DISABLED_T);
919 tegra_dc_sor_set_dp_linkctl(dp->sor, 1, tp, cfg);
920 tegra_dc_dp_dpcd_write(dp, DP_TRAINING_PATTERN_SET, data);
923 static int tegra_dp_link_config(struct tegra_dp_priv *dp,
924 const struct tegra_dp_link_config *link_cfg)
930 if (link_cfg->lane_count == 0) {
931 debug("dp: error: lane count is 0. Can not set link config.\n");
935 /* Set power state if it is not in normal level */
936 ret = tegra_dc_dp_dpcd_read(dp, DP_SET_POWER, &dpcd_data);
940 if (dpcd_data == DP_SET_POWER_D3) {
941 dpcd_data = DP_SET_POWER_D0;
943 /* DP spec requires 3 retries */
944 for (retry = 3; retry > 0; --retry) {
945 ret = tegra_dc_dp_dpcd_write(dp, DP_SET_POWER,
950 debug("dp: Failed to set DP panel power\n");
956 /* Enable ASSR if possible */
957 if (link_cfg->alt_scramber_reset_cap) {
958 ret = tegra_dc_dp_set_assr(dp, dp->sor, 1);
963 ret = tegra_dp_set_link_bandwidth(dp, dp->sor, link_cfg->link_bw);
965 debug("dp: Failed to set link bandwidth\n");
968 ret = tegra_dp_set_lane_count(dp, link_cfg, dp->sor);
970 debug("dp: Failed to set lane count\n");
973 tegra_dc_sor_set_dp_linkctl(dp->sor, 1, training_pattern_none,
979 static int tegra_dp_lower_link_config(struct tegra_dp_priv *dp,
980 const struct display_timing *timing,
981 struct tegra_dp_link_config *cfg)
983 struct tegra_dp_link_config tmp_cfg;
989 ret = _tegra_dp_lower_link_config(dp, cfg);
991 ret = tegra_dc_dp_calc_config(dp, timing, cfg);
993 ret = tegra_dp_link_config(dp, cfg);
1001 tegra_dp_link_config(dp, &tmp_cfg);
1005 static int tegra_dp_lt_config(struct tegra_dp_priv *dp, u32 pe[4], u32 vs[4],
1006 u32 pc[4], const struct tegra_dp_link_config *cfg)
1008 struct udevice *sor = dp->sor;
1009 u32 n_lanes = cfg->lane_count;
1010 u8 pc_supported = cfg->tps3_supported;
1014 for (cnt = 0; cnt < n_lanes; cnt++) {
1016 u32 pe_reg, vs_reg, pc_reg;
1021 mask = PR_LANE2_DP_LANE0_MASK;
1022 shift = PR_LANE2_DP_LANE0_SHIFT;
1025 mask = PR_LANE1_DP_LANE1_MASK;
1026 shift = PR_LANE1_DP_LANE1_SHIFT;
1029 mask = PR_LANE0_DP_LANE2_MASK;
1030 shift = PR_LANE0_DP_LANE2_SHIFT;
1033 mask = PR_LANE3_DP_LANE3_MASK;
1034 shift = PR_LANE3_DP_LANE3_SHIFT;
1037 debug("dp: incorrect lane cnt\n");
1041 pe_reg = tegra_dp_pe_regs[pc[cnt]][vs[cnt]][pe[cnt]];
1042 vs_reg = tegra_dp_vs_regs[pc[cnt]][vs[cnt]][pe[cnt]];
1043 pc_reg = tegra_dp_pc_regs[pc[cnt]][vs[cnt]][pe[cnt]];
1045 tegra_dp_set_pe_vs_pc(sor, mask, pe_reg << shift,
1046 vs_reg << shift, pc_reg << shift,
1050 tegra_dp_disable_tx_pu(dp->sor);
1053 for (cnt = 0; cnt < n_lanes; cnt++) {
1054 u32 max_vs_flag = tegra_dp_is_max_vs(pe[cnt], vs[cnt]);
1055 u32 max_pe_flag = tegra_dp_is_max_pe(pe[cnt], vs[cnt]);
1057 val = (vs[cnt] << NV_DPCD_TRAINING_LANEX_SET_DC_SHIFT) |
1059 NV_DPCD_TRAINING_LANEX_SET_DC_MAX_REACHED_T :
1060 NV_DPCD_TRAINING_LANEX_SET_DC_MAX_REACHED_F) |
1061 (pe[cnt] << NV_DPCD_TRAINING_LANEX_SET_PE_SHIFT) |
1063 NV_DPCD_TRAINING_LANEX_SET_PE_MAX_REACHED_T :
1064 NV_DPCD_TRAINING_LANEX_SET_PE_MAX_REACHED_F);
1065 tegra_dc_dp_dpcd_write(dp, (DP_TRAINING_LANE0_SET + cnt), val);
1069 for (cnt = 0; cnt < n_lanes / 2; cnt++) {
1070 u32 max_pc_flag0 = tegra_dp_is_max_pc(pc[cnt]);
1071 u32 max_pc_flag1 = tegra_dp_is_max_pc(pc[cnt + 1]);
1072 val = (pc[cnt] << NV_DPCD_LANEX_SET2_PC2_SHIFT) |
1074 NV_DPCD_LANEX_SET2_PC2_MAX_REACHED_T :
1075 NV_DPCD_LANEX_SET2_PC2_MAX_REACHED_F) |
1077 NV_DPCD_LANEXPLUS1_SET2_PC2_SHIFT) |
1079 NV_DPCD_LANEXPLUS1_SET2_PC2_MAX_REACHED_T :
1080 NV_DPCD_LANEXPLUS1_SET2_PC2_MAX_REACHED_F);
1081 tegra_dc_dp_dpcd_write(dp,
1082 NV_DPCD_TRAINING_LANE0_1_SET2 +
1090 static int _tegra_dp_channel_eq(struct tegra_dp_priv *dp, u32 pe[4],
1091 u32 vs[4], u32 pc[4], u8 pc_supported,
1093 const struct tegra_dp_link_config *cfg)
1097 for (retry_cnt = 0; retry_cnt < 4; retry_cnt++) {
1101 ret = tegra_dp_lt_adjust(dp, pe, vs, pc, pc_supported,
1105 tegra_dp_lt_config(dp, pe, vs, pc, cfg);
1108 tegra_dp_wait_aux_training(dp, false, cfg);
1110 if (!tegra_dp_clock_recovery_status(dp, cfg)) {
1111 debug("dp: CR failed in channel EQ sequence!\n");
1115 if (!tegra_dp_channel_eq_status(dp, cfg))
1122 static int tegra_dp_channel_eq(struct tegra_dp_priv *dp, u32 pe[4], u32 vs[4],
1124 const struct tegra_dp_link_config *cfg)
1126 u32 n_lanes = cfg->lane_count;
1127 u8 pc_supported = cfg->tps3_supported;
1129 u32 tp_src = training_pattern_2;
1132 tp_src = training_pattern_3;
1134 tegra_dp_tpg(dp, tp_src, n_lanes, cfg);
1136 ret = _tegra_dp_channel_eq(dp, pe, vs, pc, pc_supported, n_lanes, cfg);
1138 tegra_dp_tpg(dp, training_pattern_disabled, n_lanes, cfg);
1143 static int _tegra_dp_clk_recovery(struct tegra_dp_priv *dp, u32 pe[4],
1144 u32 vs[4], u32 pc[4], u8 pc_supported,
1146 const struct tegra_dp_link_config *cfg)
1152 tegra_dp_lt_config(dp, pe, vs, pc, cfg);
1153 tegra_dp_wait_aux_training(dp, true, cfg);
1155 if (tegra_dp_clock_recovery_status(dp, cfg))
1158 memcpy(vs_temp, vs, sizeof(vs_temp));
1159 tegra_dp_lt_adjust(dp, pe, vs, pc, pc_supported, cfg);
1161 if (memcmp(vs_temp, vs, sizeof(vs_temp)))
1165 } while (retry_cnt < 5);
1170 static int tegra_dp_clk_recovery(struct tegra_dp_priv *dp, u32 pe[4],
1171 u32 vs[4], u32 pc[4],
1172 const struct tegra_dp_link_config *cfg)
1174 u32 n_lanes = cfg->lane_count;
1175 u8 pc_supported = cfg->tps3_supported;
1178 tegra_dp_tpg(dp, training_pattern_1, n_lanes, cfg);
1180 err = _tegra_dp_clk_recovery(dp, pe, vs, pc, pc_supported, n_lanes,
1183 tegra_dp_tpg(dp, training_pattern_disabled, n_lanes, cfg);
1188 static int tegra_dc_dp_full_link_training(struct tegra_dp_priv *dp,
1189 const struct display_timing *timing,
1190 struct tegra_dp_link_config *cfg)
1192 struct udevice *sor = dp->sor;
1194 u32 pe[4], vs[4], pc[4];
1196 tegra_sor_precharge_lanes(sor, cfg);
1199 memset(pe, PREEMPHASIS_DISABLED, sizeof(pe));
1200 memset(vs, DRIVECURRENT_LEVEL0, sizeof(vs));
1201 memset(pc, POSTCURSOR2_LEVEL0, sizeof(pc));
1203 err = tegra_dp_clk_recovery(dp, pe, vs, pc, cfg);
1205 if (!tegra_dp_lower_link_config(dp, timing, cfg))
1208 debug("dp: clk recovery failed\n");
1212 err = tegra_dp_channel_eq(dp, pe, vs, pc, cfg);
1214 if (!tegra_dp_lower_link_config(dp, timing, cfg))
1217 debug("dp: channel equalization failed\n");
1221 tegra_dc_dp_dump_link_cfg(dp, cfg);
1230 * All link training functions are ported from kernel dc driver.
1231 * See more details at drivers/video/tegra/dc/dp.c
1233 static int tegra_dc_dp_fast_link_training(struct tegra_dp_priv *dp,
1234 const struct tegra_dp_link_config *link_cfg,
1235 struct udevice *sor)
1244 u32 mask = 0xffff >> ((4 - link_cfg->lane_count) * 4);
1246 tegra_dc_sor_set_lane_parm(sor, link_cfg);
1247 tegra_dc_dp_dpcd_write(dp, DP_MAIN_LINK_CHANNEL_CODING_SET,
1251 tegra_dc_sor_set_dp_linkctl(sor, 1, training_pattern_1, link_cfg);
1252 tegra_dc_dp_dpcd_write(dp, DP_TRAINING_PATTERN_SET,
1253 DP_TRAINING_PATTERN_1);
1255 for (j = 0; j < link_cfg->lane_count; ++j)
1256 tegra_dc_dp_dpcd_write(dp, DP_TRAINING_LANE0_SET + j, 0x24);
1259 size = sizeof(data16);
1260 tegra_dc_dpaux_read(dp, DPAUX_DP_AUXCTL_CMD_AUXRD,
1261 DP_LANE0_1_STATUS, (u8 *)&data16, &size, &status);
1262 status = mask & 0x1111;
1263 if ((data16 & status) != status) {
1264 debug("dp: Link training error for TP1 (%#x, status %#x)\n",
1270 tegra_dc_dp_set_assr(dp, sor, link_cfg->scramble_ena);
1271 tegra_dc_sor_set_dp_linkctl(sor, 1, training_pattern_3, link_cfg);
1273 tegra_dc_dp_dpcd_write(dp, DP_TRAINING_PATTERN_SET,
1274 link_cfg->link_bw == 20 ? 0x23 : 0x22);
1275 for (j = 0; j < link_cfg->lane_count; ++j)
1276 tegra_dc_dp_dpcd_write(dp, DP_TRAINING_LANE0_SET + j, 0x24);
1279 size = sizeof(data32);
1280 tegra_dc_dpaux_read(dp, DPAUX_DP_AUXCTL_CMD_AUXRD, DP_LANE0_1_STATUS,
1281 (u8 *)&data32, &size, &status);
1282 if ((data32 & mask) != (0x7777 & mask)) {
1283 debug("dp: Link training error for TP2/3 (0x%x)\n", data32);
1287 tegra_dc_sor_set_dp_linkctl(sor, 1, training_pattern_disabled,
1289 tegra_dc_dp_dpcd_write(dp, DP_TRAINING_PATTERN_SET, 0);
1291 if (tegra_dc_dp_link_trained(dp, link_cfg)) {
1292 tegra_dc_sor_read_link_config(sor, &link_bw, &lane_count);
1293 debug("Fast link training failed, link bw %d, lane # %d\n",
1294 link_bw, lane_count);
1298 debug("Fast link training succeeded, link bw %d, lane %d\n",
1299 link_cfg->link_bw, link_cfg->lane_count);
1304 static int tegra_dp_do_link_training(struct tegra_dp_priv *dp,
1305 struct tegra_dp_link_config *link_cfg,
1306 const struct display_timing *timing,
1307 struct udevice *sor)
1313 if (DO_FAST_LINK_TRAINING) {
1314 ret = tegra_dc_dp_fast_link_training(dp, link_cfg, sor);
1316 debug("dp: fast link training failed\n");
1319 * set to a known-good drive setting if fast link
1320 * succeeded. Ignore any error.
1322 ret = tegra_dc_sor_set_voltage_swing(dp->sor, link_cfg);
1324 debug("Failed to set voltage swing\n");
1330 /* Try full link training then */
1331 ret = tegra_dc_dp_full_link_training(dp, timing, link_cfg);
1333 debug("dp: full link training failed\n");
1338 /* Everything is good; double check the link config */
1339 tegra_dc_sor_read_link_config(sor, &link_bw, &lane_count);
1341 if ((link_cfg->link_bw == link_bw) &&
1342 (link_cfg->lane_count == lane_count))
1348 static int tegra_dc_dp_explore_link_cfg(struct tegra_dp_priv *dp,
1349 struct tegra_dp_link_config *link_cfg,
1350 struct udevice *sor,
1351 const struct display_timing *timing)
1353 struct tegra_dp_link_config temp_cfg;
1355 if (!timing->pixelclock.typ || !timing->hactive.typ ||
1356 !timing->vactive.typ) {
1357 debug("dp: error mode configuration");
1360 if (!link_cfg->max_link_bw || !link_cfg->max_lane_count) {
1361 debug("dp: error link configuration");
1365 link_cfg->is_valid = 0;
1367 memcpy(&temp_cfg, link_cfg, sizeof(temp_cfg));
1369 temp_cfg.link_bw = temp_cfg.max_link_bw;
1370 temp_cfg.lane_count = temp_cfg.max_lane_count;
1373 * set to max link config
1375 if ((!tegra_dc_dp_calc_config(dp, timing, &temp_cfg)) &&
1376 (!tegra_dp_link_config(dp, &temp_cfg)) &&
1377 (!tegra_dp_do_link_training(dp, &temp_cfg, timing, sor)))
1378 /* the max link cfg is doable */
1379 memcpy(link_cfg, &temp_cfg, sizeof(temp_cfg));
1381 return link_cfg->is_valid ? 0 : -EFAULT;
1384 static int tegra_dp_hpd_plug(struct tegra_dp_priv *dp)
1386 const int vdd_to_hpd_delay_ms = 200;
1390 start = get_timer(0);
1392 val = tegra_dpaux_readl(dp, DPAUX_DP_AUXSTAT);
1393 if (val & DPAUX_DP_AUXSTAT_HPD_STATUS_PLUGGED)
1396 } while (get_timer(start) < vdd_to_hpd_delay_ms);
1401 static int tegra_dc_dp_sink_out_of_sync(struct tegra_dp_priv *dp, u32 delay_ms)
1407 debug("%s: delay=%d\n", __func__, delay_ms);
1409 ret = tegra_dc_dp_dpcd_read(dp, DP_SINK_STATUS, &dpcd_data);
1413 out_of_sync = !(dpcd_data & DP_SINK_STATUS_PORT0_IN_SYNC);
1415 debug("SINK receive port 0 out of sync, data=%x\n", dpcd_data);
1417 debug("SINK is in synchronization\n");
1422 static int tegra_dc_dp_check_sink(struct tegra_dp_priv *dp,
1423 struct tegra_dp_link_config *link_cfg,
1424 const struct display_timing *timing)
1426 const int max_retry = 5;
1431 * DP TCON may skip some main stream frames, thus we need to wait
1432 * some delay before reading the DPCD SINK STATUS register, starting
1437 retries = max_retry;
1441 if (!tegra_dc_dp_sink_out_of_sync(dp, link_cfg->frame_in_ms *
1445 debug("%s: retries left %d\n", __func__, retries);
1447 printf("DP: Out of sync after %d retries\n", max_retry);
1450 ret = tegra_dc_sor_detach(dp->dc_dev, dp->sor);
1453 if (tegra_dc_dp_explore_link_cfg(dp, link_cfg, dp->sor,
1455 debug("dp: %s: error to configure link\n", __func__);
1459 tegra_dc_sor_set_power_state(dp->sor, 1);
1460 tegra_dc_sor_attach(dp->dc_dev, dp->sor, link_cfg, timing);
1462 /* Increase delay_frame for next try in case the sink is
1463 skipping more frames */
1468 int tegra_dp_enable(struct udevice *dev, int panel_bpp,
1469 const struct display_timing *timing)
1471 struct tegra_dp_priv *priv = dev_get_priv(dev);
1472 struct tegra_dp_link_config slink_cfg, *link_cfg = &slink_cfg;
1473 struct udevice *sor;
1478 memset(link_cfg, '\0', sizeof(*link_cfg));
1479 link_cfg->is_valid = 0;
1480 link_cfg->scramble_ena = 1;
1482 tegra_dc_dpaux_enable(priv);
1484 if (tegra_dp_hpd_plug(priv) < 0) {
1485 debug("dp: hpd plug failed\n");
1489 link_cfg->bits_per_pixel = panel_bpp;
1490 if (tegra_dc_dp_init_max_link_cfg(timing, priv, link_cfg)) {
1491 debug("dp: failed to init link configuration\n");
1495 ret = uclass_first_device(UCLASS_VIDEO_BRIDGE, &sor);
1497 debug("dp: failed to find SOR device: ret=%d\n", ret);
1501 ret = tegra_dc_sor_enable_dp(sor, link_cfg);
1505 tegra_dc_sor_set_panel_power(sor, 1);
1507 /* Write power on to DPCD */
1508 data = DP_SET_POWER_D0;
1511 ret = tegra_dc_dp_dpcd_write(priv, DP_SET_POWER, data);
1512 } while ((retry++ < DP_POWER_ON_MAX_TRIES) && ret);
1514 if (ret || retry >= DP_POWER_ON_MAX_TRIES) {
1515 debug("dp: failed to power on panel (0x%x)\n", ret);
1516 return -ENETUNREACH;
1520 /* Confirm DP plugging status */
1521 if (!(tegra_dpaux_readl(priv, DPAUX_DP_AUXSTAT) &
1522 DPAUX_DP_AUXSTAT_HPD_STATUS_PLUGGED)) {
1523 debug("dp: could not detect HPD\n");
1527 /* Check DP version */
1528 if (tegra_dc_dp_dpcd_read(priv, DP_DPCD_REV, &priv->revision)) {
1529 debug("dp: failed to read the revision number from sink\n");
1533 if (tegra_dc_dp_explore_link_cfg(priv, link_cfg, sor, timing)) {
1534 debug("dp: error configuring link\n");
1538 tegra_dc_sor_set_power_state(sor, 1);
1539 ret = tegra_dc_sor_attach(priv->dc_dev, sor, link_cfg, timing);
1540 if (ret && ret != -EEXIST)
1544 * This takes a long time, but can apparently resolve a failure to
1545 * bring up the display correctly.
1548 ret = tegra_dc_dp_check_sink(priv, link_cfg, timing);
1553 /* Power down the unused lanes to save power - a few hundred mW */
1554 tegra_dc_sor_power_down_unused_lanes(sor, link_cfg);
1556 ret = video_bridge_set_backlight(sor, 80);
1558 debug("dp: failed to set backlight\n");
1562 priv->enabled = true;
1567 static int tegra_dp_ofdata_to_platdata(struct udevice *dev)
1569 struct tegra_dp_plat *plat = dev_get_platdata(dev);
1571 plat->base = dev_read_addr(dev);
1576 static int tegra_dp_read_edid(struct udevice *dev, u8 *buf, int buf_size)
1578 struct tegra_dp_priv *priv = dev_get_priv(dev);
1579 const int tegra_edid_i2c_address = 0x50;
1582 tegra_dc_dpaux_enable(priv);
1584 return tegra_dc_i2c_aux_read(priv, tegra_edid_i2c_address, 0, buf,
1585 buf_size, &aux_stat);
1588 static const struct dm_display_ops dp_tegra_ops = {
1589 .read_edid = tegra_dp_read_edid,
1590 .enable = tegra_dp_enable,
1593 static int dp_tegra_probe(struct udevice *dev)
1595 struct tegra_dp_plat *plat = dev_get_platdata(dev);
1596 struct tegra_dp_priv *priv = dev_get_priv(dev);
1597 struct display_plat *disp_uc_plat = dev_get_uclass_platdata(dev);
1599 priv->regs = (struct dpaux_ctlr *)plat->base;
1600 priv->enabled = false;
1602 /* Remember the display controller that is sending us video */
1603 priv->dc_dev = disp_uc_plat->src_dev;
1608 static const struct udevice_id tegra_dp_ids[] = {
1609 { .compatible = "nvidia,tegra124-dpaux" },
1613 U_BOOT_DRIVER(dp_tegra) = {
1614 .name = "dpaux_tegra",
1615 .id = UCLASS_DISPLAY,
1616 .of_match = tegra_dp_ids,
1617 .ofdata_to_platdata = tegra_dp_ofdata_to_platdata,
1618 .probe = dp_tegra_probe,
1619 .ops = &dp_tegra_ops,
1620 .priv_auto_alloc_size = sizeof(struct tegra_dp_priv),
1621 .platdata_auto_alloc_size = sizeof(struct tegra_dp_plat),