Merge tag 'media/v6.9-1' of git://git.kernel.org/pub/scm/linux/kernel/git/mchehab...
[linux-2.6-microblaze.git] / drivers / media / platform / renesas / rzg2l-cru / rzg2l-csi2.c
index d20f4ef..e68fcda 100644 (file)
@@ -108,6 +108,7 @@ struct rzg2l_csi2 {
        struct reset_control *presetn;
        struct reset_control *cmn_rstb;
        struct clk *sysclk;
+       struct clk *vclk;
        unsigned long vclk_rate;
 
        struct v4l2_subdev subdev;
@@ -361,7 +362,7 @@ static int rzg2l_csi2_dphy_setting(struct v4l2_subdev *sd, bool on)
        return rzg2l_csi2_dphy_disable(csi2);
 }
 
-static void rzg2l_csi2_mipi_link_enable(struct rzg2l_csi2 *csi2)
+static int rzg2l_csi2_mipi_link_enable(struct rzg2l_csi2 *csi2)
 {
        unsigned long vclk_rate = csi2->vclk_rate / HZ_PER_MHZ;
        u32 frrskw, frrclk, frrskw_coeff, frrclk_coeff;
@@ -386,11 +387,15 @@ static void rzg2l_csi2_mipi_link_enable(struct rzg2l_csi2 *csi2)
        rzg2l_csi2_write(csi2, CSI2nDTEL, 0xf778ff0f);
        rzg2l_csi2_write(csi2, CSI2nDTEH, 0x00ffff1f);
 
+       clk_disable_unprepare(csi2->vclk);
+
        /* Enable LINK reception */
        rzg2l_csi2_write(csi2, CSI2nMCT3, CSI2nMCT3_RXEN);
+
+       return clk_prepare_enable(csi2->vclk);
 }
 
-static void rzg2l_csi2_mipi_link_disable(struct rzg2l_csi2 *csi2)
+static int rzg2l_csi2_mipi_link_disable(struct rzg2l_csi2 *csi2)
 {
        unsigned int timeout = VSRSTS_RETRIES;
 
@@ -409,18 +414,21 @@ static void rzg2l_csi2_mipi_link_disable(struct rzg2l_csi2 *csi2)
 
        if (!timeout)
                dev_err(csi2->dev, "Clearing CSI2nRTST.VSRSTS timed out\n");
+
+       return 0;
 }
 
 static int rzg2l_csi2_mipi_link_setting(struct v4l2_subdev *sd, bool on)
 {
        struct rzg2l_csi2 *csi2 = sd_to_csi2(sd);
+       int ret;
 
        if (on)
-               rzg2l_csi2_mipi_link_enable(csi2);
+               ret = rzg2l_csi2_mipi_link_enable(csi2);
        else
-               rzg2l_csi2_mipi_link_disable(csi2);
+               ret = rzg2l_csi2_mipi_link_disable(csi2);
 
-       return 0;
+       return ret;
 }
 
 static int rzg2l_csi2_s_stream(struct v4l2_subdev *sd, int enable)
@@ -731,7 +739,6 @@ static const struct media_entity_operations rzg2l_csi2_entity_ops = {
 static int rzg2l_csi2_probe(struct platform_device *pdev)
 {
        struct rzg2l_csi2 *csi2;
-       struct clk *vclk;
        int ret;
 
        csi2 = devm_kzalloc(&pdev->dev, sizeof(*csi2), GFP_KERNEL);
@@ -757,12 +764,11 @@ static int rzg2l_csi2_probe(struct platform_device *pdev)
                return dev_err_probe(&pdev->dev, PTR_ERR(csi2->sysclk),
                                     "Failed to get system clk\n");
 
-       vclk = clk_get(&pdev->dev, "video");
-       if (IS_ERR(vclk))
-               return dev_err_probe(&pdev->dev, PTR_ERR(vclk),
+       csi2->vclk = devm_clk_get(&pdev->dev, "video");
+       if (IS_ERR(csi2->vclk))
+               return dev_err_probe(&pdev->dev, PTR_ERR(csi2->vclk),
                                     "Failed to get video clock\n");
-       csi2->vclk_rate = clk_get_rate(vclk);
-       clk_put(vclk);
+       csi2->vclk_rate = clk_get_rate(csi2->vclk);
 
        csi2->dev = &pdev->dev;
 
@@ -834,7 +840,7 @@ static void rzg2l_csi2_remove(struct platform_device *pdev)
        pm_runtime_disable(&pdev->dev);
 }
 
-static int __maybe_unused rzg2l_csi2_pm_runtime_suspend(struct device *dev)
+static int rzg2l_csi2_pm_runtime_suspend(struct device *dev)
 {
        struct rzg2l_csi2 *csi2 = dev_get_drvdata(dev);
 
@@ -843,7 +849,7 @@ static int __maybe_unused rzg2l_csi2_pm_runtime_suspend(struct device *dev)
        return 0;
 }
 
-static int __maybe_unused rzg2l_csi2_pm_runtime_resume(struct device *dev)
+static int rzg2l_csi2_pm_runtime_resume(struct device *dev)
 {
        struct rzg2l_csi2 *csi2 = dev_get_drvdata(dev);
 
@@ -851,7 +857,8 @@ static int __maybe_unused rzg2l_csi2_pm_runtime_resume(struct device *dev)
 }
 
 static const struct dev_pm_ops rzg2l_csi2_pm_ops = {
-       SET_RUNTIME_PM_OPS(rzg2l_csi2_pm_runtime_suspend, rzg2l_csi2_pm_runtime_resume, NULL)
+       RUNTIME_PM_OPS(rzg2l_csi2_pm_runtime_suspend,
+                      rzg2l_csi2_pm_runtime_resume, NULL)
 };
 
 static const struct of_device_id rzg2l_csi2_of_table[] = {
@@ -865,7 +872,7 @@ static struct platform_driver rzg2l_csi2_pdrv = {
        .driver = {
                .name = "rzg2l-csi2",
                .of_match_table = rzg2l_csi2_of_table,
-               .pm = &rzg2l_csi2_pm_ops,
+               .pm = pm_ptr(&rzg2l_csi2_pm_ops),
        },
 };