mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v2 0/2] media: stm32: correct s_stream calls in dcmi & st-mipid02
@ 2023-07-21 12:03 Alain Volmat
  2023-07-21 12:03 ` [PATCH v2 1/2] media: i2c: st_mipid02: cascade s_stream call to the source subdev Alain Volmat
  2023-07-21 12:03 ` [PATCH v2 2/2] media: stm32: dcmi: only call s_stream on " Alain Volmat
  0 siblings, 2 replies; 5+ messages in thread
From: Alain Volmat @ 2023-07-21 12:03 UTC (permalink / raw)
  To: Benjamin Mugnier, Sylvain Petinot, Mauro Carvalho Chehab,
	Hugues Fruchet, Maxime Coquelin, Alexandre Torgue
  Cc: Alain Volmat, linux-media, linux-kernel, linux-stm32, linux-arm-kernel

Currently the stm32 dcmi driver is calling s_stream to all subdevs until
reaching the sensor subdev.  This serie corrects this by having a subdev
only calling s_stream on its source subdev.

v2: correct an uninitialized variable (ret) in st_mipid02 patch

Alain Volmat (2):
  media: i2c: st_mipid02: cascade s_stream call to the source subdev
  media: stm32: dcmi: only call s_stream on the source subdev

 drivers/media/i2c/st-mipid02.c               | 13 +++-
 drivers/media/platform/st/stm32/stm32-dcmi.c | 63 +++++---------------
 2 files changed, 26 insertions(+), 50 deletions(-)

-- 
2.25.1


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

* [PATCH v2 1/2] media: i2c: st_mipid02: cascade s_stream call to the source subdev
  2023-07-21 12:03 [PATCH v2 0/2] media: stm32: correct s_stream calls in dcmi & st-mipid02 Alain Volmat
@ 2023-07-21 12:03 ` Alain Volmat
  2023-07-25  7:56   ` Benjamin Mugnier
  2023-07-21 12:03 ` [PATCH v2 2/2] media: stm32: dcmi: only call s_stream on " Alain Volmat
  1 sibling, 1 reply; 5+ messages in thread
From: Alain Volmat @ 2023-07-21 12:03 UTC (permalink / raw)
  To: Benjamin Mugnier, Sylvain Petinot, Mauro Carvalho Chehab
  Cc: Alain Volmat, linux-media, linux-kernel

Cascade the s_stream call to the source subdev whenever the bridge
streaming is enable / disabled.

Signed-off-by: Alain Volmat <alain.volmat@foss.st.com>
---
v2: correct uninitialized ret variable in mipid02_stream_disable

 drivers/media/i2c/st-mipid02.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/drivers/media/i2c/st-mipid02.c b/drivers/media/i2c/st-mipid02.c
index 906553a28676..ee456bd4cf76 100644
--- a/drivers/media/i2c/st-mipid02.c
+++ b/drivers/media/i2c/st-mipid02.c
@@ -545,7 +545,14 @@ static int mipid02_configure_from_code(struct mipid02_dev *bridge)
 static int mipid02_stream_disable(struct mipid02_dev *bridge)
 {
 	struct i2c_client *client = bridge->i2c_client;
-	int ret;
+	int ret = -EINVAL;
+
+	if (!bridge->s_subdev)
+		goto error;
+
+	ret = v4l2_subdev_call(bridge->s_subdev, video, s_stream, 0);
+	if (ret)
+		goto error;
 
 	/* Disable all lanes */
 	ret = mipid02_write_reg(bridge, MIPID02_CLK_LANE_REG1, 0);
@@ -633,6 +640,10 @@ static int mipid02_stream_enable(struct mipid02_dev *bridge)
 	if (ret)
 		goto error;
 
+	ret = v4l2_subdev_call(bridge->s_subdev, video, s_stream, 1);
+	if (ret)
+		goto error;
+
 	return 0;
 
 error:
-- 
2.25.1


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

* [PATCH v2 2/2] media: stm32: dcmi: only call s_stream on the source subdev
  2023-07-21 12:03 [PATCH v2 0/2] media: stm32: correct s_stream calls in dcmi & st-mipid02 Alain Volmat
  2023-07-21 12:03 ` [PATCH v2 1/2] media: i2c: st_mipid02: cascade s_stream call to the source subdev Alain Volmat
@ 2023-07-21 12:03 ` Alain Volmat
  2023-07-25  8:34   ` Hugues FRUCHET
  1 sibling, 1 reply; 5+ messages in thread
From: Alain Volmat @ 2023-07-21 12:03 UTC (permalink / raw)
  To: Hugues Fruchet, Mauro Carvalho Chehab, Maxime Coquelin, Alexandre Torgue
  Cc: Alain Volmat, linux-media, linux-stm32, linux-arm-kernel, linux-kernel

