pxafb.c 41 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391
  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. /* Sequence from 11.7.10 */
  627. LCCR3 = fbi->reg_lccr3;
  628. LCCR2 = fbi->reg_lccr2;
  629. LCCR1 = fbi->reg_lccr1;
  630. LCCR0 = fbi->reg_lccr0 & ~LCCR0_ENB;
  631. FDADR0 = fbi->fdadr0;
  632. FDADR1 = fbi->fdadr1;
  633. LCCR0 |= LCCR0_ENB;
  634. DPRINTK("FDADR0 0x%08x\n", (unsigned int) FDADR0);
  635. DPRINTK("FDADR1 0x%08x\n", (unsigned int) FDADR1);
  636. DPRINTK("LCCR0 0x%08x\n", (unsigned int) LCCR0);
  637. DPRINTK("LCCR1 0x%08x\n", (unsigned int) LCCR1);
  638. DPRINTK("LCCR2 0x%08x\n", (unsigned int) LCCR2);
  639. DPRINTK("LCCR3 0x%08x\n", (unsigned int) LCCR3);
  640. }
  641. static void pxafb_disable_controller(struct pxafb_info *fbi)
  642. {
  643. DECLARE_WAITQUEUE(wait, current);
  644. DPRINTK("Disabling LCD controller\n");
  645. set_current_state(TASK_UNINTERRUPTIBLE);
  646. add_wait_queue(&fbi->ctrlr_wait, &wait);
  647. LCSR = 0xffffffff; /* Clear LCD Status Register */
  648. LCCR0 &= ~LCCR0_LDM; /* Enable LCD Disable Done Interrupt */
  649. LCCR0 |= LCCR0_DIS; /* Disable LCD Controller */
  650. schedule_timeout(20 * HZ / 1000);
  651. remove_wait_queue(&fbi->ctrlr_wait, &wait);
  652. }
  653. /*
  654. * pxafb_handle_irq: Handle 'LCD DONE' interrupts.
  655. */
  656. static irqreturn_t pxafb_handle_irq(int irq, void *dev_id, struct pt_regs *regs)
  657. {
  658. struct pxafb_info *fbi = dev_id;
  659. unsigned int lcsr = LCSR;
  660. if (lcsr & LCSR_LDD) {
  661. LCCR0 |= LCCR0_LDM;
  662. wake_up(&fbi->ctrlr_wait);
  663. }
  664. LCSR = lcsr;
  665. return IRQ_HANDLED;
  666. }
  667. /*
  668. * This function must be called from task context only, since it will
  669. * sleep when disabling the LCD controller, or if we get two contending
  670. * processes trying to alter state.
  671. */
  672. static void set_ctrlr_state(struct pxafb_info *fbi, u_int state)
  673. {
  674. u_int old_state;
  675. down(&fbi->ctrlr_sem);
  676. old_state = fbi->state;
  677. /*
  678. * Hack around fbcon initialisation.
  679. */
  680. if (old_state == C_STARTUP && state == C_REENABLE)
  681. state = C_ENABLE;
  682. switch (state) {
  683. case C_DISABLE_CLKCHANGE:
  684. /*
  685. * Disable controller for clock change. If the
  686. * controller is already disabled, then do nothing.
  687. */
  688. if (old_state != C_DISABLE && old_state != C_DISABLE_PM) {
  689. fbi->state = state;
  690. //TODO __pxafb_lcd_power(fbi, 0);
  691. pxafb_disable_controller(fbi);
  692. }
  693. break;
  694. case C_DISABLE_PM:
  695. case C_DISABLE:
  696. /*
  697. * Disable controller
  698. */
  699. if (old_state != C_DISABLE) {
  700. fbi->state = state;
  701. __pxafb_backlight_power(fbi, 0);
  702. __pxafb_lcd_power(fbi, 0);
  703. if (old_state != C_DISABLE_CLKCHANGE)
  704. pxafb_disable_controller(fbi);
  705. }
  706. break;
  707. case C_ENABLE_CLKCHANGE:
  708. /*
  709. * Enable the controller after clock change. Only
  710. * do this if we were disabled for the clock change.
  711. */
  712. if (old_state == C_DISABLE_CLKCHANGE) {
  713. fbi->state = C_ENABLE;
  714. pxafb_enable_controller(fbi);
  715. //TODO __pxafb_lcd_power(fbi, 1);
  716. }
  717. break;
  718. case C_REENABLE:
  719. /*
  720. * Re-enable the controller only if it was already
  721. * enabled. This is so we reprogram the control
  722. * registers.
  723. */
  724. if (old_state == C_ENABLE) {
  725. pxafb_disable_controller(fbi);
  726. pxafb_setup_gpio(fbi);
  727. pxafb_enable_controller(fbi);
  728. }
  729. break;
  730. case C_ENABLE_PM:
  731. /*
  732. * Re-enable the controller after PM. This is not
  733. * perfect - think about the case where we were doing
  734. * a clock change, and we suspended half-way through.
  735. */
  736. if (old_state != C_DISABLE_PM)
  737. break;
  738. /* fall through */
  739. case C_ENABLE:
  740. /*
  741. * Power up the LCD screen, enable controller, and
  742. * turn on the backlight.
  743. */
  744. if (old_state != C_ENABLE) {
  745. fbi->state = C_ENABLE;
  746. pxafb_setup_gpio(fbi);
  747. pxafb_enable_controller(fbi);
  748. __pxafb_lcd_power(fbi, 1);
  749. __pxafb_backlight_power(fbi, 1);
  750. }
  751. break;
  752. }
  753. up(&fbi->ctrlr_sem);
  754. }
  755. /*
  756. * Our LCD controller task (which is called when we blank or unblank)
  757. * via keventd.
  758. */
  759. static void pxafb_task(void *dummy)
  760. {
  761. struct pxafb_info *fbi = dummy;
  762. u_int state = xchg(&fbi->task_state, -1);
  763. set_ctrlr_state(fbi, state);
  764. }
  765. #ifdef CONFIG_CPU_FREQ
  766. /*
  767. * CPU clock speed change handler. We need to adjust the LCD timing
  768. * parameters when the CPU clock is adjusted by the power management
  769. * subsystem.
  770. *
  771. * TODO: Determine why f->new != 10*get_lclk_frequency_10khz()
  772. */
  773. static int
  774. pxafb_freq_transition(struct notifier_block *nb, unsigned long val, void *data)
  775. {
  776. struct pxafb_info *fbi = TO_INF(nb, freq_transition);
  777. //TODO struct cpufreq_freqs *f = data;
  778. u_int pcd;
  779. switch (val) {
  780. case CPUFREQ_PRECHANGE:
  781. set_ctrlr_state(fbi, C_DISABLE_CLKCHANGE);
  782. break;
  783. case CPUFREQ_POSTCHANGE:
  784. pcd = get_pcd(fbi->fb.var.pixclock);
  785. fbi->reg_lccr3 = (fbi->reg_lccr3 & ~0xff) | LCCR3_PixClkDiv(pcd);
  786. set_ctrlr_state(fbi, C_ENABLE_CLKCHANGE);
  787. break;
  788. }
  789. return 0;
  790. }
  791. static int
  792. pxafb_freq_policy(struct notifier_block *nb, unsigned long val, void *data)
  793. {
  794. struct pxafb_info *fbi = TO_INF(nb, freq_policy);
  795. struct fb_var_screeninfo *var = &fbi->fb.var;
  796. struct cpufreq_policy *policy = data;
  797. switch (val) {
  798. case CPUFREQ_ADJUST:
  799. case CPUFREQ_INCOMPATIBLE:
  800. printk(KERN_DEBUG "min dma period: %d ps, "
  801. "new clock %d kHz\n", pxafb_display_dma_period(var),
  802. policy->max);
  803. // TODO: fill in min/max values
  804. break;
  805. #if 0
  806. case CPUFREQ_NOTIFY:
  807. printk(KERN_ERR "%s: got CPUFREQ_NOTIFY\n", __FUNCTION__);
  808. do {} while(0);
  809. /* todo: panic if min/max values aren't fulfilled
  810. * [can't really happen unless there's a bug in the
  811. * CPU policy verification process *
  812. */
  813. break;
  814. #endif
  815. }
  816. return 0;
  817. }
  818. #endif
  819. #ifdef CONFIG_PM
  820. /*
  821. * Power management hooks. Note that we won't be called from IRQ context,
  822. * unlike the blank functions above, so we may sleep.
  823. */
  824. static int pxafb_suspend(struct device *dev, pm_message_t state, u32 level)
  825. {
  826. struct pxafb_info *fbi = dev_get_drvdata(dev);
  827. if (level == SUSPEND_DISABLE || level == SUSPEND_POWER_DOWN)
  828. set_ctrlr_state(fbi, C_DISABLE_PM);
  829. return 0;
  830. }
  831. static int pxafb_resume(struct device *dev, u32 level)
  832. {
  833. struct pxafb_info *fbi = dev_get_drvdata(dev);
  834. if (level == RESUME_ENABLE)
  835. set_ctrlr_state(fbi, C_ENABLE_PM);
  836. return 0;
  837. }
  838. #else
  839. #define pxafb_suspend NULL
  840. #define pxafb_resume NULL
  841. #endif
  842. /*
  843. * pxafb_map_video_memory():
  844. * Allocates the DRAM memory for the frame buffer. This buffer is
  845. * remapped into a non-cached, non-buffered, memory region to
  846. * allow palette and pixel writes to occur without flushing the
  847. * cache. Once this area is remapped, all virtual memory
  848. * access to the video memory should occur at the new region.
  849. */
  850. static int __init pxafb_map_video_memory(struct pxafb_info *fbi)
  851. {
  852. u_long palette_mem_size;
  853. /*
  854. * We reserve one page for the palette, plus the size
  855. * of the framebuffer.
  856. */
  857. fbi->map_size = PAGE_ALIGN(fbi->fb.fix.smem_len + PAGE_SIZE);
  858. fbi->map_cpu = dma_alloc_writecombine(fbi->dev, fbi->map_size,
  859. &fbi->map_dma, GFP_KERNEL);
  860. if (fbi->map_cpu) {
  861. /* prevent initial garbage on screen */
  862. memset(fbi->map_cpu, 0, fbi->map_size);
  863. fbi->fb.screen_base = fbi->map_cpu + PAGE_SIZE;
  864. fbi->screen_dma = fbi->map_dma + PAGE_SIZE;
  865. /*
  866. * FIXME: this is actually the wrong thing to place in
  867. * smem_start. But fbdev suffers from the problem that
  868. * it needs an API which doesn't exist (in this case,
  869. * dma_writecombine_mmap)
  870. */
  871. fbi->fb.fix.smem_start = fbi->screen_dma;
  872. fbi->palette_size = fbi->fb.var.bits_per_pixel == 8 ? 256 : 16;
  873. palette_mem_size = fbi->palette_size * sizeof(u16);
  874. DPRINTK("palette_mem_size = 0x%08lx\n", (u_long) palette_mem_size);
  875. fbi->palette_cpu = (u16 *)(fbi->map_cpu + PAGE_SIZE - palette_mem_size);
  876. fbi->palette_dma = fbi->map_dma + PAGE_SIZE - palette_mem_size;
  877. }
  878. return fbi->map_cpu ? 0 : -ENOMEM;
  879. }
  880. static struct pxafb_info * __init pxafb_init_fbinfo(struct device *dev)
  881. {
  882. struct pxafb_info *fbi;
  883. void *addr;
  884. struct pxafb_mach_info *inf = dev->platform_data;
  885. /* Alloc the pxafb_info and pseudo_palette in one step */
  886. fbi = kmalloc(sizeof(struct pxafb_info) + sizeof(u32) * 16, GFP_KERNEL);
  887. if (!fbi)
  888. return NULL;
  889. memset(fbi, 0, sizeof(struct pxafb_info));
  890. fbi->dev = dev;
  891. strcpy(fbi->fb.fix.id, PXA_NAME);
  892. fbi->fb.fix.type = FB_TYPE_PACKED_PIXELS;
  893. fbi->fb.fix.type_aux = 0;
  894. fbi->fb.fix.xpanstep = 0;
  895. fbi->fb.fix.ypanstep = 0;
  896. fbi->fb.fix.ywrapstep = 0;
  897. fbi->fb.fix.accel = FB_ACCEL_NONE;
  898. fbi->fb.var.nonstd = 0;
  899. fbi->fb.var.activate = FB_ACTIVATE_NOW;
  900. fbi->fb.var.height = -1;
  901. fbi->fb.var.width = -1;
  902. fbi->fb.var.accel_flags = 0;
  903. fbi->fb.var.vmode = FB_VMODE_NONINTERLACED;
  904. fbi->fb.fbops = &pxafb_ops;
  905. fbi->fb.flags = FBINFO_DEFAULT;
  906. fbi->fb.node = -1;
  907. addr = fbi;
  908. addr = addr + sizeof(struct pxafb_info);
  909. fbi->fb.pseudo_palette = addr;
  910. fbi->max_xres = inf->xres;
  911. fbi->fb.var.xres = inf->xres;
  912. fbi->fb.var.xres_virtual = inf->xres;
  913. fbi->max_yres = inf->yres;
  914. fbi->fb.var.yres = inf->yres;
  915. fbi->fb.var.yres_virtual = inf->yres;
  916. fbi->max_bpp = inf->bpp;
  917. fbi->fb.var.bits_per_pixel = inf->bpp;
  918. fbi->fb.var.pixclock = inf->pixclock;
  919. fbi->fb.var.hsync_len = inf->hsync_len;
  920. fbi->fb.var.left_margin = inf->left_margin;
  921. fbi->fb.var.right_margin = inf->right_margin;
  922. fbi->fb.var.vsync_len = inf->vsync_len;
  923. fbi->fb.var.upper_margin = inf->upper_margin;
  924. fbi->fb.var.lower_margin = inf->lower_margin;
  925. fbi->fb.var.sync = inf->sync;
  926. fbi->fb.var.grayscale = inf->cmap_greyscale;
  927. fbi->cmap_inverse = inf->cmap_inverse;
  928. fbi->cmap_static = inf->cmap_static;
  929. fbi->lccr0 = inf->lccr0;
  930. fbi->lccr3 = inf->lccr3;
  931. fbi->state = C_STARTUP;
  932. fbi->task_state = (u_char)-1;
  933. fbi->fb.fix.smem_len = fbi->max_xres * fbi->max_yres *
  934. fbi->max_bpp / 8;
  935. init_waitqueue_head(&fbi->ctrlr_wait);
  936. INIT_WORK(&fbi->task, pxafb_task, fbi);
  937. init_MUTEX(&fbi->ctrlr_sem);
  938. return fbi;
  939. }
  940. #ifdef CONFIG_FB_PXA_PARAMETERS
  941. static int __init pxafb_parse_options(struct device *dev, char *options)
  942. {
  943. struct pxafb_mach_info *inf = dev->platform_data;
  944. char *this_opt;
  945. if (!options || !*options)
  946. return 0;
  947. dev_dbg(dev, "options are \"%s\"\n", options ? options : "null");
  948. /* could be made table driven or similar?... */
  949. while ((this_opt = strsep(&options, ",")) != NULL) {
  950. if (!strncmp(this_opt, "mode:", 5)) {
  951. const char *name = this_opt+5;
  952. unsigned int namelen = strlen(name);
  953. int res_specified = 0, bpp_specified = 0;
  954. unsigned int xres = 0, yres = 0, bpp = 0;
  955. int yres_specified = 0;
  956. int i;
  957. for (i = namelen-1; i >= 0; i--) {
  958. switch (name[i]) {
  959. case '-':
  960. namelen = i;
  961. if (!bpp_specified && !yres_specified) {
  962. bpp = simple_strtoul(&name[i+1], NULL, 0);
  963. bpp_specified = 1;
  964. } else
  965. goto done;
  966. break;
  967. case 'x':
  968. if (!yres_specified) {
  969. yres = simple_strtoul(&name[i+1], NULL, 0);
  970. yres_specified = 1;
  971. } else
  972. goto done;
  973. break;
  974. case '0'...'9':
  975. break;
  976. default:
  977. goto done;
  978. }
  979. }
  980. if (i < 0 && yres_specified) {
  981. xres = simple_strtoul(name, NULL, 0);
  982. res_specified = 1;
  983. }
  984. done:
  985. if (res_specified) {
  986. dev_info(dev, "overriding resolution: %dx%d\n", xres, yres);
  987. inf->xres = xres; inf->yres = yres;
  988. }
  989. if (bpp_specified)
  990. switch (bpp) {
  991. case 1:
  992. case 2:
  993. case 4:
  994. case 8:
  995. case 16:
  996. inf->bpp = bpp;
  997. dev_info(dev, "overriding bit depth: %d\n", bpp);
  998. break;
  999. default:
  1000. dev_err(dev, "Depth %d is not valid\n", bpp);
  1001. }
  1002. } else if (!strncmp(this_opt, "pixclock:", 9)) {
  1003. inf->pixclock = simple_strtoul(this_opt+9, NULL, 0);
  1004. dev_info(dev, "override pixclock: %ld\n", inf->pixclock);
  1005. } else if (!strncmp(this_opt, "left:", 5)) {
  1006. inf->left_margin = simple_strtoul(this_opt+5, NULL, 0);
  1007. dev_info(dev, "override left: %u\n", inf->left_margin);
  1008. } else if (!strncmp(this_opt, "right:", 6)) {
  1009. inf->right_margin = simple_strtoul(this_opt+6, NULL, 0);
  1010. dev_info(dev, "override right: %u\n", inf->right_margin);
  1011. } else if (!strncmp(this_opt, "upper:", 6)) {
  1012. inf->upper_margin = simple_strtoul(this_opt+6, NULL, 0);
  1013. dev_info(dev, "override upper: %u\n", inf->upper_margin);
  1014. } else if (!strncmp(this_opt, "lower:", 6)) {
  1015. inf->lower_margin = simple_strtoul(this_opt+6, NULL, 0);
  1016. dev_info(dev, "override lower: %u\n", inf->lower_margin);
  1017. } else if (!strncmp(this_opt, "hsynclen:", 9)) {
  1018. inf->hsync_len = simple_strtoul(this_opt+9, NULL, 0);
  1019. dev_info(dev, "override hsynclen: %u\n", inf->hsync_len);
  1020. } else if (!strncmp(this_opt, "vsynclen:", 9)) {
  1021. inf->vsync_len = simple_strtoul(this_opt+9, NULL, 0);
  1022. dev_info(dev, "override vsynclen: %u\n", inf->vsync_len);
  1023. } else if (!strncmp(this_opt, "hsync:", 6)) {
  1024. if (simple_strtoul(this_opt+6, NULL, 0) == 0) {
  1025. dev_info(dev, "override hsync: Active Low\n");
  1026. inf->sync &= ~FB_SYNC_HOR_HIGH_ACT;
  1027. } else {
  1028. dev_info(dev, "override hsync: Active High\n");
  1029. inf->sync |= FB_SYNC_HOR_HIGH_ACT;
  1030. }
  1031. } else if (!strncmp(this_opt, "vsync:", 6)) {
  1032. if (simple_strtoul(this_opt+6, NULL, 0) == 0) {
  1033. dev_info(dev, "override vsync: Active Low\n");
  1034. inf->sync &= ~FB_SYNC_VERT_HIGH_ACT;
  1035. } else {
  1036. dev_info(dev, "override vsync: Active High\n");
  1037. inf->sync |= FB_SYNC_VERT_HIGH_ACT;
  1038. }
  1039. } else if (!strncmp(this_opt, "dpc:", 4)) {
  1040. if (simple_strtoul(this_opt+4, NULL, 0) == 0) {
  1041. dev_info(dev, "override double pixel clock: false\n");
  1042. inf->lccr3 &= ~LCCR3_DPC;
  1043. } else {
  1044. dev_info(dev, "override double pixel clock: true\n");
  1045. inf->lccr3 |= LCCR3_DPC;
  1046. }
  1047. } else if (!strncmp(this_opt, "outputen:", 9)) {
  1048. if (simple_strtoul(this_opt+9, NULL, 0) == 0) {
  1049. dev_info(dev, "override output enable: active low\n");
  1050. inf->lccr3 = (inf->lccr3 & ~LCCR3_OEP) | LCCR3_OutEnL;
  1051. } else {
  1052. dev_info(dev, "override output enable: active high\n");
  1053. inf->lccr3 = (inf->lccr3 & ~LCCR3_OEP) | LCCR3_OutEnH;
  1054. }
  1055. } else if (!strncmp(this_opt, "pixclockpol:", 12)) {
  1056. if (simple_strtoul(this_opt+12, NULL, 0) == 0) {
  1057. dev_info(dev, "override pixel clock polarity: falling edge\n");
  1058. inf->lccr3 = (inf->lccr3 & ~LCCR3_PCP) | LCCR3_PixFlEdg;
  1059. } else {
  1060. dev_info(dev, "override pixel clock polarity: rising edge\n");
  1061. inf->lccr3 = (inf->lccr3 & ~LCCR3_PCP) | LCCR3_PixRsEdg;
  1062. }
  1063. } else if (!strncmp(this_opt, "color", 5)) {
  1064. inf->lccr0 = (inf->lccr0 & ~LCCR0_CMS) | LCCR0_Color;
  1065. } else if (!strncmp(this_opt, "mono", 4)) {
  1066. inf->lccr0 = (inf->lccr0 & ~LCCR0_CMS) | LCCR0_Mono;
  1067. } else if (!strncmp(this_opt, "active", 6)) {
  1068. inf->lccr0 = (inf->lccr0 & ~LCCR0_PAS) | LCCR0_Act;
  1069. } else if (!strncmp(this_opt, "passive", 7)) {
  1070. inf->lccr0 = (inf->lccr0 & ~LCCR0_PAS) | LCCR0_Pas;
  1071. } else if (!strncmp(this_opt, "single", 6)) {
  1072. inf->lccr0 = (inf->lccr0 & ~LCCR0_SDS) | LCCR0_Sngl;
  1073. } else if (!strncmp(this_opt, "dual", 4)) {
  1074. inf->lccr0 = (inf->lccr0 & ~LCCR0_SDS) | LCCR0_Dual;
  1075. } else if (!strncmp(this_opt, "4pix", 4)) {
  1076. inf->lccr0 = (inf->lccr0 & ~LCCR0_DPD) | LCCR0_4PixMono;
  1077. } else if (!strncmp(this_opt, "8pix", 4)) {
  1078. inf->lccr0 = (inf->lccr0 & ~LCCR0_DPD) | LCCR0_8PixMono;
  1079. } else {
  1080. dev_err(dev, "unknown option: %s\n", this_opt);
  1081. return -EINVAL;
  1082. }
  1083. }
  1084. return 0;
  1085. }
  1086. #endif
  1087. int __init pxafb_probe(struct device *dev)
  1088. {
  1089. struct pxafb_info *fbi;
  1090. struct pxafb_mach_info *inf;
  1091. int ret;
  1092. dev_dbg(dev, "pxafb_probe\n");
  1093. inf = dev->platform_data;
  1094. ret = -ENOMEM;
  1095. fbi = NULL;
  1096. if (!inf)
  1097. goto failed;
  1098. #ifdef CONFIG_FB_PXA_PARAMETERS
  1099. ret = pxafb_parse_options(dev, g_options);
  1100. if (ret < 0)
  1101. goto failed;
  1102. #endif
  1103. #ifdef DEBUG_VAR
  1104. /* Check for various illegal bit-combinations. Currently only
  1105. * a warning is given. */
  1106. if (inf->lccr0 & LCCR0_INVALID_CONFIG_MASK)
  1107. dev_warn(dev, "machine LCCR0 setting contains illegal bits: %08x\n",
  1108. inf->lccr0 & LCCR0_INVALID_CONFIG_MASK);
  1109. if (inf->lccr3 & LCCR3_INVALID_CONFIG_MASK)
  1110. dev_warn(dev, "machine LCCR3 setting contains illegal bits: %08x\n",
  1111. inf->lccr3 & LCCR3_INVALID_CONFIG_MASK);
  1112. if (inf->lccr0 & LCCR0_DPD &&
  1113. ((inf->lccr0 & LCCR0_PAS) != LCCR0_Pas ||
  1114. (inf->lccr0 & LCCR0_SDS) != LCCR0_Sngl ||
  1115. (inf->lccr0 & LCCR0_CMS) != LCCR0_Mono))
  1116. dev_warn(dev, "Double Pixel Data (DPD) mode is only valid in passive mono"
  1117. " single panel mode\n");
  1118. if ((inf->lccr0 & LCCR0_PAS) == LCCR0_Act &&
  1119. (inf->lccr0 & LCCR0_SDS) == LCCR0_Dual)
  1120. dev_warn(dev, "Dual panel only valid in passive mode\n");
  1121. if ((inf->lccr0 & LCCR0_PAS) == LCCR0_Pas &&
  1122. (inf->upper_margin || inf->lower_margin))
  1123. dev_warn(dev, "Upper and lower margins must be 0 in passive mode\n");
  1124. #endif
  1125. dev_dbg(dev, "got a %dx%dx%d LCD\n",inf->xres, inf->yres, inf->bpp);
  1126. if (inf->xres == 0 || inf->yres == 0 || inf->bpp == 0) {
  1127. dev_err(dev, "Invalid resolution or bit depth\n");
  1128. ret = -EINVAL;
  1129. goto failed;
  1130. }
  1131. pxafb_backlight_power = inf->pxafb_backlight_power;
  1132. pxafb_lcd_power = inf->pxafb_lcd_power;
  1133. fbi = pxafb_init_fbinfo(dev);
  1134. if (!fbi) {
  1135. dev_err(dev, "Failed to initialize framebuffer device\n");
  1136. ret = -ENOMEM; // only reason for pxafb_init_fbinfo to fail is kmalloc
  1137. goto failed;
  1138. }
  1139. /* Initialize video memory */
  1140. ret = pxafb_map_video_memory(fbi);
  1141. if (ret) {
  1142. dev_err(dev, "Failed to allocate video RAM: %d\n", ret);
  1143. ret = -ENOMEM;
  1144. goto failed;
  1145. }
  1146. /* enable LCD controller clock */
  1147. pxa_set_cken(CKEN16_LCD, 1);
  1148. ret = request_irq(IRQ_LCD, pxafb_handle_irq, SA_INTERRUPT, "LCD", fbi);
  1149. if (ret) {
  1150. dev_err(dev, "request_irq failed: %d\n", ret);
  1151. ret = -EBUSY;
  1152. goto failed;
  1153. }
  1154. /*
  1155. * This makes sure that our colour bitfield
  1156. * descriptors are correctly initialised.
  1157. */
  1158. pxafb_check_var(&fbi->fb.var, &fbi->fb);
  1159. pxafb_set_par(&fbi->fb);
  1160. dev_set_drvdata(dev, fbi);
  1161. ret = register_framebuffer(&fbi->fb);
  1162. if (ret < 0) {
  1163. dev_err(dev, "Failed to register framebuffer device: %d\n", ret);
  1164. goto failed;
  1165. }
  1166. #ifdef CONFIG_PM
  1167. // TODO
  1168. #endif
  1169. #ifdef CONFIG_CPU_FREQ
  1170. fbi->freq_transition.notifier_call = pxafb_freq_transition;
  1171. fbi->freq_policy.notifier_call = pxafb_freq_policy;
  1172. cpufreq_register_notifier(&fbi->freq_transition, CPUFREQ_TRANSITION_NOTIFIER);
  1173. cpufreq_register_notifier(&fbi->freq_policy, CPUFREQ_POLICY_NOTIFIER);
  1174. #endif
  1175. /*
  1176. * Ok, now enable the LCD controller
  1177. */
  1178. set_ctrlr_state(fbi, C_ENABLE);
  1179. return 0;
  1180. failed:
  1181. dev_set_drvdata(dev, NULL);
  1182. kfree(fbi);
  1183. return ret;
  1184. }
  1185. static struct device_driver pxafb_driver = {
  1186. .name = "pxa2xx-fb",
  1187. .bus = &platform_bus_type,
  1188. .probe = pxafb_probe,
  1189. #ifdef CONFIG_PM
  1190. .suspend = pxafb_suspend,
  1191. .resume = pxafb_resume,
  1192. #endif
  1193. };
  1194. #ifndef MODULE
  1195. int __devinit pxafb_setup(char *options)
  1196. {
  1197. # ifdef CONFIG_FB_PXA_PARAMETERS
  1198. strlcpy(g_options, options, sizeof(g_options));
  1199. # endif
  1200. return 0;
  1201. }
  1202. #else
  1203. # ifdef CONFIG_FB_PXA_PARAMETERS
  1204. module_param_string(options, g_options, sizeof(g_options), 0);
  1205. MODULE_PARM_DESC(options, "LCD parameters (see Documentation/fb/pxafb.txt)");
  1206. # endif
  1207. #endif
  1208. int __devinit pxafb_init(void)
  1209. {
  1210. #ifndef MODULE
  1211. char *option = NULL;
  1212. if (fb_get_options("pxafb", &option))
  1213. return -ENODEV;
  1214. pxafb_setup(option);
  1215. #endif
  1216. return driver_register(&pxafb_driver);
  1217. }
  1218. module_init(pxafb_init);
  1219. MODULE_DESCRIPTION("loadable framebuffer driver for PXA");
  1220. MODULE_LICENSE("GPL");