i2c: tegra: Add stub runtime power management
[linux-2.6.git] / drivers / video / s3c-fb.c
index 77f5765..4aecf21 100644 (file)
@@ -21,6 +21,9 @@
 #include <linux/clk.h>
 #include <linux/fb.h>
 #include <linux/io.h>
+#include <linux/uaccess.h>
+#include <linux/interrupt.h>
+#include <linux/pm_runtime.h>
 
 #include <mach/map.h>
 #include <plat/regs-fb-v4.h>
 #undef writel
 #define writel(v, r) do { \
        printk(KERN_DEBUG "%s: %08x => %p\n", __func__, (unsigned int)v, r); \
-       __raw_writel(v, r); } while(0)
+       __raw_writel(v, r); } while (0)
 #endif /* FB_S3C_DEBUG_REGWRITE */
 
+/* irq_flags bits */
+#define S3C_FB_VSYNC_IRQ_EN    0
+
+#define VSYNC_TIMEOUT_MSEC 50
+
 struct s3c_fb;
 
 #define VALID_BPP(x) (1 << ((x) - 1))
@@ -71,6 +79,8 @@ struct s3c_fb;
  * @buf_end: Offset of buffer end registers.
  * @osd: The base for the OSD registers.
  * @palette: Address of palette memory, or 0 if none.
