linux-media.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v1 0/4] Add StarFive Camera Subsystem hibernation support
@ 2024-03-26  3:12 Changhuang Liang
  2024-03-26  3:12 ` [PATCH v1 1/4] media: cadence: csi2rx: Support runtime PM Changhuang Liang
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Changhuang Liang @ 2024-03-26  3:12 UTC (permalink / raw)
  To: Mauro Carvalho Chehab, Greg Kroah-Hartman
  Cc: Hans Verkuil, Laurent Pinchart, Jack Zhu, Changhuang Liang,
	Dan Carpenter, Jayshri Pawar, Jai Luthra, linux-media,
	linux-kernel, linux-staging

This series implements suspend and resume operation for StarFive Camera
Subsystem on JH7110 SoC. It supports hibernation during streaming and
resume streaming when the system wake-up stage.

Changhuang Liang (3):
  media: cadence: csi2rx: Add suspend and resume support
  staging: media: starfive: Extract the ISP stream on as a helper
    function
  staging: media: starfive: Add suspend and resume support

Jayshri Pawar (1):
  media: cadence: csi2rx: Support runtime PM

 drivers/media/platform/cadence/cdns-csi2rx.c  | 44 ++++++++++++++++-
 .../staging/media/starfive/camss/stf-camss.c  | 49 +++++++++++++++++++
 .../staging/media/starfive/camss/stf-isp.c    | 27 ++++++----
 .../staging/media/starfive/camss/stf-isp.h    |  2 +
 4 files changed, 111 insertions(+), 11 deletions(-)

--
2.25.1

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH v1 1/4] media: cadence: csi2rx: Support runtime PM
  2024-03-26  3:12 [PATCH v1 0/4] Add StarFive Camera Subsystem hibernation support Changhuang Liang
@ 2024-03-26  3:12 ` Changhuang Liang
  2024-03-26  3:12 ` [PATCH v1 2/4] media: cadence: csi2rx: Add suspend and resume support Changhuang Liang
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Changhuang Liang @ 2024-03-26  3:12 UTC (permalink / raw)
  To: Mauro Carvalho Chehab, Greg Kroah-Hartman
  Cc: Hans Verkuil, Laurent Pinchart, Jack Zhu, Changhuang Liang,
	Dan Carpenter, Jayshri Pawar, Jai Luthra, linux-media,
	linux-kernel, linux-staging

From: Jayshri Pawar <jpawar@cadence.com>

Use runtime power management hooks to save power when CSI-RX is not in
use. Also stop/start any in-progress streams, which might happen during
a system suspend/resume cycle.

Signed-off-by: Jayshri Pawar <jpawar@cadence.com>
Co-developed-by: Jai Luthra <j-luthra@ti.com>
Signed-off-by: Jai Luthra <j-luthra@ti.com>
Signed-off-by: Changhuang Liang <changhuang.liang@starfivetech.com>
---
 drivers/media/platform/cadence/cdns-csi2rx.c | 43 +++++++++++++++++++-
 1 file changed, 42 insertions(+), 1 deletion(-)

diff --git a/drivers/media/platform/cadence/cdns-csi2rx.c b/drivers/media/platform/cadence/cdns-csi2rx.c
index 2d7b0508cc9a..a8b86369e34f 100644
--- a/drivers/media/platform/cadence/cdns-csi2rx.c
+++ b/drivers/media/platform/cadence/cdns-csi2rx.c
@@ -364,6 +364,12 @@ static int csi2rx_s_stream(struct v4l2_subdev *subdev, int enable)
 	struct csi2rx_priv *csi2rx = v4l2_subdev_to_csi2rx(subdev);
 	int ret = 0;
 
+	if (enable) {
+		ret = pm_runtime_resume_and_get(csi2rx->dev);
+		if (ret < 0)
+			return ret;
+	}
+
 	mutex_lock(&csi2rx->lock);
 
 	if (enable) {
@@ -373,8 +379,10 @@ static int csi2rx_s_stream(struct v4l2_subdev *subdev, int enable)
 		 */
 		if (!csi2rx->count) {
 			ret = csi2rx_start(csi2rx);
-			if (ret)
+			if (ret) {
+				pm_runtime_put(csi2rx->dev);
 				goto out;
+			}
 		}
 
 		csi2rx->count++;
@@ -386,6 +394,8 @@ static int csi2rx_s_stream(struct v4l2_subdev *subdev, int enable)
 		 */
 		if (!csi2rx->count)
 			csi2rx_stop(csi2rx);
+
+		pm_runtime_put(csi2rx->dev);
 	}
 
 out:
@@ -659,6 +669,29 @@ static int csi2rx_parse_dt(struct csi2rx_priv *csi2rx)
 	return ret;
 }
 
+static int csi2rx_suspend(struct device *dev)
+{
+	struct csi2rx_priv *csi2rx = dev_get_drvdata(dev);
+
+	mutex_lock(&csi2rx->lock);
+	if (csi2rx->count)
+		csi2rx_stop(csi2rx);
+	mutex_unlock(&csi2rx->lock);
+
+	return 0;
+}
+
+static int csi2rx_resume(struct device *dev)
+{
+	struct csi2rx_priv *csi2rx = dev_get_drvdata(dev);
+
+	mutex_lock(&csi2rx->lock);
+	if (csi2rx->count)
+		csi2rx_start(csi2rx);
+	mutex_unlock(&csi2rx->lock);
+	return 0;
+}
+
 static int csi2rx_probe(struct platform_device *pdev)
 {
 	struct csi2rx_priv *csi2rx;
@@ -705,6 +738,7 @@ static int csi2rx_probe(struct platform_device *pdev)
 	if (ret)
 		goto err_cleanup;
 
+	pm_runtime_enable(csi2rx->dev);
 	ret = v4l2_async_register_subdev(&csi2rx->subdev);
 	if (ret < 0)
 		goto err_free_state;
@@ -719,6 +753,7 @@ static int csi2rx_probe(struct platform_device *pdev)
 
 err_free_state:
 	v4l2_subdev_cleanup(&csi2rx->subdev);
+	pm_runtime_disable(csi2rx->dev);
 err_cleanup:
 	v4l2_async_nf_unregister(&csi2rx->notifier);
 	v4l2_async_nf_cleanup(&csi2rx->notifier);
@@ -737,9 +772,14 @@ static void csi2rx_remove(struct platform_device *pdev)
 	v4l2_async_unregister_subdev(&csi2rx->subdev);
 	v4l2_subdev_cleanup(&csi2rx->subdev);
 	media_entity_cleanup(&csi2rx->subdev.entity);
+	pm_runtime_disable(csi2rx->dev);
 	kfree(csi2rx);
 }
 
+static const struct dev_pm_ops csi2rx_pm_ops = {
+	SET_RUNTIME_PM_OPS(csi2rx_suspend, csi2rx_resume, NULL)
+};
+
 static const struct of_device_id csi2rx_of_table[] = {
 	{ .compatible = "starfive,jh7110-csi2rx" },
 	{ .compatible = "cdns,csi2rx" },
@@ -754,6 +794,7 @@ static struct platform_driver csi2rx_driver = {
 	.driver	= {
 		.name		= "cdns-csi2rx",
 		.of_match_table	= csi2rx_of_table,
+		.pm		= &csi2rx_pm_ops,
 	},
 };
 module_platform_driver(csi2rx_driver);
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH v1 2/4] media: cadence: csi2rx: Add suspend and resume support
  2024-03-26  3:12 [PATCH v1 0/4] Add StarFive Camera Subsystem hibernation support Changhuang Liang
  2024-03-26  3:12 ` [PATCH v1 1/4] media: cadence: csi2rx: Support runtime PM Changhuang Liang
