]> git.karo-electronics.de Git - karo-tx-linux.git/blob - drivers/staging/media/go7007/wis-ov7640.c
Merge remote-tracking branch 'linus/master' into staging/for_v3.8
[karo-tx-linux.git] / drivers / staging / media / go7007 / wis-ov7640.c
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>
20 #include <linux/i2c.h>
21 #include <linux/videodev2.h>
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         0x12, 0x80,
34         0x12, 0x54,
35         0x14, 0x24,
36         0x15, 0x01,
37         0x28, 0x20,
38         0x75, 0x82,
39         0xFF, 0xFF, /* Terminator (reg 0xFF is unused) */
40 };
41
42 static int write_regs(struct i2c_client *client, u8 *regs)
43 {
44         int i;
45
46         for (i = 0; regs[i] != 0xFF; i += 2)
47                 if (i2c_smbus_write_byte_data(client, regs[i], regs[i + 1]) < 0)
48                         return -1;
49         return 0;
50 }
51
52 static int wis_ov7640_probe(struct i2c_client *client,
53                             const struct i2c_device_id *id)
54 {
55         struct i2c_adapter *adapter = client->adapter;
56
57         if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
58                 return -ENODEV;
59
60         client->flags = I2C_CLIENT_SCCB;
61
62         dev_dbg(&client->dev,
63                 "wis-ov7640: initializing OV7640 at address %d on %s\n",
64                 client->addr, adapter->name);
65
66         if (write_regs(client, initial_registers) < 0) {
67                 dev_err(&client->dev, "wis-ov7640: error initializing OV7640\n");
68                 return -ENODEV;
69         }
70
71         return 0;
72 }
73
74 static int wis_ov7640_remove(struct i2c_client *client)
75 {
76         return 0;
77 }
78
79 static const struct i2c_device_id wis_ov7640_id[] = {
80         { "wis_ov7640", 0 },
81         { }
82 };
83 MODULE_DEVICE_TABLE(i2c, wis_ov7640_id);
84
85 static 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
94 module_i2c_driver(wis_ov7640_driver);
95
96 MODULE_LICENSE("GPL v2");