2 * This file is part of the coreboot project.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; version 2 of the License.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
15 /* Samsung DP (Display port) register interface driver. */
17 #include <device/mmio.h>
18 #include <console/console.h>
23 #include <soc/dp-core.h>
25 #include <soc/periph.h>
28 void s5p_dp_reset(struct s5p_dp_device
*dp
)
31 struct exynos5_dp
*base
= dp
->base
;
33 write32(&base
->dp_tx_sw_reset
, RESET_DP_TX
);
36 clrbits32(&base
->video_ctl_1
, VIDEO_EN
);
37 clrbits32(&base
->video_ctl_1
, HDCP_VIDEO_MUTE
);
39 reg
= MASTER_VID_FUNC_EN_N
| SLAVE_VID_FUNC_EN_N
|
40 AUD_FIFO_FUNC_EN_N
| AUD_FUNC_EN_N
|
41 HDCP_FUNC_EN_N
| SW_FUNC_EN_N
;
42 write32(&base
->func_en_1
, reg
);
44 reg
= SSC_FUNC_EN_N
| AUX_FUNC_EN_N
|
45 SERDES_FIFO_FUNC_EN_N
|
46 LS_CLK_DOMAIN_FUNC_EN_N
;
47 write32(&base
->func_en_2
, reg
);
51 reg
= LANE3_MAP_LOGIC_LANE_3
| LANE2_MAP_LOGIC_LANE_2
|
52 LANE1_MAP_LOGIC_LANE_1
| LANE0_MAP_LOGIC_LANE_0
;
54 write32(&base
->lane_map
, reg
);
56 write32(&base
->sys_ctl_1
, 0x0);
57 write32(&base
->sys_ctl_2
, 0x40);
58 write32(&base
->sys_ctl_3
, 0x0);
59 write32(&base
->sys_ctl_4
, 0x0);
61 write32(&base
->pkt_send_ctl
, 0x0);
62 write32(&base
->dp_hdcp_ctl
, 0x0);
64 write32(&base
->dp_hpd_deglitch_l
, 0x5e);
65 write32(&base
->dp_hpd_deglitch_h
, 0x1a);
67 write32(&base
->dp_debug_ctl
, 0x10);
69 write32(&base
->dp_phy_test
, 0x0);
71 write32(&base
->dp_video_fifo_thrd
, 0x0);
72 write32(&base
->dp_audio_margin
, 0x20);
74 write32(&base
->m_vid_gen_filter_th
, 0x4);
75 write32(&base
->m_aud_gen_filter_th
, 0x2);
77 write32(&base
->soc_general_ctl
, 0x00000101);
79 /* Set Analog Parameters */
80 write32(&base
->analog_ctl_1
, 0x10);
81 write32(&base
->analog_ctl_2
, 0x0C);
82 write32(&base
->analog_ctl_3
, 0x85);
83 write32(&base
->pll_filter_ctl_1
, 0x66);
84 write32(&base
->tx_amp_tuning_ctl
, 0x0);
86 /* Set interrupt pin assertion polarity as high */
87 write32(&base
->int_ctl
, INT_POL0
| INT_POL1
);
89 /* Clear pending registers */
90 write32(&base
->common_int_sta_1
, 0xff);
91 write32(&base
->common_int_sta_2
, 0x4f);
92 write32(&base
->common_int_sta_3
, 0xe0);
93 write32(&base
->common_int_sta_4
, 0xe7);
94 write32(&base
->dp_int_sta
, 0x63);
96 /* 0:mask,1: unmask */
97 write32(&base
->common_int_mask_1
, 0x00);
98 write32(&base
->common_int_mask_2
, 0x00);
99 write32(&base
->common_int_mask_3
, 0x00);
100 write32(&base
->common_int_mask_4
, 0x00);
101 write32(&base
->int_sta_mask
, 0x00);
104 unsigned int s5p_dp_get_pll_lock_status(struct s5p_dp_device
*dp
)
108 reg
= read32(&dp
->base
->dp_debug_ctl
);
115 int s5p_dp_init_analog_func(struct s5p_dp_device
*dp
)
119 struct exynos5_dp
*base
= dp
->base
;
121 write32(&base
->dp_phy_pd
, 0x00);
124 write32(&base
->common_int_sta_1
, reg
);
126 clrbits32(&base
->dp_debug_ctl
, (F_PLL_LOCK
| PLL_LOCK_CTRL
));
129 if (s5p_dp_get_pll_lock_status(dp
) == PLL_UNLOCKED
) {
131 clrbits32(&base
->dp_pll_ctl
, DP_PLL_PD
);
133 stopwatch_init_msecs_expire(&sw
, PLL_LOCK_TIMEOUT
);
135 while (s5p_dp_get_pll_lock_status(dp
) == PLL_UNLOCKED
) {
136 if (stopwatch_expired(&sw
)) {
137 printk(BIOS_ERR
, "%s: PLL is not locked\n",
144 /* Enable Serdes FIFO function and Link symbol clock domain module */
145 clrbits32(&base
->func_en_2
, (SERDES_FIFO_FUNC_EN_N
|
146 LS_CLK_DOMAIN_FUNC_EN_N
| AUX_FUNC_EN_N
));
150 void s5p_dp_init_aux(struct s5p_dp_device
*dp
)
153 struct exynos5_dp
*base
= dp
->base
;
155 /* Clear interrupts related to AUX channel */
156 reg
= RPLY_RECEIV
| AUX_ERR
;
157 write32(&base
->dp_int_sta
, reg
);
159 /* Disable AUX channel module */
160 setbits32(&base
->func_en_2
, AUX_FUNC_EN_N
);
162 /* Disable AUX transaction H/W retry */
163 reg
= (3 & AUX_BIT_PERIOD_MASK
) << AUX_BIT_PERIOD_SHIFT
;
164 reg
|= (0 & AUX_HW_RETRY_COUNT_MASK
) << AUX_HW_RETRY_COUNT_SHIFT
;
165 reg
|= (AUX_HW_RETRY_INTERVAL_600_US
<< AUX_HW_RETRY_INTERVAL_SHIFT
);
166 write32(&base
->aux_hw_retry_ctl
, reg
);
168 /* Receive AUX Channel DEFER commands equal to DEFFER_COUNT*64 */
170 reg
|= (1 & DEFER_COUNT_MASK
) << DEFER_COUNT_SHIFT
;
171 write32(&base
->aux_ch_defer_dtl
, reg
);
173 /* Enable AUX channel module */
174 clrbits32(&base
->func_en_2
, AUX_FUNC_EN_N
);
177 int s5p_dp_start_aux_transaction(struct s5p_dp_device
*dp
)
180 struct exynos5_dp
*base
= dp
->base
;
182 /* Enable AUX CH operation */
183 setbits32(&base
->aux_ch_ctl_2
, AUX_EN
);
185 /* Is AUX CH command reply received? */
186 reg
= read32(&base
->dp_int_sta
);
187 while (!(reg
& RPLY_RECEIV
))
188 reg
= read32(&base
->dp_int_sta
);
190 /* Clear interrupt source for AUX CH command reply */
191 write32(&base
->dp_int_sta
, RPLY_RECEIV
);
193 /* Clear interrupt source for AUX CH access error */
194 reg
= read32(&base
->dp_int_sta
);
196 printk(BIOS_ERR
, "%s: AUX_ERR encountered, dp_int_sta: "
197 "0x%02x\n", __func__
, reg
);
198 write32(&base
->dp_int_sta
, AUX_ERR
);
202 /* Check AUX CH error access status */
203 reg
= read32(&base
->dp_int_sta
);
204 if ((reg
& AUX_STATUS_MASK
) != 0) {
205 printk(BIOS_ERR
, "AUX CH error happens: %d\n\n",
206 reg
& AUX_STATUS_MASK
);
213 int s5p_dp_write_byte_to_dpcd(struct s5p_dp_device
*dp
,
214 unsigned int reg_addr
,
220 struct exynos5_dp
*base
= dp
->base
;
222 for (i
= 0; i
< MAX_AUX_RETRY_COUNT
; i
++) {
223 /* Clear AUX CH data buffer */
224 write32(&base
->buf_data_ctl
, BUF_CLR
);
226 /* Select DPCD device address */
227 reg
= reg_addr
>> AUX_ADDR_7_0_SHIFT
;
228 reg
&= AUX_ADDR_7_0_MASK
;
229 write32(&base
->aux_addr_7_0
, reg
);
230 reg
= reg_addr
>> AUX_ADDR_15_8_SHIFT
;
231 reg
&= AUX_ADDR_15_8_MASK
;
232 write32(&base
->aux_addr_15_8
, reg
);
233 reg
= reg_addr
>> AUX_ADDR_19_16_SHIFT
;
234 reg
&= AUX_ADDR_19_16_MASK
;
235 write32(&base
->aux_addr_19_16
, reg
);
237 /* Write data buffer */
238 reg
= (unsigned int)data
;
239 write32(&base
->buf_data_0
, reg
);
242 * Set DisplayPort transaction and write 1 byte
243 * If bit 3 is 1, DisplayPort transaction.
244 * If Bit 3 is 0, I2C transaction.
246 reg
= AUX_TX_COMM_DP_TRANSACTION
| AUX_TX_COMM_WRITE
;
247 write32(&base
->aux_ch_ctl_1
, reg
);
249 /* Start AUX transaction */
250 retval
= s5p_dp_start_aux_transaction(dp
);
254 printk(BIOS_DEBUG
, "Aux Transaction fail!\n");
260 int s5p_dp_read_byte_from_dpcd(struct s5p_dp_device
*dp
,
261 unsigned int reg_addr
,
267 struct exynos5_dp
*base
= dp
->base
;
269 for (i
= 0; i
< MAX_AUX_RETRY_COUNT
; i
++) {
270 /* Clear AUX CH data buffer */
271 write32(&base
->buf_data_ctl
, BUF_CLR
);
273 /* Select DPCD device address */
274 reg
= reg_addr
>> AUX_ADDR_7_0_SHIFT
;
275 reg
&= AUX_ADDR_7_0_MASK
;
276 write32(&base
->aux_addr_7_0
, reg
);
277 reg
= reg_addr
>> AUX_ADDR_15_8_SHIFT
;
278 reg
&= AUX_ADDR_15_8_MASK
;
279 write32(&base
->aux_addr_15_8
, reg
);
280 reg
= reg_addr
>> AUX_ADDR_19_16_SHIFT
;
281 reg
&= AUX_ADDR_19_16_MASK
;
282 write32(&base
->aux_addr_19_16
, reg
);
285 * Set DisplayPort transaction and read 1 byte
286 * If bit 3 is 1, DisplayPort transaction.
287 * If Bit 3 is 0, I2C transaction.
289 reg
= AUX_TX_COMM_DP_TRANSACTION
| AUX_TX_COMM_READ
;
290 write32(&base
->aux_ch_ctl_1
, reg
);
292 /* Start AUX transaction */
293 retval
= s5p_dp_start_aux_transaction(dp
);
297 printk(BIOS_DEBUG
, "Aux Transaction fail!\n");
300 /* Read data buffer */
302 reg
= read32(&base
->buf_data_0
);
303 *data
= (unsigned char)(reg
& 0xff);
309 void s5p_dp_init_video(struct s5p_dp_device
*dp
)
312 struct exynos5_dp
*base
= dp
->base
;
314 reg
= VSYNC_DET
| VID_FORMAT_CHG
| VID_CLK_CHG
;
315 write32(&base
->common_int_sta_1
, reg
);
318 write32(&base
->sys_ctl_1
, reg
);
320 reg
= (4 & CHA_CRI_MASK
) << CHA_CRI_SHIFT
;
322 write32(&base
->sys_ctl_2
, reg
);
325 write32(&base
->sys_ctl_3
, reg
);
328 void s5p_dp_set_video_color_format(struct s5p_dp_device
*dp
,
329 unsigned int color_depth
,
330 unsigned int color_space
,
331 unsigned int dynamic_range
,
335 struct exynos5_dp
*base
= dp
->base
;
337 /* Configure the input color depth, color space, dynamic range */
338 reg
= (dynamic_range
<< IN_D_RANGE_SHIFT
) |
339 (color_depth
<< IN_BPC_SHIFT
) |
340 (color_space
<< IN_COLOR_F_SHIFT
);
341 write32(&base
->video_ctl_2
, reg
);
343 /* Set Input Color YCbCr Coefficients to ITU601 or ITU709 */
344 reg
= read32(&base
->video_ctl_3
);
345 reg
&= ~IN_YC_COEFFI_MASK
;
347 reg
|= IN_YC_COEFFI_ITU709
;
349 reg
|= IN_YC_COEFFI_ITU601
;
350 write32(&base
->video_ctl_3
, reg
);
353 int s5p_dp_is_slave_video_stream_clock_on(struct s5p_dp_device
*dp
)
356 struct exynos5_dp
*base
= dp
->base
;
358 reg
= read32(&base
->sys_ctl_1
);
359 write32(&base
->sys_ctl_1
, reg
);
361 reg
= read32(&base
->sys_ctl_1
);
363 if (!(reg
& DET_STA
))
366 reg
= read32(&base
->sys_ctl_2
);
367 write32(&base
->sys_ctl_2
, reg
);
369 reg
= read32(&base
->sys_ctl_2
);
372 printk(BIOS_DEBUG
, "Input stream clk is changing\n");
379 void s5p_dp_set_video_cr_mn(struct s5p_dp_device
*dp
,
380 enum clock_recovery_m_value_type type
,
381 unsigned int m_value
,
382 unsigned int n_value
)
385 struct exynos5_dp
*base
= dp
->base
;
387 if (type
== REGISTER_M
) {
388 setbits32(&base
->sys_ctl_4
, FIX_M_VID
);
390 reg
= m_value
>> M_VID_0_VALUE_SHIFT
;
391 write32(&base
->m_vid_0
, reg
);
393 reg
= (m_value
>> M_VID_1_VALUE_SHIFT
);
394 write32(&base
->m_vid_1
, reg
);
396 reg
= (m_value
>> M_VID_2_VALUE_SHIFT
);
397 write32(&base
->m_vid_2
, reg
);
399 reg
= n_value
>> N_VID_0_VALUE_SHIFT
;
400 write32(&base
->n_vid_0
, reg
);
402 reg
= (n_value
>> N_VID_1_VALUE_SHIFT
);
403 write32(&base
->n_vid_1
, reg
);
405 reg
= (n_value
>> N_VID_2_VALUE_SHIFT
);
406 write32(&base
->n_vid_2
, reg
);
408 clrbits32(&base
->sys_ctl_4
, FIX_M_VID
);
410 write32(&base
->n_vid_0
, 0x00);
411 write32(&base
->n_vid_1
, 0x80);
412 write32(&base
->n_vid_2
, 0x00);
416 void s5p_dp_enable_video_master(struct s5p_dp_device
*dp
)
419 struct exynos5_dp
*base
= dp
->base
;
421 reg
= read32(&base
->soc_general_ctl
);
422 reg
&= ~VIDEO_MODE_MASK
;
423 reg
|= VIDEO_MODE_SLAVE_MODE
;
424 write32(&base
->soc_general_ctl
, reg
);
427 int s5p_dp_is_video_stream_on(struct s5p_dp_device
*dp
)
431 struct exynos5_dp
*base
= dp
->base
;
433 /* Wait for 4 VSYNC_DET interrupts */
434 stopwatch_init_msecs_expire(&sw
, STREAM_ON_TIMEOUT
);
437 reg
= read32(&base
->common_int_sta_1
);
438 if (reg
& VSYNC_DET
) {
440 write32(&base
->common_int_sta_1
, reg
| VSYNC_DET
);
444 } while (!stopwatch_expired(&sw
));
447 printk(BIOS_DEBUG
, "s5p_dp_is_video_stream_on timeout\n");
454 void s5p_dp_config_video_slave_mode(struct s5p_dp_device
*dp
,
455 struct video_info
*video_info
)
458 struct exynos5_dp
*base
= dp
->base
;
460 reg
= read32(&base
->func_en_1
);
461 reg
&= ~(MASTER_VID_FUNC_EN_N
|SLAVE_VID_FUNC_EN_N
);
462 reg
|= MASTER_VID_FUNC_EN_N
;
463 write32(&base
->func_en_1
, reg
);
465 reg
= read32(&base
->video_ctl_10
);
466 reg
&= ~INTERACE_SCAN_CFG
;
467 reg
|= (video_info
->interlaced
<< 2);
468 write32(&base
->video_ctl_10
, reg
);
470 reg
= read32(&base
->video_ctl_10
);
471 reg
&= ~VSYNC_POLARITY_CFG
;
472 reg
|= (video_info
->v_sync_polarity
<< 1);
473 write32(&base
->video_ctl_10
, reg
);
475 reg
= read32(&base
->video_ctl_10
);
476 reg
&= ~HSYNC_POLARITY_CFG
;
477 reg
|= (video_info
->h_sync_polarity
<< 0);
478 write32(&base
->video_ctl_10
, reg
);
480 reg
= AUDIO_MODE_SPDIF_MODE
| VIDEO_MODE_SLAVE_MODE
;
481 write32(&base
->soc_general_ctl
, reg
);
484 void s5p_dp_wait_hw_link_training_done(struct s5p_dp_device
*dp
)
487 struct exynos5_dp
*base
= dp
->base
;
489 reg
= read32(&base
->dp_hw_link_training
);
490 while (reg
& HW_TRAINING_EN
)
491 reg
= read32(&base
->dp_hw_link_training
);