Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge tag 'gpio-for-v3.7' of git://git.kernel.org/pub/scm/linux/kernel/git/linusw/linux-gpio

Pull GPIO changes from Linus Walleij:
"So this is the LW GPIO patch stack for v3.7:
- refactoring from Thierry Redding at Arnd Bergmann's request to use
the seq_file iterator interface in gpiolib.
- A new driver for Avionic Design's N-bit GPIO expander.
- Two instances of mutexes replaced by spinlocks from Axel Lin to
code that is supposed to be fastpath compliant.
- IRQ demuxer and gpio_to_irq() support for pcf857x by Kuninori
Morimoto.
- Dynamic GPIO numbers, device tree support, daisy chaining and some
other fixes for the 74x164 driver by Maxime Ripard.
- IRQ domain and device tree support for the tc3589x driver by Lee
Jones.
- Some conversion to use managed resources devm_* code.
- Some instances of clk_prepare() or clk_prepare_enable() added to
support the new, stricter common clock framework.
- Some for_each_set_bit() simplifications.
- Then a lot of fixes as we fixed up all of the above tripping over
our own shoelaces and that kind of thing."

* tag 'gpio-for-v3.7' of git://git.kernel.org/pub/scm/linux/kernel/git/linusw/linux-gpio: (34 commits)
gpio: pcf857x: select IRQ_DOMAIN
gpio: Document device_node's det_debounce
gpio-lpc32xx: Add GPI_28
gpio: adnp: dt: Reference generic interrupt binding
gpio: Add Avionic Design N-bit GPIO expander support
gpio: pxa: using for_each_set_bit to simplify the code
gpio_msm: using for_each_set_bit to simplify the code
gpio: Enable the tc3298x GPIO expander driver for Device Tree
gpio: Provide the tc3589x GPIO expander driver with an IRQ domain
ARM: shmobile: kzm9g: use gpio-keys instead of gpio-keys-polled
gpio: pcf857x: fixup smatch WARNING
gpio: 74x164: Add support for the daisy-chaining
gpio: 74x164: dts: Add documentation for the dt binding
dt: Fix incorrect reference in gpio-led documentation
gpio: 74x164: Add device tree support
gpio: 74x164: Use dynamic gpio number assignment if no pdata is present
gpio: 74x164: Use devm_kzalloc
gpio: 74x164: Use module_spi_driver boiler plate function
gpio: sx150x: Use irq_data_get_irq_chip_data() at appropriate places
gpio: em: Use irq_data_get_irq_chip_data() at appropriate places
...

