2 * Copyright (C) 2012 Samsung Electronics
4 * Author: Donghwa Lee <dh09.lee@samsung.com>
6 * SPDX-License-Identifier: GPL-2.0+
11 #include <linux/err.h>
12 #include <asm/arch/cpu.h>
13 #include <asm/arch/dp_info.h>
14 #include <asm/arch/dp.h>
18 /* Declare global data pointer */
19 DECLARE_GLOBAL_DATA_PTR;
21 struct exynos_dp *dp_regs;
23 void exynos_dp_set_base_addr(void)
25 #ifdef CONFIG_OF_CONTROL
26 unsigned int node = fdtdec_next_compatible(gd->fdt_blob,
27 0, COMPAT_SAMSUNG_EXYNOS5_DP);
29 debug("exynos_dp: Can't get device node for dp\n");
31 dp_regs = (struct exynos_dp *)fdtdec_get_addr(gd->fdt_blob,
34 debug("Can't get the DP base address\n");
36 dp_regs = (struct exynos_dp *)samsung_get_base_dp();
40 static void exynos_dp_enable_video_input(unsigned int enable)
44 reg = readl(&dp_regs->video_ctl1);
45 reg &= ~VIDEO_EN_MASK;
47 /* enable video input*/
51 writel(reg, &dp_regs->video_ctl1);
56 void exynos_dp_enable_video_bist(unsigned int enable)
61 reg = readl(&dp_regs->video_ctl4);
62 reg &= ~VIDEO_BIST_MASK;
66 reg |= VIDEO_BIST_MASK;
68 writel(reg, &dp_regs->video_ctl4);
73 void exynos_dp_enable_video_mute(unsigned int enable)
77 reg = readl(&dp_regs->video_ctl1);
78 reg &= ~(VIDEO_MUTE_MASK);
80 reg |= VIDEO_MUTE_MASK;
82 writel(reg, &dp_regs->video_ctl1);
88 static void exynos_dp_init_analog_param(void)
94 * Normal bandgap, Normal swing, Tx terminal registor 61 ohm
95 * 24M Phy clock, TX digital logic power is 100:1.0625V
97 reg = SEL_BG_NEW_BANDGAP | TX_TERMINAL_CTRL_61_OHM |
98 SWING_A_30PER_G_NORMAL;
99 writel(reg, &dp_regs->analog_ctl1);
101 reg = SEL_24M | TX_DVDD_BIT_1_0625V;
102 writel(reg, &dp_regs->analog_ctl2);
105 * Set power source for internal clk driver to 1.0625v.
106 * Select current reference of TX driver current to 00:Ipp/2+Ic/2.
107 * Set VCO range of PLL +- 0uA
109 reg = DRIVE_DVDD_BIT_1_0625V | SEL_CURRENT_DEFAULT | VCO_BIT_000_MICRO;
110 writel(reg, &dp_regs->analog_ctl3);
113 * Set AUX TX terminal resistor to 102 ohm
114 * Set AUX channel amplitude control
116 reg = PD_RING_OSC | AUX_TERMINAL_CTRL_52_OHM | TX_CUR1_2X | TX_CUR_4_MA;
117 writel(reg, &dp_regs->pll_filter_ctl1);
120 * PLL loop filter bandwidth
121 * For 2.7Gbps: 175KHz, For 1.62Gbps: 234KHz
122 * PLL digital power select: 1.2500V
124 reg = CH3_AMP_0_MV | CH2_AMP_0_MV | CH1_AMP_0_MV | CH0_AMP_0_MV;
126 writel(reg, &dp_regs->amp_tuning_ctl);
129 * PLL loop filter bandwidth
130 * For 2.7Gbps: 175KHz, For 1.62Gbps: 234KHz
131 * PLL digital power select: 1.1250V
133 reg = DP_PLL_LOOP_BIT_DEFAULT | DP_PLL_REF_BIT_1_1250V;
134 writel(reg, &dp_regs->pll_ctl);
137 static void exynos_dp_init_interrupt(void)
139 /* Set interrupt registers to initial states */
143 * INT pin assertion polarity. It must be configured
144 * correctly according to ICU setting.
145 * 1 = assert high, 0 = assert low
147 writel(INT_POL, &dp_regs->int_ctl);
149 /* Clear pending regisers */
150 writel(0xff, &dp_regs->common_int_sta1);
151 writel(0xff, &dp_regs->common_int_sta2);
152 writel(0xff, &dp_regs->common_int_sta3);
153 writel(0xff, &dp_regs->common_int_sta4);
154 writel(0xff, &dp_regs->int_sta);
156 /* 0:mask,1: unmask */
157 writel(0x00, &dp_regs->int_sta_mask1);
158 writel(0x00, &dp_regs->int_sta_mask2);
159 writel(0x00, &dp_regs->int_sta_mask3);
160 writel(0x00, &dp_regs->int_sta_mask4);
161 writel(0x00, &dp_regs->int_sta_mask);
164 void exynos_dp_reset(void)
166 unsigned int reg_func_1;
169 writel(RESET_DP_TX, &dp_regs->tx_sw_reset);
171 exynos_dp_enable_video_input(DP_DISABLE);
172 exynos_dp_enable_video_bist(DP_DISABLE);
173 exynos_dp_enable_video_mute(DP_DISABLE);
176 reg_func_1 = MASTER_VID_FUNC_EN_N | SLAVE_VID_FUNC_EN_N |
177 AUD_FIFO_FUNC_EN_N | AUD_FUNC_EN_N |
178 HDCP_FUNC_EN_N | SW_FUNC_EN_N;
180 writel(reg_func_1, &dp_regs->func_en1);
181 writel(reg_func_1, &dp_regs->func_en2);
185 exynos_dp_init_analog_param();
186 exynos_dp_init_interrupt();
191 void exynos_dp_enable_sw_func(unsigned int enable)
195 reg = readl(&dp_regs->func_en1);
196 reg &= ~(SW_FUNC_EN_N);
201 writel(reg, &dp_regs->func_en1);
206 unsigned int exynos_dp_set_analog_power_down(unsigned int block, u32 enable)
210 reg = readl(&dp_regs->phy_pd);
243 reg &= ~(PHY_PD | AUX_PD | CH0_PD | CH1_PD | CH2_PD |
246 reg |= (PHY_PD | AUX_PD | CH0_PD | CH1_PD |
250 printf("DP undefined block number : %d\n", block);
254 writel(reg, &dp_regs->phy_pd);
259 unsigned int exynos_dp_get_pll_lock_status(void)
263 reg = readl(&dp_regs->debug_ctl);
271 static void exynos_dp_set_pll_power(unsigned int enable)
275 reg = readl(&dp_regs->pll_ctl);
281 writel(reg, &dp_regs->pll_ctl);
284 int exynos_dp_init_analog_func(void)
286 int ret = EXYNOS_DP_SUCCESS;
287 unsigned int retry_cnt = 10;
290 /*Power On All Analog block */
291 exynos_dp_set_analog_power_down(POWER_ALL, DP_DISABLE);
294 writel(reg, &dp_regs->common_int_sta1);
296 reg = readl(&dp_regs->debug_ctl);
297 reg &= ~(F_PLL_LOCK | PLL_LOCK_CTRL);
298 writel(reg, &dp_regs->debug_ctl);
300 /*Assert DP PLL Reset*/
301 reg = readl(&dp_regs->pll_ctl);
303 writel(reg, &dp_regs->pll_ctl);
307 /*Deassert DP PLL Reset*/
308 reg = readl(&dp_regs->pll_ctl);
309 reg &= ~(DP_PLL_RESET);
310 writel(reg, &dp_regs->pll_ctl);
312 exynos_dp_set_pll_power(DP_ENABLE);
314 while (exynos_dp_get_pll_lock_status() == PLL_UNLOCKED) {
317 if (retry_cnt == 0) {
318 printf("DP dp's pll lock failed : retry : %d\n",
324 debug("dp's pll lock success(%d)\n", retry_cnt);
326 /* Enable Serdes FIFO function and Link symbol clock domain module */
327 reg = readl(&dp_regs->func_en2);
328 reg &= ~(SERDES_FIFO_FUNC_EN_N | LS_CLK_DOMAIN_FUNC_EN_N
330 writel(reg, &dp_regs->func_en2);
335 void exynos_dp_init_hpd(void)
339 /* Clear interrupts releated to Hot Plug Dectect */
340 reg = HOTPLUG_CHG | HPD_LOST | PLUG;
341 writel(reg, &dp_regs->common_int_sta4);
344 writel(reg, &dp_regs->int_sta);
346 reg = readl(&dp_regs->sys_ctl3);
347 reg &= ~(F_HPD | HPD_CTRL);
348 writel(reg, &dp_regs->sys_ctl3);
353 static inline void exynos_dp_reset_aux(void)
357 /* Disable AUX channel module */
358 reg = readl(&dp_regs->func_en2);
359 reg |= AUX_FUNC_EN_N;
360 writel(reg, &dp_regs->func_en2);
365 void exynos_dp_init_aux(void)
369 /* Clear inerrupts related to AUX channel */
370 reg = RPLY_RECEIV | AUX_ERR;
371 writel(reg, &dp_regs->int_sta);
373 exynos_dp_reset_aux();
375 /* Disable AUX transaction H/W retry */
376 reg = AUX_BIT_PERIOD_EXPECTED_DELAY(3) | AUX_HW_RETRY_COUNT_SEL(3)|
377 AUX_HW_RETRY_INTERVAL_600_MICROSECONDS;
378 writel(reg, &dp_regs->aux_hw_retry_ctl);
380 /* Receive AUX Channel DEFER commands equal to DEFFER_COUNT*64 */
381 reg = DEFER_CTRL_EN | DEFER_COUNT(1);
382 writel(reg, &dp_regs->aux_ch_defer_ctl);
384 /* Enable AUX channel module */
385 reg = readl(&dp_regs->func_en2);
386 reg &= ~AUX_FUNC_EN_N;
387 writel(reg, &dp_regs->func_en2);
392 void exynos_dp_config_interrupt(void)
396 /* 0: mask, 1: unmask */
397 reg = COMMON_INT_MASK_1;
398 writel(reg, &dp_regs->common_int_mask1);
400 reg = COMMON_INT_MASK_2;
401 writel(reg, &dp_regs->common_int_mask2);
403 reg = COMMON_INT_MASK_3;
404 writel(reg, &dp_regs->common_int_mask3);
406 reg = COMMON_INT_MASK_4;
407 writel(reg, &dp_regs->common_int_mask4);
410 writel(reg, &dp_regs->int_sta_mask);
415 unsigned int exynos_dp_get_plug_in_status(void)
419 reg = readl(&dp_regs->sys_ctl3);
420 if (reg & HPD_STATUS)
426 unsigned int exynos_dp_detect_hpd(void)
428 int timeout_loop = DP_TIMEOUT_LOOP_COUNT;
432 while (exynos_dp_get_plug_in_status() != 0) {
433 if (timeout_loop == 0)
439 return EXYNOS_DP_SUCCESS;
442 unsigned int exynos_dp_start_aux_transaction(void)
445 unsigned int ret = 0;
446 unsigned int retry_cnt;
448 /* Enable AUX CH operation */
449 reg = readl(&dp_regs->aux_ch_ctl2);
451 writel(reg, &dp_regs->aux_ch_ctl2);
455 reg = readl(&dp_regs->int_sta);
456 if (!(reg & RPLY_RECEIV)) {
457 if (retry_cnt == 0) {
458 printf("DP Reply Timeout!!\n");
468 /* Clear interrupt source for AUX CH command reply */
469 writel(reg, &dp_regs->int_sta);
471 /* Clear interrupt source for AUX CH access error */
472 reg = readl(&dp_regs->int_sta);
474 printf("DP Aux Access Error\n");
475 writel(AUX_ERR, &dp_regs->int_sta);
480 /* Check AUX CH error access status */
481 reg = readl(&dp_regs->aux_ch_sta);
482 if ((reg & AUX_STATUS_MASK) != 0) {
483 debug("DP AUX CH error happens: %x\n", reg & AUX_STATUS_MASK);
488 return EXYNOS_DP_SUCCESS;
491 unsigned int exynos_dp_write_byte_to_dpcd(unsigned int reg_addr,
494 unsigned int reg, ret;
496 /* Clear AUX CH data buffer */
498 writel(reg, &dp_regs->buffer_data_ctl);
500 /* Select DPCD device address */
501 reg = AUX_ADDR_7_0(reg_addr);
502 writel(reg, &dp_regs->aux_addr_7_0);
503 reg = AUX_ADDR_15_8(reg_addr);
504 writel(reg, &dp_regs->aux_addr_15_8);
505 reg = AUX_ADDR_19_16(reg_addr);
506 writel(reg, &dp_regs->aux_addr_19_16);
508 /* Write data buffer */
509 reg = (unsigned int)data;
510 writel(reg, &dp_regs->buf_data0);
513 * Set DisplayPort transaction and write 1 byte
514 * If bit 3 is 1, DisplayPort transaction.
515 * If Bit 3 is 0, I2C transaction.
517 reg = AUX_TX_COMM_DP_TRANSACTION | AUX_TX_COMM_WRITE;
518 writel(reg, &dp_regs->aux_ch_ctl1);
520 /* Start AUX transaction */
521 ret = exynos_dp_start_aux_transaction();
522 if (ret != EXYNOS_DP_SUCCESS) {
523 printf("DP Aux transaction failed\n");
530 unsigned int exynos_dp_read_byte_from_dpcd(unsigned int reg_addr,
536 /* Clear AUX CH data buffer */
538 writel(reg, &dp_regs->buffer_data_ctl);
540 /* Select DPCD device address */
541 reg = AUX_ADDR_7_0(reg_addr);
542 writel(reg, &dp_regs->aux_addr_7_0);
543 reg = AUX_ADDR_15_8(reg_addr);
544 writel(reg, &dp_regs->aux_addr_15_8);
545 reg = AUX_ADDR_19_16(reg_addr);
546 writel(reg, &dp_regs->aux_addr_19_16);
549 * Set DisplayPort transaction and read 1 byte
550 * If bit 3 is 1, DisplayPort transaction.
551 * If Bit 3 is 0, I2C transaction.
553 reg = AUX_TX_COMM_DP_TRANSACTION | AUX_TX_COMM_READ;
554 writel(reg, &dp_regs->aux_ch_ctl1);
556 /* Start AUX transaction */
557 retval = exynos_dp_start_aux_transaction();
559 debug("DP Aux Transaction fail!\n");
561 /* Read data buffer */
562 reg = readl(&dp_regs->buf_data0);
563 *data = (unsigned char)(reg & 0xff);
568 unsigned int exynos_dp_write_bytes_to_dpcd(unsigned int reg_addr,
570 unsigned char data[])
573 unsigned int start_offset;
574 unsigned int cur_data_count;
575 unsigned int cur_data_idx;
576 unsigned int retry_cnt;
577 unsigned int ret = 0;
579 /* Clear AUX CH data buffer */
581 writel(reg, &dp_regs->buffer_data_ctl);
584 while (start_offset < count) {
585 /* Buffer size of AUX CH is 16 * 4bytes */
586 if ((count - start_offset) > 16)
589 cur_data_count = count - start_offset;
593 /* Select DPCD device address */
594 reg = AUX_ADDR_7_0(reg_addr + start_offset);
595 writel(reg, &dp_regs->aux_addr_7_0);
596 reg = AUX_ADDR_15_8(reg_addr + start_offset);
597 writel(reg, &dp_regs->aux_addr_15_8);
598 reg = AUX_ADDR_19_16(reg_addr + start_offset);
599 writel(reg, &dp_regs->aux_addr_19_16);
601 for (cur_data_idx = 0; cur_data_idx < cur_data_count;
603 reg = data[start_offset + cur_data_idx];
604 writel(reg, (unsigned int)&dp_regs->buf_data0 +
608 * Set DisplayPort transaction and write
609 * If bit 3 is 1, DisplayPort transaction.
610 * If Bit 3 is 0, I2C transaction.
612 reg = AUX_LENGTH(cur_data_count) |
613 AUX_TX_COMM_DP_TRANSACTION | AUX_TX_COMM_WRITE;
614 writel(reg, &dp_regs->aux_ch_ctl1);
616 /* Start AUX transaction */
617 ret = exynos_dp_start_aux_transaction();
618 if (ret != EXYNOS_DP_SUCCESS) {
619 if (retry_cnt == 0) {
620 printf("DP Aux Transaction failed\n");
627 start_offset += cur_data_count;
633 unsigned int exynos_dp_read_bytes_from_dpcd(unsigned int reg_addr,
635 unsigned char data[])
638 unsigned int start_offset;
639 unsigned int cur_data_count;
640 unsigned int cur_data_idx;
641 unsigned int retry_cnt;
642 unsigned int ret = 0;
644 /* Clear AUX CH data buffer */
646 writel(reg, &dp_regs->buffer_data_ctl);
649 while (start_offset < count) {
650 /* Buffer size of AUX CH is 16 * 4bytes */
651 if ((count - start_offset) > 16)
654 cur_data_count = count - start_offset;
658 /* Select DPCD device address */
659 reg = AUX_ADDR_7_0(reg_addr + start_offset);
660 writel(reg, &dp_regs->aux_addr_7_0);
661 reg = AUX_ADDR_15_8(reg_addr + start_offset);
662 writel(reg, &dp_regs->aux_addr_15_8);
663 reg = AUX_ADDR_19_16(reg_addr + start_offset);
664 writel(reg, &dp_regs->aux_addr_19_16);
666 * Set DisplayPort transaction and read
667 * If bit 3 is 1, DisplayPort transaction.
668 * If Bit 3 is 0, I2C transaction.
670 reg = AUX_LENGTH(cur_data_count) |
671 AUX_TX_COMM_DP_TRANSACTION | AUX_TX_COMM_READ;
672 writel(reg, &dp_regs->aux_ch_ctl1);
674 /* Start AUX transaction */
675 ret = exynos_dp_start_aux_transaction();
676 if (ret != EXYNOS_DP_SUCCESS) {
677 if (retry_cnt == 0) {
678 printf("DP Aux Transaction failed\n");
686 for (cur_data_idx = 0; cur_data_idx < cur_data_count;
688 reg = readl((unsigned int)&dp_regs->buf_data0 +
690 data[start_offset + cur_data_idx] = (unsigned char)reg;
693 start_offset += cur_data_count;
699 int exynos_dp_select_i2c_device(unsigned int device_addr,
700 unsigned int reg_addr)
705 /* Set EDID device address */
707 writel(reg, &dp_regs->aux_addr_7_0);
708 writel(0x0, &dp_regs->aux_addr_15_8);
709 writel(0x0, &dp_regs->aux_addr_19_16);
711 /* Set offset from base address of EDID device */
712 writel(reg_addr, &dp_regs->buf_data0);
715 * Set I2C transaction and write address
716 * If bit 3 is 1, DisplayPort transaction.
717 * If Bit 3 is 0, I2C transaction.
719 reg = AUX_TX_COMM_I2C_TRANSACTION | AUX_TX_COMM_MOT |
721 writel(reg, &dp_regs->aux_ch_ctl1);
723 /* Start AUX transaction */
724 retval = exynos_dp_start_aux_transaction();
726 printf("%s: DP Aux Transaction fail!\n", __func__);
731 int exynos_dp_read_byte_from_i2c(unsigned int device_addr,
732 unsigned int reg_addr,
739 for (i = 0; i < 10; i++) {
740 /* Clear AUX CH data buffer */
742 writel(reg, &dp_regs->buffer_data_ctl);
744 /* Select EDID device */
745 retval = exynos_dp_select_i2c_device(device_addr, reg_addr);
747 printf("DP Select EDID device fail. retry !\n");
752 * Set I2C transaction and read data
753 * If bit 3 is 1, DisplayPort transaction.
754 * If Bit 3 is 0, I2C transaction.
756 reg = AUX_TX_COMM_I2C_TRANSACTION |
758 writel(reg, &dp_regs->aux_ch_ctl1);
760 /* Start AUX transaction */
761 retval = exynos_dp_start_aux_transaction();
762 if (retval != EXYNOS_DP_SUCCESS)
763 printf("%s: DP Aux Transaction fail!\n", __func__);
768 *data = readl(&dp_regs->buf_data0);
773 int exynos_dp_read_bytes_from_i2c(unsigned int device_addr,
774 unsigned int reg_addr, unsigned int count, unsigned char edid[])
778 unsigned int cur_data_idx;
779 unsigned int defer = 0;
782 for (i = 0; i < count; i += 16) { /* use 16 burst */
783 for (j = 0; j < 100; j++) {
784 /* Clear AUX CH data buffer */
786 writel(reg, &dp_regs->buffer_data_ctl);
788 /* Set normal AUX CH command */
789 reg = readl(&dp_regs->aux_ch_ctl2);
791 writel(reg, &dp_regs->aux_ch_ctl2);
794 * If Rx sends defer, Tx sends only reads
795 * request without sending addres
799 exynos_dp_select_i2c_device(device_addr,
804 if (retval == EXYNOS_DP_SUCCESS) {
806 * Set I2C transaction and write data
807 * If bit 3 is 1, DisplayPort transaction.
808 * If Bit 3 is 0, I2C transaction.
810 reg = AUX_LENGTH(16) |
811 AUX_TX_COMM_I2C_TRANSACTION |
813 writel(reg, &dp_regs->aux_ch_ctl1);
815 /* Start AUX transaction */
816 retval = exynos_dp_start_aux_transaction();
820 printf("DP Aux Transaction fail!\n");
822 /* Check if Rx sends defer */
823 reg = readl(&dp_regs->aux_rx_comm);
824 if (reg == AUX_RX_COMM_AUX_DEFER ||
825 reg == AUX_RX_COMM_I2C_DEFER) {
826 printf("DP Defer: %d\n", reg);
831 for (cur_data_idx = 0; cur_data_idx < 16; cur_data_idx++) {
832 reg = readl((unsigned int)&dp_regs->buf_data0
834 edid[i + cur_data_idx] = (unsigned char)reg;
841 void exynos_dp_reset_macro(void)
845 reg = readl(&dp_regs->phy_test);
847 writel(reg, &dp_regs->phy_test);
849 /* 10 us is the minimum Macro reset time. */
853 writel(reg, &dp_regs->phy_test);
856 void exynos_dp_set_link_bandwidth(unsigned char bwtype)
860 reg = (unsigned int)bwtype;
862 /* Set bandwidth to 2.7G or 1.62G */
863 if ((bwtype == DP_LANE_BW_1_62) || (bwtype == DP_LANE_BW_2_70))
864 writel(reg, &dp_regs->link_bw_set);
867 unsigned char exynos_dp_get_link_bandwidth(void)
872 reg = readl(&dp_regs->link_bw_set);
873 ret = (unsigned char)reg;
878 void exynos_dp_set_lane_count(unsigned char count)
882 reg = (unsigned int)count;
884 if ((count == DP_LANE_CNT_1) || (count == DP_LANE_CNT_2) ||
885 (count == DP_LANE_CNT_4))
886 writel(reg, &dp_regs->lane_count_set);
889 unsigned int exynos_dp_get_lane_count(void)
893 reg = readl(&dp_regs->lane_count_set);
898 unsigned char exynos_dp_get_lanex_pre_emphasis(unsigned char lanecnt)
900 unsigned int reg_list[DP_LANE_CNT_4] = {
901 (unsigned int)&dp_regs->ln0_link_training_ctl,
902 (unsigned int)&dp_regs->ln1_link_training_ctl,
903 (unsigned int)&dp_regs->ln2_link_training_ctl,
904 (unsigned int)&dp_regs->ln3_link_training_ctl,
907 return readl(reg_list[lanecnt]);
910 void exynos_dp_set_lanex_pre_emphasis(unsigned char request_val,
911 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 writel(request_val, reg_list[lanecnt]);
923 void exynos_dp_set_lane_pre_emphasis(unsigned int level, unsigned char lanecnt)
927 unsigned int reg_list[DP_LANE_CNT_4] = {
928 (unsigned int)&dp_regs->ln0_link_training_ctl,
929 (unsigned int)&dp_regs->ln1_link_training_ctl,
930 (unsigned int)&dp_regs->ln2_link_training_ctl,
931 (unsigned int)&dp_regs->ln3_link_training_ctl,
933 unsigned int reg_shift[DP_LANE_CNT_4] = {
934 PRE_EMPHASIS_SET_0_SHIFT,
935 PRE_EMPHASIS_SET_1_SHIFT,
936 PRE_EMPHASIS_SET_2_SHIFT,
937 PRE_EMPHASIS_SET_3_SHIFT
940 for (i = 0; i < lanecnt; i++) {
941 reg = level << reg_shift[i];
942 writel(reg, reg_list[i]);
946 void exynos_dp_set_training_pattern(unsigned int pattern)
948 unsigned int reg = 0;
952 reg = SCRAMBLING_ENABLE | LINK_QUAL_PATTERN_SET_PRBS7;
955 reg = SCRAMBLING_ENABLE | LINK_QUAL_PATTERN_SET_D10_2;
958 reg = SCRAMBLING_DISABLE | SW_TRAINING_PATTERN_SET_PTN1;
961 reg = SCRAMBLING_DISABLE | SW_TRAINING_PATTERN_SET_PTN2;
964 reg = SCRAMBLING_ENABLE | LINK_QUAL_PATTERN_SET_DISABLE |
965 SW_TRAINING_PATTERN_SET_NORMAL;
971 writel(reg, &dp_regs->training_ptn_set);
974 void exynos_dp_enable_enhanced_mode(unsigned char enable)
978 reg = readl(&dp_regs->sys_ctl4);
984 writel(reg, &dp_regs->sys_ctl4);
987 void exynos_dp_enable_scrambling(unsigned int enable)
991 reg = readl(&dp_regs->training_ptn_set);
992 reg &= ~(SCRAMBLING_DISABLE);
995 reg |= SCRAMBLING_DISABLE;
997 writel(reg, &dp_regs->training_ptn_set);
1000 int exynos_dp_init_video(void)
1004 /* Clear VID_CLK_CHG[1] and VID_FORMAT_CHG[3] and VSYNC_DET[7] */
1005 reg = VSYNC_DET | VID_FORMAT_CHG | VID_CLK_CHG;
1006 writel(reg, &dp_regs->common_int_sta1);
1008 /* I_STRM__CLK detect : DE_CTL : Auto detect */
1010 writel(reg, &dp_regs->sys_ctl1);
1015 void exynos_dp_config_video_slave_mode(struct edp_video_info *video_info)
1019 /* Video Slave mode setting */
1020 reg = readl(&dp_regs->func_en1);
1021 reg &= ~(MASTER_VID_FUNC_EN_N|SLAVE_VID_FUNC_EN_N);
1022 reg |= MASTER_VID_FUNC_EN_N;
1023 writel(reg, &dp_regs->func_en1);
1025 /* Configure Interlaced for slave mode video */
1026 reg = readl(&dp_regs->video_ctl10);
1027 reg &= ~INTERACE_SCAN_CFG;
1028 reg |= (video_info->interlaced << INTERACE_SCAN_CFG_SHIFT);
1029 writel(reg, &dp_regs->video_ctl10);
1031 /* Configure V sync polarity for slave mode video */
1032 reg = readl(&dp_regs->video_ctl10);
1033 reg &= ~VSYNC_POLARITY_CFG;
1034 reg |= (video_info->v_sync_polarity << V_S_POLARITY_CFG_SHIFT);
1035 writel(reg, &dp_regs->video_ctl10);
1037 /* Configure H sync polarity for slave mode video */
1038 reg = readl(&dp_regs->video_ctl10);
1039 reg &= ~HSYNC_POLARITY_CFG;
1040 reg |= (video_info->h_sync_polarity << H_S_POLARITY_CFG_SHIFT);
1041 writel(reg, &dp_regs->video_ctl10);
1043 /*Set video mode to slave mode */
1044 reg = AUDIO_MODE_SPDIF_MODE | VIDEO_MODE_SLAVE_MODE;
1045 writel(reg, &dp_regs->soc_general_ctl);
1048 void exynos_dp_set_video_color_format(struct edp_video_info *video_info)
1052 /* Configure the input color depth, color space, dynamic range */
1053 reg = (video_info->dynamic_range << IN_D_RANGE_SHIFT) |
1054 (video_info->color_depth << IN_BPC_SHIFT) |
1055 (video_info->color_space << IN_COLOR_F_SHIFT);
1056 writel(reg, &dp_regs->video_ctl2);
1058 /* Set Input Color YCbCr Coefficients to ITU601 or ITU709 */
1059 reg = readl(&dp_regs->video_ctl3);
1060 reg &= ~IN_YC_COEFFI_MASK;
1061 if (video_info->ycbcr_coeff)
1062 reg |= IN_YC_COEFFI_ITU709;
1064 reg |= IN_YC_COEFFI_ITU601;
1065 writel(reg, &dp_regs->video_ctl3);
1068 int exynos_dp_config_video_bist(struct edp_device_info *edp_info)
1071 unsigned int bist_type = 0;
1072 struct edp_video_info video_info = edp_info->video_info;
1074 /* For master mode, you don't need to set the video format */
1075 if (video_info.master_mode == 0) {
1076 writel(TOTAL_LINE_CFG_L(edp_info->disp_info.v_total),
1077 &dp_regs->total_ln_cfg_l);
1078 writel(TOTAL_LINE_CFG_H(edp_info->disp_info.v_total),
1079 &dp_regs->total_ln_cfg_h);
1080 writel(ACTIVE_LINE_CFG_L(edp_info->disp_info.v_res),
1081 &dp_regs->active_ln_cfg_l);
1082 writel(ACTIVE_LINE_CFG_H(edp_info->disp_info.v_res),
1083 &dp_regs->active_ln_cfg_h);
1084 writel(edp_info->disp_info.v_sync_width,
1086 writel(edp_info->disp_info.v_back_porch,
1088 writel(edp_info->disp_info.v_front_porch,
1091 writel(TOTAL_PIXEL_CFG_L(edp_info->disp_info.h_total),
1092 &dp_regs->total_pix_cfg_l);
1093 writel(TOTAL_PIXEL_CFG_H(edp_info->disp_info.h_total),
1094 &dp_regs->total_pix_cfg_h);
1095 writel(ACTIVE_PIXEL_CFG_L(edp_info->disp_info.h_res),
1096 &dp_regs->active_pix_cfg_l);
1097 writel(ACTIVE_PIXEL_CFG_H(edp_info->disp_info.h_res),
1098 &dp_regs->active_pix_cfg_h);
1099 writel(H_F_PORCH_CFG_L(edp_info->disp_info.h_front_porch),
1100 &dp_regs->hfp_cfg_l);
1101 writel(H_F_PORCH_CFG_H(edp_info->disp_info.h_front_porch),
1102 &dp_regs->hfp_cfg_h);
1103 writel(H_SYNC_PORCH_CFG_L(edp_info->disp_info.h_sync_width),
1104 &dp_regs->hsw_cfg_l);
1105 writel(H_SYNC_PORCH_CFG_H(edp_info->disp_info.h_sync_width),
1106 &dp_regs->hsw_cfg_h);
1107 writel(H_B_PORCH_CFG_L(edp_info->disp_info.h_back_porch),
1108 &dp_regs->hbp_cfg_l);
1109 writel(H_B_PORCH_CFG_H(edp_info->disp_info.h_back_porch),
1110 &dp_regs->hbp_cfg_h);
1113 * Set SLAVE_I_SCAN_CFG[2], VSYNC_P_CFG[1],
1114 * HSYNC_P_CFG[0] properly
1116 reg = (video_info.interlaced << INTERACE_SCAN_CFG_SHIFT |
1117 video_info.v_sync_polarity << V_S_POLARITY_CFG_SHIFT |
1118 video_info.h_sync_polarity << H_S_POLARITY_CFG_SHIFT);
1119 writel(reg, &dp_regs->video_ctl10);
1122 /* BIST color bar width set--set to each bar is 32 pixel width */
1123 switch (video_info.bist_pattern) {
1125 bist_type = BIST_WIDTH_BAR_32_PIXEL |
1126 BIST_TYPE_COLOR_BAR;
1129 bist_type = BIST_WIDTH_BAR_64_PIXEL |
1130 BIST_TYPE_COLOR_BAR;
1132 case WHITE_GRAY_BALCKBAR_32:
1133 bist_type = BIST_WIDTH_BAR_32_PIXEL |
1134 BIST_TYPE_WHITE_GRAY_BLACK_BAR;
1136 case WHITE_GRAY_BALCKBAR_64:
1137 bist_type = BIST_WIDTH_BAR_64_PIXEL |
1138 BIST_TYPE_WHITE_GRAY_BLACK_BAR;
1140 case MOBILE_WHITEBAR_32:
1141 bist_type = BIST_WIDTH_BAR_32_PIXEL |
1142 BIST_TYPE_MOBILE_WHITE_BAR;
1144 case MOBILE_WHITEBAR_64:
1145 bist_type = BIST_WIDTH_BAR_64_PIXEL |
1146 BIST_TYPE_MOBILE_WHITE_BAR;
1153 writel(reg, &dp_regs->video_ctl4);
1158 unsigned int exynos_dp_is_slave_video_stream_clock_on(void)
1162 /* Update Video stream clk detect status */
1163 reg = readl(&dp_regs->sys_ctl1);
1164 writel(reg, &dp_regs->sys_ctl1);
1166 reg = readl(&dp_regs->sys_ctl1);
1168 if (!(reg & DET_STA)) {
1169 debug("DP Input stream clock not detected.\n");
1173 return EXYNOS_DP_SUCCESS;
1176 void exynos_dp_set_video_cr_mn(unsigned int type, unsigned int m_value,
1177 unsigned int n_value)
1181 if (type == REGISTER_M) {
1182 reg = readl(&dp_regs->sys_ctl4);
1184 writel(reg, &dp_regs->sys_ctl4);
1185 reg = M_VID0_CFG(m_value);
1186 writel(reg, &dp_regs->m_vid0);
1187 reg = M_VID1_CFG(m_value);
1188 writel(reg, &dp_regs->m_vid1);
1189 reg = M_VID2_CFG(m_value);
1190 writel(reg, &dp_regs->m_vid2);
1192 reg = N_VID0_CFG(n_value);
1193 writel(reg, &dp_regs->n_vid0);
1194 reg = N_VID1_CFG(n_value);
1195 writel(reg, &dp_regs->n_vid1);
1196 reg = N_VID2_CFG(n_value);
1197 writel(reg, &dp_regs->n_vid2);
1199 reg = readl(&dp_regs->sys_ctl4);
1201 writel(reg, &dp_regs->sys_ctl4);
1205 void exynos_dp_set_video_timing_mode(unsigned int type)
1209 reg = readl(&dp_regs->video_ctl10);
1212 if (type != VIDEO_TIMING_FROM_CAPTURE)
1215 writel(reg, &dp_regs->video_ctl10);
1218 void exynos_dp_enable_video_master(unsigned int enable)
1222 reg = readl(&dp_regs->soc_general_ctl);
1224 reg &= ~VIDEO_MODE_MASK;
1225 reg |= VIDEO_MASTER_MODE_EN | VIDEO_MODE_MASTER_MODE;
1227 reg &= ~VIDEO_MODE_MASK;
1228 reg |= VIDEO_MODE_SLAVE_MODE;
1231 writel(reg, &dp_regs->soc_general_ctl);
1234 void exynos_dp_start_video(void)
1238 /* Enable Video input and disable Mute */
1239 reg = readl(&dp_regs->video_ctl1);
1241 writel(reg, &dp_regs->video_ctl1);
1244 unsigned int exynos_dp_is_video_stream_on(void)
1248 /* Update STRM_VALID */
1249 reg = readl(&dp_regs->sys_ctl3);
1250 writel(reg, &dp_regs->sys_ctl3);
1252 reg = readl(&dp_regs->sys_ctl3);
1253 if (!(reg & STRM_VALID))
1256 return EXYNOS_DP_SUCCESS;