MLK-16695-2: mipi_csi: Add pm suspend and resume support
authorGuoniu.Zhou <guoniu.zhou@nxp.com>
Fri, 10 Nov 2017 03:01:46 +0000 (11:01 +0800)
committerLeonard Crestez <leonard.crestez@nxp.com>
Wed, 17 Apr 2019 23:51:34 +0000 (02:51 +0300)
Add power manager suspend and resume support for ISI

Reviewed-by: Sandor Yu <sandor.yu@nxp.com>
Signed-off-by: Guoniu.Zhou <guoniu.zhou@nxp.com>
drivers/media/platform/imx8/mxc-isi-core.c

index 7f4c2ee..90f1e48 100644 (file)
@@ -174,6 +174,8 @@ static int mxc_isi_probe(struct platform_device *pdev)
                goto err_sclk;
        }
 
+       mxc_isi->flags = MXC_ISI_PM_POWERED;
+
        dev_dbg(dev, "mxc_isi.%d registered successfully\n", mxc_isi->id);
 
        return 0;
@@ -194,6 +196,39 @@ static int mxc_isi_remove(struct platform_device *pdev)
        return 0;
 }
 
+static int mxc_isi_pm_suspend(struct device *dev)
+{
+       struct mxc_isi_dev *mxc_isi = dev_get_drvdata(dev);
+
+       if (mxc_isi->flags & MXC_ISI_PM_SUSPENDED)
+               return 0;
+
+       clk_disable_unprepare(mxc_isi->clk);
+       mxc_isi->flags |= MXC_ISI_PM_SUSPENDED;
+       mxc_isi->flags &= ~MXC_ISI_PM_POWERED;
+
+       return 0;
+}
+
+static int mxc_isi_pm_resume(struct device *dev)
+{
+       struct mxc_isi_dev *mxc_isi = dev_get_drvdata(dev);
+       int ret;
+
+       if (mxc_isi->flags & MXC_ISI_PM_POWERED)
+               return 0;
+
+       mxc_isi->flags |= MXC_ISI_PM_POWERED;
+       mxc_isi->flags &= ~MXC_ISI_PM_SUSPENDED;
+
+       ret = clk_prepare_enable(mxc_isi->clk);
+       return (ret) ? -EAGAIN : 0;
+}
+
+static const struct dev_pm_ops mxc_isi_pm_ops = {
+       SET_SYSTEM_SLEEP_PM_OPS(mxc_isi_pm_suspend, mxc_isi_pm_resume)
+};
+
 static const struct of_device_id mxc_isi_of_match[] = {
        {.compatible = "fsl,imx8-isi",},
        { /* sentinel */ },
@@ -206,6 +241,7 @@ static struct platform_driver mxc_isi_driver = {
        .driver = {
                .of_match_table = mxc_isi_of_match,
                .name           = MXC_ISI_DRIVER_NAME,
+               .pm             = &mxc_isi_pm_ops,
        }
 };