]>
Commit | Line | Data |
---|---|---|
866b8695 GKH |
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/module.h> | |
19 | #include <linux/init.h> | |
866b8695 | 20 | #include <linux/i2c.h> |
df20d69e | 21 | #include <linux/videodev2.h> |
866b8695 GKH |
22 | |
23 | #include "wis-i2c.h" | |
24 | ||
25 | struct wis_ov7640 { | |
26 | int brightness; | |
27 | int contrast; | |
28 | int saturation; | |
29 | int hue; | |
30 | }; | |
31 | ||
32 | static u8 initial_registers[] = | |
33 | { | |
34 | 0x12, 0x80, | |
35 | 0x12, 0x54, | |
36 | 0x14, 0x24, | |
37 | 0x15, 0x01, | |
38 | 0x28, 0x20, | |
39 | 0x75, 0x82, | |
40 | 0xFF, 0xFF, /* Terminator (reg 0xFF is unused) */ | |
41 | }; | |
42 | ||
43 | static int write_regs(struct i2c_client *client, u8 *regs) | |
44 | { | |
45 | int i; | |
46 | ||
47 | for (i = 0; regs[i] != 0xFF; i += 2) | |
48 | if (i2c_smbus_write_byte_data(client, regs[i], regs[i + 1]) < 0) | |
49 | return -1; | |
50 | return 0; | |
51 | } | |
52 | ||
53 | static struct i2c_driver wis_ov7640_driver; | |
54 | ||
55 | static struct i2c_client wis_ov7640_client_templ = { | |
56 | .name = "OV7640 (WIS)", | |
57 | .driver = &wis_ov7640_driver, | |
58 | }; | |
59 | ||
60 | static int wis_ov7640_detect(struct i2c_adapter *adapter, int addr, int kind) | |
61 | { | |
62 | struct i2c_client *client; | |
63 | ||
64 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) | |
65 | return 0; | |
66 | ||
67 | client = kmalloc(sizeof(struct i2c_client), GFP_KERNEL); | |
68 | if (client == NULL) | |
69 | return -ENOMEM; | |
70 | memcpy(client, &wis_ov7640_client_templ, | |
71 | sizeof(wis_ov7640_client_templ)); | |
72 | client->adapter = adapter; | |
73 | client->addr = addr; | |
74 | client->flags = I2C_CLIENT_SCCB; | |
75 | ||
76 | printk(KERN_DEBUG | |
77 | "wis-ov7640: initializing OV7640 at address %d on %s\n", | |
78 | addr, adapter->name); | |
79 | ||
80 | if (write_regs(client, initial_registers) < 0) { | |
81 | printk(KERN_ERR "wis-ov7640: error initializing OV7640\n"); | |
82 | kfree(client); | |
83 | return 0; | |
84 | } | |
85 | ||
86 | i2c_attach_client(client); | |
87 | return 0; | |
88 | } | |
89 | ||
90 | static int wis_ov7640_detach(struct i2c_client *client) | |
91 | { | |
92 | int r; | |
93 | ||
94 | r = i2c_detach_client(client); | |
95 | if (r < 0) | |
96 | return r; | |
97 | ||
98 | kfree(client); | |
99 | return 0; | |
100 | } | |
101 | ||
102 | static struct i2c_driver wis_ov7640_driver = { | |
103 | .driver = { | |
104 | .name = "WIS OV7640 I2C driver", | |
105 | }, | |
106 | .id = I2C_DRIVERID_WIS_OV7640, | |
107 | .detach_client = wis_ov7640_detach, | |
108 | }; | |
109 | ||
110 | static int __init wis_ov7640_init(void) | |
111 | { | |
112 | int r; | |
113 | ||
114 | r = i2c_add_driver(&wis_ov7640_driver); | |
115 | if (r < 0) | |
116 | return r; | |
117 | return wis_i2c_add_driver(wis_ov7640_driver.id, wis_ov7640_detect); | |
118 | } | |
119 | ||
120 | static void __exit wis_ov7640_cleanup(void) | |
121 | { | |
122 | wis_i2c_del_driver(wis_ov7640_detect); | |
123 | i2c_del_driver(&wis_ov7640_driver); | |
124 | } | |
125 | ||
126 | module_init(wis_ov7640_init); | |
127 | module_exit(wis_ov7640_cleanup); | |
128 | ||
129 | MODULE_LICENSE("GPL v2"); |