usb/gadget: Replace the old USB audio FU definitions in f_audio.c
[safe/jmp/linux-2.6] / drivers / video / pxafb.c
index 16e37a5..825b665 100644 (file)
  *
  *     linux-arm-kernel@lists.arm.linux.org.uk
  *
+ * Add support for overlay1 and overlay2 based on pxafb_overlay.c:
+ *
+ *   Copyright (C) 2004, Intel Corporation
+ *
+ *     2003/08/27: <yu.tang@intel.com>
+ *     2004/03/10: <stanley.cai@intel.com>
+ *     2004/10/28: <yan.yin@intel.com>
+ *
+ *   Copyright (C) 2006-2008 Marvell International Ltd.
+ *   All Rights Reserved
  */
 
-#include <linux/config.h>
 #include <linux/module.h>
 #include <linux/moduleparam.h>
 #include <linux/kernel.h>
 #include <linux/string.h>
 #include <linux/interrupt.h>
 #include <linux/slab.h>
+#include <linux/mm.h>
 #include <linux/fb.h>
 #include <linux/delay.h>
 #include <linux/init.h>
 #include <linux/ioport.h>
 #include <linux/cpufreq.h>
-#include <linux/device.h>
+#include <linux/platform_device.h>
 #include <linux/dma-mapping.h>
-
-#include <asm/hardware.h>
+#include <linux/clk.h>
+#include <linux/err.h>
+#include <linux/completion.h>
+#include <linux/mutex.h>
+#include <linux/kthread.h>
+#include <linux/freezer.h>
+
+#include <mach/hardware.h>
 #include <asm/io.h>
 #include <asm/irq.h>
-#include <asm/uaccess.h>
 #include <asm/div64.h>
-#include <asm/arch/pxa-regs.h>
-#include <asm/arch/bitfield.h>
-#include <asm/arch/pxafb.h>
+#include <mach/bitfield.h>
+#include <mach/pxafb.h>
 
 /*
  * Complain if VAR is out of range.
 #include "pxafb.h"
 
 /* Bits which should not be set in machine configuration structures */
-#define LCCR0_INVALID_CONFIG_MASK (LCCR0_OUM|LCCR0_BM|LCCR0_QDM|LCCR0_DIS|LCCR0_EFM|LCCR0_IUM|LCCR0_SFM|LCCR0_LDM|LCCR0_ENB)
-#define LCCR3_INVALID_CONFIG_MASK (LCCR3_HSP|LCCR3_VSP|LCCR3_PCD|LCCR3_BPP)
+#define LCCR0_INVALID_CONFIG_MASK      (LCCR0_OUM | LCCR0_BM | LCCR0_QDM |\
+                                        LCCR0_DIS | LCCR0_EFM | LCCR0_IUM |\
+                                        LCCR0_SFM | LCCR0_LDM | LCCR0_ENB)
 
-static void (*pxafb_backlight_power)(int);
-static void (*pxafb_lcd_power)(int);
+#define LCCR3_INVALID_CONFIG_MASK      (LCCR3_HSP | LCCR3_VSP |\
+                                        LCCR3_PCD | LCCR3_BPP(0xf))
 
-static int pxafb_activate_var(struct fb_var_screeninfo *var, struct pxafb_info *);
+static int pxafb_activate_var(struct fb_var_screeninfo *var,
+                               struct pxafb_info *);
 static void set_ctrlr_state(struct pxafb_info *fbi, u_int state);
+static void setup_base_frame(struct pxafb_info *fbi,
+                             struct fb_var_screeninfo *var, int branch);
+static int setup_frame_dma(struct pxafb_info *fbi, int dma, int pal,
+                          unsigned long offset, size_t size);
 
-#ifdef CONFIG_FB_PXA_PARAMETERS
-#define PXAFB_OPTIONS_SIZE 256
-static char g_options[PXAFB_OPTIONS_SIZE] __initdata = "";
-#endif
+static unsigned long video_mem_size = 0;
+
+static inline unsigned long
+lcd_readl(struct pxafb_info *fbi, unsigned int off)
+{
+       return __raw_readl(fbi->mmio_base + off);
+}
+
+static inline void
+lcd_writel(struct pxafb_info *fbi, unsigned int off, unsigned long val)
+{
+       __raw_writel(val, fbi->mmio_base + off);
+}
 
 static inline void pxafb_schedule_work(struct pxafb_info *fbi, u_int state)
 {
@@ -78,10 +107,12 @@ static inline void pxafb_schedule_work(struct pxafb_info *fbi, u_int state)
        /*
         * We need to handle two requests being made at the same time.
         * There are two important cases:
-        *  1. When we are changing VT (C_REENABLE) while unblanking (C_ENABLE)
-        *     We must perform the unblanking, which will do our REENABLE for us.
-        *  2. When we are blanking, but immediately unblank before we have
-        *     blanked.  We do the "REENABLE" thing here as well, just to be sure.
+        *  1. When we are changing VT (C_REENABLE) while unblanking
+        *     (C_ENABLE) We must perform the unblanking, which will
+        *     do our REENABLE for us.
+        *  2. When we are blanking, but immediately unblank before
+        *     we have blanked.  We do the "REENABLE" thing here as
+        *     well, just to be sure.
         */
        if (fbi->task_state == C_ENABLE && state == C_REENABLE)
                state = (u_int) -1;
@@ -107,20 +138,44 @@ pxafb_setpalettereg(u_int regno, u_int red, u_int green, u_int blue,
                       u_int trans, struct fb_info *info)
 {
        struct pxafb_info *fbi = (struct pxafb_info *)info;
-       u_int val, ret = 1;
+       u_int val;
 
-       if (regno < fbi->palette_size) {
-               if (fbi->fb.var.grayscale) {
-                       val = ((blue >> 8) & 0x00ff);
-               } else {
-                       val  = ((red   >>  0) & 0xf800);
-                       val |= ((green >>  5) & 0x07e0);
-                       val |= ((blue  >> 11) & 0x001f);
-               }
+       if (regno >= fbi->palette_size)
+               return 1;
+
+       if (fbi->fb.var.grayscale) {
+               fbi->palette_cpu[regno] = ((blue >> 8) & 0x00ff);
+               return 0;
+       }
+
+       switch (fbi->lccr4 & LCCR4_PAL_FOR_MASK) {
+       case LCCR4_PAL_FOR_0:
+               val  = ((red   >>  0) & 0xf800);
+               val |= ((green >>  5) & 0x07e0);
+               val |= ((blue  >> 11) & 0x001f);
                fbi->palette_cpu[regno] = val;
-               ret = 0;
+               break;
+       case LCCR4_PAL_FOR_1:
+               val  = ((red   << 8) & 0x00f80000);
+               val |= ((green >> 0) & 0x0000fc00);
+               val |= ((blue  >> 8) & 0x000000f8);
+               ((u32 *)(fbi->palette_cpu))[regno] = val;
+               break;
+       case LCCR4_PAL_FOR_2:
+               val  = ((red   << 8) & 0x00fc0000);
+               val |= ((green >> 0) & 0x0000fc00);
+               val |= ((blue  >> 8) & 0x000000fc);
+               ((u32 *)(fbi->palette_cpu))[regno] = val;
+               break;
+       case LCCR4_PAL_FOR_3:
+               val  = ((red   << 8) & 0x00ff0000);
+               val |= ((green >> 0) & 0x0000ff00);
+               val |= ((blue  >> 8) & 0x000000ff);
+               ((u32 *)(fbi->palette_cpu))[regno] = val;
+               break;
        }
-       return ret;
+
+       return 0;
 }
 
 static int
@@ -178,21 +233,110 @@ pxafb_setcolreg(u_int regno, u_int red, u_int green, u_int blue,
        return ret;
 }
 
+/* calculate pixel depth, transparency bit included, >=16bpp formats _only_ */
+static inline int var_to_depth(struct fb_var_screeninfo *var)
+{
+       return var->red.length + var->green.length +
+               var->blue.length + var->transp.length;
+}
+
+/* calculate 4-bit BPP value for LCCR3 and OVLxC1 */
+static int pxafb_var_to_bpp(struct fb_var_screeninfo *var)
+{
+       int bpp = -EINVAL;
+
+       switch (var->bits_per_pixel) {
+       case 1:  bpp = 0; break;
+       case 2:  bpp = 1; break;
+       case 4:  bpp = 2; break;
+       case 8:  bpp = 3; break;
+       case 16: bpp = 4; break;
+       case 24:
+               switch (var_to_depth(var)) {
+               case 18: bpp = 6; break; /* 18-bits/pixel packed */
+               case 19: bpp = 8; break; /* 19-bits/pixel packed */
+               case 24: bpp = 9; break;
+               }
+               break;
+       case 32:
+               switch (var_to_depth(var)) {
+               case 18: bpp = 5; break; /* 18-bits/pixel unpacked */
+               case 19: bpp = 7; break; /* 19-bits/pixel unpacked */
+               case 25: bpp = 10; break;
+               }
+               break;
+       }
+       return bpp;
+}
+
 /*
- *  pxafb_bpp_to_lccr3():
+ *  pxafb_var_to_lccr3():
  *    Convert a bits per pixel value to the correct bit pattern for LCCR3
+ *
+ *  NOTE: for PXA27x with overlays support, the LCCR3_PDFOR_x bits have an
+ *  implication of the acutal use of transparency bit,  which we handle it
+ *  here separatedly. See PXA27x Developer's Manual, Section <<7.4.6 Pixel
+ *  Formats>> for the valid combination of PDFOR, PAL_FOR for various BPP.
+ *
+ *  Transparency for palette pixel formats is not supported at the moment.
  */
-static int pxafb_bpp_to_lccr3(struct fb_var_screeninfo *var)
+static uint32_t pxafb_var_to_lccr3(struct fb_var_screeninfo *var)
 {
-        int ret = 0;
-        switch (var->bits_per_pixel) {
-        case 1:  ret = LCCR3_1BPP; break;
-        case 2:  ret = LCCR3_2BPP; break;
-        case 4:  ret = LCCR3_4BPP; break;
-        case 8:  ret = LCCR3_8BPP; break;
-        case 16: ret = LCCR3_16BPP; break;
-        }
-        return ret;
+       int bpp = pxafb_var_to_bpp(var);
+       uint32_t lccr3;
+
+       if (bpp < 0)
+               return 0;
+
+       lccr3 = LCCR3_BPP(bpp);
+
+       switch (var_to_depth(var)) {
+       case 16: lccr3 |= var->transp.length ? LCCR3_PDFOR_3 : 0; break;
+       case 18: lccr3 |= LCCR3_PDFOR_3; break;
+       case 24: lccr3 |= var->transp.length ? LCCR3_PDFOR_2 : LCCR3_PDFOR_3;
+                break;
+       case 19:
+       case 25: lccr3 |= LCCR3_PDFOR_0; break;
+       }
+       return lccr3;
+}
+
+#define SET_PIXFMT(v, r, g, b, t)                              \
+({                                                             \
+       (v)->transp.offset = (t) ? (r) + (g) + (b) : 0;         \
+       (v)->transp.length = (t) ? (t) : 0;                     \
+       (v)->blue.length   = (b); (v)->blue.offset = 0;         \
+       (v)->green.length  = (g); (v)->green.offset = (b);      \
+       (v)->red.length    = (r); (v)->red.offset = (b) + (g);  \
+})
+
+/* set the RGBT bitfields of fb_var_screeninf according to
+ * var->bits_per_pixel and given depth
+ */
+static void pxafb_set_pixfmt(struct fb_var_screeninfo *var, int depth)
+{
+       if (depth == 0)
+               depth = var->bits_per_pixel;
+
+       if (var->bits_per_pixel < 16) {
+               /* indexed pixel formats */
+               var->red.offset    = 0; var->red.length    = 8;
+               var->green.offset  = 0; var->green.length  = 8;
+               var->blue.offset   = 0; var->blue.length   = 8;
+               var->transp.offset = 0; var->transp.length = 8;
+       }
+
+       switch (depth) {
+       case 16: var->transp.length ?
+                SET_PIXFMT(var, 5, 5, 5, 1) :          /* RGBT555 */
+                SET_PIXFMT(var, 5, 6, 5, 0); break;    /* RGB565 */
+       case 18: SET_PIXFMT(var, 6, 6, 6, 0); break;    /* RGB666 */
+       case 19: SET_PIXFMT(var, 6, 6, 6, 1); break;    /* RGBT666 */
+       case 24: var->transp.length ?
+                SET_PIXFMT(var, 8, 8, 7, 1) :          /* RGBT887 */
+                SET_PIXFMT(var, 8, 8, 8, 0); break;    /* RGB888 */
+       case 25: SET_PIXFMT(var, 8, 8, 8, 1); break;    /* RGBT888 */
+       }
 }
 
 #ifdef CONFIG_CPU_FREQ
@@ -204,17 +348,103 @@ static int pxafb_bpp_to_lccr3(struct fb_var_screeninfo *var)
  */
 static unsigned int pxafb_display_dma_period(struct fb_var_screeninfo *var)
 {
-       /*
-        * Period = pixclock * bits_per_byte * bytes_per_transfer
-        *              / memory_bits_per_pixel;
-        */
-       return var->pixclock * 8 * 16 / var->bits_per_pixel;
+       /*
+        * Period = pixclock * bits_per_byte * bytes_per_transfer
+        *              / memory_bits_per_pixel;
+        */
+       return var->pixclock * 8 * 16 / var->bits_per_pixel;
 }
-
-extern unsigned int get_clk_frequency_khz(int info);
 #endif
 
 /*
+ * Select the smallest mode that allows the desired resolution to be
+ * displayed. If desired parameters can be rounded up.
+ */
+static struct pxafb_mode_info *pxafb_getmode(struct pxafb_mach_info *mach,
+                                            struct fb_var_screeninfo *var)
+{
+       struct pxafb_mode_info *mode = NULL;
+       struct pxafb_mode_info *modelist = mach->modes;
+       unsigned int best_x = 0xffffffff, best_y = 0xffffffff;
+       unsigned int i;
+
+       for (i = 0; i < mach->num_modes; i++) {
+               if (modelist[i].xres >= var->xres &&
+                   modelist[i].yres >= var->yres &&
+                   modelist[i].xres < best_x &&
+                   modelist[i].yres < best_y &&
+                   modelist[i].bpp >= var->bits_per_pixel) {
+                       best_x = modelist[i].xres;
+                       best_y = modelist[i].yres;
+                       mode = &modelist[i];
+               }
+       }
+
+       return mode;
+}
+
+static void pxafb_setmode(struct fb_var_screeninfo *var,
+                         struct pxafb_mode_info *mode)
+{
+       var->xres               = mode->xres;
+       var->yres               = mode->yres;
+       var->bits_per_pixel     = mode->bpp;
+       var->pixclock           = mode->pixclock;
+       var->hsync_len          = mode->hsync_len;
+       var->left_margin        = mode->left_margin;
+       var->right_margin       = mode->right_margin;
+       var->vsync_len          = mode->vsync_len;
+       var->upper_margin       = mode->upper_margin;
+       var->lower_margin       = mode->lower_margin;
+       var->sync               = mode->sync;
+       var->grayscale          = mode->cmap_greyscale;
+       var->transp.length      = mode->transparency;
+
+       /* set the initial RGBA bitfields */
+       pxafb_set_pixfmt(var, mode->depth);
+}
+
+static int pxafb_adjust_timing(struct pxafb_info *fbi,
+                              struct fb_var_screeninfo *var)
+{
+       int line_length;
+
+       var->xres = max_t(int, var->xres, MIN_XRES);
+       var->yres = max_t(int, var->yres, MIN_YRES);
+
+       if (!(fbi->lccr0 & LCCR0_LCDT)) {
+               clamp_val(var->hsync_len, 1, 64);
+               clamp_val(var->vsync_len, 1, 64);
+               clamp_val(var->left_margin,  1, 255);
+               clamp_val(var->right_margin, 1, 255);
+               clamp_val(var->upper_margin, 1, 255);
+               clamp_val(var->lower_margin, 1, 255);
+       }
+
+       /* make sure each line is aligned on word boundary */
+       line_length = var->xres * var->bits_per_pixel / 8;
+       line_length = ALIGN(line_length, 4);
+       var->xres = line_length * 8 / var->bits_per_pixel;
+
+       /* we don't support xpan, force xres_virtual to be equal to xres */
+       var->xres_virtual = var->xres;
+
+       if (var->accel_flags & FB_ACCELF_TEXT)
+               var->yres_virtual = fbi->fb.fix.smem_len / line_length;
+       else
+               var->yres_virtual = max(var->yres_virtual, var->yres);
+
+       /* check for limits */
+       if (var->xres > MAX_XRES || var->yres > MAX_YRES)
+               return -EINVAL;
+
+       if (var->yres > var->yres_virtual)
+               return -EINVAL;
+
+       return 0;
+}
+
+/*
  *  pxafb_check_var():
  *    Get the video params out of 'var'. If a value doesn't fit, round it up,
  *    if it's too big, return -EINVAL.
@@ -226,54 +456,37 @@ extern unsigned int get_clk_frequency_khz(int info);
 static int pxafb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
 {
        struct pxafb_info *fbi = (struct pxafb_info *)info;
+       struct pxafb_mach_info *inf = fbi->dev->platform_data;
+       int err;
 
-       if (var->xres < MIN_XRES)
-               var->xres = MIN_XRES;
-       if (var->yres < MIN_YRES)
-               var->yres = MIN_YRES;
-       if (var->xres > fbi->max_xres)
-               var->xres = fbi->max_xres;
-       if (var->yres > fbi->max_yres)
-               var->yres = fbi->max_yres;
-       var->xres_virtual =
-               max(var->xres_virtual, var->xres);
-       var->yres_virtual =
-               max(var->yres_virtual, var->yres);
-
-        /*
-        * Setup the RGB parameters for this display.
-        *
-        * The pixel packing format is described on page 7-11 of the
-        * PXA2XX Developer's Manual.
-         */
-       if (var->bits_per_pixel == 16) {
-               var->red.offset   = 11; var->red.length   = 5;
-               var->green.offset = 5;  var->green.length = 6;
-               var->blue.offset  = 0;  var->blue.length  = 5;
-               var->transp.offset = var->transp.length = 0;
-       } else {
-               var->red.offset = var->green.offset = var->blue.offset = var->transp.offset = 0;
-               var->red.length   = 8;
-               var->green.length = 8;
-               var->blue.length  = 8;
-               var->transp.length = 0;
+       if (inf->fixed_modes) {
+               struct pxafb_mode_info *mode;
+
+               mode = pxafb_getmode(inf, var);
+               if (!mode)
+                       return -EINVAL;
+               pxafb_setmode(var, mode);
        }
 
+       /* do a test conversion to BPP fields to check the color formats */
+       err = pxafb_var_to_bpp(var);
+       if (err < 0)
+               return err;
+
+       pxafb_set_pixfmt(var, var_to_depth(var));
+
+       err = pxafb_adjust_timing(fbi, var);
+       if (err)
+               return err;
+
 #ifdef CONFIG_CPU_FREQ
-       DPRINTK("dma period = %d ps, clock = %d kHz\n",
-               pxafb_display_dma_period(var),
-               get_clk_frequency_khz(0));
+       pr_debug("pxafb: dma period = %d ps\n",
+                pxafb_display_dma_period(var));
 #endif
 
        return 0;
 }
 
-static inline void pxafb_set_truecolor(u_int is_true_color)
-{
-       DPRINTK("true_color = %d\n", is_true_color);
-       // do your machine-specific setup if needed
-}
-
 /*
  * pxafb_set_par():
  *     Set the user defined part of the display for the specified console
@@ -282,11 +495,8 @@ static int pxafb_set_par(struct fb_info *info)
 {
        struct pxafb_info *fbi = (struct pxafb_info *)info;
        struct fb_var_screeninfo *var = &info->var;
-       unsigned long palette_mem_size;
-
-       DPRINTK("set_par\n");
 
-       if (var->bits_per_pixel == 16)
+       if (var->bits_per_pixel >= 16)
                fbi->fb.fix.visual = FB_VISUAL_TRUECOLOR;
        else if (!fbi->cmap_static)
                fbi->fb.fix.visual = FB_VISUAL_PSEUDOCOLOR;
@@ -301,24 +511,15 @@ static int pxafb_set_par(struct fb_info *info)
 
        fbi->fb.fix.line_length = var->xres_virtual *
                                  var->bits_per_pixel / 8;
-       if (var->bits_per_pixel == 16)
+       if (var->bits_per_pixel >= 16)
                fbi->palette_size = 0;
        else
-               fbi->palette_size = var->bits_per_pixel == 1 ? 4 : 1 << var->bits_per_pixel;
-
-       palette_mem_size = fbi->palette_size * sizeof(u16);
-
-       DPRINTK("palette_mem_size = 0x%08lx\n", (u_long) palette_mem_size);
+               fbi->palette_size = var->bits_per_pixel == 1 ?
+                                       4 : 1 << var->bits_per_pixel;
 
-       fbi->palette_cpu = (u16 *)(fbi->map_cpu + PAGE_SIZE - palette_mem_size);
-       fbi->palette_dma = fbi->map_dma + PAGE_SIZE - palette_mem_size;
+       fbi->palette_cpu = (u16 *)&fbi->dma_buff->palette[0];
 
-       /*
-        * Set (any) board control register to handle new color depth
-        */
-       pxafb_set_truecolor(fbi->fb.fix.visual == FB_VISUAL_TRUECOLOR);
-
-       if (fbi->fb.var.bits_per_pixel == 16)
+       if (fbi->fb.var.bits_per_pixel >= 16)
                fb_dealloc_cmap(&fbi->fb.cmap);
        else
                fb_alloc_cmap(&fbi->fb.cmap, 1<<fbi->fb.var.bits_per_pixel, 0);
@@ -328,35 +529,33 @@ static int pxafb_set_par(struct fb_info *info)
        return 0;
 }
 
-/*
- * Formal definition of the VESA spec:
- *  On
- *     This refers to the state of the display when it is in full operation
- *  Stand-By
- *     This defines an optional operating state of minimal power reduction with
- *     the shortest recovery time
- *  Suspend
- *     This refers to a level of power management in which substantial power
- *     reduction is achieved by the display.  The display can have a longer
- *     recovery time from this state than from the Stand-by state
- *  Off
- *     This indicates that the display is consuming the lowest level of power
- *     and is non-operational. Recovery from this state may optionally require
- *     the user to manually power on the monitor
- *
- *  Now, the fbdev driver adds an additional state, (blank), where they
- *  turn off the video (maybe by colormap tricks), but don't mess with the
- *  video itself: think of it semantically between on and Stand-By.
- *
- *  So here's what we should do in our fbdev blank routine:
- *
- *     VESA_NO_BLANKING (mode 0)       Video on,  front/back light on
- *     VESA_VSYNC_SUSPEND (mode 1)     Video on,  front/back light off
- *     VESA_HSYNC_SUSPEND (mode 2)     Video on,  front/back light off
- *     VESA_POWERDOWN (mode 3)         Video off, front/back light off
- *
- *  This will match the matrox implementation.
- */
+static int pxafb_pan_display(struct fb_var_screeninfo *var,
+                            struct fb_info *info)
+{
+       struct pxafb_info *fbi = (struct pxafb_info *)info;
+       struct fb_var_screeninfo newvar;
+       int dma = DMA_MAX + DMA_BASE;
+
+       if (fbi->state != C_ENABLE)
+               return 0;
+
+       /* Only take .xoffset, .yoffset and .vmode & FB_VMODE_YWRAP from what
+        * was passed in and copy the rest from the old screeninfo.
+        */
+       memcpy(&newvar, &fbi->fb.var, sizeof(newvar));
+       newvar.xoffset = var->xoffset;
+       newvar.yoffset = var->yoffset;
+       newvar.vmode &= ~FB_VMODE_YWRAP;
+       newvar.vmode |= var->vmode & FB_VMODE_YWRAP;
+
+       setup_base_frame(fbi, &newvar, 1);
+
+       if (fbi->lccr0 & LCCR0_SDS)
+               lcd_writel(fbi, FBR1, fbi->fdadr[dma + 1] | 0x1);
+
+       lcd_writel(fbi, FBR0, fbi->fdadr[dma] | 0x1);
+       return 0;
+}
 
 /*
  * pxafb_blank():
@@ -369,8 +568,6 @@ static int pxafb_blank(int blank, struct fb_info *info)
        struct pxafb_info *fbi = (struct pxafb_info *)info;
        int i;
 
-       DPRINTK("pxafb_blank: blank=%d\n", blank);
-
        switch (blank) {
        case FB_BLANK_POWERDOWN:
        case FB_BLANK_VSYNC_SUSPEND:
@@ -382,11 +579,11 @@ static int pxafb_blank(int blank, struct fb_info *info)
                                pxafb_setpalettereg(i, 0, 0, 0, 0, info);
 
                pxafb_schedule_work(fbi, C_DISABLE);
-               //TODO if (pxafb_blank_helper) pxafb_blank_helper(blank);
+               /* TODO if (pxafb_blank_helper) pxafb_blank_helper(blank); */
                break;
 
        case FB_BLANK_UNBLANK:
-               //TODO if (pxafb_blank_helper) pxafb_blank_helper(blank);
+               /* TODO if (pxafb_blank_helper) pxafb_blank_helper(blank); */
                if (fbi->fb.fix.visual == FB_VISUAL_PSEUDOCOLOR ||
                    fbi->fb.fix.visual == FB_VISUAL_STATIC_PSEUDOCOLOR)
                        fb_set_cmap(&fbi->fb.cmap, info);
@@ -395,33 +592,358 @@ static int pxafb_blank(int blank, struct fb_info *info)
        return 0;
 }
 
