video: tegra: host: correct runtime pm api usage
Mayuresh Kulkarni [Fri, 10 May 2013 16:00:05 +0000 (21:00 +0530)]
- enable auto-suspend only if clock gate delay != 0
- protect power gate/ungate by mutex

bug 1276972

Change-Id: If525e8a0eb5f001efed74957abc73d1a27307a24
Signed-off-by: Mayuresh Kulkarni <mkulkarni@nvidia.com>
Reviewed-on: http://git-master/r/227503
Reviewed-by: Automatic_Commit_Validation_User
Reviewed-by: Prashant Gaikwad <pgaikwad@nvidia.com>
Reviewed-by: Terje Bergstrom <tbergstrom@nvidia.com>

drivers/video/tegra/host/gr2d/gr2d.c
drivers/video/tegra/host/gr3d/gr3d.c
drivers/video/tegra/host/host1x/host1x.c
drivers/video/tegra/host/isp/isp.c
drivers/video/tegra/host/mpe/mpe.c
drivers/video/tegra/host/msenc/msenc.c
drivers/video/tegra/host/nvhost_acm.c
drivers/video/tegra/host/tsec/tsec.c
drivers/video/tegra/host/vi/vi.c

index e3ee9c6..356af70 100644 (file)
@@ -155,13 +155,19 @@ static int gr2d_probe(struct platform_device *dev)
        gr2d_pd.pd.domain.ops.resume = gr2d_resume;
        gr2d_pd.pd.dev_ops.restore_state = gr2d_restore_context;
 
-       pm_runtime_set_autosuspend_delay(&dev->dev, pdata->clockgate_delay);
-       pm_runtime_use_autosuspend(&dev->dev);
+       if (pdata->clockgate_delay) {
+               pm_runtime_set_autosuspend_delay(&dev->dev,
+                       pdata->clockgate_delay);
+               pm_runtime_use_autosuspend(&dev->dev);
+       }
        pm_runtime_enable(&dev->dev);
 
        pm_runtime_get_sync(&dev->dev);
        err = nvhost_client_device_init(dev);
-       pm_runtime_put(&dev->dev);
+       if (pdata->clockgate_delay)
+               pm_runtime_put_sync_autosuspend(&dev->dev);
+       else
+               pm_runtime_put(&dev->dev);
        if (err)
                return err;
 
index 1679591..b8068ba 100644 (file)
@@ -314,13 +314,19 @@ static int gr3d_probe(struct platform_device *dev)
        gr3d_pd.pd.domain.ops.suspend = gr3d_suspend;
        gr3d_pd.pd.domain.ops.resume = gr3d_resume;
 
-       pm_runtime_set_autosuspend_delay(&dev->dev, pdata->clockgate_delay);
-       pm_runtime_use_autosuspend(&dev->dev);
+       if (pdata->clockgate_delay) {
+               pm_runtime_set_autosuspend_delay(&dev->dev,
+                       pdata->clockgate_delay);
+               pm_runtime_use_autosuspend(&dev->dev);
+       }
        pm_runtime_enable(&dev->dev);
 
        pm_runtime_get_sync(&dev->dev);
        err = nvhost_client_device_init(dev);
-       pm_runtime_put(&dev->dev);
+       if (pdata->clockgate_delay)
+               pm_runtime_put_sync_autosuspend(&dev->dev);
+       else
+               pm_runtime_put(&dev->dev);
        if (err)
                return err;
 
index 774f8db..5f92891 100644 (file)
@@ -626,8 +626,11 @@ static int nvhost_probe(struct platform_device *dev)
                clk_disable_unprepare(pdata->clk[i]);
 
        tegra_pd_add_device(&dev->dev);
-       pm_runtime_use_autosuspend(&dev->dev);
-       pm_runtime_set_autosuspend_delay(&dev->dev, pdata->clockgate_delay);
+       if (pdata->clockgate_delay) {
+               pm_runtime_set_autosuspend_delay(&dev->dev,
+                       pdata->clockgate_delay);
+               pm_runtime_use_autosuspend(&dev->dev);
+       }
        pm_runtime_enable(&dev->dev);
        pm_suspend_ignore_children(&dev->dev, true);
 
index bcb30e8..ff21d69 100644 (file)
@@ -81,8 +81,11 @@ static int isp_probe(struct platform_device *dev)
                return err;
 
        tegra_pd_add_device(&dev->dev);
-       pm_runtime_use_autosuspend(&dev->dev);
-       pm_runtime_set_autosuspend_delay(&dev->dev, pdata->clockgate_delay);
+       if (pdata->clockgate_delay) {
+               pm_runtime_set_autosuspend_delay(&dev->dev,
+                       pdata->clockgate_delay);
+               pm_runtime_use_autosuspend(&dev->dev);
+       }
        pm_runtime_enable(&dev->dev);
 
        return 0;
index faf3c3d..9dc6b10 100644 (file)
@@ -773,13 +773,19 @@ static int mpe_probe(struct platform_device *dev)
        mpe_pd.pd.domain.ops.suspend = mpe_suspend;
        mpe_pd.pd.domain.ops.resume = mpe_resume;
 
-       pm_runtime_set_autosuspend_delay(&dev->dev, pdata->clockgate_delay);
-       pm_runtime_use_autosuspend(&dev->dev);
+       if (pdata->clockgate_delay) {
+               pm_runtime_set_autosuspend_delay(&dev->dev,
+                       pdata->clockgate_delay);
+               pm_runtime_use_autosuspend(&dev->dev);
+       }
        pm_runtime_enable(&dev->dev);
 
        pm_runtime_get_sync(&dev->dev);
        err = nvhost_client_device_init(dev);
