blob: c57f909cb7a8b16e8187962749bd9221d4860418 [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);
Eric Miao6e354842008-12-17 16:50:43 +080074static void setup_base_frame(struct pxafb_info *fbi, int branch);
Linus Torvalds1da177e2005-04-16 15:20:36 -070075
Eric Miao77e19672008-12-16 11:54:34 +080076static unsigned long video_mem_size = 0;
77
Eric Miaoa7535ba2008-04-30 00:52:24 -070078static inline unsigned long
79lcd_readl(struct pxafb_info *fbi, unsigned int off)
80{
81 return __raw_readl(fbi->mmio_base + off);
82}
83
84static inline void
85lcd_writel(struct pxafb_info *fbi, unsigned int off, unsigned long val)
86{
87 __raw_writel(val, fbi->mmio_base + off);
88}
89
Linus Torvalds1da177e2005-04-16 15:20:36 -070090static inline void pxafb_schedule_work(struct pxafb_info *fbi, u_int state)
91{
92 unsigned long flags;
93
94 local_irq_save(flags);
95 /*
96 * We need to handle two requests being made at the same time.
97 * There are two important cases:
eric miaob0086ef2008-04-30 00:52:19 -070098 * 1. When we are changing VT (C_REENABLE) while unblanking
99 * (C_ENABLE) We must perform the unblanking, which will
100 * do our REENABLE for us.
101 * 2. When we are blanking, but immediately unblank before
102 * we have blanked. We do the "REENABLE" thing here as
103 * well, just to be sure.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104 */
105 if (fbi->task_state == C_ENABLE && state == C_REENABLE)
106 state = (u_int) -1;
107 if (fbi->task_state == C_DISABLE && state == C_ENABLE)
108 state = C_REENABLE;
109
110 if (state != (u_int)-1) {
111 fbi->task_state = state;
112 schedule_work(&fbi->task);
113 }
114 local_irq_restore(flags);
115}
116
117static inline u_int chan_to_field(u_int chan, struct fb_bitfield *bf)
118{
119 chan &= 0xffff;
120 chan >>= 16 - bf->length;
121 return chan << bf->offset;
122}
123
124static int
125pxafb_setpalettereg(u_int regno, u_int red, u_int green, u_int blue,
126 u_int trans, struct fb_info *info)
127{
128 struct pxafb_info *fbi = (struct pxafb_info *)info;
Hans J. Koch9ffa7392007-10-16 01:28:41 -0700129 u_int val;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130
Hans J. Koch9ffa7392007-10-16 01:28:41 -0700131 if (regno >= fbi->palette_size)
132 return 1;
133
134 if (fbi->fb.var.grayscale) {
135 fbi->palette_cpu[regno] = ((blue >> 8) & 0x00ff);
136 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137 }
Hans J. Koch9ffa7392007-10-16 01:28:41 -0700138
139 switch (fbi->lccr4 & LCCR4_PAL_FOR_MASK) {
140 case LCCR4_PAL_FOR_0:
141 val = ((red >> 0) & 0xf800);
142 val |= ((green >> 5) & 0x07e0);
143 val |= ((blue >> 11) & 0x001f);
144 fbi->palette_cpu[regno] = val;
145 break;
146 case LCCR4_PAL_FOR_1:
147 val = ((red << 8) & 0x00f80000);
148 val |= ((green >> 0) & 0x0000fc00);
149 val |= ((blue >> 8) & 0x000000f8);
eric miaob0086ef2008-04-30 00:52:19 -0700150 ((u32 *)(fbi->palette_cpu))[regno] = val;
Hans J. Koch9ffa7392007-10-16 01:28:41 -0700151 break;
152 case LCCR4_PAL_FOR_2:
153 val = ((red << 8) & 0x00fc0000);
154 val |= ((green >> 0) & 0x0000fc00);
155 val |= ((blue >> 8) & 0x000000fc);
eric miaob0086ef2008-04-30 00:52:19 -0700156 ((u32 *)(fbi->palette_cpu))[regno] = val;
Hans J. Koch9ffa7392007-10-16 01:28:41 -0700157 break;
Eric Miaoa0427502008-12-18 22:10:00 +0800158 case LCCR4_PAL_FOR_3:
159 val = ((red << 8) & 0x00ff0000);
160 val |= ((green >> 0) & 0x0000ff00);
161 val |= ((blue >> 8) & 0x000000ff);
162 ((u32 *)(fbi->palette_cpu))[regno] = val;
163 break;
Hans J. Koch9ffa7392007-10-16 01:28:41 -0700164 }
165
166 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167}
168
169static int
170pxafb_setcolreg(u_int regno, u_int red, u_int green, u_int blue,
171 u_int trans, struct fb_info *info)
172{
173 struct pxafb_info *fbi = (struct pxafb_info *)info;
174 unsigned int val;
175 int ret = 1;
176
177 /*
178 * If inverse mode was selected, invert all the colours
179 * rather than the register number. The register number
180 * is what you poke into the framebuffer to produce the
181 * colour you requested.
182 */
183 if (fbi->cmap_inverse) {
184 red = 0xffff - red;
185 green = 0xffff - green;
186 blue = 0xffff - blue;
187 }
188
189 /*
190 * If greyscale is true, then we convert the RGB value
191 * to greyscale no matter what visual we are using.
192 */
193 if (fbi->fb.var.grayscale)
194 red = green = blue = (19595 * red + 38470 * green +
195 7471 * blue) >> 16;
196
197 switch (fbi->fb.fix.visual) {
198 case FB_VISUAL_TRUECOLOR:
199 /*
200 * 16-bit True Colour. We encode the RGB value
201 * according to the RGB bitfield information.
202 */
203 if (regno < 16) {
204 u32 *pal = fbi->fb.pseudo_palette;
205
206 val = chan_to_field(red, &fbi->fb.var.red);
207 val |= chan_to_field(green, &fbi->fb.var.green);
208 val |= chan_to_field(blue, &fbi->fb.var.blue);
209
210 pal[regno] = val;
211 ret = 0;
212 }
213 break;
214
215 case FB_VISUAL_STATIC_PSEUDOCOLOR:
216 case FB_VISUAL_PSEUDOCOLOR:
217 ret = pxafb_setpalettereg(regno, red, green, blue, trans, info);
218 break;
219 }
220
221 return ret;
222}
223
224/*
225 * pxafb_bpp_to_lccr3():
226 * Convert a bits per pixel value to the correct bit pattern for LCCR3
227 */
228static int pxafb_bpp_to_lccr3(struct fb_var_screeninfo *var)
229{
eric miaob0086ef2008-04-30 00:52:19 -0700230 int ret = 0;
231 switch (var->bits_per_pixel) {
232 case 1: ret = LCCR3_1BPP; break;
233 case 2: ret = LCCR3_2BPP; break;
234 case 4: ret = LCCR3_4BPP; break;
235 case 8: ret = LCCR3_8BPP; break;
236 case 16: ret = LCCR3_16BPP; break;
Stefan Schmidtc1450f12008-07-09 08:06:32 +0100237 case 24:
238 switch (var->red.length + var->green.length +
239 var->blue.length + var->transp.length) {
240 case 18: ret = LCCR3_18BPP_P | LCCR3_PDFOR_3; break;
241 case 19: ret = LCCR3_19BPP_P; break;
242 }
243 break;
244 case 32:
245 switch (var->red.length + var->green.length +
246 var->blue.length + var->transp.length) {
247 case 18: ret = LCCR3_18BPP | LCCR3_PDFOR_3; break;
248 case 19: ret = LCCR3_19BPP; break;
249 case 24: ret = LCCR3_24BPP | LCCR3_PDFOR_3; break;
250 case 25: ret = LCCR3_25BPP; break;
251 }
252 break;
eric miaob0086ef2008-04-30 00:52:19 -0700253 }
254 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255}
256
257#ifdef CONFIG_CPU_FREQ
258/*
259 * pxafb_display_dma_period()
260 * Calculate the minimum period (in picoseconds) between two DMA
261 * requests for the LCD controller. If we hit this, it means we're
262 * doing nothing but LCD DMA.
263 */
264static unsigned int pxafb_display_dma_period(struct fb_var_screeninfo *var)
265{
eric miaob0086ef2008-04-30 00:52:19 -0700266 /*
267 * Period = pixclock * bits_per_byte * bytes_per_transfer
268 * / memory_bits_per_pixel;
269 */
270 return var->pixclock * 8 * 16 / var->bits_per_pixel;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700272#endif
273
274/*
Richard Purdied14b2722006-09-20 22:54:21 +0100275 * Select the smallest mode that allows the desired resolution to be
276 * displayed. If desired parameters can be rounded up.
277 */
eric miaob0086ef2008-04-30 00:52:19 -0700278static struct pxafb_mode_info *pxafb_getmode(struct pxafb_mach_info *mach,
279 struct fb_var_screeninfo *var)
Richard Purdied14b2722006-09-20 22:54:21 +0100280{
281 struct pxafb_mode_info *mode = NULL;
282 struct pxafb_mode_info *modelist = mach->modes;
283 unsigned int best_x = 0xffffffff, best_y = 0xffffffff;
284 unsigned int i;
285
eric miaob0086ef2008-04-30 00:52:19 -0700286 for (i = 0; i < mach->num_modes; i++) {
287 if (modelist[i].xres >= var->xres &&
288 modelist[i].yres >= var->yres &&
289 modelist[i].xres < best_x &&
290 modelist[i].yres < best_y &&
291 modelist[i].bpp >= var->bits_per_pixel) {
Richard Purdied14b2722006-09-20 22:54:21 +0100292 best_x = modelist[i].xres;
293 best_y = modelist[i].yres;
294 mode = &modelist[i];
295 }
296 }
297
298 return mode;
299}
300
eric miaob0086ef2008-04-30 00:52:19 -0700301static void pxafb_setmode(struct fb_var_screeninfo *var,
302 struct pxafb_mode_info *mode)
Richard Purdied14b2722006-09-20 22:54:21 +0100303{
304 var->xres = mode->xres;
305 var->yres = mode->yres;
306 var->bits_per_pixel = mode->bpp;
307 var->pixclock = mode->pixclock;
308 var->hsync_len = mode->hsync_len;
309 var->left_margin = mode->left_margin;
310 var->right_margin = mode->right_margin;
311 var->vsync_len = mode->vsync_len;
312 var->upper_margin = mode->upper_margin;
313 var->lower_margin = mode->lower_margin;
314 var->sync = mode->sync;
315 var->grayscale = mode->cmap_greyscale;
Richard Purdied14b2722006-09-20 22:54:21 +0100316}
317
318/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319 * pxafb_check_var():
320 * Get the video params out of 'var'. If a value doesn't fit, round it up,
321 * if it's too big, return -EINVAL.
322 *
323 * Round up in the following order: bits_per_pixel, xres,
324 * yres, xres_virtual, yres_virtual, xoffset, yoffset, grayscale,
325 * bitfields, horizontal timing, vertical timing.
326 */
327static int pxafb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
328{
329 struct pxafb_info *fbi = (struct pxafb_info *)info;
Richard Purdied14b2722006-09-20 22:54:21 +0100330 struct pxafb_mach_info *inf = fbi->dev->platform_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331
332 if (var->xres < MIN_XRES)
333 var->xres = MIN_XRES;
334 if (var->yres < MIN_YRES)
335 var->yres = MIN_YRES;
Richard Purdied14b2722006-09-20 22:54:21 +0100336
337 if (inf->fixed_modes) {
338 struct pxafb_mode_info *mode;
339
340 mode = pxafb_getmode(inf, var);
341 if (!mode)
342 return -EINVAL;
343 pxafb_setmode(var, mode);
344 } else {
345 if (var->xres > inf->modes->xres)
346 return -EINVAL;
347 if (var->yres > inf->modes->yres)
348 return -EINVAL;
349 if (var->bits_per_pixel > inf->modes->bpp)
350 return -EINVAL;
351 }
352
Eric Miao7e4b19c2008-12-17 14:56:54 +0800353 /* we don't support xpan, force xres_virtual to be equal to xres */
354 var->xres_virtual = var->xres;
355
356 if (var->accel_flags & FB_ACCELF_TEXT)
357 var->yres_virtual = fbi->fb.fix.smem_len /
358 (var->xres_virtual * var->bits_per_pixel / 8);
359 else
360 var->yres_virtual = max(var->yres_virtual, var->yres);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700361
eric miaob0086ef2008-04-30 00:52:19 -0700362 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700363 * Setup the RGB parameters for this display.
364 *
365 * The pixel packing format is described on page 7-11 of the
366 * PXA2XX Developer's Manual.
eric miaob0086ef2008-04-30 00:52:19 -0700367 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368 if (var->bits_per_pixel == 16) {
369 var->red.offset = 11; var->red.length = 5;
370 var->green.offset = 5; var->green.length = 6;
371 var->blue.offset = 0; var->blue.length = 5;
372 var->transp.offset = var->transp.length = 0;
Stefan Schmidtc1450f12008-07-09 08:06:32 +0100373 } else if (var->bits_per_pixel > 16) {
374 struct pxafb_mode_info *mode;
375
376 mode = pxafb_getmode(inf, var);
377 if (!mode)
378 return -EINVAL;
379
380 switch (mode->depth) {
381 case 18: /* RGB666 */
382 var->transp.offset = var->transp.length = 0;
383 var->red.offset = 12; var->red.length = 6;
384 var->green.offset = 6; var->green.length = 6;
385 var->blue.offset = 0; var->blue.length = 6;
386 break;
387 case 19: /* RGBT666 */
388 var->transp.offset = 18; var->transp.length = 1;
389 var->red.offset = 12; var->red.length = 6;
390 var->green.offset = 6; var->green.length = 6;
391 var->blue.offset = 0; var->blue.length = 6;
392 break;
393 case 24: /* RGB888 */
394 var->transp.offset = var->transp.length = 0;
395 var->red.offset = 16; var->red.length = 8;
396 var->green.offset = 8; var->green.length = 8;
397 var->blue.offset = 0; var->blue.length = 8;
398 break;
399 case 25: /* RGBT888 */
400 var->transp.offset = 24; var->transp.length = 1;
401 var->red.offset = 16; var->red.length = 8;
402 var->green.offset = 8; var->green.length = 8;
403 var->blue.offset = 0; var->blue.length = 8;
404 break;
405 default:
406 return -EINVAL;
407 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408 } else {
eric miaob0086ef2008-04-30 00:52:19 -0700409 var->red.offset = var->green.offset = 0;
410 var->blue.offset = var->transp.offset = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411 var->red.length = 8;
412 var->green.length = 8;
413 var->blue.length = 8;
414 var->transp.length = 0;
415 }
416
417#ifdef CONFIG_CPU_FREQ
Russell King78d3cfd2008-05-17 22:51:14 +0100418 pr_debug("pxafb: dma period = %d ps\n",
419 pxafb_display_dma_period(var));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420#endif
421
422 return 0;
423}
424
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425/*
426 * pxafb_set_par():
427 * Set the user defined part of the display for the specified console
428 */
429static int pxafb_set_par(struct fb_info *info)
430{
431 struct pxafb_info *fbi = (struct pxafb_info *)info;
432 struct fb_var_screeninfo *var = &info->var;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700433
Stefan Schmidtc1450f12008-07-09 08:06:32 +0100434 if (var->bits_per_pixel >= 16)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435 fbi->fb.fix.visual = FB_VISUAL_TRUECOLOR;
436 else if (!fbi->cmap_static)
437 fbi->fb.fix.visual = FB_VISUAL_PSEUDOCOLOR;
438 else {
439 /*
440 * Some people have weird ideas about wanting static
441 * pseudocolor maps. I suspect their user space
442 * applications are broken.
443 */
444 fbi->fb.fix.visual = FB_VISUAL_STATIC_PSEUDOCOLOR;
445 }
446
447 fbi->fb.fix.line_length = var->xres_virtual *
448 var->bits_per_pixel / 8;
Stefan Schmidtc1450f12008-07-09 08:06:32 +0100449 if (var->bits_per_pixel >= 16)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450 fbi->palette_size = 0;
451 else
eric miaob0086ef2008-04-30 00:52:19 -0700452 fbi->palette_size = var->bits_per_pixel == 1 ?
453 4 : 1 << var->bits_per_pixel;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700454
eric miao2c42dd82008-04-30 00:52:21 -0700455 fbi->palette_cpu = (u16 *)&fbi->dma_buff->palette[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700456
Stefan Schmidtc1450f12008-07-09 08:06:32 +0100457 if (fbi->fb.var.bits_per_pixel >= 16)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700458 fb_dealloc_cmap(&fbi->fb.cmap);
459 else
460 fb_alloc_cmap(&fbi->fb.cmap, 1<<fbi->fb.var.bits_per_pixel, 0);
461
462 pxafb_activate_var(var, fbi);
463
464 return 0;
465}
466
Eric Miao6e354842008-12-17 16:50:43 +0800467static int pxafb_pan_display(struct fb_var_screeninfo *var,
468 struct fb_info *info)
469{
470 struct pxafb_info *fbi = (struct pxafb_info *)info;
471 int dma = DMA_MAX + DMA_BASE;
472
473 if (fbi->state != C_ENABLE)
474 return 0;
475
476 setup_base_frame(fbi, 1);
477
478 if (fbi->lccr0 & LCCR0_SDS)
479 lcd_writel(fbi, FBR1, fbi->fdadr[dma + 1] | 0x1);
480
481 lcd_writel(fbi, FBR0, fbi->fdadr[dma] | 0x1);
482 return 0;
483}
484
Linus Torvalds1da177e2005-04-16 15:20:36 -0700485/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700486 * pxafb_blank():
487 * Blank the display by setting all palette values to zero. Note, the
488 * 16 bpp mode does not really use the palette, so this will not
489 * blank the display in all modes.
490 */
491static int pxafb_blank(int blank, struct fb_info *info)
492{
493 struct pxafb_info *fbi = (struct pxafb_info *)info;
494 int i;
495
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496 switch (blank) {
497 case FB_BLANK_POWERDOWN:
498 case FB_BLANK_VSYNC_SUSPEND:
499 case FB_BLANK_HSYNC_SUSPEND:
500 case FB_BLANK_NORMAL:
501 if (fbi->fb.fix.visual == FB_VISUAL_PSEUDOCOLOR ||
502 fbi->fb.fix.visual == FB_VISUAL_STATIC_PSEUDOCOLOR)
503 for (i = 0; i < fbi->palette_size; i++)
504 pxafb_setpalettereg(i, 0, 0, 0, 0, info);
505
506 pxafb_schedule_work(fbi, C_DISABLE);
eric miaob0086ef2008-04-30 00:52:19 -0700507 /* TODO if (pxafb_blank_helper) pxafb_blank_helper(blank); */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700508 break;
509
510 case FB_BLANK_UNBLANK:
eric miaob0086ef2008-04-30 00:52:19 -0700511 /* TODO if (pxafb_blank_helper) pxafb_blank_helper(blank); */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700512 if (fbi->fb.fix.visual == FB_VISUAL_PSEUDOCOLOR ||
513 fbi->fb.fix.visual == FB_VISUAL_STATIC_PSEUDOCOLOR)
514 fb_set_cmap(&fbi->fb.cmap, info);
515 pxafb_schedule_work(fbi, C_ENABLE);
516 }
517 return 0;
518}
519
Linus Torvalds1da177e2005-04-16 15:20:36 -0700520static struct fb_ops pxafb_ops = {
521 .owner = THIS_MODULE,
522 .fb_check_var = pxafb_check_var,
523 .fb_set_par = pxafb_set_par,
Eric Miao6e354842008-12-17 16:50:43 +0800524 .fb_pan_display = pxafb_pan_display,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700525 .fb_setcolreg = pxafb_setcolreg,
526 .fb_fillrect = cfb_fillrect,
527 .fb_copyarea = cfb_copyarea,
528 .fb_imageblit = cfb_imageblit,
529 .fb_blank = pxafb_blank,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700530};
531
532/*
533 * Calculate the PCD value from the clock rate (in picoseconds).
534 * We take account of the PPCR clock setting.
535 * From PXA Developer's Manual:
536 *
537 * PixelClock = LCLK
538 * -------------
539 * 2 ( PCD + 1 )
540 *
541 * PCD = LCLK
542 * ------------- - 1
543 * 2(PixelClock)
544 *
545 * Where:
546 * LCLK = LCD/Memory Clock
547 * PCD = LCCR3[7:0]
548 *
549 * PixelClock here is in Hz while the pixclock argument given is the
550 * period in picoseconds. Hence PixelClock = 1 / ( pixclock * 10^-12 )
551 *
552 * The function get_lclk_frequency_10khz returns LCLK in units of
553 * 10khz. Calling the result of this function lclk gives us the
554 * following
555 *
556 * PCD = (lclk * 10^4 ) * ( pixclock * 10^-12 )
557 * -------------------------------------- - 1
558 * 2
559 *
560 * Factoring the 10^4 and 10^-12 out gives 10^-8 == 1 / 100000000 as used below.
561 */
eric miaob0086ef2008-04-30 00:52:19 -0700562static inline unsigned int get_pcd(struct pxafb_info *fbi,
563 unsigned int pixclock)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564{
565 unsigned long long pcd;
566
567 /* FIXME: Need to take into account Double Pixel Clock mode
Russell King72e35242007-08-20 10:18:42 +0100568 * (DPC) bit? or perhaps set it based on the various clock
569 * speeds */
570 pcd = (unsigned long long)(clk_get_rate(fbi->clk) / 10000);
571 pcd *= pixclock;
Nicolas Pitrebf1b8ab2005-06-23 21:56:45 +0100572 do_div(pcd, 100000000 * 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700573 /* no need for this, since we should subtract 1 anyway. they cancel */
574 /* pcd += 1; */ /* make up for integer math truncations */
575 return (unsigned int)pcd;
576}
577
578/*
Richard Purdieba44cd22005-09-09 13:10:03 -0700579 * Some touchscreens need hsync information from the video driver to
Russell King72e35242007-08-20 10:18:42 +0100580 * function correctly. We export it here. Note that 'hsync_time' and
581 * the value returned from pxafb_get_hsync_time() is the *reciprocal*
582 * of the hsync period in seconds.
Richard Purdieba44cd22005-09-09 13:10:03 -0700583 */
584static inline void set_hsync_time(struct pxafb_info *fbi, unsigned int pcd)
585{
Russell King72e35242007-08-20 10:18:42 +0100586 unsigned long htime;
Richard Purdieba44cd22005-09-09 13:10:03 -0700587
588 if ((pcd == 0) || (fbi->fb.var.hsync_len == 0)) {
eric miaob0086ef2008-04-30 00:52:19 -0700589 fbi->hsync_time = 0;
Richard Purdieba44cd22005-09-09 13:10:03 -0700590 return;
591 }
592
Russell King72e35242007-08-20 10:18:42 +0100593 htime = clk_get_rate(fbi->clk) / (pcd * fbi->fb.var.hsync_len);
594
Richard Purdieba44cd22005-09-09 13:10:03 -0700595 fbi->hsync_time = htime;
596}
597
598unsigned long pxafb_get_hsync_time(struct device *dev)
599{
600 struct pxafb_info *fbi = dev_get_drvdata(dev);
601
602 /* If display is blanked/suspended, hsync isn't active */
603 if (!fbi || (fbi->state != C_ENABLE))
604 return 0;
605
606 return fbi->hsync_time;
607}
608EXPORT_SYMBOL(pxafb_get_hsync_time);
609
eric miao2c42dd82008-04-30 00:52:21 -0700610static int setup_frame_dma(struct pxafb_info *fbi, int dma, int pal,
611 unsigned int offset, size_t size)
612{
613 struct pxafb_dma_descriptor *dma_desc, *pal_desc;
614 unsigned int dma_desc_off, pal_desc_off;
615
Eric Miao6e354842008-12-17 16:50:43 +0800616 if (dma < 0 || dma >= DMA_MAX * 2)
eric miao2c42dd82008-04-30 00:52:21 -0700617 return -EINVAL;
618
619 dma_desc = &fbi->dma_buff->dma_desc[dma];
620 dma_desc_off = offsetof(struct pxafb_dma_buff, dma_desc[dma]);
621
Eric Miao77e19672008-12-16 11:54:34 +0800622 dma_desc->fsadr = fbi->video_mem_phys + offset;
eric miao2c42dd82008-04-30 00:52:21 -0700623 dma_desc->fidr = 0;
624 dma_desc->ldcmd = size;
625
Eric Miao6e354842008-12-17 16:50:43 +0800626 if (pal < 0 || pal >= PAL_MAX * 2) {
eric miao2c42dd82008-04-30 00:52:21 -0700627 dma_desc->fdadr = fbi->dma_buff_phys + dma_desc_off;
628 fbi->fdadr[dma] = fbi->dma_buff_phys + dma_desc_off;
629 } else {
Jürgen Schindele62cfcf42008-06-11 19:56:06 +0100630 pal_desc = &fbi->dma_buff->pal_desc[pal];
631 pal_desc_off = offsetof(struct pxafb_dma_buff, pal_desc[pal]);
eric miao2c42dd82008-04-30 00:52:21 -0700632
633 pal_desc->fsadr = fbi->dma_buff_phys + pal * PALETTE_SIZE;
634 pal_desc->fidr = 0;
635
636 if ((fbi->lccr4 & LCCR4_PAL_FOR_MASK) == LCCR4_PAL_FOR_0)
637 pal_desc->ldcmd = fbi->palette_size * sizeof(u16);
638 else
639 pal_desc->ldcmd = fbi->palette_size * sizeof(u32);
640
641 pal_desc->ldcmd |= LDCMD_PAL;
642
643 /* flip back and forth between palette and frame buffer */
644 pal_desc->fdadr = fbi->dma_buff_phys + dma_desc_off;
645 dma_desc->fdadr = fbi->dma_buff_phys + pal_desc_off;
646 fbi->fdadr[dma] = fbi->dma_buff_phys + dma_desc_off;
647 }
648
649 return 0;
650}
651
Eric Miao6e354842008-12-17 16:50:43 +0800652static void setup_base_frame(struct pxafb_info *fbi, int branch)
653{
654 struct fb_var_screeninfo *var = &fbi->fb.var;
655 struct fb_fix_screeninfo *fix = &fbi->fb.fix;
656 unsigned int nbytes, offset;
657 int dma, pal, bpp = var->bits_per_pixel;
658
659 dma = DMA_BASE + (branch ? DMA_MAX : 0);
660 pal = (bpp >= 16) ? PAL_NONE : PAL_BASE + (branch ? PAL_MAX : 0);
661
662 nbytes = fix->line_length * var->yres;
663 offset = fix->line_length * var->yoffset;
664
665 if (fbi->lccr0 & LCCR0_SDS) {
666 nbytes = nbytes / 2;
667 setup_frame_dma(fbi, dma + 1, PAL_NONE, offset + nbytes, nbytes);
668 }
669
670 setup_frame_dma(fbi, dma, pal, offset, nbytes);
671}
672
Eric Miao3c42a442008-04-30 00:52:26 -0700673#ifdef CONFIG_FB_PXA_SMARTPANEL
674static int setup_smart_dma(struct pxafb_info *fbi)
675{
676 struct pxafb_dma_descriptor *dma_desc;
677 unsigned long dma_desc_off, cmd_buff_off;
678
679 dma_desc = &fbi->dma_buff->dma_desc[DMA_CMD];
680 dma_desc_off = offsetof(struct pxafb_dma_buff, dma_desc[DMA_CMD]);
681 cmd_buff_off = offsetof(struct pxafb_dma_buff, cmd_buff);
682
683 dma_desc->fdadr = fbi->dma_buff_phys + dma_desc_off;
684 dma_desc->fsadr = fbi->dma_buff_phys + cmd_buff_off;
685 dma_desc->fidr = 0;
686 dma_desc->ldcmd = fbi->n_smart_cmds * sizeof(uint16_t);
687
688 fbi->fdadr[DMA_CMD] = dma_desc->fdadr;
689 return 0;
690}
691
692int pxafb_smart_flush(struct fb_info *info)
693{
694 struct pxafb_info *fbi = container_of(info, struct pxafb_info, fb);
695 uint32_t prsr;
696 int ret = 0;
697
698 /* disable controller until all registers are set up */
699 lcd_writel(fbi, LCCR0, fbi->reg_lccr0 & ~LCCR0_ENB);
700
701 /* 1. make it an even number of commands to align on 32-bit boundary
702 * 2. add the interrupt command to the end of the chain so we can
703 * keep track of the end of the transfer
704 */
705
706 while (fbi->n_smart_cmds & 1)
707 fbi->smart_cmds[fbi->n_smart_cmds++] = SMART_CMD_NOOP;
708
709 fbi->smart_cmds[fbi->n_smart_cmds++] = SMART_CMD_INTERRUPT;
710 fbi->smart_cmds[fbi->n_smart_cmds++] = SMART_CMD_WAIT_FOR_VSYNC;
711 setup_smart_dma(fbi);
712
713 /* continue to execute next command */
714 prsr = lcd_readl(fbi, PRSR) | PRSR_ST_OK | PRSR_CON_NT;
715 lcd_writel(fbi, PRSR, prsr);
716
717 /* stop the processor in case it executed "wait for sync" cmd */
718 lcd_writel(fbi, CMDCR, 0x0001);
719
720 /* don't send interrupts for fifo underruns on channel 6 */
721 lcd_writel(fbi, LCCR5, LCCR5_IUM(6));
722
723 lcd_writel(fbi, LCCR1, fbi->reg_lccr1);
724 lcd_writel(fbi, LCCR2, fbi->reg_lccr2);
725 lcd_writel(fbi, LCCR3, fbi->reg_lccr3);
Eric Miaoa0427502008-12-18 22:10:00 +0800726 lcd_writel(fbi, LCCR4, fbi->reg_lccr4);
Eric Miao3c42a442008-04-30 00:52:26 -0700727 lcd_writel(fbi, FDADR0, fbi->fdadr[0]);
728 lcd_writel(fbi, FDADR6, fbi->fdadr[6]);
729
730 /* begin sending */
731 lcd_writel(fbi, LCCR0, fbi->reg_lccr0 | LCCR0_ENB);
732
733 if (wait_for_completion_timeout(&fbi->command_done, HZ/2) == 0) {
734 pr_warning("%s: timeout waiting for command done\n",
735 __func__);
736 ret = -ETIMEDOUT;
737 }
738
739 /* quick disable */
740 prsr = lcd_readl(fbi, PRSR) & ~(PRSR_ST_OK | PRSR_CON_NT);
741 lcd_writel(fbi, PRSR, prsr);
742 lcd_writel(fbi, LCCR0, fbi->reg_lccr0 & ~LCCR0_ENB);
743 lcd_writel(fbi, FDADR6, 0);
744 fbi->n_smart_cmds = 0;
745 return ret;
746}
747
748int pxafb_smart_queue(struct fb_info *info, uint16_t *cmds, int n_cmds)
749{
750 int i;
751 struct pxafb_info *fbi = container_of(info, struct pxafb_info, fb);
752
Eric Miao69bdea72008-12-08 18:46:00 +0800753 for (i = 0; i < n_cmds; i++, cmds++) {
754 /* if it is a software delay, flush and delay */
755 if ((*cmds & 0xff00) == SMART_CMD_DELAY) {
756 pxafb_smart_flush(info);
757 mdelay(*cmds & 0xff);
758 continue;
759 }
760
761 /* leave 2 commands for INTERRUPT and WAIT_FOR_SYNC */
Eric Miao3c42a442008-04-30 00:52:26 -0700762 if (fbi->n_smart_cmds == CMD_BUFF_SIZE - 8)
763 pxafb_smart_flush(info);
764
Eric Miao69bdea72008-12-08 18:46:00 +0800765 fbi->smart_cmds[fbi->n_smart_cmds++] = *cmds;
Eric Miao3c42a442008-04-30 00:52:26 -0700766 }
767
768 return 0;
769}
770
771static unsigned int __smart_timing(unsigned time_ns, unsigned long lcd_clk)
772{
773 unsigned int t = (time_ns * (lcd_clk / 1000000) / 1000);
774 return (t == 0) ? 1 : t;
775}
776
777static void setup_smart_timing(struct pxafb_info *fbi,
778 struct fb_var_screeninfo *var)
779{
780 struct pxafb_mach_info *inf = fbi->dev->platform_data;
781 struct pxafb_mode_info *mode = &inf->modes[0];
782 unsigned long lclk = clk_get_rate(fbi->clk);
783 unsigned t1, t2, t3, t4;
784
785 t1 = max(mode->a0csrd_set_hld, mode->a0cswr_set_hld);
786 t2 = max(mode->rd_pulse_width, mode->wr_pulse_width);
787 t3 = mode->op_hold_time;
788 t4 = mode->cmd_inh_time;
789
790 fbi->reg_lccr1 =
791 LCCR1_DisWdth(var->xres) |
792 LCCR1_BegLnDel(__smart_timing(t1, lclk)) |
793 LCCR1_EndLnDel(__smart_timing(t2, lclk)) |
794 LCCR1_HorSnchWdth(__smart_timing(t3, lclk));
795
796 fbi->reg_lccr2 = LCCR2_DisHght(var->yres);
Eric Miaoc1f99c22008-12-08 18:35:03 +0800797 fbi->reg_lccr3 = fbi->lccr3 | LCCR3_PixClkDiv(__smart_timing(t4, lclk));
798 fbi->reg_lccr3 |= (var->sync & FB_SYNC_HOR_HIGH_ACT) ? LCCR3_HSP : 0;
799 fbi->reg_lccr3 |= (var->sync & FB_SYNC_VERT_HIGH_ACT) ? LCCR3_VSP : 0;
Eric Miao3c42a442008-04-30 00:52:26 -0700800
801 /* FIXME: make this configurable */
802 fbi->reg_cmdcr = 1;
803}
804
805static int pxafb_smart_thread(void *arg)
806{
Eric Miao7f1133c2008-04-30 00:52:27 -0700807 struct pxafb_info *fbi = arg;
Eric Miao3c42a442008-04-30 00:52:26 -0700808 struct pxafb_mach_info *inf = fbi->dev->platform_data;
809
810 if (!fbi || !inf->smart_update) {
811 pr_err("%s: not properly initialized, thread terminated\n",
812 __func__);
813 return -EINVAL;
814 }
815
816 pr_debug("%s(): task starting\n", __func__);
817
818 set_freezable();
819 while (!kthread_should_stop()) {
820
821 if (try_to_freeze())
822 continue;
823
Eric Miao07f651c2008-12-08 18:51:01 +0800824 mutex_lock(&fbi->ctrlr_lock);
825
Eric Miao3c42a442008-04-30 00:52:26 -0700826 if (fbi->state == C_ENABLE) {
827 inf->smart_update(&fbi->fb);
828 complete(&fbi->refresh_done);
829 }
830
Eric Miao07f651c2008-12-08 18:51:01 +0800831 mutex_unlock(&fbi->ctrlr_lock);
832
Eric Miao3c42a442008-04-30 00:52:26 -0700833 set_current_state(TASK_INTERRUPTIBLE);
834 schedule_timeout(30 * HZ / 1000);
835 }
836
837 pr_debug("%s(): task ending\n", __func__);
838 return 0;
839}
840
841static int pxafb_smart_init(struct pxafb_info *fbi)
842{
Eric Miao07df1c42008-12-04 11:14:11 +0800843 if (!(fbi->lccr0 & LCCR0_LCDT))
Eric Miao6cc4abe2008-11-11 21:47:07 +0800844 return 0;
845
Eric Miao07df1c42008-12-04 11:14:11 +0800846 fbi->smart_cmds = (uint16_t *) fbi->dma_buff->cmd_buff;
847 fbi->n_smart_cmds = 0;
848
849 init_completion(&fbi->command_done);
850 init_completion(&fbi->refresh_done);
851
Eric Miao3c42a442008-04-30 00:52:26 -0700852 fbi->smart_thread = kthread_run(pxafb_smart_thread, fbi,
853 "lcd_refresh");
854 if (IS_ERR(fbi->smart_thread)) {
Eric Miao07df1c42008-12-04 11:14:11 +0800855 pr_err("%s: unable to create kernel thread\n", __func__);
Eric Miao3c42a442008-04-30 00:52:26 -0700856 return PTR_ERR(fbi->smart_thread);
857 }
Eric Miaoa5718a12008-11-11 21:50:39 +0800858
Eric Miao3c42a442008-04-30 00:52:26 -0700859 return 0;
860}
861#else
862int pxafb_smart_queue(struct fb_info *info, uint16_t *cmds, int n_cmds)
863{
864 return 0;
865}
866
867int pxafb_smart_flush(struct fb_info *info)
868{
869 return 0;
870}
Eric Miao07df1c42008-12-04 11:14:11 +0800871
872static inline int pxafb_smart_init(struct pxafb_info *fbi) { return 0; }
873#endif /* CONFIG_FB_PXA_SMARTPANEL */
Eric Miao3c42a442008-04-30 00:52:26 -0700874
Eric Miao90eabbf2008-04-30 00:52:25 -0700875static void setup_parallel_timing(struct pxafb_info *fbi,
876 struct fb_var_screeninfo *var)
877{
878 unsigned int lines_per_panel, pcd = get_pcd(fbi, var->pixclock);
879
880 fbi->reg_lccr1 =
881 LCCR1_DisWdth(var->xres) +
882 LCCR1_HorSnchWdth(var->hsync_len) +
883 LCCR1_BegLnDel(var->left_margin) +
884 LCCR1_EndLnDel(var->right_margin);
885
886 /*
887 * If we have a dual scan LCD, we need to halve
888 * the YRES parameter.
889 */
890 lines_per_panel = var->yres;
891 if ((fbi->lccr0 & LCCR0_SDS) == LCCR0_Dual)
892 lines_per_panel /= 2;
893
894 fbi->reg_lccr2 =
895 LCCR2_DisHght(lines_per_panel) +
896 LCCR2_VrtSnchWdth(var->vsync_len) +
897 LCCR2_BegFrmDel(var->upper_margin) +
898 LCCR2_EndFrmDel(var->lower_margin);
899
900 fbi->reg_lccr3 = fbi->lccr3 |
901 (var->sync & FB_SYNC_HOR_HIGH_ACT ?
902 LCCR3_HorSnchH : LCCR3_HorSnchL) |
903 (var->sync & FB_SYNC_VERT_HIGH_ACT ?
904 LCCR3_VrtSnchH : LCCR3_VrtSnchL);
905
906 if (pcd) {
907 fbi->reg_lccr3 |= LCCR3_PixClkDiv(pcd);
908 set_hsync_time(fbi, pcd);
909 }
910}
911
Richard Purdieba44cd22005-09-09 13:10:03 -0700912/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700913 * pxafb_activate_var():
eric miaob0086ef2008-04-30 00:52:19 -0700914 * Configures LCD Controller based on entries in var parameter.
915 * Settings are only written to the controller if changes were made.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700916 */
eric miaob0086ef2008-04-30 00:52:19 -0700917static int pxafb_activate_var(struct fb_var_screeninfo *var,
918 struct pxafb_info *fbi)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700919{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700920 u_long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700921
Linus Torvalds1da177e2005-04-16 15:20:36 -0700922#if DEBUG_VAR
Eric Miao3c42a442008-04-30 00:52:26 -0700923 if (!(fbi->lccr0 & LCCR0_LCDT)) {
924 if (var->xres < 16 || var->xres > 1024)
925 printk(KERN_ERR "%s: invalid xres %d\n",
926 fbi->fb.fix.id, var->xres);
927 switch (var->bits_per_pixel) {
928 case 1:
929 case 2:
930 case 4:
931 case 8:
932 case 16:
Stefan Schmidtc1450f12008-07-09 08:06:32 +0100933 case 24:
934 case 32:
Eric Miao3c42a442008-04-30 00:52:26 -0700935 break;
936 default:
937 printk(KERN_ERR "%s: invalid bit depth %d\n",
938 fbi->fb.fix.id, var->bits_per_pixel);
939 break;
940 }
941
942 if (var->hsync_len < 1 || var->hsync_len > 64)
943 printk(KERN_ERR "%s: invalid hsync_len %d\n",
944 fbi->fb.fix.id, var->hsync_len);
945 if (var->left_margin < 1 || var->left_margin > 255)
946 printk(KERN_ERR "%s: invalid left_margin %d\n",
947 fbi->fb.fix.id, var->left_margin);
948 if (var->right_margin < 1 || var->right_margin > 255)
949 printk(KERN_ERR "%s: invalid right_margin %d\n",
950 fbi->fb.fix.id, var->right_margin);
951 if (var->yres < 1 || var->yres > 1024)
952 printk(KERN_ERR "%s: invalid yres %d\n",
953 fbi->fb.fix.id, var->yres);
954 if (var->vsync_len < 1 || var->vsync_len > 64)
955 printk(KERN_ERR "%s: invalid vsync_len %d\n",
956 fbi->fb.fix.id, var->vsync_len);
957 if (var->upper_margin < 0 || var->upper_margin > 255)
958 printk(KERN_ERR "%s: invalid upper_margin %d\n",
959 fbi->fb.fix.id, var->upper_margin);
960 if (var->lower_margin < 0 || var->lower_margin > 255)
961 printk(KERN_ERR "%s: invalid lower_margin %d\n",
962 fbi->fb.fix.id, var->lower_margin);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700963 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700964#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700965 /* Update shadow copy atomically */
966 local_irq_save(flags);
967
Eric Miao3c42a442008-04-30 00:52:26 -0700968#ifdef CONFIG_FB_PXA_SMARTPANEL
969 if (fbi->lccr0 & LCCR0_LCDT)
970 setup_smart_timing(fbi, var);
971 else
972#endif
973 setup_parallel_timing(fbi, var);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700974
Eric Miao6e354842008-12-17 16:50:43 +0800975 setup_base_frame(fbi, 0);
976
Eric Miao90eabbf2008-04-30 00:52:25 -0700977 fbi->reg_lccr0 = fbi->lccr0 |
978 (LCCR0_LDM | LCCR0_SFM | LCCR0_IUM | LCCR0_EFM |
979 LCCR0_QDM | LCCR0_BM | LCCR0_OUM);
980
981 fbi->reg_lccr3 |= pxafb_bpp_to_lccr3(var);
982
Eric Miaoa7535ba2008-04-30 00:52:24 -0700983 fbi->reg_lccr4 = lcd_readl(fbi, LCCR4) & ~LCCR4_PAL_FOR_MASK;
Hans J. Koch9ffa7392007-10-16 01:28:41 -0700984 fbi->reg_lccr4 |= (fbi->lccr4 & LCCR4_PAL_FOR_MASK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700985 local_irq_restore(flags);
986
987 /*
988 * Only update the registers if the controller is enabled
989 * and something has changed.
990 */
Eric Miaoa7535ba2008-04-30 00:52:24 -0700991 if ((lcd_readl(fbi, LCCR0) != fbi->reg_lccr0) ||
992 (lcd_readl(fbi, LCCR1) != fbi->reg_lccr1) ||
993 (lcd_readl(fbi, LCCR2) != fbi->reg_lccr2) ||
994 (lcd_readl(fbi, LCCR3) != fbi->reg_lccr3) ||
Eric Miaoa0427502008-12-18 22:10:00 +0800995 (lcd_readl(fbi, LCCR4) != fbi->reg_lccr4) ||
Eric Miaoa7535ba2008-04-30 00:52:24 -0700996 (lcd_readl(fbi, FDADR0) != fbi->fdadr[0]) ||
997 (lcd_readl(fbi, FDADR1) != fbi->fdadr[1]))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700998 pxafb_schedule_work(fbi, C_REENABLE);
999
1000 return 0;
1001}
1002
1003/*
1004 * NOTE! The following functions are purely helpers for set_ctrlr_state.
1005 * Do not call them directly; set_ctrlr_state does the correct serialisation
1006 * to ensure that things happen in the right way 100% of time time.
1007 * -- rmk
1008 */
1009static inline void __pxafb_backlight_power(struct pxafb_info *fbi, int on)
1010{
Russell Kingca5da712005-09-29 09:44:54 +01001011 pr_debug("pxafb: backlight o%s\n", on ? "n" : "ff");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001012
Eric Miaoa5718a12008-11-11 21:50:39 +08001013 if (fbi->backlight_power)
1014 fbi->backlight_power(on);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001015}
1016
1017static inline void __pxafb_lcd_power(struct pxafb_info *fbi, int on)
1018{
Russell Kingca5da712005-09-29 09:44:54 +01001019 pr_debug("pxafb: LCD power o%s\n", on ? "n" : "ff");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001020
Eric Miaoa5718a12008-11-11 21:50:39 +08001021 if (fbi->lcd_power)
1022 fbi->lcd_power(on, &fbi->fb.var);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001023}
1024
Linus Torvalds1da177e2005-04-16 15:20:36 -07001025static void pxafb_enable_controller(struct pxafb_info *fbi)
1026{
Russell Kingca5da712005-09-29 09:44:54 +01001027 pr_debug("pxafb: Enabling LCD controller\n");
eric miao2c42dd82008-04-30 00:52:21 -07001028 pr_debug("fdadr0 0x%08x\n", (unsigned int) fbi->fdadr[0]);
1029 pr_debug("fdadr1 0x%08x\n", (unsigned int) fbi->fdadr[1]);
Russell Kingca5da712005-09-29 09:44:54 +01001030 pr_debug("reg_lccr0 0x%08x\n", (unsigned int) fbi->reg_lccr0);
1031 pr_debug("reg_lccr1 0x%08x\n", (unsigned int) fbi->reg_lccr1);
1032 pr_debug("reg_lccr2 0x%08x\n", (unsigned int) fbi->reg_lccr2);
1033 pr_debug("reg_lccr3 0x%08x\n", (unsigned int) fbi->reg_lccr3);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001034
Nicolas Pitre8d372262005-08-10 16:45:13 +01001035 /* enable LCD controller clock */
Russell King72e35242007-08-20 10:18:42 +01001036 clk_enable(fbi->clk);
Nicolas Pitre8d372262005-08-10 16:45:13 +01001037
Eric Miao3c42a442008-04-30 00:52:26 -07001038 if (fbi->lccr0 & LCCR0_LCDT)
1039 return;
1040
Linus Torvalds1da177e2005-04-16 15:20:36 -07001041 /* Sequence from 11.7.10 */
Eric Miaoa0427502008-12-18 22:10:00 +08001042 lcd_writel(fbi, LCCR4, fbi->reg_lccr4);
Eric Miaoa7535ba2008-04-30 00:52:24 -07001043 lcd_writel(fbi, LCCR3, fbi->reg_lccr3);
1044 lcd_writel(fbi, LCCR2, fbi->reg_lccr2);
1045 lcd_writel(fbi, LCCR1, fbi->reg_lccr1);
1046 lcd_writel(fbi, LCCR0, fbi->reg_lccr0 & ~LCCR0_ENB);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001047
Eric Miaoa7535ba2008-04-30 00:52:24 -07001048 lcd_writel(fbi, FDADR0, fbi->fdadr[0]);
1049 lcd_writel(fbi, FDADR1, fbi->fdadr[1]);
1050 lcd_writel(fbi, LCCR0, fbi->reg_lccr0 | LCCR0_ENB);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001051}
1052
1053static void pxafb_disable_controller(struct pxafb_info *fbi)
1054{
eric miaoce4fb7b2008-04-30 00:52:21 -07001055 uint32_t lccr0;
1056
Eric Miao3c42a442008-04-30 00:52:26 -07001057#ifdef CONFIG_FB_PXA_SMARTPANEL
1058 if (fbi->lccr0 & LCCR0_LCDT) {
1059 wait_for_completion_timeout(&fbi->refresh_done,
1060 200 * HZ / 1000);
1061 return;
1062 }
1063#endif
1064
eric miaoce4fb7b2008-04-30 00:52:21 -07001065 /* Clear LCD Status Register */
Eric Miaoa7535ba2008-04-30 00:52:24 -07001066 lcd_writel(fbi, LCSR, 0xffffffff);
eric miaoce4fb7b2008-04-30 00:52:21 -07001067
Eric Miaoa7535ba2008-04-30 00:52:24 -07001068 lccr0 = lcd_readl(fbi, LCCR0) & ~LCCR0_LDM;
1069 lcd_writel(fbi, LCCR0, lccr0);
1070 lcd_writel(fbi, LCCR0, lccr0 | LCCR0_DIS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001071
Eric Miao2ba162b2008-04-30 00:52:24 -07001072 wait_for_completion_timeout(&fbi->disable_done, 200 * HZ / 1000);
Nicolas Pitre8d372262005-08-10 16:45:13 +01001073
1074 /* disable LCD controller clock */
Russell King72e35242007-08-20 10:18:42 +01001075 clk_disable(fbi->clk);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001076}
1077
1078/*
1079 * pxafb_handle_irq: Handle 'LCD DONE' interrupts.
1080 */
David Howells7d12e782006-10-05 14:55:46 +01001081static irqreturn_t pxafb_handle_irq(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001082{
1083 struct pxafb_info *fbi = dev_id;
Eric Miaoa7535ba2008-04-30 00:52:24 -07001084 unsigned int lccr0, lcsr = lcd_readl(fbi, LCSR);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001085
1086 if (lcsr & LCSR_LDD) {
Eric Miaoa7535ba2008-04-30 00:52:24 -07001087 lccr0 = lcd_readl(fbi, LCCR0);
1088 lcd_writel(fbi, LCCR0, lccr0 | LCCR0_LDM);
Eric Miao2ba162b2008-04-30 00:52:24 -07001089 complete(&fbi->disable_done);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001090 }
1091
Eric Miao3c42a442008-04-30 00:52:26 -07001092#ifdef CONFIG_FB_PXA_SMARTPANEL
1093 if (lcsr & LCSR_CMD_INT)
1094 complete(&fbi->command_done);
1095#endif
1096
Eric Miaoa7535ba2008-04-30 00:52:24 -07001097 lcd_writel(fbi, LCSR, lcsr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001098 return IRQ_HANDLED;
1099}
1100
1101/*
1102 * This function must be called from task context only, since it will
1103 * sleep when disabling the LCD controller, or if we get two contending
1104 * processes trying to alter state.
1105 */
1106static void set_ctrlr_state(struct pxafb_info *fbi, u_int state)
1107{
1108 u_int old_state;
1109
Matthias Kaehlckeb91dbce2008-07-23 21:31:14 -07001110 mutex_lock(&fbi->ctrlr_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001111
1112 old_state = fbi->state;
1113
1114 /*
1115 * Hack around fbcon initialisation.
1116 */
1117 if (old_state == C_STARTUP && state == C_REENABLE)
1118 state = C_ENABLE;
1119
1120 switch (state) {
1121 case C_DISABLE_CLKCHANGE:
1122 /*
1123 * Disable controller for clock change. If the
1124 * controller is already disabled, then do nothing.
1125 */
1126 if (old_state != C_DISABLE && old_state != C_DISABLE_PM) {
1127 fbi->state = state;
eric miaob0086ef2008-04-30 00:52:19 -07001128 /* TODO __pxafb_lcd_power(fbi, 0); */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001129 pxafb_disable_controller(fbi);
1130 }
1131 break;
1132
1133 case C_DISABLE_PM:
1134 case C_DISABLE:
1135 /*
1136 * Disable controller
1137 */
1138 if (old_state != C_DISABLE) {
1139 fbi->state = state;
1140 __pxafb_backlight_power(fbi, 0);
1141 __pxafb_lcd_power(fbi, 0);
1142 if (old_state != C_DISABLE_CLKCHANGE)
1143 pxafb_disable_controller(fbi);
1144 }
1145 break;
1146
1147 case C_ENABLE_CLKCHANGE:
1148 /*
1149 * Enable the controller after clock change. Only
1150 * do this if we were disabled for the clock change.
1151 */
1152 if (old_state == C_DISABLE_CLKCHANGE) {
1153 fbi->state = C_ENABLE;
1154 pxafb_enable_controller(fbi);
eric miaob0086ef2008-04-30 00:52:19 -07001155 /* TODO __pxafb_lcd_power(fbi, 1); */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001156 }
1157 break;
1158
1159 case C_REENABLE:
1160 /*
1161 * Re-enable the controller only if it was already
1162 * enabled. This is so we reprogram the control
1163 * registers.
1164 */
1165 if (old_state == C_ENABLE) {
Richard Purdied14b2722006-09-20 22:54:21 +01001166 __pxafb_lcd_power(fbi, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001167 pxafb_disable_controller(fbi);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001168 pxafb_enable_controller(fbi);
Richard Purdied14b2722006-09-20 22:54:21 +01001169 __pxafb_lcd_power(fbi, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001170 }
1171 break;
1172
1173 case C_ENABLE_PM:
1174 /*
1175 * Re-enable the controller after PM. This is not
1176 * perfect - think about the case where we were doing
1177 * a clock change, and we suspended half-way through.
1178 */
1179 if (old_state != C_DISABLE_PM)
1180 break;
1181 /* fall through */
1182
1183 case C_ENABLE:
1184 /*
1185 * Power up the LCD screen, enable controller, and
1186 * turn on the backlight.
1187 */
1188 if (old_state != C_ENABLE) {
1189 fbi->state = C_ENABLE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001190 pxafb_enable_controller(fbi);
1191 __pxafb_lcd_power(fbi, 1);
1192 __pxafb_backlight_power(fbi, 1);
1193 }
1194 break;
1195 }
Matthias Kaehlckeb91dbce2008-07-23 21:31:14 -07001196 mutex_unlock(&fbi->ctrlr_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001197}
1198
1199/*
1200 * Our LCD controller task (which is called when we blank or unblank)
1201 * via keventd.
1202 */
David Howells6d5aefb2006-12-05 19:36:26 +00001203static void pxafb_task(struct work_struct *work)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001204{
David Howells6d5aefb2006-12-05 19:36:26 +00001205 struct pxafb_info *fbi =
1206 container_of(work, struct pxafb_info, task);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001207 u_int state = xchg(&fbi->task_state, -1);
1208
1209 set_ctrlr_state(fbi, state);
1210}
1211
1212#ifdef CONFIG_CPU_FREQ
1213/*
1214 * CPU clock speed change handler. We need to adjust the LCD timing
1215 * parameters when the CPU clock is adjusted by the power management
1216 * subsystem.
1217 *
1218 * TODO: Determine why f->new != 10*get_lclk_frequency_10khz()
1219 */
1220static int
1221pxafb_freq_transition(struct notifier_block *nb, unsigned long val, void *data)
1222{
1223 struct pxafb_info *fbi = TO_INF(nb, freq_transition);
eric miaob0086ef2008-04-30 00:52:19 -07001224 /* TODO struct cpufreq_freqs *f = data; */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001225 u_int pcd;
1226
1227 switch (val) {
1228 case CPUFREQ_PRECHANGE:
1229 set_ctrlr_state(fbi, C_DISABLE_CLKCHANGE);
1230 break;
1231
1232 case CPUFREQ_POSTCHANGE:
Russell King72e35242007-08-20 10:18:42 +01001233 pcd = get_pcd(fbi, fbi->fb.var.pixclock);
Richard Purdieba44cd22005-09-09 13:10:03 -07001234 set_hsync_time(fbi, pcd);
eric miaob0086ef2008-04-30 00:52:19 -07001235 fbi->reg_lccr3 = (fbi->reg_lccr3 & ~0xff) |
1236 LCCR3_PixClkDiv(pcd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001237 set_ctrlr_state(fbi, C_ENABLE_CLKCHANGE);
1238 break;
1239 }
1240 return 0;
1241}
1242
1243static int
1244pxafb_freq_policy(struct notifier_block *nb, unsigned long val, void *data)
1245{
1246 struct pxafb_info *fbi = TO_INF(nb, freq_policy);
1247 struct fb_var_screeninfo *var = &fbi->fb.var;
1248 struct cpufreq_policy *policy = data;
1249
1250 switch (val) {
1251 case CPUFREQ_ADJUST:
1252 case CPUFREQ_INCOMPATIBLE:
Holger Schurigac2bf5b2008-02-11 16:52:30 +01001253 pr_debug("min dma period: %d ps, "
Linus Torvalds1da177e2005-04-16 15:20:36 -07001254 "new clock %d kHz\n", pxafb_display_dma_period(var),
1255 policy->max);
eric miaob0086ef2008-04-30 00:52:19 -07001256 /* TODO: fill in min/max values */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001257 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001258 }
1259 return 0;
1260}
1261#endif
1262
1263#ifdef CONFIG_PM
1264/*
1265 * Power management hooks. Note that we won't be called from IRQ context,
1266 * unlike the blank functions above, so we may sleep.
1267 */
Russell King3ae5eae2005-11-09 22:32:44 +00001268static int pxafb_suspend(struct platform_device *dev, pm_message_t state)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001269{
Russell King3ae5eae2005-11-09 22:32:44 +00001270 struct pxafb_info *fbi = platform_get_drvdata(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001271
Russell King9480e302005-10-28 09:52:56 -07001272 set_ctrlr_state(fbi, C_DISABLE_PM);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001273 return 0;
1274}
1275
Russell King3ae5eae2005-11-09 22:32:44 +00001276static int pxafb_resume(struct platform_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001277{
Russell King3ae5eae2005-11-09 22:32:44 +00001278 struct pxafb_info *fbi = platform_get_drvdata(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001279
Russell King9480e302005-10-28 09:52:56 -07001280 set_ctrlr_state(fbi, C_ENABLE_PM);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001281 return 0;
1282}
1283#else
1284#define pxafb_suspend NULL
1285#define pxafb_resume NULL
1286#endif
1287
Eric Miao77e19672008-12-16 11:54:34 +08001288static int __devinit pxafb_init_video_memory(struct pxafb_info *fbi)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001289{
Eric Miao77e19672008-12-16 11:54:34 +08001290 int size = PAGE_ALIGN(fbi->video_mem_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001291
Eric Miao77e19672008-12-16 11:54:34 +08001292 fbi->video_mem = alloc_pages_exact(size, GFP_KERNEL | __GFP_ZERO);
1293 if (fbi->video_mem == NULL)
1294 return -ENOMEM;
Eric Miao3c42a442008-04-30 00:52:26 -07001295
Eric Miao77e19672008-12-16 11:54:34 +08001296 fbi->video_mem_phys = virt_to_phys(fbi->video_mem);
1297 fbi->video_mem_size = size;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001298
Eric Miao77e19672008-12-16 11:54:34 +08001299 fbi->fb.fix.smem_start = fbi->video_mem_phys;
1300 fbi->fb.fix.smem_len = fbi->video_mem_size;
1301 fbi->fb.screen_base = fbi->video_mem;
Eric Miao3c42a442008-04-30 00:52:26 -07001302
Eric Miao77e19672008-12-16 11:54:34 +08001303 return fbi->video_mem ? 0 : -ENOMEM;
eric miao84f43c32008-04-30 00:52:22 -07001304}
1305
Guennadi Liakhovetskiebdf9822008-05-05 15:31:44 +01001306static void pxafb_decode_mach_info(struct pxafb_info *fbi,
1307 struct pxafb_mach_info *inf)
eric miao84f43c32008-04-30 00:52:22 -07001308{
1309 unsigned int lcd_conn = inf->lcd_conn;
Eric Miao77e19672008-12-16 11:54:34 +08001310 struct pxafb_mode_info *m;
1311 int i;
eric miao84f43c32008-04-30 00:52:22 -07001312
1313 fbi->cmap_inverse = inf->cmap_inverse;
1314 fbi->cmap_static = inf->cmap_static;
Eric Miaoa0427502008-12-18 22:10:00 +08001315 fbi->lccr4 = inf->lccr4;
eric miao84f43c32008-04-30 00:52:22 -07001316
Eric Miao1ec26db2008-11-11 21:45:57 +08001317 switch (lcd_conn & LCD_TYPE_MASK) {
eric miao84f43c32008-04-30 00:52:22 -07001318 case LCD_TYPE_MONO_STN:
1319 fbi->lccr0 = LCCR0_CMS;
1320 break;
1321 case LCD_TYPE_MONO_DSTN:
1322 fbi->lccr0 = LCCR0_CMS | LCCR0_SDS;
1323 break;
1324 case LCD_TYPE_COLOR_STN:
1325 fbi->lccr0 = 0;
1326 break;
1327 case LCD_TYPE_COLOR_DSTN:
1328 fbi->lccr0 = LCCR0_SDS;
1329 break;
1330 case LCD_TYPE_COLOR_TFT:
1331 fbi->lccr0 = LCCR0_PAS;
1332 break;
1333 case LCD_TYPE_SMART_PANEL:
1334 fbi->lccr0 = LCCR0_LCDT | LCCR0_PAS;
1335 break;
1336 default:
1337 /* fall back to backward compatibility way */
1338 fbi->lccr0 = inf->lccr0;
1339 fbi->lccr3 = inf->lccr3;
Guennadi Liakhovetskiebdf9822008-05-05 15:31:44 +01001340 goto decode_mode;
eric miao84f43c32008-04-30 00:52:22 -07001341 }
1342
1343 if (lcd_conn == LCD_MONO_STN_8BPP)
1344 fbi->lccr0 |= LCCR0_DPD;
1345
Eric Miao9a1ac7e2008-08-15 02:50:44 -04001346 fbi->lccr0 |= (lcd_conn & LCD_ALTERNATE_MAPPING) ? LCCR0_LDDALT : 0;
1347
eric miao84f43c32008-04-30 00:52:22 -07001348 fbi->lccr3 = LCCR3_Acb((inf->lcd_conn >> 10) & 0xff);
1349 fbi->lccr3 |= (lcd_conn & LCD_BIAS_ACTIVE_LOW) ? LCCR3_OEP : 0;
1350 fbi->lccr3 |= (lcd_conn & LCD_PCLK_EDGE_FALL) ? LCCR3_PCP : 0;
1351
Guennadi Liakhovetskiebdf9822008-05-05 15:31:44 +01001352decode_mode:
Eric Miao77e19672008-12-16 11:54:34 +08001353 pxafb_setmode(&fbi->fb.var, &inf->modes[0]);
1354
1355 /* decide video memory size as follows:
1356 * 1. default to mode of maximum resolution
1357 * 2. allow platform to override
1358 * 3. allow module parameter to override
1359 */
1360 for (i = 0, m = &inf->modes[0]; i < inf->num_modes; i++, m++)
1361 fbi->video_mem_size = max_t(size_t, fbi->video_mem_size,
1362 m->xres * m->yres * m->bpp / 8);
1363
1364 if (inf->video_mem_size > fbi->video_mem_size)
1365 fbi->video_mem_size = inf->video_mem_size;
1366
1367 if (video_mem_size > fbi->video_mem_size)
1368 fbi->video_mem_size = video_mem_size;
eric miao84f43c32008-04-30 00:52:22 -07001369}
1370
Jaya Kumar9e6c2972008-06-22 04:27:27 +01001371static struct pxafb_info * __devinit pxafb_init_fbinfo(struct device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001372{
1373 struct pxafb_info *fbi;
1374 void *addr;
1375 struct pxafb_mach_info *inf = dev->platform_data;
1376
1377 /* Alloc the pxafb_info and pseudo_palette in one step */
1378 fbi = kmalloc(sizeof(struct pxafb_info) + sizeof(u32) * 16, GFP_KERNEL);
1379 if (!fbi)
1380 return NULL;
1381
1382 memset(fbi, 0, sizeof(struct pxafb_info));
1383 fbi->dev = dev;
1384
Russell King72e35242007-08-20 10:18:42 +01001385 fbi->clk = clk_get(dev, "LCDCLK");
1386 if (IS_ERR(fbi->clk)) {
1387 kfree(fbi);
1388 return NULL;
1389 }
1390
Linus Torvalds1da177e2005-04-16 15:20:36 -07001391 strcpy(fbi->fb.fix.id, PXA_NAME);
1392
1393 fbi->fb.fix.type = FB_TYPE_PACKED_PIXELS;
1394 fbi->fb.fix.type_aux = 0;
1395 fbi->fb.fix.xpanstep = 0;
Eric Miao7e4b19c2008-12-17 14:56:54 +08001396 fbi->fb.fix.ypanstep = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001397 fbi->fb.fix.ywrapstep = 0;
1398 fbi->fb.fix.accel = FB_ACCEL_NONE;
1399
1400 fbi->fb.var.nonstd = 0;
1401 fbi->fb.var.activate = FB_ACTIVATE_NOW;
1402 fbi->fb.var.height = -1;
1403 fbi->fb.var.width = -1;
Eric Miao7e4b19c2008-12-17 14:56:54 +08001404 fbi->fb.var.accel_flags = FB_ACCELF_TEXT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001405 fbi->fb.var.vmode = FB_VMODE_NONINTERLACED;
1406
1407 fbi->fb.fbops = &pxafb_ops;
1408 fbi->fb.flags = FBINFO_DEFAULT;
1409 fbi->fb.node = -1;
1410
1411 addr = fbi;
1412 addr = addr + sizeof(struct pxafb_info);
1413 fbi->fb.pseudo_palette = addr;
1414
eric miaob0086ef2008-04-30 00:52:19 -07001415 fbi->state = C_STARTUP;
1416 fbi->task_state = (u_char)-1;
Richard Purdied14b2722006-09-20 22:54:21 +01001417
eric miao84f43c32008-04-30 00:52:22 -07001418 pxafb_decode_mach_info(fbi, inf);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001419
1420 init_waitqueue_head(&fbi->ctrlr_wait);
David Howells6d5aefb2006-12-05 19:36:26 +00001421 INIT_WORK(&fbi->task, pxafb_task);
Matthias Kaehlckeb91dbce2008-07-23 21:31:14 -07001422 mutex_init(&fbi->ctrlr_lock);
Eric Miao2ba162b2008-04-30 00:52:24 -07001423 init_completion(&fbi->disable_done);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001424
1425 return fbi;
1426}
1427
1428#ifdef CONFIG_FB_PXA_PARAMETERS
Jaya Kumar9e6c2972008-06-22 04:27:27 +01001429static int __devinit parse_opt_mode(struct device *dev, const char *this_opt)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001430{
1431 struct pxafb_mach_info *inf = dev->platform_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001432
eric miao817daf12008-04-30 00:52:18 -07001433 const char *name = this_opt+5;
1434 unsigned int namelen = strlen(name);
1435 int res_specified = 0, bpp_specified = 0;
1436 unsigned int xres = 0, yres = 0, bpp = 0;
1437 int yres_specified = 0;
1438 int i;
1439 for (i = namelen-1; i >= 0; i--) {
1440 switch (name[i]) {
1441 case '-':
1442 namelen = i;
1443 if (!bpp_specified && !yres_specified) {
1444 bpp = simple_strtoul(&name[i+1], NULL, 0);
1445 bpp_specified = 1;
1446 } else
1447 goto done;
1448 break;
1449 case 'x':
1450 if (!yres_specified) {
1451 yres = simple_strtoul(&name[i+1], NULL, 0);
1452 yres_specified = 1;
1453 } else
1454 goto done;
1455 break;
1456 case '0' ... '9':
1457 break;
1458 default:
1459 goto done;
1460 }
1461 }
1462 if (i < 0 && yres_specified) {
1463 xres = simple_strtoul(name, NULL, 0);
1464 res_specified = 1;
1465 }
1466done:
1467 if (res_specified) {
1468 dev_info(dev, "overriding resolution: %dx%d\n", xres, yres);
1469 inf->modes[0].xres = xres; inf->modes[0].yres = yres;
1470 }
1471 if (bpp_specified)
1472 switch (bpp) {
1473 case 1:
1474 case 2:
1475 case 4:
1476 case 8:
1477 case 16:
1478 inf->modes[0].bpp = bpp;
1479 dev_info(dev, "overriding bit depth: %d\n", bpp);
1480 break;
1481 default:
1482 dev_err(dev, "Depth %d is not valid\n", bpp);
1483 return -EINVAL;
1484 }
1485 return 0;
1486}
1487
Jaya Kumar9e6c2972008-06-22 04:27:27 +01001488static int __devinit parse_opt(struct device *dev, char *this_opt)
eric miao817daf12008-04-30 00:52:18 -07001489{
1490 struct pxafb_mach_info *inf = dev->platform_data;
1491 struct pxafb_mode_info *mode = &inf->modes[0];
1492 char s[64];
1493
1494 s[0] = '\0';
1495
Eric Miao77e19672008-12-16 11:54:34 +08001496 if (!strncmp(this_opt, "vmem:", 5)) {
1497 video_mem_size = memparse(this_opt + 5, NULL);
1498 } else if (!strncmp(this_opt, "mode:", 5)) {
eric miao817daf12008-04-30 00:52:18 -07001499 return parse_opt_mode(dev, this_opt);
1500 } else if (!strncmp(this_opt, "pixclock:", 9)) {
1501 mode->pixclock = simple_strtoul(this_opt+9, NULL, 0);
1502 sprintf(s, "pixclock: %ld\n", mode->pixclock);
1503 } else if (!strncmp(this_opt, "left:", 5)) {
1504 mode->left_margin = simple_strtoul(this_opt+5, NULL, 0);
1505 sprintf(s, "left: %u\n", mode->left_margin);
1506 } else if (!strncmp(this_opt, "right:", 6)) {
1507 mode->right_margin = simple_strtoul(this_opt+6, NULL, 0);
1508 sprintf(s, "right: %u\n", mode->right_margin);
1509 } else if (!strncmp(this_opt, "upper:", 6)) {
1510 mode->upper_margin = simple_strtoul(this_opt+6, NULL, 0);
1511 sprintf(s, "upper: %u\n", mode->upper_margin);
1512 } else if (!strncmp(this_opt, "lower:", 6)) {
1513 mode->lower_margin = simple_strtoul(this_opt+6, NULL, 0);
1514 sprintf(s, "lower: %u\n", mode->lower_margin);
1515 } else if (!strncmp(this_opt, "hsynclen:", 9)) {
1516 mode->hsync_len = simple_strtoul(this_opt+9, NULL, 0);
1517 sprintf(s, "hsynclen: %u\n", mode->hsync_len);
1518 } else if (!strncmp(this_opt, "vsynclen:", 9)) {
1519 mode->vsync_len = simple_strtoul(this_opt+9, NULL, 0);
1520 sprintf(s, "vsynclen: %u\n", mode->vsync_len);
1521 } else if (!strncmp(this_opt, "hsync:", 6)) {
1522 if (simple_strtoul(this_opt+6, NULL, 0) == 0) {
1523 sprintf(s, "hsync: Active Low\n");
1524 mode->sync &= ~FB_SYNC_HOR_HIGH_ACT;
1525 } else {
1526 sprintf(s, "hsync: Active High\n");
1527 mode->sync |= FB_SYNC_HOR_HIGH_ACT;
1528 }
1529 } else if (!strncmp(this_opt, "vsync:", 6)) {
1530 if (simple_strtoul(this_opt+6, NULL, 0) == 0) {
1531 sprintf(s, "vsync: Active Low\n");
1532 mode->sync &= ~FB_SYNC_VERT_HIGH_ACT;
1533 } else {
1534 sprintf(s, "vsync: Active High\n");
1535 mode->sync |= FB_SYNC_VERT_HIGH_ACT;
1536 }
1537 } else if (!strncmp(this_opt, "dpc:", 4)) {
1538 if (simple_strtoul(this_opt+4, NULL, 0) == 0) {
1539 sprintf(s, "double pixel clock: false\n");
1540 inf->lccr3 &= ~LCCR3_DPC;
1541 } else {
1542 sprintf(s, "double pixel clock: true\n");
1543 inf->lccr3 |= LCCR3_DPC;
1544 }
1545 } else if (!strncmp(this_opt, "outputen:", 9)) {
1546 if (simple_strtoul(this_opt+9, NULL, 0) == 0) {
1547 sprintf(s, "output enable: active low\n");
1548 inf->lccr3 = (inf->lccr3 & ~LCCR3_OEP) | LCCR3_OutEnL;
1549 } else {
1550 sprintf(s, "output enable: active high\n");
1551 inf->lccr3 = (inf->lccr3 & ~LCCR3_OEP) | LCCR3_OutEnH;
1552 }
1553 } else if (!strncmp(this_opt, "pixclockpol:", 12)) {
1554 if (simple_strtoul(this_opt+12, NULL, 0) == 0) {
1555 sprintf(s, "pixel clock polarity: falling edge\n");
1556 inf->lccr3 = (inf->lccr3 & ~LCCR3_PCP) | LCCR3_PixFlEdg;
1557 } else {
1558 sprintf(s, "pixel clock polarity: rising edge\n");
1559 inf->lccr3 = (inf->lccr3 & ~LCCR3_PCP) | LCCR3_PixRsEdg;
1560 }
1561 } else if (!strncmp(this_opt, "color", 5)) {
1562 inf->lccr0 = (inf->lccr0 & ~LCCR0_CMS) | LCCR0_Color;
1563 } else if (!strncmp(this_opt, "mono", 4)) {
1564 inf->lccr0 = (inf->lccr0 & ~LCCR0_CMS) | LCCR0_Mono;
1565 } else if (!strncmp(this_opt, "active", 6)) {
1566 inf->lccr0 = (inf->lccr0 & ~LCCR0_PAS) | LCCR0_Act;
1567 } else if (!strncmp(this_opt, "passive", 7)) {
1568 inf->lccr0 = (inf->lccr0 & ~LCCR0_PAS) | LCCR0_Pas;
1569 } else if (!strncmp(this_opt, "single", 6)) {
1570 inf->lccr0 = (inf->lccr0 & ~LCCR0_SDS) | LCCR0_Sngl;
1571 } else if (!strncmp(this_opt, "dual", 4)) {
1572 inf->lccr0 = (inf->lccr0 & ~LCCR0_SDS) | LCCR0_Dual;
1573 } else if (!strncmp(this_opt, "4pix", 4)) {
1574 inf->lccr0 = (inf->lccr0 & ~LCCR0_DPD) | LCCR0_4PixMono;
1575 } else if (!strncmp(this_opt, "8pix", 4)) {
1576 inf->lccr0 = (inf->lccr0 & ~LCCR0_DPD) | LCCR0_8PixMono;
1577 } else {
1578 dev_err(dev, "unknown option: %s\n", this_opt);
1579 return -EINVAL;
1580 }
1581
1582 if (s[0] != '\0')
1583 dev_info(dev, "override %s", s);
1584
1585 return 0;
1586}
1587
Jaya Kumar9e6c2972008-06-22 04:27:27 +01001588static int __devinit pxafb_parse_options(struct device *dev, char *options)
eric miao817daf12008-04-30 00:52:18 -07001589{
1590 char *this_opt;
1591 int ret;
1592
1593 if (!options || !*options)
1594 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001595
1596 dev_dbg(dev, "options are \"%s\"\n", options ? options : "null");
1597
1598 /* could be made table driven or similar?... */
eric miao817daf12008-04-30 00:52:18 -07001599 while ((this_opt = strsep(&options, ",")) != NULL) {
1600 ret = parse_opt(dev, this_opt);
1601 if (ret)
1602 return ret;
1603 }
1604 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001605}
eric miao92ac73c2008-04-30 00:52:20 -07001606
1607static char g_options[256] __devinitdata = "";
1608
Jaya Kumarf1edfc42008-06-22 04:27:25 +01001609#ifndef MODULE
Jaya Kumar9e6c2972008-06-22 04:27:27 +01001610static int __init pxafb_setup_options(void)
eric miao92ac73c2008-04-30 00:52:20 -07001611{
1612 char *options = NULL;
1613
1614 if (fb_get_options("pxafb", &options))
1615 return -ENODEV;
1616
1617 if (options)
1618 strlcpy(g_options, options, sizeof(g_options));
1619
1620 return 0;
1621}
1622#else
1623#define pxafb_setup_options() (0)
1624
1625module_param_string(options, g_options, sizeof(g_options), 0);
1626MODULE_PARM_DESC(options, "LCD parameters (see Documentation/fb/pxafb.txt)");
1627#endif
1628
1629#else
1630#define pxafb_parse_options(...) (0)
1631#define pxafb_setup_options() (0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001632#endif
1633
Eric Miao4f3e2662008-08-16 03:50:51 -04001634#ifdef DEBUG_VAR
1635/* Check for various illegal bit-combinations. Currently only
1636 * a warning is given. */
1637static void __devinit pxafb_check_options(struct device *dev,
1638 struct pxafb_mach_info *inf)
1639{
1640 if (inf->lcd_conn)
1641 return;
1642
1643 if (inf->lccr0 & LCCR0_INVALID_CONFIG_MASK)
1644 dev_warn(dev, "machine LCCR0 setting contains "
1645 "illegal bits: %08x\n",
1646 inf->lccr0 & LCCR0_INVALID_CONFIG_MASK);
1647 if (inf->lccr3 & LCCR3_INVALID_CONFIG_MASK)
1648 dev_warn(dev, "machine LCCR3 setting contains "
1649 "illegal bits: %08x\n",
1650 inf->lccr3 & LCCR3_INVALID_CONFIG_MASK);
1651 if (inf->lccr0 & LCCR0_DPD &&
1652 ((inf->lccr0 & LCCR0_PAS) != LCCR0_Pas ||
1653 (inf->lccr0 & LCCR0_SDS) != LCCR0_Sngl ||
1654 (inf->lccr0 & LCCR0_CMS) != LCCR0_Mono))
1655 dev_warn(dev, "Double Pixel Data (DPD) mode is "
1656 "only valid in passive mono"
1657 " single panel mode\n");
1658 if ((inf->lccr0 & LCCR0_PAS) == LCCR0_Act &&
1659 (inf->lccr0 & LCCR0_SDS) == LCCR0_Dual)
1660 dev_warn(dev, "Dual panel only valid in passive mode\n");
1661 if ((inf->lccr0 & LCCR0_PAS) == LCCR0_Pas &&
1662 (inf->modes->upper_margin || inf->modes->lower_margin))
1663 dev_warn(dev, "Upper and lower margins must be 0 in "
1664 "passive mode\n");
1665}
1666#else
1667#define pxafb_check_options(...) do {} while (0)
1668#endif
1669
Jaya Kumar9e6c2972008-06-22 04:27:27 +01001670static int __devinit pxafb_probe(struct platform_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001671{
1672 struct pxafb_info *fbi;
1673 struct pxafb_mach_info *inf;
eric miaoce4fb7b2008-04-30 00:52:21 -07001674 struct resource *r;
1675 int irq, ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001676
Richard Purdie2cbbb3b2006-03-31 02:31:53 -08001677 dev_dbg(&dev->dev, "pxafb_probe\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001678
Russell King3ae5eae2005-11-09 22:32:44 +00001679 inf = dev->dev.platform_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001680 ret = -ENOMEM;
1681 fbi = NULL;
1682 if (!inf)
1683 goto failed;
1684
Russell King3ae5eae2005-11-09 22:32:44 +00001685 ret = pxafb_parse_options(&dev->dev, g_options);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001686 if (ret < 0)
1687 goto failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001688
Eric Miao4f3e2662008-08-16 03:50:51 -04001689 pxafb_check_options(&dev->dev, inf);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001690
eric miaob0086ef2008-04-30 00:52:19 -07001691 dev_dbg(&dev->dev, "got a %dx%dx%d LCD\n",
1692 inf->modes->xres,
1693 inf->modes->yres,
1694 inf->modes->bpp);
1695 if (inf->modes->xres == 0 ||
1696 inf->modes->yres == 0 ||
1697 inf->modes->bpp == 0) {
Russell King3ae5eae2005-11-09 22:32:44 +00001698 dev_err(&dev->dev, "Invalid resolution or bit depth\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001699 ret = -EINVAL;
1700 goto failed;
1701 }
Eric Miaoa5718a12008-11-11 21:50:39 +08001702
Russell King3ae5eae2005-11-09 22:32:44 +00001703 fbi = pxafb_init_fbinfo(&dev->dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001704 if (!fbi) {
eric miaob0086ef2008-04-30 00:52:19 -07001705 /* only reason for pxafb_init_fbinfo to fail is kmalloc */
Russell King3ae5eae2005-11-09 22:32:44 +00001706 dev_err(&dev->dev, "Failed to initialize framebuffer device\n");
eric miaob0086ef2008-04-30 00:52:19 -07001707 ret = -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001708 goto failed;
1709 }
1710
Eric Miaoa5718a12008-11-11 21:50:39 +08001711 fbi->backlight_power = inf->pxafb_backlight_power;
1712 fbi->lcd_power = inf->pxafb_lcd_power;
1713
eric miaoce4fb7b2008-04-30 00:52:21 -07001714 r = platform_get_resource(dev, IORESOURCE_MEM, 0);
1715 if (r == NULL) {
1716 dev_err(&dev->dev, "no I/O memory resource defined\n");
1717 ret = -ENODEV;
Jaya Kumaree984762008-06-22 04:27:26 +01001718 goto failed_fbi;
eric miaoce4fb7b2008-04-30 00:52:21 -07001719 }
1720
1721 r = request_mem_region(r->start, r->end - r->start + 1, dev->name);
1722 if (r == NULL) {
1723 dev_err(&dev->dev, "failed to request I/O memory\n");
1724 ret = -EBUSY;
Jaya Kumaree984762008-06-22 04:27:26 +01001725 goto failed_fbi;
eric miaoce4fb7b2008-04-30 00:52:21 -07001726 }
1727
1728 fbi->mmio_base = ioremap(r->start, r->end - r->start + 1);
1729 if (fbi->mmio_base == NULL) {
1730 dev_err(&dev->dev, "failed to map I/O memory\n");
1731 ret = -EBUSY;
1732 goto failed_free_res;
1733 }
1734
Eric Miao77e19672008-12-16 11:54:34 +08001735 fbi->dma_buff_size = PAGE_ALIGN(sizeof(struct pxafb_dma_buff));
1736 fbi->dma_buff = dma_alloc_coherent(fbi->dev, fbi->dma_buff_size,
1737 &fbi->dma_buff_phys, GFP_KERNEL);
1738 if (fbi->dma_buff == NULL) {
1739 dev_err(&dev->dev, "failed to allocate memory for DMA\n");
1740 ret = -ENOMEM;
1741 goto failed_free_io;
1742 }
1743
1744 ret = pxafb_init_video_memory(fbi);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001745 if (ret) {
Russell King3ae5eae2005-11-09 22:32:44 +00001746 dev_err(&dev->dev, "Failed to allocate video RAM: %d\n", ret);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001747 ret = -ENOMEM;
Eric Miao77e19672008-12-16 11:54:34 +08001748 goto failed_free_dma;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001749 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001750
eric miaoce4fb7b2008-04-30 00:52:21 -07001751 irq = platform_get_irq(dev, 0);
1752 if (irq < 0) {
1753 dev_err(&dev->dev, "no IRQ defined\n");
1754 ret = -ENODEV;
1755 goto failed_free_mem;
1756 }
1757
1758 ret = request_irq(irq, pxafb_handle_irq, IRQF_DISABLED, "LCD", fbi);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001759 if (ret) {
Russell King3ae5eae2005-11-09 22:32:44 +00001760 dev_err(&dev->dev, "request_irq failed: %d\n", ret);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001761 ret = -EBUSY;
eric miaoce4fb7b2008-04-30 00:52:21 -07001762 goto failed_free_mem;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001763 }
1764
Eric Miao3c42a442008-04-30 00:52:26 -07001765 ret = pxafb_smart_init(fbi);
1766 if (ret) {
1767 dev_err(&dev->dev, "failed to initialize smartpanel\n");
1768 goto failed_free_irq;
1769 }
Eric Miao07df1c42008-12-04 11:14:11 +08001770
Linus Torvalds1da177e2005-04-16 15:20:36 -07001771 /*
1772 * This makes sure that our colour bitfield
1773 * descriptors are correctly initialised.
1774 */
Jaya Kumaree984762008-06-22 04:27:26 +01001775 ret = pxafb_check_var(&fbi->fb.var, &fbi->fb);
1776 if (ret) {
1777 dev_err(&dev->dev, "failed to get suitable mode\n");
1778 goto failed_free_irq;
1779 }
1780
1781 ret = pxafb_set_par(&fbi->fb);
1782 if (ret) {
1783 dev_err(&dev->dev, "Failed to set parameters\n");
1784 goto failed_free_irq;
1785 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001786
Russell King3ae5eae2005-11-09 22:32:44 +00001787 platform_set_drvdata(dev, fbi);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001788
1789 ret = register_framebuffer(&fbi->fb);
1790 if (ret < 0) {
eric miaob0086ef2008-04-30 00:52:19 -07001791 dev_err(&dev->dev,
1792 "Failed to register framebuffer device: %d\n", ret);
Jaya Kumaree984762008-06-22 04:27:26 +01001793 goto failed_free_cmap;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001794 }
1795
Linus Torvalds1da177e2005-04-16 15:20:36 -07001796#ifdef CONFIG_CPU_FREQ
1797 fbi->freq_transition.notifier_call = pxafb_freq_transition;
1798 fbi->freq_policy.notifier_call = pxafb_freq_policy;
eric miaob0086ef2008-04-30 00:52:19 -07001799 cpufreq_register_notifier(&fbi->freq_transition,
1800 CPUFREQ_TRANSITION_NOTIFIER);
1801 cpufreq_register_notifier(&fbi->freq_policy,
1802 CPUFREQ_POLICY_NOTIFIER);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001803#endif
1804
1805 /*
1806 * Ok, now enable the LCD controller
1807 */
1808 set_ctrlr_state(fbi, C_ENABLE);
1809
1810 return 0;
1811
Jaya Kumaree984762008-06-22 04:27:26 +01001812failed_free_cmap:
1813 if (fbi->fb.cmap.len)
1814 fb_dealloc_cmap(&fbi->fb.cmap);
eric miaoce4fb7b2008-04-30 00:52:21 -07001815failed_free_irq:
1816 free_irq(irq, fbi);
eric miaoce4fb7b2008-04-30 00:52:21 -07001817failed_free_mem:
Eric Miao77e19672008-12-16 11:54:34 +08001818 free_pages_exact(fbi->video_mem, fbi->video_mem_size);
1819failed_free_dma:
1820 dma_free_coherent(&dev->dev, fbi->dma_buff_size,
1821 fbi->dma_buff, fbi->dma_buff_phys);
Jaya Kumaree984762008-06-22 04:27:26 +01001822failed_free_io:
1823 iounmap(fbi->mmio_base);
1824failed_free_res:
1825 release_mem_region(r->start, r->end - r->start + 1);
1826failed_fbi:
1827 clk_put(fbi->clk);
Russell King3ae5eae2005-11-09 22:32:44 +00001828 platform_set_drvdata(dev, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001829 kfree(fbi);
Jaya Kumaree984762008-06-22 04:27:26 +01001830failed:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001831 return ret;
1832}
1833
Jaya Kumar9f17f282008-06-22 04:27:28 +01001834static int __devexit pxafb_remove(struct platform_device *dev)
1835{
1836 struct pxafb_info *fbi = platform_get_drvdata(dev);
1837 struct resource *r;
1838 int irq;
1839 struct fb_info *info;
1840
1841 if (!fbi)
1842 return 0;
1843
1844 info = &fbi->fb;
1845
1846 unregister_framebuffer(info);
1847
1848 pxafb_disable_controller(fbi);
1849
1850 if (fbi->fb.cmap.len)
1851 fb_dealloc_cmap(&fbi->fb.cmap);
1852
1853 irq = platform_get_irq(dev, 0);
1854 free_irq(irq, fbi);
1855
Eric Miao77e19672008-12-16 11:54:34 +08001856 free_pages_exact(fbi->video_mem, fbi->video_mem_size);
1857
1858 dma_free_writecombine(&dev->dev, fbi->dma_buff_size,
1859 fbi->dma_buff, fbi->dma_buff_phys);
Jaya Kumar9f17f282008-06-22 04:27:28 +01001860
1861 iounmap(fbi->mmio_base);
1862
1863 r = platform_get_resource(dev, IORESOURCE_MEM, 0);
1864 release_mem_region(r->start, r->end - r->start + 1);
1865
1866 clk_put(fbi->clk);
1867 kfree(fbi);
1868
1869 return 0;
1870}
1871
Russell King3ae5eae2005-11-09 22:32:44 +00001872static struct platform_driver pxafb_driver = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001873 .probe = pxafb_probe,
Jaya Kumar9f17f282008-06-22 04:27:28 +01001874 .remove = pxafb_remove,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001875 .suspend = pxafb_suspend,
1876 .resume = pxafb_resume,
Russell King3ae5eae2005-11-09 22:32:44 +00001877 .driver = {
Jaya Kumar9f17f282008-06-22 04:27:28 +01001878 .owner = THIS_MODULE,
Russell King3ae5eae2005-11-09 22:32:44 +00001879 .name = "pxa2xx-fb",
1880 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001881};
1882
Jaya Kumar9e6c2972008-06-22 04:27:27 +01001883static int __init pxafb_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001884{
eric miao92ac73c2008-04-30 00:52:20 -07001885 if (pxafb_setup_options())
1886 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001887
Russell King3ae5eae2005-11-09 22:32:44 +00001888 return platform_driver_register(&pxafb_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001889}
1890
Jaya Kumar9f17f282008-06-22 04:27:28 +01001891static void __exit pxafb_exit(void)
1892{
1893 platform_driver_unregister(&pxafb_driver);
1894}
1895
Linus Torvalds1da177e2005-04-16 15:20:36 -07001896module_init(pxafb_init);
Jaya Kumar9f17f282008-06-22 04:27:28 +01001897module_exit(pxafb_exit);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001898
1899MODULE_DESCRIPTION("loadable framebuffer driver for PXA");
1900MODULE_LICENSE("GPL");