-static int pxafb_mmap(struct fb_info *info, struct file *file,
-                     struct vm_area_struct *vma)
-{
-       struct pxafb_info *fbi = (struct pxafb_info *)info;
-       unsigned long off = vma->vm_pgoff << PAGE_SHIFT;
-
-       if (off < info->fix.smem_len) {
-               vma->vm_pgoff += 1;
-               return dma_mmap_writecombine(fbi->dev, vma, fbi->map_cpu,
-                                            fbi->map_dma, fbi->map_size);
-       }
-       return -EINVAL;
-}
-
 static struct fb_ops pxafb_ops = {
        .owner          = THIS_MODULE,
        .fb_check_var   = pxafb_check_var,
        .fb_set_par     = pxafb_set_par,
+       .fb_pan_display = pxafb_pan_display,
        .fb_setcolreg   = pxafb_setcolreg,
        .fb_fillrect    = cfb_fillrect,
        .fb_copyarea    = cfb_copyarea,
        .fb_imageblit   = cfb_imageblit,
        .fb_blank       = pxafb_blank,
-       .fb_cursor      = soft_cursor,
-       .fb_mmap        = pxafb_mmap,
 };
 
+#ifdef CONFIG_FB_PXA_OVERLAY
+static void overlay1fb_setup(struct pxafb_layer *ofb)
+{
+       int size = ofb->fb.fix.line_length * ofb->fb.var.yres_virtual;
+       unsigned long start = ofb->video_mem_phys;
+       setup_frame_dma(ofb->fbi, DMA_OV1, PAL_NONE, start, size);
+}
+
+/* Depending on the enable status of overlay1/2, the DMA should be
+ * updated from FDADRx (when disabled) or FBRx (when enabled).
+ */
+static void overlay1fb_enable(struct pxafb_layer *ofb)
+{
+       int enabled = lcd_readl(ofb->fbi, OVL1C1) & OVLxC1_OEN;
+       uint32_t fdadr1 = ofb->fbi->fdadr[DMA_OV1] | (enabled ? 0x1 : 0);
+
+       lcd_writel(ofb->fbi, enabled ? FBR1 : FDADR1, fdadr1);
+       lcd_writel(ofb->fbi, OVL1C2, ofb->control[1]);
+       lcd_writel(ofb->fbi, OVL1C1, ofb->control[0] | OVLxC1_OEN);
+}
+
+static void overlay1fb_disable(struct pxafb_layer *ofb)
+{
+       uint32_t lccr5 = lcd_readl(ofb->fbi, LCCR5);
+
+       lcd_writel(ofb->fbi, OVL1C1, ofb->control[0] & ~OVLxC1_OEN);
+
+       lcd_writel(ofb->fbi, LCSR1, LCSR1_BS(1));
+       lcd_writel(ofb->fbi, LCCR5, lccr5 & ~LCSR1_BS(1));
+       lcd_writel(ofb->fbi, FBR1, ofb->fbi->fdadr[DMA_OV1] | 0x3);
+
+       if (wait_for_completion_timeout(&ofb->branch_done, 1 * HZ) == 0)
+               pr_warning("%s: timeout disabling overlay1\n", __func__);
+
+       lcd_writel(ofb->fbi, LCCR5, lccr5);
+}
+
+static void overlay2fb_setup(struct pxafb_layer *ofb)
+{
+       int size, div = 1, pfor = NONSTD_TO_PFOR(ofb->fb.var.nonstd);
+       unsigned long start[3] = { ofb->video_mem_phys, 0, 0 };
+
+       if (pfor == OVERLAY_FORMAT_RGB || pfor == OVERLAY_FORMAT_YUV444_PACKED) {
+               size = ofb->fb.fix.line_length * ofb->fb.var.yres_virtual;
+               setup_frame_dma(ofb->fbi, DMA_OV2_Y, -1, start[0], size);
+       } else {
+               size = ofb->fb.var.xres_virtual * ofb->fb.var.yres_virtual;
+               switch (pfor) {
+               case OVERLAY_FORMAT_YUV444_PLANAR: div = 1; break;
+               case OVERLAY_FORMAT_YUV422_PLANAR: div = 2; break;
+               case OVERLAY_FORMAT_YUV420_PLANAR: div = 4; break;
+               }
+               start[1] = start[0] + size;
+               start[2] = start[1] + size / div;
+               setup_frame_dma(ofb->fbi, DMA_OV2_Y,  -1, start[0], size);
+               setup_frame_dma(ofb->fbi, DMA_OV2_Cb, -1, start[1], size / div);
+               setup_frame_dma(ofb->fbi, DMA_OV2_Cr, -1, start[2], size / div);
+       }
+}
+
+static void overlay2fb_enable(struct pxafb_layer *ofb)
+{
+       int pfor = NONSTD_TO_PFOR(ofb->fb.var.nonstd);
+       int enabled = lcd_readl(ofb->fbi, OVL2C1) & OVLxC1_OEN;
+       uint32_t fdadr2 = ofb->fbi->fdadr[DMA_OV2_Y]  | (enabled ? 0x1 : 0);
+       uint32_t fdadr3 = ofb->fbi->fdadr[DMA_OV2_Cb] | (enabled ? 0x1 : 0);
+       uint32_t fdadr4 = ofb->fbi->fdadr[DMA_OV2_Cr] | (enabled ? 0x1 : 0);
+
+       if (pfor == OVERLAY_FORMAT_RGB || pfor == OVERLAY_FORMAT_YUV444_PACKED)
+               lcd_writel(ofb->fbi, enabled ? FBR2 : FDADR2, fdadr2);
+       else {
+               lcd_writel(ofb->fbi, enabled ? FBR2 : FDADR2, fdadr2);
+               lcd_writel(ofb->fbi, enabled ? FBR3 : FDADR3, fdadr3);
+               lcd_writel(ofb->fbi, enabled ? FBR4 : FDADR4, fdadr4);
+       }
+       lcd_writel(ofb->fbi, OVL2C2, ofb->control[1]);
+       lcd_writel(ofb->fbi, OVL2C1, ofb->control[0] | OVLxC1_OEN);
+}
+
+static void overlay2fb_disable(struct pxafb_layer *ofb)
+{
+       uint32_t lccr5 = lcd_readl(ofb->fbi, LCCR5);
+
+       lcd_writel(ofb->fbi, OVL2C1, ofb->control[0] & ~OVLxC1_OEN);
+
+       lcd_writel(ofb->fbi, LCSR1, LCSR1_BS(2));
+       lcd_writel(ofb->fbi, LCCR5, lccr5 & ~LCSR1_BS(2));
+       lcd_writel(ofb->fbi, FBR2, ofb->fbi->fdadr[DMA_OV2_Y]  | 0x3);
+       lcd_writel(ofb->fbi, FBR3, ofb->fbi->fdadr[DMA_OV2_Cb] | 0x3);
+       lcd_writel(ofb->fbi, FBR4, ofb->fbi->fdadr[DMA_OV2_Cr] | 0x3);
+
+       if (wait_for_completion_timeout(&ofb->branch_done, 1 * HZ) == 0)
+               pr_warning("%s: timeout disabling overlay2\n", __func__);
+}
+
+static struct pxafb_layer_ops ofb_ops[] = {
+       [0] = {
+               .enable         = overlay1fb_enable,
+               .disable        = overlay1fb_disable,
+               .setup          = overlay1fb_setup,
+       },
+       [1] = {
+               .enable         = overlay2fb_enable,
+               .disable        = overlay2fb_disable,
+               .setup          = overlay2fb_setup,
+       },
+};
+
+static int overlayfb_open(struct fb_info *info, int user)
+{
+       struct pxafb_layer *ofb = (struct pxafb_layer *)info;
+
+       /* no support for framebuffer console on overlay */
+       if (user == 0)
+               return -ENODEV;
+
+       /* allow only one user at a time */
+       if (atomic_inc_and_test(&ofb->usage))
+               return -EBUSY;
+
+       /* unblank the base framebuffer */
+       fb_blank(&ofb->fbi->fb, FB_BLANK_UNBLANK);
+       return 0;
+}
+
+static int overlayfb_release(struct fb_info *info, int user)
+{
+       struct pxafb_layer *ofb = (struct pxafb_layer*) info;
+
+       atomic_dec(&ofb->usage);
+       ofb->ops->disable(ofb);
+
+       free_pages_exact(ofb->video_mem, ofb->video_mem_size);
+       ofb->video_mem = NULL;
+       ofb->video_mem_size = 0;
+       return 0;
+}
+
+static int overlayfb_check_var(struct fb_var_screeninfo *var,
+                              struct fb_info *info)
+{
+       struct pxafb_layer *ofb = (struct pxafb_layer *)info;
+       struct fb_var_screeninfo *base_var = &ofb->fbi->fb.var;
+       int xpos, ypos, pfor, bpp;
+
+       xpos = NONSTD_TO_XPOS(var->nonstd);
+       ypos = NONSTD_TO_XPOS(var->nonstd);
+       pfor = NONSTD_TO_PFOR(var->nonstd);
+
+       bpp = pxafb_var_to_bpp(var);
+       if (bpp < 0)
+               return -EINVAL;
+
+       /* no support for YUV format on overlay1 */
+       if (ofb->id == OVERLAY1 && pfor != 0)
+               return -EINVAL;
+
+       /* for YUV packed formats, bpp = 'minimum bpp of YUV components' */
+       switch (pfor) {
+       case OVERLAY_FORMAT_RGB:
+               bpp = pxafb_var_to_bpp(var);
+               if (bpp < 0)
+                       return -EINVAL;
+
+               pxafb_set_pixfmt(var, var_to_depth(var));
+               break;
+       case OVERLAY_FORMAT_YUV444_PACKED: bpp = 24; break;
+       case OVERLAY_FORMAT_YUV444_PLANAR: bpp = 8; break;
+       case OVERLAY_FORMAT_YUV422_PLANAR: bpp = 4; break;
+       case OVERLAY_FORMAT_YUV420_PLANAR: bpp = 2; break;
+       default:
+               return -EINVAL;
+       }
+
+       /* each line must start at a 32-bit word boundary */
+       if ((xpos * bpp) % 32)
+               return -EINVAL;
+
+       /* xres must align on 32-bit word boundary */
+       var->xres = roundup(var->xres * bpp, 32) / bpp;
+
+       if ((xpos + var->xres > base_var->xres) ||
+           (ypos + var->yres > base_var->yres))
+               return -EINVAL;
+
+       var->xres_virtual = var->xres;
+       var->yres_virtual = max(var->yres, var->yres_virtual);
+       return 0;
+}
+
+static int overlayfb_map_video_memory(struct pxafb_layer *ofb)
+{
+       struct fb_var_screeninfo *var = &ofb->fb.var;
+       int pfor = NONSTD_TO_PFOR(var->nonstd);
+       int size, bpp = 0;
+
+       switch (pfor) {
+       case OVERLAY_FORMAT_RGB: bpp = var->bits_per_pixel; break;
+       case OVERLAY_FORMAT_YUV444_PACKED: bpp = 24; break;
+       case OVERLAY_FORMAT_YUV444_PLANAR: bpp = 24; break;
+       case OVERLAY_FORMAT_YUV422_PLANAR: bpp = 16; break;
+       case OVERLAY_FORMAT_YUV420_PLANAR: bpp = 12; break;
+       }
+
+       ofb->fb.fix.line_length = var->xres_virtual * bpp / 8;
+
+       size = PAGE_ALIGN(ofb->fb.fix.line_length * var->yres_virtual);
+
+       /* don't re-allocate if the original video memory is enough */
+       if (ofb->video_mem) {
+               if (ofb->video_mem_size >= size)
+                       return 0;
+
+               free_pages_exact(ofb->video_mem, ofb->video_mem_size);
+       }
+
+       ofb->video_mem = alloc_pages_exact(size, GFP_KERNEL | __GFP_ZERO);
+       if (ofb->video_mem == NULL)
+               return -ENOMEM;
+
+       ofb->video_mem_phys = virt_to_phys(ofb->video_mem);
+       ofb->video_mem_size = size;
+
+       mutex_lock(&ofb->fb.mm_lock);
+       ofb->fb.fix.smem_start  = ofb->video_mem_phys;
+       ofb->fb.fix.smem_len    = ofb->fb.fix.line_length * var->yres_virtual;
+       mutex_unlock(&ofb->fb.mm_lock);
+       ofb->fb.screen_base     = ofb->video_mem;
+       return 0;
+}
+
+static int overlayfb_set_par(struct fb_info *info)
+{
+       struct pxafb_layer *ofb = (struct pxafb_layer *)info;
+       struct fb_var_screeninfo *var = &info->var;
+       int xpos, ypos, pfor, bpp, ret;
+
+       ret = overlayfb_map_video_memory(ofb);
+       if (ret)
+               return ret;
+
+       bpp  = pxafb_var_to_bpp(var);
+       xpos = NONSTD_TO_XPOS(var->nonstd);
+       ypos = NONSTD_TO_XPOS(var->nonstd);
+       pfor = NONSTD_TO_PFOR(var->nonstd);
+
+       ofb->control[0] = OVLxC1_PPL(var->xres) | OVLxC1_LPO(var->yres) |
+                         OVLxC1_BPP(bpp);
+       ofb->control[1] = OVLxC2_XPOS(xpos) | OVLxC2_YPOS(ypos);
+
+       if (ofb->id == OVERLAY2)
+               ofb->control[1] |= OVL2C2_PFOR(pfor);
+
+       ofb->ops->setup(ofb);
+       ofb->ops->enable(ofb);
+       return 0;
+}
+
+static struct fb_ops overlay_fb_ops = {
+       .owner                  = THIS_MODULE,
+       .fb_open                = overlayfb_open,
+       .fb_release             = overlayfb_release,
+       .fb_check_var           = overlayfb_check_var,
+       .fb_set_par             = overlayfb_set_par,
+};
+
+static void __devinit init_pxafb_overlay(struct pxafb_info *fbi,
+                                        struct pxafb_layer *ofb, int id)
+{
+       sprintf(ofb->fb.fix.id, "overlay%d", id + 1);
+
+       ofb->fb.fix.type                = FB_TYPE_PACKED_PIXELS;
+       ofb->fb.fix.xpanstep            = 0;
+       ofb->fb.fix.ypanstep            = 1;
+
+       ofb->fb.var.activate            = FB_ACTIVATE_NOW;
+       ofb->fb.var.height              = -1;
+       ofb->fb.var.width               = -1;
+       ofb->fb.var.vmode               = FB_VMODE_NONINTERLACED;
+
+       ofb->fb.fbops                   = &overlay_fb_ops;
+       ofb->fb.flags                   = FBINFO_FLAG_DEFAULT;
+       ofb->fb.node                    = -1;
+       ofb->fb.pseudo_palette          = NULL;
+
+       ofb->id = id;
+       ofb->ops = &ofb_ops[id];
+       atomic_set(&ofb->usage, 0);
+       ofb->fbi = fbi;
+       init_completion(&ofb->branch_done);
+}
+
+static inline int pxafb_overlay_supported(void)
+{
+       if (cpu_is_pxa27x() || cpu_is_pxa3xx())
+               return 1;
+
+       return 0;
+}
+
+static int __devinit pxafb_overlay_init(struct pxafb_info *fbi)
+{
+       int i, ret;
+
+       if (!pxafb_overlay_supported())
+               return 0;
+
+       for (i = 0; i < 2; i++) {
+               init_pxafb_overlay(fbi, &fbi->overlay[i], i);
+               ret = register_framebuffer(&fbi->overlay[i].fb);
+               if (ret) {
+                       dev_err(fbi->dev, "failed to register overlay %d\n", i);
+                       return ret;
+               }
+       }
+
+       /* mask all IU/BS/EOF/SOF interrupts */
+       lcd_writel(fbi, LCCR5, ~0);
+
+       /* place overlay(s) on top of base */
+       fbi->lccr0 |= LCCR0_OUC;
+       pr_info("PXA Overlay driver loaded successfully!\n");
+       return 0;
+}
+
+static void __devexit pxafb_overlay_exit(struct pxafb_info *fbi)
+{
+       int i;
+
+       if (!pxafb_overlay_supported())
+               return;
+
+       for (i = 0; i < 2; i++)
+               unregister_framebuffer(&fbi->overlay[i].fb);
+}
+#else
+static inline void pxafb_overlay_init(struct pxafb_info *fbi) {}
+static inline void pxafb_overlay_exit(struct pxafb_info *fbi) {}
+#endif /* CONFIG_FB_PXA_OVERLAY */
+
 /*
  * Calculate the PCD value from the clock rate (in picoseconds).
  * We take account of the PPCR clock setting.
@@ -452,86 +974,327 @@ static struct fb_ops pxafb_ops = {
  *
  * Factoring the 10^4 and 10^-12 out gives 10^-8 == 1 / 100000000 as used below.
  */
