sh_mipi_dsi.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627
  1. /*
  2. * Renesas SH-mobile MIPI DSI support
  3. *
  4. * Copyright (C) 2010 Guennadi Liakhovetski <g.liakhovetski@gmx.de>
  5. *
  6. * This is free software; you can redistribute it and/or modify
  7. * it under the terms of version 2 of the GNU General Public License as
  8. * published by the Free Software Foundation.
  9. */
  10. #include <linux/bitmap.h>
  11. #include <linux/clk.h>
  12. #include <linux/delay.h>
  13. #include <linux/init.h>
  14. #include <linux/io.h>
  15. #include <linux/platform_device.h>
  16. #include <linux/pm_runtime.h>
  17. #include <linux/slab.h>
  18. #include <linux/string.h>
  19. #include <linux/types.h>
  20. #include <linux/module.h>
  21. #include <video/mipi_display.h>
  22. #include <video/sh_mipi_dsi.h>
  23. #include <video/sh_mobile_lcdc.h>
  24. #define SYSCTRL 0x0000
  25. #define SYSCONF 0x0004
  26. #define TIMSET 0x0008
  27. #define RESREQSET0 0x0018
  28. #define RESREQSET1 0x001c
  29. #define HSTTOVSET 0x0020
  30. #define LPRTOVSET 0x0024
  31. #define TATOVSET 0x0028
  32. #define PRTOVSET 0x002c
  33. #define DSICTRL 0x0030
  34. #define DSIINTE 0x0060
  35. #define PHYCTRL 0x0070
  36. /* relative to linkbase */
  37. #define DTCTR 0x0000
  38. #define VMCTR1 0x0020
  39. #define VMCTR2 0x0024
  40. #define VMLEN1 0x0028
  41. #define VMLEN2 0x002c
  42. #define CMTSRTREQ 0x0070
  43. #define CMTSRTCTR 0x00d0
  44. /* E.g., sh7372 has 2 MIPI-DSIs - one for each LCDC */
  45. #define MAX_SH_MIPI_DSI 2
  46. struct sh_mipi {
  47. void __iomem *base;
  48. void __iomem *linkbase;
  49. struct clk *dsit_clk;
  50. struct platform_device *pdev;
  51. void *next_board_data;
  52. void (*next_display_on)(void *board_data, struct fb_info *info);
  53. void (*next_display_off)(void *board_data);
  54. };
  55. static struct sh_mipi *mipi_dsi[MAX_SH_MIPI_DSI];
  56. /* Protect the above array */
  57. static DEFINE_MUTEX(array_lock);
  58. static struct sh_mipi *sh_mipi_by_handle(int handle)
  59. {
  60. if (handle >= ARRAY_SIZE(mipi_dsi) || handle < 0)
  61. return NULL;
  62. return mipi_dsi[handle];
  63. }
  64. static int sh_mipi_send_short(struct sh_mipi *mipi, u8 dsi_cmd,
  65. u8 cmd, u8 param)
  66. {
  67. u32 data = (dsi_cmd << 24) | (cmd << 16) | (param << 8);
  68. int cnt = 100;
  69. /* transmit a short packet to LCD panel */
  70. iowrite32(1 | data, mipi->linkbase + CMTSRTCTR);
  71. iowrite32(1, mipi->linkbase + CMTSRTREQ);
  72. while ((ioread32(mipi->linkbase + CMTSRTREQ) & 1) && --cnt)
  73. udelay(1);
  74. return cnt ? 0 : -ETIMEDOUT;
  75. }
  76. #define LCD_CHAN2MIPI(c) ((c) < LCDC_CHAN_MAINLCD || (c) > LCDC_CHAN_SUBLCD ? \
  77. -EINVAL : (c) - 1)
  78. static int sh_mipi_dcs(int handle, u8 cmd)
  79. {
  80. struct sh_mipi *mipi = sh_mipi_by_handle(LCD_CHAN2MIPI(handle));
  81. if (!mipi)
  82. return -ENODEV;
  83. return sh_mipi_send_short(mipi, MIPI_DSI_DCS_SHORT_WRITE, cmd, 0);
  84. }
  85. static int sh_mipi_dcs_param(int handle, u8 cmd, u8 param)
  86. {
  87. struct sh_mipi *mipi = sh_mipi_by_handle(LCD_CHAN2MIPI(handle));
  88. if (!mipi)
  89. return -ENODEV;
  90. return sh_mipi_send_short(mipi, MIPI_DSI_DCS_SHORT_WRITE_PARAM, cmd,
  91. param);
  92. }
  93. static void sh_mipi_dsi_enable(struct sh_mipi *mipi, bool enable)
  94. {
  95. /*
  96. * enable LCDC data tx, transition to LPS after completion of each HS
  97. * packet
  98. */
  99. iowrite32(0x00000002 | enable, mipi->linkbase + DTCTR);
  100. }
  101. static void sh_mipi_shutdown(struct platform_device *pdev)
  102. {
  103. struct sh_mipi *mipi = platform_get_drvdata(pdev);
  104. sh_mipi_dsi_enable(mipi, false);
  105. }
  106. static int __init sh_mipi_setup(struct sh_mipi *mipi,
  107. struct sh_mipi_dsi_info *pdata)
  108. {
  109. void __iomem *base = mipi->base;
  110. struct sh_mobile_lcdc_chan_cfg *ch = pdata->lcd_chan;
  111. u32 pctype, datatype, pixfmt, linelength, vmctr2;
  112. u32 tmp, top, bottom, delay, div;
  113. bool yuv;
  114. int bpp;
  115. /*
  116. * Select data format. MIPI DSI is not hot-pluggable, so, we just use
  117. * the default videomode. If this ever becomes a problem, We'll have to
  118. * move this to mipi_display_on() above and use info->var.xres
  119. */
  120. switch (pdata->data_format) {
  121. case MIPI_RGB888:
  122. pctype = 0;
  123. datatype = MIPI_DSI_PACKED_PIXEL_STREAM_24;
  124. pixfmt = MIPI_DCS_PIXEL_FMT_24BIT;
  125. linelength = ch->lcd_cfg[0].xres * 3;
  126. yuv = false;
  127. break;
  128. case MIPI_RGB565:
  129. pctype = 1;
  130. datatype = MIPI_DSI_PACKED_PIXEL_STREAM_16;
  131. pixfmt = MIPI_DCS_PIXEL_FMT_16BIT;
  132. linelength = ch->lcd_cfg[0].xres * 2;
  133. yuv = false;
  134. break;
  135. case MIPI_RGB666_LP:
  136. pctype = 2;
  137. datatype = MIPI_DSI_PIXEL_STREAM_3BYTE_18;
  138. pixfmt = MIPI_DCS_PIXEL_FMT_24BIT;
  139. linelength = ch->lcd_cfg[0].xres * 3;
  140. yuv = false;
  141. break;
  142. case MIPI_RGB666:
  143. pctype = 3;
  144. datatype = MIPI_DSI_PACKED_PIXEL_STREAM_18;
  145. pixfmt = MIPI_DCS_PIXEL_FMT_18BIT;
  146. linelength = (ch->lcd_cfg[0].xres * 18 + 7) / 8;
  147. yuv = false;
  148. break;
  149. case MIPI_BGR888:
  150. pctype = 8;
  151. datatype = MIPI_DSI_PACKED_PIXEL_STREAM_24;
  152. pixfmt = MIPI_DCS_PIXEL_FMT_24BIT;
  153. linelength = ch->lcd_cfg[0].xres * 3;
  154. yuv = false;
  155. break;
  156. case MIPI_BGR565:
  157. pctype = 9;
  158. datatype = MIPI_DSI_PACKED_PIXEL_STREAM_16;
  159. pixfmt = MIPI_DCS_PIXEL_FMT_16BIT;
  160. linelength = ch->lcd_cfg[0].xres * 2;
  161. yuv = false;
  162. break;
  163. case MIPI_BGR666_LP:
  164. pctype = 0xa;
  165. datatype = MIPI_DSI_PIXEL_STREAM_3BYTE_18;
  166. pixfmt = MIPI_DCS_PIXEL_FMT_24BIT;
  167. linelength = ch->lcd_cfg[0].xres * 3;
  168. yuv = false;
  169. break;
  170. case MIPI_BGR666:
  171. pctype = 0xb;
  172. datatype = MIPI_DSI_PACKED_PIXEL_STREAM_18;
  173. pixfmt = MIPI_DCS_PIXEL_FMT_18BIT;
  174. linelength = (ch->lcd_cfg[0].xres * 18 + 7) / 8;
  175. yuv = false;
  176. break;
  177. case MIPI_YUYV:
  178. pctype = 4;
  179. datatype = MIPI_DSI_PACKED_PIXEL_STREAM_YCBCR16;
  180. pixfmt = MIPI_DCS_PIXEL_FMT_16BIT;
  181. linelength = ch->lcd_cfg[0].xres * 2;
  182. yuv = true;
  183. break;
  184. case MIPI_UYVY:
  185. pctype = 5;
  186. datatype = MIPI_DSI_PACKED_PIXEL_STREAM_YCBCR16;
  187. pixfmt = MIPI_DCS_PIXEL_FMT_16BIT;
  188. linelength = ch->lcd_cfg[0].xres * 2;
  189. yuv = true;
  190. break;
  191. case MIPI_YUV420_L:
  192. pctype = 6;
  193. datatype = MIPI_DSI_PACKED_PIXEL_STREAM_YCBCR12;
  194. pixfmt = MIPI_DCS_PIXEL_FMT_12BIT;
  195. linelength = (ch->lcd_cfg[0].xres * 12 + 7) / 8;
  196. yuv = true;
  197. break;
  198. case MIPI_YUV420:
  199. pctype = 7;
  200. datatype = MIPI_DSI_PACKED_PIXEL_STREAM_YCBCR12;
  201. pixfmt = MIPI_DCS_PIXEL_FMT_12BIT;
  202. /* Length of U/V line */
  203. linelength = (ch->lcd_cfg[0].xres + 1) / 2;
  204. yuv = true;
  205. break;
  206. default:
  207. return -EINVAL;
  208. }
  209. if ((yuv && ch->interface_type != YUV422) ||
  210. (!yuv && ch->interface_type != RGB24))
  211. return -EINVAL;
  212. if (!pdata->lane)
  213. return -EINVAL;
  214. /* reset DSI link */
  215. iowrite32(0x00000001, base + SYSCTRL);
  216. /* Hold reset for 100 cycles of the slowest of bus, HS byte and LP clock */
  217. udelay(50);
  218. iowrite32(0x00000000, base + SYSCTRL);
  219. /* setup DSI link */
  220. /*
  221. * T_wakeup = 0x7000
  222. * T_hs-trail = 3
  223. * T_hs-prepare = 3
  224. * T_clk-trail = 3
  225. * T_clk-prepare = 2
  226. */
  227. iowrite32(0x70003332, base + TIMSET);
  228. /* no responses requested */
  229. iowrite32(0x00000000, base + RESREQSET0);
  230. /* request response to packets of type 0x28 */
  231. iowrite32(0x00000100, base + RESREQSET1);
  232. /* High-speed transmission timeout, default 0xffffffff */
  233. iowrite32(0x0fffffff, base + HSTTOVSET);
  234. /* LP reception timeout, default 0xffffffff */
  235. iowrite32(0x0fffffff, base + LPRTOVSET);
  236. /* Turn-around timeout, default 0xffffffff */
  237. iowrite32(0x0fffffff, base + TATOVSET);
  238. /* Peripheral reset timeout, default 0xffffffff */
  239. iowrite32(0x0fffffff, base + PRTOVSET);
  240. /* Interrupts not used, disable all */
  241. iowrite32(0, base + DSIINTE);
  242. /* DSI-Tx bias on */
  243. iowrite32(0x00000001, base + PHYCTRL);
  244. udelay(200);
  245. /* Deassert resets, power on */
  246. iowrite32(0x03070001, base + PHYCTRL);
  247. /*
  248. * Default = ULPS enable |
  249. * Contention detection enabled |
  250. * EoT packet transmission enable |
  251. * CRC check enable |
  252. * ECC check enable
  253. */
  254. bitmap_fill((unsigned long *)&tmp, pdata->lane);
  255. tmp |= 0x00003700;
  256. iowrite32(tmp, base + SYSCONF);
  257. /* setup l-bridge */
  258. /*
  259. * Enable transmission of all packets,
  260. * transmit LPS after each HS packet completion
  261. */
  262. iowrite32(0x00000006, mipi->linkbase + DTCTR);
  263. /* VSYNC width = 2 (<< 17) */
  264. iowrite32((ch->lcd_cfg[0].vsync_len << pdata->vsynw_offset) |
  265. (pdata->clksrc << 16) | (pctype << 12) | datatype,
  266. mipi->linkbase + VMCTR1);
  267. /*
  268. * Non-burst mode with sync pulses: VSE and HSE are output,
  269. * HSA period allowed, no commands in LP
  270. */
  271. vmctr2 = 0;
  272. if (pdata->flags & SH_MIPI_DSI_VSEE)
  273. vmctr2 |= 1 << 23;
  274. if (pdata->flags & SH_MIPI_DSI_HSEE)
  275. vmctr2 |= 1 << 22;
  276. if (pdata->flags & SH_MIPI_DSI_HSAE)
  277. vmctr2 |= 1 << 21;
  278. if (pdata->flags & SH_MIPI_DSI_BL2E)
  279. vmctr2 |= 1 << 17;
  280. if (pdata->flags & SH_MIPI_DSI_HSABM)
  281. vmctr2 |= 1 << 5;
  282. if (pdata->flags & SH_MIPI_DSI_HBPBM)
  283. vmctr2 |= 1 << 4;
  284. if (pdata->flags & SH_MIPI_DSI_HFPBM)
  285. vmctr2 |= 1 << 3;
  286. iowrite32(vmctr2, mipi->linkbase + VMCTR2);
  287. /*
  288. * VMLEN1 = RGBLEN | HSALEN
  289. *
  290. * see
  291. * Video mode - Blanking Packet setting
  292. */
  293. top = linelength << 16; /* RGBLEN */
  294. bottom = 0x00000001;
  295. if (pdata->flags & SH_MIPI_DSI_HSABM) /* HSALEN */
  296. bottom = (pdata->lane * ch->lcd_cfg[0].hsync_len) - 10;
  297. iowrite32(top | bottom , mipi->linkbase + VMLEN1);
  298. /*
  299. * VMLEN2 = HBPLEN | HFPLEN
  300. *
  301. * see
  302. * Video mode - Blanking Packet setting
  303. */
  304. top = 0x00010000;
  305. bottom = 0x00000001;
  306. delay = 0;
  307. div = 1; /* HSbyteCLK is calculation base
  308. * HS4divCLK = HSbyteCLK/2
  309. * HS6divCLK is not supported for now */
  310. if (pdata->flags & SH_MIPI_DSI_HS4divCLK)
  311. div = 2;
  312. if (pdata->flags & SH_MIPI_DSI_HFPBM) { /* HBPLEN */
  313. top = ch->lcd_cfg[0].hsync_len + ch->lcd_cfg[0].left_margin;
  314. top = ((pdata->lane * top / div) - 10) << 16;
  315. }
  316. if (pdata->flags & SH_MIPI_DSI_HBPBM) { /* HFPLEN */
  317. bottom = ch->lcd_cfg[0].right_margin;
  318. bottom = (pdata->lane * bottom / div) - 12;
  319. }
  320. bpp = linelength / ch->lcd_cfg[0].xres; /* byte / pixel */
  321. if ((pdata->lane / div) > bpp) {
  322. tmp = ch->lcd_cfg[0].xres / bpp; /* output cycle */
  323. tmp = ch->lcd_cfg[0].xres - tmp; /* (input - output) cycle */
  324. delay = (pdata->lane * tmp);
  325. }
  326. iowrite32(top | (bottom + delay) , mipi->linkbase + VMLEN2);
  327. msleep(5);
  328. /* setup LCD panel */
  329. /* cf. drivers/video/omap/lcd_mipid.c */
  330. sh_mipi_dcs(ch->chan, MIPI_DCS_EXIT_SLEEP_MODE);
  331. msleep(120);
  332. /*
  333. * [7] - Page Address Mode
  334. * [6] - Column Address Mode
  335. * [5] - Page / Column Address Mode
  336. * [4] - Display Device Line Refresh Order
  337. * [3] - RGB/BGR Order
  338. * [2] - Display Data Latch Data Order
  339. * [1] - Flip Horizontal
  340. * [0] - Flip Vertical
  341. */
  342. sh_mipi_dcs_param(ch->chan, MIPI_DCS_SET_ADDRESS_MODE, 0x00);
  343. /* cf. set_data_lines() */
  344. sh_mipi_dcs_param(ch->chan, MIPI_DCS_SET_PIXEL_FORMAT,
  345. pixfmt << 4);
  346. sh_mipi_dcs(ch->chan, MIPI_DCS_SET_DISPLAY_ON);
  347. /* Enable timeout counters */
  348. iowrite32(0x00000f00, base + DSICTRL);
  349. return 0;
  350. }
  351. static void mipi_display_on(void *arg, struct fb_info *info)
  352. {
  353. struct sh_mipi *mipi = arg;
  354. struct sh_mipi_dsi_info *pdata = mipi->pdev->dev.platform_data;
  355. int ret;
  356. pm_runtime_get_sync(&mipi->pdev->dev);
  357. ret = pdata->set_dot_clock(mipi->pdev, mipi->base, 1);
  358. if (ret < 0)
  359. goto mipi_display_on_fail1;
  360. ret = sh_mipi_setup(mipi, pdata);
  361. if (ret < 0)
  362. goto mipi_display_on_fail2;
  363. sh_mipi_dsi_enable(mipi, true);
  364. if (mipi->next_display_on)
  365. mipi->next_display_on(mipi->next_board_data, info);
  366. return;
  367. mipi_display_on_fail1:
  368. pm_runtime_put_sync(&mipi->pdev->dev);
  369. mipi_display_on_fail2:
  370. pdata->set_dot_clock(mipi->pdev, mipi->base, 0);
  371. }
  372. static void mipi_display_off(void *arg)
  373. {
  374. struct sh_mipi *mipi = arg;
  375. struct sh_mipi_dsi_info *pdata = mipi->pdev->dev.platform_data;
  376. if (mipi->next_display_off)
  377. mipi->next_display_off(mipi->next_board_data);
  378. sh_mipi_dsi_enable(mipi, false);
  379. pdata->set_dot_clock(mipi->pdev, mipi->base, 0);
  380. pm_runtime_put_sync(&mipi->pdev->dev);
  381. }
  382. static int __init sh_mipi_probe(struct platform_device *pdev)
  383. {
  384. struct sh_mipi *mipi;
  385. struct sh_mipi_dsi_info *pdata = pdev->dev.platform_data;
  386. struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  387. struct resource *res2 = platform_get_resource(pdev, IORESOURCE_MEM, 1);
  388. unsigned long rate, f_current;
  389. int idx = pdev->id, ret;
  390. if (!res || !res2 || idx >= ARRAY_SIZE(mipi_dsi) || !pdata)
  391. return -ENODEV;
  392. if (!pdata->set_dot_clock)
  393. return -EINVAL;
  394. mutex_lock(&array_lock);
  395. if (idx < 0)
  396. for (idx = 0; idx < ARRAY_SIZE(mipi_dsi) && mipi_dsi[idx]; idx++)
  397. ;
  398. if (idx == ARRAY_SIZE(mipi_dsi)) {
  399. ret = -EBUSY;
  400. goto efindslot;
  401. }
  402. mipi = kzalloc(sizeof(*mipi), GFP_KERNEL);
  403. if (!mipi) {
  404. ret = -ENOMEM;
  405. goto ealloc;
  406. }
  407. if (!request_mem_region(res->start, resource_size(res), pdev->name)) {
  408. dev_err(&pdev->dev, "MIPI register region already claimed\n");
  409. ret = -EBUSY;
  410. goto ereqreg;
  411. }
  412. mipi->base = ioremap(res->start, resource_size(res));
  413. if (!mipi->base) {
  414. ret = -ENOMEM;
  415. goto emap;
  416. }
  417. if (!request_mem_region(res2->start, resource_size(res2), pdev->name)) {
  418. dev_err(&pdev->dev, "MIPI register region 2 already claimed\n");
  419. ret = -EBUSY;
  420. goto ereqreg2;
  421. }
  422. mipi->linkbase = ioremap(res2->start, resource_size(res2));
  423. if (!mipi->linkbase) {
  424. ret = -ENOMEM;
  425. goto emap2;
  426. }
  427. mipi->pdev = pdev;
  428. mipi->dsit_clk = clk_get(&pdev->dev, "dsit_clk");
  429. if (IS_ERR(mipi->dsit_clk)) {
  430. ret = PTR_ERR(mipi->dsit_clk);
  431. goto eclktget;
  432. }
  433. f_current = clk_get_rate(mipi->dsit_clk);
  434. /* 80MHz required by the datasheet */
  435. rate = clk_round_rate(mipi->dsit_clk, 80000000);
  436. if (rate > 0 && rate != f_current)
  437. ret = clk_set_rate(mipi->dsit_clk, rate);
  438. else
  439. ret = rate;
  440. if (ret < 0)
  441. goto esettrate;
  442. dev_dbg(&pdev->dev, "DSI-T clk %lu -> %lu\n", f_current, rate);
  443. ret = clk_enable(mipi->dsit_clk);
  444. if (ret < 0)
  445. goto eclkton;
  446. mipi_dsi[idx] = mipi;
  447. pm_runtime_enable(&pdev->dev);
  448. pm_runtime_resume(&pdev->dev);
  449. mutex_unlock(&array_lock);
  450. platform_set_drvdata(pdev, mipi);
  451. /* Save original LCDC callbacks */
  452. mipi->next_board_data = pdata->lcd_chan->board_cfg.board_data;
  453. mipi->next_display_on = pdata->lcd_chan->board_cfg.display_on;
  454. mipi->next_display_off = pdata->lcd_chan->board_cfg.display_off;
  455. /* Set up LCDC callbacks */
  456. pdata->lcd_chan->board_cfg.board_data = mipi;
  457. pdata->lcd_chan->board_cfg.display_on = mipi_display_on;
  458. pdata->lcd_chan->board_cfg.display_off = mipi_display_off;
  459. pdata->lcd_chan->board_cfg.owner = THIS_MODULE;
  460. return 0;
  461. eclkton:
  462. esettrate:
  463. clk_put(mipi->dsit_clk);
  464. eclktget:
  465. iounmap(mipi->linkbase);
  466. emap2:
  467. release_mem_region(res2->start, resource_size(res2));
  468. ereqreg2:
  469. iounmap(mipi->base);
  470. emap:
  471. release_mem_region(res->start, resource_size(res));
  472. ereqreg:
  473. kfree(mipi);
  474. ealloc:
  475. efindslot:
  476. mutex_unlock(&array_lock);
  477. return ret;
  478. }
  479. static int __exit sh_mipi_remove(struct platform_device *pdev)
  480. {
  481. struct sh_mipi_dsi_info *pdata = pdev->dev.platform_data;
  482. struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  483. struct resource *res2 = platform_get_resource(pdev, IORESOURCE_MEM, 1);
  484. struct sh_mipi *mipi = platform_get_drvdata(pdev);
  485. int i, ret;
  486. mutex_lock(&array_lock);
  487. for (i = 0; i < ARRAY_SIZE(mipi_dsi) && mipi_dsi[i] != mipi; i++)
  488. ;
  489. if (i == ARRAY_SIZE(mipi_dsi)) {
  490. ret = -EINVAL;
  491. } else {
  492. ret = 0;
  493. mipi_dsi[i] = NULL;
  494. }
  495. mutex_unlock(&array_lock);
  496. if (ret < 0)
  497. return ret;
  498. pdata->lcd_chan->board_cfg.owner = NULL;
  499. pdata->lcd_chan->board_cfg.display_on = NULL;
  500. pdata->lcd_chan->board_cfg.display_off = NULL;
  501. pdata->lcd_chan->board_cfg.board_data = NULL;
  502. pm_runtime_disable(&pdev->dev);
  503. clk_disable(mipi->dsit_clk);
  504. clk_put(mipi->dsit_clk);
  505. iounmap(mipi->linkbase);
  506. if (res2)
  507. release_mem_region(res2->start, resource_size(res2));
  508. iounmap(mipi->base);
  509. if (res)
  510. release_mem_region(res->start, resource_size(res));
  511. platform_set_drvdata(pdev, NULL);
  512. kfree(mipi);
  513. return 0;
  514. }
  515. static struct platform_driver sh_mipi_driver = {
  516. .remove = __exit_p(sh_mipi_remove),
  517. .shutdown = sh_mipi_shutdown,
  518. .driver = {
  519. .name = "sh-mipi-dsi",
  520. },
  521. };
  522. static int __init sh_mipi_init(void)
  523. {
  524. return platform_driver_probe(&sh_mipi_driver, sh_mipi_probe);
  525. }
  526. module_init(sh_mipi_init);
  527. static void __exit sh_mipi_exit(void)
  528. {
  529. platform_driver_unregister(&sh_mipi_driver);
  530. }
  531. module_exit(sh_mipi_exit);
  532. MODULE_AUTHOR("Guennadi Liakhovetski <g.liakhovetski@gmx.de>");
  533. MODULE_DESCRIPTION("SuperH / ARM-shmobile MIPI DSI driver");
  534. MODULE_LICENSE("GPL v2");