15 #include <linux/module.h>
16 #include <linux/kernel.h>
17 #include <linux/errno.h>
19 #include <linux/wait.h>
23 #include <linux/ctype.h>
39 #define MIPI_FIFO_TIMEOUT msecs_to_jiffies(250)
40 #define MIPI_RX_FIFO_READ_DONE 0x30800002
41 #define MIPI_MAX_RX_FIFO 20
42 #define MHZ (1000 * 1000)
43 #define FIN_HZ (24 * MHZ)
45 #define DFIN_PLL_MIN_HZ (6 * MHZ)
46 #define DFIN_PLL_MAX_HZ (12 * MHZ)
48 #define DFVCO_MIN_HZ (500 * MHZ)
49 #define DFVCO_MAX_HZ (1000 * MHZ)
51 #define TRY_GET_FIFO_TIMEOUT (5000 * 2)
52 #define TRY_FIFO_CLEAR (10)
71 static unsigned int dpll_table[15] = {
72 100, 120, 170, 220, 270,
73 320, 390, 450, 510, 560,
74 640, 690, 770, 870, 950
80 unsigned int intsrc, intmsk;
84 intmsk = ~intmsk & intsrc;
92 dev_dbg(dsim->
dev,
"MIPI INTMSK_FIFO_EMPTY\n");
109 unsigned int data_cnt = 0,
payload = 0;
112 for (data_cnt = 0; data_cnt <
data_size; data_cnt += 4) {
117 if ((data_size - data_cnt) < 4) {
118 if ((data_size - data_cnt) == 3) {
120 data0[data_cnt + 1] << 8 |
121 data0[data_cnt + 2] << 16;
122 dev_dbg(dsim->
dev,
"count = 3 payload = %x, %x %x %x\n",
125 data0[data_cnt + 2]);
126 }
else if ((data_size - data_cnt) == 2) {
128 data0[data_cnt + 1] << 8;
130 "count = 2 payload = %x, %x %x\n",
payload,
132 data0[data_cnt + 1]);
133 }
else if ((data_size - data_cnt) == 1) {
141 data0[data_cnt + 1] << 8 |
142 data0[data_cnt + 2] << 16 |
143 data0[data_cnt + 3] << 24;
146 "count = 4 payload = %x, %x %x %x %x\n",
150 data0[data_cnt + 3]);
158 const unsigned char *data0,
unsigned int data_size)
160 unsigned int check_rx_ack = 0;
226 size = data_size * 4;
236 dev_dbg(dsim->
dev,
"count = %d payload = %x,%x %x %x\n",
237 data_size, payload, data0[0],
242 exynos_mipi_dsi_long_data_wr(dsim, data0, data_size);
246 (data_size & 0xff00) >> 8);
280 "data id %x is not supported current DSI spec.\n",
288 static unsigned int exynos_mipi_dsi_long_data_rd(
struct mipi_dsim_device *dsim,
289 unsigned int req_size,
unsigned int rx_data,
u8 *rx_buf)
291 unsigned int rcv_pkt,
i,
j;
295 rxsize = (
u16)((rx_data & 0x00ffff00) >> 8);
296 dev_dbg(dsim->
dev,
"mipi dsi rx size : %d\n", rxsize);
297 if (rxsize != req_size) {
299 "received size mismatch received: %d, requested: %d\n",
304 for (i = 0; i < (rxsize >> 2); i++) {
306 dev_dbg(dsim->
dev,
"received pkt : %08x\n", rcv_pkt);
307 for (j = 0; j < 4; j++) {
308 rx_buf[(i * 4) + j] =
309 (
u8)(rcv_pkt >> (j * 8)) & 0xff;
311 (rcv_pkt >> (j * 8)) & 0xff);
316 dev_dbg(dsim->
dev,
"received pkt : %08x\n", rcv_pkt);
317 for (j = 0; j < (rxsize % 4); j++) {
318 rx_buf[(i * 4) + j] =
319 (
u8)(rcv_pkt >> (j * 8)) & 0xff;
321 (rcv_pkt >> (j * 8)) & 0xff);
331 static unsigned int exynos_mipi_dsi_response_size(
unsigned int req_size)
344 unsigned int data0,
unsigned int req_size,
u8 *rx_buf)
346 unsigned int rx_data, rcv_pkt,
i;
364 response = exynos_mipi_dsi_response_size(req_size);
377 "data id %x is not supported current DSI spec.\n",
385 pr_err(
"RX done interrupt timeout\n");
394 if ((
u8)(rx_data & 0xff) != response) {
396 "mipi dsi wrong response rx_data : %x, response:%x\n",
403 for (i = 0; i < req_size; i++)
404 rx_buf[i] = (rx_data >> (8 + (i * 8))) & 0xff;
408 rxsize = exynos_mipi_dsi_long_data_rd(dsim, req_size, rx_data,
410 if (rxsize != req_size)
420 "Can't found RX FIFO READ DONE FLAG : %x\n", rcv_pkt);
436 "mipi dsi clear rx fifo : %08x\n", rcv_pkt);
440 "mipi dsi rx done count : %d, rcv_pkt : %08x\n", i, rcv_pkt);
469 static unsigned long exynos_mipi_dsi_change_pll(
struct mipi_dsim_device *dsim,
470 unsigned int pre_divider,
unsigned int main_divider,
473 unsigned long dfin_pll, dfvco, dpll_out;
474 unsigned int i, freq_band = 0xf;
476 dfin_pll = (
FIN_HZ / pre_divider);
499 dev_warn(dsim->
dev,
"fin_pll range should be 6MHz ~ 12MHz\n");
502 if (dfin_pll < 7 *
MHZ)
504 else if (dfin_pll < 8 *
MHZ)
506 else if (dfin_pll < 9 *
MHZ)
508 else if (dfin_pll < 10 *
MHZ)
510 else if (dfin_pll < 11 *
MHZ)
516 dfvco = dfin_pll * main_divider;
517 dev_dbg(dsim->
dev,
"dfvco = %lu, dfin_pll = %lu, main_divider = %d\n",
518 dfvco, dfin_pll, main_divider);
520 dev_warn(dsim->
dev,
"fvco range should be 500MHz ~ 1000MHz\n");
522 dpll_out = dfvco / (1 << scaler);
523 dev_dbg(dsim->
dev,
"dpll_out = %lu, dfvco = %lu, scaler = %d\n",
524 dpll_out, dfvco, scaler);
526 for (i = 0; i <
ARRAY_SIZE(dpll_table); i++) {
527 if (dpll_out < dpll_table[i] *
MHZ) {
533 dev_dbg(dsim->
dev,
"freq_band = %d\n", freq_band);
547 dev_dbg(dsim->
dev,
"FOUT of mipi dphy pll is %luMHz\n",
554 unsigned int byte_clk_sel,
unsigned int enable)
556 unsigned int esc_div;
557 unsigned long esc_clk_error_rate;
558 unsigned long hs_clk = 0, byte_clk = 0, escape_clk = 0;
568 hs_clk = exynos_mipi_dsi_change_pll(dsim,
573 "failed to get hs clock.\n");
577 byte_clk = hs_clk / 8;
579 exynos_mipi_dsi_pll_on(dsim, 1);
582 dev_warn(dsim->
dev,
"this project is not support\n");
584 "external clock source for MIPI DSIM.\n");
586 dev_warn(dsim->
dev,
"this project is not support\n");
588 "external clock source for MIPI DSIM\n");
594 "esc_div = %d, byte_clk = %lu, esc_clk = %lu\n",
596 if ((byte_clk / esc_div) >= (20 *
MHZ) ||
597 (byte_clk / esc_div) >
601 escape_clk = byte_clk / esc_div;
603 "escape_clk = %lu, byte_clk = %lu, esc_div = %d\n",
604 escape_clk, byte_clk, esc_div);
617 dev_dbg(dsim->
dev,
"escape clock that user's need is %lu\n",
619 dev_dbg(dsim->
dev,
"escape clock divider is %x\n", esc_div);
620 dev_dbg(dsim->
dev,
"escape clock is %luMHz\n",
621 ((byte_clk / esc_div) /
MHZ));
623 if ((byte_clk / esc_div) > escape_clk) {
624 esc_clk_error_rate = escape_clk /
625 (byte_clk / esc_div);
627 (esc_clk_error_rate / 100));
628 }
else if ((byte_clk / esc_div) < (escape_clk)) {
629 esc_clk_error_rate = (byte_clk / esc_div) /
632 (esc_clk_error_rate / 100));
643 exynos_mipi_dsi_pll_on(dsim, 0);
683 unsigned int src = 0;
741 dev_info(dsim->
dev,
"lcd panel ==> width = %d, height = %d\n",
749 unsigned int time_out = 100;
751 switch (dsim->
state) {
761 exynos_mipi_dsi_set_clock(dsim, dsim->
dsim_config->e_byte_clk, 1);
768 "DSI Master is not stop state.\n");
770 "Check initialization process\n");
777 "DSI Master driver has been completed.\n");
778 dev_info(dsim->
dev,
"DSI Master state is stop state\n");
793 dev_info(dsim->
dev,
"DSI Master is already init.\n");
803 dev_warn(dsim->
dev,
"DSIM is not in stop state.\n");
808 dev_warn(dsim->
dev,
"clock source is external bypass.\n");
827 dev_err(dsim->
dev,
"HS Clock lane is not enabled.\n");
836 "DSI Master is not STOP or HSDT state.\n");
874 dev_err(dsim->
dev,
"failed to clear dsim fifo.\n");