1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (C) 2012 Samsung Electronics
5 * Author: Donghwa Lee <dh09.lee@samsung.com>
14 #include <linux/delay.h>
15 #include <linux/libfdt.h>
17 #include <video_bridge.h>
18 #include <linux/compat.h>
19 #include <linux/err.h>
20 #include <asm/arch/clk.h>
21 #include <asm/arch/cpu.h>
22 #include <asm/arch/dp_info.h>
23 #include <asm/arch/dp.h>
24 #include <asm/arch/pinmux.h>
25 #include <asm/arch/power.h>
27 #include "exynos_dp_lowlevel.h"
29 DECLARE_GLOBAL_DATA_PTR;
31 static void exynos_dp_disp_info(struct edp_disp_info *disp_info)
33 disp_info->h_total = disp_info->h_res + disp_info->h_sync_width +
34 disp_info->h_back_porch + disp_info->h_front_porch;
35 disp_info->v_total = disp_info->v_res + disp_info->v_sync_width +
36 disp_info->v_back_porch + disp_info->v_front_porch;
41 static int exynos_dp_init_dp(struct exynos_dp *regs)
44 exynos_dp_reset(regs);
46 /* SW defined function Normal operation */
47 exynos_dp_enable_sw_func(regs, DP_ENABLE);
49 ret = exynos_dp_init_analog_func(regs);
50 if (ret != EXYNOS_DP_SUCCESS)
53 exynos_dp_init_hpd(regs);
54 exynos_dp_init_aux(regs);
59 static unsigned char exynos_dp_calc_edid_check_sum(unsigned char *edid_data)
62 unsigned char sum = 0;
64 for (i = 0; i < EDID_BLOCK_LENGTH; i++)
65 sum = sum + edid_data[i];
70 static unsigned int exynos_dp_read_edid(struct exynos_dp *regs)
72 unsigned char edid[EDID_BLOCK_LENGTH * 2];
73 unsigned int extend_block = 0;
75 unsigned char test_vector;
79 * EDID device address is 0x50.
80 * However, if necessary, you must have set upper address
81 * into E-EDID in I2C device, 0x30.
84 /* Read Extension Flag, Number of 128-byte EDID extension blocks */
85 exynos_dp_read_byte_from_i2c(regs, I2C_EDID_DEVICE_ADDR,
86 EDID_EXTENSION_FLAG, &extend_block);
88 if (extend_block > 0) {
89 printf("DP EDID data includes a single extension!\n");
92 retval = exynos_dp_read_bytes_from_i2c(regs,
96 &edid[EDID_HEADER_PATTERN]);
98 printf("DP EDID Read failed!\n");
101 sum = exynos_dp_calc_edid_check_sum(edid);
103 printf("DP EDID bad checksum!\n");
107 /* Read additional EDID data */
108 retval = exynos_dp_read_bytes_from_i2c(regs,
109 I2C_EDID_DEVICE_ADDR,
112 &edid[EDID_BLOCK_LENGTH]);
114 printf("DP EDID Read failed!\n");
117 sum = exynos_dp_calc_edid_check_sum(&edid[EDID_BLOCK_LENGTH]);
119 printf("DP EDID bad checksum!\n");
123 exynos_dp_read_byte_from_dpcd(regs, DPCD_TEST_REQUEST,
125 if (test_vector & DPCD_TEST_EDID_READ) {
126 exynos_dp_write_byte_to_dpcd(regs,
127 DPCD_TEST_EDID_CHECKSUM,
128 edid[EDID_BLOCK_LENGTH + EDID_CHECKSUM]);
129 exynos_dp_write_byte_to_dpcd(regs,
131 DPCD_TEST_EDID_CHECKSUM_WRITE);
134 debug("DP EDID data does not include any extensions.\n");
137 retval = exynos_dp_read_bytes_from_i2c(regs,
138 I2C_EDID_DEVICE_ADDR,
141 &edid[EDID_HEADER_PATTERN]);
144 printf("DP EDID Read failed!\n");
147 sum = exynos_dp_calc_edid_check_sum(edid);
149 printf("DP EDID bad checksum!\n");
153 exynos_dp_read_byte_from_dpcd(regs, DPCD_TEST_REQUEST,
155 if (test_vector & DPCD_TEST_EDID_READ) {
156 exynos_dp_write_byte_to_dpcd(regs,
157 DPCD_TEST_EDID_CHECKSUM, edid[EDID_CHECKSUM]);
158 exynos_dp_write_byte_to_dpcd(regs,
160 DPCD_TEST_EDID_CHECKSUM_WRITE);
164 debug("DP EDID Read success!\n");
169 static unsigned int exynos_dp_handle_edid(struct exynos_dp *regs,
170 struct exynos_dp_priv *priv)
172 unsigned char buf[12];
175 unsigned char retry_cnt;
176 unsigned char dpcd_rev[16];
177 unsigned char lane_bw[16];
178 unsigned char lane_cnt[16];
180 memset(dpcd_rev, 0, 16);
181 memset(lane_bw, 0, 16);
182 memset(lane_cnt, 0, 16);
187 /* Read DPCD 0x0000-0x000b */
188 ret = exynos_dp_read_bytes_from_dpcd(regs, DPCD_DPCD_REV, 12,
190 if (ret != EXYNOS_DP_SUCCESS) {
191 if (retry_cnt == 0) {
192 printf("DP read_byte_from_dpcd() failed\n");
201 temp = buf[DPCD_DPCD_REV];
202 if (temp == DP_DPCD_REV_10 || temp == DP_DPCD_REV_11)
203 priv->dpcd_rev = temp;
205 printf("DP Wrong DPCD Rev : %x\n", temp);
209 temp = buf[DPCD_MAX_LINK_RATE];
210 if (temp == DP_LANE_BW_1_62 || temp == DP_LANE_BW_2_70)
211 priv->lane_bw = temp;
213 printf("DP Wrong MAX LINK RATE : %x\n", temp);
217 /* Refer VESA Display Port Standard Ver1.1a Page 120 */
218 if (priv->dpcd_rev == DP_DPCD_REV_11) {
219 temp = buf[DPCD_MAX_LANE_COUNT] & 0x1f;
220 if (buf[DPCD_MAX_LANE_COUNT] & 0x80)
225 temp = buf[DPCD_MAX_LANE_COUNT];
229 if (temp == DP_LANE_CNT_1 || temp == DP_LANE_CNT_2 ||
230 temp == DP_LANE_CNT_4) {
231 priv->lane_cnt = temp;
233 printf("DP Wrong MAX LANE COUNT : %x\n", temp);
237 ret = exynos_dp_read_edid(regs);
238 if (ret != EXYNOS_DP_SUCCESS) {
239 printf("DP exynos_dp_read_edid() failed\n");
246 static void exynos_dp_init_training(struct exynos_dp *regs)
249 * MACRO_RST must be applied after the PLL_LOCK to avoid
250 * the DP inter pair skew issue for at least 10 us
252 exynos_dp_reset_macro(regs);
254 /* All DP analog module power up */
255 exynos_dp_set_analog_power_down(regs, POWER_ALL, 0);
258 static unsigned int exynos_dp_link_start(struct exynos_dp *regs,
259 struct exynos_dp_priv *priv)
261 unsigned char buf[5];
262 unsigned int ret = 0;
264 debug("DP: %s was called\n", __func__);
266 priv->lt_info.lt_status = DP_LT_CR;
267 priv->lt_info.ep_loop = 0;
268 priv->lt_info.cr_loop[0] = 0;
269 priv->lt_info.cr_loop[1] = 0;
270 priv->lt_info.cr_loop[2] = 0;
271 priv->lt_info.cr_loop[3] = 0;
273 /* Set sink to D0 (Sink Not Ready) mode. */
274 ret = exynos_dp_write_byte_to_dpcd(regs, DPCD_SINK_POWER_STATE,
275 DPCD_SET_POWER_STATE_D0);
276 if (ret != EXYNOS_DP_SUCCESS) {
277 printf("DP write_dpcd_byte failed\n");
281 /* Set link rate and count as you want to establish */
282 exynos_dp_set_link_bandwidth(regs, priv->lane_bw);
283 exynos_dp_set_lane_count(regs, priv->lane_cnt);
285 /* Setup RX configuration */
286 buf[0] = priv->lane_bw;
287 buf[1] = priv->lane_cnt;
289 ret = exynos_dp_write_bytes_to_dpcd(regs, DPCD_LINK_BW_SET, 2, buf);
290 if (ret != EXYNOS_DP_SUCCESS) {
291 printf("DP write_dpcd_byte failed\n");
295 exynos_dp_set_lane_pre_emphasis(regs, PRE_EMPHASIS_LEVEL_0,
298 /* Set training pattern 1 */
299 exynos_dp_set_training_pattern(regs, TRAINING_PTN1);
301 /* Set RX training pattern */
302 buf[0] = DPCD_SCRAMBLING_DISABLED | DPCD_TRAINING_PATTERN_1;
304 buf[1] = DPCD_PRE_EMPHASIS_SET_PATTERN_2_LEVEL_0 |
305 DPCD_VOLTAGE_SWING_SET_PATTERN_1_LEVEL_0;
306 buf[2] = DPCD_PRE_EMPHASIS_SET_PATTERN_2_LEVEL_0 |
307 DPCD_VOLTAGE_SWING_SET_PATTERN_1_LEVEL_0;
308 buf[3] = DPCD_PRE_EMPHASIS_SET_PATTERN_2_LEVEL_0 |
309 DPCD_VOLTAGE_SWING_SET_PATTERN_1_LEVEL_0;
310 buf[4] = DPCD_PRE_EMPHASIS_SET_PATTERN_2_LEVEL_0 |
311 DPCD_VOLTAGE_SWING_SET_PATTERN_1_LEVEL_0;
313 ret = exynos_dp_write_bytes_to_dpcd(regs, DPCD_TRAINING_PATTERN_SET,
315 if (ret != EXYNOS_DP_SUCCESS) {
316 printf("DP write_dpcd_byte failed\n");
323 static unsigned int exynos_dp_training_pattern_dis(struct exynos_dp *regs)
327 exynos_dp_set_training_pattern(regs, DP_NONE);
329 ret = exynos_dp_write_byte_to_dpcd(regs, DPCD_TRAINING_PATTERN_SET,
330 DPCD_TRAINING_PATTERN_DISABLED);
331 if (ret != EXYNOS_DP_SUCCESS) {
332 printf("DP request_link_training_req failed\n");
339 static unsigned int exynos_dp_enable_rx_to_enhanced_mode(
340 struct exynos_dp *regs, unsigned char enable)
345 ret = exynos_dp_read_byte_from_dpcd(regs, DPCD_LANE_COUNT_SET,
347 if (ret != EXYNOS_DP_SUCCESS) {
348 printf("DP read_from_dpcd failed\n");
353 data = DPCD_ENHANCED_FRAME_EN | DPCD_LN_COUNT_SET(data);
355 data = DPCD_LN_COUNT_SET(data);
357 ret = exynos_dp_write_byte_to_dpcd(regs, DPCD_LANE_COUNT_SET, data);
358 if (ret != EXYNOS_DP_SUCCESS) {
359 printf("DP write_to_dpcd failed\n");
367 static unsigned int exynos_dp_set_enhanced_mode(struct exynos_dp *regs,
368 unsigned char enhance_mode)
372 ret = exynos_dp_enable_rx_to_enhanced_mode(regs, enhance_mode);
373 if (ret != EXYNOS_DP_SUCCESS) {
374 printf("DP rx_enhance_mode failed\n");
378 exynos_dp_enable_enhanced_mode(regs, enhance_mode);
383 static int exynos_dp_read_dpcd_lane_stat(struct exynos_dp *regs,
384 struct exynos_dp_priv *priv,
385 unsigned char *status)
388 unsigned char buf[2];
389 unsigned char lane_stat[DP_LANE_CNT_4] = {0,};
390 unsigned char shift_val[DP_LANE_CNT_4] = {0,};
397 ret = exynos_dp_read_bytes_from_dpcd(regs, DPCD_LANE0_1_STATUS, 2,
399 if (ret != EXYNOS_DP_SUCCESS) {
400 printf("DP read lane status failed\n");
404 for (i = 0; i < priv->lane_cnt; i++) {
405 lane_stat[i] = (buf[(i / 2)] >> shift_val[i]) & 0x0f;
406 if (lane_stat[0] != lane_stat[i]) {
407 printf("Wrong lane status\n");
412 *status = lane_stat[0];
417 static unsigned int exynos_dp_read_dpcd_adj_req(struct exynos_dp *regs,
418 unsigned char lane_num, unsigned char *sw, unsigned char *em)
422 unsigned int dpcd_addr;
423 unsigned char shift_val[DP_LANE_CNT_4] = {0, 4, 0, 4};
425 /* lane_num value is used as array index, so this range 0 ~ 3 */
426 dpcd_addr = DPCD_ADJUST_REQUEST_LANE0_1 + (lane_num / 2);
428 ret = exynos_dp_read_byte_from_dpcd(regs, dpcd_addr, &buf);
429 if (ret != EXYNOS_DP_SUCCESS) {
430 printf("DP read adjust request failed\n");
434 *sw = ((buf >> shift_val[lane_num]) & 0x03);
435 *em = ((buf >> shift_val[lane_num]) & 0x0c) >> 2;
440 static int exynos_dp_equalizer_err_link(struct exynos_dp *regs,
441 struct exynos_dp_priv *priv)
445 ret = exynos_dp_training_pattern_dis(regs);
446 if (ret != EXYNOS_DP_SUCCESS) {
447 printf("DP training_pattern_disable() failed\n");
448 priv->lt_info.lt_status = DP_LT_FAIL;
451 ret = exynos_dp_set_enhanced_mode(regs, priv->dpcd_efc);
452 if (ret != EXYNOS_DP_SUCCESS) {
453 printf("DP set_enhanced_mode() failed\n");
454 priv->lt_info.lt_status = DP_LT_FAIL;
460 static int exynos_dp_reduce_link_rate(struct exynos_dp *regs,
461 struct exynos_dp_priv *priv)
465 if (priv->lane_bw == DP_LANE_BW_2_70) {
466 priv->lane_bw = DP_LANE_BW_1_62;
467 printf("DP Change lane bw to 1.62Gbps\n");
468 priv->lt_info.lt_status = DP_LT_START;
469 ret = EXYNOS_DP_SUCCESS;
471 ret = exynos_dp_training_pattern_dis(regs);
472 if (ret != EXYNOS_DP_SUCCESS)
473 printf("DP training_patter_disable() failed\n");
475 ret = exynos_dp_set_enhanced_mode(regs, priv->dpcd_efc);
476 if (ret != EXYNOS_DP_SUCCESS)
477 printf("DP set_enhanced_mode() failed\n");
479 priv->lt_info.lt_status = DP_LT_FAIL;
485 static unsigned int exynos_dp_process_clock_recovery(struct exynos_dp *regs,
486 struct exynos_dp_priv *priv)
489 unsigned char lane_stat;
490 unsigned char lt_ctl_val[DP_LANE_CNT_4] = {0, };
492 unsigned char adj_req_sw;
493 unsigned char adj_req_em;
494 unsigned char buf[5];
496 debug("DP: %s was called\n", __func__);
499 ret = exynos_dp_read_dpcd_lane_stat(regs, priv, &lane_stat);
500 if (ret != EXYNOS_DP_SUCCESS) {
501 printf("DP read lane status failed\n");
502 priv->lt_info.lt_status = DP_LT_FAIL;
506 if (lane_stat & DP_LANE_STAT_CR_DONE) {
507 debug("DP clock Recovery training succeed\n");
508 exynos_dp_set_training_pattern(regs, TRAINING_PTN2);
510 for (i = 0; i < priv->lane_cnt; i++) {
511 ret = exynos_dp_read_dpcd_adj_req(regs, i,
512 &adj_req_sw, &adj_req_em);
513 if (ret != EXYNOS_DP_SUCCESS) {
514 priv->lt_info.lt_status = DP_LT_FAIL;
519 lt_ctl_val[i] = adj_req_em << 3 | adj_req_sw;
521 if ((adj_req_sw == VOLTAGE_LEVEL_3)
522 || (adj_req_em == PRE_EMPHASIS_LEVEL_3)) {
523 lt_ctl_val[i] |= MAX_DRIVE_CURRENT_REACH_3 |
524 MAX_PRE_EMPHASIS_REACH_3;
526 exynos_dp_set_lanex_pre_emphasis(regs,
530 buf[0] = DPCD_SCRAMBLING_DISABLED | DPCD_TRAINING_PATTERN_2;
531 buf[1] = lt_ctl_val[0];
532 buf[2] = lt_ctl_val[1];
533 buf[3] = lt_ctl_val[2];
534 buf[4] = lt_ctl_val[3];
536 ret = exynos_dp_write_bytes_to_dpcd(regs,
537 DPCD_TRAINING_PATTERN_SET, 5, buf);
538 if (ret != EXYNOS_DP_SUCCESS) {
539 printf("DP write training pattern1 failed\n");
540 priv->lt_info.lt_status = DP_LT_FAIL;
543 priv->lt_info.lt_status = DP_LT_ET;
545 for (i = 0; i < priv->lane_cnt; i++) {
546 lt_ctl_val[i] = exynos_dp_get_lanex_pre_emphasis(
548 ret = exynos_dp_read_dpcd_adj_req(regs, i,
549 &adj_req_sw, &adj_req_em);
550 if (ret != EXYNOS_DP_SUCCESS) {
551 printf("DP read adj req failed\n");
552 priv->lt_info.lt_status = DP_LT_FAIL;
556 if ((adj_req_sw == VOLTAGE_LEVEL_3) ||
557 (adj_req_em == PRE_EMPHASIS_LEVEL_3))
558 ret = exynos_dp_reduce_link_rate(regs,
561 if ((DRIVE_CURRENT_SET_0_GET(lt_ctl_val[i]) ==
563 (PRE_EMPHASIS_SET_0_GET(lt_ctl_val[i]) ==
565 priv->lt_info.cr_loop[i]++;
566 if (priv->lt_info.cr_loop[i] == MAX_CR_LOOP)
567 ret = exynos_dp_reduce_link_rate(
572 lt_ctl_val[i] = adj_req_em << 3 | adj_req_sw;
574 if ((adj_req_sw == VOLTAGE_LEVEL_3) ||
575 (adj_req_em == PRE_EMPHASIS_LEVEL_3)) {
576 lt_ctl_val[i] |= MAX_DRIVE_CURRENT_REACH_3 |
577 MAX_PRE_EMPHASIS_REACH_3;
579 exynos_dp_set_lanex_pre_emphasis(regs,
583 ret = exynos_dp_write_bytes_to_dpcd(regs,
584 DPCD_TRAINING_LANE0_SET, 4, lt_ctl_val);
585 if (ret != EXYNOS_DP_SUCCESS) {
586 printf("DP write training pattern2 failed\n");
587 priv->lt_info.lt_status = DP_LT_FAIL;
595 static unsigned int exynos_dp_process_equalizer_training(
596 struct exynos_dp *regs, struct exynos_dp_priv *priv)
599 unsigned char lane_stat, adj_req_sw, adj_req_em, i;
600 unsigned char lt_ctl_val[DP_LANE_CNT_4] = {0,};
601 unsigned char interlane_aligned = 0;
603 unsigned char f_lane_cnt;
604 unsigned char sink_stat;
608 ret = exynos_dp_read_dpcd_lane_stat(regs, priv, &lane_stat);
609 if (ret != EXYNOS_DP_SUCCESS) {
610 printf("DP read lane status failed\n");
611 priv->lt_info.lt_status = DP_LT_FAIL;
615 debug("DP lane stat : %x\n", lane_stat);
617 if (lane_stat & DP_LANE_STAT_CR_DONE) {
618 ret = exynos_dp_read_byte_from_dpcd(regs,
619 DPCD_LN_ALIGN_UPDATED,
621 if (ret != EXYNOS_DP_SUCCESS) {
622 priv->lt_info.lt_status = DP_LT_FAIL;
627 interlane_aligned = (sink_stat & DPCD_INTERLANE_ALIGN_DONE);
629 for (i = 0; i < priv->lane_cnt; i++) {
630 ret = exynos_dp_read_dpcd_adj_req(regs, i,
631 &adj_req_sw, &adj_req_em);
632 if (ret != EXYNOS_DP_SUCCESS) {
633 printf("DP read adj req 1 failed\n");
634 priv->lt_info.lt_status = DP_LT_FAIL;
640 lt_ctl_val[i] = adj_req_em << 3 | adj_req_sw;
642 if ((adj_req_sw == VOLTAGE_LEVEL_3) ||
643 (adj_req_em == PRE_EMPHASIS_LEVEL_3)) {
644 lt_ctl_val[i] |= MAX_DRIVE_CURRENT_REACH_3;
645 lt_ctl_val[i] |= MAX_PRE_EMPHASIS_REACH_3;
649 if (((lane_stat&DP_LANE_STAT_CE_DONE) &&
650 (lane_stat&DP_LANE_STAT_SYM_LOCK))
651 && (interlane_aligned == DPCD_INTERLANE_ALIGN_DONE)) {
652 debug("DP Equalizer training succeed\n");
654 f_bw = exynos_dp_get_link_bandwidth(regs);
655 f_lane_cnt = exynos_dp_get_lane_count(regs);
657 debug("DP final BandWidth : %x\n", f_bw);
658 debug("DP final Lane Count : %x\n", f_lane_cnt);
660 priv->lt_info.lt_status = DP_LT_FINISHED;
662 exynos_dp_equalizer_err_link(regs, priv);
665 priv->lt_info.ep_loop++;
667 if (priv->lt_info.ep_loop > MAX_EQ_LOOP) {
668 if (priv->lane_bw == DP_LANE_BW_2_70) {
669 ret = exynos_dp_reduce_link_rate(
672 priv->lt_info.lt_status =
674 exynos_dp_equalizer_err_link(regs,
678 for (i = 0; i < priv->lane_cnt; i++)
679 exynos_dp_set_lanex_pre_emphasis(
680 regs, lt_ctl_val[i], i);
682 ret = exynos_dp_write_bytes_to_dpcd(regs,
683 DPCD_TRAINING_LANE0_SET,
685 if (ret != EXYNOS_DP_SUCCESS) {
686 printf("DP set lt pattern failed\n");
687 priv->lt_info.lt_status =
689 exynos_dp_equalizer_err_link(regs,
694 } else if (priv->lane_bw == DP_LANE_BW_2_70) {
695 ret = exynos_dp_reduce_link_rate(regs, priv);
697 priv->lt_info.lt_status = DP_LT_FAIL;
698 exynos_dp_equalizer_err_link(regs, priv);
704 static unsigned int exynos_dp_sw_link_training(struct exynos_dp *regs,
705 struct exynos_dp_priv *priv)
707 unsigned int ret = 0;
708 int training_finished;
710 /* Turn off unnecessary lane */
711 if (priv->lane_cnt == 1)
712 exynos_dp_set_analog_power_down(regs, CH1_BLOCK, 1);
714 training_finished = 0;
716 priv->lt_info.lt_status = DP_LT_START;
719 while (!training_finished) {
720 switch (priv->lt_info.lt_status) {
722 ret = exynos_dp_link_start(regs, priv);
723 if (ret != EXYNOS_DP_SUCCESS) {
724 printf("DP LT:link start failed\n");
729 ret = exynos_dp_process_clock_recovery(regs,
731 if (ret != EXYNOS_DP_SUCCESS) {
732 printf("DP LT:clock recovery failed\n");
737 ret = exynos_dp_process_equalizer_training(regs,
739 if (ret != EXYNOS_DP_SUCCESS) {
740 printf("DP LT:equalizer training failed\n");
745 training_finished = 1;
755 static unsigned int exynos_dp_set_link_train(struct exynos_dp *regs,
756 struct exynos_dp_priv *priv)
760 exynos_dp_init_training(regs);
762 ret = exynos_dp_sw_link_training(regs, priv);
763 if (ret != EXYNOS_DP_SUCCESS)
764 printf("DP dp_sw_link_training() failed\n");
769 static void exynos_dp_enable_scramble(struct exynos_dp *regs,
775 exynos_dp_enable_scrambling(regs, DP_ENABLE);
777 exynos_dp_read_byte_from_dpcd(regs,
778 DPCD_TRAINING_PATTERN_SET, &data);
779 exynos_dp_write_byte_to_dpcd(regs, DPCD_TRAINING_PATTERN_SET,
780 (u8)(data & ~DPCD_SCRAMBLING_DISABLED));
782 exynos_dp_enable_scrambling(regs, DP_DISABLE);
783 exynos_dp_read_byte_from_dpcd(regs,
784 DPCD_TRAINING_PATTERN_SET, &data);
785 exynos_dp_write_byte_to_dpcd(regs, DPCD_TRAINING_PATTERN_SET,
786 (u8)(data | DPCD_SCRAMBLING_DISABLED));
790 static unsigned int exynos_dp_config_video(struct exynos_dp *regs,
791 struct exynos_dp_priv *priv)
793 unsigned int ret = 0;
794 unsigned int retry_cnt;
798 if (priv->video_info.master_mode) {
799 printf("DP does not support master mode\n");
803 exynos_dp_config_video_slave_mode(regs,
807 exynos_dp_set_video_color_format(regs, &priv->video_info);
809 if (priv->video_info.bist_mode) {
810 if (exynos_dp_config_video_bist(regs, priv) != 0)
814 ret = exynos_dp_get_pll_lock_status(regs);
815 if (ret != PLL_LOCKED) {
816 printf("DP PLL is not locked yet\n");
820 if (priv->video_info.master_mode == 0) {
823 ret = exynos_dp_is_slave_video_stream_clock_on(regs);
824 if (ret != EXYNOS_DP_SUCCESS) {
825 if (retry_cnt == 0) {
826 printf("DP stream_clock_on failed\n");
836 /* Set to use the register calculated M/N video */
837 exynos_dp_set_video_cr_mn(regs, CALCULATED_M, 0, 0);
839 /* For video bist, Video timing must be generated by register */
840 exynos_dp_set_video_timing_mode(regs, VIDEO_TIMING_FROM_CAPTURE);
842 /* Enable video bist */
843 if (priv->video_info.bist_pattern != COLOR_RAMP &&
844 priv->video_info.bist_pattern != BALCK_WHITE_V_LINES &&
845 priv->video_info.bist_pattern != COLOR_SQUARE)
846 exynos_dp_enable_video_bist(regs,
847 priv->video_info.bist_mode);
849 exynos_dp_enable_video_bist(regs, DP_DISABLE);
851 /* Disable video mute */
852 exynos_dp_enable_video_mute(regs, DP_DISABLE);
854 /* Configure video Master or Slave mode */
855 exynos_dp_enable_video_master(regs,
856 priv->video_info.master_mode);
859 exynos_dp_start_video(regs);
861 if (priv->video_info.master_mode == 0) {
864 ret = exynos_dp_is_video_stream_on(regs);
865 if (ret != EXYNOS_DP_SUCCESS) {
866 if (retry_cnt == 0) {
867 printf("DP Timeout of video stream\n");
880 static int exynos_dp_ofdata_to_platdata(struct udevice *dev)
882 struct exynos_dp_priv *priv = dev_get_priv(dev);
883 const void *blob = gd->fdt_blob;
884 unsigned int node = dev_of_offset(dev);
887 addr = devfdt_get_addr(dev);
888 if (addr == FDT_ADDR_T_NONE) {
889 debug("Can't get the DP base address\n");
892 priv->regs = (struct exynos_dp *)addr;
893 priv->disp_info.h_res = fdtdec_get_int(blob, node,
895 priv->disp_info.h_sync_width = fdtdec_get_int(blob, node,
896 "samsung,h-sync-width", 0);
897 priv->disp_info.h_back_porch = fdtdec_get_int(blob, node,
898 "samsung,h-back-porch", 0);
899 priv->disp_info.h_front_porch = fdtdec_get_int(blob, node,
900 "samsung,h-front-porch", 0);
901 priv->disp_info.v_res = fdtdec_get_int(blob, node,
903 priv->disp_info.v_sync_width = fdtdec_get_int(blob, node,
904 "samsung,v-sync-width", 0);
905 priv->disp_info.v_back_porch = fdtdec_get_int(blob, node,
906 "samsung,v-back-porch", 0);
907 priv->disp_info.v_front_porch = fdtdec_get_int(blob, node,
908 "samsung,v-front-porch", 0);
909 priv->disp_info.v_sync_rate = fdtdec_get_int(blob, node,
910 "samsung,v-sync-rate", 0);
912 priv->lt_info.lt_status = fdtdec_get_int(blob, node,
913 "samsung,lt-status", 0);
915 priv->video_info.master_mode = fdtdec_get_int(blob, node,
916 "samsung,master-mode", 0);
917 priv->video_info.bist_mode = fdtdec_get_int(blob, node,
918 "samsung,bist-mode", 0);
919 priv->video_info.bist_pattern = fdtdec_get_int(blob, node,
920 "samsung,bist-pattern", 0);
921 priv->video_info.h_sync_polarity = fdtdec_get_int(blob, node,
922 "samsung,h-sync-polarity", 0);
923 priv->video_info.v_sync_polarity = fdtdec_get_int(blob, node,
924 "samsung,v-sync-polarity", 0);
925 priv->video_info.interlaced = fdtdec_get_int(blob, node,
926 "samsung,interlaced", 0);
927 priv->video_info.color_space = fdtdec_get_int(blob, node,
928 "samsung,color-space", 0);
929 priv->video_info.dynamic_range = fdtdec_get_int(blob, node,
930 "samsung,dynamic-range", 0);
931 priv->video_info.ycbcr_coeff = fdtdec_get_int(blob, node,
932 "samsung,ycbcr-coeff", 0);
933 priv->video_info.color_depth = fdtdec_get_int(blob, node,
934 "samsung,color-depth", 0);
938 static int exynos_dp_bridge_init(struct udevice *dev)
940 const int max_tries = 10;
944 debug("%s\n", __func__);
945 ret = video_bridge_attach(dev);
947 debug("video bridge init failed: %d\n", ret);
952 * We need to wait for 90ms after bringing up the bridge since there
953 * is a phantom "high" on the HPD chip during its bootup. The phantom
954 * high comes within 7ms of de-asserting PD and persists for at least
955 * 15ms. The real high comes roughly 50ms after PD is de-asserted. The
956 * phantom high makes it hard for us to know when the NXP chip is up.
960 for (num_tries = 0; num_tries < max_tries; num_tries++) {
961 /* Check HPD. If it's high, or we don't have it, all is well */
962 ret = video_bridge_check_attached(dev);
963 if (!ret || ret == -ENOENT)
966 debug("%s: eDP bridge failed to come up; try %d of %d\n",
967 __func__, num_tries, max_tries);
970 /* Immediately go into bridge reset if the hp line is not high */
974 static int exynos_dp_bridge_setup(const void *blob)
976 const int max_tries = 2;
981 /* Configure I2C registers for Parade bridge */
982 ret = uclass_get_device(UCLASS_VIDEO_BRIDGE, 0, &dev);
984 debug("video bridge init failed: %d\n", ret);
988 if (strncmp(dev->driver->name, "parade", 6)) {
989 /* Mux HPHPD to the special hotplug detect mode */
990 exynos_pinmux_config(PERIPH_ID_DPHPD, 0);
993 for (num_tries = 0; num_tries < max_tries; num_tries++) {
994 ret = exynos_dp_bridge_init(dev);
997 if (num_tries == max_tries - 1)
1001 * If we're here, the bridge chip failed to initialise.
1002 * Power down the bridge in an attempt to reset.
1004 video_bridge_set_active(dev, false);
1007 * Arbitrarily wait 300ms here with DP_N low. Don't know for
1008 * sure how long we should wait, but we're being paranoid.
1015 int exynos_dp_enable(struct udevice *dev, int panel_bpp,
1016 const struct display_timing *timing)
1018 struct exynos_dp_priv *priv = dev_get_priv(dev);
1019 struct exynos_dp *regs = priv->regs;
1022 debug("%s: start\n", __func__);
1023 exynos_dp_disp_info(&priv->disp_info);
1025 ret = exynos_dp_bridge_setup(gd->fdt_blob);
1026 if (ret && ret != -ENODEV)
1027 printf("LCD bridge failed to enable: %d\n", ret);
1029 exynos_dp_phy_ctrl(1);
1031 ret = exynos_dp_init_dp(regs);
1032 if (ret != EXYNOS_DP_SUCCESS) {
1033 printf("DP exynos_dp_init_dp() failed\n");
1037 ret = exynos_dp_handle_edid(regs, priv);
1038 if (ret != EXYNOS_DP_SUCCESS) {
1039 printf("EDP handle_edid fail\n");
1043 ret = exynos_dp_set_link_train(regs, priv);
1044 if (ret != EXYNOS_DP_SUCCESS) {
1045 printf("DP link training fail\n");
1049 exynos_dp_enable_scramble(regs, DP_ENABLE);
1050 exynos_dp_enable_rx_to_enhanced_mode(regs, DP_ENABLE);
1051 exynos_dp_enable_enhanced_mode(regs, DP_ENABLE);
1053 exynos_dp_set_link_bandwidth(regs, priv->lane_bw);
1054 exynos_dp_set_lane_count(regs, priv->lane_cnt);
1056 exynos_dp_init_video(regs);
1057 ret = exynos_dp_config_video(regs, priv);
1058 if (ret != EXYNOS_DP_SUCCESS) {
1059 printf("Exynos DP init failed\n");
1063 debug("Exynos DP init done\n");
1069 static const struct dm_display_ops exynos_dp_ops = {
1070 .enable = exynos_dp_enable,
1073 static const struct udevice_id exynos_dp_ids[] = {
1074 { .compatible = "samsung,exynos5-dp" },
1078 U_BOOT_DRIVER(exynos_dp) = {
1079 .name = "exynos_dp",
1080 .id = UCLASS_DISPLAY,
1081 .of_match = exynos_dp_ids,
1082 .ops = &exynos_dp_ops,
1083 .ofdata_to_platdata = exynos_dp_ofdata_to_platdata,
1084 .priv_auto_alloc_size = sizeof(struct exynos_dp_priv),