pxafb.c 42 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426
  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/config.h>
  25. #include <linux/module.h>
  26. #include <linux/moduleparam.h>
  27. #include <linux/kernel.h>
  28. #include <linux/sched.h>
  29. #include <linux/errno.h>
  30. #include <linux/string.h>
  31. #include <linux/interrupt.h>
  32. #include <linux/slab.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 <asm/hardware.h>
  41. #include <asm/io.h>
  42. #include <asm/irq.h>
  43. #include <asm/uaccess.h>
  44. #include <asm/div64.h>
  45. #include <asm/arch/pxa-regs.h>
  46. #include <asm/arch/bitfield.h>
  47. #include <asm/arch/pxafb.h>
  48. /*
  49. * Complain if VAR is out of range.
  50. */
  51. #define DEBUG_VAR 1
  52. #include "pxafb.h"
  53. /* Bits which should not be set in machine configuration structures */
  54. #define LCCR0_INVALID_CONFIG_MASK (LCCR0_OUM|LCCR0_BM|LCCR0_QDM|LCCR0_DIS|LCCR0_EFM|LCCR0_IUM|LCCR0_SFM|LCCR0_LDM|LCCR0_ENB)
  55. #define LCCR3_INVALID_CONFIG_MASK (LCCR3_HSP|LCCR3_VSP|LCCR3_PCD|LCCR3_BPP)
  56. static void (*pxafb_backlight_power)(int);
  57. static void (*pxafb_lcd_power)(int);
  58. static int pxafb_activate_var(struct fb_var_screeninfo *var, struct pxafb_info *);
  59. static void set_ctrlr_state(struct pxafb_info *fbi, u_int state);
  60. #ifdef CONFIG_FB_PXA_PARAMETERS
  61. #define PXAFB_OPTIONS_SIZE 256
  62. static char g_options[PXAFB_OPTIONS_SIZE] __initdata = "";
  63. #endif
  64. static inline void pxafb_schedule_work(struct pxafb_info *fbi, u_int state)
  65. {
  66. unsigned long flags;
  67. local_irq_save(flags);
  68. /*
  69. * We need to handle two requests being made at the same time.
  70. * There are two important cases:
  71. * 1. When we are changing VT (C_REENABLE) while unblanking (C_ENABLE)
  72. * We must perform the unblanking, which will do our REENABLE for us.
  73. * 2. When we are blanking, but immediately unblank before we have
  74. * blanked. We do the "REENABLE" thing here as well, just to be sure.
  75. */
  76. if (fbi->task_state == C_ENABLE && state == C_REENABLE)
  77. state = (u_int) -1;
  78. if (fbi->task_state == C_DISABLE && state == C_ENABLE)
  79. state = C_REENABLE;
  80. if (state != (u_int)-1) {
  81. fbi->task_state = state;
  82. schedule_work(&fbi->task);
  83. }
  84. local_irq_restore(flags);
  85. }
  86. static inline u_int chan_to_field(u_int chan, struct fb_bitfield *bf)
  87. {
  88. chan &= 0xffff;
  89. chan >>= 16 - bf->length;
  90. return chan << bf->offset;
  91. }
  92. static int
  93. pxafb_setpalettereg(u_int regno, u_int red, u_int green, u_int blue,
  94. u_int trans, struct fb_info *info)
  95. {
  96. struct pxafb_info *fbi = (struct pxafb_info *)info;
  97. u_int val, ret = 1;
  98. if (regno < fbi->palette_size) {
  99. if (fbi->fb.var.grayscale) {
  100. val = ((blue >> 8) & 0x00ff);
  101. } else {
  102. val = ((red >> 0) & 0xf800);
  103. val |= ((green >> 5) & 0x07e0);
  104. val |= ((blue >> 11) & 0x001f);
  105. }
  106. fbi->palette_cpu[regno] = val;
  107. ret = 0;
  108. }
  109. return ret;
  110. }
  111. static int
  112. pxafb_setcolreg(u_int regno, u_int red, u_int green, u_int blue,
  113. u_int trans, struct fb_info *info)
  114. {
  115. struct pxafb_info *fbi = (struct pxafb_info *)info;
  116. unsigned int val;
  117. int ret = 1;
  118. /*
  119. * If inverse mode was selected, invert all the colours
  120. * rather than the register number. The register number
  121. * is what you poke into the framebuffer to produce the
  122. * colour you requested.
  123. */
  124. if (fbi->cmap_inverse) {
  125. red = 0xffff - red;
  126. green = 0xffff - green;
  127. blue = 0xffff - blue;
  128. }
  129. /*
  130. * If greyscale is true, then we convert the RGB value
  131. * to greyscale no matter what visual we are using.
  132. */
  133. if (fbi->fb.var.grayscale)
  134. red = green = blue = (19595 * red + 38470 * green +
  135. 7471 * blue) >> 16;
  136. switch (fbi->fb.fix.visual) {
  137. case FB_VISUAL_TRUECOLOR:
  138. /*
  139. * 16-bit True Colour. We encode the RGB value
  140. * according to the RGB bitfield information.
  141. */
  142. if (regno < 16) {
  143. u32 *pal = fbi->fb.pseudo_palette;
  144. val = chan_to_field(red, &fbi->fb.var.red);
  145. val |= chan_to_field(green, &fbi->fb.var.green);
  146. val |= chan_to_field(blue, &fbi->fb.var.blue);
  147. pal[regno] = val;
  148. ret = 0;
  149. }
  150. break;
  151. case FB_VISUAL_STATIC_PSEUDOCOLOR:
  152. case FB_VISUAL_PSEUDOCOLOR:
  153. ret = pxafb_setpalettereg(regno, red, green, blue, trans, info);
  154. break;
  155. }
  156. return ret;
  157. }
  158. /*
  159. * pxafb_bpp_to_lccr3():
  160. * Convert a bits per pixel value to the correct bit pattern for LCCR3
  161. */
  162. static int pxafb_bpp_to_lccr3(struct fb_var_screeninfo *var)
  163. {
  164. int ret = 0;
  165. switch (var->bits_per_pixel) {
  166. case 1: ret = LCCR3_1BPP; break;
  167. case 2: ret = LCCR3_2BPP; break;
  168. case 4: ret = LCCR3_4BPP; break;
  169. case 8: ret = LCCR3_8BPP; break;
  170. case 16: ret = LCCR3_16BPP; break;
  171. }
  172. return ret;
  173. }
  174. #ifdef CONFIG_CPU_FREQ
  175. /*
  176. * pxafb_display_dma_period()
  177. * Calculate the minimum period (in picoseconds) between two DMA
  178. * requests for the LCD controller. If we hit this, it means we're
  179. * doing nothing but LCD DMA.
  180. */
  181. static unsigned int pxafb_display_dma_period(struct fb_var_screeninfo *var)
  182. {
  183. /*
  184. * Period = pixclock * bits_per_byte * bytes_per_transfer
  185. * / memory_bits_per_pixel;
  186. */
  187. return var->pixclock * 8 * 16 / var->bits_per_pixel;
  188. }
  189. extern unsigned int get_clk_frequency_khz(int info);
  190. #endif
  191. /*
  192. * pxafb_check_var():
  193. * Get the video params out of 'var'. If a value doesn't fit, round it up,
  194. * if it's too big, return -EINVAL.
  195. *
  196. * Round up in the following order: bits_per_pixel, xres,
  197. * yres, xres_virtual, yres_virtual, xoffset, yoffset, grayscale,
  198. * bitfields, horizontal timing, vertical timing.
  199. */
  200. static int pxafb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
  201. {
  202. struct pxafb_info *fbi = (struct pxafb_info *)info;
  203. if (var->xres < MIN_XRES)
  204. var->xres = MIN_XRES;
  205. if (var->yres < MIN_YRES)
  206. var->yres = MIN_YRES;
  207. if (var->xres > fbi->max_xres)
  208. return -EINVAL;
  209. if (var->yres > fbi->max_yres)
  210. return -EINVAL;
  211. var->xres_virtual =
  212. max(var->xres_virtual, var->xres);
  213. var->yres_virtual =
  214. max(var->yres_virtual, var->yres);
  215. /*
  216. * Setup the RGB parameters for this display.
  217. *
  218. * The pixel packing format is described on page 7-11 of the
  219. * PXA2XX Developer's Manual.
  220. */
  221. if (var->bits_per_pixel == 16) {
  222. var->red.offset = 11; var->red.length = 5;
  223. var->green.offset = 5; var->green.length = 6;
  224. var->blue.offset = 0; var->blue.length = 5;
  225. var->transp.offset = var->transp.length = 0;
  226. } else {
  227. var->red.offset = var->green.offset = var->blue.offset = var->transp.offset = 0;
  228. var->red.length = 8;
  229. var->green.length = 8;
  230. var->blue.length = 8;
  231. var->transp.length = 0;
  232. }
  233. #ifdef CONFIG_CPU_FREQ
  234. pr_debug("pxafb: dma period = %d ps, clock = %d kHz\n",
  235. pxafb_display_dma_period(var),
  236. get_clk_frequency_khz(0));
  237. #endif
  238. return 0;
  239. }
  240. static inline void pxafb_set_truecolor(u_int is_true_color)
  241. {
  242. pr_debug("pxafb: true_color = %d\n", is_true_color);
  243. // do your machine-specific setup if needed
  244. }
  245. /*
  246. * pxafb_set_par():
  247. * Set the user defined part of the display for the specified console
  248. */
  249. static int pxafb_set_par(struct fb_info *info)
  250. {
  251. struct pxafb_info *fbi = (struct pxafb_info *)info;
  252. struct fb_var_screeninfo *var = &info->var;
  253. unsigned long palette_mem_size;
  254. pr_debug("pxafb: set_par\n");
  255. if (var->bits_per_pixel == 16)
  256. fbi->fb.fix.visual = FB_VISUAL_TRUECOLOR;
  257. else if (!fbi->cmap_static)
  258. fbi->fb.fix.visual = FB_VISUAL_PSEUDOCOLOR;
  259. else {
  260. /*
  261. * Some people have weird ideas about wanting static
  262. * pseudocolor maps. I suspect their user space
  263. * applications are broken.
  264. */
  265. fbi->fb.fix.visual = FB_VISUAL_STATIC_PSEUDOCOLOR;
  266. }
  267. fbi->fb.fix.line_length = var->xres_virtual *
  268. var->bits_per_pixel / 8;
  269. if (var->bits_per_pixel == 16)
  270. fbi->palette_size = 0;
  271. else
  272. fbi->palette_size = var->bits_per_pixel == 1 ? 4 : 1 << var->bits_per_pixel;
  273. palette_mem_size = fbi->palette_size * sizeof(u16);
  274. pr_debug("pxafb: palette_mem_size = 0x%08lx\n", palette_mem_size);
  275. fbi->palette_cpu = (u16 *)(fbi->map_cpu + PAGE_SIZE - palette_mem_size);
  276. fbi->palette_dma = fbi->map_dma + PAGE_SIZE - palette_mem_size;
  277. /*
  278. * Set (any) board control register to handle new color depth
  279. */
  280. pxafb_set_truecolor(fbi->fb.fix.visual == FB_VISUAL_TRUECOLOR);
  281. if (fbi->fb.var.bits_per_pixel == 16)
  282. fb_dealloc_cmap(&fbi->fb.cmap);
  283. else
  284. fb_alloc_cmap(&fbi->fb.cmap, 1<<fbi->fb.var.bits_per_pixel, 0);
  285. pxafb_activate_var(var, fbi);
  286. return 0;
  287. }
  288. /*
  289. * Formal definition of the VESA spec:
  290. * On
  291. * This refers to the state of the display when it is in full operation
  292. * Stand-By
  293. * This defines an optional operating state of minimal power reduction with
  294. * the shortest recovery time
  295. * Suspend
  296. * This refers to a level of power management in which substantial power
  297. * reduction is achieved by the display. The display can have a longer
  298. * recovery time from this state than from the Stand-by state
  299. * Off
  300. * This indicates that the display is consuming the lowest level of power
  301. * and is non-operational. Recovery from this state may optionally require
  302. * the user to manually power on the monitor
  303. *
  304. * Now, the fbdev driver adds an additional state, (blank), where they
  305. * turn off the video (maybe by colormap tricks), but don't mess with the
  306. * video itself: think of it semantically between on and Stand-By.
  307. *
  308. * So here's what we should do in our fbdev blank routine:
  309. *
  310. * VESA_NO_BLANKING (mode 0) Video on, front/back light on
  311. * VESA_VSYNC_SUSPEND (mode 1) Video on, front/back light off
  312. * VESA_HSYNC_SUSPEND (mode 2) Video on, front/back light off
  313. * VESA_POWERDOWN (mode 3) Video off, front/back light off
  314. *
  315. * This will match the matrox implementation.
  316. */
  317. /*
  318. * pxafb_blank():
  319. * Blank the display by setting all palette values to zero. Note, the
  320. * 16 bpp mode does not really use the palette, so this will not
  321. * blank the display in all modes.
  322. */
  323. static int pxafb_blank(int blank, struct fb_info *info)
  324. {
  325. struct pxafb_info *fbi = (struct pxafb_info *)info;
  326. int i;
  327. pr_debug("pxafb: blank=%d\n", blank);
  328. switch (blank) {
  329. case FB_BLANK_POWERDOWN:
  330. case FB_BLANK_VSYNC_SUSPEND:
  331. case FB_BLANK_HSYNC_SUSPEND:
  332. case FB_BLANK_NORMAL:
  333. if (fbi->fb.fix.visual == FB_VISUAL_PSEUDOCOLOR ||
  334. fbi->fb.fix.visual == FB_VISUAL_STATIC_PSEUDOCOLOR)
  335. for (i = 0; i < fbi->palette_size; i++)
  336. pxafb_setpalettereg(i, 0, 0, 0, 0, info);
  337. pxafb_schedule_work(fbi, C_DISABLE);
  338. //TODO if (pxafb_blank_helper) pxafb_blank_helper(blank);
  339. break;
  340. case FB_BLANK_UNBLANK:
  341. //TODO if (pxafb_blank_helper) pxafb_blank_helper(blank);
  342. if (fbi->fb.fix.visual == FB_VISUAL_PSEUDOCOLOR ||
  343. fbi->fb.fix.visual == FB_VISUAL_STATIC_PSEUDOCOLOR)
  344. fb_set_cmap(&fbi->fb.cmap, info);
  345. pxafb_schedule_work(fbi, C_ENABLE);
  346. }
  347. return 0;
  348. }
  349. static int pxafb_mmap(struct fb_info *info,
  350. struct vm_area_struct *vma)
  351. {
  352. struct pxafb_info *fbi = (struct pxafb_info *)info;
  353. unsigned long off = vma->vm_pgoff << PAGE_SHIFT;
  354. if (off < info->fix.smem_len) {
  355. vma->vm_pgoff += 1;
  356. return dma_mmap_writecombine(fbi->dev, vma, fbi->map_cpu,
  357. fbi->map_dma, fbi->map_size);
  358. }
  359. return -EINVAL;
  360. }
  361. static struct fb_ops pxafb_ops = {
  362. .owner = THIS_MODULE,
  363. .fb_check_var = pxafb_check_var,
  364. .fb_set_par = pxafb_set_par,
  365. .fb_setcolreg = pxafb_setcolreg,
  366. .fb_fillrect = cfb_fillrect,
  367. .fb_copyarea = cfb_copyarea,
  368. .fb_imageblit = cfb_imageblit,
  369. .fb_blank = pxafb_blank,
  370. .fb_mmap = pxafb_mmap,
  371. };
  372. /*
  373. * Calculate the PCD value from the clock rate (in picoseconds).
  374. * We take account of the PPCR clock setting.
  375. * From PXA Developer's Manual:
  376. *
  377. * PixelClock = LCLK
  378. * -------------
  379. * 2 ( PCD + 1 )
  380. *
  381. * PCD = LCLK
  382. * ------------- - 1
  383. * 2(PixelClock)
  384. *
  385. * Where:
  386. * LCLK = LCD/Memory Clock
  387. * PCD = LCCR3[7:0]
  388. *
  389. * PixelClock here is in Hz while the pixclock argument given is the
  390. * period in picoseconds. Hence PixelClock = 1 / ( pixclock * 10^-12 )
  391. *
  392. * The function get_lclk_frequency_10khz returns LCLK in units of
  393. * 10khz. Calling the result of this function lclk gives us the
  394. * following
  395. *
  396. * PCD = (lclk * 10^4 ) * ( pixclock * 10^-12 )
  397. * -------------------------------------- - 1
  398. * 2
  399. *
  400. * Factoring the 10^4 and 10^-12 out gives 10^-8 == 1 / 100000000 as used below.
  401. */
  402. static inline unsigned int get_pcd(unsigned int pixclock)
  403. {
  404. unsigned long long pcd;
  405. /* FIXME: Need to take into account Double Pixel Clock mode
  406. * (DPC) bit? or perhaps set it based on the various clock
  407. * speeds */
  408. pcd = (unsigned long long)get_lcdclk_frequency_10khz() * pixclock;
  409. do_div(pcd, 100000000 * 2);
  410. /* no need for this, since we should subtract 1 anyway. they cancel */
  411. /* pcd += 1; */ /* make up for integer math truncations */
  412. return (unsigned int)pcd;
  413. }
  414. /*
  415. * Some touchscreens need hsync information from the video driver to
  416. * function correctly. We export it here.
  417. */
  418. static inline void set_hsync_time(struct pxafb_info *fbi, unsigned int pcd)
  419. {
  420. unsigned long long htime;
  421. if ((pcd == 0) || (fbi->fb.var.hsync_len == 0)) {
  422. fbi->hsync_time=0;
  423. return;
  424. }
  425. htime = (unsigned long long)get_lcdclk_frequency_10khz() * 10000;
  426. do_div(htime, pcd * fbi->fb.var.hsync_len);
  427. fbi->hsync_time = htime;
  428. }
  429. unsigned long pxafb_get_hsync_time(struct device *dev)
  430. {
  431. struct pxafb_info *fbi = dev_get_drvdata(dev);
  432. /* If display is blanked/suspended, hsync isn't active */
  433. if (!fbi || (fbi->state != C_ENABLE))
  434. return 0;
  435. return fbi->hsync_time;
  436. }
  437. EXPORT_SYMBOL(pxafb_get_hsync_time);
  438. /*
  439. * pxafb_activate_var():
  440. * Configures LCD Controller based on entries in var parameter. Settings are
  441. * only written to the controller if changes were made.
  442. */
  443. static int pxafb_activate_var(struct fb_var_screeninfo *var, struct pxafb_info *fbi)
  444. {
  445. struct pxafb_lcd_reg new_regs;
  446. u_long flags;
  447. u_int lines_per_panel, pcd = get_pcd(var->pixclock);
  448. pr_debug("pxafb: Configuring PXA LCD\n");
  449. pr_debug("var: xres=%d hslen=%d lm=%d rm=%d\n",
  450. var->xres, var->hsync_len,
  451. var->left_margin, var->right_margin);
  452. pr_debug("var: yres=%d vslen=%d um=%d bm=%d\n",
  453. var->yres, var->vsync_len,
  454. var->upper_margin, var->lower_margin);
  455. pr_debug("var: pixclock=%d pcd=%d\n", var->pixclock, pcd);
  456. #if DEBUG_VAR
  457. if (var->xres < 16 || var->xres > 1024)
  458. printk(KERN_ERR "%s: invalid xres %d\n",
  459. fbi->fb.fix.id, var->xres);
  460. switch(var->bits_per_pixel) {
  461. case 1:
  462. case 2:
  463. case 4:
  464. case 8:
  465. case 16:
  466. break;
  467. default:
  468. printk(KERN_ERR "%s: invalid bit depth %d\n",
  469. fbi->fb.fix.id, var->bits_per_pixel);
  470. break;
  471. }
  472. if (var->hsync_len < 1 || var->hsync_len > 64)
  473. printk(KERN_ERR "%s: invalid hsync_len %d\n",
  474. fbi->fb.fix.id, var->hsync_len);
  475. if (var->left_margin < 1 || var->left_margin > 255)
  476. printk(KERN_ERR "%s: invalid left_margin %d\n",
  477. fbi->fb.fix.id, var->left_margin);
  478. if (var->right_margin < 1 || var->right_margin > 255)
  479. printk(KERN_ERR "%s: invalid right_margin %d\n",
  480. fbi->fb.fix.id, var->right_margin);
  481. if (var->yres < 1 || var->yres > 1024)
  482. printk(KERN_ERR "%s: invalid yres %d\n",
  483. fbi->fb.fix.id, var->yres);
  484. if (var->vsync_len < 1 || var->vsync_len > 64)
  485. printk(KERN_ERR "%s: invalid vsync_len %d\n",
  486. fbi->fb.fix.id, var->vsync_len);
  487. if (var->upper_margin < 0 || var->upper_margin > 255)
  488. printk(KERN_ERR "%s: invalid upper_margin %d\n",
  489. fbi->fb.fix.id, var->upper_margin);
  490. if (var->lower_margin < 0 || var->lower_margin > 255)
  491. printk(KERN_ERR "%s: invalid lower_margin %d\n",
  492. fbi->fb.fix.id, var->lower_margin);
  493. #endif
  494. new_regs.lccr0 = fbi->lccr0 |
  495. (LCCR0_LDM | LCCR0_SFM | LCCR0_IUM | LCCR0_EFM |
  496. LCCR0_QDM | LCCR0_BM | LCCR0_OUM);
  497. new_regs.lccr1 =
  498. LCCR1_DisWdth(var->xres) +
  499. LCCR1_HorSnchWdth(var->hsync_len) +
  500. LCCR1_BegLnDel(var->left_margin) +
  501. LCCR1_EndLnDel(var->right_margin);
  502. /*
  503. * If we have a dual scan LCD, we need to halve
  504. * the YRES parameter.
  505. */
  506. lines_per_panel = var->yres;
  507. if ((fbi->lccr0 & LCCR0_SDS) == LCCR0_Dual)
  508. lines_per_panel /= 2;
  509. new_regs.lccr2 =
  510. LCCR2_DisHght(lines_per_panel) +
  511. LCCR2_VrtSnchWdth(var->vsync_len) +
  512. LCCR2_BegFrmDel(var->upper_margin) +
  513. LCCR2_EndFrmDel(var->lower_margin);
  514. new_regs.lccr3 = fbi->lccr3 |
  515. pxafb_bpp_to_lccr3(var) |
  516. (var->sync & FB_SYNC_HOR_HIGH_ACT ? LCCR3_HorSnchH : LCCR3_HorSnchL) |
  517. (var->sync & FB_SYNC_VERT_HIGH_ACT ? LCCR3_VrtSnchH : LCCR3_VrtSnchL);
  518. if (pcd)
  519. new_regs.lccr3 |= LCCR3_PixClkDiv(pcd);
  520. pr_debug("nlccr0 = 0x%08x\n", new_regs.lccr0);
  521. pr_debug("nlccr1 = 0x%08x\n", new_regs.lccr1);
  522. pr_debug("nlccr2 = 0x%08x\n", new_regs.lccr2);
  523. pr_debug("nlccr3 = 0x%08x\n", new_regs.lccr3);
  524. /* Update shadow copy atomically */
  525. local_irq_save(flags);
  526. /* setup dma descriptors */
  527. fbi->dmadesc_fblow_cpu = (struct pxafb_dma_descriptor *)((unsigned int)fbi->palette_cpu - 3*16);
  528. fbi->dmadesc_fbhigh_cpu = (struct pxafb_dma_descriptor *)((unsigned int)fbi->palette_cpu - 2*16);
  529. fbi->dmadesc_palette_cpu = (struct pxafb_dma_descriptor *)((unsigned int)fbi->palette_cpu - 1*16);
  530. fbi->dmadesc_fblow_dma = fbi->palette_dma - 3*16;
  531. fbi->dmadesc_fbhigh_dma = fbi->palette_dma - 2*16;
  532. fbi->dmadesc_palette_dma = fbi->palette_dma - 1*16;
  533. #define BYTES_PER_PANEL (lines_per_panel * fbi->fb.fix.line_length)
  534. /* populate descriptors */
  535. fbi->dmadesc_fblow_cpu->fdadr = fbi->dmadesc_fblow_dma;
  536. fbi->dmadesc_fblow_cpu->fsadr = fbi->screen_dma + BYTES_PER_PANEL;
  537. fbi->dmadesc_fblow_cpu->fidr = 0;
  538. fbi->dmadesc_fblow_cpu->ldcmd = BYTES_PER_PANEL;
  539. fbi->fdadr1 = fbi->dmadesc_fblow_dma; /* only used in dual-panel mode */
  540. fbi->dmadesc_fbhigh_cpu->fsadr = fbi->screen_dma;
  541. fbi->dmadesc_fbhigh_cpu->fidr = 0;
  542. fbi->dmadesc_fbhigh_cpu->ldcmd = BYTES_PER_PANEL;
  543. fbi->dmadesc_palette_cpu->fsadr = fbi->palette_dma;
  544. fbi->dmadesc_palette_cpu->fidr = 0;
  545. fbi->dmadesc_palette_cpu->ldcmd = (fbi->palette_size * 2) | LDCMD_PAL;
  546. if (var->bits_per_pixel == 16) {
  547. /* palette shouldn't be loaded in true-color mode */
  548. fbi->dmadesc_fbhigh_cpu->fdadr = fbi->dmadesc_fbhigh_dma;
  549. fbi->fdadr0 = fbi->dmadesc_fbhigh_dma; /* no pal just fbhigh */
  550. /* init it to something, even though we won't be using it */
  551. fbi->dmadesc_palette_cpu->fdadr = fbi->dmadesc_palette_dma;
  552. } else {
  553. fbi->dmadesc_palette_cpu->fdadr = fbi->dmadesc_fbhigh_dma;
  554. fbi->dmadesc_fbhigh_cpu->fdadr = fbi->dmadesc_palette_dma;
  555. fbi->fdadr0 = fbi->dmadesc_palette_dma; /* flips back and forth between pal and fbhigh */
  556. }
  557. #if 0
  558. pr_debug("fbi->dmadesc_fblow_cpu = 0x%p\n", fbi->dmadesc_fblow_cpu);
  559. pr_debug("fbi->dmadesc_fbhigh_cpu = 0x%p\n", fbi->dmadesc_fbhigh_cpu);
  560. pr_debug("fbi->dmadesc_palette_cpu = 0x%p\n", fbi->dmadesc_palette_cpu);
  561. pr_debug("fbi->dmadesc_fblow_dma = 0x%x\n", fbi->dmadesc_fblow_dma);
  562. pr_debug("fbi->dmadesc_fbhigh_dma = 0x%x\n", fbi->dmadesc_fbhigh_dma);
  563. pr_debug("fbi->dmadesc_palette_dma = 0x%x\n", fbi->dmadesc_palette_dma);
  564. pr_debug("fbi->dmadesc_fblow_cpu->fdadr = 0x%x\n", fbi->dmadesc_fblow_cpu->fdadr);
  565. pr_debug("fbi->dmadesc_fbhigh_cpu->fdadr = 0x%x\n", fbi->dmadesc_fbhigh_cpu->fdadr);
  566. pr_debug("fbi->dmadesc_palette_cpu->fdadr = 0x%x\n", fbi->dmadesc_palette_cpu->fdadr);
  567. pr_debug("fbi->dmadesc_fblow_cpu->fsadr = 0x%x\n", fbi->dmadesc_fblow_cpu->fsadr);
  568. pr_debug("fbi->dmadesc_fbhigh_cpu->fsadr = 0x%x\n", fbi->dmadesc_fbhigh_cpu->fsadr);
  569. pr_debug("fbi->dmadesc_palette_cpu->fsadr = 0x%x\n", fbi->dmadesc_palette_cpu->fsadr);
  570. pr_debug("fbi->dmadesc_fblow_cpu->ldcmd = 0x%x\n", fbi->dmadesc_fblow_cpu->ldcmd);
  571. pr_debug("fbi->dmadesc_fbhigh_cpu->ldcmd = 0x%x\n", fbi->dmadesc_fbhigh_cpu->ldcmd);
  572. pr_debug("fbi->dmadesc_palette_cpu->ldcmd = 0x%x\n", fbi->dmadesc_palette_cpu->ldcmd);
  573. #endif
  574. fbi->reg_lccr0 = new_regs.lccr0;
  575. fbi->reg_lccr1 = new_regs.lccr1;
  576. fbi->reg_lccr2 = new_regs.lccr2;
  577. fbi->reg_lccr3 = new_regs.lccr3;
  578. set_hsync_time(fbi, pcd);
  579. local_irq_restore(flags);
  580. /*
  581. * Only update the registers if the controller is enabled
  582. * and something has changed.
  583. */
  584. if ((LCCR0 != fbi->reg_lccr0) || (LCCR1 != fbi->reg_lccr1) ||
  585. (LCCR2 != fbi->reg_lccr2) || (LCCR3 != fbi->reg_lccr3) ||
  586. (FDADR0 != fbi->fdadr0) || (FDADR1 != fbi->fdadr1))
  587. pxafb_schedule_work(fbi, C_REENABLE);
  588. return 0;
  589. }
  590. /*
  591. * NOTE! The following functions are purely helpers for set_ctrlr_state.
  592. * Do not call them directly; set_ctrlr_state does the correct serialisation
  593. * to ensure that things happen in the right way 100% of time time.
  594. * -- rmk
  595. */
  596. static inline void __pxafb_backlight_power(struct pxafb_info *fbi, int on)
  597. {
  598. pr_debug("pxafb: backlight o%s\n", on ? "n" : "ff");
  599. if (pxafb_backlight_power)
  600. pxafb_backlight_power(on);
  601. }
  602. static inline void __pxafb_lcd_power(struct pxafb_info *fbi, int on)
  603. {
  604. pr_debug("pxafb: LCD power o%s\n", on ? "n" : "ff");
  605. if (pxafb_lcd_power)
  606. pxafb_lcd_power(on);
  607. }
  608. static void pxafb_setup_gpio(struct pxafb_info *fbi)
  609. {
  610. int gpio, ldd_bits;
  611. unsigned int lccr0 = fbi->lccr0;
  612. /*
  613. * setup is based on type of panel supported
  614. */
  615. /* 4 bit interface */
  616. if ((lccr0 & LCCR0_CMS) == LCCR0_Mono &&
  617. (lccr0 & LCCR0_SDS) == LCCR0_Sngl &&
  618. (lccr0 & LCCR0_DPD) == LCCR0_4PixMono)
  619. ldd_bits = 4;
  620. /* 8 bit interface */
  621. else if (((lccr0 & LCCR0_CMS) == LCCR0_Mono &&
  622. ((lccr0 & LCCR0_SDS) == LCCR0_Dual || (lccr0 & LCCR0_DPD) == LCCR0_8PixMono)) ||
  623. ((lccr0 & LCCR0_CMS) == LCCR0_Color &&
  624. (lccr0 & LCCR0_PAS) == LCCR0_Pas && (lccr0 & LCCR0_SDS) == LCCR0_Sngl))
  625. ldd_bits = 8;
  626. /* 16 bit interface */
  627. else if ((lccr0 & LCCR0_CMS) == LCCR0_Color &&
  628. ((lccr0 & LCCR0_SDS) == LCCR0_Dual || (lccr0 & LCCR0_PAS) == LCCR0_Act))
  629. ldd_bits = 16;
  630. else {
  631. printk(KERN_ERR "pxafb_setup_gpio: unable to determine bits per pixel\n");
  632. return;
  633. }
  634. for (gpio = 58; ldd_bits; gpio++, ldd_bits--)
  635. pxa_gpio_mode(gpio | GPIO_ALT_FN_2_OUT);
  636. pxa_gpio_mode(GPIO74_LCD_FCLK_MD);
  637. pxa_gpio_mode(GPIO75_LCD_LCLK_MD);
  638. pxa_gpio_mode(GPIO76_LCD_PCLK_MD);
  639. pxa_gpio_mode(GPIO77_LCD_ACBIAS_MD);
  640. }
  641. static void pxafb_enable_controller(struct pxafb_info *fbi)
  642. {
  643. pr_debug("pxafb: Enabling LCD controller\n");
  644. pr_debug("fdadr0 0x%08x\n", (unsigned int) fbi->fdadr0);
  645. pr_debug("fdadr1 0x%08x\n", (unsigned int) fbi->fdadr1);
  646. pr_debug("reg_lccr0 0x%08x\n", (unsigned int) fbi->reg_lccr0);
  647. pr_debug("reg_lccr1 0x%08x\n", (unsigned int) fbi->reg_lccr1);
  648. pr_debug("reg_lccr2 0x%08x\n", (unsigned int) fbi->reg_lccr2);
  649. pr_debug("reg_lccr3 0x%08x\n", (unsigned int) fbi->reg_lccr3);
  650. /* enable LCD controller clock */
  651. pxa_set_cken(CKEN16_LCD, 1);
  652. /* Sequence from 11.7.10 */
  653. LCCR3 = fbi->reg_lccr3;
  654. LCCR2 = fbi->reg_lccr2;
  655. LCCR1 = fbi->reg_lccr1;
  656. LCCR0 = fbi->reg_lccr0 & ~LCCR0_ENB;
  657. FDADR0 = fbi->fdadr0;
  658. FDADR1 = fbi->fdadr1;
  659. LCCR0 |= LCCR0_ENB;
  660. pr_debug("FDADR0 0x%08x\n", (unsigned int) FDADR0);
  661. pr_debug("FDADR1 0x%08x\n", (unsigned int) FDADR1);
  662. pr_debug("LCCR0 0x%08x\n", (unsigned int) LCCR0);
  663. pr_debug("LCCR1 0x%08x\n", (unsigned int) LCCR1);
  664. pr_debug("LCCR2 0x%08x\n", (unsigned int) LCCR2);
  665. pr_debug("LCCR3 0x%08x\n", (unsigned int) LCCR3);
  666. }
  667. static void pxafb_disable_controller(struct pxafb_info *fbi)
  668. {
  669. DECLARE_WAITQUEUE(wait, current);
  670. pr_debug("pxafb: disabling LCD controller\n");
  671. set_current_state(TASK_UNINTERRUPTIBLE);
  672. add_wait_queue(&fbi->ctrlr_wait, &wait);
  673. LCSR = 0xffffffff; /* Clear LCD Status Register */
  674. LCCR0 &= ~LCCR0_LDM; /* Enable LCD Disable Done Interrupt */
  675. LCCR0 |= LCCR0_DIS; /* Disable LCD Controller */
  676. schedule_timeout(200 * HZ / 1000);
  677. remove_wait_queue(&fbi->ctrlr_wait, &wait);
  678. /* disable LCD controller clock */
  679. pxa_set_cken(CKEN16_LCD, 0);
  680. }
  681. /*
  682. * pxafb_handle_irq: Handle 'LCD DONE' interrupts.
  683. */
  684. static irqreturn_t pxafb_handle_irq(int irq, void *dev_id, struct pt_regs *regs)
  685. {
  686. struct pxafb_info *fbi = dev_id;
  687. unsigned int lcsr = LCSR;
  688. if (lcsr & LCSR_LDD) {
  689. LCCR0 |= LCCR0_LDM;
  690. wake_up(&fbi->ctrlr_wait);
  691. }
  692. LCSR = lcsr;
  693. return IRQ_HANDLED;
  694. }
  695. /*
  696. * This function must be called from task context only, since it will
  697. * sleep when disabling the LCD controller, or if we get two contending
  698. * processes trying to alter state.
  699. */
  700. static void set_ctrlr_state(struct pxafb_info *fbi, u_int state)
  701. {
  702. u_int old_state;
  703. down(&fbi->ctrlr_sem);
  704. old_state = fbi->state;
  705. /*
  706. * Hack around fbcon initialisation.
  707. */
  708. if (old_state == C_STARTUP && state == C_REENABLE)
  709. state = C_ENABLE;
  710. switch (state) {
  711. case C_DISABLE_CLKCHANGE:
  712. /*
  713. * Disable controller for clock change. If the
  714. * controller is already disabled, then do nothing.
  715. */
  716. if (old_state != C_DISABLE && old_state != C_DISABLE_PM) {
  717. fbi->state = state;
  718. //TODO __pxafb_lcd_power(fbi, 0);
  719. pxafb_disable_controller(fbi);
  720. }
  721. break;
  722. case C_DISABLE_PM:
  723. case C_DISABLE:
  724. /*
  725. * Disable controller
  726. */
  727. if (old_state != C_DISABLE) {
  728. fbi->state = state;
  729. __pxafb_backlight_power(fbi, 0);
  730. __pxafb_lcd_power(fbi, 0);
  731. if (old_state != C_DISABLE_CLKCHANGE)
  732. pxafb_disable_controller(fbi);
  733. }
  734. break;
  735. case C_ENABLE_CLKCHANGE:
  736. /*
  737. * Enable the controller after clock change. Only
  738. * do this if we were disabled for the clock change.
  739. */
  740. if (old_state == C_DISABLE_CLKCHANGE) {
  741. fbi->state = C_ENABLE;
  742. pxafb_enable_controller(fbi);
  743. //TODO __pxafb_lcd_power(fbi, 1);
  744. }
  745. break;
  746. case C_REENABLE:
  747. /*
  748. * Re-enable the controller only if it was already
  749. * enabled. This is so we reprogram the control
  750. * registers.
  751. */
  752. if (old_state == C_ENABLE) {
  753. pxafb_disable_controller(fbi);
  754. pxafb_setup_gpio(fbi);
  755. pxafb_enable_controller(fbi);
  756. }
  757. break;
  758. case C_ENABLE_PM:
  759. /*
  760. * Re-enable the controller after PM. This is not
  761. * perfect - think about the case where we were doing
  762. * a clock change, and we suspended half-way through.
  763. */
  764. if (old_state != C_DISABLE_PM)
  765. break;
  766. /* fall through */
  767. case C_ENABLE:
  768. /*
  769. * Power up the LCD screen, enable controller, and
  770. * turn on the backlight.
  771. */
  772. if (old_state != C_ENABLE) {
  773. fbi->state = C_ENABLE;
  774. pxafb_setup_gpio(fbi);
  775. pxafb_enable_controller(fbi);
  776. __pxafb_lcd_power(fbi, 1);
  777. __pxafb_backlight_power(fbi, 1);
  778. }
  779. break;
  780. }
  781. up(&fbi->ctrlr_sem);
  782. }
  783. /*
  784. * Our LCD controller task (which is called when we blank or unblank)
  785. * via keventd.
  786. */
  787. static void pxafb_task(void *dummy)
  788. {
  789. struct pxafb_info *fbi = dummy;
  790. u_int state = xchg(&fbi->task_state, -1);
  791. set_ctrlr_state(fbi, state);
  792. }
  793. #ifdef CONFIG_CPU_FREQ
  794. /*
  795. * CPU clock speed change handler. We need to adjust the LCD timing
  796. * parameters when the CPU clock is adjusted by the power management
  797. * subsystem.
  798. *
  799. * TODO: Determine why f->new != 10*get_lclk_frequency_10khz()
  800. */
  801. static int
  802. pxafb_freq_transition(struct notifier_block *nb, unsigned long val, void *data)
  803. {
  804. struct pxafb_info *fbi = TO_INF(nb, freq_transition);
  805. //TODO struct cpufreq_freqs *f = data;
  806. u_int pcd;
  807. switch (val) {
  808. case CPUFREQ_PRECHANGE:
  809. set_ctrlr_state(fbi, C_DISABLE_CLKCHANGE);
  810. break;
  811. case CPUFREQ_POSTCHANGE:
  812. pcd = get_pcd(fbi->fb.var.pixclock);
  813. set_hsync_time(fbi, pcd);
  814. fbi->reg_lccr3 = (fbi->reg_lccr3 & ~0xff) | LCCR3_PixClkDiv(pcd);
  815. set_ctrlr_state(fbi, C_ENABLE_CLKCHANGE);
  816. break;
  817. }
  818. return 0;
  819. }
  820. static int
  821. pxafb_freq_policy(struct notifier_block *nb, unsigned long val, void *data)
  822. {
  823. struct pxafb_info *fbi = TO_INF(nb, freq_policy);
  824. struct fb_var_screeninfo *var = &fbi->fb.var;
  825. struct cpufreq_policy *policy = data;
  826. switch (val) {
  827. case CPUFREQ_ADJUST:
  828. case CPUFREQ_INCOMPATIBLE:
  829. printk(KERN_DEBUG "min dma period: %d ps, "
  830. "new clock %d kHz\n", pxafb_display_dma_period(var),
  831. policy->max);
  832. // TODO: fill in min/max values
  833. break;
  834. #if 0
  835. case CPUFREQ_NOTIFY:
  836. printk(KERN_ERR "%s: got CPUFREQ_NOTIFY\n", __FUNCTION__);
  837. do {} while(0);
  838. /* todo: panic if min/max values aren't fulfilled
  839. * [can't really happen unless there's a bug in the
  840. * CPU policy verification process *
  841. */
  842. break;
  843. #endif
  844. }
  845. return 0;
  846. }
  847. #endif
  848. #ifdef CONFIG_PM
  849. /*
  850. * Power management hooks. Note that we won't be called from IRQ context,
  851. * unlike the blank functions above, so we may sleep.
  852. */
  853. static int pxafb_suspend(struct platform_device *dev, pm_message_t state)
  854. {
  855. struct pxafb_info *fbi = platform_get_drvdata(dev);
  856. set_ctrlr_state(fbi, C_DISABLE_PM);
  857. return 0;
  858. }
  859. static int pxafb_resume(struct platform_device *dev)
  860. {
  861. struct pxafb_info *fbi = platform_get_drvdata(dev);
  862. set_ctrlr_state(fbi, C_ENABLE_PM);
  863. return 0;
  864. }
  865. #else
  866. #define pxafb_suspend NULL
  867. #define pxafb_resume NULL
  868. #endif
  869. /*
  870. * pxafb_map_video_memory():
  871. * Allocates the DRAM memory for the frame buffer. This buffer is
  872. * remapped into a non-cached, non-buffered, memory region to
  873. * allow palette and pixel writes to occur without flushing the
  874. * cache. Once this area is remapped, all virtual memory
  875. * access to the video memory should occur at the new region.
  876. */
  877. static int __init pxafb_map_video_memory(struct pxafb_info *fbi)
  878. {
  879. u_long palette_mem_size;
  880. /*
  881. * We reserve one page for the palette, plus the size
  882. * of the framebuffer.
  883. */
  884. fbi->map_size = PAGE_ALIGN(fbi->fb.fix.smem_len + PAGE_SIZE);
  885. fbi->map_cpu = dma_alloc_writecombine(fbi->dev, fbi->map_size,
  886. &fbi->map_dma, GFP_KERNEL);
  887. if (fbi->map_cpu) {
  888. /* prevent initial garbage on screen */
  889. memset(fbi->map_cpu, 0, fbi->map_size);
  890. fbi->fb.screen_base = fbi->map_cpu + PAGE_SIZE;
  891. fbi->screen_dma = fbi->map_dma + PAGE_SIZE;
  892. /*
  893. * FIXME: this is actually the wrong thing to place in
  894. * smem_start. But fbdev suffers from the problem that
  895. * it needs an API which doesn't exist (in this case,
  896. * dma_writecombine_mmap)
  897. */
  898. fbi->fb.fix.smem_start = fbi->screen_dma;
  899. fbi->palette_size = fbi->fb.var.bits_per_pixel == 8 ? 256 : 16;
  900. palette_mem_size = fbi->palette_size * sizeof(u16);
  901. pr_debug("pxafb: palette_mem_size = 0x%08lx\n", palette_mem_size);
  902. fbi->palette_cpu = (u16 *)(fbi->map_cpu + PAGE_SIZE - palette_mem_size);
  903. fbi->palette_dma = fbi->map_dma + PAGE_SIZE - palette_mem_size;
  904. }
  905. return fbi->map_cpu ? 0 : -ENOMEM;
  906. }
  907. static struct pxafb_info * __init pxafb_init_fbinfo(struct device *dev)
  908. {
  909. struct pxafb_info *fbi;
  910. void *addr;
  911. struct pxafb_mach_info *inf = dev->platform_data;
  912. /* Alloc the pxafb_info and pseudo_palette in one step */
  913. fbi = kmalloc(sizeof(struct pxafb_info) + sizeof(u32) * 16, GFP_KERNEL);
  914. if (!fbi)
  915. return NULL;
  916. memset(fbi, 0, sizeof(struct pxafb_info));
  917. fbi->dev = dev;
  918. strcpy(fbi->fb.fix.id, PXA_NAME);
  919. fbi->fb.fix.type = FB_TYPE_PACKED_PIXELS;
  920. fbi->fb.fix.type_aux = 0;
  921. fbi->fb.fix.xpanstep = 0;
  922. fbi->fb.fix.ypanstep = 0;
  923. fbi->fb.fix.ywrapstep = 0;
  924. fbi->fb.fix.accel = FB_ACCEL_NONE;
  925. fbi->fb.var.nonstd = 0;
  926. fbi->fb.var.activate = FB_ACTIVATE_NOW;
  927. fbi->fb.var.height = -1;
  928. fbi->fb.var.width = -1;
  929. fbi->fb.var.accel_flags = 0;
  930. fbi->fb.var.vmode = FB_VMODE_NONINTERLACED;
  931. fbi->fb.fbops = &pxafb_ops;
  932. fbi->fb.flags = FBINFO_DEFAULT;
  933. fbi->fb.node = -1;
  934. addr = fbi;
  935. addr = addr + sizeof(struct pxafb_info);
  936. fbi->fb.pseudo_palette = addr;
  937. fbi->max_xres = inf->xres;
  938. fbi->fb.var.xres = inf->xres;
  939. fbi->fb.var.xres_virtual = inf->xres;
  940. fbi->max_yres = inf->yres;
  941. fbi->fb.var.yres = inf->yres;
  942. fbi->fb.var.yres_virtual = inf->yres;
  943. fbi->max_bpp = inf->bpp;
  944. fbi->fb.var.bits_per_pixel = inf->bpp;
  945. fbi->fb.var.pixclock = inf->pixclock;
  946. fbi->fb.var.hsync_len = inf->hsync_len;
  947. fbi->fb.var.left_margin = inf->left_margin;
  948. fbi->fb.var.right_margin = inf->right_margin;
  949. fbi->fb.var.vsync_len = inf->vsync_len;
  950. fbi->fb.var.upper_margin = inf->upper_margin;
  951. fbi->fb.var.lower_margin = inf->lower_margin;
  952. fbi->fb.var.sync = inf->sync;
  953. fbi->fb.var.grayscale = inf->cmap_greyscale;
  954. fbi->cmap_inverse = inf->cmap_inverse;
  955. fbi->cmap_static = inf->cmap_static;
  956. fbi->lccr0 = inf->lccr0;
  957. fbi->lccr3 = inf->lccr3;
  958. fbi->state = C_STARTUP;
  959. fbi->task_state = (u_char)-1;
  960. fbi->fb.fix.smem_len = fbi->max_xres * fbi->max_yres *
  961. fbi->max_bpp / 8;
  962. init_waitqueue_head(&fbi->ctrlr_wait);
  963. INIT_WORK(&fbi->task, pxafb_task, fbi);
  964. init_MUTEX(&fbi->ctrlr_sem);
  965. return fbi;
  966. }
  967. #ifdef CONFIG_FB_PXA_PARAMETERS
  968. static int __init pxafb_parse_options(struct device *dev, char *options)
  969. {
  970. struct pxafb_mach_info *inf = dev->platform_data;
  971. char *this_opt;
  972. if (!options || !*options)
  973. return 0;
  974. dev_dbg(dev, "options are \"%s\"\n", options ? options : "null");
  975. /* could be made table driven or similar?... */
  976. while ((this_opt = strsep(&options, ",")) != NULL) {
  977. if (!strncmp(this_opt, "mode:", 5)) {
  978. const char *name = this_opt+5;
  979. unsigned int namelen = strlen(name);
  980. int res_specified = 0, bpp_specified = 0;
  981. unsigned int xres = 0, yres = 0, bpp = 0;
  982. int yres_specified = 0;
  983. int i;
  984. for (i = namelen-1; i >= 0; i--) {
  985. switch (name[i]) {
  986. case '-':
  987. namelen = i;
  988. if (!bpp_specified && !yres_specified) {
  989. bpp = simple_strtoul(&name[i+1], NULL, 0);
  990. bpp_specified = 1;
  991. } else
  992. goto done;
  993. break;
  994. case 'x':
  995. if (!yres_specified) {
  996. yres = simple_strtoul(&name[i+1], NULL, 0);
  997. yres_specified = 1;
  998. } else
  999. goto done;
  1000. break;
  1001. case '0'...'9':
  1002. break;
  1003. default:
  1004. goto done;
  1005. }
  1006. }
  1007. if (i < 0 && yres_specified) {
  1008. xres = simple_strtoul(name, NULL, 0);
  1009. res_specified = 1;
  1010. }
  1011. done:
  1012. if (res_specified) {
  1013. dev_info(dev, "overriding resolution: %dx%d\n", xres, yres);
  1014. inf->xres = xres; inf->yres = yres;
  1015. }
  1016. if (bpp_specified)
  1017. switch (bpp) {
  1018. case 1:
  1019. case 2:
  1020. case 4:
  1021. case 8:
  1022. case 16:
  1023. inf->bpp = bpp;
  1024. dev_info(dev, "overriding bit depth: %d\n", bpp);
  1025. break;
  1026. default:
  1027. dev_err(dev, "Depth %d is not valid\n", bpp);
  1028. }
  1029. } else if (!strncmp(this_opt, "pixclock:", 9)) {
  1030. inf->pixclock = simple_strtoul(this_opt+9, NULL, 0);
  1031. dev_info(dev, "override pixclock: %ld\n", inf->pixclock);
  1032. } else if (!strncmp(this_opt, "left:", 5)) {
  1033. inf->left_margin = simple_strtoul(this_opt+5, NULL, 0);
  1034. dev_info(dev, "override left: %u\n", inf->left_margin);
  1035. } else if (!strncmp(this_opt, "right:", 6)) {
  1036. inf->right_margin = simple_strtoul(this_opt+6, NULL, 0);
  1037. dev_info(dev, "override right: %u\n", inf->right_margin);
  1038. } else if (!strncmp(this_opt, "upper:", 6)) {
  1039. inf->upper_margin = simple_strtoul(this_opt+6, NULL, 0);
  1040. dev_info(dev, "override upper: %u\n", inf->upper_margin);
  1041. } else if (!strncmp(this_opt, "lower:", 6)) {
  1042. inf->lower_margin = simple_strtoul(this_opt+6, NULL, 0);
  1043. dev_info(dev, "override lower: %u\n", inf->lower_margin);
  1044. } else if (!strncmp(this_opt, "hsynclen:", 9)) {
  1045. inf->hsync_len = simple_strtoul(this_opt+9, NULL, 0);
  1046. dev_info(dev, "override hsynclen: %u\n", inf->hsync_len);
  1047. } else if (!strncmp(this_opt, "vsynclen:", 9)) {
  1048. inf->vsync_len = simple_strtoul(this_opt+9, NULL, 0);
  1049. dev_info(dev, "override vsynclen: %u\n", inf->vsync_len);
  1050. } else if (!strncmp(this_opt, "hsync:", 6)) {
  1051. if (simple_strtoul(this_opt+6, NULL, 0) == 0) {
  1052. dev_info(dev, "override hsync: Active Low\n");
  1053. inf->sync &= ~FB_SYNC_HOR_HIGH_ACT;
  1054. } else {
  1055. dev_info(dev, "override hsync: Active High\n");
  1056. inf->sync |= FB_SYNC_HOR_HIGH_ACT;
  1057. }
  1058. } else if (!strncmp(this_opt, "vsync:", 6)) {
  1059. if (simple_strtoul(this_opt+6, NULL, 0) == 0) {
  1060. dev_info(dev, "override vsync: Active Low\n");
  1061. inf->sync &= ~FB_SYNC_VERT_HIGH_ACT;
  1062. } else {
  1063. dev_info(dev, "override vsync: Active High\n");
  1064. inf->sync |= FB_SYNC_VERT_HIGH_ACT;
  1065. }
  1066. } else if (!strncmp(this_opt, "dpc:", 4)) {
  1067. if (simple_strtoul(this_opt+4, NULL, 0) == 0) {
  1068. dev_info(dev, "override double pixel clock: false\n");
  1069. inf->lccr3 &= ~LCCR3_DPC;
  1070. } else {
  1071. dev_info(dev, "override double pixel clock: true\n");
  1072. inf->lccr3 |= LCCR3_DPC;
  1073. }
  1074. } else if (!strncmp(this_opt, "outputen:", 9)) {
  1075. if (simple_strtoul(this_opt+9, NULL, 0) == 0) {
  1076. dev_info(dev, "override output enable: active low\n");
  1077. inf->lccr3 = (inf->lccr3 & ~LCCR3_OEP) | LCCR3_OutEnL;
  1078. } else {
  1079. dev_info(dev, "override output enable: active high\n");
  1080. inf->lccr3 = (inf->lccr3 & ~LCCR3_OEP) | LCCR3_OutEnH;
  1081. }
  1082. } else if (!strncmp(this_opt, "pixclockpol:", 12)) {
  1083. if (simple_strtoul(this_opt+12, NULL, 0) == 0) {
  1084. dev_info(dev, "override pixel clock polarity: falling edge\n");
  1085. inf->lccr3 = (inf->lccr3 & ~LCCR3_PCP) | LCCR3_PixFlEdg;
  1086. } else {
  1087. dev_info(dev, "override pixel clock polarity: rising edge\n");
  1088. inf->lccr3 = (inf->lccr3 & ~LCCR3_PCP) | LCCR3_PixRsEdg;
  1089. }
  1090. } else if (!strncmp(this_opt, "color", 5)) {
  1091. inf->lccr0 = (inf->lccr0 & ~LCCR0_CMS) | LCCR0_Color;
  1092. } else if (!strncmp(this_opt, "mono", 4)) {
  1093. inf->lccr0 = (inf->lccr0 & ~LCCR0_CMS) | LCCR0_Mono;
  1094. } else if (!strncmp(this_opt, "active", 6)) {
  1095. inf->lccr0 = (inf->lccr0 & ~LCCR0_PAS) | LCCR0_Act;
  1096. } else if (!strncmp(this_opt, "passive", 7)) {
  1097. inf->lccr0 = (inf->lccr0 & ~LCCR0_PAS) | LCCR0_Pas;
  1098. } else if (!strncmp(this_opt, "single", 6)) {
  1099. inf->lccr0 = (inf->lccr0 & ~LCCR0_SDS) | LCCR0_Sngl;
  1100. } else if (!strncmp(this_opt, "dual", 4)) {
  1101. inf->lccr0 = (inf->lccr0 & ~LCCR0_SDS) | LCCR0_Dual;
  1102. } else if (!strncmp(this_opt, "4pix", 4)) {
  1103. inf->lccr0 = (inf->lccr0 & ~LCCR0_DPD) | LCCR0_4PixMono;
  1104. } else if (!strncmp(this_opt, "8pix", 4)) {
  1105. inf->lccr0 = (inf->lccr0 & ~LCCR0_DPD) | LCCR0_8PixMono;
  1106. } else {
  1107. dev_err(dev, "unknown option: %s\n", this_opt);
  1108. return -EINVAL;
  1109. }
  1110. }
  1111. return 0;
  1112. }
  1113. #endif
  1114. int __init pxafb_probe(struct platform_device *dev)
  1115. {
  1116. struct pxafb_info *fbi;
  1117. struct pxafb_mach_info *inf;
  1118. int ret;
  1119. dev_dbg(&dev->dev, "pxafb_probe\n");
  1120. inf = dev->dev.platform_data;
  1121. ret = -ENOMEM;
  1122. fbi = NULL;
  1123. if (!inf)
  1124. goto failed;
  1125. #ifdef CONFIG_FB_PXA_PARAMETERS
  1126. ret = pxafb_parse_options(&dev->dev, g_options);
  1127. if (ret < 0)
  1128. goto failed;
  1129. #endif
  1130. #ifdef DEBUG_VAR
  1131. /* Check for various illegal bit-combinations. Currently only
  1132. * a warning is given. */
  1133. if (inf->lccr0 & LCCR0_INVALID_CONFIG_MASK)
  1134. dev_warn(&dev->dev, "machine LCCR0 setting contains illegal bits: %08x\n",
  1135. inf->lccr0 & LCCR0_INVALID_CONFIG_MASK);
  1136. if (inf->lccr3 & LCCR3_INVALID_CONFIG_MASK)
  1137. dev_warn(&dev->dev, "machine LCCR3 setting contains illegal bits: %08x\n",
  1138. inf->lccr3 & LCCR3_INVALID_CONFIG_MASK);
  1139. if (inf->lccr0 & LCCR0_DPD &&
  1140. ((inf->lccr0 & LCCR0_PAS) != LCCR0_Pas ||
  1141. (inf->lccr0 & LCCR0_SDS) != LCCR0_Sngl ||
  1142. (inf->lccr0 & LCCR0_CMS) != LCCR0_Mono))
  1143. dev_warn(&dev->dev, "Double Pixel Data (DPD) mode is only valid in passive mono"
  1144. " single panel mode\n");
  1145. if ((inf->lccr0 & LCCR0_PAS) == LCCR0_Act &&
  1146. (inf->lccr0 & LCCR0_SDS) == LCCR0_Dual)
  1147. dev_warn(&dev->dev, "Dual panel only valid in passive mode\n");
  1148. if ((inf->lccr0 & LCCR0_PAS) == LCCR0_Pas &&
  1149. (inf->upper_margin || inf->lower_margin))
  1150. dev_warn(&dev->dev, "Upper and lower margins must be 0 in passive mode\n");
  1151. #endif
  1152. dev_dbg(&dev->dev, "got a %dx%dx%d LCD\n",inf->xres, inf->yres, inf->bpp);
  1153. if (inf->xres == 0 || inf->yres == 0 || inf->bpp == 0) {
  1154. dev_err(&dev->dev, "Invalid resolution or bit depth\n");
  1155. ret = -EINVAL;
  1156. goto failed;
  1157. }
  1158. pxafb_backlight_power = inf->pxafb_backlight_power;
  1159. pxafb_lcd_power = inf->pxafb_lcd_power;
  1160. fbi = pxafb_init_fbinfo(&dev->dev);
  1161. if (!fbi) {
  1162. dev_err(&dev->dev, "Failed to initialize framebuffer device\n");
  1163. ret = -ENOMEM; // only reason for pxafb_init_fbinfo to fail is kmalloc
  1164. goto failed;
  1165. }
  1166. /* Initialize video memory */
  1167. ret = pxafb_map_video_memory(fbi);
  1168. if (ret) {
  1169. dev_err(&dev->dev, "Failed to allocate video RAM: %d\n", ret);
  1170. ret = -ENOMEM;
  1171. goto failed;
  1172. }
  1173. ret = request_irq(IRQ_LCD, pxafb_handle_irq, SA_INTERRUPT, "LCD", fbi);
  1174. if (ret) {
  1175. dev_err(&dev->dev, "request_irq failed: %d\n", ret);
  1176. ret = -EBUSY;
  1177. goto failed;
  1178. }
  1179. /*
  1180. * This makes sure that our colour bitfield
  1181. * descriptors are correctly initialised.
  1182. */
  1183. pxafb_check_var(&fbi->fb.var, &fbi->fb);
  1184. pxafb_set_par(&fbi->fb);
  1185. platform_set_drvdata(dev, fbi);
  1186. ret = register_framebuffer(&fbi->fb);
  1187. if (ret < 0) {
  1188. dev_err(&dev->dev, "Failed to register framebuffer device: %d\n", ret);
  1189. goto failed;
  1190. }
  1191. #ifdef CONFIG_PM
  1192. // TODO
  1193. #endif
  1194. #ifdef CONFIG_CPU_FREQ
  1195. fbi->freq_transition.notifier_call = pxafb_freq_transition;
  1196. fbi->freq_policy.notifier_call = pxafb_freq_policy;
  1197. cpufreq_register_notifier(&fbi->freq_transition, CPUFREQ_TRANSITION_NOTIFIER);
  1198. cpufreq_register_notifier(&fbi->freq_policy, CPUFREQ_POLICY_NOTIFIER);
  1199. #endif
  1200. /*
  1201. * Ok, now enable the LCD controller
  1202. */
  1203. set_ctrlr_state(fbi, C_ENABLE);
  1204. return 0;
  1205. failed:
  1206. platform_set_drvdata(dev, NULL);
  1207. kfree(fbi);
  1208. return ret;
  1209. }
  1210. static struct platform_driver pxafb_driver = {
  1211. .probe = pxafb_probe,
  1212. #ifdef CONFIG_PM
  1213. .suspend = pxafb_suspend,
  1214. .resume = pxafb_resume,
  1215. #endif
  1216. .driver = {
  1217. .name = "pxa2xx-fb",
  1218. },
  1219. };
  1220. #ifndef MODULE
  1221. int __devinit pxafb_setup(char *options)
  1222. {
  1223. # ifdef CONFIG_FB_PXA_PARAMETERS
  1224. if (options)
  1225. strlcpy(g_options, options, sizeof(g_options));
  1226. # endif
  1227. return 0;
  1228. }
  1229. #else
  1230. # ifdef CONFIG_FB_PXA_PARAMETERS
  1231. module_param_string(options, g_options, sizeof(g_options), 0);
  1232. MODULE_PARM_DESC(options, "LCD parameters (see Documentation/fb/pxafb.txt)");
  1233. # endif
  1234. #endif
  1235. int __devinit pxafb_init(void)
  1236. {
  1237. #ifndef MODULE
  1238. char *option = NULL;
  1239. if (fb_get_options("pxafb", &option))
  1240. return -ENODEV;
  1241. pxafb_setup(option);
  1242. #endif
  1243. return platform_driver_register(&pxafb_driver);
  1244. }
  1245. module_init(pxafb_init);
  1246. MODULE_DESCRIPTION("loadable framebuffer driver for PXA");
  1247. MODULE_LICENSE("GPL");