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

Merge tag 'gpio-v3.16-1' of git://git.kernel.org/pub/scm/linux/kernel/git/linusw/linux-gpio into next

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

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

Details:

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

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

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

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

* Switch the tc3589x GPIO expanders to use the irqchip helpers

* Switch the OMAP GPIO driver to use the irqchip helpers

* Add some documentation for the irqchip helpers

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

- Continued GPIO descriptor refactoring:

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

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

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

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

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

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

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

* tag 'gpio-v3.16-1' of git://git.kernel.org/pub/scm/linux/kernel/git/linusw/linux-gpio: (85 commits)
gpio: select IRQ_DOMAIN for gpiolib irqchip helpers
gpio: pca953x: use gpiolib irqchip helpers
gpio: pcf857x: Add IRQF_SHARED when request irq
gpio: pcf857x: Avoid calling irq_domain_cleanup twice
gpio: mcp23s08: switch chip count to int
gpio: dwapb: use a second irq chip
gpio: ep93xx: Use devm_ioremap_resource()
gpio: mcp23s08: fixed count variable for devicetree probing
gpio: Add run-time dependencies to R-Car driver
gpio: pch: add slab include
Documentation / ACPI: Fix location of GPIO documentation
gpio / ACPI: use *_cansleep version of gpiod_get/set APIs
gpio: generic: add request function pointer
gpio-pch: Fix Kconfig dependencies
gpio: make of_get_named_gpiod_flags() private
gpio: gpioep93xx: use devm functions
gpio: janzttl: use devm function
gpio: timberdale: use devm functions
gpio: bt8xx: use devm function for memory allocation
gpio: include linux/bug.h in interface header
...

