Skip to content

Commit

Permalink
Merge tag 'gpio-v3.16-1' of git://git.kernel.org/pub/scm/linux/kernel…
Browse files Browse the repository at this point in the history
…/git/linusw/linux-gpio into next

Pull GPIO updates from Linus Walleij:
 "This is the bulk of GPIO changes for the v3.16 series.

  There is a lot of action in the GPIO subsystem doing refactorings and
  cleanups, almost as many deletions as insertions and minor feature
  growth and no new drivers this time.  Which is actually pretty nice.
  Some GPIO-related stuff will come in through the pin control tree as
  well.

  Details:

   - We are finalizing and fixing up the gpiochip irqchip helpers
     bringing a helpful irqchip implementation into the gpiolib core and
     avoiding duplicate code and, more importantly, duplicate bug fixes:

     * Support for using the helpers with threaded interrupt handlers as
       used on sleeping GPIO-irqchips

     * Do not set up hardware triggers for edges or levels if the
       default IRQ type is IRQ_TYPE_NONE - some drivers would exploit
       the fact that you could get default initialization of the IRQ
       type from the core at probe() but if no default type is set up
       from the helper, we should not call the driver to configure
       anything.  Wait until a consumer requests the interrupt instead.

     * Make the irqchip helpers put the GPIO irqs into their own lock
       class.  The GPIO irqchips can often emit (harmless, but annoying)
       lockdep warnings about recursions when they are in fact just
       cascaded IRQs.  By putting them into their own lock class we help
       the lockdep core to keep track of things.

     * Switch the tc3589x GPIO expanders to use the irqchip helpers

     * Switch the OMAP GPIO driver to use the irqchip helpers

     * Add some documentation for the irqchip helpers

     * select IRQ_DOMAIN when using the helpers since some platforms may
       not be using this by default and it's a strict dependency.

   - Continued GPIO descriptor refactoring:

     * Remove the one instance of gpio_to_desc() from the device tree
       code, making the OF GPIO code use GPIO descriptors only.

     * Introduce gpiod_get_optional() and gpiod_get_optional_index()
       akin to the similar regulator functions for cases where the use
       of GPIO is optional and not strictly required.

     * Make of_get_named_gpiod_flags() private - we do not want to
       unnecessarily expose APIs to drivers that make the gpiolib harder
       than necessary to maintain and refactor.  Privatize this
       function.

   - Support "-gpio" suffix for the OF GPIO retrieveal path.  We used to
     look for "foo-gpios" or just "gpios" in device tree nodes, but it
     turns out that some drivers with a single GPIO line will just state
     "foo-gpio" (singularis).  Sigh.  Support this with a fallback
     looking for it, as this simplifies driver code and handles it in
     core code.

   - Switch the ACPI GPIO core to fetch GPIOs with the *_cansleep
     function variants as the GPIO operation region handler can sleep,
     and shall be able to handle gpiochips that sleep.

   - Tons of cleanups and janitorial work from Jingoo Han, Axel Lin,
     Javier Martinez Canillas and Abdoulaye Berthe.  Notably Jingoo cut
     off a ton of pointless OOM messages.

   - Incremental development and fixes for various drivers, nothing
     really special here"

* tag 'gpio-v3.16-1' of git://git.kernel.org/pub/scm/linux/kernel/git/linusw/linux-gpio: (85 commits)
  gpio: select IRQ_DOMAIN for gpiolib irqchip helpers
  gpio: pca953x: use gpiolib irqchip helpers
  gpio: pcf857x: Add IRQF_SHARED when request irq
  gpio: pcf857x: Avoid calling irq_domain_cleanup twice
  gpio: mcp23s08: switch chip count to int
  gpio: dwapb: use a second irq chip
  gpio: ep93xx: Use devm_ioremap_resource()
  gpio: mcp23s08: fixed count variable for devicetree probing
  gpio: Add run-time dependencies to R-Car driver
  gpio: pch: add slab include
  Documentation / ACPI: Fix location of GPIO documentation
  gpio / ACPI: use *_cansleep version of gpiod_get/set APIs
  gpio: generic: add request function pointer
  gpio-pch: Fix Kconfig dependencies
  gpio: make of_get_named_gpiod_flags() private
  gpio: gpioep93xx: use devm functions
  gpio: janzttl: use devm function
  gpio: timberdale: use devm functions
  gpio: bt8xx: use devm function for memory allocation
  gpio: include linux/bug.h in interface header
  ...
  • Loading branch information
