diff options
author | Wolfram Sang <w.sang@pengutronix.de> | 2010-03-05 16:44:33 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2010-03-06 14:26:48 -0500 |
commit | e952805d2d2e706aed182723e5ab3ec0b1f91de3 (patch) | |
tree | 5b4f9bfff6798f44fdea7c891ee911af2df5357b /drivers/gpio/max7300.c | |
parent | 5a98c04d78c896d52baef20ffc11f6d1ba6eb786 (diff) |
gpio: add driver for MAX7300 I2C GPIO extender
Add the MAX7300-I2C variant of the MAX7301-SPI version. Both chips share
the same core logic, so the generic part of the in-kernel SPI-driver is
refactored into a generic part. The I2C and SPI specific funtions are
then wrapped into seperate drivers picking up the generic part.
Signed-off-by: Wolfram Sang <w.sang@pengutronix.de>
Cc: Juergen Beisert <j.beisert@pengutronix.de>
Cc: David Brownell <dbrownell@users.sourceforge.net>
Cc: Jean Delvare <khali@linux-fr.org>
Cc: Anton Vorontsov <avorontsov@ru.mvista.com>
Cc: Randy Dunlap <randy.dunlap@oracle.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'drivers/gpio/max7300.c')
-rw-r--r-- | drivers/gpio/max7300.c | 94 |
1 files changed, 94 insertions, 0 deletions
diff --git a/drivers/gpio/max7300.c b/drivers/gpio/max7300.c new file mode 100644 index 000000000000..9d74eef1157a --- /dev/null +++ b/drivers/gpio/max7300.c | |||
@@ -0,0 +1,94 @@ | |||
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"); | ||