2 * Samsung SoC DP (Display Port) interface driver.
4 * Copyright (C) 2012 Samsung Electronics Co., Ltd.
5 * Author: Jingoo Han <jg1.han@samsung.com>
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2 of the License, or (at your
10 * option) any later version.
13 #include <linux/module.h>
14 #include <linux/platform_device.h>
15 #include <linux/slab.h>
16 #include <linux/err.h>
17 #include <linux/clk.h>
19 #include <linux/interrupt.h>
20 #include <linux/delay.h>
22 #include <video/exynos_dp.h>
24 #include "exynos_dp_core.h"
26 static int exynos_dp_init_dp(struct exynos_dp_device
*dp
)
30 exynos_dp_swreset(dp
);
32 /* SW defined function Normal operation */
33 exynos_dp_enable_sw_function(dp
);
35 exynos_dp_config_interrupt(dp
);
36 exynos_dp_init_analog_func(dp
);
38 exynos_dp_init_hpd(dp
);
39 exynos_dp_init_aux(dp
);
44 static int exynos_dp_detect_hpd(struct exynos_dp_device
*dp
)
48 exynos_dp_init_hpd(dp
);
50 usleep_range(200, 210);
52 while (exynos_dp_get_plug_in_status(dp
) != 0) {
54 if (DP_TIMEOUT_LOOP_COUNT
< timeout_loop
) {
55 dev_err(dp
->dev
, "failed to get hpd plug status\n");
64 static unsigned char exynos_dp_calc_edid_check_sum(unsigned char *edid_data
)
67 unsigned char sum
= 0;
69 for (i
= 0; i
< EDID_BLOCK_LENGTH
; i
++)
70 sum
= sum
+ edid_data
[i
];
75 static int exynos_dp_read_edid(struct exynos_dp_device
*dp
)
77 unsigned char edid
[EDID_BLOCK_LENGTH
* 2];
78 unsigned int extend_block
= 0;
80 unsigned char test_vector
;
84 * EDID device address is 0x50.
85 * However, if necessary, you must have set upper address
86 * into E-EDID in I2C device, 0x30.
89 /* Read Extension Flag, Number of 128-byte EDID extension blocks */
90 exynos_dp_read_byte_from_i2c(dp
, I2C_EDID_DEVICE_ADDR
,
94 if (extend_block
> 0) {
95 dev_dbg(dp
->dev
, "EDID data includes a single extension!\n");
98 retval
= exynos_dp_read_bytes_from_i2c(dp
, I2C_EDID_DEVICE_ADDR
,
101 &edid
[EDID_HEADER_PATTERN
]);
103 dev_err(dp
->dev
, "EDID Read failed!\n");
106 sum
= exynos_dp_calc_edid_check_sum(edid
);
108 dev_err(dp
->dev
, "EDID bad checksum!\n");
112 /* Read additional EDID data */
113 retval
= exynos_dp_read_bytes_from_i2c(dp
,
114 I2C_EDID_DEVICE_ADDR
,
117 &edid
[EDID_BLOCK_LENGTH
]);
119 dev_err(dp
->dev
, "EDID Read failed!\n");
122 sum
= exynos_dp_calc_edid_check_sum(&edid
[EDID_BLOCK_LENGTH
]);
124 dev_err(dp
->dev
, "EDID bad checksum!\n");
128 exynos_dp_read_byte_from_dpcd(dp
, DPCD_ADDR_TEST_REQUEST
,
130 if (test_vector
& DPCD_TEST_EDID_READ
) {
131 exynos_dp_write_byte_to_dpcd(dp
,
132 DPCD_ADDR_TEST_EDID_CHECKSUM
,
133 edid
[EDID_BLOCK_LENGTH
+ EDID_CHECKSUM
]);
134 exynos_dp_write_byte_to_dpcd(dp
,
135 DPCD_ADDR_TEST_RESPONSE
,
136 DPCD_TEST_EDID_CHECKSUM_WRITE
);
139 dev_info(dp
->dev
, "EDID data does not include any extensions.\n");
142 retval
= exynos_dp_read_bytes_from_i2c(dp
,
143 I2C_EDID_DEVICE_ADDR
,
146 &edid
[EDID_HEADER_PATTERN
]);
148 dev_err(dp
->dev
, "EDID Read failed!\n");
151 sum
= exynos_dp_calc_edid_check_sum(edid
);
153 dev_err(dp
->dev
, "EDID bad checksum!\n");
157 exynos_dp_read_byte_from_dpcd(dp
,
158 DPCD_ADDR_TEST_REQUEST
,
160 if (test_vector
& DPCD_TEST_EDID_READ
) {
161 exynos_dp_write_byte_to_dpcd(dp
,
162 DPCD_ADDR_TEST_EDID_CHECKSUM
,
163 edid
[EDID_CHECKSUM
]);
164 exynos_dp_write_byte_to_dpcd(dp
,
165 DPCD_ADDR_TEST_RESPONSE
,
166 DPCD_TEST_EDID_CHECKSUM_WRITE
);
170 dev_err(dp
->dev
, "EDID Read success!\n");
174 static int exynos_dp_handle_edid(struct exynos_dp_device
*dp
)
180 /* Read DPCD DPCD_ADDR_DPCD_REV~RECEIVE_PORT1_CAP_1 */
181 exynos_dp_read_bytes_from_dpcd(dp
,
186 for (i
= 0; i
< 3; i
++) {
187 retval
= exynos_dp_read_edid(dp
);
195 static void exynos_dp_enable_rx_to_enhanced_mode(struct exynos_dp_device
*dp
,
200 exynos_dp_read_byte_from_dpcd(dp
, DPCD_ADDR_LANE_COUNT_SET
, &data
);
203 exynos_dp_write_byte_to_dpcd(dp
, DPCD_ADDR_LANE_COUNT_SET
,
204 DPCD_ENHANCED_FRAME_EN
|
205 DPCD_LANE_COUNT_SET(data
));
207 exynos_dp_write_byte_to_dpcd(dp
, DPCD_ADDR_LANE_COUNT_SET
,
208 DPCD_LANE_COUNT_SET(data
));
211 static int exynos_dp_is_enhanced_mode_available(struct exynos_dp_device
*dp
)
216 exynos_dp_read_byte_from_dpcd(dp
, DPCD_ADDR_MAX_LANE_COUNT
, &data
);
217 retval
= DPCD_ENHANCED_FRAME_CAP(data
);
222 static void exynos_dp_set_enhanced_mode(struct exynos_dp_device
*dp
)
226 data
= exynos_dp_is_enhanced_mode_available(dp
);
227 exynos_dp_enable_rx_to_enhanced_mode(dp
, data
);
228 exynos_dp_enable_enhanced_mode(dp
, data
);
231 static void exynos_dp_training_pattern_dis(struct exynos_dp_device
*dp
)
233 exynos_dp_set_training_pattern(dp
, DP_NONE
);
235 exynos_dp_write_byte_to_dpcd(dp
,
236 DPCD_ADDR_TRAINING_PATTERN_SET
,
237 DPCD_TRAINING_PATTERN_DISABLED
);
240 static void exynos_dp_set_lane_lane_pre_emphasis(struct exynos_dp_device
*dp
,
241 int pre_emphasis
, int lane
)
245 exynos_dp_set_lane0_pre_emphasis(dp
, pre_emphasis
);
248 exynos_dp_set_lane1_pre_emphasis(dp
, pre_emphasis
);
252 exynos_dp_set_lane2_pre_emphasis(dp
, pre_emphasis
);
256 exynos_dp_set_lane3_pre_emphasis(dp
, pre_emphasis
);
261 static void exynos_dp_link_start(struct exynos_dp_device
*dp
)
267 lane_count
= dp
->link_train
.lane_count
;
269 dp
->link_train
.lt_state
= CLOCK_RECOVERY
;
270 dp
->link_train
.eq_loop
= 0;
272 for (lane
= 0; lane
< lane_count
; lane
++)
273 dp
->link_train
.cr_loop
[lane
] = 0;
275 /* Set sink to D0 (Sink Not Ready) mode. */
276 exynos_dp_write_byte_to_dpcd(dp
, DPCD_ADDR_SINK_POWER_STATE
,
277 DPCD_SET_POWER_STATE_D0
);
279 /* Set link rate and count as you want to establish*/
280 exynos_dp_set_link_bandwidth(dp
, dp
->link_train
.link_rate
);
281 exynos_dp_set_lane_count(dp
, dp
->link_train
.lane_count
);
283 /* Setup RX configuration */
284 buf
[0] = dp
->link_train
.link_rate
;
285 buf
[1] = dp
->link_train
.lane_count
;
286 exynos_dp_write_bytes_to_dpcd(dp
, DPCD_ADDR_LINK_BW_SET
,
289 /* Set TX pre-emphasis to minimum */
290 for (lane
= 0; lane
< lane_count
; lane
++)
291 exynos_dp_set_lane_lane_pre_emphasis(dp
,
292 PRE_EMPHASIS_LEVEL_0
, lane
);
294 /* Set training pattern 1 */
295 exynos_dp_set_training_pattern(dp
, TRAINING_PTN1
);
297 /* Set RX training pattern */
298 exynos_dp_write_byte_to_dpcd(dp
,
299 DPCD_ADDR_TRAINING_PATTERN_SET
,
300 DPCD_SCRAMBLING_DISABLED
|
301 DPCD_TRAINING_PATTERN_1
);
303 for (lane
= 0; lane
< lane_count
; lane
++)
304 buf
[lane
] = DPCD_PRE_EMPHASIS_PATTERN2_LEVEL0
|
305 DPCD_VOLTAGE_SWING_PATTERN1_LEVEL0
;
306 exynos_dp_write_bytes_to_dpcd(dp
,
307 DPCD_ADDR_TRAINING_LANE0_SET
,
311 static unsigned char exynos_dp_get_lane_status(u8 link_status
[2], int lane
)
313 int shift
= (lane
& 1) * 4;
314 u8 link_value
= link_status
[lane
>>1];
316 return (link_value
>> shift
) & 0xf;
319 static int exynos_dp_clock_recovery_ok(u8 link_status
[2], int lane_count
)
324 for (lane
= 0; lane
< lane_count
; lane
++) {
325 lane_status
= exynos_dp_get_lane_status(link_status
, lane
);
326 if ((lane_status
& DPCD_LANE_CR_DONE
) == 0)
332 static int exynos_dp_channel_eq_ok(u8 link_align
[3], int lane_count
)
338 lane_align
= link_align
[2];
339 if ((lane_align
& DPCD_INTERLANE_ALIGN_DONE
) == 0)
342 for (lane
= 0; lane
< lane_count
; lane
++) {
343 lane_status
= exynos_dp_get_lane_status(link_align
, lane
);
344 lane_status
&= DPCD_CHANNEL_EQ_BITS
;
345 if (lane_status
!= DPCD_CHANNEL_EQ_BITS
)
352 static unsigned char exynos_dp_get_adjust_request_voltage(u8 adjust_request
[2],
355 int shift
= (lane
& 1) * 4;
356 u8 link_value
= adjust_request
[lane
>>1];
358 return (link_value
>> shift
) & 0x3;
361 static unsigned char exynos_dp_get_adjust_request_pre_emphasis(
362 u8 adjust_request
[2],
365 int shift
= (lane
& 1) * 4;
366 u8 link_value
= adjust_request
[lane
>>1];
368 return ((link_value
>> shift
) & 0xc) >> 2;
371 static void exynos_dp_set_lane_link_training(struct exynos_dp_device
*dp
,
372 u8 training_lane_set
, int lane
)
376 exynos_dp_set_lane0_link_training(dp
, training_lane_set
);
379 exynos_dp_set_lane1_link_training(dp
, training_lane_set
);
383 exynos_dp_set_lane2_link_training(dp
, training_lane_set
);
387 exynos_dp_set_lane3_link_training(dp
, training_lane_set
);
392 static unsigned int exynos_dp_get_lane_link_training(
393 struct exynos_dp_device
*dp
,
400 reg
= exynos_dp_get_lane0_link_training(dp
);
403 reg
= exynos_dp_get_lane1_link_training(dp
);
406 reg
= exynos_dp_get_lane2_link_training(dp
);
409 reg
= exynos_dp_get_lane3_link_training(dp
);
419 static void exynos_dp_reduce_link_rate(struct exynos_dp_device
*dp
)
421 exynos_dp_training_pattern_dis(dp
);
422 exynos_dp_set_enhanced_mode(dp
);
424 dp
->link_train
.lt_state
= FAILED
;
427 static int exynos_dp_process_clock_recovery(struct exynos_dp_device
*dp
)
433 u8 adjust_request
[2];
438 usleep_range(100, 101);
440 lane_count
= dp
->link_train
.lane_count
;
442 exynos_dp_read_bytes_from_dpcd(dp
, DPCD_ADDR_LANE0_1_STATUS
,
445 if (exynos_dp_clock_recovery_ok(link_status
, lane_count
) == 0) {
446 /* set training pattern 2 for EQ */
447 exynos_dp_set_training_pattern(dp
, TRAINING_PTN2
);
449 for (lane
= 0; lane
< lane_count
; lane
++) {
450 exynos_dp_read_bytes_from_dpcd(dp
,
451 DPCD_ADDR_ADJUST_REQUEST_LANE0_1
,
453 voltage_swing
= exynos_dp_get_adjust_request_voltage(
454 adjust_request
, lane
);
455 pre_emphasis
= exynos_dp_get_adjust_request_pre_emphasis(
456 adjust_request
, lane
);
457 training_lane
= DPCD_VOLTAGE_SWING_SET(voltage_swing
) |
458 DPCD_PRE_EMPHASIS_SET(pre_emphasis
);
460 if (voltage_swing
== VOLTAGE_LEVEL_3
)
461 training_lane
|= DPCD_MAX_SWING_REACHED
;
462 if (pre_emphasis
== PRE_EMPHASIS_LEVEL_3
)
463 training_lane
|= DPCD_MAX_PRE_EMPHASIS_REACHED
;
465 dp
->link_train
.training_lane
[lane
] = training_lane
;
467 exynos_dp_set_lane_link_training(dp
,
468 dp
->link_train
.training_lane
[lane
],
472 exynos_dp_write_byte_to_dpcd(dp
,
473 DPCD_ADDR_TRAINING_PATTERN_SET
,
474 DPCD_SCRAMBLING_DISABLED
|
475 DPCD_TRAINING_PATTERN_2
);
477 exynos_dp_write_bytes_to_dpcd(dp
,
478 DPCD_ADDR_TRAINING_LANE0_SET
,
480 dp
->link_train
.training_lane
);
482 dev_info(dp
->dev
, "Link Training Clock Recovery success\n");
483 dp
->link_train
.lt_state
= EQUALIZER_TRAINING
;
485 for (lane
= 0; lane
< lane_count
; lane
++) {
486 training_lane
= exynos_dp_get_lane_link_training(
488 exynos_dp_read_bytes_from_dpcd(dp
,
489 DPCD_ADDR_ADJUST_REQUEST_LANE0_1
,
491 voltage_swing
= exynos_dp_get_adjust_request_voltage(
492 adjust_request
, lane
);
493 pre_emphasis
= exynos_dp_get_adjust_request_pre_emphasis(
494 adjust_request
, lane
);
496 if (voltage_swing
== VOLTAGE_LEVEL_3
||
497 pre_emphasis
== PRE_EMPHASIS_LEVEL_3
) {
498 dev_err(dp
->dev
, "voltage or pre emphasis reached max level\n");
499 goto reduce_link_rate
;
502 if ((DPCD_VOLTAGE_SWING_GET(training_lane
) ==
504 (DPCD_PRE_EMPHASIS_GET(training_lane
) ==
506 dp
->link_train
.cr_loop
[lane
]++;
507 if (dp
->link_train
.cr_loop
[lane
] == MAX_CR_LOOP
) {
508 dev_err(dp
->dev
, "CR Max loop\n");
509 goto reduce_link_rate
;
513 training_lane
= DPCD_VOLTAGE_SWING_SET(voltage_swing
) |
514 DPCD_PRE_EMPHASIS_SET(pre_emphasis
);
516 if (voltage_swing
== VOLTAGE_LEVEL_3
)
517 training_lane
|= DPCD_MAX_SWING_REACHED
;
518 if (pre_emphasis
== PRE_EMPHASIS_LEVEL_3
)
519 training_lane
|= DPCD_MAX_PRE_EMPHASIS_REACHED
;
521 dp
->link_train
.training_lane
[lane
] = training_lane
;
523 exynos_dp_set_lane_link_training(dp
,
524 dp
->link_train
.training_lane
[lane
], lane
);
527 exynos_dp_write_bytes_to_dpcd(dp
,
528 DPCD_ADDR_TRAINING_LANE0_SET
,
530 dp
->link_train
.training_lane
);
536 exynos_dp_reduce_link_rate(dp
);
540 static int exynos_dp_process_equalizer_training(struct exynos_dp_device
*dp
)
548 u8 adjust_request
[2];
553 usleep_range(400, 401);
555 lane_count
= dp
->link_train
.lane_count
;
557 exynos_dp_read_bytes_from_dpcd(dp
, DPCD_ADDR_LANE0_1_STATUS
,
560 if (exynos_dp_clock_recovery_ok(link_status
, lane_count
) == 0) {
561 link_align
[0] = link_status
[0];
562 link_align
[1] = link_status
[1];
564 exynos_dp_read_byte_from_dpcd(dp
,
565 DPCD_ADDR_LANE_ALIGN_STATUS_UPDATED
,
568 for (lane
= 0; lane
< lane_count
; lane
++) {
569 exynos_dp_read_bytes_from_dpcd(dp
,
570 DPCD_ADDR_ADJUST_REQUEST_LANE0_1
,
572 voltage_swing
= exynos_dp_get_adjust_request_voltage(
573 adjust_request
, lane
);
574 pre_emphasis
= exynos_dp_get_adjust_request_pre_emphasis(
575 adjust_request
, lane
);
576 training_lane
= DPCD_VOLTAGE_SWING_SET(voltage_swing
) |
577 DPCD_PRE_EMPHASIS_SET(pre_emphasis
);
579 if (voltage_swing
== VOLTAGE_LEVEL_3
)
580 training_lane
|= DPCD_MAX_SWING_REACHED
;
581 if (pre_emphasis
== PRE_EMPHASIS_LEVEL_3
)
582 training_lane
|= DPCD_MAX_PRE_EMPHASIS_REACHED
;
584 dp
->link_train
.training_lane
[lane
] = training_lane
;
587 if (exynos_dp_channel_eq_ok(link_status
, lane_count
) == 0) {
588 /* traing pattern Set to Normal */
589 exynos_dp_training_pattern_dis(dp
);
591 dev_info(dp
->dev
, "Link Training success!\n");
593 exynos_dp_get_link_bandwidth(dp
, ®
);
594 dp
->link_train
.link_rate
= reg
;
595 dev_dbg(dp
->dev
, "final bandwidth = %.2x\n",
596 dp
->link_train
.link_rate
);
598 exynos_dp_get_lane_count(dp
, ®
);
599 dp
->link_train
.lane_count
= reg
;
600 dev_dbg(dp
->dev
, "final lane count = %.2x\n",
601 dp
->link_train
.lane_count
);
603 /* set enhanced mode if available */
604 exynos_dp_set_enhanced_mode(dp
);
605 dp
->link_train
.lt_state
= FINISHED
;
608 dp
->link_train
.eq_loop
++;
610 if (dp
->link_train
.eq_loop
> MAX_EQ_LOOP
) {
611 dev_err(dp
->dev
, "EQ Max loop\n");
612 goto reduce_link_rate
;
615 for (lane
= 0; lane
< lane_count
; lane
++)
616 exynos_dp_set_lane_link_training(dp
,
617 dp
->link_train
.training_lane
[lane
],
620 exynos_dp_write_bytes_to_dpcd(dp
,
621 DPCD_ADDR_TRAINING_LANE0_SET
,
623 dp
->link_train
.training_lane
);
626 goto reduce_link_rate
;
632 exynos_dp_reduce_link_rate(dp
);
636 static void exynos_dp_get_max_rx_bandwidth(struct exynos_dp_device
*dp
,
642 * For DP rev.1.1, Maximum link rate of Main Link lanes
643 * 0x06 = 1.62 Gbps, 0x0a = 2.7 Gbps
645 exynos_dp_read_byte_from_dpcd(dp
, DPCD_ADDR_MAX_LINK_RATE
, &data
);
649 static void exynos_dp_get_max_rx_lane_count(struct exynos_dp_device
*dp
,
655 * For DP rev.1.1, Maximum number of Main Link lanes
656 * 0x01 = 1 lane, 0x02 = 2 lanes, 0x04 = 4 lanes
658 exynos_dp_read_byte_from_dpcd(dp
, DPCD_ADDR_MAX_LANE_COUNT
, &data
);
659 *lane_count
= DPCD_MAX_LANE_COUNT(data
);
662 static void exynos_dp_init_training(struct exynos_dp_device
*dp
,
663 enum link_lane_count_type max_lane
,
664 enum link_rate_type max_rate
)
667 * MACRO_RST must be applied after the PLL_LOCK to avoid
668 * the DP inter pair skew issue for at least 10 us
670 exynos_dp_reset_macro(dp
);
672 /* Initialize by reading RX's DPCD */
673 exynos_dp_get_max_rx_bandwidth(dp
, &dp
->link_train
.link_rate
);
674 exynos_dp_get_max_rx_lane_count(dp
, &dp
->link_train
.lane_count
);
676 if ((dp
->link_train
.link_rate
!= LINK_RATE_1_62GBPS
) &&
677 (dp
->link_train
.link_rate
!= LINK_RATE_2_70GBPS
)) {
678 dev_err(dp
->dev
, "Rx Max Link Rate is abnormal :%x !\n",
679 dp
->link_train
.link_rate
);
680 dp
->link_train
.link_rate
= LINK_RATE_1_62GBPS
;
683 if (dp
->link_train
.lane_count
== 0) {
684 dev_err(dp
->dev
, "Rx Max Lane count is abnormal :%x !\n",
685 dp
->link_train
.lane_count
);
686 dp
->link_train
.lane_count
= (u8
)LANE_COUNT1
;
689 /* Setup TX lane count & rate */
690 if (dp
->link_train
.lane_count
> max_lane
)
691 dp
->link_train
.lane_count
= max_lane
;
692 if (dp
->link_train
.link_rate
> max_rate
)
693 dp
->link_train
.link_rate
= max_rate
;
695 /* All DP analog module power up */
696 exynos_dp_set_analog_power_down(dp
, POWER_ALL
, 0);
699 static int exynos_dp_sw_link_training(struct exynos_dp_device
*dp
)
702 int training_finished
= 0;
704 dp
->link_train
.lt_state
= START
;
707 while (!training_finished
) {
708 switch (dp
->link_train
.lt_state
) {
710 exynos_dp_link_start(dp
);
713 retval
= exynos_dp_process_clock_recovery(dp
);
715 dev_err(dp
->dev
, "LT CR failed!\n");
717 case EQUALIZER_TRAINING
:
718 retval
= exynos_dp_process_equalizer_training(dp
);
720 dev_err(dp
->dev
, "LT EQ failed!\n");
723 training_finished
= 1;
733 static int exynos_dp_set_link_train(struct exynos_dp_device
*dp
,
740 for (i
= 0; i
< DP_TIMEOUT_LOOP_COUNT
; i
++) {
741 exynos_dp_init_training(dp
, count
, bwtype
);
742 retval
= exynos_dp_sw_link_training(dp
);
746 usleep_range(100, 110);
752 static int exynos_dp_config_video(struct exynos_dp_device
*dp
,
753 struct video_info
*video_info
)
756 int timeout_loop
= 0;
759 exynos_dp_config_video_slave_mode(dp
, video_info
);
761 exynos_dp_set_video_color_format(dp
, video_info
->color_depth
,
762 video_info
->color_space
,
763 video_info
->dynamic_range
,
764 video_info
->ycbcr_coeff
);
766 if (exynos_dp_get_pll_lock_status(dp
) == PLL_UNLOCKED
) {
767 dev_err(dp
->dev
, "PLL is not locked yet.\n");
773 if (exynos_dp_is_slave_video_stream_clock_on(dp
) == 0)
775 if (DP_TIMEOUT_LOOP_COUNT
< timeout_loop
) {
776 dev_err(dp
->dev
, "Timeout of video streamclk ok\n");
783 /* Set to use the register calculated M/N video */
784 exynos_dp_set_video_cr_mn(dp
, CALCULATED_M
, 0, 0);
786 /* For video bist, Video timing must be generated by register */
787 exynos_dp_set_video_timing_mode(dp
, VIDEO_TIMING_FROM_CAPTURE
);
789 /* Disable video mute */
790 exynos_dp_enable_video_mute(dp
, 0);
792 /* Configure video slave mode */
793 exynos_dp_enable_video_master(dp
, 0);
796 exynos_dp_start_video(dp
);
802 if (exynos_dp_is_video_stream_on(dp
) == 0) {
806 } else if (done_count
) {
809 if (DP_TIMEOUT_LOOP_COUNT
< timeout_loop
) {
810 dev_err(dp
->dev
, "Timeout of video streamclk ok\n");
814 usleep_range(1000, 1001);
818 dev_err(dp
->dev
, "Video stream is not detected!\n");
823 static void exynos_dp_enable_scramble(struct exynos_dp_device
*dp
, bool enable
)
828 exynos_dp_enable_scrambling(dp
);
830 exynos_dp_read_byte_from_dpcd(dp
,
831 DPCD_ADDR_TRAINING_PATTERN_SET
,
833 exynos_dp_write_byte_to_dpcd(dp
,
834 DPCD_ADDR_TRAINING_PATTERN_SET
,
835 (u8
)(data
& ~DPCD_SCRAMBLING_DISABLED
));
837 exynos_dp_disable_scrambling(dp
);
839 exynos_dp_read_byte_from_dpcd(dp
,
840 DPCD_ADDR_TRAINING_PATTERN_SET
,
842 exynos_dp_write_byte_to_dpcd(dp
,
843 DPCD_ADDR_TRAINING_PATTERN_SET
,
844 (u8
)(data
| DPCD_SCRAMBLING_DISABLED
));
848 static irqreturn_t
exynos_dp_irq_handler(int irq
, void *arg
)
850 struct exynos_dp_device
*dp
= arg
;
852 dev_err(dp
->dev
, "exynos_dp_irq_handler\n");
856 static int __devinit
exynos_dp_probe(struct platform_device
*pdev
)
858 struct resource
*res
;
859 struct exynos_dp_device
*dp
;
860 struct exynos_dp_platdata
*pdata
;
864 pdata
= pdev
->dev
.platform_data
;
866 dev_err(&pdev
->dev
, "no platform data\n");
870 dp
= devm_kzalloc(&pdev
->dev
, sizeof(struct exynos_dp_device
),
873 dev_err(&pdev
->dev
, "no memory for device data\n");
877 dp
->dev
= &pdev
->dev
;
879 dp
->clock
= clk_get(&pdev
->dev
, "dp");
880 if (IS_ERR(dp
->clock
)) {
881 dev_err(&pdev
->dev
, "failed to get clock\n");
882 return PTR_ERR(dp
->clock
);
885 clk_enable(dp
->clock
);
887 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
889 dev_err(&pdev
->dev
, "failed to get registers\n");
894 dp
->reg_base
= devm_request_and_ioremap(&pdev
->dev
, res
);
896 dev_err(&pdev
->dev
, "failed to ioremap\n");
901 dp
->irq
= platform_get_irq(pdev
, 0);
903 dev_err(&pdev
->dev
, "failed to get irq\n");
908 ret
= devm_request_irq(&pdev
->dev
, dp
->irq
, exynos_dp_irq_handler
, 0,
911 dev_err(&pdev
->dev
, "failed to request irq\n");
915 dp
->video_info
= pdata
->video_info
;
919 exynos_dp_init_dp(dp
);
921 ret
= exynos_dp_detect_hpd(dp
);
923 dev_err(&pdev
->dev
, "unable to detect hpd\n");
927 exynos_dp_handle_edid(dp
);
929 ret
= exynos_dp_set_link_train(dp
, dp
->video_info
->lane_count
,
930 dp
->video_info
->link_rate
);
932 dev_err(&pdev
->dev
, "unable to do link train\n");
936 exynos_dp_enable_scramble(dp
, 1);
937 exynos_dp_enable_rx_to_enhanced_mode(dp
, 1);
938 exynos_dp_enable_enhanced_mode(dp
, 1);
940 exynos_dp_set_lane_count(dp
, dp
->video_info
->lane_count
);
941 exynos_dp_set_link_bandwidth(dp
, dp
->video_info
->link_rate
);
943 exynos_dp_init_video(dp
);
944 ret
= exynos_dp_config_video(dp
, dp
->video_info
);
946 dev_err(&pdev
->dev
, "unable to config video\n");
950 platform_set_drvdata(pdev
, dp
);
960 static int __devexit
exynos_dp_remove(struct platform_device
*pdev
)
962 struct exynos_dp_platdata
*pdata
= pdev
->dev
.platform_data
;
963 struct exynos_dp_device
*dp
= platform_get_drvdata(pdev
);
965 if (pdata
&& pdata
->phy_exit
)
968 clk_disable(dp
->clock
);
974 #ifdef CONFIG_PM_SLEEP
975 static int exynos_dp_suspend(struct device
*dev
)
977 struct platform_device
*pdev
= to_platform_device(dev
);
978 struct exynos_dp_platdata
*pdata
= pdev
->dev
.platform_data
;
979 struct exynos_dp_device
*dp
= platform_get_drvdata(pdev
);
981 if (pdata
&& pdata
->phy_exit
)
984 clk_disable(dp
->clock
);
989 static int exynos_dp_resume(struct device
*dev
)
991 struct platform_device
*pdev
= to_platform_device(dev
);
992 struct exynos_dp_platdata
*pdata
= pdev
->dev
.platform_data
;
993 struct exynos_dp_device
*dp
= platform_get_drvdata(pdev
);
995 if (pdata
&& pdata
->phy_init
)
998 clk_enable(dp
->clock
);
1000 exynos_dp_init_dp(dp
);
1002 exynos_dp_detect_hpd(dp
);
1003 exynos_dp_handle_edid(dp
);
1005 exynos_dp_set_link_train(dp
, dp
->video_info
->lane_count
,
1006 dp
->video_info
->link_rate
);
1008 exynos_dp_enable_scramble(dp
, 1);
1009 exynos_dp_enable_rx_to_enhanced_mode(dp
, 1);
1010 exynos_dp_enable_enhanced_mode(dp
, 1);
1012 exynos_dp_set_lane_count(dp
, dp
->video_info
->lane_count
);
1013 exynos_dp_set_link_bandwidth(dp
, dp
->video_info
->link_rate
);
1015 exynos_dp_init_video(dp
);
1016 exynos_dp_config_video(dp
, dp
->video_info
);
1022 static const struct dev_pm_ops exynos_dp_pm_ops
= {
1023 SET_SYSTEM_SLEEP_PM_OPS(exynos_dp_suspend
, exynos_dp_resume
)
1026 static struct platform_driver exynos_dp_driver
= {
1027 .probe
= exynos_dp_probe
,
1028 .remove
= __devexit_p(exynos_dp_remove
),
1030 .name
= "exynos-dp",
1031 .owner
= THIS_MODULE
,
1032 .pm
= &exynos_dp_pm_ops
,
1036 module_platform_driver(exynos_dp_driver
);
1038 MODULE_AUTHOR("Jingoo Han <jg1.han@samsung.com>");
1039 MODULE_DESCRIPTION("Samsung SoC DP Driver");
1040 MODULE_LICENSE("GPL");