const: constify remaining dev_pm_ops
[safe/jmp/linux-2.6] / drivers / video / pxafb.c
index 7935706..b7e5805 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/module.h>
@@ -49,7 +59,6 @@
 #include <asm/io.h>
 #include <asm/irq.h>
 #include <asm/div64.h>
-#include <mach/pxa-regs.h>
 #include <mach/bitfield.h>
 #include <mach/pxafb.h>
 
 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, int branch);
+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);
 
 static unsigned long video_mem_size = 0;
 
@@ -386,6 +398,7 @@ static void pxafb_setmode(struct fb_var_screeninfo *var,
        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);
@@ -520,12 +533,22 @@ 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;
 
-       setup_base_frame(fbi, 1);
+       /* 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);
@@ -581,6 +604,346 @@ static struct fb_ops pxafb_ops = {
        .fb_blank       = pxafb_blank,
 };
 
+#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.
@@ -660,7 +1023,7 @@ unsigned long pxafb_get_hsync_time(struct device *dev)
 EXPORT_SYMBOL(pxafb_get_hsync_time);
 
 static int setup_frame_dma(struct pxafb_info *fbi, int dma, int pal,
-               unsigned int offset, size_t size)
+                          unsigned long start, size_t size)
 {
        struct pxafb_dma_descriptor *dma_desc, *pal_desc;
        unsigned int dma_desc_off, pal_desc_off;
@@ -671,7 +1034,7 @@ static int setup_frame_dma(struct pxafb_info *fbi, int dma, int pal,
        dma_desc = &fbi->dma_buff->dma_desc[dma];
        dma_desc_off = offsetof(struct pxafb_dma_buff, dma_desc[dma]);
 
-       dma_desc->fsadr = fbi->video_mem_phys + offset;
+       dma_desc->fsadr = start;
        dma_desc->fidr  = 0;
        dma_desc->ldcmd = size;
 
@@ -701,18 +1064,19 @@ static int setup_frame_dma(struct pxafb_info *fbi, int dma, int pal,
        return 0;
 }
 
-static void setup_base_frame(struct pxafb_info *fbi, int branch)
+static void setup_base_frame(struct pxafb_info *fbi,
+                             struct fb_var_screeninfo *var,
+                             int branch)
 {
-       struct fb_var_screeninfo *var = &fbi->fb.var;
        struct fb_fix_screeninfo *fix = &fbi->fb.fix;
-       unsigned int nbytes, offset;
-       int dma, pal, bpp = var->bits_per_pixel;
+       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;
+       offset = fix->line_length * var->yoffset + fbi->video_mem_phys;
 
        if (fbi->lccr0 & LCCR0_SDS) {
                nbytes = nbytes / 2;
@@ -981,7 +1345,7 @@ static int pxafb_activate_var(struct fb_var_screeninfo *var,
 #endif
                setup_parallel_timing(fbi, var);
 
-       setup_base_frame(fbi, 0);
+       setup_base_frame(fbi, var, 0);
 
        fbi->reg_lccr0 = fbi->lccr0 |
                (LCCR0_LDM | LCCR0_SFM | LCCR0_IUM | LCCR0_EFM |
@@ -1090,8 +1454,9 @@ static void pxafb_disable_controller(struct pxafb_info *fbi)
 static irqreturn_t pxafb_handle_irq(int irq, void *dev_id)
 {
        struct pxafb_info *fbi = dev_id;
-       unsigned int lccr0, lcsr = lcd_readl(fbi, LCSR);
+       unsigned int lccr0, lcsr;
 
+       lcsr = lcd_readl(fbi, LCSR);
        if (lcsr & LCSR_LDD) {
                lccr0 = lcd_readl(fbi, LCCR0);
                lcd_writel(fbi, LCCR0, lccr0 | LCCR0_LDM);
@@ -1102,8 +1467,20 @@ static irqreturn_t pxafb_handle_irq(int irq, void *dev_id)
        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;
 }
 
@@ -1274,24 +1651,26 @@ 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 platform_device *dev, pm_message_t state)
+static int pxafb_suspend(struct device *dev)
 {
-       struct pxafb_info *fbi = platform_get_drvdata(dev);
+       struct pxafb_info *fbi = dev_get_drvdata(dev);
 
        set_ctrlr_state(fbi, C_DISABLE_PM);
        return 0;
 }
 
-static int pxafb_resume(struct platform_device *dev)
+static int pxafb_resume(struct device *dev)
 {
-       struct pxafb_info *fbi = platform_get_drvdata(dev);
+       struct pxafb_info *fbi = dev_get_drvdata(dev);
 
        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
 
 static int __devinit pxafb_init_video_memory(struct pxafb_info *fbi)
@@ -1391,7 +1770,7 @@ static struct pxafb_info * __devinit pxafb_init_fbinfo(struct device *dev)
        memset(fbi, 0, sizeof(struct pxafb_info));
        fbi->dev = dev;
 
-       fbi->clk = clk_get(dev, "LCDCLK");
+       fbi->clk = clk_get(dev, NULL);
        if (IS_ERR(fbi->clk)) {
                kfree(fbi);
                return NULL;
@@ -1717,6 +2096,9 @@ static int __devinit pxafb_probe(struct platform_device *dev)
                goto failed;
        }
 
+       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;
 
@@ -1727,14 +2109,14 @@ static int __devinit pxafb_probe(struct platform_device *dev)
                goto failed_fbi;
        }
 
-       r = request_mem_region(r->start, r->end - r->start + 1, dev->name);
+       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, r->end - r->start + 1);
+       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;
@@ -1802,6 +2184,8 @@ static int __devinit pxafb_probe(struct platform_device *dev)
                goto failed_free_cmap;
        }
 
+       pxafb_overlay_init(fbi);
+
 #ifdef CONFIG_CPU_FREQ
        fbi->freq_transition.notifier_call = pxafb_freq_transition;
        fbi->freq_policy.notifier_call = pxafb_freq_policy;
@@ -1831,7 +2215,7 @@ failed_free_dma:
 failed_free_io:
        iounmap(fbi->mmio_base);
 failed_free_res:
-       release_mem_region(r->start, r->end - r->start + 1);
+       release_mem_region(r->start, resource_size(r));
 failed_fbi:
        clk_put(fbi->clk);
        platform_set_drvdata(dev, NULL);
@@ -1852,6 +2236,7 @@ static int __devexit pxafb_remove(struct platform_device *dev)
 
        info = &fbi->fb;
 
+       pxafb_overlay_exit(fbi);
        unregister_framebuffer(info);
 
        pxafb_disable_controller(fbi);
@@ -1870,7 +2255,7 @@ static int __devexit pxafb_remove(struct platform_device *dev)
        iounmap(fbi->mmio_base);
 
        r = platform_get_resource(dev, IORESOURCE_MEM, 0);
-       release_mem_region(r->start, r->end - r->start + 1);
+       release_mem_region(r->start, resource_size(r));
 
        clk_put(fbi->clk);
        kfree(fbi);
@@ -1880,12 +2265,13 @@ static int __devexit pxafb_remove(struct platform_device *dev)
 
 static struct platform_driver pxafb_driver = {
        .probe          = pxafb_probe,
-       .remove         = pxafb_remove,
-       .suspend        = pxafb_suspend,
-       .resume         = pxafb_resume,
+       .remove         = __devexit_p(pxafb_remove),
        .driver         = {
                .owner  = THIS_MODULE,
                .name   = "pxa2xx-fb",
+#ifdef CONFIG_PM
+               .pm     = &pxafb_pm_ops,
+#endif
        },
 };