pxafb.c 61 KB

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