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