sh_mobile_lcdcfb.c 31 KB

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