From d46a7e3528b5f86610ee388a18a9698a3d26e6fb Mon Sep 17 00:00:00 2001 From: Rabin Vincent Date: Fri, 19 Mar 2010 18:21:33 +0530 Subject: Add TC35892 I2C GPIO expander driver Add a simple driver for the I2C-controlled TC35892 GPIO expander. Change-Id: I49389d808353ca6b43cc38e1c7518de38f14ef51 Signed-off-by: Rabin Vincent Reviewed-on: http://gerrit.lud.stericsson.com/gerrit/1047 Reviewed-by: Par-Olof HAKANSSON Reviewed-by: Jonas ABERG Tested-by: Jonas ABERG --- drivers/gpio/Makefile | 1 + drivers/gpio/tc35892.c | 76 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 77 insertions(+) create mode 100644 drivers/gpio/tc35892.c (limited to 'drivers') diff --git a/drivers/gpio/Makefile b/drivers/gpio/Makefile index acba56c1c..fc3ee5ea9 100644 --- a/drivers/gpio/Makefile +++ b/drivers/gpio/Makefile @@ -28,6 +28,7 @@ LIB := $(obj)libgpio.a COBJS-$(CONFIG_KIRKWOOD_GPIO) += kw_gpio.o COBJS-$(CONFIG_MX31_GPIO) += mx31_gpio.o COBJS-$(CONFIG_PCA953X) += pca953x.o +COBJS-$(CONFIG_TC35892_GPIO) += tc35892.o COBJS := $(COBJS-y) SRCS := $(COBJS:.o=.c) diff --git a/drivers/gpio/tc35892.c b/drivers/gpio/tc35892.c new file mode 100644 index 000000000..7fa55263d --- /dev/null +++ b/drivers/gpio/tc35892.c @@ -0,0 +1,76 @@ +/* + * Copyright (C) 2010 ST-Ericsson SA + * + * Author: Rabin Vincent + * + * See file CREDITS for list of people who contributed to this + * project. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + */ + +#include +#include +#include + +#define GPIODATA0 0xC0 +#define GPIODATA1 0xC2 +#define GPIODATA2 0xC4 +#define GPIODIR0 0xC6 +#define GPIODIR1 0xC7 +#define GPIODIR2 0xC8 + +int tc35892_gpio_dir(int addr, int pin, int dir) +{ + uchar reg = GPIODIR0 + pin / 8; + uchar pos = pin % 8; + uchar data; + int ret; + + ret = i2c_read(addr, reg, sizeof(reg), &data, sizeof(data)); + if (ret) + return ret; + + if (dir) + data |= (1 << pos); + else + data &= ~(1 << pos); + + return i2c_write(addr, reg, sizeof(reg), &data, sizeof(data)); +} + +int tc35892_gpio_get(int addr, int pin, int val) +{ + uchar reg = GPIODATA0 + (pin / 8) * 2; + uchar pos = pin % 8; + uchar data; + int ret; + + ret = i2c_read(addr, reg, sizeof(reg), &data, sizeof(data)); + if (ret < 0) + return ret; + + return !!(data & (1 << pos)); +} + +int tc35892_gpio_set(int addr, int pin, int val) +{ + uchar reg = GPIODATA0 + (pin / 8) * 2; + uchar pos = pin % 8; + uchar data[] = {val << pos, 1 << pos}; + + return i2c_write(addr, reg, sizeof(reg), data, sizeof(data)); +} -- cgit v1.2.3