1 /* linux/drivers/video/exynos/exynos_mipi_dsi_lowlevel.c
3 * Samsung SoC MIPI-DSI lowlevel driver.
5 * Copyright (c) 2012 Samsung Electronics Co., Ltd
7 * InKi Dae, <inki.dae@samsung.com>
8 * Donghwa Lee, <dh09.lee@samsung.com>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2 as
12 * published by the Free Software Foundation.
15 #include <linux/module.h>
16 #include <linux/kernel.h>
17 #include <linux/errno.h>
18 #include <linux/mutex.h>
19 #include <linux/wait.h>
20 #include <linux/delay.h>
23 #include <linux/ctype.h>
24 #include <linux/platform_device.h>
27 #include <video/exynos_mipi_dsim.h>
29 #include "exynos_mipi_dsi_regs.h"
30 #include "exynos_mipi_dsi_lowlevel.h"
32 void exynos_mipi_dsi_func_reset(struct mipi_dsim_device
*dsim
)
36 reg
= readl(dsim
->reg_base
+ EXYNOS_DSIM_SWRST
);
40 writel(reg
, dsim
->reg_base
+ EXYNOS_DSIM_SWRST
);
43 void exynos_mipi_dsi_sw_reset(struct mipi_dsim_device
*dsim
)
47 reg
= readl(dsim
->reg_base
+ EXYNOS_DSIM_SWRST
);
51 writel(reg
, dsim
->reg_base
+ EXYNOS_DSIM_SWRST
);
54 void exynos_mipi_dsi_sw_reset_release(struct mipi_dsim_device
*dsim
)
58 reg
= readl(dsim
->reg_base
+ EXYNOS_DSIM_INTSRC
);
60 reg
|= INTSRC_SW_RST_RELEASE
;
62 writel(reg
, dsim
->reg_base
+ EXYNOS_DSIM_INTSRC
);
65 int exynos_mipi_dsi_get_sw_reset_release(struct mipi_dsim_device
*dsim
)
67 return (readl(dsim
->reg_base
+ EXYNOS_DSIM_INTSRC
)) &
68 INTSRC_SW_RST_RELEASE
;
71 unsigned int exynos_mipi_dsi_read_interrupt_mask(struct mipi_dsim_device
*dsim
)
75 reg
= readl(dsim
->reg_base
+ EXYNOS_DSIM_INTMSK
);
80 void exynos_mipi_dsi_set_interrupt_mask(struct mipi_dsim_device
*dsim
,
81 unsigned int mode
, unsigned int mask
)
90 writel(reg
, dsim
->reg_base
+ EXYNOS_DSIM_INTMSK
);
93 void exynos_mipi_dsi_init_fifo_pointer(struct mipi_dsim_device
*dsim
,
98 reg
= readl(dsim
->reg_base
+ EXYNOS_DSIM_FIFOCTRL
);
100 writel(reg
& ~(cfg
), dsim
->reg_base
+ EXYNOS_DSIM_FIFOCTRL
);
104 writel(reg
, dsim
->reg_base
+ EXYNOS_DSIM_FIFOCTRL
);
108 * this function set PLL P, M and S value in D-PHY
110 void exynos_mipi_dsi_set_phy_tunning(struct mipi_dsim_device
*dsim
,
113 writel(DSIM_AFC_CTL(value
), dsim
->reg_base
+ EXYNOS_DSIM_PHYACCHR
);
116 void exynos_mipi_dsi_set_main_stand_by(struct mipi_dsim_device
*dsim
,
121 reg
= readl(dsim
->reg_base
+ EXYNOS_DSIM_MDRESOL
);
123 reg
&= ~DSIM_MAIN_STAND_BY
;
126 reg
|= DSIM_MAIN_STAND_BY
;
128 writel(reg
, dsim
->reg_base
+ EXYNOS_DSIM_MDRESOL
);
131 void exynos_mipi_dsi_set_main_disp_resol(struct mipi_dsim_device
*dsim
,
132 unsigned int width_resol
, unsigned int height_resol
)
136 /* standby should be set after configuration so set to not ready*/
137 reg
= (readl(dsim
->reg_base
+ EXYNOS_DSIM_MDRESOL
)) &
138 ~(DSIM_MAIN_STAND_BY
);
139 writel(reg
, dsim
->reg_base
+ EXYNOS_DSIM_MDRESOL
);
141 reg
&= ~((0x7ff << 16) | (0x7ff << 0));
142 reg
|= DSIM_MAIN_VRESOL(height_resol
) | DSIM_MAIN_HRESOL(width_resol
);
144 reg
|= DSIM_MAIN_STAND_BY
;
145 writel(reg
, dsim
->reg_base
+ EXYNOS_DSIM_MDRESOL
);
148 void exynos_mipi_dsi_set_main_disp_vporch(struct mipi_dsim_device
*dsim
,
149 unsigned int cmd_allow
, unsigned int vfront
, unsigned int vback
)
153 reg
= (readl(dsim
->reg_base
+ EXYNOS_DSIM_MVPORCH
)) &
154 ~((DSIM_CMD_ALLOW_MASK
) | (DSIM_STABLE_VFP_MASK
) |
155 (DSIM_MAIN_VBP_MASK
));
157 reg
|= (DSIM_CMD_ALLOW_SHIFT(cmd_allow
& 0xf) |
158 DSIM_STABLE_VFP_SHIFT(vfront
& 0x7ff) |
159 DSIM_MAIN_VBP_SHIFT(vback
& 0x7ff));
161 writel(reg
, dsim
->reg_base
+ EXYNOS_DSIM_MVPORCH
);
164 void exynos_mipi_dsi_set_main_disp_hporch(struct mipi_dsim_device
*dsim
,
165 unsigned int front
, unsigned int back
)
169 reg
= (readl(dsim
->reg_base
+ EXYNOS_DSIM_MHPORCH
)) &
170 ~((DSIM_MAIN_HFP_MASK
) | (DSIM_MAIN_HBP_MASK
));
172 reg
|= DSIM_MAIN_HFP_SHIFT(front
) | DSIM_MAIN_HBP_SHIFT(back
);
174 writel(reg
, dsim
->reg_base
+ EXYNOS_DSIM_MHPORCH
);
177 void exynos_mipi_dsi_set_main_disp_sync_area(struct mipi_dsim_device
*dsim
,
178 unsigned int vert
, unsigned int hori
)
182 reg
= (readl(dsim
->reg_base
+ EXYNOS_DSIM_MSYNC
)) &
183 ~((DSIM_MAIN_VSA_MASK
) | (DSIM_MAIN_HSA_MASK
));
185 reg
|= (DSIM_MAIN_VSA_SHIFT(vert
& 0x3ff) |
186 DSIM_MAIN_HSA_SHIFT(hori
));
188 writel(reg
, dsim
->reg_base
+ EXYNOS_DSIM_MSYNC
);
191 void exynos_mipi_dsi_set_sub_disp_resol(struct mipi_dsim_device
*dsim
,
192 unsigned int vert
, unsigned int hori
)
196 reg
= (readl(dsim
->reg_base
+ EXYNOS_DSIM_SDRESOL
)) &
197 ~(DSIM_SUB_STANDY_MASK
);
199 writel(reg
, dsim
->reg_base
+ EXYNOS_DSIM_SDRESOL
);
201 reg
&= ~(DSIM_SUB_VRESOL_MASK
) | ~(DSIM_SUB_HRESOL_MASK
);
202 reg
|= (DSIM_SUB_VRESOL_SHIFT(vert
& 0x7ff) |
203 DSIM_SUB_HRESOL_SHIFT(hori
& 0x7ff));
204 writel(reg
, dsim
->reg_base
+ EXYNOS_DSIM_SDRESOL
);
206 reg
|= DSIM_SUB_STANDY_SHIFT(1);
207 writel(reg
, dsim
->reg_base
+ EXYNOS_DSIM_SDRESOL
);
210 void exynos_mipi_dsi_init_config(struct mipi_dsim_device
*dsim
)
212 struct mipi_dsim_config
*dsim_config
= dsim
->dsim_config
;
214 unsigned int cfg
= (readl(dsim
->reg_base
+ EXYNOS_DSIM_CONFIG
)) &
215 ~((1 << 28) | (0x1f << 20) | (0x3 << 5));
217 cfg
= ((DSIM_AUTO_FLUSH(dsim_config
->auto_flush
)) |
218 (DSIM_EOT_DISABLE(dsim_config
->eot_disable
)) |
219 (DSIM_AUTO_MODE_SHIFT(dsim_config
->auto_vertical_cnt
)) |
220 (DSIM_HSE_MODE_SHIFT(dsim_config
->hse
)) |
221 (DSIM_HFP_MODE_SHIFT(dsim_config
->hfp
)) |
222 (DSIM_HBP_MODE_SHIFT(dsim_config
->hbp
)) |
223 (DSIM_HSA_MODE_SHIFT(dsim_config
->hsa
)) |
224 (DSIM_NUM_OF_DATALANE_SHIFT(dsim_config
->e_no_data_lane
)));
226 writel(cfg
, dsim
->reg_base
+ EXYNOS_DSIM_CONFIG
);
229 void exynos_mipi_dsi_display_config(struct mipi_dsim_device
*dsim
,
230 struct mipi_dsim_config
*dsim_config
)
232 u32 reg
= (readl(dsim
->reg_base
+ EXYNOS_DSIM_CONFIG
)) &
233 ~((0x3 << 26) | (1 << 25) | (0x3 << 18) | (0x7 << 12) |
234 (0x3 << 16) | (0x7 << 8));
236 if (dsim_config
->e_interface
== DSIM_VIDEO
)
238 else if (dsim_config
->e_interface
== DSIM_COMMAND
)
241 dev_err(dsim
->dev
, "unknown lcd type.\n");
246 reg
|= ((u8
) (dsim_config
->e_burst_mode
) & 0x3) << 26 |
247 ((u8
) (dsim_config
->e_virtual_ch
) & 0x3) << 18 |
248 ((u8
) (dsim_config
->e_pixel_format
) & 0x7) << 12;
250 writel(reg
, dsim
->reg_base
+ EXYNOS_DSIM_CONFIG
);
253 void exynos_mipi_dsi_enable_lane(struct mipi_dsim_device
*dsim
, unsigned int lane
,
258 reg
= readl(dsim
->reg_base
+ EXYNOS_DSIM_CONFIG
);
261 reg
|= DSIM_LANE_ENx(lane
);
263 reg
&= ~DSIM_LANE_ENx(lane
);
265 writel(reg
, dsim
->reg_base
+ EXYNOS_DSIM_CONFIG
);
269 void exynos_mipi_dsi_set_data_lane_number(struct mipi_dsim_device
*dsim
,
274 /* get the data lane number. */
275 cfg
= DSIM_NUM_OF_DATALANE_SHIFT(count
);
277 writel(cfg
, dsim
->reg_base
+ EXYNOS_DSIM_CONFIG
);
280 void exynos_mipi_dsi_enable_afc(struct mipi_dsim_device
*dsim
, unsigned int enable
,
281 unsigned int afc_code
)
283 unsigned int reg
= readl(dsim
->reg_base
+ EXYNOS_DSIM_PHYACCHR
);
288 reg
|= (afc_code
& 0x7) << 5;
292 writel(reg
, dsim
->reg_base
+ EXYNOS_DSIM_PHYACCHR
);
295 void exynos_mipi_dsi_enable_pll_bypass(struct mipi_dsim_device
*dsim
,
298 unsigned int reg
= (readl(dsim
->reg_base
+ EXYNOS_DSIM_CLKCTRL
)) &
299 ~(DSIM_PLL_BYPASS_SHIFT(0x1));
301 reg
|= DSIM_PLL_BYPASS_SHIFT(enable
);
303 writel(reg
, dsim
->reg_base
+ EXYNOS_DSIM_CLKCTRL
);
306 void exynos_mipi_dsi_set_pll_pms(struct mipi_dsim_device
*dsim
, unsigned int p
,
307 unsigned int m
, unsigned int s
)
309 unsigned int reg
= readl(dsim
->reg_base
+ EXYNOS_DSIM_PLLCTRL
);
311 reg
|= ((p
& 0x3f) << 13) | ((m
& 0x1ff) << 4) | ((s
& 0x7) << 1);
313 writel(reg
, dsim
->reg_base
+ EXYNOS_DSIM_PLLCTRL
);
316 void exynos_mipi_dsi_pll_freq_band(struct mipi_dsim_device
*dsim
,
317 unsigned int freq_band
)
319 unsigned int reg
= (readl(dsim
->reg_base
+ EXYNOS_DSIM_PLLCTRL
)) &
320 ~(DSIM_FREQ_BAND_SHIFT(0x1f));
322 reg
|= DSIM_FREQ_BAND_SHIFT(freq_band
& 0x1f);
324 writel(reg
, dsim
->reg_base
+ EXYNOS_DSIM_PLLCTRL
);
327 void exynos_mipi_dsi_pll_freq(struct mipi_dsim_device
*dsim
,
328 unsigned int pre_divider
, unsigned int main_divider
,
331 unsigned int reg
= (readl(dsim
->reg_base
+ EXYNOS_DSIM_PLLCTRL
)) &
334 reg
|= (pre_divider
& 0x3f) << 13 | (main_divider
& 0x1ff) << 4 |
337 writel(reg
, dsim
->reg_base
+ EXYNOS_DSIM_PLLCTRL
);
340 void exynos_mipi_dsi_pll_stable_time(struct mipi_dsim_device
*dsim
,
341 unsigned int lock_time
)
343 writel(lock_time
, dsim
->reg_base
+ EXYNOS_DSIM_PLLTMR
);
346 void exynos_mipi_dsi_enable_pll(struct mipi_dsim_device
*dsim
, unsigned int enable
)
348 unsigned int reg
= (readl(dsim
->reg_base
+ EXYNOS_DSIM_PLLCTRL
)) &
349 ~(DSIM_PLL_EN_SHIFT(0x1));
351 reg
|= DSIM_PLL_EN_SHIFT(enable
& 0x1);
353 writel(reg
, dsim
->reg_base
+ EXYNOS_DSIM_PLLCTRL
);
356 void exynos_mipi_dsi_set_byte_clock_src(struct mipi_dsim_device
*dsim
,
359 unsigned int reg
= (readl(dsim
->reg_base
+ EXYNOS_DSIM_CLKCTRL
)) &
360 ~(DSIM_BYTE_CLK_SRC_SHIFT(0x3));
362 reg
|= (DSIM_BYTE_CLK_SRC_SHIFT(src
));
364 writel(reg
, dsim
->reg_base
+ EXYNOS_DSIM_CLKCTRL
);
367 void exynos_mipi_dsi_enable_byte_clock(struct mipi_dsim_device
*dsim
,
370 unsigned int reg
= (readl(dsim
->reg_base
+ EXYNOS_DSIM_CLKCTRL
)) &
371 ~(DSIM_BYTE_CLKEN_SHIFT(0x1));
373 reg
|= DSIM_BYTE_CLKEN_SHIFT(enable
);
375 writel(reg
, dsim
->reg_base
+ EXYNOS_DSIM_CLKCTRL
);
378 void exynos_mipi_dsi_set_esc_clk_prs(struct mipi_dsim_device
*dsim
,
379 unsigned int enable
, unsigned int prs_val
)
381 unsigned int reg
= (readl(dsim
->reg_base
+ EXYNOS_DSIM_CLKCTRL
)) &
382 ~(DSIM_ESC_CLKEN_SHIFT(0x1) | 0xffff);
384 reg
|= DSIM_ESC_CLKEN_SHIFT(enable
);
388 writel(reg
, dsim
->reg_base
+ EXYNOS_DSIM_CLKCTRL
);
391 void exynos_mipi_dsi_enable_esc_clk_on_lane(struct mipi_dsim_device
*dsim
,
392 unsigned int lane_sel
, unsigned int enable
)
394 unsigned int reg
= readl(dsim
->reg_base
+ EXYNOS_DSIM_CLKCTRL
);
397 reg
|= DSIM_LANE_ESC_CLKEN(lane_sel
);
400 reg
&= ~DSIM_LANE_ESC_CLKEN(lane_sel
);
402 writel(reg
, dsim
->reg_base
+ EXYNOS_DSIM_CLKCTRL
);
405 void exynos_mipi_dsi_force_dphy_stop_state(struct mipi_dsim_device
*dsim
,
408 unsigned int reg
= (readl(dsim
->reg_base
+ EXYNOS_DSIM_ESCMODE
)) &
409 ~(DSIM_FORCE_STOP_STATE_SHIFT(0x1));
411 reg
|= (DSIM_FORCE_STOP_STATE_SHIFT(enable
& 0x1));
413 writel(reg
, dsim
->reg_base
+ EXYNOS_DSIM_ESCMODE
);
416 unsigned int exynos_mipi_dsi_is_lane_state(struct mipi_dsim_device
*dsim
)
418 unsigned int reg
= readl(dsim
->reg_base
+ EXYNOS_DSIM_STATUS
);
421 * check clock and data lane states.
422 * if MIPI-DSI controller was enabled at bootloader then
423 * TX_READY_HS_CLK is enabled otherwise STOP_STATE_CLK.
424 * so it should be checked for two case.
426 if ((reg
& DSIM_STOP_STATE_DAT(0xf)) &&
427 ((reg
& DSIM_STOP_STATE_CLK
) ||
428 (reg
& DSIM_TX_READY_HS_CLK
)))
434 void exynos_mipi_dsi_set_stop_state_counter(struct mipi_dsim_device
*dsim
,
435 unsigned int cnt_val
)
437 unsigned int reg
= (readl(dsim
->reg_base
+ EXYNOS_DSIM_ESCMODE
)) &
438 ~(DSIM_STOP_STATE_CNT_SHIFT(0x7ff));
440 reg
|= (DSIM_STOP_STATE_CNT_SHIFT(cnt_val
& 0x7ff));
442 writel(reg
, dsim
->reg_base
+ EXYNOS_DSIM_ESCMODE
);
445 void exynos_mipi_dsi_set_bta_timeout(struct mipi_dsim_device
*dsim
,
446 unsigned int timeout
)
448 unsigned int reg
= (readl(dsim
->reg_base
+ EXYNOS_DSIM_TIMEOUT
)) &
449 ~(DSIM_BTA_TOUT_SHIFT(0xff));
451 reg
|= (DSIM_BTA_TOUT_SHIFT(timeout
));
453 writel(reg
, dsim
->reg_base
+ EXYNOS_DSIM_TIMEOUT
);
456 void exynos_mipi_dsi_set_lpdr_timeout(struct mipi_dsim_device
*dsim
,
457 unsigned int timeout
)
459 unsigned int reg
= (readl(dsim
->reg_base
+ EXYNOS_DSIM_TIMEOUT
)) &
460 ~(DSIM_LPDR_TOUT_SHIFT(0xffff));
462 reg
|= (DSIM_LPDR_TOUT_SHIFT(timeout
));
464 writel(reg
, dsim
->reg_base
+ EXYNOS_DSIM_TIMEOUT
);
467 void exynos_mipi_dsi_set_cpu_transfer_mode(struct mipi_dsim_device
*dsim
,
470 unsigned int reg
= readl(dsim
->reg_base
+ EXYNOS_DSIM_ESCMODE
);
472 reg
&= ~DSIM_CMD_LPDT_LP
;
475 reg
|= DSIM_CMD_LPDT_LP
;
477 writel(reg
, dsim
->reg_base
+ EXYNOS_DSIM_ESCMODE
);
480 void exynos_mipi_dsi_set_lcdc_transfer_mode(struct mipi_dsim_device
*dsim
,
483 unsigned int reg
= readl(dsim
->reg_base
+ EXYNOS_DSIM_ESCMODE
);
485 reg
&= ~DSIM_TX_LPDT_LP
;
488 reg
|= DSIM_TX_LPDT_LP
;
490 writel(reg
, dsim
->reg_base
+ EXYNOS_DSIM_ESCMODE
);
493 void exynos_mipi_dsi_enable_hs_clock(struct mipi_dsim_device
*dsim
,
496 unsigned int reg
= (readl(dsim
->reg_base
+ EXYNOS_DSIM_CLKCTRL
)) &
497 ~(DSIM_TX_REQUEST_HSCLK_SHIFT(0x1));
499 reg
|= DSIM_TX_REQUEST_HSCLK_SHIFT(enable
);
501 writel(reg
, dsim
->reg_base
+ EXYNOS_DSIM_CLKCTRL
);
504 void exynos_mipi_dsi_dp_dn_swap(struct mipi_dsim_device
*dsim
,
505 unsigned int swap_en
)
507 unsigned int reg
= readl(dsim
->reg_base
+ EXYNOS_DSIM_PHYACCHR1
);
510 reg
|= (swap_en
& 0x3) << 0;
512 writel(reg
, dsim
->reg_base
+ EXYNOS_DSIM_PHYACCHR1
);
515 void exynos_mipi_dsi_hs_zero_ctrl(struct mipi_dsim_device
*dsim
,
516 unsigned int hs_zero
)
518 unsigned int reg
= (readl(dsim
->reg_base
+ EXYNOS_DSIM_PLLCTRL
)) &
521 reg
|= ((hs_zero
& 0xf) << 28);
523 writel(reg
, dsim
->reg_base
+ EXYNOS_DSIM_PLLCTRL
);
526 void exynos_mipi_dsi_prep_ctrl(struct mipi_dsim_device
*dsim
, unsigned int prep
)
528 unsigned int reg
= (readl(dsim
->reg_base
+ EXYNOS_DSIM_PLLCTRL
)) &
531 reg
|= ((prep
& 0x7) << 20);
533 writel(reg
, dsim
->reg_base
+ EXYNOS_DSIM_PLLCTRL
);
536 unsigned int exynos_mipi_dsi_read_interrupt(struct mipi_dsim_device
*dsim
)
538 return readl(dsim
->reg_base
+ EXYNOS_DSIM_INTSRC
);
541 void exynos_mipi_dsi_clear_interrupt(struct mipi_dsim_device
*dsim
,
544 unsigned int reg
= readl(dsim
->reg_base
+ EXYNOS_DSIM_INTSRC
);
548 writel(reg
, dsim
->reg_base
+ EXYNOS_DSIM_INTSRC
);
551 void exynos_mipi_dsi_set_interrupt(struct mipi_dsim_device
*dsim
,
552 unsigned int src
, unsigned int enable
)
554 unsigned int reg
= 0;
561 writel(reg
, dsim
->reg_base
+ EXYNOS_DSIM_INTSRC
);
564 unsigned int exynos_mipi_dsi_is_pll_stable(struct mipi_dsim_device
*dsim
)
568 reg
= readl(dsim
->reg_base
+ EXYNOS_DSIM_STATUS
);
570 return reg
& (1 << 31) ? 1 : 0;
573 unsigned int exynos_mipi_dsi_get_fifo_state(struct mipi_dsim_device
*dsim
)
575 return readl(dsim
->reg_base
+ EXYNOS_DSIM_FIFOCTRL
) & ~(0x1f);
578 void exynos_mipi_dsi_wr_tx_header(struct mipi_dsim_device
*dsim
,
579 unsigned int di
, unsigned int data0
, unsigned int data1
)
581 unsigned int reg
= (data1
<< 16) | (data0
<< 8) | ((di
& 0x3f) << 0);
583 writel(reg
, dsim
->reg_base
+ EXYNOS_DSIM_PKTHDR
);
586 void exynos_mipi_dsi_rd_tx_header(struct mipi_dsim_device
*dsim
,
587 unsigned int di
, unsigned int data0
)
589 unsigned int reg
= (data0
<< 8) | (di
<< 0);
591 writel(reg
, dsim
->reg_base
+ EXYNOS_DSIM_PKTHDR
);
594 unsigned int exynos_mipi_dsi_rd_rx_fifo(struct mipi_dsim_device
*dsim
)
596 return readl(dsim
->reg_base
+ EXYNOS_DSIM_RXFIFO
);
599 unsigned int _exynos_mipi_dsi_get_frame_done_status(struct mipi_dsim_device
*dsim
)
601 unsigned int reg
= readl(dsim
->reg_base
+ EXYNOS_DSIM_INTSRC
);
603 return (reg
& INTSRC_FRAME_DONE
) ? 1 : 0;
606 void _exynos_mipi_dsi_clear_frame_done(struct mipi_dsim_device
*dsim
)
608 unsigned int reg
= readl(dsim
->reg_base
+ EXYNOS_DSIM_INTSRC
);
610 writel(reg
| INTSRC_FRAME_DONE
, dsim
->reg_base
+
614 void exynos_mipi_dsi_wr_tx_data(struct mipi_dsim_device
*dsim
,
615 unsigned int tx_data
)
617 writel(tx_data
, dsim
->reg_base
+ EXYNOS_DSIM_PAYLOAD
);