pxafb.c 49 KB

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