Re: [U-Boot] [PATCHv3] pca953x: support 16-pin devices

2010-12-18 Thread Wolfgang Denk
Dear Chris Packham,

In message aanlkti=uruvino-px-yc+7ofskodjadd_qpgrydrh...@mail.gmail.com you 
wrote:

 There is one minor fixup we might want to squash into v3 (or if
 someone wants me to submit a v4 I can). It makes sense to have
 pca953x_ngpio as a function in both cases. The compiler will
 auto-inline the function so we won't see a increase in size and having
 a function instead of a macro allows the compiler to do proper type
 checking.

Please send a v4.  Thanks.

Best regards,

Wolfgang Denk

-- 
DENX Software Engineering GmbH, MD: Wolfgang Denk  Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: w...@denx.de
I've seen it. It's rubbish.  - Marvin the Paranoid Android
___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


Re: [U-Boot] [PATCHv3] pca953x: support 16-pin devices

2010-12-14 Thread Chris Packham
On Fri, Dec 10, 2010 at 6:08 AM, Peter Tyser pty...@xes-inc.com wrote:
 On Thu, 2010-12-09 at 22:11 +1300, Chris Packham wrote:
 This adds support for for the PCA9535/PCA9539 family of gpio devices which
 have 16 output pins.

 To let the driver know which devices are 16-pin it is necessary to define
 CONFIG_SYS_I2C_PCA953X_WIDTH in your board config file. This is used to
 create an array of {chip, ngpio} tuples that are used to determine the
 width of a particular chip. For backwards compatibility it is assumed that
 any chip not defined in CONFIG_SYS_I2C_PCA953X_WIDTH has 8 pins.

 Signed-off-by: Chris Packham chris.pack...@alliedtelesis.co.nz

 Looks good to me and works as advertised.

 Acked-by: Peter Tyser pty...@xes-inc.com
 Tested-by: Peter Tyser pty...@xes-inc.com


There is one minor fixup we might want to squash into v3 (or if
someone wants me to submit a v4 I can). It makes sense to have
pca953x_ngpio as a function in both cases. The compiler will
auto-inline the function so we won't see a increase in size and having
a function instead of a macro allows the compiler to do proper type
checking.

---8---

From: Chris Packham chris.pack...@alliedtelesis.co.nz
Date: Wed, 15 Dec 2010 15:44:17 +1300
Subject: [PATCH] fixup! pca953x: support 16-pin devices

---
 drivers/gpio/pca953x.c |5 -
 1 files changed, 4 insertions(+), 1 deletions(-)

diff --git a/drivers/gpio/pca953x.c b/drivers/gpio/pca953x.c
index c8f5403..359fdee 100644
--- a/drivers/gpio/pca953x.c
+++ b/drivers/gpio/pca953x.c
@@ -65,7 +65,10 @@ static int pca953x_ngpio(uint8_t chip)
return 8;
 }
 #else
-#define pca953x_ngpio(chip)8
+static int pca953x_ngpio(uint8_t chip)
+{
+   return 8;
+}
 #endif

 /*
-- 
1.7.3.2
___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


[U-Boot] [PATCHv3] pca953x: support 16-pin devices

2010-12-09 Thread Chris Packham
This adds support for for the PCA9535/PCA9539 family of gpio devices which
have 16 output pins.

To let the driver know which devices are 16-pin it is necessary to define
CONFIG_SYS_I2C_PCA953X_WIDTH in your board config file. This is used to
create an array of {chip, ngpio} tuples that are used to determine the
width of a particular chip. For backwards compatibility it is assumed that
any chip not defined in CONFIG_SYS_I2C_PCA953X_WIDTH has 8 pins.

Signed-off-by: Chris Packham chris.pack...@alliedtelesis.co.nz
---
Changes since v2:
- I've addressed Peters style comments.
- I've added a blurb to README describing the new config option

 README |4 ++
 drivers/gpio/pca953x.c |  111 ++--
 2 files changed, 92 insertions(+), 23 deletions(-)

diff --git a/README b/README
index 68f5fb0..831c5af 100644
--- a/README
+++ b/README
@@ -746,6 +746,10 @@ The following options need to be configured:
CONFIG_PCA953X  - use NXP's PCA953X series I2C GPIO
CONFIG_PCA953X_INFO - enable pca953x info command

+   The CONFIG_SYS_I2C_PCA953X_WIDTH option specifies a list of
+   chip-ngpio pairs that tell the PCA953X driver the number of
+   pins supported by a particular chip.
+
Note that if the GPIO device uses I2C, then the I2C interface
must also be configured. See I2C Support, below.

diff --git a/drivers/gpio/pca953x.c b/drivers/gpio/pca953x.c
index 6e82bd6..c8f5403 100644
--- a/drivers/gpio/pca953x.c
+++ b/drivers/gpio/pca953x.c
@@ -17,8 +17,8 @@
  */

 /*
- * Driver for NXP's 4 and 8 bit I2C gpio expanders (eg pca9537, pca9557, etc)
- * TODO: support additional devices with more than 8-bits GPIO
+ * Driver for NXP's 4, 8 and 16 bit I2C gpio expanders (eg pca9537, pca9557,
+ * pca9539, etc)
  */

 #include common.h