torvalds committed Jun 2, 2014
2 parents 9f888b3 + fc34627 commit 80fb974
Show file tree
Hide file tree
Showing 53 changed files with 704 additions and 685 deletions.
2 changes: 1 addition & 1 deletion Documentation/acpi/enumeration.txt
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ specifies the path to the controller. In order to use these GPIOs in Linux
we need to translate them to the corresponding Linux GPIO descriptors.

There is a standard GPIO API for that and is documented in
Documentation/gpio.txt.
Documentation/gpio/.

In the above example we can get the corresponding two GPIO descriptors with
a code like this:
Expand Down
6 changes: 6 additions & 0 deletions Documentation/devicetree/bindings/gpio/renesas,gpio-rcar.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ Required Properties:
GPIO_ACTIVE_HIGH and GPIO_ACTIVE_LOW flags are supported.
- gpio-ranges: Range of pins managed by the GPIO controller.

Optional properties:

- clocks: Must contain a reference to the functional clock. The property is
mandatory if the hardware implements a controllable functional clock for
the GPIO instance.

Please refer to gpio.txt in this directory for details of gpio-ranges property
and the common GPIO bindings used by client devices.

Expand Down
7 changes: 7 additions & 0 deletions Documentation/driver-model/devres.txt
Original file line number Diff line number Diff line change
Expand Up @@ -308,3 +308,10 @@ SLAVE DMA ENGINE

SPI
devm_spi_register_master()

GPIO
devm_gpiod_get()
devm_gpiod_get_index()
devm_gpiod_get_optional()
devm_gpiod_get_index_optional()
devm_gpiod_put()
59 changes: 59 additions & 0 deletions Documentation/gpio/driver.txt
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,65 @@ The IRQ portions of the GPIO block are implemented using an irqchip, using
the header <linux/irq.h>. So basically such a driver is utilizing two sub-
systems simultaneously: gpio and irq.

GPIO irqchips usually fall in one of two categories:

* CHAINED GPIO irqchips: these are usually the type that is embedded on
an SoC. This means that there is a fast IRQ handler for the GPIOs that
gets called in a chain from the parent IRQ handler, most typically the
system interrupt controller. This means the GPIO irqchip is registered
using irq_set_chained_handler() or the corresponding
gpiochip_set_chained_irqchip() helper function, and the GPIO irqchip
handler will be called immediately from the parent irqchip, while
holding the IRQs disabled. The GPIO irqchip will then end up calling
something like this sequence in its interrupt handler:

static irqreturn_t tc3589x_gpio_irq(int irq, void *data)
chained_irq_enter(...);
generic_handle_irq(...);
chained_irq_exit(...);

Chained GPIO irqchips typically can NOT set the .can_sleep flag on
struct gpio_chip, as everything happens directly in the callbacks.

* NESTED THREADED GPIO irqchips: these are off-chip GPIO expanders and any
other GPIO irqchip residing on the other side of a sleeping bus. Of course
such drivers that need slow bus traffic to read out IRQ status and similar,
traffic which may in turn incur other IRQs to happen, cannot be handled
in a quick IRQ handler with IRQs disabled. Instead they need to spawn a
thread and then mask the parent IRQ line until the interrupt is handled
by the driver. The hallmark of this driver is to call something like
this in its interrupt handler:

static irqreturn_t tc3589x_gpio_irq(int irq, void *data)
...
handle_nested_irq(irq);

