pxafb.c 60 KB

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