media: Split v4l2_pipeline_pm_use into v4l2_pipeline_pm_{get, put}
authorEzequiel Garcia <ezequiel@collabora.com>
Fri, 24 Jan 2020 20:35:43 +0000 (21:35 +0100)
committerMauro Carvalho Chehab <mchehab+huawei@kernel.org>
Mon, 2 Mar 2020 14:11:40 +0000 (15:11 +0100)
Currently, v4l2_pipeline_pm_use() prototype is:

  int v4l2_pipeline_pm_use(struct media_entity *entity, int use)

Where the 'use' argument shall only be set to '1' for enable/power-on,
or to '0' for disable/power-off. The integer return is specified
as only meaningful when 'use' is set to '1'.

Let's enforce this semantic by splitting the function in two:
v4l2_pipeline_pm_get and v4l2_pipeline_pm_put. This is done
for several reasons.

It makes the API easier to use (or harder to misuse).
It removes the constraint on the values the 'use' argument
shall take. Also, it removes the need to constraint
the return value, by making v4l2_pipeline_pm_put void return.

And last, it's more consistent with other kernel APIs, such
as the runtime pm APIs, which makes the code more symmetric.

Signed-off-by: Ezequiel Garcia <ezequiel@collabora.com>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
Documentation/media/kapi/csi2.rst
drivers/media/platform/omap3isp/ispvideo.c
drivers/media/platform/qcom/camss/camss-video.c
drivers/media/platform/rcar-vin/rcar-v4l2.c
drivers/media/platform/sunxi/sun4i-csi/sun4i_v4l2.c
drivers/media/platform/sunxi/sun6i-csi/sun6i_video.c
drivers/media/v4l2-core/v4l2-mc.c
drivers/staging/media/imx/imx-media-capture.c
drivers/staging/media/omap4iss/iss_video.c
drivers/staging/media/rkisp1/rkisp1-capture.c
include/media/v4l2-mc.h

index 030a5c41ec75c48bb1c5ae5a113a798bc77b6d04..e111ff7bfd3dbd8cc424afbb2e2facfdfa2afbf8 100644 (file)
@@ -74,7 +74,7 @@ Before the receiver driver may enable the CSI-2 transmitter by using
 the :c:type:`v4l2_subdev_video_ops`->s_stream(), it must have powered
 the transmitter up by using the
 :c:type:`v4l2_subdev_core_ops`->s_power() callback. This may take
-place either indirectly by using :c:func:`v4l2_pipeline_pm_use` or
+place either indirectly by using :c:func:`v4l2_pipeline_pm_get` or
 directly.
 
 Formats
index 0ed250ffd95b93b9b05c3cbcdeef36c75587a76d..6f769c527faedf481f0745021a9537ad132d6d0d 100644 (file)
@@ -1311,7 +1311,7 @@ static int isp_video_open(struct file *file)
                goto done;
        }
 
