media: starfive: stf_video: Multi open only set power one time
authorChanghuang Liang <changhuang.liang@starfivetech.com>
Wed, 11 Jan 2023 07:32:03 +0000 (15:32 +0800)
committerChanghuang Liang <changhuang.liang@starfivetech.com>
Wed, 11 Jan 2023 07:32:03 +0000 (15:32 +0800)
Multi open the same video node only set power one time.

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

index 05f4882..9aef386 100644 (file)
@@ -1611,13 +1611,17 @@ static int video_open(struct file *file)
 
        file->private_data = vfh;
 
-       ret = v4l2_pipeline_pm_get(&vdev->entity);
-       if (ret < 0) {
-               st_err(ST_VIDEO,
-                       "Failed to power up pipeline: %d\n", ret);
-               goto error_pm_use;
+       if (!video->pm_count) {
+               ret = v4l2_pipeline_pm_get(&vdev->entity);
+               if (ret < 0) {
+                       st_err(ST_VIDEO,
+                               "Failed to power up pipeline: %d\n", ret);
+                       goto error_pm_use;
+               }
        }
 
+       video->pm_count++;
+
        mutex_unlock(&video->lock);
 
        return 0;
@@ -1632,9 +1636,15 @@ error_alloc:
 static int video_release(struct file *file)
 {
        struct video_device *vdev = video_devdata(file);
+       struct stfcamss_video *video = video_drvdata(file);
 
        vb2_fop_release(file);
-       v4l2_pipeline_pm_put(&vdev->entity);
+
+       video->pm_count--;
+
+       if (!video->pm_count)
+               v4l2_pipeline_pm_put(&vdev->entity);
+
        file->private_data = NULL;
 
        return 0;
index d134ee6..6037d0e 100644 (file)
@@ -69,6 +69,7 @@ struct stfcamss_video {
        const struct stfcamss_format_info *formats;
        unsigned int nformats;
        unsigned int is_mp;
+       unsigned int pm_count;
 };
 
 int stf_video_register(struct stfcamss_video *video,