sh_mipi_dsi.c 16 KB

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