pxafb.c 50 KB

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