-       ret = v4l2_pipeline_pm_use(&video->video.entity, 1);
+       ret = v4l2_pipeline_pm_get(&video->video.entity);
        if (ret < 0) {
                omap3isp_put(video->isp);
                goto done;
@@ -1363,7 +1363,7 @@ static int isp_video_release(struct file *file)
        vb2_queue_release(&handle->queue);
        mutex_unlock(&video->queue_lock);
 
-       v4l2_pipeline_pm_use(&video->video.entity, 0);
+       v4l2_pipeline_pm_put(&video->video.entity);
 
        /* Release the file handle. */
        v4l2_fh_del(vfh);
index c4220778ad472aea84dd7f4eed0f0c56bb151997..cdbd6dba11220c5ed0a607d482dfe5a09e8b24c3 100644 (file)
@@ -745,7 +745,7 @@ static int video_open(struct file *file)
 
        file->private_data = vfh;
 
-       ret = v4l2_pipeline_pm_use(&vdev->entity, 1);
+       ret = v4l2_pipeline_pm_get(&vdev->entity);
        if (ret < 0) {
                dev_err(video->camss->dev, "Failed to power up pipeline: %d\n",
                        ret);
@@ -771,7 +771,7 @@ static int video_release(struct file *file)
 
        vb2_fop_release(file);
 
-       v4l2_pipeline_pm_use(&vdev->entity, 0);
+       v4l2_pipeline_pm_put(&vdev->entity);
 
        file->private_data = NULL;
 
index b12b3f88836a37c7f2e4fdb196f2b91b7ec8195a..5151a3cd8a6e67546d25c6c16ec47b688fd62978 100644 (file)
@@ -842,7 +842,7 @@ static int rvin_open(struct file *file)
                goto err_unlock;
 
        if (vin->info->use_mc)
-               ret = v4l2_pipeline_pm_use(&vin->vdev.entity, 1);
+               ret = v4l2_pipeline_pm_get(&vin->vdev.entity);
        else if (v4l2_fh_is_singular_file(file))
                ret = rvin_power_parallel(vin, true);
 
@@ -858,7 +858,7 @@ static int rvin_open(struct file *file)
        return 0;
 err_power:
        if (vin->info->use_mc)
-               v4l2_pipeline_pm_use(&vin->vdev.entity, 0);
+               v4l2_pipeline_pm_put(&vin->vdev.entity);
        else if (v4l2_fh_is_singular_file(file))
                rvin_power_parallel(vin, false);
 err_open:
@@ -886,7 +886,7 @@ static int rvin_release(struct file *file)
        ret = _vb2_fop_release(file, NULL);
 
        if (vin->info->use_mc) {
-               v4l2_pipeline_pm_use(&vin->vdev.entity, 0);
+               v4l2_pipeline_pm_put(&vin->vdev.entity);
        } else {
                if (fh_singular)
                        rvin_power_parallel(vin, false);
index 5aee3fd875ada7c2b0c9cbf27efbae362754b45c..1721e5aee9c68ae1ceb10d1e1f8176894b629141 100644 (file)
@@ -214,7 +214,7 @@ static int sun4i_csi_open(struct file *file)
        if (ret < 0)
                goto err_pm_put;
 
-       ret = v4l2_pipeline_pm_use(&csi->vdev.entity, 1);
+       ret = v4l2_pipeline_pm_get(&csi->vdev.entity);
        if (ret)
                goto err_pm_put;
 
@@ -227,7 +227,7 @@ static int sun4i_csi_open(struct file *file)
        return 0;
 
 err_pipeline_pm_put:
-       v4l2_pipeline_pm_use(&csi->vdev.entity, 0);
+       v4l2_pipeline_pm_put(&csi->vdev.entity);
 
 err_pm_put:
        pm_runtime_put(csi->dev);
@@ -243,7 +243,7 @@ static int sun4i_csi_release(struct file *file)
        mutex_lock(&csi->lock);
 
        v4l2_fh_release(file);
-       v4l2_pipeline_pm_use(&csi->vdev.entity, 0);
+       v4l2_pipeline_pm_put(&csi->vdev.entity);
        pm_runtime_put(csi->dev);
 
        mutex_unlock(&csi->lock);
index cb30efb5d1f1d066e3a1f54c72f39f2cfa88a2bd..d9648b2810b9b09c5f0df019f5b2f397ccbfb06e 100644 (file)
@@ -474,7 +474,7 @@ static int sun6i_video_open(struct file *file)
        if (ret < 0)
                goto unlock;
 
-       ret = v4l2_pipeline_pm_use(&video->vdev.entity, 1);
+       ret = v4l2_pipeline_pm_get(&video->vdev.entity);
        if (ret < 0)
                goto fh_release;
 
@@ -507,7 +507,7 @@ static int sun6i_video_close(struct file *file)
 
        _vb2_fop_release(file, NULL);
 
-       v4l2_pipeline_pm_use(&video->vdev.entity, 0);
+       v4l2_pipeline_pm_put(&video->vdev.entity);
 
        if (last_fh)
                sun6i_csi_set_power(video->csi, false);
index 014a2a97cadd87065247e0eeb678d086b3270104..0fffdd3ce6a43ee8a01e7c08d901183ed0c3d0fd 100644 (file)
@@ -321,7 +321,7 @@ EXPORT_SYMBOL_GPL(v4l_vb2q_enable_media_source);
  * use_count field stores the total number of users of all video device nodes
  * in the pipeline.
  *
- * The v4l2_pipeline_pm_use() function must be called in the open() and
+ * The v4l2_pipeline_pm_{get, put}() functions must be called in the open() and
  * close() handlers of video device nodes. It increments or decrements the use
  * count of all subdev entities in the pipeline.
  *
@@ -423,7 +423,7 @@ static int pipeline_pm_power(struct media_entity *entity, int change,
        return ret;
 }
 
-int v4l2_pipeline_pm_use(struct media_entity *entity, int use)
+static int v4l2_pipeline_pm_use(struct media_entity *entity, unsigned int use)
 {
        struct media_device *mdev = entity->graph_obj.mdev;
        int change = use ? 1 : -1;
@@ -444,7 +444,19 @@ int v4l2_pipeline_pm_use(struct media_entity *entity, int use)
 
        return ret;
 }
-EXPORT_SYMBOL_GPL(v4l2_pipeline_pm_use);
+
+int v4l2_pipeline_pm_get(struct media_entity *entity)
+{
+       return v4l2_pipeline_pm_use(entity, 1);
+}
+EXPORT_SYMBOL_GPL(v4l2_pipeline_pm_get);
+
+void v4l2_pipeline_pm_put(struct media_entity *entity)
+{
+       /* Powering off entities shouldn't fail. */
+       WARN_ON(v4l2_pipeline_pm_use(entity, 0));
+}
+EXPORT_SYMBOL_GPL(v4l2_pipeline_pm_put);
 
 int v4l2_pipeline_link_notify(struct media_link *link, u32 flags,
                              unsigned int notification)
index 0dd6a2fafd895e440316192d4d8bce88b53bd292..d37b776ff86ded3a47ff6450fdbaa7633838c925 100644 (file)
@@ -643,7 +643,7 @@ static int capture_open(struct file *file)
        if (ret)
                v4l2_err(priv->src_sd, "v4l2_fh_open failed\n");
 
-       ret = v4l2_pipeline_pm_use(&vfd->entity, 1);
+       ret = v4l2_pipeline_pm_get(&vfd->entity);
        if (ret)
                v4l2_fh_release(file);
 
@@ -664,7 +664,7 @@ static int capture_release(struct file *file)
                vq->owner = NULL;
        }
 
-       v4l2_pipeline_pm_use(&vfd->entity, 0);
+       v4l2_pipeline_pm_put(&vfd->entity);
 
        v4l2_fh_release(file);
        mutex_unlock(&priv->mutex);
index bf7e999998c3e6e3fbd9ac0b24e228ac5c838be4..66975a37dc85f1ff5624d4862cf289a1ded182b1 100644 (file)
@@ -1111,7 +1111,7 @@ static int iss_video_open(struct file *file)
                goto done;
        }
 
-       ret = v4l2_pipeline_pm_use(&video->video.entity, 1);
+       ret = v4l2_pipeline_pm_get(&video->video.entity);
        if (ret < 0) {
                omap4iss_put(video->iss);
                goto done;
@@ -1160,7 +1160,7 @@ static int iss_video_release(struct file *file)
        /* Disable streaming and free the buffers queue resources. */
        iss_video_streamoff(file, vfh, video->type);
 
-       v4l2_pipeline_pm_use(&video->video.entity, 0);
+       v4l2_pipeline_pm_put(&video->video.entity);
 
        /* Release the videobuf2 queue */
        vb2_queue_release(&handle->queue);
index 7cc2ace193d1dee17ff71409a19ae75853845238..026470c7b43dc45515046b53baf642bec64fc530 100644 (file)
@@ -937,10 +937,7 @@ static void rkisp1_vb2_stop_streaming(struct vb2_queue *queue)
 
        rkisp1_return_all_buffers(cap, VB2_BUF_STATE_ERROR);
 
-       ret = v4l2_pipeline_pm_use(&node->vdev.entity, 0);
-       if (ret)
-               dev_err(rkisp1->dev, "pipeline close failed error:%d\n", ret);
-
+       v4l2_pipeline_pm_put(&node->vdev.entity);
        ret = pm_runtime_put(rkisp1->dev);
        if (ret)
                dev_err(rkisp1->dev, "power down failed error:%d\n", ret);
@@ -999,7 +996,7 @@ rkisp1_vb2_start_streaming(struct vb2_queue *queue, unsigned int count)
                dev_err(cap->rkisp1->dev, "power up failed %d\n", ret);
                goto err_destroy_dummy;
        }
-       ret = v4l2_pipeline_pm_use(entity, 1);
+       ret = v4l2_pipeline_pm_get(entity);
        if (ret) {
                dev_err(cap->rkisp1->dev, "open cif pipeline failed %d\n", ret);
                goto err_pipe_pm_put;
@@ -1025,7 +1022,7 @@ err_pipe_disable:
        rkisp1_pipeline_sink_walk(entity, NULL, rkisp1_pipeline_disable_cb);
 err_stop_stream:
        rkisp1_stream_stop(cap);
-       v4l2_pipeline_pm_use(entity, 0);
+       v4l2_pipeline_pm_put(entity);
 err_pipe_pm_put:
        pm_runtime_put(cap->rkisp1->dev);
 err_destroy_dummy:
index 384960249f01b5dc4b7b43032ab3aec2439609ae..5e73eb8e28f6343ea98c85b9014e7d89299a5d91 100644 (file)
@@ -86,23 +86,30 @@ int v4l_vb2q_enable_media_source(struct vb2_queue *q);
 
 
 /**
- * v4l2_pipeline_pm_use - Update the use count of an entity
- * @entity: The entity
- * @use: Use (1) or stop using (0) the entity
+ * v4l2_pipeline_pm_get - Increase the use count of a pipeline
+ * @entity: The root entity of a pipeline
  *
- * Update the use count of all entities in the pipeline and power entities on or
- * off accordingly.
+ * Update the use count of all entities in the pipeline and power entities on.
  *
- * This function is intended to be called in video node open (use ==
- * 1) and release (use == 0). It uses struct media_entity.use_count to
- * track the power status. The use of this function should be paired
- * with v4l2_pipeline_link_notify().
+ * This function is intended to be called in video node open. It uses
+ * struct media_entity.use_count to track the power status. The use
+ * of this function should be paired with v4l2_pipeline_link_notify().
  *
- * Return 0 on success or a negative error code on failure. Powering entities
- * off is assumed to never fail. No failure can occur when the use parameter is
- * set to 0.
+ * Return 0 on success or a negative error code on failure.
  */
-int v4l2_pipeline_pm_use(struct media_entity *entity, int use);
+int v4l2_pipeline_pm_get(struct media_entity *entity);
+
+/**
+ * v4l2_pipeline_pm_put - Decrease the use count of a pipeline
+ * @entity: The root entity of a pipeline
+ *
+ * Update the use count of all entities in the pipeline and power entities off.
+ *
+ * This function is intended to be called in video node release. It uses
+ * struct media_entity.use_count to track the power status. The use
+ * of this function should be paired with v4l2_pipeline_link_notify().
+ */
+void v4l2_pipeline_pm_put(struct media_entity *entity);
 
 
 /**
@@ -114,7 +121,7 @@ int v4l2_pipeline_pm_use(struct media_entity *entity, int use);
  * React to link management on powered pipelines by updating the use count of
  * all entities in the source and sink sides of the link. Entities are powered
  * on or off accordingly. The use of this function should be paired
- * with v4l2_pipeline_pm_use().
+ * with v4l2_pipeline_pm_{get,put}().
  *
  * Return 0 on success or a negative error code on failure. Powering entities
  * off is assumed to never fail. This function will not fail for disconnection
@@ -144,11 +151,14 @@ static inline int v4l_vb2q_enable_media_source(struct vb2_queue *q)
        return 0;
 }
 
-static inline int v4l2_pipeline_pm_use(struct media_entity *entity, int use)
+static inline int v4l2_pipeline_pm_get(struct media_entity *entity)
 {
        return 0;
 }
 
+static inline void v4l2_pipeline_pm_put(struct media_entity *entity)
+{}
+
 static inline int v4l2_pipeline_link_notify(struct media_link *link, u32 flags,
                                            unsigned int notification)
 {