LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
From: Anton Vorontsov <avorontsov@ru.mvista.com>
To: linux-kernel@vger.kernel.org
Cc: David Brownell <dbrownell@users.sourceforge.net>,
"Steven A. Falco" <sfalco@harris.com>,
Grant Likely <grant.likely@secretlab.ca>,
Jean Delvare <khali@linux-fr.org>,
David Miller <davem@davemloft.net>,
i2c@lm-sensors.org, linuxppc-dev@ozlabs.org
Subject: [PATCH 5/7] of/gpio: implement of_dev_gpiochip_{add,remove} calls
Date: Thu, 16 Oct 2008 21:13:03 +0400 [thread overview]
Message-ID: <20081016171303.GE5515@oksana.dev.rtsoft.ru> (raw)
In-Reply-To: <20081016171222.GA24812@oksana.dev.rtsoft.ru>
And let the gpiolib forward all dev_gpiochip_ calls to of_ versions, there
we can glue the gpiochips with the device tree.
Signed-off-by: Anton Vorontsov <avorontsov@ru.mvista.com>
---
arch/powerpc/include/asm/gpio.h | 7 +++-
drivers/of/gpio.c | 75 +++++++++++++++++++++++++++++++++++++-
include/linux/of_gpio.h | 7 ++++
3 files changed, 86 insertions(+), 3 deletions(-)
diff --git a/arch/powerpc/include/asm/gpio.h b/arch/powerpc/include/asm/gpio.h
index ea04632..92610b1 100644
--- a/arch/powerpc/include/asm/gpio.h
+++ b/arch/powerpc/include/asm/gpio.h
@@ -14,8 +14,13 @@
#ifndef __ASM_POWERPC_GPIO_H
#define __ASM_POWERPC_GPIO_H
-#include <linux/errno.h>
+/* Tell the gpiolib that we'll handle the dev_gpiochip_* calls. */
+#define __dev_gpiochip_add of_dev_gpiochip_add
+#define __dev_gpiochip_remove of_dev_gpiochip_remove
+
#include <asm-generic/gpio.h>
+#include <linux/errno.h>
+#include <linux/of_gpio.h>
#ifdef CONFIG_GPIOLIB
diff --git a/drivers/of/gpio.c b/drivers/of/gpio.c
index 7cd7301..b6f56af 100644
--- a/drivers/of/gpio.c
+++ b/drivers/of/gpio.c
@@ -12,12 +12,33 @@
*/
#include <linux/kernel.h>
+#include <linux/device.h>
#include <linux/errno.h>
#include <linux/io.h>
#include <linux/of.h>
#include <linux/of_gpio.h>
#include <asm/prom.h>
+static struct gpio_chip *of_gc_to_gc(struct of_gpio_chip *of_gc)
+{
+ /*
+ * Currently there are two ways to register OF GPIO controllers:
+ *
+ * 1. Allocating the of_gpio_chip structure and passing the
+ * &of_gc->gc pointer to the gpiochip_add. (Can use container_of
+ * to convert the gpio_chip to the of_gpio_chip.)
+ *
+ * 2. Allocating and registering the gpio_chip structure separately
+ * from the of_gpio_chip. (Since two allocations are separate,
+ * container_of won't work.)
+ *
+ * As time goes by we may kill the first option.
+ */
+ if (of_gc->chip)
+ return of_gc->chip;
+ return &of_gc->gc;
+}
+
/**
* of_get_gpio - Get a GPIO number from the device tree to use with GPIO API
* @np: device node to get GPIO from
@@ -63,7 +84,7 @@ int of_get_gpio(struct device_node *np, int index)
if (ret < 0)
goto err1;
- ret += of_gc->gc.base;
+ ret += of_gc_to_gc(of_gc)->base;
err1:
of_node_put(gc);
err0:
@@ -87,7 +108,7 @@ int of_gpio_simple_xlate(struct of_gpio_chip *of_gc, struct device_node *np,
{
const u32 *gpio = gpio_spec;
- if (*gpio > of_gc->gc.ngpio)
+ if (*gpio > of_gc_to_gc(of_gc)->ngpio)
return -EINVAL;
return *gpio;
@@ -161,3 +182,53 @@ err0:
return ret;
}
EXPORT_SYMBOL(of_mm_gpiochip_add);
+
+int of_dev_gpiochip_add(struct device *dev, struct gpio_chip *chip)
+{
+ struct device_node *np = dev_archdata_get_node(&dev->archdata);
+ struct of_gpio_chip *of_gc;
+ int ret;
+
+ if (!np || np->data)
+ return -EINVAL;
+
+ of_gc = kzalloc(sizeof(*of_gc), GFP_KERNEL);
+ if (!of_gc)
+ return -ENOMEM;
+ /*
+ * NOTE: for simple cases we use the simple_xlate with 2 cells scheme.
+ * You can always overwrite it with an exceptions list that would
+ * match on of_device_is_compatible().
+ */
+ of_gc->gpio_cells = 2;
+ of_gc->xlate = of_gpio_simple_xlate;
+
+ chip->dev = dev;
+ of_gc->chip = chip;
+ np->data = of_gc;
+
+ ret = gpiochip_add(chip);
+ if (ret)
+ goto err_gpiochip_add;
+ return 0;
+
+err_gpiochip_add:
+ np->data = NULL;
+ chip->dev = NULL;
+ kfree(of_gc);
+ return ret;
+}
+EXPORT_SYMBOL(of_dev_gpiochip_add);
+
+int of_dev_gpiochip_remove(struct device *dev, struct gpio_chip *chip)
+{
+ struct device_node *np = dev_archdata_get_node(&dev->archdata);
+ int ret;
+
+ ret = gpiochip_remove(chip);
+ if (ret)
+ return ret;
+ np->data = NULL;
+ return 0;
+}
+EXPORT_SYMBOL(of_dev_gpiochip_remove);
diff --git a/include/linux/of_gpio.h b/include/linux/of_gpio.h
index 67db101..273cd79 100644
--- a/include/linux/of_gpio.h
+++ b/include/linux/of_gpio.h
@@ -14,16 +14,21 @@
#ifndef __LINUX_OF_GPIO_H
#define __LINUX_OF_GPIO_H
+#include <linux/compiler.h>
#include <linux/errno.h>
#include <linux/gpio.h>
#ifdef CONFIG_OF_GPIO
+struct device_node;
+struct device;
+
/*
* Generic OF GPIO chip
*/
struct of_gpio_chip {
struct gpio_chip gc;
+ struct gpio_chip *chip;
int gpio_cells;
int (*xlate)(struct of_gpio_chip *of_gc, struct device_node *np,
const void *gpio_spec);
@@ -53,6 +58,8 @@ static inline struct of_mm_gpio_chip *to_of_mm_gpio_chip(struct gpio_chip *gc)
extern int of_get_gpio(struct device_node *np, int index);
extern int of_mm_gpiochip_add(struct device_node *np,
struct of_mm_gpio_chip *mm_gc);
+extern int of_dev_gpiochip_add(struct device *dev, struct gpio_chip *chip);
+extern int of_dev_gpiochip_remove(struct device *dev, struct gpio_chip *chip);
extern int of_gpio_simple_xlate(struct of_gpio_chip *of_gc,
struct device_node *np,
const void *gpio_spec);
--
1.5.6.3
next prev parent reply other threads:[~2008-10-16 17:14 UTC|newest]
Thread overview: 52+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-10-16 17:12 [PATCH 0/7 RFC] Handle I2C GPIO controllers with the OF (was: pca9539 I2C gpio expander) Anton Vorontsov
2008-10-16 17:12 ` [PATCH 1/7] powerpc and sparc: introduce dev_archdata node accessors Anton Vorontsov
2008-10-16 22:36 ` David Miller
2008-10-16 23:02 ` Grant Likely
2008-10-16 17:12 ` [PATCH 2/7] i2c: add info->archdata field Anton Vorontsov
2008-10-17 9:21 ` Jean Delvare
2008-10-22 0:27 ` Benjamin Herrenschmidt
2008-10-22 6:50 ` Jean Delvare
2008-10-22 7:37 ` Benjamin Herrenschmidt
2008-10-22 10:08 ` Anton Vorontsov
2008-10-22 11:07 ` Jean Delvare
2008-10-22 12:50 ` Anton Vorontsov
2008-10-16 17:12 ` [PATCH 3/7] of: fill the archdata for I2C devices Anton Vorontsov
2008-10-22 4:14 ` Grant Likely
2008-10-16 17:12 ` [PATCH 4/7] gpiolib: implement dev_gpiochip_{add,remove} calls Anton Vorontsov
2008-10-17 20:24 ` David Brownell
2008-10-17 21:29 ` Anton Vorontsov
2008-10-20 7:29 ` David Brownell
2008-10-20 15:48 ` Anton Vorontsov
2008-10-22 0:29 ` Benjamin Herrenschmidt
2008-10-22 1:03 ` Anton Vorontsov
2008-10-22 1:42 ` Anton Vorontsov
2008-10-22 2:28 ` Benjamin Herrenschmidt
2008-10-22 4:20 ` Grant Likely
2008-10-22 4:22 ` David Brownell
2008-10-22 10:36 ` Anton Vorontsov
2008-10-22 10:46 ` Anton Vorontsov
2008-10-22 18:32 ` Anton Vorontsov
2008-10-22 21:04 ` David Brownell
2008-10-22 21:22 ` Anton Vorontsov
2008-10-22 21:52 ` David Brownell
2008-10-22 22:29 ` Anton Vorontsov
2008-10-23 5:19 ` David Brownell
2008-10-23 4:45 ` Benjamin Herrenschmidt
2008-10-23 6:06 ` David Brownell
2008-10-23 6:15 ` David Brownell
2008-10-28 17:45 ` [PATCH 0/6 RFC] OF-glue devices for I2C/SPI (was: " Anton Vorontsov
2008-10-28 17:46 ` [PATCH 1/6] of/base: Add new helper of_should_create_pdev() Anton Vorontsov
2008-10-28 17:46 ` [PATCH 2/6] of/of_i2c: implement of_{,un}register_i2c_device Anton Vorontsov
2008-10-28 17:46 ` [PATCH 3/6] of/of_i2c: add support for dedicated OF I2C devices Anton Vorontsov
2008-10-28 18:41 ` David Miller
2008-10-28 17:46 ` [PATCH 4/6] of/gpio: add support for two-stage registration for the of_gpio_chips Anton Vorontsov
2008-10-28 17:46 ` [PATCH 5/6] gpio/pca953x: pass gpio_chip pointer to the setup/teardown callbacks Anton Vorontsov
2008-10-28 17:46 ` [PATCH 6/6] gpio: OpenFirmware bindings for the pca953x Anton Vorontsov
2008-10-28 17:53 ` [PATCH 0/6 RFC] OF-glue devices for I2C/SPI (was: Re: [PATCH 4/7] gpiolib: implement dev_gpiochip_{add,remove} calls Grant Likely
2008-10-22 2:27 ` Benjamin Herrenschmidt
2008-10-16 17:13 ` Anton Vorontsov [this message]
2008-10-17 20:25 ` [PATCH 5/7] of/gpio: implement of_dev_gpiochip_{add,remove} calls David Brownell
2008-10-17 21:13 ` Anton Vorontsov
2008-10-16 17:13 ` [PATCH 6/7] gpio/pca953x: convert to dev_gpiochip_add and make it work with the OF Anton Vorontsov
2008-10-16 17:13 ` [PATCH 7/7] i2c/mcu_mpc8349emitx: convert to the new I2C/OF/GPIO infrastructure Anton Vorontsov
2008-10-17 16:07 ` [PATCH 0/7 RFC] Handle I2C GPIO controllers with the OF (was: pca9539 I2C gpio expander) Steven A. Falco
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20081016171303.GE5515@oksana.dev.rtsoft.ru \
--to=avorontsov@ru.mvista.com \
--cc=davem@davemloft.net \
--cc=dbrownell@users.sourceforge.net \
--cc=grant.likely@secretlab.ca \
--cc=i2c@lm-sensors.org \
--cc=khali@linux-fr.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linuxppc-dev@ozlabs.org \
--cc=sfalco@harris.com \
--subject='Re: [PATCH 5/7] of/gpio: implement of_dev_gpiochip_{add,remove} calls' \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).