pxafb.c 60 KB

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