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)
committerNitin Garg <nitin.garg@nxp.com>
Mon, 19 Mar 2018 20:46:56 +0000 (15:46 -0500)
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>
(cherry picked from commit 4af299fed1568551d2e8c4696ec33d87cc873510)

drivers/media/platform/imx8/mxc-isi-core.c
drivers/media/platform/imx8/mxc-isi-core.h

index 7f4c2ee..dfa985f 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,40 @@ static int mxc_isi_remove(struct platform_device *pdev)
        return 0;
 }
 
+#ifdef CONFIG_PM_SLEEP
+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 +242,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,
        }
 };
 
index 0b71b3d..2117a13 100644 (file)
@@ -153,6 +153,11 @@ enum mxc_isi_m2m_in_fmt {
        MXC_ISI_M2M_IN_FMT_YUV422_1P10P,
 };
 
+enum mxc_isi_power_state {
+       MXC_ISI_PM_SUSPENDED = 0x01,
+       MXC_ISI_PM_POWERED = 0x02,
+};
+
 struct mxc_isi_fmt {
        char    *name;
        u32 mbus_code;
@@ -268,6 +273,7 @@ struct mxc_isi_dev {
        struct clk              *clk;
 
        u32 interface[MAX_PORTS];
+       u32 flags;
 
        /* scale factor */
        u32     xfactor;