1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (C) 2012 Samsung Electronics
10 #include <linux/err.h>
11 #include <asm/arch/cpu.h>
12 #include <asm/arch/dp_info.h>
13 #include <asm/arch/dp.h>
15 #include <linux/libfdt.h>
16 #include "exynos_dp_lowlevel.h"
18 /* Declare global data pointer */
19 static void exynos_dp_enable_video_input(struct exynos_dp *dp_regs,
24 reg = readl(&dp_regs->video_ctl1);
25 reg &= ~VIDEO_EN_MASK;
27 /* enable video input */
31 writel(reg, &dp_regs->video_ctl1);
36 void exynos_dp_enable_video_bist(struct exynos_dp *dp_regs, unsigned int enable)
38 /* enable video bist */
41 reg = readl(&dp_regs->video_ctl4);
42 reg &= ~VIDEO_BIST_MASK;
44 /* enable video bist */
46 reg |= VIDEO_BIST_MASK;
48 writel(reg, &dp_regs->video_ctl4);
53 void exynos_dp_enable_video_mute(struct exynos_dp *dp_regs, unsigned int enable)
57 reg = readl(&dp_regs->video_ctl1);
58 reg &= ~(VIDEO_MUTE_MASK);
60 reg |= VIDEO_MUTE_MASK;
62 writel(reg, &dp_regs->video_ctl1);
68 static void exynos_dp_init_analog_param(struct exynos_dp *dp_regs)
74 * Normal bandgap, Normal swing, Tx terminal registor 61 ohm
75 * 24M Phy clock, TX digital logic power is 100:1.0625V
77 reg = SEL_BG_NEW_BANDGAP | TX_TERMINAL_CTRL_61_OHM |
78 SWING_A_30PER_G_NORMAL;
79 writel(reg, &dp_regs->analog_ctl1);
81 reg = SEL_24M | TX_DVDD_BIT_1_0625V;
82 writel(reg, &dp_regs->analog_ctl2);
85 * Set power source for internal clk driver to 1.0625v.
86 * Select current reference of TX driver current to 00:Ipp/2+Ic/2.
87 * Set VCO range of PLL +- 0uA
89 reg = DRIVE_DVDD_BIT_1_0625V | SEL_CURRENT_DEFAULT | VCO_BIT_000_MICRO;
90 writel(reg, &dp_regs->analog_ctl3);
93 * Set AUX TX terminal resistor to 102 ohm
94 * Set AUX channel amplitude control
96 reg = PD_RING_OSC | AUX_TERMINAL_CTRL_52_OHM | TX_CUR1_2X | TX_CUR_4_MA;
97 writel(reg, &dp_regs->pll_filter_ctl1);
100 * PLL loop filter bandwidth
101 * For 2.7Gbps: 175KHz, For 1.62Gbps: 234KHz
102 * PLL digital power select: 1.2500V
104 reg = CH3_AMP_0_MV | CH2_AMP_0_MV | CH1_AMP_0_MV | CH0_AMP_0_MV;
106 writel(reg, &dp_regs->amp_tuning_ctl);
109 * PLL loop filter bandwidth
110 * For 2.7Gbps: 175KHz, For 1.62Gbps: 234KHz
111 * PLL digital power select: 1.1250V
113 reg = DP_PLL_LOOP_BIT_DEFAULT | DP_PLL_REF_BIT_1_1250V;
114 writel(reg, &dp_regs->pll_ctl);
117 static void exynos_dp_init_interrupt(struct exynos_dp *dp_regs)
119 /* Set interrupt registers to initial states */
123 * INT pin assertion polarity. It must be configured
124 * correctly according to ICU setting.
125 * 1 = assert high, 0 = assert low
127 writel(INT_POL, &dp_regs->int_ctl);
129 /* Clear pending registers */
130 writel(0xff, &dp_regs->common_int_sta1);
131 writel(0xff, &dp_regs->common_int_sta2);
132 writel(0xff, &dp_regs->common_int_sta3);
133 writel(0xff, &dp_regs->common_int_sta4);
134 writel(0xff, &dp_regs->int_sta);
136 /* 0:mask,1: unmask */
137 writel(0x00, &dp_regs->int_sta_mask1);
138 writel(0x00, &dp_regs->int_sta_mask2);
139 writel(0x00, &dp_regs->int_sta_mask3);
140 writel(0x00, &dp_regs->int_sta_mask4);
141 writel(0x00, &dp_regs->int_sta_mask);
144 void exynos_dp_reset(struct exynos_dp *dp_regs)
146 unsigned int reg_func_1;
149 writel(RESET_DP_TX, &dp_regs->tx_sw_reset);
151 exynos_dp_enable_video_input(dp_regs, DP_DISABLE);
152 exynos_dp_enable_video_bist(dp_regs, DP_DISABLE);
153 exynos_dp_enable_video_mute(dp_regs, DP_DISABLE);
156 reg_func_1 = MASTER_VID_FUNC_EN_N | SLAVE_VID_FUNC_EN_N |
157 AUD_FIFO_FUNC_EN_N | AUD_FUNC_EN_N |
158 HDCP_FUNC_EN_N | SW_FUNC_EN_N;
160 writel(reg_func_1, &dp_regs->func_en1);
161 writel(reg_func_1, &dp_regs->func_en2);
165 exynos_dp_init_analog_param(dp_regs);
166 exynos_dp_init_interrupt(dp_regs);
171 void exynos_dp_enable_sw_func(struct exynos_dp *dp_regs, unsigned int enable)
175 reg = readl(&dp_regs->func_en1);
176 reg &= ~(SW_FUNC_EN_N);
181 writel(reg, &dp_regs->func_en1);
186 unsigned int exynos_dp_set_analog_power_down(struct exynos_dp *dp_regs,
187 unsigned int block, u32 enable)
191 reg = readl(&dp_regs->phy_pd);
224 reg &= ~(PHY_PD | AUX_PD | CH0_PD | CH1_PD | CH2_PD |
227 reg |= (PHY_PD | AUX_PD | CH0_PD | CH1_PD |
231 printf("DP undefined block number : %d\n", block);
235 writel(reg, &dp_regs->phy_pd);
240 unsigned int exynos_dp_get_pll_lock_status(struct exynos_dp *dp_regs)
244 reg = readl(&dp_regs->debug_ctl);
252 static void exynos_dp_set_pll_power(struct exynos_dp *dp_regs,
257 reg = readl(&dp_regs->pll_ctl);
263 writel(reg, &dp_regs->pll_ctl);
266 int exynos_dp_init_analog_func(struct exynos_dp *dp_regs)
268 int ret = EXYNOS_DP_SUCCESS;
269 unsigned int retry_cnt = 10;
272 /* Power On All Analog block */
273 exynos_dp_set_analog_power_down(dp_regs, POWER_ALL, DP_DISABLE);
276 writel(reg, &dp_regs->common_int_sta1);
278 reg = readl(&dp_regs->debug_ctl);
279 reg &= ~(F_PLL_LOCK | PLL_LOCK_CTRL);
280 writel(reg, &dp_regs->debug_ctl);
282 /* Assert DP PLL Reset */
283 reg = readl(&dp_regs->pll_ctl);
285 writel(reg, &dp_regs->pll_ctl);
289 /* Deassert DP PLL Reset */
290 reg = readl(&dp_regs->pll_ctl);
291 reg &= ~(DP_PLL_RESET);
292 writel(reg, &dp_regs->pll_ctl);
294 exynos_dp_set_pll_power(dp_regs, DP_ENABLE);
296 while (exynos_dp_get_pll_lock_status(dp_regs) == PLL_UNLOCKED) {
299 if (retry_cnt == 0) {
300 printf("DP dp's pll lock failed : retry : %d\n",
306 debug("dp's pll lock success(%d)\n", retry_cnt);
308 /* Enable Serdes FIFO function and Link symbol clock domain module */
309 reg = readl(&dp_regs->func_en2);
310 reg &= ~(SERDES_FIFO_FUNC_EN_N | LS_CLK_DOMAIN_FUNC_EN_N
312 writel(reg, &dp_regs->func_en2);
317 void exynos_dp_init_hpd(struct exynos_dp *dp_regs)
321 /* Clear interrupts related to Hot Plug Detect */
322 reg = HOTPLUG_CHG | HPD_LOST | PLUG;
323 writel(reg, &dp_regs->common_int_sta4);
326 writel(reg, &dp_regs->int_sta);
328 reg = readl(&dp_regs->sys_ctl3);
329 reg &= ~(F_HPD | HPD_CTRL);
330 writel(reg, &dp_regs->sys_ctl3);
335 static inline void exynos_dp_reset_aux(struct exynos_dp *dp_regs)
339 /* Disable AUX channel module */
340 reg = readl(&dp_regs->func_en2);
341 reg |= AUX_FUNC_EN_N;
342 writel(reg, &dp_regs->func_en2);
347 void exynos_dp_init_aux(struct exynos_dp *dp_regs)
351 /* Clear interrupts related to AUX channel */
352 reg = RPLY_RECEIV | AUX_ERR;
353 writel(reg, &dp_regs->int_sta);
355 exynos_dp_reset_aux(dp_regs);
357 /* Disable AUX transaction H/W retry */
358 reg = AUX_BIT_PERIOD_EXPECTED_DELAY(3) | AUX_HW_RETRY_COUNT_SEL(3)|
359 AUX_HW_RETRY_INTERVAL_600_MICROSECONDS;
360 writel(reg, &dp_regs->aux_hw_retry_ctl);
362 /* Receive AUX Channel DEFER commands equal to DEFER_COUNT*64 */
363 reg = DEFER_CTRL_EN | DEFER_COUNT(1);
364 writel(reg, &dp_regs->aux_ch_defer_ctl);
366 /* Enable AUX channel module */
367 reg = readl(&dp_regs->func_en2);
368 reg &= ~AUX_FUNC_EN_N;
369 writel(reg, &dp_regs->func_en2);
374 void exynos_dp_config_interrupt(struct exynos_dp *dp_regs)
378 /* 0: mask, 1: unmask */
379 reg = COMMON_INT_MASK_1;
380 writel(reg, &dp_regs->common_int_mask1);
382 reg = COMMON_INT_MASK_2;
383 writel(reg, &dp_regs->common_int_mask2);
385 reg = COMMON_INT_MASK_3;
386 writel(reg, &dp_regs->common_int_mask3);
388 reg = COMMON_INT_MASK_4;
389 writel(reg, &dp_regs->common_int_mask4);
392 writel(reg, &dp_regs->int_sta_mask);
397 unsigned int exynos_dp_get_plug_in_status(struct exynos_dp *dp_regs)
401 reg = readl(&dp_regs->sys_ctl3);
402 if (reg & HPD_STATUS)
408 unsigned int exynos_dp_detect_hpd(struct exynos_dp *dp_regs)
410 int timeout_loop = DP_TIMEOUT_LOOP_COUNT;
414 while (exynos_dp_get_plug_in_status(dp_regs) != 0) {
415 if (timeout_loop == 0)
421 return EXYNOS_DP_SUCCESS;
424 unsigned int exynos_dp_start_aux_transaction(struct exynos_dp *dp_regs)
427 unsigned int ret = 0;
428 unsigned int retry_cnt;
430 /* Enable AUX CH operation */
431 reg = readl(&dp_regs->aux_ch_ctl2);
433 writel(reg, &dp_regs->aux_ch_ctl2);
437 reg = readl(&dp_regs->int_sta);
438 if (!(reg & RPLY_RECEIV)) {
439 if (retry_cnt == 0) {
440 printf("DP Reply Timeout!!\n");
450 /* Clear interrupt source for AUX CH command reply */
451 writel(reg, &dp_regs->int_sta);
453 /* Clear interrupt source for AUX CH access error */
454 reg = readl(&dp_regs->int_sta);
456 printf("DP Aux Access Error\n");
457 writel(AUX_ERR, &dp_regs->int_sta);
462 /* Check AUX CH error access status */
463 reg = readl(&dp_regs->aux_ch_sta);
464 if ((reg & AUX_STATUS_MASK) != 0) {
465 debug("DP AUX CH error happens: %x\n", reg & AUX_STATUS_MASK);
470 return EXYNOS_DP_SUCCESS;
473 unsigned int exynos_dp_write_byte_to_dpcd(struct exynos_dp *dp_regs,
474 unsigned int reg_addr,
477 unsigned int reg, ret;
479 /* Clear AUX CH data buffer */
481 writel(reg, &dp_regs->buffer_data_ctl);
483 /* Select DPCD device address */
484 reg = AUX_ADDR_7_0(reg_addr);
485 writel(reg, &dp_regs->aux_addr_7_0);
486 reg = AUX_ADDR_15_8(reg_addr);
487 writel(reg, &dp_regs->aux_addr_15_8);
488 reg = AUX_ADDR_19_16(reg_addr);
489 writel(reg, &dp_regs->aux_addr_19_16);
491 /* Write data buffer */
492 reg = (unsigned int)data;
493 writel(reg, &dp_regs->buf_data0);
496 * Set DisplayPort transaction and write 1 byte
497 * If bit 3 is 1, DisplayPort transaction.
498 * If Bit 3 is 0, I2C transaction.
500 reg = AUX_TX_COMM_DP_TRANSACTION | AUX_TX_COMM_WRITE;
501 writel(reg, &dp_regs->aux_ch_ctl1);
503 /* Start AUX transaction */
504 ret = exynos_dp_start_aux_transaction(dp_regs);
505 if (ret != EXYNOS_DP_SUCCESS) {
506 printf("DP Aux transaction failed\n");
513 unsigned int exynos_dp_read_byte_from_dpcd(struct exynos_dp *dp_regs,
514 unsigned int reg_addr,
520 /* Clear AUX CH data buffer */
522 writel(reg, &dp_regs->buffer_data_ctl);
524 /* Select DPCD device address */
525 reg = AUX_ADDR_7_0(reg_addr);
526 writel(reg, &dp_regs->aux_addr_7_0);
527 reg = AUX_ADDR_15_8(reg_addr);
528 writel(reg, &dp_regs->aux_addr_15_8);
529 reg = AUX_ADDR_19_16(reg_addr);
530 writel(reg, &dp_regs->aux_addr_19_16);
533 * Set DisplayPort transaction and read 1 byte
534 * If bit 3 is 1, DisplayPort transaction.
535 * If Bit 3 is 0, I2C transaction.
537 reg = AUX_TX_COMM_DP_TRANSACTION | AUX_TX_COMM_READ;
538 writel(reg, &dp_regs->aux_ch_ctl1);
540 /* Start AUX transaction */
541 retval = exynos_dp_start_aux_transaction(dp_regs);
543 debug("DP Aux Transaction fail!\n");
545 /* Read data buffer */
546 reg = readl(&dp_regs->buf_data0);
547 *data = (unsigned char)(reg & 0xff);
552 unsigned int exynos_dp_write_bytes_to_dpcd(struct exynos_dp *dp_regs,
553 unsigned int reg_addr,
555 unsigned char data[])
558 unsigned int start_offset;
559 unsigned int cur_data_count;
560 unsigned int cur_data_idx;
561 unsigned int retry_cnt;
562 unsigned int ret = 0;
564 /* Clear AUX CH data buffer */
566 writel(reg, &dp_regs->buffer_data_ctl);
569 while (start_offset < count) {
570 /* Buffer size of AUX CH is 16 * 4bytes */
571 if ((count - start_offset) > 16)
574 cur_data_count = count - start_offset;
578 /* Select DPCD device address */
579 reg = AUX_ADDR_7_0(reg_addr + start_offset);
580 writel(reg, &dp_regs->aux_addr_7_0);
581 reg = AUX_ADDR_15_8(reg_addr + start_offset);
582 writel(reg, &dp_regs->aux_addr_15_8);
583 reg = AUX_ADDR_19_16(reg_addr + start_offset);
584 writel(reg, &dp_regs->aux_addr_19_16);
586 for (cur_data_idx = 0; cur_data_idx < cur_data_count;
588 reg = data[start_offset + cur_data_idx];
589 writel(reg, (unsigned int)&dp_regs->buf_data0 +
593 * Set DisplayPort transaction and write
594 * If bit 3 is 1, DisplayPort transaction.
595 * If Bit 3 is 0, I2C transaction.
597 reg = AUX_LENGTH(cur_data_count) |
598 AUX_TX_COMM_DP_TRANSACTION | AUX_TX_COMM_WRITE;
599 writel(reg, &dp_regs->aux_ch_ctl1);
601 /* Start AUX transaction */
602 ret = exynos_dp_start_aux_transaction(dp_regs);
603 if (ret != EXYNOS_DP_SUCCESS) {
604 if (retry_cnt == 0) {
605 printf("DP Aux Transaction failed\n");
612 start_offset += cur_data_count;
618 unsigned int exynos_dp_read_bytes_from_dpcd(struct exynos_dp *dp_regs,
619 unsigned int reg_addr,
621 unsigned char data[])
624 unsigned int start_offset;
625 unsigned int cur_data_count;
626 unsigned int cur_data_idx;
627 unsigned int retry_cnt;
628 unsigned int ret = 0;
630 /* Clear AUX CH data buffer */
632 writel(reg, &dp_regs->buffer_data_ctl);
635 while (start_offset < count) {
636 /* Buffer size of AUX CH is 16 * 4bytes */
637 if ((count - start_offset) > 16)
640 cur_data_count = count - start_offset;
644 /* Select DPCD device address */
645 reg = AUX_ADDR_7_0(reg_addr + start_offset);
646 writel(reg, &dp_regs->aux_addr_7_0);
647 reg = AUX_ADDR_15_8(reg_addr + start_offset);
648 writel(reg, &dp_regs->aux_addr_15_8);
649 reg = AUX_ADDR_19_16(reg_addr + start_offset);
650 writel(reg, &dp_regs->aux_addr_19_16);
652 * Set DisplayPort transaction and read
653 * If bit 3 is 1, DisplayPort transaction.
654 * If Bit 3 is 0, I2C transaction.
656 reg = AUX_LENGTH(cur_data_count) |
657 AUX_TX_COMM_DP_TRANSACTION | AUX_TX_COMM_READ;
658 writel(reg, &dp_regs->aux_ch_ctl1);
660 /* Start AUX transaction */
661 ret = exynos_dp_start_aux_transaction(dp_regs);
662 if (ret != EXYNOS_DP_SUCCESS) {
663 if (retry_cnt == 0) {
664 printf("DP Aux Transaction failed\n");
672 for (cur_data_idx = 0; cur_data_idx < cur_data_count;
674 reg = readl((unsigned int)&dp_regs->buf_data0 +
676 data[start_offset + cur_data_idx] = (unsigned char)reg;
679 start_offset += cur_data_count;
685 int exynos_dp_select_i2c_device(struct exynos_dp *dp_regs,
686 unsigned int device_addr, unsigned int reg_addr)
691 /* Set EDID device address */
693 writel(reg, &dp_regs->aux_addr_7_0);
694 writel(0x0, &dp_regs->aux_addr_15_8);
695 writel(0x0, &dp_regs->aux_addr_19_16);
697 /* Set offset from base address of EDID device */
698 writel(reg_addr, &dp_regs->buf_data0);
701 * Set I2C transaction and write address
702 * If bit 3 is 1, DisplayPort transaction.
703 * If Bit 3 is 0, I2C transaction.
705 reg = AUX_TX_COMM_I2C_TRANSACTION | AUX_TX_COMM_MOT |
707 writel(reg, &dp_regs->aux_ch_ctl1);
709 /* Start AUX transaction */
710 retval = exynos_dp_start_aux_transaction(dp_regs);
712 printf("%s: DP Aux Transaction fail!\n", __func__);
717 int exynos_dp_read_byte_from_i2c(struct exynos_dp *dp_regs,
718 unsigned int device_addr,
719 unsigned int reg_addr, unsigned int *data)
725 for (i = 0; i < 10; i++) {
726 /* Clear AUX CH data buffer */
728 writel(reg, &dp_regs->buffer_data_ctl);
730 /* Select EDID device */
731 retval = exynos_dp_select_i2c_device(dp_regs, device_addr,
734 printf("DP Select EDID device fail. retry !\n");
739 * Set I2C transaction and read data
740 * If bit 3 is 1, DisplayPort transaction.
741 * If Bit 3 is 0, I2C transaction.
743 reg = AUX_TX_COMM_I2C_TRANSACTION |
745 writel(reg, &dp_regs->aux_ch_ctl1);
747 /* Start AUX transaction */
748 retval = exynos_dp_start_aux_transaction(dp_regs);
749 if (retval != EXYNOS_DP_SUCCESS)
750 printf("%s: DP Aux Transaction fail!\n", __func__);
755 *data = readl(&dp_regs->buf_data0);
760 int exynos_dp_read_bytes_from_i2c(struct exynos_dp *dp_regs,
761 unsigned int device_addr,
762 unsigned int reg_addr, unsigned int count,
763 unsigned char edid[])
767 unsigned int cur_data_idx;
768 unsigned int defer = 0;
771 for (i = 0; i < count; i += 16) { /* use 16 burst */
772 for (j = 0; j < 100; j++) {
773 /* Clear AUX CH data buffer */
775 writel(reg, &dp_regs->buffer_data_ctl);
777 /* Set normal AUX CH command */
778 reg = readl(&dp_regs->aux_ch_ctl2);
780 writel(reg, &dp_regs->aux_ch_ctl2);
783 * If Rx sends defer, Tx sends only reads
784 * request without sending addres
787 retval = exynos_dp_select_i2c_device(
788 dp_regs, device_addr, reg_addr + i);
792 if (retval == EXYNOS_DP_SUCCESS) {
794 * Set I2C transaction and write data
795 * If bit 3 is 1, DisplayPort transaction.
796 * If Bit 3 is 0, I2C transaction.
798 reg = AUX_LENGTH(16) |
799 AUX_TX_COMM_I2C_TRANSACTION |
801 writel(reg, &dp_regs->aux_ch_ctl1);
803 /* Start AUX transaction */
804 retval = exynos_dp_start_aux_transaction(
809 printf("DP Aux Transaction fail!\n");
811 /* Check if Rx sends defer */
812 reg = readl(&dp_regs->aux_rx_comm);
813 if (reg == AUX_RX_COMM_AUX_DEFER ||
814 reg == AUX_RX_COMM_I2C_DEFER) {
815 printf("DP Defer: %d\n", reg);
820 for (cur_data_idx = 0; cur_data_idx < 16; cur_data_idx++) {
821 reg = readl((unsigned int)&dp_regs->buf_data0
823 edid[i + cur_data_idx] = (unsigned char)reg;
830 void exynos_dp_reset_macro(struct exynos_dp *dp_regs)
834 reg = readl(&dp_regs->phy_test);
836 writel(reg, &dp_regs->phy_test);
838 /* 10 us is the minimum Macro reset time. */
842 writel(reg, &dp_regs->phy_test);
845 void exynos_dp_set_link_bandwidth(struct exynos_dp *dp_regs,
846 unsigned char bwtype)
850 reg = (unsigned int)bwtype;
852 /* Set bandwidth to 2.7G or 1.62G */
853 if ((bwtype == DP_LANE_BW_1_62) || (bwtype == DP_LANE_BW_2_70))
854 writel(reg, &dp_regs->link_bw_set);
857 unsigned char exynos_dp_get_link_bandwidth(struct exynos_dp *dp_regs)
862 reg = readl(&dp_regs->link_bw_set);
863 ret = (unsigned char)reg;
868 void exynos_dp_set_lane_count(struct exynos_dp *dp_regs, unsigned char count)
872 reg = (unsigned int)count;
874 if ((count == DP_LANE_CNT_1) || (count == DP_LANE_CNT_2) ||
875 (count == DP_LANE_CNT_4))
876 writel(reg, &dp_regs->lane_count_set);
879 unsigned int exynos_dp_get_lane_count(struct exynos_dp *dp_regs)
881 return readl(&dp_regs->lane_count_set);
884 unsigned char exynos_dp_get_lanex_pre_emphasis(struct exynos_dp *dp_regs,
885 unsigned char lanecnt)
887 unsigned int reg_list[DP_LANE_CNT_4] = {
888 (unsigned int)&dp_regs->ln0_link_training_ctl,
889 (unsigned int)&dp_regs->ln1_link_training_ctl,
890 (unsigned int)&dp_regs->ln2_link_training_ctl,
891 (unsigned int)&dp_regs->ln3_link_training_ctl,
894 return readl(reg_list[lanecnt]);
897 void exynos_dp_set_lanex_pre_emphasis(struct exynos_dp *dp_regs,
898 unsigned char request_val,
899 unsigned char lanecnt)
901 unsigned int reg_list[DP_LANE_CNT_4] = {
902 (unsigned int)&dp_regs->ln0_link_training_ctl,
903 (unsigned int)&dp_regs->ln1_link_training_ctl,
904 (unsigned int)&dp_regs->ln2_link_training_ctl,
905 (unsigned int)&dp_regs->ln3_link_training_ctl,
908 writel(request_val, reg_list[lanecnt]);
911 void exynos_dp_set_lane_pre_emphasis(struct exynos_dp *dp_regs,
912 unsigned int level, unsigned char lanecnt)
916 unsigned int reg_list[DP_LANE_CNT_4] = {
917 (unsigned int)&dp_regs->ln0_link_training_ctl,
918 (unsigned int)&dp_regs->ln1_link_training_ctl,
919 (unsigned int)&dp_regs->ln2_link_training_ctl,
920 (unsigned int)&dp_regs->ln3_link_training_ctl,
922 unsigned int reg_shift[DP_LANE_CNT_4] = {
923 PRE_EMPHASIS_SET_0_SHIFT,
924 PRE_EMPHASIS_SET_1_SHIFT,
925 PRE_EMPHASIS_SET_2_SHIFT,
926 PRE_EMPHASIS_SET_3_SHIFT
929 for (i = 0; i < lanecnt; i++) {
930 reg = level << reg_shift[i];
931 writel(reg, reg_list[i]);
935 void exynos_dp_set_training_pattern(struct exynos_dp *dp_regs,
936 unsigned int pattern)
938 unsigned int reg = 0;
942 reg = SCRAMBLING_ENABLE | LINK_QUAL_PATTERN_SET_PRBS7;
945 reg = SCRAMBLING_ENABLE | LINK_QUAL_PATTERN_SET_D10_2;
948 reg = SCRAMBLING_DISABLE | SW_TRAINING_PATTERN_SET_PTN1;
951 reg = SCRAMBLING_DISABLE | SW_TRAINING_PATTERN_SET_PTN2;
954 reg = SCRAMBLING_ENABLE | LINK_QUAL_PATTERN_SET_DISABLE |
955 SW_TRAINING_PATTERN_SET_NORMAL;
961 writel(reg, &dp_regs->training_ptn_set);
964 void exynos_dp_enable_enhanced_mode(struct exynos_dp *dp_regs,
965 unsigned char enable)
969 reg = readl(&dp_regs->sys_ctl4);
975 writel(reg, &dp_regs->sys_ctl4);
978 void exynos_dp_enable_scrambling(struct exynos_dp *dp_regs, unsigned int enable)
982 reg = readl(&dp_regs->training_ptn_set);
983 reg &= ~(SCRAMBLING_DISABLE);
986 reg |= SCRAMBLING_DISABLE;
988 writel(reg, &dp_regs->training_ptn_set);
991 int exynos_dp_init_video(struct exynos_dp *dp_regs)
995 /* Clear VID_CLK_CHG[1] and VID_FORMAT_CHG[3] and VSYNC_DET[7] */
996 reg = VSYNC_DET | VID_FORMAT_CHG | VID_CLK_CHG;
997 writel(reg, &dp_regs->common_int_sta1);
999 /* I_STRM__CLK detect : DE_CTL : Auto detect */
1001 writel(reg, &dp_regs->sys_ctl1);
1006 void exynos_dp_config_video_slave_mode(struct exynos_dp *dp_regs,
1007 struct edp_video_info *video_info)
1011 /* Video Slave mode setting */
1012 reg = readl(&dp_regs->func_en1);
1013 reg &= ~(MASTER_VID_FUNC_EN_N|SLAVE_VID_FUNC_EN_N);
1014 reg |= MASTER_VID_FUNC_EN_N;
1015 writel(reg, &dp_regs->func_en1);
1017 /* Configure Interlaced for slave mode video */
1018 reg = readl(&dp_regs->video_ctl10);
1019 reg &= ~INTERACE_SCAN_CFG;
1020 reg |= (video_info->interlaced << INTERACE_SCAN_CFG_SHIFT);
1021 writel(reg, &dp_regs->video_ctl10);
1023 /* Configure V sync polarity for slave mode video */
1024 reg = readl(&dp_regs->video_ctl10);
1025 reg &= ~VSYNC_POLARITY_CFG;
1026 reg |= (video_info->v_sync_polarity << V_S_POLARITY_CFG_SHIFT);
1027 writel(reg, &dp_regs->video_ctl10);
1029 /* Configure H sync polarity for slave mode video */
1030 reg = readl(&dp_regs->video_ctl10);
1031 reg &= ~HSYNC_POLARITY_CFG;
1032 reg |= (video_info->h_sync_polarity << H_S_POLARITY_CFG_SHIFT);
1033 writel(reg, &dp_regs->video_ctl10);
1035 /* Set video mode to slave mode */
1036 reg = AUDIO_MODE_SPDIF_MODE | VIDEO_MODE_SLAVE_MODE;
1037 writel(reg, &dp_regs->soc_general_ctl);
1040 void exynos_dp_set_video_color_format(struct exynos_dp *dp_regs,
1041 struct edp_video_info *video_info)
1045 /* Configure the input color depth, color space, dynamic range */
1046 reg = (video_info->dynamic_range << IN_D_RANGE_SHIFT) |
1047 (video_info->color_depth << IN_BPC_SHIFT) |
1048 (video_info->color_space << IN_COLOR_F_SHIFT);
1049 writel(reg, &dp_regs->video_ctl2);
1051 /* Set Input Color YCbCr Coefficients to ITU601 or ITU709 */
1052 reg = readl(&dp_regs->video_ctl3);
1053 reg &= ~IN_YC_COEFFI_MASK;
1054 if (video_info->ycbcr_coeff)
1055 reg |= IN_YC_COEFFI_ITU709;
1057 reg |= IN_YC_COEFFI_ITU601;
1058 writel(reg, &dp_regs->video_ctl3);
1061 int exynos_dp_config_video_bist(struct exynos_dp *dp_regs,
1062 struct exynos_dp_priv *priv)
1065 unsigned int bist_type = 0;
1066 struct edp_video_info video_info = priv->video_info;
1068 /* For master mode, you don't need to set the video format */
1069 if (video_info.master_mode == 0) {
1070 writel(TOTAL_LINE_CFG_L(priv->disp_info.v_total),
1071 &dp_regs->total_ln_cfg_l);
1072 writel(TOTAL_LINE_CFG_H(priv->disp_info.v_total),
1073 &dp_regs->total_ln_cfg_h);
1074 writel(ACTIVE_LINE_CFG_L(priv->disp_info.v_res),
1075 &dp_regs->active_ln_cfg_l);
1076 writel(ACTIVE_LINE_CFG_H(priv->disp_info.v_res),
1077 &dp_regs->active_ln_cfg_h);
1078 writel(priv->disp_info.v_sync_width, &dp_regs->vsw_cfg);
1079 writel(priv->disp_info.v_back_porch, &dp_regs->vbp_cfg);
1080 writel(priv->disp_info.v_front_porch, &dp_regs->vfp_cfg);
1082 writel(TOTAL_PIXEL_CFG_L(priv->disp_info.h_total),
1083 &dp_regs->total_pix_cfg_l);
1084 writel(TOTAL_PIXEL_CFG_H(priv->disp_info.h_total),
1085 &dp_regs->total_pix_cfg_h);
1086 writel(ACTIVE_PIXEL_CFG_L(priv->disp_info.h_res),
1087 &dp_regs->active_pix_cfg_l);
1088 writel(ACTIVE_PIXEL_CFG_H(priv->disp_info.h_res),
1089 &dp_regs->active_pix_cfg_h);
1090 writel(H_F_PORCH_CFG_L(priv->disp_info.h_front_porch),
1091 &dp_regs->hfp_cfg_l);
1092 writel(H_F_PORCH_CFG_H(priv->disp_info.h_front_porch),
1093 &dp_regs->hfp_cfg_h);
1094 writel(H_SYNC_PORCH_CFG_L(priv->disp_info.h_sync_width),
1095 &dp_regs->hsw_cfg_l);
1096 writel(H_SYNC_PORCH_CFG_H(priv->disp_info.h_sync_width),
1097 &dp_regs->hsw_cfg_h);
1098 writel(H_B_PORCH_CFG_L(priv->disp_info.h_back_porch),
1099 &dp_regs->hbp_cfg_l);
1100 writel(H_B_PORCH_CFG_H(priv->disp_info.h_back_porch),
1101 &dp_regs->hbp_cfg_h);
1104 * Set SLAVE_I_SCAN_CFG[2], VSYNC_P_CFG[1],
1105 * HSYNC_P_CFG[0] properly
1107 reg = (video_info.interlaced << INTERACE_SCAN_CFG_SHIFT |
1108 video_info.v_sync_polarity << V_S_POLARITY_CFG_SHIFT |
1109 video_info.h_sync_polarity << H_S_POLARITY_CFG_SHIFT);
1110 writel(reg, &dp_regs->video_ctl10);
1113 /* BIST color bar width set--set to each bar is 32 pixel width */
1114 switch (video_info.bist_pattern) {
1116 bist_type = BIST_WIDTH_BAR_32_PIXEL |
1117 BIST_TYPE_COLOR_BAR;
1120 bist_type = BIST_WIDTH_BAR_64_PIXEL |
1121 BIST_TYPE_COLOR_BAR;
1123 case WHITE_GRAY_BALCKBAR_32:
1124 bist_type = BIST_WIDTH_BAR_32_PIXEL |
1125 BIST_TYPE_WHITE_GRAY_BLACK_BAR;
1127 case WHITE_GRAY_BALCKBAR_64:
1128 bist_type = BIST_WIDTH_BAR_64_PIXEL |
1129 BIST_TYPE_WHITE_GRAY_BLACK_BAR;
1131 case MOBILE_WHITEBAR_32:
1132 bist_type = BIST_WIDTH_BAR_32_PIXEL |
1133 BIST_TYPE_MOBILE_WHITE_BAR;
1135 case MOBILE_WHITEBAR_64:
1136 bist_type = BIST_WIDTH_BAR_64_PIXEL |
1137 BIST_TYPE_MOBILE_WHITE_BAR;
1144 writel(reg, &dp_regs->video_ctl4);
1149 unsigned int exynos_dp_is_slave_video_stream_clock_on(struct exynos_dp *dp_regs)
1153 /* Update Video stream clk detect status */
1154 reg = readl(&dp_regs->sys_ctl1);
1155 writel(reg, &dp_regs->sys_ctl1);
1157 reg = readl(&dp_regs->sys_ctl1);
1159 if (!(reg & DET_STA)) {
1160 debug("DP Input stream clock not detected.\n");
1164 return EXYNOS_DP_SUCCESS;
1167 void exynos_dp_set_video_cr_mn(struct exynos_dp *dp_regs, unsigned int type,
1168 unsigned int m_value, unsigned int n_value)
1172 if (type == REGISTER_M) {
1173 reg = readl(&dp_regs->sys_ctl4);
1175 writel(reg, &dp_regs->sys_ctl4);
1176 reg = M_VID0_CFG(m_value);
1177 writel(reg, &dp_regs->m_vid0);
1178 reg = M_VID1_CFG(m_value);
1179 writel(reg, &dp_regs->m_vid1);
1180 reg = M_VID2_CFG(m_value);
1181 writel(reg, &dp_regs->m_vid2);
1183 reg = N_VID0_CFG(n_value);
1184 writel(reg, &dp_regs->n_vid0);
1185 reg = N_VID1_CFG(n_value);
1186 writel(reg, &dp_regs->n_vid1);
1187 reg = N_VID2_CFG(n_value);
1188 writel(reg, &dp_regs->n_vid2);
1190 reg = readl(&dp_regs->sys_ctl4);
1192 writel(reg, &dp_regs->sys_ctl4);
1196 void exynos_dp_set_video_timing_mode(struct exynos_dp *dp_regs,
1201 reg = readl(&dp_regs->video_ctl10);
1204 if (type != VIDEO_TIMING_FROM_CAPTURE)
1207 writel(reg, &dp_regs->video_ctl10);
1210 void exynos_dp_enable_video_master(struct exynos_dp *dp_regs,
1211 unsigned int enable)
1215 reg = readl(&dp_regs->soc_general_ctl);
1217 reg &= ~VIDEO_MODE_MASK;
1218 reg |= VIDEO_MASTER_MODE_EN | VIDEO_MODE_MASTER_MODE;
1220 reg &= ~VIDEO_MODE_MASK;
1221 reg |= VIDEO_MODE_SLAVE_MODE;
1224 writel(reg, &dp_regs->soc_general_ctl);
1227 void exynos_dp_start_video(struct exynos_dp *dp_regs)
1231 /* Enable Video input and disable Mute */
1232 reg = readl(&dp_regs->video_ctl1);
1234 writel(reg, &dp_regs->video_ctl1);
1237 unsigned int exynos_dp_is_video_stream_on(struct exynos_dp *dp_regs)
1241 /* Update STRM_VALID */
1242 reg = readl(&dp_regs->sys_ctl3);
1243 writel(reg, &dp_regs->sys_ctl3);
1245 reg = readl(&dp_regs->sys_ctl3);
1246 if (!(reg & STRM_VALID))
1249 return EXYNOS_DP_SUCCESS;