blob: 670c2f9be31c277e7b2e23de6d65507dc73d38da [file] [log] [blame]
Andrzej Hajda7eb8f062014-04-04 01:19:56 +09001/*
2 * Samsung SoC MIPI DSI Master driver.
3 *
4 * Copyright (c) 2014 Samsung Electronics Co., Ltd
5 *
6 * Contacts: Tomasz Figa <t.figa@samsung.com>
7 *
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.
11*/
12
13#include <drm/drmP.h>
14#include <drm/drm_crtc_helper.h>
15#include <drm/drm_mipi_dsi.h>
16#include <drm/drm_panel.h>
17
18#include <linux/clk.h>
YoungJun Choe17ddec2014-07-22 19:49:44 +090019#include <linux/gpio/consumer.h>
Andrzej Hajda7eb8f062014-04-04 01:19:56 +090020#include <linux/irq.h>
YoungJun Cho9a320412014-07-17 18:01:23 +090021#include <linux/of_device.h>
YoungJun Choe17ddec2014-07-22 19:49:44 +090022#include <linux/of_gpio.h>
Andrzej Hajda7eb8f062014-04-04 01:19:56 +090023#include <linux/phy/phy.h>
24#include <linux/regulator/consumer.h>
Inki Daef37cd5e2014-05-09 14:25:20 +090025#include <linux/component.h>
Andrzej Hajda7eb8f062014-04-04 01:19:56 +090026
27#include <video/mipi_display.h>
28#include <video/videomode.h>
29
YoungJun Choe17ddec2014-07-22 19:49:44 +090030#include "exynos_drm_crtc.h"
Andrzej Hajda7eb8f062014-04-04 01:19:56 +090031#include "exynos_drm_drv.h"
32
33/* returns true iff both arguments logically differs */
34#define NEQV(a, b) (!(a) ^ !(b))
35
36#define DSIM_STATUS_REG 0x0 /* Status register */
37#define DSIM_SWRST_REG 0x4 /* Software reset register */
38#define DSIM_CLKCTRL_REG 0x8 /* Clock control register */
39#define DSIM_TIMEOUT_REG 0xc /* Time out register */
40#define DSIM_CONFIG_REG 0x10 /* Configuration register */
41#define DSIM_ESCMODE_REG 0x14 /* Escape mode register */
42
43/* Main display image resolution register */
44#define DSIM_MDRESOL_REG 0x18
45#define DSIM_MVPORCH_REG 0x1c /* Main display Vporch register */
46#define DSIM_MHPORCH_REG 0x20 /* Main display Hporch register */
47#define DSIM_MSYNC_REG 0x24 /* Main display sync area register */
48
49/* Sub display image resolution register */
50#define DSIM_SDRESOL_REG 0x28
51#define DSIM_INTSRC_REG 0x2c /* Interrupt source register */
52#define DSIM_INTMSK_REG 0x30 /* Interrupt mask register */
53#define DSIM_PKTHDR_REG 0x34 /* Packet Header FIFO register */
54#define DSIM_PAYLOAD_REG 0x38 /* Payload FIFO register */
55#define DSIM_RXFIFO_REG 0x3c /* Read FIFO register */
56#define DSIM_FIFOTHLD_REG 0x40 /* FIFO threshold level register */
57#define DSIM_FIFOCTRL_REG 0x44 /* FIFO status and control register */
58
59/* FIFO memory AC characteristic register */
60#define DSIM_PLLCTRL_REG 0x4c /* PLL control register */
Andrzej Hajda7eb8f062014-04-04 01:19:56 +090061#define DSIM_PHYACCHR_REG 0x54 /* D-PHY AC characteristic register */
62#define DSIM_PHYACCHR1_REG 0x58 /* D-PHY AC characteristic register1 */
YoungJun Cho9a320412014-07-17 18:01:23 +090063#define DSIM_PHYCTRL_REG 0x5c
64#define DSIM_PHYTIMING_REG 0x64
65#define DSIM_PHYTIMING1_REG 0x68
66#define DSIM_PHYTIMING2_REG 0x6c
Andrzej Hajda7eb8f062014-04-04 01:19:56 +090067
68/* DSIM_STATUS */
69#define DSIM_STOP_STATE_DAT(x) (((x) & 0xf) << 0)
70#define DSIM_STOP_STATE_CLK (1 << 8)
71#define DSIM_TX_READY_HS_CLK (1 << 10)
72#define DSIM_PLL_STABLE (1 << 31)
73
74/* DSIM_SWRST */
75#define DSIM_FUNCRST (1 << 16)
76#define DSIM_SWRST (1 << 0)
77
78/* DSIM_TIMEOUT */
79#define DSIM_LPDR_TIMEOUT(x) ((x) << 0)
80#define DSIM_BTA_TIMEOUT(x) ((x) << 16)
81
82/* DSIM_CLKCTRL */
83#define DSIM_ESC_PRESCALER(x) (((x) & 0xffff) << 0)
84#define DSIM_ESC_PRESCALER_MASK (0xffff << 0)
85#define DSIM_LANE_ESC_CLK_EN_CLK (1 << 19)
86#define DSIM_LANE_ESC_CLK_EN_DATA(x) (((x) & 0xf) << 20)
87#define DSIM_LANE_ESC_CLK_EN_DATA_MASK (0xf << 20)
88#define DSIM_BYTE_CLKEN (1 << 24)
89#define DSIM_BYTE_CLK_SRC(x) (((x) & 0x3) << 25)
90#define DSIM_BYTE_CLK_SRC_MASK (0x3 << 25)
91#define DSIM_PLL_BYPASS (1 << 27)
92#define DSIM_ESC_CLKEN (1 << 28)
93#define DSIM_TX_REQUEST_HSCLK (1 << 31)
94
95/* DSIM_CONFIG */
96#define DSIM_LANE_EN_CLK (1 << 0)
97#define DSIM_LANE_EN(x) (((x) & 0xf) << 1)
98#define DSIM_NUM_OF_DATA_LANE(x) (((x) & 0x3) << 5)
99#define DSIM_SUB_PIX_FORMAT(x) (((x) & 0x7) << 8)
100#define DSIM_MAIN_PIX_FORMAT_MASK (0x7 << 12)
101#define DSIM_MAIN_PIX_FORMAT_RGB888 (0x7 << 12)
102#define DSIM_MAIN_PIX_FORMAT_RGB666 (0x6 << 12)
103#define DSIM_MAIN_PIX_FORMAT_RGB666_P (0x5 << 12)
104#define DSIM_MAIN_PIX_FORMAT_RGB565 (0x4 << 12)
105#define DSIM_SUB_VC (((x) & 0x3) << 16)
106#define DSIM_MAIN_VC (((x) & 0x3) << 18)
107#define DSIM_HSA_MODE (1 << 20)
108#define DSIM_HBP_MODE (1 << 21)
109#define DSIM_HFP_MODE (1 << 22)
110#define DSIM_HSE_MODE (1 << 23)
111#define DSIM_AUTO_MODE (1 << 24)
112#define DSIM_VIDEO_MODE (1 << 25)
113#define DSIM_BURST_MODE (1 << 26)
114#define DSIM_SYNC_INFORM (1 << 27)
115#define DSIM_EOT_DISABLE (1 << 28)
116#define DSIM_MFLUSH_VS (1 << 29)
Inki Dae78d3a8c2014-08-13 17:03:12 +0900117/* This flag is valid only for exynos3250/3472/4415/5260/5430 */
118#define DSIM_CLKLANE_STOP (1 << 30)
Andrzej Hajda7eb8f062014-04-04 01:19:56 +0900119
120/* DSIM_ESCMODE */
121#define DSIM_TX_TRIGGER_RST (1 << 4)
122#define DSIM_TX_LPDT_LP (1 << 6)
123#define DSIM_CMD_LPDT_LP (1 << 7)
124#define DSIM_FORCE_BTA (1 << 16)
125#define DSIM_FORCE_STOP_STATE (1 << 20)
126#define DSIM_STOP_STATE_CNT(x) (((x) & 0x7ff) << 21)
127#define DSIM_STOP_STATE_CNT_MASK (0x7ff << 21)
128
129/* DSIM_MDRESOL */
130#define DSIM_MAIN_STAND_BY (1 << 31)
131#define DSIM_MAIN_VRESOL(x) (((x) & 0x7ff) << 16)
132#define DSIM_MAIN_HRESOL(x) (((x) & 0X7ff) << 0)
133
134/* DSIM_MVPORCH */
135#define DSIM_CMD_ALLOW(x) ((x) << 28)
136#define DSIM_STABLE_VFP(x) ((x) << 16)
137#define DSIM_MAIN_VBP(x) ((x) << 0)
138#define DSIM_CMD_ALLOW_MASK (0xf << 28)
139#define DSIM_STABLE_VFP_MASK (0x7ff << 16)
140#define DSIM_MAIN_VBP_MASK (0x7ff << 0)
141
142/* DSIM_MHPORCH */
143#define DSIM_MAIN_HFP(x) ((x) << 16)
144#define DSIM_MAIN_HBP(x) ((x) << 0)
145#define DSIM_MAIN_HFP_MASK ((0xffff) << 16)
146#define DSIM_MAIN_HBP_MASK ((0xffff) << 0)
147
148/* DSIM_MSYNC */
149#define DSIM_MAIN_VSA(x) ((x) << 22)
150#define DSIM_MAIN_HSA(x) ((x) << 0)
151#define DSIM_MAIN_VSA_MASK ((0x3ff) << 22)
152#define DSIM_MAIN_HSA_MASK ((0xffff) << 0)
153
154/* DSIM_SDRESOL */
155#define DSIM_SUB_STANDY(x) ((x) << 31)
156#define DSIM_SUB_VRESOL(x) ((x) << 16)
157#define DSIM_SUB_HRESOL(x) ((x) << 0)
158#define DSIM_SUB_STANDY_MASK ((0x1) << 31)
159#define DSIM_SUB_VRESOL_MASK ((0x7ff) << 16)
160#define DSIM_SUB_HRESOL_MASK ((0x7ff) << 0)
161
162/* DSIM_INTSRC */
163#define DSIM_INT_PLL_STABLE (1 << 31)
164#define DSIM_INT_SW_RST_RELEASE (1 << 30)
165#define DSIM_INT_SFR_FIFO_EMPTY (1 << 29)
166#define DSIM_INT_BTA (1 << 25)
167#define DSIM_INT_FRAME_DONE (1 << 24)
168#define DSIM_INT_RX_TIMEOUT (1 << 21)
169#define DSIM_INT_BTA_TIMEOUT (1 << 20)
170#define DSIM_INT_RX_DONE (1 << 18)
171#define DSIM_INT_RX_TE (1 << 17)
172#define DSIM_INT_RX_ACK (1 << 16)
173#define DSIM_INT_RX_ECC_ERR (1 << 15)
174#define DSIM_INT_RX_CRC_ERR (1 << 14)
175
176/* DSIM_FIFOCTRL */
177#define DSIM_RX_DATA_FULL (1 << 25)
178#define DSIM_RX_DATA_EMPTY (1 << 24)
179#define DSIM_SFR_HEADER_FULL (1 << 23)
180#define DSIM_SFR_HEADER_EMPTY (1 << 22)
181#define DSIM_SFR_PAYLOAD_FULL (1 << 21)
182#define DSIM_SFR_PAYLOAD_EMPTY (1 << 20)
183#define DSIM_I80_HEADER_FULL (1 << 19)
184#define DSIM_I80_HEADER_EMPTY (1 << 18)
185#define DSIM_I80_PAYLOAD_FULL (1 << 17)
186#define DSIM_I80_PAYLOAD_EMPTY (1 << 16)
187#define DSIM_SD_HEADER_FULL (1 << 15)
188#define DSIM_SD_HEADER_EMPTY (1 << 14)
189#define DSIM_SD_PAYLOAD_FULL (1 << 13)
190#define DSIM_SD_PAYLOAD_EMPTY (1 << 12)
191#define DSIM_MD_HEADER_FULL (1 << 11)
192#define DSIM_MD_HEADER_EMPTY (1 << 10)
193#define DSIM_MD_PAYLOAD_FULL (1 << 9)
194#define DSIM_MD_PAYLOAD_EMPTY (1 << 8)
195#define DSIM_RX_FIFO (1 << 4)
196#define DSIM_SFR_FIFO (1 << 3)
197#define DSIM_I80_FIFO (1 << 2)
198#define DSIM_SD_FIFO (1 << 1)
199#define DSIM_MD_FIFO (1 << 0)
200
201/* DSIM_PHYACCHR */
202#define DSIM_AFC_EN (1 << 14)
203#define DSIM_AFC_CTL(x) (((x) & 0x7) << 5)
204
205/* DSIM_PLLCTRL */
206#define DSIM_FREQ_BAND(x) ((x) << 24)
207#define DSIM_PLL_EN (1 << 23)
208#define DSIM_PLL_P(x) ((x) << 13)
209#define DSIM_PLL_M(x) ((x) << 4)
210#define DSIM_PLL_S(x) ((x) << 1)
211
YoungJun Cho9a320412014-07-17 18:01:23 +0900212/* DSIM_PHYCTRL */
213#define DSIM_PHYCTRL_ULPS_EXIT(x) (((x) & 0x1ff) << 0)
214
215/* DSIM_PHYTIMING */
216#define DSIM_PHYTIMING_LPX(x) ((x) << 8)
217#define DSIM_PHYTIMING_HS_EXIT(x) ((x) << 0)
218
219/* DSIM_PHYTIMING1 */
220#define DSIM_PHYTIMING1_CLK_PREPARE(x) ((x) << 24)
221#define DSIM_PHYTIMING1_CLK_ZERO(x) ((x) << 16)
222#define DSIM_PHYTIMING1_CLK_POST(x) ((x) << 8)
223#define DSIM_PHYTIMING1_CLK_TRAIL(x) ((x) << 0)
224
225/* DSIM_PHYTIMING2 */
226#define DSIM_PHYTIMING2_HS_PREPARE(x) ((x) << 16)
227#define DSIM_PHYTIMING2_HS_ZERO(x) ((x) << 8)
228#define DSIM_PHYTIMING2_HS_TRAIL(x) ((x) << 0)
229
Andrzej Hajda7eb8f062014-04-04 01:19:56 +0900230#define DSI_MAX_BUS_WIDTH 4
231#define DSI_NUM_VIRTUAL_CHANNELS 4
232#define DSI_TX_FIFO_SIZE 2048
233#define DSI_RX_FIFO_SIZE 256
234#define DSI_XFER_TIMEOUT_MS 100
235#define DSI_RX_FIFO_EMPTY 0x30800002
236
237enum exynos_dsi_transfer_type {
238 EXYNOS_DSI_TX,
239 EXYNOS_DSI_RX,
240};
241
242struct exynos_dsi_transfer {
243 struct list_head list;
244 struct completion completed;
245 int result;
246 u8 data_id;
247 u8 data[2];
248 u16 flags;
249
250 const u8 *tx_payload;
251 u16 tx_len;
252 u16 tx_done;
253
254 u8 *rx_payload;
255 u16 rx_len;
256 u16 rx_done;
257};
258
259#define DSIM_STATE_ENABLED BIT(0)
260#define DSIM_STATE_INITIALIZED BIT(1)
261#define DSIM_STATE_CMD_LPM BIT(2)
262
YoungJun Cho9a320412014-07-17 18:01:23 +0900263struct exynos_dsi_driver_data {
264 unsigned int plltmr_reg;
265
266 unsigned int has_freqband:1;
Inki Dae78d3a8c2014-08-13 17:03:12 +0900267 unsigned int has_clklane_stop:1;
YoungJun Cho9a320412014-07-17 18:01:23 +0900268};
269
Andrzej Hajda7eb8f062014-04-04 01:19:56 +0900270struct exynos_dsi {
271 struct mipi_dsi_host dsi_host;
272 struct drm_connector connector;
273 struct drm_encoder *encoder;
274 struct device_node *panel_node;
275 struct drm_panel *panel;
276 struct device *dev;
277
278 void __iomem *reg_base;
279 struct phy *phy;
280 struct clk *pll_clk;
281 struct clk *bus_clk;
282 struct regulator_bulk_data supplies[2];
283 int irq;
YoungJun Choe17ddec2014-07-22 19:49:44 +0900284 int te_gpio;
Andrzej Hajda7eb8f062014-04-04 01:19:56 +0900285
286 u32 pll_clk_rate;
287 u32 burst_clk_rate;
288 u32 esc_clk_rate;
289 u32 lanes;
290 u32 mode_flags;
291 u32 format;
292 struct videomode vm;
293
294 int state;
295 struct drm_property *brightness;
296 struct completion completed;
297
298 spinlock_t transfer_lock; /* protects transfer_list */
299 struct list_head transfer_list;
YoungJun Cho9a320412014-07-17 18:01:23 +0900300
301 struct exynos_dsi_driver_data *driver_data;
Andrzej Hajda7eb8f062014-04-04 01:19:56 +0900302};
303
304#define host_to_dsi(host) container_of(host, struct exynos_dsi, dsi_host)
305#define connector_to_dsi(c) container_of(c, struct exynos_dsi, connector)
306
YoungJun Cho9a320412014-07-17 18:01:23 +0900307static struct exynos_dsi_driver_data exynos4_dsi_driver_data = {
308 .plltmr_reg = 0x50,
309 .has_freqband = 1,
Inki Dae78d3a8c2014-08-13 17:03:12 +0900310 .has_clklane_stop = 1,
YoungJun Cho9a320412014-07-17 18:01:23 +0900311};
312
313static struct exynos_dsi_driver_data exynos5_dsi_driver_data = {
314 .plltmr_reg = 0x58,
315};
316
317static struct of_device_id exynos_dsi_of_match[] = {
318 { .compatible = "samsung,exynos4210-mipi-dsi",
319 .data = &exynos4_dsi_driver_data },
320 { .compatible = "samsung,exynos5410-mipi-dsi",
321 .data = &exynos5_dsi_driver_data },
322 { }
323};
324
325static inline struct exynos_dsi_driver_data *exynos_dsi_get_driver_data(
326 struct platform_device *pdev)
327{
328 const struct of_device_id *of_id =
329 of_match_device(exynos_dsi_of_match, &pdev->dev);
330
331 return (struct exynos_dsi_driver_data *)of_id->data;
332}
333
Andrzej Hajda7eb8f062014-04-04 01:19:56 +0900334static void exynos_dsi_wait_for_reset(struct exynos_dsi *dsi)
335{
336 if (wait_for_completion_timeout(&dsi->completed, msecs_to_jiffies(300)))
337 return;
338
339 dev_err(dsi->dev, "timeout waiting for reset\n");
340}
341
342static void exynos_dsi_reset(struct exynos_dsi *dsi)
343{
344 reinit_completion(&dsi->completed);
345 writel(DSIM_SWRST, dsi->reg_base + DSIM_SWRST_REG);
346}
347
348#ifndef MHZ
349#define MHZ (1000*1000)
350#endif
351
352static unsigned long exynos_dsi_pll_find_pms(struct exynos_dsi *dsi,
353 unsigned long fin, unsigned long fout, u8 *p, u16 *m, u8 *s)
354{
355 unsigned long best_freq = 0;
356 u32 min_delta = 0xffffffff;
357 u8 p_min, p_max;
358 u8 _p, uninitialized_var(best_p);
359 u16 _m, uninitialized_var(best_m);
360 u8 _s, uninitialized_var(best_s);
361
362 p_min = DIV_ROUND_UP(fin, (12 * MHZ));
363 p_max = fin / (6 * MHZ);
364
365 for (_p = p_min; _p <= p_max; ++_p) {
366 for (_s = 0; _s <= 5; ++_s) {
367 u64 tmp;
368 u32 delta;
369
370 tmp = (u64)fout * (_p << _s);
371 do_div(tmp, fin);
372 _m = tmp;
373 if (_m < 41 || _m > 125)
374 continue;
375
376 tmp = (u64)_m * fin;
377 do_div(tmp, _p);
378 if (tmp < 500 * MHZ || tmp > 1000 * MHZ)
379 continue;
380
381 tmp = (u64)_m * fin;
382 do_div(tmp, _p << _s);
383
384 delta = abs(fout - tmp);
385 if (delta < min_delta) {
386 best_p = _p;
387 best_m = _m;
388 best_s = _s;
389 min_delta = delta;
390 best_freq = tmp;
391 }
392 }
393 }
394
395 if (best_freq) {
396 *p = best_p;
397 *m = best_m;
398 *s = best_s;
399 }
400
401 return best_freq;
402}
403
404static unsigned long exynos_dsi_set_pll(struct exynos_dsi *dsi,
405 unsigned long freq)
406{
YoungJun Cho9a320412014-07-17 18:01:23 +0900407 struct exynos_dsi_driver_data *driver_data = dsi->driver_data;
Andrzej Hajda7eb8f062014-04-04 01:19:56 +0900408 unsigned long fin, fout;
YoungJun Cho9a320412014-07-17 18:01:23 +0900409 int timeout;
Andrzej Hajda7eb8f062014-04-04 01:19:56 +0900410 u8 p, s;
411 u16 m;
412 u32 reg;
413
414 clk_set_rate(dsi->pll_clk, dsi->pll_clk_rate);
415
416 fin = clk_get_rate(dsi->pll_clk);
417 if (!fin) {
418 dev_err(dsi->dev, "failed to get PLL clock frequency\n");
419 return 0;
420 }
421
422 dev_dbg(dsi->dev, "PLL input frequency: %lu\n", fin);
423
424 fout = exynos_dsi_pll_find_pms(dsi, fin, freq, &p, &m, &s);
425 if (!fout) {
426 dev_err(dsi->dev,
427 "failed to find PLL PMS for requested frequency\n");
YoungJun Cho8525b5e2014-08-14 11:22:36 +0900428 return 0;
Andrzej Hajda7eb8f062014-04-04 01:19:56 +0900429 }
YoungJun Cho9a320412014-07-17 18:01:23 +0900430 dev_dbg(dsi->dev, "PLL freq %lu, (p %d, m %d, s %d)\n", fout, p, m, s);
Andrzej Hajda7eb8f062014-04-04 01:19:56 +0900431
YoungJun Cho9a320412014-07-17 18:01:23 +0900432 writel(500, dsi->reg_base + driver_data->plltmr_reg);
Andrzej Hajda7eb8f062014-04-04 01:19:56 +0900433
YoungJun Cho9a320412014-07-17 18:01:23 +0900434 reg = DSIM_PLL_EN | DSIM_PLL_P(p) | DSIM_PLL_M(m) | DSIM_PLL_S(s);
Andrzej Hajda7eb8f062014-04-04 01:19:56 +0900435
YoungJun Cho9a320412014-07-17 18:01:23 +0900436 if (driver_data->has_freqband) {
437 static const unsigned long freq_bands[] = {
438 100 * MHZ, 120 * MHZ, 160 * MHZ, 200 * MHZ,
439 270 * MHZ, 320 * MHZ, 390 * MHZ, 450 * MHZ,
440 510 * MHZ, 560 * MHZ, 640 * MHZ, 690 * MHZ,
441 770 * MHZ, 870 * MHZ, 950 * MHZ,
442 };
443 int band;
Andrzej Hajda7eb8f062014-04-04 01:19:56 +0900444
YoungJun Cho9a320412014-07-17 18:01:23 +0900445 for (band = 0; band < ARRAY_SIZE(freq_bands); ++band)
446 if (fout < freq_bands[band])
447 break;
448
449 dev_dbg(dsi->dev, "band %d\n", band);
450
451 reg |= DSIM_FREQ_BAND(band);
452 }
453
Andrzej Hajda7eb8f062014-04-04 01:19:56 +0900454 writel(reg, dsi->reg_base + DSIM_PLLCTRL_REG);
455
456 timeout = 1000;
457 do {
458 if (timeout-- == 0) {
459 dev_err(dsi->dev, "PLL failed to stabilize\n");
YoungJun Cho8525b5e2014-08-14 11:22:36 +0900460 return 0;
Andrzej Hajda7eb8f062014-04-04 01:19:56 +0900461 }
462 reg = readl(dsi->reg_base + DSIM_STATUS_REG);
463 } while ((reg & DSIM_PLL_STABLE) == 0);
464
465 return fout;
466}
467
468static int exynos_dsi_enable_clock(struct exynos_dsi *dsi)
469{
470 unsigned long hs_clk, byte_clk, esc_clk;
471 unsigned long esc_div;
472 u32 reg;
473
474 hs_clk = exynos_dsi_set_pll(dsi, dsi->burst_clk_rate);
475 if (!hs_clk) {
476 dev_err(dsi->dev, "failed to configure DSI PLL\n");
477 return -EFAULT;
478 }
479
480 byte_clk = hs_clk / 8;
481 esc_div = DIV_ROUND_UP(byte_clk, dsi->esc_clk_rate);
482 esc_clk = byte_clk / esc_div;
483
484 if (esc_clk > 20 * MHZ) {
485 ++esc_div;
486 esc_clk = byte_clk / esc_div;
487 }
488
489 dev_dbg(dsi->dev, "hs_clk = %lu, byte_clk = %lu, esc_clk = %lu\n",
490 hs_clk, byte_clk, esc_clk);
491
492 reg = readl(dsi->reg_base + DSIM_CLKCTRL_REG);
493 reg &= ~(DSIM_ESC_PRESCALER_MASK | DSIM_LANE_ESC_CLK_EN_CLK
494 | DSIM_LANE_ESC_CLK_EN_DATA_MASK | DSIM_PLL_BYPASS
495 | DSIM_BYTE_CLK_SRC_MASK);
496 reg |= DSIM_ESC_CLKEN | DSIM_BYTE_CLKEN
497 | DSIM_ESC_PRESCALER(esc_div)
498 | DSIM_LANE_ESC_CLK_EN_CLK
499 | DSIM_LANE_ESC_CLK_EN_DATA(BIT(dsi->lanes) - 1)
500 | DSIM_BYTE_CLK_SRC(0)
501 | DSIM_TX_REQUEST_HSCLK;
502 writel(reg, dsi->reg_base + DSIM_CLKCTRL_REG);
503
504 return 0;
505}
506
YoungJun Cho9a320412014-07-17 18:01:23 +0900507static void exynos_dsi_set_phy_ctrl(struct exynos_dsi *dsi)
508{
509 struct exynos_dsi_driver_data *driver_data = dsi->driver_data;
510 u32 reg;
511
512 if (driver_data->has_freqband)
513 return;
514
515 /* B D-PHY: D-PHY Master & Slave Analog Block control */
516 reg = DSIM_PHYCTRL_ULPS_EXIT(0x0af);
517 writel(reg, dsi->reg_base + DSIM_PHYCTRL_REG);
518
519 /*
520 * T LPX: Transmitted length of any Low-Power state period
521 * T HS-EXIT: Time that the transmitter drives LP-11 following a HS
522 * burst
523 */
524 reg = DSIM_PHYTIMING_LPX(0x06) | DSIM_PHYTIMING_HS_EXIT(0x0b);
525 writel(reg, dsi->reg_base + DSIM_PHYTIMING_REG);
526
527 /*
528 * T CLK-PREPARE: Time that the transmitter drives the Clock Lane LP-00
529 * Line state immediately before the HS-0 Line state starting the
530 * HS transmission
531 * T CLK-ZERO: Time that the transmitter drives the HS-0 state prior to
532 * transmitting the Clock.
533 * T CLK_POST: Time that the transmitter continues to send HS clock
534 * after the last associated Data Lane has transitioned to LP Mode
535 * Interval is defined as the period from the end of T HS-TRAIL to
536 * the beginning of T CLK-TRAIL
537 * T CLK-TRAIL: Time that the transmitter drives the HS-0 state after
538 * the last payload clock bit of a HS transmission burst
539 */
540 reg = DSIM_PHYTIMING1_CLK_PREPARE(0x07) |
541 DSIM_PHYTIMING1_CLK_ZERO(0x27) |
542 DSIM_PHYTIMING1_CLK_POST(0x0d) |
543 DSIM_PHYTIMING1_CLK_TRAIL(0x08);
544 writel(reg, dsi->reg_base + DSIM_PHYTIMING1_REG);
545
546 /*
547 * T HS-PREPARE: Time that the transmitter drives the Data Lane LP-00
548 * Line state immediately before the HS-0 Line state starting the
549 * HS transmission
550 * T HS-ZERO: Time that the transmitter drives the HS-0 state prior to
551 * transmitting the Sync sequence.
552 * T HS-TRAIL: Time that the transmitter drives the flipped differential
553 * state after last payload data bit of a HS transmission burst
554 */
555 reg = DSIM_PHYTIMING2_HS_PREPARE(0x09) | DSIM_PHYTIMING2_HS_ZERO(0x0d) |
556 DSIM_PHYTIMING2_HS_TRAIL(0x0b);
557 writel(reg, dsi->reg_base + DSIM_PHYTIMING2_REG);
558}
559
Andrzej Hajda7eb8f062014-04-04 01:19:56 +0900560static void exynos_dsi_disable_clock(struct exynos_dsi *dsi)
561{
562 u32 reg;
563
564 reg = readl(dsi->reg_base + DSIM_CLKCTRL_REG);
565 reg &= ~(DSIM_LANE_ESC_CLK_EN_CLK | DSIM_LANE_ESC_CLK_EN_DATA_MASK
566 | DSIM_ESC_CLKEN | DSIM_BYTE_CLKEN);
567 writel(reg, dsi->reg_base + DSIM_CLKCTRL_REG);
568
569 reg = readl(dsi->reg_base + DSIM_PLLCTRL_REG);
570 reg &= ~DSIM_PLL_EN;
571 writel(reg, dsi->reg_base + DSIM_PLLCTRL_REG);
572}
573
574static int exynos_dsi_init_link(struct exynos_dsi *dsi)
575{
Inki Dae78d3a8c2014-08-13 17:03:12 +0900576 struct exynos_dsi_driver_data *driver_data = dsi->driver_data;
Andrzej Hajda7eb8f062014-04-04 01:19:56 +0900577 int timeout;
578 u32 reg;
579 u32 lanes_mask;
580
581 /* Initialize FIFO pointers */
582 reg = readl(dsi->reg_base + DSIM_FIFOCTRL_REG);
583 reg &= ~0x1f;
584 writel(reg, dsi->reg_base + DSIM_FIFOCTRL_REG);
585
586 usleep_range(9000, 11000);
587
588 reg |= 0x1f;
589 writel(reg, dsi->reg_base + DSIM_FIFOCTRL_REG);
590
591 usleep_range(9000, 11000);
592
593 /* DSI configuration */
594 reg = 0;
595
YoungJun Cho2f36e332014-07-17 18:01:16 +0900596 /*
597 * The first bit of mode_flags specifies display configuration.
598 * If this bit is set[= MIPI_DSI_MODE_VIDEO], dsi will support video
599 * mode, otherwise it will support command mode.
600 */
Andrzej Hajda7eb8f062014-04-04 01:19:56 +0900601 if (dsi->mode_flags & MIPI_DSI_MODE_VIDEO) {
602 reg |= DSIM_VIDEO_MODE;
603
YoungJun Cho2f36e332014-07-17 18:01:16 +0900604 /*
605 * The user manual describes that following bits are ignored in
606 * command mode.
607 */
Andrzej Hajda7eb8f062014-04-04 01:19:56 +0900608 if (!(dsi->mode_flags & MIPI_DSI_MODE_VSYNC_FLUSH))
609 reg |= DSIM_MFLUSH_VS;
Andrzej Hajda7eb8f062014-04-04 01:19:56 +0900610 if (dsi->mode_flags & MIPI_DSI_MODE_VIDEO_SYNC_PULSE)
611 reg |= DSIM_SYNC_INFORM;
612 if (dsi->mode_flags & MIPI_DSI_MODE_VIDEO_BURST)
613 reg |= DSIM_BURST_MODE;
614 if (dsi->mode_flags & MIPI_DSI_MODE_VIDEO_AUTO_VERT)
615 reg |= DSIM_AUTO_MODE;
616 if (dsi->mode_flags & MIPI_DSI_MODE_VIDEO_HSE)
617 reg |= DSIM_HSE_MODE;
618 if (!(dsi->mode_flags & MIPI_DSI_MODE_VIDEO_HFP))
619 reg |= DSIM_HFP_MODE;
620 if (!(dsi->mode_flags & MIPI_DSI_MODE_VIDEO_HBP))
621 reg |= DSIM_HBP_MODE;
622 if (!(dsi->mode_flags & MIPI_DSI_MODE_VIDEO_HSA))
623 reg |= DSIM_HSA_MODE;
624 }
625
YoungJun Cho2f36e332014-07-17 18:01:16 +0900626 if (!(dsi->mode_flags & MIPI_DSI_MODE_EOT_PACKET))
627 reg |= DSIM_EOT_DISABLE;
628
Andrzej Hajda7eb8f062014-04-04 01:19:56 +0900629 switch (dsi->format) {
630 case MIPI_DSI_FMT_RGB888:
631 reg |= DSIM_MAIN_PIX_FORMAT_RGB888;
632 break;
633 case MIPI_DSI_FMT_RGB666:
634 reg |= DSIM_MAIN_PIX_FORMAT_RGB666;
635 break;
636 case MIPI_DSI_FMT_RGB666_PACKED:
637 reg |= DSIM_MAIN_PIX_FORMAT_RGB666_P;
638 break;
639 case MIPI_DSI_FMT_RGB565:
640 reg |= DSIM_MAIN_PIX_FORMAT_RGB565;
641 break;
642 default:
643 dev_err(dsi->dev, "invalid pixel format\n");
644 return -EINVAL;
645 }
646
647 reg |= DSIM_NUM_OF_DATA_LANE(dsi->lanes - 1);
648
649 writel(reg, dsi->reg_base + DSIM_CONFIG_REG);
650
651 reg |= DSIM_LANE_EN_CLK;
652 writel(reg, dsi->reg_base + DSIM_CONFIG_REG);
653
654 lanes_mask = BIT(dsi->lanes) - 1;
655 reg |= DSIM_LANE_EN(lanes_mask);
656 writel(reg, dsi->reg_base + DSIM_CONFIG_REG);
657
Inki Dae78d3a8c2014-08-13 17:03:12 +0900658 /*
659 * Use non-continuous clock mode if the periparal wants and
660 * host controller supports
661 *
662 * In non-continous clock mode, host controller will turn off
663 * the HS clock between high-speed transmissions to reduce
664 * power consumption.
665 */
666 if (driver_data->has_clklane_stop &&
667 dsi->mode_flags & MIPI_DSI_CLOCK_NON_CONTINUOUS) {
668 reg |= DSIM_CLKLANE_STOP;
669 writel(reg, dsi->reg_base + DSIM_CONFIG_REG);
670 }
671
Andrzej Hajda7eb8f062014-04-04 01:19:56 +0900672 /* Check clock and data lane state are stop state */
673 timeout = 100;
674 do {
675 if (timeout-- == 0) {
676 dev_err(dsi->dev, "waiting for bus lanes timed out\n");
677 return -EFAULT;
678 }
679
680 reg = readl(dsi->reg_base + DSIM_STATUS_REG);
681 if ((reg & DSIM_STOP_STATE_DAT(lanes_mask))
682 != DSIM_STOP_STATE_DAT(lanes_mask))
683 continue;
684 } while (!(reg & (DSIM_STOP_STATE_CLK | DSIM_TX_READY_HS_CLK)));
685
686 reg = readl(dsi->reg_base + DSIM_ESCMODE_REG);
687 reg &= ~DSIM_STOP_STATE_CNT_MASK;
688 reg |= DSIM_STOP_STATE_CNT(0xf);
689 writel(reg, dsi->reg_base + DSIM_ESCMODE_REG);
690
691 reg = DSIM_BTA_TIMEOUT(0xff) | DSIM_LPDR_TIMEOUT(0xffff);
692 writel(reg, dsi->reg_base + DSIM_TIMEOUT_REG);
693
694 return 0;
695}
696
697static void exynos_dsi_set_display_mode(struct exynos_dsi *dsi)
698{
699 struct videomode *vm = &dsi->vm;
700 u32 reg;
701
702 if (dsi->mode_flags & MIPI_DSI_MODE_VIDEO) {
703 reg = DSIM_CMD_ALLOW(0xf)
704 | DSIM_STABLE_VFP(vm->vfront_porch)
705 | DSIM_MAIN_VBP(vm->vback_porch);
706 writel(reg, dsi->reg_base + DSIM_MVPORCH_REG);
707
708 reg = DSIM_MAIN_HFP(vm->hfront_porch)
709 | DSIM_MAIN_HBP(vm->hback_porch);
710 writel(reg, dsi->reg_base + DSIM_MHPORCH_REG);
711
712 reg = DSIM_MAIN_VSA(vm->vsync_len)
713 | DSIM_MAIN_HSA(vm->hsync_len);
714 writel(reg, dsi->reg_base + DSIM_MSYNC_REG);
715 }
716
717 reg = DSIM_MAIN_HRESOL(vm->hactive) | DSIM_MAIN_VRESOL(vm->vactive);
718 writel(reg, dsi->reg_base + DSIM_MDRESOL_REG);
719
720 dev_dbg(dsi->dev, "LCD size = %dx%d\n", vm->hactive, vm->vactive);
721}
722
723static void exynos_dsi_set_display_enable(struct exynos_dsi *dsi, bool enable)
724{
725 u32 reg;
726
727 reg = readl(dsi->reg_base + DSIM_MDRESOL_REG);
728 if (enable)
729 reg |= DSIM_MAIN_STAND_BY;
730 else
731 reg &= ~DSIM_MAIN_STAND_BY;
732 writel(reg, dsi->reg_base + DSIM_MDRESOL_REG);
733}
734
735static int exynos_dsi_wait_for_hdr_fifo(struct exynos_dsi *dsi)
736{
737 int timeout = 2000;
738
739 do {
740 u32 reg = readl(dsi->reg_base + DSIM_FIFOCTRL_REG);
741
742 if (!(reg & DSIM_SFR_HEADER_FULL))
743 return 0;
744
745 if (!cond_resched())
746 usleep_range(950, 1050);
747 } while (--timeout);
748
749 return -ETIMEDOUT;
750}
751
752static void exynos_dsi_set_cmd_lpm(struct exynos_dsi *dsi, bool lpm)
753{
754 u32 v = readl(dsi->reg_base + DSIM_ESCMODE_REG);
755
756 if (lpm)
757 v |= DSIM_CMD_LPDT_LP;
758 else
759 v &= ~DSIM_CMD_LPDT_LP;
760
761 writel(v, dsi->reg_base + DSIM_ESCMODE_REG);
762}
763
764static void exynos_dsi_force_bta(struct exynos_dsi *dsi)
765{
766 u32 v = readl(dsi->reg_base + DSIM_ESCMODE_REG);
767
768 v |= DSIM_FORCE_BTA;
769 writel(v, dsi->reg_base + DSIM_ESCMODE_REG);
770}
771
772static void exynos_dsi_send_to_fifo(struct exynos_dsi *dsi,
773 struct exynos_dsi_transfer *xfer)
774{
775 struct device *dev = dsi->dev;
776 const u8 *payload = xfer->tx_payload + xfer->tx_done;
777 u16 length = xfer->tx_len - xfer->tx_done;
778 bool first = !xfer->tx_done;
779 u32 reg;
780
781 dev_dbg(dev, "< xfer %p: tx len %u, done %u, rx len %u, done %u\n",
782 xfer, xfer->tx_len, xfer->tx_done, xfer->rx_len, xfer->rx_done);
783
784 if (length > DSI_TX_FIFO_SIZE)
785 length = DSI_TX_FIFO_SIZE;
786
787 xfer->tx_done += length;
788
789 /* Send payload */
790 while (length >= 4) {
791 reg = (payload[3] << 24) | (payload[2] << 16)
792 | (payload[1] << 8) | payload[0];
793 writel(reg, dsi->reg_base + DSIM_PAYLOAD_REG);
794 payload += 4;
795 length -= 4;
796 }
797
798 reg = 0;
799 switch (length) {
800 case 3:
801 reg |= payload[2] << 16;
802 /* Fall through */
803 case 2:
804 reg |= payload[1] << 8;
805 /* Fall through */
806 case 1:
807 reg |= payload[0];
808 writel(reg, dsi->reg_base + DSIM_PAYLOAD_REG);
809 break;
810 case 0:
811 /* Do nothing */
812 break;
813 }
814
815 /* Send packet header */
816 if (!first)
817 return;
818
819 reg = (xfer->data[1] << 16) | (xfer->data[0] << 8) | xfer->data_id;
820 if (exynos_dsi_wait_for_hdr_fifo(dsi)) {
821 dev_err(dev, "waiting for header FIFO timed out\n");
822 return;
823 }
824
825 if (NEQV(xfer->flags & MIPI_DSI_MSG_USE_LPM,
826 dsi->state & DSIM_STATE_CMD_LPM)) {
827 exynos_dsi_set_cmd_lpm(dsi, xfer->flags & MIPI_DSI_MSG_USE_LPM);
828 dsi->state ^= DSIM_STATE_CMD_LPM;
829 }
830
831 writel(reg, dsi->reg_base + DSIM_PKTHDR_REG);
832
833 if (xfer->flags & MIPI_DSI_MSG_REQ_ACK)
834 exynos_dsi_force_bta(dsi);
835}
836
837static void exynos_dsi_read_from_fifo(struct exynos_dsi *dsi,
838 struct exynos_dsi_transfer *xfer)
839{
840 u8 *payload = xfer->rx_payload + xfer->rx_done;
841 bool first = !xfer->rx_done;
842 struct device *dev = dsi->dev;
843 u16 length;
844 u32 reg;
845
846 if (first) {
847 reg = readl(dsi->reg_base + DSIM_RXFIFO_REG);
848
849 switch (reg & 0x3f) {
850 case MIPI_DSI_RX_GENERIC_SHORT_READ_RESPONSE_2BYTE:
851 case MIPI_DSI_RX_DCS_SHORT_READ_RESPONSE_2BYTE:
852 if (xfer->rx_len >= 2) {
853 payload[1] = reg >> 16;
854 ++xfer->rx_done;
855 }
856 /* Fall through */
857 case MIPI_DSI_RX_GENERIC_SHORT_READ_RESPONSE_1BYTE:
858 case MIPI_DSI_RX_DCS_SHORT_READ_RESPONSE_1BYTE:
859 payload[0] = reg >> 8;
860 ++xfer->rx_done;
861 xfer->rx_len = xfer->rx_done;
862 xfer->result = 0;
863 goto clear_fifo;
864 case MIPI_DSI_RX_ACKNOWLEDGE_AND_ERROR_REPORT:
865 dev_err(dev, "DSI Error Report: 0x%04x\n",
866 (reg >> 8) & 0xffff);
867 xfer->result = 0;
868 goto clear_fifo;
869 }
870
871 length = (reg >> 8) & 0xffff;
872 if (length > xfer->rx_len) {
873 dev_err(dev,
874 "response too long (%u > %u bytes), stripping\n",
875 xfer->rx_len, length);
876 length = xfer->rx_len;
877 } else if (length < xfer->rx_len)
878 xfer->rx_len = length;
879 }
880
881 length = xfer->rx_len - xfer->rx_done;
882 xfer->rx_done += length;
883
884 /* Receive payload */
885 while (length >= 4) {
886 reg = readl(dsi->reg_base + DSIM_RXFIFO_REG);
887 payload[0] = (reg >> 0) & 0xff;
888 payload[1] = (reg >> 8) & 0xff;
889 payload[2] = (reg >> 16) & 0xff;
890 payload[3] = (reg >> 24) & 0xff;
891 payload += 4;
892 length -= 4;
893 }
894
895 if (length) {
896 reg = readl(dsi->reg_base + DSIM_RXFIFO_REG);
897 switch (length) {
898 case 3:
899 payload[2] = (reg >> 16) & 0xff;
900 /* Fall through */
901 case 2:
902 payload[1] = (reg >> 8) & 0xff;
903 /* Fall through */
904 case 1:
905 payload[0] = reg & 0xff;
906 }
907 }
908
909 if (xfer->rx_done == xfer->rx_len)
910 xfer->result = 0;
911
912clear_fifo:
913 length = DSI_RX_FIFO_SIZE / 4;
914 do {
915 reg = readl(dsi->reg_base + DSIM_RXFIFO_REG);
916 if (reg == DSI_RX_FIFO_EMPTY)
917 break;
918 } while (--length);
919}
920
921static void exynos_dsi_transfer_start(struct exynos_dsi *dsi)
922{
923 unsigned long flags;
924 struct exynos_dsi_transfer *xfer;
925 bool start = false;
926
927again:
928 spin_lock_irqsave(&dsi->transfer_lock, flags);
929
930 if (list_empty(&dsi->transfer_list)) {
931 spin_unlock_irqrestore(&dsi->transfer_lock, flags);
932 return;
933 }
934
935 xfer = list_first_entry(&dsi->transfer_list,
936 struct exynos_dsi_transfer, list);
937
938 spin_unlock_irqrestore(&dsi->transfer_lock, flags);
939
940 if (xfer->tx_len && xfer->tx_done == xfer->tx_len)
941 /* waiting for RX */
942 return;
943
944 exynos_dsi_send_to_fifo(dsi, xfer);
945
946 if (xfer->tx_len || xfer->rx_len)
947 return;
948
949 xfer->result = 0;
950 complete(&xfer->completed);
951
952 spin_lock_irqsave(&dsi->transfer_lock, flags);
953
954 list_del_init(&xfer->list);
955 start = !list_empty(&dsi->transfer_list);
956
957 spin_unlock_irqrestore(&dsi->transfer_lock, flags);
958
959 if (start)
960 goto again;
961}
962
963static bool exynos_dsi_transfer_finish(struct exynos_dsi *dsi)
964{
965 struct exynos_dsi_transfer *xfer;
966 unsigned long flags;
967 bool start = true;
968
969 spin_lock_irqsave(&dsi->transfer_lock, flags);
970
971 if (list_empty(&dsi->transfer_list)) {
972 spin_unlock_irqrestore(&dsi->transfer_lock, flags);
973 return false;
974 }
975
976 xfer = list_first_entry(&dsi->transfer_list,
977 struct exynos_dsi_transfer, list);
978
979 spin_unlock_irqrestore(&dsi->transfer_lock, flags);
980
981 dev_dbg(dsi->dev,
982 "> xfer %p, tx_len %u, tx_done %u, rx_len %u, rx_done %u\n",
983 xfer, xfer->tx_len, xfer->tx_done, xfer->rx_len, xfer->rx_done);
984
985 if (xfer->tx_done != xfer->tx_len)
986 return true;
987
988 if (xfer->rx_done != xfer->rx_len)
989 exynos_dsi_read_from_fifo(dsi, xfer);
990
991 if (xfer->rx_done != xfer->rx_len)
992 return true;
993
994 spin_lock_irqsave(&dsi->transfer_lock, flags);
995
996 list_del_init(&xfer->list);
997 start = !list_empty(&dsi->transfer_list);
998
999 spin_unlock_irqrestore(&dsi->transfer_lock, flags);
1000
1001 if (!xfer->rx_len)
1002 xfer->result = 0;
1003 complete(&xfer->completed);
1004
1005 return start;
1006}
1007
1008static void exynos_dsi_remove_transfer(struct exynos_dsi *dsi,
1009 struct exynos_dsi_transfer *xfer)
1010{
1011 unsigned long flags;
1012 bool start;
1013
1014 spin_lock_irqsave(&dsi->transfer_lock, flags);
1015
1016 if (!list_empty(&dsi->transfer_list) &&
1017 xfer == list_first_entry(&dsi->transfer_list,
1018 struct exynos_dsi_transfer, list)) {
1019 list_del_init(&xfer->list);
1020 start = !list_empty(&dsi->transfer_list);
1021 spin_unlock_irqrestore(&dsi->transfer_lock, flags);
1022 if (start)
1023 exynos_dsi_transfer_start(dsi);
1024 return;
1025 }
1026
1027 list_del_init(&xfer->list);
1028
1029 spin_unlock_irqrestore(&dsi->transfer_lock, flags);
1030}
1031
1032static int exynos_dsi_transfer(struct exynos_dsi *dsi,
1033 struct exynos_dsi_transfer *xfer)
1034{
1035 unsigned long flags;
1036 bool stopped;
1037
1038 xfer->tx_done = 0;
1039 xfer->rx_done = 0;
1040 xfer->result = -ETIMEDOUT;
1041 init_completion(&xfer->completed);
1042
1043 spin_lock_irqsave(&dsi->transfer_lock, flags);
1044
1045 stopped = list_empty(&dsi->transfer_list);
1046 list_add_tail(&xfer->list, &dsi->transfer_list);
1047
1048 spin_unlock_irqrestore(&dsi->transfer_lock, flags);
1049
1050 if (stopped)
1051 exynos_dsi_transfer_start(dsi);
1052
1053 wait_for_completion_timeout(&xfer->completed,
1054 msecs_to_jiffies(DSI_XFER_TIMEOUT_MS));
1055 if (xfer->result == -ETIMEDOUT) {
1056 exynos_dsi_remove_transfer(dsi, xfer);
1057 dev_err(dsi->dev, "xfer timed out: %*ph %*ph\n", 2, xfer->data,
1058 xfer->tx_len, xfer->tx_payload);
1059 return -ETIMEDOUT;
1060 }
1061
1062 /* Also covers hardware timeout condition */
1063 return xfer->result;
1064}
1065
1066static irqreturn_t exynos_dsi_irq(int irq, void *dev_id)
1067{
1068 struct exynos_dsi *dsi = dev_id;
1069 u32 status;
1070
1071 status = readl(dsi->reg_base + DSIM_INTSRC_REG);
1072 if (!status) {
1073 static unsigned long int j;
1074 if (printk_timed_ratelimit(&j, 500))
1075 dev_warn(dsi->dev, "spurious interrupt\n");
1076 return IRQ_HANDLED;
1077 }
1078 writel(status, dsi->reg_base + DSIM_INTSRC_REG);
1079
1080 if (status & DSIM_INT_SW_RST_RELEASE) {
1081 u32 mask = ~(DSIM_INT_RX_DONE | DSIM_INT_SFR_FIFO_EMPTY);
1082 writel(mask, dsi->reg_base + DSIM_INTMSK_REG);
1083 complete(&dsi->completed);
1084 return IRQ_HANDLED;
1085 }
1086
1087 if (!(status & (DSIM_INT_RX_DONE | DSIM_INT_SFR_FIFO_EMPTY)))
1088 return IRQ_HANDLED;
1089
1090 if (exynos_dsi_transfer_finish(dsi))
1091 exynos_dsi_transfer_start(dsi);
1092
1093 return IRQ_HANDLED;
1094}
1095
YoungJun Choe17ddec2014-07-22 19:49:44 +09001096static irqreturn_t exynos_dsi_te_irq_handler(int irq, void *dev_id)
1097{
1098 struct exynos_dsi *dsi = (struct exynos_dsi *)dev_id;
1099 struct drm_encoder *encoder = dsi->encoder;
1100
1101 if (dsi->state & DSIM_STATE_ENABLED)
1102 exynos_drm_crtc_te_handler(encoder->crtc);
1103
1104 return IRQ_HANDLED;
1105}
1106
1107static void exynos_dsi_enable_irq(struct exynos_dsi *dsi)
1108{
1109 enable_irq(dsi->irq);
1110
1111 if (gpio_is_valid(dsi->te_gpio))
1112 enable_irq(gpio_to_irq(dsi->te_gpio));
1113}
1114
1115static void exynos_dsi_disable_irq(struct exynos_dsi *dsi)
1116{
1117 if (gpio_is_valid(dsi->te_gpio))
1118 disable_irq(gpio_to_irq(dsi->te_gpio));
1119
1120 disable_irq(dsi->irq);
1121}
1122
Andrzej Hajda7eb8f062014-04-04 01:19:56 +09001123static int exynos_dsi_init(struct exynos_dsi *dsi)
1124{
Andrzej Hajda7eb8f062014-04-04 01:19:56 +09001125 exynos_dsi_reset(dsi);
YoungJun Choe17ddec2014-07-22 19:49:44 +09001126 exynos_dsi_enable_irq(dsi);
YoungJun Cho9a320412014-07-17 18:01:23 +09001127 exynos_dsi_enable_clock(dsi);
Andrzej Hajda7eb8f062014-04-04 01:19:56 +09001128 exynos_dsi_wait_for_reset(dsi);
YoungJun Cho9a320412014-07-17 18:01:23 +09001129 exynos_dsi_set_phy_ctrl(dsi);
Andrzej Hajda7eb8f062014-04-04 01:19:56 +09001130 exynos_dsi_init_link(dsi);
1131
1132 return 0;
1133}
1134
YoungJun Choe17ddec2014-07-22 19:49:44 +09001135static int exynos_dsi_register_te_irq(struct exynos_dsi *dsi)
1136{
1137 int ret;
1138
1139 dsi->te_gpio = of_get_named_gpio(dsi->panel_node, "te-gpios", 0);
1140 if (!gpio_is_valid(dsi->te_gpio)) {
1141 dev_err(dsi->dev, "no te-gpios specified\n");
1142 ret = dsi->te_gpio;
1143 goto out;
1144 }
1145
1146 ret = gpio_request_one(dsi->te_gpio, GPIOF_IN, "te_gpio");
1147 if (ret) {
1148 dev_err(dsi->dev, "gpio request failed with %d\n", ret);
1149 goto out;
1150 }
1151
1152 /*
1153 * This TE GPIO IRQ should not be set to IRQ_NOAUTOEN, because panel
1154 * calls drm_panel_init() first then calls mipi_dsi_attach() in probe().
1155 * It means that te_gpio is invalid when exynos_dsi_enable_irq() is
1156 * called by drm_panel_init() before panel is attached.
1157 */
1158 ret = request_threaded_irq(gpio_to_irq(dsi->te_gpio),
1159 exynos_dsi_te_irq_handler, NULL,
1160 IRQF_TRIGGER_RISING, "TE", dsi);
1161 if (ret) {
1162 dev_err(dsi->dev, "request interrupt failed with %d\n", ret);
1163 gpio_free(dsi->te_gpio);
1164 goto out;
1165 }
1166
1167out:
1168 return ret;
1169}
1170
1171static void exynos_dsi_unregister_te_irq(struct exynos_dsi *dsi)
1172{
1173 if (gpio_is_valid(dsi->te_gpio)) {
1174 free_irq(gpio_to_irq(dsi->te_gpio), dsi);
1175 gpio_free(dsi->te_gpio);
1176 dsi->te_gpio = -ENOENT;
1177 }
1178}
1179
Andrzej Hajda7eb8f062014-04-04 01:19:56 +09001180static int exynos_dsi_host_attach(struct mipi_dsi_host *host,
1181 struct mipi_dsi_device *device)
1182{
1183 struct exynos_dsi *dsi = host_to_dsi(host);
1184
1185 dsi->lanes = device->lanes;
1186 dsi->format = device->format;
1187 dsi->mode_flags = device->mode_flags;
1188 dsi->panel_node = device->dev.of_node;
1189
1190 if (dsi->connector.dev)
1191 drm_helper_hpd_irq_event(dsi->connector.dev);
1192
YoungJun Choe17ddec2014-07-22 19:49:44 +09001193 /*
1194 * This is a temporary solution and should be made by more generic way.
1195 *
1196 * If attached panel device is for command mode one, dsi should register
1197 * TE interrupt handler.
1198 */
1199 if (!(dsi->mode_flags & MIPI_DSI_MODE_VIDEO)) {
1200 int ret = exynos_dsi_register_te_irq(dsi);
1201
1202 if (ret)
1203 return ret;
1204 }
1205
Andrzej Hajda7eb8f062014-04-04 01:19:56 +09001206 return 0;
1207}
1208
1209static int exynos_dsi_host_detach(struct mipi_dsi_host *host,
1210 struct mipi_dsi_device *device)
1211{
1212 struct exynos_dsi *dsi = host_to_dsi(host);
1213
YoungJun Choe17ddec2014-07-22 19:49:44 +09001214 exynos_dsi_unregister_te_irq(dsi);
1215
Andrzej Hajda7eb8f062014-04-04 01:19:56 +09001216 dsi->panel_node = NULL;
1217
1218 if (dsi->connector.dev)
1219 drm_helper_hpd_irq_event(dsi->connector.dev);
1220
1221 return 0;
1222}
1223
1224/* distinguish between short and long DSI packet types */
1225static bool exynos_dsi_is_short_dsi_type(u8 type)
1226{
1227 return (type & 0x0f) <= 8;
1228}
1229
1230static ssize_t exynos_dsi_host_transfer(struct mipi_dsi_host *host,
1231 struct mipi_dsi_msg *msg)
1232{
1233 struct exynos_dsi *dsi = host_to_dsi(host);
1234 struct exynos_dsi_transfer xfer;
1235 int ret;
1236
1237 if (!(dsi->state & DSIM_STATE_INITIALIZED)) {
1238 ret = exynos_dsi_init(dsi);
1239 if (ret)
1240 return ret;
1241 dsi->state |= DSIM_STATE_INITIALIZED;
1242 }
1243
1244 if (msg->tx_len == 0)
1245 return -EINVAL;
1246
1247 xfer.data_id = msg->type | (msg->channel << 6);
1248
1249 if (exynos_dsi_is_short_dsi_type(msg->type)) {
1250 const char *tx_buf = msg->tx_buf;
1251
1252 if (msg->tx_len > 2)
1253 return -EINVAL;
1254 xfer.tx_len = 0;
1255 xfer.data[0] = tx_buf[0];
1256 xfer.data[1] = (msg->tx_len == 2) ? tx_buf[1] : 0;
1257 } else {
1258 xfer.tx_len = msg->tx_len;
1259 xfer.data[0] = msg->tx_len & 0xff;
1260 xfer.data[1] = msg->tx_len >> 8;
1261 xfer.tx_payload = msg->tx_buf;
1262 }
1263
1264 xfer.rx_len = msg->rx_len;
1265 xfer.rx_payload = msg->rx_buf;
1266 xfer.flags = msg->flags;
1267
1268 ret = exynos_dsi_transfer(dsi, &xfer);
1269 return (ret < 0) ? ret : xfer.rx_done;
1270}
1271
1272static const struct mipi_dsi_host_ops exynos_dsi_ops = {
1273 .attach = exynos_dsi_host_attach,
1274 .detach = exynos_dsi_host_detach,
1275 .transfer = exynos_dsi_host_transfer,
1276};
1277
1278static int exynos_dsi_poweron(struct exynos_dsi *dsi)
1279{
1280 int ret;
1281
1282 ret = regulator_bulk_enable(ARRAY_SIZE(dsi->supplies), dsi->supplies);
1283 if (ret < 0) {
1284 dev_err(dsi->dev, "cannot enable regulators %d\n", ret);
1285 return ret;
1286 }
1287
1288 ret = clk_prepare_enable(dsi->bus_clk);
1289 if (ret < 0) {
1290 dev_err(dsi->dev, "cannot enable bus clock %d\n", ret);
1291 goto err_bus_clk;
1292 }
1293
1294 ret = clk_prepare_enable(dsi->pll_clk);
1295 if (ret < 0) {
1296 dev_err(dsi->dev, "cannot enable pll clock %d\n", ret);
1297 goto err_pll_clk;
1298 }
1299
1300 ret = phy_power_on(dsi->phy);
1301 if (ret < 0) {
1302 dev_err(dsi->dev, "cannot enable phy %d\n", ret);
1303 goto err_phy;
1304 }
1305
1306 return 0;
1307
1308err_phy:
1309 clk_disable_unprepare(dsi->pll_clk);
1310err_pll_clk:
1311 clk_disable_unprepare(dsi->bus_clk);
1312err_bus_clk:
1313 regulator_bulk_disable(ARRAY_SIZE(dsi->supplies), dsi->supplies);
1314
1315 return ret;
1316}
1317
1318static void exynos_dsi_poweroff(struct exynos_dsi *dsi)
1319{
1320 int ret;
1321
1322 usleep_range(10000, 20000);
1323
1324 if (dsi->state & DSIM_STATE_INITIALIZED) {
1325 dsi->state &= ~DSIM_STATE_INITIALIZED;
1326
1327 exynos_dsi_disable_clock(dsi);
1328
YoungJun Choe17ddec2014-07-22 19:49:44 +09001329 exynos_dsi_disable_irq(dsi);
Andrzej Hajda7eb8f062014-04-04 01:19:56 +09001330 }
1331
1332 dsi->state &= ~DSIM_STATE_CMD_LPM;
1333
1334 phy_power_off(dsi->phy);
1335
1336 clk_disable_unprepare(dsi->pll_clk);
1337 clk_disable_unprepare(dsi->bus_clk);
1338
1339 ret = regulator_bulk_disable(ARRAY_SIZE(dsi->supplies), dsi->supplies);
1340 if (ret < 0)
1341 dev_err(dsi->dev, "cannot disable regulators %d\n", ret);
1342}
1343
1344static int exynos_dsi_enable(struct exynos_dsi *dsi)
1345{
1346 int ret;
1347
1348 if (dsi->state & DSIM_STATE_ENABLED)
1349 return 0;
1350
1351 ret = exynos_dsi_poweron(dsi);
1352 if (ret < 0)
1353 return ret;
1354
Ajay Kumarcdfb8692014-07-31 23:12:06 +05301355 ret = drm_panel_prepare(dsi->panel);
Andrzej Hajda7eb8f062014-04-04 01:19:56 +09001356 if (ret < 0) {
1357 exynos_dsi_poweroff(dsi);
1358 return ret;
1359 }
1360
1361 exynos_dsi_set_display_mode(dsi);
1362 exynos_dsi_set_display_enable(dsi, true);
1363
Ajay Kumarcdfb8692014-07-31 23:12:06 +05301364 ret = drm_panel_enable(dsi->panel);
1365 if (ret < 0) {
1366 exynos_dsi_set_display_enable(dsi, false);
1367 drm_panel_unprepare(dsi->panel);
1368 exynos_dsi_poweroff(dsi);
1369 return ret;
1370 }
1371
Andrzej Hajda7eb8f062014-04-04 01:19:56 +09001372 dsi->state |= DSIM_STATE_ENABLED;
1373
1374 return 0;
1375}
1376
1377static void exynos_dsi_disable(struct exynos_dsi *dsi)
1378{
1379 if (!(dsi->state & DSIM_STATE_ENABLED))
1380 return;
1381
Andrzej Hajda7eb8f062014-04-04 01:19:56 +09001382 drm_panel_disable(dsi->panel);
Ajay Kumarcdfb8692014-07-31 23:12:06 +05301383 exynos_dsi_set_display_enable(dsi, false);
1384 drm_panel_unprepare(dsi->panel);
Andrzej Hajda7eb8f062014-04-04 01:19:56 +09001385 exynos_dsi_poweroff(dsi);
1386
1387 dsi->state &= ~DSIM_STATE_ENABLED;
1388}
1389
1390static void exynos_dsi_dpms(struct exynos_drm_display *display, int mode)
1391{
1392 struct exynos_dsi *dsi = display->ctx;
1393
1394 if (dsi->panel) {
1395 switch (mode) {
1396 case DRM_MODE_DPMS_ON:
1397 exynos_dsi_enable(dsi);
1398 break;
1399 case DRM_MODE_DPMS_STANDBY:
1400 case DRM_MODE_DPMS_SUSPEND:
1401 case DRM_MODE_DPMS_OFF:
1402 exynos_dsi_disable(dsi);
1403 break;
1404 default:
1405 break;
1406 }
1407 }
1408}
1409
1410static enum drm_connector_status
1411exynos_dsi_detect(struct drm_connector *connector, bool force)
1412{
1413 struct exynos_dsi *dsi = connector_to_dsi(connector);
1414
1415 if (!dsi->panel) {
1416 dsi->panel = of_drm_find_panel(dsi->panel_node);
1417 if (dsi->panel)
1418 drm_panel_attach(dsi->panel, &dsi->connector);
1419 } else if (!dsi->panel_node) {
1420 struct exynos_drm_display *display;
1421
1422 display = platform_get_drvdata(to_platform_device(dsi->dev));
1423 exynos_dsi_dpms(display, DRM_MODE_DPMS_OFF);
1424 drm_panel_detach(dsi->panel);
1425 dsi->panel = NULL;
1426 }
1427
1428 if (dsi->panel)
1429 return connector_status_connected;
1430
1431 return connector_status_disconnected;
1432}
1433
1434static void exynos_dsi_connector_destroy(struct drm_connector *connector)
1435{
1436}
1437
1438static struct drm_connector_funcs exynos_dsi_connector_funcs = {
1439 .dpms = drm_helper_connector_dpms,
1440 .detect = exynos_dsi_detect,
1441 .fill_modes = drm_helper_probe_single_connector_modes,
1442 .destroy = exynos_dsi_connector_destroy,
1443};
1444
1445static int exynos_dsi_get_modes(struct drm_connector *connector)
1446{
1447 struct exynos_dsi *dsi = connector_to_dsi(connector);
1448
1449 if (dsi->panel)
1450 return dsi->panel->funcs->get_modes(dsi->panel);
1451
1452 return 0;
1453}
1454
1455static int exynos_dsi_mode_valid(struct drm_connector *connector,
1456 struct drm_display_mode *mode)
1457{
1458 return MODE_OK;
1459}
1460
1461static struct drm_encoder *
1462exynos_dsi_best_encoder(struct drm_connector *connector)
1463{
1464 struct exynos_dsi *dsi = connector_to_dsi(connector);
1465
1466 return dsi->encoder;
1467}
1468
1469static struct drm_connector_helper_funcs exynos_dsi_connector_helper_funcs = {
1470 .get_modes = exynos_dsi_get_modes,
1471 .mode_valid = exynos_dsi_mode_valid,
1472 .best_encoder = exynos_dsi_best_encoder,
1473};
1474
1475static int exynos_dsi_create_connector(struct exynos_drm_display *display,
1476 struct drm_encoder *encoder)
1477{
1478 struct exynos_dsi *dsi = display->ctx;
1479 struct drm_connector *connector = &dsi->connector;
1480 int ret;
1481
1482 dsi->encoder = encoder;
1483
1484 connector->polled = DRM_CONNECTOR_POLL_HPD;
1485
1486 ret = drm_connector_init(encoder->dev, connector,
1487 &exynos_dsi_connector_funcs,
1488 DRM_MODE_CONNECTOR_DSI);
1489 if (ret) {
1490 DRM_ERROR("Failed to initialize connector with drm\n");
1491 return ret;
1492 }
1493
1494 drm_connector_helper_add(connector, &exynos_dsi_connector_helper_funcs);
Thomas Wood34ea3d32014-05-29 16:57:41 +01001495 drm_connector_register(connector);
Andrzej Hajda7eb8f062014-04-04 01:19:56 +09001496 drm_mode_connector_attach_encoder(connector, encoder);
1497
1498 return 0;
1499}
1500
1501static void exynos_dsi_mode_set(struct exynos_drm_display *display,
1502 struct drm_display_mode *mode)
1503{
1504 struct exynos_dsi *dsi = display->ctx;
1505 struct videomode *vm = &dsi->vm;
1506
1507 vm->hactive = mode->hdisplay;
1508 vm->vactive = mode->vdisplay;
1509 vm->vfront_porch = mode->vsync_start - mode->vdisplay;
1510 vm->vback_porch = mode->vtotal - mode->vsync_end;
1511 vm->vsync_len = mode->vsync_end - mode->vsync_start;
1512 vm->hfront_porch = mode->hsync_start - mode->hdisplay;
1513 vm->hback_porch = mode->htotal - mode->hsync_end;
1514 vm->hsync_len = mode->hsync_end - mode->hsync_start;
1515}
1516
1517static struct exynos_drm_display_ops exynos_dsi_display_ops = {
1518 .create_connector = exynos_dsi_create_connector,
1519 .mode_set = exynos_dsi_mode_set,
1520 .dpms = exynos_dsi_dpms
1521};
1522
1523static struct exynos_drm_display exynos_dsi_display = {
1524 .type = EXYNOS_DISPLAY_TYPE_LCD,
1525 .ops = &exynos_dsi_display_ops,
1526};
Sjoerd Simonsbd024b82014-07-30 11:29:41 +09001527MODULE_DEVICE_TABLE(of, exynos_dsi_of_match);
Andrzej Hajda7eb8f062014-04-04 01:19:56 +09001528
1529/* of_* functions will be removed after merge of of_graph patches */
1530static struct device_node *
1531of_get_child_by_name_reg(struct device_node *parent, const char *name, u32 reg)
1532{
1533 struct device_node *np;
1534
1535 for_each_child_of_node(parent, np) {
1536 u32 r;
1537
1538 if (!np->name || of_node_cmp(np->name, name))
1539 continue;
1540
1541 if (of_property_read_u32(np, "reg", &r) < 0)
1542 r = 0;
1543
1544 if (reg == r)
1545 break;
1546 }
1547
1548 return np;
1549}
1550
1551static struct device_node *of_graph_get_port_by_reg(struct device_node *parent,
1552 u32 reg)
1553{
1554 struct device_node *ports, *port;
1555
1556 ports = of_get_child_by_name(parent, "ports");
1557 if (ports)
1558 parent = ports;
1559
1560 port = of_get_child_by_name_reg(parent, "port", reg);
1561
1562 of_node_put(ports);
1563
1564 return port;
1565}
1566
1567static struct device_node *
1568of_graph_get_endpoint_by_reg(struct device_node *port, u32 reg)
1569{
1570 return of_get_child_by_name_reg(port, "endpoint", reg);
1571}
1572
1573static int exynos_dsi_of_read_u32(const struct device_node *np,
1574 const char *propname, u32 *out_value)
1575{
1576 int ret = of_property_read_u32(np, propname, out_value);
1577
1578 if (ret < 0)
1579 pr_err("%s: failed to get '%s' property\n", np->full_name,
1580 propname);
1581
1582 return ret;
1583}
1584
1585enum {
1586 DSI_PORT_IN,
1587 DSI_PORT_OUT
1588};
1589
1590static int exynos_dsi_parse_dt(struct exynos_dsi *dsi)
1591{
1592 struct device *dev = dsi->dev;
1593 struct device_node *node = dev->of_node;
1594 struct device_node *port, *ep;
1595 int ret;
1596
1597 ret = exynos_dsi_of_read_u32(node, "samsung,pll-clock-frequency",
1598 &dsi->pll_clk_rate);
1599 if (ret < 0)
1600 return ret;
1601
1602 port = of_graph_get_port_by_reg(node, DSI_PORT_OUT);
1603 if (!port) {
1604 dev_err(dev, "no output port specified\n");
1605 return -EINVAL;
1606 }
1607
1608 ep = of_graph_get_endpoint_by_reg(port, 0);
1609 of_node_put(port);
1610 if (!ep) {
1611 dev_err(dev, "no endpoint specified in output port\n");
1612 return -EINVAL;
1613 }
1614
1615 ret = exynos_dsi_of_read_u32(ep, "samsung,burst-clock-frequency",
1616 &dsi->burst_clk_rate);
1617 if (ret < 0)
1618 goto end;
1619
1620 ret = exynos_dsi_of_read_u32(ep, "samsung,esc-clock-frequency",
1621 &dsi->esc_clk_rate);
1622
1623end:
1624 of_node_put(ep);
1625
1626 return ret;
1627}
1628
Inki Daef37cd5e2014-05-09 14:25:20 +09001629static int exynos_dsi_bind(struct device *dev, struct device *master,
1630 void *data)
1631{
1632 struct drm_device *drm_dev = data;
1633 struct exynos_dsi *dsi;
1634 int ret;
1635
1636 ret = exynos_drm_create_enc_conn(drm_dev, &exynos_dsi_display);
1637 if (ret) {
1638 DRM_ERROR("Encoder create [%d] failed with %d\n",
1639 exynos_dsi_display.type, ret);
1640 return ret;
1641 }
1642
1643 dsi = exynos_dsi_display.ctx;
1644
1645 return mipi_dsi_host_register(&dsi->dsi_host);
1646}
1647
1648static void exynos_dsi_unbind(struct device *dev, struct device *master,
1649 void *data)
1650{
1651 struct exynos_dsi *dsi = exynos_dsi_display.ctx;
1652 struct drm_encoder *encoder = dsi->encoder;
1653
1654 exynos_dsi_dpms(&exynos_dsi_display, DRM_MODE_DPMS_OFF);
1655
1656 mipi_dsi_host_unregister(&dsi->dsi_host);
1657
1658 encoder->funcs->destroy(encoder);
1659 drm_connector_cleanup(&dsi->connector);
1660}
1661
Inki Daef37cd5e2014-05-09 14:25:20 +09001662static const struct component_ops exynos_dsi_component_ops = {
1663 .bind = exynos_dsi_bind,
1664 .unbind = exynos_dsi_unbind,
1665};
1666
Andrzej Hajda7eb8f062014-04-04 01:19:56 +09001667static int exynos_dsi_probe(struct platform_device *pdev)
1668{
1669 struct resource *res;
1670 struct exynos_dsi *dsi;
1671 int ret;
1672
Inki Daedf5225b2014-05-29 18:28:02 +09001673 ret = exynos_drm_component_add(&pdev->dev, EXYNOS_DEVICE_TYPE_CONNECTOR,
1674 exynos_dsi_display.type);
1675 if (ret)
1676 return ret;
1677
Andrzej Hajda7eb8f062014-04-04 01:19:56 +09001678 dsi = devm_kzalloc(&pdev->dev, sizeof(*dsi), GFP_KERNEL);
1679 if (!dsi) {
1680 dev_err(&pdev->dev, "failed to allocate dsi object.\n");
Inki Daedf5225b2014-05-29 18:28:02 +09001681 ret = -ENOMEM;
1682 goto err_del_component;
Andrzej Hajda7eb8f062014-04-04 01:19:56 +09001683 }
1684
YoungJun Choe17ddec2014-07-22 19:49:44 +09001685 /* To be checked as invalid one */
1686 dsi->te_gpio = -ENOENT;
1687
Andrzej Hajda7eb8f062014-04-04 01:19:56 +09001688 init_completion(&dsi->completed);
1689 spin_lock_init(&dsi->transfer_lock);
1690 INIT_LIST_HEAD(&dsi->transfer_list);
1691
1692 dsi->dsi_host.ops = &exynos_dsi_ops;
1693 dsi->dsi_host.dev = &pdev->dev;
1694
1695 dsi->dev = &pdev->dev;
YoungJun Cho9a320412014-07-17 18:01:23 +09001696 dsi->driver_data = exynos_dsi_get_driver_data(pdev);
Andrzej Hajda7eb8f062014-04-04 01:19:56 +09001697
1698 ret = exynos_dsi_parse_dt(dsi);
1699 if (ret)
Inki Daedf5225b2014-05-29 18:28:02 +09001700 goto err_del_component;
Andrzej Hajda7eb8f062014-04-04 01:19:56 +09001701
1702 dsi->supplies[0].supply = "vddcore";
1703 dsi->supplies[1].supply = "vddio";
1704 ret = devm_regulator_bulk_get(&pdev->dev, ARRAY_SIZE(dsi->supplies),
1705 dsi->supplies);
1706 if (ret) {
1707 dev_info(&pdev->dev, "failed to get regulators: %d\n", ret);
1708 return -EPROBE_DEFER;
1709 }
1710
1711 dsi->pll_clk = devm_clk_get(&pdev->dev, "pll_clk");
1712 if (IS_ERR(dsi->pll_clk)) {
1713 dev_info(&pdev->dev, "failed to get dsi pll input clock\n");
Inki Daedf5225b2014-05-29 18:28:02 +09001714 ret = PTR_ERR(dsi->pll_clk);
1715 goto err_del_component;
Andrzej Hajda7eb8f062014-04-04 01:19:56 +09001716 }
1717
1718 dsi->bus_clk = devm_clk_get(&pdev->dev, "bus_clk");
1719 if (IS_ERR(dsi->bus_clk)) {
1720 dev_info(&pdev->dev, "failed to get dsi bus clock\n");
Inki Daedf5225b2014-05-29 18:28:02 +09001721 ret = PTR_ERR(dsi->bus_clk);
1722 goto err_del_component;
Andrzej Hajda7eb8f062014-04-04 01:19:56 +09001723 }
1724
1725 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1726 dsi->reg_base = devm_ioremap_resource(&pdev->dev, res);
Jingoo Han293d3f62014-04-17 19:08:40 +09001727 if (IS_ERR(dsi->reg_base)) {
Andrzej Hajda7eb8f062014-04-04 01:19:56 +09001728 dev_err(&pdev->dev, "failed to remap io region\n");
Inki Daedf5225b2014-05-29 18:28:02 +09001729 ret = PTR_ERR(dsi->reg_base);
1730 goto err_del_component;
Andrzej Hajda7eb8f062014-04-04 01:19:56 +09001731 }
1732
1733 dsi->phy = devm_phy_get(&pdev->dev, "dsim");
1734 if (IS_ERR(dsi->phy)) {
1735 dev_info(&pdev->dev, "failed to get dsim phy\n");
Inki Daedf5225b2014-05-29 18:28:02 +09001736 ret = PTR_ERR(dsi->phy);
1737 goto err_del_component;
Andrzej Hajda7eb8f062014-04-04 01:19:56 +09001738 }
1739
1740 dsi->irq = platform_get_irq(pdev, 0);
1741 if (dsi->irq < 0) {
1742 dev_err(&pdev->dev, "failed to request dsi irq resource\n");
Inki Daedf5225b2014-05-29 18:28:02 +09001743 ret = dsi->irq;
1744 goto err_del_component;
Andrzej Hajda7eb8f062014-04-04 01:19:56 +09001745 }
1746
1747 irq_set_status_flags(dsi->irq, IRQ_NOAUTOEN);
1748 ret = devm_request_threaded_irq(&pdev->dev, dsi->irq, NULL,
1749 exynos_dsi_irq, IRQF_ONESHOT,
1750 dev_name(&pdev->dev), dsi);
1751 if (ret) {
1752 dev_err(&pdev->dev, "failed to request dsi irq\n");
Inki Daedf5225b2014-05-29 18:28:02 +09001753 goto err_del_component;
Andrzej Hajda7eb8f062014-04-04 01:19:56 +09001754 }
1755
1756 exynos_dsi_display.ctx = dsi;
1757
1758 platform_set_drvdata(pdev, &exynos_dsi_display);
Andrzej Hajda7eb8f062014-04-04 01:19:56 +09001759
Inki Daedf5225b2014-05-29 18:28:02 +09001760 ret = component_add(&pdev->dev, &exynos_dsi_component_ops);
1761 if (ret)
1762 goto err_del_component;
1763
1764 return ret;
1765
1766err_del_component:
1767 exynos_drm_component_del(&pdev->dev, EXYNOS_DEVICE_TYPE_CONNECTOR);
1768 return ret;
Andrzej Hajda7eb8f062014-04-04 01:19:56 +09001769}
1770
1771static int exynos_dsi_remove(struct platform_device *pdev)
1772{
Inki Daedf5225b2014-05-29 18:28:02 +09001773 component_del(&pdev->dev, &exynos_dsi_component_ops);
1774 exynos_drm_component_del(&pdev->dev, EXYNOS_DEVICE_TYPE_CONNECTOR);
1775
Andrzej Hajda7eb8f062014-04-04 01:19:56 +09001776 return 0;
1777}
1778
Andrzej Hajda7eb8f062014-04-04 01:19:56 +09001779struct platform_driver dsi_driver = {
1780 .probe = exynos_dsi_probe,
1781 .remove = exynos_dsi_remove,
1782 .driver = {
1783 .name = "exynos-dsi",
1784 .owner = THIS_MODULE,
Andrzej Hajda7eb8f062014-04-04 01:19:56 +09001785 .of_match_table = exynos_dsi_of_match,
1786 },
1787};
1788
1789MODULE_AUTHOR("Tomasz Figa <t.figa@samsung.com>");
1790MODULE_AUTHOR("Andrzej Hajda <a.hajda@samsung.com>");
1791MODULE_DESCRIPTION("Samsung SoC MIPI DSI Master");
1792MODULE_LICENSE("GPL v2");