blob: 6bc9470fecb6f13de14d8bb1106a5209525f1102 [file] [log] [blame]
Greg Kroah-Hartman866b8692008-02-15 16:53:09 -08001/*
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>
Greg Kroah-Hartman866b8692008-02-15 16:53:09 -080020#include <linux/i2c.h>
Ross Cohendf20d692008-09-29 22:36:24 -040021#include <linux/videodev2.h>
Greg Kroah-Hartman866b8692008-02-15 16:53:09 -080022
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, /* Terminator (reg 0xFF is unused) */
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
Jean Delvare74005162009-04-21 21:47:22 +020053static int wis_ov7640_probe(struct i2c_client *client,
54 const struct i2c_device_id *id)
Greg Kroah-Hartman866b8692008-02-15 16:53:09 -080055{
Jean Delvare74005162009-04-21 21:47:22 +020056 struct i2c_adapter *adapter = client->adapter;
Greg Kroah-Hartman866b8692008-02-15 16:53:09 -080057
58 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
Jean Delvare74005162009-04-21 21:47:22 +020059 return -ENODEV;
Greg Kroah-Hartman866b8692008-02-15 16:53:09 -080060
Greg Kroah-Hartman866b8692008-02-15 16:53:09 -080061 client->flags = I2C_CLIENT_SCCB;
62
63 printk(KERN_DEBUG
64 "wis-ov7640: initializing OV7640 at address %d on %s\n",
Jean Delvare74005162009-04-21 21:47:22 +020065 client->addr, adapter->name);
Greg Kroah-Hartman866b8692008-02-15 16:53:09 -080066
67 if (write_regs(client, initial_registers) < 0) {
68 printk(KERN_ERR "wis-ov7640: error initializing OV7640\n");
Jean Delvare74005162009-04-21 21:47:22 +020069 return -ENODEV;
Greg Kroah-Hartman866b8692008-02-15 16:53:09 -080070 }
71
Greg Kroah-Hartman866b8692008-02-15 16:53:09 -080072 return 0;
73}
74
Jean Delvare74005162009-04-21 21:47:22 +020075static int wis_ov7640_remove(struct i2c_client *client)
Greg Kroah-Hartman866b8692008-02-15 16:53:09 -080076{
Greg Kroah-Hartman866b8692008-02-15 16:53:09 -080077 return 0;
78}
79
Németh Mártonb76a3262010-01-10 00:18:41 +010080static const struct i2c_device_id wis_ov7640_id[] = {
Jean Delvare74005162009-04-21 21:47:22 +020081 { "wis_ov7640", 0 },
82 { }
83};
Laurent Pinchart3946b4a2010-09-24 08:09:08 -030084MODULE_DEVICE_TABLE(i2c, wis_ov7640_id);
Jean Delvare74005162009-04-21 21:47:22 +020085
Greg Kroah-Hartman866b8692008-02-15 16:53:09 -080086static struct i2c_driver wis_ov7640_driver = {
87 .driver = {
88 .name = "WIS OV7640 I2C driver",
89 },
Jean Delvare74005162009-04-21 21:47:22 +020090 .probe = wis_ov7640_probe,
91 .remove = wis_ov7640_remove,
92 .id_table = wis_ov7640_id,
Greg Kroah-Hartman866b8692008-02-15 16:53:09 -080093};
94
95static int __init wis_ov7640_init(void)
96{
Jean Delvare74005162009-04-21 21:47:22 +020097 return i2c_add_driver(&wis_ov7640_driver);
Greg Kroah-Hartman866b8692008-02-15 16:53:09 -080098}
99
100static void __exit wis_ov7640_cleanup(void)
101{
Greg Kroah-Hartman866b8692008-02-15 16:53:09 -0800102 i2c_del_driver(&wis_ov7640_driver);
103}
104
105module_init(wis_ov7640_init);
106module_exit(wis_ov7640_cleanup);
107
108MODULE_LICENSE("GPL v2");