Linux Media Controller development
 help / color / mirror / Atom feed
From: Mehdi Djait <mehdi.djait@linux.intel.com>
To: Tarang Raval <tarang.raval@siliconsignals.io>
Cc: Sakari Ailus <sakari.ailus@linux.intel.com>,
	 Himanshu Bhavani <himanshu.bhavani@siliconsignals.io>,
	Elgin Perumbilly <elgin.perumbilly@siliconsignals.io>,
	 Mauro Carvalho Chehab <mchehab@kernel.org>,
	Vladimir Zapolskiy <vladimir.zapolskiy@linaro.org>,
	 Hans Verkuil <hverkuil+cisco@kernel.org>,
	linux-media@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 08/15] media: i2c: os05b10: add 12-bit RAW mode support
Date: Thu, 2 Jul 2026 17:00:55 +0200	[thread overview]
Message-ID: <akZ7Gl2w0dg0b9ZR@mdjait-mobl> (raw)
In-Reply-To: <20260325114404.95188-9-tarang.raval@siliconsignals.io>

Hi Tarang,

On Wed, Mar 25, 2026 at 05:13:54PM +0530, Tarang Raval wrote:

[..]

> -static u32 os05b10_get_format_code(struct os05b10 *os05b10)
> +static u32 os05b10_get_format_code(struct os05b10 *os05b10, u8 bpp)
>  {
> -	static const u32 codes[2][2] = {
> +	static const u32 codes_12[2][2] = {
> +		{ MEDIA_BUS_FMT_SBGGR12_1X12, MEDIA_BUS_FMT_SGBRG12_1X12, },
> +		{ MEDIA_BUS_FMT_SGRBG12_1X12, MEDIA_BUS_FMT_SRGGB12_1X12, },
> +	};
> +
> +	static const u32 codes_10[2][2] = {
>  		{ MEDIA_BUS_FMT_SBGGR10_1X10, MEDIA_BUS_FMT_SGBRG10_1X10, },
>  		{ MEDIA_BUS_FMT_SGRBG10_1X10, MEDIA_BUS_FMT_SRGGB10_1X10, },
>  	};
>  
> +	const u32 (*codes)[2] = (bpp == 12) ? codes_12 : codes_10;
> +

I don't know about the code above..

How about one array:

        static const u32 codes[2][2][2] = {
                {
                        { MEDIA_BUS_FMT_SBGGR10_1X10, MEDIA_BUS_FMT_SGBRG10_1X10, },
                        { MEDIA_BUS_FMT_SGRBG10_1X10, MEDIA_BUS_FMT_SRGGB10_1X10, },
                }, {
                        { MEDIA_BUS_FMT_SBGGR12_1X12, MEDIA_BUS_FMT_SGBRG12_1X12, },
                        { MEDIA_BUS_FMT_SGRBG12_1X12, MEDIA_BUS_FMT_SRGGB12_1X12, },
                },
        };

And the first index will be dependent on the bpp == 12 or not.

or
        static const u32 codes[4][2];

and have an offset of 2. I think the first is cleaner.

>  	u32 code = codes[os05b10->vflip->val][os05b10->hflip->val];
>  
>  	return code;
> @@ -654,8 +676,8 @@ static int os05b10_enum_mbus_code(struct v4l2_subdev *sd,
>  	if (code->index >= ARRAY_SIZE(os05b10_mbus_codes))
>  		return -EINVAL;
>  
> -	code->code = os05b10_get_format_code(os05b10);
> -
> +	code->code = os05b10_get_format_code(os05b10,
> +					     (code->index == 1) ? 12 : 10);
>  	return 0;
>  }
>  
> @@ -684,15 +706,42 @@ static int os05b10_set_framing_limits(struct os05b10 *os05b10,
>  					OS05B10_EXPOSURE_STEP, mode->exp);
>  }
>  
> +static inline void get_mode_table(unsigned int code,
> +				  const struct os05b10_mode **mode_list,
> +				  unsigned int *num_modes)
> +{
> +	switch (code) {
> +	case MEDIA_BUS_FMT_SBGGR12_1X12:
> +		*mode_list = supported_modes_12bit;
> +		*num_modes = ARRAY_SIZE(supported_modes_12bit);
> +		break;
> +
> +	case MEDIA_BUS_FMT_SBGGR10_1X10:
> +		*mode_list = supported_modes_10bit;
> +		*num_modes = ARRAY_SIZE(supported_modes_10bit);
> +		break;
> +	default:
> +		*mode_list = NULL;
> +		*num_modes = 0;
> +		break;
> +	}
> +}
> +
>  static int os05b10_set_pad_format(struct v4l2_subdev *sd,
>  				  struct v4l2_subdev_state *sd_state,
>  				  struct v4l2_subdev_format *fmt)
>  {
> -	const struct os05b10_mode *mode = &supported_modes_10bit[0];
>  	struct os05b10 *os05b10 = to_os05b10(sd);
> +	const struct os05b10_mode *mode_list;
>  	struct v4l2_mbus_framefmt *format;
> +	const struct os05b10_mode *mode;
> +	unsigned int num_modes;
>  	int ret;
>  
> +	get_mode_table(fmt->format.code, &mode_list, &num_modes);
> +	mode = v4l2_find_nearest_size(mode_list, num_modes, width, height,
> +				      fmt->format.width, fmt->format.height);
> +

What would happen here if get_mode_table returns NULL and 0 for
mode_list and num_modes ?

>  	fmt->format.width = mode->width;

Will this cause a kernel panic ?

>  	fmt->format.height = mode->height;
>  	fmt->format.field = V4L2_FIELD_NONE;
> @@ -735,12 +784,17 @@ static int os05b10_enum_frame_size(struct v4l2_subdev *sd,
>  				   struct v4l2_subdev_state *sd_state,
>  				   struct v4l2_subdev_frame_size_enum *fse)
> +	const struct os05b10_mode *mode_list;
> +	unsigned int num_modes;
> +
> +	get_mode_table(fse->code, &mode_list, &num_modes);
> +
> +	if (fse->index >= num_modes)
>  		return -EINVAL;
>  
> -	fse->min_width = supported_modes_10bit[fse->index].width;
> +	fse->min_width = mode_list[fse->index].width;
>  	fse->max_width = fse->min_width;
> -	fse->min_height = supported_modes_10bit[fse->index].height;
> +	fse->min_height = mode_list[fse->index].height;
>  	fse->max_height = fse->min_height;
>  
>  	return 0;

--
Kind Regards
Mehdi Djait

  reply	other threads:[~2026-07-02 15:01 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-25 11:43 [PATCH v2 00/15] media: i2c: os05b10: Refactor driver and Add new features Tarang Raval
2026-03-25 11:43 ` [PATCH v2 01/15] media: i2c: os05b10: Use pm_runtime_get_if_active() when applying controls Tarang Raval
2026-06-29 15:22   ` Mehdi Djait
2026-06-30  7:17     ` Tarang Raval
2026-03-25 11:43 ` [PATCH v2 02/15] media: i2c: os05b10: drop unused group-hold programming Tarang Raval
2026-06-29 15:22   ` Mehdi Djait
2026-03-25 11:43 ` [PATCH v2 03/15] media: i2c: os05b10: add register definitions and use them in init table Tarang Raval
2026-06-29 15:45   ` Mehdi Djait
2026-06-30  7:24     ` Tarang Raval
2026-03-25 11:43 ` [PATCH v2 04/15] media: i2c: os05b10: split common and mode-specific init registers Tarang Raval
2026-06-30 15:17   ` Mehdi Djait
2026-07-01  6:35     ` Tarang Raval
2026-06-30 15:24   ` Mehdi Djait
2026-06-30 15:25     ` Mehdi Djait
2026-03-25 11:43 ` [PATCH v2 05/15] media: i2c: os05b10: add V4L2 digital gain control Tarang Raval
2026-06-30 15:27   ` Mehdi Djait
2026-03-25 11:43 ` [PATCH v2 06/15] media: i2c: os05b10: Add H/V flip support Tarang Raval
2026-07-02  8:06   ` Mehdi Djait
2026-03-25 11:43 ` [PATCH v2 07/15] media: i2c: os05b10: Add test pattern options Tarang Raval
2026-07-02  8:29   ` Mehdi Djait
2026-07-02 10:45     ` Tarang Raval
2026-03-25 11:43 ` [PATCH v2 08/15] media: i2c: os05b10: add 12-bit RAW mode support Tarang Raval
2026-07-02 15:00   ` Mehdi Djait [this message]
2026-03-25 11:43 ` [PATCH v2 09/15] media: i2c: os05b10: update pixel rate on 10/12-bit mode switch Tarang Raval
2026-03-25 11:43 ` [PATCH v2 10/15] media: i2c: os05b10: Add 1080p and 2x2 binning 720p modes Tarang Raval
2026-03-25 11:43 ` [PATCH v2 11/15] media: i2c: os05b10: keep vblank and exposure range in sync on mode switch Tarang Raval
2026-03-25 11:43 ` [PATCH v2 12/15] media: i2c: os05b10: Update active format before adjusting framing controls Tarang Raval
2026-03-25 11:43 ` [PATCH v2 13/15] media: i2c: os05b10: Rename vmax variable in VBLANK control Tarang Raval
2026-03-25 11:44 ` [PATCH v2 14/15] media: i2c: os05b10: add 2-lane support Tarang Raval
2026-03-25 11:44 ` [PATCH v2 15/15] media: i2c: os05b10: fix negative hblank calculation Tarang Raval
2026-04-27  9:24 ` [PATCH v2 00/15] media: i2c: os05b10: Refactor driver and Add new features Tarang Raval
2026-05-26  7:09   ` Tarang Raval
2026-05-26  8:36     ` Mehdi Djait
2026-05-26  9:22       ` Tarang Raval

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=akZ7Gl2w0dg0b9ZR@mdjait-mobl \
    --to=mehdi.djait@linux.intel.com \
    --cc=elgin.perumbilly@siliconsignals.io \
    --cc=himanshu.bhavani@siliconsignals.io \
    --cc=hverkuil+cisco@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=mchehab@kernel.org \
    --cc=sakari.ailus@linux.intel.com \
    --cc=tarang.raval@siliconsignals.io \
    --cc=vladimir.zapolskiy@linaro.org \
    /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