From 3334f6716c7b5babb1e6436c11830068c5d40249 Mon Sep 17 00:00:00 2001 From: Changhuang Liang Date: Wed, 11 Jan 2023 15:32:03 +0800 Subject: [PATCH] media: starfive: stf_video: Multi open only set power one time Multi open the same video node only set power one time. Signed-off-by: Changhuang Liang --- .../platform/starfive/v4l2_driver/stf_video.c | 22 ++++++++++++++----- .../platform/starfive/v4l2_driver/stf_video.h | 1 + 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/drivers/media/platform/starfive/v4l2_driver/stf_video.c b/drivers/media/platform/starfive/v4l2_driver/stf_video.c index 05f48828a593..9aef386e9b54 100644 --- a/drivers/media/platform/starfive/v4l2_driver/stf_video.c +++ b/drivers/media/platform/starfive/v4l2_driver/stf_video.c @@ -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; diff --git a/drivers/media/platform/starfive/v4l2_driver/stf_video.h b/drivers/media/platform/starfive/v4l2_driver/stf_video.h index d134ee69c34e..6037d0ec7ac5 100644 --- a/drivers/media/platform/starfive/v4l2_driver/stf_video.h +++ b/drivers/media/platform/starfive/v4l2_driver/stf_video.h @@ -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, -- 2.34.1