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>
17 #include "exynos_dp_core.h"
18 #include "exynos_dp_reg.h"
20 #define COMMON_INT_MASK_1 0
21 #define COMMON_INT_MASK_2 0
22 #define COMMON_INT_MASK_3 0
23 #define COMMON_INT_MASK_4 (HOTPLUG_CHG | HPD_LOST | PLUG)
24 #define INT_STA_MASK INT_HPD
26 void exynos_dp_enable_video_mute(struct exynos_dp_device
*dp
, bool enable
)
31 reg
= readl(dp
->reg_base
+ EXYNOS_DP_VIDEO_CTL_1
);
32 reg
|= HDCP_VIDEO_MUTE
;
33 writel(reg
, dp
->reg_base
+ EXYNOS_DP_VIDEO_CTL_1
);
35 reg
= readl(dp
->reg_base
+ EXYNOS_DP_VIDEO_CTL_1
);
36 reg
&= ~HDCP_VIDEO_MUTE
;
37 writel(reg
, dp
->reg_base
+ EXYNOS_DP_VIDEO_CTL_1
);
41 void exynos_dp_stop_video(struct exynos_dp_device
*dp
)
45 reg
= readl(dp
->reg_base
+ EXYNOS_DP_VIDEO_CTL_1
);
47 writel(reg
, dp
->reg_base
+ EXYNOS_DP_VIDEO_CTL_1
);
50 void exynos_dp_lane_swap(struct exynos_dp_device
*dp
, bool enable
)
55 reg
= LANE3_MAP_LOGIC_LANE_0
| LANE2_MAP_LOGIC_LANE_1
|
56 LANE1_MAP_LOGIC_LANE_2
| LANE0_MAP_LOGIC_LANE_3
;
58 reg
= LANE3_MAP_LOGIC_LANE_3
| LANE2_MAP_LOGIC_LANE_2
|
59 LANE1_MAP_LOGIC_LANE_1
| LANE0_MAP_LOGIC_LANE_0
;
61 writel(reg
, dp
->reg_base
+ EXYNOS_DP_LANE_MAP
);
64 void exynos_dp_init_analog_param(struct exynos_dp_device
*dp
)
68 reg
= TX_TERMINAL_CTRL_50_OHM
;
69 writel(reg
, dp
->reg_base
+ EXYNOS_DP_ANALOG_CTL_1
);
71 reg
= SEL_24M
| TX_DVDD_BIT_1_0625V
;
72 writel(reg
, dp
->reg_base
+ EXYNOS_DP_ANALOG_CTL_2
);
74 reg
= DRIVE_DVDD_BIT_1_0625V
| VCO_BIT_600_MICRO
;
75 writel(reg
, dp
->reg_base
+ EXYNOS_DP_ANALOG_CTL_3
);
77 reg
= PD_RING_OSC
| AUX_TERMINAL_CTRL_50_OHM
|
78 TX_CUR1_2X
| TX_CUR_16_MA
;
79 writel(reg
, dp
->reg_base
+ EXYNOS_DP_PLL_FILTER_CTL_1
);
81 reg
= CH3_AMP_400_MV
| CH2_AMP_400_MV
|
82 CH1_AMP_400_MV
| CH0_AMP_400_MV
;
83 writel(reg
, dp
->reg_base
+ EXYNOS_DP_TX_AMP_TUNING_CTL
);
86 void exynos_dp_init_interrupt(struct exynos_dp_device
*dp
)
88 /* Set interrupt pin assertion polarity as high */
89 writel(INT_POL1
| INT_POL0
, dp
->reg_base
+ EXYNOS_DP_INT_CTL
);
91 /* Clear pending regisers */
92 writel(0xff, dp
->reg_base
+ EXYNOS_DP_COMMON_INT_STA_1
);
93 writel(0x4f, dp
->reg_base
+ EXYNOS_DP_COMMON_INT_STA_2
);
94 writel(0xe0, dp
->reg_base
+ EXYNOS_DP_COMMON_INT_STA_3
);
95 writel(0xe7, dp
->reg_base
+ EXYNOS_DP_COMMON_INT_STA_4
);
96 writel(0x63, dp
->reg_base
+ EXYNOS_DP_INT_STA
);
98 /* 0:mask,1: unmask */
99 writel(0x00, dp
->reg_base
+ EXYNOS_DP_COMMON_INT_MASK_1
);
100 writel(0x00, dp
->reg_base
+ EXYNOS_DP_COMMON_INT_MASK_2
);
101 writel(0x00, dp
->reg_base
+ EXYNOS_DP_COMMON_INT_MASK_3
);
102 writel(0x00, dp
->reg_base
+ EXYNOS_DP_COMMON_INT_MASK_4
);
103 writel(0x00, dp
->reg_base
+ EXYNOS_DP_INT_STA_MASK
);
106 void exynos_dp_reset(struct exynos_dp_device
*dp
)
110 exynos_dp_stop_video(dp
);
111 exynos_dp_enable_video_mute(dp
, 0);
113 reg
= MASTER_VID_FUNC_EN_N
| SLAVE_VID_FUNC_EN_N
|
114 AUD_FIFO_FUNC_EN_N
| AUD_FUNC_EN_N
|
115 HDCP_FUNC_EN_N
| SW_FUNC_EN_N
;
116 writel(reg
, dp
->reg_base
+ EXYNOS_DP_FUNC_EN_1
);
118 reg
= SSC_FUNC_EN_N
| AUX_FUNC_EN_N
|
119 SERDES_FIFO_FUNC_EN_N
|
120 LS_CLK_DOMAIN_FUNC_EN_N
;
121 writel(reg
, dp
->reg_base
+ EXYNOS_DP_FUNC_EN_2
);
123 usleep_range(20, 30);
125 exynos_dp_lane_swap(dp
, 0);
127 writel(0x0, dp
->reg_base
+ EXYNOS_DP_SYS_CTL_1
);
128 writel(0x40, dp
->reg_base
+ EXYNOS_DP_SYS_CTL_2
);
129 writel(0x0, dp
->reg_base
+ EXYNOS_DP_SYS_CTL_3
);
130 writel(0x0, dp
->reg_base
+ EXYNOS_DP_SYS_CTL_4
);
132 writel(0x0, dp
->reg_base
+ EXYNOS_DP_PKT_SEND_CTL
);
133 writel(0x0, dp
->reg_base
+ EXYNOS_DP_HDCP_CTL
);
135 writel(0x5e, dp
->reg_base
+ EXYNOS_DP_HPD_DEGLITCH_L
);
136 writel(0x1a, dp
->reg_base
+ EXYNOS_DP_HPD_DEGLITCH_H
);
138 writel(0x10, dp
->reg_base
+ EXYNOS_DP_LINK_DEBUG_CTL
);
140 writel(0x0, dp
->reg_base
+ EXYNOS_DP_PHY_TEST
);
142 writel(0x0, dp
->reg_base
+ EXYNOS_DP_VIDEO_FIFO_THRD
);
143 writel(0x20, dp
->reg_base
+ EXYNOS_DP_AUDIO_MARGIN
);
145 writel(0x4, dp
->reg_base
+ EXYNOS_DP_M_VID_GEN_FILTER_TH
);
146 writel(0x2, dp
->reg_base
+ EXYNOS_DP_M_AUD_GEN_FILTER_TH
);
148 writel(0x00000101, dp
->reg_base
+ EXYNOS_DP_SOC_GENERAL_CTL
);
151 void exynos_dp_swreset(struct exynos_dp_device
*dp
)
153 writel(RESET_DP_TX
, dp
->reg_base
+ EXYNOS_DP_TX_SW_RESET
);
156 void exynos_dp_config_interrupt(struct exynos_dp_device
*dp
)
160 /* 0: mask, 1: unmask */
161 reg
= COMMON_INT_MASK_1
;
162 writel(reg
, dp
->reg_base
+ EXYNOS_DP_COMMON_INT_MASK_1
);
164 reg
= COMMON_INT_MASK_2
;
165 writel(reg
, dp
->reg_base
+ EXYNOS_DP_COMMON_INT_MASK_2
);
167 reg
= COMMON_INT_MASK_3
;
168 writel(reg
, dp
->reg_base
+ EXYNOS_DP_COMMON_INT_MASK_3
);
170 reg
= COMMON_INT_MASK_4
;
171 writel(reg
, dp
->reg_base
+ EXYNOS_DP_COMMON_INT_MASK_4
);
174 writel(reg
, dp
->reg_base
+ EXYNOS_DP_INT_STA_MASK
);
177 enum pll_status
exynos_dp_get_pll_lock_status(struct exynos_dp_device
*dp
)
181 reg
= readl(dp
->reg_base
+ EXYNOS_DP_DEBUG_CTL
);
188 void exynos_dp_set_pll_power_down(struct exynos_dp_device
*dp
, bool enable
)
193 reg
= readl(dp
->reg_base
+ EXYNOS_DP_PLL_CTL
);
195 writel(reg
, dp
->reg_base
+ EXYNOS_DP_PLL_CTL
);
197 reg
= readl(dp
->reg_base
+ EXYNOS_DP_PLL_CTL
);
199 writel(reg
, dp
->reg_base
+ EXYNOS_DP_PLL_CTL
);
203 void exynos_dp_set_analog_power_down(struct exynos_dp_device
*dp
,
204 enum analog_power_block block
,
212 reg
= readl(dp
->reg_base
+ EXYNOS_DP_PHY_PD
);
214 writel(reg
, dp
->reg_base
+ EXYNOS_DP_PHY_PD
);
216 reg
= readl(dp
->reg_base
+ EXYNOS_DP_PHY_PD
);
218 writel(reg
, dp
->reg_base
+ EXYNOS_DP_PHY_PD
);
223 reg
= readl(dp
->reg_base
+ EXYNOS_DP_PHY_PD
);
225 writel(reg
, dp
->reg_base
+ EXYNOS_DP_PHY_PD
);
227 reg
= readl(dp
->reg_base
+ EXYNOS_DP_PHY_PD
);
229 writel(reg
, dp
->reg_base
+ EXYNOS_DP_PHY_PD
);
234 reg
= readl(dp
->reg_base
+ EXYNOS_DP_PHY_PD
);
236 writel(reg
, dp
->reg_base
+ EXYNOS_DP_PHY_PD
);
238 reg
= readl(dp
->reg_base
+ EXYNOS_DP_PHY_PD
);
240 writel(reg
, dp
->reg_base
+ EXYNOS_DP_PHY_PD
);
245 reg
= readl(dp
->reg_base
+ EXYNOS_DP_PHY_PD
);
247 writel(reg
, dp
->reg_base
+ EXYNOS_DP_PHY_PD
);
249 reg
= readl(dp
->reg_base
+ EXYNOS_DP_PHY_PD
);
251 writel(reg
, dp
->reg_base
+ EXYNOS_DP_PHY_PD
);
256 reg
= readl(dp
->reg_base
+ EXYNOS_DP_PHY_PD
);
258 writel(reg
, dp
->reg_base
+ EXYNOS_DP_PHY_PD
);
260 reg
= readl(dp
->reg_base
+ EXYNOS_DP_PHY_PD
);
262 writel(reg
, dp
->reg_base
+ EXYNOS_DP_PHY_PD
);
267 reg
= readl(dp
->reg_base
+ EXYNOS_DP_PHY_PD
);
269 writel(reg
, dp
->reg_base
+ EXYNOS_DP_PHY_PD
);
271 reg
= readl(dp
->reg_base
+ EXYNOS_DP_PHY_PD
);
273 writel(reg
, dp
->reg_base
+ EXYNOS_DP_PHY_PD
);
278 reg
= DP_PHY_PD
| AUX_PD
| CH3_PD
| CH2_PD
|
280 writel(reg
, dp
->reg_base
+ EXYNOS_DP_PHY_PD
);
282 writel(0x00, dp
->reg_base
+ EXYNOS_DP_PHY_PD
);
290 void exynos_dp_init_analog_func(struct exynos_dp_device
*dp
)
293 int timeout_loop
= 0;
295 exynos_dp_set_analog_power_down(dp
, POWER_ALL
, 0);
298 writel(reg
, dp
->reg_base
+ EXYNOS_DP_COMMON_INT_STA_1
);
300 reg
= readl(dp
->reg_base
+ EXYNOS_DP_DEBUG_CTL
);
301 reg
&= ~(F_PLL_LOCK
| PLL_LOCK_CTRL
);
302 writel(reg
, dp
->reg_base
+ EXYNOS_DP_DEBUG_CTL
);
305 if (exynos_dp_get_pll_lock_status(dp
) == PLL_UNLOCKED
) {
306 exynos_dp_set_pll_power_down(dp
, 0);
308 while (exynos_dp_get_pll_lock_status(dp
) == PLL_UNLOCKED
) {
310 if (DP_TIMEOUT_LOOP_COUNT
< timeout_loop
) {
311 dev_err(dp
->dev
, "failed to get pll lock status\n");
314 usleep_range(10, 20);
318 /* Enable Serdes FIFO function and Link symbol clock domain module */
319 reg
= readl(dp
->reg_base
+ EXYNOS_DP_FUNC_EN_2
);
320 reg
&= ~(SERDES_FIFO_FUNC_EN_N
| LS_CLK_DOMAIN_FUNC_EN_N
322 writel(reg
, dp
->reg_base
+ EXYNOS_DP_FUNC_EN_2
);
325 void exynos_dp_clear_hotplug_interrupts(struct exynos_dp_device
*dp
)
329 reg
= HOTPLUG_CHG
| HPD_LOST
| PLUG
;
330 writel(reg
, dp
->reg_base
+ EXYNOS_DP_COMMON_INT_STA_4
);
333 writel(reg
, dp
->reg_base
+ EXYNOS_DP_INT_STA
);
336 void exynos_dp_init_hpd(struct exynos_dp_device
*dp
)
340 exynos_dp_clear_hotplug_interrupts(dp
);
342 reg
= readl(dp
->reg_base
+ EXYNOS_DP_SYS_CTL_3
);
343 reg
&= ~(F_HPD
| HPD_CTRL
);
344 writel(reg
, dp
->reg_base
+ EXYNOS_DP_SYS_CTL_3
);
347 enum dp_irq_type
exynos_dp_get_irq_type(struct exynos_dp_device
*dp
)
351 /* Parse hotplug interrupt status register */
352 reg
= readl(dp
->reg_base
+ EXYNOS_DP_COMMON_INT_STA_4
);
355 return DP_IRQ_TYPE_HP_CABLE_IN
;
358 return DP_IRQ_TYPE_HP_CABLE_OUT
;
360 if (reg
& HOTPLUG_CHG
)
361 return DP_IRQ_TYPE_HP_CHANGE
;
363 return DP_IRQ_TYPE_UNKNOWN
;
366 void exynos_dp_reset_aux(struct exynos_dp_device
*dp
)
370 /* Disable AUX channel module */
371 reg
= readl(dp
->reg_base
+ EXYNOS_DP_FUNC_EN_2
);
372 reg
|= AUX_FUNC_EN_N
;
373 writel(reg
, dp
->reg_base
+ EXYNOS_DP_FUNC_EN_2
);
376 void exynos_dp_init_aux(struct exynos_dp_device
*dp
)
380 /* Clear inerrupts related to AUX channel */
381 reg
= RPLY_RECEIV
| AUX_ERR
;
382 writel(reg
, dp
->reg_base
+ EXYNOS_DP_INT_STA
);
384 exynos_dp_reset_aux(dp
);
386 /* Disable AUX transaction H/W retry */
387 reg
= AUX_BIT_PERIOD_EXPECTED_DELAY(3) | AUX_HW_RETRY_COUNT_SEL(0)|
388 AUX_HW_RETRY_INTERVAL_600_MICROSECONDS
;
389 writel(reg
, dp
->reg_base
+ EXYNOS_DP_AUX_HW_RETRY_CTL
) ;
391 /* Receive AUX Channel DEFER commands equal to DEFFER_COUNT*64 */
392 reg
= DEFER_CTRL_EN
| DEFER_COUNT(1);
393 writel(reg
, dp
->reg_base
+ EXYNOS_DP_AUX_CH_DEFER_CTL
);
395 /* Enable AUX channel module */
396 reg
= readl(dp
->reg_base
+ EXYNOS_DP_FUNC_EN_2
);
397 reg
&= ~AUX_FUNC_EN_N
;
398 writel(reg
, dp
->reg_base
+ EXYNOS_DP_FUNC_EN_2
);
401 int exynos_dp_get_plug_in_status(struct exynos_dp_device
*dp
)
405 reg
= readl(dp
->reg_base
+ EXYNOS_DP_SYS_CTL_3
);
406 if (reg
& HPD_STATUS
)
412 void exynos_dp_enable_sw_function(struct exynos_dp_device
*dp
)
416 reg
= readl(dp
->reg_base
+ EXYNOS_DP_FUNC_EN_1
);
417 reg
&= ~SW_FUNC_EN_N
;
418 writel(reg
, dp
->reg_base
+ EXYNOS_DP_FUNC_EN_1
);
421 int exynos_dp_start_aux_transaction(struct exynos_dp_device
*dp
)
425 int timeout_loop
= 0;
427 /* Enable AUX CH operation */
428 reg
= readl(dp
->reg_base
+ EXYNOS_DP_AUX_CH_CTL_2
);
430 writel(reg
, dp
->reg_base
+ EXYNOS_DP_AUX_CH_CTL_2
);
432 /* Is AUX CH command reply received? */
433 reg
= readl(dp
->reg_base
+ EXYNOS_DP_INT_STA
);
434 while (!(reg
& RPLY_RECEIV
)) {
436 if (DP_TIMEOUT_LOOP_COUNT
< timeout_loop
) {
437 dev_err(dp
->dev
, "AUX CH command reply failed!\n");
440 reg
= readl(dp
->reg_base
+ EXYNOS_DP_INT_STA
);
441 usleep_range(10, 11);
444 /* Clear interrupt source for AUX CH command reply */
445 writel(RPLY_RECEIV
, dp
->reg_base
+ EXYNOS_DP_INT_STA
);
447 /* Clear interrupt source for AUX CH access error */
448 reg
= readl(dp
->reg_base
+ EXYNOS_DP_INT_STA
);
450 writel(AUX_ERR
, dp
->reg_base
+ EXYNOS_DP_INT_STA
);
454 /* Check AUX CH error access status */
455 reg
= readl(dp
->reg_base
+ EXYNOS_DP_AUX_CH_STA
);
456 if ((reg
& AUX_STATUS_MASK
) != 0) {
457 dev_err(dp
->dev
, "AUX CH error happens: %d\n\n",
458 reg
& AUX_STATUS_MASK
);
465 int exynos_dp_write_byte_to_dpcd(struct exynos_dp_device
*dp
,
466 unsigned int reg_addr
,
473 for (i
= 0; i
< 3; i
++) {
474 /* Clear AUX CH data buffer */
476 writel(reg
, dp
->reg_base
+ EXYNOS_DP_BUFFER_DATA_CTL
);
478 /* Select DPCD device address */
479 reg
= AUX_ADDR_7_0(reg_addr
);
480 writel(reg
, dp
->reg_base
+ EXYNOS_DP_AUX_ADDR_7_0
);
481 reg
= AUX_ADDR_15_8(reg_addr
);
482 writel(reg
, dp
->reg_base
+ EXYNOS_DP_AUX_ADDR_15_8
);
483 reg
= AUX_ADDR_19_16(reg_addr
);
484 writel(reg
, dp
->reg_base
+ EXYNOS_DP_AUX_ADDR_19_16
);
486 /* Write data buffer */
487 reg
= (unsigned int)data
;
488 writel(reg
, dp
->reg_base
+ EXYNOS_DP_BUF_DATA_0
);
491 * Set DisplayPort transaction and write 1 byte
492 * If bit 3 is 1, DisplayPort transaction.
493 * If Bit 3 is 0, I2C transaction.
495 reg
= AUX_TX_COMM_DP_TRANSACTION
| AUX_TX_COMM_WRITE
;
496 writel(reg
, dp
->reg_base
+ EXYNOS_DP_AUX_CH_CTL_1
);
498 /* Start AUX transaction */
499 retval
= exynos_dp_start_aux_transaction(dp
);
503 dev_dbg(dp
->dev
, "%s: Aux Transaction fail!\n",
510 int exynos_dp_read_byte_from_dpcd(struct exynos_dp_device
*dp
,
511 unsigned int reg_addr
,
518 for (i
= 0; i
< 3; i
++) {
519 /* Clear AUX CH data buffer */
521 writel(reg
, dp
->reg_base
+ EXYNOS_DP_BUFFER_DATA_CTL
);
523 /* Select DPCD device address */
524 reg
= AUX_ADDR_7_0(reg_addr
);
525 writel(reg
, dp
->reg_base
+ EXYNOS_DP_AUX_ADDR_7_0
);
526 reg
= AUX_ADDR_15_8(reg_addr
);
527 writel(reg
, dp
->reg_base
+ EXYNOS_DP_AUX_ADDR_15_8
);
528 reg
= AUX_ADDR_19_16(reg_addr
);
529 writel(reg
, dp
->reg_base
+ EXYNOS_DP_AUX_ADDR_19_16
);
532 * Set DisplayPort transaction and read 1 byte
533 * If bit 3 is 1, DisplayPort transaction.
534 * If Bit 3 is 0, I2C transaction.
536 reg
= AUX_TX_COMM_DP_TRANSACTION
| AUX_TX_COMM_READ
;
537 writel(reg
, dp
->reg_base
+ EXYNOS_DP_AUX_CH_CTL_1
);
539 /* Start AUX transaction */
540 retval
= exynos_dp_start_aux_transaction(dp
);
544 dev_dbg(dp
->dev
, "%s: Aux Transaction fail!\n",
548 /* Read data buffer */
549 reg
= readl(dp
->reg_base
+ EXYNOS_DP_BUF_DATA_0
);
550 *data
= (unsigned char)(reg
& 0xff);
555 int exynos_dp_write_bytes_to_dpcd(struct exynos_dp_device
*dp
,
556 unsigned int reg_addr
,
558 unsigned char data
[])
561 unsigned int start_offset
;
562 unsigned int cur_data_count
;
563 unsigned int cur_data_idx
;
567 /* Clear AUX CH data buffer */
569 writel(reg
, dp
->reg_base
+ EXYNOS_DP_BUFFER_DATA_CTL
);
572 while (start_offset
< count
) {
573 /* Buffer size of AUX CH is 16 * 4bytes */
574 if ((count
- start_offset
) > 16)
577 cur_data_count
= count
- start_offset
;
579 for (i
= 0; i
< 3; i
++) {
580 /* Select DPCD device address */
581 reg
= AUX_ADDR_7_0(reg_addr
+ start_offset
);
582 writel(reg
, dp
->reg_base
+ EXYNOS_DP_AUX_ADDR_7_0
);
583 reg
= AUX_ADDR_15_8(reg_addr
+ start_offset
);
584 writel(reg
, dp
->reg_base
+ EXYNOS_DP_AUX_ADDR_15_8
);
585 reg
= AUX_ADDR_19_16(reg_addr
+ start_offset
);
586 writel(reg
, dp
->reg_base
+ EXYNOS_DP_AUX_ADDR_19_16
);
588 for (cur_data_idx
= 0; cur_data_idx
< cur_data_count
;
590 reg
= data
[start_offset
+ cur_data_idx
];
591 writel(reg
, dp
->reg_base
+ EXYNOS_DP_BUF_DATA_0
596 * Set DisplayPort transaction and write
597 * If bit 3 is 1, DisplayPort transaction.
598 * If Bit 3 is 0, I2C transaction.
600 reg
= AUX_LENGTH(cur_data_count
) |
601 AUX_TX_COMM_DP_TRANSACTION
| AUX_TX_COMM_WRITE
;
602 writel(reg
, dp
->reg_base
+ EXYNOS_DP_AUX_CH_CTL_1
);
604 /* Start AUX transaction */
605 retval
= exynos_dp_start_aux_transaction(dp
);
609 dev_dbg(dp
->dev
, "%s: Aux Transaction fail!\n",
613 start_offset
+= cur_data_count
;
619 int exynos_dp_read_bytes_from_dpcd(struct exynos_dp_device
*dp
,
620 unsigned int reg_addr
,
622 unsigned char data
[])
625 unsigned int start_offset
;
626 unsigned int cur_data_count
;
627 unsigned int cur_data_idx
;
631 /* Clear AUX CH data buffer */
633 writel(reg
, dp
->reg_base
+ EXYNOS_DP_BUFFER_DATA_CTL
);
636 while (start_offset
< count
) {
637 /* Buffer size of AUX CH is 16 * 4bytes */
638 if ((count
- start_offset
) > 16)
641 cur_data_count
= count
- start_offset
;
643 /* AUX CH Request Transaction process */
644 for (i
= 0; i
< 3; i
++) {
645 /* Select DPCD device address */
646 reg
= AUX_ADDR_7_0(reg_addr
+ start_offset
);
647 writel(reg
, dp
->reg_base
+ EXYNOS_DP_AUX_ADDR_7_0
);
648 reg
= AUX_ADDR_15_8(reg_addr
+ start_offset
);
649 writel(reg
, dp
->reg_base
+ EXYNOS_DP_AUX_ADDR_15_8
);
650 reg
= AUX_ADDR_19_16(reg_addr
+ start_offset
);
651 writel(reg
, dp
->reg_base
+ EXYNOS_DP_AUX_ADDR_19_16
);
654 * Set DisplayPort transaction and read
655 * If bit 3 is 1, DisplayPort transaction.
656 * If Bit 3 is 0, I2C transaction.
658 reg
= AUX_LENGTH(cur_data_count
) |
659 AUX_TX_COMM_DP_TRANSACTION
| AUX_TX_COMM_READ
;
660 writel(reg
, dp
->reg_base
+ EXYNOS_DP_AUX_CH_CTL_1
);
662 /* Start AUX transaction */
663 retval
= exynos_dp_start_aux_transaction(dp
);
667 dev_dbg(dp
->dev
, "%s: Aux Transaction fail!\n",
671 for (cur_data_idx
= 0; cur_data_idx
< cur_data_count
;
673 reg
= readl(dp
->reg_base
+ EXYNOS_DP_BUF_DATA_0
675 data
[start_offset
+ cur_data_idx
] =
679 start_offset
+= cur_data_count
;
685 int exynos_dp_select_i2c_device(struct exynos_dp_device
*dp
,
686 unsigned int device_addr
,
687 unsigned int reg_addr
)
692 /* Set EDID device address */
694 writel(reg
, dp
->reg_base
+ EXYNOS_DP_AUX_ADDR_7_0
);
695 writel(0x0, dp
->reg_base
+ EXYNOS_DP_AUX_ADDR_15_8
);
696 writel(0x0, dp
->reg_base
+ EXYNOS_DP_AUX_ADDR_19_16
);
698 /* Set offset from base address of EDID device */
699 writel(reg_addr
, dp
->reg_base
+ EXYNOS_DP_BUF_DATA_0
);
702 * Set I2C transaction and write address
703 * If bit 3 is 1, DisplayPort transaction.
704 * If Bit 3 is 0, I2C transaction.
706 reg
= AUX_TX_COMM_I2C_TRANSACTION
| AUX_TX_COMM_MOT
|
708 writel(reg
, dp
->reg_base
+ EXYNOS_DP_AUX_CH_CTL_1
);
710 /* Start AUX transaction */
711 retval
= exynos_dp_start_aux_transaction(dp
);
713 dev_dbg(dp
->dev
, "%s: Aux Transaction fail!\n", __func__
);
718 int exynos_dp_read_byte_from_i2c(struct exynos_dp_device
*dp
,
719 unsigned int device_addr
,
720 unsigned int reg_addr
,
727 for (i
= 0; i
< 3; i
++) {
728 /* Clear AUX CH data buffer */
730 writel(reg
, dp
->reg_base
+ EXYNOS_DP_BUFFER_DATA_CTL
);
732 /* Select EDID device */
733 retval
= exynos_dp_select_i2c_device(dp
, device_addr
, reg_addr
);
738 * Set I2C transaction and read data
739 * If bit 3 is 1, DisplayPort transaction.
740 * If Bit 3 is 0, I2C transaction.
742 reg
= AUX_TX_COMM_I2C_TRANSACTION
|
744 writel(reg
, dp
->reg_base
+ EXYNOS_DP_AUX_CH_CTL_1
);
746 /* Start AUX transaction */
747 retval
= exynos_dp_start_aux_transaction(dp
);
751 dev_dbg(dp
->dev
, "%s: Aux Transaction fail!\n",
757 *data
= readl(dp
->reg_base
+ EXYNOS_DP_BUF_DATA_0
);
762 int exynos_dp_read_bytes_from_i2c(struct exynos_dp_device
*dp
,
763 unsigned int device_addr
,
764 unsigned int reg_addr
,
766 unsigned char edid
[])
770 unsigned int cur_data_idx
;
771 unsigned int defer
= 0;
774 for (i
= 0; i
< count
; i
+= 16) {
775 for (j
= 0; j
< 3; j
++) {
776 /* Clear AUX CH data buffer */
778 writel(reg
, dp
->reg_base
+ EXYNOS_DP_BUFFER_DATA_CTL
);
780 /* Set normal AUX CH command */
781 reg
= readl(dp
->reg_base
+ EXYNOS_DP_AUX_CH_CTL_2
);
783 writel(reg
, dp
->reg_base
+ EXYNOS_DP_AUX_CH_CTL_2
);
786 * If Rx sends defer, Tx sends only reads
787 * request without sending address
790 retval
= exynos_dp_select_i2c_device(dp
,
791 device_addr
, reg_addr
+ i
);
797 * Set I2C transaction and write data
798 * If bit 3 is 1, DisplayPort transaction.
799 * If Bit 3 is 0, I2C transaction.
801 reg
= AUX_LENGTH(16) |
802 AUX_TX_COMM_I2C_TRANSACTION
|
804 writel(reg
, dp
->reg_base
+
805 EXYNOS_DP_AUX_CH_CTL_1
);
807 /* Start AUX transaction */
808 retval
= exynos_dp_start_aux_transaction(dp
);
813 "%s: Aux Transaction fail!\n",
816 /* Check if Rx sends defer */
817 reg
= readl(dp
->reg_base
+ EXYNOS_DP_AUX_RX_COMM
);
818 if (reg
== AUX_RX_COMM_AUX_DEFER
||
819 reg
== AUX_RX_COMM_I2C_DEFER
) {
820 dev_err(dp
->dev
, "Defer: %d\n\n", reg
);
825 for (cur_data_idx
= 0; cur_data_idx
< 16; cur_data_idx
++) {
826 reg
= readl(dp
->reg_base
+ EXYNOS_DP_BUF_DATA_0
828 edid
[i
+ cur_data_idx
] = (unsigned char)reg
;
835 void exynos_dp_set_link_bandwidth(struct exynos_dp_device
*dp
, u32 bwtype
)
840 if ((bwtype
== LINK_RATE_2_70GBPS
) || (bwtype
== LINK_RATE_1_62GBPS
))
841 writel(reg
, dp
->reg_base
+ EXYNOS_DP_LINK_BW_SET
);
844 void exynos_dp_get_link_bandwidth(struct exynos_dp_device
*dp
, u32
*bwtype
)
848 reg
= readl(dp
->reg_base
+ EXYNOS_DP_LINK_BW_SET
);
852 void exynos_dp_set_lane_count(struct exynos_dp_device
*dp
, u32 count
)
857 writel(reg
, dp
->reg_base
+ EXYNOS_DP_LANE_COUNT_SET
);
860 void exynos_dp_get_lane_count(struct exynos_dp_device
*dp
, u32
*count
)
864 reg
= readl(dp
->reg_base
+ EXYNOS_DP_LANE_COUNT_SET
);
868 void exynos_dp_enable_enhanced_mode(struct exynos_dp_device
*dp
, bool enable
)
873 reg
= readl(dp
->reg_base
+ EXYNOS_DP_SYS_CTL_4
);
875 writel(reg
, dp
->reg_base
+ EXYNOS_DP_SYS_CTL_4
);
877 reg
= readl(dp
->reg_base
+ EXYNOS_DP_SYS_CTL_4
);
879 writel(reg
, dp
->reg_base
+ EXYNOS_DP_SYS_CTL_4
);
883 void exynos_dp_set_training_pattern(struct exynos_dp_device
*dp
,
884 enum pattern_set pattern
)
890 reg
= SCRAMBLING_ENABLE
| LINK_QUAL_PATTERN_SET_PRBS7
;
891 writel(reg
, dp
->reg_base
+ EXYNOS_DP_TRAINING_PTN_SET
);
894 reg
= SCRAMBLING_ENABLE
| LINK_QUAL_PATTERN_SET_D10_2
;
895 writel(reg
, dp
->reg_base
+ EXYNOS_DP_TRAINING_PTN_SET
);
898 reg
= SCRAMBLING_DISABLE
| SW_TRAINING_PATTERN_SET_PTN1
;
899 writel(reg
, dp
->reg_base
+ EXYNOS_DP_TRAINING_PTN_SET
);
902 reg
= SCRAMBLING_DISABLE
| SW_TRAINING_PATTERN_SET_PTN2
;
903 writel(reg
, dp
->reg_base
+ EXYNOS_DP_TRAINING_PTN_SET
);
906 reg
= SCRAMBLING_ENABLE
|
907 LINK_QUAL_PATTERN_SET_DISABLE
|
908 SW_TRAINING_PATTERN_SET_NORMAL
;
909 writel(reg
, dp
->reg_base
+ EXYNOS_DP_TRAINING_PTN_SET
);
916 void exynos_dp_set_lane0_pre_emphasis(struct exynos_dp_device
*dp
, u32 level
)
920 reg
= readl(dp
->reg_base
+ EXYNOS_DP_LN0_LINK_TRAINING_CTL
);
921 reg
&= ~PRE_EMPHASIS_SET_MASK
;
922 reg
|= level
<< PRE_EMPHASIS_SET_SHIFT
;
923 writel(reg
, dp
->reg_base
+ EXYNOS_DP_LN0_LINK_TRAINING_CTL
);
926 void exynos_dp_set_lane1_pre_emphasis(struct exynos_dp_device
*dp
, u32 level
)
930 reg
= readl(dp
->reg_base
+ EXYNOS_DP_LN1_LINK_TRAINING_CTL
);
931 reg
&= ~PRE_EMPHASIS_SET_MASK
;
932 reg
|= level
<< PRE_EMPHASIS_SET_SHIFT
;
933 writel(reg
, dp
->reg_base
+ EXYNOS_DP_LN1_LINK_TRAINING_CTL
);
936 void exynos_dp_set_lane2_pre_emphasis(struct exynos_dp_device
*dp
, u32 level
)
940 reg
= readl(dp
->reg_base
+ EXYNOS_DP_LN2_LINK_TRAINING_CTL
);
941 reg
&= ~PRE_EMPHASIS_SET_MASK
;
942 reg
|= level
<< PRE_EMPHASIS_SET_SHIFT
;
943 writel(reg
, dp
->reg_base
+ EXYNOS_DP_LN2_LINK_TRAINING_CTL
);
946 void exynos_dp_set_lane3_pre_emphasis(struct exynos_dp_device
*dp
, u32 level
)
950 reg
= readl(dp
->reg_base
+ EXYNOS_DP_LN3_LINK_TRAINING_CTL
);
951 reg
&= ~PRE_EMPHASIS_SET_MASK
;
952 reg
|= level
<< PRE_EMPHASIS_SET_SHIFT
;
953 writel(reg
, dp
->reg_base
+ EXYNOS_DP_LN3_LINK_TRAINING_CTL
);
956 void exynos_dp_set_lane0_link_training(struct exynos_dp_device
*dp
,
962 writel(reg
, dp
->reg_base
+ EXYNOS_DP_LN0_LINK_TRAINING_CTL
);
965 void exynos_dp_set_lane1_link_training(struct exynos_dp_device
*dp
,
971 writel(reg
, dp
->reg_base
+ EXYNOS_DP_LN1_LINK_TRAINING_CTL
);
974 void exynos_dp_set_lane2_link_training(struct exynos_dp_device
*dp
,
980 writel(reg
, dp
->reg_base
+ EXYNOS_DP_LN2_LINK_TRAINING_CTL
);
983 void exynos_dp_set_lane3_link_training(struct exynos_dp_device
*dp
,
989 writel(reg
, dp
->reg_base
+ EXYNOS_DP_LN3_LINK_TRAINING_CTL
);
992 u32
exynos_dp_get_lane0_link_training(struct exynos_dp_device
*dp
)
996 reg
= readl(dp
->reg_base
+ EXYNOS_DP_LN0_LINK_TRAINING_CTL
);
1000 u32
exynos_dp_get_lane1_link_training(struct exynos_dp_device
*dp
)
1004 reg
= readl(dp
->reg_base
+ EXYNOS_DP_LN1_LINK_TRAINING_CTL
);
1008 u32
exynos_dp_get_lane2_link_training(struct exynos_dp_device
*dp
)
1012 reg
= readl(dp
->reg_base
+ EXYNOS_DP_LN2_LINK_TRAINING_CTL
);
1016 u32
exynos_dp_get_lane3_link_training(struct exynos_dp_device
*dp
)
1020 reg
= readl(dp
->reg_base
+ EXYNOS_DP_LN3_LINK_TRAINING_CTL
);
1024 void exynos_dp_reset_macro(struct exynos_dp_device
*dp
)
1028 reg
= readl(dp
->reg_base
+ EXYNOS_DP_PHY_TEST
);
1030 writel(reg
, dp
->reg_base
+ EXYNOS_DP_PHY_TEST
);
1032 /* 10 us is the minimum reset time. */
1033 usleep_range(10, 20);
1036 writel(reg
, dp
->reg_base
+ EXYNOS_DP_PHY_TEST
);
1039 void exynos_dp_init_video(struct exynos_dp_device
*dp
)
1043 reg
= VSYNC_DET
| VID_FORMAT_CHG
| VID_CLK_CHG
;
1044 writel(reg
, dp
->reg_base
+ EXYNOS_DP_COMMON_INT_STA_1
);
1047 writel(reg
, dp
->reg_base
+ EXYNOS_DP_SYS_CTL_1
);
1049 reg
= CHA_CRI(4) | CHA_CTRL
;
1050 writel(reg
, dp
->reg_base
+ EXYNOS_DP_SYS_CTL_2
);
1053 writel(reg
, dp
->reg_base
+ EXYNOS_DP_SYS_CTL_3
);
1055 reg
= VID_HRES_TH(2) | VID_VRES_TH(0);
1056 writel(reg
, dp
->reg_base
+ EXYNOS_DP_VIDEO_CTL_8
);
1059 void exynos_dp_set_video_color_format(struct exynos_dp_device
*dp
)
1063 /* Configure the input color depth, color space, dynamic range */
1064 reg
= (dp
->video_info
->dynamic_range
<< IN_D_RANGE_SHIFT
) |
1065 (dp
->video_info
->color_depth
<< IN_BPC_SHIFT
) |
1066 (dp
->video_info
->color_space
<< IN_COLOR_F_SHIFT
);
1067 writel(reg
, dp
->reg_base
+ EXYNOS_DP_VIDEO_CTL_2
);
1069 /* Set Input Color YCbCr Coefficients to ITU601 or ITU709 */
1070 reg
= readl(dp
->reg_base
+ EXYNOS_DP_VIDEO_CTL_3
);
1071 reg
&= ~IN_YC_COEFFI_MASK
;
1072 if (dp
->video_info
->ycbcr_coeff
)
1073 reg
|= IN_YC_COEFFI_ITU709
;
1075 reg
|= IN_YC_COEFFI_ITU601
;
1076 writel(reg
, dp
->reg_base
+ EXYNOS_DP_VIDEO_CTL_3
);
1079 int exynos_dp_is_slave_video_stream_clock_on(struct exynos_dp_device
*dp
)
1083 reg
= readl(dp
->reg_base
+ EXYNOS_DP_SYS_CTL_1
);
1084 writel(reg
, dp
->reg_base
+ EXYNOS_DP_SYS_CTL_1
);
1086 reg
= readl(dp
->reg_base
+ EXYNOS_DP_SYS_CTL_1
);
1088 if (!(reg
& DET_STA
)) {
1089 dev_dbg(dp
->dev
, "Input stream clock not detected.\n");
1093 reg
= readl(dp
->reg_base
+ EXYNOS_DP_SYS_CTL_2
);
1094 writel(reg
, dp
->reg_base
+ EXYNOS_DP_SYS_CTL_2
);
1096 reg
= readl(dp
->reg_base
+ EXYNOS_DP_SYS_CTL_2
);
1097 dev_dbg(dp
->dev
, "wait SYS_CTL_2.\n");
1099 if (reg
& CHA_STA
) {
1100 dev_dbg(dp
->dev
, "Input stream clk is changing\n");
1107 void exynos_dp_set_video_cr_mn(struct exynos_dp_device
*dp
,
1108 enum clock_recovery_m_value_type type
,
1114 if (type
== REGISTER_M
) {
1115 reg
= readl(dp
->reg_base
+ EXYNOS_DP_SYS_CTL_4
);
1117 writel(reg
, dp
->reg_base
+ EXYNOS_DP_SYS_CTL_4
);
1118 reg
= m_value
& 0xff;
1119 writel(reg
, dp
->reg_base
+ EXYNOS_DP_M_VID_0
);
1120 reg
= (m_value
>> 8) & 0xff;
1121 writel(reg
, dp
->reg_base
+ EXYNOS_DP_M_VID_1
);
1122 reg
= (m_value
>> 16) & 0xff;
1123 writel(reg
, dp
->reg_base
+ EXYNOS_DP_M_VID_2
);
1125 reg
= n_value
& 0xff;
1126 writel(reg
, dp
->reg_base
+ EXYNOS_DP_N_VID_0
);
1127 reg
= (n_value
>> 8) & 0xff;
1128 writel(reg
, dp
->reg_base
+ EXYNOS_DP_N_VID_1
);
1129 reg
= (n_value
>> 16) & 0xff;
1130 writel(reg
, dp
->reg_base
+ EXYNOS_DP_N_VID_2
);
1132 reg
= readl(dp
->reg_base
+ EXYNOS_DP_SYS_CTL_4
);
1134 writel(reg
, dp
->reg_base
+ EXYNOS_DP_SYS_CTL_4
);
1136 writel(0x00, dp
->reg_base
+ EXYNOS_DP_N_VID_0
);
1137 writel(0x80, dp
->reg_base
+ EXYNOS_DP_N_VID_1
);
1138 writel(0x00, dp
->reg_base
+ EXYNOS_DP_N_VID_2
);
1142 void exynos_dp_set_video_timing_mode(struct exynos_dp_device
*dp
, u32 type
)
1146 if (type
== VIDEO_TIMING_FROM_CAPTURE
) {
1147 reg
= readl(dp
->reg_base
+ EXYNOS_DP_VIDEO_CTL_10
);
1149 writel(reg
, dp
->reg_base
+ EXYNOS_DP_VIDEO_CTL_10
);
1151 reg
= readl(dp
->reg_base
+ EXYNOS_DP_VIDEO_CTL_10
);
1153 writel(reg
, dp
->reg_base
+ EXYNOS_DP_VIDEO_CTL_10
);
1157 void exynos_dp_enable_video_master(struct exynos_dp_device
*dp
, bool enable
)
1162 reg
= readl(dp
->reg_base
+ EXYNOS_DP_SOC_GENERAL_CTL
);
1163 reg
&= ~VIDEO_MODE_MASK
;
1164 reg
|= VIDEO_MASTER_MODE_EN
| VIDEO_MODE_MASTER_MODE
;
1165 writel(reg
, dp
->reg_base
+ EXYNOS_DP_SOC_GENERAL_CTL
);
1167 reg
= readl(dp
->reg_base
+ EXYNOS_DP_SOC_GENERAL_CTL
);
1168 reg
&= ~VIDEO_MODE_MASK
;
1169 reg
|= VIDEO_MODE_SLAVE_MODE
;
1170 writel(reg
, dp
->reg_base
+ EXYNOS_DP_SOC_GENERAL_CTL
);
1174 void exynos_dp_start_video(struct exynos_dp_device
*dp
)
1178 reg
= readl(dp
->reg_base
+ EXYNOS_DP_VIDEO_CTL_1
);
1180 writel(reg
, dp
->reg_base
+ EXYNOS_DP_VIDEO_CTL_1
);
1183 int exynos_dp_is_video_stream_on(struct exynos_dp_device
*dp
)
1187 reg
= readl(dp
->reg_base
+ EXYNOS_DP_SYS_CTL_3
);
1188 writel(reg
, dp
->reg_base
+ EXYNOS_DP_SYS_CTL_3
);
1190 reg
= readl(dp
->reg_base
+ EXYNOS_DP_SYS_CTL_3
);
1191 if (!(reg
& STRM_VALID
)) {
1192 dev_dbg(dp
->dev
, "Input video stream is not detected.\n");
1199 void exynos_dp_config_video_slave_mode(struct exynos_dp_device
*dp
)
1203 reg
= readl(dp
->reg_base
+ EXYNOS_DP_FUNC_EN_1
);
1204 reg
&= ~(MASTER_VID_FUNC_EN_N
|SLAVE_VID_FUNC_EN_N
);
1205 reg
|= MASTER_VID_FUNC_EN_N
;
1206 writel(reg
, dp
->reg_base
+ EXYNOS_DP_FUNC_EN_1
);
1208 reg
= readl(dp
->reg_base
+ EXYNOS_DP_VIDEO_CTL_10
);
1209 reg
&= ~INTERACE_SCAN_CFG
;
1210 reg
|= (dp
->video_info
->interlaced
<< 2);
1211 writel(reg
, dp
->reg_base
+ EXYNOS_DP_VIDEO_CTL_10
);
1213 reg
= readl(dp
->reg_base
+ EXYNOS_DP_VIDEO_CTL_10
);
1214 reg
&= ~VSYNC_POLARITY_CFG
;
1215 reg
|= (dp
->video_info
->v_sync_polarity
<< 1);
1216 writel(reg
, dp
->reg_base
+ EXYNOS_DP_VIDEO_CTL_10
);
1218 reg
= readl(dp
->reg_base
+ EXYNOS_DP_VIDEO_CTL_10
);
1219 reg
&= ~HSYNC_POLARITY_CFG
;
1220 reg
|= (dp
->video_info
->h_sync_polarity
<< 0);
1221 writel(reg
, dp
->reg_base
+ EXYNOS_DP_VIDEO_CTL_10
);
1223 reg
= AUDIO_MODE_SPDIF_MODE
| VIDEO_MODE_SLAVE_MODE
;
1224 writel(reg
, dp
->reg_base
+ EXYNOS_DP_SOC_GENERAL_CTL
);
1227 void exynos_dp_enable_scrambling(struct exynos_dp_device
*dp
)
1231 reg
= readl(dp
->reg_base
+ EXYNOS_DP_TRAINING_PTN_SET
);
1232 reg
&= ~SCRAMBLING_DISABLE
;
1233 writel(reg
, dp
->reg_base
+ EXYNOS_DP_TRAINING_PTN_SET
);
1236 void exynos_dp_disable_scrambling(struct exynos_dp_device
*dp
)
1240 reg
= readl(dp
->reg_base
+ EXYNOS_DP_TRAINING_PTN_SET
);
1241 reg
|= SCRAMBLING_DISABLE
;
1242 writel(reg
, dp
->reg_base
+ EXYNOS_DP_TRAINING_PTN_SET
);