]> git.karo-electronics.de Git - karo-tx-linux.git/blobdiff - drivers/gpu/drm/exynos/exynos_drm_fimd.c
Merge branch 'x86-vdso-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git...
[karo-tx-linux.git] / drivers / gpu / drm / exynos / exynos_drm_fimd.c
index ff1ba947700264e1da0c6b62944ccf64bfd24cd4..40fd6ccfcd6f7595671d750b57ea44066ddf4b87 100644 (file)
@@ -105,22 +105,18 @@ struct fimd_win_data {
 };
 
 struct fimd_context {
-       struct exynos_drm_subdrv        subdrv;
        struct device                   *dev;
        struct drm_device               *drm_dev;
-       int                             irq;
-       struct drm_crtc                 *crtc;
        struct clk                      *bus_clk;
        struct clk                      *lcd_clk;
        void __iomem                    *regs;
+       struct drm_display_mode         mode;
        struct fimd_win_data            win_data[WINDOWS_NR];
-       unsigned int                    clkdiv;
        unsigned int                    default_win;
        unsigned long                   irq_flags;
-       u32                             vidcon0;
        u32                             vidcon1;
        bool                            suspended;
-       struct mutex                    lock;
+       int                             pipe;
        wait_queue_head_t               wait_vsync_queue;
        atomic_t                        wait_vsync_event;
 
@@ -147,148 +143,141 @@ static inline struct fimd_driver_data *drm_fimd_get_driver_data(
        return (struct fimd_driver_data *)of_id->data;
 }
 
-static bool fimd_display_is_connected(struct device *dev)
+static int fimd_mgr_initialize(struct exynos_drm_manager *mgr,
+                       struct drm_device *drm_dev, int pipe)
 {
-       /* TODO. */
+       struct fimd_context *ctx = mgr->ctx;
 
-       return true;
-}
+       ctx->drm_dev = drm_dev;
+       ctx->pipe = pipe;
 
-static void *fimd_get_panel(struct device *dev)
-{
-       struct exynos_drm_manager *mgr = get_fimd_manager(dev);
-       struct fimd_context *ctx = mgr->ctx;
+       /*
+        * enable drm irq mode.
+        * - with irq_enabled = true, we can use the vblank feature.
+        *
+        * P.S. note that we wouldn't use drm irq handler but
+        *      just specific driver own one instead because
+        *      drm framework supports only one irq handler.
+        */
+       drm_dev->irq_enabled = true;
 
-       return &ctx->panel;
-}
+       /*
+        * with vblank_disable_allowed = true, vblank interrupt will be disabled
+        * by drm timer once a current process gives up ownership of
+        * vblank event.(after drm_vblank_put function is called)
+        */
+       drm_dev->vblank_disable_allowed = true;
 
-static int fimd_check_mode(struct device *dev, struct drm_display_mode *mode)
-{
-       /* TODO. */
+       /* attach this sub driver to iommu mapping if supported. */
+       if (is_drm_iommu_supported(ctx->drm_dev))
+               drm_iommu_attach_device(ctx->drm_dev, ctx->dev);
 
        return 0;
 }
 
-static struct exynos_drm_display_ops fimd_display_ops = {
-       .type = EXYNOS_DISPLAY_TYPE_LCD,
-       .is_connected = fimd_display_is_connected,
-       .get_panel = fimd_get_panel,
-       .check_mode = fimd_check_mode,
-};
-
-static int fimd_mgr_initialize(struct exynos_drm_manager *mgr,
-                       struct drm_device *drm_dev)
+static void fimd_mgr_remove(struct exynos_drm_manager *mgr)
 {
        struct fimd_context *ctx = mgr->ctx;
 
-       ctx->drm_dev = drm_dev;
-
-       return 0;
+       /* detach this sub driver from iommu mapping if supported. */
+       if (is_drm_iommu_supported(ctx->drm_dev))
+               drm_iommu_detach_device(ctx->drm_dev, ctx->dev);
 }
 
-static void fimd_dpms(struct exynos_drm_manager *mgr, int mode)
+static u32 fimd_calc_clkdiv(struct fimd_context *ctx,
+               const struct drm_display_mode *mode)
 {
-       struct fimd_context *ctx = mgr->ctx;
+       unsigned long ideal_clk = mode->htotal * mode->vtotal * mode->vrefresh;
+       u32 clkdiv;
 
-       DRM_DEBUG_KMS("%d\n", mode);
+       /* Find the clock divider value that gets us closest to ideal_clk */
+       clkdiv = DIV_ROUND_UP(clk_get_rate(ctx->lcd_clk), ideal_clk);
 
-       mutex_lock(&ctx->lock);
+       return (clkdiv < 0x100) ? clkdiv : 0xff;
+}
 
-       switch (mode) {
-       case DRM_MODE_DPMS_ON:
-               /*
-                * enable fimd hardware only if suspended status.
-                *
-                * P.S. fimd_dpms function would be called at booting time so
-                * clk_enable could be called double time.
-                */
-               if (ctx->suspended)
-                       pm_runtime_get_sync(ctx->dev);
-               break;
-       case DRM_MODE_DPMS_STANDBY:
-       case DRM_MODE_DPMS_SUSPEND:
-       case DRM_MODE_DPMS_OFF:
-               if (!ctx->suspended)
-                       pm_runtime_put_sync(ctx->dev);
-               break;
-       default:
-               DRM_DEBUG_KMS("unspecified mode %d\n", mode);
-               break;
-       }
+static bool fimd_mode_fixup(struct exynos_drm_manager *mgr,
+               const struct drm_display_mode *mode,
+               struct drm_display_mode *adjusted_mode)
+{
+       if (adjusted_mode->vrefresh == 0)
+               adjusted_mode->vrefresh = FIMD_DEFAULT_FRAMERATE;
 
-       mutex_unlock(&ctx->lock);
+       return true;
 }
 
-static void fimd_apply(struct exynos_drm_manager *mgr)
+static void fimd_mode_set(struct exynos_drm_manager *mgr,
+               const struct drm_display_mode *in_mode)
 {
        struct fimd_context *ctx = mgr->ctx;
-       struct exynos_drm_manager_ops *mgr_ops = mgr->ops;
-       struct fimd_win_data *win_data;
-       int i;
-
-       for (i = 0; i < WINDOWS_NR; i++) {
-               win_data = &ctx->win_data[i];
-               if (win_data->enabled && (mgr_ops && mgr_ops->win_commit))
-                       mgr_ops->win_commit(mgr, i);
-       }
 
-       if (mgr_ops && mgr_ops->commit)
-               mgr_ops->commit(mgr);
+       drm_mode_copy(&ctx->mode, in_mode);
 }
 
 static void fimd_commit(struct exynos_drm_manager *mgr)
 {
        struct fimd_context *ctx = mgr->ctx;
-       struct exynos_drm_panel_info *panel = &ctx->panel;
-       struct videomode *vm = &panel->vm;
+       struct drm_display_mode *mode = &ctx->mode;
        struct fimd_driver_data *driver_data;
-       u32 val;
+       u32 val, clkdiv, vidcon1;
+       int vsync_len, vbpd, vfpd, hsync_len, hbpd, hfpd;
 
        driver_data = ctx->driver_data;
        if (ctx->suspended)
                return;
 
-       /* setup polarity values from machine code. */
-       writel(ctx->vidcon1, ctx->regs + driver_data->timing_base + VIDCON1);
+       /* nothing to do if we haven't set the mode yet */
+       if (mode->htotal == 0 || mode->vtotal == 0)
+               return;
+
+       /* setup polarity values */
+       vidcon1 = ctx->vidcon1;
+       if (mode->flags & DRM_MODE_FLAG_NVSYNC)
+               vidcon1 |= VIDCON1_INV_VSYNC;
+       if (mode->flags & DRM_MODE_FLAG_NHSYNC)
+               vidcon1 |= VIDCON1_INV_HSYNC;
+       writel(vidcon1, ctx->regs + driver_data->timing_base + VIDCON1);
 
        /* setup vertical timing values. */
-       val = VIDTCON0_VBPD(vm->vback_porch - 1) |
-              VIDTCON0_VFPD(vm->vfront_porch - 1) |
-              VIDTCON0_VSPW(vm->vsync_len - 1);
+       vsync_len = mode->crtc_vsync_end - mode->crtc_vsync_start;
+       vbpd = mode->crtc_vtotal - mode->crtc_vsync_end;
+       vfpd = mode->crtc_vsync_start - mode->crtc_vdisplay;
+
+       val = VIDTCON0_VBPD(vbpd - 1) |
+               VIDTCON0_VFPD(vfpd - 1) |
+               VIDTCON0_VSPW(vsync_len - 1);
        writel(val, ctx->regs + driver_data->timing_base + VIDTCON0);
 
        /* setup horizontal timing values.  */
-       val = VIDTCON1_HBPD(vm->hback_porch - 1) |
-              VIDTCON1_HFPD(vm->hfront_porch - 1) |
-              VIDTCON1_HSPW(vm->hsync_len - 1);
+       hsync_len = mode->crtc_hsync_end - mode->crtc_hsync_start;
+       hbpd = mode->crtc_htotal - mode->crtc_hsync_end;
+       hfpd = mode->crtc_hsync_start - mode->crtc_hdisplay;
+
+       val = VIDTCON1_HBPD(hbpd - 1) |
+               VIDTCON1_HFPD(hfpd - 1) |
+               VIDTCON1_HSPW(hsync_len - 1);
        writel(val, ctx->regs + driver_data->timing_base + VIDTCON1);
 
        /* setup horizontal and vertical display size. */
-       val = VIDTCON2_LINEVAL(vm->vactive - 1) |
-              VIDTCON2_HOZVAL(vm->hactive - 1) |
-              VIDTCON2_LINEVAL_E(vm->vactive - 1) |
-              VIDTCON2_HOZVAL_E(vm->hactive - 1);
+       val = VIDTCON2_LINEVAL(mode->vdisplay - 1) |
+              VIDTCON2_HOZVAL(mode->hdisplay - 1) |
+              VIDTCON2_LINEVAL_E(mode->vdisplay - 1) |
+              VIDTCON2_HOZVAL_E(mode->hdisplay - 1);
        writel(val, ctx->regs + driver_data->timing_base + VIDTCON2);
 
-       /* setup clock source, clock divider, enable dma. */
-       val = ctx->vidcon0;
-       val &= ~(VIDCON0_CLKVAL_F_MASK | VIDCON0_CLKDIR);
-
-       if (ctx->driver_data->has_clksel) {
-               val &= ~VIDCON0_CLKSEL_MASK;
-               val |= VIDCON0_CLKSEL_LCD;
-       }
-
-       if (ctx->clkdiv > 1)
-               val |= VIDCON0_CLKVAL_F(ctx->clkdiv - 1) | VIDCON0_CLKDIR;
-       else
-               val &= ~VIDCON0_CLKDIR; /* 1:1 clock */
-
        /*
         * fields of register with prefix '_F' would be updated
         * at vsync(same as dma start)
         */
-       val |= VIDCON0_ENVID | VIDCON0_ENVID_F;
+       val = VIDCON0_ENVID | VIDCON0_ENVID_F;
+
+       if (ctx->driver_data->has_clksel)
+               val |= VIDCON0_CLKSEL_LCD;
+
+       clkdiv = fimd_calc_clkdiv(ctx, mode);
+       if (clkdiv > 1)
+               val |= VIDCON0_CLKVAL_F(clkdiv - 1) | VIDCON0_CLKDIR;
+
        writel(val, ctx->regs + VIDCON0);
 }
 
@@ -520,6 +509,12 @@ static void fimd_win_commit(struct exynos_drm_manager *mgr, int zpos)
 
        win_data = &ctx->win_data[win];
 
+       /* If suspended, enable this on resume */
+       if (ctx->suspended) {
+               win_data->resume = true;
+               return;
+       }
+
        /*
         * SHADOWCON/PRTCON register is used for enabling timing.
         *
@@ -661,136 +656,6 @@ static void fimd_win_disable(struct exynos_drm_manager *mgr, int zpos)
        win_data->enabled = false;
 }
 
-static struct exynos_drm_manager_ops fimd_manager_ops = {
-       .initialize = fimd_mgr_initialize,
-       .dpms = fimd_dpms,
-       .commit = fimd_commit,
-       .enable_vblank = fimd_enable_vblank,
-       .disable_vblank = fimd_disable_vblank,
-       .wait_for_vblank = fimd_wait_for_vblank,
-       .win_mode_set = fimd_win_mode_set,
-       .win_commit = fimd_win_commit,
-       .win_disable = fimd_win_disable,
-};
-
-static struct exynos_drm_manager fimd_manager = {
-       .pipe           = -1,
-       .ops            = &fimd_manager_ops,
-       .display_ops    = &fimd_display_ops,
-};
-
-static irqreturn_t fimd_irq_handler(int irq, void *dev_id)
-{
-       struct fimd_context *ctx = (struct fimd_context *)dev_id;
-       struct exynos_drm_subdrv *subdrv = &ctx->subdrv;
-       struct exynos_drm_manager *manager = subdrv->manager;
-       u32 val;
-
-       val = readl(ctx->regs + VIDINTCON1);
-
-       if (val & VIDINTCON1_INT_FRAME)
-               /* VSYNC interrupt */
-               writel(VIDINTCON1_INT_FRAME, ctx->regs + VIDINTCON1);
-
-       /* check the crtc is detached already from encoder */
-       if (manager->pipe < 0 || !ctx->drm_dev)
-               goto out;
-
-       drm_handle_vblank(ctx->drm_dev, manager->pipe);
-       exynos_drm_crtc_finish_pageflip(ctx->drm_dev, manager->pipe);
-
-       /* set wait vsync event to zero and wake up queue. */
-       if (atomic_read(&ctx->wait_vsync_event)) {
-               atomic_set(&ctx->wait_vsync_event, 0);
-               wake_up(&ctx->wait_vsync_queue);
-       }
-out:
-       return IRQ_HANDLED;
-}
-
-static int fimd_subdrv_probe(struct drm_device *drm_dev, struct device *dev)
-{
-       /*
-        * enable drm irq mode.
-        * - with irq_enabled = true, we can use the vblank feature.
-        *
-        * P.S. note that we wouldn't use drm irq handler but
-        *      just specific driver own one instead because
-        *      drm framework supports only one irq handler.
-        */
-       drm_dev->irq_enabled = true;
-
-       /*
-        * with vblank_disable_allowed = true, vblank interrupt will be disabled
-        * by drm timer once a current process gives up ownership of
-        * vblank event.(after drm_vblank_put function is called)
-        */
-       drm_dev->vblank_disable_allowed = true;
-
-       /* attach this sub driver to iommu mapping if supported. */
-       if (is_drm_iommu_supported(drm_dev))
-               drm_iommu_attach_device(drm_dev, dev);
-
-       return 0;
-}
-
-static void fimd_subdrv_remove(struct drm_device *drm_dev, struct device *dev)
-{
-       /* detach this sub driver from iommu mapping if supported. */
-       if (is_drm_iommu_supported(drm_dev))
-               drm_iommu_detach_device(drm_dev, dev);
-}
-
-static int fimd_configure_clocks(struct fimd_context *ctx, struct device *dev)
-{
-       struct videomode *vm = &ctx->panel.vm;
-       unsigned long clk;
-
-       ctx->bus_clk = devm_clk_get(dev, "fimd");
-       if (IS_ERR(ctx->bus_clk)) {
-               dev_err(dev, "failed to get bus clock\n");
-               return PTR_ERR(ctx->bus_clk);
-       }
-
-       ctx->lcd_clk = devm_clk_get(dev, "sclk_fimd");
-       if (IS_ERR(ctx->lcd_clk)) {
-               dev_err(dev, "failed to get lcd clock\n");
-               return PTR_ERR(ctx->lcd_clk);
-       }
-
-       clk = clk_get_rate(ctx->lcd_clk);
-       if (clk == 0) {
-               dev_err(dev, "error getting sclk_fimd clock rate\n");
-               return -EINVAL;
-       }
-
-       if (vm->pixelclock == 0) {
-               unsigned long c;
-               c = vm->hactive + vm->hback_porch + vm->hfront_porch +
-                   vm->hsync_len;
-               c *= vm->vactive + vm->vback_porch + vm->vfront_porch +
-                    vm->vsync_len;
-               vm->pixelclock = c * FIMD_DEFAULT_FRAMERATE;
-               if (vm->pixelclock == 0) {
-                       dev_err(dev, "incorrect display timings\n");
-                       return -EINVAL;
-               }
-               dev_warn(dev, "pixel clock recalculated to %luHz (%dHz frame rate)\n",
-                        vm->pixelclock, FIMD_DEFAULT_FRAMERATE);
-       }
-       ctx->clkdiv = DIV_ROUND_UP(clk, vm->pixelclock);
-       if (ctx->clkdiv > 256) {
-               dev_warn(dev, "calculated pixel clock divider too high (%u), lowered to 256\n",
-                        ctx->clkdiv);
-               ctx->clkdiv = 256;
-       }
-       vm->pixelclock = clk / ctx->clkdiv;
-       DRM_DEBUG_KMS("pixel clock = %lu, clkdiv = %d\n", vm->pixelclock,
-                     ctx->clkdiv);
-
-       return 0;
-}
-
 static void fimd_clear_win(struct fimd_context *ctx, int win)
 {
        writel(0, ctx->regs + WINCON(win));
@@ -804,31 +669,8 @@ static void fimd_clear_win(struct fimd_context *ctx, int win)
        fimd_shadow_protect_win(ctx, win, false);
 }
 
