2 * Copyright (C) 2012 Samsung Electronics
6 * SPDX-License-Identifier: GPL-2.0+
12 #include <linux/compat.h>
13 #include <linux/err.h>
14 #include <asm/arch/clk.h>
15 #include <asm/arch/cpu.h>
16 #include <asm/arch/dp_info.h>
17 #include <asm/arch/dp.h>
18 #include <asm/arch/power.h>
22 #include "exynos_dp_lowlevel.h"
24 DECLARE_GLOBAL_DATA_PTR;
26 static void exynos_dp_disp_info(struct edp_disp_info *disp_info)
28 disp_info->h_total = disp_info->h_res + disp_info->h_sync_width +
29 disp_info->h_back_porch + disp_info->h_front_porch;
30 disp_info->v_total = disp_info->v_res + disp_info->v_sync_width +
31 disp_info->v_back_porch + disp_info->v_front_porch;
36 static int exynos_dp_init_dp(struct exynos_dp *regs)
39 exynos_dp_reset(regs);
41 /* SW defined function Normal operation */
42 exynos_dp_enable_sw_func(regs, DP_ENABLE);
44 ret = exynos_dp_init_analog_func(regs);
45 if (ret != EXYNOS_DP_SUCCESS)
48 exynos_dp_init_hpd(regs);
49 exynos_dp_init_aux(regs);
54 static unsigned char exynos_dp_calc_edid_check_sum(unsigned char *edid_data)
57 unsigned char sum = 0;
59 for (i = 0; i < EDID_BLOCK_LENGTH; i++)
60 sum = sum + edid_data[i];
65 static unsigned int exynos_dp_read_edid(struct exynos_dp *regs)
67 unsigned char edid[EDID_BLOCK_LENGTH * 2];
68 unsigned int extend_block = 0;
70 unsigned char test_vector;
74 * EDID device address is 0x50.
75 * However, if necessary, you must have set upper address
76 * into E-EDID in I2C device, 0x30.
79 /* Read Extension Flag, Number of 128-byte EDID extension blocks */
80 exynos_dp_read_byte_from_i2c(regs, I2C_EDID_DEVICE_ADDR,
81 EDID_EXTENSION_FLAG, &extend_block);
83 if (extend_block > 0) {
84 printf("DP EDID data includes a single extension!\n");
87 retval = exynos_dp_read_bytes_from_i2c(regs,
91 &edid[EDID_HEADER_PATTERN]);
93 printf("DP EDID Read failed!\n");
96 sum = exynos_dp_calc_edid_check_sum(edid);
98 printf("DP EDID bad checksum!\n");
102 /* Read additional EDID data */
103 retval = exynos_dp_read_bytes_from_i2c(regs,
104 I2C_EDID_DEVICE_ADDR,
107 &edid[EDID_BLOCK_LENGTH]);
109 printf("DP EDID Read failed!\n");
112 sum = exynos_dp_calc_edid_check_sum(&edid[EDID_BLOCK_LENGTH]);
114 printf("DP EDID bad checksum!\n");
118 exynos_dp_read_byte_from_dpcd(regs, DPCD_TEST_REQUEST,
120 if (test_vector & DPCD_TEST_EDID_READ) {
121 exynos_dp_write_byte_to_dpcd(regs,
122 DPCD_TEST_EDID_CHECKSUM,
123 edid[EDID_BLOCK_LENGTH + EDID_CHECKSUM]);
124 exynos_dp_write_byte_to_dpcd(regs,
126 DPCD_TEST_EDID_CHECKSUM_WRITE);
129 debug("DP EDID data does not include any extensions.\n");
132 retval = exynos_dp_read_bytes_from_i2c(regs,
133 I2C_EDID_DEVICE_ADDR,
136 &edid[EDID_HEADER_PATTERN]);
139 printf("DP EDID Read failed!\n");
142 sum = exynos_dp_calc_edid_check_sum(edid);
144 printf("DP EDID bad checksum!\n");
148 exynos_dp_read_byte_from_dpcd(regs, DPCD_TEST_REQUEST,
150 if (test_vector & DPCD_TEST_EDID_READ) {
151 exynos_dp_write_byte_to_dpcd(regs,
152 DPCD_TEST_EDID_CHECKSUM, edid[EDID_CHECKSUM]);
153 exynos_dp_write_byte_to_dpcd(regs,
155 DPCD_TEST_EDID_CHECKSUM_WRITE);
159 debug("DP EDID Read success!\n");
164 static unsigned int exynos_dp_handle_edid(struct exynos_dp *regs,
165 struct exynos_dp_priv *priv)
167 unsigned char buf[12];
170 unsigned char retry_cnt;
171 unsigned char dpcd_rev[16];
172 unsigned char lane_bw[16];
173 unsigned char lane_cnt[16];
175 memset(dpcd_rev, 0, 16);
176 memset(lane_bw, 0, 16);
177 memset(lane_cnt, 0, 16);
182 /* Read DPCD 0x0000-0x000b */
183 ret = exynos_dp_read_bytes_from_dpcd(regs, DPCD_DPCD_REV, 12,
185 if (ret != EXYNOS_DP_SUCCESS) {
186 if (retry_cnt == 0) {
187 printf("DP read_byte_from_dpcd() failed\n");
196 temp = buf[DPCD_DPCD_REV];
197 if (temp == DP_DPCD_REV_10 || temp == DP_DPCD_REV_11)
198 priv->dpcd_rev = temp;
200 printf("DP Wrong DPCD Rev : %x\n", temp);
204 temp = buf[DPCD_MAX_LINK_RATE];
205 if (temp == DP_LANE_BW_1_62 || temp == DP_LANE_BW_2_70)
206 priv->lane_bw = temp;
208 printf("DP Wrong MAX LINK RATE : %x\n", temp);
212 /* Refer VESA Display Port Standard Ver1.1a Page 120 */
213 if (priv->dpcd_rev == DP_DPCD_REV_11) {
214 temp = buf[DPCD_MAX_LANE_COUNT] & 0x1f;
215 if (buf[DPCD_MAX_LANE_COUNT] & 0x80)
220 temp = buf[DPCD_MAX_LANE_COUNT];
224 if (temp == DP_LANE_CNT_1 || temp == DP_LANE_CNT_2 ||
225 temp == DP_LANE_CNT_4) {
226 priv->lane_cnt = temp;
228 printf("DP Wrong MAX LANE COUNT : %x\n", temp);
232 ret = exynos_dp_read_edid(regs);
233 if (ret != EXYNOS_DP_SUCCESS) {
234 printf("DP exynos_dp_read_edid() failed\n");
241 static void exynos_dp_init_training(struct exynos_dp *regs)
244 * MACRO_RST must be applied after the PLL_LOCK to avoid
245 * the DP inter pair skew issue for at least 10 us
247 exynos_dp_reset_macro(regs);
249 /* All DP analog module power up */
250 exynos_dp_set_analog_power_down(regs, POWER_ALL, 0);
253 static unsigned int exynos_dp_link_start(struct exynos_dp *regs,
254 struct exynos_dp_priv *priv)
256 unsigned char buf[5];
257 unsigned int ret = 0;
259 debug("DP: %s was called\n", __func__);
261 priv->lt_info.lt_status = DP_LT_CR;
262 priv->lt_info.ep_loop = 0;
263 priv->lt_info.cr_loop[0] = 0;
264 priv->lt_info.cr_loop[1] = 0;
265 priv->lt_info.cr_loop[2] = 0;
266 priv->lt_info.cr_loop[3] = 0;
268 /* Set sink to D0 (Sink Not Ready) mode. */
269 ret = exynos_dp_write_byte_to_dpcd(regs, DPCD_SINK_POWER_STATE,
270 DPCD_SET_POWER_STATE_D0);
271 if (ret != EXYNOS_DP_SUCCESS) {
272 printf("DP write_dpcd_byte failed\n");
276 /* Set link rate and count as you want to establish */
277 exynos_dp_set_link_bandwidth(regs, priv->lane_bw);
278 exynos_dp_set_lane_count(regs, priv->lane_cnt);
280 /* Setup RX configuration */
281 buf[0] = priv->lane_bw;
282 buf[1] = priv->lane_cnt;
284 ret = exynos_dp_write_bytes_to_dpcd(regs, DPCD_LINK_BW_SET, 2, buf);
285 if (ret != EXYNOS_DP_SUCCESS) {
286 printf("DP write_dpcd_byte failed\n");
290 exynos_dp_set_lane_pre_emphasis(regs, PRE_EMPHASIS_LEVEL_0,
293 /* Set training pattern 1 */
294 exynos_dp_set_training_pattern(regs, TRAINING_PTN1);
296 /* Set RX training pattern */
297 buf[0] = DPCD_SCRAMBLING_DISABLED | DPCD_TRAINING_PATTERN_1;
299 buf[1] = DPCD_PRE_EMPHASIS_SET_PATTERN_2_LEVEL_0 |
300 DPCD_VOLTAGE_SWING_SET_PATTERN_1_LEVEL_0;
301 buf[2] = DPCD_PRE_EMPHASIS_SET_PATTERN_2_LEVEL_0 |
302 DPCD_VOLTAGE_SWING_SET_PATTERN_1_LEVEL_0;
303 buf[3] = DPCD_PRE_EMPHASIS_SET_PATTERN_2_LEVEL_0 |
304 DPCD_VOLTAGE_SWING_SET_PATTERN_1_LEVEL_0;
305 buf[4] = DPCD_PRE_EMPHASIS_SET_PATTERN_2_LEVEL_0 |
306 DPCD_VOLTAGE_SWING_SET_PATTERN_1_LEVEL_0;
308 ret = exynos_dp_write_bytes_to_dpcd(regs, DPCD_TRAINING_PATTERN_SET,
310 if (ret != EXYNOS_DP_SUCCESS) {
311 printf("DP write_dpcd_byte failed\n");
318 static unsigned int exynos_dp_training_pattern_dis(struct exynos_dp *regs)
320 unsigned int ret = EXYNOS_DP_SUCCESS;
322 exynos_dp_set_training_pattern(regs, DP_NONE);
324 ret = exynos_dp_write_byte_to_dpcd(regs, DPCD_TRAINING_PATTERN_SET,
325 DPCD_TRAINING_PATTERN_DISABLED);
326 if (ret != EXYNOS_DP_SUCCESS) {
327 printf("DP request_link_training_req failed\n");
334 static unsigned int exynos_dp_enable_rx_to_enhanced_mode(
335 struct exynos_dp *regs, unsigned char enable)
338 unsigned int ret = EXYNOS_DP_SUCCESS;
340 ret = exynos_dp_read_byte_from_dpcd(regs, DPCD_LANE_COUNT_SET,
342 if (ret != EXYNOS_DP_SUCCESS) {
343 printf("DP read_from_dpcd failed\n");
348 data = DPCD_ENHANCED_FRAME_EN | DPCD_LN_COUNT_SET(data);
350 data = DPCD_LN_COUNT_SET(data);
352 ret = exynos_dp_write_byte_to_dpcd(regs, DPCD_LANE_COUNT_SET, data);
353 if (ret != EXYNOS_DP_SUCCESS) {
354 printf("DP write_to_dpcd failed\n");
362 static unsigned int exynos_dp_set_enhanced_mode(struct exynos_dp *regs,
363 unsigned char enhance_mode)
365 unsigned int ret = EXYNOS_DP_SUCCESS;
367 ret = exynos_dp_enable_rx_to_enhanced_mode(regs, enhance_mode);
368 if (ret != EXYNOS_DP_SUCCESS) {
369 printf("DP rx_enhance_mode failed\n");
373 exynos_dp_enable_enhanced_mode(regs, enhance_mode);
378 static int exynos_dp_read_dpcd_lane_stat(struct exynos_dp *regs,
379 struct exynos_dp_priv *priv,
380 unsigned char *status)
383 unsigned char buf[2];
384 unsigned char lane_stat[DP_LANE_CNT_4] = {0,};
385 unsigned char shift_val[DP_LANE_CNT_4] = {0,};
392 ret = exynos_dp_read_bytes_from_dpcd(regs, DPCD_LANE0_1_STATUS, 2,
394 if (ret != EXYNOS_DP_SUCCESS) {
395 printf("DP read lane status failed\n");
399 for (i = 0; i < priv->lane_cnt; i++) {
400 lane_stat[i] = (buf[(i / 2)] >> shift_val[i]) & 0x0f;
401 if (lane_stat[0] != lane_stat[i]) {
402 printf("Wrong lane status\n");
407 *status = lane_stat[0];
412 static unsigned int exynos_dp_read_dpcd_adj_req(struct exynos_dp *regs,
413 unsigned char lane_num, unsigned char *sw, unsigned char *em)
415 unsigned int ret = EXYNOS_DP_SUCCESS;
417 unsigned int dpcd_addr;
418 unsigned char shift_val[DP_LANE_CNT_4] = {0, 4, 0, 4};
420 /* lane_num value is used as array index, so this range 0 ~ 3 */
421 dpcd_addr = DPCD_ADJUST_REQUEST_LANE0_1 + (lane_num / 2);
423 ret = exynos_dp_read_byte_from_dpcd(regs, dpcd_addr, &buf);
424 if (ret != EXYNOS_DP_SUCCESS) {
425 printf("DP read adjust request failed\n");
429 *sw = ((buf >> shift_val[lane_num]) & 0x03);
430 *em = ((buf >> shift_val[lane_num]) & 0x0c) >> 2;
435 static int exynos_dp_equalizer_err_link(struct exynos_dp *regs,
436 struct exynos_dp_priv *priv)
440 ret = exynos_dp_training_pattern_dis(regs);
441 if (ret != EXYNOS_DP_SUCCESS) {
442 printf("DP training_pattern_disable() failed\n");
443 priv->lt_info.lt_status = DP_LT_FAIL;
446 ret = exynos_dp_set_enhanced_mode(regs, priv->dpcd_efc);
447 if (ret != EXYNOS_DP_SUCCESS) {
448 printf("DP set_enhanced_mode() failed\n");
449 priv->lt_info.lt_status = DP_LT_FAIL;
455 static int exynos_dp_reduce_link_rate(struct exynos_dp *regs,
456 struct exynos_dp_priv *priv)
460 if (priv->lane_bw == DP_LANE_BW_2_70) {
461 priv->lane_bw = DP_LANE_BW_1_62;
462 printf("DP Change lane bw to 1.62Gbps\n");
463 priv->lt_info.lt_status = DP_LT_START;
464 ret = EXYNOS_DP_SUCCESS;
466 ret = exynos_dp_training_pattern_dis(regs);
467 if (ret != EXYNOS_DP_SUCCESS)
468 printf("DP training_patter_disable() failed\n");
470 ret = exynos_dp_set_enhanced_mode(regs, priv->dpcd_efc);
471 if (ret != EXYNOS_DP_SUCCESS)
472 printf("DP set_enhanced_mode() failed\n");
474 priv->lt_info.lt_status = DP_LT_FAIL;
480 static unsigned int exynos_dp_process_clock_recovery(struct exynos_dp *regs,
481 struct exynos_dp_priv *priv)
483 unsigned int ret = EXYNOS_DP_SUCCESS;
484 unsigned char lane_stat;
485 unsigned char lt_ctl_val[DP_LANE_CNT_4] = {0, };
487 unsigned char adj_req_sw;
488 unsigned char adj_req_em;
489 unsigned char buf[5];
491 debug("DP: %s was called\n", __func__);
494 ret = exynos_dp_read_dpcd_lane_stat(regs, priv, &lane_stat);
495 if (ret != EXYNOS_DP_SUCCESS) {
496 printf("DP read lane status failed\n");
497 priv->lt_info.lt_status = DP_LT_FAIL;
501 if (lane_stat & DP_LANE_STAT_CR_DONE) {
502 debug("DP clock Recovery training succeed\n");
503 exynos_dp_set_training_pattern(regs, TRAINING_PTN2);
505 for (i = 0; i < priv->lane_cnt; i++) {
506 ret = exynos_dp_read_dpcd_adj_req(regs, i,
507 &adj_req_sw, &adj_req_em);
508 if (ret != EXYNOS_DP_SUCCESS) {
509 priv->lt_info.lt_status = DP_LT_FAIL;
514 lt_ctl_val[i] = adj_req_em << 3 | adj_req_sw;
516 if ((adj_req_sw == VOLTAGE_LEVEL_3)
517 || (adj_req_em == PRE_EMPHASIS_LEVEL_3)) {
518 lt_ctl_val[i] |= MAX_DRIVE_CURRENT_REACH_3 |
519 MAX_PRE_EMPHASIS_REACH_3;
521 exynos_dp_set_lanex_pre_emphasis(regs,
525 buf[0] = DPCD_SCRAMBLING_DISABLED | DPCD_TRAINING_PATTERN_2;
526 buf[1] = lt_ctl_val[0];
527 buf[2] = lt_ctl_val[1];
528 buf[3] = lt_ctl_val[2];
529 buf[4] = lt_ctl_val[3];
531 ret = exynos_dp_write_bytes_to_dpcd(regs,
532 DPCD_TRAINING_PATTERN_SET, 5, buf);
533 if (ret != EXYNOS_DP_SUCCESS) {
534 printf("DP write training pattern1 failed\n");
535 priv->lt_info.lt_status = DP_LT_FAIL;
538 priv->lt_info.lt_status = DP_LT_ET;
540 for (i = 0; i < priv->lane_cnt; i++) {
541 lt_ctl_val[i] = exynos_dp_get_lanex_pre_emphasis(
543 ret = exynos_dp_read_dpcd_adj_req(regs, i,
544 &adj_req_sw, &adj_req_em);
545 if (ret != EXYNOS_DP_SUCCESS) {
546 printf("DP read adj req failed\n");
547 priv->lt_info.lt_status = DP_LT_FAIL;
551 if ((adj_req_sw == VOLTAGE_LEVEL_3) ||
552 (adj_req_em == PRE_EMPHASIS_LEVEL_3))
553 ret = exynos_dp_reduce_link_rate(regs,
556 if ((DRIVE_CURRENT_SET_0_GET(lt_ctl_val[i]) ==
558 (PRE_EMPHASIS_SET_0_GET(lt_ctl_val[i]) ==
560 priv->lt_info.cr_loop[i]++;
561 if (priv->lt_info.cr_loop[i] == MAX_CR_LOOP)
562 ret = exynos_dp_reduce_link_rate(
567 lt_ctl_val[i] = adj_req_em << 3 | adj_req_sw;
569 if ((adj_req_sw == VOLTAGE_LEVEL_3) ||
570 (adj_req_em == PRE_EMPHASIS_LEVEL_3)) {
571 lt_ctl_val[i] |= MAX_DRIVE_CURRENT_REACH_3 |
572 MAX_PRE_EMPHASIS_REACH_3;
574 exynos_dp_set_lanex_pre_emphasis(regs,
578 ret = exynos_dp_write_bytes_to_dpcd(regs,
579 DPCD_TRAINING_LANE0_SET, 4, lt_ctl_val);
580 if (ret != EXYNOS_DP_SUCCESS) {
581 printf("DP write training pattern2 failed\n");
582 priv->lt_info.lt_status = DP_LT_FAIL;
590 static unsigned int exynos_dp_process_equalizer_training(
591 struct exynos_dp *regs, struct exynos_dp_priv *priv)
593 unsigned int ret = EXYNOS_DP_SUCCESS;
594 unsigned char lane_stat, adj_req_sw, adj_req_em, i;
595 unsigned char lt_ctl_val[DP_LANE_CNT_4] = {0,};
596 unsigned char interlane_aligned = 0;
598 unsigned char f_lane_cnt;
599 unsigned char sink_stat;
603 ret = exynos_dp_read_dpcd_lane_stat(regs, priv, &lane_stat);
604 if (ret != EXYNOS_DP_SUCCESS) {
605 printf("DP read lane status failed\n");
606 priv->lt_info.lt_status = DP_LT_FAIL;
610 debug("DP lane stat : %x\n", lane_stat);
612 if (lane_stat & DP_LANE_STAT_CR_DONE) {
613 ret = exynos_dp_read_byte_from_dpcd(regs,
614 DPCD_LN_ALIGN_UPDATED,
616 if (ret != EXYNOS_DP_SUCCESS) {
617 priv->lt_info.lt_status = DP_LT_FAIL;
622 interlane_aligned = (sink_stat & DPCD_INTERLANE_ALIGN_DONE);
624 for (i = 0; i < priv->lane_cnt; i++) {
625 ret = exynos_dp_read_dpcd_adj_req(regs, i,
626 &adj_req_sw, &adj_req_em);
627 if (ret != EXYNOS_DP_SUCCESS) {
628 printf("DP read adj req 1 failed\n");
629 priv->lt_info.lt_status = DP_LT_FAIL;
635 lt_ctl_val[i] = adj_req_em << 3 | adj_req_sw;
637 if ((adj_req_sw == VOLTAGE_LEVEL_3) ||
638 (adj_req_em == PRE_EMPHASIS_LEVEL_3)) {
639 lt_ctl_val[i] |= MAX_DRIVE_CURRENT_REACH_3;
640 lt_ctl_val[i] |= MAX_PRE_EMPHASIS_REACH_3;
644 if (((lane_stat&DP_LANE_STAT_CE_DONE) &&
645 (lane_stat&DP_LANE_STAT_SYM_LOCK))
646 && (interlane_aligned == DPCD_INTERLANE_ALIGN_DONE)) {
647 debug("DP Equalizer training succeed\n");
649 f_bw = exynos_dp_get_link_bandwidth(regs);
650 f_lane_cnt = exynos_dp_get_lane_count(regs);
652 debug("DP final BandWidth : %x\n", f_bw);
653 debug("DP final Lane Count : %x\n", f_lane_cnt);
655 priv->lt_info.lt_status = DP_LT_FINISHED;
657 exynos_dp_equalizer_err_link(regs, priv);
660 priv->lt_info.ep_loop++;
662 if (priv->lt_info.ep_loop > MAX_EQ_LOOP) {
663 if (priv->lane_bw == DP_LANE_BW_2_70) {
664 ret = exynos_dp_reduce_link_rate(
667 priv->lt_info.lt_status =
669 exynos_dp_equalizer_err_link(regs,
673 for (i = 0; i < priv->lane_cnt; i++)
674 exynos_dp_set_lanex_pre_emphasis(
675 regs, lt_ctl_val[i], i);
677 ret = exynos_dp_write_bytes_to_dpcd(regs,
678 DPCD_TRAINING_LANE0_SET,
680 if (ret != EXYNOS_DP_SUCCESS) {
681 printf("DP set lt pattern failed\n");
682 priv->lt_info.lt_status =
684 exynos_dp_equalizer_err_link(regs,
689 } else if (priv->lane_bw == DP_LANE_BW_2_70) {
690 ret = exynos_dp_reduce_link_rate(regs, priv);
692 priv->lt_info.lt_status = DP_LT_FAIL;
693 exynos_dp_equalizer_err_link(regs, priv);
699 static unsigned int exynos_dp_sw_link_training(struct exynos_dp *regs,
700 struct exynos_dp_priv *priv)
702 unsigned int ret = 0;
703 int training_finished;
705 /* Turn off unnecessary lane */
706 if (priv->lane_cnt == 1)
707 exynos_dp_set_analog_power_down(regs, CH1_BLOCK, 1);
709 training_finished = 0;
711 priv->lt_info.lt_status = DP_LT_START;
714 while (!training_finished) {
715 switch (priv->lt_info.lt_status) {
717 ret = exynos_dp_link_start(regs, priv);
718 if (ret != EXYNOS_DP_SUCCESS) {
719 printf("DP LT:link start failed\n");
724 ret = exynos_dp_process_clock_recovery(regs,
726 if (ret != EXYNOS_DP_SUCCESS) {
727 printf("DP LT:clock recovery failed\n");
732 ret = exynos_dp_process_equalizer_training(regs,
734 if (ret != EXYNOS_DP_SUCCESS) {
735 printf("DP LT:equalizer training failed\n");
740 training_finished = 1;
750 static unsigned int exynos_dp_set_link_train(struct exynos_dp *regs,
751 struct exynos_dp_priv *priv)
755 exynos_dp_init_training(regs);
757 ret = exynos_dp_sw_link_training(regs, priv);
758 if (ret != EXYNOS_DP_SUCCESS)
759 printf("DP dp_sw_link_training() failed\n");
764 static void exynos_dp_enable_scramble(struct exynos_dp *regs,
770 exynos_dp_enable_scrambling(regs, DP_ENABLE);
772 exynos_dp_read_byte_from_dpcd(regs,
773 DPCD_TRAINING_PATTERN_SET, &data);
774 exynos_dp_write_byte_to_dpcd(regs, DPCD_TRAINING_PATTERN_SET,
775 (u8)(data & ~DPCD_SCRAMBLING_DISABLED));
777 exynos_dp_enable_scrambling(regs, DP_DISABLE);
778 exynos_dp_read_byte_from_dpcd(regs,
779 DPCD_TRAINING_PATTERN_SET, &data);
780 exynos_dp_write_byte_to_dpcd(regs, DPCD_TRAINING_PATTERN_SET,
781 (u8)(data | DPCD_SCRAMBLING_DISABLED));
785 static unsigned int exynos_dp_config_video(struct exynos_dp *regs,
786 struct exynos_dp_priv *priv)
788 unsigned int ret = 0;
789 unsigned int retry_cnt;
793 if (priv->video_info.master_mode) {
794 printf("DP does not support master mode\n");
798 exynos_dp_config_video_slave_mode(regs,
802 exynos_dp_set_video_color_format(regs, &priv->video_info);
804 if (priv->video_info.bist_mode) {
805 if (exynos_dp_config_video_bist(regs, priv) != 0)
809 ret = exynos_dp_get_pll_lock_status(regs);
810 if (ret != PLL_LOCKED) {
811 printf("DP PLL is not locked yet\n");
815 if (priv->video_info.master_mode == 0) {
818 ret = exynos_dp_is_slave_video_stream_clock_on(regs);
819 if (ret != EXYNOS_DP_SUCCESS) {
820 if (retry_cnt == 0) {
821 printf("DP stream_clock_on failed\n");
831 /* Set to use the register calculated M/N video */
832 exynos_dp_set_video_cr_mn(regs, CALCULATED_M, 0, 0);
834 /* For video bist, Video timing must be generated by register */
835 exynos_dp_set_video_timing_mode(regs, VIDEO_TIMING_FROM_CAPTURE);
837 /* Enable video bist */
838 if (priv->video_info.bist_pattern != COLOR_RAMP &&
839 priv->video_info.bist_pattern != BALCK_WHITE_V_LINES &&
840 priv->video_info.bist_pattern != COLOR_SQUARE)
841 exynos_dp_enable_video_bist(regs,
842 priv->video_info.bist_mode);
844 exynos_dp_enable_video_bist(regs, DP_DISABLE);
846 /* Disable video mute */
847 exynos_dp_enable_video_mute(regs, DP_DISABLE);
849 /* Configure video Master or Slave mode */
850 exynos_dp_enable_video_master(regs,
851 priv->video_info.master_mode);
854 exynos_dp_start_video(regs);
856 if (priv->video_info.master_mode == 0) {
859 ret = exynos_dp_is_video_stream_on(regs);
860 if (ret != EXYNOS_DP_SUCCESS) {
861 if (retry_cnt == 0) {
862 printf("DP Timeout of video stream\n");
875 int exynos_dp_parse_dt(const void *blob, struct exynos_dp_priv *priv)
877 unsigned int node = fdtdec_next_compatible(blob, 0,
878 COMPAT_SAMSUNG_EXYNOS5_DP);
880 debug("exynos_dp: Can't get device node for dp\n");
884 priv->disp_info.h_res = fdtdec_get_int(blob, node,
886 priv->disp_info.h_sync_width = fdtdec_get_int(blob, node,
887 "samsung,h-sync-width", 0);
888 priv->disp_info.h_back_porch = fdtdec_get_int(blob, node,
889 "samsung,h-back-porch", 0);
890 priv->disp_info.h_front_porch = fdtdec_get_int(blob, node,
891 "samsung,h-front-porch", 0);
892 priv->disp_info.v_res = fdtdec_get_int(blob, node,
894 priv->disp_info.v_sync_width = fdtdec_get_int(blob, node,
895 "samsung,v-sync-width", 0);
896 priv->disp_info.v_back_porch = fdtdec_get_int(blob, node,
897 "samsung,v-back-porch", 0);
898 priv->disp_info.v_front_porch = fdtdec_get_int(blob, node,
899 "samsung,v-front-porch", 0);
900 priv->disp_info.v_sync_rate = fdtdec_get_int(blob, node,
901 "samsung,v-sync-rate", 0);
903 priv->lt_info.lt_status = fdtdec_get_int(blob, node,
904 "samsung,lt-status", 0);
906 priv->video_info.master_mode = fdtdec_get_int(blob, node,
907 "samsung,master-mode", 0);
908 priv->video_info.bist_mode = fdtdec_get_int(blob, node,
909 "samsung,bist-mode", 0);
910 priv->video_info.bist_pattern = fdtdec_get_int(blob, node,
911 "samsung,bist-pattern", 0);
912 priv->video_info.h_sync_polarity = fdtdec_get_int(blob, node,
913 "samsung,h-sync-polarity", 0);
914 priv->video_info.v_sync_polarity = fdtdec_get_int(blob, node,
915 "samsung,v-sync-polarity", 0);
916 priv->video_info.interlaced = fdtdec_get_int(blob, node,
917 "samsung,interlaced", 0);
918 priv->video_info.color_space = fdtdec_get_int(blob, node,
919 "samsung,color-space", 0);
920 priv->video_info.dynamic_range = fdtdec_get_int(blob, node,
921 "samsung,dynamic-range", 0);
922 priv->video_info.ycbcr_coeff = fdtdec_get_int(blob, node,
923 "samsung,ycbcr-coeff", 0);
924 priv->video_info.color_depth = fdtdec_get_int(blob, node,
925 "samsung,color-depth", 0);
929 unsigned int exynos_init_dp(void)
932 struct exynos_dp_priv *priv;
933 struct exynos_dp *regs;
936 priv = kzalloc(sizeof(struct exynos_dp_priv), GFP_KERNEL);
938 debug("failed to allocate edp device object.\n");
942 if (exynos_dp_parse_dt(gd->fdt_blob, priv))
943 debug("unable to parse DP DT node\n");
945 node = fdtdec_next_compatible(gd->fdt_blob, 0,
946 COMPAT_SAMSUNG_EXYNOS5_DP);
948 debug("exynos_dp: Can't get device node for dp\n");
950 regs = (struct exynos_dp *)fdtdec_get_addr(gd->fdt_blob, node,
953 debug("Can't get the DP base address\n");
955 exynos_dp_disp_info(&priv->disp_info);
957 exynos_dp_phy_ctrl(1);
959 ret = exynos_dp_init_dp(regs);
960 if (ret != EXYNOS_DP_SUCCESS) {
961 printf("DP exynos_dp_init_dp() failed\n");
965 ret = exynos_dp_handle_edid(regs, priv);
966 if (ret != EXYNOS_DP_SUCCESS) {
967 printf("EDP handle_edid fail\n");
971 ret = exynos_dp_set_link_train(regs, priv);
972 if (ret != EXYNOS_DP_SUCCESS) {
973 printf("DP link training fail\n");
977 exynos_dp_enable_scramble(regs, DP_ENABLE);
978 exynos_dp_enable_rx_to_enhanced_mode(regs, DP_ENABLE);
979 exynos_dp_enable_enhanced_mode(regs, DP_ENABLE);
981 exynos_dp_set_link_bandwidth(regs, priv->lane_bw);
982 exynos_dp_set_lane_count(regs, priv->lane_cnt);
984 exynos_dp_init_video(regs);
985 ret = exynos_dp_config_video(regs, priv);
986 if (ret != EXYNOS_DP_SUCCESS) {
987 printf("Exynos DP init failed\n");
991 debug("Exynos DP init done\n");