Skip to contentSkip to conversation

gpiolib: basic support for 16-bit PCA9539 GPIO expander

PATCH In review eric miao 2 participants 4 messages Dec 15, 2007 – Dec 17, 2007 GPIO

lore
Share & tools
lore

eric miao

author
#0 lore raw

PATCH 1/3 gpiolib: basic support for 16-bit PCA9539 GPIO expander

Quoted 1 line

From 5ebe07bbbb236b99587296cbf603a965d284ceaf Mon Sep 17 00:00:00 2001

From: eric miao <[email protected]>
Date: Mon, 10 Dec 2007 17:19:12 +0800
Subject: [PATCH] gpiolib: basic support for 16-bit PCA9539 GPIO expander

1. use 16-bit register access to simplify the logic, cache OUTPUT and DIRECTION registers for fast access

2. platform code is required to setup
a) the numbering of GPIO for PCA9539 (base and number)
c) pass "pca9539_platform_data" within "i2c_board_info"

Derived from drivers/i2c/chips/pca9539.c (which has no current known users).

---
 drivers/gpio/Kconfig        |   10 ++
 drivers/gpio/Makefile       |    1 +
 drivers/gpio/pca9539.c      |  247 +++++++++++++++++++++++++++++++++++++++++++
 include/linux/i2c/pca9539.h |   18 +++
 4 files changed, 276 insertions(+), 0 deletions(-)
 create mode 100644 drivers/gpio/pca9539.c
 create mode 100644 include/linux/i2c/pca9539.h
drivers/gpio/Kconfig +10 -0
index dd9e697..4b54f60 100644
@@ -9,6 +9,16 @@ menu "GPIO Expanders"
 
 comment "I2C GPIO expanders:"
 
+config GPIO_PCA9539
+	tristate "PCA9539 16-bit I/O port"
+	depends on I2C
+	help
+	  Say yes here to support the PCA9539 16-bit I/O port. These
+	  parts are made by NXP and TI.
+
+	  This driver can also be built as a module.  If so, the module
+	  will be called pca9539.
+
 config GPIO_PCF857X
 	tristate "PCF857x, PCA857x, and PCA967x I2C GPIO expanders"
 	depends on I2C
drivers/gpio/Makefile +1 -0
index 575bb57..d14fc1e 100644
@@ -1,4 +1,5 @@
 # gpio support: dedicated expander chips, etc
 
 obj-$(CONFIG_GPIO_MCP23S08)	+= mcp23s08.o
+obj-$(CONFIG_GPIO_PCA9539)	+= pca9539.o
 obj-$(CONFIG_GPIO_PCF857X)	+= pcf857x.o
drivers/gpio/pca9539.c new file +247 -0

247 lines not on this page · raw message

include/linux/i2c/pca9539.h new file +18 -0
new file mode 100644
index 0000000..611d84a
@@ -0,0 +1,18 @@
+/* platform data for the PCA9539 16-bit I/O expander driver */
+
+struct pca9539_platform_data {
+	/* number of the first GPIO */
+	unsigned	gpio_base;
+
+	/* initial polarity inversion setting */
+	uint16_t	invert;
+
+	void		*context;	/* param to setup/teardown */
+
+	int		(*setup)(struct i2c_client *client,
+				unsigned gpio, unsigned ngpio,
+				void *context);
+	int		(*teardown)(struct i2c_client *client,
+				unsigned gpio, unsigned ngpio,
+				void *context);
+};
Signature · 6 lines
1.5.2.5.GIT


-- 
Cheers
- eric
#1 lore raw

drivers/gpio/pca9539.c line 185

Quoted 10 lines
drivers/gpio/pca9539.c new file +10 -0
+	/* initialize cached registers from their original values */
+	pca9539_read_reg(chip, PCA9539_OUTPUT, &chip->reg_output);
+	pca9539_read_reg(chip, PCA9539_DIRECTION, &chip->reg_direction);
+
+	/* set platform specific polarity inversion */
+	pca9539_write_reg(chip, PCA9539_INVERT, pdata->invert);
+
+	ret = pca9539_init_gpio(chip);
+	if (ret)
+		goto out_failed;

I'm glad to see this patch no longer trashes previous chip state, but there's still an issue in that area. Surely the code should

	ret = pca9539_read_reg(...)
	if (ret)
		goto out_failed;

and likewise for the write? If the chip isn't present (and thus an I/O error is reported), its probe() should fail.

- Dave

author
#2 lore raw

[ Yup, it's an issue, patch updated as below:]

Quoted 1 line

From 8de0246423cbbd0c6bb03a20baf61d360930c350 Mon Sep 17 00:00:00 2001

From: eric miao <[email protected]>
Date: Mon, 10 Dec 2007 17:19:12 +0800
Subject: [PATCH] gpiolib: basic support for 16-bit PCA9539 GPIO expander

1. use 16-bit register access to simplify the logic, cache OUTPUT and DIRECTION registers for fast access

2. platform code is required to setup
a) the numbering of GPIO for PCA9539 (base and number)
c) pass "pca9539_platform_data" within "i2c_board_info"

Derived from drivers/i2c/chips/pca9539.c (which has no current known users).

---
 drivers/gpio/Kconfig        |   10 ++
 drivers/gpio/Makefile       |    1 +
 drivers/gpio/pca9539.c      |  254 +++++++++++++++++++++++++++++++++++++++++++
 include/linux/i2c/pca9539.h |   18 +++
 4 files changed, 283 insertions(+), 0 deletions(-)
 create mode 100644 drivers/gpio/pca9539.c
 create mode 100644 include/linux/i2c/pca9539.h
