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