pxafb.c 50 KB

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