pxafb.c 50 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919
  1. /*
  2. * linux/drivers/video/pxafb.c
  3. *
  4. * Copyright (C) 1999 Eric A. Thomas.
  5. * Copyright (C) 2004 Jean-Frederic Clere.
  6. * Copyright (C) 2004 Ian Campbell.
  7. * Copyright (C) 2004 Jeff Lackey.
  8. * Based on sa1100fb.c Copyright (C) 1999 Eric A. Thomas
  9. * which in turn is
  10. * Based on acornfb.c Copyright (C) Russell King.
  11. *
  12. * This file is subject to the terms and conditions of the GNU General Public
  13. * License. See the file COPYING in the main directory of this archive for
  14. * more details.
  15. *
  16. * Intel PXA250/210 LCD Controller Frame Buffer Driver
  17. *
  18. * Please direct your questions and comments on this driver to the following
  19. * email address:
  20. *
  21. * linux-arm-kernel@lists.arm.linux.org.uk
  22. *
  23. */
  24. #include <linux/module.h>
  25. #include <linux/moduleparam.h>
  26. #include <linux/kernel.h>
  27. #include <linux/sched.h>
  28. #include <linux/errno.h>
  29. #include <linux/string.h>
  30. #include <linux/interrupt.h>
  31. #include <linux/slab.h>
  32. #include <linux/mm.h>
  33. #include <linux/fb.h>
  34. #include <linux/delay.h>
  35. #include <linux/init.h>
  36. #include <linux/ioport.h>
  37. #include <linux/cpufreq.h>
  38. #include <linux/platform_device.h>
  39. #include <linux/dma-mapping.h>
  40. #include <linux/clk.h>
  41. #include <linux/err.h>
  42. #include <linux/completion.h>
  43. #include <linux/mutex.h>
  44. #include <linux/kthread.h>
  45. #include <linux/freezer.h>
  46. #include <asm/hardware.h>
  47. #include <asm/io.h>
  48. #include <asm/irq.h>
  49. #include <asm/div64.h>
  50. #include <asm/arch/pxa-regs.h>
  51. #include <asm/arch/pxa2xx-gpio.h>
  52. #include <asm/arch/bitfield.h>
  53. #include <asm/arch/pxafb.h>
  54. /*
  55. * Complain if VAR is out of range.
  56. */
  57. #define DEBUG_VAR 1
  58. #include "pxafb.h"
  59. /* Bits which should not be set in machine configuration structures */
  60. #define LCCR0_INVALID_CONFIG_MASK (LCCR0_OUM | LCCR0_BM | LCCR0_QDM |\
  61. LCCR0_DIS | LCCR0_EFM | LCCR0_IUM |\
  62. LCCR0_SFM | LCCR0_LDM | LCCR0_ENB)
  63. #define LCCR3_INVALID_CONFIG_MASK (LCCR3_HSP | LCCR3_VSP |\
  64. LCCR3_PCD | LCCR3_BPP)
  65. static void (*pxafb_backlight_power)(int);
  66. static void (*pxafb_lcd_power)(int, struct fb_var_screeninfo *);
  67. static int pxafb_activate_var(struct fb_var_screeninfo *var,
  68. struct pxafb_info *);
  69. static void set_ctrlr_state(struct pxafb_info *fbi, u_int state);
  70. static inline unsigned long
  71. lcd_readl(struct pxafb_info *fbi, unsigned int off)
  72. {
  73. return __raw_readl(fbi->mmio_base + off);
  74. }
  75. static inline void
  76. lcd_writel(struct pxafb_info *fbi, unsigned int off, unsigned long val)
  77. {
  78. __raw_writel(val, fbi->mmio_base + off);
  79. }
  80. static inline void pxafb_schedule_work(struct pxafb_info *fbi, u_int state)
  81. {
  82. unsigned long flags;
  83. local_irq_save(flags);
  84. /*
  85. * We need to handle two requests being made at the same time.
  86. * There are two important cases:
  87. * 1. When we are changing VT (C_REENABLE) while unblanking
  88. * (C_ENABLE) We must perform the unblanking, which will
  89. * do our REENABLE for us.
  90. * 2. When we are blanking, but immediately unblank before
  91. * we have blanked. We do the "REENABLE" thing here as
  92. * well, just to be sure.
  93. */
  94. if (fbi->task_state == C_ENABLE && state == C_REENABLE)
  95. state = (u_int) -1;
  96. if (fbi->task_state == C_DISABLE && state == C_ENABLE)
  97. state = C_REENABLE;
  98. if (state != (u_int)-1) {
  99. fbi->task_state = state;
  100. schedule_work(&fbi->task);
  101. }
  102. local_irq_restore(flags);
  103. }
  104. static inline u_int chan_to_field(u_int chan, struct fb_bitfield *bf)
  105. {
  106. chan &= 0xffff;
  107. chan >>= 16 - bf->length;
  108. return chan << bf->offset;
  109. }
  110. static int
  111. pxafb_setpalettereg(u_int regno, u_int red, u_int green, u_int blue,
  112. u_int trans, struct fb_info *info)
  113. {
  114. struct pxafb_info *fbi = (struct pxafb_info *)info;
  115. u_int val;
  116. if (regno >= fbi->palette_size)
  117. return 1;
  118. if (fbi->fb.var.grayscale) {
  119. fbi->palette_cpu[regno] = ((blue >> 8) & 0x00ff);
  120. return 0;
  121. }
  122. switch (fbi->lccr4 & LCCR4_PAL_FOR_MASK) {
  123. case LCCR4_PAL_FOR_0:
  124. val = ((red >> 0) & 0xf800);
  125. val |= ((green >> 5) & 0x07e0);
  126. val |= ((blue >> 11) & 0x001f);
  127. fbi->palette_cpu[regno] = val;
  128. break;
  129. case LCCR4_PAL_FOR_1:
  130. val = ((red << 8) & 0x00f80000);
  131. val |= ((green >> 0) & 0x0000fc00);
  132. val |= ((blue >> 8) & 0x000000f8);
  133. ((u32 *)(fbi->palette_cpu))[regno] = val;
  134. break;
  135. case LCCR4_PAL_FOR_2:
  136. val = ((red << 8) & 0x00fc0000);
  137. val |= ((green >> 0) & 0x0000fc00);
  138. val |= ((blue >> 8) & 0x000000fc);
  139. ((u32 *)(fbi->palette_cpu))[regno] = val;
  140. break;
  141. }
  142. return 0;
  143. }
  144. static int
  145. pxafb_setcolreg(u_int regno, u_int red, u_int green, u_int blue,
  146. u_int trans, struct fb_info *info)
  147. {
  148. struct pxafb_info *fbi = (struct pxafb_info *)info;
  149. unsigned int val;
  150. int ret = 1;
  151. /*
  152. * If inverse mode was selected, invert all the colours
  153. * rather than the register number. The register number
  154. * is what you poke into the framebuffer to produce the
  155. * colour you requested.
  156. */
  157. if (fbi->cmap_inverse) {
  158. red = 0xffff - red;
  159. green = 0xffff - green;
  160. blue = 0xffff - blue;
  161. }
  162. /*
  163. * If greyscale is true, then we convert the RGB value
  164. * to greyscale no matter what visual we are using.
  165. */
  166. if (fbi->fb.var.grayscale)
  167. red = green = blue = (19595 * red + 38470 * green +
  168. 7471 * blue) >> 16;
  169. switch (fbi->fb.fix.visual) {
  170. case FB_VISUAL_TRUECOLOR:
  171. /*
  172. * 16-bit True Colour. We encode the RGB value
  173. * according to the RGB bitfield information.
  174. */
  175. if (regno < 16) {
  176. u32 *pal = fbi->fb.pseudo_palette;
  177. val = chan_to_field(red, &fbi->fb.var.red);
  178. val |= chan_to_field(green, &fbi->fb.var.green);
  179. val |= chan_to_field(blue, &fbi->fb.var.blue);
  180. pal[regno] = val;
  181. ret = 0;
  182. }
  183. break;
  184. case FB_VISUAL_STATIC_PSEUDOCOLOR:
  185. case FB_VISUAL_PSEUDOCOLOR:
  186. ret = pxafb_setpalettereg(regno, red, green, blue, trans, info);
  187. break;
  188. }
  189. return ret;
  190. }
  191. /*
  192. * pxafb_bpp_to_lccr3():
  193. * Convert a bits per pixel value to the correct bit pattern for LCCR3
  194. */
  195. static int pxafb_bpp_to_lccr3(struct fb_var_screeninfo *var)
  196. {
  197. int ret = 0;
  198. switch (var->bits_per_pixel) {
  199. case 1: ret = LCCR3_1BPP; break;
  200. case 2: ret = LCCR3_2BPP; break;
  201. case 4: ret = LCCR3_4BPP; break;
  202. case 8: ret = LCCR3_8BPP; break;
  203. case 16: ret = LCCR3_16BPP; break;
  204. case 24:
  205. switch (var->red.length + var->green.length +
  206. var->blue.length + var->transp.length) {
  207. case 18: ret = LCCR3_18BPP_P | LCCR3_PDFOR_3; break;
  208. case 19: ret = LCCR3_19BPP_P; break;
  209. }
  210. break;
  211. case 32:
  212. switch (var->red.length + var->green.length +
  213. var->blue.length + var->transp.length) {
  214. case 18: ret = LCCR3_18BPP | LCCR3_PDFOR_3; break;
  215. case 19: ret = LCCR3_19BPP; break;
  216. case 24: ret = LCCR3_24BPP | LCCR3_PDFOR_3; break;
  217. case 25: ret = LCCR3_25BPP; break;
  218. }
  219. break;
  220. }
  221. return ret;
  222. }
  223. #ifdef CONFIG_CPU_FREQ
  224. /*
  225. * pxafb_display_dma_period()
  226. * Calculate the minimum period (in picoseconds) between two DMA
  227. * requests for the LCD controller. If we hit this, it means we're
  228. * doing nothing but LCD DMA.
  229. */
  230. static unsigned int pxafb_display_dma_period(struct fb_var_screeninfo *var)
  231. {
  232. /*
  233. * Period = pixclock * bits_per_byte * bytes_per_transfer
  234. * / memory_bits_per_pixel;
  235. */
  236. return var->pixclock * 8 * 16 / var->bits_per_pixel;
  237. }
  238. #endif
  239. /*
  240. * Select the smallest mode that allows the desired resolution to be
  241. * displayed. If desired parameters can be rounded up.
  242. */
  243. static struct pxafb_mode_info *pxafb_getmode(struct pxafb_mach_info *mach,
  244. struct fb_var_screeninfo *var)
  245. {
  246. struct pxafb_mode_info *mode = NULL;
  247. struct pxafb_mode_info *modelist = mach->modes;
  248. unsigned int best_x = 0xffffffff, best_y = 0xffffffff;
  249. unsigned int i;
  250. for (i = 0; i < mach->num_modes; i++) {
  251. if (modelist[i].xres >= var->xres &&
  252. modelist[i].yres >= var->yres &&
  253. modelist[i].xres < best_x &&
  254. modelist[i].yres < best_y &&
  255. modelist[i].bpp >= var->bits_per_pixel) {
  256. best_x = modelist[i].xres;
  257. best_y = modelist[i].yres;
  258. mode = &modelist[i];
  259. }
  260. }
  261. return mode;
  262. }
  263. static void pxafb_setmode(struct fb_var_screeninfo *var,
  264. struct pxafb_mode_info *mode)
  265. {
  266. var->xres = mode->xres;
  267. var->yres = mode->yres;
  268. var->bits_per_pixel = mode->bpp;
  269. var->pixclock = mode->pixclock;
  270. var->hsync_len = mode->hsync_len;
  271. var->left_margin = mode->left_margin;
  272. var->right_margin = mode->right_margin;
  273. var->vsync_len = mode->vsync_len;
  274. var->upper_margin = mode->upper_margin;
  275. var->lower_margin = mode->lower_margin;
  276. var->sync = mode->sync;
  277. var->grayscale = mode->cmap_greyscale;
  278. var->xres_virtual = var->xres;
  279. var->yres_virtual = var->yres;
  280. }
  281. /*
  282. * pxafb_check_var():
  283. * Get the video params out of 'var'. If a value doesn't fit, round it up,
  284. * if it's too big, return -EINVAL.
  285. *
  286. * Round up in the following order: bits_per_pixel, xres,
  287. * yres, xres_virtual, yres_virtual, xoffset, yoffset, grayscale,
  288. * bitfields, horizontal timing, vertical timing.
  289. */
  290. static int pxafb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
  291. {
  292. struct pxafb_info *fbi = (struct pxafb_info *)info;
  293. struct pxafb_mach_info *inf = fbi->dev->platform_data;
  294. if (var->xres < MIN_XRES)
  295. var->xres = MIN_XRES;
  296. if (var->yres < MIN_YRES)
  297. var->yres = MIN_YRES;
  298. if (inf->fixed_modes) {
  299. struct pxafb_mode_info *mode;
  300. mode = pxafb_getmode(inf, var);
  301. if (!mode)
  302. return -EINVAL;
  303. pxafb_setmode(var, mode);
  304. } else {
  305. if (var->xres > inf->modes->xres)
  306. return -EINVAL;
  307. if (var->yres > inf->modes->yres)
  308. return -EINVAL;
  309. if (var->bits_per_pixel > inf->modes->bpp)
  310. return -EINVAL;
  311. }
  312. var->xres_virtual =
  313. max(var->xres_virtual, var->xres);
  314. var->yres_virtual =
  315. max(var->yres_virtual, var->yres);
  316. /*
  317. * Setup the RGB parameters for this display.
  318. *
  319. * The pixel packing format is described on page 7-11 of the
  320. * PXA2XX Developer's Manual.
  321. */
  322. if (var->bits_per_pixel == 16) {
  323. var->red.offset = 11; var->red.length = 5;
  324. var->green.offset = 5; var->green.length = 6;
  325. var->blue.offset = 0; var->blue.length = 5;
  326. var->transp.offset = var->transp.length = 0;
  327. } else if (var->bits_per_pixel > 16) {
  328. struct pxafb_mode_info *mode;
  329. mode = pxafb_getmode(inf, var);
  330. if (!mode)
  331. return -EINVAL;
  332. switch (mode->depth) {
  333. case 18: /* RGB666 */
  334. var->transp.offset = var->transp.length = 0;
  335. var->red.offset = 12; var->red.length = 6;
  336. var->green.offset = 6; var->green.length = 6;
  337. var->blue.offset = 0; var->blue.length = 6;
  338. break;
  339. case 19: /* RGBT666 */
  340. var->transp.offset = 18; var->transp.length = 1;
  341. var->red.offset = 12; var->red.length = 6;
  342. var->green.offset = 6; var->green.length = 6;
  343. var->blue.offset = 0; var->blue.length = 6;
  344. break;
  345. case 24: /* RGB888 */
  346. var->transp.offset = var->transp.length = 0;
  347. var->red.offset = 16; var->red.length = 8;
  348. var->green.offset = 8; var->green.length = 8;
  349. var->blue.offset = 0; var->blue.length = 8;
  350. break;
  351. case 25: /* RGBT888 */
  352. var->transp.offset = 24; var->transp.length = 1;
  353. var->red.offset = 16; var->red.length = 8;
  354. var->green.offset = 8; var->green.length = 8;
  355. var->blue.offset = 0; var->blue.length = 8;
  356. break;
  357. default:
  358. return -EINVAL;
  359. }
  360. } else {
  361. var->red.offset = var->green.offset = 0;
  362. var->blue.offset = var->transp.offset = 0;
  363. var->red.length = 8;
  364. var->green.length = 8;
  365. var->blue.length = 8;
  366. var->transp.length = 0;
  367. }
  368. #ifdef CONFIG_CPU_FREQ
  369. pr_debug("pxafb: dma period = %d ps\n",
  370. pxafb_display_dma_period(var));
  371. #endif
  372. return 0;
  373. }
  374. static inline void pxafb_set_truecolor(u_int is_true_color)
  375. {
  376. /* do your machine-specific setup if needed */
  377. }
  378. /*
  379. * pxafb_set_par():
  380. * Set the user defined part of the display for the specified console
  381. */
  382. static int pxafb_set_par(struct fb_info *info)
  383. {
  384. struct pxafb_info *fbi = (struct pxafb_info *)info;
  385. struct fb_var_screeninfo *var = &info->var;
  386. if (var->bits_per_pixel >= 16)
  387. fbi->fb.fix.visual = FB_VISUAL_TRUECOLOR;
  388. else if (!fbi->cmap_static)
  389. fbi->fb.fix.visual = FB_VISUAL_PSEUDOCOLOR;
  390. else {
  391. /*
  392. * Some people have weird ideas about wanting static
  393. * pseudocolor maps. I suspect their user space
  394. * applications are broken.
  395. */
  396. fbi->fb.fix.visual = FB_VISUAL_STATIC_PSEUDOCOLOR;
  397. }
  398. fbi->fb.fix.line_length = var->xres_virtual *
  399. var->bits_per_pixel / 8;
  400. if (var->bits_per_pixel >= 16)
  401. fbi->palette_size = 0;
  402. else
  403. fbi->palette_size = var->bits_per_pixel == 1 ?
  404. 4 : 1 << var->bits_per_pixel;
  405. fbi->palette_cpu = (u16 *)&fbi->dma_buff->palette[0];
  406. /*
  407. * Set (any) board control register to handle new color depth
  408. */
  409. pxafb_set_truecolor(fbi->fb.fix.visual == FB_VISUAL_TRUECOLOR);
  410. if (fbi->fb.var.bits_per_pixel >= 16)
  411. fb_dealloc_cmap(&fbi->fb.cmap);
  412. else
  413. fb_alloc_cmap(&fbi->fb.cmap, 1<<fbi->fb.var.bits_per_pixel, 0);
  414. pxafb_activate_var(var, fbi);
  415. return 0;
  416. }
  417. /*
  418. * pxafb_blank():
  419. * Blank the display by setting all palette values to zero. Note, the
  420. * 16 bpp mode does not really use the palette, so this will not
  421. * blank the display in all modes.
  422. */
  423. static int pxafb_blank(int blank, struct fb_info *info)
  424. {
  425. struct pxafb_info *fbi = (struct pxafb_info *)info;
  426. int i;
  427. switch (blank) {
  428. case FB_BLANK_POWERDOWN:
  429. case FB_BLANK_VSYNC_SUSPEND:
  430. case FB_BLANK_HSYNC_SUSPEND:
  431. case FB_BLANK_NORMAL:
  432. if (fbi->fb.fix.visual == FB_VISUAL_PSEUDOCOLOR ||
  433. fbi->fb.fix.visual == FB_VISUAL_STATIC_PSEUDOCOLOR)
  434. for (i = 0; i < fbi->palette_size; i++)
  435. pxafb_setpalettereg(i, 0, 0, 0, 0, info);
  436. pxafb_schedule_work(fbi, C_DISABLE);
  437. /* TODO if (pxafb_blank_helper) pxafb_blank_helper(blank); */
  438. break;
  439. case FB_BLANK_UNBLANK:
  440. /* TODO if (pxafb_blank_helper) pxafb_blank_helper(blank); */
  441. if (fbi->fb.fix.visual == FB_VISUAL_PSEUDOCOLOR ||
  442. fbi->fb.fix.visual == FB_VISUAL_STATIC_PSEUDOCOLOR)
  443. fb_set_cmap(&fbi->fb.cmap, info);
  444. pxafb_schedule_work(fbi, C_ENABLE);
  445. }
  446. return 0;
  447. }
  448. static int pxafb_mmap(struct fb_info *info,
  449. struct vm_area_struct *vma)
  450. {
  451. struct pxafb_info *fbi = (struct pxafb_info *)info;
  452. unsigned long off = vma->vm_pgoff << PAGE_SHIFT;
  453. if (off < info->fix.smem_len) {
  454. vma->vm_pgoff += fbi->video_offset / PAGE_SIZE;
  455. return dma_mmap_writecombine(fbi->dev, vma, fbi->map_cpu,
  456. fbi->map_dma, fbi->map_size);
  457. }
  458. return -EINVAL;
  459. }
  460. static struct fb_ops pxafb_ops = {
  461. .owner = THIS_MODULE,
  462. .fb_check_var = pxafb_check_var,
  463. .fb_set_par = pxafb_set_par,
  464. .fb_setcolreg = pxafb_setcolreg,
  465. .fb_fillrect = cfb_fillrect,
  466. .fb_copyarea = cfb_copyarea,
  467. .fb_imageblit = cfb_imageblit,
  468. .fb_blank = pxafb_blank,
  469. .fb_mmap = pxafb_mmap,
  470. };
  471. /*
  472. * Calculate the PCD value from the clock rate (in picoseconds).
  473. * We take account of the PPCR clock setting.
  474. * From PXA Developer's Manual:
  475. *
  476. * PixelClock = LCLK
  477. * -------------
  478. * 2 ( PCD + 1 )
  479. *
  480. * PCD = LCLK
  481. * ------------- - 1
  482. * 2(PixelClock)
  483. *
  484. * Where:
  485. * LCLK = LCD/Memory Clock
  486. * PCD = LCCR3[7:0]
  487. *
  488. * PixelClock here is in Hz while the pixclock argument given is the
  489. * period in picoseconds. Hence PixelClock = 1 / ( pixclock * 10^-12 )
  490. *
  491. * The function get_lclk_frequency_10khz returns LCLK in units of
  492. * 10khz. Calling the result of this function lclk gives us the
  493. * following
  494. *
  495. * PCD = (lclk * 10^4 ) * ( pixclock * 10^-12 )
  496. * -------------------------------------- - 1
  497. * 2
  498. *
  499. * Factoring the 10^4 and 10^-12 out gives 10^-8 == 1 / 100000000 as used below.
  500. */
  501. static inline unsigned int get_pcd(struct pxafb_info *fbi,
  502. unsigned int pixclock)
  503. {
  504. unsigned long long pcd;
  505. /* FIXME: Need to take into account Double Pixel Clock mode
  506. * (DPC) bit? or perhaps set it based on the various clock
  507. * speeds */
  508. pcd = (unsigned long long)(clk_get_rate(fbi->clk) / 10000);
  509. pcd *= pixclock;
  510. do_div(pcd, 100000000 * 2);
  511. /* no need for this, since we should subtract 1 anyway. they cancel */
  512. /* pcd += 1; */ /* make up for integer math truncations */
  513. return (unsigned int)pcd;
  514. }
  515. /*
  516. * Some touchscreens need hsync information from the video driver to
  517. * function correctly. We export it here. Note that 'hsync_time' and
  518. * the value returned from pxafb_get_hsync_time() is the *reciprocal*
  519. * of the hsync period in seconds.
  520. */
  521. static inline void set_hsync_time(struct pxafb_info *fbi, unsigned int pcd)
  522. {
  523. unsigned long htime;
  524. if ((pcd == 0) || (fbi->fb.var.hsync_len == 0)) {
  525. fbi->hsync_time = 0;
  526. return;
  527. }
  528. htime = clk_get_rate(fbi->clk) / (pcd * fbi->fb.var.hsync_len);
  529. fbi->hsync_time = htime;
  530. }
  531. unsigned long pxafb_get_hsync_time(struct device *dev)
  532. {
  533. struct pxafb_info *fbi = dev_get_drvdata(dev);
  534. /* If display is blanked/suspended, hsync isn't active */
  535. if (!fbi || (fbi->state != C_ENABLE))
  536. return 0;
  537. return fbi->hsync_time;
  538. }
  539. EXPORT_SYMBOL(pxafb_get_hsync_time);
  540. static int setup_frame_dma(struct pxafb_info *fbi, int dma, int pal,
  541. unsigned int offset, size_t size)
  542. {
  543. struct pxafb_dma_descriptor *dma_desc, *pal_desc;
  544. unsigned int dma_desc_off, pal_desc_off;
  545. if (dma < 0 || dma >= DMA_MAX)
  546. return -EINVAL;
  547. dma_desc = &fbi->dma_buff->dma_desc[dma];
  548. dma_desc_off = offsetof(struct pxafb_dma_buff, dma_desc[dma]);
  549. dma_desc->fsadr = fbi->screen_dma + offset;
  550. dma_desc->fidr = 0;
  551. dma_desc->ldcmd = size;
  552. if (pal < 0 || pal >= PAL_MAX) {
  553. dma_desc->fdadr = fbi->dma_buff_phys + dma_desc_off;
  554. fbi->fdadr[dma] = fbi->dma_buff_phys + dma_desc_off;
  555. } else {
  556. pal_desc = &fbi->dma_buff->pal_desc[pal];
  557. pal_desc_off = offsetof(struct pxafb_dma_buff, pal_desc[pal]);
  558. pal_desc->fsadr = fbi->dma_buff_phys + pal * PALETTE_SIZE;
  559. pal_desc->fidr = 0;
  560. if ((fbi->lccr4 & LCCR4_PAL_FOR_MASK) == LCCR4_PAL_FOR_0)
  561. pal_desc->ldcmd = fbi->palette_size * sizeof(u16);
  562. else
  563. pal_desc->ldcmd = fbi->palette_size * sizeof(u32);
  564. pal_desc->ldcmd |= LDCMD_PAL;
  565. /* flip back and forth between palette and frame buffer */
  566. pal_desc->fdadr = fbi->dma_buff_phys + dma_desc_off;
  567. dma_desc->fdadr = fbi->dma_buff_phys + pal_desc_off;
  568. fbi->fdadr[dma] = fbi->dma_buff_phys + dma_desc_off;
  569. }
  570. return 0;
  571. }
  572. #ifdef CONFIG_FB_PXA_SMARTPANEL
  573. static int setup_smart_dma(struct pxafb_info *fbi)
  574. {
  575. struct pxafb_dma_descriptor *dma_desc;
  576. unsigned long dma_desc_off, cmd_buff_off;
  577. dma_desc = &fbi->dma_buff->dma_desc[DMA_CMD];
  578. dma_desc_off = offsetof(struct pxafb_dma_buff, dma_desc[DMA_CMD]);
  579. cmd_buff_off = offsetof(struct pxafb_dma_buff, cmd_buff);
  580. dma_desc->fdadr = fbi->dma_buff_phys + dma_desc_off;
  581. dma_desc->fsadr = fbi->dma_buff_phys + cmd_buff_off;
  582. dma_desc->fidr = 0;
  583. dma_desc->ldcmd = fbi->n_smart_cmds * sizeof(uint16_t);
  584. fbi->fdadr[DMA_CMD] = dma_desc->fdadr;
  585. return 0;
  586. }
  587. int pxafb_smart_flush(struct fb_info *info)
  588. {
  589. struct pxafb_info *fbi = container_of(info, struct pxafb_info, fb);
  590. uint32_t prsr;
  591. int ret = 0;
  592. /* disable controller until all registers are set up */
  593. lcd_writel(fbi, LCCR0, fbi->reg_lccr0 & ~LCCR0_ENB);
  594. /* 1. make it an even number of commands to align on 32-bit boundary
  595. * 2. add the interrupt command to the end of the chain so we can
  596. * keep track of the end of the transfer
  597. */
  598. while (fbi->n_smart_cmds & 1)
  599. fbi->smart_cmds[fbi->n_smart_cmds++] = SMART_CMD_NOOP;
  600. fbi->smart_cmds[fbi->n_smart_cmds++] = SMART_CMD_INTERRUPT;
  601. fbi->smart_cmds[fbi->n_smart_cmds++] = SMART_CMD_WAIT_FOR_VSYNC;
  602. setup_smart_dma(fbi);
  603. /* continue to execute next command */
  604. prsr = lcd_readl(fbi, PRSR) | PRSR_ST_OK | PRSR_CON_NT;
  605. lcd_writel(fbi, PRSR, prsr);
  606. /* stop the processor in case it executed "wait for sync" cmd */
  607. lcd_writel(fbi, CMDCR, 0x0001);
  608. /* don't send interrupts for fifo underruns on channel 6 */
  609. lcd_writel(fbi, LCCR5, LCCR5_IUM(6));
  610. lcd_writel(fbi, LCCR1, fbi->reg_lccr1);
  611. lcd_writel(fbi, LCCR2, fbi->reg_lccr2);
  612. lcd_writel(fbi, LCCR3, fbi->reg_lccr3);
  613. lcd_writel(fbi, FDADR0, fbi->fdadr[0]);
  614. lcd_writel(fbi, FDADR6, fbi->fdadr[6]);
  615. /* begin sending */
  616. lcd_writel(fbi, LCCR0, fbi->reg_lccr0 | LCCR0_ENB);
  617. if (wait_for_completion_timeout(&fbi->command_done, HZ/2) == 0) {
  618. pr_warning("%s: timeout waiting for command done\n",
  619. __func__);
  620. ret = -ETIMEDOUT;
  621. }
  622. /* quick disable */
  623. prsr = lcd_readl(fbi, PRSR) & ~(PRSR_ST_OK | PRSR_CON_NT);
  624. lcd_writel(fbi, PRSR, prsr);
  625. lcd_writel(fbi, LCCR0, fbi->reg_lccr0 & ~LCCR0_ENB);
  626. lcd_writel(fbi, FDADR6, 0);
  627. fbi->n_smart_cmds = 0;
  628. return ret;
  629. }
  630. int pxafb_smart_queue(struct fb_info *info, uint16_t *cmds, int n_cmds)
  631. {
  632. int i;
  633. struct pxafb_info *fbi = container_of(info, struct pxafb_info, fb);
  634. /* leave 2 commands for INTERRUPT and WAIT_FOR_SYNC */
  635. for (i = 0; i < n_cmds; i++) {
  636. if (fbi->n_smart_cmds == CMD_BUFF_SIZE - 8)
  637. pxafb_smart_flush(info);
  638. fbi->smart_cmds[fbi->n_smart_cmds++] = *cmds++;
  639. }
  640. return 0;
  641. }
  642. static unsigned int __smart_timing(unsigned time_ns, unsigned long lcd_clk)
  643. {
  644. unsigned int t = (time_ns * (lcd_clk / 1000000) / 1000);
  645. return (t == 0) ? 1 : t;
  646. }
  647. static void setup_smart_timing(struct pxafb_info *fbi,
  648. struct fb_var_screeninfo *var)
  649. {
  650. struct pxafb_mach_info *inf = fbi->dev->platform_data;
  651. struct pxafb_mode_info *mode = &inf->modes[0];
  652. unsigned long lclk = clk_get_rate(fbi->clk);
  653. unsigned t1, t2, t3, t4;
  654. t1 = max(mode->a0csrd_set_hld, mode->a0cswr_set_hld);
  655. t2 = max(mode->rd_pulse_width, mode->wr_pulse_width);
  656. t3 = mode->op_hold_time;
  657. t4 = mode->cmd_inh_time;
  658. fbi->reg_lccr1 =
  659. LCCR1_DisWdth(var->xres) |
  660. LCCR1_BegLnDel(__smart_timing(t1, lclk)) |
  661. LCCR1_EndLnDel(__smart_timing(t2, lclk)) |
  662. LCCR1_HorSnchWdth(__smart_timing(t3, lclk));
  663. fbi->reg_lccr2 = LCCR2_DisHght(var->yres);
  664. fbi->reg_lccr3 = LCCR3_PixClkDiv(__smart_timing(t4, lclk));
  665. /* FIXME: make this configurable */
  666. fbi->reg_cmdcr = 1;
  667. }
  668. static int pxafb_smart_thread(void *arg)
  669. {
  670. struct pxafb_info *fbi = arg;
  671. struct pxafb_mach_info *inf = fbi->dev->platform_data;
  672. if (!fbi || !inf->smart_update) {
  673. pr_err("%s: not properly initialized, thread terminated\n",
  674. __func__);
  675. return -EINVAL;
  676. }
  677. pr_debug("%s(): task starting\n", __func__);
  678. set_freezable();
  679. while (!kthread_should_stop()) {
  680. if (try_to_freeze())
  681. continue;
  682. if (fbi->state == C_ENABLE) {
  683. inf->smart_update(&fbi->fb);
  684. complete(&fbi->refresh_done);
  685. }
  686. set_current_state(TASK_INTERRUPTIBLE);
  687. schedule_timeout(30 * HZ / 1000);
  688. }
  689. pr_debug("%s(): task ending\n", __func__);
  690. return 0;
  691. }
  692. static int pxafb_smart_init(struct pxafb_info *fbi)
  693. {
  694. fbi->smart_thread = kthread_run(pxafb_smart_thread, fbi,
  695. "lcd_refresh");
  696. if (IS_ERR(fbi->smart_thread)) {
  697. printk(KERN_ERR "%s: unable to create kernel thread\n",
  698. __func__);
  699. return PTR_ERR(fbi->smart_thread);
  700. }
  701. return 0;
  702. }
  703. #else
  704. int pxafb_smart_queue(struct fb_info *info, uint16_t *cmds, int n_cmds)
  705. {
  706. return 0;
  707. }
  708. int pxafb_smart_flush(struct fb_info *info)
  709. {
  710. return 0;
  711. }
  712. #endif /* CONFIG_FB_SMART_PANEL */
  713. static void setup_parallel_timing(struct pxafb_info *fbi,
  714. struct fb_var_screeninfo *var)
  715. {
  716. unsigned int lines_per_panel, pcd = get_pcd(fbi, var->pixclock);
  717. fbi->reg_lccr1 =
  718. LCCR1_DisWdth(var->xres) +
  719. LCCR1_HorSnchWdth(var->hsync_len) +
  720. LCCR1_BegLnDel(var->left_margin) +
  721. LCCR1_EndLnDel(var->right_margin);
  722. /*
  723. * If we have a dual scan LCD, we need to halve
  724. * the YRES parameter.
  725. */
  726. lines_per_panel = var->yres;
  727. if ((fbi->lccr0 & LCCR0_SDS) == LCCR0_Dual)
  728. lines_per_panel /= 2;
  729. fbi->reg_lccr2 =
  730. LCCR2_DisHght(lines_per_panel) +
  731. LCCR2_VrtSnchWdth(var->vsync_len) +
  732. LCCR2_BegFrmDel(var->upper_margin) +
  733. LCCR2_EndFrmDel(var->lower_margin);
  734. fbi->reg_lccr3 = fbi->lccr3 |
  735. (var->sync & FB_SYNC_HOR_HIGH_ACT ?
  736. LCCR3_HorSnchH : LCCR3_HorSnchL) |
  737. (var->sync & FB_SYNC_VERT_HIGH_ACT ?
  738. LCCR3_VrtSnchH : LCCR3_VrtSnchL);
  739. if (pcd) {
  740. fbi->reg_lccr3 |= LCCR3_PixClkDiv(pcd);
  741. set_hsync_time(fbi, pcd);
  742. }
  743. }
  744. /*
  745. * pxafb_activate_var():
  746. * Configures LCD Controller based on entries in var parameter.
  747. * Settings are only written to the controller if changes were made.
  748. */
  749. static int pxafb_activate_var(struct fb_var_screeninfo *var,
  750. struct pxafb_info *fbi)
  751. {
  752. u_long flags;
  753. size_t nbytes;
  754. #if DEBUG_VAR
  755. if (!(fbi->lccr0 & LCCR0_LCDT)) {
  756. if (var->xres < 16 || var->xres > 1024)
  757. printk(KERN_ERR "%s: invalid xres %d\n",
  758. fbi->fb.fix.id, var->xres);
  759. switch (var->bits_per_pixel) {
  760. case 1:
  761. case 2:
  762. case 4:
  763. case 8:
  764. case 16:
  765. case 24:
  766. case 32:
  767. break;
  768. default:
  769. printk(KERN_ERR "%s: invalid bit depth %d\n",
  770. fbi->fb.fix.id, var->bits_per_pixel);
  771. break;
  772. }
  773. if (var->hsync_len < 1 || var->hsync_len > 64)
  774. printk(KERN_ERR "%s: invalid hsync_len %d\n",
  775. fbi->fb.fix.id, var->hsync_len);
  776. if (var->left_margin < 1 || var->left_margin > 255)
  777. printk(KERN_ERR "%s: invalid left_margin %d\n",
  778. fbi->fb.fix.id, var->left_margin);
  779. if (var->right_margin < 1 || var->right_margin > 255)
  780. printk(KERN_ERR "%s: invalid right_margin %d\n",
  781. fbi->fb.fix.id, var->right_margin);
  782. if (var->yres < 1 || var->yres > 1024)
  783. printk(KERN_ERR "%s: invalid yres %d\n",
  784. fbi->fb.fix.id, var->yres);
  785. if (var->vsync_len < 1 || var->vsync_len > 64)
  786. printk(KERN_ERR "%s: invalid vsync_len %d\n",
  787. fbi->fb.fix.id, var->vsync_len);
  788. if (var->upper_margin < 0 || var->upper_margin > 255)
  789. printk(KERN_ERR "%s: invalid upper_margin %d\n",
  790. fbi->fb.fix.id, var->upper_margin);
  791. if (var->lower_margin < 0 || var->lower_margin > 255)
  792. printk(KERN_ERR "%s: invalid lower_margin %d\n",
  793. fbi->fb.fix.id, var->lower_margin);
  794. }
  795. #endif
  796. /* Update shadow copy atomically */
  797. local_irq_save(flags);
  798. #ifdef CONFIG_FB_PXA_SMARTPANEL
  799. if (fbi->lccr0 & LCCR0_LCDT)
  800. setup_smart_timing(fbi, var);
  801. else
  802. #endif
  803. setup_parallel_timing(fbi, var);
  804. fbi->reg_lccr0 = fbi->lccr0 |
  805. (LCCR0_LDM | LCCR0_SFM | LCCR0_IUM | LCCR0_EFM |
  806. LCCR0_QDM | LCCR0_BM | LCCR0_OUM);
  807. fbi->reg_lccr3 |= pxafb_bpp_to_lccr3(var);
  808. nbytes = var->yres * fbi->fb.fix.line_length;
  809. if ((fbi->lccr0 & LCCR0_SDS) == LCCR0_Dual) {
  810. nbytes = nbytes / 2;
  811. setup_frame_dma(fbi, DMA_LOWER, PAL_NONE, nbytes, nbytes);
  812. }
  813. if ((var->bits_per_pixel >= 16) || (fbi->lccr0 & LCCR0_LCDT))
  814. setup_frame_dma(fbi, DMA_BASE, PAL_NONE, 0, nbytes);
  815. else
  816. setup_frame_dma(fbi, DMA_BASE, PAL_BASE, 0, nbytes);
  817. fbi->reg_lccr4 = lcd_readl(fbi, LCCR4) & ~LCCR4_PAL_FOR_MASK;
  818. fbi->reg_lccr4 |= (fbi->lccr4 & LCCR4_PAL_FOR_MASK);
  819. local_irq_restore(flags);
  820. /*
  821. * Only update the registers if the controller is enabled
  822. * and something has changed.
  823. */
  824. if ((lcd_readl(fbi, LCCR0) != fbi->reg_lccr0) ||
  825. (lcd_readl(fbi, LCCR1) != fbi->reg_lccr1) ||
  826. (lcd_readl(fbi, LCCR2) != fbi->reg_lccr2) ||
  827. (lcd_readl(fbi, LCCR3) != fbi->reg_lccr3) ||
  828. (lcd_readl(fbi, FDADR0) != fbi->fdadr[0]) ||
  829. (lcd_readl(fbi, FDADR1) != fbi->fdadr[1]))
  830. pxafb_schedule_work(fbi, C_REENABLE);
  831. return 0;
  832. }
  833. /*
  834. * NOTE! The following functions are purely helpers for set_ctrlr_state.
  835. * Do not call them directly; set_ctrlr_state does the correct serialisation
  836. * to ensure that things happen in the right way 100% of time time.
  837. * -- rmk
  838. */
  839. static inline void __pxafb_backlight_power(struct pxafb_info *fbi, int on)
  840. {
  841. pr_debug("pxafb: backlight o%s\n", on ? "n" : "ff");
  842. if (pxafb_backlight_power)
  843. pxafb_backlight_power(on);
  844. }
  845. static inline void __pxafb_lcd_power(struct pxafb_info *fbi, int on)
  846. {
  847. pr_debug("pxafb: LCD power o%s\n", on ? "n" : "ff");
  848. if (pxafb_lcd_power)
  849. pxafb_lcd_power(on, &fbi->fb.var);
  850. }
  851. static void pxafb_setup_gpio(struct pxafb_info *fbi)
  852. {
  853. int gpio, ldd_bits;
  854. unsigned int lccr0 = fbi->lccr0;
  855. /*
  856. * setup is based on type of panel supported
  857. */
  858. /* 4 bit interface */
  859. if ((lccr0 & LCCR0_CMS) == LCCR0_Mono &&
  860. (lccr0 & LCCR0_SDS) == LCCR0_Sngl &&
  861. (lccr0 & LCCR0_DPD) == LCCR0_4PixMono)
  862. ldd_bits = 4;
  863. /* 8 bit interface */
  864. else if (((lccr0 & LCCR0_CMS) == LCCR0_Mono &&
  865. ((lccr0 & LCCR0_SDS) == LCCR0_Dual ||
  866. (lccr0 & LCCR0_DPD) == LCCR0_8PixMono)) ||
  867. ((lccr0 & LCCR0_CMS) == LCCR0_Color &&
  868. (lccr0 & LCCR0_PAS) == LCCR0_Pas &&
  869. (lccr0 & LCCR0_SDS) == LCCR0_Sngl))
  870. ldd_bits = 8;
  871. /* 16 bit interface */
  872. else if ((lccr0 & LCCR0_CMS) == LCCR0_Color &&
  873. ((lccr0 & LCCR0_SDS) == LCCR0_Dual ||
  874. (lccr0 & LCCR0_PAS) == LCCR0_Act))
  875. ldd_bits = 16;
  876. else {
  877. printk(KERN_ERR "pxafb_setup_gpio: unable to determine "
  878. "bits per pixel\n");
  879. return;
  880. }
  881. for (gpio = 58; ldd_bits; gpio++, ldd_bits--)
  882. pxa_gpio_mode(gpio | GPIO_ALT_FN_2_OUT);
  883. /* 18 bit interface */
  884. if (fbi->fb.var.bits_per_pixel > 16) {
  885. pxa_gpio_mode(86 | GPIO_ALT_FN_2_OUT);
  886. pxa_gpio_mode(87 | GPIO_ALT_FN_2_OUT);
  887. }
  888. pxa_gpio_mode(GPIO74_LCD_FCLK_MD);
  889. pxa_gpio_mode(GPIO75_LCD_LCLK_MD);
  890. pxa_gpio_mode(GPIO76_LCD_PCLK_MD);
  891. pxa_gpio_mode(GPIO77_LCD_ACBIAS_MD);
  892. }
  893. static void pxafb_enable_controller(struct pxafb_info *fbi)
  894. {
  895. pr_debug("pxafb: Enabling LCD controller\n");
  896. pr_debug("fdadr0 0x%08x\n", (unsigned int) fbi->fdadr[0]);
  897. pr_debug("fdadr1 0x%08x\n", (unsigned int) fbi->fdadr[1]);
  898. pr_debug("reg_lccr0 0x%08x\n", (unsigned int) fbi->reg_lccr0);
  899. pr_debug("reg_lccr1 0x%08x\n", (unsigned int) fbi->reg_lccr1);
  900. pr_debug("reg_lccr2 0x%08x\n", (unsigned int) fbi->reg_lccr2);
  901. pr_debug("reg_lccr3 0x%08x\n", (unsigned int) fbi->reg_lccr3);
  902. /* enable LCD controller clock */
  903. clk_enable(fbi->clk);
  904. if (fbi->lccr0 & LCCR0_LCDT)
  905. return;
  906. /* Sequence from 11.7.10 */
  907. lcd_writel(fbi, LCCR3, fbi->reg_lccr3);
  908. lcd_writel(fbi, LCCR2, fbi->reg_lccr2);
  909. lcd_writel(fbi, LCCR1, fbi->reg_lccr1);
  910. lcd_writel(fbi, LCCR0, fbi->reg_lccr0 & ~LCCR0_ENB);
  911. lcd_writel(fbi, FDADR0, fbi->fdadr[0]);
  912. lcd_writel(fbi, FDADR1, fbi->fdadr[1]);
  913. lcd_writel(fbi, LCCR0, fbi->reg_lccr0 | LCCR0_ENB);
  914. }
  915. static void pxafb_disable_controller(struct pxafb_info *fbi)
  916. {
  917. uint32_t lccr0;
  918. #ifdef CONFIG_FB_PXA_SMARTPANEL
  919. if (fbi->lccr0 & LCCR0_LCDT) {
  920. wait_for_completion_timeout(&fbi->refresh_done,
  921. 200 * HZ / 1000);
  922. return;
  923. }
  924. #endif
  925. /* Clear LCD Status Register */
  926. lcd_writel(fbi, LCSR, 0xffffffff);
  927. lccr0 = lcd_readl(fbi, LCCR0) & ~LCCR0_LDM;
  928. lcd_writel(fbi, LCCR0, lccr0);
  929. lcd_writel(fbi, LCCR0, lccr0 | LCCR0_DIS);
  930. wait_for_completion_timeout(&fbi->disable_done, 200 * HZ / 1000);
  931. /* disable LCD controller clock */
  932. clk_disable(fbi->clk);
  933. }
  934. /*
  935. * pxafb_handle_irq: Handle 'LCD DONE' interrupts.
  936. */
  937. static irqreturn_t pxafb_handle_irq(int irq, void *dev_id)
  938. {
  939. struct pxafb_info *fbi = dev_id;
  940. unsigned int lccr0, lcsr = lcd_readl(fbi, LCSR);
  941. if (lcsr & LCSR_LDD) {
  942. lccr0 = lcd_readl(fbi, LCCR0);
  943. lcd_writel(fbi, LCCR0, lccr0 | LCCR0_LDM);
  944. complete(&fbi->disable_done);
  945. }
  946. #ifdef CONFIG_FB_PXA_SMARTPANEL
  947. if (lcsr & LCSR_CMD_INT)
  948. complete(&fbi->command_done);
  949. #endif
  950. lcd_writel(fbi, LCSR, lcsr);
  951. return IRQ_HANDLED;
  952. }
  953. /*
  954. * This function must be called from task context only, since it will
  955. * sleep when disabling the LCD controller, or if we get two contending
  956. * processes trying to alter state.
  957. */
  958. static void set_ctrlr_state(struct pxafb_info *fbi, u_int state)
  959. {
  960. u_int old_state;
  961. mutex_lock(&fbi->ctrlr_lock);
  962. old_state = fbi->state;
  963. /*
  964. * Hack around fbcon initialisation.
  965. */
  966. if (old_state == C_STARTUP && state == C_REENABLE)
  967. state = C_ENABLE;
  968. switch (state) {
  969. case C_DISABLE_CLKCHANGE:
  970. /*
  971. * Disable controller for clock change. If the
  972. * controller is already disabled, then do nothing.
  973. */
  974. if (old_state != C_DISABLE && old_state != C_DISABLE_PM) {
  975. fbi->state = state;
  976. /* TODO __pxafb_lcd_power(fbi, 0); */
  977. pxafb_disable_controller(fbi);
  978. }
  979. break;
  980. case C_DISABLE_PM:
  981. case C_DISABLE:
  982. /*
  983. * Disable controller
  984. */
  985. if (old_state != C_DISABLE) {
  986. fbi->state = state;
  987. __pxafb_backlight_power(fbi, 0);
  988. __pxafb_lcd_power(fbi, 0);
  989. if (old_state != C_DISABLE_CLKCHANGE)
  990. pxafb_disable_controller(fbi);
  991. }
  992. break;
  993. case C_ENABLE_CLKCHANGE:
  994. /*
  995. * Enable the controller after clock change. Only
  996. * do this if we were disabled for the clock change.
  997. */
  998. if (old_state == C_DISABLE_CLKCHANGE) {
  999. fbi->state = C_ENABLE;
  1000. pxafb_enable_controller(fbi);
  1001. /* TODO __pxafb_lcd_power(fbi, 1); */
  1002. }
  1003. break;
  1004. case C_REENABLE:
  1005. /*
  1006. * Re-enable the controller only if it was already
  1007. * enabled. This is so we reprogram the control
  1008. * registers.
  1009. */
  1010. if (old_state == C_ENABLE) {
  1011. __pxafb_lcd_power(fbi, 0);
  1012. pxafb_disable_controller(fbi);
  1013. pxafb_setup_gpio(fbi);
  1014. pxafb_enable_controller(fbi);
  1015. __pxafb_lcd_power(fbi, 1);
  1016. }
  1017. break;
  1018. case C_ENABLE_PM:
  1019. /*
  1020. * Re-enable the controller after PM. This is not
  1021. * perfect - think about the case where we were doing
  1022. * a clock change, and we suspended half-way through.
  1023. */
  1024. if (old_state != C_DISABLE_PM)
  1025. break;
  1026. /* fall through */
  1027. case C_ENABLE:
  1028. /*
  1029. * Power up the LCD screen, enable controller, and
  1030. * turn on the backlight.
  1031. */
  1032. if (old_state != C_ENABLE) {
  1033. fbi->state = C_ENABLE;
  1034. pxafb_setup_gpio(fbi);
  1035. pxafb_enable_controller(fbi);
  1036. __pxafb_lcd_power(fbi, 1);
  1037. __pxafb_backlight_power(fbi, 1);
  1038. }
  1039. break;
  1040. }
  1041. mutex_unlock(&fbi->ctrlr_lock);
  1042. }
  1043. /*
  1044. * Our LCD controller task (which is called when we blank or unblank)
  1045. * via keventd.
  1046. */
  1047. static void pxafb_task(struct work_struct *work)
  1048. {
  1049. struct pxafb_info *fbi =
  1050. container_of(work, struct pxafb_info, task);
  1051. u_int state = xchg(&fbi->task_state, -1);
  1052. set_ctrlr_state(fbi, state);
  1053. }
  1054. #ifdef CONFIG_CPU_FREQ
  1055. /*
  1056. * CPU clock speed change handler. We need to adjust the LCD timing
  1057. * parameters when the CPU clock is adjusted by the power management
  1058. * subsystem.
  1059. *
  1060. * TODO: Determine why f->new != 10*get_lclk_frequency_10khz()
  1061. */
  1062. static int
  1063. pxafb_freq_transition(struct notifier_block *nb, unsigned long val, void *data)
  1064. {
  1065. struct pxafb_info *fbi = TO_INF(nb, freq_transition);
  1066. /* TODO struct cpufreq_freqs *f = data; */
  1067. u_int pcd;
  1068. switch (val) {
  1069. case CPUFREQ_PRECHANGE:
  1070. set_ctrlr_state(fbi, C_DISABLE_CLKCHANGE);
  1071. break;
  1072. case CPUFREQ_POSTCHANGE:
  1073. pcd = get_pcd(fbi, fbi->fb.var.pixclock);
  1074. set_hsync_time(fbi, pcd);
  1075. fbi->reg_lccr3 = (fbi->reg_lccr3 & ~0xff) |
  1076. LCCR3_PixClkDiv(pcd);
  1077. set_ctrlr_state(fbi, C_ENABLE_CLKCHANGE);
  1078. break;
  1079. }
  1080. return 0;
  1081. }
  1082. static int
  1083. pxafb_freq_policy(struct notifier_block *nb, unsigned long val, void *data)
  1084. {
  1085. struct pxafb_info *fbi = TO_INF(nb, freq_policy);
  1086. struct fb_var_screeninfo *var = &fbi->fb.var;
  1087. struct cpufreq_policy *policy = data;
  1088. switch (val) {
  1089. case CPUFREQ_ADJUST:
  1090. case CPUFREQ_INCOMPATIBLE:
  1091. pr_debug("min dma period: %d ps, "
  1092. "new clock %d kHz\n", pxafb_display_dma_period(var),
  1093. policy->max);
  1094. /* TODO: fill in min/max values */
  1095. break;
  1096. }
  1097. return 0;
  1098. }
  1099. #endif
  1100. #ifdef CONFIG_PM
  1101. /*
  1102. * Power management hooks. Note that we won't be called from IRQ context,
  1103. * unlike the blank functions above, so we may sleep.
  1104. */
  1105. static int pxafb_suspend(struct platform_device *dev, pm_message_t state)
  1106. {
  1107. struct pxafb_info *fbi = platform_get_drvdata(dev);
  1108. set_ctrlr_state(fbi, C_DISABLE_PM);
  1109. return 0;
  1110. }
  1111. static int pxafb_resume(struct platform_device *dev)
  1112. {
  1113. struct pxafb_info *fbi = platform_get_drvdata(dev);
  1114. set_ctrlr_state(fbi, C_ENABLE_PM);
  1115. return 0;
  1116. }
  1117. #else
  1118. #define pxafb_suspend NULL
  1119. #define pxafb_resume NULL
  1120. #endif
  1121. /*
  1122. * pxafb_map_video_memory():
  1123. * Allocates the DRAM memory for the frame buffer. This buffer is
  1124. * remapped into a non-cached, non-buffered, memory region to
  1125. * allow palette and pixel writes to occur without flushing the
  1126. * cache. Once this area is remapped, all virtual memory
  1127. * access to the video memory should occur at the new region.
  1128. */
  1129. static int __devinit pxafb_map_video_memory(struct pxafb_info *fbi)
  1130. {
  1131. /*
  1132. * We reserve one page for the palette, plus the size
  1133. * of the framebuffer.
  1134. */
  1135. fbi->video_offset = PAGE_ALIGN(sizeof(struct pxafb_dma_buff));
  1136. fbi->map_size = PAGE_ALIGN(fbi->fb.fix.smem_len + fbi->video_offset);
  1137. fbi->map_cpu = dma_alloc_writecombine(fbi->dev, fbi->map_size,
  1138. &fbi->map_dma, GFP_KERNEL);
  1139. if (fbi->map_cpu) {
  1140. /* prevent initial garbage on screen */
  1141. memset(fbi->map_cpu, 0, fbi->map_size);
  1142. fbi->fb.screen_base = fbi->map_cpu + fbi->video_offset;
  1143. fbi->screen_dma = fbi->map_dma + fbi->video_offset;
  1144. /*
  1145. * FIXME: this is actually the wrong thing to place in
  1146. * smem_start. But fbdev suffers from the problem that
  1147. * it needs an API which doesn't exist (in this case,
  1148. * dma_writecombine_mmap)
  1149. */
  1150. fbi->fb.fix.smem_start = fbi->screen_dma;
  1151. fbi->palette_size = fbi->fb.var.bits_per_pixel == 8 ? 256 : 16;
  1152. fbi->dma_buff = (void *) fbi->map_cpu;
  1153. fbi->dma_buff_phys = fbi->map_dma;
  1154. fbi->palette_cpu = (u16 *) fbi->dma_buff->palette;
  1155. pr_debug("pxafb: palette_mem_size = 0x%08x\n", fbi->palette_size*sizeof(u16));
  1156. #ifdef CONFIG_FB_PXA_SMARTPANEL
  1157. fbi->smart_cmds = (uint16_t *) fbi->dma_buff->cmd_buff;
  1158. fbi->n_smart_cmds = 0;
  1159. #endif
  1160. }
  1161. return fbi->map_cpu ? 0 : -ENOMEM;
  1162. }
  1163. static void pxafb_decode_mode_info(struct pxafb_info *fbi,
  1164. struct pxafb_mode_info *modes,
  1165. unsigned int num_modes)
  1166. {
  1167. unsigned int i, smemlen;
  1168. pxafb_setmode(&fbi->fb.var, &modes[0]);
  1169. for (i = 0; i < num_modes; i++) {
  1170. smemlen = modes[i].xres * modes[i].yres * modes[i].bpp / 8;
  1171. if (smemlen > fbi->fb.fix.smem_len)
  1172. fbi->fb.fix.smem_len = smemlen;
  1173. }
  1174. }
  1175. static void pxafb_decode_mach_info(struct pxafb_info *fbi,
  1176. struct pxafb_mach_info *inf)
  1177. {
  1178. unsigned int lcd_conn = inf->lcd_conn;
  1179. fbi->cmap_inverse = inf->cmap_inverse;
  1180. fbi->cmap_static = inf->cmap_static;
  1181. switch (lcd_conn & 0xf) {
  1182. case LCD_TYPE_MONO_STN:
  1183. fbi->lccr0 = LCCR0_CMS;
  1184. break;
  1185. case LCD_TYPE_MONO_DSTN:
  1186. fbi->lccr0 = LCCR0_CMS | LCCR0_SDS;
  1187. break;
  1188. case LCD_TYPE_COLOR_STN:
  1189. fbi->lccr0 = 0;
  1190. break;
  1191. case LCD_TYPE_COLOR_DSTN:
  1192. fbi->lccr0 = LCCR0_SDS;
  1193. break;
  1194. case LCD_TYPE_COLOR_TFT:
  1195. fbi->lccr0 = LCCR0_PAS;
  1196. break;
  1197. case LCD_TYPE_SMART_PANEL:
  1198. fbi->lccr0 = LCCR0_LCDT | LCCR0_PAS;
  1199. break;
  1200. default:
  1201. /* fall back to backward compatibility way */
  1202. fbi->lccr0 = inf->lccr0;
  1203. fbi->lccr3 = inf->lccr3;
  1204. fbi->lccr4 = inf->lccr4;
  1205. goto decode_mode;
  1206. }
  1207. if (lcd_conn == LCD_MONO_STN_8BPP)
  1208. fbi->lccr0 |= LCCR0_DPD;
  1209. fbi->lccr3 = LCCR3_Acb((inf->lcd_conn >> 10) & 0xff);
  1210. fbi->lccr3 |= (lcd_conn & LCD_BIAS_ACTIVE_LOW) ? LCCR3_OEP : 0;
  1211. fbi->lccr3 |= (lcd_conn & LCD_PCLK_EDGE_FALL) ? LCCR3_PCP : 0;
  1212. decode_mode:
  1213. pxafb_decode_mode_info(fbi, inf->modes, inf->num_modes);
  1214. }
  1215. static struct pxafb_info * __devinit pxafb_init_fbinfo(struct device *dev)
  1216. {
  1217. struct pxafb_info *fbi;
  1218. void *addr;
  1219. struct pxafb_mach_info *inf = dev->platform_data;
  1220. /* Alloc the pxafb_info and pseudo_palette in one step */
  1221. fbi = kmalloc(sizeof(struct pxafb_info) + sizeof(u32) * 16, GFP_KERNEL);
  1222. if (!fbi)
  1223. return NULL;
  1224. memset(fbi, 0, sizeof(struct pxafb_info));
  1225. fbi->dev = dev;
  1226. fbi->clk = clk_get(dev, "LCDCLK");
  1227. if (IS_ERR(fbi->clk)) {
  1228. kfree(fbi);
  1229. return NULL;
  1230. }
  1231. strcpy(fbi->fb.fix.id, PXA_NAME);
  1232. fbi->fb.fix.type = FB_TYPE_PACKED_PIXELS;
  1233. fbi->fb.fix.type_aux = 0;
  1234. fbi->fb.fix.xpanstep = 0;
  1235. fbi->fb.fix.ypanstep = 0;
  1236. fbi->fb.fix.ywrapstep = 0;
  1237. fbi->fb.fix.accel = FB_ACCEL_NONE;
  1238. fbi->fb.var.nonstd = 0;
  1239. fbi->fb.var.activate = FB_ACTIVATE_NOW;
  1240. fbi->fb.var.height = -1;
  1241. fbi->fb.var.width = -1;
  1242. fbi->fb.var.accel_flags = 0;
  1243. fbi->fb.var.vmode = FB_VMODE_NONINTERLACED;
  1244. fbi->fb.fbops = &pxafb_ops;
  1245. fbi->fb.flags = FBINFO_DEFAULT;
  1246. fbi->fb.node = -1;
  1247. addr = fbi;
  1248. addr = addr + sizeof(struct pxafb_info);
  1249. fbi->fb.pseudo_palette = addr;
  1250. fbi->state = C_STARTUP;
  1251. fbi->task_state = (u_char)-1;
  1252. pxafb_decode_mach_info(fbi, inf);
  1253. init_waitqueue_head(&fbi->ctrlr_wait);
  1254. INIT_WORK(&fbi->task, pxafb_task);
  1255. mutex_init(&fbi->ctrlr_lock);
  1256. init_completion(&fbi->disable_done);
  1257. #ifdef CONFIG_FB_PXA_SMARTPANEL
  1258. init_completion(&fbi->command_done);
  1259. init_completion(&fbi->refresh_done);
  1260. #endif
  1261. return fbi;
  1262. }
  1263. #ifdef CONFIG_FB_PXA_PARAMETERS
  1264. static int __devinit parse_opt_mode(struct device *dev, const char *this_opt)
  1265. {
  1266. struct pxafb_mach_info *inf = dev->platform_data;
  1267. const char *name = this_opt+5;
  1268. unsigned int namelen = strlen(name);
  1269. int res_specified = 0, bpp_specified = 0;
  1270. unsigned int xres = 0, yres = 0, bpp = 0;
  1271. int yres_specified = 0;
  1272. int i;
  1273. for (i = namelen-1; i >= 0; i--) {
  1274. switch (name[i]) {
  1275. case '-':
  1276. namelen = i;
  1277. if (!bpp_specified && !yres_specified) {
  1278. bpp = simple_strtoul(&name[i+1], NULL, 0);
  1279. bpp_specified = 1;
  1280. } else
  1281. goto done;
  1282. break;
  1283. case 'x':
  1284. if (!yres_specified) {
  1285. yres = simple_strtoul(&name[i+1], NULL, 0);
  1286. yres_specified = 1;
  1287. } else
  1288. goto done;
  1289. break;
  1290. case '0' ... '9':
  1291. break;
  1292. default:
  1293. goto done;
  1294. }
  1295. }
  1296. if (i < 0 && yres_specified) {
  1297. xres = simple_strtoul(name, NULL, 0);
  1298. res_specified = 1;
  1299. }
  1300. done:
  1301. if (res_specified) {
  1302. dev_info(dev, "overriding resolution: %dx%d\n", xres, yres);
  1303. inf->modes[0].xres = xres; inf->modes[0].yres = yres;
  1304. }
  1305. if (bpp_specified)
  1306. switch (bpp) {
  1307. case 1:
  1308. case 2:
  1309. case 4:
  1310. case 8:
  1311. case 16:
  1312. inf->modes[0].bpp = bpp;
  1313. dev_info(dev, "overriding bit depth: %d\n", bpp);
  1314. break;
  1315. default:
  1316. dev_err(dev, "Depth %d is not valid\n", bpp);
  1317. return -EINVAL;
  1318. }
  1319. return 0;
  1320. }
  1321. static int __devinit parse_opt(struct device *dev, char *this_opt)
  1322. {
  1323. struct pxafb_mach_info *inf = dev->platform_data;
  1324. struct pxafb_mode_info *mode = &inf->modes[0];
  1325. char s[64];
  1326. s[0] = '\0';
  1327. if (!strncmp(this_opt, "mode:", 5)) {
  1328. return parse_opt_mode(dev, this_opt);
  1329. } else if (!strncmp(this_opt, "pixclock:", 9)) {
  1330. mode->pixclock = simple_strtoul(this_opt+9, NULL, 0);
  1331. sprintf(s, "pixclock: %ld\n", mode->pixclock);
  1332. } else if (!strncmp(this_opt, "left:", 5)) {
  1333. mode->left_margin = simple_strtoul(this_opt+5, NULL, 0);
  1334. sprintf(s, "left: %u\n", mode->left_margin);
  1335. } else if (!strncmp(this_opt, "right:", 6)) {
  1336. mode->right_margin = simple_strtoul(this_opt+6, NULL, 0);
  1337. sprintf(s, "right: %u\n", mode->right_margin);
  1338. } else if (!strncmp(this_opt, "upper:", 6)) {
  1339. mode->upper_margin = simple_strtoul(this_opt+6, NULL, 0);
  1340. sprintf(s, "upper: %u\n", mode->upper_margin);
  1341. } else if (!strncmp(this_opt, "lower:", 6)) {
  1342. mode->lower_margin = simple_strtoul(this_opt+6, NULL, 0);
  1343. sprintf(s, "lower: %u\n", mode->lower_margin);
  1344. } else if (!strncmp(this_opt, "hsynclen:", 9)) {
  1345. mode->hsync_len = simple_strtoul(this_opt+9, NULL, 0);
  1346. sprintf(s, "hsynclen: %u\n", mode->hsync_len);
  1347. } else if (!strncmp(this_opt, "vsynclen:", 9)) {
  1348. mode->vsync_len = simple_strtoul(this_opt+9, NULL, 0);
  1349. sprintf(s, "vsynclen: %u\n", mode->vsync_len);
  1350. } else if (!strncmp(this_opt, "hsync:", 6)) {
  1351. if (simple_strtoul(this_opt+6, NULL, 0) == 0) {
  1352. sprintf(s, "hsync: Active Low\n");
  1353. mode->sync &= ~FB_SYNC_HOR_HIGH_ACT;
  1354. } else {
  1355. sprintf(s, "hsync: Active High\n");
  1356. mode->sync |= FB_SYNC_HOR_HIGH_ACT;
  1357. }
  1358. } else if (!strncmp(this_opt, "vsync:", 6)) {
  1359. if (simple_strtoul(this_opt+6, NULL, 0) == 0) {
  1360. sprintf(s, "vsync: Active Low\n");
  1361. mode->sync &= ~FB_SYNC_VERT_HIGH_ACT;
  1362. } else {
  1363. sprintf(s, "vsync: Active High\n");
  1364. mode->sync |= FB_SYNC_VERT_HIGH_ACT;
  1365. }
  1366. } else if (!strncmp(this_opt, "dpc:", 4)) {
  1367. if (simple_strtoul(this_opt+4, NULL, 0) == 0) {
  1368. sprintf(s, "double pixel clock: false\n");
  1369. inf->lccr3 &= ~LCCR3_DPC;
  1370. } else {
  1371. sprintf(s, "double pixel clock: true\n");
  1372. inf->lccr3 |= LCCR3_DPC;
  1373. }
  1374. } else if (!strncmp(this_opt, "outputen:", 9)) {
  1375. if (simple_strtoul(this_opt+9, NULL, 0) == 0) {
  1376. sprintf(s, "output enable: active low\n");
  1377. inf->lccr3 = (inf->lccr3 & ~LCCR3_OEP) | LCCR3_OutEnL;
  1378. } else {
  1379. sprintf(s, "output enable: active high\n");
  1380. inf->lccr3 = (inf->lccr3 & ~LCCR3_OEP) | LCCR3_OutEnH;
  1381. }
  1382. } else if (!strncmp(this_opt, "pixclockpol:", 12)) {
  1383. if (simple_strtoul(this_opt+12, NULL, 0) == 0) {
  1384. sprintf(s, "pixel clock polarity: falling edge\n");
  1385. inf->lccr3 = (inf->lccr3 & ~LCCR3_PCP) | LCCR3_PixFlEdg;
  1386. } else {
  1387. sprintf(s, "pixel clock polarity: rising edge\n");
  1388. inf->lccr3 = (inf->lccr3 & ~LCCR3_PCP) | LCCR3_PixRsEdg;
  1389. }
  1390. } else if (!strncmp(this_opt, "color", 5)) {
  1391. inf->lccr0 = (inf->lccr0 & ~LCCR0_CMS) | LCCR0_Color;
  1392. } else if (!strncmp(this_opt, "mono", 4)) {
  1393. inf->lccr0 = (inf->lccr0 & ~LCCR0_CMS) | LCCR0_Mono;
  1394. } else if (!strncmp(this_opt, "active", 6)) {
  1395. inf->lccr0 = (inf->lccr0 & ~LCCR0_PAS) | LCCR0_Act;
  1396. } else if (!strncmp(this_opt, "passive", 7)) {
  1397. inf->lccr0 = (inf->lccr0 & ~LCCR0_PAS) | LCCR0_Pas;
  1398. } else if (!strncmp(this_opt, "single", 6)) {
  1399. inf->lccr0 = (inf->lccr0 & ~LCCR0_SDS) | LCCR0_Sngl;
  1400. } else if (!strncmp(this_opt, "dual", 4)) {
  1401. inf->lccr0 = (inf->lccr0 & ~LCCR0_SDS) | LCCR0_Dual;
  1402. } else if (!strncmp(this_opt, "4pix", 4)) {
  1403. inf->lccr0 = (inf->lccr0 & ~LCCR0_DPD) | LCCR0_4PixMono;
  1404. } else if (!strncmp(this_opt, "8pix", 4)) {
  1405. inf->lccr0 = (inf->lccr0 & ~LCCR0_DPD) | LCCR0_8PixMono;
  1406. } else {
  1407. dev_err(dev, "unknown option: %s\n", this_opt);
  1408. return -EINVAL;
  1409. }
  1410. if (s[0] != '\0')
  1411. dev_info(dev, "override %s", s);
  1412. return 0;
  1413. }
  1414. static int __devinit pxafb_parse_options(struct device *dev, char *options)
  1415. {
  1416. char *this_opt;
  1417. int ret;
  1418. if (!options || !*options)
  1419. return 0;
  1420. dev_dbg(dev, "options are \"%s\"\n", options ? options : "null");
  1421. /* could be made table driven or similar?... */
  1422. while ((this_opt = strsep(&options, ",")) != NULL) {
  1423. ret = parse_opt(dev, this_opt);
  1424. if (ret)
  1425. return ret;
  1426. }
  1427. return 0;
  1428. }
  1429. static char g_options[256] __devinitdata = "";
  1430. #ifndef MODULE
  1431. static int __init pxafb_setup_options(void)
  1432. {
  1433. char *options = NULL;
  1434. if (fb_get_options("pxafb", &options))
  1435. return -ENODEV;
  1436. if (options)
  1437. strlcpy(g_options, options, sizeof(g_options));
  1438. return 0;
  1439. }
  1440. #else
  1441. #define pxafb_setup_options() (0)
  1442. module_param_string(options, g_options, sizeof(g_options), 0);
  1443. MODULE_PARM_DESC(options, "LCD parameters (see Documentation/fb/pxafb.txt)");
  1444. #endif
  1445. #else
  1446. #define pxafb_parse_options(...) (0)
  1447. #define pxafb_setup_options() (0)
  1448. #endif
  1449. static int __devinit pxafb_probe(struct platform_device *dev)
  1450. {
  1451. struct pxafb_info *fbi;
  1452. struct pxafb_mach_info *inf;
  1453. struct resource *r;
  1454. int irq, ret;
  1455. dev_dbg(&dev->dev, "pxafb_probe\n");
  1456. inf = dev->dev.platform_data;
  1457. ret = -ENOMEM;
  1458. fbi = NULL;
  1459. if (!inf)
  1460. goto failed;
  1461. ret = pxafb_parse_options(&dev->dev, g_options);
  1462. if (ret < 0)
  1463. goto failed;
  1464. #ifdef DEBUG_VAR
  1465. /* Check for various illegal bit-combinations. Currently only
  1466. * a warning is given. */
  1467. if (inf->lccr0 & LCCR0_INVALID_CONFIG_MASK)
  1468. dev_warn(&dev->dev, "machine LCCR0 setting contains "
  1469. "illegal bits: %08x\n",
  1470. inf->lccr0 & LCCR0_INVALID_CONFIG_MASK);
  1471. if (inf->lccr3 & LCCR3_INVALID_CONFIG_MASK)
  1472. dev_warn(&dev->dev, "machine LCCR3 setting contains "
  1473. "illegal bits: %08x\n",
  1474. inf->lccr3 & LCCR3_INVALID_CONFIG_MASK);
  1475. if (inf->lccr0 & LCCR0_DPD &&
  1476. ((inf->lccr0 & LCCR0_PAS) != LCCR0_Pas ||
  1477. (inf->lccr0 & LCCR0_SDS) != LCCR0_Sngl ||
  1478. (inf->lccr0 & LCCR0_CMS) != LCCR0_Mono))
  1479. dev_warn(&dev->dev, "Double Pixel Data (DPD) mode is "
  1480. "only valid in passive mono"
  1481. " single panel mode\n");
  1482. if ((inf->lccr0 & LCCR0_PAS) == LCCR0_Act &&
  1483. (inf->lccr0 & LCCR0_SDS) == LCCR0_Dual)
  1484. dev_warn(&dev->dev, "Dual panel only valid in passive mode\n");
  1485. if ((inf->lccr0 & LCCR0_PAS) == LCCR0_Pas &&
  1486. (inf->modes->upper_margin || inf->modes->lower_margin))
  1487. dev_warn(&dev->dev, "Upper and lower margins must be 0 in "
  1488. "passive mode\n");
  1489. #endif
  1490. dev_dbg(&dev->dev, "got a %dx%dx%d LCD\n",
  1491. inf->modes->xres,
  1492. inf->modes->yres,
  1493. inf->modes->bpp);
  1494. if (inf->modes->xres == 0 ||
  1495. inf->modes->yres == 0 ||
  1496. inf->modes->bpp == 0) {
  1497. dev_err(&dev->dev, "Invalid resolution or bit depth\n");
  1498. ret = -EINVAL;
  1499. goto failed;
  1500. }
  1501. pxafb_backlight_power = inf->pxafb_backlight_power;
  1502. pxafb_lcd_power = inf->pxafb_lcd_power;
  1503. fbi = pxafb_init_fbinfo(&dev->dev);
  1504. if (!fbi) {
  1505. /* only reason for pxafb_init_fbinfo to fail is kmalloc */
  1506. dev_err(&dev->dev, "Failed to initialize framebuffer device\n");
  1507. ret = -ENOMEM;
  1508. goto failed;
  1509. }
  1510. r = platform_get_resource(dev, IORESOURCE_MEM, 0);
  1511. if (r == NULL) {
  1512. dev_err(&dev->dev, "no I/O memory resource defined\n");
  1513. ret = -ENODEV;
  1514. goto failed_fbi;
  1515. }
  1516. r = request_mem_region(r->start, r->end - r->start + 1, dev->name);
  1517. if (r == NULL) {
  1518. dev_err(&dev->dev, "failed to request I/O memory\n");
  1519. ret = -EBUSY;
  1520. goto failed_fbi;
  1521. }
  1522. fbi->mmio_base = ioremap(r->start, r->end - r->start + 1);
  1523. if (fbi->mmio_base == NULL) {
  1524. dev_err(&dev->dev, "failed to map I/O memory\n");
  1525. ret = -EBUSY;
  1526. goto failed_free_res;
  1527. }
  1528. /* Initialize video memory */
  1529. ret = pxafb_map_video_memory(fbi);
  1530. if (ret) {
  1531. dev_err(&dev->dev, "Failed to allocate video RAM: %d\n", ret);
  1532. ret = -ENOMEM;
  1533. goto failed_free_io;
  1534. }
  1535. irq = platform_get_irq(dev, 0);
  1536. if (irq < 0) {
  1537. dev_err(&dev->dev, "no IRQ defined\n");
  1538. ret = -ENODEV;
  1539. goto failed_free_mem;
  1540. }
  1541. ret = request_irq(irq, pxafb_handle_irq, IRQF_DISABLED, "LCD", fbi);
  1542. if (ret) {
  1543. dev_err(&dev->dev, "request_irq failed: %d\n", ret);
  1544. ret = -EBUSY;
  1545. goto failed_free_mem;
  1546. }
  1547. #ifdef CONFIG_FB_PXA_SMARTPANEL
  1548. ret = pxafb_smart_init(fbi);
  1549. if (ret) {
  1550. dev_err(&dev->dev, "failed to initialize smartpanel\n");
  1551. goto failed_free_irq;
  1552. }
  1553. #endif
  1554. /*
  1555. * This makes sure that our colour bitfield
  1556. * descriptors are correctly initialised.
  1557. */
  1558. ret = pxafb_check_var(&fbi->fb.var, &fbi->fb);
  1559. if (ret) {
  1560. dev_err(&dev->dev, "failed to get suitable mode\n");
  1561. goto failed_free_irq;
  1562. }
  1563. ret = pxafb_set_par(&fbi->fb);
  1564. if (ret) {
  1565. dev_err(&dev->dev, "Failed to set parameters\n");
  1566. goto failed_free_irq;
  1567. }
  1568. platform_set_drvdata(dev, fbi);
  1569. ret = register_framebuffer(&fbi->fb);
  1570. if (ret < 0) {
  1571. dev_err(&dev->dev,
  1572. "Failed to register framebuffer device: %d\n", ret);
  1573. goto failed_free_cmap;
  1574. }
  1575. #ifdef CONFIG_CPU_FREQ
  1576. fbi->freq_transition.notifier_call = pxafb_freq_transition;
  1577. fbi->freq_policy.notifier_call = pxafb_freq_policy;
  1578. cpufreq_register_notifier(&fbi->freq_transition,
  1579. CPUFREQ_TRANSITION_NOTIFIER);
  1580. cpufreq_register_notifier(&fbi->freq_policy,
  1581. CPUFREQ_POLICY_NOTIFIER);
  1582. #endif
  1583. /*
  1584. * Ok, now enable the LCD controller
  1585. */
  1586. set_ctrlr_state(fbi, C_ENABLE);
  1587. return 0;
  1588. failed_free_cmap:
  1589. if (fbi->fb.cmap.len)
  1590. fb_dealloc_cmap(&fbi->fb.cmap);
  1591. failed_free_irq:
  1592. free_irq(irq, fbi);
  1593. failed_free_mem:
  1594. dma_free_writecombine(&dev->dev, fbi->map_size,
  1595. fbi->map_cpu, fbi->map_dma);
  1596. failed_free_io:
  1597. iounmap(fbi->mmio_base);
  1598. failed_free_res:
  1599. release_mem_region(r->start, r->end - r->start + 1);
  1600. failed_fbi:
  1601. clk_put(fbi->clk);
  1602. platform_set_drvdata(dev, NULL);
  1603. kfree(fbi);
  1604. failed:
  1605. return ret;
  1606. }
  1607. static int __devexit pxafb_remove(struct platform_device *dev)
  1608. {
  1609. struct pxafb_info *fbi = platform_get_drvdata(dev);
  1610. struct resource *r;
  1611. int irq;
  1612. struct fb_info *info;
  1613. if (!fbi)
  1614. return 0;
  1615. info = &fbi->fb;
  1616. unregister_framebuffer(info);
  1617. pxafb_disable_controller(fbi);
  1618. if (fbi->fb.cmap.len)
  1619. fb_dealloc_cmap(&fbi->fb.cmap);
  1620. irq = platform_get_irq(dev, 0);
  1621. free_irq(irq, fbi);
  1622. dma_free_writecombine(&dev->dev, fbi->map_size,
  1623. fbi->map_cpu, fbi->map_dma);
  1624. iounmap(fbi->mmio_base);
  1625. r = platform_get_resource(dev, IORESOURCE_MEM, 0);
  1626. release_mem_region(r->start, r->end - r->start + 1);
  1627. clk_put(fbi->clk);
  1628. kfree(fbi);
  1629. return 0;
  1630. }
  1631. static struct platform_driver pxafb_driver = {
  1632. .probe = pxafb_probe,
  1633. .remove = pxafb_remove,
  1634. .suspend = pxafb_suspend,
  1635. .resume = pxafb_resume,
  1636. .driver = {
  1637. .owner = THIS_MODULE,
  1638. .name = "pxa2xx-fb",
  1639. },
  1640. };
  1641. static int __init pxafb_init(void)
  1642. {
  1643. if (pxafb_setup_options())
  1644. return -EINVAL;
  1645. return platform_driver_register(&pxafb_driver);
  1646. }
  1647. static void __exit pxafb_exit(void)
  1648. {
  1649. platform_driver_unregister(&pxafb_driver);
  1650. }
  1651. module_init(pxafb_init);
  1652. module_exit(pxafb_exit);
  1653. MODULE_DESCRIPTION("loadable framebuffer driver for PXA");
  1654. MODULE_LICENSE("GPL");