1 /* SPDX-License-Identifier: GPL-2.0-only */
4 * drivers/video/tegra/dc/dp.c
7 #include <console/console.h>
9 #include <device/device.h>
10 #include <device/i2c_simple.h>
12 #include <soc/addressmap.h>
13 #include <soc/nvidia/tegra/i2c.h>
14 #include <soc/nvidia/tegra/dc.h>
15 #include <soc/nvidia/tegra/displayport.h>
27 struct tegra_dc_dp_data dp_data
;
29 static inline u32
tegra_dpaux_readl(struct tegra_dc_dp_data
*dp
, u32 reg
)
31 void *addr
= dp
->aux_base
+ (u32
)(reg
<< 2);
32 u32 reg_val
= READL(addr
);
36 static inline void tegra_dpaux_writel(struct tegra_dc_dp_data
*dp
,
39 void *addr
= dp
->aux_base
+ (u32
)(reg
<< 2);
43 static inline u32
tegra_dc_dpaux_poll_register(struct tegra_dc_dp_data
*dp
,
44 u32 reg
, u32 mask
, u32 exp_val
,
49 u32 temp
= timeout_us
;
52 udelay(poll_interval_us
);
53 reg_val
= tegra_dpaux_readl(dp
, reg
);
54 if (timeout_us
> poll_interval_us
)
55 timeout_us
-= poll_interval_us
;
58 } while ((reg_val
& mask
) != exp_val
);
60 if ((reg_val
& mask
) == exp_val
)
61 return 0; /* success */
63 "dpaux_poll_register 0x%x: timeout: "
64 "(reg_val)0x%08x & (mask)0x%08x != (exp_val)0x%08x\n",
65 reg
, reg_val
, mask
, exp_val
);
69 static inline int tegra_dpaux_wait_transaction(struct tegra_dc_dp_data
*dp
)
71 /* According to DP spec, each aux transaction needs to finish
73 if (tegra_dc_dpaux_poll_register(dp
, DPAUX_DP_AUXCTL
,
74 DPAUX_DP_AUXCTL_TRANSACTREQ_MASK
,
75 DPAUX_DP_AUXCTL_TRANSACTREQ_DONE
,
76 100, DP_AUX_TIMEOUT_MS
* 1000) != 0) {
77 printk(BIOS_INFO
, "dp: DPAUX transaction timeout\n");
83 static int tegra_dc_dpaux_write_chunk(struct tegra_dc_dp_data
*dp
, u32 cmd
,
84 u32 addr
, u8
*data
, u32
*size
,
89 u32 timeout_retries
= DP_AUX_TIMEOUT_MAX_TRIES
;
90 u32 defer_retries
= DP_AUX_DEFER_MAX_TRIES
;
93 if (*size
> DP_AUX_MAX_BYTES
)
94 return -1; /* only write one chunk of data */
96 /* Make sure the command is write command */
98 case DPAUX_DP_AUXCTL_CMD_I2CWR
:
99 case DPAUX_DP_AUXCTL_CMD_MOTWR
:
100 case DPAUX_DP_AUXCTL_CMD_AUXWR
:
103 printk(BIOS_ERR
, "dp: aux write cmd 0x%x is invalid\n",
108 tegra_dpaux_writel(dp
, DPAUX_DP_AUXADDR
, addr
);
109 for (i
= 0; i
< DP_AUX_MAX_BYTES
/ 4; ++i
) {
110 memcpy(&temp_data
, data
, 4);
111 tegra_dpaux_writel(dp
, DPAUX_DP_AUXDATA_WRITE_W(i
), temp_data
);
115 reg_val
= tegra_dpaux_readl(dp
, DPAUX_DP_AUXCTL
);
116 reg_val
&= ~DPAUX_DP_AUXCTL_CMD_MASK
;
118 reg_val
&= ~DPAUX_DP_AUXCTL_CMDLEN_FIELD
;
119 reg_val
|= ((*size
- 1) << DPAUX_DP_AUXCTL_CMDLEN_SHIFT
);
121 while ((timeout_retries
> 0) && (defer_retries
> 0)) {
122 if ((timeout_retries
!= DP_AUX_TIMEOUT_MAX_TRIES
) ||
123 (defer_retries
!= DP_AUX_DEFER_MAX_TRIES
))
126 reg_val
|= DPAUX_DP_AUXCTL_TRANSACTREQ_PENDING
;
127 tegra_dpaux_writel(dp
, DPAUX_DP_AUXCTL
, reg_val
);
129 if (tegra_dpaux_wait_transaction(dp
))
130 printk(BIOS_ERR
, "dp: aux write transaction timeout\n");
132 *aux_stat
= tegra_dpaux_readl(dp
, DPAUX_DP_AUXSTAT
);
134 if ((*aux_stat
& DPAUX_DP_AUXSTAT_TIMEOUT_ERROR_PENDING
) ||
135 (*aux_stat
& DPAUX_DP_AUXSTAT_RX_ERROR_PENDING
) ||
136 (*aux_stat
& DPAUX_DP_AUXSTAT_SINKSTAT_ERROR_PENDING
) ||
137 (*aux_stat
& DPAUX_DP_AUXSTAT_NO_STOP_ERROR_PENDING
)) {
138 if (timeout_retries
-- > 0) {
139 printk(BIOS_INFO
, "dp: aux write retry (0x%x) -- %d\n",
140 *aux_stat
, timeout_retries
);
141 /* clear the error bits */
142 tegra_dpaux_writel(dp
, DPAUX_DP_AUXSTAT
, *aux_stat
);
145 printk(BIOS_ERR
, "dp: aux write got error (0x%x)\n",
151 if ((*aux_stat
& DPAUX_DP_AUXSTAT_REPLYTYPE_I2CDEFER
) ||
152 (*aux_stat
& DPAUX_DP_AUXSTAT_REPLYTYPE_DEFER
)) {
153 if (defer_retries
-- > 0) {
154 printk(BIOS_INFO
, "dp: aux write defer (0x%x) -- %d\n",
155 *aux_stat
, defer_retries
);
156 /* clear the error bits */
157 tegra_dpaux_writel(dp
, DPAUX_DP_AUXSTAT
, *aux_stat
);
160 printk(BIOS_ERR
, "dp: aux write defer exceeds max retries "
161 "(0x%x)\n", *aux_stat
);
166 if ((*aux_stat
& DPAUX_DP_AUXSTAT_REPLYTYPE_MASK
) ==
167 DPAUX_DP_AUXSTAT_REPLYTYPE_ACK
) {
168 *size
= ((*aux_stat
) & DPAUX_DP_AUXSTAT_REPLY_M_MASK
);
171 printk(BIOS_ERR
, "dp: aux write failed (0x%x)\n",
176 /* Should never come to here */
180 static int tegra_dc_dpaux_read_chunk(struct tegra_dc_dp_data
*dp
, u32 cmd
,
181 u32 addr
, u8
*data
, u32
*size
,
185 u32 timeout_retries
= DP_AUX_TIMEOUT_MAX_TRIES
;
186 u32 defer_retries
= DP_AUX_DEFER_MAX_TRIES
;
188 if (*size
> DP_AUX_MAX_BYTES
)
189 return -1; /* only read one chunk */
191 /* Check to make sure the command is read command */
193 case DPAUX_DP_AUXCTL_CMD_I2CRD
:
194 case DPAUX_DP_AUXCTL_CMD_I2CREQWSTAT
:
195 case DPAUX_DP_AUXCTL_CMD_MOTRD
:
196 case DPAUX_DP_AUXCTL_CMD_AUXRD
:
199 printk(BIOS_ERR
, "dp: aux read cmd 0x%x is invalid\n",
204 *aux_stat
= tegra_dpaux_readl(dp
, DPAUX_DP_AUXSTAT
);
205 if (!(*aux_stat
& DPAUX_DP_AUXSTAT_HPD_STATUS_PLUGGED
)) {
206 printk(BIOS_SPEW
, "dp: HPD is not detected\n");
210 tegra_dpaux_writel(dp
, DPAUX_DP_AUXADDR
, addr
);
212 reg_val
= tegra_dpaux_readl(dp
, DPAUX_DP_AUXCTL
);
213 reg_val
&= ~DPAUX_DP_AUXCTL_CMD_MASK
;
215 reg_val
&= ~DPAUX_DP_AUXCTL_CMDLEN_FIELD
;
216 reg_val
|= ((*size
- 1) << DPAUX_DP_AUXCTL_CMDLEN_SHIFT
);
217 while ((timeout_retries
> 0) && (defer_retries
> 0)) {
218 if ((timeout_retries
!= DP_AUX_TIMEOUT_MAX_TRIES
) ||
219 (defer_retries
!= DP_AUX_DEFER_MAX_TRIES
))
220 udelay(DP_DPCP_RETRY_SLEEP_NS
* 2);
222 reg_val
|= DPAUX_DP_AUXCTL_TRANSACTREQ_PENDING
;
223 tegra_dpaux_writel(dp
, DPAUX_DP_AUXCTL
, reg_val
);
225 if (tegra_dpaux_wait_transaction(dp
))
226 printk(BIOS_INFO
, "dp: aux read transaction timeout\n");
228 *aux_stat
= tegra_dpaux_readl(dp
, DPAUX_DP_AUXSTAT
);
230 if ((*aux_stat
& DPAUX_DP_AUXSTAT_TIMEOUT_ERROR_PENDING
) ||
231 (*aux_stat
& DPAUX_DP_AUXSTAT_RX_ERROR_PENDING
) ||
232 (*aux_stat
& DPAUX_DP_AUXSTAT_SINKSTAT_ERROR_PENDING
) ||
233 (*aux_stat
& DPAUX_DP_AUXSTAT_NO_STOP_ERROR_PENDING
)) {
234 if (timeout_retries
-- > 0) {
235 printk(BIOS_INFO
, "dp: aux read retry (0x%x)"
236 " -- %d\n", *aux_stat
,
238 /* clear the error bits */
239 tegra_dpaux_writel(dp
, DPAUX_DP_AUXSTAT
,
241 continue; /* retry */
243 printk(BIOS_ERR
, "dp: aux read got error"
244 " (0x%x)\n", *aux_stat
);
249 if ((*aux_stat
& DPAUX_DP_AUXSTAT_REPLYTYPE_I2CDEFER
) ||
250 (*aux_stat
& DPAUX_DP_AUXSTAT_REPLYTYPE_DEFER
)) {
251 if (defer_retries
-- > 0) {
252 printk(BIOS_INFO
, "dp: aux read defer (0x%x) -- %d\n",
253 *aux_stat
, defer_retries
);
254 /* clear the error bits */
255 tegra_dpaux_writel(dp
, DPAUX_DP_AUXSTAT
, *aux_stat
);
258 printk(BIOS_INFO
, "dp: aux read defer exceeds max retries "
259 "(0x%x)\n", *aux_stat
);
264 if ((*aux_stat
& DPAUX_DP_AUXSTAT_REPLYTYPE_MASK
) ==
265 DPAUX_DP_AUXSTAT_REPLYTYPE_ACK
) {
269 for (i
= 0; i
< DP_AUX_MAX_BYTES
/ 4; ++i
)
270 temp_data
[i
] = tegra_dpaux_readl(dp
,
271 DPAUX_DP_AUXDATA_READ_W(i
));
273 *size
= ((*aux_stat
) & DPAUX_DP_AUXSTAT_REPLY_M_MASK
);
274 memcpy(data
, temp_data
, *size
);
278 printk(BIOS_ERR
, "dp: aux read failed (0x%x\n",
283 /* Should never come to here */
284 printk(BIOS_ERR
, "%s: can't\n", __func__
);
288 static int tegra_dc_dpaux_read(struct tegra_dc_dp_data
*dp
, u32 cmd
, u32 addr
,
289 u8
*data
, u32
*size
, u32
*aux_stat
)
296 cur_size
= *size
- finished
;
297 if (cur_size
> DP_AUX_MAX_BYTES
)
298 cur_size
= DP_AUX_MAX_BYTES
;
300 ret
= tegra_dc_dpaux_read_chunk(dp
, cmd
, addr
,
301 data
, &cur_size
, aux_stat
);
305 /* cur_size should be the real size returned */
308 finished
+= cur_size
;
310 } while (*size
> finished
);
316 static int tegra_dc_dp_dpcd_read(struct tegra_dc_dp_data
*dp
, u32 cmd
,
323 ret
= tegra_dc_dpaux_read_chunk(dp
, DPAUX_DP_AUXCTL_CMD_AUXRD
,
324 cmd
, data_ptr
, &size
, &status
);
327 "dp: Failed to read DPCD data. CMD 0x%x, Status 0x%x\n",
333 static int tegra_dc_dp_dpcd_write(struct tegra_dc_dp_data
*dp
, u32 cmd
,
340 ret
= tegra_dc_dpaux_write_chunk(dp
, DPAUX_DP_AUXCTL_CMD_AUXWR
,
341 cmd
, &data
, &size
, &status
);
344 "dp: Failed to write DPCD data. CMD 0x%x, Status 0x%x\n",
349 static int tegra_dc_i2c_aux_read(struct tegra_dc_dp_data
*dp
, u32 i2c_addr
,
350 u8 addr
, u8
*data
, u32
*size
, u32
*aux_stat
)
356 u32 cur_size
= MIN(DP_AUX_MAX_BYTES
, *size
- finished
);
359 ret
= tegra_dc_dpaux_write_chunk(
360 dp
, DPAUX_DP_AUXCTL_CMD_MOTWR
, i2c_addr
,
361 &addr
, &len
, aux_stat
);
363 printk(BIOS_ERR
, "%s: error sending address to read.\n",
368 ret
= tegra_dc_dpaux_read_chunk(
369 dp
, DPAUX_DP_AUXCTL_CMD_I2CRD
, i2c_addr
,
370 data
, &cur_size
, aux_stat
);
372 printk(BIOS_ERR
, "%s: error reading data.\n", __func__
);
376 /* cur_size should be the real size returned */
379 finished
+= cur_size
;
380 } while (*size
> finished
);
386 static void tegra_dc_dpaux_enable(struct tegra_dc_dp_data
*dp
)
388 /* clear interrupt */
389 tegra_dpaux_writel(dp
, DPAUX_INTR_AUX
, 0xffffffff);
390 /* do not enable interrupt for now. Enable them when Isr in place */
391 tegra_dpaux_writel(dp
, DPAUX_INTR_EN_AUX
, 0x0);
393 tegra_dpaux_writel(dp
, DPAUX_HYBRID_PADCTL
,
394 DPAUX_HYBRID_PADCTL_AUX_DRVZ_OHM_50
|
395 DPAUX_HYBRID_PADCTL_AUX_CMH_V0_70
|
396 0x18 << DPAUX_HYBRID_PADCTL_AUX_DRVI_SHIFT
|
397 DPAUX_HYBRID_PADCTL_AUX_INPUT_RCV_ENABLE
);
399 tegra_dpaux_writel(dp
, DPAUX_HYBRID_SPARE
,
400 DPAUX_HYBRID_SPARE_PAD_PWR_POWERUP
);
403 static void tegra_dc_dp_dump_link_cfg(struct tegra_dc_dp_data
*dp
,
404 const struct tegra_dc_dp_link_config
*link_cfg
)
406 printk(BIOS_INFO
, "DP config: cfg_name "
408 printk(BIOS_INFO
, " Lane Count %d\n",
409 link_cfg
->max_lane_count
);
410 printk(BIOS_INFO
, " SupportEnhancedFraming %s\n",
411 link_cfg
->support_enhanced_framing
? "Y" : "N");
412 printk(BIOS_INFO
, " Bandwidth %d\n",
413 link_cfg
->max_link_bw
);
414 printk(BIOS_INFO
, " bpp %d\n",
415 link_cfg
->bits_per_pixel
);
416 printk(BIOS_INFO
, " EnhancedFraming %s\n",
417 link_cfg
->enhanced_framing
? "Y" : "N");
418 printk(BIOS_INFO
, " Scramble_enabled %s\n",
419 link_cfg
->scramble_ena
? "Y" : "N");
420 printk(BIOS_INFO
, " LinkBW %d\n",
422 printk(BIOS_INFO
, " lane_count %d\n",
423 link_cfg
->lane_count
);
424 printk(BIOS_INFO
, " activespolarity %d\n",
425 link_cfg
->activepolarity
);
426 printk(BIOS_INFO
, " active_count %d\n",
427 link_cfg
->active_count
);
428 printk(BIOS_INFO
, " tu_size %d\n",
430 printk(BIOS_INFO
, " active_frac %d\n",
431 link_cfg
->active_frac
);
432 printk(BIOS_INFO
, " watermark %d\n",
433 link_cfg
->watermark
);
434 printk(BIOS_INFO
, " hblank_sym %d\n",
435 link_cfg
->hblank_sym
);
436 printk(BIOS_INFO
, " vblank_sym %d\n",
437 link_cfg
->vblank_sym
);
440 static int _tegra_dp_lower_link_config(struct tegra_dc_dp_data
*dp
,
441 struct tegra_dc_dp_link_config
*cfg
)
443 switch (cfg
->link_bw
){
444 case SOR_LINK_SPEED_G1_62
:
445 if (cfg
->max_link_bw
> SOR_LINK_SPEED_G1_62
)
446 cfg
->link_bw
= SOR_LINK_SPEED_G2_7
;
447 cfg
->lane_count
/= 2;
449 case SOR_LINK_SPEED_G2_7
:
450 cfg
->link_bw
= SOR_LINK_SPEED_G1_62
;
452 case SOR_LINK_SPEED_G5_4
:
453 if (cfg
->lane_count
== 1) {
454 cfg
->link_bw
= SOR_LINK_SPEED_G2_7
;
455 cfg
->lane_count
= cfg
->max_lane_count
;
457 cfg
->lane_count
/= 2;
460 printk(BIOS_ERR
,"dp: Error link rate %d\n", cfg
->link_bw
);
464 return (cfg
->lane_count
> 0) ? DP_LT_SUCCESS
: DP_LT_FAILED
;
467 /* Calculate if given cfg can meet the mode request. */
468 /* Return true if mode is possible, false otherwise. */
469 static int tegra_dc_dp_calc_config(struct tegra_dc_dp_data
*dp
,
470 const struct soc_nvidia_tegra124_config
*config
,
471 struct tegra_dc_dp_link_config
*link_cfg
)
473 const u32 link_rate
= 27 * link_cfg
->link_bw
* 1000 * 1000;
474 const u64 f
= 100000; /* precision factor */
476 u32 num_linkclk_line
; /* Number of link clocks per line */
477 u64 ratio_f
; /* Ratio of incoming to outgoing data rate */
480 u64 activesym_f
; /* Activesym per TU */
486 u64 accumulated_error_f
= 0;
487 u32 lowest_neg_activecount
= 0;
488 u32 lowest_neg_activepolarity
= 0;
489 u32 lowest_neg_tusize
= 64;
490 u32 num_symbols_per_line
;
491 u64 lowest_neg_activefrac
= 0;
492 u64 lowest_neg_error_f
= 64 * f
;
498 if (!link_rate
|| !link_cfg
->lane_count
|| !config
->pixel_clock
||
499 !link_cfg
->bits_per_pixel
)
502 if ((u64
)config
->pixel_clock
* link_cfg
->bits_per_pixel
>=
503 (u64
)link_rate
* 8 * link_cfg
->lane_count
)
506 num_linkclk_line
= (u32
)((u64
)link_rate
* (u64
)config
->xres
/ config
->pixel_clock
);
508 ratio_f
= (u64
)config
->pixel_clock
* link_cfg
->bits_per_pixel
* f
;
510 ratio_f
= (u64
)(ratio_f
/ (link_rate
* link_cfg
->lane_count
));
512 for (i
= 64; i
>= 32; --i
) {
513 activesym_f
= ratio_f
* i
;
514 activecount_f
= (u64
)(activesym_f
/ (u32
)f
) * f
;
515 frac_f
= activesym_f
- activecount_f
;
516 activecount
= (u32
)((u64
)(activecount_f
/ (u32
)f
));
518 if (frac_f
< (f
/ 2)) /* fraction < 0.5 */
526 frac_f
= (u64
)((f
* f
) / frac_f
); /* 1/fraction */
527 if (frac_f
> (15 * f
))
528 activefrac
= activepolarity
? 1 : 15;
530 activefrac
= activepolarity
?
531 (u32
)((u64
)(frac_f
/ (u32
)f
)) + 1 :
532 (u32
)((u64
)(frac_f
/ (u32
)f
));
538 if (activepolarity
== 1)
539 approx_value_f
= activefrac
? (u64
)(
540 (activecount_f
+ (activefrac
* f
- f
) * f
) /
544 approx_value_f
= activefrac
?
545 activecount_f
+ (u64
)(f
/ activefrac
) :
548 if (activesym_f
< approx_value_f
) {
549 accumulated_error_f
= num_linkclk_line
*
550 (u64
)((approx_value_f
- activesym_f
) / i
);
553 accumulated_error_f
= num_linkclk_line
*
554 (u64
)((activesym_f
- approx_value_f
) / i
);
558 if ((neg
&& (lowest_neg_error_f
> accumulated_error_f
)) ||
559 (accumulated_error_f
== 0)) {
560 lowest_neg_error_f
= accumulated_error_f
;
561 lowest_neg_tusize
= i
;
562 lowest_neg_activecount
= activecount
;
563 lowest_neg_activepolarity
= activepolarity
;
564 lowest_neg_activefrac
= activefrac
;
566 if (accumulated_error_f
== 0)
571 if (lowest_neg_activefrac
== 0) {
572 link_cfg
->activepolarity
= 0;
573 link_cfg
->active_count
= lowest_neg_activepolarity
?
574 lowest_neg_activecount
: lowest_neg_activecount
- 1;
575 link_cfg
->tu_size
= lowest_neg_tusize
;
576 link_cfg
->active_frac
= 1;
578 link_cfg
->activepolarity
= lowest_neg_activepolarity
;
579 link_cfg
->active_count
= (u32
)lowest_neg_activecount
;
580 link_cfg
->tu_size
= lowest_neg_tusize
;
581 link_cfg
->active_frac
= (u32
)lowest_neg_activefrac
;
584 watermark_f
= (u64
)((ratio_f
* link_cfg
->tu_size
* (f
- ratio_f
)) / f
);
585 link_cfg
->watermark
= (u32
)((u64
)((watermark_f
+ lowest_neg_error_f
) /
586 f
)) + link_cfg
->bits_per_pixel
/ 4 - 1;
587 num_symbols_per_line
= (config
->xres
* link_cfg
->bits_per_pixel
) /
588 (8 * link_cfg
->lane_count
);
590 if (link_cfg
->watermark
> 30) {
592 "dp: sor setting: unable to get a good tusize, "
593 "force watermark to 30.\n");
594 link_cfg
->watermark
= 30;
596 } else if (link_cfg
->watermark
> num_symbols_per_line
) {
598 "dp: sor setting: force watermark to the number "
599 "of symbols in the line.\n");
600 link_cfg
->watermark
= num_symbols_per_line
;
604 /* Refer to dev_disp.ref for more information. */
605 /* # symbols/hblank = ((SetRasterBlankEnd.X + SetRasterSize.Width - */
606 /* SetRasterBlankStart.X - 7) * link_clk / pclk) */
607 /* - 3 * enhanced_framing - Y */
608 /* where Y = (# lanes == 4) 3 : (# lanes == 2) ? 6 : 12 */
609 link_cfg
->hblank_sym
= (int)((u64
)(((u64
)(config
->hback_porch
+
610 config
->hfront_porch
+ config
->hsync_width
- 7) *
611 link_rate
) / config
->pixel_clock
)) -
612 3 * link_cfg
->enhanced_framing
-
613 (12 / link_cfg
->lane_count
);
615 if (link_cfg
->hblank_sym
< 0)
616 link_cfg
->hblank_sym
= 0;
618 /* Refer to dev_disp.ref for more information. */
619 /* # symbols/vblank = ((SetRasterBlankStart.X - */
620 /* SetRasterBlankEen.X - 25) * link_clk / pclk) */
622 /* where Y = (# lanes == 4) 12 : (# lanes == 2) ? 21 : 39 */
623 link_cfg
->vblank_sym
= (int)((u64
)((u64
)(config
->xres
- 25)
624 * link_rate
/ config
->pixel_clock
)) - (36 /
625 link_cfg
->lane_count
) - 4;
627 if (link_cfg
->vblank_sym
< 0)
628 link_cfg
->vblank_sym
= 0;
630 link_cfg
->is_valid
= 1;
631 tegra_dc_dp_dump_link_cfg(dp
, link_cfg
);
636 static int tegra_dc_dp_init_max_link_cfg(
637 struct soc_nvidia_tegra124_config
*config
,
638 struct tegra_dc_dp_data
*dp
,
639 struct tegra_dc_dp_link_config
*link_cfg
)
644 CHECK_RET(tegra_dc_dp_dpcd_read(dp
, NV_DPCD_MAX_LANE_COUNT
,
646 link_cfg
->max_lane_count
= dpcd_data
& NV_DPCD_MAX_LANE_COUNT_MASK
;
647 link_cfg
->tps3_supported
= (dpcd_data
&
648 NV_DPCD_MAX_LANE_COUNT_TPS3_SUPPORTED_YES
) ? 1 : 0;
650 link_cfg
->support_enhanced_framing
=
651 (dpcd_data
& NV_DPCD_MAX_LANE_COUNT_ENHANCED_FRAMING_YES
) ?
654 CHECK_RET(tegra_dc_dp_dpcd_read(dp
, NV_DPCD_MAX_DOWNSPREAD
,
656 link_cfg
->downspread
= (dpcd_data
& NV_DPCD_MAX_DOWNSPREAD_VAL_0_5_PCT
)?
659 CHECK_RET(tegra_dc_dp_dpcd_read(dp
, NV_DPCD_TRAINING_AUX_RD_INTERVAL
,
660 &link_cfg
->aux_rd_interval
));
662 CHECK_RET(tegra_dc_dp_dpcd_read(dp
, NV_DPCD_MAX_LINK_BANDWIDTH
,
663 &link_cfg
->max_link_bw
));
665 link_cfg
->bits_per_pixel
= config
->panel_bits_per_pixel
;
668 * Set to a high value for link training and attach.
669 * Will be re-programmed when dp is enabled.
671 link_cfg
->drive_current
= config
->drive_current
;
672 link_cfg
->preemphasis
= config
->preemphasis
;
673 link_cfg
->postcursor
= config
->postcursor
;
675 CHECK_RET(tegra_dc_dp_dpcd_read(dp
, NV_DPCD_EDP_CONFIG_CAP
,
677 link_cfg
->alt_scramber_reset_cap
=
678 (dpcd_data
& NV_DPCD_EDP_CONFIG_CAP_ASC_RESET_YES
) ?
680 link_cfg
->only_enhanced_framing
=
681 (dpcd_data
& NV_DPCD_EDP_CONFIG_CAP_FRAMING_CHANGE_YES
) ?
684 link_cfg
->lane_count
= link_cfg
->max_lane_count
;
685 link_cfg
->link_bw
= link_cfg
->max_link_bw
;
686 link_cfg
->enhanced_framing
= link_cfg
->support_enhanced_framing
;
688 tegra_dc_dp_calc_config(dp
, config
, link_cfg
);
692 static int tegra_dc_dp_set_assr(struct tegra_dc_dp_data
*dp
, int ena
)
697 NV_DPCD_EDP_CONFIG_SET_ASC_RESET_ENABLE
:
698 NV_DPCD_EDP_CONFIG_SET_ASC_RESET_DISABLE
;
700 CHECK_RET(tegra_dc_dp_dpcd_write(dp
, NV_DPCD_EDP_CONFIG_SET
,
703 /* Also reset the scrambler to 0xfffe */
704 tegra_dc_sor_set_internal_panel(&dp
->sor
, ena
);
708 static int tegra_dp_set_link_bandwidth(struct tegra_dc_dp_data
*dp
, u8 link_bw
)
710 tegra_dc_sor_set_link_bandwidth(&dp
->sor
, link_bw
);
713 return tegra_dc_dp_dpcd_write(dp
, NV_DPCD_LINK_BANDWIDTH_SET
, link_bw
);
716 static int tegra_dp_set_lane_count(struct tegra_dc_dp_data
*dp
,
717 const struct tegra_dc_dp_link_config
*link_cfg
)
722 /* check if panel support enhanched_framing */
723 dpcd_data
= link_cfg
->lane_count
;
724 if (link_cfg
->enhanced_framing
)
725 dpcd_data
|= NV_DPCD_LANE_COUNT_SET_ENHANCEDFRAMING_T
;
726 CHECK_RET(tegra_dc_dp_dpcd_write(dp
, NV_DPCD_LANE_COUNT_SET
,
729 tegra_dc_sor_set_lane_count(&dp
->sor
, link_cfg
->lane_count
);
731 /* Also power down lanes that will not be used */
735 static int tegra_dc_dp_link_trained(struct tegra_dc_dp_data
*dp
,
736 const struct tegra_dc_dp_link_config
*cfg
)
743 for (lane
= 0; lane
< cfg
->lane_count
; ++lane
) {
744 CHECK_RET(tegra_dc_dp_dpcd_read(dp
, (lane
/2) ?
745 NV_DPCD_LANE2_3_STATUS
: NV_DPCD_LANE0_1_STATUS
,
748 NV_DPCD_STATUS_LANEXPLUS1_CR_DONE_YES
|
749 NV_DPCD_STATUS_LANEXPLUS1_CHN_EQ_DONE_YES
|
750 NV_DPCD_STATUS_LANEXPLUS1_SYMBOL_LOCKED_YES
:
751 NV_DPCD_STATUS_LANEX_CR_DONE_YES
|
752 NV_DPCD_STATUS_LANEX_CHN_EQ_DONE_YES
|
753 NV_DPCD_STATUS_LANEX_SYMBOL_LOCKED_YES
;
754 if ((data
& mask
) != mask
)
760 static int tegra_dp_channel_eq_status(struct tegra_dc_dp_data
*dp
)
763 u32 n_lanes
= dp
->link_cfg
.lane_count
;
767 for (cnt
= 0; cnt
< n_lanes
/ 2; cnt
++) {
768 tegra_dc_dp_dpcd_read(dp
, (NV_DPCD_LANE0_1_STATUS
+ cnt
), &data
);
772 (0x1 << NV_DPCD_STATUS_LANEX_CHN_EQ_DONE_SHIFT
)) &&
773 (data
& (0x1 << NV_DPCD_STATUS_LANEX_SYMBOL_LOCKED_SHFIT
));
775 } else if (!(data
& (0x1 << NV_DPCD_STATUS_LANEX_CHN_EQ_DONE_SHIFT
)) ||
776 !(data
& (0x1 << NV_DPCD_STATUS_LANEX_SYMBOL_LOCKED_SHFIT
)) ||
777 !(data
& (0x1 << NV_DPCD_STATUS_LANEXPLUS1_CHN_EQ_DONE_SHIFT
)) ||
778 !(data
& (0x1 << NV_DPCD_STATUS_LANEXPLUS1_SYMBOL_LOCKED_SHIFT
)))
783 tegra_dc_dp_dpcd_read(dp
, NV_DPCD_LANE_ALIGN_STATUS_UPDATED
, &data
);
784 if (!(data
& NV_DPCD_LANE_ALIGN_STATUS_UPDATED_DONE_YES
))
791 static u8
tegra_dp_clock_recovery_status(struct tegra_dc_dp_data
*dp
)
794 u32 n_lanes
= dp
->link_cfg
.lane_count
;
797 for (cnt
= 0; cnt
< n_lanes
/ 2; cnt
++) {
798 tegra_dc_dp_dpcd_read(dp
,
799 (NV_DPCD_LANE0_1_STATUS
+ cnt
), &data_ptr
);
802 return (data_ptr
& NV_DPCD_STATUS_LANEX_CR_DONE_YES
) ? 1 : 0;
803 else if (!(data_ptr
& NV_DPCD_STATUS_LANEX_CR_DONE_YES
) ||
805 (NV_DPCD_STATUS_LANEXPLUS1_CR_DONE_YES
)))
812 static void tegra_dp_lt_adjust(struct tegra_dc_dp_data
*dp
,
813 u32 pe
[4], u32 vs
[4], u32 pc
[4],
818 u32 n_lanes
= dp
->link_cfg
.lane_count
;
820 for (cnt
= 0; cnt
< n_lanes
/ 2; cnt
++) {
821 tegra_dc_dp_dpcd_read(dp
,
822 (NV_DPCD_LANE0_1_ADJUST_REQ
+ cnt
), &data_ptr
);
823 pe
[2 * cnt
] = (data_ptr
& NV_DPCD_ADJUST_REQ_LANEX_PE_MASK
) >>
824 NV_DPCD_ADJUST_REQ_LANEX_PE_SHIFT
;
825 vs
[2 * cnt
] = (data_ptr
& NV_DPCD_ADJUST_REQ_LANEX_DC_MASK
) >>
826 NV_DPCD_ADJUST_REQ_LANEX_DC_SHIFT
;
828 (data_ptr
& NV_DPCD_ADJUST_REQ_LANEXPLUS1_PE_MASK
) >>
829 NV_DPCD_ADJUST_REQ_LANEXPLUS1_PE_SHIFT
;
831 (data_ptr
& NV_DPCD_ADJUST_REQ_LANEXPLUS1_DC_MASK
) >>
832 NV_DPCD_ADJUST_REQ_LANEXPLUS1_DC_SHIFT
;
835 tegra_dc_dp_dpcd_read(dp
,
836 NV_DPCD_ADJUST_REQ_POST_CURSOR2
, &data_ptr
);
837 for (cnt
= 0; cnt
< n_lanes
; cnt
++) {
838 pc
[cnt
] = (data_ptr
>>
839 NV_DPCD_ADJUST_REQ_POST_CURSOR2_LANE_SHIFT(cnt
)) &
840 NV_DPCD_ADJUST_REQ_POST_CURSOR2_LANE_MASK
;
845 static inline u32
tegra_dp_wait_aux_training(struct tegra_dc_dp_data
*dp
,
848 if (!dp
->link_cfg
.aux_rd_interval
)
849 is_clk_recovery
? udelay(200) :
852 mdelay(dp
->link_cfg
.aux_rd_interval
* 4);
854 return dp
->link_cfg
.aux_rd_interval
;
857 static void tegra_dp_tpg(struct tegra_dc_dp_data
*dp
, u32 tp
, u32 n_lanes
)
859 u8 data
= (tp
== training_pattern_disabled
)
860 ? (tp
| NV_DPCD_TRAINING_PATTERN_SET_SC_DISABLED_F
)
861 : (tp
| NV_DPCD_TRAINING_PATTERN_SET_SC_DISABLED_T
);
863 tegra_dc_sor_set_dp_linkctl(&dp
->sor
, 1, tp
, &dp
->link_cfg
);
864 tegra_dc_dp_dpcd_write(dp
, NV_DPCD_TRAINING_PATTERN_SET
, data
);
867 static int tegra_dp_link_config(struct tegra_dc_dp_data
*dp
,
868 const struct tegra_dc_dp_link_config
*link_cfg
)
873 if (link_cfg
->lane_count
== 0) {
874 printk(BIOS_ERR
, "dp: error: lane count is 0. "
875 "Can not set link config.\n");
879 /* Set power state if it is not in normal level */
880 if (tegra_dc_dp_dpcd_read(dp
, NV_DPCD_SET_POWER
, &dpcd_data
))
883 if (dpcd_data
== NV_DPCD_SET_POWER_VAL_D3_PWRDWN
) {
884 dpcd_data
= NV_DPCD_SET_POWER_VAL_D0_NORMAL
;
886 /* DP spec requires 3 retries */
887 for (retry
= 3; retry
> 0; --retry
){
888 if (tegra_dc_dp_dpcd_write(dp
, NV_DPCD_SET_POWER
, dpcd_data
))
891 printk(BIOS_ERR
, "dp: Failed to set DP panel power\n");
897 /* Enable ASSR if possible */
898 if (link_cfg
->alt_scramber_reset_cap
)
899 if (tegra_dc_dp_set_assr(dp
, 1))
902 if (tegra_dp_set_link_bandwidth(dp
, link_cfg
->link_bw
)) {
903 printk(BIOS_ERR
, "dp: Failed to set link bandwidth\n");
906 if (tegra_dp_set_lane_count(dp
, link_cfg
)) {
907 printk(BIOS_ERR
, "dp: Failed to set lane count\n");
910 tegra_dc_sor_set_dp_linkctl(&dp
->sor
, 1, training_pattern_none
,
912 return DP_LT_SUCCESS
;
915 static int tegra_dp_lower_link_config(struct tegra_dc_dp_data
*dp
,
916 struct tegra_dc_dp_link_config
*cfg
)
918 struct tegra_dc_dp_link_config tmp_cfg
;
920 tmp_cfg
= dp
->link_cfg
;
923 if (_tegra_dp_lower_link_config(dp
, cfg
))
926 if (tegra_dc_dp_calc_config(dp
, dp
->dc
->config
, cfg
))
928 tegra_dp_link_config(dp
, cfg
);
930 return DP_LT_SUCCESS
;
932 dp
->link_cfg
= tmp_cfg
;
933 tegra_dp_link_config(dp
, &tmp_cfg
);
937 static void tegra_dp_lt_config(struct tegra_dc_dp_data
*dp
,
938 u32 pe
[4], u32 vs
[4], u32 pc
[4])
940 struct tegra_dc_sor_data
*sor
= &dp
->sor
;
941 u32 n_lanes
= dp
->link_cfg
.lane_count
;
942 u8 pc_supported
= dp
->link_cfg
.tps3_supported
;
946 for (cnt
= 0; cnt
< n_lanes
; cnt
++) {
948 u32 pe_reg
, vs_reg
, pc_reg
;
953 mask
= NV_SOR_PR_LANE2_DP_LANE0_MASK
;
954 shift
= NV_SOR_PR_LANE2_DP_LANE0_SHIFT
;
957 mask
= NV_SOR_PR_LANE1_DP_LANE1_MASK
;
958 shift
= NV_SOR_PR_LANE1_DP_LANE1_SHIFT
;
961 mask
= NV_SOR_PR_LANE0_DP_LANE2_MASK
;
962 shift
= NV_SOR_PR_LANE0_DP_LANE2_SHIFT
;
965 mask
= NV_SOR_PR_LANE3_DP_LANE3_MASK
;
966 shift
= NV_SOR_PR_LANE3_DP_LANE3_SHIFT
;
970 "dp: incorrect lane cnt\n");
973 pe_reg
= tegra_dp_pe_regs
[pc
[cnt
]][vs
[cnt
]][pe
[cnt
]];
974 vs_reg
= tegra_dp_vs_regs
[pc
[cnt
]][vs
[cnt
]][pe
[cnt
]];
975 pc_reg
= tegra_dp_pc_regs
[pc
[cnt
]][vs
[cnt
]][pe
[cnt
]];
977 tegra_dp_set_pe_vs_pc(sor
, mask
, pe_reg
<< shift
,
978 vs_reg
<< shift
, pc_reg
<< shift
, pc_supported
);
981 tegra_dp_disable_tx_pu(&dp
->sor
);
984 for (cnt
= 0; cnt
< n_lanes
; cnt
++) {
985 u32 max_vs_flag
= tegra_dp_is_max_vs(pe
[cnt
], vs
[cnt
]);
986 u32 max_pe_flag
= tegra_dp_is_max_pe(pe
[cnt
], vs
[cnt
]);
988 val
= (vs
[cnt
] << NV_DPCD_TRAINING_LANEX_SET_DC_SHIFT
) |
990 NV_DPCD_TRAINING_LANEX_SET_DC_MAX_REACHED_T
:
991 NV_DPCD_TRAINING_LANEX_SET_DC_MAX_REACHED_F
) |
992 (pe
[cnt
] << NV_DPCD_TRAINING_LANEX_SET_PE_SHIFT
) |
994 NV_DPCD_TRAINING_LANEX_SET_PE_MAX_REACHED_T
:
995 NV_DPCD_TRAINING_LANEX_SET_PE_MAX_REACHED_F
);
996 tegra_dc_dp_dpcd_write(dp
,
997 (NV_DPCD_TRAINING_LANE0_SET
+ cnt
), val
);
1001 for (cnt
= 0; cnt
< n_lanes
/ 2; cnt
++) {
1002 u32 max_pc_flag0
= tegra_dp_is_max_pc(pc
[cnt
]);
1003 u32 max_pc_flag1
= tegra_dp_is_max_pc(pc
[cnt
+ 1]);
1004 val
= (pc
[cnt
] << NV_DPCD_LANEX_SET2_PC2_SHIFT
) |
1006 NV_DPCD_LANEX_SET2_PC2_MAX_REACHED_T
:
1007 NV_DPCD_LANEX_SET2_PC2_MAX_REACHED_F
) |
1009 NV_DPCD_LANEXPLUS1_SET2_PC2_SHIFT
) |
1011 NV_DPCD_LANEXPLUS1_SET2_PC2_MAX_REACHED_T
:
1012 NV_DPCD_LANEXPLUS1_SET2_PC2_MAX_REACHED_F
);
1013 tegra_dc_dp_dpcd_write(dp
,
1014 (NV_DPCD_TRAINING_LANE0_1_SET2
+ cnt
), val
);
1019 static int _tegra_dp_channel_eq(struct tegra_dc_dp_data
*dp
, u32 pe
[4],
1020 u32 vs
[4], u32 pc
[4], u8 pc_supported
,
1025 for (retry_cnt
= 0; retry_cnt
< 4; retry_cnt
++) {
1027 tegra_dp_lt_adjust(dp
, pe
, vs
, pc
, pc_supported
);
1028 tegra_dp_lt_config(dp
, pe
, vs
, pc
);
1031 tegra_dp_wait_aux_training(dp
, 0);
1033 if (!tegra_dp_clock_recovery_status(dp
)) {
1034 printk(BIOS_ERR
,"dp: CR failed in channel EQ sequence!\n");
1038 if (tegra_dp_channel_eq_status(dp
))
1039 return DP_LT_SUCCESS
;
1042 return DP_LT_FAILED
;
1045 static int tegra_dp_channel_eq(struct tegra_dc_dp_data
*dp
,
1046 u32 pe
[4], u32 vs
[4], u32 pc
[4])
1048 u32 n_lanes
= dp
->link_cfg
.lane_count
;
1049 u8 pc_supported
= dp
->link_cfg
.tps3_supported
;
1051 u32 tp_src
= training_pattern_2
;
1054 tp_src
= training_pattern_3
;
1056 tegra_dp_tpg(dp
, tp_src
, n_lanes
);
1058 err
= _tegra_dp_channel_eq(dp
, pe
, vs
, pc
, pc_supported
, n_lanes
);
1060 tegra_dp_tpg(dp
, training_pattern_disabled
, n_lanes
);
1065 static int _tegra_dp_clk_recovery(struct tegra_dc_dp_data
*dp
, u32 pe
[4],
1066 u32 vs
[4], u32 pc
[4], u8 pc_supported
,
1073 tegra_dp_lt_config(dp
, pe
, vs
, pc
);
1074 tegra_dp_wait_aux_training(dp
, 1);
1076 if (tegra_dp_clock_recovery_status(dp
))
1077 return DP_LT_SUCCESS
;
1079 memcpy(vs_temp
, vs
, sizeof(vs_temp
));
1080 tegra_dp_lt_adjust(dp
, pe
, vs
, pc
, pc_supported
);
1082 if (memcmp(vs_temp
, vs
, sizeof(vs_temp
)))
1086 } while (retry_cnt
< 5);
1088 return DP_LT_FAILED
;
1091 static int tegra_dp_clk_recovery(struct tegra_dc_dp_data
*dp
,
1092 u32 pe
[4], u32 vs
[4], u32 pc
[4])
1094 u32 n_lanes
= dp
->link_cfg
.lane_count
;
1095 u8 pc_supported
= dp
->link_cfg
.tps3_supported
;
1098 tegra_dp_tpg(dp
, training_pattern_1
, n_lanes
);
1100 err
= _tegra_dp_clk_recovery(dp
, pe
, vs
, pc
, pc_supported
, n_lanes
);
1102 tegra_dp_tpg(dp
, training_pattern_disabled
, n_lanes
);
1107 static int tegra_dc_dp_full_link_training(struct tegra_dc_dp_data
*dp
)
1109 struct tegra_dc_sor_data
*sor
= &dp
->sor
;
1111 u32 pe
[4], vs
[4], pc
[4];
1113 tegra_sor_precharge_lanes(sor
);
1116 memset(pe
, preEmphasis_Disabled
, sizeof(pe
));
1117 memset(vs
, driveCurrent_Level0
, sizeof(vs
));
1118 memset(pc
, postCursor2_Level0
, sizeof(pc
));
1120 err
= tegra_dp_clk_recovery(dp
, pe
, vs
, pc
);
1121 if (err
!= DP_LT_SUCCESS
) {
1122 if (!tegra_dp_lower_link_config(dp
, &dp
->link_cfg
))
1125 printk(BIOS_ERR
, "dp: clk recovery failed\n");
1129 err
= tegra_dp_channel_eq(dp
, pe
, vs
, pc
);
1130 if (err
!= DP_LT_SUCCESS
) {
1131 if (!tegra_dp_lower_link_config(dp
, &dp
->link_cfg
))
1135 "dp: channel equalization failed\n");
1139 tegra_dc_dp_dump_link_cfg(dp
, &dp
->link_cfg
);
1147 * All link training functions are ported from kernel dc driver.
1148 * See more details at drivers/video/tegra/dc/dp.c
1150 static int tegra_dc_dp_fast_link_training(struct tegra_dc_dp_data
*dp
,
1151 const struct tegra_dc_dp_link_config
*link_cfg
)
1153 struct tegra_dc_sor_data
*sor
= &dp
->sor
;
1161 u32 mask
= 0xffff >> ((4 - link_cfg
->lane_count
) * 4);
1163 tegra_dc_sor_set_lane_parm(sor
, link_cfg
);
1164 tegra_dc_dp_dpcd_write(dp
, NV_DPCD_MAIN_LINK_CHANNEL_CODING_SET
,
1165 NV_DPCD_MAIN_LINK_CHANNEL_CODING_SET_ANSI_8B10B
);
1168 tegra_dc_sor_set_dp_linkctl(sor
, 1, training_pattern_1
, link_cfg
);
1169 tegra_dc_dp_dpcd_write(dp
, NV_DPCD_TRAINING_PATTERN_SET
,
1170 NV_DPCD_TRAINING_PATTERN_SET_TPS_TP1
);
1172 for (j
= 0; j
< link_cfg
->lane_count
; ++j
)
1173 tegra_dc_dp_dpcd_write(dp
, NV_DPCD_TRAINING_LANE0_SET
+ j
,
1177 size
= sizeof(data16
);
1178 tegra_dc_dpaux_read(dp
, DPAUX_DP_AUXCTL_CMD_AUXRD
,
1179 NV_DPCD_LANE0_1_STATUS
, (u8
*)&data16
, &size
, &status
);
1180 status
= mask
& 0x1111;
1181 if ((data16
& status
) != status
) {
1183 "dp: Link training error for TP1 (%#x)\n", data16
);
1188 tegra_dc_dp_set_assr(dp
, link_cfg
->scramble_ena
);
1189 tegra_dc_sor_set_dp_linkctl(sor
, 1, training_pattern_3
, link_cfg
);
1191 tegra_dc_dp_dpcd_write(dp
, NV_DPCD_TRAINING_PATTERN_SET
,
1192 link_cfg
->link_bw
== 20 ? 0x23 : 0x22);
1193 for (j
= 0; j
< link_cfg
->lane_count
; ++j
)
1194 tegra_dc_dp_dpcd_write(dp
, NV_DPCD_TRAINING_LANE0_SET
+ j
,
1198 size
= sizeof(data32
);
1199 tegra_dc_dpaux_read(dp
, DPAUX_DP_AUXCTL_CMD_AUXRD
,
1200 NV_DPCD_LANE0_1_STATUS
, (u8
*)&data32
, &size
, &status
);
1201 if ((data32
& mask
) != (0x7777 & mask
)) {
1203 "dp: Link training error for TP2/3 (0x%x)\n", data32
);
1207 tegra_dc_sor_set_dp_linkctl(sor
, 1, training_pattern_disabled
,
1209 tegra_dc_dp_dpcd_write(dp
, NV_DPCD_TRAINING_PATTERN_SET
, 0);
1211 if (tegra_dc_dp_link_trained(dp
, link_cfg
)) {
1212 tegra_dc_sor_read_link_config(&dp
->sor
, &link_bw
,
1215 "Fast link trainging failed, link bw %d, lane # %d\n",
1216 link_bw
, lane_count
);
1221 "Fast link trainging succeeded, link bw %d, lane %d\n",
1222 link_cfg
->link_bw
, link_cfg
->lane_count
);
1227 static int tegra_dp_do_link_training(struct tegra_dc_dp_data
*dp
,
1228 const struct tegra_dc_dp_link_config
*link_cfg
)
1234 /* Now do the fast link training for eDP */
1235 ret
= tegra_dc_dp_fast_link_training(dp
, link_cfg
);
1237 printk(BIOS_ERR
, "dp: fast link training failed\n");
1239 /* Try full link training then */
1240 if (tegra_dc_dp_full_link_training(dp
)){
1241 printk(BIOS_ERR
, "dp: full link training failed\n");
1245 /* set to a known-good drive setting if fast link succeeded */
1246 tegra_dc_sor_set_voltage_swing(&dp
->sor
);
1249 /* Everything goes well, double check the link config */
1250 /* TODO: record edc/c2 data for debugging */
1251 tegra_dc_sor_read_link_config(&dp
->sor
, &link_bw
, &lane_count
);
1253 if ((link_cfg
->link_bw
== link_bw
) &&
1254 (link_cfg
->lane_count
== lane_count
))
1260 static int tegra_dc_dp_explore_link_cfg(struct tegra_dc_dp_data
*dp
,
1261 struct tegra_dc_dp_link_config
*link_cfg
,
1262 const struct soc_nvidia_tegra124_config
*config
)
1264 struct tegra_dc_dp_link_config temp_cfg
;
1266 if (!config
->pixel_clock
|| !config
->xres
|| !config
->yres
) {
1268 "dp: error mode configuration");
1271 if (!link_cfg
->max_link_bw
|| !link_cfg
->max_lane_count
) {
1273 "dp: error link configuration");
1277 link_cfg
->is_valid
= 0;
1279 memcpy(&temp_cfg
, link_cfg
, sizeof(temp_cfg
));
1281 temp_cfg
.link_bw
= temp_cfg
.max_link_bw
;
1282 temp_cfg
.lane_count
= temp_cfg
.max_lane_count
;
1285 * set to max link config
1287 if ((!tegra_dc_dp_calc_config(dp
, config
, &temp_cfg
)) &&
1288 (!tegra_dp_link_config(dp
, &temp_cfg
)) &&
1289 (!tegra_dp_do_link_training(dp
, &temp_cfg
)))
1290 /* the max link cfg is doable */
1291 memcpy(link_cfg
, &temp_cfg
, sizeof(temp_cfg
));
1293 return link_cfg
->is_valid
? 0 : -EFAULT
;
1296 static void tegra_dp_update_config(struct tegra_dc_dp_data
*dp
,
1297 struct soc_nvidia_tegra124_config
*config
)
1301 u32 size
= sizeof(buf
), aux_stat
= 0;
1303 tegra_dc_dpaux_enable(dp
);
1304 if (tegra_dc_i2c_aux_read(dp
, TEGRA_EDID_I2C_ADDRESS
, 0, buf
, &size
,
1306 printk(BIOS_ERR
, "%s: Failed to read EDID. Use defaults.\n",
1311 if (decode_edid(buf
, sizeof(buf
), &edid
) != EDID_CONFORMANT
) {
1312 printk(BIOS_ERR
, "%s: Failed to decode EDID. Use defaults.\n",
1317 config
->xres
= edid
.mode
.ha
;
1318 config
->yres
= edid
.mode
.va
;
1319 config
->pixel_clock
= edid
.mode
.pixel_clock
* 1000;
1321 config
->hfront_porch
= edid
.mode
.hso
;
1322 config
->hsync_width
= edid
.mode
.hspw
;
1323 config
->hback_porch
= edid
.mode
.hbl
- edid
.mode
.hso
- edid
.mode
.hspw
;
1325 config
->vfront_porch
= edid
.mode
.vso
;
1326 config
->vsync_width
= edid
.mode
.vspw
;
1327 config
->vback_porch
= edid
.mode
.vbl
- edid
.mode
.vso
- edid
.mode
.vspw
;
1330 * Note edid->framebuffer_bits_per_pixel is currently hard-coded as 32,
1331 * so we should keep the default value in device config.
1333 * EDID v1.3 panels may not have color depth info, so we need to check
1334 * if these values are zero before updating config.
1336 if (edid
.panel_bits_per_pixel
)
1337 config
->panel_bits_per_pixel
= edid
.panel_bits_per_pixel
;
1338 if (edid
.panel_bits_per_color
)
1339 config
->color_depth
= edid
.panel_bits_per_color
;
1340 printk(BIOS_SPEW
, "%s: configuration updated by EDID.\n", __func__
);
1343 void dp_init(void *_config
)
1345 struct soc_nvidia_tegra124_config
*config
= (void *)_config
;
1346 struct tegra_dc
*dc
= config
->dc_data
;
1347 struct tegra_dc_dp_data
*dp
= &dp_data
;
1349 // set up links among config, dc, dp and sor
1354 dp
->sor
.power_is_up
= 0;
1355 dp
->sor
.base
= (void *)TEGRA_ARM_SOR
;
1356 dp
->sor
.pmc_base
= (void *)TEGRA_PMC_BASE
;
1357 dp
->sor
.portnum
= 0;
1358 dp
->sor
.link_cfg
= &dp
->link_cfg
;
1359 dp
->aux_base
= (void *)TEGRA_ARM_DPAUX
;
1360 dp
->link_cfg
.is_valid
= 0;
1363 tegra_dp_update_config(dp
, config
);
1366 static void tegra_dp_hpd_config(struct tegra_dc_dp_data
*dp
,
1367 struct soc_nvidia_tegra124_config
*config
)
1371 val
= config
->hpd_plug_min_us
|
1372 (config
->hpd_unplug_min_us
<<
1373 DPAUX_HPD_CONFIG_UNPLUG_MIN_TIME_SHIFT
);
1374 tegra_dpaux_writel(dp
, DPAUX_HPD_CONFIG
, val
);
1376 tegra_dpaux_writel(dp
, DPAUX_HPD_IRQ_CONFIG
, config
->hpd_irq_min_us
);
1379 static int tegra_dp_hpd_plug(struct tegra_dc_dp_data
*dp
, int timeout_ms
)
1382 u32 timeout
= timeout_ms
* 1000;
1384 val
= tegra_dpaux_readl(dp
, DPAUX_DP_AUXSTAT
);
1385 if (val
& DPAUX_DP_AUXSTAT_HPD_STATUS_PLUGGED
)
1389 } while (timeout
> 0);
1393 void dp_enable(void *_dp
)
1395 struct tegra_dc_dp_data
*dp
= _dp
;
1396 struct tegra_dc
*dc
= dp
->dc
;
1397 struct soc_nvidia_tegra124_config
*config
= dc
->config
;
1403 tegra_dc_dpaux_enable(dp
);
1405 tegra_dp_hpd_config(dp
, config
);
1406 if (tegra_dp_hpd_plug(dp
, config
->vdd_to_hpd_delay_ms
) < 0) {
1407 printk(BIOS_ERR
, "dp: hpd plug failed\n");
1411 if (tegra_dc_dp_init_max_link_cfg(config
, dp
, &dp
->link_cfg
)) {
1412 printk(BIOS_ERR
, "dp: failed to init link configuration\n");
1416 tegra_dc_sor_enable_dp(&dp
->sor
);
1418 tegra_dc_sor_set_panel_power(&dp
->sor
, 1);
1420 /* Write power on to DPCD */
1421 data
= NV_DPCD_SET_POWER_VAL_D0_NORMAL
;
1424 ret
= tegra_dc_dp_dpcd_write(dp
,
1425 NV_DPCD_SET_POWER
, data
);
1426 } while ((retry
++ < DP_POWER_ON_MAX_TRIES
) && ret
);
1428 if (ret
|| retry
>= DP_POWER_ON_MAX_TRIES
) {
1430 "dp: failed to power on panel (0x%x)\n", ret
);
1434 /* Confirm DP is plugging status */
1435 if (!(tegra_dpaux_readl(dp
, DPAUX_DP_AUXSTAT
) &
1436 DPAUX_DP_AUXSTAT_HPD_STATUS_PLUGGED
)) {
1437 printk(BIOS_ERR
, "dp: could not detect HPD\n");
1441 /* Check DP version */
1442 if (tegra_dc_dp_dpcd_read(dp
, NV_DPCD_REV
, &dp
->revision
))
1444 "dp: failed to read the revision number from sink\n");
1446 if (tegra_dc_dp_explore_link_cfg(dp
, &dp
->link_cfg
, config
)) {
1447 printk(BIOS_ERR
, "dp: error to configure link\n");
1451 tegra_dc_sor_set_power_state(&dp
->sor
, 1);
1452 tegra_dc_sor_attach(&dp
->sor
);
1455 * Power down the unused lanes to save power
1456 * (about hundreds milli-watts, varies from boards).
1458 tegra_dc_sor_power_down_unused_lanes(&dp
->sor
);