@@ -38,20 +38,78 @@ enum {
PCA953X_CMD_INVERT,
 };

+#ifdef CONFIG_SYS_I2C_PCA953X_WIDTH
+struct pca953x_chip_ngpio {
+   uint8_t chip;
+   uint8_t ngpio;
+};
+
+static struct pca953x_chip_ngpio pca953x_chip_ngpios[] =
+CONFIG_SYS_I2C_PCA953X_WIDTH;
+
+#define NUM_CHIP_GPIOS (sizeof(pca953x_chip_ngpios) / \
+   sizeof(struct pca953x_chip_ngpio))
+
+/*
+ * Determine the number of GPIO pins supported. If we don't know we assume
+ * 8 pins.
+ */
+static int pca953x_ngpio(uint8_t chip)
+{
+   int i;
+
+   for (i = 0; i  NUM_CHIP_GPIOS; i++)
+   if (pca953x_chip_ngpios[i].chip == chip)
+   return pca953x_chip_ngpios[i].ngpio;
+
+   return 8;
+}
+#else
+#define pca953x_ngpio(chip)8
+#endif
+
 /*
  * Modify masked bits in register
  */
 static int pca953x_reg_write(uint8_t chip, uint addr, uint mask, uint data)
 {
-   uint8_t val;
+   uint8_t valb;
+   uint16_t valw;

-   if (i2c_read(chip, addr, 1, val, 1))
-   return -1;
+   if (pca953x_ngpio(chip) = 8) {
+   if (i2c_read(chip, addr, 1, valb, 1))
+   return -1;
+
+   valb = ~mask;
+   valb |= data;
+
+   return i2c_write(chip, addr, 1, valb, 1);
+   } else {
+   if (i2c_read(chip, addr  1, 1, (u8*)valw, 2))
+   return -1;
+
+   valw = ~mask;
+   valw |= data;
+
+   return i2c_write(chip, addr  1, 1, (u8*)valw, 2);
+   }
+}

-   val = ~mask;
-   val |= data;
+static int pca953x_reg_read(uint8_t chip, uint addr, uint *data)
+{
+   uint8_t valb;
+   uint16_t valw;

-   return i2c_write(chip, addr, 1, val, 1);
+   if (pca953x_ngpio(chip) = 8) {
+   if (i2c_read(chip, addr, 1, valb, 1))
+   return -1;
+   *data = (int)valb;
+   } else {
+   if (i2c_read(chip, addr  1, 1, (u8*)valw, 2))
+   return -1;
+   *data = (int)valw;
+   }
+   return 0;
 }

 /*
@@ -86,9 +144,9 @@ int pca953x_set_dir(uint8_t chip, uint mask, uint data)
  */
 int pca953x_get_val(uint8_t chip)
 {
-   uint8_t val;
+   uint val;

-   if (i2c_read(chip, 0, 1, val, 1))
+   if (pca953x_reg_read(chip, PCA953X_IN, val)  0)
return -1;

return (int)val;
@@ -102,37 +160,44 @@ int pca953x_get_val(uint8_t chip)
 static int pca953x_info(uint8_t chip)
 {
int i;
-   uint8_t data;
+   uint data;
+   int nr_gpio = pca953x_ngpio(chip);
+   int msb = nr_gpio - 1;

-   printf(pca953x@ 0x%x:\n\n, chip);
-   printf(gpio pins: 76543210\n);
-   printf(---\n);
+   printf(pca953x@ 0x%x (%d pins):\n\n, chip, nr_gpio);
+   printf(gpio pins: );
+   for (i = msb; i = 0; i--)
+   printf(%x, i);
+   printf(\n);
+   for (i = 11 + nr_gpio; i  0; i--)
+   printf(-);
+   printf(\n);

-   if (i2c_read(chip, PCA953X_CONF, 1, data, 1))
+   if 

Re: [U-Boot] [PATCHv3] pca953x: support 16-pin devices

2010-12-09 Thread Peter Tyser
On Thu, 2010-12-09 at 22:11 +1300, Chris Packham wrote:
 This adds support for for the PCA9535/PCA9539 family of gpio devices which
 have 16 output pins.
 
 To let the driver know which devices are 16-pin it is necessary to define
 CONFIG_SYS_I2C_PCA953X_WIDTH in your board config file. This is used to
 create an array of {chip, ngpio} tuples that are used to determine the
 width of a particular chip. For backwards compatibility it is assumed that
 any chip not defined in CONFIG_SYS_I2C_PCA953X_WIDTH has 8 pins.
 
 Signed-off-by: Chris Packham chris.pack...@alliedtelesis.co.nz

Looks good to me and works as advertised.

Acked-by: Peter Tyser pty...@xes-inc.com
Tested-by: Peter Tyser pty...@xes-inc.com

___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot