Linux kernel and device drivers for NXP i.MX platforms
 help / color / mirror / Atom feed
From: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
To: Frank Li <Frank.li@nxp.com>
Cc: linux-media@vger.kernel.org, Rui Miguel Silva <rmfrfs@gmail.com>,
	Martin Kepplinger <martink@posteo.de>,
	Purism Kernel Team <kernel@puri.sm>,
	Pengutronix Kernel Team <kernel@pengutronix.de>,
	imx@lists.linux.dev, Stefan Klug <stefan.klug@ideasonboard.com>,
	Sakari Ailus <sakari.ailus@iki.fi>
Subject: Re: [PATCH v1 2/6] media: imx-mipi-csis: Switch to .enable_streams()
Date: Fri, 7 Nov 2025 20:32:55 +0200	[thread overview]
Message-ID: <20251107183255.GD5558@pendragon.ideasonboard.com> (raw)
In-Reply-To: <aQ4eaPxL3n1I/95Y@lizhi-Precision-Tower-5810>

On Fri, Nov 07, 2025 at 11:29:28AM -0500, Frank Li wrote:
> On Fri, Nov 07, 2025 at 03:58:09AM +0200, Laurent Pinchart wrote:
> > To prepare for multi-stream support, switch from the legacy .s_stream()
> > operation to the .enable_streams() and .disable_streams() operations.
> >
> > Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> > ---
> >  drivers/media/platform/nxp/imx-mipi-csis.c | 146 ++++++++++++---------
> >  1 file changed, 87 insertions(+), 59 deletions(-)
> >
> > diff --git a/drivers/media/platform/nxp/imx-mipi-csis.c b/drivers/media/platform/nxp/imx-mipi-csis.c
> > index 42b1ec8eed96..f142e79acbcf 100644
> > --- a/drivers/media/platform/nxp/imx-mipi-csis.c
> > +++ b/drivers/media/platform/nxp/imx-mipi-csis.c
> > @@ -350,6 +350,7 @@ struct mipi_csis_device {
> >  	struct {
> >  		struct v4l2_subdev *sd;
> >  		const struct media_pad *pad;
> > +		u64 enabled_streams;
> >  	} source;
> >
> >  	struct v4l2_mbus_config_mipi_csi2 bus;
> > @@ -1019,64 +1020,6 @@ static struct mipi_csis_device *sd_to_mipi_csis_device(struct v4l2_subdev *sdev)
> >  	return container_of(sdev, struct mipi_csis_device, sd);
> >  }
> >
> > -static int mipi_csis_s_stream(struct v4l2_subdev *sd, int enable)
> > -{
> > -	struct mipi_csis_device *csis = sd_to_mipi_csis_device(sd);
> > -	const struct v4l2_mbus_framefmt *format;
> > -	const struct csis_pix_format *csis_fmt;
> > -	struct v4l2_subdev_state *state;
> > -	int ret;
> > -
> > -	if (!enable) {
> > -		v4l2_subdev_disable_streams(csis->source.sd,
> > -					    csis->source.pad->index, BIT(0));
> > -
> > -		mipi_csis_stop_stream(csis);
> > -		if (csis->debug.enable)
> > -			mipi_csis_log_counters(csis, true);
> > -
> > -		pm_runtime_put(csis->dev);
> > -
> > -		return 0;
> > -	}
> > -
> > -	state = v4l2_subdev_lock_and_get_active_state(sd);
> > -
> > -	format = v4l2_subdev_state_get_format(state, CSIS_PAD_SINK);
> > -	csis_fmt = find_csis_format(format->code);
> > -
> > -	ret = mipi_csis_calculate_params(csis, csis_fmt);
> > -	if (ret < 0)
> > -		goto err_unlock;
> > -
> > -	mipi_csis_clear_counters(csis);
> > -
> > -	ret = pm_runtime_resume_and_get(csis->dev);
> > -	if (ret < 0)
> > -		goto err_unlock;
> > -
> > -	mipi_csis_start_stream(csis, format, csis_fmt);
> > -
> > -	ret = v4l2_subdev_enable_streams(csis->source.sd,
> > -					 csis->source.pad->index, BIT(0));
> > -	if (ret < 0)
> > -		goto err_stop;
> > -
> > -	mipi_csis_log_counters(csis, true);
> > -
> > -	v4l2_subdev_unlock_state(state);
> > -
> > -	return 0;
> > -
> > -err_stop:
> > -	mipi_csis_stop_stream(csis);
> > -	pm_runtime_put(csis->dev);
> > -err_unlock:
> > -	v4l2_subdev_unlock_state(state);
> > -
> > -	return ret;
> > -}
> > -
> >  static int mipi_csis_enum_mbus_code(struct v4l2_subdev *sd,
> >  				    struct v4l2_subdev_state *state,
> >  				    struct v4l2_subdev_mbus_code_enum *code)
> > @@ -1211,6 +1154,89 @@ static int mipi_csis_get_frame_desc(struct v4l2_subdev *sd, unsigned int pad,
> >  	return 0;
> >  }
> >
> > +static int mipi_csis_enable_streams(struct v4l2_subdev *sd,
> > +				    struct v4l2_subdev_state *state,
> > +				    u32 pad, u64 streams_mask)
> > +{
> > +	struct mipi_csis_device *csis = sd_to_mipi_csis_device(sd);
> > +	u64 sink_streams;
> > +	int ret;
> > +
> > +	sink_streams = v4l2_subdev_state_xlate_streams(state, CSIS_PAD_SOURCE,
> > +						       CSIS_PAD_SINK,
> 
> Original code use hardcode BIT(0), I think keep the same logic with original
> code in this type patch to easy review.
> 
> Add bitmask enabled_streams should be following patch.

It could be moved to patch 6/6, which is where support for multiple
streams is enabled, but I've decided to instead keep it here as 6/6 is
already a bit patch. I also think it's better to handle it all here
instead of doing a partial conversion to .enable_streams(), a
self-contained feature is easier to review than a partial implementation
that then gets fixed in a separate patch.

> > +						       &streams_mask);
> > +	if (!sink_streams || !streams_mask)
> > +		return -EINVAL;
> > +
> > +	/* Start the CSIS with the first stream. */
> > +	if (!csis->source.enabled_streams) {
> > +		const struct v4l2_mbus_framefmt *format;
> > +		const struct csis_pix_format *csis_fmt;
> > +
> > +		format = v4l2_subdev_state_get_format(state, CSIS_PAD_SINK);
> > +		csis_fmt = find_csis_format(format->code);
> > +
> > +		ret = mipi_csis_calculate_params(csis, csis_fmt);
> > +		if (ret)
> > +			return ret;
> > +
> > +		mipi_csis_clear_counters(csis);
> > +
> > +		ret = pm_runtime_resume_and_get(csis->dev);
> > +		if (ret < 0)
> > +			return ret;
> > +
> > +		mipi_csis_start_stream(csis, format, csis_fmt);
> > +	}
> > +
> > +	ret = v4l2_subdev_enable_streams(csis->source.sd,
> > +					 csis->source.pad->index, sink_streams);
> > +	if (ret) {
> > +		if (!csis->source.enabled_streams) {
> > +			mipi_csis_stop_stream(csis);
> > +			pm_runtime_put(csis->dev);
> > +		}
> > +
> > +		return ret;
> > +	}
> > +
> > +	mipi_csis_log_counters(csis, true);
> > +
> > +	csis->source.enabled_streams |= streams_mask;
> > +
> > +	return 0;
> > +}
> > +
> > +static int mipi_csis_disable_streams(struct v4l2_subdev *sd,
> > +				     struct v4l2_subdev_state *state,
> > +				     u32 pad, u64 streams_mask)
> > +{
> > +	struct mipi_csis_device *csis = sd_to_mipi_csis_device(sd);
> > +	u64 sink_streams;
> > +
> > +	sink_streams = v4l2_subdev_state_xlate_streams(state, CSIS_PAD_SOURCE,
> > +						       CSIS_PAD_SINK,
> > +						       &streams_mask);
> > +	if (!sink_streams || !streams_mask)
> > +		return -EINVAL;
> > +
> > +	v4l2_subdev_disable_streams(csis->source.sd,
> > +				    csis->source.pad->index, sink_streams);
> > +`
> > +	csis->source.enabled_streams &= ~streams_mask;
> > +
> > +	/* Stop the CSIS with the last stream. */
> > +	if (!csis->source.enabled_streams) {
> > +		mipi_csis_stop_stream(csis);
> > +		pm_runtime_put(csis->dev);
> > +
> > +		if (csis->debug.enable)
> > +			mipi_csis_log_counters(csis, true);
> > +	}
> > +
> > +	return 0;
> > +}
> > +
> >  static int mipi_csis_init_state(struct v4l2_subdev *sd,
> >  				struct v4l2_subdev_state *state)
> >  {
> > @@ -1263,7 +1289,7 @@ static const struct v4l2_subdev_core_ops mipi_csis_core_ops = {
> >  };
> >
> >  static const struct v4l2_subdev_video_ops mipi_csis_video_ops = {
> > -	.s_stream	= mipi_csis_s_stream,
> > +	.s_stream		= v4l2_subdev_s_stream_helper,
> >  };
> >
> >  static const struct v4l2_subdev_pad_ops mipi_csis_pad_ops = {
> > @@ -1271,6 +1297,8 @@ static const struct v4l2_subdev_pad_ops mipi_csis_pad_ops = {
> >  	.get_fmt		= v4l2_subdev_get_fmt,
> >  	.set_fmt		= mipi_csis_set_fmt,
> >  	.get_frame_desc		= mipi_csis_get_frame_desc,
> > +	.enable_streams		= mipi_csis_enable_streams,
> > +	.disable_streams	= mipi_csis_disable_streams,
> >  };
> >
> >  static const struct v4l2_subdev_ops mipi_csis_subdev_ops = {

-- 
Regards,

Laurent Pinchart

  reply	other threads:[~2025-11-07 18:33 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-11-07  1:58 [PATCH v1 0/6] media: imx-mipi-csis: Add streams support Laurent Pinchart
2025-11-07  1:58 ` [PATCH v1 1/6] media: imx-mipi-csis: Add VC-related register fields Laurent Pinchart
2025-11-07 16:19   ` Frank Li
2025-11-07 18:44     ` Laurent Pinchart
2025-11-07 20:37       ` Frank Li
2025-11-07  1:58 ` [PATCH v1 2/6] media: imx-mipi-csis: Switch to .enable_streams() Laurent Pinchart
2025-11-07 16:29   ` Frank Li
2025-11-07 18:32     ` Laurent Pinchart [this message]
2025-11-07  1:58 ` [PATCH v1 3/6] media: imx-mipi-csis: Implement the .set_routing() operation Laurent Pinchart
2025-11-07 16:36   ` Frank Li
2025-11-07 18:30     ` Laurent Pinchart
2025-11-07 20:38       ` Frank Li
2025-11-09 21:48   ` kernel test robot
2025-11-07  1:58 ` [PATCH v1 4/6] media: imx-mipi-csis: Group runtime parameters in structure Laurent Pinchart
2025-11-07 16:40   ` Frank Li
2025-11-07  1:58 ` [PATCH v1 5/6] media: imx-mipi-csis: Set all per-channel registers in one function Laurent Pinchart
2025-11-07 16:37   ` Frank Li
2025-11-07  1:58 ` [PATCH v1 6/6] media: imx-mipi-csis: Add multi-channel support Laurent Pinchart
2025-11-07 16:48   ` Frank Li
2025-11-07 18:43     ` Laurent Pinchart
2025-11-20  3:12     ` G.N. Zhou
2025-11-20 15:23       ` Frank Li
2025-11-20 16:22       ` Laurent Pinchart
2025-12-02  0:59         ` [EXT] " G.N. Zhou
2025-11-07  9:31 ` [PATCH v1 0/6] media: imx-mipi-csis: Add streams support Martin Kepplinger
2025-11-07 18:28   ` Laurent Pinchart

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20251107183255.GD5558@pendragon.ideasonboard.com \
    --to=laurent.pinchart@ideasonboard.com \
    --cc=Frank.li@nxp.com \
    --cc=imx@lists.linux.dev \
    --cc=kernel@pengutronix.de \
    --cc=kernel@puri.sm \
    --cc=linux-media@vger.kernel.org \
    --cc=martink@posteo.de \
    --cc=rmfrfs@gmail.com \
    --cc=sakari.ailus@iki.fi \
    --cc=stefan.klug@ideasonboard.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox