Skip to content

Commit

Permalink
gpio: add driver for MAX7300 I2C GPIO extender
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Wolfram Sang authored and Linus Torvalds committed Mar 6, 2010
1 parent 5a98c04 commit e952805
Show file tree
Hide file tree
Showing 6 changed files with 404 additions and 260 deletions.
13 changes: 12 additions & 1 deletion drivers/gpio/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ config GPIO_SYSFS

# put expanders in the right section, in alphabetical order

config GPIO_MAX730X
tristate

comment "Memory mapped GPIO expanders:"

config GPIO_PL061
Expand All @@ -87,6 +90,13 @@ config GPIO_VR41XX

comment "I2C GPIO expanders:"

config GPIO_MAX7300
tristate "Maxim MAX7300 GPIO expander"
depends on I2C
select GPIO_MAX730X
help
GPIO driver for Maxim MAX7301 I2C-based GPIO expander.

config GPIO_MAX732X
tristate "MAX7319, MAX7320-7327 I2C Port Expanders"
depends on I2C
Expand Down Expand Up @@ -226,8 +236,9 @@ comment "SPI GPIO expanders:"
config GPIO_MAX7301
tristate "Maxim MAX7301 GPIO expander"
depends on SPI_MASTER
select GPIO_MAX730X
help
gpio driver for Maxim MAX7301 SPI GPIO expander.
GPIO driver for Maxim MAX7301 SPI-based GPIO expander.

config GPIO_MCP23S08
tristate "Microchip MCP23S08 I/O expander"
Expand Down
2 changes: 2 additions & 0 deletions drivers/gpio/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ obj-$(CONFIG_GPIOLIB) += gpiolib.o
obj-$(CONFIG_GPIO_ADP5520) += adp5520-gpio.o
obj-$(CONFIG_GPIO_ADP5588) += adp5588-gpio.o
obj-$(CONFIG_GPIO_LANGWELL) += langwell_gpio.o
obj-$(CONFIG_GPIO_MAX730X) += max730x.o
obj-$(CONFIG_GPIO_MAX7300) += max7300.o
obj-$(CONFIG_GPIO_MAX7301) += max7301.o
obj-$(CONFIG_GPIO_MAX732X) += max732x.o
obj-$(CONFIG_GPIO_MC33880) += mc33880.o
Expand Down
94 changes: 94 additions & 0 deletions drivers/gpio/max7300.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
/*
* drivers/gpio/max7300.c
*
* Copyright (C) 2009 Wolfram Sang, Pengutronix
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* Check max730x.c for further details.
*/

#include <linux/module.h>
#include <linux/init.h>
#include <linux/platform_device.h>
#include <linux/mutex.h>
#include <linux/i2c.h>
#include <linux/spi/max7301.h>

static int max7300_i2c_write(struct device *dev, unsigned int reg,
unsigned int val)
{
struct i2c_client *client = to_i2c_client(dev);

return i2c_smbus_write_byte_data(client, reg, val);
}

static int max7300_i2c_read(struct device *dev, unsigned int reg)
{
struct i2c_client *client = to_i2c_client(dev);

return i2c_smbus_read_byte_data(client, reg);
}

static int __devinit max7300_probe(struct i2c_client *client,
const struct i2c_device_id *id)
{
struct max7301 *ts;
int ret;

if (!i2c_check_functionality(client->adapter,
I2C_FUNC_SMBUS_BYTE_DATA))
return -EIO;

ts = kzalloc(sizeof(struct max7301), GFP_KERNEL);
if (!ts)
return -ENOMEM;

ts->read = max7300_i2c_read;
ts->write = max7300_i2c_write;
ts->dev = &client->dev;

ret = __max730x_probe(ts);
if (ret)
kfree(ts);
return ret;
}

static int __devexit max7300_remove(struct i2c_client *client)
{
return __max730x_remove(&client->dev);
}

static const struct i2c_device_id max7300_id[] = {
{ "max7300", 0 },
{ }
};
MODULE_DEVICE_TABLE(i2c, max7300_id);

static struct i2c_driver max7300_driver = {
.driver = {
.name = "max7300",
.owner = THIS_MODULE,
},
.probe = max7300_probe,
.remove = __devexit_p(max7300_remove),
.id_table = max7300_id,
};

static int __init max7300_init(void)
{
return i2c_add_driver(&max7300_driver);
}
subsys_initcall(max7300_init);

static void __exit max7300_exit(void)
{
i2c_del_driver(&max7300_driver);
}
module_exit(max7300_exit);

MODULE_AUTHOR("Wolfram Sang");
MODULE_LICENSE("GPL v2");
MODULE_DESCRIPTION("MAX7300 GPIO-Expander");
Loading

0 comments on commit e952805

Please sign in to comment.