pxafb.c 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395
  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/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. var->xres = fbi->max_xres;
  209. if (var->yres > fbi->max_yres)
  210. var->yres = fbi->max_yres;
  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. DPRINTK("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. DPRINTK("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. DPRINTK("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. DPRINTK("palette_mem_size = 0x%08lx\n", (u_long) 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. DPRINTK("pxafb_blank: 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, struct file *file,
  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_cursor = soft_cursor,
  371. .fb_mmap = pxafb_mmap,
  372. };
  373. /*
  374. * Calculate the PCD value from the clock rate (in picoseconds).
  375. * We take account of the PPCR clock setting.
  376. * From PXA Developer's Manual:
  377. *
  378. * PixelClock = LCLK
  379. * -------------
  380. * 2 ( PCD + 1 )
  381. *
  382. * PCD = LCLK
  383. * ------------- - 1
  384. * 2(PixelClock)
  385. *
  386. * Where:
  387. * LCLK = LCD/Memory Clock
  388. * PCD = LCCR3[7:0]
  389. *
  390. * PixelClock here is in Hz while the pixclock argument given is the
  391. * period in picoseconds. Hence PixelClock = 1 / ( pixclock * 10^-12 )
  392. *
  393. * The function get_lclk_frequency_10khz returns LCLK in units of
  394. * 10khz. Calling the result of this function lclk gives us the
  395. * following
  396. *
  397. * PCD = (lclk * 10^4 ) * ( pixclock * 10^-12 )
  398. * -------------------------------------- - 1
  399. * 2
  400. *
  401. * Factoring the 10^4 and 10^-12 out gives 10^-8 == 1 / 100000000 as used below.
  402. */
  403. static inline unsigned int get_pcd(unsigned int pixclock)
  404. {
  405. unsigned long long pcd;
  406. /* FIXME: Need to take into account Double Pixel Clock mode
  407. * (DPC) bit? or perhaps set it based on the various clock
  408. * speeds */
  409. pcd = (unsigned long long)get_lcdclk_frequency_10khz() * pixclock;
  410. do_div(pcd, 100000000 * 2);
  411. /* no need for this, since we should subtract 1 anyway. they cancel */
  412. /* pcd += 1; */ /* make up for integer math truncations */
  413. return (unsigned int)pcd;
  414. }
  415. /*
  416. * pxafb_activate_var():
  417. * Configures LCD Controller based on entries in var parameter. Settings are
  418. * only written to the controller if changes were made.
  419. */
  420. static int pxafb_activate_var(struct fb_var_screeninfo *var, struct pxafb_info *fbi)
  421. {
  422. struct pxafb_lcd_reg new_regs;
  423. u_long flags;
  424. u_int lines_per_panel, pcd = get_pcd(var->pixclock);
  425. DPRINTK("Configuring PXA LCD\n");
  426. DPRINTK("var: xres=%d hslen=%d lm=%d rm=%d\n",
  427. var->xres, var->hsync_len,
  428. var->left_margin, var->right_margin);
  429. DPRINTK("var: yres=%d vslen=%d um=%d bm=%d\n",
  430. var->yres, var->vsync_len,
  431. var->upper_margin, var->lower_margin);
  432. DPRINTK("var: pixclock=%d pcd=%d\n", var->pixclock, pcd);
  433. #if DEBUG_VAR
  434. if (var->xres < 16 || var->xres > 1024)
  435. printk(KERN_ERR "%s: invalid xres %d\n",
  436. fbi->fb.fix.id, var->xres);
  437. switch(var->bits_per_pixel) {
  438. case 1:
  439. case 2:
  440. case 4:
  441. case 8:
  442. case 16:
  443. break;
  444. default:
  445. printk(KERN_ERR "%s: invalid bit depth %d\n",
  446. fbi->fb.fix.id, var->bits_per_pixel);
  447. break;
  448. }
  449. if (var->hsync_len < 1 || var->hsync_len > 64)
  450. printk(KERN_ERR "%s: invalid hsync_len %d\n",
  451. fbi->fb.fix.id, var->hsync_len);
  452. if (var->left_margin < 1 || var->left_margin > 255)
  453. printk(KERN_ERR "%s: invalid left_margin %d\n",
  454. fbi->fb.fix.id, var->left_margin);
  455. if (var->right_margin < 1 || var->right_margin > 255)
  456. printk(KERN_ERR "%s: invalid right_margin %d\n",
  457. fbi->fb.fix.id, var->right_margin);
  458. if (var->yres < 1 || var->yres > 1024)
  459. printk(KERN_ERR "%s: invalid yres %d\n",
  460. fbi->fb.fix.id, var->yres);
  461. if (var->vsync_len < 1 || var->vsync_len > 64)
  462. printk(KERN_ERR "%s: invalid vsync_len %d\n",
  463. fbi->fb.fix.id, var->vsync_len);
  464. if (var->upper_margin < 0 || var->upper_margin > 255)
  465. printk(KERN_ERR "%s: invalid upper_margin %d\n",
  466. fbi->fb.fix.id, var->upper_margin);
  467. if (var->lower_margin < 0 || var->lower_margin > 255)
  468. printk(KERN_ERR "%s: invalid lower_margin %d\n",
  469. fbi->fb.fix.id, var->lower_margin);
  470. #endif
  471. new_regs.lccr0 = fbi->lccr0 |
  472. (LCCR0_LDM | LCCR0_SFM | LCCR0_IUM | LCCR0_EFM |
  473. LCCR0_QDM | LCCR0_BM | LCCR0_OUM);
  474. new_regs.lccr1 =
  475. LCCR1_DisWdth(var->xres) +
  476. LCCR1_HorSnchWdth(var->hsync_len) +
  477. LCCR1_BegLnDel(var->left_margin) +
  478. LCCR1_EndLnDel(var->right_margin);
  479. /*
  480. * If we have a dual scan LCD, we need to halve
  481. * the YRES parameter.
  482. */
  483. lines_per_panel = var->yres;
  484. if ((fbi->lccr0 & LCCR0_SDS) == LCCR0_Dual)
  485. lines_per_panel /= 2;
  486. new_regs.lccr2 =
  487. LCCR2_DisHght(lines_per_panel) +
  488. LCCR2_VrtSnchWdth(var->vsync_len) +
  489. LCCR2_BegFrmDel(var->upper_margin) +
  490. LCCR2_EndFrmDel(var->lower_margin);
  491. new_regs.lccr3 = fbi->lccr3 |
  492. pxafb_bpp_to_lccr3(var) |
  493. (var->sync & FB_SYNC_HOR_HIGH_ACT ? LCCR3_HorSnchH : LCCR3_HorSnchL) |
  494. (var->sync & FB_SYNC_VERT_HIGH_ACT ? LCCR3_VrtSnchH : LCCR3_VrtSnchL);
  495. if (pcd)
  496. new_regs.lccr3 |= LCCR3_PixClkDiv(pcd);
  497. DPRINTK("nlccr0 = 0x%08x\n", new_regs.lccr0);
  498. DPRINTK("nlccr1 = 0x%08x\n", new_regs.lccr1);
  499. DPRINTK("nlccr2 = 0x%08x\n", new_regs.lccr2);
  500. DPRINTK("nlccr3 = 0x%08x\n", new_regs.lccr3);
  501. /* Update shadow copy atomically */
  502. local_irq_save(flags);
  503. /* setup dma descriptors */
  504. fbi->dmadesc_fblow_cpu = (struct pxafb_dma_descriptor *)((unsigned int)fbi->palette_cpu - 3*16);
  505. fbi->dmadesc_fbhigh_cpu = (struct pxafb_dma_descriptor *)((unsigned int)fbi->palette_cpu - 2*16);
  506. fbi->dmadesc_palette_cpu = (struct pxafb_dma_descriptor *)((unsigned int)fbi->palette_cpu - 1*16);
  507. fbi->dmadesc_fblow_dma = fbi->palette_dma - 3*16;
  508. fbi->dmadesc_fbhigh_dma = fbi->palette_dma - 2*16;
  509. fbi->dmadesc_palette_dma = fbi->palette_dma - 1*16;
  510. #define BYTES_PER_PANEL (lines_per_panel * fbi->fb.fix.line_length)
  511. /* populate descriptors */
  512. fbi->dmadesc_fblow_cpu->fdadr = fbi->dmadesc_fblow_dma;
  513. fbi->dmadesc_fblow_cpu->fsadr = fbi->screen_dma + BYTES_PER_PANEL;
  514. fbi->dmadesc_fblow_cpu->fidr = 0;
  515. fbi->dmadesc_fblow_cpu->ldcmd = BYTES_PER_PANEL;
  516. fbi->fdadr1 = fbi->dmadesc_fblow_dma; /* only used in dual-panel mode */
  517. fbi->dmadesc_fbhigh_cpu->fsadr = fbi->screen_dma;
  518. fbi->dmadesc_fbhigh_cpu->fidr = 0;
  519. fbi->dmadesc_fbhigh_cpu->ldcmd = BYTES_PER_PANEL;
  520. fbi->dmadesc_palette_cpu->fsadr = fbi->palette_dma;
  521. fbi->dmadesc_palette_cpu->fidr = 0;
  522. fbi->dmadesc_palette_cpu->ldcmd = (fbi->palette_size * 2) | LDCMD_PAL;
  523. if (var->bits_per_pixel == 16) {
  524. /* palette shouldn't be loaded in true-color mode */
  525. fbi->dmadesc_fbhigh_cpu->fdadr = fbi->dmadesc_fbhigh_dma;
  526. fbi->fdadr0 = fbi->dmadesc_fbhigh_dma; /* no pal just fbhigh */
  527. /* init it to something, even though we won't be using it */
  528. fbi->dmadesc_palette_cpu->fdadr = fbi->dmadesc_palette_dma;
  529. } else {
  530. fbi->dmadesc_palette_cpu->fdadr = fbi->dmadesc_fbhigh_dma;
  531. fbi->dmadesc_fbhigh_cpu->fdadr = fbi->dmadesc_palette_dma;
  532. fbi->fdadr0 = fbi->dmadesc_palette_dma; /* flips back and forth between pal and fbhigh */
  533. }
  534. #if 0
  535. DPRINTK("fbi->dmadesc_fblow_cpu = 0x%p\n", fbi->dmadesc_fblow_cpu);
  536. DPRINTK("fbi->dmadesc_fbhigh_cpu = 0x%p\n", fbi->dmadesc_fbhigh_cpu);
  537. DPRINTK("fbi->dmadesc_palette_cpu = 0x%p\n", fbi->dmadesc_palette_cpu);
  538. DPRINTK("fbi->dmadesc_fblow_dma = 0x%x\n", fbi->dmadesc_fblow_dma);
  539. DPRINTK("fbi->dmadesc_fbhigh_dma = 0x%x\n", fbi->dmadesc_fbhigh_dma);
  540. DPRINTK("fbi->dmadesc_palette_dma = 0x%x\n", fbi->dmadesc_palette_dma);
  541. DPRINTK("fbi->dmadesc_fblow_cpu->fdadr = 0x%x\n", fbi->dmadesc_fblow_cpu->fdadr);
  542. DPRINTK("fbi->dmadesc_fbhigh_cpu->fdadr = 0x%x\n", fbi->dmadesc_fbhigh_cpu->fdadr);
  543. DPRINTK("fbi->dmadesc_palette_cpu->fdadr = 0x%x\n", fbi->dmadesc_palette_cpu->fdadr);
  544. DPRINTK("fbi->dmadesc_fblow_cpu->fsadr = 0x%x\n", fbi->dmadesc_fblow_cpu->fsadr);
  545. DPRINTK("fbi->dmadesc_fbhigh_cpu->fsadr = 0x%x\n", fbi->dmadesc_fbhigh_cpu->fsadr);
  546. DPRINTK("fbi->dmadesc_palette_cpu->fsadr = 0x%x\n", fbi->dmadesc_palette_cpu->fsadr);
  547. DPRINTK("fbi->dmadesc_fblow_cpu->ldcmd = 0x%x\n", fbi->dmadesc_fblow_cpu->ldcmd);
  548. DPRINTK("fbi->dmadesc_fbhigh_cpu->ldcmd = 0x%x\n", fbi->dmadesc_fbhigh_cpu->ldcmd);
  549. DPRINTK("fbi->dmadesc_palette_cpu->ldcmd = 0x%x\n", fbi->dmadesc_palette_cpu->ldcmd);
  550. #endif
  551. fbi->reg_lccr0 = new_regs.lccr0;
  552. fbi->reg_lccr1 = new_regs.lccr1;
  553. fbi->reg_lccr2 = new_regs.lccr2;
  554. fbi->reg_lccr3 = new_regs.lccr3;
  555. local_irq_restore(flags);
  556. /*
  557. * Only update the registers if the controller is enabled
  558. * and something has changed.
  559. */
  560. if ((LCCR0 != fbi->reg_lccr0) || (LCCR1 != fbi->reg_lccr1) ||
  561. (LCCR2 != fbi->reg_lccr2) || (LCCR3 != fbi->reg_lccr3) ||
  562. (FDADR0 != fbi->fdadr0) || (FDADR1 != fbi->fdadr1))
  563. pxafb_schedule_work(fbi, C_REENABLE);
  564. return 0;
  565. }
  566. /*
  567. * NOTE! The following functions are purely helpers for set_ctrlr_state.
  568. * Do not call them directly; set_ctrlr_state does the correct serialisation
  569. * to ensure that things happen in the right way 100% of time time.
  570. * -- rmk
  571. */
  572. static inline void __pxafb_backlight_power(struct pxafb_info *fbi, int on)
  573. {
  574. DPRINTK("backlight o%s\n", on ? "n" : "ff");
  575. if (pxafb_backlight_power)
  576. pxafb_backlight_power(on);
  577. }
  578. static inline void __pxafb_lcd_power(struct pxafb_info *fbi, int on)
  579. {
  580. DPRINTK("LCD power o%s\n", on ? "n" : "ff");
  581. if (pxafb_lcd_power)
  582. pxafb_lcd_power(on);
  583. }
  584. static void pxafb_setup_gpio(struct pxafb_info *fbi)
  585. {
  586. int gpio, ldd_bits;
  587. unsigned int lccr0 = fbi->lccr0;
  588. /*
  589. * setup is based on type of panel supported
  590. */
  591. /* 4 bit interface */
  592. if ((lccr0 & LCCR0_CMS) == LCCR0_Mono &&
  593. (lccr0 & LCCR0_SDS) == LCCR0_Sngl &&
  594. (lccr0 & LCCR0_DPD) == LCCR0_4PixMono)
  595. ldd_bits = 4;
  596. /* 8 bit interface */
  597. else if (((lccr0 & LCCR0_CMS) == LCCR0_Mono &&
  598. ((lccr0 & LCCR0_SDS) == LCCR0_Dual || (lccr0 & LCCR0_DPD) == LCCR0_8PixMono)) ||
  599. ((lccr0 & LCCR0_CMS) == LCCR0_Color &&
  600. (lccr0 & LCCR0_PAS) == LCCR0_Pas && (lccr0 & LCCR0_SDS) == LCCR0_Sngl))
  601. ldd_bits = 8;
  602. /* 16 bit interface */
  603. else if ((lccr0 & LCCR0_CMS) == LCCR0_Color &&
  604. ((lccr0 & LCCR0_SDS) == LCCR0_Dual || (lccr0 & LCCR0_PAS) == LCCR0_Act))
  605. ldd_bits = 16;
  606. else {
  607. printk(KERN_ERR "pxafb_setup_gpio: unable to determine bits per pixel\n");
  608. return;
  609. }
  610. for (gpio = 58; ldd_bits; gpio++, ldd_bits--)
  611. pxa_gpio_mode(gpio | GPIO_ALT_FN_2_OUT);
  612. pxa_gpio_mode(GPIO74_LCD_FCLK_MD);
  613. pxa_gpio_mode(GPIO75_LCD_LCLK_MD);
  614. pxa_gpio_mode(GPIO76_LCD_PCLK_MD);
  615. pxa_gpio_mode(GPIO77_LCD_ACBIAS_MD);
  616. }
  617. static void pxafb_enable_controller(struct pxafb_info *fbi)
  618. {
  619. DPRINTK("Enabling LCD controller\n");
  620. DPRINTK("fdadr0 0x%08x\n", (unsigned int) fbi->fdadr0);
  621. DPRINTK("fdadr1 0x%08x\n", (unsigned int) fbi->fdadr1);
  622. DPRINTK("reg_lccr0 0x%08x\n", (unsigned int) fbi->reg_lccr0);
  623. DPRINTK("reg_lccr1 0x%08x\n", (unsigned int) fbi->reg_lccr1);
  624. DPRINTK("reg_lccr2 0x%08x\n", (unsigned int) fbi->reg_lccr2);
  625. DPRINTK("reg_lccr3 0x%08x\n", (unsigned int) fbi->reg_lccr3);
  626. /* enable LCD controller clock */
  627. pxa_set_cken(CKEN16_LCD, 1);
  628. /* Sequence from 11.7.10 */
  629. LCCR3 = fbi->reg_lccr3;
  630. LCCR2 = fbi->reg_lccr2;
  631. LCCR1 = fbi->reg_lccr1;
  632. LCCR0 = fbi->reg_lccr0 & ~LCCR0_ENB;
  633. FDADR0 = fbi->fdadr0;
  634. FDADR1 = fbi->fdadr1;
  635. LCCR0 |= LCCR0_ENB;
  636. DPRINTK("FDADR0 0x%08x\n", (unsigned int) FDADR0);
  637. DPRINTK("FDADR1 0x%08x\n", (unsigned int) FDADR1);
  638. DPRINTK("LCCR0 0x%08x\n", (unsigned int) LCCR0);
  639. DPRINTK("LCCR1 0x%08x\n", (unsigned int) LCCR1);
  640. DPRINTK("LCCR2 0x%08x\n", (unsigned int) LCCR2);
  641. DPRINTK("LCCR3 0x%08x\n", (unsigned int) LCCR3);
  642. }
  643. static void pxafb_disable_controller(struct pxafb_info *fbi)
  644. {
  645. DECLARE_WAITQUEUE(wait, current);
  646. DPRINTK("Disabling LCD controller\n");
  647. set_current_state(TASK_UNINTERRUPTIBLE);
  648. add_wait_queue(&fbi->ctrlr_wait, &wait);
  649. LCSR = 0xffffffff; /* Clear LCD Status Register */
  650. LCCR0 &= ~LCCR0_LDM; /* Enable LCD Disable Done Interrupt */
  651. LCCR0 |= LCCR0_DIS; /* Disable LCD Controller */
  652. schedule_timeout(20 * HZ / 1000);
  653. remove_wait_queue(&fbi->ctrlr_wait, &wait);
  654. /* disable LCD controller clock */
  655. pxa_set_cken(CKEN16_LCD, 0);
  656. }
  657. /*
  658. * pxafb_handle_irq: Handle 'LCD DONE' interrupts.
  659. */
  660. static irqreturn_t pxafb_handle_irq(int irq, void *dev_id, struct pt_regs *regs)
  661. {
  662. struct pxafb_info *fbi = dev_id;
  663. unsigned int lcsr = LCSR;
  664. if (lcsr & LCSR_LDD) {
  665. LCCR0 |= LCCR0_LDM;
  666. wake_up(&fbi->ctrlr_wait);
  667. }
  668. LCSR = lcsr;
  669. return IRQ_HANDLED;
  670. }
  671. /*
  672. * This function must be called from task context only, since it will
  673. * sleep when disabling the LCD controller, or if we get two contending
  674. * processes trying to alter state.
  675. */
  676. static void set_ctrlr_state(struct pxafb_info *fbi, u_int state)
  677. {
  678. u_int old_state;
  679. down(&fbi->ctrlr_sem);
  680. old_state = fbi->state;
  681. /*
  682. * Hack around fbcon initialisation.
  683. */
  684. if (old_state == C_STARTUP && state == C_REENABLE)
  685. state = C_ENABLE;
  686. switch (state) {
  687. case C_DISABLE_CLKCHANGE:
  688. /*
  689. * Disable controller for clock change. If the
  690. * controller is already disabled, then do nothing.
  691. */
  692. if (old_state != C_DISABLE && old_state != C_DISABLE_PM) {
  693. fbi->state = state;
  694. //TODO __pxafb_lcd_power(fbi, 0);
  695. pxafb_disable_controller(fbi);
  696. }
  697. break;
  698. case C_DISABLE_PM:
  699. case C_DISABLE:
  700. /*
  701. * Disable controller
  702. */
  703. if (old_state != C_DISABLE) {
  704. fbi->state = state;
  705. __pxafb_backlight_power(fbi, 0);
  706. __pxafb_lcd_power(fbi, 0);
  707. if (old_state != C_DISABLE_CLKCHANGE)
  708. pxafb_disable_controller(fbi);
  709. }
  710. break;
  711. case C_ENABLE_CLKCHANGE:
  712. /*
  713. * Enable the controller after clock change. Only
  714. * do this if we were disabled for the clock change.
  715. */
  716. if (old_state == C_DISABLE_CLKCHANGE) {
  717. fbi->state = C_ENABLE;
  718. pxafb_enable_controller(fbi);
  719. //TODO __pxafb_lcd_power(fbi, 1);
  720. }
  721. break;
  722. case C_REENABLE:
  723. /*
  724. * Re-enable the controller only if it was already
  725. * enabled. This is so we reprogram the control
  726. * registers.
  727. */
  728. if (old_state == C_ENABLE) {
  729. pxafb_disable_controller(fbi);
  730. pxafb_setup_gpio(fbi);
  731. pxafb_enable_controller(fbi);
  732. }
  733. break;
  734. case C_ENABLE_PM:
  735. /*
  736. * Re-enable the controller after PM. This is not
  737. * perfect - think about the case where we were doing
  738. * a clock change, and we suspended half-way through.
  739. */
  740. if (old_state != C_DISABLE_PM)
  741. break;
  742. /* fall through */
  743. case C_ENABLE:
  744. /*
  745. * Power up the LCD screen, enable controller, and
  746. * turn on the backlight.
  747. */
  748. if (old_state != C_ENABLE) {
  749. fbi->state = C_ENABLE;
  750. pxafb_setup_gpio(fbi);
  751. pxafb_enable_controller(fbi);
  752. __pxafb_lcd_power(fbi, 1);
  753. __pxafb_backlight_power(fbi, 1);
  754. }
  755. break;
  756. }
  757. up(&fbi->ctrlr_sem);
  758. }
  759. /*
  760. * Our LCD controller task (which is called when we blank or unblank)
  761. * via keventd.
  762. */
  763. static void pxafb_task(void *dummy)
  764. {
  765. struct pxafb_info *fbi = dummy;
  766. u_int state = xchg(&fbi->task_state, -1);
  767. set_ctrlr_state(fbi, state);
  768. }
  769. #ifdef CONFIG_CPU_FREQ
  770. /*
  771. * CPU clock speed change handler. We need to adjust the LCD timing
  772. * parameters when the CPU clock is adjusted by the power management
  773. * subsystem.
  774. *
  775. * TODO: Determine why f->new != 10*get_lclk_frequency_10khz()
  776. */
  777. static int
  778. pxafb_freq_transition(struct notifier_block *nb, unsigned long val, void *data)
  779. {
  780. struct pxafb_info *fbi = TO_INF(nb, freq_transition);
  781. //TODO struct cpufreq_freqs *f = data;
  782. u_int pcd;
  783. switch (val) {
  784. case CPUFREQ_PRECHANGE:
  785. set_ctrlr_state(fbi, C_DISABLE_CLKCHANGE);
  786. break;
  787. case CPUFREQ_POSTCHANGE:
  788. pcd = get_pcd(fbi->fb.var.pixclock);
  789. fbi->reg_lccr3 = (fbi->reg_lccr3 & ~0xff) | LCCR3_PixClkDiv(pcd);
  790. set_ctrlr_state(fbi, C_ENABLE_CLKCHANGE);
  791. break;
  792. }
  793. return 0;
  794. }
  795. static int
  796. pxafb_freq_policy(struct notifier_block *nb, unsigned long val, void *data)
  797. {
  798. struct pxafb_info *fbi = TO_INF(nb, freq_policy);
  799. struct fb_var_screeninfo *var = &fbi->fb.var;
  800. struct cpufreq_policy *policy = data;
  801. switch (val) {
  802. case CPUFREQ_ADJUST:
  803. case CPUFREQ_INCOMPATIBLE:
  804. printk(KERN_DEBUG "min dma period: %d ps, "
  805. "new clock %d kHz\n", pxafb_display_dma_period(var),
  806. policy->max);
  807. // TODO: fill in min/max values
  808. break;
  809. #if 0
  810. case CPUFREQ_NOTIFY:
  811. printk(KERN_ERR "%s: got CPUFREQ_NOTIFY\n", __FUNCTION__);
  812. do {} while(0);
  813. /* todo: panic if min/max values aren't fulfilled
  814. * [can't really happen unless there's a bug in the
  815. * CPU policy verification process *
  816. */
  817. break;
  818. #endif
  819. }
  820. return 0;
  821. }
  822. #endif
  823. #ifdef CONFIG_PM
  824. /*
  825. * Power management hooks. Note that we won't be called from IRQ context,
  826. * unlike the blank functions above, so we may sleep.
  827. */
  828. static int pxafb_suspend(struct device *dev, pm_message_t state, u32 level)
  829. {
  830. struct pxafb_info *fbi = dev_get_drvdata(dev);
  831. if (level == SUSPEND_DISABLE || level == SUSPEND_POWER_DOWN)
  832. set_ctrlr_state(fbi, C_DISABLE_PM);
  833. return 0;
  834. }
  835. static int pxafb_resume(struct device *dev, u32 level)
  836. {
  837. struct pxafb_info *fbi = dev_get_drvdata(dev);
  838. if (level == RESUME_ENABLE)
  839. set_ctrlr_state(fbi, C_ENABLE_PM);
  840. return 0;
  841. }
  842. #else
  843. #define pxafb_suspend NULL
  844. #define pxafb_resume NULL
  845. #endif
  846. /*
  847. * pxafb_map_video_memory():
  848. * Allocates the DRAM memory for the frame buffer. This buffer is
  849. * remapped into a non-cached, non-buffered, memory region to
  850. * allow palette and pixel writes to occur without flushing the
  851. * cache. Once this area is remapped, all virtual memory
  852. * access to the video memory should occur at the new region.
  853. */
  854. static int __init pxafb_map_video_memory(struct pxafb_info *fbi)
  855. {
  856. u_long palette_mem_size;
  857. /*
  858. * We reserve one page for the palette, plus the size
  859. * of the framebuffer.
  860. */
  861. fbi->map_size = PAGE_ALIGN(fbi->fb.fix.smem_len + PAGE_SIZE);
  862. fbi->map_cpu = dma_alloc_writecombine(fbi->dev, fbi->map_size,
  863. &fbi->map_dma, GFP_KERNEL);
  864. if (fbi->map_cpu) {
  865. /* prevent initial garbage on screen */
  866. memset(fbi->map_cpu, 0, fbi->map_size);
  867. fbi->fb.screen_base = fbi->map_cpu + PAGE_SIZE;
  868. fbi->screen_dma = fbi->map_dma + PAGE_SIZE;
  869. /*
  870. * FIXME: this is actually the wrong thing to place in
  871. * smem_start. But fbdev suffers from the problem that
  872. * it needs an API which doesn't exist (in this case,
  873. * dma_writecombine_mmap)
  874. */
  875. fbi->fb.fix.smem_start = fbi->screen_dma;
  876. fbi->palette_size = fbi->fb.var.bits_per_pixel == 8 ? 256 : 16;
  877. palette_mem_size = fbi->palette_size * sizeof(u16);
  878. DPRINTK("palette_mem_size = 0x%08lx\n", (u_long) palette_mem_size);
  879. fbi->palette_cpu = (u16 *)(fbi->map_cpu + PAGE_SIZE - palette_mem_size);
  880. fbi->palette_dma = fbi->map_dma + PAGE_SIZE - palette_mem_size;
  881. }
  882. return fbi->map_cpu ? 0 : -ENOMEM;
  883. }
  884. static struct pxafb_info * __init pxafb_init_fbinfo(struct device *dev)
  885. {
  886. struct pxafb_info *fbi;
  887. void *addr;
  888. struct pxafb_mach_info *inf = dev->platform_data;
  889. /* Alloc the pxafb_info and pseudo_palette in one step */
  890. fbi = kmalloc(sizeof(struct pxafb_info) + sizeof(u32) * 16, GFP_KERNEL);
  891. if (!fbi)
  892. return NULL;
  893. memset(fbi, 0, sizeof(struct pxafb_info));
  894. fbi->dev = dev;
  895. strcpy(fbi->fb.fix.id, PXA_NAME);
  896. fbi->fb.fix.type = FB_TYPE_PACKED_PIXELS;
  897. fbi->fb.fix.type_aux = 0;
  898. fbi->fb.fix.xpanstep = 0;
  899. fbi->fb.fix.ypanstep = 0;
  900. fbi->fb.fix.ywrapstep = 0;
  901. fbi->fb.fix.accel = FB_ACCEL_NONE;
  902. fbi->fb.var.nonstd = 0;
  903. fbi->fb.var.activate = FB_ACTIVATE_NOW;
  904. fbi->fb.var.height = -1;
  905. fbi->fb.var.width = -1;
  906. fbi->fb.var.accel_flags = 0;
  907. fbi->fb.var.vmode = FB_VMODE_NONINTERLACED;
  908. fbi->fb.fbops = &pxafb_ops;
  909. fbi->fb.flags = FBINFO_DEFAULT;
  910. fbi->fb.node = -1;
  911. addr = fbi;
  912. addr = addr + sizeof(struct pxafb_info);
  913. fbi->fb.pseudo_palette = addr;
  914. fbi->max_xres = inf->xres;
  915. fbi->fb.var.xres = inf->xres;
  916. fbi->fb.var.xres_virtual = inf->xres;
  917. fbi->max_yres = inf->yres;
  918. fbi->fb.var.yres = inf->yres;
  919. fbi->fb.var.yres_virtual = inf->yres;
  920. fbi->max_bpp = inf->bpp;
  921. fbi->fb.var.bits_per_pixel = inf->bpp;
  922. fbi->fb.var.pixclock = inf->pixclock;
  923. fbi->fb.var.hsync_len = inf->hsync_len;
  924. fbi->fb.var.left_margin = inf->left_margin;
  925. fbi->fb.var.right_margin = inf->right_margin;
  926. fbi->fb.var.vsync_len = inf->vsync_len;
  927. fbi->fb.var.upper_margin = inf->upper_margin;
  928. fbi->fb.var.lower_margin = inf->lower_margin;
  929. fbi->fb.var.sync = inf->sync;
  930. fbi->fb.var.grayscale = inf->cmap_greyscale;
  931. fbi->cmap_inverse = inf->cmap_inverse;
  932. fbi->cmap_static = inf->cmap_static;
  933. fbi->lccr0 = inf->lccr0;
  934. fbi->lccr3 = inf->lccr3;
  935. fbi->state = C_STARTUP;
  936. fbi->task_state = (u_char)-1;
  937. fbi->fb.fix.smem_len = fbi->max_xres * fbi->max_yres *
  938. fbi->max_bpp / 8;
  939. init_waitqueue_head(&fbi->ctrlr_wait);
  940. INIT_WORK(&fbi->task, pxafb_task, fbi);
  941. init_MUTEX(&fbi->ctrlr_sem);
  942. return fbi;
  943. }
  944. #ifdef CONFIG_FB_PXA_PARAMETERS
  945. static int __init pxafb_parse_options(struct device *dev, char *options)
  946. {
  947. struct pxafb_mach_info *inf = dev->platform_data;
  948. char *this_opt;
  949. if (!options || !*options)
  950. return 0;
  951. dev_dbg(dev, "options are \"%s\"\n", options ? options : "null");
  952. /* could be made table driven or similar?... */
  953. while ((this_opt = strsep(&options, ",")) != NULL) {
  954. if (!strncmp(this_opt, "mode:", 5)) {
  955. const char *name = this_opt+5;
  956. unsigned int namelen = strlen(name);
  957. int res_specified = 0, bpp_specified = 0;
  958. unsigned int xres = 0, yres = 0, bpp = 0;
  959. int yres_specified = 0;
  960. int i;
  961. for (i = namelen-1; i >= 0; i--) {
  962. switch (name[i]) {
  963. case '-':
  964. namelen = i;
  965. if (!bpp_specified && !yres_specified) {
  966. bpp = simple_strtoul(&name[i+1], NULL, 0);
  967. bpp_specified = 1;
  968. } else
  969. goto done;
  970. break;
  971. case 'x':
  972. if (!yres_specified) {
  973. yres = simple_strtoul(&name[i+1], NULL, 0);
  974. yres_specified = 1;
  975. } else
  976. goto done;
  977. break;
  978. case '0'...'9':
  979. break;
  980. default:
  981. goto done;
  982. }
  983. }
  984. if (i < 0 && yres_specified) {
  985. xres = simple_strtoul(name, NULL, 0);
  986. res_specified = 1;
  987. }
  988. done:
  989. if (res_specified) {
  990. dev_info(dev, "overriding resolution: %dx%d\n", xres, yres);
  991. inf->xres = xres; inf->yres = yres;
  992. }
  993. if (bpp_specified)
  994. switch (bpp) {
  995. case 1:
  996. case 2:
  997. case 4:
  998. case 8:
  999. case 16:
  1000. inf->bpp = bpp;
  1001. dev_info(dev, "overriding bit depth: %d\n", bpp);
  1002. break;
  1003. default:
  1004. dev_err(dev, "Depth %d is not valid\n", bpp);
  1005. }
  1006. } else if (!strncmp(this_opt, "pixclock:", 9)) {
  1007. inf->pixclock = simple_strtoul(this_opt+9, NULL, 0);
  1008. dev_info(dev, "override pixclock: %ld\n", inf->pixclock);
  1009. } else if (!strncmp(this_opt, "left:", 5)) {
  1010. inf->left_margin = simple_strtoul(this_opt+5, NULL, 0);
  1011. dev_info(dev, "override left: %u\n", inf->left_margin);
  1012. } else if (!strncmp(this_opt, "right:", 6)) {
  1013. inf->right_margin = simple_strtoul(this_opt+6, NULL, 0);
  1014. dev_info(dev, "override right: %u\n", inf->right_margin);
  1015. } else if (!strncmp(this_opt, "upper:", 6)) {
  1016. inf->upper_margin = simple_strtoul(this_opt+6, NULL, 0);
  1017. dev_info(dev, "override upper: %u\n", inf->upper_margin);
  1018. } else if (!strncmp(this_opt, "lower:", 6)) {
  1019. inf->lower_margin = simple_strtoul(this_opt+6, NULL, 0);
  1020. dev_info(dev, "override lower: %u\n", inf->lower_margin);
  1021. } else if (!strncmp(this_opt, "hsynclen:", 9)) {
  1022. inf->hsync_len = simple_strtoul(this_opt+9, NULL, 0);
  1023. dev_info(dev, "override hsynclen: %u\n", inf->hsync_len);
  1024. } else if (!strncmp(this_opt, "vsynclen:", 9)) {
  1025. inf->vsync_len = simple_strtoul(this_opt+9, NULL, 0);
  1026. dev_info(dev, "override vsynclen: %u\n", inf->vsync_len);
  1027. } else if (!strncmp(this_opt, "hsync:", 6)) {
  1028. if (simple_strtoul(this_opt+6, NULL, 0) == 0) {
  1029. dev_info(dev, "override hsync: Active Low\n");
  1030. inf->sync &= ~FB_SYNC_HOR_HIGH_ACT;
  1031. } else {
  1032. dev_info(dev, "override hsync: Active High\n");
  1033. inf->sync |= FB_SYNC_HOR_HIGH_ACT;
  1034. }
  1035. } else if (!strncmp(this_opt, "vsync:", 6)) {
  1036. if (simple_strtoul(this_opt+6, NULL, 0) == 0) {
  1037. dev_info(dev, "override vsync: Active Low\n");
  1038. inf->sync &= ~FB_SYNC_VERT_HIGH_ACT;
  1039. } else {
  1040. dev_info(dev, "override vsync: Active High\n");
  1041. inf->sync |= FB_SYNC_VERT_HIGH_ACT;
  1042. }
  1043. } else if (!strncmp(this_opt, "dpc:", 4)) {
  1044. if (simple_strtoul(this_opt+4, NULL, 0) == 0) {
  1045. dev_info(dev, "override double pixel clock: false\n");
  1046. inf->lccr3 &= ~LCCR3_DPC;
  1047. } else {
  1048. dev_info(dev, "override double pixel clock: true\n");
  1049. inf->lccr3 |= LCCR3_DPC;
  1050. }
  1051. } else if (!strncmp(this_opt, "outputen:", 9)) {
  1052. if (simple_strtoul(this_opt+9, NULL, 0) == 0) {
  1053. dev_info(dev, "override output enable: active low\n");
  1054. inf->lccr3 = (inf->lccr3 & ~LCCR3_OEP) | LCCR3_OutEnL;
  1055. } else {
  1056. dev_info(dev, "override output enable: active high\n");
  1057. inf->lccr3 = (inf->lccr3 & ~LCCR3_OEP) | LCCR3_OutEnH;
  1058. }
  1059. } else if (!strncmp(this_opt, "pixclockpol:", 12)) {
  1060. if (simple_strtoul(this_opt+12, NULL, 0) == 0) {
  1061. dev_info(dev, "override pixel clock polarity: falling edge\n");
  1062. inf->lccr3 = (inf->lccr3 & ~LCCR3_PCP) | LCCR3_PixFlEdg;
  1063. } else {
  1064. dev_info(dev, "override pixel clock polarity: rising edge\n");
  1065. inf->lccr3 = (inf->lccr3 & ~LCCR3_PCP) | LCCR3_PixRsEdg;
  1066. }
  1067. } else if (!strncmp(this_opt, "color", 5)) {
  1068. inf->lccr0 = (inf->lccr0 & ~LCCR0_CMS) | LCCR0_Color;
  1069. } else if (!strncmp(this_opt, "mono", 4)) {
  1070. inf->lccr0 = (inf->lccr0 & ~LCCR0_CMS) | LCCR0_Mono;
  1071. } else if (!strncmp(this_opt, "active", 6)) {
  1072. inf->lccr0 = (inf->lccr0 & ~LCCR0_PAS) | LCCR0_Act;
  1073. } else if (!strncmp(this_opt, "passive", 7)) {
  1074. inf->lccr0 = (inf->lccr0 & ~LCCR0_PAS) | LCCR0_Pas;
  1075. } else if (!strncmp(this_opt, "single", 6)) {
  1076. inf->lccr0 = (inf->lccr0 & ~LCCR0_SDS) | LCCR0_Sngl;
  1077. } else if (!strncmp(this_opt, "dual", 4)) {
  1078. inf->lccr0 = (inf->lccr0 & ~LCCR0_SDS) | LCCR0_Dual;
  1079. } else if (!strncmp(this_opt, "4pix", 4)) {
  1080. inf->lccr0 = (inf->lccr0 & ~LCCR0_DPD) | LCCR0_4PixMono;
  1081. } else if (!strncmp(this_opt, "8pix", 4)) {
  1082. inf->lccr0 = (inf->lccr0 & ~LCCR0_DPD) | LCCR0_8PixMono;
  1083. } else {
  1084. dev_err(dev, "unknown option: %s\n", this_opt);
  1085. return -EINVAL;
  1086. }
  1087. }
  1088. return 0;
  1089. }
  1090. #endif
  1091. int __init pxafb_probe(struct device *dev)
  1092. {
  1093. struct pxafb_info *fbi;
  1094. struct pxafb_mach_info *inf;
  1095. int ret;
  1096. dev_dbg(dev, "pxafb_probe\n");
  1097. inf = dev->platform_data;
  1098. ret = -ENOMEM;
  1099. fbi = NULL;
  1100. if (!inf)
  1101. goto failed;
  1102. #ifdef CONFIG_FB_PXA_PARAMETERS
  1103. ret = pxafb_parse_options(dev, g_options);
  1104. if (ret < 0)
  1105. goto failed;
  1106. #endif
  1107. #ifdef DEBUG_VAR
  1108. /* Check for various illegal bit-combinations. Currently only
  1109. * a warning is given. */
  1110. if (inf->lccr0 & LCCR0_INVALID_CONFIG_MASK)
  1111. dev_warn(dev, "machine LCCR0 setting contains illegal bits: %08x\n",
  1112. inf->lccr0 & LCCR0_INVALID_CONFIG_MASK);
  1113. if (inf->lccr3 & LCCR3_INVALID_CONFIG_MASK)
  1114. dev_warn(dev, "machine LCCR3 setting contains illegal bits: %08x\n",
  1115. inf->lccr3 & LCCR3_INVALID_CONFIG_MASK);
  1116. if (inf->lccr0 & LCCR0_DPD &&
  1117. ((inf->lccr0 & LCCR0_PAS) != LCCR0_Pas ||
  1118. (inf->lccr0 & LCCR0_SDS) != LCCR0_Sngl ||
  1119. (inf->lccr0 & LCCR0_CMS) != LCCR0_Mono))
  1120. dev_warn(dev, "Double Pixel Data (DPD) mode is only valid in passive mono"
  1121. " single panel mode\n");
  1122. if ((inf->lccr0 & LCCR0_PAS) == LCCR0_Act &&
  1123. (inf->lccr0 & LCCR0_SDS) == LCCR0_Dual)
  1124. dev_warn(dev, "Dual panel only valid in passive mode\n");
  1125. if ((inf->lccr0 & LCCR0_PAS) == LCCR0_Pas &&
  1126. (inf->upper_margin || inf->lower_margin))
  1127. dev_warn(dev, "Upper and lower margins must be 0 in passive mode\n");
  1128. #endif
  1129. dev_dbg(dev, "got a %dx%dx%d LCD\n",inf->xres, inf->yres, inf->bpp);
  1130. if (inf->xres == 0 || inf->yres == 0 || inf->bpp == 0) {
  1131. dev_err(dev, "Invalid resolution or bit depth\n");
  1132. ret = -EINVAL;
  1133. goto failed;
  1134. }
  1135. pxafb_backlight_power = inf->pxafb_backlight_power;
  1136. pxafb_lcd_power = inf->pxafb_lcd_power;
  1137. fbi = pxafb_init_fbinfo(dev);
  1138. if (!fbi) {
  1139. dev_err(dev, "Failed to initialize framebuffer device\n");
  1140. ret = -ENOMEM; // only reason for pxafb_init_fbinfo to fail is kmalloc
  1141. goto failed;
  1142. }
  1143. /* Initialize video memory */
  1144. ret = pxafb_map_video_memory(fbi);
  1145. if (ret) {
  1146. dev_err(dev, "Failed to allocate video RAM: %d\n", ret);
  1147. ret = -ENOMEM;
  1148. goto failed;
  1149. }
  1150. ret = request_irq(IRQ_LCD, pxafb_handle_irq, SA_INTERRUPT, "LCD", fbi);
  1151. if (ret) {
  1152. dev_err(dev, "request_irq failed: %d\n", ret);
  1153. ret = -EBUSY;
  1154. goto failed;
  1155. }
  1156. /*
  1157. * This makes sure that our colour bitfield
  1158. * descriptors are correctly initialised.
  1159. */
  1160. pxafb_check_var(&fbi->fb.var, &fbi->fb);
  1161. pxafb_set_par(&fbi->fb);
  1162. dev_set_drvdata(dev, fbi);
  1163. ret = register_framebuffer(&fbi->fb);
  1164. if (ret < 0) {
  1165. dev_err(dev, "Failed to register framebuffer device: %d\n", ret);
  1166. goto failed;
  1167. }
  1168. #ifdef CONFIG_PM
  1169. // TODO
  1170. #endif
  1171. #ifdef CONFIG_CPU_FREQ
  1172. fbi->freq_transition.notifier_call = pxafb_freq_transition;
  1173. fbi->freq_policy.notifier_call = pxafb_freq_policy;
  1174. cpufreq_register_notifier(&fbi->freq_transition, CPUFREQ_TRANSITION_NOTIFIER);
  1175. cpufreq_register_notifier(&fbi->freq_policy, CPUFREQ_POLICY_NOTIFIER);
  1176. #endif
  1177. /*
  1178. * Ok, now enable the LCD controller
  1179. */
  1180. set_ctrlr_state(fbi, C_ENABLE);
  1181. return 0;
  1182. failed:
  1183. dev_set_drvdata(dev, NULL);
  1184. kfree(fbi);
  1185. return ret;
  1186. }
  1187. static struct device_driver pxafb_driver = {
  1188. .name = "pxa2xx-fb",
  1189. .bus = &platform_bus_type,
  1190. .probe = pxafb_probe,
  1191. #ifdef CONFIG_PM
  1192. .suspend = pxafb_suspend,
  1193. .resume = pxafb_resume,
  1194. #endif
  1195. };
  1196. #ifndef MODULE
  1197. int __devinit pxafb_setup(char *options)
  1198. {
  1199. # ifdef CONFIG_FB_PXA_PARAMETERS
  1200. strlcpy(g_options, options, sizeof(g_options));
  1201. # endif
  1202. return 0;
  1203. }
  1204. #else
  1205. # ifdef CONFIG_FB_PXA_PARAMETERS
  1206. module_param_string(options, g_options, sizeof(g_options), 0);
  1207. MODULE_PARM_DESC(options, "LCD parameters (see Documentation/fb/pxafb.txt)");
  1208. # endif
  1209. #endif
  1210. int __devinit pxafb_init(void)
  1211. {
  1212. #ifndef MODULE
  1213. char *option = NULL;
  1214. if (fb_get_options("pxafb", &option))
  1215. return -ENODEV;
  1216. pxafb_setup(option);
  1217. #endif
  1218. return driver_register(&pxafb_driver);
  1219. }
  1220. module_init(pxafb_init);
  1221. MODULE_DESCRIPTION("loadable framebuffer driver for PXA");
  1222. MODULE_LICENSE("GPL");