[PATCH] IB/ipath: print better debug info when handling 32/64-bit DMA mask problems
[linux-2.6] / drivers / video / au1100fb.c
1 /*
2  * BRIEF MODULE DESCRIPTION
3  *      Au1100 LCD Driver.
4  *
5  * Rewritten for 2.6 by Embedded Alley Solutions
6  *      <source@embeddedalley.com>, based on submissions by
7  *      Karl Lessard <klessard@sunrisetelecom.com>
8  *      <c.pellegrin@exadron.com>
9  *
10  * PM support added by Rodolfo Giometti <giometti@linux.it>
11  *
12  * Copyright 2002 MontaVista Software
13  * Author: MontaVista Software, Inc.
14  *              ppopov@mvista.com or source@mvista.com
15  *
16  * Copyright 2002 Alchemy Semiconductor
17  * Author: Alchemy Semiconductor
18  *
19  * Based on:
20  * linux/drivers/video/skeletonfb.c -- Skeleton for a frame buffer device
21  *  Created 28 Dec 1997 by Geert Uytterhoeven
22  *
23  *  This program is free software; you can redistribute  it and/or modify it
24  *  under  the terms of  the GNU General  Public License as published by the
25  *  Free Software Foundation;  either version 2 of the  License, or (at your
26  *  option) any later version.
27  *
28  *  THIS  SOFTWARE  IS PROVIDED   ``AS  IS'' AND   ANY  EXPRESS OR IMPLIED
29  *  WARRANTIES,   INCLUDING, BUT NOT  LIMITED  TO, THE IMPLIED WARRANTIES OF
30  *  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN
31  *  NO  EVENT  SHALL   THE AUTHOR  BE    LIABLE FOR ANY   DIRECT, INDIRECT,
32  *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
33  *  NOT LIMITED   TO, PROCUREMENT OF  SUBSTITUTE GOODS  OR SERVICES; LOSS OF
34  *  USE, DATA,  OR PROFITS; OR  BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
35  *  ANY THEORY OF LIABILITY, WHETHER IN  CONTRACT, STRICT LIABILITY, OR TORT
36  *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
37  *  THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38  *
39  *  You should have received a copy of the  GNU General Public License along
40  *  with this program; if not, write  to the Free Software Foundation, Inc.,
41  *  675 Mass Ave, Cambridge, MA 02139, USA.
42  */
43 #include <linux/module.h>
44 #include <linux/kernel.h>
45 #include <linux/errno.h>
46 #include <linux/string.h>
47 #include <linux/mm.h>
48 #include <linux/fb.h>
49 #include <linux/init.h>
50 #include <linux/interrupt.h>
51 #include <linux/ctype.h>
52 #include <linux/dma-mapping.h>
53 #include <linux/platform_device.h>
54
55 #include <asm/mach-au1x00/au1000.h>
56
57 #define DEBUG 0
58
59 #include "au1100fb.h"
60
61 /*
62  * Sanity check. If this is a new Au1100 based board, search for
63  * the PB1100 ifdefs to make sure you modify the code accordingly.
64  */
65 #if defined(CONFIG_MIPS_PB1100)
66   #include <asm/mach-pb1x00/pb1100.h>
67 #elif defined(CONFIG_MIPS_DB1100)
68   #include <asm/mach-db1x00/db1x00.h>
69 #else
70   #error "Unknown Au1100 board, Au1100 FB driver not supported"
71 #endif
72
73 #define DRIVER_NAME "au1100fb"
74 #define DRIVER_DESC "LCD controller driver for AU1100 processors"
75
76 #define to_au1100fb_device(_info) \
77           (_info ? container_of(_info, struct au1100fb_device, info) : NULL);
78
79 /* Bitfields format supported by the controller. Note that the order of formats
80  * SHOULD be the same as in the LCD_CONTROL_SBPPF field, so we can retrieve the
81  * right pixel format by doing rgb_bitfields[LCD_CONTROL_SBPPF_XXX >> LCD_CONTROL_SBPPF]
82  */
83 struct fb_bitfield rgb_bitfields[][4] =
84 {
85         /*     Red,        Green,        Blue,       Transp   */
86         { { 10, 6, 0 }, { 5, 5, 0 }, { 0, 5, 0 }, { 0, 0, 0 } },
87         { { 11, 5, 0 }, { 5, 6, 0 }, { 0, 5, 0 }, { 0, 0, 0 } },
88         { { 11, 5, 0 }, { 6, 5, 0 }, { 0, 6, 0 }, { 0, 0, 0 } },
89         { { 10, 5, 0 }, { 5, 5, 0 }, { 0, 5, 0 }, { 15, 1, 0 } },
90         { { 11, 5, 0 }, { 6, 5, 0 }, { 1, 5, 0 }, { 0, 1, 0 } },
91
92         /* The last is used to describe 12bpp format */
93         { { 8, 4, 0 },  { 4, 4, 0 }, { 0, 4, 0 }, { 0, 0, 0 } },
94 };
95
96 static struct fb_fix_screeninfo au1100fb_fix __initdata = {
97         .id             = "AU1100 FB",
98         .xpanstep       = 1,
99         .ypanstep       = 1,
100         .type           = FB_TYPE_PACKED_PIXELS,
101         .accel          = FB_ACCEL_NONE,
102 };
103
104 static struct fb_var_screeninfo au1100fb_var __initdata = {
105         .activate       = FB_ACTIVATE_NOW,
106         .height         = -1,
107         .width          = -1,
108         .vmode          = FB_VMODE_NONINTERLACED,
109 };
110
111 static struct au1100fb_drv_info drv_info;
112
113 /*
114  * Set hardware with var settings. This will enable the controller with a specific
115  * mode, normally validated with the fb_check_var method
116          */
117 int au1100fb_setmode(struct au1100fb_device *fbdev)
118 {
119         struct fb_info *info = &fbdev->info;
120         u32 words;
121         int index;
122
123         if (!fbdev)
124                 return -EINVAL;
125
126         /* Update var-dependent FB info */
127         if (panel_is_active(fbdev->panel) || panel_is_color(fbdev->panel)) {
128                 if (info->var.bits_per_pixel <= 8) {
129                         /* palettized */
130                         info->var.red.offset    = 0;
131                         info->var.red.length    = info->var.bits_per_pixel;
132                         info->var.red.msb_right = 0;
133
134                         info->var.green.offset  = 0;
135                         info->var.green.length  = info->var.bits_per_pixel;
136                         info->var.green.msb_right = 0;
137
138                         info->var.blue.offset   = 0;
139                         info->var.blue.length   = info->var.bits_per_pixel;
140                         info->var.blue.msb_right = 0;
141
142                         info->var.transp.offset = 0;
143                         info->var.transp.length = 0;
144                         info->var.transp.msb_right = 0;
145
146                         info->fix.visual = FB_VISUAL_PSEUDOCOLOR;
147                         info->fix.line_length = info->var.xres_virtual /
148                                                         (8/info->var.bits_per_pixel);
149                 } else {
150                         /* non-palettized */
151                         index = (fbdev->panel->control_base & LCD_CONTROL_SBPPF_MASK) >> LCD_CONTROL_SBPPF_BIT;
152                         info->var.red = rgb_bitfields[index][0];
153                         info->var.green = rgb_bitfields[index][1];
154                         info->var.blue = rgb_bitfields[index][2];
155                         info->var.transp = rgb_bitfields[index][3];
156
157                         info->fix.visual = FB_VISUAL_TRUECOLOR;
158                         info->fix.line_length = info->var.xres_virtual << 1; /* depth=16 */
159         }
160         } else {
161                 /* mono */
162                 info->fix.visual = FB_VISUAL_MONO10;
163                 info->fix.line_length = info->var.xres_virtual / 8;
164         }
165
166         info->screen_size = info->fix.line_length * info->var.yres_virtual;
167
168         /* Determine BPP mode and format */
169         fbdev->regs->lcd_control = fbdev->panel->control_base |
170                             ((info->var.rotate/90) << LCD_CONTROL_SM_BIT);
171
172         fbdev->regs->lcd_intenable = 0;
173         fbdev->regs->lcd_intstatus = 0;
174
175         fbdev->regs->lcd_horztiming = fbdev->panel->horztiming;
176
177         fbdev->regs->lcd_verttiming = fbdev->panel->verttiming;
178
179         fbdev->regs->lcd_clkcontrol = fbdev->panel->clkcontrol_base;
180
181         fbdev->regs->lcd_dmaaddr0 = LCD_DMA_SA_N(fbdev->fb_phys);
182
183         if (panel_is_dual(fbdev->panel)) {
184                 /* Second panel display seconf half of screen if possible,
185                  * otherwise display the same as the first panel */
186                 if (info->var.yres_virtual >= (info->var.yres << 1)) {
187                         fbdev->regs->lcd_dmaaddr1 = LCD_DMA_SA_N(fbdev->fb_phys +
188                                                           (info->fix.line_length *
189                                                           (info->var.yres_virtual >> 1)));
190                 } else {
191                         fbdev->regs->lcd_dmaaddr1 = LCD_DMA_SA_N(fbdev->fb_phys);
192                 }
193         }
194
195         words = info->fix.line_length / sizeof(u32);
196         if (!info->var.rotate || (info->var.rotate == 180)) {
197                 words *= info->var.yres_virtual;
198                 if (info->var.rotate /* 180 */) {
199                         words -= (words % 8); /* should be divisable by 8 */
200                 }
201         }
202         fbdev->regs->lcd_words = LCD_WRD_WRDS_N(words);
203
204         fbdev->regs->lcd_pwmdiv = 0;
205         fbdev->regs->lcd_pwmhi = 0;
206
207         /* Resume controller */
208         fbdev->regs->lcd_control |= LCD_CONTROL_GO;
209
210         return 0;
211 }
212
213 /* fb_setcolreg
214  * Set color in LCD palette.
215  */
216 int au1100fb_fb_setcolreg(unsigned regno, unsigned red, unsigned green, unsigned blue, unsigned transp, struct fb_info *fbi)
217 {
218         struct au1100fb_device *fbdev;
219         u32 *palette;
220         u32 value;
221
222         fbdev = to_au1100fb_device(fbi);
223         palette = fbdev->regs->lcd_pallettebase;
224
225         if (regno > (AU1100_LCD_NBR_PALETTE_ENTRIES - 1))
226                 return -EINVAL;
227
228         if (fbi->var.grayscale) {
229                 /* Convert color to grayscale */
230                 red = green = blue =
231                         (19595 * red + 38470 * green + 7471 * blue) >> 16;
232         }
233
234         if (fbi->fix.visual == FB_VISUAL_TRUECOLOR) {
235                 /* Place color in the pseudopalette */
236                 if (regno > 16)
237                         return -EINVAL;
238
239                 palette = (u32*)fbi->pseudo_palette;
240
241                 red   >>= (16 - fbi->var.red.length);
242                 green >>= (16 - fbi->var.green.length);
243                 blue  >>= (16 - fbi->var.blue.length);
244
245                 value = (red   << fbi->var.red.offset)  |
246                         (green << fbi->var.green.offset)|
247                         (blue  << fbi->var.blue.offset);
248                 value &= 0xFFFF;
249
250         } else if (panel_is_active(fbdev->panel)) {
251                 /* COLOR TFT PALLETTIZED (use RGB 565) */
252                 value = (red & 0xF800)|((green >> 5) & 0x07E0)|((blue >> 11) & 0x001F);
253                 value &= 0xFFFF;
254
255         } else if (panel_is_color(fbdev->panel)) {
256                 /* COLOR STN MODE */
257                 value = (((panel_swap_rgb(fbdev->panel) ? blue : red) >> 12) & 0x000F) |
258                         ((green >> 8) & 0x00F0) |
259                         (((panel_swap_rgb(fbdev->panel) ? red : blue) >> 4) & 0x0F00);
260                 value &= 0xFFF;
261         } else {
262                 /* MONOCHROME MODE */
263                 value = (green >> 12) & 0x000F;
264                 value &= 0xF;
265         }
266
267         palette[regno] = value;
268
269         return 0;
270 }
271
272 /* fb_blank
273  * Blank the screen. Depending on the mode, the screen will be
274  * activated with the backlight color, or desactivated
275  */
276 int au1100fb_fb_blank(int blank_mode, struct fb_info *fbi)
277 {
278         struct au1100fb_device *fbdev = to_au1100fb_device(fbi);
279
280         print_dbg("fb_blank %d %p", blank_mode, fbi);
281
282         switch (blank_mode) {
283
284         case VESA_NO_BLANKING:
285                         /* Turn on panel */
286                         fbdev->regs->lcd_control |= LCD_CONTROL_GO;
287 #ifdef CONFIG_MIPS_PB1100
288                         if (drv_info.panel_idx == 1) {
289                                 au_writew(au_readw(PB1100_G_CONTROL)
290                                           | (PB1100_G_CONTROL_BL | PB1100_G_CONTROL_VDD),
291                         PB1100_G_CONTROL);
292                         }
293 #endif
294                 au_sync();
295                 break;
296
297         case VESA_VSYNC_SUSPEND:
298         case VESA_HSYNC_SUSPEND:
299         case VESA_POWERDOWN:
300                         /* Turn off panel */
301                         fbdev->regs->lcd_control &= ~LCD_CONTROL_GO;
302 #ifdef CONFIG_MIPS_PB1100
303                         if (drv_info.panel_idx == 1) {
304                                 au_writew(au_readw(PB1100_G_CONTROL)
305                                           & ~(PB1100_G_CONTROL_BL | PB1100_G_CONTROL_VDD),
306                         PB1100_G_CONTROL);
307                         }
308 #endif
309                 au_sync();
310                 break;
311         default:
312                 break;
313
314         }
315         return 0;
316 }
317
318 /* fb_pan_display
319  * Pan display in x and/or y as specified
320  */
321 int au1100fb_fb_pan_display(struct fb_var_screeninfo *var, struct fb_info *fbi)
322 {
323         struct au1100fb_device *fbdev;
324         int dy;
325
326         fbdev = to_au1100fb_device(fbi);
327
328         print_dbg("fb_pan_display %p %p", var, fbi);
329
330         if (!var || !fbdev) {
331                 return -EINVAL;
332         }
333
334         if (var->xoffset - fbi->var.xoffset) {
335                 /* No support for X panning for now! */
336                 return -EINVAL;
337         }
338
339         print_dbg("fb_pan_display 2 %p %p", var, fbi);
340         dy = var->yoffset - fbi->var.yoffset;
341         if (dy) {
342
343                 u32 dmaaddr;
344
345                 print_dbg("Panning screen of %d lines", dy);
346
347                 dmaaddr = fbdev->regs->lcd_dmaaddr0;
348                 dmaaddr += (fbi->fix.line_length * dy);
349
350                 /* TODO: Wait for current frame to finished */
351                 fbdev->regs->lcd_dmaaddr0 = LCD_DMA_SA_N(dmaaddr);
352
353                 if (panel_is_dual(fbdev->panel)) {
354                         dmaaddr = fbdev->regs->lcd_dmaaddr1;
355                         dmaaddr += (fbi->fix.line_length * dy);
356                         fbdev->regs->lcd_dmaaddr0 = LCD_DMA_SA_N(dmaaddr);
357         }
358         }
359         print_dbg("fb_pan_display 3 %p %p", var, fbi);
360
361         return 0;
362 }
363
364 /* fb_rotate
365  * Rotate the display of this angle. This doesn't seems to be used by the core,
366  * but as our hardware supports it, so why not implementing it...
367  */
368 void au1100fb_fb_rotate(struct fb_info *fbi, int angle)
369 {
370         struct au1100fb_device *fbdev = to_au1100fb_device(fbi);
371
372         print_dbg("fb_rotate %p %d", fbi, angle);
373
374         if (fbdev && (angle > 0) && !(angle % 90)) {
375
376                 fbdev->regs->lcd_control &= ~LCD_CONTROL_GO;
377
378                 fbdev->regs->lcd_control &= ~(LCD_CONTROL_SM_MASK);
379                 fbdev->regs->lcd_control |= ((angle/90) << LCD_CONTROL_SM_BIT);
380
381                 fbdev->regs->lcd_control |= LCD_CONTROL_GO;
382         }
383 }
384
385 /* fb_mmap
386  * Map video memory in user space. We don't use the generic fb_mmap method mainly
387  * to allow the use of the TLB streaming flag (CCA=6)
388  */
389 int au1100fb_fb_mmap(struct fb_info *fbi, struct vm_area_struct *vma)
390 {
391         struct au1100fb_device *fbdev;
392         unsigned int len;
393         unsigned long start=0, off;
394
395         fbdev = to_au1100fb_device(fbi);
396
397         if (vma->vm_pgoff > (~0UL >> PAGE_SHIFT)) {
398                 return -EINVAL;
399         }
400
401         start = fbdev->fb_phys & PAGE_MASK;
402         len = PAGE_ALIGN((start & ~PAGE_MASK) + fbdev->fb_len);
403
404         off = vma->vm_pgoff << PAGE_SHIFT;
405
406         if ((vma->vm_end - vma->vm_start + off) > len) {
407                 return -EINVAL;
408         }
409
410         off += start;
411         vma->vm_pgoff = off >> PAGE_SHIFT;
412
413         vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
414         pgprot_val(vma->vm_page_prot) |= (6 << 9); //CCA=6
415
416         vma->vm_flags |= VM_IO;
417
418         if (io_remap_pfn_range(vma, vma->vm_start, off >> PAGE_SHIFT,
419                                 vma->vm_end - vma->vm_start,
420                                 vma->vm_page_prot)) {
421                 return -EAGAIN;
422         }
423
424         return 0;
425 }
426
427 static struct fb_ops au1100fb_ops =
428 {
429         .owner                  = THIS_MODULE,
430         .fb_setcolreg           = au1100fb_fb_setcolreg,
431         .fb_blank               = au1100fb_fb_blank,
432         .fb_pan_display         = au1100fb_fb_pan_display,
433         .fb_fillrect            = cfb_fillrect,
434         .fb_copyarea            = cfb_copyarea,
435         .fb_imageblit           = cfb_imageblit,
436         .fb_rotate              = au1100fb_fb_rotate,
437         .fb_mmap                = au1100fb_fb_mmap,
438 };
439
440
441 /*-------------------------------------------------------------------------*/
442
443 /* AU1100 LCD controller device driver */
444
445 int au1100fb_drv_probe(struct device *dev)
446 {
447         struct au1100fb_device *fbdev = NULL;
448         struct resource *regs_res;
449         unsigned long page;
450         u32 sys_clksrc;
451
452         if (!dev)
453                         return -EINVAL;
454
455         /* Allocate new device private */
456         if (!(fbdev = kmalloc(sizeof(struct au1100fb_device), GFP_KERNEL))) {
457                 print_err("fail to allocate device private record");
458                 return -ENOMEM;
459         }
460         memset((void*)fbdev, 0, sizeof(struct au1100fb_device));
461
462         fbdev->panel = &known_lcd_panels[drv_info.panel_idx];
463
464         dev_set_drvdata(dev, (void*)fbdev);
465
466         /* Allocate region for our registers and map them */
467         if (!(regs_res = platform_get_resource(to_platform_device(dev),
468                                         IORESOURCE_MEM, 0))) {
469                 print_err("fail to retrieve registers resource");
470                 return -EFAULT;
471         }
472
473         au1100fb_fix.mmio_start = regs_res->start;
474         au1100fb_fix.mmio_len = regs_res->end - regs_res->start + 1;
475
476         if (!request_mem_region(au1100fb_fix.mmio_start, au1100fb_fix.mmio_len,
477                                 DRIVER_NAME)) {
478                 print_err("fail to lock memory region at 0x%08lx",
479                                 au1100fb_fix.mmio_start);
480                 return -EBUSY;
481         }
482
483         fbdev->regs = (struct au1100fb_regs*)KSEG1ADDR(au1100fb_fix.mmio_start);
484
485         print_dbg("Register memory map at %p", fbdev->regs);
486         print_dbg("phys=0x%08x, size=%d", fbdev->regs_phys, fbdev->regs_len);
487
488
489
490         /* Allocate the framebuffer to the maximum screen size * nbr of video buffers */
491         fbdev->fb_len = fbdev->panel->xres * fbdev->panel->yres *
492                         (fbdev->panel->bpp >> 3) * AU1100FB_NBR_VIDEO_BUFFERS;
493
494         fbdev->fb_mem = dma_alloc_coherent(dev, PAGE_ALIGN(fbdev->fb_len),
495                                         &fbdev->fb_phys, GFP_KERNEL);
496         if (!fbdev->fb_mem) {
497                 print_err("fail to allocate frambuffer (size: %dK))",
498                           fbdev->fb_len / 1024);
499                 return -ENOMEM;
500         }
501
502         au1100fb_fix.smem_start = fbdev->fb_phys;
503         au1100fb_fix.smem_len = fbdev->fb_len;
504
505         /*
506          * Set page reserved so that mmap will work. This is necessary
507          * since we'll be remapping normal memory.
508          */
509         for (page = (unsigned long)fbdev->fb_mem;
510              page < PAGE_ALIGN((unsigned long)fbdev->fb_mem + fbdev->fb_len);
511              page += PAGE_SIZE) {
512 #if CONFIG_DMA_NONCOHERENT
513                 SetPageReserved(virt_to_page(CAC_ADDR(page)));
514 #else
515                 SetPageReserved(virt_to_page(page));
516 #endif
517         }
518
519         print_dbg("Framebuffer memory map at %p", fbdev->fb_mem);
520         print_dbg("phys=0x%08x, size=%dK", fbdev->fb_phys, fbdev->fb_len / 1024);
521
522         /* Setup LCD clock to AUX (48 MHz) */
523         sys_clksrc = au_readl(SYS_CLKSRC) & ~(SYS_CS_ML_MASK | SYS_CS_DL | SYS_CS_CL);
524         au_writel((sys_clksrc | (1 << SYS_CS_ML_BIT)), SYS_CLKSRC);
525
526         /* load the panel info into the var struct */
527         au1100fb_var.bits_per_pixel = fbdev->panel->bpp;
528         au1100fb_var.xres = fbdev->panel->xres;
529         au1100fb_var.xres_virtual = au1100fb_var.xres;
530         au1100fb_var.yres = fbdev->panel->yres;
531         au1100fb_var.yres_virtual = au1100fb_var.yres;
532
533         fbdev->info.screen_base = fbdev->fb_mem;
534         fbdev->info.fbops = &au1100fb_ops;
535         fbdev->info.fix = au1100fb_fix;
536
537         if (!(fbdev->info.pseudo_palette = kmalloc(sizeof(u32) * 16, GFP_KERNEL))) {
538                 return -ENOMEM;
539         }
540         memset(fbdev->info.pseudo_palette, 0, sizeof(u32) * 16);
541
542         if (fb_alloc_cmap(&fbdev->info.cmap, AU1100_LCD_NBR_PALETTE_ENTRIES, 0) < 0) {
543                 print_err("Fail to allocate colormap (%d entries)",
544                            AU1100_LCD_NBR_PALETTE_ENTRIES);
545                 kfree(fbdev->info.pseudo_palette);
546                 return -EFAULT;
547         }
548
549         fbdev->info.var = au1100fb_var;
550
551         /* Set h/w registers */
552         au1100fb_setmode(fbdev);
553
554         /* Register new framebuffer */
555         if (register_framebuffer(&fbdev->info) < 0) {
556                 print_err("cannot register new framebuffer");
557                 goto failed;
558         }
559
560         return 0;
561
562 failed:
563         if (fbdev->regs) {
564                 release_mem_region(fbdev->regs_phys, fbdev->regs_len);
565         }
566         if (fbdev->fb_mem) {
567                 dma_free_noncoherent(dev, fbdev->fb_len, fbdev->fb_mem, fbdev->fb_phys);
568         }
569         if (fbdev->info.cmap.len != 0) {
570                 fb_dealloc_cmap(&fbdev->info.cmap);
571         }
572         kfree(fbdev);
573         dev_set_drvdata(dev, NULL);
574
575         return 0;
576 }
577
578 int au1100fb_drv_remove(struct device *dev)
579 {
580         struct au1100fb_device *fbdev = NULL;
581
582         if (!dev)
583                 return -ENODEV;
584
585         fbdev = (struct au1100fb_device*) dev_get_drvdata(dev);
586
587 #if !defined(CONFIG_FRAMEBUFFER_CONSOLE) && defined(CONFIG_LOGO)
588         au1100fb_fb_blank(VESA_POWERDOWN, &fbdev->info);
589 #endif
590         fbdev->regs->lcd_control &= ~LCD_CONTROL_GO;
591
592         /* Clean up all probe data */
593         unregister_framebuffer(&fbdev->info);
594
595         release_mem_region(fbdev->regs_phys, fbdev->regs_len);
596
597         dma_free_coherent(dev, PAGE_ALIGN(fbdev->fb_len), fbdev->fb_mem, fbdev->fb_phys);
598
599         fb_dealloc_cmap(&fbdev->info.cmap);
600         kfree(fbdev->info.pseudo_palette);
601         kfree((void*)fbdev);
602
603         return 0;
604 }
605
606 #ifdef CONFIG_PM
607 static u32 sys_clksrc;
608 static struct au1100fb_regs fbregs;
609
610 int au1100fb_drv_suspend(struct device *dev, pm_message_t state)
611 {
612         struct au1100fb_device *fbdev = dev_get_drvdata(dev);
613
614         if (!fbdev)
615                 return 0;
616
617         /* Save the clock source state */
618         sys_clksrc = au_readl(SYS_CLKSRC);
619
620         /* Blank the LCD */
621         au1100fb_fb_blank(VESA_POWERDOWN, &fbdev->info);
622
623         /* Stop LCD clocking */
624         au_writel(sys_clksrc & ~SYS_CS_ML_MASK, SYS_CLKSRC);
625
626         memcpy(&fbregs, fbdev->regs, sizeof(struct au1100fb_regs));
627
628         return 0;
629 }
630
631 int au1100fb_drv_resume(struct device *dev)
632 {
633         struct au1100fb_device *fbdev = dev_get_drvdata(dev);
634
635         if (!fbdev)
636                 return 0;
637
638         memcpy(fbdev->regs, &fbregs, sizeof(struct au1100fb_regs));
639
640         /* Restart LCD clocking */
641         au_writel(sys_clksrc, SYS_CLKSRC);
642
643         /* Unblank the LCD */
644         au1100fb_fb_blank(VESA_NO_BLANKING, &fbdev->info);
645
646         return 0;
647 }
648 #else
649 #define au1100fb_drv_suspend NULL
650 #define au1100fb_drv_resume NULL
651 #endif
652
653 static struct device_driver au1100fb_driver = {
654         .name           = "au1100-lcd",
655         .bus            = &platform_bus_type,
656
657         .probe          = au1100fb_drv_probe,
658         .remove         = au1100fb_drv_remove,
659         .suspend        = au1100fb_drv_suspend,
660         .resume         = au1100fb_drv_resume,
661 };
662
663 /*-------------------------------------------------------------------------*/
664
665 /* Kernel driver */
666
667 int au1100fb_setup(char *options)
668 {
669         char* this_opt;
670         int num_panels = ARRAY_SIZE(known_lcd_panels);
671         char* mode = NULL;
672         int panel_idx = 0;
673
674         if (num_panels <= 0) {
675                 print_err("No LCD panels supported by driver!");
676                 return -EFAULT;
677                         }
678
679         if (options) {
680                 while ((this_opt = strsep(&options,",")) != NULL) {
681                         /* Panel option */
682                 if (!strncmp(this_opt, "panel:", 6)) {
683                                 int i;
684                                 this_opt += 6;
685                                 for (i = 0; i < num_panels; i++) {
686                                         if (!strncmp(this_opt,
687                                                      known_lcd_panels[i].name,
688                                                         strlen(this_opt))) {
689                                                 panel_idx = i;
690                                         break;
691                                 }
692                         }
693                                 if (i >= num_panels) {
694                                         print_warn("Panel %s not supported!", this_opt);
695                                 }
696                         }
697                         /* Mode option (only option that start with digit) */
698                         else if (isdigit(this_opt[0])) {
699                                 mode = kmalloc(strlen(this_opt) + 1, GFP_KERNEL);
700                                 strncpy(mode, this_opt, strlen(this_opt) + 1);
701                         }
702                         /* Unsupported option */
703                         else {
704                                 print_warn("Unsupported option \"%s\"", this_opt);
705                 }
706                 }
707         }
708
709         drv_info.panel_idx = panel_idx;
710         drv_info.opt_mode = mode;
711
712         print_info("Panel=%s Mode=%s",
713                         known_lcd_panels[drv_info.panel_idx].name,
714                         drv_info.opt_mode ? drv_info.opt_mode : "default");
715
716         return 0;
717 }
718
719 int __init au1100fb_init(void)
720 {
721         char* options;
722         int ret;
723
724         print_info("" DRIVER_DESC "");
725
726         memset(&drv_info, 0, sizeof(drv_info));
727
728         if (fb_get_options(DRIVER_NAME, &options))
729                 return -ENODEV;
730
731         /* Setup driver with options */
732         ret = au1100fb_setup(options);
733         if (ret < 0) {
734                 print_err("Fail to setup driver");
735                 return ret;
736         }
737
738         return driver_register(&au1100fb_driver);
739 }
740
741 void __exit au1100fb_cleanup(void)
742 {
743         driver_unregister(&au1100fb_driver);
744
745         kfree(drv_info.opt_mode);
746 }
747
748 module_init(au1100fb_init);
749 module_exit(au1100fb_cleanup);
750
751 MODULE_DESCRIPTION(DRIVER_DESC);
752 MODULE_LICENSE("GPL");