sh_mobile_lcdcfb.c 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200
  1. /*
  2. * SuperH Mobile LCDC Framebuffer
  3. *
  4. * Copyright (c) 2008 Magnus Damm
  5. *
  6. * This file is subject to the terms and conditions of the GNU General Public
  7. * License. See the file "COPYING" in the main directory of this archive
  8. * for more details.
  9. */
  10. #include <linux/kernel.h>
  11. #include <linux/init.h>
  12. #include <linux/delay.h>
  13. #include <linux/mm.h>
  14. #include <linux/fb.h>
  15. #include <linux/clk.h>
  16. #include <linux/pm_runtime.h>
  17. #include <linux/platform_device.h>
  18. #include <linux/dma-mapping.h>
  19. #include <linux/interrupt.h>
  20. #include <linux/vmalloc.h>
  21. #include <linux/ioctl.h>
  22. #include <video/sh_mobile_lcdc.h>
  23. #include <asm/atomic.h>
  24. #define PALETTE_NR 16
  25. #define SIDE_B_OFFSET 0x1000
  26. #define MIRROR_OFFSET 0x2000
  27. /* shared registers */
  28. #define _LDDCKR 0x410
  29. #define _LDDCKSTPR 0x414
  30. #define _LDINTR 0x468
  31. #define _LDSR 0x46c
  32. #define _LDCNT1R 0x470
  33. #define _LDCNT2R 0x474
  34. #define _LDRCNTR 0x478
  35. #define _LDDDSR 0x47c
  36. #define _LDDWD0R 0x800
  37. #define _LDDRDR 0x840
  38. #define _LDDWAR 0x900
  39. #define _LDDRAR 0x904
  40. /* shared registers and their order for context save/restore */
  41. static int lcdc_shared_regs[] = {
  42. _LDDCKR,
  43. _LDDCKSTPR,
  44. _LDINTR,
  45. _LDDDSR,
  46. _LDCNT1R,
  47. _LDCNT2R,
  48. };
  49. #define NR_SHARED_REGS ARRAY_SIZE(lcdc_shared_regs)
  50. /* per-channel registers */
  51. enum { LDDCKPAT1R, LDDCKPAT2R, LDMT1R, LDMT2R, LDMT3R, LDDFR, LDSM1R,
  52. LDSM2R, LDSA1R, LDMLSR, LDHCNR, LDHSYNR, LDVLNR, LDVSYNR, LDPMR,
  53. NR_CH_REGS };
  54. static unsigned long lcdc_offs_mainlcd[NR_CH_REGS] = {
  55. [LDDCKPAT1R] = 0x400,
  56. [LDDCKPAT2R] = 0x404,
  57. [LDMT1R] = 0x418,
  58. [LDMT2R] = 0x41c,
  59. [LDMT3R] = 0x420,
  60. [LDDFR] = 0x424,
  61. [LDSM1R] = 0x428,
  62. [LDSM2R] = 0x42c,
  63. [LDSA1R] = 0x430,
  64. [LDMLSR] = 0x438,
  65. [LDHCNR] = 0x448,
  66. [LDHSYNR] = 0x44c,
  67. [LDVLNR] = 0x450,
  68. [LDVSYNR] = 0x454,
  69. [LDPMR] = 0x460,
  70. };
  71. static unsigned long lcdc_offs_sublcd[NR_CH_REGS] = {
  72. [LDDCKPAT1R] = 0x408,
  73. [LDDCKPAT2R] = 0x40c,
  74. [LDMT1R] = 0x600,
  75. [LDMT2R] = 0x604,
  76. [LDMT3R] = 0x608,
  77. [LDDFR] = 0x60c,
  78. [LDSM1R] = 0x610,
  79. [LDSM2R] = 0x614,
  80. [LDSA1R] = 0x618,
  81. [LDMLSR] = 0x620,
  82. [LDHCNR] = 0x624,
  83. [LDHSYNR] = 0x628,
  84. [LDVLNR] = 0x62c,
  85. [LDVSYNR] = 0x630,
  86. [LDPMR] = 0x63c,
  87. };
  88. #define START_LCDC 0x00000001
  89. #define LCDC_RESET 0x00000100
  90. #define DISPLAY_BEU 0x00000008
  91. #define LCDC_ENABLE 0x00000001
  92. #define LDINTR_FE 0x00000400
  93. #define LDINTR_VSE 0x00000200
  94. #define LDINTR_VEE 0x00000100
  95. #define LDINTR_FS 0x00000004
  96. #define LDINTR_VSS 0x00000002
  97. #define LDINTR_VES 0x00000001
  98. #define LDRCNTR_SRS 0x00020000
  99. #define LDRCNTR_SRC 0x00010000
  100. #define LDRCNTR_MRS 0x00000002
  101. #define LDRCNTR_MRC 0x00000001
  102. #define LDSR_MRS 0x00000100
  103. struct sh_mobile_lcdc_priv;
  104. struct sh_mobile_lcdc_chan {
  105. struct sh_mobile_lcdc_priv *lcdc;
  106. unsigned long *reg_offs;
  107. unsigned long ldmt1r_value;
  108. unsigned long enabled; /* ME and SE in LDCNT2R */
  109. struct sh_mobile_lcdc_chan_cfg cfg;
  110. u32 pseudo_palette[PALETTE_NR];
  111. unsigned long saved_ch_regs[NR_CH_REGS];
  112. struct fb_info *info;
  113. dma_addr_t dma_handle;
  114. struct fb_deferred_io defio;
  115. struct scatterlist *sglist;
  116. unsigned long frame_end;
  117. unsigned long pan_offset;
  118. wait_queue_head_t frame_end_wait;
  119. struct completion vsync_completion;
  120. };
  121. struct sh_mobile_lcdc_priv {
  122. void __iomem *base;
  123. int irq;
  124. atomic_t hw_usecnt;
  125. struct device *dev;
  126. struct clk *dot_clk;
  127. unsigned long lddckr;
  128. struct sh_mobile_lcdc_chan ch[2];
  129. unsigned long saved_shared_regs[NR_SHARED_REGS];
  130. int started;
  131. };
  132. static bool banked(int reg_nr)
  133. {
  134. switch (reg_nr) {
  135. case LDMT1R:
  136. case LDMT2R:
  137. case LDMT3R:
  138. case LDDFR:
  139. case LDSM1R:
  140. case LDSA1R:
  141. case LDMLSR:
  142. case LDHCNR:
  143. case LDHSYNR:
  144. case LDVLNR:
  145. case LDVSYNR:
  146. return true;
  147. }
  148. return false;
  149. }
  150. static void lcdc_write_chan(struct sh_mobile_lcdc_chan *chan,
  151. int reg_nr, unsigned long data)
  152. {
  153. iowrite32(data, chan->lcdc->base + chan->reg_offs[reg_nr]);
  154. if (banked(reg_nr))
  155. iowrite32(data, chan->lcdc->base + chan->reg_offs[reg_nr] +
  156. SIDE_B_OFFSET);
  157. }
  158. static void lcdc_write_chan_mirror(struct sh_mobile_lcdc_chan *chan,
  159. int reg_nr, unsigned long data)
  160. {
  161. iowrite32(data, chan->lcdc->base + chan->reg_offs[reg_nr] +
  162. MIRROR_OFFSET);
  163. }
  164. static unsigned long lcdc_read_chan(struct sh_mobile_lcdc_chan *chan,
  165. int reg_nr)
  166. {
  167. return ioread32(chan->lcdc->base + chan->reg_offs[reg_nr]);
  168. }
  169. static void lcdc_write(struct sh_mobile_lcdc_priv *priv,
  170. unsigned long reg_offs, unsigned long data)
  171. {
  172. iowrite32(data, priv->base + reg_offs);
  173. }
  174. static unsigned long lcdc_read(struct sh_mobile_lcdc_priv *priv,
  175. unsigned long reg_offs)
  176. {
  177. return ioread32(priv->base + reg_offs);
  178. }
  179. static void lcdc_wait_bit(struct sh_mobile_lcdc_priv *priv,
  180. unsigned long reg_offs,
  181. unsigned long mask, unsigned long until)
  182. {
  183. while ((lcdc_read(priv, reg_offs) & mask) != until)
  184. cpu_relax();
  185. }
  186. static int lcdc_chan_is_sublcd(struct sh_mobile_lcdc_chan *chan)
  187. {
  188. return chan->cfg.chan == LCDC_CHAN_SUBLCD;
  189. }
  190. static void lcdc_sys_write_index(void *handle, unsigned long data)
  191. {
  192. struct sh_mobile_lcdc_chan *ch = handle;
  193. lcdc_write(ch->lcdc, _LDDWD0R, data | 0x10000000);
  194. lcdc_wait_bit(ch->lcdc, _LDSR, 2, 0);
  195. lcdc_write(ch->lcdc, _LDDWAR, 1 | (lcdc_chan_is_sublcd(ch) ? 2 : 0));
  196. lcdc_wait_bit(ch->lcdc, _LDSR, 2, 0);
  197. }
  198. static void lcdc_sys_write_data(void *handle, unsigned long data)
  199. {
  200. struct sh_mobile_lcdc_chan *ch = handle;
  201. lcdc_write(ch->lcdc, _LDDWD0R, data | 0x11000000);
  202. lcdc_wait_bit(ch->lcdc, _LDSR, 2, 0);
  203. lcdc_write(ch->lcdc, _LDDWAR, 1 | (lcdc_chan_is_sublcd(ch) ? 2 : 0));
  204. lcdc_wait_bit(ch->lcdc, _LDSR, 2, 0);
  205. }
  206. static unsigned long lcdc_sys_read_data(void *handle)
  207. {
  208. struct sh_mobile_lcdc_chan *ch = handle;
  209. lcdc_write(ch->lcdc, _LDDRDR, 0x01000000);
  210. lcdc_wait_bit(ch->lcdc, _LDSR, 2, 0);
  211. lcdc_write(ch->lcdc, _LDDRAR, 1 | (lcdc_chan_is_sublcd(ch) ? 2 : 0));
  212. udelay(1);
  213. lcdc_wait_bit(ch->lcdc, _LDSR, 2, 0);
  214. return lcdc_read(ch->lcdc, _LDDRDR) & 0x3ffff;
  215. }
  216. struct sh_mobile_lcdc_sys_bus_ops sh_mobile_lcdc_sys_bus_ops = {
  217. lcdc_sys_write_index,
  218. lcdc_sys_write_data,
  219. lcdc_sys_read_data,
  220. };
  221. static void sh_mobile_lcdc_clk_on(struct sh_mobile_lcdc_priv *priv)
  222. {
  223. if (atomic_inc_and_test(&priv->hw_usecnt)) {
  224. pm_runtime_get_sync(priv->dev);
  225. if (priv->dot_clk)
  226. clk_enable(priv->dot_clk);
  227. }
  228. }
  229. static void sh_mobile_lcdc_clk_off(struct sh_mobile_lcdc_priv *priv)
  230. {
  231. if (atomic_sub_return(1, &priv->hw_usecnt) == -1) {
  232. if (priv->dot_clk)
  233. clk_disable(priv->dot_clk);
  234. pm_runtime_put(priv->dev);
  235. }
  236. }
  237. static int sh_mobile_lcdc_sginit(struct fb_info *info,
  238. struct list_head *pagelist)
  239. {
  240. struct sh_mobile_lcdc_chan *ch = info->par;
  241. unsigned int nr_pages_max = info->fix.smem_len >> PAGE_SHIFT;
  242. struct page *page;
  243. int nr_pages = 0;
  244. sg_init_table(ch->sglist, nr_pages_max);
  245. list_for_each_entry(page, pagelist, lru)
  246. sg_set_page(&ch->sglist[nr_pages++], page, PAGE_SIZE, 0);
  247. return nr_pages;
  248. }
  249. static void sh_mobile_lcdc_deferred_io(struct fb_info *info,
  250. struct list_head *pagelist)
  251. {
  252. struct sh_mobile_lcdc_chan *ch = info->par;
  253. struct sh_mobile_lcdc_board_cfg *bcfg = &ch->cfg.board_cfg;
  254. /* enable clocks before accessing hardware */
  255. sh_mobile_lcdc_clk_on(ch->lcdc);
  256. /*
  257. * It's possible to get here without anything on the pagelist via
  258. * sh_mobile_lcdc_deferred_io_touch() or via a userspace fsync()
  259. * invocation. In the former case, the acceleration routines are
  260. * stepped in to when using the framebuffer console causing the
  261. * workqueue to be scheduled without any dirty pages on the list.
  262. *
  263. * Despite this, a panel update is still needed given that the
  264. * acceleration routines have their own methods for writing in
  265. * that still need to be updated.
  266. *
  267. * The fsync() and empty pagelist case could be optimized for,
  268. * but we don't bother, as any application exhibiting such
  269. * behaviour is fundamentally broken anyways.
  270. */
  271. if (!list_empty(pagelist)) {
  272. unsigned int nr_pages = sh_mobile_lcdc_sginit(info, pagelist);
  273. /* trigger panel update */
  274. dma_map_sg(info->dev, ch->sglist, nr_pages, DMA_TO_DEVICE);
  275. if (bcfg->start_transfer)
  276. bcfg->start_transfer(bcfg->board_data, ch,
  277. &sh_mobile_lcdc_sys_bus_ops);
  278. lcdc_write_chan(ch, LDSM2R, 1);
  279. dma_unmap_sg(info->dev, ch->sglist, nr_pages, DMA_TO_DEVICE);
  280. } else {
  281. if (bcfg->start_transfer)
  282. bcfg->start_transfer(bcfg->board_data, ch,
  283. &sh_mobile_lcdc_sys_bus_ops);
  284. lcdc_write_chan(ch, LDSM2R, 1);
  285. }
  286. }
  287. static void sh_mobile_lcdc_deferred_io_touch(struct fb_info *info)
  288. {
  289. struct fb_deferred_io *fbdefio = info->fbdefio;
  290. if (fbdefio)
  291. schedule_delayed_work(&info->deferred_work, fbdefio->delay);
  292. }
  293. static irqreturn_t sh_mobile_lcdc_irq(int irq, void *data)
  294. {
  295. struct sh_mobile_lcdc_priv *priv = data;
  296. struct sh_mobile_lcdc_chan *ch;
  297. unsigned long tmp;
  298. unsigned long ldintr;
  299. int is_sub;
  300. int k;
  301. /* acknowledge interrupt */
  302. ldintr = tmp = lcdc_read(priv, _LDINTR);
  303. /*
  304. * disable further VSYNC End IRQs, preserve all other enabled IRQs,
  305. * write 0 to bits 0-6 to ack all triggered IRQs.
  306. */
  307. tmp &= 0xffffff00 & ~LDINTR_VEE;
  308. lcdc_write(priv, _LDINTR, tmp);
  309. /* figure out if this interrupt is for main or sub lcd */
  310. is_sub = (lcdc_read(priv, _LDSR) & (1 << 10)) ? 1 : 0;
  311. /* wake up channel and disable clocks */
  312. for (k = 0; k < ARRAY_SIZE(priv->ch); k++) {
  313. ch = &priv->ch[k];
  314. if (!ch->enabled)
  315. continue;
  316. /* Frame Start */
  317. if (ldintr & LDINTR_FS) {
  318. if (is_sub == lcdc_chan_is_sublcd(ch)) {
  319. ch->frame_end = 1;
  320. wake_up(&ch->frame_end_wait);
  321. sh_mobile_lcdc_clk_off(priv);
  322. }
  323. }
  324. /* VSYNC End */
  325. if (ldintr & LDINTR_VES)
  326. complete(&ch->vsync_completion);
  327. }
  328. return IRQ_HANDLED;
  329. }
  330. static void sh_mobile_lcdc_start_stop(struct sh_mobile_lcdc_priv *priv,
  331. int start)
  332. {
  333. unsigned long tmp = lcdc_read(priv, _LDCNT2R);
  334. int k;
  335. /* start or stop the lcdc */
  336. if (start)
  337. lcdc_write(priv, _LDCNT2R, tmp | START_LCDC);
  338. else
  339. lcdc_write(priv, _LDCNT2R, tmp & ~START_LCDC);
  340. /* wait until power is applied/stopped on all channels */
  341. for (k = 0; k < ARRAY_SIZE(priv->ch); k++)
  342. if (lcdc_read(priv, _LDCNT2R) & priv->ch[k].enabled)
  343. while (1) {
  344. tmp = lcdc_read_chan(&priv->ch[k], LDPMR) & 3;
  345. if (start && tmp == 3)
  346. break;
  347. if (!start && tmp == 0)
  348. break;
  349. cpu_relax();
  350. }
  351. if (!start)
  352. lcdc_write(priv, _LDDCKSTPR, 1); /* stop dotclock */
  353. }
  354. static int sh_mobile_lcdc_start(struct sh_mobile_lcdc_priv *priv)
  355. {
  356. struct sh_mobile_lcdc_chan *ch;
  357. struct fb_videomode *lcd_cfg;
  358. struct sh_mobile_lcdc_board_cfg *board_cfg;
  359. unsigned long tmp;
  360. int k, m;
  361. int ret = 0;
  362. /* enable clocks before accessing the hardware */
  363. for (k = 0; k < ARRAY_SIZE(priv->ch); k++)
  364. if (priv->ch[k].enabled)
  365. sh_mobile_lcdc_clk_on(priv);
  366. /* reset */
  367. lcdc_write(priv, _LDCNT2R, lcdc_read(priv, _LDCNT2R) | LCDC_RESET);
  368. lcdc_wait_bit(priv, _LDCNT2R, LCDC_RESET, 0);
  369. /* enable LCDC channels */
  370. tmp = lcdc_read(priv, _LDCNT2R);
  371. tmp |= priv->ch[0].enabled;
  372. tmp |= priv->ch[1].enabled;
  373. lcdc_write(priv, _LDCNT2R, tmp);
  374. /* read data from external memory, avoid using the BEU for now */
  375. lcdc_write(priv, _LDCNT2R, lcdc_read(priv, _LDCNT2R) & ~DISPLAY_BEU);
  376. /* stop the lcdc first */
  377. sh_mobile_lcdc_start_stop(priv, 0);
  378. /* configure clocks */
  379. tmp = priv->lddckr;
  380. for (k = 0; k < ARRAY_SIZE(priv->ch); k++) {
  381. ch = &priv->ch[k];
  382. if (!priv->ch[k].enabled)
  383. continue;
  384. m = ch->cfg.clock_divider;
  385. if (!m)
  386. continue;
  387. if (m == 1)
  388. m = 1 << 6;
  389. tmp |= m << (lcdc_chan_is_sublcd(ch) ? 8 : 0);
  390. lcdc_write_chan(ch, LDDCKPAT1R, 0x00000000);
  391. lcdc_write_chan(ch, LDDCKPAT2R, (1 << (m/2)) - 1);
  392. }
  393. lcdc_write(priv, _LDDCKR, tmp);
  394. /* start dotclock again */
  395. lcdc_write(priv, _LDDCKSTPR, 0);
  396. lcdc_wait_bit(priv, _LDDCKSTPR, ~0, 0);
  397. /* interrupts are disabled to begin with */
  398. lcdc_write(priv, _LDINTR, 0);
  399. for (k = 0; k < ARRAY_SIZE(priv->ch); k++) {
  400. ch = &priv->ch[k];
  401. lcd_cfg = &ch->cfg.lcd_cfg;
  402. if (!ch->enabled)
  403. continue;
  404. tmp = ch->ldmt1r_value;
  405. tmp |= (lcd_cfg->sync & FB_SYNC_VERT_HIGH_ACT) ? 0 : 1 << 28;
  406. tmp |= (lcd_cfg->sync & FB_SYNC_HOR_HIGH_ACT) ? 0 : 1 << 27;
  407. tmp |= (ch->cfg.flags & LCDC_FLAGS_DWPOL) ? 1 << 26 : 0;
  408. tmp |= (ch->cfg.flags & LCDC_FLAGS_DIPOL) ? 1 << 25 : 0;
  409. tmp |= (ch->cfg.flags & LCDC_FLAGS_DAPOL) ? 1 << 24 : 0;
  410. tmp |= (ch->cfg.flags & LCDC_FLAGS_HSCNT) ? 1 << 17 : 0;
  411. tmp |= (ch->cfg.flags & LCDC_FLAGS_DWCNT) ? 1 << 16 : 0;
  412. lcdc_write_chan(ch, LDMT1R, tmp);
  413. /* setup SYS bus */
  414. lcdc_write_chan(ch, LDMT2R, ch->cfg.sys_bus_cfg.ldmt2r);
  415. lcdc_write_chan(ch, LDMT3R, ch->cfg.sys_bus_cfg.ldmt3r);
  416. /* horizontal configuration */
  417. tmp = lcd_cfg->xres + lcd_cfg->hsync_len;
  418. tmp += lcd_cfg->left_margin;
  419. tmp += lcd_cfg->right_margin;
  420. tmp /= 8; /* HTCN */
  421. tmp |= (lcd_cfg->xres / 8) << 16; /* HDCN */
  422. lcdc_write_chan(ch, LDHCNR, tmp);
  423. tmp = lcd_cfg->xres;
  424. tmp += lcd_cfg->right_margin;
  425. tmp /= 8; /* HSYNP */
  426. tmp |= (lcd_cfg->hsync_len / 8) << 16; /* HSYNW */
  427. lcdc_write_chan(ch, LDHSYNR, tmp);
  428. /* power supply */
  429. lcdc_write_chan(ch, LDPMR, 0);
  430. /* vertical configuration */
  431. tmp = lcd_cfg->yres + lcd_cfg->vsync_len;
  432. tmp += lcd_cfg->upper_margin;
  433. tmp += lcd_cfg->lower_margin; /* VTLN */
  434. tmp |= lcd_cfg->yres << 16; /* VDLN */
  435. lcdc_write_chan(ch, LDVLNR, tmp);
  436. tmp = lcd_cfg->yres;
  437. tmp += lcd_cfg->lower_margin; /* VSYNP */
  438. tmp |= lcd_cfg->vsync_len << 16; /* VSYNW */
  439. lcdc_write_chan(ch, LDVSYNR, tmp);
  440. board_cfg = &ch->cfg.board_cfg;
  441. if (board_cfg->setup_sys)
  442. ret = board_cfg->setup_sys(board_cfg->board_data, ch,
  443. &sh_mobile_lcdc_sys_bus_ops);
  444. if (ret)
  445. return ret;
  446. }
  447. /* word and long word swap */
  448. lcdc_write(priv, _LDDDSR, lcdc_read(priv, _LDDDSR) | 6);
  449. for (k = 0; k < ARRAY_SIZE(priv->ch); k++) {
  450. ch = &priv->ch[k];
  451. if (!priv->ch[k].enabled)
  452. continue;
  453. /* set bpp format in PKF[4:0] */
  454. tmp = lcdc_read_chan(ch, LDDFR);
  455. tmp &= ~(0x0001001f);
  456. tmp |= (ch->info->var.bits_per_pixel == 16) ? 3 : 0;
  457. lcdc_write_chan(ch, LDDFR, tmp);
  458. /* point out our frame buffer */
  459. lcdc_write_chan(ch, LDSA1R, ch->info->fix.smem_start);
  460. /* set line size */
  461. lcdc_write_chan(ch, LDMLSR, ch->info->fix.line_length);
  462. /* setup deferred io if SYS bus */
  463. tmp = ch->cfg.sys_bus_cfg.deferred_io_msec;
  464. if (ch->ldmt1r_value & (1 << 12) && tmp) {
  465. ch->defio.deferred_io = sh_mobile_lcdc_deferred_io;
  466. ch->defio.delay = msecs_to_jiffies(tmp);
  467. ch->info->fbdefio = &ch->defio;
  468. fb_deferred_io_init(ch->info);
  469. /* one-shot mode */
  470. lcdc_write_chan(ch, LDSM1R, 1);
  471. /* enable "Frame End Interrupt Enable" bit */
  472. lcdc_write(priv, _LDINTR, LDINTR_FE);
  473. } else {
  474. /* continuous read mode */
  475. lcdc_write_chan(ch, LDSM1R, 0);
  476. }
  477. }
  478. /* display output */
  479. lcdc_write(priv, _LDCNT1R, LCDC_ENABLE);
  480. /* start the lcdc */
  481. sh_mobile_lcdc_start_stop(priv, 1);
  482. priv->started = 1;
  483. /* tell the board code to enable the panel */
  484. for (k = 0; k < ARRAY_SIZE(priv->ch); k++) {
  485. ch = &priv->ch[k];
  486. if (!ch->enabled)
  487. continue;
  488. board_cfg = &ch->cfg.board_cfg;
  489. if (board_cfg->display_on)
  490. board_cfg->display_on(board_cfg->board_data);
  491. }
  492. return 0;
  493. }
  494. static void sh_mobile_lcdc_stop(struct sh_mobile_lcdc_priv *priv)
  495. {
  496. struct sh_mobile_lcdc_chan *ch;
  497. struct sh_mobile_lcdc_board_cfg *board_cfg;
  498. int k;
  499. /* clean up deferred io and ask board code to disable panel */
  500. for (k = 0; k < ARRAY_SIZE(priv->ch); k++) {
  501. ch = &priv->ch[k];
  502. if (!ch->enabled)
  503. continue;
  504. /* deferred io mode:
  505. * flush frame, and wait for frame end interrupt
  506. * clean up deferred io and enable clock
  507. */
  508. if (ch->info->fbdefio) {
  509. ch->frame_end = 0;
  510. schedule_delayed_work(&ch->info->deferred_work, 0);
  511. wait_event(ch->frame_end_wait, ch->frame_end);
  512. fb_deferred_io_cleanup(ch->info);
  513. ch->info->fbdefio = NULL;
  514. sh_mobile_lcdc_clk_on(priv);
  515. }
  516. board_cfg = &ch->cfg.board_cfg;
  517. if (board_cfg->display_off)
  518. board_cfg->display_off(board_cfg->board_data);
  519. }
  520. /* stop the lcdc */
  521. if (priv->started) {
  522. sh_mobile_lcdc_start_stop(priv, 0);
  523. priv->started = 0;
  524. }
  525. /* stop clocks */
  526. for (k = 0; k < ARRAY_SIZE(priv->ch); k++)
  527. if (priv->ch[k].enabled)
  528. sh_mobile_lcdc_clk_off(priv);
  529. }
  530. static int sh_mobile_lcdc_check_interface(struct sh_mobile_lcdc_chan *ch)
  531. {
  532. int ifm, miftyp;
  533. switch (ch->cfg.interface_type) {
  534. case RGB8: ifm = 0; miftyp = 0; break;
  535. case RGB9: ifm = 0; miftyp = 4; break;
  536. case RGB12A: ifm = 0; miftyp = 5; break;
  537. case RGB12B: ifm = 0; miftyp = 6; break;
  538. case RGB16: ifm = 0; miftyp = 7; break;
  539. case RGB18: ifm = 0; miftyp = 10; break;
  540. case RGB24: ifm = 0; miftyp = 11; break;
  541. case SYS8A: ifm = 1; miftyp = 0; break;
  542. case SYS8B: ifm = 1; miftyp = 1; break;
  543. case SYS8C: ifm = 1; miftyp = 2; break;
  544. case SYS8D: ifm = 1; miftyp = 3; break;
  545. case SYS9: ifm = 1; miftyp = 4; break;
  546. case SYS12: ifm = 1; miftyp = 5; break;
  547. case SYS16A: ifm = 1; miftyp = 7; break;
  548. case SYS16B: ifm = 1; miftyp = 8; break;
  549. case SYS16C: ifm = 1; miftyp = 9; break;
  550. case SYS18: ifm = 1; miftyp = 10; break;
  551. case SYS24: ifm = 1; miftyp = 11; break;
  552. default: goto bad;
  553. }
  554. /* SUBLCD only supports SYS interface */
  555. if (lcdc_chan_is_sublcd(ch)) {
  556. if (ifm == 0)
  557. goto bad;
  558. else
  559. ifm = 0;
  560. }
  561. ch->ldmt1r_value = (ifm << 12) | miftyp;
  562. return 0;
  563. bad:
  564. return -EINVAL;
  565. }
  566. static int sh_mobile_lcdc_setup_clocks(struct platform_device *pdev,
  567. int clock_source,
  568. struct sh_mobile_lcdc_priv *priv)
  569. {
  570. char *str;
  571. int icksel;
  572. switch (clock_source) {
  573. case LCDC_CLK_BUS: str = "bus_clk"; icksel = 0; break;
  574. case LCDC_CLK_PERIPHERAL: str = "peripheral_clk"; icksel = 1; break;
  575. case LCDC_CLK_EXTERNAL: str = NULL; icksel = 2; break;
  576. default:
  577. return -EINVAL;
  578. }
  579. priv->lddckr = icksel << 16;
  580. if (str) {
  581. priv->dot_clk = clk_get(&pdev->dev, str);
  582. if (IS_ERR(priv->dot_clk)) {
  583. dev_err(&pdev->dev, "cannot get dot clock %s\n", str);
  584. return PTR_ERR(priv->dot_clk);
  585. }
  586. }
  587. atomic_set(&priv->hw_usecnt, -1);
  588. /* Runtime PM support involves two step for this driver:
  589. * 1) Enable Runtime PM
  590. * 2) Force Runtime PM Resume since hardware is accessed from probe()
  591. */
  592. pm_runtime_enable(priv->dev);
  593. pm_runtime_resume(priv->dev);
  594. return 0;
  595. }
  596. static int sh_mobile_lcdc_setcolreg(u_int regno,
  597. u_int red, u_int green, u_int blue,
  598. u_int transp, struct fb_info *info)
  599. {
  600. u32 *palette = info->pseudo_palette;
  601. if (regno >= PALETTE_NR)
  602. return -EINVAL;
  603. /* only FB_VISUAL_TRUECOLOR supported */
  604. red >>= 16 - info->var.red.length;
  605. green >>= 16 - info->var.green.length;
  606. blue >>= 16 - info->var.blue.length;
  607. transp >>= 16 - info->var.transp.length;
  608. palette[regno] = (red << info->var.red.offset) |
  609. (green << info->var.green.offset) |
  610. (blue << info->var.blue.offset) |
  611. (transp << info->var.transp.offset);
  612. return 0;
  613. }
  614. static struct fb_fix_screeninfo sh_mobile_lcdc_fix = {
  615. .id = "SH Mobile LCDC",
  616. .type = FB_TYPE_PACKED_PIXELS,
  617. .visual = FB_VISUAL_TRUECOLOR,
  618. .accel = FB_ACCEL_NONE,
  619. .xpanstep = 0,
  620. .ypanstep = 1,
  621. .ywrapstep = 0,
  622. };
  623. static void sh_mobile_lcdc_fillrect(struct fb_info *info,
  624. const struct fb_fillrect *rect)
  625. {
  626. sys_fillrect(info, rect);
  627. sh_mobile_lcdc_deferred_io_touch(info);
  628. }
  629. static void sh_mobile_lcdc_copyarea(struct fb_info *info,
  630. const struct fb_copyarea *area)
  631. {
  632. sys_copyarea(info, area);
  633. sh_mobile_lcdc_deferred_io_touch(info);
  634. }
  635. static void sh_mobile_lcdc_imageblit(struct fb_info *info,
  636. const struct fb_image *image)
  637. {
  638. sys_imageblit(info, image);
  639. sh_mobile_lcdc_deferred_io_touch(info);
  640. }
  641. static int sh_mobile_fb_pan_display(struct fb_var_screeninfo *var,
  642. struct fb_info *info)
  643. {
  644. struct sh_mobile_lcdc_chan *ch = info->par;
  645. struct sh_mobile_lcdc_priv *priv = ch->lcdc;
  646. unsigned long ldrcntr;
  647. unsigned long new_pan_offset;
  648. new_pan_offset = (var->yoffset * info->fix.line_length) +
  649. (var->xoffset * (info->var.bits_per_pixel / 8));
  650. if (new_pan_offset == ch->pan_offset)
  651. return 0; /* No change, do nothing */
  652. ldrcntr = lcdc_read(priv, _LDRCNTR);
  653. /* Set the source address for the next refresh */
  654. lcdc_write_chan_mirror(ch, LDSA1R, ch->dma_handle + new_pan_offset);
  655. if (lcdc_chan_is_sublcd(ch))
  656. lcdc_write(ch->lcdc, _LDRCNTR, ldrcntr ^ LDRCNTR_SRS);
  657. else
  658. lcdc_write(ch->lcdc, _LDRCNTR, ldrcntr ^ LDRCNTR_MRS);
  659. ch->pan_offset = new_pan_offset;
  660. sh_mobile_lcdc_deferred_io_touch(info);
  661. return 0;
  662. }
  663. static int sh_mobile_wait_for_vsync(struct fb_info *info)
  664. {
  665. struct sh_mobile_lcdc_chan *ch = info->par;
  666. unsigned long ldintr;
  667. int ret;
  668. /* Enable VSync End interrupt */
  669. ldintr = lcdc_read(ch->lcdc, _LDINTR);
  670. ldintr |= LDINTR_VEE;
  671. lcdc_write(ch->lcdc, _LDINTR, ldintr);
  672. ret = wait_for_completion_interruptible_timeout(&ch->vsync_completion,
  673. msecs_to_jiffies(100));
  674. if (!ret)
  675. return -ETIMEDOUT;
  676. return 0;
  677. }
  678. static int sh_mobile_ioctl(struct fb_info *info, unsigned int cmd,
  679. unsigned long arg)
  680. {
  681. int retval;
  682. switch (cmd) {
  683. case FBIO_WAITFORVSYNC:
  684. retval = sh_mobile_wait_for_vsync(info);
  685. break;
  686. default:
  687. retval = -ENOIOCTLCMD;
  688. break;
  689. }
  690. return retval;
  691. }
  692. static struct fb_ops sh_mobile_lcdc_ops = {
  693. .owner = THIS_MODULE,
  694. .fb_setcolreg = sh_mobile_lcdc_setcolreg,
  695. .fb_read = fb_sys_read,
  696. .fb_write = fb_sys_write,
  697. .fb_fillrect = sh_mobile_lcdc_fillrect,
  698. .fb_copyarea = sh_mobile_lcdc_copyarea,
  699. .fb_imageblit = sh_mobile_lcdc_imageblit,
  700. .fb_pan_display = sh_mobile_fb_pan_display,
  701. .fb_ioctl = sh_mobile_ioctl,
  702. };
  703. static int sh_mobile_lcdc_set_bpp(struct fb_var_screeninfo *var, int bpp)
  704. {
  705. switch (bpp) {
  706. case 16: /* PKF[4:0] = 00011 - RGB 565 */
  707. var->red.offset = 11;
  708. var->red.length = 5;
  709. var->green.offset = 5;
  710. var->green.length = 6;
  711. var->blue.offset = 0;
  712. var->blue.length = 5;
  713. var->transp.offset = 0;
  714. var->transp.length = 0;
  715. break;
  716. case 32: /* PKF[4:0] = 00000 - RGB 888
  717. * sh7722 pdf says 00RRGGBB but reality is GGBB00RR
  718. * this may be because LDDDSR has word swap enabled..
  719. */
  720. var->red.offset = 0;
  721. var->red.length = 8;
  722. var->green.offset = 24;
  723. var->green.length = 8;
  724. var->blue.offset = 16;
  725. var->blue.length = 8;
  726. var->transp.offset = 0;
  727. var->transp.length = 0;
  728. break;
  729. default:
  730. return -EINVAL;
  731. }
  732. var->bits_per_pixel = bpp;
  733. var->red.msb_right = 0;
  734. var->green.msb_right = 0;
  735. var->blue.msb_right = 0;
  736. var->transp.msb_right = 0;
  737. return 0;
  738. }
  739. static int sh_mobile_lcdc_suspend(struct device *dev)
  740. {
  741. struct platform_device *pdev = to_platform_device(dev);
  742. sh_mobile_lcdc_stop(platform_get_drvdata(pdev));
  743. return 0;
  744. }
  745. static int sh_mobile_lcdc_resume(struct device *dev)
  746. {
  747. struct platform_device *pdev = to_platform_device(dev);
  748. return sh_mobile_lcdc_start(platform_get_drvdata(pdev));
  749. }
  750. static int sh_mobile_lcdc_runtime_suspend(struct device *dev)
  751. {
  752. struct platform_device *pdev = to_platform_device(dev);
  753. struct sh_mobile_lcdc_priv *p = platform_get_drvdata(pdev);
  754. struct sh_mobile_lcdc_chan *ch;
  755. int k, n;
  756. /* save per-channel registers */
  757. for (k = 0; k < ARRAY_SIZE(p->ch); k++) {
  758. ch = &p->ch[k];
  759. if (!ch->enabled)
  760. continue;
  761. for (n = 0; n < NR_CH_REGS; n++)
  762. ch->saved_ch_regs[n] = lcdc_read_chan(ch, n);
  763. }
  764. /* save shared registers */
  765. for (n = 0; n < NR_SHARED_REGS; n++)
  766. p->saved_shared_regs[n] = lcdc_read(p, lcdc_shared_regs[n]);
  767. /* turn off LCDC hardware */
  768. lcdc_write(p, _LDCNT1R, 0);
  769. return 0;
  770. }
  771. static int sh_mobile_lcdc_runtime_resume(struct device *dev)
  772. {
  773. struct platform_device *pdev = to_platform_device(dev);
  774. struct sh_mobile_lcdc_priv *p = platform_get_drvdata(pdev);
  775. struct sh_mobile_lcdc_chan *ch;
  776. int k, n;
  777. /* restore per-channel registers */
  778. for (k = 0; k < ARRAY_SIZE(p->ch); k++) {
  779. ch = &p->ch[k];
  780. if (!ch->enabled)
  781. continue;
  782. for (n = 0; n < NR_CH_REGS; n++)
  783. lcdc_write_chan(ch, n, ch->saved_ch_regs[n]);
  784. }
  785. /* restore shared registers */
  786. for (n = 0; n < NR_SHARED_REGS; n++)
  787. lcdc_write(p, lcdc_shared_regs[n], p->saved_shared_regs[n]);
  788. return 0;
  789. }
  790. static const struct dev_pm_ops sh_mobile_lcdc_dev_pm_ops = {
  791. .suspend = sh_mobile_lcdc_suspend,
  792. .resume = sh_mobile_lcdc_resume,
  793. .runtime_suspend = sh_mobile_lcdc_runtime_suspend,
  794. .runtime_resume = sh_mobile_lcdc_runtime_resume,
  795. };
  796. static int sh_mobile_lcdc_remove(struct platform_device *pdev);
  797. static int __devinit sh_mobile_lcdc_probe(struct platform_device *pdev)
  798. {
  799. struct fb_info *info;
  800. struct sh_mobile_lcdc_priv *priv;
  801. struct sh_mobile_lcdc_info *pdata;
  802. struct sh_mobile_lcdc_chan_cfg *cfg;
  803. struct resource *res;
  804. int error;
  805. void *buf;
  806. int i, j;
  807. if (!pdev->dev.platform_data) {
  808. dev_err(&pdev->dev, "no platform data defined\n");
  809. error = -EINVAL;
  810. goto err0;
  811. }
  812. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  813. i = platform_get_irq(pdev, 0);
  814. if (!res || i < 0) {
  815. dev_err(&pdev->dev, "cannot get platform resources\n");
  816. error = -ENOENT;
  817. goto err0;
  818. }
  819. priv = kzalloc(sizeof(*priv), GFP_KERNEL);
  820. if (!priv) {
  821. dev_err(&pdev->dev, "cannot allocate device data\n");
  822. error = -ENOMEM;
  823. goto err0;
  824. }
  825. error = request_irq(i, sh_mobile_lcdc_irq, IRQF_DISABLED,
  826. dev_name(&pdev->dev), priv);
  827. if (error) {
  828. dev_err(&pdev->dev, "unable to request irq\n");
  829. goto err1;
  830. }
  831. priv->irq = i;
  832. priv->dev = &pdev->dev;
  833. platform_set_drvdata(pdev, priv);
  834. pdata = pdev->dev.platform_data;
  835. j = 0;
  836. for (i = 0; i < ARRAY_SIZE(pdata->ch); i++) {
  837. priv->ch[j].lcdc = priv;
  838. memcpy(&priv->ch[j].cfg, &pdata->ch[i], sizeof(pdata->ch[i]));
  839. error = sh_mobile_lcdc_check_interface(&priv->ch[i]);
  840. if (error) {
  841. dev_err(&pdev->dev, "unsupported interface type\n");
  842. goto err1;
  843. }
  844. init_waitqueue_head(&priv->ch[i].frame_end_wait);
  845. init_completion(&priv->ch[i].vsync_completion);
  846. priv->ch[j].pan_offset = 0;
  847. switch (pdata->ch[i].chan) {
  848. case LCDC_CHAN_MAINLCD:
  849. priv->ch[j].enabled = 1 << 1;
  850. priv->ch[j].reg_offs = lcdc_offs_mainlcd;
  851. j++;
  852. break;
  853. case LCDC_CHAN_SUBLCD:
  854. priv->ch[j].enabled = 1 << 2;
  855. priv->ch[j].reg_offs = lcdc_offs_sublcd;
  856. j++;
  857. break;
  858. }
  859. }
  860. if (!j) {
  861. dev_err(&pdev->dev, "no channels defined\n");
  862. error = -EINVAL;
  863. goto err1;
  864. }
  865. error = sh_mobile_lcdc_setup_clocks(pdev, pdata->clock_source, priv);
  866. if (error) {
  867. dev_err(&pdev->dev, "unable to setup clocks\n");
  868. goto err1;
  869. }
  870. priv->base = ioremap_nocache(res->start, (res->end - res->start) + 1);
  871. for (i = 0; i < j; i++) {
  872. cfg = &priv->ch[i].cfg;
  873. priv->ch[i].info = framebuffer_alloc(0, &pdev->dev);
  874. if (!priv->ch[i].info) {
  875. dev_err(&pdev->dev, "unable to allocate fb_info\n");
  876. error = -ENOMEM;
  877. break;
  878. }
  879. info = priv->ch[i].info;
  880. info->fbops = &sh_mobile_lcdc_ops;
  881. info->var.xres = info->var.xres_virtual = cfg->lcd_cfg.xres;
  882. info->var.yres = cfg->lcd_cfg.yres;
  883. /* Default Y virtual resolution is 2x panel size */
  884. info->var.yres_virtual = info->var.yres * 2;
  885. info->var.width = cfg->lcd_size_cfg.width;
  886. info->var.height = cfg->lcd_size_cfg.height;
  887. info->var.activate = FB_ACTIVATE_NOW;
  888. error = sh_mobile_lcdc_set_bpp(&info->var, cfg->bpp);
  889. if (error)
  890. break;
  891. info->fix = sh_mobile_lcdc_fix;
  892. info->fix.line_length = cfg->lcd_cfg.xres * (cfg->bpp / 8);
  893. info->fix.smem_len = info->fix.line_length *
  894. info->var.yres_virtual;
  895. buf = dma_alloc_coherent(&pdev->dev, info->fix.smem_len,
  896. &priv->ch[i].dma_handle, GFP_KERNEL);
  897. if (!buf) {
  898. dev_err(&pdev->dev, "unable to allocate buffer\n");
  899. error = -ENOMEM;
  900. break;
  901. }
  902. info->pseudo_palette = &priv->ch[i].pseudo_palette;
  903. info->flags = FBINFO_FLAG_DEFAULT;
  904. error = fb_alloc_cmap(&info->cmap, PALETTE_NR, 0);
  905. if (error < 0) {
  906. dev_err(&pdev->dev, "unable to allocate cmap\n");
  907. dma_free_coherent(&pdev->dev, info->fix.smem_len,
  908. buf, priv->ch[i].dma_handle);
  909. break;
  910. }
  911. memset(buf, 0, info->fix.smem_len);
  912. info->fix.smem_start = priv->ch[i].dma_handle;
  913. info->screen_base = buf;
  914. info->device = &pdev->dev;
  915. info->par = &priv->ch[i];
  916. }
  917. if (error)
  918. goto err1;
  919. error = sh_mobile_lcdc_start(priv);
  920. if (error) {
  921. dev_err(&pdev->dev, "unable to start hardware\n");
  922. goto err1;
  923. }
  924. for (i = 0; i < j; i++) {
  925. struct sh_mobile_lcdc_chan *ch = priv->ch + i;
  926. info = ch->info;
  927. if (info->fbdefio) {
  928. priv->ch->sglist = vmalloc(sizeof(struct scatterlist) *
  929. info->fix.smem_len >> PAGE_SHIFT);
  930. if (!priv->ch->sglist) {
  931. dev_err(&pdev->dev, "cannot allocate sglist\n");
  932. goto err1;
  933. }
  934. }
  935. error = register_framebuffer(info);
  936. if (error < 0)
  937. goto err1;
  938. dev_info(info->dev,
  939. "registered %s/%s as %dx%d %dbpp.\n",
  940. pdev->name,
  941. (ch->cfg.chan == LCDC_CHAN_MAINLCD) ?
  942. "mainlcd" : "sublcd",
  943. (int) ch->cfg.lcd_cfg.xres,
  944. (int) ch->cfg.lcd_cfg.yres,
  945. ch->cfg.bpp);
  946. /* deferred io mode: disable clock to save power */
  947. if (info->fbdefio)
  948. sh_mobile_lcdc_clk_off(priv);
  949. }
  950. return 0;
  951. err1:
  952. sh_mobile_lcdc_remove(pdev);
  953. err0:
  954. return error;
  955. }
  956. static int sh_mobile_lcdc_remove(struct platform_device *pdev)
  957. {
  958. struct sh_mobile_lcdc_priv *priv = platform_get_drvdata(pdev);
  959. struct fb_info *info;
  960. int i;
  961. for (i = 0; i < ARRAY_SIZE(priv->ch); i++)
  962. if (priv->ch[i].info->dev)
  963. unregister_framebuffer(priv->ch[i].info);
  964. sh_mobile_lcdc_stop(priv);
  965. for (i = 0; i < ARRAY_SIZE(priv->ch); i++) {
  966. info = priv->ch[i].info;
  967. if (!info || !info->device)
  968. continue;
  969. if (priv->ch[i].sglist)
  970. vfree(priv->ch[i].sglist);
  971. dma_free_coherent(&pdev->dev, info->fix.smem_len,
  972. info->screen_base, priv->ch[i].dma_handle);
  973. fb_dealloc_cmap(&info->cmap);
  974. framebuffer_release(info);
  975. }
  976. if (priv->dot_clk)
  977. clk_put(priv->dot_clk);
  978. pm_runtime_disable(priv->dev);
  979. if (priv->base)
  980. iounmap(priv->base);
  981. if (priv->irq)
  982. free_irq(priv->irq, priv);
  983. kfree(priv);
  984. return 0;
  985. }
  986. static struct platform_driver sh_mobile_lcdc_driver = {
  987. .driver = {
  988. .name = "sh_mobile_lcdc_fb",
  989. .owner = THIS_MODULE,
  990. .pm = &sh_mobile_lcdc_dev_pm_ops,
  991. },
  992. .probe = sh_mobile_lcdc_probe,
  993. .remove = sh_mobile_lcdc_remove,
  994. };
  995. static int __init sh_mobile_lcdc_init(void)
  996. {
  997. return platform_driver_register(&sh_mobile_lcdc_driver);
  998. }
  999. static void __exit sh_mobile_lcdc_exit(void)
  1000. {
  1001. platform_driver_unregister(&sh_mobile_lcdc_driver);
  1002. }
  1003. module_init(sh_mobile_lcdc_init);
  1004. module_exit(sh_mobile_lcdc_exit);
  1005. MODULE_DESCRIPTION("SuperH Mobile LCDC Framebuffer driver");
  1006. MODULE_AUTHOR("Magnus Damm <damm@opensource.se>");
  1007. MODULE_LICENSE("GPL v2");