pxafb.c 47 KB

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