bcm27xx: switch to kernel v6.1
[openwrt/openwrt.git] / target / linux / bcm27xx / patches-5.15 / 950-0735-media-i2c-ov7251-Limit-exposure-based-on-VTS.patch
1 From 1c779e83e5f78cadcd8dfc6cfca33e7aeb323f27 Mon Sep 17 00:00:00 2001
2 From: Dave Stevenson <dave.stevenson@raspberrypi.com>
3 Date: Thu, 17 Feb 2022 16:44:33 +0000
4 Subject: [PATCH] media: i2c: ov7251: Limit exposure based on VTS
5
6 The maximum exposure is dictated by VTS, so compute it rather
7 than having the value in the mode table.
8
9 Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
10 ---
11 drivers/media/i2c/ov7251.c | 14 ++++++--------
12 1 file changed, 6 insertions(+), 8 deletions(-)
13
14 --- a/drivers/media/i2c/ov7251.c
15 +++ b/drivers/media/i2c/ov7251.c
16 @@ -37,6 +37,8 @@
17 #define OV7251_AEC_EXPO_2 0x3502
18 #define OV7251_AEC_AGC_ADJ_0 0x350a
19 #define OV7251_AEC_AGC_ADJ_1 0x350b
20 +/* Exposure must be at least 20 lines shorter than VTS */
21 +#define OV7251_EXPOSURE_OFFSET 20
22 /* HTS is registers 0x380c and 0x380d */
23 #define OV7251_HTS 0x3a0
24 #define OV7251_VTS_HIGH 0x380e
25 @@ -82,7 +84,6 @@ struct ov7251_mode_info {
26 u32 height;
27 const struct reg_value *data;
28 u32 data_size;
29 - u16 exposure_max;
30 u16 exposure_def;
31 u16 vts;
32 struct v4l2_fract timeperframe;
33 @@ -348,7 +349,6 @@ static const struct ov7251_mode_info ov7
34 .height = 480,
35 .data = ov7251_setting_vga,
36 .data_size = ARRAY_SIZE(ov7251_setting_vga),
37 - .exposure_max = 1704,
38 .exposure_def = 504,
39 .vts = 0x6bc,
40 .timeperframe = {
41 @@ -361,7 +361,6 @@ static const struct ov7251_mode_info ov7
42 .height = 480,
43 .data = ov7251_setting_vga,
44 .data_size = ARRAY_SIZE(ov7251_setting_vga),
45 - .exposure_max = 840,
46 .exposure_def = 504,
47 .vts = 0x35c,
48 .timeperframe = {
49 @@ -374,7 +373,6 @@ static const struct ov7251_mode_info ov7
50 .height = 480,
51 .data = ov7251_setting_vga,
52 .data_size = ARRAY_SIZE(ov7251_setting_vga),
53 - .exposure_max = 552,
54 .exposure_def = 504,
55 .vts = 0x23c,
56 .timeperframe = {
57 @@ -915,8 +913,8 @@ static int ov7251_set_format(struct v4l2
58 h_blank, 1, h_blank);
59 __v4l2_ctrl_s_ctrl(ov7251->hblank, h_blank);
60
61 - ret = __v4l2_ctrl_modify_range(ov7251->exposure,
62 - 1, new_mode->exposure_max,
63 + ret = __v4l2_ctrl_modify_range(ov7251->exposure, 1,
64 + new_mode->vts - OV7251_EXPOSURE_OFFSET,
65 1, new_mode->exposure_def);
66 if (ret < 0)
67 goto exit;
68 @@ -1092,8 +1090,8 @@ static int ov7251_set_frame_interval(str
69 new_mode = ov7251_find_mode_by_ival(ov7251, &fi->interval);
70
71 if (new_mode != ov7251->current_mode) {
72 - ret = __v4l2_ctrl_modify_range(ov7251->exposure,
73 - 1, new_mode->exposure_max,
74 + ret = __v4l2_ctrl_modify_range(ov7251->exposure, 1,
75 + new_mode->vts - OV7251_EXPOSURE_OFFSET,
76 1, new_mode->exposure_def);
77 if (ret < 0)
78 goto exit;