bcm27xx: add support for linux v5.15
[openwrt/staging/chunkeey.git] / target / linux / bcm27xx / patches-5.15 / 950-0730-media-i2c-ov7251-Add-V4L2_CID_HBLANK-control.patch
1 From 45a2ad18add0e5c14d1cad5ef0c2c10097b583d9 Mon Sep 17 00:00:00 2001
2 From: Dave Stevenson <dave.stevenson@raspberrypi.com>
3 Date: Sat, 12 Feb 2022 12:05:02 +0000
4 Subject: [PATCH] media: i2c: ov7251: Add V4L2_CID_HBLANK control
5
6 HBLANK is a fixed value in this driver, so add as a fixed
7 read-only control.
8 The value is updated during set_format as the V4L2 control is
9 dependent on width, even though only one width is actually
10 defined.
11
12 Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
13 ---
14 drivers/media/i2c/ov7251.c | 18 +++++++++++++++++-
15 1 file changed, 17 insertions(+), 1 deletion(-)
16
17 --- a/drivers/media/i2c/ov7251.c
18 +++ b/drivers/media/i2c/ov7251.c
19 @@ -37,6 +37,8 @@
20 #define OV7251_AEC_EXPO_2 0x3502
21 #define OV7251_AEC_AGC_ADJ_0 0x350a
22 #define OV7251_AEC_AGC_ADJ_1 0x350b
23 + /* HTS is registers 0x380c and 0x380d */
24 +#define OV7251_HTS 0x3a0
25 #define OV7251_TIMING_FORMAT1 0x3820
26 #define OV7251_TIMING_FORMAT1_VFLIP BIT(2)
27 #define OV7251_TIMING_FORMAT2 0x3821
28 @@ -114,6 +116,7 @@ struct ov7251 {
29 struct v4l2_ctrl_handler ctrls;
30 struct v4l2_ctrl *exposure;
31 struct v4l2_ctrl *gain;
32 + struct v4l2_ctrl *hblank;
33
34 /* Cached register values */
35 u8 aec_pk_manual;
36 @@ -1131,6 +1134,7 @@ static int ov7251_set_format(struct v4l2
37 struct v4l2_mbus_framefmt *__format;
38 struct v4l2_rect *__crop;
39 const struct ov7251_mode_info *new_mode;
40 + s64 h_blank;
41 int ret = 0;
42
43 mutex_lock(&ov7251->lock);
44 @@ -1147,6 +1151,11 @@ static int ov7251_set_format(struct v4l2
45 __crop->height = new_mode->height;
46
47 if (format->which == V4L2_SUBDEV_FORMAT_ACTIVE) {
48 + h_blank = OV7251_HTS - new_mode->width;
49 + __v4l2_ctrl_modify_range(ov7251->hblank, h_blank,
50 + h_blank, 1, h_blank);
51 + __v4l2_ctrl_s_ctrl(ov7251->hblank, h_blank);
52 +
53 ret = __v4l2_ctrl_modify_range(ov7251->exposure,
54 1, new_mode->exposure_max,
55 1, new_mode->exposure_def);
56 @@ -1452,6 +1461,7 @@ static int ov7251_probe(struct i2c_clien
57 struct v4l2_ctrl *ctrl;
58 struct ov7251 *ov7251;
59 unsigned int rate = 0;
60 + u32 h_blank;
61 int ret;
62 int i;
63
64 @@ -1531,7 +1541,7 @@ static int ov7251_probe(struct i2c_clien
65
66 ov7251->current_mode = &ov7251_mode_info_data[0];
67
68 - v4l2_ctrl_handler_init(&ov7251->ctrls, 9);
69 + v4l2_ctrl_handler_init(&ov7251->ctrls, 10);
70 ov7251->ctrls.lock = &ov7251->lock;
71
72 v4l2_ctrl_new_std(&ov7251->ctrls, &ov7251_ctrl_ops,
73 @@ -1555,6 +1565,12 @@ static int ov7251_probe(struct i2c_clien
74 0, link_freq);
75 if (ctrl)
76 ctrl->flags |= V4L2_CTRL_FLAG_READ_ONLY;
77 + h_blank = OV7251_HTS - ov7251->current_mode->width;
78 + ov7251->hblank = v4l2_ctrl_new_std(&ov7251->ctrls, NULL,
79 + V4L2_CID_HBLANK, h_blank,
80 + h_blank, 1, h_blank);
81 + if (ov7251->hblank)
82 + ov7251->hblank->flags |= V4L2_CTRL_FLAG_READ_ONLY;
83
84 ov7251->sd.ctrl_handler = &ov7251->ctrls;
85