pxafb.c 50 KB

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