-static int fimd_clock(struct fimd_context *ctx, bool enable)
-{
-       if (enable) {
-               int ret;
-
-               ret = clk_prepare_enable(ctx->bus_clk);
-               if (ret < 0)
-                       return ret;
-
-               ret = clk_prepare_enable(ctx->lcd_clk);
-               if  (ret < 0) {
-                       clk_disable_unprepare(ctx->bus_clk);
-                       return ret;
-               }
-       } else {
-               clk_disable_unprepare(ctx->lcd_clk);
-               clk_disable_unprepare(ctx->bus_clk);
-       }
-
-       return 0;
-}
-
-static void fimd_window_suspend(struct device *dev)
+static void fimd_window_suspend(struct exynos_drm_manager *mgr)
 {
-       struct exynos_drm_manager *mgr = get_fimd_manager(dev);
        struct fimd_context *ctx = mgr->ctx;
        struct fimd_win_data *win_data;
        int i;
@@ -836,14 +678,14 @@ static void fimd_window_suspend(struct device *dev)
        for (i = 0; i < WINDOWS_NR; i++) {
                win_data = &ctx->win_data[i];
                win_data->resume = win_data->enabled;
-               fimd_win_disable(mgr, i);
+               if (win_data->enabled)
+                       fimd_win_disable(mgr, i);
        }
        fimd_wait_for_vblank(mgr);
 }
 
