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
6 The maximum exposure is dictated by VTS, so compute it rather
7 than having the value in the mode table.
9 Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
11 drivers/media/i2c/ov7251.c | 14 ++++++--------
12 1 file changed, 6 insertions(+), 8 deletions(-)
14 --- a/drivers/media/i2c/ov7251.c
15 +++ b/drivers/media/i2c/ov7251.c
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 {
27 const struct reg_value *data;
32 struct v4l2_fract timeperframe;
33 @@ -348,7 +349,6 @@ static const struct ov7251_mode_info ov7
35 .data = ov7251_setting_vga,
36 .data_size = ARRAY_SIZE(ov7251_setting_vga),
37 - .exposure_max = 1704,
41 @@ -361,7 +361,6 @@ static const struct ov7251_mode_info ov7
43 .data = ov7251_setting_vga,
44 .data_size = ARRAY_SIZE(ov7251_setting_vga),
45 - .exposure_max = 840,
49 @@ -374,7 +373,6 @@ static const struct ov7251_mode_info ov7
51 .data = ov7251_setting_vga,
52 .data_size = ARRAY_SIZE(ov7251_setting_vga),
53 - .exposure_max = 552,
57 @@ -915,8 +913,8 @@ static int ov7251_set_format(struct v4l2
59 __v4l2_ctrl_s_ctrl(ov7251->hblank, h_blank);
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);
68 @@ -1092,8 +1090,8 @@ static int ov7251_set_frame_interval(str
69 new_mode = ov7251_find_mode_by_ival(ov7251, &fi->interval);
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);