tmiofb.c 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050
  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 console_lock() */
  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 tmio_fb_data *data = mfd_get_data(dev);
  233. struct fb_info *info = platform_get_drvdata(dev);
  234. struct tmiofb_par *par = info->par;
  235. tmio_iowrite16(0, par->ccr + CCR_UGCC);
  236. tmio_iowrite16(0, par->lcr + LCR_GM);
  237. data->lcd_set_power(dev, 0);
  238. tmio_iowrite16(0x0010, par->lcr + LCR_LCDCCRC);
  239. return 0;
  240. }
  241. /*
  242. * Initializes the LCD host controller.
  243. */
  244. static int tmiofb_hw_init(struct platform_device *dev)
  245. {
  246. const struct mfd_cell *cell = mfd_get_cell(dev);
  247. struct fb_info *info = platform_get_drvdata(dev);
  248. struct tmiofb_par *par = info->par;
  249. const struct resource *nlcr = &cell->resources[0];
  250. const struct resource *vram = &cell->resources[2];
  251. unsigned long base;
  252. if (nlcr == NULL || vram == NULL)
  253. return -EINVAL;
  254. base = nlcr->start;
  255. tmio_iowrite16(0x003a, par->ccr + CCR_UGCC);
  256. tmio_iowrite16(0x003a, par->ccr + CCR_GCC);
  257. tmio_iowrite16(0x3f00, par->ccr + CCR_USC);
  258. msleep(2); /* wait for device to settle */
  259. tmio_iowrite16(0x0000, par->ccr + CCR_USC);
  260. tmio_iowrite16(base >> 16, par->ccr + CCR_BASEH);
  261. tmio_iowrite16(base, par->ccr + CCR_BASEL);
  262. tmio_iowrite16(0x0002, par->ccr + CCR_CMD); /* base address enable */
  263. tmio_iowrite16(0x40a8, par->ccr + CCR_VRAMRTC); /* VRAMRC, VRAMTC */
  264. tmio_iowrite16(0x0018, par->ccr + CCR_VRAMSAC); /* VRAMSTS, VRAMAC */
  265. tmio_iowrite16(0x0002, par->ccr + CCR_VRAMBC);
  266. msleep(2); /* wait for device to settle */
  267. tmio_iowrite16(0x000b, par->ccr + CCR_VRAMBC);
  268. base = vram->start + info->screen_size;
  269. tmio_iowrite16(base >> 16, par->lcr + LCR_CFSAH);
  270. tmio_iowrite16(base, par->lcr + LCR_CFSAL);
  271. tmio_iowrite16(TMIOFB_FIFO_SIZE - 1, par->lcr + LCR_CFS);
  272. tmio_iowrite16(1, par->lcr + LCR_CFC);
  273. tmio_iowrite16(1, par->lcr + LCR_BBIE);
  274. tmio_iowrite16(0, par->lcr + LCR_CFWS);
  275. return 0;
  276. }
  277. /*
  278. * Sets the LCD controller's output resolution and pixel clock
  279. */
  280. static void tmiofb_hw_mode(struct platform_device *dev)
  281. {
  282. struct tmio_fb_data *data = mfd_get_data(dev);
  283. struct fb_info *info = platform_get_drvdata(dev);
  284. struct fb_videomode *mode = info->mode;
  285. struct tmiofb_par *par = info->par;
  286. unsigned int i;
  287. tmio_iowrite16(0, par->lcr + LCR_GM);
  288. data->lcd_set_power(dev, 0);
  289. tmio_iowrite16(0x0010, par->lcr + LCR_LCDCCRC);
  290. data->lcd_mode(dev, mode);
  291. data->lcd_set_power(dev, 1);
  292. tmio_iowrite16(info->fix.line_length, par->lcr + LCR_VHPN);
  293. tmio_iowrite16(0, par->lcr + LCR_GDSAH);
  294. tmio_iowrite16(0, par->lcr + LCR_GDSAL);
  295. tmio_iowrite16(info->fix.line_length >> 16, par->lcr + LCR_VHPCH);
  296. tmio_iowrite16(info->fix.line_length, par->lcr + LCR_VHPCL);
  297. tmio_iowrite16(i = 0, par->lcr + LCR_HSS);
  298. tmio_iowrite16(i += mode->hsync_len, par->lcr + LCR_HSE);
  299. tmio_iowrite16(i += mode->left_margin, par->lcr + LCR_HDS);
  300. tmio_iowrite16(i += mode->xres + mode->right_margin, par->lcr + LCR_HT);
  301. tmio_iowrite16(mode->xres, par->lcr + LCR_HNP);
  302. tmio_iowrite16(i = 0, par->lcr + LCR_VSS);
  303. tmio_iowrite16(i += mode->vsync_len, par->lcr + LCR_VSE);
  304. tmio_iowrite16(i += mode->upper_margin, par->lcr + LCR_VDS);
  305. tmio_iowrite16(i += mode->yres, par->lcr + LCR_ILN);
  306. tmio_iowrite16(i += mode->lower_margin, par->lcr + LCR_VT);
  307. tmio_iowrite16(3, par->lcr + LCR_MISC); /* RGB565 mode */
  308. tmio_iowrite16(1, par->lcr + LCR_GM); /* VRAM enable */
  309. tmio_iowrite16(0x4007, par->lcr + LCR_LCDCC);
  310. tmio_iowrite16(3, par->lcr + LCR_SP); /* sync polarity */
  311. tmio_iowrite16(0x0010, par->lcr + LCR_LCDCCRC);
  312. msleep(5); /* wait for device to settle */
  313. tmio_iowrite16(0x0014, par->lcr + LCR_LCDCCRC); /* STOP_CKP */
  314. msleep(5); /* wait for device to settle */
  315. tmio_iowrite16(0x0015, par->lcr + LCR_LCDCCRC); /* STOP_CKP|SOFT_RESET*/
  316. tmio_iowrite16(0xfffa, par->lcr + LCR_VCS);
  317. }
  318. /*--------------------------------------------------------------------------*/
  319. #ifdef CONFIG_FB_TMIO_ACCELL
  320. static int __must_check
  321. tmiofb_acc_wait(struct fb_info *info, unsigned int ccs)
  322. {
  323. struct tmiofb_par *par = info->par;
  324. /*
  325. * This code can be called whith interrupts disabled.
  326. * So instead of relaying on irq to trigger the event,
  327. * poll the state till the necessary command is executed.
  328. */
  329. if (irqs_disabled() || par->use_polling) {
  330. int i = 0;
  331. while (tmio_ioread16(par->lcr + LCR_CCS) > ccs) {
  332. udelay(1);
  333. i++;
  334. if (i > 10000) {
  335. pr_err("tmiofb: timeout waiting for %d\n",
  336. ccs);
  337. return -ETIMEDOUT;
  338. }
  339. tmiofb_irq(-1, info);
  340. }
  341. } else {
  342. if (!wait_event_interruptible_timeout(par->wait_acc,
  343. tmio_ioread16(par->lcr + LCR_CCS) <= ccs,
  344. 1000)) {
  345. pr_err("tmiofb: timeout waiting for %d\n", ccs);
  346. return -ETIMEDOUT;
  347. }
  348. }
  349. return 0;
  350. }
  351. /*
  352. * Writes an accelerator command to the accelerator's FIFO.
  353. */
  354. static int
  355. tmiofb_acc_write(struct fb_info *info, const u32 *cmd, unsigned int count)
  356. {
  357. struct tmiofb_par *par = info->par;
  358. int ret;
  359. ret = tmiofb_acc_wait(info, TMIOFB_FIFO_SIZE - count);
  360. if (ret)
  361. return ret;
  362. for (; count; count--, cmd++) {
  363. tmio_iowrite16(*cmd >> 16, par->lcr + LCR_CMDH);
  364. tmio_iowrite16(*cmd, par->lcr + LCR_CMDL);
  365. }
  366. return ret;
  367. }
  368. /*
  369. * Wait for the accelerator to finish its operations before writing
  370. * to the framebuffer for consistent display output.
  371. */
  372. static int tmiofb_sync(struct fb_info *fbi)
  373. {
  374. struct tmiofb_par *par = fbi->par;
  375. int ret;
  376. int i = 0;
  377. ret = tmiofb_acc_wait(fbi, 0);
  378. while (tmio_ioread16(par->lcr + LCR_BBES) & 2) { /* blit active */
  379. udelay(1);
  380. i++ ;
  381. if (i > 10000) {
  382. printk(KERN_ERR "timeout waiting for blit to end!\n");
  383. return -ETIMEDOUT;
  384. }
  385. }
  386. return ret;
  387. }
  388. static void
  389. tmiofb_fillrect(struct fb_info *fbi, const struct fb_fillrect *rect)
  390. {
  391. const u32 cmd[] = {
  392. TMIOFB_ACC_DSADR((rect->dy * fbi->mode->xres + rect->dx) * 2),
  393. TMIOFB_ACC_DHPIX(rect->width - 1),
  394. TMIOFB_ACC_DVPIX(rect->height - 1),
  395. TMIOFB_ACC_FILL(rect->color),
  396. TMIOFB_ACC_FLGO,
  397. };
  398. if (fbi->state != FBINFO_STATE_RUNNING ||
  399. fbi->flags & FBINFO_HWACCEL_DISABLED) {
  400. cfb_fillrect(fbi, rect);
  401. return;
  402. }
  403. tmiofb_acc_write(fbi, cmd, ARRAY_SIZE(cmd));
  404. }
  405. static void
  406. tmiofb_copyarea(struct fb_info *fbi, const struct fb_copyarea *area)
  407. {
  408. const u32 cmd[] = {
  409. TMIOFB_ACC_DSADR((area->dy * fbi->mode->xres + area->dx) * 2),
  410. TMIOFB_ACC_DHPIX(area->width - 1),
  411. TMIOFB_ACC_DVPIX(area->height - 1),
  412. TMIOFB_ACC_SSADR((area->sy * fbi->mode->xres + area->sx) * 2),
  413. TMIOFB_ACC_SCGO,
  414. };
  415. if (fbi->state != FBINFO_STATE_RUNNING ||
  416. fbi->flags & FBINFO_HWACCEL_DISABLED) {
  417. cfb_copyarea(fbi, area);
  418. return;
  419. }
  420. tmiofb_acc_write(fbi, cmd, ARRAY_SIZE(cmd));
  421. }
  422. #endif
  423. static void tmiofb_clearscreen(struct fb_info *info)
  424. {
  425. const struct fb_fillrect rect = {
  426. .dx = 0,
  427. .dy = 0,
  428. .width = info->mode->xres,
  429. .height = info->mode->yres,
  430. .color = 0,
  431. .rop = ROP_COPY,
  432. };
  433. info->fbops->fb_fillrect(info, &rect);
  434. }
  435. static int tmiofb_vblank(struct fb_info *fbi, struct fb_vblank *vblank)
  436. {
  437. struct tmiofb_par *par = fbi->par;
  438. struct fb_videomode *mode = fbi->mode;
  439. unsigned int vcount = tmio_ioread16(par->lcr + LCR_CDLN);
  440. unsigned int vds = mode->vsync_len + mode->upper_margin;
  441. vblank->vcount = vcount;
  442. vblank->flags = FB_VBLANK_HAVE_VBLANK | FB_VBLANK_HAVE_VCOUNT
  443. | FB_VBLANK_HAVE_VSYNC;
  444. if (vcount < mode->vsync_len)
  445. vblank->flags |= FB_VBLANK_VSYNCING;
  446. if (vcount < vds || vcount > vds + mode->yres)
  447. vblank->flags |= FB_VBLANK_VBLANKING;
  448. return 0;
  449. }
  450. static int tmiofb_ioctl(struct fb_info *fbi,
  451. unsigned int cmd, unsigned long arg)
  452. {
  453. switch (cmd) {
  454. case FBIOGET_VBLANK: {
  455. struct fb_vblank vblank = {0};
  456. void __user *argp = (void __user *) arg;
  457. tmiofb_vblank(fbi, &vblank);
  458. if (copy_to_user(argp, &vblank, sizeof vblank))
  459. return -EFAULT;
  460. return 0;
  461. }
  462. #ifdef CONFIG_FB_TMIO_ACCELL
  463. case FBIO_TMIO_ACC_SYNC:
  464. tmiofb_sync(fbi);
  465. return 0;
  466. case FBIO_TMIO_ACC_WRITE: {
  467. u32 __user *argp = (void __user *) arg;
  468. u32 len;
  469. u32 acc[16];
  470. if (get_user(len, argp))
  471. return -EFAULT;
  472. if (len > ARRAY_SIZE(acc))
  473. return -EINVAL;
  474. if (copy_from_user(acc, argp + 1, sizeof(u32) * len))
  475. return -EFAULT;
  476. return tmiofb_acc_write(fbi, acc, len);
  477. }
  478. #endif
  479. }
  480. return -ENOTTY;
  481. }
  482. /*--------------------------------------------------------------------------*/
  483. /* Select the smallest mode that allows the desired resolution to be
  484. * displayed. If desired, the x and y parameters can be rounded up to
  485. * match the selected mode.
  486. */
  487. static struct fb_videomode *
  488. tmiofb_find_mode(struct fb_info *info, struct fb_var_screeninfo *var)
  489. {
  490. struct tmio_fb_data *data =
  491. mfd_get_data(to_platform_device(info->device));
  492. struct fb_videomode *best = NULL;
  493. int i;
  494. for (i = 0; i < data->num_modes; i++) {
  495. struct fb_videomode *mode = data->modes + i;
  496. if (mode->xres >= var->xres && mode->yres >= var->yres
  497. && (!best || (mode->xres < best->xres
  498. && mode->yres < best->yres)))
  499. best = mode;
  500. }
  501. return best;
  502. }
  503. static int tmiofb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
  504. {
  505. struct fb_videomode *mode;
  506. struct tmio_fb_data *data =
  507. mfd_get_data(to_platform_device(info->device));
  508. mode = tmiofb_find_mode(info, var);
  509. if (!mode || var->bits_per_pixel > 16)
  510. return -EINVAL;
  511. fb_videomode_to_var(var, mode);
  512. var->xres_virtual = mode->xres;
  513. var->yres_virtual = info->screen_size / (mode->xres * 2);
  514. if (var->yres_virtual < var->yres)
  515. return -EINVAL;
  516. var->xoffset = 0;
  517. var->yoffset = 0;
  518. var->bits_per_pixel = 16;
  519. var->grayscale = 0;
  520. var->red.offset = 11;
  521. var->red.length = 5;
  522. var->green.offset = 5;
  523. var->green.length = 6;
  524. var->blue.offset = 0;
  525. var->blue.length = 5;
  526. var->transp.offset = 0;
  527. var->transp.length = 0;
  528. var->nonstd = 0;
  529. var->height = data->height; /* mm */
  530. var->width = data->width; /* mm */
  531. var->rotate = 0;
  532. return 0;
  533. }
  534. static int tmiofb_set_par(struct fb_info *info)
  535. {
  536. struct fb_var_screeninfo *var = &info->var;
  537. struct fb_videomode *mode;
  538. mode = tmiofb_find_mode(info, var);
  539. if (!mode)
  540. return -EINVAL;
  541. info->mode = mode;
  542. info->fix.line_length = info->mode->xres *
  543. var->bits_per_pixel / 8;
  544. tmiofb_hw_mode(to_platform_device(info->device));
  545. tmiofb_clearscreen(info);
  546. return 0;
  547. }
  548. static int tmiofb_setcolreg(unsigned regno, unsigned red, unsigned green,
  549. unsigned blue, unsigned transp,
  550. struct fb_info *info)
  551. {
  552. struct tmiofb_par *par = info->par;
  553. if (regno < ARRAY_SIZE(par->pseudo_palette)) {
  554. par->pseudo_palette[regno] =
  555. ((red & 0xf800)) |
  556. ((green & 0xfc00) >> 5) |
  557. ((blue & 0xf800) >> 11);
  558. return 0;
  559. }
  560. return -EINVAL;
  561. }
  562. static int tmiofb_blank(int blank, struct fb_info *info)
  563. {
  564. /*
  565. * everything is done in lcd/bl drivers.
  566. * this is purely to make sysfs happy and work.
  567. */
  568. return 0;
  569. }
  570. static struct fb_ops tmiofb_ops = {
  571. .owner = THIS_MODULE,
  572. .fb_ioctl = tmiofb_ioctl,
  573. .fb_check_var = tmiofb_check_var,
  574. .fb_set_par = tmiofb_set_par,
  575. .fb_setcolreg = tmiofb_setcolreg,
  576. .fb_blank = tmiofb_blank,
  577. .fb_imageblit = cfb_imageblit,
  578. #ifdef CONFIG_FB_TMIO_ACCELL
  579. .fb_sync = tmiofb_sync,
  580. .fb_fillrect = tmiofb_fillrect,
  581. .fb_copyarea = tmiofb_copyarea,
  582. #else
  583. .fb_fillrect = cfb_fillrect,
  584. .fb_copyarea = cfb_copyarea,
  585. #endif
  586. };
  587. /*--------------------------------------------------------------------------*/
  588. static int __devinit tmiofb_probe(struct platform_device *dev)
  589. {
  590. const struct mfd_cell *cell = mfd_get_cell(dev);
  591. struct tmio_fb_data *data = mfd_get_data(dev);
  592. struct resource *ccr = platform_get_resource(dev, IORESOURCE_MEM, 1);
  593. struct resource *lcr = platform_get_resource(dev, IORESOURCE_MEM, 0);
  594. struct resource *vram = platform_get_resource(dev, IORESOURCE_MEM, 2);
  595. int irq = platform_get_irq(dev, 0);
  596. struct fb_info *info;
  597. struct tmiofb_par *par;
  598. int retval;
  599. /*
  600. * This is the only way ATM to disable the fb
  601. */
  602. if (data == NULL) {
  603. dev_err(&dev->dev, "NULL platform data!\n");
  604. return -EINVAL;
  605. }
  606. info = framebuffer_alloc(sizeof(struct tmiofb_par), &dev->dev);
  607. if (!info)
  608. return -ENOMEM;
  609. par = info->par;
  610. #ifdef CONFIG_FB_TMIO_ACCELL
  611. init_waitqueue_head(&par->wait_acc);
  612. par->use_polling = true;
  613. info->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_COPYAREA
  614. | FBINFO_HWACCEL_FILLRECT;
  615. #else
  616. info->flags = FBINFO_DEFAULT;
  617. #endif
  618. info->fbops = &tmiofb_ops;
  619. strcpy(info->fix.id, "tmio-fb");
  620. info->fix.smem_start = vram->start;
  621. info->fix.smem_len = resource_size(vram);
  622. info->fix.type = FB_TYPE_PACKED_PIXELS;
  623. info->fix.visual = FB_VISUAL_TRUECOLOR;
  624. info->fix.mmio_start = lcr->start;
  625. info->fix.mmio_len = resource_size(lcr);
  626. info->fix.accel = FB_ACCEL_NONE;
  627. info->screen_size = info->fix.smem_len - (4 * TMIOFB_FIFO_SIZE);
  628. info->pseudo_palette = par->pseudo_palette;
  629. par->ccr = ioremap(ccr->start, resource_size(ccr));
  630. if (!par->ccr) {
  631. retval = -ENOMEM;
  632. goto err_ioremap_ccr;
  633. }
  634. par->lcr = ioremap(info->fix.mmio_start, info->fix.mmio_len);
  635. if (!par->lcr) {
  636. retval = -ENOMEM;
  637. goto err_ioremap_lcr;
  638. }
  639. info->screen_base = ioremap(info->fix.smem_start, info->fix.smem_len);
  640. if (!info->screen_base) {
  641. retval = -ENOMEM;
  642. goto err_ioremap_vram;
  643. }
  644. retval = request_irq(irq, &tmiofb_irq, IRQF_DISABLED,
  645. dev_name(&dev->dev), info);
  646. if (retval)
  647. goto err_request_irq;
  648. platform_set_drvdata(dev, info);
  649. retval = fb_find_mode(&info->var, info, mode_option,
  650. data->modes, data->num_modes,
  651. data->modes, 16);
  652. if (!retval) {
  653. retval = -EINVAL;
  654. goto err_find_mode;
  655. }
  656. if (cell->enable) {
  657. retval = cell->enable(dev);
  658. if (retval)
  659. goto err_enable;
  660. }
  661. retval = tmiofb_hw_init(dev);
  662. if (retval)
  663. goto err_hw_init;
  664. fb_videomode_to_modelist(data->modes, data->num_modes,
  665. &info->modelist);
  666. retval = register_framebuffer(info);
  667. if (retval < 0)
  668. goto err_register_framebuffer;
  669. printk(KERN_INFO "fb%d: %s frame buffer device\n",
  670. info->node, info->fix.id);
  671. return 0;
  672. err_register_framebuffer:
  673. /*err_set_par:*/
  674. tmiofb_hw_stop(dev);
  675. err_hw_init:
  676. if (cell->disable)
  677. cell->disable(dev);
  678. err_enable:
  679. err_find_mode:
  680. platform_set_drvdata(dev, NULL);
  681. free_irq(irq, info);
  682. err_request_irq:
  683. iounmap(info->screen_base);
  684. err_ioremap_vram:
  685. iounmap(par->lcr);
  686. err_ioremap_lcr:
  687. iounmap(par->ccr);
  688. err_ioremap_ccr:
  689. framebuffer_release(info);
  690. return retval;
  691. }
  692. static int __devexit tmiofb_remove(struct platform_device *dev)
  693. {
  694. const struct mfd_cell *cell = mfd_get_cell(dev);
  695. struct fb_info *info = platform_get_drvdata(dev);
  696. int irq = platform_get_irq(dev, 0);
  697. struct tmiofb_par *par;
  698. if (info) {
  699. par = info->par;
  700. unregister_framebuffer(info);
  701. tmiofb_hw_stop(dev);
  702. if (cell->disable)
  703. cell->disable(dev);
  704. platform_set_drvdata(dev, NULL);
  705. free_irq(irq, info);
  706. iounmap(info->screen_base);
  707. iounmap(par->lcr);
  708. iounmap(par->ccr);
  709. framebuffer_release(info);
  710. }
  711. return 0;
  712. }
  713. #ifdef DEBUG
  714. static void tmiofb_dump_regs(struct platform_device *dev)
  715. {
  716. struct fb_info *info = platform_get_drvdata(dev);
  717. struct tmiofb_par *par = info->par;
  718. printk(KERN_DEBUG "lhccr:\n");
  719. #define CCR_PR(n) printk(KERN_DEBUG "\t" #n " = \t%04x\n",\
  720. tmio_ioread16(par->ccr + CCR_ ## n));
  721. CCR_PR(CMD);
  722. CCR_PR(REVID);
  723. CCR_PR(BASEL);
  724. CCR_PR(BASEH);
  725. CCR_PR(UGCC);
  726. CCR_PR(GCC);
  727. CCR_PR(USC);
  728. CCR_PR(VRAMRTC);
  729. CCR_PR(VRAMSAC);
  730. CCR_PR(VRAMBC);
  731. #undef CCR_PR
  732. printk(KERN_DEBUG "lcr: \n");
  733. #define LCR_PR(n) printk(KERN_DEBUG "\t" #n " = \t%04x\n",\
  734. tmio_ioread16(par->lcr + LCR_ ## n));
  735. LCR_PR(UIS);
  736. LCR_PR(VHPN);
  737. LCR_PR(CFSAL);
  738. LCR_PR(CFSAH);
  739. LCR_PR(CFS);
  740. LCR_PR(CFWS);
  741. LCR_PR(BBIE);
  742. LCR_PR(BBISC);
  743. LCR_PR(CCS);
  744. LCR_PR(BBES);
  745. LCR_PR(CMDL);
  746. LCR_PR(CMDH);
  747. LCR_PR(CFC);
  748. LCR_PR(CCIFC);
  749. LCR_PR(HWT);
  750. LCR_PR(LCDCCRC);
  751. LCR_PR(LCDCC);
  752. LCR_PR(LCDCOPC);
  753. LCR_PR(LCDIS);
  754. LCR_PR(LCDIM);
  755. LCR_PR(LCDIE);
  756. LCR_PR(GDSAL);
  757. LCR_PR(GDSAH);
  758. LCR_PR(VHPCL);
  759. LCR_PR(VHPCH);
  760. LCR_PR(GM);
  761. LCR_PR(HT);
  762. LCR_PR(HDS);
  763. LCR_PR(HSS);
  764. LCR_PR(HSE);
  765. LCR_PR(HNP);
  766. LCR_PR(VT);
  767. LCR_PR(VDS);
  768. LCR_PR(VSS);
  769. LCR_PR(VSE);
  770. LCR_PR(CDLN);
  771. LCR_PR(ILN);
  772. LCR_PR(SP);
  773. LCR_PR(MISC);
  774. LCR_PR(VIHSS);
  775. LCR_PR(VIVS);
  776. LCR_PR(VIVE);
  777. LCR_PR(VIVSS);
  778. LCR_PR(VCCIS);
  779. LCR_PR(VIDWSAL);
  780. LCR_PR(VIDWSAH);
  781. LCR_PR(VIDRSAL);
  782. LCR_PR(VIDRSAH);
  783. LCR_PR(VIPDDST);
  784. LCR_PR(VIPDDET);
  785. LCR_PR(VIE);
  786. LCR_PR(VCS);
  787. LCR_PR(VPHWC);
  788. LCR_PR(VPHS);
  789. LCR_PR(VPVWC);
  790. LCR_PR(VPVS);
  791. LCR_PR(PLHPIX);
  792. LCR_PR(XS);
  793. LCR_PR(XCKHW);
  794. LCR_PR(STHS);
  795. LCR_PR(VT2);
  796. LCR_PR(YCKSW);
  797. LCR_PR(YSTS);
  798. LCR_PR(PPOLS);
  799. LCR_PR(PRECW);
  800. LCR_PR(VCLKHW);
  801. LCR_PR(OC);
  802. #undef LCR_PR
  803. }
  804. #endif
  805. #ifdef CONFIG_PM
  806. static int tmiofb_suspend(struct platform_device *dev, pm_message_t state)
  807. {
  808. struct fb_info *info = platform_get_drvdata(dev);
  809. #ifdef CONFIG_FB_TMIO_ACCELL
  810. struct tmiofb_par *par = info->par;
  811. #endif
  812. const struct mfd_cell *cell = mfd_get_cell(dev);
  813. int retval = 0;
  814. console_lock();
  815. fb_set_suspend(info, 1);
  816. if (info->fbops->fb_sync)
  817. info->fbops->fb_sync(info);
  818. #ifdef CONFIG_FB_TMIO_ACCELL
  819. /*
  820. * The fb should be usable even if interrupts are disabled (and they are
  821. * during suspend/resume). Switch temporary to forced polling.
  822. */
  823. printk(KERN_INFO "tmiofb: switching to polling\n");
  824. par->use_polling = true;
  825. #endif
  826. tmiofb_hw_stop(dev);
  827. if (cell->suspend)
  828. retval = cell->suspend(dev);
  829. console_unlock();
  830. return retval;
  831. }
  832. static int tmiofb_resume(struct platform_device *dev)
  833. {
  834. struct fb_info *info = platform_get_drvdata(dev);
  835. const struct mfd_cell *cell = mfd_get_cell(dev);
  836. int retval = 0;
  837. console_lock();
  838. if (cell->resume) {
  839. retval = cell->resume(dev);
  840. if (retval)
  841. goto out;
  842. }
  843. tmiofb_irq(-1, info);
  844. tmiofb_hw_init(dev);
  845. tmiofb_hw_mode(dev);
  846. fb_set_suspend(info, 0);
  847. out:
  848. console_unlock();
  849. return retval;
  850. }
  851. #else
  852. #define tmiofb_suspend NULL
  853. #define tmiofb_resume NULL
  854. #endif
  855. static struct platform_driver tmiofb_driver = {
  856. .driver.name = "tmio-fb",
  857. .driver.owner = THIS_MODULE,
  858. .probe = tmiofb_probe,
  859. .remove = __devexit_p(tmiofb_remove),
  860. .suspend = tmiofb_suspend,
  861. .resume = tmiofb_resume,
  862. };
  863. /*--------------------------------------------------------------------------*/
  864. #ifndef MODULE
  865. static void __init tmiofb_setup(char *options)
  866. {
  867. char *this_opt;
  868. if (!options || !*options)
  869. return;
  870. while ((this_opt = strsep(&options, ",")) != NULL) {
  871. if (!*this_opt)
  872. continue;
  873. /*
  874. * FIXME
  875. */
  876. }
  877. }
  878. #endif
  879. static int __init tmiofb_init(void)
  880. {
  881. #ifndef MODULE
  882. char *option = NULL;
  883. if (fb_get_options("tmiofb", &option))
  884. return -ENODEV;
  885. tmiofb_setup(option);
  886. #endif
  887. return platform_driver_register(&tmiofb_driver);
  888. }
  889. static void __exit tmiofb_cleanup(void)
  890. {
  891. platform_driver_unregister(&tmiofb_driver);
  892. }
  893. module_init(tmiofb_init);
  894. module_exit(tmiofb_cleanup);
  895. MODULE_DESCRIPTION("TMIO framebuffer driver");
  896. MODULE_AUTHOR("Chris Humbert, Dirk Opfer, Dmitry Baryshkov");
  897. MODULE_LICENSE("GPL");