-static void fimd_window_resume(struct device *dev)
+static void fimd_window_resume(struct exynos_drm_manager *mgr)
 {
-       struct exynos_drm_manager *mgr = get_fimd_manager(dev);
        struct fimd_context *ctx = mgr->ctx;
        struct fimd_win_data *win_data;
        int i;
@@ -855,66 +697,162 @@ static void fimd_window_resume(struct device *dev)
        }
 }
 
-static int fimd_activate(struct exynos_drm_manager *mgr, bool enable)
+static void fimd_apply(struct exynos_drm_manager *mgr)
 {
        struct fimd_context *ctx = mgr->ctx;
-       struct device *dev = ctx->subdrv.dev;
+       struct fimd_win_data *win_data;
+       int i;
+
+       for (i = 0; i < WINDOWS_NR; i++) {
+               win_data = &ctx->win_data[i];
+               if (win_data->enabled)
+                       fimd_win_commit(mgr, i);
+       }
 
-       if (enable) {
-               int ret;
+       fimd_commit(mgr);
+}
+
+static int fimd_poweron(struct exynos_drm_manager *mgr)
+{
+       struct fimd_context *ctx = mgr->ctx;
+       int ret;
 
-               ret = fimd_clock(ctx, true);
-               if (ret < 0)
-                       return ret;
+       if (!ctx->suspended)
+               return 0;
 
-               ctx->suspended = false;
+       ctx->suspended = false;
 
-               /* if vblank was enabled status, enable it again. */
-               if (test_and_clear_bit(0, &ctx->irq_flags))
-                       fimd_enable_vblank(mgr);
+       pm_runtime_get_sync(ctx->dev);
 
-               fimd_window_resume(dev);
+       ret = clk_prepare_enable(ctx->bus_clk);
+       if (ret < 0) {
+               DRM_ERROR("Failed to prepare_enable the bus clk [%d]\n", ret);
+               goto bus_clk_err;
+       }
 
-               fimd_apply(mgr);
-       } else {
-               fimd_window_suspend(dev);
+       ret = clk_prepare_enable(ctx->lcd_clk);
+       if  (ret < 0) {
+               DRM_ERROR("Failed to prepare_enable the lcd clk [%d]\n", ret);
+               goto lcd_clk_err;
+       }
 
-               fimd_clock(ctx, false);
-               ctx->suspended = true;
+       /* if vblank was enabled status, enable it again. */
+       if (test_and_clear_bit(0, &ctx->irq_flags)) {
+               ret = fimd_enable_vblank(mgr);
+               if (ret) {
+                       DRM_ERROR("Failed to re-enable vblank [%d]\n", ret);
+                       goto enable_vblank_err;
+               }
        }
 
+       fimd_window_resume(mgr);
+
+       fimd_apply(mgr);
+
        return 0;
+
+enable_vblank_err:
+       clk_disable_unprepare(ctx->lcd_clk);
+lcd_clk_err:
+       clk_disable_unprepare(ctx->bus_clk);
+bus_clk_err:
+       ctx->suspended = true;
+       return ret;
 }
 
-static int fimd_get_platform_data(struct fimd_context *ctx, struct device *dev)
+static int fimd_poweroff(struct exynos_drm_manager *mgr)
 {
-       struct videomode *vm;
-       int ret;
+       struct fimd_context *ctx = mgr->ctx;
 
-       vm = &ctx->panel.vm;
-       ret = of_get_videomode(dev->of_node, vm, OF_USE_NATIVE_MODE);
-       if (ret) {
-               DRM_ERROR("failed: of_get_videomode() : %d\n", ret);
-               return ret;
-       }
+       if (ctx->suspended)
+               return 0;
 
-       if (vm->flags & DISPLAY_FLAGS_VSYNC_LOW)
-               ctx->vidcon1 |= VIDCON1_INV_VSYNC;
-       if (vm->flags & DISPLAY_FLAGS_HSYNC_LOW)
-               ctx->vidcon1 |= VIDCON1_INV_HSYNC;
-       if (vm->flags & DISPLAY_FLAGS_DE_LOW)
-               ctx->vidcon1 |= VIDCON1_INV_VDEN;
-       if (vm->flags & DISPLAY_FLAGS_PIXDATA_NEGEDGE)
-               ctx->vidcon1 |= VIDCON1_INV_VCLK;
+       /*
+        * We need to make sure that all windows are disabled before we
+        * suspend that connector. Otherwise we might try to scan from
+        * a destroyed buffer later.
+        */
+       fimd_window_suspend(mgr);
+
+       clk_disable_unprepare(ctx->lcd_clk);
+       clk_disable_unprepare(ctx->bus_clk);
 
+       pm_runtime_put_sync(ctx->dev);
+
+       ctx->suspended = true;
        return 0;
 }
 
+static void fimd_dpms(struct exynos_drm_manager *mgr, int mode)
+{
+       DRM_DEBUG_KMS("%s, %d\n", __FILE__, mode);
+
+       switch (mode) {
+       case DRM_MODE_DPMS_ON:
+               fimd_poweron(mgr);
+               break;
+       case DRM_MODE_DPMS_STANDBY:
+       case DRM_MODE_DPMS_SUSPEND:
+       case DRM_MODE_DPMS_OFF:
+               fimd_poweroff(mgr);
+               break;
+       default:
+               DRM_DEBUG_KMS("unspecified mode %d\n", mode);
+               break;
+       }
+}
+
+static struct exynos_drm_manager_ops fimd_manager_ops = {
+       .initialize = fimd_mgr_initialize,
+       .remove = fimd_mgr_remove,
+       .dpms = fimd_dpms,
+       .mode_fixup = fimd_mode_fixup,
+       .mode_set = fimd_mode_set,
+       .commit = fimd_commit,
+       .enable_vblank = fimd_enable_vblank,
+       .disable_vblank = fimd_disable_vblank,
+       .wait_for_vblank = fimd_wait_for_vblank,
+       .win_mode_set = fimd_win_mode_set,
+       .win_commit = fimd_win_commit,
+       .win_disable = fimd_win_disable,
+};
+
+static struct exynos_drm_manager fimd_manager = {
+       .type = EXYNOS_DISPLAY_TYPE_LCD,
+       .ops = &fimd_manager_ops,
+};
+
+static irqreturn_t fimd_irq_handler(int irq, void *dev_id)
+{
+       struct fimd_context *ctx = (struct fimd_context *)dev_id;
+       u32 val;
+
+       val = readl(ctx->regs + VIDINTCON1);
+
+       if (val & VIDINTCON1_INT_FRAME)
+               /* VSYNC interrupt */
+               writel(VIDINTCON1_INT_FRAME, ctx->regs + VIDINTCON1);
+
+       /* check the crtc is detached already from encoder */
+       if (ctx->pipe < 0 || !ctx->drm_dev)
+               goto out;
+
+       drm_handle_vblank(ctx->drm_dev, ctx->pipe);
+       exynos_drm_crtc_finish_pageflip(ctx->drm_dev, ctx->pipe);
+
+       /* set wait vsync event to zero and wake up queue. */
+       if (atomic_read(&ctx->wait_vsync_event)) {
+               atomic_set(&ctx->wait_vsync_event, 0);
+               wake_up(&ctx->wait_vsync_queue);
+       }
+out:
+       return IRQ_HANDLED;
+}
+
 static int fimd_probe(struct platform_device *pdev)
 {
        struct device *dev = &pdev->dev;
        struct fimd_context *ctx;
-       struct exynos_drm_subdrv *subdrv;
        struct resource *res;
        int win;
        int ret = -EINVAL;
@@ -927,14 +865,24 @@ static int fimd_probe(struct platform_device *pdev)
                return -ENOMEM;
 
        ctx->dev = dev;
+       ctx->suspended = true;
 
-       ret = fimd_get_platform_data(ctx, dev);
-       if (ret)
-               return ret;
+       if (of_property_read_bool(dev->of_node, "samsung,invert-vden"))
+               ctx->vidcon1 |= VIDCON1_INV_VDEN;
+       if (of_property_read_bool(dev->of_node, "samsung,invert-vclk"))
+               ctx->vidcon1 |= VIDCON1_INV_VCLK;
 
-       ret = fimd_configure_clocks(ctx, dev);
-       if (ret)
-               return ret;
+       ctx->bus_clk = devm_clk_get(dev, "fimd");
+       if (IS_ERR(ctx->bus_clk)) {
+               dev_err(dev, "failed to get bus clock\n");
+               return PTR_ERR(ctx->bus_clk);
+       }
+
+       ctx->lcd_clk = devm_clk_get(dev, "sclk_fimd");
+       if (IS_ERR(ctx->lcd_clk)) {
+               dev_err(dev, "failed to get lcd clock\n");
+               return PTR_ERR(ctx->lcd_clk);
+       }
 
        res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
 
@@ -948,9 +896,7 @@ static int fimd_probe(struct platform_device *pdev)
                return -ENXIO;
        }
 
-       ctx->irq = res->start;
-
-       ret = devm_request_irq(dev, ctx->irq, fimd_irq_handler,
+       ret = devm_request_irq(dev, res->start, fimd_irq_handler,
                                                        0, "drm_fimd", ctx);
        if (ret) {
                dev_err(dev, "irq request failed.\n");
@@ -961,110 +907,42 @@ static int fimd_probe(struct platform_device *pdev)
        init_waitqueue_head(&ctx->wait_vsync_queue);
        atomic_set(&ctx->wait_vsync_event, 0);
 
-       fimd_manager.ctx = ctx;
-
-       subdrv = &ctx->subdrv;
-
-       subdrv->dev = dev;
-       subdrv->manager = &fimd_manager;
-       subdrv->probe = fimd_subdrv_probe;
-       subdrv->remove = fimd_subdrv_remove;
+       platform_set_drvdata(pdev, &fimd_manager);
 
-       mutex_init(&ctx->lock);
+       fimd_manager.ctx = ctx;
+       exynos_drm_manager_register(&fimd_manager);
 
-       platform_set_drvdata(pdev, &fimd_manager);
+       exynos_dpi_probe(ctx->dev);
 
        pm_runtime_enable(dev);
-       pm_runtime_get_sync(dev);
 
        for (win = 0; win < WINDOWS_NR; win++)
                fimd_clear_win(ctx, win);
 
-       exynos_drm_subdrv_register(subdrv);
-
        return 0;
 }
 
 static int fimd_remove(struct platform_device *pdev)
 {
-       struct device *dev = &pdev->dev;
        struct exynos_drm_manager *mgr = platform_get_drvdata(pdev);
-       struct fimd_context *ctx = mgr->ctx;
 
-       exynos_drm_subdrv_unregister(&ctx->subdrv);
+       exynos_dpi_remove(&pdev->dev);
 
-       if (ctx->suspended)
-               goto out;
+       exynos_drm_manager_unregister(&fimd_manager);
 
-       pm_runtime_set_suspended(dev);
-       pm_runtime_put_sync(dev);
+       fimd_dpms(mgr, DRM_MODE_DPMS_OFF);
 
-out:
-       pm_runtime_disable(dev);
+       pm_runtime_disable(&pdev->dev);
 
        return 0;
 }
 
-#ifdef CONFIG_PM_SLEEP
-static int fimd_suspend(struct device *dev)
-{
-       struct exynos_drm_manager *mgr = get_fimd_manager(dev);
-
-       /*
-        * do not use pm_runtime_suspend(). if pm_runtime_suspend() is
-        * called here, an error would be returned by that interface
-        * because the usage_count of pm runtime is more than 1.
-        */
-       if (!pm_runtime_suspended(dev))
-               return fimd_activate(mgr, false);
-
-       return 0;
-}
-
-static int fimd_resume(struct device *dev)
-{
-       struct exynos_drm_manager *mgr = get_fimd_manager(dev);
-
-       /*
-        * if entered to sleep when lcd panel was on, the usage_count
-        * of pm runtime would still be 1 so in this case, fimd driver
-        * should be on directly not drawing on pm runtime interface.
-        */
-       if (pm_runtime_suspended(dev))
-               return 0;
-
-       return fimd_activate(mgr, true);
-}
-#endif
-
-#ifdef CONFIG_PM_RUNTIME
-static int fimd_runtime_suspend(struct device *dev)
-{
-       struct exynos_drm_manager *mgr = get_fimd_manager(dev);
-
-       return fimd_activate(mgr, false);
-}
-
-static int fimd_runtime_resume(struct device *dev)
-{
-       struct exynos_drm_manager *mgr = get_fimd_manager(dev);
-
-       return fimd_activate(mgr, true);
-}
-#endif
-
-static const struct dev_pm_ops fimd_pm_ops = {
-       SET_SYSTEM_SLEEP_PM_OPS(fimd_suspend, fimd_resume)
-       SET_RUNTIME_PM_OPS(fimd_runtime_suspend, fimd_runtime_resume, NULL)
-};
-
 struct platform_driver fimd_driver = {
        .probe          = fimd_probe,
        .remove         = fimd_remove,
        .driver         = {
                .name   = "exynos4-fb",
                .owner  = THIS_MODULE,
-               .pm     = &fimd_pm_ops,
                .of_match_table = fimd_driver_dt_match,
        },
 };