diff options
author | Hans Verkuil <hans.verkuil@cisco.com> | 2013-03-09 05:09:18 -0500 |
---|---|---|
committer | Mauro Carvalho Chehab <mchehab@redhat.com> | 2013-03-24 11:23:33 -0400 |
commit | ec367c3cd18697991923685eb0e833f4424d37fb (patch) | |
tree | a966f81796fdfcb785dd29b316334207c713b03e | |
parent | c7c54a988d21626874e9f1b8dc6bb0547bcddf9c (diff) |
[media] ov7640: add new ov7640 driver
This based on the wis-ov7640.c driver that's part of the go7007 driver.
It has been converted to a v4l subdev driver by Pete Eberlein, and I made
additional cleanups.
Based on work by: Pete Eberlein <pete@sensoray.com>
Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
-rw-r--r-- | drivers/media/i2c/Kconfig | 11 | ||||
-rw-r--r-- | drivers/media/i2c/Makefile | 3 | ||||
-rw-r--r-- | drivers/media/i2c/ov7640.c | 106 |
3 files changed, 119 insertions, 1 deletions
diff --git a/drivers/media/i2c/Kconfig b/drivers/media/i2c/Kconfig index 785e2132a573..790788597bad 100644 --- a/drivers/media/i2c/Kconfig +++ b/drivers/media/i2c/Kconfig | |||
@@ -395,6 +395,17 @@ config VIDEO_APTINA_PLL | |||
395 | config VIDEO_SMIAPP_PLL | 395 | config VIDEO_SMIAPP_PLL |
396 | tristate | 396 | tristate |
397 | 397 | ||
398 | config VIDEO_OV7640 | ||
399 | tristate "OmniVision OV7640 sensor support" | ||
400 | depends on I2C && VIDEO_V4L2 | ||
401 | depends on MEDIA_CAMERA_SUPPORT | ||
402 | ---help--- | ||
403 | This is a Video4Linux2 sensor-level driver for the OmniVision | ||
404 | OV7640 camera. | ||
405 | |||
406 | To compile this driver as a module, choose M here: the | ||
407 | module will be called ov7640. | ||
408 | |||
398 | config VIDEO_OV7670 | 409 | config VIDEO_OV7670 |
399 | tristate "OmniVision OV7670 sensor support" | 410 | tristate "OmniVision OV7670 sensor support" |
400 | depends on I2C && VIDEO_V4L2 | 411 | depends on I2C && VIDEO_V4L2 |
diff --git a/drivers/media/i2c/Makefile b/drivers/media/i2c/Makefile index 4c570757089e..adf950406a94 100644 --- a/drivers/media/i2c/Makefile +++ b/drivers/media/i2c/Makefile | |||
@@ -47,7 +47,8 @@ obj-$(CONFIG_VIDEO_VP27SMPX) += vp27smpx.o | |||
47 | obj-$(CONFIG_VIDEO_SONY_BTF_MPX) += sony-btf-mpx.o | 47 | obj-$(CONFIG_VIDEO_SONY_BTF_MPX) += sony-btf-mpx.o |
48 | obj-$(CONFIG_VIDEO_UPD64031A) += upd64031a.o | 48 | obj-$(CONFIG_VIDEO_UPD64031A) += upd64031a.o |
49 | obj-$(CONFIG_VIDEO_UPD64083) += upd64083.o | 49 | obj-$(CONFIG_VIDEO_UPD64083) += upd64083.o |
50 | obj-$(CONFIG_VIDEO_OV7670) += ov7670.o | 50 | obj-$(CONFIG_VIDEO_OV7640) += ov7640.o |
51 | obj-$(CONFIG_VIDEO_OV7670) += ov7670.o | ||
51 | obj-$(CONFIG_VIDEO_OV9650) += ov9650.o | 52 | obj-$(CONFIG_VIDEO_OV9650) += ov9650.o |
52 | obj-$(CONFIG_VIDEO_TCM825X) += tcm825x.o | 53 | obj-$(CONFIG_VIDEO_TCM825X) += tcm825x.o |
53 | obj-$(CONFIG_VIDEO_MT9M032) += mt9m032.o | 54 | obj-$(CONFIG_VIDEO_MT9M032) += mt9m032.o |
diff --git a/drivers/media/i2c/ov7640.c b/drivers/media/i2c/ov7640.c new file mode 100644 index 000000000000..b0cc927e8b19 --- /dev/null +++ b/drivers/media/i2c/ov7640.c | |||
@@ -0,0 +1,106 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2005-2006 Micronas USA Inc. | ||
3 | * | ||
4 | * This program is free software; you can redistribute it and/or modify | ||
5 | * it under the terms of the GNU General Public License (Version 2) as | ||
6 | * published by the Free Software Foundation. | ||
7 | * | ||
8 | * This program is distributed in the hope that it will be useful, | ||
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
11 | * GNU General Public License for more details. | ||
12 | * | ||
13 | * You should have received a copy of the GNU General Public License | ||
14 | * along with this program; if not, write to the Free Software Foundation, | ||
15 | * Inc., 59 Temple Place - Suite 330, Boston MA 02111-1307, USA. | ||
16 | */ | ||
17 | |||
18 | #include <linux/init.h> | ||
19 | #include <linux/module.h> | ||
20 | #include <linux/i2c.h> | ||
21 | #include <linux/videodev2.h> | ||
22 | #include <media/v4l2-device.h> | ||
23 | #include <media/v4l2-chip-ident.h> | ||
24 | #include <linux/slab.h> | ||
25 | |||
26 | MODULE_DESCRIPTION("OmniVision ov7640 sensor driver"); | ||
27 | MODULE_LICENSE("GPL v2"); | ||
28 | |||
29 | static const u8 initial_registers[] = { | ||
30 | 0x12, 0x80, | ||
31 | 0x12, 0x54, | ||
32 | 0x14, 0x24, | ||
33 | 0x15, 0x01, | ||
34 | 0x28, 0x20, | ||
35 | 0x75, 0x82, | ||
36 | 0xFF, 0xFF, /* Terminator (reg 0xFF is unused) */ | ||
37 | }; | ||
38 | |||
39 | static int write_regs(struct i2c_client *client, const u8 *regs) | ||
40 | { | ||
41 | int i; | ||
42 | |||
43 | for (i = 0; regs[i] != 0xFF; i += 2) | ||
44 | if (i2c_smbus_write_byte_data(client, regs[i], regs[i + 1]) < 0) | ||
45 | return -1; | ||
46 | return 0; | ||
47 | } | ||
48 | |||
49 | /* ----------------------------------------------------------------------- */ | ||
50 | |||
51 | static const struct v4l2_subdev_ops ov7640_ops; | ||
52 | |||
53 | static int ov7640_probe(struct i2c_client *client, | ||
54 | const struct i2c_device_id *id) | ||
55 | { | ||
56 | struct i2c_adapter *adapter = client->adapter; | ||
57 | struct v4l2_subdev *sd; | ||
58 | |||
59 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) | ||
60 | return -ENODEV; | ||
61 | |||
62 | sd = kzalloc(sizeof(struct v4l2_subdev), GFP_KERNEL); | ||
63 | if (sd == NULL) | ||
64 | return -ENOMEM; | ||
65 | v4l2_i2c_subdev_init(sd, client, &ov7640_ops); | ||
66 | |||
67 | client->flags = I2C_CLIENT_SCCB; | ||
68 | |||
69 | v4l_info(client, "chip found @ 0x%02x (%s)\n", | ||
70 | client->addr << 1, client->adapter->name); | ||
71 | |||
72 | if (write_regs(client, initial_registers) < 0) { | ||
73 | v4l_err(client, "error initializing OV7640\n"); | ||
74 | kfree(sd); | ||
75 | return -ENODEV; | ||
76 | } | ||
77 | |||
78 | return 0; | ||
79 | } | ||
80 | |||
81 | |||
82 | static int ov7640_remove(struct i2c_client *client) | ||
83 | { | ||
84 | struct v4l2_subdev *sd = i2c_get_clientdata(client); | ||
85 | |||
86 | v4l2_device_unregister_subdev(sd); | ||
87 | kfree(sd); | ||
88 | return 0; | ||
89 | } | ||
90 | |||
91 | static const struct i2c_device_id ov7640_id[] = { | ||
92 | { "ov7640", 0 }, | ||
93 | { } | ||
94 | }; | ||
95 | MODULE_DEVICE_TABLE(i2c, ov7640_id); | ||
96 | |||
97 | static struct i2c_driver ov7640_driver = { | ||
98 | .driver = { | ||
99 | .owner = THIS_MODULE, | ||
100 | .name = "ov7640", | ||
101 | }, | ||
102 | .probe = ov7640_probe, | ||
103 | .remove = ov7640_remove, | ||
104 | .id_table = ov7640_id, | ||
105 | }; | ||
106 | module_i2c_driver(ov7640_driver); | ||