pxafb.c 60 KB

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