imx219: Separate set stream and runtime PM
authorchanghuang.liang <changhuang.liang@starfivetech.com>
Thu, 29 Sep 2022 07:14:05 +0000 (15:14 +0800)
committermason.huo <mason.huo@starfivetech.com>
Thu, 27 Oct 2022 05:54:45 +0000 (13:54 +0800)
Separate set stream and runtime PM, use runtime PM.

Signed-off-by: changhuang.liang <changhuang.liang@starfivetech.com>
drivers/media/platform/starfive/v4l2_driver/imx219_mipi.c

index 5ce43f9..9bc20d1 100644 (file)
@@ -1086,37 +1086,31 @@ static int imx219_start_streaming(struct imx219 *imx219)
        const struct imx219_reg_list *reg_list;
        int ret;
 
-       ret = pm_runtime_get_sync(&client->dev);
-       if (ret < 0) {
-               pm_runtime_put_noidle(&client->dev);
-               return ret;
-       }
-
        /* Apply default values of current mode */
        reg_list = &imx219->mode->reg_list;
        ret = imx219_write_regs(imx219, reg_list->regs, reg_list->num_of_regs);
        if (ret) {
                dev_err(&client->dev, "%s failed to set mode\n", __func__);
-               goto err_rpm_put;
+               goto err;
        }
 
        ret = imx219_set_framefmt(imx219);
        if (ret) {
                dev_err(&client->dev, "%s failed to set frame format: %d\n",
                        __func__, ret);
-               goto err_rpm_put;
+               goto err;
        }
 
        /* Apply customized values from user */
        ret =  __v4l2_ctrl_handler_setup(imx219->sd.ctrl_handler);
        if (ret)
-               goto err_rpm_put;
+               goto err;
 
        /* set stream on register */
        ret = imx219_write_reg(imx219, IMX219_REG_MODE_SELECT,
                               IMX219_REG_VALUE_08BIT, IMX219_MODE_STREAMING);
        if (ret)
-               goto err_rpm_put;
+               goto err;
 
        /* vflip and hflip cannot change during streaming */
        __v4l2_ctrl_grab(imx219->vflip, true);
@@ -1124,8 +1118,7 @@ static int imx219_start_streaming(struct imx219 *imx219)
 
        return 0;
 
-err_rpm_put:
-       pm_runtime_put(&client->dev);
+err:
        return ret;
 }
 
@@ -1142,13 +1135,12 @@ static void imx219_stop_streaming(struct imx219 *imx219)
 
        __v4l2_ctrl_grab(imx219->vflip, false);
        __v4l2_ctrl_grab(imx219->hflip, false);
-
-       pm_runtime_put(&client->dev);
 }
 
 static int imx219_set_stream(struct v4l2_subdev *sd, int enable)
 {
        struct imx219 *imx219 = to_imx219(sd);
+       struct i2c_client *client = v4l2_get_subdevdata(sd);
        int ret = 0;
 
        mutex_lock(&imx219->mutex);
@@ -1156,6 +1148,12 @@ static int imx219_set_stream(struct v4l2_subdev *sd, int enable)
                goto unlock;
 
        if (enable) {
+               ret = pm_runtime_get_sync(&client->dev);
+               if (ret < 0) {
+                       pm_runtime_put_noidle(&client->dev);
+                       return ret;
+               }
+
                /*
                 * Apply default & customized values
                 * and then start streaming.
@@ -1165,6 +1163,7 @@ static int imx219_set_stream(struct v4l2_subdev *sd, int enable)
                        goto err_unlock;
        } else {
                imx219_stop_streaming(imx219);
+               pm_runtime_put(&client->dev);
        }
 
 unlock:
@@ -1176,6 +1175,7 @@ unlock:
        return ret;
 
 err_unlock:
+       pm_runtime_put(&client->dev);
        mutex_unlock(&imx219->mutex);
 
        return ret;
@@ -1244,38 +1244,6 @@ static int imx219_power_off(struct device *dev)
        return 0;
 }
 
-static int __maybe_unused imx219_suspend(struct device *dev)
-{
-       struct v4l2_subdev *sd = dev_get_drvdata(dev);
-       struct imx219 *imx219 = to_imx219(sd);
-
-       if (imx219->streaming)
-               imx219_stop_streaming(imx219);
-
-       return 0;
-}
-
-static int __maybe_unused imx219_resume(struct device *dev)
-{
-       struct v4l2_subdev *sd = dev_get_drvdata(dev);
-       struct imx219 *imx219 = to_imx219(sd);
-       int ret;
-
-       if (imx219->streaming) {
-               ret = imx219_start_streaming(imx219);
-               if (ret)
-                       goto error;
-       }
-
-       return 0;
-
-error:
-       imx219_stop_streaming(imx219);
-       imx219->streaming = false;
-
-       return ret;
-}
-
 static int imx219_get_regulators(struct imx219 *imx219)
 {
        struct i2c_client *client = v4l2_get_subdevdata(&imx219->sd);
@@ -1655,7 +1623,6 @@ static const struct of_device_id imx219_dt_ids[] = {
 MODULE_DEVICE_TABLE(of, imx219_dt_ids);
 
 static const struct dev_pm_ops imx219_pm_ops = {
-       SET_SYSTEM_SLEEP_PM_OPS(imx219_suspend, imx219_resume)
        SET_RUNTIME_PM_OPS(imx219_power_off, imx219_power_on, NULL)
 };