pxafb.c 42 KB

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