brcm63xx: backport upstream generic gpio changes
Backport patches that add a data pointer to gpio_chip. Signed-off-by: Jonas Gorski <jonas.gorski@gmail.com>
This commit is contained in:
parent
5e4bb476c0
commit
f9b7bfa088
5 changed files with 2727 additions and 19 deletions
|
@ -0,0 +1,121 @@
|
||||||
|
From b08ea35a3296ee25c4cb53a977b752266dafa2c2 Mon Sep 17 00:00:00 2001
|
||||||
|
From: Linus Walleij <linus.walleij@linaro.org>
|
||||||
|
Date: Thu, 3 Dec 2015 15:14:13 +0100
|
||||||
|
Subject: [PATCH] gpio: add a data pointer to gpio_chip
|
||||||
|
|
||||||
|
This adds a void * pointer to gpio_chip so that driver can
|
||||||
|
assign and retrieve some states. This is done to get rid of
|
||||||
|
container_of() calls for gpio_chips embedded inside state
|
||||||
|
containers, so we can remove the need to have the gpio_chip
|
||||||
|
or later (planned) struct gpio_device be dynamically allocated
|
||||||
|
at registration time, so that its struct device can be properly
|
||||||
|
reference counted and not bound to its parent device (e.g.
|
||||||
|
a platform_device) but instead live on after unregistration
|
||||||
|
if it is opened by e.g. a char device or sysfs.
|
||||||
|
|
||||||
|
The data is added with the new function gpiochip_add_data()
|
||||||
|
and for compatibility we add static inline wrapper function
|
||||||
|
gpiochip_add() that will call gpiochip_add_data() with
|
||||||
|
NULL as argument. The latter will be removed once we have
|
||||||
|
exorcised gpiochip_add() from the kernel.
|
||||||
|
|
||||||
|
gpiochip_get_data() is added as a static inline accessor
|
||||||
|
for drivers to quickly get their data out.
|
||||||
|
|
||||||
|
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
|
||||||
|
---
|
||||||
|
drivers/gpio/gpiolib.c | 10 ++++++----
|
||||||
|
include/linux/gpio/driver.h | 14 +++++++++++++-
|
||||||
|
2 files changed, 19 insertions(+), 5 deletions(-)
|
||||||
|
|
||||||
|
--- a/drivers/gpio/gpiolib.c
|
||||||
|
+++ b/drivers/gpio/gpiolib.c
|
||||||
|
@@ -280,7 +280,7 @@ static int gpiochip_set_desc_names(struc
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
- * gpiochip_add() - register a gpio_chip
|
||||||
|
+ * gpiochip_add_data() - register a gpio_chip
|
||||||
|
* @chip: the chip to register, with chip->base initialized
|
||||||
|
* Context: potentially before irqs will work
|
||||||
|
*
|
||||||
|
@@ -288,7 +288,7 @@ static int gpiochip_set_desc_names(struc
|
||||||
|
* because the chip->base is invalid or already associated with a
|
||||||
|
* different chip. Otherwise it returns zero as a success code.
|
||||||
|
*
|
||||||
|
- * When gpiochip_add() is called very early during boot, so that GPIOs
|
||||||
|
+ * When gpiochip_add_data() is called very early during boot, so that GPIOs
|
||||||
|
* can be freely used, the chip->dev device must be registered before
|
||||||
|
* the gpio framework's arch_initcall(). Otherwise sysfs initialization
|
||||||
|
* for GPIOs will fail rudely.
|
||||||
|
@@ -296,7 +296,7 @@ static int gpiochip_set_desc_names(struc
|
||||||
|
* If chip->base is negative, this requests dynamic assignment of
|
||||||
|
* a range of valid GPIOs.
|
||||||
|
*/
|
||||||
|
-int gpiochip_add(struct gpio_chip *chip)
|
||||||
|
+int gpiochip_add_data(struct gpio_chip *chip, void *data)
|
||||||
|
{
|
||||||
|
unsigned long flags;
|
||||||
|
int status = 0;
|
||||||
|
@@ -308,6 +308,8 @@ int gpiochip_add(struct gpio_chip *chip)
|
||||||
|
if (!descs)
|
||||||
|
return -ENOMEM;
|
||||||
|
|
||||||
|
+ chip->data = data;
|
||||||
|
+
|
||||||
|
spin_lock_irqsave(&gpio_lock, flags);
|
||||||
|
|
||||||
|
if (base < 0) {
|
||||||
|
@@ -389,7 +391,7 @@ err_free_descs:
|
||||||
|
chip->label ? : "generic");
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
-EXPORT_SYMBOL_GPL(gpiochip_add);
|
||||||
|
+EXPORT_SYMBOL_GPL(gpiochip_add_data);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* gpiochip_remove() - unregister a gpio_chip
|
||||||
|
--- a/include/linux/gpio/driver.h
|
||||||
|
+++ b/include/linux/gpio/driver.h
|
||||||
|
@@ -23,6 +23,7 @@ struct seq_file;
|
||||||
|
* @dev: optional device providing the GPIOs
|
||||||
|
* @cdev: class device used by sysfs interface (may be NULL)
|
||||||
|
* @owner: helps prevent removal of modules exporting active GPIOs
|
||||||
|
+ * @data: per-instance data assigned by the driver
|
||||||
|
* @list: links gpio_chips together for traversal
|
||||||
|
* @request: optional hook for chip-specific activation, such as
|
||||||
|
* enabling module power and clock; may sleep
|
||||||
|
@@ -92,6 +93,7 @@ struct gpio_chip {
|
||||||
|
struct device *dev;
|
||||||
|
struct device *cdev;
|
||||||
|
struct module *owner;
|
||||||
|
+ void *data;
|
||||||
|
struct list_head list;
|
||||||
|
|
||||||
|
int (*request)(struct gpio_chip *chip,
|
||||||
|
@@ -166,7 +168,11 @@ extern const char *gpiochip_is_requested
|
||||||
|
unsigned offset);
|
||||||
|
|
||||||
|
/* add/remove chips */
|
||||||
|
-extern int gpiochip_add(struct gpio_chip *chip);
|
||||||
|
+extern int gpiochip_add_data(struct gpio_chip *chip, void *data);
|
||||||
|
+static inline int gpiochip_add(struct gpio_chip *chip)
|
||||||
|
+{
|
||||||
|
+ return gpiochip_add_data(chip, NULL);
|
||||||
|
+}
|
||||||
|
extern void gpiochip_remove(struct gpio_chip *chip);
|
||||||
|
extern struct gpio_chip *gpiochip_find(void *data,
|
||||||
|
int (*match)(struct gpio_chip *chip, void *data));
|
||||||
|
@@ -175,6 +181,12 @@ extern struct gpio_chip *gpiochip_find(v
|
||||||
|
int gpiochip_lock_as_irq(struct gpio_chip *chip, unsigned int offset);
|
||||||
|
void gpiochip_unlock_as_irq(struct gpio_chip *chip, unsigned int offset);
|
||||||
|
|
||||||
|
+/* get driver data */
|
||||||
|
+static inline void *gpiochip_get_data(struct gpio_chip *chip)
|
||||||
|
+{
|
||||||
|
+ return chip->data;
|
||||||
|
+}
|
||||||
|
+
|
||||||
|
struct gpio_chip *gpiod_to_chip(const struct gpio_desc *desc);
|
||||||
|
|
||||||
|
#ifdef CONFIG_GPIOLIB_IRQCHIP
|
File diff suppressed because it is too large
Load diff
|
@ -8,7 +8,7 @@ Signed-off-by: Jonas Gorski <jogo@openwrt.org>
|
||||||
---
|
---
|
||||||
drivers/gpio/Kconfig | 8 +++
|
drivers/gpio/Kconfig | 8 +++
|
||||||
drivers/gpio/Makefile | 1 +
|
drivers/gpio/Makefile | 1 +
|
||||||
drivers/gpio/gpio-bcm63xx.c | 122 +++++++++++++++++++++++++++++++++++++++++++
|
drivers/gpio/gpio-bcm63xx.c | 135 +++++++++++++++++++++++++++++++++++++++++++
|
||||||
3 files changed, 131 insertions(+)
|
3 files changed, 131 insertions(+)
|
||||||
create mode 100644 drivers/gpio/gpio-bcm63xx.c
|
create mode 100644 drivers/gpio/gpio-bcm63xx.c
|
||||||
|
|
||||||
|
@ -40,7 +40,7 @@ Signed-off-by: Jonas Gorski <jogo@openwrt.org>
|
||||||
obj-$(CONFIG_GPIO_CLPS711X) += gpio-clps711x.o
|
obj-$(CONFIG_GPIO_CLPS711X) += gpio-clps711x.o
|
||||||
--- /dev/null
|
--- /dev/null
|
||||||
+++ b/drivers/gpio/gpio-bcm63xx.c
|
+++ b/drivers/gpio/gpio-bcm63xx.c
|
||||||
@@ -0,0 +1,134 @@
|
@@ -0,0 +1,135 @@
|
||||||
+/*
|
+/*
|
||||||
+ * Driver for BCM63XX memory-mapped GPIO controllers, based on
|
+ * Driver for BCM63XX memory-mapped GPIO controllers, based on
|
||||||
+ * Generic driver for memory-mapped GPIO controllers.
|
+ * Generic driver for memory-mapped GPIO controllers.
|
||||||
|
@ -68,10 +68,10 @@ Signed-off-by: Jonas Gorski <jogo@openwrt.org>
|
||||||
+#include <linux/ioport.h>
|
+#include <linux/ioport.h>
|
||||||
+#include <linux/io.h>
|
+#include <linux/io.h>
|
||||||
+#include <linux/gpio.h>
|
+#include <linux/gpio.h>
|
||||||
|
+#include <linux/gpio/driver.h>
|
||||||
+#include <linux/slab.h>
|
+#include <linux/slab.h>
|
||||||
+#include <linux/platform_device.h>
|
+#include <linux/platform_device.h>
|
||||||
+#include <linux/mod_devicetable.h>
|
+#include <linux/mod_devicetable.h>
|
||||||
+#include <linux/basic_mmio_gpio.h>
|
|
||||||
+#include <linux/of.h>
|
+#include <linux/of.h>
|
||||||
+#include <linux/of_irq.h>
|
+#include <linux/of_irq.h>
|
||||||
+#include <linux/of_gpio.h>
|
+#include <linux/of_gpio.h>
|
||||||
|
@ -92,7 +92,7 @@ Signed-off-by: Jonas Gorski <jogo@openwrt.org>
|
||||||
+ void __iomem *dirout;
|
+ void __iomem *dirout;
|
||||||
+ unsigned long sz;
|
+ unsigned long sz;
|
||||||
+ int err;
|
+ int err;
|
||||||
+ struct bgpio_chip *bgc;
|
+ struct gpio_chip *gc;
|
||||||
+ struct bgpio_pdata *pdata = dev_get_platdata(dev);
|
+ struct bgpio_pdata *pdata = dev_get_platdata(dev);
|
||||||
+
|
+
|
||||||
+ dirout_r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
|
+ dirout_r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
|
||||||
|
@ -113,45 +113,46 @@ Signed-off-by: Jonas Gorski <jogo@openwrt.org>
|
||||||
+ if (IS_ERR(dirout))
|
+ if (IS_ERR(dirout))
|
||||||
+ return PTR_ERR(dirout);
|
+ return PTR_ERR(dirout);
|
||||||
+
|
+
|
||||||
+ bgc = devm_kzalloc(&pdev->dev, sizeof(*bgc), GFP_KERNEL);
|
+ gc = devm_kzalloc(&pdev->dev, sizeof(*gc), GFP_KERNEL);
|
||||||
+ if (!bgc)
|
+ if (!gc)
|
||||||
+ return -ENOMEM;
|
+ return -ENOMEM;
|
||||||
+
|
+
|
||||||
+ err = bgpio_init(bgc, dev, sz, dat, NULL, NULL, dirout, NULL,
|
+ err = bgpio_init(gc, dev, sz, dat, NULL, NULL, dirout, NULL,
|
||||||
+ BGPIOF_BIG_ENDIAN_BYTE_ORDER);
|
+ BGPIOF_BIG_ENDIAN_BYTE_ORDER);
|
||||||
+ if (err)
|
+ if (err)
|
||||||
+ return err;
|
+ return err;
|
||||||
+
|
+
|
||||||
+ platform_set_drvdata(pdev, bgc);
|
+ platform_set_drvdata(pdev, gc);
|
||||||
+
|
+
|
||||||
+ if (dev->of_node) {
|
+ if (dev->of_node) {
|
||||||
+ int id = of_alias_get_id(dev->of_node, "gpio");
|
+ int id = of_alias_get_id(dev->of_node, "gpio");
|
||||||
+ u32 ngpios;
|
+ u32 ngpios;
|
||||||
+
|
+
|
||||||
+ if (id >= 0)
|
+ if (id >= 0)
|
||||||
+ bgc->gc.label = devm_kasprintf(dev, GFP_KERNEL,
|
+ gc->label = devm_kasprintf(dev, GFP_KERNEL,
|
||||||
+ "bcm63xx-gpio.%d", id);
|
+ "bcm63xx-gpio.%d", id);
|
||||||
+
|
+
|
||||||
+ if (!of_property_read_u32(dev->of_node, "ngpios", &ngpios))
|
+ if (!of_property_read_u32(dev->of_node, "ngpios", &ngpios))
|
||||||
+ bgc->gc.ngpio = ngpios;
|
+ gc->ngpio = ngpios;
|
||||||
+
|
+
|
||||||
+ if (of_get_property(dev->of_node, "interrupt-names", NULL))
|
+ if (of_get_property(dev->of_node, "interrupt-names", NULL))
|
||||||
+ bgc->gc.to_irq = bcm63xx_gpio_to_irq;
|
+ gc->to_irq = bcm63xx_gpio_to_irq;
|
||||||
+
|
+
|
||||||
+ } else if (pdata) {
|
+ } else if (pdata) {
|
||||||
+ bgc->gc.base = pdata->base;
|
+ gc->base = pdata->base;
|
||||||
+ if (pdata->ngpio > 0)
|
+ if (pdata->ngpio > 0)
|
||||||
+ bgc->gc.ngpio = pdata->ngpio;
|
+ gc->ngpio = pdata->ngpio;
|
||||||
+ }
|
+ }
|
||||||
+
|
+
|
||||||
+ return gpiochip_add(&bgc->gc);
|
+ return gpiochip_add(gc);
|
||||||
+}
|
+}
|
||||||
+
|
+
|
||||||
+static int bcm63xx_gpio_remove(struct platform_device *pdev)
|
+static int bcm63xx_gpio_remove(struct platform_device *pdev)
|
||||||
+{
|
+{
|
||||||
+ struct bgpio_chip *bgc = platform_get_drvdata(pdev);
|
+ struct gpio_chip *gc = platform_get_drvdata(pdev);
|
||||||
+
|
+
|
||||||
+ return bgpio_remove(bgc);
|
+ gpiochip_remove(gc);
|
||||||
|
+ return 0;
|
||||||
+}
|
+}
|
||||||
+
|
+
|
||||||
+#ifdef CONFIG_OF
|
+#ifdef CONFIG_OF
|
||||||
|
|
|
@ -34,7 +34,7 @@ Signed-off-by: Jonas Gorski <jogo@openwrt.org>
|
||||||
-#include <linux/module.h>
|
-#include <linux/module.h>
|
||||||
-#include <linux/spinlock.h>
|
-#include <linux/spinlock.h>
|
||||||
#include <linux/platform_device.h>
|
#include <linux/platform_device.h>
|
||||||
+#include <linux/basic_mmio_gpio.h>
|
+#include <linux/gpio/driver.h>
|
||||||
#include <linux/gpio.h>
|
#include <linux/gpio.h>
|
||||||
|
|
||||||
#include <bcm63xx_cpu.h>
|
#include <bcm63xx_cpu.h>
|
||||||
|
|
|
@ -50,7 +50,7 @@ Signed-off-by: Jonas Gorski <jogo@openwrt.org>
|
||||||
+
|
+
|
||||||
#include <linux/kernel.h>
|
#include <linux/kernel.h>
|
||||||
#include <linux/platform_device.h>
|
#include <linux/platform_device.h>
|
||||||
#include <linux/basic_mmio_gpio.h>
|
#include <linux/gpio/driver.h>
|
||||||
#include <linux/gpio.h>
|
#include <linux/gpio.h>
|
||||||
+#include <linux/gpio/machine.h>
|
+#include <linux/gpio/machine.h>
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue