2 * Samsung SoC MIPI DSI Master driver.
4 * Copyright (c) 2014 Samsung Electronics Co., Ltd
6 * Contacts: Tomasz Figa <t.figa@samsung.com>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
14 #include <drm/drm_crtc_helper.h>
15 #include <drm/drm_mipi_dsi.h>
16 #include <drm/drm_panel.h>
18 #include <linux/clk.h>
19 #include <linux/gpio/consumer.h>
20 #include <linux/irq.h>
21 #include <linux/of_gpio.h>
22 #include <linux/phy/phy.h>
23 #include <linux/regulator/consumer.h>
24 #include <linux/component.h>
26 #include <video/mipi_display.h>
27 #include <video/videomode.h>
29 #include "exynos_drm_crtc.h"
30 #include "exynos_drm_drv.h"
32 /* returns true iff both arguments logically differs */
33 #define NEQV(a, b) (!(a) ^ !(b))
35 #define DSIM_STATUS_REG 0x0 /* Status register */
36 #define DSIM_SWRST_REG 0x4 /* Software reset register */
37 #define DSIM_CLKCTRL_REG 0x8 /* Clock control register */
38 #define DSIM_TIMEOUT_REG 0xc /* Time out register */
39 #define DSIM_CONFIG_REG 0x10 /* Configuration register */
40 #define DSIM_ESCMODE_REG 0x14 /* Escape mode register */
42 /* Main display image resolution register */
43 #define DSIM_MDRESOL_REG 0x18
44 #define DSIM_MVPORCH_REG 0x1c /* Main display Vporch register */
45 #define DSIM_MHPORCH_REG 0x20 /* Main display Hporch register */
46 #define DSIM_MSYNC_REG 0x24 /* Main display sync area register */
48 /* Sub display image resolution register */
49 #define DSIM_SDRESOL_REG 0x28
50 #define DSIM_INTSRC_REG 0x2c /* Interrupt source register */
51 #define DSIM_INTMSK_REG 0x30 /* Interrupt mask register */
52 #define DSIM_PKTHDR_REG 0x34 /* Packet Header FIFO register */
53 #define DSIM_PAYLOAD_REG 0x38 /* Payload FIFO register */
54 #define DSIM_RXFIFO_REG 0x3c /* Read FIFO register */
55 #define DSIM_FIFOTHLD_REG 0x40 /* FIFO threshold level register */
56 #define DSIM_FIFOCTRL_REG 0x44 /* FIFO status and control register */
58 /* FIFO memory AC characteristic register */
59 #define DSIM_PLLCTRL_REG 0x4c /* PLL control register */
60 #define DSIM_PLLTMR_REG 0x50 /* PLL timer register */
61 #define DSIM_PHYACCHR_REG 0x54 /* D-PHY AC characteristic register */
62 #define DSIM_PHYACCHR1_REG 0x58 /* D-PHY AC characteristic register1 */
65 #define DSIM_STOP_STATE_DAT(x) (((x) & 0xf) << 0)
66 #define DSIM_STOP_STATE_CLK (1 << 8)
67 #define DSIM_TX_READY_HS_CLK (1 << 10)
68 #define DSIM_PLL_STABLE (1 << 31)
71 #define DSIM_FUNCRST (1 << 16)
72 #define DSIM_SWRST (1 << 0)
75 #define DSIM_LPDR_TIMEOUT(x) ((x) << 0)
76 #define DSIM_BTA_TIMEOUT(x) ((x) << 16)
79 #define DSIM_ESC_PRESCALER(x) (((x) & 0xffff) << 0)
80 #define DSIM_ESC_PRESCALER_MASK (0xffff << 0)
81 #define DSIM_LANE_ESC_CLK_EN_CLK (1 << 19)
82 #define DSIM_LANE_ESC_CLK_EN_DATA(x) (((x) & 0xf) << 20)
83 #define DSIM_LANE_ESC_CLK_EN_DATA_MASK (0xf << 20)
84 #define DSIM_BYTE_CLKEN (1 << 24)
85 #define DSIM_BYTE_CLK_SRC(x) (((x) & 0x3) << 25)
86 #define DSIM_BYTE_CLK_SRC_MASK (0x3 << 25)
87 #define DSIM_PLL_BYPASS (1 << 27)
88 #define DSIM_ESC_CLKEN (1 << 28)
89 #define DSIM_TX_REQUEST_HSCLK (1 << 31)
92 #define DSIM_LANE_EN_CLK (1 << 0)
93 #define DSIM_LANE_EN(x) (((x) & 0xf) << 1)
94 #define DSIM_NUM_OF_DATA_LANE(x) (((x) & 0x3) << 5)
95 #define DSIM_SUB_PIX_FORMAT(x) (((x) & 0x7) << 8)
96 #define DSIM_MAIN_PIX_FORMAT_MASK (0x7 << 12)
97 #define DSIM_MAIN_PIX_FORMAT_RGB888 (0x7 << 12)
98 #define DSIM_MAIN_PIX_FORMAT_RGB666 (0x6 << 12)
99 #define DSIM_MAIN_PIX_FORMAT_RGB666_P (0x5 << 12)
100 #define DSIM_MAIN_PIX_FORMAT_RGB565 (0x4 << 12)
101 #define DSIM_SUB_VC (((x) & 0x3) << 16)
102 #define DSIM_MAIN_VC (((x) & 0x3) << 18)
103 #define DSIM_HSA_MODE (1 << 20)
104 #define DSIM_HBP_MODE (1 << 21)
105 #define DSIM_HFP_MODE (1 << 22)
106 #define DSIM_HSE_MODE (1 << 23)
107 #define DSIM_AUTO_MODE (1 << 24)
108 #define DSIM_VIDEO_MODE (1 << 25)
109 #define DSIM_BURST_MODE (1 << 26)
110 #define DSIM_SYNC_INFORM (1 << 27)
111 #define DSIM_EOT_DISABLE (1 << 28)
112 #define DSIM_MFLUSH_VS (1 << 29)
115 #define DSIM_TX_TRIGGER_RST (1 << 4)
116 #define DSIM_TX_LPDT_LP (1 << 6)
117 #define DSIM_CMD_LPDT_LP (1 << 7)
118 #define DSIM_FORCE_BTA (1 << 16)
119 #define DSIM_FORCE_STOP_STATE (1 << 20)
120 #define DSIM_STOP_STATE_CNT(x) (((x) & 0x7ff) << 21)
121 #define DSIM_STOP_STATE_CNT_MASK (0x7ff << 21)
124 #define DSIM_MAIN_STAND_BY (1 << 31)
125 #define DSIM_MAIN_VRESOL(x) (((x) & 0x7ff) << 16)
126 #define DSIM_MAIN_HRESOL(x) (((x) & 0X7ff) << 0)
129 #define DSIM_CMD_ALLOW(x) ((x) << 28)
130 #define DSIM_STABLE_VFP(x) ((x) << 16)
131 #define DSIM_MAIN_VBP(x) ((x) << 0)
132 #define DSIM_CMD_ALLOW_MASK (0xf << 28)
133 #define DSIM_STABLE_VFP_MASK (0x7ff << 16)
134 #define DSIM_MAIN_VBP_MASK (0x7ff << 0)
137 #define DSIM_MAIN_HFP(x) ((x) << 16)
138 #define DSIM_MAIN_HBP(x) ((x) << 0)
139 #define DSIM_MAIN_HFP_MASK ((0xffff) << 16)
140 #define DSIM_MAIN_HBP_MASK ((0xffff) << 0)
143 #define DSIM_MAIN_VSA(x) ((x) << 22)
144 #define DSIM_MAIN_HSA(x) ((x) << 0)
145 #define DSIM_MAIN_VSA_MASK ((0x3ff) << 22)
146 #define DSIM_MAIN_HSA_MASK ((0xffff) << 0)
149 #define DSIM_SUB_STANDY(x) ((x) << 31)
150 #define DSIM_SUB_VRESOL(x) ((x) << 16)
151 #define DSIM_SUB_HRESOL(x) ((x) << 0)
152 #define DSIM_SUB_STANDY_MASK ((0x1) << 31)
153 #define DSIM_SUB_VRESOL_MASK ((0x7ff) << 16)
154 #define DSIM_SUB_HRESOL_MASK ((0x7ff) << 0)
157 #define DSIM_INT_PLL_STABLE (1 << 31)
158 #define DSIM_INT_SW_RST_RELEASE (1 << 30)
159 #define DSIM_INT_SFR_FIFO_EMPTY (1 << 29)
160 #define DSIM_INT_BTA (1 << 25)
161 #define DSIM_INT_FRAME_DONE (1 << 24)
162 #define DSIM_INT_RX_TIMEOUT (1 << 21)
163 #define DSIM_INT_BTA_TIMEOUT (1 << 20)
164 #define DSIM_INT_RX_DONE (1 << 18)
165 #define DSIM_INT_RX_TE (1 << 17)
166 #define DSIM_INT_RX_ACK (1 << 16)
167 #define DSIM_INT_RX_ECC_ERR (1 << 15)
168 #define DSIM_INT_RX_CRC_ERR (1 << 14)
171 #define DSIM_RX_DATA_FULL (1 << 25)
172 #define DSIM_RX_DATA_EMPTY (1 << 24)
173 #define DSIM_SFR_HEADER_FULL (1 << 23)
174 #define DSIM_SFR_HEADER_EMPTY (1 << 22)
175 #define DSIM_SFR_PAYLOAD_FULL (1 << 21)
176 #define DSIM_SFR_PAYLOAD_EMPTY (1 << 20)
177 #define DSIM_I80_HEADER_FULL (1 << 19)
178 #define DSIM_I80_HEADER_EMPTY (1 << 18)
179 #define DSIM_I80_PAYLOAD_FULL (1 << 17)
180 #define DSIM_I80_PAYLOAD_EMPTY (1 << 16)
181 #define DSIM_SD_HEADER_FULL (1 << 15)
182 #define DSIM_SD_HEADER_EMPTY (1 << 14)
183 #define DSIM_SD_PAYLOAD_FULL (1 << 13)
184 #define DSIM_SD_PAYLOAD_EMPTY (1 << 12)
185 #define DSIM_MD_HEADER_FULL (1 << 11)
186 #define DSIM_MD_HEADER_EMPTY (1 << 10)
187 #define DSIM_MD_PAYLOAD_FULL (1 << 9)
188 #define DSIM_MD_PAYLOAD_EMPTY (1 << 8)
189 #define DSIM_RX_FIFO (1 << 4)
190 #define DSIM_SFR_FIFO (1 << 3)
191 #define DSIM_I80_FIFO (1 << 2)
192 #define DSIM_SD_FIFO (1 << 1)
193 #define DSIM_MD_FIFO (1 << 0)
196 #define DSIM_AFC_EN (1 << 14)
197 #define DSIM_AFC_CTL(x) (((x) & 0x7) << 5)
200 #define DSIM_FREQ_BAND(x) ((x) << 24)
201 #define DSIM_PLL_EN (1 << 23)
202 #define DSIM_PLL_P(x) ((x) << 13)
203 #define DSIM_PLL_M(x) ((x) << 4)
204 #define DSIM_PLL_S(x) ((x) << 1)
206 #define DSI_MAX_BUS_WIDTH 4
207 #define DSI_NUM_VIRTUAL_CHANNELS 4
208 #define DSI_TX_FIFO_SIZE 2048
209 #define DSI_RX_FIFO_SIZE 256
210 #define DSI_XFER_TIMEOUT_MS 100
211 #define DSI_RX_FIFO_EMPTY 0x30800002
213 enum exynos_dsi_transfer_type {
218 struct exynos_dsi_transfer {
219 struct list_head list;
220 struct completion completed;
226 const u8 *tx_payload;
235 #define DSIM_STATE_ENABLED BIT(0)
236 #define DSIM_STATE_INITIALIZED BIT(1)
237 #define DSIM_STATE_CMD_LPM BIT(2)
240 struct mipi_dsi_host dsi_host;
241 struct drm_connector connector;
242 struct drm_encoder *encoder;
243 struct device_node *panel_node;
244 struct drm_panel *panel;
247 void __iomem *reg_base;
251 struct regulator_bulk_data supplies[2];
264 struct drm_property *brightness;
265 struct completion completed;
267 spinlock_t transfer_lock; /* protects transfer_list */
268 struct list_head transfer_list;
271 #define host_to_dsi(host) container_of(host, struct exynos_dsi, dsi_host)
272 #define connector_to_dsi(c) container_of(c, struct exynos_dsi, connector)
274 static void exynos_dsi_wait_for_reset(struct exynos_dsi *dsi)
276 if (wait_for_completion_timeout(&dsi->completed, msecs_to_jiffies(300)))
279 dev_err(dsi->dev, "timeout waiting for reset\n");
282 static void exynos_dsi_reset(struct exynos_dsi *dsi)
284 reinit_completion(&dsi->completed);
285 writel(DSIM_SWRST, dsi->reg_base + DSIM_SWRST_REG);
289 #define MHZ (1000*1000)
292 static unsigned long exynos_dsi_pll_find_pms(struct exynos_dsi *dsi,
293 unsigned long fin, unsigned long fout, u8 *p, u16 *m, u8 *s)
295 unsigned long best_freq = 0;
296 u32 min_delta = 0xffffffff;
298 u8 _p, uninitialized_var(best_p);
299 u16 _m, uninitialized_var(best_m);
300 u8 _s, uninitialized_var(best_s);
302 p_min = DIV_ROUND_UP(fin, (12 * MHZ));
303 p_max = fin / (6 * MHZ);
305 for (_p = p_min; _p <= p_max; ++_p) {
306 for (_s = 0; _s <= 5; ++_s) {
310 tmp = (u64)fout * (_p << _s);
313 if (_m < 41 || _m > 125)
318 if (tmp < 500 * MHZ || tmp > 1000 * MHZ)
322 do_div(tmp, _p << _s);
324 delta = abs(fout - tmp);
325 if (delta < min_delta) {
344 static unsigned long exynos_dsi_set_pll(struct exynos_dsi *dsi,
347 static const unsigned long freq_bands[] = {
348 100 * MHZ, 120 * MHZ, 160 * MHZ, 200 * MHZ,
349 270 * MHZ, 320 * MHZ, 390 * MHZ, 450 * MHZ,
350 510 * MHZ, 560 * MHZ, 640 * MHZ, 690 * MHZ,
351 770 * MHZ, 870 * MHZ, 950 * MHZ,
353 unsigned long fin, fout;
359 clk_set_rate(dsi->pll_clk, dsi->pll_clk_rate);
361 fin = clk_get_rate(dsi->pll_clk);
363 dev_err(dsi->dev, "failed to get PLL clock frequency\n");
367 dev_dbg(dsi->dev, "PLL input frequency: %lu\n", fin);
369 fout = exynos_dsi_pll_find_pms(dsi, fin, freq, &p, &m, &s);
372 "failed to find PLL PMS for requested frequency\n");
376 for (band = 0; band < ARRAY_SIZE(freq_bands); ++band)
377 if (fout < freq_bands[band])
380 dev_dbg(dsi->dev, "PLL freq %lu, (p %d, m %d, s %d), band %d\n", fout,
383 writel(500, dsi->reg_base + DSIM_PLLTMR_REG);
385 reg = DSIM_FREQ_BAND(band) | DSIM_PLL_EN
386 | DSIM_PLL_P(p) | DSIM_PLL_M(m) | DSIM_PLL_S(s);
387 writel(reg, dsi->reg_base + DSIM_PLLCTRL_REG);
391 if (timeout-- == 0) {
392 dev_err(dsi->dev, "PLL failed to stabilize\n");
395 reg = readl(dsi->reg_base + DSIM_STATUS_REG);
396 } while ((reg & DSIM_PLL_STABLE) == 0);
401 static int exynos_dsi_enable_clock(struct exynos_dsi *dsi)
403 unsigned long hs_clk, byte_clk, esc_clk;
404 unsigned long esc_div;
407 hs_clk = exynos_dsi_set_pll(dsi, dsi->burst_clk_rate);
409 dev_err(dsi->dev, "failed to configure DSI PLL\n");
413 byte_clk = hs_clk / 8;
414 esc_div = DIV_ROUND_UP(byte_clk, dsi->esc_clk_rate);
415 esc_clk = byte_clk / esc_div;
417 if (esc_clk > 20 * MHZ) {
419 esc_clk = byte_clk / esc_div;
422 dev_dbg(dsi->dev, "hs_clk = %lu, byte_clk = %lu, esc_clk = %lu\n",
423 hs_clk, byte_clk, esc_clk);
425 reg = readl(dsi->reg_base + DSIM_CLKCTRL_REG);
426 reg &= ~(DSIM_ESC_PRESCALER_MASK | DSIM_LANE_ESC_CLK_EN_CLK
427 | DSIM_LANE_ESC_CLK_EN_DATA_MASK | DSIM_PLL_BYPASS
428 | DSIM_BYTE_CLK_SRC_MASK);
429 reg |= DSIM_ESC_CLKEN | DSIM_BYTE_CLKEN
430 | DSIM_ESC_PRESCALER(esc_div)
431 | DSIM_LANE_ESC_CLK_EN_CLK
432 | DSIM_LANE_ESC_CLK_EN_DATA(BIT(dsi->lanes) - 1)
433 | DSIM_BYTE_CLK_SRC(0)
434 | DSIM_TX_REQUEST_HSCLK;
435 writel(reg, dsi->reg_base + DSIM_CLKCTRL_REG);
440 static void exynos_dsi_disable_clock(struct exynos_dsi *dsi)
444 reg = readl(dsi->reg_base + DSIM_CLKCTRL_REG);
445 reg &= ~(DSIM_LANE_ESC_CLK_EN_CLK | DSIM_LANE_ESC_CLK_EN_DATA_MASK
446 | DSIM_ESC_CLKEN | DSIM_BYTE_CLKEN);
447 writel(reg, dsi->reg_base + DSIM_CLKCTRL_REG);
449 reg = readl(dsi->reg_base + DSIM_PLLCTRL_REG);
451 writel(reg, dsi->reg_base + DSIM_PLLCTRL_REG);
454 static int exynos_dsi_init_link(struct exynos_dsi *dsi)
460 /* Initialize FIFO pointers */
461 reg = readl(dsi->reg_base + DSIM_FIFOCTRL_REG);
463 writel(reg, dsi->reg_base + DSIM_FIFOCTRL_REG);
465 usleep_range(9000, 11000);
468 writel(reg, dsi->reg_base + DSIM_FIFOCTRL_REG);
470 usleep_range(9000, 11000);
472 /* DSI configuration */
476 * The first bit of mode_flags specifies display configuration.
477 * If this bit is set[= MIPI_DSI_MODE_VIDEO], dsi will support video
478 * mode, otherwise it will support command mode.
480 if (dsi->mode_flags & MIPI_DSI_MODE_VIDEO) {
481 reg |= DSIM_VIDEO_MODE;
484 * The user manual describes that following bits are ignored in
487 if (!(dsi->mode_flags & MIPI_DSI_MODE_VSYNC_FLUSH))
488 reg |= DSIM_MFLUSH_VS;
489 if (dsi->mode_flags & MIPI_DSI_MODE_VIDEO_SYNC_PULSE)
490 reg |= DSIM_SYNC_INFORM;
491 if (dsi->mode_flags & MIPI_DSI_MODE_VIDEO_BURST)
492 reg |= DSIM_BURST_MODE;
493 if (dsi->mode_flags & MIPI_DSI_MODE_VIDEO_AUTO_VERT)
494 reg |= DSIM_AUTO_MODE;
495 if (dsi->mode_flags & MIPI_DSI_MODE_VIDEO_HSE)
496 reg |= DSIM_HSE_MODE;
497 if (!(dsi->mode_flags & MIPI_DSI_MODE_VIDEO_HFP))
498 reg |= DSIM_HFP_MODE;
499 if (!(dsi->mode_flags & MIPI_DSI_MODE_VIDEO_HBP))
500 reg |= DSIM_HBP_MODE;
501 if (!(dsi->mode_flags & MIPI_DSI_MODE_VIDEO_HSA))
502 reg |= DSIM_HSA_MODE;
505 if (!(dsi->mode_flags & MIPI_DSI_MODE_EOT_PACKET))
506 reg |= DSIM_EOT_DISABLE;
508 switch (dsi->format) {
509 case MIPI_DSI_FMT_RGB888:
510 reg |= DSIM_MAIN_PIX_FORMAT_RGB888;
512 case MIPI_DSI_FMT_RGB666:
513 reg |= DSIM_MAIN_PIX_FORMAT_RGB666;
515 case MIPI_DSI_FMT_RGB666_PACKED:
516 reg |= DSIM_MAIN_PIX_FORMAT_RGB666_P;
518 case MIPI_DSI_FMT_RGB565:
519 reg |= DSIM_MAIN_PIX_FORMAT_RGB565;
522 dev_err(dsi->dev, "invalid pixel format\n");
526 reg |= DSIM_NUM_OF_DATA_LANE(dsi->lanes - 1);
528 writel(reg, dsi->reg_base + DSIM_CONFIG_REG);
530 reg |= DSIM_LANE_EN_CLK;
531 writel(reg, dsi->reg_base + DSIM_CONFIG_REG);
533 lanes_mask = BIT(dsi->lanes) - 1;
534 reg |= DSIM_LANE_EN(lanes_mask);
535 writel(reg, dsi->reg_base + DSIM_CONFIG_REG);
537 /* Check clock and data lane state are stop state */
540 if (timeout-- == 0) {
541 dev_err(dsi->dev, "waiting for bus lanes timed out\n");
545 reg = readl(dsi->reg_base + DSIM_STATUS_REG);
546 if ((reg & DSIM_STOP_STATE_DAT(lanes_mask))
547 != DSIM_STOP_STATE_DAT(lanes_mask))
549 } while (!(reg & (DSIM_STOP_STATE_CLK | DSIM_TX_READY_HS_CLK)));
551 reg = readl(dsi->reg_base + DSIM_ESCMODE_REG);
552 reg &= ~DSIM_STOP_STATE_CNT_MASK;
553 reg |= DSIM_STOP_STATE_CNT(0xf);
554 writel(reg, dsi->reg_base + DSIM_ESCMODE_REG);
556 reg = DSIM_BTA_TIMEOUT(0xff) | DSIM_LPDR_TIMEOUT(0xffff);
557 writel(reg, dsi->reg_base + DSIM_TIMEOUT_REG);
562 static void exynos_dsi_set_display_mode(struct exynos_dsi *dsi)
564 struct videomode *vm = &dsi->vm;
567 if (dsi->mode_flags & MIPI_DSI_MODE_VIDEO) {
568 reg = DSIM_CMD_ALLOW(0xf)
569 | DSIM_STABLE_VFP(vm->vfront_porch)
570 | DSIM_MAIN_VBP(vm->vback_porch);
571 writel(reg, dsi->reg_base + DSIM_MVPORCH_REG);
573 reg = DSIM_MAIN_HFP(vm->hfront_porch)
574 | DSIM_MAIN_HBP(vm->hback_porch);
575 writel(reg, dsi->reg_base + DSIM_MHPORCH_REG);
577 reg = DSIM_MAIN_VSA(vm->vsync_len)
578 | DSIM_MAIN_HSA(vm->hsync_len);
579 writel(reg, dsi->reg_base + DSIM_MSYNC_REG);
582 reg = DSIM_MAIN_HRESOL(vm->hactive) | DSIM_MAIN_VRESOL(vm->vactive);
583 writel(reg, dsi->reg_base + DSIM_MDRESOL_REG);
585 dev_dbg(dsi->dev, "LCD size = %dx%d\n", vm->hactive, vm->vactive);
588 static void exynos_dsi_set_display_enable(struct exynos_dsi *dsi, bool enable)
592 reg = readl(dsi->reg_base + DSIM_MDRESOL_REG);
594 reg |= DSIM_MAIN_STAND_BY;
596 reg &= ~DSIM_MAIN_STAND_BY;
597 writel(reg, dsi->reg_base + DSIM_MDRESOL_REG);
600 static int exynos_dsi_wait_for_hdr_fifo(struct exynos_dsi *dsi)
605 u32 reg = readl(dsi->reg_base + DSIM_FIFOCTRL_REG);
607 if (!(reg & DSIM_SFR_HEADER_FULL))
611 usleep_range(950, 1050);
617 static void exynos_dsi_set_cmd_lpm(struct exynos_dsi *dsi, bool lpm)
619 u32 v = readl(dsi->reg_base + DSIM_ESCMODE_REG);
622 v |= DSIM_CMD_LPDT_LP;
624 v &= ~DSIM_CMD_LPDT_LP;
626 writel(v, dsi->reg_base + DSIM_ESCMODE_REG);
629 static void exynos_dsi_force_bta(struct exynos_dsi *dsi)
631 u32 v = readl(dsi->reg_base + DSIM_ESCMODE_REG);
634 writel(v, dsi->reg_base + DSIM_ESCMODE_REG);
637 static void exynos_dsi_send_to_fifo(struct exynos_dsi *dsi,
638 struct exynos_dsi_transfer *xfer)
640 struct device *dev = dsi->dev;
641 const u8 *payload = xfer->tx_payload + xfer->tx_done;
642 u16 length = xfer->tx_len - xfer->tx_done;
643 bool first = !xfer->tx_done;
646 dev_dbg(dev, "< xfer %p: tx len %u, done %u, rx len %u, done %u\n",
647 xfer, xfer->tx_len, xfer->tx_done, xfer->rx_len, xfer->rx_done);
649 if (length > DSI_TX_FIFO_SIZE)
650 length = DSI_TX_FIFO_SIZE;
652 xfer->tx_done += length;
655 while (length >= 4) {
656 reg = (payload[3] << 24) | (payload[2] << 16)
657 | (payload[1] << 8) | payload[0];
658 writel(reg, dsi->reg_base + DSIM_PAYLOAD_REG);
666 reg |= payload[2] << 16;
669 reg |= payload[1] << 8;
673 writel(reg, dsi->reg_base + DSIM_PAYLOAD_REG);
680 /* Send packet header */
684 reg = (xfer->data[1] << 16) | (xfer->data[0] << 8) | xfer->data_id;
685 if (exynos_dsi_wait_for_hdr_fifo(dsi)) {
686 dev_err(dev, "waiting for header FIFO timed out\n");
690 if (NEQV(xfer->flags & MIPI_DSI_MSG_USE_LPM,
691 dsi->state & DSIM_STATE_CMD_LPM)) {
692 exynos_dsi_set_cmd_lpm(dsi, xfer->flags & MIPI_DSI_MSG_USE_LPM);
693 dsi->state ^= DSIM_STATE_CMD_LPM;
696 writel(reg, dsi->reg_base + DSIM_PKTHDR_REG);
698 if (xfer->flags & MIPI_DSI_MSG_REQ_ACK)
699 exynos_dsi_force_bta(dsi);
702 static void exynos_dsi_read_from_fifo(struct exynos_dsi *dsi,
703 struct exynos_dsi_transfer *xfer)
705 u8 *payload = xfer->rx_payload + xfer->rx_done;
706 bool first = !xfer->rx_done;
707 struct device *dev = dsi->dev;
712 reg = readl(dsi->reg_base + DSIM_RXFIFO_REG);
714 switch (reg & 0x3f) {
715 case MIPI_DSI_RX_GENERIC_SHORT_READ_RESPONSE_2BYTE:
716 case MIPI_DSI_RX_DCS_SHORT_READ_RESPONSE_2BYTE:
717 if (xfer->rx_len >= 2) {
718 payload[1] = reg >> 16;
722 case MIPI_DSI_RX_GENERIC_SHORT_READ_RESPONSE_1BYTE:
723 case MIPI_DSI_RX_DCS_SHORT_READ_RESPONSE_1BYTE:
724 payload[0] = reg >> 8;
726 xfer->rx_len = xfer->rx_done;
729 case MIPI_DSI_RX_ACKNOWLEDGE_AND_ERROR_REPORT:
730 dev_err(dev, "DSI Error Report: 0x%04x\n",
731 (reg >> 8) & 0xffff);
736 length = (reg >> 8) & 0xffff;
737 if (length > xfer->rx_len) {
739 "response too long (%u > %u bytes), stripping\n",
740 xfer->rx_len, length);
741 length = xfer->rx_len;
742 } else if (length < xfer->rx_len)
743 xfer->rx_len = length;
746 length = xfer->rx_len - xfer->rx_done;
747 xfer->rx_done += length;
749 /* Receive payload */
750 while (length >= 4) {
751 reg = readl(dsi->reg_base + DSIM_RXFIFO_REG);
752 payload[0] = (reg >> 0) & 0xff;
753 payload[1] = (reg >> 8) & 0xff;
754 payload[2] = (reg >> 16) & 0xff;
755 payload[3] = (reg >> 24) & 0xff;
761 reg = readl(dsi->reg_base + DSIM_RXFIFO_REG);
764 payload[2] = (reg >> 16) & 0xff;
767 payload[1] = (reg >> 8) & 0xff;
770 payload[0] = reg & 0xff;
774 if (xfer->rx_done == xfer->rx_len)
778 length = DSI_RX_FIFO_SIZE / 4;
780 reg = readl(dsi->reg_base + DSIM_RXFIFO_REG);
781 if (reg == DSI_RX_FIFO_EMPTY)
786 static void exynos_dsi_transfer_start(struct exynos_dsi *dsi)
789 struct exynos_dsi_transfer *xfer;
793 spin_lock_irqsave(&dsi->transfer_lock, flags);
795 if (list_empty(&dsi->transfer_list)) {
796 spin_unlock_irqrestore(&dsi->transfer_lock, flags);
800 xfer = list_first_entry(&dsi->transfer_list,
801 struct exynos_dsi_transfer, list);
803 spin_unlock_irqrestore(&dsi->transfer_lock, flags);
805 if (xfer->tx_len && xfer->tx_done == xfer->tx_len)
809 exynos_dsi_send_to_fifo(dsi, xfer);
811 if (xfer->tx_len || xfer->rx_len)
815 complete(&xfer->completed);
817 spin_lock_irqsave(&dsi->transfer_lock, flags);
819 list_del_init(&xfer->list);
820 start = !list_empty(&dsi->transfer_list);
822 spin_unlock_irqrestore(&dsi->transfer_lock, flags);
828 static bool exynos_dsi_transfer_finish(struct exynos_dsi *dsi)
830 struct exynos_dsi_transfer *xfer;
834 spin_lock_irqsave(&dsi->transfer_lock, flags);
836 if (list_empty(&dsi->transfer_list)) {
837 spin_unlock_irqrestore(&dsi->transfer_lock, flags);
841 xfer = list_first_entry(&dsi->transfer_list,
842 struct exynos_dsi_transfer, list);
844 spin_unlock_irqrestore(&dsi->transfer_lock, flags);
847 "> xfer %p, tx_len %u, tx_done %u, rx_len %u, rx_done %u\n",
848 xfer, xfer->tx_len, xfer->tx_done, xfer->rx_len, xfer->rx_done);
850 if (xfer->tx_done != xfer->tx_len)
853 if (xfer->rx_done != xfer->rx_len)
854 exynos_dsi_read_from_fifo(dsi, xfer);
856 if (xfer->rx_done != xfer->rx_len)
859 spin_lock_irqsave(&dsi->transfer_lock, flags);
861 list_del_init(&xfer->list);
862 start = !list_empty(&dsi->transfer_list);
864 spin_unlock_irqrestore(&dsi->transfer_lock, flags);
868 complete(&xfer->completed);
873 static void exynos_dsi_remove_transfer(struct exynos_dsi *dsi,
874 struct exynos_dsi_transfer *xfer)
879 spin_lock_irqsave(&dsi->transfer_lock, flags);
881 if (!list_empty(&dsi->transfer_list) &&
882 xfer == list_first_entry(&dsi->transfer_list,
883 struct exynos_dsi_transfer, list)) {
884 list_del_init(&xfer->list);
885 start = !list_empty(&dsi->transfer_list);
886 spin_unlock_irqrestore(&dsi->transfer_lock, flags);
888 exynos_dsi_transfer_start(dsi);
892 list_del_init(&xfer->list);
894 spin_unlock_irqrestore(&dsi->transfer_lock, flags);
897 static int exynos_dsi_transfer(struct exynos_dsi *dsi,
898 struct exynos_dsi_transfer *xfer)
905 xfer->result = -ETIMEDOUT;
906 init_completion(&xfer->completed);
908 spin_lock_irqsave(&dsi->transfer_lock, flags);
910 stopped = list_empty(&dsi->transfer_list);
911 list_add_tail(&xfer->list, &dsi->transfer_list);
913 spin_unlock_irqrestore(&dsi->transfer_lock, flags);
916 exynos_dsi_transfer_start(dsi);
918 wait_for_completion_timeout(&xfer->completed,
919 msecs_to_jiffies(DSI_XFER_TIMEOUT_MS));
920 if (xfer->result == -ETIMEDOUT) {
921 exynos_dsi_remove_transfer(dsi, xfer);
922 dev_err(dsi->dev, "xfer timed out: %*ph %*ph\n", 2, xfer->data,
923 xfer->tx_len, xfer->tx_payload);
927 /* Also covers hardware timeout condition */
931 static irqreturn_t exynos_dsi_irq(int irq, void *dev_id)
933 struct exynos_dsi *dsi = dev_id;
936 status = readl(dsi->reg_base + DSIM_INTSRC_REG);
938 static unsigned long int j;
939 if (printk_timed_ratelimit(&j, 500))
940 dev_warn(dsi->dev, "spurious interrupt\n");
943 writel(status, dsi->reg_base + DSIM_INTSRC_REG);
945 if (status & DSIM_INT_SW_RST_RELEASE) {
946 u32 mask = ~(DSIM_INT_RX_DONE | DSIM_INT_SFR_FIFO_EMPTY);
947 writel(mask, dsi->reg_base + DSIM_INTMSK_REG);
948 complete(&dsi->completed);
952 if (!(status & (DSIM_INT_RX_DONE | DSIM_INT_SFR_FIFO_EMPTY)))
955 if (exynos_dsi_transfer_finish(dsi))
956 exynos_dsi_transfer_start(dsi);
961 static irqreturn_t exynos_dsi_te_irq_handler(int irq, void *dev_id)
963 struct exynos_dsi *dsi = (struct exynos_dsi *)dev_id;
964 struct drm_encoder *encoder = dsi->encoder;
966 if (dsi->state & DSIM_STATE_ENABLED)
967 exynos_drm_crtc_te_handler(encoder->crtc);
972 static void exynos_dsi_enable_irq(struct exynos_dsi *dsi)
974 enable_irq(dsi->irq);
976 if (gpio_is_valid(dsi->te_gpio))
977 enable_irq(gpio_to_irq(dsi->te_gpio));
980 static void exynos_dsi_disable_irq(struct exynos_dsi *dsi)
982 if (gpio_is_valid(dsi->te_gpio))
983 disable_irq(gpio_to_irq(dsi->te_gpio));
985 disable_irq(dsi->irq);
988 static int exynos_dsi_init(struct exynos_dsi *dsi)
990 exynos_dsi_enable_clock(dsi);
991 exynos_dsi_reset(dsi);
992 exynos_dsi_enable_irq(dsi);
993 exynos_dsi_wait_for_reset(dsi);
994 exynos_dsi_init_link(dsi);
999 static int exynos_dsi_register_te_irq(struct exynos_dsi *dsi)
1003 dsi->te_gpio = of_get_named_gpio(dsi->panel_node, "te-gpios", 0);
1004 if (!gpio_is_valid(dsi->te_gpio)) {
1005 dev_err(dsi->dev, "no te-gpios specified\n");
1010 ret = gpio_request_one(dsi->te_gpio, GPIOF_IN, "te_gpio");
1012 dev_err(dsi->dev, "gpio request failed with %d\n", ret);
1017 * This TE GPIO IRQ should not be set to IRQ_NOAUTOEN, because panel
1018 * calls drm_panel_init() first then calls mipi_dsi_attach() in probe().
1019 * It means that te_gpio is invalid when exynos_dsi_enable_irq() is
1020 * called by drm_panel_init() before panel is attached.
1022 ret = request_threaded_irq(gpio_to_irq(dsi->te_gpio),
1023 exynos_dsi_te_irq_handler, NULL,
1024 IRQF_TRIGGER_RISING, "TE", dsi);
1026 dev_err(dsi->dev, "request interrupt failed with %d\n", ret);
1027 gpio_free(dsi->te_gpio);
1035 static void exynos_dsi_unregister_te_irq(struct exynos_dsi *dsi)
1037 if (gpio_is_valid(dsi->te_gpio)) {
1038 free_irq(gpio_to_irq(dsi->te_gpio), dsi);
1039 gpio_free(dsi->te_gpio);
1040 dsi->te_gpio = -ENOENT;
1044 static int exynos_dsi_host_attach(struct mipi_dsi_host *host,
1045 struct mipi_dsi_device *device)
1047 struct exynos_dsi *dsi = host_to_dsi(host);
1049 dsi->lanes = device->lanes;
1050 dsi->format = device->format;
1051 dsi->mode_flags = device->mode_flags;
1052 dsi->panel_node = device->dev.of_node;
1054 if (dsi->connector.dev)
1055 drm_helper_hpd_irq_event(dsi->connector.dev);
1058 * This is a temporary solution and should be made by more generic way.
1060 * If attached panel device is for command mode one, dsi should register
1061 * TE interrupt handler.
1063 if (!(dsi->mode_flags & MIPI_DSI_MODE_VIDEO)) {
1064 int ret = exynos_dsi_register_te_irq(dsi);
1073 static int exynos_dsi_host_detach(struct mipi_dsi_host *host,
1074 struct mipi_dsi_device *device)
1076 struct exynos_dsi *dsi = host_to_dsi(host);
1078 exynos_dsi_unregister_te_irq(dsi);
1080 dsi->panel_node = NULL;
1082 if (dsi->connector.dev)
1083 drm_helper_hpd_irq_event(dsi->connector.dev);
1088 /* distinguish between short and long DSI packet types */
1089 static bool exynos_dsi_is_short_dsi_type(u8 type)
1091 return (type & 0x0f) <= 8;
1094 static ssize_t exynos_dsi_host_transfer(struct mipi_dsi_host *host,
1095 struct mipi_dsi_msg *msg)
1097 struct exynos_dsi *dsi = host_to_dsi(host);
1098 struct exynos_dsi_transfer xfer;
1101 if (!(dsi->state & DSIM_STATE_INITIALIZED)) {
1102 ret = exynos_dsi_init(dsi);
1105 dsi->state |= DSIM_STATE_INITIALIZED;
1108 if (msg->tx_len == 0)
1111 xfer.data_id = msg->type | (msg->channel << 6);
1113 if (exynos_dsi_is_short_dsi_type(msg->type)) {
1114 const char *tx_buf = msg->tx_buf;
1116 if (msg->tx_len > 2)
1119 xfer.data[0] = tx_buf[0];
1120 xfer.data[1] = (msg->tx_len == 2) ? tx_buf[1] : 0;
1122 xfer.tx_len = msg->tx_len;
1123 xfer.data[0] = msg->tx_len & 0xff;
1124 xfer.data[1] = msg->tx_len >> 8;
1125 xfer.tx_payload = msg->tx_buf;
1128 xfer.rx_len = msg->rx_len;
1129 xfer.rx_payload = msg->rx_buf;
1130 xfer.flags = msg->flags;
1132 ret = exynos_dsi_transfer(dsi, &xfer);
1133 return (ret < 0) ? ret : xfer.rx_done;
1136 static const struct mipi_dsi_host_ops exynos_dsi_ops = {
1137 .attach = exynos_dsi_host_attach,
1138 .detach = exynos_dsi_host_detach,
1139 .transfer = exynos_dsi_host_transfer,
1142 static int exynos_dsi_poweron(struct exynos_dsi *dsi)
1146 ret = regulator_bulk_enable(ARRAY_SIZE(dsi->supplies), dsi->supplies);
1148 dev_err(dsi->dev, "cannot enable regulators %d\n", ret);
1152 ret = clk_prepare_enable(dsi->bus_clk);
1154 dev_err(dsi->dev, "cannot enable bus clock %d\n", ret);
1158 ret = clk_prepare_enable(dsi->pll_clk);
1160 dev_err(dsi->dev, "cannot enable pll clock %d\n", ret);
1164 ret = phy_power_on(dsi->phy);
1166 dev_err(dsi->dev, "cannot enable phy %d\n", ret);
1173 clk_disable_unprepare(dsi->pll_clk);
1175 clk_disable_unprepare(dsi->bus_clk);
1177 regulator_bulk_disable(ARRAY_SIZE(dsi->supplies), dsi->supplies);
1182 static void exynos_dsi_poweroff(struct exynos_dsi *dsi)
1186 usleep_range(10000, 20000);
1188 if (dsi->state & DSIM_STATE_INITIALIZED) {
1189 dsi->state &= ~DSIM_STATE_INITIALIZED;
1191 exynos_dsi_disable_clock(dsi);
1193 exynos_dsi_disable_irq(dsi);
1196 dsi->state &= ~DSIM_STATE_CMD_LPM;
1198 phy_power_off(dsi->phy);
1200 clk_disable_unprepare(dsi->pll_clk);
1201 clk_disable_unprepare(dsi->bus_clk);
1203 ret = regulator_bulk_disable(ARRAY_SIZE(dsi->supplies), dsi->supplies);
1205 dev_err(dsi->dev, "cannot disable regulators %d\n", ret);
1208 static int exynos_dsi_enable(struct exynos_dsi *dsi)
1212 if (dsi->state & DSIM_STATE_ENABLED)
1215 ret = exynos_dsi_poweron(dsi);
1219 ret = drm_panel_enable(dsi->panel);
1221 exynos_dsi_poweroff(dsi);
1225 exynos_dsi_set_display_mode(dsi);
1226 exynos_dsi_set_display_enable(dsi, true);
1228 dsi->state |= DSIM_STATE_ENABLED;
1233 static void exynos_dsi_disable(struct exynos_dsi *dsi)
1235 if (!(dsi->state & DSIM_STATE_ENABLED))
1238 exynos_dsi_set_display_enable(dsi, false);
1239 drm_panel_disable(dsi->panel);
1240 exynos_dsi_poweroff(dsi);
1242 dsi->state &= ~DSIM_STATE_ENABLED;
1245 static void exynos_dsi_dpms(struct exynos_drm_display *display, int mode)
1247 struct exynos_dsi *dsi = display->ctx;
1251 case DRM_MODE_DPMS_ON:
1252 exynos_dsi_enable(dsi);
1254 case DRM_MODE_DPMS_STANDBY:
1255 case DRM_MODE_DPMS_SUSPEND:
1256 case DRM_MODE_DPMS_OFF:
1257 exynos_dsi_disable(dsi);
1265 static enum drm_connector_status
1266 exynos_dsi_detect(struct drm_connector *connector, bool force)
1268 struct exynos_dsi *dsi = connector_to_dsi(connector);
1271 dsi->panel = of_drm_find_panel(dsi->panel_node);
1273 drm_panel_attach(dsi->panel, &dsi->connector);
1274 } else if (!dsi->panel_node) {
1275 struct exynos_drm_display *display;
1277 display = platform_get_drvdata(to_platform_device(dsi->dev));
1278 exynos_dsi_dpms(display, DRM_MODE_DPMS_OFF);
1279 drm_panel_detach(dsi->panel);
1284 return connector_status_connected;
1286 return connector_status_disconnected;
1289 static void exynos_dsi_connector_destroy(struct drm_connector *connector)
1293 static struct drm_connector_funcs exynos_dsi_connector_funcs = {
1294 .dpms = drm_helper_connector_dpms,
1295 .detect = exynos_dsi_detect,
1296 .fill_modes = drm_helper_probe_single_connector_modes,
1297 .destroy = exynos_dsi_connector_destroy,
1300 static int exynos_dsi_get_modes(struct drm_connector *connector)
1302 struct exynos_dsi *dsi = connector_to_dsi(connector);
1305 return dsi->panel->funcs->get_modes(dsi->panel);
1310 static int exynos_dsi_mode_valid(struct drm_connector *connector,
1311 struct drm_display_mode *mode)
1316 static struct drm_encoder *
1317 exynos_dsi_best_encoder(struct drm_connector *connector)
1319 struct exynos_dsi *dsi = connector_to_dsi(connector);
1321 return dsi->encoder;
1324 static struct drm_connector_helper_funcs exynos_dsi_connector_helper_funcs = {
1325 .get_modes = exynos_dsi_get_modes,
1326 .mode_valid = exynos_dsi_mode_valid,
1327 .best_encoder = exynos_dsi_best_encoder,
1330 static int exynos_dsi_create_connector(struct exynos_drm_display *display,
1331 struct drm_encoder *encoder)
1333 struct exynos_dsi *dsi = display->ctx;
1334 struct drm_connector *connector = &dsi->connector;
1337 dsi->encoder = encoder;
1339 connector->polled = DRM_CONNECTOR_POLL_HPD;
1341 ret = drm_connector_init(encoder->dev, connector,
1342 &exynos_dsi_connector_funcs,
1343 DRM_MODE_CONNECTOR_DSI);
1345 DRM_ERROR("Failed to initialize connector with drm\n");
1349 drm_connector_helper_add(connector, &exynos_dsi_connector_helper_funcs);
1350 drm_connector_register(connector);
1351 drm_mode_connector_attach_encoder(connector, encoder);
1356 static void exynos_dsi_mode_set(struct exynos_drm_display *display,
1357 struct drm_display_mode *mode)
1359 struct exynos_dsi *dsi = display->ctx;
1360 struct videomode *vm = &dsi->vm;
1362 vm->hactive = mode->hdisplay;
1363 vm->vactive = mode->vdisplay;
1364 vm->vfront_porch = mode->vsync_start - mode->vdisplay;
1365 vm->vback_porch = mode->vtotal - mode->vsync_end;
1366 vm->vsync_len = mode->vsync_end - mode->vsync_start;
1367 vm->hfront_porch = mode->hsync_start - mode->hdisplay;
1368 vm->hback_porch = mode->htotal - mode->hsync_end;
1369 vm->hsync_len = mode->hsync_end - mode->hsync_start;
1372 static struct exynos_drm_display_ops exynos_dsi_display_ops = {
1373 .create_connector = exynos_dsi_create_connector,
1374 .mode_set = exynos_dsi_mode_set,
1375 .dpms = exynos_dsi_dpms
1378 static struct exynos_drm_display exynos_dsi_display = {
1379 .type = EXYNOS_DISPLAY_TYPE_LCD,
1380 .ops = &exynos_dsi_display_ops,
1383 /* of_* functions will be removed after merge of of_graph patches */
1384 static struct device_node *
1385 of_get_child_by_name_reg(struct device_node *parent, const char *name, u32 reg)
1387 struct device_node *np;
1389 for_each_child_of_node(parent, np) {
1392 if (!np->name || of_node_cmp(np->name, name))
1395 if (of_property_read_u32(np, "reg", &r) < 0)
1405 static struct device_node *of_graph_get_port_by_reg(struct device_node *parent,
1408 struct device_node *ports, *port;
1410 ports = of_get_child_by_name(parent, "ports");
1414 port = of_get_child_by_name_reg(parent, "port", reg);
1421 static struct device_node *
1422 of_graph_get_endpoint_by_reg(struct device_node *port, u32 reg)
1424 return of_get_child_by_name_reg(port, "endpoint", reg);
1427 static int exynos_dsi_of_read_u32(const struct device_node *np,
1428 const char *propname, u32 *out_value)
1430 int ret = of_property_read_u32(np, propname, out_value);
1433 pr_err("%s: failed to get '%s' property\n", np->full_name,
1444 static int exynos_dsi_parse_dt(struct exynos_dsi *dsi)
1446 struct device *dev = dsi->dev;
1447 struct device_node *node = dev->of_node;
1448 struct device_node *port, *ep;
1451 ret = exynos_dsi_of_read_u32(node, "samsung,pll-clock-frequency",
1452 &dsi->pll_clk_rate);
1456 port = of_graph_get_port_by_reg(node, DSI_PORT_OUT);
1458 dev_err(dev, "no output port specified\n");
1462 ep = of_graph_get_endpoint_by_reg(port, 0);
1465 dev_err(dev, "no endpoint specified in output port\n");
1469 ret = exynos_dsi_of_read_u32(ep, "samsung,burst-clock-frequency",
1470 &dsi->burst_clk_rate);
1474 ret = exynos_dsi_of_read_u32(ep, "samsung,esc-clock-frequency",
1475 &dsi->esc_clk_rate);
1483 static int exynos_dsi_bind(struct device *dev, struct device *master,
1486 struct drm_device *drm_dev = data;
1487 struct exynos_dsi *dsi;
1490 ret = exynos_drm_create_enc_conn(drm_dev, &exynos_dsi_display);
1492 DRM_ERROR("Encoder create [%d] failed with %d\n",
1493 exynos_dsi_display.type, ret);
1497 dsi = exynos_dsi_display.ctx;
1499 return mipi_dsi_host_register(&dsi->dsi_host);
1502 static void exynos_dsi_unbind(struct device *dev, struct device *master,
1505 struct exynos_dsi *dsi = exynos_dsi_display.ctx;
1506 struct drm_encoder *encoder = dsi->encoder;
1508 exynos_dsi_dpms(&exynos_dsi_display, DRM_MODE_DPMS_OFF);
1510 mipi_dsi_host_unregister(&dsi->dsi_host);
1512 encoder->funcs->destroy(encoder);
1513 drm_connector_cleanup(&dsi->connector);
1516 static const struct component_ops exynos_dsi_component_ops = {
1517 .bind = exynos_dsi_bind,
1518 .unbind = exynos_dsi_unbind,
1521 static int exynos_dsi_probe(struct platform_device *pdev)
1523 struct resource *res;
1524 struct exynos_dsi *dsi;
1527 ret = exynos_drm_component_add(&pdev->dev, EXYNOS_DEVICE_TYPE_CONNECTOR,
1528 exynos_dsi_display.type);
1532 dsi = devm_kzalloc(&pdev->dev, sizeof(*dsi), GFP_KERNEL);
1534 dev_err(&pdev->dev, "failed to allocate dsi object.\n");
1536 goto err_del_component;
1539 /* To be checked as invalid one */
1540 dsi->te_gpio = -ENOENT;
1542 init_completion(&dsi->completed);
1543 spin_lock_init(&dsi->transfer_lock);
1544 INIT_LIST_HEAD(&dsi->transfer_list);
1546 dsi->dsi_host.ops = &exynos_dsi_ops;
1547 dsi->dsi_host.dev = &pdev->dev;
1549 dsi->dev = &pdev->dev;
1551 ret = exynos_dsi_parse_dt(dsi);
1553 goto err_del_component;
1555 dsi->supplies[0].supply = "vddcore";
1556 dsi->supplies[1].supply = "vddio";
1557 ret = devm_regulator_bulk_get(&pdev->dev, ARRAY_SIZE(dsi->supplies),
1560 dev_info(&pdev->dev, "failed to get regulators: %d\n", ret);
1561 return -EPROBE_DEFER;
1564 dsi->pll_clk = devm_clk_get(&pdev->dev, "pll_clk");
1565 if (IS_ERR(dsi->pll_clk)) {
1566 dev_info(&pdev->dev, "failed to get dsi pll input clock\n");
1567 ret = PTR_ERR(dsi->pll_clk);
1568 goto err_del_component;
1571 dsi->bus_clk = devm_clk_get(&pdev->dev, "bus_clk");
1572 if (IS_ERR(dsi->bus_clk)) {
1573 dev_info(&pdev->dev, "failed to get dsi bus clock\n");
1574 ret = PTR_ERR(dsi->bus_clk);
1575 goto err_del_component;
1578 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1579 dsi->reg_base = devm_ioremap_resource(&pdev->dev, res);
1580 if (IS_ERR(dsi->reg_base)) {
1581 dev_err(&pdev->dev, "failed to remap io region\n");
1582 ret = PTR_ERR(dsi->reg_base);
1583 goto err_del_component;
1586 dsi->phy = devm_phy_get(&pdev->dev, "dsim");
1587 if (IS_ERR(dsi->phy)) {
1588 dev_info(&pdev->dev, "failed to get dsim phy\n");
1589 ret = PTR_ERR(dsi->phy);
1590 goto err_del_component;
1593 dsi->irq = platform_get_irq(pdev, 0);
1595 dev_err(&pdev->dev, "failed to request dsi irq resource\n");
1597 goto err_del_component;
1600 irq_set_status_flags(dsi->irq, IRQ_NOAUTOEN);
1601 ret = devm_request_threaded_irq(&pdev->dev, dsi->irq, NULL,
1602 exynos_dsi_irq, IRQF_ONESHOT,
1603 dev_name(&pdev->dev), dsi);
1605 dev_err(&pdev->dev, "failed to request dsi irq\n");
1606 goto err_del_component;
1609 exynos_dsi_display.ctx = dsi;
1611 platform_set_drvdata(pdev, &exynos_dsi_display);
1613 ret = component_add(&pdev->dev, &exynos_dsi_component_ops);
1615 goto err_del_component;
1620 exynos_drm_component_del(&pdev->dev, EXYNOS_DEVICE_TYPE_CONNECTOR);
1624 static int exynos_dsi_remove(struct platform_device *pdev)
1626 component_del(&pdev->dev, &exynos_dsi_component_ops);
1627 exynos_drm_component_del(&pdev->dev, EXYNOS_DEVICE_TYPE_CONNECTOR);
1632 static struct of_device_id exynos_dsi_of_match[] = {
1633 { .compatible = "samsung,exynos4210-mipi-dsi" },
1637 struct platform_driver dsi_driver = {
1638 .probe = exynos_dsi_probe,
1639 .remove = exynos_dsi_remove,
1641 .name = "exynos-dsi",
1642 .owner = THIS_MODULE,
1643 .of_match_table = exynos_dsi_of_match,
1647 MODULE_AUTHOR("Tomasz Figa <t.figa@samsung.com>");
1648 MODULE_AUTHOR("Andrzej Hajda <a.hajda@samsung.com>");
1649 MODULE_DESCRIPTION("Samsung SoC MIPI DSI Master");
1650 MODULE_LICENSE("GPL v2");