blob: ab816cadb470f9064a8ae50a674fbb4d7ecdcdde [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
Linus Torvalds1da177e2005-04-16 15:20:36 -070025#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>
Andrea Righi27ac7922008-07-23 21:28:13 -070033#include <linux/mm.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070034#include <linux/fb.h>
35#include <linux/delay.h>
36#include <linux/init.h>
37#include <linux/ioport.h>
38#include <linux/cpufreq.h>
Russell Kingd052d1b2005-10-29 19:07:23 +010039#include <linux/platform_device.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070040#include <linux/dma-mapping.h>
Russell King72e35242007-08-20 10:18:42 +010041#include <linux/clk.h>
42#include <linux/err.h>
Eric Miao2ba162b2008-04-30 00:52:24 -070043#include <linux/completion.h>
Matthias Kaehlckeb91dbce2008-07-23 21:31:14 -070044#include <linux/mutex.h>
Eric Miao3c42a442008-04-30 00:52:26 -070045#include <linux/kthread.h>
46#include <linux/freezer.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070047
Russell Kinga09e64f2008-08-05 16:14:15 +010048#include <mach/hardware.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070049#include <asm/io.h>
50#include <asm/irq.h>
Nicolas Pitrebf1b8ab2005-06-23 21:56:45 +010051#include <asm/div64.h>
Russell Kinga09e64f2008-08-05 16:14:15 +010052#include <mach/pxa-regs.h>
Russell Kinga09e64f2008-08-05 16:14:15 +010053#include <mach/bitfield.h>
54#include <mach/pxafb.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070055
56/*
57 * Complain if VAR is out of range.
58 */
59#define DEBUG_VAR 1
60
61#include "pxafb.h"
62
63/* Bits which should not be set in machine configuration structures */
eric miaob0086ef2008-04-30 00:52:19 -070064#define LCCR0_INVALID_CONFIG_MASK (LCCR0_OUM | LCCR0_BM | LCCR0_QDM |\
65 LCCR0_DIS | LCCR0_EFM | LCCR0_IUM |\
66 LCCR0_SFM | LCCR0_LDM | LCCR0_ENB)
67
68#define LCCR3_INVALID_CONFIG_MASK (LCCR3_HSP | LCCR3_VSP |\
69 LCCR3_PCD | LCCR3_BPP)
Linus Torvalds1da177e2005-04-16 15:20:36 -070070
eric miaob0086ef2008-04-30 00:52:19 -070071static int pxafb_activate_var(struct fb_var_screeninfo *var,
72 struct pxafb_info *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070073static void set_ctrlr_state(struct pxafb_info *fbi, u_int state);
74
Eric Miao77e19672008-12-16 11:54:34 +080075static unsigned long video_mem_size = 0;
76
Eric Miaoa7535ba2008-04-30 00:52:24 -070077static inline unsigned long
78lcd_readl(struct pxafb_info *fbi, unsigned int off)
79{
80 return __raw_readl(fbi->mmio_base + off);
81}
82
83static inline void
84lcd_writel(struct pxafb_info *fbi, unsigned int off, unsigned long val)
85{
86 __raw_writel(val, fbi->mmio_base + off);
87}
88
Linus Torvalds1da177e2005-04-16 15:20:36 -070089static inline void pxafb_schedule_work(struct pxafb_info *fbi, u_int state)
90{
91 unsigned long flags;
92
93 local_irq_save(flags);
94 /*
95 * We need to handle two requests being made at the same time.
96 * There are two important cases:
eric miaob0086ef2008-04-30 00:52:19 -070097 * 1. When we are changing VT (C_REENABLE) while unblanking
98 * (C_ENABLE) We must perform the unblanking, which will
99 * do our REENABLE for us.
100 * 2. When we are blanking, but immediately unblank before
101 * we have blanked. We do the "REENABLE" thing here as
102 * well, just to be sure.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103 */
104 if (fbi->task_state == C_ENABLE && state == C_REENABLE)
105 state = (u_int) -1;
106 if (fbi->task_state == C_DISABLE && state == C_ENABLE)
107 state = C_REENABLE;
108
109 if (state != (u_int)-1) {
110 fbi->task_state = state;
111 schedule_work(&fbi->task);
112 }
113 local_irq_restore(flags);
114}
115
116static inline u_int chan_to_field(u_int chan, struct fb_bitfield *bf)
117{
118 chan &= 0xffff;
119 chan >>= 16 - bf->length;
120 return chan << bf->offset;
121}
122
123static int
124pxafb_setpalettereg(u_int regno, u_int red, u_int green, u_int blue,
125 u_int trans, struct fb_info *info)
126{
127 struct pxafb_info *fbi = (struct pxafb_info *)info;
Hans J. Koch9ffa7392007-10-16 01:28:41 -0700128 u_int val;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129
Hans J. Koch9ffa7392007-10-16 01:28:41 -0700130 if (regno >= fbi->palette_size)
131 return 1;
132
133 if (fbi->fb.var.grayscale) {
134 fbi->palette_cpu[regno] = ((blue >> 8) & 0x00ff);
135 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136 }
Hans J. Koch9ffa7392007-10-16 01:28:41 -0700137
138 switch (fbi->lccr4 & LCCR4_PAL_FOR_MASK) {
139 case LCCR4_PAL_FOR_0:
140 val = ((red >> 0) & 0xf800);
141 val |= ((green >> 5) & 0x07e0);
142 val |= ((blue >> 11) & 0x001f);
143 fbi->palette_cpu[regno] = val;
144 break;
145 case LCCR4_PAL_FOR_1:
146 val = ((red << 8) & 0x00f80000);
147 val |= ((green >> 0) & 0x0000fc00);
148 val |= ((blue >> 8) & 0x000000f8);
eric miaob0086ef2008-04-30 00:52:19 -0700149 ((u32 *)(fbi->palette_cpu))[regno] = val;
Hans J. Koch9ffa7392007-10-16 01:28:41 -0700150 break;
151 case LCCR4_PAL_FOR_2:
152 val = ((red << 8) & 0x00fc0000);
153 val |= ((green >> 0) & 0x0000fc00);
154 val |= ((blue >> 8) & 0x000000fc);
eric miaob0086ef2008-04-30 00:52:19 -0700155 ((u32 *)(fbi->palette_cpu))[regno] = val;
Hans J. Koch9ffa7392007-10-16 01:28:41 -0700156 break;
157 }
158
159 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160}
161
162static int
163pxafb_setcolreg(u_int regno, u_int red, u_int green, u_int blue,
164 u_int trans, struct fb_info *info)
165{
166 struct pxafb_info *fbi = (struct pxafb_info *)info;
167 unsigned int val;
168 int ret = 1;
169
170 /*
171 * If inverse mode was selected, invert all the colours
172 * rather than the register number. The register number
173 * is what you poke into the framebuffer to produce the
174 * colour you requested.
175 */
176 if (fbi->cmap_inverse) {
177 red = 0xffff - red;
178 green = 0xffff - green;
179 blue = 0xffff - blue;
180 }
181
182 /*
183 * If greyscale is true, then we convert the RGB value
184 * to greyscale no matter what visual we are using.
185 */
186 if (fbi->fb.var.grayscale)
187 red = green = blue = (19595 * red + 38470 * green +
188 7471 * blue) >> 16;
189
190 switch (fbi->fb.fix.visual) {
191 case FB_VISUAL_TRUECOLOR:
192 /*
193 * 16-bit True Colour. We encode the RGB value
194 * according to the RGB bitfield information.
195 */
196 if (regno < 16) {
197 u32 *pal = fbi->fb.pseudo_palette;
198
199 val = chan_to_field(red, &fbi->fb.var.red);
200 val |= chan_to_field(green, &fbi->fb.var.green);
201 val |= chan_to_field(blue, &fbi->fb.var.blue);
202
203 pal[regno] = val;
204 ret = 0;
205 }
206 break;
207
208 case FB_VISUAL_STATIC_PSEUDOCOLOR:
209 case FB_VISUAL_PSEUDOCOLOR:
210 ret = pxafb_setpalettereg(regno, red, green, blue, trans, info);
211 break;
212 }
213
214 return ret;
215}
216
217/*
218 * pxafb_bpp_to_lccr3():
219 * Convert a bits per pixel value to the correct bit pattern for LCCR3
220 */
221static int pxafb_bpp_to_lccr3(struct fb_var_screeninfo *var)
222{
eric miaob0086ef2008-04-30 00:52:19 -0700223 int ret = 0;
224 switch (var->bits_per_pixel) {
225 case 1: ret = LCCR3_1BPP; break;
226 case 2: ret = LCCR3_2BPP; break;
227 case 4: ret = LCCR3_4BPP; break;
228 case 8: ret = LCCR3_8BPP; break;
229 case 16: ret = LCCR3_16BPP; break;
Stefan Schmidtc1450f12008-07-09 08:06:32 +0100230 case 24:
231 switch (var->red.length + var->green.length +
232 var->blue.length + var->transp.length) {
233 case 18: ret = LCCR3_18BPP_P | LCCR3_PDFOR_3; break;
234 case 19: ret = LCCR3_19BPP_P; break;
235 }
236 break;
237 case 32:
238 switch (var->red.length + var->green.length +
239 var->blue.length + var->transp.length) {
240 case 18: ret = LCCR3_18BPP | LCCR3_PDFOR_3; break;
241 case 19: ret = LCCR3_19BPP; break;
242 case 24: ret = LCCR3_24BPP | LCCR3_PDFOR_3; break;
243 case 25: ret = LCCR3_25BPP; break;
244 }
245 break;
eric miaob0086ef2008-04-30 00:52:19 -0700246 }
247 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248}
249
250#ifdef CONFIG_CPU_FREQ
251/*
252 * pxafb_display_dma_period()
253 * Calculate the minimum period (in picoseconds) between two DMA
254 * requests for the LCD controller. If we hit this, it means we're
255 * doing nothing but LCD DMA.
256 */
257static unsigned int pxafb_display_dma_period(struct fb_var_screeninfo *var)
258{
eric miaob0086ef2008-04-30 00:52:19 -0700259 /*
260 * Period = pixclock * bits_per_byte * bytes_per_transfer
261 * / memory_bits_per_pixel;
262 */
263 return var->pixclock * 8 * 16 / var->bits_per_pixel;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265#endif
266
267/*
Richard Purdied14b2722006-09-20 22:54:21 +0100268 * Select the smallest mode that allows the desired resolution to be
269 * displayed. If desired parameters can be rounded up.
270 */
eric miaob0086ef2008-04-30 00:52:19 -0700271static struct pxafb_mode_info *pxafb_getmode(struct pxafb_mach_info *mach,
272 struct fb_var_screeninfo *var)
Richard Purdied14b2722006-09-20 22:54:21 +0100273{
274 struct pxafb_mode_info *mode = NULL;
275 struct pxafb_mode_info *modelist = mach->modes;
276 unsigned int best_x = 0xffffffff, best_y = 0xffffffff;
277 unsigned int i;
278
eric miaob0086ef2008-04-30 00:52:19 -0700279 for (i = 0; i < mach->num_modes; i++) {
280 if (modelist[i].xres >= var->xres &&
281 modelist[i].yres >= var->yres &&
282 modelist[i].xres < best_x &&
283 modelist[i].yres < best_y &&
284 modelist[i].bpp >= var->bits_per_pixel) {
Richard Purdied14b2722006-09-20 22:54:21 +0100285 best_x = modelist[i].xres;
286 best_y = modelist[i].yres;
287 mode = &modelist[i];
288 }
289 }
290
291 return mode;
292}
293
eric miaob0086ef2008-04-30 00:52:19 -0700294static void pxafb_setmode(struct fb_var_screeninfo *var,
295 struct pxafb_mode_info *mode)
Richard Purdied14b2722006-09-20 22:54:21 +0100296{
297 var->xres = mode->xres;
298 var->yres = mode->yres;
299 var->bits_per_pixel = mode->bpp;
300 var->pixclock = mode->pixclock;
301 var->hsync_len = mode->hsync_len;
302 var->left_margin = mode->left_margin;
303 var->right_margin = mode->right_margin;
304 var->vsync_len = mode->vsync_len;
305 var->upper_margin = mode->upper_margin;
306 var->lower_margin = mode->lower_margin;
307 var->sync = mode->sync;
308 var->grayscale = mode->cmap_greyscale;
Richard Purdied14b2722006-09-20 22:54:21 +0100309}
310
311/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312 * pxafb_check_var():
313 * Get the video params out of 'var'. If a value doesn't fit, round it up,
314 * if it's too big, return -EINVAL.
315 *
316 * Round up in the following order: bits_per_pixel, xres,
317 * yres, xres_virtual, yres_virtual, xoffset, yoffset, grayscale,
318 * bitfields, horizontal timing, vertical timing.
319 */
320static int pxafb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
321{
322 struct pxafb_info *fbi = (struct pxafb_info *)info;
Richard Purdied14b2722006-09-20 22:54:21 +0100323 struct pxafb_mach_info *inf = fbi->dev->platform_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324
325 if (var->xres < MIN_XRES)
326 var->xres = MIN_XRES;
327 if (var->yres < MIN_YRES)
328 var->yres = MIN_YRES;
Richard Purdied14b2722006-09-20 22:54:21 +0100329
330 if (inf->fixed_modes) {
331 struct pxafb_mode_info *mode;
332
333 mode = pxafb_getmode(inf, var);
334 if (!mode)
335 return -EINVAL;
336 pxafb_setmode(var, mode);
337 } else {
338 if (var->xres > inf->modes->xres)
339 return -EINVAL;
340 if (var->yres > inf->modes->yres)
341 return -EINVAL;
342 if (var->bits_per_pixel > inf->modes->bpp)
343 return -EINVAL;
344 }
345
Eric Miao7e4b19c2008-12-17 14:56:54 +0800346 /* we don't support xpan, force xres_virtual to be equal to xres */
347 var->xres_virtual = var->xres;
348
349 if (var->accel_flags & FB_ACCELF_TEXT)
350 var->yres_virtual = fbi->fb.fix.smem_len /
351 (var->xres_virtual * var->bits_per_pixel / 8);
352 else
353 var->yres_virtual = max(var->yres_virtual, var->yres);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354
eric miaob0086ef2008-04-30 00:52:19 -0700355 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356 * Setup the RGB parameters for this display.
357 *
358 * The pixel packing format is described on page 7-11 of the
359 * PXA2XX Developer's Manual.
eric miaob0086ef2008-04-30 00:52:19 -0700360 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700361 if (var->bits_per_pixel == 16) {
362 var->red.offset = 11; var->red.length = 5;
363 var->green.offset = 5; var->green.length = 6;
364 var->blue.offset = 0; var->blue.length = 5;
365 var->transp.offset = var->transp.length = 0;
Stefan Schmidtc1450f12008-07-09 08:06:32 +0100366 } else if (var->bits_per_pixel > 16) {
367 struct pxafb_mode_info *mode;
368
369 mode = pxafb_getmode(inf, var);
370 if (!mode)
371 return -EINVAL;
372
373 switch (mode->depth) {
374 case 18: /* RGB666 */
375 var->transp.offset = var->transp.length = 0;
376 var->red.offset = 12; var->red.length = 6;
377 var->green.offset = 6; var->green.length = 6;
378 var->blue.offset = 0; var->blue.length = 6;
379 break;
380 case 19: /* RGBT666 */
381 var->transp.offset = 18; var->transp.length = 1;
382 var->red.offset = 12; var->red.length = 6;
383 var->green.offset = 6; var->green.length = 6;
384 var->blue.offset = 0; var->blue.length = 6;
385 break;
386 case 24: /* RGB888 */
387 var->transp.offset = var->transp.length = 0;
388 var->red.offset = 16; var->red.length = 8;
389 var->green.offset = 8; var->green.length = 8;
390 var->blue.offset = 0; var->blue.length = 8;
391 break;
392 case 25: /* RGBT888 */
393 var->transp.offset = 24; var->transp.length = 1;
394 var->red.offset = 16; var->red.length = 8;
395 var->green.offset = 8; var->green.length = 8;
396 var->blue.offset = 0; var->blue.length = 8;
397 break;
398 default:
399 return -EINVAL;
400 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401 } else {
eric miaob0086ef2008-04-30 00:52:19 -0700402 var->red.offset = var->green.offset = 0;
403 var->blue.offset = var->transp.offset = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404 var->red.length = 8;
405 var->green.length = 8;
406 var->blue.length = 8;
407 var->transp.length = 0;
408 }
409
410#ifdef CONFIG_CPU_FREQ
Russell King78d3cfd2008-05-17 22:51:14 +0100411 pr_debug("pxafb: dma period = %d ps\n",
412 pxafb_display_dma_period(var));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413#endif
414
415 return 0;
416}
417
418static inline void pxafb_set_truecolor(u_int is_true_color)
419{
eric miaob0086ef2008-04-30 00:52:19 -0700420 /* do your machine-specific setup if needed */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421}
422
423/*
424 * pxafb_set_par():
425 * Set the user defined part of the display for the specified console
426 */
427static int pxafb_set_par(struct fb_info *info)
428{
429 struct pxafb_info *fbi = (struct pxafb_info *)info;
430 struct fb_var_screeninfo *var = &info->var;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431
Stefan Schmidtc1450f12008-07-09 08:06:32 +0100432 if (var->bits_per_pixel >= 16)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700433 fbi->fb.fix.visual = FB_VISUAL_TRUECOLOR;
434 else if (!fbi->cmap_static)
435 fbi->fb.fix.visual = FB_VISUAL_PSEUDOCOLOR;
436 else {
437 /*
438 * Some people have weird ideas about wanting static
439 * pseudocolor maps. I suspect their user space
440 * applications are broken.
441 */
442 fbi->fb.fix.visual = FB_VISUAL_STATIC_PSEUDOCOLOR;
443 }
444
445 fbi->fb.fix.line_length = var->xres_virtual *
446 var->bits_per_pixel / 8;
Stefan Schmidtc1450f12008-07-09 08:06:32 +0100447 if (var->bits_per_pixel >= 16)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700448 fbi->palette_size = 0;
449 else
eric miaob0086ef2008-04-30 00:52:19 -0700450 fbi->palette_size = var->bits_per_pixel == 1 ?
451 4 : 1 << var->bits_per_pixel;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700452
eric miao2c42dd82008-04-30 00:52:21 -0700453 fbi->palette_cpu = (u16 *)&fbi->dma_buff->palette[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700454
455 /*
456 * Set (any) board control register to handle new color depth
457 */
458 pxafb_set_truecolor(fbi->fb.fix.visual == FB_VISUAL_TRUECOLOR);
459
Stefan Schmidtc1450f12008-07-09 08:06:32 +0100460 if (fbi->fb.var.bits_per_pixel >= 16)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461 fb_dealloc_cmap(&fbi->fb.cmap);
462 else
463 fb_alloc_cmap(&fbi->fb.cmap, 1<<fbi->fb.var.bits_per_pixel, 0);
464
465 pxafb_activate_var(var, fbi);
466
467 return 0;
468}
469
470/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471 * pxafb_blank():
472 * Blank the display by setting all palette values to zero. Note, the
473 * 16 bpp mode does not really use the palette, so this will not
474 * blank the display in all modes.
475 */
476static int pxafb_blank(int blank, struct fb_info *info)
477{
478 struct pxafb_info *fbi = (struct pxafb_info *)info;
479 int i;
480
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481 switch (blank) {
482 case FB_BLANK_POWERDOWN:
483 case FB_BLANK_VSYNC_SUSPEND:
484 case FB_BLANK_HSYNC_SUSPEND:
485 case FB_BLANK_NORMAL:
486 if (fbi->fb.fix.visual == FB_VISUAL_PSEUDOCOLOR ||
487 fbi->fb.fix.visual == FB_VISUAL_STATIC_PSEUDOCOLOR)
488 for (i = 0; i < fbi->palette_size; i++)
489 pxafb_setpalettereg(i, 0, 0, 0, 0, info);
490
491 pxafb_schedule_work(fbi, C_DISABLE);
eric miaob0086ef2008-04-30 00:52:19 -0700492 /* TODO if (pxafb_blank_helper) pxafb_blank_helper(blank); */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700493 break;
494
495 case FB_BLANK_UNBLANK:
eric miaob0086ef2008-04-30 00:52:19 -0700496 /* TODO if (pxafb_blank_helper) pxafb_blank_helper(blank); */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497 if (fbi->fb.fix.visual == FB_VISUAL_PSEUDOCOLOR ||
498 fbi->fb.fix.visual == FB_VISUAL_STATIC_PSEUDOCOLOR)
499 fb_set_cmap(&fbi->fb.cmap, info);
500 pxafb_schedule_work(fbi, C_ENABLE);
501 }
502 return 0;
503}
504
Linus Torvalds1da177e2005-04-16 15:20:36 -0700505static struct fb_ops pxafb_ops = {
506 .owner = THIS_MODULE,
507 .fb_check_var = pxafb_check_var,
508 .fb_set_par = pxafb_set_par,
509 .fb_setcolreg = pxafb_setcolreg,
510 .fb_fillrect = cfb_fillrect,
511 .fb_copyarea = cfb_copyarea,
512 .fb_imageblit = cfb_imageblit,
513 .fb_blank = pxafb_blank,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514};
515
516/*
517 * Calculate the PCD value from the clock rate (in picoseconds).
518 * We take account of the PPCR clock setting.
519 * From PXA Developer's Manual:
520 *
521 * PixelClock = LCLK
522 * -------------
523 * 2 ( PCD + 1 )
524 *
525 * PCD = LCLK
526 * ------------- - 1
527 * 2(PixelClock)
528 *
529 * Where:
530 * LCLK = LCD/Memory Clock
531 * PCD = LCCR3[7:0]
532 *
533 * PixelClock here is in Hz while the pixclock argument given is the
534 * period in picoseconds. Hence PixelClock = 1 / ( pixclock * 10^-12 )
535 *
536 * The function get_lclk_frequency_10khz returns LCLK in units of
537 * 10khz. Calling the result of this function lclk gives us the
538 * following
539 *
540 * PCD = (lclk * 10^4 ) * ( pixclock * 10^-12 )
541 * -------------------------------------- - 1
542 * 2
543 *
544 * Factoring the 10^4 and 10^-12 out gives 10^-8 == 1 / 100000000 as used below.
545 */
eric miaob0086ef2008-04-30 00:52:19 -0700546static inline unsigned int get_pcd(struct pxafb_info *fbi,
547 unsigned int pixclock)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700548{
549 unsigned long long pcd;
550
551 /* FIXME: Need to take into account Double Pixel Clock mode
Russell King72e35242007-08-20 10:18:42 +0100552 * (DPC) bit? or perhaps set it based on the various clock
553 * speeds */
554 pcd = (unsigned long long)(clk_get_rate(fbi->clk) / 10000);
555 pcd *= pixclock;
Nicolas Pitrebf1b8ab2005-06-23 21:56:45 +0100556 do_div(pcd, 100000000 * 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557 /* no need for this, since we should subtract 1 anyway. they cancel */
558 /* pcd += 1; */ /* make up for integer math truncations */
559 return (unsigned int)pcd;
560}
561
562/*
Richard Purdieba44cd22005-09-09 13:10:03 -0700563 * Some touchscreens need hsync information from the video driver to
Russell King72e35242007-08-20 10:18:42 +0100564 * function correctly. We export it here. Note that 'hsync_time' and
565 * the value returned from pxafb_get_hsync_time() is the *reciprocal*
566 * of the hsync period in seconds.
Richard Purdieba44cd22005-09-09 13:10:03 -0700567 */
568static inline void set_hsync_time(struct pxafb_info *fbi, unsigned int pcd)
569{
Russell King72e35242007-08-20 10:18:42 +0100570 unsigned long htime;
Richard Purdieba44cd22005-09-09 13:10:03 -0700571
572 if ((pcd == 0) || (fbi->fb.var.hsync_len == 0)) {
eric miaob0086ef2008-04-30 00:52:19 -0700573 fbi->hsync_time = 0;
Richard Purdieba44cd22005-09-09 13:10:03 -0700574 return;
575 }
576
Russell King72e35242007-08-20 10:18:42 +0100577 htime = clk_get_rate(fbi->clk) / (pcd * fbi->fb.var.hsync_len);
578
Richard Purdieba44cd22005-09-09 13:10:03 -0700579 fbi->hsync_time = htime;
580}
581
582unsigned long pxafb_get_hsync_time(struct device *dev)
583{
584 struct pxafb_info *fbi = dev_get_drvdata(dev);
585
586 /* If display is blanked/suspended, hsync isn't active */
587 if (!fbi || (fbi->state != C_ENABLE))
588 return 0;
589
590 return fbi->hsync_time;
591}
592EXPORT_SYMBOL(pxafb_get_hsync_time);
593
eric miao2c42dd82008-04-30 00:52:21 -0700594static int setup_frame_dma(struct pxafb_info *fbi, int dma, int pal,
595 unsigned int offset, size_t size)
596{
597 struct pxafb_dma_descriptor *dma_desc, *pal_desc;
598 unsigned int dma_desc_off, pal_desc_off;
599
600 if (dma < 0 || dma >= DMA_MAX)
601 return -EINVAL;
602
603 dma_desc = &fbi->dma_buff->dma_desc[dma];
604 dma_desc_off = offsetof(struct pxafb_dma_buff, dma_desc[dma]);
605
Eric Miao77e19672008-12-16 11:54:34 +0800606 dma_desc->fsadr = fbi->video_mem_phys + offset;
eric miao2c42dd82008-04-30 00:52:21 -0700607 dma_desc->fidr = 0;
608 dma_desc->ldcmd = size;
609
610 if (pal < 0 || pal >= PAL_MAX) {
611 dma_desc->fdadr = fbi->dma_buff_phys + dma_desc_off;
612 fbi->fdadr[dma] = fbi->dma_buff_phys + dma_desc_off;
613 } else {
Jürgen Schindele62cfcf42008-06-11 19:56:06 +0100614 pal_desc = &fbi->dma_buff->pal_desc[pal];
615 pal_desc_off = offsetof(struct pxafb_dma_buff, pal_desc[pal]);
eric miao2c42dd82008-04-30 00:52:21 -0700616
617 pal_desc->fsadr = fbi->dma_buff_phys + pal * PALETTE_SIZE;
618 pal_desc->fidr = 0;
619
620 if ((fbi->lccr4 & LCCR4_PAL_FOR_MASK) == LCCR4_PAL_FOR_0)
621 pal_desc->ldcmd = fbi->palette_size * sizeof(u16);
622 else
623 pal_desc->ldcmd = fbi->palette_size * sizeof(u32);
624
625 pal_desc->ldcmd |= LDCMD_PAL;
626
627 /* flip back and forth between palette and frame buffer */
628 pal_desc->fdadr = fbi->dma_buff_phys + dma_desc_off;
629 dma_desc->fdadr = fbi->dma_buff_phys + pal_desc_off;
630 fbi->fdadr[dma] = fbi->dma_buff_phys + dma_desc_off;
631 }
632
633 return 0;
634}
635
Eric Miao3c42a442008-04-30 00:52:26 -0700636#ifdef CONFIG_FB_PXA_SMARTPANEL
637static int setup_smart_dma(struct pxafb_info *fbi)
638{
639 struct pxafb_dma_descriptor *dma_desc;
640 unsigned long dma_desc_off, cmd_buff_off;
641
642 dma_desc = &fbi->dma_buff->dma_desc[DMA_CMD];
643 dma_desc_off = offsetof(struct pxafb_dma_buff, dma_desc[DMA_CMD]);
644 cmd_buff_off = offsetof(struct pxafb_dma_buff, cmd_buff);
645
646 dma_desc->fdadr = fbi->dma_buff_phys + dma_desc_off;
647 dma_desc->fsadr = fbi->dma_buff_phys + cmd_buff_off;
648 dma_desc->fidr = 0;
649 dma_desc->ldcmd = fbi->n_smart_cmds * sizeof(uint16_t);
650
651 fbi->fdadr[DMA_CMD] = dma_desc->fdadr;
652 return 0;
653}
654
655int pxafb_smart_flush(struct fb_info *info)
656{
657 struct pxafb_info *fbi = container_of(info, struct pxafb_info, fb);
658 uint32_t prsr;
659 int ret = 0;
660
661 /* disable controller until all registers are set up */
662 lcd_writel(fbi, LCCR0, fbi->reg_lccr0 & ~LCCR0_ENB);
663
664 /* 1. make it an even number of commands to align on 32-bit boundary
665 * 2. add the interrupt command to the end of the chain so we can
666 * keep track of the end of the transfer
667 */
668
669 while (fbi->n_smart_cmds & 1)
670 fbi->smart_cmds[fbi->n_smart_cmds++] = SMART_CMD_NOOP;
671
672 fbi->smart_cmds[fbi->n_smart_cmds++] = SMART_CMD_INTERRUPT;
673 fbi->smart_cmds[fbi->n_smart_cmds++] = SMART_CMD_WAIT_FOR_VSYNC;
674 setup_smart_dma(fbi);
675
676 /* continue to execute next command */
677 prsr = lcd_readl(fbi, PRSR) | PRSR_ST_OK | PRSR_CON_NT;
678 lcd_writel(fbi, PRSR, prsr);
679
680 /* stop the processor in case it executed "wait for sync" cmd */
681 lcd_writel(fbi, CMDCR, 0x0001);
682
683 /* don't send interrupts for fifo underruns on channel 6 */
684 lcd_writel(fbi, LCCR5, LCCR5_IUM(6));
685
686 lcd_writel(fbi, LCCR1, fbi->reg_lccr1);
687 lcd_writel(fbi, LCCR2, fbi->reg_lccr2);
688 lcd_writel(fbi, LCCR3, fbi->reg_lccr3);
689 lcd_writel(fbi, FDADR0, fbi->fdadr[0]);
690 lcd_writel(fbi, FDADR6, fbi->fdadr[6]);
691
692 /* begin sending */
693 lcd_writel(fbi, LCCR0, fbi->reg_lccr0 | LCCR0_ENB);
694
695 if (wait_for_completion_timeout(&fbi->command_done, HZ/2) == 0) {
696 pr_warning("%s: timeout waiting for command done\n",
697 __func__);
698 ret = -ETIMEDOUT;
699 }
700
701 /* quick disable */
702 prsr = lcd_readl(fbi, PRSR) & ~(PRSR_ST_OK | PRSR_CON_NT);
703 lcd_writel(fbi, PRSR, prsr);
704 lcd_writel(fbi, LCCR0, fbi->reg_lccr0 & ~LCCR0_ENB);
705 lcd_writel(fbi, FDADR6, 0);
706 fbi->n_smart_cmds = 0;
707 return ret;
708}
709
710int pxafb_smart_queue(struct fb_info *info, uint16_t *cmds, int n_cmds)
711{
712 int i;
713 struct pxafb_info *fbi = container_of(info, struct pxafb_info, fb);
714
Eric Miao69bdea72008-12-08 18:46:00 +0800715 for (i = 0; i < n_cmds; i++, cmds++) {
716 /* if it is a software delay, flush and delay */
717 if ((*cmds & 0xff00) == SMART_CMD_DELAY) {
718 pxafb_smart_flush(info);
719 mdelay(*cmds & 0xff);
720 continue;
721 }
722
723 /* leave 2 commands for INTERRUPT and WAIT_FOR_SYNC */
Eric Miao3c42a442008-04-30 00:52:26 -0700724 if (fbi->n_smart_cmds == CMD_BUFF_SIZE - 8)
725 pxafb_smart_flush(info);
726
Eric Miao69bdea72008-12-08 18:46:00 +0800727 fbi->smart_cmds[fbi->n_smart_cmds++] = *cmds;
Eric Miao3c42a442008-04-30 00:52:26 -0700728 }
729
730 return 0;
731}
732
733static unsigned int __smart_timing(unsigned time_ns, unsigned long lcd_clk)
734{
735 unsigned int t = (time_ns * (lcd_clk / 1000000) / 1000);
736 return (t == 0) ? 1 : t;
737}
738
739static void setup_smart_timing(struct pxafb_info *fbi,
740 struct fb_var_screeninfo *var)
741{
742 struct pxafb_mach_info *inf = fbi->dev->platform_data;
743 struct pxafb_mode_info *mode = &inf->modes[0];
744 unsigned long lclk = clk_get_rate(fbi->clk);
745 unsigned t1, t2, t3, t4;
746
747 t1 = max(mode->a0csrd_set_hld, mode->a0cswr_set_hld);
748 t2 = max(mode->rd_pulse_width, mode->wr_pulse_width);
749 t3 = mode->op_hold_time;
750 t4 = mode->cmd_inh_time;
751
752 fbi->reg_lccr1 =
753 LCCR1_DisWdth(var->xres) |
754 LCCR1_BegLnDel(__smart_timing(t1, lclk)) |
755 LCCR1_EndLnDel(__smart_timing(t2, lclk)) |
756 LCCR1_HorSnchWdth(__smart_timing(t3, lclk));
757
758 fbi->reg_lccr2 = LCCR2_DisHght(var->yres);
Eric Miaoc1f99c22008-12-08 18:35:03 +0800759 fbi->reg_lccr3 = fbi->lccr3 | LCCR3_PixClkDiv(__smart_timing(t4, lclk));
760 fbi->reg_lccr3 |= (var->sync & FB_SYNC_HOR_HIGH_ACT) ? LCCR3_HSP : 0;
761 fbi->reg_lccr3 |= (var->sync & FB_SYNC_VERT_HIGH_ACT) ? LCCR3_VSP : 0;
Eric Miao3c42a442008-04-30 00:52:26 -0700762
763 /* FIXME: make this configurable */
764 fbi->reg_cmdcr = 1;
765}
766
767static int pxafb_smart_thread(void *arg)
768{
Eric Miao7f1133c2008-04-30 00:52:27 -0700769 struct pxafb_info *fbi = arg;
Eric Miao3c42a442008-04-30 00:52:26 -0700770 struct pxafb_mach_info *inf = fbi->dev->platform_data;
771
772 if (!fbi || !inf->smart_update) {
773 pr_err("%s: not properly initialized, thread terminated\n",
774 __func__);
775 return -EINVAL;
776 }
777
778 pr_debug("%s(): task starting\n", __func__);
779
780 set_freezable();
781 while (!kthread_should_stop()) {
782
783 if (try_to_freeze())
784 continue;
785
Eric Miao07f651c2008-12-08 18:51:01 +0800786 mutex_lock(&fbi->ctrlr_lock);
787
Eric Miao3c42a442008-04-30 00:52:26 -0700788 if (fbi->state == C_ENABLE) {
789 inf->smart_update(&fbi->fb);
790 complete(&fbi->refresh_done);
791 }
792
Eric Miao07f651c2008-12-08 18:51:01 +0800793 mutex_unlock(&fbi->ctrlr_lock);
794
Eric Miao3c42a442008-04-30 00:52:26 -0700795 set_current_state(TASK_INTERRUPTIBLE);
796 schedule_timeout(30 * HZ / 1000);
797 }
798
799 pr_debug("%s(): task ending\n", __func__);
800 return 0;
801}
802
803static int pxafb_smart_init(struct pxafb_info *fbi)
804{
Eric Miao07df1c42008-12-04 11:14:11 +0800805 if (!(fbi->lccr0 & LCCR0_LCDT))
Eric Miao6cc4abe2008-11-11 21:47:07 +0800806 return 0;
807
Eric Miao07df1c42008-12-04 11:14:11 +0800808 fbi->smart_cmds = (uint16_t *) fbi->dma_buff->cmd_buff;
809 fbi->n_smart_cmds = 0;
810
811 init_completion(&fbi->command_done);
812 init_completion(&fbi->refresh_done);
813
Eric Miao3c42a442008-04-30 00:52:26 -0700814 fbi->smart_thread = kthread_run(pxafb_smart_thread, fbi,
815 "lcd_refresh");
816 if (IS_ERR(fbi->smart_thread)) {
Eric Miao07df1c42008-12-04 11:14:11 +0800817 pr_err("%s: unable to create kernel thread\n", __func__);
Eric Miao3c42a442008-04-30 00:52:26 -0700818 return PTR_ERR(fbi->smart_thread);
819 }
Eric Miaoa5718a12008-11-11 21:50:39 +0800820
Eric Miao3c42a442008-04-30 00:52:26 -0700821 return 0;
822}
823#else
824int pxafb_smart_queue(struct fb_info *info, uint16_t *cmds, int n_cmds)
825{
826 return 0;
827}
828
829int pxafb_smart_flush(struct fb_info *info)
830{
831 return 0;
832}
Eric Miao07df1c42008-12-04 11:14:11 +0800833
834static inline int pxafb_smart_init(struct pxafb_info *fbi) { return 0; }
835#endif /* CONFIG_FB_PXA_SMARTPANEL */
Eric Miao3c42a442008-04-30 00:52:26 -0700836
Eric Miao90eabbf2008-04-30 00:52:25 -0700837static void setup_parallel_timing(struct pxafb_info *fbi,
838 struct fb_var_screeninfo *var)
839{
840 unsigned int lines_per_panel, pcd = get_pcd(fbi, var->pixclock);
841
842 fbi->reg_lccr1 =
843 LCCR1_DisWdth(var->xres) +
844 LCCR1_HorSnchWdth(var->hsync_len) +
845 LCCR1_BegLnDel(var->left_margin) +
846 LCCR1_EndLnDel(var->right_margin);
847
848 /*
849 * If we have a dual scan LCD, we need to halve
850 * the YRES parameter.
851 */
852 lines_per_panel = var->yres;
853 if ((fbi->lccr0 & LCCR0_SDS) == LCCR0_Dual)
854 lines_per_panel /= 2;
855
856 fbi->reg_lccr2 =
857 LCCR2_DisHght(lines_per_panel) +
858 LCCR2_VrtSnchWdth(var->vsync_len) +
859 LCCR2_BegFrmDel(var->upper_margin) +
860 LCCR2_EndFrmDel(var->lower_margin);
861
862 fbi->reg_lccr3 = fbi->lccr3 |
863 (var->sync & FB_SYNC_HOR_HIGH_ACT ?
864 LCCR3_HorSnchH : LCCR3_HorSnchL) |
865 (var->sync & FB_SYNC_VERT_HIGH_ACT ?
866 LCCR3_VrtSnchH : LCCR3_VrtSnchL);
867
868 if (pcd) {
869 fbi->reg_lccr3 |= LCCR3_PixClkDiv(pcd);
870 set_hsync_time(fbi, pcd);
871 }
872}
873
Richard Purdieba44cd22005-09-09 13:10:03 -0700874/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700875 * pxafb_activate_var():
eric miaob0086ef2008-04-30 00:52:19 -0700876 * Configures LCD Controller based on entries in var parameter.
877 * Settings are only written to the controller if changes were made.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700878 */
eric miaob0086ef2008-04-30 00:52:19 -0700879static int pxafb_activate_var(struct fb_var_screeninfo *var,
880 struct pxafb_info *fbi)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700881{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700882 u_long flags;
Eric Miao7e4b19c2008-12-17 14:56:54 +0800883 size_t nbytes, offset;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700884
Linus Torvalds1da177e2005-04-16 15:20:36 -0700885#if DEBUG_VAR
Eric Miao3c42a442008-04-30 00:52:26 -0700886 if (!(fbi->lccr0 & LCCR0_LCDT)) {
887 if (var->xres < 16 || var->xres > 1024)
888 printk(KERN_ERR "%s: invalid xres %d\n",
889 fbi->fb.fix.id, var->xres);
890 switch (var->bits_per_pixel) {
891 case 1:
892 case 2:
893 case 4:
894 case 8:
895 case 16:
Stefan Schmidtc1450f12008-07-09 08:06:32 +0100896 case 24:
897 case 32:
Eric Miao3c42a442008-04-30 00:52:26 -0700898 break;
899 default:
900 printk(KERN_ERR "%s: invalid bit depth %d\n",
901 fbi->fb.fix.id, var->bits_per_pixel);
902 break;
903 }
904
905 if (var->hsync_len < 1 || var->hsync_len > 64)
906 printk(KERN_ERR "%s: invalid hsync_len %d\n",
907 fbi->fb.fix.id, var->hsync_len);
908 if (var->left_margin < 1 || var->left_margin > 255)
909 printk(KERN_ERR "%s: invalid left_margin %d\n",
910 fbi->fb.fix.id, var->left_margin);
911 if (var->right_margin < 1 || var->right_margin > 255)
912 printk(KERN_ERR "%s: invalid right_margin %d\n",
913 fbi->fb.fix.id, var->right_margin);
914 if (var->yres < 1 || var->yres > 1024)
915 printk(KERN_ERR "%s: invalid yres %d\n",
916 fbi->fb.fix.id, var->yres);
917 if (var->vsync_len < 1 || var->vsync_len > 64)
918 printk(KERN_ERR "%s: invalid vsync_len %d\n",
919 fbi->fb.fix.id, var->vsync_len);
920 if (var->upper_margin < 0 || var->upper_margin > 255)
921 printk(KERN_ERR "%s: invalid upper_margin %d\n",
922 fbi->fb.fix.id, var->upper_margin);
923 if (var->lower_margin < 0 || var->lower_margin > 255)
924 printk(KERN_ERR "%s: invalid lower_margin %d\n",
925 fbi->fb.fix.id, var->lower_margin);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700926 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700927#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700928 /* Update shadow copy atomically */
929 local_irq_save(flags);
930
Eric Miao3c42a442008-04-30 00:52:26 -0700931#ifdef CONFIG_FB_PXA_SMARTPANEL
932 if (fbi->lccr0 & LCCR0_LCDT)
933 setup_smart_timing(fbi, var);
934 else
935#endif
936 setup_parallel_timing(fbi, var);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700937
Eric Miao90eabbf2008-04-30 00:52:25 -0700938 fbi->reg_lccr0 = fbi->lccr0 |
939 (LCCR0_LDM | LCCR0_SFM | LCCR0_IUM | LCCR0_EFM |
940 LCCR0_QDM | LCCR0_BM | LCCR0_OUM);
941
942 fbi->reg_lccr3 |= pxafb_bpp_to_lccr3(var);
943
Eric Miao7e4b19c2008-12-17 14:56:54 +0800944 nbytes = fbi->fb.fix.line_length * var->yres;
945 offset = fbi->fb.fix.line_length * var->yoffset;
Eric Miao90eabbf2008-04-30 00:52:25 -0700946
947 if ((fbi->lccr0 & LCCR0_SDS) == LCCR0_Dual) {
948 nbytes = nbytes / 2;
Eric Miao7e4b19c2008-12-17 14:56:54 +0800949 setup_frame_dma(fbi, DMA_LOWER, PAL_NONE, offset + nbytes, nbytes);
Eric Miao90eabbf2008-04-30 00:52:25 -0700950 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700951
Eric Miao3c42a442008-04-30 00:52:26 -0700952 if ((var->bits_per_pixel >= 16) || (fbi->lccr0 & LCCR0_LCDT))
Eric Miao7e4b19c2008-12-17 14:56:54 +0800953 setup_frame_dma(fbi, DMA_BASE, PAL_NONE, offset, nbytes);
Hans J. Koch9ffa7392007-10-16 01:28:41 -0700954 else
Eric Miao7e4b19c2008-12-17 14:56:54 +0800955 setup_frame_dma(fbi, DMA_BASE, PAL_BASE, offset, nbytes);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700956
Eric Miaoa7535ba2008-04-30 00:52:24 -0700957 fbi->reg_lccr4 = lcd_readl(fbi, LCCR4) & ~LCCR4_PAL_FOR_MASK;
Hans J. Koch9ffa7392007-10-16 01:28:41 -0700958 fbi->reg_lccr4 |= (fbi->lccr4 & LCCR4_PAL_FOR_MASK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700959 local_irq_restore(flags);
960
961 /*
962 * Only update the registers if the controller is enabled
963 * and something has changed.
964 */
Eric Miaoa7535ba2008-04-30 00:52:24 -0700965 if ((lcd_readl(fbi, LCCR0) != fbi->reg_lccr0) ||
966 (lcd_readl(fbi, LCCR1) != fbi->reg_lccr1) ||
967 (lcd_readl(fbi, LCCR2) != fbi->reg_lccr2) ||
968 (lcd_readl(fbi, LCCR3) != fbi->reg_lccr3) ||
969 (lcd_readl(fbi, FDADR0) != fbi->fdadr[0]) ||
970 (lcd_readl(fbi, FDADR1) != fbi->fdadr[1]))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700971 pxafb_schedule_work(fbi, C_REENABLE);
972
973 return 0;
974}
975
976/*
977 * NOTE! The following functions are purely helpers for set_ctrlr_state.
978 * Do not call them directly; set_ctrlr_state does the correct serialisation
979 * to ensure that things happen in the right way 100% of time time.
980 * -- rmk
981 */
982static inline void __pxafb_backlight_power(struct pxafb_info *fbi, int on)
983{
Russell Kingca5da712005-09-29 09:44:54 +0100984 pr_debug("pxafb: backlight o%s\n", on ? "n" : "ff");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700985
Eric Miaoa5718a12008-11-11 21:50:39 +0800986 if (fbi->backlight_power)
987 fbi->backlight_power(on);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700988}
989
990static inline void __pxafb_lcd_power(struct pxafb_info *fbi, int on)
991{
Russell Kingca5da712005-09-29 09:44:54 +0100992 pr_debug("pxafb: LCD power o%s\n", on ? "n" : "ff");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700993
Eric Miaoa5718a12008-11-11 21:50:39 +0800994 if (fbi->lcd_power)
995 fbi->lcd_power(on, &fbi->fb.var);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700996}
997
Linus Torvalds1da177e2005-04-16 15:20:36 -0700998static void pxafb_enable_controller(struct pxafb_info *fbi)
999{
Russell Kingca5da712005-09-29 09:44:54 +01001000 pr_debug("pxafb: Enabling LCD controller\n");
eric miao2c42dd82008-04-30 00:52:21 -07001001 pr_debug("fdadr0 0x%08x\n", (unsigned int) fbi->fdadr[0]);
1002 pr_debug("fdadr1 0x%08x\n", (unsigned int) fbi->fdadr[1]);
Russell Kingca5da712005-09-29 09:44:54 +01001003 pr_debug("reg_lccr0 0x%08x\n", (unsigned int) fbi->reg_lccr0);
1004 pr_debug("reg_lccr1 0x%08x\n", (unsigned int) fbi->reg_lccr1);
1005 pr_debug("reg_lccr2 0x%08x\n", (unsigned int) fbi->reg_lccr2);
1006 pr_debug("reg_lccr3 0x%08x\n", (unsigned int) fbi->reg_lccr3);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001007
Nicolas Pitre8d372262005-08-10 16:45:13 +01001008 /* enable LCD controller clock */
Russell King72e35242007-08-20 10:18:42 +01001009 clk_enable(fbi->clk);
Nicolas Pitre8d372262005-08-10 16:45:13 +01001010
Eric Miao3c42a442008-04-30 00:52:26 -07001011 if (fbi->lccr0 & LCCR0_LCDT)
1012 return;
1013
Linus Torvalds1da177e2005-04-16 15:20:36 -07001014 /* Sequence from 11.7.10 */
Eric Miaoa7535ba2008-04-30 00:52:24 -07001015 lcd_writel(fbi, LCCR3, fbi->reg_lccr3);
1016 lcd_writel(fbi, LCCR2, fbi->reg_lccr2);
1017 lcd_writel(fbi, LCCR1, fbi->reg_lccr1);
1018 lcd_writel(fbi, LCCR0, fbi->reg_lccr0 & ~LCCR0_ENB);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001019
Eric Miaoa7535ba2008-04-30 00:52:24 -07001020 lcd_writel(fbi, FDADR0, fbi->fdadr[0]);
1021 lcd_writel(fbi, FDADR1, fbi->fdadr[1]);
1022 lcd_writel(fbi, LCCR0, fbi->reg_lccr0 | LCCR0_ENB);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001023}
1024
1025static void pxafb_disable_controller(struct pxafb_info *fbi)
1026{
eric miaoce4fb7b2008-04-30 00:52:21 -07001027 uint32_t lccr0;
1028
Eric Miao3c42a442008-04-30 00:52:26 -07001029#ifdef CONFIG_FB_PXA_SMARTPANEL
1030 if (fbi->lccr0 & LCCR0_LCDT) {
1031 wait_for_completion_timeout(&fbi->refresh_done,
1032 200 * HZ / 1000);
1033 return;
1034 }
1035#endif
1036
eric miaoce4fb7b2008-04-30 00:52:21 -07001037 /* Clear LCD Status Register */
Eric Miaoa7535ba2008-04-30 00:52:24 -07001038 lcd_writel(fbi, LCSR, 0xffffffff);
eric miaoce4fb7b2008-04-30 00:52:21 -07001039
Eric Miaoa7535ba2008-04-30 00:52:24 -07001040 lccr0 = lcd_readl(fbi, LCCR0) & ~LCCR0_LDM;
1041 lcd_writel(fbi, LCCR0, lccr0);
1042 lcd_writel(fbi, LCCR0, lccr0 | LCCR0_DIS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001043
Eric Miao2ba162b2008-04-30 00:52:24 -07001044 wait_for_completion_timeout(&fbi->disable_done, 200 * HZ / 1000);
Nicolas Pitre8d372262005-08-10 16:45:13 +01001045
1046 /* disable LCD controller clock */
Russell King72e35242007-08-20 10:18:42 +01001047 clk_disable(fbi->clk);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001048}
1049
1050/*
1051 * pxafb_handle_irq: Handle 'LCD DONE' interrupts.
1052 */
David Howells7d12e782006-10-05 14:55:46 +01001053static irqreturn_t pxafb_handle_irq(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001054{
1055 struct pxafb_info *fbi = dev_id;
Eric Miaoa7535ba2008-04-30 00:52:24 -07001056 unsigned int lccr0, lcsr = lcd_readl(fbi, LCSR);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001057
1058 if (lcsr & LCSR_LDD) {
Eric Miaoa7535ba2008-04-30 00:52:24 -07001059 lccr0 = lcd_readl(fbi, LCCR0);
1060 lcd_writel(fbi, LCCR0, lccr0 | LCCR0_LDM);
Eric Miao2ba162b2008-04-30 00:52:24 -07001061 complete(&fbi->disable_done);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001062 }
1063
Eric Miao3c42a442008-04-30 00:52:26 -07001064#ifdef CONFIG_FB_PXA_SMARTPANEL
1065 if (lcsr & LCSR_CMD_INT)
1066 complete(&fbi->command_done);
1067#endif
1068
Eric Miaoa7535ba2008-04-30 00:52:24 -07001069 lcd_writel(fbi, LCSR, lcsr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001070 return IRQ_HANDLED;
1071}
1072
1073/*
1074 * This function must be called from task context only, since it will
1075 * sleep when disabling the LCD controller, or if we get two contending
1076 * processes trying to alter state.
1077 */
1078static void set_ctrlr_state(struct pxafb_info *fbi, u_int state)
1079{
1080 u_int old_state;
1081
Matthias Kaehlckeb91dbce2008-07-23 21:31:14 -07001082 mutex_lock(&fbi->ctrlr_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001083
1084 old_state = fbi->state;
1085
1086 /*
1087 * Hack around fbcon initialisation.
1088 */
1089 if (old_state == C_STARTUP && state == C_REENABLE)
1090 state = C_ENABLE;
1091
1092 switch (state) {
1093 case C_DISABLE_CLKCHANGE:
1094 /*
1095 * Disable controller for clock change. If the
1096 * controller is already disabled, then do nothing.
1097 */
1098 if (old_state != C_DISABLE && old_state != C_DISABLE_PM) {
1099 fbi->state = state;
eric miaob0086ef2008-04-30 00:52:19 -07001100 /* TODO __pxafb_lcd_power(fbi, 0); */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001101 pxafb_disable_controller(fbi);
1102 }
1103 break;
1104
1105 case C_DISABLE_PM:
1106 case C_DISABLE:
1107 /*
1108 * Disable controller
1109 */
1110 if (old_state != C_DISABLE) {
1111 fbi->state = state;
1112 __pxafb_backlight_power(fbi, 0);
1113 __pxafb_lcd_power(fbi, 0);
1114 if (old_state != C_DISABLE_CLKCHANGE)
1115 pxafb_disable_controller(fbi);
1116 }
1117 break;
1118
1119 case C_ENABLE_CLKCHANGE:
1120 /*
1121 * Enable the controller after clock change. Only
1122 * do this if we were disabled for the clock change.
1123 */
1124 if (old_state == C_DISABLE_CLKCHANGE) {
1125 fbi->state = C_ENABLE;
1126 pxafb_enable_controller(fbi);
eric miaob0086ef2008-04-30 00:52:19 -07001127 /* TODO __pxafb_lcd_power(fbi, 1); */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001128 }
1129 break;
1130
1131 case C_REENABLE:
1132 /*
1133 * Re-enable the controller only if it was already
1134 * enabled. This is so we reprogram the control
1135 * registers.
1136 */
1137 if (old_state == C_ENABLE) {
Richard Purdied14b2722006-09-20 22:54:21 +01001138 __pxafb_lcd_power(fbi, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001139 pxafb_disable_controller(fbi);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001140 pxafb_enable_controller(fbi);
Richard Purdied14b2722006-09-20 22:54:21 +01001141 __pxafb_lcd_power(fbi, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001142 }
1143 break;
1144
1145 case C_ENABLE_PM:
1146 /*
1147 * Re-enable the controller after PM. This is not
1148 * perfect - think about the case where we were doing
1149 * a clock change, and we suspended half-way through.
1150 */
1151 if (old_state != C_DISABLE_PM)
1152 break;
1153 /* fall through */
1154
1155 case C_ENABLE:
1156 /*
1157 * Power up the LCD screen, enable controller, and
1158 * turn on the backlight.
1159 */
1160 if (old_state != C_ENABLE) {
1161 fbi->state = C_ENABLE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001162 pxafb_enable_controller(fbi);
1163 __pxafb_lcd_power(fbi, 1);
1164 __pxafb_backlight_power(fbi, 1);
1165 }
1166 break;
1167 }
Matthias Kaehlckeb91dbce2008-07-23 21:31:14 -07001168 mutex_unlock(&fbi->ctrlr_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001169}
1170
1171/*
1172 * Our LCD controller task (which is called when we blank or unblank)
1173 * via keventd.
1174 */
David Howells6d5aefb2006-12-05 19:36:26 +00001175static void pxafb_task(struct work_struct *work)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001176{
David Howells6d5aefb2006-12-05 19:36:26 +00001177 struct pxafb_info *fbi =
1178 container_of(work, struct pxafb_info, task);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001179 u_int state = xchg(&fbi->task_state, -1);
1180
1181 set_ctrlr_state(fbi, state);
1182}
1183
1184#ifdef CONFIG_CPU_FREQ
1185/*
1186 * CPU clock speed change handler. We need to adjust the LCD timing
1187 * parameters when the CPU clock is adjusted by the power management
1188 * subsystem.
1189 *
1190 * TODO: Determine why f->new != 10*get_lclk_frequency_10khz()
1191 */
1192static int
1193pxafb_freq_transition(struct notifier_block *nb, unsigned long val, void *data)
1194{
1195 struct pxafb_info *fbi = TO_INF(nb, freq_transition);
eric miaob0086ef2008-04-30 00:52:19 -07001196 /* TODO struct cpufreq_freqs *f = data; */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001197 u_int pcd;
1198
1199 switch (val) {
1200 case CPUFREQ_PRECHANGE:
1201 set_ctrlr_state(fbi, C_DISABLE_CLKCHANGE);
1202 break;
1203
1204 case CPUFREQ_POSTCHANGE:
Russell King72e35242007-08-20 10:18:42 +01001205 pcd = get_pcd(fbi, fbi->fb.var.pixclock);
Richard Purdieba44cd22005-09-09 13:10:03 -07001206 set_hsync_time(fbi, pcd);
eric miaob0086ef2008-04-30 00:52:19 -07001207 fbi->reg_lccr3 = (fbi->reg_lccr3 & ~0xff) |
1208 LCCR3_PixClkDiv(pcd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001209 set_ctrlr_state(fbi, C_ENABLE_CLKCHANGE);
1210 break;
1211 }
1212 return 0;
1213}
1214
1215static int
1216pxafb_freq_policy(struct notifier_block *nb, unsigned long val, void *data)
1217{
1218 struct pxafb_info *fbi = TO_INF(nb, freq_policy);
1219 struct fb_var_screeninfo *var = &fbi->fb.var;
1220 struct cpufreq_policy *policy = data;
1221
1222 switch (val) {
1223 case CPUFREQ_ADJUST:
1224 case CPUFREQ_INCOMPATIBLE:
Holger Schurigac2bf5b2008-02-11 16:52:30 +01001225 pr_debug("min dma period: %d ps, "
Linus Torvalds1da177e2005-04-16 15:20:36 -07001226 "new clock %d kHz\n", pxafb_display_dma_period(var),
1227 policy->max);
eric miaob0086ef2008-04-30 00:52:19 -07001228 /* TODO: fill in min/max values */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001229 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001230 }
1231 return 0;
1232}
1233#endif
1234
1235#ifdef CONFIG_PM
1236/*
1237 * Power management hooks. Note that we won't be called from IRQ context,
1238 * unlike the blank functions above, so we may sleep.
1239 */
Russell King3ae5eae2005-11-09 22:32:44 +00001240static int pxafb_suspend(struct platform_device *dev, pm_message_t state)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001241{
Russell King3ae5eae2005-11-09 22:32:44 +00001242 struct pxafb_info *fbi = platform_get_drvdata(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001243
Russell King9480e302005-10-28 09:52:56 -07001244 set_ctrlr_state(fbi, C_DISABLE_PM);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001245 return 0;
1246}
1247
Russell King3ae5eae2005-11-09 22:32:44 +00001248static int pxafb_resume(struct platform_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001249{
Russell King3ae5eae2005-11-09 22:32:44 +00001250 struct pxafb_info *fbi = platform_get_drvdata(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001251
Russell King9480e302005-10-28 09:52:56 -07001252 set_ctrlr_state(fbi, C_ENABLE_PM);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001253 return 0;
1254}
1255#else
1256#define pxafb_suspend NULL
1257#define pxafb_resume NULL
1258#endif
1259
Eric Miao77e19672008-12-16 11:54:34 +08001260static int __devinit pxafb_init_video_memory(struct pxafb_info *fbi)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001261{
Eric Miao77e19672008-12-16 11:54:34 +08001262 int size = PAGE_ALIGN(fbi->video_mem_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001263
Eric Miao77e19672008-12-16 11:54:34 +08001264 fbi->video_mem = alloc_pages_exact(size, GFP_KERNEL | __GFP_ZERO);
1265 if (fbi->video_mem == NULL)
1266 return -ENOMEM;
Eric Miao3c42a442008-04-30 00:52:26 -07001267
Eric Miao77e19672008-12-16 11:54:34 +08001268 fbi->video_mem_phys = virt_to_phys(fbi->video_mem);
1269 fbi->video_mem_size = size;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001270
Eric Miao77e19672008-12-16 11:54:34 +08001271 fbi->fb.fix.smem_start = fbi->video_mem_phys;
1272 fbi->fb.fix.smem_len = fbi->video_mem_size;
1273 fbi->fb.screen_base = fbi->video_mem;
Eric Miao3c42a442008-04-30 00:52:26 -07001274
Eric Miao77e19672008-12-16 11:54:34 +08001275 return fbi->video_mem ? 0 : -ENOMEM;
eric miao84f43c32008-04-30 00:52:22 -07001276}
1277
Guennadi Liakhovetskiebdf9822008-05-05 15:31:44 +01001278static void pxafb_decode_mach_info(struct pxafb_info *fbi,
1279 struct pxafb_mach_info *inf)
eric miao84f43c32008-04-30 00:52:22 -07001280{
1281 unsigned int lcd_conn = inf->lcd_conn;
Eric Miao77e19672008-12-16 11:54:34 +08001282 struct pxafb_mode_info *m;
1283 int i;
eric miao84f43c32008-04-30 00:52:22 -07001284
1285 fbi->cmap_inverse = inf->cmap_inverse;
1286 fbi->cmap_static = inf->cmap_static;
1287
Eric Miao1ec26db2008-11-11 21:45:57 +08001288 switch (lcd_conn & LCD_TYPE_MASK) {
eric miao84f43c32008-04-30 00:52:22 -07001289 case LCD_TYPE_MONO_STN:
1290 fbi->lccr0 = LCCR0_CMS;
1291 break;
1292 case LCD_TYPE_MONO_DSTN:
1293 fbi->lccr0 = LCCR0_CMS | LCCR0_SDS;
1294 break;
1295 case LCD_TYPE_COLOR_STN:
1296 fbi->lccr0 = 0;
1297 break;
1298 case LCD_TYPE_COLOR_DSTN:
1299 fbi->lccr0 = LCCR0_SDS;
1300 break;
1301 case LCD_TYPE_COLOR_TFT:
1302 fbi->lccr0 = LCCR0_PAS;
1303 break;
1304 case LCD_TYPE_SMART_PANEL:
1305 fbi->lccr0 = LCCR0_LCDT | LCCR0_PAS;
1306 break;
1307 default:
1308 /* fall back to backward compatibility way */
1309 fbi->lccr0 = inf->lccr0;
1310 fbi->lccr3 = inf->lccr3;
1311 fbi->lccr4 = inf->lccr4;
Guennadi Liakhovetskiebdf9822008-05-05 15:31:44 +01001312 goto decode_mode;
eric miao84f43c32008-04-30 00:52:22 -07001313 }
1314
1315 if (lcd_conn == LCD_MONO_STN_8BPP)
1316 fbi->lccr0 |= LCCR0_DPD;
1317
Eric Miao9a1ac7e2008-08-15 02:50:44 -04001318 fbi->lccr0 |= (lcd_conn & LCD_ALTERNATE_MAPPING) ? LCCR0_LDDALT : 0;
1319
eric miao84f43c32008-04-30 00:52:22 -07001320 fbi->lccr3 = LCCR3_Acb((inf->lcd_conn >> 10) & 0xff);
1321 fbi->lccr3 |= (lcd_conn & LCD_BIAS_ACTIVE_LOW) ? LCCR3_OEP : 0;
1322 fbi->lccr3 |= (lcd_conn & LCD_PCLK_EDGE_FALL) ? LCCR3_PCP : 0;
1323
Guennadi Liakhovetskiebdf9822008-05-05 15:31:44 +01001324decode_mode:
Eric Miao77e19672008-12-16 11:54:34 +08001325 pxafb_setmode(&fbi->fb.var, &inf->modes[0]);
1326
1327 /* decide video memory size as follows:
1328 * 1. default to mode of maximum resolution
1329 * 2. allow platform to override
1330 * 3. allow module parameter to override
1331 */
1332 for (i = 0, m = &inf->modes[0]; i < inf->num_modes; i++, m++)
1333 fbi->video_mem_size = max_t(size_t, fbi->video_mem_size,
1334 m->xres * m->yres * m->bpp / 8);
1335
1336 if (inf->video_mem_size > fbi->video_mem_size)
1337 fbi->video_mem_size = inf->video_mem_size;
1338
1339 if (video_mem_size > fbi->video_mem_size)
1340 fbi->video_mem_size = video_mem_size;
eric miao84f43c32008-04-30 00:52:22 -07001341}
1342
Jaya Kumar9e6c2972008-06-22 04:27:27 +01001343static struct pxafb_info * __devinit pxafb_init_fbinfo(struct device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001344{
1345 struct pxafb_info *fbi;
1346 void *addr;
1347 struct pxafb_mach_info *inf = dev->platform_data;
1348
1349 /* Alloc the pxafb_info and pseudo_palette in one step */
1350 fbi = kmalloc(sizeof(struct pxafb_info) + sizeof(u32) * 16, GFP_KERNEL);
1351 if (!fbi)
1352 return NULL;
1353
1354 memset(fbi, 0, sizeof(struct pxafb_info));
1355 fbi->dev = dev;
1356
Russell King72e35242007-08-20 10:18:42 +01001357 fbi->clk = clk_get(dev, "LCDCLK");
1358 if (IS_ERR(fbi->clk)) {
1359 kfree(fbi);
1360 return NULL;
1361 }
1362
Linus Torvalds1da177e2005-04-16 15:20:36 -07001363 strcpy(fbi->fb.fix.id, PXA_NAME);
1364
1365 fbi->fb.fix.type = FB_TYPE_PACKED_PIXELS;
1366 fbi->fb.fix.type_aux = 0;
1367 fbi->fb.fix.xpanstep = 0;
Eric Miao7e4b19c2008-12-17 14:56:54 +08001368 fbi->fb.fix.ypanstep = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001369 fbi->fb.fix.ywrapstep = 0;
1370 fbi->fb.fix.accel = FB_ACCEL_NONE;
1371
1372 fbi->fb.var.nonstd = 0;
1373 fbi->fb.var.activate = FB_ACTIVATE_NOW;
1374 fbi->fb.var.height = -1;
1375 fbi->fb.var.width = -1;
Eric Miao7e4b19c2008-12-17 14:56:54 +08001376 fbi->fb.var.accel_flags = FB_ACCELF_TEXT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001377 fbi->fb.var.vmode = FB_VMODE_NONINTERLACED;
1378
1379 fbi->fb.fbops = &pxafb_ops;
1380 fbi->fb.flags = FBINFO_DEFAULT;
1381 fbi->fb.node = -1;
1382
1383 addr = fbi;
1384 addr = addr + sizeof(struct pxafb_info);
1385 fbi->fb.pseudo_palette = addr;
1386
eric miaob0086ef2008-04-30 00:52:19 -07001387 fbi->state = C_STARTUP;
1388 fbi->task_state = (u_char)-1;
Richard Purdied14b2722006-09-20 22:54:21 +01001389
eric miao84f43c32008-04-30 00:52:22 -07001390 pxafb_decode_mach_info(fbi, inf);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001391
1392 init_waitqueue_head(&fbi->ctrlr_wait);
David Howells6d5aefb2006-12-05 19:36:26 +00001393 INIT_WORK(&fbi->task, pxafb_task);
Matthias Kaehlckeb91dbce2008-07-23 21:31:14 -07001394 mutex_init(&fbi->ctrlr_lock);
Eric Miao2ba162b2008-04-30 00:52:24 -07001395 init_completion(&fbi->disable_done);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001396
1397 return fbi;
1398}
1399
1400#ifdef CONFIG_FB_PXA_PARAMETERS
Jaya Kumar9e6c2972008-06-22 04:27:27 +01001401static int __devinit parse_opt_mode(struct device *dev, const char *this_opt)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001402{
1403 struct pxafb_mach_info *inf = dev->platform_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001404
eric miao817daf12008-04-30 00:52:18 -07001405 const char *name = this_opt+5;
1406 unsigned int namelen = strlen(name);
1407 int res_specified = 0, bpp_specified = 0;
1408 unsigned int xres = 0, yres = 0, bpp = 0;
1409 int yres_specified = 0;
1410 int i;
1411 for (i = namelen-1; i >= 0; i--) {
1412 switch (name[i]) {
1413 case '-':
1414 namelen = i;
1415 if (!bpp_specified && !yres_specified) {
1416 bpp = simple_strtoul(&name[i+1], NULL, 0);
1417 bpp_specified = 1;
1418 } else
1419 goto done;
1420 break;
1421 case 'x':
1422 if (!yres_specified) {
1423 yres = simple_strtoul(&name[i+1], NULL, 0);
1424 yres_specified = 1;
1425 } else
1426 goto done;
1427 break;
1428 case '0' ... '9':
1429 break;
1430 default:
1431 goto done;
1432 }
1433 }
1434 if (i < 0 && yres_specified) {
1435 xres = simple_strtoul(name, NULL, 0);
1436 res_specified = 1;
1437 }
1438done:
1439 if (res_specified) {
1440 dev_info(dev, "overriding resolution: %dx%d\n", xres, yres);
1441 inf->modes[0].xres = xres; inf->modes[0].yres = yres;
1442 }
1443 if (bpp_specified)
1444 switch (bpp) {
1445 case 1:
1446 case 2:
1447 case 4:
1448 case 8:
1449 case 16:
1450 inf->modes[0].bpp = bpp;
1451 dev_info(dev, "overriding bit depth: %d\n", bpp);
1452 break;
1453 default:
1454 dev_err(dev, "Depth %d is not valid\n", bpp);
1455 return -EINVAL;
1456 }
1457 return 0;
1458}
1459
Jaya Kumar9e6c2972008-06-22 04:27:27 +01001460static int __devinit parse_opt(struct device *dev, char *this_opt)
eric miao817daf12008-04-30 00:52:18 -07001461{
1462 struct pxafb_mach_info *inf = dev->platform_data;
1463 struct pxafb_mode_info *mode = &inf->modes[0];
1464 char s[64];
1465
1466 s[0] = '\0';
1467
Eric Miao77e19672008-12-16 11:54:34 +08001468 if (!strncmp(this_opt, "vmem:", 5)) {
1469 video_mem_size = memparse(this_opt + 5, NULL);
1470 } else if (!strncmp(this_opt, "mode:", 5)) {
eric miao817daf12008-04-30 00:52:18 -07001471 return parse_opt_mode(dev, this_opt);
1472 } else if (!strncmp(this_opt, "pixclock:", 9)) {
1473 mode->pixclock = simple_strtoul(this_opt+9, NULL, 0);
1474 sprintf(s, "pixclock: %ld\n", mode->pixclock);
1475 } else if (!strncmp(this_opt, "left:", 5)) {
1476 mode->left_margin = simple_strtoul(this_opt+5, NULL, 0);
1477 sprintf(s, "left: %u\n", mode->left_margin);
1478 } else if (!strncmp(this_opt, "right:", 6)) {
1479 mode->right_margin = simple_strtoul(this_opt+6, NULL, 0);
1480 sprintf(s, "right: %u\n", mode->right_margin);
1481 } else if (!strncmp(this_opt, "upper:", 6)) {
1482 mode->upper_margin = simple_strtoul(this_opt+6, NULL, 0);
1483 sprintf(s, "upper: %u\n", mode->upper_margin);
1484 } else if (!strncmp(this_opt, "lower:", 6)) {
1485 mode->lower_margin = simple_strtoul(this_opt+6, NULL, 0);
1486 sprintf(s, "lower: %u\n", mode->lower_margin);
1487 } else if (!strncmp(this_opt, "hsynclen:", 9)) {
1488 mode->hsync_len = simple_strtoul(this_opt+9, NULL, 0);
1489 sprintf(s, "hsynclen: %u\n", mode->hsync_len);
1490 } else if (!strncmp(this_opt, "vsynclen:", 9)) {
1491 mode->vsync_len = simple_strtoul(this_opt+9, NULL, 0);
1492 sprintf(s, "vsynclen: %u\n", mode->vsync_len);
1493 } else if (!strncmp(this_opt, "hsync:", 6)) {
1494 if (simple_strtoul(this_opt+6, NULL, 0) == 0) {
1495 sprintf(s, "hsync: Active Low\n");
1496 mode->sync &= ~FB_SYNC_HOR_HIGH_ACT;
1497 } else {
1498 sprintf(s, "hsync: Active High\n");
1499 mode->sync |= FB_SYNC_HOR_HIGH_ACT;
1500 }
1501 } else if (!strncmp(this_opt, "vsync:", 6)) {
1502 if (simple_strtoul(this_opt+6, NULL, 0) == 0) {
1503 sprintf(s, "vsync: Active Low\n");
1504 mode->sync &= ~FB_SYNC_VERT_HIGH_ACT;
1505 } else {
1506 sprintf(s, "vsync: Active High\n");
1507 mode->sync |= FB_SYNC_VERT_HIGH_ACT;
1508 }
1509 } else if (!strncmp(this_opt, "dpc:", 4)) {
1510 if (simple_strtoul(this_opt+4, NULL, 0) == 0) {
1511 sprintf(s, "double pixel clock: false\n");
1512 inf->lccr3 &= ~LCCR3_DPC;
1513 } else {
1514 sprintf(s, "double pixel clock: true\n");
1515 inf->lccr3 |= LCCR3_DPC;
1516 }
1517 } else if (!strncmp(this_opt, "outputen:", 9)) {
1518 if (simple_strtoul(this_opt+9, NULL, 0) == 0) {
1519 sprintf(s, "output enable: active low\n");
1520 inf->lccr3 = (inf->lccr3 & ~LCCR3_OEP) | LCCR3_OutEnL;
1521 } else {
1522 sprintf(s, "output enable: active high\n");
1523 inf->lccr3 = (inf->lccr3 & ~LCCR3_OEP) | LCCR3_OutEnH;
1524 }
1525 } else if (!strncmp(this_opt, "pixclockpol:", 12)) {
1526 if (simple_strtoul(this_opt+12, NULL, 0) == 0) {
1527 sprintf(s, "pixel clock polarity: falling edge\n");
1528 inf->lccr3 = (inf->lccr3 & ~LCCR3_PCP) | LCCR3_PixFlEdg;
1529 } else {
1530 sprintf(s, "pixel clock polarity: rising edge\n");
1531 inf->lccr3 = (inf->lccr3 & ~LCCR3_PCP) | LCCR3_PixRsEdg;
1532 }
1533 } else if (!strncmp(this_opt, "color", 5)) {
1534 inf->lccr0 = (inf->lccr0 & ~LCCR0_CMS) | LCCR0_Color;
1535 } else if (!strncmp(this_opt, "mono", 4)) {
1536 inf->lccr0 = (inf->lccr0 & ~LCCR0_CMS) | LCCR0_Mono;
1537 } else if (!strncmp(this_opt, "active", 6)) {
1538 inf->lccr0 = (inf->lccr0 & ~LCCR0_PAS) | LCCR0_Act;
1539 } else if (!strncmp(this_opt, "passive", 7)) {
1540 inf->lccr0 = (inf->lccr0 & ~LCCR0_PAS) | LCCR0_Pas;
1541 } else if (!strncmp(this_opt, "single", 6)) {
1542 inf->lccr0 = (inf->lccr0 & ~LCCR0_SDS) | LCCR0_Sngl;
1543 } else if (!strncmp(this_opt, "dual", 4)) {
1544 inf->lccr0 = (inf->lccr0 & ~LCCR0_SDS) | LCCR0_Dual;
1545 } else if (!strncmp(this_opt, "4pix", 4)) {
1546 inf->lccr0 = (inf->lccr0 & ~LCCR0_DPD) | LCCR0_4PixMono;
1547 } else if (!strncmp(this_opt, "8pix", 4)) {
1548 inf->lccr0 = (inf->lccr0 & ~LCCR0_DPD) | LCCR0_8PixMono;
1549 } else {
1550 dev_err(dev, "unknown option: %s\n", this_opt);
1551 return -EINVAL;
1552 }
1553
1554 if (s[0] != '\0')
1555 dev_info(dev, "override %s", s);
1556
1557 return 0;
1558}
1559
Jaya Kumar9e6c2972008-06-22 04:27:27 +01001560static int __devinit pxafb_parse_options(struct device *dev, char *options)
eric miao817daf12008-04-30 00:52:18 -07001561{
1562 char *this_opt;
1563 int ret;
1564
1565 if (!options || !*options)
1566 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001567
1568 dev_dbg(dev, "options are \"%s\"\n", options ? options : "null");
1569
1570 /* could be made table driven or similar?... */
eric miao817daf12008-04-30 00:52:18 -07001571 while ((this_opt = strsep(&options, ",")) != NULL) {
1572 ret = parse_opt(dev, this_opt);
1573 if (ret)
1574 return ret;
1575 }
1576 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001577}
eric miao92ac73c2008-04-30 00:52:20 -07001578
1579static char g_options[256] __devinitdata = "";
1580
Jaya Kumarf1edfc42008-06-22 04:27:25 +01001581#ifndef MODULE
Jaya Kumar9e6c2972008-06-22 04:27:27 +01001582static int __init pxafb_setup_options(void)
eric miao92ac73c2008-04-30 00:52:20 -07001583{
1584 char *options = NULL;
1585
1586 if (fb_get_options("pxafb", &options))
1587 return -ENODEV;
1588
1589 if (options)
1590 strlcpy(g_options, options, sizeof(g_options));
1591
1592 return 0;
1593}
1594#else
1595#define pxafb_setup_options() (0)
1596
1597module_param_string(options, g_options, sizeof(g_options), 0);
1598MODULE_PARM_DESC(options, "LCD parameters (see Documentation/fb/pxafb.txt)");
1599#endif
1600
1601#else
1602#define pxafb_parse_options(...) (0)
1603#define pxafb_setup_options() (0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001604#endif
1605
Eric Miao4f3e2662008-08-16 03:50:51 -04001606#ifdef DEBUG_VAR
1607/* Check for various illegal bit-combinations. Currently only
1608 * a warning is given. */
1609static void __devinit pxafb_check_options(struct device *dev,
1610 struct pxafb_mach_info *inf)
1611{
1612 if (inf->lcd_conn)
1613 return;
1614
1615 if (inf->lccr0 & LCCR0_INVALID_CONFIG_MASK)
1616 dev_warn(dev, "machine LCCR0 setting contains "
1617 "illegal bits: %08x\n",
1618 inf->lccr0 & LCCR0_INVALID_CONFIG_MASK);
1619 if (inf->lccr3 & LCCR3_INVALID_CONFIG_MASK)
1620 dev_warn(dev, "machine LCCR3 setting contains "
1621 "illegal bits: %08x\n",
1622 inf->lccr3 & LCCR3_INVALID_CONFIG_MASK);
1623 if (inf->lccr0 & LCCR0_DPD &&
1624 ((inf->lccr0 & LCCR0_PAS) != LCCR0_Pas ||
1625 (inf->lccr0 & LCCR0_SDS) != LCCR0_Sngl ||
1626 (inf->lccr0 & LCCR0_CMS) != LCCR0_Mono))
1627 dev_warn(dev, "Double Pixel Data (DPD) mode is "
1628 "only valid in passive mono"
1629 " single panel mode\n");
1630 if ((inf->lccr0 & LCCR0_PAS) == LCCR0_Act &&
1631 (inf->lccr0 & LCCR0_SDS) == LCCR0_Dual)
1632 dev_warn(dev, "Dual panel only valid in passive mode\n");
1633 if ((inf->lccr0 & LCCR0_PAS) == LCCR0_Pas &&
1634 (inf->modes->upper_margin || inf->modes->lower_margin))
1635 dev_warn(dev, "Upper and lower margins must be 0 in "
1636 "passive mode\n");
1637}
1638#else
1639#define pxafb_check_options(...) do {} while (0)
1640#endif
1641
Jaya Kumar9e6c2972008-06-22 04:27:27 +01001642static int __devinit pxafb_probe(struct platform_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001643{
1644 struct pxafb_info *fbi;
1645 struct pxafb_mach_info *inf;
eric miaoce4fb7b2008-04-30 00:52:21 -07001646 struct resource *r;
1647 int irq, ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001648
Richard Purdie2cbbb3b2006-03-31 02:31:53 -08001649 dev_dbg(&dev->dev, "pxafb_probe\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001650
Russell King3ae5eae2005-11-09 22:32:44 +00001651 inf = dev->dev.platform_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001652 ret = -ENOMEM;
1653 fbi = NULL;
1654 if (!inf)
1655 goto failed;
1656
Russell King3ae5eae2005-11-09 22:32:44 +00001657 ret = pxafb_parse_options(&dev->dev, g_options);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001658 if (ret < 0)
1659 goto failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001660
Eric Miao4f3e2662008-08-16 03:50:51 -04001661 pxafb_check_options(&dev->dev, inf);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001662
eric miaob0086ef2008-04-30 00:52:19 -07001663 dev_dbg(&dev->dev, "got a %dx%dx%d LCD\n",
1664 inf->modes->xres,
1665 inf->modes->yres,
1666 inf->modes->bpp);
1667 if (inf->modes->xres == 0 ||
1668 inf->modes->yres == 0 ||
1669 inf->modes->bpp == 0) {
Russell King3ae5eae2005-11-09 22:32:44 +00001670 dev_err(&dev->dev, "Invalid resolution or bit depth\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001671 ret = -EINVAL;
1672 goto failed;
1673 }
Eric Miaoa5718a12008-11-11 21:50:39 +08001674
Russell King3ae5eae2005-11-09 22:32:44 +00001675 fbi = pxafb_init_fbinfo(&dev->dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001676 if (!fbi) {
eric miaob0086ef2008-04-30 00:52:19 -07001677 /* only reason for pxafb_init_fbinfo to fail is kmalloc */
Russell King3ae5eae2005-11-09 22:32:44 +00001678 dev_err(&dev->dev, "Failed to initialize framebuffer device\n");
eric miaob0086ef2008-04-30 00:52:19 -07001679 ret = -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001680 goto failed;
1681 }
1682
Eric Miaoa5718a12008-11-11 21:50:39 +08001683 fbi->backlight_power = inf->pxafb_backlight_power;
1684 fbi->lcd_power = inf->pxafb_lcd_power;
1685
eric miaoce4fb7b2008-04-30 00:52:21 -07001686 r = platform_get_resource(dev, IORESOURCE_MEM, 0);
1687 if (r == NULL) {
1688 dev_err(&dev->dev, "no I/O memory resource defined\n");
1689 ret = -ENODEV;
Jaya Kumaree984762008-06-22 04:27:26 +01001690 goto failed_fbi;
eric miaoce4fb7b2008-04-30 00:52:21 -07001691 }
1692
1693 r = request_mem_region(r->start, r->end - r->start + 1, dev->name);
1694 if (r == NULL) {
1695 dev_err(&dev->dev, "failed to request I/O memory\n");
1696 ret = -EBUSY;
Jaya Kumaree984762008-06-22 04:27:26 +01001697 goto failed_fbi;
eric miaoce4fb7b2008-04-30 00:52:21 -07001698 }
1699
1700 fbi->mmio_base = ioremap(r->start, r->end - r->start + 1);
1701 if (fbi->mmio_base == NULL) {
1702 dev_err(&dev->dev, "failed to map I/O memory\n");
1703 ret = -EBUSY;
1704 goto failed_free_res;
1705 }
1706
Eric Miao77e19672008-12-16 11:54:34 +08001707 fbi->dma_buff_size = PAGE_ALIGN(sizeof(struct pxafb_dma_buff));
1708 fbi->dma_buff = dma_alloc_coherent(fbi->dev, fbi->dma_buff_size,
1709 &fbi->dma_buff_phys, GFP_KERNEL);
1710 if (fbi->dma_buff == NULL) {
1711 dev_err(&dev->dev, "failed to allocate memory for DMA\n");
1712 ret = -ENOMEM;
1713 goto failed_free_io;
1714 }
1715
1716 ret = pxafb_init_video_memory(fbi);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001717 if (ret) {
Russell King3ae5eae2005-11-09 22:32:44 +00001718 dev_err(&dev->dev, "Failed to allocate video RAM: %d\n", ret);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001719 ret = -ENOMEM;
Eric Miao77e19672008-12-16 11:54:34 +08001720 goto failed_free_dma;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001721 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001722
eric miaoce4fb7b2008-04-30 00:52:21 -07001723 irq = platform_get_irq(dev, 0);
1724 if (irq < 0) {
1725 dev_err(&dev->dev, "no IRQ defined\n");
1726 ret = -ENODEV;
1727 goto failed_free_mem;
1728 }
1729
1730 ret = request_irq(irq, pxafb_handle_irq, IRQF_DISABLED, "LCD", fbi);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001731 if (ret) {
Russell King3ae5eae2005-11-09 22:32:44 +00001732 dev_err(&dev->dev, "request_irq failed: %d\n", ret);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001733 ret = -EBUSY;
eric miaoce4fb7b2008-04-30 00:52:21 -07001734 goto failed_free_mem;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001735 }
1736
Eric Miao3c42a442008-04-30 00:52:26 -07001737 ret = pxafb_smart_init(fbi);
1738 if (ret) {
1739 dev_err(&dev->dev, "failed to initialize smartpanel\n");
1740 goto failed_free_irq;
1741 }
Eric Miao07df1c42008-12-04 11:14:11 +08001742
Linus Torvalds1da177e2005-04-16 15:20:36 -07001743 /*
1744 * This makes sure that our colour bitfield
1745 * descriptors are correctly initialised.
1746 */
Jaya Kumaree984762008-06-22 04:27:26 +01001747 ret = pxafb_check_var(&fbi->fb.var, &fbi->fb);
1748 if (ret) {
1749 dev_err(&dev->dev, "failed to get suitable mode\n");
1750 goto failed_free_irq;
1751 }
1752
1753 ret = pxafb_set_par(&fbi->fb);
1754 if (ret) {
1755 dev_err(&dev->dev, "Failed to set parameters\n");
1756 goto failed_free_irq;
1757 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001758
Russell King3ae5eae2005-11-09 22:32:44 +00001759 platform_set_drvdata(dev, fbi);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001760
1761 ret = register_framebuffer(&fbi->fb);
1762 if (ret < 0) {
eric miaob0086ef2008-04-30 00:52:19 -07001763 dev_err(&dev->dev,
1764 "Failed to register framebuffer device: %d\n", ret);
Jaya Kumaree984762008-06-22 04:27:26 +01001765 goto failed_free_cmap;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001766 }
1767
Linus Torvalds1da177e2005-04-16 15:20:36 -07001768#ifdef CONFIG_CPU_FREQ
1769 fbi->freq_transition.notifier_call = pxafb_freq_transition;
1770 fbi->freq_policy.notifier_call = pxafb_freq_policy;
eric miaob0086ef2008-04-30 00:52:19 -07001771 cpufreq_register_notifier(&fbi->freq_transition,
1772 CPUFREQ_TRANSITION_NOTIFIER);
1773 cpufreq_register_notifier(&fbi->freq_policy,
1774 CPUFREQ_POLICY_NOTIFIER);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001775#endif
1776
1777 /*
1778 * Ok, now enable the LCD controller
1779 */
1780 set_ctrlr_state(fbi, C_ENABLE);
1781
1782 return 0;
1783
Jaya Kumaree984762008-06-22 04:27:26 +01001784failed_free_cmap:
1785 if (fbi->fb.cmap.len)
1786 fb_dealloc_cmap(&fbi->fb.cmap);
eric miaoce4fb7b2008-04-30 00:52:21 -07001787failed_free_irq:
1788 free_irq(irq, fbi);
eric miaoce4fb7b2008-04-30 00:52:21 -07001789failed_free_mem:
Eric Miao77e19672008-12-16 11:54:34 +08001790 free_pages_exact(fbi->video_mem, fbi->video_mem_size);
1791failed_free_dma:
1792 dma_free_coherent(&dev->dev, fbi->dma_buff_size,
1793 fbi->dma_buff, fbi->dma_buff_phys);
Jaya Kumaree984762008-06-22 04:27:26 +01001794failed_free_io:
1795 iounmap(fbi->mmio_base);
1796failed_free_res:
1797 release_mem_region(r->start, r->end - r->start + 1);
1798failed_fbi:
1799 clk_put(fbi->clk);
Russell King3ae5eae2005-11-09 22:32:44 +00001800 platform_set_drvdata(dev, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001801 kfree(fbi);
Jaya Kumaree984762008-06-22 04:27:26 +01001802failed:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001803 return ret;
1804}
1805
Jaya Kumar9f17f282008-06-22 04:27:28 +01001806static int __devexit pxafb_remove(struct platform_device *dev)
1807{
1808 struct pxafb_info *fbi = platform_get_drvdata(dev);
1809 struct resource *r;
1810 int irq;
1811 struct fb_info *info;
1812
1813 if (!fbi)
1814 return 0;
1815
1816 info = &fbi->fb;
1817
1818 unregister_framebuffer(info);
1819
1820 pxafb_disable_controller(fbi);
1821
1822 if (fbi->fb.cmap.len)
1823 fb_dealloc_cmap(&fbi->fb.cmap);
1824
1825 irq = platform_get_irq(dev, 0);
1826 free_irq(irq, fbi);
1827
Eric Miao77e19672008-12-16 11:54:34 +08001828 free_pages_exact(fbi->video_mem, fbi->video_mem_size);
1829
1830 dma_free_writecombine(&dev->dev, fbi->dma_buff_size,
1831 fbi->dma_buff, fbi->dma_buff_phys);
Jaya Kumar9f17f282008-06-22 04:27:28 +01001832
1833 iounmap(fbi->mmio_base);
1834
1835 r = platform_get_resource(dev, IORESOURCE_MEM, 0);
1836 release_mem_region(r->start, r->end - r->start + 1);
1837
1838 clk_put(fbi->clk);
1839 kfree(fbi);
1840
1841 return 0;
1842}
1843
Russell King3ae5eae2005-11-09 22:32:44 +00001844static struct platform_driver pxafb_driver = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001845 .probe = pxafb_probe,
Jaya Kumar9f17f282008-06-22 04:27:28 +01001846 .remove = pxafb_remove,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001847 .suspend = pxafb_suspend,
1848 .resume = pxafb_resume,
Russell King3ae5eae2005-11-09 22:32:44 +00001849 .driver = {
Jaya Kumar9f17f282008-06-22 04:27:28 +01001850 .owner = THIS_MODULE,
Russell King3ae5eae2005-11-09 22:32:44 +00001851 .name = "pxa2xx-fb",
1852 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001853};
1854
Jaya Kumar9e6c2972008-06-22 04:27:27 +01001855static int __init pxafb_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001856{
eric miao92ac73c2008-04-30 00:52:20 -07001857 if (pxafb_setup_options())
1858 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001859
Russell King3ae5eae2005-11-09 22:32:44 +00001860 return platform_driver_register(&pxafb_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001861}
1862
Jaya Kumar9f17f282008-06-22 04:27:28 +01001863static void __exit pxafb_exit(void)
1864{
1865 platform_driver_unregister(&pxafb_driver);
1866}
1867
Linus Torvalds1da177e2005-04-16 15:20:36 -07001868module_init(pxafb_init);
Jaya Kumar9f17f282008-06-22 04:27:28 +01001869module_exit(pxafb_exit);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001870
1871MODULE_DESCRIPTION("loadable framebuffer driver for PXA");
1872MODULE_LICENSE("GPL");