1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18#include <linux/module.h>
19#include <linux/init.h>
20#include <linux/i2c.h>
21#include <linux/videodev2.h>
22
23#include "wis-i2c.h"
24
25struct wis_ov7640 {
26 int brightness;
27 int contrast;
28 int saturation;
29 int hue;
30};
31
32static 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,
41};
42
43static 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
53static int wis_ov7640_probe(struct i2c_client *client,
54 const struct i2c_device_id *id)
55{
56 struct i2c_adapter *adapter = client->adapter;
57
58 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
59 return -ENODEV;
60
61 client->flags = I2C_CLIENT_SCCB;
62
63 printk(KERN_DEBUG
64 "wis-ov7640: initializing OV7640 at address %d on %s\n",
65 client->addr, adapter->name);
66
67 if (write_regs(client, initial_registers) < 0) {
68 printk(KERN_ERR "wis-ov7640: error initializing OV7640\n");
69 return -ENODEV;
70 }
71
72 return 0;
73}
74
75static int wis_ov7640_remove(struct i2c_client *client)
76{
77 return 0;
78}
79
80static struct i2c_device_id wis_ov7640_id[] = {
81 { "wis_ov7640", 0 },
82 { }
83};
84
85static struct i2c_driver wis_ov7640_driver = {
86 .driver = {
87 .name = "WIS OV7640 I2C driver",
88 },
89 .probe = wis_ov7640_probe,
90 .remove = wis_ov7640_remove,
91 .id_table = wis_ov7640_id,
92};
93
94static int __init wis_ov7640_init(void)
95{
96 return i2c_add_driver(&wis_ov7640_driver);
97}
98
99static void __exit wis_ov7640_cleanup(void)
100{
101 i2c_del_driver(&wis_ov7640_driver);
102}
103
104module_init(wis_ov7640_init);
105module_exit(wis_ov7640_cleanup);
106
107MODULE_LICENSE("GPL v2");
108