aboutsummaryrefslogtreecommitdiffstats
path: root/target/linux/bcm27xx/patches-5.15/950-0735-media-i2c-ov7251-Limit-exposure-based-on-VTS.patch
blob: 77686190e5246ec5c79ad93e02173b3f0349d4e2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
From 1c779e83e5f78cadcd8dfc6cfca33e7aeb323f27 Mon Sep 17 00:00:00 2001
From: Dave Stevenson <dave.stevenson@raspberrypi.com>
Date: Thu, 17 Feb 2022 16:44:33 +0000
Subject: [PATCH] media: i2c: ov7251: Limit exposure based on VTS

The maximum exposure is dictated by VTS, so compute it rather
than having the value in the mode table.

Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
---
 drivers/media/i2c/ov7251.c | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)

--- a/drivers/media/i2c/ov7251.c
+++ b/drivers/media/i2c/ov7251.c
@@ -37,6 +37,8 @@
 #define OV7251_AEC_EXPO_2		0x3502
 #define OV7251_AEC_AGC_ADJ_0		0x350a
 #define OV7251_AEC_AGC_ADJ_1		0x350b
+/* Exposure must be at least 20 lines shorter than VTS */
+#define OV7251_EXPOSURE_OFFSET		20
  /* HTS is registers 0x380c and 0x380d */
 #define OV7251_HTS			0x3a0
 #define OV7251_VTS_HIGH			0x380e
@@ -82,7 +84,6 @@ struct ov7251_mode_info {
 	u32 height;
 	const struct reg_value *data;
 	u32 data_size;
-	u16 exposure_max;
 	u16 exposure_def;
 	u16 vts;
 	struct v4l2_fract timeperframe;
@@ -348,7 +349,6 @@ static const struct ov7251_mode_info ov7
 		.height = 480,
 		.data = ov7251_setting_vga,
 		.data_size = ARRAY_SIZE(ov7251_setting_vga),
-		.exposure_max = 1704,
 		.exposure_def = 504,
 		.vts = 0x6bc,
 		.timeperframe = {
@@ -361,7 +361,6 @@ static const struct ov7251_mode_info ov7
 		.height = 480,
 		.data = ov7251_setting_vga,
 		.data_size = ARRAY_SIZE(ov7251_setting_vga),
-		.exposure_max = 840,
 		.exposure_def = 504,
 		.vts = 0x35c,
 		.timeperframe = {
@@ -374,7 +373,6 @@ static const struct ov7251_mode_info ov7
 		.height = 480,
 		.data = ov7251_setting_vga,
 		.data_size = ARRAY_SIZE(ov7251_setting_vga),
-		.exposure_max = 552,
 		.exposure_def = 504,
 		.vts = 0x23c,
 		.timeperframe = {
@@ -915,8 +913,8 @@ static int ov7251_set_format(struct v4l2
 					 h_blank, 1, h_blank);
 		__v4l2_ctrl_s_ctrl(ov7251->hblank, h_blank);
 
-		ret = __v4l2_ctrl_modify_range(ov7251->exposure,
-					       1, new_mode->exposure_max,
+		ret = __v4l2_ctrl_modify_range(ov7251->exposure, 1,
+					       new_mode->vts - OV7251_EXPOSURE_OFFSET,
 					       1, new_mode->exposure_def);
 		if (ret < 0)
 			goto exit;
@@ -1092,8 +1090,8 @@ static int ov7251_set_frame_interval(str
 	new_mode = ov7251_find_mode_by_ival(ov7251, &fi->interval);
 
 	if (new_mode != ov7251->current_mode) {
-		ret = __v4l2_ctrl_modify_range(ov7251->exposure,
-					       1, new_mode->exposure_max,
+		ret = __v4l2_ctrl_modify_range(ov7251->exposure, 1,
+					       new_mode->vts - OV7251_EXPOSURE_OFFSET,
 					       1, new_mode->exposure_def);
 		if (ret < 0)
 			goto exit;