blob: cc59c52e1103dfdd48cd161fb37a385023890b5a [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>
53#include <mach/pxa2xx-gpio.h>
54#include <mach/bitfield.h>
55#include <mach/pxafb.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070056
57/*
58 * Complain if VAR is out of range.
59 */
60#define DEBUG_VAR 1
61
62#include "pxafb.h"
63
64/* Bits which should not be set in machine configuration structures */
eric miaob0086ef2008-04-30 00:52:19 -070065#define LCCR0_INVALID_CONFIG_MASK (LCCR0_OUM | LCCR0_BM | LCCR0_QDM |\
66 LCCR0_DIS | LCCR0_EFM | LCCR0_IUM |\
67 LCCR0_SFM | LCCR0_LDM | LCCR0_ENB)
68
69#define LCCR3_INVALID_CONFIG_MASK (LCCR3_HSP | LCCR3_VSP |\
70 LCCR3_PCD | LCCR3_BPP)
Linus Torvalds1da177e2005-04-16 15:20:36 -070071
72static void (*pxafb_backlight_power)(int);
Richard Purdied14b2722006-09-20 22:54:21 +010073static void (*pxafb_lcd_power)(int, struct fb_var_screeninfo *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070074
eric miaob0086ef2008-04-30 00:52:19 -070075static int pxafb_activate_var(struct fb_var_screeninfo *var,
76 struct pxafb_info *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070077static void set_ctrlr_state(struct pxafb_info *fbi, u_int state);
78
Eric Miaoa7535ba2008-04-30 00:52:24 -070079static inline unsigned long
80lcd_readl(struct pxafb_info *fbi, unsigned int off)
81{
82 return __raw_readl(fbi->mmio_base + off);
83}
84
85static inline void
86lcd_writel(struct pxafb_info *fbi, unsigned int off, unsigned long val)
87{
88 __raw_writel(val, fbi->mmio_base + off);
89}
90
Linus Torvalds1da177e2005-04-16 15:20:36 -070091static inline void pxafb_schedule_work(struct pxafb_info *fbi, u_int state)
92{
93 unsigned long flags;
94
95 local_irq_save(flags);
96 /*
97 * We need to handle two requests being made at the same time.
98 * There are two important cases:
eric miaob0086ef2008-04-30 00:52:19 -070099 * 1. When we are changing VT (C_REENABLE) while unblanking
100 * (C_ENABLE) We must perform the unblanking, which will
101 * do our REENABLE for us.
102 * 2. When we are blanking, but immediately unblank before
103 * we have blanked. We do the "REENABLE" thing here as
104 * well, just to be sure.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105 */
106 if (fbi->task_state == C_ENABLE && state == C_REENABLE)
107 state = (u_int) -1;
108 if (fbi->task_state == C_DISABLE && state == C_ENABLE)
109 state = C_REENABLE;
110
111 if (state != (u_int)-1) {
112 fbi->task_state = state;
113 schedule_work(&fbi->task);
114 }
115 local_irq_restore(flags);
116}
117
118static inline u_int chan_to_field(u_int chan, struct fb_bitfield *bf)
119{
120 chan &= 0xffff;
121 chan >>= 16 - bf->length;
122 return chan << bf->offset;
123}
124
125static int
126pxafb_setpalettereg(u_int regno, u_int red, u_int green, u_int blue,
127 u_int trans, struct fb_info *info)
128{
129 struct pxafb_info *fbi = (struct pxafb_info *)info;
Hans J. Koch9ffa7392007-10-16 01:28:41 -0700130 u_int val;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131
Hans J. Koch9ffa7392007-10-16 01:28:41 -0700132 if (regno >= fbi->palette_size)
133 return 1;
134
135 if (fbi->fb.var.grayscale) {
136 fbi->palette_cpu[regno] = ((blue >> 8) & 0x00ff);
137 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138 }
Hans J. Koch9ffa7392007-10-16 01:28:41 -0700139
140 switch (fbi->lccr4 & LCCR4_PAL_FOR_MASK) {
141 case LCCR4_PAL_FOR_0:
142 val = ((red >> 0) & 0xf800);
143 val |= ((green >> 5) & 0x07e0);
144 val |= ((blue >> 11) & 0x001f);
145 fbi->palette_cpu[regno] = val;
146 break;
147 case LCCR4_PAL_FOR_1:
148 val = ((red << 8) & 0x00f80000);
149 val |= ((green >> 0) & 0x0000fc00);
150 val |= ((blue >> 8) & 0x000000f8);
eric miaob0086ef2008-04-30 00:52:19 -0700151 ((u32 *)(fbi->palette_cpu))[regno] = val;
Hans J. Koch9ffa7392007-10-16 01:28:41 -0700152 break;
153 case LCCR4_PAL_FOR_2:
154 val = ((red << 8) & 0x00fc0000);
155 val |= ((green >> 0) & 0x0000fc00);
156 val |= ((blue >> 8) & 0x000000fc);
eric miaob0086ef2008-04-30 00:52:19 -0700157 ((u32 *)(fbi->palette_cpu))[regno] = val;
Hans J. Koch9ffa7392007-10-16 01:28:41 -0700158 break;
159 }
160
161 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162}
163
164static int
165pxafb_setcolreg(u_int regno, u_int red, u_int green, u_int blue,
166 u_int trans, struct fb_info *info)
167{
168 struct pxafb_info *fbi = (struct pxafb_info *)info;
169 unsigned int val;
170 int ret = 1;
171
172 /*
173 * If inverse mode was selected, invert all the colours
174 * rather than the register number. The register number
175 * is what you poke into the framebuffer to produce the
176 * colour you requested.
177 */
178 if (fbi->cmap_inverse) {
179 red = 0xffff - red;
180 green = 0xffff - green;
181 blue = 0xffff - blue;
182 }
183
184 /*
185 * If greyscale is true, then we convert the RGB value
186 * to greyscale no matter what visual we are using.
187 */
188 if (fbi->fb.var.grayscale)
189 red = green = blue = (19595 * red + 38470 * green +
190 7471 * blue) >> 16;
191
192 switch (fbi->fb.fix.visual) {
193 case FB_VISUAL_TRUECOLOR:
194 /*
195 * 16-bit True Colour. We encode the RGB value
196 * according to the RGB bitfield information.
197 */
198 if (regno < 16) {
199 u32 *pal = fbi->fb.pseudo_palette;
200
201 val = chan_to_field(red, &fbi->fb.var.red);
202 val |= chan_to_field(green, &fbi->fb.var.green);
203 val |= chan_to_field(blue, &fbi->fb.var.blue);
204
205 pal[regno] = val;
206 ret = 0;
207 }
208 break;
209
210 case FB_VISUAL_STATIC_PSEUDOCOLOR:
211 case FB_VISUAL_PSEUDOCOLOR:
212 ret = pxafb_setpalettereg(regno, red, green, blue, trans, info);
213 break;
214 }
215
216 return ret;
217}
218
219/*
220 * pxafb_bpp_to_lccr3():
221 * Convert a bits per pixel value to the correct bit pattern for LCCR3
222 */
223static int pxafb_bpp_to_lccr3(struct fb_var_screeninfo *var)
224{
eric miaob0086ef2008-04-30 00:52:19 -0700225 int ret = 0;
226 switch (var->bits_per_pixel) {
227 case 1: ret = LCCR3_1BPP; break;
228 case 2: ret = LCCR3_2BPP; break;
229 case 4: ret = LCCR3_4BPP; break;
230 case 8: ret = LCCR3_8BPP; break;
231 case 16: ret = LCCR3_16BPP; break;
Stefan Schmidtc1450f12008-07-09 08:06:32 +0100232 case 24:
233 switch (var->red.length + var->green.length +
234 var->blue.length + var->transp.length) {
235 case 18: ret = LCCR3_18BPP_P | LCCR3_PDFOR_3; break;
236 case 19: ret = LCCR3_19BPP_P; break;
237 }
238 break;
239 case 32:
240 switch (var->red.length + var->green.length +
241 var->blue.length + var->transp.length) {
242 case 18: ret = LCCR3_18BPP | LCCR3_PDFOR_3; break;
243 case 19: ret = LCCR3_19BPP; break;
244 case 24: ret = LCCR3_24BPP | LCCR3_PDFOR_3; break;
245 case 25: ret = LCCR3_25BPP; break;
246 }
247 break;
eric miaob0086ef2008-04-30 00:52:19 -0700248 }
249 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250}
251
252#ifdef CONFIG_CPU_FREQ
253/*
254 * pxafb_display_dma_period()
255 * Calculate the minimum period (in picoseconds) between two DMA
256 * requests for the LCD controller. If we hit this, it means we're
257 * doing nothing but LCD DMA.
258 */
259static unsigned int pxafb_display_dma_period(struct fb_var_screeninfo *var)
260{
eric miaob0086ef2008-04-30 00:52:19 -0700261 /*
262 * Period = pixclock * bits_per_byte * bytes_per_transfer
263 * / memory_bits_per_pixel;
264 */
265 return var->pixclock * 8 * 16 / var->bits_per_pixel;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267#endif
268
269/*
Richard Purdied14b2722006-09-20 22:54:21 +0100270 * Select the smallest mode that allows the desired resolution to be
271 * displayed. If desired parameters can be rounded up.
272 */
eric miaob0086ef2008-04-30 00:52:19 -0700273static struct pxafb_mode_info *pxafb_getmode(struct pxafb_mach_info *mach,
274 struct fb_var_screeninfo *var)
Richard Purdied14b2722006-09-20 22:54:21 +0100275{
276 struct pxafb_mode_info *mode = NULL;
277 struct pxafb_mode_info *modelist = mach->modes;
278 unsigned int best_x = 0xffffffff, best_y = 0xffffffff;
279 unsigned int i;
280
eric miaob0086ef2008-04-30 00:52:19 -0700281 for (i = 0; i < mach->num_modes; i++) {
282 if (modelist[i].xres >= var->xres &&
283 modelist[i].yres >= var->yres &&
284 modelist[i].xres < best_x &&
285 modelist[i].yres < best_y &&
286 modelist[i].bpp >= var->bits_per_pixel) {
Richard Purdied14b2722006-09-20 22:54:21 +0100287 best_x = modelist[i].xres;
288 best_y = modelist[i].yres;
289 mode = &modelist[i];
290 }
291 }
292
293 return mode;
294}
295
eric miaob0086ef2008-04-30 00:52:19 -0700296static void pxafb_setmode(struct fb_var_screeninfo *var,
297 struct pxafb_mode_info *mode)
Richard Purdied14b2722006-09-20 22:54:21 +0100298{
299 var->xres = mode->xres;
300 var->yres = mode->yres;
301 var->bits_per_pixel = mode->bpp;
302 var->pixclock = mode->pixclock;
303 var->hsync_len = mode->hsync_len;
304 var->left_margin = mode->left_margin;
305 var->right_margin = mode->right_margin;
306 var->vsync_len = mode->vsync_len;
307 var->upper_margin = mode->upper_margin;
308 var->lower_margin = mode->lower_margin;
309 var->sync = mode->sync;
310 var->grayscale = mode->cmap_greyscale;
311 var->xres_virtual = var->xres;
312 var->yres_virtual = var->yres;
313}
314
315/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316 * pxafb_check_var():
317 * Get the video params out of 'var'. If a value doesn't fit, round it up,
318 * if it's too big, return -EINVAL.
319 *
320 * Round up in the following order: bits_per_pixel, xres,
321 * yres, xres_virtual, yres_virtual, xoffset, yoffset, grayscale,
322 * bitfields, horizontal timing, vertical timing.
323 */
324static int pxafb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
325{
326 struct pxafb_info *fbi = (struct pxafb_info *)info;
Richard Purdied14b2722006-09-20 22:54:21 +0100327 struct pxafb_mach_info *inf = fbi->dev->platform_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328
329 if (var->xres < MIN_XRES)
330 var->xres = MIN_XRES;
331 if (var->yres < MIN_YRES)
332 var->yres = MIN_YRES;
Richard Purdied14b2722006-09-20 22:54:21 +0100333
334 if (inf->fixed_modes) {
335 struct pxafb_mode_info *mode;
336
337 mode = pxafb_getmode(inf, var);
338 if (!mode)
339 return -EINVAL;
340 pxafb_setmode(var, mode);
341 } else {
342 if (var->xres > inf->modes->xres)
343 return -EINVAL;
344 if (var->yres > inf->modes->yres)
345 return -EINVAL;
346 if (var->bits_per_pixel > inf->modes->bpp)
347 return -EINVAL;
348 }
349
Linus Torvalds1da177e2005-04-16 15:20:36 -0700350 var->xres_virtual =
351 max(var->xres_virtual, var->xres);
352 var->yres_virtual =
353 max(var->yres_virtual, var->yres);
354
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
Christoph Hellwig216d5262006-01-14 13:21:25 -0800505static int pxafb_mmap(struct fb_info *info,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700506 struct vm_area_struct *vma)
507{
508 struct pxafb_info *fbi = (struct pxafb_info *)info;
509 unsigned long off = vma->vm_pgoff << PAGE_SHIFT;
510
511 if (off < info->fix.smem_len) {
Eric Miao3c42a442008-04-30 00:52:26 -0700512 vma->vm_pgoff += fbi->video_offset / PAGE_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700513 return dma_mmap_writecombine(fbi->dev, vma, fbi->map_cpu,
514 fbi->map_dma, fbi->map_size);
515 }
516 return -EINVAL;
517}
518
519static struct fb_ops pxafb_ops = {
520 .owner = THIS_MODULE,
521 .fb_check_var = pxafb_check_var,
522 .fb_set_par = pxafb_set_par,
523 .fb_setcolreg = pxafb_setcolreg,
524 .fb_fillrect = cfb_fillrect,
525 .fb_copyarea = cfb_copyarea,
526 .fb_imageblit = cfb_imageblit,
527 .fb_blank = pxafb_blank,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528 .fb_mmap = pxafb_mmap,
529};
530
531/*
532 * Calculate the PCD value from the clock rate (in picoseconds).
533 * We take account of the PPCR clock setting.
534 * From PXA Developer's Manual:
535 *
536 * PixelClock = LCLK
537 * -------------
538 * 2 ( PCD + 1 )
539 *
540 * PCD = LCLK
541 * ------------- - 1
542 * 2(PixelClock)
543 *
544 * Where:
545 * LCLK = LCD/Memory Clock
546 * PCD = LCCR3[7:0]
547 *
548 * PixelClock here is in Hz while the pixclock argument given is the
549 * period in picoseconds. Hence PixelClock = 1 / ( pixclock * 10^-12 )
550 *
551 * The function get_lclk_frequency_10khz returns LCLK in units of
552 * 10khz. Calling the result of this function lclk gives us the
553 * following
554 *
555 * PCD = (lclk * 10^4 ) * ( pixclock * 10^-12 )
556 * -------------------------------------- - 1
557 * 2
558 *
559 * Factoring the 10^4 and 10^-12 out gives 10^-8 == 1 / 100000000 as used below.
560 */
eric miaob0086ef2008-04-30 00:52:19 -0700561static inline unsigned int get_pcd(struct pxafb_info *fbi,
562 unsigned int pixclock)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700563{
564 unsigned long long pcd;
565
566 /* FIXME: Need to take into account Double Pixel Clock mode
Russell King72e35242007-08-20 10:18:42 +0100567 * (DPC) bit? or perhaps set it based on the various clock
568 * speeds */
569 pcd = (unsigned long long)(clk_get_rate(fbi->clk) / 10000);
570 pcd *= pixclock;
Nicolas Pitrebf1b8ab2005-06-23 21:56:45 +0100571 do_div(pcd, 100000000 * 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700572 /* no need for this, since we should subtract 1 anyway. they cancel */
573 /* pcd += 1; */ /* make up for integer math truncations */
574 return (unsigned int)pcd;
575}
576
577/*
Richard Purdieba44cd22005-09-09 13:10:03 -0700578 * Some touchscreens need hsync information from the video driver to
Russell King72e35242007-08-20 10:18:42 +0100579 * function correctly. We export it here. Note that 'hsync_time' and
580 * the value returned from pxafb_get_hsync_time() is the *reciprocal*
581 * of the hsync period in seconds.
Richard Purdieba44cd22005-09-09 13:10:03 -0700582 */
583static inline void set_hsync_time(struct pxafb_info *fbi, unsigned int pcd)
584{
Russell King72e35242007-08-20 10:18:42 +0100585 unsigned long htime;
Richard Purdieba44cd22005-09-09 13:10:03 -0700586
587 if ((pcd == 0) || (fbi->fb.var.hsync_len == 0)) {
eric miaob0086ef2008-04-30 00:52:19 -0700588 fbi->hsync_time = 0;
Richard Purdieba44cd22005-09-09 13:10:03 -0700589 return;
590 }
591
Russell King72e35242007-08-20 10:18:42 +0100592 htime = clk_get_rate(fbi->clk) / (pcd * fbi->fb.var.hsync_len);
593
Richard Purdieba44cd22005-09-09 13:10:03 -0700594 fbi->hsync_time = htime;
595}
596
597unsigned long pxafb_get_hsync_time(struct device *dev)
598{
599 struct pxafb_info *fbi = dev_get_drvdata(dev);
600
601 /* If display is blanked/suspended, hsync isn't active */
602 if (!fbi || (fbi->state != C_ENABLE))
603 return 0;
604
605 return fbi->hsync_time;
606}
607EXPORT_SYMBOL(pxafb_get_hsync_time);
608
eric miao2c42dd82008-04-30 00:52:21 -0700609static int setup_frame_dma(struct pxafb_info *fbi, int dma, int pal,
610 unsigned int offset, size_t size)
611{
612 struct pxafb_dma_descriptor *dma_desc, *pal_desc;
613 unsigned int dma_desc_off, pal_desc_off;
614
615 if (dma < 0 || dma >= DMA_MAX)
616 return -EINVAL;
617
618 dma_desc = &fbi->dma_buff->dma_desc[dma];
619 dma_desc_off = offsetof(struct pxafb_dma_buff, dma_desc[dma]);
620
621 dma_desc->fsadr = fbi->screen_dma + offset;
622 dma_desc->fidr = 0;
623 dma_desc->ldcmd = size;
624
625 if (pal < 0 || pal >= PAL_MAX) {
626 dma_desc->fdadr = fbi->dma_buff_phys + dma_desc_off;
627 fbi->fdadr[dma] = fbi->dma_buff_phys + dma_desc_off;
628 } else {
Jürgen Schindele62cfcf42008-06-11 19:56:06 +0100629 pal_desc = &fbi->dma_buff->pal_desc[pal];
630 pal_desc_off = offsetof(struct pxafb_dma_buff, pal_desc[pal]);
eric miao2c42dd82008-04-30 00:52:21 -0700631
632 pal_desc->fsadr = fbi->dma_buff_phys + pal * PALETTE_SIZE;
633 pal_desc->fidr = 0;
634
635 if ((fbi->lccr4 & LCCR4_PAL_FOR_MASK) == LCCR4_PAL_FOR_0)
636 pal_desc->ldcmd = fbi->palette_size * sizeof(u16);
637 else
638 pal_desc->ldcmd = fbi->palette_size * sizeof(u32);
639
640 pal_desc->ldcmd |= LDCMD_PAL;
641
642 /* flip back and forth between palette and frame buffer */
643 pal_desc->fdadr = fbi->dma_buff_phys + dma_desc_off;
644 dma_desc->fdadr = fbi->dma_buff_phys + pal_desc_off;
645 fbi->fdadr[dma] = fbi->dma_buff_phys + dma_desc_off;
646 }
647
648 return 0;
649}
650
Eric Miao3c42a442008-04-30 00:52:26 -0700651#ifdef CONFIG_FB_PXA_SMARTPANEL
652static int setup_smart_dma(struct pxafb_info *fbi)
653{
654 struct pxafb_dma_descriptor *dma_desc;
655 unsigned long dma_desc_off, cmd_buff_off;
656
657 dma_desc = &fbi->dma_buff->dma_desc[DMA_CMD];
658 dma_desc_off = offsetof(struct pxafb_dma_buff, dma_desc[DMA_CMD]);
659 cmd_buff_off = offsetof(struct pxafb_dma_buff, cmd_buff);
660
661 dma_desc->fdadr = fbi->dma_buff_phys + dma_desc_off;
662 dma_desc->fsadr = fbi->dma_buff_phys + cmd_buff_off;
663 dma_desc->fidr = 0;
664 dma_desc->ldcmd = fbi->n_smart_cmds * sizeof(uint16_t);
665
666 fbi->fdadr[DMA_CMD] = dma_desc->fdadr;
667 return 0;
668}
669
670int pxafb_smart_flush(struct fb_info *info)
671{
672 struct pxafb_info *fbi = container_of(info, struct pxafb_info, fb);
673 uint32_t prsr;
674 int ret = 0;
675
676 /* disable controller until all registers are set up */
677 lcd_writel(fbi, LCCR0, fbi->reg_lccr0 & ~LCCR0_ENB);
678
679 /* 1. make it an even number of commands to align on 32-bit boundary
680 * 2. add the interrupt command to the end of the chain so we can
681 * keep track of the end of the transfer
682 */
683
684 while (fbi->n_smart_cmds & 1)
685 fbi->smart_cmds[fbi->n_smart_cmds++] = SMART_CMD_NOOP;
686
687 fbi->smart_cmds[fbi->n_smart_cmds++] = SMART_CMD_INTERRUPT;
688 fbi->smart_cmds[fbi->n_smart_cmds++] = SMART_CMD_WAIT_FOR_VSYNC;
689 setup_smart_dma(fbi);
690
691 /* continue to execute next command */
692 prsr = lcd_readl(fbi, PRSR) | PRSR_ST_OK | PRSR_CON_NT;
693 lcd_writel(fbi, PRSR, prsr);
694
695 /* stop the processor in case it executed "wait for sync" cmd */
696 lcd_writel(fbi, CMDCR, 0x0001);
697
698 /* don't send interrupts for fifo underruns on channel 6 */
699 lcd_writel(fbi, LCCR5, LCCR5_IUM(6));
700
701 lcd_writel(fbi, LCCR1, fbi->reg_lccr1);
702 lcd_writel(fbi, LCCR2, fbi->reg_lccr2);
703 lcd_writel(fbi, LCCR3, fbi->reg_lccr3);
704 lcd_writel(fbi, FDADR0, fbi->fdadr[0]);
705 lcd_writel(fbi, FDADR6, fbi->fdadr[6]);
706
707 /* begin sending */
708 lcd_writel(fbi, LCCR0, fbi->reg_lccr0 | LCCR0_ENB);
709
710 if (wait_for_completion_timeout(&fbi->command_done, HZ/2) == 0) {
711 pr_warning("%s: timeout waiting for command done\n",
712 __func__);
713 ret = -ETIMEDOUT;
714 }
715
716 /* quick disable */
717 prsr = lcd_readl(fbi, PRSR) & ~(PRSR_ST_OK | PRSR_CON_NT);
718 lcd_writel(fbi, PRSR, prsr);
719 lcd_writel(fbi, LCCR0, fbi->reg_lccr0 & ~LCCR0_ENB);
720 lcd_writel(fbi, FDADR6, 0);
721 fbi->n_smart_cmds = 0;
722 return ret;
723}
724
725int pxafb_smart_queue(struct fb_info *info, uint16_t *cmds, int n_cmds)
726{
727 int i;
728 struct pxafb_info *fbi = container_of(info, struct pxafb_info, fb);
729
730 /* leave 2 commands for INTERRUPT and WAIT_FOR_SYNC */
731 for (i = 0; i < n_cmds; i++) {
732 if (fbi->n_smart_cmds == CMD_BUFF_SIZE - 8)
733 pxafb_smart_flush(info);
734
735 fbi->smart_cmds[fbi->n_smart_cmds++] = *cmds++;
736 }
737
738 return 0;
739}
740
741static unsigned int __smart_timing(unsigned time_ns, unsigned long lcd_clk)
742{
743 unsigned int t = (time_ns * (lcd_clk / 1000000) / 1000);
744 return (t == 0) ? 1 : t;
745}
746
747static void setup_smart_timing(struct pxafb_info *fbi,
748 struct fb_var_screeninfo *var)
749{
750 struct pxafb_mach_info *inf = fbi->dev->platform_data;
751 struct pxafb_mode_info *mode = &inf->modes[0];
752 unsigned long lclk = clk_get_rate(fbi->clk);
753 unsigned t1, t2, t3, t4;
754
755 t1 = max(mode->a0csrd_set_hld, mode->a0cswr_set_hld);
756 t2 = max(mode->rd_pulse_width, mode->wr_pulse_width);
757 t3 = mode->op_hold_time;
758 t4 = mode->cmd_inh_time;
759
760 fbi->reg_lccr1 =
761 LCCR1_DisWdth(var->xres) |
762 LCCR1_BegLnDel(__smart_timing(t1, lclk)) |
763 LCCR1_EndLnDel(__smart_timing(t2, lclk)) |
764 LCCR1_HorSnchWdth(__smart_timing(t3, lclk));
765
766 fbi->reg_lccr2 = LCCR2_DisHght(var->yres);
767 fbi->reg_lccr3 = LCCR3_PixClkDiv(__smart_timing(t4, lclk));
768
769 /* FIXME: make this configurable */
770 fbi->reg_cmdcr = 1;
771}
772
773static int pxafb_smart_thread(void *arg)
774{
Eric Miao7f1133c2008-04-30 00:52:27 -0700775 struct pxafb_info *fbi = arg;
Eric Miao3c42a442008-04-30 00:52:26 -0700776 struct pxafb_mach_info *inf = fbi->dev->platform_data;
777
778 if (!fbi || !inf->smart_update) {
779 pr_err("%s: not properly initialized, thread terminated\n",
780 __func__);
781 return -EINVAL;
782 }
783
784 pr_debug("%s(): task starting\n", __func__);
785
786 set_freezable();
787 while (!kthread_should_stop()) {
788
789 if (try_to_freeze())
790 continue;
791
792 if (fbi->state == C_ENABLE) {
793 inf->smart_update(&fbi->fb);
794 complete(&fbi->refresh_done);
795 }
796
797 set_current_state(TASK_INTERRUPTIBLE);
798 schedule_timeout(30 * HZ / 1000);
799 }
800
801 pr_debug("%s(): task ending\n", __func__);
802 return 0;
803}
804
805static int pxafb_smart_init(struct pxafb_info *fbi)
806{
Eric Miao6cc4abe2008-11-11 21:47:07 +0800807 if (!(fbi->lccr0 | LCCR0_LCDT))
808 return 0;
809
Eric Miao3c42a442008-04-30 00:52:26 -0700810 fbi->smart_thread = kthread_run(pxafb_smart_thread, fbi,
811 "lcd_refresh");
812 if (IS_ERR(fbi->smart_thread)) {
813 printk(KERN_ERR "%s: unable to create kernel thread\n",
814 __func__);
815 return PTR_ERR(fbi->smart_thread);
816 }
817 return 0;
818}
819#else
820int pxafb_smart_queue(struct fb_info *info, uint16_t *cmds, int n_cmds)
821{
822 return 0;
823}
824
825int pxafb_smart_flush(struct fb_info *info)
826{
827 return 0;
828}
829#endif /* CONFIG_FB_SMART_PANEL */
830
Eric Miao90eabbf2008-04-30 00:52:25 -0700831static void setup_parallel_timing(struct pxafb_info *fbi,
832 struct fb_var_screeninfo *var)
833{
834 unsigned int lines_per_panel, pcd = get_pcd(fbi, var->pixclock);
835
836 fbi->reg_lccr1 =
837 LCCR1_DisWdth(var->xres) +
838 LCCR1_HorSnchWdth(var->hsync_len) +
839 LCCR1_BegLnDel(var->left_margin) +
840 LCCR1_EndLnDel(var->right_margin);
841
842 /*
843 * If we have a dual scan LCD, we need to halve
844 * the YRES parameter.
845 */
846 lines_per_panel = var->yres;
847 if ((fbi->lccr0 & LCCR0_SDS) == LCCR0_Dual)
848 lines_per_panel /= 2;
849
850 fbi->reg_lccr2 =
851 LCCR2_DisHght(lines_per_panel) +
852 LCCR2_VrtSnchWdth(var->vsync_len) +
853 LCCR2_BegFrmDel(var->upper_margin) +
854 LCCR2_EndFrmDel(var->lower_margin);
855
856 fbi->reg_lccr3 = fbi->lccr3 |
857 (var->sync & FB_SYNC_HOR_HIGH_ACT ?
858 LCCR3_HorSnchH : LCCR3_HorSnchL) |
859 (var->sync & FB_SYNC_VERT_HIGH_ACT ?
860 LCCR3_VrtSnchH : LCCR3_VrtSnchL);
861
862 if (pcd) {
863 fbi->reg_lccr3 |= LCCR3_PixClkDiv(pcd);
864 set_hsync_time(fbi, pcd);
865 }
866}
867
Richard Purdieba44cd22005-09-09 13:10:03 -0700868/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700869 * pxafb_activate_var():
eric miaob0086ef2008-04-30 00:52:19 -0700870 * Configures LCD Controller based on entries in var parameter.
871 * Settings are only written to the controller if changes were made.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700872 */
eric miaob0086ef2008-04-30 00:52:19 -0700873static int pxafb_activate_var(struct fb_var_screeninfo *var,
874 struct pxafb_info *fbi)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700875{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700876 u_long flags;
eric miao2c42dd82008-04-30 00:52:21 -0700877 size_t nbytes;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700878
Linus Torvalds1da177e2005-04-16 15:20:36 -0700879#if DEBUG_VAR
Eric Miao3c42a442008-04-30 00:52:26 -0700880 if (!(fbi->lccr0 & LCCR0_LCDT)) {
881 if (var->xres < 16 || var->xres > 1024)
882 printk(KERN_ERR "%s: invalid xres %d\n",
883 fbi->fb.fix.id, var->xres);
884 switch (var->bits_per_pixel) {
885 case 1:
886 case 2:
887 case 4:
888 case 8:
889 case 16:
Stefan Schmidtc1450f12008-07-09 08:06:32 +0100890 case 24:
891 case 32:
Eric Miao3c42a442008-04-30 00:52:26 -0700892 break;
893 default:
894 printk(KERN_ERR "%s: invalid bit depth %d\n",
895 fbi->fb.fix.id, var->bits_per_pixel);
896 break;
897 }
898
899 if (var->hsync_len < 1 || var->hsync_len > 64)
900 printk(KERN_ERR "%s: invalid hsync_len %d\n",
901 fbi->fb.fix.id, var->hsync_len);
902 if (var->left_margin < 1 || var->left_margin > 255)
903 printk(KERN_ERR "%s: invalid left_margin %d\n",
904 fbi->fb.fix.id, var->left_margin);
905 if (var->right_margin < 1 || var->right_margin > 255)
906 printk(KERN_ERR "%s: invalid right_margin %d\n",
907 fbi->fb.fix.id, var->right_margin);
908 if (var->yres < 1 || var->yres > 1024)
909 printk(KERN_ERR "%s: invalid yres %d\n",
910 fbi->fb.fix.id, var->yres);
911 if (var->vsync_len < 1 || var->vsync_len > 64)
912 printk(KERN_ERR "%s: invalid vsync_len %d\n",
913 fbi->fb.fix.id, var->vsync_len);
914 if (var->upper_margin < 0 || var->upper_margin > 255)
915 printk(KERN_ERR "%s: invalid upper_margin %d\n",
916 fbi->fb.fix.id, var->upper_margin);
917 if (var->lower_margin < 0 || var->lower_margin > 255)
918 printk(KERN_ERR "%s: invalid lower_margin %d\n",
919 fbi->fb.fix.id, var->lower_margin);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700920 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700921#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700922 /* Update shadow copy atomically */
923 local_irq_save(flags);
924
Eric Miao3c42a442008-04-30 00:52:26 -0700925#ifdef CONFIG_FB_PXA_SMARTPANEL
926 if (fbi->lccr0 & LCCR0_LCDT)
927 setup_smart_timing(fbi, var);
928 else
929#endif
930 setup_parallel_timing(fbi, var);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700931
Eric Miao90eabbf2008-04-30 00:52:25 -0700932 fbi->reg_lccr0 = fbi->lccr0 |
933 (LCCR0_LDM | LCCR0_SFM | LCCR0_IUM | LCCR0_EFM |
934 LCCR0_QDM | LCCR0_BM | LCCR0_OUM);
935
936 fbi->reg_lccr3 |= pxafb_bpp_to_lccr3(var);
937
938 nbytes = var->yres * fbi->fb.fix.line_length;
939
940 if ((fbi->lccr0 & LCCR0_SDS) == LCCR0_Dual) {
941 nbytes = nbytes / 2;
eric miao2c42dd82008-04-30 00:52:21 -0700942 setup_frame_dma(fbi, DMA_LOWER, PAL_NONE, nbytes, nbytes);
Eric Miao90eabbf2008-04-30 00:52:25 -0700943 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700944
Eric Miao3c42a442008-04-30 00:52:26 -0700945 if ((var->bits_per_pixel >= 16) || (fbi->lccr0 & LCCR0_LCDT))
eric miao2c42dd82008-04-30 00:52:21 -0700946 setup_frame_dma(fbi, DMA_BASE, PAL_NONE, 0, nbytes);
Hans J. Koch9ffa7392007-10-16 01:28:41 -0700947 else
eric miao2c42dd82008-04-30 00:52:21 -0700948 setup_frame_dma(fbi, DMA_BASE, PAL_BASE, 0, nbytes);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700949
Eric Miaoa7535ba2008-04-30 00:52:24 -0700950 fbi->reg_lccr4 = lcd_readl(fbi, LCCR4) & ~LCCR4_PAL_FOR_MASK;
Hans J. Koch9ffa7392007-10-16 01:28:41 -0700951 fbi->reg_lccr4 |= (fbi->lccr4 & LCCR4_PAL_FOR_MASK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700952 local_irq_restore(flags);
953
954 /*
955 * Only update the registers if the controller is enabled
956 * and something has changed.
957 */
Eric Miaoa7535ba2008-04-30 00:52:24 -0700958 if ((lcd_readl(fbi, LCCR0) != fbi->reg_lccr0) ||
959 (lcd_readl(fbi, LCCR1) != fbi->reg_lccr1) ||
960 (lcd_readl(fbi, LCCR2) != fbi->reg_lccr2) ||
961 (lcd_readl(fbi, LCCR3) != fbi->reg_lccr3) ||
962 (lcd_readl(fbi, FDADR0) != fbi->fdadr[0]) ||
963 (lcd_readl(fbi, FDADR1) != fbi->fdadr[1]))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700964 pxafb_schedule_work(fbi, C_REENABLE);
965
966 return 0;
967}
968
969/*
970 * NOTE! The following functions are purely helpers for set_ctrlr_state.
971 * Do not call them directly; set_ctrlr_state does the correct serialisation
972 * to ensure that things happen in the right way 100% of time time.
973 * -- rmk
974 */
975static inline void __pxafb_backlight_power(struct pxafb_info *fbi, int on)
976{
Russell Kingca5da712005-09-29 09:44:54 +0100977 pr_debug("pxafb: backlight o%s\n", on ? "n" : "ff");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700978
eric miaob0086ef2008-04-30 00:52:19 -0700979 if (pxafb_backlight_power)
980 pxafb_backlight_power(on);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700981}
982
983static inline void __pxafb_lcd_power(struct pxafb_info *fbi, int on)
984{
Russell Kingca5da712005-09-29 09:44:54 +0100985 pr_debug("pxafb: LCD power o%s\n", on ? "n" : "ff");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700986
987 if (pxafb_lcd_power)
Richard Purdied14b2722006-09-20 22:54:21 +0100988 pxafb_lcd_power(on, &fbi->fb.var);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700989}
990
991static void pxafb_setup_gpio(struct pxafb_info *fbi)
992{
993 int gpio, ldd_bits;
eric miaob0086ef2008-04-30 00:52:19 -0700994 unsigned int lccr0 = fbi->lccr0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700995
996 /*
997 * setup is based on type of panel supported
eric miaob0086ef2008-04-30 00:52:19 -0700998 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700999
1000 /* 4 bit interface */
1001 if ((lccr0 & LCCR0_CMS) == LCCR0_Mono &&
1002 (lccr0 & LCCR0_SDS) == LCCR0_Sngl &&
1003 (lccr0 & LCCR0_DPD) == LCCR0_4PixMono)
1004 ldd_bits = 4;
1005
1006 /* 8 bit interface */
eric miaob0086ef2008-04-30 00:52:19 -07001007 else if (((lccr0 & LCCR0_CMS) == LCCR0_Mono &&
1008 ((lccr0 & LCCR0_SDS) == LCCR0_Dual ||
1009 (lccr0 & LCCR0_DPD) == LCCR0_8PixMono)) ||
1010 ((lccr0 & LCCR0_CMS) == LCCR0_Color &&
1011 (lccr0 & LCCR0_PAS) == LCCR0_Pas &&
1012 (lccr0 & LCCR0_SDS) == LCCR0_Sngl))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001013 ldd_bits = 8;
1014
1015 /* 16 bit interface */
1016 else if ((lccr0 & LCCR0_CMS) == LCCR0_Color &&
eric miaob0086ef2008-04-30 00:52:19 -07001017 ((lccr0 & LCCR0_SDS) == LCCR0_Dual ||
1018 (lccr0 & LCCR0_PAS) == LCCR0_Act))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001019 ldd_bits = 16;
1020
1021 else {
eric miaob0086ef2008-04-30 00:52:19 -07001022 printk(KERN_ERR "pxafb_setup_gpio: unable to determine "
1023 "bits per pixel\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001024 return;
eric miaob0086ef2008-04-30 00:52:19 -07001025 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001026
1027 for (gpio = 58; ldd_bits; gpio++, ldd_bits--)
1028 pxa_gpio_mode(gpio | GPIO_ALT_FN_2_OUT);
Stefan Schmidtc1450f12008-07-09 08:06:32 +01001029 /* 18 bit interface */
1030 if (fbi->fb.var.bits_per_pixel > 16) {
1031 pxa_gpio_mode(86 | GPIO_ALT_FN_2_OUT);
1032 pxa_gpio_mode(87 | GPIO_ALT_FN_2_OUT);
1033 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001034 pxa_gpio_mode(GPIO74_LCD_FCLK_MD);
1035 pxa_gpio_mode(GPIO75_LCD_LCLK_MD);
1036 pxa_gpio_mode(GPIO76_LCD_PCLK_MD);
Eric Miaocb477292008-08-16 03:59:11 -04001037
1038 if ((lccr0 & LCCR0_PAS) == 0)
1039 pxa_gpio_mode(GPIO77_LCD_ACBIAS_MD);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001040}
1041
1042static void pxafb_enable_controller(struct pxafb_info *fbi)
1043{
Russell Kingca5da712005-09-29 09:44:54 +01001044 pr_debug("pxafb: Enabling LCD controller\n");
eric miao2c42dd82008-04-30 00:52:21 -07001045 pr_debug("fdadr0 0x%08x\n", (unsigned int) fbi->fdadr[0]);
1046 pr_debug("fdadr1 0x%08x\n", (unsigned int) fbi->fdadr[1]);
Russell Kingca5da712005-09-29 09:44:54 +01001047 pr_debug("reg_lccr0 0x%08x\n", (unsigned int) fbi->reg_lccr0);
1048 pr_debug("reg_lccr1 0x%08x\n", (unsigned int) fbi->reg_lccr1);
1049 pr_debug("reg_lccr2 0x%08x\n", (unsigned int) fbi->reg_lccr2);
1050 pr_debug("reg_lccr3 0x%08x\n", (unsigned int) fbi->reg_lccr3);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001051
Nicolas Pitre8d372262005-08-10 16:45:13 +01001052 /* enable LCD controller clock */
Russell King72e35242007-08-20 10:18:42 +01001053 clk_enable(fbi->clk);
Nicolas Pitre8d372262005-08-10 16:45:13 +01001054
Eric Miao3c42a442008-04-30 00:52:26 -07001055 if (fbi->lccr0 & LCCR0_LCDT)
1056 return;
1057
Linus Torvalds1da177e2005-04-16 15:20:36 -07001058 /* Sequence from 11.7.10 */
Eric Miaoa7535ba2008-04-30 00:52:24 -07001059 lcd_writel(fbi, LCCR3, fbi->reg_lccr3);
1060 lcd_writel(fbi, LCCR2, fbi->reg_lccr2);
1061 lcd_writel(fbi, LCCR1, fbi->reg_lccr1);
1062 lcd_writel(fbi, LCCR0, fbi->reg_lccr0 & ~LCCR0_ENB);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001063
Eric Miaoa7535ba2008-04-30 00:52:24 -07001064 lcd_writel(fbi, FDADR0, fbi->fdadr[0]);
1065 lcd_writel(fbi, FDADR1, fbi->fdadr[1]);
1066 lcd_writel(fbi, LCCR0, fbi->reg_lccr0 | LCCR0_ENB);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001067}
1068
1069static void pxafb_disable_controller(struct pxafb_info *fbi)
1070{
eric miaoce4fb7b2008-04-30 00:52:21 -07001071 uint32_t lccr0;
1072
Eric Miao3c42a442008-04-30 00:52:26 -07001073#ifdef CONFIG_FB_PXA_SMARTPANEL
1074 if (fbi->lccr0 & LCCR0_LCDT) {
1075 wait_for_completion_timeout(&fbi->refresh_done,
1076 200 * HZ / 1000);
1077 return;
1078 }
1079#endif
1080
eric miaoce4fb7b2008-04-30 00:52:21 -07001081 /* Clear LCD Status Register */
Eric Miaoa7535ba2008-04-30 00:52:24 -07001082 lcd_writel(fbi, LCSR, 0xffffffff);
eric miaoce4fb7b2008-04-30 00:52:21 -07001083
Eric Miaoa7535ba2008-04-30 00:52:24 -07001084 lccr0 = lcd_readl(fbi, LCCR0) & ~LCCR0_LDM;
1085 lcd_writel(fbi, LCCR0, lccr0);
1086 lcd_writel(fbi, LCCR0, lccr0 | LCCR0_DIS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001087
Eric Miao2ba162b2008-04-30 00:52:24 -07001088 wait_for_completion_timeout(&fbi->disable_done, 200 * HZ / 1000);
Nicolas Pitre8d372262005-08-10 16:45:13 +01001089
1090 /* disable LCD controller clock */
Russell King72e35242007-08-20 10:18:42 +01001091 clk_disable(fbi->clk);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001092}
1093
1094/*
1095 * pxafb_handle_irq: Handle 'LCD DONE' interrupts.
1096 */
David Howells7d12e782006-10-05 14:55:46 +01001097static irqreturn_t pxafb_handle_irq(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001098{
1099 struct pxafb_info *fbi = dev_id;
Eric Miaoa7535ba2008-04-30 00:52:24 -07001100 unsigned int lccr0, lcsr = lcd_readl(fbi, LCSR);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001101
1102 if (lcsr & LCSR_LDD) {
Eric Miaoa7535ba2008-04-30 00:52:24 -07001103 lccr0 = lcd_readl(fbi, LCCR0);
1104 lcd_writel(fbi, LCCR0, lccr0 | LCCR0_LDM);
Eric Miao2ba162b2008-04-30 00:52:24 -07001105 complete(&fbi->disable_done);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001106 }
1107
Eric Miao3c42a442008-04-30 00:52:26 -07001108#ifdef CONFIG_FB_PXA_SMARTPANEL
1109 if (lcsr & LCSR_CMD_INT)
1110 complete(&fbi->command_done);
1111#endif
1112
Eric Miaoa7535ba2008-04-30 00:52:24 -07001113 lcd_writel(fbi, LCSR, lcsr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001114 return IRQ_HANDLED;
1115}
1116
1117/*
1118 * This function must be called from task context only, since it will
1119 * sleep when disabling the LCD controller, or if we get two contending
1120 * processes trying to alter state.
1121 */
1122static void set_ctrlr_state(struct pxafb_info *fbi, u_int state)
1123{
1124 u_int old_state;
1125
Matthias Kaehlckeb91dbce2008-07-23 21:31:14 -07001126 mutex_lock(&fbi->ctrlr_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001127
1128 old_state = fbi->state;
1129
1130 /*
1131 * Hack around fbcon initialisation.
1132 */
1133 if (old_state == C_STARTUP && state == C_REENABLE)
1134 state = C_ENABLE;
1135
1136 switch (state) {
1137 case C_DISABLE_CLKCHANGE:
1138 /*
1139 * Disable controller for clock change. If the
1140 * controller is already disabled, then do nothing.
1141 */
1142 if (old_state != C_DISABLE && old_state != C_DISABLE_PM) {
1143 fbi->state = state;
eric miaob0086ef2008-04-30 00:52:19 -07001144 /* TODO __pxafb_lcd_power(fbi, 0); */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001145 pxafb_disable_controller(fbi);
1146 }
1147 break;
1148
1149 case C_DISABLE_PM:
1150 case C_DISABLE:
1151 /*
1152 * Disable controller
1153 */
1154 if (old_state != C_DISABLE) {
1155 fbi->state = state;
1156 __pxafb_backlight_power(fbi, 0);
1157 __pxafb_lcd_power(fbi, 0);
1158 if (old_state != C_DISABLE_CLKCHANGE)
1159 pxafb_disable_controller(fbi);
1160 }
1161 break;
1162
1163 case C_ENABLE_CLKCHANGE:
1164 /*
1165 * Enable the controller after clock change. Only
1166 * do this if we were disabled for the clock change.
1167 */
1168 if (old_state == C_DISABLE_CLKCHANGE) {
1169 fbi->state = C_ENABLE;
1170 pxafb_enable_controller(fbi);
eric miaob0086ef2008-04-30 00:52:19 -07001171 /* TODO __pxafb_lcd_power(fbi, 1); */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001172 }
1173 break;
1174
1175 case C_REENABLE:
1176 /*
1177 * Re-enable the controller only if it was already
1178 * enabled. This is so we reprogram the control
1179 * registers.
1180 */
1181 if (old_state == C_ENABLE) {
Richard Purdied14b2722006-09-20 22:54:21 +01001182 __pxafb_lcd_power(fbi, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001183 pxafb_disable_controller(fbi);
1184 pxafb_setup_gpio(fbi);
1185 pxafb_enable_controller(fbi);
Richard Purdied14b2722006-09-20 22:54:21 +01001186 __pxafb_lcd_power(fbi, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001187 }
1188 break;
1189
1190 case C_ENABLE_PM:
1191 /*
1192 * Re-enable the controller after PM. This is not
1193 * perfect - think about the case where we were doing
1194 * a clock change, and we suspended half-way through.
1195 */
1196 if (old_state != C_DISABLE_PM)
1197 break;
1198 /* fall through */
1199
1200 case C_ENABLE:
1201 /*
1202 * Power up the LCD screen, enable controller, and
1203 * turn on the backlight.
1204 */
1205 if (old_state != C_ENABLE) {
1206 fbi->state = C_ENABLE;
1207 pxafb_setup_gpio(fbi);
1208 pxafb_enable_controller(fbi);
1209 __pxafb_lcd_power(fbi, 1);
1210 __pxafb_backlight_power(fbi, 1);
1211 }
1212 break;
1213 }
Matthias Kaehlckeb91dbce2008-07-23 21:31:14 -07001214 mutex_unlock(&fbi->ctrlr_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001215}
1216
1217/*
1218 * Our LCD controller task (which is called when we blank or unblank)
1219 * via keventd.
1220 */
David Howells6d5aefb2006-12-05 19:36:26 +00001221static void pxafb_task(struct work_struct *work)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001222{
David Howells6d5aefb2006-12-05 19:36:26 +00001223 struct pxafb_info *fbi =
1224 container_of(work, struct pxafb_info, task);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001225 u_int state = xchg(&fbi->task_state, -1);
1226
1227 set_ctrlr_state(fbi, state);
1228}
1229
1230#ifdef CONFIG_CPU_FREQ
1231/*
1232 * CPU clock speed change handler. We need to adjust the LCD timing
1233 * parameters when the CPU clock is adjusted by the power management
1234 * subsystem.
1235 *
1236 * TODO: Determine why f->new != 10*get_lclk_frequency_10khz()
1237 */
1238static int
1239pxafb_freq_transition(struct notifier_block *nb, unsigned long val, void *data)
1240{
1241 struct pxafb_info *fbi = TO_INF(nb, freq_transition);
eric miaob0086ef2008-04-30 00:52:19 -07001242 /* TODO struct cpufreq_freqs *f = data; */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001243 u_int pcd;
1244
1245 switch (val) {
1246 case CPUFREQ_PRECHANGE:
1247 set_ctrlr_state(fbi, C_DISABLE_CLKCHANGE);
1248 break;
1249
1250 case CPUFREQ_POSTCHANGE:
Russell King72e35242007-08-20 10:18:42 +01001251 pcd = get_pcd(fbi, fbi->fb.var.pixclock);
Richard Purdieba44cd22005-09-09 13:10:03 -07001252 set_hsync_time(fbi, pcd);
eric miaob0086ef2008-04-30 00:52:19 -07001253 fbi->reg_lccr3 = (fbi->reg_lccr3 & ~0xff) |
1254 LCCR3_PixClkDiv(pcd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001255 set_ctrlr_state(fbi, C_ENABLE_CLKCHANGE);
1256 break;
1257 }
1258 return 0;
1259}
1260
1261static int
1262pxafb_freq_policy(struct notifier_block *nb, unsigned long val, void *data)
1263{
1264 struct pxafb_info *fbi = TO_INF(nb, freq_policy);
1265 struct fb_var_screeninfo *var = &fbi->fb.var;
1266 struct cpufreq_policy *policy = data;
1267
1268 switch (val) {
1269 case CPUFREQ_ADJUST:
1270 case CPUFREQ_INCOMPATIBLE:
Holger Schurigac2bf5b2008-02-11 16:52:30 +01001271 pr_debug("min dma period: %d ps, "
Linus Torvalds1da177e2005-04-16 15:20:36 -07001272 "new clock %d kHz\n", pxafb_display_dma_period(var),
1273 policy->max);
eric miaob0086ef2008-04-30 00:52:19 -07001274 /* TODO: fill in min/max values */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001275 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001276 }
1277 return 0;
1278}
1279#endif
1280
1281#ifdef CONFIG_PM
1282/*
1283 * Power management hooks. Note that we won't be called from IRQ context,
1284 * unlike the blank functions above, so we may sleep.
1285 */
Russell King3ae5eae2005-11-09 22:32:44 +00001286static int pxafb_suspend(struct platform_device *dev, pm_message_t state)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001287{
Russell King3ae5eae2005-11-09 22:32:44 +00001288 struct pxafb_info *fbi = platform_get_drvdata(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001289
Russell King9480e302005-10-28 09:52:56 -07001290 set_ctrlr_state(fbi, C_DISABLE_PM);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001291 return 0;
1292}
1293
Russell King3ae5eae2005-11-09 22:32:44 +00001294static int pxafb_resume(struct platform_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001295{
Russell King3ae5eae2005-11-09 22:32:44 +00001296 struct pxafb_info *fbi = platform_get_drvdata(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001297
Russell King9480e302005-10-28 09:52:56 -07001298 set_ctrlr_state(fbi, C_ENABLE_PM);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001299 return 0;
1300}
1301#else
1302#define pxafb_suspend NULL
1303#define pxafb_resume NULL
1304#endif
1305
1306/*
1307 * pxafb_map_video_memory():
1308 * Allocates the DRAM memory for the frame buffer. This buffer is
1309 * remapped into a non-cached, non-buffered, memory region to
1310 * allow palette and pixel writes to occur without flushing the
1311 * cache. Once this area is remapped, all virtual memory
1312 * access to the video memory should occur at the new region.
1313 */
Jaya Kumar9e6c2972008-06-22 04:27:27 +01001314static int __devinit pxafb_map_video_memory(struct pxafb_info *fbi)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001315{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001316 /*
1317 * We reserve one page for the palette, plus the size
1318 * of the framebuffer.
1319 */
Eric Miao3c42a442008-04-30 00:52:26 -07001320 fbi->video_offset = PAGE_ALIGN(sizeof(struct pxafb_dma_buff));
1321 fbi->map_size = PAGE_ALIGN(fbi->fb.fix.smem_len + fbi->video_offset);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001322 fbi->map_cpu = dma_alloc_writecombine(fbi->dev, fbi->map_size,
1323 &fbi->map_dma, GFP_KERNEL);
1324
1325 if (fbi->map_cpu) {
1326 /* prevent initial garbage on screen */
1327 memset(fbi->map_cpu, 0, fbi->map_size);
Eric Miao3c42a442008-04-30 00:52:26 -07001328 fbi->fb.screen_base = fbi->map_cpu + fbi->video_offset;
1329 fbi->screen_dma = fbi->map_dma + fbi->video_offset;
1330
Linus Torvalds1da177e2005-04-16 15:20:36 -07001331 /*
1332 * FIXME: this is actually the wrong thing to place in
1333 * smem_start. But fbdev suffers from the problem that
1334 * it needs an API which doesn't exist (in this case,
1335 * dma_writecombine_mmap)
1336 */
1337 fbi->fb.fix.smem_start = fbi->screen_dma;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001338 fbi->palette_size = fbi->fb.var.bits_per_pixel == 8 ? 256 : 16;
1339
Eric Miao3c42a442008-04-30 00:52:26 -07001340 fbi->dma_buff = (void *) fbi->map_cpu;
eric miao2c42dd82008-04-30 00:52:21 -07001341 fbi->dma_buff_phys = fbi->map_dma;
Eric Miao3c42a442008-04-30 00:52:26 -07001342 fbi->palette_cpu = (u16 *) fbi->dma_buff->palette;
1343
Ian Moltone84e9542008-07-21 11:02:40 +01001344 pr_debug("pxafb: palette_mem_size = 0x%08x\n", fbi->palette_size*sizeof(u16));
Jürgen Schindele62cfcf42008-06-11 19:56:06 +01001345
Eric Miao3c42a442008-04-30 00:52:26 -07001346#ifdef CONFIG_FB_PXA_SMARTPANEL
1347 fbi->smart_cmds = (uint16_t *) fbi->dma_buff->cmd_buff;
1348 fbi->n_smart_cmds = 0;
1349#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001350 }
1351
1352 return fbi->map_cpu ? 0 : -ENOMEM;
1353}
1354
eric miao84f43c32008-04-30 00:52:22 -07001355static void pxafb_decode_mode_info(struct pxafb_info *fbi,
1356 struct pxafb_mode_info *modes,
1357 unsigned int num_modes)
1358{
1359 unsigned int i, smemlen;
1360
1361 pxafb_setmode(&fbi->fb.var, &modes[0]);
1362
1363 for (i = 0; i < num_modes; i++) {
1364 smemlen = modes[i].xres * modes[i].yres * modes[i].bpp / 8;
1365 if (smemlen > fbi->fb.fix.smem_len)
1366 fbi->fb.fix.smem_len = smemlen;
1367 }
1368}
1369
Guennadi Liakhovetskiebdf9822008-05-05 15:31:44 +01001370static void pxafb_decode_mach_info(struct pxafb_info *fbi,
1371 struct pxafb_mach_info *inf)
eric miao84f43c32008-04-30 00:52:22 -07001372{
1373 unsigned int lcd_conn = inf->lcd_conn;
1374
1375 fbi->cmap_inverse = inf->cmap_inverse;
1376 fbi->cmap_static = inf->cmap_static;
1377
Eric Miao1ec26db2008-11-11 21:45:57 +08001378 switch (lcd_conn & LCD_TYPE_MASK) {
eric miao84f43c32008-04-30 00:52:22 -07001379 case LCD_TYPE_MONO_STN:
1380 fbi->lccr0 = LCCR0_CMS;
1381 break;
1382 case LCD_TYPE_MONO_DSTN:
1383 fbi->lccr0 = LCCR0_CMS | LCCR0_SDS;
1384 break;
1385 case LCD_TYPE_COLOR_STN:
1386 fbi->lccr0 = 0;
1387 break;
1388 case LCD_TYPE_COLOR_DSTN:
1389 fbi->lccr0 = LCCR0_SDS;
1390 break;
1391 case LCD_TYPE_COLOR_TFT:
1392 fbi->lccr0 = LCCR0_PAS;
1393 break;
1394 case LCD_TYPE_SMART_PANEL:
1395 fbi->lccr0 = LCCR0_LCDT | LCCR0_PAS;
1396 break;
1397 default:
1398 /* fall back to backward compatibility way */
1399 fbi->lccr0 = inf->lccr0;
1400 fbi->lccr3 = inf->lccr3;
1401 fbi->lccr4 = inf->lccr4;
Guennadi Liakhovetskiebdf9822008-05-05 15:31:44 +01001402 goto decode_mode;
eric miao84f43c32008-04-30 00:52:22 -07001403 }
1404
1405 if (lcd_conn == LCD_MONO_STN_8BPP)
1406 fbi->lccr0 |= LCCR0_DPD;
1407
Eric Miao9a1ac7e2008-08-15 02:50:44 -04001408 fbi->lccr0 |= (lcd_conn & LCD_ALTERNATE_MAPPING) ? LCCR0_LDDALT : 0;
1409
eric miao84f43c32008-04-30 00:52:22 -07001410 fbi->lccr3 = LCCR3_Acb((inf->lcd_conn >> 10) & 0xff);
1411 fbi->lccr3 |= (lcd_conn & LCD_BIAS_ACTIVE_LOW) ? LCCR3_OEP : 0;
1412 fbi->lccr3 |= (lcd_conn & LCD_PCLK_EDGE_FALL) ? LCCR3_PCP : 0;
1413
Guennadi Liakhovetskiebdf9822008-05-05 15:31:44 +01001414decode_mode:
eric miao84f43c32008-04-30 00:52:22 -07001415 pxafb_decode_mode_info(fbi, inf->modes, inf->num_modes);
eric miao84f43c32008-04-30 00:52:22 -07001416}
1417
Jaya Kumar9e6c2972008-06-22 04:27:27 +01001418static struct pxafb_info * __devinit pxafb_init_fbinfo(struct device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001419{
1420 struct pxafb_info *fbi;
1421 void *addr;
1422 struct pxafb_mach_info *inf = dev->platform_data;
1423
1424 /* Alloc the pxafb_info and pseudo_palette in one step */
1425 fbi = kmalloc(sizeof(struct pxafb_info) + sizeof(u32) * 16, GFP_KERNEL);
1426 if (!fbi)
1427 return NULL;
1428
1429 memset(fbi, 0, sizeof(struct pxafb_info));
1430 fbi->dev = dev;
1431
Russell King72e35242007-08-20 10:18:42 +01001432 fbi->clk = clk_get(dev, "LCDCLK");
1433 if (IS_ERR(fbi->clk)) {
1434 kfree(fbi);
1435 return NULL;
1436 }
1437
Linus Torvalds1da177e2005-04-16 15:20:36 -07001438 strcpy(fbi->fb.fix.id, PXA_NAME);
1439
1440 fbi->fb.fix.type = FB_TYPE_PACKED_PIXELS;
1441 fbi->fb.fix.type_aux = 0;
1442 fbi->fb.fix.xpanstep = 0;
1443 fbi->fb.fix.ypanstep = 0;
1444 fbi->fb.fix.ywrapstep = 0;
1445 fbi->fb.fix.accel = FB_ACCEL_NONE;
1446
1447 fbi->fb.var.nonstd = 0;
1448 fbi->fb.var.activate = FB_ACTIVATE_NOW;
1449 fbi->fb.var.height = -1;
1450 fbi->fb.var.width = -1;
1451 fbi->fb.var.accel_flags = 0;
1452 fbi->fb.var.vmode = FB_VMODE_NONINTERLACED;
1453
1454 fbi->fb.fbops = &pxafb_ops;
1455 fbi->fb.flags = FBINFO_DEFAULT;
1456 fbi->fb.node = -1;
1457
1458 addr = fbi;
1459 addr = addr + sizeof(struct pxafb_info);
1460 fbi->fb.pseudo_palette = addr;
1461
eric miaob0086ef2008-04-30 00:52:19 -07001462 fbi->state = C_STARTUP;
1463 fbi->task_state = (u_char)-1;
Richard Purdied14b2722006-09-20 22:54:21 +01001464
eric miao84f43c32008-04-30 00:52:22 -07001465 pxafb_decode_mach_info(fbi, inf);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001466
1467 init_waitqueue_head(&fbi->ctrlr_wait);
David Howells6d5aefb2006-12-05 19:36:26 +00001468 INIT_WORK(&fbi->task, pxafb_task);
Matthias Kaehlckeb91dbce2008-07-23 21:31:14 -07001469 mutex_init(&fbi->ctrlr_lock);
Eric Miao2ba162b2008-04-30 00:52:24 -07001470 init_completion(&fbi->disable_done);
Eric Miao3c42a442008-04-30 00:52:26 -07001471#ifdef CONFIG_FB_PXA_SMARTPANEL
1472 init_completion(&fbi->command_done);
1473 init_completion(&fbi->refresh_done);
1474#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001475
1476 return fbi;
1477}
1478
1479#ifdef CONFIG_FB_PXA_PARAMETERS
Jaya Kumar9e6c2972008-06-22 04:27:27 +01001480static int __devinit parse_opt_mode(struct device *dev, const char *this_opt)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001481{
1482 struct pxafb_mach_info *inf = dev->platform_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001483
eric miao817daf12008-04-30 00:52:18 -07001484 const char *name = this_opt+5;
1485 unsigned int namelen = strlen(name);
1486 int res_specified = 0, bpp_specified = 0;
1487 unsigned int xres = 0, yres = 0, bpp = 0;
1488 int yres_specified = 0;
1489 int i;
1490 for (i = namelen-1; i >= 0; i--) {
1491 switch (name[i]) {
1492 case '-':
1493 namelen = i;
1494 if (!bpp_specified && !yres_specified) {
1495 bpp = simple_strtoul(&name[i+1], NULL, 0);
1496 bpp_specified = 1;
1497 } else
1498 goto done;
1499 break;
1500 case 'x':
1501 if (!yres_specified) {
1502 yres = simple_strtoul(&name[i+1], NULL, 0);
1503 yres_specified = 1;
1504 } else
1505 goto done;
1506 break;
1507 case '0' ... '9':
1508 break;
1509 default:
1510 goto done;
1511 }
1512 }
1513 if (i < 0 && yres_specified) {
1514 xres = simple_strtoul(name, NULL, 0);
1515 res_specified = 1;
1516 }
1517done:
1518 if (res_specified) {
1519 dev_info(dev, "overriding resolution: %dx%d\n", xres, yres);
1520 inf->modes[0].xres = xres; inf->modes[0].yres = yres;
1521 }
1522 if (bpp_specified)
1523 switch (bpp) {
1524 case 1:
1525 case 2:
1526 case 4:
1527 case 8:
1528 case 16:
1529 inf->modes[0].bpp = bpp;
1530 dev_info(dev, "overriding bit depth: %d\n", bpp);
1531 break;
1532 default:
1533 dev_err(dev, "Depth %d is not valid\n", bpp);
1534 return -EINVAL;
1535 }
1536 return 0;
1537}
1538
Jaya Kumar9e6c2972008-06-22 04:27:27 +01001539static int __devinit parse_opt(struct device *dev, char *this_opt)
eric miao817daf12008-04-30 00:52:18 -07001540{
1541 struct pxafb_mach_info *inf = dev->platform_data;
1542 struct pxafb_mode_info *mode = &inf->modes[0];
1543 char s[64];
1544
1545 s[0] = '\0';
1546
1547 if (!strncmp(this_opt, "mode:", 5)) {
1548 return parse_opt_mode(dev, this_opt);
1549 } else if (!strncmp(this_opt, "pixclock:", 9)) {
1550 mode->pixclock = simple_strtoul(this_opt+9, NULL, 0);
1551 sprintf(s, "pixclock: %ld\n", mode->pixclock);
1552 } else if (!strncmp(this_opt, "left:", 5)) {
1553 mode->left_margin = simple_strtoul(this_opt+5, NULL, 0);
1554 sprintf(s, "left: %u\n", mode->left_margin);
1555 } else if (!strncmp(this_opt, "right:", 6)) {
1556 mode->right_margin = simple_strtoul(this_opt+6, NULL, 0);
1557 sprintf(s, "right: %u\n", mode->right_margin);
1558 } else if (!strncmp(this_opt, "upper:", 6)) {
1559 mode->upper_margin = simple_strtoul(this_opt+6, NULL, 0);
1560 sprintf(s, "upper: %u\n", mode->upper_margin);
1561 } else if (!strncmp(this_opt, "lower:", 6)) {
1562 mode->lower_margin = simple_strtoul(this_opt+6, NULL, 0);
1563 sprintf(s, "lower: %u\n", mode->lower_margin);
1564 } else if (!strncmp(this_opt, "hsynclen:", 9)) {
1565 mode->hsync_len = simple_strtoul(this_opt+9, NULL, 0);
1566 sprintf(s, "hsynclen: %u\n", mode->hsync_len);
1567 } else if (!strncmp(this_opt, "vsynclen:", 9)) {
1568 mode->vsync_len = simple_strtoul(this_opt+9, NULL, 0);
1569 sprintf(s, "vsynclen: %u\n", mode->vsync_len);
1570 } else if (!strncmp(this_opt, "hsync:", 6)) {
1571 if (simple_strtoul(this_opt+6, NULL, 0) == 0) {
1572 sprintf(s, "hsync: Active Low\n");
1573 mode->sync &= ~FB_SYNC_HOR_HIGH_ACT;
1574 } else {
1575 sprintf(s, "hsync: Active High\n");
1576 mode->sync |= FB_SYNC_HOR_HIGH_ACT;
1577 }
1578 } else if (!strncmp(this_opt, "vsync:", 6)) {
1579 if (simple_strtoul(this_opt+6, NULL, 0) == 0) {
1580 sprintf(s, "vsync: Active Low\n");
1581 mode->sync &= ~FB_SYNC_VERT_HIGH_ACT;
1582 } else {
1583 sprintf(s, "vsync: Active High\n");
1584 mode->sync |= FB_SYNC_VERT_HIGH_ACT;
1585 }
1586 } else if (!strncmp(this_opt, "dpc:", 4)) {
1587 if (simple_strtoul(this_opt+4, NULL, 0) == 0) {
1588 sprintf(s, "double pixel clock: false\n");
1589 inf->lccr3 &= ~LCCR3_DPC;
1590 } else {
1591 sprintf(s, "double pixel clock: true\n");
1592 inf->lccr3 |= LCCR3_DPC;
1593 }
1594 } else if (!strncmp(this_opt, "outputen:", 9)) {
1595 if (simple_strtoul(this_opt+9, NULL, 0) == 0) {
1596 sprintf(s, "output enable: active low\n");
1597 inf->lccr3 = (inf->lccr3 & ~LCCR3_OEP) | LCCR3_OutEnL;
1598 } else {
1599 sprintf(s, "output enable: active high\n");
1600 inf->lccr3 = (inf->lccr3 & ~LCCR3_OEP) | LCCR3_OutEnH;
1601 }
1602 } else if (!strncmp(this_opt, "pixclockpol:", 12)) {
1603 if (simple_strtoul(this_opt+12, NULL, 0) == 0) {
1604 sprintf(s, "pixel clock polarity: falling edge\n");
1605 inf->lccr3 = (inf->lccr3 & ~LCCR3_PCP) | LCCR3_PixFlEdg;
1606 } else {
1607 sprintf(s, "pixel clock polarity: rising edge\n");
1608 inf->lccr3 = (inf->lccr3 & ~LCCR3_PCP) | LCCR3_PixRsEdg;
1609 }
1610 } else if (!strncmp(this_opt, "color", 5)) {
1611 inf->lccr0 = (inf->lccr0 & ~LCCR0_CMS) | LCCR0_Color;
1612 } else if (!strncmp(this_opt, "mono", 4)) {
1613 inf->lccr0 = (inf->lccr0 & ~LCCR0_CMS) | LCCR0_Mono;
1614 } else if (!strncmp(this_opt, "active", 6)) {
1615 inf->lccr0 = (inf->lccr0 & ~LCCR0_PAS) | LCCR0_Act;
1616 } else if (!strncmp(this_opt, "passive", 7)) {
1617 inf->lccr0 = (inf->lccr0 & ~LCCR0_PAS) | LCCR0_Pas;
1618 } else if (!strncmp(this_opt, "single", 6)) {
1619 inf->lccr0 = (inf->lccr0 & ~LCCR0_SDS) | LCCR0_Sngl;
1620 } else if (!strncmp(this_opt, "dual", 4)) {
1621 inf->lccr0 = (inf->lccr0 & ~LCCR0_SDS) | LCCR0_Dual;
1622 } else if (!strncmp(this_opt, "4pix", 4)) {
1623 inf->lccr0 = (inf->lccr0 & ~LCCR0_DPD) | LCCR0_4PixMono;
1624 } else if (!strncmp(this_opt, "8pix", 4)) {
1625 inf->lccr0 = (inf->lccr0 & ~LCCR0_DPD) | LCCR0_8PixMono;
1626 } else {
1627 dev_err(dev, "unknown option: %s\n", this_opt);
1628 return -EINVAL;
1629 }
1630
1631 if (s[0] != '\0')
1632 dev_info(dev, "override %s", s);
1633
1634 return 0;
1635}
1636
Jaya Kumar9e6c2972008-06-22 04:27:27 +01001637static int __devinit pxafb_parse_options(struct device *dev, char *options)
eric miao817daf12008-04-30 00:52:18 -07001638{
1639 char *this_opt;
1640 int ret;
1641
1642 if (!options || !*options)
1643 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001644
1645 dev_dbg(dev, "options are \"%s\"\n", options ? options : "null");
1646
1647 /* could be made table driven or similar?... */
eric miao817daf12008-04-30 00:52:18 -07001648 while ((this_opt = strsep(&options, ",")) != NULL) {
1649 ret = parse_opt(dev, this_opt);
1650 if (ret)
1651 return ret;
1652 }
1653 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001654}
eric miao92ac73c2008-04-30 00:52:20 -07001655
1656static char g_options[256] __devinitdata = "";
1657
Jaya Kumarf1edfc42008-06-22 04:27:25 +01001658#ifndef MODULE
Jaya Kumar9e6c2972008-06-22 04:27:27 +01001659static int __init pxafb_setup_options(void)
eric miao92ac73c2008-04-30 00:52:20 -07001660{
1661 char *options = NULL;
1662
1663 if (fb_get_options("pxafb", &options))
1664 return -ENODEV;
1665
1666 if (options)
1667 strlcpy(g_options, options, sizeof(g_options));
1668
1669 return 0;
1670}
1671#else
1672#define pxafb_setup_options() (0)
1673
1674module_param_string(options, g_options, sizeof(g_options), 0);
1675MODULE_PARM_DESC(options, "LCD parameters (see Documentation/fb/pxafb.txt)");
1676#endif
1677
1678#else
1679#define pxafb_parse_options(...) (0)
1680#define pxafb_setup_options() (0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001681#endif
1682
Eric Miao4f3e2662008-08-16 03:50:51 -04001683#ifdef DEBUG_VAR
1684/* Check for various illegal bit-combinations. Currently only
1685 * a warning is given. */
1686static void __devinit pxafb_check_options(struct device *dev,
1687 struct pxafb_mach_info *inf)
1688{
1689 if (inf->lcd_conn)
1690 return;
1691
1692 if (inf->lccr0 & LCCR0_INVALID_CONFIG_MASK)
1693 dev_warn(dev, "machine LCCR0 setting contains "
1694 "illegal bits: %08x\n",
1695 inf->lccr0 & LCCR0_INVALID_CONFIG_MASK);
1696 if (inf->lccr3 & LCCR3_INVALID_CONFIG_MASK)
1697 dev_warn(dev, "machine LCCR3 setting contains "
1698 "illegal bits: %08x\n",
1699 inf->lccr3 & LCCR3_INVALID_CONFIG_MASK);
1700 if (inf->lccr0 & LCCR0_DPD &&
1701 ((inf->lccr0 & LCCR0_PAS) != LCCR0_Pas ||
1702 (inf->lccr0 & LCCR0_SDS) != LCCR0_Sngl ||
1703 (inf->lccr0 & LCCR0_CMS) != LCCR0_Mono))
1704 dev_warn(dev, "Double Pixel Data (DPD) mode is "
1705 "only valid in passive mono"
1706 " single panel mode\n");
1707 if ((inf->lccr0 & LCCR0_PAS) == LCCR0_Act &&
1708 (inf->lccr0 & LCCR0_SDS) == LCCR0_Dual)
1709 dev_warn(dev, "Dual panel only valid in passive mode\n");
1710 if ((inf->lccr0 & LCCR0_PAS) == LCCR0_Pas &&
1711 (inf->modes->upper_margin || inf->modes->lower_margin))
1712 dev_warn(dev, "Upper and lower margins must be 0 in "
1713 "passive mode\n");
1714}
1715#else
1716#define pxafb_check_options(...) do {} while (0)
1717#endif
1718
Jaya Kumar9e6c2972008-06-22 04:27:27 +01001719static int __devinit pxafb_probe(struct platform_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001720{
1721 struct pxafb_info *fbi;
1722 struct pxafb_mach_info *inf;
eric miaoce4fb7b2008-04-30 00:52:21 -07001723 struct resource *r;
1724 int irq, ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001725
Richard Purdie2cbbb3b2006-03-31 02:31:53 -08001726 dev_dbg(&dev->dev, "pxafb_probe\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001727
Russell King3ae5eae2005-11-09 22:32:44 +00001728 inf = dev->dev.platform_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001729 ret = -ENOMEM;
1730 fbi = NULL;
1731 if (!inf)
1732 goto failed;
1733
Russell King3ae5eae2005-11-09 22:32:44 +00001734 ret = pxafb_parse_options(&dev->dev, g_options);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001735 if (ret < 0)
1736 goto failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001737
Eric Miao4f3e2662008-08-16 03:50:51 -04001738 pxafb_check_options(&dev->dev, inf);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001739
eric miaob0086ef2008-04-30 00:52:19 -07001740 dev_dbg(&dev->dev, "got a %dx%dx%d LCD\n",
1741 inf->modes->xres,
1742 inf->modes->yres,
1743 inf->modes->bpp);
1744 if (inf->modes->xres == 0 ||
1745 inf->modes->yres == 0 ||
1746 inf->modes->bpp == 0) {
Russell King3ae5eae2005-11-09 22:32:44 +00001747 dev_err(&dev->dev, "Invalid resolution or bit depth\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001748 ret = -EINVAL;
1749 goto failed;
1750 }
1751 pxafb_backlight_power = inf->pxafb_backlight_power;
1752 pxafb_lcd_power = inf->pxafb_lcd_power;
Russell King3ae5eae2005-11-09 22:32:44 +00001753 fbi = pxafb_init_fbinfo(&dev->dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001754 if (!fbi) {
eric miaob0086ef2008-04-30 00:52:19 -07001755 /* only reason for pxafb_init_fbinfo to fail is kmalloc */
Russell King3ae5eae2005-11-09 22:32:44 +00001756 dev_err(&dev->dev, "Failed to initialize framebuffer device\n");
eric miaob0086ef2008-04-30 00:52:19 -07001757 ret = -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001758 goto failed;
1759 }
1760
eric miaoce4fb7b2008-04-30 00:52:21 -07001761 r = platform_get_resource(dev, IORESOURCE_MEM, 0);
1762 if (r == NULL) {
1763 dev_err(&dev->dev, "no I/O memory resource defined\n");
1764 ret = -ENODEV;
Jaya Kumaree984762008-06-22 04:27:26 +01001765 goto failed_fbi;
eric miaoce4fb7b2008-04-30 00:52:21 -07001766 }
1767
1768 r = request_mem_region(r->start, r->end - r->start + 1, dev->name);
1769 if (r == NULL) {
1770 dev_err(&dev->dev, "failed to request I/O memory\n");
1771 ret = -EBUSY;
Jaya Kumaree984762008-06-22 04:27:26 +01001772 goto failed_fbi;
eric miaoce4fb7b2008-04-30 00:52:21 -07001773 }
1774
1775 fbi->mmio_base = ioremap(r->start, r->end - r->start + 1);
1776 if (fbi->mmio_base == NULL) {
1777 dev_err(&dev->dev, "failed to map I/O memory\n");
1778 ret = -EBUSY;
1779 goto failed_free_res;
1780 }
1781
Linus Torvalds1da177e2005-04-16 15:20:36 -07001782 /* Initialize video memory */
1783 ret = pxafb_map_video_memory(fbi);
1784 if (ret) {
Russell King3ae5eae2005-11-09 22:32:44 +00001785 dev_err(&dev->dev, "Failed to allocate video RAM: %d\n", ret);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001786 ret = -ENOMEM;
eric miaoce4fb7b2008-04-30 00:52:21 -07001787 goto failed_free_io;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001788 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001789
eric miaoce4fb7b2008-04-30 00:52:21 -07001790 irq = platform_get_irq(dev, 0);
1791 if (irq < 0) {
1792 dev_err(&dev->dev, "no IRQ defined\n");
1793 ret = -ENODEV;
1794 goto failed_free_mem;
1795 }
1796
1797 ret = request_irq(irq, pxafb_handle_irq, IRQF_DISABLED, "LCD", fbi);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001798 if (ret) {
Russell King3ae5eae2005-11-09 22:32:44 +00001799 dev_err(&dev->dev, "request_irq failed: %d\n", ret);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001800 ret = -EBUSY;
eric miaoce4fb7b2008-04-30 00:52:21 -07001801 goto failed_free_mem;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001802 }
1803
Eric Miao3c42a442008-04-30 00:52:26 -07001804#ifdef CONFIG_FB_PXA_SMARTPANEL
1805 ret = pxafb_smart_init(fbi);
1806 if (ret) {
1807 dev_err(&dev->dev, "failed to initialize smartpanel\n");
1808 goto failed_free_irq;
1809 }
1810#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001811 /*
1812 * This makes sure that our colour bitfield
1813 * descriptors are correctly initialised.
1814 */
Jaya Kumaree984762008-06-22 04:27:26 +01001815 ret = pxafb_check_var(&fbi->fb.var, &fbi->fb);
1816 if (ret) {
1817 dev_err(&dev->dev, "failed to get suitable mode\n");
1818 goto failed_free_irq;
1819 }
1820
1821 ret = pxafb_set_par(&fbi->fb);
1822 if (ret) {
1823 dev_err(&dev->dev, "Failed to set parameters\n");
1824 goto failed_free_irq;
1825 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001826
Russell King3ae5eae2005-11-09 22:32:44 +00001827 platform_set_drvdata(dev, fbi);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001828
1829 ret = register_framebuffer(&fbi->fb);
1830 if (ret < 0) {
eric miaob0086ef2008-04-30 00:52:19 -07001831 dev_err(&dev->dev,
1832 "Failed to register framebuffer device: %d\n", ret);
Jaya Kumaree984762008-06-22 04:27:26 +01001833 goto failed_free_cmap;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001834 }
1835
Linus Torvalds1da177e2005-04-16 15:20:36 -07001836#ifdef CONFIG_CPU_FREQ
1837 fbi->freq_transition.notifier_call = pxafb_freq_transition;
1838 fbi->freq_policy.notifier_call = pxafb_freq_policy;
eric miaob0086ef2008-04-30 00:52:19 -07001839 cpufreq_register_notifier(&fbi->freq_transition,
1840 CPUFREQ_TRANSITION_NOTIFIER);
1841 cpufreq_register_notifier(&fbi->freq_policy,
1842 CPUFREQ_POLICY_NOTIFIER);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001843#endif
1844
1845 /*
1846 * Ok, now enable the LCD controller
1847 */
1848 set_ctrlr_state(fbi, C_ENABLE);
1849
1850 return 0;
1851
Jaya Kumaree984762008-06-22 04:27:26 +01001852failed_free_cmap:
1853 if (fbi->fb.cmap.len)
1854 fb_dealloc_cmap(&fbi->fb.cmap);
eric miaoce4fb7b2008-04-30 00:52:21 -07001855failed_free_irq:
1856 free_irq(irq, fbi);
eric miaoce4fb7b2008-04-30 00:52:21 -07001857failed_free_mem:
1858 dma_free_writecombine(&dev->dev, fbi->map_size,
1859 fbi->map_cpu, fbi->map_dma);
Jaya Kumaree984762008-06-22 04:27:26 +01001860failed_free_io:
1861 iounmap(fbi->mmio_base);
1862failed_free_res:
1863 release_mem_region(r->start, r->end - r->start + 1);
1864failed_fbi:
1865 clk_put(fbi->clk);
Russell King3ae5eae2005-11-09 22:32:44 +00001866 platform_set_drvdata(dev, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001867 kfree(fbi);
Jaya Kumaree984762008-06-22 04:27:26 +01001868failed:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001869 return ret;
1870}
1871
Jaya Kumar9f17f282008-06-22 04:27:28 +01001872static int __devexit pxafb_remove(struct platform_device *dev)
1873{
1874 struct pxafb_info *fbi = platform_get_drvdata(dev);
1875 struct resource *r;
1876 int irq;
1877 struct fb_info *info;
1878
1879 if (!fbi)
1880 return 0;
1881
1882 info = &fbi->fb;
1883
1884 unregister_framebuffer(info);
1885
1886 pxafb_disable_controller(fbi);
1887
1888 if (fbi->fb.cmap.len)
1889 fb_dealloc_cmap(&fbi->fb.cmap);
1890
1891 irq = platform_get_irq(dev, 0);
1892 free_irq(irq, fbi);
1893
1894 dma_free_writecombine(&dev->dev, fbi->map_size,
1895 fbi->map_cpu, fbi->map_dma);
1896
1897 iounmap(fbi->mmio_base);
1898
1899 r = platform_get_resource(dev, IORESOURCE_MEM, 0);
1900 release_mem_region(r->start, r->end - r->start + 1);
1901
1902 clk_put(fbi->clk);
1903 kfree(fbi);
1904
1905 return 0;
1906}
1907
Russell King3ae5eae2005-11-09 22:32:44 +00001908static struct platform_driver pxafb_driver = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001909 .probe = pxafb_probe,
Jaya Kumar9f17f282008-06-22 04:27:28 +01001910 .remove = pxafb_remove,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001911 .suspend = pxafb_suspend,
1912 .resume = pxafb_resume,
Russell King3ae5eae2005-11-09 22:32:44 +00001913 .driver = {
Jaya Kumar9f17f282008-06-22 04:27:28 +01001914 .owner = THIS_MODULE,
Russell King3ae5eae2005-11-09 22:32:44 +00001915 .name = "pxa2xx-fb",
1916 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001917};
1918
Jaya Kumar9e6c2972008-06-22 04:27:27 +01001919static int __init pxafb_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001920{
eric miao92ac73c2008-04-30 00:52:20 -07001921 if (pxafb_setup_options())
1922 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001923
Russell King3ae5eae2005-11-09 22:32:44 +00001924 return platform_driver_register(&pxafb_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001925}
1926
Jaya Kumar9f17f282008-06-22 04:27:28 +01001927static void __exit pxafb_exit(void)
1928{
1929 platform_driver_unregister(&pxafb_driver);
1930}
1931
Linus Torvalds1da177e2005-04-16 15:20:36 -07001932module_init(pxafb_init);
Jaya Kumar9f17f282008-06-22 04:27:28 +01001933module_exit(pxafb_exit);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001934
1935MODULE_DESCRIPTION("loadable framebuffer driver for PXA");
1936MODULE_LICENSE("GPL");