.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
---|
1 | 2 | /* |
---|
2 | 3 | * Copyright (C) 2011-2013 Freescale Semiconductor, Inc. All Rights Reserved. |
---|
3 | 4 | * Copyright (C) 2014-2017 Mentor Graphics Inc. |
---|
4 | | - * |
---|
5 | | - * This program is free software; you can redistribute it and/or modify |
---|
6 | | - * it under the terms of the GNU General Public License as published by |
---|
7 | | - * the Free Software Foundation; either version 2 of the License, or |
---|
8 | | - * (at your option) any later version. |
---|
9 | 5 | */ |
---|
10 | 6 | |
---|
11 | 7 | #include <linux/clk.h> |
---|
.. | .. |
---|
25 | 21 | #include <media/v4l2-async.h> |
---|
26 | 22 | #include <media/v4l2-ctrls.h> |
---|
27 | 23 | #include <media/v4l2-device.h> |
---|
| 24 | +#include <media/v4l2-event.h> |
---|
28 | 25 | #include <media/v4l2-fwnode.h> |
---|
29 | 26 | #include <media/v4l2-subdev.h> |
---|
30 | 27 | |
---|
.. | .. |
---|
37 | 34 | #define OV5640_REG_SYS_RESET02 0x3002 |
---|
38 | 35 | #define OV5640_REG_SYS_CLOCK_ENABLE02 0x3006 |
---|
39 | 36 | #define OV5640_REG_SYS_CTRL0 0x3008 |
---|
| 37 | +#define OV5640_REG_SYS_CTRL0_SW_PWDN 0x42 |
---|
| 38 | +#define OV5640_REG_SYS_CTRL0_SW_PWUP 0x02 |
---|
40 | 39 | #define OV5640_REG_CHIP_ID 0x300a |
---|
41 | 40 | #define OV5640_REG_IO_MIPI_CTRL00 0x300e |
---|
42 | 41 | #define OV5640_REG_PAD_OUTPUT_ENABLE01 0x3017 |
---|
.. | .. |
---|
82 | 81 | #define OV5640_REG_SIGMADELTA_CTRL0C 0x3c0c |
---|
83 | 82 | #define OV5640_REG_FRAME_CTRL01 0x4202 |
---|
84 | 83 | #define OV5640_REG_FORMAT_CONTROL00 0x4300 |
---|
| 84 | +#define OV5640_REG_VFIFO_HSIZE 0x4602 |
---|
| 85 | +#define OV5640_REG_VFIFO_VSIZE 0x4604 |
---|
| 86 | +#define OV5640_REG_JPG_MODE_SELECT 0x4713 |
---|
| 87 | +#define OV5640_REG_CCIR656_CTRL00 0x4730 |
---|
85 | 88 | #define OV5640_REG_POLARITY_CTRL00 0x4740 |
---|
86 | 89 | #define OV5640_REG_MIPI_CTRL00 0x4800 |
---|
87 | 90 | #define OV5640_REG_DEBUG_MODE 0x4814 |
---|
.. | .. |
---|
93 | 96 | #define OV5640_REG_SDE_CTRL4 0x5584 |
---|
94 | 97 | #define OV5640_REG_SDE_CTRL5 0x5585 |
---|
95 | 98 | #define OV5640_REG_AVG_READOUT 0x56a1 |
---|
96 | | - |
---|
97 | | -#define OV5640_SCLK2X_ROOT_DIVIDER_DEFAULT 1 |
---|
98 | | -#define OV5640_SCLK_ROOT_DIVIDER_DEFAULT 2 |
---|
99 | 99 | |
---|
100 | 100 | enum ov5640_mode_id { |
---|
101 | 101 | OV5640_MODE_QCIF_176_144 = 0, |
---|
.. | .. |
---|
113 | 113 | enum ov5640_frame_rate { |
---|
114 | 114 | OV5640_15_FPS = 0, |
---|
115 | 115 | OV5640_30_FPS, |
---|
| 116 | + OV5640_60_FPS, |
---|
116 | 117 | OV5640_NUM_FRAMERATES, |
---|
| 118 | +}; |
---|
| 119 | + |
---|
| 120 | +enum ov5640_format_mux { |
---|
| 121 | + OV5640_FMT_MUX_YUV422 = 0, |
---|
| 122 | + OV5640_FMT_MUX_RGB, |
---|
| 123 | + OV5640_FMT_MUX_DITHER, |
---|
| 124 | + OV5640_FMT_MUX_RAW_DPC, |
---|
| 125 | + OV5640_FMT_MUX_SNR_RAW, |
---|
| 126 | + OV5640_FMT_MUX_RAW_CIP, |
---|
117 | 127 | }; |
---|
118 | 128 | |
---|
119 | 129 | struct ov5640_pixfmt { |
---|
.. | .. |
---|
127 | 137 | { MEDIA_BUS_FMT_YUYV8_2X8, V4L2_COLORSPACE_SRGB, }, |
---|
128 | 138 | { MEDIA_BUS_FMT_RGB565_2X8_LE, V4L2_COLORSPACE_SRGB, }, |
---|
129 | 139 | { MEDIA_BUS_FMT_RGB565_2X8_BE, V4L2_COLORSPACE_SRGB, }, |
---|
| 140 | + { MEDIA_BUS_FMT_SBGGR8_1X8, V4L2_COLORSPACE_SRGB, }, |
---|
| 141 | + { MEDIA_BUS_FMT_SGBRG8_1X8, V4L2_COLORSPACE_SRGB, }, |
---|
| 142 | + { MEDIA_BUS_FMT_SGRBG8_1X8, V4L2_COLORSPACE_SRGB, }, |
---|
| 143 | + { MEDIA_BUS_FMT_SRGGB8_1X8, V4L2_COLORSPACE_SRGB, }, |
---|
130 | 144 | }; |
---|
131 | 145 | |
---|
132 | 146 | /* |
---|
.. | .. |
---|
141 | 155 | static const int ov5640_framerates[] = { |
---|
142 | 156 | [OV5640_15_FPS] = 15, |
---|
143 | 157 | [OV5640_30_FPS] = 30, |
---|
| 158 | + [OV5640_60_FPS] = 60, |
---|
144 | 159 | }; |
---|
145 | 160 | |
---|
146 | 161 | /* regulator supplies */ |
---|
147 | 162 | static const char * const ov5640_supply_name[] = { |
---|
148 | 163 | "DOVDD", /* Digital I/O (1.8V) supply */ |
---|
149 | | - "DVDD", /* Digital Core (1.5V) supply */ |
---|
150 | 164 | "AVDD", /* Analog (2.8V) supply */ |
---|
| 165 | + "DVDD", /* Digital Core (1.5V) supply */ |
---|
151 | 166 | }; |
---|
152 | 167 | |
---|
153 | 168 | #define OV5640_NUM_SUPPLIES ARRAY_SIZE(ov5640_supply_name) |
---|
.. | .. |
---|
177 | 192 | u32 vtot; |
---|
178 | 193 | const struct reg_value *reg_data; |
---|
179 | 194 | u32 reg_data_size; |
---|
| 195 | + u32 max_fps; |
---|
180 | 196 | }; |
---|
181 | 197 | |
---|
182 | 198 | struct ov5640_ctrls { |
---|
183 | 199 | struct v4l2_ctrl_handler handler; |
---|
| 200 | + struct v4l2_ctrl *pixel_rate; |
---|
184 | 201 | struct { |
---|
185 | 202 | struct v4l2_ctrl *auto_exp; |
---|
186 | 203 | struct v4l2_ctrl *exposure; |
---|
.. | .. |
---|
260 | 277 | /* YUV422 UYVY VGA@30fps */ |
---|
261 | 278 | static const struct reg_value ov5640_init_setting_30fps_VGA[] = { |
---|
262 | 279 | {0x3103, 0x11, 0, 0}, {0x3008, 0x82, 0, 5}, {0x3008, 0x42, 0, 0}, |
---|
263 | | - {0x3103, 0x03, 0, 0}, {0x3017, 0x00, 0, 0}, {0x3018, 0x00, 0, 0}, |
---|
264 | | - {0x3034, 0x18, 0, 0}, {0x3035, 0x14, 0, 0}, {0x3036, 0x38, 0, 0}, |
---|
265 | | - {0x3037, 0x13, 0, 0}, {0x3630, 0x36, 0, 0}, |
---|
| 280 | + {0x3103, 0x03, 0, 0}, {0x3630, 0x36, 0, 0}, |
---|
266 | 281 | {0x3631, 0x0e, 0, 0}, {0x3632, 0xe2, 0, 0}, {0x3633, 0x12, 0, 0}, |
---|
267 | 282 | {0x3621, 0xe0, 0, 0}, {0x3704, 0xa0, 0, 0}, {0x3703, 0x5a, 0, 0}, |
---|
268 | 283 | {0x3715, 0x78, 0, 0}, {0x3717, 0x01, 0, 0}, {0x370b, 0x60, 0, 0}, |
---|
.. | .. |
---|
289 | 304 | {0x4001, 0x02, 0, 0}, {0x4004, 0x02, 0, 0}, {0x3000, 0x00, 0, 0}, |
---|
290 | 305 | {0x3002, 0x1c, 0, 0}, {0x3004, 0xff, 0, 0}, {0x3006, 0xc3, 0, 0}, |
---|
291 | 306 | {0x302e, 0x08, 0, 0}, {0x4300, 0x3f, 0, 0}, |
---|
292 | | - {0x501f, 0x00, 0, 0}, {0x4713, 0x03, 0, 0}, {0x4407, 0x04, 0, 0}, |
---|
| 307 | + {0x501f, 0x00, 0, 0}, {0x4407, 0x04, 0, 0}, |
---|
293 | 308 | {0x440e, 0x00, 0, 0}, {0x460b, 0x35, 0, 0}, {0x460c, 0x22, 0, 0}, |
---|
294 | 309 | {0x4837, 0x0a, 0, 0}, {0x3824, 0x02, 0, 0}, |
---|
295 | 310 | {0x5000, 0xa7, 0, 0}, {0x5001, 0xa3, 0, 0}, {0x5180, 0xff, 0, 0}, |
---|
.. | .. |
---|
344 | 359 | {0x3a1f, 0x14, 0, 0}, {0x3008, 0x02, 0, 0}, {0x3c00, 0x04, 0, 300}, |
---|
345 | 360 | }; |
---|
346 | 361 | |
---|
347 | | -static const struct reg_value ov5640_setting_30fps_VGA_640_480[] = { |
---|
348 | | - {0x3035, 0x14, 0, 0}, {0x3036, 0x38, 0, 0}, {0x3c07, 0x08, 0, 0}, |
---|
349 | | - {0x3c09, 0x1c, 0, 0}, {0x3c0a, 0x9c, 0, 0}, {0x3c0b, 0x40, 0, 0}, |
---|
350 | | - {0x3814, 0x31, 0, 0}, |
---|
351 | | - {0x3815, 0x31, 0, 0}, {0x3800, 0x00, 0, 0}, {0x3801, 0x00, 0, 0}, |
---|
352 | | - {0x3802, 0x00, 0, 0}, {0x3803, 0x04, 0, 0}, {0x3804, 0x0a, 0, 0}, |
---|
353 | | - {0x3805, 0x3f, 0, 0}, {0x3806, 0x07, 0, 0}, {0x3807, 0x9b, 0, 0}, |
---|
354 | | - {0x3810, 0x00, 0, 0}, |
---|
355 | | - {0x3811, 0x10, 0, 0}, {0x3812, 0x00, 0, 0}, {0x3813, 0x06, 0, 0}, |
---|
356 | | - {0x3618, 0x00, 0, 0}, {0x3612, 0x29, 0, 0}, {0x3708, 0x64, 0, 0}, |
---|
357 | | - {0x3709, 0x52, 0, 0}, {0x370c, 0x03, 0, 0}, {0x3a02, 0x03, 0, 0}, |
---|
358 | | - {0x3a03, 0xd8, 0, 0}, {0x3a08, 0x01, 0, 0}, {0x3a09, 0x0e, 0, 0}, |
---|
359 | | - {0x3a0a, 0x00, 0, 0}, {0x3a0b, 0xf6, 0, 0}, {0x3a0e, 0x03, 0, 0}, |
---|
360 | | - {0x3a0d, 0x04, 0, 0}, {0x3a14, 0x03, 0, 0}, {0x3a15, 0xd8, 0, 0}, |
---|
361 | | - {0x4001, 0x02, 0, 0}, {0x4004, 0x02, 0, 0}, {0x4713, 0x03, 0, 0}, |
---|
362 | | - {0x4407, 0x04, 0, 0}, {0x460b, 0x35, 0, 0}, {0x460c, 0x22, 0, 0}, |
---|
363 | | - {0x3824, 0x02, 0, 0}, {0x5001, 0xa3, 0, 0}, {0x3503, 0x00, 0, 0}, |
---|
364 | | -}; |
---|
365 | | - |
---|
366 | | -static const struct reg_value ov5640_setting_15fps_VGA_640_480[] = { |
---|
367 | | - {0x3035, 0x22, 0, 0}, {0x3036, 0x38, 0, 0}, {0x3c07, 0x08, 0, 0}, |
---|
| 362 | +static const struct reg_value ov5640_setting_VGA_640_480[] = { |
---|
| 363 | + {0x3c07, 0x08, 0, 0}, |
---|
368 | 364 | {0x3c09, 0x1c, 0, 0}, {0x3c0a, 0x9c, 0, 0}, {0x3c0b, 0x40, 0, 0}, |
---|
369 | 365 | {0x3814, 0x31, 0, 0}, |
---|
370 | 366 | {0x3815, 0x31, 0, 0}, {0x3800, 0x00, 0, 0}, {0x3801, 0x00, 0, 0}, |
---|
.. | .. |
---|
377 | 373 | {0x3a03, 0xd8, 0, 0}, {0x3a08, 0x01, 0, 0}, {0x3a09, 0x27, 0, 0}, |
---|
378 | 374 | {0x3a0a, 0x00, 0, 0}, {0x3a0b, 0xf6, 0, 0}, {0x3a0e, 0x03, 0, 0}, |
---|
379 | 375 | {0x3a0d, 0x04, 0, 0}, {0x3a14, 0x03, 0, 0}, {0x3a15, 0xd8, 0, 0}, |
---|
380 | | - {0x4001, 0x02, 0, 0}, {0x4004, 0x02, 0, 0}, {0x4713, 0x03, 0, 0}, |
---|
| 376 | + {0x4001, 0x02, 0, 0}, {0x4004, 0x02, 0, 0}, |
---|
381 | 377 | {0x4407, 0x04, 0, 0}, {0x460b, 0x35, 0, 0}, {0x460c, 0x22, 0, 0}, |
---|
382 | 378 | {0x3824, 0x02, 0, 0}, {0x5001, 0xa3, 0, 0}, |
---|
383 | 379 | }; |
---|
384 | 380 | |
---|
385 | | -static const struct reg_value ov5640_setting_30fps_XGA_1024_768[] = { |
---|
386 | | - {0x3035, 0x14, 0, 0}, {0x3036, 0x38, 0, 0}, {0x3c07, 0x08, 0, 0}, |
---|
387 | | - {0x3c09, 0x1c, 0, 0}, {0x3c0a, 0x9c, 0, 0}, {0x3c0b, 0x40, 0, 0}, |
---|
388 | | - {0x3814, 0x31, 0, 0}, |
---|
389 | | - {0x3815, 0x31, 0, 0}, {0x3800, 0x00, 0, 0}, {0x3801, 0x00, 0, 0}, |
---|
390 | | - {0x3802, 0x00, 0, 0}, {0x3803, 0x04, 0, 0}, {0x3804, 0x0a, 0, 0}, |
---|
391 | | - {0x3805, 0x3f, 0, 0}, {0x3806, 0x07, 0, 0}, {0x3807, 0x9b, 0, 0}, |
---|
392 | | - {0x3810, 0x00, 0, 0}, |
---|
393 | | - {0x3811, 0x10, 0, 0}, {0x3812, 0x00, 0, 0}, {0x3813, 0x06, 0, 0}, |
---|
394 | | - {0x3618, 0x00, 0, 0}, {0x3612, 0x29, 0, 0}, {0x3708, 0x64, 0, 0}, |
---|
395 | | - {0x3709, 0x52, 0, 0}, {0x370c, 0x03, 0, 0}, {0x3a02, 0x03, 0, 0}, |
---|
396 | | - {0x3a03, 0xd8, 0, 0}, {0x3a08, 0x01, 0, 0}, {0x3a09, 0x0e, 0, 0}, |
---|
397 | | - {0x3a0a, 0x00, 0, 0}, {0x3a0b, 0xf6, 0, 0}, {0x3a0e, 0x03, 0, 0}, |
---|
398 | | - {0x3a0d, 0x04, 0, 0}, {0x3a14, 0x03, 0, 0}, {0x3a15, 0xd8, 0, 0}, |
---|
399 | | - {0x4001, 0x02, 0, 0}, {0x4004, 0x02, 0, 0}, {0x4713, 0x03, 0, 0}, |
---|
400 | | - {0x4407, 0x04, 0, 0}, {0x460b, 0x35, 0, 0}, {0x460c, 0x22, 0, 0}, |
---|
401 | | - {0x3824, 0x02, 0, 0}, {0x5001, 0xa3, 0, 0}, {0x3503, 0x00, 0, 0}, |
---|
402 | | - {0x3035, 0x12, 0, 0}, |
---|
403 | | -}; |
---|
404 | | - |
---|
405 | | -static const struct reg_value ov5640_setting_15fps_XGA_1024_768[] = { |
---|
406 | | - {0x3035, 0x22, 0, 0}, {0x3036, 0x38, 0, 0}, {0x3c07, 0x08, 0, 0}, |
---|
| 381 | +static const struct reg_value ov5640_setting_XGA_1024_768[] = { |
---|
| 382 | + {0x3c07, 0x08, 0, 0}, |
---|
407 | 383 | {0x3c09, 0x1c, 0, 0}, {0x3c0a, 0x9c, 0, 0}, {0x3c0b, 0x40, 0, 0}, |
---|
408 | 384 | {0x3814, 0x31, 0, 0}, |
---|
409 | 385 | {0x3815, 0x31, 0, 0}, {0x3800, 0x00, 0, 0}, {0x3801, 0x00, 0, 0}, |
---|
.. | .. |
---|
416 | 392 | {0x3a03, 0xd8, 0, 0}, {0x3a08, 0x01, 0, 0}, {0x3a09, 0x27, 0, 0}, |
---|
417 | 393 | {0x3a0a, 0x00, 0, 0}, {0x3a0b, 0xf6, 0, 0}, {0x3a0e, 0x03, 0, 0}, |
---|
418 | 394 | {0x3a0d, 0x04, 0, 0}, {0x3a14, 0x03, 0, 0}, {0x3a15, 0xd8, 0, 0}, |
---|
419 | | - {0x4001, 0x02, 0, 0}, {0x4004, 0x02, 0, 0}, {0x4713, 0x03, 0, 0}, |
---|
| 395 | + {0x4001, 0x02, 0, 0}, {0x4004, 0x02, 0, 0}, |
---|
420 | 396 | {0x4407, 0x04, 0, 0}, {0x460b, 0x35, 0, 0}, {0x460c, 0x22, 0, 0}, |
---|
421 | 397 | {0x3824, 0x02, 0, 0}, {0x5001, 0xa3, 0, 0}, |
---|
422 | 398 | }; |
---|
423 | 399 | |
---|
424 | | -static const struct reg_value ov5640_setting_30fps_QVGA_320_240[] = { |
---|
425 | | - {0x3035, 0x14, 0, 0}, {0x3036, 0x38, 0, 0}, {0x3c07, 0x08, 0, 0}, |
---|
| 400 | +static const struct reg_value ov5640_setting_QVGA_320_240[] = { |
---|
| 401 | + {0x3c07, 0x08, 0, 0}, |
---|
426 | 402 | {0x3c09, 0x1c, 0, 0}, {0x3c0a, 0x9c, 0, 0}, {0x3c0b, 0x40, 0, 0}, |
---|
427 | 403 | {0x3814, 0x31, 0, 0}, |
---|
428 | 404 | {0x3815, 0x31, 0, 0}, {0x3800, 0x00, 0, 0}, {0x3801, 0x00, 0, 0}, |
---|
.. | .. |
---|
435 | 411 | {0x3a03, 0xd8, 0, 0}, {0x3a08, 0x01, 0, 0}, {0x3a09, 0x27, 0, 0}, |
---|
436 | 412 | {0x3a0a, 0x00, 0, 0}, {0x3a0b, 0xf6, 0, 0}, {0x3a0e, 0x03, 0, 0}, |
---|
437 | 413 | {0x3a0d, 0x04, 0, 0}, {0x3a14, 0x03, 0, 0}, {0x3a15, 0xd8, 0, 0}, |
---|
438 | | - {0x4001, 0x02, 0, 0}, {0x4004, 0x02, 0, 0}, {0x4713, 0x03, 0, 0}, |
---|
| 414 | + {0x4001, 0x02, 0, 0}, {0x4004, 0x02, 0, 0}, |
---|
439 | 415 | {0x4407, 0x04, 0, 0}, {0x460b, 0x35, 0, 0}, {0x460c, 0x22, 0, 0}, |
---|
440 | 416 | {0x3824, 0x02, 0, 0}, {0x5001, 0xa3, 0, 0}, |
---|
441 | 417 | }; |
---|
442 | 418 | |
---|
443 | | -static const struct reg_value ov5640_setting_15fps_QVGA_320_240[] = { |
---|
444 | | - {0x3035, 0x22, 0, 0}, {0x3036, 0x38, 0, 0}, {0x3c07, 0x08, 0, 0}, |
---|
| 419 | +static const struct reg_value ov5640_setting_QCIF_176_144[] = { |
---|
| 420 | + {0x3c07, 0x08, 0, 0}, |
---|
445 | 421 | {0x3c09, 0x1c, 0, 0}, {0x3c0a, 0x9c, 0, 0}, {0x3c0b, 0x40, 0, 0}, |
---|
446 | 422 | {0x3814, 0x31, 0, 0}, |
---|
447 | 423 | {0x3815, 0x31, 0, 0}, {0x3800, 0x00, 0, 0}, {0x3801, 0x00, 0, 0}, |
---|
.. | .. |
---|
454 | 430 | {0x3a03, 0xd8, 0, 0}, {0x3a08, 0x01, 0, 0}, {0x3a09, 0x27, 0, 0}, |
---|
455 | 431 | {0x3a0a, 0x00, 0, 0}, {0x3a0b, 0xf6, 0, 0}, {0x3a0e, 0x03, 0, 0}, |
---|
456 | 432 | {0x3a0d, 0x04, 0, 0}, {0x3a14, 0x03, 0, 0}, {0x3a15, 0xd8, 0, 0}, |
---|
457 | | - {0x4001, 0x02, 0, 0}, {0x4004, 0x02, 0, 0}, {0x4713, 0x03, 0, 0}, |
---|
| 433 | + {0x4001, 0x02, 0, 0}, {0x4004, 0x02, 0, 0}, |
---|
458 | 434 | {0x4407, 0x04, 0, 0}, {0x460b, 0x35, 0, 0}, {0x460c, 0x22, 0, 0}, |
---|
459 | 435 | {0x3824, 0x02, 0, 0}, {0x5001, 0xa3, 0, 0}, |
---|
460 | 436 | }; |
---|
461 | 437 | |
---|
462 | | -static const struct reg_value ov5640_setting_30fps_QCIF_176_144[] = { |
---|
463 | | - {0x3035, 0x14, 0, 0}, {0x3036, 0x38, 0, 0}, {0x3c07, 0x08, 0, 0}, |
---|
464 | | - {0x3c09, 0x1c, 0, 0}, {0x3c0a, 0x9c, 0, 0}, {0x3c0b, 0x40, 0, 0}, |
---|
465 | | - {0x3814, 0x31, 0, 0}, |
---|
466 | | - {0x3815, 0x31, 0, 0}, {0x3800, 0x00, 0, 0}, {0x3801, 0x00, 0, 0}, |
---|
467 | | - {0x3802, 0x00, 0, 0}, {0x3803, 0x04, 0, 0}, {0x3804, 0x0a, 0, 0}, |
---|
468 | | - {0x3805, 0x3f, 0, 0}, {0x3806, 0x07, 0, 0}, {0x3807, 0x9b, 0, 0}, |
---|
469 | | - {0x3810, 0x00, 0, 0}, |
---|
470 | | - {0x3811, 0x10, 0, 0}, {0x3812, 0x00, 0, 0}, {0x3813, 0x06, 0, 0}, |
---|
471 | | - {0x3618, 0x00, 0, 0}, {0x3612, 0x29, 0, 0}, {0x3708, 0x64, 0, 0}, |
---|
472 | | - {0x3709, 0x52, 0, 0}, {0x370c, 0x03, 0, 0}, {0x3a02, 0x03, 0, 0}, |
---|
473 | | - {0x3a03, 0xd8, 0, 0}, {0x3a08, 0x01, 0, 0}, {0x3a09, 0x27, 0, 0}, |
---|
474 | | - {0x3a0a, 0x00, 0, 0}, {0x3a0b, 0xf6, 0, 0}, {0x3a0e, 0x03, 0, 0}, |
---|
475 | | - {0x3a0d, 0x04, 0, 0}, {0x3a14, 0x03, 0, 0}, {0x3a15, 0xd8, 0, 0}, |
---|
476 | | - {0x4001, 0x02, 0, 0}, {0x4004, 0x02, 0, 0}, {0x4713, 0x03, 0, 0}, |
---|
477 | | - {0x4407, 0x04, 0, 0}, {0x460b, 0x35, 0, 0}, {0x460c, 0x22, 0, 0}, |
---|
478 | | - {0x3824, 0x02, 0, 0}, {0x5001, 0xa3, 0, 0}, |
---|
479 | | -}; |
---|
480 | | - |
---|
481 | | -static const struct reg_value ov5640_setting_15fps_QCIF_176_144[] = { |
---|
482 | | - {0x3035, 0x22, 0, 0}, {0x3036, 0x38, 0, 0}, {0x3c07, 0x08, 0, 0}, |
---|
483 | | - {0x3c09, 0x1c, 0, 0}, {0x3c0a, 0x9c, 0, 0}, {0x3c0b, 0x40, 0, 0}, |
---|
484 | | - {0x3814, 0x31, 0, 0}, |
---|
485 | | - {0x3815, 0x31, 0, 0}, {0x3800, 0x00, 0, 0}, {0x3801, 0x00, 0, 0}, |
---|
486 | | - {0x3802, 0x00, 0, 0}, {0x3803, 0x04, 0, 0}, {0x3804, 0x0a, 0, 0}, |
---|
487 | | - {0x3805, 0x3f, 0, 0}, {0x3806, 0x07, 0, 0}, {0x3807, 0x9b, 0, 0}, |
---|
488 | | - {0x3810, 0x00, 0, 0}, |
---|
489 | | - {0x3811, 0x10, 0, 0}, {0x3812, 0x00, 0, 0}, {0x3813, 0x06, 0, 0}, |
---|
490 | | - {0x3618, 0x00, 0, 0}, {0x3612, 0x29, 0, 0}, {0x3708, 0x64, 0, 0}, |
---|
491 | | - {0x3709, 0x52, 0, 0}, {0x370c, 0x03, 0, 0}, {0x3a02, 0x03, 0, 0}, |
---|
492 | | - {0x3a03, 0xd8, 0, 0}, {0x3a08, 0x01, 0, 0}, {0x3a09, 0x27, 0, 0}, |
---|
493 | | - {0x3a0a, 0x00, 0, 0}, {0x3a0b, 0xf6, 0, 0}, {0x3a0e, 0x03, 0, 0}, |
---|
494 | | - {0x3a0d, 0x04, 0, 0}, {0x3a14, 0x03, 0, 0}, {0x3a15, 0xd8, 0, 0}, |
---|
495 | | - {0x4001, 0x02, 0, 0}, {0x4004, 0x02, 0, 0}, {0x4713, 0x03, 0, 0}, |
---|
496 | | - {0x4407, 0x04, 0, 0}, {0x460b, 0x35, 0, 0}, {0x460c, 0x22, 0, 0}, |
---|
497 | | - {0x3824, 0x02, 0, 0}, {0x5001, 0xa3, 0, 0}, |
---|
498 | | -}; |
---|
499 | | - |
---|
500 | | -static const struct reg_value ov5640_setting_30fps_NTSC_720_480[] = { |
---|
501 | | - {0x3035, 0x12, 0, 0}, {0x3036, 0x38, 0, 0}, {0x3c07, 0x08, 0, 0}, |
---|
| 438 | +static const struct reg_value ov5640_setting_NTSC_720_480[] = { |
---|
| 439 | + {0x3c07, 0x08, 0, 0}, |
---|
502 | 440 | {0x3c09, 0x1c, 0, 0}, {0x3c0a, 0x9c, 0, 0}, {0x3c0b, 0x40, 0, 0}, |
---|
503 | 441 | {0x3814, 0x31, 0, 0}, |
---|
504 | 442 | {0x3815, 0x31, 0, 0}, {0x3800, 0x00, 0, 0}, {0x3801, 0x00, 0, 0}, |
---|
.. | .. |
---|
511 | 449 | {0x3a03, 0xd8, 0, 0}, {0x3a08, 0x01, 0, 0}, {0x3a09, 0x27, 0, 0}, |
---|
512 | 450 | {0x3a0a, 0x00, 0, 0}, {0x3a0b, 0xf6, 0, 0}, {0x3a0e, 0x03, 0, 0}, |
---|
513 | 451 | {0x3a0d, 0x04, 0, 0}, {0x3a14, 0x03, 0, 0}, {0x3a15, 0xd8, 0, 0}, |
---|
514 | | - {0x4001, 0x02, 0, 0}, {0x4004, 0x02, 0, 0}, {0x4713, 0x03, 0, 0}, |
---|
| 452 | + {0x4001, 0x02, 0, 0}, {0x4004, 0x02, 0, 0}, |
---|
515 | 453 | {0x4407, 0x04, 0, 0}, {0x460b, 0x35, 0, 0}, {0x460c, 0x22, 0, 0}, |
---|
516 | 454 | {0x3824, 0x02, 0, 0}, {0x5001, 0xa3, 0, 0}, |
---|
517 | 455 | }; |
---|
518 | 456 | |
---|
519 | | -static const struct reg_value ov5640_setting_15fps_NTSC_720_480[] = { |
---|
520 | | - {0x3035, 0x22, 0, 0}, {0x3036, 0x38, 0, 0}, {0x3c07, 0x08, 0, 0}, |
---|
521 | | - {0x3c09, 0x1c, 0, 0}, {0x3c0a, 0x9c, 0, 0}, {0x3c0b, 0x40, 0, 0}, |
---|
522 | | - {0x3814, 0x31, 0, 0}, |
---|
523 | | - {0x3815, 0x31, 0, 0}, {0x3800, 0x00, 0, 0}, {0x3801, 0x00, 0, 0}, |
---|
524 | | - {0x3802, 0x00, 0, 0}, {0x3803, 0x04, 0, 0}, {0x3804, 0x0a, 0, 0}, |
---|
525 | | - {0x3805, 0x3f, 0, 0}, {0x3806, 0x07, 0, 0}, {0x3807, 0x9b, 0, 0}, |
---|
526 | | - {0x3810, 0x00, 0, 0}, |
---|
527 | | - {0x3811, 0x10, 0, 0}, {0x3812, 0x00, 0, 0}, {0x3813, 0x3c, 0, 0}, |
---|
528 | | - {0x3618, 0x00, 0, 0}, {0x3612, 0x29, 0, 0}, {0x3708, 0x64, 0, 0}, |
---|
529 | | - {0x3709, 0x52, 0, 0}, {0x370c, 0x03, 0, 0}, {0x3a02, 0x03, 0, 0}, |
---|
530 | | - {0x3a03, 0xd8, 0, 0}, {0x3a08, 0x01, 0, 0}, {0x3a09, 0x27, 0, 0}, |
---|
531 | | - {0x3a0a, 0x00, 0, 0}, {0x3a0b, 0xf6, 0, 0}, {0x3a0e, 0x03, 0, 0}, |
---|
532 | | - {0x3a0d, 0x04, 0, 0}, {0x3a14, 0x03, 0, 0}, {0x3a15, 0xd8, 0, 0}, |
---|
533 | | - {0x4001, 0x02, 0, 0}, {0x4004, 0x02, 0, 0}, {0x4713, 0x03, 0, 0}, |
---|
534 | | - {0x4407, 0x04, 0, 0}, {0x460b, 0x35, 0, 0}, {0x460c, 0x22, 0, 0}, |
---|
535 | | - {0x3824, 0x02, 0, 0}, {0x5001, 0xa3, 0, 0}, |
---|
536 | | -}; |
---|
537 | | - |
---|
538 | | -static const struct reg_value ov5640_setting_30fps_PAL_720_576[] = { |
---|
539 | | - {0x3035, 0x12, 0, 0}, {0x3036, 0x38, 0, 0}, {0x3c07, 0x08, 0, 0}, |
---|
| 457 | +static const struct reg_value ov5640_setting_PAL_720_576[] = { |
---|
| 458 | + {0x3c07, 0x08, 0, 0}, |
---|
540 | 459 | {0x3c09, 0x1c, 0, 0}, {0x3c0a, 0x9c, 0, 0}, {0x3c0b, 0x40, 0, 0}, |
---|
541 | 460 | {0x3814, 0x31, 0, 0}, |
---|
542 | 461 | {0x3815, 0x31, 0, 0}, {0x3800, 0x00, 0, 0}, {0x3801, 0x00, 0, 0}, |
---|
.. | .. |
---|
549 | 468 | {0x3a03, 0xd8, 0, 0}, {0x3a08, 0x01, 0, 0}, {0x3a09, 0x27, 0, 0}, |
---|
550 | 469 | {0x3a0a, 0x00, 0, 0}, {0x3a0b, 0xf6, 0, 0}, {0x3a0e, 0x03, 0, 0}, |
---|
551 | 470 | {0x3a0d, 0x04, 0, 0}, {0x3a14, 0x03, 0, 0}, {0x3a15, 0xd8, 0, 0}, |
---|
552 | | - {0x4001, 0x02, 0, 0}, {0x4004, 0x02, 0, 0}, {0x4713, 0x03, 0, 0}, |
---|
| 471 | + {0x4001, 0x02, 0, 0}, {0x4004, 0x02, 0, 0}, |
---|
553 | 472 | {0x4407, 0x04, 0, 0}, {0x460b, 0x35, 0, 0}, {0x460c, 0x22, 0, 0}, |
---|
554 | 473 | {0x3824, 0x02, 0, 0}, {0x5001, 0xa3, 0, 0}, |
---|
555 | 474 | }; |
---|
556 | 475 | |
---|
557 | | -static const struct reg_value ov5640_setting_15fps_PAL_720_576[] = { |
---|
558 | | - {0x3035, 0x22, 0, 0}, {0x3036, 0x38, 0, 0}, {0x3c07, 0x08, 0, 0}, |
---|
559 | | - {0x3c09, 0x1c, 0, 0}, {0x3c0a, 0x9c, 0, 0}, {0x3c0b, 0x40, 0, 0}, |
---|
560 | | - {0x3814, 0x31, 0, 0}, |
---|
561 | | - {0x3815, 0x31, 0, 0}, {0x3800, 0x00, 0, 0}, {0x3801, 0x00, 0, 0}, |
---|
562 | | - {0x3802, 0x00, 0, 0}, {0x3803, 0x04, 0, 0}, {0x3804, 0x0a, 0, 0}, |
---|
563 | | - {0x3805, 0x3f, 0, 0}, {0x3806, 0x07, 0, 0}, {0x3807, 0x9b, 0, 0}, |
---|
564 | | - {0x3810, 0x00, 0, 0}, |
---|
565 | | - {0x3811, 0x38, 0, 0}, {0x3812, 0x00, 0, 0}, {0x3813, 0x06, 0, 0}, |
---|
566 | | - {0x3618, 0x00, 0, 0}, {0x3612, 0x29, 0, 0}, {0x3708, 0x64, 0, 0}, |
---|
567 | | - {0x3709, 0x52, 0, 0}, {0x370c, 0x03, 0, 0}, {0x3a02, 0x03, 0, 0}, |
---|
568 | | - {0x3a03, 0xd8, 0, 0}, {0x3a08, 0x01, 0, 0}, {0x3a09, 0x27, 0, 0}, |
---|
569 | | - {0x3a0a, 0x00, 0, 0}, {0x3a0b, 0xf6, 0, 0}, {0x3a0e, 0x03, 0, 0}, |
---|
570 | | - {0x3a0d, 0x04, 0, 0}, {0x3a14, 0x03, 0, 0}, {0x3a15, 0xd8, 0, 0}, |
---|
571 | | - {0x4001, 0x02, 0, 0}, {0x4004, 0x02, 0, 0}, {0x4713, 0x03, 0, 0}, |
---|
572 | | - {0x4407, 0x04, 0, 0}, {0x460b, 0x35, 0, 0}, {0x460c, 0x22, 0, 0}, |
---|
573 | | - {0x3824, 0x02, 0, 0}, {0x5001, 0xa3, 0, 0}, |
---|
574 | | -}; |
---|
575 | | - |
---|
576 | | -static const struct reg_value ov5640_setting_30fps_720P_1280_720[] = { |
---|
577 | | - {0x3008, 0x42, 0, 0}, |
---|
578 | | - {0x3035, 0x21, 0, 0}, {0x3036, 0x54, 0, 0}, {0x3c07, 0x07, 0, 0}, |
---|
| 476 | +static const struct reg_value ov5640_setting_720P_1280_720[] = { |
---|
| 477 | + {0x3c07, 0x07, 0, 0}, |
---|
579 | 478 | {0x3c09, 0x1c, 0, 0}, {0x3c0a, 0x9c, 0, 0}, {0x3c0b, 0x40, 0, 0}, |
---|
580 | 479 | {0x3814, 0x31, 0, 0}, |
---|
581 | 480 | {0x3815, 0x31, 0, 0}, {0x3800, 0x00, 0, 0}, {0x3801, 0x00, 0, 0}, |
---|
.. | .. |
---|
588 | 487 | {0x3a03, 0xe4, 0, 0}, {0x3a08, 0x01, 0, 0}, {0x3a09, 0xbc, 0, 0}, |
---|
589 | 488 | {0x3a0a, 0x01, 0, 0}, {0x3a0b, 0x72, 0, 0}, {0x3a0e, 0x01, 0, 0}, |
---|
590 | 489 | {0x3a0d, 0x02, 0, 0}, {0x3a14, 0x02, 0, 0}, {0x3a15, 0xe4, 0, 0}, |
---|
591 | | - {0x4001, 0x02, 0, 0}, {0x4004, 0x02, 0, 0}, {0x4713, 0x02, 0, 0}, |
---|
592 | | - {0x4407, 0x04, 0, 0}, {0x460b, 0x37, 0, 0}, {0x460c, 0x20, 0, 0}, |
---|
593 | | - {0x3824, 0x04, 0, 0}, {0x5001, 0x83, 0, 0}, {0x4005, 0x1a, 0, 0}, |
---|
594 | | - {0x3008, 0x02, 0, 0}, {0x3503, 0, 0, 0}, |
---|
595 | | -}; |
---|
596 | | - |
---|
597 | | -static const struct reg_value ov5640_setting_15fps_720P_1280_720[] = { |
---|
598 | | - {0x3035, 0x41, 0, 0}, {0x3036, 0x54, 0, 0}, {0x3c07, 0x07, 0, 0}, |
---|
599 | | - {0x3c09, 0x1c, 0, 0}, {0x3c0a, 0x9c, 0, 0}, {0x3c0b, 0x40, 0, 0}, |
---|
600 | | - {0x3814, 0x31, 0, 0}, |
---|
601 | | - {0x3815, 0x31, 0, 0}, {0x3800, 0x00, 0, 0}, {0x3801, 0x00, 0, 0}, |
---|
602 | | - {0x3802, 0x00, 0, 0}, {0x3803, 0xfa, 0, 0}, {0x3804, 0x0a, 0, 0}, |
---|
603 | | - {0x3805, 0x3f, 0, 0}, {0x3806, 0x06, 0, 0}, {0x3807, 0xa9, 0, 0}, |
---|
604 | | - {0x3810, 0x00, 0, 0}, |
---|
605 | | - {0x3811, 0x10, 0, 0}, {0x3812, 0x00, 0, 0}, {0x3813, 0x04, 0, 0}, |
---|
606 | | - {0x3618, 0x00, 0, 0}, {0x3612, 0x29, 0, 0}, {0x3708, 0x64, 0, 0}, |
---|
607 | | - {0x3709, 0x52, 0, 0}, {0x370c, 0x03, 0, 0}, {0x3a02, 0x02, 0, 0}, |
---|
608 | | - {0x3a03, 0xe4, 0, 0}, {0x3a08, 0x01, 0, 0}, {0x3a09, 0xbc, 0, 0}, |
---|
609 | | - {0x3a0a, 0x01, 0, 0}, {0x3a0b, 0x72, 0, 0}, {0x3a0e, 0x01, 0, 0}, |
---|
610 | | - {0x3a0d, 0x02, 0, 0}, {0x3a14, 0x02, 0, 0}, {0x3a15, 0xe4, 0, 0}, |
---|
611 | | - {0x4001, 0x02, 0, 0}, {0x4004, 0x02, 0, 0}, {0x4713, 0x02, 0, 0}, |
---|
| 490 | + {0x4001, 0x02, 0, 0}, {0x4004, 0x02, 0, 0}, |
---|
612 | 491 | {0x4407, 0x04, 0, 0}, {0x460b, 0x37, 0, 0}, {0x460c, 0x20, 0, 0}, |
---|
613 | 492 | {0x3824, 0x04, 0, 0}, {0x5001, 0x83, 0, 0}, |
---|
614 | 493 | }; |
---|
615 | 494 | |
---|
616 | | -static const struct reg_value ov5640_setting_30fps_1080P_1920_1080[] = { |
---|
617 | | - {0x3008, 0x42, 0, 0}, |
---|
618 | | - {0x3035, 0x21, 0, 0}, {0x3036, 0x54, 0, 0}, {0x3c07, 0x08, 0, 0}, |
---|
| 495 | +static const struct reg_value ov5640_setting_1080P_1920_1080[] = { |
---|
| 496 | + {0x3c07, 0x08, 0, 0}, |
---|
619 | 497 | {0x3c09, 0x1c, 0, 0}, {0x3c0a, 0x9c, 0, 0}, {0x3c0b, 0x40, 0, 0}, |
---|
620 | 498 | {0x3814, 0x11, 0, 0}, |
---|
621 | 499 | {0x3815, 0x11, 0, 0}, {0x3800, 0x00, 0, 0}, {0x3801, 0x00, 0, 0}, |
---|
.. | .. |
---|
628 | 506 | {0x3a03, 0xd8, 0, 0}, {0x3a08, 0x01, 0, 0}, {0x3a09, 0x27, 0, 0}, |
---|
629 | 507 | {0x3a0a, 0x00, 0, 0}, {0x3a0b, 0xf6, 0, 0}, {0x3a0e, 0x03, 0, 0}, |
---|
630 | 508 | {0x3a0d, 0x04, 0, 0}, {0x3a14, 0x03, 0, 0}, {0x3a15, 0xd8, 0, 0}, |
---|
631 | | - {0x4001, 0x02, 0, 0}, {0x4004, 0x06, 0, 0}, {0x4713, 0x03, 0, 0}, |
---|
| 509 | + {0x4001, 0x02, 0, 0}, {0x4004, 0x06, 0, 0}, |
---|
632 | 510 | {0x4407, 0x04, 0, 0}, {0x460b, 0x35, 0, 0}, {0x460c, 0x22, 0, 0}, |
---|
633 | | - {0x3824, 0x02, 0, 0}, {0x5001, 0x83, 0, 0}, {0x3035, 0x11, 0, 0}, |
---|
634 | | - {0x3036, 0x54, 0, 0}, {0x3c07, 0x07, 0, 0}, {0x3c08, 0x00, 0, 0}, |
---|
| 511 | + {0x3824, 0x02, 0, 0}, {0x5001, 0x83, 0, 0}, |
---|
| 512 | + {0x3c07, 0x07, 0, 0}, {0x3c08, 0x00, 0, 0}, |
---|
635 | 513 | {0x3c09, 0x1c, 0, 0}, {0x3c0a, 0x9c, 0, 0}, {0x3c0b, 0x40, 0, 0}, |
---|
636 | 514 | {0x3800, 0x01, 0, 0}, {0x3801, 0x50, 0, 0}, {0x3802, 0x01, 0, 0}, |
---|
637 | 515 | {0x3803, 0xb2, 0, 0}, {0x3804, 0x08, 0, 0}, {0x3805, 0xef, 0, 0}, |
---|
.. | .. |
---|
640 | 518 | {0x3a02, 0x04, 0, 0}, {0x3a03, 0x60, 0, 0}, {0x3a08, 0x01, 0, 0}, |
---|
641 | 519 | {0x3a09, 0x50, 0, 0}, {0x3a0a, 0x01, 0, 0}, {0x3a0b, 0x18, 0, 0}, |
---|
642 | 520 | {0x3a0e, 0x03, 0, 0}, {0x3a0d, 0x04, 0, 0}, {0x3a14, 0x04, 0, 0}, |
---|
643 | | - {0x3a15, 0x60, 0, 0}, {0x4713, 0x02, 0, 0}, {0x4407, 0x04, 0, 0}, |
---|
| 521 | + {0x3a15, 0x60, 0, 0}, {0x4407, 0x04, 0, 0}, |
---|
644 | 522 | {0x460b, 0x37, 0, 0}, {0x460c, 0x20, 0, 0}, {0x3824, 0x04, 0, 0}, |
---|
645 | | - {0x4005, 0x1a, 0, 0}, {0x3008, 0x02, 0, 0}, |
---|
646 | | - {0x3503, 0, 0, 0}, |
---|
| 523 | + {0x4005, 0x1a, 0, 0}, |
---|
647 | 524 | }; |
---|
648 | 525 | |
---|
649 | | -static const struct reg_value ov5640_setting_15fps_1080P_1920_1080[] = { |
---|
650 | | - {0x3008, 0x42, 0, 0}, |
---|
651 | | - {0x3035, 0x21, 0, 0}, {0x3036, 0x54, 0, 0}, {0x3c07, 0x08, 0, 0}, |
---|
| 526 | +static const struct reg_value ov5640_setting_QSXGA_2592_1944[] = { |
---|
| 527 | + {0x3c07, 0x08, 0, 0}, |
---|
652 | 528 | {0x3c09, 0x1c, 0, 0}, {0x3c0a, 0x9c, 0, 0}, {0x3c0b, 0x40, 0, 0}, |
---|
653 | 529 | {0x3814, 0x11, 0, 0}, |
---|
654 | 530 | {0x3815, 0x11, 0, 0}, {0x3800, 0x00, 0, 0}, {0x3801, 0x00, 0, 0}, |
---|
.. | .. |
---|
661 | 537 | {0x3a03, 0xd8, 0, 0}, {0x3a08, 0x01, 0, 0}, {0x3a09, 0x27, 0, 0}, |
---|
662 | 538 | {0x3a0a, 0x00, 0, 0}, {0x3a0b, 0xf6, 0, 0}, {0x3a0e, 0x03, 0, 0}, |
---|
663 | 539 | {0x3a0d, 0x04, 0, 0}, {0x3a14, 0x03, 0, 0}, {0x3a15, 0xd8, 0, 0}, |
---|
664 | | - {0x4001, 0x02, 0, 0}, {0x4004, 0x06, 0, 0}, {0x4713, 0x03, 0, 0}, |
---|
665 | | - {0x4407, 0x04, 0, 0}, {0x460b, 0x35, 0, 0}, {0x460c, 0x22, 0, 0}, |
---|
666 | | - {0x3824, 0x02, 0, 0}, {0x5001, 0x83, 0, 0}, {0x3035, 0x21, 0, 0}, |
---|
667 | | - {0x3036, 0x54, 0, 1}, {0x3c07, 0x07, 0, 0}, {0x3c08, 0x00, 0, 0}, |
---|
668 | | - {0x3c09, 0x1c, 0, 0}, {0x3c0a, 0x9c, 0, 0}, {0x3c0b, 0x40, 0, 0}, |
---|
669 | | - {0x3800, 0x01, 0, 0}, {0x3801, 0x50, 0, 0}, {0x3802, 0x01, 0, 0}, |
---|
670 | | - {0x3803, 0xb2, 0, 0}, {0x3804, 0x08, 0, 0}, {0x3805, 0xef, 0, 0}, |
---|
671 | | - {0x3806, 0x05, 0, 0}, {0x3807, 0xf1, 0, 0}, |
---|
672 | | - {0x3612, 0x2b, 0, 0}, {0x3708, 0x64, 0, 0}, |
---|
673 | | - {0x3a02, 0x04, 0, 0}, {0x3a03, 0x60, 0, 0}, {0x3a08, 0x01, 0, 0}, |
---|
674 | | - {0x3a09, 0x50, 0, 0}, {0x3a0a, 0x01, 0, 0}, {0x3a0b, 0x18, 0, 0}, |
---|
675 | | - {0x3a0e, 0x03, 0, 0}, {0x3a0d, 0x04, 0, 0}, {0x3a14, 0x04, 0, 0}, |
---|
676 | | - {0x3a15, 0x60, 0, 0}, {0x4713, 0x02, 0, 0}, {0x4407, 0x04, 0, 0}, |
---|
677 | | - {0x460b, 0x37, 0, 0}, {0x460c, 0x20, 0, 0}, {0x3824, 0x04, 0, 0}, |
---|
678 | | - {0x4005, 0x1a, 0, 0}, {0x3008, 0x02, 0, 0}, {0x3503, 0, 0, 0}, |
---|
679 | | -}; |
---|
680 | | - |
---|
681 | | -static const struct reg_value ov5640_setting_15fps_QSXGA_2592_1944[] = { |
---|
682 | | - {0x3035, 0x21, 0, 0}, {0x3036, 0x54, 0, 0}, {0x3c07, 0x08, 0, 0}, |
---|
683 | | - {0x3c09, 0x1c, 0, 0}, {0x3c0a, 0x9c, 0, 0}, {0x3c0b, 0x40, 0, 0}, |
---|
684 | | - {0x3814, 0x11, 0, 0}, |
---|
685 | | - {0x3815, 0x11, 0, 0}, {0x3800, 0x00, 0, 0}, {0x3801, 0x00, 0, 0}, |
---|
686 | | - {0x3802, 0x00, 0, 0}, {0x3803, 0x00, 0, 0}, {0x3804, 0x0a, 0, 0}, |
---|
687 | | - {0x3805, 0x3f, 0, 0}, {0x3806, 0x07, 0, 0}, {0x3807, 0x9f, 0, 0}, |
---|
688 | | - {0x3810, 0x00, 0, 0}, |
---|
689 | | - {0x3811, 0x10, 0, 0}, {0x3812, 0x00, 0, 0}, {0x3813, 0x04, 0, 0}, |
---|
690 | | - {0x3618, 0x04, 0, 0}, {0x3612, 0x29, 0, 0}, {0x3708, 0x21, 0, 0}, |
---|
691 | | - {0x3709, 0x12, 0, 0}, {0x370c, 0x00, 0, 0}, {0x3a02, 0x03, 0, 0}, |
---|
692 | | - {0x3a03, 0xd8, 0, 0}, {0x3a08, 0x01, 0, 0}, {0x3a09, 0x27, 0, 0}, |
---|
693 | | - {0x3a0a, 0x00, 0, 0}, {0x3a0b, 0xf6, 0, 0}, {0x3a0e, 0x03, 0, 0}, |
---|
694 | | - {0x3a0d, 0x04, 0, 0}, {0x3a14, 0x03, 0, 0}, {0x3a15, 0xd8, 0, 0}, |
---|
695 | | - {0x4001, 0x02, 0, 0}, {0x4004, 0x06, 0, 0}, {0x4713, 0x03, 0, 0}, |
---|
| 540 | + {0x4001, 0x02, 0, 0}, {0x4004, 0x06, 0, 0}, |
---|
696 | 541 | {0x4407, 0x04, 0, 0}, {0x460b, 0x35, 0, 0}, {0x460c, 0x22, 0, 0}, |
---|
697 | 542 | {0x3824, 0x02, 0, 0}, {0x5001, 0x83, 0, 70}, |
---|
698 | 543 | }; |
---|
.. | .. |
---|
702 | 547 | 0, SUBSAMPLING, 640, 1896, 480, 984, |
---|
703 | 548 | ov5640_init_setting_30fps_VGA, |
---|
704 | 549 | ARRAY_SIZE(ov5640_init_setting_30fps_VGA), |
---|
| 550 | + OV5640_30_FPS, |
---|
705 | 551 | }; |
---|
706 | 552 | |
---|
707 | 553 | static const struct ov5640_mode_info |
---|
708 | | -ov5640_mode_data[OV5640_NUM_FRAMERATES][OV5640_NUM_MODES] = { |
---|
709 | | - { |
---|
710 | | - {OV5640_MODE_QCIF_176_144, SUBSAMPLING, |
---|
711 | | - 176, 1896, 144, 984, |
---|
712 | | - ov5640_setting_15fps_QCIF_176_144, |
---|
713 | | - ARRAY_SIZE(ov5640_setting_15fps_QCIF_176_144)}, |
---|
714 | | - {OV5640_MODE_QVGA_320_240, SUBSAMPLING, |
---|
715 | | - 320, 1896, 240, 984, |
---|
716 | | - ov5640_setting_15fps_QVGA_320_240, |
---|
717 | | - ARRAY_SIZE(ov5640_setting_15fps_QVGA_320_240)}, |
---|
718 | | - {OV5640_MODE_VGA_640_480, SUBSAMPLING, |
---|
719 | | - 640, 1896, 480, 1080, |
---|
720 | | - ov5640_setting_15fps_VGA_640_480, |
---|
721 | | - ARRAY_SIZE(ov5640_setting_15fps_VGA_640_480)}, |
---|
722 | | - {OV5640_MODE_NTSC_720_480, SUBSAMPLING, |
---|
723 | | - 720, 1896, 480, 984, |
---|
724 | | - ov5640_setting_15fps_NTSC_720_480, |
---|
725 | | - ARRAY_SIZE(ov5640_setting_15fps_NTSC_720_480)}, |
---|
726 | | - {OV5640_MODE_PAL_720_576, SUBSAMPLING, |
---|
727 | | - 720, 1896, 576, 984, |
---|
728 | | - ov5640_setting_15fps_PAL_720_576, |
---|
729 | | - ARRAY_SIZE(ov5640_setting_15fps_PAL_720_576)}, |
---|
730 | | - {OV5640_MODE_XGA_1024_768, SUBSAMPLING, |
---|
731 | | - 1024, 1896, 768, 1080, |
---|
732 | | - ov5640_setting_15fps_XGA_1024_768, |
---|
733 | | - ARRAY_SIZE(ov5640_setting_15fps_XGA_1024_768)}, |
---|
734 | | - {OV5640_MODE_720P_1280_720, SUBSAMPLING, |
---|
735 | | - 1280, 1892, 720, 740, |
---|
736 | | - ov5640_setting_15fps_720P_1280_720, |
---|
737 | | - ARRAY_SIZE(ov5640_setting_15fps_720P_1280_720)}, |
---|
738 | | - {OV5640_MODE_1080P_1920_1080, SCALING, |
---|
739 | | - 1920, 2500, 1080, 1120, |
---|
740 | | - ov5640_setting_15fps_1080P_1920_1080, |
---|
741 | | - ARRAY_SIZE(ov5640_setting_15fps_1080P_1920_1080)}, |
---|
742 | | - {OV5640_MODE_QSXGA_2592_1944, SCALING, |
---|
743 | | - 2592, 2844, 1944, 1968, |
---|
744 | | - ov5640_setting_15fps_QSXGA_2592_1944, |
---|
745 | | - ARRAY_SIZE(ov5640_setting_15fps_QSXGA_2592_1944)}, |
---|
746 | | - }, { |
---|
747 | | - {OV5640_MODE_QCIF_176_144, SUBSAMPLING, |
---|
748 | | - 176, 1896, 144, 984, |
---|
749 | | - ov5640_setting_30fps_QCIF_176_144, |
---|
750 | | - ARRAY_SIZE(ov5640_setting_30fps_QCIF_176_144)}, |
---|
751 | | - {OV5640_MODE_QVGA_320_240, SUBSAMPLING, |
---|
752 | | - 320, 1896, 240, 984, |
---|
753 | | - ov5640_setting_30fps_QVGA_320_240, |
---|
754 | | - ARRAY_SIZE(ov5640_setting_30fps_QVGA_320_240)}, |
---|
755 | | - {OV5640_MODE_VGA_640_480, SUBSAMPLING, |
---|
756 | | - 640, 1896, 480, 1080, |
---|
757 | | - ov5640_setting_30fps_VGA_640_480, |
---|
758 | | - ARRAY_SIZE(ov5640_setting_30fps_VGA_640_480)}, |
---|
759 | | - {OV5640_MODE_NTSC_720_480, SUBSAMPLING, |
---|
760 | | - 720, 1896, 480, 984, |
---|
761 | | - ov5640_setting_30fps_NTSC_720_480, |
---|
762 | | - ARRAY_SIZE(ov5640_setting_30fps_NTSC_720_480)}, |
---|
763 | | - {OV5640_MODE_PAL_720_576, SUBSAMPLING, |
---|
764 | | - 720, 1896, 576, 984, |
---|
765 | | - ov5640_setting_30fps_PAL_720_576, |
---|
766 | | - ARRAY_SIZE(ov5640_setting_30fps_PAL_720_576)}, |
---|
767 | | - {OV5640_MODE_XGA_1024_768, SUBSAMPLING, |
---|
768 | | - 1024, 1896, 768, 1080, |
---|
769 | | - ov5640_setting_30fps_XGA_1024_768, |
---|
770 | | - ARRAY_SIZE(ov5640_setting_30fps_XGA_1024_768)}, |
---|
771 | | - {OV5640_MODE_720P_1280_720, SUBSAMPLING, |
---|
772 | | - 1280, 1892, 720, 740, |
---|
773 | | - ov5640_setting_30fps_720P_1280_720, |
---|
774 | | - ARRAY_SIZE(ov5640_setting_30fps_720P_1280_720)}, |
---|
775 | | - {OV5640_MODE_1080P_1920_1080, SCALING, |
---|
776 | | - 1920, 2500, 1080, 1120, |
---|
777 | | - ov5640_setting_30fps_1080P_1920_1080, |
---|
778 | | - ARRAY_SIZE(ov5640_setting_30fps_1080P_1920_1080)}, |
---|
779 | | - {OV5640_MODE_QSXGA_2592_1944, -1, 0, 0, 0, 0, NULL, 0}, |
---|
780 | | - }, |
---|
| 554 | +ov5640_mode_data[OV5640_NUM_MODES] = { |
---|
| 555 | + {OV5640_MODE_QCIF_176_144, SUBSAMPLING, |
---|
| 556 | + 176, 1896, 144, 984, |
---|
| 557 | + ov5640_setting_QCIF_176_144, |
---|
| 558 | + ARRAY_SIZE(ov5640_setting_QCIF_176_144), |
---|
| 559 | + OV5640_30_FPS}, |
---|
| 560 | + {OV5640_MODE_QVGA_320_240, SUBSAMPLING, |
---|
| 561 | + 320, 1896, 240, 984, |
---|
| 562 | + ov5640_setting_QVGA_320_240, |
---|
| 563 | + ARRAY_SIZE(ov5640_setting_QVGA_320_240), |
---|
| 564 | + OV5640_30_FPS}, |
---|
| 565 | + {OV5640_MODE_VGA_640_480, SUBSAMPLING, |
---|
| 566 | + 640, 1896, 480, 1080, |
---|
| 567 | + ov5640_setting_VGA_640_480, |
---|
| 568 | + ARRAY_SIZE(ov5640_setting_VGA_640_480), |
---|
| 569 | + OV5640_60_FPS}, |
---|
| 570 | + {OV5640_MODE_NTSC_720_480, SUBSAMPLING, |
---|
| 571 | + 720, 1896, 480, 984, |
---|
| 572 | + ov5640_setting_NTSC_720_480, |
---|
| 573 | + ARRAY_SIZE(ov5640_setting_NTSC_720_480), |
---|
| 574 | + OV5640_30_FPS}, |
---|
| 575 | + {OV5640_MODE_PAL_720_576, SUBSAMPLING, |
---|
| 576 | + 720, 1896, 576, 984, |
---|
| 577 | + ov5640_setting_PAL_720_576, |
---|
| 578 | + ARRAY_SIZE(ov5640_setting_PAL_720_576), |
---|
| 579 | + OV5640_30_FPS}, |
---|
| 580 | + {OV5640_MODE_XGA_1024_768, SUBSAMPLING, |
---|
| 581 | + 1024, 1896, 768, 1080, |
---|
| 582 | + ov5640_setting_XGA_1024_768, |
---|
| 583 | + ARRAY_SIZE(ov5640_setting_XGA_1024_768), |
---|
| 584 | + OV5640_30_FPS}, |
---|
| 585 | + {OV5640_MODE_720P_1280_720, SUBSAMPLING, |
---|
| 586 | + 1280, 1892, 720, 740, |
---|
| 587 | + ov5640_setting_720P_1280_720, |
---|
| 588 | + ARRAY_SIZE(ov5640_setting_720P_1280_720), |
---|
| 589 | + OV5640_30_FPS}, |
---|
| 590 | + {OV5640_MODE_1080P_1920_1080, SCALING, |
---|
| 591 | + 1920, 2500, 1080, 1120, |
---|
| 592 | + ov5640_setting_1080P_1920_1080, |
---|
| 593 | + ARRAY_SIZE(ov5640_setting_1080P_1920_1080), |
---|
| 594 | + OV5640_30_FPS}, |
---|
| 595 | + {OV5640_MODE_QSXGA_2592_1944, SCALING, |
---|
| 596 | + 2592, 2844, 1944, 1968, |
---|
| 597 | + ov5640_setting_QSXGA_2592_1944, |
---|
| 598 | + ARRAY_SIZE(ov5640_setting_QSXGA_2592_1944), |
---|
| 599 | + OV5640_15_FPS}, |
---|
781 | 600 | }; |
---|
782 | 601 | |
---|
783 | 602 | static int ov5640_init_slave_id(struct ov5640_dev *sensor) |
---|
.. | .. |
---|
909 | 728 | return ov5640_write_reg(sensor, reg, val); |
---|
910 | 729 | } |
---|
911 | 730 | |
---|
| 731 | +/* |
---|
| 732 | + * After trying the various combinations, reading various |
---|
| 733 | + * documentations spread around the net, and from the various |
---|
| 734 | + * feedback, the clock tree is probably as follows: |
---|
| 735 | + * |
---|
| 736 | + * +--------------+ |
---|
| 737 | + * | Ext. Clock | |
---|
| 738 | + * +-+------------+ |
---|
| 739 | + * | +----------+ |
---|
| 740 | + * +->| PLL1 | - reg 0x3036, for the multiplier |
---|
| 741 | + * +-+--------+ - reg 0x3037, bits 0-3 for the pre-divider |
---|
| 742 | + * | +--------------+ |
---|
| 743 | + * +->| System Clock | - reg 0x3035, bits 4-7 |
---|
| 744 | + * +-+------------+ |
---|
| 745 | + * | +--------------+ |
---|
| 746 | + * +->| MIPI Divider | - reg 0x3035, bits 0-3 |
---|
| 747 | + * | +-+------------+ |
---|
| 748 | + * | +----------------> MIPI SCLK |
---|
| 749 | + * | + +-----+ |
---|
| 750 | + * | +->| / 2 |-------> MIPI BIT CLK |
---|
| 751 | + * | +-----+ |
---|
| 752 | + * | +--------------+ |
---|
| 753 | + * +->| PLL Root Div | - reg 0x3037, bit 4 |
---|
| 754 | + * +-+------------+ |
---|
| 755 | + * | +---------+ |
---|
| 756 | + * +->| Bit Div | - reg 0x3034, bits 0-3 |
---|
| 757 | + * +-+-------+ |
---|
| 758 | + * | +-------------+ |
---|
| 759 | + * +->| SCLK Div | - reg 0x3108, bits 0-1 |
---|
| 760 | + * | +-+-----------+ |
---|
| 761 | + * | +---------------> SCLK |
---|
| 762 | + * | +-------------+ |
---|
| 763 | + * +->| SCLK 2X Div | - reg 0x3108, bits 2-3 |
---|
| 764 | + * | +-+-----------+ |
---|
| 765 | + * | +---------------> SCLK 2X |
---|
| 766 | + * | +-------------+ |
---|
| 767 | + * +->| PCLK Div | - reg 0x3108, bits 4-5 |
---|
| 768 | + * ++------------+ |
---|
| 769 | + * + +-----------+ |
---|
| 770 | + * +->| P_DIV | - reg 0x3035, bits 0-3 |
---|
| 771 | + * +-----+-----+ |
---|
| 772 | + * +------------> PCLK |
---|
| 773 | + * |
---|
| 774 | + * This is deviating from the datasheet at least for the register |
---|
| 775 | + * 0x3108, since it's said here that the PCLK would be clocked from |
---|
| 776 | + * the PLL. |
---|
| 777 | + * |
---|
| 778 | + * There seems to be also (unverified) constraints: |
---|
| 779 | + * - the PLL pre-divider output rate should be in the 4-27MHz range |
---|
| 780 | + * - the PLL multiplier output rate should be in the 500-1000MHz range |
---|
| 781 | + * - PCLK >= SCLK * 2 in YUV, >= SCLK in Raw or JPEG |
---|
| 782 | + * |
---|
| 783 | + * In the two latter cases, these constraints are met since our |
---|
| 784 | + * factors are hardcoded. If we were to change that, we would need to |
---|
| 785 | + * take this into account. The only varying parts are the PLL |
---|
| 786 | + * multiplier and the system clock divider, which are shared between |
---|
| 787 | + * all these clocks so won't cause any issue. |
---|
| 788 | + */ |
---|
| 789 | + |
---|
| 790 | +/* |
---|
| 791 | + * This is supposed to be ranging from 1 to 8, but the value is always |
---|
| 792 | + * set to 3 in the vendor kernels. |
---|
| 793 | + */ |
---|
| 794 | +#define OV5640_PLL_PREDIV 3 |
---|
| 795 | + |
---|
| 796 | +#define OV5640_PLL_MULT_MIN 4 |
---|
| 797 | +#define OV5640_PLL_MULT_MAX 252 |
---|
| 798 | + |
---|
| 799 | +/* |
---|
| 800 | + * This is supposed to be ranging from 1 to 16, but the value is |
---|
| 801 | + * always set to either 1 or 2 in the vendor kernels. |
---|
| 802 | + */ |
---|
| 803 | +#define OV5640_SYSDIV_MIN 1 |
---|
| 804 | +#define OV5640_SYSDIV_MAX 16 |
---|
| 805 | + |
---|
| 806 | +/* |
---|
| 807 | + * Hardcode these values for scaler and non-scaler modes. |
---|
| 808 | + * FIXME: to be re-calcualted for 1 data lanes setups |
---|
| 809 | + */ |
---|
| 810 | +#define OV5640_MIPI_DIV_PCLK 2 |
---|
| 811 | +#define OV5640_MIPI_DIV_SCLK 1 |
---|
| 812 | + |
---|
| 813 | +/* |
---|
| 814 | + * This is supposed to be ranging from 1 to 2, but the value is always |
---|
| 815 | + * set to 2 in the vendor kernels. |
---|
| 816 | + */ |
---|
| 817 | +#define OV5640_PLL_ROOT_DIV 2 |
---|
| 818 | +#define OV5640_PLL_CTRL3_PLL_ROOT_DIV_2 BIT(4) |
---|
| 819 | + |
---|
| 820 | +/* |
---|
| 821 | + * We only supports 8-bit formats at the moment |
---|
| 822 | + */ |
---|
| 823 | +#define OV5640_BIT_DIV 2 |
---|
| 824 | +#define OV5640_PLL_CTRL0_MIPI_MODE_8BIT 0x08 |
---|
| 825 | + |
---|
| 826 | +/* |
---|
| 827 | + * This is supposed to be ranging from 1 to 8, but the value is always |
---|
| 828 | + * set to 2 in the vendor kernels. |
---|
| 829 | + */ |
---|
| 830 | +#define OV5640_SCLK_ROOT_DIV 2 |
---|
| 831 | + |
---|
| 832 | +/* |
---|
| 833 | + * This is hardcoded so that the consistency is maintained between SCLK and |
---|
| 834 | + * SCLK 2x. |
---|
| 835 | + */ |
---|
| 836 | +#define OV5640_SCLK2X_ROOT_DIV (OV5640_SCLK_ROOT_DIV / 2) |
---|
| 837 | + |
---|
| 838 | +/* |
---|
| 839 | + * This is supposed to be ranging from 1 to 8, but the value is always |
---|
| 840 | + * set to 1 in the vendor kernels. |
---|
| 841 | + */ |
---|
| 842 | +#define OV5640_PCLK_ROOT_DIV 1 |
---|
| 843 | +#define OV5640_PLL_SYS_ROOT_DIVIDER_BYPASS 0x00 |
---|
| 844 | + |
---|
| 845 | +static unsigned long ov5640_compute_sys_clk(struct ov5640_dev *sensor, |
---|
| 846 | + u8 pll_prediv, u8 pll_mult, |
---|
| 847 | + u8 sysdiv) |
---|
| 848 | +{ |
---|
| 849 | + unsigned long sysclk = sensor->xclk_freq / pll_prediv * pll_mult; |
---|
| 850 | + |
---|
| 851 | + /* PLL1 output cannot exceed 1GHz. */ |
---|
| 852 | + if (sysclk / 1000000 > 1000) |
---|
| 853 | + return 0; |
---|
| 854 | + |
---|
| 855 | + return sysclk / sysdiv; |
---|
| 856 | +} |
---|
| 857 | + |
---|
| 858 | +static unsigned long ov5640_calc_sys_clk(struct ov5640_dev *sensor, |
---|
| 859 | + unsigned long rate, |
---|
| 860 | + u8 *pll_prediv, u8 *pll_mult, |
---|
| 861 | + u8 *sysdiv) |
---|
| 862 | +{ |
---|
| 863 | + unsigned long best = ~0; |
---|
| 864 | + u8 best_sysdiv = 1, best_mult = 1; |
---|
| 865 | + u8 _sysdiv, _pll_mult; |
---|
| 866 | + |
---|
| 867 | + for (_sysdiv = OV5640_SYSDIV_MIN; |
---|
| 868 | + _sysdiv <= OV5640_SYSDIV_MAX; |
---|
| 869 | + _sysdiv++) { |
---|
| 870 | + for (_pll_mult = OV5640_PLL_MULT_MIN; |
---|
| 871 | + _pll_mult <= OV5640_PLL_MULT_MAX; |
---|
| 872 | + _pll_mult++) { |
---|
| 873 | + unsigned long _rate; |
---|
| 874 | + |
---|
| 875 | + /* |
---|
| 876 | + * The PLL multiplier cannot be odd if above |
---|
| 877 | + * 127. |
---|
| 878 | + */ |
---|
| 879 | + if (_pll_mult > 127 && (_pll_mult % 2)) |
---|
| 880 | + continue; |
---|
| 881 | + |
---|
| 882 | + _rate = ov5640_compute_sys_clk(sensor, |
---|
| 883 | + OV5640_PLL_PREDIV, |
---|
| 884 | + _pll_mult, _sysdiv); |
---|
| 885 | + |
---|
| 886 | + /* |
---|
| 887 | + * We have reached the maximum allowed PLL1 output, |
---|
| 888 | + * increase sysdiv. |
---|
| 889 | + */ |
---|
| 890 | + if (!_rate) |
---|
| 891 | + break; |
---|
| 892 | + |
---|
| 893 | + /* |
---|
| 894 | + * Prefer rates above the expected clock rate than |
---|
| 895 | + * below, even if that means being less precise. |
---|
| 896 | + */ |
---|
| 897 | + if (_rate < rate) |
---|
| 898 | + continue; |
---|
| 899 | + |
---|
| 900 | + if (abs(rate - _rate) < abs(rate - best)) { |
---|
| 901 | + best = _rate; |
---|
| 902 | + best_sysdiv = _sysdiv; |
---|
| 903 | + best_mult = _pll_mult; |
---|
| 904 | + } |
---|
| 905 | + |
---|
| 906 | + if (_rate == rate) |
---|
| 907 | + goto out; |
---|
| 908 | + } |
---|
| 909 | + } |
---|
| 910 | + |
---|
| 911 | +out: |
---|
| 912 | + *sysdiv = best_sysdiv; |
---|
| 913 | + *pll_prediv = OV5640_PLL_PREDIV; |
---|
| 914 | + *pll_mult = best_mult; |
---|
| 915 | + |
---|
| 916 | + return best; |
---|
| 917 | +} |
---|
| 918 | + |
---|
| 919 | +/* |
---|
| 920 | + * ov5640_set_mipi_pclk() - Calculate the clock tree configuration values |
---|
| 921 | + * for the MIPI CSI-2 output. |
---|
| 922 | + * |
---|
| 923 | + * @rate: The requested bandwidth per lane in bytes per second. |
---|
| 924 | + * 'Bandwidth Per Lane' is calculated as: |
---|
| 925 | + * bpl = HTOT * VTOT * FPS * bpp / num_lanes; |
---|
| 926 | + * |
---|
| 927 | + * This function use the requested bandwidth to calculate: |
---|
| 928 | + * - sample_rate = bpl / (bpp / num_lanes); |
---|
| 929 | + * = bpl / (PLL_RDIV * BIT_DIV * PCLK_DIV * MIPI_DIV / num_lanes); |
---|
| 930 | + * |
---|
| 931 | + * - mipi_sclk = bpl / MIPI_DIV / 2; ( / 2 is for CSI-2 DDR) |
---|
| 932 | + * |
---|
| 933 | + * with these fixed parameters: |
---|
| 934 | + * PLL_RDIV = 2; |
---|
| 935 | + * BIT_DIVIDER = 2; (MIPI_BIT_MODE == 8 ? 2 : 2,5); |
---|
| 936 | + * PCLK_DIV = 1; |
---|
| 937 | + * |
---|
| 938 | + * The MIPI clock generation differs for modes that use the scaler and modes |
---|
| 939 | + * that do not. In case the scaler is in use, the MIPI_SCLK generates the MIPI |
---|
| 940 | + * BIT CLk, and thus: |
---|
| 941 | + * |
---|
| 942 | + * - mipi_sclk = bpl / MIPI_DIV / 2; |
---|
| 943 | + * MIPI_DIV = 1; |
---|
| 944 | + * |
---|
| 945 | + * For modes that do not go through the scaler, the MIPI BIT CLOCK is generated |
---|
| 946 | + * from the pixel clock, and thus: |
---|
| 947 | + * |
---|
| 948 | + * - sample_rate = bpl / (bpp / num_lanes); |
---|
| 949 | + * = bpl / (2 * 2 * 1 * MIPI_DIV / num_lanes); |
---|
| 950 | + * = bpl / (4 * MIPI_DIV / num_lanes); |
---|
| 951 | + * - MIPI_DIV = bpp / (4 * num_lanes); |
---|
| 952 | + * |
---|
| 953 | + * FIXME: this have been tested with 16bpp and 2 lanes setup only. |
---|
| 954 | + * MIPI_DIV is fixed to value 2, but it -might- be changed according to the |
---|
| 955 | + * above formula for setups with 1 lane or image formats with different bpp. |
---|
| 956 | + * |
---|
| 957 | + * FIXME: this deviates from the sensor manual documentation which is quite |
---|
| 958 | + * thin on the MIPI clock tree generation part. |
---|
| 959 | + */ |
---|
| 960 | +static int ov5640_set_mipi_pclk(struct ov5640_dev *sensor, |
---|
| 961 | + unsigned long rate) |
---|
| 962 | +{ |
---|
| 963 | + const struct ov5640_mode_info *mode = sensor->current_mode; |
---|
| 964 | + u8 prediv, mult, sysdiv; |
---|
| 965 | + u8 mipi_div; |
---|
| 966 | + int ret; |
---|
| 967 | + |
---|
| 968 | + /* |
---|
| 969 | + * 1280x720 is reported to use 'SUBSAMPLING' only, |
---|
| 970 | + * but according to the sensor manual it goes through the |
---|
| 971 | + * scaler before subsampling. |
---|
| 972 | + */ |
---|
| 973 | + if (mode->dn_mode == SCALING || |
---|
| 974 | + (mode->id == OV5640_MODE_720P_1280_720)) |
---|
| 975 | + mipi_div = OV5640_MIPI_DIV_SCLK; |
---|
| 976 | + else |
---|
| 977 | + mipi_div = OV5640_MIPI_DIV_PCLK; |
---|
| 978 | + |
---|
| 979 | + ov5640_calc_sys_clk(sensor, rate, &prediv, &mult, &sysdiv); |
---|
| 980 | + |
---|
| 981 | + ret = ov5640_mod_reg(sensor, OV5640_REG_SC_PLL_CTRL0, |
---|
| 982 | + 0x0f, OV5640_PLL_CTRL0_MIPI_MODE_8BIT); |
---|
| 983 | + |
---|
| 984 | + ret = ov5640_mod_reg(sensor, OV5640_REG_SC_PLL_CTRL1, |
---|
| 985 | + 0xff, sysdiv << 4 | mipi_div); |
---|
| 986 | + if (ret) |
---|
| 987 | + return ret; |
---|
| 988 | + |
---|
| 989 | + ret = ov5640_mod_reg(sensor, OV5640_REG_SC_PLL_CTRL2, 0xff, mult); |
---|
| 990 | + if (ret) |
---|
| 991 | + return ret; |
---|
| 992 | + |
---|
| 993 | + ret = ov5640_mod_reg(sensor, OV5640_REG_SC_PLL_CTRL3, |
---|
| 994 | + 0x1f, OV5640_PLL_CTRL3_PLL_ROOT_DIV_2 | prediv); |
---|
| 995 | + if (ret) |
---|
| 996 | + return ret; |
---|
| 997 | + |
---|
| 998 | + return ov5640_mod_reg(sensor, OV5640_REG_SYS_ROOT_DIVIDER, |
---|
| 999 | + 0x30, OV5640_PLL_SYS_ROOT_DIVIDER_BYPASS); |
---|
| 1000 | +} |
---|
| 1001 | + |
---|
| 1002 | +static unsigned long ov5640_calc_pclk(struct ov5640_dev *sensor, |
---|
| 1003 | + unsigned long rate, |
---|
| 1004 | + u8 *pll_prediv, u8 *pll_mult, u8 *sysdiv, |
---|
| 1005 | + u8 *pll_rdiv, u8 *bit_div, u8 *pclk_div) |
---|
| 1006 | +{ |
---|
| 1007 | + unsigned long _rate = rate * OV5640_PLL_ROOT_DIV * OV5640_BIT_DIV * |
---|
| 1008 | + OV5640_PCLK_ROOT_DIV; |
---|
| 1009 | + |
---|
| 1010 | + _rate = ov5640_calc_sys_clk(sensor, _rate, pll_prediv, pll_mult, |
---|
| 1011 | + sysdiv); |
---|
| 1012 | + *pll_rdiv = OV5640_PLL_ROOT_DIV; |
---|
| 1013 | + *bit_div = OV5640_BIT_DIV; |
---|
| 1014 | + *pclk_div = OV5640_PCLK_ROOT_DIV; |
---|
| 1015 | + |
---|
| 1016 | + return _rate / *pll_rdiv / *bit_div / *pclk_div; |
---|
| 1017 | +} |
---|
| 1018 | + |
---|
| 1019 | +static int ov5640_set_dvp_pclk(struct ov5640_dev *sensor, unsigned long rate) |
---|
| 1020 | +{ |
---|
| 1021 | + u8 prediv, mult, sysdiv, pll_rdiv, bit_div, pclk_div; |
---|
| 1022 | + int ret; |
---|
| 1023 | + |
---|
| 1024 | + ov5640_calc_pclk(sensor, rate, &prediv, &mult, &sysdiv, &pll_rdiv, |
---|
| 1025 | + &bit_div, &pclk_div); |
---|
| 1026 | + |
---|
| 1027 | + if (bit_div == 2) |
---|
| 1028 | + bit_div = 8; |
---|
| 1029 | + |
---|
| 1030 | + ret = ov5640_mod_reg(sensor, OV5640_REG_SC_PLL_CTRL0, |
---|
| 1031 | + 0x0f, bit_div); |
---|
| 1032 | + if (ret) |
---|
| 1033 | + return ret; |
---|
| 1034 | + |
---|
| 1035 | + /* |
---|
| 1036 | + * We need to set sysdiv according to the clock, and to clear |
---|
| 1037 | + * the MIPI divider. |
---|
| 1038 | + */ |
---|
| 1039 | + ret = ov5640_mod_reg(sensor, OV5640_REG_SC_PLL_CTRL1, |
---|
| 1040 | + 0xff, sysdiv << 4); |
---|
| 1041 | + if (ret) |
---|
| 1042 | + return ret; |
---|
| 1043 | + |
---|
| 1044 | + ret = ov5640_mod_reg(sensor, OV5640_REG_SC_PLL_CTRL2, |
---|
| 1045 | + 0xff, mult); |
---|
| 1046 | + if (ret) |
---|
| 1047 | + return ret; |
---|
| 1048 | + |
---|
| 1049 | + ret = ov5640_mod_reg(sensor, OV5640_REG_SC_PLL_CTRL3, |
---|
| 1050 | + 0x1f, prediv | ((pll_rdiv - 1) << 4)); |
---|
| 1051 | + if (ret) |
---|
| 1052 | + return ret; |
---|
| 1053 | + |
---|
| 1054 | + return ov5640_mod_reg(sensor, OV5640_REG_SYS_ROOT_DIVIDER, 0x30, |
---|
| 1055 | + (ilog2(pclk_div) << 4)); |
---|
| 1056 | +} |
---|
| 1057 | + |
---|
| 1058 | +/* set JPEG framing sizes */ |
---|
| 1059 | +static int ov5640_set_jpeg_timings(struct ov5640_dev *sensor, |
---|
| 1060 | + const struct ov5640_mode_info *mode) |
---|
| 1061 | +{ |
---|
| 1062 | + int ret; |
---|
| 1063 | + |
---|
| 1064 | + /* |
---|
| 1065 | + * compression mode 3 timing |
---|
| 1066 | + * |
---|
| 1067 | + * Data is transmitted with programmable width (VFIFO_HSIZE). |
---|
| 1068 | + * No padding done. Last line may have less data. Varying |
---|
| 1069 | + * number of lines per frame, depending on amount of data. |
---|
| 1070 | + */ |
---|
| 1071 | + ret = ov5640_mod_reg(sensor, OV5640_REG_JPG_MODE_SELECT, 0x7, 0x3); |
---|
| 1072 | + if (ret < 0) |
---|
| 1073 | + return ret; |
---|
| 1074 | + |
---|
| 1075 | + ret = ov5640_write_reg16(sensor, OV5640_REG_VFIFO_HSIZE, mode->hact); |
---|
| 1076 | + if (ret < 0) |
---|
| 1077 | + return ret; |
---|
| 1078 | + |
---|
| 1079 | + return ov5640_write_reg16(sensor, OV5640_REG_VFIFO_VSIZE, mode->vact); |
---|
| 1080 | +} |
---|
| 1081 | + |
---|
912 | 1082 | /* download ov5640 settings to sensor through i2c */ |
---|
913 | 1083 | static int ov5640_set_timings(struct ov5640_dev *sensor, |
---|
914 | 1084 | const struct ov5640_mode_info *mode) |
---|
915 | 1085 | { |
---|
916 | 1086 | int ret; |
---|
| 1087 | + |
---|
| 1088 | + if (sensor->fmt.code == MEDIA_BUS_FMT_JPEG_1X8) { |
---|
| 1089 | + ret = ov5640_set_jpeg_timings(sensor, mode); |
---|
| 1090 | + if (ret < 0) |
---|
| 1091 | + return ret; |
---|
| 1092 | + } |
---|
917 | 1093 | |
---|
918 | 1094 | ret = ov5640_write_reg16(sensor, OV5640_REG_TIMING_DVPHO, mode->hact); |
---|
919 | 1095 | if (ret < 0) |
---|
.. | .. |
---|
945 | 1121 | reg_addr = regs->reg_addr; |
---|
946 | 1122 | val = regs->val; |
---|
947 | 1123 | mask = regs->mask; |
---|
| 1124 | + |
---|
| 1125 | + /* remain in power down mode for DVP */ |
---|
| 1126 | + if (regs->reg_addr == OV5640_REG_SYS_CTRL0 && |
---|
| 1127 | + val == OV5640_REG_SYS_CTRL0_SW_PWUP && |
---|
| 1128 | + sensor->ep.bus_type != V4L2_MBUS_CSI2_DPHY) |
---|
| 1129 | + continue; |
---|
948 | 1130 | |
---|
949 | 1131 | if (mask) |
---|
950 | 1132 | ret = ov5640_mod_reg(sensor, reg_addr, mask, val); |
---|
.. | .. |
---|
1036 | 1218 | |
---|
1037 | 1219 | static int ov5640_set_stream_dvp(struct ov5640_dev *sensor, bool on) |
---|
1038 | 1220 | { |
---|
1039 | | - int ret; |
---|
1040 | | - unsigned int flags = sensor->ep.bus.parallel.flags; |
---|
1041 | | - u8 pclk_pol = 0; |
---|
1042 | | - u8 hsync_pol = 0; |
---|
1043 | | - u8 vsync_pol = 0; |
---|
1044 | | - |
---|
1045 | | - /* |
---|
1046 | | - * Note about parallel port configuration. |
---|
1047 | | - * |
---|
1048 | | - * When configured in parallel mode, the OV5640 will |
---|
1049 | | - * output 10 bits data on DVP data lines [9:0]. |
---|
1050 | | - * If only 8 bits data are wanted, the 8 bits data lines |
---|
1051 | | - * of the camera interface must be physically connected |
---|
1052 | | - * on the DVP data lines [9:2]. |
---|
1053 | | - * |
---|
1054 | | - * Control lines polarity can be configured through |
---|
1055 | | - * devicetree endpoint control lines properties. |
---|
1056 | | - * If no endpoint control lines properties are set, |
---|
1057 | | - * polarity will be as below: |
---|
1058 | | - * - VSYNC: active high |
---|
1059 | | - * - HREF: active low |
---|
1060 | | - * - PCLK: active low |
---|
1061 | | - */ |
---|
1062 | | - |
---|
1063 | | - if (on) { |
---|
1064 | | - /* |
---|
1065 | | - * reset MIPI PCLK/SERCLK divider |
---|
1066 | | - * |
---|
1067 | | - * SC PLL CONTRL1 0 |
---|
1068 | | - * - [3..0]: MIPI PCLK/SERCLK divider |
---|
1069 | | - */ |
---|
1070 | | - ret = ov5640_mod_reg(sensor, OV5640_REG_SC_PLL_CTRL1, 0x0f, 0); |
---|
1071 | | - if (ret) |
---|
1072 | | - return ret; |
---|
1073 | | - |
---|
1074 | | - /* |
---|
1075 | | - * configure parallel port control lines polarity |
---|
1076 | | - * |
---|
1077 | | - * POLARITY CTRL0 |
---|
1078 | | - * - [5]: PCLK polarity (0: active low, 1: active high) |
---|
1079 | | - * - [1]: HREF polarity (0: active low, 1: active high) |
---|
1080 | | - * - [0]: VSYNC polarity (mismatch here between |
---|
1081 | | - * datasheet and hardware, 0 is active high |
---|
1082 | | - * and 1 is active low...) |
---|
1083 | | - */ |
---|
1084 | | - if (flags & V4L2_MBUS_PCLK_SAMPLE_RISING) |
---|
1085 | | - pclk_pol = 1; |
---|
1086 | | - if (flags & V4L2_MBUS_HSYNC_ACTIVE_HIGH) |
---|
1087 | | - hsync_pol = 1; |
---|
1088 | | - if (flags & V4L2_MBUS_VSYNC_ACTIVE_LOW) |
---|
1089 | | - vsync_pol = 1; |
---|
1090 | | - |
---|
1091 | | - ret = ov5640_write_reg(sensor, |
---|
1092 | | - OV5640_REG_POLARITY_CTRL00, |
---|
1093 | | - (pclk_pol << 5) | |
---|
1094 | | - (hsync_pol << 1) | |
---|
1095 | | - vsync_pol); |
---|
1096 | | - |
---|
1097 | | - if (ret) |
---|
1098 | | - return ret; |
---|
1099 | | - } |
---|
1100 | | - |
---|
1101 | | - /* |
---|
1102 | | - * powerdown MIPI TX/RX PHY & disable MIPI |
---|
1103 | | - * |
---|
1104 | | - * MIPI CONTROL 00 |
---|
1105 | | - * 4: PWDN PHY TX |
---|
1106 | | - * 3: PWDN PHY RX |
---|
1107 | | - * 2: MIPI enable |
---|
1108 | | - */ |
---|
1109 | | - ret = ov5640_write_reg(sensor, |
---|
1110 | | - OV5640_REG_IO_MIPI_CTRL00, on ? 0x18 : 0); |
---|
1111 | | - if (ret) |
---|
1112 | | - return ret; |
---|
1113 | | - |
---|
1114 | | - /* |
---|
1115 | | - * enable VSYNC/HREF/PCLK DVP control lines |
---|
1116 | | - * & D[9:6] DVP data lines |
---|
1117 | | - * |
---|
1118 | | - * PAD OUTPUT ENABLE 01 |
---|
1119 | | - * - 6: VSYNC output enable |
---|
1120 | | - * - 5: HREF output enable |
---|
1121 | | - * - 4: PCLK output enable |
---|
1122 | | - * - [3:0]: D[9:6] output enable |
---|
1123 | | - */ |
---|
1124 | | - ret = ov5640_write_reg(sensor, |
---|
1125 | | - OV5640_REG_PAD_OUTPUT_ENABLE01, |
---|
1126 | | - on ? 0x7f : 0); |
---|
1127 | | - if (ret) |
---|
1128 | | - return ret; |
---|
1129 | | - |
---|
1130 | | - /* |
---|
1131 | | - * enable D[5:0] DVP data lines |
---|
1132 | | - * |
---|
1133 | | - * PAD OUTPUT ENABLE 02 |
---|
1134 | | - * - [7:2]: D[5:0] output enable |
---|
1135 | | - */ |
---|
1136 | | - return ov5640_write_reg(sensor, |
---|
1137 | | - OV5640_REG_PAD_OUTPUT_ENABLE02, |
---|
1138 | | - on ? 0xfc : 0); |
---|
| 1221 | + return ov5640_write_reg(sensor, OV5640_REG_SYS_CTRL0, on ? |
---|
| 1222 | + OV5640_REG_SYS_CTRL0_SW_PWUP : |
---|
| 1223 | + OV5640_REG_SYS_CTRL0_SW_PWDN); |
---|
1139 | 1224 | } |
---|
1140 | 1225 | |
---|
1141 | 1226 | static int ov5640_set_stream_mipi(struct ov5640_dev *sensor, bool on) |
---|
.. | .. |
---|
1444 | 1529 | { |
---|
1445 | 1530 | const struct ov5640_mode_info *mode; |
---|
1446 | 1531 | |
---|
1447 | | - mode = v4l2_find_nearest_size(ov5640_mode_data[fr], |
---|
1448 | | - ARRAY_SIZE(ov5640_mode_data[fr]), |
---|
| 1532 | + mode = v4l2_find_nearest_size(ov5640_mode_data, |
---|
| 1533 | + ARRAY_SIZE(ov5640_mode_data), |
---|
1449 | 1534 | hact, vact, |
---|
1450 | 1535 | width, height); |
---|
1451 | 1536 | |
---|
.. | .. |
---|
1453 | 1538 | (!nearest && (mode->hact != width || mode->vact != height))) |
---|
1454 | 1539 | return NULL; |
---|
1455 | 1540 | |
---|
| 1541 | + /* Check to see if the current mode exceeds the max frame rate */ |
---|
| 1542 | + if (ov5640_framerates[fr] > ov5640_framerates[mode->max_fps]) |
---|
| 1543 | + return NULL; |
---|
| 1544 | + |
---|
1456 | 1545 | return mode; |
---|
| 1546 | +} |
---|
| 1547 | + |
---|
| 1548 | +static u64 ov5640_calc_pixel_rate(struct ov5640_dev *sensor) |
---|
| 1549 | +{ |
---|
| 1550 | + u64 rate; |
---|
| 1551 | + |
---|
| 1552 | + rate = sensor->current_mode->vtot * sensor->current_mode->htot; |
---|
| 1553 | + rate *= ov5640_framerates[sensor->current_fr]; |
---|
| 1554 | + |
---|
| 1555 | + return rate; |
---|
1457 | 1556 | } |
---|
1458 | 1557 | |
---|
1459 | 1558 | /* |
---|
.. | .. |
---|
1637 | 1736 | enum ov5640_downsize_mode dn_mode, orig_dn_mode; |
---|
1638 | 1737 | bool auto_gain = sensor->ctrls.auto_gain->val == 1; |
---|
1639 | 1738 | bool auto_exp = sensor->ctrls.auto_exp->val == V4L2_EXPOSURE_AUTO; |
---|
| 1739 | + unsigned long rate; |
---|
1640 | 1740 | int ret; |
---|
1641 | 1741 | |
---|
1642 | 1742 | dn_mode = mode->dn_mode; |
---|
.. | .. |
---|
1654 | 1754 | if (ret) |
---|
1655 | 1755 | goto restore_auto_gain; |
---|
1656 | 1756 | } |
---|
| 1757 | + |
---|
| 1758 | + /* |
---|
| 1759 | + * All the formats we support have 16 bits per pixel, seems to require |
---|
| 1760 | + * the same rate than YUV, so we can just use 16 bpp all the time. |
---|
| 1761 | + */ |
---|
| 1762 | + rate = ov5640_calc_pixel_rate(sensor) * 16; |
---|
| 1763 | + if (sensor->ep.bus_type == V4L2_MBUS_CSI2_DPHY) { |
---|
| 1764 | + rate = rate / sensor->ep.bus.mipi_csi2.num_data_lanes; |
---|
| 1765 | + ret = ov5640_set_mipi_pclk(sensor, rate); |
---|
| 1766 | + } else { |
---|
| 1767 | + rate = rate / sensor->ep.bus.parallel.bus_width; |
---|
| 1768 | + ret = ov5640_set_dvp_pclk(sensor, rate); |
---|
| 1769 | + } |
---|
| 1770 | + |
---|
| 1771 | + if (ret < 0) |
---|
| 1772 | + return 0; |
---|
1657 | 1773 | |
---|
1658 | 1774 | if ((dn_mode == SUBSAMPLING && orig_dn_mode == SCALING) || |
---|
1659 | 1775 | (dn_mode == SCALING && orig_dn_mode == SUBSAMPLING)) { |
---|
.. | .. |
---|
1724 | 1840 | sensor->last_mode = &ov5640_mode_init_data; |
---|
1725 | 1841 | |
---|
1726 | 1842 | ret = ov5640_mod_reg(sensor, OV5640_REG_SYS_ROOT_DIVIDER, 0x3f, |
---|
1727 | | - (ilog2(OV5640_SCLK2X_ROOT_DIVIDER_DEFAULT) << 2) | |
---|
1728 | | - ilog2(OV5640_SCLK_ROOT_DIVIDER_DEFAULT)); |
---|
| 1843 | + (ilog2(OV5640_SCLK2X_ROOT_DIV) << 2) | |
---|
| 1844 | + ilog2(OV5640_SCLK_ROOT_DIV)); |
---|
1729 | 1845 | if (ret) |
---|
1730 | 1846 | return ret; |
---|
1731 | 1847 | |
---|
.. | .. |
---|
1806 | 1922 | clk_disable_unprepare(sensor->xclk); |
---|
1807 | 1923 | } |
---|
1808 | 1924 | |
---|
| 1925 | +static int ov5640_set_power_mipi(struct ov5640_dev *sensor, bool on) |
---|
| 1926 | +{ |
---|
| 1927 | + int ret; |
---|
| 1928 | + |
---|
| 1929 | + if (!on) { |
---|
| 1930 | + /* Reset MIPI bus settings to their default values. */ |
---|
| 1931 | + ov5640_write_reg(sensor, OV5640_REG_IO_MIPI_CTRL00, 0x58); |
---|
| 1932 | + ov5640_write_reg(sensor, OV5640_REG_MIPI_CTRL00, 0x04); |
---|
| 1933 | + ov5640_write_reg(sensor, OV5640_REG_PAD_OUTPUT00, 0x00); |
---|
| 1934 | + return 0; |
---|
| 1935 | + } |
---|
| 1936 | + |
---|
| 1937 | + /* |
---|
| 1938 | + * Power up MIPI HS Tx and LS Rx; 2 data lanes mode |
---|
| 1939 | + * |
---|
| 1940 | + * 0x300e = 0x40 |
---|
| 1941 | + * [7:5] = 010 : 2 data lanes mode (see FIXME note in |
---|
| 1942 | + * "ov5640_set_stream_mipi()") |
---|
| 1943 | + * [4] = 0 : Power up MIPI HS Tx |
---|
| 1944 | + * [3] = 0 : Power up MIPI LS Rx |
---|
| 1945 | + * [2] = 0 : MIPI interface disabled |
---|
| 1946 | + */ |
---|
| 1947 | + ret = ov5640_write_reg(sensor, OV5640_REG_IO_MIPI_CTRL00, 0x40); |
---|
| 1948 | + if (ret) |
---|
| 1949 | + return ret; |
---|
| 1950 | + |
---|
| 1951 | + /* |
---|
| 1952 | + * Gate clock and set LP11 in 'no packets mode' (idle) |
---|
| 1953 | + * |
---|
| 1954 | + * 0x4800 = 0x24 |
---|
| 1955 | + * [5] = 1 : Gate clock when 'no packets' |
---|
| 1956 | + * [2] = 1 : MIPI bus in LP11 when 'no packets' |
---|
| 1957 | + */ |
---|
| 1958 | + ret = ov5640_write_reg(sensor, OV5640_REG_MIPI_CTRL00, 0x24); |
---|
| 1959 | + if (ret) |
---|
| 1960 | + return ret; |
---|
| 1961 | + |
---|
| 1962 | + /* |
---|
| 1963 | + * Set data lanes and clock in LP11 when 'sleeping' |
---|
| 1964 | + * |
---|
| 1965 | + * 0x3019 = 0x70 |
---|
| 1966 | + * [6] = 1 : MIPI data lane 2 in LP11 when 'sleeping' |
---|
| 1967 | + * [5] = 1 : MIPI data lane 1 in LP11 when 'sleeping' |
---|
| 1968 | + * [4] = 1 : MIPI clock lane in LP11 when 'sleeping' |
---|
| 1969 | + */ |
---|
| 1970 | + ret = ov5640_write_reg(sensor, OV5640_REG_PAD_OUTPUT00, 0x70); |
---|
| 1971 | + if (ret) |
---|
| 1972 | + return ret; |
---|
| 1973 | + |
---|
| 1974 | + /* Give lanes some time to coax into LP11 state. */ |
---|
| 1975 | + usleep_range(500, 1000); |
---|
| 1976 | + |
---|
| 1977 | + return 0; |
---|
| 1978 | +} |
---|
| 1979 | + |
---|
| 1980 | +static int ov5640_set_power_dvp(struct ov5640_dev *sensor, bool on) |
---|
| 1981 | +{ |
---|
| 1982 | + unsigned int flags = sensor->ep.bus.parallel.flags; |
---|
| 1983 | + bool bt656 = sensor->ep.bus_type == V4L2_MBUS_BT656; |
---|
| 1984 | + u8 polarities = 0; |
---|
| 1985 | + int ret; |
---|
| 1986 | + |
---|
| 1987 | + if (!on) { |
---|
| 1988 | + /* Reset settings to their default values. */ |
---|
| 1989 | + ov5640_write_reg(sensor, OV5640_REG_CCIR656_CTRL00, 0x00); |
---|
| 1990 | + ov5640_write_reg(sensor, OV5640_REG_IO_MIPI_CTRL00, 0x58); |
---|
| 1991 | + ov5640_write_reg(sensor, OV5640_REG_POLARITY_CTRL00, 0x20); |
---|
| 1992 | + ov5640_write_reg(sensor, OV5640_REG_PAD_OUTPUT_ENABLE01, 0x00); |
---|
| 1993 | + ov5640_write_reg(sensor, OV5640_REG_PAD_OUTPUT_ENABLE02, 0x00); |
---|
| 1994 | + return 0; |
---|
| 1995 | + } |
---|
| 1996 | + |
---|
| 1997 | + /* |
---|
| 1998 | + * Note about parallel port configuration. |
---|
| 1999 | + * |
---|
| 2000 | + * When configured in parallel mode, the OV5640 will |
---|
| 2001 | + * output 10 bits data on DVP data lines [9:0]. |
---|
| 2002 | + * If only 8 bits data are wanted, the 8 bits data lines |
---|
| 2003 | + * of the camera interface must be physically connected |
---|
| 2004 | + * on the DVP data lines [9:2]. |
---|
| 2005 | + * |
---|
| 2006 | + * Control lines polarity can be configured through |
---|
| 2007 | + * devicetree endpoint control lines properties. |
---|
| 2008 | + * If no endpoint control lines properties are set, |
---|
| 2009 | + * polarity will be as below: |
---|
| 2010 | + * - VSYNC: active high |
---|
| 2011 | + * - HREF: active low |
---|
| 2012 | + * - PCLK: active low |
---|
| 2013 | + * |
---|
| 2014 | + * VSYNC & HREF are not configured if BT656 bus mode is selected |
---|
| 2015 | + */ |
---|
| 2016 | + |
---|
| 2017 | + /* |
---|
| 2018 | + * BT656 embedded synchronization configuration |
---|
| 2019 | + * |
---|
| 2020 | + * CCIR656 CTRL00 |
---|
| 2021 | + * - [7]: SYNC code selection (0: auto generate sync code, |
---|
| 2022 | + * 1: sync code from regs 0x4732-0x4735) |
---|
| 2023 | + * - [6]: f value in CCIR656 SYNC code when fixed f value |
---|
| 2024 | + * - [5]: Fixed f value |
---|
| 2025 | + * - [4:3]: Blank toggle data options (00: data=1'h040/1'h200, |
---|
| 2026 | + * 01: data from regs 0x4736-0x4738, 10: always keep 0) |
---|
| 2027 | + * - [1]: Clip data disable |
---|
| 2028 | + * - [0]: CCIR656 mode enable |
---|
| 2029 | + * |
---|
| 2030 | + * Default CCIR656 SAV/EAV mode with default codes |
---|
| 2031 | + * SAV=0xff000080 & EAV=0xff00009d is enabled here with settings: |
---|
| 2032 | + * - CCIR656 mode enable |
---|
| 2033 | + * - auto generation of sync codes |
---|
| 2034 | + * - blank toggle data 1'h040/1'h200 |
---|
| 2035 | + * - clip reserved data (0x00 & 0xff changed to 0x01 & 0xfe) |
---|
| 2036 | + */ |
---|
| 2037 | + ret = ov5640_write_reg(sensor, OV5640_REG_CCIR656_CTRL00, |
---|
| 2038 | + bt656 ? 0x01 : 0x00); |
---|
| 2039 | + if (ret) |
---|
| 2040 | + return ret; |
---|
| 2041 | + |
---|
| 2042 | + /* |
---|
| 2043 | + * configure parallel port control lines polarity |
---|
| 2044 | + * |
---|
| 2045 | + * POLARITY CTRL0 |
---|
| 2046 | + * - [5]: PCLK polarity (0: active low, 1: active high) |
---|
| 2047 | + * - [1]: HREF polarity (0: active low, 1: active high) |
---|
| 2048 | + * - [0]: VSYNC polarity (mismatch here between |
---|
| 2049 | + * datasheet and hardware, 0 is active high |
---|
| 2050 | + * and 1 is active low...) |
---|
| 2051 | + */ |
---|
| 2052 | + if (!bt656) { |
---|
| 2053 | + if (flags & V4L2_MBUS_HSYNC_ACTIVE_HIGH) |
---|
| 2054 | + polarities |= BIT(1); |
---|
| 2055 | + if (flags & V4L2_MBUS_VSYNC_ACTIVE_LOW) |
---|
| 2056 | + polarities |= BIT(0); |
---|
| 2057 | + } |
---|
| 2058 | + if (flags & V4L2_MBUS_PCLK_SAMPLE_RISING) |
---|
| 2059 | + polarities |= BIT(5); |
---|
| 2060 | + |
---|
| 2061 | + ret = ov5640_write_reg(sensor, OV5640_REG_POLARITY_CTRL00, polarities); |
---|
| 2062 | + if (ret) |
---|
| 2063 | + return ret; |
---|
| 2064 | + |
---|
| 2065 | + /* |
---|
| 2066 | + * powerdown MIPI TX/RX PHY & enable DVP |
---|
| 2067 | + * |
---|
| 2068 | + * MIPI CONTROL 00 |
---|
| 2069 | + * [4] = 1 : Power down MIPI HS Tx |
---|
| 2070 | + * [3] = 1 : Power down MIPI LS Rx |
---|
| 2071 | + * [2] = 0 : DVP enable (MIPI disable) |
---|
| 2072 | + */ |
---|
| 2073 | + ret = ov5640_write_reg(sensor, OV5640_REG_IO_MIPI_CTRL00, 0x18); |
---|
| 2074 | + if (ret) |
---|
| 2075 | + return ret; |
---|
| 2076 | + |
---|
| 2077 | + /* |
---|
| 2078 | + * enable VSYNC/HREF/PCLK DVP control lines |
---|
| 2079 | + * & D[9:6] DVP data lines |
---|
| 2080 | + * |
---|
| 2081 | + * PAD OUTPUT ENABLE 01 |
---|
| 2082 | + * - 6: VSYNC output enable |
---|
| 2083 | + * - 5: HREF output enable |
---|
| 2084 | + * - 4: PCLK output enable |
---|
| 2085 | + * - [3:0]: D[9:6] output enable |
---|
| 2086 | + */ |
---|
| 2087 | + ret = ov5640_write_reg(sensor, OV5640_REG_PAD_OUTPUT_ENABLE01, |
---|
| 2088 | + bt656 ? 0x1f : 0x7f); |
---|
| 2089 | + if (ret) |
---|
| 2090 | + return ret; |
---|
| 2091 | + |
---|
| 2092 | + /* |
---|
| 2093 | + * enable D[5:0] DVP data lines |
---|
| 2094 | + * |
---|
| 2095 | + * PAD OUTPUT ENABLE 02 |
---|
| 2096 | + * - [7:2]: D[5:0] output enable |
---|
| 2097 | + */ |
---|
| 2098 | + return ov5640_write_reg(sensor, OV5640_REG_PAD_OUTPUT_ENABLE02, 0xfc); |
---|
| 2099 | +} |
---|
| 2100 | + |
---|
1809 | 2101 | static int ov5640_set_power(struct ov5640_dev *sensor, bool on) |
---|
1810 | 2102 | { |
---|
1811 | 2103 | int ret = 0; |
---|
.. | .. |
---|
1818 | 2110 | ret = ov5640_restore_mode(sensor); |
---|
1819 | 2111 | if (ret) |
---|
1820 | 2112 | goto power_off; |
---|
1821 | | - |
---|
1822 | | - /* We're done here for DVP bus, while CSI-2 needs setup. */ |
---|
1823 | | - if (sensor->ep.bus_type != V4L2_MBUS_CSI2) |
---|
1824 | | - return 0; |
---|
1825 | | - |
---|
1826 | | - /* |
---|
1827 | | - * Power up MIPI HS Tx and LS Rx; 2 data lanes mode |
---|
1828 | | - * |
---|
1829 | | - * 0x300e = 0x40 |
---|
1830 | | - * [7:5] = 010 : 2 data lanes mode (see FIXME note in |
---|
1831 | | - * "ov5640_set_stream_mipi()") |
---|
1832 | | - * [4] = 0 : Power up MIPI HS Tx |
---|
1833 | | - * [3] = 0 : Power up MIPI LS Rx |
---|
1834 | | - * [2] = 0 : MIPI interface disabled |
---|
1835 | | - */ |
---|
1836 | | - ret = ov5640_write_reg(sensor, |
---|
1837 | | - OV5640_REG_IO_MIPI_CTRL00, 0x40); |
---|
1838 | | - if (ret) |
---|
1839 | | - goto power_off; |
---|
1840 | | - |
---|
1841 | | - /* |
---|
1842 | | - * Gate clock and set LP11 in 'no packets mode' (idle) |
---|
1843 | | - * |
---|
1844 | | - * 0x4800 = 0x24 |
---|
1845 | | - * [5] = 1 : Gate clock when 'no packets' |
---|
1846 | | - * [2] = 1 : MIPI bus in LP11 when 'no packets' |
---|
1847 | | - */ |
---|
1848 | | - ret = ov5640_write_reg(sensor, |
---|
1849 | | - OV5640_REG_MIPI_CTRL00, 0x24); |
---|
1850 | | - if (ret) |
---|
1851 | | - goto power_off; |
---|
1852 | | - |
---|
1853 | | - /* |
---|
1854 | | - * Set data lanes and clock in LP11 when 'sleeping' |
---|
1855 | | - * |
---|
1856 | | - * 0x3019 = 0x70 |
---|
1857 | | - * [6] = 1 : MIPI data lane 2 in LP11 when 'sleeping' |
---|
1858 | | - * [5] = 1 : MIPI data lane 1 in LP11 when 'sleeping' |
---|
1859 | | - * [4] = 1 : MIPI clock lane in LP11 when 'sleeping' |
---|
1860 | | - */ |
---|
1861 | | - ret = ov5640_write_reg(sensor, |
---|
1862 | | - OV5640_REG_PAD_OUTPUT00, 0x70); |
---|
1863 | | - if (ret) |
---|
1864 | | - goto power_off; |
---|
1865 | | - |
---|
1866 | | - /* Give lanes some time to coax into LP11 state. */ |
---|
1867 | | - usleep_range(500, 1000); |
---|
1868 | | - |
---|
1869 | | - } else { |
---|
1870 | | - if (sensor->ep.bus_type == V4L2_MBUS_CSI2) { |
---|
1871 | | - /* Reset MIPI bus settings to their default values. */ |
---|
1872 | | - ov5640_write_reg(sensor, |
---|
1873 | | - OV5640_REG_IO_MIPI_CTRL00, 0x58); |
---|
1874 | | - ov5640_write_reg(sensor, |
---|
1875 | | - OV5640_REG_MIPI_CTRL00, 0x04); |
---|
1876 | | - ov5640_write_reg(sensor, |
---|
1877 | | - OV5640_REG_PAD_OUTPUT00, 0x00); |
---|
1878 | | - } |
---|
1879 | | - |
---|
1880 | | - ov5640_set_power_off(sensor); |
---|
1881 | 2113 | } |
---|
| 2114 | + |
---|
| 2115 | + if (sensor->ep.bus_type == V4L2_MBUS_CSI2_DPHY) |
---|
| 2116 | + ret = ov5640_set_power_mipi(sensor, on); |
---|
| 2117 | + else |
---|
| 2118 | + ret = ov5640_set_power_dvp(sensor, on); |
---|
| 2119 | + if (ret) |
---|
| 2120 | + goto power_off; |
---|
| 2121 | + |
---|
| 2122 | + if (!on) |
---|
| 2123 | + ov5640_set_power_off(sensor); |
---|
1882 | 2124 | |
---|
1883 | 2125 | return 0; |
---|
1884 | 2126 | |
---|
.. | .. |
---|
1925 | 2167 | u32 width, u32 height) |
---|
1926 | 2168 | { |
---|
1927 | 2169 | const struct ov5640_mode_info *mode; |
---|
1928 | | - u32 minfps, maxfps, fps; |
---|
1929 | | - int ret; |
---|
| 2170 | + enum ov5640_frame_rate rate = OV5640_15_FPS; |
---|
| 2171 | + int minfps, maxfps, best_fps, fps; |
---|
| 2172 | + int i; |
---|
1930 | 2173 | |
---|
1931 | 2174 | minfps = ov5640_framerates[OV5640_15_FPS]; |
---|
1932 | | - maxfps = ov5640_framerates[OV5640_30_FPS]; |
---|
| 2175 | + maxfps = ov5640_framerates[OV5640_60_FPS]; |
---|
1933 | 2176 | |
---|
1934 | 2177 | if (fi->numerator == 0) { |
---|
1935 | 2178 | fi->denominator = maxfps; |
---|
1936 | 2179 | fi->numerator = 1; |
---|
1937 | | - return OV5640_30_FPS; |
---|
| 2180 | + rate = OV5640_60_FPS; |
---|
| 2181 | + goto find_mode; |
---|
1938 | 2182 | } |
---|
1939 | 2183 | |
---|
1940 | | - fps = DIV_ROUND_CLOSEST(fi->denominator, fi->numerator); |
---|
| 2184 | + fps = clamp_val(DIV_ROUND_CLOSEST(fi->denominator, fi->numerator), |
---|
| 2185 | + minfps, maxfps); |
---|
| 2186 | + |
---|
| 2187 | + best_fps = minfps; |
---|
| 2188 | + for (i = 0; i < ARRAY_SIZE(ov5640_framerates); i++) { |
---|
| 2189 | + int curr_fps = ov5640_framerates[i]; |
---|
| 2190 | + |
---|
| 2191 | + if (abs(curr_fps - fps) < abs(best_fps - fps)) { |
---|
| 2192 | + best_fps = curr_fps; |
---|
| 2193 | + rate = i; |
---|
| 2194 | + } |
---|
| 2195 | + } |
---|
1941 | 2196 | |
---|
1942 | 2197 | fi->numerator = 1; |
---|
1943 | | - if (fps > maxfps) |
---|
1944 | | - fi->denominator = maxfps; |
---|
1945 | | - else if (fps < minfps) |
---|
1946 | | - fi->denominator = minfps; |
---|
1947 | | - else if (2 * fps >= 2 * minfps + (maxfps - minfps)) |
---|
1948 | | - fi->denominator = maxfps; |
---|
1949 | | - else |
---|
1950 | | - fi->denominator = minfps; |
---|
| 2198 | + fi->denominator = best_fps; |
---|
1951 | 2199 | |
---|
1952 | | - ret = (fi->denominator == minfps) ? OV5640_15_FPS : OV5640_30_FPS; |
---|
1953 | | - |
---|
1954 | | - mode = ov5640_find_mode(sensor, ret, width, height, false); |
---|
1955 | | - return mode ? ret : -EINVAL; |
---|
| 2200 | +find_mode: |
---|
| 2201 | + mode = ov5640_find_mode(sensor, rate, width, height, false); |
---|
| 2202 | + return mode ? rate : -EINVAL; |
---|
1956 | 2203 | } |
---|
1957 | 2204 | |
---|
1958 | 2205 | static int ov5640_get_fmt(struct v4l2_subdev *sd, |
---|
.. | .. |
---|
2052 | 2299 | if (mbus_fmt->code != sensor->fmt.code) |
---|
2053 | 2300 | sensor->pending_fmt_change = true; |
---|
2054 | 2301 | |
---|
| 2302 | + __v4l2_ctrl_s_ctrl_int64(sensor->ctrls.pixel_rate, |
---|
| 2303 | + ov5640_calc_pixel_rate(sensor)); |
---|
2055 | 2304 | out: |
---|
2056 | 2305 | mutex_unlock(&sensor->lock); |
---|
2057 | 2306 | return ret; |
---|
.. | .. |
---|
2061 | 2310 | struct v4l2_mbus_framefmt *format) |
---|
2062 | 2311 | { |
---|
2063 | 2312 | int ret = 0; |
---|
2064 | | - bool is_rgb = false; |
---|
2065 | 2313 | bool is_jpeg = false; |
---|
2066 | | - u8 val; |
---|
| 2314 | + u8 fmt, mux; |
---|
2067 | 2315 | |
---|
2068 | 2316 | switch (format->code) { |
---|
2069 | 2317 | case MEDIA_BUS_FMT_UYVY8_2X8: |
---|
2070 | 2318 | /* YUV422, UYVY */ |
---|
2071 | | - val = 0x3f; |
---|
| 2319 | + fmt = 0x3f; |
---|
| 2320 | + mux = OV5640_FMT_MUX_YUV422; |
---|
2072 | 2321 | break; |
---|
2073 | 2322 | case MEDIA_BUS_FMT_YUYV8_2X8: |
---|
2074 | 2323 | /* YUV422, YUYV */ |
---|
2075 | | - val = 0x30; |
---|
| 2324 | + fmt = 0x30; |
---|
| 2325 | + mux = OV5640_FMT_MUX_YUV422; |
---|
2076 | 2326 | break; |
---|
2077 | 2327 | case MEDIA_BUS_FMT_RGB565_2X8_LE: |
---|
2078 | 2328 | /* RGB565 {g[2:0],b[4:0]},{r[4:0],g[5:3]} */ |
---|
2079 | | - val = 0x6F; |
---|
2080 | | - is_rgb = true; |
---|
| 2329 | + fmt = 0x6F; |
---|
| 2330 | + mux = OV5640_FMT_MUX_RGB; |
---|
2081 | 2331 | break; |
---|
2082 | 2332 | case MEDIA_BUS_FMT_RGB565_2X8_BE: |
---|
2083 | 2333 | /* RGB565 {r[4:0],g[5:3]},{g[2:0],b[4:0]} */ |
---|
2084 | | - val = 0x61; |
---|
2085 | | - is_rgb = true; |
---|
| 2334 | + fmt = 0x61; |
---|
| 2335 | + mux = OV5640_FMT_MUX_RGB; |
---|
2086 | 2336 | break; |
---|
2087 | 2337 | case MEDIA_BUS_FMT_JPEG_1X8: |
---|
2088 | 2338 | /* YUV422, YUYV */ |
---|
2089 | | - val = 0x30; |
---|
| 2339 | + fmt = 0x30; |
---|
| 2340 | + mux = OV5640_FMT_MUX_YUV422; |
---|
2090 | 2341 | is_jpeg = true; |
---|
| 2342 | + break; |
---|
| 2343 | + case MEDIA_BUS_FMT_SBGGR8_1X8: |
---|
| 2344 | + /* Raw, BGBG... / GRGR... */ |
---|
| 2345 | + fmt = 0x00; |
---|
| 2346 | + mux = OV5640_FMT_MUX_RAW_DPC; |
---|
| 2347 | + break; |
---|
| 2348 | + case MEDIA_BUS_FMT_SGBRG8_1X8: |
---|
| 2349 | + /* Raw bayer, GBGB... / RGRG... */ |
---|
| 2350 | + fmt = 0x01; |
---|
| 2351 | + mux = OV5640_FMT_MUX_RAW_DPC; |
---|
| 2352 | + break; |
---|
| 2353 | + case MEDIA_BUS_FMT_SGRBG8_1X8: |
---|
| 2354 | + /* Raw bayer, GRGR... / BGBG... */ |
---|
| 2355 | + fmt = 0x02; |
---|
| 2356 | + mux = OV5640_FMT_MUX_RAW_DPC; |
---|
| 2357 | + break; |
---|
| 2358 | + case MEDIA_BUS_FMT_SRGGB8_1X8: |
---|
| 2359 | + /* Raw bayer, RGRG... / GBGB... */ |
---|
| 2360 | + fmt = 0x03; |
---|
| 2361 | + mux = OV5640_FMT_MUX_RAW_DPC; |
---|
2091 | 2362 | break; |
---|
2092 | 2363 | default: |
---|
2093 | 2364 | return -EINVAL; |
---|
2094 | 2365 | } |
---|
2095 | 2366 | |
---|
2096 | 2367 | /* FORMAT CONTROL00: YUV and RGB formatting */ |
---|
2097 | | - ret = ov5640_write_reg(sensor, OV5640_REG_FORMAT_CONTROL00, val); |
---|
| 2368 | + ret = ov5640_write_reg(sensor, OV5640_REG_FORMAT_CONTROL00, fmt); |
---|
2098 | 2369 | if (ret) |
---|
2099 | 2370 | return ret; |
---|
2100 | 2371 | |
---|
2101 | 2372 | /* FORMAT MUX CONTROL: ISP YUV or RGB */ |
---|
2102 | | - ret = ov5640_write_reg(sensor, OV5640_REG_ISP_FORMAT_MUX_CTRL, |
---|
2103 | | - is_rgb ? 0x01 : 0x00); |
---|
| 2373 | + ret = ov5640_write_reg(sensor, OV5640_REG_ISP_FORMAT_MUX_CTRL, mux); |
---|
2104 | 2374 | if (ret) |
---|
2105 | 2375 | return ret; |
---|
2106 | 2376 | |
---|
.. | .. |
---|
2268 | 2538 | return ret; |
---|
2269 | 2539 | } |
---|
2270 | 2540 | |
---|
| 2541 | +static const char * const test_pattern_menu[] = { |
---|
| 2542 | + "Disabled", |
---|
| 2543 | + "Color bars", |
---|
| 2544 | + "Color bars w/ rolling bar", |
---|
| 2545 | + "Color squares", |
---|
| 2546 | + "Color squares w/ rolling bar", |
---|
| 2547 | +}; |
---|
| 2548 | + |
---|
| 2549 | +#define OV5640_TEST_ENABLE BIT(7) |
---|
| 2550 | +#define OV5640_TEST_ROLLING BIT(6) /* rolling horizontal bar */ |
---|
| 2551 | +#define OV5640_TEST_TRANSPARENT BIT(5) |
---|
| 2552 | +#define OV5640_TEST_SQUARE_BW BIT(4) /* black & white squares */ |
---|
| 2553 | +#define OV5640_TEST_BAR_STANDARD (0 << 2) |
---|
| 2554 | +#define OV5640_TEST_BAR_VERT_CHANGE_1 (1 << 2) |
---|
| 2555 | +#define OV5640_TEST_BAR_HOR_CHANGE (2 << 2) |
---|
| 2556 | +#define OV5640_TEST_BAR_VERT_CHANGE_2 (3 << 2) |
---|
| 2557 | +#define OV5640_TEST_BAR (0 << 0) |
---|
| 2558 | +#define OV5640_TEST_RANDOM (1 << 0) |
---|
| 2559 | +#define OV5640_TEST_SQUARE (2 << 0) |
---|
| 2560 | +#define OV5640_TEST_BLACK (3 << 0) |
---|
| 2561 | + |
---|
| 2562 | +static const u8 test_pattern_val[] = { |
---|
| 2563 | + 0, |
---|
| 2564 | + OV5640_TEST_ENABLE | OV5640_TEST_BAR_VERT_CHANGE_1 | |
---|
| 2565 | + OV5640_TEST_BAR, |
---|
| 2566 | + OV5640_TEST_ENABLE | OV5640_TEST_ROLLING | |
---|
| 2567 | + OV5640_TEST_BAR_VERT_CHANGE_1 | OV5640_TEST_BAR, |
---|
| 2568 | + OV5640_TEST_ENABLE | OV5640_TEST_SQUARE, |
---|
| 2569 | + OV5640_TEST_ENABLE | OV5640_TEST_ROLLING | OV5640_TEST_SQUARE, |
---|
| 2570 | +}; |
---|
| 2571 | + |
---|
2271 | 2572 | static int ov5640_set_ctrl_test_pattern(struct ov5640_dev *sensor, int value) |
---|
2272 | 2573 | { |
---|
2273 | | - return ov5640_mod_reg(sensor, OV5640_REG_PRE_ISP_TEST_SET1, |
---|
2274 | | - 0xa4, value ? 0xa4 : 0); |
---|
| 2574 | + return ov5640_write_reg(sensor, OV5640_REG_PRE_ISP_TEST_SET1, |
---|
| 2575 | + test_pattern_val[value]); |
---|
2275 | 2576 | } |
---|
2276 | 2577 | |
---|
2277 | 2578 | static int ov5640_set_ctrl_light_freq(struct ov5640_dev *sensor, int value) |
---|
.. | .. |
---|
2412 | 2713 | .s_ctrl = ov5640_s_ctrl, |
---|
2413 | 2714 | }; |
---|
2414 | 2715 | |
---|
2415 | | -static const char * const test_pattern_menu[] = { |
---|
2416 | | - "Disabled", |
---|
2417 | | - "Color bars", |
---|
2418 | | -}; |
---|
2419 | | - |
---|
2420 | 2716 | static int ov5640_init_controls(struct ov5640_dev *sensor) |
---|
2421 | 2717 | { |
---|
2422 | 2718 | const struct v4l2_ctrl_ops *ops = &ov5640_ctrl_ops; |
---|
.. | .. |
---|
2428 | 2724 | |
---|
2429 | 2725 | /* we can use our own mutex for the ctrl lock */ |
---|
2430 | 2726 | hdl->lock = &sensor->lock; |
---|
| 2727 | + |
---|
| 2728 | + /* Clock related controls */ |
---|
| 2729 | + ctrls->pixel_rate = v4l2_ctrl_new_std(hdl, ops, V4L2_CID_PIXEL_RATE, |
---|
| 2730 | + 0, INT_MAX, 1, |
---|
| 2731 | + ov5640_calc_pixel_rate(sensor)); |
---|
2431 | 2732 | |
---|
2432 | 2733 | /* Auto/manual white balance */ |
---|
2433 | 2734 | ctrls->auto_wb = v4l2_ctrl_new_std(hdl, ops, |
---|
.. | .. |
---|
2476 | 2777 | goto free_ctrls; |
---|
2477 | 2778 | } |
---|
2478 | 2779 | |
---|
| 2780 | + ctrls->pixel_rate->flags |= V4L2_CTRL_FLAG_READ_ONLY; |
---|
2479 | 2781 | ctrls->gain->flags |= V4L2_CTRL_FLAG_VOLATILE; |
---|
2480 | 2782 | ctrls->exposure->flags |= V4L2_CTRL_FLAG_VOLATILE; |
---|
2481 | 2783 | |
---|
.. | .. |
---|
2501 | 2803 | return -EINVAL; |
---|
2502 | 2804 | |
---|
2503 | 2805 | fse->min_width = |
---|
2504 | | - ov5640_mode_data[0][fse->index].hact; |
---|
| 2806 | + ov5640_mode_data[fse->index].hact; |
---|
2505 | 2807 | fse->max_width = fse->min_width; |
---|
2506 | 2808 | fse->min_height = |
---|
2507 | | - ov5640_mode_data[0][fse->index].vact; |
---|
| 2809 | + ov5640_mode_data[fse->index].vact; |
---|
2508 | 2810 | fse->max_height = fse->min_height; |
---|
2509 | 2811 | |
---|
2510 | 2812 | return 0; |
---|
.. | .. |
---|
2569 | 2871 | |
---|
2570 | 2872 | frame_rate = ov5640_try_frame_interval(sensor, &fi->interval, |
---|
2571 | 2873 | mode->hact, mode->vact); |
---|
2572 | | - if (frame_rate < 0) |
---|
2573 | | - frame_rate = OV5640_15_FPS; |
---|
| 2874 | + if (frame_rate < 0) { |
---|
| 2875 | + /* Always return a valid frame interval value */ |
---|
| 2876 | + fi->interval = sensor->frame_interval; |
---|
| 2877 | + goto out; |
---|
| 2878 | + } |
---|
2574 | 2879 | |
---|
2575 | 2880 | mode = ov5640_find_mode(sensor, frame_rate, mode->hact, |
---|
2576 | 2881 | mode->vact, true); |
---|
.. | .. |
---|
2585 | 2890 | sensor->frame_interval = fi->interval; |
---|
2586 | 2891 | sensor->current_mode = mode; |
---|
2587 | 2892 | sensor->pending_mode_change = true; |
---|
| 2893 | + |
---|
| 2894 | + __v4l2_ctrl_s_ctrl_int64(sensor->ctrls.pixel_rate, |
---|
| 2895 | + ov5640_calc_pixel_rate(sensor)); |
---|
2588 | 2896 | } |
---|
2589 | 2897 | out: |
---|
2590 | 2898 | mutex_unlock(&sensor->lock); |
---|
.. | .. |
---|
2625 | 2933 | sensor->pending_fmt_change = false; |
---|
2626 | 2934 | } |
---|
2627 | 2935 | |
---|
2628 | | - if (sensor->ep.bus_type == V4L2_MBUS_CSI2) |
---|
| 2936 | + if (sensor->ep.bus_type == V4L2_MBUS_CSI2_DPHY) |
---|
2629 | 2937 | ret = ov5640_set_stream_mipi(sensor, enable); |
---|
2630 | 2938 | else |
---|
2631 | 2939 | ret = ov5640_set_stream_dvp(sensor, enable); |
---|
.. | .. |
---|
2640 | 2948 | |
---|
2641 | 2949 | static const struct v4l2_subdev_core_ops ov5640_core_ops = { |
---|
2642 | 2950 | .s_power = ov5640_s_power, |
---|
| 2951 | + .log_status = v4l2_ctrl_subdev_log_status, |
---|
| 2952 | + .subscribe_event = v4l2_ctrl_subdev_subscribe_event, |
---|
| 2953 | + .unsubscribe_event = v4l2_event_subdev_unsubscribe, |
---|
2643 | 2954 | }; |
---|
2644 | 2955 | |
---|
2645 | 2956 | static const struct v4l2_subdev_video_ops ov5640_video_ops = { |
---|
.. | .. |
---|
2702 | 3013 | return ret; |
---|
2703 | 3014 | } |
---|
2704 | 3015 | |
---|
2705 | | -static int ov5640_probe(struct i2c_client *client, |
---|
2706 | | - const struct i2c_device_id *id) |
---|
| 3016 | +static int ov5640_probe(struct i2c_client *client) |
---|
2707 | 3017 | { |
---|
2708 | 3018 | struct device *dev = &client->dev; |
---|
2709 | 3019 | struct fwnode_handle *endpoint; |
---|
.. | .. |
---|
2735 | 3045 | sensor->frame_interval.denominator = ov5640_framerates[OV5640_30_FPS]; |
---|
2736 | 3046 | sensor->current_fr = OV5640_30_FPS; |
---|
2737 | 3047 | sensor->current_mode = |
---|
2738 | | - &ov5640_mode_data[OV5640_30_FPS][OV5640_MODE_VGA_640_480]; |
---|
| 3048 | + &ov5640_mode_data[OV5640_MODE_VGA_640_480]; |
---|
2739 | 3049 | sensor->last_mode = sensor->current_mode; |
---|
2740 | 3050 | |
---|
2741 | 3051 | sensor->ae_target = 52; |
---|
.. | .. |
---|
2747 | 3057 | switch (rotation) { |
---|
2748 | 3058 | case 180: |
---|
2749 | 3059 | sensor->upside_down = true; |
---|
2750 | | - /* fall through */ |
---|
| 3060 | + fallthrough; |
---|
2751 | 3061 | case 0: |
---|
2752 | 3062 | break; |
---|
2753 | 3063 | default: |
---|
.. | .. |
---|
2768 | 3078 | if (ret) { |
---|
2769 | 3079 | dev_err(dev, "Could not parse endpoint\n"); |
---|
2770 | 3080 | return ret; |
---|
| 3081 | + } |
---|
| 3082 | + |
---|
| 3083 | + if (sensor->ep.bus_type != V4L2_MBUS_PARALLEL && |
---|
| 3084 | + sensor->ep.bus_type != V4L2_MBUS_CSI2_DPHY && |
---|
| 3085 | + sensor->ep.bus_type != V4L2_MBUS_BT656) { |
---|
| 3086 | + dev_err(dev, "Unsupported bus type %d\n", sensor->ep.bus_type); |
---|
| 3087 | + return -EINVAL; |
---|
2771 | 3088 | } |
---|
2772 | 3089 | |
---|
2773 | 3090 | /* get system clock (xclk) */ |
---|
.. | .. |
---|
2799 | 3116 | |
---|
2800 | 3117 | v4l2_i2c_subdev_init(&sensor->sd, client, &ov5640_subdev_ops); |
---|
2801 | 3118 | |
---|
2802 | | - sensor->sd.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE; |
---|
| 3119 | + sensor->sd.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE | |
---|
| 3120 | + V4L2_SUBDEV_FL_HAS_EVENTS; |
---|
2803 | 3121 | sensor->pad.flags = MEDIA_PAD_FL_SOURCE; |
---|
2804 | 3122 | sensor->sd.entity.function = MEDIA_ENT_F_CAM_SENSOR; |
---|
2805 | 3123 | ret = media_entity_pads_init(&sensor->sd.entity, 1, &sensor->pad); |
---|
.. | .. |
---|
2820 | 3138 | if (ret) |
---|
2821 | 3139 | goto entity_cleanup; |
---|
2822 | 3140 | |
---|
2823 | | - ret = v4l2_async_register_subdev(&sensor->sd); |
---|
| 3141 | + ret = v4l2_async_register_subdev_sensor_common(&sensor->sd); |
---|
2824 | 3142 | if (ret) |
---|
2825 | 3143 | goto free_ctrls; |
---|
2826 | 3144 | |
---|
.. | .. |
---|
2865 | 3183 | .of_match_table = ov5640_dt_ids, |
---|
2866 | 3184 | }, |
---|
2867 | 3185 | .id_table = ov5640_id, |
---|
2868 | | - .probe = ov5640_probe, |
---|
| 3186 | + .probe_new = ov5640_probe, |
---|
2869 | 3187 | .remove = ov5640_remove, |
---|
2870 | 3188 | }; |
---|
2871 | 3189 | |
---|