13 #include <linux/module.h>
15 #include <linux/slab.h>
58 dev_err(dp->
dev,
"failed to get hpd plug status\n");
67 static unsigned char exynos_dp_calc_edid_check_sum(
unsigned char *edid_data)
70 unsigned char sum = 0;
73 sum = sum + edid_data[i];
81 unsigned int extend_block = 0;
83 unsigned char test_vector;
97 if (extend_block > 0) {
98 dev_dbg(dp->
dev,
"EDID data includes a single extension!\n");
109 sum = exynos_dp_calc_edid_check_sum(edid);
142 dev_info(dp->
dev,
"EDID data does not include any extensions.\n");
154 sum = exynos_dp_calc_edid_check_sum(edid);
189 for (i = 0; i < 3; i++) {
190 retval = exynos_dp_read_edid(dp);
198 static void exynos_dp_enable_rx_to_enhanced_mode(
struct exynos_dp_device *dp,
214 static int exynos_dp_is_enhanced_mode_available(
struct exynos_dp_device *dp)
229 data = exynos_dp_is_enhanced_mode_available(dp);
230 exynos_dp_enable_rx_to_enhanced_mode(dp, data);
243 static void exynos_dp_set_lane_lane_pre_emphasis(
struct exynos_dp_device *dp,
244 int pre_emphasis,
int lane)
275 for (lane = 0; lane < lane_count; lane++)
293 for (lane = 0; lane < lane_count; lane++)
294 exynos_dp_set_lane_lane_pre_emphasis(dp,
306 for (lane = 0; lane < lane_count; lane++)
314 static unsigned char exynos_dp_get_lane_status(
u8 link_status[2],
int lane)
316 int shift = (lane & 1) * 4;
317 u8 link_value = link_status[lane>>1];
319 return (link_value >> shift) & 0xf;
322 static int exynos_dp_clock_recovery_ok(
u8 link_status[2],
int lane_count)
327 for (lane = 0; lane < lane_count; lane++) {
328 lane_status = exynos_dp_get_lane_status(link_status, lane);
335 static int exynos_dp_channel_eq_ok(
u8 link_align[3],
int lane_count)
341 lane_align = link_align[2];
345 for (lane = 0; lane < lane_count; lane++) {
346 lane_status = exynos_dp_get_lane_status(link_align, lane);
355 static unsigned char exynos_dp_get_adjust_request_voltage(
u8 adjust_request[2],
358 int shift = (lane & 1) * 4;
359 u8 link_value = adjust_request[lane>>1];
361 return (link_value >> shift) & 0x3;
364 static unsigned char exynos_dp_get_adjust_request_pre_emphasis(
365 u8 adjust_request[2],
368 int shift = (lane & 1) * 4;
369 u8 link_value = adjust_request[lane>>1];
371 return ((link_value >> shift) & 0xc) >> 2;
375 u8 training_lane_set,
int lane)
395 static unsigned int exynos_dp_get_lane_link_training(
424 exynos_dp_training_pattern_dis(dp);
425 exynos_dp_set_enhanced_mode(dp);
436 u8 adjust_request[2];
448 if (exynos_dp_clock_recovery_ok(link_status, lane_count) == 0) {
452 for (lane = 0; lane < lane_count; lane++) {
456 voltage_swing = exynos_dp_get_adjust_request_voltage(
457 adjust_request, lane);
458 pre_emphasis = exynos_dp_get_adjust_request_pre_emphasis(
459 adjust_request, lane);
468 dp->
link_train.training_lane[lane] = training_lane;
470 exynos_dp_set_lane_link_training(dp,
485 dev_info(dp->
dev,
"Link Training Clock Recovery success\n");
488 for (lane = 0; lane < lane_count; lane++) {
489 training_lane = exynos_dp_get_lane_link_training(
494 voltage_swing = exynos_dp_get_adjust_request_voltage(
495 adjust_request, lane);
496 pre_emphasis = exynos_dp_get_adjust_request_pre_emphasis(
497 adjust_request, lane);
501 dev_err(dp->
dev,
"voltage or pre emphasis reached max level\n");
502 goto reduce_link_rate;
512 goto reduce_link_rate;
524 dp->
link_train.training_lane[lane] = training_lane;
526 exynos_dp_set_lane_link_training(dp,
539 exynos_dp_reduce_link_rate(dp);
543 static int exynos_dp_process_equalizer_training(
struct exynos_dp_device *dp)
551 u8 adjust_request[2];
563 if (exynos_dp_clock_recovery_ok(link_status, lane_count) == 0) {
564 link_align[0] = link_status[0];
565 link_align[1] = link_status[1];
571 for (lane = 0; lane < lane_count; lane++) {
575 voltage_swing = exynos_dp_get_adjust_request_voltage(
576 adjust_request, lane);
577 pre_emphasis = exynos_dp_get_adjust_request_pre_emphasis(
578 adjust_request, lane);
587 dp->
link_train.training_lane[lane] = training_lane;
590 if (exynos_dp_channel_eq_ok(link_align, lane_count) == 0) {
592 exynos_dp_training_pattern_dis(dp);
607 exynos_dp_set_enhanced_mode(dp);
615 goto reduce_link_rate;
618 for (lane = 0; lane < lane_count; lane++)
619 exynos_dp_set_lane_link_training(dp,
629 goto reduce_link_rate;
635 exynos_dp_reduce_link_rate(dp);
676 exynos_dp_get_max_rx_bandwidth(dp, &dp->
link_train.link_rate);
677 exynos_dp_get_max_rx_lane_count(dp, &dp->
link_train.lane_count);
681 dev_err(dp->
dev,
"Rx Max Link Rate is abnormal :%x !\n",
687 dev_err(dp->
dev,
"Rx Max Lane count is abnormal :%x !\n",
705 int training_finished = 0;
710 while (!training_finished) {
713 exynos_dp_link_start(dp);
716 retval = exynos_dp_process_clock_recovery(dp);
721 retval = exynos_dp_process_equalizer_training(dp);
726 training_finished = 1;
744 exynos_dp_init_training(dp, count, bwtype);
745 retval = exynos_dp_sw_link_training(dp);
759 int timeout_loop = 0;
778 if (DP_TIMEOUT_LOOP_COUNT < timeout_loop) {
779 dev_err(dp->
dev,
"Timeout of video streamclk ok\n");
809 }
else if (done_count) {
812 if (DP_TIMEOUT_LOOP_COUNT < timeout_loop) {
813 dev_err(dp->
dev,
"Timeout of video streamclk ok\n");
821 dev_err(dp->
dev,
"Video stream is not detected!\n");
826 static void exynos_dp_enable_scramble(
struct exynos_dp_device *dp,
bool enable)
867 pdata = pdev->
dev.platform_data;
876 dev_err(&pdev->
dev,
"no memory for device data\n");
883 if (IS_ERR(dp->
clock)) {
885 return PTR_ERR(dp->
clock);
888 clk_prepare_enable(dp->
clock);
904 ret = devm_request_irq(&pdev->
dev, dp->
irq, exynos_dp_irq_handler, 0,
907 dev_err(&pdev->
dev,
"failed to request irq\n");
915 exynos_dp_init_dp(dp);
917 ret = exynos_dp_detect_hpd(dp);
919 dev_err(&pdev->
dev,
"unable to detect hpd\n");
923 exynos_dp_handle_edid(dp);
925 ret = exynos_dp_set_link_train(dp, dp->
video_info->lane_count,
928 dev_err(&pdev->
dev,
"unable to do link train\n");
932 exynos_dp_enable_scramble(dp, 1);
933 exynos_dp_enable_rx_to_enhanced_mode(dp, 1);
940 ret = exynos_dp_config_video(dp, dp->
video_info);
942 dev_err(&pdev->
dev,
"unable to config video\n");
946 platform_set_drvdata(pdev, dp);
959 clk_disable_unprepare(dp->
clock);
964 #ifdef CONFIG_PM_SLEEP
965 static int exynos_dp_suspend(
struct device *
dev)
974 clk_disable_unprepare(dp->
clock);
979 static int exynos_dp_resume(
struct device *dev)
988 clk_prepare_enable(dp->
clock);
990 exynos_dp_init_dp(dp);
992 exynos_dp_detect_hpd(dp);
993 exynos_dp_handle_edid(dp);
995 exynos_dp_set_link_train(dp, dp->
video_info->lane_count,
998 exynos_dp_enable_scramble(dp, 1);
999 exynos_dp_enable_rx_to_enhanced_mode(dp, 1);
1012 static const struct dev_pm_ops exynos_dp_pm_ops = {
1017 .probe = exynos_dp_probe,
1020 .name =
"exynos-dp",
1022 .pm = &exynos_dp_pm_ops,