aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/gpio
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2014-06-02 11:46:03 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2014-06-02 11:46:03 -0400
commit80fb97479878f2c7c4f300de7758304fc0401006 (patch)
tree8883d339e309c944590014f7a05c860c83f001f5 /drivers/gpio
parent9f888b3a10782de27864659d4ab48eb6ef2c0bf3 (diff)
parentfc346270124a1a05a5b3c47f277d467ff410b3ae (diff)
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 ...
Diffstat (limited to 'drivers/gpio')
-rw-r--r--drivers/gpio/Kconfig20
-rw-r--r--drivers/gpio/Makefile2
-rw-r--r--drivers/gpio/devres.c43
-rw-r--r--drivers/gpio/gpio-adp5520.c4
-rw-r--r--drivers/gpio/gpio-adp5588.c4
-rw-r--r--drivers/gpio/gpio-bt8xx.c19
-rw-r--r--drivers/gpio/gpio-davinci.c4
-rw-r--r--drivers/gpio/gpio-dwapb.c38
-rw-r--r--drivers/gpio/gpio-em.c3
-rw-r--r--drivers/gpio/gpio-ep93xx.c34
-rw-r--r--drivers/gpio/gpio-ge.c174
-rw-r--r--drivers/gpio/gpio-generic.c9
-rw-r--r--drivers/gpio/gpio-grgpio.c2
-rw-r--r--drivers/gpio/gpio-janz-ttl.c38
-rw-r--r--drivers/gpio/gpio-kempld.c4
-rw-r--r--drivers/gpio/gpio-lynxpoint.c4
-rw-r--r--drivers/gpio/gpio-max730x.c5
-rw-r--r--drivers/gpio/gpio-mcp23s08.c17
-rw-r--r--drivers/gpio/gpio-moxart.c4
-rw-r--r--drivers/gpio/gpio-mvebu.c13
-rw-r--r--drivers/gpio/gpio-omap.c205
-rw-r--r--drivers/gpio/gpio-palmas.c6
-rw-r--r--drivers/gpio/gpio-pca953x.c102
-rw-r--r--drivers/gpio/gpio-pcf857x.c11
-rw-r--r--drivers/gpio/gpio-pch.c1
-rw-r--r--drivers/gpio/gpio-pl061.c27
-rw-r--r--drivers/gpio/gpio-rc5t583.c4
-rw-r--r--drivers/gpio/gpio-rcar.c9
-rw-r--r--drivers/gpio/gpio-rdc321x.c23
-rw-r--r--drivers/gpio/gpio-sch.c26
-rw-r--r--drivers/gpio/gpio-sch311x.c16
-rw-r--r--drivers/gpio/gpio-spear-spics.c4
-rw-r--r--drivers/gpio/gpio-sx150x.c1
-rw-r--r--drivers/gpio/gpio-tc3589x.c148
-rw-r--r--drivers/gpio/gpio-tegra.c6
-rw-r--r--drivers/gpio/gpio-timberdale.c47
-rw-r--r--drivers/gpio/gpio-tps6586x.c4
-rw-r--r--drivers/gpio/gpio-tps65910.c4
-rw-r--r--drivers/gpio/gpio-xilinx.c2
-rw-r--r--drivers/gpio/gpio-zevio.c18
-rw-r--r--drivers/gpio/gpiolib-acpi.c5
-rw-r--r--drivers/gpio/gpiolib-of.c16
-rw-r--r--drivers/gpio/gpiolib.c101
-rw-r--r--drivers/gpio/gpiolib.h5
44 files changed, 582 insertions, 650 deletions
diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig
index a86c49a605c6..4a1b5113e527 100644
--- a/drivers/gpio/Kconfig
+++ b/drivers/gpio/Kconfig
@@ -56,6 +56,7 @@ config GPIO_ACPI
56 depends on ACPI 56 depends on ACPI
57 57
58config GPIOLIB_IRQCHIP 58config GPIOLIB_IRQCHIP
59 select IRQ_DOMAIN
59 bool 60 bool
60 61
61config DEBUG_GPIO 62config DEBUG_GPIO
@@ -243,6 +244,15 @@ config GPIO_OCTEON
243 Say yes here to support the on-chip GPIO lines on the OCTEON 244 Say yes here to support the on-chip GPIO lines on the OCTEON
244 family of SOCs. 245 family of SOCs.
245 246
247config GPIO_OMAP
248 bool "TI OMAP GPIO support" if COMPILE_TEST && !ARCH_OMAP2PLUS
249 default y if ARCH_OMAP
250 depends on ARM
251 select GENERIC_IRQ_CHIP
252 select GPIOLIB_IRQCHIP
253 help
254 Say yes here to enable GPIO support for TI OMAP SoCs.
255
246config GPIO_PL061 256config GPIO_PL061
247 bool "PrimeCell PL061 GPIO support" 257 bool "PrimeCell PL061 GPIO support"
248 depends on ARM_AMBA 258 depends on ARM_AMBA
@@ -259,7 +269,7 @@ config GPIO_PXA
259 269
260config GPIO_RCAR 270config GPIO_RCAR
261 tristate "Renesas R-Car GPIO" 271 tristate "Renesas R-Car GPIO"
262 depends on ARM 272 depends on ARM && (ARCH_SHMOBILE || COMPILE_TEST)
263 help 273 help
264 Say yes here to support GPIO on Renesas R-Car SoCs. 274 Say yes here to support GPIO on Renesas R-Car SoCs.
265 275
@@ -510,6 +520,7 @@ config GPIO_PCA953X
510config GPIO_PCA953X_IRQ 520config GPIO_PCA953X_IRQ
511 bool "Interrupt controller support for PCA953x" 521 bool "Interrupt controller support for PCA953x"
512 depends on GPIO_PCA953X=y 522 depends on GPIO_PCA953X=y
523 select GPIOLIB_IRQCHIP
513 help 524 help
514 Say yes here to enable the pca953x to be used as an interrupt 525 Say yes here to enable the pca953x to be used as an interrupt
515 controller. It requires the driver to be built in the kernel. 526 controller. It requires the driver to be built in the kernel.
@@ -579,6 +590,7 @@ config GPIO_STP_XWAY
579config GPIO_TC3589X 590config GPIO_TC3589X
580 bool "TC3589X GPIOs" 591 bool "TC3589X GPIOs"
581 depends on MFD_TC3589X 592 depends on MFD_TC3589X
593 select GPIOLIB_IRQCHIP
582 help 594 help
583 This enables support for the GPIOs found on the TC3589X 595 This enables support for the GPIOs found on the TC3589X
584 I/O Expander. 596 I/O Expander.
@@ -699,13 +711,13 @@ config GPIO_AMD8111
699config GPIO_INTEL_MID 711config GPIO_INTEL_MID
700 bool "Intel Mid GPIO support" 712 bool "Intel Mid GPIO support"
701 depends on PCI && X86 713 depends on PCI && X86
702 select IRQ_DOMAIN 714 select GPIOLIB_IRQCHIP
703 help 715 help
704 Say Y here to support Intel Mid GPIO. 716 Say Y here to support Intel Mid GPIO.
705 717
706config GPIO_PCH 718config GPIO_PCH
707 tristate "Intel EG20T PCH/LAPIS Semiconductor IOH(ML7223/ML7831) GPIO" 719 tristate "Intel EG20T PCH/LAPIS Semiconductor IOH(ML7223/ML7831) GPIO"
708 depends on PCI && X86 720 depends on PCI && (X86_32 || COMPILE_TEST)
709 select GENERIC_IRQ_CHIP 721 select GENERIC_IRQ_CHIP
710 help 722 help
711 This driver is for PCH(Platform controller Hub) GPIO of Intel Topcliff 723 This driver is for PCH(Platform controller Hub) GPIO of Intel Topcliff
@@ -739,7 +751,7 @@ config GPIO_SODAVILLE
739 751
740config GPIO_TIMBERDALE 752config GPIO_TIMBERDALE
741 bool "Support for timberdale GPIO IP" 753 bool "Support for timberdale GPIO IP"
742 depends on MFD_TIMBERDALE && HAS_IOMEM 754 depends on MFD_TIMBERDALE
743 ---help--- 755 ---help---
744 Add support for the GPIO IP in the timberdale FPGA. 756 Add support for the GPIO IP in the timberdale FPGA.
745 757
diff --git a/drivers/gpio/Makefile b/drivers/gpio/Makefile
index 6309aff1d806..d10f6a9d875a 100644
--- a/drivers/gpio/Makefile
+++ b/drivers/gpio/Makefile
@@ -58,7 +58,7 @@ obj-$(CONFIG_GPIO_MVEBU) += gpio-mvebu.o
58obj-$(CONFIG_GPIO_MXC) += gpio-mxc.o 58obj-$(CONFIG_GPIO_MXC) += gpio-mxc.o
59obj-$(CONFIG_GPIO_MXS) += gpio-mxs.o 59obj-$(CONFIG_GPIO_MXS) += gpio-mxs.o
60obj-$(CONFIG_GPIO_OCTEON) += gpio-octeon.o 60obj-$(CONFIG_GPIO_OCTEON) += gpio-octeon.o
61obj-$(CONFIG_ARCH_OMAP) += gpio-omap.o 61obj-$(CONFIG_GPIO_OMAP) += gpio-omap.o
62obj-$(CONFIG_GPIO_PCA953X) += gpio-pca953x.o 62obj-$(CONFIG_GPIO_PCA953X) += gpio-pca953x.o
63obj-$(CONFIG_GPIO_PCF857X) += gpio-pcf857x.o 63obj-$(CONFIG_GPIO_PCF857X) += gpio-pcf857x.o
64obj-$(CONFIG_GPIO_PCH) += gpio-pch.o 64obj-$(CONFIG_GPIO_PCH) += gpio-pch.o
diff --git a/drivers/gpio/devres.c b/drivers/gpio/devres.c
index 307464fd015f..65978cf85f79 100644
--- a/drivers/gpio/devres.c
+++ b/drivers/gpio/devres.c
@@ -52,6 +52,22 @@ struct gpio_desc *__must_check devm_gpiod_get(struct device *dev,
52EXPORT_SYMBOL(devm_gpiod_get); 52EXPORT_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 */
63struct 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}
68EXPORT_SYMBOL(devm_gpiod_get_optional);
69
70/**
55 * devm_gpiod_get_index - Resource-managed gpiod_get_index() 71 * devm_gpiod_get_index - Resource-managed gpiod_get_index()
56 * @dev: GPIO consumer 72 * @dev: GPIO consumer
57 * @con_id: function within the GPIO consumer 73 * @con_id: function within the GPIO consumer
@@ -87,6 +103,33 @@ struct gpio_desc *__must_check devm_gpiod_get_index(struct device *dev,
87EXPORT_SYMBOL(devm_gpiod_get_index); 103EXPORT_SYMBOL(devm_gpiod_get_index);
88 104
89/** 105/**
106 * devm_gpiod_get_index_optional - Resource-managed gpiod_get_index_optional()
107 * @dev: GPIO consumer
108 * @con_id: function within the GPIO consumer
109 * @index: index of the GPIO to obtain in the consumer
110 *
111 * Managed gpiod_get_index_optional(). GPIO descriptors returned from this
112 * function are automatically disposed on driver detach. See
113 * gpiod_get_index_optional() for detailed information about behavior and
114 * return values.
115 */
116struct gpio_desc *__must_check devm_gpiod_get_index_optional(struct device *dev,
117 const char *con_id,
118 unsigned int index)
119{
120 struct gpio_desc *desc;
121
122 desc = devm_gpiod_get_index(dev, con_id, index);
123 if (IS_ERR(desc)) {
124 if (PTR_ERR(desc) == -ENOENT)
125 return NULL;
126 }
127
128 return desc;
129}
130EXPORT_SYMBOL(devm_gpiod_get_index_optional);
131
132/**
90 * devm_gpiod_put - Resource-managed gpiod_put() 133 * devm_gpiod_put - Resource-managed gpiod_put()
91 * @desc: GPIO descriptor to dispose of 134 * @desc: GPIO descriptor to dispose of
92 * 135 *
diff --git a/drivers/gpio/gpio-adp5520.c b/drivers/gpio/gpio-adp5520.c
index 613265944e2e..f1ade8fa3218 100644
--- a/drivers/gpio/gpio-adp5520.c
+++ b/drivers/gpio/gpio-adp5520.c
@@ -106,10 +106,8 @@ static int adp5520_gpio_probe(struct platform_device *pdev)
106 } 106 }
107 107
108 dev = devm_kzalloc(&pdev->dev, sizeof(*dev), GFP_KERNEL); 108 dev = devm_kzalloc(&pdev->dev, sizeof(*dev), GFP_KERNEL);
109 if (dev == NULL) { 109 if (dev == NULL)
110 dev_err(&pdev->dev, "failed to alloc memory\n");
111 return -ENOMEM; 110 return -ENOMEM;
112 }
113 111
114 dev->master = pdev->dev.parent; 112 dev->master = pdev->dev.parent;
115 113
diff --git a/drivers/gpio/gpio-adp5588.c b/drivers/gpio/gpio-adp5588.c
index d974020b78bb..ef19bc33f2bd 100644
--- a/drivers/gpio/gpio-adp5588.c
+++ b/drivers/gpio/gpio-adp5588.c
@@ -379,10 +379,8 @@ static int adp5588_gpio_probe(struct i2c_client *client,
379 } 379 }
380 380
381 dev = kzalloc(sizeof(*dev), GFP_KERNEL); 381 dev = kzalloc(sizeof(*dev), GFP_KERNEL);
382 if (dev == NULL) { 382 if (dev == NULL)
383 dev_err(&client->dev, "failed to alloc memory\n");
384 return -ENOMEM; 383 return -ENOMEM;
385 }
386 384
387 dev->client = client; 385 dev->client = client;
388 386
diff --git a/drivers/gpio/gpio-bt8xx.c b/drivers/gpio/gpio-bt8xx.c
index ecb3ca2d1d10..6557147d9331 100644
--- a/drivers/gpio/gpio-bt8xx.c
+++ b/drivers/gpio/gpio-bt8xx.c
@@ -178,7 +178,7 @@ static int bt8xxgpio_probe(struct pci_dev *dev,
178 struct bt8xxgpio *bg; 178 struct bt8xxgpio *bg;
179 int err; 179 int err;
180 180
181 bg = kzalloc(sizeof(*bg), GFP_KERNEL); 181 bg = devm_kzalloc(&dev->dev, sizeof(struct bt8xxgpio), GFP_KERNEL);
182 if (!bg) 182 if (!bg)
183 return -ENOMEM; 183 return -ENOMEM;
184 184
@@ -188,9 +188,9 @@ static int bt8xxgpio_probe(struct pci_dev *dev,
188 err = pci_enable_device(dev); 188 err = pci_enable_device(dev);
189 if (err) { 189 if (err) {
190 printk(KERN_ERR "bt8xxgpio: Can't enable device.\n"); 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 pci_resource_len(dev, 0), 194 pci_resource_len(dev, 0),
195 "bt8xxgpio")) { 195 "bt8xxgpio")) {
196 printk(KERN_WARNING "bt8xxgpio: Can't request iomem (0x%llx).\n", 196 printk(KERN_WARNING "bt8xxgpio: Can't request iomem (0x%llx).\n",
@@ -201,11 +201,11 @@ static int bt8xxgpio_probe(struct pci_dev *dev,
201 pci_set_master(dev); 201 pci_set_master(dev);
202 pci_set_drvdata(dev, bg); 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 if (!bg->mmio) { 205 if (!bg->mmio) {
206 printk(KERN_ERR "bt8xxgpio: ioremap() failed\n"); 206 printk(KERN_ERR "bt8xxgpio: ioremap() failed\n");
207 err = -EIO; 207 err = -EIO;
208 goto err_release_mem; 208 goto err_disable;
209 } 209 }
210 210
211 /* Disable interrupts */ 211 /* Disable interrupts */
@@ -220,18 +220,13 @@ static int bt8xxgpio_probe(struct pci_dev *dev,
220 err = gpiochip_add(&bg->gpio); 220 err = gpiochip_add(&bg->gpio);
221 if (err) { 221 if (err) {
222 printk(KERN_ERR "bt8xxgpio: Failed to register GPIOs\n"); 222 printk(KERN_ERR "bt8xxgpio: Failed to register GPIOs\n");
223 goto err_release_mem; 223 goto err_disable;
224 } 224 }
225 225
226 return 0; 226 return 0;
227 227
228err_release_mem:
229 release_mem_region(pci_resource_start(dev, 0),
230 pci_resource_len(dev, 0));
231err_disable: 228err_disable:
232 pci_disable_device(dev); 229 pci_disable_device(dev);
233err_freebg:
234 kfree(bg);
235 230
236 return err; 231 return err;
237} 232}
@@ -250,8 +245,6 @@ static void bt8xxgpio_remove(struct pci_dev *pdev)
250 release_mem_region(pci_resource_start(pdev, 0), 245 release_mem_region(pci_resource_start(pdev, 0),
251 pci_resource_len(pdev, 0)); 246 pci_resource_len(pdev, 0));
252 pci_disable_device(pdev); 247 pci_disable_device(pdev);
253
254 kfree(bg);
255} 248}
256 249
257#ifdef CONFIG_PM 250#ifdef CONFIG_PM
diff --git a/drivers/gpio/gpio-davinci.c b/drivers/gpio/gpio-davinci.c
index 339f9dac591b..9f0682534e2f 100644
--- a/drivers/gpio/gpio-davinci.c
+++ b/drivers/gpio/gpio-davinci.c
@@ -230,10 +230,8 @@ static int davinci_gpio_probe(struct platform_device *pdev)
230 chips = devm_kzalloc(dev, 230 chips = devm_kzalloc(dev,
231 ngpio * sizeof(struct davinci_gpio_controller), 231 ngpio * sizeof(struct davinci_gpio_controller),
232 GFP_KERNEL); 232 GFP_KERNEL);
233 if (!chips) { 233 if (!chips)
234 dev_err(dev, "Memory allocation failed\n");
235 return -ENOMEM; 234 return -ENOMEM;
236 }
237 235
238 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 236 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
239 if (!res) { 237 if (!res) {
diff --git a/drivers/gpio/gpio-dwapb.c b/drivers/gpio/gpio-dwapb.c
index ed5711f77e2d..cd3b81435274 100644
--- a/drivers/gpio/gpio-dwapb.c
+++ b/drivers/gpio/gpio-dwapb.c
@@ -198,6 +198,8 @@ static int dwapb_irq_set_type(struct irq_data *d, u32 type)
198 break; 198 break;
199 } 199 }
200 200
201 irq_setup_alt_chip(d, type);
202
201 writel(level, gpio->regs + GPIO_INTTYPE_LEVEL); 203 writel(level, gpio->regs + GPIO_INTTYPE_LEVEL);
202 writel(polarity, gpio->regs + GPIO_INT_POLARITY); 204 writel(polarity, gpio->regs + GPIO_INT_POLARITY);
203 spin_unlock_irqrestore(&bgc->lock, flags); 205 spin_unlock_irqrestore(&bgc->lock, flags);
@@ -213,7 +215,7 @@ static void dwapb_configure_irqs(struct dwapb_gpio *gpio,
213 struct irq_chip_generic *irq_gc; 215 struct irq_chip_generic *irq_gc;
214 unsigned int hwirq, ngpio = gc->ngpio; 216 unsigned int hwirq, ngpio = gc->ngpio;
215 struct irq_chip_type *ct; 217 struct irq_chip_type *ct;
216 int err, irq; 218 int err, irq, i;
217 219
218 irq = irq_of_parse_and_map(node, 0); 220 irq = irq_of_parse_and_map(node, 0);
219 if (!irq) { 221 if (!irq) {
@@ -227,7 +229,7 @@ static void dwapb_configure_irqs(struct dwapb_gpio *gpio,
227 if (!gpio->domain) 229 if (!gpio->domain)
228 return; 230 return;
229 231
230 err = irq_alloc_domain_generic_chips(gpio->domain, ngpio, 1, 232 err = irq_alloc_domain_generic_chips(gpio->domain, ngpio, 2,
231 "gpio-dwapb", handle_level_irq, 233 "gpio-dwapb", handle_level_irq,
232 IRQ_NOREQUEST, 0, 234 IRQ_NOREQUEST, 0,
233 IRQ_GC_INIT_NESTED_LOCK); 235 IRQ_GC_INIT_NESTED_LOCK);
@@ -248,20 +250,24 @@ static void dwapb_configure_irqs(struct dwapb_gpio *gpio,
248 irq_gc->reg_base = gpio->regs; 250 irq_gc->reg_base = gpio->regs;
249 irq_gc->private = gpio; 251 irq_gc->private = gpio;
250 252
251 ct = irq_gc->chip_types; 253 for (i = 0; i < 2; i++) {
252 ct->chip.irq_ack = irq_gc_ack_set_bit; 254 ct = &irq_gc->chip_types[i];
253 ct->chip.irq_mask = irq_gc_mask_set_bit; 255 ct->chip.irq_ack = irq_gc_ack_set_bit;
254 ct->chip.irq_unmask = irq_gc_mask_clr_bit; 256 ct->chip.irq_mask = irq_gc_mask_set_bit;
255 ct->chip.irq_set_type = dwapb_irq_set_type; 257 ct->chip.irq_unmask = irq_gc_mask_clr_bit;
256 ct->chip.irq_enable = dwapb_irq_enable; 258 ct->chip.irq_set_type = dwapb_irq_set_type;
257 ct->chip.irq_disable = dwapb_irq_disable; 259 ct->chip.irq_enable = dwapb_irq_enable;
258 ct->chip.irq_request_resources = dwapb_irq_reqres; 260 ct->chip.irq_disable = dwapb_irq_disable;
259 ct->chip.irq_release_resources = dwapb_irq_relres; 261 ct->chip.irq_request_resources = dwapb_irq_reqres;
260 ct->regs.ack = GPIO_PORTA_EOI; 262 ct->chip.irq_release_resources = dwapb_irq_relres;
261 ct->regs.mask = GPIO_INTMASK; 263 ct->regs.ack = GPIO_PORTA_EOI;
262 264 ct->regs.mask = GPIO_INTMASK;
263 irq_setup_generic_chip(irq_gc, IRQ_MSK(port->bgc.gc.ngpio), 265 ct->type = IRQ_TYPE_LEVEL_MASK;
264 IRQ_GC_INIT_NESTED_LOCK, IRQ_NOREQUEST, 0); 266 }
267
268 irq_gc->chip_types[0].type = IRQ_TYPE_LEVEL_MASK;
269 irq_gc->chip_types[1].type = IRQ_TYPE_EDGE_BOTH;
270 irq_gc->chip_types[1].handler = handle_edge_irq;
265 271
266 irq_set_chained_handler(irq, dwapb_irq_handler); 272 irq_set_chained_handler(irq, dwapb_irq_handler);
267 irq_set_handler_data(irq, gpio); 273 irq_set_handler_data(irq, gpio);
diff --git a/drivers/gpio/gpio-em.c b/drivers/gpio/gpio-em.c
index 8765bd6f48e1..cde36054c387 100644
--- a/drivers/gpio/gpio-em.c
+++ b/drivers/gpio/gpio-em.c
@@ -212,7 +212,7 @@ static void __em_gio_set(struct gpio_chip *chip, unsigned int reg,
212{ 212{
213 /* upper 16 bits contains mask and lower 16 actual value */ 213 /* upper 16 bits contains mask and lower 16 actual value */
214 em_gio_write(gpio_to_priv(chip), reg, 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
218static void em_gio_set(struct gpio_chip *chip, unsigned offset, int value) 218static void em_gio_set(struct gpio_chip *chip, unsigned offset, int value)
@@ -284,7 +284,6 @@ static int em_gio_probe(struct platform_device *pdev)
284 284
285 p = devm_kzalloc(&pdev->dev, sizeof(*p), GFP_KERNEL); 285 p = devm_kzalloc(&pdev->dev, sizeof(*p), GFP_KERNEL);
286 if (!p) { 286 if (!p) {
287 dev_err(&pdev->dev, "failed to allocate driver data\n");
288 ret = -ENOMEM; 287 ret = -ENOMEM;
289 goto err0; 288 goto err0;
290 } 289 }
diff --git a/drivers/gpio/gpio-ep93xx.c b/drivers/gpio/gpio-ep93xx.c
index 80829f3c6543..dcc2bb4074ef 100644
--- a/drivers/gpio/gpio-ep93xx.c
+++ b/drivers/gpio/gpio-ep93xx.c
@@ -344,37 +344,24 @@ static int ep93xx_gpio_probe(struct platform_device *pdev)
344{ 344{
345 struct ep93xx_gpio *ep93xx_gpio; 345 struct ep93xx_gpio *ep93xx_gpio;
346 struct resource *res; 346 struct resource *res;
347 void __iomem *mmio;
348 int i; 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 if (!ep93xx_gpio) 351 if (!ep93xx_gpio)
353 return -ENOMEM; 352 return -ENOMEM;
354 353
355 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 354 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
356 if (!res) { 355 ep93xx_gpio->mmio_base = devm_ioremap_resource(dev, res);
357 ret = -ENXIO; 356 if (IS_ERR(ep93xx_gpio->mmio_base))
358 goto exit_free; 357 return PTR_ERR(ep93xx_gpio->mmio_base);
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;
372 358
373 for (i = 0; i < ARRAY_SIZE(ep93xx_gpio_banks); i++) { 359 for (i = 0; i < ARRAY_SIZE(ep93xx_gpio_banks); i++) {
374 struct bgpio_chip *bgc = &ep93xx_gpio->bgc[i]; 360 struct bgpio_chip *bgc = &ep93xx_gpio->bgc[i];
375 struct ep93xx_gpio_bank *bank = &ep93xx_gpio_banks[i]; 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 dev_warn(&pdev->dev, "Unable to add gpio bank %s\n", 365 dev_warn(&pdev->dev, "Unable to add gpio bank %s\n",
379 bank->label); 366 bank->label);
380 } 367 }
@@ -382,13 +369,6 @@ static int ep93xx_gpio_probe(struct platform_device *pdev)
382 ep93xx_gpio_init_irq(); 369 ep93xx_gpio_init_irq();
383 370
384 return 0; 371 return 0;
385
386exit_release:
387 release_mem_region(res->start, resource_size(res));
388exit_free:
389 kfree(ep93xx_gpio);
390 dev_info(&pdev->dev, "%s failed with errno %d\n", __func__, ret);
391 return ret;
392} 372}
393 373
394static struct platform_driver ep93xx_gpio_driver = { 374static struct platform_driver ep93xx_gpio_driver = {
diff --git a/drivers/gpio/gpio-ge.c b/drivers/gpio/gpio-ge.c
index 7b95a4a8318c..1237a73c3c91 100644
--- a/drivers/gpio/gpio-ge.c
+++ b/drivers/gpio/gpio-ge.c
@@ -18,15 +18,9 @@
18 */ 18 */
19 19
20#include <linux/kernel.h> 20#include <linux/kernel.h>
21#include <linux/compiler.h>
22#include <linux/init.h>
23#include <linux/io.h> 21#include <linux/io.h>
24#include <linux/of.h>
25#include <linux/of_device.h> 22#include <linux/of_device.h>
26#include <linux/of_platform.h>
27#include <linux/of_gpio.h> 23#include <linux/of_gpio.h>
28#include <linux/gpio.h>
29#include <linux/slab.h>
30#include <linux/module.h> 24#include <linux/module.h>
31 25
32#define GEF_GPIO_DIRECT 0x00 26#define GEF_GPIO_DIRECT 0x00
@@ -39,28 +33,26 @@
39#define GEF_GPIO_OVERRUN 0x1C 33#define GEF_GPIO_OVERRUN 0x1C
40#define GEF_GPIO_MODE 0x20 34#define GEF_GPIO_MODE 0x20
41 35
42static void _gef_gpio_set(void __iomem *reg, unsigned int offset, int value) 36static void gef_gpio_set(struct gpio_chip *chip, unsigned offset, int value)
43{ 37{
38 struct of_mm_gpio_chip *mmchip = to_of_mm_gpio_chip(chip);
44 unsigned int data; 39 unsigned int data;
45 40
46 data = ioread32be(reg); 41 data = ioread32be(mmchip->regs + GEF_GPIO_OUT);
47 /* value: 0=low; 1=high */ 42 if (value)
48 if (value & 0x1) 43 data = data | BIT(offset);
49 data = data | (0x1 << offset);
50 else 44 else
51 data = data & ~(0x1 << offset); 45 data = data & ~BIT(offset);
52 46 iowrite32be(data, mmchip->regs + GEF_GPIO_OUT);
53 iowrite32be(data, reg);
54} 47}
55 48
56
57static int gef_gpio_dir_in(struct gpio_chip *chip, unsigned offset) 49static int gef_gpio_dir_in(struct gpio_chip *chip, unsigned offset)
58{ 50{
59 unsigned int data; 51 unsigned int data;
60 struct of_mm_gpio_chip *mmchip = to_of_mm_gpio_chip(chip); 52 struct of_mm_gpio_chip *mmchip = to_of_mm_gpio_chip(chip);
61 53
62 data = ioread32be(mmchip->regs + GEF_GPIO_DIRECT); 54 data = ioread32be(mmchip->regs + GEF_GPIO_DIRECT);
63 data = data | (0x1 << offset); 55 data = data | BIT(offset);
64 iowrite32be(data, mmchip->regs + GEF_GPIO_DIRECT); 56 iowrite32be(data, mmchip->regs + GEF_GPIO_DIRECT);
65 57
66 return 0; 58 return 0;
@@ -71,11 +63,11 @@ static int gef_gpio_dir_out(struct gpio_chip *chip, unsigned offset, int value)
71 unsigned int data; 63 unsigned int data;
72 struct of_mm_gpio_chip *mmchip = to_of_mm_gpio_chip(chip); 64 struct of_mm_gpio_chip *mmchip = to_of_mm_gpio_chip(chip);
73 65
74 /* Set direction before switching to input */ 66 /* Set value before switching to output */
75 _gef_gpio_set(mmchip->regs + GEF_GPIO_OUT, offset, value); 67 gef_gpio_set(mmchip->regs + GEF_GPIO_OUT, offset, value);
76 68
77 data = ioread32be(mmchip->regs + GEF_GPIO_DIRECT); 69 data = ioread32be(mmchip->regs + GEF_GPIO_DIRECT);
78 data = data & ~(0x1 << offset); 70 data = data & ~BIT(offset);
79 iowrite32be(data, mmchip->regs + GEF_GPIO_DIRECT); 71 iowrite32be(data, mmchip->regs + GEF_GPIO_DIRECT);
80 72
81 return 0; 73 return 0;
@@ -83,116 +75,56 @@ static int gef_gpio_dir_out(struct gpio_chip *chip, unsigned offset, int value)
83 75
84static int gef_gpio_get(struct gpio_chip *chip, unsigned offset) 76static int gef_gpio_get(struct gpio_chip *chip, unsigned offset)
85{ 77{
86 unsigned int data;
87 int state = 0;
88 struct of_mm_gpio_chip *mmchip = to_of_mm_gpio_chip(chip); 78 struct of_mm_gpio_chip *mmchip = to_of_mm_gpio_chip(chip);
89 79
90 data = ioread32be(mmchip->regs + GEF_GPIO_IN); 80 return !!(ioread32be(mmchip->regs + GEF_GPIO_IN) & BIT(offset));
91 state = (int)((data >> offset) & 0x1);
92
93 return state;
94} 81}
95 82
96static void gef_gpio_set(struct gpio_chip *chip, unsigned offset, int value) 83static const struct of_device_id gef_gpio_ids[] = {
97{ 84 {
98 struct of_mm_gpio_chip *mmchip = to_of_mm_gpio_chip(chip); 85 .compatible = "gef,sbc610-gpio",
99 86 .data = (void *)19,
100 _gef_gpio_set(mmchip->regs + GEF_GPIO_OUT, offset, value); 87 }, {
101} 88 .compatible = "gef,sbc310-gpio",
89 .data = (void *)6,
90 }, {
91 .compatible = "ge,imp3a-gpio",
92 .data = (void *)16,
93 },
94 { }
95};
96MODULE_DEVICE_TABLE(of, gef_gpio_ids);
102 97
103static int __init gef_gpio_init(void) 98static int __init gef_gpio_probe(struct platform_device *pdev)
104{ 99{
105 struct device_node *np; 100 const struct of_device_id *of_id =
106 int retval; 101 of_match_device(gef_gpio_ids, &pdev->dev);
107 struct of_mm_gpio_chip *gef_gpio_chip; 102 struct of_mm_gpio_chip *mmchip;
108 103
109 for_each_compatible_node(np, NULL, "gef,sbc610-gpio") { 104 mmchip = devm_kzalloc(&pdev->dev, sizeof(*mmchip), GFP_KERNEL);
110 105 if (!mmchip)
111 pr_debug("%s: Initialising GEF GPIO\n", np->full_name); 106 return -ENOMEM;
112 107
113 /* Allocate chip structure */ 108 /* Setup pointers to chip functions */
114 gef_gpio_chip = kzalloc(sizeof(*gef_gpio_chip), GFP_KERNEL); 109 mmchip->gc.ngpio = (u16)(uintptr_t)of_id->data;
115 if (!gef_gpio_chip) { 110 mmchip->gc.of_gpio_n_cells = 2;
116 pr_err("%s: Unable to allocate structure\n", 111 mmchip->gc.direction_input = gef_gpio_dir_in;
117 np->full_name); 112 mmchip->gc.direction_output = gef_gpio_dir_out;
118 continue; 113 mmchip->gc.get = gef_gpio_get;
119 } 114 mmchip->gc.set = gef_gpio_set;
120 115
121 /* Setup pointers to chip functions */ 116 /* This function adds a memory mapped GPIO chip */
122 gef_gpio_chip->gc.of_gpio_n_cells = 2; 117 return of_mm_gpiochip_add(pdev->dev.of_node, mmchip);
123 gef_gpio_chip->gc.ngpio = 19; 118};
124 gef_gpio_chip->gc.direction_input = gef_gpio_dir_in;
125 gef_gpio_chip->gc.direction_output = gef_gpio_dir_out;
126 gef_gpio_chip->gc.get = gef_gpio_get;
127 gef_gpio_chip->gc.set = gef_gpio_set;
128
129 /* This function adds a memory mapped GPIO chip */
130 retval = of_mm_gpiochip_add(np, gef_gpio_chip);
131 if (retval) {
132 kfree(gef_gpio_chip);
133 pr_err("%s: Unable to add GPIO\n", np->full_name);
134 }
135 }
136
137 for_each_compatible_node(np, NULL, "gef,sbc310-gpio") {
138
139 pr_debug("%s: Initialising GEF GPIO\n", np->full_name);
140
141 /* Allocate chip structure */
142 gef_gpio_chip = kzalloc(sizeof(*gef_gpio_chip), GFP_KERNEL);
143 if (!gef_gpio_chip) {
144 pr_err("%s: Unable to allocate structure\n",
145 np->full_name);
146 continue;
147 }
148
149 /* Setup pointers to chip functions */
150 gef_gpio_chip->gc.of_gpio_n_cells = 2;
151 gef_gpio_chip->gc.ngpio = 6;
152 gef_gpio_chip->gc.direction_input = gef_gpio_dir_in;
153 gef_gpio_chip->gc.direction_output = gef_gpio_dir_out;
154 gef_gpio_chip->gc.get = gef_gpio_get;
155 gef_gpio_chip->gc.set = gef_gpio_set;
156
157 /* This function adds a memory mapped GPIO chip */
158 retval = of_mm_gpiochip_add(np, gef_gpio_chip);
159 if (retval) {
160 kfree(gef_gpio_chip);
161 pr_err("%s: Unable to add GPIO\n", np->full_name);
162 }
163 }
164
165 for_each_compatible_node(np, NULL, "ge,imp3a-gpio") {
166
167 pr_debug("%s: Initialising GE GPIO\n", np->full_name);
168
169 /* Allocate chip structure */
170 gef_gpio_chip = kzalloc(sizeof(*gef_gpio_chip), GFP_KERNEL);
171 if (!gef_gpio_chip) {
172 pr_err("%s: Unable to allocate structure\n",
173 np->full_name);
174 continue;
175 }
176
177 /* Setup pointers to chip functions */
178 gef_gpio_chip->gc.of_gpio_n_cells = 2;
179 gef_gpio_chip->gc.ngpio = 16;
180 gef_gpio_chip->gc.direction_input = gef_gpio_dir_in;
181 gef_gpio_chip->gc.direction_output = gef_gpio_dir_out;
182 gef_gpio_chip->gc.get = gef_gpio_get;
183 gef_gpio_chip->gc.set = gef_gpio_set;
184
185 /* This function adds a memory mapped GPIO chip */
186 retval = of_mm_gpiochip_add(np, gef_gpio_chip);
187 if (retval) {
188 kfree(gef_gpio_chip);
189 pr_err("%s: Unable to add GPIO\n", np->full_name);
190 }
191 }
192 119
193 return 0; 120static struct platform_driver gef_gpio_driver = {
121 .driver = {
122 .name = "gef-gpio",
123 .owner = THIS_MODULE,
124 .of_match_table = gef_gpio_ids,
125 },
194}; 126};
195arch_initcall(gef_gpio_init); 127module_platform_driver_probe(gef_gpio_driver, gef_gpio_probe);
196 128
197MODULE_DESCRIPTION("GE I/O FPGA GPIO driver"); 129MODULE_DESCRIPTION("GE I/O FPGA GPIO driver");
198MODULE_AUTHOR("Martyn Welch <martyn.welch@ge.com"); 130MODULE_AUTHOR("Martyn Welch <martyn.welch@ge.com");
diff --git a/drivers/gpio/gpio-generic.c b/drivers/gpio/gpio-generic.c
index b5dff9e742f8..fea8c82bb8fc 100644
--- a/drivers/gpio/gpio-generic.c
+++ b/drivers/gpio/gpio-generic.c
@@ -388,6 +388,14 @@ static int bgpio_setup_direction(struct bgpio_chip *bgc,
388 return 0; 388 return 0;
389} 389}
390 390
391static 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
391int bgpio_remove(struct bgpio_chip *bgc) 399int bgpio_remove(struct bgpio_chip *bgc)
392{ 400{
393 return gpiochip_remove(&bgc->gc); 401 return gpiochip_remove(&bgc->gc);
@@ -413,6 +421,7 @@ int bgpio_init(struct bgpio_chip *bgc, struct device *dev,
413 bgc->gc.label = dev_name(dev); 421 bgc->gc.label = dev_name(dev);
414 bgc->gc.base = -1; 422 bgc->gc.base = -1;
415 bgc->gc.ngpio = bgc->bits; 423 bgc->gc.ngpio = bgc->bits;
424 bgc->gc.request = bgpio_request;
416 425
417 ret = bgpio_setup_io(bgc, dat, set, clr); 426 ret = bgpio_setup_io(bgc, dat, set, clr);
418 if (ret) 427 if (ret)
diff --git a/drivers/gpio/gpio-grgpio.c b/drivers/gpio/gpio-grgpio.c
index 84d2478ec294..3c3f515b7916 100644
--- a/drivers/gpio/gpio-grgpio.c
+++ b/drivers/gpio/gpio-grgpio.c
@@ -481,7 +481,7 @@ out:
481 return ret; 481 return ret;
482} 482}
483 483
484static struct of_device_id grgpio_match[] = { 484static const struct of_device_id grgpio_match[] = {
485 {.name = "GAISLER_GPIO"}, 485 {.name = "GAISLER_GPIO"},
486 {.name = "01_01a"}, 486 {.name = "01_01a"},
487 {}, 487 {},
diff --git a/drivers/gpio/gpio-janz-ttl.c b/drivers/gpio/gpio-janz-ttl.c
index 2ecd3a09c743..42852eaaf020 100644
--- a/drivers/gpio/gpio-janz-ttl.c
+++ b/drivers/gpio/gpio-janz-ttl.c
@@ -152,34 +152,21 @@ static int ttl_probe(struct platform_device *pdev)
152 pdata = dev_get_platdata(&pdev->dev); 152 pdata = dev_get_platdata(&pdev->dev);
153 if (!pdata) { 153 if (!pdata) {
154 dev_err(dev, "no platform data\n"); 154 dev_err(dev, "no platform data\n");
155 ret = -ENXIO; 155 return -ENXIO;
156 goto out_return;
157 } 156 }
158 157
159 mod = kzalloc(sizeof(*mod), GFP_KERNEL); 158 mod = devm_kzalloc(dev, sizeof(*mod), GFP_KERNEL);
160 if (!mod) { 159 if (!mod)
161 dev_err(dev, "unable to allocate private data\n"); 160 return -ENOMEM;
162 ret = -ENOMEM;
163 goto out_return;
164 }
165 161
166 platform_set_drvdata(pdev, mod); 162 platform_set_drvdata(pdev, mod);
167 spin_lock_init(&mod->lock); 163 spin_lock_init(&mod->lock);
168 164
169 /* get access to the MODULbus registers for this module */ 165 /* get access to the MODULbus registers for this module */
170 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 166 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
171 if (!res) { 167 mod->regs = devm_ioremap_resource(dev, res);
172 dev_err(dev, "MODULbus registers not found\n"); 168 if (IS_ERR(mod->regs))
173 ret = -ENODEV; 169 return PTR_ERR(mod->regs);
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 }
183 170
184 ttl_setup_device(mod); 171 ttl_setup_device(mod);
185 172
@@ -198,17 +185,10 @@ static int ttl_probe(struct platform_device *pdev)
198 ret = gpiochip_add(gpio); 185 ret = gpiochip_add(gpio);
199 if (ret) { 186 if (ret) {
200 dev_err(dev, "unable to add GPIO chip\n"); 187 dev_err(dev, "unable to add GPIO chip\n");
201 goto out_iounmap_regs; 188 return ret;
202 } 189 }
203 190
204 return 0; 191 return 0;
205
206out_iounmap_regs:
207 iounmap(mod->regs);
208out_free_mod:
209 kfree(mod);
210out_return:
211 return ret;
212} 192}
213 193
214static int ttl_remove(struct platform_device *pdev) 194static int ttl_remove(struct platform_device *pdev)
@@ -223,8 +203,6 @@ static int ttl_remove(struct platform_device *pdev)
223 return ret; 203 return ret;
224 } 204 }
225 205
226 iounmap(mod->regs);
227 kfree(mod);
228 return 0; 206 return 0;
229} 207}
230 208
diff --git a/drivers/gpio/gpio-kempld.c b/drivers/gpio/gpio-kempld.c
index c6d88173f5a2..1e5e51987d31 100644
--- a/drivers/gpio/gpio-kempld.c
+++ b/drivers/gpio/gpio-kempld.c
@@ -24,7 +24,7 @@
24#include <linux/mfd/kempld.h> 24#include <linux/mfd/kempld.h>
25 25
26#define KEMPLD_GPIO_MAX_NUM 16 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#define KEMPLD_GPIO_DIR_NUM(x) (0x40 + (x) / 8) 28#define KEMPLD_GPIO_DIR_NUM(x) (0x40 + (x) / 8)
29#define KEMPLD_GPIO_LVL_NUM(x) (0x42 + (x) / 8) 29#define KEMPLD_GPIO_LVL_NUM(x) (0x42 + (x) / 8)
30#define KEMPLD_GPIO_EVT_LVL_EDGE 0x46 30#define KEMPLD_GPIO_EVT_LVL_EDGE 0x46
@@ -216,4 +216,4 @@ module_platform_driver(kempld_gpio_driver);
216MODULE_DESCRIPTION("KEM PLD GPIO Driver"); 216MODULE_DESCRIPTION("KEM PLD GPIO Driver");
217MODULE_AUTHOR("Michael Brunner <michael.brunner@kontron.com>"); 217MODULE_AUTHOR("Michael Brunner <michael.brunner@kontron.com>");
218MODULE_LICENSE("GPL"); 218MODULE_LICENSE("GPL");
219MODULE_ALIAS("platform:gpio-kempld"); 219MODULE_ALIAS("platform:kempld-gpio");
diff --git a/drivers/gpio/gpio-lynxpoint.c b/drivers/gpio/gpio-lynxpoint.c
index 9a82a9074a2c..2bea89b72508 100644
--- a/drivers/gpio/gpio-lynxpoint.c
+++ b/drivers/gpio/gpio-lynxpoint.c
@@ -375,10 +375,8 @@ static int lp_gpio_probe(struct platform_device *pdev)
375 int ret = -ENODEV; 375 int ret = -ENODEV;
376 376
377 lg = devm_kzalloc(dev, sizeof(struct lp_gpio), GFP_KERNEL); 377 lg = devm_kzalloc(dev, sizeof(struct lp_gpio), GFP_KERNEL);
378 if (!lg) { 378 if (!lg)
379 dev_err(dev, "can't allocate lp_gpio chip data\n");
380 return -ENOMEM; 379 return -ENOMEM;
381 }
382 380
383 lg->pdev = pdev; 381 lg->pdev = pdev;
384 platform_set_drvdata(pdev, lg); 382 platform_set_drvdata(pdev, lg);
diff --git a/drivers/gpio/gpio-max730x.c b/drivers/gpio/gpio-max730x.c
index 8672755f95c9..0814584fcdc1 100644
--- a/drivers/gpio/gpio-max730x.c
+++ b/drivers/gpio/gpio-max730x.c
@@ -237,10 +237,9 @@ int __max730x_remove(struct device *dev)
237 ts->write(dev, 0x04, 0x00); 237 ts->write(dev, 0x04, 0x00);
238 238
239 ret = gpiochip_remove(&ts->chip); 239 ret = gpiochip_remove(&ts->chip);
240 if (!ret) { 240 if (!ret)
241 mutex_destroy(&ts->lock); 241 mutex_destroy(&ts->lock);
242 kfree(ts); 242 else
243 } else
244 dev_err(dev, "Failed to remove GPIO controller: %d\n", ret); 243 dev_err(dev, "Failed to remove GPIO controller: %d\n", ret);
245 244
246 return ret; 245 return ret;
diff --git a/drivers/gpio/gpio-mcp23s08.c b/drivers/gpio/gpio-mcp23s08.c
index 3d53fd6880d1..fe7c0e211f9a 100644
--- a/drivers/gpio/gpio-mcp23s08.c
+++ b/drivers/gpio/gpio-mcp23s08.c
@@ -714,7 +714,7 @@ fail:
714 714
715#ifdef CONFIG_OF 715#ifdef CONFIG_OF
716#ifdef CONFIG_SPI_MASTER 716#ifdef CONFIG_SPI_MASTER
717static struct of_device_id mcp23s08_spi_of_match[] = { 717static const struct of_device_id mcp23s08_spi_of_match[] = {
718 { 718 {
719 .compatible = "microchip,mcp23s08", 719 .compatible = "microchip,mcp23s08",
720 .data = (void *) MCP_TYPE_S08, 720 .data = (void *) MCP_TYPE_S08,
@@ -738,7 +738,7 @@ MODULE_DEVICE_TABLE(of, mcp23s08_spi_of_match);
738#endif 738#endif
739 739
740#if IS_ENABLED(CONFIG_I2C) 740#if IS_ENABLED(CONFIG_I2C)
741static struct of_device_id mcp23s08_i2c_of_match[] = { 741static const struct of_device_id mcp23s08_i2c_of_match[] = {
742 { 742 {
743 .compatible = "microchip,mcp23008", 743 .compatible = "microchip,mcp23008",
744 .data = (void *) MCP_TYPE_008, 744 .data = (void *) MCP_TYPE_008,
@@ -867,7 +867,7 @@ static int mcp23s08_probe(struct spi_device *spi)
867{ 867{
868 struct mcp23s08_platform_data *pdata; 868 struct mcp23s08_platform_data *pdata;
869 unsigned addr; 869 unsigned addr;
870 unsigned chips = 0; 870 int chips = 0;
871 struct mcp23s08_driver_data *data; 871 struct mcp23s08_driver_data *data;
872 int status, type; 872 int status, type;
873 unsigned base = -1, 873 unsigned base = -1,
@@ -894,11 +894,14 @@ static int mcp23s08_probe(struct spi_device *spi)
894 dev_err(&spi->dev, "invalid spi-present-mask\n"); 894 dev_err(&spi->dev, "invalid spi-present-mask\n");
895 return -ENODEV; 895 return -ENODEV;
896 } 896 }
897
897 for (addr = 0; addr < ARRAY_SIZE(pdata->chip); addr++) { 898 for (addr = 0; addr < ARRAY_SIZE(pdata->chip); addr++) {
898 if ((spi_present_mask & (1 << addr)))
899 chips++;
900 pullups[addr] = 0; 899 pullups[addr] = 0;
900 if (spi_present_mask & (1 << addr))
901 chips++;
901 } 902 }
903 if (!chips)
904 return -ENODEV;
902 } else { 905 } else {
903 type = spi_get_device_id(spi)->driver_data; 906 type = spi_get_device_id(spi)->driver_data;
904 pdata = dev_get_platdata(&spi->dev); 907 pdata = dev_get_platdata(&spi->dev);
@@ -937,6 +940,10 @@ static int mcp23s08_probe(struct spi_device *spi)
937 if (!(spi_present_mask & (1 << addr))) 940 if (!(spi_present_mask & (1 << addr)))
938 continue; 941 continue;
939 chips--; 942 chips--;
943 if (chips < 0) {
944 dev_err(&spi->dev, "FATAL: invalid negative chip id\n");
945 goto fail;
946 }
940 data->mcp[addr] = &data->chip[chips]; 947 data->mcp[addr] = &data->chip[chips];
941 status = mcp23s08_probe_one(data->mcp[addr], &spi->dev, spi, 948 status = mcp23s08_probe_one(data->mcp[addr], &spi->dev, spi,
942 0x40 | (addr << 1), type, base, 949 0x40 | (addr << 1), type, base,
diff --git a/drivers/gpio/gpio-moxart.c b/drivers/gpio/gpio-moxart.c
index ccd45704e5fd..4661e181be04 100644
--- a/drivers/gpio/gpio-moxart.c
+++ b/drivers/gpio/gpio-moxart.c
@@ -113,10 +113,8 @@ static int moxart_gpio_probe(struct platform_device *pdev)
113 int ret; 113 int ret;
114 114
115 mgc = devm_kzalloc(dev, sizeof(*mgc), GFP_KERNEL); 115 mgc = devm_kzalloc(dev, sizeof(*mgc), GFP_KERNEL);
116 if (!mgc) { 116 if (!mgc)
117 dev_err(dev, "can't allocate GPIO chip container\n");
118 return -ENOMEM; 117 return -ENOMEM;
119 }
120 mgc->gpio = moxart_template_chip; 118 mgc->gpio = moxart_template_chip;
121 119
122 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 120 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
diff --git a/drivers/gpio/gpio-mvebu.c b/drivers/gpio/gpio-mvebu.c
index d42509422394..418e38650363 100644
--- a/drivers/gpio/gpio-mvebu.c
+++ b/drivers/gpio/gpio-mvebu.c
@@ -535,7 +535,7 @@ static void mvebu_gpio_dbg_show(struct seq_file *s, struct gpio_chip *chip)
535#define mvebu_gpio_dbg_show NULL 535#define mvebu_gpio_dbg_show NULL
536#endif 536#endif
537 537
538static struct of_device_id mvebu_gpio_of_match[] = { 538static const struct of_device_id mvebu_gpio_of_match[] = {
539 { 539 {
540 .compatible = "marvell,orion-gpio", 540 .compatible = "marvell,orion-gpio",
541 .data = (void *) MVEBU_GPIO_SOC_VARIANT_ORION, 541 .data = (void *) MVEBU_GPIO_SOC_VARIANT_ORION,
@@ -574,10 +574,8 @@ static int mvebu_gpio_probe(struct platform_device *pdev)
574 soc_variant = MVEBU_GPIO_SOC_VARIANT_ORION; 574 soc_variant = MVEBU_GPIO_SOC_VARIANT_ORION;
575 575
576 mvchip = devm_kzalloc(&pdev->dev, sizeof(struct mvebu_gpio_chip), GFP_KERNEL); 576 mvchip = devm_kzalloc(&pdev->dev, sizeof(struct mvebu_gpio_chip), GFP_KERNEL);
577 if (!mvchip) { 577 if (!mvchip)
578 dev_err(&pdev->dev, "Cannot allocate memory\n");
579 return -ENOMEM; 578 return -ENOMEM;
580 }
581 579
582 if (of_property_read_u32(pdev->dev.of_node, "ngpios", &ngpios)) { 580 if (of_property_read_u32(pdev->dev.of_node, "ngpios", &ngpios)) {
583 dev_err(&pdev->dev, "Missing ngpios OF property\n"); 581 dev_err(&pdev->dev, "Missing ngpios OF property\n");
@@ -738,9 +736,4 @@ static struct platform_driver mvebu_gpio_driver = {
738 }, 736 },
739 .probe = mvebu_gpio_probe, 737 .probe = mvebu_gpio_probe,
740}; 738};
741 739module_platform_driver(mvebu_gpio_driver);
742static int __init mvebu_gpio_init(void)
743{
744 return platform_driver_register(&mvebu_gpio_driver);
745}
746postcore_initcall(mvebu_gpio_init);
diff --git a/drivers/gpio/gpio-omap.c b/drivers/gpio/gpio-omap.c
index 19b886c21b1d..00f29aa1fb9d 100644
--- a/drivers/gpio/gpio-omap.c
+++ b/drivers/gpio/gpio-omap.c
@@ -24,9 +24,9 @@
24#include <linux/pm.h> 24#include <linux/pm.h>
25#include <linux/of.h> 25#include <linux/of.h>
26#include <linux/of_device.h> 26#include <linux/of_device.h>
27#include <linux/irqdomain.h>
28#include <linux/irqchip/chained_irq.h> 27#include <linux/irqchip/chained_irq.h>
29#include <linux/gpio.h> 28#include <linux/gpio.h>
29#include <linux/bitops.h>
30#include <linux/platform_data/gpio-omap.h> 30#include <linux/platform_data/gpio-omap.h>
31 31
32#define OFF_MODE 1 32#define OFF_MODE 1
@@ -52,7 +52,6 @@ struct gpio_bank {
52 struct list_head node; 52 struct list_head node;
53 void __iomem *base; 53 void __iomem *base;
54 u16 irq; 54 u16 irq;
55 struct irq_domain *domain;
56 u32 non_wakeup_gpios; 55 u32 non_wakeup_gpios;
57 u32 enabled_non_wakeup_gpios; 56 u32 enabled_non_wakeup_gpios;
58 struct gpio_regs context; 57 struct gpio_regs context;
@@ -84,22 +83,21 @@ struct gpio_bank {
84}; 83};
85 84
86#define GPIO_INDEX(bank, gpio) (gpio % bank->width) 85#define GPIO_INDEX(bank, gpio) (gpio % bank->width)
87#define GPIO_BIT(bank, gpio) (1 << GPIO_INDEX(bank, gpio)) 86#define GPIO_BIT(bank, gpio) (BIT(GPIO_INDEX(bank, gpio)))
88#define GPIO_MOD_CTRL_BIT BIT(0) 87#define GPIO_MOD_CTRL_BIT BIT(0)
89 88
90#define BANK_USED(bank) (bank->mod_usage || bank->irq_usage) 89#define BANK_USED(bank) (bank->mod_usage || bank->irq_usage)
91#define LINE_USED(line, offset) (line & (1 << offset)) 90#define LINE_USED(line, offset) (line & (BIT(offset)))
92 91
93static int irq_to_gpio(struct gpio_bank *bank, unsigned int gpio_irq) 92static int irq_to_gpio(struct gpio_bank *bank, unsigned int gpio_irq)
94{ 93{
95 return bank->chip.base + gpio_irq; 94 return bank->chip.base + gpio_irq;
96} 95}
97 96
98static int omap_gpio_to_irq(struct gpio_chip *chip, unsigned offset) 97static inline struct gpio_bank *_irq_data_get_bank(struct irq_data *d)
99{ 98{
100 struct gpio_bank *bank = container_of(chip, struct gpio_bank, chip); 99 struct gpio_chip *chip = irq_data_get_irq_chip_data(d);
101 100 return container_of(chip, struct gpio_bank, chip);
102 return irq_find_mapping(bank->domain, offset);
103} 101}
104 102
105static void _set_gpio_direction(struct gpio_bank *bank, int gpio, int is_input) 103static void _set_gpio_direction(struct gpio_bank *bank, int gpio, int is_input)
@@ -110,9 +108,9 @@ static void _set_gpio_direction(struct gpio_bank *bank, int gpio, int is_input)
110 reg += bank->regs->direction; 108 reg += bank->regs->direction;
111 l = readl_relaxed(reg); 109 l = readl_relaxed(reg);
112 if (is_input) 110 if (is_input)
113 l |= 1 << gpio; 111 l |= BIT(gpio);
114 else 112 else
115 l &= ~(1 << gpio); 113 l &= ~(BIT(gpio));
116 writel_relaxed(l, reg); 114 writel_relaxed(l, reg);
117 bank->context.oe = l; 115 bank->context.oe = l;
118} 116}
@@ -155,14 +153,14 @@ static int _get_gpio_datain(struct gpio_bank *bank, int offset)
155{ 153{
156 void __iomem *reg = bank->base + bank->regs->datain; 154 void __iomem *reg = bank->base + bank->regs->datain;
157 155
158 return (readl_relaxed(reg) & (1 << offset)) != 0; 156 return (readl_relaxed(reg) & (BIT(offset))) != 0;
159} 157}
160 158
161static int _get_gpio_dataout(struct gpio_bank *bank, int offset) 159static int _get_gpio_dataout(struct gpio_bank *bank, int offset)
162{ 160{
163 void __iomem *reg = bank->base + bank->regs->dataout; 161 void __iomem *reg = bank->base + bank->regs->dataout;
164 162
165 return (readl_relaxed(reg) & (1 << offset)) != 0; 163 return (readl_relaxed(reg) & (BIT(offset))) != 0;
166} 164}
167 165
168static inline void _gpio_rmw(void __iomem *base, u32 reg, u32 mask, bool set) 166static inline void _gpio_rmw(void __iomem *base, u32 reg, u32 mask, bool set)
@@ -180,7 +178,7 @@ static inline void _gpio_rmw(void __iomem *base, u32 reg, u32 mask, bool set)
180static inline void _gpio_dbck_enable(struct gpio_bank *bank) 178static inline void _gpio_dbck_enable(struct gpio_bank *bank)
181{ 179{
182 if (bank->dbck_enable_mask && !bank->dbck_enabled) { 180 if (bank->dbck_enable_mask && !bank->dbck_enabled) {
183 clk_enable(bank->dbck); 181 clk_prepare_enable(bank->dbck);
184 bank->dbck_enabled = true; 182 bank->dbck_enabled = true;
185 183
186 writel_relaxed(bank->dbck_enable_mask, 184 writel_relaxed(bank->dbck_enable_mask,
@@ -198,7 +196,7 @@ static inline void _gpio_dbck_disable(struct gpio_bank *bank)
198 */ 196 */
199 writel_relaxed(0, bank->base + bank->regs->debounce_en); 197 writel_relaxed(0, bank->base + bank->regs->debounce_en);
200 198
201 clk_disable(bank->dbck); 199 clk_disable_unprepare(bank->dbck);
202 bank->dbck_enabled = false; 200 bank->dbck_enabled = false;
203 } 201 }
204} 202}
@@ -231,7 +229,7 @@ static void _set_gpio_debounce(struct gpio_bank *bank, unsigned gpio,
231 229
232 l = GPIO_BIT(bank, gpio); 230 l = GPIO_BIT(bank, gpio);
233 231
234 clk_enable(bank->dbck); 232 clk_prepare_enable(bank->dbck);
235 reg = bank->base + bank->regs->debounce; 233 reg = bank->base + bank->regs->debounce;
236 writel_relaxed(debounce, reg); 234 writel_relaxed(debounce, reg);
237 235
@@ -245,7 +243,7 @@ static void _set_gpio_debounce(struct gpio_bank *bank, unsigned gpio,
245 bank->dbck_enable_mask = val; 243 bank->dbck_enable_mask = val;
246 244
247 writel_relaxed(val, reg); 245 writel_relaxed(val, reg);
248 clk_disable(bank->dbck); 246 clk_disable_unprepare(bank->dbck);
249 /* 247 /*
250 * Enable debounce clock per module. 248 * Enable debounce clock per module.
251 * This call is mandatory because in omap_gpio_request() when 249 * This call is mandatory because in omap_gpio_request() when
@@ -290,7 +288,7 @@ static void _clear_gpio_debounce(struct gpio_bank *bank, unsigned gpio)
290 bank->context.debounce = 0; 288 bank->context.debounce = 0;
291 writel_relaxed(bank->context.debounce, bank->base + 289 writel_relaxed(bank->context.debounce, bank->base +
292 bank->regs->debounce); 290 bank->regs->debounce);
293 clk_disable(bank->dbck); 291 clk_disable_unprepare(bank->dbck);
294 bank->dbck_enabled = false; 292 bank->dbck_enabled = false;
295 } 293 }
296} 294}
@@ -299,7 +297,7 @@ static inline void set_gpio_trigger(struct gpio_bank *bank, int gpio,
299 unsigned trigger) 297 unsigned trigger)
300{ 298{
301 void __iomem *base = bank->base; 299 void __iomem *base = bank->base;
302 u32 gpio_bit = 1 << gpio; 300 u32 gpio_bit = BIT(gpio);
303 301
304 _gpio_rmw(base, bank->regs->leveldetect0, gpio_bit, 302 _gpio_rmw(base, bank->regs->leveldetect0, gpio_bit,
305 trigger & IRQ_TYPE_LEVEL_LOW); 303 trigger & IRQ_TYPE_LEVEL_LOW);
@@ -368,9 +366,9 @@ static void _toggle_gpio_edge_triggering(struct gpio_bank *bank, int gpio)
368 366
369 l = readl_relaxed(reg); 367 l = readl_relaxed(reg);
370 if ((l >> gpio) & 1) 368 if ((l >> gpio) & 1)
371 l &= ~(1 << gpio); 369 l &= ~(BIT(gpio));
372 else 370 else
373 l |= 1 << gpio; 371 l |= BIT(gpio);
374 372
375 writel_relaxed(l, reg); 373 writel_relaxed(l, reg);
376} 374}
@@ -392,11 +390,11 @@ static int _set_gpio_triggering(struct gpio_bank *bank, int gpio,
392 390
393 l = readl_relaxed(reg); 391 l = readl_relaxed(reg);
394 if ((trigger & IRQ_TYPE_SENSE_MASK) == IRQ_TYPE_EDGE_BOTH) 392 if ((trigger & IRQ_TYPE_SENSE_MASK) == IRQ_TYPE_EDGE_BOTH)
395 bank->toggle_mask |= 1 << gpio; 393 bank->toggle_mask |= BIT(gpio);
396 if (trigger & IRQ_TYPE_EDGE_RISING) 394 if (trigger & IRQ_TYPE_EDGE_RISING)
397 l |= 1 << gpio; 395 l |= BIT(gpio);
398 else if (trigger & IRQ_TYPE_EDGE_FALLING) 396 else if (trigger & IRQ_TYPE_EDGE_FALLING)
399 l &= ~(1 << gpio); 397 l &= ~(BIT(gpio));
400 else 398 else
401 return -EINVAL; 399 return -EINVAL;
402 400
@@ -413,10 +411,10 @@ static int _set_gpio_triggering(struct gpio_bank *bank, int gpio,
413 if (trigger & IRQ_TYPE_EDGE_RISING) 411 if (trigger & IRQ_TYPE_EDGE_RISING)
414 l |= 2 << (gpio << 1); 412 l |= 2 << (gpio << 1);
415 if (trigger & IRQ_TYPE_EDGE_FALLING) 413 if (trigger & IRQ_TYPE_EDGE_FALLING)
416 l |= 1 << (gpio << 1); 414 l |= BIT(gpio << 1);
417 415
418 /* Enable wake-up during idle for dynamic tick */ 416 /* Enable wake-up during idle for dynamic tick */
419 _gpio_rmw(base, bank->regs->wkup_en, 1 << gpio, trigger); 417 _gpio_rmw(base, bank->regs->wkup_en, BIT(gpio), trigger);
420 bank->context.wake_en = 418 bank->context.wake_en =
421 readl_relaxed(bank->base + bank->regs->wkup_en); 419 readl_relaxed(bank->base + bank->regs->wkup_en);
422 writel_relaxed(l, reg); 420 writel_relaxed(l, reg);
@@ -430,7 +428,7 @@ static void _enable_gpio_module(struct gpio_bank *bank, unsigned offset)
430 void __iomem *reg = bank->base + bank->regs->pinctrl; 428 void __iomem *reg = bank->base + bank->regs->pinctrl;
431 429
432 /* Claim the pin for MPU */ 430 /* Claim the pin for MPU */
433 writel_relaxed(readl_relaxed(reg) | (1 << offset), reg); 431 writel_relaxed(readl_relaxed(reg) | (BIT(offset)), reg);
434 } 432 }
435 433
436 if (bank->regs->ctrl && !BANK_USED(bank)) { 434 if (bank->regs->ctrl && !BANK_USED(bank)) {
@@ -453,7 +451,7 @@ static void _disable_gpio_module(struct gpio_bank *bank, unsigned offset)
453 !LINE_USED(bank->mod_usage, offset) && 451 !LINE_USED(bank->mod_usage, offset) &&
454 !LINE_USED(bank->irq_usage, offset)) { 452 !LINE_USED(bank->irq_usage, offset)) {
455 /* Disable wake-up during idle for dynamic tick */ 453 /* Disable wake-up during idle for dynamic tick */
456 _gpio_rmw(base, bank->regs->wkup_en, 1 << offset, 0); 454 _gpio_rmw(base, bank->regs->wkup_en, BIT(offset), 0);
457 bank->context.wake_en = 455 bank->context.wake_en =
458 readl_relaxed(bank->base + bank->regs->wkup_en); 456 readl_relaxed(bank->base + bank->regs->wkup_en);
459 } 457 }
@@ -479,7 +477,7 @@ static int gpio_is_input(struct gpio_bank *bank, int mask)
479 477
480static int gpio_irq_type(struct irq_data *d, unsigned type) 478static int gpio_irq_type(struct irq_data *d, unsigned type)
481{ 479{
482 struct gpio_bank *bank = irq_data_get_irq_chip_data(d); 480 struct gpio_bank *bank = _irq_data_get_bank(d);
483 unsigned gpio = 0; 481 unsigned gpio = 0;
484 int retval; 482 int retval;
485 unsigned long flags; 483 unsigned long flags;
@@ -509,20 +507,12 @@ static int gpio_irq_type(struct irq_data *d, unsigned type)
509 if (!LINE_USED(bank->mod_usage, offset)) { 507 if (!LINE_USED(bank->mod_usage, offset)) {
510 _enable_gpio_module(bank, offset); 508 _enable_gpio_module(bank, offset);
511 _set_gpio_direction(bank, offset, 1); 509 _set_gpio_direction(bank, offset, 1);
512 } else if (!gpio_is_input(bank, 1 << offset)) { 510 } else if (!gpio_is_input(bank, BIT(offset))) {
513 spin_unlock_irqrestore(&bank->lock, flags); 511 spin_unlock_irqrestore(&bank->lock, flags);
514 return -EINVAL; 512 return -EINVAL;
515 } 513 }
516 514
517 retval = gpio_lock_as_irq(&bank->chip, offset); 515 bank->irq_usage |= BIT(GPIO_INDEX(bank, gpio));
518 if (retval) {
519 dev_err(bank->dev, "unable to lock offset %d for IRQ\n",
520 offset);
521 spin_unlock_irqrestore(&bank->lock, flags);
522 return retval;
523 }
524
525 bank->irq_usage |= 1 << GPIO_INDEX(bank, gpio);
526 spin_unlock_irqrestore(&bank->lock, flags); 516 spin_unlock_irqrestore(&bank->lock, flags);
527 517
528 if (type & (IRQ_TYPE_LEVEL_LOW | IRQ_TYPE_LEVEL_HIGH)) 518 if (type & (IRQ_TYPE_LEVEL_LOW | IRQ_TYPE_LEVEL_HIGH))
@@ -559,7 +549,7 @@ static u32 _get_gpio_irqbank_mask(struct gpio_bank *bank)
559{ 549{
560 void __iomem *reg = bank->base; 550 void __iomem *reg = bank->base;
561 u32 l; 551 u32 l;
562 u32 mask = (1 << bank->width) - 1; 552 u32 mask = (BIT(bank->width)) - 1;
563 553
564 reg += bank->regs->irqenable; 554 reg += bank->regs->irqenable;
565 l = readl_relaxed(reg); 555 l = readl_relaxed(reg);
@@ -664,7 +654,7 @@ static void _reset_gpio(struct gpio_bank *bank, int gpio)
664/* Use disable_irq_wake() and enable_irq_wake() functions from drivers */ 654/* Use disable_irq_wake() and enable_irq_wake() functions from drivers */
665static int gpio_wake_enable(struct irq_data *d, unsigned int enable) 655static int gpio_wake_enable(struct irq_data *d, unsigned int enable)
666{ 656{
667 struct gpio_bank *bank = irq_data_get_irq_chip_data(d); 657 struct gpio_bank *bank = _irq_data_get_bank(d);
668 unsigned int gpio = irq_to_gpio(bank, d->hwirq); 658 unsigned int gpio = irq_to_gpio(bank, d->hwirq);
669 659
670 return _set_gpio_wakeup(bank, gpio, enable); 660 return _set_gpio_wakeup(bank, gpio, enable);
@@ -691,7 +681,7 @@ static int omap_gpio_request(struct gpio_chip *chip, unsigned offset)
691 _set_gpio_triggering(bank, offset, IRQ_TYPE_NONE); 681 _set_gpio_triggering(bank, offset, IRQ_TYPE_NONE);
692 _enable_gpio_module(bank, offset); 682 _enable_gpio_module(bank, offset);
693 } 683 }
694 bank->mod_usage |= 1 << offset; 684 bank->mod_usage |= BIT(offset);
695 spin_unlock_irqrestore(&bank->lock, flags); 685 spin_unlock_irqrestore(&bank->lock, flags);
696 686
697 return 0; 687 return 0;
@@ -703,7 +693,7 @@ static void omap_gpio_free(struct gpio_chip *chip, unsigned offset)
703 unsigned long flags; 693 unsigned long flags;
704 694
705 spin_lock_irqsave(&bank->lock, flags); 695 spin_lock_irqsave(&bank->lock, flags);
706 bank->mod_usage &= ~(1 << offset); 696 bank->mod_usage &= ~(BIT(offset));
707 _disable_gpio_module(bank, offset); 697 _disable_gpio_module(bank, offset);
708 _reset_gpio(bank, bank->chip.base + offset); 698 _reset_gpio(bank, bank->chip.base + offset);
709 spin_unlock_irqrestore(&bank->lock, flags); 699 spin_unlock_irqrestore(&bank->lock, flags);
@@ -732,11 +722,12 @@ static void gpio_irq_handler(unsigned int irq, struct irq_desc *desc)
732 unsigned int bit; 722 unsigned int bit;
733 struct gpio_bank *bank; 723 struct gpio_bank *bank;
734 int unmasked = 0; 724 int unmasked = 0;
735 struct irq_chip *chip = irq_desc_get_chip(desc); 725 struct irq_chip *irqchip = irq_desc_get_chip(desc);
726 struct gpio_chip *chip = irq_get_handler_data(irq);
736 727
737 chained_irq_enter(chip, desc); 728 chained_irq_enter(irqchip, desc);
738 729
739 bank = irq_get_handler_data(irq); 730 bank = container_of(chip, struct gpio_bank, chip);
740 isr_reg = bank->base + bank->regs->irqstatus; 731 isr_reg = bank->base + bank->regs->irqstatus;
741 pm_runtime_get_sync(bank->dev); 732 pm_runtime_get_sync(bank->dev);
742 733
@@ -764,7 +755,7 @@ static void gpio_irq_handler(unsigned int irq, struct irq_desc *desc)
764 configured, we could unmask GPIO bank interrupt immediately */ 755 configured, we could unmask GPIO bank interrupt immediately */
765 if (!level_mask && !unmasked) { 756 if (!level_mask && !unmasked) {
766 unmasked = 1; 757 unmasked = 1;
767 chained_irq_exit(chip, desc); 758 chained_irq_exit(irqchip, desc);
768 } 759 }
769 760
770 if (!isr) 761 if (!isr)
@@ -772,7 +763,7 @@ static void gpio_irq_handler(unsigned int irq, struct irq_desc *desc)
772 763
773 while (isr) { 764 while (isr) {
774 bit = __ffs(isr); 765 bit = __ffs(isr);
775 isr &= ~(1 << bit); 766 isr &= ~(BIT(bit));
776 767
777 /* 768 /*
778 * Some chips can't respond to both rising and falling 769 * Some chips can't respond to both rising and falling
@@ -781,10 +772,11 @@ static void gpio_irq_handler(unsigned int irq, struct irq_desc *desc)
781 * to respond to the IRQ for the opposite direction. 772 * to respond to the IRQ for the opposite direction.
782 * This will be indicated in the bank toggle_mask. 773 * This will be indicated in the bank toggle_mask.
783 */ 774 */
784 if (bank->toggle_mask & (1 << bit)) 775 if (bank->toggle_mask & (BIT(bit)))
785 _toggle_gpio_edge_triggering(bank, bit); 776 _toggle_gpio_edge_triggering(bank, bit);
786 777
787 generic_handle_irq(irq_find_mapping(bank->domain, bit)); 778 generic_handle_irq(irq_find_mapping(bank->chip.irqdomain,
779 bit));
788 } 780 }
789 } 781 }
790 /* if bank has any level sensitive GPIO pin interrupt 782 /* if bank has any level sensitive GPIO pin interrupt
@@ -793,20 +785,20 @@ static void gpio_irq_handler(unsigned int irq, struct irq_desc *desc)
793 interrupt */ 785 interrupt */
794exit: 786exit:
795 if (!unmasked) 787 if (!unmasked)
796 chained_irq_exit(chip, desc); 788 chained_irq_exit(irqchip, desc);
797 pm_runtime_put(bank->dev); 789 pm_runtime_put(bank->dev);
798} 790}
799 791
800static void gpio_irq_shutdown(struct irq_data *d) 792static void gpio_irq_shutdown(struct irq_data *d)
801{ 793{
802 struct gpio_bank *bank = irq_data_get_irq_chip_data(d); 794 struct gpio_bank *bank = _irq_data_get_bank(d);
803 unsigned int gpio = irq_to_gpio(bank, d->hwirq); 795 unsigned int gpio = irq_to_gpio(bank, d->hwirq);
804 unsigned long flags; 796 unsigned long flags;
805 unsigned offset = GPIO_INDEX(bank, gpio); 797 unsigned offset = GPIO_INDEX(bank, gpio);
806 798
807 spin_lock_irqsave(&bank->lock, flags); 799 spin_lock_irqsave(&bank->lock, flags);
808 gpio_unlock_as_irq(&bank->chip, offset); 800 gpio_unlock_as_irq(&bank->chip, offset);
809 bank->irq_usage &= ~(1 << offset); 801 bank->irq_usage &= ~(BIT(offset));
810 _disable_gpio_module(bank, offset); 802 _disable_gpio_module(bank, offset);
811 _reset_gpio(bank, gpio); 803 _reset_gpio(bank, gpio);
812 spin_unlock_irqrestore(&bank->lock, flags); 804 spin_unlock_irqrestore(&bank->lock, flags);
@@ -821,7 +813,7 @@ static void gpio_irq_shutdown(struct irq_data *d)
821 813
822static void gpio_ack_irq(struct irq_data *d) 814static void gpio_ack_irq(struct irq_data *d)
823{ 815{
824 struct gpio_bank *bank = irq_data_get_irq_chip_data(d); 816 struct gpio_bank *bank = _irq_data_get_bank(d);
825 unsigned int gpio = irq_to_gpio(bank, d->hwirq); 817 unsigned int gpio = irq_to_gpio(bank, d->hwirq);
826 818
827 _clear_gpio_irqstatus(bank, gpio); 819 _clear_gpio_irqstatus(bank, gpio);
@@ -829,7 +821,7 @@ static void gpio_ack_irq(struct irq_data *d)
829 821
830static void gpio_mask_irq(struct irq_data *d) 822static void gpio_mask_irq(struct irq_data *d)
831{ 823{
832 struct gpio_bank *bank = irq_data_get_irq_chip_data(d); 824 struct gpio_bank *bank = _irq_data_get_bank(d);
833 unsigned int gpio = irq_to_gpio(bank, d->hwirq); 825 unsigned int gpio = irq_to_gpio(bank, d->hwirq);
834 unsigned long flags; 826 unsigned long flags;
835 827
@@ -841,7 +833,7 @@ static void gpio_mask_irq(struct irq_data *d)
841 833
842static void gpio_unmask_irq(struct irq_data *d) 834static void gpio_unmask_irq(struct irq_data *d)
843{ 835{
844 struct gpio_bank *bank = irq_data_get_irq_chip_data(d); 836 struct gpio_bank *bank = _irq_data_get_bank(d);
845 unsigned int gpio = irq_to_gpio(bank, d->hwirq); 837 unsigned int gpio = irq_to_gpio(bank, d->hwirq);
846 unsigned int irq_mask = GPIO_BIT(bank, gpio); 838 unsigned int irq_mask = GPIO_BIT(bank, gpio);
847 u32 trigger = irqd_get_trigger_type(d); 839 u32 trigger = irqd_get_trigger_type(d);
@@ -936,6 +928,21 @@ static inline void mpuio_init(struct gpio_bank *bank)
936 928
937/*---------------------------------------------------------------------*/ 929/*---------------------------------------------------------------------*/
938 930
931static int gpio_get_direction(struct gpio_chip *chip, unsigned offset)
932{
933 struct gpio_bank *bank;
934 unsigned long flags;
935 void __iomem *reg;
936 int dir;
937
938 bank = container_of(chip, struct gpio_bank, chip);
939 reg = bank->base + bank->regs->direction;
940 spin_lock_irqsave(&bank->lock, flags);
941 dir = !!(readl_relaxed(reg) & BIT(offset));
942 spin_unlock_irqrestore(&bank->lock, flags);
943 return dir;
944}
945
939static int gpio_input(struct gpio_chip *chip, unsigned offset) 946static int gpio_input(struct gpio_chip *chip, unsigned offset)
940{ 947{
941 struct gpio_bank *bank; 948 struct gpio_bank *bank;
@@ -954,7 +961,7 @@ static int gpio_get(struct gpio_chip *chip, unsigned offset)
954 u32 mask; 961 u32 mask;
955 962
956 bank = container_of(chip, struct gpio_bank, chip); 963 bank = container_of(chip, struct gpio_bank, chip);
957 mask = (1 << offset); 964 mask = (BIT(offset));
958 965
959 if (gpio_is_input(bank, mask)) 966 if (gpio_is_input(bank, mask))
960 return _get_gpio_datain(bank, offset); 967 return _get_gpio_datain(bank, offset);
@@ -1081,10 +1088,12 @@ omap_mpuio_alloc_gc(struct gpio_bank *bank, unsigned int irq_start,
1081 IRQ_NOREQUEST | IRQ_NOPROBE, 0); 1088 IRQ_NOREQUEST | IRQ_NOPROBE, 0);
1082} 1089}
1083 1090
1084static void omap_gpio_chip_init(struct gpio_bank *bank) 1091static int omap_gpio_chip_init(struct gpio_bank *bank)
1085{ 1092{
1086 int j; 1093 int j;
1087 static int gpio; 1094 static int gpio;
1095 int irq_base = 0;
1096 int ret;
1088 1097
1089 /* 1098 /*
1090 * REVISIT eventually switch from OMAP-specific gpio structs 1099 * REVISIT eventually switch from OMAP-specific gpio structs
@@ -1092,12 +1101,12 @@ static void omap_gpio_chip_init(struct gpio_bank *bank)
1092 */ 1101 */
1093 bank->chip.request = omap_gpio_request; 1102 bank->chip.request = omap_gpio_request;
1094 bank->chip.free = omap_gpio_free; 1103 bank->chip.free = omap_gpio_free;
1104 bank->chip.get_direction = gpio_get_direction;
1095 bank->chip.direction_input = gpio_input; 1105 bank->chip.direction_input = gpio_input;
1096 bank->chip.get = gpio_get; 1106 bank->chip.get = gpio_get;
1097 bank->chip.direction_output = gpio_output; 1107 bank->chip.direction_output = gpio_output;
1098 bank->chip.set_debounce = gpio_debounce; 1108 bank->chip.set_debounce = gpio_debounce;
1099 bank->chip.set = gpio_set; 1109 bank->chip.set = gpio_set;
1100 bank->chip.to_irq = omap_gpio_to_irq;
1101 if (bank->is_mpuio) { 1110 if (bank->is_mpuio) {
1102 bank->chip.label = "mpuio"; 1111 bank->chip.label = "mpuio";
1103 if (bank->regs->wkup_en) 1112 if (bank->regs->wkup_en)
@@ -1110,22 +1119,48 @@ static void omap_gpio_chip_init(struct gpio_bank *bank)
1110 } 1119 }
1111 bank->chip.ngpio = bank->width; 1120 bank->chip.ngpio = bank->width;
1112 1121
1113 gpiochip_add(&bank->chip); 1122 ret = gpiochip_add(&bank->chip);
1123 if (ret) {
1124 dev_err(bank->dev, "Could not register gpio chip %d\n", ret);
1125 return ret;
1126 }
1127
1128#ifdef CONFIG_ARCH_OMAP1
1129 /*
1130 * REVISIT: Once we have OMAP1 supporting SPARSE_IRQ, we can drop
1131 * irq_alloc_descs() since a base IRQ offset will no longer be needed.
1132 */
1133 irq_base = irq_alloc_descs(-1, 0, bank->width, 0);
1134 if (irq_base < 0) {
1135 dev_err(bank->dev, "Couldn't allocate IRQ numbers\n");
1136 return -ENODEV;
1137 }
1138#endif
1139
1140 ret = gpiochip_irqchip_add(&bank->chip, &gpio_irq_chip,
1141 irq_base, gpio_irq_handler,
1142 IRQ_TYPE_NONE);
1143
1144 if (ret) {
1145 dev_err(bank->dev, "Couldn't add irqchip to gpiochip %d\n", ret);
1146 ret = gpiochip_remove(&bank->chip);
1147 return -ENODEV;
1148 }
1149
1150 gpiochip_set_chained_irqchip(&bank->chip, &gpio_irq_chip,
1151 bank->irq, gpio_irq_handler);
1114 1152
1115 for (j = 0; j < bank->width; j++) { 1153 for (j = 0; j < bank->width; j++) {
1116 int irq = irq_create_mapping(bank->domain, j); 1154 int irq = irq_find_mapping(bank->chip.irqdomain, j);
1117 irq_set_lockdep_class(irq, &gpio_lock_class); 1155 irq_set_lockdep_class(irq, &gpio_lock_class);
1118 irq_set_chip_data(irq, bank);
1119 if (bank->is_mpuio) { 1156 if (bank->is_mpuio) {
1120 omap_mpuio_alloc_gc(bank, irq, bank->width); 1157 omap_mpuio_alloc_gc(bank, irq, bank->width);
1121 } else { 1158 irq_set_chip_and_handler(irq, NULL, NULL);
1122 irq_set_chip_and_handler(irq, &gpio_irq_chip, 1159 set_irq_flags(irq, 0);
1123 handle_simple_irq);
1124 set_irq_flags(irq, IRQF_VALID);
1125 } 1160 }
1126 } 1161 }
1127 irq_set_chained_handler(bank->irq, gpio_irq_handler); 1162
1128 irq_set_handler_data(bank->irq, bank); 1163 return 0;
1129} 1164}
1130 1165
1131static const struct of_device_id omap_gpio_match[]; 1166static const struct of_device_id omap_gpio_match[];
@@ -1138,9 +1173,7 @@ static int omap_gpio_probe(struct platform_device *pdev)
1138 const struct omap_gpio_platform_data *pdata; 1173 const struct omap_gpio_platform_data *pdata;
1139 struct resource *res; 1174 struct resource *res;
1140 struct gpio_bank *bank; 1175 struct gpio_bank *bank;
1141#ifdef CONFIG_ARCH_OMAP1 1176 int ret;
1142 int irq_base;
1143#endif
1144 1177
1145 match = of_match_device(of_match_ptr(omap_gpio_match), dev); 1178 match = of_match_device(of_match_ptr(omap_gpio_match), dev);
1146 1179
@@ -1162,6 +1195,7 @@ static int omap_gpio_probe(struct platform_device *pdev)
1162 1195
1163 bank->irq = res->start; 1196 bank->irq = res->start;
1164 bank->dev = dev; 1197 bank->dev = dev;
1198 bank->chip.dev = dev;
1165 bank->dbck_flag = pdata->dbck_flag; 1199 bank->dbck_flag = pdata->dbck_flag;
1166 bank->stride = pdata->bank_stride; 1200 bank->stride = pdata->bank_stride;
1167 bank->width = pdata->bank_width; 1201 bank->width = pdata->bank_width;
@@ -1182,29 +1216,6 @@ static int omap_gpio_probe(struct platform_device *pdev)
1182 pdata->get_context_loss_count; 1216 pdata->get_context_loss_count;
1183 } 1217 }
1184 1218
1185#ifdef CONFIG_ARCH_OMAP1
1186 /*
1187 * REVISIT: Once we have OMAP1 supporting SPARSE_IRQ, we can drop
1188 * irq_alloc_descs() and irq_domain_add_legacy() and just use a
1189 * linear IRQ domain mapping for all OMAP platforms.
1190 */
1191 irq_base = irq_alloc_descs(-1, 0, bank->width, 0);
1192 if (irq_base < 0) {
1193 dev_err(dev, "Couldn't allocate IRQ numbers\n");
1194 return -ENODEV;
1195 }
1196
1197 bank->domain = irq_domain_add_legacy(node, bank->width, irq_base,
1198 0, &irq_domain_simple_ops, NULL);
1199#else
1200 bank->domain = irq_domain_add_linear(node, bank->width,
1201 &irq_domain_simple_ops, NULL);
1202#endif
1203 if (!bank->domain) {
1204 dev_err(dev, "Couldn't register an IRQ domain\n");
1205 return -ENODEV;
1206 }
1207
1208 if (bank->regs->set_dataout && bank->regs->clr_dataout) 1219 if (bank->regs->set_dataout && bank->regs->clr_dataout)
1209 bank->set_dataout = _set_gpio_dataout_reg; 1220 bank->set_dataout = _set_gpio_dataout_reg;
1210 else 1221 else
@@ -1216,7 +1227,7 @@ static int omap_gpio_probe(struct platform_device *pdev)
1216 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 1227 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1217 bank->base = devm_ioremap_resource(dev, res); 1228 bank->base = devm_ioremap_resource(dev, res);
1218 if (IS_ERR(bank->base)) { 1229 if (IS_ERR(bank->base)) {
1219 irq_domain_remove(bank->domain); 1230 irq_domain_remove(bank->chip.irqdomain);
1220 return PTR_ERR(bank->base); 1231 return PTR_ERR(bank->base);
1221 } 1232 }
1222 1233
@@ -1230,7 +1241,11 @@ static int omap_gpio_probe(struct platform_device *pdev)
1230 mpuio_init(bank); 1241 mpuio_init(bank);
1231 1242
1232 omap_gpio_mod_init(bank); 1243 omap_gpio_mod_init(bank);
1233 omap_gpio_chip_init(bank); 1244
1245 ret = omap_gpio_chip_init(bank);
1246 if (ret)
1247 return ret;
1248
1234 omap_gpio_show_rev(bank); 1249 omap_gpio_show_rev(bank);
1235 1250
1236 pm_runtime_put(bank->dev); 1251 pm_runtime_put(bank->dev);
diff --git a/drivers/gpio/gpio-palmas.c b/drivers/gpio/gpio-palmas.c
index da9d33252e56..86bdbe362068 100644
--- a/drivers/gpio/gpio-palmas.c
+++ b/drivers/gpio/gpio-palmas.c
@@ -148,7 +148,7 @@ static const struct palmas_device_data tps80036_dev_data = {
148 .ngpio = 16, 148 .ngpio = 16,
149}; 149};
150 150
151static struct of_device_id of_palmas_gpio_match[] = { 151static const struct of_device_id of_palmas_gpio_match[] = {
152 { .compatible = "ti,palmas-gpio", .data = &palmas_dev_data,}, 152 { .compatible = "ti,palmas-gpio", .data = &palmas_dev_data,},
153 { .compatible = "ti,tps65913-gpio", .data = &palmas_dev_data,}, 153 { .compatible = "ti,tps65913-gpio", .data = &palmas_dev_data,},
154 { .compatible = "ti,tps65914-gpio", .data = &palmas_dev_data,}, 154 { .compatible = "ti,tps65914-gpio", .data = &palmas_dev_data,},
@@ -173,10 +173,8 @@ static int palmas_gpio_probe(struct platform_device *pdev)
173 173
174 palmas_gpio = devm_kzalloc(&pdev->dev, 174 palmas_gpio = devm_kzalloc(&pdev->dev,
175 sizeof(*palmas_gpio), GFP_KERNEL); 175 sizeof(*palmas_gpio), GFP_KERNEL);
176 if (!palmas_gpio) { 176 if (!palmas_gpio)
177 dev_err(&pdev->dev, "Could not allocate palmas_gpio\n");
178 return -ENOMEM; 177 return -ENOMEM;
179 }
180 178
181 palmas_gpio->palmas = palmas; 179 palmas_gpio->palmas = palmas;
182 palmas_gpio->gpio_chip.owner = THIS_MODULE; 180 palmas_gpio->gpio_chip.owner = THIS_MODULE;
diff --git a/drivers/gpio/gpio-pca953x.c b/drivers/gpio/gpio-pca953x.c
index d550d8e58705..e721a37c3473 100644
--- a/drivers/gpio/gpio-pca953x.c
+++ b/drivers/gpio/gpio-pca953x.c
@@ -15,8 +15,6 @@
15#include <linux/init.h> 15#include <linux/init.h>
16#include <linux/gpio.h> 16#include <linux/gpio.h>
17#include <linux/interrupt.h> 17#include <linux/interrupt.h>
18#include <linux/irq.h>
19#include <linux/irqdomain.h>
20#include <linux/i2c.h> 18#include <linux/i2c.h>
21#include <linux/platform_data/pca953x.h> 19#include <linux/platform_data/pca953x.h>
22#include <linux/slab.h> 20#include <linux/slab.h>
@@ -91,7 +89,6 @@ struct pca953x_chip {
91 u8 irq_stat[MAX_BANK]; 89 u8 irq_stat[MAX_BANK];
92 u8 irq_trig_raise[MAX_BANK]; 90 u8 irq_trig_raise[MAX_BANK];
93 u8 irq_trig_fall[MAX_BANK]; 91 u8 irq_trig_fall[MAX_BANK];
94 struct irq_domain *domain;
95#endif 92#endif
96 93
97 struct i2c_client *client; 94 struct i2c_client *client;
@@ -100,6 +97,11 @@ struct pca953x_chip {
100 int chip_type; 97 int chip_type;
101}; 98};
102 99
100static inline struct pca953x_chip *to_pca(struct gpio_chip *gc)
101{
102 return container_of(gc, struct pca953x_chip, gpio_chip);
103}
104
103static int pca953x_read_single(struct pca953x_chip *chip, int reg, u32 *val, 105static int pca953x_read_single(struct pca953x_chip *chip, int reg, u32 *val,
104 int off) 106 int off)
105{ 107{
@@ -202,12 +204,10 @@ static int pca953x_read_regs(struct pca953x_chip *chip, int reg, u8 *val)
202 204
203static int pca953x_gpio_direction_input(struct gpio_chip *gc, unsigned off) 205static int pca953x_gpio_direction_input(struct gpio_chip *gc, unsigned off)
204{ 206{
205 struct pca953x_chip *chip; 207 struct pca953x_chip *chip = to_pca(gc);
206 u8 reg_val; 208 u8 reg_val;
207 int ret, offset = 0; 209 int ret, offset = 0;
208 210
209 chip = container_of(gc, struct pca953x_chip, gpio_chip);
210
211 mutex_lock(&chip->i2c_lock); 211 mutex_lock(&chip->i2c_lock);
212 reg_val = chip->reg_direction[off / BANK_SZ] | (1u << (off % BANK_SZ)); 212 reg_val = chip->reg_direction[off / BANK_SZ] | (1u << (off % BANK_SZ));
213 213
@@ -233,12 +233,10 @@ exit:
233static int pca953x_gpio_direction_output(struct gpio_chip *gc, 233static int pca953x_gpio_direction_output(struct gpio_chip *gc,
234 unsigned off, int val) 234 unsigned off, int val)
235{ 235{
236 struct pca953x_chip *chip; 236 struct pca953x_chip *chip = to_pca(gc);
237 u8 reg_val; 237 u8 reg_val;
238 int ret, offset = 0; 238 int ret, offset = 0;
239 239
240 chip = container_of(gc, struct pca953x_chip, gpio_chip);
241
242 mutex_lock(&chip->i2c_lock); 240 mutex_lock(&chip->i2c_lock);
243 /* set output level */ 241 /* set output level */
244 if (val) 242 if (val)
@@ -285,12 +283,10 @@ exit:
285 283
286static int pca953x_gpio_get_value(struct gpio_chip *gc, unsigned off) 284static int pca953x_gpio_get_value(struct gpio_chip *gc, unsigned off)
287{ 285{
288 struct pca953x_chip *chip; 286 struct pca953x_chip *chip = to_pca(gc);
289 u32 reg_val; 287 u32 reg_val;
290 int ret, offset = 0; 288 int ret, offset = 0;
291 289
292 chip = container_of(gc, struct pca953x_chip, gpio_chip);
293
294 mutex_lock(&chip->i2c_lock); 290 mutex_lock(&chip->i2c_lock);
295 switch (chip->chip_type) { 291 switch (chip->chip_type) {
296 case PCA953X_TYPE: 292 case PCA953X_TYPE:
@@ -315,12 +311,10 @@ static int pca953x_gpio_get_value(struct gpio_chip *gc, unsigned off)
315 311
316static void pca953x_gpio_set_value(struct gpio_chip *gc, unsigned off, int val) 312static void pca953x_gpio_set_value(struct gpio_chip *gc, unsigned off, int val)
317{ 313{
318 struct pca953x_chip *chip; 314 struct pca953x_chip *chip = to_pca(gc);
319 u8 reg_val; 315 u8 reg_val;
320 int ret, offset = 0; 316 int ret, offset = 0;
321 317
322 chip = container_of(gc, struct pca953x_chip, gpio_chip);
323
324 mutex_lock(&chip->i2c_lock); 318 mutex_lock(&chip->i2c_lock);
325 if (val) 319 if (val)
326 reg_val = chip->reg_output[off / BANK_SZ] 320 reg_val = chip->reg_output[off / BANK_SZ]
@@ -367,38 +361,34 @@ static void pca953x_setup_gpio(struct pca953x_chip *chip, int gpios)
367} 361}
368 362
369#ifdef CONFIG_GPIO_PCA953X_IRQ 363#ifdef CONFIG_GPIO_PCA953X_IRQ
370static int pca953x_gpio_to_irq(struct gpio_chip *gc, unsigned off)
371{
372 struct pca953x_chip *chip;
373
374 chip = container_of(gc, struct pca953x_chip, gpio_chip);
375 return irq_create_mapping(chip->domain, off);
376}
377
378static void pca953x_irq_mask(struct irq_data *d) 364static void pca953x_irq_mask(struct irq_data *d)
379{ 365{
380 struct pca953x_chip *chip = irq_data_get_irq_chip_data(d); 366 struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
367 struct pca953x_chip *chip = to_pca(gc);
381 368
382 chip->irq_mask[d->hwirq / BANK_SZ] &= ~(1 << (d->hwirq % BANK_SZ)); 369 chip->irq_mask[d->hwirq / BANK_SZ] &= ~(1 << (d->hwirq % BANK_SZ));
383} 370}
384 371
385static void pca953x_irq_unmask(struct irq_data *d) 372static void pca953x_irq_unmask(struct irq_data *d)
386{ 373{
387 struct pca953x_chip *chip = irq_data_get_irq_chip_data(d); 374 struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
375 struct pca953x_chip *chip = to_pca(gc);
388 376
389 chip->irq_mask[d->hwirq / BANK_SZ] |= 1 << (d->hwirq % BANK_SZ); 377 chip->irq_mask[d->hwirq / BANK_SZ] |= 1 << (d->hwirq % BANK_SZ);
390} 378}
391 379
392static void pca953x_irq_bus_lock(struct irq_data *d) 380static void pca953x_irq_bus_lock(struct irq_data *d)
393{ 381{
394 struct pca953x_chip *chip = irq_data_get_irq_chip_data(d); 382 struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
383 struct pca953x_chip *chip = to_pca(gc);
395 384
396 mutex_lock(&chip->irq_lock); 385 mutex_lock(&chip->irq_lock);
397} 386}
398 387
399static void pca953x_irq_bus_sync_unlock(struct irq_data *d) 388static void pca953x_irq_bus_sync_unlock(struct irq_data *d)
400{ 389{
401 struct pca953x_chip *chip = irq_data_get_irq_chip_data(d); 390 struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
391 struct pca953x_chip *chip = to_pca(gc);
402 u8 new_irqs; 392 u8 new_irqs;
403 int level, i; 393 int level, i;
404 394
@@ -420,7 +410,8 @@ static void pca953x_irq_bus_sync_unlock(struct irq_data *d)
420 410
421static int pca953x_irq_set_type(struct irq_data *d, unsigned int type) 411static int pca953x_irq_set_type(struct irq_data *d, unsigned int type)
422{ 412{
423 struct pca953x_chip *chip = irq_data_get_irq_chip_data(d); 413 struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
414 struct pca953x_chip *chip = to_pca(gc);
424 int bank_nb = d->hwirq / BANK_SZ; 415 int bank_nb = d->hwirq / BANK_SZ;
425 u8 mask = 1 << (d->hwirq % BANK_SZ); 416 u8 mask = 1 << (d->hwirq % BANK_SZ);
426 417
@@ -503,44 +494,25 @@ static irqreturn_t pca953x_irq_handler(int irq, void *devid)
503 struct pca953x_chip *chip = devid; 494 struct pca953x_chip *chip = devid;
504 u8 pending[MAX_BANK]; 495 u8 pending[MAX_BANK];
505 u8 level; 496 u8 level;
497 unsigned nhandled = 0;
506 int i; 498 int i;
507 499
508 if (!pca953x_irq_pending(chip, pending)) 500 if (!pca953x_irq_pending(chip, pending))
509 return IRQ_HANDLED; 501 return IRQ_NONE;
510 502
511 for (i = 0; i < NBANK(chip); i++) { 503 for (i = 0; i < NBANK(chip); i++) {
512 while (pending[i]) { 504 while (pending[i]) {
513 level = __ffs(pending[i]); 505 level = __ffs(pending[i]);
514 handle_nested_irq(irq_find_mapping(chip->domain, 506 handle_nested_irq(irq_find_mapping(chip->gpio_chip.irqdomain,
515 level + (BANK_SZ * i))); 507 level + (BANK_SZ * i)));
516 pending[i] &= ~(1 << level); 508 pending[i] &= ~(1 << level);
509 nhandled++;
517 } 510 }
518 } 511 }
519 512
520 return IRQ_HANDLED; 513 return (nhandled > 0) ? IRQ_HANDLED : IRQ_NONE;
521} 514}
522 515
523static int pca953x_gpio_irq_map(struct irq_domain *d, unsigned int irq,
524 irq_hw_number_t hwirq)
525{
526 irq_clear_status_flags(irq, IRQ_NOREQUEST);
527 irq_set_chip_data(irq, d->host_data);
528 irq_set_chip(irq, &pca953x_irq_chip);
529 irq_set_nested_thread(irq, true);
530#ifdef CONFIG_ARM
531 set_irq_flags(irq, IRQF_VALID);
532#else
533 irq_set_noprobe(irq);
534#endif
535
536 return 0;
537}
538
539static const struct irq_domain_ops pca953x_irq_simple_ops = {
540 .map = pca953x_gpio_irq_map,
541 .xlate = irq_domain_xlate_twocell,
542};
543
544static int pca953x_irq_setup(struct pca953x_chip *chip, 516static int pca953x_irq_setup(struct pca953x_chip *chip,
545 const struct i2c_device_id *id, 517 const struct i2c_device_id *id,
546 int irq_base) 518 int irq_base)
@@ -572,19 +544,12 @@ static int pca953x_irq_setup(struct pca953x_chip *chip,
572 chip->irq_stat[i] &= chip->reg_direction[i]; 544 chip->irq_stat[i] &= chip->reg_direction[i];
573 mutex_init(&chip->irq_lock); 545 mutex_init(&chip->irq_lock);
574 546
575 chip->domain = irq_domain_add_simple(client->dev.of_node,
576 chip->gpio_chip.ngpio,
577 irq_base,
578 &pca953x_irq_simple_ops,
579 chip);
580 if (!chip->domain)
581 return -ENODEV;
582
583 ret = devm_request_threaded_irq(&client->dev, 547 ret = devm_request_threaded_irq(&client->dev,
584 client->irq, 548 client->irq,
585 NULL, 549 NULL,
586 pca953x_irq_handler, 550 pca953x_irq_handler,
587 IRQF_TRIGGER_LOW | IRQF_ONESHOT, 551 IRQF_TRIGGER_LOW | IRQF_ONESHOT |
552 IRQF_SHARED,
588 dev_name(&client->dev), chip); 553 dev_name(&client->dev), chip);
589 if (ret) { 554 if (ret) {
590 dev_err(&client->dev, "failed to request irq %d\n", 555 dev_err(&client->dev, "failed to request irq %d\n",
@@ -592,7 +557,16 @@ static int pca953x_irq_setup(struct pca953x_chip *chip,
592 return ret; 557 return ret;
593 } 558 }
594 559
595 chip->gpio_chip.to_irq = pca953x_gpio_to_irq; 560 ret = gpiochip_irqchip_add(&chip->gpio_chip,
561 &pca953x_irq_chip,
562 irq_base,
563 handle_simple_irq,
564 IRQ_TYPE_NONE);
565 if (ret) {
566 dev_err(&client->dev,
567 "could not connect irqchip to gpiochip\n");
568 return ret;
569 }
596 } 570 }
597 571
598 return 0; 572 return 0;
@@ -756,11 +730,11 @@ static int pca953x_probe(struct i2c_client *client,
756 if (ret) 730 if (ret)
757 return ret; 731 return ret;
758 732
759 ret = pca953x_irq_setup(chip, id, irq_base); 733 ret = gpiochip_add(&chip->gpio_chip);
760 if (ret) 734 if (ret)
761 return ret; 735 return ret;
762 736
763 ret = gpiochip_add(&chip->gpio_chip); 737 ret = pca953x_irq_setup(chip, id, irq_base);
764 if (ret) 738 if (ret)
765 return ret; 739 return ret;
766 740
diff --git a/drivers/gpio/gpio-pcf857x.c b/drivers/gpio/gpio-pcf857x.c
index 82735822bc9d..27b46751ea7e 100644
--- a/drivers/gpio/gpio-pcf857x.c
+++ b/drivers/gpio/gpio-pcf857x.c
@@ -262,7 +262,7 @@ static int pcf857x_irq_domain_init(struct pcf857x *gpio,
262 /* enable real irq */ 262 /* enable real irq */
263 status = devm_request_threaded_irq(&client->dev, client->irq, 263 status = devm_request_threaded_irq(&client->dev, client->irq,
264 NULL, pcf857x_irq, IRQF_ONESHOT | 264 NULL, pcf857x_irq, IRQF_ONESHOT |
265 IRQF_TRIGGER_FALLING, 265 IRQF_TRIGGER_FALLING | IRQF_SHARED,
266 dev_name(&client->dev), gpio); 266 dev_name(&client->dev), gpio);
267 267
268 if (status) 268 if (status)
@@ -319,7 +319,7 @@ static int pcf857x_probe(struct i2c_client *client,
319 status = pcf857x_irq_domain_init(gpio, client); 319 status = pcf857x_irq_domain_init(gpio, client);
320 if (status < 0) { 320 if (status < 0) {
321 dev_err(&client->dev, "irq_domain init failed\n"); 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,12 +414,13 @@ static int pcf857x_probe(struct i2c_client *client,
414 return 0; 414 return 0;
415 415
416fail: 416fail:
417 dev_dbg(&client->dev, "probe error %d for '%s'\n",
418 status, client->name);
419
420 if (client->irq) 417 if (client->irq)
421 pcf857x_irq_domain_cleanup(gpio); 418 pcf857x_irq_domain_cleanup(gpio);
422 419
420fail_irq_domain:
421 dev_dbg(&client->dev, "probe error %d for '%s'\n",
422 status, client->name);
423
423 return status; 424 return status;
424} 425}
425 426
diff --git a/drivers/gpio/gpio-pch.c b/drivers/gpio/gpio-pch.c
index 83a156397474..d6eac9b17db9 100644
--- a/drivers/gpio/gpio-pch.c
+++ b/drivers/gpio/gpio-pch.c
@@ -20,6 +20,7 @@
20#include <linux/gpio.h> 20#include <linux/gpio.h>
21#include <linux/interrupt.h> 21#include <linux/interrupt.h>
22#include <linux/irq.h> 22#include <linux/irq.h>
23#include <linux/slab.h>
23 24
24#define PCH_EDGE_FALLING 0 25#define PCH_EDGE_FALLING 0
25#define PCH_EDGE_RISING BIT(0) 26#define PCH_EDGE_RISING BIT(0)
diff --git a/drivers/gpio/gpio-pl061.c b/drivers/gpio/gpio-pl061.c
index b0f475243cef..84b49cfb81a8 100644
--- a/drivers/gpio/gpio-pl061.c
+++ b/drivers/gpio/gpio-pl061.c
@@ -17,7 +17,6 @@
17#include <linux/irq.h> 17#include <linux/irq.h>
18#include <linux/irqchip/chained_irq.h> 18#include <linux/irqchip/chained_irq.h>
19#include <linux/bitops.h> 19#include <linux/bitops.h>
20#include <linux/workqueue.h>
21#include <linux/gpio.h> 20#include <linux/gpio.h>
22#include <linux/device.h> 21#include <linux/device.h>
23#include <linux/amba/bus.h> 22#include <linux/amba/bus.h>
@@ -88,7 +87,7 @@ static int pl061_direction_input(struct gpio_chip *gc, unsigned offset)
88 87
89 spin_lock_irqsave(&chip->lock, flags); 88 spin_lock_irqsave(&chip->lock, flags);
90 gpiodir = readb(chip->base + GPIODIR); 89 gpiodir = readb(chip->base + GPIODIR);
91 gpiodir &= ~(1 << offset); 90 gpiodir &= ~(BIT(offset));
92 writeb(gpiodir, chip->base + GPIODIR); 91 writeb(gpiodir, chip->base + GPIODIR);
93 spin_unlock_irqrestore(&chip->lock, flags); 92 spin_unlock_irqrestore(&chip->lock, flags);
94 93
@@ -106,16 +105,16 @@ static int pl061_direction_output(struct gpio_chip *gc, unsigned offset,
106 return -EINVAL; 105 return -EINVAL;
107 106
108 spin_lock_irqsave(&chip->lock, flags); 107 spin_lock_irqsave(&chip->lock, flags);
109 writeb(!!value << offset, chip->base + (1 << (offset + 2))); 108 writeb(!!value << offset, chip->base + (BIT(offset + 2)));
110 gpiodir = readb(chip->base + GPIODIR); 109 gpiodir = readb(chip->base + GPIODIR);
111 gpiodir |= 1 << offset; 110 gpiodir |= BIT(offset);
112 writeb(gpiodir, chip->base + GPIODIR); 111 writeb(gpiodir, chip->base + GPIODIR);
113 112
114 /* 113 /*
115 * gpio value is set again, because pl061 doesn't allow to set value of 114 * gpio value is set again, because pl061 doesn't allow to set value of
116 * a gpio pin before configuring it in OUT mode. 115 * a gpio pin before configuring it in OUT mode.
117 */ 116 */
118 writeb(!!value << offset, chip->base + (1 << (offset + 2))); 117 writeb(!!value << offset, chip->base + (BIT(offset + 2)));
119 spin_unlock_irqrestore(&chip->lock, flags); 118 spin_unlock_irqrestore(&chip->lock, flags);
120 119
121 return 0; 120 return 0;
@@ -125,14 +124,14 @@ static int pl061_get_value(struct gpio_chip *gc, unsigned offset)
125{ 124{
126 struct pl061_gpio *chip = container_of(gc, struct pl061_gpio, gc); 125 struct pl061_gpio *chip = container_of(gc, struct pl061_gpio, gc);
127 126
128 return !!readb(chip->base + (1 << (offset + 2))); 127 return !!readb(chip->base + (BIT(offset + 2)));
129} 128}
130 129
131static void pl061_set_value(struct gpio_chip *gc, unsigned offset, int value) 130static void pl061_set_value(struct gpio_chip *gc, unsigned offset, int value)
132{ 131{
133 struct pl061_gpio *chip = container_of(gc, struct pl061_gpio, gc); 132 struct pl061_gpio *chip = container_of(gc, struct pl061_gpio, gc);
134 133
135 writeb(!!value << offset, chip->base + (1 << (offset + 2))); 134 writeb(!!value << offset, chip->base + (BIT(offset + 2)));
136} 135}
137 136
138static int pl061_irq_type(struct irq_data *d, unsigned trigger) 137static int pl061_irq_type(struct irq_data *d, unsigned trigger)
@@ -207,7 +206,7 @@ static void pl061_irq_mask(struct irq_data *d)
207{ 206{
208 struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 207 struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
209 struct pl061_gpio *chip = container_of(gc, struct pl061_gpio, gc); 208 struct pl061_gpio *chip = container_of(gc, struct pl061_gpio, gc);
210 u8 mask = 1 << (irqd_to_hwirq(d) % PL061_GPIO_NR); 209 u8 mask = BIT(irqd_to_hwirq(d) % PL061_GPIO_NR);
211 u8 gpioie; 210 u8 gpioie;
212 211
213 spin_lock(&chip->lock); 212 spin_lock(&chip->lock);
@@ -220,7 +219,7 @@ static void pl061_irq_unmask(struct irq_data *d)
220{ 219{
221 struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 220 struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
222 struct pl061_gpio *chip = container_of(gc, struct pl061_gpio, gc); 221 struct pl061_gpio *chip = container_of(gc, struct pl061_gpio, gc);
223 u8 mask = 1 << (irqd_to_hwirq(d) % PL061_GPIO_NR); 222 u8 mask = BIT(irqd_to_hwirq(d) % PL061_GPIO_NR);
224 u8 gpioie; 223 u8 gpioie;
225 224
226 spin_lock(&chip->lock); 225 spin_lock(&chip->lock);
@@ -302,9 +301,9 @@ static int pl061_probe(struct amba_device *adev, const struct amba_id *id)
302 301
303 for (i = 0; i < PL061_GPIO_NR; i++) { 302 for (i = 0; i < PL061_GPIO_NR; i++) {
304 if (pdata) { 303 if (pdata) {
305 if (pdata->directions & (1 << i)) 304 if (pdata->directions & (BIT(i)))
306 pl061_direction_output(&chip->gc, i, 305 pl061_direction_output(&chip->gc, i,
307 pdata->values & (1 << i)); 306 pdata->values & (BIT(i)));
308 else 307 else
309 pl061_direction_input(&chip->gc, i); 308 pl061_direction_input(&chip->gc, i);
310 } 309 }
@@ -331,7 +330,7 @@ static int pl061_suspend(struct device *dev)
331 chip->csave_regs.gpio_ie = readb(chip->base + GPIOIE); 330 chip->csave_regs.gpio_ie = readb(chip->base + GPIOIE);
332 331
333 for (offset = 0; offset < PL061_GPIO_NR; offset++) { 332 for (offset = 0; offset < PL061_GPIO_NR; offset++) {
334 if (chip->csave_regs.gpio_dir & (1 << offset)) 333 if (chip->csave_regs.gpio_dir & (BIT(offset)))
335 chip->csave_regs.gpio_data |= 334 chip->csave_regs.gpio_data |=
336 pl061_get_value(&chip->gc, offset) << offset; 335 pl061_get_value(&chip->gc, offset) << offset;
337 } 336 }
@@ -345,10 +344,10 @@ static int pl061_resume(struct device *dev)
345 int offset; 344 int offset;
346 345
347 for (offset = 0; offset < PL061_GPIO_NR; offset++) { 346 for (offset = 0; offset < PL061_GPIO_NR; offset++) {
348 if (chip->csave_regs.gpio_dir & (1 << offset)) 347 if (chip->csave_regs.gpio_dir & (BIT(offset)))
349 pl061_direction_output(&chip->gc, offset, 348 pl061_direction_output(&chip->gc, offset,
350 chip->csave_regs.gpio_data & 349 chip->csave_regs.gpio_data &
351 (1 << offset)); 350 (BIT(offset)));
352 else 351 else
353 pl061_direction_input(&chip->gc, offset); 352 pl061_direction_input(&chip->gc, offset);
354 } 353 }
diff --git a/drivers/gpio/gpio-rc5t583.c b/drivers/gpio/gpio-rc5t583.c
index 9b423173ab50..562b0c4d9cc8 100644
--- a/drivers/gpio/gpio-rc5t583.c
+++ b/drivers/gpio/gpio-rc5t583.c
@@ -119,10 +119,8 @@ static int rc5t583_gpio_probe(struct platform_device *pdev)
119 119
120 rc5t583_gpio = devm_kzalloc(&pdev->dev, sizeof(*rc5t583_gpio), 120 rc5t583_gpio = devm_kzalloc(&pdev->dev, sizeof(*rc5t583_gpio),
121 GFP_KERNEL); 121 GFP_KERNEL);
122 if (!rc5t583_gpio) { 122 if (!rc5t583_gpio)
123 dev_warn(&pdev->dev, "Mem allocation for rc5t583_gpio failed");
124 return -ENOMEM; 123 return -ENOMEM;
125 }
126 124
127 rc5t583_gpio->gpio_chip.label = "gpio-rc5t583", 125 rc5t583_gpio->gpio_chip.label = "gpio-rc5t583",
128 rc5t583_gpio->gpio_chip.owner = THIS_MODULE, 126 rc5t583_gpio->gpio_chip.owner = THIS_MODULE,
diff --git a/drivers/gpio/gpio-rcar.c b/drivers/gpio/gpio-rcar.c
index 03c91482432c..0c9f803fc1ac 100644
--- a/drivers/gpio/gpio-rcar.c
+++ b/drivers/gpio/gpio-rcar.c
@@ -26,6 +26,7 @@
26#include <linux/pinctrl/consumer.h> 26#include <linux/pinctrl/consumer.h>
27#include <linux/platform_data/gpio-rcar.h> 27#include <linux/platform_data/gpio-rcar.h>
28#include <linux/platform_device.h> 28#include <linux/platform_device.h>
29#include <linux/pm_runtime.h>
29#include <linux/spinlock.h> 30#include <linux/spinlock.h>
30#include <linux/slab.h> 31#include <linux/slab.h>
31 32
@@ -362,7 +363,6 @@ static int gpio_rcar_probe(struct platform_device *pdev)
362 363
363 p = devm_kzalloc(dev, sizeof(*p), GFP_KERNEL); 364 p = devm_kzalloc(dev, sizeof(*p), GFP_KERNEL);
364 if (!p) { 365 if (!p) {
365 dev_err(dev, "failed to allocate driver data\n");
366 ret = -ENOMEM; 366 ret = -ENOMEM;
367 goto err0; 367 goto err0;
368 } 368 }
@@ -377,6 +377,9 @@ static int gpio_rcar_probe(struct platform_device *pdev)
377 377
378 platform_set_drvdata(pdev, p); 378 platform_set_drvdata(pdev, p);
379 379
380 pm_runtime_enable(dev);
381 pm_runtime_get_sync(dev);
382
380 io = platform_get_resource(pdev, IORESOURCE_MEM, 0); 383 io = platform_get_resource(pdev, IORESOURCE_MEM, 0);
381 irq = platform_get_resource(pdev, IORESOURCE_IRQ, 0); 384 irq = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
382 385
@@ -460,6 +463,8 @@ static int gpio_rcar_probe(struct platform_device *pdev)
460err1: 463err1:
461 irq_domain_remove(p->irq_domain); 464 irq_domain_remove(p->irq_domain);
462err0: 465err0:
466 pm_runtime_put(dev);
467 pm_runtime_disable(dev);
463 return ret; 468 return ret;
464} 469}
465 470
@@ -473,6 +478,8 @@ static int gpio_rcar_remove(struct platform_device *pdev)
473 return ret; 478 return ret;
474 479
475 irq_domain_remove(p->irq_domain); 480 irq_domain_remove(p->irq_domain);
481 pm_runtime_put(&pdev->dev);
482 pm_runtime_disable(&pdev->dev);
476 return 0; 483 return 0;
477} 484}
478 485
diff --git a/drivers/gpio/gpio-rdc321x.c b/drivers/gpio/gpio-rdc321x.c
index 88577c3272a5..9fa7e53331c9 100644
--- a/drivers/gpio/gpio-rdc321x.c
+++ b/drivers/gpio/gpio-rdc321x.c
@@ -141,17 +141,15 @@ static int rdc321x_gpio_probe(struct platform_device *pdev)
141 return -ENODEV; 141 return -ENODEV;
142 } 142 }
143 143
144 rdc321x_gpio_dev = kzalloc(sizeof(struct rdc321x_gpio), GFP_KERNEL); 144 rdc321x_gpio_dev = devm_kzalloc(&pdev->dev, sizeof(struct rdc321x_gpio),
145 if (!rdc321x_gpio_dev) { 145 GFP_KERNEL);
146 dev_err(&pdev->dev, "failed to allocate private data\n"); 146 if (!rdc321x_gpio_dev)
147 return -ENOMEM; 147 return -ENOMEM;
148 }
149 148
150 r = platform_get_resource_byname(pdev, IORESOURCE_IO, "gpio-reg1"); 149 r = platform_get_resource_byname(pdev, IORESOURCE_IO, "gpio-reg1");
151 if (!r) { 150 if (!r) {
152 dev_err(&pdev->dev, "failed to get gpio-reg1 resource\n"); 151 dev_err(&pdev->dev, "failed to get gpio-reg1 resource\n");
153 err = -ENODEV; 152 return -ENODEV;
154 goto out_free;
155 } 153 }
156 154
157 spin_lock_init(&rdc321x_gpio_dev->lock); 155 spin_lock_init(&rdc321x_gpio_dev->lock);
@@ -162,8 +160,7 @@ static int rdc321x_gpio_probe(struct platform_device *pdev)
162 r = platform_get_resource_byname(pdev, IORESOURCE_IO, "gpio-reg2"); 160 r = platform_get_resource_byname(pdev, IORESOURCE_IO, "gpio-reg2");
163 if (!r) { 161 if (!r) {
164 dev_err(&pdev->dev, "failed to get gpio-reg2 resource\n"); 162 dev_err(&pdev->dev, "failed to get gpio-reg2 resource\n");
165 err = -ENODEV; 163 return -ENODEV;
166 goto out_free;
167 } 164 }
168 165
169 rdc321x_gpio_dev->reg2_ctrl_base = r->start; 166 rdc321x_gpio_dev->reg2_ctrl_base = r->start;
@@ -187,21 +184,17 @@ static int rdc321x_gpio_probe(struct platform_device *pdev)
187 rdc321x_gpio_dev->reg1_data_base, 184 rdc321x_gpio_dev->reg1_data_base,
188 &rdc321x_gpio_dev->data_reg[0]); 185 &rdc321x_gpio_dev->data_reg[0]);
189 if (err) 186 if (err)
190 goto out_free; 187 return err;
191 188
192 err = pci_read_config_dword(rdc321x_gpio_dev->sb_pdev, 189 err = pci_read_config_dword(rdc321x_gpio_dev->sb_pdev,
193 rdc321x_gpio_dev->reg2_data_base, 190 rdc321x_gpio_dev->reg2_data_base,
194 &rdc321x_gpio_dev->data_reg[1]); 191 &rdc321x_gpio_dev->data_reg[1]);
195 if (err) 192 if (err)
196 goto out_free; 193 return err;
197 194
198 dev_info(&pdev->dev, "registering %d GPIOs\n", 195 dev_info(&pdev->dev, "registering %d GPIOs\n",
199 rdc321x_gpio_dev->chip.ngpio); 196 rdc321x_gpio_dev->chip.ngpio);
200 return gpiochip_add(&rdc321x_gpio_dev->chip); 197 return gpiochip_add(&rdc321x_gpio_dev->chip);
201
202out_free:
203 kfree(rdc321x_gpio_dev);
204 return err;
205} 198}
206 199
207static int rdc321x_gpio_remove(struct platform_device *pdev) 200static int rdc321x_gpio_remove(struct platform_device *pdev)
@@ -213,8 +206,6 @@ static int rdc321x_gpio_remove(struct platform_device *pdev)
213 if (ret) 206 if (ret)
214 dev_err(&pdev->dev, "failed to unregister chip\n"); 207 dev_err(&pdev->dev, "failed to unregister chip\n");
215 208
216 kfree(rdc321x_gpio_dev);
217
218 return ret; 209 return ret;
219} 210}
220 211
diff --git a/drivers/gpio/gpio-sch.c b/drivers/gpio/gpio-sch.c
index 5af65719b95d..a9b1cd16c848 100644
--- a/drivers/gpio/gpio-sch.c
+++ b/drivers/gpio/gpio-sch.c
@@ -97,8 +97,6 @@ static int sch_gpio_core_direction_out(struct gpio_chip *gc,
97 u8 curr_dirs; 97 u8 curr_dirs;
98 unsigned short offset, bit; 98 unsigned short offset, bit;
99 99
100 sch_gpio_core_set(gc, gpio_num, val);
101
102 spin_lock(&gpio_lock); 100 spin_lock(&gpio_lock);
103 101
104 offset = CGIO + gpio_num / 8; 102 offset = CGIO + gpio_num / 8;
@@ -109,6 +107,17 @@ static int sch_gpio_core_direction_out(struct gpio_chip *gc,
109 outb(curr_dirs & ~(1 << bit), gpio_ba + offset); 107 outb(curr_dirs & ~(1 << bit), gpio_ba + offset);
110 108
111 spin_unlock(&gpio_lock); 109 spin_unlock(&gpio_lock);
110
111 /*
112 * according to the datasheet, writing to the level register has no
113 * effect when GPIO is programmed as input.
114 * Actually the the level register is read-only when configured as input.
115 * Thus presetting the output level before switching to output is _NOT_ possible.
116 * Hence we set the level after configuring the GPIO as output.
117 * But we cannot prevent a short low pulse if direction is set to high
118 * and an external pull-up is connected.
119 */
120 sch_gpio_core_set(gc, gpio_num, val);
112 return 0; 121 return 0;
113} 122}
114 123
@@ -178,8 +187,6 @@ static int sch_gpio_resume_direction_out(struct gpio_chip *gc,
178 u8 curr_dirs; 187 u8 curr_dirs;
179 unsigned short offset, bit; 188 unsigned short offset, bit;
180 189
181 sch_gpio_resume_set(gc, gpio_num, val);
182
183 offset = RGIO + gpio_num / 8; 190 offset = RGIO + gpio_num / 8;
184 bit = gpio_num % 8; 191 bit = gpio_num % 8;
185 192
@@ -190,6 +197,17 @@ static int sch_gpio_resume_direction_out(struct gpio_chip *gc,
190 outb(curr_dirs & ~(1 << bit), gpio_ba + offset); 197 outb(curr_dirs & ~(1 << bit), gpio_ba + offset);
191 198
192 spin_unlock(&gpio_lock); 199 spin_unlock(&gpio_lock);
200
201 /*
202 * according to the datasheet, writing to the level register has no
203 * effect when GPIO is programmed as input.
204 * Actually the the level register is read-only when configured as input.
205 * Thus presetting the output level before switching to output is _NOT_ possible.
206 * Hence we set the level after configuring the GPIO as output.
207 * But we cannot prevent a short low pulse if direction is set to high
208 * and an external pull-up is connected.
209 */
210 sch_gpio_resume_set(gc, gpio_num, val);
193 return 0; 211 return 0;
194} 212}
195 213
diff --git a/drivers/gpio/gpio-sch311x.c b/drivers/gpio/gpio-sch311x.c
index 0357387b3645..f942b80ee403 100644
--- a/drivers/gpio/gpio-sch311x.c
+++ b/drivers/gpio/gpio-sch311x.c
@@ -327,14 +327,22 @@ static int __init sch311x_detect(int sio_config_port, unsigned short *addr)
327 if (err) 327 if (err)
328 return err; 328 return err;
329 329
330 /* Check device ID. We currently know about: 330 /* Check device ID. */
331 * SCH3112 (0x7c), SCH3114 (0x7d), and SCH3116 (0x7f). */
332 reg = sch311x_sio_inb(sio_config_port, 0x20); 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 err = -ENODEV; 343 err = -ENODEV;
335 goto exit; 344 goto exit;
336 } 345 }
337 dev_id = reg == 0x7c ? 2 : reg == 0x7d ? 4 : 6;
338 346
339 /* Select logical device A (runtime registers) */ 347 /* Select logical device A (runtime registers) */
340 sch311x_sio_outb(sio_config_port, 0x07, 0x0a); 348 sch311x_sio_outb(sio_config_port, 0x07, 0x0a);
diff --git a/drivers/gpio/gpio-spear-spics.c b/drivers/gpio/gpio-spear-spics.c
index 30bcc539425d..353263c85d26 100644
--- a/drivers/gpio/gpio-spear-spics.c
+++ b/drivers/gpio/gpio-spear-spics.c
@@ -129,10 +129,8 @@ static int spics_gpio_probe(struct platform_device *pdev)
129 int ret; 129 int ret;
130 130
131 spics = devm_kzalloc(&pdev->dev, sizeof(*spics), GFP_KERNEL); 131 spics = devm_kzalloc(&pdev->dev, sizeof(*spics), GFP_KERNEL);
132 if (!spics) { 132 if (!spics)
133 dev_err(&pdev->dev, "memory allocation fail\n");
134 return -ENOMEM; 133 return -ENOMEM;
135 }
136 134
137 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 135 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
138 spics->base = devm_ioremap_resource(&pdev->dev, res); 136 spics->base = devm_ioremap_resource(&pdev->dev, res);
diff --git a/drivers/gpio/gpio-sx150x.c b/drivers/gpio/gpio-sx150x.c
index 13d73fb2b5e1..b51ca9f5c140 100644
--- a/drivers/gpio/gpio-sx150x.c
+++ b/drivers/gpio/gpio-sx150x.c
@@ -22,7 +22,6 @@
22#include <linux/module.h> 22#include <linux/module.h>
23#include <linux/mutex.h> 23#include <linux/mutex.h>
24#include <linux/slab.h> 24#include <linux/slab.h>
25#include <linux/workqueue.h>
26#include <linux/i2c/sx150x.h> 25#include <linux/i2c/sx150x.h>
27 26
28#define NO_UPDATE_PENDING -1 27#define NO_UPDATE_PENDING -1
diff --git a/drivers/gpio/gpio-tc3589x.c b/drivers/gpio/gpio-tc3589x.c
index 1019320984d7..51f7cbd9ff71 100644
--- a/drivers/gpio/gpio-tc3589x.c
+++ b/drivers/gpio/gpio-tc3589x.c
@@ -12,8 +12,6 @@
12#include <linux/slab.h> 12#include <linux/slab.h>
13#include <linux/gpio.h> 13#include <linux/gpio.h>
14#include <linux/of.h> 14#include <linux/of.h>
15#include <linux/irq.h>
16#include <linux/irqdomain.h>
17#include <linux/interrupt.h> 15#include <linux/interrupt.h>
18#include <linux/mfd/tc3589x.h> 16#include <linux/mfd/tc3589x.h>
19 17
@@ -31,10 +29,6 @@ struct tc3589x_gpio {
31 struct tc3589x *tc3589x; 29 struct tc3589x *tc3589x;
32 struct device *dev; 30 struct device *dev;
33 struct mutex irq_lock; 31 struct mutex irq_lock;
34 struct irq_domain *domain;
35
36 int irq_base;
37
38 /* Caches of interrupt control registers for bus_lock */ 32 /* Caches of interrupt control registers for bus_lock */
39 u8 regs[CACHE_NR_REGS][CACHE_NR_BANKS]; 33 u8 regs[CACHE_NR_REGS][CACHE_NR_BANKS];
40 u8 oldregs[CACHE_NR_REGS][CACHE_NR_BANKS]; 34 u8 oldregs[CACHE_NR_REGS][CACHE_NR_BANKS];
@@ -95,30 +89,6 @@ static int tc3589x_gpio_direction_input(struct gpio_chip *chip,
95 return tc3589x_set_bits(tc3589x, reg, 1 << pos, 0); 89 return tc3589x_set_bits(tc3589x, reg, 1 << pos, 0);
96} 90}
97 91
98/**
99 * tc3589x_gpio_irq_get_irq(): Map a hardware IRQ on a chip to a Linux IRQ
100 *
101 * @tc3589x_gpio: tc3589x_gpio_irq controller to operate on.
102 * @irq: index of the hardware interrupt requested in the chip IRQs
103 *
104 * Useful for drivers to request their own IRQs.
105 */
106static int tc3589x_gpio_irq_get_irq(struct tc3589x_gpio *tc3589x_gpio,
107 int hwirq)
108{
109 if (!tc3589x_gpio)
110 return -EINVAL;
111
112 return irq_create_mapping(tc3589x_gpio->domain, hwirq);
113}
114
115static int tc3589x_gpio_to_irq(struct gpio_chip *chip, unsigned offset)
116{
117 struct tc3589x_gpio *tc3589x_gpio = to_tc3589x_gpio(chip);
118
119 return tc3589x_gpio_irq_get_irq(tc3589x_gpio, offset);
120}
121
122static struct gpio_chip template_chip = { 92static struct gpio_chip template_chip = {
123 .label = "tc3589x", 93 .label = "tc3589x",
124 .owner = THIS_MODULE, 94 .owner = THIS_MODULE,
@@ -126,13 +96,13 @@ static struct gpio_chip template_chip = {
126 .get = tc3589x_gpio_get, 96 .get = tc3589x_gpio_get,
127 .direction_output = tc3589x_gpio_direction_output, 97 .direction_output = tc3589x_gpio_direction_output,
128 .set = tc3589x_gpio_set, 98 .set = tc3589x_gpio_set,
129 .to_irq = tc3589x_gpio_to_irq,
130 .can_sleep = true, 99 .can_sleep = true,
131}; 100};
132 101
133static int tc3589x_gpio_irq_set_type(struct irq_data *d, unsigned int type) 102static int tc3589x_gpio_irq_set_type(struct irq_data *d, unsigned int type)
134{ 103{
135 struct tc3589x_gpio *tc3589x_gpio = irq_data_get_irq_chip_data(d); 104 struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
105 struct tc3589x_gpio *tc3589x_gpio = container_of(gc, struct tc3589x_gpio, chip);
136 int offset = d->hwirq; 106 int offset = d->hwirq;
137 int regoffset = offset / 8; 107 int regoffset = offset / 8;
138 int mask = 1 << (offset % 8); 108 int mask = 1 << (offset % 8);
@@ -159,14 +129,16 @@ static int tc3589x_gpio_irq_set_type(struct irq_data *d, unsigned int type)
159 129
160static void tc3589x_gpio_irq_lock(struct irq_data *d) 130static void tc3589x_gpio_irq_lock(struct irq_data *d)
161{ 131{
162 struct tc3589x_gpio *tc3589x_gpio = irq_data_get_irq_chip_data(d); 132 struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
133 struct tc3589x_gpio *tc3589x_gpio = container_of(gc, struct tc3589x_gpio, chip);
163 134
164 mutex_lock(&tc3589x_gpio->irq_lock); 135 mutex_lock(&tc3589x_gpio->irq_lock);
165} 136}
166 137
167static void tc3589x_gpio_irq_sync_unlock(struct irq_data *d) 138static void tc3589x_gpio_irq_sync_unlock(struct irq_data *d)
168{ 139{
169 struct tc3589x_gpio *tc3589x_gpio = irq_data_get_irq_chip_data(d); 140 struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
141 struct tc3589x_gpio *tc3589x_gpio = container_of(gc, struct tc3589x_gpio, chip);
170 struct tc3589x *tc3589x = tc3589x_gpio->tc3589x; 142 struct tc3589x *tc3589x = tc3589x_gpio->tc3589x;
171 static const u8 regmap[] = { 143 static const u8 regmap[] = {
172 [REG_IBE] = TC3589x_GPIOIBE0, 144 [REG_IBE] = TC3589x_GPIOIBE0,
@@ -194,7 +166,8 @@ static void tc3589x_gpio_irq_sync_unlock(struct irq_data *d)
194 166
195static void tc3589x_gpio_irq_mask(struct irq_data *d) 167static void tc3589x_gpio_irq_mask(struct irq_data *d)
196{ 168{
197 struct tc3589x_gpio *tc3589x_gpio = irq_data_get_irq_chip_data(d); 169 struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
170 struct tc3589x_gpio *tc3589x_gpio = container_of(gc, struct tc3589x_gpio, chip);
198 int offset = d->hwirq; 171 int offset = d->hwirq;
199 int regoffset = offset / 8; 172 int regoffset = offset / 8;
200 int mask = 1 << (offset % 8); 173 int mask = 1 << (offset % 8);
@@ -204,7 +177,8 @@ static void tc3589x_gpio_irq_mask(struct irq_data *d)
204 177
205static void tc3589x_gpio_irq_unmask(struct irq_data *d) 178static void tc3589x_gpio_irq_unmask(struct irq_data *d)
206{ 179{
207 struct tc3589x_gpio *tc3589x_gpio = irq_data_get_irq_chip_data(d); 180 struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
181 struct tc3589x_gpio *tc3589x_gpio = container_of(gc, struct tc3589x_gpio, chip);
208 int offset = d->hwirq; 182 int offset = d->hwirq;
209 int regoffset = offset / 8; 183 int regoffset = offset / 8;
210 int mask = 1 << (offset % 8); 184 int mask = 1 << (offset % 8);
@@ -242,7 +216,8 @@ static irqreturn_t tc3589x_gpio_irq(int irq, void *dev)
242 while (stat) { 216 while (stat) {
243 int bit = __ffs(stat); 217 int bit = __ffs(stat);
244 int line = i * 8 + bit; 218 int line = i * 8 + bit;
245 int irq = tc3589x_gpio_irq_get_irq(tc3589x_gpio, line); 219 int irq = irq_find_mapping(tc3589x_gpio->chip.irqdomain,
220 line);
246 221
247 handle_nested_irq(irq); 222 handle_nested_irq(irq);
248 stat &= ~(1 << bit); 223 stat &= ~(1 << bit);
@@ -254,61 +229,6 @@ static irqreturn_t tc3589x_gpio_irq(int irq, void *dev)
254 return IRQ_HANDLED; 229 return IRQ_HANDLED;
255} 230}
256 231
257static int tc3589x_gpio_irq_map(struct irq_domain *d, unsigned int irq,
258 irq_hw_number_t hwirq)
259{
260 struct tc3589x *tc3589x_gpio = d->host_data;
261
262 irq_set_chip_data(irq, tc3589x_gpio);
263 irq_set_chip_and_handler(irq, &tc3589x_gpio_irq_chip,
264 handle_simple_irq);
265 irq_set_nested_thread(irq, 1);
266#ifdef CONFIG_ARM
267 set_irq_flags(irq, IRQF_VALID);
268#else
269 irq_set_noprobe(irq);
270#endif
271
272 return 0;
273}
274
275static void tc3589x_gpio_irq_unmap(struct irq_domain *d, unsigned int irq)
276{
277#ifdef CONFIG_ARM
278 set_irq_flags(irq, 0);
279#endif
280 irq_set_chip_and_handler(irq, NULL, NULL);
281 irq_set_chip_data(irq, NULL);
282}
283
284static struct irq_domain_ops tc3589x_irq_ops = {
285 .map = tc3589x_gpio_irq_map,
286 .unmap = tc3589x_gpio_irq_unmap,
287 .xlate = irq_domain_xlate_twocell,
288};
289
290static int tc3589x_gpio_irq_init(struct tc3589x_gpio *tc3589x_gpio,
291 struct device_node *np)
292{
293 int base = tc3589x_gpio->irq_base;
294
295 /*
296 * If this results in a linear domain, irq_create_mapping() will
297 * take care of allocating IRQ descriptors at runtime. When a base
298 * is provided, the IRQ descriptors will be allocated when the
299 * domain is instantiated.
300 */
301 tc3589x_gpio->domain = irq_domain_add_simple(np,
302 tc3589x_gpio->chip.ngpio, base, &tc3589x_irq_ops,
303 tc3589x_gpio);
304 if (!tc3589x_gpio->domain) {
305 dev_err(tc3589x_gpio->dev, "Failed to create irqdomain\n");
306 return -ENOSYS;
307 }
308
309 return 0;
310}
311
312static int tc3589x_gpio_probe(struct platform_device *pdev) 232static int tc3589x_gpio_probe(struct platform_device *pdev)
313{ 233{
314 struct tc3589x *tc3589x = dev_get_drvdata(pdev->dev.parent); 234 struct tc3589x *tc3589x = dev_get_drvdata(pdev->dev.parent);
@@ -329,7 +249,8 @@ static int tc3589x_gpio_probe(struct platform_device *pdev)
329 if (irq < 0) 249 if (irq < 0)
330 return irq; 250 return irq;
331 251
332 tc3589x_gpio = kzalloc(sizeof(struct tc3589x_gpio), GFP_KERNEL); 252 tc3589x_gpio = devm_kzalloc(&pdev->dev, sizeof(struct tc3589x_gpio),
253 GFP_KERNEL);
333 if (!tc3589x_gpio) 254 if (!tc3589x_gpio)
334 return -ENOMEM; 255 return -ENOMEM;
335 256
@@ -347,30 +268,36 @@ static int tc3589x_gpio_probe(struct platform_device *pdev)
347 tc3589x_gpio->chip.of_node = np; 268 tc3589x_gpio->chip.of_node = np;
348#endif 269#endif
349 270
350 tc3589x_gpio->irq_base = tc3589x->irq_base ?
351 tc3589x->irq_base + TC3589x_INT_GPIO(0) : 0;
352
353 /* Bring the GPIO module out of reset */ 271 /* Bring the GPIO module out of reset */
354 ret = tc3589x_set_bits(tc3589x, TC3589x_RSTCTRL, 272 ret = tc3589x_set_bits(tc3589x, TC3589x_RSTCTRL,
355 TC3589x_RSTCTRL_GPIRST, 0); 273 TC3589x_RSTCTRL_GPIRST, 0);
356 if (ret < 0) 274 if (ret < 0)
357 goto out_free; 275 return ret;
358
359 ret = tc3589x_gpio_irq_init(tc3589x_gpio, np);
360 if (ret)
361 goto out_free;
362 276
363 ret = request_threaded_irq(irq, NULL, tc3589x_gpio_irq, IRQF_ONESHOT, 277 ret = devm_request_threaded_irq(&pdev->dev,
364 "tc3589x-gpio", tc3589x_gpio); 278 irq, NULL, tc3589x_gpio_irq,
279 IRQF_ONESHOT, "tc3589x-gpio",
280 tc3589x_gpio);
365 if (ret) { 281 if (ret) {
366 dev_err(&pdev->dev, "unable to get irq: %d\n", ret); 282 dev_err(&pdev->dev, "unable to get irq: %d\n", ret);
367 goto out_free; 283 return ret;
368 } 284 }
369 285
370 ret = gpiochip_add(&tc3589x_gpio->chip); 286 ret = gpiochip_add(&tc3589x_gpio->chip);
371 if (ret) { 287 if (ret) {
372 dev_err(&pdev->dev, "unable to add gpiochip: %d\n", ret); 288 dev_err(&pdev->dev, "unable to add gpiochip: %d\n", ret);
373 goto out_freeirq; 289 return ret;
290 }
291
292 ret = gpiochip_irqchip_add(&tc3589x_gpio->chip,
293 &tc3589x_gpio_irq_chip,
294 0,
295 handle_simple_irq,
296 IRQ_TYPE_NONE);
297 if (ret) {
298 dev_err(&pdev->dev,
299 "could not connect irqchip to gpiochip\n");
300 return ret;
374 } 301 }
375 302
376 if (pdata && pdata->setup) 303 if (pdata && pdata->setup)
@@ -379,12 +306,6 @@ static int tc3589x_gpio_probe(struct platform_device *pdev)
379 platform_set_drvdata(pdev, tc3589x_gpio); 306 platform_set_drvdata(pdev, tc3589x_gpio);
380 307
381 return 0; 308 return 0;
382
383out_freeirq:
384 free_irq(irq, tc3589x_gpio);
385out_free:
386 kfree(tc3589x_gpio);
387 return ret;
388} 309}
389 310
390static int tc3589x_gpio_remove(struct platform_device *pdev) 311static int tc3589x_gpio_remove(struct platform_device *pdev)
@@ -392,7 +313,6 @@ static int tc3589x_gpio_remove(struct platform_device *pdev)
392 struct tc3589x_gpio *tc3589x_gpio = platform_get_drvdata(pdev); 313 struct tc3589x_gpio *tc3589x_gpio = platform_get_drvdata(pdev);
393 struct tc3589x *tc3589x = tc3589x_gpio->tc3589x; 314 struct tc3589x *tc3589x = tc3589x_gpio->tc3589x;
394 struct tc3589x_gpio_platform_data *pdata = tc3589x->pdata->gpio; 315 struct tc3589x_gpio_platform_data *pdata = tc3589x->pdata->gpio;
395 int irq = platform_get_irq(pdev, 0);
396 int ret; 316 int ret;
397 317
398 if (pdata && pdata->remove) 318 if (pdata && pdata->remove)
@@ -405,10 +325,6 @@ static int tc3589x_gpio_remove(struct platform_device *pdev)
405 return ret; 325 return ret;
406 } 326 }
407 327
408 free_irq(irq, tc3589x_gpio);
409
410 kfree(tc3589x_gpio);
411
412 return 0; 328 return 0;
413} 329}
414 330
diff --git a/drivers/gpio/gpio-tegra.c b/drivers/gpio/gpio-tegra.c
index 2b49f878b56c..4e8fb8261a87 100644
--- a/drivers/gpio/gpio-tegra.c
+++ b/drivers/gpio/gpio-tegra.c
@@ -408,7 +408,7 @@ static struct tegra_gpio_soc_config tegra30_gpio_config = {
408 .upper_offset = 0x80, 408 .upper_offset = 0x80,
409}; 409};
410 410
411static struct of_device_id tegra_gpio_of_match[] = { 411static const struct of_device_id tegra_gpio_of_match[] = {
412 { .compatible = "nvidia,tegra30-gpio", .data = &tegra30_gpio_config }, 412 { .compatible = "nvidia,tegra30-gpio", .data = &tegra30_gpio_config },
413 { .compatible = "nvidia,tegra20-gpio", .data = &tegra20_gpio_config }, 413 { .compatible = "nvidia,tegra20-gpio", .data = &tegra20_gpio_config },
414 { }, 414 { },
@@ -458,10 +458,8 @@ static int tegra_gpio_probe(struct platform_device *pdev)
458 tegra_gpio_banks = devm_kzalloc(&pdev->dev, 458 tegra_gpio_banks = devm_kzalloc(&pdev->dev,
459 tegra_gpio_bank_count * sizeof(*tegra_gpio_banks), 459 tegra_gpio_bank_count * sizeof(*tegra_gpio_banks),
460 GFP_KERNEL); 460 GFP_KERNEL);
461 if (!tegra_gpio_banks) { 461 if (!tegra_gpio_banks)
462 dev_err(&pdev->dev, "Couldn't allocate bank structure\n");
463 return -ENODEV; 462 return -ENODEV;
464 }
465 463
466 irq_domain = irq_domain_add_linear(pdev->dev.of_node, 464 irq_domain = irq_domain_add_linear(pdev->dev.of_node,
467 tegra_gpio_chip.ngpio, 465 tegra_gpio_chip.ngpio,
diff --git a/drivers/gpio/gpio-timberdale.c b/drivers/gpio/gpio-timberdale.c
index f9a8fbde108e..efc7c129016d 100644
--- a/drivers/gpio/gpio-timberdale.c
+++ b/drivers/gpio/gpio-timberdale.c
@@ -224,6 +224,7 @@ static struct irq_chip timbgpio_irqchip = {
224static int timbgpio_probe(struct platform_device *pdev) 224static int timbgpio_probe(struct platform_device *pdev)
225{ 225{
226 int err, i; 226 int err, i;
227 struct device *dev = &pdev->dev;
227 struct gpio_chip *gc; 228 struct gpio_chip *gc;
228 struct timbgpio *tgpio; 229 struct timbgpio *tgpio;
229 struct resource *iomem; 230 struct resource *iomem;
@@ -231,35 +232,35 @@ static int timbgpio_probe(struct platform_device *pdev)
231 int irq = platform_get_irq(pdev, 0); 232 int irq = platform_get_irq(pdev, 0);
232 233
233 if (!pdata || pdata->nr_pins > 32) { 234 if (!pdata || pdata->nr_pins > 32) {
234 err = -EINVAL; 235 dev_err(dev, "Invalid platform data\n");
235 goto err_mem; 236 return -EINVAL;
236 } 237 }
237 238
238 iomem = platform_get_resource(pdev, IORESOURCE_MEM, 0); 239 iomem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
239 if (!iomem) { 240 if (!iomem) {
240 err = -EINVAL; 241 dev_err(dev, "Unable to get resource\n");
241 goto err_mem; 242 return -EINVAL;
242 } 243 }
243 244
244 tgpio = kzalloc(sizeof(*tgpio), GFP_KERNEL); 245 tgpio = devm_kzalloc(dev, sizeof(struct timbgpio), GFP_KERNEL);
245 if (!tgpio) { 246 if (!tgpio) {
246 err = -EINVAL; 247 dev_err(dev, "Memory alloc failed\n");
247 goto err_mem; 248 return -EINVAL;
248 } 249 }
249 tgpio->irq_base = pdata->irq_base; 250 tgpio->irq_base = pdata->irq_base;
250 251
251 spin_lock_init(&tgpio->lock); 252 spin_lock_init(&tgpio->lock);
252 253
253 if (!request_mem_region(iomem->start, resource_size(iomem), 254 if (!devm_request_mem_region(dev, iomem->start, resource_size(iomem),
254 DRIVER_NAME)) { 255 DRIVER_NAME)) {
255 err = -EBUSY; 256 dev_err(dev, "Region already claimed\n");
256 goto err_request; 257 return -EBUSY;
257 } 258 }
258 259
259 tgpio->membase = ioremap(iomem->start, resource_size(iomem)); 260 tgpio->membase = devm_ioremap(dev, iomem->start, resource_size(iomem));
260 if (!tgpio->membase) { 261 if (!tgpio->membase) {
261 err = -ENOMEM; 262 dev_err(dev, "Cannot ioremap\n");
262 goto err_ioremap; 263 return -ENOMEM;
263 } 264 }
264 265
265 gc = &tgpio->gpio; 266 gc = &tgpio->gpio;
@@ -279,7 +280,7 @@ static int timbgpio_probe(struct platform_device *pdev)
279 280
280 err = gpiochip_add(gc); 281 err = gpiochip_add(gc);
281 if (err) 282 if (err)
282 goto err_chipadd; 283 return err;
283 284
284 platform_set_drvdata(pdev, tgpio); 285 platform_set_drvdata(pdev, tgpio);
285 286
@@ -302,17 +303,6 @@ static int timbgpio_probe(struct platform_device *pdev)
302 irq_set_chained_handler(irq, timbgpio_irq); 303 irq_set_chained_handler(irq, timbgpio_irq);
303 304
304 return 0; 305 return 0;
305
306err_chipadd:
307 iounmap(tgpio->membase);
308err_ioremap:
309 release_mem_region(iomem->start, resource_size(iomem));
310err_request:
311 kfree(tgpio);
312err_mem:
313 printk(KERN_ERR DRIVER_NAME": Failed to register GPIOs: %d\n", err);
314
315 return err;
316} 306}
317 307
318static int timbgpio_remove(struct platform_device *pdev) 308static int timbgpio_remove(struct platform_device *pdev)
@@ -320,7 +310,6 @@ static int timbgpio_remove(struct platform_device *pdev)
320 int err; 310 int err;
321 struct timbgpio_platform_data *pdata = dev_get_platdata(&pdev->dev); 311 struct timbgpio_platform_data *pdata = dev_get_platdata(&pdev->dev);
322 struct timbgpio *tgpio = platform_get_drvdata(pdev); 312 struct timbgpio *tgpio = platform_get_drvdata(pdev);
323 struct resource *iomem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
324 int irq = platform_get_irq(pdev, 0); 313 int irq = platform_get_irq(pdev, 0);
325 314
326 if (irq >= 0 && tgpio->irq_base > 0) { 315 if (irq >= 0 && tgpio->irq_base > 0) {
@@ -338,10 +327,6 @@ static int timbgpio_remove(struct platform_device *pdev)
338 if (err) 327 if (err)
339 printk(KERN_ERR DRIVER_NAME": failed to remove gpio_chip\n"); 328 printk(KERN_ERR DRIVER_NAME": failed to remove gpio_chip\n");
340 329
341 iounmap(tgpio->membase);
342 release_mem_region(iomem->start, resource_size(iomem));
343 kfree(tgpio);
344
345 return 0; 330 return 0;
346} 331}
347 332
diff --git a/drivers/gpio/gpio-tps6586x.c b/drivers/gpio/gpio-tps6586x.c
index 8994dfa13491..a69fbea41253 100644
--- a/drivers/gpio/gpio-tps6586x.c
+++ b/drivers/gpio/gpio-tps6586x.c
@@ -97,10 +97,8 @@ static int tps6586x_gpio_probe(struct platform_device *pdev)
97 pdata = dev_get_platdata(pdev->dev.parent); 97 pdata = dev_get_platdata(pdev->dev.parent);
98 tps6586x_gpio = devm_kzalloc(&pdev->dev, 98 tps6586x_gpio = devm_kzalloc(&pdev->dev,
99 sizeof(*tps6586x_gpio), GFP_KERNEL); 99 sizeof(*tps6586x_gpio), GFP_KERNEL);
100 if (!tps6586x_gpio) { 100 if (!tps6586x_gpio)
101 dev_err(&pdev->dev, "Could not allocate tps6586x_gpio\n");
102 return -ENOMEM; 101 return -ENOMEM;
103 }
104 102
105 tps6586x_gpio->parent = pdev->dev.parent; 103 tps6586x_gpio->parent = pdev->dev.parent;
106 104
diff --git a/drivers/gpio/gpio-tps65910.c b/drivers/gpio/gpio-tps65910.c
index b6e818e68007..e2f8cda235ea 100644
--- a/drivers/gpio/gpio-tps65910.c
+++ b/drivers/gpio/gpio-tps65910.c
@@ -123,10 +123,8 @@ static int tps65910_gpio_probe(struct platform_device *pdev)
123 123
124 tps65910_gpio = devm_kzalloc(&pdev->dev, 124 tps65910_gpio = devm_kzalloc(&pdev->dev,
125 sizeof(*tps65910_gpio), GFP_KERNEL); 125 sizeof(*tps65910_gpio), GFP_KERNEL);
126 if (!tps65910_gpio) { 126 if (!tps65910_gpio)
127 dev_err(&pdev->dev, "Could not allocate tps65910_gpio\n");
128 return -ENOMEM; 127 return -ENOMEM;
129 }
130 128
131 tps65910_gpio->tps65910 = tps65910; 129 tps65910_gpio->tps65910 = tps65910;
132 130
diff --git a/drivers/gpio/gpio-xilinx.c b/drivers/gpio/gpio-xilinx.c
index 792a05ad4649..12481867daf1 100644
--- a/drivers/gpio/gpio-xilinx.c
+++ b/drivers/gpio/gpio-xilinx.c
@@ -289,7 +289,7 @@ static int xgpio_of_probe(struct device_node *np)
289 return 0; 289 return 0;
290} 290}
291 291
292static struct of_device_id xgpio_of_match[] = { 292static const struct of_device_id xgpio_of_match[] = {
293 { .compatible = "xlnx,xps-gpio-1.00.a", }, 293 { .compatible = "xlnx,xps-gpio-1.00.a", },
294 { /* end of list */ }, 294 { /* end of list */ },
295}; 295};
diff --git a/drivers/gpio/gpio-zevio.c b/drivers/gpio/gpio-zevio.c
index 9bf5034b6cdb..54e54e4cc6c4 100644
--- a/drivers/gpio/gpio-zevio.c
+++ b/drivers/gpio/gpio-zevio.c
@@ -81,9 +81,15 @@ static inline void zevio_gpio_port_set(struct zevio_gpio *c, unsigned pin,
81static int zevio_gpio_get(struct gpio_chip *chip, unsigned pin) 81static int zevio_gpio_get(struct gpio_chip *chip, unsigned pin)
82{ 82{
83 struct zevio_gpio *controller = to_zevio_gpio(chip); 83 struct zevio_gpio *controller = to_zevio_gpio(chip);
84 u32 val, dir;
84 85
85 /* Only reading allowed, so no spinlock needed */ 86 spin_lock(&controller->lock);
86 u32 val = zevio_gpio_port_get(controller, pin, ZEVIO_GPIO_INPUT); 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 return (val >> ZEVIO_GPIO_BIT(pin)) & 0x1; 94 return (val >> ZEVIO_GPIO_BIT(pin)) & 0x1;
89} 95}
@@ -172,10 +178,8 @@ static int zevio_gpio_probe(struct platform_device *pdev)
172 int status, i; 178 int status, i;
173 179
174 controller = devm_kzalloc(&pdev->dev, sizeof(*controller), GFP_KERNEL); 180 controller = devm_kzalloc(&pdev->dev, sizeof(*controller), GFP_KERNEL);
175 if (!controller) { 181 if (!controller)
176 dev_err(&pdev->dev, "not enough free memory\n");
177 return -ENOMEM; 182 return -ENOMEM;
178 }
179 183
180 /* Copy our reference */ 184 /* Copy our reference */
181 controller->chip.gc = zevio_gpio_chip; 185 controller->chip.gc = zevio_gpio_chip;
@@ -198,7 +202,7 @@ static int zevio_gpio_probe(struct platform_device *pdev)
198 return 0; 202 return 0;
199} 203}
200 204
201static struct of_device_id zevio_gpio_of_match[] = { 205static const struct of_device_id zevio_gpio_of_match[] = {
202 { .compatible = "lsi,zevio-gpio", }, 206 { .compatible = "lsi,zevio-gpio", },
203 { }, 207 { },
204}; 208};
@@ -209,7 +213,7 @@ static struct platform_driver zevio_gpio_driver = {
209 .driver = { 213 .driver = {
210 .name = "gpio-zevio", 214 .name = "gpio-zevio",
211 .owner = THIS_MODULE, 215 .owner = THIS_MODULE,
212 .of_match_table = of_match_ptr(zevio_gpio_of_match), 216 .of_match_table = zevio_gpio_of_match,
213 }, 217 },
214 .probe = zevio_gpio_probe, 218 .probe = zevio_gpio_probe,
215}; 219};
diff --git a/drivers/gpio/gpiolib-acpi.c b/drivers/gpio/gpiolib-acpi.c
index 401add28933f..4a987917c186 100644
--- a/drivers/gpio/gpiolib-acpi.c
+++ b/drivers/gpio/gpiolib-acpi.c
@@ -449,9 +449,10 @@ acpi_gpio_adr_space_handler(u32 function, acpi_physical_address address,
449 mutex_unlock(&achip->conn_lock); 449 mutex_unlock(&achip->conn_lock);
450 450
451 if (function == ACPI_WRITE) 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 else 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
457out: 458out:
diff --git a/drivers/gpio/gpiolib-of.c b/drivers/gpio/gpiolib-of.c
index 2024d45e5503..af7e25c9a9ae 100644
--- a/drivers/gpio/gpiolib-of.c
+++ b/drivers/gpio/gpiolib-of.c
@@ -48,7 +48,7 @@ static int of_gpiochip_find_and_xlate(struct gpio_chip *gc, void *data)
48 if (ret < 0) 48 if (ret < 0)
49 return false; 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 return true; 52 return true;
53} 53}
54 54
@@ -96,6 +96,20 @@ struct gpio_desc *of_get_named_gpiod_flags(struct device_node *np,
96} 96}
97EXPORT_SYMBOL(of_get_named_gpiod_flags); 97EXPORT_SYMBOL(of_get_named_gpiod_flags);
98 98
99int 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}
111EXPORT_SYMBOL(of_get_named_gpio_flags);
112
99/** 113/**
100 * of_gpio_simple_xlate - translate gpio_spec to the GPIO number and flags 114 * of_gpio_simple_xlate - translate gpio_spec to the GPIO number and flags
101 * @gc: pointer to the gpio_chip structure 115 * @gc: pointer to the gpio_chip structure
diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index f48817d97480..d9c9cb4665db 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -1363,6 +1363,11 @@ void gpiochip_set_chained_irqchip(struct gpio_chip *gpiochip,
1363 int parent_irq, 1363 int parent_irq,
1364 irq_flow_handler_t parent_handler) 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 irq_set_chained_handler(parent_irq, parent_handler); 1371 irq_set_chained_handler(parent_irq, parent_handler);
1367 /* 1372 /*
1368 * The parent irqchip is already using the chip_data for this 1373 * The parent irqchip is already using the chip_data for this
@@ -1372,6 +1377,12 @@ void gpiochip_set_chained_irqchip(struct gpio_chip *gpiochip,
1372} 1377}
1373EXPORT_SYMBOL_GPL(gpiochip_set_chained_irqchip); 1378EXPORT_SYMBOL_GPL(gpiochip_set_chained_irqchip);
1374 1379
1380/*
1381 * This lock class tells lockdep that GPIO irqs are in a different
1382 * category than their parents, so it won't report false recursion.
1383 */
1384static struct lock_class_key gpiochip_irq_lock_class;
1385
1375/** 1386/**
1376 * gpiochip_irq_map() - maps an IRQ into a GPIO irqchip 1387 * gpiochip_irq_map() - maps an IRQ into a GPIO irqchip
1377 * @d: the irqdomain used by this irqchip 1388 * @d: the irqdomain used by this irqchip
@@ -1388,22 +1399,35 @@ static int gpiochip_irq_map(struct irq_domain *d, unsigned int irq,
1388 struct gpio_chip *chip = d->host_data; 1399 struct gpio_chip *chip = d->host_data;
1389 1400
1390 irq_set_chip_data(irq, chip); 1401 irq_set_chip_data(irq, chip);
1402 irq_set_lockdep_class(irq, &gpiochip_irq_lock_class);
1391 irq_set_chip_and_handler(irq, chip->irqchip, chip->irq_handler); 1403 irq_set_chip_and_handler(irq, chip->irqchip, chip->irq_handler);
1404 /* Chips that can sleep need nested thread handlers */
1405 if (chip->can_sleep)
1406 irq_set_nested_thread(irq, 1);
1392#ifdef CONFIG_ARM 1407#ifdef CONFIG_ARM
1393 set_irq_flags(irq, IRQF_VALID); 1408 set_irq_flags(irq, IRQF_VALID);
1394#else 1409#else
1395 irq_set_noprobe(irq); 1410 irq_set_noprobe(irq);
1396#endif 1411#endif
1397 irq_set_irq_type(irq, chip->irq_default_type); 1412 /*
1413 * No set-up of the hardware will happen if IRQ_TYPE_NONE
1414 * is passed as default type.
1415 */
1416 if (chip->irq_default_type != IRQ_TYPE_NONE)
1417 irq_set_irq_type(irq, chip->irq_default_type);
1398 1418
1399 return 0; 1419 return 0;
1400} 1420}
1401 1421
1402static void gpiochip_irq_unmap(struct irq_domain *d, unsigned int irq) 1422static void gpiochip_irq_unmap(struct irq_domain *d, unsigned int irq)
1403{ 1423{
1424 struct gpio_chip *chip = d->host_data;
1425
1404#ifdef CONFIG_ARM 1426#ifdef CONFIG_ARM
1405 set_irq_flags(irq, 0); 1427 set_irq_flags(irq, 0);
1406#endif 1428#endif
1429 if (chip->can_sleep)
1430 irq_set_nested_thread(irq, 0);
1407 irq_set_chip_and_handler(irq, NULL, NULL); 1431 irq_set_chip_and_handler(irq, NULL, NULL);
1408 irq_set_chip_data(irq, NULL); 1432 irq_set_chip_data(irq, NULL);
1409} 1433}
@@ -1471,7 +1495,8 @@ static void gpiochip_irqchip_remove(struct gpio_chip *gpiochip)
1471 * @first_irq: if not dynamically assigned, the base (first) IRQ to 1495 * @first_irq: if not dynamically assigned, the base (first) IRQ to
1472 * allocate gpiochip irqs from 1496 * allocate gpiochip irqs from
1473 * @handler: the irq handler to use (often a predefined irq core function) 1497 * @handler: the irq handler to use (often a predefined irq core function)
1474 * @type: the default type for IRQs on this irqchip 1498 * @type: the default type for IRQs on this irqchip, pass IRQ_TYPE_NONE
1499 * to have the core avoid setting up any default type in the hardware.
1475 * 1500 *
1476 * This function closely associates a certain irqchip with a certain 1501 * This function closely associates a certain irqchip with a certain
1477 * gpiochip, providing an irq domain to translate the local IRQs to 1502 * gpiochip, providing an irq domain to translate the local IRQs to
@@ -2571,22 +2596,27 @@ void gpiod_add_lookup_table(struct gpiod_lookup_table *table)
2571 mutex_unlock(&gpio_lookup_lock); 2596 mutex_unlock(&gpio_lookup_lock);
2572} 2597}
2573 2598
2574#ifdef CONFIG_OF
2575static struct gpio_desc *of_find_gpio(struct device *dev, const char *con_id, 2599static struct gpio_desc *of_find_gpio(struct device *dev, const char *con_id,
2576 unsigned int idx, 2600 unsigned int idx,
2577 enum gpio_lookup_flags *flags) 2601 enum gpio_lookup_flags *flags)
2578{ 2602{
2603 static const char *suffixes[] = { "gpios", "gpio" };
2579 char prop_name[32]; /* 32 is max size of property name */ 2604 char prop_name[32]; /* 32 is max size of property name */
2580 enum of_gpio_flags of_flags; 2605 enum of_gpio_flags of_flags;
2581 struct gpio_desc *desc; 2606 struct gpio_desc *desc;
2607 unsigned int i;
2582 2608
2583 if (con_id) 2609 for (i = 0; i < ARRAY_SIZE(suffixes); i++) {
2584 snprintf(prop_name, 32, "%s-gpios", con_id); 2610 if (con_id)
2585 else 2611 snprintf(prop_name, 32, "%s-%s", con_id, suffixes[i]);
2586 snprintf(prop_name, 32, "gpios"); 2612 else
2613 snprintf(prop_name, 32, "%s", suffixes[i]);
2587 2614
2588 desc = of_get_named_gpiod_flags(dev->of_node, prop_name, idx, 2615 desc = of_get_named_gpiod_flags(dev->of_node, prop_name, idx,
2589 &of_flags); 2616 &of_flags);
2617 if (!IS_ERR(desc))
2618 break;
2619 }
2590 2620
2591 if (IS_ERR(desc)) 2621 if (IS_ERR(desc))
2592 return desc; 2622 return desc;
@@ -2596,14 +2626,6 @@ static struct gpio_desc *of_find_gpio(struct device *dev, const char *con_id,
2596 2626
2597 return desc; 2627 return desc;
2598} 2628}
2599#else
2600static struct gpio_desc *of_find_gpio(struct device *dev, const char *con_id,
2601 unsigned int idx,
2602 enum gpio_lookup_flags *flags)
2603{
2604 return ERR_PTR(-ENODEV);
2605}
2606#endif
2607 2629
2608static struct gpio_desc *acpi_find_gpio(struct device *dev, const char *con_id, 2630static struct gpio_desc *acpi_find_gpio(struct device *dev, const char *con_id,
2609 unsigned int idx, 2631 unsigned int idx,
@@ -2701,7 +2723,7 @@ static struct gpio_desc *gpiod_find(struct device *dev, const char *con_id,
2701} 2723}
2702 2724
2703/** 2725/**
2704 * gpio_get - obtain a GPIO for a given GPIO function 2726 * gpiod_get - obtain a GPIO for a given GPIO function
2705 * @dev: GPIO consumer, can be NULL for system-global GPIOs 2727 * @dev: GPIO consumer, can be NULL for system-global GPIOs
2706 * @con_id: function within the GPIO consumer 2728 * @con_id: function within the GPIO consumer
2707 * 2729 *
@@ -2716,6 +2738,22 @@ struct gpio_desc *__must_check gpiod_get(struct device *dev, const char *con_id)
2716EXPORT_SYMBOL_GPL(gpiod_get); 2738EXPORT_SYMBOL_GPL(gpiod_get);
2717 2739
2718/** 2740/**
2741 * gpiod_get_optional - obtain an optional GPIO for a given GPIO function
2742 * @dev: GPIO consumer, can be NULL for system-global GPIOs
2743 * @con_id: function within the GPIO consumer
2744 *
2745 * This is equivalent to gpiod_get(), except that when no GPIO was assigned to
2746 * the requested function it will return NULL. This is convenient for drivers
2747 * that need to handle optional GPIOs.
2748 */
2749struct gpio_desc *__must_check gpiod_get_optional(struct device *dev,
2750 const char *con_id)
2751{
2752 return gpiod_get_index_optional(dev, con_id, 0);
2753}
2754EXPORT_SYMBOL_GPL(gpiod_get_optional);
2755
2756/**
2719 * gpiod_get_index - obtain a GPIO from a multi-index GPIO function 2757 * gpiod_get_index - obtain a GPIO from a multi-index GPIO function
2720 * @dev: GPIO consumer, can be NULL for system-global GPIOs 2758 * @dev: GPIO consumer, can be NULL for system-global GPIOs
2721 * @con_id: function within the GPIO consumer 2759 * @con_id: function within the GPIO consumer
@@ -2778,6 +2816,33 @@ struct gpio_desc *__must_check gpiod_get_index(struct device *dev,
2778EXPORT_SYMBOL_GPL(gpiod_get_index); 2816EXPORT_SYMBOL_GPL(gpiod_get_index);
2779 2817
2780/** 2818/**
2819 * gpiod_get_index_optional - obtain an optional GPIO from a multi-index GPIO
2820 * function
2821 * @dev: GPIO consumer, can be NULL for system-global GPIOs
2822 * @con_id: function within the GPIO consumer
2823 * @index: index of the GPIO to obtain in the consumer
2824 *
2825 * This is equivalent to gpiod_get_index(), except that when no GPIO with the
2826 * specified index was assigned to the requested function it will return NULL.
2827 * This is convenient for drivers that need to handle optional GPIOs.
2828 */
2829struct gpio_desc *__must_check gpiod_get_index_optional(struct device *dev,
2830 const char *con_id,
2831 unsigned int index)
2832{
2833 struct gpio_desc *desc;
2834
2835 desc = gpiod_get_index(dev, con_id, index);
2836 if (IS_ERR(desc)) {
2837 if (PTR_ERR(desc) == -ENOENT)
2838 return NULL;
2839 }
2840
2841 return desc;
2842}
2843EXPORT_SYMBOL_GPL(gpiod_get_index_optional);
2844
2845/**
2781 * gpiod_put - dispose of a GPIO descriptor 2846 * gpiod_put - dispose of a GPIO descriptor
2782 * @desc: GPIO descriptor to dispose of 2847 * @desc: GPIO descriptor to dispose of
2783 * 2848 *
diff --git a/drivers/gpio/gpiolib.h b/drivers/gpio/gpiolib.h
index cf092941a9fd..1a4103dd38df 100644
--- a/drivers/gpio/gpiolib.h
+++ b/drivers/gpio/gpiolib.h
@@ -15,6 +15,8 @@
15#include <linux/err.h> 15#include <linux/err.h>
16#include <linux/device.h> 16#include <linux/device.h>
17 17
18enum of_gpio_flags;
19
18/** 20/**
19 * struct acpi_gpio_info - ACPI GPIO specific information 21 * struct acpi_gpio_info - ACPI GPIO specific information
20 * @gpioint: if %true this GPIO is of type GpioInt otherwise type is GpioIo 22 * @gpioint: if %true this GPIO is of type GpioInt otherwise type is GpioIo
@@ -46,4 +48,7 @@ acpi_get_gpiod_by_index(struct device *dev, int index,
46int gpiochip_request_own_desc(struct gpio_desc *desc, const char *label); 48int gpiochip_request_own_desc(struct gpio_desc *desc, const char *label);
47void gpiochip_free_own_desc(struct gpio_desc *desc); 49void gpiochip_free_own_desc(struct gpio_desc *desc);
48 50
51struct gpio_desc *of_get_named_gpiod_flags(struct device_node *np,
52 const char *list_name, int index, enum of_gpio_flags *flags);
53
49#endif /* GPIOLIB_H */ 54#endif /* GPIOLIB_H */