@ 2024-03-26  3:12 ` Changhuang Liang
  2024-03-26  3:12 ` [PATCH v1 3/4] staging: media: starfive: Extract the ISP stream on as a helper function Changhuang Liang
  2024-03-26  3:12 ` [PATCH v1 4/4] staging: media: starfive: Add suspend and resume support Changhuang Liang
  3 siblings, 0 replies; 5+ messages in thread
From: Changhuang Liang @ 2024-03-26  3:12 UTC (permalink / raw)
  To: Mauro Carvalho Chehab, Greg Kroah-Hartman
  Cc: Hans Verkuil, Laurent Pinchart, Jack Zhu, Changhuang Liang,
	Dan Carpenter, Jayshri Pawar, Jai Luthra, linux-media,
	linux-kernel, linux-staging

This patch implements suspend and resume operation for Cadence MIPI-CSI2
RX Controller.

Signed-off-by: Changhuang Liang <changhuang.liang@starfivetech.com>
---
 drivers/media/platform/cadence/cdns-csi2rx.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/media/platform/cadence/cdns-csi2rx.c b/drivers/media/platform/cadence/cdns-csi2rx.c
index a8b86369e34f..1f629be91bf5 100644
--- a/drivers/media/platform/cadence/cdns-csi2rx.c
+++ b/drivers/media/platform/cadence/cdns-csi2rx.c
@@ -778,6 +778,7 @@ static void csi2rx_remove(struct platform_device *pdev)
 
 static const struct dev_pm_ops csi2rx_pm_ops = {
 	SET_RUNTIME_PM_OPS(csi2rx_suspend, csi2rx_resume, NULL)
+	SET_SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend, pm_runtime_force_resume)
 };
 
 static const struct of_device_id csi2rx_of_table[] = {
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH v1 3/4] staging: media: starfive: Extract the ISP stream on as a helper function
  2024-03-26  3:12 [PATCH v1 0/4] Add StarFive Camera Subsystem hibernation support Changhuang Liang
  2024-03-26  3:12 ` [PATCH v1 1/4] media: cadence: csi2rx: Support runtime PM Changhuang Liang
  2024-03-26  3:12 ` [PATCH v1 2/4] media: cadence: csi2rx: Add suspend and resume support Changhuang Liang
@ 2024-03-26  3:12 ` Changhuang Liang
  2024-03-26  3:12 ` [PATCH v1 4/4] staging: media: starfive: Add suspend and resume support Changhuang Liang
  3 siblings, 0 replies; 5+ messages in thread
From: Changhuang Liang @ 2024-03-26  3:12 UTC (permalink / raw)
  To: Mauro Carvalho Chehab, Greg Kroah-Hartman
  Cc: Hans Verkuil, Laurent Pinchart, Jack Zhu, Changhuang Liang,
	Dan Carpenter, Jayshri Pawar, Jai Luthra, linux-media,
	linux-kernel, linux-staging

Extract the ISP stream on as a helper function and open it, Let the
other files can use it.

Signed-off-by: Changhuang Liang <changhuang.liang@starfivetech.com>
---
 .../staging/media/starfive/camss/stf-isp.c    | 27 ++++++++++++-------
 .../staging/media/starfive/camss/stf-isp.h    |  2 ++
 2 files changed, 19 insertions(+), 10 deletions(-)

diff --git a/drivers/staging/media/starfive/camss/stf-isp.c b/drivers/staging/media/starfive/camss/stf-isp.c
index d50616ef351e..16694b502e56 100644
--- a/drivers/staging/media/starfive/camss/stf-isp.c
+++ b/drivers/staging/media/starfive/camss/stf-isp.c
@@ -58,23 +58,30 @@ int stf_isp_init(struct stfcamss *stfcamss)
 	return 0;
 }
 
-static int isp_set_stream(struct v4l2_subdev *sd, int enable)
+void stf_isp_stream_on(struct stf_isp_dev *isp_dev,
+		       struct v4l2_subdev_state *sd_state)
 {
-	struct stf_isp_dev *isp_dev = v4l2_get_subdevdata(sd);
-	struct v4l2_subdev_state *sd_state;
 	struct v4l2_mbus_framefmt *fmt;
 	struct v4l2_rect *crop;
 
-	sd_state = v4l2_subdev_lock_and_get_active_state(sd);
 	fmt = v4l2_subdev_state_get_format(sd_state, STF_ISP_PAD_SINK);
 	crop = v4l2_subdev_state_get_crop(sd_state, STF_ISP_PAD_SRC);
 
-	if (enable) {
-		stf_isp_reset(isp_dev);
-		stf_isp_init_cfg(isp_dev);
-		stf_isp_settings(isp_dev, crop, fmt->code);
-		stf_isp_stream_set(isp_dev);
-	}
+	stf_isp_reset(isp_dev);
+	stf_isp_init_cfg(isp_dev);
+	stf_isp_settings(isp_dev, crop, fmt->code);
+	stf_isp_stream_set(isp_dev);
+}
+
+static int isp_set_stream(struct v4l2_subdev *sd, int enable)
+{
+	struct stf_isp_dev *isp_dev = v4l2_get_subdevdata(sd);
+	struct v4l2_subdev_state *sd_state;
+
+	sd_state = v4l2_subdev_lock_and_get_active_state(sd);
+
+	if (enable)
+		stf_isp_stream_on(isp_dev, sd_state);
 
 	v4l2_subdev_call(isp_dev->source_subdev, video, s_stream, enable);
 
diff --git a/drivers/staging/media/starfive/camss/stf-isp.h b/drivers/staging/media/starfive/camss/stf-isp.h
index 955cbb048363..1a3e8cf7859c 100644
--- a/drivers/staging/media/starfive/camss/stf-isp.h
+++ b/drivers/staging/media/starfive/camss/stf-isp.h
@@ -421,6 +421,8 @@ void stf_isp_init_cfg(struct stf_isp_dev *isp_dev);
 void stf_isp_settings(struct stf_isp_dev *isp_dev,
 		      struct v4l2_rect *crop, u32 mcode);
 void stf_isp_stream_set(struct stf_isp_dev *isp_dev);
+void stf_isp_stream_on(struct stf_isp_dev *isp_dev,
+		       struct v4l2_subdev_state *sd_state);
 int stf_isp_init(struct stfcamss *stfcamss);
 int stf_isp_register(struct stf_isp_dev *isp_dev, struct v4l2_device *v4l2_dev);
 int stf_isp_unregister(struct stf_isp_dev *isp_dev);
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH v1 4/4] staging: media: starfive: Add suspend and resume support
  2024-03-26  3:12 [PATCH v1 0/4] Add StarFive Camera Subsystem hibernation support Changhuang Liang
                   ` (2 preceding siblings ...)
  2024-03-26  3:12 ` [PATCH v1 3/4] staging: media: starfive: Extract the ISP stream on as a helper function Changhuang Liang
@ 2024-03-26  3:12 ` Changhuang Liang
  3 siblings, 0 replies; 5+ messages in thread