-static inline unsigned int get_pcd(unsigned int pixclock)
+static inline unsigned int get_pcd(struct pxafb_info *fbi,
+                                  unsigned int pixclock)
 {
        unsigned long long pcd;
 
-       /* FIXME: Need to take into account Double Pixel Clock mode
-         * (DPC) bit? or perhaps set it based on the various clock
-         * speeds */
+       /* FIXME: Need to take into account Double Pixel Clock mode
+        * (DPC) bit? or perhaps set it based on the various clock
+        * speeds */
+       pcd = (unsigned long long)(clk_get_rate(fbi->clk) / 10000);
+       pcd *= pixclock;
+       do_div(pcd, 100000000 * 2);
+       /* no need for this, since we should subtract 1 anyway. they cancel */
+       /* pcd += 1; */ /* make up for integer math truncations */
+       return (unsigned int)pcd;
+}
+
+/*
+ * Some touchscreens need hsync information from the video driver to
+ * function correctly. We export it here.  Note that 'hsync_time' and
+ * the value returned from pxafb_get_hsync_time() is the *reciprocal*
+ * of the hsync period in seconds.
+ */
+static inline void set_hsync_time(struct pxafb_info *fbi, unsigned int pcd)
+{
+       unsigned long htime;
+
+       if ((pcd == 0) || (fbi->fb.var.hsync_len == 0)) {
+               fbi->hsync_time = 0;
+               return;
+       }
+
+       htime = clk_get_rate(fbi->clk) / (pcd * fbi->fb.var.hsync_len);
+
+       fbi->hsync_time = htime;
+}
+
+unsigned long pxafb_get_hsync_time(struct device *dev)
+{
+       struct pxafb_info *fbi = dev_get_drvdata(dev);
+
+       /* If display is blanked/suspended, hsync isn't active */
+       if (!fbi || (fbi->state != C_ENABLE))
+               return 0;
+
+       return fbi->hsync_time;
+}
+EXPORT_SYMBOL(pxafb_get_hsync_time);
+
+static int setup_frame_dma(struct pxafb_info *fbi, int dma, int pal,
+                          unsigned long start, size_t size)
+{
+       struct pxafb_dma_descriptor *dma_desc, *pal_desc;
+       unsigned int dma_desc_off, pal_desc_off;
+
+       if (dma < 0 || dma >= DMA_MAX * 2)
+               return -EINVAL;
+
+       dma_desc = &fbi->dma_buff->dma_desc[dma];
+       dma_desc_off = offsetof(struct pxafb_dma_buff, dma_desc[dma]);
+
+       dma_desc->fsadr = start;
+       dma_desc->fidr  = 0;
+       dma_desc->ldcmd = size;
+
+       if (pal < 0 || pal >= PAL_MAX * 2) {
+               dma_desc->fdadr = fbi->dma_buff_phys + dma_desc_off;
+               fbi->fdadr[dma] = fbi->dma_buff_phys + dma_desc_off;
+       } else {
+               pal_desc = &fbi->dma_buff->pal_desc[pal];
+               pal_desc_off = offsetof(struct pxafb_dma_buff, pal_desc[pal]);
+
+               pal_desc->fsadr = fbi->dma_buff_phys + pal * PALETTE_SIZE;
+               pal_desc->fidr  = 0;
+
+               if ((fbi->lccr4 & LCCR4_PAL_FOR_MASK) == LCCR4_PAL_FOR_0)
+                       pal_desc->ldcmd = fbi->palette_size * sizeof(u16);
+               else
+                       pal_desc->ldcmd = fbi->palette_size * sizeof(u32);
+
+               pal_desc->ldcmd |= LDCMD_PAL;
+
+               /* flip back and forth between palette and frame buffer */
+               pal_desc->fdadr = fbi->dma_buff_phys + dma_desc_off;
+               dma_desc->fdadr = fbi->dma_buff_phys + pal_desc_off;
+               fbi->fdadr[dma] = fbi->dma_buff_phys + dma_desc_off;
+       }
+
+       return 0;
+}
+
+static void setup_base_frame(struct pxafb_info *fbi,
+                             struct fb_var_screeninfo *var,
+                             int branch)
+{
+       struct fb_fix_screeninfo *fix = &fbi->fb.fix;
+       int nbytes, dma, pal, bpp = var->bits_per_pixel;
+       unsigned long offset;
+
+       dma = DMA_BASE + (branch ? DMA_MAX : 0);
+       pal = (bpp >= 16) ? PAL_NONE : PAL_BASE + (branch ? PAL_MAX : 0);
+
+       nbytes = fix->line_length * var->yres;
+       offset = fix->line_length * var->yoffset + fbi->video_mem_phys;
+
+       if (fbi->lccr0 & LCCR0_SDS) {
+               nbytes = nbytes / 2;
+               setup_frame_dma(fbi, dma + 1, PAL_NONE, offset + nbytes, nbytes);
+       }
+
+       setup_frame_dma(fbi, dma, pal, offset, nbytes);
+}
+
+#ifdef CONFIG_FB_PXA_SMARTPANEL
+static int setup_smart_dma(struct pxafb_info *fbi)
+{
+       struct pxafb_dma_descriptor *dma_desc;
+       unsigned long dma_desc_off, cmd_buff_off;
+
+       dma_desc = &fbi->dma_buff->dma_desc[DMA_CMD];
+       dma_desc_off = offsetof(struct pxafb_dma_buff, dma_desc[DMA_CMD]);
+       cmd_buff_off = offsetof(struct pxafb_dma_buff, cmd_buff);
+
+       dma_desc->fdadr = fbi->dma_buff_phys + dma_desc_off;
+       dma_desc->fsadr = fbi->dma_buff_phys + cmd_buff_off;
+       dma_desc->fidr  = 0;
+       dma_desc->ldcmd = fbi->n_smart_cmds * sizeof(uint16_t);
+
+       fbi->fdadr[DMA_CMD] = dma_desc->fdadr;
+       return 0;
+}
+
+int pxafb_smart_flush(struct fb_info *info)
+{
+       struct pxafb_info *fbi = container_of(info, struct pxafb_info, fb);
+       uint32_t prsr;
+       int ret = 0;
+
+       /* disable controller until all registers are set up */
+       lcd_writel(fbi, LCCR0, fbi->reg_lccr0 & ~LCCR0_ENB);
+
+       /* 1. make it an even number of commands to align on 32-bit boundary
+        * 2. add the interrupt command to the end of the chain so we can
+        *    keep track of the end of the transfer
+        */
+
+       while (fbi->n_smart_cmds & 1)
+               fbi->smart_cmds[fbi->n_smart_cmds++] = SMART_CMD_NOOP;
+
+       fbi->smart_cmds[fbi->n_smart_cmds++] = SMART_CMD_INTERRUPT;
+       fbi->smart_cmds[fbi->n_smart_cmds++] = SMART_CMD_WAIT_FOR_VSYNC;
+       setup_smart_dma(fbi);
+
+       /* continue to execute next command */
+       prsr = lcd_readl(fbi, PRSR) | PRSR_ST_OK | PRSR_CON_NT;
+       lcd_writel(fbi, PRSR, prsr);
+
+       /* stop the processor in case it executed "wait for sync" cmd */
+       lcd_writel(fbi, CMDCR, 0x0001);
+
+       /* don't send interrupts for fifo underruns on channel 6 */
+       lcd_writel(fbi, LCCR5, LCCR5_IUM(6));
+
+       lcd_writel(fbi, LCCR1, fbi->reg_lccr1);
+       lcd_writel(fbi, LCCR2, fbi->reg_lccr2);
+       lcd_writel(fbi, LCCR3, fbi->reg_lccr3);
+       lcd_writel(fbi, LCCR4, fbi->reg_lccr4);
+       lcd_writel(fbi, FDADR0, fbi->fdadr[0]);
+       lcd_writel(fbi, FDADR6, fbi->fdadr[6]);
+
+       /* begin sending */
+       lcd_writel(fbi, LCCR0, fbi->reg_lccr0 | LCCR0_ENB);
+
+       if (wait_for_completion_timeout(&fbi->command_done, HZ/2) == 0) {
+               pr_warning("%s: timeout waiting for command done\n",
+                               __func__);
+               ret = -ETIMEDOUT;
+       }
+
+       /* quick disable */
+       prsr = lcd_readl(fbi, PRSR) & ~(PRSR_ST_OK | PRSR_CON_NT);
+       lcd_writel(fbi, PRSR, prsr);
+       lcd_writel(fbi, LCCR0, fbi->reg_lccr0 & ~LCCR0_ENB);
+       lcd_writel(fbi, FDADR6, 0);
+       fbi->n_smart_cmds = 0;
+       return ret;
+}
+
+int pxafb_smart_queue(struct fb_info *info, uint16_t *cmds, int n_cmds)
+{
+       int i;
+       struct pxafb_info *fbi = container_of(info, struct pxafb_info, fb);
+
+       for (i = 0; i < n_cmds; i++, cmds++) {
+               /* if it is a software delay, flush and delay */
+               if ((*cmds & 0xff00) == SMART_CMD_DELAY) {
+                       pxafb_smart_flush(info);
+                       mdelay(*cmds & 0xff);
+                       continue;
+               }
+
+               /* leave 2 commands for INTERRUPT and WAIT_FOR_SYNC */
+               if (fbi->n_smart_cmds == CMD_BUFF_SIZE - 8)
+                       pxafb_smart_flush(info);
+
+               fbi->smart_cmds[fbi->n_smart_cmds++] = *cmds;
+       }
+
+       return 0;
+}
+
+static unsigned int __smart_timing(unsigned time_ns, unsigned long lcd_clk)
+{
+       unsigned int t = (time_ns * (lcd_clk / 1000000) / 1000);
+       return (t == 0) ? 1 : t;
+}
+
+static void setup_smart_timing(struct pxafb_info *fbi,
+                               struct fb_var_screeninfo *var)
+{
+       struct pxafb_mach_info *inf = fbi->dev->platform_data;
+       struct pxafb_mode_info *mode = &inf->modes[0];
+       unsigned long lclk = clk_get_rate(fbi->clk);
+       unsigned t1, t2, t3, t4;
+
+       t1 = max(mode->a0csrd_set_hld, mode->a0cswr_set_hld);
+       t2 = max(mode->rd_pulse_width, mode->wr_pulse_width);
+       t3 = mode->op_hold_time;
+       t4 = mode->cmd_inh_time;
+
+       fbi->reg_lccr1 =
+               LCCR1_DisWdth(var->xres) |
+               LCCR1_BegLnDel(__smart_timing(t1, lclk)) |
+               LCCR1_EndLnDel(__smart_timing(t2, lclk)) |
+               LCCR1_HorSnchWdth(__smart_timing(t3, lclk));
+
+       fbi->reg_lccr2 = LCCR2_DisHght(var->yres);
+       fbi->reg_lccr3 = fbi->lccr3 | LCCR3_PixClkDiv(__smart_timing(t4, lclk));
+       fbi->reg_lccr3 |= (var->sync & FB_SYNC_HOR_HIGH_ACT) ? LCCR3_HSP : 0;
+       fbi->reg_lccr3 |= (var->sync & FB_SYNC_VERT_HIGH_ACT) ? LCCR3_VSP : 0;
+
+       /* FIXME: make this configurable */
+       fbi->reg_cmdcr = 1;
+}
+
+static int pxafb_smart_thread(void *arg)
+{
+       struct pxafb_info *fbi = arg;
+       struct pxafb_mach_info *inf = fbi->dev->platform_data;
+
+       if (!inf->smart_update) {
+               pr_err("%s: not properly initialized, thread terminated\n",
+                               __func__);
+               return -EINVAL;
+       }
+       inf = fbi->dev->platform_data;
+
+       pr_debug("%s(): task starting\n", __func__);
+
+       set_freezable();
+       while (!kthread_should_stop()) {
+
+               if (try_to_freeze())
+                       continue;
+
+               mutex_lock(&fbi->ctrlr_lock);
+
+               if (fbi->state == C_ENABLE) {
+                       inf->smart_update(&fbi->fb);
+                       complete(&fbi->refresh_done);
+               }
+
+               mutex_unlock(&fbi->ctrlr_lock);
 
-       pcd = (unsigned long long)get_lcdclk_frequency_10khz() * pixclock;
-       do_div(pcd, 100000000 * 2);
-       /* no need for this, since we should subtract 1 anyway. they cancel */
-       /* pcd += 1; */ /* make up for integer math truncations */
-       return (unsigned int)pcd;
+               set_current_state(TASK_INTERRUPTIBLE);
+               schedule_timeout(30 * HZ / 1000);
+       }
+
+       pr_debug("%s(): task ending\n", __func__);
+       return 0;
 }
 
