sh_mobile_lcdcfb.c 30 KB

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