public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
* [U-Boot] [PATCH] gpio: Adapt PCA9698 to standard GPIO API
@ 2011-10-31  8:39 Dirk Eibach
  2011-10-31 18:30 ` Mike Frysinger
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Dirk Eibach @ 2011-10-31  8:39 UTC (permalink / raw)
  To: u-boot

Signed-off-by: Dirk Eibach <eibach@gdsys.de>
---
 drivers/gpio/pca9698.c |   62 +++++++++++++++++++++++++++++++----------------
 include/pca9698.h      |   33 ++++++++++++++++++++++---
 2 files changed, 70 insertions(+), 25 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);
 }
diff --git a/include/pca9698.h b/include/pca9698.h
index 2506088..67b364e 100644
--- a/include/pca9698.h
+++ b/include/pca9698.h
@@ -1,9 +1,34 @@
+/*
+ * (C) Copyright 2011
+ * Dirk Eibach,  Guntermann & Drunck GmbH, eibach at gdsys.de
+ *
+ * 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
+ */
+
 #ifndef __PCA9698_H_
 #define __PCA9698_H_
 
-int pca9698_direction_input(u8 chip, unsigned offset);
-int pca9698_direction_output(u8 chip, unsigned offset);
-int pca9698_get_input(u8 chip, unsigned offset);
-int pca9698_set_output(u8 chip, unsigned offset, int value);
+int pca9698_request(unsigned gpio, const char *label);
+void pca9698_free(unsigned gpio);
+int pca9698_direction_input(u8 addr, unsigned gpio);
+int pca9698_direction_output(u8 addr, unsigned gpio, int value);
+int pca9698_get_value(u8 addr, unsigned gpio);
+int pca9698_set_value(u8 addr, unsigned gpio, int value);
 
 #endif /* __PCA9698_H_ */
-- 
1.5.6.5

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [U-Boot] [PATCH] gpio: Adapt PCA9698 to standard GPIO API
  2011-10-31  8:39 [U-Boot] [PATCH] gpio: Adapt PCA9698 to standard GPIO API Dirk Eibach
@ 2011-10-31 18:30 ` Mike Frysinger
  2011-11-01  6:42 ` Stefan Roese
  2011-11-18 13:12 ` Stefan Roese
  2 siblings, 0 replies; 4+ messages in thread
From: Mike Frysinger @ 2011-10-31 18:30 UTC (permalink / raw)
  To: u-boot

nice ...
Acked-by: Mike Frysinger <vapier@gentoo.org>
-mike
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part.
Url : http://lists.denx.de/pipermail/u-boot/attachments/20111031/ff1b8df3/attachment.pgp 

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [U-Boot] [PATCH] gpio: Adapt PCA9698 to standard GPIO API
  2011-10-31  8:39 [U-Boot] [PATCH] gpio: Adapt PCA9698 to standard GPIO API Dirk Eibach
  2011-10-31 18:30 ` Mike Frysinger
@ 2011-11-01  6:42 ` Stefan Roese
  2011-11-18 13:12 ` Stefan Roese
  2 siblings, 0 replies; 4+ messages in thread
From: Stefan Roese @ 2011-11-01  6:42 UTC (permalink / raw)
  To: u-boot

On Monday 31 October 2011 09:39:12 Dirk Eibach wrote:
> Signed-off-by: Dirk Eibach <eibach@gdsys.de>

Acked-by: Stefan Roese <sr@denx.de>

Thanks,
Stefan

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [U-Boot] [PATCH] gpio: Adapt PCA9698 to standard GPIO API
  2011-10-31  8:39 [U-Boot] [PATCH] gpio: Adapt PCA9698 to standard GPIO API Dirk Eibach
  2011-10-31 18:30 ` Mike Frysinger
  2011-11-01  6:42 ` Stefan Roese
@ 2011-11-18 13:12 ` Stefan Roese
  2 siblings, 0 replies; 4+ messages in thread
From: Stefan Roese @ 2011-11-18 13:12 UTC (permalink / raw)
  To: u-boot

On Monday 31 October 2011 09:39:12 Dirk Eibach wrote:
> Signed-off-by: Dirk Eibach <eibach@gdsys.de>

Applied to u-boot-staging sr at denx.de. Thanks.

Best regards,
Stefan

--
DENX Software Engineering GmbH,      MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich,  Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-0 Fax: (+49)-8142-66989-80 Email: office at denx.de

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2011-11-18 13:12 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-10-31  8:39 [U-Boot] [PATCH] gpio: Adapt PCA9698 to standard GPIO API Dirk Eibach
2011-10-31 18:30 ` Mike Frysinger
2011-11-01  6:42 ` Stefan Roese
2011-11-18 13:12 ` Stefan Roese

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox