2 * Samsung DP (Display port) register 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/device.h>
15 #include <linux/delay.h>
16 #include <linux/gpio.h>
18 #include "exynos_dp_core.h"
19 #include "exynos_dp_reg.h"
21 #define COMMON_INT_MASK_1 0
22 #define COMMON_INT_MASK_2 0
23 #define COMMON_INT_MASK_3 0
24 #define COMMON_INT_MASK_4 (HOTPLUG_CHG | HPD_LOST | PLUG)
25 #define INT_STA_MASK INT_HPD
27 void exynos_dp_enable_video_mute(struct exynos_dp_device
*dp
, bool enable
)
32 reg
= readl(dp
->reg_base
+ EXYNOS_DP_VIDEO_CTL_1
);
33 reg
|= HDCP_VIDEO_MUTE
;
34 writel(reg
, dp
->reg_base
+ EXYNOS_DP_VIDEO_CTL_1
);
36 reg
= readl(dp
->reg_base
+ EXYNOS_DP_VIDEO_CTL_1
);
37 reg
&= ~HDCP_VIDEO_MUTE
;
38 writel(reg
, dp
->reg_base
+ EXYNOS_DP_VIDEO_CTL_1
);
42 void exynos_dp_stop_video(struct exynos_dp_device
*dp
)
46 reg
= readl(dp
->reg_base
+ EXYNOS_DP_VIDEO_CTL_1
);
48 writel(reg
, dp
->reg_base
+ EXYNOS_DP_VIDEO_CTL_1
);
51 void exynos_dp_lane_swap(struct exynos_dp_device
*dp
, bool enable
)
56 reg
= LANE3_MAP_LOGIC_LANE_0
| LANE2_MAP_LOGIC_LANE_1
|
57 LANE1_MAP_LOGIC_LANE_2
| LANE0_MAP_LOGIC_LANE_3
;
59 reg
= LANE3_MAP_LOGIC_LANE_3
| LANE2_MAP_LOGIC_LANE_2
|
60 LANE1_MAP_LOGIC_LANE_1
| LANE0_MAP_LOGIC_LANE_0
;
62 writel(reg
, dp
->reg_base
+ EXYNOS_DP_LANE_MAP
);
65 void exynos_dp_init_analog_param(struct exynos_dp_device
*dp
)
69 reg
= TX_TERMINAL_CTRL_50_OHM
;
70 writel(reg
, dp
->reg_base
+ EXYNOS_DP_ANALOG_CTL_1
);
72 reg
= SEL_24M
| TX_DVDD_BIT_1_0625V
;
73 writel(reg
, dp
->reg_base
+ EXYNOS_DP_ANALOG_CTL_2
);
75 reg
= DRIVE_DVDD_BIT_1_0625V
| VCO_BIT_600_MICRO
;
76 writel(reg
, dp
->reg_base
+ EXYNOS_DP_ANALOG_CTL_3
);
78 reg
= PD_RING_OSC
| AUX_TERMINAL_CTRL_50_OHM
|
79 TX_CUR1_2X
| TX_CUR_16_MA
;
80 writel(reg
, dp
->reg_base
+ EXYNOS_DP_PLL_FILTER_CTL_1
);
82 reg
= CH3_AMP_400_MV
| CH2_AMP_400_MV
|
83 CH1_AMP_400_MV
| CH0_AMP_400_MV
;
84 writel(reg
, dp
->reg_base
+ EXYNOS_DP_TX_AMP_TUNING_CTL
);
87 void exynos_dp_init_interrupt(struct exynos_dp_device
*dp
)
89 /* Set interrupt pin assertion polarity as high */
90 writel(INT_POL1
| INT_POL0
, dp
->reg_base
+ EXYNOS_DP_INT_CTL
);
92 /* Clear pending regisers */
93 writel(0xff, dp
->reg_base
+ EXYNOS_DP_COMMON_INT_STA_1
);
94 writel(0x4f, dp
->reg_base
+ EXYNOS_DP_COMMON_INT_STA_2
);
95 writel(0xe0, dp
->reg_base
+ EXYNOS_DP_COMMON_INT_STA_3
);
96 writel(0xe7, dp
->reg_base
+ EXYNOS_DP_COMMON_INT_STA_4
);
97 writel(0x63, dp
->reg_base
+ EXYNOS_DP_INT_STA
);
99 /* 0:mask,1: unmask */
100 writel(0x00, dp
->reg_base
+ EXYNOS_DP_COMMON_INT_MASK_1
);
101 writel(0x00, dp
->reg_base
+ EXYNOS_DP_COMMON_INT_MASK_2
);
102 writel(0x00, dp
->reg_base
+ EXYNOS_DP_COMMON_INT_MASK_3
);
103 writel(0x00, dp
->reg_base
+ EXYNOS_DP_COMMON_INT_MASK_4
);
104 writel(0x00, dp
->reg_base
+ EXYNOS_DP_INT_STA_MASK
);
107 void exynos_dp_reset(struct exynos_dp_device
*dp
)
111 exynos_dp_stop_video(dp
);
112 exynos_dp_enable_video_mute(dp
, 0);
114 reg
= MASTER_VID_FUNC_EN_N
| SLAVE_VID_FUNC_EN_N
|
115 AUD_FIFO_FUNC_EN_N
| AUD_FUNC_EN_N
|
116 HDCP_FUNC_EN_N
| SW_FUNC_EN_N
;
117 writel(reg
, dp
->reg_base
+ EXYNOS_DP_FUNC_EN_1
);
119 reg
= SSC_FUNC_EN_N
| AUX_FUNC_EN_N
|
120 SERDES_FIFO_FUNC_EN_N
|
121 LS_CLK_DOMAIN_FUNC_EN_N
;
122 writel(reg
, dp
->reg_base
+ EXYNOS_DP_FUNC_EN_2
);
124 usleep_range(20, 30);
126 exynos_dp_lane_swap(dp
, 0);
128 writel(0x0, dp
->reg_base
+ EXYNOS_DP_SYS_CTL_1
);
129 writel(0x40, dp
->reg_base
+ EXYNOS_DP_SYS_CTL_2
);
130 writel(0x0, dp
->reg_base
+ EXYNOS_DP_SYS_CTL_3
);
131 writel(0x0, dp
->reg_base
+ EXYNOS_DP_SYS_CTL_4
);
133 writel(0x0, dp
->reg_base
+ EXYNOS_DP_PKT_SEND_CTL
);
134 writel(0x0, dp
->reg_base
+ EXYNOS_DP_HDCP_CTL
);
136 writel(0x5e, dp
->reg_base
+ EXYNOS_DP_HPD_DEGLITCH_L
);
137 writel(0x1a, dp
->reg_base
+ EXYNOS_DP_HPD_DEGLITCH_H
);
139 writel(0x10, dp
->reg_base
+ EXYNOS_DP_LINK_DEBUG_CTL
);
141 writel(0x0, dp
->reg_base
+ EXYNOS_DP_PHY_TEST
);
143 writel(0x0, dp
->reg_base
+ EXYNOS_DP_VIDEO_FIFO_THRD
);
144 writel(0x20, dp
->reg_base
+ EXYNOS_DP_AUDIO_MARGIN
);
146 writel(0x4, dp
->reg_base
+ EXYNOS_DP_M_VID_GEN_FILTER_TH
);
147 writel(0x2, dp
->reg_base
+ EXYNOS_DP_M_AUD_GEN_FILTER_TH
);
149 writel(0x00000101, dp
->reg_base
+ EXYNOS_DP_SOC_GENERAL_CTL
);
152 void exynos_dp_swreset(struct exynos_dp_device
*dp
)
154 writel(RESET_DP_TX
, dp
->reg_base
+ EXYNOS_DP_TX_SW_RESET
);
157 void exynos_dp_config_interrupt(struct exynos_dp_device
*dp
)
161 /* 0: mask, 1: unmask */
162 reg
= COMMON_INT_MASK_1
;
163 writel(reg
, dp
->reg_base
+ EXYNOS_DP_COMMON_INT_MASK_1
);
165 reg
= COMMON_INT_MASK_2
;
166 writel(reg
, dp
->reg_base
+ EXYNOS_DP_COMMON_INT_MASK_2
);
168 reg
= COMMON_INT_MASK_3
;
169 writel(reg
, dp
->reg_base
+ EXYNOS_DP_COMMON_INT_MASK_3
);
171 reg
= COMMON_INT_MASK_4
;
172 writel(reg
, dp
->reg_base
+ EXYNOS_DP_COMMON_INT_MASK_4
);
175 writel(reg
, dp
->reg_base
+ EXYNOS_DP_INT_STA_MASK
);
178 enum pll_status
exynos_dp_get_pll_lock_status(struct exynos_dp_device
*dp
)
182 reg
= readl(dp
->reg_base
+ EXYNOS_DP_DEBUG_CTL
);
189 void exynos_dp_set_pll_power_down(struct exynos_dp_device
*dp
, bool enable
)
194 reg
= readl(dp
->reg_base
+ EXYNOS_DP_PLL_CTL
);
196 writel(reg
, dp
->reg_base
+ EXYNOS_DP_PLL_CTL
);
198 reg
= readl(dp
->reg_base
+ EXYNOS_DP_PLL_CTL
);
200 writel(reg
, dp
->reg_base
+ EXYNOS_DP_PLL_CTL
);
204 void exynos_dp_set_analog_power_down(struct exynos_dp_device
*dp
,
205 enum analog_power_block block
,
213 reg
= readl(dp
->reg_base
+ EXYNOS_DP_PHY_PD
);
215 writel(reg
, dp
->reg_base
+ EXYNOS_DP_PHY_PD
);
217 reg
= readl(dp
->reg_base
+ EXYNOS_DP_PHY_PD
);
219 writel(reg
, dp
->reg_base
+ EXYNOS_DP_PHY_PD
);
224 reg
= readl(dp
->reg_base
+ EXYNOS_DP_PHY_PD
);
226 writel(reg
, dp
->reg_base
+ EXYNOS_DP_PHY_PD
);
228 reg
= readl(dp
->reg_base
+ EXYNOS_DP_PHY_PD
);
230 writel(reg
, dp
->reg_base
+ EXYNOS_DP_PHY_PD
);
235 reg
= readl(dp
->reg_base
+ EXYNOS_DP_PHY_PD
);
237 writel(reg
, dp
->reg_base
+ EXYNOS_DP_PHY_PD
);
239 reg
= readl(dp
->reg_base
+ EXYNOS_DP_PHY_PD
);
241 writel(reg
, dp
->reg_base
+ EXYNOS_DP_PHY_PD
);
246 reg
= readl(dp
->reg_base
+ EXYNOS_DP_PHY_PD
);
248 writel(reg
, dp
->reg_base
+ EXYNOS_DP_PHY_PD
);
250 reg
= readl(dp
->reg_base
+ EXYNOS_DP_PHY_PD
);
252 writel(reg
, dp
->reg_base
+ EXYNOS_DP_PHY_PD
);
257 reg
= readl(dp
->reg_base
+ EXYNOS_DP_PHY_PD
);
259 writel(reg
, dp
->reg_base
+ EXYNOS_DP_PHY_PD
);
261 reg
= readl(dp
->reg_base
+ EXYNOS_DP_PHY_PD
);
263 writel(reg
, dp
->reg_base
+ EXYNOS_DP_PHY_PD
);
268 reg
= readl(dp
->reg_base
+ EXYNOS_DP_PHY_PD
);
270 writel(reg
, dp
->reg_base
+ EXYNOS_DP_PHY_PD
);
272 reg
= readl(dp
->reg_base
+ EXYNOS_DP_PHY_PD
);
274 writel(reg
, dp
->reg_base
+ EXYNOS_DP_PHY_PD
);
279 reg
= DP_PHY_PD
| AUX_PD
| CH3_PD
| CH2_PD
|
281 writel(reg
, dp
->reg_base
+ EXYNOS_DP_PHY_PD
);
283 writel(0x00, dp
->reg_base
+ EXYNOS_DP_PHY_PD
);
291 void exynos_dp_init_analog_func(struct exynos_dp_device
*dp
)
294 int timeout_loop
= 0;
296 exynos_dp_set_analog_power_down(dp
, POWER_ALL
, 0);
299 writel(reg
, dp
->reg_base
+ EXYNOS_DP_COMMON_INT_STA_1
);
301 reg
= readl(dp
->reg_base
+ EXYNOS_DP_DEBUG_CTL
);
302 reg
&= ~(F_PLL_LOCK
| PLL_LOCK_CTRL
);
303 writel(reg
, dp
->reg_base
+ EXYNOS_DP_DEBUG_CTL
);
306 if (exynos_dp_get_pll_lock_status(dp
) == PLL_UNLOCKED
) {
307 exynos_dp_set_pll_power_down(dp
, 0);
309 while (exynos_dp_get_pll_lock_status(dp
) == PLL_UNLOCKED
) {
311 if (DP_TIMEOUT_LOOP_COUNT
< timeout_loop
) {
312 dev_err(dp
->dev
, "failed to get pll lock status\n");
315 usleep_range(10, 20);
319 /* Enable Serdes FIFO function and Link symbol clock domain module */
320 reg
= readl(dp
->reg_base
+ EXYNOS_DP_FUNC_EN_2
);
321 reg
&= ~(SERDES_FIFO_FUNC_EN_N
| LS_CLK_DOMAIN_FUNC_EN_N
323 writel(reg
, dp
->reg_base
+ EXYNOS_DP_FUNC_EN_2
);
326 void exynos_dp_clear_hotplug_interrupts(struct exynos_dp_device
*dp
)
330 if (gpio_is_valid(dp
->hpd_gpio
))
333 reg
= HOTPLUG_CHG
| HPD_LOST
| PLUG
;
334 writel(reg
, dp
->reg_base
+ EXYNOS_DP_COMMON_INT_STA_4
);
337 writel(reg
, dp
->reg_base
+ EXYNOS_DP_INT_STA
);
340 void exynos_dp_init_hpd(struct exynos_dp_device
*dp
)
344 if (gpio_is_valid(dp
->hpd_gpio
))
347 exynos_dp_clear_hotplug_interrupts(dp
);
349 reg
= readl(dp
->reg_base
+ EXYNOS_DP_SYS_CTL_3
);
350 reg
&= ~(F_HPD
| HPD_CTRL
);
351 writel(reg
, dp
->reg_base
+ EXYNOS_DP_SYS_CTL_3
);
354 enum dp_irq_type
exynos_dp_get_irq_type(struct exynos_dp_device
*dp
)
358 if (gpio_is_valid(dp
->hpd_gpio
)) {
359 reg
= gpio_get_value(dp
->hpd_gpio
);
361 return DP_IRQ_TYPE_HP_CABLE_IN
;
363 return DP_IRQ_TYPE_HP_CABLE_OUT
;
365 /* Parse hotplug interrupt status register */
366 reg
= readl(dp
->reg_base
+ EXYNOS_DP_COMMON_INT_STA_4
);
369 return DP_IRQ_TYPE_HP_CABLE_IN
;
372 return DP_IRQ_TYPE_HP_CABLE_OUT
;
374 if (reg
& HOTPLUG_CHG
)
375 return DP_IRQ_TYPE_HP_CHANGE
;
377 return DP_IRQ_TYPE_UNKNOWN
;
381 void exynos_dp_reset_aux(struct exynos_dp_device
*dp
)
385 /* Disable AUX channel module */
386 reg
= readl(dp
->reg_base
+ EXYNOS_DP_FUNC_EN_2
);
387 reg
|= AUX_FUNC_EN_N
;
388 writel(reg
, dp
->reg_base
+ EXYNOS_DP_FUNC_EN_2
);
391 void exynos_dp_init_aux(struct exynos_dp_device
*dp
)
395 /* Clear inerrupts related to AUX channel */
396 reg
= RPLY_RECEIV
| AUX_ERR
;
397 writel(reg
, dp
->reg_base
+ EXYNOS_DP_INT_STA
);
399 exynos_dp_reset_aux(dp
);
401 /* Disable AUX transaction H/W retry */
402 reg
= AUX_BIT_PERIOD_EXPECTED_DELAY(3) | AUX_HW_RETRY_COUNT_SEL(0)|
403 AUX_HW_RETRY_INTERVAL_600_MICROSECONDS
;
404 writel(reg
, dp
->reg_base
+ EXYNOS_DP_AUX_HW_RETRY_CTL
);
406 /* Receive AUX Channel DEFER commands equal to DEFFER_COUNT*64 */
407 reg
= DEFER_CTRL_EN
| DEFER_COUNT(1);
408 writel(reg
, dp
->reg_base
+ EXYNOS_DP_AUX_CH_DEFER_CTL
);
410 /* Enable AUX channel module */
411 reg
= readl(dp
->reg_base
+ EXYNOS_DP_FUNC_EN_2
);
412 reg
&= ~AUX_FUNC_EN_N
;
413 writel(reg
, dp
->reg_base
+ EXYNOS_DP_FUNC_EN_2
);
416 int exynos_dp_get_plug_in_status(struct exynos_dp_device
*dp
)
420 if (gpio_is_valid(dp
->hpd_gpio
)) {
421 if (gpio_get_value(dp
->hpd_gpio
))
424 reg
= readl(dp
->reg_base
+ EXYNOS_DP_SYS_CTL_3
);
425 if (reg
& HPD_STATUS
)
432 void exynos_dp_enable_sw_function(struct exynos_dp_device
*dp
)
436 reg
= readl(dp
->reg_base
+ EXYNOS_DP_FUNC_EN_1
);
437 reg
&= ~SW_FUNC_EN_N
;
438 writel(reg
, dp
->reg_base
+ EXYNOS_DP_FUNC_EN_1
);
441 int exynos_dp_start_aux_transaction(struct exynos_dp_device
*dp
)
445 int timeout_loop
= 0;
447 /* Enable AUX CH operation */
448 reg
= readl(dp
->reg_base
+ EXYNOS_DP_AUX_CH_CTL_2
);
450 writel(reg
, dp
->reg_base
+ EXYNOS_DP_AUX_CH_CTL_2
);
452 /* Is AUX CH command reply received? */
453 reg
= readl(dp
->reg_base
+ EXYNOS_DP_INT_STA
);
454 while (!(reg
& RPLY_RECEIV
)) {
456 if (DP_TIMEOUT_LOOP_COUNT
< timeout_loop
) {
457 dev_err(dp
->dev
, "AUX CH command reply failed!\n");
460 reg
= readl(dp
->reg_base
+ EXYNOS_DP_INT_STA
);
461 usleep_range(10, 11);
464 /* Clear interrupt source for AUX CH command reply */
465 writel(RPLY_RECEIV
, dp
->reg_base
+ EXYNOS_DP_INT_STA
);
467 /* Clear interrupt source for AUX CH access error */
468 reg
= readl(dp
->reg_base
+ EXYNOS_DP_INT_STA
);
470 writel(AUX_ERR
, dp
->reg_base
+ EXYNOS_DP_INT_STA
);
474 /* Check AUX CH error access status */
475 reg
= readl(dp
->reg_base
+ EXYNOS_DP_AUX_CH_STA
);
476 if ((reg
& AUX_STATUS_MASK
) != 0) {
477 dev_err(dp
->dev
, "AUX CH error happens: %d\n\n",
478 reg
& AUX_STATUS_MASK
);
485 int exynos_dp_write_byte_to_dpcd(struct exynos_dp_device
*dp
,
486 unsigned int reg_addr
,
493 for (i
= 0; i
< 3; i
++) {
494 /* Clear AUX CH data buffer */
496 writel(reg
, dp
->reg_base
+ EXYNOS_DP_BUFFER_DATA_CTL
);
498 /* Select DPCD device address */
499 reg
= AUX_ADDR_7_0(reg_addr
);
500 writel(reg
, dp
->reg_base
+ EXYNOS_DP_AUX_ADDR_7_0
);
501 reg
= AUX_ADDR_15_8(reg_addr
);
502 writel(reg
, dp
->reg_base
+ EXYNOS_DP_AUX_ADDR_15_8
);
503 reg
= AUX_ADDR_19_16(reg_addr
);
504 writel(reg
, dp
->reg_base
+ EXYNOS_DP_AUX_ADDR_19_16
);
506 /* Write data buffer */
507 reg
= (unsigned int)data
;
508 writel(reg
, dp
->reg_base
+ EXYNOS_DP_BUF_DATA_0
);
511 * Set DisplayPort transaction and write 1 byte
512 * If bit 3 is 1, DisplayPort transaction.
513 * If Bit 3 is 0, I2C transaction.
515 reg
= AUX_TX_COMM_DP_TRANSACTION
| AUX_TX_COMM_WRITE
;
516 writel(reg
, dp
->reg_base
+ EXYNOS_DP_AUX_CH_CTL_1
);
518 /* Start AUX transaction */
519 retval
= exynos_dp_start_aux_transaction(dp
);
523 dev_dbg(dp
->dev
, "%s: Aux Transaction fail!\n",
530 int exynos_dp_read_byte_from_dpcd(struct exynos_dp_device
*dp
,
531 unsigned int reg_addr
,
538 for (i
= 0; i
< 3; i
++) {
539 /* Clear AUX CH data buffer */
541 writel(reg
, dp
->reg_base
+ EXYNOS_DP_BUFFER_DATA_CTL
);
543 /* Select DPCD device address */
544 reg
= AUX_ADDR_7_0(reg_addr
);
545 writel(reg
, dp
->reg_base
+ EXYNOS_DP_AUX_ADDR_7_0
);
546 reg
= AUX_ADDR_15_8(reg_addr
);
547 writel(reg
, dp
->reg_base
+ EXYNOS_DP_AUX_ADDR_15_8
);
548 reg
= AUX_ADDR_19_16(reg_addr
);
549 writel(reg
, dp
->reg_base
+ EXYNOS_DP_AUX_ADDR_19_16
);
552 * Set DisplayPort transaction and read 1 byte
553 * If bit 3 is 1, DisplayPort transaction.
554 * If Bit 3 is 0, I2C transaction.
556 reg
= AUX_TX_COMM_DP_TRANSACTION
| AUX_TX_COMM_READ
;
557 writel(reg
, dp
->reg_base
+ EXYNOS_DP_AUX_CH_CTL_1
);
559 /* Start AUX transaction */
560 retval
= exynos_dp_start_aux_transaction(dp
);
564 dev_dbg(dp
->dev
, "%s: Aux Transaction fail!\n",
568 /* Read data buffer */
569 reg
= readl(dp
->reg_base
+ EXYNOS_DP_BUF_DATA_0
);
570 *data
= (unsigned char)(reg
& 0xff);
575 int exynos_dp_write_bytes_to_dpcd(struct exynos_dp_device
*dp
,
576 unsigned int reg_addr
,
578 unsigned char data
[])
581 unsigned int start_offset
;
582 unsigned int cur_data_count
;
583 unsigned int cur_data_idx
;
587 /* Clear AUX CH data buffer */
589 writel(reg
, dp
->reg_base
+ EXYNOS_DP_BUFFER_DATA_CTL
);
592 while (start_offset
< count
) {
593 /* Buffer size of AUX CH is 16 * 4bytes */
594 if ((count
- start_offset
) > 16)
597 cur_data_count
= count
- start_offset
;
599 for (i
= 0; i
< 3; i
++) {
600 /* Select DPCD device address */
601 reg
= AUX_ADDR_7_0(reg_addr
+ start_offset
);
602 writel(reg
, dp
->reg_base
+ EXYNOS_DP_AUX_ADDR_7_0
);
603 reg
= AUX_ADDR_15_8(reg_addr
+ start_offset
);
604 writel(reg
, dp
->reg_base
+ EXYNOS_DP_AUX_ADDR_15_8
);
605 reg
= AUX_ADDR_19_16(reg_addr
+ start_offset
);
606 writel(reg
, dp
->reg_base
+ EXYNOS_DP_AUX_ADDR_19_16
);
608 for (cur_data_idx
= 0; cur_data_idx
< cur_data_count
;
610 reg
= data
[start_offset
+ cur_data_idx
];
611 writel(reg
, dp
->reg_base
+ EXYNOS_DP_BUF_DATA_0
616 * Set DisplayPort transaction and write
617 * If bit 3 is 1, DisplayPort transaction.
618 * If Bit 3 is 0, I2C transaction.
620 reg
= AUX_LENGTH(cur_data_count
) |
621 AUX_TX_COMM_DP_TRANSACTION
| AUX_TX_COMM_WRITE
;
622 writel(reg
, dp
->reg_base
+ EXYNOS_DP_AUX_CH_CTL_1
);
624 /* Start AUX transaction */
625 retval
= exynos_dp_start_aux_transaction(dp
);
629 dev_dbg(dp
->dev
, "%s: Aux Transaction fail!\n",
633 start_offset
+= cur_data_count
;
639 int exynos_dp_read_bytes_from_dpcd(struct exynos_dp_device
*dp
,
640 unsigned int reg_addr
,
642 unsigned char data
[])
645 unsigned int start_offset
;
646 unsigned int cur_data_count
;
647 unsigned int cur_data_idx
;
651 /* Clear AUX CH data buffer */
653 writel(reg
, dp
->reg_base
+ EXYNOS_DP_BUFFER_DATA_CTL
);
656 while (start_offset
< count
) {
657 /* Buffer size of AUX CH is 16 * 4bytes */
658 if ((count
- start_offset
) > 16)
661 cur_data_count
= count
- start_offset
;
663 /* AUX CH Request Transaction process */
664 for (i
= 0; i
< 3; i
++) {
665 /* Select DPCD device address */
666 reg
= AUX_ADDR_7_0(reg_addr
+ start_offset
);
667 writel(reg
, dp
->reg_base
+ EXYNOS_DP_AUX_ADDR_7_0
);
668 reg
= AUX_ADDR_15_8(reg_addr
+ start_offset
);
669 writel(reg
, dp
->reg_base
+ EXYNOS_DP_AUX_ADDR_15_8
);
670 reg
= AUX_ADDR_19_16(reg_addr
+ start_offset
);
671 writel(reg
, dp
->reg_base
+ EXYNOS_DP_AUX_ADDR_19_16
);
674 * Set DisplayPort transaction and read
675 * If bit 3 is 1, DisplayPort transaction.
676 * If Bit 3 is 0, I2C transaction.
678 reg
= AUX_LENGTH(cur_data_count
) |
679 AUX_TX_COMM_DP_TRANSACTION
| AUX_TX_COMM_READ
;
680 writel(reg
, dp
->reg_base
+ EXYNOS_DP_AUX_CH_CTL_1
);
682 /* Start AUX transaction */
683 retval
= exynos_dp_start_aux_transaction(dp
);
687 dev_dbg(dp
->dev
, "%s: Aux Transaction fail!\n",
691 for (cur_data_idx
= 0; cur_data_idx
< cur_data_count
;
693 reg
= readl(dp
->reg_base
+ EXYNOS_DP_BUF_DATA_0
695 data
[start_offset
+ cur_data_idx
] =
699 start_offset
+= cur_data_count
;
705 int exynos_dp_select_i2c_device(struct exynos_dp_device
*dp
,
706 unsigned int device_addr
,
707 unsigned int reg_addr
)
712 /* Set EDID device address */
714 writel(reg
, dp
->reg_base
+ EXYNOS_DP_AUX_ADDR_7_0
);
715 writel(0x0, dp
->reg_base
+ EXYNOS_DP_AUX_ADDR_15_8
);
716 writel(0x0, dp
->reg_base
+ EXYNOS_DP_AUX_ADDR_19_16
);
718 /* Set offset from base address of EDID device */
719 writel(reg_addr
, dp
->reg_base
+ EXYNOS_DP_BUF_DATA_0
);
722 * Set I2C transaction and write address
723 * If bit 3 is 1, DisplayPort transaction.
724 * If Bit 3 is 0, I2C transaction.
726 reg
= AUX_TX_COMM_I2C_TRANSACTION
| AUX_TX_COMM_MOT
|
728 writel(reg
, dp
->reg_base
+ EXYNOS_DP_AUX_CH_CTL_1
);
730 /* Start AUX transaction */
731 retval
= exynos_dp_start_aux_transaction(dp
);
733 dev_dbg(dp
->dev
, "%s: Aux Transaction fail!\n", __func__
);
738 int exynos_dp_read_byte_from_i2c(struct exynos_dp_device
*dp
,
739 unsigned int device_addr
,
740 unsigned int reg_addr
,
747 for (i
= 0; i
< 3; i
++) {
748 /* Clear AUX CH data buffer */
750 writel(reg
, dp
->reg_base
+ EXYNOS_DP_BUFFER_DATA_CTL
);
752 /* Select EDID device */
753 retval
= exynos_dp_select_i2c_device(dp
, device_addr
, reg_addr
);
758 * Set I2C transaction and read data
759 * If bit 3 is 1, DisplayPort transaction.
760 * If Bit 3 is 0, I2C transaction.
762 reg
= AUX_TX_COMM_I2C_TRANSACTION
|
764 writel(reg
, dp
->reg_base
+ EXYNOS_DP_AUX_CH_CTL_1
);
766 /* Start AUX transaction */
767 retval
= exynos_dp_start_aux_transaction(dp
);
771 dev_dbg(dp
->dev
, "%s: Aux Transaction fail!\n",
777 *data
= readl(dp
->reg_base
+ EXYNOS_DP_BUF_DATA_0
);
782 int exynos_dp_read_bytes_from_i2c(struct exynos_dp_device
*dp
,
783 unsigned int device_addr
,
784 unsigned int reg_addr
,
786 unsigned char edid
[])
790 unsigned int cur_data_idx
;
791 unsigned int defer
= 0;
794 for (i
= 0; i
< count
; i
+= 16) {
795 for (j
= 0; j
< 3; j
++) {
796 /* Clear AUX CH data buffer */
798 writel(reg
, dp
->reg_base
+ EXYNOS_DP_BUFFER_DATA_CTL
);
800 /* Set normal AUX CH command */
801 reg
= readl(dp
->reg_base
+ EXYNOS_DP_AUX_CH_CTL_2
);
803 writel(reg
, dp
->reg_base
+ EXYNOS_DP_AUX_CH_CTL_2
);
806 * If Rx sends defer, Tx sends only reads
807 * request without sending address
810 retval
= exynos_dp_select_i2c_device(dp
,
811 device_addr
, reg_addr
+ i
);
817 * Set I2C transaction and write data
818 * If bit 3 is 1, DisplayPort transaction.
819 * If Bit 3 is 0, I2C transaction.
821 reg
= AUX_LENGTH(16) |
822 AUX_TX_COMM_I2C_TRANSACTION
|
824 writel(reg
, dp
->reg_base
+
825 EXYNOS_DP_AUX_CH_CTL_1
);
827 /* Start AUX transaction */
828 retval
= exynos_dp_start_aux_transaction(dp
);
833 "%s: Aux Transaction fail!\n",
836 /* Check if Rx sends defer */
837 reg
= readl(dp
->reg_base
+ EXYNOS_DP_AUX_RX_COMM
);
838 if (reg
== AUX_RX_COMM_AUX_DEFER
||
839 reg
== AUX_RX_COMM_I2C_DEFER
) {
840 dev_err(dp
->dev
, "Defer: %d\n\n", reg
);
845 for (cur_data_idx
= 0; cur_data_idx
< 16; cur_data_idx
++) {
846 reg
= readl(dp
->reg_base
+ EXYNOS_DP_BUF_DATA_0
848 edid
[i
+ cur_data_idx
] = (unsigned char)reg
;
855 void exynos_dp_set_link_bandwidth(struct exynos_dp_device
*dp
, u32 bwtype
)
860 if ((bwtype
== LINK_RATE_2_70GBPS
) || (bwtype
== LINK_RATE_1_62GBPS
))
861 writel(reg
, dp
->reg_base
+ EXYNOS_DP_LINK_BW_SET
);
864 void exynos_dp_get_link_bandwidth(struct exynos_dp_device
*dp
, u32
*bwtype
)
868 reg
= readl(dp
->reg_base
+ EXYNOS_DP_LINK_BW_SET
);
872 void exynos_dp_set_lane_count(struct exynos_dp_device
*dp
, u32 count
)
877 writel(reg
, dp
->reg_base
+ EXYNOS_DP_LANE_COUNT_SET
);
880 void exynos_dp_get_lane_count(struct exynos_dp_device
*dp
, u32
*count
)
884 reg
= readl(dp
->reg_base
+ EXYNOS_DP_LANE_COUNT_SET
);
888 void exynos_dp_enable_enhanced_mode(struct exynos_dp_device
*dp
, bool enable
)
893 reg
= readl(dp
->reg_base
+ EXYNOS_DP_SYS_CTL_4
);
895 writel(reg
, dp
->reg_base
+ EXYNOS_DP_SYS_CTL_4
);
897 reg
= readl(dp
->reg_base
+ EXYNOS_DP_SYS_CTL_4
);
899 writel(reg
, dp
->reg_base
+ EXYNOS_DP_SYS_CTL_4
);
903 void exynos_dp_set_training_pattern(struct exynos_dp_device
*dp
,
904 enum pattern_set pattern
)
910 reg
= SCRAMBLING_ENABLE
| LINK_QUAL_PATTERN_SET_PRBS7
;
911 writel(reg
, dp
->reg_base
+ EXYNOS_DP_TRAINING_PTN_SET
);
914 reg
= SCRAMBLING_ENABLE
| LINK_QUAL_PATTERN_SET_D10_2
;
915 writel(reg
, dp
->reg_base
+ EXYNOS_DP_TRAINING_PTN_SET
);
918 reg
= SCRAMBLING_DISABLE
| SW_TRAINING_PATTERN_SET_PTN1
;
919 writel(reg
, dp
->reg_base
+ EXYNOS_DP_TRAINING_PTN_SET
);
922 reg
= SCRAMBLING_DISABLE
| SW_TRAINING_PATTERN_SET_PTN2
;
923 writel(reg
, dp
->reg_base
+ EXYNOS_DP_TRAINING_PTN_SET
);
926 reg
= SCRAMBLING_ENABLE
|
927 LINK_QUAL_PATTERN_SET_DISABLE
|
928 SW_TRAINING_PATTERN_SET_NORMAL
;
929 writel(reg
, dp
->reg_base
+ EXYNOS_DP_TRAINING_PTN_SET
);
936 void exynos_dp_set_lane0_pre_emphasis(struct exynos_dp_device
*dp
, u32 level
)
940 reg
= readl(dp
->reg_base
+ EXYNOS_DP_LN0_LINK_TRAINING_CTL
);
941 reg
&= ~PRE_EMPHASIS_SET_MASK
;
942 reg
|= level
<< PRE_EMPHASIS_SET_SHIFT
;
943 writel(reg
, dp
->reg_base
+ EXYNOS_DP_LN0_LINK_TRAINING_CTL
);
946 void exynos_dp_set_lane1_pre_emphasis(struct exynos_dp_device
*dp
, u32 level
)
950 reg
= readl(dp
->reg_base
+ EXYNOS_DP_LN1_LINK_TRAINING_CTL
);
951 reg
&= ~PRE_EMPHASIS_SET_MASK
;
952 reg
|= level
<< PRE_EMPHASIS_SET_SHIFT
;
953 writel(reg
, dp
->reg_base
+ EXYNOS_DP_LN1_LINK_TRAINING_CTL
);
956 void exynos_dp_set_lane2_pre_emphasis(struct exynos_dp_device
*dp
, u32 level
)
960 reg
= readl(dp
->reg_base
+ EXYNOS_DP_LN2_LINK_TRAINING_CTL
);
961 reg
&= ~PRE_EMPHASIS_SET_MASK
;
962 reg
|= level
<< PRE_EMPHASIS_SET_SHIFT
;
963 writel(reg
, dp
->reg_base
+ EXYNOS_DP_LN2_LINK_TRAINING_CTL
);
966 void exynos_dp_set_lane3_pre_emphasis(struct exynos_dp_device
*dp
, u32 level
)
970 reg
= readl(dp
->reg_base
+ EXYNOS_DP_LN3_LINK_TRAINING_CTL
);
971 reg
&= ~PRE_EMPHASIS_SET_MASK
;
972 reg
|= level
<< PRE_EMPHASIS_SET_SHIFT
;
973 writel(reg
, dp
->reg_base
+ EXYNOS_DP_LN3_LINK_TRAINING_CTL
);
976 void exynos_dp_set_lane0_link_training(struct exynos_dp_device
*dp
,
982 writel(reg
, dp
->reg_base
+ EXYNOS_DP_LN0_LINK_TRAINING_CTL
);
985 void exynos_dp_set_lane1_link_training(struct exynos_dp_device
*dp
,
991 writel(reg
, dp
->reg_base
+ EXYNOS_DP_LN1_LINK_TRAINING_CTL
);
994 void exynos_dp_set_lane2_link_training(struct exynos_dp_device
*dp
,
1000 writel(reg
, dp
->reg_base
+ EXYNOS_DP_LN2_LINK_TRAINING_CTL
);
1003 void exynos_dp_set_lane3_link_training(struct exynos_dp_device
*dp
,
1008 reg
= training_lane
;
1009 writel(reg
, dp
->reg_base
+ EXYNOS_DP_LN3_LINK_TRAINING_CTL
);
1012 u32
exynos_dp_get_lane0_link_training(struct exynos_dp_device
*dp
)
1016 reg
= readl(dp
->reg_base
+ EXYNOS_DP_LN0_LINK_TRAINING_CTL
);
1020 u32
exynos_dp_get_lane1_link_training(struct exynos_dp_device
*dp
)
1024 reg
= readl(dp
->reg_base
+ EXYNOS_DP_LN1_LINK_TRAINING_CTL
);
1028 u32
exynos_dp_get_lane2_link_training(struct exynos_dp_device
*dp
)
1032 reg
= readl(dp
->reg_base
+ EXYNOS_DP_LN2_LINK_TRAINING_CTL
);
1036 u32
exynos_dp_get_lane3_link_training(struct exynos_dp_device
*dp
)
1040 reg
= readl(dp
->reg_base
+ EXYNOS_DP_LN3_LINK_TRAINING_CTL
);
1044 void exynos_dp_reset_macro(struct exynos_dp_device
*dp
)
1048 reg
= readl(dp
->reg_base
+ EXYNOS_DP_PHY_TEST
);
1050 writel(reg
, dp
->reg_base
+ EXYNOS_DP_PHY_TEST
);
1052 /* 10 us is the minimum reset time. */
1053 usleep_range(10, 20);
1056 writel(reg
, dp
->reg_base
+ EXYNOS_DP_PHY_TEST
);
1059 void exynos_dp_init_video(struct exynos_dp_device
*dp
)
1063 reg
= VSYNC_DET
| VID_FORMAT_CHG
| VID_CLK_CHG
;
1064 writel(reg
, dp
->reg_base
+ EXYNOS_DP_COMMON_INT_STA_1
);
1067 writel(reg
, dp
->reg_base
+ EXYNOS_DP_SYS_CTL_1
);
1069 reg
= CHA_CRI(4) | CHA_CTRL
;
1070 writel(reg
, dp
->reg_base
+ EXYNOS_DP_SYS_CTL_2
);
1073 writel(reg
, dp
->reg_base
+ EXYNOS_DP_SYS_CTL_3
);
1075 reg
= VID_HRES_TH(2) | VID_VRES_TH(0);
1076 writel(reg
, dp
->reg_base
+ EXYNOS_DP_VIDEO_CTL_8
);
1079 void exynos_dp_set_video_color_format(struct exynos_dp_device
*dp
)
1083 /* Configure the input color depth, color space, dynamic range */
1084 reg
= (dp
->video_info
->dynamic_range
<< IN_D_RANGE_SHIFT
) |
1085 (dp
->video_info
->color_depth
<< IN_BPC_SHIFT
) |
1086 (dp
->video_info
->color_space
<< IN_COLOR_F_SHIFT
);
1087 writel(reg
, dp
->reg_base
+ EXYNOS_DP_VIDEO_CTL_2
);
1089 /* Set Input Color YCbCr Coefficients to ITU601 or ITU709 */
1090 reg
= readl(dp
->reg_base
+ EXYNOS_DP_VIDEO_CTL_3
);
1091 reg
&= ~IN_YC_COEFFI_MASK
;
1092 if (dp
->video_info
->ycbcr_coeff
)
1093 reg
|= IN_YC_COEFFI_ITU709
;
1095 reg
|= IN_YC_COEFFI_ITU601
;
1096 writel(reg
, dp
->reg_base
+ EXYNOS_DP_VIDEO_CTL_3
);
1099 int exynos_dp_is_slave_video_stream_clock_on(struct exynos_dp_device
*dp
)
1103 reg
= readl(dp
->reg_base
+ EXYNOS_DP_SYS_CTL_1
);
1104 writel(reg
, dp
->reg_base
+ EXYNOS_DP_SYS_CTL_1
);
1106 reg
= readl(dp
->reg_base
+ EXYNOS_DP_SYS_CTL_1
);
1108 if (!(reg
& DET_STA
)) {
1109 dev_dbg(dp
->dev
, "Input stream clock not detected.\n");
1113 reg
= readl(dp
->reg_base
+ EXYNOS_DP_SYS_CTL_2
);
1114 writel(reg
, dp
->reg_base
+ EXYNOS_DP_SYS_CTL_2
);
1116 reg
= readl(dp
->reg_base
+ EXYNOS_DP_SYS_CTL_2
);
1117 dev_dbg(dp
->dev
, "wait SYS_CTL_2.\n");
1119 if (reg
& CHA_STA
) {
1120 dev_dbg(dp
->dev
, "Input stream clk is changing\n");
1127 void exynos_dp_set_video_cr_mn(struct exynos_dp_device
*dp
,
1128 enum clock_recovery_m_value_type type
,
1134 if (type
== REGISTER_M
) {
1135 reg
= readl(dp
->reg_base
+ EXYNOS_DP_SYS_CTL_4
);
1137 writel(reg
, dp
->reg_base
+ EXYNOS_DP_SYS_CTL_4
);
1138 reg
= m_value
& 0xff;
1139 writel(reg
, dp
->reg_base
+ EXYNOS_DP_M_VID_0
);
1140 reg
= (m_value
>> 8) & 0xff;
1141 writel(reg
, dp
->reg_base
+ EXYNOS_DP_M_VID_1
);
1142 reg
= (m_value
>> 16) & 0xff;
1143 writel(reg
, dp
->reg_base
+ EXYNOS_DP_M_VID_2
);
1145 reg
= n_value
& 0xff;
1146 writel(reg
, dp
->reg_base
+ EXYNOS_DP_N_VID_0
);
1147 reg
= (n_value
>> 8) & 0xff;
1148 writel(reg
, dp
->reg_base
+ EXYNOS_DP_N_VID_1
);
1149 reg
= (n_value
>> 16) & 0xff;
1150 writel(reg
, dp
->reg_base
+ EXYNOS_DP_N_VID_2
);
1152 reg
= readl(dp
->reg_base
+ EXYNOS_DP_SYS_CTL_4
);
1154 writel(reg
, dp
->reg_base
+ EXYNOS_DP_SYS_CTL_4
);
1156 writel(0x00, dp
->reg_base
+ EXYNOS_DP_N_VID_0
);
1157 writel(0x80, dp
->reg_base
+ EXYNOS_DP_N_VID_1
);
1158 writel(0x00, dp
->reg_base
+ EXYNOS_DP_N_VID_2
);
1162 void exynos_dp_set_video_timing_mode(struct exynos_dp_device
*dp
, u32 type
)
1166 if (type
== VIDEO_TIMING_FROM_CAPTURE
) {
1167 reg
= readl(dp
->reg_base
+ EXYNOS_DP_VIDEO_CTL_10
);
1169 writel(reg
, dp
->reg_base
+ EXYNOS_DP_VIDEO_CTL_10
);
1171 reg
= readl(dp
->reg_base
+ EXYNOS_DP_VIDEO_CTL_10
);
1173 writel(reg
, dp
->reg_base
+ EXYNOS_DP_VIDEO_CTL_10
);
1177 void exynos_dp_enable_video_master(struct exynos_dp_device
*dp
, bool enable
)
1182 reg
= readl(dp
->reg_base
+ EXYNOS_DP_SOC_GENERAL_CTL
);
1183 reg
&= ~VIDEO_MODE_MASK
;
1184 reg
|= VIDEO_MASTER_MODE_EN
| VIDEO_MODE_MASTER_MODE
;
1185 writel(reg
, dp
->reg_base
+ EXYNOS_DP_SOC_GENERAL_CTL
);
1187 reg
= readl(dp
->reg_base
+ EXYNOS_DP_SOC_GENERAL_CTL
);
1188 reg
&= ~VIDEO_MODE_MASK
;
1189 reg
|= VIDEO_MODE_SLAVE_MODE
;
1190 writel(reg
, dp
->reg_base
+ EXYNOS_DP_SOC_GENERAL_CTL
);
1194 void exynos_dp_start_video(struct exynos_dp_device
*dp
)
1198 reg
= readl(dp
->reg_base
+ EXYNOS_DP_VIDEO_CTL_1
);
1200 writel(reg
, dp
->reg_base
+ EXYNOS_DP_VIDEO_CTL_1
);
1203 int exynos_dp_is_video_stream_on(struct exynos_dp_device
*dp
)
1207 reg
= readl(dp
->reg_base
+ EXYNOS_DP_SYS_CTL_3
);
1208 writel(reg
, dp
->reg_base
+ EXYNOS_DP_SYS_CTL_3
);
1210 reg
= readl(dp
->reg_base
+ EXYNOS_DP_SYS_CTL_3
);
1211 if (!(reg
& STRM_VALID
)) {
1212 dev_dbg(dp
->dev
, "Input video stream is not detected.\n");
1219 void exynos_dp_config_video_slave_mode(struct exynos_dp_device
*dp
)
1223 reg
= readl(dp
->reg_base
+ EXYNOS_DP_FUNC_EN_1
);
1224 reg
&= ~(MASTER_VID_FUNC_EN_N
|SLAVE_VID_FUNC_EN_N
);
1225 reg
|= MASTER_VID_FUNC_EN_N
;
1226 writel(reg
, dp
->reg_base
+ EXYNOS_DP_FUNC_EN_1
);
1228 reg
= readl(dp
->reg_base
+ EXYNOS_DP_VIDEO_CTL_10
);
1229 reg
&= ~INTERACE_SCAN_CFG
;
1230 reg
|= (dp
->video_info
->interlaced
<< 2);
1231 writel(reg
, dp
->reg_base
+ EXYNOS_DP_VIDEO_CTL_10
);
1233 reg
= readl(dp
->reg_base
+ EXYNOS_DP_VIDEO_CTL_10
);
1234 reg
&= ~VSYNC_POLARITY_CFG
;
1235 reg
|= (dp
->video_info
->v_sync_polarity
<< 1);
1236 writel(reg
, dp
->reg_base
+ EXYNOS_DP_VIDEO_CTL_10
);
1238 reg
= readl(dp
->reg_base
+ EXYNOS_DP_VIDEO_CTL_10
);
1239 reg
&= ~HSYNC_POLARITY_CFG
;
1240 reg
|= (dp
->video_info
->h_sync_polarity
<< 0);
1241 writel(reg
, dp
->reg_base
+ EXYNOS_DP_VIDEO_CTL_10
);
1243 reg
= AUDIO_MODE_SPDIF_MODE
| VIDEO_MODE_SLAVE_MODE
;
1244 writel(reg
, dp
->reg_base
+ EXYNOS_DP_SOC_GENERAL_CTL
);
1247 void exynos_dp_enable_scrambling(struct exynos_dp_device
*dp
)
1251 reg
= readl(dp
->reg_base
+ EXYNOS_DP_TRAINING_PTN_SET
);
1252 reg
&= ~SCRAMBLING_DISABLE
;
1253 writel(reg
, dp
->reg_base
+ EXYNOS_DP_TRAINING_PTN_SET
);
1256 void exynos_dp_disable_scrambling(struct exynos_dp_device
*dp
)
1260 reg
= readl(dp
->reg_base
+ EXYNOS_DP_TRAINING_PTN_SET
);
1261 reg
|= SCRAMBLING_DISABLE
;
1262 writel(reg
, dp
->reg_base
+ EXYNOS_DP_TRAINING_PTN_SET
);