+ * @has_prtcon: Set if has PRTCON register.
+ * @has_shadowcon: Set if has SHADOWCON register.
  */
 struct s3c_fb_variant {
        unsigned int    is_2443:1;
@@ -85,14 +95,20 @@ struct s3c_fb_variant {
        unsigned short  osd;
        unsigned short  osd_stride;
        unsigned short  palette[S3C_FB_MAX_WIN];
+
+       unsigned int    has_prtcon:1;
+       unsigned int    has_shadowcon:1;
 };
 
 /**
  * struct s3c_fb_win_variant
  * @has_osd_c: Set if has OSD C register.
  * @has_osd_d: Set if has OSD D register.
+ * @has_osd_alpha: Set if can change alpha transparency for a window.
  * @palette_sz: Size of palette in entries.
  * @palette_16bpp: Set if palette is 16bits wide.
+ * @osd_size_off: If != 0, supports setting up OSD for a window; the appropriate
+ *                register is located at the given offset from OSD_BASE.
  * @valid_bpp: 1 bit per BPP setting to show valid bits-per-pixel.
  *
  * valid_bpp bit x is set if (x+1)BPP is supported.
@@ -100,7 +116,9 @@ struct s3c_fb_variant {
 struct s3c_fb_win_variant {
        unsigned int    has_osd_c:1;
        unsigned int    has_osd_d:1;
+       unsigned int    has_osd_alpha:1;
        unsigned int    palette_16bpp:1;
+       unsigned short  osd_size_off;
        unsigned short  palette_sz;
        u32             valid_bpp;
 };
@@ -153,7 +171,18 @@ struct s3c_fb_win {
 };
 
 /**
+ * struct s3c_fb_vsync - vsync information
+ * @wait:      a queue for processes waiting for vsync
+ * @count:     vsync interrupt count
+ */
+struct s3c_fb_vsync {
+       wait_queue_head_t       wait;
+       unsigned int            count;
+};
+
+/**
  * struct s3c_fb - overall hardware state of the hardware
+ * @slock: The spinlock protection for this data sturcture.
  * @dev: The device that we bound to, for printing, etc.
  * @regs_res: The resource we claimed for the IO registers.
  * @bus_clk: The clk (hclk) feeding our interface and possibly pixclk.
@@ -162,8 +191,12 @@ struct s3c_fb_win {
  * @enabled: A bitmask of enabled hardware windows.
  * @pdata: The platform configuration data passed with the device.
  * @windows: The hardware windows that have been claimed.
+ * @irq_no: IRQ line number
+ * @irq_flags: irq flags
+ * @vsync_info: VSYNC-related information (count, queues...)
  */
 struct s3c_fb {
+       spinlock_t              slock;
        struct device           *dev;
        struct resource         *regs_res;
        struct clk              *bus_clk;
@@ -174,6 +207,10 @@ struct s3c_fb {
 
        struct s3c_fb_platdata  *pdata;
        struct s3c_fb_win       *windows[S3C_FB_MAX_WIN];
+
+       int                      irq_no;
+       unsigned long            irq_flags;
+       struct s3c_fb_vsync      vsync_info;
 };
 
 /**
@@ -198,13 +235,12 @@ static int s3c_fb_check_var(struct fb_var_screeninfo *var,
                            struct fb_info *info)
 {
        struct s3c_fb_win *win = info->par;
-       struct s3c_fb_pd_win *windata = win->windata;
        struct s3c_fb *sfb = win->parent;
 
        dev_dbg(sfb->dev, "checking parameters\n");
 
-       var->xres_virtual = max((unsigned int)windata->virtual_x, var->xres);
-       var->yres_virtual = max((unsigned int)windata->virtual_y, var->yres);
+       var->xres_virtual = max(var->xres_virtual, var->xres);
+       var->yres_virtual = max(var->yres_virtual, var->yres);
 
        if (!s3c_fb_validate_win_bpp(win, var->bits_per_pixel)) {
                dev_dbg(sfb->dev, "win %d: unsupported bpp %d\n",
@@ -265,6 +301,7 @@ static int s3c_fb_check_var(struct fb_var_screeninfo *var,
                var->blue.length        = 5;
                break;
 
+       case 32:
        case 28:
        case 25:
                var->transp.length      = var->bits_per_pixel - 24;
@@ -273,7 +310,6 @@ static int s3c_fb_check_var(struct fb_var_screeninfo *var,
        case 24:
                /* our 24bpp is unpacked, so 32bpp */
                var->bits_per_pixel     = 32;
-       case 32:
                var->red.offset         = 16;
                var->red.length         = 8;
                var->green.offset       = 8;
@@ -336,6 +372,66 @@ static int s3c_fb_align_word(unsigned int bpp, unsigned int pix)
 }
 
 /**
+ * vidosd_set_size() - set OSD size for a window
+ *
+ * @win: the window to set OSD size for
+ * @size: OSD size register value
+ */
+static void vidosd_set_size(struct s3c_fb_win *win, u32 size)
+{
+       struct s3c_fb *sfb = win->parent;
+
+       /* OSD can be set up if osd_size_off != 0 for this window */
+       if (win->variant.osd_size_off)
+               writel(size, sfb->regs + OSD_BASE(win->index, sfb->variant)
+                               + win->variant.osd_size_off);
+}
+
+/**
+ * vidosd_set_alpha() - set alpha transparency for a window
+ *
+ * @win: the window to set OSD size for
+ * @alpha: alpha register value
+ */
+static void vidosd_set_alpha(struct s3c_fb_win *win, u32 alpha)
+{
+       struct s3c_fb *sfb = win->parent;
+
+       if (win->variant.has_osd_alpha)
+               writel(alpha, sfb->regs + VIDOSD_C(win->index, sfb->variant));
+}
+
+/**
+ * shadow_protect_win() - disable updating values from shadow registers at vsync
+ *
+ * @win: window to protect registers for
+ * @protect: 1 to protect (disable updates)
+ */
+static void shadow_protect_win(struct s3c_fb_win *win, bool protect)
+{
+       struct s3c_fb *sfb = win->parent;
+       u32 reg;
+
+       if (protect) {
+               if (sfb->variant.has_prtcon) {
+                       writel(PRTCON_PROTECT, sfb->regs + PRTCON);
+               } else if (sfb->variant.has_shadowcon) {
+                       reg = readl(sfb->regs + SHADOWCON);
+                       writel(reg | SHADOWCON_WINx_PROTECT(win->index),
+                               sfb->regs + SHADOWCON);
+               }
+       } else {
+               if (sfb->variant.has_prtcon) {
+                       writel(0, sfb->regs + PRTCON);
+               } else if (sfb->variant.has_shadowcon) {
+                       reg = readl(sfb->regs + SHADOWCON);
+                       writel(reg & ~SHADOWCON_WINx_PROTECT(win->index),
+                               sfb->regs + SHADOWCON);
+               }
+       }
+}
+
+/**
  * s3c_fb_set_par() - framebuffer request to set new framebuffer state.
  * @info: The framebuffer to change.
  *
@@ -349,13 +445,15 @@ static int s3c_fb_set_par(struct fb_info *info)
        void __iomem *regs = sfb->regs;
        void __iomem *buf = regs;
        int win_no = win->index;
-       u32 osdc_data = 0;
+       u32 alpha = 0;
        u32 data;
        u32 pagewidth;
        int clkdiv;
 
        dev_dbg(sfb->dev, "setting framebuffer parameters\n");
 
+       shadow_protect_win(win, 1);
+
        switch (var->bits_per_pixel) {
        case 32:
        case 24:
@@ -379,6 +477,9 @@ static int s3c_fb_set_par(struct fb_info *info)
 
        info->fix.line_length = (var->xres_virtual * var->bits_per_pixel) / 8;
 
+       info->fix.xpanstep = info->var.xres_virtual > info->var.xres ? 1 : 0;
+       info->fix.ypanstep = info->var.yres_virtual > info->var.yres ? 1 : 0;
+
        /* disable the window whilst we update it */
        writel(0, regs + WINCON(win_no));
 
@@ -418,7 +519,7 @@ static int s3c_fb_set_par(struct fb_info *info)
 
                data = VIDTCON2_LINEVAL(var->yres - 1) |
                       VIDTCON2_HOZVAL(var->xres - 1);
-               writel(data, regs +sfb->variant.vidtcon + 8 );
+               writel(data, regs + sfb->variant.vidtcon + 8);
        }
 
        /* write the buffer address */
@@ -449,15 +550,19 @@ static int s3c_fb_set_par(struct fb_info *info)
 
        data = var->xres * var->yres;
 
-       osdc_data = VIDISD14C_ALPHA1_R(0xf) |
+       alpha = VIDISD14C_ALPHA1_R(0xf) |
                VIDISD14C_ALPHA1_G(0xf) |
                VIDISD14C_ALPHA1_B(0xf);
 
