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