pxafb.c 60 KB

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