pxafb.c 60 KB

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