2 * Copyright (C) 2012 Samsung Electronics
4 * Author: Donghwa Lee <dh09.lee@samsung.com>
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation; either version 2 of
9 * the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
24 #include <linux/err.h>
25 #include <asm/arch/cpu.h>
26 #include <asm/arch/dp_info.h>
27 #include <asm/arch/dp.h>
31 /* Declare global data pointer */
32 DECLARE_GLOBAL_DATA_PTR;
34 struct exynos_dp *dp_regs;
36 void exynos_dp_set_base_addr(void)
38 #ifdef CONFIG_OF_CONTROL
39 unsigned int node = fdtdec_next_compatible(gd->fdt_blob,
40 0, COMPAT_SAMSUNG_EXYNOS5_DP);
42 debug("exynos_dp: Can't get device node for dp\n");
44 dp_regs = (struct exynos_dp *)fdtdec_get_addr(gd->fdt_blob,
47 debug("Can't get the DP base address\n");
49 dp_regs = (struct exynos_dp *)samsung_get_base_dp();
53 static void exynos_dp_enable_video_input(unsigned int enable)
57 reg = readl(&dp_regs->video_ctl1);
58 reg &= ~VIDEO_EN_MASK;
60 /* enable video input*/
64 writel(reg, &dp_regs->video_ctl1);
69 void exynos_dp_enable_video_bist(unsigned int enable)
74 reg = readl(&dp_regs->video_ctl4);
75 reg &= ~VIDEO_BIST_MASK;
79 reg |= VIDEO_BIST_MASK;
81 writel(reg, &dp_regs->video_ctl4);
86 void exynos_dp_enable_video_mute(unsigned int enable)
90 reg = readl(&dp_regs->video_ctl1);
91 reg &= ~(VIDEO_MUTE_MASK);
93 reg |= VIDEO_MUTE_MASK;
95 writel(reg, &dp_regs->video_ctl1);
101 static void exynos_dp_init_analog_param(void)
107 * Normal bandgap, Normal swing, Tx terminal registor 61 ohm
108 * 24M Phy clock, TX digital logic power is 100:1.0625V
110 reg = SEL_BG_NEW_BANDGAP | TX_TERMINAL_CTRL_61_OHM |
111 SWING_A_30PER_G_NORMAL;
112 writel(reg, &dp_regs->analog_ctl1);
114 reg = SEL_24M | TX_DVDD_BIT_1_0625V;
115 writel(reg, &dp_regs->analog_ctl2);
118 * Set power source for internal clk driver to 1.0625v.
119 * Select current reference of TX driver current to 00:Ipp/2+Ic/2.
120 * Set VCO range of PLL +- 0uA
122 reg = DRIVE_DVDD_BIT_1_0625V | SEL_CURRENT_DEFAULT | VCO_BIT_000_MICRO;
123 writel(reg, &dp_regs->analog_ctl3);
126 * Set AUX TX terminal resistor to 102 ohm
127 * Set AUX channel amplitude control
129 reg = PD_RING_OSC | AUX_TERMINAL_CTRL_52_OHM | TX_CUR1_2X | TX_CUR_4_MA;
130 writel(reg, &dp_regs->pll_filter_ctl1);
133 * PLL loop filter bandwidth
134 * For 2.7Gbps: 175KHz, For 1.62Gbps: 234KHz
135 * PLL digital power select: 1.2500V
137 reg = CH3_AMP_0_MV | CH2_AMP_0_MV | CH1_AMP_0_MV | CH0_AMP_0_MV;
139 writel(reg, &dp_regs->amp_tuning_ctl);
142 * PLL loop filter bandwidth
143 * For 2.7Gbps: 175KHz, For 1.62Gbps: 234KHz
144 * PLL digital power select: 1.1250V
146 reg = DP_PLL_LOOP_BIT_DEFAULT | DP_PLL_REF_BIT_1_1250V;
147 writel(reg, &dp_regs->pll_ctl);
150 static void exynos_dp_init_interrupt(void)
152 /* Set interrupt registers to initial states */
156 * INT pin assertion polarity. It must be configured
157 * correctly according to ICU setting.
158 * 1 = assert high, 0 = assert low
160 writel(INT_POL, &dp_regs->int_ctl);
162 /* Clear pending regisers */
163 writel(0xff, &dp_regs->common_int_sta1);
164 writel(0xff, &dp_regs->common_int_sta2);
165 writel(0xff, &dp_regs->common_int_sta3);
166 writel(0xff, &dp_regs->common_int_sta4);
167 writel(0xff, &dp_regs->int_sta);
169 /* 0:mask,1: unmask */
170 writel(0x00, &dp_regs->int_sta_mask1);
171 writel(0x00, &dp_regs->int_sta_mask2);
172 writel(0x00, &dp_regs->int_sta_mask3);
173 writel(0x00, &dp_regs->int_sta_mask4);
174 writel(0x00, &dp_regs->int_sta_mask);
177 void exynos_dp_reset(void)
179 unsigned int reg_func_1;
182 writel(RESET_DP_TX, &dp_regs->tx_sw_reset);
184 exynos_dp_enable_video_input(DP_DISABLE);
185 exynos_dp_enable_video_bist(DP_DISABLE);
186 exynos_dp_enable_video_mute(DP_DISABLE);
189 reg_func_1 = MASTER_VID_FUNC_EN_N | SLAVE_VID_FUNC_EN_N |
190 AUD_FIFO_FUNC_EN_N | AUD_FUNC_EN_N |
191 HDCP_FUNC_EN_N | SW_FUNC_EN_N;
193 writel(reg_func_1, &dp_regs->func_en1);
194 writel(reg_func_1, &dp_regs->func_en2);
198 exynos_dp_init_analog_param();
199 exynos_dp_init_interrupt();
204 void exynos_dp_enable_sw_func(unsigned int enable)
208 reg = readl(&dp_regs->func_en1);
209 reg &= ~(SW_FUNC_EN_N);
214 writel(reg, &dp_regs->func_en1);
219 unsigned int exynos_dp_set_analog_power_down(unsigned int block, u32 enable)
223 reg = readl(&dp_regs->phy_pd);
256 reg &= ~(PHY_PD | AUX_PD | CH0_PD | CH1_PD | CH2_PD |
259 reg |= (PHY_PD | AUX_PD | CH0_PD | CH1_PD |
263 printf("DP undefined block number : %d\n", block);
267 writel(reg, &dp_regs->phy_pd);
272 unsigned int exynos_dp_get_pll_lock_status(void)
276 reg = readl(&dp_regs->debug_ctl);
284 static void exynos_dp_set_pll_power(unsigned int enable)
288 reg = readl(&dp_regs->pll_ctl);
294 writel(reg, &dp_regs->pll_ctl);
297 int exynos_dp_init_analog_func(void)
299 int ret = EXYNOS_DP_SUCCESS;
300 unsigned int retry_cnt = 10;
303 /*Power On All Analog block */
304 exynos_dp_set_analog_power_down(POWER_ALL, DP_DISABLE);
307 writel(reg, &dp_regs->common_int_sta1);
309 reg = readl(&dp_regs->debug_ctl);
310 reg &= ~(F_PLL_LOCK | PLL_LOCK_CTRL);
311 writel(reg, &dp_regs->debug_ctl);
313 /*Assert DP PLL Reset*/
314 reg = readl(&dp_regs->pll_ctl);
316 writel(reg, &dp_regs->pll_ctl);
320 /*Deassert DP PLL Reset*/
321 reg = readl(&dp_regs->pll_ctl);
322 reg &= ~(DP_PLL_RESET);
323 writel(reg, &dp_regs->pll_ctl);
325 exynos_dp_set_pll_power(DP_ENABLE);
327 while (exynos_dp_get_pll_lock_status() == PLL_UNLOCKED) {
330 if (retry_cnt == 0) {
331 printf("DP dp's pll lock failed : retry : %d\n",
337 debug("dp's pll lock success(%d)\n", retry_cnt);
339 /* Enable Serdes FIFO function and Link symbol clock domain module */
340 reg = readl(&dp_regs->func_en2);
341 reg &= ~(SERDES_FIFO_FUNC_EN_N | LS_CLK_DOMAIN_FUNC_EN_N
343 writel(reg, &dp_regs->func_en2);
348 void exynos_dp_init_hpd(void)
352 /* Clear interrupts releated to Hot Plug Dectect */
353 reg = HOTPLUG_CHG | HPD_LOST | PLUG;
354 writel(reg, &dp_regs->common_int_sta4);
357 writel(reg, &dp_regs->int_sta);
359 reg = readl(&dp_regs->sys_ctl3);
360 reg &= ~(F_HPD | HPD_CTRL);
361 writel(reg, &dp_regs->sys_ctl3);
366 static inline void exynos_dp_reset_aux(void)
370 /* Disable AUX channel module */
371 reg = readl(&dp_regs->func_en2);
372 reg |= AUX_FUNC_EN_N;
373 writel(reg, &dp_regs->func_en2);
378 void exynos_dp_init_aux(void)
382 /* Clear inerrupts related to AUX channel */
383 reg = RPLY_RECEIV | AUX_ERR;
384 writel(reg, &dp_regs->int_sta);
386 exynos_dp_reset_aux();
388 /* Disable AUX transaction H/W retry */
389 reg = AUX_BIT_PERIOD_EXPECTED_DELAY(3) | AUX_HW_RETRY_COUNT_SEL(3)|
390 AUX_HW_RETRY_INTERVAL_600_MICROSECONDS;
391 writel(reg, &dp_regs->aux_hw_retry_ctl);
393 /* Receive AUX Channel DEFER commands equal to DEFFER_COUNT*64 */
394 reg = DEFER_CTRL_EN | DEFER_COUNT(1);
395 writel(reg, &dp_regs->aux_ch_defer_ctl);
397 /* Enable AUX channel module */
398 reg = readl(&dp_regs->func_en2);
399 reg &= ~AUX_FUNC_EN_N;
400 writel(reg, &dp_regs->func_en2);
405 void exynos_dp_config_interrupt(void)
409 /* 0: mask, 1: unmask */
410 reg = COMMON_INT_MASK_1;
411 writel(reg, &dp_regs->common_int_mask1);
413 reg = COMMON_INT_MASK_2;
414 writel(reg, &dp_regs->common_int_mask2);
416 reg = COMMON_INT_MASK_3;
417 writel(reg, &dp_regs->common_int_mask3);
419 reg = COMMON_INT_MASK_4;
420 writel(reg, &dp_regs->common_int_mask4);
423 writel(reg, &dp_regs->int_sta_mask);
428 unsigned int exynos_dp_get_plug_in_status(void)
432 reg = readl(&dp_regs->sys_ctl3);
433 if (reg & HPD_STATUS)
439 unsigned int exynos_dp_detect_hpd(void)
441 int timeout_loop = DP_TIMEOUT_LOOP_COUNT;
445 while (exynos_dp_get_plug_in_status() != 0) {
446 if (timeout_loop == 0)
452 return EXYNOS_DP_SUCCESS;
455 unsigned int exynos_dp_start_aux_transaction(void)
458 unsigned int ret = 0;
459 unsigned int retry_cnt;
461 /* Enable AUX CH operation */
462 reg = readl(&dp_regs->aux_ch_ctl2);
464 writel(reg, &dp_regs->aux_ch_ctl2);
468 reg = readl(&dp_regs->int_sta);
469 if (!(reg & RPLY_RECEIV)) {
470 if (retry_cnt == 0) {
471 printf("DP Reply Timeout!!\n");
481 /* Clear interrupt source for AUX CH command reply */
482 writel(reg, &dp_regs->int_sta);
484 /* Clear interrupt source for AUX CH access error */
485 reg = readl(&dp_regs->int_sta);
487 printf("DP Aux Access Error\n");
488 writel(AUX_ERR, &dp_regs->int_sta);
493 /* Check AUX CH error access status */
494 reg = readl(&dp_regs->aux_ch_sta);
495 if ((reg & AUX_STATUS_MASK) != 0) {
496 debug("DP AUX CH error happens: %x\n", reg & AUX_STATUS_MASK);
501 return EXYNOS_DP_SUCCESS;
504 unsigned int exynos_dp_write_byte_to_dpcd(unsigned int reg_addr,
507 unsigned int reg, ret;
509 /* Clear AUX CH data buffer */
511 writel(reg, &dp_regs->buffer_data_ctl);
513 /* Select DPCD device address */
514 reg = AUX_ADDR_7_0(reg_addr);
515 writel(reg, &dp_regs->aux_addr_7_0);
516 reg = AUX_ADDR_15_8(reg_addr);
517 writel(reg, &dp_regs->aux_addr_15_8);
518 reg = AUX_ADDR_19_16(reg_addr);
519 writel(reg, &dp_regs->aux_addr_19_16);
521 /* Write data buffer */
522 reg = (unsigned int)data;
523 writel(reg, &dp_regs->buf_data0);
526 * Set DisplayPort transaction and write 1 byte
527 * If bit 3 is 1, DisplayPort transaction.
528 * If Bit 3 is 0, I2C transaction.
530 reg = AUX_TX_COMM_DP_TRANSACTION | AUX_TX_COMM_WRITE;
531 writel(reg, &dp_regs->aux_ch_ctl1);
533 /* Start AUX transaction */
534 ret = exynos_dp_start_aux_transaction();
535 if (ret != EXYNOS_DP_SUCCESS) {
536 printf("DP Aux transaction failed\n");
543 unsigned int exynos_dp_read_byte_from_dpcd(unsigned int reg_addr,
549 /* Clear AUX CH data buffer */
551 writel(reg, &dp_regs->buffer_data_ctl);
553 /* Select DPCD device address */
554 reg = AUX_ADDR_7_0(reg_addr);
555 writel(reg, &dp_regs->aux_addr_7_0);
556 reg = AUX_ADDR_15_8(reg_addr);
557 writel(reg, &dp_regs->aux_addr_15_8);
558 reg = AUX_ADDR_19_16(reg_addr);
559 writel(reg, &dp_regs->aux_addr_19_16);
562 * Set DisplayPort transaction and read 1 byte
563 * If bit 3 is 1, DisplayPort transaction.
564 * If Bit 3 is 0, I2C transaction.
566 reg = AUX_TX_COMM_DP_TRANSACTION | AUX_TX_COMM_READ;
567 writel(reg, &dp_regs->aux_ch_ctl1);
569 /* Start AUX transaction */
570 retval = exynos_dp_start_aux_transaction();
572 debug("DP Aux Transaction fail!\n");
574 /* Read data buffer */
575 reg = readl(&dp_regs->buf_data0);
576 *data = (unsigned char)(reg & 0xff);
581 unsigned int exynos_dp_write_bytes_to_dpcd(unsigned int reg_addr,
583 unsigned char data[])
586 unsigned int start_offset;
587 unsigned int cur_data_count;
588 unsigned int cur_data_idx;
589 unsigned int retry_cnt;
590 unsigned int ret = 0;
592 /* Clear AUX CH data buffer */
594 writel(reg, &dp_regs->buffer_data_ctl);
597 while (start_offset < count) {
598 /* Buffer size of AUX CH is 16 * 4bytes */
599 if ((count - start_offset) > 16)
602 cur_data_count = count - start_offset;
606 /* Select DPCD device address */
607 reg = AUX_ADDR_7_0(reg_addr + start_offset);
608 writel(reg, &dp_regs->aux_addr_7_0);
609 reg = AUX_ADDR_15_8(reg_addr + start_offset);
610 writel(reg, &dp_regs->aux_addr_15_8);
611 reg = AUX_ADDR_19_16(reg_addr + start_offset);
612 writel(reg, &dp_regs->aux_addr_19_16);
614 for (cur_data_idx = 0; cur_data_idx < cur_data_count;
616 reg = data[start_offset + cur_data_idx];
617 writel(reg, (unsigned int)&dp_regs->buf_data0 +
621 * Set DisplayPort transaction and write
622 * If bit 3 is 1, DisplayPort transaction.
623 * If Bit 3 is 0, I2C transaction.
625 reg = AUX_LENGTH(cur_data_count) |
626 AUX_TX_COMM_DP_TRANSACTION | AUX_TX_COMM_WRITE;
627 writel(reg, &dp_regs->aux_ch_ctl1);
629 /* Start AUX transaction */
630 ret = exynos_dp_start_aux_transaction();
631 if (ret != EXYNOS_DP_SUCCESS) {
632 if (retry_cnt == 0) {
633 printf("DP Aux Transaction failed\n");
640 start_offset += cur_data_count;
646 unsigned int exynos_dp_read_bytes_from_dpcd(unsigned int reg_addr,
648 unsigned char data[])
651 unsigned int start_offset;
652 unsigned int cur_data_count;
653 unsigned int cur_data_idx;
654 unsigned int retry_cnt;
655 unsigned int ret = 0;
657 /* Clear AUX CH data buffer */
659 writel(reg, &dp_regs->buffer_data_ctl);
662 while (start_offset < count) {
663 /* Buffer size of AUX CH is 16 * 4bytes */
664 if ((count - start_offset) > 16)
667 cur_data_count = count - start_offset;
671 /* Select DPCD device address */
672 reg = AUX_ADDR_7_0(reg_addr + start_offset);
673 writel(reg, &dp_regs->aux_addr_7_0);
674 reg = AUX_ADDR_15_8(reg_addr + start_offset);
675 writel(reg, &dp_regs->aux_addr_15_8);
676 reg = AUX_ADDR_19_16(reg_addr + start_offset);
677 writel(reg, &dp_regs->aux_addr_19_16);
679 * Set DisplayPort transaction and read
680 * If bit 3 is 1, DisplayPort transaction.
681 * If Bit 3 is 0, I2C transaction.
683 reg = AUX_LENGTH(cur_data_count) |
684 AUX_TX_COMM_DP_TRANSACTION | AUX_TX_COMM_READ;
685 writel(reg, &dp_regs->aux_ch_ctl1);
687 /* Start AUX transaction */
688 ret = exynos_dp_start_aux_transaction();
689 if (ret != EXYNOS_DP_SUCCESS) {
690 if (retry_cnt == 0) {
691 printf("DP Aux Transaction failed\n");
699 for (cur_data_idx = 0; cur_data_idx < cur_data_count;
701 reg = readl((unsigned int)&dp_regs->buf_data0 +
703 data[start_offset + cur_data_idx] = (unsigned char)reg;
706 start_offset += cur_data_count;
712 int exynos_dp_select_i2c_device(unsigned int device_addr,
713 unsigned int reg_addr)
718 /* Set EDID device address */
720 writel(reg, &dp_regs->aux_addr_7_0);
721 writel(0x0, &dp_regs->aux_addr_15_8);
722 writel(0x0, &dp_regs->aux_addr_19_16);
724 /* Set offset from base address of EDID device */
725 writel(reg_addr, &dp_regs->buf_data0);
728 * Set I2C transaction and write address
729 * If bit 3 is 1, DisplayPort transaction.
730 * If Bit 3 is 0, I2C transaction.
732 reg = AUX_TX_COMM_I2C_TRANSACTION | AUX_TX_COMM_MOT |
734 writel(reg, &dp_regs->aux_ch_ctl1);
736 /* Start AUX transaction */
737 retval = exynos_dp_start_aux_transaction();
739 printf("%s: DP Aux Transaction fail!\n", __func__);
744 int exynos_dp_read_byte_from_i2c(unsigned int device_addr,
745 unsigned int reg_addr,
752 for (i = 0; i < 10; i++) {
753 /* Clear AUX CH data buffer */
755 writel(reg, &dp_regs->buffer_data_ctl);
757 /* Select EDID device */
758 retval = exynos_dp_select_i2c_device(device_addr, reg_addr);
760 printf("DP Select EDID device fail. retry !\n");
765 * Set I2C transaction and read data
766 * If bit 3 is 1, DisplayPort transaction.
767 * If Bit 3 is 0, I2C transaction.
769 reg = AUX_TX_COMM_I2C_TRANSACTION |
771 writel(reg, &dp_regs->aux_ch_ctl1);
773 /* Start AUX transaction */
774 retval = exynos_dp_start_aux_transaction();
775 if (retval != EXYNOS_DP_SUCCESS)
776 printf("%s: DP Aux Transaction fail!\n", __func__);
781 *data = readl(&dp_regs->buf_data0);
786 int exynos_dp_read_bytes_from_i2c(unsigned int device_addr,
787 unsigned int reg_addr, unsigned int count, unsigned char edid[])
791 unsigned int cur_data_idx;
792 unsigned int defer = 0;
795 for (i = 0; i < count; i += 16) { /* use 16 burst */
796 for (j = 0; j < 100; j++) {
797 /* Clear AUX CH data buffer */
799 writel(reg, &dp_regs->buffer_data_ctl);
801 /* Set normal AUX CH command */
802 reg = readl(&dp_regs->aux_ch_ctl2);
804 writel(reg, &dp_regs->aux_ch_ctl2);
807 * If Rx sends defer, Tx sends only reads
808 * request without sending addres
812 exynos_dp_select_i2c_device(device_addr,
817 if (retval == EXYNOS_DP_SUCCESS) {
819 * Set I2C transaction and write data
820 * If bit 3 is 1, DisplayPort transaction.
821 * If Bit 3 is 0, I2C transaction.
823 reg = AUX_LENGTH(16) |
824 AUX_TX_COMM_I2C_TRANSACTION |
826 writel(reg, &dp_regs->aux_ch_ctl1);
828 /* Start AUX transaction */
829 retval = exynos_dp_start_aux_transaction();
833 printf("DP Aux Transaction fail!\n");
835 /* Check if Rx sends defer */
836 reg = readl(&dp_regs->aux_rx_comm);
837 if (reg == AUX_RX_COMM_AUX_DEFER ||
838 reg == AUX_RX_COMM_I2C_DEFER) {
839 printf("DP Defer: %d\n\n", reg);
844 for (cur_data_idx = 0; cur_data_idx < 16; cur_data_idx++) {
845 reg = readl((unsigned int)&dp_regs->buf_data0
847 edid[i + cur_data_idx] = (unsigned char)reg;
854 void exynos_dp_reset_macro(void)
858 reg = readl(&dp_regs->phy_test);
860 writel(reg, &dp_regs->phy_test);
862 /* 10 us is the minimum Macro reset time. */
866 writel(reg, &dp_regs->phy_test);
869 void exynos_dp_set_link_bandwidth(unsigned char bwtype)
873 reg = (unsigned int)bwtype;
875 /* Set bandwidth to 2.7G or 1.62G */
876 if ((bwtype == DP_LANE_BW_1_62) || (bwtype == DP_LANE_BW_2_70))
877 writel(reg, &dp_regs->link_bw_set);
880 unsigned char exynos_dp_get_link_bandwidth(void)
885 reg = readl(&dp_regs->link_bw_set);
886 ret = (unsigned char)reg;
891 void exynos_dp_set_lane_count(unsigned char count)
895 reg = (unsigned int)count;
897 if ((count == DP_LANE_CNT_1) || (count == DP_LANE_CNT_2) ||
898 (count == DP_LANE_CNT_4))
899 writel(reg, &dp_regs->lane_count_set);
902 unsigned int exynos_dp_get_lane_count(void)
906 reg = readl(&dp_regs->lane_count_set);
911 unsigned char exynos_dp_get_lanex_pre_emphasis(unsigned char lanecnt)
913 unsigned int reg_list[DP_LANE_CNT_4] = {
914 (unsigned int)&dp_regs->ln0_link_training_ctl,
915 (unsigned int)&dp_regs->ln1_link_training_ctl,
916 (unsigned int)&dp_regs->ln2_link_training_ctl,
917 (unsigned int)&dp_regs->ln3_link_training_ctl,
920 return readl(reg_list[lanecnt]);
923 void exynos_dp_set_lanex_pre_emphasis(unsigned char request_val,
924 unsigned char lanecnt)
926 unsigned int reg_list[DP_LANE_CNT_4] = {
927 (unsigned int)&dp_regs->ln0_link_training_ctl,
928 (unsigned int)&dp_regs->ln1_link_training_ctl,
929 (unsigned int)&dp_regs->ln2_link_training_ctl,
930 (unsigned int)&dp_regs->ln3_link_training_ctl,
933 writel(request_val, reg_list[lanecnt]);
936 void exynos_dp_set_lane_pre_emphasis(unsigned int level, unsigned char lanecnt)
940 unsigned int reg_list[DP_LANE_CNT_4] = {
941 (unsigned int)&dp_regs->ln0_link_training_ctl,
942 (unsigned int)&dp_regs->ln1_link_training_ctl,
943 (unsigned int)&dp_regs->ln2_link_training_ctl,
944 (unsigned int)&dp_regs->ln3_link_training_ctl,
946 unsigned int reg_shift[DP_LANE_CNT_4] = {
947 PRE_EMPHASIS_SET_0_SHIFT,
948 PRE_EMPHASIS_SET_1_SHIFT,
949 PRE_EMPHASIS_SET_2_SHIFT,
950 PRE_EMPHASIS_SET_3_SHIFT
953 for (i = 0; i < lanecnt; i++) {
954 reg = level << reg_shift[i];
955 writel(reg, reg_list[i]);
959 void exynos_dp_set_training_pattern(unsigned int pattern)
961 unsigned int reg = 0;
965 reg = SCRAMBLING_ENABLE | LINK_QUAL_PATTERN_SET_PRBS7;
968 reg = SCRAMBLING_ENABLE | LINK_QUAL_PATTERN_SET_D10_2;
971 reg = SCRAMBLING_DISABLE | SW_TRAINING_PATTERN_SET_PTN1;
974 reg = SCRAMBLING_DISABLE | SW_TRAINING_PATTERN_SET_PTN2;
977 reg = SCRAMBLING_ENABLE | LINK_QUAL_PATTERN_SET_DISABLE |
978 SW_TRAINING_PATTERN_SET_NORMAL;
984 writel(reg, &dp_regs->training_ptn_set);
987 void exynos_dp_enable_enhanced_mode(unsigned char enable)
991 reg = readl(&dp_regs->sys_ctl4);
997 writel(reg, &dp_regs->sys_ctl4);
1000 void exynos_dp_enable_scrambling(unsigned int enable)
1004 reg = readl(&dp_regs->training_ptn_set);
1005 reg &= ~(SCRAMBLING_DISABLE);
1008 reg |= SCRAMBLING_DISABLE;
1010 writel(reg, &dp_regs->training_ptn_set);
1013 int exynos_dp_init_video(void)
1017 /* Clear VID_CLK_CHG[1] and VID_FORMAT_CHG[3] and VSYNC_DET[7] */
1018 reg = VSYNC_DET | VID_FORMAT_CHG | VID_CLK_CHG;
1019 writel(reg, &dp_regs->common_int_sta1);
1021 /* I_STRM__CLK detect : DE_CTL : Auto detect */
1023 writel(reg, &dp_regs->sys_ctl1);
1028 void exynos_dp_config_video_slave_mode(struct edp_video_info *video_info)
1032 /* Video Slave mode setting */
1033 reg = readl(&dp_regs->func_en1);
1034 reg &= ~(MASTER_VID_FUNC_EN_N|SLAVE_VID_FUNC_EN_N);
1035 reg |= MASTER_VID_FUNC_EN_N;
1036 writel(reg, &dp_regs->func_en1);
1038 /* Configure Interlaced for slave mode video */
1039 reg = readl(&dp_regs->video_ctl10);
1040 reg &= ~INTERACE_SCAN_CFG;
1041 reg |= (video_info->interlaced << INTERACE_SCAN_CFG_SHIFT);
1042 writel(reg, &dp_regs->video_ctl10);
1044 /* Configure V sync polarity for slave mode video */
1045 reg = readl(&dp_regs->video_ctl10);
1046 reg &= ~VSYNC_POLARITY_CFG;
1047 reg |= (video_info->v_sync_polarity << V_S_POLARITY_CFG_SHIFT);
1048 writel(reg, &dp_regs->video_ctl10);
1050 /* Configure H sync polarity for slave mode video */
1051 reg = readl(&dp_regs->video_ctl10);
1052 reg &= ~HSYNC_POLARITY_CFG;
1053 reg |= (video_info->h_sync_polarity << H_S_POLARITY_CFG_SHIFT);
1054 writel(reg, &dp_regs->video_ctl10);
1056 /*Set video mode to slave mode */
1057 reg = AUDIO_MODE_SPDIF_MODE | VIDEO_MODE_SLAVE_MODE;
1058 writel(reg, &dp_regs->soc_general_ctl);
1061 void exynos_dp_set_video_color_format(struct edp_video_info *video_info)
1065 /* Configure the input color depth, color space, dynamic range */
1066 reg = (video_info->dynamic_range << IN_D_RANGE_SHIFT) |
1067 (video_info->color_depth << IN_BPC_SHIFT) |
1068 (video_info->color_space << IN_COLOR_F_SHIFT);
1069 writel(reg, &dp_regs->video_ctl2);
1071 /* Set Input Color YCbCr Coefficients to ITU601 or ITU709 */
1072 reg = readl(&dp_regs->video_ctl3);
1073 reg &= ~IN_YC_COEFFI_MASK;
1074 if (video_info->ycbcr_coeff)
1075 reg |= IN_YC_COEFFI_ITU709;
1077 reg |= IN_YC_COEFFI_ITU601;
1078 writel(reg, &dp_regs->video_ctl3);
1081 int exynos_dp_config_video_bist(struct edp_device_info *edp_info)
1084 unsigned int bist_type = 0;
1085 struct edp_video_info video_info = edp_info->video_info;
1087 /* For master mode, you don't need to set the video format */
1088 if (video_info.master_mode == 0) {
1089 writel(TOTAL_LINE_CFG_L(edp_info->disp_info.v_total),
1090 &dp_regs->total_ln_cfg_l);
1091 writel(TOTAL_LINE_CFG_H(edp_info->disp_info.v_total),
1092 &dp_regs->total_ln_cfg_h);
1093 writel(ACTIVE_LINE_CFG_L(edp_info->disp_info.v_res),
1094 &dp_regs->active_ln_cfg_l);
1095 writel(ACTIVE_LINE_CFG_H(edp_info->disp_info.v_res),
1096 &dp_regs->active_ln_cfg_h);
1097 writel(edp_info->disp_info.v_sync_width,
1099 writel(edp_info->disp_info.v_back_porch,
1101 writel(edp_info->disp_info.v_front_porch,
1104 writel(TOTAL_PIXEL_CFG_L(edp_info->disp_info.h_total),
1105 &dp_regs->total_pix_cfg_l);
1106 writel(TOTAL_PIXEL_CFG_H(edp_info->disp_info.h_total),
1107 &dp_regs->total_pix_cfg_h);
1108 writel(ACTIVE_PIXEL_CFG_L(edp_info->disp_info.h_res),
1109 &dp_regs->active_pix_cfg_l);
1110 writel(ACTIVE_PIXEL_CFG_H(edp_info->disp_info.h_res),
1111 &dp_regs->active_pix_cfg_h);
1112 writel(H_F_PORCH_CFG_L(edp_info->disp_info.h_front_porch),
1113 &dp_regs->hfp_cfg_l);
1114 writel(H_F_PORCH_CFG_H(edp_info->disp_info.h_front_porch),
1115 &dp_regs->hfp_cfg_h);
1116 writel(H_SYNC_PORCH_CFG_L(edp_info->disp_info.h_sync_width),
1117 &dp_regs->hsw_cfg_l);
1118 writel(H_SYNC_PORCH_CFG_H(edp_info->disp_info.h_sync_width),
1119 &dp_regs->hsw_cfg_h);
1120 writel(H_B_PORCH_CFG_L(edp_info->disp_info.h_back_porch),
1121 &dp_regs->hbp_cfg_l);
1122 writel(H_B_PORCH_CFG_H(edp_info->disp_info.h_back_porch),
1123 &dp_regs->hbp_cfg_h);
1126 * Set SLAVE_I_SCAN_CFG[2], VSYNC_P_CFG[1],
1127 * HSYNC_P_CFG[0] properly
1129 reg = (video_info.interlaced << INTERACE_SCAN_CFG_SHIFT |
1130 video_info.v_sync_polarity << V_S_POLARITY_CFG_SHIFT |
1131 video_info.h_sync_polarity << H_S_POLARITY_CFG_SHIFT);
1132 writel(reg, &dp_regs->video_ctl10);
1135 /* BIST color bar width set--set to each bar is 32 pixel width */
1136 switch (video_info.bist_pattern) {
1138 bist_type = BIST_WIDTH_BAR_32_PIXEL |
1139 BIST_TYPE_COLOR_BAR;
1142 bist_type = BIST_WIDTH_BAR_64_PIXEL |
1143 BIST_TYPE_COLOR_BAR;
1145 case WHITE_GRAY_BALCKBAR_32:
1146 bist_type = BIST_WIDTH_BAR_32_PIXEL |
1147 BIST_TYPE_WHITE_GRAY_BLACK_BAR;
1149 case WHITE_GRAY_BALCKBAR_64:
1150 bist_type = BIST_WIDTH_BAR_64_PIXEL |
1151 BIST_TYPE_WHITE_GRAY_BLACK_BAR;
1153 case MOBILE_WHITEBAR_32:
1154 bist_type = BIST_WIDTH_BAR_32_PIXEL |
1155 BIST_TYPE_MOBILE_WHITE_BAR;
1157 case MOBILE_WHITEBAR_64:
1158 bist_type = BIST_WIDTH_BAR_64_PIXEL |
1159 BIST_TYPE_MOBILE_WHITE_BAR;
1166 writel(reg, &dp_regs->video_ctl4);
1171 unsigned int exynos_dp_is_slave_video_stream_clock_on(void)
1175 /* Update Video stream clk detect status */
1176 reg = readl(&dp_regs->sys_ctl1);
1177 writel(reg, &dp_regs->sys_ctl1);
1179 reg = readl(&dp_regs->sys_ctl1);
1181 if (!(reg & DET_STA)) {
1182 debug("DP Input stream clock not detected.\n");
1186 return EXYNOS_DP_SUCCESS;
1189 void exynos_dp_set_video_cr_mn(unsigned int type, unsigned int m_value,
1190 unsigned int n_value)
1194 if (type == REGISTER_M) {
1195 reg = readl(&dp_regs->sys_ctl4);
1197 writel(reg, &dp_regs->sys_ctl4);
1198 reg = M_VID0_CFG(m_value);
1199 writel(reg, &dp_regs->m_vid0);
1200 reg = M_VID1_CFG(m_value);
1201 writel(reg, &dp_regs->m_vid1);
1202 reg = M_VID2_CFG(m_value);
1203 writel(reg, &dp_regs->m_vid2);
1205 reg = N_VID0_CFG(n_value);
1206 writel(reg, &dp_regs->n_vid0);
1207 reg = N_VID1_CFG(n_value);
1208 writel(reg, &dp_regs->n_vid1);
1209 reg = N_VID2_CFG(n_value);
1210 writel(reg, &dp_regs->n_vid2);
1212 reg = readl(&dp_regs->sys_ctl4);
1214 writel(reg, &dp_regs->sys_ctl4);
1218 void exynos_dp_set_video_timing_mode(unsigned int type)
1222 reg = readl(&dp_regs->video_ctl10);
1225 if (type != VIDEO_TIMING_FROM_CAPTURE)
1228 writel(reg, &dp_regs->video_ctl10);
1231 void exynos_dp_enable_video_master(unsigned int enable)
1235 reg = readl(&dp_regs->soc_general_ctl);
1237 reg &= ~VIDEO_MODE_MASK;
1238 reg |= VIDEO_MASTER_MODE_EN | VIDEO_MODE_MASTER_MODE;
1240 reg &= ~VIDEO_MODE_MASK;
1241 reg |= VIDEO_MODE_SLAVE_MODE;
1244 writel(reg, &dp_regs->soc_general_ctl);
1247 void exynos_dp_start_video(void)
1251 /* Enable Video input and disable Mute */
1252 reg = readl(&dp_regs->video_ctl1);
1254 writel(reg, &dp_regs->video_ctl1);
1257 unsigned int exynos_dp_is_video_stream_on(void)
1261 /* Update STRM_VALID */
1262 reg = readl(&dp_regs->sys_ctl3);
1263 writel(reg, &dp_regs->sys_ctl3);
1265 reg = readl(&dp_regs->sys_ctl3);
1266 if (!(reg & STRM_VALID))
1269 return EXYNOS_DP_SUCCESS;