2 * Analogix DP (Display port) core 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 <drm/bridge/analogix_dp.h>
20 #include "analogix_dp_core.h"
21 #include "analogix_dp_reg.h"
23 #define COMMON_INT_MASK_1 0
24 #define COMMON_INT_MASK_2 0
25 #define COMMON_INT_MASK_3 0
26 #define COMMON_INT_MASK_4 (HOTPLUG_CHG | HPD_LOST | PLUG)
27 #define INT_STA_MASK INT_HPD
29 void analogix_dp_enable_video_mute(struct analogix_dp_device
*dp
, bool enable
)
34 reg
= readl(dp
->reg_base
+ ANALOGIX_DP_VIDEO_CTL_1
);
35 reg
|= HDCP_VIDEO_MUTE
;
36 writel(reg
, dp
->reg_base
+ ANALOGIX_DP_VIDEO_CTL_1
);
38 reg
= readl(dp
->reg_base
+ ANALOGIX_DP_VIDEO_CTL_1
);
39 reg
&= ~HDCP_VIDEO_MUTE
;
40 writel(reg
, dp
->reg_base
+ ANALOGIX_DP_VIDEO_CTL_1
);
44 void analogix_dp_stop_video(struct analogix_dp_device
*dp
)
48 reg
= readl(dp
->reg_base
+ ANALOGIX_DP_VIDEO_CTL_1
);
50 writel(reg
, dp
->reg_base
+ ANALOGIX_DP_VIDEO_CTL_1
);
53 void analogix_dp_lane_swap(struct analogix_dp_device
*dp
, bool enable
)
58 reg
= LANE3_MAP_LOGIC_LANE_0
| LANE2_MAP_LOGIC_LANE_1
|
59 LANE1_MAP_LOGIC_LANE_2
| LANE0_MAP_LOGIC_LANE_3
;
61 reg
= LANE3_MAP_LOGIC_LANE_3
| LANE2_MAP_LOGIC_LANE_2
|
62 LANE1_MAP_LOGIC_LANE_1
| LANE0_MAP_LOGIC_LANE_0
;
64 writel(reg
, dp
->reg_base
+ ANALOGIX_DP_LANE_MAP
);
67 void analogix_dp_init_analog_param(struct analogix_dp_device
*dp
)
71 reg
= TX_TERMINAL_CTRL_50_OHM
;
72 writel(reg
, dp
->reg_base
+ ANALOGIX_DP_ANALOG_CTL_1
);
74 reg
= SEL_24M
| TX_DVDD_BIT_1_0625V
;
75 writel(reg
, dp
->reg_base
+ ANALOGIX_DP_ANALOG_CTL_2
);
77 if (dp
->plat_data
&& is_rockchip(dp
->plat_data
->dev_type
)) {
79 if (dp
->plat_data
->dev_type
== RK3288_DP
)
82 writel(reg
, dp
->reg_base
+ ANALOGIX_DP_PLL_REG_1
);
83 writel(0x95, dp
->reg_base
+ ANALOGIX_DP_PLL_REG_2
);
84 writel(0x40, dp
->reg_base
+ ANALOGIX_DP_PLL_REG_3
);
85 writel(0x58, dp
->reg_base
+ ANALOGIX_DP_PLL_REG_4
);
86 writel(0x22, dp
->reg_base
+ ANALOGIX_DP_PLL_REG_5
);
89 reg
= DRIVE_DVDD_BIT_1_0625V
| VCO_BIT_600_MICRO
;
90 writel(reg
, dp
->reg_base
+ ANALOGIX_DP_ANALOG_CTL_3
);
92 reg
= PD_RING_OSC
| AUX_TERMINAL_CTRL_50_OHM
|
93 TX_CUR1_2X
| TX_CUR_16_MA
;
94 writel(reg
, dp
->reg_base
+ ANALOGIX_DP_PLL_FILTER_CTL_1
);
96 reg
= CH3_AMP_400_MV
| CH2_AMP_400_MV
|
97 CH1_AMP_400_MV
| CH0_AMP_400_MV
;
98 writel(reg
, dp
->reg_base
+ ANALOGIX_DP_TX_AMP_TUNING_CTL
);
101 void analogix_dp_init_interrupt(struct analogix_dp_device
*dp
)
103 /* Set interrupt pin assertion polarity as high */
104 writel(INT_POL1
| INT_POL0
, dp
->reg_base
+ ANALOGIX_DP_INT_CTL
);
106 /* Clear pending regisers */
107 writel(0xff, dp
->reg_base
+ ANALOGIX_DP_COMMON_INT_STA_1
);
108 writel(0x4f, dp
->reg_base
+ ANALOGIX_DP_COMMON_INT_STA_2
);
109 writel(0xe0, dp
->reg_base
+ ANALOGIX_DP_COMMON_INT_STA_3
);
110 writel(0xe7, dp
->reg_base
+ ANALOGIX_DP_COMMON_INT_STA_4
);
111 writel(0x63, dp
->reg_base
+ ANALOGIX_DP_INT_STA
);
113 /* 0:mask,1: unmask */
114 writel(0x00, dp
->reg_base
+ ANALOGIX_DP_COMMON_INT_MASK_1
);
115 writel(0x00, dp
->reg_base
+ ANALOGIX_DP_COMMON_INT_MASK_2
);
116 writel(0x00, dp
->reg_base
+ ANALOGIX_DP_COMMON_INT_MASK_3
);
117 writel(0x00, dp
->reg_base
+ ANALOGIX_DP_COMMON_INT_MASK_4
);
118 writel(0x00, dp
->reg_base
+ ANALOGIX_DP_INT_STA_MASK
);
121 void analogix_dp_reset(struct analogix_dp_device
*dp
)
125 analogix_dp_stop_video(dp
);
126 analogix_dp_enable_video_mute(dp
, 0);
128 reg
= MASTER_VID_FUNC_EN_N
| SLAVE_VID_FUNC_EN_N
|
129 AUD_FIFO_FUNC_EN_N
| AUD_FUNC_EN_N
|
130 HDCP_FUNC_EN_N
| SW_FUNC_EN_N
;
131 writel(reg
, dp
->reg_base
+ ANALOGIX_DP_FUNC_EN_1
);
133 reg
= SSC_FUNC_EN_N
| AUX_FUNC_EN_N
|
134 SERDES_FIFO_FUNC_EN_N
|
135 LS_CLK_DOMAIN_FUNC_EN_N
;
136 writel(reg
, dp
->reg_base
+ ANALOGIX_DP_FUNC_EN_2
);
138 usleep_range(20, 30);
140 analogix_dp_lane_swap(dp
, 0);
142 writel(0x0, dp
->reg_base
+ ANALOGIX_DP_SYS_CTL_1
);
143 writel(0x40, dp
->reg_base
+ ANALOGIX_DP_SYS_CTL_2
);
144 writel(0x0, dp
->reg_base
+ ANALOGIX_DP_SYS_CTL_3
);
145 writel(0x0, dp
->reg_base
+ ANALOGIX_DP_SYS_CTL_4
);
147 writel(0x0, dp
->reg_base
+ ANALOGIX_DP_PKT_SEND_CTL
);
148 writel(0x0, dp
->reg_base
+ ANALOGIX_DP_HDCP_CTL
);
150 writel(0x5e, dp
->reg_base
+ ANALOGIX_DP_HPD_DEGLITCH_L
);
151 writel(0x1a, dp
->reg_base
+ ANALOGIX_DP_HPD_DEGLITCH_H
);
153 writel(0x10, dp
->reg_base
+ ANALOGIX_DP_LINK_DEBUG_CTL
);
155 writel(0x0, dp
->reg_base
+ ANALOGIX_DP_PHY_TEST
);
157 writel(0x0, dp
->reg_base
+ ANALOGIX_DP_VIDEO_FIFO_THRD
);
158 writel(0x20, dp
->reg_base
+ ANALOGIX_DP_AUDIO_MARGIN
);
160 writel(0x4, dp
->reg_base
+ ANALOGIX_DP_M_VID_GEN_FILTER_TH
);
161 writel(0x2, dp
->reg_base
+ ANALOGIX_DP_M_AUD_GEN_FILTER_TH
);
163 writel(0x00000101, dp
->reg_base
+ ANALOGIX_DP_SOC_GENERAL_CTL
);
166 void analogix_dp_swreset(struct analogix_dp_device
*dp
)
168 writel(RESET_DP_TX
, dp
->reg_base
+ ANALOGIX_DP_TX_SW_RESET
);
171 void analogix_dp_config_interrupt(struct analogix_dp_device
*dp
)
175 /* 0: mask, 1: unmask */
176 reg
= COMMON_INT_MASK_1
;
177 writel(reg
, dp
->reg_base
+ ANALOGIX_DP_COMMON_INT_MASK_1
);
179 reg
= COMMON_INT_MASK_2
;
180 writel(reg
, dp
->reg_base
+ ANALOGIX_DP_COMMON_INT_MASK_2
);
182 reg
= COMMON_INT_MASK_3
;
183 writel(reg
, dp
->reg_base
+ ANALOGIX_DP_COMMON_INT_MASK_3
);
185 reg
= COMMON_INT_MASK_4
;
186 writel(reg
, dp
->reg_base
+ ANALOGIX_DP_COMMON_INT_MASK_4
);
189 writel(reg
, dp
->reg_base
+ ANALOGIX_DP_INT_STA_MASK
);
192 void analogix_dp_mute_hpd_interrupt(struct analogix_dp_device
*dp
)
196 /* 0: mask, 1: unmask */
197 reg
= readl(dp
->reg_base
+ ANALOGIX_DP_COMMON_INT_MASK_4
);
198 reg
&= ~COMMON_INT_MASK_4
;
199 writel(reg
, dp
->reg_base
+ ANALOGIX_DP_COMMON_INT_MASK_4
);
201 reg
= readl(dp
->reg_base
+ ANALOGIX_DP_INT_STA_MASK
);
202 reg
&= ~INT_STA_MASK
;
203 writel(reg
, dp
->reg_base
+ ANALOGIX_DP_INT_STA_MASK
);
206 void analogix_dp_unmute_hpd_interrupt(struct analogix_dp_device
*dp
)
210 /* 0: mask, 1: unmask */
211 reg
= COMMON_INT_MASK_4
;
212 writel(reg
, dp
->reg_base
+ ANALOGIX_DP_COMMON_INT_MASK_4
);
215 writel(reg
, dp
->reg_base
+ ANALOGIX_DP_INT_STA_MASK
);
218 enum pll_status
analogix_dp_get_pll_lock_status(struct analogix_dp_device
*dp
)
222 reg
= readl(dp
->reg_base
+ ANALOGIX_DP_DEBUG_CTL
);
229 void analogix_dp_set_pll_power_down(struct analogix_dp_device
*dp
, bool enable
)
234 reg
= readl(dp
->reg_base
+ ANALOGIX_DP_PLL_CTL
);
236 writel(reg
, dp
->reg_base
+ ANALOGIX_DP_PLL_CTL
);
238 reg
= readl(dp
->reg_base
+ ANALOGIX_DP_PLL_CTL
);
240 writel(reg
, dp
->reg_base
+ ANALOGIX_DP_PLL_CTL
);
244 void analogix_dp_set_analog_power_down(struct analogix_dp_device
*dp
,
245 enum analog_power_block block
,
249 u32 phy_pd_addr
= ANALOGIX_DP_PHY_PD
;
251 if (dp
->plat_data
&& is_rockchip(dp
->plat_data
->dev_type
))
252 phy_pd_addr
= ANALOGIX_DP_PD
;
257 reg
= readl(dp
->reg_base
+ phy_pd_addr
);
259 writel(reg
, dp
->reg_base
+ phy_pd_addr
);
261 reg
= readl(dp
->reg_base
+ phy_pd_addr
);
263 writel(reg
, dp
->reg_base
+ phy_pd_addr
);
268 reg
= readl(dp
->reg_base
+ phy_pd_addr
);
270 writel(reg
, dp
->reg_base
+ phy_pd_addr
);
272 reg
= readl(dp
->reg_base
+ phy_pd_addr
);
274 writel(reg
, dp
->reg_base
+ phy_pd_addr
);
279 reg
= readl(dp
->reg_base
+ phy_pd_addr
);
281 writel(reg
, dp
->reg_base
+ phy_pd_addr
);
283 reg
= readl(dp
->reg_base
+ phy_pd_addr
);
285 writel(reg
, dp
->reg_base
+ phy_pd_addr
);
290 reg
= readl(dp
->reg_base
+ phy_pd_addr
);
292 writel(reg
, dp
->reg_base
+ phy_pd_addr
);
294 reg
= readl(dp
->reg_base
+ phy_pd_addr
);
296 writel(reg
, dp
->reg_base
+ phy_pd_addr
);
301 reg
= readl(dp
->reg_base
+ phy_pd_addr
);
303 writel(reg
, dp
->reg_base
+ phy_pd_addr
);
305 reg
= readl(dp
->reg_base
+ phy_pd_addr
);
307 writel(reg
, dp
->reg_base
+ phy_pd_addr
);
312 reg
= readl(dp
->reg_base
+ phy_pd_addr
);
314 writel(reg
, dp
->reg_base
+ phy_pd_addr
);
316 reg
= readl(dp
->reg_base
+ phy_pd_addr
);
318 writel(reg
, dp
->reg_base
+ phy_pd_addr
);
323 reg
= DP_PHY_PD
| AUX_PD
| CH3_PD
| CH2_PD
|
325 writel(reg
, dp
->reg_base
+ phy_pd_addr
);
327 writel(0x00, dp
->reg_base
+ phy_pd_addr
);
335 void analogix_dp_init_analog_func(struct analogix_dp_device
*dp
)
338 int timeout_loop
= 0;
340 analogix_dp_set_analog_power_down(dp
, POWER_ALL
, 0);
343 writel(reg
, dp
->reg_base
+ ANALOGIX_DP_COMMON_INT_STA_1
);
345 reg
= readl(dp
->reg_base
+ ANALOGIX_DP_DEBUG_CTL
);
346 reg
&= ~(F_PLL_LOCK
| PLL_LOCK_CTRL
);
347 writel(reg
, dp
->reg_base
+ ANALOGIX_DP_DEBUG_CTL
);
350 if (analogix_dp_get_pll_lock_status(dp
) == PLL_UNLOCKED
) {
351 analogix_dp_set_pll_power_down(dp
, 0);
353 while (analogix_dp_get_pll_lock_status(dp
) == PLL_UNLOCKED
) {
355 if (DP_TIMEOUT_LOOP_COUNT
< timeout_loop
) {
356 dev_err(dp
->dev
, "failed to get pll lock status\n");
359 usleep_range(10, 20);
363 /* Enable Serdes FIFO function and Link symbol clock domain module */
364 reg
= readl(dp
->reg_base
+ ANALOGIX_DP_FUNC_EN_2
);
365 reg
&= ~(SERDES_FIFO_FUNC_EN_N
| LS_CLK_DOMAIN_FUNC_EN_N
367 writel(reg
, dp
->reg_base
+ ANALOGIX_DP_FUNC_EN_2
);
370 void analogix_dp_clear_hotplug_interrupts(struct analogix_dp_device
*dp
)
374 if (gpio_is_valid(dp
->hpd_gpio
))
377 reg
= HOTPLUG_CHG
| HPD_LOST
| PLUG
;
378 writel(reg
, dp
->reg_base
+ ANALOGIX_DP_COMMON_INT_STA_4
);
381 writel(reg
, dp
->reg_base
+ ANALOGIX_DP_INT_STA
);
384 void analogix_dp_init_hpd(struct analogix_dp_device
*dp
)
388 if (gpio_is_valid(dp
->hpd_gpio
))
391 analogix_dp_clear_hotplug_interrupts(dp
);
393 reg
= readl(dp
->reg_base
+ ANALOGIX_DP_SYS_CTL_3
);
394 reg
&= ~(F_HPD
| HPD_CTRL
);
395 writel(reg
, dp
->reg_base
+ ANALOGIX_DP_SYS_CTL_3
);
398 void analogix_dp_force_hpd(struct analogix_dp_device
*dp
)
402 reg
= readl(dp
->reg_base
+ ANALOGIX_DP_SYS_CTL_3
);
403 reg
= (F_HPD
| HPD_CTRL
);
404 writel(reg
, dp
->reg_base
+ ANALOGIX_DP_SYS_CTL_3
);
407 enum dp_irq_type
analogix_dp_get_irq_type(struct analogix_dp_device
*dp
)
411 if (gpio_is_valid(dp
->hpd_gpio
)) {
412 reg
= gpio_get_value(dp
->hpd_gpio
);
414 return DP_IRQ_TYPE_HP_CABLE_IN
;
416 return DP_IRQ_TYPE_HP_CABLE_OUT
;
418 /* Parse hotplug interrupt status register */
419 reg
= readl(dp
->reg_base
+ ANALOGIX_DP_COMMON_INT_STA_4
);
422 return DP_IRQ_TYPE_HP_CABLE_IN
;
425 return DP_IRQ_TYPE_HP_CABLE_OUT
;
427 if (reg
& HOTPLUG_CHG
)
428 return DP_IRQ_TYPE_HP_CHANGE
;
430 return DP_IRQ_TYPE_UNKNOWN
;
434 void analogix_dp_reset_aux(struct analogix_dp_device
*dp
)
438 /* Disable AUX channel module */
439 reg
= readl(dp
->reg_base
+ ANALOGIX_DP_FUNC_EN_2
);
440 reg
|= AUX_FUNC_EN_N
;
441 writel(reg
, dp
->reg_base
+ ANALOGIX_DP_FUNC_EN_2
);
444 void analogix_dp_init_aux(struct analogix_dp_device
*dp
)
448 /* Clear inerrupts related to AUX channel */
449 reg
= RPLY_RECEIV
| AUX_ERR
;
450 writel(reg
, dp
->reg_base
+ ANALOGIX_DP_INT_STA
);
452 analogix_dp_reset_aux(dp
);
454 /* Disable AUX transaction H/W retry */
455 if (dp
->plat_data
&& is_rockchip(dp
->plat_data
->dev_type
))
456 reg
= AUX_BIT_PERIOD_EXPECTED_DELAY(0) |
457 AUX_HW_RETRY_COUNT_SEL(3) |
458 AUX_HW_RETRY_INTERVAL_600_MICROSECONDS
;
460 reg
= AUX_BIT_PERIOD_EXPECTED_DELAY(3) |
461 AUX_HW_RETRY_COUNT_SEL(0) |
462 AUX_HW_RETRY_INTERVAL_600_MICROSECONDS
;
463 writel(reg
, dp
->reg_base
+ ANALOGIX_DP_AUX_HW_RETRY_CTL
);
465 /* Receive AUX Channel DEFER commands equal to DEFFER_COUNT*64 */
466 reg
= DEFER_CTRL_EN
| DEFER_COUNT(1);
467 writel(reg
, dp
->reg_base
+ ANALOGIX_DP_AUX_CH_DEFER_CTL
);
469 /* Enable AUX channel module */
470 reg
= readl(dp
->reg_base
+ ANALOGIX_DP_FUNC_EN_2
);
471 reg
&= ~AUX_FUNC_EN_N
;
472 writel(reg
, dp
->reg_base
+ ANALOGIX_DP_FUNC_EN_2
);
475 int analogix_dp_get_plug_in_status(struct analogix_dp_device
*dp
)
479 if (gpio_is_valid(dp
->hpd_gpio
)) {
480 if (gpio_get_value(dp
->hpd_gpio
))
483 reg
= readl(dp
->reg_base
+ ANALOGIX_DP_SYS_CTL_3
);
484 if (reg
& HPD_STATUS
)
491 void analogix_dp_enable_sw_function(struct analogix_dp_device
*dp
)
495 reg
= readl(dp
->reg_base
+ ANALOGIX_DP_FUNC_EN_1
);
496 reg
&= ~SW_FUNC_EN_N
;
497 writel(reg
, dp
->reg_base
+ ANALOGIX_DP_FUNC_EN_1
);
500 int analogix_dp_start_aux_transaction(struct analogix_dp_device
*dp
)
504 int timeout_loop
= 0;
506 /* Enable AUX CH operation */
507 reg
= readl(dp
->reg_base
+ ANALOGIX_DP_AUX_CH_CTL_2
);
509 writel(reg
, dp
->reg_base
+ ANALOGIX_DP_AUX_CH_CTL_2
);
511 /* Is AUX CH command reply received? */
512 reg
= readl(dp
->reg_base
+ ANALOGIX_DP_INT_STA
);
513 while (!(reg
& RPLY_RECEIV
)) {
515 if (DP_TIMEOUT_LOOP_COUNT
< timeout_loop
) {
516 dev_err(dp
->dev
, "AUX CH command reply failed!\n");
519 reg
= readl(dp
->reg_base
+ ANALOGIX_DP_INT_STA
);
520 usleep_range(10, 11);
523 /* Clear interrupt source for AUX CH command reply */
524 writel(RPLY_RECEIV
, dp
->reg_base
+ ANALOGIX_DP_INT_STA
);
526 /* Clear interrupt source for AUX CH access error */
527 reg
= readl(dp
->reg_base
+ ANALOGIX_DP_INT_STA
);
529 writel(AUX_ERR
, dp
->reg_base
+ ANALOGIX_DP_INT_STA
);
533 /* Check AUX CH error access status */
534 reg
= readl(dp
->reg_base
+ ANALOGIX_DP_AUX_CH_STA
);
535 if ((reg
& AUX_STATUS_MASK
) != 0) {
536 dev_err(dp
->dev
, "AUX CH error happens: %d\n\n",
537 reg
& AUX_STATUS_MASK
);
544 int analogix_dp_write_byte_to_dpcd(struct analogix_dp_device
*dp
,
545 unsigned int reg_addr
,
552 for (i
= 0; i
< 3; i
++) {
553 /* Clear AUX CH data buffer */
555 writel(reg
, dp
->reg_base
+ ANALOGIX_DP_BUFFER_DATA_CTL
);
557 /* Select DPCD device address */
558 reg
= AUX_ADDR_7_0(reg_addr
);
559 writel(reg
, dp
->reg_base
+ ANALOGIX_DP_AUX_ADDR_7_0
);
560 reg
= AUX_ADDR_15_8(reg_addr
);
561 writel(reg
, dp
->reg_base
+ ANALOGIX_DP_AUX_ADDR_15_8
);
562 reg
= AUX_ADDR_19_16(reg_addr
);
563 writel(reg
, dp
->reg_base
+ ANALOGIX_DP_AUX_ADDR_19_16
);
565 /* Write data buffer */
566 reg
= (unsigned int)data
;
567 writel(reg
, dp
->reg_base
+ ANALOGIX_DP_BUF_DATA_0
);
570 * Set DisplayPort transaction and write 1 byte
571 * If bit 3 is 1, DisplayPort transaction.
572 * If Bit 3 is 0, I2C transaction.
574 reg
= AUX_TX_COMM_DP_TRANSACTION
| AUX_TX_COMM_WRITE
;
575 writel(reg
, dp
->reg_base
+ ANALOGIX_DP_AUX_CH_CTL_1
);
577 /* Start AUX transaction */
578 retval
= analogix_dp_start_aux_transaction(dp
);
582 dev_dbg(dp
->dev
, "%s: Aux Transaction fail!\n", __func__
);
588 void analogix_dp_set_link_bandwidth(struct analogix_dp_device
*dp
, u32 bwtype
)
593 if ((bwtype
== DP_LINK_BW_2_7
) || (bwtype
== DP_LINK_BW_1_62
))
594 writel(reg
, dp
->reg_base
+ ANALOGIX_DP_LINK_BW_SET
);
597 void analogix_dp_get_link_bandwidth(struct analogix_dp_device
*dp
, u32
*bwtype
)
601 reg
= readl(dp
->reg_base
+ ANALOGIX_DP_LINK_BW_SET
);
605 void analogix_dp_set_lane_count(struct analogix_dp_device
*dp
, u32 count
)
610 writel(reg
, dp
->reg_base
+ ANALOGIX_DP_LANE_COUNT_SET
);
613 void analogix_dp_get_lane_count(struct analogix_dp_device
*dp
, u32
*count
)
617 reg
= readl(dp
->reg_base
+ ANALOGIX_DP_LANE_COUNT_SET
);
621 void analogix_dp_enable_enhanced_mode(struct analogix_dp_device
*dp
,
627 reg
= readl(dp
->reg_base
+ ANALOGIX_DP_SYS_CTL_4
);
629 writel(reg
, dp
->reg_base
+ ANALOGIX_DP_SYS_CTL_4
);
631 reg
= readl(dp
->reg_base
+ ANALOGIX_DP_SYS_CTL_4
);
633 writel(reg
, dp
->reg_base
+ ANALOGIX_DP_SYS_CTL_4
);
637 void analogix_dp_set_training_pattern(struct analogix_dp_device
*dp
,
638 enum pattern_set pattern
)
644 reg
= SCRAMBLING_ENABLE
| LINK_QUAL_PATTERN_SET_PRBS7
;
645 writel(reg
, dp
->reg_base
+ ANALOGIX_DP_TRAINING_PTN_SET
);
648 reg
= SCRAMBLING_ENABLE
| LINK_QUAL_PATTERN_SET_D10_2
;
649 writel(reg
, dp
->reg_base
+ ANALOGIX_DP_TRAINING_PTN_SET
);
652 reg
= SCRAMBLING_DISABLE
| SW_TRAINING_PATTERN_SET_PTN1
;
653 writel(reg
, dp
->reg_base
+ ANALOGIX_DP_TRAINING_PTN_SET
);
656 reg
= SCRAMBLING_DISABLE
| SW_TRAINING_PATTERN_SET_PTN2
;
657 writel(reg
, dp
->reg_base
+ ANALOGIX_DP_TRAINING_PTN_SET
);
660 reg
= SCRAMBLING_ENABLE
|
661 LINK_QUAL_PATTERN_SET_DISABLE
|
662 SW_TRAINING_PATTERN_SET_NORMAL
;
663 writel(reg
, dp
->reg_base
+ ANALOGIX_DP_TRAINING_PTN_SET
);
670 void analogix_dp_set_lane0_pre_emphasis(struct analogix_dp_device
*dp
,
675 reg
= readl(dp
->reg_base
+ ANALOGIX_DP_LN0_LINK_TRAINING_CTL
);
676 reg
&= ~PRE_EMPHASIS_SET_MASK
;
677 reg
|= level
<< PRE_EMPHASIS_SET_SHIFT
;
678 writel(reg
, dp
->reg_base
+ ANALOGIX_DP_LN0_LINK_TRAINING_CTL
);
681 void analogix_dp_set_lane1_pre_emphasis(struct analogix_dp_device
*dp
,
686 reg
= readl(dp
->reg_base
+ ANALOGIX_DP_LN1_LINK_TRAINING_CTL
);
687 reg
&= ~PRE_EMPHASIS_SET_MASK
;
688 reg
|= level
<< PRE_EMPHASIS_SET_SHIFT
;
689 writel(reg
, dp
->reg_base
+ ANALOGIX_DP_LN1_LINK_TRAINING_CTL
);
692 void analogix_dp_set_lane2_pre_emphasis(struct analogix_dp_device
*dp
,
697 reg
= readl(dp
->reg_base
+ ANALOGIX_DP_LN2_LINK_TRAINING_CTL
);
698 reg
&= ~PRE_EMPHASIS_SET_MASK
;
699 reg
|= level
<< PRE_EMPHASIS_SET_SHIFT
;
700 writel(reg
, dp
->reg_base
+ ANALOGIX_DP_LN2_LINK_TRAINING_CTL
);
703 void analogix_dp_set_lane3_pre_emphasis(struct analogix_dp_device
*dp
,
708 reg
= readl(dp
->reg_base
+ ANALOGIX_DP_LN3_LINK_TRAINING_CTL
);
709 reg
&= ~PRE_EMPHASIS_SET_MASK
;
710 reg
|= level
<< PRE_EMPHASIS_SET_SHIFT
;
711 writel(reg
, dp
->reg_base
+ ANALOGIX_DP_LN3_LINK_TRAINING_CTL
);
714 void analogix_dp_set_lane0_link_training(struct analogix_dp_device
*dp
,
720 writel(reg
, dp
->reg_base
+ ANALOGIX_DP_LN0_LINK_TRAINING_CTL
);
723 void analogix_dp_set_lane1_link_training(struct analogix_dp_device
*dp
,
729 writel(reg
, dp
->reg_base
+ ANALOGIX_DP_LN1_LINK_TRAINING_CTL
);
732 void analogix_dp_set_lane2_link_training(struct analogix_dp_device
*dp
,
738 writel(reg
, dp
->reg_base
+ ANALOGIX_DP_LN2_LINK_TRAINING_CTL
);
741 void analogix_dp_set_lane3_link_training(struct analogix_dp_device
*dp
,
747 writel(reg
, dp
->reg_base
+ ANALOGIX_DP_LN3_LINK_TRAINING_CTL
);
750 u32
analogix_dp_get_lane0_link_training(struct analogix_dp_device
*dp
)
752 return readl(dp
->reg_base
+ ANALOGIX_DP_LN0_LINK_TRAINING_CTL
);
755 u32
analogix_dp_get_lane1_link_training(struct analogix_dp_device
*dp
)
757 return readl(dp
->reg_base
+ ANALOGIX_DP_LN1_LINK_TRAINING_CTL
);
760 u32
analogix_dp_get_lane2_link_training(struct analogix_dp_device
*dp
)
762 return readl(dp
->reg_base
+ ANALOGIX_DP_LN2_LINK_TRAINING_CTL
);
765 u32
analogix_dp_get_lane3_link_training(struct analogix_dp_device
*dp
)
767 return readl(dp
->reg_base
+ ANALOGIX_DP_LN3_LINK_TRAINING_CTL
);
770 void analogix_dp_reset_macro(struct analogix_dp_device
*dp
)
774 reg
= readl(dp
->reg_base
+ ANALOGIX_DP_PHY_TEST
);
776 writel(reg
, dp
->reg_base
+ ANALOGIX_DP_PHY_TEST
);
778 /* 10 us is the minimum reset time. */
779 usleep_range(10, 20);
782 writel(reg
, dp
->reg_base
+ ANALOGIX_DP_PHY_TEST
);
785 void analogix_dp_init_video(struct analogix_dp_device
*dp
)
789 reg
= VSYNC_DET
| VID_FORMAT_CHG
| VID_CLK_CHG
;
790 writel(reg
, dp
->reg_base
+ ANALOGIX_DP_COMMON_INT_STA_1
);
793 writel(reg
, dp
->reg_base
+ ANALOGIX_DP_SYS_CTL_1
);
795 reg
= CHA_CRI(4) | CHA_CTRL
;
796 writel(reg
, dp
->reg_base
+ ANALOGIX_DP_SYS_CTL_2
);
799 writel(reg
, dp
->reg_base
+ ANALOGIX_DP_SYS_CTL_3
);
801 reg
= VID_HRES_TH(2) | VID_VRES_TH(0);
802 writel(reg
, dp
->reg_base
+ ANALOGIX_DP_VIDEO_CTL_8
);
805 void analogix_dp_set_video_color_format(struct analogix_dp_device
*dp
)
809 /* Configure the input color depth, color space, dynamic range */
810 reg
= (dp
->video_info
.dynamic_range
<< IN_D_RANGE_SHIFT
) |
811 (dp
->video_info
.color_depth
<< IN_BPC_SHIFT
) |
812 (dp
->video_info
.color_space
<< IN_COLOR_F_SHIFT
);
813 writel(reg
, dp
->reg_base
+ ANALOGIX_DP_VIDEO_CTL_2
);
815 /* Set Input Color YCbCr Coefficients to ITU601 or ITU709 */
816 reg
= readl(dp
->reg_base
+ ANALOGIX_DP_VIDEO_CTL_3
);
817 reg
&= ~IN_YC_COEFFI_MASK
;
818 if (dp
->video_info
.ycbcr_coeff
)
819 reg
|= IN_YC_COEFFI_ITU709
;
821 reg
|= IN_YC_COEFFI_ITU601
;
822 writel(reg
, dp
->reg_base
+ ANALOGIX_DP_VIDEO_CTL_3
);
825 int analogix_dp_is_slave_video_stream_clock_on(struct analogix_dp_device
*dp
)
829 reg
= readl(dp
->reg_base
+ ANALOGIX_DP_SYS_CTL_1
);
830 writel(reg
, dp
->reg_base
+ ANALOGIX_DP_SYS_CTL_1
);
832 reg
= readl(dp
->reg_base
+ ANALOGIX_DP_SYS_CTL_1
);
834 if (!(reg
& DET_STA
)) {
835 dev_dbg(dp
->dev
, "Input stream clock not detected.\n");
839 reg
= readl(dp
->reg_base
+ ANALOGIX_DP_SYS_CTL_2
);
840 writel(reg
, dp
->reg_base
+ ANALOGIX_DP_SYS_CTL_2
);
842 reg
= readl(dp
->reg_base
+ ANALOGIX_DP_SYS_CTL_2
);
843 dev_dbg(dp
->dev
, "wait SYS_CTL_2.\n");
846 dev_dbg(dp
->dev
, "Input stream clk is changing\n");
853 void analogix_dp_set_video_cr_mn(struct analogix_dp_device
*dp
,
854 enum clock_recovery_m_value_type type
,
855 u32 m_value
, u32 n_value
)
859 if (type
== REGISTER_M
) {
860 reg
= readl(dp
->reg_base
+ ANALOGIX_DP_SYS_CTL_4
);
862 writel(reg
, dp
->reg_base
+ ANALOGIX_DP_SYS_CTL_4
);
863 reg
= m_value
& 0xff;
864 writel(reg
, dp
->reg_base
+ ANALOGIX_DP_M_VID_0
);
865 reg
= (m_value
>> 8) & 0xff;
866 writel(reg
, dp
->reg_base
+ ANALOGIX_DP_M_VID_1
);
867 reg
= (m_value
>> 16) & 0xff;
868 writel(reg
, dp
->reg_base
+ ANALOGIX_DP_M_VID_2
);
870 reg
= n_value
& 0xff;
871 writel(reg
, dp
->reg_base
+ ANALOGIX_DP_N_VID_0
);
872 reg
= (n_value
>> 8) & 0xff;
873 writel(reg
, dp
->reg_base
+ ANALOGIX_DP_N_VID_1
);
874 reg
= (n_value
>> 16) & 0xff;
875 writel(reg
, dp
->reg_base
+ ANALOGIX_DP_N_VID_2
);
877 reg
= readl(dp
->reg_base
+ ANALOGIX_DP_SYS_CTL_4
);
879 writel(reg
, dp
->reg_base
+ ANALOGIX_DP_SYS_CTL_4
);
881 writel(0x00, dp
->reg_base
+ ANALOGIX_DP_N_VID_0
);
882 writel(0x80, dp
->reg_base
+ ANALOGIX_DP_N_VID_1
);
883 writel(0x00, dp
->reg_base
+ ANALOGIX_DP_N_VID_2
);
887 void analogix_dp_set_video_timing_mode(struct analogix_dp_device
*dp
, u32 type
)
891 if (type
== VIDEO_TIMING_FROM_CAPTURE
) {
892 reg
= readl(dp
->reg_base
+ ANALOGIX_DP_VIDEO_CTL_10
);
894 writel(reg
, dp
->reg_base
+ ANALOGIX_DP_VIDEO_CTL_10
);
896 reg
= readl(dp
->reg_base
+ ANALOGIX_DP_VIDEO_CTL_10
);
898 writel(reg
, dp
->reg_base
+ ANALOGIX_DP_VIDEO_CTL_10
);
902 void analogix_dp_enable_video_master(struct analogix_dp_device
*dp
, bool enable
)
907 reg
= readl(dp
->reg_base
+ ANALOGIX_DP_SOC_GENERAL_CTL
);
908 reg
&= ~VIDEO_MODE_MASK
;
909 reg
|= VIDEO_MASTER_MODE_EN
| VIDEO_MODE_MASTER_MODE
;
910 writel(reg
, dp
->reg_base
+ ANALOGIX_DP_SOC_GENERAL_CTL
);
912 reg
= readl(dp
->reg_base
+ ANALOGIX_DP_SOC_GENERAL_CTL
);
913 reg
&= ~VIDEO_MODE_MASK
;
914 reg
|= VIDEO_MODE_SLAVE_MODE
;
915 writel(reg
, dp
->reg_base
+ ANALOGIX_DP_SOC_GENERAL_CTL
);
919 void analogix_dp_start_video(struct analogix_dp_device
*dp
)
923 reg
= readl(dp
->reg_base
+ ANALOGIX_DP_VIDEO_CTL_1
);
925 writel(reg
, dp
->reg_base
+ ANALOGIX_DP_VIDEO_CTL_1
);
928 int analogix_dp_is_video_stream_on(struct analogix_dp_device
*dp
)
932 reg
= readl(dp
->reg_base
+ ANALOGIX_DP_SYS_CTL_3
);
933 writel(reg
, dp
->reg_base
+ ANALOGIX_DP_SYS_CTL_3
);
935 reg
= readl(dp
->reg_base
+ ANALOGIX_DP_SYS_CTL_3
);
936 if (!(reg
& STRM_VALID
)) {
937 dev_dbg(dp
->dev
, "Input video stream is not detected.\n");
944 void analogix_dp_config_video_slave_mode(struct analogix_dp_device
*dp
)
948 reg
= readl(dp
->reg_base
+ ANALOGIX_DP_FUNC_EN_1
);
949 reg
&= ~(MASTER_VID_FUNC_EN_N
| SLAVE_VID_FUNC_EN_N
);
950 reg
|= MASTER_VID_FUNC_EN_N
;
951 writel(reg
, dp
->reg_base
+ ANALOGIX_DP_FUNC_EN_1
);
953 reg
= readl(dp
->reg_base
+ ANALOGIX_DP_VIDEO_CTL_10
);
954 reg
&= ~INTERACE_SCAN_CFG
;
955 reg
|= (dp
->video_info
.interlaced
<< 2);
956 writel(reg
, dp
->reg_base
+ ANALOGIX_DP_VIDEO_CTL_10
);
958 reg
= readl(dp
->reg_base
+ ANALOGIX_DP_VIDEO_CTL_10
);
959 reg
&= ~VSYNC_POLARITY_CFG
;
960 reg
|= (dp
->video_info
.v_sync_polarity
<< 1);
961 writel(reg
, dp
->reg_base
+ ANALOGIX_DP_VIDEO_CTL_10
);
963 reg
= readl(dp
->reg_base
+ ANALOGIX_DP_VIDEO_CTL_10
);
964 reg
&= ~HSYNC_POLARITY_CFG
;
965 reg
|= (dp
->video_info
.h_sync_polarity
<< 0);
966 writel(reg
, dp
->reg_base
+ ANALOGIX_DP_VIDEO_CTL_10
);
968 reg
= AUDIO_MODE_SPDIF_MODE
| VIDEO_MODE_SLAVE_MODE
;
969 writel(reg
, dp
->reg_base
+ ANALOGIX_DP_SOC_GENERAL_CTL
);
972 void analogix_dp_enable_scrambling(struct analogix_dp_device
*dp
)
976 reg
= readl(dp
->reg_base
+ ANALOGIX_DP_TRAINING_PTN_SET
);
977 reg
&= ~SCRAMBLING_DISABLE
;
978 writel(reg
, dp
->reg_base
+ ANALOGIX_DP_TRAINING_PTN_SET
);
981 void analogix_dp_disable_scrambling(struct analogix_dp_device
*dp
)
985 reg
= readl(dp
->reg_base
+ ANALOGIX_DP_TRAINING_PTN_SET
);
986 reg
|= SCRAMBLING_DISABLE
;
987 writel(reg
, dp
->reg_base
+ ANALOGIX_DP_TRAINING_PTN_SET
);
990 void analogix_dp_enable_psr_crc(struct analogix_dp_device
*dp
)
992 writel(PSR_VID_CRC_ENABLE
, dp
->reg_base
+ ANALOGIX_DP_CRC_CON
);
995 void analogix_dp_send_psr_spd(struct analogix_dp_device
*dp
,
996 struct edp_vsc_psr
*vsc
)
1000 /* don't send info frame */
1001 val
= readl(dp
->reg_base
+ ANALOGIX_DP_PKT_SEND_CTL
);
1003 writel(val
, dp
->reg_base
+ ANALOGIX_DP_PKT_SEND_CTL
);
1005 /* configure single frame update mode */
1006 writel(PSR_FRAME_UP_TYPE_BURST
| PSR_CRC_SEL_HARDWARE
,
1007 dp
->reg_base
+ ANALOGIX_DP_PSR_FRAME_UPDATE_CTRL
);
1009 /* configure VSC HB0~HB3 */
1010 writel(vsc
->sdp_header
.HB0
, dp
->reg_base
+ ANALOGIX_DP_SPD_HB0
);
1011 writel(vsc
->sdp_header
.HB1
, dp
->reg_base
+ ANALOGIX_DP_SPD_HB1
);
1012 writel(vsc
->sdp_header
.HB2
, dp
->reg_base
+ ANALOGIX_DP_SPD_HB2
);
1013 writel(vsc
->sdp_header
.HB3
, dp
->reg_base
+ ANALOGIX_DP_SPD_HB3
);
1015 /* configure reused VSC PB0~PB3, magic number from vendor */
1016 writel(0x00, dp
->reg_base
+ ANALOGIX_DP_SPD_PB0
);
1017 writel(0x16, dp
->reg_base
+ ANALOGIX_DP_SPD_PB1
);
1018 writel(0xCE, dp
->reg_base
+ ANALOGIX_DP_SPD_PB2
);
1019 writel(0x5D, dp
->reg_base
+ ANALOGIX_DP_SPD_PB3
);
1021 /* configure DB0 / DB1 values */
1022 writel(vsc
->DB0
, dp
->reg_base
+ ANALOGIX_DP_VSC_SHADOW_DB0
);
1023 writel(vsc
->DB1
, dp
->reg_base
+ ANALOGIX_DP_VSC_SHADOW_DB1
);
1025 /* set reuse spd inforframe */
1026 val
= readl(dp
->reg_base
+ ANALOGIX_DP_VIDEO_CTL_3
);
1027 val
|= REUSE_SPD_EN
;
1028 writel(val
, dp
->reg_base
+ ANALOGIX_DP_VIDEO_CTL_3
);
1030 /* mark info frame update */
1031 val
= readl(dp
->reg_base
+ ANALOGIX_DP_PKT_SEND_CTL
);
1032 val
= (val
| IF_UP
) & ~IF_EN
;
1033 writel(val
, dp
->reg_base
+ ANALOGIX_DP_PKT_SEND_CTL
);
1035 /* send info frame */
1036 val
= readl(dp
->reg_base
+ ANALOGIX_DP_PKT_SEND_CTL
);
1038 writel(val
, dp
->reg_base
+ ANALOGIX_DP_PKT_SEND_CTL
);
1041 ssize_t
analogix_dp_transfer(struct analogix_dp_device
*dp
,
1042 struct drm_dp_aux_msg
*msg
)
1045 u8
*buffer
= msg
->buffer
;
1046 int timeout_loop
= 0;
1048 int num_transferred
= 0;
1050 /* Buffer size of AUX CH is 16 bytes */
1051 if (WARN_ON(msg
->size
> 16))
1054 /* Clear AUX CH data buffer */
1056 writel(reg
, dp
->reg_base
+ ANALOGIX_DP_BUFFER_DATA_CTL
);
1058 switch (msg
->request
& ~DP_AUX_I2C_MOT
) {
1059 case DP_AUX_I2C_WRITE
:
1060 reg
= AUX_TX_COMM_WRITE
| AUX_TX_COMM_I2C_TRANSACTION
;
1061 if (msg
->request
& DP_AUX_I2C_MOT
)
1062 reg
|= AUX_TX_COMM_MOT
;
1065 case DP_AUX_I2C_READ
:
1066 reg
= AUX_TX_COMM_READ
| AUX_TX_COMM_I2C_TRANSACTION
;
1067 if (msg
->request
& DP_AUX_I2C_MOT
)
1068 reg
|= AUX_TX_COMM_MOT
;
1071 case DP_AUX_NATIVE_WRITE
:
1072 reg
= AUX_TX_COMM_WRITE
| AUX_TX_COMM_DP_TRANSACTION
;
1075 case DP_AUX_NATIVE_READ
:
1076 reg
= AUX_TX_COMM_READ
| AUX_TX_COMM_DP_TRANSACTION
;
1083 reg
|= AUX_LENGTH(msg
->size
);
1084 writel(reg
, dp
->reg_base
+ ANALOGIX_DP_AUX_CH_CTL_1
);
1086 /* Select DPCD device address */
1087 reg
= AUX_ADDR_7_0(msg
->address
);
1088 writel(reg
, dp
->reg_base
+ ANALOGIX_DP_AUX_ADDR_7_0
);
1089 reg
= AUX_ADDR_15_8(msg
->address
);
1090 writel(reg
, dp
->reg_base
+ ANALOGIX_DP_AUX_ADDR_15_8
);
1091 reg
= AUX_ADDR_19_16(msg
->address
);
1092 writel(reg
, dp
->reg_base
+ ANALOGIX_DP_AUX_ADDR_19_16
);
1094 if (!(msg
->request
& DP_AUX_I2C_READ
)) {
1095 for (i
= 0; i
< msg
->size
; i
++) {
1097 writel(reg
, dp
->reg_base
+ ANALOGIX_DP_BUF_DATA_0
+
1103 /* Enable AUX CH operation */
1106 /* Zero-sized messages specify address-only transactions. */
1110 writel(reg
, dp
->reg_base
+ ANALOGIX_DP_AUX_CH_CTL_2
);
1112 /* Is AUX CH command reply received? */
1113 /* TODO: Wait for an interrupt instead of looping? */
1114 reg
= readl(dp
->reg_base
+ ANALOGIX_DP_INT_STA
);
1115 while (!(reg
& RPLY_RECEIV
)) {
1117 if (timeout_loop
> DP_TIMEOUT_LOOP_COUNT
) {
1118 dev_err(dp
->dev
, "AUX CH command reply failed!\n");
1121 reg
= readl(dp
->reg_base
+ ANALOGIX_DP_INT_STA
);
1122 usleep_range(10, 11);
1125 /* Clear interrupt source for AUX CH command reply */
1126 writel(RPLY_RECEIV
, dp
->reg_base
+ ANALOGIX_DP_INT_STA
);
1128 /* Clear interrupt source for AUX CH access error */
1129 reg
= readl(dp
->reg_base
+ ANALOGIX_DP_INT_STA
);
1130 if (reg
& AUX_ERR
) {
1131 writel(AUX_ERR
, dp
->reg_base
+ ANALOGIX_DP_INT_STA
);
1135 /* Check AUX CH error access status */
1136 reg
= readl(dp
->reg_base
+ ANALOGIX_DP_AUX_CH_STA
);
1137 if ((reg
& AUX_STATUS_MASK
)) {
1138 dev_err(dp
->dev
, "AUX CH error happened: %d\n\n",
1139 reg
& AUX_STATUS_MASK
);
1143 if (msg
->request
& DP_AUX_I2C_READ
) {
1144 for (i
= 0; i
< msg
->size
; i
++) {
1145 reg
= readl(dp
->reg_base
+ ANALOGIX_DP_BUF_DATA_0
+
1147 buffer
[i
] = (unsigned char)reg
;
1152 /* Check if Rx sends defer */
1153 reg
= readl(dp
->reg_base
+ ANALOGIX_DP_AUX_RX_COMM
);
1154 if (reg
== AUX_RX_COMM_AUX_DEFER
)
1155 msg
->reply
= DP_AUX_NATIVE_REPLY_DEFER
;
1156 else if (reg
== AUX_RX_COMM_I2C_DEFER
)
1157 msg
->reply
= DP_AUX_I2C_REPLY_DEFER
;
1158 else if ((msg
->request
& ~DP_AUX_I2C_MOT
) == DP_AUX_I2C_WRITE
||
1159 (msg
->request
& ~DP_AUX_I2C_MOT
) == DP_AUX_I2C_READ
)
1160 msg
->reply
= DP_AUX_I2C_REPLY_ACK
;
1161 else if ((msg
->request
& ~DP_AUX_I2C_MOT
) == DP_AUX_NATIVE_WRITE
||
1162 (msg
->request
& ~DP_AUX_I2C_MOT
) == DP_AUX_NATIVE_READ
)
1163 msg
->reply
= DP_AUX_NATIVE_REPLY_ACK
;
1165 return num_transferred
> 0 ? num_transferred
: -EBUSY
;