tmiofb.c 28 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054
  1. /*
  2. * Frame Buffer Device for Toshiba Mobile IO(TMIO) controller
  3. *
  4. * Copyright(C) 2005-2006 Chris Humbert
  5. * Copyright(C) 2005 Dirk Opfer
  6. * Copytight(C) 2007,2008 Dmitry Baryshkov
  7. *
  8. * Based on:
  9. * drivers/video/w100fb.c
  10. * code written by Sharp/Lineo for 2.4 kernels
  11. *
  12. * This program is free software; you can redistribute it and/or modify
  13. * it under the terms of the GNU General Public License version 2
  14. * as published by the Free Software Foundation;
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU General Public License for more details.
  20. */
  21. #include <linux/kernel.h>
  22. #include <linux/module.h>
  23. #include <linux/platform_device.h>
  24. #include <linux/fb.h>
  25. #include <linux/interrupt.h>
  26. #include <linux/delay.h>
  27. /* Why should fb driver call console functions? because acquire_console_sem() */
  28. #include <linux/console.h>
  29. #include <linux/mfd/core.h>
  30. #include <linux/mfd/tmio.h>
  31. #include <linux/uaccess.h>
  32. /*
  33. * accelerator commands
  34. */
  35. #define TMIOFB_ACC_CSADR(x) (0x00000000 | ((x) & 0x001ffffe))
  36. #define TMIOFB_ACC_CHPIX(x) (0x01000000 | ((x) & 0x000003ff))
  37. #define TMIOFB_ACC_CVPIX(x) (0x02000000 | ((x) & 0x000003ff))
  38. #define TMIOFB_ACC_PSADR(x) (0x03000000 | ((x) & 0x00fffffe))
  39. #define TMIOFB_ACC_PHPIX(x) (0x04000000 | ((x) & 0x000003ff))
  40. #define TMIOFB_ACC_PVPIX(x) (0x05000000 | ((x) & 0x000003ff))
  41. #define TMIOFB_ACC_PHOFS(x) (0x06000000 | ((x) & 0x000003ff))
  42. #define TMIOFB_ACC_PVOFS(x) (0x07000000 | ((x) & 0x000003ff))
  43. #define TMIOFB_ACC_POADR(x) (0x08000000 | ((x) & 0x00fffffe))
  44. #define TMIOFB_ACC_RSTR(x) (0x09000000 | ((x) & 0x000000ff))
  45. #define TMIOFB_ACC_TCLOR(x) (0x0A000000 | ((x) & 0x0000ffff))
  46. #define TMIOFB_ACC_FILL(x) (0x0B000000 | ((x) & 0x0000ffff))
  47. #define TMIOFB_ACC_DSADR(x) (0x0C000000 | ((x) & 0x00fffffe))
  48. #define TMIOFB_ACC_SSADR(x) (0x0D000000 | ((x) & 0x00fffffe))
  49. #define TMIOFB_ACC_DHPIX(x) (0x0E000000 | ((x) & 0x000003ff))
  50. #define TMIOFB_ACC_DVPIX(x) (0x0F000000 | ((x) & 0x000003ff))
  51. #define TMIOFB_ACC_SHPIX(x) (0x10000000 | ((x) & 0x000003ff))
  52. #define TMIOFB_ACC_SVPIX(x) (0x11000000 | ((x) & 0x000003ff))
  53. #define TMIOFB_ACC_LBINI(x) (0x12000000 | ((x) & 0x0000ffff))
  54. #define TMIOFB_ACC_LBK2(x) (0x13000000 | ((x) & 0x0000ffff))
  55. #define TMIOFB_ACC_SHBINI(x) (0x14000000 | ((x) & 0x0000ffff))
  56. #define TMIOFB_ACC_SHBK2(x) (0x15000000 | ((x) & 0x0000ffff))
  57. #define TMIOFB_ACC_SVBINI(x) (0x16000000 | ((x) & 0x0000ffff))
  58. #define TMIOFB_ACC_SVBK2(x) (0x17000000 | ((x) & 0x0000ffff))
  59. #define TMIOFB_ACC_CMGO 0x20000000
  60. #define TMIOFB_ACC_CMGO_CEND 0x00000001
  61. #define TMIOFB_ACC_CMGO_INT 0x00000002
  62. #define TMIOFB_ACC_CMGO_CMOD 0x00000010
  63. #define TMIOFB_ACC_CMGO_CDVRV 0x00000020
  64. #define TMIOFB_ACC_CMGO_CDHRV 0x00000040
  65. #define TMIOFB_ACC_CMGO_RUND 0x00008000
  66. #define TMIOFB_ACC_SCGO 0x21000000
  67. #define TMIOFB_ACC_SCGO_CEND 0x00000001
  68. #define TMIOFB_ACC_SCGO_INT 0x00000002
  69. #define TMIOFB_ACC_SCGO_ROP3 0x00000004
  70. #define TMIOFB_ACC_SCGO_TRNS 0x00000008
  71. #define TMIOFB_ACC_SCGO_DVRV 0x00000010
  72. #define TMIOFB_ACC_SCGO_DHRV 0x00000020
  73. #define TMIOFB_ACC_SCGO_SVRV 0x00000040
  74. #define TMIOFB_ACC_SCGO_SHRV 0x00000080
  75. #define TMIOFB_ACC_SCGO_DSTXY 0x00008000
  76. #define TMIOFB_ACC_SBGO 0x22000000
  77. #define TMIOFB_ACC_SBGO_CEND 0x00000001
  78. #define TMIOFB_ACC_SBGO_INT 0x00000002
  79. #define TMIOFB_ACC_SBGO_DVRV 0x00000010
  80. #define TMIOFB_ACC_SBGO_DHRV 0x00000020
  81. #define TMIOFB_ACC_SBGO_SVRV 0x00000040
  82. #define TMIOFB_ACC_SBGO_SHRV 0x00000080
  83. #define TMIOFB_ACC_SBGO_SBMD 0x00000100
  84. #define TMIOFB_ACC_FLGO 0x23000000
  85. #define TMIOFB_ACC_FLGO_CEND 0x00000001
  86. #define TMIOFB_ACC_FLGO_INT 0x00000002
  87. #define TMIOFB_ACC_FLGO_ROP3 0x00000004
  88. #define TMIOFB_ACC_LDGO 0x24000000
  89. #define TMIOFB_ACC_LDGO_CEND 0x00000001
  90. #define TMIOFB_ACC_LDGO_INT 0x00000002
  91. #define TMIOFB_ACC_LDGO_ROP3 0x00000004
  92. #define TMIOFB_ACC_LDGO_ENDPX 0x00000008
  93. #define TMIOFB_ACC_LDGO_LVRV 0x00000010
  94. #define TMIOFB_ACC_LDGO_LHRV 0x00000020
  95. #define TMIOFB_ACC_LDGO_LDMOD 0x00000040
  96. /* a FIFO is always allocated, even if acceleration is not used */
  97. #define TMIOFB_FIFO_SIZE 512
  98. /*
  99. * LCD Host Controller Configuration Register
  100. *
  101. * This iomem area supports only 16-bit IO.
  102. */
  103. #define CCR_CMD 0x04 /* Command */
  104. #define CCR_REVID 0x08 /* Revision ID */
  105. #define CCR_BASEL 0x10 /* LCD Control Reg Base Addr Low */
  106. #define CCR_BASEH 0x12 /* LCD Control Reg Base Addr High */
  107. #define CCR_UGCC 0x40 /* Unified Gated Clock Control */
  108. #define CCR_GCC 0x42 /* Gated Clock Control */
  109. #define CCR_USC 0x50 /* Unified Software Clear */
  110. #define CCR_VRAMRTC 0x60 /* VRAM Timing Control */
  111. /* 0x61 VRAM Refresh Control */
  112. #define CCR_VRAMSAC 0x62 /* VRAM Access Control */
  113. /* 0x63 VRAM Status */
  114. #define CCR_VRAMBC 0x64 /* VRAM Block Control */
  115. /*
  116. * LCD Control Register
  117. *
  118. * This iomem area supports only 16-bit IO.
  119. */
  120. #define LCR_UIS 0x000 /* Unified Interrupt Status */
  121. #define LCR_VHPN 0x008 /* VRAM Horizontal Pixel Number */
  122. #define LCR_CFSAL 0x00a /* Command FIFO Start Address Low */
  123. #define LCR_CFSAH 0x00c /* Command FIFO Start Address High */
  124. #define LCR_CFS 0x00e /* Command FIFO Size */
  125. #define LCR_CFWS 0x010 /* Command FIFO Writeable Size */
  126. #define LCR_BBIE 0x012 /* BitBLT Interrupt Enable */
  127. #define LCR_BBISC 0x014 /* BitBLT Interrupt Status and Clear */
  128. #define LCR_CCS 0x016 /* Command Count Status */
  129. #define LCR_BBES 0x018 /* BitBLT Execution Status */
  130. #define LCR_CMDL 0x01c /* Command Low */
  131. #define LCR_CMDH 0x01e /* Command High */
  132. #define LCR_CFC 0x022 /* Command FIFO Clear */
  133. #define LCR_CCIFC 0x024 /* CMOS Camera IF Control */
  134. #define LCR_HWT 0x026 /* Hardware Test */
  135. #define LCR_LCDCCRC 0x100 /* LCDC Clock and Reset Control */
  136. #define LCR_LCDCC 0x102 /* LCDC Control */
  137. #define LCR_LCDCOPC 0x104 /* LCDC Output Pin Control */
  138. #define LCR_LCDIS 0x108 /* LCD Interrupt Status */
  139. #define LCR_LCDIM 0x10a /* LCD Interrupt Mask */
  140. #define LCR_LCDIE 0x10c /* LCD Interrupt Enable */
  141. #define LCR_GDSAL 0x122 /* Graphics Display Start Address Low */
  142. #define LCR_GDSAH 0x124 /* Graphics Display Start Address High */
  143. #define LCR_VHPCL 0x12a /* VRAM Horizontal Pixel Count Low */
  144. #define LCR_VHPCH 0x12c /* VRAM Horizontal Pixel Count High */
  145. #define LCR_GM 0x12e /* Graphic Mode(VRAM access enable) */
  146. #define LCR_HT 0x140 /* Horizontal Total */
  147. #define LCR_HDS 0x142 /* Horizontal Display Start */
  148. #define LCR_HSS 0x144 /* H-Sync Start */
  149. #define LCR_HSE 0x146 /* H-Sync End */
  150. #define LCR_HNP 0x14c /* Horizontal Number of Pixels */
  151. #define LCR_VT 0x150 /* Vertical Total */
  152. #define LCR_VDS 0x152 /* Vertical Display Start */
  153. #define LCR_VSS 0x154 /* V-Sync Start */
  154. #define LCR_VSE 0x156 /* V-Sync End */
  155. #define LCR_CDLN 0x160 /* Current Display Line Number */
  156. #define LCR_ILN 0x162 /* Interrupt Line Number */
  157. #define LCR_SP 0x164 /* Sync Polarity */
  158. #define LCR_MISC 0x166 /* MISC(RGB565 mode) */
  159. #define LCR_VIHSS 0x16a /* Video Interface H-Sync Start */
  160. #define LCR_VIVS 0x16c /* Video Interface Vertical Start */
  161. #define LCR_VIVE 0x16e /* Video Interface Vertical End */
  162. #define LCR_VIVSS 0x170 /* Video Interface V-Sync Start */
  163. #define LCR_VCCIS 0x17e /* Video / CMOS Camera Interface Select */
  164. #define LCR_VIDWSAL 0x180 /* VI Data Write Start Address Low */
  165. #define LCR_VIDWSAH 0x182 /* VI Data Write Start Address High */
  166. #define LCR_VIDRSAL 0x184 /* VI Data Read Start Address Low */
  167. #define LCR_VIDRSAH 0x186 /* VI Data Read Start Address High */
  168. #define LCR_VIPDDST 0x188 /* VI Picture Data Display Start Timing */
  169. #define LCR_VIPDDET 0x186 /* VI Picture Data Display End Timing */
  170. #define LCR_VIE 0x18c /* Video Interface Enable */
  171. #define LCR_VCS 0x18e /* Video/Camera Select */
  172. #define LCR_VPHWC 0x194 /* Video Picture Horizontal Wait Count */
  173. #define LCR_VPHS 0x196 /* Video Picture Horizontal Size */
  174. #define LCR_VPVWC 0x198 /* Video Picture Vertical Wait Count */
  175. #define LCR_VPVS 0x19a /* Video Picture Vertical Size */
  176. #define LCR_PLHPIX 0x1a0 /* PLHPIX */
  177. #define LCR_XS 0x1a2 /* XStart */
  178. #define LCR_XCKHW 0x1a4 /* XCK High Width */
  179. #define LCR_STHS 0x1a8 /* STH Start */
  180. #define LCR_VT2 0x1aa /* Vertical Total */
  181. #define LCR_YCKSW 0x1ac /* YCK Start Wait */
  182. #define LCR_YSTS 0x1ae /* YST Start */
  183. #define LCR_PPOLS 0x1b0 /* #PPOL Start */
  184. #define LCR_PRECW 0x1b2 /* PREC Width */
  185. #define LCR_VCLKHW 0x1b4 /* VCLK High Width */
  186. #define LCR_OC 0x1b6 /* Output Control */
  187. static char *mode_option __devinitdata;
  188. struct tmiofb_par {
  189. u32 pseudo_palette[16];
  190. #ifdef CONFIG_FB_TMIO_ACCELL
  191. wait_queue_head_t wait_acc;
  192. bool use_polling;
  193. #endif
  194. void __iomem *ccr;
  195. void __iomem *lcr;
  196. };
  197. /*--------------------------------------------------------------------------*/
  198. /*
  199. * reasons for an interrupt:
  200. * uis bbisc lcdis
  201. * 0100 0001 accelerator command completed
  202. * 2000 0001 vsync start
  203. * 2000 0002 display start
  204. * 2000 0004 line number match(0x1ff mask???)
  205. */
  206. static irqreturn_t tmiofb_irq(int irq, void *__info)
  207. {
  208. struct fb_info *info = __info;
  209. struct tmiofb_par *par = info->par;
  210. unsigned int bbisc = tmio_ioread16(par->lcr + LCR_BBISC);
  211. tmio_iowrite16(bbisc, par->lcr + LCR_BBISC);
  212. #ifdef CONFIG_FB_TMIO_ACCELL
  213. /*
  214. * We were in polling mode and now we got correct irq.
  215. * Switch back to IRQ-based sync of command FIFO
  216. */
  217. if (unlikely(par->use_polling && irq != -1)) {
  218. printk(KERN_INFO "tmiofb: switching to waitq\n");
  219. par->use_polling = false;
  220. }
  221. if (bbisc & 1)
  222. wake_up(&par->wait_acc);
  223. #endif
  224. return IRQ_HANDLED;
  225. }
  226. /*--------------------------------------------------------------------------*/
  227. /*
  228. * Turns off the LCD controller and LCD host controller.
  229. */
  230. static int tmiofb_hw_stop(struct platform_device *dev)
  231. {
  232. struct mfd_cell *cell = dev->dev.platform_data;
  233. struct tmio_fb_data *data = cell->driver_data;
  234. struct fb_info *info = platform_get_drvdata(dev);
  235. struct tmiofb_par *par = info->par;
  236. tmio_iowrite16(0, par->ccr + CCR_UGCC);
  237. tmio_iowrite16(0, par->lcr + LCR_GM);
  238. data->lcd_set_power(dev, 0);
  239. tmio_iowrite16(0x0010, par->lcr + LCR_LCDCCRC);
  240. return 0;
  241. }
  242. /*
  243. * Initializes the LCD host controller.
  244. */
  245. static int tmiofb_hw_init(struct platform_device *dev)
  246. {
  247. struct mfd_cell *cell = dev->dev.platform_data;
  248. struct fb_info *info = platform_get_drvdata(dev);
  249. struct tmiofb_par *par = info->par;
  250. const struct resource *nlcr = &cell->resources[0];
  251. const struct resource *vram = &cell->resources[2];
  252. unsigned long base;
  253. if (nlcr == NULL || vram == NULL)
  254. return -EINVAL;
  255. base = nlcr->start;
  256. tmio_iowrite16(0x003a, par->ccr + CCR_UGCC);
  257. tmio_iowrite16(0x003a, par->ccr + CCR_GCC);
  258. tmio_iowrite16(0x3f00, par->ccr + CCR_USC);
  259. msleep(2); /* wait for device to settle */
  260. tmio_iowrite16(0x0000, par->ccr + CCR_USC);
  261. tmio_iowrite16(base >> 16, par->ccr + CCR_BASEH);
  262. tmio_iowrite16(base, par->ccr + CCR_BASEL);
  263. tmio_iowrite16(0x0002, par->ccr + CCR_CMD); /* base address enable */
  264. tmio_iowrite16(0x40a8, par->ccr + CCR_VRAMRTC); /* VRAMRC, VRAMTC */
  265. tmio_iowrite16(0x0018, par->ccr + CCR_VRAMSAC); /* VRAMSTS, VRAMAC */
  266. tmio_iowrite16(0x0002, par->ccr + CCR_VRAMBC);
  267. msleep(2); /* wait for device to settle */
  268. tmio_iowrite16(0x000b, par->ccr + CCR_VRAMBC);
  269. base = vram->start + info->screen_size;
  270. tmio_iowrite16(base >> 16, par->lcr + LCR_CFSAH);
  271. tmio_iowrite16(base, par->lcr + LCR_CFSAL);
  272. tmio_iowrite16(TMIOFB_FIFO_SIZE - 1, par->lcr + LCR_CFS);
  273. tmio_iowrite16(1, par->lcr + LCR_CFC);
  274. tmio_iowrite16(1, par->lcr + LCR_BBIE);
  275. tmio_iowrite16(0, par->lcr + LCR_CFWS);
  276. return 0;
  277. }
  278. /*
  279. * Sets the LCD controller's output resolution and pixel clock
  280. */
  281. static void tmiofb_hw_mode(struct platform_device *dev)
  282. {
  283. struct mfd_cell *cell = dev->dev.platform_data;
  284. struct tmio_fb_data *data = cell->driver_data;
  285. struct fb_info *info = platform_get_drvdata(dev);
  286. struct fb_videomode *mode = info->mode;
  287. struct tmiofb_par *par = info->par;
  288. unsigned int i;
  289. tmio_iowrite16(0, par->lcr + LCR_GM);
  290. data->lcd_set_power(dev, 0);
  291. tmio_iowrite16(0x0010, par->lcr + LCR_LCDCCRC);
  292. data->lcd_mode(dev, mode);
  293. data->lcd_set_power(dev, 1);
  294. tmio_iowrite16(info->fix.line_length, par->lcr + LCR_VHPN);
  295. tmio_iowrite16(0, par->lcr + LCR_GDSAH);
  296. tmio_iowrite16(0, par->lcr + LCR_GDSAL);
  297. tmio_iowrite16(info->fix.line_length >> 16, par->lcr + LCR_VHPCH);
  298. tmio_iowrite16(info->fix.line_length, par->lcr + LCR_VHPCL);
  299. tmio_iowrite16(i = 0, par->lcr + LCR_HSS);
  300. tmio_iowrite16(i += mode->hsync_len, par->lcr + LCR_HSE);
  301. tmio_iowrite16(i += mode->left_margin, par->lcr + LCR_HDS);
  302. tmio_iowrite16(i += mode->xres + mode->right_margin, par->lcr + LCR_HT);
  303. tmio_iowrite16(mode->xres, par->lcr + LCR_HNP);
  304. tmio_iowrite16(i = 0, par->lcr + LCR_VSS);
  305. tmio_iowrite16(i += mode->vsync_len, par->lcr + LCR_VSE);
  306. tmio_iowrite16(i += mode->upper_margin, par->lcr + LCR_VDS);
  307. tmio_iowrite16(i += mode->yres, par->lcr + LCR_ILN);
  308. tmio_iowrite16(i += mode->lower_margin, par->lcr + LCR_VT);
  309. tmio_iowrite16(3, par->lcr + LCR_MISC); /* RGB565 mode */
  310. tmio_iowrite16(1, par->lcr + LCR_GM); /* VRAM enable */
  311. tmio_iowrite16(0x4007, par->lcr + LCR_LCDCC);
  312. tmio_iowrite16(3, par->lcr + LCR_SP); /* sync polarity */
  313. tmio_iowrite16(0x0010, par->lcr + LCR_LCDCCRC);
  314. msleep(5); /* wait for device to settle */
  315. tmio_iowrite16(0x0014, par->lcr + LCR_LCDCCRC); /* STOP_CKP */
  316. msleep(5); /* wait for device to settle */
  317. tmio_iowrite16(0x0015, par->lcr + LCR_LCDCCRC); /* STOP_CKP|SOFT_RESET*/
  318. tmio_iowrite16(0xfffa, par->lcr + LCR_VCS);
  319. }
  320. /*--------------------------------------------------------------------------*/
  321. #ifdef CONFIG_FB_TMIO_ACCELL
  322. static int __must_check
  323. tmiofb_acc_wait(struct fb_info *info, unsigned int ccs)
  324. {
  325. struct tmiofb_par *par = info->par;
  326. /*
  327. * This code can be called whith interrupts disabled.
  328. * So instead of relaying on irq to trigger the event,
  329. * poll the state till the necessary command is executed.
  330. */
  331. if (irqs_disabled() || par->use_polling) {
  332. int i = 0;
  333. while (tmio_ioread16(par->lcr + LCR_CCS) > ccs) {
  334. udelay(1);
  335. i++;
  336. if (i > 10000) {
  337. pr_err("tmiofb: timeout waiting for %d\n",
  338. ccs);
  339. return -ETIMEDOUT;
  340. }
  341. tmiofb_irq(-1, info);
  342. }
  343. } else {
  344. if (!wait_event_interruptible_timeout(par->wait_acc,
  345. tmio_ioread16(par->lcr + LCR_CCS) <= ccs,
  346. 1000)) {
  347. pr_err("tmiofb: timeout waiting for %d\n", ccs);
  348. return -ETIMEDOUT;
  349. }
  350. }
  351. return 0;
  352. }
  353. /*
  354. * Writes an accelerator command to the accelerator's FIFO.
  355. */
  356. static int
  357. tmiofb_acc_write(struct fb_info *info, const u32 *cmd, unsigned int count)
  358. {
  359. struct tmiofb_par *par = info->par;
  360. int ret;
  361. ret = tmiofb_acc_wait(info, TMIOFB_FIFO_SIZE - count);
  362. if (ret)
  363. return ret;
  364. for (; count; count--, cmd++) {
  365. tmio_iowrite16(*cmd >> 16, par->lcr + LCR_CMDH);
  366. tmio_iowrite16(*cmd, par->lcr + LCR_CMDL);
  367. }
  368. return ret;
  369. }
  370. /*
  371. * Wait for the accelerator to finish its operations before writing
  372. * to the framebuffer for consistent display output.
  373. */
  374. static int tmiofb_sync(struct fb_info *fbi)
  375. {
  376. struct tmiofb_par *par = fbi->par;
  377. int ret;
  378. int i = 0;
  379. ret = tmiofb_acc_wait(fbi, 0);
  380. while (tmio_ioread16(par->lcr + LCR_BBES) & 2) { /* blit active */
  381. udelay(1);
  382. i++ ;
  383. if (i > 10000) {
  384. printk(KERN_ERR "timeout waiting for blit to end!\n");
  385. return -ETIMEDOUT;
  386. }
  387. }
  388. return ret;
  389. }
  390. static void
  391. tmiofb_fillrect(struct fb_info *fbi, const struct fb_fillrect *rect)
  392. {
  393. const u32 cmd[] = {
  394. TMIOFB_ACC_DSADR((rect->dy * fbi->mode->xres + rect->dx) * 2),
  395. TMIOFB_ACC_DHPIX(rect->width - 1),
  396. TMIOFB_ACC_DVPIX(rect->height - 1),
  397. TMIOFB_ACC_FILL(rect->color),
  398. TMIOFB_ACC_FLGO,
  399. };
  400. if (fbi->state != FBINFO_STATE_RUNNING ||
  401. fbi->flags & FBINFO_HWACCEL_DISABLED) {
  402. cfb_fillrect(fbi, rect);
  403. return;
  404. }
  405. tmiofb_acc_write(fbi, cmd, ARRAY_SIZE(cmd));
  406. }
  407. static void
  408. tmiofb_copyarea(struct fb_info *fbi, const struct fb_copyarea *area)
  409. {
  410. const u32 cmd[] = {
  411. TMIOFB_ACC_DSADR((area->dy * fbi->mode->xres + area->dx) * 2),
  412. TMIOFB_ACC_DHPIX(area->width - 1),
  413. TMIOFB_ACC_DVPIX(area->height - 1),
  414. TMIOFB_ACC_SSADR((area->sy * fbi->mode->xres + area->sx) * 2),
  415. TMIOFB_ACC_SCGO,
  416. };
  417. if (fbi->state != FBINFO_STATE_RUNNING ||
  418. fbi->flags & FBINFO_HWACCEL_DISABLED) {
  419. cfb_copyarea(fbi, area);
  420. return;
  421. }
  422. tmiofb_acc_write(fbi, cmd, ARRAY_SIZE(cmd));
  423. }
  424. #endif
  425. static void tmiofb_clearscreen(struct fb_info *info)
  426. {
  427. const struct fb_fillrect rect = {
  428. .dx = 0,
  429. .dy = 0,
  430. .width = info->mode->xres,
  431. .height = info->mode->yres,
  432. .color = 0,
  433. .rop = ROP_COPY,
  434. };
  435. info->fbops->fb_fillrect(info, &rect);
  436. }
  437. static int tmiofb_vblank(struct fb_info *fbi, struct fb_vblank *vblank)
  438. {
  439. struct tmiofb_par *par = fbi->par;
  440. struct fb_videomode *mode = fbi->mode;
  441. unsigned int vcount = tmio_ioread16(par->lcr + LCR_CDLN);
  442. unsigned int vds = mode->vsync_len + mode->upper_margin;
  443. vblank->vcount = vcount;
  444. vblank->flags = FB_VBLANK_HAVE_VBLANK | FB_VBLANK_HAVE_VCOUNT
  445. | FB_VBLANK_HAVE_VSYNC;
  446. if (vcount < mode->vsync_len)
  447. vblank->flags |= FB_VBLANK_VSYNCING;
  448. if (vcount < vds || vcount > vds + mode->yres)
  449. vblank->flags |= FB_VBLANK_VBLANKING;
  450. return 0;
  451. }
  452. static int tmiofb_ioctl(struct fb_info *fbi,
  453. unsigned int cmd, unsigned long arg)
  454. {
  455. switch (cmd) {
  456. case FBIOGET_VBLANK: {
  457. struct fb_vblank vblank = {0};
  458. void __user *argp = (void __user *) arg;
  459. tmiofb_vblank(fbi, &vblank);
  460. if (copy_to_user(argp, &vblank, sizeof vblank))
  461. return -EFAULT;
  462. return 0;
  463. }
  464. #ifdef CONFIG_FB_TMIO_ACCELL
  465. case FBIO_TMIO_ACC_SYNC:
  466. tmiofb_sync(fbi);
  467. return 0;
  468. case FBIO_TMIO_ACC_WRITE: {
  469. u32 __user *argp = (void __user *) arg;
  470. u32 len;
  471. u32 acc[16];
  472. if (get_user(len, argp))
  473. return -EFAULT;
  474. if (len > ARRAY_SIZE(acc))
  475. return -EINVAL;
  476. if (copy_from_user(acc, argp + 1, sizeof(u32) * len))
  477. return -EFAULT;
  478. return tmiofb_acc_write(fbi, acc, len);
  479. }
  480. #endif
  481. }
  482. return -ENOTTY;
  483. }
  484. /*--------------------------------------------------------------------------*/
  485. /* Select the smallest mode that allows the desired resolution to be
  486. * displayed. If desired, the x and y parameters can be rounded up to
  487. * match the selected mode.
  488. */
  489. static struct fb_videomode *
  490. tmiofb_find_mode(struct fb_info *info, struct fb_var_screeninfo *var)
  491. {
  492. struct mfd_cell *cell =
  493. info->device->platform_data;
  494. struct tmio_fb_data *data = cell->driver_data;
  495. struct fb_videomode *best = NULL;
  496. int i;
  497. for (i = 0; i < data->num_modes; i++) {
  498. struct fb_videomode *mode = data->modes + i;
  499. if (mode->xres >= var->xres && mode->yres >= var->yres
  500. && (!best || (mode->xres < best->xres
  501. && mode->yres < best->yres)))
  502. best = mode;
  503. }
  504. return best;
  505. }
  506. static int tmiofb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
  507. {
  508. struct fb_videomode *mode;
  509. struct mfd_cell *cell =
  510. info->device->platform_data;
  511. struct tmio_fb_data *data = cell->driver_data;
  512. mode = tmiofb_find_mode(info, var);
  513. if (!mode || var->bits_per_pixel > 16)
  514. return -EINVAL;
  515. fb_videomode_to_var(var, mode);
  516. var->xres_virtual = mode->xres;
  517. var->yres_virtual = info->screen_size / (mode->xres * 2);
  518. if (var->yres_virtual < var->yres)
  519. return -EINVAL;
  520. var->xoffset = 0;
  521. var->yoffset = 0;
  522. var->bits_per_pixel = 16;
  523. var->grayscale = 0;
  524. var->red.offset = 11;
  525. var->red.length = 5;
  526. var->green.offset = 5;
  527. var->green.length = 6;
  528. var->blue.offset = 0;
  529. var->blue.length = 5;
  530. var->transp.offset = 0;
  531. var->transp.length = 0;
  532. var->nonstd = 0;
  533. var->height = data->height; /* mm */
  534. var->width = data->width; /* mm */
  535. var->rotate = 0;
  536. return 0;
  537. }
  538. static int tmiofb_set_par(struct fb_info *info)
  539. {
  540. struct fb_var_screeninfo *var = &info->var;
  541. struct fb_videomode *mode;
  542. mode = tmiofb_find_mode(info, var);
  543. if (!mode)
  544. return -EINVAL;
  545. info->mode = mode;
  546. info->fix.line_length = info->mode->xres *
  547. var->bits_per_pixel / 8;
  548. tmiofb_hw_mode(to_platform_device(info->device));
  549. tmiofb_clearscreen(info);
  550. return 0;
  551. }
  552. static int tmiofb_setcolreg(unsigned regno, unsigned red, unsigned green,
  553. unsigned blue, unsigned transp,
  554. struct fb_info *info)
  555. {
  556. struct tmiofb_par *par = info->par;
  557. if (regno < ARRAY_SIZE(par->pseudo_palette)) {
  558. par->pseudo_palette[regno] =
  559. ((red & 0xf800)) |
  560. ((green & 0xfc00) >> 5) |
  561. ((blue & 0xf800) >> 11);
  562. return 0;
  563. }
  564. return -EINVAL;
  565. }
  566. static int tmiofb_blank(int blank, struct fb_info *info)
  567. {
  568. /*
  569. * everything is done in lcd/bl drivers.
  570. * this is purely to make sysfs happy and work.
  571. */
  572. return 0;
  573. }
  574. static struct fb_ops tmiofb_ops = {
  575. .owner = THIS_MODULE,
  576. .fb_ioctl = tmiofb_ioctl,
  577. .fb_check_var = tmiofb_check_var,
  578. .fb_set_par = tmiofb_set_par,
  579. .fb_setcolreg = tmiofb_setcolreg,
  580. .fb_blank = tmiofb_blank,
  581. .fb_imageblit = cfb_imageblit,
  582. #ifdef CONFIG_FB_TMIO_ACCELL
  583. .fb_sync = tmiofb_sync,
  584. .fb_fillrect = tmiofb_fillrect,
  585. .fb_copyarea = tmiofb_copyarea,
  586. #else
  587. .fb_fillrect = cfb_fillrect,
  588. .fb_copyarea = cfb_copyarea,
  589. #endif
  590. };
  591. /*--------------------------------------------------------------------------*/
  592. static int __devinit tmiofb_probe(struct platform_device *dev)
  593. {
  594. struct mfd_cell *cell = dev->dev.platform_data;
  595. struct tmio_fb_data *data = cell->driver_data;
  596. struct resource *ccr = platform_get_resource(dev, IORESOURCE_MEM, 1);
  597. struct resource *lcr = platform_get_resource(dev, IORESOURCE_MEM, 0);
  598. struct resource *vram = platform_get_resource(dev, IORESOURCE_MEM, 2);
  599. int irq = platform_get_irq(dev, 0);
  600. struct fb_info *info;
  601. struct tmiofb_par *par;
  602. int retval;
  603. /*
  604. * This is the only way ATM to disable the fb
  605. */
  606. if (data == NULL) {
  607. dev_err(&dev->dev, "NULL platform data!\n");
  608. return -EINVAL;
  609. }
  610. info = framebuffer_alloc(sizeof(struct tmiofb_par), &dev->dev);
  611. if (!info)
  612. return -ENOMEM;
  613. par = info->par;
  614. #ifdef CONFIG_FB_TMIO_ACCELL
  615. init_waitqueue_head(&par->wait_acc);
  616. par->use_polling = true;
  617. info->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_COPYAREA
  618. | FBINFO_HWACCEL_FILLRECT;
  619. #else
  620. info->flags = FBINFO_DEFAULT;
  621. #endif
  622. info->fbops = &tmiofb_ops;
  623. strcpy(info->fix.id, "tmio-fb");
  624. info->fix.smem_start = vram->start;
  625. info->fix.smem_len = resource_size(vram);
  626. info->fix.type = FB_TYPE_PACKED_PIXELS;
  627. info->fix.visual = FB_VISUAL_TRUECOLOR;
  628. info->fix.mmio_start = lcr->start;
  629. info->fix.mmio_len = resource_size(lcr);
  630. info->fix.accel = FB_ACCEL_NONE;
  631. info->screen_size = info->fix.smem_len - (4 * TMIOFB_FIFO_SIZE);
  632. info->pseudo_palette = par->pseudo_palette;
  633. par->ccr = ioremap(ccr->start, resource_size(ccr));
  634. if (!par->ccr) {
  635. retval = -ENOMEM;
  636. goto err_ioremap_ccr;
  637. }
  638. par->lcr = ioremap(info->fix.mmio_start, info->fix.mmio_len);
  639. if (!par->lcr) {
  640. retval = -ENOMEM;
  641. goto err_ioremap_lcr;
  642. }
  643. info->screen_base = ioremap(info->fix.smem_start, info->fix.smem_len);
  644. if (!info->screen_base) {
  645. retval = -ENOMEM;
  646. goto err_ioremap_vram;
  647. }
  648. retval = request_irq(irq, &tmiofb_irq, IRQF_DISABLED,
  649. dev->dev.bus_id, info);
  650. if (retval)
  651. goto err_request_irq;
  652. platform_set_drvdata(dev, info);
  653. retval = fb_find_mode(&info->var, info, mode_option,
  654. data->modes, data->num_modes,
  655. data->modes, 16);
  656. if (!retval) {
  657. retval = -EINVAL;
  658. goto err_find_mode;
  659. }
  660. if (cell->enable) {
  661. retval = cell->enable(dev);
  662. if (retval)
  663. goto err_enable;
  664. }
  665. retval = tmiofb_hw_init(dev);
  666. if (retval)
  667. goto err_hw_init;
  668. fb_videomode_to_modelist(data->modes, data->num_modes,
  669. &info->modelist);
  670. retval = register_framebuffer(info);
  671. if (retval < 0)
  672. goto err_register_framebuffer;
  673. printk(KERN_INFO "fb%d: %s frame buffer device\n",
  674. info->node, info->fix.id);
  675. return 0;
  676. err_register_framebuffer:
  677. /*err_set_par:*/
  678. tmiofb_hw_stop(dev);
  679. err_hw_init:
  680. if (cell->disable)
  681. cell->disable(dev);
  682. err_enable:
  683. err_find_mode:
  684. platform_set_drvdata(dev, NULL);
  685. free_irq(irq, info);
  686. err_request_irq:
  687. iounmap(info->screen_base);
  688. err_ioremap_vram:
  689. iounmap(par->lcr);
  690. err_ioremap_lcr:
  691. iounmap(par->ccr);
  692. err_ioremap_ccr:
  693. framebuffer_release(info);
  694. return retval;
  695. }
  696. static int __devexit tmiofb_remove(struct platform_device *dev)
  697. {
  698. struct mfd_cell *cell = dev->dev.platform_data;
  699. struct fb_info *info = platform_get_drvdata(dev);
  700. int irq = platform_get_irq(dev, 0);
  701. struct tmiofb_par *par;
  702. if (info) {
  703. par = info->par;
  704. unregister_framebuffer(info);
  705. tmiofb_hw_stop(dev);
  706. if (cell->disable)
  707. cell->disable(dev);
  708. platform_set_drvdata(dev, NULL);
  709. free_irq(irq, info);
  710. iounmap(info->screen_base);
  711. iounmap(par->lcr);
  712. iounmap(par->ccr);
  713. framebuffer_release(info);
  714. }
  715. return 0;
  716. }
  717. #ifdef DEBUG
  718. static void tmiofb_dump_regs(struct platform_device *dev)
  719. {
  720. struct fb_info *info = platform_get_drvdata(dev);
  721. struct tmiofb_par *par = info->par;
  722. printk(KERN_DEBUG "lhccr:\n");
  723. #define CCR_PR(n) printk(KERN_DEBUG "\t" #n " = \t%04x\n",\
  724. tmio_ioread16(par->ccr + CCR_ ## n));
  725. CCR_PR(CMD);
  726. CCR_PR(REVID);
  727. CCR_PR(BASEL);
  728. CCR_PR(BASEH);
  729. CCR_PR(UGCC);
  730. CCR_PR(GCC);
  731. CCR_PR(USC);
  732. CCR_PR(VRAMRTC);
  733. CCR_PR(VRAMSAC);
  734. CCR_PR(VRAMBC);
  735. #undef CCR_PR
  736. printk(KERN_DEBUG "lcr: \n");
  737. #define LCR_PR(n) printk(KERN_DEBUG "\t" #n " = \t%04x\n",\
  738. tmio_ioread16(par->lcr + LCR_ ## n));
  739. LCR_PR(UIS);
  740. LCR_PR(VHPN);
  741. LCR_PR(CFSAL);
  742. LCR_PR(CFSAH);
  743. LCR_PR(CFS);
  744. LCR_PR(CFWS);
  745. LCR_PR(BBIE);
  746. LCR_PR(BBISC);
  747. LCR_PR(CCS);
  748. LCR_PR(BBES);
  749. LCR_PR(CMDL);
  750. LCR_PR(CMDH);
  751. LCR_PR(CFC);
  752. LCR_PR(CCIFC);
  753. LCR_PR(HWT);
  754. LCR_PR(LCDCCRC);
  755. LCR_PR(LCDCC);
  756. LCR_PR(LCDCOPC);
  757. LCR_PR(LCDIS);
  758. LCR_PR(LCDIM);
  759. LCR_PR(LCDIE);
  760. LCR_PR(GDSAL);
  761. LCR_PR(GDSAH);
  762. LCR_PR(VHPCL);
  763. LCR_PR(VHPCH);
  764. LCR_PR(GM);
  765. LCR_PR(HT);
  766. LCR_PR(HDS);
  767. LCR_PR(HSS);
  768. LCR_PR(HSE);
  769. LCR_PR(HNP);
  770. LCR_PR(VT);
  771. LCR_PR(VDS);
  772. LCR_PR(VSS);
  773. LCR_PR(VSE);
  774. LCR_PR(CDLN);
  775. LCR_PR(ILN);
  776. LCR_PR(SP);
  777. LCR_PR(MISC);
  778. LCR_PR(VIHSS);
  779. LCR_PR(VIVS);
  780. LCR_PR(VIVE);
  781. LCR_PR(VIVSS);
  782. LCR_PR(VCCIS);
  783. LCR_PR(VIDWSAL);
  784. LCR_PR(VIDWSAH);
  785. LCR_PR(VIDRSAL);
  786. LCR_PR(VIDRSAH);
  787. LCR_PR(VIPDDST);
  788. LCR_PR(VIPDDET);
  789. LCR_PR(VIE);
  790. LCR_PR(VCS);
  791. LCR_PR(VPHWC);
  792. LCR_PR(VPHS);
  793. LCR_PR(VPVWC);
  794. LCR_PR(VPVS);
  795. LCR_PR(PLHPIX);
  796. LCR_PR(XS);
  797. LCR_PR(XCKHW);
  798. LCR_PR(STHS);
  799. LCR_PR(VT2);
  800. LCR_PR(YCKSW);
  801. LCR_PR(YSTS);
  802. LCR_PR(PPOLS);
  803. LCR_PR(PRECW);
  804. LCR_PR(VCLKHW);
  805. LCR_PR(OC);
  806. #undef LCR_PR
  807. }
  808. #endif
  809. #ifdef CONFIG_PM
  810. static int tmiofb_suspend(struct platform_device *dev, pm_message_t state)
  811. {
  812. struct fb_info *info = platform_get_drvdata(dev);
  813. #ifdef CONFIG_FB_TMIO_ACCELL
  814. struct tmiofb_par *par = info->par;
  815. #endif
  816. struct mfd_cell *cell = dev->dev.platform_data;
  817. int retval = 0;
  818. acquire_console_sem();
  819. fb_set_suspend(info, 1);
  820. if (info->fbops->fb_sync)
  821. info->fbops->fb_sync(info);
  822. #ifdef CONFIG_FB_TMIO_ACCELL
  823. /*
  824. * The fb should be usable even if interrupts are disabled (and they are
  825. * during suspend/resume). Switch temporary to forced polling.
  826. */
  827. printk(KERN_INFO "tmiofb: switching to polling\n");
  828. par->use_polling = true;
  829. #endif
  830. tmiofb_hw_stop(dev);
  831. if (cell->suspend)
  832. retval = cell->suspend(dev);
  833. release_console_sem();
  834. return retval;
  835. }
  836. static int tmiofb_resume(struct platform_device *dev)
  837. {
  838. struct fb_info *info = platform_get_drvdata(dev);
  839. struct mfd_cell *cell = dev->dev.platform_data;
  840. int retval;
  841. acquire_console_sem();
  842. if (cell->resume) {
  843. retval = cell->resume(dev);
  844. if (retval)
  845. goto out;
  846. }
  847. tmiofb_irq(-1, info);
  848. tmiofb_hw_init(dev);
  849. tmiofb_hw_mode(dev);
  850. fb_set_suspend(info, 0);
  851. out:
  852. release_console_sem();
  853. return retval;
  854. }
  855. #else
  856. #define tmiofb_suspend NULL
  857. #define tmiofb_resume NULL
  858. #endif
  859. static struct platform_driver tmiofb_driver = {
  860. .driver.name = "tmio-fb",
  861. .driver.owner = THIS_MODULE,
  862. .probe = tmiofb_probe,
  863. .remove = __devexit_p(tmiofb_remove),
  864. .suspend = tmiofb_suspend,
  865. .resume = tmiofb_resume,
  866. };
  867. /*--------------------------------------------------------------------------*/
  868. #ifndef MODULE
  869. static void __init tmiofb_setup(char *options)
  870. {
  871. char *this_opt;
  872. if (!options || !*options)
  873. return;
  874. while ((this_opt = strsep(&options, ",")) != NULL) {
  875. if (!*this_opt)
  876. continue;
  877. /*
  878. * FIXME
  879. */
  880. }
  881. }
  882. #endif
  883. static int __init tmiofb_init(void)
  884. {
  885. #ifndef MODULE
  886. char *option = NULL;
  887. if (fb_get_options("tmiofb", &option))
  888. return -ENODEV;
  889. tmiofb_setup(option);
  890. #endif
  891. return platform_driver_register(&tmiofb_driver);
  892. }
  893. static void __exit tmiofb_cleanup(void)
  894. {
  895. platform_driver_unregister(&tmiofb_driver);
  896. }
  897. module_init(tmiofb_init);
  898. module_exit(tmiofb_cleanup);
  899. MODULE_DESCRIPTION("TMIO framebuffer driver");
  900. MODULE_AUTHOR("Chris Humbert, Dirk Opfer, Dmitry Baryshkov");
  901. MODULE_LICENSE("GPL");