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>
21 #include "exynos_dp_lowlevel.h"
23 DECLARE_GLOBAL_DATA_PTR;
25 void __exynos_set_dp_phy(unsigned int onoff)
28 void exynos_set_dp_phy(unsigned int onoff)
29 __attribute__((weak, alias("__exynos_set_dp_phy")));
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(void)
46 /* SW defined function Normal operation */
47 exynos_dp_enable_sw_func(DP_ENABLE);
49 ret = exynos_dp_init_analog_func();
50 if (ret != EXYNOS_DP_SUCCESS)
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(void)
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(I2C_EDID_DEVICE_ADDR, EDID_EXTENSION_FLAG,
88 if (extend_block > 0) {
89 printf("DP EDID data includes a single extension!\n");
92 retval = exynos_dp_read_bytes_from_i2c(I2C_EDID_DEVICE_ADDR,
95 &edid[EDID_HEADER_PATTERN]);
97 printf("DP EDID Read failed!\n");
100 sum = exynos_dp_calc_edid_check_sum(edid);
102 printf("DP EDID bad checksum!\n");
106 /* Read additional EDID data */
107 retval = exynos_dp_read_bytes_from_i2c(I2C_EDID_DEVICE_ADDR,
110 &edid[EDID_BLOCK_LENGTH]);
112 printf("DP EDID Read failed!\n");
115 sum = exynos_dp_calc_edid_check_sum(&edid[EDID_BLOCK_LENGTH]);
117 printf("DP EDID bad checksum!\n");
121 exynos_dp_read_byte_from_dpcd(DPCD_TEST_REQUEST,
123 if (test_vector & DPCD_TEST_EDID_READ) {
124 exynos_dp_write_byte_to_dpcd(DPCD_TEST_EDID_CHECKSUM,
125 edid[EDID_BLOCK_LENGTH + EDID_CHECKSUM]);
126 exynos_dp_write_byte_to_dpcd(DPCD_TEST_RESPONSE,
127 DPCD_TEST_EDID_CHECKSUM_WRITE);
130 debug("DP EDID data does not include any extensions.\n");
133 retval = exynos_dp_read_bytes_from_i2c(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(DPCD_TEST_REQUEST,
150 if (test_vector & DPCD_TEST_EDID_READ) {
151 exynos_dp_write_byte_to_dpcd(DPCD_TEST_EDID_CHECKSUM,
152 edid[EDID_CHECKSUM]);
153 exynos_dp_write_byte_to_dpcd(DPCD_TEST_RESPONSE,
154 DPCD_TEST_EDID_CHECKSUM_WRITE);
158 debug("DP EDID Read success!\n");
163 static unsigned int exynos_dp_handle_edid(struct edp_device_info *edp_info)
165 unsigned char buf[12];
168 unsigned char retry_cnt;
169 unsigned char dpcd_rev[16];
170 unsigned char lane_bw[16];
171 unsigned char lane_cnt[16];
173 memset(dpcd_rev, 0, 16);
174 memset(lane_bw, 0, 16);
175 memset(lane_cnt, 0, 16);
180 /* Read DPCD 0x0000-0x000b */
181 ret = exynos_dp_read_bytes_from_dpcd(DPCD_DPCD_REV, 12,
183 if (ret != EXYNOS_DP_SUCCESS) {
184 if (retry_cnt == 0) {
185 printf("DP read_byte_from_dpcd() failed\n");
194 temp = buf[DPCD_DPCD_REV];
195 if (temp == DP_DPCD_REV_10 || temp == DP_DPCD_REV_11)
196 edp_info->dpcd_rev = temp;
198 printf("DP Wrong DPCD Rev : %x\n", temp);
202 temp = buf[DPCD_MAX_LINK_RATE];
203 if (temp == DP_LANE_BW_1_62 || temp == DP_LANE_BW_2_70)
204 edp_info->lane_bw = temp;
206 printf("DP Wrong MAX LINK RATE : %x\n", temp);
210 /* Refer VESA Display Port Standard Ver1.1a Page 120 */
211 if (edp_info->dpcd_rev == DP_DPCD_REV_11) {
212 temp = buf[DPCD_MAX_LANE_COUNT] & 0x1f;
213 if (buf[DPCD_MAX_LANE_COUNT] & 0x80)
214 edp_info->dpcd_efc = 1;
216 edp_info->dpcd_efc = 0;
218 temp = buf[DPCD_MAX_LANE_COUNT];
219 edp_info->dpcd_efc = 0;
222 if (temp == DP_LANE_CNT_1 || temp == DP_LANE_CNT_2 ||
223 temp == DP_LANE_CNT_4) {
224 edp_info->lane_cnt = temp;
226 printf("DP Wrong MAX LANE COUNT : %x\n", temp);
230 ret = exynos_dp_read_edid();
231 if (ret != EXYNOS_DP_SUCCESS) {
232 printf("DP exynos_dp_read_edid() failed\n");
239 static void exynos_dp_init_training(void)
242 * MACRO_RST must be applied after the PLL_LOCK to avoid
243 * the DP inter pair skew issue for at least 10 us
245 exynos_dp_reset_macro();
247 /* All DP analog module power up */
248 exynos_dp_set_analog_power_down(POWER_ALL, 0);
251 static unsigned int exynos_dp_link_start(struct edp_device_info *edp_info)
253 unsigned char buf[5];
254 unsigned int ret = 0;
256 debug("DP: %s was called\n", __func__);
258 edp_info->lt_info.lt_status = DP_LT_CR;
259 edp_info->lt_info.ep_loop = 0;
260 edp_info->lt_info.cr_loop[0] = 0;
261 edp_info->lt_info.cr_loop[1] = 0;
262 edp_info->lt_info.cr_loop[2] = 0;
263 edp_info->lt_info.cr_loop[3] = 0;
265 /* Set sink to D0 (Sink Not Ready) mode. */
266 ret = exynos_dp_write_byte_to_dpcd(DPCD_SINK_POWER_STATE,
267 DPCD_SET_POWER_STATE_D0);
268 if (ret != EXYNOS_DP_SUCCESS) {
269 printf("DP write_dpcd_byte failed\n");
273 /* Set link rate and count as you want to establish */
274 exynos_dp_set_link_bandwidth(edp_info->lane_bw);
275 exynos_dp_set_lane_count(edp_info->lane_cnt);
277 /* Setup RX configuration */
278 buf[0] = edp_info->lane_bw;
279 buf[1] = edp_info->lane_cnt;
281 ret = exynos_dp_write_bytes_to_dpcd(DPCD_LINK_BW_SET, 2,
283 if (ret != EXYNOS_DP_SUCCESS) {
284 printf("DP write_dpcd_byte failed\n");
288 exynos_dp_set_lane_pre_emphasis(PRE_EMPHASIS_LEVEL_0,
291 /* Set training pattern 1 */
292 exynos_dp_set_training_pattern(TRAINING_PTN1);
294 /* Set RX training pattern */
295 buf[0] = DPCD_SCRAMBLING_DISABLED | DPCD_TRAINING_PATTERN_1;
297 buf[1] = DPCD_PRE_EMPHASIS_SET_PATTERN_2_LEVEL_0 |
298 DPCD_VOLTAGE_SWING_SET_PATTERN_1_LEVEL_0;
299 buf[2] = DPCD_PRE_EMPHASIS_SET_PATTERN_2_LEVEL_0 |
300 DPCD_VOLTAGE_SWING_SET_PATTERN_1_LEVEL_0;
301 buf[3] = DPCD_PRE_EMPHASIS_SET_PATTERN_2_LEVEL_0 |
302 DPCD_VOLTAGE_SWING_SET_PATTERN_1_LEVEL_0;
303 buf[4] = DPCD_PRE_EMPHASIS_SET_PATTERN_2_LEVEL_0 |
304 DPCD_VOLTAGE_SWING_SET_PATTERN_1_LEVEL_0;
306 ret = exynos_dp_write_bytes_to_dpcd(DPCD_TRAINING_PATTERN_SET,
308 if (ret != EXYNOS_DP_SUCCESS) {
309 printf("DP write_dpcd_byte failed\n");
316 static unsigned int exynos_dp_training_pattern_dis(void)
318 unsigned int ret = EXYNOS_DP_SUCCESS;
320 exynos_dp_set_training_pattern(DP_NONE);
322 ret = exynos_dp_write_byte_to_dpcd(DPCD_TRAINING_PATTERN_SET,
323 DPCD_TRAINING_PATTERN_DISABLED);
324 if (ret != EXYNOS_DP_SUCCESS) {
325 printf("DP request_link_training_req failed\n");
332 static unsigned int exynos_dp_enable_rx_to_enhanced_mode(unsigned char enable)
335 unsigned int ret = EXYNOS_DP_SUCCESS;
337 ret = exynos_dp_read_byte_from_dpcd(DPCD_LANE_COUNT_SET,
339 if (ret != EXYNOS_DP_SUCCESS) {
340 printf("DP read_from_dpcd failed\n");
345 data = DPCD_ENHANCED_FRAME_EN | DPCD_LN_COUNT_SET(data);
347 data = DPCD_LN_COUNT_SET(data);
349 ret = exynos_dp_write_byte_to_dpcd(DPCD_LANE_COUNT_SET,
351 if (ret != EXYNOS_DP_SUCCESS) {
352 printf("DP write_to_dpcd failed\n");
360 static unsigned int exynos_dp_set_enhanced_mode(unsigned char enhance_mode)
362 unsigned int ret = EXYNOS_DP_SUCCESS;
364 ret = exynos_dp_enable_rx_to_enhanced_mode(enhance_mode);
365 if (ret != EXYNOS_DP_SUCCESS) {
366 printf("DP rx_enhance_mode failed\n");
370 exynos_dp_enable_enhanced_mode(enhance_mode);
375 static int exynos_dp_read_dpcd_lane_stat(struct edp_device_info *edp_info,
376 unsigned char *status)
379 unsigned char buf[2];
380 unsigned char lane_stat[DP_LANE_CNT_4] = {0,};
381 unsigned char shift_val[DP_LANE_CNT_4] = {0,};
388 ret = exynos_dp_read_bytes_from_dpcd(DPCD_LANE0_1_STATUS, 2, buf);
389 if (ret != EXYNOS_DP_SUCCESS) {
390 printf("DP read lane status failed\n");
394 for (i = 0; i < edp_info->lane_cnt; i++) {
395 lane_stat[i] = (buf[(i / 2)] >> shift_val[i]) & 0x0f;
396 if (lane_stat[0] != lane_stat[i]) {
397 printf("Wrong lane status\n");
402 *status = lane_stat[0];
407 static unsigned int exynos_dp_read_dpcd_adj_req(unsigned char lane_num,
408 unsigned char *sw, unsigned char *em)
410 unsigned int ret = EXYNOS_DP_SUCCESS;
412 unsigned int dpcd_addr;
413 unsigned char shift_val[DP_LANE_CNT_4] = {0, 4, 0, 4};
415 /* lane_num value is used as array index, so this range 0 ~ 3 */
416 dpcd_addr = DPCD_ADJUST_REQUEST_LANE0_1 + (lane_num / 2);
418 ret = exynos_dp_read_byte_from_dpcd(dpcd_addr, &buf);
419 if (ret != EXYNOS_DP_SUCCESS) {
420 printf("DP read adjust request failed\n");
424 *sw = ((buf >> shift_val[lane_num]) & 0x03);
425 *em = ((buf >> shift_val[lane_num]) & 0x0c) >> 2;
430 static int exynos_dp_equalizer_err_link(struct edp_device_info *edp_info)
434 ret = exynos_dp_training_pattern_dis();
435 if (ret != EXYNOS_DP_SUCCESS) {
436 printf("DP training_pattern_disable() failed\n");
437 edp_info->lt_info.lt_status = DP_LT_FAIL;
440 ret = exynos_dp_set_enhanced_mode(edp_info->dpcd_efc);
441 if (ret != EXYNOS_DP_SUCCESS) {
442 printf("DP set_enhanced_mode() failed\n");
443 edp_info->lt_info.lt_status = DP_LT_FAIL;
449 static int exynos_dp_reduce_link_rate(struct edp_device_info *edp_info)
453 if (edp_info->lane_bw == DP_LANE_BW_2_70) {
454 edp_info->lane_bw = DP_LANE_BW_1_62;
455 printf("DP Change lane bw to 1.62Gbps\n");
456 edp_info->lt_info.lt_status = DP_LT_START;
457 ret = EXYNOS_DP_SUCCESS;
459 ret = exynos_dp_training_pattern_dis();
460 if (ret != EXYNOS_DP_SUCCESS)
461 printf("DP training_patter_disable() failed\n");
463 ret = exynos_dp_set_enhanced_mode(edp_info->dpcd_efc);
464 if (ret != EXYNOS_DP_SUCCESS)
465 printf("DP set_enhanced_mode() failed\n");
467 edp_info->lt_info.lt_status = DP_LT_FAIL;
473 static unsigned int exynos_dp_process_clock_recovery(struct edp_device_info
476 unsigned int ret = EXYNOS_DP_SUCCESS;
477 unsigned char lane_stat;
478 unsigned char lt_ctl_val[DP_LANE_CNT_4] = {0, };
480 unsigned char adj_req_sw;
481 unsigned char adj_req_em;
482 unsigned char buf[5];
484 debug("DP: %s was called\n", __func__);
487 ret = exynos_dp_read_dpcd_lane_stat(edp_info, &lane_stat);
488 if (ret != EXYNOS_DP_SUCCESS) {
489 printf("DP read lane status failed\n");
490 edp_info->lt_info.lt_status = DP_LT_FAIL;
494 if (lane_stat & DP_LANE_STAT_CR_DONE) {
495 debug("DP clock Recovery training succeed\n");
496 exynos_dp_set_training_pattern(TRAINING_PTN2);
498 for (i = 0; i < edp_info->lane_cnt; i++) {
499 ret = exynos_dp_read_dpcd_adj_req(i, &adj_req_sw,
501 if (ret != EXYNOS_DP_SUCCESS) {
502 edp_info->lt_info.lt_status = DP_LT_FAIL;
507 lt_ctl_val[i] = adj_req_em << 3 | adj_req_sw;
509 if ((adj_req_sw == VOLTAGE_LEVEL_3)
510 || (adj_req_em == PRE_EMPHASIS_LEVEL_3)) {
511 lt_ctl_val[i] |= MAX_DRIVE_CURRENT_REACH_3 |
512 MAX_PRE_EMPHASIS_REACH_3;
514 exynos_dp_set_lanex_pre_emphasis(lt_ctl_val[i], i);
517 buf[0] = DPCD_SCRAMBLING_DISABLED | DPCD_TRAINING_PATTERN_2;
518 buf[1] = lt_ctl_val[0];
519 buf[2] = lt_ctl_val[1];
520 buf[3] = lt_ctl_val[2];
521 buf[4] = lt_ctl_val[3];
523 ret = exynos_dp_write_bytes_to_dpcd(
524 DPCD_TRAINING_PATTERN_SET, 5, buf);
525 if (ret != EXYNOS_DP_SUCCESS) {
526 printf("DP write training pattern1 failed\n");
527 edp_info->lt_info.lt_status = DP_LT_FAIL;
530 edp_info->lt_info.lt_status = DP_LT_ET;
532 for (i = 0; i < edp_info->lane_cnt; i++) {
533 lt_ctl_val[i] = exynos_dp_get_lanex_pre_emphasis(i);
534 ret = exynos_dp_read_dpcd_adj_req(i,
535 &adj_req_sw, &adj_req_em);
536 if (ret != EXYNOS_DP_SUCCESS) {
537 printf("DP read adj req failed\n");
538 edp_info->lt_info.lt_status = DP_LT_FAIL;
542 if ((adj_req_sw == VOLTAGE_LEVEL_3) ||
543 (adj_req_em == PRE_EMPHASIS_LEVEL_3))
544 ret = exynos_dp_reduce_link_rate(edp_info);
546 if ((DRIVE_CURRENT_SET_0_GET(lt_ctl_val[i]) ==
548 (PRE_EMPHASIS_SET_0_GET(lt_ctl_val[i]) ==
550 edp_info->lt_info.cr_loop[i]++;
551 if (edp_info->lt_info.cr_loop[i] == MAX_CR_LOOP)
552 ret = exynos_dp_reduce_link_rate(
557 lt_ctl_val[i] = adj_req_em << 3 | adj_req_sw;
559 if ((adj_req_sw == VOLTAGE_LEVEL_3) ||
560 (adj_req_em == PRE_EMPHASIS_LEVEL_3)) {
561 lt_ctl_val[i] |= MAX_DRIVE_CURRENT_REACH_3 |
562 MAX_PRE_EMPHASIS_REACH_3;
564 exynos_dp_set_lanex_pre_emphasis(lt_ctl_val[i], i);
567 ret = exynos_dp_write_bytes_to_dpcd(
568 DPCD_TRAINING_LANE0_SET, 4, lt_ctl_val);
569 if (ret != EXYNOS_DP_SUCCESS) {
570 printf("DP write training pattern2 failed\n");
571 edp_info->lt_info.lt_status = DP_LT_FAIL;
579 static unsigned int exynos_dp_process_equalizer_training(struct edp_device_info
582 unsigned int ret = EXYNOS_DP_SUCCESS;
583 unsigned char lane_stat, adj_req_sw, adj_req_em, i;
584 unsigned char lt_ctl_val[DP_LANE_CNT_4] = {0,};
585 unsigned char interlane_aligned = 0;
587 unsigned char f_lane_cnt;
588 unsigned char sink_stat;
592 ret = exynos_dp_read_dpcd_lane_stat(edp_info, &lane_stat);
593 if (ret != EXYNOS_DP_SUCCESS) {
594 printf("DP read lane status failed\n");
595 edp_info->lt_info.lt_status = DP_LT_FAIL;
599 debug("DP lane stat : %x\n", lane_stat);
601 if (lane_stat & DP_LANE_STAT_CR_DONE) {
602 ret = exynos_dp_read_byte_from_dpcd(DPCD_LN_ALIGN_UPDATED,
604 if (ret != EXYNOS_DP_SUCCESS) {
605 edp_info->lt_info.lt_status = DP_LT_FAIL;
610 interlane_aligned = (sink_stat & DPCD_INTERLANE_ALIGN_DONE);
612 for (i = 0; i < edp_info->lane_cnt; i++) {
613 ret = exynos_dp_read_dpcd_adj_req(i,
614 &adj_req_sw, &adj_req_em);
615 if (ret != EXYNOS_DP_SUCCESS) {
616 printf("DP read adj req 1 failed\n");
617 edp_info->lt_info.lt_status = DP_LT_FAIL;
623 lt_ctl_val[i] = adj_req_em << 3 | adj_req_sw;
625 if ((adj_req_sw == VOLTAGE_LEVEL_3) ||
626 (adj_req_em == PRE_EMPHASIS_LEVEL_3)) {
627 lt_ctl_val[i] |= MAX_DRIVE_CURRENT_REACH_3;
628 lt_ctl_val[i] |= MAX_PRE_EMPHASIS_REACH_3;
632 if (((lane_stat&DP_LANE_STAT_CE_DONE) &&
633 (lane_stat&DP_LANE_STAT_SYM_LOCK))
634 && (interlane_aligned == DPCD_INTERLANE_ALIGN_DONE)) {
635 debug("DP Equalizer training succeed\n");
637 f_bw = exynos_dp_get_link_bandwidth();
638 f_lane_cnt = exynos_dp_get_lane_count();
640 debug("DP final BandWidth : %x\n", f_bw);
641 debug("DP final Lane Count : %x\n", f_lane_cnt);
643 edp_info->lt_info.lt_status = DP_LT_FINISHED;
645 exynos_dp_equalizer_err_link(edp_info);
648 edp_info->lt_info.ep_loop++;
650 if (edp_info->lt_info.ep_loop > MAX_EQ_LOOP) {
651 if (edp_info->lane_bw == DP_LANE_BW_2_70) {
652 ret = exynos_dp_reduce_link_rate(
655 edp_info->lt_info.lt_status =
657 exynos_dp_equalizer_err_link(edp_info);
660 for (i = 0; i < edp_info->lane_cnt; i++)
661 exynos_dp_set_lanex_pre_emphasis(
664 ret = exynos_dp_write_bytes_to_dpcd(
665 DPCD_TRAINING_LANE0_SET,
667 if (ret != EXYNOS_DP_SUCCESS) {
668 printf("DP set lt pattern failed\n");
669 edp_info->lt_info.lt_status =
671 exynos_dp_equalizer_err_link(edp_info);
675 } else if (edp_info->lane_bw == DP_LANE_BW_2_70) {
676 ret = exynos_dp_reduce_link_rate(edp_info);
678 edp_info->lt_info.lt_status = DP_LT_FAIL;
679 exynos_dp_equalizer_err_link(edp_info);
685 static unsigned int exynos_dp_sw_link_training(struct edp_device_info *edp_info)
687 unsigned int ret = 0;
688 int training_finished;
690 /* Turn off unnecessary lane */
691 if (edp_info->lane_cnt == 1)
692 exynos_dp_set_analog_power_down(CH1_BLOCK, 1);
694 training_finished = 0;
696 edp_info->lt_info.lt_status = DP_LT_START;
699 while (!training_finished) {
700 switch (edp_info->lt_info.lt_status) {
702 ret = exynos_dp_link_start(edp_info);
703 if (ret != EXYNOS_DP_SUCCESS) {
704 printf("DP LT:link start failed\n");
709 ret = exynos_dp_process_clock_recovery(edp_info);
710 if (ret != EXYNOS_DP_SUCCESS) {
711 printf("DP LT:clock recovery failed\n");
716 ret = exynos_dp_process_equalizer_training(edp_info);
717 if (ret != EXYNOS_DP_SUCCESS) {
718 printf("DP LT:equalizer training failed\n");
723 training_finished = 1;
733 static unsigned int exynos_dp_set_link_train(struct edp_device_info *edp_info)
737 exynos_dp_init_training();
739 ret = exynos_dp_sw_link_training(edp_info);
740 if (ret != EXYNOS_DP_SUCCESS)
741 printf("DP dp_sw_link_training() failed\n");
746 static void exynos_dp_enable_scramble(unsigned int enable)
751 exynos_dp_enable_scrambling(DP_ENABLE);
753 exynos_dp_read_byte_from_dpcd(DPCD_TRAINING_PATTERN_SET,
755 exynos_dp_write_byte_to_dpcd(DPCD_TRAINING_PATTERN_SET,
756 (u8)(data & ~DPCD_SCRAMBLING_DISABLED));
758 exynos_dp_enable_scrambling(DP_DISABLE);
759 exynos_dp_read_byte_from_dpcd(DPCD_TRAINING_PATTERN_SET,
761 exynos_dp_write_byte_to_dpcd(DPCD_TRAINING_PATTERN_SET,
762 (u8)(data | DPCD_SCRAMBLING_DISABLED));
766 static unsigned int exynos_dp_config_video(struct edp_device_info *edp_info)
768 unsigned int ret = 0;
769 unsigned int retry_cnt;
773 if (edp_info->video_info.master_mode) {
774 printf("DP does not support master mode\n");
778 exynos_dp_config_video_slave_mode(&edp_info->video_info);
781 exynos_dp_set_video_color_format(&edp_info->video_info);
783 if (edp_info->video_info.bist_mode) {
784 if (exynos_dp_config_video_bist(edp_info) != 0)
788 ret = exynos_dp_get_pll_lock_status();
789 if (ret != PLL_LOCKED) {
790 printf("DP PLL is not locked yet\n");
794 if (edp_info->video_info.master_mode == 0) {
797 ret = exynos_dp_is_slave_video_stream_clock_on();
798 if (ret != EXYNOS_DP_SUCCESS) {
799 if (retry_cnt == 0) {
800 printf("DP stream_clock_on failed\n");
810 /* Set to use the register calculated M/N video */
811 exynos_dp_set_video_cr_mn(CALCULATED_M, 0, 0);
813 /* For video bist, Video timing must be generated by register */
814 exynos_dp_set_video_timing_mode(VIDEO_TIMING_FROM_CAPTURE);
816 /* Enable video bist */
817 if (edp_info->video_info.bist_pattern != COLOR_RAMP &&
818 edp_info->video_info.bist_pattern != BALCK_WHITE_V_LINES &&
819 edp_info->video_info.bist_pattern != COLOR_SQUARE)
820 exynos_dp_enable_video_bist(edp_info->video_info.bist_mode);
822 exynos_dp_enable_video_bist(DP_DISABLE);
824 /* Disable video mute */
825 exynos_dp_enable_video_mute(DP_DISABLE);
827 /* Configure video Master or Slave mode */
828 exynos_dp_enable_video_master(edp_info->video_info.master_mode);
831 exynos_dp_start_video();
833 if (edp_info->video_info.master_mode == 0) {
836 ret = exynos_dp_is_video_stream_on();
837 if (ret != EXYNOS_DP_SUCCESS) {
838 if (retry_cnt == 0) {
839 printf("DP Timeout of video stream\n");
852 int exynos_dp_parse_dt(const void *blob, struct edp_device_info *edp_info)
854 unsigned int node = fdtdec_next_compatible(blob, 0,
855 COMPAT_SAMSUNG_EXYNOS5_DP);
857 debug("exynos_dp: Can't get device node for dp\n");
861 edp_info->disp_info.h_res = fdtdec_get_int(blob, node,
863 edp_info->disp_info.h_sync_width = fdtdec_get_int(blob, node,
864 "samsung,h-sync-width", 0);
865 edp_info->disp_info.h_back_porch = fdtdec_get_int(blob, node,
866 "samsung,h-back-porch", 0);
867 edp_info->disp_info.h_front_porch = fdtdec_get_int(blob, node,
868 "samsung,h-front-porch", 0);
869 edp_info->disp_info.v_res = fdtdec_get_int(blob, node,
871 edp_info->disp_info.v_sync_width = fdtdec_get_int(blob, node,
872 "samsung,v-sync-width", 0);
873 edp_info->disp_info.v_back_porch = fdtdec_get_int(blob, node,
874 "samsung,v-back-porch", 0);
875 edp_info->disp_info.v_front_porch = fdtdec_get_int(blob, node,
876 "samsung,v-front-porch", 0);
877 edp_info->disp_info.v_sync_rate = fdtdec_get_int(blob, node,
878 "samsung,v-sync-rate", 0);
880 edp_info->lt_info.lt_status = fdtdec_get_int(blob, node,
881 "samsung,lt-status", 0);
883 edp_info->video_info.master_mode = fdtdec_get_int(blob, node,
884 "samsung,master-mode", 0);
885 edp_info->video_info.bist_mode = fdtdec_get_int(blob, node,
886 "samsung,bist-mode", 0);
887 edp_info->video_info.bist_pattern = fdtdec_get_int(blob, node,
888 "samsung,bist-pattern", 0);
889 edp_info->video_info.h_sync_polarity = fdtdec_get_int(blob, node,
890 "samsung,h-sync-polarity", 0);
891 edp_info->video_info.v_sync_polarity = fdtdec_get_int(blob, node,
892 "samsung,v-sync-polarity", 0);
893 edp_info->video_info.interlaced = fdtdec_get_int(blob, node,
894 "samsung,interlaced", 0);
895 edp_info->video_info.color_space = fdtdec_get_int(blob, node,
896 "samsung,color-space", 0);
897 edp_info->video_info.dynamic_range = fdtdec_get_int(blob, node,
898 "samsung,dynamic-range", 0);
899 edp_info->video_info.ycbcr_coeff = fdtdec_get_int(blob, node,
900 "samsung,ycbcr-coeff", 0);
901 edp_info->video_info.color_depth = fdtdec_get_int(blob, node,
902 "samsung,color-depth", 0);
906 unsigned int exynos_init_dp(void)
909 struct edp_device_info *edp_info;
911 edp_info = kzalloc(sizeof(struct edp_device_info), GFP_KERNEL);
913 debug("failed to allocate edp device object.\n");
917 if (exynos_dp_parse_dt(gd->fdt_blob, edp_info))
918 debug("unable to parse DP DT node\n");
920 exynos_dp_set_base_addr();
922 exynos_dp_disp_info(&edp_info->disp_info);
924 exynos_set_dp_phy(1);
926 ret = exynos_dp_init_dp();
927 if (ret != EXYNOS_DP_SUCCESS) {
928 printf("DP exynos_dp_init_dp() failed\n");
932 ret = exynos_dp_handle_edid(edp_info);
933 if (ret != EXYNOS_DP_SUCCESS) {
934 printf("EDP handle_edid fail\n");
938 ret = exynos_dp_set_link_train(edp_info);
939 if (ret != EXYNOS_DP_SUCCESS) {
940 printf("DP link training fail\n");
944 exynos_dp_enable_scramble(DP_ENABLE);
945 exynos_dp_enable_rx_to_enhanced_mode(DP_ENABLE);
946 exynos_dp_enable_enhanced_mode(DP_ENABLE);
948 exynos_dp_set_link_bandwidth(edp_info->lane_bw);
949 exynos_dp_set_lane_count(edp_info->lane_cnt);
951 exynos_dp_init_video();
952 ret = exynos_dp_config_video(edp_info);
953 if (ret != EXYNOS_DP_SUCCESS) {
954 printf("Exynos DP init failed\n");
958 debug("Exynos DP init done\n");