sh_mobile_lcdcfb.c 31 KB

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