2 * linux/drivers/video/pxafb.c
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
10 * Based on acornfb.c Copyright (C) Russell King.
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
16 * Intel PXA250/210 LCD Controller Frame Buffer Driver
18 * Please direct your questions and comments on this driver to the following
21 * linux-arm-kernel@lists.arm.linux.org.uk
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>
34 #include <linux/delay.h>
35 #include <linux/init.h>
36 #include <linux/ioport.h>
37 #include <linux/cpufreq.h>
38 #include <linux/platform_device.h>
39 #include <linux/dma-mapping.h>
40 #include <linux/clk.h>
41 #include <linux/err.h>
43 #include <asm/hardware.h>
46 #include <asm/div64.h>
47 #include <asm/arch/pxa-regs.h>
48 #include <asm/arch/pxa2xx-gpio.h>
49 #include <asm/arch/bitfield.h>
50 #include <asm/arch/pxafb.h>
53 * Complain if VAR is out of range.
59 /* Bits which should not be set in machine configuration structures */
60 #define LCCR0_INVALID_CONFIG_MASK (LCCR0_OUM | LCCR0_BM | LCCR0_QDM |\
61 LCCR0_DIS | LCCR0_EFM | LCCR0_IUM |\
62 LCCR0_SFM | LCCR0_LDM | LCCR0_ENB)
64 #define LCCR3_INVALID_CONFIG_MASK (LCCR3_HSP | LCCR3_VSP |\
65 LCCR3_PCD | LCCR3_BPP)
67 static void (*pxafb_backlight_power)(int);
68 static void (*pxafb_lcd_power)(int, struct fb_var_screeninfo *);
70 static int pxafb_activate_var(struct fb_var_screeninfo *var,
72 static void set_ctrlr_state(struct pxafb_info *fbi, u_int state);
74 #ifdef CONFIG_FB_PXA_PARAMETERS
75 #define PXAFB_OPTIONS_SIZE 256
76 static char g_options[PXAFB_OPTIONS_SIZE] __devinitdata = "";
79 static inline void pxafb_schedule_work(struct pxafb_info *fbi, u_int state)
83 local_irq_save(flags);
85 * We need to handle two requests being made at the same time.
86 * There are two important cases:
87 * 1. When we are changing VT (C_REENABLE) while unblanking
88 * (C_ENABLE) We must perform the unblanking, which will
89 * do our REENABLE for us.
90 * 2. When we are blanking, but immediately unblank before
91 * we have blanked. We do the "REENABLE" thing here as
92 * well, just to be sure.
94 if (fbi->task_state == C_ENABLE && state == C_REENABLE)
96 if (fbi->task_state == C_DISABLE && state == C_ENABLE)
99 if (state != (u_int)-1) {
100 fbi->task_state = state;
101 schedule_work(&fbi->task);
103 local_irq_restore(flags);
106 static inline u_int chan_to_field(u_int chan, struct fb_bitfield *bf)
109 chan >>= 16 - bf->length;
110 return chan << bf->offset;
114 pxafb_setpalettereg(u_int regno, u_int red, u_int green, u_int blue,
115 u_int trans, struct fb_info *info)
117 struct pxafb_info *fbi = (struct pxafb_info *)info;
120 if (regno >= fbi->palette_size)
123 if (fbi->fb.var.grayscale) {
124 fbi->palette_cpu[regno] = ((blue >> 8) & 0x00ff);
128 switch (fbi->lccr4 & LCCR4_PAL_FOR_MASK) {
129 case LCCR4_PAL_FOR_0:
130 val = ((red >> 0) & 0xf800);
131 val |= ((green >> 5) & 0x07e0);
132 val |= ((blue >> 11) & 0x001f);
133 fbi->palette_cpu[regno] = val;
135 case LCCR4_PAL_FOR_1:
136 val = ((red << 8) & 0x00f80000);
137 val |= ((green >> 0) & 0x0000fc00);
138 val |= ((blue >> 8) & 0x000000f8);
139 ((u32 *)(fbi->palette_cpu))[regno] = val;
141 case LCCR4_PAL_FOR_2:
142 val = ((red << 8) & 0x00fc0000);
143 val |= ((green >> 0) & 0x0000fc00);
144 val |= ((blue >> 8) & 0x000000fc);
145 ((u32 *)(fbi->palette_cpu))[regno] = val;
153 pxafb_setcolreg(u_int regno, u_int red, u_int green, u_int blue,
154 u_int trans, struct fb_info *info)
156 struct pxafb_info *fbi = (struct pxafb_info *)info;
161 * If inverse mode was selected, invert all the colours
162 * rather than the register number. The register number
163 * is what you poke into the framebuffer to produce the
164 * colour you requested.
166 if (fbi->cmap_inverse) {
168 green = 0xffff - green;
169 blue = 0xffff - blue;
173 * If greyscale is true, then we convert the RGB value
174 * to greyscale no matter what visual we are using.
176 if (fbi->fb.var.grayscale)
177 red = green = blue = (19595 * red + 38470 * green +
180 switch (fbi->fb.fix.visual) {
181 case FB_VISUAL_TRUECOLOR:
183 * 16-bit True Colour. We encode the RGB value
184 * according to the RGB bitfield information.
187 u32 *pal = fbi->fb.pseudo_palette;
189 val = chan_to_field(red, &fbi->fb.var.red);
190 val |= chan_to_field(green, &fbi->fb.var.green);
191 val |= chan_to_field(blue, &fbi->fb.var.blue);
198 case FB_VISUAL_STATIC_PSEUDOCOLOR:
199 case FB_VISUAL_PSEUDOCOLOR:
200 ret = pxafb_setpalettereg(regno, red, green, blue, trans, info);
208 * pxafb_bpp_to_lccr3():
209 * Convert a bits per pixel value to the correct bit pattern for LCCR3
211 static int pxafb_bpp_to_lccr3(struct fb_var_screeninfo *var)
214 switch (var->bits_per_pixel) {
215 case 1: ret = LCCR3_1BPP; break;
216 case 2: ret = LCCR3_2BPP; break;
217 case 4: ret = LCCR3_4BPP; break;
218 case 8: ret = LCCR3_8BPP; break;
219 case 16: ret = LCCR3_16BPP; break;
224 #ifdef CONFIG_CPU_FREQ
226 * pxafb_display_dma_period()
227 * Calculate the minimum period (in picoseconds) between two DMA
228 * requests for the LCD controller. If we hit this, it means we're
229 * doing nothing but LCD DMA.
231 static unsigned int pxafb_display_dma_period(struct fb_var_screeninfo *var)
234 * Period = pixclock * bits_per_byte * bytes_per_transfer
235 * / memory_bits_per_pixel;
237 return var->pixclock * 8 * 16 / var->bits_per_pixel;
242 * Select the smallest mode that allows the desired resolution to be
243 * displayed. If desired parameters can be rounded up.
245 static struct pxafb_mode_info *pxafb_getmode(struct pxafb_mach_info *mach,
246 struct fb_var_screeninfo *var)
248 struct pxafb_mode_info *mode = NULL;
249 struct pxafb_mode_info *modelist = mach->modes;
250 unsigned int best_x = 0xffffffff, best_y = 0xffffffff;
253 for (i = 0; i < mach->num_modes; i++) {
254 if (modelist[i].xres >= var->xres &&
255 modelist[i].yres >= var->yres &&
256 modelist[i].xres < best_x &&
257 modelist[i].yres < best_y &&
258 modelist[i].bpp >= var->bits_per_pixel) {
259 best_x = modelist[i].xres;
260 best_y = modelist[i].yres;
268 static void pxafb_setmode(struct fb_var_screeninfo *var,
269 struct pxafb_mode_info *mode)
271 var->xres = mode->xres;
272 var->yres = mode->yres;
273 var->bits_per_pixel = mode->bpp;
274 var->pixclock = mode->pixclock;
275 var->hsync_len = mode->hsync_len;
276 var->left_margin = mode->left_margin;
277 var->right_margin = mode->right_margin;
278 var->vsync_len = mode->vsync_len;
279 var->upper_margin = mode->upper_margin;
280 var->lower_margin = mode->lower_margin;
281 var->sync = mode->sync;
282 var->grayscale = mode->cmap_greyscale;
283 var->xres_virtual = var->xres;
284 var->yres_virtual = var->yres;
289 * Get the video params out of 'var'. If a value doesn't fit, round it up,
290 * if it's too big, return -EINVAL.
292 * Round up in the following order: bits_per_pixel, xres,
293 * yres, xres_virtual, yres_virtual, xoffset, yoffset, grayscale,
294 * bitfields, horizontal timing, vertical timing.
296 static int pxafb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
298 struct pxafb_info *fbi = (struct pxafb_info *)info;
299 struct pxafb_mach_info *inf = fbi->dev->platform_data;
301 if (var->xres < MIN_XRES)
302 var->xres = MIN_XRES;
303 if (var->yres < MIN_YRES)
304 var->yres = MIN_YRES;
306 if (inf->fixed_modes) {
307 struct pxafb_mode_info *mode;
309 mode = pxafb_getmode(inf, var);
312 pxafb_setmode(var, mode);
314 if (var->xres > inf->modes->xres)
316 if (var->yres > inf->modes->yres)
318 if (var->bits_per_pixel > inf->modes->bpp)
323 max(var->xres_virtual, var->xres);
325 max(var->yres_virtual, var->yres);
328 * Setup the RGB parameters for this display.
330 * The pixel packing format is described on page 7-11 of the
331 * PXA2XX Developer's Manual.
333 if (var->bits_per_pixel == 16) {
334 var->red.offset = 11; var->red.length = 5;
335 var->green.offset = 5; var->green.length = 6;
336 var->blue.offset = 0; var->blue.length = 5;
337 var->transp.offset = var->transp.length = 0;
339 var->red.offset = var->green.offset = 0;
340 var->blue.offset = var->transp.offset = 0;
342 var->green.length = 8;
343 var->blue.length = 8;
344 var->transp.length = 0;
347 #ifdef CONFIG_CPU_FREQ
348 pr_debug("pxafb: dma period = %d ps, clock = %d kHz\n",
349 pxafb_display_dma_period(var),
350 get_clk_frequency_khz(0));
356 static inline void pxafb_set_truecolor(u_int is_true_color)
358 pr_debug("pxafb: true_color = %d\n", is_true_color);
359 /* do your machine-specific setup if needed */
364 * Set the user defined part of the display for the specified console
366 static int pxafb_set_par(struct fb_info *info)
368 struct pxafb_info *fbi = (struct pxafb_info *)info;
369 struct fb_var_screeninfo *var = &info->var;
370 unsigned long palette_mem_size;
372 pr_debug("pxafb: set_par\n");
374 if (var->bits_per_pixel == 16)
375 fbi->fb.fix.visual = FB_VISUAL_TRUECOLOR;
376 else if (!fbi->cmap_static)
377 fbi->fb.fix.visual = FB_VISUAL_PSEUDOCOLOR;
380 * Some people have weird ideas about wanting static
381 * pseudocolor maps. I suspect their user space
382 * applications are broken.
384 fbi->fb.fix.visual = FB_VISUAL_STATIC_PSEUDOCOLOR;
387 fbi->fb.fix.line_length = var->xres_virtual *
388 var->bits_per_pixel / 8;
389 if (var->bits_per_pixel == 16)
390 fbi->palette_size = 0;
392 fbi->palette_size = var->bits_per_pixel == 1 ?
393 4 : 1 << var->bits_per_pixel;
395 if ((fbi->lccr4 & LCCR4_PAL_FOR_MASK) == LCCR4_PAL_FOR_0)
396 palette_mem_size = fbi->palette_size * sizeof(u16);
398 palette_mem_size = fbi->palette_size * sizeof(u32);
400 pr_debug("pxafb: palette_mem_size = 0x%08lx\n", palette_mem_size);
402 fbi->palette_cpu = (u16 *)(fbi->map_cpu + PAGE_SIZE - palette_mem_size);
403 fbi->palette_dma = fbi->map_dma + PAGE_SIZE - palette_mem_size;
406 * Set (any) board control register to handle new color depth
408 pxafb_set_truecolor(fbi->fb.fix.visual == FB_VISUAL_TRUECOLOR);
410 if (fbi->fb.var.bits_per_pixel == 16)
411 fb_dealloc_cmap(&fbi->fb.cmap);
413 fb_alloc_cmap(&fbi->fb.cmap, 1<<fbi->fb.var.bits_per_pixel, 0);
415 pxafb_activate_var(var, fbi);
421 * Formal definition of the VESA spec:
423 * This refers to the state of the display when it is in full operation
425 * This defines an optional operating state of minimal power reduction with
426 * the shortest recovery time
428 * This refers to a level of power management in which substantial power
429 * reduction is achieved by the display. The display can have a longer
430 * recovery time from this state than from the Stand-by state
432 * This indicates that the display is consuming the lowest level of power
433 * and is non-operational. Recovery from this state may optionally require
434 * the user to manually power on the monitor
436 * Now, the fbdev driver adds an additional state, (blank), where they
437 * turn off the video (maybe by colormap tricks), but don't mess with the
438 * video itself: think of it semantically between on and Stand-By.
440 * So here's what we should do in our fbdev blank routine:
442 * VESA_NO_BLANKING (mode 0) Video on, front/back light on
443 * VESA_VSYNC_SUSPEND (mode 1) Video on, front/back light off
444 * VESA_HSYNC_SUSPEND (mode 2) Video on, front/back light off
445 * VESA_POWERDOWN (mode 3) Video off, front/back light off
447 * This will match the matrox implementation.
452 * Blank the display by setting all palette values to zero. Note, the
453 * 16 bpp mode does not really use the palette, so this will not
454 * blank the display in all modes.
456 static int pxafb_blank(int blank, struct fb_info *info)
458 struct pxafb_info *fbi = (struct pxafb_info *)info;
461 pr_debug("pxafb: blank=%d\n", blank);
464 case FB_BLANK_POWERDOWN:
465 case FB_BLANK_VSYNC_SUSPEND:
466 case FB_BLANK_HSYNC_SUSPEND:
467 case FB_BLANK_NORMAL:
468 if (fbi->fb.fix.visual == FB_VISUAL_PSEUDOCOLOR ||
469 fbi->fb.fix.visual == FB_VISUAL_STATIC_PSEUDOCOLOR)
470 for (i = 0; i < fbi->palette_size; i++)
471 pxafb_setpalettereg(i, 0, 0, 0, 0, info);
473 pxafb_schedule_work(fbi, C_DISABLE);
474 /* TODO if (pxafb_blank_helper) pxafb_blank_helper(blank); */
477 case FB_BLANK_UNBLANK:
478 /* TODO if (pxafb_blank_helper) pxafb_blank_helper(blank); */
479 if (fbi->fb.fix.visual == FB_VISUAL_PSEUDOCOLOR ||
480 fbi->fb.fix.visual == FB_VISUAL_STATIC_PSEUDOCOLOR)
481 fb_set_cmap(&fbi->fb.cmap, info);
482 pxafb_schedule_work(fbi, C_ENABLE);
487 static int pxafb_mmap(struct fb_info *info,
488 struct vm_area_struct *vma)
490 struct pxafb_info *fbi = (struct pxafb_info *)info;
491 unsigned long off = vma->vm_pgoff << PAGE_SHIFT;
493 if (off < info->fix.smem_len) {
495 return dma_mmap_writecombine(fbi->dev, vma, fbi->map_cpu,
496 fbi->map_dma, fbi->map_size);
501 static struct fb_ops pxafb_ops = {
502 .owner = THIS_MODULE,
503 .fb_check_var = pxafb_check_var,
504 .fb_set_par = pxafb_set_par,
505 .fb_setcolreg = pxafb_setcolreg,
506 .fb_fillrect = cfb_fillrect,
507 .fb_copyarea = cfb_copyarea,
508 .fb_imageblit = cfb_imageblit,
509 .fb_blank = pxafb_blank,
510 .fb_mmap = pxafb_mmap,
514 * Calculate the PCD value from the clock rate (in picoseconds).
515 * We take account of the PPCR clock setting.
516 * From PXA Developer's Manual:
527 * LCLK = LCD/Memory Clock
530 * PixelClock here is in Hz while the pixclock argument given is the
531 * period in picoseconds. Hence PixelClock = 1 / ( pixclock * 10^-12 )
533 * The function get_lclk_frequency_10khz returns LCLK in units of
534 * 10khz. Calling the result of this function lclk gives us the
537 * PCD = (lclk * 10^4 ) * ( pixclock * 10^-12 )
538 * -------------------------------------- - 1
541 * Factoring the 10^4 and 10^-12 out gives 10^-8 == 1 / 100000000 as used below.
543 static inline unsigned int get_pcd(struct pxafb_info *fbi,
544 unsigned int pixclock)
546 unsigned long long pcd;
548 /* FIXME: Need to take into account Double Pixel Clock mode
549 * (DPC) bit? or perhaps set it based on the various clock
551 pcd = (unsigned long long)(clk_get_rate(fbi->clk) / 10000);
553 do_div(pcd, 100000000 * 2);
554 /* no need for this, since we should subtract 1 anyway. they cancel */
555 /* pcd += 1; */ /* make up for integer math truncations */
556 return (unsigned int)pcd;
560 * Some touchscreens need hsync information from the video driver to
561 * function correctly. We export it here. Note that 'hsync_time' and
562 * the value returned from pxafb_get_hsync_time() is the *reciprocal*
563 * of the hsync period in seconds.
565 static inline void set_hsync_time(struct pxafb_info *fbi, unsigned int pcd)
569 if ((pcd == 0) || (fbi->fb.var.hsync_len == 0)) {
574 htime = clk_get_rate(fbi->clk) / (pcd * fbi->fb.var.hsync_len);
576 fbi->hsync_time = htime;
579 unsigned long pxafb_get_hsync_time(struct device *dev)
581 struct pxafb_info *fbi = dev_get_drvdata(dev);
583 /* If display is blanked/suspended, hsync isn't active */
584 if (!fbi || (fbi->state != C_ENABLE))
587 return fbi->hsync_time;
589 EXPORT_SYMBOL(pxafb_get_hsync_time);
592 * pxafb_activate_var():
593 * Configures LCD Controller based on entries in var parameter.
594 * Settings are only written to the controller if changes were made.
596 static int pxafb_activate_var(struct fb_var_screeninfo *var,
597 struct pxafb_info *fbi)
599 struct pxafb_lcd_reg new_regs;
601 u_int lines_per_panel, pcd = get_pcd(fbi, var->pixclock);
603 pr_debug("pxafb: Configuring PXA LCD\n");
605 pr_debug("var: xres=%d hslen=%d lm=%d rm=%d\n",
606 var->xres, var->hsync_len,
607 var->left_margin, var->right_margin);
608 pr_debug("var: yres=%d vslen=%d um=%d bm=%d\n",
609 var->yres, var->vsync_len,
610 var->upper_margin, var->lower_margin);
611 pr_debug("var: pixclock=%d pcd=%d\n", var->pixclock, pcd);
614 if (var->xres < 16 || var->xres > 1024)
615 printk(KERN_ERR "%s: invalid xres %d\n",
616 fbi->fb.fix.id, var->xres);
617 switch (var->bits_per_pixel) {
625 printk(KERN_ERR "%s: invalid bit depth %d\n",
626 fbi->fb.fix.id, var->bits_per_pixel);
629 if (var->hsync_len < 1 || var->hsync_len > 64)
630 printk(KERN_ERR "%s: invalid hsync_len %d\n",
631 fbi->fb.fix.id, var->hsync_len);
632 if (var->left_margin < 1 || var->left_margin > 255)
633 printk(KERN_ERR "%s: invalid left_margin %d\n",
634 fbi->fb.fix.id, var->left_margin);
635 if (var->right_margin < 1 || var->right_margin > 255)
636 printk(KERN_ERR "%s: invalid right_margin %d\n",
637 fbi->fb.fix.id, var->right_margin);
638 if (var->yres < 1 || var->yres > 1024)
639 printk(KERN_ERR "%s: invalid yres %d\n",
640 fbi->fb.fix.id, var->yres);
641 if (var->vsync_len < 1 || var->vsync_len > 64)
642 printk(KERN_ERR "%s: invalid vsync_len %d\n",
643 fbi->fb.fix.id, var->vsync_len);
644 if (var->upper_margin < 0 || var->upper_margin > 255)
645 printk(KERN_ERR "%s: invalid upper_margin %d\n",
646 fbi->fb.fix.id, var->upper_margin);
647 if (var->lower_margin < 0 || var->lower_margin > 255)
648 printk(KERN_ERR "%s: invalid lower_margin %d\n",
649 fbi->fb.fix.id, var->lower_margin);
652 new_regs.lccr0 = fbi->lccr0 |
653 (LCCR0_LDM | LCCR0_SFM | LCCR0_IUM | LCCR0_EFM |
654 LCCR0_QDM | LCCR0_BM | LCCR0_OUM);
657 LCCR1_DisWdth(var->xres) +
658 LCCR1_HorSnchWdth(var->hsync_len) +
659 LCCR1_BegLnDel(var->left_margin) +
660 LCCR1_EndLnDel(var->right_margin);
663 * If we have a dual scan LCD, we need to halve
664 * the YRES parameter.
666 lines_per_panel = var->yres;
667 if ((fbi->lccr0 & LCCR0_SDS) == LCCR0_Dual)
668 lines_per_panel /= 2;
671 LCCR2_DisHght(lines_per_panel) +
672 LCCR2_VrtSnchWdth(var->vsync_len) +
673 LCCR2_BegFrmDel(var->upper_margin) +
674 LCCR2_EndFrmDel(var->lower_margin);
676 new_regs.lccr3 = fbi->lccr3 |
677 pxafb_bpp_to_lccr3(var) |
678 (var->sync & FB_SYNC_HOR_HIGH_ACT ?
679 LCCR3_HorSnchH : LCCR3_HorSnchL) |
680 (var->sync & FB_SYNC_VERT_HIGH_ACT ?
681 LCCR3_VrtSnchH : LCCR3_VrtSnchL);
684 new_regs.lccr3 |= LCCR3_PixClkDiv(pcd);
686 pr_debug("nlccr0 = 0x%08x\n", new_regs.lccr0);
687 pr_debug("nlccr1 = 0x%08x\n", new_regs.lccr1);
688 pr_debug("nlccr2 = 0x%08x\n", new_regs.lccr2);
689 pr_debug("nlccr3 = 0x%08x\n", new_regs.lccr3);
691 /* Update shadow copy atomically */
692 local_irq_save(flags);
694 /* setup dma descriptors */
695 fbi->dmadesc_fblow_cpu = (struct pxafb_dma_descriptor *)
696 ((unsigned int)fbi->palette_cpu - 3*16);
697 fbi->dmadesc_fbhigh_cpu = (struct pxafb_dma_descriptor *)
698 ((unsigned int)fbi->palette_cpu - 2*16);
699 fbi->dmadesc_palette_cpu = (struct pxafb_dma_descriptor *)
700 ((unsigned int)fbi->palette_cpu - 1*16);
702 fbi->dmadesc_fblow_dma = fbi->palette_dma - 3*16;
703 fbi->dmadesc_fbhigh_dma = fbi->palette_dma - 2*16;
704 fbi->dmadesc_palette_dma = fbi->palette_dma - 1*16;
706 #define BYTES_PER_PANEL (lines_per_panel * fbi->fb.fix.line_length)
708 /* populate descriptors */
709 fbi->dmadesc_fblow_cpu->fdadr = fbi->dmadesc_fblow_dma;
710 fbi->dmadesc_fblow_cpu->fsadr = fbi->screen_dma + BYTES_PER_PANEL;
711 fbi->dmadesc_fblow_cpu->fidr = 0;
712 fbi->dmadesc_fblow_cpu->ldcmd = BYTES_PER_PANEL;
714 fbi->fdadr1 = fbi->dmadesc_fblow_dma; /* only used in dual-panel mode */
716 fbi->dmadesc_fbhigh_cpu->fsadr = fbi->screen_dma;
717 fbi->dmadesc_fbhigh_cpu->fidr = 0;
718 fbi->dmadesc_fbhigh_cpu->ldcmd = BYTES_PER_PANEL;
720 fbi->dmadesc_palette_cpu->fsadr = fbi->palette_dma;
721 fbi->dmadesc_palette_cpu->fidr = 0;
722 if ((fbi->lccr4 & LCCR4_PAL_FOR_MASK) == LCCR4_PAL_FOR_0)
723 fbi->dmadesc_palette_cpu->ldcmd = fbi->palette_size *
726 fbi->dmadesc_palette_cpu->ldcmd = fbi->palette_size *
728 fbi->dmadesc_palette_cpu->ldcmd |= LDCMD_PAL;
730 if (var->bits_per_pixel == 16) {
731 /* palette shouldn't be loaded in true-color mode */
732 fbi->dmadesc_fbhigh_cpu->fdadr = fbi->dmadesc_fbhigh_dma;
733 fbi->fdadr0 = fbi->dmadesc_fbhigh_dma; /* no pal just fbhigh */
734 /* init it to something, even though we won't be using it */
735 fbi->dmadesc_palette_cpu->fdadr = fbi->dmadesc_palette_dma;
737 /* flips back and forth between pal and fbhigh */
738 fbi->dmadesc_palette_cpu->fdadr = fbi->dmadesc_fbhigh_dma;
739 fbi->dmadesc_fbhigh_cpu->fdadr = fbi->dmadesc_palette_dma;
740 fbi->fdadr0 = fbi->dmadesc_palette_dma;
743 fbi->reg_lccr0 = new_regs.lccr0;
744 fbi->reg_lccr1 = new_regs.lccr1;
745 fbi->reg_lccr2 = new_regs.lccr2;
746 fbi->reg_lccr3 = new_regs.lccr3;
747 fbi->reg_lccr4 = LCCR4 & (~LCCR4_PAL_FOR_MASK);
748 fbi->reg_lccr4 |= (fbi->lccr4 & LCCR4_PAL_FOR_MASK);
749 set_hsync_time(fbi, pcd);
750 local_irq_restore(flags);
753 * Only update the registers if the controller is enabled
754 * and something has changed.
756 if ((LCCR0 != fbi->reg_lccr0) || (LCCR1 != fbi->reg_lccr1) ||
757 (LCCR2 != fbi->reg_lccr2) || (LCCR3 != fbi->reg_lccr3) ||
758 (FDADR0 != fbi->fdadr0) || (FDADR1 != fbi->fdadr1))
759 pxafb_schedule_work(fbi, C_REENABLE);
765 * NOTE! The following functions are purely helpers for set_ctrlr_state.
766 * Do not call them directly; set_ctrlr_state does the correct serialisation
767 * to ensure that things happen in the right way 100% of time time.
770 static inline void __pxafb_backlight_power(struct pxafb_info *fbi, int on)
772 pr_debug("pxafb: backlight o%s\n", on ? "n" : "ff");
774 if (pxafb_backlight_power)
775 pxafb_backlight_power(on);
778 static inline void __pxafb_lcd_power(struct pxafb_info *fbi, int on)
780 pr_debug("pxafb: LCD power o%s\n", on ? "n" : "ff");
783 pxafb_lcd_power(on, &fbi->fb.var);
786 static void pxafb_setup_gpio(struct pxafb_info *fbi)
789 unsigned int lccr0 = fbi->lccr0;
792 * setup is based on type of panel supported
795 /* 4 bit interface */
796 if ((lccr0 & LCCR0_CMS) == LCCR0_Mono &&
797 (lccr0 & LCCR0_SDS) == LCCR0_Sngl &&
798 (lccr0 & LCCR0_DPD) == LCCR0_4PixMono)
801 /* 8 bit interface */
802 else if (((lccr0 & LCCR0_CMS) == LCCR0_Mono &&
803 ((lccr0 & LCCR0_SDS) == LCCR0_Dual ||
804 (lccr0 & LCCR0_DPD) == LCCR0_8PixMono)) ||
805 ((lccr0 & LCCR0_CMS) == LCCR0_Color &&
806 (lccr0 & LCCR0_PAS) == LCCR0_Pas &&
807 (lccr0 & LCCR0_SDS) == LCCR0_Sngl))
810 /* 16 bit interface */
811 else if ((lccr0 & LCCR0_CMS) == LCCR0_Color &&
812 ((lccr0 & LCCR0_SDS) == LCCR0_Dual ||
813 (lccr0 & LCCR0_PAS) == LCCR0_Act))
817 printk(KERN_ERR "pxafb_setup_gpio: unable to determine "
822 for (gpio = 58; ldd_bits; gpio++, ldd_bits--)
823 pxa_gpio_mode(gpio | GPIO_ALT_FN_2_OUT);
824 pxa_gpio_mode(GPIO74_LCD_FCLK_MD);
825 pxa_gpio_mode(GPIO75_LCD_LCLK_MD);
826 pxa_gpio_mode(GPIO76_LCD_PCLK_MD);
827 pxa_gpio_mode(GPIO77_LCD_ACBIAS_MD);
830 static void pxafb_enable_controller(struct pxafb_info *fbi)
832 pr_debug("pxafb: Enabling LCD controller\n");
833 pr_debug("fdadr0 0x%08x\n", (unsigned int) fbi->fdadr0);
834 pr_debug("fdadr1 0x%08x\n", (unsigned int) fbi->fdadr1);
835 pr_debug("reg_lccr0 0x%08x\n", (unsigned int) fbi->reg_lccr0);
836 pr_debug("reg_lccr1 0x%08x\n", (unsigned int) fbi->reg_lccr1);
837 pr_debug("reg_lccr2 0x%08x\n", (unsigned int) fbi->reg_lccr2);
838 pr_debug("reg_lccr3 0x%08x\n", (unsigned int) fbi->reg_lccr3);
840 /* enable LCD controller clock */
841 clk_enable(fbi->clk);
843 /* Sequence from 11.7.10 */
844 LCCR3 = fbi->reg_lccr3;
845 LCCR2 = fbi->reg_lccr2;
846 LCCR1 = fbi->reg_lccr1;
847 LCCR0 = fbi->reg_lccr0 & ~LCCR0_ENB;
849 FDADR0 = fbi->fdadr0;
850 FDADR1 = fbi->fdadr1;
853 pr_debug("FDADR0 0x%08x\n", (unsigned int) FDADR0);
854 pr_debug("FDADR1 0x%08x\n", (unsigned int) FDADR1);
855 pr_debug("LCCR0 0x%08x\n", (unsigned int) LCCR0);
856 pr_debug("LCCR1 0x%08x\n", (unsigned int) LCCR1);
857 pr_debug("LCCR2 0x%08x\n", (unsigned int) LCCR2);
858 pr_debug("LCCR3 0x%08x\n", (unsigned int) LCCR3);
859 pr_debug("LCCR4 0x%08x\n", (unsigned int) LCCR4);
862 static void pxafb_disable_controller(struct pxafb_info *fbi)
864 DECLARE_WAITQUEUE(wait, current);
866 pr_debug("pxafb: disabling LCD controller\n");
868 set_current_state(TASK_UNINTERRUPTIBLE);
869 add_wait_queue(&fbi->ctrlr_wait, &wait);
871 LCSR = 0xffffffff; /* Clear LCD Status Register */
872 LCCR0 &= ~LCCR0_LDM; /* Enable LCD Disable Done Interrupt */
873 LCCR0 |= LCCR0_DIS; /* Disable LCD Controller */
875 schedule_timeout(200 * HZ / 1000);
876 remove_wait_queue(&fbi->ctrlr_wait, &wait);
878 /* disable LCD controller clock */
879 clk_disable(fbi->clk);
883 * pxafb_handle_irq: Handle 'LCD DONE' interrupts.
885 static irqreturn_t pxafb_handle_irq(int irq, void *dev_id)
887 struct pxafb_info *fbi = dev_id;
888 unsigned int lcsr = LCSR;
890 if (lcsr & LCSR_LDD) {
892 wake_up(&fbi->ctrlr_wait);
900 * This function must be called from task context only, since it will
901 * sleep when disabling the LCD controller, or if we get two contending
902 * processes trying to alter state.
904 static void set_ctrlr_state(struct pxafb_info *fbi, u_int state)
908 down(&fbi->ctrlr_sem);
910 old_state = fbi->state;
913 * Hack around fbcon initialisation.
915 if (old_state == C_STARTUP && state == C_REENABLE)
919 case C_DISABLE_CLKCHANGE:
921 * Disable controller for clock change. If the
922 * controller is already disabled, then do nothing.
924 if (old_state != C_DISABLE && old_state != C_DISABLE_PM) {
926 /* TODO __pxafb_lcd_power(fbi, 0); */
927 pxafb_disable_controller(fbi);
936 if (old_state != C_DISABLE) {
938 __pxafb_backlight_power(fbi, 0);
939 __pxafb_lcd_power(fbi, 0);
940 if (old_state != C_DISABLE_CLKCHANGE)
941 pxafb_disable_controller(fbi);
945 case C_ENABLE_CLKCHANGE:
947 * Enable the controller after clock change. Only
948 * do this if we were disabled for the clock change.
950 if (old_state == C_DISABLE_CLKCHANGE) {
951 fbi->state = C_ENABLE;
952 pxafb_enable_controller(fbi);
953 /* TODO __pxafb_lcd_power(fbi, 1); */
959 * Re-enable the controller only if it was already
960 * enabled. This is so we reprogram the control
963 if (old_state == C_ENABLE) {
964 __pxafb_lcd_power(fbi, 0);
965 pxafb_disable_controller(fbi);
966 pxafb_setup_gpio(fbi);
967 pxafb_enable_controller(fbi);
968 __pxafb_lcd_power(fbi, 1);
974 * Re-enable the controller after PM. This is not
975 * perfect - think about the case where we were doing
976 * a clock change, and we suspended half-way through.
978 if (old_state != C_DISABLE_PM)
984 * Power up the LCD screen, enable controller, and
985 * turn on the backlight.
987 if (old_state != C_ENABLE) {
988 fbi->state = C_ENABLE;
989 pxafb_setup_gpio(fbi);
990 pxafb_enable_controller(fbi);
991 __pxafb_lcd_power(fbi, 1);
992 __pxafb_backlight_power(fbi, 1);
1000 * Our LCD controller task (which is called when we blank or unblank)
1003 static void pxafb_task(struct work_struct *work)
1005 struct pxafb_info *fbi =
1006 container_of(work, struct pxafb_info, task);
1007 u_int state = xchg(&fbi->task_state, -1);
1009 set_ctrlr_state(fbi, state);
1012 #ifdef CONFIG_CPU_FREQ
1014 * CPU clock speed change handler. We need to adjust the LCD timing
1015 * parameters when the CPU clock is adjusted by the power management
1018 * TODO: Determine why f->new != 10*get_lclk_frequency_10khz()
1021 pxafb_freq_transition(struct notifier_block *nb, unsigned long val, void *data)
1023 struct pxafb_info *fbi = TO_INF(nb, freq_transition);
1024 /* TODO struct cpufreq_freqs *f = data; */
1028 case CPUFREQ_PRECHANGE:
1029 set_ctrlr_state(fbi, C_DISABLE_CLKCHANGE);
1032 case CPUFREQ_POSTCHANGE:
1033 pcd = get_pcd(fbi, fbi->fb.var.pixclock);
1034 set_hsync_time(fbi, pcd);
1035 fbi->reg_lccr3 = (fbi->reg_lccr3 & ~0xff) |
1036 LCCR3_PixClkDiv(pcd);
1037 set_ctrlr_state(fbi, C_ENABLE_CLKCHANGE);
1044 pxafb_freq_policy(struct notifier_block *nb, unsigned long val, void *data)
1046 struct pxafb_info *fbi = TO_INF(nb, freq_policy);
1047 struct fb_var_screeninfo *var = &fbi->fb.var;
1048 struct cpufreq_policy *policy = data;
1051 case CPUFREQ_ADJUST:
1052 case CPUFREQ_INCOMPATIBLE:
1053 pr_debug("min dma period: %d ps, "
1054 "new clock %d kHz\n", pxafb_display_dma_period(var),
1056 /* TODO: fill in min/max values */
1065 * Power management hooks. Note that we won't be called from IRQ context,
1066 * unlike the blank functions above, so we may sleep.
1068 static int pxafb_suspend(struct platform_device *dev, pm_message_t state)
1070 struct pxafb_info *fbi = platform_get_drvdata(dev);
1072 set_ctrlr_state(fbi, C_DISABLE_PM);
1076 static int pxafb_resume(struct platform_device *dev)
1078 struct pxafb_info *fbi = platform_get_drvdata(dev);
1080 set_ctrlr_state(fbi, C_ENABLE_PM);
1084 #define pxafb_suspend NULL
1085 #define pxafb_resume NULL
1089 * pxafb_map_video_memory():
1090 * Allocates the DRAM memory for the frame buffer. This buffer is
1091 * remapped into a non-cached, non-buffered, memory region to
1092 * allow palette and pixel writes to occur without flushing the
1093 * cache. Once this area is remapped, all virtual memory
1094 * access to the video memory should occur at the new region.
1096 static int __init pxafb_map_video_memory(struct pxafb_info *fbi)
1098 u_long palette_mem_size;
1101 * We reserve one page for the palette, plus the size
1102 * of the framebuffer.
1104 fbi->map_size = PAGE_ALIGN(fbi->fb.fix.smem_len + PAGE_SIZE);
1105 fbi->map_cpu = dma_alloc_writecombine(fbi->dev, fbi->map_size,
1106 &fbi->map_dma, GFP_KERNEL);
1109 /* prevent initial garbage on screen */
1110 memset(fbi->map_cpu, 0, fbi->map_size);
1111 fbi->fb.screen_base = fbi->map_cpu + PAGE_SIZE;
1112 fbi->screen_dma = fbi->map_dma + PAGE_SIZE;
1114 * FIXME: this is actually the wrong thing to place in
1115 * smem_start. But fbdev suffers from the problem that
1116 * it needs an API which doesn't exist (in this case,
1117 * dma_writecombine_mmap)
1119 fbi->fb.fix.smem_start = fbi->screen_dma;
1120 fbi->palette_size = fbi->fb.var.bits_per_pixel == 8 ? 256 : 16;
1122 if ((fbi->lccr4 & LCCR4_PAL_FOR_MASK) == LCCR4_PAL_FOR_0)
1123 palette_mem_size = fbi->palette_size * sizeof(u16);
1125 palette_mem_size = fbi->palette_size * sizeof(u32);
1127 pr_debug("pxafb: palette_mem_size = 0x%08lx\n",
1130 fbi->palette_cpu = (u16 *)(fbi->map_cpu + PAGE_SIZE
1131 - palette_mem_size);
1132 fbi->palette_dma = fbi->map_dma + PAGE_SIZE - palette_mem_size;
1135 return fbi->map_cpu ? 0 : -ENOMEM;
1138 static struct pxafb_info * __init pxafb_init_fbinfo(struct device *dev)
1140 struct pxafb_info *fbi;
1142 struct pxafb_mach_info *inf = dev->platform_data;
1143 struct pxafb_mode_info *mode = inf->modes;
1146 /* Alloc the pxafb_info and pseudo_palette in one step */
1147 fbi = kmalloc(sizeof(struct pxafb_info) + sizeof(u32) * 16, GFP_KERNEL);
1151 memset(fbi, 0, sizeof(struct pxafb_info));
1154 fbi->clk = clk_get(dev, "LCDCLK");
1155 if (IS_ERR(fbi->clk)) {
1160 strcpy(fbi->fb.fix.id, PXA_NAME);
1162 fbi->fb.fix.type = FB_TYPE_PACKED_PIXELS;
1163 fbi->fb.fix.type_aux = 0;
1164 fbi->fb.fix.xpanstep = 0;
1165 fbi->fb.fix.ypanstep = 0;
1166 fbi->fb.fix.ywrapstep = 0;
1167 fbi->fb.fix.accel = FB_ACCEL_NONE;
1169 fbi->fb.var.nonstd = 0;
1170 fbi->fb.var.activate = FB_ACTIVATE_NOW;
1171 fbi->fb.var.height = -1;
1172 fbi->fb.var.width = -1;
1173 fbi->fb.var.accel_flags = 0;
1174 fbi->fb.var.vmode = FB_VMODE_NONINTERLACED;
1176 fbi->fb.fbops = &pxafb_ops;
1177 fbi->fb.flags = FBINFO_DEFAULT;
1181 addr = addr + sizeof(struct pxafb_info);
1182 fbi->fb.pseudo_palette = addr;
1184 pxafb_setmode(&fbi->fb.var, mode);
1186 fbi->cmap_inverse = inf->cmap_inverse;
1187 fbi->cmap_static = inf->cmap_static;
1189 fbi->lccr0 = inf->lccr0;
1190 fbi->lccr3 = inf->lccr3;
1191 fbi->lccr4 = inf->lccr4;
1192 fbi->state = C_STARTUP;
1193 fbi->task_state = (u_char)-1;
1195 for (i = 0; i < inf->num_modes; i++) {
1196 smemlen = mode[i].xres * mode[i].yres * mode[i].bpp / 8;
1197 if (smemlen > fbi->fb.fix.smem_len)
1198 fbi->fb.fix.smem_len = smemlen;
1201 init_waitqueue_head(&fbi->ctrlr_wait);
1202 INIT_WORK(&fbi->task, pxafb_task);
1203 init_MUTEX(&fbi->ctrlr_sem);
1208 #ifdef CONFIG_FB_PXA_PARAMETERS
1209 static int __init parse_opt_mode(struct device *dev, const char *this_opt)
1211 struct pxafb_mach_info *inf = dev->platform_data;
1213 const char *name = this_opt+5;
1214 unsigned int namelen = strlen(name);
1215 int res_specified = 0, bpp_specified = 0;
1216 unsigned int xres = 0, yres = 0, bpp = 0;
1217 int yres_specified = 0;
1219 for (i = namelen-1; i >= 0; i--) {
1223 if (!bpp_specified && !yres_specified) {
1224 bpp = simple_strtoul(&name[i+1], NULL, 0);
1230 if (!yres_specified) {
1231 yres = simple_strtoul(&name[i+1], NULL, 0);
1242 if (i < 0 && yres_specified) {
1243 xres = simple_strtoul(name, NULL, 0);
1247 if (res_specified) {
1248 dev_info(dev, "overriding resolution: %dx%d\n", xres, yres);
1249 inf->modes[0].xres = xres; inf->modes[0].yres = yres;
1258 inf->modes[0].bpp = bpp;
1259 dev_info(dev, "overriding bit depth: %d\n", bpp);
1262 dev_err(dev, "Depth %d is not valid\n", bpp);
1268 static int __init parse_opt(struct device *dev, char *this_opt)
1270 struct pxafb_mach_info *inf = dev->platform_data;
1271 struct pxafb_mode_info *mode = &inf->modes[0];
1276 if (!strncmp(this_opt, "mode:", 5)) {
1277 return parse_opt_mode(dev, this_opt);
1278 } else if (!strncmp(this_opt, "pixclock:", 9)) {
1279 mode->pixclock = simple_strtoul(this_opt+9, NULL, 0);
1280 sprintf(s, "pixclock: %ld\n", mode->pixclock);
1281 } else if (!strncmp(this_opt, "left:", 5)) {
1282 mode->left_margin = simple_strtoul(this_opt+5, NULL, 0);
1283 sprintf(s, "left: %u\n", mode->left_margin);
1284 } else if (!strncmp(this_opt, "right:", 6)) {
1285 mode->right_margin = simple_strtoul(this_opt+6, NULL, 0);
1286 sprintf(s, "right: %u\n", mode->right_margin);
1287 } else if (!strncmp(this_opt, "upper:", 6)) {
1288 mode->upper_margin = simple_strtoul(this_opt+6, NULL, 0);
1289 sprintf(s, "upper: %u\n", mode->upper_margin);
1290 } else if (!strncmp(this_opt, "lower:", 6)) {
1291 mode->lower_margin = simple_strtoul(this_opt+6, NULL, 0);
1292 sprintf(s, "lower: %u\n", mode->lower_margin);
1293 } else if (!strncmp(this_opt, "hsynclen:", 9)) {
1294 mode->hsync_len = simple_strtoul(this_opt+9, NULL, 0);
1295 sprintf(s, "hsynclen: %u\n", mode->hsync_len);
1296 } else if (!strncmp(this_opt, "vsynclen:", 9)) {
1297 mode->vsync_len = simple_strtoul(this_opt+9, NULL, 0);
1298 sprintf(s, "vsynclen: %u\n", mode->vsync_len);
1299 } else if (!strncmp(this_opt, "hsync:", 6)) {
1300 if (simple_strtoul(this_opt+6, NULL, 0) == 0) {
1301 sprintf(s, "hsync: Active Low\n");
1302 mode->sync &= ~FB_SYNC_HOR_HIGH_ACT;
1304 sprintf(s, "hsync: Active High\n");
1305 mode->sync |= FB_SYNC_HOR_HIGH_ACT;
1307 } else if (!strncmp(this_opt, "vsync:", 6)) {
1308 if (simple_strtoul(this_opt+6, NULL, 0) == 0) {
1309 sprintf(s, "vsync: Active Low\n");
1310 mode->sync &= ~FB_SYNC_VERT_HIGH_ACT;
1312 sprintf(s, "vsync: Active High\n");
1313 mode->sync |= FB_SYNC_VERT_HIGH_ACT;
1315 } else if (!strncmp(this_opt, "dpc:", 4)) {
1316 if (simple_strtoul(this_opt+4, NULL, 0) == 0) {
1317 sprintf(s, "double pixel clock: false\n");
1318 inf->lccr3 &= ~LCCR3_DPC;
1320 sprintf(s, "double pixel clock: true\n");
1321 inf->lccr3 |= LCCR3_DPC;
1323 } else if (!strncmp(this_opt, "outputen:", 9)) {
1324 if (simple_strtoul(this_opt+9, NULL, 0) == 0) {
1325 sprintf(s, "output enable: active low\n");
1326 inf->lccr3 = (inf->lccr3 & ~LCCR3_OEP) | LCCR3_OutEnL;
1328 sprintf(s, "output enable: active high\n");
1329 inf->lccr3 = (inf->lccr3 & ~LCCR3_OEP) | LCCR3_OutEnH;
1331 } else if (!strncmp(this_opt, "pixclockpol:", 12)) {
1332 if (simple_strtoul(this_opt+12, NULL, 0) == 0) {
1333 sprintf(s, "pixel clock polarity: falling edge\n");
1334 inf->lccr3 = (inf->lccr3 & ~LCCR3_PCP) | LCCR3_PixFlEdg;
1336 sprintf(s, "pixel clock polarity: rising edge\n");
1337 inf->lccr3 = (inf->lccr3 & ~LCCR3_PCP) | LCCR3_PixRsEdg;
1339 } else if (!strncmp(this_opt, "color", 5)) {
1340 inf->lccr0 = (inf->lccr0 & ~LCCR0_CMS) | LCCR0_Color;
1341 } else if (!strncmp(this_opt, "mono", 4)) {
1342 inf->lccr0 = (inf->lccr0 & ~LCCR0_CMS) | LCCR0_Mono;
1343 } else if (!strncmp(this_opt, "active", 6)) {
1344 inf->lccr0 = (inf->lccr0 & ~LCCR0_PAS) | LCCR0_Act;
1345 } else if (!strncmp(this_opt, "passive", 7)) {
1346 inf->lccr0 = (inf->lccr0 & ~LCCR0_PAS) | LCCR0_Pas;
1347 } else if (!strncmp(this_opt, "single", 6)) {
1348 inf->lccr0 = (inf->lccr0 & ~LCCR0_SDS) | LCCR0_Sngl;
1349 } else if (!strncmp(this_opt, "dual", 4)) {
1350 inf->lccr0 = (inf->lccr0 & ~LCCR0_SDS) | LCCR0_Dual;
1351 } else if (!strncmp(this_opt, "4pix", 4)) {
1352 inf->lccr0 = (inf->lccr0 & ~LCCR0_DPD) | LCCR0_4PixMono;
1353 } else if (!strncmp(this_opt, "8pix", 4)) {
1354 inf->lccr0 = (inf->lccr0 & ~LCCR0_DPD) | LCCR0_8PixMono;
1356 dev_err(dev, "unknown option: %s\n", this_opt);
1361 dev_info(dev, "override %s", s);
1366 static int __init pxafb_parse_options(struct device *dev, char *options)
1371 if (!options || !*options)
1374 dev_dbg(dev, "options are \"%s\"\n", options ? options : "null");
1376 /* could be made table driven or similar?... */
1377 while ((this_opt = strsep(&options, ",")) != NULL) {
1378 ret = parse_opt(dev, this_opt);
1386 static int __init pxafb_probe(struct platform_device *dev)
1388 struct pxafb_info *fbi;
1389 struct pxafb_mach_info *inf;
1392 dev_dbg(&dev->dev, "pxafb_probe\n");
1394 inf = dev->dev.platform_data;
1400 #ifdef CONFIG_FB_PXA_PARAMETERS
1401 ret = pxafb_parse_options(&dev->dev, g_options);
1407 /* Check for various illegal bit-combinations. Currently only
1408 * a warning is given. */
1410 if (inf->lccr0 & LCCR0_INVALID_CONFIG_MASK)
1411 dev_warn(&dev->dev, "machine LCCR0 setting contains "
1412 "illegal bits: %08x\n",
1413 inf->lccr0 & LCCR0_INVALID_CONFIG_MASK);
1414 if (inf->lccr3 & LCCR3_INVALID_CONFIG_MASK)
1415 dev_warn(&dev->dev, "machine LCCR3 setting contains "
1416 "illegal bits: %08x\n",
1417 inf->lccr3 & LCCR3_INVALID_CONFIG_MASK);
1418 if (inf->lccr0 & LCCR0_DPD &&
1419 ((inf->lccr0 & LCCR0_PAS) != LCCR0_Pas ||
1420 (inf->lccr0 & LCCR0_SDS) != LCCR0_Sngl ||
1421 (inf->lccr0 & LCCR0_CMS) != LCCR0_Mono))
1422 dev_warn(&dev->dev, "Double Pixel Data (DPD) mode is "
1423 "only valid in passive mono"
1424 " single panel mode\n");
1425 if ((inf->lccr0 & LCCR0_PAS) == LCCR0_Act &&
1426 (inf->lccr0 & LCCR0_SDS) == LCCR0_Dual)
1427 dev_warn(&dev->dev, "Dual panel only valid in passive mode\n");
1428 if ((inf->lccr0 & LCCR0_PAS) == LCCR0_Pas &&
1429 (inf->modes->upper_margin || inf->modes->lower_margin))
1430 dev_warn(&dev->dev, "Upper and lower margins must be 0 in "
1434 dev_dbg(&dev->dev, "got a %dx%dx%d LCD\n",
1438 if (inf->modes->xres == 0 ||
1439 inf->modes->yres == 0 ||
1440 inf->modes->bpp == 0) {
1441 dev_err(&dev->dev, "Invalid resolution or bit depth\n");
1445 pxafb_backlight_power = inf->pxafb_backlight_power;
1446 pxafb_lcd_power = inf->pxafb_lcd_power;
1447 fbi = pxafb_init_fbinfo(&dev->dev);
1449 /* only reason for pxafb_init_fbinfo to fail is kmalloc */
1450 dev_err(&dev->dev, "Failed to initialize framebuffer device\n");
1455 /* Initialize video memory */
1456 ret = pxafb_map_video_memory(fbi);
1458 dev_err(&dev->dev, "Failed to allocate video RAM: %d\n", ret);
1463 ret = request_irq(IRQ_LCD, pxafb_handle_irq, IRQF_DISABLED, "LCD", fbi);
1465 dev_err(&dev->dev, "request_irq failed: %d\n", ret);
1471 * This makes sure that our colour bitfield
1472 * descriptors are correctly initialised.
1474 pxafb_check_var(&fbi->fb.var, &fbi->fb);
1475 pxafb_set_par(&fbi->fb);
1477 platform_set_drvdata(dev, fbi);
1479 ret = register_framebuffer(&fbi->fb);
1482 "Failed to register framebuffer device: %d\n", ret);
1490 #ifdef CONFIG_CPU_FREQ
1491 fbi->freq_transition.notifier_call = pxafb_freq_transition;
1492 fbi->freq_policy.notifier_call = pxafb_freq_policy;
1493 cpufreq_register_notifier(&fbi->freq_transition,
1494 CPUFREQ_TRANSITION_NOTIFIER);
1495 cpufreq_register_notifier(&fbi->freq_policy,
1496 CPUFREQ_POLICY_NOTIFIER);
1500 * Ok, now enable the LCD controller
1502 set_ctrlr_state(fbi, C_ENABLE);
1507 platform_set_drvdata(dev, NULL);
1512 static struct platform_driver pxafb_driver = {
1513 .probe = pxafb_probe,
1515 .suspend = pxafb_suspend,
1516 .resume = pxafb_resume,
1519 .name = "pxa2xx-fb",
1524 static int __devinit pxafb_setup(char *options)
1526 # ifdef CONFIG_FB_PXA_PARAMETERS
1528 strlcpy(g_options, options, sizeof(g_options));
1533 # ifdef CONFIG_FB_PXA_PARAMETERS
1534 module_param_string(options, g_options, sizeof(g_options), 0);
1535 MODULE_PARM_DESC(options, "LCD parameters (see Documentation/fb/pxafb.txt)");
1539 static int __devinit pxafb_init(void)
1542 char *option = NULL;
1544 if (fb_get_options("pxafb", &option))
1546 pxafb_setup(option);
1548 return platform_driver_register(&pxafb_driver);
1551 module_init(pxafb_init);
1553 MODULE_DESCRIPTION("loadable framebuffer driver for PXA");
1554 MODULE_LICENSE("GPL");