drm/rockchip: vop: Enable pm domain before vop_initial
authorJeffy Chen <jeffy.chen@rock-chips.com>
Thu, 6 Apr 2017 12:31:20 +0000 (20:31 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 22 Mar 2018 08:17:49 +0000 (09:17 +0100)
[ Upstream commit 5e570373c015b60a68828b1cd9d475cb33d3be4b ]

We're trying to access vop registers here, so need to make sure
the pm domain is on.

Normally it should be enabled by the bootloader, but there's no
guarantee of it. And if we wanna do unbind/bind, it would also
cause the device to hang.

And this patch also does these:
1/ move vop_initial to the end of vop_bind for eaiser error handling.
2/ correct the err_put_pm_runtime of vop_enable.

Signed-off-by: Jeffy Chen <jeffy.chen@rock-chips.com>
Signed-off-by: Sean Paul <seanpaul@chromium.org>
Link: http://patchwork.freedesktop.org/patch/msgid/1491481885-13775-8-git-send-email-jeffy.chen@rock-chips.com
Signed-off-by: Sasha Levin <alexander.levin@microsoft.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/gpu/drm/rockchip/rockchip_drm_vop.c

index c7eba305c48830b225d3927185ad849dac193d07..6e3c4acb16ac77036805eb0063621a067d05a27d 100644 (file)
@@ -503,7 +503,7 @@ static int vop_enable(struct drm_crtc *crtc)
        ret = pm_runtime_get_sync(vop->dev);
        if (ret < 0) {
                dev_err(vop->dev, "failed to get pm runtime: %d\n", ret);
-               goto err_put_pm_runtime;
+               return ret;
        }
 
        ret = clk_enable(vop->hclk);
@@ -1348,10 +1348,16 @@ static int vop_initial(struct vop *vop)
                return PTR_ERR(vop->dclk);
        }
 
+       ret = pm_runtime_get_sync(vop->dev);
+       if (ret < 0) {
+               dev_err(vop->dev, "failed to get pm runtime: %d\n", ret);
+               return ret;
+       }
+
        ret = clk_prepare(vop->dclk);
        if (ret < 0) {
                dev_err(vop->dev, "failed to prepare dclk\n");
-               return ret;
+               goto err_put_pm_runtime;
        }
 
        /* Enable both the hclk and aclk to setup the vop */
@@ -1411,6 +1417,8 @@ static int vop_initial(struct vop *vop)
 
        vop->is_enabled = false;
 
+       pm_runtime_put_sync(vop->dev);
+
        return 0;
 
 err_disable_aclk:
@@ -1419,6 +1427,8 @@ err_disable_hclk:
        clk_disable_unprepare(vop->hclk);
 err_unprepare_dclk:
        clk_unprepare(vop->dclk);
+err_put_pm_runtime:
+       pm_runtime_put_sync(vop->dev);
        return ret;
 }
 
@@ -1519,12 +1529,6 @@ static int vop_bind(struct device *dev, struct device *master, void *data)
        if (!vop->regsbak)
                return -ENOMEM;
 
-       ret = vop_initial(vop);
-       if (ret < 0) {
-               dev_err(&pdev->dev, "cannot initial vop dev - err %d\n", ret);
-               return ret;
-       }
-
        irq = platform_get_irq(pdev, 0);
        if (irq < 0) {
                dev_err(dev, "cannot find irq for vop\n");
@@ -1551,8 +1555,17 @@ static int vop_bind(struct device *dev, struct device *master, void *data)
 
        pm_runtime_enable(&pdev->dev);
 
+       ret = vop_initial(vop);
+       if (ret < 0) {
+               dev_err(&pdev->dev, "cannot initial vop dev - err %d\n", ret);
+               goto err_disable_pm_runtime;
+       }
+
        return 0;
 
+err_disable_pm_runtime:
+       pm_runtime_disable(&pdev->dev);
+       vop_destroy_crtc(vop);
 err_enable_irq:
        enable_irq(vop->irq); /* To balance out the disable_irq above */
        return ret;