drivers/gpio/Kconfig +10 -0
index dd9e697..4b54f60 100644
@@ -9,6 +9,16 @@ menu "GPIO Expanders"
 
 comment "I2C GPIO expanders:"
 
+config GPIO_PCA9539
+	tristate "PCA9539 16-bit I/O port"
+	depends on I2C
+	help
+	  Say yes here to support the PCA9539 16-bit I/O port. These
+	  parts are made by NXP and TI.
+
+	  This driver can also be built as a module.  If so, the module
+	  will be called pca9539.
+
 config GPIO_PCF857X
 	tristate "PCF857x, PCA857x, and PCA967x I2C GPIO expanders"
 	depends on I2C
drivers/gpio/Makefile +1 -0
index 575bb57..d14fc1e 100644
@@ -1,4 +1,5 @@
 # gpio support: dedicated expander chips, etc
 
 obj-$(CONFIG_GPIO_MCP23S08)	+= mcp23s08.o
+obj-$(CONFIG_GPIO_PCA9539)	+= pca9539.o
 obj-$(CONFIG_GPIO_PCF857X)	+= pcf857x.o
drivers/gpio/pca9539.c new file +254 -0

254 lines not on this page · raw message

include/linux/i2c/pca9539.h new file +18 -0
new file mode 100644
index 0000000..611d84a
@@ -0,0 +1,18 @@
+/* platform data for the PCA9539 16-bit I/O expander driver */
+
+struct pca9539_platform_data {
+	/* number of the first GPIO */
+	unsigned	gpio_base;
+
+	/* initial polarity inversion setting */
+	uint16_t	invert;
+
+	void		*context;	/* param to setup/teardown */
+
+	int		(*setup)(struct i2c_client *client,
+				unsigned gpio, unsigned ngpio,
+				void *context);
+	int		(*teardown)(struct i2c_client *client,
+				unsigned gpio, unsigned ngpio,
+				void *context);
+};
Signature · 5 lines
1.5.2.5.GIT

---
Cheers
- eric
author
#3 lore raw

[ forget about the previous patch, sorry for my carelessness not to free the chip structure, below is the correct one ]

Quoted 1 line

From c4be69e8dad28dc75e80b393f9c60f740cca7047 Mon Sep 17 00:00:00 2001

From: eric miao <[email protected]>
Date: Mon, 10 Dec 2007 17:19:12 +0800
Subject: [PATCH] gpiolib: basic support for 16-bit PCA9539 GPIO expander

1. use 16-bit register access to simplify the logic, cache OUTPUT and DIRECTION registers for fast access

2. platform code is required to setup
a) the numbering of GPIO for PCA9539 (base and number)
c) pass "pca9539_platform_data" within "i2c_board_info"

Derived from drivers/i2c/chips/pca9539.c (which has no current known users).

---
 drivers/gpio/Kconfig        |   10 ++
 drivers/gpio/Makefile       |    1 +
 drivers/gpio/pca9539.c      |  260 +++++++++++++++++++++++++++++++++++++++++++
 include/linux/i2c/pca9539.h |   18 +++
 4 files changed, 289 insertions(+), 0 deletions(-)
 create mode 100644 drivers/gpio/pca9539.c
 create mode 100644 include/linux/i2c/pca9539.h
drivers/gpio/Kconfig +10 -0
index dd9e697..4b54f60 100644
@@ -9,6 +9,16 @@ menu "GPIO Expanders"
 
 comment "I2C GPIO expanders:"
 
+config GPIO_PCA9539
+	tristate "PCA9539 16-bit I/O port"
+	depends on I2C
+	help
+	  Say yes here to support the PCA9539 16-bit I/O port. These
+	  parts are made by NXP and TI.
+
+	  This driver can also be built as a module.  If so, the module
+	  will be called pca9539.
+
 config GPIO_PCF857X
 	tristate "PCF857x, PCA857x, and PCA967x I2C GPIO expanders"
 	depends on I2C
drivers/gpio/Makefile +1 -0
index 575bb57..d14fc1e 100644
@@ -1,4 +1,5 @@
 # gpio support: dedicated expander chips, etc
 
 obj-$(CONFIG_GPIO_MCP23S08)	+= mcp23s08.o
+obj-$(CONFIG_GPIO_PCA9539)	+= pca9539.o
 obj-$(CONFIG_GPIO_PCF857X)	+= pcf857x.o
drivers/gpio/pca9539.c new file +260 -0

260 lines not on this page · raw message

include/linux/i2c/pca9539.h new file +18 -0
new file mode 100644
index 0000000..611d84a
@@ -0,0 +1,18 @@
+/* platform data for the PCA9539 16-bit I/O expander driver */
+
+struct pca9539_platform_data {
+	/* number of the first GPIO */
+	unsigned	gpio_base;
+
+	/* initial polarity inversion setting */
+	uint16_t	invert;
+
+	void		*context;	/* param to setup/teardown */
+
+	int		(*setup)(struct i2c_client *client,
+				unsigned gpio, unsigned ngpio,
+				void *context);
+	int		(*teardown)(struct i2c_client *client,
+				unsigned gpio, unsigned ngpio,
+				void *context);
+};
Signature · 5 lines
1.5.2.5.GIT

---
Cheers
- eric