-       pm_runtime_put(&dev->dev);
+       if (pdata->clockgate_delay)
+               pm_runtime_put_sync_autosuspend(&dev->dev);
+       else
+               pm_runtime_put(&dev->dev);
        if (err)
                return err;
 
index c30598f..883b731 100644 (file)
@@ -522,8 +522,11 @@ static int msenc_probe(struct platform_device *dev)
 
        /* enable runtime pm. this is needed now since we need to call
         * _get_sync/_put during boot-up to ensure MC domain is ON */
-       pm_runtime_set_autosuspend_delay(&dev->dev, pdata->clockgate_delay);
-       pm_runtime_use_autosuspend(&dev->dev);
+       if (pdata->clockgate_delay) {
+               pm_runtime_set_autosuspend_delay(&dev->dev,
+                       pdata->clockgate_delay);
+               pm_runtime_use_autosuspend(&dev->dev);
+       }
        pm_runtime_enable(&dev->dev);
 
        err = nvhost_client_device_get_resources(dev);
@@ -532,7 +535,10 @@ static int msenc_probe(struct platform_device *dev)
 
        pm_runtime_get_sync(&dev->dev);
        err = nvhost_client_device_init(dev);
-       pm_runtime_put(&dev->dev);
+       if (pdata->clockgate_delay)
+               pm_runtime_put_sync_autosuspend(&dev->dev);
+       else
+               pm_runtime_put(&dev->dev);
        if (err)
                return err;
 
index 507aefb..d4a056f 100644 (file)
@@ -158,7 +158,10 @@ void nvhost_module_idle_mult(struct platform_device *dev, int refs)
 
        while (refs--) {
                pm_runtime_mark_last_busy(&dev->dev);
-               pm_runtime_put_autosuspend(&dev->dev);
+               if (pdata->clockgate_delay)
+                       pm_runtime_put_sync_autosuspend(&dev->dev);
+               else
+                       pm_runtime_put(&dev->dev);
        }
 
 #ifdef CONFIG_PM_RUNTIME
@@ -604,16 +607,15 @@ int nvhost_module_power_on(struct platform_device *pdev)
        if (!pdata)
                return -EINVAL;
 
+       mutex_lock(&pdata->lock);
        if (pdata->can_powergate) {
                do_unpowergate_locked(pdata->powergate_ids[0]);
                do_unpowergate_locked(pdata->powergate_ids[1]);
        }
 
-       if (pdata->powerup_reset) {
-               mutex_lock(&pdata->lock);
+       if (pdata->powerup_reset)
                do_module_reset_locked(pdev);
-               mutex_unlock(&pdata->lock);
-       }
+       mutex_unlock(&pdata->lock);
 
        return 0;
 }
@@ -624,10 +626,12 @@ int nvhost_module_power_off(struct platform_device *pdev)
        if (!pdata)
                return -EINVAL;
 
+       mutex_lock(&pdata->lock);
        if (pdata->can_powergate) {
                do_powergate_locked(pdata->powergate_ids[0]);
                do_powergate_locked(pdata->powergate_ids[1]);
        }
+       mutex_unlock(&pdata->lock);
 
        return 0;
 }
index 9c7e167..a31bd93 100644 (file)
@@ -563,25 +563,30 @@ static int tsec_probe(struct platform_device *dev)
 
        tsec = dev;
 
+       tegra_pd_add_device(&dev->dev);
+       if (pdata->clockgate_delay) {
+               pm_runtime_set_autosuspend_delay(&dev->dev,
+                       pdata->clockgate_delay);
+               pm_runtime_use_autosuspend(&dev->dev);
+       }
+       pm_runtime_enable(&dev->dev);
+
+       pm_runtime_get_sync(&dev->dev);
+
        err = nvhost_client_device_init(dev);
        if (err)
                return err;
 
-       nvhost_module_busy(to_platform_device(dev->dev.parent));
-
        /* Reset TSEC at boot-up. Otherwise it starts sending interrupts. */
-       clk_prepare_enable(pdata->clk[0]);
        tegra_periph_reset_assert(pdata->clk[0]);
        udelay(10);
        tegra_periph_reset_deassert(pdata->clk[0]);
-       clk_disable_unprepare(pdata->clk[0]);
 
-       tegra_pd_add_device(&dev->dev);
-       pm_runtime_use_autosuspend(&dev->dev);
-       pm_runtime_set_autosuspend_delay(&dev->dev, pdata->clockgate_delay);
-       pm_runtime_enable(&dev->dev);
+       if (pdata->clockgate_delay)
+               pm_runtime_put_sync_autosuspend(&dev->dev);
+       else
+               pm_runtime_put(&dev->dev);
 
-       nvhost_module_idle(to_platform_device(dev->dev.parent));
        return err;
 }
 
index 13f4f46..b00e146 100644 (file)
@@ -100,8 +100,11 @@ static int vi_probe(struct platform_device *dev)
                goto camera_register_fail;
 
        tegra_pd_add_device(&dev->dev);
-       pm_runtime_use_autosuspend(&dev->dev);
-       pm_runtime_set_autosuspend_delay(&dev->dev, pdata->clockgate_delay);
+       if (pdata->clockgate_delay) {
+               pm_runtime_set_autosuspend_delay(&dev->dev,
+                       pdata->clockgate_delay);
+               pm_runtime_use_autosuspend(&dev->dev);
+       }
        pm_runtime_enable(&dev->dev);
 
        return 0;