mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Minseo Park <hiyoukou@gmail.com>
To: sakari.ailus@linux.intel.com, kieran.bingham@ideasonboard.com,
	mchehab@kernel.org, hverkuil@kernel.org, uajain@igalia.com
Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org,
	Minseo Park <hiyoukou@gmail.com>
Subject: [PATCH] media: imx335: do not change the sensor state from the TRY path
Date: Wed, 25 Nov 2026 19:05:36 +0900	[thread overview]
Message-ID: <20261125100536.3746-1-hiyoukou@gmail.com> (raw)

imx335_set_pad_format() stores the requested media bus code into
imx335->cur_mbus_code before it looks at fmt->which, so a
VIDIOC_SUBDEV_S_FMT with which == V4L2_SUBDEV_FORMAT_TRY changes it as
well.

That used to be observable, because the driver's own .get_fmt returned
cur_mbus_code too.  Since commit df3ef05b51e0 ("media: imx355: Use
subdev active state"), which changes imx335 despite what its subject
says, .get_fmt is v4l2_subdev_get_fmt() and reports the subdev state.
A TRY call now leaves the active format alone while still changing the
code the sensor is programmed with: imx335_set_framefmt() derives the
output bit width from cur_mbus_code and writes it to IMX335_REG_MDBIT
when streaming starts.

A TRY request on any handle therefore makes the sensor emit 12-bit data
for an active format that still reads as 10-bit, or the other way
round, while the receiver and the buffers behind it were set up from
that active format.

Drop the device wide copy and take the code from the subdev state, which
.enable_streams() is already given.  imx335_fill_pad_format() and
imx335_set_framefmt() now receive the code to use, so the TRY path only
writes to the state of the handle it was called on.

An unsupported code now falls back to the code in the state being
configured rather than to the device wide one, which for a TRY call is
the format of that handle.

cur_mode is not affected, it is already only assigned when
fmt->which is V4L2_SUBDEV_FORMAT_ACTIVE.

Fixes: cfa49ff0558a ("media: i2c: imx335: Support 2592x1940 10-bit mode")
Signed-off-by: Minseo Park <hiyoukou@gmail.com>
---
 drivers/media/i2c/imx335.c | 31 +++++++++++++++++--------------
 1 file changed, 17 insertions(+), 14 deletions(-)

diff --git a/drivers/media/i2c/imx335.c b/drivers/media/i2c/imx335.c
index 5790aa4fabeb..48f42a4adf80 100644
--- a/drivers/media/i2c/imx335.c
+++ b/drivers/media/i2c/imx335.c
@@ -215,7 +215,6 @@ struct imx335_mode {
  * @lane_mode: Mode for number of connected data lanes
  * @cur_mode: Pointer to current selected sensor mode
  * @link_freq_bitmap: Menu bitmap for link_freq_ctrl
- * @cur_mbus_code: Currently selected media bus format code
  */
 struct imx335 {
 	struct device *dev;
@@ -241,7 +240,6 @@ struct imx335 {
 	u32 lane_mode;
 	const struct imx335_mode *cur_mode;
 	unsigned long link_freq_bitmap;
-	u32 cur_mbus_code;
 };
 
 static const char * const imx335_tpg_menu[] = {
@@ -853,17 +851,16 @@ static int imx335_enum_frame_size(struct v4l2_subdev *sd,
 /**
  * imx335_fill_pad_format() - Fill subdevice pad format
  *                            from selected sensor mode
- * @imx335: pointer to imx335 device
  * @mode: pointer to imx335_mode sensor mode
+ * @code: media bus format code to report
  * @fmt: V4L2 sub-device format need to be filled
  */
-static void imx335_fill_pad_format(struct imx335 *imx335,
-				   const struct imx335_mode *mode,
+static void imx335_fill_pad_format(const struct imx335_mode *mode, u32 code,
 				   struct v4l2_subdev_format *fmt)
 {
 	fmt->format.width = mode->width;
 	fmt->format.height = mode->height;
-	fmt->format.code = imx335->cur_mbus_code;
+	fmt->format.code = code;
 	fmt->format.field = V4L2_FIELD_NONE;
 	fmt->format.colorspace = V4L2_COLORSPACE_RAW;
 	fmt->format.ycbcr_enc = V4L2_YCBCR_ENC_DEFAULT;
@@ -888,20 +885,24 @@ static int imx335_set_pad_format(struct v4l2_subdev *sd,
 	const struct imx335_mode *mode;
 	struct v4l2_rect *crop;
 	int i, ret = 0;
+	u32 code;
 
 	mode = v4l2_find_nearest_size(supported_modes,
 				      ARRAY_SIZE(supported_modes),
 				      width, height,
 				      fmt->format.width, fmt->format.height);
 
+	format = v4l2_subdev_state_get_format(sd_state, fmt->pad);
+
+	/* Keep the current code if the requested one is not supported. */
+	code = format->code;
 	for (i = 0; i < ARRAY_SIZE(imx335_mbus_codes); i++) {
 		if (imx335_mbus_codes[i] == fmt->format.code)
-			imx335->cur_mbus_code = imx335_mbus_codes[i];
+			code = imx335_mbus_codes[i];
 	}
 
-	imx335_fill_pad_format(imx335, mode, fmt);
+	imx335_fill_pad_format(mode, code, fmt);
 
-	format = v4l2_subdev_state_get_format(sd_state, fmt->pad);
 	*format = fmt->format;
 
 	crop = v4l2_subdev_state_get_crop(sd_state, fmt->pad);
@@ -937,7 +938,8 @@ static int imx335_init_state(struct v4l2_subdev *sd,
 	struct v4l2_subdev_format fmt = { 0 };
 
 	fmt.which = sd_state ? V4L2_SUBDEV_FORMAT_TRY : V4L2_SUBDEV_FORMAT_ACTIVE;
-	imx335_fill_pad_format(imx335, &supported_modes[0], &fmt);
+	imx335_fill_pad_format(&supported_modes[0], imx335_mbus_codes[0],
+			       &fmt);
 
 	__v4l2_ctrl_modify_range(imx335->link_freq_ctrl, 0,
 				 __fls(imx335->link_freq_bitmap),
@@ -978,7 +980,7 @@ static int imx335_get_selection(struct v4l2_subdev *sd,
 	return -EINVAL;
 }
 
-static int imx335_set_framefmt(struct imx335 *imx335)
+static int imx335_set_framefmt(struct imx335 *imx335, u32 code)
 {
 	/*
 	 * In the all-pixel scan mode the AD conversion shall match the output
@@ -989,7 +991,7 @@ static int imx335_set_framefmt(struct imx335 *imx335)
 	 * That's as much as the documentation gives us...
 	 */
 	int ret = 0;
-	u8 bpp = imx335->cur_mbus_code == MEDIA_BUS_FMT_SRGGB10_1X10 ? 10 : 12;
+	u8 bpp = code == MEDIA_BUS_FMT_SRGGB10_1X10 ? 10 : 12;
 	u8 ad_conv = bpp;
 
 	/* Start with the output mode */
@@ -1025,6 +1027,7 @@ static int imx335_enable_streams(struct v4l2_subdev *sd,
 				 u64 streams_mask)
 {
 	struct imx335 *imx335 = to_imx335(sd);
+	const struct v4l2_mbus_framefmt *fmt;
 	const struct imx335_reg_list *reg_list;
 	int ret;
 
@@ -1058,7 +1061,8 @@ static int imx335_enable_streams(struct v4l2_subdev *sd,
 		goto err_rpm_put;
 	}
 
-	ret = imx335_set_framefmt(imx335);
+	fmt = v4l2_subdev_state_get_format(state, pad);
+	ret = imx335_set_framefmt(imx335, fmt->code);
 	if (ret) {
 		dev_err(imx335->dev, "%s failed to set frame format: %d\n",
 			__func__, ret);
@@ -1477,7 +1481,6 @@ static int imx335_probe(struct i2c_client *client)
 
 	/* Set default mode to max resolution */
 	imx335->cur_mode = &supported_modes[0];
-	imx335->cur_mbus_code = imx335_mbus_codes[0];
 	imx335->vblank = imx335->cur_mode->vblank;
 
 	ret = imx335_init_controls(imx335);
-- 
2.43.0


                 reply	other threads:[~2026-11-25 10:05 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20261125100536.3746-1-hiyoukou@gmail.com \
    --to=hiyoukou@gmail.com \
    --cc=hverkuil@kernel.org \
    --cc=kieran.bingham@ideasonboard.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=mchehab@kernel.org \
    --cc=sakari.ailus@linux.intel.com \
    --cc=uajain@igalia.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

all inboxes | Powered by JetHome®