aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/video
diff options
context:
space:
mode:
authorBastian Hecht <hechtb@googlemail.com>2011-06-24 06:57:36 -0400
committerMauro Carvalho Chehab <mchehab@redhat.com>2011-07-27 16:56:09 -0400
commitb52a851d9182e8a20704152d537c7e19ed34cc99 (patch)
treef97df2e3dc02a2850d3a46d56262fc29439143ec /drivers/media/video
parentcb74cf5349a6a9225bbab278a808d5a0739c3b2c (diff)
[media] V4L: initial driver for ov5642 CMOS sensor
This is an initial driver release for the Omnivision 5642 CMOS sensor. Signed-off-by: Bastian Hecht <hechtb@gmail.com> Signed-off-by: Guennadi Liakhovetski <g.liakhovetski@gmx.de> Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
Diffstat (limited to 'drivers/media/video')
-rw-r--r--drivers/media/video/Kconfig6
-rw-r--r--drivers/media/video/Makefile1
-rw-r--r--drivers/media/video/ov5642.c1011
3 files changed, 1018 insertions, 0 deletions
diff --git a/drivers/media/video/Kconfig b/drivers/media/video/Kconfig
index 176ac49e9c7..f574dc012ca 100644
--- a/drivers/media/video/Kconfig
+++ b/drivers/media/video/Kconfig
@@ -848,6 +848,12 @@ config SOC_CAMERA_OV2640
848 help 848 help
849 This is a ov2640 camera driver 849 This is a ov2640 camera driver
850 850
851config SOC_CAMERA_OV5642
852 tristate "ov5642 camera support"
853 depends on SOC_CAMERA && I2C
854 help
855 This is a V4L2 camera driver for the OmniVision OV5642 sensor
856
851config SOC_CAMERA_OV6650 857config SOC_CAMERA_OV6650
852 tristate "ov6650 sensor support" 858 tristate "ov6650 sensor support"
853 depends on SOC_CAMERA && I2C 859 depends on SOC_CAMERA && I2C
diff --git a/drivers/media/video/Makefile b/drivers/media/video/Makefile
index 6cca52a7e2d..272390072ae 100644
--- a/drivers/media/video/Makefile
+++ b/drivers/media/video/Makefile
@@ -79,6 +79,7 @@ obj-$(CONFIG_SOC_CAMERA_MT9T031) += mt9t031.o
79obj-$(CONFIG_SOC_CAMERA_MT9T112) += mt9t112.o 79obj-$(CONFIG_SOC_CAMERA_MT9T112) += mt9t112.o
80obj-$(CONFIG_SOC_CAMERA_MT9V022) += mt9v022.o 80obj-$(CONFIG_SOC_CAMERA_MT9V022) += mt9v022.o
81obj-$(CONFIG_SOC_CAMERA_OV2640) += ov2640.o 81obj-$(CONFIG_SOC_CAMERA_OV2640) += ov2640.o
82obj-$(CONFIG_SOC_CAMERA_OV5642) += ov5642.o
82obj-$(CONFIG_SOC_CAMERA_OV6650) += ov6650.o 83obj-$(CONFIG_SOC_CAMERA_OV6650) += ov6650.o
83obj-$(CONFIG_SOC_CAMERA_OV772X) += ov772x.o 84obj-$(CONFIG_SOC_CAMERA_OV772X) += ov772x.o
84obj-$(CONFIG_SOC_CAMERA_OV9640) += ov9640.o 85obj-$(CONFIG_SOC_CAMERA_OV9640) += ov9640.o
diff --git a/drivers/media/video/ov5642.c b/drivers/media/video/ov5642.c
new file mode 100644
index 00000000000..3cdae971dfa
--- /dev/null
+++ b/drivers/media/video/ov5642.c
@@ -0,0 +1,1011 @@
1/*
2 * Driver for OV5642 CMOS Image Sensor from Omnivision
3 *
4 * Copyright (C) 2011, Bastian Hecht <hechtb@gmail.com>
5 *
6 * Based on Sony IMX074 Camera Driver
7 * Copyright (C) 2010, Guennadi Liakhovetski <g.liakhovetski@gmx.de>
8 *
9 * Based on Omnivision OV7670 Camera Driver
10 * Copyright (C) 2006-7 Jonathan Corbet <corbet@lwn.net>
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License version 2 as
14 * published by the Free Software Foundation.
15 */
16
17#include <linux/delay.h>
18#include <linux/i2c.h>
19#include <linux/slab.h>
20#include <linux/videodev2.h>
21
22#include <media/soc_camera.h>
23#include <media/soc_mediabus.h>
24#include <media/v4l2-chip-ident.h>
25#include <media/v4l2-subdev.h>
26
27/* OV5642 registers */
28#define REG_CHIP_ID_HIGH 0x300a
29#define REG_CHIP_ID_LOW 0x300b
30
31#define REG_WINDOW_START_X_HIGH 0x3800
32#define REG_WINDOW_START_X_LOW 0x3801
33#define REG_WINDOW_START_Y_HIGH 0x3802
34#define REG_WINDOW_START_Y_LOW 0x3803
35#define REG_WINDOW_WIDTH_HIGH 0x3804
36#define REG_WINDOW_WIDTH_LOW 0x3805
37#define REG_WINDOW_HEIGHT_HIGH 0x3806
38#define REG_WINDOW_HEIGHT_LOW 0x3807
39#define REG_OUT_WIDTH_HIGH 0x3808
40#define REG_OUT_WIDTH_LOW 0x3809
41#define REG_OUT_HEIGHT_HIGH 0x380a
42#define REG_OUT_HEIGHT_LOW 0x380b
43#define REG_OUT_TOTAL_WIDTH_HIGH 0x380c
44#define REG_OUT_TOTAL_WIDTH_LOW 0x380d
45#define REG_OUT_TOTAL_HEIGHT_HIGH 0x380e
46#define REG_OUT_TOTAL_HEIGHT_LOW 0x380f
47
48/*
49 * define standard resolution.
50 * Works currently only for up to 720 lines
51 * eg. 320x240, 640x480, 800x600, 1280x720, 2048x720
52 */
53
54#define OV5642_WIDTH 1280
55#define OV5642_HEIGHT 720
56#define OV5642_TOTAL_WIDTH 3200
57#define OV5642_TOTAL_HEIGHT 2000
58#define OV5642_SENSOR_SIZE_X 2592
59#define OV5642_SENSOR_SIZE_Y 1944
60
61struct regval_list {
62 u16 reg_num;
63 u8 value;
64};
65
66static struct regval_list ov5642_default_regs_init[] = {
67 { 0x3103, 0x93 },
68 { 0x3008, 0x82 },
69 { 0x3017, 0x7f },
70 { 0x3018, 0xfc },
71 { 0x3810, 0xc2 },
72 { 0x3615, 0xf0 },
73 { 0x3000, 0x0 },
74 { 0x3001, 0x0 },
75 { 0x3002, 0x0 },
76 { 0x3003, 0x0 },
77 { 0x3004, 0xff },
78 { 0x3030, 0x2b },
79 { 0x3011, 0x8 },
80 { 0x3010, 0x10 },
81 { 0x3604, 0x60 },
82 { 0x3622, 0x60 },
83 { 0x3621, 0x9 },
84 { 0x3709, 0x0 },
85 { 0x4000, 0x21 },
86 { 0x401d, 0x22 },
87 { 0x3600, 0x54 },
88 { 0x3605, 0x4 },
89 { 0x3606, 0x3f },
90 { 0x3c01, 0x80 },
91 { 0x300d, 0x22 },
92 { 0x3623, 0x22 },
93 { 0x5000, 0x4f },
94 { 0x5020, 0x4 },
95 { 0x5181, 0x79 },
96 { 0x5182, 0x0 },
97 { 0x5185, 0x22 },
98 { 0x5197, 0x1 },
99 { 0x5500, 0xa },
100 { 0x5504, 0x0 },
101 { 0x5505, 0x7f },
102 { 0x5080, 0x8 },
103 { 0x300e, 0x18 },
104 { 0x4610, 0x0 },
105 { 0x471d, 0x5 },
106 { 0x4708, 0x6 },
107 { 0x370c, 0xa0 },
108 { 0x5687, 0x94 },
109 { 0x501f, 0x0 },
110 { 0x5000, 0x4f },
111 { 0x5001, 0xcf },
112 { 0x4300, 0x30 },
113 { 0x4300, 0x30 },
114 { 0x460b, 0x35 },
115 { 0x471d, 0x0 },
116 { 0x3002, 0xc },
117 { 0x3002, 0x0 },
118 { 0x4713, 0x3 },
119 { 0x471c, 0x50 },
120 { 0x4721, 0x2 },
121 { 0x4402, 0x90 },
122 { 0x460c, 0x22 },
123 { 0x3815, 0x44 },
124 { 0x3503, 0x7 },
125 { 0x3501, 0x73 },
126 { 0x3502, 0x80 },
127 { 0x350b, 0x0 },
128 { 0x3818, 0xc8 },
129 { 0x3824, 0x11 },
130 { 0x3a00, 0x78 },
131 { 0x3a1a, 0x4 },
132 { 0x3a13, 0x30 },
133 { 0x3a18, 0x0 },
134 { 0x3a19, 0x7c },
135 { 0x3a08, 0x12 },
136 { 0x3a09, 0xc0 },
137 { 0x3a0a, 0xf },
138 { 0x3a0b, 0xa0 },
139 { 0x350c, 0x7 },
140 { 0x350d, 0xd0 },
141 { 0x3a0d, 0x8 },
142 { 0x3a0e, 0x6 },
143 { 0x3500, 0x0 },
144 { 0x3501, 0x0 },
145 { 0x3502, 0x0 },
146 { 0x350a, 0x0 },
147 { 0x350b, 0x0 },
148 { 0x3503, 0x0 },
149 { 0x3a0f, 0x3c },
150 { 0x3a10, 0x32 },
151 { 0x3a1b, 0x3c },
152 { 0x3a1e, 0x32 },
153 { 0x3a11, 0x80 },
154 { 0x3a1f, 0x20 },
155 { 0x3030, 0x2b },
156 { 0x3a02, 0x0 },
157 { 0x3a03, 0x7d },
158 { 0x3a04, 0x0 },
159 { 0x3a14, 0x0 },
160 { 0x3a15, 0x7d },
161 { 0x3a16, 0x0 },
162 { 0x3a00, 0x78 },
163 { 0x3a08, 0x9 },
164 { 0x3a09, 0x60 },
165 { 0x3a0a, 0x7 },
166 { 0x3a0b, 0xd0 },
167 { 0x3a0d, 0x10 },
168 { 0x3a0e, 0xd },
169 { 0x4407, 0x4 },
170 { 0x5193, 0x70 },
171 { 0x589b, 0x0 },
172 { 0x589a, 0xc0 },
173 { 0x401e, 0x20 },
174 { 0x4001, 0x42 },
175 { 0x401c, 0x6 },
176 { 0x3825, 0xac },
177 { 0x3827, 0xc },
178 { 0x528a, 0x1 },
179 { 0x528b, 0x4 },
180 { 0x528c, 0x8 },
181 { 0x528d, 0x10 },
182 { 0x528e, 0x20 },
183 { 0x528f, 0x28 },
184 { 0x5290, 0x30 },
185 { 0x5292, 0x0 },
186 { 0x5293, 0x1 },
187 { 0x5294, 0x0 },
188 { 0x5295, 0x4 },
189 { 0x5296, 0x0 },
190 { 0x5297, 0x8 },
191 { 0x5298, 0x0 },
192 { 0x5299, 0x10 },
193 { 0x529a, 0x0 },
194 { 0x529b, 0x20 },
195 { 0x529c, 0x0 },
196 { 0x529d, 0x28 },
197 { 0x529e, 0x0 },
198 { 0x529f, 0x30 },
199 { 0x5282, 0x0 },
200 { 0x5300, 0x0 },
201 { 0x5301, 0x20 },
202 { 0x5302, 0x0 },
203 { 0x5303, 0x7c },
204 { 0x530c, 0x0 },
205 { 0x530d, 0xc },
206 { 0x530e, 0x20 },
207 { 0x530f, 0x80 },
208 { 0x5310, 0x20 },
209 { 0x5311, 0x80 },
210 { 0x5308, 0x20 },
211 { 0x5309, 0x40 },
212 { 0x5304, 0x0 },
213 { 0x5305, 0x30 },
214 { 0x5306, 0x0 },
215 { 0x5307, 0x80 },
216 { 0x5314, 0x8 },
217 { 0x5315, 0x20 },
218 { 0x5319, 0x30 },
219 { 0x5316, 0x10 },
220 { 0x5317, 0x0 },
221 { 0x5318, 0x2 },
222 { 0x5380, 0x1 },
223 { 0x5381, 0x0 },
224 { 0x5382, 0x0 },
225 { 0x5383, 0x4e },
226 { 0x5384, 0x0 },
227 { 0x5385, 0xf },
228 { 0x5386, 0x0 },
229 { 0x5387, 0x0 },
230 { 0x5388, 0x1 },
231 { 0x5389, 0x15 },
232 { 0x538a, 0x0 },
233 { 0x538b, 0x31 },
234 { 0x538c, 0x0 },
235 { 0x538d, 0x0 },
236 { 0x538e, 0x0 },
237 { 0x538f, 0xf },
238 { 0x5390, 0x0 },
239 { 0x5391, 0xab },
240 { 0x5392, 0x0 },
241 { 0x5393, 0xa2 },
242 { 0x5394, 0x8 },
243 { 0x5480, 0x14 },
244 { 0x5481, 0x21 },
245 { 0x5482, 0x36 },
246 { 0x5483, 0x57 },
247 { 0x5484, 0x65 },
248 { 0x5485, 0x71 },
249 { 0x5486, 0x7d },
250 { 0x5487, 0x87 },
251 { 0x5488, 0x91 },
252 { 0x5489, 0x9a },
253 { 0x548a, 0xaa },
254 { 0x548b, 0xb8 },
255 { 0x548c, 0xcd },
256 { 0x548d, 0xdd },
257 { 0x548e, 0xea },
258 { 0x548f, 0x1d },
259 { 0x5490, 0x5 },
260 { 0x5491, 0x0 },
261 { 0x5492, 0x4 },
262 { 0x5493, 0x20 },
263 { 0x5494, 0x3 },
264 { 0x5495, 0x60 },
265 { 0x5496, 0x2 },
266 { 0x5497, 0xb8 },
267 { 0x5498, 0x2 },
268 { 0x5499, 0x86 },
269 { 0x549a, 0x2 },
270 { 0x549b, 0x5b },
271 { 0x549c, 0x2 },
272 { 0x549d, 0x3b },
273 { 0x549e, 0x2 },
274 { 0x549f, 0x1c },
275 { 0x54a0, 0x2 },
276 { 0x54a1, 0x4 },
277 { 0x54a2, 0x1 },
278 { 0x54a3, 0xed },
279 { 0x54a4, 0x1 },
280 { 0x54a5, 0xc5 },
281 { 0x54a6, 0x1 },
282 { 0x54a7, 0xa5 },
283 { 0x54a8, 0x1 },
284 { 0x54a9, 0x6c },
285 { 0x54aa, 0x1 },
286 { 0x54ab, 0x41 },
287 { 0x54ac, 0x1 },
288 { 0x54ad, 0x20 },
289 { 0x54ae, 0x0 },
290 { 0x54af, 0x16 },
291 { 0x54b0, 0x1 },
292 { 0x54b1, 0x20 },
293 { 0x54b2, 0x0 },
294 { 0x54b3, 0x10 },
295 { 0x54b4, 0x0 },
296 { 0x54b5, 0xf0 },
297 { 0x54b6, 0x0 },
298 { 0x54b7, 0xdf },
299 { 0x5402, 0x3f },
300 { 0x5403, 0x0 },
301 { 0x3406, 0x0 },
302 { 0x5180, 0xff },
303 { 0x5181, 0x52 },
304 { 0x5182, 0x11 },
305 { 0x5183, 0x14 },
306 { 0x5184, 0x25 },
307 { 0x5185, 0x24 },
308 { 0x5186, 0x6 },
309 { 0x5187, 0x8 },
310 { 0x5188, 0x8 },
311 { 0x5189, 0x7c },
312 { 0x518a, 0x60 },
313 { 0x518b, 0xb2 },
314 { 0x518c, 0xb2 },
315 { 0x518d, 0x44 },
316 { 0x518e, 0x3d },
317 { 0x518f, 0x58 },
318 { 0x5190, 0x46 },
319 { 0x5191, 0xf8 },
320 { 0x5192, 0x4 },
321 { 0x5193, 0x70 },
322 { 0x5194, 0xf0 },
323 { 0x5195, 0xf0 },
324 { 0x5196, 0x3 },
325 { 0x5197, 0x1 },
326 { 0x5198, 0x4 },
327 { 0x5199, 0x12 },
328 { 0x519a, 0x4 },
329 { 0x519b, 0x0 },
330 { 0x519c, 0x6 },
331 { 0x519d, 0x82 },
332 { 0x519e, 0x0 },
333 { 0x5025, 0x80 },
334 { 0x3a0f, 0x38 },
335 { 0x3a10, 0x30 },
336 { 0x3a1b, 0x3a },
337 { 0x3a1e, 0x2e },
338 { 0x3a11, 0x60 },
339 { 0x3a1f, 0x10 },
340 { 0x5688, 0xa6 },
341 { 0x5689, 0x6a },
342 { 0x568a, 0xea },
343 { 0x568b, 0xae },
344 { 0x568c, 0xa6 },
345 { 0x568d, 0x6a },
346 { 0x568e, 0x62 },
347 { 0x568f, 0x26 },
348 { 0x5583, 0x40 },
349 { 0x5584, 0x40 },
350 { 0x5580, 0x2 },
351 { 0x5000, 0xcf },
352 { 0x5800, 0x27 },
353 { 0x5801, 0x19 },
354 { 0x5802, 0x12 },
355 { 0x5803, 0xf },
356 { 0x5804, 0x10 },
357 { 0x5805, 0x15 },
358 { 0x5806, 0x1e },
359 { 0x5807, 0x2f },
360 { 0x5808, 0x15 },
361 { 0x5809, 0xd },
362 { 0x580a, 0xa },
363 { 0x580b, 0x9 },
364 { 0x580c, 0xa },
365 { 0x580d, 0xc },
366 { 0x580e, 0x12 },
367 { 0x580f, 0x19 },
368 { 0x5810, 0xb },
369 { 0x5811, 0x7 },
370 { 0x5812, 0x4 },
371 { 0x5813, 0x3 },
372 { 0x5814, 0x3 },
373 { 0x5815, 0x6 },
374 { 0x5816, 0xa },
375 { 0x5817, 0xf },
376 { 0x5818, 0xa },
377 { 0x5819, 0x5 },
378 { 0x581a, 0x1 },
379 { 0x581b, 0x0 },
380 { 0x581c, 0x0 },
381 { 0x581d, 0x3 },
382 { 0x581e, 0x8 },
383 { 0x581f, 0xc },
384 { 0x5820, 0xa },
385 { 0x5821, 0x5 },
386 { 0x5822, 0x1 },
387 { 0x5823, 0x0 },
388 { 0x5824, 0x0 },
389 { 0x5825, 0x3 },
390 { 0x5826, 0x8 },
391 { 0x5827, 0xc },
392 { 0x5828, 0xe },
393 { 0x5829, 0x8 },
394 { 0x582a, 0x6 },
395 { 0x582b, 0x4 },
396 { 0x582c, 0x5 },
397 { 0x582d, 0x7 },
398 { 0x582e, 0xb },
399 { 0x582f, 0x12 },
400 { 0x5830, 0x18 },
401 { 0x5831, 0x10 },
402 { 0x5832, 0xc },
403 { 0x5833, 0xa },
404 { 0x5834, 0xb },
405 { 0x5835, 0xe },
406 { 0x5836, 0x15 },
407 { 0x5837, 0x19 },
408 { 0x5838, 0x32 },
409 { 0x5839, 0x1f },
410 { 0x583a, 0x18 },
411 { 0x583b, 0x16 },
412 { 0x583c, 0x17 },
413 { 0x583d, 0x1e },
414 { 0x583e, 0x26 },
415 { 0x583f, 0x53 },
416 { 0x5840, 0x10 },
417 { 0x5841, 0xf },
418 { 0x5842, 0xd },
419 { 0x5843, 0xc },
420 { 0x5844, 0xe },
421 { 0x5845, 0x9 },
422 { 0x5846, 0x11 },
423 { 0x5847, 0x10 },
424 { 0x5848, 0x10 },
425 { 0x5849, 0x10 },
426 { 0x584a, 0x10 },
427 { 0x584b, 0xe },
428 { 0x584c, 0x10 },
429 { 0x584d, 0x10 },
430 { 0x584e, 0x11 },
431 { 0x584f, 0x10 },
432 { 0x5850, 0xf },
433 { 0x5851, 0xc },
434 { 0x5852, 0xf },
435 { 0x5853, 0x10 },
436 { 0x5854, 0x10 },
437 { 0x5855, 0xf },
438 { 0x5856, 0xe },
439 { 0x5857, 0xb },
440 { 0x5858, 0x10 },
441 { 0x5859, 0xd },
442 { 0x585a, 0xd },
443 { 0x585b, 0xc },
444 { 0x585c, 0xc },
445 { 0x585d, 0xc },
446 { 0x585e, 0xb },
447 { 0x585f, 0xc },
448 { 0x5860, 0xc },
449 { 0x5861, 0xc },
450 { 0x5862, 0xd },
451 { 0x5863, 0x8 },
452 { 0x5864, 0x11 },
453 { 0x5865, 0x18 },
454 { 0x5866, 0x18 },
455 { 0x5867, 0x19 },
456 { 0x5868, 0x17 },
457 { 0x5869, 0x19 },
458 { 0x586a, 0x16 },
459 { 0x586b, 0x13 },
460 { 0x586c, 0x13 },
461 { 0x586d, 0x12 },
462 { 0x586e, 0x13 },
463 { 0x586f, 0x16 },
464 { 0x5870, 0x14 },
465 { 0x5871, 0x12 },
466 { 0x5872, 0x10 },
467 { 0x5873, 0x11 },
468 { 0x5874, 0x11 },
469 { 0x5875, 0x16 },
470 { 0x5876, 0x14 },
471 { 0x5877, 0x11 },
472 { 0x5878, 0x10 },
473 { 0x5879, 0xf },
474 { 0x587a, 0x10 },
475 { 0x587b, 0x14 },
476 { 0x587c, 0x13 },
477 { 0x587d, 0x12 },
478 { 0x587e, 0x11 },
479 { 0x587f, 0x11 },
480 { 0x5880, 0x12 },
481 { 0x5881, 0x15 },
482 { 0x5882, 0x14 },
483 { 0x5883, 0x15 },
484 { 0x5884, 0x15 },
485 { 0x5885, 0x15 },
486 { 0x5886, 0x13 },
487 { 0x5887, 0x17 },
488 { 0x3710, 0x10 },
489 { 0x3632, 0x51 },
490 { 0x3702, 0x10 },
491 { 0x3703, 0xb2 },
492 { 0x3704, 0x18 },
493 { 0x370b, 0x40 },
494 { 0x370d, 0x3 },
495 { 0x3631, 0x1 },
496 { 0x3632, 0x52 },
497 { 0x3606, 0x24 },
498 { 0x3620, 0x96 },
499 { 0x5785, 0x7 },
500 { 0x3a13, 0x30 },
501 { 0x3600, 0x52 },
502 { 0x3604, 0x48 },
503 { 0x3606, 0x1b },
504 { 0x370d, 0xb },
505 { 0x370f, 0xc0 },
506 { 0x3709, 0x1 },
507 { 0x3823, 0x0 },
508 { 0x5007, 0x0 },
509 { 0x5009, 0x0 },
510 { 0x5011, 0x0 },
511 { 0x5013, 0x0 },
512 { 0x519e, 0x0 },
513 { 0x5086, 0x0 },
514 { 0x5087, 0x0 },
515 { 0x5088, 0x0 },
516 { 0x5089, 0x0 },
517 { 0x302b, 0x0 },
518 { 0x3503, 0x7 },
519 { 0x3011, 0x8 },
520 { 0x350c, 0x2 },
521 { 0x350d, 0xe4 },
522 { 0x3621, 0xc9 },
523 { 0x370a, 0x81 },
524 { 0xffff, 0xff },
525};
526
527static struct regval_list ov5642_default_regs_finalise[] = {
528 { 0x3810, 0xc2 },
529 { 0x3818, 0xc9 },
530 { 0x381c, 0x10 },
531 { 0x381d, 0xa0 },
532 { 0x381e, 0x5 },
533 { 0x381f, 0xb0 },
534 { 0x3820, 0x0 },
535 { 0x3821, 0x0 },
536 { 0x3824, 0x11 },
537 { 0x3a08, 0x1b },
538 { 0x3a09, 0xc0 },
539 { 0x3a0a, 0x17 },
540 { 0x3a0b, 0x20 },
541 { 0x3a0d, 0x2 },
542 { 0x3a0e, 0x1 },
543 { 0x401c, 0x4 },
544 { 0x5682, 0x5 },
545 { 0x5683, 0x0 },
546 { 0x5686, 0x2 },
547 { 0x5687, 0xcc },
548 { 0x5001, 0x4f },
549 { 0x589b, 0x6 },
550 { 0x589a, 0xc5 },
551 { 0x3503, 0x0 },
552 { 0x460c, 0x20 },
553 { 0x460b, 0x37 },
554 { 0x471c, 0xd0 },
555 { 0x471d, 0x5 },
556 { 0x3815, 0x1 },
557 { 0x3818, 0xc1 },
558 { 0x501f, 0x0 },
559 { 0x5002, 0xe0 },
560 { 0x4300, 0x32 }, /* UYVY */
561 { 0x3002, 0x1c },
562 { 0x4800, 0x14 },
563 { 0x4801, 0xf },
564 { 0x3007, 0x3b },
565 { 0x300e, 0x4 },
566 { 0x4803, 0x50 },
567 { 0x3815, 0x1 },
568 { 0x4713, 0x2 },
569 { 0x4842, 0x1 },
570 { 0x300f, 0xe },
571 { 0x3003, 0x3 },
572 { 0x3003, 0x1 },
573 { 0xffff, 0xff },
574};
575
576struct ov5642_datafmt {
577 enum v4l2_mbus_pixelcode code;
578 enum v4l2_colorspace colorspace;
579};
580
581struct ov5642 {
582 struct v4l2_subdev subdev;
583 const struct ov5642_datafmt *fmt;
584};
585
586static const struct ov5642_datafmt ov5642_colour_fmts[] = {
587 {V4L2_MBUS_FMT_UYVY8_2X8, V4L2_COLORSPACE_JPEG},
588};
589
590static struct ov5642 *to_ov5642(const struct i2c_client *client)
591{
592 return container_of(i2c_get_clientdata(client), struct ov5642, subdev);
593}
594
595/* Find a data format by a pixel code in an array */
596static const struct ov5642_datafmt
597 *ov5642_find_datafmt(enum v4l2_mbus_pixelcode code)
598{
599 int i;
600
601 for (i = 0; i < ARRAY_SIZE(ov5642_colour_fmts); i++)
602 if (ov5642_colour_fmts[i].code == code)
603 return ov5642_colour_fmts + i;
604
605 return NULL;
606}
607
608static int reg_read(struct i2c_client *client, u16 reg, u8 *val)
609{
610 int ret;
611 /* We have 16-bit i2c addresses - care for endianess */
612 unsigned char data[2] = { reg >> 8, reg & 0xff };
613
614 ret = i2c_master_send(client, data, 2);
615 if (ret < 2) {
616 dev_err(&client->dev, "%s: i2c read error, reg: %x\n",
617 __func__, reg);
618 return ret < 0 ? ret : -EIO;
619 }
620
621 ret = i2c_master_recv(client, val, 1);
622 if (ret < 1) {
623 dev_err(&client->dev, "%s: i2c read error, reg: %x\n",
624 __func__, reg);
625 return ret < 0 ? ret : -EIO;
626 }
627 return 0;
628}
629
630static int reg_write(struct i2c_client *client, u16 reg, u8 val)
631{
632 int ret;
633 unsigned char data[3] = { reg >> 8, reg & 0xff, val };
634
635 ret = i2c_master_send(client, data, 3);
636 if (ret < 3) {
637 dev_err(&client->dev, "%s: i2c write error, reg: %x\n",
638 __func__, reg);
639 return ret < 0 ? ret : -EIO;
640 }
641
642 return 0;
643}
644#ifdef CONFIG_VIDEO_ADV_DEBUG
645static int ov5642_get_register(struct v4l2_subdev *sd, struct v4l2_dbg_register *reg)
646{
647 struct i2c_client *client = v4l2_get_subdevdata(sd);
648 int ret;
649 u8 val;
650
651 if (reg->reg & ~0xffff)
652 return -EINVAL;
653
654 reg->size = 1;
655
656 ret = reg_read(client, reg->reg, &val);
657 if (!ret)
658 reg->val = (__u64)val;
659
660 return ret;
661}
662
663static int ov5642_set_register(struct v4l2_subdev *sd, struct v4l2_dbg_register *reg)
664{
665 struct i2c_client *client = v4l2_get_subdevdata(sd);
666
667 if (reg->reg & ~0xffff || reg->val & ~0xff)
668 return -EINVAL;
669
670 return reg_write(client, reg->reg, reg->val);
671}
672#endif
673
674static int ov5642_write_array(struct i2c_client *client,
675 struct regval_list *vals)
676{
677 while (vals->reg_num != 0xffff || vals->value != 0xff) {
678 int ret = reg_write(client, vals->reg_num, vals->value);
679 if (ret < 0)
680 return ret;
681 vals++;
682 }
683 dev_dbg(&client->dev, "Register list loaded\n");
684 return 0;
685}
686
687static int ov5642_set_resolution(struct i2c_client *client)
688{
689 int ret;
690 u8 start_x_high = ((OV5642_SENSOR_SIZE_X - OV5642_WIDTH) / 2) >> 8;
691 u8 start_x_low = ((OV5642_SENSOR_SIZE_X - OV5642_WIDTH) / 2) & 0xff;
692 u8 start_y_high = ((OV5642_SENSOR_SIZE_Y - OV5642_HEIGHT) / 2) >> 8;
693 u8 start_y_low = ((OV5642_SENSOR_SIZE_Y - OV5642_HEIGHT) / 2) & 0xff;
694
695 u8 width_high = OV5642_WIDTH >> 8;
696 u8 width_low = OV5642_WIDTH & 0xff;
697 u8 height_high = OV5642_HEIGHT >> 8;
698 u8 height_low = OV5642_HEIGHT & 0xff;
699
700 u8 total_width_high = OV5642_TOTAL_WIDTH >> 8;
701 u8 total_width_low = OV5642_TOTAL_WIDTH & 0xff;
702 u8 total_height_high = OV5642_TOTAL_HEIGHT >> 8;
703 u8 total_height_low = OV5642_TOTAL_HEIGHT & 0xff;
704
705 ret = reg_write(client, REG_WINDOW_START_X_HIGH, start_x_high);
706 if (!ret)
707 ret = reg_write(client, REG_WINDOW_START_X_LOW, start_x_low);
708 if (!ret)
709 ret = reg_write(client, REG_WINDOW_START_Y_HIGH, start_y_high);
710 if (!ret)
711 ret = reg_write(client, REG_WINDOW_START_Y_LOW, start_y_low);
712
713 if (!ret)
714 ret = reg_write(client, REG_WINDOW_WIDTH_HIGH, width_high);
715 if (!ret)
716 ret = reg_write(client, REG_WINDOW_WIDTH_LOW , width_low);
717 if (!ret)
718 ret = reg_write(client, REG_WINDOW_HEIGHT_HIGH, height_high);
719 if (!ret)
720 ret = reg_write(client, REG_WINDOW_HEIGHT_LOW, height_low);
721
722 if (!ret)
723 ret = reg_write(client, REG_OUT_WIDTH_HIGH, width_high);
724 if (!ret)
725 ret = reg_write(client, REG_OUT_WIDTH_LOW , width_low);
726 if (!ret)
727 ret = reg_write(client, REG_OUT_HEIGHT_HIGH, height_high);
728 if (!ret)
729 ret = reg_write(client, REG_OUT_HEIGHT_LOW, height_low);
730
731 if (!ret)
732 ret = reg_write(client, REG_OUT_TOTAL_WIDTH_HIGH, total_width_high);
733 if (!ret)
734 ret = reg_write(client, REG_OUT_TOTAL_WIDTH_LOW, total_width_low);
735 if (!ret)
736 ret = reg_write(client, REG_OUT_TOTAL_HEIGHT_HIGH, total_height_high);
737 if (!ret)
738 ret = reg_write(client, REG_OUT_TOTAL_HEIGHT_LOW, total_height_low);
739
740 return ret;
741}
742
743static int ov5642_try_fmt(struct v4l2_subdev *sd,
744 struct v4l2_mbus_framefmt *mf)
745{
746 const struct ov5642_datafmt *fmt = ov5642_find_datafmt(mf->code);
747
748 dev_dbg(sd->v4l2_dev->dev, "%s(%u) width: %u heigth: %u\n",
749 __func__, mf->code, mf->width, mf->height);
750
751 if (!fmt) {
752 mf->code = ov5642_colour_fmts[0].code;
753 mf->colorspace = ov5642_colour_fmts[0].colorspace;
754 }
755
756 mf->width = OV5642_WIDTH;
757 mf->height = OV5642_HEIGHT;
758 mf->field = V4L2_FIELD_NONE;
759
760 return 0;
761}
762
763static int ov5642_s_fmt(struct v4l2_subdev *sd,
764 struct v4l2_mbus_framefmt *mf)
765{
766 struct i2c_client *client = v4l2_get_subdevdata(sd);
767 struct ov5642 *priv = to_ov5642(client);
768
769 dev_dbg(sd->v4l2_dev->dev, "%s(%u)\n", __func__, mf->code);
770
771 /* MIPI CSI could have changed the format, double-check */
772 if (!ov5642_find_datafmt(mf->code))
773 return -EINVAL;
774
775 ov5642_try_fmt(sd, mf);
776
777 priv->fmt = ov5642_find_datafmt(mf->code);
778
779 ov5642_write_array(client, ov5642_default_regs_init);
780 ov5642_set_resolution(client);
781 ov5642_write_array(client, ov5642_default_regs_finalise);
782
783 return 0;
784}
785
786static int ov5642_g_fmt(struct v4l2_subdev *sd,
787 struct v4l2_mbus_framefmt *mf)
788{
789 struct i2c_client *client = v4l2_get_subdevdata(sd);
790 struct ov5642 *priv = to_ov5642(client);
791
792 const struct ov5642_datafmt *fmt = priv->fmt;
793
794 mf->code = fmt->code;
795 mf->colorspace = fmt->colorspace;
796 mf->width = OV5642_WIDTH;
797 mf->height = OV5642_HEIGHT;
798 mf->field = V4L2_FIELD_NONE;
799
800 return 0;
801}
802
803static int ov5642_enum_fmt(struct v4l2_subdev *sd, unsigned int index,
804 enum v4l2_mbus_pixelcode *code)
805{
806 if (index >= ARRAY_SIZE(ov5642_colour_fmts))
807 return -EINVAL;
808
809 *code = ov5642_colour_fmts[index].code;
810 return 0;
811}
812
813static int ov5642_g_chip_ident(struct v4l2_subdev *sd,
814 struct v4l2_dbg_chip_ident *id)
815{
816 struct i2c_client *client = v4l2_get_subdevdata(sd);
817
818 if (id->match.type != V4L2_CHIP_MATCH_I2C_ADDR)
819 return -EINVAL;
820
821 if (id->match.addr != client->addr)
822 return -ENODEV;
823
824 id->ident = V4L2_IDENT_OV5642;
825 id->revision = 0;
826
827 return 0;
828}
829
830static int ov5642_g_crop(struct v4l2_subdev *sd, struct v4l2_crop *a)
831{
832 struct v4l2_rect *rect = &a->c;
833
834 a->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
835 rect->top = 0;
836 rect->left = 0;
837 rect->width = OV5642_WIDTH;
838 rect->height = OV5642_HEIGHT;
839
840 return 0;
841}
842
843static int ov5642_cropcap(struct v4l2_subdev *sd, struct v4l2_cropcap *a)
844{
845 a->bounds.left = 0;
846 a->bounds.top = 0;
847 a->bounds.width = OV5642_WIDTH;
848 a->bounds.height = OV5642_HEIGHT;
849 a->defrect = a->bounds;
850 a->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
851 a->pixelaspect.numerator = 1;
852 a->pixelaspect.denominator = 1;
853
854 return 0;
855}
856
857static struct v4l2_subdev_video_ops ov5642_subdev_video_ops = {
858 .s_mbus_fmt = ov5642_s_fmt,
859 .g_mbus_fmt = ov5642_g_fmt,
860 .try_mbus_fmt = ov5642_try_fmt,
861 .enum_mbus_fmt = ov5642_enum_fmt,
862 .g_crop = ov5642_g_crop,
863 .cropcap = ov5642_cropcap,
864};
865
866static struct v4l2_subdev_core_ops ov5642_subdev_core_ops = {
867 .g_chip_ident = ov5642_g_chip_ident,
868#ifdef CONFIG_VIDEO_ADV_DEBUG
869 .g_register = ov5642_get_register,
870 .s_register = ov5642_set_register,
871#endif
872};
873
874static struct v4l2_subdev_ops ov5642_subdev_ops = {
875 .core = &ov5642_subdev_core_ops,
876 .video = &ov5642_subdev_video_ops,
877};
878
879/*
880 * We have to provide soc-camera operations, but we don't have anything to say
881 * there. The MIPI CSI2 driver will provide .query_bus_param and .set_bus_param
882 */
883static unsigned long soc_ov5642_query_bus_param(struct soc_camera_device *icd)
884{
885 return 0;
886}
887
888static int soc_ov5642_set_bus_param(struct soc_camera_device *icd,
889 unsigned long flags)
890{
891 return -EINVAL;
892}
893
894static struct soc_camera_ops soc_ov5642_ops = {
895 .query_bus_param = soc_ov5642_query_bus_param,
896 .set_bus_param = soc_ov5642_set_bus_param,
897};
898
899static int ov5642_video_probe(struct soc_camera_device *icd,
900 struct i2c_client *client)
901{
902 int ret;
903 u8 id_high, id_low;
904 u16 id;
905
906 /* Read sensor Model ID */
907 ret = reg_read(client, REG_CHIP_ID_HIGH, &id_high);
908 if (ret < 0)
909 return ret;
910
911 id = id_high << 8;
912
913 ret = reg_read(client, REG_CHIP_ID_LOW, &id_low);
914 if (ret < 0)
915 return ret;
916
917 id |= id_low;
918
919 dev_info(&client->dev, "Chip ID 0x%04x detected\n", id);
920
921 if (id != 0x5642)
922 return -ENODEV;
923
924 return 0;
925}
926
927static int ov5642_probe(struct i2c_client *client,
928 const struct i2c_device_id *did)
929{
930 struct ov5642 *priv;
931 struct soc_camera_device *icd = client->dev.platform_data;
932 struct soc_camera_link *icl;
933 int ret;
934
935 if (!icd) {
936 dev_err(&client->dev, "OV5642: missing soc-camera data!\n");
937 return -EINVAL;
938 }
939
940 icl = to_soc_camera_link(icd);
941 if (!icl) {
942 dev_err(&client->dev, "OV5642: missing platform data!\n");
943 return -EINVAL;
944 }
945
946 priv = kzalloc(sizeof(struct ov5642), GFP_KERNEL);
947 if (!priv)
948 return -ENOMEM;
949
950 v4l2_i2c_subdev_init(&priv->subdev, client, &ov5642_subdev_ops);
951
952 icd->ops = &soc_ov5642_ops;
953 priv->fmt = &ov5642_colour_fmts[0];
954
955 ret = ov5642_video_probe(icd, client);
956 if (ret < 0)
957 goto error;
958
959 return 0;
960
961error:
962 icd->ops = NULL;
963 kfree(priv);
964 return ret;
965}
966
967static int ov5642_remove(struct i2c_client *client)
968{
969 struct ov5642 *priv = to_ov5642(client);
970 struct soc_camera_device *icd = client->dev.platform_data;
971 struct soc_camera_link *icl = to_soc_camera_link(icd);
972
973 icd->ops = NULL;
974 if (icl->free_bus)
975 icl->free_bus(icl);
976 kfree(priv);
977
978 return 0;
979}
980
981static const struct i2c_device_id ov5642_id[] = {
982 { "ov5642", 0 },
983 { }
984};
985MODULE_DEVICE_TABLE(i2c, ov5642_id);
986
987static struct i2c_driver ov5642_i2c_driver = {
988 .driver = {
989 .name = "ov5642",
990 },
991 .probe = ov5642_probe,
992 .remove = ov5642_remove,
993 .id_table = ov5642_id,
994};
995
996static int __init ov5642_mod_init(void)
997{
998 return i2c_add_driver(&ov5642_i2c_driver);
999}
1000
1001static void __exit ov5642_mod_exit(void)
1002{
1003 i2c_del_driver(&ov5642_i2c_driver);
1004}
1005
1006module_init(ov5642_mod_init);
1007module_exit(ov5642_mod_exit);
1008
1009MODULE_DESCRIPTION("Omnivision OV5642 Camera driver");
1010MODULE_AUTHOR("Bastian Hecht <hechtb@gmail.com>");
1011MODULE_LICENSE("GPL v2");