Skip to contentSkip to conversation

media: i2c: mira016: Fix analogue gain range for the default format

PATCH In review David Carlier 2 participants 2 messages Nov 21 – Nov 22 Media (V4L/DVB)

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 media: i2c: mira016: Fix analogue gain range for the default format

The analogue gain control is created with a 1..1 range, and the range is only updated when an active format is set. The default 8-bit format is applied by init_state as a TRY format, so the gain cannot be changed until userspace sets the active format.

Create the control with the 8-bit gain range to match the default format.

The issue was found by code inspection with an LLM, build tested only.

Fixes ab4a4c39c611 ("media: i2c: mira016: Add driver for Mira016")
---
 drivers/media/i2c/mira016.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/media/i2c/mira016.c +4 -2
index 082442ffad28..076e8a22be82 100644
@@ -1917,9 +1917,11 @@ static int mira016_init_controls(struct mira016 *mira016)
 					      MIRA016_MAX_EXPOSURE, 1,
 					      def_exposure);
 
+	/* The gain range matches the default 8-bit format set in init_state. */
 	mira016->gain = v4l2_ctrl_new_std(ctrl_hdlr, &mira016_ctrl_ops,
-					  V4L2_CID_ANALOGUE_GAIN,
-					  1, 1, 1, 1);
+					  V4L2_CID_ANALOGUE_GAIN, 1,
+					  ARRAY_SIZE(mira016_gain_lut_8bit),
+					  1, 1);
 
 	/*
 	 * Changing VFLIP requires re-programming the top point, hence we
Signature · 1 line
2.55.0
#1 lore raw

Hi David

Quoted 6 lines · David Carlier

The analogue gain control is created with a 1..1 range, and the range is only updated when an active format is set. The default 8-bit format is applied by init_state as a TRY format, so the gain cannot be changed until userspace sets the active format.

Create the control with the 8-bit gain range to match the default format.

I'm surprised I used the 8-bits format as default. I thought it was 12 and clearly overlooked it.

Honestly, I would use the 12 bits format as a default as higher bitdepths are maybe preferable ?

Quoted 4 lines

The issue was found by code inspection with an LLM, build tested only.

Fixes ab4a4c39c611 ("media: i2c: mira016: Add driver for Mira016")

Do we need one ? The driver didn't land in any published kernel yet.

Quoted 26 lines
---
 drivers/media/i2c/mira016.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/media/i2c/mira016.c +4 -3
index 082442ffad28..076e8a22be82 100644
@@ -1917,9 +1917,11 @@ static int mira016_init_controls(struct mira016 *mira016)
 					      MIRA016_MAX_EXPOSURE, 1,
 					      def_exposure);
 
+	/* The gain range matches the default 8-bit format set in init_state. */
 	mira016->gain = v4l2_ctrl_new_std(ctrl_hdlr, &mira016_ctrl_ops,
-					  V4L2_CID_ANALOGUE_GAIN,
-					  1, 1, 1, 1);
+					  V4L2_CID_ANALOGUE_GAIN, 1,
+					  ARRAY_SIZE(mira016_gain_lut_8bit),
+					  1, 1);
 
 	/*
 	 * Changing VFLIP requires re-programming the top point, hence we
--

2.55.0