+1104 -248
+22
Documentation/devicetree/bindings/gpio/gpio-74x164.txt
··· 1 + * Generic 8-bits shift register GPIO driver 2 + 3 + Required properties: 4 + - compatible : Should be "fairchild,74hc595" 5 + - reg : chip select number 6 + - gpio-controller : Marks the device node as a gpio controller. 7 + - #gpio-cells : Should be two. The first cell is the pin number and 8 + the second cell is used to specify the gpio polarity: 9 + 0 = active high 10 + 1 = active low 11 + - registers-number: Number of daisy-chained shift registers 12 + 13 + Example: 14 + 15 + gpio5: gpio5@0 { 16 + compatible = "fairchild,74hc595"; 17 + reg = <0>; 18 + gpio-controller; 19 + #gpio-cells = <2>; 20 + registers-number = <4>; 21 + spi-max-frequency = <100000>; 22 + };
+34
Documentation/devicetree/bindings/gpio/gpio-adnp.txt
··· 1 + Avionic Design N-bit GPIO expander bindings 2 + 3 + Required properties: 4 + - compatible: should be "ad,gpio-adnp" 5 + - reg: The I2C slave address for this device. 6 + - interrupt-parent: phandle of the parent interrupt controller. 7 + - interrupts: Interrupt specifier for the controllers interrupt. 8 + - #gpio-cells: Should be 2. The first cell is the GPIO number and the 9 + second cell is used to specify optional parameters: 10 + - bit 0: polarity (0: normal, 1: inverted) 11 + - gpio-controller: Marks the device as a GPIO controller 12 + - nr-gpios: The number of pins supported by the controller. 13 + 14 + The GPIO expander can optionally be used as an interrupt controller, in 15 + which case it uses the default two cell specifier as described in 16 + Documentation/devicetree/bindings/interrupt-controller/interrupts.txt. 17 + 18 + Example: 19 + 20 + gpioext: gpio-controller@41 { 21 + compatible = "ad,gpio-adnp"; 22 + reg = <0x41>; 23 + 24 + interrupt-parent = <&gpio>; 25 + interrupts = <160 1>; 26 + 27 + gpio-controller; 28 + #gpio-cells = <2>; 29 + 30 + interrupt-controller; 31 + #interrupt-cells = <2>; 32 + 33 + nr-gpios = <64>; 34 + };
+1 -1
Documentation/devicetree/bindings/gpio/led.txt
··· 8 8 9 9 LED sub-node properties: 10 10 - gpios : Should specify the LED's GPIO, see "gpios property" in 11 - Documentation/devicetree/gpio.txt. Active low LEDs should be 11 + Documentation/devicetree/bindings/gpio/gpio.txt. Active low LEDs should be 12 12 indicated using flags in the GPIO specifier. 13 13 - label : (optional) The label for this LED. If omitted, the label is 14 14 taken from the node name (excluding the unit address).
+1 -1
arch/arm/configs/kzm9g_defconfig
··· 23 23 # CONFIG_IOSCHED_DEADLINE is not set 24 24 # CONFIG_IOSCHED_CFQ is not set 25 25 CONFIG_ARCH_SHMOBILE=y 26 - CONFIG_KEYBOARD_GPIO_POLLED=y 27 26 CONFIG_ARCH_SH73A0=y 28 27 CONFIG_MACH_KZM9G=y 29 28 CONFIG_MEMORY_START=0x41000000 ··· 70 71 # CONFIG_INPUT_MOUSEDEV is not set 71 72 CONFIG_INPUT_EVDEV=y 72 73 # CONFIG_KEYBOARD_ATKBD is not set 74 + CONFIG_KEYBOARD_GPIO=y 73 75 # CONFIG_INPUT_MOUSE is not set 74 76 CONFIG_INPUT_TOUCHSCREEN=y 75 77 CONFIG_TOUCHSCREEN_ST1232=y
+2 -3
arch/arm/mach-shmobile/board-kzm9g.c
··· 482 482 static struct gpio_keys_platform_data gpio_key_info = { 483 483 .buttons = gpio_buttons, 484 484 .nbuttons = ARRAY_SIZE(gpio_buttons), 485 - .poll_interval = 250, /* poling at this point */ 486 485 }; 487 486 488 487 static struct platform_device gpio_keys_device = { 489 - /* gpio-pcf857x.c driver doesn't support gpio_to_irq() */ 490 - .name = "gpio-keys-polled", 488 + .name = "gpio-keys", 491 489 .dev = { 492 490 .platform_data = &gpio_key_info, 493 491 }, ··· 548 550 /* I2C */ 549 551 static struct pcf857x_platform_data pcf8575_pdata = { 550 552 .gpio_base = GPIO_PCF8575_BASE, 553 + .irq = intcs_evt2irq(0x3260), /* IRQ19 */ 551 554 }; 552 555 553 556 static struct i2c_board_info i2c0_devices[] = {
+13 -1
drivers/gpio/Kconfig
··· 82 82 83 83 config GPIO_DA9052 84 84 tristate "Dialog DA9052 GPIO" 85 - depends on PMIC_DA9052 && BROKEN 85 + depends on PMIC_DA9052 86 86 help 87 87 Say yes here to enable the GPIO driver for the DA9052 chip. 88 88 ··· 330 330 config GPIO_PCF857X 331 331 tristate "PCF857x, PCA{85,96}7x, and MAX732[89] I2C GPIO expanders" 332 332 depends on I2C 333 + select IRQ_DOMAIN 333 334 help 334 335 Say yes here to provide access to most "quasi-bidirectional" I2C 335 336 GPIO expanders used for additional digital outputs or inputs. ··· 450 449 help 451 450 Say yes here to enable the adp5588 to be used as an interrupt 452 451 controller. It requires the driver to be built in the kernel. 452 + 453 + config GPIO_ADNP 454 + tristate "Avionic Design N-bit GPIO expander" 455 + depends on I2C && OF 456 + help 457 + This option enables support for N GPIOs found on Avionic Design 458 + I2C GPIO expanders. The register space will be extended by powers 459 + of two, so the controller will need to accomodate for that. For 460 + example: if a controller provides 48 pins, 6 registers will be 461 + enough to represent all pins, but the driver will assume a 462 + register layout for 64 pins (8 registers). 453 463 454 464 comment "PCI GPIO expanders:" 455 465
+1
drivers/gpio/Makefile
··· 10 10 11 11 obj-$(CONFIG_GPIO_74X164) += gpio-74x164.o 12 12 obj-$(CONFIG_GPIO_AB8500) += gpio-ab8500.o 13 + obj-$(CONFIG_GPIO_ADNP) += gpio-adnp.o 13 14 obj-$(CONFIG_GPIO_ADP5520) += gpio-adp5520.o 14 15 obj-$(CONFIG_GPIO_ADP5588) += gpio-adp5588.o 15 16 obj-$(CONFIG_GPIO_AMD8111) += gpio-amd8111.o
+75 -28
drivers/gpio/gpio-74x164.c
··· 14 14 #include <linux/spi/spi.h> 15 15 #include <linux/spi/74x164.h> 16 16 #include <linux/gpio.h> 17 + #include <linux/of_gpio.h> 17 18 #include <linux/slab.h> 18 19 #include <linux/module.h> 19 20 21 + #define GEN_74X164_NUMBER_GPIOS 8 22 + 20 23 struct gen_74x164_chip { 21 24 struct spi_device *spi; 25 + u8 *buffer; 22 26 struct gpio_chip gpio_chip; 23 27 struct mutex lock; 24 - u8 port_config; 28 + u32 registers; 25 29 }; 26 30 27 31 static struct gen_74x164_chip *gpio_to_74x164_chip(struct gpio_chip *gc) ··· 35 31 36 32 static int __gen_74x164_write_config(struct gen_74x164_chip *chip) 37 33 { 38 - return spi_write(chip->spi, 39 - &chip->port_config, sizeof(chip->port_config)); 34 + struct spi_message message; 35 + struct spi_transfer *msg_buf; 36 + int i, ret = 0; 37 + 38 + msg_buf = kzalloc(chip->registers * sizeof(struct spi_transfer), 39 + GFP_KERNEL); 40 + if (!msg_buf) 41 + return -ENOMEM; 42 + 43 + spi_message_init(&message); 44 + 45 + /* 46 + * Since the registers are chained, every byte sent will make 47 + * the previous byte shift to the next register in the 48 + * chain. Thus, the first byte send will end up in the last 49 + * register at the end of the transfer. So, to have a logical 50 + * numbering, send the bytes in reverse order so that the last 51 + * byte of the buffer will end up in the last register. 52 + */ 53 + for (i = chip->registers - 1; i >= 0; i--) { 54 + msg_buf[i].tx_buf = chip->buffer +i; 55 + msg_buf[i].len = sizeof(u8); 56 + spi_message_add_tail(msg_buf + i, &message); 57 + } 58 + 59 + ret = spi_sync(chip->spi, &message); 60 + 61 + kfree(msg_buf); 62 + 63 + return ret; 40 64 } 41 65 42 66 static int gen_74x164_get_value(struct gpio_chip *gc, unsigned offset) 43 67 { 44 68 struct gen_74x164_chip *chip = gpio_to_74x164_chip(gc); 69 + u8 bank = offset / 8; 70 + u8 pin = offset % 8; 45 71 int ret; 46 72 47 73 mutex_lock(&chip->lock); 48 - ret = (chip->port_config >> offset) & 0x1; 74 + ret = (chip->buffer[bank] >> pin) & 0x1; 49 75 mutex_unlock(&chip->lock); 50 76 51 77 return ret; ··· 85 51 unsigned offset, int val) 86 52 { 87 53 struct gen_74x164_chip *chip = gpio_to_74x164_chip(gc); 54 + u8 bank = offset / 8; 55 + u8 pin = offset % 8; 88 56 89 57 mutex_lock(&chip->lock); 90 58 if (val) 91 - chip->port_config |= (1 << offset); 59 + chip->buffer[bank] |= (1 << pin); 92 60 else 93 - chip->port_config &= ~(1 << offset); 61 + chip->buffer[bank] &= ~(1 << pin); 94 62 95 63 __gen_74x164_write_config(chip); 96 64 mutex_unlock(&chip->lock); ··· 111 75 struct gen_74x164_chip_platform_data *pdata; 112 76 int ret; 113 77 114 - pdata = spi->dev.platform_data; 115 - if (!pdata || !pdata->base) { 116 - dev_dbg(&spi->dev, "incorrect or missing platform data\n"); 78 + if (!spi->dev.of_node) { 79 + dev_err(&spi->dev, "No device tree data available.\n"); 117 80 return -EINVAL; 118 81 } 119 82 ··· 125 90 if (ret < 0) 126 91 return ret; 127 92 128 - chip = kzalloc(sizeof(*chip), GFP_KERNEL); 93 + chip = devm_kzalloc(&spi->dev, sizeof(*chip), GFP_KERNEL); 129 94 if (!chip) 130 95 return -ENOMEM; 96 + 97 + pdata = spi->dev.platform_data; 98 + if (pdata && pdata->base) 99 + chip->gpio_chip.base = pdata->base; 100 + else 101 + chip->gpio_chip.base = -1; 131 102 132 103 mutex_init(&chip->lock); 133 104 ··· 145 104 chip->gpio_chip.direction_output = gen_74x164_direction_output; 146 105 chip->gpio_chip.get = gen_74x164_get_value; 147 106 chip->gpio_chip.set = gen_74x164_set_value; 148 - chip->gpio_chip.base = pdata->base; 149 - chip->gpio_chip.ngpio = 8; 107 + 108 + if (of_property_read_u32(spi->dev.of_node, "registers-number", &chip->registers)) { 109 + dev_err(&spi->dev, "Missing registers-number property in the DT.\n"); 110 + ret = -EINVAL; 111 + goto exit_destroy; 112 + } 113 + 114 + chip->gpio_chip.ngpio = GEN_74X164_NUMBER_GPIOS * chip->registers; 115 + chip->buffer = devm_kzalloc(&spi->dev, chip->gpio_chip.ngpio, GFP_KERNEL); 116 + if (!chip->buffer) { 117 + ret = -ENOMEM; 118 + goto exit_destroy; 119 + } 120 + 150 121 chip->gpio_chip.can_sleep = 1; 151 122 chip->gpio_chip.dev = &spi->dev; 152 123 chip->gpio_chip.owner = THIS_MODULE; ··· 178 125 exit_destroy: 179 126 dev_set_drvdata(&spi->dev, NULL); 180 127 mutex_destroy(&chip->lock); 181 - kfree(chip); 182 128 return ret; 183 129 } 184 130 ··· 193 141 dev_set_drvdata(&spi->dev, NULL); 194 142 195 143 ret = gpiochip_remove(&chip->gpio_chip); 196 - if (!ret) { 144 + if (!ret) 197 145 mutex_destroy(&chip->lock); 198 - kfree(chip); 199 - } else 146 + else 200 147 dev_err(&spi->dev, "Failed to remove the GPIO controller: %d\n", 201 148 ret); 202 149 203 150 return ret; 204 151 } 205 152 153 + static const struct of_device_id gen_74x164_dt_ids[] = { 154 + { .compatible = "fairchild,74hc595" }, 155 + {}, 156 + }; 157 + MODULE_DEVICE_TABLE(of, gen_74x164_dt_ids); 158 + 206 159 static struct spi_driver gen_74x164_driver = { 207 160 .driver = { 208 161 .name = "74x164", 209 162 .owner = THIS_MODULE, 163 + .of_match_table = of_match_ptr(gen_74x164_dt_ids), 210 164 }, 211 165 .probe = gen_74x164_probe, 212 166 .remove = __devexit_p(gen_74x164_remove), 213 167 }; 214 - 215 - static int __init gen_74x164_init(void) 216 - { 217 - return spi_register_driver(&gen_74x164_driver); 218 - } 219 - subsys_initcall(gen_74x164_init); 220 - 221 - static void __exit gen_74x164_exit(void) 222 - { 223 - spi_unregister_driver(&gen_74x164_driver); 224 - } 225 - module_exit(gen_74x164_exit); 168 + module_spi_driver(gen_74x164_driver); 226 169 227 170 MODULE_AUTHOR("Gabor Juhos <juhosg@openwrt.org>"); 228 171 MODULE_AUTHOR("Miguel Gaio <miguel.gaio@efixo.com>");
+611
drivers/gpio/gpio-adnp.c
··· 1 + /* 2 + * Copyright (C) 2011-2012 Avionic Design GmbH 3 + * 4 + * This program is free software; you can redistribute it and/or modify 5 + * it under the terms of the GNU General Public License version 2 as 6 + * published by the Free Software Foundation. 7 + */ 8 + 9 + #include <linux/gpio.h> 10 + #include <linux/i2c.h> 11 + #include <linux/interrupt.h> 12 + #include <linux/irqdomain.h> 13 + #include <linux/module.h> 14 + #include <linux/of_irq.h> 15 + #include <linux/seq_file.h> 16 + #include <linux/slab.h> 17 + 18 + #define GPIO_DDR(gpio) (0x00 << (gpio)->reg_shift) 19 + #define GPIO_PLR(gpio) (0x01 << (gpio)->reg_shift) 20 + #define GPIO_IER(gpio) (0x02 << (gpio)->reg_shift) 21 + #define GPIO_ISR(gpio) (0x03 << (gpio)->reg_shift) 22 + #define GPIO_PTR(gpio) (0x04 << (gpio)->reg_shift) 23 + 24 + struct adnp { 25 + struct i2c_client *client; 26 + struct gpio_chip gpio; 27 + unsigned int reg_shift; 28 + 29 + struct mutex i2c_lock; 30 + 31 + struct irq_domain *domain; 32 + struct mutex irq_lock; 33 + 34 + u8 *irq_enable; 35 + u8 *irq_level; 36 + u8 *irq_rise; 37 + u8 *irq_fall; 38 + u8 *irq_high; 39 + u8 *irq_low; 40 + }; 41 + 42 + static inline struct adnp *to_adnp(struct gpio_chip *chip) 43 + { 44 + return container_of(chip, struct adnp, gpio); 45 + } 46 + 47 + static int adnp_read(struct adnp *adnp, unsigned offset, uint8_t *value) 48 + { 49 + int err; 50 + 51 + err = i2c_smbus_read_byte_data(adnp->client, offset); 52 + if (err < 0) { 53 + dev_err(adnp->gpio.dev, "%s failed: %d\n", 54 + "i2c_smbus_read_byte_data()", err); 55 + return err; 56 + } 57 + 58 + *value = err; 59 + return 0; 60 + } 61 + 62 + static int adnp_write(struct adnp *adnp, unsigned offset, uint8_t value) 63 + { 64 + int err; 65 + 66 + err = i2c_smbus_write_byte_data(adnp->client, offset, value); 67 + if (err < 0) { 68 + dev_err(adnp->gpio.dev, "%s failed: %d\n", 69 + "i2c_smbus_write_byte_data()", err); 70 + return err; 71 + } 72 + 73 + return 0; 74 + } 75 + 76 + static int adnp_gpio_get(struct gpio_chip *chip, unsigned offset) 77 + { 78 + struct adnp *adnp = to_adnp(chip); 79 + unsigned int reg = offset >> adnp->reg_shift; 80 + unsigned int pos = offset & 7; 81 + u8 value; 82 + int err; 83 + 84 + err = adnp_read(adnp, GPIO_PLR(adnp) + reg, &value); 85 + if (err < 0) 86 + return err; 87 + 88 + return (value & BIT(pos)) ? 1 : 0; 89 + } 90 + 91 + static void __adnp_gpio_set(struct adnp *adnp, unsigned offset, int value) 92 + { 93 + unsigned int reg = offset >> adnp->reg_shift; 94 + unsigned int pos = offset & 7; 95 + int err; 96 + u8 val; 97 + 98 + err = adnp_read(adnp, GPIO_PLR(adnp) + reg, &val); 99 + if (err < 0) 100 + return; 101 + 102 + if (value) 103 + val |= BIT(pos); 104 + else 105 + val &= ~BIT(pos); 106 + 107 + adnp_write(adnp, GPIO_PLR(adnp) + reg, val); 108 + } 109 + 110 + static void adnp_gpio_set(struct gpio_chip *chip, unsigned offset, int value) 111 + { 112 + struct adnp *adnp = to_adnp(chip); 113 + 114 + mutex_lock(&adnp->i2c_lock); 115 + __adnp_gpio_set(adnp, offset, value); 116 + mutex_unlock(&adnp->i2c_lock); 117 + } 118 + 119 + static int adnp_gpio_direction_input(struct gpio_chip *chip, unsigned offset) 120 + { 121 + struct adnp *adnp = to_adnp(chip); 122 + unsigned int reg = offset >> adnp->reg_shift; 123 + unsigned int pos = offset & 7; 124 + u8 value; 125 + int err; 126 + 127 + mutex_lock(&adnp->i2c_lock); 128 + 129 + err = adnp_read(adnp, GPIO_DDR(adnp) + reg, &value); 130 + if (err < 0) 131 + goto out; 132 + 133 + value &= ~BIT(pos); 134 + 135 + err = adnp_write(adnp, GPIO_DDR(adnp) + reg, value); 136 + if (err < 0) 137 + goto out; 138 + 139 + err = adnp_read(adnp, GPIO_DDR(adnp) + reg, &value); 140 + if (err < 0) 141 + goto out; 142 + 143 + if (err & BIT(pos)) 144 + err = -EACCES; 145 + 146 + err = 0; 147 + 148 + out: 149 + mutex_unlock(&adnp->i2c_lock); 150 + return err; 151 + } 152 + 153 + static int adnp_gpio_direction_output(struct gpio_chip *chip, unsigned offset, 154 + int value) 155 + { 156 + struct adnp *adnp = to_adnp(chip); 157 + unsigned int reg = offset >> adnp->reg_shift; 158 + unsigned int pos = offset & 7; 159 + int err; 160 + u8 val; 161 + 162 + mutex_lock(&adnp->i2c_lock); 163 + 164 + err = adnp_read(adnp, GPIO_DDR(adnp) + reg, &val); 165 + if (err < 0) 166 + goto out; 167 + 168 + val |= BIT(pos); 169 + 170 + err = adnp_write(adnp, GPIO_DDR(adnp) + reg, val); 171 + if (err < 0) 172 + goto out; 173 + 174 + err = adnp_read(adnp, GPIO_DDR(adnp) + reg, &val); 175 + if (err < 0) 176 + goto out; 177 + 178 + if (!(val & BIT(pos))) { 179 + err = -EPERM; 180 + goto out; 181 + } 182 + 183 + __adnp_gpio_set(adnp, offset, value); 184 + err = 0; 185 + 186 + out: 187 + mutex_unlock(&adnp->i2c_lock); 188 + return err; 189 + } 190 + 191 + static void adnp_gpio_dbg_show(struct seq_file *s, struct gpio_chip *chip) 192 + { 193 + struct adnp *adnp = to_adnp(chip); 194 + unsigned int num_regs = 1 << adnp->reg_shift, i, j; 195 + int err; 196 + 197 + for (i = 0; i < num_regs; i++) { 198 + u8 ddr, plr, ier, isr; 199 + 200 + mutex_lock(&adnp->i2c_lock); 201 + 202 + err = adnp_read(adnp, GPIO_DDR(adnp) + i, &ddr); 203 + if (err < 0) { 204 + mutex_unlock(&adnp->i2c_lock); 205 + return; 206 + } 207 + 208 + err = adnp_read(adnp, GPIO_PLR(adnp) + i, &plr); 209 + if (err < 0) { 210 + mutex_unlock(&adnp->i2c_lock); 211 + return; 212 + } 213 + 214 + err = adnp_read(adnp, GPIO_IER(adnp) + i, &ier); 215 + if (err < 0) { 216 + mutex_unlock(&adnp->i2c_lock); 217 + return; 218 + } 219 + 220 + err = adnp_read(adnp, GPIO_ISR(adnp) + i, &isr); 221 + if (err < 0) { 222 + mutex_unlock(&adnp->i2c_lock); 223 + return; 224 + } 225 + 226 + mutex_unlock(&adnp->i2c_lock); 227 + 228 + for (j = 0; j < 8; j++) { 229 + unsigned int bit = (i << adnp->reg_shift) + j; 230 + const char *direction = "input "; 231 + const char *level = "low "; 232 + const char *interrupt = "disabled"; 233 + const char *pending = ""; 234 + 235 + if (ddr & BIT(j)) 236 + direction = "output"; 237 + 238 + if (plr & BIT(j)) 239 + level = "high"; 240 + 241 + if (ier & BIT(j)) 242 + interrupt = "enabled "; 243 + 244 + if (isr & BIT(j)) 245 + pending = "pending"; 246 + 247 + seq_printf(s, "%2u: %s %s IRQ %s %s\n", bit, 248 + direction, level, interrupt, pending); 249 + } 250 + } 251 + } 252 + 253 + static int adnp_gpio_setup(struct adnp *adnp, unsigned int num_gpios) 254 + { 255 + struct gpio_chip *chip = &adnp->gpio; 256 + 257 + adnp->reg_shift = get_count_order(num_gpios) - 3; 258 + 259 + chip->direction_input = adnp_gpio_direction_input; 260 + chip->direction_output = adnp_gpio_direction_output; 261 + chip->get = adnp_gpio_get; 262 + chip->set = adnp_gpio_set; 263 + chip->can_sleep = 1; 264 + 265 + if (IS_ENABLED(CONFIG_DEBUG_FS)) 266 + chip->dbg_show = adnp_gpio_dbg_show; 267 + 268 + chip->base = -1; 269 + chip->ngpio = num_gpios; 270 + chip->label = adnp->client->name; 271 + chip->dev = &adnp->client->dev; 272 + chip->of_node = chip->dev->of_node; 273 + chip->owner = THIS_MODULE; 274 + 275 + return 0; 276 + } 277 + 278 + static irqreturn_t adnp_irq(int irq, void *data) 279 + { 280 + struct adnp *adnp = data; 281 + unsigned int num_regs, i; 282 + 283 + num_regs = 1 << adnp->reg_shift; 284 + 285 + for (i = 0; i < num_regs; i++) { 286 + unsigned int base = i << adnp->reg_shift, bit; 287 + u8 changed, level, isr, ier; 288 + unsigned long pending; 289 + int err; 290 + 291 + mutex_lock(&adnp->i2c_lock); 292 + 293 + err = adnp_read(adnp, GPIO_PLR(adnp) + i, &level); 294 + if (err < 0) { 295 + mutex_unlock(&adnp->i2c_lock); 296 + continue; 297 + } 298 + 299 + err = adnp_read(adnp, GPIO_ISR(adnp) + i, &isr); 300 + if (err < 0) { 301 + mutex_unlock(&adnp->i2c_lock); 302 + continue; 303 + } 304 + 305 + err = adnp_read(adnp, GPIO_IER(adnp) + i, &ier); 306 + if (err < 0) { 307 + mutex_unlock(&adnp->i2c_lock); 308 + continue; 309 + } 310 + 311 + mutex_unlock(&adnp->i2c_lock); 312 + 313 + /* determine pins that changed levels */ 314 + changed = level ^ adnp->irq_level[i]; 315 + 316 + /* compute edge-triggered interrupts */ 317 + pending = changed & ((adnp->irq_fall[i] & ~level) | 318 + (adnp->irq_rise[i] & level)); 319 + 320 + /* add in level-triggered interrupts */ 321 + pending |= (adnp->irq_high[i] & level) | 322 + (adnp->irq_low[i] & ~level); 323 + 324 + /* mask out non-pending and disabled interrupts */ 325 + pending &= isr & ier; 326 + 327 + for_each_set_bit(bit, &pending, 8) { 328 + unsigned int virq; 329 + virq = irq_find_mapping(adnp->domain, base + bit); 330 + handle_nested_irq(virq); 331 + } 332 + } 333 + 334 + return IRQ_HANDLED; 335 + } 336 + 337 + static int adnp_gpio_to_irq(struct gpio_chip *chip, unsigned offset) 338 + { 339 + struct adnp *adnp = to_adnp(chip); 340 + return irq_create_mapping(adnp->domain, offset); 341 + } 342 + 343 + static void adnp_irq_mask(struct irq_data *data) 344 + { 345 + struct adnp *adnp = irq_data_get_irq_chip_data(data); 346 + unsigned int reg = data->hwirq >> adnp->reg_shift; 347 + unsigned int pos = data->hwirq & 7; 348 + 349 + adnp->irq_enable[reg] &= ~BIT(pos); 350 + } 351 + 352 + static void adnp_irq_unmask(struct irq_data *data) 353 + { 354 + struct adnp *adnp = irq_data_get_irq_chip_data(data); 355 + unsigned int reg = data->hwirq >> adnp->reg_shift; 356 + unsigned int pos = data->hwirq & 7; 357 + 358 + adnp->irq_enable[reg] |= BIT(pos); 359 + } 360 + 361 + static int adnp_irq_set_type(struct irq_data *data, unsigned int type) 362 + { 363 + struct adnp *adnp = irq_data_get_irq_chip_data(data); 364 + unsigned int reg = data->hwirq >> adnp->reg_shift; 365 + unsigned int pos = data->hwirq & 7; 366 + 367 + if (type & IRQ_TYPE_EDGE_RISING) 368 + adnp->irq_rise[reg] |= BIT(pos); 369 + else 370 + adnp->irq_rise[reg] &= ~BIT(pos); 371 + 372 + if (type & IRQ_TYPE_EDGE_FALLING) 373 + adnp->irq_fall[reg] |= BIT(pos); 374 + else 375 + adnp->irq_fall[reg] &= ~BIT(pos); 376 + 377 + if (type & IRQ_TYPE_LEVEL_HIGH) 378 + adnp->irq_high[reg] |= BIT(pos); 379 + else 380 + adnp->irq_high[reg] &= ~BIT(pos); 381 + 382 + if (type & IRQ_TYPE_LEVEL_LOW) 383 + adnp->irq_low[reg] |= BIT(pos); 384 + else 385 + adnp->irq_low[reg] &= ~BIT(pos); 386 + 387 + return 0; 388 + } 389 + 390 + static void adnp_irq_bus_lock(struct irq_data *data) 391 + { 392 + struct adnp *adnp = irq_data_get_irq_chip_data(data); 393 + 394 + mutex_lock(&adnp->irq_lock); 395 + } 396 + 397 + static void adnp_irq_bus_unlock(struct irq_data *data) 398 + { 399 + struct adnp *adnp = irq_data_get_irq_chip_data(data); 400 + unsigned int num_regs = 1 << adnp->reg_shift, i; 401 + 402 + mutex_lock(&adnp->i2c_lock); 403 + 404 + for (i = 0; i < num_regs; i++) 405 + adnp_write(adnp, GPIO_IER(adnp) + i, adnp->irq_enable[i]); 406 + 407 + mutex_unlock(&adnp->i2c_lock); 408 + mutex_unlock(&adnp->irq_lock); 409 + } 410 + 411 + static struct irq_chip adnp_irq_chip = { 412 + .name = "gpio-adnp", 413 + .irq_mask = adnp_irq_mask, 414 + .irq_unmask = adnp_irq_unmask, 415 + .irq_set_type = adnp_irq_set_type, 416 + .irq_bus_lock = adnp_irq_bus_lock, 417 + .irq_bus_sync_unlock = adnp_irq_bus_unlock, 418 + }; 419 + 420 + static int adnp_irq_map(struct irq_domain *domain, unsigned int irq, 421 + irq_hw_number_t hwirq) 422 + { 423 + irq_set_chip_data(irq, domain->host_data); 424 + irq_set_chip(irq, &adnp_irq_chip); 425 + irq_set_nested_thread(irq, true); 426 + 427 + #ifdef CONFIG_ARM 428 + set_irq_flags(irq, IRQF_VALID); 429 + #else 430 + irq_set_noprobe(irq); 431 + #endif 432 + 433 + return 0; 434 + } 435 + 436 + static const struct irq_domain_ops adnp_irq_domain_ops = { 437 + .map = adnp_irq_map, 438 + .xlate = irq_domain_xlate_twocell, 439 + }; 440 + 441 + static int adnp_irq_setup(struct adnp *adnp) 442 + { 443 + unsigned int num_regs = 1 << adnp->reg_shift, i; 444 + struct gpio_chip *chip = &adnp->gpio; 445 + int err; 446 + 447 + mutex_init(&adnp->irq_lock); 448 + 449 + /* 450 + * Allocate memory to keep track of the current level and trigger 451 + * modes of the interrupts. To avoid multiple allocations, a single 452 + * large buffer is allocated and pointers are setup to point at the 453 + * corresponding offsets. For consistency, the layout of the buffer 454 + * is chosen to match the register layout of the hardware in that 455 + * each segment contains the corresponding bits for all interrupts. 456 + */ 457 + adnp->irq_enable = devm_kzalloc(chip->dev, num_regs * 6, GFP_KERNEL); 458 + if (!adnp->irq_enable) 459 + return -ENOMEM; 460 + 461 + adnp->irq_level = adnp->irq_enable + (num_regs * 1); 462 + adnp->irq_rise = adnp->irq_enable + (num_regs * 2); 463 + adnp->irq_fall = adnp->irq_enable + (num_regs * 3); 464 + adnp->irq_high = adnp->irq_enable + (num_regs * 4); 465 + adnp->irq_low = adnp->irq_enable + (num_regs * 5); 466 + 467 + for (i = 0; i < num_regs; i++) { 468 + /* 469 + * Read the initial level of all pins to allow the emulation 470 + * of edge triggered interrupts. 471 + */ 472 + err = adnp_read(adnp, GPIO_PLR(adnp) + i, &adnp->irq_level[i]); 473 + if (err < 0) 474 + return err; 475 + 476 + /* disable all interrupts */ 477 + err = adnp_write(adnp, GPIO_IER(adnp) + i, 0); 478 + if (err < 0) 479 + return err; 480 + 481 + adnp->irq_enable[i] = 0x00; 482 + } 483 + 484 + adnp->domain = irq_domain_add_linear(chip->of_node, chip->ngpio, 485 + &adnp_irq_domain_ops, adnp); 486 + 487 + err = request_threaded_irq(adnp->client->irq, NULL, adnp_irq, 488 + IRQF_TRIGGER_RISING | IRQF_ONESHOT, 489 + dev_name(chip->dev), adnp); 490 + if (err != 0) { 491 + dev_err(chip->dev, "can't request IRQ#%d: %d\n", 492 + adnp->client->irq, err); 493 + goto error; 494 + } 495 + 496 + chip->to_irq = adnp_gpio_to_irq; 497 + return 0; 498 + 499 + error: 500 + irq_domain_remove(adnp->domain); 501 + return err; 502 + } 503 + 504 + static void adnp_irq_teardown(struct adnp *adnp) 505 + { 506 + unsigned int irq, i; 507 + 508 + free_irq(adnp->client->irq, adnp); 509 + 510 + for (i = 0; i < adnp->gpio.ngpio; i++) { 511 + irq = irq_find_mapping(adnp->domain, i); 512 + if (irq > 0) 513 + irq_dispose_mapping(irq); 514 + } 515 + 516 + irq_domain_remove(adnp->domain); 517 + } 518 + 519 + static __devinit int adnp_i2c_probe(struct i2c_client *client, 520 + const struct i2c_device_id *id) 521 + { 522 + struct device_node *np = client->dev.of_node; 523 + struct adnp *adnp; 524 + u32 num_gpios; 525 + int err; 526 + 527 + err = of_property_read_u32(np, "nr-gpios", &num_gpios); 528 + if (err < 0) 529 + return err; 530 + 531 + client->irq = irq_of_parse_and_map(np, 0); 532 + if (!client->irq) 533 + return -EPROBE_DEFER; 534 + 535 + adnp = devm_kzalloc(&client->dev, sizeof(*adnp), GFP_KERNEL); 536 + if (!adnp) 537 + return -ENOMEM; 538 + 539 + mutex_init(&adnp->i2c_lock); 540 + adnp->client = client; 541 + 542 + err = adnp_gpio_setup(adnp, num_gpios); 543 + if (err < 0) 544 + return err; 545 + 546 + if (of_find_property(np, "interrupt-controller", NULL)) { 547 + err = adnp_irq_setup(adnp); 548 + if (err < 0) 549 + goto teardown; 550 + } 551 + 552 + err = gpiochip_add(&adnp->gpio); 553 + if (err < 0) 554 + goto teardown; 555 + 556 + i2c_set_clientdata(client, adnp); 557 + return 0; 558 + 559 + teardown: 560 + if (of_find_property(np, "interrupt-controller", NULL)) 561 + adnp_irq_teardown(adnp); 562 + 563 + return err; 564 + } 565 + 566 + static __devexit int adnp_i2c_remove(struct i2c_client *client) 567 + { 568 + struct adnp *adnp = i2c_get_clientdata(client); 569 + struct device_node *np = client->dev.of_node; 570 + int err; 571 + 572 + err = gpiochip_remove(&adnp->gpio); 573 + if (err < 0) { 574 + dev_err(&client->dev, "%s failed: %d\n", "gpiochip_remove()", 575 + err); 576 + return err; 577 + } 578 + 579 + if (of_find_property(np, "interrupt-controller", NULL)) 580 + adnp_irq_teardown(adnp); 581 + 582 + return 0; 583 + } 584 + 585 + static const struct i2c_device_id adnp_i2c_id[] __devinitconst = { 586 + { "gpio-adnp" }, 587 + { }, 588 + }; 589 + MODULE_DEVICE_TABLE(i2c, adnp_i2c_id); 590 + 591 + static const struct of_device_id adnp_of_match[] __devinitconst = { 592 + { .compatible = "ad,gpio-adnp", }, 593 + { }, 594 + }; 595 + MODULE_DEVICE_TABLE(of, adnp_of_match); 596 + 597 + static struct i2c_driver adnp_i2c_driver = { 598 + .driver = { 599 + .name = "gpio-adnp", 600 + .owner = THIS_MODULE, 601 + .of_match_table = of_match_ptr(adnp_of_match), 602 + }, 603 + .probe = adnp_i2c_probe, 604 + .remove = __devexit_p(adnp_i2c_remove), 605 + .id_table = adnp_i2c_id, 606 + }; 607 + module_i2c_driver(adnp_i2c_driver); 608 + 609 + MODULE_DESCRIPTION("Avionic Design N-bit GPIO expander"); 610 + MODULE_AUTHOR("Thierry Reding <thierry.reding@avionic-design.de>"); 611 + MODULE_LICENSE("GPL");
+1 -13
drivers/gpio/gpio-adp5588.c
··· 483 483 .id_table = adp5588_gpio_id, 484 484 }; 485 485 486 - static int __init adp5588_gpio_init(void) 487 - { 488 - return i2c_add_driver(&adp5588_gpio_driver); 489 - } 490 - 491 - module_init(adp5588_gpio_init); 492 - 493 - static void __exit adp5588_gpio_exit(void) 494 - { 495 - i2c_del_driver(&adp5588_gpio_driver); 496 - } 497 - 498 - module_exit(adp5588_gpio_exit); 486 + module_i2c_driver(adp5588_gpio_driver); 499 487 500 488 MODULE_AUTHOR("Michael Hennerich <hennerich@blackfin.uclinux.org>"); 501 489 MODULE_DESCRIPTION("GPIO ADP5588 Driver");
+1 -1
drivers/gpio/gpio-bt8xx.c
··· 310 310 #define bt8xxgpio_resume NULL 311 311 #endif /* CONFIG_PM */ 312 312 313 - static struct pci_device_id bt8xxgpio_pci_tbl[] = { 313 + static DEFINE_PCI_DEVICE_TABLE(bt8xxgpio_pci_tbl) = { 314 314 { PCI_DEVICE(PCI_VENDOR_ID_BROOKTREE, PCI_DEVICE_ID_BT848) }, 315 315 { PCI_DEVICE(PCI_VENDOR_ID_BROOKTREE, PCI_DEVICE_ID_BT849) }, 316 316 { PCI_DEVICE(PCI_VENDOR_ID_BROOKTREE, PCI_DEVICE_ID_BT878) },
+3 -12
drivers/gpio/gpio-da9052.c
··· 207 207 struct da9052_pdata *pdata; 208 208 int ret; 209 209 210 - gpio = kzalloc(sizeof(*gpio), GFP_KERNEL); 210 + gpio = devm_kzalloc(&pdev->dev, sizeof(*gpio), GFP_KERNEL); 211 211 if (gpio == NULL) 212 212 return -ENOMEM; 213 213 ··· 221 221 ret = gpiochip_add(&gpio->gp); 222 222 if (ret < 0) { 223 223 dev_err(&pdev->dev, "Could not register gpiochip, %d\n", ret); 224 - goto err_mem; 224 + return ret; 225 225 } 226 226 227 227 platform_set_drvdata(pdev, gpio); 228 228 229 229 return 0; 230 - 231 - err_mem: 232 - kfree(gpio); 233 - return ret; 234 230 } 235 231 236 232 static int __devexit da9052_gpio_remove(struct platform_device *pdev) 237 233 { 238 234 struct da9052_gpio *gpio = platform_get_drvdata(pdev); 239 - int ret; 240 235 241 - ret = gpiochip_remove(&gpio->gp); 242 - if (ret == 0) 243 - kfree(gpio); 244 - 245 - return ret; 236 + return gpiochip_remove(&gpio->gp); 246 237 } 247 238 248 239 static struct platform_driver da9052_gpio_driver = {
+1 -1
drivers/gpio/gpio-davinci.c
··· 366 366 PTR_ERR(clk)); 367 367 return PTR_ERR(clk); 368 368 } 369 - clk_enable(clk); 369 + clk_prepare_enable(clk); 370 370 371 371 /* Arrange gpio_to_irq() support, handling either direct IRQs or 372 372 * banked IRQs. Having GPIOs in the first GPIO bank use direct
+3 -9
drivers/gpio/gpio-em.c
··· 85 85 iowrite32(value, p->base1 + (offs - GIO_IDT0)); 86 86 } 87 87 88 - static inline struct em_gio_priv *irq_to_priv(struct irq_data *d) 89 - { 90 - struct irq_chip *chip = irq_data_get_irq_chip(d); 91 - return container_of(chip, struct em_gio_priv, irq_chip); 92 - } 93 - 94 88 static void em_gio_irq_disable(struct irq_data *d) 95 89 { 96 - struct em_gio_priv *p = irq_to_priv(d); 90 + struct em_gio_priv *p = irq_data_get_irq_chip_data(d); 97 91 98 92 em_gio_write(p, GIO_IDS, BIT(irqd_to_hwirq(d))); 99 93 } 100 94 101 95 static void em_gio_irq_enable(struct irq_data *d) 102 96 { 103 - struct em_gio_priv *p = irq_to_priv(d); 97 + struct em_gio_priv *p = irq_data_get_irq_chip_data(d); 104 98 105 99 em_gio_write(p, GIO_IEN, BIT(irqd_to_hwirq(d))); 106 100 } ··· 112 118 static int em_gio_irq_set_type(struct irq_data *d, unsigned int type) 113 119 { 114 120 unsigned char value = em_gio_sense_table[type & IRQ_TYPE_SENSE_MASK]; 115 - struct em_gio_priv *p = irq_to_priv(d); 121 + struct em_gio_priv *p = irq_data_get_irq_chip_data(d); 116 122 unsigned int reg, offset, shift; 117 123 unsigned long flags; 118 124 unsigned long tmp;
+2 -1
drivers/gpio/gpio-lpc32xx.c
··· 113 113 NULL, NULL, NULL, "gpi15", 114 114 "gpi16", "gpi17", "gpi18", "gpi19", 115 115 "gpi20", "gpi21", "gpi22", "gpi23", 116 - "gpi24", "gpi25", "gpi26", "gpi27" 116 + "gpi24", "gpi25", "gpi26", "gpi27", 117 + "gpi28" 117 118 }; 118 119 119 120 static const char *gpo_p3_names[LPC32XX_GPO_P3_MAX] = {
+3 -18
drivers/gpio/gpio-mc9s08dz60.c
··· 91 91 static int mc9s08dz60_probe(struct i2c_client *client, 92 92 const struct i2c_device_id *id) 93 93 { 94 - int ret = 0; 95 94 struct mc9s08dz60 *mc9s; 96 95 97 - mc9s = kzalloc(sizeof(*mc9s), GFP_KERNEL); 96 + mc9s = devm_kzalloc(&client->dev, sizeof(*mc9s), GFP_KERNEL); 98 97 if (!mc9s) 99 98 return -ENOMEM; 100 99 ··· 109 110 mc9s->client = client; 110 111 i2c_set_clientdata(client, mc9s); 111 112 112 - ret = gpiochip_add(&mc9s->chip); 113 - if (ret) 114 - goto error; 115 - 116 - return 0; 117 - 118 - error: 119 - kfree(mc9s); 120 - return ret; 113 + return gpiochip_add(&mc9s->chip); 121 114 } 122 115 123 116 static int mc9s08dz60_remove(struct i2c_client *client) 124 117 { 125 118 struct mc9s08dz60 *mc9s; 126 - int ret; 127 119 128 120 mc9s = i2c_get_clientdata(client); 129 121 130 - ret = gpiochip_remove(&mc9s->chip); 131 - if (!ret) 132 - kfree(mc9s); 133 - 134 - return ret; 135 - 122 + return gpiochip_remove(&mc9s->chip); 136 123 } 137 124 138 125 static const struct i2c_device_id mc9s08dz60_id[] = {
+10 -10
drivers/gpio/gpio-ml-ioh.c
··· 87 87 * @gpio_use_sel: Save GPIO_USE_SEL1~4 register for PM 88 88 * @ch: Indicate GPIO channel 89 89 * @irq_base: Save base of IRQ number for interrupt 90 - * @spinlock: Used for register access protection in 91 - * interrupt context ioh_irq_type and PM; 90 + * @spinlock: Used for register access protection 92 91 */ 93 92 struct ioh_gpio { 94 93 void __iomem *base; ··· 96 97 struct gpio_chip gpio; 97 98 struct ioh_gpio_reg_data ioh_gpio_reg; 98 99 u32 gpio_use_sel; 99 - struct mutex lock; 100 100 int ch; 101 101 int irq_base; 102 102 spinlock_t spinlock; ··· 107 109 { 108 110 u32 reg_val; 109 111 struct ioh_gpio *chip = container_of(gpio, struct ioh_gpio, gpio); 112 + unsigned long flags; 110 113 111 - mutex_lock(&chip->lock); 114 + spin_lock_irqsave(&chip->spinlock, flags); 112 115 reg_val = ioread32(&chip->reg->regs[chip->ch].po); 113 116 if (val) 114 117 reg_val |= (1 << nr); ··· 117 118 reg_val &= ~(1 << nr); 118 119 119 120 iowrite32(reg_val, &chip->reg->regs[chip->ch].po); 120 - mutex_unlock(&chip->lock); 121 + spin_unlock_irqrestore(&chip->spinlock, flags); 121 122 } 122 123 123 124 static int ioh_gpio_get(struct gpio_chip *gpio, unsigned nr) ··· 133 134 struct ioh_gpio *chip = container_of(gpio, struct ioh_gpio, gpio); 134 135 u32 pm; 135 136 u32 reg_val; 137 + unsigned long flags; 136 138 137 - mutex_lock(&chip->lock); 139 + spin_lock_irqsave(&chip->spinlock, flags); 138 140 pm = ioread32(&chip->reg->regs[chip->ch].pm) & 139 141 ((1 << num_ports[chip->ch]) - 1); 140 142 pm |= (1 << nr); ··· 148 148 reg_val &= ~(1 << nr); 149 149 iowrite32(reg_val, &chip->reg->regs[chip->ch].po); 150 150 151 - mutex_unlock(&chip->lock); 151 + spin_unlock_irqrestore(&chip->spinlock, flags); 152 152 153 153 return 0; 154 154 } ··· 157 157 { 158 158 struct ioh_gpio *chip = container_of(gpio, struct ioh_gpio, gpio); 159 159 u32 pm; 160 + unsigned long flags; 160 161 161 - mutex_lock(&chip->lock); 162 + spin_lock_irqsave(&chip->spinlock, flags); 162 163 pm = ioread32(&chip->reg->regs[chip->ch].pm) & 163 164 ((1 << num_ports[chip->ch]) - 1); 164 165 pm &= ~(1 << nr); 165 166 iowrite32(pm, &chip->reg->regs[chip->ch].pm); 166 - mutex_unlock(&chip->lock); 167 + spin_unlock_irqrestore(&chip->spinlock, flags); 167 168 168 169 return 0; 169 170 } ··· 448 447 chip->base = base; 449 448 chip->reg = chip->base; 450 449 chip->ch = i; 451 - mutex_init(&chip->lock); 452 450 spin_lock_init(&chip->spinlock); 453 451 ioh_gpio_setup(chip, num_ports[i]); 454 452 ret = gpiochip_add(&chip->gpio);
+1 -3
drivers/gpio/gpio-msm-v2.c
··· 317 317 318 318 chained_irq_enter(chip, desc); 319 319 320 - for (i = find_first_bit(msm_gpio.enabled_irqs, NR_GPIO_IRQS); 321 - i < NR_GPIO_IRQS; 322 - i = find_next_bit(msm_gpio.enabled_irqs, NR_GPIO_IRQS, i + 1)) { 320 + for_each_set_bit(i, msm_gpio.enabled_irqs, NR_GPIO_IRQS) { 323 321 if (readl(GPIO_INTR_STATUS(i)) & BIT(INTR_STATUS)) 324 322 generic_handle_irq(msm_gpio_to_irq(&msm_gpio.gpio_chip, 325 323 i));
+122
drivers/gpio/gpio-pcf857x.c
··· 23 23 #include <linux/gpio.h> 24 24 #include <linux/i2c.h> 25 25 #include <linux/i2c/pcf857x.h> 26 + #include <linux/interrupt.h> 27 + #include <linux/irq.h> 28 + #include <linux/irqdomain.h> 26 29 #include <linux/module.h> 30 + #include <linux/spinlock.h> 31 + #include <linux/workqueue.h> 27 32 28 33 29 34 static const struct i2c_device_id pcf857x_id[] = { ··· 65 60 struct gpio_chip chip; 66 61 struct i2c_client *client; 67 62 struct mutex lock; /* protect 'out' */ 63 + struct work_struct work; /* irq demux work */ 64 + struct irq_domain *irq_domain; /* for irq demux */ 65 + spinlock_t slock; /* protect irq demux */ 68 66 unsigned out; /* software latch */ 67 + unsigned status; /* current status */ 68 + int irq; /* real irq number */ 69 69 70 70 int (*write)(struct i2c_client *client, unsigned data); 71 71 int (*read)(struct i2c_client *client); ··· 160 150 161 151 /*-------------------------------------------------------------------------*/ 162 152 153 + static int pcf857x_to_irq(struct gpio_chip *chip, unsigned offset) 154 + { 155 + struct pcf857x *gpio = container_of(chip, struct pcf857x, chip); 156 + 157 + return irq_create_mapping(gpio->irq_domain, offset); 158 + } 159 + 160 + static void pcf857x_irq_demux_work(struct work_struct *work) 161 + { 162 + struct pcf857x *gpio = container_of(work, 163 + struct pcf857x, 164 + work); 165 + unsigned long change, i, status, flags; 166 + 167 + status = gpio->read(gpio->client); 168 + 169 + spin_lock_irqsave(&gpio->slock, flags); 170 + 171 + change = gpio->status ^ status; 172 + for_each_set_bit(i, &change, gpio->chip.ngpio) 173 + generic_handle_irq(irq_find_mapping(gpio->irq_domain, i)); 174 + gpio->status = status; 175 + 176 + spin_unlock_irqrestore(&gpio->slock, flags); 177 + } 178 + 179 + static irqreturn_t pcf857x_irq_demux(int irq, void *data) 180 + { 181 + struct pcf857x *gpio = data; 182 + 183 + /* 184 + * pcf857x can't read/write data here, 185 + * since i2c data access might go to sleep. 186 + */ 187 + schedule_work(&gpio->work); 188 + 189 + return IRQ_HANDLED; 190 + } 191 + 192 + static int pcf857x_irq_domain_map(struct irq_domain *domain, unsigned int virq, 193 + irq_hw_number_t hw) 194 + { 195 + irq_set_chip_and_handler(virq, 196 + &dummy_irq_chip, 197 + handle_level_irq); 198 + return 0; 199 + } 200 + 201 + static struct irq_domain_ops pcf857x_irq_domain_ops = { 202 + .map = pcf857x_irq_domain_map, 203 + }; 204 + 205 + static void pcf857x_irq_domain_cleanup(struct pcf857x *gpio) 206 + { 207 + if (gpio->irq_domain) 208 + irq_domain_remove(gpio->irq_domain); 209 + 210 + if (gpio->irq) 211 + free_irq(gpio->irq, gpio); 212 + } 213 + 214 + static int pcf857x_irq_domain_init(struct pcf857x *gpio, 215 + struct pcf857x_platform_data *pdata, 216 + struct device *dev) 217 + { 218 + int status; 219 + 220 + gpio->irq_domain = irq_domain_add_linear(dev->of_node, 221 + gpio->chip.ngpio, 222 + &pcf857x_irq_domain_ops, 223 + NULL); 224 + if (!gpio->irq_domain) 225 + goto fail; 226 + 227 + /* enable real irq */ 228 + status = request_irq(pdata->irq, pcf857x_irq_demux, 0, 229 + dev_name(dev), gpio); 230 + if (status) 231 + goto fail; 232 + 233 + /* enable gpio_to_irq() */ 234 + INIT_WORK(&gpio->work, pcf857x_irq_demux_work); 235 + gpio->chip.to_irq = pcf857x_to_irq; 236 + gpio->irq = pdata->irq; 237 + 238 + return 0; 239 + 240 + fail: 241 + pcf857x_irq_domain_cleanup(gpio); 242 + return -EINVAL; 243 + } 244 + 245 + /*-------------------------------------------------------------------------*/ 246 + 163 247 static int pcf857x_probe(struct i2c_client *client, 164 248 const struct i2c_device_id *id) 165 249 { ··· 272 168 return -ENOMEM; 273 169 274 170 mutex_init(&gpio->lock); 171 + spin_lock_init(&gpio->slock); 275 172 276 173 gpio->chip.base = pdata ? pdata->gpio_base : -1; 277 174 gpio->chip.can_sleep = 1; ··· 283 178 gpio->chip.direction_input = pcf857x_input; 284 179 gpio->chip.direction_output = pcf857x_output; 285 180 gpio->chip.ngpio = id->driver_data; 181 + 182 + /* enable gpio_to_irq() if platform has settings */ 183 + if (pdata && pdata->irq) { 184 + status = pcf857x_irq_domain_init(gpio, pdata, &client->dev); 185 + if (status < 0) { 186 + dev_err(&client->dev, "irq_domain init failed\n"); 187 + goto fail; 188 + } 189 + } 286 190 287 191 /* NOTE: the OnSemi jlc1562b is also largely compatible with 288 192 * these parts, notably for output. It has a low-resolution ··· 362 248 * all-ones reset state. Otherwise it flags pins to be driven low. 363 249 */ 364 250 gpio->out = pdata ? ~pdata->n_latch : ~0; 251 + gpio->status = gpio->out; 365 252 366 253 status = gpiochip_add(&gpio->chip); 367 254 if (status < 0) ··· 393 278 fail: 394 279 dev_dbg(&client->dev, "probe error %d for '%s'\n", 395 280 status, client->name); 281 + 282 + if (pdata && pdata->irq) 283 + pcf857x_irq_domain_cleanup(gpio); 284 + 396 285 kfree(gpio); 397 286 return status; 398 287 } ··· 417 298 return status; 418 299 } 419 300 } 301 + 302 + if (pdata && pdata->irq) 303 + pcf857x_irq_domain_cleanup(gpio); 420 304 421 305 status = gpiochip_remove(&gpio->chip); 422 306 if (status == 0)
+10 -12
drivers/gpio/gpio-pch.c
··· 92 92 * @lock: Used for register access protection 93 93 * @irq_base: Save base of IRQ number for interrupt 94 94 * @ioh: IOH ID 95 - * @spinlock: Used for register access protection in 96 - * interrupt context pch_irq_mask, 97 - * pch_irq_unmask and pch_irq_type; 95 + * @spinlock: Used for register access protection 98 96 */ 99 97 struct pch_gpio { 100 98 void __iomem *base; ··· 100 102 struct device *dev; 101 103 struct gpio_chip gpio; 102 104 struct pch_gpio_reg_data pch_gpio_reg; 103 - struct mutex lock; 104 105 int irq_base; 105 106 enum pch_type_t ioh; 106 107 spinlock_t spinlock; ··· 109 112 { 110 113 u32 reg_val; 111 114 struct pch_gpio *chip = container_of(gpio, struct pch_gpio, gpio); 115 + unsigned long flags; 112 116 113 - mutex_lock(&chip->lock); 117 + spin_lock_irqsave(&chip->spinlock, flags); 114 118 reg_val = ioread32(&chip->reg->po); 115 119 if (val) 116 120 reg_val |= (1 << nr); ··· 119 121 reg_val &= ~(1 << nr); 120 122 121 123 iowrite32(reg_val, &chip->reg->po); 122 - mutex_unlock(&chip->lock); 124 + spin_unlock_irqrestore(&chip->spinlock, flags); 123 125 } 124 126 125 127 static int pch_gpio_get(struct gpio_chip *gpio, unsigned nr) ··· 135 137 struct pch_gpio *chip = container_of(gpio, struct pch_gpio, gpio); 136 138 u32 pm; 137 139 u32 reg_val; 140 + unsigned long flags; 138 141 139 - mutex_lock(&chip->lock); 142 + spin_lock_irqsave(&chip->spinlock, flags); 140 143 pm = ioread32(&chip->reg->pm) & ((1 << gpio_pins[chip->ioh]) - 1); 141 144 pm |= (1 << nr); 142 145 iowrite32(pm, &chip->reg->pm); ··· 148 149 else 149 150 reg_val &= ~(1 << nr); 150 151 iowrite32(reg_val, &chip->reg->po); 151 - 152 - mutex_unlock(&chip->lock); 152 + spin_unlock_irqrestore(&chip->spinlock, flags); 153 153 154 154 return 0; 155 155 } ··· 157 159 { 158 160 struct pch_gpio *chip = container_of(gpio, struct pch_gpio, gpio); 159 161 u32 pm; 162 + unsigned long flags; 160 163 161 - mutex_lock(&chip->lock); 164 + spin_lock_irqsave(&chip->spinlock, flags); 162 165 pm = ioread32(&chip->reg->pm) & ((1 << gpio_pins[chip->ioh]) - 1); 163 166 pm &= ~(1 << nr); 164 167 iowrite32(pm, &chip->reg->pm); 165 - mutex_unlock(&chip->lock); 168 + spin_unlock_irqrestore(&chip->spinlock, flags); 166 169 167 170 return 0; 168 171 } ··· 386 387 387 388 chip->reg = chip->base; 388 389 pci_set_drvdata(pdev, chip); 389 - mutex_init(&chip->lock); 390 390 spin_lock_init(&chip->spinlock); 391 391 pch_gpio_setup(chip); 392 392 ret = gpiochip_add(&chip->gpio);
+2 -11
drivers/gpio/gpio-pxa.c
··· 370 370 gedr = gedr & c->irq_mask; 371 371 writel_relaxed(gedr, c->regbase + GEDR_OFFSET); 372 372 373 - n = find_first_bit(&gedr, BITS_PER_LONG); 374 - while (n < BITS_PER_LONG) { 373 + for_each_set_bit(n, &gedr, BITS_PER_LONG) { 375 374 loop = 1; 376 375 377 376 generic_handle_irq(gpio_to_irq(gpio_base + n)); 378 - n = find_next_bit(&gedr, BITS_PER_LONG, n + 1); 379 377 } 380 378 } 381 379 } while (loop); ··· 587 589 iounmap(gpio_reg_base); 588 590 return PTR_ERR(clk); 589 591 } 590 - ret = clk_prepare(clk); 592 + ret = clk_prepare_enable(clk); 591 593 if (ret) { 592 - clk_put(clk); 593 - iounmap(gpio_reg_base); 594 - return ret; 595 - } 596 - ret = clk_enable(clk); 597 - if (ret) { 598 - clk_unprepare(clk); 599 594 clk_put(clk); 600 595 iounmap(gpio_reg_base); 601 596 return ret;
+1 -1
drivers/gpio/gpio-sodaville.c
··· 270 270 kfree(sd); 271 271 } 272 272 273 - static struct pci_device_id sdv_gpio_pci_ids[] __devinitdata = { 273 + static DEFINE_PCI_DEVICE_TABLE(sdv_gpio_pci_ids) = { 274 274 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_SDV_GPIO) }, 275 275 { 0, }, 276 276 };
+6 -18
drivers/gpio/gpio-sx150x.c
··· 311 311 312 312 static void sx150x_irq_mask(struct irq_data *d) 313 313 { 314 - struct irq_chip *ic = irq_data_get_irq_chip(d); 315 - struct sx150x_chip *chip; 314 + struct sx150x_chip *chip = irq_data_get_irq_chip_data(d); 316 315 unsigned n; 317 316 318 - chip = container_of(ic, struct sx150x_chip, irq_chip); 319 317 n = d->irq - chip->irq_base; 320 318 chip->irq_masked |= (1 << n); 321 319 chip->irq_update = n; ··· 321 323 322 324 static void sx150x_irq_unmask(struct irq_data *d) 323 325 { 324 - struct irq_chip *ic = irq_data_get_irq_chip(d); 325 - struct sx150x_chip *chip; 326 + struct sx150x_chip *chip = irq_data_get_irq_chip_data(d); 326 327 unsigned n; 327 328 328 - chip = container_of(ic, struct sx150x_chip, irq_chip); 329 329 n = d->irq - chip->irq_base; 330 - 331 330 chip->irq_masked &= ~(1 << n); 332 331 chip->irq_update = n; 333 332 } 334 333 335 334 static int sx150x_irq_set_type(struct irq_data *d, unsigned int flow_type) 336 335 { 337 - struct irq_chip *ic = irq_data_get_irq_chip(d); 338 - struct sx150x_chip *chip; 336 + struct sx150x_chip *chip = irq_data_get_irq_chip_data(d); 339 337 unsigned n, val = 0; 340 338 341 339 if (flow_type & (IRQ_TYPE_LEVEL_HIGH | IRQ_TYPE_LEVEL_LOW)) 342 340 return -EINVAL; 343 341 344 - chip = container_of(ic, struct sx150x_chip, irq_chip); 345 342 n = d->irq - chip->irq_base; 346 343 347 344 if (flow_type & IRQ_TYPE_EDGE_RISING) ··· 384 391 385 392 static void sx150x_irq_bus_lock(struct irq_data *d) 386 393 { 387 - struct irq_chip *ic = irq_data_get_irq_chip(d); 388 - struct sx150x_chip *chip; 389 - 390 - chip = container_of(ic, struct sx150x_chip, irq_chip); 394 + struct sx150x_chip *chip = irq_data_get_irq_chip_data(d); 391 395 392 396 mutex_lock(&chip->lock); 393 397 } 394 398 395 399 static void sx150x_irq_bus_sync_unlock(struct irq_data *d) 396 400 { 397 - struct irq_chip *ic = irq_data_get_irq_chip(d); 398 - struct sx150x_chip *chip; 401 + struct sx150x_chip *chip = irq_data_get_irq_chip_data(d); 399 402 unsigned n; 400 - 401 - chip = container_of(ic, struct sx150x_chip, irq_chip); 402 403 403 404 if (chip->irq_update == NO_UPDATE_PENDING) 404 405 goto out; ··· 538 551 539 552 for (n = 0; n < chip->dev_cfg->ngpios; ++n) { 540 553 irq = irq_base + n; 554 + irq_set_chip_data(irq, chip); 541 555 irq_set_chip_and_handler(irq, &chip->irq_chip, handle_edge_irq); 542 556 irq_set_nested_thread(irq, 1); 543 557 #ifdef CONFIG_ARM
+85 -35
drivers/gpio/gpio-tc3589x.c
··· 11 11 #include <linux/platform_device.h> 12 12 #include <linux/slab.h> 13 13 #include <linux/gpio.h> 14 + #include <linux/of.h> 14 15 #include <linux/irq.h> 16 + #include <linux/irqdomain.h> 15 17 #include <linux/interrupt.h> 16 18 #include <linux/mfd/tc3589x.h> 17 19 ··· 31 29 struct tc3589x *tc3589x; 32 30 struct device *dev; 33 31 struct mutex irq_lock; 32 + struct irq_domain *domain; 34 33 35 34 int irq_base; 36 35 ··· 95 92 return tc3589x_set_bits(tc3589x, reg, 1 << pos, 0); 96 93 } 97 94 95 + /** 96 + * tc3589x_gpio_irq_get_virq(): Map an interrupt on a chip to a virtual IRQ 97 + * 98 + * @tc3589x_gpio: tc3589x_gpio_irq controller to operate on. 99 + * @irq: index of the interrupt requested in the chip IRQs 100 + * 101 + * Useful for drivers to request their own IRQs. 102 + */ 103 + static int tc3589x_gpio_irq_get_virq(struct tc3589x_gpio *tc3589x_gpio, 104 + int irq) 105 + { 106 + if (!tc3589x_gpio) 107 + return -EINVAL; 108 + 109 + return irq_create_mapping(tc3589x_gpio->domain, irq); 110 + } 111 + 98 112 static int tc3589x_gpio_to_irq(struct gpio_chip *chip, unsigned offset) 99 113 { 100 114 struct tc3589x_gpio *tc3589x_gpio = to_tc3589x_gpio(chip); 101 115 102 - return tc3589x_gpio->irq_base + offset; 116 + return tc3589x_gpio_irq_get_virq(tc3589x_gpio, offset); 103 117 } 104 118 105 119 static struct gpio_chip template_chip = { ··· 133 113 static int tc3589x_gpio_irq_set_type(struct irq_data *d, unsigned int type) 134 114 { 135 115 struct tc3589x_gpio *tc3589x_gpio = irq_data_get_irq_chip_data(d); 136 - int offset = d->irq - tc3589x_gpio->irq_base; 116 + int offset = d->hwirq; 137 117 int regoffset = offset / 8; 138 118 int mask = 1 << (offset % 8); 139 119 ··· 195 175 static void tc3589x_gpio_irq_mask(struct irq_data *d) 196 176 { 197 177 struct tc3589x_gpio *tc3589x_gpio = irq_data_get_irq_chip_data(d); 198 - int offset = d->irq - tc3589x_gpio->irq_base; 178 + int offset = d->hwirq; 199 179 int regoffset = offset / 8; 200 180 int mask = 1 << (offset % 8); 201 181 ··· 205 185 static void tc3589x_gpio_irq_unmask(struct irq_data *d) 206 186 { 207 187 struct tc3589x_gpio *tc3589x_gpio = irq_data_get_irq_chip_data(d); 208 - int offset = d->irq - tc3589x_gpio->irq_base; 188 + int offset = d->hwirq; 209 189 int regoffset = offset / 8; 210 190 int mask = 1 << (offset % 8); 211 191 ··· 242 222 while (stat) { 243 223 int bit = __ffs(stat); 244 224 int line = i * 8 + bit; 225 + int virq = tc3589x_gpio_irq_get_virq(tc3589x_gpio, line); 245 226 246 - handle_nested_irq(tc3589x_gpio->irq_base + line); 227 + handle_nested_irq(virq); 247 228 stat &= ~(1 << bit); 248 229 } 249 230 ··· 254 233 return IRQ_HANDLED; 255 234 } 256 235 257 - static int tc3589x_gpio_irq_init(struct tc3589x_gpio *tc3589x_gpio) 236 + static int tc3589x_gpio_irq_map(struct irq_domain *d, unsigned int virq, 237 + irq_hw_number_t hwirq) 258 238 { 259 - int base = tc3589x_gpio->irq_base; 260 - int irq; 239 + struct tc3589x *tc3589x_gpio = d->host_data; 261 240 262 - for (irq = base; irq < base + tc3589x_gpio->chip.ngpio; irq++) { 263 - irq_set_chip_data(irq, tc3589x_gpio); 264 - irq_set_chip_and_handler(irq, &tc3589x_gpio_irq_chip, 265 - handle_simple_irq); 266 - irq_set_nested_thread(irq, 1); 241 + irq_set_chip_data(virq, tc3589x_gpio); 242 + irq_set_chip_and_handler(virq, &tc3589x_gpio_irq_chip, 243 + handle_simple_irq); 244 + irq_set_nested_thread(virq, 1); 267 245 #ifdef CONFIG_ARM 268 - set_irq_flags(irq, IRQF_VALID); 246 + set_irq_flags(virq, IRQF_VALID); 269 247 #else 270 - irq_set_noprobe(irq); 248 + irq_set_noprobe(virq); 271 249 #endif 272 - } 273 250 274 251 return 0; 275 252 } 276 253 277 - static void tc3589x_gpio_irq_remove(struct tc3589x_gpio *tc3589x_gpio) 254 + static void tc3589x_gpio_irq_unmap(struct irq_domain *d, unsigned int virq) 255 + { 256 + #ifdef CONFIG_ARM 257 + set_irq_flags(virq, 0); 258 + #endif 259 + irq_set_chip_and_handler(virq, NULL, NULL); 260 + irq_set_chip_data(virq, NULL); 261 + } 262 + 263 + static struct irq_domain_ops tc3589x_irq_ops = { 264 + .map = tc3589x_gpio_irq_map, 265 + .unmap = tc3589x_gpio_irq_unmap, 266 + .xlate = irq_domain_xlate_twocell, 267 + }; 268 + 269 + static int tc3589x_gpio_irq_init(struct tc3589x_gpio *tc3589x_gpio, 270 + struct device_node *np) 278 271 { 279 272 int base = tc3589x_gpio->irq_base; 280 - int irq; 281 273 282 - for (irq = base; irq < base + tc3589x_gpio->chip.ngpio; irq++) { 283 - #ifdef CONFIG_ARM 284 - set_irq_flags(irq, 0); 285 - #endif 286 - irq_set_chip_and_handler(irq, NULL, NULL); 287 - irq_set_chip_data(irq, NULL); 274 + if (base) { 275 + tc3589x_gpio->domain = irq_domain_add_legacy( 276 + NULL, tc3589x_gpio->chip.ngpio, base, 277 + 0, &tc3589x_irq_ops, tc3589x_gpio); 288 278 } 279 + else { 280 + tc3589x_gpio->domain = irq_domain_add_linear( 281 + np, tc3589x_gpio->chip.ngpio, 282 + &tc3589x_irq_ops, tc3589x_gpio); 283 + } 284 + 285 + if (!tc3589x_gpio->domain) { 286 + dev_err(tc3589x_gpio->dev, "Failed to create irqdomain\n"); 287 + return -ENOSYS; 288 + } 289 + 290 + return 0; 289 291 } 290 292 291 293 static int __devinit tc3589x_gpio_probe(struct platform_device *pdev) 292 294 { 293 295 struct tc3589x *tc3589x = dev_get_drvdata(pdev->dev.parent); 294 296 struct tc3589x_gpio_platform_data *pdata; 297 + struct device_node *np = pdev->dev.of_node; 295 298 struct tc3589x_gpio *tc3589x_gpio; 296 299 int ret; 297 300 int irq; 298 301 299 302 pdata = tc3589x->pdata->gpio; 300 - if (!pdata) 301 - return -ENODEV; 303 + 304 + if (!(pdata || np)) { 305 + dev_err(&pdev->dev, "No platform data or Device Tree found\n"); 306 + return -EINVAL; 307 + } 302 308 303 309 irq = platform_get_irq(pdev, 0); 304 310 if (irq < 0) ··· 343 295 tc3589x_gpio->chip = template_chip; 344 296 tc3589x_gpio->chip.ngpio = tc3589x->num_gpio; 345 297 tc3589x_gpio->chip.dev = &pdev->dev; 346 - tc3589x_gpio->chip.base = pdata->gpio_base; 298 + tc3589x_gpio->chip.base = (pdata) ? pdata->gpio_base : -1; 347 299 348 - tc3589x_gpio->irq_base = tc3589x->irq_base + TC3589x_INT_GPIO(0); 300 + #ifdef CONFIG_OF_GPIO 301 + tc3589x_gpio->chip.of_node = np; 302 + #endif 303 + 304 + tc3589x_gpio->irq_base = tc3589x->irq_base ? 305 + tc3589x->irq_base + TC3589x_INT_GPIO(0) : 0; 349 306 350 307 /* Bring the GPIO module out of reset */ 351 308 ret = tc3589x_set_bits(tc3589x, TC3589x_RSTCTRL, ··· 358 305 if (ret < 0) 359 306 goto out_free; 360 307 361 - ret = tc3589x_gpio_irq_init(tc3589x_gpio); 308 + ret = tc3589x_gpio_irq_init(tc3589x_gpio, np); 362 309 if (ret) 363 310 goto out_free; 364 311 ··· 366 313 "tc3589x-gpio", tc3589x_gpio); 367 314 if (ret) { 368 315 dev_err(&pdev->dev, "unable to get irq: %d\n", ret); 369 - goto out_removeirq; 316 + goto out_free; 370 317 } 371 318 372 319 ret = gpiochip_add(&tc3589x_gpio->chip); ··· 375 322 goto out_freeirq; 376 323 } 377 324 378 - if (pdata->setup) 325 + if (pdata && pdata->setup) 379 326 pdata->setup(tc3589x, tc3589x_gpio->chip.base); 380 327 381 328 platform_set_drvdata(pdev, tc3589x_gpio); ··· 384 331 385 332 out_freeirq: 386 333 free_irq(irq, tc3589x_gpio); 387 - out_removeirq: 388 - tc3589x_gpio_irq_remove(tc3589x_gpio); 389 334 out_free: 390 335 kfree(tc3589x_gpio); 391 336 return ret; ··· 397 346 int irq = platform_get_irq(pdev, 0); 398 347 int ret; 399 348 400 - if (pdata->remove) 349 + if (pdata && pdata->remove) 401 350 pdata->remove(tc3589x, tc3589x_gpio->chip.base); 402 351 403 352 ret = gpiochip_remove(&tc3589x_gpio->chip); ··· 408 357 } 409 358 410 359 free_irq(irq, tc3589x_gpio); 411 - tc3589x_gpio_irq_remove(tc3589x_gpio); 412 360 413 361 platform_set_drvdata(pdev, NULL); 414 362 kfree(tc3589x_gpio);
+4 -13
drivers/gpio/gpio-tps65912.c
··· 70 70 71 71 return tps65912_clear_bits(tps65912, TPS65912_GPIO1 + offset, 72 72 GPIO_CFG_MASK); 73 - 74 73 } 75 74 76 75 static struct gpio_chip template_chip = { ··· 91 92 struct tps65912_gpio_data *tps65912_gpio; 92 93 int ret; 93 94 94 - tps65912_gpio = kzalloc(sizeof(*tps65912_gpio), GFP_KERNEL); 95 + tps65912_gpio = devm_kzalloc(&pdev->dev, sizeof(*tps65912_gpio), 96 + GFP_KERNEL); 95 97 if (tps65912_gpio == NULL) 96 98 return -ENOMEM; 97 99 ··· 105 105 ret = gpiochip_add(&tps65912_gpio->gpio_chip); 106 106 if (ret < 0) { 107 107 dev_err(&pdev->dev, "Failed to register gpiochip, %d\n", ret); 108 - goto err; 108 + return ret; 109 109 } 110 110 111 111 platform_set_drvdata(pdev, tps65912_gpio); 112 112 113 - return ret; 114 - 115 - err: 116 - kfree(tps65912_gpio); 117 113 return ret; 118 114 } 119 115 120 116 static int __devexit tps65912_gpio_remove(struct platform_device *pdev) 121 117 { 122 118 struct tps65912_gpio_data *tps65912_gpio = platform_get_drvdata(pdev); 123 - int ret; 124 119 125 - ret = gpiochip_remove(&tps65912_gpio->gpio_chip); 126 - if (ret == 0) 127 - kfree(tps65912_gpio); 128 - 129 - return ret; 120 + return gpiochip_remove(&tps65912_gpio->gpio_chip); 130 121 } 131 122 132 123 static struct platform_driver tps65912_gpio_driver = {
+5 -14
drivers/gpio/gpio-wm831x.c
··· 250 250 struct wm831x_gpio *wm831x_gpio; 251 251 int ret; 252 252 253 - wm831x_gpio = kzalloc(sizeof(*wm831x_gpio), GFP_KERNEL); 253 + wm831x_gpio = devm_kzalloc(&pdev->dev, sizeof(*wm831x_gpio), 254 + GFP_KERNEL); 254 255 if (wm831x_gpio == NULL) 255 256 return -ENOMEM; 256 257 ··· 266 265 267 266 ret = gpiochip_add(&wm831x_gpio->gpio_chip); 268 267 if (ret < 0) { 269 - dev_err(&pdev->dev, "Could not register gpiochip, %d\n", 270 - ret); 271 - goto err; 268 + dev_err(&pdev->dev, "Could not register gpiochip, %d\n", ret); 269 + return ret; 272 270 } 273 271 274 272 platform_set_drvdata(pdev, wm831x_gpio); 275 273 276 - return ret; 277 - 278 - err: 279 - kfree(wm831x_gpio); 280 274 return ret; 281 275 } 282 276 283 277 static int __devexit wm831x_gpio_remove(struct platform_device *pdev) 284 278 { 285 279 struct wm831x_gpio *wm831x_gpio = platform_get_drvdata(pdev); 286 - int ret; 287 280 288 - ret = gpiochip_remove(&wm831x_gpio->gpio_chip); 289 - if (ret == 0) 290 - kfree(wm831x_gpio); 291 - 292 - return ret; 281 + return gpiochip_remove(&wm831x_gpio->gpio_chip); 293 282 } 294 283 295 284 static struct platform_driver wm831x_gpio_driver = {
+5 -14
drivers/gpio/gpio-wm8350.c
··· 116 116 struct wm8350_gpio_data *wm8350_gpio; 117 117 int ret; 118 118 119 - wm8350_gpio = kzalloc(sizeof(*wm8350_gpio), GFP_KERNEL); 119 + wm8350_gpio = devm_kzalloc(&pdev->dev, sizeof(*wm8350_gpio), 120 + GFP_KERNEL); 120 121 if (wm8350_gpio == NULL) 121 122 return -ENOMEM; 122 123 ··· 132 131 133 132 ret = gpiochip_add(&wm8350_gpio->gpio_chip); 134 133 if (ret < 0) { 135 - dev_err(&pdev->dev, "Could not register gpiochip, %d\n", 136 - ret); 137 - goto err; 134 + dev_err(&pdev->dev, "Could not register gpiochip, %d\n", ret); 135 + return ret; 138 136 } 139 137 140 138 platform_set_drvdata(pdev, wm8350_gpio); 141 139 142 - return ret; 143 - 144 - err: 145 - kfree(wm8350_gpio); 146 140 return ret; 147 141 } 148 142 149 143 static int __devexit wm8350_gpio_remove(struct platform_device *pdev) 150 144 { 151 145 struct wm8350_gpio_data *wm8350_gpio = platform_get_drvdata(pdev); 152 - int ret; 153 146 154 - ret = gpiochip_remove(&wm8350_gpio->gpio_chip); 155 - if (ret == 0) 156 - kfree(wm8350_gpio); 157 - 158 - return ret; 147 + return gpiochip_remove(&wm8350_gpio->gpio_chip); 159 148 } 160 149 161 150 static struct platform_driver wm8350_gpio_driver = {
+74 -28
drivers/gpio/gpiolib.c
··· 1773 1773 } 1774 1774 } 1775 1775 1776 - static int gpiolib_show(struct seq_file *s, void *unused) 1776 + static void *gpiolib_seq_start(struct seq_file *s, loff_t *pos) 1777 1777 { 1778 - struct gpio_chip *chip = NULL; 1779 - unsigned gpio; 1780 - int started = 0; 1778 + struct gpio_chip *chip = NULL; 1779 + unsigned int gpio; 1780 + void *ret = NULL; 1781 + loff_t index = 0; 1781 1782 1782 1783 /* REVISIT this isn't locked against gpio_chip removal ... */ 1783 1784 1784 1785 for (gpio = 0; gpio_is_valid(gpio); gpio++) { 1785 - struct device *dev; 1786 - 1787 - if (chip == gpio_desc[gpio].chip) 1786 + if (gpio_desc[gpio].chip == chip) 1788 1787 continue; 1788 + 1789 1789 chip = gpio_desc[gpio].chip; 1790 1790 if (!chip) 1791 1791 continue; 1792 1792 1793 - seq_printf(s, "%sGPIOs %d-%d", 1794 - started ? "\n" : "", 1795 - chip->base, chip->base + chip->ngpio - 1); 1796 - dev = chip->dev; 1797 - if (dev) 1798 - seq_printf(s, ", %s/%s", 1799 - dev->bus ? dev->bus->name : "no-bus", 1800 - dev_name(dev)); 1801 - if (chip->label) 1802 - seq_printf(s, ", %s", chip->label); 1803 - if (chip->can_sleep) 1804 - seq_printf(s, ", can sleep"); 1805 - seq_printf(s, ":\n"); 1806 - 1807 - started = 1; 1808 - if (chip->dbg_show) 1809 - chip->dbg_show(s, chip); 1810 - else 1811 - gpiolib_dbg_show(s, chip); 1793 + if (index++ >= *pos) { 1794 + ret = chip; 1795 + break; 1796 + } 1812 1797 } 1798 + 1799 + s->private = ""; 1800 + 1801 + return ret; 1802 + } 1803 + 1804 + static void *gpiolib_seq_next(struct seq_file *s, void *v, loff_t *pos) 1805 + { 1806 + struct gpio_chip *chip = v; 1807 + unsigned int gpio; 1808 + void *ret = NULL; 1809 + 1810 + /* skip GPIOs provided by the current chip */ 1811 + for (gpio = chip->base + chip->ngpio; gpio_is_valid(gpio); gpio++) { 1812 + chip = gpio_desc[gpio].chip; 1813 + if (chip) { 1814 + ret = chip; 1815 + break; 1816 + } 1817 + } 1818 + 1819 + s->private = "\n"; 1820 + ++*pos; 1821 + 1822 + return ret; 1823 + } 1824 + 1825 + static void gpiolib_seq_stop(struct seq_file *s, void *v) 1826 + { 1827 + } 1828 + 1829 + static int gpiolib_seq_show(struct seq_file *s, void *v) 1830 + { 1831 + struct gpio_chip *chip = v; 1832 + struct device *dev; 1833 + 1834 + seq_printf(s, "%sGPIOs %d-%d", (char *)s->private, 1835 + chip->base, chip->base + chip->ngpio - 1); 1836 + dev = chip->dev; 1837 + if (dev) 1838 + seq_printf(s, ", %s/%s", dev->bus ? dev->bus->name : "no-bus", 1839 + dev_name(dev)); 1840 + if (chip->label) 1841 + seq_printf(s, ", %s", chip->label); 1842 + if (chip->can_sleep) 1843 + seq_printf(s, ", can sleep"); 1844 + seq_printf(s, ":\n"); 1845 + 1846 + if (chip->dbg_show) 1847 + chip->dbg_show(s, chip); 1848 + else 1849 + gpiolib_dbg_show(s, chip); 1850 + 1813 1851 return 0; 1814 1852 } 1815 1853 1854 + static const struct seq_operations gpiolib_seq_ops = { 1855 + .start = gpiolib_seq_start, 1856 + .next = gpiolib_seq_next, 1857 + .stop = gpiolib_seq_stop, 1858 + .show = gpiolib_seq_show, 1859 + }; 1860 + 1816 1861 static int gpiolib_open(struct inode *inode, struct file *file) 1817 1862 { 1818 - return single_open(file, gpiolib_show, NULL); 1863 + return seq_open(file, &gpiolib_seq_ops); 1819 1864 } 1820 1865 1821 1866 static const struct file_operations gpiolib_operations = { 1867 + .owner = THIS_MODULE, 1822 1868 .open = gpiolib_open, 1823 1869 .read = seq_read, 1824 1870 .llseek = seq_lseek, 1825 - .release = single_release, 1871 + .release = seq_release, 1826 1872 }; 1827 1873 1828 1874 static int __init gpiolib_debugfs_init(void)
+2
include/asm-generic/gpio.h
··· 60 60 * @get: returns value for signal "offset"; for output signals this 61 61 * returns either the value actually sensed, or zero 62 62 * @direction_output: configures signal "offset" as output, or returns error 63 + * @set_debounce: optional hook for setting debounce time for specified gpio in 64 + * interrupt triggered gpio chips 63 65 * @set: assigns output value for signal "offset" 64 66 * @to_irq: optional hook supporting non-static gpio_to_irq() mappings; 65 67 * implementation may not sleep
+3
include/linux/i2c/pcf857x.h
··· 10 10 * @setup: optional callback issued once the GPIOs are valid 11 11 * @teardown: optional callback issued before the GPIOs are invalidated 12 12 * @context: optional parameter passed to setup() and teardown() 13 + * @irq: optional interrupt number 13 14 * 14 15 * In addition to the I2C_BOARD_INFO() state appropriate to each chip, 15 16 * the i2c_board_info used with the pcf875x driver must provide its ··· 40 39 int gpio, unsigned ngpio, 41 40 void *context); 42 41 void *context; 42 + 43 + int irq; 43 44 }; 44 45 45 46 #endif /* __LINUX_PCF857X_H */