+706 -687
+1 -1
Documentation/acpi/enumeration.txt
··· 296 296 we need to translate them to the corresponding Linux GPIO descriptors. 297 297 298 298 There is a standard GPIO API for that and is documented in 299 - Documentation/gpio.txt. 299 + Documentation/gpio/. 300 300 301 301 In the above example we can get the corresponding two GPIO descriptors with 302 302 a code like this:
+6
Documentation/devicetree/bindings/gpio/renesas,gpio-rcar.txt
··· 21 21 GPIO_ACTIVE_HIGH and GPIO_ACTIVE_LOW flags are supported. 22 22 - gpio-ranges: Range of pins managed by the GPIO controller. 23 23 24 + Optional properties: 25 + 26 + - clocks: Must contain a reference to the functional clock. The property is 27 + mandatory if the hardware implements a controllable functional clock for 28 + the GPIO instance. 29 + 24 30 Please refer to gpio.txt in this directory for details of gpio-ranges property 25 31 and the common GPIO bindings used by client devices. 26 32
+7
Documentation/driver-model/devres.txt
··· 308 308 309 309 SPI 310 310 devm_spi_register_master() 311 + 312 + GPIO 313 + devm_gpiod_get() 314 + devm_gpiod_get_index() 315 + devm_gpiod_get_optional() 316 + devm_gpiod_get_index_optional() 317 + devm_gpiod_put()
+59
Documentation/gpio/driver.txt
··· 73 73 the header <linux/irq.h>. So basically such a driver is utilizing two sub- 74 74 systems simultaneously: gpio and irq. 75 75 76 + GPIO irqchips usually fall in one of two categories: 77 + 78 + * CHAINED GPIO irqchips: these are usually the type that is embedded on 79 + an SoC. This means that there is a fast IRQ handler for the GPIOs that 80 + gets called in a chain from the parent IRQ handler, most typically the 81 + system interrupt controller. This means the GPIO irqchip is registered 82 + using irq_set_chained_handler() or the corresponding 83 + gpiochip_set_chained_irqchip() helper function, and the GPIO irqchip 84 + handler will be called immediately from the parent irqchip, while 85 + holding the IRQs disabled. The GPIO irqchip will then end up calling 86 + something like this sequence in its interrupt handler: 87 + 88 + static irqreturn_t tc3589x_gpio_irq(int irq, void *data) 89 + chained_irq_enter(...); 90 + generic_handle_irq(...); 91 + chained_irq_exit(...); 92 + 93 + Chained GPIO irqchips typically can NOT set the .can_sleep flag on 94 + struct gpio_chip, as everything happens directly in the callbacks. 95 + 96 + * NESTED THREADED GPIO irqchips: these are off-chip GPIO expanders and any 97 + other GPIO irqchip residing on the other side of a sleeping bus. Of course 98 + such drivers that need slow bus traffic to read out IRQ status and similar, 99 + traffic which may in turn incur other IRQs to happen, cannot be handled 100 + in a quick IRQ handler with IRQs disabled. Instead they need to spawn a 101 + thread and then mask the parent IRQ line until the interrupt is handled 102 + by the driver. The hallmark of this driver is to call something like 103 + this in its interrupt handler: 104 + 105 + static irqreturn_t tc3589x_gpio_irq(int irq, void *data) 106 + ... 107 + handle_nested_irq(irq); 108 + 109 + The hallmark of threaded GPIO irqchips is that they set the .can_sleep 110 + flag on struct gpio_chip to true, indicating that this chip may sleep 111 + when accessing the GPIOs. 112 + 113 + To help out in handling the set-up and management of GPIO irqchips and the 114 + associated irqdomain and resource allocation callbacks, the gpiolib has 115 + some helpers that can be enabled by selecting the GPIOLIB_IRQCHIP Kconfig 116 + symbol: 117 + 118 + * gpiochip_irqchip_add(): adds an irqchip to a gpiochip. It will pass 119 + the struct gpio_chip* for the chip to all IRQ callbacks, so the callbacks 120 + need to embed the gpio_chip in its state container and obtain a pointer 121 + to the container using container_of(). 122 + (See Documentation/driver-model/design-patterns.txt) 123 + 124 + * gpiochip_set_chained_irqchip(): sets up a chained irq handler for a 125 + gpio_chip from a parent IRQ and passes the struct gpio_chip* as handler 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. 128 + 129 + To use the helpers please keep the following in mind: 130 + 131 + - Make sure to assign all relevant members of the struct gpio_chip so that 132 + the irqchip can initialize. E.g. .dev and .can_sleep shall be set up 133 + properly. 134 + 76 135 It is legal for any IRQ consumer to request an IRQ from any irqchip no matter 77 136 if that is a combined GPIO+IRQ driver. The basic premise is that gpio_chip and 78 137 irq_chip are orthogonal, and offering their services independent of each
+1
MAINTAINERS
··· 6418 6418 F: arch/arm/*omap*/usb* 6419 6419 6420 6420 OMAP GPIO DRIVER 6421 + M: Javier Martinez Canillas <javier@dowhile0.org> 6421 6422 M: Santosh Shilimkar <santosh.shilimkar@ti.com> 6422 6423 M: Kevin Hilman <khilman@deeprootsystems.com> 6423 6424 L: linux-omap@vger.kernel.org
+16 -4
drivers/gpio/Kconfig
··· 56 56 depends on ACPI 57 57 58 58 config GPIOLIB_IRQCHIP 59 + select IRQ_DOMAIN 59 60 bool 60 61 61 62 config DEBUG_GPIO ··· 244 243 Say yes here to support the on-chip GPIO lines on the OCTEON 245 244 family of SOCs. 246 245 246 + config GPIO_OMAP 247 + bool "TI OMAP GPIO support" if COMPILE_TEST && !ARCH_OMAP2PLUS 248 + default y if ARCH_OMAP 249 + depends on ARM 250 + select GENERIC_IRQ_CHIP 251 + select GPIOLIB_IRQCHIP 252 + help 253 + Say yes here to enable GPIO support for TI OMAP SoCs. 254 + 247 255 config GPIO_PL061 248 256 bool "PrimeCell PL061 GPIO support" 249 257 depends on ARM_AMBA ··· 269 259 270 260 config GPIO_RCAR 271 261 tristate "Renesas R-Car GPIO" 272 - depends on ARM 262 + depends on ARM && (ARCH_SHMOBILE || COMPILE_TEST) 273 263 help 274 264 Say yes here to support GPIO on Renesas R-Car SoCs. 275 265 ··· 520 510 config GPIO_PCA953X_IRQ 521 511 bool "Interrupt controller support for PCA953x" 522 512 depends on GPIO_PCA953X=y 513 + select GPIOLIB_IRQCHIP 523 514 help 524 515 Say yes here to enable the pca953x to be used as an interrupt 525 516 controller. It requires the driver to be built in the kernel. ··· 590 579 config GPIO_TC3589X 591 580 bool "TC3589X GPIOs" 592 581 depends on MFD_TC3589X 582 + select GPIOLIB_IRQCHIP 593 583 help 594 584 This enables support for the GPIOs found on the TC3589X 595 585 I/O Expander. ··· 711 699 config GPIO_INTEL_MID 712 700 bool "Intel Mid GPIO support" 713 701 depends on PCI && X86 714 - select IRQ_DOMAIN 702 + select GPIOLIB_IRQCHIP 715 703 help 716 704 Say Y here to support Intel Mid GPIO. 717 705 718 706 config GPIO_PCH 719 707 tristate "Intel EG20T PCH/LAPIS Semiconductor IOH(ML7223/ML7831) GPIO" 720 - depends on PCI && X86 708 + depends on PCI && (X86_32 || COMPILE_TEST) 721 709 select GENERIC_IRQ_CHIP 722 710 help 723 711 This driver is for PCH(Platform controller Hub) GPIO of Intel Topcliff ··· 751 739 752 740 config GPIO_TIMBERDALE 753 741 bool "Support for timberdale GPIO IP" 754 - depends on MFD_TIMBERDALE && HAS_IOMEM 742 + depends on MFD_TIMBERDALE 755 743 ---help--- 756 744 Add support for the GPIO IP in the timberdale FPGA. 757 745
+1 -1
drivers/gpio/Makefile
··· 58 58 obj-$(CONFIG_GPIO_MXC) += gpio-mxc.o 59 59 obj-$(CONFIG_GPIO_MXS) += gpio-mxs.o 60 60 obj-$(CONFIG_GPIO_OCTEON) += gpio-octeon.o 61 - obj-$(CONFIG_ARCH_OMAP) += gpio-omap.o 61 + obj-$(CONFIG_GPIO_OMAP) += gpio-omap.o 62 62 obj-$(CONFIG_GPIO_PCA953X) += gpio-pca953x.o 63 63 obj-$(CONFIG_GPIO_PCF857X) += gpio-pcf857x.o 64 64 obj-$(CONFIG_GPIO_PCH) += gpio-pch.o
+43
drivers/gpio/devres.c
··· 52 52 EXPORT_SYMBOL(devm_gpiod_get); 53 53 54 54 /** 55 + * devm_gpiod_get_optional - Resource-managed gpiod_get_optional() 56 + * @dev: GPIO consumer 57 + * @con_id: function within the GPIO consumer 58 + * 59 + * Managed gpiod_get_optional(). GPIO descriptors returned from this function 60 + * are automatically disposed on driver detach. See gpiod_get_optional() for 61 + * detailed information about behavior and return values. 62 + */ 63 + struct gpio_desc *__must_check devm_gpiod_get_optional(struct device *dev, 64 + const char *con_id) 65 + { 66 + return devm_gpiod_get_index_optional(dev, con_id, 0); 67 + } 68 + EXPORT_SYMBOL(devm_gpiod_get_optional); 69 + 70 + /** 55 71 * devm_gpiod_get_index - Resource-managed gpiod_get_index() 56 72 * @dev: GPIO consumer 57 73 * @con_id: function within the GPIO consumer ··· 101 85 return desc; 102 86 } 103 87 EXPORT_SYMBOL(devm_gpiod_get_index); 88 + 89 + /** 90 + * devm_gpiod_get_index_optional - Resource-managed gpiod_get_index_optional() 91 + * @dev: GPIO consumer 92 + * @con_id: function within the GPIO consumer 93 + * @index: index of the GPIO to obtain in the consumer 94 + * 95 + * Managed gpiod_get_index_optional(). GPIO descriptors returned from this 96 + * function are automatically disposed on driver detach. See 97 + * gpiod_get_index_optional() for detailed information about behavior and 98 + * return values. 99 + */ 100 + struct gpio_desc *__must_check devm_gpiod_get_index_optional(struct device *dev, 101 + const char *con_id, 102 + unsigned int index) 103 + { 104 + struct gpio_desc *desc; 105 + 106 + desc = devm_gpiod_get_index(dev, con_id, index); 107 + if (IS_ERR(desc)) { 108 + if (PTR_ERR(desc) == -ENOENT) 109 + return NULL; 110 + } 111 + 112 + return desc; 113 + } 114 + EXPORT_SYMBOL(devm_gpiod_get_index_optional); 104 115 105 116 /** 106 117 * devm_gpiod_put - Resource-managed gpiod_put()
+1 -3
drivers/gpio/gpio-adp5520.c
··· 106 106 } 107 107 108 108 dev = devm_kzalloc(&pdev->dev, sizeof(*dev), GFP_KERNEL); 109 - if (dev == NULL) { 110 - dev_err(&pdev->dev, "failed to alloc memory\n"); 109 + if (dev == NULL) 111 110 return -ENOMEM; 112 - } 113 111 114 112 dev->master = pdev->dev.parent; 115 113
+1 -3
drivers/gpio/gpio-adp5588.c
··· 379 379 } 380 380 381 381 dev = kzalloc(sizeof(*dev), GFP_KERNEL); 382 - if (dev == NULL) { 383 - dev_err(&client->dev, "failed to alloc memory\n"); 382 + if (dev == NULL) 384 383 return -ENOMEM; 385 - } 386 384 387 385 dev->client = client; 388 386
+6 -13
drivers/gpio/gpio-bt8xx.c
··· 178 178 struct bt8xxgpio *bg; 179 179 int err; 180 180 181 - bg = kzalloc(sizeof(*bg), GFP_KERNEL); 181 + bg = devm_kzalloc(&dev->dev, sizeof(struct bt8xxgpio), GFP_KERNEL); 182 182 if (!bg) 183 183 return -ENOMEM; 184 184 ··· 188 188 err = pci_enable_device(dev); 189 189 if (err) { 190 190 printk(KERN_ERR "bt8xxgpio: Can't enable device.\n"); 191 - goto err_freebg; 191 + return err; 192 192 } 193 - if (!request_mem_region(pci_resource_start(dev, 0), 193 + if (!devm_request_mem_region(&dev->dev, pci_resource_start(dev, 0), 194 194 pci_resource_len(dev, 0), 195 195 "bt8xxgpio")) { 196 196 printk(KERN_WARNING "bt8xxgpio: Can't request iomem (0x%llx).\n", ··· 201 201 pci_set_master(dev); 202 202 pci_set_drvdata(dev, bg); 203 203 204 - bg->mmio = ioremap(pci_resource_start(dev, 0), 0x1000); 204 + bg->mmio = devm_ioremap(&dev->dev, pci_resource_start(dev, 0), 0x1000); 205 205 if (!bg->mmio) { 206 206 printk(KERN_ERR "bt8xxgpio: ioremap() failed\n"); 207 207 err = -EIO; 208 - goto err_release_mem; 208 + goto err_disable; 209 209 } 210 210 211 211 /* Disable interrupts */ ··· 220 220 err = gpiochip_add(&bg->gpio); 221 221 if (err) { 222 222 printk(KERN_ERR "bt8xxgpio: Failed to register GPIOs\n"); 223 - goto err_release_mem; 223 + goto err_disable; 224 224 } 225 225 226 226 return 0; 227 227 228 - err_release_mem: 229 - release_mem_region(pci_resource_start(dev, 0), 230 - pci_resource_len(dev, 0)); 231 228 err_disable: 232 229 pci_disable_device(dev); 233 - err_freebg: 234 - kfree(bg); 235 230 236 231 return err; 237 232 } ··· 245 250 release_mem_region(pci_resource_start(pdev, 0), 246 251 pci_resource_len(pdev, 0)); 247 252 pci_disable_device(pdev); 248 - 249 - kfree(bg); 250 253 } 251 254 252 255 #ifdef CONFIG_PM
+1 -3
drivers/gpio/gpio-davinci.c
··· 230 230 chips = devm_kzalloc(dev, 231 231 ngpio * sizeof(struct davinci_gpio_controller), 232 232 GFP_KERNEL); 233 - if (!chips) { 234 - dev_err(dev, "Memory allocation failed\n"); 233 + if (!chips) 235 234 return -ENOMEM; 236 - } 237 235 238 236 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 239 237 if (!res) {
+21 -15
drivers/gpio/gpio-dwapb.c
··· 198 198 break; 199 199 } 200 200 201 + irq_setup_alt_chip(d, type); 202 + 201 203 writel(level, gpio->regs + GPIO_INTTYPE_LEVEL); 202 204 writel(polarity, gpio->regs + GPIO_INT_POLARITY); 203 205 spin_unlock_irqrestore(&bgc->lock, flags); ··· 215 213 struct irq_chip_generic *irq_gc; 216 214 unsigned int hwirq, ngpio = gc->ngpio; 217 215 struct irq_chip_type *ct; 218 - int err, irq; 216 + int err, irq, i; 219 217 220 218 irq = irq_of_parse_and_map(node, 0); 221 219 if (!irq) { ··· 229 227 if (!gpio->domain) 230 228 return; 231 229 232 - err = irq_alloc_domain_generic_chips(gpio->domain, ngpio, 1, 230 + err = irq_alloc_domain_generic_chips(gpio->domain, ngpio, 2, 233 231 "gpio-dwapb", handle_level_irq, 234 232 IRQ_NOREQUEST, 0, 235 233 IRQ_GC_INIT_NESTED_LOCK); ··· 250 248 irq_gc->reg_base = gpio->regs; 251 249 irq_gc->private = gpio; 252 250 253 - ct = irq_gc->chip_types; 254 - ct->chip.irq_ack = irq_gc_ack_set_bit; 255 - ct->chip.irq_mask = irq_gc_mask_set_bit; 256 - ct->chip.irq_unmask = irq_gc_mask_clr_bit; 257 - ct->chip.irq_set_type = dwapb_irq_set_type; 258 - ct->chip.irq_enable = dwapb_irq_enable; 259 - ct->chip.irq_disable = dwapb_irq_disable; 260 - ct->chip.irq_request_resources = dwapb_irq_reqres; 261 - ct->chip.irq_release_resources = dwapb_irq_relres; 262 - ct->regs.ack = GPIO_PORTA_EOI; 263 - ct->regs.mask = GPIO_INTMASK; 251 + for (i = 0; i < 2; i++) { 252 + ct = &irq_gc->chip_types[i]; 253 + ct->chip.irq_ack = irq_gc_ack_set_bit; 254 + ct->chip.irq_mask = irq_gc_mask_set_bit; 255 + ct->chip.irq_unmask = irq_gc_mask_clr_bit; 256 + ct->chip.irq_set_type = dwapb_irq_set_type; 257 + ct->chip.irq_enable = dwapb_irq_enable; 258 + ct->chip.irq_disable = dwapb_irq_disable; 259 + ct->chip.irq_request_resources = dwapb_irq_reqres; 260 + ct->chip.irq_release_resources = dwapb_irq_relres; 261 + ct->regs.ack = GPIO_PORTA_EOI; 262 + ct->regs.mask = GPIO_INTMASK; 263 + ct->type = IRQ_TYPE_LEVEL_MASK; 264 + } 264 265 265 - irq_setup_generic_chip(irq_gc, IRQ_MSK(port->bgc.gc.ngpio), 266 - IRQ_GC_INIT_NESTED_LOCK, IRQ_NOREQUEST, 0); 266 + irq_gc->chip_types[0].type = IRQ_TYPE_LEVEL_MASK; 267 + irq_gc->chip_types[1].type = IRQ_TYPE_EDGE_BOTH; 268 + irq_gc->chip_types[1].handler = handle_edge_irq; 267 269 268 270 irq_set_chained_handler(irq, dwapb_irq_handler); 269 271 irq_set_handler_data(irq, gpio);
+1 -2
drivers/gpio/gpio-em.c
··· 212 212 { 213 213 /* upper 16 bits contains mask and lower 16 actual value */ 214 214 em_gio_write(gpio_to_priv(chip), reg, 215 - (1 << (shift + 16)) | (value << shift)); 215 + (BIT(shift + 16)) | (value << shift)); 216 216 } 217 217 218 218 static void em_gio_set(struct gpio_chip *chip, unsigned offset, int value) ··· 284 284 285 285 p = devm_kzalloc(&pdev->dev, sizeof(*p), GFP_KERNEL); 286 286 if (!p) { 287 - dev_err(&pdev->dev, "failed to allocate driver data\n"); 288 287 ret = -ENOMEM; 289 288 goto err0; 290 289 }
+7 -27
drivers/gpio/gpio-ep93xx.c
··· 344 344 { 345 345 struct ep93xx_gpio *ep93xx_gpio; 346 346 struct resource *res; 347 - void __iomem *mmio; 348 347 int i; 349 - int ret; 348 + struct device *dev = &pdev->dev; 350 349 351 - ep93xx_gpio = kzalloc(sizeof(*ep93xx_gpio), GFP_KERNEL); 350 + ep93xx_gpio = devm_kzalloc(dev, sizeof(struct ep93xx_gpio), GFP_KERNEL); 352 351 if (!ep93xx_gpio) 353 352 return -ENOMEM; 354 353 355 354 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 356 - if (!res) { 357 - ret = -ENXIO; 358 - goto exit_free; 359 - } 360 - 361 - if (!request_mem_region(res->start, resource_size(res), pdev->name)) { 362 - ret = -EBUSY; 363 - goto exit_free; 364 - } 365 - 366 - mmio = ioremap(res->start, resource_size(res)); 367 - if (!mmio) { 368 - ret = -ENXIO; 369 - goto exit_release; 370 - } 371 - ep93xx_gpio->mmio_base = mmio; 355 + ep93xx_gpio->mmio_base = devm_ioremap_resource(dev, res); 356 + if (IS_ERR(ep93xx_gpio->mmio_base)) 357 + return PTR_ERR(ep93xx_gpio->mmio_base); 372 358 373 359 for (i = 0; i < ARRAY_SIZE(ep93xx_gpio_banks); i++) { 374 360 struct bgpio_chip *bgc = &ep93xx_gpio->bgc[i]; 375 361 struct ep93xx_gpio_bank *bank = &ep93xx_gpio_banks[i]; 376 362 377 - if (ep93xx_gpio_add_bank(bgc, &pdev->dev, mmio, bank)) 363 + if (ep93xx_gpio_add_bank(bgc, &pdev->dev, 364 + ep93xx_gpio->mmio_base, bank)) 378 365 dev_warn(&pdev->dev, "Unable to add gpio bank %s\n", 379 366 bank->label); 380 367 } ··· 369 382 ep93xx_gpio_init_irq(); 370 383 371 384 return 0; 372 - 373 - exit_release: 374 - release_mem_region(res->start, resource_size(res)); 375 - exit_free: 376 - kfree(ep93xx_gpio); 377 - dev_info(&pdev->dev, "%s failed with errno %d\n", __func__, ret); 378 - return ret; 379 385 } 380 386 381 387 static struct platform_driver ep93xx_gpio_driver = {
+56 -124
drivers/gpio/gpio-ge.c
··· 18 18 */ 19 19 20 20 #include <linux/kernel.h> 21 - #include <linux/compiler.h> 22 - #include <linux/init.h> 23 21 #include <linux/io.h> 24 - #include <linux/of.h> 25 22 #include <linux/of_device.h> 26 - #include <linux/of_platform.h> 27 23 #include <linux/of_gpio.h> 28 - #include <linux/gpio.h> 29 - #include <linux/slab.h> 30 24 #include <linux/module.h> 31 25 32 26 #define GEF_GPIO_DIRECT 0x00 ··· 33 39 #define GEF_GPIO_OVERRUN 0x1C 34 40 #define GEF_GPIO_MODE 0x20 35 41 36 - static void _gef_gpio_set(void __iomem *reg, unsigned int offset, int value) 42 + static void gef_gpio_set(struct gpio_chip *chip, unsigned offset, int value) 37 43 { 44 + struct of_mm_gpio_chip *mmchip = to_of_mm_gpio_chip(chip); 38 45 unsigned int data; 39 46 40 - data = ioread32be(reg); 41 - /* value: 0=low; 1=high */ 42 - if (value & 0x1) 43 - data = data | (0x1 << offset); 47 + data = ioread32be(mmchip->regs + GEF_GPIO_OUT); 48 + if (value) 49 + data = data | BIT(offset); 44 50 else 45 - data = data & ~(0x1 << offset); 46 - 47 - iowrite32be(data, reg); 51 + data = data & ~BIT(offset); 52 + iowrite32be(data, mmchip->regs + GEF_GPIO_OUT); 48 53 } 49 - 50 54 51 55 static int gef_gpio_dir_in(struct gpio_chip *chip, unsigned offset) 52 56 { ··· 52 60 struct of_mm_gpio_chip *mmchip = to_of_mm_gpio_chip(chip); 53 61 54 62 data = ioread32be(mmchip->regs + GEF_GPIO_DIRECT); 55 - data = data | (0x1 << offset); 63 + data = data | BIT(offset); 56 64 iowrite32be(data, mmchip->regs + GEF_GPIO_DIRECT); 57 65 58 66 return 0; ··· 63 71 unsigned int data; 64 72 struct of_mm_gpio_chip *mmchip = to_of_mm_gpio_chip(chip); 65 73 66 - /* Set direction before switching to input */ 67 - _gef_gpio_set(mmchip->regs + GEF_GPIO_OUT, offset, value); 74 + /* Set value before switching to output */ 75 + gef_gpio_set(mmchip->regs + GEF_GPIO_OUT, offset, value); 68 76 69 77 data = ioread32be(mmchip->regs + GEF_GPIO_DIRECT); 70 - data = data & ~(0x1 << offset); 78 + data = data & ~BIT(offset); 71 79 iowrite32be(data, mmchip->regs + GEF_GPIO_DIRECT); 72 80 73 81 return 0; ··· 75 83 76 84 static int gef_gpio_get(struct gpio_chip *chip, unsigned offset) 77 85 { 78 - unsigned int data; 79 - int state = 0; 80 86 struct of_mm_gpio_chip *mmchip = to_of_mm_gpio_chip(chip); 81 87 82 - data = ioread32be(mmchip->regs + GEF_GPIO_IN); 83 - state = (int)((data >> offset) & 0x1); 84 - 85 - return state; 88 + return !!(ioread32be(mmchip->regs + GEF_GPIO_IN) & BIT(offset)); 86 89 } 87 90 88 - static void gef_gpio_set(struct gpio_chip *chip, unsigned offset, int value) 89 - { 90 - struct of_mm_gpio_chip *mmchip = to_of_mm_gpio_chip(chip); 91 - 92 - _gef_gpio_set(mmchip->regs + GEF_GPIO_OUT, offset, value); 93 - } 94 - 95 - static int __init gef_gpio_init(void) 96 - { 97 - struct device_node *np; 98 - int retval; 99 - struct of_mm_gpio_chip *gef_gpio_chip; 100 - 101 - for_each_compatible_node(np, NULL, "gef,sbc610-gpio") { 102 - 103 - pr_debug("%s: Initialising GEF GPIO\n", np->full_name); 104 - 105 - /* Allocate chip structure */ 106 - gef_gpio_chip = kzalloc(sizeof(*gef_gpio_chip), GFP_KERNEL); 107 - if (!gef_gpio_chip) { 108 - pr_err("%s: Unable to allocate structure\n", 109 - np->full_name); 110 - continue; 111 - } 112 - 113 - /* Setup pointers to chip functions */ 114 - gef_gpio_chip->gc.of_gpio_n_cells = 2; 115 - gef_gpio_chip->gc.ngpio = 19; 116 - gef_gpio_chip->gc.direction_input = gef_gpio_dir_in; 117 - gef_gpio_chip->gc.direction_output = gef_gpio_dir_out; 118 - gef_gpio_chip->gc.get = gef_gpio_get; 119 - gef_gpio_chip->gc.set = gef_gpio_set; 120 - 121 - /* This function adds a memory mapped GPIO chip */ 122 - retval = of_mm_gpiochip_add(np, gef_gpio_chip); 123 - if (retval) { 124 - kfree(gef_gpio_chip); 125 - pr_err("%s: Unable to add GPIO\n", np->full_name); 126 - } 127 - } 128 - 129 - for_each_compatible_node(np, NULL, "gef,sbc310-gpio") { 130 - 131 - pr_debug("%s: Initialising GEF GPIO\n", np->full_name); 132 - 133 - /* Allocate chip structure */ 134 - gef_gpio_chip = kzalloc(sizeof(*gef_gpio_chip), GFP_KERNEL); 135 - if (!gef_gpio_chip) { 136 - pr_err("%s: Unable to allocate structure\n", 137 - np->full_name); 138 - continue; 139 - } 140 - 141 - /* Setup pointers to chip functions */ 142 - gef_gpio_chip->gc.of_gpio_n_cells = 2; 143 - gef_gpio_chip->gc.ngpio = 6; 144 - gef_gpio_chip->gc.direction_input = gef_gpio_dir_in; 145 - gef_gpio_chip->gc.direction_output = gef_gpio_dir_out; 146 - gef_gpio_chip->gc.get = gef_gpio_get; 147 - gef_gpio_chip->gc.set = gef_gpio_set; 148 - 149 - /* This function adds a memory mapped GPIO chip */ 150 - retval = of_mm_gpiochip_add(np, gef_gpio_chip); 151 - if (retval) { 152 - kfree(gef_gpio_chip); 153 - pr_err("%s: Unable to add GPIO\n", np->full_name); 154 - } 155 - } 156 - 157 - for_each_compatible_node(np, NULL, "ge,imp3a-gpio") { 158 - 159 - pr_debug("%s: Initialising GE GPIO\n", np->full_name); 160 - 161 - /* Allocate chip structure */ 162 - gef_gpio_chip = kzalloc(sizeof(*gef_gpio_chip), GFP_KERNEL); 163 - if (!gef_gpio_chip) { 164 - pr_err("%s: Unable to allocate structure\n", 165 - np->full_name); 166 - continue; 167 - } 168 - 169 - /* Setup pointers to chip functions */ 170 - gef_gpio_chip->gc.of_gpio_n_cells = 2; 171 - gef_gpio_chip->gc.ngpio = 16; 172 - gef_gpio_chip->gc.direction_input = gef_gpio_dir_in; 173 - gef_gpio_chip->gc.direction_output = gef_gpio_dir_out; 174 - gef_gpio_chip->gc.get = gef_gpio_get; 175 - gef_gpio_chip->gc.set = gef_gpio_set; 176 - 177 - /* This function adds a memory mapped GPIO chip */ 178 - retval = of_mm_gpiochip_add(np, gef_gpio_chip); 179 - if (retval) { 180 - kfree(gef_gpio_chip); 181 - pr_err("%s: Unable to add GPIO\n", np->full_name); 182 - } 183 - } 184 - 185 - return 0; 91 + static const struct of_device_id gef_gpio_ids[] = { 92 + { 93 + .compatible = "gef,sbc610-gpio", 94 + .data = (void *)19, 95 + }, { 96 + .compatible = "gef,sbc310-gpio", 97 + .data = (void *)6, 98 + }, { 99 + .compatible = "ge,imp3a-gpio", 100 + .data = (void *)16, 101 + }, 102 + { } 186 103 }; 187 - arch_initcall(gef_gpio_init); 104 + MODULE_DEVICE_TABLE(of, gef_gpio_ids); 105 + 106 + static int __init gef_gpio_probe(struct platform_device *pdev) 107 + { 108 + const struct of_device_id *of_id = 109 + of_match_device(gef_gpio_ids, &pdev->dev); 110 + struct of_mm_gpio_chip *mmchip; 111 + 112 + mmchip = devm_kzalloc(&pdev->dev, sizeof(*mmchip), GFP_KERNEL); 113 + if (!mmchip) 114 + return -ENOMEM; 115 + 116 + /* Setup pointers to chip functions */ 117 + mmchip->gc.ngpio = (u16)(uintptr_t)of_id->data; 118 + mmchip->gc.of_gpio_n_cells = 2; 119 + mmchip->gc.direction_input = gef_gpio_dir_in; 120 + mmchip->gc.direction_output = gef_gpio_dir_out; 121 + mmchip->gc.get = gef_gpio_get; 122 + mmchip->gc.set = gef_gpio_set; 123 + 124 + /* This function adds a memory mapped GPIO chip */ 125 + return of_mm_gpiochip_add(pdev->dev.of_node, mmchip); 126 + }; 127 + 128 + static struct platform_driver gef_gpio_driver = { 129 + .driver = { 130 + .name = "gef-gpio", 131 + .owner = THIS_MODULE, 132 + .of_match_table = gef_gpio_ids, 133 + }, 134 + }; 135 + module_platform_driver_probe(gef_gpio_driver, gef_gpio_probe); 188 136 189 137 MODULE_DESCRIPTION("GE I/O FPGA GPIO driver"); 190 138 MODULE_AUTHOR("Martyn Welch <martyn.welch@ge.com");
+9
drivers/gpio/gpio-generic.c
··· 388 388 return 0; 389 389 } 390 390 391 + static int bgpio_request(struct gpio_chip *chip, unsigned gpio_pin) 392 + { 393 + if (gpio_pin < chip->ngpio) 394 + return 0; 395 + 396 + return -EINVAL; 397 + } 398 + 391 399 int bgpio_remove(struct bgpio_chip *bgc) 392 400 { 393 401 return gpiochip_remove(&bgc->gc); ··· 421 413 bgc->gc.label = dev_name(dev); 422 414 bgc->gc.base = -1; 423 415 bgc->gc.ngpio = bgc->bits; 416 + bgc->gc.request = bgpio_request; 424 417 425 418 ret = bgpio_setup_io(bgc, dat, set, clr); 426 419 if (ret)
+1 -1
drivers/gpio/gpio-grgpio.c
··· 481 481 return ret; 482 482 } 483 483 484 - static struct of_device_id grgpio_match[] = { 484 + static const struct of_device_id grgpio_match[] = { 485 485 {.name = "GAISLER_GPIO"}, 486 486 {.name = "01_01a"}, 487 487 {},
+8 -30
drivers/gpio/gpio-janz-ttl.c
··· 152 152 pdata = dev_get_platdata(&pdev->dev); 153 153 if (!pdata) { 154 154 dev_err(dev, "no platform data\n"); 155 - ret = -ENXIO; 156 - goto out_return; 155 + return -ENXIO; 157 156 } 158 157 159 - mod = kzalloc(sizeof(*mod), GFP_KERNEL); 160 - if (!mod) { 161 - dev_err(dev, "unable to allocate private data\n"); 162 - ret = -ENOMEM; 163 - goto out_return; 164 - } 158 + mod = devm_kzalloc(dev, sizeof(*mod), GFP_KERNEL); 159 + if (!mod) 160 + return -ENOMEM; 165 161 166 162 platform_set_drvdata(pdev, mod); 167 163 spin_lock_init(&mod->lock); 168 164 169 165 /* get access to the MODULbus registers for this module */ 170 166 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 171 - if (!res) { 172 - dev_err(dev, "MODULbus registers not found\n"); 173 - ret = -ENODEV; 174 - goto out_free_mod; 175 - } 176 - 177 - mod->regs = ioremap(res->start, resource_size(res)); 178 - if (!mod->regs) { 179 - dev_err(dev, "MODULbus registers not ioremap\n"); 180 - ret = -ENOMEM; 181 - goto out_free_mod; 182 - } 167 + mod->regs = devm_ioremap_resource(dev, res); 168 + if (IS_ERR(mod->regs)) 169 + return PTR_ERR(mod->regs); 183 170 184 171 ttl_setup_device(mod); 185 172 ··· 185 198 ret = gpiochip_add(gpio); 186 199 if (ret) { 187 200 dev_err(dev, "unable to add GPIO chip\n"); 188 - goto out_iounmap_regs; 201 + return ret; 189 202 } 190 203 191 204 return 0; 192 - 193 - out_iounmap_regs: 194 - iounmap(mod->regs); 195 - out_free_mod: 196 - kfree(mod); 197 - out_return: 198 - return ret; 199 205 } 200 206 201 207 static int ttl_remove(struct platform_device *pdev) ··· 203 223 return ret; 204 224 } 205 225 206 - iounmap(mod->regs); 207 - kfree(mod); 208 226 return 0; 209 227 } 210 228
+2 -2
drivers/gpio/gpio-kempld.c
··· 24 24 #include <linux/mfd/kempld.h> 25 25 26 26 #define KEMPLD_GPIO_MAX_NUM 16 27 - #define KEMPLD_GPIO_MASK(x) (1 << ((x) % 8)) 27 + #define KEMPLD_GPIO_MASK(x) (BIT((x) % 8)) 28 28 #define KEMPLD_GPIO_DIR_NUM(x) (0x40 + (x) / 8) 29 29 #define KEMPLD_GPIO_LVL_NUM(x) (0x42 + (x) / 8) 30 30 #define KEMPLD_GPIO_EVT_LVL_EDGE 0x46 ··· 216 216 MODULE_DESCRIPTION("KEM PLD GPIO Driver"); 217 217 MODULE_AUTHOR("Michael Brunner <michael.brunner@kontron.com>"); 218 218 MODULE_LICENSE("GPL"); 219 - MODULE_ALIAS("platform:gpio-kempld"); 219 + MODULE_ALIAS("platform:kempld-gpio");
+1 -3
drivers/gpio/gpio-lynxpoint.c
··· 375 375 int ret = -ENODEV; 376 376 377 377 lg = devm_kzalloc(dev, sizeof(struct lp_gpio), GFP_KERNEL); 378 - if (!lg) { 379 - dev_err(dev, "can't allocate lp_gpio chip data\n"); 378 + if (!lg) 380 379 return -ENOMEM; 381 - } 382 380 383 381 lg->pdev = pdev; 384 382 platform_set_drvdata(pdev, lg);
+2 -3
drivers/gpio/gpio-max730x.c
··· 237 237 ts->write(dev, 0x04, 0x00); 238 238 239 239 ret = gpiochip_remove(&ts->chip); 240 - if (!ret) { 240 + if (!ret) 241 241 mutex_destroy(&ts->lock); 242 - kfree(ts); 243 - } else 242 + else 244 243 dev_err(dev, "Failed to remove GPIO controller: %d\n", ret); 245 244 246 245 return ret;
+12 -5
drivers/gpio/gpio-mcp23s08.c
··· 714 714 715 715 #ifdef CONFIG_OF 716 716 #ifdef CONFIG_SPI_MASTER 717 - static struct of_device_id mcp23s08_spi_of_match[] = { 717 + static const struct of_device_id mcp23s08_spi_of_match[] = { 718 718 { 719 719 .compatible = "microchip,mcp23s08", 720 720 .data = (void *) MCP_TYPE_S08, ··· 738 738 #endif 739 739 740 740 #if IS_ENABLED(CONFIG_I2C) 741 - static struct of_device_id mcp23s08_i2c_of_match[] = { 741 + static const struct of_device_id mcp23s08_i2c_of_match[] = { 742 742 { 743 743 .compatible = "microchip,mcp23008", 744 744 .data = (void *) MCP_TYPE_008, ··· 867 867 { 868 868 struct mcp23s08_platform_data *pdata; 869 869 unsigned addr; 870 - unsigned chips = 0; 870 + int chips = 0; 871 871 struct mcp23s08_driver_data *data; 872 872 int status, type; 873 873 unsigned base = -1, ··· 894 894 dev_err(&spi->dev, "invalid spi-present-mask\n"); 895 895 return -ENODEV; 896 896 } 897 + 897 898 for (addr = 0; addr < ARRAY_SIZE(pdata->chip); addr++) { 898 - if ((spi_present_mask & (1 << addr))) 899 - chips++; 900 899 pullups[addr] = 0; 900 + if (spi_present_mask & (1 << addr)) 901 + chips++; 901 902 } 903 + if (!chips) 904 + return -ENODEV; 902 905 } else { 903 906 type = spi_get_device_id(spi)->driver_data; 904 907 pdata = dev_get_platdata(&spi->dev); ··· 940 937 if (!(spi_present_mask & (1 << addr))) 941 938 continue; 942 939 chips--; 940 + if (chips < 0) { 941 + dev_err(&spi->dev, "FATAL: invalid negative chip id\n"); 942 + goto fail; 943 + } 943 944 data->mcp[addr] = &data->chip[chips]; 944 945 status = mcp23s08_probe_one(data->mcp[addr], &spi->dev, spi, 945 946 0x40 | (addr << 1), type, base,
+1 -3
drivers/gpio/gpio-moxart.c
··· 113 113 int ret; 114 114 115 115 mgc = devm_kzalloc(dev, sizeof(*mgc), GFP_KERNEL); 116 - if (!mgc) { 117 - dev_err(dev, "can't allocate GPIO chip container\n"); 116 + if (!mgc) 118 117 return -ENOMEM; 119 - } 120 118 mgc->gpio = moxart_template_chip; 121 119 122 120 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+3 -10
drivers/gpio/gpio-mvebu.c
··· 535 535 #define mvebu_gpio_dbg_show NULL 536 536 #endif 537 537 538 - static struct of_device_id mvebu_gpio_of_match[] = { 538 + static const struct of_device_id mvebu_gpio_of_match[] = { 539 539 { 540 540 .compatible = "marvell,orion-gpio", 541 541 .data = (void *) MVEBU_GPIO_SOC_VARIANT_ORION, ··· 574 574 soc_variant = MVEBU_GPIO_SOC_VARIANT_ORION; 575 575 576 576 mvchip = devm_kzalloc(&pdev->dev, sizeof(struct mvebu_gpio_chip), GFP_KERNEL); 577 - if (!mvchip) { 578 - dev_err(&pdev->dev, "Cannot allocate memory\n"); 577 + if (!mvchip) 579 578 return -ENOMEM; 580 - } 581 579 582 580 if (of_property_read_u32(pdev->dev.of_node, "ngpios", &ngpios)) { 583 581 dev_err(&pdev->dev, "Missing ngpios OF property\n"); ··· 736 738 }, 737 739 .probe = mvebu_gpio_probe, 738 740 }; 739 - 740 - static int __init mvebu_gpio_init(void) 741 - { 742 - return platform_driver_register(&mvebu_gpio_driver); 743 - } 744 - postcore_initcall(mvebu_gpio_init); 741 + module_platform_driver(mvebu_gpio_driver);
+110 -95
drivers/gpio/gpio-omap.c
··· 24 24 #include <linux/pm.h> 25 25 #include <linux/of.h> 26 26 #include <linux/of_device.h> 27 - #include <linux/irqdomain.h> 28 27 #include <linux/irqchip/chained_irq.h> 29 28 #include <linux/gpio.h> 29 + #include <linux/bitops.h> 30 30 #include <linux/platform_data/gpio-omap.h> 31 31 32 32 #define OFF_MODE 1 ··· 52 52 struct list_head node; 53 53 void __iomem *base; 54 54 u16 irq; 55 - struct irq_domain *domain; 56 55 u32 non_wakeup_gpios; 57 56 u32 enabled_non_wakeup_gpios; 58 57 struct gpio_regs context; ··· 83 84 }; 84 85 85 86 #define GPIO_INDEX(bank, gpio) (gpio % bank->width) 86 - #define GPIO_BIT(bank, gpio) (1 << GPIO_INDEX(bank, gpio)) 87 + #define GPIO_BIT(bank, gpio) (BIT(GPIO_INDEX(bank, gpio))) 87 88 #define GPIO_MOD_CTRL_BIT BIT(0) 88 89 89 90 #define BANK_USED(bank) (bank->mod_usage || bank->irq_usage) 90 - #define LINE_USED(line, offset) (line & (1 << offset)) 91 + #define LINE_USED(line, offset) (line & (BIT(offset))) 91 92 92 93 static int irq_to_gpio(struct gpio_bank *bank, unsigned int gpio_irq) 93 94 { 94 95 return bank->chip.base + gpio_irq; 95 96 } 96 97 97 - static int omap_gpio_to_irq(struct gpio_chip *chip, unsigned offset) 98 + static inline struct gpio_bank *_irq_data_get_bank(struct irq_data *d) 98 99 { 99 - struct gpio_bank *bank = container_of(chip, struct gpio_bank, chip); 100 - 101 - return irq_find_mapping(bank->domain, offset); 100 + struct gpio_chip *chip = irq_data_get_irq_chip_data(d); 101 + return container_of(chip, struct gpio_bank, chip); 102 102 } 103 103 104 104 static void _set_gpio_direction(struct gpio_bank *bank, int gpio, int is_input) ··· 108 110 reg += bank->regs->direction; 109 111 l = readl_relaxed(reg); 110 112 if (is_input) 111 - l |= 1 << gpio; 113 + l |= BIT(gpio); 112 114 else 113 - l &= ~(1 << gpio); 115 + l &= ~(BIT(gpio)); 114 116 writel_relaxed(l, reg); 115 117 bank->context.oe = l; 116 118 } ··· 153 155 { 154 156 void __iomem *reg = bank->base + bank->regs->datain; 155 157 156 - return (readl_relaxed(reg) & (1 << offset)) != 0; 158 + return (readl_relaxed(reg) & (BIT(offset))) != 0; 157 159 } 158 160 159 161 static int _get_gpio_dataout(struct gpio_bank *bank, int offset) 160 162 { 161 163 void __iomem *reg = bank->base + bank->regs->dataout; 162 164 163 - return (readl_relaxed(reg) & (1 << offset)) != 0; 165 + return (readl_relaxed(reg) & (BIT(offset))) != 0; 164 166 } 165 167 166 168 static inline void _gpio_rmw(void __iomem *base, u32 reg, u32 mask, bool set) ··· 178 180 static inline void _gpio_dbck_enable(struct gpio_bank *bank) 179 181 { 180 182 if (bank->dbck_enable_mask && !bank->dbck_enabled) { 181 - clk_enable(bank->dbck); 183 + clk_prepare_enable(bank->dbck); 182 184 bank->dbck_enabled = true; 183 185 184 186 writel_relaxed(bank->dbck_enable_mask, ··· 196 198 */ 197 199 writel_relaxed(0, bank->base + bank->regs->debounce_en); 198 200 199 - clk_disable(bank->dbck); 201 + clk_disable_unprepare(bank->dbck); 200 202 bank->dbck_enabled = false; 201 203 } 202 204 } ··· 229 231 230 232 l = GPIO_BIT(bank, gpio); 231 233 232 - clk_enable(bank->dbck); 234 + clk_prepare_enable(bank->dbck); 233 235 reg = bank->base + bank->regs->debounce; 234 236 writel_relaxed(debounce, reg); 235 237 ··· 243 245 bank->dbck_enable_mask = val; 244 246 245 247 writel_relaxed(val, reg); 246 - clk_disable(bank->dbck); 248 + clk_disable_unprepare(bank->dbck); 247 249 /* 248 250 * Enable debounce clock per module. 249 251 * This call is mandatory because in omap_gpio_request() when ··· 288 290 bank->context.debounce = 0; 289 291 writel_relaxed(bank->context.debounce, bank->base + 290 292 bank->regs->debounce); 291 - clk_disable(bank->dbck); 293 + clk_disable_unprepare(bank->dbck); 292 294 bank->dbck_enabled = false; 293 295 } 294 296 } ··· 297 299 unsigned trigger) 298 300 { 299 301 void __iomem *base = bank->base; 300 - u32 gpio_bit = 1 << gpio; 302 + u32 gpio_bit = BIT(gpio); 301 303 302 304 _gpio_rmw(base, bank->regs->leveldetect0, gpio_bit, 303 305 trigger & IRQ_TYPE_LEVEL_LOW); ··· 366 368 367 369 l = readl_relaxed(reg); 368 370 if ((l >> gpio) & 1) 369 - l &= ~(1 << gpio); 371 + l &= ~(BIT(gpio)); 370 372 else 371 - l |= 1 << gpio; 373 + l |= BIT(gpio); 372 374 373 375 writel_relaxed(l, reg); 374 376 } ··· 390 392 391 393 l = readl_relaxed(reg); 392 394 if ((trigger & IRQ_TYPE_SENSE_MASK) == IRQ_TYPE_EDGE_BOTH) 393 - bank->toggle_mask |= 1 << gpio; 395 + bank->toggle_mask |= BIT(gpio); 394 396 if (trigger & IRQ_TYPE_EDGE_RISING) 395 - l |= 1 << gpio; 397 + l |= BIT(gpio); 396 398 else if (trigger & IRQ_TYPE_EDGE_FALLING) 397 - l &= ~(1 << gpio); 399 + l &= ~(BIT(gpio)); 398 400 else 399 401 return -EINVAL; 400 402 ··· 411 413 if (trigger & IRQ_TYPE_EDGE_RISING) 412 414 l |= 2 << (gpio << 1); 413 415 if (trigger & IRQ_TYPE_EDGE_FALLING) 414 - l |= 1 << (gpio << 1); 416 + l |= BIT(gpio << 1); 415 417 416 418 /* Enable wake-up during idle for dynamic tick */ 417 - _gpio_rmw(base, bank->regs->wkup_en, 1 << gpio, trigger); 419 + _gpio_rmw(base, bank->regs->wkup_en, BIT(gpio), trigger); 418 420 bank->context.wake_en = 419 421 readl_relaxed(bank->base + bank->regs->wkup_en); 420 422 writel_relaxed(l, reg); ··· 428 430 void __iomem *reg = bank->base + bank->regs->pinctrl; 429 431 430 432 /* Claim the pin for MPU */ 431 - writel_relaxed(readl_relaxed(reg) | (1 << offset), reg); 433 + writel_relaxed(readl_relaxed(reg) | (BIT(offset)), reg); 432 434 } 433 435 434 436 if (bank->regs->ctrl && !BANK_USED(bank)) { ··· 451 453 !LINE_USED(bank->mod_usage, offset) && 452 454 !LINE_USED(bank->irq_usage, offset)) { 453 455 /* Disable wake-up during idle for dynamic tick */ 454 - _gpio_rmw(base, bank->regs->wkup_en, 1 << offset, 0); 456 + _gpio_rmw(base, bank->regs->wkup_en, BIT(offset), 0); 455 457 bank->context.wake_en = 456 458 readl_relaxed(bank->base + bank->regs->wkup_en); 457 459 } ··· 477 479 478 480 static int gpio_irq_type(struct irq_data *d, unsigned type) 479 481 { 480 - struct gpio_bank *bank = irq_data_get_irq_chip_data(d); 482 + struct gpio_bank *bank = _irq_data_get_bank(d); 481 483 unsigned gpio = 0; 482 484 int retval; 483 485 unsigned long flags; ··· 507 509 if (!LINE_USED(bank->mod_usage, offset)) { 508 510 _enable_gpio_module(bank, offset); 509 511 _set_gpio_direction(bank, offset, 1); 510 - } else if (!gpio_is_input(bank, 1 << offset)) { 512 + } else if (!gpio_is_input(bank, BIT(offset))) { 511 513 spin_unlock_irqrestore(&bank->lock, flags); 512 514 return -EINVAL; 513 515 } 514 516 515 - retval = gpio_lock_as_irq(&bank->chip, offset); 516 - if (retval) { 517 - dev_err(bank->dev, "unable to lock offset %d for IRQ\n", 518 - offset); 519 - spin_unlock_irqrestore(&bank->lock, flags); 520 - return retval; 521 - } 522 - 523 - bank->irq_usage |= 1 << GPIO_INDEX(bank, gpio); 517 + bank->irq_usage |= BIT(GPIO_INDEX(bank, gpio)); 524 518 spin_unlock_irqrestore(&bank->lock, flags); 525 519 526 520 if (type & (IRQ_TYPE_LEVEL_LOW | IRQ_TYPE_LEVEL_HIGH)) ··· 549 559 { 550 560 void __iomem *reg = bank->base; 551 561 u32 l; 552 - u32 mask = (1 << bank->width) - 1; 562 + u32 mask = (BIT(bank->width)) - 1; 553 563 554 564 reg += bank->regs->irqenable; 555 565 l = readl_relaxed(reg); ··· 654 664 /* Use disable_irq_wake() and enable_irq_wake() functions from drivers */ 655 665 static int gpio_wake_enable(struct irq_data *d, unsigned int enable) 656 666 { 657 - struct gpio_bank *bank = irq_data_get_irq_chip_data(d); 667 + struct gpio_bank *bank = _irq_data_get_bank(d); 658 668 unsigned int gpio = irq_to_gpio(bank, d->hwirq); 659 669 660 670 return _set_gpio_wakeup(bank, gpio, enable); ··· 681 691 _set_gpio_triggering(bank, offset, IRQ_TYPE_NONE); 682 692 _enable_gpio_module(bank, offset); 683 693 } 684 - bank->mod_usage |= 1 << offset; 694 + bank->mod_usage |= BIT(offset); 685 695 spin_unlock_irqrestore(&bank->lock, flags); 686 696 687 697 return 0; ··· 693 703 unsigned long flags; 694 704 695 705 spin_lock_irqsave(&bank->lock, flags); 696 - bank->mod_usage &= ~(1 << offset); 706 + bank->mod_usage &= ~(BIT(offset)); 697 707 _disable_gpio_module(bank, offset); 698 708 _reset_gpio(bank, bank->chip.base + offset); 699 709 spin_unlock_irqrestore(&bank->lock, flags); ··· 722 732 unsigned int bit; 723 733 struct gpio_bank *bank; 724 734 int unmasked = 0; 725 - struct irq_chip *chip = irq_desc_get_chip(desc); 735 + struct irq_chip *irqchip = irq_desc_get_chip(desc); 736 + struct gpio_chip *chip = irq_get_handler_data(irq); 726 737 727 - chained_irq_enter(chip, desc); 738 + chained_irq_enter(irqchip, desc); 728 739 729 - bank = irq_get_handler_data(irq); 740 + bank = container_of(chip, struct gpio_bank, chip); 730 741 isr_reg = bank->base + bank->regs->irqstatus; 731 742 pm_runtime_get_sync(bank->dev); 732 743 ··· 755 764 configured, we could unmask GPIO bank interrupt immediately */ 756 765 if (!level_mask && !unmasked) { 757 766 unmasked = 1; 758 - chained_irq_exit(chip, desc); 767 + chained_irq_exit(irqchip, desc); 759 768 } 760 769 761 770 if (!isr) ··· 763 772 764 773 while (isr) { 765 774 bit = __ffs(isr); 766 - isr &= ~(1 << bit); 775 + isr &= ~(BIT(bit)); 767 776 768 777 /* 769 778 * Some chips can't respond to both rising and falling ··· 772 781 * to respond to the IRQ for the opposite direction. 773 782 * This will be indicated in the bank toggle_mask. 774 783 */ 775 - if (bank->toggle_mask & (1 << bit)) 784 + if (bank->toggle_mask & (BIT(bit))) 776 785 _toggle_gpio_edge_triggering(bank, bit); 777 786 778 - generic_handle_irq(irq_find_mapping(bank->domain, bit)); 787 + generic_handle_irq(irq_find_mapping(bank->chip.irqdomain, 788 + bit)); 779 789 } 780 790 } 781 791 /* if bank has any level sensitive GPIO pin interrupt ··· 785 793 interrupt */ 786 794 exit: 787 795 if (!unmasked) 788 - chained_irq_exit(chip, desc); 796 + chained_irq_exit(irqchip, desc); 789 797 pm_runtime_put(bank->dev); 790 798 } 791 799 792 800 static void gpio_irq_shutdown(struct irq_data *d) 793 801 { 794 - struct gpio_bank *bank = irq_data_get_irq_chip_data(d); 802 + struct gpio_bank *bank = _irq_data_get_bank(d); 795 803 unsigned int gpio = irq_to_gpio(bank, d->hwirq); 796 804 unsigned long flags; 797 805 unsigned offset = GPIO_INDEX(bank, gpio); 798 806 799 807 spin_lock_irqsave(&bank->lock, flags); 800 808 gpio_unlock_as_irq(&bank->chip, offset); 801 - bank->irq_usage &= ~(1 << offset); 809 + bank->irq_usage &= ~(BIT(offset)); 802 810 _disable_gpio_module(bank, offset); 803 811 _reset_gpio(bank, gpio); 804 812 spin_unlock_irqrestore(&bank->lock, flags); ··· 813 821 814 822 static void gpio_ack_irq(struct irq_data *d) 815 823 { 816 - struct gpio_bank *bank = irq_data_get_irq_chip_data(d); 824 + struct gpio_bank *bank = _irq_data_get_bank(d); 817 825 unsigned int gpio = irq_to_gpio(bank, d->hwirq); 818 826 819 827 _clear_gpio_irqstatus(bank, gpio); ··· 821 829 822 830 static void gpio_mask_irq(struct irq_data *d) 823 831 { 824 - struct gpio_bank *bank = irq_data_get_irq_chip_data(d); 832 + struct gpio_bank *bank = _irq_data_get_bank(d); 825 833 unsigned int gpio = irq_to_gpio(bank, d->hwirq); 826 834 unsigned long flags; 827 835 ··· 833 841 834 842 static void gpio_unmask_irq(struct irq_data *d) 835 843 { 836 - struct gpio_bank *bank = irq_data_get_irq_chip_data(d); 844 + struct gpio_bank *bank = _irq_data_get_bank(d); 837 845 unsigned int gpio = irq_to_gpio(bank, d->hwirq); 838 846 unsigned int irq_mask = GPIO_BIT(bank, gpio); 839 847 u32 trigger = irqd_get_trigger_type(d); ··· 928 936 929 937 /*---------------------------------------------------------------------*/ 930 938 939 + static int gpio_get_direction(struct gpio_chip *chip, unsigned offset) 940 + { 941 + struct gpio_bank *bank; 942 + unsigned long flags; 943 + void __iomem *reg; 944 + int dir; 945 + 946 + bank = container_of(chip, struct gpio_bank, chip); 947 + reg = bank->base + bank->regs->direction; 948 + spin_lock_irqsave(&bank->lock, flags); 949 + dir = !!(readl_relaxed(reg) & BIT(offset)); 950 + spin_unlock_irqrestore(&bank->lock, flags); 951 + return dir; 952 + } 953 + 931 954 static int gpio_input(struct gpio_chip *chip, unsigned offset) 932 955 { 933 956 struct gpio_bank *bank; ··· 961 954 u32 mask; 962 955 963 956 bank = container_of(chip, struct gpio_bank, chip); 964 - mask = (1 << offset); 957 + mask = (BIT(offset)); 965 958 966 959 if (gpio_is_input(bank, mask)) 967 960 return _get_gpio_datain(bank, offset); ··· 1088 1081 IRQ_NOREQUEST | IRQ_NOPROBE, 0); 1089 1082 } 1090 1083 1091 - static void omap_gpio_chip_init(struct gpio_bank *bank) 1084 + static int omap_gpio_chip_init(struct gpio_bank *bank) 1092 1085 { 1093 1086 int j; 1094 1087 static int gpio; 1088 + int irq_base = 0; 1089 + int ret; 1095 1090 1096 1091 /* 1097 1092 * REVISIT eventually switch from OMAP-specific gpio structs ··· 1101 1092 */ 1102 1093 bank->chip.request = omap_gpio_request; 1103 1094 bank->chip.free = omap_gpio_free; 1095 + bank->chip.get_direction = gpio_get_direction; 1104 1096 bank->chip.direction_input = gpio_input; 1105 1097 bank->chip.get = gpio_get; 1106 1098 bank->chip.direction_output = gpio_output; 1107 1099 bank->chip.set_debounce = gpio_debounce; 1108 1100 bank->chip.set = gpio_set; 1109 - bank->chip.to_irq = omap_gpio_to_irq; 1110 1101 if (bank->is_mpuio) { 1111 1102 bank->chip.label = "mpuio"; 1112 1103 if (bank->regs->wkup_en) ··· 1119 1110 } 1120 1111 bank->chip.ngpio = bank->width; 1121 1112 1122 - gpiochip_add(&bank->chip); 1113 + ret = gpiochip_add(&bank->chip); 1114 + if (ret) { 1115 + dev_err(bank->dev, "Could not register gpio chip %d\n", ret); 1116 + return ret; 1117 + } 1118 + 1119 + #ifdef CONFIG_ARCH_OMAP1 1120 + /* 1121 + * REVISIT: Once we have OMAP1 supporting SPARSE_IRQ, we can drop 1122 + * irq_alloc_descs() since a base IRQ offset will no longer be needed. 1123 + */ 1124 + irq_base = irq_alloc_descs(-1, 0, bank->width, 0); 1125 + if (irq_base < 0) { 1126 + dev_err(bank->dev, "Couldn't allocate IRQ numbers\n"); 1127 + return -ENODEV; 1128 + } 1129 + #endif 1130 + 1131 + ret = gpiochip_irqchip_add(&bank->chip, &gpio_irq_chip, 1132 + irq_base, gpio_irq_handler, 1133 + IRQ_TYPE_NONE); 1134 + 1135 + if (ret) { 1136 + dev_err(bank->dev, "Couldn't add irqchip to gpiochip %d\n", ret); 1137 + ret = gpiochip_remove(&bank->chip); 1138 + return -ENODEV; 1139 + } 1140 + 1141 + gpiochip_set_chained_irqchip(&bank->chip, &gpio_irq_chip, 1142 + bank->irq, gpio_irq_handler); 1123 1143 1124 1144 for (j = 0; j < bank->width; j++) { 1125 - int irq = irq_create_mapping(bank->domain, j); 1145 + int irq = irq_find_mapping(bank->chip.irqdomain, j); 1126 1146 irq_set_lockdep_class(irq, &gpio_lock_class); 1127 - irq_set_chip_data(irq, bank); 1128 1147 if (bank->is_mpuio) { 1129 1148 omap_mpuio_alloc_gc(bank, irq, bank->width); 1130 - } else { 1131 - irq_set_chip_and_handler(irq, &gpio_irq_chip, 1132 - handle_simple_irq); 1133 - set_irq_flags(irq, IRQF_VALID); 1149 + irq_set_chip_and_handler(irq, NULL, NULL); 1150 + set_irq_flags(irq, 0); 1134 1151 } 1135 1152 } 1136 - irq_set_chained_handler(bank->irq, gpio_irq_handler); 1137 - irq_set_handler_data(bank->irq, bank); 1153 + 1154 + return 0; 1138 1155 } 1139 1156 1140 1157 static const struct of_device_id omap_gpio_match[]; ··· 1173 1138 const struct omap_gpio_platform_data *pdata; 1174 1139 struct resource *res; 1175 1140 struct gpio_bank *bank; 1176 - #ifdef CONFIG_ARCH_OMAP1 1177 - int irq_base; 1178 - #endif 1141 + int ret; 1179 1142 1180 1143 match = of_match_device(of_match_ptr(omap_gpio_match), dev); 1181 1144 ··· 1195 1162 1196 1163 bank->irq = res->start; 1197 1164 bank->dev = dev; 1165 + bank->chip.dev = dev; 1198 1166 bank->dbck_flag = pdata->dbck_flag; 1199 1167 bank->stride = pdata->bank_stride; 1200 1168 bank->width = pdata->bank_width; ··· 1216 1182 pdata->get_context_loss_count; 1217 1183 } 1218 1184 1219 - #ifdef CONFIG_ARCH_OMAP1 1220 - /* 1221 - * REVISIT: Once we have OMAP1 supporting SPARSE_IRQ, we can drop 1222 - * irq_alloc_descs() and irq_domain_add_legacy() and just use a 1223 - * linear IRQ domain mapping for all OMAP platforms. 1224 - */ 1225 - irq_base = irq_alloc_descs(-1, 0, bank->width, 0); 1226 - if (irq_base < 0) { 1227 - dev_err(dev, "Couldn't allocate IRQ numbers\n"); 1228 - return -ENODEV; 1229 - } 1230 - 1231 - bank->domain = irq_domain_add_legacy(node, bank->width, irq_base, 1232 - 0, &irq_domain_simple_ops, NULL); 1233 - #else 1234 - bank->domain = irq_domain_add_linear(node, bank->width, 1235 - &irq_domain_simple_ops, NULL); 1236 - #endif 1237 - if (!bank->domain) { 1238 - dev_err(dev, "Couldn't register an IRQ domain\n"); 1239 - return -ENODEV; 1240 - } 1241 - 1242 1185 if (bank->regs->set_dataout && bank->regs->clr_dataout) 1243 1186 bank->set_dataout = _set_gpio_dataout_reg; 1244 1187 else ··· 1227 1216 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 1228 1217 bank->base = devm_ioremap_resource(dev, res); 1229 1218 if (IS_ERR(bank->base)) { 1230 - irq_domain_remove(bank->domain); 1219 + irq_domain_remove(bank->chip.irqdomain); 1231 1220 return PTR_ERR(bank->base); 1232 1221 } 1233 1222 ··· 1241 1230 mpuio_init(bank); 1242 1231 1243 1232 omap_gpio_mod_init(bank); 1244 - omap_gpio_chip_init(bank); 1233 + 1234 + ret = omap_gpio_chip_init(bank); 1235 + if (ret) 1236 + return ret; 1237 + 1245 1238 omap_gpio_show_rev(bank); 1246 1239 1247 1240 pm_runtime_put(bank->dev);
+2 -4
drivers/gpio/gpio-palmas.c
··· 148 148 .ngpio = 16, 149 149 }; 150 150 151 - static struct of_device_id of_palmas_gpio_match[] = { 151 + static const struct of_device_id of_palmas_gpio_match[] = { 152 152 { .compatible = "ti,palmas-gpio", .data = &palmas_dev_data,}, 153 153 { .compatible = "ti,tps65913-gpio", .data = &palmas_dev_data,}, 154 154 { .compatible = "ti,tps65914-gpio", .data = &palmas_dev_data,}, ··· 173 173 174 174 palmas_gpio = devm_kzalloc(&pdev->dev, 175 175 sizeof(*palmas_gpio), GFP_KERNEL); 176 - if (!palmas_gpio) { 177 - dev_err(&pdev->dev, "Could not allocate palmas_gpio\n"); 176 + if (!palmas_gpio) 178 177 return -ENOMEM; 179 - } 180 178 181 179 palmas_gpio->palmas = palmas; 182 180 palmas_gpio->gpio_chip.owner = THIS_MODULE;
+38 -64
drivers/gpio/gpio-pca953x.c
··· 15 15 #include <linux/init.h> 16 16 #include <linux/gpio.h> 17 17 #include <linux/interrupt.h> 18 - #include <linux/irq.h> 19 - #include <linux/irqdomain.h> 20 18 #include <linux/i2c.h> 21 19 #include <linux/platform_data/pca953x.h> 22 20 #include <linux/slab.h> ··· 89 91 u8 irq_stat[MAX_BANK]; 90 92 u8 irq_trig_raise[MAX_BANK]; 91 93 u8 irq_trig_fall[MAX_BANK]; 92 - struct irq_domain *domain; 93 94 #endif 94 95 95 96 struct i2c_client *client; ··· 96 99 const char *const *names; 97 100 int chip_type; 98 101 }; 102 + 103 + static inline struct pca953x_chip *to_pca(struct gpio_chip *gc) 104 + { 105 + return container_of(gc, struct pca953x_chip, gpio_chip); 106 + } 99 107 100 108 static int pca953x_read_single(struct pca953x_chip *chip, int reg, u32 *val, 101 109 int off) ··· 204 202 205 203 static int pca953x_gpio_direction_input(struct gpio_chip *gc, unsigned off) 206 204 { 207 - struct pca953x_chip *chip; 205 + struct pca953x_chip *chip = to_pca(gc); 208 206 u8 reg_val; 209 207 int ret, offset = 0; 210 - 211 - chip = container_of(gc, struct pca953x_chip, gpio_chip); 212 208 213 209 mutex_lock(&chip->i2c_lock); 214 210 reg_val = chip->reg_direction[off / BANK_SZ] | (1u << (off % BANK_SZ)); ··· 233 233 static int pca953x_gpio_direction_output(struct gpio_chip *gc, 234 234 unsigned off, int val) 235 235 { 236 - struct pca953x_chip *chip; 236 + struct pca953x_chip *chip = to_pca(gc); 237 237 u8 reg_val; 238 238 int ret, offset = 0; 239 - 240 - chip = container_of(gc, struct pca953x_chip, gpio_chip); 241 239 242 240 mutex_lock(&chip->i2c_lock); 243 241 /* set output level */ ··· 283 285 284 286 static int pca953x_gpio_get_value(struct gpio_chip *gc, unsigned off) 285 287 { 286 - struct pca953x_chip *chip; 288 + struct pca953x_chip *chip = to_pca(gc); 287 289 u32 reg_val; 288 290 int ret, offset = 0; 289 - 290 - chip = container_of(gc, struct pca953x_chip, gpio_chip); 291 291 292 292 mutex_lock(&chip->i2c_lock); 293 293 switch (chip->chip_type) { ··· 311 315 312 316 static void pca953x_gpio_set_value(struct gpio_chip *gc, unsigned off, int val) 313 317 { 314 - struct pca953x_chip *chip; 318 + struct pca953x_chip *chip = to_pca(gc); 315 319 u8 reg_val; 316 320 int ret, offset = 0; 317 - 318 - chip = container_of(gc, struct pca953x_chip, gpio_chip); 319 321 320 322 mutex_lock(&chip->i2c_lock); 321 323 if (val) ··· 361 367 } 362 368 363 369 #ifdef CONFIG_GPIO_PCA953X_IRQ 364 - static int pca953x_gpio_to_irq(struct gpio_chip *gc, unsigned off) 365 - { 366 - struct pca953x_chip *chip; 367 - 368 - chip = container_of(gc, struct pca953x_chip, gpio_chip); 369 - return irq_create_mapping(chip->domain, off); 370 - } 371 - 372 370 static void pca953x_irq_mask(struct irq_data *d) 373 371 { 374 - struct pca953x_chip *chip = irq_data_get_irq_chip_data(d); 372 + struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 373 + struct pca953x_chip *chip = to_pca(gc); 375 374 376 375 chip->irq_mask[d->hwirq / BANK_SZ] &= ~(1 << (d->hwirq % BANK_SZ)); 377 376 } 378 377 379 378 static void pca953x_irq_unmask(struct irq_data *d) 380 379 { 381 - struct pca953x_chip *chip = irq_data_get_irq_chip_data(d); 380 + struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 381 + struct pca953x_chip *chip = to_pca(gc); 382 382 383 383 chip->irq_mask[d->hwirq / BANK_SZ] |= 1 << (d->hwirq % BANK_SZ); 384 384 } 385 385 386 386 static void pca953x_irq_bus_lock(struct irq_data *d) 387 387 { 388 - struct pca953x_chip *chip = irq_data_get_irq_chip_data(d); 388 + struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 389 + struct pca953x_chip *chip = to_pca(gc); 389 390 390 391 mutex_lock(&chip->irq_lock); 391 392 } 392 393 393 394 static void pca953x_irq_bus_sync_unlock(struct irq_data *d) 394 395 { 395 - struct pca953x_chip *chip = irq_data_get_irq_chip_data(d); 396 + struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 397 + struct pca953x_chip *chip = to_pca(gc); 396 398 u8 new_irqs; 397 399 int level, i; 398 400 ··· 410 420 411 421 static int pca953x_irq_set_type(struct irq_data *d, unsigned int type) 412 422 { 413 - struct pca953x_chip *chip = irq_data_get_irq_chip_data(d); 423 + struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 424 + struct pca953x_chip *chip = to_pca(gc); 414 425 int bank_nb = d->hwirq / BANK_SZ; 415 426 u8 mask = 1 << (d->hwirq % BANK_SZ); 416 427 ··· 494 503 struct pca953x_chip *chip = devid; 495 504 u8 pending[MAX_BANK]; 496 505 u8 level; 506 + unsigned nhandled = 0; 497 507 int i; 498 508 499 509 if (!pca953x_irq_pending(chip, pending)) 500 - return IRQ_HANDLED; 510 + return IRQ_NONE; 501 511 502 512 for (i = 0; i < NBANK(chip); i++) { 503 513 while (pending[i]) { 504 514 level = __ffs(pending[i]); 505 - handle_nested_irq(irq_find_mapping(chip->domain, 515 + handle_nested_irq(irq_find_mapping(chip->gpio_chip.irqdomain, 506 516 level + (BANK_SZ * i))); 507 517 pending[i] &= ~(1 << level); 518 + nhandled++; 508 519 } 509 520 } 510 521 511 - return IRQ_HANDLED; 522 + return (nhandled > 0) ? IRQ_HANDLED : IRQ_NONE; 512 523 } 513 - 514 - static int pca953x_gpio_irq_map(struct irq_domain *d, unsigned int irq, 515 - irq_hw_number_t hwirq) 516 - { 517 - irq_clear_status_flags(irq, IRQ_NOREQUEST); 518 - irq_set_chip_data(irq, d->host_data); 519 - irq_set_chip(irq, &pca953x_irq_chip); 520 - irq_set_nested_thread(irq, true); 521 - #ifdef CONFIG_ARM 522 - set_irq_flags(irq, IRQF_VALID); 523 - #else 524 - irq_set_noprobe(irq); 525 - #endif 526 - 527 - return 0; 528 - } 529 - 530 - static const struct irq_domain_ops pca953x_irq_simple_ops = { 531 - .map = pca953x_gpio_irq_map, 532 - .xlate = irq_domain_xlate_twocell, 533 - }; 534 524 535 525 static int pca953x_irq_setup(struct pca953x_chip *chip, 536 526 const struct i2c_device_id *id, ··· 544 572 chip->irq_stat[i] &= chip->reg_direction[i]; 545 573 mutex_init(&chip->irq_lock); 546 574 547 - chip->domain = irq_domain_add_simple(client->dev.of_node, 548 - chip->gpio_chip.ngpio, 549 - irq_base, 550 - &pca953x_irq_simple_ops, 551 - chip); 552 - if (!chip->domain) 553 - return -ENODEV; 554 - 555 575 ret = devm_request_threaded_irq(&client->dev, 556 576 client->irq, 557 577 NULL, 558 578 pca953x_irq_handler, 559 - IRQF_TRIGGER_LOW | IRQF_ONESHOT, 579 + IRQF_TRIGGER_LOW | IRQF_ONESHOT | 580 + IRQF_SHARED, 560 581 dev_name(&client->dev), chip); 561 582 if (ret) { 562 583 dev_err(&client->dev, "failed to request irq %d\n", ··· 557 592 return ret; 558 593 } 559 594 560 - chip->gpio_chip.to_irq = pca953x_gpio_to_irq; 595 + ret = gpiochip_irqchip_add(&chip->gpio_chip, 596 + &pca953x_irq_chip, 597 + irq_base, 598 + handle_simple_irq, 599 + IRQ_TYPE_NONE); 600 + if (ret) { 601 + dev_err(&client->dev, 602 + "could not connect irqchip to gpiochip\n"); 603 + return ret; 604 + } 561 605 } 562 606 563 607 return 0; ··· 730 756 if (ret) 731 757 return ret; 732 758 733 - ret = pca953x_irq_setup(chip, id, irq_base); 759 + ret = gpiochip_add(&chip->gpio_chip); 734 760 if (ret) 735 761 return ret; 736 762 737 - ret = gpiochip_add(&chip->gpio_chip); 763 + ret = pca953x_irq_setup(chip, id, irq_base); 738 764 if (ret) 739 765 return ret; 740 766
+6 -5
drivers/gpio/gpio-pcf857x.c
··· 262 262 /* enable real irq */ 263 263 status = devm_request_threaded_irq(&client->dev, client->irq, 264 264 NULL, pcf857x_irq, IRQF_ONESHOT | 265 - IRQF_TRIGGER_FALLING, 265 + IRQF_TRIGGER_FALLING | IRQF_SHARED, 266 266 dev_name(&client->dev), gpio); 267 267 268 268 if (status) ··· 319 319 status = pcf857x_irq_domain_init(gpio, client); 320 320 if (status < 0) { 321 321 dev_err(&client->dev, "irq_domain init failed\n"); 322 - goto fail; 322 + goto fail_irq_domain; 323 323 } 324 324 } 325 325 ··· 414 414 return 0; 415 415 416 416 fail: 417 - dev_dbg(&client->dev, "probe error %d for '%s'\n", 418 - status, client->name); 419 - 420 417 if (client->irq) 421 418 pcf857x_irq_domain_cleanup(gpio); 419 + 420 + fail_irq_domain: 421 + dev_dbg(&client->dev, "probe error %d for '%s'\n", 422 + status, client->name); 422 423 423 424 return status; 424 425 }
+1
drivers/gpio/gpio-pch.c
··· 20 20 #include <linux/gpio.h> 21 21 #include <linux/interrupt.h> 22 22 #include <linux/irq.h> 23 + #include <linux/slab.h> 23 24 24 25 #define PCH_EDGE_FALLING 0 25 26 #define PCH_EDGE_RISING BIT(0)
+13 -14
drivers/gpio/gpio-pl061.c
··· 17 17 #include <linux/irq.h> 18 18 #include <linux/irqchip/chained_irq.h> 19 19 #include <linux/bitops.h> 20 - #include <linux/workqueue.h> 21 20 #include <linux/gpio.h> 22 21 #include <linux/device.h> 23 22 #include <linux/amba/bus.h> ··· 87 88 88 89 spin_lock_irqsave(&chip->lock, flags); 89 90 gpiodir = readb(chip->base + GPIODIR); 90 - gpiodir &= ~(1 << offset); 91 + gpiodir &= ~(BIT(offset)); 91 92 writeb(gpiodir, chip->base + GPIODIR); 92 93 spin_unlock_irqrestore(&chip->lock, flags); 93 94 ··· 105 106 return -EINVAL; 106 107 107 108 spin_lock_irqsave(&chip->lock, flags); 108 - writeb(!!value << offset, chip->base + (1 << (offset + 2))); 109 + writeb(!!value << offset, chip->base + (BIT(offset + 2))); 109 110 gpiodir = readb(chip->base + GPIODIR); 110 - gpiodir |= 1 << offset; 111 + gpiodir |= BIT(offset); 111 112 writeb(gpiodir, chip->base + GPIODIR); 112 113 113 114 /* 114 115 * gpio value is set again, because pl061 doesn't allow to set value of 115 116 * a gpio pin before configuring it in OUT mode. 116 117 */ 117 - writeb(!!value << offset, chip->base + (1 << (offset + 2))); 118 + writeb(!!value << offset, chip->base + (BIT(offset + 2))); 118 119 spin_unlock_irqrestore(&chip->lock, flags); 119 120 120 121 return 0; ··· 124 125 { 125 126 struct pl061_gpio *chip = container_of(gc, struct pl061_gpio, gc); 126 127 127 - return !!readb(chip->base + (1 << (offset + 2))); 128 + return !!readb(chip->base + (BIT(offset + 2))); 128 129 } 129 130 130 131 static void pl061_set_value(struct gpio_chip *gc, unsigned offset, int value) 131 132 { 132 133 struct pl061_gpio *chip = container_of(gc, struct pl061_gpio, gc); 133 134 134 - writeb(!!value << offset, chip->base + (1 << (offset + 2))); 135 + writeb(!!value << offset, chip->base + (BIT(offset + 2))); 135 136 } 136 137 137 138 static int pl061_irq_type(struct irq_data *d, unsigned trigger) ··· 206 207 { 207 208 struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 208 209 struct pl061_gpio *chip = container_of(gc, struct pl061_gpio, gc); 209 - u8 mask = 1 << (irqd_to_hwirq(d) % PL061_GPIO_NR); 210 + u8 mask = BIT(irqd_to_hwirq(d) % PL061_GPIO_NR); 210 211 u8 gpioie; 211 212 212 213 spin_lock(&chip->lock); ··· 219 220 { 220 221 struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 221 222 struct pl061_gpio *chip = container_of(gc, struct pl061_gpio, gc); 222 - u8 mask = 1 << (irqd_to_hwirq(d) % PL061_GPIO_NR); 223 + u8 mask = BIT(irqd_to_hwirq(d) % PL061_GPIO_NR); 223 224 u8 gpioie; 224 225 225 226 spin_lock(&chip->lock); ··· 301 302 302 303 for (i = 0; i < PL061_GPIO_NR; i++) { 303 304 if (pdata) { 304 - if (pdata->directions & (1 << i)) 305 + if (pdata->directions & (BIT(i))) 305 306 pl061_direction_output(&chip->gc, i, 306 - pdata->values & (1 << i)); 307 + pdata->values & (BIT(i))); 307 308 else 308 309 pl061_direction_input(&chip->gc, i); 309 310 } ··· 330 331 chip->csave_regs.gpio_ie = readb(chip->base + GPIOIE); 331 332 332 333 for (offset = 0; offset < PL061_GPIO_NR; offset++) { 333 - if (chip->csave_regs.gpio_dir & (1 << offset)) 334 + if (chip->csave_regs.gpio_dir & (BIT(offset))) 334 335 chip->csave_regs.gpio_data |= 335 336 pl061_get_value(&chip->gc, offset) << offset; 336 337 } ··· 344 345 int offset; 345 346 346 347 for (offset = 0; offset < PL061_GPIO_NR; offset++) { 347 - if (chip->csave_regs.gpio_dir & (1 << offset)) 348 + if (chip->csave_regs.gpio_dir & (BIT(offset))) 348 349 pl061_direction_output(&chip->gc, offset, 349 350 chip->csave_regs.gpio_data & 350 - (1 << offset)); 351 + (BIT(offset))); 351 352 else 352 353 pl061_direction_input(&chip->gc, offset); 353 354 }
+1 -3
drivers/gpio/gpio-rc5t583.c
··· 119 119 120 120 rc5t583_gpio = devm_kzalloc(&pdev->dev, sizeof(*rc5t583_gpio), 121 121 GFP_KERNEL); 122 - if (!rc5t583_gpio) { 123 - dev_warn(&pdev->dev, "Mem allocation for rc5t583_gpio failed"); 122 + if (!rc5t583_gpio) 124 123 return -ENOMEM; 125 - } 126 124 127 125 rc5t583_gpio->gpio_chip.label = "gpio-rc5t583", 128 126 rc5t583_gpio->gpio_chip.owner = THIS_MODULE,
+8 -1
drivers/gpio/gpio-rcar.c
··· 26 26 #include <linux/pinctrl/consumer.h> 27 27 #include <linux/platform_data/gpio-rcar.h> 28 28 #include <linux/platform_device.h> 29 + #include <linux/pm_runtime.h> 29 30 #include <linux/spinlock.h> 30 31 #include <linux/slab.h> 31 32 ··· 363 362 364 363 p = devm_kzalloc(dev, sizeof(*p), GFP_KERNEL); 365 364 if (!p) { 366 - dev_err(dev, "failed to allocate driver data\n"); 367 365 ret = -ENOMEM; 368 366 goto err0; 369 367 } ··· 376 376 return ret; 377 377 378 378 platform_set_drvdata(pdev, p); 379 + 380 + pm_runtime_enable(dev); 381 + pm_runtime_get_sync(dev); 379 382 380 383 io = platform_get_resource(pdev, IORESOURCE_MEM, 0); 381 384 irq = platform_get_resource(pdev, IORESOURCE_IRQ, 0); ··· 463 460 err1: 464 461 irq_domain_remove(p->irq_domain); 465 462 err0: 463 + pm_runtime_put(dev); 464 + pm_runtime_disable(dev); 466 465 return ret; 467 466 } 468 467 ··· 478 473 return ret; 479 474 480 475 irq_domain_remove(p->irq_domain); 476 + pm_runtime_put(&pdev->dev); 477 + pm_runtime_disable(&pdev->dev); 481 478 return 0; 482 479 } 483 480
+7 -16
drivers/gpio/gpio-rdc321x.c
··· 141 141 return -ENODEV; 142 142 } 143 143 144 - rdc321x_gpio_dev = kzalloc(sizeof(struct rdc321x_gpio), GFP_KERNEL); 145 - if (!rdc321x_gpio_dev) { 146 - dev_err(&pdev->dev, "failed to allocate private data\n"); 144 + rdc321x_gpio_dev = devm_kzalloc(&pdev->dev, sizeof(struct rdc321x_gpio), 145 + GFP_KERNEL); 146 + if (!rdc321x_gpio_dev) 147 147 return -ENOMEM; 148 - } 149 148 150 149 r = platform_get_resource_byname(pdev, IORESOURCE_IO, "gpio-reg1"); 151 150 if (!r) { 152 151 dev_err(&pdev->dev, "failed to get gpio-reg1 resource\n"); 153 - err = -ENODEV; 154 - goto out_free; 152 + return -ENODEV; 155 153 } 156 154 157 155 spin_lock_init(&rdc321x_gpio_dev->lock); ··· 160 162 r = platform_get_resource_byname(pdev, IORESOURCE_IO, "gpio-reg2"); 161 163 if (!r) { 162 164 dev_err(&pdev->dev, "failed to get gpio-reg2 resource\n"); 163 - err = -ENODEV; 164 - goto out_free; 165 + return -ENODEV; 165 166 } 166 167 167 168 rdc321x_gpio_dev->reg2_ctrl_base = r->start; ··· 184 187 rdc321x_gpio_dev->reg1_data_base, 185 188 &rdc321x_gpio_dev->data_reg[0]); 186 189 if (err) 187 - goto out_free; 190 + return err; 188 191 189 192 err = pci_read_config_dword(rdc321x_gpio_dev->sb_pdev, 190 193 rdc321x_gpio_dev->reg2_data_base, 191 194 &rdc321x_gpio_dev->data_reg[1]); 192 195 if (err) 193 - goto out_free; 196 + return err; 194 197 195 198 dev_info(&pdev->dev, "registering %d GPIOs\n", 196 199 rdc321x_gpio_dev->chip.ngpio); 197 200 return gpiochip_add(&rdc321x_gpio_dev->chip); 198 - 199 - out_free: 200 - kfree(rdc321x_gpio_dev); 201 - return err; 202 201 } 203 202 204 203 static int rdc321x_gpio_remove(struct platform_device *pdev) ··· 205 212 ret = gpiochip_remove(&rdc321x_gpio_dev->chip); 206 213 if (ret) 207 214 dev_err(&pdev->dev, "failed to unregister chip\n"); 208 - 209 - kfree(rdc321x_gpio_dev); 210 215 211 216 return ret; 212 217 }
+22 -4
drivers/gpio/gpio-sch.c
··· 97 97 u8 curr_dirs; 98 98 unsigned short offset, bit; 99 99 100 - sch_gpio_core_set(gc, gpio_num, val); 101 - 102 100 spin_lock(&gpio_lock); 103 101 104 102 offset = CGIO + gpio_num / 8; ··· 107 109 outb(curr_dirs & ~(1 << bit), gpio_ba + offset); 108 110 109 111 spin_unlock(&gpio_lock); 112 + 113 + /* 114 + * according to the datasheet, writing to the level register has no 115 + * effect when GPIO is programmed as input. 116 + * Actually the the level register is read-only when configured as input. 117 + * Thus presetting the output level before switching to output is _NOT_ possible. 118 + * Hence we set the level after configuring the GPIO as output. 119 + * But we cannot prevent a short low pulse if direction is set to high 120 + * and an external pull-up is connected. 121 + */ 122 + sch_gpio_core_set(gc, gpio_num, val); 110 123 return 0; 111 124 } 112 125 ··· 187 178 u8 curr_dirs; 188 179 unsigned short offset, bit; 189 180 190 - sch_gpio_resume_set(gc, gpio_num, val); 191 - 192 181 offset = RGIO + gpio_num / 8; 193 182 bit = gpio_num % 8; 194 183 ··· 197 190 outb(curr_dirs & ~(1 << bit), gpio_ba + offset); 198 191 199 192 spin_unlock(&gpio_lock); 193 + 194 + /* 195 + * according to the datasheet, writing to the level register has no 196 + * effect when GPIO is programmed as input. 197 + * Actually the the level register is read-only when configured as input. 198 + * Thus presetting the output level before switching to output is _NOT_ possible. 199 + * Hence we set the level after configuring the GPIO as output. 200 + * But we cannot prevent a short low pulse if direction is set to high 201 + * and an external pull-up is connected. 202 + */ 203 + sch_gpio_resume_set(gc, gpio_num, val); 200 204 return 0; 201 205 } 202 206
+12 -4
drivers/gpio/gpio-sch311x.c
··· 327 327 if (err) 328 328 return err; 329 329 330 - /* Check device ID. We currently know about: 331 - * SCH3112 (0x7c), SCH3114 (0x7d), and SCH3116 (0x7f). */ 330 + /* Check device ID. */ 332 331 reg = sch311x_sio_inb(sio_config_port, 0x20); 333 - if (!(reg == 0x7c || reg == 0x7d || reg == 0x7f)) { 332 + switch (reg) { 333 + case 0x7c: /* SCH3112 */ 334 + dev_id = 2; 335 + break; 336 + case 0x7d: /* SCH3114 */ 337 + dev_id = 4; 338 + break; 339 + case 0x7f: /* SCH3116 */ 340 + dev_id = 6; 341 + break; 342 + default: 334 343 err = -ENODEV; 335 344 goto exit; 336 345 } 337 - dev_id = reg == 0x7c ? 2 : reg == 0x7d ? 4 : 6; 338 346 339 347 /* Select logical device A (runtime registers) */ 340 348 sch311x_sio_outb(sio_config_port, 0x07, 0x0a);
+1 -3
drivers/gpio/gpio-spear-spics.c
··· 129 129 int ret; 130 130 131 131 spics = devm_kzalloc(&pdev->dev, sizeof(*spics), GFP_KERNEL); 132 - if (!spics) { 133 - dev_err(&pdev->dev, "memory allocation fail\n"); 132 + if (!spics) 134 133 return -ENOMEM; 135 - } 136 134 137 135 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 138 136 spics->base = devm_ioremap_resource(&pdev->dev, res);
-1
drivers/gpio/gpio-sx150x.c
··· 22 22 #include <linux/module.h> 23 23 #include <linux/mutex.h> 24 24 #include <linux/slab.h> 25 - #include <linux/workqueue.h> 26 25 #include <linux/i2c/sx150x.h> 27 26 28 27 #define NO_UPDATE_PENDING -1
+32 -116
drivers/gpio/gpio-tc3589x.c
··· 12 12 #include <linux/slab.h> 13 13 #include <linux/gpio.h> 14 14 #include <linux/of.h> 15 - #include <linux/irq.h> 16 - #include <linux/irqdomain.h> 17 15 #include <linux/interrupt.h> 18 16 #include <linux/mfd/tc3589x.h> 19 17 ··· 29 31 struct tc3589x *tc3589x; 30 32 struct device *dev; 31 33 struct mutex irq_lock; 32 - struct irq_domain *domain; 33 - 34 - int irq_base; 35 - 36 34 /* Caches of interrupt control registers for bus_lock */ 37 35 u8 regs[CACHE_NR_REGS][CACHE_NR_BANKS]; 38 36 u8 oldregs[CACHE_NR_REGS][CACHE_NR_BANKS]; ··· 89 95 return tc3589x_set_bits(tc3589x, reg, 1 << pos, 0); 90 96 } 91 97 92 - /** 93 - * tc3589x_gpio_irq_get_irq(): Map a hardware IRQ on a chip to a Linux IRQ 94 - * 95 - * @tc3589x_gpio: tc3589x_gpio_irq controller to operate on. 96 - * @irq: index of the hardware interrupt requested in the chip IRQs 97 - * 98 - * Useful for drivers to request their own IRQs. 99 - */ 100 - static int tc3589x_gpio_irq_get_irq(struct tc3589x_gpio *tc3589x_gpio, 101 - int hwirq) 102 - { 103 - if (!tc3589x_gpio) 104 - return -EINVAL; 105 - 106 - return irq_create_mapping(tc3589x_gpio->domain, hwirq); 107 - } 108 - 109 - static int tc3589x_gpio_to_irq(struct gpio_chip *chip, unsigned offset) 110 - { 111 - struct tc3589x_gpio *tc3589x_gpio = to_tc3589x_gpio(chip); 112 - 113 - return tc3589x_gpio_irq_get_irq(tc3589x_gpio, offset); 114 - } 115 - 116 98 static struct gpio_chip template_chip = { 117 99 .label = "tc3589x", 118 100 .owner = THIS_MODULE, ··· 96 126 .get = tc3589x_gpio_get, 97 127 .direction_output = tc3589x_gpio_direction_output, 98 128 .set = tc3589x_gpio_set, 99 - .to_irq = tc3589x_gpio_to_irq, 100 129 .can_sleep = true, 101 130 }; 102 131 103 132 static int tc3589x_gpio_irq_set_type(struct irq_data *d, unsigned int type) 104 133 { 105 - struct tc3589x_gpio *tc3589x_gpio = irq_data_get_irq_chip_data(d); 134 + struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 135 + struct tc3589x_gpio *tc3589x_gpio = container_of(gc, struct tc3589x_gpio, chip); 106 136 int offset = d->hwirq; 107 137 int regoffset = offset / 8; 108 138 int mask = 1 << (offset % 8); ··· 129 159 130 160 static void tc3589x_gpio_irq_lock(struct irq_data *d) 131 161 { 132 - struct tc3589x_gpio *tc3589x_gpio = irq_data_get_irq_chip_data(d); 162 + struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 163 + struct tc3589x_gpio *tc3589x_gpio = container_of(gc, struct tc3589x_gpio, chip); 133 164 134 165 mutex_lock(&tc3589x_gpio->irq_lock); 135 166 } 136 167 137 168 static void tc3589x_gpio_irq_sync_unlock(struct irq_data *d) 138 169 { 139 - struct tc3589x_gpio *tc3589x_gpio = irq_data_get_irq_chip_data(d); 170 + struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 171 + struct tc3589x_gpio *tc3589x_gpio = container_of(gc, struct tc3589x_gpio, chip); 140 172 struct tc3589x *tc3589x = tc3589x_gpio->tc3589x; 141 173 static const u8 regmap[] = { 142 174 [REG_IBE] = TC3589x_GPIOIBE0, ··· 166 194 167 195 static void tc3589x_gpio_irq_mask(struct irq_data *d) 168 196 { 169 - struct tc3589x_gpio *tc3589x_gpio = irq_data_get_irq_chip_data(d); 197 + struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 198 + struct tc3589x_gpio *tc3589x_gpio = container_of(gc, struct tc3589x_gpio, chip); 170 199 int offset = d->hwirq; 171 200 int regoffset = offset / 8; 172 201 int mask = 1 << (offset % 8); ··· 177 204 178 205 static void tc3589x_gpio_irq_unmask(struct irq_data *d) 179 206 { 180 - struct tc3589x_gpio *tc3589x_gpio = irq_data_get_irq_chip_data(d); 207 + struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 208 + struct tc3589x_gpio *tc3589x_gpio = container_of(gc, struct tc3589x_gpio, chip); 181 209 int offset = d->hwirq; 182 210 int regoffset = offset / 8; 183 211 int mask = 1 << (offset % 8); ··· 216 242 while (stat) { 217 243 int bit = __ffs(stat); 218 244 int line = i * 8 + bit; 219 - int irq = tc3589x_gpio_irq_get_irq(tc3589x_gpio, line); 245 + int irq = irq_find_mapping(tc3589x_gpio->chip.irqdomain, 246 + line); 220 247 221 248 handle_nested_irq(irq); 222 249 stat &= ~(1 << bit); ··· 227 252 } 228 253 229 254 return IRQ_HANDLED; 230 - } 231 - 232 - static int tc3589x_gpio_irq_map(struct irq_domain *d, unsigned int irq, 233 - irq_hw_number_t hwirq) 234 - { 235 - struct tc3589x *tc3589x_gpio = d->host_data; 236 - 237 - irq_set_chip_data(irq, tc3589x_gpio); 238 - irq_set_chip_and_handler(irq, &tc3589x_gpio_irq_chip, 239 - handle_simple_irq); 240 - irq_set_nested_thread(irq, 1); 241 - #ifdef CONFIG_ARM 242 - set_irq_flags(irq, IRQF_VALID); 243 - #else 244 - irq_set_noprobe(irq); 245 - #endif 246 - 247 - return 0; 248 - } 249 - 250 - static void tc3589x_gpio_irq_unmap(struct irq_domain *d, unsigned int irq) 251 - { 252 - #ifdef CONFIG_ARM 253 - set_irq_flags(irq, 0); 254 - #endif 255 - irq_set_chip_and_handler(irq, NULL, NULL); 256 - irq_set_chip_data(irq, NULL); 257 - } 258 - 259 - static struct irq_domain_ops tc3589x_irq_ops = { 260 - .map = tc3589x_gpio_irq_map, 261 - .unmap = tc3589x_gpio_irq_unmap, 262 - .xlate = irq_domain_xlate_twocell, 263 - }; 264 - 265 - static int tc3589x_gpio_irq_init(struct tc3589x_gpio *tc3589x_gpio, 266 - struct device_node *np) 267 - { 268 - int base = tc3589x_gpio->irq_base; 269 - 270 - /* 271 - * If this results in a linear domain, irq_create_mapping() will 272 - * take care of allocating IRQ descriptors at runtime. When a base 273 - * is provided, the IRQ descriptors will be allocated when the 274 - * domain is instantiated. 275 - */ 276 - tc3589x_gpio->domain = irq_domain_add_simple(np, 277 - tc3589x_gpio->chip.ngpio, base, &tc3589x_irq_ops, 278 - tc3589x_gpio); 279 - if (!tc3589x_gpio->domain) { 280 - dev_err(tc3589x_gpio->dev, "Failed to create irqdomain\n"); 281 - return -ENOSYS; 282 - } 283 - 284 - return 0; 285 255 } 286 256 287 257 static int tc3589x_gpio_probe(struct platform_device *pdev) ··· 249 329 if (irq < 0) 250 330 return irq; 251 331 252 - tc3589x_gpio = kzalloc(sizeof(struct tc3589x_gpio), GFP_KERNEL); 332 + tc3589x_gpio = devm_kzalloc(&pdev->dev, sizeof(struct tc3589x_gpio), 333 + GFP_KERNEL); 253 334 if (!tc3589x_gpio) 254 335 return -ENOMEM; 255 336 ··· 268 347 tc3589x_gpio->chip.of_node = np; 269 348 #endif 270 349 271 - tc3589x_gpio->irq_base = tc3589x->irq_base ? 272 - tc3589x->irq_base + TC3589x_INT_GPIO(0) : 0; 273 - 274 350 /* Bring the GPIO module out of reset */ 275 351 ret = tc3589x_set_bits(tc3589x, TC3589x_RSTCTRL, 276 352 TC3589x_RSTCTRL_GPIRST, 0); 277 353 if (ret < 0) 278 - goto out_free; 354 + return ret; 279 355 280 - ret = tc3589x_gpio_irq_init(tc3589x_gpio, np); 281 - if (ret) 282 - goto out_free; 283 - 284 - ret = request_threaded_irq(irq, NULL, tc3589x_gpio_irq, IRQF_ONESHOT, 285 - "tc3589x-gpio", tc3589x_gpio); 356 + ret = devm_request_threaded_irq(&pdev->dev, 357 + irq, NULL, tc3589x_gpio_irq, 358 + IRQF_ONESHOT, "tc3589x-gpio", 359 + tc3589x_gpio); 286 360 if (ret) { 287 361 dev_err(&pdev->dev, "unable to get irq: %d\n", ret); 288 - goto out_free; 362 + return ret; 289 363 } 290 364 291 365 ret = gpiochip_add(&tc3589x_gpio->chip); 292 366 if (ret) { 293 367 dev_err(&pdev->dev, "unable to add gpiochip: %d\n", ret); 294 - goto out_freeirq; 368 + return ret; 369 + } 370 + 371 + ret = gpiochip_irqchip_add(&tc3589x_gpio->chip, 372 + &tc3589x_gpio_irq_chip, 373 + 0, 374 + handle_simple_irq, 375 + IRQ_TYPE_NONE); 376 + if (ret) { 377 + dev_err(&pdev->dev, 378 + "could not connect irqchip to gpiochip\n"); 379 + return ret; 295 380 } 296 381 297 382 if (pdata && pdata->setup) ··· 306 379 platform_set_drvdata(pdev, tc3589x_gpio); 307 380 308 381 return 0; 309 - 310 - out_freeirq: 311 - free_irq(irq, tc3589x_gpio); 312 - out_free: 313 - kfree(tc3589x_gpio); 314 - return ret; 315 382 } 316 383 317 384 static int tc3589x_gpio_remove(struct platform_device *pdev) ··· 313 392 struct tc3589x_gpio *tc3589x_gpio = platform_get_drvdata(pdev); 314 393 struct tc3589x *tc3589x = tc3589x_gpio->tc3589x; 315 394 struct tc3589x_gpio_platform_data *pdata = tc3589x->pdata->gpio; 316 - int irq = platform_get_irq(pdev, 0); 317 395 int ret; 318 396 319 397 if (pdata && pdata->remove) ··· 324 404 "unable to remove gpiochip: %d\n", ret); 325 405 return ret; 326 406 } 327 - 328 - free_irq(irq, tc3589x_gpio); 329 - 330 - kfree(tc3589x_gpio); 331 407 332 408 return 0; 333 409 }
+2 -4
drivers/gpio/gpio-tegra.c
··· 408 408 .upper_offset = 0x80, 409 409 }; 410 410 411 - static struct of_device_id tegra_gpio_of_match[] = { 411 + static const struct of_device_id tegra_gpio_of_match[] = { 412 412 { .compatible = "nvidia,tegra30-gpio", .data = &tegra30_gpio_config }, 413 413 { .compatible = "nvidia,tegra20-gpio", .data = &tegra20_gpio_config }, 414 414 { }, ··· 458 458 tegra_gpio_banks = devm_kzalloc(&pdev->dev, 459 459 tegra_gpio_bank_count * sizeof(*tegra_gpio_banks), 460 460 GFP_KERNEL); 461 - if (!tegra_gpio_banks) { 462 - dev_err(&pdev->dev, "Couldn't allocate bank structure\n"); 461 + if (!tegra_gpio_banks) 463 462 return -ENODEV; 464 - } 465 463 466 464 irq_domain = irq_domain_add_linear(pdev->dev.of_node, 467 465 tegra_gpio_chip.ngpio,
+16 -31
drivers/gpio/gpio-timberdale.c
··· 224 224 static int timbgpio_probe(struct platform_device *pdev) 225 225 { 226 226 int err, i; 227 + struct device *dev = &pdev->dev; 227 228 struct gpio_chip *gc; 228 229 struct timbgpio *tgpio; 229 230 struct resource *iomem; ··· 232 231 int irq = platform_get_irq(pdev, 0); 233 232 234 233 if (!pdata || pdata->nr_pins > 32) { 235 - err = -EINVAL; 236 - goto err_mem; 234 + dev_err(dev, "Invalid platform data\n"); 235 + return -EINVAL; 237 236 } 238 237 239 238 iomem = platform_get_resource(pdev, IORESOURCE_MEM, 0); 240 239 if (!iomem) { 241 - err = -EINVAL; 242 - goto err_mem; 240 + dev_err(dev, "Unable to get resource\n"); 241 + return -EINVAL; 243 242 } 244 243 245 - tgpio = kzalloc(sizeof(*tgpio), GFP_KERNEL); 244 + tgpio = devm_kzalloc(dev, sizeof(struct timbgpio), GFP_KERNEL); 246 245 if (!tgpio) { 247 - err = -EINVAL; 248 - goto err_mem; 246 + dev_err(dev, "Memory alloc failed\n"); 247 + return -EINVAL; 249 248 } 250 249 tgpio->irq_base = pdata->irq_base; 251 250 252 251 spin_lock_init(&tgpio->lock); 253 252 254 - if (!request_mem_region(iomem->start, resource_size(iomem), 255 - DRIVER_NAME)) { 256 - err = -EBUSY; 257 - goto err_request; 253 + if (!devm_request_mem_region(dev, iomem->start, resource_size(iomem), 254 + DRIVER_NAME)) { 255 + dev_err(dev, "Region already claimed\n"); 256 + return -EBUSY; 258 257 } 259 258 260 - tgpio->membase = ioremap(iomem->start, resource_size(iomem)); 259 + tgpio->membase = devm_ioremap(dev, iomem->start, resource_size(iomem)); 261 260 if (!tgpio->membase) { 262 - err = -ENOMEM; 263 - goto err_ioremap; 261 + dev_err(dev, "Cannot ioremap\n"); 262 + return -ENOMEM; 264 263 } 265 264 266 265 gc = &tgpio->gpio; ··· 280 279 281 280 err = gpiochip_add(gc); 282 281 if (err) 283 - goto err_chipadd; 282 + return err; 284 283 285 284 platform_set_drvdata(pdev, tgpio); 286 285 ··· 303 302 irq_set_chained_handler(irq, timbgpio_irq); 304 303 305 304 return 0; 306 - 307 - err_chipadd: 308 - iounmap(tgpio->membase); 309 - err_ioremap: 310 - release_mem_region(iomem->start, resource_size(iomem)); 311 - err_request: 312 - kfree(tgpio); 313 - err_mem: 314 - printk(KERN_ERR DRIVER_NAME": Failed to register GPIOs: %d\n", err); 315 - 316 - return err; 317 305 } 318 306 319 307 static int timbgpio_remove(struct platform_device *pdev) ··· 310 320 int err; 311 321 struct timbgpio_platform_data *pdata = dev_get_platdata(&pdev->dev); 312 322 struct timbgpio *tgpio = platform_get_drvdata(pdev); 313 - struct resource *iomem = platform_get_resource(pdev, IORESOURCE_MEM, 0); 314 323 int irq = platform_get_irq(pdev, 0); 315 324 316 325 if (irq >= 0 && tgpio->irq_base > 0) { ··· 326 337 err = gpiochip_remove(&tgpio->gpio); 327 338 if (err) 328 339 printk(KERN_ERR DRIVER_NAME": failed to remove gpio_chip\n"); 329 - 330 - iounmap(tgpio->membase); 331 - release_mem_region(iomem->start, resource_size(iomem)); 332 - kfree(tgpio); 333 340 334 341 return 0; 335 342 }
+1 -3
drivers/gpio/gpio-tps6586x.c
··· 97 97 pdata = dev_get_platdata(pdev->dev.parent); 98 98 tps6586x_gpio = devm_kzalloc(&pdev->dev, 99 99 sizeof(*tps6586x_gpio), GFP_KERNEL); 100 - if (!tps6586x_gpio) { 101 - dev_err(&pdev->dev, "Could not allocate tps6586x_gpio\n"); 100 + if (!tps6586x_gpio) 102 101 return -ENOMEM; 103 - } 104 102 105 103 tps6586x_gpio->parent = pdev->dev.parent; 106 104
+1 -3
drivers/gpio/gpio-tps65910.c
··· 123 123 124 124 tps65910_gpio = devm_kzalloc(&pdev->dev, 125 125 sizeof(*tps65910_gpio), GFP_KERNEL); 126 - if (!tps65910_gpio) { 127 - dev_err(&pdev->dev, "Could not allocate tps65910_gpio\n"); 126 + if (!tps65910_gpio) 128 127 return -ENOMEM; 129 - } 130 128 131 129 tps65910_gpio->tps65910 = tps65910; 132 130
+1 -1
drivers/gpio/gpio-xilinx.c
··· 289 289 return 0; 290 290 } 291 291 292 - static struct of_device_id xgpio_of_match[] = { 292 + static const struct of_device_id xgpio_of_match[] = { 293 293 { .compatible = "xlnx,xps-gpio-1.00.a", }, 294 294 { /* end of list */ }, 295 295 };
+11 -7
drivers/gpio/gpio-zevio.c
··· 81 81 static int zevio_gpio_get(struct gpio_chip *chip, unsigned pin) 82 82 { 83 83 struct zevio_gpio *controller = to_zevio_gpio(chip); 84 + u32 val, dir; 84 85 85 - /* Only reading allowed, so no spinlock needed */ 86 - u32 val = zevio_gpio_port_get(controller, pin, ZEVIO_GPIO_INPUT); 86 + spin_lock(&controller->lock); 87 + dir = zevio_gpio_port_get(controller, pin, ZEVIO_GPIO_DIRECTION); 88 + if (dir & BIT(ZEVIO_GPIO_BIT(pin))) 89 + val = zevio_gpio_port_get(controller, pin, ZEVIO_GPIO_INPUT); 90 + else 91 + val = zevio_gpio_port_get(controller, pin, ZEVIO_GPIO_OUTPUT); 92 + spin_unlock(&controller->lock); 87 93 88 94 return (val >> ZEVIO_GPIO_BIT(pin)) & 0x1; 89 95 } ··· 178 172 int status, i; 179 173 180 174 controller = devm_kzalloc(&pdev->dev, sizeof(*controller), GFP_KERNEL); 181 - if (!controller) { 182 - dev_err(&pdev->dev, "not enough free memory\n"); 175 + if (!controller) 183 176 return -ENOMEM; 184 - } 185 177 186 178 /* Copy our reference */ 187 179 controller->chip.gc = zevio_gpio_chip; ··· 202 198 return 0; 203 199 } 204 200 205 - static struct of_device_id zevio_gpio_of_match[] = { 201 + static const struct of_device_id zevio_gpio_of_match[] = { 206 202 { .compatible = "lsi,zevio-gpio", }, 207 203 { }, 208 204 }; ··· 213 209 .driver = { 214 210 .name = "gpio-zevio", 215 211 .owner = THIS_MODULE, 216 - .of_match_table = of_match_ptr(zevio_gpio_of_match), 212 + .of_match_table = zevio_gpio_of_match, 217 213 }, 218 214 .probe = zevio_gpio_probe, 219 215 };
+3 -2
drivers/gpio/gpiolib-acpi.c
··· 449 449 mutex_unlock(&achip->conn_lock); 450 450 451 451 if (function == ACPI_WRITE) 452 - gpiod_set_raw_value(desc, !!((1 << i) & *value)); 452 + gpiod_set_raw_value_cansleep(desc, 453 + !!((1 << i) & *value)); 453 454 else 454 - *value |= (u64)gpiod_get_raw_value(desc) << i; 455 + *value |= (u64)gpiod_get_raw_value_cansleep(desc) << i; 455 456 } 456 457 457 458 out:
+15 -1
drivers/gpio/gpiolib-of.c
··· 48 48 if (ret < 0) 49 49 return false; 50 50 51 - gg_data->out_gpio = gpio_to_desc(ret + gc->base); 51 + gg_data->out_gpio = gpiochip_get_desc(gc, ret); 52 52 return true; 53 53 } 54 54 ··· 95 95 return gg_data.out_gpio; 96 96 } 97 97 EXPORT_SYMBOL(of_get_named_gpiod_flags); 98 + 99 + int of_get_named_gpio_flags(struct device_node *np, const char *list_name, 100 + int index, enum of_gpio_flags *flags) 101 + { 102 + struct gpio_desc *desc; 103 + 104 + desc = of_get_named_gpiod_flags(np, list_name, index, flags); 105 + 106 + if (IS_ERR(desc)) 107 + return PTR_ERR(desc); 108 + else 109 + return desc_to_gpio(desc); 110 + } 111 + EXPORT_SYMBOL(of_get_named_gpio_flags); 98 112 99 113 /** 100 114 * of_gpio_simple_xlate - translate gpio_spec to the GPIO number and flags
+83 -18
drivers/gpio/gpiolib.c
··· 1363 1363 int parent_irq, 1364 1364 irq_flow_handler_t parent_handler) 1365 1365 { 1366 + if (gpiochip->can_sleep) { 1367 + chip_err(gpiochip, "you cannot have chained interrupts on a chip that may sleep\n"); 1368 + return; 1369 + } 1370 + 1366 1371 irq_set_chained_handler(parent_irq, parent_handler); 1367 1372 /* 1368 1373 * The parent irqchip is already using the chip_data for this ··· 1376 1371 irq_set_handler_data(parent_irq, gpiochip); 1377 1372 } 1378 1373 EXPORT_SYMBOL_GPL(gpiochip_set_chained_irqchip); 1374 + 1375 + /* 1376 + * This lock class tells lockdep that GPIO irqs are in a different 1377 + * category than their parents, so it won't report false recursion. 1378 + */ 1379 + static struct lock_class_key gpiochip_irq_lock_class; 1379 1380 1380 1381 /** 1381 1382 * gpiochip_irq_map() - maps an IRQ into a GPIO irqchip ··· 1399 1388 struct gpio_chip *chip = d->host_data; 1400 1389 1401 1390 irq_set_chip_data(irq, chip); 1391 + irq_set_lockdep_class(irq, &gpiochip_irq_lock_class); 1402 1392 irq_set_chip_and_handler(irq, chip->irqchip, chip->irq_handler); 1393 + /* Chips that can sleep need nested thread handlers */ 1394 + if (chip->can_sleep) 1395 + irq_set_nested_thread(irq, 1); 1403 1396 #ifdef CONFIG_ARM 1404 1397 set_irq_flags(irq, IRQF_VALID); 1405 1398 #else 1406 1399 irq_set_noprobe(irq); 1407 1400 #endif 1408 - irq_set_irq_type(irq, chip->irq_default_type); 1401 + /* 1402 + * No set-up of the hardware will happen if IRQ_TYPE_NONE 1403 + * is passed as default type. 1404 + */ 1405 + if (chip->irq_default_type != IRQ_TYPE_NONE) 1406 + irq_set_irq_type(irq, chip->irq_default_type); 1409 1407 1410 1408 return 0; 1411 1409 } 1412 1410 1413 1411 static void gpiochip_irq_unmap(struct irq_domain *d, unsigned int irq) 1414 1412 { 1413 + struct gpio_chip *chip = d->host_data; 1414 + 1415 1415 #ifdef CONFIG_ARM 1416 1416 set_irq_flags(irq, 0); 1417 1417 #endif 1418 + if (chip->can_sleep) 1419 + irq_set_nested_thread(irq, 0); 1418 1420 irq_set_chip_and_handler(irq, NULL, NULL); 1419 1421 irq_set_chip_data(irq, NULL); 1420 1422 } ··· 1495 1471 * @first_irq: if not dynamically assigned, the base (first) IRQ to 1496 1472 * allocate gpiochip irqs from 1497 1473 * @handler: the irq handler to use (often a predefined irq core function) 1498 - * @type: the default type for IRQs on this irqchip 1474 + * @type: the default type for IRQs on this irqchip, pass IRQ_TYPE_NONE 1475 + * to have the core avoid setting up any default type in the hardware. 1499 1476 * 1500 1477 * This function closely associates a certain irqchip with a certain 1501 1478 * gpiochip, providing an irq domain to translate the local IRQs to ··· 2596 2571 mutex_unlock(&gpio_lookup_lock); 2597 2572 } 2598 2573 2599 - #ifdef CONFIG_OF 2600 2574 static struct gpio_desc *of_find_gpio(struct device *dev, const char *con_id, 2601 2575 unsigned int idx, 2602 2576 enum gpio_lookup_flags *flags) 2603 2577 { 2578 + static const char *suffixes[] = { "gpios", "gpio" }; 2604 2579 char prop_name[32]; /* 32 is max size of property name */ 2605 2580 enum of_gpio_flags of_flags; 2606 2581 struct gpio_desc *desc; 2582 + unsigned int i; 2607 2583 2608 - if (con_id) 2609 - snprintf(prop_name, 32, "%s-gpios", con_id); 2610 - else 2611 - snprintf(prop_name, 32, "gpios"); 2584 + for (i = 0; i < ARRAY_SIZE(suffixes); i++) { 2585 + if (con_id) 2586 + snprintf(prop_name, 32, "%s-%s", con_id, suffixes[i]); 2587 + else 2588 + snprintf(prop_name, 32, "%s", suffixes[i]); 2612 2589 2613 - desc = of_get_named_gpiod_flags(dev->of_node, prop_name, idx, 2614 - &of_flags); 2590 + desc = of_get_named_gpiod_flags(dev->of_node, prop_name, idx, 2591 + &of_flags); 2592 + if (!IS_ERR(desc)) 2593 + break; 2594 + } 2615 2595 2616 2596 if (IS_ERR(desc)) 2617 2597 return desc; ··· 2626 2596 2627 2597 return desc; 2628 2598 } 2629 - #else 2630 - static struct gpio_desc *of_find_gpio(struct device *dev, const char *con_id, 2631 - unsigned int idx, 2632 - enum gpio_lookup_flags *flags) 2633 - { 2634 - return ERR_PTR(-ENODEV); 2635 - } 2636 - #endif 2637 2599 2638 2600 static struct gpio_desc *acpi_find_gpio(struct device *dev, const char *con_id, 2639 2601 unsigned int idx, ··· 2723 2701 } 2724 2702 2725 2703 /** 2726 - * gpio_get - obtain a GPIO for a given GPIO function 2704 + * gpiod_get - obtain a GPIO for a given GPIO function 2727 2705 * @dev: GPIO consumer, can be NULL for system-global GPIOs 2728 2706 * @con_id: function within the GPIO consumer 2729 2707 * ··· 2736 2714 return gpiod_get_index(dev, con_id, 0); 2737 2715 } 2738 2716 EXPORT_SYMBOL_GPL(gpiod_get); 2717 + 2718 + /** 2719 + * gpiod_get_optional - obtain an optional GPIO for a given GPIO function 2720 + * @dev: GPIO consumer, can be NULL for system-global GPIOs 2721 + * @con_id: function within the GPIO consumer 2722 + * 2723 + * This is equivalent to gpiod_get(), except that when no GPIO was assigned to 2724 + * the requested function it will return NULL. This is convenient for drivers 2725 + * that need to handle optional GPIOs. 2726 + */ 2727 + struct gpio_desc *__must_check gpiod_get_optional(struct device *dev, 2728 + const char *con_id) 2729 + { 2730 + return gpiod_get_index_optional(dev, con_id, 0); 2731 + } 2732 + EXPORT_SYMBOL_GPL(gpiod_get_optional); 2739 2733 2740 2734 /** 2741 2735 * gpiod_get_index - obtain a GPIO from a multi-index GPIO function ··· 2814 2776 return desc; 2815 2777 } 2816 2778 EXPORT_SYMBOL_GPL(gpiod_get_index); 2779 + 2780 + /** 2781 + * gpiod_get_index_optional - obtain an optional GPIO from a multi-index GPIO 2782 + * function 2783 + * @dev: GPIO consumer, can be NULL for system-global GPIOs 2784 + * @con_id: function within the GPIO consumer 2785 + * @index: index of the GPIO to obtain in the consumer 2786 + * 2787 + * This is equivalent to gpiod_get_index(), except that when no GPIO with the 2788 + * specified index was assigned to the requested function it will return NULL. 2789 + * This is convenient for drivers that need to handle optional GPIOs. 2790 + */ 2791 + struct gpio_desc *__must_check gpiod_get_index_optional(struct device *dev, 2792 + const char *con_id, 2793 + unsigned int index) 2794 + { 2795 + struct gpio_desc *desc; 2796 + 2797 + desc = gpiod_get_index(dev, con_id, index); 2798 + if (IS_ERR(desc)) { 2799 + if (PTR_ERR(desc) == -ENOENT) 2800 + return NULL; 2801 + } 2802 + 2803 + return desc; 2804 + } 2805 + EXPORT_SYMBOL_GPL(gpiod_get_index_optional); 2817 2806 2818 2807 /** 2819 2808 * gpiod_put - dispose of a GPIO descriptor
+5
drivers/gpio/gpiolib.h
··· 15 15 #include <linux/err.h> 16 16 #include <linux/device.h> 17 17 18 + enum of_gpio_flags; 19 + 18 20 /** 19 21 * struct acpi_gpio_info - ACPI GPIO specific information 20 22 * @gpioint: if %true this GPIO is of type GpioInt otherwise type is GpioIo ··· 47 45 48 46 int gpiochip_request_own_desc(struct gpio_desc *desc, const char *label); 49 47 void gpiochip_free_own_desc(struct gpio_desc *desc); 48 + 49 + struct gpio_desc *of_get_named_gpiod_flags(struct device_node *np, 50 + const char *list_name, int index, enum of_gpio_flags *flags); 50 51 51 52 #endif /* GPIOLIB_H */
+41
include/linux/gpio/consumer.h
··· 1 1 #ifndef __LINUX_GPIO_CONSUMER_H 2 2 #define __LINUX_GPIO_CONSUMER_H 3 3 4 + #include <linux/bug.h> 4 5 #include <linux/err.h> 5 6 #include <linux/kernel.h> 6 7 ··· 24 23 struct gpio_desc *__must_check gpiod_get_index(struct device *dev, 25 24 const char *con_id, 26 25 unsigned int idx); 26 + struct gpio_desc *__must_check gpiod_get_optional(struct device *dev, 27 + const char *con_id); 28 + struct gpio_desc *__must_check gpiod_get_index_optional(struct device *dev, 29 + const char *con_id, 30 + unsigned int index); 31 + 27 32 void gpiod_put(struct gpio_desc *desc); 28 33 29 34 struct gpio_desc *__must_check devm_gpiod_get(struct device *dev, ··· 37 30 struct gpio_desc *__must_check devm_gpiod_get_index(struct device *dev, 38 31 const char *con_id, 39 32 unsigned int idx); 33 + struct gpio_desc *__must_check devm_gpiod_get_optional(struct device *dev, 34 + const char *con_id); 35 + struct gpio_desc *__must_check 36 + devm_gpiod_get_index_optional(struct device *dev, const char *con_id, 37 + unsigned int index); 38 + 40 39 void devm_gpiod_put(struct device *dev, struct gpio_desc *desc); 41 40 42 41 int gpiod_get_direction(const struct gpio_desc *desc); ··· 86 73 { 87 74 return ERR_PTR(-ENOSYS); 88 75 } 76 + 77 + static inline struct gpio_desc *__must_check 78 + gpiod_get_optional(struct device *dev, const char *con_id) 79 + { 80 + return ERR_PTR(-ENOSYS); 81 + } 82 + 83 + static inline struct gpio_desc *__must_check 84 + gpiod_get_index_optional(struct device *dev, const char *con_id, 85 + unsigned int index) 86 + { 87 + return ERR_PTR(-ENOSYS); 88 + } 89 + 89 90 static inline void gpiod_put(struct gpio_desc *desc) 90 91 { 91 92 might_sleep(); ··· 120 93 { 121 94 return ERR_PTR(-ENOSYS); 122 95 } 96 + 97 + static inline struct gpio_desc *__must_check 98 + devm_gpiod_get_optional(struct device *dev, const char *con_id) 99 + { 100 + return ERR_PTR(-ENOSYS); 101 + } 102 + 103 + static inline struct gpio_desc *__must_check 104 + devm_gpiod_get_index_optional(struct device *dev, const char *con_id, 105 + unsigned int index) 106 + { 107 + return ERR_PTR(-ENOSYS); 108 + } 109 + 123 110 static inline void devm_gpiod_put(struct device *dev, struct gpio_desc *desc) 124 111 { 125 112 might_sleep();
+4 -1
include/linux/gpio/driver.h
··· 51 51 * format specifier for an unsigned int. It is substituted by the actual 52 52 * number of the gpio. 53 53 * @can_sleep: flag must be set iff get()/set() methods sleep, as they 54 - * must while accessing GPIO expander chips over I2C or SPI 54 + * must while accessing GPIO expander chips over I2C or SPI. This 55 + * implies that if the chip supports IRQs, these IRQs need to be threaded 56 + * as the chip access may sleep when e.g. reading out the IRQ status 57 + * registers. 55 58 * @exported: flags if the gpiochip is exported for use from sysfs. Private. 56 59 * 57 60 * A gpio_chip can help platforms abstract various sources of GPIOs so
-1
include/linux/mfd/tc3589x.h
··· 111 111 #define TC3589x_INT_PORIRQ 7 112 112 113 113 #define TC3589x_NR_INTERNAL_IRQS 8 114 - #define TC3589x_INT_GPIO(x) (TC3589x_NR_INTERNAL_IRQS + (x)) 115 114 116 115 struct tc3589x { 117 116 struct mutex lock;
+3 -32
include/linux/of_gpio.h
··· 19 19 #include <linux/errno.h> 20 20 #include <linux/gpio.h> 21 21 #include <linux/of.h> 22 - #include <linux/gpio/consumer.h> 23 22 24 23 struct device_node; 25 24 ··· 47 48 return container_of(gc, struct of_mm_gpio_chip, gc); 48 49 } 49 50 50 - extern struct gpio_desc *of_get_named_gpiod_flags(struct device_node *np, 51 + extern int of_get_named_gpio_flags(struct device_node *np, 51 52 const char *list_name, int index, enum of_gpio_flags *flags); 52 53 53 54 extern int of_mm_gpiochip_add(struct device_node *np, ··· 62 63 #else /* CONFIG_OF_GPIO */ 63 64 64 65 /* Drivers may not strictly depend on the GPIO support, so let them link. */ 65 - static inline struct gpio_desc *of_get_named_gpiod_flags(struct device_node *np, 66 + static inline int of_get_named_gpio_flags(struct device_node *np, 66 67 const char *list_name, int index, enum of_gpio_flags *flags) 67 68 { 68 - return ERR_PTR(-ENOSYS); 69 + return -ENOSYS; 69 70 } 70 71 71 72 static inline int of_gpio_simple_xlate(struct gpio_chip *gc, ··· 79 80 static inline void of_gpiochip_remove(struct gpio_chip *gc) { } 80 81 81 82 #endif /* CONFIG_OF_GPIO */ 82 - 83 - static inline int of_get_named_gpio_flags(struct device_node *np, 84 - const char *list_name, int index, enum of_gpio_flags *flags) 85 - { 86 - struct gpio_desc *desc; 87 - desc = of_get_named_gpiod_flags(np, list_name, index, flags); 88 - 89 - if (IS_ERR(desc)) 90 - return PTR_ERR(desc); 91 - else 92 - return desc_to_gpio(desc); 93 - } 94 83 95 84 /** 96 85 * of_gpio_named_count() - Count GPIOs for a device ··· 114 127 static inline int of_gpio_count(struct device_node *np) 115 128 { 116 129 return of_gpio_named_count(np, "gpios"); 117 - } 118 - 119 - /** 120 - * of_get_gpiod_flags() - Get a GPIO descriptor and flags to use with GPIO API 121 - * @np: device node to get GPIO from 122 - * @index: index of the GPIO 123 - * @flags: a flags pointer to fill in 124 - * 125 - * Returns GPIO descriptor to use with Linux generic GPIO API, or a errno 126 - * value on the error condition. If @flags is not NULL the function also fills 127 - * in flags for the GPIO. 128 - */ 129 - static inline struct gpio_desc *of_get_gpiod_flags(struct device_node *np, 130 - int index, enum of_gpio_flags *flags) 131 - { 132 - return of_get_named_gpiod_flags(np, "gpios", index, flags); 133 130 } 134 131 135 132 static inline int of_get_gpio_flags(struct device_node *np, int index,