public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
To: Prabhakar <prabhakar.csengg@gmail.com>
Cc: Sakari Ailus <sakari.ailus@linux.intel.com>,
	Kieran Bingham <kieran.bingham@ideasonboard.com>,
	Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>,
	Jacopo Mondi <jacopo.mondi@ideasonboard.com>,
	Mauro Carvalho Chehab <mchehab@kernel.org>,
	Hans Verkuil <hverkuil-cisco@xs4all.nl>,
	linux-media@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-renesas-soc@vger.kernel.org,
	Biju Das <biju.das.jz@bp.renesas.com>,
	Fabrizio Castro <fabrizio.castro.jz@renesas.com>,
	Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com>
Subject: Re: [PATCH v2 09/11] media: i2c: ov5645: Add internal image sink pad
Date: Wed, 25 Sep 2024 19:21:53 +0300	[thread overview]
Message-ID: <20240925162153.GA27666@pendragon.ideasonboard.com> (raw)
In-Reply-To: <20240910170610.226189-10-prabhakar.mahadev-lad.rj@bp.renesas.com>

Hi Prabhakar,

Thank you for the patch.

On Tue, Sep 10, 2024 at 06:06:08PM +0100, Prabhakar wrote:
> From: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com>
> 
> Use the newly added internal pad API to expose the internal
> configuration of the sensor to userspace in a standard manner.
> 
> Signed-off-by: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com>
> ---
>  drivers/media/i2c/ov5645.c | 107 +++++++++++++++++++++++++++----------
>  1 file changed, 79 insertions(+), 28 deletions(-)
> 
> diff --git a/drivers/media/i2c/ov5645.c b/drivers/media/i2c/ov5645.c
> index dc93514608ee..255c6395a268 100644
> --- a/drivers/media/i2c/ov5645.c
> +++ b/drivers/media/i2c/ov5645.c
> @@ -60,6 +60,10 @@
>  #define OV5645_SDE_SAT_U		0x5583
>  #define OV5645_SDE_SAT_V		0x5584
>  
> +#define OV5645_NATIVE_FORMAT	MEDIA_BUS_FMT_SBGGR8_1X8
> +#define OV5645_NATIVE_WIDTH	2592
> +#define OV5645_NATIVE_HEIGHT	1944
> +
>  /* regulator supplies */
>  static const char * const ov5645_supply_name[] = {
>  	"vdddo", /* Digital I/O (1.8V) supply */
> @@ -69,6 +73,12 @@ static const char * const ov5645_supply_name[] = {
>  
>  #define OV5645_NUM_SUPPLIES ARRAY_SIZE(ov5645_supply_name)
>  
> +enum ov5645_pad_ids {
> +	OV5645_PAD_SOURCE,
> +	OV5645_PAD_IMAGE,
> +	OV5645_NUM_PADS,
> +};
> +
>  struct reg_value {
>  	u16 reg;
>  	u8 val;
> @@ -87,7 +97,7 @@ struct ov5645 {
>  	struct i2c_client *i2c_client;
>  	struct device *dev;
>  	struct v4l2_subdev sd;
> -	struct media_pad pad;
> +	struct media_pad pads[OV5645_NUM_PADS];
>  	struct v4l2_fwnode_endpoint ep;
>  	struct v4l2_rect crop;
>  	struct clk *xclk;
> @@ -826,7 +836,10 @@ static int ov5645_enum_mbus_code(struct v4l2_subdev *sd,
>  	if (code->index > 0)
>  		return -EINVAL;
>  
> -	code->code = MEDIA_BUS_FMT_UYVY8_1X16;
> +	if (code->pad == OV5645_PAD_IMAGE)
> +		code->code = OV5645_NATIVE_FORMAT;
> +	else
> +		code->code = MEDIA_BUS_FMT_UYVY8_1X16;
>  
>  	return 0;
>  }
> @@ -835,16 +848,24 @@ static int ov5645_enum_frame_size(struct v4l2_subdev *subdev,
>  				  struct v4l2_subdev_state *sd_state,
>  				  struct v4l2_subdev_frame_size_enum *fse)
>  {
> -	if (fse->code != MEDIA_BUS_FMT_UYVY8_1X16)
> -		return -EINVAL;
> -
> -	if (fse->index >= ARRAY_SIZE(ov5645_mode_info_data))
> -		return -EINVAL;
> -
> -	fse->min_width = ov5645_mode_info_data[fse->index].width;
> -	fse->max_width = ov5645_mode_info_data[fse->index].width;
> -	fse->min_height = ov5645_mode_info_data[fse->index].height;
> -	fse->max_height = ov5645_mode_info_data[fse->index].height;
> +	if (fse->pad == OV5645_PAD_IMAGE) {
> +		if (fse->code != OV5645_NATIVE_FORMAT || fse->index > 0)
> +			return -EINVAL;
> +
> +		fse->min_width = OV5645_NATIVE_WIDTH;
> +		fse->max_width = OV5645_NATIVE_WIDTH;
> +		fse->min_height = OV5645_NATIVE_HEIGHT;
> +		fse->max_height = OV5645_NATIVE_HEIGHT;
> +	} else {
> +		if (fse->code != MEDIA_BUS_FMT_UYVY8_1X16 ||

This will be interesting. With internal pads we will introduce the
concept of a "subdev model", which will formally document how the V4L2
subdev configuration items (formats, selection rectangles, ...) maps to
hardware features. Sakari is working on the definition of a subdev model
for raw sensors, that should catter for the needs of raw sensors without
a bayer scaler (the vast majority of them). To use internal pads with a
non-raw sensor, we'll have to define a model. It may be more
challenging/complicated to do so, as the YUV sensor features are less
standardized, but it will be an interesting development.

> +		    fse->index >= ARRAY_SIZE(ov5645_mode_info_data))
> +			return -EINVAL;
> +
> +		fse->min_width = ov5645_mode_info_data[fse->index].width;
> +		fse->max_width = ov5645_mode_info_data[fse->index].width;
> +		fse->min_height = ov5645_mode_info_data[fse->index].height;
> +		fse->max_height = ov5645_mode_info_data[fse->index].height;
> +	}
>  
>  	return 0;
>  }
> @@ -855,18 +876,55 @@ static int ov5645_set_format(struct v4l2_subdev *sd,
>  {
>  	struct ov5645 *ov5645 = to_ov5645(sd);
>  	struct v4l2_mbus_framefmt *__format;
> +	struct v4l2_rect *compose;
>  	struct v4l2_rect *__crop;

While at it, could you rename __crop to crop ?

>  	const struct ov5645_mode_info *new_mode;
>  	int ret;
>  
> -	__crop = v4l2_subdev_state_get_crop(sd_state, 0);
> +	if (format->pad != OV5645_PAD_SOURCE)
> +		return v4l2_subdev_get_fmt(sd, sd_state, format);
> +
>  	new_mode = v4l2_find_nearest_size(ov5645_mode_info_data,
>  					  ARRAY_SIZE(ov5645_mode_info_data),
>  					  width, height, format->format.width,
>  					  format->format.height);
> -
> -	__crop->width = new_mode->width;
> -	__crop->height = new_mode->height;
> +	format->format.code = MEDIA_BUS_FMT_UYVY8_1X16;
> +	format->format.width = new_mode->width;
> +	format->format.height = new_mode->height;
> +	format->format.field = V4L2_FIELD_NONE;
> +	format->format.colorspace = V4L2_COLORSPACE_SRGB;
> +	format->format.ycbcr_enc = V4L2_YCBCR_ENC_DEFAULT;
> +	format->format.quantization = V4L2_QUANTIZATION_DEFAULT;
> +	format->format.xfer_func = V4L2_XFER_FUNC_DEFAULT;

Drivers are not supposed to return DEFAULT values, you should pick
appropriate values.

> +
> +	__format = v4l2_subdev_state_get_format(sd_state, OV5645_PAD_IMAGE);

Maybe __format could also become fmt.

> +	*__format = format->format;
> +	__format->code = OV5645_NATIVE_FORMAT;
> +	__format->width = OV5645_NATIVE_WIDTH;
> +	__format->height = OV5645_NATIVE_HEIGHT;
> +
> +	__crop = v4l2_subdev_state_get_crop(sd_state, OV5645_PAD_IMAGE);
> +	__crop->width = format->format.width;
> +	__crop->height = format->format.height;
> +
> +	/*
> +	 * The compose rectangle models binning, its size is the sensor output
> +	 * size.
> +	 */
> +	compose = v4l2_subdev_state_get_compose(sd_state, OV5645_PAD_IMAGE);
> +	compose->left = 0;
> +	compose->top = 0;
> +	compose->width = format->format.width;
> +	compose->height = format->format.height;
> +
> +	__crop = v4l2_subdev_state_get_crop(sd_state, OV5645_PAD_SOURCE);
> +	__crop->left = 0;
> +	__crop->top = 0;
> +	__crop->width = format->format.width;
> +	__crop->height = format->format.height;
> +
> +	__format = v4l2_subdev_state_get_format(sd_state, OV5645_PAD_SOURCE);
> +	*__format = format->format;
>  
>  	if (format->which == V4L2_SUBDEV_FORMAT_ACTIVE) {
>  		ret = __v4l2_ctrl_s_ctrl_int64(ov5645->pixel_clock,
> @@ -882,14 +940,6 @@ static int ov5645_set_format(struct v4l2_subdev *sd,
>  		ov5645->current_mode = new_mode;
>  	}
>  
> -	__format = v4l2_subdev_state_get_format(sd_state, 0);
> -	__format->width = __crop->width;
> -	__format->height = __crop->height;
> -	__format->code = MEDIA_BUS_FMT_UYVY8_1X16;
> -	__format->field = V4L2_FIELD_NONE;
> -	__format->colorspace = V4L2_COLORSPACE_SRGB;
> -
> -	format->format = *__format;
>  
>  	return 0;
>  }
> @@ -899,7 +949,7 @@ static int ov5645_init_state(struct v4l2_subdev *subdev,
>  {
>  	struct v4l2_subdev_format fmt = {
>  		.which = V4L2_SUBDEV_FORMAT_TRY,
> -		.pad = 0,
> +		.pad = OV5645_PAD_SOURCE,
>  		.format = {
>  			.code = MEDIA_BUS_FMT_UYVY8_1X16,
>  			.width = ov5645_mode_info_data[1].width,
> @@ -919,7 +969,7 @@ static int ov5645_get_selection(struct v4l2_subdev *sd,
>  	if (sel->target != V4L2_SEL_TGT_CROP)
>  		return -EINVAL;
>  
> -	sel->r = *v4l2_subdev_state_get_crop(sd_state, 0);
> +	sel->r = *v4l2_subdev_state_get_crop(sd_state, sel->pad);

Now there's a compose rectangle, you should support getting it.

>  	return 0;
>  }
>  
> @@ -1123,11 +1173,12 @@ static int ov5645_probe(struct i2c_client *client)
>  	v4l2_i2c_subdev_init(&ov5645->sd, client, &ov5645_subdev_ops);
>  	ov5645->sd.internal_ops = &ov5645_internal_ops;
>  	ov5645->sd.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE | V4L2_SUBDEV_FL_HAS_EVENTS;
> -	ov5645->pad.flags = MEDIA_PAD_FL_SOURCE;
> +	ov5645->pads[OV5645_PAD_SOURCE].flags = MEDIA_PAD_FL_SOURCE;
> +	ov5645->pads[OV5645_PAD_IMAGE].flags = MEDIA_PAD_FL_SINK | MEDIA_PAD_FL_INTERNAL;
>  	ov5645->sd.dev = dev;
>  	ov5645->sd.entity.function = MEDIA_ENT_F_CAM_SENSOR;
>  
> -	ret = media_entity_pads_init(&ov5645->sd.entity, 1, &ov5645->pad);
> +	ret = media_entity_pads_init(&ov5645->sd.entity, ARRAY_SIZE(ov5645->pads), ov5645->pads);

Line wrap.

>  	if (ret < 0) {
>  		dev_err_probe(dev, ret, "could not register media entity\n");
>  		goto free_ctrl;

-- 
Regards,

Laurent Pinchart

  reply	other threads:[~2024-09-25 16:21 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-09-10 17:05 [PATCH v2 00/11] media: ov5645: Add support for streams Prabhakar
2024-09-10 17:06 ` [PATCH v2 01/11] media: i2c: ov5645: Add V4L2_SUBDEV_FL_HAS_EVENTS and subscribe hooks Prabhakar
2024-09-24 22:35   ` Laurent Pinchart
2024-09-10 17:06 ` [PATCH v2 02/11] media: i2c: ov5645: Use local `dev` pointer for subdev device assignment Prabhakar
2024-09-24 22:35   ` Laurent Pinchart
2024-09-10 17:06 ` [PATCH v2 03/11] media: i2c: ov5645: Enable runtime PM after v4l2_async_register_subdev() Prabhakar
2024-09-24 22:37   ` Laurent Pinchart
2024-09-25 15:22     ` Lad, Prabhakar
2024-09-10 17:06 ` [PATCH v2 04/11] media: i2c: ov5645: Use dev_err_probe instead of dev_err Prabhakar
2024-09-24 22:43   ` Laurent Pinchart
2024-09-25 15:24     ` Lad, Prabhakar
2024-09-10 17:06 ` [PATCH v2 05/11] media: i2c: ov5645: Use v4l2_async_register_subdev_sensor() Prabhakar
2024-09-24 22:44   ` Laurent Pinchart
2024-09-25 15:26     ` Lad, Prabhakar
2024-09-10 17:06 ` [PATCH v2 06/11] media: i2c: ov5645: Drop `power_lock` mutex Prabhakar
2024-09-24 22:46   ` Laurent Pinchart
2024-09-25 15:35     ` Lad, Prabhakar
2024-09-10 17:06 ` [PATCH v2 07/11] media: i2c: ov5645: Use subdev active state Prabhakar
2024-09-24 22:51   ` Laurent Pinchart
2024-09-10 17:06 ` [PATCH v2 08/11] media: i2c: ov5645: Switch to {enable,disable}_streams Prabhakar
2024-09-24 22:55   ` Laurent Pinchart
2024-09-10 17:06 ` [PATCH v2 09/11] media: i2c: ov5645: Add internal image sink pad Prabhakar
2024-09-25 16:21   ` Laurent Pinchart [this message]
2024-09-26 15:49     ` Sakari Ailus
2024-09-27 15:35       ` Lad, Prabhakar
2024-09-10 17:06 ` [PATCH v2 10/11] media: i2c: ov5645: Report internal routes to userspace Prabhakar
2024-09-10 17:06 ` [PATCH v2 11/11] media: i2c: ov5645: Report streams using frame descriptors Prabhakar
2024-09-25 16:26   ` Laurent Pinchart
2024-09-26 10:16     ` Lad, Prabhakar
2024-09-26 15:45   ` Sakari Ailus
2024-09-26 17:48     ` Laurent Pinchart
2024-09-26 18:57       ` Sakari Ailus
2024-09-27 15:31         ` Lad, Prabhakar
2024-09-27 16:01           ` Sakari Ailus

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=20240925162153.GA27666@pendragon.ideasonboard.com \
    --to=laurent.pinchart@ideasonboard.com \
    --cc=biju.das.jz@bp.renesas.com \
    --cc=fabrizio.castro.jz@renesas.com \
    --cc=hverkuil-cisco@xs4all.nl \
    --cc=jacopo.mondi@ideasonboard.com \
    --cc=kieran.bingham@ideasonboard.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=linux-renesas-soc@vger.kernel.org \
    --cc=mchehab@kernel.org \
    --cc=prabhakar.csengg@gmail.com \
    --cc=prabhakar.mahadev-lad.rj@bp.renesas.com \
    --cc=sakari.ailus@linux.intel.com \
    --cc=tomi.valkeinen@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