The hallmark of threaded GPIO irqchips is that they set the .can_sleep
flag on struct gpio_chip to true, indicating that this chip may sleep
when accessing the GPIOs.

To help out in handling the set-up and management of GPIO irqchips and the
associated irqdomain and resource allocation callbacks, the gpiolib has
some helpers that can be enabled by selecting the GPIOLIB_IRQCHIP Kconfig
symbol:

* gpiochip_irqchip_add(): adds an irqchip to a gpiochip. It will pass
the struct gpio_chip* for the chip to all IRQ callbacks, so the callbacks
need to embed the gpio_chip in its state container and obtain a pointer
to the container using container_of().
(See Documentation/driver-model/design-patterns.txt)

* gpiochip_set_chained_irqchip(): sets up a chained irq handler for a
gpio_chip from a parent IRQ and passes the struct gpio_chip* as handler
data. (Notice handler data, since the irqchip data is likely used by the
parent irqchip!) This is for the chained type of chip.

To use the helpers please keep the following in mind:

- Make sure to assign all relevant members of the struct gpio_chip so that
the irqchip can initialize. E.g. .dev and .can_sleep shall be set up
properly.

It is legal for any IRQ consumer to request an IRQ from any irqchip no matter
if that is a combined GPIO+IRQ driver. The basic premise is that gpio_chip and
irq_chip are orthogonal, and offering their services independent of each
Expand Down
1 change: 1 addition & 0 deletions MAINTAINERS
Original file line number Diff line number Diff line change
Expand Up @@ -6418,6 +6418,7 @@ F: drivers/usb/*/*omap*
F: arch/arm/*omap*/usb*

OMAP GPIO DRIVER
M: Javier Martinez Canillas <javier@dowhile0.org>
M: Santosh Shilimkar <santosh.shilimkar@ti.com>
M: Kevin Hilman <khilman@deeprootsystems.com>
L: linux-omap@vger.kernel.org
Expand Down
20 changes: 16 additions & 4 deletions drivers/gpio/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ config GPIO_ACPI
depends on ACPI

config GPIOLIB_IRQCHIP
select IRQ_DOMAIN
bool

config DEBUG_GPIO
Expand Down Expand Up @@ -243,6 +244,15 @@ config GPIO_OCTEON
Say yes here to support the on-chip GPIO lines on the OCTEON
family of SOCs.

config GPIO_OMAP
bool "TI OMAP GPIO support" if COMPILE_TEST && !ARCH_OMAP2PLUS
default y if ARCH_OMAP
depends on ARM
select GENERIC_IRQ_CHIP
select GPIOLIB_IRQCHIP
help
Say yes here to enable GPIO support for TI OMAP SoCs.

config GPIO_PL061
bool "PrimeCell PL061 GPIO support"
depends on ARM_AMBA
Expand All @@ -259,7 +269,7 @@ config GPIO_PXA

config GPIO_RCAR
tristate "Renesas R-Car GPIO"
depends on ARM
depends on ARM && (ARCH_SHMOBILE || COMPILE_TEST)
help
Say yes here to support GPIO on Renesas R-Car SoCs.

Expand Down Expand Up @@ -510,6 +520,7 @@ config GPIO_PCA953X
config GPIO_PCA953X_IRQ
bool "Interrupt controller support for PCA953x"
depends on GPIO_PCA953X=y
select GPIOLIB_IRQCHIP
help
Say yes here to enable the pca953x to be used as an interrupt
controller. It requires the driver to be built in the kernel.
Expand Down Expand Up @@ -579,6 +590,7 @@ config GPIO_STP_XWAY
config GPIO_TC3589X
bool "TC3589X GPIOs"
depends on MFD_TC3589X
select GPIOLIB_IRQCHIP
help
This enables support for the GPIOs found on the TC3589X
I/O Expander.
Expand Down Expand Up @@ -699,13 +711,13 @@ config GPIO_AMD8111
config GPIO_INTEL_MID
bool "Intel Mid GPIO support"
depends on PCI && X86
select IRQ_DOMAIN
select GPIOLIB_IRQCHIP
help
Say Y here to support Intel Mid GPIO.