-/*
- * pxafb_activate_var():
- *     Configures LCD Controller based on entries in var parameter.  Settings are
- *     only written to the controller if changes were made.
- */
-static int pxafb_activate_var(struct fb_var_screeninfo *var, struct pxafb_info *fbi)
+static int pxafb_smart_init(struct pxafb_info *fbi)
 {
-       struct pxafb_lcd_reg new_regs;
-       u_long flags;
-       u_int lines_per_panel, pcd = get_pcd(var->pixclock);
-
-       DPRINTK("Configuring PXA LCD\n");
-
-       DPRINTK("var: xres=%d hslen=%d lm=%d rm=%d\n",
-               var->xres, var->hsync_len,
-               var->left_margin, var->right_margin);
-       DPRINTK("var: yres=%d vslen=%d um=%d bm=%d\n",
-               var->yres, var->vsync_len,
-               var->upper_margin, var->lower_margin);
-       DPRINTK("var: pixclock=%d pcd=%d\n", var->pixclock, pcd);
-
-#if DEBUG_VAR
-       if (var->xres < 16        || var->xres > 1024)
-               printk(KERN_ERR "%s: invalid xres %d\n",
-                       fbi->fb.fix.id, var->xres);
-       switch(var->bits_per_pixel) {
-       case 1:
-       case 2:
-       case 4:
-       case 8:
-       case 16:
-               break;
-       default:
-               printk(KERN_ERR "%s: invalid bit depth %d\n",
-                      fbi->fb.fix.id, var->bits_per_pixel);
-               break;
+       if (!(fbi->lccr0 & LCCR0_LCDT))
+               return 0;
+
+       fbi->smart_cmds = (uint16_t *) fbi->dma_buff->cmd_buff;
+       fbi->n_smart_cmds = 0;
+
+       init_completion(&fbi->command_done);
+       init_completion(&fbi->refresh_done);
+
+       fbi->smart_thread = kthread_run(pxafb_smart_thread, fbi,
+                                       "lcd_refresh");
+       if (IS_ERR(fbi->smart_thread)) {
+               pr_err("%s: unable to create kernel thread\n", __func__);
+               return PTR_ERR(fbi->smart_thread);
        }
-       if (var->hsync_len < 1    || var->hsync_len > 64)
-               printk(KERN_ERR "%s: invalid hsync_len %d\n",
-                       fbi->fb.fix.id, var->hsync_len);
-       if (var->left_margin < 1  || var->left_margin > 255)
-               printk(KERN_ERR "%s: invalid left_margin %d\n",
-                       fbi->fb.fix.id, var->left_margin);
-       if (var->right_margin < 1 || var->right_margin > 255)
-               printk(KERN_ERR "%s: invalid right_margin %d\n",
-                       fbi->fb.fix.id, var->right_margin);
-       if (var->yres < 1         || var->yres > 1024)
-               printk(KERN_ERR "%s: invalid yres %d\n",
-                       fbi->fb.fix.id, var->yres);
-       if (var->vsync_len < 1    || var->vsync_len > 64)
-               printk(KERN_ERR "%s: invalid vsync_len %d\n",
-                       fbi->fb.fix.id, var->vsync_len);
-       if (var->upper_margin < 0 || var->upper_margin > 255)
-               printk(KERN_ERR "%s: invalid upper_margin %d\n",
-                       fbi->fb.fix.id, var->upper_margin);
-       if (var->lower_margin < 0 || var->lower_margin > 255)
-               printk(KERN_ERR "%s: invalid lower_margin %d\n",
-                       fbi->fb.fix.id, var->lower_margin);
-#endif
 
-       new_regs.lccr0 = fbi->lccr0 |
-               (LCCR0_LDM | LCCR0_SFM | LCCR0_IUM | LCCR0_EFM |
-                 LCCR0_QDM | LCCR0_BM  | LCCR0_OUM);
+       return 0;
+}
+#else
+int pxafb_smart_queue(struct fb_info *info, uint16_t *cmds, int n_cmds)
+{
+       return 0;
+}
+
+int pxafb_smart_flush(struct fb_info *info)
+{
+       return 0;
+}
+
+static inline int pxafb_smart_init(struct pxafb_info *fbi) { return 0; }
+#endif /* CONFIG_FB_PXA_SMARTPANEL */
+
+static void setup_parallel_timing(struct pxafb_info *fbi,
+                                 struct fb_var_screeninfo *var)
+{
+       unsigned int lines_per_panel, pcd = get_pcd(fbi, var->pixclock);
 
-       new_regs.lccr1 =
+       fbi->reg_lccr1 =
                LCCR1_DisWdth(var->xres) +
                LCCR1_HorSnchWdth(var->hsync_len) +
                LCCR1_BegLnDel(var->left_margin) +
@@ -545,101 +1308,67 @@ static int pxafb_activate_var(struct fb_var_screeninfo *var, struct pxafb_info *
        if ((fbi->lccr0 & LCCR0_SDS) == LCCR0_Dual)
                lines_per_panel /= 2;
 
-       new_regs.lccr2 =
+       fbi->reg_lccr2 =
                LCCR2_DisHght(lines_per_panel) +
                LCCR2_VrtSnchWdth(var->vsync_len) +
                LCCR2_BegFrmDel(var->upper_margin) +
                LCCR2_EndFrmDel(var->lower_margin);
 
-       new_regs.lccr3 = fbi->lccr3 |
-               pxafb_bpp_to_lccr3(var) |
-               (var->sync & FB_SYNC_HOR_HIGH_ACT ? LCCR3_HorSnchH : LCCR3_HorSnchL) |
-               (var->sync & FB_SYNC_VERT_HIGH_ACT ? LCCR3_VrtSnchH : LCCR3_VrtSnchL);
+       fbi->reg_lccr3 = fbi->lccr3 |
+               (var->sync & FB_SYNC_HOR_HIGH_ACT ?
+                LCCR3_HorSnchH : LCCR3_HorSnchL) |
+               (var->sync & FB_SYNC_VERT_HIGH_ACT ?
+                LCCR3_VrtSnchH : LCCR3_VrtSnchL);
 
-       if (pcd)
-               new_regs.lccr3 |= LCCR3_PixClkDiv(pcd);
+       if (pcd) {
+               fbi->reg_lccr3 |= LCCR3_PixClkDiv(pcd);
+               set_hsync_time(fbi, pcd);
+       }
+}
 
-       DPRINTK("nlccr0 = 0x%08x\n", new_regs.lccr0);
-       DPRINTK("nlccr1 = 0x%08x\n", new_regs.lccr1);
-       DPRINTK("nlccr2 = 0x%08x\n", new_regs.lccr2);
-       DPRINTK("nlccr3 = 0x%08x\n", new_regs.lccr3);
+/*
+ * pxafb_activate_var():
+ *     Configures LCD Controller based on entries in var parameter.
+ *     Settings are only written to the controller if changes were made.
+ */
+static int pxafb_activate_var(struct fb_var_screeninfo *var,
+                             struct pxafb_info *fbi)
+{
+       u_long flags;
 
        /* Update shadow copy atomically */
        local_irq_save(flags);
 
-       /* setup dma descriptors */
-       fbi->dmadesc_fblow_cpu = (struct pxafb_dma_descriptor *)((unsigned int)fbi->palette_cpu - 3*16);
-       fbi->dmadesc_fbhigh_cpu = (struct pxafb_dma_descriptor *)((unsigned int)fbi->palette_cpu - 2*16);
-       fbi->dmadesc_palette_cpu = (struct pxafb_dma_descriptor *)((unsigned int)fbi->palette_cpu - 1*16);
-
-       fbi->dmadesc_fblow_dma = fbi->palette_dma - 3*16;
-       fbi->dmadesc_fbhigh_dma = fbi->palette_dma - 2*16;
-       fbi->dmadesc_palette_dma = fbi->palette_dma - 1*16;
-
-#define BYTES_PER_PANEL (lines_per_panel * fbi->fb.fix.line_length)
-
-       /* populate descriptors */
-       fbi->dmadesc_fblow_cpu->fdadr = fbi->dmadesc_fblow_dma;
-       fbi->dmadesc_fblow_cpu->fsadr = fbi->screen_dma + BYTES_PER_PANEL;
-       fbi->dmadesc_fblow_cpu->fidr  = 0;
-       fbi->dmadesc_fblow_cpu->ldcmd = BYTES_PER_PANEL;
-
-       fbi->fdadr1 = fbi->dmadesc_fblow_dma; /* only used in dual-panel mode */
-
-       fbi->dmadesc_fbhigh_cpu->fsadr = fbi->screen_dma;
-       fbi->dmadesc_fbhigh_cpu->fidr = 0;
-       fbi->dmadesc_fbhigh_cpu->ldcmd = BYTES_PER_PANEL;
+#ifdef CONFIG_FB_PXA_SMARTPANEL
+       if (fbi->lccr0 & LCCR0_LCDT)
+               setup_smart_timing(fbi, var);
+       else
+#endif
+               setup_parallel_timing(fbi, var);
 
-       fbi->dmadesc_palette_cpu->fsadr = fbi->palette_dma;
-       fbi->dmadesc_palette_cpu->fidr  = 0;
-       fbi->dmadesc_palette_cpu->ldcmd = (fbi->palette_size * 2) | LDCMD_PAL;
+       setup_base_frame(fbi, var, 0);
 
-       if (var->bits_per_pixel == 16) {
-               /* palette shouldn't be loaded in true-color mode */
-               fbi->dmadesc_fbhigh_cpu->fdadr = fbi->dmadesc_fbhigh_dma;
-               fbi->fdadr0 = fbi->dmadesc_fbhigh_dma; /* no pal just fbhigh */
-               /* init it to something, even though we won't be using it */
-               fbi->dmadesc_palette_cpu->fdadr = fbi->dmadesc_palette_dma;
-       } else {
-               fbi->dmadesc_palette_cpu->fdadr = fbi->dmadesc_fbhigh_dma;
-               fbi->dmadesc_fbhigh_cpu->fdadr = fbi->dmadesc_palette_dma;
-               fbi->fdadr0 = fbi->dmadesc_palette_dma; /* flips back and forth between pal and fbhigh */
-       }
+       fbi->reg_lccr0 = fbi->lccr0 |
+               (LCCR0_LDM | LCCR0_SFM | LCCR0_IUM | LCCR0_EFM |
+                LCCR0_QDM | LCCR0_BM  | LCCR0_OUM);
 
-#if 0
-       DPRINTK("fbi->dmadesc_fblow_cpu = 0x%p\n", fbi->dmadesc_fblow_cpu);
-       DPRINTK("fbi->dmadesc_fbhigh_cpu = 0x%p\n", fbi->dmadesc_fbhigh_cpu);
-       DPRINTK("fbi->dmadesc_palette_cpu = 0x%p\n", fbi->dmadesc_palette_cpu);
-       DPRINTK("fbi->dmadesc_fblow_dma = 0x%x\n", fbi->dmadesc_fblow_dma);
-       DPRINTK("fbi->dmadesc_fbhigh_dma = 0x%x\n", fbi->dmadesc_fbhigh_dma);
-       DPRINTK("fbi->dmadesc_palette_dma = 0x%x\n", fbi->dmadesc_palette_dma);
-
-       DPRINTK("fbi->dmadesc_fblow_cpu->fdadr = 0x%x\n", fbi->dmadesc_fblow_cpu->fdadr);
-       DPRINTK("fbi->dmadesc_fbhigh_cpu->fdadr = 0x%x\n", fbi->dmadesc_fbhigh_cpu->fdadr);
-       DPRINTK("fbi->dmadesc_palette_cpu->fdadr = 0x%x\n", fbi->dmadesc_palette_cpu->fdadr);
-
-       DPRINTK("fbi->dmadesc_fblow_cpu->fsadr = 0x%x\n", fbi->dmadesc_fblow_cpu->fsadr);
-       DPRINTK("fbi->dmadesc_fbhigh_cpu->fsadr = 0x%x\n", fbi->dmadesc_fbhigh_cpu->fsadr);
-       DPRINTK("fbi->dmadesc_palette_cpu->fsadr = 0x%x\n", fbi->dmadesc_palette_cpu->fsadr);
-
-       DPRINTK("fbi->dmadesc_fblow_cpu->ldcmd = 0x%x\n", fbi->dmadesc_fblow_cpu->ldcmd);
-       DPRINTK("fbi->dmadesc_fbhigh_cpu->ldcmd = 0x%x\n", fbi->dmadesc_fbhigh_cpu->ldcmd);
-       DPRINTK("fbi->dmadesc_palette_cpu->ldcmd = 0x%x\n", fbi->dmadesc_palette_cpu->ldcmd);
-#endif
+       fbi->reg_lccr3 |= pxafb_var_to_lccr3(var);
 
-       fbi->reg_lccr0 = new_regs.lccr0;
-       fbi->reg_lccr1 = new_regs.lccr1;
-       fbi->reg_lccr2 = new_regs.lccr2;
-       fbi->reg_lccr3 = new_regs.lccr3;
+       fbi->reg_lccr4 = lcd_readl(fbi, LCCR4) & ~LCCR4_PAL_FOR_MASK;
+       fbi->reg_lccr4 |= (fbi->lccr4 & LCCR4_PAL_FOR_MASK);
        local_irq_restore(flags);
 
        /*
         * Only update the registers if the controller is enabled
         * and something has changed.
         */
-       if ((LCCR0  != fbi->reg_lccr0) || (LCCR1  != fbi->reg_lccr1) ||
-           (LCCR2  != fbi->reg_lccr2) || (LCCR3  != fbi->reg_lccr3) ||
-           (FDADR0 != fbi->fdadr0)    || (FDADR1 != fbi->fdadr1))
+       if ((lcd_readl(fbi, LCCR0) != fbi->reg_lccr0) ||
+           (lcd_readl(fbi, LCCR1) != fbi->reg_lccr1) ||
+           (lcd_readl(fbi, LCCR2) != fbi->reg_lccr2) ||
+           (lcd_readl(fbi, LCCR3) != fbi->reg_lccr3) ||
+           (lcd_readl(fbi, LCCR4) != fbi->reg_lccr4) ||
+           (lcd_readl(fbi, FDADR0) != fbi->fdadr[0]) ||
+           (lcd_readl(fbi, FDADR1) != fbi->fdadr[1]))
                pxafb_schedule_work(fbi, C_REENABLE);
 
        return 0;
@@ -653,119 +1382,106 @@ static int pxafb_activate_var(struct fb_var_screeninfo *var, struct pxafb_info *
  */
 static inline void __pxafb_backlight_power(struct pxafb_info *fbi, int on)
 {
-       DPRINTK("backlight o%s\n", on ? "n" : "ff");
+       pr_debug("pxafb: backlight o%s\n", on ? "n" : "ff");
 
-       if (pxafb_backlight_power)
-               pxafb_backlight_power(on);
+       if (fbi->backlight_power)
+               fbi->backlight_power(on);
 }
 
 static inline void __pxafb_lcd_power(struct pxafb_info *fbi, int on)
 {
-       DPRINTK("LCD power o%s\n", on ? "n" : "ff");
+       pr_debug("pxafb: LCD power o%s\n", on ? "n" : "ff");
 
-       if (pxafb_lcd_power)
-               pxafb_lcd_power(on);
+       if (fbi->lcd_power)
+               fbi->lcd_power(on, &fbi->fb.var);
 }
 
-static void pxafb_setup_gpio(struct pxafb_info *fbi)
+static void pxafb_enable_controller(struct pxafb_info *fbi)
 {
-       int gpio, ldd_bits;
-        unsigned int lccr0 = fbi->lccr0;
+       pr_debug("pxafb: Enabling LCD controller\n");
+       pr_debug("fdadr0 0x%08x\n", (unsigned int) fbi->fdadr[0]);
+       pr_debug("fdadr1 0x%08x\n", (unsigned int) fbi->fdadr[1]);
+       pr_debug("reg_lccr0 0x%08x\n", (unsigned int) fbi->reg_lccr0);
+       pr_debug("reg_lccr1 0x%08x\n", (unsigned int) fbi->reg_lccr1);
+       pr_debug("reg_lccr2 0x%08x\n", (unsigned int) fbi->reg_lccr2);
+       pr_debug("reg_lccr3 0x%08x\n", (unsigned int) fbi->reg_lccr3);
 
-       /*
-        * setup is based on type of panel supported
-        */
-
-       /* 4 bit interface */
-       if ((lccr0 & LCCR0_CMS) == LCCR0_Mono &&
-           (lccr0 & LCCR0_SDS) == LCCR0_Sngl &&
-           (lccr0 & LCCR0_DPD) == LCCR0_4PixMono)
-               ldd_bits = 4;
-
-       /* 8 bit interface */
-        else if (((lccr0 & LCCR0_CMS) == LCCR0_Mono &&
-                 ((lccr0 & LCCR0_SDS) == LCCR0_Dual || (lccr0 & LCCR0_DPD) == LCCR0_8PixMono)) ||
-                 ((lccr0 & LCCR0_CMS) == LCCR0_Color &&
-                 (lccr0 & LCCR0_PAS) == LCCR0_Pas && (lccr0 & LCCR0_SDS) == LCCR0_Sngl))
-               ldd_bits = 8;
-
-       /* 16 bit interface */
-       else if ((lccr0 & LCCR0_CMS) == LCCR0_Color &&
-                ((lccr0 & LCCR0_SDS) == LCCR0_Dual || (lccr0 & LCCR0_PAS) == LCCR0_Act))
-               ldd_bits = 16;
+       /* enable LCD controller clock */
+       clk_enable(fbi->clk);
 
-       else {
-               printk(KERN_ERR "pxafb_setup_gpio: unable to determine bits per pixel\n");
+       if (fbi->lccr0 & LCCR0_LCDT)
                return;
-        }
-
-       for (gpio = 58; ldd_bits; gpio++, ldd_bits--)
-               pxa_gpio_mode(gpio | GPIO_ALT_FN_2_OUT);
-       pxa_gpio_mode(GPIO74_LCD_FCLK_MD);
-       pxa_gpio_mode(GPIO75_LCD_LCLK_MD);
-       pxa_gpio_mode(GPIO76_LCD_PCLK_MD);
-       pxa_gpio_mode(GPIO77_LCD_ACBIAS_MD);
-}
-
-static void pxafb_enable_controller(struct pxafb_info *fbi)
-{
-       DPRINTK("Enabling LCD controller\n");
-       DPRINTK("fdadr0 0x%08x\n", (unsigned int) fbi->fdadr0);
-       DPRINTK("fdadr1 0x%08x\n", (unsigned int) fbi->fdadr1);
-       DPRINTK("reg_lccr0 0x%08x\n", (unsigned int) fbi->reg_lccr0);
-       DPRINTK("reg_lccr1 0x%08x\n", (unsigned int) fbi->reg_lccr1);
-       DPRINTK("reg_lccr2 0x%08x\n", (unsigned int) fbi->reg_lccr2);
-       DPRINTK("reg_lccr3 0x%08x\n", (unsigned int) fbi->reg_lccr3);
 
        /* Sequence from 11.7.10 */
-       LCCR3 = fbi->reg_lccr3;
-       LCCR2 = fbi->reg_lccr2;
-       LCCR1 = fbi->reg_lccr1;
-       LCCR0 = fbi->reg_lccr0 & ~LCCR0_ENB;
-
-       FDADR0 = fbi->fdadr0;
-       FDADR1 = fbi->fdadr1;
-       LCCR0 |= LCCR0_ENB;
-
-       DPRINTK("FDADR0 0x%08x\n", (unsigned int) FDADR0);
-       DPRINTK("FDADR1 0x%08x\n", (unsigned int) FDADR1);
-       DPRINTK("LCCR0 0x%08x\n", (unsigned int) LCCR0);
-       DPRINTK("LCCR1 0x%08x\n", (unsigned int) LCCR1);
-       DPRINTK("LCCR2 0x%08x\n", (unsigned int) LCCR2);
-       DPRINTK("LCCR3 0x%08x\n", (unsigned int) LCCR3);
+       lcd_writel(fbi, LCCR4, fbi->reg_lccr4);
+       lcd_writel(fbi, LCCR3, fbi->reg_lccr3);
+       lcd_writel(fbi, LCCR2, fbi->reg_lccr2);
+       lcd_writel(fbi, LCCR1, fbi->reg_lccr1);
+       lcd_writel(fbi, LCCR0, fbi->reg_lccr0 & ~LCCR0_ENB);
+
+       lcd_writel(fbi, FDADR0, fbi->fdadr[0]);
+       lcd_writel(fbi, FDADR1, fbi->fdadr[1]);
+       lcd_writel(fbi, LCCR0, fbi->reg_lccr0 | LCCR0_ENB);
 }
 
 static void pxafb_disable_controller(struct pxafb_info *fbi)
 {
-       DECLARE_WAITQUEUE(wait, current);
+       uint32_t lccr0;
+
+#ifdef CONFIG_FB_PXA_SMARTPANEL
+       if (fbi->lccr0 & LCCR0_LCDT) {
+               wait_for_completion_timeout(&fbi->refresh_done,
+                               200 * HZ / 1000);
+               return;
+       }
+#endif
 
-       DPRINTK("Disabling LCD controller\n");
+       /* Clear LCD Status Register */
+       lcd_writel(fbi, LCSR, 0xffffffff);
 
-       set_current_state(TASK_UNINTERRUPTIBLE);
-       add_wait_queue(&fbi->ctrlr_wait, &wait);
+       lccr0 = lcd_readl(fbi, LCCR0) & ~LCCR0_LDM;
+       lcd_writel(fbi, LCCR0, lccr0);
+       lcd_writel(fbi, LCCR0, lccr0 | LCCR0_DIS);
 
-       LCSR = 0xffffffff;      /* Clear LCD Status Register */
-       LCCR0 &= ~LCCR0_LDM;    /* Enable LCD Disable Done Interrupt */
-       LCCR0 |= LCCR0_DIS;     /* Disable LCD Controller */
+       wait_for_completion_timeout(&fbi->disable_done, 200 * HZ / 1000);
 
-       schedule_timeout(20 * HZ / 1000);
-       remove_wait_queue(&fbi->ctrlr_wait, &wait);
+       /* disable LCD controller clock */
+       clk_disable(fbi->clk);
 }
 
 /*
  *  pxafb_handle_irq: Handle 'LCD DONE' interrupts.
  */
-static irqreturn_t pxafb_handle_irq(int irq, void *dev_id, struct pt_regs *regs)
+static irqreturn_t pxafb_handle_irq(int irq, void *dev_id)
 {
        struct pxafb_info *fbi = dev_id;
-       unsigned int lcsr = LCSR;
+       unsigned int lccr0, lcsr;
 
+       lcsr = lcd_readl(fbi, LCSR);
        if (lcsr & LCSR_LDD) {
-               LCCR0 |= LCCR0_LDM;
-               wake_up(&fbi->ctrlr_wait);
+               lccr0 = lcd_readl(fbi, LCCR0);
+               lcd_writel(fbi, LCCR0, lccr0 | LCCR0_LDM);
+               complete(&fbi->disable_done);
        }
 
-       LCSR = lcsr;
+#ifdef CONFIG_FB_PXA_SMARTPANEL
+       if (lcsr & LCSR_CMD_INT)
+               complete(&fbi->command_done);
+#endif
+       lcd_writel(fbi, LCSR, lcsr);
+
+#ifdef CONFIG_FB_PXA_OVERLAY
+       {
+               unsigned int lcsr1 = lcd_readl(fbi, LCSR1);
+               if (lcsr1 & LCSR1_BS(1))
+                       complete(&fbi->overlay[0].branch_done);
+
+               if (lcsr1 & LCSR1_BS(2))
+                       complete(&fbi->overlay[1].branch_done);
+
+               lcd_writel(fbi, LCSR1, lcsr1);
+       }
+#endif
        return IRQ_HANDLED;
 }
 
@@ -778,7 +1494,7 @@ static void set_ctrlr_state(struct pxafb_info *fbi, u_int state)
 {
        u_int old_state;
 
-       down(&fbi->ctrlr_sem);
+       mutex_lock(&fbi->ctrlr_lock);
 
        old_state = fbi->state;
 
@@ -796,7 +1512,7 @@ static void set_ctrlr_state(struct pxafb_info *fbi, u_int state)
                 */
                if (old_state != C_DISABLE && old_state != C_DISABLE_PM) {
                        fbi->state = state;
-                       //TODO __pxafb_lcd_power(fbi, 0);
+                       /* TODO __pxafb_lcd_power(fbi, 0); */
                        pxafb_disable_controller(fbi);
                }
                break;
@@ -823,7 +1539,7 @@ static void set_ctrlr_state(struct pxafb_info *fbi, u_int state)
                if (old_state == C_DISABLE_CLKCHANGE) {
                        fbi->state = C_ENABLE;
                        pxafb_enable_controller(fbi);
-                       //TODO __pxafb_lcd_power(fbi, 1);
+                       /* TODO __pxafb_lcd_power(fbi, 1); */
                }
                break;
 
@@ -834,9 +1550,10 @@ static void set_ctrlr_state(struct pxafb_info *fbi, u_int state)
                 * registers.
                 */
                if (old_state == C_ENABLE) {
+                       __pxafb_lcd_power(fbi, 0);
                        pxafb_disable_controller(fbi);
-                       pxafb_setup_gpio(fbi);
                        pxafb_enable_controller(fbi);
+                       __pxafb_lcd_power(fbi, 1);
                }
                break;
 
@@ -857,23 +1574,23 @@ static void set_ctrlr_state(struct pxafb_info *fbi, u_int state)
                 */
                if (old_state != C_ENABLE) {
                        fbi->state = C_ENABLE;
-                       pxafb_setup_gpio(fbi);
                        pxafb_enable_controller(fbi);
                        __pxafb_lcd_power(fbi, 1);
                        __pxafb_backlight_power(fbi, 1);
                }
                break;
        }
-       up(&fbi->ctrlr_sem);
+       mutex_unlock(&fbi->ctrlr_lock);
 }
 
 /*
  * Our LCD controller task (which is called when we blank or unblank)
  * via keventd.
  */
-static void pxafb_task(void *dummy)
+static void pxafb_task(struct work_struct *work)
 {
-       struct pxafb_info *fbi = dummy;
+       struct pxafb_info *fbi =
+               container_of(work, struct pxafb_info, task);
        u_int state = xchg(&fbi->task_state, -1);
 
        set_ctrlr_state(fbi, state);
@@ -891,7 +1608,7 @@ static int
 pxafb_freq_transition(struct notifier_block *nb, unsigned long val, void *data)
 {
        struct pxafb_info *fbi = TO_INF(nb, freq_transition);
-       //TODO struct cpufreq_freqs *f = data;
+       /* TODO struct cpufreq_freqs *f = data; */
        u_int pcd;
 
        switch (val) {
@@ -900,8 +1617,10 @@ pxafb_freq_transition(struct notifier_block *nb, unsigned long val, void *data)
                break;
 
        case CPUFREQ_POSTCHANGE:
-               pcd = get_pcd(fbi->fb.var.pixclock);
-               fbi->reg_lccr3 = (fbi->reg_lccr3 & ~0xff) | LCCR3_PixClkDiv(pcd);
+               pcd = get_pcd(fbi, fbi->fb.var.pixclock);
+               set_hsync_time(fbi, pcd);
+               fbi->reg_lccr3 = (fbi->reg_lccr3 & ~0xff) |
+                                 LCCR3_PixClkDiv(pcd);
                set_ctrlr_state(fbi, C_ENABLE_CLKCHANGE);
                break;
        }
@@ -918,21 +1637,11 @@ pxafb_freq_policy(struct notifier_block *nb, unsigned long val, void *data)
        switch (val) {
        case CPUFREQ_ADJUST:
        case CPUFREQ_INCOMPATIBLE:
-               printk(KERN_DEBUG "min dma period: %d ps, "
+               pr_debug("min dma period: %d ps, "
                        "new clock %d kHz\n", pxafb_display_dma_period(var),
                        policy->max);
-               // TODO: fill in min/max values
-               break;
-#if 0
-       case CPUFREQ_NOTIFY:
-               printk(KERN_ERR "%s: got CPUFREQ_NOTIFY\n", __FUNCTION__);
-               do {} while(0);
-               /* todo: panic if min/max values aren't fulfilled
-                * [can't really happen unless there's a bug in the
-                * CPU policy verification process *
-                */
+               /* TODO: fill in min/max values */
                break;
-#endif
        }
        return 0;
 }
@@ -943,74 +1652,112 @@ pxafb_freq_policy(struct notifier_block *nb, unsigned long val, void *data)
  * Power management hooks.  Note that we won't be called from IRQ context,
  * unlike the blank functions above, so we may sleep.
  */
-static int pxafb_suspend(struct device *dev, pm_message_t state, u32 level)
+static int pxafb_suspend(struct device *dev)
 {
        struct pxafb_info *fbi = dev_get_drvdata(dev);
 
-       if (level == SUSPEND_DISABLE || level == SUSPEND_POWER_DOWN)
-               set_ctrlr_state(fbi, C_DISABLE_PM);
+       set_ctrlr_state(fbi, C_DISABLE_PM);
        return 0;
 }
 
-static int pxafb_resume(struct device *dev, u32 level)
+static int pxafb_resume(struct device *dev)
 {
        struct pxafb_info *fbi = dev_get_drvdata(dev);
 
-       if (level == RESUME_ENABLE)
-               set_ctrlr_state(fbi, C_ENABLE_PM);
+       set_ctrlr_state(fbi, C_ENABLE_PM);
        return 0;
 }
-#else
-#define pxafb_suspend  NULL
-#define pxafb_resume   NULL
+
+static const struct dev_pm_ops pxafb_pm_ops = {
+       .suspend        = pxafb_suspend,
+       .resume         = pxafb_resume,
+};
 #endif
 
-/*
- * pxafb_map_video_memory():
- *      Allocates the DRAM memory for the frame buffer.  This buffer is
- *     remapped into a non-cached, non-buffered, memory region to
- *      allow palette and pixel writes to occur without flushing the
- *      cache.  Once this area is remapped, all virtual memory
- *      access to the video memory should occur at the new region.
- */
-static int __init pxafb_map_video_memory(struct pxafb_info *fbi)
+static int __devinit pxafb_init_video_memory(struct pxafb_info *fbi)
 {
-       u_long palette_mem_size;
+       int size = PAGE_ALIGN(fbi->video_mem_size);
 
-       /*
-        * We reserve one page for the palette, plus the size
-        * of the framebuffer.
-        */
-       fbi->map_size = PAGE_ALIGN(fbi->fb.fix.smem_len + PAGE_SIZE);
-       fbi->map_cpu = dma_alloc_writecombine(fbi->dev, fbi->map_size,
-                                             &fbi->map_dma, GFP_KERNEL);
-
-       if (fbi->map_cpu) {
-               /* prevent initial garbage on screen */
-               memset(fbi->map_cpu, 0, fbi->map_size);
-               fbi->fb.screen_base = fbi->map_cpu + PAGE_SIZE;
-               fbi->screen_dma = fbi->map_dma + PAGE_SIZE;
-               /*
-                * FIXME: this is actually the wrong thing to place in
-                * smem_start.  But fbdev suffers from the problem that
-                * it needs an API which doesn't exist (in this case,
-                * dma_writecombine_mmap)
-                */
-               fbi->fb.fix.smem_start = fbi->screen_dma;
+       fbi->video_mem = alloc_pages_exact(size, GFP_KERNEL | __GFP_ZERO);
+       if (fbi->video_mem == NULL)
+               return -ENOMEM;
 
-               fbi->palette_size = fbi->fb.var.bits_per_pixel == 8 ? 256 : 16;
+       fbi->video_mem_phys = virt_to_phys(fbi->video_mem);
+       fbi->video_mem_size = size;
 
-               palette_mem_size = fbi->palette_size * sizeof(u16);
-               DPRINTK("palette_mem_size = 0x%08lx\n", (u_long) palette_mem_size);
+       fbi->fb.fix.smem_start  = fbi->video_mem_phys;
+       fbi->fb.fix.smem_len    = fbi->video_mem_size;
+       fbi->fb.screen_base     = fbi->video_mem;
 
-               fbi->palette_cpu = (u16 *)(fbi->map_cpu + PAGE_SIZE - palette_mem_size);
-               fbi->palette_dma = fbi->map_dma + PAGE_SIZE - palette_mem_size;
+       return fbi->video_mem ? 0 : -ENOMEM;
+}
+
+static void pxafb_decode_mach_info(struct pxafb_info *fbi,
+                                  struct pxafb_mach_info *inf)
+{
+       unsigned int lcd_conn = inf->lcd_conn;
+       struct pxafb_mode_info *m;
+       int i;
+
+       fbi->cmap_inverse       = inf->cmap_inverse;
+       fbi->cmap_static        = inf->cmap_static;
+       fbi->lccr4              = inf->lccr4;
+
+       switch (lcd_conn & LCD_TYPE_MASK) {
+       case LCD_TYPE_MONO_STN:
+               fbi->lccr0 = LCCR0_CMS;
+               break;
+       case LCD_TYPE_MONO_DSTN:
+               fbi->lccr0 = LCCR0_CMS | LCCR0_SDS;
+               break;
+       case LCD_TYPE_COLOR_STN:
+               fbi->lccr0 = 0;
+               break;
+       case LCD_TYPE_COLOR_DSTN:
+               fbi->lccr0 = LCCR0_SDS;
+               break;
+       case LCD_TYPE_COLOR_TFT:
+               fbi->lccr0 = LCCR0_PAS;
+               break;
+       case LCD_TYPE_SMART_PANEL:
+               fbi->lccr0 = LCCR0_LCDT | LCCR0_PAS;
+               break;
+       default:
+               /* fall back to backward compatibility way */
+               fbi->lccr0 = inf->lccr0;
+               fbi->lccr3 = inf->lccr3;
+               goto decode_mode;
        }
 
-       return fbi->map_cpu ? 0 : -ENOMEM;
+       if (lcd_conn == LCD_MONO_STN_8BPP)
+               fbi->lccr0 |= LCCR0_DPD;
+
+       fbi->lccr0 |= (lcd_conn & LCD_ALTERNATE_MAPPING) ? LCCR0_LDDALT : 0;
+
+       fbi->lccr3 = LCCR3_Acb((inf->lcd_conn >> 10) & 0xff);
+       fbi->lccr3 |= (lcd_conn & LCD_BIAS_ACTIVE_LOW) ? LCCR3_OEP : 0;
+       fbi->lccr3 |= (lcd_conn & LCD_PCLK_EDGE_FALL)  ? LCCR3_PCP : 0;
+
+decode_mode:
+       pxafb_setmode(&fbi->fb.var, &inf->modes[0]);
+
+       /* decide video memory size as follows:
+        * 1. default to mode of maximum resolution
+        * 2. allow platform to override
+        * 3. allow module parameter to override
+        */
+       for (i = 0, m = &inf->modes[0]; i < inf->num_modes; i++, m++)
+               fbi->video_mem_size = max_t(size_t, fbi->video_mem_size,
+                               m->xres * m->yres * m->bpp / 8);
+
+       if (inf->video_mem_size > fbi->video_mem_size)
+               fbi->video_mem_size = inf->video_mem_size;
+
+       if (video_mem_size > fbi->video_mem_size)
+               fbi->video_mem_size = video_mem_size;
 }
 
-static struct pxafb_info * __init pxafb_init_fbinfo(struct device *dev)
+static struct pxafb_info * __devinit pxafb_init_fbinfo(struct device *dev)
 {
        struct pxafb_info *fbi;
        void *addr;
@@ -1024,12 +1771,18 @@ static struct pxafb_info * __init pxafb_init_fbinfo(struct device *dev)
        memset(fbi, 0, sizeof(struct pxafb_info));
        fbi->dev = dev;
 
+       fbi->clk = clk_get(dev, NULL);
+       if (IS_ERR(fbi->clk)) {
+               kfree(fbi);
+               return NULL;
+       }
+
        strcpy(fbi->fb.fix.id, PXA_NAME);
 
        fbi->fb.fix.type        = FB_TYPE_PACKED_PIXELS;
        fbi->fb.fix.type_aux    = 0;
        fbi->fb.fix.xpanstep    = 0;
-       fbi->fb.fix.ypanstep    = 0;
+       fbi->fb.fix.ypanstep    = 1;
        fbi->fb.fix.ywrapstep   = 0;
        fbi->fb.fix.accel       = FB_ACCEL_NONE;
 
@@ -1037,7 +1790,7 @@ static struct pxafb_info * __init pxafb_init_fbinfo(struct device *dev)
        fbi->fb.var.activate    = FB_ACTIVATE_NOW;
        fbi->fb.var.height      = -1;
        fbi->fb.var.width       = -1;
-       fbi->fb.var.accel_flags = 0;
+       fbi->fb.var.accel_flags = FB_ACCELF_TEXT;
        fbi->fb.var.vmode       = FB_VMODE_NONINTERLACED;
 
        fbi->fb.fbops           = &pxafb_ops;
@@ -1048,291 +1801,399 @@ static struct pxafb_info * __init pxafb_init_fbinfo(struct device *dev)
        addr = addr + sizeof(struct pxafb_info);
        fbi->fb.pseudo_palette  = addr;
 
-       fbi->max_xres                   = inf->xres;
-       fbi->fb.var.xres                = inf->xres;
-       fbi->fb.var.xres_virtual        = inf->xres;
-       fbi->max_yres                   = inf->yres;
-       fbi->fb.var.yres                = inf->yres;
-       fbi->fb.var.yres_virtual        = inf->yres;
-       fbi->max_bpp                    = inf->bpp;
-       fbi->fb.var.bits_per_pixel      = inf->bpp;
-       fbi->fb.var.pixclock            = inf->pixclock;
-       fbi->fb.var.hsync_len           = inf->hsync_len;
-       fbi->fb.var.left_margin         = inf->left_margin;
-       fbi->fb.var.right_margin        = inf->right_margin;
-       fbi->fb.var.vsync_len           = inf->vsync_len;
-       fbi->fb.var.upper_margin        = inf->upper_margin;
-       fbi->fb.var.lower_margin        = inf->lower_margin;
-       fbi->fb.var.sync                = inf->sync;
-       fbi->fb.var.grayscale           = inf->cmap_greyscale;
-       fbi->cmap_inverse               = inf->cmap_inverse;
-       fbi->cmap_static                = inf->cmap_static;
-       fbi->lccr0                      = inf->lccr0;
-       fbi->lccr3                      = inf->lccr3;
-       fbi->state                      = C_STARTUP;
-       fbi->task_state                 = (u_char)-1;
-       fbi->fb.fix.smem_len            = fbi->max_xres * fbi->max_yres *
-                                         fbi->max_bpp / 8;
+       fbi->state              = C_STARTUP;
+       fbi->task_state         = (u_char)-1;
+
+       pxafb_decode_mach_info(fbi, inf);
 
        init_waitqueue_head(&fbi->ctrlr_wait);
-       INIT_WORK(&fbi->task, pxafb_task, fbi);
-       init_MUTEX(&fbi->ctrlr_sem);
+       INIT_WORK(&fbi->task, pxafb_task);
+       mutex_init(&fbi->ctrlr_lock);
+       init_completion(&fbi->disable_done);
 
        return fbi;
 }
 
 #ifdef CONFIG_FB_PXA_PARAMETERS
-static int __init pxafb_parse_options(struct device *dev, char *options)
+static int __devinit parse_opt_mode(struct device *dev, const char *this_opt)
+{
+       struct pxafb_mach_info *inf = dev->platform_data;
+
+       const char *name = this_opt+5;
+       unsigned int namelen = strlen(name);
+       int res_specified = 0, bpp_specified = 0;
+       unsigned int xres = 0, yres = 0, bpp = 0;
+       int yres_specified = 0;
+       int i;
+       for (i = namelen-1; i >= 0; i--) {
+               switch (name[i]) {
+               case '-':
+                       namelen = i;
+                       if (!bpp_specified && !yres_specified) {
+                               bpp = simple_strtoul(&name[i+1], NULL, 0);
+                               bpp_specified = 1;
+                       } else
+                               goto done;
+                       break;
+               case 'x':
+                       if (!yres_specified) {
+                               yres = simple_strtoul(&name[i+1], NULL, 0);
+                               yres_specified = 1;
+                       } else
+                               goto done;
+                       break;
+               case '0' ... '9':
+                       break;
+               default:
+                       goto done;
+               }
+       }
+       if (i < 0 && yres_specified) {
+               xres = simple_strtoul(name, NULL, 0);
+               res_specified = 1;
+       }
+done:
+       if (res_specified) {
+               dev_info(dev, "overriding resolution: %dx%d\n", xres, yres);
+               inf->modes[0].xres = xres; inf->modes[0].yres = yres;
+       }
+       if (bpp_specified)
+               switch (bpp) {
+               case 1:
+               case 2:
+               case 4:
+               case 8:
+               case 16:
+                       inf->modes[0].bpp = bpp;
+                       dev_info(dev, "overriding bit depth: %d\n", bpp);
+                       break;
+               default:
+                       dev_err(dev, "Depth %d is not valid\n", bpp);
+                       return -EINVAL;
+               }
+       return 0;
+}
+
+static int __devinit parse_opt(struct device *dev, char *this_opt)
 {
        struct pxafb_mach_info *inf = dev->platform_data;
+       struct pxafb_mode_info *mode = &inf->modes[0];
+       char s[64];
+
+       s[0] = '\0';
+
+       if (!strncmp(this_opt, "vmem:", 5)) {
+               video_mem_size = memparse(this_opt + 5, NULL);
+       } else if (!strncmp(this_opt, "mode:", 5)) {
+               return parse_opt_mode(dev, this_opt);
+       } else if (!strncmp(this_opt, "pixclock:", 9)) {
+               mode->pixclock = simple_strtoul(this_opt+9, NULL, 0);
+               sprintf(s, "pixclock: %ld\n", mode->pixclock);
+       } else if (!strncmp(this_opt, "left:", 5)) {
+               mode->left_margin = simple_strtoul(this_opt+5, NULL, 0);
+               sprintf(s, "left: %u\n", mode->left_margin);
+       } else if (!strncmp(this_opt, "right:", 6)) {
+               mode->right_margin = simple_strtoul(this_opt+6, NULL, 0);
+               sprintf(s, "right: %u\n", mode->right_margin);
+       } else if (!strncmp(this_opt, "upper:", 6)) {
+               mode->upper_margin = simple_strtoul(this_opt+6, NULL, 0);
+               sprintf(s, "upper: %u\n", mode->upper_margin);
+       } else if (!strncmp(this_opt, "lower:", 6)) {
+               mode->lower_margin = simple_strtoul(this_opt+6, NULL, 0);
+               sprintf(s, "lower: %u\n", mode->lower_margin);
+       } else if (!strncmp(this_opt, "hsynclen:", 9)) {
+               mode->hsync_len = simple_strtoul(this_opt+9, NULL, 0);
+               sprintf(s, "hsynclen: %u\n", mode->hsync_len);
+       } else if (!strncmp(this_opt, "vsynclen:", 9)) {
+               mode->vsync_len = simple_strtoul(this_opt+9, NULL, 0);
+               sprintf(s, "vsynclen: %u\n", mode->vsync_len);
+       } else if (!strncmp(this_opt, "hsync:", 6)) {
+               if (simple_strtoul(this_opt+6, NULL, 0) == 0) {
+                       sprintf(s, "hsync: Active Low\n");
+                       mode->sync &= ~FB_SYNC_HOR_HIGH_ACT;
+               } else {
+                       sprintf(s, "hsync: Active High\n");
+                       mode->sync |= FB_SYNC_HOR_HIGH_ACT;
+               }
+       } else if (!strncmp(this_opt, "vsync:", 6)) {
+               if (simple_strtoul(this_opt+6, NULL, 0) == 0) {
+                       sprintf(s, "vsync: Active Low\n");
+                       mode->sync &= ~FB_SYNC_VERT_HIGH_ACT;
+               } else {
+                       sprintf(s, "vsync: Active High\n");
+                       mode->sync |= FB_SYNC_VERT_HIGH_ACT;
+               }
+       } else if (!strncmp(this_opt, "dpc:", 4)) {
+               if (simple_strtoul(this_opt+4, NULL, 0) == 0) {
+                       sprintf(s, "double pixel clock: false\n");
+                       inf->lccr3 &= ~LCCR3_DPC;
+               } else {
+                       sprintf(s, "double pixel clock: true\n");
+                       inf->lccr3 |= LCCR3_DPC;
+               }
+       } else if (!strncmp(this_opt, "outputen:", 9)) {
+               if (simple_strtoul(this_opt+9, NULL, 0) == 0) {
+                       sprintf(s, "output enable: active low\n");
+                       inf->lccr3 = (inf->lccr3 & ~LCCR3_OEP) | LCCR3_OutEnL;
+               } else {
+                       sprintf(s, "output enable: active high\n");
+                       inf->lccr3 = (inf->lccr3 & ~LCCR3_OEP) | LCCR3_OutEnH;
+               }
+       } else if (!strncmp(this_opt, "pixclockpol:", 12)) {
+               if (simple_strtoul(this_opt+12, NULL, 0) == 0) {
+                       sprintf(s, "pixel clock polarity: falling edge\n");
+                       inf->lccr3 = (inf->lccr3 & ~LCCR3_PCP) | LCCR3_PixFlEdg;
+               } else {
+                       sprintf(s, "pixel clock polarity: rising edge\n");
+                       inf->lccr3 = (inf->lccr3 & ~LCCR3_PCP) | LCCR3_PixRsEdg;
+               }
+       } else if (!strncmp(this_opt, "color", 5)) {
+               inf->lccr0 = (inf->lccr0 & ~LCCR0_CMS) | LCCR0_Color;
+       } else if (!strncmp(this_opt, "mono", 4)) {
+               inf->lccr0 = (inf->lccr0 & ~LCCR0_CMS) | LCCR0_Mono;
+       } else if (!strncmp(this_opt, "active", 6)) {
+               inf->lccr0 = (inf->lccr0 & ~LCCR0_PAS) | LCCR0_Act;
+       } else if (!strncmp(this_opt, "passive", 7)) {
+               inf->lccr0 = (inf->lccr0 & ~LCCR0_PAS) | LCCR0_Pas;
+       } else if (!strncmp(this_opt, "single", 6)) {
+               inf->lccr0 = (inf->lccr0 & ~LCCR0_SDS) | LCCR0_Sngl;
+       } else if (!strncmp(this_opt, "dual", 4)) {
+               inf->lccr0 = (inf->lccr0 & ~LCCR0_SDS) | LCCR0_Dual;
+       } else if (!strncmp(this_opt, "4pix", 4)) {
+               inf->lccr0 = (inf->lccr0 & ~LCCR0_DPD) | LCCR0_4PixMono;
+       } else if (!strncmp(this_opt, "8pix", 4)) {
+               inf->lccr0 = (inf->lccr0 & ~LCCR0_DPD) | LCCR0_8PixMono;
+       } else {
+               dev_err(dev, "unknown option: %s\n", this_opt);
+               return -EINVAL;
+       }
+
+       if (s[0] != '\0')
+               dev_info(dev, "override %s", s);
+
+       return 0;
+}
+
+static int __devinit pxafb_parse_options(struct device *dev, char *options)
+{
        char *this_opt;
+       int ret;
 
-        if (!options || !*options)
-                return 0;
+       if (!options || !*options)
+               return 0;
 
        dev_dbg(dev, "options are \"%s\"\n", options ? options : "null");
 
        /* could be made table driven or similar?... */
-        while ((this_opt = strsep(&options, ",")) != NULL) {
-                if (!strncmp(this_opt, "mode:", 5)) {
-                       const char *name = this_opt+5;
-                       unsigned int namelen = strlen(name);
-                       int res_specified = 0, bpp_specified = 0;
-                       unsigned int xres = 0, yres = 0, bpp = 0;
-                       int yres_specified = 0;
-                       int i;
-                       for (i = namelen-1; i >= 0; i--) {
-                               switch (name[i]) {
-                               case '-':
-                                       namelen = i;
-                                       if (!bpp_specified && !yres_specified) {
-                                               bpp = simple_strtoul(&name[i+1], NULL, 0);
-                                               bpp_specified = 1;
-                                       } else
-                                               goto done;
-                                       break;
-                               case 'x':
-                                       if (!yres_specified) {
-                                               yres = simple_strtoul(&name[i+1], NULL, 0);
-                                               yres_specified = 1;
-                                       } else
-                                               goto done;
-                                       break;
-                               case '0'...'9':
-                                       break;
-                               default:
-                                       goto done;
-                               }
-                       }
-                       if (i < 0 && yres_specified) {
-                               xres = simple_strtoul(name, NULL, 0);
-                               res_specified = 1;
-                       }
-               done:
-                       if (res_specified) {
-                               dev_info(dev, "overriding resolution: %dx%d\n", xres, yres);
-                               inf->xres = xres; inf->yres = yres;
-                       }
-                       if (bpp_specified)
-                               switch (bpp) {
-                               case 1:
-                               case 2:
-                               case 4:
-                               case 8:
-                               case 16:
-                                       inf->bpp = bpp;
-                                       dev_info(dev, "overriding bit depth: %d\n", bpp);
-                                       break;
-                               default:
-                                       dev_err(dev, "Depth %d is not valid\n", bpp);
-                               }
-                } else if (!strncmp(this_opt, "pixclock:", 9)) {
-                        inf->pixclock = simple_strtoul(this_opt+9, NULL, 0);
-                       dev_info(dev, "override pixclock: %ld\n", inf->pixclock);
-                } else if (!strncmp(this_opt, "left:", 5)) {
-                        inf->left_margin = simple_strtoul(this_opt+5, NULL, 0);
-                       dev_info(dev, "override left: %u\n", inf->left_margin);
-                } else if (!strncmp(this_opt, "right:", 6)) {
-                        inf->right_margin = simple_strtoul(this_opt+6, NULL, 0);
-                       dev_info(dev, "override right: %u\n", inf->right_margin);
-                } else if (!strncmp(this_opt, "upper:", 6)) {
-                        inf->upper_margin = simple_strtoul(this_opt+6, NULL, 0);
-                       dev_info(dev, "override upper: %u\n", inf->upper_margin);
-                } else if (!strncmp(this_opt, "lower:", 6)) {
-                        inf->lower_margin = simple_strtoul(this_opt+6, NULL, 0);
-                       dev_info(dev, "override lower: %u\n", inf->lower_margin);
-                } else if (!strncmp(this_opt, "hsynclen:", 9)) {
-                        inf->hsync_len = simple_strtoul(this_opt+9, NULL, 0);
-                       dev_info(dev, "override hsynclen: %u\n", inf->hsync_len);
-                } else if (!strncmp(this_opt, "vsynclen:", 9)) {
-                        inf->vsync_len = simple_strtoul(this_opt+9, NULL, 0);
-                       dev_info(dev, "override vsynclen: %u\n", inf->vsync_len);
-                } else if (!strncmp(this_opt, "hsync:", 6)) {
-                        if (simple_strtoul(this_opt+6, NULL, 0) == 0) {
-                               dev_info(dev, "override hsync: Active Low\n");
-                               inf->sync &= ~FB_SYNC_HOR_HIGH_ACT;
-                       } else {
-                               dev_info(dev, "override hsync: Active High\n");
-                               inf->sync |= FB_SYNC_HOR_HIGH_ACT;
-                       }
-                } else if (!strncmp(this_opt, "vsync:", 6)) {
-                        if (simple_strtoul(this_opt+6, NULL, 0) == 0) {
-                               dev_info(dev, "override vsync: Active Low\n");
-                               inf->sync &= ~FB_SYNC_VERT_HIGH_ACT;
-                       } else {
-                               dev_info(dev, "override vsync: Active High\n");
-                               inf->sync |= FB_SYNC_VERT_HIGH_ACT;
-                       }
-                } else if (!strncmp(this_opt, "dpc:", 4)) {
-                        if (simple_strtoul(this_opt+4, NULL, 0) == 0) {
-                               dev_info(dev, "override double pixel clock: false\n");
-                               inf->lccr3 &= ~LCCR3_DPC;
-                       } else {
-                               dev_info(dev, "override double pixel clock: true\n");
-                               inf->lccr3 |= LCCR3_DPC;
-                       }
-                } else if (!strncmp(this_opt, "outputen:", 9)) {
-                        if (simple_strtoul(this_opt+9, NULL, 0) == 0) {
-                               dev_info(dev, "override output enable: active low\n");
-                               inf->lccr3 = (inf->lccr3 & ~LCCR3_OEP) | LCCR3_OutEnL;
-                       } else {
-                               dev_info(dev, "override output enable: active high\n");
-                               inf->lccr3 = (inf->lccr3 & ~LCCR3_OEP) | LCCR3_OutEnH;
-                       }
-                } else if (!strncmp(this_opt, "pixclockpol:", 12)) {
-                        if (simple_strtoul(this_opt+12, NULL, 0) == 0) {
-                               dev_info(dev, "override pixel clock polarity: falling edge\n");
-                               inf->lccr3 = (inf->lccr3 & ~LCCR3_PCP) | LCCR3_PixFlEdg;
-                       } else {
-                               dev_info(dev, "override pixel clock polarity: rising edge\n");
-                               inf->lccr3 = (inf->lccr3 & ~LCCR3_PCP) | LCCR3_PixRsEdg;
-                       }
-                } else if (!strncmp(this_opt, "color", 5)) {
-                       inf->lccr0 = (inf->lccr0 & ~LCCR0_CMS) | LCCR0_Color;
-                } else if (!strncmp(this_opt, "mono", 4)) {
-                       inf->lccr0 = (inf->lccr0 & ~LCCR0_CMS) | LCCR0_Mono;
-                } else if (!strncmp(this_opt, "active", 6)) {
-                       inf->lccr0 = (inf->lccr0 & ~LCCR0_PAS) | LCCR0_Act;
-                } else if (!strncmp(this_opt, "passive", 7)) {
-                       inf->lccr0 = (inf->lccr0 & ~LCCR0_PAS) | LCCR0_Pas;
-                } else if (!strncmp(this_opt, "single", 6)) {
-                       inf->lccr0 = (inf->lccr0 & ~LCCR0_SDS) | LCCR0_Sngl;
-                } else if (!strncmp(this_opt, "dual", 4)) {
-                       inf->lccr0 = (inf->lccr0 & ~LCCR0_SDS) | LCCR0_Dual;
-                } else if (!strncmp(this_opt, "4pix", 4)) {
-                       inf->lccr0 = (inf->lccr0 & ~LCCR0_DPD) | LCCR0_4PixMono;
-                } else if (!strncmp(this_opt, "8pix", 4)) {
-                       inf->lccr0 = (inf->lccr0 & ~LCCR0_DPD) | LCCR0_8PixMono;
-               } else {
-                       dev_err(dev, "unknown option: %s\n", this_opt);
-                       return -EINVAL;
-               }
-        }
-        return 0;
+       while ((this_opt = strsep(&options, ",")) != NULL) {
+               ret = parse_opt(dev, this_opt);
+               if (ret)
+                       return ret;
+       }
+       return 0;
+}
+
+static char g_options[256] __devinitdata = "";
+
+#ifndef MODULE
+static int __init pxafb_setup_options(void)
+{
+       char *options = NULL;
+
+       if (fb_get_options("pxafb", &options))
+               return -ENODEV;
 
+       if (options)
+               strlcpy(g_options, options, sizeof(g_options));
+
+       return 0;
+}
+#else
+#define pxafb_setup_options()          (0)
+
+module_param_string(options, g_options, sizeof(g_options), 0);
+MODULE_PARM_DESC(options, "LCD parameters (see Documentation/fb/pxafb.txt)");
+#endif
+
+#else
+#define pxafb_parse_options(...)       (0)
+#define pxafb_setup_options()          (0)
+#endif
+
+#ifdef DEBUG_VAR
+/* Check for various illegal bit-combinations. Currently only
+ * a warning is given. */
+static void __devinit pxafb_check_options(struct device *dev,
+                                         struct pxafb_mach_info *inf)
+{
+       if (inf->lcd_conn)
+               return;
+
+       if (inf->lccr0 & LCCR0_INVALID_CONFIG_MASK)
+               dev_warn(dev, "machine LCCR0 setting contains "
+                               "illegal bits: %08x\n",
+                       inf->lccr0 & LCCR0_INVALID_CONFIG_MASK);
+       if (inf->lccr3 & LCCR3_INVALID_CONFIG_MASK)
+               dev_warn(dev, "machine LCCR3 setting contains "
+                               "illegal bits: %08x\n",
+                       inf->lccr3 & LCCR3_INVALID_CONFIG_MASK);
+       if (inf->lccr0 & LCCR0_DPD &&
+           ((inf->lccr0 & LCCR0_PAS) != LCCR0_Pas ||
+            (inf->lccr0 & LCCR0_SDS) != LCCR0_Sngl ||
+            (inf->lccr0 & LCCR0_CMS) != LCCR0_Mono))
+               dev_warn(dev, "Double Pixel Data (DPD) mode is "
+                               "only valid in passive mono"
+                               " single panel mode\n");
+       if ((inf->lccr0 & LCCR0_PAS) == LCCR0_Act &&
+           (inf->lccr0 & LCCR0_SDS) == LCCR0_Dual)
+               dev_warn(dev, "Dual panel only valid in passive mode\n");
+       if ((inf->lccr0 & LCCR0_PAS) == LCCR0_Pas &&
+            (inf->modes->upper_margin || inf->modes->lower_margin))
+               dev_warn(dev, "Upper and lower margins must be 0 in "
+                               "passive mode\n");
 }
+#else
+#define pxafb_check_options(...)       do {} while (0)
 #endif
 
-int __init pxafb_probe(struct device *dev)
+static int __devinit pxafb_probe(struct platform_device *dev)
 {
        struct pxafb_info *fbi;
        struct pxafb_mach_info *inf;
-       int ret;
+       struct resource *r;
+       int irq, ret;
 
-       dev_dbg(dev, "pxafb_probe\n");
+       dev_dbg(&dev->dev, "pxafb_probe\n");
 
-       inf = dev->platform_data;
+       inf = dev->dev.platform_data;
        ret = -ENOMEM;
        fbi = NULL;
        if (!inf)
                goto failed;
 
-#ifdef CONFIG_FB_PXA_PARAMETERS
-       ret = pxafb_parse_options(dev, g_options);
+       ret = pxafb_parse_options(&dev->dev, g_options);
        if (ret < 0)
                goto failed;
-#endif
 
-#ifdef DEBUG_VAR
-        /* Check for various illegal bit-combinations. Currently only
-        * a warning is given. */
-
-        if (inf->lccr0 & LCCR0_INVALID_CONFIG_MASK)
-                dev_warn(dev, "machine LCCR0 setting contains illegal bits: %08x\n",
-                        inf->lccr0 & LCCR0_INVALID_CONFIG_MASK);
-        if (inf->lccr3 & LCCR3_INVALID_CONFIG_MASK)
-                dev_warn(dev, "machine LCCR3 setting contains illegal bits: %08x\n",
-                        inf->lccr3 & LCCR3_INVALID_CONFIG_MASK);
-        if (inf->lccr0 & LCCR0_DPD &&
-           ((inf->lccr0 & LCCR0_PAS) != LCCR0_Pas ||
-            (inf->lccr0 & LCCR0_SDS) != LCCR0_Sngl ||
-            (inf->lccr0 & LCCR0_CMS) != LCCR0_Mono))
-                dev_warn(dev, "Double Pixel Data (DPD) mode is only valid in passive mono"
-                        " single panel mode\n");
-        if ((inf->lccr0 & LCCR0_PAS) == LCCR0_Act &&
-           (inf->lccr0 & LCCR0_SDS) == LCCR0_Dual)
-                dev_warn(dev, "Dual panel only valid in passive mode\n");
-        if ((inf->lccr0 & LCCR0_PAS) == LCCR0_Pas &&
-             (inf->upper_margin || inf->lower_margin))
-                dev_warn(dev, "Upper and lower margins must be 0 in passive mode\n");
-#endif
+       pxafb_check_options(&dev->dev, inf);
 
-       dev_dbg(dev, "got a %dx%dx%d LCD\n",inf->xres, inf->yres, inf->bpp);
-       if (inf->xres == 0 || inf->yres == 0 || inf->bpp == 0) {
-               dev_err(dev, "Invalid resolution or bit depth\n");
+       dev_dbg(&dev->dev, "got a %dx%dx%d LCD\n",
+                       inf->modes->xres,
+                       inf->modes->yres,
+                       inf->modes->bpp);
+       if (inf->modes->xres == 0 ||
+           inf->modes->yres == 0 ||
+           inf->modes->bpp == 0) {
+               dev_err(&dev->dev, "Invalid resolution or bit depth\n");
                ret = -EINVAL;
                goto failed;
        }
-       pxafb_backlight_power = inf->pxafb_backlight_power;
-       pxafb_lcd_power = inf->pxafb_lcd_power;
-       fbi = pxafb_init_fbinfo(dev);
+
+       fbi = pxafb_init_fbinfo(&dev->dev);
        if (!fbi) {
-               dev_err(dev, "Failed to initialize framebuffer device\n");
-               ret = -ENOMEM; // only reason for pxafb_init_fbinfo to fail is kmalloc
+               /* only reason for pxafb_init_fbinfo to fail is kmalloc */
+               dev_err(&dev->dev, "Failed to initialize framebuffer device\n");
+               ret = -ENOMEM;
                goto failed;
        }
 
-       /* Initialize video memory */
-       ret = pxafb_map_video_memory(fbi);
+       if (cpu_is_pxa3xx() && inf->acceleration_enabled)
+               fbi->fb.fix.accel = FB_ACCEL_PXA3XX;
+
+       fbi->backlight_power = inf->pxafb_backlight_power;
+       fbi->lcd_power = inf->pxafb_lcd_power;
+
+       r = platform_get_resource(dev, IORESOURCE_MEM, 0);
+       if (r == NULL) {
+               dev_err(&dev->dev, "no I/O memory resource defined\n");
+               ret = -ENODEV;
+               goto failed_fbi;
+       }
+
+       r = request_mem_region(r->start, resource_size(r), dev->name);
+       if (r == NULL) {
+               dev_err(&dev->dev, "failed to request I/O memory\n");
+               ret = -EBUSY;
+               goto failed_fbi;
+       }
+
+       fbi->mmio_base = ioremap(r->start, resource_size(r));
+       if (fbi->mmio_base == NULL) {
+               dev_err(&dev->dev, "failed to map I/O memory\n");
+               ret = -EBUSY;
+               goto failed_free_res;
+       }
+
+       fbi->dma_buff_size = PAGE_ALIGN(sizeof(struct pxafb_dma_buff));
+       fbi->dma_buff = dma_alloc_coherent(fbi->dev, fbi->dma_buff_size,
+                               &fbi->dma_buff_phys, GFP_KERNEL);
+       if (fbi->dma_buff == NULL) {
+               dev_err(&dev->dev, "failed to allocate memory for DMA\n");
+               ret = -ENOMEM;
+               goto failed_free_io;
+       }
+
+       ret = pxafb_init_video_memory(fbi);
        if (ret) {
-               dev_err(dev, "Failed to allocate video RAM: %d\n", ret);
+               dev_err(&dev->dev, "Failed to allocate video RAM: %d\n", ret);
                ret = -ENOMEM;
-               goto failed;
+               goto failed_free_dma;
+       }
+
+       irq = platform_get_irq(dev, 0);
+       if (irq < 0) {
+               dev_err(&dev->dev, "no IRQ defined\n");
+               ret = -ENODEV;
+               goto failed_free_mem;
        }
-       /* enable LCD controller clock */
-       pxa_set_cken(CKEN16_LCD, 1);
 
-       ret = request_irq(IRQ_LCD, pxafb_handle_irq, SA_INTERRUPT, "LCD", fbi);
+       ret = request_irq(irq, pxafb_handle_irq, IRQF_DISABLED, "LCD", fbi);
        if (ret) {
-               dev_err(dev, "request_irq failed: %d\n", ret);
+               dev_err(&dev->dev, "request_irq failed: %d\n", ret);
                ret = -EBUSY;
-               goto failed;
+               goto failed_free_mem;
+       }
+
+       ret = pxafb_smart_init(fbi);
+       if (ret) {
+               dev_err(&dev->dev, "failed to initialize smartpanel\n");
+               goto failed_free_irq;
        }
 
        /*
         * This makes sure that our colour bitfield
         * descriptors are correctly initialised.
         */
-       pxafb_check_var(&fbi->fb.var, &fbi->fb);
-       pxafb_set_par(&fbi->fb);
+       ret = pxafb_check_var(&fbi->fb.var, &fbi->fb);
+       if (ret) {
+               dev_err(&dev->dev, "failed to get suitable mode\n");
+               goto failed_free_irq;
+       }
+
+       ret = pxafb_set_par(&fbi->fb);
+       if (ret) {
+               dev_err(&dev->dev, "Failed to set parameters\n");
+               goto failed_free_irq;
+       }
 
-       dev_set_drvdata(dev, fbi);
+       platform_set_drvdata(dev, fbi);
 
        ret = register_framebuffer(&fbi->fb);
        if (ret < 0) {
-               dev_err(dev, "Failed to register framebuffer device: %d\n", ret);
-               goto failed;
+               dev_err(&dev->dev,
+                       "Failed to register framebuffer device: %d\n", ret);
+               goto failed_free_cmap;
        }
 
-#ifdef CONFIG_PM
-       // TODO
-#endif
+       pxafb_overlay_init(fbi);
 
 #ifdef CONFIG_CPU_FREQ
        fbi->freq_transition.notifier_call = pxafb_freq_transition;
        fbi->freq_policy.notifier_call = pxafb_freq_policy;
-       cpufreq_register_notifier(&fbi->freq_transition, CPUFREQ_TRANSITION_NOTIFIER);
-       cpufreq_register_notifier(&fbi->freq_policy, CPUFREQ_POLICY_NOTIFIER);
+       cpufreq_register_notifier(&fbi->freq_transition,
+                               CPUFREQ_TRANSITION_NOTIFIER);
+       cpufreq_register_notifier(&fbi->freq_policy,
+                               CPUFREQ_POLICY_NOTIFIER);
 #endif
 
        /*
@@ -1342,50 +2203,94 @@ int __init pxafb_probe(struct device *dev)
 
        return 0;
 
-failed:
-       dev_set_drvdata(dev, NULL);
+failed_free_cmap:
+       if (fbi->fb.cmap.len)
+               fb_dealloc_cmap(&fbi->fb.cmap);
+failed_free_irq:
+       free_irq(irq, fbi);
+failed_free_mem:
+       free_pages_exact(fbi->video_mem, fbi->video_mem_size);
+failed_free_dma:
+       dma_free_coherent(&dev->dev, fbi->dma_buff_size,
+                       fbi->dma_buff, fbi->dma_buff_phys);
+failed_free_io:
+       iounmap(fbi->mmio_base);
+failed_free_res:
+       release_mem_region(r->start, resource_size(r));
+failed_fbi:
+       clk_put(fbi->clk);
+       platform_set_drvdata(dev, NULL);
        kfree(fbi);
+failed:
        return ret;
 }
 
-static struct device_driver pxafb_driver = {
-       .name           = "pxa2xx-fb",
-       .bus            = &platform_bus_type,
+static int __devexit pxafb_remove(struct platform_device *dev)
+{
+       struct pxafb_info *fbi = platform_get_drvdata(dev);
+       struct resource *r;
+       int irq;
+       struct fb_info *info;
+
+       if (!fbi)
+               return 0;
+
+       info = &fbi->fb;
+
+       pxafb_overlay_exit(fbi);
+       unregister_framebuffer(info);
+
+       pxafb_disable_controller(fbi);
+
+       if (fbi->fb.cmap.len)
+               fb_dealloc_cmap(&fbi->fb.cmap);
+
+       irq = platform_get_irq(dev, 0);
+       free_irq(irq, fbi);
+
+       free_pages_exact(fbi->video_mem, fbi->video_mem_size);
+
+       dma_free_writecombine(&dev->dev, fbi->dma_buff_size,
+                       fbi->dma_buff, fbi->dma_buff_phys);
+
+       iounmap(fbi->mmio_base);
+
+       r = platform_get_resource(dev, IORESOURCE_MEM, 0);
+       release_mem_region(r->start, resource_size(r));
+
+       clk_put(fbi->clk);
+       kfree(fbi);
+
+       return 0;
+}
+
+static struct platform_driver pxafb_driver = {
        .probe          = pxafb_probe,
+       .remove         = __devexit_p(pxafb_remove),
+       .driver         = {
+               .owner  = THIS_MODULE,
+               .name   = "pxa2xx-fb",
 #ifdef CONFIG_PM
-       .suspend        = pxafb_suspend,
-       .resume         = pxafb_resume,
+               .pm     = &pxafb_pm_ops,
 #endif
+       },
 };
 
-#ifndef MODULE
-int __devinit pxafb_setup(char *options)
+static int __init pxafb_init(void)
 {
-# ifdef CONFIG_FB_PXA_PARAMETERS
-       strlcpy(g_options, options, sizeof(g_options));
-# endif
-       return 0;
+       if (pxafb_setup_options())
+               return -EINVAL;
+
+       return platform_driver_register(&pxafb_driver);
 }
-#else
-# ifdef CONFIG_FB_PXA_PARAMETERS
-module_param_string(options, g_options, sizeof(g_options), 0);
-MODULE_PARM_DESC(options, "LCD parameters (see Documentation/fb/pxafb.txt)");
-# endif
-#endif
 
-int __devinit pxafb_init(void)
+static void __exit pxafb_exit(void)
 {
-#ifndef MODULE
-       char *option = NULL;
-
-       if (fb_get_options("pxafb", &option))
-               return -ENODEV;
-       pxafb_setup(option);
-#endif
-       return driver_register(&pxafb_driver);
+       platform_driver_unregister(&pxafb_driver);
 }
 
 module_init(pxafb_init);
+module_exit(pxafb_exit);
 
 MODULE_DESCRIPTION("loadable framebuffer driver for PXA");
 MODULE_LICENSE("GPL");