1 From f6523a46d1ad95d1f269a691ddb7998c86b9264f Mon Sep 17 00:00:00 2001
2 From: Dave Stevenson <dave.stevenson@raspberrypi.com>
3 Date: Wed, 16 Jun 2021 17:19:17 +0100
4 Subject: [PATCH] media: i2c: imx258: Follow normal V4L2 behaviours for
7 V4L2 sensor drivers are expected are expected to clip the supported
8 exposure range based on the VBLANK configured.
9 IMX258 wasn't doing that as register 0x350 (FRM_LENGTH_CTL)
10 switches it to a mode where frame length tracks coarse exposure time.
12 Disable this mode and clip the range for V4L2_CID_EXPOSURE appropriately
13 based on V4L2_CID_VBLANK.
15 Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
17 drivers/media/i2c/imx258.c | 35 ++++++++++++++++++++++++++++-------
18 1 file changed, 28 insertions(+), 7 deletions(-)
20 --- a/drivers/media/i2c/imx258.c
21 +++ b/drivers/media/i2c/imx258.c
24 #define IMX258_REG_VTS 0x0340
26 -/* HBLANK control - read only */
27 -#define IMX258_PPL_DEFAULT 5352
29 /* Exposure control */
30 #define IMX258_REG_EXPOSURE 0x0202
31 +#define IMX258_EXPOSURE_OFFSET 10
32 #define IMX258_EXPOSURE_MIN 4
33 #define IMX258_EXPOSURE_STEP 1
34 #define IMX258_EXPOSURE_DEFAULT 0x640
35 -#define IMX258_EXPOSURE_MAX 65535
36 +#define IMX258_EXPOSURE_MAX (IMX258_VTS_MAX - IMX258_EXPOSURE_OFFSET)
38 +/* HBLANK control - read only */
39 +#define IMX258_PPL_DEFAULT 5352
41 /* Analog gain control */
42 #define IMX258_REG_ANALOG_GAIN 0x0204
43 @@ -377,7 +378,7 @@ static const struct imx258_reg mode_4208
52 @@ -489,7 +490,7 @@ static const struct imx258_reg mode_2104
61 @@ -601,7 +602,7 @@ static const struct imx258_reg mode_1048
70 @@ -966,6 +967,19 @@ static int imx258_update_digital_gain(st
74 +static void imx258_adjust_exposure_range(struct imx258 *imx258)
76 + int exposure_max, exposure_def;
78 + /* Honour the VBLANK limits when setting exposure. */
79 + exposure_max = imx258->cur_mode->height + imx258->vblank->val -
80 + IMX258_EXPOSURE_OFFSET;
81 + exposure_def = min(exposure_max, imx258->exposure->val);
82 + __v4l2_ctrl_modify_range(imx258->exposure, imx258->exposure->minimum,
83 + exposure_max, imx258->exposure->step,
87 static int imx258_set_ctrl(struct v4l2_ctrl *ctrl)
89 struct imx258 *imx258 =
90 @@ -974,6 +988,13 @@ static int imx258_set_ctrl(struct v4l2_c
94 + * The VBLANK control may change the limits of usable exposure, so check
95 + * and adjust if necessary.
97 + if (ctrl->id == V4L2_CID_VBLANK)
98 + imx258_adjust_exposure_range(imx258);
101 * Applying V4L2 control value only happens
102 * when power is up for streaming