2 * Copyright (C) 2011-2013 Freescale Semiconductor, Inc. All Rights Reserved.
3 * Copyright (C) 2014-2017 Mentor Graphics Inc.
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.
11 #include <linux/clk.h>
12 #include <linux/clk-provider.h>
13 #include <linux/clkdev.h>
14 #include <linux/ctype.h>
15 #include <linux/delay.h>
16 #include <linux/device.h>
17 #include <linux/i2c.h>
18 #include <linux/init.h>
19 #include <linux/module.h>
20 #include <linux/of_device.h>
21 #include <linux/slab.h>
22 #include <linux/types.h>
23 #include <linux/gpio/consumer.h>
24 #include <linux/regulator/consumer.h>
25 #include <media/v4l2-async.h>
26 #include <media/v4l2-ctrls.h>
27 #include <media/v4l2-device.h>
28 #include <media/v4l2-fwnode.h>
29 #include <media/v4l2-subdev.h>
31 /* min/typical/max system clock (xclk) frequencies */
32 #define OV5640_XCLK_MIN 6000000
33 #define OV5640_XCLK_MAX 24000000
35 #define OV5640_DEFAULT_SLAVE_ID 0x3c
37 #define OV5640_REG_SYS_CTRL0 0x3008
38 #define OV5640_REG_CHIP_ID 0x300a
39 #define OV5640_REG_IO_MIPI_CTRL00 0x300e
40 #define OV5640_REG_PAD_OUTPUT_ENABLE01 0x3017
41 #define OV5640_REG_PAD_OUTPUT_ENABLE02 0x3018
42 #define OV5640_REG_PAD_OUTPUT00 0x3019
43 #define OV5640_REG_SYSTEM_CONTROL1 0x302e
44 #define OV5640_REG_SC_PLL_CTRL0 0x3034
45 #define OV5640_REG_SC_PLL_CTRL1 0x3035
46 #define OV5640_REG_SC_PLL_CTRL2 0x3036
47 #define OV5640_REG_SC_PLL_CTRL3 0x3037
48 #define OV5640_REG_SLAVE_ID 0x3100
49 #define OV5640_REG_SCCB_SYS_CTRL1 0x3103
50 #define OV5640_REG_SYS_ROOT_DIVIDER 0x3108
51 #define OV5640_REG_AWB_R_GAIN 0x3400
52 #define OV5640_REG_AWB_G_GAIN 0x3402
53 #define OV5640_REG_AWB_B_GAIN 0x3404
54 #define OV5640_REG_AWB_MANUAL_CTRL 0x3406
55 #define OV5640_REG_AEC_PK_EXPOSURE_HI 0x3500
56 #define OV5640_REG_AEC_PK_EXPOSURE_MED 0x3501
57 #define OV5640_REG_AEC_PK_EXPOSURE_LO 0x3502
58 #define OV5640_REG_AEC_PK_MANUAL 0x3503
59 #define OV5640_REG_AEC_PK_REAL_GAIN 0x350a
60 #define OV5640_REG_AEC_PK_VTS 0x350c
61 #define OV5640_REG_TIMING_HTS 0x380c
62 #define OV5640_REG_TIMING_VTS 0x380e
63 #define OV5640_REG_TIMING_TC_REG21 0x3821
64 #define OV5640_REG_AEC_CTRL00 0x3a00
65 #define OV5640_REG_AEC_B50_STEP 0x3a08
66 #define OV5640_REG_AEC_B60_STEP 0x3a0a
67 #define OV5640_REG_AEC_CTRL0D 0x3a0d
68 #define OV5640_REG_AEC_CTRL0E 0x3a0e
69 #define OV5640_REG_AEC_CTRL0F 0x3a0f
70 #define OV5640_REG_AEC_CTRL10 0x3a10
71 #define OV5640_REG_AEC_CTRL11 0x3a11
72 #define OV5640_REG_AEC_CTRL1B 0x3a1b
73 #define OV5640_REG_AEC_CTRL1E 0x3a1e
74 #define OV5640_REG_AEC_CTRL1F 0x3a1f
75 #define OV5640_REG_HZ5060_CTRL00 0x3c00
76 #define OV5640_REG_HZ5060_CTRL01 0x3c01
77 #define OV5640_REG_SIGMADELTA_CTRL0C 0x3c0c
78 #define OV5640_REG_FRAME_CTRL01 0x4202
79 #define OV5640_REG_FORMAT_CONTROL00 0x4300
80 #define OV5640_REG_POLARITY_CTRL00 0x4740
81 #define OV5640_REG_MIPI_CTRL00 0x4800
82 #define OV5640_REG_DEBUG_MODE 0x4814
83 #define OV5640_REG_ISP_FORMAT_MUX_CTRL 0x501f
84 #define OV5640_REG_PRE_ISP_TEST_SET1 0x503d
85 #define OV5640_REG_SDE_CTRL0 0x5580
86 #define OV5640_REG_SDE_CTRL1 0x5581
87 #define OV5640_REG_SDE_CTRL3 0x5583
88 #define OV5640_REG_SDE_CTRL4 0x5584
89 #define OV5640_REG_SDE_CTRL5 0x5585
90 #define OV5640_REG_AVG_READOUT 0x56a1
93 OV5640_MODE_QCIF_176_144
= 0,
94 OV5640_MODE_QVGA_320_240
,
95 OV5640_MODE_VGA_640_480
,
96 OV5640_MODE_NTSC_720_480
,
97 OV5640_MODE_PAL_720_576
,
98 OV5640_MODE_XGA_1024_768
,
99 OV5640_MODE_720P_1280_720
,
100 OV5640_MODE_1080P_1920_1080
,
101 OV5640_MODE_QSXGA_2592_1944
,
105 enum ov5640_frame_rate
{
108 OV5640_NUM_FRAMERATES
,
111 struct ov5640_pixfmt
{
116 static const struct ov5640_pixfmt ov5640_formats
[] = {
117 { MEDIA_BUS_FMT_UYVY8_2X8
, V4L2_COLORSPACE_SRGB
, },
118 { MEDIA_BUS_FMT_YUYV8_2X8
, V4L2_COLORSPACE_SRGB
, },
119 { MEDIA_BUS_FMT_RGB565_2X8_LE
, V4L2_COLORSPACE_SRGB
, },
120 { MEDIA_BUS_FMT_RGB565_2X8_BE
, V4L2_COLORSPACE_SRGB
, },
124 * FIXME: remove this when a subdev API becomes available
125 * to set the MIPI CSI-2 virtual channel.
127 static unsigned int virtual_channel
;
128 module_param(virtual_channel
, int, 0);
129 MODULE_PARM_DESC(virtual_channel
,
130 "MIPI CSI-2 virtual channel (0..3), default 0");
132 static const int ov5640_framerates
[] = {
133 [OV5640_15_FPS
] = 15,
134 [OV5640_30_FPS
] = 30,
137 /* regulator supplies */
138 static const char * const ov5640_supply_name
[] = {
139 "DOVDD", /* Digital I/O (1.8V) suppply */
140 "DVDD", /* Digital Core (1.5V) supply */
141 "AVDD", /* Analog (2.8V) supply */
144 #define OV5640_NUM_SUPPLIES ARRAY_SIZE(ov5640_supply_name)
147 * Image size under 1280 * 960 are SUBSAMPLING
148 * Image size upper 1280 * 960 are SCALING
150 enum ov5640_downsize_mode
{
162 struct ov5640_mode_info
{
163 enum ov5640_mode_id id
;
164 enum ov5640_downsize_mode dn_mode
;
167 const struct reg_value
*reg_data
;
171 struct ov5640_ctrls
{
172 struct v4l2_ctrl_handler handler
;
174 struct v4l2_ctrl
*auto_exp
;
175 struct v4l2_ctrl
*exposure
;
178 struct v4l2_ctrl
*auto_wb
;
179 struct v4l2_ctrl
*blue_balance
;
180 struct v4l2_ctrl
*red_balance
;
183 struct v4l2_ctrl
*auto_gain
;
184 struct v4l2_ctrl
*gain
;
186 struct v4l2_ctrl
*brightness
;
187 struct v4l2_ctrl
*saturation
;
188 struct v4l2_ctrl
*contrast
;
189 struct v4l2_ctrl
*hue
;
190 struct v4l2_ctrl
*test_pattern
;
194 struct i2c_client
*i2c_client
;
195 struct v4l2_subdev sd
;
196 struct media_pad pad
;
197 struct v4l2_fwnode_endpoint ep
; /* the parsed DT endpoint info */
198 struct clk
*xclk
; /* system clock to OV5640 */
201 struct regulator_bulk_data supplies
[OV5640_NUM_SUPPLIES
];
202 struct gpio_desc
*reset_gpio
;
203 struct gpio_desc
*pwdn_gpio
;
205 /* lock to protect all members below */
210 struct v4l2_mbus_framefmt fmt
;
212 const struct ov5640_mode_info
*current_mode
;
213 enum ov5640_frame_rate current_fr
;
214 struct v4l2_fract frame_interval
;
216 struct ov5640_ctrls ctrls
;
218 u32 prev_sysclk
, prev_hts
;
219 u32 ae_low
, ae_high
, ae_target
;
221 bool pending_mode_change
;
225 static inline struct ov5640_dev
*to_ov5640_dev(struct v4l2_subdev
*sd
)
227 return container_of(sd
, struct ov5640_dev
, sd
);
230 static inline struct v4l2_subdev
*ctrl_to_sd(struct v4l2_ctrl
*ctrl
)
232 return &container_of(ctrl
->handler
, struct ov5640_dev
,
237 * FIXME: all of these register tables are likely filled with
238 * entries that set the register to their power-on default values,
239 * and which are otherwise not touched by this driver. Those entries
240 * should be identified and removed to speed register load time
244 static const struct reg_value ov5640_init_setting_30fps_VGA
[] = {
246 {0x3103, 0x11, 0, 0}, {0x3008, 0x82, 0, 5}, {0x3008, 0x42, 0, 0},
247 {0x3103, 0x03, 0, 0}, {0x3017, 0x00, 0, 0}, {0x3018, 0x00, 0, 0},
248 {0x3034, 0x18, 0, 0}, {0x3035, 0x14, 0, 0}, {0x3036, 0x38, 0, 0},
249 {0x3037, 0x13, 0, 0}, {0x3108, 0x01, 0, 0}, {0x3630, 0x36, 0, 0},
250 {0x3631, 0x0e, 0, 0}, {0x3632, 0xe2, 0, 0}, {0x3633, 0x12, 0, 0},
251 {0x3621, 0xe0, 0, 0}, {0x3704, 0xa0, 0, 0}, {0x3703, 0x5a, 0, 0},
252 {0x3715, 0x78, 0, 0}, {0x3717, 0x01, 0, 0}, {0x370b, 0x60, 0, 0},
253 {0x3705, 0x1a, 0, 0}, {0x3905, 0x02, 0, 0}, {0x3906, 0x10, 0, 0},
254 {0x3901, 0x0a, 0, 0}, {0x3731, 0x12, 0, 0}, {0x3600, 0x08, 0, 0},
255 {0x3601, 0x33, 0, 0}, {0x302d, 0x60, 0, 0}, {0x3620, 0x52, 0, 0},
256 {0x371b, 0x20, 0, 0}, {0x471c, 0x50, 0, 0}, {0x3a13, 0x43, 0, 0},
257 {0x3a18, 0x00, 0, 0}, {0x3a19, 0xf8, 0, 0}, {0x3635, 0x13, 0, 0},
258 {0x3636, 0x03, 0, 0}, {0x3634, 0x40, 0, 0}, {0x3622, 0x01, 0, 0},
259 {0x3c01, 0xa4, 0, 0}, {0x3c04, 0x28, 0, 0}, {0x3c05, 0x98, 0, 0},
260 {0x3c06, 0x00, 0, 0}, {0x3c07, 0x08, 0, 0}, {0x3c08, 0x00, 0, 0},
261 {0x3c09, 0x1c, 0, 0}, {0x3c0a, 0x9c, 0, 0}, {0x3c0b, 0x40, 0, 0},
262 {0x3820, 0x41, 0, 0}, {0x3821, 0x07, 0, 0}, {0x3814, 0x31, 0, 0},
263 {0x3815, 0x31, 0, 0}, {0x3800, 0x00, 0, 0}, {0x3801, 0x00, 0, 0},
264 {0x3802, 0x00, 0, 0}, {0x3803, 0x04, 0, 0}, {0x3804, 0x0a, 0, 0},
265 {0x3805, 0x3f, 0, 0}, {0x3806, 0x07, 0, 0}, {0x3807, 0x9b, 0, 0},
266 {0x3808, 0x02, 0, 0}, {0x3809, 0x80, 0, 0}, {0x380a, 0x01, 0, 0},
267 {0x380b, 0xe0, 0, 0}, {0x380c, 0x07, 0, 0}, {0x380d, 0x68, 0, 0},
268 {0x380e, 0x03, 0, 0}, {0x380f, 0xd8, 0, 0}, {0x3810, 0x00, 0, 0},
269 {0x3811, 0x10, 0, 0}, {0x3812, 0x00, 0, 0}, {0x3813, 0x06, 0, 0},
270 {0x3618, 0x00, 0, 0}, {0x3612, 0x29, 0, 0}, {0x3708, 0x64, 0, 0},
271 {0x3709, 0x52, 0, 0}, {0x370c, 0x03, 0, 0}, {0x3a02, 0x03, 0, 0},
272 {0x3a03, 0xd8, 0, 0}, {0x3a08, 0x01, 0, 0}, {0x3a09, 0x27, 0, 0},
273 {0x3a0a, 0x00, 0, 0}, {0x3a0b, 0xf6, 0, 0}, {0x3a0e, 0x03, 0, 0},
274 {0x3a0d, 0x04, 0, 0}, {0x3a14, 0x03, 0, 0}, {0x3a15, 0xd8, 0, 0},
275 {0x4001, 0x02, 0, 0}, {0x4004, 0x02, 0, 0}, {0x3000, 0x00, 0, 0},
276 {0x3002, 0x1c, 0, 0}, {0x3004, 0xff, 0, 0}, {0x3006, 0xc3, 0, 0},
277 {0x300e, 0x45, 0, 0}, {0x302e, 0x08, 0, 0}, {0x4300, 0x3f, 0, 0},
278 {0x501f, 0x00, 0, 0}, {0x4713, 0x03, 0, 0}, {0x4407, 0x04, 0, 0},
279 {0x440e, 0x00, 0, 0}, {0x460b, 0x35, 0, 0}, {0x460c, 0x22, 0, 0},
280 {0x4837, 0x0a, 0, 0}, {0x4800, 0x04, 0, 0}, {0x3824, 0x02, 0, 0},
281 {0x5000, 0xa7, 0, 0}, {0x5001, 0xa3, 0, 0}, {0x5180, 0xff, 0, 0},
282 {0x5181, 0xf2, 0, 0}, {0x5182, 0x00, 0, 0}, {0x5183, 0x14, 0, 0},
283 {0x5184, 0x25, 0, 0}, {0x5185, 0x24, 0, 0}, {0x5186, 0x09, 0, 0},
284 {0x5187, 0x09, 0, 0}, {0x5188, 0x09, 0, 0}, {0x5189, 0x88, 0, 0},
285 {0x518a, 0x54, 0, 0}, {0x518b, 0xee, 0, 0}, {0x518c, 0xb2, 0, 0},
286 {0x518d, 0x50, 0, 0}, {0x518e, 0x34, 0, 0}, {0x518f, 0x6b, 0, 0},
287 {0x5190, 0x46, 0, 0}, {0x5191, 0xf8, 0, 0}, {0x5192, 0x04, 0, 0},
288 {0x5193, 0x70, 0, 0}, {0x5194, 0xf0, 0, 0}, {0x5195, 0xf0, 0, 0},
289 {0x5196, 0x03, 0, 0}, {0x5197, 0x01, 0, 0}, {0x5198, 0x04, 0, 0},
290 {0x5199, 0x6c, 0, 0}, {0x519a, 0x04, 0, 0}, {0x519b, 0x00, 0, 0},
291 {0x519c, 0x09, 0, 0}, {0x519d, 0x2b, 0, 0}, {0x519e, 0x38, 0, 0},
292 {0x5381, 0x1e, 0, 0}, {0x5382, 0x5b, 0, 0}, {0x5383, 0x08, 0, 0},
293 {0x5384, 0x0a, 0, 0}, {0x5385, 0x7e, 0, 0}, {0x5386, 0x88, 0, 0},
294 {0x5387, 0x7c, 0, 0}, {0x5388, 0x6c, 0, 0}, {0x5389, 0x10, 0, 0},
295 {0x538a, 0x01, 0, 0}, {0x538b, 0x98, 0, 0}, {0x5300, 0x08, 0, 0},
296 {0x5301, 0x30, 0, 0}, {0x5302, 0x10, 0, 0}, {0x5303, 0x00, 0, 0},
297 {0x5304, 0x08, 0, 0}, {0x5305, 0x30, 0, 0}, {0x5306, 0x08, 0, 0},
298 {0x5307, 0x16, 0, 0}, {0x5309, 0x08, 0, 0}, {0x530a, 0x30, 0, 0},
299 {0x530b, 0x04, 0, 0}, {0x530c, 0x06, 0, 0}, {0x5480, 0x01, 0, 0},
300 {0x5481, 0x08, 0, 0}, {0x5482, 0x14, 0, 0}, {0x5483, 0x28, 0, 0},
301 {0x5484, 0x51, 0, 0}, {0x5485, 0x65, 0, 0}, {0x5486, 0x71, 0, 0},
302 {0x5487, 0x7d, 0, 0}, {0x5488, 0x87, 0, 0}, {0x5489, 0x91, 0, 0},
303 {0x548a, 0x9a, 0, 0}, {0x548b, 0xaa, 0, 0}, {0x548c, 0xb8, 0, 0},
304 {0x548d, 0xcd, 0, 0}, {0x548e, 0xdd, 0, 0}, {0x548f, 0xea, 0, 0},
305 {0x5490, 0x1d, 0, 0}, {0x5580, 0x02, 0, 0}, {0x5583, 0x40, 0, 0},
306 {0x5584, 0x10, 0, 0}, {0x5589, 0x10, 0, 0}, {0x558a, 0x00, 0, 0},
307 {0x558b, 0xf8, 0, 0}, {0x5800, 0x23, 0, 0}, {0x5801, 0x14, 0, 0},
308 {0x5802, 0x0f, 0, 0}, {0x5803, 0x0f, 0, 0}, {0x5804, 0x12, 0, 0},
309 {0x5805, 0x26, 0, 0}, {0x5806, 0x0c, 0, 0}, {0x5807, 0x08, 0, 0},
310 {0x5808, 0x05, 0, 0}, {0x5809, 0x05, 0, 0}, {0x580a, 0x08, 0, 0},
311 {0x580b, 0x0d, 0, 0}, {0x580c, 0x08, 0, 0}, {0x580d, 0x03, 0, 0},
312 {0x580e, 0x00, 0, 0}, {0x580f, 0x00, 0, 0}, {0x5810, 0x03, 0, 0},
313 {0x5811, 0x09, 0, 0}, {0x5812, 0x07, 0, 0}, {0x5813, 0x03, 0, 0},
314 {0x5814, 0x00, 0, 0}, {0x5815, 0x01, 0, 0}, {0x5816, 0x03, 0, 0},
315 {0x5817, 0x08, 0, 0}, {0x5818, 0x0d, 0, 0}, {0x5819, 0x08, 0, 0},
316 {0x581a, 0x05, 0, 0}, {0x581b, 0x06, 0, 0}, {0x581c, 0x08, 0, 0},
317 {0x581d, 0x0e, 0, 0}, {0x581e, 0x29, 0, 0}, {0x581f, 0x17, 0, 0},
318 {0x5820, 0x11, 0, 0}, {0x5821, 0x11, 0, 0}, {0x5822, 0x15, 0, 0},
319 {0x5823, 0x28, 0, 0}, {0x5824, 0x46, 0, 0}, {0x5825, 0x26, 0, 0},
320 {0x5826, 0x08, 0, 0}, {0x5827, 0x26, 0, 0}, {0x5828, 0x64, 0, 0},
321 {0x5829, 0x26, 0, 0}, {0x582a, 0x24, 0, 0}, {0x582b, 0x22, 0, 0},
322 {0x582c, 0x24, 0, 0}, {0x582d, 0x24, 0, 0}, {0x582e, 0x06, 0, 0},
323 {0x582f, 0x22, 0, 0}, {0x5830, 0x40, 0, 0}, {0x5831, 0x42, 0, 0},
324 {0x5832, 0x24, 0, 0}, {0x5833, 0x26, 0, 0}, {0x5834, 0x24, 0, 0},
325 {0x5835, 0x22, 0, 0}, {0x5836, 0x22, 0, 0}, {0x5837, 0x26, 0, 0},
326 {0x5838, 0x44, 0, 0}, {0x5839, 0x24, 0, 0}, {0x583a, 0x26, 0, 0},
327 {0x583b, 0x28, 0, 0}, {0x583c, 0x42, 0, 0}, {0x583d, 0xce, 0, 0},
328 {0x5025, 0x00, 0, 0}, {0x3a0f, 0x30, 0, 0}, {0x3a10, 0x28, 0, 0},
329 {0x3a1b, 0x30, 0, 0}, {0x3a1e, 0x26, 0, 0}, {0x3a11, 0x60, 0, 0},
330 {0x3a1f, 0x14, 0, 0}, {0x3008, 0x02, 0, 0}, {0x3c00, 0x04, 0, 300},
333 static const struct reg_value ov5640_setting_30fps_VGA_640_480
[] = {
335 {0x3035, 0x14, 0, 0}, {0x3036, 0x38, 0, 0}, {0x3c07, 0x08, 0, 0},
336 {0x3c09, 0x1c, 0, 0}, {0x3c0a, 0x9c, 0, 0}, {0x3c0b, 0x40, 0, 0},
337 {0x3820, 0x41, 0, 0}, {0x3821, 0x07, 0, 0}, {0x3814, 0x31, 0, 0},
338 {0x3815, 0x31, 0, 0}, {0x3800, 0x00, 0, 0}, {0x3801, 0x00, 0, 0},
339 {0x3802, 0x00, 0, 0}, {0x3803, 0x04, 0, 0}, {0x3804, 0x0a, 0, 0},
340 {0x3805, 0x3f, 0, 0}, {0x3806, 0x07, 0, 0}, {0x3807, 0x9b, 0, 0},
341 {0x3808, 0x02, 0, 0}, {0x3809, 0x80, 0, 0}, {0x380a, 0x01, 0, 0},
342 {0x380b, 0xe0, 0, 0}, {0x380c, 0x07, 0, 0}, {0x380d, 0x68, 0, 0},
343 {0x380e, 0x04, 0, 0}, {0x380f, 0x38, 0, 0}, {0x3810, 0x00, 0, 0},
344 {0x3811, 0x10, 0, 0}, {0x3812, 0x00, 0, 0}, {0x3813, 0x06, 0, 0},
345 {0x3618, 0x00, 0, 0}, {0x3612, 0x29, 0, 0}, {0x3708, 0x64, 0, 0},
346 {0x3709, 0x52, 0, 0}, {0x370c, 0x03, 0, 0}, {0x3a02, 0x03, 0, 0},
347 {0x3a03, 0xd8, 0, 0}, {0x3a08, 0x01, 0, 0}, {0x3a09, 0x0e, 0, 0},
348 {0x3a0a, 0x00, 0, 0}, {0x3a0b, 0xf6, 0, 0}, {0x3a0e, 0x03, 0, 0},
349 {0x3a0d, 0x04, 0, 0}, {0x3a14, 0x03, 0, 0}, {0x3a15, 0xd8, 0, 0},
350 {0x4001, 0x02, 0, 0}, {0x4004, 0x02, 0, 0}, {0x4713, 0x03, 0, 0},
351 {0x4407, 0x04, 0, 0}, {0x460b, 0x35, 0, 0}, {0x460c, 0x22, 0, 0},
352 {0x3824, 0x02, 0, 0}, {0x5001, 0xa3, 0, 0}, {0x3503, 0x00, 0, 0},
355 static const struct reg_value ov5640_setting_15fps_VGA_640_480
[] = {
356 {0x3035, 0x22, 0, 0}, {0x3036, 0x38, 0, 0}, {0x3c07, 0x08, 0, 0},
357 {0x3c09, 0x1c, 0, 0}, {0x3c0a, 0x9c, 0, 0}, {0x3c0b, 0x40, 0, 0},
358 {0x3820, 0x41, 0, 0}, {0x3821, 0x07, 0, 0}, {0x3814, 0x31, 0, 0},
359 {0x3815, 0x31, 0, 0}, {0x3800, 0x00, 0, 0}, {0x3801, 0x00, 0, 0},
360 {0x3802, 0x00, 0, 0}, {0x3803, 0x04, 0, 0}, {0x3804, 0x0a, 0, 0},
361 {0x3805, 0x3f, 0, 0}, {0x3806, 0x07, 0, 0}, {0x3807, 0x9b, 0, 0},
362 {0x3808, 0x02, 0, 0}, {0x3809, 0x80, 0, 0}, {0x380a, 0x01, 0, 0},
363 {0x380b, 0xe0, 0, 0}, {0x380c, 0x07, 0, 0}, {0x380d, 0x68, 0, 0},
364 {0x380e, 0x03, 0, 0}, {0x380f, 0xd8, 0, 0}, {0x3810, 0x00, 0, 0},
365 {0x3811, 0x10, 0, 0}, {0x3812, 0x00, 0, 0}, {0x3813, 0x06, 0, 0},
366 {0x3618, 0x00, 0, 0}, {0x3612, 0x29, 0, 0}, {0x3708, 0x64, 0, 0},
367 {0x3709, 0x52, 0, 0}, {0x370c, 0x03, 0, 0}, {0x3a02, 0x03, 0, 0},
368 {0x3a03, 0xd8, 0, 0}, {0x3a08, 0x01, 0, 0}, {0x3a09, 0x27, 0, 0},
369 {0x3a0a, 0x00, 0, 0}, {0x3a0b, 0xf6, 0, 0}, {0x3a0e, 0x03, 0, 0},
370 {0x3a0d, 0x04, 0, 0}, {0x3a14, 0x03, 0, 0}, {0x3a15, 0xd8, 0, 0},
371 {0x4001, 0x02, 0, 0}, {0x4004, 0x02, 0, 0}, {0x4713, 0x03, 0, 0},
372 {0x4407, 0x04, 0, 0}, {0x460b, 0x35, 0, 0}, {0x460c, 0x22, 0, 0},
373 {0x3824, 0x02, 0, 0}, {0x5001, 0xa3, 0, 0},
376 static const struct reg_value ov5640_setting_30fps_XGA_1024_768
[] = {
378 {0x3035, 0x14, 0, 0}, {0x3036, 0x38, 0, 0}, {0x3c07, 0x08, 0, 0},
379 {0x3c09, 0x1c, 0, 0}, {0x3c0a, 0x9c, 0, 0}, {0x3c0b, 0x40, 0, 0},
380 {0x3820, 0x41, 0, 0}, {0x3821, 0x07, 0, 0}, {0x3814, 0x31, 0, 0},
381 {0x3815, 0x31, 0, 0}, {0x3800, 0x00, 0, 0}, {0x3801, 0x00, 0, 0},
382 {0x3802, 0x00, 0, 0}, {0x3803, 0x04, 0, 0}, {0x3804, 0x0a, 0, 0},
383 {0x3805, 0x3f, 0, 0}, {0x3806, 0x07, 0, 0}, {0x3807, 0x9b, 0, 0},
384 {0x3808, 0x02, 0, 0}, {0x3809, 0x80, 0, 0}, {0x380a, 0x01, 0, 0},
385 {0x380b, 0xe0, 0, 0}, {0x380c, 0x07, 0, 0}, {0x380d, 0x68, 0, 0},
386 {0x380e, 0x04, 0, 0}, {0x380f, 0x38, 0, 0}, {0x3810, 0x00, 0, 0},
387 {0x3811, 0x10, 0, 0}, {0x3812, 0x00, 0, 0}, {0x3813, 0x06, 0, 0},
388 {0x3618, 0x00, 0, 0}, {0x3612, 0x29, 0, 0}, {0x3708, 0x64, 0, 0},
389 {0x3709, 0x52, 0, 0}, {0x370c, 0x03, 0, 0}, {0x3a02, 0x03, 0, 0},
390 {0x3a03, 0xd8, 0, 0}, {0x3a08, 0x01, 0, 0}, {0x3a09, 0x0e, 0, 0},
391 {0x3a0a, 0x00, 0, 0}, {0x3a0b, 0xf6, 0, 0}, {0x3a0e, 0x03, 0, 0},
392 {0x3a0d, 0x04, 0, 0}, {0x3a14, 0x03, 0, 0}, {0x3a15, 0xd8, 0, 0},
393 {0x4001, 0x02, 0, 0}, {0x4004, 0x02, 0, 0}, {0x4713, 0x03, 0, 0},
394 {0x4407, 0x04, 0, 0}, {0x460b, 0x35, 0, 0}, {0x460c, 0x22, 0, 0},
395 {0x3824, 0x02, 0, 0}, {0x5001, 0xa3, 0, 0}, {0x3503, 0x00, 0, 0},
396 {0x3808, 0x04, 0, 0}, {0x3809, 0x00, 0, 0}, {0x380a, 0x03, 0, 0},
397 {0x380b, 0x00, 0, 0}, {0x3035, 0x12, 0, 0},
400 static const struct reg_value ov5640_setting_15fps_XGA_1024_768
[] = {
401 {0x3035, 0x22, 0, 0}, {0x3036, 0x38, 0, 0}, {0x3c07, 0x08, 0, 0},
402 {0x3c09, 0x1c, 0, 0}, {0x3c0a, 0x9c, 0, 0}, {0x3c0b, 0x40, 0, 0},
403 {0x3820, 0x41, 0, 0}, {0x3821, 0x07, 0, 0}, {0x3814, 0x31, 0, 0},
404 {0x3815, 0x31, 0, 0}, {0x3800, 0x00, 0, 0}, {0x3801, 0x00, 0, 0},
405 {0x3802, 0x00, 0, 0}, {0x3803, 0x04, 0, 0}, {0x3804, 0x0a, 0, 0},
406 {0x3805, 0x3f, 0, 0}, {0x3806, 0x07, 0, 0}, {0x3807, 0x9b, 0, 0},
407 {0x3808, 0x02, 0, 0}, {0x3809, 0x80, 0, 0}, {0x380a, 0x01, 0, 0},
408 {0x380b, 0xe0, 0, 0}, {0x380c, 0x07, 0, 0}, {0x380d, 0x68, 0, 0},
409 {0x380e, 0x03, 0, 0}, {0x380f, 0xd8, 0, 0}, {0x3810, 0x00, 0, 0},
410 {0x3811, 0x10, 0, 0}, {0x3812, 0x00, 0, 0}, {0x3813, 0x06, 0, 0},
411 {0x3618, 0x00, 0, 0}, {0x3612, 0x29, 0, 0}, {0x3708, 0x64, 0, 0},
412 {0x3709, 0x52, 0, 0}, {0x370c, 0x03, 0, 0}, {0x3a02, 0x03, 0, 0},
413 {0x3a03, 0xd8, 0, 0}, {0x3a08, 0x01, 0, 0}, {0x3a09, 0x27, 0, 0},
414 {0x3a0a, 0x00, 0, 0}, {0x3a0b, 0xf6, 0, 0}, {0x3a0e, 0x03, 0, 0},
415 {0x3a0d, 0x04, 0, 0}, {0x3a14, 0x03, 0, 0}, {0x3a15, 0xd8, 0, 0},
416 {0x4001, 0x02, 0, 0}, {0x4004, 0x02, 0, 0}, {0x4713, 0x03, 0, 0},
417 {0x4407, 0x04, 0, 0}, {0x460b, 0x35, 0, 0}, {0x460c, 0x22, 0, 0},
418 {0x3824, 0x02, 0, 0}, {0x5001, 0xa3, 0, 0}, {0x3808, 0x04, 0, 0},
419 {0x3809, 0x00, 0, 0}, {0x380a, 0x03, 0, 0}, {0x380b, 0x00, 0, 0},
422 static const struct reg_value ov5640_setting_30fps_QVGA_320_240
[] = {
423 {0x3035, 0x14, 0, 0}, {0x3036, 0x38, 0, 0}, {0x3c07, 0x08, 0, 0},
424 {0x3c09, 0x1c, 0, 0}, {0x3c0a, 0x9c, 0, 0}, {0x3c0b, 0x40, 0, 0},
425 {0x3820, 0x41, 0, 0}, {0x3821, 0x07, 0, 0}, {0x3814, 0x31, 0, 0},
426 {0x3815, 0x31, 0, 0}, {0x3800, 0x00, 0, 0}, {0x3801, 0x00, 0, 0},
427 {0x3802, 0x00, 0, 0}, {0x3803, 0x04, 0, 0}, {0x3804, 0x0a, 0, 0},
428 {0x3805, 0x3f, 0, 0}, {0x3806, 0x07, 0, 0}, {0x3807, 0x9b, 0, 0},
429 {0x3808, 0x01, 0, 0}, {0x3809, 0x40, 0, 0}, {0x380a, 0x00, 0, 0},
430 {0x380b, 0xf0, 0, 0}, {0x380c, 0x07, 0, 0}, {0x380d, 0x68, 0, 0},
431 {0x380e, 0x03, 0, 0}, {0x380f, 0xd8, 0, 0}, {0x3810, 0x00, 0, 0},
432 {0x3811, 0x10, 0, 0}, {0x3812, 0x00, 0, 0}, {0x3813, 0x06, 0, 0},
433 {0x3618, 0x00, 0, 0}, {0x3612, 0x29, 0, 0}, {0x3708, 0x64, 0, 0},
434 {0x3709, 0x52, 0, 0}, {0x370c, 0x03, 0, 0}, {0x3a02, 0x03, 0, 0},
435 {0x3a03, 0xd8, 0, 0}, {0x3a08, 0x01, 0, 0}, {0x3a09, 0x27, 0, 0},
436 {0x3a0a, 0x00, 0, 0}, {0x3a0b, 0xf6, 0, 0}, {0x3a0e, 0x03, 0, 0},
437 {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},
439 {0x4407, 0x04, 0, 0}, {0x460b, 0x35, 0, 0}, {0x460c, 0x22, 0, 0},
440 {0x3824, 0x02, 0, 0}, {0x5001, 0xa3, 0, 0},
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},
445 {0x3c09, 0x1c, 0, 0}, {0x3c0a, 0x9c, 0, 0}, {0x3c0b, 0x40, 0, 0},
446 {0x3820, 0x41, 0, 0}, {0x3821, 0x07, 0, 0}, {0x3814, 0x31, 0, 0},
447 {0x3815, 0x31, 0, 0}, {0x3800, 0x00, 0, 0}, {0x3801, 0x00, 0, 0},
448 {0x3802, 0x00, 0, 0}, {0x3803, 0x04, 0, 0}, {0x3804, 0x0a, 0, 0},
449 {0x3805, 0x3f, 0, 0}, {0x3806, 0x07, 0, 0}, {0x3807, 0x9b, 0, 0},
450 {0x3808, 0x01, 0, 0}, {0x3809, 0x40, 0, 0}, {0x380a, 0x00, 0, 0},
451 {0x380b, 0xf0, 0, 0}, {0x380c, 0x07, 0, 0}, {0x380d, 0x68, 0, 0},
452 {0x380e, 0x03, 0, 0}, {0x380f, 0xd8, 0, 0}, {0x3810, 0x00, 0, 0},
453 {0x3811, 0x10, 0, 0}, {0x3812, 0x00, 0, 0}, {0x3813, 0x06, 0, 0},
454 {0x3618, 0x00, 0, 0}, {0x3612, 0x29, 0, 0}, {0x3708, 0x64, 0, 0},
455 {0x3709, 0x52, 0, 0}, {0x370c, 0x03, 0, 0}, {0x3a02, 0x03, 0, 0},
456 {0x3a03, 0xd8, 0, 0}, {0x3a08, 0x01, 0, 0}, {0x3a09, 0x27, 0, 0},
457 {0x3a0a, 0x00, 0, 0}, {0x3a0b, 0xf6, 0, 0}, {0x3a0e, 0x03, 0, 0},
458 {0x3a0d, 0x04, 0, 0}, {0x3a14, 0x03, 0, 0}, {0x3a15, 0xd8, 0, 0},
459 {0x4001, 0x02, 0, 0}, {0x4004, 0x02, 0, 0}, {0x4713, 0x03, 0, 0},
460 {0x4407, 0x04, 0, 0}, {0x460b, 0x35, 0, 0}, {0x460c, 0x22, 0, 0},
461 {0x3824, 0x02, 0, 0}, {0x5001, 0xa3, 0, 0},
464 static const struct reg_value ov5640_setting_30fps_QCIF_176_144
[] = {
465 {0x3035, 0x14, 0, 0}, {0x3036, 0x38, 0, 0}, {0x3c07, 0x08, 0, 0},
466 {0x3c09, 0x1c, 0, 0}, {0x3c0a, 0x9c, 0, 0}, {0x3c0b, 0x40, 0, 0},
467 {0x3820, 0x41, 0, 0}, {0x3821, 0x07, 0, 0}, {0x3814, 0x31, 0, 0},
468 {0x3815, 0x31, 0, 0}, {0x3800, 0x00, 0, 0}, {0x3801, 0x00, 0, 0},
469 {0x3802, 0x00, 0, 0}, {0x3803, 0x04, 0, 0}, {0x3804, 0x0a, 0, 0},
470 {0x3805, 0x3f, 0, 0}, {0x3806, 0x07, 0, 0}, {0x3807, 0x9b, 0, 0},
471 {0x3808, 0x00, 0, 0}, {0x3809, 0xb0, 0, 0}, {0x380a, 0x00, 0, 0},
472 {0x380b, 0x90, 0, 0}, {0x380c, 0x07, 0, 0}, {0x380d, 0x68, 0, 0},
473 {0x380e, 0x03, 0, 0}, {0x380f, 0xd8, 0, 0}, {0x3810, 0x00, 0, 0},
474 {0x3811, 0x10, 0, 0}, {0x3812, 0x00, 0, 0}, {0x3813, 0x06, 0, 0},
475 {0x3618, 0x00, 0, 0}, {0x3612, 0x29, 0, 0}, {0x3708, 0x64, 0, 0},
476 {0x3709, 0x52, 0, 0}, {0x370c, 0x03, 0, 0}, {0x3a02, 0x03, 0, 0},
477 {0x3a03, 0xd8, 0, 0}, {0x3a08, 0x01, 0, 0}, {0x3a09, 0x27, 0, 0},
478 {0x3a0a, 0x00, 0, 0}, {0x3a0b, 0xf6, 0, 0}, {0x3a0e, 0x03, 0, 0},
479 {0x3a0d, 0x04, 0, 0}, {0x3a14, 0x03, 0, 0}, {0x3a15, 0xd8, 0, 0},
480 {0x4001, 0x02, 0, 0}, {0x4004, 0x02, 0, 0}, {0x4713, 0x03, 0, 0},
481 {0x4407, 0x04, 0, 0}, {0x460b, 0x35, 0, 0}, {0x460c, 0x22, 0, 0},
482 {0x3824, 0x02, 0, 0}, {0x5001, 0xa3, 0, 0},
484 static const struct reg_value ov5640_setting_15fps_QCIF_176_144
[] = {
485 {0x3035, 0x22, 0, 0}, {0x3036, 0x38, 0, 0}, {0x3c07, 0x08, 0, 0},
486 {0x3c09, 0x1c, 0, 0}, {0x3c0a, 0x9c, 0, 0}, {0x3c0b, 0x40, 0, 0},
487 {0x3820, 0x41, 0, 0}, {0x3821, 0x07, 0, 0}, {0x3814, 0x31, 0, 0},
488 {0x3815, 0x31, 0, 0}, {0x3800, 0x00, 0, 0}, {0x3801, 0x00, 0, 0},
489 {0x3802, 0x00, 0, 0}, {0x3803, 0x04, 0, 0}, {0x3804, 0x0a, 0, 0},
490 {0x3805, 0x3f, 0, 0}, {0x3806, 0x07, 0, 0}, {0x3807, 0x9b, 0, 0},
491 {0x3808, 0x00, 0, 0}, {0x3809, 0xb0, 0, 0}, {0x380a, 0x00, 0, 0},
492 {0x380b, 0x90, 0, 0}, {0x380c, 0x07, 0, 0}, {0x380d, 0x68, 0, 0},
493 {0x380e, 0x03, 0, 0}, {0x380f, 0xd8, 0, 0}, {0x3810, 0x00, 0, 0},
494 {0x3811, 0x10, 0, 0}, {0x3812, 0x00, 0, 0}, {0x3813, 0x06, 0, 0},
495 {0x3618, 0x00, 0, 0}, {0x3612, 0x29, 0, 0}, {0x3708, 0x64, 0, 0},
496 {0x3709, 0x52, 0, 0}, {0x370c, 0x03, 0, 0}, {0x3a02, 0x03, 0, 0},
497 {0x3a03, 0xd8, 0, 0}, {0x3a08, 0x01, 0, 0}, {0x3a09, 0x27, 0, 0},
498 {0x3a0a, 0x00, 0, 0}, {0x3a0b, 0xf6, 0, 0}, {0x3a0e, 0x03, 0, 0},
499 {0x3a0d, 0x04, 0, 0}, {0x3a14, 0x03, 0, 0}, {0x3a15, 0xd8, 0, 0},
500 {0x4001, 0x02, 0, 0}, {0x4004, 0x02, 0, 0}, {0x4713, 0x03, 0, 0},
501 {0x4407, 0x04, 0, 0}, {0x460b, 0x35, 0, 0}, {0x460c, 0x22, 0, 0},
502 {0x3824, 0x02, 0, 0}, {0x5001, 0xa3, 0, 0},
505 static const struct reg_value ov5640_setting_30fps_NTSC_720_480
[] = {
506 {0x3035, 0x12, 0, 0}, {0x3036, 0x38, 0, 0}, {0x3c07, 0x08, 0, 0},
507 {0x3c09, 0x1c, 0, 0}, {0x3c0a, 0x9c, 0, 0}, {0x3c0b, 0x40, 0, 0},
508 {0x3820, 0x41, 0, 0}, {0x3821, 0x07, 0, 0}, {0x3814, 0x31, 0, 0},
509 {0x3815, 0x31, 0, 0}, {0x3800, 0x00, 0, 0}, {0x3801, 0x00, 0, 0},
510 {0x3802, 0x00, 0, 0}, {0x3803, 0x04, 0, 0}, {0x3804, 0x0a, 0, 0},
511 {0x3805, 0x3f, 0, 0}, {0x3806, 0x07, 0, 0}, {0x3807, 0x9b, 0, 0},
512 {0x3808, 0x02, 0, 0}, {0x3809, 0xd0, 0, 0}, {0x380a, 0x01, 0, 0},
513 {0x380b, 0xe0, 0, 0}, {0x380c, 0x07, 0, 0}, {0x380d, 0x68, 0, 0},
514 {0x380e, 0x03, 0, 0}, {0x380f, 0xd8, 0, 0}, {0x3810, 0x00, 0, 0},
515 {0x3811, 0x10, 0, 0}, {0x3812, 0x00, 0, 0}, {0x3813, 0x3c, 0, 0},
516 {0x3618, 0x00, 0, 0}, {0x3612, 0x29, 0, 0}, {0x3708, 0x64, 0, 0},
517 {0x3709, 0x52, 0, 0}, {0x370c, 0x03, 0, 0}, {0x3a02, 0x03, 0, 0},
518 {0x3a03, 0xd8, 0, 0}, {0x3a08, 0x01, 0, 0}, {0x3a09, 0x27, 0, 0},
519 {0x3a0a, 0x00, 0, 0}, {0x3a0b, 0xf6, 0, 0}, {0x3a0e, 0x03, 0, 0},
520 {0x3a0d, 0x04, 0, 0}, {0x3a14, 0x03, 0, 0}, {0x3a15, 0xd8, 0, 0},
521 {0x4001, 0x02, 0, 0}, {0x4004, 0x02, 0, 0}, {0x4713, 0x03, 0, 0},
522 {0x4407, 0x04, 0, 0}, {0x460b, 0x35, 0, 0}, {0x460c, 0x22, 0, 0},
523 {0x3824, 0x02, 0, 0}, {0x5001, 0xa3, 0, 0},
526 static const struct reg_value ov5640_setting_15fps_NTSC_720_480
[] = {
527 {0x3035, 0x22, 0, 0}, {0x3036, 0x38, 0, 0}, {0x3c07, 0x08, 0, 0},
528 {0x3c09, 0x1c, 0, 0}, {0x3c0a, 0x9c, 0, 0}, {0x3c0b, 0x40, 0, 0},
529 {0x3820, 0x41, 0, 0}, {0x3821, 0x07, 0, 0}, {0x3814, 0x31, 0, 0},
530 {0x3815, 0x31, 0, 0}, {0x3800, 0x00, 0, 0}, {0x3801, 0x00, 0, 0},
531 {0x3802, 0x00, 0, 0}, {0x3803, 0x04, 0, 0}, {0x3804, 0x0a, 0, 0},
532 {0x3805, 0x3f, 0, 0}, {0x3806, 0x07, 0, 0}, {0x3807, 0x9b, 0, 0},
533 {0x3808, 0x02, 0, 0}, {0x3809, 0xd0, 0, 0}, {0x380a, 0x01, 0, 0},
534 {0x380b, 0xe0, 0, 0}, {0x380c, 0x07, 0, 0}, {0x380d, 0x68, 0, 0},
535 {0x380e, 0x03, 0, 0}, {0x380f, 0xd8, 0, 0}, {0x3810, 0x00, 0, 0},
536 {0x3811, 0x10, 0, 0}, {0x3812, 0x00, 0, 0}, {0x3813, 0x3c, 0, 0},
537 {0x3618, 0x00, 0, 0}, {0x3612, 0x29, 0, 0}, {0x3708, 0x64, 0, 0},
538 {0x3709, 0x52, 0, 0}, {0x370c, 0x03, 0, 0}, {0x3a02, 0x03, 0, 0},
539 {0x3a03, 0xd8, 0, 0}, {0x3a08, 0x01, 0, 0}, {0x3a09, 0x27, 0, 0},
540 {0x3a0a, 0x00, 0, 0}, {0x3a0b, 0xf6, 0, 0}, {0x3a0e, 0x03, 0, 0},
541 {0x3a0d, 0x04, 0, 0}, {0x3a14, 0x03, 0, 0}, {0x3a15, 0xd8, 0, 0},
542 {0x4001, 0x02, 0, 0}, {0x4004, 0x02, 0, 0}, {0x4713, 0x03, 0, 0},
543 {0x4407, 0x04, 0, 0}, {0x460b, 0x35, 0, 0}, {0x460c, 0x22, 0, 0},
544 {0x3824, 0x02, 0, 0}, {0x5001, 0xa3, 0, 0},
547 static const struct reg_value ov5640_setting_30fps_PAL_720_576
[] = {
548 {0x3035, 0x12, 0, 0}, {0x3036, 0x38, 0, 0}, {0x3c07, 0x08, 0, 0},
549 {0x3c09, 0x1c, 0, 0}, {0x3c0a, 0x9c, 0, 0}, {0x3c0b, 0x40, 0, 0},
550 {0x3820, 0x41, 0, 0}, {0x3821, 0x07, 0, 0}, {0x3814, 0x31, 0, 0},
551 {0x3815, 0x31, 0, 0}, {0x3800, 0x00, 0, 0}, {0x3801, 0x00, 0, 0},
552 {0x3802, 0x00, 0, 0}, {0x3803, 0x04, 0, 0}, {0x3804, 0x0a, 0, 0},
553 {0x3805, 0x3f, 0, 0}, {0x3806, 0x07, 0, 0}, {0x3807, 0x9b, 0, 0},
554 {0x3808, 0x02, 0, 0}, {0x3809, 0xd0, 0, 0}, {0x380a, 0x02, 0, 0},
555 {0x380b, 0x40, 0, 0}, {0x380c, 0x07, 0, 0}, {0x380d, 0x68, 0, 0},
556 {0x380e, 0x03, 0, 0}, {0x380f, 0xd8, 0, 0}, {0x3810, 0x00, 0, 0},
557 {0x3811, 0x38, 0, 0}, {0x3812, 0x00, 0, 0}, {0x3813, 0x06, 0, 0},
558 {0x3618, 0x00, 0, 0}, {0x3612, 0x29, 0, 0}, {0x3708, 0x64, 0, 0},
559 {0x3709, 0x52, 0, 0}, {0x370c, 0x03, 0, 0}, {0x3a02, 0x03, 0, 0},
560 {0x3a03, 0xd8, 0, 0}, {0x3a08, 0x01, 0, 0}, {0x3a09, 0x27, 0, 0},
561 {0x3a0a, 0x00, 0, 0}, {0x3a0b, 0xf6, 0, 0}, {0x3a0e, 0x03, 0, 0},
562 {0x3a0d, 0x04, 0, 0}, {0x3a14, 0x03, 0, 0}, {0x3a15, 0xd8, 0, 0},
563 {0x4001, 0x02, 0, 0}, {0x4004, 0x02, 0, 0}, {0x4713, 0x03, 0, 0},
564 {0x4407, 0x04, 0, 0}, {0x460b, 0x35, 0, 0}, {0x460c, 0x22, 0, 0},
565 {0x3824, 0x02, 0, 0}, {0x5001, 0xa3, 0, 0},
568 static const struct reg_value ov5640_setting_15fps_PAL_720_576
[] = {
569 {0x3035, 0x22, 0, 0}, {0x3036, 0x38, 0, 0}, {0x3c07, 0x08, 0, 0},
570 {0x3c09, 0x1c, 0, 0}, {0x3c0a, 0x9c, 0, 0}, {0x3c0b, 0x40, 0, 0},
571 {0x3820, 0x41, 0, 0}, {0x3821, 0x07, 0, 0}, {0x3814, 0x31, 0, 0},
572 {0x3815, 0x31, 0, 0}, {0x3800, 0x00, 0, 0}, {0x3801, 0x00, 0, 0},
573 {0x3802, 0x00, 0, 0}, {0x3803, 0x04, 0, 0}, {0x3804, 0x0a, 0, 0},
574 {0x3805, 0x3f, 0, 0}, {0x3806, 0x07, 0, 0}, {0x3807, 0x9b, 0, 0},
575 {0x3808, 0x02, 0, 0}, {0x3809, 0xd0, 0, 0}, {0x380a, 0x02, 0, 0},
576 {0x380b, 0x40, 0, 0}, {0x380c, 0x07, 0, 0}, {0x380d, 0x68, 0, 0},
577 {0x380e, 0x03, 0, 0}, {0x380f, 0xd8, 0, 0}, {0x3810, 0x00, 0, 0},
578 {0x3811, 0x38, 0, 0}, {0x3812, 0x00, 0, 0}, {0x3813, 0x06, 0, 0},
579 {0x3618, 0x00, 0, 0}, {0x3612, 0x29, 0, 0}, {0x3708, 0x64, 0, 0},
580 {0x3709, 0x52, 0, 0}, {0x370c, 0x03, 0, 0}, {0x3a02, 0x03, 0, 0},
581 {0x3a03, 0xd8, 0, 0}, {0x3a08, 0x01, 0, 0}, {0x3a09, 0x27, 0, 0},
582 {0x3a0a, 0x00, 0, 0}, {0x3a0b, 0xf6, 0, 0}, {0x3a0e, 0x03, 0, 0},
583 {0x3a0d, 0x04, 0, 0}, {0x3a14, 0x03, 0, 0}, {0x3a15, 0xd8, 0, 0},
584 {0x4001, 0x02, 0, 0}, {0x4004, 0x02, 0, 0}, {0x4713, 0x03, 0, 0},
585 {0x4407, 0x04, 0, 0}, {0x460b, 0x35, 0, 0}, {0x460c, 0x22, 0, 0},
586 {0x3824, 0x02, 0, 0}, {0x5001, 0xa3, 0, 0},
589 static const struct reg_value ov5640_setting_30fps_720P_1280_720
[] = {
590 {0x3008, 0x42, 0, 0},
591 {0x3035, 0x21, 0, 0}, {0x3036, 0x54, 0, 0}, {0x3c07, 0x07, 0, 0},
592 {0x3c09, 0x1c, 0, 0}, {0x3c0a, 0x9c, 0, 0}, {0x3c0b, 0x40, 0, 0},
593 {0x3820, 0x41, 0, 0}, {0x3821, 0x07, 0, 0}, {0x3814, 0x31, 0, 0},
594 {0x3815, 0x31, 0, 0}, {0x3800, 0x00, 0, 0}, {0x3801, 0x00, 0, 0},
595 {0x3802, 0x00, 0, 0}, {0x3803, 0xfa, 0, 0}, {0x3804, 0x0a, 0, 0},
596 {0x3805, 0x3f, 0, 0}, {0x3806, 0x06, 0, 0}, {0x3807, 0xa9, 0, 0},
597 {0x3808, 0x05, 0, 0}, {0x3809, 0x00, 0, 0}, {0x380a, 0x02, 0, 0},
598 {0x380b, 0xd0, 0, 0}, {0x380c, 0x07, 0, 0}, {0x380d, 0x64, 0, 0},
599 {0x380e, 0x02, 0, 0}, {0x380f, 0xe4, 0, 0}, {0x3810, 0x00, 0, 0},
600 {0x3811, 0x10, 0, 0}, {0x3812, 0x00, 0, 0}, {0x3813, 0x04, 0, 0},
601 {0x3618, 0x00, 0, 0}, {0x3612, 0x29, 0, 0}, {0x3708, 0x64, 0, 0},
602 {0x3709, 0x52, 0, 0}, {0x370c, 0x03, 0, 0}, {0x3a02, 0x02, 0, 0},
603 {0x3a03, 0xe4, 0, 0}, {0x3a08, 0x01, 0, 0}, {0x3a09, 0xbc, 0, 0},
604 {0x3a0a, 0x01, 0, 0}, {0x3a0b, 0x72, 0, 0}, {0x3a0e, 0x01, 0, 0},
605 {0x3a0d, 0x02, 0, 0}, {0x3a14, 0x02, 0, 0}, {0x3a15, 0xe4, 0, 0},
606 {0x4001, 0x02, 0, 0}, {0x4004, 0x02, 0, 0}, {0x4713, 0x02, 0, 0},
607 {0x4407, 0x04, 0, 0}, {0x460b, 0x37, 0, 0}, {0x460c, 0x20, 0, 0},
608 {0x3824, 0x04, 0, 0}, {0x5001, 0x83, 0, 0}, {0x4005, 0x1a, 0, 0},
609 {0x3008, 0x02, 0, 0}, {0x3503, 0, 0, 0},
612 static const struct reg_value ov5640_setting_15fps_720P_1280_720
[] = {
613 {0x3035, 0x41, 0, 0}, {0x3036, 0x54, 0, 0}, {0x3c07, 0x07, 0, 0},
614 {0x3c09, 0x1c, 0, 0}, {0x3c0a, 0x9c, 0, 0}, {0x3c0b, 0x40, 0, 0},
615 {0x3820, 0x41, 0, 0}, {0x3821, 0x07, 0, 0}, {0x3814, 0x31, 0, 0},
616 {0x3815, 0x31, 0, 0}, {0x3800, 0x00, 0, 0}, {0x3801, 0x00, 0, 0},
617 {0x3802, 0x00, 0, 0}, {0x3803, 0xfa, 0, 0}, {0x3804, 0x0a, 0, 0},
618 {0x3805, 0x3f, 0, 0}, {0x3806, 0x06, 0, 0}, {0x3807, 0xa9, 0, 0},
619 {0x3808, 0x05, 0, 0}, {0x3809, 0x00, 0, 0}, {0x380a, 0x02, 0, 0},
620 {0x380b, 0xd0, 0, 0}, {0x380c, 0x07, 0, 0}, {0x380d, 0x64, 0, 0},
621 {0x380e, 0x02, 0, 0}, {0x380f, 0xe4, 0, 0}, {0x3810, 0x00, 0, 0},
622 {0x3811, 0x10, 0, 0}, {0x3812, 0x00, 0, 0}, {0x3813, 0x04, 0, 0},
623 {0x3618, 0x00, 0, 0}, {0x3612, 0x29, 0, 0}, {0x3708, 0x64, 0, 0},
624 {0x3709, 0x52, 0, 0}, {0x370c, 0x03, 0, 0}, {0x3a02, 0x02, 0, 0},
625 {0x3a03, 0xe4, 0, 0}, {0x3a08, 0x01, 0, 0}, {0x3a09, 0xbc, 0, 0},
626 {0x3a0a, 0x01, 0, 0}, {0x3a0b, 0x72, 0, 0}, {0x3a0e, 0x01, 0, 0},
627 {0x3a0d, 0x02, 0, 0}, {0x3a14, 0x02, 0, 0}, {0x3a15, 0xe4, 0, 0},
628 {0x4001, 0x02, 0, 0}, {0x4004, 0x02, 0, 0}, {0x4713, 0x02, 0, 0},
629 {0x4407, 0x04, 0, 0}, {0x460b, 0x37, 0, 0}, {0x460c, 0x20, 0, 0},
630 {0x3824, 0x04, 0, 0}, {0x5001, 0x83, 0, 0},
633 static const struct reg_value ov5640_setting_30fps_1080P_1920_1080
[] = {
634 {0x3008, 0x42, 0, 0},
635 {0x3035, 0x21, 0, 0}, {0x3036, 0x54, 0, 0}, {0x3c07, 0x08, 0, 0},
636 {0x3c09, 0x1c, 0, 0}, {0x3c0a, 0x9c, 0, 0}, {0x3c0b, 0x40, 0, 0},
637 {0x3820, 0x40, 0, 0}, {0x3821, 0x06, 0, 0}, {0x3814, 0x11, 0, 0},
638 {0x3815, 0x11, 0, 0}, {0x3800, 0x00, 0, 0}, {0x3801, 0x00, 0, 0},
639 {0x3802, 0x00, 0, 0}, {0x3803, 0x00, 0, 0}, {0x3804, 0x0a, 0, 0},
640 {0x3805, 0x3f, 0, 0}, {0x3806, 0x07, 0, 0}, {0x3807, 0x9f, 0, 0},
641 {0x3808, 0x0a, 0, 0}, {0x3809, 0x20, 0, 0}, {0x380a, 0x07, 0, 0},
642 {0x380b, 0x98, 0, 0}, {0x380c, 0x0b, 0, 0}, {0x380d, 0x1c, 0, 0},
643 {0x380e, 0x07, 0, 0}, {0x380f, 0xb0, 0, 0}, {0x3810, 0x00, 0, 0},
644 {0x3811, 0x10, 0, 0}, {0x3812, 0x00, 0, 0}, {0x3813, 0x04, 0, 0},
645 {0x3618, 0x04, 0, 0}, {0x3612, 0x29, 0, 0}, {0x3708, 0x21, 0, 0},
646 {0x3709, 0x12, 0, 0}, {0x370c, 0x00, 0, 0}, {0x3a02, 0x03, 0, 0},
647 {0x3a03, 0xd8, 0, 0}, {0x3a08, 0x01, 0, 0}, {0x3a09, 0x27, 0, 0},
648 {0x3a0a, 0x00, 0, 0}, {0x3a0b, 0xf6, 0, 0}, {0x3a0e, 0x03, 0, 0},
649 {0x3a0d, 0x04, 0, 0}, {0x3a14, 0x03, 0, 0}, {0x3a15, 0xd8, 0, 0},
650 {0x4001, 0x02, 0, 0}, {0x4004, 0x06, 0, 0}, {0x4713, 0x03, 0, 0},
651 {0x4407, 0x04, 0, 0}, {0x460b, 0x35, 0, 0}, {0x460c, 0x22, 0, 0},
652 {0x3824, 0x02, 0, 0}, {0x5001, 0x83, 0, 0}, {0x3035, 0x11, 0, 0},
653 {0x3036, 0x54, 0, 0}, {0x3c07, 0x07, 0, 0}, {0x3c08, 0x00, 0, 0},
654 {0x3c09, 0x1c, 0, 0}, {0x3c0a, 0x9c, 0, 0}, {0x3c0b, 0x40, 0, 0},
655 {0x3800, 0x01, 0, 0}, {0x3801, 0x50, 0, 0}, {0x3802, 0x01, 0, 0},
656 {0x3803, 0xb2, 0, 0}, {0x3804, 0x08, 0, 0}, {0x3805, 0xef, 0, 0},
657 {0x3806, 0x05, 0, 0}, {0x3807, 0xf1, 0, 0}, {0x3808, 0x07, 0, 0},
658 {0x3809, 0x80, 0, 0}, {0x380a, 0x04, 0, 0}, {0x380b, 0x38, 0, 0},
659 {0x380c, 0x09, 0, 0}, {0x380d, 0xc4, 0, 0}, {0x380e, 0x04, 0, 0},
660 {0x380f, 0x60, 0, 0}, {0x3612, 0x2b, 0, 0}, {0x3708, 0x64, 0, 0},
661 {0x3a02, 0x04, 0, 0}, {0x3a03, 0x60, 0, 0}, {0x3a08, 0x01, 0, 0},
662 {0x3a09, 0x50, 0, 0}, {0x3a0a, 0x01, 0, 0}, {0x3a0b, 0x18, 0, 0},
663 {0x3a0e, 0x03, 0, 0}, {0x3a0d, 0x04, 0, 0}, {0x3a14, 0x04, 0, 0},
664 {0x3a15, 0x60, 0, 0}, {0x4713, 0x02, 0, 0}, {0x4407, 0x04, 0, 0},
665 {0x460b, 0x37, 0, 0}, {0x460c, 0x20, 0, 0}, {0x3824, 0x04, 0, 0},
666 {0x4005, 0x1a, 0, 0}, {0x3008, 0x02, 0, 0},
670 static const struct reg_value ov5640_setting_15fps_1080P_1920_1080
[] = {
671 {0x3008, 0x42, 0, 0},
672 {0x3035, 0x21, 0, 0}, {0x3036, 0x54, 0, 0}, {0x3c07, 0x08, 0, 0},
673 {0x3c09, 0x1c, 0, 0}, {0x3c0a, 0x9c, 0, 0}, {0x3c0b, 0x40, 0, 0},
674 {0x3820, 0x40, 0, 0}, {0x3821, 0x06, 0, 0}, {0x3814, 0x11, 0, 0},
675 {0x3815, 0x11, 0, 0}, {0x3800, 0x00, 0, 0}, {0x3801, 0x00, 0, 0},
676 {0x3802, 0x00, 0, 0}, {0x3803, 0x00, 0, 0}, {0x3804, 0x0a, 0, 0},
677 {0x3805, 0x3f, 0, 0}, {0x3806, 0x07, 0, 0}, {0x3807, 0x9f, 0, 0},
678 {0x3808, 0x0a, 0, 0}, {0x3809, 0x20, 0, 0}, {0x380a, 0x07, 0, 0},
679 {0x380b, 0x98, 0, 0}, {0x380c, 0x0b, 0, 0}, {0x380d, 0x1c, 0, 0},
680 {0x380e, 0x07, 0, 0}, {0x380f, 0xb0, 0, 0}, {0x3810, 0x00, 0, 0},
681 {0x3811, 0x10, 0, 0}, {0x3812, 0x00, 0, 0}, {0x3813, 0x04, 0, 0},
682 {0x3618, 0x04, 0, 0}, {0x3612, 0x29, 0, 0}, {0x3708, 0x21, 0, 0},
683 {0x3709, 0x12, 0, 0}, {0x370c, 0x00, 0, 0}, {0x3a02, 0x03, 0, 0},
684 {0x3a03, 0xd8, 0, 0}, {0x3a08, 0x01, 0, 0}, {0x3a09, 0x27, 0, 0},
685 {0x3a0a, 0x00, 0, 0}, {0x3a0b, 0xf6, 0, 0}, {0x3a0e, 0x03, 0, 0},
686 {0x3a0d, 0x04, 0, 0}, {0x3a14, 0x03, 0, 0}, {0x3a15, 0xd8, 0, 0},
687 {0x4001, 0x02, 0, 0}, {0x4004, 0x06, 0, 0}, {0x4713, 0x03, 0, 0},
688 {0x4407, 0x04, 0, 0}, {0x460b, 0x35, 0, 0}, {0x460c, 0x22, 0, 0},
689 {0x3824, 0x02, 0, 0}, {0x5001, 0x83, 0, 0}, {0x3035, 0x21, 0, 0},
690 {0x3036, 0x54, 0, 1}, {0x3c07, 0x07, 0, 0}, {0x3c08, 0x00, 0, 0},
691 {0x3c09, 0x1c, 0, 0}, {0x3c0a, 0x9c, 0, 0}, {0x3c0b, 0x40, 0, 0},
692 {0x3800, 0x01, 0, 0}, {0x3801, 0x50, 0, 0}, {0x3802, 0x01, 0, 0},
693 {0x3803, 0xb2, 0, 0}, {0x3804, 0x08, 0, 0}, {0x3805, 0xef, 0, 0},
694 {0x3806, 0x05, 0, 0}, {0x3807, 0xf1, 0, 0}, {0x3808, 0x07, 0, 0},
695 {0x3809, 0x80, 0, 0}, {0x380a, 0x04, 0, 0}, {0x380b, 0x38, 0, 0},
696 {0x380c, 0x09, 0, 0}, {0x380d, 0xc4, 0, 0}, {0x380e, 0x04, 0, 0},
697 {0x380f, 0x60, 0, 0}, {0x3612, 0x2b, 0, 0}, {0x3708, 0x64, 0, 0},
698 {0x3a02, 0x04, 0, 0}, {0x3a03, 0x60, 0, 0}, {0x3a08, 0x01, 0, 0},
699 {0x3a09, 0x50, 0, 0}, {0x3a0a, 0x01, 0, 0}, {0x3a0b, 0x18, 0, 0},
700 {0x3a0e, 0x03, 0, 0}, {0x3a0d, 0x04, 0, 0}, {0x3a14, 0x04, 0, 0},
701 {0x3a15, 0x60, 0, 0}, {0x4713, 0x02, 0, 0}, {0x4407, 0x04, 0, 0},
702 {0x460b, 0x37, 0, 0}, {0x460c, 0x20, 0, 0}, {0x3824, 0x04, 0, 0},
703 {0x4005, 0x1a, 0, 0}, {0x3008, 0x02, 0, 0}, {0x3503, 0, 0, 0},
706 static const struct reg_value ov5640_setting_15fps_QSXGA_2592_1944
[] = {
707 {0x3820, 0x40, 0, 0}, {0x3821, 0x06, 0, 0},
708 {0x3035, 0x21, 0, 0}, {0x3036, 0x54, 0, 0}, {0x3c07, 0x08, 0, 0},
709 {0x3c09, 0x1c, 0, 0}, {0x3c0a, 0x9c, 0, 0}, {0x3c0b, 0x40, 0, 0},
710 {0x3820, 0x40, 0, 0}, {0x3821, 0x06, 0, 0}, {0x3814, 0x11, 0, 0},
711 {0x3815, 0x11, 0, 0}, {0x3800, 0x00, 0, 0}, {0x3801, 0x00, 0, 0},
712 {0x3802, 0x00, 0, 0}, {0x3803, 0x00, 0, 0}, {0x3804, 0x0a, 0, 0},
713 {0x3805, 0x3f, 0, 0}, {0x3806, 0x07, 0, 0}, {0x3807, 0x9f, 0, 0},
714 {0x3808, 0x0a, 0, 0}, {0x3809, 0x20, 0, 0}, {0x380a, 0x07, 0, 0},
715 {0x380b, 0x98, 0, 0}, {0x380c, 0x0b, 0, 0}, {0x380d, 0x1c, 0, 0},
716 {0x380e, 0x07, 0, 0}, {0x380f, 0xb0, 0, 0}, {0x3810, 0x00, 0, 0},
717 {0x3811, 0x10, 0, 0}, {0x3812, 0x00, 0, 0}, {0x3813, 0x04, 0, 0},
718 {0x3618, 0x04, 0, 0}, {0x3612, 0x29, 0, 0}, {0x3708, 0x21, 0, 0},
719 {0x3709, 0x12, 0, 0}, {0x370c, 0x00, 0, 0}, {0x3a02, 0x03, 0, 0},
720 {0x3a03, 0xd8, 0, 0}, {0x3a08, 0x01, 0, 0}, {0x3a09, 0x27, 0, 0},
721 {0x3a0a, 0x00, 0, 0}, {0x3a0b, 0xf6, 0, 0}, {0x3a0e, 0x03, 0, 0},
722 {0x3a0d, 0x04, 0, 0}, {0x3a14, 0x03, 0, 0}, {0x3a15, 0xd8, 0, 0},
723 {0x4001, 0x02, 0, 0}, {0x4004, 0x06, 0, 0}, {0x4713, 0x03, 0, 0},
724 {0x4407, 0x04, 0, 0}, {0x460b, 0x35, 0, 0}, {0x460c, 0x22, 0, 0},
725 {0x3824, 0x02, 0, 0}, {0x5001, 0x83, 0, 70},
728 /* power-on sensor init reg table */
729 static const struct ov5640_mode_info ov5640_mode_init_data
= {
730 0, SUBSAMPLING
, 640, 480, ov5640_init_setting_30fps_VGA
,
731 ARRAY_SIZE(ov5640_init_setting_30fps_VGA
),
734 static const struct ov5640_mode_info
735 ov5640_mode_data
[OV5640_NUM_FRAMERATES
][OV5640_NUM_MODES
] = {
737 {OV5640_MODE_QCIF_176_144
, SUBSAMPLING
, 176, 144,
738 ov5640_setting_15fps_QCIF_176_144
,
739 ARRAY_SIZE(ov5640_setting_15fps_QCIF_176_144
)},
740 {OV5640_MODE_QVGA_320_240
, SUBSAMPLING
, 320, 240,
741 ov5640_setting_15fps_QVGA_320_240
,
742 ARRAY_SIZE(ov5640_setting_15fps_QVGA_320_240
)},
743 {OV5640_MODE_VGA_640_480
, SUBSAMPLING
, 640, 480,
744 ov5640_setting_15fps_VGA_640_480
,
745 ARRAY_SIZE(ov5640_setting_15fps_VGA_640_480
)},
746 {OV5640_MODE_NTSC_720_480
, SUBSAMPLING
, 720, 480,
747 ov5640_setting_15fps_NTSC_720_480
,
748 ARRAY_SIZE(ov5640_setting_15fps_NTSC_720_480
)},
749 {OV5640_MODE_PAL_720_576
, SUBSAMPLING
, 720, 576,
750 ov5640_setting_15fps_PAL_720_576
,
751 ARRAY_SIZE(ov5640_setting_15fps_PAL_720_576
)},
752 {OV5640_MODE_XGA_1024_768
, SUBSAMPLING
, 1024, 768,
753 ov5640_setting_15fps_XGA_1024_768
,
754 ARRAY_SIZE(ov5640_setting_15fps_XGA_1024_768
)},
755 {OV5640_MODE_720P_1280_720
, SUBSAMPLING
, 1280, 720,
756 ov5640_setting_15fps_720P_1280_720
,
757 ARRAY_SIZE(ov5640_setting_15fps_720P_1280_720
)},
758 {OV5640_MODE_1080P_1920_1080
, SCALING
, 1920, 1080,
759 ov5640_setting_15fps_1080P_1920_1080
,
760 ARRAY_SIZE(ov5640_setting_15fps_1080P_1920_1080
)},
761 {OV5640_MODE_QSXGA_2592_1944
, SCALING
, 2592, 1944,
762 ov5640_setting_15fps_QSXGA_2592_1944
,
763 ARRAY_SIZE(ov5640_setting_15fps_QSXGA_2592_1944
)},
765 {OV5640_MODE_QCIF_176_144
, SUBSAMPLING
, 176, 144,
766 ov5640_setting_30fps_QCIF_176_144
,
767 ARRAY_SIZE(ov5640_setting_30fps_QCIF_176_144
)},
768 {OV5640_MODE_QVGA_320_240
, SUBSAMPLING
, 320, 240,
769 ov5640_setting_30fps_QVGA_320_240
,
770 ARRAY_SIZE(ov5640_setting_30fps_QVGA_320_240
)},
771 {OV5640_MODE_VGA_640_480
, SUBSAMPLING
, 640, 480,
772 ov5640_setting_30fps_VGA_640_480
,
773 ARRAY_SIZE(ov5640_setting_30fps_VGA_640_480
)},
774 {OV5640_MODE_NTSC_720_480
, SUBSAMPLING
, 720, 480,
775 ov5640_setting_30fps_NTSC_720_480
,
776 ARRAY_SIZE(ov5640_setting_30fps_NTSC_720_480
)},
777 {OV5640_MODE_PAL_720_576
, SUBSAMPLING
, 720, 576,
778 ov5640_setting_30fps_PAL_720_576
,
779 ARRAY_SIZE(ov5640_setting_30fps_PAL_720_576
)},
780 {OV5640_MODE_XGA_1024_768
, SUBSAMPLING
, 1024, 768,
781 ov5640_setting_30fps_XGA_1024_768
,
782 ARRAY_SIZE(ov5640_setting_30fps_XGA_1024_768
)},
783 {OV5640_MODE_720P_1280_720
, SUBSAMPLING
, 1280, 720,
784 ov5640_setting_30fps_720P_1280_720
,
785 ARRAY_SIZE(ov5640_setting_30fps_720P_1280_720
)},
786 {OV5640_MODE_1080P_1920_1080
, SCALING
, 1920, 1080,
787 ov5640_setting_30fps_1080P_1920_1080
,
788 ARRAY_SIZE(ov5640_setting_30fps_1080P_1920_1080
)},
789 {OV5640_MODE_QSXGA_2592_1944
, -1, 0, 0, NULL
, 0},
793 static int ov5640_init_slave_id(struct ov5640_dev
*sensor
)
795 struct i2c_client
*client
= sensor
->i2c_client
;
800 if (client
->addr
== OV5640_DEFAULT_SLAVE_ID
)
803 buf
[0] = OV5640_REG_SLAVE_ID
>> 8;
804 buf
[1] = OV5640_REG_SLAVE_ID
& 0xff;
805 buf
[2] = client
->addr
<< 1;
807 msg
.addr
= OV5640_DEFAULT_SLAVE_ID
;
810 msg
.len
= sizeof(buf
);
812 ret
= i2c_transfer(client
->adapter
, &msg
, 1);
814 dev_err(&client
->dev
, "%s: failed with %d\n", __func__
, ret
);
821 static int ov5640_write_reg(struct ov5640_dev
*sensor
, u16 reg
, u8 val
)
823 struct i2c_client
*client
= sensor
->i2c_client
;
832 msg
.addr
= client
->addr
;
833 msg
.flags
= client
->flags
;
835 msg
.len
= sizeof(buf
);
837 ret
= i2c_transfer(client
->adapter
, &msg
, 1);
839 v4l2_err(&sensor
->sd
, "%s: error: reg=%x, val=%x\n",
847 static int ov5640_read_reg(struct ov5640_dev
*sensor
, u16 reg
, u8
*val
)
849 struct i2c_client
*client
= sensor
->i2c_client
;
850 struct i2c_msg msg
[2];
857 msg
[0].addr
= client
->addr
;
858 msg
[0].flags
= client
->flags
;
860 msg
[0].len
= sizeof(buf
);
862 msg
[1].addr
= client
->addr
;
863 msg
[1].flags
= client
->flags
| I2C_M_RD
;
867 ret
= i2c_transfer(client
->adapter
, msg
, 2);
875 static int ov5640_read_reg16(struct ov5640_dev
*sensor
, u16 reg
, u16
*val
)
880 ret
= ov5640_read_reg(sensor
, reg
, &hi
);
883 ret
= ov5640_read_reg(sensor
, reg
+1, &lo
);
887 *val
= ((u16
)hi
<< 8) | (u16
)lo
;
891 static int ov5640_write_reg16(struct ov5640_dev
*sensor
, u16 reg
, u16 val
)
895 ret
= ov5640_write_reg(sensor
, reg
, val
>> 8);
899 return ov5640_write_reg(sensor
, reg
+ 1, val
& 0xff);
902 static int ov5640_mod_reg(struct ov5640_dev
*sensor
, u16 reg
,
908 ret
= ov5640_read_reg(sensor
, reg
, &readval
);
916 return ov5640_write_reg(sensor
, reg
, val
);
919 /* download ov5640 settings to sensor through i2c */
920 static int ov5640_load_regs(struct ov5640_dev
*sensor
,
921 const struct ov5640_mode_info
*mode
)
923 const struct reg_value
*regs
= mode
->reg_data
;
930 for (i
= 0; i
< mode
->reg_data_size
; ++i
, ++regs
) {
931 delay_ms
= regs
->delay_ms
;
932 reg_addr
= regs
->reg_addr
;
937 ret
= ov5640_mod_reg(sensor
, reg_addr
, mask
, val
);
939 ret
= ov5640_write_reg(sensor
, reg_addr
, val
);
944 usleep_range(1000*delay_ms
, 1000*delay_ms
+100);
950 /* read exposure, in number of line periods */
951 static int ov5640_get_exposure(struct ov5640_dev
*sensor
)
956 ret
= ov5640_read_reg(sensor
, OV5640_REG_AEC_PK_EXPOSURE_HI
, &temp
);
959 exp
= ((int)temp
& 0x0f) << 16;
960 ret
= ov5640_read_reg(sensor
, OV5640_REG_AEC_PK_EXPOSURE_MED
, &temp
);
963 exp
|= ((int)temp
<< 8);
964 ret
= ov5640_read_reg(sensor
, OV5640_REG_AEC_PK_EXPOSURE_LO
, &temp
);
972 /* write exposure, given number of line periods */
973 static int ov5640_set_exposure(struct ov5640_dev
*sensor
, u32 exposure
)
979 ret
= ov5640_write_reg(sensor
,
980 OV5640_REG_AEC_PK_EXPOSURE_LO
,
984 ret
= ov5640_write_reg(sensor
,
985 OV5640_REG_AEC_PK_EXPOSURE_MED
,
986 (exposure
>> 8) & 0xff);
989 return ov5640_write_reg(sensor
,
990 OV5640_REG_AEC_PK_EXPOSURE_HI
,
991 (exposure
>> 16) & 0x0f);
994 static int ov5640_get_gain(struct ov5640_dev
*sensor
)
999 ret
= ov5640_read_reg16(sensor
, OV5640_REG_AEC_PK_REAL_GAIN
, &gain
);
1003 return gain
& 0x3ff;
1006 static int ov5640_set_stream_dvp(struct ov5640_dev
*sensor
, bool on
)
1009 unsigned int flags
= sensor
->ep
.bus
.parallel
.flags
;
1015 * Note about parallel port configuration.
1017 * When configured in parallel mode, the OV5640 will
1018 * output 10 bits data on DVP data lines [9:0].
1019 * If only 8 bits data are wanted, the 8 bits data lines
1020 * of the camera interface must be physically connected
1021 * on the DVP data lines [9:2].
1023 * Control lines polarity can be configured through
1024 * devicetree endpoint control lines properties.
1025 * If no endpoint control lines properties are set,
1026 * polarity will be as below:
1027 * - VSYNC: active high
1028 * - HREF: active low
1029 * - PCLK: active low
1034 * reset MIPI PCLK/SERCLK divider
1037 * - [3..0]: MIPI PCLK/SERCLK divider
1039 ret
= ov5640_mod_reg(sensor
, OV5640_REG_SC_PLL_CTRL1
, 0x0f, 0);
1044 * configure parallel port control lines polarity
1047 * - [5]: PCLK polarity (0: active low, 1: active high)
1048 * - [1]: HREF polarity (0: active low, 1: active high)
1049 * - [0]: VSYNC polarity (mismatch here between
1050 * datasheet and hardware, 0 is active high
1051 * and 1 is active low...)
1053 if (flags
& V4L2_MBUS_PCLK_SAMPLE_RISING
)
1055 if (flags
& V4L2_MBUS_HSYNC_ACTIVE_HIGH
)
1057 if (flags
& V4L2_MBUS_VSYNC_ACTIVE_LOW
)
1060 ret
= ov5640_write_reg(sensor
,
1061 OV5640_REG_POLARITY_CTRL00
,
1071 * powerdown MIPI TX/RX PHY & disable MIPI
1078 ret
= ov5640_write_reg(sensor
,
1079 OV5640_REG_IO_MIPI_CTRL00
, on
? 0x18 : 0);
1084 * enable VSYNC/HREF/PCLK DVP control lines
1085 * & D[9:6] DVP data lines
1087 * PAD OUTPUT ENABLE 01
1088 * - 6: VSYNC output enable
1089 * - 5: HREF output enable
1090 * - 4: PCLK output enable
1091 * - [3:0]: D[9:6] output enable
1093 ret
= ov5640_write_reg(sensor
,
1094 OV5640_REG_PAD_OUTPUT_ENABLE01
,
1100 * enable D[5:0] DVP data lines
1102 * PAD OUTPUT ENABLE 02
1103 * - [7:2]: D[5:0] output enable
1105 return ov5640_write_reg(sensor
,
1106 OV5640_REG_PAD_OUTPUT_ENABLE02
,
1110 static int ov5640_set_stream_mipi(struct ov5640_dev
*sensor
, bool on
)
1114 ret
= ov5640_mod_reg(sensor
, OV5640_REG_MIPI_CTRL00
, BIT(5),
1118 ret
= ov5640_write_reg(sensor
, OV5640_REG_PAD_OUTPUT00
,
1123 return ov5640_write_reg(sensor
, OV5640_REG_FRAME_CTRL01
,
1127 static int ov5640_get_sysclk(struct ov5640_dev
*sensor
)
1129 /* calculate sysclk */
1130 u32 xvclk
= sensor
->xclk_freq
/ 10000;
1131 u32 multiplier
, prediv
, VCO
, sysdiv
, pll_rdiv
;
1132 u32 sclk_rdiv_map
[] = {1, 2, 4, 8};
1133 u32 bit_div2x
= 1, sclk_rdiv
, sysclk
;
1137 ret
= ov5640_read_reg(sensor
, OV5640_REG_SC_PLL_CTRL0
, &temp1
);
1140 temp2
= temp1
& 0x0f;
1141 if (temp2
== 8 || temp2
== 10)
1142 bit_div2x
= temp2
/ 2;
1144 ret
= ov5640_read_reg(sensor
, OV5640_REG_SC_PLL_CTRL1
, &temp1
);
1147 sysdiv
= temp1
>> 4;
1151 ret
= ov5640_read_reg(sensor
, OV5640_REG_SC_PLL_CTRL2
, &temp1
);
1156 ret
= ov5640_read_reg(sensor
, OV5640_REG_SC_PLL_CTRL3
, &temp1
);
1159 prediv
= temp1
& 0x0f;
1160 pll_rdiv
= ((temp1
>> 4) & 0x01) + 1;
1162 ret
= ov5640_read_reg(sensor
, OV5640_REG_SYS_ROOT_DIVIDER
, &temp1
);
1165 temp2
= temp1
& 0x03;
1166 sclk_rdiv
= sclk_rdiv_map
[temp2
];
1168 if (!prediv
|| !sysdiv
|| !pll_rdiv
|| !bit_div2x
)
1171 VCO
= xvclk
* multiplier
/ prediv
;
1173 sysclk
= VCO
/ sysdiv
/ pll_rdiv
* 2 / bit_div2x
/ sclk_rdiv
;
1178 static int ov5640_set_night_mode(struct ov5640_dev
*sensor
)
1180 /* read HTS from register settings */
1184 ret
= ov5640_read_reg(sensor
, OV5640_REG_AEC_CTRL00
, &mode
);
1188 return ov5640_write_reg(sensor
, OV5640_REG_AEC_CTRL00
, mode
);
1191 static int ov5640_get_hts(struct ov5640_dev
*sensor
)
1193 /* read HTS from register settings */
1197 ret
= ov5640_read_reg16(sensor
, OV5640_REG_TIMING_HTS
, &hts
);
1203 static int ov5640_get_vts(struct ov5640_dev
*sensor
)
1208 ret
= ov5640_read_reg16(sensor
, OV5640_REG_TIMING_VTS
, &vts
);
1214 static int ov5640_set_vts(struct ov5640_dev
*sensor
, int vts
)
1216 return ov5640_write_reg16(sensor
, OV5640_REG_TIMING_VTS
, vts
);
1219 static int ov5640_get_light_freq(struct ov5640_dev
*sensor
)
1221 /* get banding filter value */
1222 int ret
, light_freq
= 0;
1225 ret
= ov5640_read_reg(sensor
, OV5640_REG_HZ5060_CTRL01
, &temp
);
1231 ret
= ov5640_read_reg(sensor
, OV5640_REG_HZ5060_CTRL00
,
1244 ret
= ov5640_read_reg(sensor
, OV5640_REG_SIGMADELTA_CTRL0C
,
1260 static int ov5640_set_bandingfilter(struct ov5640_dev
*sensor
)
1262 u32 band_step60
, max_band60
, band_step50
, max_band50
, prev_vts
;
1265 /* read preview PCLK */
1266 ret
= ov5640_get_sysclk(sensor
);
1271 sensor
->prev_sysclk
= ret
;
1272 /* read preview HTS */
1273 ret
= ov5640_get_hts(sensor
);
1278 sensor
->prev_hts
= ret
;
1280 /* read preview VTS */
1281 ret
= ov5640_get_vts(sensor
);
1287 /* calculate banding filter */
1289 band_step60
= sensor
->prev_sysclk
* 100 / sensor
->prev_hts
* 100 / 120;
1290 ret
= ov5640_write_reg16(sensor
, OV5640_REG_AEC_B60_STEP
, band_step60
);
1295 max_band60
= (int)((prev_vts
- 4) / band_step60
);
1296 ret
= ov5640_write_reg(sensor
, OV5640_REG_AEC_CTRL0D
, max_band60
);
1301 band_step50
= sensor
->prev_sysclk
* 100 / sensor
->prev_hts
;
1302 ret
= ov5640_write_reg16(sensor
, OV5640_REG_AEC_B50_STEP
, band_step50
);
1307 max_band50
= (int)((prev_vts
- 4) / band_step50
);
1308 return ov5640_write_reg(sensor
, OV5640_REG_AEC_CTRL0E
, max_band50
);
1311 static int ov5640_set_ae_target(struct ov5640_dev
*sensor
, int target
)
1313 /* stable in high */
1314 u32 fast_high
, fast_low
;
1317 sensor
->ae_low
= target
* 23 / 25; /* 0.92 */
1318 sensor
->ae_high
= target
* 27 / 25; /* 1.08 */
1320 fast_high
= sensor
->ae_high
<< 1;
1321 if (fast_high
> 255)
1324 fast_low
= sensor
->ae_low
>> 1;
1326 ret
= ov5640_write_reg(sensor
, OV5640_REG_AEC_CTRL0F
, sensor
->ae_high
);
1329 ret
= ov5640_write_reg(sensor
, OV5640_REG_AEC_CTRL10
, sensor
->ae_low
);
1332 ret
= ov5640_write_reg(sensor
, OV5640_REG_AEC_CTRL1B
, sensor
->ae_high
);
1335 ret
= ov5640_write_reg(sensor
, OV5640_REG_AEC_CTRL1E
, sensor
->ae_low
);
1338 ret
= ov5640_write_reg(sensor
, OV5640_REG_AEC_CTRL11
, fast_high
);
1341 return ov5640_write_reg(sensor
, OV5640_REG_AEC_CTRL1F
, fast_low
);
1344 static int ov5640_binning_on(struct ov5640_dev
*sensor
)
1349 ret
= ov5640_read_reg(sensor
, OV5640_REG_TIMING_TC_REG21
, &temp
);
1353 return temp
? 1 : 0;
1356 static int ov5640_set_virtual_channel(struct ov5640_dev
*sensor
)
1358 u8 temp
, channel
= virtual_channel
;
1364 ret
= ov5640_read_reg(sensor
, OV5640_REG_DEBUG_MODE
, &temp
);
1368 temp
|= (channel
<< 6);
1369 return ov5640_write_reg(sensor
, OV5640_REG_DEBUG_MODE
, temp
);
1372 static const struct ov5640_mode_info
*
1373 ov5640_find_mode(struct ov5640_dev
*sensor
, enum ov5640_frame_rate fr
,
1374 int width
, int height
, bool nearest
)
1376 const struct ov5640_mode_info
*mode
= NULL
;
1379 for (i
= OV5640_NUM_MODES
- 1; i
>= 0; i
--) {
1380 mode
= &ov5640_mode_data
[fr
][i
];
1382 if (!mode
->reg_data
)
1385 if ((nearest
&& mode
->width
<= width
&&
1386 mode
->height
<= height
) ||
1387 (!nearest
&& mode
->width
== width
&&
1388 mode
->height
== height
))
1392 if (nearest
&& i
< 0)
1393 mode
= &ov5640_mode_data
[fr
][0];
1399 * sensor changes between scaling and subsampling, go through
1400 * exposure calculation
1402 static int ov5640_set_mode_exposure_calc(
1403 struct ov5640_dev
*sensor
, const struct ov5640_mode_info
*mode
)
1405 u32 prev_shutter
, prev_gain16
;
1406 u32 cap_shutter
, cap_gain16
;
1407 u32 cap_sysclk
, cap_hts
, cap_vts
;
1408 u32 light_freq
, cap_bandfilt
, cap_maxband
;
1409 u32 cap_gain16_shutter
;
1413 if (mode
->reg_data
== NULL
)
1416 /* read preview shutter */
1417 ret
= ov5640_get_exposure(sensor
);
1421 ret
= ov5640_binning_on(sensor
);
1424 if (ret
&& mode
->id
!= OV5640_MODE_720P_1280_720
&&
1425 mode
->id
!= OV5640_MODE_1080P_1920_1080
)
1428 /* read preview gain */
1429 ret
= ov5640_get_gain(sensor
);
1435 ret
= ov5640_read_reg(sensor
, OV5640_REG_AVG_READOUT
, &average
);
1439 /* turn off night mode for capture */
1440 ret
= ov5640_set_night_mode(sensor
);
1444 /* Write capture setting */
1445 ret
= ov5640_load_regs(sensor
, mode
);
1449 /* read capture VTS */
1450 ret
= ov5640_get_vts(sensor
);
1454 ret
= ov5640_get_hts(sensor
);
1461 ret
= ov5640_get_sysclk(sensor
);
1468 /* calculate capture banding filter */
1469 ret
= ov5640_get_light_freq(sensor
);
1474 if (light_freq
== 60) {
1476 cap_bandfilt
= cap_sysclk
* 100 / cap_hts
* 100 / 120;
1479 cap_bandfilt
= cap_sysclk
* 100 / cap_hts
;
1482 if (!sensor
->prev_sysclk
) {
1483 ret
= ov5640_get_sysclk(sensor
);
1488 sensor
->prev_sysclk
= ret
;
1494 cap_maxband
= (int)((cap_vts
- 4) / cap_bandfilt
);
1496 /* calculate capture shutter/gain16 */
1497 if (average
> sensor
->ae_low
&& average
< sensor
->ae_high
) {
1498 /* in stable range */
1499 cap_gain16_shutter
=
1500 prev_gain16
* prev_shutter
*
1501 cap_sysclk
/ sensor
->prev_sysclk
*
1502 sensor
->prev_hts
/ cap_hts
*
1503 sensor
->ae_target
/ average
;
1505 cap_gain16_shutter
=
1506 prev_gain16
* prev_shutter
*
1507 cap_sysclk
/ sensor
->prev_sysclk
*
1508 sensor
->prev_hts
/ cap_hts
;
1511 /* gain to shutter */
1512 if (cap_gain16_shutter
< (cap_bandfilt
* 16)) {
1513 /* shutter < 1/100 */
1514 cap_shutter
= cap_gain16_shutter
/ 16;
1515 if (cap_shutter
< 1)
1518 cap_gain16
= cap_gain16_shutter
/ cap_shutter
;
1519 if (cap_gain16
< 16)
1522 if (cap_gain16_shutter
> (cap_bandfilt
* cap_maxband
* 16)) {
1523 /* exposure reach max */
1524 cap_shutter
= cap_bandfilt
* cap_maxband
;
1528 cap_gain16
= cap_gain16_shutter
/ cap_shutter
;
1530 /* 1/100 < (cap_shutter = n/100) =< max */
1532 ((int)(cap_gain16_shutter
/ 16 / cap_bandfilt
))
1537 cap_gain16
= cap_gain16_shutter
/ cap_shutter
;
1541 /* set capture gain */
1542 ret
= __v4l2_ctrl_s_ctrl(sensor
->ctrls
.gain
, cap_gain16
);
1546 /* write capture shutter */
1547 if (cap_shutter
> (cap_vts
- 4)) {
1548 cap_vts
= cap_shutter
+ 4;
1549 ret
= ov5640_set_vts(sensor
, cap_vts
);
1555 return __v4l2_ctrl_s_ctrl(sensor
->ctrls
.exposure
, cap_shutter
);
1559 * if sensor changes inside scaling or subsampling
1560 * change mode directly
1562 static int ov5640_set_mode_direct(struct ov5640_dev
*sensor
,
1563 const struct ov5640_mode_info
*mode
)
1567 if (mode
->reg_data
== NULL
)
1570 /* Write capture setting */
1571 ret
= ov5640_load_regs(sensor
, mode
);
1575 /* turn auto gain/exposure back on for direct mode */
1576 ret
= __v4l2_ctrl_s_ctrl(sensor
->ctrls
.auto_gain
, 1);
1579 return __v4l2_ctrl_s_ctrl(sensor
->ctrls
.auto_exp
, V4L2_EXPOSURE_AUTO
);
1582 static int ov5640_set_mode(struct ov5640_dev
*sensor
,
1583 const struct ov5640_mode_info
*orig_mode
)
1585 const struct ov5640_mode_info
*mode
= sensor
->current_mode
;
1586 enum ov5640_downsize_mode dn_mode
, orig_dn_mode
;
1589 dn_mode
= mode
->dn_mode
;
1590 orig_dn_mode
= orig_mode
->dn_mode
;
1592 /* auto gain and exposure must be turned off when changing modes */
1593 ret
= __v4l2_ctrl_s_ctrl(sensor
->ctrls
.auto_gain
, 0);
1596 ret
= __v4l2_ctrl_s_ctrl(sensor
->ctrls
.auto_exp
, V4L2_EXPOSURE_MANUAL
);
1600 if ((dn_mode
== SUBSAMPLING
&& orig_dn_mode
== SCALING
) ||
1601 (dn_mode
== SCALING
&& orig_dn_mode
== SUBSAMPLING
)) {
1603 * change between subsampling and scaling
1604 * go through exposure calucation
1606 ret
= ov5640_set_mode_exposure_calc(sensor
, mode
);
1609 * change inside subsampling or scaling
1610 * download firmware directly
1612 ret
= ov5640_set_mode_direct(sensor
, mode
);
1618 ret
= ov5640_set_ae_target(sensor
, sensor
->ae_target
);
1621 ret
= ov5640_get_light_freq(sensor
);
1624 ret
= ov5640_set_bandingfilter(sensor
);
1627 ret
= ov5640_set_virtual_channel(sensor
);
1631 sensor
->pending_mode_change
= false;
1636 /* restore the last set video mode after chip power-on */
1637 static int ov5640_restore_mode(struct ov5640_dev
*sensor
)
1641 /* first load the initial register values */
1642 ret
= ov5640_load_regs(sensor
, &ov5640_mode_init_data
);
1646 /* now restore the last capture mode */
1647 return ov5640_set_mode(sensor
, &ov5640_mode_init_data
);
1650 static void ov5640_power(struct ov5640_dev
*sensor
, bool enable
)
1652 gpiod_set_value_cansleep(sensor
->pwdn_gpio
, enable
? 0 : 1);
1655 static void ov5640_reset(struct ov5640_dev
*sensor
)
1657 if (!sensor
->reset_gpio
)
1660 gpiod_set_value_cansleep(sensor
->reset_gpio
, 0);
1662 /* camera power cycle */
1663 ov5640_power(sensor
, false);
1664 usleep_range(5000, 10000);
1665 ov5640_power(sensor
, true);
1666 usleep_range(5000, 10000);
1668 gpiod_set_value_cansleep(sensor
->reset_gpio
, 1);
1669 usleep_range(1000, 2000);
1671 gpiod_set_value_cansleep(sensor
->reset_gpio
, 0);
1672 usleep_range(5000, 10000);
1675 static int ov5640_set_power_on(struct ov5640_dev
*sensor
)
1677 struct i2c_client
*client
= sensor
->i2c_client
;
1680 ret
= clk_prepare_enable(sensor
->xclk
);
1682 dev_err(&client
->dev
, "%s: failed to enable clock\n",
1687 ret
= regulator_bulk_enable(OV5640_NUM_SUPPLIES
,
1690 dev_err(&client
->dev
, "%s: failed to enable regulators\n",
1695 ov5640_reset(sensor
);
1696 ov5640_power(sensor
, true);
1698 ret
= ov5640_init_slave_id(sensor
);
1705 ov5640_power(sensor
, false);
1706 regulator_bulk_disable(OV5640_NUM_SUPPLIES
, sensor
->supplies
);
1708 clk_disable_unprepare(sensor
->xclk
);
1712 static void ov5640_set_power_off(struct ov5640_dev
*sensor
)
1714 ov5640_power(sensor
, false);
1715 regulator_bulk_disable(OV5640_NUM_SUPPLIES
, sensor
->supplies
);
1716 clk_disable_unprepare(sensor
->xclk
);
1719 static int ov5640_set_power(struct ov5640_dev
*sensor
, bool on
)
1724 ret
= ov5640_set_power_on(sensor
);
1728 ret
= ov5640_restore_mode(sensor
);
1732 if (sensor
->ep
.bus_type
== V4L2_MBUS_CSI2
) {
1734 * start streaming briefly followed by stream off in
1735 * order to coax the clock lane into LP-11 state.
1737 ret
= ov5640_set_stream_mipi(sensor
, true);
1740 usleep_range(1000, 2000);
1741 ret
= ov5640_set_stream_mipi(sensor
, false);
1750 ov5640_set_power_off(sensor
);
1754 /* --------------- Subdev Operations --------------- */
1756 static int ov5640_s_power(struct v4l2_subdev
*sd
, int on
)
1758 struct ov5640_dev
*sensor
= to_ov5640_dev(sd
);
1761 mutex_lock(&sensor
->lock
);
1764 * If the power count is modified from 0 to != 0 or from != 0 to 0,
1765 * update the power state.
1767 if (sensor
->power_count
== !on
) {
1768 ret
= ov5640_set_power(sensor
, !!on
);
1773 /* Update the power count. */
1774 sensor
->power_count
+= on
? 1 : -1;
1775 WARN_ON(sensor
->power_count
< 0);
1777 mutex_unlock(&sensor
->lock
);
1779 if (on
&& !ret
&& sensor
->power_count
== 1) {
1780 /* restore controls */
1781 ret
= v4l2_ctrl_handler_setup(&sensor
->ctrls
.handler
);
1787 static int ov5640_try_frame_interval(struct ov5640_dev
*sensor
,
1788 struct v4l2_fract
*fi
,
1789 u32 width
, u32 height
)
1791 const struct ov5640_mode_info
*mode
;
1792 u32 minfps
, maxfps
, fps
;
1795 minfps
= ov5640_framerates
[OV5640_15_FPS
];
1796 maxfps
= ov5640_framerates
[OV5640_30_FPS
];
1798 if (fi
->numerator
== 0) {
1799 fi
->denominator
= maxfps
;
1801 return OV5640_30_FPS
;
1804 fps
= DIV_ROUND_CLOSEST(fi
->denominator
, fi
->numerator
);
1808 fi
->denominator
= maxfps
;
1809 else if (fps
< minfps
)
1810 fi
->denominator
= minfps
;
1811 else if (2 * fps
>= 2 * minfps
+ (maxfps
- minfps
))
1812 fi
->denominator
= maxfps
;
1814 fi
->denominator
= minfps
;
1816 ret
= (fi
->denominator
== minfps
) ? OV5640_15_FPS
: OV5640_30_FPS
;
1818 mode
= ov5640_find_mode(sensor
, ret
, width
, height
, false);
1819 return mode
? ret
: -EINVAL
;
1822 static int ov5640_get_fmt(struct v4l2_subdev
*sd
,
1823 struct v4l2_subdev_pad_config
*cfg
,
1824 struct v4l2_subdev_format
*format
)
1826 struct ov5640_dev
*sensor
= to_ov5640_dev(sd
);
1827 struct v4l2_mbus_framefmt
*fmt
;
1829 if (format
->pad
!= 0)
1832 mutex_lock(&sensor
->lock
);
1834 if (format
->which
== V4L2_SUBDEV_FORMAT_TRY
)
1835 fmt
= v4l2_subdev_get_try_format(&sensor
->sd
, cfg
,
1840 format
->format
= *fmt
;
1842 mutex_unlock(&sensor
->lock
);
1847 static int ov5640_try_fmt_internal(struct v4l2_subdev
*sd
,
1848 struct v4l2_mbus_framefmt
*fmt
,
1849 enum ov5640_frame_rate fr
,
1850 const struct ov5640_mode_info
**new_mode
)
1852 struct ov5640_dev
*sensor
= to_ov5640_dev(sd
);
1853 const struct ov5640_mode_info
*mode
;
1856 mode
= ov5640_find_mode(sensor
, fr
, fmt
->width
, fmt
->height
, true);
1859 fmt
->width
= mode
->width
;
1860 fmt
->height
= mode
->height
;
1865 for (i
= 0; i
< ARRAY_SIZE(ov5640_formats
); i
++)
1866 if (ov5640_formats
[i
].code
== fmt
->code
)
1868 if (i
>= ARRAY_SIZE(ov5640_formats
))
1869 fmt
->code
= ov5640_formats
[0].code
;
1874 static int ov5640_set_fmt(struct v4l2_subdev
*sd
,
1875 struct v4l2_subdev_pad_config
*cfg
,
1876 struct v4l2_subdev_format
*format
)
1878 struct ov5640_dev
*sensor
= to_ov5640_dev(sd
);
1879 const struct ov5640_mode_info
*new_mode
;
1882 if (format
->pad
!= 0)
1885 mutex_lock(&sensor
->lock
);
1887 if (sensor
->streaming
) {
1892 ret
= ov5640_try_fmt_internal(sd
, &format
->format
,
1893 sensor
->current_fr
, &new_mode
);
1897 if (format
->which
== V4L2_SUBDEV_FORMAT_TRY
) {
1898 struct v4l2_mbus_framefmt
*fmt
=
1899 v4l2_subdev_get_try_format(sd
, cfg
, 0);
1901 *fmt
= format
->format
;
1905 sensor
->current_mode
= new_mode
;
1906 sensor
->fmt
= format
->format
;
1907 sensor
->pending_mode_change
= true;
1909 mutex_unlock(&sensor
->lock
);
1913 static int ov5640_set_framefmt(struct ov5640_dev
*sensor
,
1914 struct v4l2_mbus_framefmt
*format
)
1917 bool is_rgb
= false;
1920 switch (format
->code
) {
1921 case MEDIA_BUS_FMT_UYVY8_2X8
:
1925 case MEDIA_BUS_FMT_YUYV8_2X8
:
1929 case MEDIA_BUS_FMT_RGB565_2X8_LE
:
1930 /* RGB565 {g[2:0],b[4:0]},{r[4:0],g[5:3]} */
1934 case MEDIA_BUS_FMT_RGB565_2X8_BE
:
1935 /* RGB565 {r[4:0],g[5:3]},{g[2:0],b[4:0]} */
1943 /* FORMAT CONTROL00: YUV and RGB formatting */
1944 ret
= ov5640_write_reg(sensor
, OV5640_REG_FORMAT_CONTROL00
, val
);
1948 /* FORMAT MUX CONTROL: ISP YUV or RGB */
1949 return ov5640_write_reg(sensor
, OV5640_REG_ISP_FORMAT_MUX_CTRL
,
1950 is_rgb
? 0x01 : 0x00);
1957 static int ov5640_set_ctrl_hue(struct ov5640_dev
*sensor
, int value
)
1962 ret
= ov5640_mod_reg(sensor
, OV5640_REG_SDE_CTRL0
,
1966 ret
= ov5640_write_reg16(sensor
, OV5640_REG_SDE_CTRL1
, value
);
1968 ret
= ov5640_mod_reg(sensor
, OV5640_REG_SDE_CTRL0
, BIT(0), 0);
1974 static int ov5640_set_ctrl_contrast(struct ov5640_dev
*sensor
, int value
)
1979 ret
= ov5640_mod_reg(sensor
, OV5640_REG_SDE_CTRL0
,
1983 ret
= ov5640_write_reg(sensor
, OV5640_REG_SDE_CTRL5
,
1986 ret
= ov5640_mod_reg(sensor
, OV5640_REG_SDE_CTRL0
, BIT(2), 0);
1992 static int ov5640_set_ctrl_saturation(struct ov5640_dev
*sensor
, int value
)
1997 ret
= ov5640_mod_reg(sensor
, OV5640_REG_SDE_CTRL0
,
2001 ret
= ov5640_write_reg(sensor
, OV5640_REG_SDE_CTRL3
,
2005 ret
= ov5640_write_reg(sensor
, OV5640_REG_SDE_CTRL4
,
2008 ret
= ov5640_mod_reg(sensor
, OV5640_REG_SDE_CTRL0
, BIT(1), 0);
2014 static int ov5640_set_ctrl_white_balance(struct ov5640_dev
*sensor
, int awb
)
2018 ret
= ov5640_mod_reg(sensor
, OV5640_REG_AWB_MANUAL_CTRL
,
2019 BIT(0), awb
? 0 : 1);
2024 u16 red
= (u16
)sensor
->ctrls
.red_balance
->val
;
2025 u16 blue
= (u16
)sensor
->ctrls
.blue_balance
->val
;
2027 ret
= ov5640_write_reg16(sensor
, OV5640_REG_AWB_R_GAIN
, red
);
2030 ret
= ov5640_write_reg16(sensor
, OV5640_REG_AWB_B_GAIN
, blue
);
2036 static int ov5640_set_ctrl_exposure(struct ov5640_dev
*sensor
, int exp
)
2038 struct ov5640_ctrls
*ctrls
= &sensor
->ctrls
;
2039 bool auto_exposure
= (exp
== V4L2_EXPOSURE_AUTO
);
2042 if (ctrls
->auto_exp
->is_new
) {
2043 ret
= ov5640_mod_reg(sensor
, OV5640_REG_AEC_PK_MANUAL
,
2044 BIT(0), auto_exposure
? 0 : BIT(0));
2049 if (!auto_exposure
&& ctrls
->exposure
->is_new
) {
2052 ret
= ov5640_read_reg16(sensor
, OV5640_REG_AEC_PK_VTS
,
2056 ret
= ov5640_get_vts(sensor
);
2062 if (ctrls
->exposure
->val
< max_exp
)
2063 ret
= ov5640_set_exposure(sensor
, ctrls
->exposure
->val
);
2069 static int ov5640_set_ctrl_gain(struct ov5640_dev
*sensor
, int auto_gain
)
2071 struct ov5640_ctrls
*ctrls
= &sensor
->ctrls
;
2074 if (ctrls
->auto_gain
->is_new
) {
2075 ret
= ov5640_mod_reg(sensor
, OV5640_REG_AEC_PK_MANUAL
,
2076 BIT(1), ctrls
->auto_gain
->val
? 0 : BIT(1));
2081 if (!auto_gain
&& ctrls
->gain
->is_new
) {
2082 u16 gain
= (u16
)ctrls
->gain
->val
;
2084 ret
= ov5640_write_reg16(sensor
, OV5640_REG_AEC_PK_REAL_GAIN
,
2091 static int ov5640_set_ctrl_test_pattern(struct ov5640_dev
*sensor
, int value
)
2093 return ov5640_mod_reg(sensor
, OV5640_REG_PRE_ISP_TEST_SET1
,
2094 0xa4, value
? 0xa4 : 0);
2097 static int ov5640_g_volatile_ctrl(struct v4l2_ctrl
*ctrl
)
2099 struct v4l2_subdev
*sd
= ctrl_to_sd(ctrl
);
2100 struct ov5640_dev
*sensor
= to_ov5640_dev(sd
);
2103 /* v4l2_ctrl_lock() locks our own mutex */
2106 case V4L2_CID_AUTOGAIN
:
2109 val
= ov5640_get_gain(sensor
);
2112 sensor
->ctrls
.gain
->val
= val
;
2114 case V4L2_CID_EXPOSURE_AUTO
:
2115 if (ctrl
->val
== V4L2_EXPOSURE_MANUAL
)
2117 val
= ov5640_get_exposure(sensor
);
2120 sensor
->ctrls
.exposure
->val
= val
;
2127 static int ov5640_s_ctrl(struct v4l2_ctrl
*ctrl
)
2129 struct v4l2_subdev
*sd
= ctrl_to_sd(ctrl
);
2130 struct ov5640_dev
*sensor
= to_ov5640_dev(sd
);
2133 /* v4l2_ctrl_lock() locks our own mutex */
2136 * If the device is not powered up by the host driver do
2137 * not apply any controls to H/W at this time. Instead
2138 * the controls will be restored right after power-up.
2140 if (sensor
->power_count
== 0)
2144 case V4L2_CID_AUTOGAIN
:
2145 ret
= ov5640_set_ctrl_gain(sensor
, ctrl
->val
);
2147 case V4L2_CID_EXPOSURE_AUTO
:
2148 ret
= ov5640_set_ctrl_exposure(sensor
, ctrl
->val
);
2150 case V4L2_CID_AUTO_WHITE_BALANCE
:
2151 ret
= ov5640_set_ctrl_white_balance(sensor
, ctrl
->val
);
2154 ret
= ov5640_set_ctrl_hue(sensor
, ctrl
->val
);
2156 case V4L2_CID_CONTRAST
:
2157 ret
= ov5640_set_ctrl_contrast(sensor
, ctrl
->val
);
2159 case V4L2_CID_SATURATION
:
2160 ret
= ov5640_set_ctrl_saturation(sensor
, ctrl
->val
);
2162 case V4L2_CID_TEST_PATTERN
:
2163 ret
= ov5640_set_ctrl_test_pattern(sensor
, ctrl
->val
);
2173 static const struct v4l2_ctrl_ops ov5640_ctrl_ops
= {
2174 .g_volatile_ctrl
= ov5640_g_volatile_ctrl
,
2175 .s_ctrl
= ov5640_s_ctrl
,
2178 static const char * const test_pattern_menu
[] = {
2183 static int ov5640_init_controls(struct ov5640_dev
*sensor
)
2185 const struct v4l2_ctrl_ops
*ops
= &ov5640_ctrl_ops
;
2186 struct ov5640_ctrls
*ctrls
= &sensor
->ctrls
;
2187 struct v4l2_ctrl_handler
*hdl
= &ctrls
->handler
;
2190 v4l2_ctrl_handler_init(hdl
, 32);
2192 /* we can use our own mutex for the ctrl lock */
2193 hdl
->lock
= &sensor
->lock
;
2195 /* Auto/manual white balance */
2196 ctrls
->auto_wb
= v4l2_ctrl_new_std(hdl
, ops
,
2197 V4L2_CID_AUTO_WHITE_BALANCE
,
2199 ctrls
->blue_balance
= v4l2_ctrl_new_std(hdl
, ops
, V4L2_CID_BLUE_BALANCE
,
2201 ctrls
->red_balance
= v4l2_ctrl_new_std(hdl
, ops
, V4L2_CID_RED_BALANCE
,
2203 /* Auto/manual exposure */
2204 ctrls
->auto_exp
= v4l2_ctrl_new_std_menu(hdl
, ops
,
2205 V4L2_CID_EXPOSURE_AUTO
,
2206 V4L2_EXPOSURE_MANUAL
, 0,
2207 V4L2_EXPOSURE_AUTO
);
2208 ctrls
->exposure
= v4l2_ctrl_new_std(hdl
, ops
, V4L2_CID_EXPOSURE
,
2210 /* Auto/manual gain */
2211 ctrls
->auto_gain
= v4l2_ctrl_new_std(hdl
, ops
, V4L2_CID_AUTOGAIN
,
2213 ctrls
->gain
= v4l2_ctrl_new_std(hdl
, ops
, V4L2_CID_GAIN
,
2216 ctrls
->saturation
= v4l2_ctrl_new_std(hdl
, ops
, V4L2_CID_SATURATION
,
2218 ctrls
->hue
= v4l2_ctrl_new_std(hdl
, ops
, V4L2_CID_HUE
,
2220 ctrls
->contrast
= v4l2_ctrl_new_std(hdl
, ops
, V4L2_CID_CONTRAST
,
2222 ctrls
->test_pattern
=
2223 v4l2_ctrl_new_std_menu_items(hdl
, ops
, V4L2_CID_TEST_PATTERN
,
2224 ARRAY_SIZE(test_pattern_menu
) - 1,
2225 0, 0, test_pattern_menu
);
2232 ctrls
->gain
->flags
|= V4L2_CTRL_FLAG_VOLATILE
;
2233 ctrls
->exposure
->flags
|= V4L2_CTRL_FLAG_VOLATILE
;
2235 v4l2_ctrl_auto_cluster(3, &ctrls
->auto_wb
, 0, false);
2236 v4l2_ctrl_auto_cluster(2, &ctrls
->auto_gain
, 0, true);
2237 v4l2_ctrl_auto_cluster(2, &ctrls
->auto_exp
, 1, true);
2239 sensor
->sd
.ctrl_handler
= hdl
;
2243 v4l2_ctrl_handler_free(hdl
);
2247 static int ov5640_enum_frame_size(struct v4l2_subdev
*sd
,
2248 struct v4l2_subdev_pad_config
*cfg
,
2249 struct v4l2_subdev_frame_size_enum
*fse
)
2253 if (fse
->index
>= OV5640_NUM_MODES
)
2256 fse
->min_width
= fse
->max_width
=
2257 ov5640_mode_data
[0][fse
->index
].width
;
2258 fse
->min_height
= fse
->max_height
=
2259 ov5640_mode_data
[0][fse
->index
].height
;
2264 static int ov5640_enum_frame_interval(
2265 struct v4l2_subdev
*sd
,
2266 struct v4l2_subdev_pad_config
*cfg
,
2267 struct v4l2_subdev_frame_interval_enum
*fie
)
2269 struct ov5640_dev
*sensor
= to_ov5640_dev(sd
);
2270 struct v4l2_fract tpf
;
2275 if (fie
->index
>= OV5640_NUM_FRAMERATES
)
2279 tpf
.denominator
= ov5640_framerates
[fie
->index
];
2281 ret
= ov5640_try_frame_interval(sensor
, &tpf
,
2282 fie
->width
, fie
->height
);
2286 fie
->interval
= tpf
;
2290 static int ov5640_g_frame_interval(struct v4l2_subdev
*sd
,
2291 struct v4l2_subdev_frame_interval
*fi
)
2293 struct ov5640_dev
*sensor
= to_ov5640_dev(sd
);
2295 mutex_lock(&sensor
->lock
);
2296 fi
->interval
= sensor
->frame_interval
;
2297 mutex_unlock(&sensor
->lock
);
2302 static int ov5640_s_frame_interval(struct v4l2_subdev
*sd
,
2303 struct v4l2_subdev_frame_interval
*fi
)
2305 struct ov5640_dev
*sensor
= to_ov5640_dev(sd
);
2306 const struct ov5640_mode_info
*mode
;
2307 int frame_rate
, ret
= 0;
2312 mutex_lock(&sensor
->lock
);
2314 if (sensor
->streaming
) {
2319 mode
= sensor
->current_mode
;
2321 frame_rate
= ov5640_try_frame_interval(sensor
, &fi
->interval
,
2322 mode
->width
, mode
->height
);
2324 frame_rate
= OV5640_15_FPS
;
2326 sensor
->current_fr
= frame_rate
;
2327 sensor
->frame_interval
= fi
->interval
;
2328 sensor
->pending_mode_change
= true;
2330 mutex_unlock(&sensor
->lock
);
2334 static int ov5640_enum_mbus_code(struct v4l2_subdev
*sd
,
2335 struct v4l2_subdev_pad_config
*cfg
,
2336 struct v4l2_subdev_mbus_code_enum
*code
)
2340 if (code
->index
>= ARRAY_SIZE(ov5640_formats
))
2343 code
->code
= ov5640_formats
[code
->index
].code
;
2347 static int ov5640_s_stream(struct v4l2_subdev
*sd
, int enable
)
2349 struct ov5640_dev
*sensor
= to_ov5640_dev(sd
);
2352 mutex_lock(&sensor
->lock
);
2354 if (sensor
->streaming
== !enable
) {
2355 if (enable
&& sensor
->pending_mode_change
) {
2356 ret
= ov5640_set_mode(sensor
, sensor
->current_mode
);
2360 ret
= ov5640_set_framefmt(sensor
, &sensor
->fmt
);
2365 if (sensor
->ep
.bus_type
== V4L2_MBUS_CSI2
)
2366 ret
= ov5640_set_stream_mipi(sensor
, enable
);
2368 ret
= ov5640_set_stream_dvp(sensor
, enable
);
2371 sensor
->streaming
= enable
;
2374 mutex_unlock(&sensor
->lock
);
2378 static const struct v4l2_subdev_core_ops ov5640_core_ops
= {
2379 .s_power
= ov5640_s_power
,
2382 static const struct v4l2_subdev_video_ops ov5640_video_ops
= {
2383 .g_frame_interval
= ov5640_g_frame_interval
,
2384 .s_frame_interval
= ov5640_s_frame_interval
,
2385 .s_stream
= ov5640_s_stream
,
2388 static const struct v4l2_subdev_pad_ops ov5640_pad_ops
= {
2389 .enum_mbus_code
= ov5640_enum_mbus_code
,
2390 .get_fmt
= ov5640_get_fmt
,
2391 .set_fmt
= ov5640_set_fmt
,
2392 .enum_frame_size
= ov5640_enum_frame_size
,
2393 .enum_frame_interval
= ov5640_enum_frame_interval
,
2396 static const struct v4l2_subdev_ops ov5640_subdev_ops
= {
2397 .core
= &ov5640_core_ops
,
2398 .video
= &ov5640_video_ops
,
2399 .pad
= &ov5640_pad_ops
,
2402 static int ov5640_get_regulators(struct ov5640_dev
*sensor
)
2406 for (i
= 0; i
< OV5640_NUM_SUPPLIES
; i
++)
2407 sensor
->supplies
[i
].supply
= ov5640_supply_name
[i
];
2409 return devm_regulator_bulk_get(&sensor
->i2c_client
->dev
,
2410 OV5640_NUM_SUPPLIES
,
2414 static int ov5640_check_chip_id(struct ov5640_dev
*sensor
)
2416 struct i2c_client
*client
= sensor
->i2c_client
;
2420 ret
= ov5640_set_power_on(sensor
);
2424 ret
= ov5640_read_reg16(sensor
, OV5640_REG_CHIP_ID
, &chip_id
);
2426 dev_err(&client
->dev
, "%s: failed to read chip identifier\n",
2431 if (chip_id
!= 0x5640) {
2432 dev_err(&client
->dev
, "%s: wrong chip identifier, expected 0x5640, got 0x%x\n",
2438 ov5640_set_power_off(sensor
);
2442 static int ov5640_probe(struct i2c_client
*client
,
2443 const struct i2c_device_id
*id
)
2445 struct device
*dev
= &client
->dev
;
2446 struct fwnode_handle
*endpoint
;
2447 struct ov5640_dev
*sensor
;
2450 sensor
= devm_kzalloc(dev
, sizeof(*sensor
), GFP_KERNEL
);
2454 sensor
->i2c_client
= client
;
2455 sensor
->fmt
.code
= MEDIA_BUS_FMT_UYVY8_2X8
;
2456 sensor
->fmt
.width
= 640;
2457 sensor
->fmt
.height
= 480;
2458 sensor
->fmt
.field
= V4L2_FIELD_NONE
;
2459 sensor
->frame_interval
.numerator
= 1;
2460 sensor
->frame_interval
.denominator
= ov5640_framerates
[OV5640_30_FPS
];
2461 sensor
->current_fr
= OV5640_30_FPS
;
2462 sensor
->current_mode
=
2463 &ov5640_mode_data
[OV5640_30_FPS
][OV5640_MODE_VGA_640_480
];
2464 sensor
->pending_mode_change
= true;
2466 sensor
->ae_target
= 52;
2468 endpoint
= fwnode_graph_get_next_endpoint(
2469 of_fwnode_handle(client
->dev
.of_node
), NULL
);
2471 dev_err(dev
, "endpoint node not found\n");
2475 ret
= v4l2_fwnode_endpoint_parse(endpoint
, &sensor
->ep
);
2476 fwnode_handle_put(endpoint
);
2478 dev_err(dev
, "Could not parse endpoint\n");
2482 /* get system clock (xclk) */
2483 sensor
->xclk
= devm_clk_get(dev
, "xclk");
2484 if (IS_ERR(sensor
->xclk
)) {
2485 dev_err(dev
, "failed to get xclk\n");
2486 return PTR_ERR(sensor
->xclk
);
2489 sensor
->xclk_freq
= clk_get_rate(sensor
->xclk
);
2490 if (sensor
->xclk_freq
< OV5640_XCLK_MIN
||
2491 sensor
->xclk_freq
> OV5640_XCLK_MAX
) {
2492 dev_err(dev
, "xclk frequency out of range: %d Hz\n",
2497 /* request optional power down pin */
2498 sensor
->pwdn_gpio
= devm_gpiod_get_optional(dev
, "powerdown",
2500 /* request optional reset pin */
2501 sensor
->reset_gpio
= devm_gpiod_get_optional(dev
, "reset",
2504 v4l2_i2c_subdev_init(&sensor
->sd
, client
, &ov5640_subdev_ops
);
2506 sensor
->sd
.flags
|= V4L2_SUBDEV_FL_HAS_DEVNODE
;
2507 sensor
->pad
.flags
= MEDIA_PAD_FL_SOURCE
;
2508 sensor
->sd
.entity
.function
= MEDIA_ENT_F_CAM_SENSOR
;
2509 ret
= media_entity_pads_init(&sensor
->sd
.entity
, 1, &sensor
->pad
);
2513 ret
= ov5640_get_regulators(sensor
);
2517 mutex_init(&sensor
->lock
);
2519 ret
= ov5640_check_chip_id(sensor
);
2521 goto entity_cleanup
;
2523 ret
= ov5640_init_controls(sensor
);
2525 goto entity_cleanup
;
2527 ret
= v4l2_async_register_subdev(&sensor
->sd
);
2534 v4l2_ctrl_handler_free(&sensor
->ctrls
.handler
);
2536 mutex_destroy(&sensor
->lock
);
2537 media_entity_cleanup(&sensor
->sd
.entity
);
2541 static int ov5640_remove(struct i2c_client
*client
)
2543 struct v4l2_subdev
*sd
= i2c_get_clientdata(client
);
2544 struct ov5640_dev
*sensor
= to_ov5640_dev(sd
);
2546 v4l2_async_unregister_subdev(&sensor
->sd
);
2547 mutex_destroy(&sensor
->lock
);
2548 media_entity_cleanup(&sensor
->sd
.entity
);
2549 v4l2_ctrl_handler_free(&sensor
->ctrls
.handler
);
2554 static const struct i2c_device_id ov5640_id
[] = {
2558 MODULE_DEVICE_TABLE(i2c
, ov5640_id
);
2560 static const struct of_device_id ov5640_dt_ids
[] = {
2561 { .compatible
= "ovti,ov5640" },
2564 MODULE_DEVICE_TABLE(of
, ov5640_dt_ids
);
2566 static struct i2c_driver ov5640_i2c_driver
= {
2569 .of_match_table
= ov5640_dt_ids
,
2571 .id_table
= ov5640_id
,
2572 .probe
= ov5640_probe
,
2573 .remove
= ov5640_remove
,
2576 module_i2c_driver(ov5640_i2c_driver
);
2578 MODULE_DESCRIPTION("OV5640 MIPI Camera Subdev Driver");
2579 MODULE_LICENSE("GPL");