bcm27xx: switch to kernel v6.1
[openwrt/openwrt.git] / target / linux / bcm27xx / patches-5.15 / 950-0734-media-i2c-ov7251-Set-VTS-instead-of-having-full-tabl.patch
1 From 26934caec8e9a365d71e437333998002b2f2879c Mon Sep 17 00:00:00 2001
2 From: Dave Stevenson <dave.stevenson@raspberrypi.com>
3 Date: Thu, 17 Feb 2022 16:24:51 +0000
4 Subject: [PATCH] media: i2c: ov7251: Set VTS instead of having full
5 tables for FPS.
6
7 The driver did have a full copy of the registers for each of
8 the 30, 60, and 90 fps modes. The main difference between them were
9 registers 0x380e/f which set the total height of the frame (VTS).
10
11 Remove the excess register settings, and Set that register value
12 explicitly for each mode.
13
14 This has dropped a change for the 30fps mode to registers 0x3016,
15 0x3017, 0x3018, 0x301a, 0x301b, and 0x301c. The data available
16 doesn't describe these registers, but the sensor seems fully
17 functional without the alternate settings.
18
19 Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
20 ---
21 drivers/media/i2c/ov7251.c | 286 +++----------------------------------
22 1 file changed, 21 insertions(+), 265 deletions(-)
23
24 --- a/drivers/media/i2c/ov7251.c
25 +++ b/drivers/media/i2c/ov7251.c
26 @@ -39,6 +39,8 @@
27 #define OV7251_AEC_AGC_ADJ_1 0x350b
28 /* HTS is registers 0x380c and 0x380d */
29 #define OV7251_HTS 0x3a0
30 +#define OV7251_VTS_HIGH 0x380e
31 +#define OV7251_VTS_LOW 0x380f
32 #define OV7251_TIMING_FORMAT1 0x3820
33 #define OV7251_TIMING_FORMAT1_VFLIP BIT(2)
34 #define OV7251_TIMING_FORMAT2 0x3821
35 @@ -82,6 +84,7 @@ struct ov7251_mode_info {
36 u32 data_size;
37 u16 exposure_max;
38 u16 exposure_def;
39 + u16 vts;
40 struct v4l2_fract timeperframe;
41 };
42
43 @@ -204,263 +207,7 @@ static const struct reg_value ov7251_glo
44 { 0x303b, 0x02 },
45 };
46
47 -static const struct reg_value ov7251_setting_vga_30fps[] = {
48 - { 0x3005, 0x00 },
49 - { 0x3012, 0xc0 },
50 - { 0x3013, 0xd2 },
51 - { 0x3014, 0x04 },
52 - { 0x3016, 0xf0 },
53 - { 0x3017, 0xf0 },
54 - { 0x3018, 0xf0 },
55 - { 0x301a, 0xf0 },
56 - { 0x301b, 0xf0 },
57 - { 0x301c, 0xf0 },
58 - { 0x3023, 0x05 },
59 - { 0x3037, 0xf0 },
60 - { 0x3106, 0xda },
61 - { 0x3503, 0x07 },
62 - { 0x3509, 0x10 },
63 - { 0x3600, 0x1c },
64 - { 0x3602, 0x62 },
65 - { 0x3620, 0xb7 },
66 - { 0x3622, 0x04 },
67 - { 0x3626, 0x21 },
68 - { 0x3627, 0x30 },
69 - { 0x3630, 0x44 },
70 - { 0x3631, 0x35 },
71 - { 0x3634, 0x60 },
72 - { 0x3636, 0x00 },
73 - { 0x3662, 0x01 },
74 - { 0x3663, 0x70 },
75 - { 0x3664, 0x50 },
76 - { 0x3666, 0x0a },
77 - { 0x3669, 0x1a },
78 - { 0x366a, 0x00 },
79 - { 0x366b, 0x50 },
80 - { 0x3673, 0x01 },
81 - { 0x3674, 0xff },
82 - { 0x3675, 0x03 },
83 - { 0x3705, 0xc1 },
84 - { 0x3709, 0x40 },
85 - { 0x373c, 0x08 },
86 - { 0x3742, 0x00 },
87 - { 0x3757, 0xb3 },
88 - { 0x3788, 0x00 },
89 - { 0x37a8, 0x01 },
90 - { 0x37a9, 0xc0 },
91 - { 0x3800, 0x00 },
92 - { 0x3801, 0x04 },
93 - { 0x3802, 0x00 },
94 - { 0x3803, 0x04 },
95 - { 0x3804, 0x02 },
96 - { 0x3805, 0x8b },
97 - { 0x3806, 0x01 },
98 - { 0x3807, 0xeb },
99 - { 0x3808, 0x02 }, /* width high */
100 - { 0x3809, 0x80 }, /* width low */
101 - { 0x380a, 0x01 }, /* height high */
102 - { 0x380b, 0xe0 }, /* height low */
103 - { 0x380c, 0x03 }, /* total horiz timing high */
104 - { 0x380d, 0xa0 }, /* total horiz timing low */
105 - { 0x380e, 0x06 }, /* total vertical timing high */
106 - { 0x380f, 0xbc }, /* total vertical timing low */
107 - { 0x3810, 0x00 },
108 - { 0x3811, 0x04 },
109 - { 0x3812, 0x00 },
110 - { 0x3813, 0x05 },
111 - { 0x3814, 0x11 },
112 - { 0x3815, 0x11 },
113 - { 0x3820, 0x40 },
114 - { 0x3821, 0x00 },
115 - { 0x382f, 0x0e },
116 - { 0x3832, 0x00 },
117 - { 0x3833, 0x05 },
118 - { 0x3834, 0x00 },
119 - { 0x3835, 0x0c },
120 - { 0x3837, 0x00 },
121 - { 0x3b80, 0x00 },
122 - { 0x3b81, 0xa5 },
123 - { 0x3b82, 0x10 },
124 - { 0x3b83, 0x00 },
125 - { 0x3b84, 0x08 },
126 - { 0x3b85, 0x00 },
127 - { 0x3b86, 0x01 },
128 - { 0x3b87, 0x00 },
129 - { 0x3b88, 0x00 },
130 - { 0x3b89, 0x00 },
131 - { 0x3b8a, 0x00 },
132 - { 0x3b8b, 0x05 },
133 - { 0x3b8c, 0x00 },
134 - { 0x3b8d, 0x00 },
135 - { 0x3b8e, 0x00 },
136 - { 0x3b8f, 0x1a },
137 - { 0x3b94, 0x05 },
138 - { 0x3b95, 0xf2 },
139 - { 0x3b96, 0x40 },
140 - { 0x3c00, 0x89 },
141 - { 0x3c01, 0x63 },
142 - { 0x3c02, 0x01 },
143 - { 0x3c03, 0x00 },
144 - { 0x3c04, 0x00 },
145 - { 0x3c05, 0x03 },
146 - { 0x3c06, 0x00 },
147 - { 0x3c07, 0x06 },
148 - { 0x3c0c, 0x01 },
149 - { 0x3c0d, 0xd0 },
150 - { 0x3c0e, 0x02 },
151 - { 0x3c0f, 0x0a },
152 - { 0x4001, 0x42 },
153 - { 0x4004, 0x04 },
154 - { 0x4005, 0x00 },
155 - { 0x404e, 0x01 },
156 - { 0x4300, 0xff },
157 - { 0x4301, 0x00 },
158 - { 0x4315, 0x00 },
159 - { 0x4501, 0x48 },
160 - { 0x4600, 0x00 },
161 - { 0x4601, 0x4e },
162 - { 0x4801, 0x0f },
163 - { 0x4806, 0x0f },
164 - { 0x4819, 0xaa },
165 - { 0x4823, 0x3e },
166 - { 0x4837, 0x19 },
167 - { 0x4a0d, 0x00 },
168 - { 0x4a47, 0x7f },
169 - { 0x4a49, 0xf0 },
170 - { 0x4a4b, 0x30 },
171 - { 0x5000, 0x85 },
172 - { 0x5001, 0x80 },
173 -};
174 -
175 -static const struct reg_value ov7251_setting_vga_60fps[] = {
176 - { 0x3005, 0x00 },
177 - { 0x3012, 0xc0 },
178 - { 0x3013, 0xd2 },
179 - { 0x3014, 0x04 },
180 - { 0x3016, 0x10 },
181 - { 0x3017, 0x00 },
182 - { 0x3018, 0x00 },
183 - { 0x301a, 0x00 },
184 - { 0x301b, 0x00 },
185 - { 0x301c, 0x00 },
186 - { 0x3023, 0x05 },
187 - { 0x3037, 0xf0 },
188 - { 0x3106, 0xda },
189 - { 0x3503, 0x07 },
190 - { 0x3509, 0x10 },
191 - { 0x3600, 0x1c },
192 - { 0x3602, 0x62 },
193 - { 0x3620, 0xb7 },
194 - { 0x3622, 0x04 },
195 - { 0x3626, 0x21 },
196 - { 0x3627, 0x30 },
197 - { 0x3630, 0x44 },
198 - { 0x3631, 0x35 },
199 - { 0x3634, 0x60 },
200 - { 0x3636, 0x00 },
201 - { 0x3662, 0x01 },
202 - { 0x3663, 0x70 },
203 - { 0x3664, 0x50 },
204 - { 0x3666, 0x0a },
205 - { 0x3669, 0x1a },
206 - { 0x366a, 0x00 },
207 - { 0x366b, 0x50 },
208 - { 0x3673, 0x01 },
209 - { 0x3674, 0xff },
210 - { 0x3675, 0x03 },
211 - { 0x3705, 0xc1 },
212 - { 0x3709, 0x40 },
213 - { 0x373c, 0x08 },
214 - { 0x3742, 0x00 },
215 - { 0x3757, 0xb3 },
216 - { 0x3788, 0x00 },
217 - { 0x37a8, 0x01 },
218 - { 0x37a9, 0xc0 },
219 - { 0x3800, 0x00 },
220 - { 0x3801, 0x04 },
221 - { 0x3802, 0x00 },
222 - { 0x3803, 0x04 },
223 - { 0x3804, 0x02 },
224 - { 0x3805, 0x8b },
225 - { 0x3806, 0x01 },
226 - { 0x3807, 0xeb },
227 - { 0x3808, 0x02 }, /* width high */
228 - { 0x3809, 0x80 }, /* width low */
229 - { 0x380a, 0x01 }, /* height high */
230 - { 0x380b, 0xe0 }, /* height low */
231 - { 0x380c, 0x03 }, /* total horiz timing high */
232 - { 0x380d, 0xa0 }, /* total horiz timing low */
233 - { 0x380e, 0x03 }, /* total vertical timing high */
234 - { 0x380f, 0x5c }, /* total vertical timing low */
235 - { 0x3810, 0x00 },
236 - { 0x3811, 0x04 },
237 - { 0x3812, 0x00 },
238 - { 0x3813, 0x05 },
239 - { 0x3814, 0x11 },
240 - { 0x3815, 0x11 },
241 - { 0x3820, 0x40 },
242 - { 0x3821, 0x00 },
243 - { 0x382f, 0x0e },
244 - { 0x3832, 0x00 },
245 - { 0x3833, 0x05 },
246 - { 0x3834, 0x00 },
247 - { 0x3835, 0x0c },
248 - { 0x3837, 0x00 },
249 - { 0x3b80, 0x00 },
250 - { 0x3b81, 0xa5 },
251 - { 0x3b82, 0x10 },
252 - { 0x3b83, 0x00 },
253 - { 0x3b84, 0x08 },
254 - { 0x3b85, 0x00 },
255 - { 0x3b86, 0x01 },
256 - { 0x3b87, 0x00 },
257 - { 0x3b88, 0x00 },
258 - { 0x3b89, 0x00 },
259 - { 0x3b8a, 0x00 },
260 - { 0x3b8b, 0x05 },
261 - { 0x3b8c, 0x00 },
262 - { 0x3b8d, 0x00 },
263 - { 0x3b8e, 0x00 },
264 - { 0x3b8f, 0x1a },
265 - { 0x3b94, 0x05 },
266 - { 0x3b95, 0xf2 },
267 - { 0x3b96, 0x40 },
268 - { 0x3c00, 0x89 },
269 - { 0x3c01, 0x63 },
270 - { 0x3c02, 0x01 },
271 - { 0x3c03, 0x00 },
272 - { 0x3c04, 0x00 },
273 - { 0x3c05, 0x03 },
274 - { 0x3c06, 0x00 },
275 - { 0x3c07, 0x06 },
276 - { 0x3c0c, 0x01 },
277 - { 0x3c0d, 0xd0 },
278 - { 0x3c0e, 0x02 },
279 - { 0x3c0f, 0x0a },
280 - { 0x4001, 0x42 },
281 - { 0x4004, 0x04 },
282 - { 0x4005, 0x00 },
283 - { 0x404e, 0x01 },
284 - { 0x4300, 0xff },
285 - { 0x4301, 0x00 },
286 - { 0x4315, 0x00 },
287 - { 0x4501, 0x48 },
288 - { 0x4600, 0x00 },
289 - { 0x4601, 0x4e },
290 - { 0x4801, 0x0f },
291 - { 0x4806, 0x0f },
292 - { 0x4819, 0xaa },
293 - { 0x4823, 0x3e },
294 - { 0x4837, 0x19 },
295 - { 0x4a0d, 0x00 },
296 - { 0x4a47, 0x7f },
297 - { 0x4a49, 0xf0 },
298 - { 0x4a4b, 0x30 },
299 - { 0x5000, 0x85 },
300 - { 0x5001, 0x80 },
301 -};
302 -
303 -static const struct reg_value ov7251_setting_vga_90fps[] = {
304 +static const struct reg_value ov7251_setting_vga[] = {
305 { 0x3005, 0x00 },
306 { 0x3012, 0xc0 },
307 { 0x3013, 0xd2 },
308 @@ -518,8 +265,6 @@ static const struct reg_value ov7251_set
309 { 0x380b, 0xe0 }, /* height low */
310 { 0x380c, 0x03 }, /* total horiz timing high */
311 { 0x380d, 0xa0 }, /* total horiz timing low */
312 - { 0x380e, 0x02 }, /* total vertical timing high */
313 - { 0x380f, 0x3c }, /* total vertical timing low */
314 { 0x3810, 0x00 },
315 { 0x3811, 0x04 },
316 { 0x3812, 0x00 },
317 @@ -601,10 +346,11 @@ static const struct ov7251_mode_info ov7
318 {
319 .width = 640,
320 .height = 480,
321 - .data = ov7251_setting_vga_30fps,
322 - .data_size = ARRAY_SIZE(ov7251_setting_vga_30fps),
323 + .data = ov7251_setting_vga,
324 + .data_size = ARRAY_SIZE(ov7251_setting_vga),
325 .exposure_max = 1704,
326 .exposure_def = 504,
327 + .vts = 0x6bc,
328 .timeperframe = {
329 .numerator = 100,
330 .denominator = 3000
331 @@ -613,10 +359,11 @@ static const struct ov7251_mode_info ov7
332 {
333 .width = 640,
334 .height = 480,
335 - .data = ov7251_setting_vga_60fps,
336 - .data_size = ARRAY_SIZE(ov7251_setting_vga_60fps),
337 + .data = ov7251_setting_vga,
338 + .data_size = ARRAY_SIZE(ov7251_setting_vga),
339 .exposure_max = 840,
340 .exposure_def = 504,
341 + .vts = 0x35c,
342 .timeperframe = {
343 .numerator = 100,
344 .denominator = 6014
345 @@ -625,10 +372,11 @@ static const struct ov7251_mode_info ov7
346 {
347 .width = 640,
348 .height = 480,
349 - .data = ov7251_setting_vga_90fps,
350 - .data_size = ARRAY_SIZE(ov7251_setting_vga_90fps),
351 + .data = ov7251_setting_vga,
352 + .data_size = ARRAY_SIZE(ov7251_setting_vga),
353 .exposure_max = 552,
354 .exposure_def = 504,
355 + .vts = 0x23c,
356 .timeperframe = {
357 .numerator = 100,
358 .denominator = 9043
359 @@ -1289,6 +1037,14 @@ static int ov7251_s_stream(struct v4l2_s
360 ov7251->current_mode->height);
361 goto err_power_down;
362 }
363 + ret = ov7251_write_reg(ov7251, OV7251_VTS_HIGH,
364 + ov7251->current_mode->vts >> 8);
365 + if (ret)
366 + goto err_power_down;
367 + ret = ov7251_write_reg(ov7251, OV7251_VTS_LOW,
368 + ov7251->current_mode->vts & 0xff);
369 + if (ret)
370 + goto err_power_down;
371 ret = __v4l2_ctrl_handler_setup(&ov7251->ctrls);
372 if (ret < 0) {
373 dev_err(ov7251->dev, "could not sync v4l2 controls\n");