wireguard: bump to 1.0.20200330
[openwrt/openwrt.git] / target / linux / bcm27xx / patches-5.4 / 950-0470-media-ov5647-Add-extra-10-bit-sensor-modes.patch
1 From 28c0004a54ce9b2c5862b38408952583b07458f9 Mon Sep 17 00:00:00 2001
2 From: David Plowman <david.plowman@raspberrypi.com>
3 Date: Wed, 29 Jan 2020 15:31:28 +0000
4 Subject: [PATCH] media: ov5647: Add extra 10-bit sensor modes.
5
6 The 8-bit VGA mode remains, we add the following 10-bit modes:
7
8 Mode 0: 2592x1944 full resolution.
9
10 Mode 1: 1920x1080 full resolution, but centre-cropped.
11 (This mode achieves 30fps, mode 0 does not.)
12
13 Mode 2: 1296x972 full field-of-view 2x2 binned mode.
14
15 Mode 3: VGA full field of view mode.
16
17 Signed-off-by: David Plowman <david.plowman@raspberrypi.com>
18 Signed-off-by: Naushir Patuck <naush@raspberrypi.com>
19 ---
20 drivers/media/i2c/ov5647.c | 463 ++++++++++++++++++++++++++++++++++++-
21 1 file changed, 452 insertions(+), 11 deletions(-)
22
23 --- a/drivers/media/i2c/ov5647.c
24 +++ b/drivers/media/i2c/ov5647.c
25 @@ -111,6 +111,7 @@ struct ov5647 {
26 struct gpio_desc *pwdn;
27 unsigned int flags;
28 struct v4l2_ctrl_handler ctrls;
29 + bool write_mode_regs;
30 };
31
32 static inline struct ov5647 *to_state(struct v4l2_subdev *sd)
33 @@ -130,7 +131,7 @@ static struct regval_list sensor_oe_enab
34 {0x3002, 0xe4},
35 };
36
37 -static struct regval_list ov5647_640x480[] = {
38 +static struct regval_list ov5647_640x480_8bit[] = {
39 {0x0100, 0x00},
40 {0x0103, 0x01},
41 {0x3034, 0x08},
42 @@ -220,9 +221,378 @@ static struct regval_list ov5647_640x480
43 {0x0100, 0x01},
44 };
45
46 +static struct regval_list ov5647_2592x1944_10bit[] = {
47 + {0x0100, 0x00},
48 + {0x0103, 0x01},
49 + {0x3034, 0x1a},
50 + {0x3035, 0x21},
51 + {0x3036, 0x69},
52 + {0x303c, 0x11},
53 + {0x3106, 0xf5},
54 + {0x3821, 0x06},
55 + {0x3820, 0x00},
56 + {0x3827, 0xec},
57 + {0x370c, 0x03},
58 + {0x3612, 0x5b},
59 + {0x3618, 0x04},
60 + {0x5000, 0x06},
61 + {0x5002, 0x41},
62 + {0x5003, 0x08},
63 + {0x5a00, 0x08},
64 + {0x3000, 0x00},
65 + {0x3001, 0x00},
66 + {0x3002, 0x00},
67 + {0x3016, 0x08},
68 + {0x3017, 0xe0},
69 + {0x3018, 0x44},
70 + {0x301c, 0xf8},
71 + {0x301d, 0xf0},
72 + {0x3a18, 0x00},
73 + {0x3a19, 0xf8},
74 + {0x3c01, 0x80},
75 + {0x3b07, 0x0c},
76 + {0x380c, 0x0b},
77 + {0x380d, 0x1c},
78 + {0x380e, 0x07},
79 + {0x380f, 0xb0},
80 + {0x3814, 0x11},
81 + {0x3815, 0x11},
82 + {0x3708, 0x64},
83 + {0x3709, 0x12},
84 + {0x3808, 0x0a},
85 + {0x3809, 0x20},
86 + {0x380a, 0x07},
87 + {0x380b, 0x98},
88 + {0x3800, 0x00},
89 + {0x3801, 0x00},
90 + {0x3802, 0x00},
91 + {0x3803, 0x00},
92 + {0x3804, 0x0a},
93 + {0x3805, 0x3f},
94 + {0x3806, 0x07},
95 + {0x3807, 0xa3},
96 + {0x3811, 0x10},
97 + {0x3813, 0x06},
98 + {0x3630, 0x2e},
99 + {0x3632, 0xe2},
100 + {0x3633, 0x23},
101 + {0x3634, 0x44},
102 + {0x3636, 0x06},
103 + {0x3620, 0x64},
104 + {0x3621, 0xe0},
105 + {0x3600, 0x37},
106 + {0x3704, 0xa0},
107 + {0x3703, 0x5a},
108 + {0x3715, 0x78},
109 + {0x3717, 0x01},
110 + {0x3731, 0x02},
111 + {0x370b, 0x60},
112 + {0x3705, 0x1a},
113 + {0x3f05, 0x02},
114 + {0x3f06, 0x10},
115 + {0x3f01, 0x0a},
116 + {0x3a08, 0x01},
117 + {0x3a09, 0x28},
118 + {0x3a0a, 0x00},
119 + {0x3a0b, 0xf6},
120 + {0x3a0d, 0x08},
121 + {0x3a0e, 0x06},
122 + {0x3a0f, 0x58},
123 + {0x3a10, 0x50},
124 + {0x3a1b, 0x58},
125 + {0x3a1e, 0x50},
126 + {0x3a11, 0x60},
127 + {0x3a1f, 0x28},
128 + {0x4001, 0x02},
129 + {0x4004, 0x04},
130 + {0x4000, 0x09},
131 + {0x4837, 0x19},
132 + {0x4800, 0x24},
133 + {0x3503, 0x03},
134 + {0x0100, 0x01},
135 +};
136 +
137 +static struct regval_list ov5647_1080p30_10bit[] = {
138 + {0x0100, 0x00},
139 + {0x0103, 0x01},
140 + {0x3034, 0x1a},
141 + {0x3035, 0x21},
142 + {0x3036, 0x62},
143 + {0x303c, 0x11},
144 + {0x3106, 0xf5},
145 + {0x3821, 0x06},
146 + {0x3820, 0x00},
147 + {0x3827, 0xec},
148 + {0x370c, 0x03},
149 + {0x3612, 0x5b},
150 + {0x3618, 0x04},
151 + {0x5000, 0x06},
152 + {0x5002, 0x41},
153 + {0x5003, 0x08},
154 + {0x5a00, 0x08},
155 + {0x3000, 0x00},
156 + {0x3001, 0x00},
157 + {0x3002, 0x00},
158 + {0x3016, 0x08},
159 + {0x3017, 0xe0},
160 + {0x3018, 0x44},
161 + {0x301c, 0xf8},
162 + {0x301d, 0xf0},
163 + {0x3a18, 0x00},
164 + {0x3a19, 0xf8},
165 + {0x3c01, 0x80},
166 + {0x3b07, 0x0c},
167 + {0x380c, 0x09},
168 + {0x380d, 0x70},
169 + {0x380e, 0x04},
170 + {0x380f, 0x50},
171 + {0x3814, 0x11},
172 + {0x3815, 0x11},
173 + {0x3708, 0x64},
174 + {0x3709, 0x12},
175 + {0x3808, 0x07},
176 + {0x3809, 0x80},
177 + {0x380a, 0x04},
178 + {0x380b, 0x38},
179 + {0x3800, 0x01},
180 + {0x3801, 0x5c},
181 + {0x3802, 0x01},
182 + {0x3803, 0xb2},
183 + {0x3804, 0x08},
184 + {0x3805, 0xe3},
185 + {0x3806, 0x05},
186 + {0x3807, 0xf1},
187 + {0x3811, 0x04},
188 + {0x3813, 0x02},
189 + {0x3630, 0x2e},
190 + {0x3632, 0xe2},
191 + {0x3633, 0x23},
192 + {0x3634, 0x44},
193 + {0x3636, 0x06},
194 + {0x3620, 0x64},
195 + {0x3621, 0xe0},
196 + {0x3600, 0x37},
197 + {0x3704, 0xa0},
198 + {0x3703, 0x5a},
199 + {0x3715, 0x78},
200 + {0x3717, 0x01},
201 + {0x3731, 0x02},
202 + {0x370b, 0x60},
203 + {0x3705, 0x1a},
204 + {0x3f05, 0x02},
205 + {0x3f06, 0x10},
206 + {0x3f01, 0x0a},
207 + {0x3a08, 0x01},
208 + {0x3a09, 0x4b},
209 + {0x3a0a, 0x01},
210 + {0x3a0b, 0x13},
211 + {0x3a0d, 0x04},
212 + {0x3a0e, 0x03},
213 + {0x3a0f, 0x58},
214 + {0x3a10, 0x50},
215 + {0x3a1b, 0x58},
216 + {0x3a1e, 0x50},
217 + {0x3a11, 0x60},
218 + {0x3a1f, 0x28},
219 + {0x4001, 0x02},
220 + {0x4004, 0x04},
221 + {0x4000, 0x09},
222 + {0x4837, 0x19},
223 + {0x4800, 0x34},
224 + {0x3503, 0x03},
225 + {0x0100, 0x01},
226 +};
227 +
228 +static struct regval_list ov5647_2x2binned_10bit[] = {
229 + {0x0100, 0x00},
230 + {0x0103, 0x01},
231 + {0x3034, 0x1A},
232 + {0x3035, 0x21},
233 + {0x3036, 0x62},
234 + {0x303C, 0x11},
235 + {0x3106, 0xF5},
236 + {0x3827, 0xEC},
237 + {0x370C, 0x03},
238 + {0x3612, 0x59},
239 + {0x3618, 0x00},
240 + {0x5000, 0x06},
241 + {0x5002, 0x41},
242 + {0x5003, 0x08},
243 + {0x5A00, 0x08},
244 + {0x3000, 0x00},
245 + {0x3001, 0x00},
246 + {0x3002, 0x00},
247 + {0x3016, 0x08},
248 + {0x3017, 0xE0},
249 + {0x3018, 0x44},
250 + {0x301C, 0xF8},
251 + {0x301D, 0xF0},
252 + {0x3A18, 0x00},
253 + {0x3A19, 0xF8},
254 + {0x3C01, 0x80},
255 + {0x3B07, 0x0C},
256 + {0x3800, 0x00},
257 + {0x3801, 0x00},
258 + {0x3802, 0x00},
259 + {0x3803, 0x00},
260 + {0x3804, 0x0A},
261 + {0x3805, 0x3F},
262 + {0x3806, 0x07},
263 + {0x3807, 0xA3},
264 + {0x3808, 0x05},
265 + {0x3809, 0x10},
266 + {0x380A, 0x03},
267 + {0x380B, 0xCC},
268 + {0x380C, 0x07},
269 + {0x380D, 0x68},
270 + {0x3811, 0x0c},
271 + {0x3813, 0x06},
272 + {0x3814, 0x31},
273 + {0x3815, 0x31},
274 + {0x3630, 0x2E},
275 + {0x3632, 0xE2},
276 + {0x3633, 0x23},
277 + {0x3634, 0x44},
278 + {0x3636, 0x06},
279 + {0x3620, 0x64},
280 + {0x3621, 0xE0},
281 + {0x3600, 0x37},
282 + {0x3704, 0xA0},
283 + {0x3703, 0x5A},
284 + {0x3715, 0x78},
285 + {0x3717, 0x01},
286 + {0x3731, 0x02},
287 + {0x370B, 0x60},
288 + {0x3705, 0x1A},
289 + {0x3F05, 0x02},
290 + {0x3F06, 0x10},
291 + {0x3F01, 0x0A},
292 + {0x3A08, 0x01},
293 + {0x3A09, 0x28},
294 + {0x3A0A, 0x00},
295 + {0x3A0B, 0xF6},
296 + {0x3A0D, 0x08},
297 + {0x3A0E, 0x06},
298 + {0x3A0F, 0x58},
299 + {0x3A10, 0x50},
300 + {0x3A1B, 0x58},
301 + {0x3A1E, 0x50},
302 + {0x3A11, 0x60},
303 + {0x3A1F, 0x28},
304 + {0x4001, 0x02},
305 + {0x4004, 0x04},
306 + {0x4000, 0x09},
307 + {0x4837, 0x16},
308 + {0x4800, 0x24},
309 + {0x3503, 0x03},
310 + {0x3820, 0x41},
311 + {0x3821, 0x07},
312 + {0x380E, 0x05},
313 + {0x380F, 0x9B},
314 + {0x350A, 0x00},
315 + {0x350B, 0x10},
316 + {0x3500, 0x00},
317 + {0x3501, 0x1A},
318 + {0x3502, 0xF0},
319 + {0x3212, 0xA0},
320 + {0x0100, 0x01},
321 +};
322 +
323 +static struct regval_list ov5647_640x480_10bit[] = {
324 + {0x0100, 0x00},
325 + {0x0103, 0x01},
326 + {0x3035, 0x11},
327 + {0x3036, 0x46},
328 + {0x303c, 0x11},
329 + {0x3821, 0x07},
330 + {0x3820, 0x41},
331 + {0x370c, 0x03},
332 + {0x3612, 0x59},
333 + {0x3618, 0x00},
334 + {0x5000, 0x06},
335 + {0x5003, 0x08},
336 + {0x5a00, 0x08},
337 + {0x3000, 0xff},
338 + {0x3001, 0xff},
339 + {0x3002, 0xff},
340 + {0x301d, 0xf0},
341 + {0x3a18, 0x00},
342 + {0x3a19, 0xf8},
343 + {0x3c01, 0x80},
344 + {0x3b07, 0x0c},
345 + {0x380c, 0x07},
346 + {0x380d, 0x3c},
347 + {0x380e, 0x01},
348 + {0x380f, 0xf8},
349 + {0x3814, 0x35},
350 + {0x3815, 0x35},
351 + {0x3708, 0x64},
352 + {0x3709, 0x52},
353 + {0x3808, 0x02},
354 + {0x3809, 0x80},
355 + {0x380a, 0x01},
356 + {0x380b, 0xe0},
357 + {0x3800, 0x00},
358 + {0x3801, 0x10},
359 + {0x3802, 0x00},
360 + {0x3803, 0x00},
361 + {0x3804, 0x0a},
362 + {0x3805, 0x2f},
363 + {0x3806, 0x07},
364 + {0x3807, 0x9f},
365 + {0x3630, 0x2e},
366 + {0x3632, 0xe2},
367 + {0x3633, 0x23},
368 + {0x3634, 0x44},
369 + {0x3620, 0x64},
370 + {0x3621, 0xe0},
371 + {0x3600, 0x37},
372 + {0x3704, 0xa0},
373 + {0x3703, 0x5a},
374 + {0x3715, 0x78},
375 + {0x3717, 0x01},
376 + {0x3731, 0x02},
377 + {0x370b, 0x60},
378 + {0x3705, 0x1a},
379 + {0x3f05, 0x02},
380 + {0x3f06, 0x10},
381 + {0x3f01, 0x0a},
382 + {0x3a08, 0x01},
383 + {0x3a09, 0x2e},
384 + {0x3a0a, 0x00},
385 + {0x3a0b, 0xfb},
386 + {0x3a0d, 0x02},
387 + {0x3a0e, 0x01},
388 + {0x3a0f, 0x58},
389 + {0x3a10, 0x50},
390 + {0x3a1b, 0x58},
391 + {0x3a1e, 0x50},
392 + {0x3a11, 0x60},
393 + {0x3a1f, 0x28},
394 + {0x4001, 0x02},
395 + {0x4004, 0x02},
396 + {0x4000, 0x09},
397 + {0x3000, 0x00},
398 + {0x3001, 0x00},
399 + {0x3002, 0x00},
400 + {0x3017, 0xe0},
401 + {0x301c, 0xfc},
402 + {0x3636, 0x06},
403 + {0x3016, 0x08},
404 + {0x3827, 0xec},
405 + {0x3018, 0x44},
406 + {0x3035, 0x21},
407 + {0x3106, 0xf5},
408 + {0x3034, 0x1a},
409 + {0x301c, 0xf8},
410 + {0x4800, 0x34},
411 + {0x3503, 0x03},
412 + {0x0100, 0x01},
413 +};
414 +
415 static struct ov5647_mode supported_modes_8bit[] = {
416 /*
417 - * Original 8-bit VGA mode
418 + * MODE 0: Original 8-bit VGA mode.
419 * Uncentred crop (top left quarter) from 2x2 binned 1296x972 image.
420 */
421 {
422 @@ -233,14 +603,70 @@ static struct ov5647_mode supported_mode
423 .width = 640,
424 .height = 480
425 },
426 - ov5647_640x480,
427 - ARRAY_SIZE(ov5647_640x480)
428 + ov5647_640x480_8bit,
429 + ARRAY_SIZE(ov5647_640x480_8bit)
430 },
431 - /* more modes below here... */
432 };
433
434 static struct ov5647_mode supported_modes_10bit[] = {
435 - /* no 10-bit modes yet */
436 + /*
437 + * MODE 0: 2592x1944 full resolution full FOV 10-bit mode.
438 + */
439 + {
440 + {
441 + .code = MEDIA_BUS_FMT_SBGGR10_1X10,
442 + .colorspace = V4L2_COLORSPACE_SRGB,
443 + .field = V4L2_FIELD_NONE,
444 + .width = 2592,
445 + .height = 1944
446 + },
447 + ov5647_2592x1944_10bit,
448 + ARRAY_SIZE(ov5647_2592x1944_10bit)
449 + },
450 + /*
451 + * MODE 1: 1080p30 10-bit mode.
452 + * Full resolution centre-cropped down to 1080p.
453 + */
454 + {
455 + {
456 + .code = MEDIA_BUS_FMT_SBGGR10_1X10,
457 + .colorspace = V4L2_COLORSPACE_SRGB,
458 + .field = V4L2_FIELD_NONE,
459 + .width = 1920,
460 + .height = 1080
461 + },
462 + ov5647_1080p30_10bit,
463 + ARRAY_SIZE(ov5647_1080p30_10bit)
464 + },
465 + /*
466 + * MODE 2: 2x2 binned full FOV 10-bit mode.
467 + */
468 + {
469 + {
470 + .code = MEDIA_BUS_FMT_SBGGR10_1X10,
471 + .colorspace = V4L2_COLORSPACE_SRGB,
472 + .field = V4L2_FIELD_NONE,
473 + .width = 1296,
474 + .height = 972
475 + },
476 + ov5647_2x2binned_10bit,
477 + ARRAY_SIZE(ov5647_2x2binned_10bit)
478 + },
479 + /*
480 + * MODE 3: 10-bit VGA full FOV mode 60fps.
481 + * 2x2 binned and subsampled down to VGA.
482 + */
483 + {
484 + {
485 + .code = MEDIA_BUS_FMT_SBGGR10_1X10,
486 + .colorspace = V4L2_COLORSPACE_SRGB,
487 + .field = V4L2_FIELD_NONE,
488 + .width = 640,
489 + .height = 480
490 + },
491 + ov5647_640x480_10bit,
492 + ARRAY_SIZE(ov5647_640x480_10bit)
493 + },
494 };
495
496 /* Use original 8-bit VGA mode as default. */
497 @@ -343,11 +769,14 @@ static int __sensor_init(struct v4l2_sub
498 if (ret < 0)
499 return ret;
500
501 - ret = ov5647_write_array(sd, state->mode->reg_list,
502 - state->mode->num_regs);
503 - if (ret < 0) {
504 - dev_err(&client->dev, "write sensor default regs error\n");
505 - return ret;
506 + if (state->write_mode_regs) {
507 + ret = ov5647_write_array(sd, state->mode->reg_list,
508 + state->mode->num_regs);
509 + if (ret < 0) {
510 + dev_err(&client->dev, "write sensor default regs error\n");
511 + return ret;
512 + }
513 + state->write_mode_regs = false;
514 }
515
516 ret = ov5647_set_virtual_channel(sd, 0);
517 @@ -475,6 +904,9 @@ static int ov5647_sensor_power(struct v4
518 "Camera not available, check Power\n");
519 goto out;
520 }
521 +
522 + /* Write out the register set over I2C on stream-on. */
523 + ov5647->write_mode_regs = true;
524 } else if (!on && ov5647->power_count == 1) {
525 dev_dbg(&client->dev, "OV5647 power off\n");
526
527 @@ -650,6 +1082,12 @@ static int ov5647_set_fmt(struct v4l2_su
528 framefmt = v4l2_subdev_get_try_format(sd, cfg, format->pad);
529 *framefmt = format->format;
530 } else {
531 + /*
532 + * If we have changed modes, write the I2C register list on
533 + * a stream_on().
534 + */
535 + if (state->mode != mode)
536 + state->write_mode_regs = true;
537 state->mode = mode;
538 }
539
540 @@ -967,6 +1405,9 @@ static int ov5647_probe(struct i2c_clien
541 /* Set the default mode before we init the subdev */
542 sensor->mode = OV5647_DEFAULT_MODE;
543
544 + /* Write out the register set over I2C on stream-on. */
545 + sensor->write_mode_regs = true;
546 +
547 sd = &sensor->sd;
548 v4l2_i2c_subdev_init(sd, client, &ov5647_subdev_ops);
549 sensor->sd.internal_ops = &ov5647_subdev_internal_ops;