All of lore.kernel.org
 help / color / mirror / Atom feed
From: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
To: Jacopo Mondi <jacopo@jmondi.org>
Cc: linux-media@vger.kernel.org, linux-renesas-soc@vger.kernel.org,
	"Kieran Bingham" <kieran.bingham@ideasonboard.com>,
	"Niklas Söderlund" <niklas.soderlund@ragnatech.se>,
	"Thomas Nizan" <tnizan@witekio.com>
Subject: Re: [PATCH v2 07/11] media: i2c: max9286: Support 12-bit raw bayer formats
Date: Mon, 10 Jan 2022 01:19:01 +0200	[thread overview]
Message-ID: <YdttZRlTlTRJNmCP@pendragon.ideasonboard.com> (raw)
In-Reply-To: <20220109103409.dedytvxvchnar7m2@uno.localdomain>

Hi Jacopo,

On Sun, Jan 09, 2022 at 11:34:09AM +0100, Jacopo Mondi wrote:
> On Sat, Jan 01, 2022 at 08:28:02PM +0200, Laurent Pinchart wrote:
> > Add support for 12-bit raw bayer formats to the driver, configuring the
> > GMSL format accordingly.
> >
> > Signed-off-by: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>
> > ---
> >  drivers/media/i2c/max9286.c | 128 ++++++++++++++++++++++++++----------
> >  1 file changed, 95 insertions(+), 33 deletions(-)
> >
> > diff --git a/drivers/media/i2c/max9286.c b/drivers/media/i2c/max9286.c
> > index 576d9c6fac14..24c2bf4fda53 100644
> > --- a/drivers/media/i2c/max9286.c
> > +++ b/drivers/media/i2c/max9286.c
> > @@ -135,6 +135,11 @@
> >  #define MAX9286_N_PADS			5
> >  #define MAX9286_SRC_PAD			4
> >
> > +struct max9286_format_info {
> > +	u32 code;
> > +	u8 datatype;
> > +};
> > +
> >  struct max9286_source {
> >  	struct v4l2_subdev *sd;
> >  	struct fwnode_handle *fwnode;
> > @@ -214,6 +219,34 @@ static inline struct max9286_priv *sd_to_max9286(struct v4l2_subdev *sd)
> >  	return container_of(sd, struct max9286_priv, sd);
> >  }
> >
> > +static const struct max9286_format_info max9286_formats[] = {
> > +	{
> > +		.code = MEDIA_BUS_FMT_UYVY8_1X16,
> > +		.datatype = MAX9286_DATATYPE_YUV422_8BIT,
> > +	}, {
> > +		.code = MEDIA_BUS_FMT_VYUY8_1X16,
> > +		.datatype = MAX9286_DATATYPE_YUV422_8BIT,
> > +	}, {
> > +		.code = MEDIA_BUS_FMT_YUYV8_1X16,
> > +		.datatype = MAX9286_DATATYPE_YUV422_8BIT,
> > +	}, {
> > +		.code = MEDIA_BUS_FMT_YVYU8_1X16,
> > +		.datatype = MAX9286_DATATYPE_YUV422_8BIT,
> > +	}, {
> > +		.code = MEDIA_BUS_FMT_SBGGR12_1X12,
> > +		.datatype = MAX9286_DATATYPE_RAW12,
> > +	}, {
> > +		.code = MEDIA_BUS_FMT_SGBRG12_1X12,
> > +		.datatype = MAX9286_DATATYPE_RAW12,
> > +	}, {
> > +		.code = MEDIA_BUS_FMT_SGRBG12_1X12,
> > +		.datatype = MAX9286_DATATYPE_RAW12,
> > +	}, {
> > +		.code = MEDIA_BUS_FMT_SRGGB12_1X12,
> > +		.datatype = MAX9286_DATATYPE_RAW12,
> > +	},
> > +};
> > +
> >  /* -----------------------------------------------------------------------------
> >   * I2C IO
> >   */
> > @@ -475,6 +508,38 @@ static int max9286_check_config_link(struct max9286_priv *priv,
> >  	return 0;
> >  }
> >
> > +static void max9286_set_video_format(struct max9286_priv *priv,
> > +				     const struct v4l2_mbus_framefmt *format)
> > +{
> > +	const struct max9286_format_info *info = NULL;
> > +	unsigned int i;
> > +
> > +	for (i = 0; i < ARRAY_SIZE(max9286_formats); ++i) {
> > +		if (max9286_formats[i].code == format->code) {
> > +			info = &max9286_formats[i];
> > +			break;
> > +		}
> > +	}
> > +
> > +	if (WARN_ON(!info))
> > +		return;
> > +
> > +	/*
> > +	 * Video format setup:
> > +	 * Disable CSI output, VC is set according to Link number.
> > +	 */
> > +	max9286_write(priv, 0x15, MAX9286_VCTYPE | MAX9286_0X15_RESV);
> 
> I'm a bit scared about the fact settnig the video format disables the
> CSI-2 output. But for the current usage pattern, it seems ok

I'd like to further reorganize this (on top of this series) by avoiding
the max9286_set_video_format() call from max9286_setup(), as that
shouldn't be needed at probe time.

> > +
> > +	/* Enable CSI-2 Lane D0-D3 only, DBL mode. */
> > +	max9286_write(priv, 0x12, MAX9286_CSIDBL | MAX9286_DBL |
> > +		      MAX9286_CSILANECNT(priv->csi2_data_lanes) |
> > +		      info->datatype);
> > +
> > +	/* Enable HS/VS encoding, use D14/15 for HS/VS, invert VS. */
> > +	max9286_write(priv, 0x0c, MAX9286_HVEN | MAX9286_INVVS |
> > +		      MAX9286_HVSRC_D14);
> > +}
> > +
> >  static void max9286_set_fsync_period(struct max9286_priv *priv)
> >  {
> >  	u32 fsync;
> > @@ -693,6 +758,15 @@ static int max9286_s_stream(struct v4l2_subdev *sd, int enable)
> >  	int ret;
> >
> >  	if (enable) {
> > +		const struct v4l2_mbus_framefmt *format;
> > +
> > +		/*
> > +		 * Get the format from the first used sink pad, as all sink
> > +		 * formats must be identical.
> > +		 */
> > +		format = &priv->fmt[__ffs(priv->bound_sources)];
> > +
> > +		max9286_set_video_format(priv, format);
> >  		max9286_set_fsync_period(priv);
> >
> >  		/*
> > @@ -813,22 +887,20 @@ static int max9286_set_fmt(struct v4l2_subdev *sd,
> >  {
> >  	struct max9286_priv *priv = sd_to_max9286(sd);
> >  	struct v4l2_mbus_framefmt *cfg_fmt;
> > +	unsigned int i;
> >
> >  	if (format->pad == MAX9286_SRC_PAD)
> >  		return -EINVAL;
> >
> > -	/* Refuse non YUV422 formats as we hardcode DT to 8 bit YUV422 */
> > -	switch (format->format.code) {
> > -	case MEDIA_BUS_FMT_UYVY8_1X16:
> > -	case MEDIA_BUS_FMT_VYUY8_1X16:
> > -	case MEDIA_BUS_FMT_YUYV8_1X16:
> > -	case MEDIA_BUS_FMT_YVYU8_1X16:
> > -		break;
> > -	default:
> > -		format->format.code = MEDIA_BUS_FMT_UYVY8_1X16;
> > -		break;
> > +	/* Validate the format. */
> > +	for (i = 0; i < ARRAY_SIZE(max9286_formats); ++i) {
> > +		if (max9286_formats[i].code == format->format.code)
> > +			break;
> >  	}
> >
> > +	if (i == ARRAY_SIZE(max9286_formats))
> > +		format->format.code = max9286_formats[i].code;
> 
> Isn't i past the end of the array now ?

Oops, it should be [0]. I'll fix it.

> > +
> >  	cfg_fmt = max9286_get_pad_format(priv, sd_state, format->pad,
> >  					 format->which);
> >  	if (!cfg_fmt)
> > @@ -886,16 +958,20 @@ static const struct v4l2_subdev_ops max9286_subdev_ops = {
> >  	.pad		= &max9286_pad_ops,
> >  };
> >
> > +static const struct v4l2_mbus_framefmt max9286_default_format = {
> > +	.width		= 1280,
> > +	.height		= 800,
> > +	.code		= MEDIA_BUS_FMT_UYVY8_1X16,
> > +	.colorspace	= V4L2_COLORSPACE_SRGB,
> > +	.field		= V4L2_FIELD_NONE,
> > +	.ycbcr_enc	= V4L2_YCBCR_ENC_DEFAULT,
> > +	.quantization	= V4L2_QUANTIZATION_DEFAULT,
> > +	.xfer_func	= V4L2_XFER_FUNC_DEFAULT,
> > +};
> > +
> >  static void max9286_init_format(struct v4l2_mbus_framefmt *fmt)
> >  {
> > -	fmt->width		= 1280;
> > -	fmt->height		= 800;
> > -	fmt->code		= MEDIA_BUS_FMT_UYVY8_1X16;
> > -	fmt->colorspace		= V4L2_COLORSPACE_SRGB;
> > -	fmt->field		= V4L2_FIELD_NONE;
> > -	fmt->ycbcr_enc		= V4L2_YCBCR_ENC_DEFAULT;
> > -	fmt->quantization	= V4L2_QUANTIZATION_DEFAULT;
> > -	fmt->xfer_func		= V4L2_XFER_FUNC_DEFAULT;
> > +	*fmt = max9286_default_format;
> >  }
> >
> >  static int max9286_open(struct v4l2_subdev *subdev, struct v4l2_subdev_fh *fh)
> > @@ -1054,23 +1130,9 @@ static int max9286_setup(struct max9286_priv *priv)
> >  	max9286_write(priv, 0x0b, link_order[priv->route_mask]);
> >  	max9286_write(priv, 0x69, (0xf & ~priv->route_mask));
> >
> > -	/*
> > -	 * Video format setup:
> > -	 * Disable CSI output, VC is set according to Link number.
> > -	 */
> > -	max9286_write(priv, 0x15, MAX9286_VCTYPE | MAX9286_0X15_RESV);
> > -
> > -	/* Enable CSI-2 Lane D0-D3 only, DBL mode, YUV422 8-bit. */
> > -	max9286_write(priv, 0x12, MAX9286_CSIDBL | MAX9286_DBL |
> > -		      MAX9286_CSILANECNT(priv->csi2_data_lanes) |
> > -		      MAX9286_DATATYPE_YUV422_8BIT);
> > -
> > +	max9286_set_video_format(priv, &max9286_default_format);
> >  	max9286_set_fsync_period(priv);
> >
> > -	/* Enable HS/VS encoding, use D14/15 for HS/VS, invert VS. */
> > -	max9286_write(priv, 0x0c, MAX9286_HVEN | MAX9286_INVVS |
> > -		      MAX9286_HVSRC_D14);
> > -
> >  	/*
> >  	 * The overlap window seems to provide additional validation by tracking
> >  	 * the delay between vsync and frame sync, generating an error if the

-- 
Regards,

Laurent Pinchart

  reply	other threads:[~2022-01-09 23:19 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-01 18:27 [PATCH v2 00/11] media: i2c: max9286: Small new features Laurent Pinchart
2022-01-01 18:27 ` [PATCH v2 01/11] dt-bindings: media: i2c: max9286: Add support for per-port supplies Laurent Pinchart
2022-01-09 11:48   ` Jacopo Mondi
2022-01-10 20:47   ` Rob Herring
2022-01-01 18:27 ` [PATCH v2 02/11] dt-bindings: media: i2c: max9286: Add property to select I2C speed Laurent Pinchart
2022-01-01 22:01   ` Rob Herring
2022-01-04 15:56   ` Rob Herring
2022-01-01 18:27 ` [PATCH v2 03/11] dt-bindings: media: i2c: max9286: Add property to select bus width Laurent Pinchart
2022-01-09 11:47   ` Jacopo Mondi
2022-01-10 20:53   ` Rob Herring
2022-01-10 21:24   ` [PATCH v2.1 " Laurent Pinchart
2022-01-22  0:28     ` Rob Herring
2022-01-01 18:27 ` [PATCH v2 04/11] media: i2c: max9286: Add support for port regulators Laurent Pinchart
2022-01-09 10:04   ` Jacopo Mondi
2022-01-09 23:16     ` Laurent Pinchart
2022-01-01 18:28 ` [PATCH v2 05/11] media: i2c: max9286: Support manual framesync operation Laurent Pinchart
2022-01-09 10:26   ` Jacopo Mondi
2022-01-01 18:28 ` [PATCH v2 06/11] media: i2c: max9286: Rename MAX9286_DATATYPE_RAW11 to RAW12 Laurent Pinchart
2022-01-09 10:26   ` Jacopo Mondi
2022-01-01 18:28 ` [PATCH v2 07/11] media: i2c: max9286: Support 12-bit raw bayer formats Laurent Pinchart
2022-01-09 10:34   ` Jacopo Mondi
2022-01-09 23:19     ` Laurent Pinchart [this message]
2022-01-01 18:28 ` [PATCH v2 08/11] media: i2c: max9286: Define macros for all bits of register 0x15 Laurent Pinchart
2022-01-09 10:37   ` Jacopo Mondi
2022-01-09 23:21     ` Laurent Pinchart
2022-01-10 10:37       ` Sergey Shtylyov
2022-01-10 11:32         ` Laurent Pinchart
2022-01-01 18:28 ` [PATCH v2 09/11] media: i2c: max9286: Configure remote I2C speed from device tree Laurent Pinchart
2022-01-09 10:43   ` Jacopo Mondi
2022-01-09 23:29     ` Laurent Pinchart
2022-01-01 18:28 ` [PATCH v2 10/11] media: i2c: max9286: Configure bus width " Laurent Pinchart
2022-01-09 10:56   ` Jacopo Mondi
2022-01-09 23:32     ` Laurent Pinchart
2022-01-01 18:28 ` [PATCH v2 11/11] media: i2c: max9286: Select HS as data enable signal Laurent Pinchart
2022-01-09 11:42   ` Jacopo Mondi
2022-01-01 23:26 ` [PATCH v2 12/11] media: i2c: max9286: Print power-up GMSL link configuration Laurent Pinchart
2022-01-09 11:44   ` Jacopo Mondi

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=YdttZRlTlTRJNmCP@pendragon.ideasonboard.com \
    --to=laurent.pinchart@ideasonboard.com \
    --cc=jacopo@jmondi.org \
    --cc=kieran.bingham@ideasonboard.com \
    --cc=linux-media@vger.kernel.org \
    --cc=linux-renesas-soc@vger.kernel.org \
    --cc=niklas.soderlund@ragnatech.se \
    --cc=tnizan@witekio.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.