pxafb.c 49 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882
  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_thread = kthread_run(pxafb_smart_thread, fbi,
  694. "lcd_refresh");
  695. if (IS_ERR(fbi->smart_thread)) {
  696. printk(KERN_ERR "%s: unable to create kernel thread\n",
  697. __func__);
  698. return PTR_ERR(fbi->smart_thread);
  699. }
  700. return 0;
  701. }
  702. #else
  703. int pxafb_smart_queue(struct fb_info *info, uint16_t *cmds, int n_cmds)
  704. {
  705. return 0;
  706. }
  707. int pxafb_smart_flush(struct fb_info *info)
  708. {
  709. return 0;
  710. }
  711. #endif /* CONFIG_FB_SMART_PANEL */
  712. static void setup_parallel_timing(struct pxafb_info *fbi,
  713. struct fb_var_screeninfo *var)
  714. {
  715. unsigned int lines_per_panel, pcd = get_pcd(fbi, var->pixclock);
  716. fbi->reg_lccr1 =
  717. LCCR1_DisWdth(var->xres) +
  718. LCCR1_HorSnchWdth(var->hsync_len) +
  719. LCCR1_BegLnDel(var->left_margin) +
  720. LCCR1_EndLnDel(var->right_margin);
  721. /*
  722. * If we have a dual scan LCD, we need to halve
  723. * the YRES parameter.
  724. */
  725. lines_per_panel = var->yres;
  726. if ((fbi->lccr0 & LCCR0_SDS) == LCCR0_Dual)
  727. lines_per_panel /= 2;
  728. fbi->reg_lccr2 =
  729. LCCR2_DisHght(lines_per_panel) +
  730. LCCR2_VrtSnchWdth(var->vsync_len) +
  731. LCCR2_BegFrmDel(var->upper_margin) +
  732. LCCR2_EndFrmDel(var->lower_margin);
  733. fbi->reg_lccr3 = fbi->lccr3 |
  734. (var->sync & FB_SYNC_HOR_HIGH_ACT ?
  735. LCCR3_HorSnchH : LCCR3_HorSnchL) |
  736. (var->sync & FB_SYNC_VERT_HIGH_ACT ?
  737. LCCR3_VrtSnchH : LCCR3_VrtSnchL);
  738. if (pcd) {
  739. fbi->reg_lccr3 |= LCCR3_PixClkDiv(pcd);
  740. set_hsync_time(fbi, pcd);
  741. }
  742. }
  743. /*
  744. * pxafb_activate_var():
  745. * Configures LCD Controller based on entries in var parameter.
  746. * Settings are only written to the controller if changes were made.
  747. */
  748. static int pxafb_activate_var(struct fb_var_screeninfo *var,
  749. struct pxafb_info *fbi)
  750. {
  751. u_long flags;
  752. size_t nbytes;
  753. #if DEBUG_VAR
  754. if (!(fbi->lccr0 & LCCR0_LCDT)) {
  755. if (var->xres < 16 || var->xres > 1024)
  756. printk(KERN_ERR "%s: invalid xres %d\n",
  757. fbi->fb.fix.id, var->xres);
  758. switch (var->bits_per_pixel) {
  759. case 1:
  760. case 2:
  761. case 4:
  762. case 8:
  763. case 16:
  764. case 24:
  765. case 32:
  766. break;
  767. default:
  768. printk(KERN_ERR "%s: invalid bit depth %d\n",
  769. fbi->fb.fix.id, var->bits_per_pixel);
  770. break;
  771. }
  772. if (var->hsync_len < 1 || var->hsync_len > 64)
  773. printk(KERN_ERR "%s: invalid hsync_len %d\n",
  774. fbi->fb.fix.id, var->hsync_len);
  775. if (var->left_margin < 1 || var->left_margin > 255)
  776. printk(KERN_ERR "%s: invalid left_margin %d\n",
  777. fbi->fb.fix.id, var->left_margin);
  778. if (var->right_margin < 1 || var->right_margin > 255)
  779. printk(KERN_ERR "%s: invalid right_margin %d\n",
  780. fbi->fb.fix.id, var->right_margin);
  781. if (var->yres < 1 || var->yres > 1024)
  782. printk(KERN_ERR "%s: invalid yres %d\n",
  783. fbi->fb.fix.id, var->yres);
  784. if (var->vsync_len < 1 || var->vsync_len > 64)
  785. printk(KERN_ERR "%s: invalid vsync_len %d\n",
  786. fbi->fb.fix.id, var->vsync_len);
  787. if (var->upper_margin < 0 || var->upper_margin > 255)
  788. printk(KERN_ERR "%s: invalid upper_margin %d\n",
  789. fbi->fb.fix.id, var->upper_margin);
  790. if (var->lower_margin < 0 || var->lower_margin > 255)
  791. printk(KERN_ERR "%s: invalid lower_margin %d\n",
  792. fbi->fb.fix.id, var->lower_margin);
  793. }
  794. #endif
  795. /* Update shadow copy atomically */
  796. local_irq_save(flags);
  797. #ifdef CONFIG_FB_PXA_SMARTPANEL
  798. if (fbi->lccr0 & LCCR0_LCDT)
  799. setup_smart_timing(fbi, var);
  800. else
  801. #endif
  802. setup_parallel_timing(fbi, var);
  803. fbi->reg_lccr0 = fbi->lccr0 |
  804. (LCCR0_LDM | LCCR0_SFM | LCCR0_IUM | LCCR0_EFM |
  805. LCCR0_QDM | LCCR0_BM | LCCR0_OUM);
  806. fbi->reg_lccr3 |= pxafb_bpp_to_lccr3(var);
  807. nbytes = var->yres * fbi->fb.fix.line_length;
  808. if ((fbi->lccr0 & LCCR0_SDS) == LCCR0_Dual) {
  809. nbytes = nbytes / 2;
  810. setup_frame_dma(fbi, DMA_LOWER, PAL_NONE, nbytes, nbytes);
  811. }
  812. if ((var->bits_per_pixel >= 16) || (fbi->lccr0 & LCCR0_LCDT))
  813. setup_frame_dma(fbi, DMA_BASE, PAL_NONE, 0, nbytes);
  814. else
  815. setup_frame_dma(fbi, DMA_BASE, PAL_BASE, 0, nbytes);
  816. fbi->reg_lccr4 = lcd_readl(fbi, LCCR4) & ~LCCR4_PAL_FOR_MASK;
  817. fbi->reg_lccr4 |= (fbi->lccr4 & LCCR4_PAL_FOR_MASK);
  818. local_irq_restore(flags);
  819. /*
  820. * Only update the registers if the controller is enabled
  821. * and something has changed.
  822. */
  823. if ((lcd_readl(fbi, LCCR0) != fbi->reg_lccr0) ||
  824. (lcd_readl(fbi, LCCR1) != fbi->reg_lccr1) ||
  825. (lcd_readl(fbi, LCCR2) != fbi->reg_lccr2) ||
  826. (lcd_readl(fbi, LCCR3) != fbi->reg_lccr3) ||
  827. (lcd_readl(fbi, FDADR0) != fbi->fdadr[0]) ||
  828. (lcd_readl(fbi, FDADR1) != fbi->fdadr[1]))
  829. pxafb_schedule_work(fbi, C_REENABLE);
  830. return 0;
  831. }
  832. /*
  833. * NOTE! The following functions are purely helpers for set_ctrlr_state.
  834. * Do not call them directly; set_ctrlr_state does the correct serialisation
  835. * to ensure that things happen in the right way 100% of time time.
  836. * -- rmk
  837. */
  838. static inline void __pxafb_backlight_power(struct pxafb_info *fbi, int on)
  839. {
  840. pr_debug("pxafb: backlight o%s\n", on ? "n" : "ff");
  841. if (fbi->backlight_power)
  842. fbi->backlight_power(on);
  843. }
  844. static inline void __pxafb_lcd_power(struct pxafb_info *fbi, int on)
  845. {
  846. pr_debug("pxafb: LCD power o%s\n", on ? "n" : "ff");
  847. if (fbi->lcd_power)
  848. fbi->lcd_power(on, &fbi->fb.var);
  849. }
  850. static void pxafb_enable_controller(struct pxafb_info *fbi)
  851. {
  852. pr_debug("pxafb: Enabling LCD controller\n");
  853. pr_debug("fdadr0 0x%08x\n", (unsigned int) fbi->fdadr[0]);
  854. pr_debug("fdadr1 0x%08x\n", (unsigned int) fbi->fdadr[1]);
  855. pr_debug("reg_lccr0 0x%08x\n", (unsigned int) fbi->reg_lccr0);
  856. pr_debug("reg_lccr1 0x%08x\n", (unsigned int) fbi->reg_lccr1);
  857. pr_debug("reg_lccr2 0x%08x\n", (unsigned int) fbi->reg_lccr2);
  858. pr_debug("reg_lccr3 0x%08x\n", (unsigned int) fbi->reg_lccr3);
  859. /* enable LCD controller clock */
  860. clk_enable(fbi->clk);
  861. if (fbi->lccr0 & LCCR0_LCDT)
  862. return;
  863. /* Sequence from 11.7.10 */
  864. lcd_writel(fbi, LCCR3, fbi->reg_lccr3);
  865. lcd_writel(fbi, LCCR2, fbi->reg_lccr2);
  866. lcd_writel(fbi, LCCR1, fbi->reg_lccr1);
  867. lcd_writel(fbi, LCCR0, fbi->reg_lccr0 & ~LCCR0_ENB);
  868. lcd_writel(fbi, FDADR0, fbi->fdadr[0]);
  869. lcd_writel(fbi, FDADR1, fbi->fdadr[1]);
  870. lcd_writel(fbi, LCCR0, fbi->reg_lccr0 | LCCR0_ENB);
  871. }
  872. static void pxafb_disable_controller(struct pxafb_info *fbi)
  873. {
  874. uint32_t lccr0;
  875. #ifdef CONFIG_FB_PXA_SMARTPANEL
  876. if (fbi->lccr0 & LCCR0_LCDT) {
  877. wait_for_completion_timeout(&fbi->refresh_done,
  878. 200 * HZ / 1000);
  879. return;
  880. }
  881. #endif
  882. /* Clear LCD Status Register */
  883. lcd_writel(fbi, LCSR, 0xffffffff);
  884. lccr0 = lcd_readl(fbi, LCCR0) & ~LCCR0_LDM;
  885. lcd_writel(fbi, LCCR0, lccr0);
  886. lcd_writel(fbi, LCCR0, lccr0 | LCCR0_DIS);
  887. wait_for_completion_timeout(&fbi->disable_done, 200 * HZ / 1000);
  888. /* disable LCD controller clock */
  889. clk_disable(fbi->clk);
  890. }
  891. /*
  892. * pxafb_handle_irq: Handle 'LCD DONE' interrupts.
  893. */
  894. static irqreturn_t pxafb_handle_irq(int irq, void *dev_id)
  895. {
  896. struct pxafb_info *fbi = dev_id;
  897. unsigned int lccr0, lcsr = lcd_readl(fbi, LCSR);
  898. if (lcsr & LCSR_LDD) {
  899. lccr0 = lcd_readl(fbi, LCCR0);
  900. lcd_writel(fbi, LCCR0, lccr0 | LCCR0_LDM);
  901. complete(&fbi->disable_done);
  902. }
  903. #ifdef CONFIG_FB_PXA_SMARTPANEL
  904. if (lcsr & LCSR_CMD_INT)
  905. complete(&fbi->command_done);
  906. #endif
  907. lcd_writel(fbi, LCSR, lcsr);
  908. return IRQ_HANDLED;
  909. }
  910. /*
  911. * This function must be called from task context only, since it will
  912. * sleep when disabling the LCD controller, or if we get two contending
  913. * processes trying to alter state.
  914. */
  915. static void set_ctrlr_state(struct pxafb_info *fbi, u_int state)
  916. {
  917. u_int old_state;
  918. mutex_lock(&fbi->ctrlr_lock);
  919. old_state = fbi->state;
  920. /*
  921. * Hack around fbcon initialisation.
  922. */
  923. if (old_state == C_STARTUP && state == C_REENABLE)
  924. state = C_ENABLE;
  925. switch (state) {
  926. case C_DISABLE_CLKCHANGE:
  927. /*
  928. * Disable controller for clock change. If the
  929. * controller is already disabled, then do nothing.
  930. */
  931. if (old_state != C_DISABLE && old_state != C_DISABLE_PM) {
  932. fbi->state = state;
  933. /* TODO __pxafb_lcd_power(fbi, 0); */
  934. pxafb_disable_controller(fbi);
  935. }
  936. break;
  937. case C_DISABLE_PM:
  938. case C_DISABLE:
  939. /*
  940. * Disable controller
  941. */
  942. if (old_state != C_DISABLE) {
  943. fbi->state = state;
  944. __pxafb_backlight_power(fbi, 0);
  945. __pxafb_lcd_power(fbi, 0);
  946. if (old_state != C_DISABLE_CLKCHANGE)
  947. pxafb_disable_controller(fbi);
  948. }
  949. break;
  950. case C_ENABLE_CLKCHANGE:
  951. /*
  952. * Enable the controller after clock change. Only
  953. * do this if we were disabled for the clock change.
  954. */
  955. if (old_state == C_DISABLE_CLKCHANGE) {
  956. fbi->state = C_ENABLE;
  957. pxafb_enable_controller(fbi);
  958. /* TODO __pxafb_lcd_power(fbi, 1); */
  959. }
  960. break;
  961. case C_REENABLE:
  962. /*
  963. * Re-enable the controller only if it was already
  964. * enabled. This is so we reprogram the control
  965. * registers.
  966. */
  967. if (old_state == C_ENABLE) {
  968. __pxafb_lcd_power(fbi, 0);
  969. pxafb_disable_controller(fbi);
  970. pxafb_enable_controller(fbi);
  971. __pxafb_lcd_power(fbi, 1);
  972. }
  973. break;
  974. case C_ENABLE_PM:
  975. /*
  976. * Re-enable the controller after PM. This is not
  977. * perfect - think about the case where we were doing
  978. * a clock change, and we suspended half-way through.
  979. */
  980. if (old_state != C_DISABLE_PM)
  981. break;
  982. /* fall through */
  983. case C_ENABLE:
  984. /*
  985. * Power up the LCD screen, enable controller, and
  986. * turn on the backlight.
  987. */
  988. if (old_state != C_ENABLE) {
  989. fbi->state = C_ENABLE;
  990. pxafb_enable_controller(fbi);
  991. __pxafb_lcd_power(fbi, 1);
  992. __pxafb_backlight_power(fbi, 1);
  993. }
  994. break;
  995. }
  996. mutex_unlock(&fbi->ctrlr_lock);
  997. }
  998. /*
  999. * Our LCD controller task (which is called when we blank or unblank)
  1000. * via keventd.
  1001. */
  1002. static void pxafb_task(struct work_struct *work)
  1003. {
  1004. struct pxafb_info *fbi =
  1005. container_of(work, struct pxafb_info, task);
  1006. u_int state = xchg(&fbi->task_state, -1);
  1007. set_ctrlr_state(fbi, state);
  1008. }
  1009. #ifdef CONFIG_CPU_FREQ
  1010. /*
  1011. * CPU clock speed change handler. We need to adjust the LCD timing
  1012. * parameters when the CPU clock is adjusted by the power management
  1013. * subsystem.
  1014. *
  1015. * TODO: Determine why f->new != 10*get_lclk_frequency_10khz()
  1016. */
  1017. static int
  1018. pxafb_freq_transition(struct notifier_block *nb, unsigned long val, void *data)
  1019. {
  1020. struct pxafb_info *fbi = TO_INF(nb, freq_transition);
  1021. /* TODO struct cpufreq_freqs *f = data; */
  1022. u_int pcd;
  1023. switch (val) {
  1024. case CPUFREQ_PRECHANGE:
  1025. set_ctrlr_state(fbi, C_DISABLE_CLKCHANGE);
  1026. break;
  1027. case CPUFREQ_POSTCHANGE:
  1028. pcd = get_pcd(fbi, fbi->fb.var.pixclock);
  1029. set_hsync_time(fbi, pcd);
  1030. fbi->reg_lccr3 = (fbi->reg_lccr3 & ~0xff) |
  1031. LCCR3_PixClkDiv(pcd);
  1032. set_ctrlr_state(fbi, C_ENABLE_CLKCHANGE);
  1033. break;
  1034. }
  1035. return 0;
  1036. }
  1037. static int
  1038. pxafb_freq_policy(struct notifier_block *nb, unsigned long val, void *data)
  1039. {
  1040. struct pxafb_info *fbi = TO_INF(nb, freq_policy);
  1041. struct fb_var_screeninfo *var = &fbi->fb.var;
  1042. struct cpufreq_policy *policy = data;
  1043. switch (val) {
  1044. case CPUFREQ_ADJUST:
  1045. case CPUFREQ_INCOMPATIBLE:
  1046. pr_debug("min dma period: %d ps, "
  1047. "new clock %d kHz\n", pxafb_display_dma_period(var),
  1048. policy->max);
  1049. /* TODO: fill in min/max values */
  1050. break;
  1051. }
  1052. return 0;
  1053. }
  1054. #endif
  1055. #ifdef CONFIG_PM
  1056. /*
  1057. * Power management hooks. Note that we won't be called from IRQ context,
  1058. * unlike the blank functions above, so we may sleep.
  1059. */
  1060. static int pxafb_suspend(struct platform_device *dev, pm_message_t state)
  1061. {
  1062. struct pxafb_info *fbi = platform_get_drvdata(dev);
  1063. set_ctrlr_state(fbi, C_DISABLE_PM);
  1064. return 0;
  1065. }
  1066. static int pxafb_resume(struct platform_device *dev)
  1067. {
  1068. struct pxafb_info *fbi = platform_get_drvdata(dev);
  1069. set_ctrlr_state(fbi, C_ENABLE_PM);
  1070. return 0;
  1071. }
  1072. #else
  1073. #define pxafb_suspend NULL
  1074. #define pxafb_resume NULL
  1075. #endif
  1076. /*
  1077. * pxafb_map_video_memory():
  1078. * Allocates the DRAM memory for the frame buffer. This buffer is
  1079. * remapped into a non-cached, non-buffered, memory region to
  1080. * allow palette and pixel writes to occur without flushing the
  1081. * cache. Once this area is remapped, all virtual memory
  1082. * access to the video memory should occur at the new region.
  1083. */
  1084. static int __devinit pxafb_map_video_memory(struct pxafb_info *fbi)
  1085. {
  1086. /*
  1087. * We reserve one page for the palette, plus the size
  1088. * of the framebuffer.
  1089. */
  1090. fbi->video_offset = PAGE_ALIGN(sizeof(struct pxafb_dma_buff));
  1091. fbi->map_size = PAGE_ALIGN(fbi->fb.fix.smem_len + fbi->video_offset);
  1092. fbi->map_cpu = dma_alloc_writecombine(fbi->dev, fbi->map_size,
  1093. &fbi->map_dma, GFP_KERNEL);
  1094. if (fbi->map_cpu) {
  1095. /* prevent initial garbage on screen */
  1096. memset(fbi->map_cpu, 0, fbi->map_size);
  1097. fbi->fb.screen_base = fbi->map_cpu + fbi->video_offset;
  1098. fbi->screen_dma = fbi->map_dma + fbi->video_offset;
  1099. /*
  1100. * FIXME: this is actually the wrong thing to place in
  1101. * smem_start. But fbdev suffers from the problem that
  1102. * it needs an API which doesn't exist (in this case,
  1103. * dma_writecombine_mmap)
  1104. */
  1105. fbi->fb.fix.smem_start = fbi->screen_dma;
  1106. fbi->palette_size = fbi->fb.var.bits_per_pixel == 8 ? 256 : 16;
  1107. fbi->dma_buff = (void *) fbi->map_cpu;
  1108. fbi->dma_buff_phys = fbi->map_dma;
  1109. fbi->palette_cpu = (u16 *) fbi->dma_buff->palette;
  1110. pr_debug("pxafb: palette_mem_size = 0x%08x\n", fbi->palette_size*sizeof(u16));
  1111. #ifdef CONFIG_FB_PXA_SMARTPANEL
  1112. fbi->smart_cmds = (uint16_t *) fbi->dma_buff->cmd_buff;
  1113. fbi->n_smart_cmds = 0;
  1114. #endif
  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. #ifdef CONFIG_FB_PXA_SMARTPANEL
  1214. init_completion(&fbi->command_done);
  1215. init_completion(&fbi->refresh_done);
  1216. #endif
  1217. return fbi;
  1218. }
  1219. #ifdef CONFIG_FB_PXA_PARAMETERS
  1220. static int __devinit parse_opt_mode(struct device *dev, const char *this_opt)
  1221. {
  1222. struct pxafb_mach_info *inf = dev->platform_data;
  1223. const char *name = this_opt+5;
  1224. unsigned int namelen = strlen(name);
  1225. int res_specified = 0, bpp_specified = 0;
  1226. unsigned int xres = 0, yres = 0, bpp = 0;
  1227. int yres_specified = 0;
  1228. int i;
  1229. for (i = namelen-1; i >= 0; i--) {
  1230. switch (name[i]) {
  1231. case '-':
  1232. namelen = i;
  1233. if (!bpp_specified && !yres_specified) {
  1234. bpp = simple_strtoul(&name[i+1], NULL, 0);
  1235. bpp_specified = 1;
  1236. } else
  1237. goto done;
  1238. break;
  1239. case 'x':
  1240. if (!yres_specified) {
  1241. yres = simple_strtoul(&name[i+1], NULL, 0);
  1242. yres_specified = 1;
  1243. } else
  1244. goto done;
  1245. break;
  1246. case '0' ... '9':
  1247. break;
  1248. default:
  1249. goto done;
  1250. }
  1251. }
  1252. if (i < 0 && yres_specified) {
  1253. xres = simple_strtoul(name, NULL, 0);
  1254. res_specified = 1;
  1255. }
  1256. done:
  1257. if (res_specified) {
  1258. dev_info(dev, "overriding resolution: %dx%d\n", xres, yres);
  1259. inf->modes[0].xres = xres; inf->modes[0].yres = yres;
  1260. }
  1261. if (bpp_specified)
  1262. switch (bpp) {
  1263. case 1:
  1264. case 2:
  1265. case 4:
  1266. case 8:
  1267. case 16:
  1268. inf->modes[0].bpp = bpp;
  1269. dev_info(dev, "overriding bit depth: %d\n", bpp);
  1270. break;
  1271. default:
  1272. dev_err(dev, "Depth %d is not valid\n", bpp);
  1273. return -EINVAL;
  1274. }
  1275. return 0;
  1276. }
  1277. static int __devinit parse_opt(struct device *dev, char *this_opt)
  1278. {
  1279. struct pxafb_mach_info *inf = dev->platform_data;
  1280. struct pxafb_mode_info *mode = &inf->modes[0];
  1281. char s[64];
  1282. s[0] = '\0';
  1283. if (!strncmp(this_opt, "mode:", 5)) {
  1284. return parse_opt_mode(dev, this_opt);
  1285. } else if (!strncmp(this_opt, "pixclock:", 9)) {
  1286. mode->pixclock = simple_strtoul(this_opt+9, NULL, 0);
  1287. sprintf(s, "pixclock: %ld\n", mode->pixclock);
  1288. } else if (!strncmp(this_opt, "left:", 5)) {
  1289. mode->left_margin = simple_strtoul(this_opt+5, NULL, 0);
  1290. sprintf(s, "left: %u\n", mode->left_margin);
  1291. } else if (!strncmp(this_opt, "right:", 6)) {
  1292. mode->right_margin = simple_strtoul(this_opt+6, NULL, 0);
  1293. sprintf(s, "right: %u\n", mode->right_margin);
  1294. } else if (!strncmp(this_opt, "upper:", 6)) {
  1295. mode->upper_margin = simple_strtoul(this_opt+6, NULL, 0);
  1296. sprintf(s, "upper: %u\n", mode->upper_margin);
  1297. } else if (!strncmp(this_opt, "lower:", 6)) {
  1298. mode->lower_margin = simple_strtoul(this_opt+6, NULL, 0);
  1299. sprintf(s, "lower: %u\n", mode->lower_margin);
  1300. } else if (!strncmp(this_opt, "hsynclen:", 9)) {
  1301. mode->hsync_len = simple_strtoul(this_opt+9, NULL, 0);
  1302. sprintf(s, "hsynclen: %u\n", mode->hsync_len);
  1303. } else if (!strncmp(this_opt, "vsynclen:", 9)) {
  1304. mode->vsync_len = simple_strtoul(this_opt+9, NULL, 0);
  1305. sprintf(s, "vsynclen: %u\n", mode->vsync_len);
  1306. } else if (!strncmp(this_opt, "hsync:", 6)) {
  1307. if (simple_strtoul(this_opt+6, NULL, 0) == 0) {
  1308. sprintf(s, "hsync: Active Low\n");
  1309. mode->sync &= ~FB_SYNC_HOR_HIGH_ACT;
  1310. } else {
  1311. sprintf(s, "hsync: Active High\n");
  1312. mode->sync |= FB_SYNC_HOR_HIGH_ACT;
  1313. }
  1314. } else if (!strncmp(this_opt, "vsync:", 6)) {
  1315. if (simple_strtoul(this_opt+6, NULL, 0) == 0) {
  1316. sprintf(s, "vsync: Active Low\n");
  1317. mode->sync &= ~FB_SYNC_VERT_HIGH_ACT;
  1318. } else {
  1319. sprintf(s, "vsync: Active High\n");
  1320. mode->sync |= FB_SYNC_VERT_HIGH_ACT;
  1321. }
  1322. } else if (!strncmp(this_opt, "dpc:", 4)) {
  1323. if (simple_strtoul(this_opt+4, NULL, 0) == 0) {
  1324. sprintf(s, "double pixel clock: false\n");
  1325. inf->lccr3 &= ~LCCR3_DPC;
  1326. } else {
  1327. sprintf(s, "double pixel clock: true\n");
  1328. inf->lccr3 |= LCCR3_DPC;
  1329. }
  1330. } else if (!strncmp(this_opt, "outputen:", 9)) {
  1331. if (simple_strtoul(this_opt+9, NULL, 0) == 0) {
  1332. sprintf(s, "output enable: active low\n");
  1333. inf->lccr3 = (inf->lccr3 & ~LCCR3_OEP) | LCCR3_OutEnL;
  1334. } else {
  1335. sprintf(s, "output enable: active high\n");
  1336. inf->lccr3 = (inf->lccr3 & ~LCCR3_OEP) | LCCR3_OutEnH;
  1337. }
  1338. } else if (!strncmp(this_opt, "pixclockpol:", 12)) {
  1339. if (simple_strtoul(this_opt+12, NULL, 0) == 0) {
  1340. sprintf(s, "pixel clock polarity: falling edge\n");
  1341. inf->lccr3 = (inf->lccr3 & ~LCCR3_PCP) | LCCR3_PixFlEdg;
  1342. } else {
  1343. sprintf(s, "pixel clock polarity: rising edge\n");
  1344. inf->lccr3 = (inf->lccr3 & ~LCCR3_PCP) | LCCR3_PixRsEdg;
  1345. }
  1346. } else if (!strncmp(this_opt, "color", 5)) {
  1347. inf->lccr0 = (inf->lccr0 & ~LCCR0_CMS) | LCCR0_Color;
  1348. } else if (!strncmp(this_opt, "mono", 4)) {
  1349. inf->lccr0 = (inf->lccr0 & ~LCCR0_CMS) | LCCR0_Mono;
  1350. } else if (!strncmp(this_opt, "active", 6)) {
  1351. inf->lccr0 = (inf->lccr0 & ~LCCR0_PAS) | LCCR0_Act;
  1352. } else if (!strncmp(this_opt, "passive", 7)) {
  1353. inf->lccr0 = (inf->lccr0 & ~LCCR0_PAS) | LCCR0_Pas;
  1354. } else if (!strncmp(this_opt, "single", 6)) {
  1355. inf->lccr0 = (inf->lccr0 & ~LCCR0_SDS) | LCCR0_Sngl;
  1356. } else if (!strncmp(this_opt, "dual", 4)) {
  1357. inf->lccr0 = (inf->lccr0 & ~LCCR0_SDS) | LCCR0_Dual;
  1358. } else if (!strncmp(this_opt, "4pix", 4)) {
  1359. inf->lccr0 = (inf->lccr0 & ~LCCR0_DPD) | LCCR0_4PixMono;
  1360. } else if (!strncmp(this_opt, "8pix", 4)) {
  1361. inf->lccr0 = (inf->lccr0 & ~LCCR0_DPD) | LCCR0_8PixMono;
  1362. } else {
  1363. dev_err(dev, "unknown option: %s\n", this_opt);
  1364. return -EINVAL;
  1365. }
  1366. if (s[0] != '\0')
  1367. dev_info(dev, "override %s", s);
  1368. return 0;
  1369. }
  1370. static int __devinit pxafb_parse_options(struct device *dev, char *options)
  1371. {
  1372. char *this_opt;
  1373. int ret;
  1374. if (!options || !*options)
  1375. return 0;
  1376. dev_dbg(dev, "options are \"%s\"\n", options ? options : "null");
  1377. /* could be made table driven or similar?... */
  1378. while ((this_opt = strsep(&options, ",")) != NULL) {
  1379. ret = parse_opt(dev, this_opt);
  1380. if (ret)
  1381. return ret;
  1382. }
  1383. return 0;
  1384. }
  1385. static char g_options[256] __devinitdata = "";
  1386. #ifndef MODULE
  1387. static int __init pxafb_setup_options(void)
  1388. {
  1389. char *options = NULL;
  1390. if (fb_get_options("pxafb", &options))
  1391. return -ENODEV;
  1392. if (options)
  1393. strlcpy(g_options, options, sizeof(g_options));
  1394. return 0;
  1395. }
  1396. #else
  1397. #define pxafb_setup_options() (0)
  1398. module_param_string(options, g_options, sizeof(g_options), 0);
  1399. MODULE_PARM_DESC(options, "LCD parameters (see Documentation/fb/pxafb.txt)");
  1400. #endif
  1401. #else
  1402. #define pxafb_parse_options(...) (0)
  1403. #define pxafb_setup_options() (0)
  1404. #endif
  1405. #ifdef DEBUG_VAR
  1406. /* Check for various illegal bit-combinations. Currently only
  1407. * a warning is given. */
  1408. static void __devinit pxafb_check_options(struct device *dev,
  1409. struct pxafb_mach_info *inf)
  1410. {
  1411. if (inf->lcd_conn)
  1412. return;
  1413. if (inf->lccr0 & LCCR0_INVALID_CONFIG_MASK)
  1414. dev_warn(dev, "machine LCCR0 setting contains "
  1415. "illegal bits: %08x\n",
  1416. inf->lccr0 & LCCR0_INVALID_CONFIG_MASK);
  1417. if (inf->lccr3 & LCCR3_INVALID_CONFIG_MASK)
  1418. dev_warn(dev, "machine LCCR3 setting contains "
  1419. "illegal bits: %08x\n",
  1420. inf->lccr3 & LCCR3_INVALID_CONFIG_MASK);
  1421. if (inf->lccr0 & LCCR0_DPD &&
  1422. ((inf->lccr0 & LCCR0_PAS) != LCCR0_Pas ||
  1423. (inf->lccr0 & LCCR0_SDS) != LCCR0_Sngl ||
  1424. (inf->lccr0 & LCCR0_CMS) != LCCR0_Mono))
  1425. dev_warn(dev, "Double Pixel Data (DPD) mode is "
  1426. "only valid in passive mono"
  1427. " single panel mode\n");
  1428. if ((inf->lccr0 & LCCR0_PAS) == LCCR0_Act &&
  1429. (inf->lccr0 & LCCR0_SDS) == LCCR0_Dual)
  1430. dev_warn(dev, "Dual panel only valid in passive mode\n");
  1431. if ((inf->lccr0 & LCCR0_PAS) == LCCR0_Pas &&
  1432. (inf->modes->upper_margin || inf->modes->lower_margin))
  1433. dev_warn(dev, "Upper and lower margins must be 0 in "
  1434. "passive mode\n");
  1435. }
  1436. #else
  1437. #define pxafb_check_options(...) do {} while (0)
  1438. #endif
  1439. static int __devinit pxafb_probe(struct platform_device *dev)
  1440. {
  1441. struct pxafb_info *fbi;
  1442. struct pxafb_mach_info *inf;
  1443. struct resource *r;
  1444. int irq, ret;
  1445. dev_dbg(&dev->dev, "pxafb_probe\n");
  1446. inf = dev->dev.platform_data;
  1447. ret = -ENOMEM;
  1448. fbi = NULL;
  1449. if (!inf)
  1450. goto failed;
  1451. ret = pxafb_parse_options(&dev->dev, g_options);
  1452. if (ret < 0)
  1453. goto failed;
  1454. pxafb_check_options(&dev->dev, inf);
  1455. dev_dbg(&dev->dev, "got a %dx%dx%d LCD\n",
  1456. inf->modes->xres,
  1457. inf->modes->yres,
  1458. inf->modes->bpp);
  1459. if (inf->modes->xres == 0 ||
  1460. inf->modes->yres == 0 ||
  1461. inf->modes->bpp == 0) {
  1462. dev_err(&dev->dev, "Invalid resolution or bit depth\n");
  1463. ret = -EINVAL;
  1464. goto failed;
  1465. }
  1466. fbi = pxafb_init_fbinfo(&dev->dev);
  1467. if (!fbi) {
  1468. /* only reason for pxafb_init_fbinfo to fail is kmalloc */
  1469. dev_err(&dev->dev, "Failed to initialize framebuffer device\n");
  1470. ret = -ENOMEM;
  1471. goto failed;
  1472. }
  1473. fbi->backlight_power = inf->pxafb_backlight_power;
  1474. fbi->lcd_power = inf->pxafb_lcd_power;
  1475. r = platform_get_resource(dev, IORESOURCE_MEM, 0);
  1476. if (r == NULL) {
  1477. dev_err(&dev->dev, "no I/O memory resource defined\n");
  1478. ret = -ENODEV;
  1479. goto failed_fbi;
  1480. }
  1481. r = request_mem_region(r->start, r->end - r->start + 1, dev->name);
  1482. if (r == NULL) {
  1483. dev_err(&dev->dev, "failed to request I/O memory\n");
  1484. ret = -EBUSY;
  1485. goto failed_fbi;
  1486. }
  1487. fbi->mmio_base = ioremap(r->start, r->end - r->start + 1);
  1488. if (fbi->mmio_base == NULL) {
  1489. dev_err(&dev->dev, "failed to map I/O memory\n");
  1490. ret = -EBUSY;
  1491. goto failed_free_res;
  1492. }
  1493. /* Initialize video memory */
  1494. ret = pxafb_map_video_memory(fbi);
  1495. if (ret) {
  1496. dev_err(&dev->dev, "Failed to allocate video RAM: %d\n", ret);
  1497. ret = -ENOMEM;
  1498. goto failed_free_io;
  1499. }
  1500. irq = platform_get_irq(dev, 0);
  1501. if (irq < 0) {
  1502. dev_err(&dev->dev, "no IRQ defined\n");
  1503. ret = -ENODEV;
  1504. goto failed_free_mem;
  1505. }
  1506. ret = request_irq(irq, pxafb_handle_irq, IRQF_DISABLED, "LCD", fbi);
  1507. if (ret) {
  1508. dev_err(&dev->dev, "request_irq failed: %d\n", ret);
  1509. ret = -EBUSY;
  1510. goto failed_free_mem;
  1511. }
  1512. #ifdef CONFIG_FB_PXA_SMARTPANEL
  1513. ret = pxafb_smart_init(fbi);
  1514. if (ret) {
  1515. dev_err(&dev->dev, "failed to initialize smartpanel\n");
  1516. goto failed_free_irq;
  1517. }
  1518. #endif
  1519. /*
  1520. * This makes sure that our colour bitfield
  1521. * descriptors are correctly initialised.
  1522. */
  1523. ret = pxafb_check_var(&fbi->fb.var, &fbi->fb);
  1524. if (ret) {
  1525. dev_err(&dev->dev, "failed to get suitable mode\n");
  1526. goto failed_free_irq;
  1527. }
  1528. ret = pxafb_set_par(&fbi->fb);
  1529. if (ret) {
  1530. dev_err(&dev->dev, "Failed to set parameters\n");
  1531. goto failed_free_irq;
  1532. }
  1533. platform_set_drvdata(dev, fbi);
  1534. ret = register_framebuffer(&fbi->fb);
  1535. if (ret < 0) {
  1536. dev_err(&dev->dev,
  1537. "Failed to register framebuffer device: %d\n", ret);
  1538. goto failed_free_cmap;
  1539. }
  1540. #ifdef CONFIG_CPU_FREQ
  1541. fbi->freq_transition.notifier_call = pxafb_freq_transition;
  1542. fbi->freq_policy.notifier_call = pxafb_freq_policy;
  1543. cpufreq_register_notifier(&fbi->freq_transition,
  1544. CPUFREQ_TRANSITION_NOTIFIER);
  1545. cpufreq_register_notifier(&fbi->freq_policy,
  1546. CPUFREQ_POLICY_NOTIFIER);
  1547. #endif
  1548. /*
  1549. * Ok, now enable the LCD controller
  1550. */
  1551. set_ctrlr_state(fbi, C_ENABLE);
  1552. return 0;
  1553. failed_free_cmap:
  1554. if (fbi->fb.cmap.len)
  1555. fb_dealloc_cmap(&fbi->fb.cmap);
  1556. failed_free_irq:
  1557. free_irq(irq, fbi);
  1558. failed_free_mem:
  1559. dma_free_writecombine(&dev->dev, fbi->map_size,
  1560. fbi->map_cpu, fbi->map_dma);
  1561. failed_free_io:
  1562. iounmap(fbi->mmio_base);
  1563. failed_free_res:
  1564. release_mem_region(r->start, r->end - r->start + 1);
  1565. failed_fbi:
  1566. clk_put(fbi->clk);
  1567. platform_set_drvdata(dev, NULL);
  1568. kfree(fbi);
  1569. failed:
  1570. return ret;
  1571. }
  1572. static int __devexit pxafb_remove(struct platform_device *dev)
  1573. {
  1574. struct pxafb_info *fbi = platform_get_drvdata(dev);
  1575. struct resource *r;
  1576. int irq;
  1577. struct fb_info *info;
  1578. if (!fbi)
  1579. return 0;
  1580. info = &fbi->fb;
  1581. unregister_framebuffer(info);
  1582. pxafb_disable_controller(fbi);
  1583. if (fbi->fb.cmap.len)
  1584. fb_dealloc_cmap(&fbi->fb.cmap);
  1585. irq = platform_get_irq(dev, 0);
  1586. free_irq(irq, fbi);
  1587. dma_free_writecombine(&dev->dev, fbi->map_size,
  1588. fbi->map_cpu, fbi->map_dma);
  1589. iounmap(fbi->mmio_base);
  1590. r = platform_get_resource(dev, IORESOURCE_MEM, 0);
  1591. release_mem_region(r->start, r->end - r->start + 1);
  1592. clk_put(fbi->clk);
  1593. kfree(fbi);
  1594. return 0;
  1595. }
  1596. static struct platform_driver pxafb_driver = {
  1597. .probe = pxafb_probe,
  1598. .remove = pxafb_remove,
  1599. .suspend = pxafb_suspend,
  1600. .resume = pxafb_resume,
  1601. .driver = {
  1602. .owner = THIS_MODULE,
  1603. .name = "pxa2xx-fb",
  1604. },
  1605. };
  1606. static int __init pxafb_init(void)
  1607. {
  1608. if (pxafb_setup_options())
  1609. return -EINVAL;
  1610. return platform_driver_register(&pxafb_driver);
  1611. }
  1612. static void __exit pxafb_exit(void)
  1613. {
  1614. platform_driver_unregister(&pxafb_driver);
  1615. }
  1616. module_init(pxafb_init);
  1617. module_exit(pxafb_exit);
  1618. MODULE_DESCRIPTION("loadable framebuffer driver for PXA");
  1619. MODULE_LICENSE("GPL");