config GPIO_PCH
tristate "Intel EG20T PCH/LAPIS Semiconductor IOH(ML7223/ML7831) GPIO"
depends on PCI && X86
depends on PCI && (X86_32 || COMPILE_TEST)
select GENERIC_IRQ_CHIP
help
This driver is for PCH(Platform controller Hub) GPIO of Intel Topcliff
Expand Down Expand Up @@ -739,7 +751,7 @@ config GPIO_SODAVILLE

config GPIO_TIMBERDALE
bool "Support for timberdale GPIO IP"
depends on MFD_TIMBERDALE && HAS_IOMEM
depends on MFD_TIMBERDALE
---help---
Add support for the GPIO IP in the timberdale FPGA.

Expand Down
2 changes: 1 addition & 1 deletion drivers/gpio/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ obj-$(CONFIG_GPIO_MVEBU) += gpio-mvebu.o
obj-$(CONFIG_GPIO_MXC) += gpio-mxc.o
obj-$(CONFIG_GPIO_MXS) += gpio-mxs.o
obj-$(CONFIG_GPIO_OCTEON) += gpio-octeon.o
obj-$(CONFIG_ARCH_OMAP) += gpio-omap.o
obj-$(CONFIG_GPIO_OMAP) += gpio-omap.o
obj-$(CONFIG_GPIO_PCA953X) += gpio-pca953x.o
obj-$(CONFIG_GPIO_PCF857X) += gpio-pcf857x.o
obj-$(CONFIG_GPIO_PCH) += gpio-pch.o
Expand Down
43 changes: 43 additions & 0 deletions drivers/gpio/devres.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,22 @@ struct gpio_desc *__must_check devm_gpiod_get(struct device *dev,
}
EXPORT_SYMBOL(devm_gpiod_get);

/**
* devm_gpiod_get_optional - Resource-managed gpiod_get_optional()
* @dev: GPIO consumer
* @con_id: function within the GPIO consumer
*
* Managed gpiod_get_optional(). GPIO descriptors returned from this function
* are automatically disposed on driver detach. See gpiod_get_optional() for
* detailed information about behavior and return values.
*/
struct gpio_desc *__must_check devm_gpiod_get_optional(struct device *dev,
const char *con_id)
{
return devm_gpiod_get_index_optional(dev, con_id, 0);
}
EXPORT_SYMBOL(devm_gpiod_get_optional);

/**
* devm_gpiod_get_index - Resource-managed gpiod_get_index()
* @dev: GPIO consumer
Expand Down Expand Up @@ -86,6 +102,33 @@ struct gpio_desc *__must_check devm_gpiod_get_index(struct device *dev,
}
EXPORT_SYMBOL(devm_gpiod_get_index);

/**
* devm_gpiod_get_index_optional - Resource-managed gpiod_get_index_optional()
* @dev: GPIO consumer
* @con_id: function within the GPIO consumer
* @index: index of the GPIO to obtain in the consumer
*
* Managed gpiod_get_index_optional(). GPIO descriptors returned from this
* function are automatically disposed on driver detach. See
* gpiod_get_index_optional() for detailed information about behavior and
* return values.
*/
struct gpio_desc *__must_check devm_gpiod_get_index_optional(struct device *dev,
const char *con_id,
unsigned int index)
{
struct gpio_desc *desc;

desc = devm_gpiod_get_index(dev, con_id, index);
if (IS_ERR(desc)) {
if (PTR_ERR(desc) == -ENOENT)
return NULL;
}

return desc;
}
EXPORT_SYMBOL(devm_gpiod_get_index_optional);