Avoid calling s_stream on each subdev until reaching the sensor and
instead call s_stream on the source subdev only (which will in turn
do whatever needed to start the stream).

Signed-off-by: Alain Volmat <alain.volmat@foss.st.com>
---
 drivers/media/platform/st/stm32/stm32-dcmi.c | 63 +++++---------------
 1 file changed, 14 insertions(+), 49 deletions(-)

diff --git a/drivers/media/platform/st/stm32/stm32-dcmi.c b/drivers/media/platform/st/stm32/stm32-dcmi.c
index dad6e22e4ce4..ac8a5031dce6 100644
--- a/drivers/media/platform/st/stm32/stm32-dcmi.c
+++ b/drivers/media/platform/st/stm32/stm32-dcmi.c
@@ -134,6 +134,7 @@ struct stm32_dcmi {
 	struct video_device		*vdev;
 	struct v4l2_async_notifier	notifier;
 	struct v4l2_subdev		*source;
+	struct v4l2_subdev		*s_subdev;
 	struct v4l2_format		fmt;
 	struct v4l2_rect		crop;
 	bool				do_crop;
@@ -692,51 +693,6 @@ static int dcmi_pipeline_s_fmt(struct stm32_dcmi *dcmi,
 	return 0;
 }
 
-static int dcmi_pipeline_s_stream(struct stm32_dcmi *dcmi, int state)
-{
-	struct media_entity *entity = &dcmi->vdev->entity;
-	struct v4l2_subdev *subdev;
-	struct media_pad *pad;
-	int ret;
-
-	/* Start/stop all entities within pipeline */
-	while (1) {
-		pad = &entity->pads[0];
-		if (!(pad->flags & MEDIA_PAD_FL_SINK))
-			break;
-
-		pad = media_pad_remote_pad_first(pad);
-		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
-			break;
-
-		entity = pad->entity;
-		subdev = media_entity_to_v4l2_subdev(entity);
-
-		ret = v4l2_subdev_call(subdev, video, s_stream, state);
-		if (ret < 0 && ret != -ENOIOCTLCMD) {
-			dev_err(dcmi->dev, "%s: \"%s\" failed to %s streaming (%d)\n",
-				__func__, subdev->name,
-				state ? "start" : "stop", ret);
-			return ret;
-		}
-
-		dev_dbg(dcmi->dev, "\"%s\" is %s\n",
-			subdev->name, state ? "started" : "stopped");
-	}
-
-	return 0;
-}
-
-static int dcmi_pipeline_start(struct stm32_dcmi *dcmi)
-{
-	return dcmi_pipeline_s_stream(dcmi, 1);
-}
-
-static void dcmi_pipeline_stop(struct stm32_dcmi *dcmi)
-{
-	dcmi_pipeline_s_stream(dcmi, 0);
-}
-
 static int dcmi_start_streaming(struct vb2_queue *vq, unsigned int count)
 {
 	struct stm32_dcmi *dcmi = vb2_get_drv_priv(vq);
@@ -758,9 +714,12 @@ static int dcmi_start_streaming(struct vb2_queue *vq, unsigned int count)
 		goto err_pm_put;
 	}
 
-	ret = dcmi_pipeline_start(dcmi);
-	if (ret)
+	ret = v4l2_subdev_call(dcmi->s_subdev, video, s_stream, 1);
+	if (ret < 0) {
+		dev_err(dcmi->dev, "%s: Failed to start source subdev, error (%d)\n",
+			__func__, ret);
 		goto err_media_pipeline_stop;
+	}
 
 	spin_lock_irq(&dcmi->irqlock);
 
@@ -862,7 +821,7 @@ static int dcmi_start_streaming(struct vb2_queue *vq, unsigned int count)
 	return 0;
 
 err_pipeline_stop:
-	dcmi_pipeline_stop(dcmi);
+	v4l2_subdev_call(dcmi->s_subdev, video, s_stream, 0);
 
 err_media_pipeline_stop:
 	video_device_pipeline_stop(dcmi->vdev);
@@ -889,8 +848,12 @@ static void dcmi_stop_streaming(struct vb2_queue *vq)
 {
 	struct stm32_dcmi *dcmi = vb2_get_drv_priv(vq);
 	struct dcmi_buf *buf, *node;
+	int ret;
 
-	dcmi_pipeline_stop(dcmi);
+	ret = v4l2_subdev_call(dcmi->s_subdev, video, s_stream, 0);
+	if (ret < 0)
+		dev_err(dcmi->dev, "%s: Failed to stop source subdev, error (%d)\n",
+			__func__, ret);
 
 	video_device_pipeline_stop(dcmi->vdev);
 
@@ -1876,6 +1839,8 @@ static int dcmi_graph_notify_bound(struct v4l2_async_notifier *notifier,
 		dev_dbg(dcmi->dev, "DCMI is now linked to \"%s\"\n",
 			subdev->name);
 
+	dcmi->s_subdev = subdev;
+
 	return ret;
 }
 
-- 
2.25.1


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

* Re: [PATCH v2 1/2] media: i2c: st_mipid02: cascade s_stream call to the source subdev
  2023-07-21 12:03 ` [PATCH v2 1/2] media: i2c: st_mipid02: cascade s_stream call to the source subdev Alain Volmat
@ 2023-07-25  7:56   ` Benjamin Mugnier
  0 siblings, 0 replies; 5+ messages in thread
From: Benjamin Mugnier @ 2023-07-25  7:56 UTC (permalink / raw)
  To: Alain Volmat, Sylvain Petinot, Mauro Carvalho Chehab
  Cc: linux-media, linux-kernel

Hi Alain,

Reviewed-By: Benjamin Mugnier <benjamin.mugnier@foss.st.com>

On 7/21/23 14:03, Alain Volmat wrote:
> Cascade the s_stream call to the source subdev whenever the bridge
> streaming is enable / disabled.
> 
> Signed-off-by: Alain Volmat <alain.volmat@foss.st.com>
> ---
> v2: correct uninitialized ret variable in mipid02_stream_disable
> 
>  drivers/media/i2c/st-mipid02.c | 13 ++++++++++++-
>  1 file changed, 12 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/media/i2c/st-mipid02.c b/drivers/media/i2c/st-mipid02.c
> index 906553a28676..ee456bd4cf76 100644
> --- a/drivers/media/i2c/st-mipid02.c
> +++ b/drivers/media/i2c/st-mipid02.c
> @@ -545,7 +545,14 @@ static int mipid02_configure_from_code(struct mipid02_dev *bridge)
>  static int mipid02_stream_disable(struct mipid02_dev *bridge)
>  {
>  	struct i2c_client *client = bridge->i2c_client;
> -	int ret;
> +	int ret = -EINVAL;
> +
> +	if (!bridge->s_subdev)
> +		goto error;
> +
> +	ret = v4l2_subdev_call(bridge->s_subdev, video, s_stream, 0);
> +	if (ret)
> +		goto error;
>  
>  	/* Disable all lanes */
>  	ret = mipid02_write_reg(bridge, MIPID02_CLK_LANE_REG1, 0);
> @@ -633,6 +640,10 @@ static int mipid02_stream_enable(struct mipid02_dev *bridge)
>  	if (ret)
>  		goto error;
>  
> +	ret = v4l2_subdev_call(bridge->s_subdev, video, s_stream, 1);
> +	if (ret)
> +		goto error;
> +
>  	return 0;
>  
>  error:

-- 
Regards,

Benjamin

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

* Re: [PATCH v2 2/2] media: stm32: dcmi: only call s_stream on the source subdev
  2023-07-21 12:03 ` [PATCH v2 2/2] media: stm32: dcmi: only call s_stream on " Alain Volmat
@ 2023-07-25  8:34   ` Hugues FRUCHET
  0 siblings, 0 replies; 5+ messages in thread
From: Hugues FRUCHET @ 2023-07-25  8:34 UTC (permalink / raw)
  To: Alain Volmat, Mauro Carvalho Chehab, Maxime Coquelin, Alexandre Torgue
  Cc: linux-media, linux-stm32, linux-arm-kernel, linux-kernel

Reviewed-by: Hugues FRUCHET <hugues.fruchet@foss.st.com>

On 7/21/23 14:03, Alain Volmat wrote:
> Avoid calling s_stream on each subdev until reaching the sensor and
> instead call s_stream on the source subdev only (which will in turn
> do whatever needed to start the stream).
> 
> Signed-off-by: Alain Volmat <alain.volmat@foss.st.com>
> ---
>   drivers/media/platform/st/stm32/stm32-dcmi.c | 63 +++++---------------
>   1 file changed, 14 insertions(+), 49 deletions(-)
> 
> diff --git a/drivers/media/platform/st/stm32/stm32-dcmi.c b/drivers/media/platform/st/stm32/stm32-dcmi.c
> index dad6e22e4ce4..ac8a5031dce6 100644
> --- a/drivers/media/platform/st/stm32/stm32-dcmi.c
> +++ b/drivers/media/platform/st/stm32/stm32-dcmi.c
> @@ -134,6 +134,7 @@ struct stm32_dcmi {
>   	struct video_device		*vdev;
>   	struct v4l2_async_notifier	notifier;
>   	struct v4l2_subdev		*source;
> +	struct v4l2_subdev		*s_subdev;
>   	struct v4l2_format		fmt;
>   	struct v4l2_rect		crop;
>   	bool				do_crop;
> @@ -692,51 +693,6 @@ static int dcmi_pipeline_s_fmt(struct stm32_dcmi *dcmi,
>   	return 0;
>   }
>   
> -static int dcmi_pipeline_s_stream(struct stm32_dcmi *dcmi, int state)
> -{
> -	struct media_entity *entity = &dcmi->vdev->entity;
> -	struct v4l2_subdev *subdev;
> -	struct media_pad *pad;
> -	int ret;
> -
> -	/* Start/stop all entities within pipeline */
> -	while (1) {
> -		pad = &entity->pads[0];
> -		if (!(pad->flags & MEDIA_PAD_FL_SINK))
> -			break;
> -
> -		pad = media_pad_remote_pad_first(pad);
> -		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
> -			break;
> -
> -		entity = pad->entity;
> -		subdev = media_entity_to_v4l2_subdev(entity);
> -
> -		ret = v4l2_subdev_call(subdev, video, s_stream, state);
> -		if (ret < 0 && ret != -ENOIOCTLCMD) {
> -			dev_err(dcmi->dev, "%s: \"%s\" failed to %s streaming (%d)\n",
> -				__func__, subdev->name,
> -				state ? "start" : "stop", ret);
> -			return ret;
> -		}
> -
> -		dev_dbg(dcmi->dev, "\"%s\" is %s\n",
> -			subdev->name, state ? "started" : "stopped");
> -	}
> -
> -	return 0;
> -}
> -
> -static int dcmi_pipeline_start(struct stm32_dcmi *dcmi)
> -{
> -	return dcmi_pipeline_s_stream(dcmi, 1);
> -}
> -
> -static void dcmi_pipeline_stop(struct stm32_dcmi *dcmi)
> -{
> -	dcmi_pipeline_s_stream(dcmi, 0);
> -}
> -
>   static int dcmi_start_streaming(struct vb2_queue *vq, unsigned int count)
>   {
>   	struct stm32_dcmi *dcmi = vb2_get_drv_priv(vq);
> @@ -758,9 +714,12 @@ static int dcmi_start_streaming(struct vb2_queue *vq, unsigned int count)
>   		goto err_pm_put;
>   	}
>   
> -	ret = dcmi_pipeline_start(dcmi);
> -	if (ret)
> +	ret = v4l2_subdev_call(dcmi->s_subdev, video, s_stream, 1);
> +	if (ret < 0) {
> +		dev_err(dcmi->dev, "%s: Failed to start source subdev, error (%d)\n",
> +			__func__, ret);
>   		goto err_media_pipeline_stop;
> +	}
>   
>   	spin_lock_irq(&dcmi->irqlock);
>   
> @@ -862,7 +821,7 @@ static int dcmi_start_streaming(struct vb2_queue *vq, unsigned int count)
>   	return 0;
>   
>   err_pipeline_stop:
> -	dcmi_pipeline_stop(dcmi);
> +	v4l2_subdev_call(dcmi->s_subdev, video, s_stream, 0);
>   
>   err_media_pipeline_stop:
>   	video_device_pipeline_stop(dcmi->vdev);
> @@ -889,8 +848,12 @@ static void dcmi_stop_streaming(struct vb2_queue *vq)
>   {
>   	struct stm32_dcmi *dcmi = vb2_get_drv_priv(vq);
>   	struct dcmi_buf *buf, *node;
> +	int ret;
>   
> -	dcmi_pipeline_stop(dcmi);
> +	ret = v4l2_subdev_call(dcmi->s_subdev, video, s_stream, 0);
> +	if (ret < 0)
> +		dev_err(dcmi->dev, "%s: Failed to stop source subdev, error (%d)\n",
> +			__func__, ret);
>   
>   	video_device_pipeline_stop(dcmi->vdev);
>   
> @@ -1876,6 +1839,8 @@ static int dcmi_graph_notify_bound(struct v4l2_async_notifier *notifier,
>   		dev_dbg(dcmi->dev, "DCMI is now linked to \"%s\"\n",
>   			subdev->name);
>   
> +	dcmi->s_subdev = subdev;
> +
>   	return ret;
>   }
>   

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

end of thread, other threads:[~2023-07-25  8:35 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-07-21 12:03 [PATCH v2 0/2] media: stm32: correct s_stream calls in dcmi & st-mipid02 Alain Volmat
2023-07-21 12:03 ` [PATCH v2 1/2] media: i2c: st_mipid02: cascade s_stream call to the source subdev Alain Volmat
2023-07-25  7:56   ` Benjamin Mugnier
2023-07-21 12:03 ` [PATCH v2 2/2] media: stm32: dcmi: only call s_stream on " Alain Volmat
2023-07-25  8:34   ` Hugues FRUCHET

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®