From: Changhuang Liang @ 2024-03-26  3:12 UTC (permalink / raw)
  To: Mauro Carvalho Chehab, Greg Kroah-Hartman
  Cc: Hans Verkuil, Laurent Pinchart, Jack Zhu, Changhuang Liang,
	Dan Carpenter, Jayshri Pawar, Jai Luthra, linux-media,
	linux-kernel, linux-staging

This patch implements suspend and resume operation for StarFive Camera
Subsystem. It supports hibernation during streaming and resume streaming
when the system wake-up stage.

Signed-off-by: Changhuang Liang <changhuang.liang@starfivetech.com>
---
 .../staging/media/starfive/camss/stf-camss.c  | 49 +++++++++++++++++++
 1 file changed, 49 insertions(+)

diff --git a/drivers/staging/media/starfive/camss/stf-camss.c b/drivers/staging/media/starfive/camss/stf-camss.c
index a587f860101a..9abd8ee405e2 100644
--- a/drivers/staging/media/starfive/camss/stf-camss.c
+++ b/drivers/staging/media/starfive/camss/stf-camss.c
@@ -412,10 +412,59 @@ static int __maybe_unused stfcamss_runtime_resume(struct device *dev)
 	return 0;
 }
 
+static int __maybe_unused stfcamss_suspend(struct device *dev)
+{
+	struct stfcamss *stfcamss = dev_get_drvdata(dev);
+	struct stfcamss_video *video;
+	unsigned int i;
+
+	for (i = 0; i < STF_CAPTURE_NUM; ++i) {
+		video = &stfcamss->captures[i].video;
+		if (video->vb2_q.streaming) {
+			video->ops->stop_streaming(video);
+			video->ops->flush_buffers(video, VB2_BUF_STATE_ERROR);
+		}
+	}
+
+	return pm_runtime_force_suspend(dev);
+}
+
+static int __maybe_unused stfcamss_resume(struct device *dev)
+{
+	struct stfcamss *stfcamss = dev_get_drvdata(dev);
+	struct stf_isp_dev *isp_dev = &stfcamss->isp_dev;
+	struct v4l2_subdev_state *sd_state;
+	struct stfcamss_video *video;
+	unsigned int i;
+	int ret;
+
+	ret = pm_runtime_force_resume(dev);
+	if (ret < 0) {
+		dev_err(dev, "Failed to resume\n");
+		return ret;
+	}
+
+	sd_state = v4l2_subdev_lock_and_get_active_state(&isp_dev->subdev);
+
+	if (isp_dev->subdev.enabled_streams)
+		stf_isp_stream_on(isp_dev, sd_state);
+
+	v4l2_subdev_unlock_state(sd_state);
+
+	for (i = 0; i < STF_CAPTURE_NUM; ++i) {
+		video = &stfcamss->captures[i].video;
+		if (video->vb2_q.streaming)
+			video->ops->start_streaming(video);
+	}
+
+	return 0;
+}
+
 static const struct dev_pm_ops stfcamss_pm_ops = {
 	SET_RUNTIME_PM_OPS(stfcamss_runtime_suspend,
 			   stfcamss_runtime_resume,
 			   NULL)
+	SET_SYSTEM_SLEEP_PM_OPS(stfcamss_suspend, stfcamss_resume)
 };
 
 static struct platform_driver stfcamss_driver = {
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2024-03-26  5:48 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-26  3:12 [PATCH v1 0/4] Add StarFive Camera Subsystem hibernation support Changhuang Liang
2024-03-26  3:12 ` [PATCH v1 1/4] media: cadence: csi2rx: Support runtime PM Changhuang Liang
2024-03-26  3:12 ` [PATCH v1 2/4] media: cadence: csi2rx: Add suspend and resume support Changhuang Liang
2024-03-26  3:12 ` [PATCH v1 3/4] staging: media: starfive: Extract the ISP stream on as a helper function Changhuang Liang
2024-03-26  3:12 ` [PATCH v1 4/4] staging: media: starfive: Add suspend and resume support Changhuang Liang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).