mirror of
https://github.com/torvalds/linux.git
synced 2024-12-04 01:51:34 +00:00
ea584595fc
cycle: - Increase the default ARCH_NR_GPIO from 256 to 512. This was done to avoid having a custom <asm/gpio.h> header for the x86 architecture - GPIO is custom and complicated enough as it is already! We want to move to a radix to store the descriptors going forward, and finally get rid of this fixed array size altogether. - Endgame patching of the gpio_remove() semantics initiated by Abdoulaye Berthe. It is not accepted by the system that the removal of a GPIO chip fails during e.g. reboot or shutdown, and therefore the return value has now painfully been refactored away. For special cases like GPIO expanders on a hot-pluggable bus like USB, we may later add some gpiochip_try_remove() call, but for the cases we have now, return values are moot. - Some incremental refactoring of the gpiolib core and ACPI GPIO library for more descriptor usage. - Refactor the chained IRQ handler set-up method to handle also threaded, nested interrupts and set up the parent IRQ correctly. Switch STMPE and TC3589x drivers to use this registration method. - Add a .irq_not_threaded flag to the struct gpio_chip, so that also GPIO expanders that block but are still not using threaded IRQ handlers. - New drivers for the ARM64 X-Gene SoC GPIO controller. - The syscon GPIO driver has been improved to handle the "DSP GPIO" found on the TI Keystone 2 SoC:s. - ADNP driver switched to use gpiolib irqchip helpers. - Refactor the DWAPB driver to support being instantiated from and MFD cell (platform device). - Incremental feature improvement in the Zynq, MCP23S08, DWAPB, OMAP, Xilinx and Crystalcove drivers. - Various minor fixes. -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iQIcBAABAgAGBQJUNOr0AAoJEEEQszewGV1z9toP/2ISXRnsi3+jlqVmEGm/y6EA PPwJOiYnOhZR2/fTCHIF0PNbIi9pw7xKnzxttYCu4uCz7geHX+FfTwUZ2/KWMfqi ZJ9kEoOVVKzKjmL/m2a2tO4IRSBHqJ8dF3yvaNjS3AL7EDfG6F5STErQurdLEynK SeJZ2OwM/vRFCac6F7oDlqAUTu3xYGbVD8+zI0H0V/ReocosFlEwcbl2S8ctDWUd h98M+gY+A8rxkvVMnmQ/k7rUTme/glDQ3z5xVx+uHbS2/a5M1jSM/71cXE6YnSrR it0CK7CHomq2RzHsKf7oH7GD4kFkukMwFKeMoqz75JWz3352VZPTF53chCIqRSgO hrgGwZ7WF6pUUUhsn1ZdZsnBPA2Fou2uwslyLSAiE+OYEH2/NSVIOUcorjQcWqU/ 0Kix5yb8X1ZzRMhR+TVrTD5V0jguqp2buXq+0P2XlU6MoO2vy7iNf2eXvPg8sF8C anjTCKgmkzy7eyT2uzfDaNZAyfSBKb1TiKiR9zA0SRChJkCi1ErJEXDGeHiptvSA +D2k68Ils2LqsvdrnEd2XvVFMllh0iq7b+16o7D+Els0WRbnHpfYCaqfOuF5F4U0 SmeyI0ruawNDc5e9EBKXstt0/R9AMOetyTcTu29U2ZVo90zGaT1ofT8+R1jJ0kGa bPARJZrgecgv1E9Qnnnd =8InA -----END PGP SIGNATURE----- Merge tag 'gpio-v3.18-1' of git://git.kernel.org/pub/scm/linux/kernel/git/linusw/linux-gpio Pull GPIO changes from Linus Walleij: "This is the bulk of GPIO changes for the v3.18 development cycle: - Increase the default ARCH_NR_GPIO from 256 to 512. This was done to avoid having a custom <asm/gpio.h> header for the x86 architecture - GPIO is custom and complicated enough as it is already! We want to move to a radix to store the descriptors going forward, and finally get rid of this fixed array size altogether. - Endgame patching of the gpio_remove() semantics initiated by Abdoulaye Berthe. It is not accepted by the system that the removal of a GPIO chip fails during eg reboot or shutdown, and therefore the return value has now painfully been refactored away. For special cases like GPIO expanders on a hot-pluggable bus like USB, we may later add some gpiochip_try_remove() call, but for the cases we have now, return values are moot. - Some incremental refactoring of the gpiolib core and ACPI GPIO library for more descriptor usage. - Refactor the chained IRQ handler set-up method to handle also threaded, nested interrupts and set up the parent IRQ correctly. Switch STMPE and TC3589x drivers to use this registration method. - Add a .irq_not_threaded flag to the struct gpio_chip, so that also GPIO expanders that block but are still not using threaded IRQ handlers. - New drivers for the ARM64 X-Gene SoC GPIO controller. - The syscon GPIO driver has been improved to handle the "DSP GPIO" found on the TI Keystone 2 SoC:s. - ADNP driver switched to use gpiolib irqchip helpers. - Refactor the DWAPB driver to support being instantiated from and MFD cell (platform device). - Incremental feature improvement in the Zynq, MCP23S08, DWAPB, OMAP, Xilinx and Crystalcove drivers. - Various minor fixes" * tag 'gpio-v3.18-1' of git://git.kernel.org/pub/scm/linux/kernel/git/linusw/linux-gpio: (52 commits) gpio: pch: Build context save/restore only for PM pinctrl: abx500: get rid of unused variable gpio: ks8695: fix 'else should follow close brace '}'' gpio: stmpe: add verbose debug code gpio: stmpe: fix up interrupt enable logic gpio: staticize xway_stp_init() gpio: handle also nested irqchips in the chained handler set-up gpio: set parent irq on chained handlers gpiolib: irqchip: use irq_find_mapping while removing irqchip gpio: crystalcove: support virtual GPIO pinctrl: bcm281xx: make Kconfig dependency more strict gpio: kona: enable only on BCM_MOBILE or for compile testing gpio, bcm-kona, LLVMLinux: Remove use of __initconst gpio: Fix ngpio in gpio-xilinx driver gpio: dwapb: fix pointer to integer cast gpio: xgene: Remove unneeded #ifdef CONFIG_OF guard gpio: xgene: Remove unneeded forward declation for struct xgene_gpio gpio: xgene: Fix missing spin_lock_init() gpio: ks8695: fix switch case indentation gpiolib: add irq_not_threaded flag to gpio_chip ...
261 lines
6.1 KiB
C
261 lines
6.1 KiB
C
/*
|
|
* Broadcom specific AMBA
|
|
* GPIO driver
|
|
*
|
|
* Copyright 2011, Broadcom Corporation
|
|
* Copyright 2012, Hauke Mehrtens <hauke@hauke-m.de>
|
|
*
|
|
* Licensed under the GNU/GPL. See COPYING for details.
|
|
*/
|
|
|
|
#include <linux/gpio.h>
|
|
#include <linux/irq.h>
|
|
#include <linux/interrupt.h>
|
|
#include <linux/irqdomain.h>
|
|
#include <linux/export.h>
|
|
#include <linux/bcma/bcma.h>
|
|
|
|
#include "bcma_private.h"
|
|
|
|
static inline struct bcma_drv_cc *bcma_gpio_get_cc(struct gpio_chip *chip)
|
|
{
|
|
return container_of(chip, struct bcma_drv_cc, gpio);
|
|
}
|
|
|
|
static int bcma_gpio_get_value(struct gpio_chip *chip, unsigned gpio)
|
|
{
|
|
struct bcma_drv_cc *cc = bcma_gpio_get_cc(chip);
|
|
|
|
return !!bcma_chipco_gpio_in(cc, 1 << gpio);
|
|
}
|
|
|
|
static void bcma_gpio_set_value(struct gpio_chip *chip, unsigned gpio,
|
|
int value)
|
|
{
|
|
struct bcma_drv_cc *cc = bcma_gpio_get_cc(chip);
|
|
|
|
bcma_chipco_gpio_out(cc, 1 << gpio, value ? 1 << gpio : 0);
|
|
}
|
|
|
|
static int bcma_gpio_direction_input(struct gpio_chip *chip, unsigned gpio)
|
|
{
|
|
struct bcma_drv_cc *cc = bcma_gpio_get_cc(chip);
|
|
|
|
bcma_chipco_gpio_outen(cc, 1 << gpio, 0);
|
|
return 0;
|
|
}
|
|
|
|
static int bcma_gpio_direction_output(struct gpio_chip *chip, unsigned gpio,
|
|
int value)
|
|
{
|
|
struct bcma_drv_cc *cc = bcma_gpio_get_cc(chip);
|
|
|
|
bcma_chipco_gpio_outen(cc, 1 << gpio, 1 << gpio);
|
|
bcma_chipco_gpio_out(cc, 1 << gpio, value ? 1 << gpio : 0);
|
|
return 0;
|
|
}
|
|
|
|
static int bcma_gpio_request(struct gpio_chip *chip, unsigned gpio)
|
|
{
|
|
struct bcma_drv_cc *cc = bcma_gpio_get_cc(chip);
|
|
|
|
bcma_chipco_gpio_control(cc, 1 << gpio, 0);
|
|
/* clear pulldown */
|
|
bcma_chipco_gpio_pulldown(cc, 1 << gpio, 0);
|
|
/* Set pullup */
|
|
bcma_chipco_gpio_pullup(cc, 1 << gpio, 1 << gpio);
|
|
|
|
return 0;
|
|
}
|
|
|
|
static void bcma_gpio_free(struct gpio_chip *chip, unsigned gpio)
|
|
{
|
|
struct bcma_drv_cc *cc = bcma_gpio_get_cc(chip);
|
|
|
|
/* clear pullup */
|
|
bcma_chipco_gpio_pullup(cc, 1 << gpio, 0);
|
|
}
|
|
|
|
#if IS_BUILTIN(CONFIG_BCM47XX)
|
|
static int bcma_gpio_to_irq(struct gpio_chip *chip, unsigned gpio)
|
|
{
|
|
struct bcma_drv_cc *cc = bcma_gpio_get_cc(chip);
|
|
|
|
if (cc->core->bus->hosttype == BCMA_HOSTTYPE_SOC)
|
|
return irq_find_mapping(cc->irq_domain, gpio);
|
|
else
|
|
return -EINVAL;
|
|
}
|
|
|
|
static void bcma_gpio_irq_unmask(struct irq_data *d)
|
|
{
|
|
struct bcma_drv_cc *cc = irq_data_get_irq_chip_data(d);
|
|
int gpio = irqd_to_hwirq(d);
|
|
u32 val = bcma_chipco_gpio_in(cc, BIT(gpio));
|
|
|
|
bcma_chipco_gpio_polarity(cc, BIT(gpio), val);
|
|
bcma_chipco_gpio_intmask(cc, BIT(gpio), BIT(gpio));
|
|
}
|
|
|
|
static void bcma_gpio_irq_mask(struct irq_data *d)
|
|
{
|
|
struct bcma_drv_cc *cc = irq_data_get_irq_chip_data(d);
|
|
int gpio = irqd_to_hwirq(d);
|
|
|
|
bcma_chipco_gpio_intmask(cc, BIT(gpio), 0);
|
|
}
|
|
|
|
static struct irq_chip bcma_gpio_irq_chip = {
|
|
.name = "BCMA-GPIO",
|
|
.irq_mask = bcma_gpio_irq_mask,
|
|
.irq_unmask = bcma_gpio_irq_unmask,
|
|
};
|
|
|
|
static irqreturn_t bcma_gpio_irq_handler(int irq, void *dev_id)
|
|
{
|
|
struct bcma_drv_cc *cc = dev_id;
|
|
u32 val = bcma_cc_read32(cc, BCMA_CC_GPIOIN);
|
|
u32 mask = bcma_cc_read32(cc, BCMA_CC_GPIOIRQ);
|
|
u32 pol = bcma_cc_read32(cc, BCMA_CC_GPIOPOL);
|
|
unsigned long irqs = (val ^ pol) & mask;
|
|
int gpio;
|
|
|
|
if (!irqs)
|
|
return IRQ_NONE;
|
|
|
|
for_each_set_bit(gpio, &irqs, cc->gpio.ngpio)
|
|
generic_handle_irq(bcma_gpio_to_irq(&cc->gpio, gpio));
|
|
bcma_chipco_gpio_polarity(cc, irqs, val & irqs);
|
|
|
|
return IRQ_HANDLED;
|
|
}
|
|
|
|
static int bcma_gpio_irq_domain_init(struct bcma_drv_cc *cc)
|
|
{
|
|
struct gpio_chip *chip = &cc->gpio;
|
|
int gpio, hwirq, err;
|
|
|
|
if (cc->core->bus->hosttype != BCMA_HOSTTYPE_SOC)
|
|
return 0;
|
|
|
|
cc->irq_domain = irq_domain_add_linear(NULL, chip->ngpio,
|
|
&irq_domain_simple_ops, cc);
|
|
if (!cc->irq_domain) {
|
|
err = -ENODEV;
|
|
goto err_irq_domain;
|
|
}
|
|
for (gpio = 0; gpio < chip->ngpio; gpio++) {
|
|
int irq = irq_create_mapping(cc->irq_domain, gpio);
|
|
|
|
irq_set_chip_data(irq, cc);
|
|
irq_set_chip_and_handler(irq, &bcma_gpio_irq_chip,
|
|
handle_simple_irq);
|
|
}
|
|
|
|
hwirq = bcma_core_irq(cc->core);
|
|
err = request_irq(hwirq, bcma_gpio_irq_handler, IRQF_SHARED, "gpio",
|
|
cc);
|
|
if (err)
|
|
goto err_req_irq;
|
|
|
|
bcma_chipco_gpio_intmask(cc, ~0, 0);
|
|
bcma_cc_set32(cc, BCMA_CC_IRQMASK, BCMA_CC_IRQ_GPIO);
|
|
|
|
return 0;
|
|
|
|
err_req_irq:
|
|
for (gpio = 0; gpio < chip->ngpio; gpio++) {
|
|
int irq = irq_find_mapping(cc->irq_domain, gpio);
|
|
|
|
irq_dispose_mapping(irq);
|
|
}
|
|
irq_domain_remove(cc->irq_domain);
|
|
err_irq_domain:
|
|
return err;
|
|
}
|
|
|
|
static void bcma_gpio_irq_domain_exit(struct bcma_drv_cc *cc)
|
|
{
|
|
struct gpio_chip *chip = &cc->gpio;
|
|
int gpio;
|
|
|
|
if (cc->core->bus->hosttype != BCMA_HOSTTYPE_SOC)
|
|
return;
|
|
|
|
bcma_cc_mask32(cc, BCMA_CC_IRQMASK, ~BCMA_CC_IRQ_GPIO);
|
|
free_irq(bcma_core_irq(cc->core), cc);
|
|
for (gpio = 0; gpio < chip->ngpio; gpio++) {
|
|
int irq = irq_find_mapping(cc->irq_domain, gpio);
|
|
|
|
irq_dispose_mapping(irq);
|
|
}
|
|
irq_domain_remove(cc->irq_domain);
|
|
}
|
|
#else
|
|
static int bcma_gpio_irq_domain_init(struct bcma_drv_cc *cc)
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
static void bcma_gpio_irq_domain_exit(struct bcma_drv_cc *cc)
|
|
{
|
|
}
|
|
#endif
|
|
|
|
int bcma_gpio_init(struct bcma_drv_cc *cc)
|
|
{
|
|
struct gpio_chip *chip = &cc->gpio;
|
|
int err;
|
|
|
|
chip->label = "bcma_gpio";
|
|
chip->owner = THIS_MODULE;
|
|
chip->request = bcma_gpio_request;
|
|
chip->free = bcma_gpio_free;
|
|
chip->get = bcma_gpio_get_value;
|
|
chip->set = bcma_gpio_set_value;
|
|
chip->direction_input = bcma_gpio_direction_input;
|
|
chip->direction_output = bcma_gpio_direction_output;
|
|
#if IS_BUILTIN(CONFIG_BCM47XX)
|
|
chip->to_irq = bcma_gpio_to_irq;
|
|
#endif
|
|
#if IS_BUILTIN(CONFIG_OF)
|
|
if (cc->core->bus->hosttype == BCMA_HOSTTYPE_SOC)
|
|
chip->of_node = cc->core->dev.of_node;
|
|
#endif
|
|
switch (cc->core->bus->chipinfo.id) {
|
|
case BCMA_CHIP_ID_BCM5357:
|
|
case BCMA_CHIP_ID_BCM53572:
|
|
chip->ngpio = 32;
|
|
break;
|
|
default:
|
|
chip->ngpio = 16;
|
|
}
|
|
|
|
/* There is just one SoC in one device and its GPIO addresses should be
|
|
* deterministic to address them more easily. The other buses could get
|
|
* a random base number. */
|
|
if (cc->core->bus->hosttype == BCMA_HOSTTYPE_SOC)
|
|
chip->base = 0;
|
|
else
|
|
chip->base = -1;
|
|
|
|
err = bcma_gpio_irq_domain_init(cc);
|
|
if (err)
|
|
return err;
|
|
|
|
err = gpiochip_add(chip);
|
|
if (err) {
|
|
bcma_gpio_irq_domain_exit(cc);
|
|
return err;
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
int bcma_gpio_unregister(struct bcma_drv_cc *cc)
|
|
{
|
|
bcma_gpio_irq_domain_exit(cc);
|
|
gpiochip_remove(&cc->gpio);
|
|
return 0;
|
|
}
|