* [PATCH next 0/2] gpio: pca953x updates
@ 2009-06-08 22:51 Nate Case
2009-06-08 22:51 ` [PATCH next 1/2] gpio: pca953x: Get platform_data from OpenFirmware Nate Case
0 siblings, 1 reply; 4+ messages in thread
From: Nate Case @ 2009-06-08 22:51 UTC (permalink / raw)
To: David Brownell; +Cc: linux-kernel
The following changes were needed to support PCA95xx GPIO on our PowerPC
boards. We use both the PCA9557 and the PCA9556 (on older boards).
This should probably be for -next.
---
Nate Case (2):
gpio: pca953x: Add support for PCA9556
gpio: pca953x: Get platform_data from OpenFirmware
drivers/gpio/pca953x.c | 80 +++++++++++++++++++++++++++++++++++++--
1 files changed, 75 insertions(+), 5 deletions(-)
--
Nate Case <ncase@xes-inc.com>
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH next 1/2] gpio: pca953x: Get platform_data from OpenFirmware
2009-06-08 22:51 [PATCH next 0/2] gpio: pca953x updates Nate Case
@ 2009-06-08 22:51 ` Nate Case
2009-06-08 22:51 ` [PATCH next 2/2] gpio: pca953x: Add support for PCA9556 Nate Case
2009-06-10 23:40 ` [PATCH next 1/2] gpio: pca953x: Get platform_data from OpenFirmware Nate Case
0 siblings, 2 replies; 4+ messages in thread
From: Nate Case @ 2009-06-08 22:51 UTC (permalink / raw)
To: David Brownell; +Cc: linux-kernel, Nate Case
On OpenFirmware platforms, it makes the most sense to get platform_data
from the device tree. Make an attempt to translate OF node properties
into platform_data struct before bailing out.
Note that the implementation approach taken differs from other device
drivers that make use of device tree information. This is because I2C
chips are already registered automatically by of_i2c, so we can get by
with a small translator function in the driver.
Signed-off-by: Nate Case <ncase@xes-inc.com>
---
drivers/gpio/pca953x.c | 79 ++++++++++++++++++++++++++++++++++++++++++++---
1 files changed, 74 insertions(+), 5 deletions(-)
diff --git a/drivers/gpio/pca953x.c b/drivers/gpio/pca953x.c
index 8dc0164..258246e 100644
--- a/drivers/gpio/pca953x.c
+++ b/drivers/gpio/pca953x.c
@@ -15,6 +15,10 @@
#include <linux/init.h>
#include <linux/i2c.h>
#include <linux/i2c/pca953x.h>
+#ifdef CONFIG_OF_GPIO
+#include <linux/of_platform.h>
+#include <linux/of_gpio.h>
+#endif
#include <asm/gpio.h>
@@ -49,6 +53,7 @@ struct pca953x_chip {
uint16_t reg_direction;
struct i2c_client *client;
+ struct pca953x_platform_data *dyn_pdata;
struct gpio_chip gpio_chip;
};
@@ -194,6 +199,55 @@ static void pca953x_setup_gpio(struct pca953x_chip *chip, int gpios)
gc->owner = THIS_MODULE;
}
+/*
+ * Handlers for alternative sources of platform_data
+ */
+#ifdef CONFIG_OF_GPIO
+/*
+ * Translate OpenFirmware node properties into platform_data
+ */
+static struct pca953x_platform_data *
+pca953x_get_alt_pdata(struct i2c_client *client)
+{
+ struct pca953x_platform_data *pdata;
+ struct device_node *node;
+ const uint16_t *val;
+
+ node = dev_archdata_get_node(&client->dev.archdata);
+ if (node == NULL)
+ return NULL;
+
+ pdata = kzalloc(sizeof(struct pca953x_platform_data), GFP_KERNEL);
+ if (pdata == NULL) {
+ dev_err(&client->dev, "Unable to allocate platform_data\n");
+ return NULL;
+ }
+
+ pdata->gpio_base = -1;
+ val = of_get_property(node, "linux,gpio-base", NULL);
+ if (val) {
+ if (*val < 0)
+ dev_warn(&client->dev,
+ "invalid gpio-base in device tree\n");
+ else
+ pdata->gpio_base = *val;
+ }
+
+ val = of_get_property(node, "polarity", NULL);
+ if (val) {
+ pdata->invert = *val;
+ }
+
+ return pdata;
+}
+#else
+static struct pca953x_platform_data *
+pca953x_get_alt_pdata(struct i2c_client *client)
+{
+ return NULL;
+}
+#endif
+
static int __devinit pca953x_probe(struct i2c_client *client,
const struct i2c_device_id *id)
{
@@ -201,15 +255,25 @@ static int __devinit pca953x_probe(struct i2c_client *client,
struct pca953x_chip *chip;
int ret;
+ chip = kzalloc(sizeof(struct pca953x_chip), GFP_KERNEL);
+ if (chip == NULL)
+ return -ENOMEM;
+
pdata = client->dev.platform_data;
if (pdata == NULL) {
- dev_dbg(&client->dev, "no platform data\n");
- return -EINVAL;
+ pdata = pca953x_get_alt_pdata(client);
+ /*
+ * Unlike normal platform_data, this is allocated
+ * dynamically and must be freed in the driver
+ */
+ chip->dyn_pdata = pdata;
}
- chip = kzalloc(sizeof(struct pca953x_chip), GFP_KERNEL);
- if (chip == NULL)
- return -ENOMEM;
+ if (pdata == NULL) {
+ dev_dbg(&client->dev, "no platform data\n");
+ ret = -EINVAL;
+ goto out_failed;
+ }
chip->client = client;
@@ -249,6 +313,8 @@ static int __devinit pca953x_probe(struct i2c_client *client,
return 0;
out_failed:
+ if (chip->dyn_pdata != NULL)
+ kfree(chip->dyn_pdata);
kfree(chip);
return ret;
}
@@ -276,6 +342,9 @@ static int pca953x_remove(struct i2c_client *client)
return ret;
}
+ if (chip->dyn_pdata != NULL)
+ kfree(chip->dyn_pdata);
+
kfree(chip);
return 0;
}
--
1.6.0.2
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH next 2/2] gpio: pca953x: Add support for PCA9556
2009-06-08 22:51 ` [PATCH next 1/2] gpio: pca953x: Get platform_data from OpenFirmware Nate Case
@ 2009-06-08 22:51 ` Nate Case
2009-06-10 23:40 ` [PATCH next 1/2] gpio: pca953x: Get platform_data from OpenFirmware Nate Case
1 sibling, 0 replies; 4+ messages in thread
From: Nate Case @ 2009-06-08 22:51 UTC (permalink / raw)
To: David Brownell; +Cc: linux-kernel, Nate Case
PCA9556 is the software-compatible predecessor to the PCA9557, so add
it to the supported I2C device ID table.
Signed-off-by: Nate Case <ncase@xes-inc.com>
---
drivers/gpio/pca953x.c | 1 +
1 files changed, 1 insertions(+), 0 deletions(-)
diff --git a/drivers/gpio/pca953x.c b/drivers/gpio/pca953x.c
index 258246e..bbd08a9 100644
--- a/drivers/gpio/pca953x.c
+++ b/drivers/gpio/pca953x.c
@@ -36,6 +36,7 @@ static const struct i2c_device_id pca953x_id[] = {
{ "pca9539", 16, },
{ "pca9554", 8, },
{ "pca9555", 16, },
+ { "pca9556", 8, },
{ "pca9557", 8, },
{ "max7310", 8, },
--
1.6.0.2
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH next 1/2] gpio: pca953x: Get platform_data from OpenFirmware
2009-06-08 22:51 ` [PATCH next 1/2] gpio: pca953x: Get platform_data from OpenFirmware Nate Case
2009-06-08 22:51 ` [PATCH next 2/2] gpio: pca953x: Add support for PCA9556 Nate Case
@ 2009-06-10 23:40 ` Nate Case
1 sibling, 0 replies; 4+ messages in thread
From: Nate Case @ 2009-06-10 23:40 UTC (permalink / raw)
To: linux-kernel
On Mon, 2009-06-08 at 17:51 -0500, Nate Case wrote:
> On OpenFirmware platforms, it makes the most sense to get
> platform_data
> from the device tree. Make an attempt to translate OF node properties
> into platform_data struct before bailing out.
>
> Note that the implementation approach taken differs from other device
> drivers that make use of device tree information. This is because I2C
> chips are already registered automatically by of_i2c, so we can get by
> with a small translator function in the driver.
Hmm.. this patch doesn't show up in patchwork. Did it get missed
somehow?
--
Nate Case <ncase@xes-inc.com>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2009-06-10 23:40 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-06-08 22:51 [PATCH next 0/2] gpio: pca953x updates Nate Case
2009-06-08 22:51 ` [PATCH next 1/2] gpio: pca953x: Get platform_data from OpenFirmware Nate Case
2009-06-08 22:51 ` [PATCH next 2/2] gpio: pca953x: Add support for PCA9556 Nate Case
2009-06-10 23:40 ` [PATCH next 1/2] gpio: pca953x: Get platform_data from OpenFirmware Nate Case
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®