Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/sage/ceph...
[pandora-kernel.git] / drivers / gpio / max7300.c
1 /*
2  * drivers/gpio/max7300.c
3  *
4  * Copyright (C) 2009 Wolfram Sang, Pengutronix
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 as
8  * published by the Free Software Foundation.
9  *
10  * Check max730x.c for further details.
11  */
12
13 #include <linux/module.h>
14 #include <linux/init.h>
15 #include <linux/platform_device.h>
16 #include <linux/mutex.h>
17 #include <linux/i2c.h>
18 #include <linux/spi/max7301.h>
19
20 static int max7300_i2c_write(struct device *dev, unsigned int reg,
21                                 unsigned int val)
22 {
23         struct i2c_client *client = to_i2c_client(dev);
24
25         return i2c_smbus_write_byte_data(client, reg, val);
26 }
27
28 static int max7300_i2c_read(struct device *dev, unsigned int reg)
29 {
30         struct i2c_client *client = to_i2c_client(dev);
31
32         return i2c_smbus_read_byte_data(client, reg);
33 }
34
35 static int __devinit max7300_probe(struct i2c_client *client,
36                          const struct i2c_device_id *id)
37 {
38         struct max7301 *ts;
39         int ret;
40
41         if (!i2c_check_functionality(client->adapter,
42                         I2C_FUNC_SMBUS_BYTE_DATA))
43                 return -EIO;
44
45         ts = kzalloc(sizeof(struct max7301), GFP_KERNEL);
46         if (!ts)
47                 return -ENOMEM;
48
49         ts->read = max7300_i2c_read;
50         ts->write = max7300_i2c_write;
51         ts->dev = &client->dev;
52
53         ret = __max730x_probe(ts);
54         if (ret)
55                 kfree(ts);
56         return ret;
57 }
58
59 static int __devexit max7300_remove(struct i2c_client *client)
60 {
61         return __max730x_remove(&client->dev);
62 }
63
64 static const struct i2c_device_id max7300_id[] = {
65         { "max7300", 0 },
66         { }
67 };
68 MODULE_DEVICE_TABLE(i2c, max7300_id);
69
70 static struct i2c_driver max7300_driver = {
71         .driver = {
72                 .name = "max7300",
73                 .owner = THIS_MODULE,
74         },
75         .probe = max7300_probe,
76         .remove = __devexit_p(max7300_remove),
77         .id_table = max7300_id,
78 };
79
80 static int __init max7300_init(void)
81 {
82         return i2c_add_driver(&max7300_driver);
83 }
84 subsys_initcall(max7300_init);
85
86 static void __exit max7300_exit(void)
87 {
88         i2c_del_driver(&max7300_driver);
89 }
90 module_exit(max7300_exit);
91
92 MODULE_AUTHOR("Wolfram Sang");
93 MODULE_LICENSE("GPL v2");
94 MODULE_DESCRIPTION("MAX7300 GPIO-Expander");