-       if (win->variant.has_osd_d) {
-               writel(data, regs + VIDOSD_D(win_no, sfb->variant));
-               writel(osdc_data, regs + VIDOSD_C(win_no, sfb->variant));
-       } else
-               writel(data, regs + VIDOSD_C(win_no, sfb->variant));
+       vidosd_set_alpha(win, alpha);
+       vidosd_set_size(win, data);
+
+       /* Enable DMA channel for this window */
+       if (sfb->variant.has_shadowcon) {
+               data = readl(sfb->regs + SHADOWCON);
+               data |= SHADOWCON_CHx_ENABLE(win_no);
+               writel(data, sfb->regs + SHADOWCON);
+       }
 
        data = WINCONx_ENWIN;
 
@@ -538,6 +643,8 @@ static int s3c_fb_set_par(struct fb_info *info)
        writel(data, regs + sfb->variant.wincon + (win_no * 4));
        writel(0x0, regs + sfb->variant.winmap + (win_no * 4));
 
+       shadow_protect_win(win, 0);
+
        return 0;
 }
 
@@ -735,8 +842,206 @@ static int s3c_fb_blank(int blank_mode, struct fb_info *info)
        return 0;
 }
 
+/**
+ * s3c_fb_pan_display() - Pan the display.
+ *
+ * Note that the offsets can be written to the device at any time, as their
+ * values are latched at each vsync automatically. This also means that only
+ * the last call to this function will have any effect on next vsync, but
+ * there is no need to sleep waiting for it to prevent tearing.
+ *
+ * @var: The screen information to verify.
+ * @info: The framebuffer device.
+ */
+static int s3c_fb_pan_display(struct fb_var_screeninfo *var,
+                             struct fb_info *info)
+{
+       struct s3c_fb_win *win  = info->par;
+       struct s3c_fb *sfb      = win->parent;
+       void __iomem *buf       = sfb->regs + win->index * 8;
+       unsigned int start_boff, end_boff;
+
+       /* Offset in bytes to the start of the displayed area */
+       start_boff = var->yoffset * info->fix.line_length;
+       /* X offset depends on the current bpp */
+       if (info->var.bits_per_pixel >= 8) {
+               start_boff += var->xoffset * (info->var.bits_per_pixel >> 3);
+       } else {
+               switch (info->var.bits_per_pixel) {
+               case 4:
+                       start_boff += var->xoffset >> 1;
+                       break;
+               case 2:
+                       start_boff += var->xoffset >> 2;
+                       break;
+               case 1:
+                       start_boff += var->xoffset >> 3;
+                       break;
+               default:
+                       dev_err(sfb->dev, "invalid bpp\n");
+                       return -EINVAL;
+               }
+       }
+       /* Offset in bytes to the end of the displayed area */
+       end_boff = start_boff + var->yres * info->fix.line_length;
+
+       /* Temporarily turn off per-vsync update from shadow registers until
+        * both start and end addresses are updated to prevent corruption */
+       shadow_protect_win(win, 1);
+
+       writel(info->fix.smem_start + start_boff, buf + sfb->variant.buf_start);
+       writel(info->fix.smem_start + end_boff, buf + sfb->variant.buf_end);
+
+       shadow_protect_win(win, 0);
+
+       return 0;
+}
+
+/**
+ * s3c_fb_enable_irq() - enable framebuffer interrupts
+ * @sfb: main hardware state
+ */
+static void s3c_fb_enable_irq(struct s3c_fb *sfb)
+{
+       void __iomem *regs = sfb->regs;
+       u32 irq_ctrl_reg;
+
+       if (!test_and_set_bit(S3C_FB_VSYNC_IRQ_EN, &sfb->irq_flags)) {
+               /* IRQ disabled, enable it */
+               irq_ctrl_reg = readl(regs + VIDINTCON0);
+
+               irq_ctrl_reg |= VIDINTCON0_INT_ENABLE;
+               irq_ctrl_reg |= VIDINTCON0_INT_FRAME;
+
+               irq_ctrl_reg &= ~VIDINTCON0_FRAMESEL0_MASK;
+               irq_ctrl_reg |= VIDINTCON0_FRAMESEL0_VSYNC;
+               irq_ctrl_reg &= ~VIDINTCON0_FRAMESEL1_MASK;
+               irq_ctrl_reg |= VIDINTCON0_FRAMESEL1_NONE;
+
+               writel(irq_ctrl_reg, regs + VIDINTCON0);
+       }
+}
+
+/**
+ * s3c_fb_disable_irq() - disable framebuffer interrupts
+ * @sfb: main hardware state
+ */
+static void s3c_fb_disable_irq(struct s3c_fb *sfb)
+{
+       void __iomem *regs = sfb->regs;
+       u32 irq_ctrl_reg;
+
+       if (test_and_clear_bit(S3C_FB_VSYNC_IRQ_EN, &sfb->irq_flags)) {
+               /* IRQ enabled, disable it */
+               irq_ctrl_reg = readl(regs + VIDINTCON0);
+
+               irq_ctrl_reg &= ~VIDINTCON0_INT_FRAME;
+               irq_ctrl_reg &= ~VIDINTCON0_INT_ENABLE;
+
+               writel(irq_ctrl_reg, regs + VIDINTCON0);
+       }
+}
+
+static irqreturn_t s3c_fb_irq(int irq, void *dev_id)
+{
+       struct s3c_fb *sfb = dev_id;
+       void __iomem  *regs = sfb->regs;
+       u32 irq_sts_reg;
+
+       spin_lock(&sfb->slock);
+
+       irq_sts_reg = readl(regs + VIDINTCON1);
+
+       if (irq_sts_reg & VIDINTCON1_INT_FRAME) {
+
+               /* VSYNC interrupt, accept it */
+               writel(VIDINTCON1_INT_FRAME, regs + VIDINTCON1);
+
+               sfb->vsync_info.count++;
+               wake_up_interruptible(&sfb->vsync_info.wait);
+       }
+
+       /* We only support waiting for VSYNC for now, so it's safe
+        * to always disable irqs here.
+        */
+       s3c_fb_disable_irq(sfb);
+
+       spin_unlock(&sfb->slock);
+       return IRQ_HANDLED;
+}
+
+/**
+ * s3c_fb_wait_for_vsync() - sleep until next VSYNC interrupt or timeout
+ * @sfb: main hardware state
+ * @crtc: head index.
+ */
+static int s3c_fb_wait_for_vsync(struct s3c_fb *sfb, u32 crtc)
+{
+       unsigned long count;
+       int ret;
+
+       if (crtc != 0)
+               return -ENODEV;
+
+       count = sfb->vsync_info.count;
+       s3c_fb_enable_irq(sfb);
+       ret = wait_event_interruptible_timeout(sfb->vsync_info.wait,
+                                      count != sfb->vsync_info.count,
+                                      msecs_to_jiffies(VSYNC_TIMEOUT_MSEC));
+       if (ret == 0)
+               return -ETIMEDOUT;
+
+       return 0;
+}
+
+static int s3c_fb_ioctl(struct fb_info *info, unsigned int cmd,
+                       unsigned long arg)
+{
+       struct s3c_fb_win *win = info->par;
+       struct s3c_fb *sfb = win->parent;
+       int ret;
+       u32 crtc;
+
+       switch (cmd) {
+       case FBIO_WAITFORVSYNC:
+               if (get_user(crtc, (u32 __user *)arg)) {
+                       ret = -EFAULT;
+                       break;
+               }
+
+               ret = s3c_fb_wait_for_vsync(sfb, crtc);
+               break;
+       default:
+               ret = -ENOTTY;
+       }
+
+       return ret;
+}
+
+static int s3c_fb_open(struct fb_info *info, int user)
+{
+       struct s3c_fb_win *win = info->par;
+       struct s3c_fb *sfb = win->parent;
+
+       pm_runtime_get_sync(sfb->dev);
+
+       return 0;
+}
+
+static int s3c_fb_release(struct fb_info *info, int user)
+{
+       struct s3c_fb_win *win = info->par;
+       struct s3c_fb *sfb = win->parent;
+
+       pm_runtime_put_sync(sfb->dev);
+
+       return 0;
+}
+
 static struct fb_ops s3c_fb_ops = {
        .owner          = THIS_MODULE,
+       .fb_open        = s3c_fb_open,
+       .fb_release     = s3c_fb_release,
        .fb_check_var   = s3c_fb_check_var,
        .fb_set_par     = s3c_fb_set_par,
        .fb_blank       = s3c_fb_blank,
@@ -744,9 +1049,33 @@ static struct fb_ops s3c_fb_ops = {
        .fb_fillrect    = cfb_fillrect,
        .fb_copyarea    = cfb_copyarea,
        .fb_imageblit   = cfb_imageblit,
+       .fb_pan_display = s3c_fb_pan_display,
+       .fb_ioctl       = s3c_fb_ioctl,
 };
 
 /**
+ * s3c_fb_missing_pixclock() - calculates pixel clock
+ * @mode: The video mode to change.
+ *
+ * Calculate the pixel clock when none has been given through platform data.
+ */
+static void __devinit s3c_fb_missing_pixclock(struct fb_videomode *mode)
+{
+       u64 pixclk = 1000000000000ULL;
+       u32 div;
+
+       div  = mode->left_margin + mode->hsync_len + mode->right_margin +
+              mode->xres;
+       div *= mode->upper_margin + mode->vsync_len + mode->lower_margin +
+              mode->yres;
+       div *= mode->refresh ? : 60;
+
+       do_div(pixclk, div);
+
+       mode->pixclock = pixclk;
+}
+
+/**
  * s3c_fb_alloc_memory() - allocate display memory for framebuffer window
  * @sfb: The base resources for the hardware.
  * @win: The window to initialise memory for.
@@ -818,7 +1147,15 @@ static void s3c_fb_free_memory(struct s3c_fb *sfb, struct s3c_fb_win *win)
  */
 static void s3c_fb_release_win(struct s3c_fb *sfb, struct s3c_fb_win *win)
 {
+       u32 data;
+
        if (win->fbinfo) {
+               if (sfb->variant.has_shadowcon) {
+                       data = readl(sfb->regs + SHADOWCON);
+                       data &= ~SHADOWCON_CHx_ENABLE(win->index);
+                       data &= ~SHADOWCON_CHx_LOCAL_ENABLE(win->index);
+                       writel(data, sfb->regs + SHADOWCON);
+               }
                unregister_framebuffer(win->fbinfo);
                if (win->fbinfo->cmap.len)
                        fb_dealloc_cmap(&win->fbinfo->cmap);
@@ -850,6 +1187,8 @@ static int __devinit s3c_fb_probe_win(struct s3c_fb *sfb, unsigned int win_no,
 
        dev_dbg(sfb->dev, "probing window %d, variant %p\n", win_no, variant);
 
+       init_waitqueue_head(&sfb->vsync_info.wait);
+
        palette_size = variant->palette_sz * 4;
 
        fbinfo = framebuffer_alloc(sizeof(struct s3c_fb_win) +
@@ -957,15 +1296,19 @@ static int __devinit s3c_fb_probe_win(struct s3c_fb *sfb, unsigned int win_no,
 static void s3c_fb_clear_win(struct s3c_fb *sfb, int win)
 {
        void __iomem *regs = sfb->regs;
+       u32 reg;
 
        writel(0, regs + sfb->variant.wincon + (win * 4));
        writel(0, regs + VIDOSD_A(win, sfb->variant));
        writel(0, regs + VIDOSD_B(win, sfb->variant));
        writel(0, regs + VIDOSD_C(win, sfb->variant));
+       reg = readl(regs + SHADOWCON);
+       writel(reg & ~SHADOWCON_WINx_PROTECT(win), regs + SHADOWCON);
 }
 
 static int __devinit s3c_fb_probe(struct platform_device *pdev)
 {
+       const struct platform_device_id *platid;
        struct s3c_fb_driverdata *fbdrv;
        struct device *dev = &pdev->dev;
        struct s3c_fb_platdata *pd;
@@ -974,7 +1317,8 @@ static int __devinit s3c_fb_probe(struct platform_device *pdev)
        int win;
        int ret = 0;
 
-       fbdrv = (struct s3c_fb_driverdata *)platform_get_device_id(pdev)->driver_data;
+       platid = platform_get_device_id(pdev);
+       fbdrv = (struct s3c_fb_driverdata *)platid->driver_data;
 
        if (fbdrv->variant.nr_windows > S3C_FB_MAX_WIN) {
                dev_err(dev, "too many windows, cannot attach\n");
@@ -999,14 +1343,19 @@ static int __devinit s3c_fb_probe(struct platform_device *pdev)
        sfb->pdata = pd;
        sfb->variant = fbdrv->variant;
 
+       spin_lock_init(&sfb->slock);
+
        sfb->bus_clk = clk_get(dev, "lcd");
        if (IS_ERR(sfb->bus_clk)) {
                dev_err(dev, "failed to get bus clock\n");
+               ret = PTR_ERR(sfb->bus_clk);
                goto err_sfb;
        }
 
        clk_enable(sfb->bus_clk);
 
+       pm_runtime_enable(sfb->dev);
+
        res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
        if (!res) {
                dev_err(dev, "failed to find registers\n");
@@ -1029,8 +1378,25 @@ static int __devinit s3c_fb_probe(struct platform_device *pdev)
                goto err_req_region;
        }
 
+       res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
+       if (!res) {
+               dev_err(dev, "failed to acquire irq resource\n");
+               ret = -ENOENT;
+               goto err_ioremap;
+       }
+       sfb->irq_no = res->start;
+       ret = request_irq(sfb->irq_no, s3c_fb_irq,
+                         0, "s3c_fb", sfb);
+       if (ret) {
+               dev_err(dev, "irq request failed\n");
+               goto err_ioremap;
+       }
+
        dev_dbg(dev, "got resources (regs %p), probing windows\n", sfb->regs);
 
+       platform_set_drvdata(pdev, sfb);
+       pm_runtime_get_sync(sfb->dev);
+
        /* setup gpio and output polarity controls */
 
        pd->setup_gpio();
@@ -1057,26 +1423,32 @@ static int __devinit s3c_fb_probe(struct platform_device *pdev)
                if (!pd->win[win])
                        continue;
 
+               if (!pd->win[win]->win_mode.pixclock)
+                       s3c_fb_missing_pixclock(&pd->win[win]->win_mode);
+
                ret = s3c_fb_probe_win(sfb, win, fbdrv->win[win],
                                       &sfb->windows[win]);
                if (ret < 0) {
                        dev_err(dev, "failed to create window %d\n", win);
                        for (; win >= 0; win--)
                                s3c_fb_release_win(sfb, sfb->windows[win]);
-                       goto err_ioremap;
+                       goto err_irq;
                }
        }
 
        platform_set_drvdata(pdev, sfb);
+       pm_runtime_put_sync(sfb->dev);
 
        return 0;
 
+err_irq:
+       free_irq(sfb->irq_no, sfb);
+
 err_ioremap:
        iounmap(sfb->regs);
 
 err_req_region:
-       release_resource(sfb->regs_res);
-       kfree(sfb->regs_res);
+       release_mem_region(sfb->regs_res->start, resource_size(sfb->regs_res));
 
 err_clk:
        clk_disable(sfb->bus_clk);
@@ -1099,26 +1471,32 @@ static int __devexit s3c_fb_remove(struct platform_device *pdev)
        struct s3c_fb *sfb = platform_get_drvdata(pdev);
        int win;
 
+       pm_runtime_get_sync(sfb->dev);
+
        for (win = 0; win < S3C_FB_MAX_WIN; win++)
                if (sfb->windows[win])
                        s3c_fb_release_win(sfb, sfb->windows[win]);
 
+       free_irq(sfb->irq_no, sfb);
+
        iounmap(sfb->regs);
 
        clk_disable(sfb->bus_clk);
        clk_put(sfb->bus_clk);
 
-       release_resource(sfb->regs_res);
-       kfree(sfb->regs_res);
+       release_mem_region(sfb->regs_res->start, resource_size(sfb->regs_res));
 
-       kfree(sfb);
+       pm_runtime_put_sync(sfb->dev);
+       pm_runtime_disable(sfb->dev);
 
+       kfree(sfb);
        return 0;
 }
 
 #ifdef CONFIG_PM
-static int s3c_fb_suspend(struct platform_device *pdev, pm_message_t state)
+static int s3c_fb_suspend(struct device *dev)
 {
+       struct platform_device *pdev = to_platform_device(dev);
        struct s3c_fb *sfb = platform_get_drvdata(pdev);
        struct s3c_fb_win *win;
        int win_no;
@@ -1136,8 +1514,9 @@ static int s3c_fb_suspend(struct platform_device *pdev, pm_message_t state)
        return 0;
 }
 
-static int s3c_fb_resume(struct platform_device *pdev)
+static int s3c_fb_resume(struct device *dev)
 {
+       struct platform_device *pdev = to_platform_device(dev);
        struct s3c_fb *sfb = platform_get_drvdata(pdev);
        struct s3c_fb_platdata *pd = sfb->pdata;
        struct s3c_fb_win *win;
@@ -1145,7 +1524,8 @@ static int s3c_fb_resume(struct platform_device *pdev)
 
        clk_enable(sfb->bus_clk);
 
-       /* setup registers */
+       /* setup gpio and output polarity controls */
+       pd->setup_gpio();
        writel(pd->vidcon1, sfb->regs + VIDCON1);
 
        /* zero all windows before we do anything */
@@ -1172,58 +1552,188 @@ static int s3c_fb_resume(struct platform_device *pdev)
 
        return 0;
 }
+
+static int s3c_fb_runtime_suspend(struct device *dev)
+{
+       struct platform_device *pdev = to_platform_device(dev);
+       struct s3c_fb *sfb = platform_get_drvdata(pdev);
+       struct s3c_fb_win *win;
+       int win_no;
+
+       for (win_no = S3C_FB_MAX_WIN - 1; win_no >= 0; win_no--) {
+               win = sfb->windows[win_no];
+               if (!win)
+                       continue;
+
+               /* use the blank function to push into power-down */
+               s3c_fb_blank(FB_BLANK_POWERDOWN, win->fbinfo);
+       }
+
+       clk_disable(sfb->bus_clk);
+       return 0;
+}
+
+static int s3c_fb_runtime_resume(struct device *dev)
+{
+       struct platform_device *pdev = to_platform_device(dev);
+       struct s3c_fb *sfb = platform_get_drvdata(pdev);
+       struct s3c_fb_platdata *pd = sfb->pdata;
+       struct s3c_fb_win *win;
+       int win_no;
+
+       clk_enable(sfb->bus_clk);
+
+       /* setup gpio and output polarity controls */
+       pd->setup_gpio();
+       writel(pd->vidcon1, sfb->regs + VIDCON1);
+
+       /* zero all windows before we do anything */
+       for (win_no = 0; win_no < sfb->variant.nr_windows; win_no++)
+               s3c_fb_clear_win(sfb, win_no);
+
+       for (win_no = 0; win_no < sfb->variant.nr_windows - 1; win_no++) {
+               void __iomem *regs = sfb->regs + sfb->variant.keycon;
+
+               regs += (win_no * 8);
+               writel(0xffffff, regs + WKEYCON0);
+               writel(0xffffff, regs + WKEYCON1);
+       }
+
+       /* restore framebuffers */
+       for (win_no = 0; win_no < S3C_FB_MAX_WIN; win_no++) {
+               win = sfb->windows[win_no];
+               if (!win)
+                       continue;
+
+               dev_dbg(&pdev->dev, "resuming window %d\n", win_no);
+               s3c_fb_set_par(win->fbinfo);
+       }
+
+       return 0;
+}
+
 #else
 #define s3c_fb_suspend NULL
 #define s3c_fb_resume  NULL
+#define s3c_fb_runtime_suspend NULL
+#define s3c_fb_runtime_resume NULL
 #endif
 
 
 #define VALID_BPP124 (VALID_BPP(1) | VALID_BPP(2) | VALID_BPP(4))
 #define VALID_BPP1248 (VALID_BPP124 | VALID_BPP(8))
 
-static struct s3c_fb_win_variant s3c_fb_data_64xx_wins[] __devinitdata = {
+static struct s3c_fb_win_variant s3c_fb_data_64xx_wins[] = {
        [0] = {
                .has_osd_c      = 1,
+               .osd_size_off   = 0x8,
                .palette_sz     = 256,
-               .valid_bpp      = VALID_BPP1248 | VALID_BPP(16) | VALID_BPP(24),
+               .valid_bpp      = (VALID_BPP1248 | VALID_BPP(16) |
+                                  VALID_BPP(18) | VALID_BPP(24)),
        },
        [1] = {
                .has_osd_c      = 1,
                .has_osd_d      = 1,
+               .osd_size_off   = 0xc,
+               .has_osd_alpha  = 1,
                .palette_sz     = 256,
                .valid_bpp      = (VALID_BPP1248 | VALID_BPP(16) |
                                   VALID_BPP(18) | VALID_BPP(19) |
-                                  VALID_BPP(24) | VALID_BPP(25)),
+                                  VALID_BPP(24) | VALID_BPP(25) |
+                                  VALID_BPP(28)),
        },
        [2] = {
                .has_osd_c      = 1,
                .has_osd_d      = 1,
+               .osd_size_off   = 0xc,
+               .has_osd_alpha  = 1,
                .palette_sz     = 16,
                .palette_16bpp  = 1,
                .valid_bpp      = (VALID_BPP1248 | VALID_BPP(16) |
                                   VALID_BPP(18) | VALID_BPP(19) |
-                                  VALID_BPP(24) | VALID_BPP(25)),
+                                  VALID_BPP(24) | VALID_BPP(25) |
+                                  VALID_BPP(28)),
        },
        [3] = {
                .has_osd_c      = 1,
-               .has_osd_d      = 1,
+               .has_osd_alpha  = 1,
                .palette_sz     = 16,
                .palette_16bpp  = 1,
                .valid_bpp      = (VALID_BPP124  | VALID_BPP(16) |
                                   VALID_BPP(18) | VALID_BPP(19) |
-                                  VALID_BPP(24) | VALID_BPP(25)),
+                                  VALID_BPP(24) | VALID_BPP(25) |
+                                  VALID_BPP(28)),
        },
        [4] = {
                .has_osd_c      = 1,
+               .has_osd_alpha  = 1,
                .palette_sz     = 4,
                .palette_16bpp  = 1,
                .valid_bpp      = (VALID_BPP(1) | VALID_BPP(2) |
                                   VALID_BPP(16) | VALID_BPP(18) |
-                                  VALID_BPP(24) | VALID_BPP(25)),
+                                  VALID_BPP(19) | VALID_BPP(24) |
+                                  VALID_BPP(25) | VALID_BPP(28)),
+       },
+};
+
+static struct s3c_fb_win_variant s3c_fb_data_s5p_wins[] = {
+       [0] = {
+               .has_osd_c      = 1,
+               .osd_size_off   = 0x8,
+               .palette_sz     = 256,
+               .valid_bpp      = (VALID_BPP1248 | VALID_BPP(13) |
+                                  VALID_BPP(15) | VALID_BPP(16) |
+                                  VALID_BPP(18) | VALID_BPP(19) |
+                                  VALID_BPP(24) | VALID_BPP(25) |
+                                  VALID_BPP(32)),
+       },
+       [1] = {
+               .has_osd_c      = 1,
+               .has_osd_d      = 1,
+               .osd_size_off   = 0xc,
+               .has_osd_alpha  = 1,
+               .palette_sz     = 256,
+               .valid_bpp      = (VALID_BPP1248 | VALID_BPP(13) |
+                                  VALID_BPP(15) | VALID_BPP(16) |
+                                  VALID_BPP(18) | VALID_BPP(19) |
+                                  VALID_BPP(24) | VALID_BPP(25) |
+                                  VALID_BPP(32)),
+       },
+       [2] = {
+               .has_osd_c      = 1,
+               .has_osd_d      = 1,
+               .osd_size_off   = 0xc,
+               .has_osd_alpha  = 1,
+               .palette_sz     = 256,
+               .valid_bpp      = (VALID_BPP1248 | VALID_BPP(13) |
+                                  VALID_BPP(15) | VALID_BPP(16) |
+                                  VALID_BPP(18) | VALID_BPP(19) |
+                                  VALID_BPP(24) | VALID_BPP(25) |
+                                  VALID_BPP(32)),
+       },
+       [3] = {
+               .has_osd_c      = 1,
+               .has_osd_alpha  = 1,
+               .palette_sz     = 256,
+               .valid_bpp      = (VALID_BPP1248 | VALID_BPP(13) |
+                                  VALID_BPP(15) | VALID_BPP(16) |
+                                  VALID_BPP(18) | VALID_BPP(19) |
+                                  VALID_BPP(24) | VALID_BPP(25) |
+                                  VALID_BPP(32)),
+       },
+       [4] = {
+               .has_osd_c      = 1,
+               .has_osd_alpha  = 1,
+               .palette_sz     = 256,
+               .valid_bpp      = (VALID_BPP1248 | VALID_BPP(13) |
+                                  VALID_BPP(15) | VALID_BPP(16) |
+                                  VALID_BPP(18) | VALID_BPP(19) |
+                                  VALID_BPP(24) | VALID_BPP(25) |
+                                  VALID_BPP(32)),
        },
 };
 
-static struct s3c_fb_driverdata s3c_fb_data_64xx __devinitdata = {
+static struct s3c_fb_driverdata s3c_fb_data_64xx = {
        .variant = {
                .nr_windows     = 5,
                .vidtcon        = VIDTCON0,
@@ -1243,6 +1753,8 @@ static struct s3c_fb_driverdata s3c_fb_data_64xx __devinitdata = {
                        [3] = 0x320,
                        [4] = 0x340,
                },
+
+               .has_prtcon     = 1,
        },
        .win[0] = &s3c_fb_data_64xx_wins[0],
        .win[1] = &s3c_fb_data_64xx_wins[1],
@@ -1251,7 +1763,7 @@ static struct s3c_fb_driverdata s3c_fb_data_64xx __devinitdata = {
        .win[4] = &s3c_fb_data_64xx_wins[4],
 };
 
-static struct s3c_fb_driverdata s3c_fb_data_s5p __devinitdata = {
+static struct s3c_fb_driverdata s3c_fb_data_s5pc100 = {
        .variant = {
                .nr_windows     = 5,
                .vidtcon        = VIDTCON0,
@@ -1271,16 +1783,48 @@ static struct s3c_fb_driverdata s3c_fb_data_s5p __devinitdata = {
                        [3] = 0x3000,
                        [4] = 0x3400,
                },
+
+               .has_prtcon     = 1,
        },
-       .win[0] = &s3c_fb_data_64xx_wins[0],
-       .win[1] = &s3c_fb_data_64xx_wins[1],
-       .win[2] = &s3c_fb_data_64xx_wins[2],
-       .win[3] = &s3c_fb_data_64xx_wins[3],
-       .win[4] = &s3c_fb_data_64xx_wins[4],
+       .win[0] = &s3c_fb_data_s5p_wins[0],
+       .win[1] = &s3c_fb_data_s5p_wins[1],
+       .win[2] = &s3c_fb_data_s5p_wins[2],
+       .win[3] = &s3c_fb_data_s5p_wins[3],
+       .win[4] = &s3c_fb_data_s5p_wins[4],
+};
+
+static struct s3c_fb_driverdata s3c_fb_data_s5pv210 = {
+       .variant = {
+               .nr_windows     = 5,
+               .vidtcon        = VIDTCON0,
+               .wincon         = WINCON(0),
+               .winmap         = WINxMAP(0),
+               .keycon         = WKEYCON,
+               .osd            = VIDOSD_BASE,
+               .osd_stride     = 16,
+               .buf_start      = VIDW_BUF_START(0),
+               .buf_size       = VIDW_BUF_SIZE(0),
+               .buf_end        = VIDW_BUF_END(0),
+
+               .palette = {
+                       [0] = 0x2400,
+                       [1] = 0x2800,
+                       [2] = 0x2c00,
+                       [3] = 0x3000,
+                       [4] = 0x3400,
+               },
+
+               .has_shadowcon  = 1,
+       },
+       .win[0] = &s3c_fb_data_s5p_wins[0],
+       .win[1] = &s3c_fb_data_s5p_wins[1],
+       .win[2] = &s3c_fb_data_s5p_wins[2],
+       .win[3] = &s3c_fb_data_s5p_wins[3],
+       .win[4] = &s3c_fb_data_s5p_wins[4],
 };
 
 /* S3C2443/S3C2416 style hardware */
-static struct s3c_fb_driverdata s3c_fb_data_s3c2443 __devinitdata = {
+static struct s3c_fb_driverdata s3c_fb_data_s3c2443 = {
        .variant = {
                .nr_windows     = 2,
                .is_2443        = 1,
@@ -1306,6 +1850,7 @@ static struct s3c_fb_driverdata s3c_fb_data_s3c2443 __devinitdata = {
        },
        .win[1] = &(struct s3c_fb_win_variant) {
                .has_osd_c      = 1,
+               .has_osd_alpha  = 1,
                .palette_sz     = 256,
                .valid_bpp      = (VALID_BPP1248 | VALID_BPP(16) |
                                   VALID_BPP(18) | VALID_BPP(19) |
@@ -1319,8 +1864,11 @@ static struct platform_device_id s3c_fb_driver_ids[] = {
                .name           = "s3c-fb",
                .driver_data    = (unsigned long)&s3c_fb_data_64xx,
        }, {
-               .name           = "s5p-fb",
-               .driver_data    = (unsigned long)&s3c_fb_data_s5p,
+               .name           = "s5pc100-fb",
+               .driver_data    = (unsigned long)&s3c_fb_data_s5pc100,
+       }, {
+               .name           = "s5pv210-fb",
+               .driver_data    = (unsigned long)&s3c_fb_data_s5pv210,
        }, {
                .name           = "s3c2443-fb",
                .driver_data    = (unsigned long)&s3c_fb_data_s3c2443,
@@ -1329,15 +1877,21 @@ static struct platform_device_id s3c_fb_driver_ids[] = {
 };
 MODULE_DEVICE_TABLE(platform, s3c_fb_driver_ids);
 
+static const struct dev_pm_ops s3cfb_pm_ops = {
+       .suspend        = s3c_fb_suspend,
+       .resume         = s3c_fb_resume,
+       .runtime_suspend        = s3c_fb_runtime_suspend,
+       .runtime_resume         = s3c_fb_runtime_resume,
+};
+
 static struct platform_driver s3c_fb_driver = {
        .probe          = s3c_fb_probe,
        .remove         = __devexit_p(s3c_fb_remove),
-       .suspend        = s3c_fb_suspend,
-       .resume         = s3c_fb_resume,
        .id_table       = s3c_fb_driver_ids,
        .driver         = {
                .name   = "s3c-fb",
                .owner  = THIS_MODULE,
+               .pm     = &s3cfb_pm_ops,
        },
 };