b0db5a656c682dd272bfd9a74d3952a2fa3aebc4
[openwrt/staging/pepe2k.git] /
1 From 1ca6523a7173ac73f612c4633fc6308c6b5aade9 Mon Sep 17 00:00:00 2001
2 From: Dave Stevenson <dave.stevenson@raspberrypi.com>
3 Date: Thu, 14 Sep 2023 12:23:05 +0100
4 Subject: [PATCH 0499/1085] media: i2c: imx219: make HBLANK r/w to allow longer
5 exposures
6
7 The HBLANK control was read-only, and always configured such
8 that the sensor HTS register was 3448. This limited the maximum
9 exposure time that could be achieved to around 1.26 secs.
10
11 Make HBLANK read/write so that the line time can be extended,
12 and thereby allow longer exposures (and slower frame rates).
13 Retain the overall HTS setting when changing modes rather than
14 resetting it to a default.
15
16 Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
17 ---
18 drivers/media/i2c/imx219.c | 36 ++++++++++++++++++++++++------------
19 1 file changed, 24 insertions(+), 12 deletions(-)
20
21 --- a/drivers/media/i2c/imx219.c
22 +++ b/drivers/media/i2c/imx219.c
23 @@ -85,8 +85,10 @@
24 #define IMX219_FLL_STEP 1
25 #define IMX219_FLL_DEFAULT 0x0c98
26
27 -/* HBLANK control - read only */
28 -#define IMX219_PPL_DEFAULT 3448
29 +/* HBLANK control range */
30 +#define IMX219_PPL_MIN 3448
31 +#define IMX219_PPL_MAX 0x7ff0
32 +#define IMX219_REG_HTS 0x0162
33
34 #define IMX219_REG_LINE_LENGTH_A CCI_REG16(0x0162)
35 #define IMX219_REG_X_ADD_STA_A CCI_REG16(0x0164)
36 @@ -548,6 +550,10 @@ static int imx219_set_ctrl(struct v4l2_c
37 cci_write(imx219->regmap, IMX219_REG_VTS,
38 imx219->mode->height + ctrl->val, &ret);
39 break;
40 + case V4L2_CID_HBLANK:
41 + cci_write(imx219->regmap, IMX219_REG_HTS,
42 + imx219->mode->width + ctrl->val, &ret);
43 + break;
44 case V4L2_CID_TEST_PATTERN_RED:
45 cci_write(imx219->regmap, IMX219_REG_TESTP_RED,
46 ctrl->val, &ret);
47 @@ -677,6 +683,8 @@ static int imx219_set_pad_format(struct
48 *crop = mode->crop;
49
50 if (fmt->which == V4L2_SUBDEV_FORMAT_ACTIVE) {
51 + u32 prev_hts = imx219->mode->width + imx219->hblank->val;
52 +
53 imx219->mode = mode;
54 /* Update limits and set FPS to default */
55 __v4l2_ctrl_modify_range(imx219->vblank, IMX219_VBLANK_MIN,
56 @@ -693,13 +701,18 @@ static int imx219_set_pad_format(struct
57 exposure_max, imx219->exposure->step,
58 exposure_def);
59 /*
60 - * Currently PPL is fixed to IMX219_PPL_DEFAULT, so hblank
61 - * depends on mode->width only, and is not changeble in any
62 - * way other than changing the mode.
63 + * Retain PPL setting from previous mode so that the
64 + * line time does not change on a mode change.
65 + * Limits have to be recomputed as the controls define
66 + * the blanking only, so PPL values need to have the
67 + * mode width subtracted.
68 */
69 - hblank = IMX219_PPL_DEFAULT - mode->width;
70 - __v4l2_ctrl_modify_range(imx219->hblank, hblank, hblank, 1,
71 - hblank);
72 + hblank = prev_hts - mode->width;
73 + __v4l2_ctrl_modify_range(imx219->hblank,
74 + IMX219_PPL_MIN - mode->width,
75 + IMX219_PPL_MAX - mode->width,
76 + 1, IMX219_PPL_MIN - mode->width);
77 + __v4l2_ctrl_s_ctrl(imx219->hblank, hblank);
78 }
79
80 return 0;
81 @@ -1094,12 +1107,11 @@ static int imx219_init_controls(struct i
82 V4L2_CID_VBLANK, IMX219_VBLANK_MIN,
83 IMX219_VTS_MAX - height, 1,
84 imx219->mode->vts_def - height);
85 - hblank = IMX219_PPL_DEFAULT - imx219->mode->width;
86 + hblank = IMX219_PPL_MIN - imx219->mode->width;
87 imx219->hblank = v4l2_ctrl_new_std(ctrl_hdlr, &imx219_ctrl_ops,
88 - V4L2_CID_HBLANK, hblank, hblank,
89 + V4L2_CID_HBLANK, hblank,
90 + IMX219_PPL_MIN - imx219->mode->width,
91 1, hblank);
92 - if (imx219->hblank)
93 - imx219->hblank->flags |= V4L2_CTRL_FLAG_READ_ONLY;
94 exposure_max = imx219->mode->vts_def - 4;
95 exposure_def = (exposure_max < IMX219_EXPOSURE_DEFAULT) ?
96 exposure_max : IMX219_EXPOSURE_DEFAULT;