diff options
author | Dirk Eibach <eibach@gdsys.de> | 2011-10-31 09:39:12 +0100 |
---|---|---|
committer | Stefan Roese <sr@denx.de> | 2011-11-18 14:04:25 +0100 |
commit | 042f9f106272a46214dccbe6177b11d87798351d (patch) | |
tree | 9017d9d3cdb3d18fa8a679dcd2968f6c0ba676dc /drivers | |
parent | 5721385b187b3154c7768e6c182501022f4e2e45 (diff) | |
download | u-boot-imx-042f9f106272a46214dccbe6177b11d87798351d.zip u-boot-imx-042f9f106272a46214dccbe6177b11d87798351d.tar.gz u-boot-imx-042f9f106272a46214dccbe6177b11d87798351d.tar.bz2 |
gpio: Adapt PCA9698 to standard GPIO API
Signed-off-by: Dirk Eibach <eibach@gdsys.de>
Acked-by: Mike Frysinger <vapier@gentoo.org>
Acked-by: Stefan Roese <sr@denx.de>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/gpio/pca9698.c | 62 |
1 files changed, 41 insertions, 21 deletions
diff --git a/drivers/gpio/pca9698.c b/drivers/gpio/pca9698.c index b946efa..fe6d2c6 100644 --- a/drivers/gpio/pca9698.c +++ b/drivers/gpio/pca9698.c @@ -27,6 +27,7 @@ #include <common.h> #include <i2c.h> +#include <asm/errno.h> #include <pca9698.h> /* @@ -39,19 +40,20 @@ #define PCA9698_REG_CONFIG 0x18 #define PCA9698_BUFFER_SIZE 5 +#define PCA9698_GPIO_COUNT 40 -static int pca9698_read40(u8 chip, u8 offset, u8 *buffer) +static int pca9698_read40(u8 addr, u8 offset, u8 *buffer) { u8 command = offset | 0x80; /* autoincrement */ - return i2c_read(chip, command, 1, buffer, PCA9698_BUFFER_SIZE); + return i2c_read(addr, command, 1, buffer, PCA9698_BUFFER_SIZE); } -static int pca9698_write40(u8 chip, u8 offset, u8 *buffer) +static int pca9698_write40(u8 addr, u8 offset, u8 *buffer) { u8 command = offset | 0x80; /* autoincrement */ - return i2c_write(chip, command, 1, buffer, PCA9698_BUFFER_SIZE); + return i2c_write(addr, command, 1, buffer, PCA9698_BUFFER_SIZE); } static void pca9698_set_bit(unsigned gpio, u8 *buffer, unsigned value) @@ -65,41 +67,59 @@ static void pca9698_set_bit(unsigned gpio, u8 *buffer, unsigned value) buffer[byte] &= ~(1 << bit); } -int pca9698_direction_input(u8 chip, unsigned offset) +int pca9698_request(unsigned gpio, const char *label) +{ + if (gpio >= PCA9698_GPIO_COUNT) + return -EINVAL; + + return 0; +} + +void pca9698_free(unsigned gpio) +{ +} + +int pca9698_direction_input(u8 addr, unsigned gpio) { u8 data[PCA9698_BUFFER_SIZE]; int res; - res = pca9698_read40(chip, PCA9698_REG_CONFIG, data); + res = pca9698_read40(addr, PCA9698_REG_CONFIG, data); if (res) return res; - pca9698_set_bit(offset, data, 1); - return pca9698_write40(chip, PCA9698_REG_CONFIG, data); + pca9698_set_bit(gpio, data, 1); + + return pca9698_write40(addr, PCA9698_REG_CONFIG, data); } -int pca9698_direction_output(u8 chip, unsigned offset) +int pca9698_direction_output(u8 addr, unsigned gpio, int value) { u8 data[PCA9698_BUFFER_SIZE]; int res; - res = pca9698_read40(chip, PCA9698_REG_CONFIG, data); + res = pca9698_set_value(addr, gpio, value); + if (res) + return res; + + res = pca9698_read40(addr, PCA9698_REG_CONFIG, data); if (res) return res; - pca9698_set_bit(offset, data, 0); - return pca9698_write40(chip, PCA9698_REG_CONFIG, data); + pca9698_set_bit(gpio, data, 0); + + return pca9698_write40(addr, PCA9698_REG_CONFIG, data); } -int pca9698_get_input(u8 chip, unsigned offset) +int pca9698_get_value(u8 addr, unsigned gpio) { - unsigned config_byte = offset / 8; - unsigned config_bit = offset % 8; + unsigned config_byte = gpio / 8; + unsigned config_bit = gpio % 8; unsigned value; u8 data[PCA9698_BUFFER_SIZE]; int res; - res = pca9698_read40(chip, PCA9698_REG_INPUT, data); + res = pca9698_read40(addr, PCA9698_REG_INPUT, data); if (res) return -1; @@ -108,16 +128,16 @@ int pca9698_get_input(u8 chip, unsigned offset) return !!value; } -int pca9698_set_output(u8 chip, unsigned offset, int value) +int pca9698_set_value(u8 addr, unsigned gpio, int value) { u8 data[PCA9698_BUFFER_SIZE]; int res; - res = pca9698_read40(chip, PCA9698_REG_OUTPUT, data); + res = pca9698_read40(addr, PCA9698_REG_OUTPUT, data); if (res) return res; - memset(data, sizeof(data), 0); - pca9698_set_bit(offset, data, value); - return pca9698_write40(chip, PCA9698_REG_OUTPUT, data); + pca9698_set_bit(gpio, data, value); + + return pca9698_write40(addr, PCA9698_REG_OUTPUT, data); } |