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

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
...

+1297 -659
+39
Documentation/devicetree/bindings/gpio/gpio-dsp-keystone.txt
··· 1 + Keystone 2 DSP GPIO controller bindings 2 + 3 + HOST OS userland running on ARM can send interrupts to DSP cores using 4 + the DSP GPIO controller IP. It provides 28 IRQ signals per each DSP core. 5 + This is one of the component used by the IPC mechanism used on Keystone SOCs. 6 + 7 + For example TCI6638K2K SoC has 8 DSP GPIO controllers: 8 + - 8 for C66x CorePacx CPUs 0-7 9 + 10 + Keystone 2 DSP GPIO controller has specific features: 11 + - each GPIO can be configured only as output pin; 12 + - setting GPIO value to 1 causes IRQ generation on target DSP core; 13 + - reading pin value returns 0 - if IRQ was handled or 1 - IRQ is still 14 + pending. 15 + 16 + Required Properties: 17 + - compatible: should be "ti,keystone-dsp-gpio" 18 + - ti,syscon-dev: phandle/offset pair. The phandle to syscon used to 19 + access device state control registers and the offset of device's specific 20 + registers within device state control registers range. 21 + - gpio-controller: Marks the device node as a gpio controller. 22 + - #gpio-cells: Should be 2. 23 + 24 + Please refer to gpio.txt in this directory for details of the common GPIO 25 + bindings used by client devices. 26 + 27 + Example: 28 + dspgpio0: keystone_dsp_gpio@02620240 { 29 + compatible = "ti,keystone-dsp-gpio"; 30 + ti,syscon-dev = <&devctrl 0x240>; 31 + gpio-controller; 32 + #gpio-cells = <2>; 33 + }; 34 + 35 + dsp0: dsp0 { 36 + compatible = "linux,rproc-user"; 37 + ... 38 + kick-gpio = <&dspgpio0 27>; 39 + };
+39
Documentation/devicetree/bindings/gpio/gpio-pca953x.txt
··· 1 + * NXP PCA953x I2C GPIO multiplexer 2 + 3 + Required properties: 4 + - compatible: Has to contain one of the following: 5 + nxp,pca9505 6 + nxp,pca9534 7 + nxp,pca9535 8 + nxp,pca9536 9 + nxp,pca9537 10 + nxp,pca9538 11 + nxp,pca9539 12 + nxp,pca9554 13 + nxp,pca9555 14 + nxp,pca9556 15 + nxp,pca9557 16 + nxp,pca9574 17 + nxp,pca9575 18 + nxp,pca9698 19 + maxim,max7310 20 + maxim,max7312 21 + maxim,max7313 22 + maxim,max7315 23 + ti,pca6107 24 + ti,tca6408 25 + ti,tca6416 26 + ti,tca6424 27 + exar,xra1202 28 + 29 + Example: 30 + 31 + 32 + gpio@20 { 33 + compatible = "nxp,pca9505"; 34 + reg = <0x20>; 35 + pinctrl-names = "default"; 36 + pinctrl-0 = <&pinctrl_pca9505>; 37 + interrupt-parent = <&gpio3>; 38 + interrupts = <23 IRQ_TYPE_LEVEL_LOW>; 39 + };
+22
Documentation/devicetree/bindings/gpio/gpio-xgene.txt
··· 1 + APM X-Gene SoC GPIO controller bindings 2 + 3 + This is a gpio controller that is part of the flash controller. 4 + This gpio controller controls a total of 48 gpios. 5 + 6 + Required properties: 7 + - compatible: "apm,xgene-gpio" for X-Gene GPIO controller 8 + - reg: Physical base address and size of the controller's registers 9 + - #gpio-cells: Should be two. 10 + - first cell is the pin number 11 + - second cell is used to specify the gpio polarity: 12 + 0 = active high 13 + 1 = active low 14 + - gpio-controller: Marks the device node as a GPIO controller. 15 + 16 + Example: 17 + gpio0: gpio0@1701c000 { 18 + compatible = "apm,xgene-gpio"; 19 + reg = <0x0 0x1701c000 0x0 0x40>; 20 + gpio-controller; 21 + #gpio-cells = <2>; 22 + };
+14 -1
Documentation/devicetree/bindings/gpio/mrvl-gpio.txt
··· 19 19 - gpio-controller : Marks the device node as a gpio controller. 20 20 - #gpio-cells : Should be one. It is the pin number. 21 21 22 - Example: 22 + Example for a MMP platform: 23 23 24 24 gpio: gpio@d4019000 { 25 25 compatible = "marvell,mmp-gpio"; ··· 31 31 interrupt-controller; 32 32 #interrupt-cells = <1>; 33 33 }; 34 + 35 + Example for a PXA3xx platform: 36 + 37 + gpio: gpio@40e00000 { 38 + compatible = "intel,pxa3xx-gpio"; 39 + reg = <0x40e00000 0x10000>; 40 + interrupt-names = "gpio0", "gpio1", "gpio_mux"; 41 + interrupts = <8 9 10>; 42 + gpio-controller; 43 + #gpio-cells = <0x2>; 44 + interrupt-controller; 45 + #interrupt-cells = <0x2>; 46 + }; 34 47 35 48 * Marvell Orion GPIO Controller 36 49
+4 -2
Documentation/gpio/driver.txt
··· 124 124 * gpiochip_set_chained_irqchip(): sets up a chained irq handler for a 125 125 gpio_chip from a parent IRQ and passes the struct gpio_chip* as handler 126 126 data. (Notice handler data, since the irqchip data is likely used by the 127 - parent irqchip!) This is for the chained type of chip. 127 + parent irqchip!) This is for the chained type of chip. This is also used 128 + to set up a nested irqchip if NULL is passed as handler. 128 129 129 130 To use the helpers please keep the following in mind: 130 131 ··· 179 178 try_module_get()). A GPIO driver can use the following functions instead 180 179 to request and free descriptors without being pinned to the kernel forever. 181 180 182 - int gpiochip_request_own_desc(struct gpio_desc *desc, const char *label) 181 + struct gpio_desc *gpiochip_request_own_desc(struct gpio_desc *desc, 182 + const char *label) 183 183 184 184 void gpiochip_free_own_desc(struct gpio_desc *desc) 185 185
+2 -8
arch/arm/common/scoop.c
··· 243 243 static int scoop_remove(struct platform_device *pdev) 244 244 { 245 245 struct scoop_dev *sdev = platform_get_drvdata(pdev); 246 - int ret; 247 246 248 247 if (!sdev) 249 248 return -EINVAL; 250 249 251 - if (sdev->gpio.base != -1) { 252 - ret = gpiochip_remove(&sdev->gpio); 253 - if (ret) { 254 - dev_err(&pdev->dev, "Can't remove gpio chip: %d\n", ret); 255 - return ret; 256 - } 257 - } 250 + if (sdev->gpio.base != -1) 251 + gpiochip_remove(&sdev->gpio); 258 252 259 253 platform_set_drvdata(pdev, NULL); 260 254 iounmap(sdev->base);
+2 -2
arch/mips/txx9/generic/setup.c
··· 789 789 if (platform_device_add(pdev)) 790 790 goto out_pdev; 791 791 return; 792 + 792 793 out_pdev: 793 794 platform_device_put(pdev); 794 795 out_gpio: 795 - if (gpiochip_remove(&iocled->chip)) 796 - return; 796 + gpiochip_remove(&iocled->chip); 797 797 out_unmap: 798 798 iounmap(iocled->mmioaddr); 799 799 out_free:
+2 -1
arch/powerpc/platforms/83xx/mcu_mpc8349emitx.c
··· 141 141 142 142 static int mcu_gpiochip_remove(struct mcu *mcu) 143 143 { 144 - return gpiochip_remove(&mcu->gc); 144 + gpiochip_remove(&mcu->gc); 145 + return 0; 145 146 } 146 147 147 148 static int mcu_probe(struct i2c_client *client, const struct i2c_device_id *id)
+2 -4
arch/sh/boards/mach-x3proto/gpio.c
··· 128 128 return 0; 129 129 130 130 err_irq: 131 - ret = gpiochip_remove(&x3proto_gpio_chip); 132 - if (unlikely(ret)) 133 - pr_err("Failed deregistering GPIO\n"); 134 - 131 + gpiochip_remove(&x3proto_gpio_chip); 132 + ret = 0; 135 133 err_gpio: 136 134 synchronize_irq(ilsel); 137 135
+2 -1
drivers/bcma/driver_gpio.c
··· 255 255 int bcma_gpio_unregister(struct bcma_drv_cc *cc) 256 256 { 257 257 bcma_gpio_irq_domain_exit(cc); 258 - return gpiochip_remove(&cc->gpio); 258 + gpiochip_remove(&cc->gpio); 259 + return 0; 259 260 }
+11 -3
drivers/gpio/Kconfig
··· 136 136 tristate "Synopsys DesignWare APB GPIO driver" 137 137 select GPIO_GENERIC 138 138 select GENERIC_IRQ_CHIP 139 - depends on OF_GPIO 140 139 help 141 140 Say Y or M here to build support for the Synopsys DesignWare APB 142 141 GPIO block. ··· 332 333 default y 333 334 help 334 335 Say yes here to support Toumaz Xenif TZ1090 PDC GPIOs. 336 + 337 + config GPIO_XGENE 338 + bool "APM X-Gene GPIO controller support" 339 + depends on ARM64 && OF_GPIO 340 + help 341 + This driver is to support the GPIO block within the APM X-Gene SoC 342 + platform's generic flash controller. The GPIO pins are muxed with 343 + the generic flash controller's address and data pins. Say yes 344 + here to enable the GFC GPIO functionality. 335 345 336 346 config GPIO_XILINX 337 347 bool "Xilinx GPIO support" ··· 689 681 config GPIO_ADNP 690 682 tristate "Avionic Design N-bit GPIO expander" 691 683 depends on I2C && OF_GPIO 684 + select GPIOLIB_IRQCHIP 692 685 help 693 686 This option enables support for N GPIOs found on Avionic Design 694 687 I2C GPIO expanders. The register space will be extended by powers ··· 805 796 806 797 config GPIO_MCP23S08 807 798 tristate "Microchip MCP23xxx I/O expander" 808 - depends on OF_GPIO 809 799 depends on (SPI_MASTER && !I2C) || I2C 810 800 help 811 801 SPI/I2C driver for Microchip MCP23S08/MCP23S17/MCP23008/MCP23017 ··· 888 880 889 881 config GPIO_BCM_KONA 890 882 bool "Broadcom Kona GPIO" 891 - depends on OF_GPIO 883 + depends on OF_GPIO && (ARCH_BCM_MOBILE || COMPILE_TEST) 892 884 help 893 885 Turn on GPIO support for Broadcom "Kona" chips. 894 886
+1
drivers/gpio/Makefile
··· 101 101 obj-$(CONFIG_GPIO_WM831X) += gpio-wm831x.o 102 102 obj-$(CONFIG_GPIO_WM8350) += gpio-wm8350.o 103 103 obj-$(CONFIG_GPIO_WM8994) += gpio-wm8994.o 104 + obj-$(CONFIG_GPIO_XGENE) += gpio-xgene.o 104 105 obj-$(CONFIG_GPIO_XILINX) += gpio-xilinx.o 105 106 obj-$(CONFIG_GPIO_XTENSA) += gpio-xtensa.o 106 107 obj-$(CONFIG_GPIO_ZEVIO) += gpio-zevio.o
+47 -108
drivers/gpio/gpio-adnp.c
··· 6 6 * published by the Free Software Foundation. 7 7 */ 8 8 9 - #include <linux/gpio.h> 9 + #include <linux/gpio/driver.h> 10 10 #include <linux/i2c.h> 11 11 #include <linux/interrupt.h> 12 - #include <linux/irqdomain.h> 13 12 #include <linux/module.h> 14 13 #include <linux/of_irq.h> 15 14 #include <linux/seq_file.h> ··· 26 27 unsigned int reg_shift; 27 28 28 29 struct mutex i2c_lock; 29 - 30 - struct irq_domain *domain; 31 30 struct mutex irq_lock; 32 31 33 32 u8 *irq_enable; ··· 250 253 static int adnp_gpio_setup(struct adnp *adnp, unsigned int num_gpios) 251 254 { 252 255 struct gpio_chip *chip = &adnp->gpio; 256 + int err; 253 257 254 258 adnp->reg_shift = get_count_order(num_gpios) - 3; 255 259 ··· 269 271 chip->dev = &adnp->client->dev; 270 272 chip->of_node = chip->dev->of_node; 271 273 chip->owner = THIS_MODULE; 274 + 275 + err = gpiochip_add(chip); 276 + if (err) 277 + return err; 272 278 273 279 return 0; 274 280 } ··· 328 326 329 327 for_each_set_bit(bit, &pending, 8) { 330 328 unsigned int child_irq; 331 - child_irq = irq_find_mapping(adnp->domain, base + bit); 329 + child_irq = irq_find_mapping(adnp->gpio.irqdomain, 330 + base + bit); 332 331 handle_nested_irq(child_irq); 333 332 } 334 333 } ··· 337 334 return IRQ_HANDLED; 338 335 } 339 336 340 - static int adnp_gpio_to_irq(struct gpio_chip *chip, unsigned offset) 337 + static void adnp_irq_mask(struct irq_data *d) 341 338 { 342 - struct adnp *adnp = to_adnp(chip); 343 - return irq_create_mapping(adnp->domain, offset); 344 - } 345 - 346 - static void adnp_irq_mask(struct irq_data *data) 347 - { 348 - struct adnp *adnp = irq_data_get_irq_chip_data(data); 349 - unsigned int reg = data->hwirq >> adnp->reg_shift; 350 - unsigned int pos = data->hwirq & 7; 339 + struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 340 + struct adnp *adnp = to_adnp(gc); 341 + unsigned int reg = d->hwirq >> adnp->reg_shift; 342 + unsigned int pos = d->hwirq & 7; 351 343 352 344 adnp->irq_enable[reg] &= ~BIT(pos); 353 345 } 354 346 355 - static void adnp_irq_unmask(struct irq_data *data) 347 + static void adnp_irq_unmask(struct irq_data *d) 356 348 { 357 - struct adnp *adnp = irq_data_get_irq_chip_data(data); 358 - unsigned int reg = data->hwirq >> adnp->reg_shift; 359 - unsigned int pos = data->hwirq & 7; 349 + struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 350 + struct adnp *adnp = to_adnp(gc); 351 + unsigned int reg = d->hwirq >> adnp->reg_shift; 352 + unsigned int pos = d->hwirq & 7; 360 353 361 354 adnp->irq_enable[reg] |= BIT(pos); 362 355 } 363 356 364 - static int adnp_irq_set_type(struct irq_data *data, unsigned int type) 357 + static int adnp_irq_set_type(struct irq_data *d, unsigned int type) 365 358 { 366 - struct adnp *adnp = irq_data_get_irq_chip_data(data); 367 - unsigned int reg = data->hwirq >> adnp->reg_shift; 368 - unsigned int pos = data->hwirq & 7; 359 + struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 360 + struct adnp *adnp = to_adnp(gc); 361 + unsigned int reg = d->hwirq >> adnp->reg_shift; 362 + unsigned int pos = d->hwirq & 7; 369 363 370 364 if (type & IRQ_TYPE_EDGE_RISING) 371 365 adnp->irq_rise[reg] |= BIT(pos); ··· 387 387 return 0; 388 388 } 389 389 390 - static void adnp_irq_bus_lock(struct irq_data *data) 390 + static void adnp_irq_bus_lock(struct irq_data *d) 391 391 { 392 - struct adnp *adnp = irq_data_get_irq_chip_data(data); 392 + struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 393 + struct adnp *adnp = to_adnp(gc); 393 394 394 395 mutex_lock(&adnp->irq_lock); 395 396 } 396 397 397 - static void adnp_irq_bus_unlock(struct irq_data *data) 398 + static void adnp_irq_bus_unlock(struct irq_data *d) 398 399 { 399 - struct adnp *adnp = irq_data_get_irq_chip_data(data); 400 + struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 401 + struct adnp *adnp = to_adnp(gc); 400 402 unsigned int num_regs = 1 << adnp->reg_shift, i; 401 403 402 404 mutex_lock(&adnp->i2c_lock); ··· 410 408 mutex_unlock(&adnp->irq_lock); 411 409 } 412 410 413 - static int adnp_irq_reqres(struct irq_data *data) 414 - { 415 - struct adnp *adnp = irq_data_get_irq_chip_data(data); 416 - 417 - if (gpio_lock_as_irq(&adnp->gpio, data->hwirq)) { 418 - dev_err(adnp->gpio.dev, 419 - "unable to lock HW IRQ %lu for IRQ\n", 420 - data->hwirq); 421 - return -EINVAL; 422 - } 423 - return 0; 424 - } 425 - 426 - static void adnp_irq_relres(struct irq_data *data) 427 - { 428 - struct adnp *adnp = irq_data_get_irq_chip_data(data); 429 - 430 - gpio_unlock_as_irq(&adnp->gpio, data->hwirq); 431 - } 432 - 433 411 static struct irq_chip adnp_irq_chip = { 434 412 .name = "gpio-adnp", 435 413 .irq_mask = adnp_irq_mask, ··· 417 435 .irq_set_type = adnp_irq_set_type, 418 436 .irq_bus_lock = adnp_irq_bus_lock, 419 437 .irq_bus_sync_unlock = adnp_irq_bus_unlock, 420 - .irq_request_resources = adnp_irq_reqres, 421 - .irq_release_resources = adnp_irq_relres, 422 - }; 423 - 424 - static int adnp_irq_map(struct irq_domain *domain, unsigned int irq, 425 - irq_hw_number_t hwirq) 426 - { 427 - irq_set_chip_data(irq, domain->host_data); 428 - irq_set_chip(irq, &adnp_irq_chip); 429 - irq_set_nested_thread(irq, true); 430 - 431 - #ifdef CONFIG_ARM 432 - set_irq_flags(irq, IRQF_VALID); 433 - #else 434 - irq_set_noprobe(irq); 435 - #endif 436 - 437 - return 0; 438 - } 439 - 440 - static const struct irq_domain_ops adnp_irq_domain_ops = { 441 - .map = adnp_irq_map, 442 - .xlate = irq_domain_xlate_twocell, 443 438 }; 444 439 445 440 static int adnp_irq_setup(struct adnp *adnp) ··· 462 503 adnp->irq_enable[i] = 0x00; 463 504 } 464 505 465 - adnp->domain = irq_domain_add_linear(chip->of_node, chip->ngpio, 466 - &adnp_irq_domain_ops, adnp); 467 - 468 - err = request_threaded_irq(adnp->client->irq, NULL, adnp_irq, 469 - IRQF_TRIGGER_RISING | IRQF_ONESHOT, 470 - dev_name(chip->dev), adnp); 506 + err = devm_request_threaded_irq(chip->dev, adnp->client->irq, 507 + NULL, adnp_irq, 508 + IRQF_TRIGGER_RISING | IRQF_ONESHOT, 509 + dev_name(chip->dev), adnp); 471 510 if (err != 0) { 472 511 dev_err(chip->dev, "can't request IRQ#%d: %d\n", 473 512 adnp->client->irq, err); 474 513 return err; 475 514 } 476 515 477 - chip->to_irq = adnp_gpio_to_irq; 478 - return 0; 479 - } 480 - 481 - static void adnp_irq_teardown(struct adnp *adnp) 482 - { 483 - unsigned int irq, i; 484 - 485 - free_irq(adnp->client->irq, adnp); 486 - 487 - for (i = 0; i < adnp->gpio.ngpio; i++) { 488 - irq = irq_find_mapping(adnp->domain, i); 489 - if (irq > 0) 490 - irq_dispose_mapping(irq); 516 + err = gpiochip_irqchip_add(chip, 517 + &adnp_irq_chip, 518 + 0, 519 + handle_simple_irq, 520 + IRQ_TYPE_NONE); 521 + if (err) { 522 + dev_err(chip->dev, 523 + "could not connect irqchip to gpiochip\n"); 524 + return err; 491 525 } 492 526 493 - irq_domain_remove(adnp->domain); 527 + return 0; 494 528 } 495 529 496 530 static int adnp_i2c_probe(struct i2c_client *client, ··· 510 558 adnp->client = client; 511 559 512 560 err = adnp_gpio_setup(adnp, num_gpios); 513 - if (err < 0) 561 + if (err) 514 562 return err; 515 563 516 564 if (of_find_property(np, "interrupt-controller", NULL)) { 517 565 err = adnp_irq_setup(adnp); 518 - if (err < 0) 519 - goto teardown; 566 + if (err) 567 + return err; 520 568 } 521 569 522 - err = gpiochip_add(&adnp->gpio); 523 - if (err < 0) 524 - goto teardown; 525 - 526 570 i2c_set_clientdata(client, adnp); 571 + 527 572 return 0; 528 - 529 - teardown: 530 - if (of_find_property(np, "interrupt-controller", NULL)) 531 - adnp_irq_teardown(adnp); 532 - 533 - return err; 534 573 } 535 574 536 575 static int adnp_i2c_remove(struct i2c_client *client) 537 576 { 538 577 struct adnp *adnp = i2c_get_clientdata(client); 539 - struct device_node *np = client->dev.of_node; 540 578 541 579 gpiochip_remove(&adnp->gpio); 542 - if (of_find_property(np, "interrupt-controller", NULL)) 543 - adnp_irq_teardown(adnp); 544 - 545 580 return 0; 546 581 } 547 582
+1 -1
drivers/gpio/gpio-bcm-kona.c
··· 496 496 .irq_release_resources = bcm_kona_gpio_irq_relres, 497 497 }; 498 498 499 - static struct __initconst of_device_id bcm_kona_gpio_of_match[] = { 499 + static struct of_device_id const bcm_kona_gpio_of_match[] = { 500 500 { .compatible = "brcm,kona-gpio" }, 501 501 {} 502 502 };
+19 -9
drivers/gpio/gpio-crystalcove.c
··· 24 24 #include <linux/mfd/intel_soc_pmic.h> 25 25 26 26 #define CRYSTALCOVE_GPIO_NUM 16 27 + #define CRYSTALCOVE_VGPIO_NUM 94 27 28 28 29 #define UPDATE_IRQ_TYPE BIT(0) 29 30 #define UPDATE_IRQ_MASK BIT(1) ··· 131 130 { 132 131 struct crystalcove_gpio *cg = to_cg(chip); 133 132 133 + if (gpio > CRYSTALCOVE_VGPIO_NUM) 134 + return 0; 135 + 134 136 return regmap_write(cg->regmap, to_reg(gpio, CTRL_OUT), 135 137 CTLO_INPUT_SET); 136 138 } ··· 142 138 int value) 143 139 { 144 140 struct crystalcove_gpio *cg = to_cg(chip); 141 + 142 + if (gpio > CRYSTALCOVE_VGPIO_NUM) 143 + return 0; 145 144 146 145 return regmap_write(cg->regmap, to_reg(gpio, CTRL_OUT), 147 146 CTLO_OUTPUT_SET | value); ··· 155 148 struct crystalcove_gpio *cg = to_cg(chip); 156 149 int ret; 157 150 unsigned int val; 151 + 152 + if (gpio > CRYSTALCOVE_VGPIO_NUM) 153 + return 0; 158 154 159 155 ret = regmap_read(cg->regmap, to_reg(gpio, CTRL_IN), &val); 160 156 if (ret) ··· 170 160 unsigned gpio, int value) 171 161 { 172 162 struct crystalcove_gpio *cg = to_cg(chip); 163 + 164 + if (gpio > CRYSTALCOVE_VGPIO_NUM) 165 + return; 173 166 174 167 if (value) 175 168 regmap_update_bits(cg->regmap, to_reg(gpio, CTRL_OUT), 1, 1); ··· 269 256 270 257 pending = p0 | p1 << 8; 271 258 272 - for (gpio = 0; gpio < cg->chip.ngpio; gpio++) { 259 + for (gpio = 0; gpio < CRYSTALCOVE_GPIO_NUM; gpio++) { 273 260 if (pending & BIT(gpio)) { 274 261 virq = irq_find_mapping(cg->chip.irqdomain, gpio); 275 262 generic_handle_irq(virq); ··· 286 273 int gpio, offset; 287 274 unsigned int ctlo, ctli, mirqs0, mirqsx, irq; 288 275 289 - for (gpio = 0; gpio < cg->chip.ngpio; gpio++) { 276 + for (gpio = 0; gpio < CRYSTALCOVE_GPIO_NUM; gpio++) { 290 277 regmap_read(cg->regmap, to_reg(gpio, CTRL_OUT), &ctlo); 291 278 regmap_read(cg->regmap, to_reg(gpio, CTRL_IN), &ctli); 292 279 regmap_read(cg->regmap, gpio < 8 ? MGPIO0IRQS0 : MGPIO1IRQS0, ··· 333 320 cg->chip.get = crystalcove_gpio_get; 334 321 cg->chip.set = crystalcove_gpio_set; 335 322 cg->chip.base = -1; 336 - cg->chip.ngpio = CRYSTALCOVE_GPIO_NUM; 323 + cg->chip.ngpio = CRYSTALCOVE_VGPIO_NUM; 337 324 cg->chip.can_sleep = true; 338 325 cg->chip.dev = dev; 339 326 cg->chip.dbg_show = crystalcove_gpio_dbg_show; ··· 359 346 return 0; 360 347 361 348 out_remove_gpio: 362 - WARN_ON(gpiochip_remove(&cg->chip)); 349 + gpiochip_remove(&cg->chip); 363 350 return retval; 364 351 } 365 352 ··· 367 354 { 368 355 struct crystalcove_gpio *cg = platform_get_drvdata(pdev); 369 356 int irq = platform_get_irq(pdev, 0); 370 - int err; 371 357 372 - err = gpiochip_remove(&cg->chip); 373 - 358 + gpiochip_remove(&cg->chip); 374 359 if (irq >= 0) 375 360 free_irq(irq, cg); 376 - 377 - return err; 361 + return 0; 378 362 } 379 363 380 364 static struct platform_driver crystalcove_gpio_driver = {
+6 -3
drivers/gpio/gpio-cs5535.c
··· 201 201 202 202 static int chip_gpio_request(struct gpio_chip *c, unsigned offset) 203 203 { 204 - struct cs5535_gpio_chip *chip = (struct cs5535_gpio_chip *) c; 204 + struct cs5535_gpio_chip *chip = 205 + container_of(c, struct cs5535_gpio_chip, chip); 205 206 unsigned long flags; 206 207 207 208 spin_lock_irqsave(&chip->lock, flags); ··· 242 241 243 242 static int chip_direction_input(struct gpio_chip *c, unsigned offset) 244 243 { 245 - struct cs5535_gpio_chip *chip = (struct cs5535_gpio_chip *) c; 244 + struct cs5535_gpio_chip *chip = 245 + container_of(c, struct cs5535_gpio_chip, chip); 246 246 unsigned long flags; 247 247 248 248 spin_lock_irqsave(&chip->lock, flags); ··· 256 254 257 255 static int chip_direction_output(struct gpio_chip *c, unsigned offset, int val) 258 256 { 259 - struct cs5535_gpio_chip *chip = (struct cs5535_gpio_chip *) c; 257 + struct cs5535_gpio_chip *chip = 258 + container_of(c, struct cs5535_gpio_chip, chip); 260 259 unsigned long flags; 261 260 262 261 spin_lock_irqsave(&chip->lock, flags);
+342 -68
drivers/gpio/gpio-dwapb.c
··· 21 21 #include <linux/of_irq.h> 22 22 #include <linux/platform_device.h> 23 23 #include <linux/spinlock.h> 24 + #include <linux/platform_data/gpio-dwapb.h> 25 + #include <linux/slab.h> 24 26 25 27 #define GPIO_SWPORTA_DR 0x00 26 28 #define GPIO_SWPORTA_DDR 0x04 ··· 37 35 #define GPIO_INTTYPE_LEVEL 0x38 38 36 #define GPIO_INT_POLARITY 0x3c 39 37 #define GPIO_INTSTATUS 0x40 38 + #define GPIO_PORTA_DEBOUNCE 0x48 40 39 #define GPIO_PORTA_EOI 0x4c 41 40 #define GPIO_EXT_PORTA 0x50 42 41 #define GPIO_EXT_PORTB 0x54 ··· 51 48 52 49 struct dwapb_gpio; 53 50 51 + #ifdef CONFIG_PM_SLEEP 52 + /* Store GPIO context across system-wide suspend/resume transitions */ 53 + struct dwapb_context { 54 + u32 data; 55 + u32 dir; 56 + u32 ext; 57 + u32 int_en; 58 + u32 int_mask; 59 + u32 int_type; 60 + u32 int_pol; 61 + u32 int_deb; 62 + }; 63 + #endif 64 + 54 65 struct dwapb_gpio_port { 55 66 struct bgpio_chip bgc; 56 67 bool is_registered; 57 68 struct dwapb_gpio *gpio; 69 + #ifdef CONFIG_PM_SLEEP 70 + struct dwapb_context *ctx; 71 + #endif 72 + unsigned int idx; 58 73 }; 59 74 60 75 struct dwapb_gpio { ··· 83 62 struct irq_domain *domain; 84 63 }; 85 64 65 + static inline struct dwapb_gpio_port * 66 + to_dwapb_gpio_port(struct bgpio_chip *bgc) 67 + { 68 + return container_of(bgc, struct dwapb_gpio_port, bgc); 69 + } 70 + 71 + static inline u32 dwapb_read(struct dwapb_gpio *gpio, unsigned int offset) 72 + { 73 + struct bgpio_chip *bgc = &gpio->ports[0].bgc; 74 + void __iomem *reg_base = gpio->regs; 75 + 76 + return bgc->read_reg(reg_base + offset); 77 + } 78 + 79 + static inline void dwapb_write(struct dwapb_gpio *gpio, unsigned int offset, 80 + u32 val) 81 + { 82 + struct bgpio_chip *bgc = &gpio->ports[0].bgc; 83 + void __iomem *reg_base = gpio->regs; 84 + 85 + bgc->write_reg(reg_base + offset, val); 86 + } 87 + 86 88 static int dwapb_gpio_to_irq(struct gpio_chip *gc, unsigned offset) 87 89 { 88 90 struct bgpio_chip *bgc = to_bgpio_chip(gc); 89 - struct dwapb_gpio_port *port = container_of(bgc, struct 90 - dwapb_gpio_port, bgc); 91 + struct dwapb_gpio_port *port = to_dwapb_gpio_port(bgc); 91 92 struct dwapb_gpio *gpio = port->gpio; 92 93 93 94 return irq_find_mapping(gpio->domain, offset); ··· 117 74 118 75 static void dwapb_toggle_trigger(struct dwapb_gpio *gpio, unsigned int offs) 119 76 { 120 - u32 v = readl(gpio->regs + GPIO_INT_POLARITY); 77 + u32 v = dwapb_read(gpio, GPIO_INT_POLARITY); 121 78 122 79 if (gpio_get_value(gpio->ports[0].bgc.gc.base + offs)) 123 80 v &= ~BIT(offs); 124 81 else 125 82 v |= BIT(offs); 126 83 127 - writel(v, gpio->regs + GPIO_INT_POLARITY); 84 + dwapb_write(gpio, GPIO_INT_POLARITY, v); 128 85 } 129 86 130 - static void dwapb_irq_handler(u32 irq, struct irq_desc *desc) 87 + static u32 dwapb_do_irq(struct dwapb_gpio *gpio) 131 88 { 132 - struct dwapb_gpio *gpio = irq_get_handler_data(irq); 133 - struct irq_chip *chip = irq_desc_get_chip(desc); 134 89 u32 irq_status = readl_relaxed(gpio->regs + GPIO_INTSTATUS); 90 + u32 ret = irq_status; 135 91 136 92 while (irq_status) { 137 93 int hwirq = fls(irq_status) - 1; ··· 143 101 == IRQ_TYPE_EDGE_BOTH) 144 102 dwapb_toggle_trigger(gpio, hwirq); 145 103 } 104 + 105 + return ret; 106 + } 107 + 108 + static void dwapb_irq_handler(u32 irq, struct irq_desc *desc) 109 + { 110 + struct dwapb_gpio *gpio = irq_get_handler_data(irq); 111 + struct irq_chip *chip = irq_desc_get_chip(desc); 112 + 113 + dwapb_do_irq(gpio); 146 114 147 115 if (chip->irq_eoi) 148 116 chip->irq_eoi(irq_desc_get_irq_data(desc)); ··· 167 115 u32 val; 168 116 169 117 spin_lock_irqsave(&bgc->lock, flags); 170 - val = readl(gpio->regs + GPIO_INTEN); 118 + val = dwapb_read(gpio, GPIO_INTEN); 171 119 val |= BIT(d->hwirq); 172 - writel(val, gpio->regs + GPIO_INTEN); 120 + dwapb_write(gpio, GPIO_INTEN, val); 173 121 spin_unlock_irqrestore(&bgc->lock, flags); 174 122 } 175 123 ··· 182 130 u32 val; 183 131 184 132 spin_lock_irqsave(&bgc->lock, flags); 185 - val = readl(gpio->regs + GPIO_INTEN); 133 + val = dwapb_read(gpio, GPIO_INTEN); 186 134 val &= ~BIT(d->hwirq); 187 - writel(val, gpio->regs + GPIO_INTEN); 135 + dwapb_write(gpio, GPIO_INTEN, val); 188 136 spin_unlock_irqrestore(&bgc->lock, flags); 189 137 } 190 138 ··· 224 172 return -EINVAL; 225 173 226 174 spin_lock_irqsave(&bgc->lock, flags); 227 - level = readl(gpio->regs + GPIO_INTTYPE_LEVEL); 228 - polarity = readl(gpio->regs + GPIO_INT_POLARITY); 175 + level = dwapb_read(gpio, GPIO_INTTYPE_LEVEL); 176 + polarity = dwapb_read(gpio, GPIO_INT_POLARITY); 229 177 230 178 switch (type) { 231 179 case IRQ_TYPE_EDGE_BOTH: ··· 252 200 253 201 irq_setup_alt_chip(d, type); 254 202 255 - writel(level, gpio->regs + GPIO_INTTYPE_LEVEL); 256 - writel(polarity, gpio->regs + GPIO_INT_POLARITY); 203 + dwapb_write(gpio, GPIO_INTTYPE_LEVEL, level); 204 + dwapb_write(gpio, GPIO_INT_POLARITY, polarity); 257 205 spin_unlock_irqrestore(&bgc->lock, flags); 258 206 259 207 return 0; 260 208 } 261 209 210 + static int dwapb_gpio_set_debounce(struct gpio_chip *gc, 211 + unsigned offset, unsigned debounce) 212 + { 213 + struct bgpio_chip *bgc = to_bgpio_chip(gc); 214 + struct dwapb_gpio_port *port = to_dwapb_gpio_port(bgc); 215 + struct dwapb_gpio *gpio = port->gpio; 216 + unsigned long flags, val_deb; 217 + unsigned long mask = bgc->pin2mask(bgc, offset); 218 + 219 + spin_lock_irqsave(&bgc->lock, flags); 220 + 221 + val_deb = dwapb_read(gpio, GPIO_PORTA_DEBOUNCE); 222 + if (debounce) 223 + dwapb_write(gpio, GPIO_PORTA_DEBOUNCE, val_deb | mask); 224 + else 225 + dwapb_write(gpio, GPIO_PORTA_DEBOUNCE, val_deb & ~mask); 226 + 227 + spin_unlock_irqrestore(&bgc->lock, flags); 228 + 229 + return 0; 230 + } 231 + 232 + static irqreturn_t dwapb_irq_handler_mfd(int irq, void *dev_id) 233 + { 234 + u32 worked; 235 + struct dwapb_gpio *gpio = dev_id; 236 + 237 + worked = dwapb_do_irq(gpio); 238 + 239 + return worked ? IRQ_HANDLED : IRQ_NONE; 240 + } 241 + 262 242 static void dwapb_configure_irqs(struct dwapb_gpio *gpio, 263 - struct dwapb_gpio_port *port) 243 + struct dwapb_gpio_port *port, 244 + struct dwapb_port_property *pp) 264 245 { 265 246 struct gpio_chip *gc = &port->bgc.gc; 266 - struct device_node *node = gc->of_node; 267 - struct irq_chip_generic *irq_gc; 247 + struct device_node *node = pp->node; 248 + struct irq_chip_generic *irq_gc = NULL; 268 249 unsigned int hwirq, ngpio = gc->ngpio; 269 250 struct irq_chip_type *ct; 270 - int err, irq, i; 271 - 272 - irq = irq_of_parse_and_map(node, 0); 273 - if (!irq) { 274 - dev_warn(gpio->dev, "no irq for bank %s\n", 275 - port->bgc.gc.of_node->full_name); 276 - return; 277 - } 251 + int err, i; 278 252 279 253 gpio->domain = irq_domain_add_linear(node, ngpio, 280 254 &irq_generic_chip_ops, gpio); ··· 347 269 irq_gc->chip_types[1].type = IRQ_TYPE_EDGE_BOTH; 348 270 irq_gc->chip_types[1].handler = handle_edge_irq; 349 271 350 - irq_set_chained_handler(irq, dwapb_irq_handler); 351 - irq_set_handler_data(irq, gpio); 272 + if (!pp->irq_shared) { 273 + irq_set_chained_handler(pp->irq, dwapb_irq_handler); 274 + irq_set_handler_data(pp->irq, gpio); 275 + } else { 276 + /* 277 + * Request a shared IRQ since where MFD would have devices 278 + * using the same irq pin 279 + */ 280 + err = devm_request_irq(gpio->dev, pp->irq, 281 + dwapb_irq_handler_mfd, 282 + IRQF_SHARED, "gpio-dwapb-mfd", gpio); 283 + if (err) { 284 + dev_err(gpio->dev, "error requesting IRQ\n"); 285 + irq_domain_remove(gpio->domain); 286 + gpio->domain = NULL; 287 + return; 288 + } 289 + } 352 290 353 291 for (hwirq = 0 ; hwirq < ngpio ; hwirq++) 354 292 irq_create_mapping(gpio->domain, hwirq); ··· 390 296 } 391 297 392 298 static int dwapb_gpio_add_port(struct dwapb_gpio *gpio, 393 - struct device_node *port_np, 299 + struct dwapb_port_property *pp, 394 300 unsigned int offs) 395 301 { 396 302 struct dwapb_gpio_port *port; 397 - u32 port_idx, ngpio; 398 303 void __iomem *dat, *set, *dirout; 399 304 int err; 400 305 401 - if (of_property_read_u32(port_np, "reg", &port_idx) || 402 - port_idx >= DWAPB_MAX_PORTS) { 403 - dev_err(gpio->dev, "missing/invalid port index for %s\n", 404 - port_np->full_name); 405 - return -EINVAL; 406 - } 407 - 408 306 port = &gpio->ports[offs]; 409 307 port->gpio = gpio; 308 + port->idx = pp->idx; 410 309 411 - if (of_property_read_u32(port_np, "snps,nr-gpios", &ngpio)) { 412 - dev_info(gpio->dev, "failed to get number of gpios for %s\n", 413 - port_np->full_name); 414 - ngpio = 32; 415 - } 310 + #ifdef CONFIG_PM_SLEEP 311 + port->ctx = devm_kzalloc(gpio->dev, sizeof(*port->ctx), GFP_KERNEL); 312 + if (!port->ctx) 313 + return -ENOMEM; 314 + #endif 416 315 417 - dat = gpio->regs + GPIO_EXT_PORTA + (port_idx * GPIO_EXT_PORT_SIZE); 418 - set = gpio->regs + GPIO_SWPORTA_DR + (port_idx * GPIO_SWPORT_DR_SIZE); 316 + dat = gpio->regs + GPIO_EXT_PORTA + (pp->idx * GPIO_EXT_PORT_SIZE); 317 + set = gpio->regs + GPIO_SWPORTA_DR + (pp->idx * GPIO_SWPORT_DR_SIZE); 419 318 dirout = gpio->regs + GPIO_SWPORTA_DDR + 420 - (port_idx * GPIO_SWPORT_DDR_SIZE); 319 + (pp->idx * GPIO_SWPORT_DDR_SIZE); 421 320 422 321 err = bgpio_init(&port->bgc, gpio->dev, 4, dat, set, NULL, dirout, 423 322 NULL, false); 424 323 if (err) { 425 324 dev_err(gpio->dev, "failed to init gpio chip for %s\n", 426 - port_np->full_name); 325 + pp->name); 427 326 return err; 428 327 } 429 328 430 - port->bgc.gc.ngpio = ngpio; 431 - port->bgc.gc.of_node = port_np; 329 + #ifdef CONFIG_OF_GPIO 330 + port->bgc.gc.of_node = pp->node; 331 + #endif 332 + port->bgc.gc.ngpio = pp->ngpio; 333 + port->bgc.gc.base = pp->gpio_base; 432 334 433 - /* 434 - * Only port A can provide interrupts in all configurations of the IP. 435 - */ 436 - if (port_idx == 0 && 437 - of_property_read_bool(port_np, "interrupt-controller")) 438 - dwapb_configure_irqs(gpio, port); 335 + /* Only port A support debounce */ 336 + if (pp->idx == 0) 337 + port->bgc.gc.set_debounce = dwapb_gpio_set_debounce; 338 + 339 + if (pp->irq) 340 + dwapb_configure_irqs(gpio, port, pp); 439 341 440 342 err = gpiochip_add(&port->bgc.gc); 441 343 if (err) 442 344 dev_err(gpio->dev, "failed to register gpiochip for %s\n", 443 - port_np->full_name); 345 + pp->name); 444 346 else 445 347 port->is_registered = true; 446 348 ··· 452 362 gpiochip_remove(&gpio->ports[m].bgc.gc); 453 363 } 454 364 365 + static struct dwapb_platform_data * 366 + dwapb_gpio_get_pdata_of(struct device *dev) 367 + { 368 + struct device_node *node, *port_np; 369 + struct dwapb_platform_data *pdata; 370 + struct dwapb_port_property *pp; 371 + int nports; 372 + int i; 373 + 374 + node = dev->of_node; 375 + if (!IS_ENABLED(CONFIG_OF_GPIO) || !node) 376 + return ERR_PTR(-ENODEV); 377 + 378 + nports = of_get_child_count(node); 379 + if (nports == 0) 380 + return ERR_PTR(-ENODEV); 381 + 382 + pdata = kzalloc(sizeof(*pdata), GFP_KERNEL); 383 + if (!pdata) 384 + return ERR_PTR(-ENOMEM); 385 + 386 + pdata->properties = kcalloc(nports, sizeof(*pp), GFP_KERNEL); 387 + if (!pdata->properties) { 388 + kfree(pdata); 389 + return ERR_PTR(-ENOMEM); 390 + } 391 + 392 + pdata->nports = nports; 393 + 394 + i = 0; 395 + for_each_child_of_node(node, port_np) { 396 + pp = &pdata->properties[i++]; 397 + pp->node = port_np; 398 + 399 + if (of_property_read_u32(port_np, "reg", &pp->idx) || 400 + pp->idx >= DWAPB_MAX_PORTS) { 401 + dev_err(dev, "missing/invalid port index for %s\n", 402 + port_np->full_name); 403 + kfree(pdata->properties); 404 + kfree(pdata); 405 + return ERR_PTR(-EINVAL); 406 + } 407 + 408 + if (of_property_read_u32(port_np, "snps,nr-gpios", 409 + &pp->ngpio)) { 410 + dev_info(dev, "failed to get number of gpios for %s\n", 411 + port_np->full_name); 412 + pp->ngpio = 32; 413 + } 414 + 415 + /* 416 + * Only port A can provide interrupts in all configurations of 417 + * the IP. 418 + */ 419 + if (pp->idx == 0 && 420 + of_property_read_bool(port_np, "interrupt-controller")) { 421 + pp->irq = irq_of_parse_and_map(port_np, 0); 422 + if (!pp->irq) { 423 + dev_warn(dev, "no irq for bank %s\n", 424 + port_np->full_name); 425 + } 426 + } 427 + 428 + pp->irq_shared = false; 429 + pp->gpio_base = -1; 430 + pp->name = port_np->full_name; 431 + } 432 + 433 + return pdata; 434 + } 435 + 436 + static inline void dwapb_free_pdata_of(struct dwapb_platform_data *pdata) 437 + { 438 + if (!IS_ENABLED(CONFIG_OF_GPIO) || !pdata) 439 + return; 440 + 441 + kfree(pdata->properties); 442 + kfree(pdata); 443 + } 444 + 455 445 static int dwapb_gpio_probe(struct platform_device *pdev) 456 446 { 447 + unsigned int i; 457 448 struct resource *res; 458 449 struct dwapb_gpio *gpio; 459 - struct device_node *np; 460 450 int err; 461 - unsigned int offs = 0; 451 + struct device *dev = &pdev->dev; 452 + struct dwapb_platform_data *pdata = dev_get_platdata(dev); 453 + bool is_pdata_alloc = !pdata; 462 454 463 - gpio = devm_kzalloc(&pdev->dev, sizeof(*gpio), GFP_KERNEL); 464 - if (!gpio) 465 - return -ENOMEM; 466 - gpio->dev = &pdev->dev; 455 + if (is_pdata_alloc) { 456 + pdata = dwapb_gpio_get_pdata_of(dev); 457 + if (IS_ERR(pdata)) 458 + return PTR_ERR(pdata); 459 + } 467 460 468 - gpio->nr_ports = of_get_child_count(pdev->dev.of_node); 469 - if (!gpio->nr_ports) { 470 - err = -EINVAL; 461 + if (!pdata->nports) { 462 + err = -ENODEV; 471 463 goto out_err; 472 464 } 473 - gpio->ports = devm_kzalloc(&pdev->dev, gpio->nr_ports * 465 + 466 + gpio = devm_kzalloc(&pdev->dev, sizeof(*gpio), GFP_KERNEL); 467 + if (!gpio) { 468 + err = -ENOMEM; 469 + goto out_err; 470 + } 471 + gpio->dev = &pdev->dev; 472 + gpio->nr_ports = pdata->nports; 473 + 474 + gpio->ports = devm_kcalloc(&pdev->dev, gpio->nr_ports, 474 475 sizeof(*gpio->ports), GFP_KERNEL); 475 476 if (!gpio->ports) { 476 477 err = -ENOMEM; ··· 575 394 goto out_err; 576 395 } 577 396 578 - for_each_child_of_node(pdev->dev.of_node, np) { 579 - err = dwapb_gpio_add_port(gpio, np, offs++); 397 + for (i = 0; i < gpio->nr_ports; i++) { 398 + err = dwapb_gpio_add_port(gpio, &pdata->properties[i], i); 580 399 if (err) 581 400 goto out_unregister; 582 401 } 583 402 platform_set_drvdata(pdev, gpio); 584 403 585 - return 0; 404 + goto out_err; 586 405 587 406 out_unregister: 588 407 dwapb_gpio_unregister(gpio); 589 408 dwapb_irq_teardown(gpio); 590 409 591 410 out_err: 411 + if (is_pdata_alloc) 412 + dwapb_free_pdata_of(pdata); 413 + 592 414 return err; 593 415 } 594 416 ··· 611 427 }; 612 428 MODULE_DEVICE_TABLE(of, dwapb_of_match); 613 429 430 + #ifdef CONFIG_PM_SLEEP 431 + static int dwapb_gpio_suspend(struct device *dev) 432 + { 433 + struct platform_device *pdev = to_platform_device(dev); 434 + struct dwapb_gpio *gpio = platform_get_drvdata(pdev); 435 + struct bgpio_chip *bgc = &gpio->ports[0].bgc; 436 + unsigned long flags; 437 + int i; 438 + 439 + spin_lock_irqsave(&bgc->lock, flags); 440 + for (i = 0; i < gpio->nr_ports; i++) { 441 + unsigned int offset; 442 + unsigned int idx = gpio->ports[i].idx; 443 + struct dwapb_context *ctx = gpio->ports[i].ctx; 444 + 445 + BUG_ON(!ctx); 446 + 447 + offset = GPIO_SWPORTA_DDR + idx * GPIO_SWPORT_DDR_SIZE; 448 + ctx->dir = dwapb_read(gpio, offset); 449 + 450 + offset = GPIO_SWPORTA_DR + idx * GPIO_SWPORT_DR_SIZE; 451 + ctx->data = dwapb_read(gpio, offset); 452 + 453 + offset = GPIO_EXT_PORTA + idx * GPIO_EXT_PORT_SIZE; 454 + ctx->ext = dwapb_read(gpio, offset); 455 + 456 + /* Only port A can provide interrupts */ 457 + if (idx == 0) { 458 + ctx->int_mask = dwapb_read(gpio, GPIO_INTMASK); 459 + ctx->int_en = dwapb_read(gpio, GPIO_INTEN); 460 + ctx->int_pol = dwapb_read(gpio, GPIO_INT_POLARITY); 461 + ctx->int_type = dwapb_read(gpio, GPIO_INTTYPE_LEVEL); 462 + ctx->int_deb = dwapb_read(gpio, GPIO_PORTA_DEBOUNCE); 463 + 464 + /* Mask out interrupts */ 465 + dwapb_write(gpio, GPIO_INTMASK, 0xffffffff); 466 + } 467 + } 468 + spin_unlock_irqrestore(&bgc->lock, flags); 469 + 470 + return 0; 471 + } 472 + 473 + static int dwapb_gpio_resume(struct device *dev) 474 + { 475 + struct platform_device *pdev = to_platform_device(dev); 476 + struct dwapb_gpio *gpio = platform_get_drvdata(pdev); 477 + struct bgpio_chip *bgc = &gpio->ports[0].bgc; 478 + unsigned long flags; 479 + int i; 480 + 481 + spin_lock_irqsave(&bgc->lock, flags); 482 + for (i = 0; i < gpio->nr_ports; i++) { 483 + unsigned int offset; 484 + unsigned int idx = gpio->ports[i].idx; 485 + struct dwapb_context *ctx = gpio->ports[i].ctx; 486 + 487 + BUG_ON(!ctx); 488 + 489 + offset = GPIO_SWPORTA_DR + idx * GPIO_SWPORT_DR_SIZE; 490 + dwapb_write(gpio, offset, ctx->data); 491 + 492 + offset = GPIO_SWPORTA_DDR + idx * GPIO_SWPORT_DDR_SIZE; 493 + dwapb_write(gpio, offset, ctx->dir); 494 + 495 + offset = GPIO_EXT_PORTA + idx * GPIO_EXT_PORT_SIZE; 496 + dwapb_write(gpio, offset, ctx->ext); 497 + 498 + /* Only port A can provide interrupts */ 499 + if (idx == 0) { 500 + dwapb_write(gpio, GPIO_INTTYPE_LEVEL, ctx->int_type); 501 + dwapb_write(gpio, GPIO_INT_POLARITY, ctx->int_pol); 502 + dwapb_write(gpio, GPIO_PORTA_DEBOUNCE, ctx->int_deb); 503 + dwapb_write(gpio, GPIO_INTEN, ctx->int_en); 504 + dwapb_write(gpio, GPIO_INTMASK, ctx->int_mask); 505 + 506 + /* Clear out spurious interrupts */ 507 + dwapb_write(gpio, GPIO_PORTA_EOI, 0xffffffff); 508 + } 509 + } 510 + spin_unlock_irqrestore(&bgc->lock, flags); 511 + 512 + return 0; 513 + } 514 + #endif 515 + 516 + static SIMPLE_DEV_PM_OPS(dwapb_gpio_pm_ops, dwapb_gpio_suspend, 517 + dwapb_gpio_resume); 518 + 614 519 static struct platform_driver dwapb_gpio_driver = { 615 520 .driver = { 616 521 .name = "gpio-dwapb", 617 522 .owner = THIS_MODULE, 523 + .pm = &dwapb_gpio_pm_ops, 618 524 .of_match_table = of_match_ptr(dwapb_of_match), 619 525 }, 620 526 .probe = dwapb_gpio_probe,
+14 -16
drivers/gpio/gpio-ks8695.c
··· 265 265 seq_printf(s, "EXT%i ", i); 266 266 267 267 switch ((ctrl & intmask[i]) >> (4 * i)) { 268 - case IOPC_TM_LOW: 269 - seq_printf(s, "(Low)"); break; 270 - case IOPC_TM_HIGH: 271 - seq_printf(s, "(High)"); break; 272 - case IOPC_TM_RISING: 273 - seq_printf(s, "(Rising)"); break; 274 - case IOPC_TM_FALLING: 275 - seq_printf(s, "(Falling)"); break; 276 - case IOPC_TM_EDGE: 277 - seq_printf(s, "(Edges)"); break; 268 + case IOPC_TM_LOW: 269 + seq_printf(s, "(Low)"); break; 270 + case IOPC_TM_HIGH: 271 + seq_printf(s, "(High)"); break; 272 + case IOPC_TM_RISING: 273 + seq_printf(s, "(Rising)"); break; 274 + case IOPC_TM_FALLING: 275 + seq_printf(s, "(Falling)"); break; 276 + case IOPC_TM_EDGE: 277 + seq_printf(s, "(Edges)"); break; 278 278 } 279 - } 280 - else 279 + } else 281 280 seq_printf(s, "GPIO\t"); 282 - } 283 - else if (i <= KS8695_GPIO_5) { 281 + } else if (i <= KS8695_GPIO_5) { 284 282 if (ctrl & enable[i]) 285 283 seq_printf(s, "TOUT%i\t", i - KS8695_GPIO_4); 286 284 else 287 285 seq_printf(s, "GPIO\t"); 288 - } 289 - else 286 + } else { 290 287 seq_printf(s, "GPIO\t"); 288 + } 291 289 292 290 seq_printf(s, "\t"); 293 291
+34 -30
drivers/gpio/gpio-mcp23s08.c
··· 479 479 480 480 mutex_init(&mcp->irq_lock); 481 481 482 - mcp->irq_domain = irq_domain_add_linear(chip->of_node, chip->ngpio, 482 + mcp->irq_domain = irq_domain_add_linear(chip->dev->of_node, chip->ngpio, 483 483 &irq_domain_simple_ops, mcp); 484 484 if (!mcp->irq_domain) 485 485 return -ENODEV; ··· 581 581 582 582 static int mcp23s08_probe_one(struct mcp23s08 *mcp, struct device *dev, 583 583 void *data, unsigned addr, unsigned type, 584 - unsigned base, unsigned pullups) 584 + struct mcp23s08_platform_data *pdata, int cs) 585 585 { 586 586 int status; 587 587 bool mirror = false; ··· 635 635 return -EINVAL; 636 636 } 637 637 638 - mcp->chip.base = base; 638 + mcp->chip.base = pdata->base; 639 639 mcp->chip.can_sleep = true; 640 640 mcp->chip.dev = dev; 641 641 mcp->chip.owner = THIS_MODULE; ··· 648 648 if (status < 0) 649 649 goto fail; 650 650 651 - mcp->irq_controller = of_property_read_bool(mcp->chip.of_node, 652 - "interrupt-controller"); 651 + mcp->irq_controller = pdata->irq_controller; 653 652 if (mcp->irq && mcp->irq_controller && (type == MCP_TYPE_017)) 654 - mirror = of_property_read_bool(mcp->chip.of_node, 655 - "microchip,irq-mirror"); 653 + mirror = pdata->mirror; 656 654 657 655 if ((status & IOCON_SEQOP) || !(status & IOCON_HAEN) || mirror) { 658 656 /* mcp23s17 has IOCON twice, make sure they are in sync */ ··· 666 668 } 667 669 668 670 /* configure ~100K pullups */ 669 - status = mcp->ops->write(mcp, MCP_GPPU, pullups); 671 + status = mcp->ops->write(mcp, MCP_GPPU, pdata->chip[cs].pullups); 670 672 if (status < 0) 671 673 goto fail; 672 674 ··· 766 768 static int mcp230xx_probe(struct i2c_client *client, 767 769 const struct i2c_device_id *id) 768 770 { 769 - struct mcp23s08_platform_data *pdata; 771 + struct mcp23s08_platform_data *pdata, local_pdata; 770 772 struct mcp23s08 *mcp; 771 - int status, base, pullups; 773 + int status; 772 774 const struct of_device_id *match; 773 775 774 776 match = of_match_device(of_match_ptr(mcp23s08_i2c_of_match), 775 777 &client->dev); 776 - pdata = dev_get_platdata(&client->dev); 777 - if (match || !pdata) { 778 - base = -1; 779 - pullups = 0; 778 + if (match) { 779 + pdata = &local_pdata; 780 + pdata->base = -1; 781 + pdata->chip[0].pullups = 0; 782 + pdata->irq_controller = of_property_read_bool( 783 + client->dev.of_node, 784 + "interrupt-controller"); 785 + pdata->mirror = of_property_read_bool(client->dev.of_node, 786 + "microchip,irq-mirror"); 780 787 client->irq = irq_of_parse_and_map(client->dev.of_node, 0); 781 788 } else { 782 - if (!gpio_is_valid(pdata->base)) { 789 + pdata = dev_get_platdata(&client->dev); 790 + if (!pdata || !gpio_is_valid(pdata->base)) { 783 791 dev_dbg(&client->dev, "invalid platform data\n"); 784 792 return -EINVAL; 785 793 } 786 - base = pdata->base; 787 - pullups = pdata->chip[0].pullups; 788 794 } 789 795 790 796 mcp = kzalloc(sizeof(*mcp), GFP_KERNEL); ··· 797 795 798 796 mcp->irq = client->irq; 799 797 status = mcp23s08_probe_one(mcp, &client->dev, client, client->addr, 800 - id->driver_data, base, pullups); 798 + id->driver_data, pdata, 0); 801 799 if (status) 802 800 goto fail; 803 801 ··· 865 863 866 864 static int mcp23s08_probe(struct spi_device *spi) 867 865 { 868 - struct mcp23s08_platform_data *pdata; 866 + struct mcp23s08_platform_data *pdata, local_pdata; 869 867 unsigned addr; 870 868 int chips = 0; 871 869 struct mcp23s08_driver_data *data; 872 870 int status, type; 873 - unsigned base = -1, 874 - ngpio = 0, 875 - pullups[ARRAY_SIZE(pdata->chip)]; 871 + unsigned ngpio = 0; 876 872 const struct of_device_id *match; 877 873 u32 spi_present_mask = 0; 878 874 ··· 893 893 return -ENODEV; 894 894 } 895 895 896 + pdata = &local_pdata; 897 + pdata->base = -1; 896 898 for (addr = 0; addr < ARRAY_SIZE(pdata->chip); addr++) { 897 - pullups[addr] = 0; 899 + pdata->chip[addr].pullups = 0; 898 900 if (spi_present_mask & (1 << addr)) 899 901 chips++; 900 902 } 903 + pdata->irq_controller = of_property_read_bool( 904 + spi->dev.of_node, 905 + "interrupt-controller"); 906 + pdata->mirror = of_property_read_bool(spi->dev.of_node, 907 + "microchip,irq-mirror"); 901 908 } else { 902 909 type = spi_get_device_id(spi)->driver_data; 903 910 pdata = dev_get_platdata(&spi->dev); ··· 924 917 return -EINVAL; 925 918 } 926 919 spi_present_mask |= 1 << addr; 927 - pullups[addr] = pdata->chip[addr].pullups; 928 920 } 929 - 930 - base = pdata->base; 931 921 } 932 922 933 923 if (!chips) ··· 942 938 chips--; 943 939 data->mcp[addr] = &data->chip[chips]; 944 940 status = mcp23s08_probe_one(data->mcp[addr], &spi->dev, spi, 945 - 0x40 | (addr << 1), type, base, 946 - pullups[addr]); 941 + 0x40 | (addr << 1), type, pdata, 942 + addr); 947 943 if (status < 0) 948 944 goto fail; 949 945 950 - if (base != -1) 951 - base += (type == MCP_TYPE_S17) ? 16 : 8; 946 + if (pdata->base != -1) 947 + pdata->base += (type == MCP_TYPE_S17) ? 16 : 8; 952 948 ngpio += (type == MCP_TYPE_S17) ? 16 : 8; 953 949 } 954 950 data->ngpio = ngpio;
+18 -15
drivers/gpio/gpio-omap.c
··· 857 857 spin_unlock_irqrestore(&bank->lock, flags); 858 858 } 859 859 860 - static struct irq_chip gpio_irq_chip = { 861 - .name = "GPIO", 862 - .irq_shutdown = omap_gpio_irq_shutdown, 863 - .irq_ack = omap_gpio_ack_irq, 864 - .irq_mask = omap_gpio_mask_irq, 865 - .irq_unmask = omap_gpio_unmask_irq, 866 - .irq_set_type = omap_gpio_irq_type, 867 - .irq_set_wake = omap_gpio_wake_enable, 868 - }; 869 - 870 860 /*---------------------------------------------------------------------*/ 871 861 872 862 static int omap_mpuio_suspend_noirq(struct device *dev) ··· 1078 1088 IRQ_NOREQUEST | IRQ_NOPROBE, 0); 1079 1089 } 1080 1090 1081 - static int omap_gpio_chip_init(struct gpio_bank *bank) 1091 + static int omap_gpio_chip_init(struct gpio_bank *bank, struct irq_chip *irqc) 1082 1092 { 1083 1093 int j; 1084 1094 static int gpio; ··· 1127 1137 } 1128 1138 #endif 1129 1139 1130 - ret = gpiochip_irqchip_add(&bank->chip, &gpio_irq_chip, 1140 + ret = gpiochip_irqchip_add(&bank->chip, irqc, 1131 1141 irq_base, omap_gpio_irq_handler, 1132 1142 IRQ_TYPE_NONE); 1133 1143 1134 1144 if (ret) { 1135 1145 dev_err(bank->dev, "Couldn't add irqchip to gpiochip %d\n", ret); 1136 - ret = gpiochip_remove(&bank->chip); 1146 + gpiochip_remove(&bank->chip); 1137 1147 return -ENODEV; 1138 1148 } 1139 1149 1140 - gpiochip_set_chained_irqchip(&bank->chip, &gpio_irq_chip, 1150 + gpiochip_set_chained_irqchip(&bank->chip, irqc, 1141 1151 bank->irq, omap_gpio_irq_handler); 1142 1152 1143 1153 for (j = 0; j < bank->width; j++) { ··· 1162 1172 const struct omap_gpio_platform_data *pdata; 1163 1173 struct resource *res; 1164 1174 struct gpio_bank *bank; 1175 + struct irq_chip *irqc; 1165 1176 int ret; 1166 1177 1167 1178 match = of_match_device(of_match_ptr(omap_gpio_match), dev); ··· 1176 1185 dev_err(dev, "Memory alloc failed\n"); 1177 1186 return -ENOMEM; 1178 1187 } 1188 + 1189 + irqc = devm_kzalloc(dev, sizeof(*irqc), GFP_KERNEL); 1190 + if (!irqc) 1191 + return -ENOMEM; 1192 + 1193 + irqc->irq_shutdown = omap_gpio_irq_shutdown, 1194 + irqc->irq_ack = omap_gpio_ack_irq, 1195 + irqc->irq_mask = omap_gpio_mask_irq, 1196 + irqc->irq_unmask = omap_gpio_unmask_irq, 1197 + irqc->irq_set_type = omap_gpio_irq_type, 1198 + irqc->irq_set_wake = omap_gpio_wake_enable, 1199 + irqc->name = dev_name(&pdev->dev); 1179 1200 1180 1201 res = platform_get_resource(pdev, IORESOURCE_IRQ, 0); 1181 1202 if (unlikely(!res)) { ··· 1244 1241 1245 1242 omap_gpio_mod_init(bank); 1246 1243 1247 - ret = omap_gpio_chip_init(bank); 1244 + ret = omap_gpio_chip_init(bank, irqc); 1248 1245 if (ret) 1249 1246 return ret; 1250 1247
+3 -51
drivers/gpio/gpio-pca953x.c
··· 520 520 struct i2c_client *client = chip->client; 521 521 int ret, i, offset = 0; 522 522 523 - if (irq_base != -1 523 + if (client->irq && irq_base != -1 524 524 && (id->driver_data & PCA_INT)) { 525 525 526 526 switch (chip->chip_type) { ··· 583 583 dev_warn(&client->dev, "interrupt support not compiled in\n"); 584 584 585 585 return 0; 586 - } 587 - #endif 588 - 589 - /* 590 - * Handlers for alternative sources of platform_data 591 - */ 592 - #ifdef CONFIG_OF_GPIO 593 - /* 594 - * Translate OpenFirmware node properties into platform_data 595 - * WARNING: This is DEPRECATED and will be removed eventually! 596 - */ 597 - static void 598 - pca953x_get_alt_pdata(struct i2c_client *client, int *gpio_base, u32 *invert) 599 - { 600 - struct device_node *node; 601 - const __be32 *val; 602 - int size; 603 - 604 - *gpio_base = -1; 605 - 606 - node = client->dev.of_node; 607 - if (node == NULL) 608 - return; 609 - 610 - val = of_get_property(node, "linux,gpio-base", &size); 611 - WARN(val, "%s: device-tree property 'linux,gpio-base' is deprecated!", __func__); 612 - if (val) { 613 - if (size != sizeof(*val)) 614 - dev_warn(&client->dev, "%s: wrong linux,gpio-base\n", 615 - node->full_name); 616 - else 617 - *gpio_base = be32_to_cpup(val); 618 - } 619 - 620 - val = of_get_property(node, "polarity", NULL); 621 - WARN(val, "%s: device-tree property 'polarity' is deprecated!", __func__); 622 - if (val) 623 - *invert = *val; 624 - } 625 - #else 626 - static void 627 - pca953x_get_alt_pdata(struct i2c_client *client, int *gpio_base, u32 *invert) 628 - { 629 - *gpio_base = -1; 630 586 } 631 587 #endif 632 588 ··· 660 704 invert = pdata->invert; 661 705 chip->names = pdata->names; 662 706 } else { 663 - pca953x_get_alt_pdata(client, &chip->gpio_start, &invert); 664 - #ifdef CONFIG_OF_GPIO 665 - /* If I2C node has no interrupts property, disable GPIO interrupts */ 666 - if (of_find_property(client->dev.of_node, "interrupts", NULL) == NULL) 667 - irq_base = -1; 668 - #endif 707 + chip->gpio_start = -1; 708 + irq_base = 0; 669 709 } 670 710 671 711 chip->client = client;
+2
drivers/gpio/gpio-pch.c
··· 171 171 return 0; 172 172 } 173 173 174 + #ifdef CONFIG_PM 174 175 /* 175 176 * Save register configuration and disable interrupts. 176 177 */ ··· 207 206 iowrite32(chip->pch_gpio_reg.gpio_use_sel_reg, 208 207 &chip->reg->gpio_use_sel); 209 208 } 209 + #endif 210 210 211 211 static int pch_gpio_to_irq(struct gpio_chip *gpio, unsigned offset) 212 212 {
-50
drivers/gpio/gpio-samsung.c
··· 1309 1309 } 1310 1310 EXPORT_SYMBOL(s3c_gpio_getpull); 1311 1311 1312 - #ifdef CONFIG_S5P_GPIO_DRVSTR 1313 - s5p_gpio_drvstr_t s5p_gpio_get_drvstr(unsigned int pin) 1314 - { 1315 - struct samsung_gpio_chip *chip = samsung_gpiolib_getchip(pin); 1316 - unsigned int off; 1317 - void __iomem *reg; 1318 - int shift; 1319 - u32 drvstr; 1320 - 1321 - if (!chip) 1322 - return -EINVAL; 1323 - 1324 - off = pin - chip->chip.base; 1325 - shift = off * 2; 1326 - reg = chip->base + 0x0C; 1327 - 1328 - drvstr = __raw_readl(reg); 1329 - drvstr = drvstr >> shift; 1330 - drvstr &= 0x3; 1331 - 1332 - return (__force s5p_gpio_drvstr_t)drvstr; 1333 - } 1334 - EXPORT_SYMBOL(s5p_gpio_get_drvstr); 1335 - 1336 - int s5p_gpio_set_drvstr(unsigned int pin, s5p_gpio_drvstr_t drvstr) 1337 - { 1338 - struct samsung_gpio_chip *chip = samsung_gpiolib_getchip(pin); 1339 - unsigned int off; 1340 - void __iomem *reg; 1341 - int shift; 1342 - u32 tmp; 1343 - 1344 - if (!chip) 1345 - return -EINVAL; 1346 - 1347 - off = pin - chip->chip.base; 1348 - shift = off * 2; 1349 - reg = chip->base + 0x0C; 1350 - 1351 - tmp = __raw_readl(reg); 1352 - tmp &= ~(0x3 << shift); 1353 - tmp |= drvstr << shift; 1354 - 1355 - __raw_writel(tmp, reg); 1356 - 1357 - return 0; 1358 - } 1359 - EXPORT_SYMBOL(s5p_gpio_set_drvstr); 1360 - #endif /* CONFIG_S5P_GPIO_DRVSTR */ 1361 - 1362 1312 #ifdef CONFIG_PLAT_S3C24XX 1363 1313 unsigned int s3c2410_modify_misccr(unsigned int clear, unsigned int change) 1364 1314 {
+90 -9
drivers/gpio/gpio-stmpe.c
··· 13 13 #include <linux/interrupt.h> 14 14 #include <linux/of.h> 15 15 #include <linux/mfd/stmpe.h> 16 + #include <linux/seq_file.h> 16 17 17 18 /* 18 19 * These registers are modified under the irq bus lock and cached to avoid ··· 128 127 int regoffset = offset / 8; 129 128 int mask = 1 << (offset % 8); 130 129 131 - if (type == IRQ_TYPE_LEVEL_LOW || type == IRQ_TYPE_LEVEL_HIGH) 130 + if (type & IRQ_TYPE_LEVEL_LOW || type & IRQ_TYPE_LEVEL_HIGH) 132 131 return -EINVAL; 133 132 134 133 /* STMPE801 doesn't have RE and FE registers */ 135 134 if (stmpe_gpio->stmpe->partnum == STMPE801) 136 135 return 0; 137 136 138 - if (type == IRQ_TYPE_EDGE_RISING) 137 + if (type & IRQ_TYPE_EDGE_RISING) 139 138 stmpe_gpio->regs[REG_RE][regoffset] |= mask; 140 139 else 141 140 stmpe_gpio->regs[REG_RE][regoffset] &= ~mask; 142 141 143 - if (type == IRQ_TYPE_EDGE_FALLING) 142 + if (type & IRQ_TYPE_EDGE_FALLING) 144 143 stmpe_gpio->regs[REG_FE][regoffset] |= mask; 145 144 else 146 145 stmpe_gpio->regs[REG_FE][regoffset] &= ~mask; ··· 210 209 int mask = 1 << (offset % 8); 211 210 212 211 stmpe_gpio->regs[REG_IE][regoffset] |= mask; 212 + } 213 + 214 + static void stmpe_dbg_show_one(struct seq_file *s, 215 + struct gpio_chip *gc, 216 + unsigned offset, unsigned gpio) 217 + { 218 + struct stmpe_gpio *stmpe_gpio = to_stmpe_gpio(gc); 219 + struct stmpe *stmpe = stmpe_gpio->stmpe; 220 + const char *label = gpiochip_is_requested(gc, offset); 221 + int num_banks = DIV_ROUND_UP(stmpe->num_gpios, 8); 222 + bool val = !!stmpe_gpio_get(gc, offset); 223 + u8 dir_reg = stmpe->regs[STMPE_IDX_GPDR_LSB] - (offset / 8); 224 + u8 mask = 1 << (offset % 8); 225 + int ret; 226 + u8 dir; 227 + 228 + ret = stmpe_reg_read(stmpe, dir_reg); 229 + if (ret < 0) 230 + return; 231 + dir = !!(ret & mask); 232 + 233 + if (dir) { 234 + seq_printf(s, " gpio-%-3d (%-20.20s) out %s", 235 + gpio, label ?: "(none)", 236 + val ? "hi" : "lo"); 237 + } else { 238 + u8 edge_det_reg = stmpe->regs[STMPE_IDX_GPEDR_MSB] + num_banks - 1 - (offset / 8); 239 + u8 rise_reg = stmpe->regs[STMPE_IDX_GPRER_LSB] - (offset / 8); 240 + u8 fall_reg = stmpe->regs[STMPE_IDX_GPFER_LSB] - (offset / 8); 241 + u8 irqen_reg = stmpe->regs[STMPE_IDX_IEGPIOR_LSB] - (offset / 8); 242 + bool edge_det; 243 + bool rise; 244 + bool fall; 245 + bool irqen; 246 + 247 + ret = stmpe_reg_read(stmpe, edge_det_reg); 248 + if (ret < 0) 249 + return; 250 + edge_det = !!(ret & mask); 251 + ret = stmpe_reg_read(stmpe, rise_reg); 252 + if (ret < 0) 253 + return; 254 + rise = !!(ret & mask); 255 + ret = stmpe_reg_read(stmpe, fall_reg); 256 + if (ret < 0) 257 + return; 258 + fall = !!(ret & mask); 259 + ret = stmpe_reg_read(stmpe, irqen_reg); 260 + if (ret < 0) 261 + return; 262 + irqen = !!(ret & mask); 263 + 264 + seq_printf(s, " gpio-%-3d (%-20.20s) in %s %s %s%s%s", 265 + gpio, label ?: "(none)", 266 + val ? "hi" : "lo", 267 + edge_det ? "edge-asserted" : "edge-inactive", 268 + irqen ? "IRQ-enabled" : "", 269 + rise ? " rising-edge-detection" : "", 270 + fall ? " falling-edge-detection" : ""); 271 + } 272 + } 273 + 274 + static void stmpe_dbg_show(struct seq_file *s, struct gpio_chip *gc) 275 + { 276 + unsigned i; 277 + unsigned gpio = gc->base; 278 + 279 + for (i = 0; i < gc->ngpio; i++, gpio++) { 280 + stmpe_dbg_show_one(s, gc, i, gpio); 281 + seq_printf(s, "\n"); 282 + } 213 283 } 214 284 215 285 static struct irq_chip stmpe_gpio_irq_chip = { ··· 365 293 #endif 366 294 stmpe_gpio->chip.base = -1; 367 295 296 + if (IS_ENABLED(CONFIG_DEBUG_FS)) 297 + stmpe_gpio->chip.dbg_show = stmpe_dbg_show; 298 + 368 299 if (pdata) 369 300 stmpe_gpio->norequest_mask = pdata->norequest_mask; 370 301 else if (np) ··· 382 307 ret = stmpe_enable(stmpe, STMPE_BLOCK_GPIO); 383 308 if (ret) 384 309 goto out_free; 310 + 311 + ret = gpiochip_add(&stmpe_gpio->chip); 312 + if (ret) { 313 + dev_err(&pdev->dev, "unable to add gpiochip: %d\n", ret); 314 + goto out_disable; 315 + } 385 316 386 317 if (irq > 0) { 387 318 ret = devm_request_threaded_irq(&pdev->dev, irq, NULL, ··· 405 324 if (ret) { 406 325 dev_err(&pdev->dev, 407 326 "could not connect irqchip to gpiochip\n"); 408 - return ret; 327 + goto out_disable; 409 328 } 410 - } 411 329 412 - ret = gpiochip_add(&stmpe_gpio->chip); 413 - if (ret) { 414 - dev_err(&pdev->dev, "unable to add gpiochip: %d\n", ret); 415 - goto out_disable; 330 + gpiochip_set_chained_irqchip(&stmpe_gpio->chip, 331 + &stmpe_gpio_irq_chip, 332 + irq, 333 + NULL); 416 334 } 417 335 418 336 if (pdata && pdata->setup) ··· 423 343 424 344 out_disable: 425 345 stmpe_disable(stmpe, STMPE_BLOCK_GPIO); 346 + gpiochip_remove(&stmpe_gpio->chip); 426 347 out_free: 427 348 kfree(stmpe_gpio); 428 349 return ret;
+1 -1
drivers/gpio/gpio-stp-xway.c
··· 292 292 }, 293 293 }; 294 294 295 - int __init xway_stp_init(void) 295 + static int __init xway_stp_init(void) 296 296 { 297 297 return platform_driver_register(&xway_stp_driver); 298 298 }
+84 -10
drivers/gpio/gpio-syscon.c
··· 37 37 * dat_bit_offset: Offset (in bits) to the first GPIO bit. 38 38 * dir_bit_offset: Optional offset (in bits) to the first bit to switch 39 39 * GPIO direction (Used with GPIO_SYSCON_FEAT_DIR flag). 40 + * set: HW specific callback to assigns output value 41 + * for signal "offset" 40 42 */ 41 43 42 44 struct syscon_gpio_data { ··· 47 45 unsigned int bit_count; 48 46 unsigned int dat_bit_offset; 49 47 unsigned int dir_bit_offset; 48 + void (*set)(struct gpio_chip *chip, 49 + unsigned offset, int value); 50 50 }; 51 51 52 52 struct syscon_gpio_priv { 53 53 struct gpio_chip chip; 54 54 struct regmap *syscon; 55 55 const struct syscon_gpio_data *data; 56 + u32 dreg_offset; 57 + u32 dir_reg_offset; 56 58 }; 57 59 58 60 static inline struct syscon_gpio_priv *to_syscon_gpio(struct gpio_chip *chip) ··· 67 61 static int syscon_gpio_get(struct gpio_chip *chip, unsigned offset) 68 62 { 69 63 struct syscon_gpio_priv *priv = to_syscon_gpio(chip); 70 - unsigned int val, offs = priv->data->dat_bit_offset + offset; 64 + unsigned int val, offs; 71 65 int ret; 66 + 67 + offs = priv->dreg_offset + priv->data->dat_bit_offset + offset; 72 68 73 69 ret = regmap_read(priv->syscon, 74 70 (offs / SYSCON_REG_BITS) * SYSCON_REG_SIZE, &val); ··· 83 75 static void syscon_gpio_set(struct gpio_chip *chip, unsigned offset, int val) 84 76 { 85 77 struct syscon_gpio_priv *priv = to_syscon_gpio(chip); 86 - unsigned int offs = priv->data->dat_bit_offset + offset; 78 + unsigned int offs; 79 + 80 + offs = priv->dreg_offset + priv->data->dat_bit_offset + offset; 87 81 88 82 regmap_update_bits(priv->syscon, 89 83 (offs / SYSCON_REG_BITS) * SYSCON_REG_SIZE, ··· 98 88 struct syscon_gpio_priv *priv = to_syscon_gpio(chip); 99 89 100 90 if (priv->data->flags & GPIO_SYSCON_FEAT_DIR) { 101 - unsigned int offs = priv->data->dir_bit_offset + offset; 91 + unsigned int offs; 92 + 93 + offs = priv->dir_reg_offset + 94 + priv->data->dir_bit_offset + offset; 102 95 103 96 regmap_update_bits(priv->syscon, 104 97 (offs / SYSCON_REG_BITS) * SYSCON_REG_SIZE, ··· 116 103 struct syscon_gpio_priv *priv = to_syscon_gpio(chip); 117 104 118 105 if (priv->data->flags & GPIO_SYSCON_FEAT_DIR) { 119 - unsigned int offs = priv->data->dir_bit_offset + offset; 106 + unsigned int offs; 107 + 108 + offs = priv->dir_reg_offset + 109 + priv->data->dir_bit_offset + offset; 120 110 121 111 regmap_update_bits(priv->syscon, 122 112 (offs / SYSCON_REG_BITS) * SYSCON_REG_SIZE, ··· 127 111 BIT(offs % SYSCON_REG_BITS)); 128 112 } 129 113 130 - syscon_gpio_set(chip, offset, val); 114 + priv->data->set(chip, offset, val); 131 115 132 116 return 0; 133 117 } ··· 140 124 .dat_bit_offset = 0x40 * 8 + 8, 141 125 }; 142 126 127 + #define KEYSTONE_LOCK_BIT BIT(0) 128 + 129 + static void keystone_gpio_set(struct gpio_chip *chip, unsigned offset, int val) 130 + { 131 + struct syscon_gpio_priv *priv = to_syscon_gpio(chip); 132 + unsigned int offs; 133 + int ret; 134 + 135 + offs = priv->dreg_offset + priv->data->dat_bit_offset + offset; 136 + 137 + if (!val) 138 + return; 139 + 140 + ret = regmap_update_bits( 141 + priv->syscon, 142 + (offs / SYSCON_REG_BITS) * SYSCON_REG_SIZE, 143 + BIT(offs % SYSCON_REG_BITS) | KEYSTONE_LOCK_BIT, 144 + BIT(offs % SYSCON_REG_BITS) | KEYSTONE_LOCK_BIT); 145 + if (ret < 0) 146 + dev_err(chip->dev, "gpio write failed ret(%d)\n", ret); 147 + } 148 + 149 + static const struct syscon_gpio_data keystone_dsp_gpio = { 150 + /* ARM Keystone 2 */ 151 + .compatible = NULL, 152 + .flags = GPIO_SYSCON_FEAT_OUT, 153 + .bit_count = 28, 154 + .dat_bit_offset = 4, 155 + .set = keystone_gpio_set, 156 + }; 157 + 143 158 static const struct of_device_id syscon_gpio_ids[] = { 144 159 { 145 160 .compatible = "cirrus,clps711x-mctrl-gpio", 146 161 .data = &clps711x_mctrl_gpio, 162 + }, 163 + { 164 + .compatible = "ti,keystone-dsp-gpio", 165 + .data = &keystone_dsp_gpio, 147 166 }, 148 167 { } 149 168 }; ··· 189 138 struct device *dev = &pdev->dev; 190 139 const struct of_device_id *of_id = of_match_device(syscon_gpio_ids, dev); 191 140 struct syscon_gpio_priv *priv; 141 + struct device_node *np = dev->of_node; 142 + int ret; 192 143 193 144 priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); 194 145 if (!priv) ··· 198 145 199 146 priv->data = of_id->data; 200 147 201 - priv->syscon = 202 - syscon_regmap_lookup_by_compatible(priv->data->compatible); 203 - if (IS_ERR(priv->syscon)) 204 - return PTR_ERR(priv->syscon); 148 + if (priv->data->compatible) { 149 + priv->syscon = syscon_regmap_lookup_by_compatible( 150 + priv->data->compatible); 151 + if (IS_ERR(priv->syscon)) 152 + return PTR_ERR(priv->syscon); 153 + } else { 154 + priv->syscon = 155 + syscon_regmap_lookup_by_phandle(np, "gpio,syscon-dev"); 156 + if (IS_ERR(priv->syscon)) 157 + return PTR_ERR(priv->syscon); 158 + 159 + ret = of_property_read_u32_index(np, "gpio,syscon-dev", 1, 160 + &priv->dreg_offset); 161 + if (ret) 162 + dev_err(dev, "can't read the data register offset!\n"); 163 + 164 + priv->dreg_offset <<= 3; 165 + 166 + ret = of_property_read_u32_index(np, "gpio,syscon-dev", 2, 167 + &priv->dir_reg_offset); 168 + if (ret) 169 + dev_err(dev, "can't read the dir register offset!\n"); 170 + 171 + priv->dir_reg_offset <<= 3; 172 + } 205 173 206 174 priv->chip.dev = dev; 207 175 priv->chip.owner = THIS_MODULE; ··· 233 159 if (priv->data->flags & GPIO_SYSCON_FEAT_IN) 234 160 priv->chip.direction_input = syscon_gpio_dir_in; 235 161 if (priv->data->flags & GPIO_SYSCON_FEAT_OUT) { 236 - priv->chip.set = syscon_gpio_set; 162 + priv->chip.set = priv->data->set ? : syscon_gpio_set; 237 163 priv->chip.direction_output = syscon_gpio_dir_out; 238 164 } 239 165
+5
drivers/gpio/gpio-tc3589x.c
··· 300 300 return ret; 301 301 } 302 302 303 + gpiochip_set_chained_irqchip(&tc3589x_gpio->chip, 304 + &tc3589x_gpio_irq_chip, 305 + irq, 306 + NULL); 307 + 303 308 if (pdata && pdata->setup) 304 309 pdata->setup(tc3589x, tc3589x_gpio->chip.base); 305 310
+244
drivers/gpio/gpio-xgene.c
··· 1 + /* 2 + * AppliedMicro X-Gene SoC GPIO Driver 3 + * 4 + * Copyright (c) 2014, Applied Micro Circuits Corporation 5 + * Author: Feng Kan <fkan@apm.com>. 6 + * 7 + * This program is free software; you can redistribute it and/or modify 8 + * it under the terms of the GNU General Public License version 2 as 9 + * published by the Free Software Foundation. 10 + * 11 + * This program is distributed in the hope that it will be useful, 12 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 + * GNU General Public License for more details. 15 + * 16 + * You should have received a copy of the GNU General Public License 17 + * along with this program. If not, see <http://www.gnu.org/licenses/>. 18 + */ 19 + 20 + #include <linux/module.h> 21 + #include <linux/kernel.h> 22 + #include <linux/init.h> 23 + #include <linux/io.h> 24 + #include <linux/spinlock.h> 25 + #include <linux/platform_device.h> 26 + #include <linux/gpio/driver.h> 27 + #include <linux/types.h> 28 + #include <linux/bitops.h> 29 + 30 + #define GPIO_SET_DR_OFFSET 0x0C 31 + #define GPIO_DATA_OFFSET 0x14 32 + #define GPIO_BANK_STRIDE 0x0C 33 + 34 + #define XGENE_GPIOS_PER_BANK 16 35 + #define XGENE_MAX_GPIO_BANKS 3 36 + #define XGENE_MAX_GPIOS (XGENE_GPIOS_PER_BANK * XGENE_MAX_GPIO_BANKS) 37 + 38 + #define GPIO_BIT_OFFSET(x) (x % XGENE_GPIOS_PER_BANK) 39 + #define GPIO_BANK_OFFSET(x) ((x / XGENE_GPIOS_PER_BANK) * GPIO_BANK_STRIDE) 40 + 41 + struct xgene_gpio { 42 + struct gpio_chip chip; 43 + void __iomem *base; 44 + spinlock_t lock; 45 + #ifdef CONFIG_PM 46 + u32 set_dr_val[XGENE_MAX_GPIO_BANKS]; 47 + #endif 48 + }; 49 + 50 + static inline struct xgene_gpio *to_xgene_gpio(struct gpio_chip *chip) 51 + { 52 + return container_of(chip, struct xgene_gpio, chip); 53 + } 54 + 55 + static int xgene_gpio_get(struct gpio_chip *gc, unsigned int offset) 56 + { 57 + struct xgene_gpio *chip = to_xgene_gpio(gc); 58 + unsigned long bank_offset; 59 + u32 bit_offset; 60 + 61 + bank_offset = GPIO_DATA_OFFSET + GPIO_BANK_OFFSET(offset); 62 + bit_offset = GPIO_BIT_OFFSET(offset); 63 + return !!(ioread32(chip->base + bank_offset) & BIT(bit_offset)); 64 + } 65 + 66 + static void __xgene_gpio_set(struct gpio_chip *gc, unsigned int offset, int val) 67 + { 68 + struct xgene_gpio *chip = to_xgene_gpio(gc); 69 + unsigned long bank_offset; 70 + u32 setval, bit_offset; 71 + 72 + bank_offset = GPIO_SET_DR_OFFSET + GPIO_BANK_OFFSET(offset); 73 + bit_offset = GPIO_BIT_OFFSET(offset) + XGENE_GPIOS_PER_BANK; 74 + 75 + setval = ioread32(chip->base + bank_offset); 76 + if (val) 77 + setval |= BIT(bit_offset); 78 + else 79 + setval &= ~BIT(bit_offset); 80 + iowrite32(setval, chip->base + bank_offset); 81 + } 82 + 83 + static void xgene_gpio_set(struct gpio_chip *gc, unsigned int offset, int val) 84 + { 85 + struct xgene_gpio *chip = to_xgene_gpio(gc); 86 + unsigned long flags; 87 + 88 + spin_lock_irqsave(&chip->lock, flags); 89 + __xgene_gpio_set(gc, offset, val); 90 + spin_unlock_irqrestore(&chip->lock, flags); 91 + } 92 + 93 + static int xgene_gpio_dir_in(struct gpio_chip *gc, unsigned int offset) 94 + { 95 + struct xgene_gpio *chip = to_xgene_gpio(gc); 96 + unsigned long flags, bank_offset; 97 + u32 dirval, bit_offset; 98 + 99 + bank_offset = GPIO_SET_DR_OFFSET + GPIO_BANK_OFFSET(offset); 100 + bit_offset = GPIO_BIT_OFFSET(offset); 101 + 102 + spin_lock_irqsave(&chip->lock, flags); 103 + 104 + dirval = ioread32(chip->base + bank_offset); 105 + dirval |= BIT(bit_offset); 106 + iowrite32(dirval, chip->base + bank_offset); 107 + 108 + spin_unlock_irqrestore(&chip->lock, flags); 109 + 110 + return 0; 111 + } 112 + 113 + static int xgene_gpio_dir_out(struct gpio_chip *gc, 114 + unsigned int offset, int val) 115 + { 116 + struct xgene_gpio *chip = to_xgene_gpio(gc); 117 + unsigned long flags, bank_offset; 118 + u32 dirval, bit_offset; 119 + 120 + bank_offset = GPIO_SET_DR_OFFSET + GPIO_BANK_OFFSET(offset); 121 + bit_offset = GPIO_BIT_OFFSET(offset); 122 + 123 + spin_lock_irqsave(&chip->lock, flags); 124 + 125 + dirval = ioread32(chip->base + bank_offset); 126 + dirval &= ~BIT(bit_offset); 127 + iowrite32(dirval, chip->base + bank_offset); 128 + __xgene_gpio_set(gc, offset, val); 129 + 130 + spin_unlock_irqrestore(&chip->lock, flags); 131 + 132 + return 0; 133 + } 134 + 135 + #ifdef CONFIG_PM 136 + static int xgene_gpio_suspend(struct device *dev) 137 + { 138 + struct xgene_gpio *gpio = dev_get_drvdata(dev); 139 + unsigned long bank_offset; 140 + unsigned int bank; 141 + 142 + for (bank = 0; bank < XGENE_MAX_GPIO_BANKS; bank++) { 143 + bank_offset = GPIO_SET_DR_OFFSET + bank * GPIO_BANK_STRIDE; 144 + gpio->set_dr_val[bank] = ioread32(gpio->base + bank_offset); 145 + } 146 + return 0; 147 + } 148 + 149 + static int xgene_gpio_resume(struct device *dev) 150 + { 151 + struct xgene_gpio *gpio = dev_get_drvdata(dev); 152 + unsigned long bank_offset; 153 + unsigned int bank; 154 + 155 + for (bank = 0; bank < XGENE_MAX_GPIO_BANKS; bank++) { 156 + bank_offset = GPIO_SET_DR_OFFSET + bank * GPIO_BANK_STRIDE; 157 + iowrite32(gpio->set_dr_val[bank], gpio->base + bank_offset); 158 + } 159 + return 0; 160 + } 161 + 162 + static SIMPLE_DEV_PM_OPS(xgene_gpio_pm, xgene_gpio_suspend, xgene_gpio_resume); 163 + #define XGENE_GPIO_PM_OPS (&xgene_gpio_pm) 164 + #else 165 + #define XGENE_GPIO_PM_OPS NULL 166 + #endif 167 + 168 + static int xgene_gpio_probe(struct platform_device *pdev) 169 + { 170 + struct resource *res; 171 + struct xgene_gpio *gpio; 172 + int err = 0; 173 + 174 + gpio = devm_kzalloc(&pdev->dev, sizeof(*gpio), GFP_KERNEL); 175 + if (!gpio) { 176 + err = -ENOMEM; 177 + goto err; 178 + } 179 + 180 + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 181 + gpio->base = devm_ioremap_nocache(&pdev->dev, res->start, 182 + resource_size(res)); 183 + if (!gpio->base) { 184 + err = -ENOMEM; 185 + goto err; 186 + } 187 + 188 + gpio->chip.ngpio = XGENE_MAX_GPIOS; 189 + 190 + spin_lock_init(&gpio->lock); 191 + gpio->chip.dev = &pdev->dev; 192 + gpio->chip.direction_input = xgene_gpio_dir_in; 193 + gpio->chip.direction_output = xgene_gpio_dir_out; 194 + gpio->chip.get = xgene_gpio_get; 195 + gpio->chip.set = xgene_gpio_set; 196 + gpio->chip.label = dev_name(&pdev->dev); 197 + gpio->chip.base = -1; 198 + 199 + platform_set_drvdata(pdev, gpio); 200 + 201 + err = gpiochip_add(&gpio->chip); 202 + if (err) { 203 + dev_err(&pdev->dev, 204 + "failed to register gpiochip.\n"); 205 + goto err; 206 + } 207 + 208 + dev_info(&pdev->dev, "X-Gene GPIO driver registered.\n"); 209 + return 0; 210 + err: 211 + dev_err(&pdev->dev, "X-Gene GPIO driver registration failed.\n"); 212 + return err; 213 + } 214 + 215 + static int xgene_gpio_remove(struct platform_device *pdev) 216 + { 217 + struct xgene_gpio *gpio = platform_get_drvdata(pdev); 218 + 219 + gpiochip_remove(&gpio->chip); 220 + return 0; 221 + } 222 + 223 + static const struct of_device_id xgene_gpio_of_match[] = { 224 + { .compatible = "apm,xgene-gpio", }, 225 + {}, 226 + }; 227 + MODULE_DEVICE_TABLE(of, xgene_gpio_of_match); 228 + 229 + static struct platform_driver xgene_gpio_driver = { 230 + .driver = { 231 + .name = "xgene-gpio", 232 + .owner = THIS_MODULE, 233 + .of_match_table = xgene_gpio_of_match, 234 + .pm = XGENE_GPIO_PM_OPS, 235 + }, 236 + .probe = xgene_gpio_probe, 237 + .remove = xgene_gpio_remove, 238 + }; 239 + 240 + module_platform_driver(xgene_gpio_driver); 241 + 242 + MODULE_AUTHOR("Feng Kan <fkan@apm.com>"); 243 + MODULE_DESCRIPTION("APM X-Gene GPIO driver"); 244 + MODULE_LICENSE("GPL");
+15 -12
drivers/gpio/gpio-xilinx.c
··· 197 197 struct xgpio_instance *chip; 198 198 int status = 0; 199 199 const u32 *tree_info; 200 + u32 ngpio; 200 201 201 202 chip = kzalloc(sizeof(*chip), GFP_KERNEL); 202 203 if (!chip) ··· 212 211 /* Update GPIO direction shadow register with default value */ 213 212 of_property_read_u32(np, "xlnx,tri-default", &chip->gpio_dir); 214 213 215 - /* By default assume full GPIO controller */ 216 - chip->mmchip.gc.ngpio = 32; 217 - 218 - /* Check device node and parent device node for device width */ 219 - of_property_read_u32(np, "xlnx,gpio-width", 220 - (u32 *)&chip->mmchip.gc.ngpio); 214 + /* 215 + * Check device node and parent device node for device width 216 + * and assume default width of 32 217 + */ 218 + if (of_property_read_u32(np, "xlnx,gpio-width", &ngpio)) 219 + ngpio = 32; 220 + chip->mmchip.gc.ngpio = (u16)ngpio; 221 221 222 222 spin_lock_init(&chip->gpio_lock); 223 223 ··· 260 258 /* Update GPIO direction shadow register with default value */ 261 259 of_property_read_u32(np, "xlnx,tri-default-2", &chip->gpio_dir); 262 260 263 - /* By default assume full GPIO controller */ 264 - chip->mmchip.gc.ngpio = 32; 265 - 266 - /* Check device node and parent device node for device width */ 267 - of_property_read_u32(np, "xlnx,gpio2-width", 268 - (u32 *)&chip->mmchip.gc.ngpio); 261 + /* 262 + * Check device node and parent device node for device width 263 + * and assume default width of 32 264 + */ 265 + if (of_property_read_u32(np, "xlnx,gpio2-width", &ngpio)) 266 + ngpio = 32; 267 + chip->mmchip.gc.ngpio = (u16)ngpio; 269 268 270 269 spin_lock_init(&chip->gpio_lock); 271 270
+52 -37
drivers/gpio/gpio-zynq.c
··· 88 88 * @chip: instance of the gpio_chip 89 89 * @base_addr: base address of the GPIO device 90 90 * @clk: clock resource for this controller 91 + * @irq: interrupt for the GPIO device 91 92 */ 92 93 struct zynq_gpio { 93 94 struct gpio_chip chip; 94 95 void __iomem *base_addr; 95 96 struct clk *clk; 97 + int irq; 96 98 }; 97 99 98 100 static struct irq_chip zynq_gpio_level_irqchip; 99 101 static struct irq_chip zynq_gpio_edge_irqchip; 100 - 101 102 /** 102 103 * zynq_gpio_get_bank_pin - Get the bank number and pin number within that bank 103 104 * for a given pin in the GPIO device ··· 138 137 break; 139 138 } 140 139 } 140 + 141 + static const unsigned int zynq_gpio_bank_offset[] = { 142 + ZYNQ_GPIO_BANK0_PIN_MIN, 143 + ZYNQ_GPIO_BANK1_PIN_MIN, 144 + ZYNQ_GPIO_BANK2_PIN_MIN, 145 + ZYNQ_GPIO_BANK3_PIN_MIN, 146 + }; 141 147 142 148 /** 143 149 * zynq_gpio_get_value - Get the state of the specified pin of GPIO device ··· 435 427 436 428 static int zynq_gpio_set_wake(struct irq_data *data, unsigned int on) 437 429 { 438 - if (on) 439 - zynq_gpio_irq_unmask(data); 440 - else 441 - zynq_gpio_irq_mask(data); 430 + struct zynq_gpio *gpio = irq_data_get_irq_chip_data(data); 431 + 432 + irq_set_irq_wake(gpio->irq, on); 442 433 443 434 return 0; 444 435 } ··· 451 444 .irq_unmask = zynq_gpio_irq_unmask, 452 445 .irq_set_type = zynq_gpio_set_irq_type, 453 446 .irq_set_wake = zynq_gpio_set_wake, 454 - .flags = IRQCHIP_EOI_THREADED | IRQCHIP_EOI_IF_HANDLED, 447 + .flags = IRQCHIP_EOI_THREADED | IRQCHIP_EOI_IF_HANDLED | 448 + IRQCHIP_MASK_ON_SUSPEND, 455 449 }; 456 450 457 451 static struct irq_chip zynq_gpio_edge_irqchip = { ··· 463 455 .irq_unmask = zynq_gpio_irq_unmask, 464 456 .irq_set_type = zynq_gpio_set_irq_type, 465 457 .irq_set_wake = zynq_gpio_set_wake, 458 + .flags = IRQCHIP_MASK_ON_SUSPEND, 466 459 }; 460 + 461 + static void zynq_gpio_handle_bank_irq(struct zynq_gpio *gpio, 462 + unsigned int bank_num, 463 + unsigned long pending) 464 + { 465 + unsigned int bank_offset = zynq_gpio_bank_offset[bank_num]; 466 + struct irq_domain *irqdomain = gpio->chip.irqdomain; 467 + int offset; 468 + 469 + if (!pending) 470 + return; 471 + 472 + for_each_set_bit(offset, &pending, 32) { 473 + unsigned int gpio_irq; 474 + 475 + gpio_irq = irq_find_mapping(irqdomain, offset + bank_offset); 476 + generic_handle_irq(gpio_irq); 477 + } 478 + } 467 479 468 480 /** 469 481 * zynq_gpio_irqhandler - IRQ handler for the gpio banks of a gpio device ··· 510 482 ZYNQ_GPIO_INTSTS_OFFSET(bank_num)); 511 483 int_enb = readl_relaxed(gpio->base_addr + 512 484 ZYNQ_GPIO_INTMASK_OFFSET(bank_num)); 513 - int_sts &= ~int_enb; 514 - if (int_sts) { 515 - int offset; 516 - unsigned long pending = int_sts; 517 - 518 - for_each_set_bit(offset, &pending, 32) { 519 - unsigned int gpio_irq = 520 - irq_find_mapping(gpio->chip.irqdomain, 521 - offset); 522 - generic_handle_irq(gpio_irq); 523 - } 524 - } 485 + zynq_gpio_handle_bank_irq(gpio, bank_num, int_sts & ~int_enb); 525 486 } 526 487 527 488 chained_irq_exit(irqchip, desc); ··· 518 501 519 502 static int __maybe_unused zynq_gpio_suspend(struct device *dev) 520 503 { 521 - if (!device_may_wakeup(dev)) 504 + struct platform_device *pdev = to_platform_device(dev); 505 + int irq = platform_get_irq(pdev, 0); 506 + struct irq_data *data = irq_get_irq_data(irq); 507 + 508 + if (!irqd_is_wakeup_set(data)) 522 509 return pm_runtime_force_suspend(dev); 523 510 524 511 return 0; ··· 530 509 531 510 static int __maybe_unused zynq_gpio_resume(struct device *dev) 532 511 { 533 - if (!device_may_wakeup(dev)) 512 + struct platform_device *pdev = to_platform_device(dev); 513 + int irq = platform_get_irq(pdev, 0); 514 + struct irq_data *data = irq_get_irq_data(irq); 515 + 516 + if (!irqd_is_wakeup_set(data)) 534 517 return pm_runtime_force_resume(dev); 535 518 536 519 return 0; ··· 595 570 */ 596 571 static int zynq_gpio_probe(struct platform_device *pdev) 597 572 { 598 - int ret, bank_num, irq; 573 + int ret, bank_num; 599 574 struct zynq_gpio *gpio; 600 575 struct gpio_chip *chip; 601 576 struct resource *res; ··· 611 586 if (IS_ERR(gpio->base_addr)) 612 587 return PTR_ERR(gpio->base_addr); 613 588 614 - irq = platform_get_irq(pdev, 0); 615 - if (irq < 0) { 589 + gpio->irq = platform_get_irq(pdev, 0); 590 + if (gpio->irq < 0) { 616 591 dev_err(&pdev->dev, "invalid IRQ\n"); 617 - return irq; 592 + return gpio->irq; 618 593 } 619 594 620 595 /* configure the gpio chip */ ··· 662 637 goto err_rm_gpiochip; 663 638 } 664 639 665 - gpiochip_set_chained_irqchip(chip, &zynq_gpio_edge_irqchip, irq, 640 + gpiochip_set_chained_irqchip(chip, &zynq_gpio_edge_irqchip, gpio->irq, 666 641 zynq_gpio_irqhandler); 667 642 668 643 pm_runtime_set_active(&pdev->dev); 669 644 pm_runtime_enable(&pdev->dev); 670 645 671 - device_set_wakeup_capable(&pdev->dev, 1); 672 - 673 646 return 0; 674 647 675 648 err_rm_gpiochip: 676 - if (gpiochip_remove(chip)) 677 - dev_err(&pdev->dev, "Failed to remove gpio chip\n"); 649 + gpiochip_remove(chip); 678 650 err_disable_clk: 679 651 clk_disable_unprepare(gpio->clk); 680 652 ··· 686 664 */ 687 665 static int zynq_gpio_remove(struct platform_device *pdev) 688 666 { 689 - int ret; 690 667 struct zynq_gpio *gpio = platform_get_drvdata(pdev); 691 668 692 669 pm_runtime_get_sync(&pdev->dev); 693 - 694 - ret = gpiochip_remove(&gpio->chip); 695 - if (ret) { 696 - dev_err(&pdev->dev, "Failed to remove gpio chip\n"); 697 - return ret; 698 - } 670 + gpiochip_remove(&gpio->chip); 699 671 clk_disable_unprepare(gpio->clk); 700 672 device_set_wakeup_capable(&pdev->dev, 0); 701 673 return 0; ··· 704 688 static struct platform_driver zynq_gpio_driver = { 705 689 .driver = { 706 690 .name = DRIVER_NAME, 707 - .owner = THIS_MODULE, 708 691 .pm = &zynq_gpio_dev_pm_ops, 709 692 .of_match_table = zynq_gpio_of_match, 710 693 },
+11 -19
drivers/gpio/gpiolib-acpi.c
··· 25 25 acpi_handle handle; 26 26 unsigned int pin; 27 27 unsigned int irq; 28 + struct gpio_desc *desc; 28 29 }; 29 30 30 31 struct acpi_gpio_connection { 31 32 struct list_head node; 33 + unsigned int pin; 32 34 struct gpio_desc *desc; 33 35 }; 34 36 ··· 145 143 if (!handler) 146 144 return AE_BAD_PARAMETER; 147 145 148 - desc = gpiochip_get_desc(chip, pin); 146 + desc = gpiochip_request_own_desc(chip, pin, "ACPI:Event"); 149 147 if (IS_ERR(desc)) { 150 - dev_err(chip->dev, "Failed to get GPIO descriptor\n"); 151 - return AE_ERROR; 152 - } 153 - 154 - ret = gpiochip_request_own_desc(desc, "ACPI:Event"); 155 - if (ret) { 156 148 dev_err(chip->dev, "Failed to request GPIO\n"); 157 149 return AE_ERROR; 158 150 } ··· 193 197 event->handle = evt_handle; 194 198 event->irq = irq; 195 199 event->pin = pin; 200 + event->desc = desc; 196 201 197 202 ret = request_threaded_irq(event->irq, NULL, handler, irqflags, 198 203 "ACPI:Event", event); ··· 277 280 struct gpio_desc *desc; 278 281 279 282 free_irq(event->irq, event); 280 - desc = gpiochip_get_desc(chip, event->pin); 283 + desc = event->desc; 281 284 if (WARN_ON(IS_ERR(desc))) 282 285 continue; 283 286 gpio_unlock_as_irq(chip, event->pin); ··· 406 409 struct gpio_desc *desc; 407 410 bool found; 408 411 409 - desc = gpiochip_get_desc(chip, pin); 410 - if (IS_ERR(desc)) { 411 - status = AE_ERROR; 412 - goto out; 413 - } 414 - 415 412 mutex_lock(&achip->conn_lock); 416 413 417 414 found = false; 418 415 list_for_each_entry(conn, &achip->conns, node) { 419 - if (conn->desc == desc) { 416 + if (conn->pin == pin) { 420 417 found = true; 418 + desc = conn->desc; 421 419 break; 422 420 } 423 421 } 424 422 if (!found) { 425 - int ret; 426 - 427 - ret = gpiochip_request_own_desc(desc, "ACPI:OpRegion"); 428 - if (ret) { 423 + desc = gpiochip_request_own_desc(chip, pin, 424 + "ACPI:OpRegion"); 425 + if (IS_ERR(desc)) { 429 426 status = AE_ERROR; 430 427 mutex_unlock(&achip->conn_lock); 431 428 goto out; ··· 456 465 goto out; 457 466 } 458 467 468 + conn->pin = pin; 459 469 conn->desc = desc; 460 470 list_add_tail(&conn->node, &achip->conns); 461 471 }
+54 -36
drivers/gpio/gpiolib.c
··· 308 308 * 309 309 * A gpio_chip with any GPIOs still requested may not be removed. 310 310 */ 311 - int gpiochip_remove(struct gpio_chip *chip) 311 + void gpiochip_remove(struct gpio_chip *chip) 312 312 { 313 313 unsigned long flags; 314 - int status = 0; 315 314 unsigned id; 316 315 317 316 acpi_gpiochip_remove(chip); ··· 322 323 of_gpiochip_remove(chip); 323 324 324 325 for (id = 0; id < chip->ngpio; id++) { 325 - if (test_bit(FLAG_REQUESTED, &chip->desc[id].flags)) { 326 - status = -EBUSY; 327 - break; 328 - } 326 + if (test_bit(FLAG_REQUESTED, &chip->desc[id].flags)) 327 + dev_crit(chip->dev, "REMOVING GPIOCHIP WITH GPIOS STILL REQUESTED\n"); 329 328 } 330 - if (status == 0) { 331 - for (id = 0; id < chip->ngpio; id++) 332 - chip->desc[id].chip = NULL; 329 + for (id = 0; id < chip->ngpio; id++) 330 + chip->desc[id].chip = NULL; 333 331 334 - list_del(&chip->list); 335 - } 336 - 332 + list_del(&chip->list); 337 333 spin_unlock_irqrestore(&gpio_lock, flags); 338 - 339 - if (status == 0) 340 - gpiochip_unexport(chip); 341 - 342 - return status; 334 + gpiochip_unexport(chip); 343 335 } 344 336 EXPORT_SYMBOL_GPL(gpiochip_remove); 345 337 ··· 385 395 */ 386 396 387 397 /** 388 - * gpiochip_add_chained_irqchip() - adds a chained irqchip to a gpiochip 389 - * @gpiochip: the gpiochip to add the irqchip to 390 - * @irqchip: the irqchip to add to the gpiochip 398 + * gpiochip_set_chained_irqchip() - sets a chained irqchip to a gpiochip 399 + * @gpiochip: the gpiochip to set the irqchip chain to 400 + * @irqchip: the irqchip to chain to the gpiochip 391 401 * @parent_irq: the irq number corresponding to the parent IRQ for this 392 402 * chained irqchip 393 403 * @parent_handler: the parent interrupt handler for the accumulated IRQ 394 - * coming out of the gpiochip 404 + * coming out of the gpiochip. If the interrupt is nested rather than 405 + * cascaded, pass NULL in this handler argument 395 406 */ 396 407 void gpiochip_set_chained_irqchip(struct gpio_chip *gpiochip, 397 408 struct irq_chip *irqchip, 398 409 int parent_irq, 399 410 irq_flow_handler_t parent_handler) 400 411 { 401 - if (gpiochip->can_sleep) { 402 - chip_err(gpiochip, "you cannot have chained interrupts on a chip that may sleep\n"); 412 + unsigned int offset; 413 + 414 + if (!gpiochip->irqdomain) { 415 + chip_err(gpiochip, "called %s before setting up irqchip\n", 416 + __func__); 403 417 return; 404 418 } 405 419 406 - /* 407 - * The parent irqchip is already using the chip_data for this 408 - * irqchip, so our callbacks simply use the handler_data. 409 - */ 410 - irq_set_handler_data(parent_irq, gpiochip); 411 - irq_set_chained_handler(parent_irq, parent_handler); 420 + if (parent_handler) { 421 + if (gpiochip->can_sleep) { 422 + chip_err(gpiochip, 423 + "you cannot have chained interrupts on a " 424 + "chip that may sleep\n"); 425 + return; 426 + } 427 + /* 428 + * The parent irqchip is already using the chip_data for this 429 + * irqchip, so our callbacks simply use the handler_data. 430 + */ 431 + irq_set_handler_data(parent_irq, gpiochip); 432 + irq_set_chained_handler(parent_irq, parent_handler); 433 + } 434 + 435 + /* Set the parent IRQ for all affected IRQs */ 436 + for (offset = 0; offset < gpiochip->ngpio; offset++) 437 + irq_set_parent(irq_find_mapping(gpiochip->irqdomain, offset), 438 + parent_irq); 412 439 } 413 440 EXPORT_SYMBOL_GPL(gpiochip_set_chained_irqchip); 414 441 ··· 454 447 irq_set_lockdep_class(irq, &gpiochip_irq_lock_class); 455 448 irq_set_chip_and_handler(irq, chip->irqchip, chip->irq_handler); 456 449 /* Chips that can sleep need nested thread handlers */ 457 - if (chip->can_sleep) 450 + if (chip->can_sleep && !chip->irq_not_threaded) 458 451 irq_set_nested_thread(irq, 1); 459 452 #ifdef CONFIG_ARM 460 453 set_irq_flags(irq, IRQF_VALID); ··· 531 524 /* Remove all IRQ mappings and delete the domain */ 532 525 if (gpiochip->irqdomain) { 533 526 for (offset = 0; offset < gpiochip->ngpio; offset++) 534 - irq_dispose_mapping(gpiochip->irq_base + offset); 527 + irq_dispose_mapping( 528 + irq_find_mapping(gpiochip->irqdomain, offset)); 535 529 irq_domain_remove(gpiochip->irqdomain); 536 530 } 537 531 ··· 903 895 * allows the GPIO chip module to be unloaded as needed (we assume that the 904 896 * GPIO chip driver handles freeing the GPIOs it has requested). 905 897 */ 906 - int gpiochip_request_own_desc(struct gpio_desc *desc, const char *label) 898 + struct gpio_desc *gpiochip_request_own_desc(struct gpio_chip *chip, u16 hwnum, 899 + const char *label) 907 900 { 908 - if (!desc || !desc->chip) 909 - return -EINVAL; 901 + struct gpio_desc *desc = gpiochip_get_desc(chip, hwnum); 902 + int err; 910 903 911 - return __gpiod_request(desc, label); 904 + if (IS_ERR(desc)) { 905 + chip_err(chip, "failed to get GPIO descriptor\n"); 906 + return desc; 907 + } 908 + 909 + err = __gpiod_request(desc, label); 910 + if (err < 0) 911 + return ERR_PTR(err); 912 + 913 + return desc; 912 914 } 913 915 EXPORT_SYMBOL_GPL(gpiochip_request_own_desc); 914 916 ··· 1670 1652 * a result. In that case, use platform lookup as a fallback. 1671 1653 */ 1672 1654 if (!desc || desc == ERR_PTR(-ENOENT)) { 1673 - dev_dbg(dev, "using lookup tables for GPIO lookup"); 1655 + dev_dbg(dev, "using lookup tables for GPIO lookup\n"); 1674 1656 desc = gpiod_find(dev, con_id, idx, &lookupflags); 1675 1657 } 1676 1658
+2 -4
drivers/hid/hid-cp2112.c
··· 1069 1069 return ret; 1070 1070 1071 1071 err_gpiochip_remove: 1072 - if (gpiochip_remove(&dev->gc) < 0) 1073 - hid_err(hdev, "error removing gpio chip\n"); 1072 + gpiochip_remove(&dev->gc); 1074 1073 err_free_i2c: 1075 1074 i2c_del_adapter(&dev->adap); 1076 1075 err_free_dev: ··· 1088 1089 struct cp2112_device *dev = hid_get_drvdata(hdev); 1089 1090 1090 1091 sysfs_remove_group(&hdev->dev.kobj, &cp2112_attr_group); 1091 - if (gpiochip_remove(&dev->gc)) 1092 - hid_err(hdev, "unable to remove gpio chip\n"); 1092 + gpiochip_remove(&dev->gc); 1093 1093 i2c_del_adapter(&dev->adap); 1094 1094 /* i2c_del_adapter has finished removing all i2c devices from our 1095 1095 * adapter. Well behaved devices should no longer call our cp2112_xfer
+1 -3
drivers/input/keyboard/adp5588-keys.c
··· 251 251 dev_warn(dev, "teardown failed %d\n", error); 252 252 } 253 253 254 - error = gpiochip_remove(&kpad->gc); 255 - if (error) 256 - dev_warn(dev, "gpiochip_remove failed %d\n", error); 254 + gpiochip_remove(&kpad->gc); 257 255 } 258 256 #else 259 257 static inline int adp5588_gpio_add(struct adp5588_kpad *kpad)
+1 -3
drivers/input/keyboard/adp5589-keys.c
··· 567 567 dev_warn(dev, "teardown failed %d\n", error); 568 568 } 569 569 570 - error = gpiochip_remove(&kpad->gc); 571 - if (error) 572 - dev_warn(dev, "gpiochip_remove failed %d\n", error); 570 + gpiochip_remove(&kpad->gc); 573 571 } 574 572 #else 575 573 static inline int adp5589_gpio_add(struct adp5589_kpad *kpad)
+3 -7
drivers/input/touchscreen/ad7879.c
··· 470 470 static void ad7879_gpio_remove(struct ad7879 *ts) 471 471 { 472 472 const struct ad7879_platform_data *pdata = dev_get_platdata(ts->dev); 473 - int ret; 474 473 475 - if (pdata->gpio_export) { 476 - ret = gpiochip_remove(&ts->gc); 477 - if (ret) 478 - dev_err(ts->dev, "failed to remove gpio %d\n", 479 - ts->gc.base); 480 - } 474 + if (pdata->gpio_export) 475 + gpiochip_remove(&ts->gc); 476 + 481 477 } 482 478 #else 483 479 static inline int ad7879_gpio_add(struct ad7879 *ts,
+2 -8
drivers/leds/leds-pca9532.c
··· 319 319 } 320 320 321 321 #ifdef CONFIG_LEDS_PCA9532_GPIO 322 - if (data->gpio.dev) { 323 - int err = gpiochip_remove(&data->gpio); 324 - if (err) { 325 - dev_err(&data->client->dev, "%s failed, %d\n", 326 - "gpiochip_remove()", err); 327 - return err; 328 - } 329 - } 322 + if (data->gpio.dev) 323 + gpiochip_remove(&data->gpio); 330 324 #endif 331 325 332 326 return 0;
+2 -5
drivers/leds/leds-tca6507.c
··· 667 667 668 668 static void tca6507_remove_gpio(struct tca6507_chip *tca) 669 669 { 670 - if (tca->gpio.ngpio) { 671 - int err = gpiochip_remove(&tca->gpio); 672 - dev_err(&tca->client->dev, "%s failed, %d\n", 673 - "gpiochip_remove()", err); 674 - } 670 + if (tca->gpio.ngpio) 671 + gpiochip_remove(&tca->gpio); 675 672 } 676 673 #else /* CONFIG_GPIOLIB */ 677 674 static int tca6507_probe_gpios(struct i2c_client *client,
+3 -7
drivers/media/dvb-frontends/cxd2820r_core.c
··· 584 584 static void cxd2820r_release(struct dvb_frontend *fe) 585 585 { 586 586 struct cxd2820r_priv *priv = fe->demodulator_priv; 587 - int uninitialized_var(ret); /* silence compiler warning */ 588 587 589 588 dev_dbg(&priv->i2c->dev, "%s\n", __func__); 590 589 591 590 #ifdef CONFIG_GPIOLIB 592 591 /* remove GPIOs */ 593 - if (priv->gpio_chip.label) { 594 - ret = gpiochip_remove(&priv->gpio_chip); 595 - if (ret) 596 - dev_err(&priv->i2c->dev, "%s: gpiochip_remove() " \ 597 - "failed=%d\n", KBUILD_MODNAME, ret); 598 - } 592 + if (priv->gpio_chip.label) 593 + gpiochip_remove(&priv->gpio_chip); 594 + 599 595 #endif 600 596 kfree(priv); 601 597 return;
+2 -1
drivers/mfd/asic3.c
··· 605 605 { 606 606 struct asic3 *asic = platform_get_drvdata(pdev); 607 607 608 - return gpiochip_remove(&asic->gpio); 608 + gpiochip_remove(&asic->gpio); 609 + return 0; 609 610 } 610 611 611 612 static void asic3_clk_enable(struct asic3 *asic, struct asic3_clk *clk)
+1 -7
drivers/mfd/htc-i2cpld.c
··· 481 481 482 482 ret = gpiochip_add(&(chip->chip_in)); 483 483 if (ret) { 484 - int error; 485 - 486 484 dev_warn(dev, "Unable to register input GPIOs for 0x%x: %d\n", 487 485 plat_chip_data->addr, ret); 488 - 489 - error = gpiochip_remove(&(chip->chip_out)); 490 - if (error) 491 - dev_warn(dev, "Error while trying to unregister gpio chip: %d\n", error); 492 - 486 + gpiochip_remove(&(chip->chip_out)); 493 487 return ret; 494 488 } 495 489
+3 -14
drivers/mfd/sm501.c
··· 1047 1047 struct sm501_gpio *gpio = &sm->gpio; 1048 1048 resource_size_t iobase = sm->io_res->start + SM501_GPIO; 1049 1049 int ret; 1050 - int tmp; 1051 1050 1052 1051 dev_dbg(sm->dev, "registering gpio block %08llx\n", 1053 1052 (unsigned long long)iobase); ··· 1085 1086 return 0; 1086 1087 1087 1088 err_low_chip: 1088 - tmp = gpiochip_remove(&gpio->low.gpio); 1089 - if (tmp) { 1090 - dev_err(sm->dev, "cannot remove low chip, cannot tidy up\n"); 1091 - return ret; 1092 - } 1089 + gpiochip_remove(&gpio->low.gpio); 1093 1090 1094 1091 err_mapped: 1095 1092 iounmap(gpio->regs); ··· 1100 1105 static void sm501_gpio_remove(struct sm501_devdata *sm) 1101 1106 { 1102 1107 struct sm501_gpio *gpio = &sm->gpio; 1103 - int ret; 1104 1108 1105 1109 if (!sm->gpio.registered) 1106 1110 return; 1107 1111 1108 - ret = gpiochip_remove(&gpio->low.gpio); 1109 - if (ret) 1110 - dev_err(sm->dev, "cannot remove low chip, cannot tidy up\n"); 1111 - 1112 - ret = gpiochip_remove(&gpio->high.gpio); 1113 - if (ret) 1114 - dev_err(sm->dev, "cannot remove high chip, cannot tidy up\n"); 1112 + gpiochip_remove(&gpio->low.gpio); 1113 + gpiochip_remove(&gpio->high.gpio); 1115 1114 1116 1115 iounmap(gpio->regs); 1117 1116 release_resource(gpio->regs_res);
+4 -9
drivers/mfd/tc6393xb.c
··· 607 607 struct tc6393xb_platform_data *tcpd = dev_get_platdata(&dev->dev); 608 608 struct tc6393xb *tc6393xb; 609 609 struct resource *iomem, *rscr; 610 - int ret, temp; 610 + int ret; 611 611 612 612 iomem = platform_get_resource(dev, IORESOURCE_MEM, 0); 613 613 if (!iomem) ··· 714 714 715 715 err_gpio_add: 716 716 if (tc6393xb->gpio.base != -1) 717 - temp = gpiochip_remove(&tc6393xb->gpio); 717 + gpiochip_remove(&tc6393xb->gpio); 718 718 tcpd->disable(dev); 719 719 err_enable: 720 720 clk_disable(tc6393xb->clk); ··· 744 744 745 745 tc6393xb_detach_irq(dev); 746 746 747 - if (tc6393xb->gpio.base != -1) { 748 - ret = gpiochip_remove(&tc6393xb->gpio); 749 - if (ret) { 750 - dev_err(&dev->dev, "Can't remove gpio chip: %d\n", ret); 751 - return ret; 752 - } 753 - } 747 + if (tc6393xb->gpio.base != -1) 748 + gpiochip_remove(&tc6393xb->gpio); 754 749 755 750 ret = tcpd->disable(dev); 756 751 clk_disable(tc6393xb->clk);
+2 -6
drivers/mfd/ucb1x00-core.c
··· 621 621 struct ucb1x00_plat_data *pdata = mcp->attached_device.platform_data; 622 622 struct ucb1x00 *ucb = mcp_get_drvdata(mcp); 623 623 struct list_head *l, *n; 624 - int ret; 625 624 626 625 mutex_lock(&ucb1x00_mutex); 627 626 list_del(&ucb->node); ··· 630 631 } 631 632 mutex_unlock(&ucb1x00_mutex); 632 633 633 - if (ucb->gpio.base != -1) { 634 - ret = gpiochip_remove(&ucb->gpio); 635 - if (ret) 636 - dev_err(&ucb->dev, "Can't remove gpio chip: %d\n", ret); 637 - } 634 + if (ucb->gpio.base != -1) 635 + gpiochip_remove(&ucb->gpio); 638 636 639 637 irq_set_chained_handler(ucb->irq, NULL); 640 638 irq_free_descs(ucb->irq_base, 16);
+1 -1
drivers/pinctrl/Kconfig
··· 86 86 87 87 config PINCTRL_BCM281XX 88 88 bool "Broadcom BCM281xx pinctrl driver" 89 - depends on OF 89 + depends on OF && (ARCH_BCM_MOBILE || COMPILE_TEST) 90 90 select PINMUX 91 91 select PINCONF 92 92 select GENERIC_PINCONF
+3 -13
drivers/pinctrl/nomadik/pinctrl-abx500.c
··· 1174 1174 const struct of_device_id *match; 1175 1175 struct abx500_pinctrl *pct; 1176 1176 unsigned int id = -1; 1177 - int ret, err; 1177 + int ret; 1178 1178 int i; 1179 1179 1180 1180 if (!np) { ··· 1266 1266 return 0; 1267 1267 1268 1268 out_rem_chip: 1269 - err = gpiochip_remove(&pct->chip); 1270 - if (err) 1271 - dev_info(&pdev->dev, "failed to remove gpiochip\n"); 1272 - 1269 + gpiochip_remove(&pct->chip); 1273 1270 return ret; 1274 1271 } 1275 1272 ··· 1277 1280 static int abx500_gpio_remove(struct platform_device *pdev) 1278 1281 { 1279 1282 struct abx500_pinctrl *pct = platform_get_drvdata(pdev); 1280 - int ret; 1281 1283 1282 - ret = gpiochip_remove(&pct->chip); 1283 - if (ret < 0) { 1284 - dev_err(pct->dev, "unable to remove gpiochip: %d\n", 1285 - ret); 1286 - return ret; 1287 - } 1288 - 1284 + gpiochip_remove(&pct->chip); 1289 1285 return 0; 1290 1286 } 1291 1287
+1 -1
drivers/pinctrl/nomadik/pinctrl-nomadik.c
··· 1276 1276 IRQ_TYPE_EDGE_FALLING); 1277 1277 if (ret) { 1278 1278 dev_err(&dev->dev, "could not add irqchip\n"); 1279 - ret = gpiochip_remove(&nmk_chip->chip); 1279 + gpiochip_remove(&nmk_chip->chip); 1280 1280 return -ENODEV; 1281 1281 } 1282 1282 /* Then register the chain on the parent IRQ */
+1 -7
drivers/pinctrl/qcom/pinctrl-msm.c
··· 936 936 int msm_pinctrl_remove(struct platform_device *pdev) 937 937 { 938 938 struct msm_pinctrl *pctrl = platform_get_drvdata(pdev); 939 - int ret; 940 939 941 - ret = gpiochip_remove(&pctrl->chip); 942 - if (ret) { 943 - dev_err(&pdev->dev, "Failed to remove gpiochip\n"); 944 - return ret; 945 - } 946 - 940 + gpiochip_remove(&pctrl->chip); 947 941 pinctrl_unregister(pctrl->pctrl); 948 942 949 943 unregister_restart_handler(&pctrl->restart_nb);
+1 -5
drivers/pinctrl/samsung/pinctrl-exynos5440.c
··· 874 874 static int exynos5440_gpiolib_unregister(struct platform_device *pdev, 875 875 struct exynos5440_pinctrl_priv_data *priv) 876 876 { 877 - int ret = gpiochip_remove(priv->gc); 878 - if (ret) { 879 - dev_err(&pdev->dev, "gpio chip remove failed\n"); 880 - return ret; 881 - } 877 + gpiochip_remove(priv->gc); 882 878 return 0; 883 879 } 884 880
+4 -11
drivers/pinctrl/samsung/pinctrl-samsung.c
··· 946 946 947 947 fail: 948 948 for (--i, --bank; i >= 0; --i, --bank) 949 - if (gpiochip_remove(&bank->gpio_chip)) 950 - dev_err(&pdev->dev, "gpio chip %s remove failed\n", 951 - bank->gpio_chip.label); 949 + gpiochip_remove(&bank->gpio_chip); 952 950 return ret; 953 951 } 954 952 ··· 956 958 { 957 959 struct samsung_pin_ctrl *ctrl = drvdata->ctrl; 958 960 struct samsung_pin_bank *bank = ctrl->pin_banks; 959 - int ret = 0; 960 961 int i; 961 962 962 - for (i = 0; !ret && i < ctrl->nr_banks; ++i, ++bank) 963 - ret = gpiochip_remove(&bank->gpio_chip); 964 - 965 - if (ret) 966 - dev_err(&pdev->dev, "gpio chip remove failed\n"); 967 - 968 - return ret; 963 + for (i = 0; i < ctrl->nr_banks; ++i, ++bank) 964 + gpiochip_remove(&bank->gpio_chip); 965 + return 0; 969 966 } 970 967 971 968 static const struct of_device_id samsung_pinctrl_dt_match[];
+1 -2
drivers/pinctrl/sirf/pinctrl-sirf.c
··· 891 891 892 892 out_no_range: 893 893 out_banks: 894 - if (gpiochip_remove(&sgpio->chip.gc)) 895 - dev_err(&pdev->dev, "could not remove gpio chip\n"); 894 + gpiochip_remove(&sgpio->chip.gc); 896 895 out: 897 896 iounmap(regs); 898 897 return err;
+1 -2
drivers/platform/x86/intel_pmic_gpio.c
··· 301 301 return 0; 302 302 303 303 fail_request_irq: 304 - if (gpiochip_remove(&pg->chip)) 305 - pr_err("gpiochip_remove failed\n"); 304 + gpiochip_remove(&pg->chip); 306 305 err: 307 306 iounmap(pg->gpiointr); 308 307 err2:
+2 -1
drivers/ssb/driver_gpio.c
··· 475 475 { 476 476 if (ssb_chipco_available(&bus->chipco) || 477 477 ssb_extif_available(&bus->extif)) { 478 - return gpiochip_remove(&bus->gpio); 478 + gpiochip_remove(&bus->gpio); 479 + return 0; 479 480 } else { 480 481 SSB_WARN_ON(1); 481 482 }
+1 -3
drivers/staging/vme/devices/vme_pio2_gpio.c
··· 221 221 { 222 222 const char *label = card->gc.label; 223 223 224 - if (gpiochip_remove(&(card->gc))) 225 - dev_err(&card->vdev->dev, "Failed to remove GPIO\n"); 226 - 224 + gpiochip_remove(&(card->gc)); 227 225 kfree(label); 228 226 } 229 227
+4 -6
drivers/tty/serial/max310x.c
··· 1248 1248 mutex_destroy(&s->mutex); 1249 1249 1250 1250 #ifdef CONFIG_GPIOLIB 1251 - WARN_ON(gpiochip_remove(&s->gpio)); 1251 + gpiochip_remove(&s->gpio); 1252 1252 1253 1253 out_uart: 1254 1254 #endif ··· 1263 1263 static int max310x_remove(struct device *dev) 1264 1264 { 1265 1265 struct max310x_port *s = dev_get_drvdata(dev); 1266 - int i, ret = 0; 1266 + int i; 1267 1267 1268 1268 #ifdef CONFIG_GPIOLIB 1269 - ret = gpiochip_remove(&s->gpio); 1270 - if (ret) 1271 - return ret; 1269 + gpiochip_remove(&s->gpio); 1272 1270 #endif 1273 1271 1274 1272 for (i = 0; i < s->uart.nr; i++) { ··· 1280 1282 uart_unregister_driver(&s->uart); 1281 1283 clk_disable_unprepare(s->clk); 1282 1284 1283 - return ret; 1285 + return 0; 1284 1286 } 1285 1287 1286 1288 static const struct of_device_id __maybe_unused max310x_dt_ids[] = {
+5 -8
drivers/tty/serial/sc16is7xx.c
··· 1157 1157 1158 1158 #ifdef CONFIG_GPIOLIB 1159 1159 if (devtype->nr_gpio) 1160 - WARN_ON(gpiochip_remove(&s->gpio)); 1160 + gpiochip_remove(&s->gpio); 1161 1161 1162 1162 out_uart: 1163 1163 #endif ··· 1173 1173 static int sc16is7xx_remove(struct device *dev) 1174 1174 { 1175 1175 struct sc16is7xx_port *s = dev_get_drvdata(dev); 1176 - int i, ret = 0; 1176 + int i; 1177 1177 1178 1178 #ifdef CONFIG_GPIOLIB 1179 - if (s->devtype->nr_gpio) { 1180 - ret = gpiochip_remove(&s->gpio); 1181 - if (ret) 1182 - return ret; 1183 - } 1179 + if (s->devtype->nr_gpio) 1180 + gpiochip_remove(&s->gpio); 1184 1181 #endif 1185 1182 1186 1183 for (i = 0; i < s->uart.nr; i++) { ··· 1192 1195 if (!IS_ERR(s->clk)) 1193 1196 clk_disable_unprepare(s->clk); 1194 1197 1195 - return ret; 1198 + return 0; 1196 1199 } 1197 1200 1198 1201 static const struct of_device_id __maybe_unused sc16is7xx_dt_ids[] = {
+3 -7
drivers/video/fbdev/via/via-gpio.c
··· 270 270 static int viafb_gpio_remove(struct platform_device *platdev) 271 271 { 272 272 unsigned long flags; 273 - int ret = 0, i; 273 + int i; 274 274 275 275 #ifdef CONFIG_PM 276 276 viafb_pm_unregister(&viafb_gpio_pm_hooks); ··· 280 280 * Get unregistered. 281 281 */ 282 282 if (viafb_gpio_config.gpio_chip.ngpio > 0) { 283 - ret = gpiochip_remove(&viafb_gpio_config.gpio_chip); 284 - if (ret) { /* Somebody still using it? */ 285 - printk(KERN_ERR "Viafb: GPIO remove failed\n"); 286 - return ret; 287 - } 283 + gpiochip_remove(&viafb_gpio_config.gpio_chip); 288 284 } 289 285 /* 290 286 * Disable the ports. ··· 290 294 viafb_gpio_disable(viafb_gpio_config.active_gpios[i]); 291 295 viafb_gpio_config.gpio_chip.ngpio = 0; 292 296 spin_unlock_irqrestore(&viafb_gpio_config.vdev->reg_lock, flags); 293 - return ret; 297 + return 0; 294 298 } 295 299 296 300 static struct platform_driver via_gpio_driver = {
+1 -1
include/asm-generic/gpio.h
··· 27 27 */ 28 28 29 29 #ifndef ARCH_NR_GPIOS 30 - #define ARCH_NR_GPIOS 256 30 + #define ARCH_NR_GPIOS 512 31 31 #endif 32 32 33 33 /*
+6 -2
include/linux/gpio/driver.h
··· 56 56 * as the chip access may sleep when e.g. reading out the IRQ status 57 57 * registers. 58 58 * @exported: flags if the gpiochip is exported for use from sysfs. Private. 59 + * @irq_not_threaded: flag must be set if @can_sleep is set but the 60 + * IRQs don't need to be threaded 59 61 * 60 62 * A gpio_chip can help platforms abstract various sources of GPIOs so 61 63 * they can all be accessed through a common programing interface. ··· 103 101 struct gpio_desc *desc; 104 102 const char *const *names; 105 103 bool can_sleep; 104 + bool irq_not_threaded; 106 105 bool exported; 107 106 108 107 #ifdef CONFIG_GPIOLIB_IRQCHIP ··· 144 141 145 142 /* add/remove chips */ 146 143 extern int gpiochip_add(struct gpio_chip *chip); 147 - extern int gpiochip_remove(struct gpio_chip *chip); 144 + extern void gpiochip_remove(struct gpio_chip *chip); 148 145 extern struct gpio_chip *gpiochip_find(void *data, 149 146 int (*match)(struct gpio_chip *chip, void *data)); 150 147 ··· 169 166 170 167 #endif /* CONFIG_GPIOLIB_IRQCHIP */ 171 168 172 - int gpiochip_request_own_desc(struct gpio_desc *desc, const char *label); 169 + struct gpio_desc *gpiochip_request_own_desc(struct gpio_chip *chip, u16 hwnum, 170 + const char *label); 173 171 void gpiochip_free_own_desc(struct gpio_desc *desc); 174 172 175 173 #else /* CONFIG_GPIOLIB */
+32
include/linux/platform_data/gpio-dwapb.h
··· 1 + /* 2 + * Copyright(c) 2014 Intel Corporation. 3 + * 4 + * This program is free software; you can redistribute it and/or modify it 5 + * under the terms and conditions of the GNU General Public License, 6 + * version 2, as published by the Free Software Foundation. 7 + * 8 + * This program is distributed in the hope it will be useful, but WITHOUT 9 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 10 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 11 + * more details. 12 + */ 13 + 14 + #ifndef GPIO_DW_APB_H 15 + #define GPIO_DW_APB_H 16 + 17 + struct dwapb_port_property { 18 + struct device_node *node; 19 + const char *name; 20 + unsigned int idx; 21 + unsigned int ngpio; 22 + unsigned int gpio_base; 23 + unsigned int irq; 24 + bool irq_shared; 25 + }; 26 + 27 + struct dwapb_platform_data { 28 + struct dwapb_port_property *properties; 29 + unsigned int nports; 30 + }; 31 + 32 + #endif
+18
include/linux/spi/mcp23s08.h
··· 22 22 * base to base+15 (or base+31 for s17 variant). 23 23 */ 24 24 unsigned base; 25 + /* Marks the device as a interrupt controller. 26 + * NOTE: The interrupt functionality is only supported for i2c 27 + * versions of the chips. The spi chips can also do the interrupts, 28 + * but this is not supported by the linux driver yet. 29 + */ 30 + bool irq_controller; 31 + 32 + /* Sets the mirror flag in the IOCON register. Devices 33 + * with two interrupt outputs (these are the devices ending with 17 and 34 + * those that have 16 IOs) have two IO banks: IO 0-7 form bank 1 and 35 + * IO 8-15 are bank 2. These chips have two different interrupt outputs: 36 + * One for bank 1 and another for bank 2. If irq-mirror is set, both 37 + * interrupts are generated regardless of the bank that an input change 38 + * occurred on. If it is not set, the interrupt are only generated for 39 + * the bank they belong to. 40 + * On devices with only one interrupt output this property is useless. 41 + */ 42 + bool mirror; 25 43 };
+1 -4
sound/soc/codecs/wm5100.c
··· 2319 2319 static void wm5100_free_gpio(struct i2c_client *i2c) 2320 2320 { 2321 2321 struct wm5100_priv *wm5100 = i2c_get_clientdata(i2c); 2322 - int ret; 2323 2322 2324 - ret = gpiochip_remove(&wm5100->gpio_chip); 2325 - if (ret != 0) 2326 - dev_err(&i2c->dev, "Failed to remove GPIOs: %d\n", ret); 2323 + gpiochip_remove(&wm5100->gpio_chip); 2327 2324 } 2328 2325 #else 2329 2326 static void wm5100_init_gpio(struct i2c_client *i2c)
+1 -5
sound/soc/codecs/wm8903.c
··· 1877 1877 1878 1878 static void wm8903_free_gpio(struct wm8903_priv *wm8903) 1879 1879 { 1880 - int ret; 1881 - 1882 - ret = gpiochip_remove(&wm8903->gpio_chip); 1883 - if (ret != 0) 1884 - dev_err(wm8903->dev, "Failed to remove GPIOs: %d\n", ret); 1880 + gpiochip_remove(&wm8903->gpio_chip); 1885 1881 } 1886 1882 #else 1887 1883 static void wm8903_init_gpio(struct wm8903_priv *wm8903)
+1 -4
sound/soc/codecs/wm8962.c
··· 3398 3398 static void wm8962_free_gpio(struct snd_soc_codec *codec) 3399 3399 { 3400 3400 struct wm8962_priv *wm8962 = snd_soc_codec_get_drvdata(codec); 3401 - int ret; 3402 3401 3403 - ret = gpiochip_remove(&wm8962->gpio_chip); 3404 - if (ret != 0) 3405 - dev_err(codec->dev, "Failed to remove GPIOs: %d\n", ret); 3402 + gpiochip_remove(&wm8962->gpio_chip); 3406 3403 } 3407 3404 #else 3408 3405 static void wm8962_init_gpio(struct snd_soc_codec *codec)
+1 -5
sound/soc/codecs/wm8996.c
··· 2216 2216 2217 2217 static void wm8996_free_gpio(struct wm8996_priv *wm8996) 2218 2218 { 2219 - int ret; 2220 - 2221 - ret = gpiochip_remove(&wm8996->gpio_chip); 2222 - if (ret != 0) 2223 - dev_err(wm8996->dev, "Failed to remove GPIOs: %d\n", ret); 2219 + gpiochip_remove(&wm8996->gpio_chip); 2224 2220 } 2225 2221 #else 2226 2222 static void wm8996_init_gpio(struct wm8996_priv *wm8996)