1 /* linux/drivers/video/exynos/exynos_mipi_dsi_common.c
3 * Samsung SoC MIPI-DSI common 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>
23 #include <linux/ctype.h>
24 #include <linux/platform_device.h>
26 #include <linux/memory.h>
27 #include <linux/delay.h>
28 #include <linux/kthread.h>
30 #include <video/mipi_display.h>
31 #include <video/exynos_mipi_dsim.h>
35 #include "exynos_mipi_dsi_regs.h"
36 #include "exynos_mipi_dsi_lowlevel.h"
37 #include "exynos_mipi_dsi_common.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)
54 /* MIPI-DSIM status types. */
56 DSIM_STATE_INIT
, /* should be initialized. */
57 DSIM_STATE_STOP
, /* CPU and LCDC are LP mode. */
58 DSIM_STATE_HSCLKEN
, /* HS clock was enabled. */
62 /* define DSI lane types. */
64 DSIM_LANE_CLOCK
= (1 << 0),
65 DSIM_LANE_DATA0
= (1 << 1),
66 DSIM_LANE_DATA1
= (1 << 2),
67 DSIM_LANE_DATA2
= (1 << 3),
68 DSIM_LANE_DATA3
= (1 << 4)
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
77 irqreturn_t
exynos_mipi_dsi_interrupt_handler(int irq
, void *dev_id
)
79 unsigned int intsrc
= 0;
80 unsigned int intmsk
= 0;
81 struct mipi_dsim_device
*dsim
= NULL
;
85 dev_dbg(dsim
->dev
, KERN_ERR
"%s:error: wrong parameter\n",
90 intsrc
= exynos_mipi_dsi_read_interrupt(dsim
);
91 intmsk
= exynos_mipi_dsi_read_interrupt_mask(dsim
);
93 intmsk
= ~(intmsk
) & intsrc
;
97 complete(&dsim_rd_comp
);
98 dev_dbg(dsim
->dev
, "MIPI INTMSK_RX_DONE\n");
100 case INTMSK_FIFO_EMPTY
:
101 complete(&dsim_wr_comp
);
102 dev_dbg(dsim
->dev
, "MIPI INTMSK_FIFO_EMPTY\n");
108 exynos_mipi_dsi_clear_interrupt(dsim
, intmsk
);
114 * write long packet to mipi dsi slave
115 * @dsim: mipi dsim device structure.
116 * @data0: packet data to send.
117 * @data1: size of packet data
119 static void exynos_mipi_dsi_long_data_wr(struct mipi_dsim_device
*dsim
,
120 const unsigned char *data0
, unsigned int data_size
)
122 unsigned int data_cnt
= 0, payload
= 0;
124 /* in case that data count is more then 4 */
125 for (data_cnt
= 0; data_cnt
< data_size
; data_cnt
+= 4) {
127 * after sending 4bytes per one time,
128 * send remainder data less then 4.
130 if ((data_size
- data_cnt
) < 4) {
131 if ((data_size
- data_cnt
) == 3) {
132 payload
= data0
[data_cnt
] |
133 data0
[data_cnt
+ 1] << 8 |
134 data0
[data_cnt
+ 2] << 16;
135 dev_dbg(dsim
->dev
, "count = 3 payload = %x, %x %x %x\n",
136 payload
, data0
[data_cnt
],
138 data0
[data_cnt
+ 2]);
139 } else if ((data_size
- data_cnt
) == 2) {
140 payload
= data0
[data_cnt
] |
141 data0
[data_cnt
+ 1] << 8;
143 "count = 2 payload = %x, %x %x\n", payload
,
145 data0
[data_cnt
+ 1]);
146 } else if ((data_size
- data_cnt
) == 1) {
147 payload
= data0
[data_cnt
];
150 exynos_mipi_dsi_wr_tx_data(dsim
, payload
);
151 /* send 4bytes per one time. */
153 payload
= data0
[data_cnt
] |
154 data0
[data_cnt
+ 1] << 8 |
155 data0
[data_cnt
+ 2] << 16 |
156 data0
[data_cnt
+ 3] << 24;
159 "count = 4 payload = %x, %x %x %x %x\n",
160 payload
, *(u8
*)(data0
+ data_cnt
),
163 data0
[data_cnt
+ 3]);
165 exynos_mipi_dsi_wr_tx_data(dsim
, payload
);
170 int exynos_mipi_dsi_wr_data(struct mipi_dsim_device
*dsim
, unsigned int data_id
,
171 const unsigned char *data0
, unsigned int data_size
)
173 unsigned int check_rx_ack
= 0;
175 if (dsim
->state
== DSIM_STATE_ULPS
) {
176 dev_err(dsim
->dev
, "state is ULPS.\n");
181 /* FIXME!!! why does it need this delay? */
184 mutex_lock(&dsim
->lock
);
187 /* short packet types of packet types for command. */
188 case MIPI_DSI_GENERIC_SHORT_WRITE_0_PARAM
:
189 case MIPI_DSI_GENERIC_SHORT_WRITE_1_PARAM
:
190 case MIPI_DSI_GENERIC_SHORT_WRITE_2_PARAM
:
191 case MIPI_DSI_DCS_SHORT_WRITE
:
192 case MIPI_DSI_DCS_SHORT_WRITE_PARAM
:
193 case MIPI_DSI_SET_MAXIMUM_RETURN_PACKET_SIZE
:
194 exynos_mipi_dsi_wr_tx_header(dsim
, data_id
, data0
[0], data0
[1]);
196 /* process response func should be implemented */
197 mutex_unlock(&dsim
->lock
);
200 mutex_unlock(&dsim
->lock
);
204 /* general command */
205 case MIPI_DSI_COLOR_MODE_OFF
:
206 case MIPI_DSI_COLOR_MODE_ON
:
207 case MIPI_DSI_SHUTDOWN_PERIPHERAL
:
208 case MIPI_DSI_TURN_ON_PERIPHERAL
:
209 exynos_mipi_dsi_wr_tx_header(dsim
, data_id
, data0
[0], data0
[1]);
211 /* process response func should be implemented. */
212 mutex_unlock(&dsim
->lock
);
215 mutex_unlock(&dsim
->lock
);
219 /* packet types for video data */
220 case MIPI_DSI_V_SYNC_START
:
221 case MIPI_DSI_V_SYNC_END
:
222 case MIPI_DSI_H_SYNC_START
:
223 case MIPI_DSI_H_SYNC_END
:
224 case MIPI_DSI_END_OF_TRANSMISSION
:
225 mutex_unlock(&dsim
->lock
);
228 /* long packet type and null packet */
229 case MIPI_DSI_NULL_PACKET
:
230 case MIPI_DSI_BLANKING_PACKET
:
231 mutex_unlock(&dsim
->lock
);
233 case MIPI_DSI_GENERIC_LONG_WRITE
:
234 case MIPI_DSI_DCS_LONG_WRITE
:
236 unsigned int size
, payload
= 0;
237 INIT_COMPLETION(dsim_wr_comp
);
239 size
= data_size
* 4;
241 /* if data count is less then 4, then send 3bytes data. */
247 exynos_mipi_dsi_wr_tx_data(dsim
, payload
);
249 dev_dbg(dsim
->dev
, "count = %d payload = %x,%x %x %x\n",
250 data_size
, payload
, data0
[0],
253 /* in case that data count is more then 4 */
255 exynos_mipi_dsi_long_data_wr(dsim
, data0
, data_size
);
257 /* put data into header fifo */
258 exynos_mipi_dsi_wr_tx_header(dsim
, data_id
, data_size
& 0xff,
259 (data_size
& 0xff00) >> 8);
261 if (!wait_for_completion_interruptible_timeout(&dsim_wr_comp
,
262 MIPI_FIFO_TIMEOUT
)) {
263 dev_warn(dsim
->dev
, "command write timeout.\n");
264 mutex_unlock(&dsim
->lock
);
269 /* process response func should be implemented. */
270 mutex_unlock(&dsim
->lock
);
273 mutex_unlock(&dsim
->lock
);
278 /* packet typo for video data */
279 case MIPI_DSI_PACKED_PIXEL_STREAM_16
:
280 case MIPI_DSI_PACKED_PIXEL_STREAM_18
:
281 case MIPI_DSI_PIXEL_STREAM_3BYTE_18
:
282 case MIPI_DSI_PACKED_PIXEL_STREAM_24
:
284 /* process response func should be implemented. */
285 mutex_unlock(&dsim
->lock
);
288 mutex_unlock(&dsim
->lock
);
293 "data id %x is not supported current DSI spec.\n",
296 mutex_unlock(&dsim
->lock
);
300 mutex_unlock(&dsim
->lock
);
304 static unsigned int exynos_mipi_dsi_long_data_rd(struct mipi_dsim_device
*dsim
,
305 unsigned int req_size
, unsigned int rx_data
, u8
*rx_buf
)
307 unsigned int rcv_pkt
, i
, j
;
310 /* for long packet */
311 rxsize
= (u16
)((rx_data
& 0x00ffff00) >> 8);
312 dev_dbg(dsim
->dev
, "mipi dsi rx size : %d\n", rxsize
);
313 if (rxsize
!= req_size
) {
315 "received size mismatch received: %d, requested: %d\n",
320 for (i
= 0; i
< (rxsize
>> 2); i
++) {
321 rcv_pkt
= exynos_mipi_dsi_rd_rx_fifo(dsim
);
322 dev_dbg(dsim
->dev
, "received pkt : %08x\n", rcv_pkt
);
323 for (j
= 0; j
< 4; j
++) {
324 rx_buf
[(i
* 4) + j
] =
325 (u8
)(rcv_pkt
>> (j
* 8)) & 0xff;
326 dev_dbg(dsim
->dev
, "received value : %02x\n",
327 (rcv_pkt
>> (j
* 8)) & 0xff);
331 rcv_pkt
= exynos_mipi_dsi_rd_rx_fifo(dsim
);
332 dev_dbg(dsim
->dev
, "received pkt : %08x\n", rcv_pkt
);
333 for (j
= 0; j
< (rxsize
% 4); j
++) {
334 rx_buf
[(i
* 4) + j
] =
335 (u8
)(rcv_pkt
>> (j
* 8)) & 0xff;
336 dev_dbg(dsim
->dev
, "received value : %02x\n",
337 (rcv_pkt
>> (j
* 8)) & 0xff);
347 static unsigned int exynos_mipi_dsi_response_size(unsigned int req_size
)
351 return MIPI_DSI_RX_GENERIC_SHORT_READ_RESPONSE_1BYTE
;
353 return MIPI_DSI_RX_GENERIC_SHORT_READ_RESPONSE_2BYTE
;
355 return MIPI_DSI_RX_GENERIC_LONG_READ_RESPONSE
;
359 int exynos_mipi_dsi_rd_data(struct mipi_dsim_device
*dsim
, unsigned int data_id
,
360 unsigned int data0
, unsigned int req_size
, u8
*rx_buf
)
362 unsigned int rx_data
, rcv_pkt
, i
;
366 if (dsim
->state
== DSIM_STATE_ULPS
) {
367 dev_err(dsim
->dev
, "state is ULPS.\n");
375 mutex_lock(&dsim
->lock
);
376 INIT_COMPLETION(dsim_rd_comp
);
377 exynos_mipi_dsi_rd_tx_header(dsim
,
378 MIPI_DSI_SET_MAXIMUM_RETURN_PACKET_SIZE
, req_size
);
380 response
= exynos_mipi_dsi_response_size(req_size
);
383 case MIPI_DSI_GENERIC_READ_REQUEST_0_PARAM
:
384 case MIPI_DSI_GENERIC_READ_REQUEST_1_PARAM
:
385 case MIPI_DSI_GENERIC_READ_REQUEST_2_PARAM
:
386 case MIPI_DSI_DCS_READ
:
387 exynos_mipi_dsi_rd_tx_header(dsim
,
389 /* process response func should be implemented. */
393 "data id %x is not supported current DSI spec.\n",
399 if (!wait_for_completion_interruptible_timeout(&dsim_rd_comp
,
400 MIPI_FIFO_TIMEOUT
)) {
401 pr_err("RX done interrupt timeout\n");
402 mutex_unlock(&dsim
->lock
);
408 rx_data
= exynos_mipi_dsi_rd_rx_fifo(dsim
);
410 if ((u8
)(rx_data
& 0xff) != response
) {
412 "mipi dsi wrong response rx_data : %x, response:%x\n",
418 /* for short packet */
419 for (i
= 0; i
< req_size
; i
++)
420 rx_buf
[i
] = (rx_data
>> (8 + (i
* 8))) & 0xff;
423 /* for long packet */
424 rxsize
= exynos_mipi_dsi_long_data_rd(dsim
, req_size
, rx_data
,
426 if (rxsize
!= req_size
)
430 rcv_pkt
= exynos_mipi_dsi_rd_rx_fifo(dsim
);
434 if (rcv_pkt
!= MIPI_RX_FIFO_READ_DONE
) {
436 "Can't found RX FIFO READ DONE FLAG : %x\n", rcv_pkt
);
440 mutex_unlock(&dsim
->lock
);
447 rcv_pkt
= exynos_mipi_dsi_rd_rx_fifo(dsim
);
448 if ((rcv_pkt
== MIPI_RX_FIFO_READ_DONE
)
449 || (i
> MIPI_MAX_RX_FIFO
))
452 "mipi dsi clear rx fifo : %08x\n", rcv_pkt
);
456 "mipi dsi rx done count : %d, rcv_pkt : %08x\n", i
, rcv_pkt
);
458 mutex_unlock(&dsim
->lock
);
463 static int exynos_mipi_dsi_pll_on(struct mipi_dsim_device
*dsim
,
471 exynos_mipi_dsi_enable_pll(dsim
, 1);
474 if (exynos_mipi_dsi_is_pll_stable(dsim
))
480 exynos_mipi_dsi_enable_pll(dsim
, 0);
485 static unsigned long exynos_mipi_dsi_change_pll(struct mipi_dsim_device
*dsim
,
486 unsigned int pre_divider
, unsigned int main_divider
,
489 unsigned long dfin_pll
, dfvco
, dpll_out
;
490 unsigned int i
, freq_band
= 0xf;
492 dfin_pll
= (FIN_HZ
/ pre_divider
);
494 /******************************************************
495 * Serial Clock(=ByteClk X 8) FreqBand[3:0] *
496 ******************************************************
498 * 100 ~ 119.99 MHz 0001
499 * 120 ~ 159.99 MHz 0010
500 * 160 ~ 199.99 MHz 0011
501 * 200 ~ 239.99 MHz 0100
502 * 140 ~ 319.99 MHz 0101
503 * 320 ~ 389.99 MHz 0110
504 * 390 ~ 449.99 MHz 0111
505 * 450 ~ 509.99 MHz 1000
506 * 510 ~ 559.99 MHz 1001
507 * 560 ~ 639.99 MHz 1010
508 * 640 ~ 689.99 MHz 1011
509 * 690 ~ 769.99 MHz 1100
510 * 770 ~ 869.99 MHz 1101
511 * 870 ~ 949.99 MHz 1110
512 * 950 ~ 1000 MHz 1111
513 ******************************************************/
514 if (dfin_pll
< DFIN_PLL_MIN_HZ
|| dfin_pll
> DFIN_PLL_MAX_HZ
) {
515 dev_warn(dsim
->dev
, "fin_pll range should be 6MHz ~ 12MHz\n");
516 exynos_mipi_dsi_enable_afc(dsim
, 0, 0);
518 if (dfin_pll
< 7 * MHZ
)
519 exynos_mipi_dsi_enable_afc(dsim
, 1, 0x1);
520 else if (dfin_pll
< 8 * MHZ
)
521 exynos_mipi_dsi_enable_afc(dsim
, 1, 0x0);
522 else if (dfin_pll
< 9 * MHZ
)
523 exynos_mipi_dsi_enable_afc(dsim
, 1, 0x3);
524 else if (dfin_pll
< 10 * MHZ
)
525 exynos_mipi_dsi_enable_afc(dsim
, 1, 0x2);
526 else if (dfin_pll
< 11 * MHZ
)
527 exynos_mipi_dsi_enable_afc(dsim
, 1, 0x5);
529 exynos_mipi_dsi_enable_afc(dsim
, 1, 0x4);
532 dfvco
= dfin_pll
* main_divider
;
533 dev_dbg(dsim
->dev
, "dfvco = %lu, dfin_pll = %lu, main_divider = %d\n",
534 dfvco
, dfin_pll
, main_divider
);
535 if (dfvco
< DFVCO_MIN_HZ
|| dfvco
> DFVCO_MAX_HZ
)
536 dev_warn(dsim
->dev
, "fvco range should be 500MHz ~ 1000MHz\n");
538 dpll_out
= dfvco
/ (1 << scaler
);
539 dev_dbg(dsim
->dev
, "dpll_out = %lu, dfvco = %lu, scaler = %d\n",
540 dpll_out
, dfvco
, scaler
);
542 for (i
= 0; i
< ARRAY_SIZE(dpll_table
); i
++) {
543 if (dpll_out
< dpll_table
[i
] * MHZ
) {
549 dev_dbg(dsim
->dev
, "freq_band = %d\n", freq_band
);
551 exynos_mipi_dsi_pll_freq(dsim
, pre_divider
, main_divider
, scaler
);
553 exynos_mipi_dsi_hs_zero_ctrl(dsim
, 0);
554 exynos_mipi_dsi_prep_ctrl(dsim
, 0);
557 exynos_mipi_dsi_pll_freq_band(dsim
, freq_band
);
560 exynos_mipi_dsi_pll_stable_time(dsim
, dsim
->dsim_config
->pll_stable_time
);
563 dev_dbg(dsim
->dev
, "FOUT of mipi dphy pll is %luMHz\n",
569 static int exynos_mipi_dsi_set_clock(struct mipi_dsim_device
*dsim
,
570 unsigned int byte_clk_sel
, unsigned int enable
)
572 unsigned int esc_div
;
573 unsigned long esc_clk_error_rate
;
574 unsigned long hs_clk
= 0, byte_clk
= 0, escape_clk
= 0;
577 dsim
->e_clk_src
= byte_clk_sel
;
579 /* Escape mode clock and byte clock source */
580 exynos_mipi_dsi_set_byte_clock_src(dsim
, byte_clk_sel
);
582 /* DPHY, DSIM Link : D-PHY clock out */
583 if (byte_clk_sel
== DSIM_PLL_OUT_DIV8
) {
584 hs_clk
= exynos_mipi_dsi_change_pll(dsim
,
585 dsim
->dsim_config
->p
, dsim
->dsim_config
->m
,
586 dsim
->dsim_config
->s
);
589 "failed to get hs clock.\n");
593 byte_clk
= hs_clk
/ 8;
594 exynos_mipi_dsi_enable_pll_bypass(dsim
, 0);
595 exynos_mipi_dsi_pll_on(dsim
, 1);
596 /* DPHY : D-PHY clock out, DSIM link : external clock out */
597 } else if (byte_clk_sel
== DSIM_EXT_CLK_DIV8
) {
598 dev_warn(dsim
->dev
, "this project is not support\n");
600 "external clock source for MIPI DSIM.\n");
601 } else if (byte_clk_sel
== DSIM_EXT_CLK_BYPASS
) {
602 dev_warn(dsim
->dev
, "this project is not support\n");
604 "external clock source for MIPI DSIM\n");
607 /* escape clock divider */
608 esc_div
= byte_clk
/ (dsim
->dsim_config
->esc_clk
);
610 "esc_div = %d, byte_clk = %lu, esc_clk = %lu\n",
611 esc_div
, byte_clk
, dsim
->dsim_config
->esc_clk
);
612 if ((byte_clk
/ esc_div
) >= (20 * MHZ
) ||
613 (byte_clk
/ esc_div
) >
614 dsim
->dsim_config
->esc_clk
)
617 escape_clk
= byte_clk
/ esc_div
;
619 "escape_clk = %lu, byte_clk = %lu, esc_div = %d\n",
620 escape_clk
, byte_clk
, esc_div
);
622 /* enable escape clock. */
623 exynos_mipi_dsi_enable_byte_clock(dsim
, 1);
625 /* enable byte clk and escape clock */
626 exynos_mipi_dsi_set_esc_clk_prs(dsim
, 1, esc_div
);
627 /* escape clock on lane */
628 exynos_mipi_dsi_enable_esc_clk_on_lane(dsim
,
629 (DSIM_LANE_CLOCK
| dsim
->data_lane
), 1);
631 dev_dbg(dsim
->dev
, "byte clock is %luMHz\n",
633 dev_dbg(dsim
->dev
, "escape clock that user's need is %lu\n",
634 (dsim
->dsim_config
->esc_clk
/ MHZ
));
635 dev_dbg(dsim
->dev
, "escape clock divider is %x\n", esc_div
);
636 dev_dbg(dsim
->dev
, "escape clock is %luMHz\n",
637 ((byte_clk
/ esc_div
) / MHZ
));
639 if ((byte_clk
/ esc_div
) > escape_clk
) {
640 esc_clk_error_rate
= escape_clk
/
641 (byte_clk
/ esc_div
);
642 dev_warn(dsim
->dev
, "error rate is %lu over.\n",
643 (esc_clk_error_rate
/ 100));
644 } else if ((byte_clk
/ esc_div
) < (escape_clk
)) {
645 esc_clk_error_rate
= (byte_clk
/ esc_div
) /
647 dev_warn(dsim
->dev
, "error rate is %lu under.\n",
648 (esc_clk_error_rate
/ 100));
651 exynos_mipi_dsi_enable_esc_clk_on_lane(dsim
,
652 (DSIM_LANE_CLOCK
| dsim
->data_lane
), 0);
653 exynos_mipi_dsi_set_esc_clk_prs(dsim
, 0, 0);
655 /* disable escape clock. */
656 exynos_mipi_dsi_enable_byte_clock(dsim
, 0);
658 if (byte_clk_sel
== DSIM_PLL_OUT_DIV8
)
659 exynos_mipi_dsi_pll_on(dsim
, 0);
665 int exynos_mipi_dsi_init_dsim(struct mipi_dsim_device
*dsim
)
667 dsim
->state
= DSIM_STATE_INIT
;
669 switch (dsim
->dsim_config
->e_no_data_lane
) {
670 case DSIM_DATA_LANE_1
:
671 dsim
->data_lane
= DSIM_LANE_DATA0
;
673 case DSIM_DATA_LANE_2
:
674 dsim
->data_lane
= DSIM_LANE_DATA0
| DSIM_LANE_DATA1
;
676 case DSIM_DATA_LANE_3
:
677 dsim
->data_lane
= DSIM_LANE_DATA0
| DSIM_LANE_DATA1
|
680 case DSIM_DATA_LANE_4
:
681 dsim
->data_lane
= DSIM_LANE_DATA0
| DSIM_LANE_DATA1
|
682 DSIM_LANE_DATA2
| DSIM_LANE_DATA3
;
685 dev_info(dsim
->dev
, "data lane is invalid.\n");
689 exynos_mipi_dsi_sw_reset(dsim
);
690 exynos_mipi_dsi_func_reset(dsim
);
692 exynos_mipi_dsi_dp_dn_swap(dsim
, 0);
697 void exynos_mipi_dsi_init_interrupt(struct mipi_dsim_device
*dsim
)
699 unsigned int src
= 0;
701 src
= (INTSRC_SFR_FIFO_EMPTY
| INTSRC_RX_DATA_DONE
);
702 exynos_mipi_dsi_set_interrupt(dsim
, src
, 1);
705 src
= ~(INTMSK_RX_DONE
| INTMSK_FIFO_EMPTY
);
706 exynos_mipi_dsi_set_interrupt_mask(dsim
, src
, 1);
709 int exynos_mipi_dsi_enable_frame_done_int(struct mipi_dsim_device
*dsim
,
712 /* enable only frame done interrupt */
713 exynos_mipi_dsi_set_interrupt_mask(dsim
, INTMSK_FRAME_DONE
, enable
);
718 void exynos_mipi_dsi_stand_by(struct mipi_dsim_device
*dsim
,
722 /* consider Main display and Sub display. */
724 exynos_mipi_dsi_set_main_stand_by(dsim
, enable
);
727 int exynos_mipi_dsi_set_display_mode(struct mipi_dsim_device
*dsim
,
728 struct mipi_dsim_config
*dsim_config
)
730 struct mipi_dsim_platform_data
*dsim_pd
;
731 struct fb_videomode
*timing
;
733 dsim_pd
= (struct mipi_dsim_platform_data
*)dsim
->pd
;
734 timing
= (struct fb_videomode
*)dsim_pd
->lcd_panel_info
;
736 /* in case of VIDEO MODE (RGB INTERFACE), it sets polarities. */
737 if (dsim_config
->e_interface
== (u32
) DSIM_VIDEO
) {
738 if (dsim_config
->auto_vertical_cnt
== 0) {
739 exynos_mipi_dsi_set_main_disp_vporch(dsim
,
740 dsim_config
->cmd_allow
,
741 timing
->upper_margin
,
742 timing
->lower_margin
);
743 exynos_mipi_dsi_set_main_disp_hporch(dsim
,
745 timing
->right_margin
);
746 exynos_mipi_dsi_set_main_disp_sync_area(dsim
,
752 exynos_mipi_dsi_set_main_disp_resol(dsim
, timing
->xres
,
755 exynos_mipi_dsi_display_config(dsim
, dsim_config
);
757 dev_info(dsim
->dev
, "lcd panel ==> width = %d, height = %d\n",
758 timing
->xres
, timing
->yres
);
763 int exynos_mipi_dsi_init_link(struct mipi_dsim_device
*dsim
)
765 unsigned int time_out
= 100;
767 switch (dsim
->state
) {
768 case DSIM_STATE_INIT
:
769 exynos_mipi_dsi_init_fifo_pointer(dsim
, 0x1f);
771 /* dsi configuration */
772 exynos_mipi_dsi_init_config(dsim
);
773 exynos_mipi_dsi_enable_lane(dsim
, DSIM_LANE_CLOCK
, 1);
774 exynos_mipi_dsi_enable_lane(dsim
, dsim
->data_lane
, 1);
776 /* set clock configuration */
777 exynos_mipi_dsi_set_clock(dsim
, dsim
->dsim_config
->e_byte_clk
, 1);
779 /* check clock and data lane state are stop state */
780 while (!(exynos_mipi_dsi_is_lane_state(dsim
))) {
784 "DSI Master is not stop state.\n");
786 "Check initialization process\n");
793 "DSI Master driver has been completed.\n");
794 dev_info(dsim
->dev
, "DSI Master state is stop state\n");
797 dsim
->state
= DSIM_STATE_STOP
;
799 /* BTA sequence counters */
800 exynos_mipi_dsi_set_stop_state_counter(dsim
,
801 dsim
->dsim_config
->stop_holding_cnt
);
802 exynos_mipi_dsi_set_bta_timeout(dsim
,
803 dsim
->dsim_config
->bta_timeout
);
804 exynos_mipi_dsi_set_lpdr_timeout(dsim
,
805 dsim
->dsim_config
->rx_timeout
);
809 dev_info(dsim
->dev
, "DSI Master is already init.\n");
816 int exynos_mipi_dsi_set_hs_enable(struct mipi_dsim_device
*dsim
)
818 if (dsim
->state
!= DSIM_STATE_STOP
) {
819 dev_warn(dsim
->dev
, "DSIM is not in stop state.\n");
823 if (dsim
->e_clk_src
== DSIM_EXT_CLK_BYPASS
) {
824 dev_warn(dsim
->dev
, "clock source is external bypass.\n");
828 dsim
->state
= DSIM_STATE_HSCLKEN
;
830 /* set LCDC and CPU transfer mode to HS. */
831 exynos_mipi_dsi_set_lcdc_transfer_mode(dsim
, 0);
832 exynos_mipi_dsi_set_cpu_transfer_mode(dsim
, 0);
833 exynos_mipi_dsi_enable_hs_clock(dsim
, 1);
838 int exynos_mipi_dsi_set_data_transfer_mode(struct mipi_dsim_device
*dsim
,
842 if (dsim
->state
!= DSIM_STATE_HSCLKEN
) {
843 dev_err(dsim
->dev
, "HS Clock lane is not enabled.\n");
847 exynos_mipi_dsi_set_lcdc_transfer_mode(dsim
, 0);
849 if (dsim
->state
== DSIM_STATE_INIT
|| dsim
->state
==
852 "DSI Master is not STOP or HSDT state.\n");
856 exynos_mipi_dsi_set_cpu_transfer_mode(dsim
, 0);
862 int exynos_mipi_dsi_get_frame_done_status(struct mipi_dsim_device
*dsim
)
864 return _exynos_mipi_dsi_get_frame_done_status(dsim
);
867 int exynos_mipi_dsi_clear_frame_done(struct mipi_dsim_device
*dsim
)
869 _exynos_mipi_dsi_clear_frame_done(dsim
);
874 int exynos_mipi_dsi_fifo_clear(struct mipi_dsim_device
*dsim
,
877 int try = TRY_FIFO_CLEAR
;
879 exynos_mipi_dsi_sw_reset_release(dsim
);
880 exynos_mipi_dsi_func_reset(dsim
);
883 if (exynos_mipi_dsi_get_sw_reset_release(dsim
)) {
884 exynos_mipi_dsi_init_interrupt(dsim
);
885 dev_dbg(dsim
->dev
, "reset release done.\n");
890 dev_err(dsim
->dev
, "failed to clear dsim fifo.\n");
894 MODULE_AUTHOR("InKi Dae <inki.dae@samsung.com>");
895 MODULE_DESCRIPTION("Samusung SoC MIPI-DSI common driver");
896 MODULE_LICENSE("GPL");