/**
* devm_gpiod_put - Resource-managed gpiod_put()
* @desc: GPIO descriptor to dispose of
Expand Down
4 changes: 1 addition & 3 deletions drivers/gpio/gpio-adp5520.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,8 @@ static int adp5520_gpio_probe(struct platform_device *pdev)
}

dev = devm_kzalloc(&pdev->dev, sizeof(*dev), GFP_KERNEL);
if (dev == NULL) {
dev_err(&pdev->dev, "failed to alloc memory\n");
if (dev == NULL)
return -ENOMEM;
}

dev->master = pdev->dev.parent;

Expand Down
4 changes: 1 addition & 3 deletions drivers/gpio/gpio-adp5588.c
Original file line number Diff line number Diff line change
Expand Up @@ -379,10 +379,8 @@ static int adp5588_gpio_probe(struct i2c_client *client,
}

dev = kzalloc(sizeof(*dev), GFP_KERNEL);
if (dev == NULL) {
dev_err(&client->dev, "failed to alloc memory\n");
if (dev == NULL)
return -ENOMEM;
}

dev->client = client;

Expand Down
19 changes: 6 additions & 13 deletions drivers/gpio/gpio-bt8xx.c
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ static int bt8xxgpio_probe(struct pci_dev *dev,
struct bt8xxgpio *bg;
int err;

bg = kzalloc(sizeof(*bg), GFP_KERNEL);
bg = devm_kzalloc(&dev->dev, sizeof(struct bt8xxgpio), GFP_KERNEL);
if (!bg)
return -ENOMEM;

Expand All @@ -188,9 +188,9 @@ static int bt8xxgpio_probe(struct pci_dev *dev,
err = pci_enable_device(dev);
if (err) {
printk(KERN_ERR "bt8xxgpio: Can't enable device.\n");
goto err_freebg;
return err;
}
if (!request_mem_region(pci_resource_start(dev, 0),
if (!devm_request_mem_region(&dev->dev, pci_resource_start(dev, 0),
pci_resource_len(dev, 0),
"bt8xxgpio")) {
printk(KERN_WARNING "bt8xxgpio: Can't request iomem (0x%llx).\n",
Expand All @@ -201,11 +201,11 @@ static int bt8xxgpio_probe(struct pci_dev *dev,
pci_set_master(dev);
pci_set_drvdata(dev, bg);

bg->mmio = ioremap(pci_resource_start(dev, 0), 0x1000);
bg->mmio = devm_ioremap(&dev->dev, pci_resource_start(dev, 0), 0x1000);
if (!bg->mmio) {
printk(KERN_ERR "bt8xxgpio: ioremap() failed\n");
err = -EIO;
goto err_release_mem;
goto err_disable;
}

/* Disable interrupts */
Expand All @@ -220,18 +220,13 @@ static int bt8xxgpio_probe(struct pci_dev *dev,
err = gpiochip_add(&bg->gpio);
if (err) {
printk(KERN_ERR "bt8xxgpio: Failed to register GPIOs\n");
goto err_release_mem;
goto err_disable;
}

return 0;

err_release_mem:
release_mem_region(pci_resource_start(dev, 0),
pci_resource_len(dev, 0));
err_disable:
pci_disable_device(dev);
err_freebg:
kfree(bg);

return err;
}
Expand All @@ -250,8 +245,6 @@ static void bt8xxgpio_remove(struct pci_dev *pdev)
release_mem_region(pci_resource_start(pdev, 0),
pci_resource_len(pdev, 0));
pci_disable_device(pdev);

kfree(bg);
}

#ifdef CONFIG_PM
Expand Down
4 changes: 1 addition & 3 deletions drivers/gpio/gpio-davinci.c
Original file line number Diff line number Diff line change
Expand Up @@ -230,10 +230,8 @@ static int davinci_gpio_probe(struct platform_device *pdev)
chips = devm_kzalloc(dev,
ngpio * sizeof(struct davinci_gpio_controller),
GFP_KERNEL);
if (!chips) {
dev_err(dev, "Memory allocation failed\n");
if (!chips)
return -ENOMEM;
}

res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
if (!res) {
Expand Down
Loading

0 comments on commit 80fb974

Please sign in to comment.