1 From 98105970373a9e79dcaa4291f2802b1dd9fe909e Mon Sep 17 00:00:00 2001
2 From: Dave Stevenson <dave.stevenson@raspberrypi.com>
3 Date: Thu, 16 Feb 2023 00:29:57 +0200
4 Subject: [PATCH] media: i2c: imx290: Convert V4L2_CID_HBLANK to
7 Should be upstream commit 8cab2bd86307
9 The driver exposed V4L2_CID_HBLANK as a read only control to allow
10 for exposure calculations and determination of the frame rate.
12 Convert to a read/write control so that the frame rate can be
15 Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
16 Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
17 Reviewed-by: Alexander Stein <alexander.stein@ew.tq-group.com>
18 Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
19 Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
21 drivers/media/i2c/imx290.c | 33 +++++++++++++++++++--------------
22 1 file changed, 19 insertions(+), 14 deletions(-)
24 --- a/drivers/media/i2c/imx290.c
25 +++ b/drivers/media/i2c/imx290.c
27 #define IMX290_GAIN IMX290_REG_8BIT(0x3014)
28 #define IMX290_VMAX IMX290_REG_24BIT(0x3018)
29 #define IMX290_HMAX IMX290_REG_16BIT(0x301c)
30 +#define IMX290_HMAX_MAX 0xffff
31 #define IMX290_SHS1 IMX290_REG_24BIT(0x3020)
32 #define IMX290_WINWV_OB IMX290_REG_8BIT(0x303a)
33 #define IMX290_WINPV IMX290_REG_16BIT(0x303c)
34 @@ -186,7 +187,7 @@ struct imx290_regval {
42 const struct imx290_regval *data;
43 @@ -429,7 +430,7 @@ static const struct imx290_mode imx290_m
49 .link_freq_index = FREQ_INDEX_1080P,
50 .data = imx290_1080p_settings,
51 .data_size = ARRAY_SIZE(imx290_1080p_settings),
52 @@ -437,7 +438,7 @@ static const struct imx290_mode imx290_m
58 .link_freq_index = FREQ_INDEX_720P,
59 .data = imx290_720p_settings,
60 .data_size = ARRAY_SIZE(imx290_720p_settings),
61 @@ -448,7 +449,7 @@ static const struct imx290_mode imx290_m
67 .link_freq_index = FREQ_INDEX_1080P,
68 .data = imx290_1080p_settings,
69 .data_size = ARRAY_SIZE(imx290_1080p_settings),
70 @@ -456,7 +457,7 @@ static const struct imx290_mode imx290_m
76 .link_freq_index = FREQ_INDEX_720P,
77 .data = imx290_720p_settings,
78 .data_size = ARRAY_SIZE(imx290_720p_settings),
79 @@ -712,6 +713,12 @@ static int imx290_set_ctrl(struct v4l2_c
83 + case V4L2_CID_HBLANK:
84 + ret = imx290_write(imx290, IMX290_HMAX,
85 + ctrl->val + imx290->current_mode->width,
92 @@ -742,12 +749,14 @@ static void imx290_ctrl_update(struct im
93 const struct v4l2_mbus_framefmt *format,
94 const struct imx290_mode *mode)
96 - unsigned int hblank = mode->hmax - mode->width;
97 + unsigned int hblank_min = mode->hmax_min - mode->width;
98 + unsigned int hblank_max = IMX290_HMAX_MAX - mode->width;
99 unsigned int vblank = IMX290_VMAX_DEFAULT - mode->height;
101 __v4l2_ctrl_s_ctrl(imx290->link_freq, mode->link_freq_index);
103 - __v4l2_ctrl_modify_range(imx290->hblank, hblank, hblank, 1, hblank);
104 + __v4l2_ctrl_modify_range(imx290->hblank, hblank_min, hblank_max, 1,
106 __v4l2_ctrl_modify_range(imx290->vblank, vblank, vblank, 1, vblank);
109 @@ -804,10 +813,11 @@ static int imx290_ctrl_init(struct imx29
110 ARRAY_SIZE(imx290_test_pattern_menu) - 1,
111 0, 0, imx290_test_pattern_menu);
114 + * Actual range will be set from imx290_ctrl_update later in the probe.
116 imx290->hblank = v4l2_ctrl_new_std(&imx290->ctrls, &imx290_ctrl_ops,
117 V4L2_CID_HBLANK, 1, 1, 1, 1);
118 - if (imx290->hblank)
119 - imx290->hblank->flags |= V4L2_CTRL_FLAG_READ_ONLY;
121 imx290->vblank = v4l2_ctrl_new_std(&imx290->ctrls, &imx290_ctrl_ops,
122 V4L2_CID_VBLANK, 1, 1, 1, 1);
123 @@ -876,11 +886,6 @@ static int imx290_start_streaming(struct
127 - ret = imx290_write(imx290, IMX290_HMAX, imx290->current_mode->hmax,
132 /* Apply customized values from user */
133 ret = __v4l2_ctrl_handler_setup(imx290->sd.ctrl_handler);