aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWolfram Sang <w.sang@pengutronix.de>2010-03-05 16:44:33 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2010-03-06 14:26:48 -0500
commite952805d2d2e706aed182723e5ab3ec0b1f91de3 (patch)
tree5b4f9bfff6798f44fdea7c891ee911af2df5357b
parent5a98c04d78c896d52baef20ffc11f6d1ba6eb786 (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>
-rw-r--r--drivers/gpio/Kconfig13
-rw-r--r--drivers/gpio/Makefile2
-rw-r--r--drivers/gpio/max7300.c94
-rw-r--r--drivers/gpio/max7301.c293
-rw-r--r--drivers/gpio/max730x.c244
-rw-r--r--include/linux/spi/max7301.h18
6 files changed, 404 insertions, 260 deletions
diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig
index 1f1d88ae68d6..f3549b8779d8 100644
--- a/drivers/gpio/Kconfig
+++ b/drivers/gpio/Kconfig
@@ -65,6 +65,9 @@ config GPIO_SYSFS
65 65
66# put expanders in the right section, in alphabetical order 66# put expanders in the right section, in alphabetical order
67 67
68config GPIO_MAX730X
69 tristate
70
68comment "Memory mapped GPIO expanders:" 71comment "Memory mapped GPIO expanders:"
69 72
70config GPIO_PL061 73config GPIO_PL061
@@ -87,6 +90,13 @@ config GPIO_VR41XX
87 90
88comment "I2C GPIO expanders:" 91comment "I2C GPIO expanders:"
89 92
93config GPIO_MAX7300
94 tristate "Maxim MAX7300 GPIO expander"
95 depends on I2C
96 select GPIO_MAX730X
97 help
98 GPIO driver for Maxim MAX7301 I2C-based GPIO expander.
99
90config GPIO_MAX732X 100config GPIO_MAX732X
91 tristate "MAX7319, MAX7320-7327 I2C Port Expanders" 101 tristate "MAX7319, MAX7320-7327 I2C Port Expanders"
92 depends on I2C 102 depends on I2C
@@ -226,8 +236,9 @@ comment "SPI GPIO expanders:"
226config GPIO_MAX7301 236config GPIO_MAX7301
227 tristate "Maxim MAX7301 GPIO expander" 237 tristate "Maxim MAX7301 GPIO expander"
228 depends on SPI_MASTER 238 depends on SPI_MASTER
239 select GPIO_MAX730X
229 help 240 help
230 gpio driver for Maxim MAX7301 SPI GPIO expander. 241 GPIO driver for Maxim MAX7301 SPI-based GPIO expander.
231 242
232config GPIO_MCP23S08 243config GPIO_MCP23S08
233 tristate "Microchip MCP23S08 I/O expander" 244 tristate "Microchip MCP23S08 I/O expander"
diff --git a/drivers/gpio/Makefile b/drivers/gpio/Makefile
index 48687238edb1..508a1b202cdb 100644
--- a/drivers/gpio/Makefile
+++ b/drivers/gpio/Makefile
@@ -7,6 +7,8 @@ obj-$(CONFIG_GPIOLIB) += gpiolib.o
7obj-$(CONFIG_GPIO_ADP5520) += adp5520-gpio.o 7obj-$(CONFIG_GPIO_ADP5520) += adp5520-gpio.o
8obj-$(CONFIG_GPIO_ADP5588) += adp5588-gpio.o 8obj-$(CONFIG_GPIO_ADP5588) += adp5588-gpio.o
9obj-$(CONFIG_GPIO_LANGWELL) += langwell_gpio.o 9obj-$(CONFIG_GPIO_LANGWELL) += langwell_gpio.o
10obj-$(CONFIG_GPIO_MAX730X) += max730x.o
11obj-$(CONFIG_GPIO_MAX7300) += max7300.o
10obj-$(CONFIG_GPIO_MAX7301) += max7301.o 12obj-$(CONFIG_GPIO_MAX7301) += max7301.o
11obj-$(CONFIG_GPIO_MAX732X) += max732x.o 13obj-$(CONFIG_GPIO_MAX732X) += max732x.o
12obj-$(CONFIG_GPIO_MC33880) += mc33880.o 14obj-$(CONFIG_GPIO_MC33880) += mc33880.o
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
20static 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
28static 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
35static 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
59static int __devexit max7300_remove(struct i2c_client *client)
60{
61 return __max730x_remove(&client->dev);
62}
63
64static const struct i2c_device_id max7300_id[] = {
65 { "max7300", 0 },
66 { }
67};
68MODULE_DEVICE_TABLE(i2c, max7300_id);
69
70static 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
80static int __init max7300_init(void)
81{
82 return i2c_add_driver(&max7300_driver);
83}
84subsys_initcall(max7300_init);
85
86static void __exit max7300_exit(void)
87{
88 i2c_del_driver(&max7300_driver);
89}
90module_exit(max7300_exit);
91
92MODULE_AUTHOR("Wolfram Sang");
93MODULE_LICENSE("GPL v2");
94MODULE_DESCRIPTION("MAX7300 GPIO-Expander");
diff --git a/drivers/gpio/max7301.c b/drivers/gpio/max7301.c
index 480956f1ca50..965d9b1ea13e 100644
--- a/drivers/gpio/max7301.c
+++ b/drivers/gpio/max7301.c
@@ -1,98 +1,41 @@
1/** 1/*
2 * drivers/gpio/max7301.c 2 * drivers/gpio/max7301.c
3 * 3 *
4 * Copyright (C) 2006 Juergen Beisert, Pengutronix 4 * Copyright (C) 2006 Juergen Beisert, Pengutronix
5 * Copyright (C) 2008 Guennadi Liakhovetski, Pengutronix 5 * Copyright (C) 2008 Guennadi Liakhovetski, Pengutronix
6 * Copyright (C) 2009 Wolfram Sang, Pengutronix
6 * 7 *
7 * This program is free software; you can redistribute it and/or modify 8 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as 9 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation. 10 * published by the Free Software Foundation.
10 * 11 *
11 * The Maxim's MAX7301 device is an SPI driven GPIO expander. There are 12 * Check max730x.c for further details.
12 * 28 GPIOs. 8 of them can trigger an interrupt. See datasheet for more
13 * details
14 * Note:
15 * - DIN must be stable at the rising edge of clock.
16 * - when writing:
17 * - always clock in 16 clocks at once
18 * - at DIN: D15 first, D0 last
19 * - D0..D7 = databyte, D8..D14 = commandbyte
20 * - D15 = low -> write command
21 * - when reading
22 * - always clock in 16 clocks at once
23 * - at DIN: D15 first, D0 last
24 * - D0..D7 = dummy, D8..D14 = register address
25 * - D15 = high -> read command
26 * - raise CS and assert it again
27 * - always clock in 16 clocks at once
28 * - at DOUT: D15 first, D0 last
29 * - D0..D7 contains the data from the first cycle
30 *