aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/gpio
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2013-05-06 18:40:55 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2013-05-06 18:40:55 -0400
commit30c67e93c526639aaac90fa873800104b7c16d16 (patch)
tree6d8d0fd248d4e60bdc175dacbd196fc44f23ce11 /drivers/gpio
parentf87bb9ee62700fa11713c630ac5671f253233b94 (diff)
parent08ffb2229fafc2c3a696b325a74bf4198d6b91d7 (diff)
Merge tag 'gpio-for-linus' of git://git.secretlab.ca/git/linux
Pull GPIO changes from Grant Likely: "The usual selection of bug fixes and driver updates for GPIO. Nothing really stands out except the addition of the GRGPIO driver and some enhacements to ACPI support" I'm pulling this despite the earlier mess. Let's hope it compiles these days. * tag 'gpio-for-linus' of git://git.secretlab.ca/git/linux: (46 commits) gpio: grgpio: Add irq support gpio: grgpio: Add device driver for GRGPIO cores gpiolib-acpi: introduce acpi_get_gpio_by_index() helper GPIO: gpio-generic: remove kfree() from bgpio_remove call gpio / ACPI: Handle ACPI events in accordance with the spec gpio: lpc32xx: Fix off-by-one valid range checking for bank gpio: mcp23s08: convert driver to DT gpio/omap: force restore if context loss is not detectable gpio/omap: optimise interrupt service routine gpio/omap: remove extra context restores in *_runtime_resume() gpio/omap: free irq domain in probe() failure paths gpio: gpio-generic: Add 16 and 32 bit big endian byte order support gpio: samsung: Add terminating entry for exynos_pinctrl_ids gpio: mvebu: add dbg_show function MAX7301 GPIO: Do not force SPI speed when using OF Platform gpio: gpio-tps65910.c: fix checkpatch error gpio: gpio-timberdale.c: fix checkpatch error gpio: gpio-tc3589x.c: fix checkpatch errors gpio: gpio-stp-xway.c: fix checkpatch error gpio: gpio-sch.c: fix checkpatch error ...
Diffstat (limited to 'drivers/gpio')
-rw-r--r--drivers/gpio/Kconfig11
-rw-r--r--drivers/gpio/Makefile1
-rw-r--r--drivers/gpio/gpio-74x164.c8
-rw-r--r--drivers/gpio/gpio-adp5520.c4
-rw-r--r--drivers/gpio/gpio-em.c94
-rw-r--r--drivers/gpio/gpio-generic.c62
-rw-r--r--drivers/gpio/gpio-grgpio.c505
-rw-r--r--drivers/gpio/gpio-ich.c17
-rw-r--r--drivers/gpio/gpio-lpc32xx.c2
-rw-r--r--drivers/gpio/gpio-lynxpoint.c1
-rw-r--r--drivers/gpio/gpio-max7300.c4
-rw-r--r--drivers/gpio/gpio-max7301.c7
-rw-r--r--drivers/gpio/gpio-max732x.c5
-rw-r--r--drivers/gpio/gpio-mc33880.c19
-rw-r--r--drivers/gpio/gpio-mcp23s08.c137
-rw-r--r--drivers/gpio/gpio-mvebu.c85
-rw-r--r--drivers/gpio/gpio-omap.c116
-rw-r--r--drivers/gpio/gpio-pca953x.c3
-rw-r--r--drivers/gpio/gpio-pcf857x.c8
-rw-r--r--drivers/gpio/gpio-pxa.c4
-rw-r--r--drivers/gpio/gpio-samsung.c1
-rw-r--r--drivers/gpio/gpio-sch.c111
-rw-r--r--drivers/gpio/gpio-stp-xway.c2
-rw-r--r--drivers/gpio/gpio-tc3589x.c8
-rw-r--r--drivers/gpio/gpio-tegra.c11
-rw-r--r--drivers/gpio/gpio-timberdale.c3
-rw-r--r--drivers/gpio/gpio-tps65910.c2
-rw-r--r--drivers/gpio/gpio-viperboard.c4
-rw-r--r--drivers/gpio/gpiolib-acpi.c217
-rw-r--r--drivers/gpio/gpiolib-of.c2
30 files changed, 1164 insertions, 290 deletions
diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig
index b166e30b3bc4..ff7f0c87745a 100644
--- a/drivers/gpio/Kconfig
+++ b/drivers/gpio/Kconfig
@@ -297,12 +297,21 @@ config GPIO_GE_FPGA
297 297
298config GPIO_LYNXPOINT 298config GPIO_LYNXPOINT
299 bool "Intel Lynxpoint GPIO support" 299 bool "Intel Lynxpoint GPIO support"
300 depends on ACPI 300 depends on ACPI && X86
301 select IRQ_DOMAIN 301 select IRQ_DOMAIN
302 help 302 help
303 driver for GPIO functionality on Intel Lynxpoint PCH chipset 303 driver for GPIO functionality on Intel Lynxpoint PCH chipset
304 Requires ACPI device enumeration code to set up a platform device. 304 Requires ACPI device enumeration code to set up a platform device.
305 305
306config GPIO_GRGPIO
307 tristate "Aeroflex Gaisler GRGPIO support"
308 depends on OF
309 select GPIO_GENERIC
310 select IRQ_DOMAIN
311 help
312 Select this to support Aeroflex Gaisler GRGPIO cores from the GRLIB
313 VHDL IP core library.
314
306comment "I2C GPIO expanders:" 315comment "I2C GPIO expanders:"
307 316
308config GPIO_ARIZONA 317config GPIO_ARIZONA
diff --git a/drivers/gpio/Makefile b/drivers/gpio/Makefile
index a274d7df3c8c..6aab73d577d1 100644
--- a/drivers/gpio/Makefile
+++ b/drivers/gpio/Makefile
@@ -25,6 +25,7 @@ obj-$(CONFIG_ARCH_DAVINCI) += gpio-davinci.o
25obj-$(CONFIG_GPIO_EM) += gpio-em.o 25obj-$(CONFIG_GPIO_EM) += gpio-em.o
26obj-$(CONFIG_GPIO_EP93XX) += gpio-ep93xx.o 26obj-$(CONFIG_GPIO_EP93XX) += gpio-ep93xx.o
27obj-$(CONFIG_GPIO_GE_FPGA) += gpio-ge.o 27obj-$(CONFIG_GPIO_GE_FPGA) += gpio-ge.o
28obj-$(CONFIG_GPIO_GRGPIO) += gpio-grgpio.o
28obj-$(CONFIG_GPIO_ICH) += gpio-ich.o 29obj-$(CONFIG_GPIO_ICH) += gpio-ich.o
29obj-$(CONFIG_GPIO_IT8761E) += gpio-it8761e.o 30obj-$(CONFIG_GPIO_IT8761E) += gpio-it8761e.o
30obj-$(CONFIG_GPIO_JANZ_TTL) += gpio-janz-ttl.o 31obj-$(CONFIG_GPIO_JANZ_TTL) += gpio-janz-ttl.o
diff --git a/drivers/gpio/gpio-74x164.c b/drivers/gpio/gpio-74x164.c
index 464be961f605..721607904d0a 100644
--- a/drivers/gpio/gpio-74x164.c
+++ b/drivers/gpio/gpio-74x164.c
@@ -137,7 +137,7 @@ static int gen_74x164_probe(struct spi_device *spi)
137 137
138 mutex_init(&chip->lock); 138 mutex_init(&chip->lock);
139 139
140 dev_set_drvdata(&spi->dev, chip); 140 spi_set_drvdata(spi, chip);
141 141
142 chip->spi = spi; 142 chip->spi = spi;
143 143
@@ -176,7 +176,7 @@ static int gen_74x164_probe(struct spi_device *spi)
176 return ret; 176 return ret;
177 177
178exit_destroy: 178exit_destroy:
179 dev_set_drvdata(&spi->dev, NULL); 179 spi_set_drvdata(spi, NULL);
180 mutex_destroy(&chip->lock); 180 mutex_destroy(&chip->lock);
181 return ret; 181 return ret;
182} 182}
@@ -186,11 +186,11 @@ static int gen_74x164_remove(struct spi_device *spi)
186 struct gen_74x164_chip *chip; 186 struct gen_74x164_chip *chip;
187 int ret; 187 int ret;
188 188
189 chip = dev_get_drvdata(&spi->dev); 189 chip = spi_get_drvdata(spi);
190 if (chip == NULL) 190 if (chip == NULL)
191 return -ENODEV; 191 return -ENODEV;
192 192
193 dev_set_drvdata(&spi->dev, NULL); 193 spi_set_drvdata(spi, NULL);
194 194
195 ret = gpiochip_remove(&chip->gpio_chip); 195 ret = gpiochip_remove(&chip->gpio_chip);
196 if (!ret) 196 if (!ret)
diff --git a/drivers/gpio/gpio-adp5520.c b/drivers/gpio/gpio-adp5520.c
index 8afa95f831b1..f33f78dcadaa 100644
--- a/drivers/gpio/gpio-adp5520.c
+++ b/drivers/gpio/gpio-adp5520.c
@@ -105,7 +105,7 @@ static int adp5520_gpio_probe(struct platform_device *pdev)
105 return -ENODEV; 105 return -ENODEV;
106 } 106 }
107 107
108 dev = kzalloc(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"); 110 dev_err(&pdev->dev, "failed to alloc memory\n");
111 return -ENOMEM; 111 return -ENOMEM;
@@ -163,7 +163,6 @@ static int adp5520_gpio_probe(struct platform_device *pdev)
163 return 0; 163 return 0;
164 164
165err: 165err:
166 kfree(dev);
167 return ret; 166 return ret;
168} 167}
169 168
@@ -180,7 +179,6 @@ static int adp5520_gpio_remove(struct platform_device *pdev)
180 return ret; 179 return ret;
181 } 180 }
182 181
183 kfree(dev);
184 return 0; 182 return 0;
185} 183}
186 184
diff --git a/drivers/gpio/gpio-em.c b/drivers/gpio/gpio-em.c
index deca78f99316..5cba855638bf 100644
--- a/drivers/gpio/gpio-em.c
+++ b/drivers/gpio/gpio-em.c
@@ -231,10 +231,12 @@ static int em_gio_irq_domain_map(struct irq_domain *h, unsigned int virq,
231 231
232static struct irq_domain_ops em_gio_irq_domain_ops = { 232static struct irq_domain_ops em_gio_irq_domain_ops = {
233 .map = em_gio_irq_domain_map, 233 .map = em_gio_irq_domain_map,
234 .xlate = irq_domain_xlate_twocell,
234}; 235};
235 236
236static int em_gio_probe(struct platform_device *pdev) 237static int em_gio_probe(struct platform_device *pdev)
237{ 238{
239 struct gpio_em_config pdata_dt;
238 struct gpio_em_config *pdata = pdev->dev.platform_data; 240 struct gpio_em_config *pdata = pdev->dev.platform_data;
239 struct em_gio_priv *p; 241 struct em_gio_priv *p;
240 struct resource *io[2], *irq[2]; 242 struct resource *io[2], *irq[2];
@@ -243,7 +245,7 @@ static int em_gio_probe(struct platform_device *pdev)
243 const char *name = dev_name(&pdev->dev); 245 const char *name = dev_name(&pdev->dev);
244 int ret; 246 int ret;
245 247
246 p = kzalloc(sizeof(*p), GFP_KERNEL); 248 p = devm_kzalloc(&pdev->dev, sizeof(*p), GFP_KERNEL);
247 if (!p) { 249 if (!p) {
248 dev_err(&pdev->dev, "failed to allocate driver data\n"); 250 dev_err(&pdev->dev, "failed to allocate driver data\n");
249 ret = -ENOMEM; 251 ret = -ENOMEM;
@@ -259,24 +261,45 @@ static int em_gio_probe(struct platform_device *pdev)
259 irq[0] = platform_get_resource(pdev, IORESOURCE_IRQ, 0); 261 irq[0] = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
260 irq[1] = platform_get_resource(pdev, IORESOURCE_IRQ, 1); 262 irq[1] = platform_get_resource(pdev, IORESOURCE_IRQ, 1);
261 263
262 if (!io[0] || !io[1] || !irq[0] || !irq[1] || !pdata) { 264 if (!io[0] || !io[1] || !irq[0] || !irq[1]) {
263 dev_err(&pdev->dev, "missing IRQ, IOMEM or configuration\n"); 265 dev_err(&pdev->dev, "missing IRQ or IOMEM\n");
264 ret = -EINVAL; 266 ret = -EINVAL;
265 goto err1; 267 goto err0;
266 } 268 }
267 269
268 p->base0 = ioremap_nocache(io[0]->start, resource_size(io[0])); 270 p->base0 = devm_ioremap_nocache(&pdev->dev, io[0]->start,
271 resource_size(io[0]));
269 if (!p->base0) { 272 if (!p->base0) {
270 dev_err(&pdev->dev, "failed to remap low I/O memory\n"); 273 dev_err(&pdev->dev, "failed to remap low I/O memory\n");
271 ret = -ENXIO; 274 ret = -ENXIO;
272 goto err1; 275 goto err0;
273 } 276 }
274 277
275 p->base1 = ioremap_nocache(io[1]->start, resource_size(io[1])); 278 p->base1 = devm_ioremap_nocache(&pdev->dev, io[1]->start,
279 resource_size(io[1]));
276 if (!p->base1) { 280 if (!p->base1) {
277 dev_err(&pdev->dev, "failed to remap high I/O memory\n"); 281 dev_err(&pdev->dev, "failed to remap high I/O memory\n");
278 ret = -ENXIO; 282 ret = -ENXIO;
279 goto err2; 283 goto err0;
284 }
285
286 if (!pdata) {
287 memset(&pdata_dt, 0, sizeof(pdata_dt));
288 pdata = &pdata_dt;
289
290 if (of_property_read_u32(pdev->dev.of_node, "ngpios",
291 &pdata->number_of_pins)) {
292 dev_err(&pdev->dev, "Missing ngpios OF property\n");
293 ret = -EINVAL;
294 goto err0;
295 }
296
297 ret = of_alias_get_id(pdev->dev.of_node, "gpio");
298 if (ret < 0) {
299 dev_err(&pdev->dev, "Couldn't get OF id\n");
300 goto err0;
301 }
302 pdata->gpio_base = ret * 32; /* 32 GPIOs per instance */
280 } 303 }
281 304
282 gpio_chip = &p->gpio_chip; 305 gpio_chip = &p->gpio_chip;
@@ -306,40 +329,32 @@ static int em_gio_probe(struct platform_device *pdev)
306 if (!p->irq_domain) { 329 if (!p->irq_domain) {
307 ret = -ENXIO; 330 ret = -ENXIO;
308 dev_err(&pdev->dev, "cannot initialize irq domain\n"); 331 dev_err(&pdev->dev, "cannot initialize irq domain\n");
309 goto err3; 332 goto err0;
310 } 333 }
311 334
312 if (request_irq(irq[0]->start, em_gio_irq_handler, 0, name, p)) { 335 if (devm_request_irq(&pdev->dev, irq[0]->start,
336 em_gio_irq_handler, 0, name, p)) {
313 dev_err(&pdev->dev, "failed to request low IRQ\n"); 337 dev_err(&pdev->dev, "failed to request low IRQ\n");
314 ret = -ENOENT; 338 ret = -ENOENT;
315 goto err4; 339 goto err1;
316 } 340 }
317 341
318 if (request_irq(irq[1]->start, em_gio_irq_handler, 0, name, p)) { 342 if (devm_request_irq(&pdev->dev, irq[1]->start,
343 em_gio_irq_handler, 0, name, p)) {
319 dev_err(&pdev->dev, "failed to request high IRQ\n"); 344 dev_err(&pdev->dev, "failed to request high IRQ\n");
320 ret = -ENOENT; 345 ret = -ENOENT;
321 goto err5; 346 goto err1;
322 } 347 }
323 348
324 ret = gpiochip_add(gpio_chip); 349 ret = gpiochip_add(gpio_chip);
325 if (ret) { 350 if (ret) {
326 dev_err(&pdev->dev, "failed to add GPIO controller\n"); 351 dev_err(&pdev->dev, "failed to add GPIO controller\n");
327 goto err6; 352 goto err1;
328 } 353 }
329 return 0; 354 return 0;
330 355
331err6:
332 free_irq(irq[1]->start, pdev);
333err5:
334 free_irq(irq[0]->start, pdev);
335err4:
336 irq_domain_remove(p->irq_domain);
337err3:
338 iounmap(p->base1);
339err2:
340 iounmap(p->base0);
341err1: 356err1:
342 kfree(p); 357 irq_domain_remove(p->irq_domain);
343err0: 358err0:
344 return ret; 359 return ret;
345} 360}
@@ -347,34 +362,43 @@ err0:
347static int em_gio_remove(struct platform_device *pdev) 362static int em_gio_remove(struct platform_device *pdev)
348{ 363{
349 struct em_gio_priv *p = platform_get_drvdata(pdev); 364 struct em_gio_priv *p = platform_get_drvdata(pdev);
350 struct resource *irq[2];
351 int ret; 365 int ret;
352 366
353 ret = gpiochip_remove(&p->gpio_chip); 367 ret = gpiochip_remove(&p->gpio_chip);
354 if (ret) 368 if (ret)
355 return ret; 369 return ret;
356 370
357 irq[0] = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
358 irq[1] = platform_get_resource(pdev, IORESOURCE_IRQ, 1);
359
360 free_irq(irq[1]->start, pdev);
361 free_irq(irq[0]->start, pdev);
362 irq_domain_remove(p->irq_domain); 371 irq_domain_remove(p->irq_domain);
363 iounmap(p->base1);
364 iounmap(p->base0);
365 kfree(p);
366 return 0; 372 return 0;
367} 373}
368 374
375static const struct of_device_id em_gio_dt_ids[] = {
376 { .compatible = "renesas,em-gio", },
377 {},
378};
379MODULE_DEVICE_TABLE(of, em_gio_dt_ids);
380
369static struct platform_driver em_gio_device_driver = { 381static struct platform_driver em_gio_device_driver = {
370 .probe = em_gio_probe, 382 .probe = em_gio_probe,
371 .remove = em_gio_remove, 383 .remove = em_gio_remove,
372 .driver = { 384 .driver = {
373 .name = "em_gio", 385 .name = "em_gio",
386 .of_match_table = em_gio_dt_ids,
387 .owner = THIS_MODULE,
374 } 388 }
375}; 389};
376 390
377module_platform_driver(em_gio_device_driver); 391static int __init em_gio_init(void)
392{
393 return platform_driver_register(&em_gio_device_driver);
394}
395postcore_initcall(em_gio_init);
396
397static void __exit em_gio_exit(void)
398{
399 platform_driver_unregister(&em_gio_device_driver);
400}
401module_exit(em_gio_exit);
378 402
379MODULE_AUTHOR("Magnus Damm"); 403MODULE_AUTHOR("Magnus Damm");
380MODULE_DESCRIPTION("Renesas Emma Mobile GIO Driver"); 404MODULE_DESCRIPTION("Renesas Emma Mobile GIO Driver");
diff --git a/drivers/gpio/gpio-generic.c b/drivers/gpio/gpio-generic.c
index 05fcc0f247ca..d2196bf73847 100644
--- a/drivers/gpio/gpio-generic.c
+++ b/drivers/gpio/gpio-generic.c
@@ -104,6 +104,26 @@ static unsigned long bgpio_read64(void __iomem *reg)
104} 104}
105#endif /* BITS_PER_LONG >= 64 */ 105#endif /* BITS_PER_LONG >= 64 */
106 106
107static void bgpio_write16be(void __iomem *reg, unsigned long data)
108{
109 iowrite16be(data, reg);
110}
111
112static unsigned long bgpio_read16be(void __iomem *reg)
113{
114 return ioread16be(reg);
115}
116
117static void bgpio_write32be(void __iomem *reg, unsigned long data)
118{
119 iowrite32be(data, reg);
120}
121
122static unsigned long bgpio_read32be(void __iomem *reg)
123{
124 return ioread32be(reg);
125}
126
107static unsigned long bgpio_pin2mask(struct bgpio_chip *bgc, unsigned int pin) 127static unsigned long bgpio_pin2mask(struct bgpio_chip *bgc, unsigned int pin)
108{ 128{
109 return 1 << pin; 129 return 1 << pin;
@@ -249,7 +269,8 @@ static int bgpio_dir_out_inv(struct gpio_chip *gc, unsigned int gpio, int val)
249 269
250static int bgpio_setup_accessors(struct device *dev, 270static int bgpio_setup_accessors(struct device *dev,
251 struct bgpio_chip *bgc, 271 struct bgpio_chip *bgc,
252 bool be) 272 bool bit_be,
273 bool byte_be)
253{ 274{
254 275
255 switch (bgc->bits) { 276 switch (bgc->bits) {
@@ -258,17 +279,33 @@ static int bgpio_setup_accessors(struct device *dev,
258 bgc->write_reg = bgpio_write8; 279 bgc->write_reg = bgpio_write8;
259 break; 280 break;
260 case 16: 281 case 16:
261 bgc->read_reg = bgpio_read16; 282 if (byte_be) {
262 bgc->write_reg = bgpio_write16; 283 bgc->read_reg = bgpio_read16be;
284 bgc->write_reg = bgpio_write16be;
285 } else {
286 bgc->read_reg = bgpio_read16;
287 bgc->write_reg = bgpio_write16;
288 }
263 break; 289 break;
264 case 32: 290 case 32:
265 bgc->read_reg = bgpio_read32; 291 if (byte_be) {
266 bgc->write_reg = bgpio_write32; 292 bgc->read_reg = bgpio_read32be;
293 bgc->write_reg = bgpio_write32be;
294 } else {
295 bgc->read_reg = bgpio_read32;
296 bgc->write_reg = bgpio_write32;
297 }
267 break; 298 break;
268#if BITS_PER_LONG >= 64 299#if BITS_PER_LONG >= 64
269 case 64: 300 case 64:
270 bgc->read_reg = bgpio_read64; 301 if (byte_be) {
271 bgc->write_reg = bgpio_write64; 302 dev_err(dev,
303 "64 bit big endian byte order unsupported\n");
304 return -EINVAL;
305 } else {
306 bgc->read_reg = bgpio_read64;
307 bgc->write_reg = bgpio_write64;
308 }
272 break; 309 break;
273#endif /* BITS_PER_LONG >= 64 */ 310#endif /* BITS_PER_LONG >= 64 */
274 default: 311 default:
@@ -276,7 +313,7 @@ static int bgpio_setup_accessors(struct device *dev,
276 return -EINVAL; 313 return -EINVAL;
277 } 314 }
278 315
279 bgc->pin2mask = be ? bgpio_pin2mask_be : bgpio_pin2mask; 316 bgc->pin2mask = bit_be ? bgpio_pin2mask_be : bgpio_pin2mask;
280 317
281 return 0; 318 return 0;
282} 319}
@@ -353,11 +390,7 @@ static int bgpio_setup_direction(struct bgpio_chip *bgc,
353 390
354int bgpio_remove(struct bgpio_chip *bgc) 391int bgpio_remove(struct bgpio_chip *bgc)
355{ 392{
356 int err = gpiochip_remove(&bgc->gc); 393 return gpiochip_remove(&bgc->gc);
357
358 kfree(bgc);
359
360 return err;
361} 394}
362EXPORT_SYMBOL_GPL(bgpio_remove); 395EXPORT_SYMBOL_GPL(bgpio_remove);
363 396
@@ -385,7 +418,8 @@ int bgpio_init(struct bgpio_chip *bgc, struct device *dev,
385 if (ret) 418 if (ret)
386 return ret; 419 return ret;
387 420
388 ret = bgpio_setup_accessors(dev, bgc, flags & BGPIOF_BIG_ENDIAN); 421 ret = bgpio_setup_accessors(dev, bgc, flags & BGPIOF_BIG_ENDIAN,
422 flags & BGPIOF_BIG_ENDIAN_BYTE_ORDER);
389 if (ret) 423 if (ret)
390 return ret; 424 return ret;
391 425
diff --git a/drivers/gpio/gpio-grgpio.c b/drivers/gpio/gpio-grgpio.c
new file mode 100644
index 000000000000..8e08b8647655
--- /dev/null
+++ b/drivers/gpio/gpio-grgpio.c
@@ -0,0 +1,505 @@
1/*
2 * Driver for Aeroflex Gaisler GRGPIO General Purpose I/O cores.
3 *
4 * 2013 (c) Aeroflex Gaisler AB
5 *
6 * This driver supports the GRGPIO GPIO core available in the GRLIB VHDL
7 * IP core library.
8 *
9 * Full documentation of the GRGPIO core can be found here:
10 * http://www.gaisler.com/products/grlib/grip.pdf
11 *
12 * See "Documentation/devicetree/bindings/gpio/gpio-grgpio.txt" for
13 * information on open firmware properties.
14 *
15 * This program is free software; you can redistribute it and/or modify it
16 * under the terms of the GNU General Public License as published by the
17 * Free Software Foundation; either version 2 of the License, or (at your
18 * option) any later version.
19 *
20 * Contributors: Andreas Larsson <andreas@gaisler.com>
21 */
22
23#include <linux/kernel.h>
24#include <linux/module.h>
25#include <linux/init.h>
26#include <linux/spinlock.h>
27#include <linux/io.h>
28#include <linux/of.h>
29#include <linux/of_gpio.h>
30#include <linux/of_platform.h>
31#include <linux/gpio.h>
32#include <linux/slab.h>
33#include <linux/err.h>
34#include <linux/basic_mmio_gpio.h>
35#include <linux/interrupt.h>
36#include <linux/irq.h>
37#include <linux/irqdomain.h>
38
39#define GRGPIO_MAX_NGPIO 32
40
41#define GRGPIO_DATA 0x00
42#define GRGPIO_OUTPUT 0x04
43#define GRGPIO_DIR 0x08
44#define GRGPIO_IMASK 0x0c
45#define GRGPIO_IPOL 0x10
46#define GRGPIO_IEDGE 0x14
47#define GRGPIO_BYPASS 0x18
48#define GRGPIO_IMAP_BASE 0x20
49
50/* Structure for an irq of the core - called an underlying irq */
51struct grgpio_uirq {
52 u8 refcnt; /* Reference counter to manage requesting/freeing of uirq */
53 u8 uirq; /* Underlying irq of the gpio driver */
54};
55
56/*
57 * Structure for an irq of a gpio line handed out by this driver. The index is
58 * used to map to the corresponding underlying irq.
59 */
60struct grgpio_lirq {
61 s8 index; /* Index into struct grgpio_priv's uirqs, or -1 */
62 u8 irq; /* irq for the gpio line */
63};
64
65struct grgpio_priv {
66 struct bgpio_chip bgc;
67 void __iomem *regs;
68 struct device *dev;
69
70 u32 imask; /* irq mask shadow register */
71
72 /*
73 * The grgpio core can have multiple "underlying" irqs. The gpio lines
74 * can be mapped to any one or none of these underlying irqs
75 * independently of each other. This driver sets up an irq domain and
76 * hands out separate irqs to each gpio line
77 */
78 struct irq_domain *domain;
79
80 /*
81 * This array contains information on each underlying irq, each
82 * irq of the grgpio core itself.
83 */
84 struct grgpio_uirq uirqs[GRGPIO_MAX_NGPIO];
85
86 /*
87 * This array contains information for each gpio line on the irqs
88 * obtains from this driver. An index value of -1 for a certain gpio
89 * line indicates that the line has no irq. Otherwise the index connects
90 * the irq to the underlying irq by pointing into the uirqs array.
91 */
92 struct grgpio_lirq lirqs[GRGPIO_MAX_NGPIO];
93};
94
95static inline struct grgpio_priv *grgpio_gc_to_priv(struct gpio_chip *gc)
96{
97 struct bgpio_chip *bgc = to_bgpio_chip(gc);
98
99 return container_of(bgc, struct grgpio_priv, bgc);
100}
101
102static void grgpio_set_imask(struct grgpio_priv *priv, unsigned int offset,
103 int val)
104{
105 struct bgpio_chip *bgc = &priv->bgc;
106 unsigned long mask = bgc->pin2mask(bgc, offset);
107 unsigned long flags;
108
109 spin_lock_irqsave(&bgc->lock, flags);
110
111 if (val)
112 priv->imask |= mask;
113 else
114 priv->imask &= ~mask;
115 bgc->write_reg(priv->regs + GRGPIO_IMASK, priv->imask);
116
117 spin_unlock_irqrestore(&bgc->lock, flags);
118}
119
120static int grgpio_to_irq(struct gpio_chip *gc, unsigned offset)
121{
122 struct grgpio_priv *priv = grgpio_gc_to_priv(gc);
123
124 if (offset > gc->ngpio)
125 return -ENXIO;
126
127 if (priv->lirqs[offset].index < 0)
128 return -ENXIO;
129
130 return irq_create_mapping(priv->domain, offset);
131}
132
133/* -------------------- IRQ chip functions -------------------- */
134
135static int grgpio_irq_set_type(struct irq_data *d, unsigned int type)
136{
137 struct grgpio_priv *priv = irq_data_get_irq_chip_data(d);
138 unsigned long flags;
139 u32 mask = BIT(d->hwirq);
140 u32 ipol;
141 u32 iedge;
142 u32 pol;
143 u32 edge;
144
145 switch (type) {
146 case IRQ_TYPE_LEVEL_LOW:
147 pol = 0;
148 edge = 0;
149 break;
150 case IRQ_TYPE_LEVEL_HIGH:
151 pol = mask;
152 edge = 0;
153 break;
154 case IRQ_TYPE_EDGE_FALLING:
155 pol = 0;
156 edge = mask;
157 break;
158 case IRQ_TYPE_EDGE_RISING:
159 pol = mask;
160 edge = mask;
161 break;
162 default:
163 return -EINVAL;
164 }
165
166 spin_lock_irqsave(&priv->bgc.lock, flags);
167
168 ipol = priv->bgc.read_reg(priv->regs + GRGPIO_IPOL) & ~mask;
169 iedge = priv->bgc.read_reg(priv->regs + GRGPIO_IEDGE) & ~mask;
170
171 priv->bgc.write_reg(priv->regs + GRGPIO_IPOL, ipol | pol);
172 priv->bgc.write_reg(priv->regs + GRGPIO_IEDGE, iedge | edge);
173
174 spin_unlock_irqrestore(&priv->bgc.lock, flags);
175
176 return 0;
177}
178
179static void grgpio_irq_mask(struct irq_data *d)
180{
181 struct grgpio_priv *priv = irq_data_get_irq_chip_data(d);
182 int offset = d->hwirq;
183
184 grgpio_set_imask(priv, offset, 0);
185}
186
187static void grgpio_irq_unmask(struct irq_data *d)
188{
189 struct grgpio_priv *priv = irq_data_get_irq_chip_data(d);
190 int offset = d->hwirq;
191
192 grgpio_set_imask(priv, offset, 1);
193}
194
195static struct irq_chip grgpio_irq_chip = {
196 .name = "grgpio",
197 .irq_mask = grgpio_irq_mask,
198 .irq_unmask = grgpio_irq_unmask,
199 .irq_set_type = grgpio_irq_set_type,
200};
201
202static irqreturn_t grgpio_irq_handler(int irq, void *dev)
203{
204 struct grgpio_priv *priv = dev;
205 int ngpio = priv->bgc.gc.ngpio;
206 unsigned long flags;
207 int i;
208 int match = 0;
209
210 spin_lock_irqsave(&priv->bgc.lock, flags);
211
212 /*
213 * For each gpio line, call its interrupt handler if it its underlying
214 * irq matches the current irq that is handled.
215 */
216 for (i = 0; i < ngpio; i++) {
217 struct grgpio_lirq *lirq = &priv->lirqs[i];
218
219 if (priv->imask & BIT(i) && lirq->index >= 0 &&
220 priv->uirqs[lirq->index].uirq == irq) {
221 generic_handle_irq(lirq->irq);
222 match = 1;
223 }
224 }
225
226 spin_unlock_irqrestore(&priv->bgc.lock, flags);
227
228 if (!match)
229 dev_warn(priv->dev, "No gpio line matched irq %d\n", irq);
230
231 return IRQ_HANDLED;
232}
233
234/*
235 * This function will be called as a consequence of the call to
236 * irq_create_mapping in grgpio_to_irq
237 */
238int grgpio_irq_map(struct irq_domain *d, unsigned int irq,
239 irq_hw_number_t hwirq)
240{
241 struct grgpio_priv *priv = d->host_data;
242 struct grgpio_lirq *lirq;
243 struct grgpio_uirq *uirq;
244 unsigned long flags;
245 int offset = hwirq;
246 int ret = 0;
247
248 if (!priv)
249 return -EINVAL;
250
251 lirq = &priv->lirqs[offset];
252 if (lirq->index < 0)
253 return -EINVAL;
254
255 dev_dbg(priv->dev, "Mapping irq %d for gpio line %d\n",
256 irq, offset);
257
258 spin_lock_irqsave(&priv->bgc.lock, flags);
259
260 /* Request underlying irq if not already requested */
261 lirq->irq = irq;
262 uirq = &priv->uirqs[lirq->index];
263 if (uirq->refcnt == 0) {
264 ret = request_irq(uirq->uirq, grgpio_irq_handler, 0,
265 dev_name(priv->dev), priv);
266 if (ret) {
267 dev_err(priv->dev,
268 "Could not request underlying irq %d\n",
269 uirq->uirq);
270
271 spin_unlock_irqrestore(&priv->bgc.lock, flags);
272
273 return ret;
274 }
275 }
276 uirq->refcnt++;
277
278 spin_unlock_irqrestore(&priv->bgc.lock, flags);
279
280 /* Setup irq */
281 irq_set_chip_data(irq, priv);
282 irq_set_chip_and_handler(irq, &grgpio_irq_chip,
283 handle_simple_irq);
284 irq_clear_status_flags(irq, IRQ_NOREQUEST);
285#ifdef CONFIG_ARM
286 set_irq_flags(irq, IRQF_VALID);
287#else
288 irq_set_noprobe(irq);
289#endif
290
291 return ret;
292}
293
294void grgpio_irq_unmap(struct irq_domain *d, unsigned int irq)
295{
296 struct grgpio_priv *priv = d->host_data;
297 int index;
298 struct grgpio_lirq *lirq;
299 struct grgpio_uirq *uirq;
300 unsigned long flags;
301 int ngpio = priv->bgc.gc.ngpio;
302 int i;
303
304#ifdef CONFIG_ARM
305 set_irq_flags(irq, 0);
306#endif
307 irq_set_chip_and_handler(irq, NULL, NULL);
308 irq_set_chip_data(irq, NULL);
309
310 spin_lock_irqsave(&priv->bgc.lock, flags);
311
312 /* Free underlying irq if last user unmapped */
313 index = -1;
314 for (i = 0; i < ngpio; i++) {
315 lirq = &priv->lirqs[i];
316 if (lirq->irq == irq) {
317 grgpio_set_imask(priv, i, 0);
318 lirq->irq = 0;
319 index = lirq->index;
320 break;
321 }
322 }
323 WARN_ON(index < 0);
324
325 if (index >= 0) {
326 uirq = &priv->uirqs[lirq->index];
327 uirq->refcnt--;
328 if (uirq->refcnt == 0)
329 free_irq(uirq->uirq, priv);
330 }
331
332 spin_unlock_irqrestore(&priv->bgc.lock, flags);
333}
334
335static struct irq_domain_ops grgpio_irq_domain_ops = {
336 .map = grgpio_irq_map,
337 .unmap = grgpio_irq_unmap,
338};
339
340/* ------------------------------------------------------------ */
341
342static int grgpio_probe(struct platform_device *ofdev)
343{
344 struct device_node *np = ofdev->dev.of_node;
345 void __iomem *regs;
346 struct gpio_chip *gc;
347 struct bgpio_chip *bgc;
348 struct grgpio_priv *priv;
349 struct resource *res;
350 int err;
351 u32 prop;
352 s32 *irqmap;
353 int size;
354 int i;
355
356 priv = devm_kzalloc(&ofdev->dev, sizeof(*priv), GFP_KERNEL);
357 if (!priv)
358 return -ENOMEM;
359
360 res = platform_get_resource(ofdev, IORESOURCE_MEM, 0);
361 regs = devm_ioremap_resource(&ofdev->dev, res);
362 if (IS_ERR(regs))
363 return PTR_ERR(regs);
364
365 bgc = &priv->bgc;
366 err = bgpio_init(bgc, &ofdev->dev, 4, regs + GRGPIO_DATA,
367 regs + GRGPIO_OUTPUT, NULL, regs + GRGPIO_DIR, NULL,
368 BGPIOF_BIG_ENDIAN_BYTE_ORDER);
369 if (err) {
370 dev_err(&ofdev->dev, "bgpio_init() failed\n");
371 return err;
372 }
373
374 priv->regs = regs;
375 priv->imask = bgc->read_reg(regs + GRGPIO_IMASK);
376 priv->dev = &ofdev->dev;
377
378 gc = &bgc->gc;
379 gc->of_node = np;
380 gc->owner = THIS_MODULE;
381 gc->to_irq = grgpio_to_irq;
382 gc->label = np->full_name;
383 gc->base = -1;
384
385 err = of_property_read_u32(np, "nbits", &prop);
386 if (err || prop <= 0 || prop > GRGPIO_MAX_NGPIO) {
387 gc->ngpio = GRGPIO_MAX_NGPIO;
388 dev_dbg(&ofdev->dev,
389 "No or invalid nbits property: assume %d\n", gc->ngpio);
390 } else {
391 gc->ngpio = prop;
392 }
393
394 /*
395 * The irqmap contains the index values indicating which underlying irq,
396 * if anyone, is connected to that line
397 */
398 irqmap = (s32 *)of_get_property(np, "irqmap", &size);
399 if (irqmap) {
400 if (size < gc->ngpio) {
401 dev_err(&ofdev->dev,
402 "irqmap shorter than ngpio (%d < %d)\n",
403 size, gc->ngpio);
404 return -EINVAL;
405 }
406
407 priv->domain = irq_domain_add_linear(np, gc->ngpio,
408 &grgpio_irq_domain_ops,
409 priv);
410 if (!priv->domain) {
411 dev_err(&ofdev->dev, "Could not add irq domain\n");
412 return -EINVAL;
413 }
414
415 for (i = 0; i < gc->ngpio; i++) {
416 struct grgpio_lirq *lirq;
417 int ret;
418
419 lirq = &priv->lirqs[i];
420 lirq->index = irqmap[i];
421
422 if (lirq->index < 0)
423 continue;
424
425 ret = platform_get_irq(ofdev, lirq->index);
426 if (ret <= 0) {
427 /*
428 * Continue without irq functionality for that
429 * gpio line
430 */
431 dev_err(priv->dev,
432 "Failed to get irq for offset %d\n", i);
433 continue;
434 }
435 priv->uirqs[lirq->index].uirq = ret;
436 }
437 }
438
439 platform_set_drvdata(ofdev, priv);
440
441 err = gpiochip_add(gc);
442 if (err) {
443 dev_err(&ofdev->dev, "Could not add gpiochip\n");
444 return err;
445 }
446
447 dev_info(&ofdev->dev, "regs=0x%p, base=%d, ngpio=%d, irqs=%s\n",
448 priv->regs, gc->base, gc->ngpio, priv->domain ? "on" : "off");
449
450 return 0;
451}
452
453static int grgpio_remove(struct platform_device *ofdev)
454{
455 struct grgpio_priv *priv = platform_get_drvdata(ofdev);
456 unsigned long flags;
457 int i;
458 int ret = 0;
459
460 spin_lock_irqsave(&priv->bgc.lock, flags);
461
462 if (priv->domain) {
463 for (i = 0; i < GRGPIO_MAX_NGPIO; i++) {
464 if (priv->uirqs[i].refcnt != 0) {
465 ret = -EBUSY;
466 goto out;
467 }
468 }
469 }
470
471 ret = gpiochip_remove(&priv->bgc.gc);
472 if (ret)
473 goto out;
474
475 if (priv->domain)
476 irq_domain_remove(priv->domain);
477
478out:
479 spin_unlock_irqrestore(&priv->bgc.lock, flags);
480
481 return ret;
482}
483
484static struct of_device_id grgpio_match[] = {
485 {.name = "GAISLER_GPIO"},
486 {.name = "01_01a"},
487 {},
488};
489
490MODULE_DEVICE_TABLE(of, grgpio_match);
491
492static struct platform_driver grgpio_driver = {
493 .driver = {
494 .name = "grgpio",
495 .owner = THIS_MODULE,
496 .of_match_table = grgpio_match,
497 },
498 .probe = grgpio_probe,
499 .remove = grgpio_remove,
500};
501module_platform_driver(grgpio_driver);
502
503MODULE_AUTHOR("Aeroflex Gaisler AB.");
504MODULE_DESCRIPTION("Driver for Aeroflex Gaisler GRGPIO");
505MODULE_LICENSE("GPL");
diff --git a/drivers/gpio/gpio-ich.c b/drivers/gpio/gpio-ich.c
index de3c317bd3e2..e16d932fd444 100644
--- a/drivers/gpio/gpio-ich.c
+++ b/drivers/gpio/gpio-ich.c
@@ -130,14 +130,11 @@ static int ichx_read_bit(int reg, unsigned nr)
130 130
131static bool ichx_gpio_check_available(struct gpio_chip *gpio, unsigned nr) 131static bool ichx_gpio_check_available(struct gpio_chip *gpio, unsigned nr)
132{ 132{
133 return ichx_priv.use_gpio & (1 << (nr / 32)); 133 return !!(ichx_priv.use_gpio & (1 << (nr / 32)));
134} 134}
135 135
136static int ichx_gpio_direction_input(struct gpio_chip *gpio, unsigned nr) 136static int ichx_gpio_direction_input(struct gpio_chip *gpio, unsigned nr)
137{ 137{
138 if (!ichx_gpio_check_available(gpio, nr))
139 return -ENXIO;
140
141 /* 138 /*
142 * Try setting pin as an input and verify it worked since many pins 139 * Try setting pin as an input and verify it worked since many pins
143 * are output-only. 140 * are output-only.
@@ -151,9 +148,6 @@ static int ichx_gpio_direction_input(struct gpio_chip *gpio, unsigned nr)
151static int ichx_gpio_direction_output(struct gpio_chip *gpio, unsigned nr, 148static int ichx_gpio_direction_output(struct gpio_chip *gpio, unsigned nr,
152 int val) 149 int val)
153{ 150{
154 if (!ichx_gpio_check_available(gpio, nr))
155 return -ENXIO;
156
157 /* Set GPIO output value. */ 151 /* Set GPIO output value. */
158 ichx_write_bit(GPIO_LVL, nr, val, 0); 152 ichx_write_bit(GPIO_LVL, nr, val, 0);
159 153
@@ -169,9 +163,6 @@ static int ichx_gpio_direction_output(struct gpio_chip *gpio, unsigned nr,
169 163
170static int ichx_gpio_get(struct gpio_chip *chip, unsigned nr) 164static int ichx_gpio_get(struct gpio_chip *chip, unsigned nr)
171{ 165{
172 if (!ichx_gpio_check_available(chip, nr))
173 return -ENXIO;
174
175 return ichx_read_bit(GPIO_LVL, nr); 166 return ichx_read_bit(GPIO_LVL, nr);
176} 167}
177 168
@@ -180,9 +171,6 @@ static int ich6_gpio_get(struct gpio_chip *chip, unsigned nr)
180 unsigned long flags; 171 unsigned long flags;
181 u32 data; 172 u32 data;
182 173
183 if (!ichx_gpio_check_available(chip, nr))
184 return -ENXIO;
185
186 /* 174 /*
187 * GPI 0 - 15 need to be read from the power management registers on 175 * GPI 0 - 15 need to be read from the power management registers on
188 * a ICH6/3100 bridge. 176 * a ICH6/3100 bridge.
@@ -207,6 +195,9 @@ static int ich6_gpio_get(struct gpio_chip *chip, unsigned nr)
207 195
208static int ichx_gpio_request(struct gpio_chip *chip, unsigned nr) 196static int ichx_gpio_request(struct gpio_chip *chip, unsigned nr)
209{ 197{
198 if (!ichx_gpio_check_available(chip, nr))
199 return -ENXIO;
200
210 /* 201 /*
211 * Note we assume the BIOS properly set a bridge's USE value. Some 202 * Note we assume the BIOS properly set a bridge's USE value. Some
212 * chips (eg Intel 3100) have bogus USE values though, so first see if 203 * chips (eg Intel 3100) have bogus USE values though, so first see if
diff --git a/drivers/gpio/gpio-lpc32xx.c b/drivers/gpio/gpio-lpc32xx.c
index 36d7dee07b28..dda6a756a3d9 100644
--- a/drivers/gpio/gpio-lpc32xx.c
+++ b/drivers/gpio/gpio-lpc32xx.c
@@ -533,7 +533,7 @@ static int lpc32xx_of_xlate(struct gpio_chip *gc,
533{ 533{
534 /* Is this the correct bank? */ 534 /* Is this the correct bank? */
535 u32 bank = gpiospec->args[0]; 535 u32 bank = gpiospec->args[0];
536 if ((bank > ARRAY_SIZE(lpc32xx_gpiochip) || 536 if ((bank >= ARRAY_SIZE(lpc32xx_gpiochip) ||
537 (gc != &lpc32xx_gpiochip[bank].chip))) 537 (gc != &lpc32xx_gpiochip[bank].chip)))
538 return -EINVAL; 538 return -EINVAL;
539 539
diff --git a/drivers/gpio/gpio-lynxpoint.c b/drivers/gpio/gpio-lynxpoint.c
index 3472b05ac512..86c17de87692 100644
--- a/drivers/gpio/gpio-lynxpoint.c
+++ b/drivers/gpio/gpio-lynxpoint.c
@@ -32,6 +32,7 @@
32#include <linux/acpi.h> 32#include <linux/acpi.h>
33#include <linux/platform_device.h> 33#include <linux/platform_device.h>
34#include <linux/pm_runtime.h> 34#include <linux/pm_runtime.h>
35#include <linux/io.h>
35 36
36/* LynxPoint chipset has support for 94 gpio pins */ 37/* LynxPoint chipset has support for 94 gpio pins */
37 38
diff --git a/drivers/gpio/gpio-max7300.c b/drivers/gpio/gpio-max7300.c
index 4b6b9a04e326..40ab6dfb6021 100644
--- a/drivers/gpio/gpio-max7300.c
+++ b/drivers/gpio/gpio-max7300.c
@@ -41,7 +41,7 @@ static int max7300_probe(struct i2c_client *client,
41 I2C_FUNC_SMBUS_BYTE_DATA)) 41 I2C_FUNC_SMBUS_BYTE_DATA))
42 return -EIO; 42 return -EIO;
43 43
44 ts = kzalloc(sizeof(struct max7301), GFP_KERNEL); 44 ts = devm_kzalloc(&client->dev, sizeof(struct max7301), GFP_KERNEL);
45 if (!ts) 45 if (!ts)
46 return -ENOMEM; 46 return -ENOMEM;
47 47
@@ -50,8 +50,6 @@ static int max7300_probe(struct i2c_client *client,
50 ts->dev = &client->dev; 50 ts->dev = &client->dev;
51 51
52 ret = __max730x_probe(ts); 52 ret = __max730x_probe(ts);
53 if (ret)
54 kfree(ts);
55 return ret; 53 return ret;
56} 54}
57 55
diff --git a/drivers/gpio/gpio-max7301.c b/drivers/gpio/gpio-max7301.c
index c6c535c1310e..3b16ab701630 100644
--- a/drivers/gpio/gpio-max7301.c
+++ b/drivers/gpio/gpio-max7301.c
@@ -56,12 +56,13 @@ static int max7301_probe(struct spi_device *spi)
56 int ret; 56 int ret;
57 57
58 /* bits_per_word cannot be configured in platform data */ 58 /* bits_per_word cannot be configured in platform data */
59 spi->bits_per_word = 16; 59 if (spi->dev.platform_data)
60 spi->bits_per_word = 16;
60 ret = spi_setup(spi); 61 ret = spi_setup(spi);
61 if (ret < 0) 62 if (ret < 0)
62 return ret; 63 return ret;
63 64
64 ts = kzalloc(sizeof(struct max7301), GFP_KERNEL); 65 ts = devm_kzalloc(&spi->dev, sizeof(struct max7301), GFP_KERNEL);
65 if (!ts) 66 if (!ts)
66 return -ENOMEM; 67 return -ENOMEM;
67 68
@@ -70,8 +71,6 @@ static int max7301_probe(struct spi_device *spi)
70 ts->dev = &spi->dev; 71 ts->dev = &spi->dev;
71 72
72 ret = __max730x_probe(ts); 73 ret = __max730x_probe(ts);
73 if (ret)
74 kfree(ts);
75 return ret; 74 return ret;
76} 75}
77 76
diff --git a/drivers/gpio/gpio-max732x.c b/drivers/gpio/gpio-max732x.c
index 1e0467ce4c37..d4b51b163b03 100644
--- a/drivers/gpio/gpio-max732x.c
+++ b/drivers/gpio/gpio-max732x.c
@@ -589,7 +589,8 @@ static int max732x_probe(struct i2c_client *client,
589 return -EINVAL; 589 return -EINVAL;
590 } 590 }
591 591
592 chip = kzalloc(sizeof(struct max732x_chip), GFP_KERNEL); 592 chip = devm_kzalloc(&client->dev, sizeof(struct max732x_chip),
593 GFP_KERNEL);
593 if (chip == NULL) 594 if (chip == NULL)
594 return -ENOMEM; 595 return -ENOMEM;
595 chip->client = client; 596 chip->client = client;
@@ -647,7 +648,6 @@ static int max732x_probe(struct i2c_client *client,
647 648
648out_failed: 649out_failed:
649 max732x_irq_teardown(chip); 650 max732x_irq_teardown(chip);
650 kfree(chip);
651 return ret; 651 return ret;
652} 652}
653 653
@@ -680,7 +680,6 @@ static int max732x_remove(struct i2c_client *client)
680 if (chip->client_dummy) 680 if (chip->client_dummy)
681 i2c_unregister_device(chip->client_dummy); 681 i2c_unregister_device(chip->client_dummy);
682 682
683 kfree(chip);
684 return 0; 683 return 0;
685} 684}
686 685
diff --git a/drivers/gpio/gpio-mc33880.c b/drivers/gpio/gpio-mc33880.c
index 6a8fdc26ae6a..63a7a1bfb2d9 100644
--- a/drivers/gpio/gpio-mc33880.c
+++ b/drivers/gpio/gpio-mc33880.c
@@ -101,13 +101,13 @@ static int mc33880_probe(struct spi_device *spi)
101 if (ret < 0) 101 if (ret < 0)
102 return ret; 102 return ret;
103 103
104 mc = kzalloc(sizeof(struct mc33880), GFP_KERNEL); 104 mc = devm_kzalloc(&spi->dev, sizeof(struct mc33880), GFP_KERNEL);
105 if (!mc) 105 if (!mc)
106 return -ENOMEM; 106 return -ENOMEM;
107 107
108 mutex_init(&mc->lock); 108 mutex_init(&mc->lock);
109 109
110 dev_set_drvdata(&spi->dev, mc); 110 spi_set_drvdata(spi, mc);
111 111
112 mc->spi = spi; 112 mc->spi = spi;
113 113
@@ -130,7 +130,8 @@ static int mc33880_probe(struct spi_device *spi)
130 ret = mc33880_write_config(mc); 130 ret = mc33880_write_config(mc);
131 131
132 if (ret) { 132 if (ret) {
133 printk(KERN_ERR "Failed writing to " DRIVER_NAME ": %d\n", ret); 133 dev_err(&spi->dev, "Failed writing to " DRIVER_NAME ": %d\n",
134 ret);
134 goto exit_destroy; 135 goto exit_destroy;
135 } 136 }
136 137
@@ -141,9 +142,8 @@ static int mc33880_probe(struct spi_device *spi)
141 return ret; 142 return ret;
142 143
143exit_destroy: 144exit_destroy:
144 dev_set_drvdata(&spi->dev, NULL); 145 spi_set_drvdata(spi, NULL);
145 mutex_destroy(&mc->lock); 146 mutex_destroy(&mc->lock);
146 kfree(mc);
147 return ret; 147 return ret;
148} 148}
149 149
@@ -152,17 +152,16 @@ static int mc33880_remove(struct spi_device *spi)
152 struct mc33880 *mc; 152 struct mc33880 *mc;
153 int ret; 153 int ret;
154 154
155 mc = dev_get_drvdata(&spi->dev); 155 mc = spi_get_drvdata(spi);
156 if (mc == NULL) 156 if (mc == NULL)
157 return -ENODEV; 157 return -ENODEV;
158 158
159 dev_set_drvdata(&spi->dev, NULL); 159 spi_set_drvdata(spi, NULL);
160 160
161 ret = gpiochip_remove(&mc->chip); 161 ret = gpiochip_remove(&mc->chip);
162 if (!ret) { 162 if (!ret)
163 mutex_destroy(&mc->lock); 163 mutex_destroy(&mc->lock);
164 kfree(mc); 164 else
165 } else
166 dev_err(&spi->dev, "Failed to remove the GPIO controller: %d\n", 165 dev_err(&spi->dev, "Failed to remove the GPIO controller: %d\n",
167 ret); 166 ret);
168 167
diff --git a/drivers/gpio/gpio-mcp23s08.c b/drivers/gpio/gpio-mcp23s08.c
index 3cea0ea79e80..6a4470b84488 100644
--- a/drivers/gpio/gpio-mcp23s08.c
+++ b/drivers/gpio/gpio-mcp23s08.c
@@ -12,6 +12,8 @@
12#include <linux/spi/mcp23s08.h> 12#include <linux/spi/mcp23s08.h>
13#include <linux/slab.h> 13#include <linux/slab.h>
14#include <asm/byteorder.h> 14#include <asm/byteorder.h>
15#include <linux/of.h>
16#include <linux/of_device.h>
15 17
16/** 18/**
17 * MCP types supported by driver 19 * MCP types supported by driver
@@ -383,6 +385,10 @@ static int mcp23s08_probe_one(struct mcp23s08 *mcp, struct device *dev,
383 mcp->chip.direction_output = mcp23s08_direction_output; 385 mcp->chip.direction_output = mcp23s08_direction_output;
384 mcp->chip.set = mcp23s08_set; 386 mcp->chip.set = mcp23s08_set;
385 mcp->chip.dbg_show = mcp23s08_dbg_show; 387 mcp->chip.dbg_show = mcp23s08_dbg_show;
388#ifdef CONFIG_OF
389 mcp->chip.of_gpio_n_cells = 2;
390 mcp->chip.of_node = dev->of_node;
391#endif
386 392
387 switch (type) { 393 switch (type) {
388#ifdef CONFIG_SPI_MASTER 394#ifdef CONFIG_SPI_MASTER
@@ -473,6 +479,35 @@ fail:
473 479
474/*----------------------------------------------------------------------*/ 480/*----------------------------------------------------------------------*/
475 481
482#ifdef CONFIG_OF
483#ifdef CONFIG_SPI_MASTER
484static struct of_device_id mcp23s08_spi_of_match[] = {
485 {
486 .compatible = "mcp,mcp23s08", .data = (void *) MCP_TYPE_S08,
487 },
488 {
489 .compatible = "mcp,mcp23s17", .data = (void *) MCP_TYPE_S17,
490 },
491 { },
492};
493MODULE_DEVICE_TABLE(of, mcp23s08_spi_of_match);
494#endif
495
496#if IS_ENABLED(CONFIG_I2C)
497static struct of_device_id mcp23s08_i2c_of_match[] = {
498 {
499 .compatible = "mcp,mcp23008", .data = (void *) MCP_TYPE_008,
500 },
501 {
502 .compatible = "mcp,mcp23017", .data = (void *) MCP_TYPE_017,
503 },
504 { },
505};
506MODULE_DEVICE_TABLE(of, mcp23s08_i2c_of_match);
507#endif
508#endif /* CONFIG_OF */
509
510
476#if IS_ENABLED(CONFIG_I2C) 511#if IS_ENABLED(CONFIG_I2C)
477 512
478static int mcp230xx_probe(struct i2c_client *client, 513static int mcp230xx_probe(struct i2c_client *client,
@@ -480,12 +515,23 @@ static int mcp230xx_probe(struct i2c_client *client,
480{ 515{
481 struct mcp23s08_platform_data *pdata; 516 struct mcp23s08_platform_data *pdata;
482 struct mcp23s08 *mcp; 517 struct mcp23s08 *mcp;
483 int status; 518 int status, base, pullups;
484 519 const struct of_device_id *match;
485 pdata = client->dev.platform_data; 520
486 if (!pdata || !gpio_is_valid(pdata->base)) { 521 match = of_match_device(of_match_ptr(mcp23s08_i2c_of_match),
487 dev_dbg(&client->dev, "invalid or missing platform data\n"); 522 &client->dev);
488 return -EINVAL; 523 if (match) {
524 base = -1;
525 pullups = 0;
526 } else {
527 pdata = client->dev.platform_data;
528 if (!pdata || !gpio_is_valid(pdata->base)) {
529 dev_dbg(&client->dev,
530 "invalid or missing platform data\n");
531 return -EINVAL;
532 }
533 base = pdata->base;
534 pullups = pdata->chip[0].pullups;
489 } 535 }
490 536
491 mcp = kzalloc(sizeof *mcp, GFP_KERNEL); 537 mcp = kzalloc(sizeof *mcp, GFP_KERNEL);
@@ -493,8 +539,7 @@ static int mcp230xx_probe(struct i2c_client *client,
493 return -ENOMEM; 539 return -ENOMEM;
494 540
495 status = mcp23s08_probe_one(mcp, &client->dev, client, client->addr, 541 status = mcp23s08_probe_one(mcp, &client->dev, client, client->addr,
496 id->driver_data, pdata->base, 542 id->driver_data, base, pullups);
497 pdata->chip[0].pullups);
498 if (status) 543 if (status)
499 goto fail; 544 goto fail;
500 545
@@ -531,6 +576,7 @@ static struct i2c_driver mcp230xx_driver = {
531 .driver = { 576 .driver = {
532 .name = "mcp230xx", 577 .name = "mcp230xx",
533 .owner = THIS_MODULE, 578 .owner = THIS_MODULE,
579 .of_match_table = of_match_ptr(mcp23s08_i2c_of_match),
534 }, 580 },
535 .probe = mcp230xx_probe, 581 .probe = mcp230xx_probe,
536 .remove = mcp230xx_remove, 582 .remove = mcp230xx_remove,
@@ -565,28 +611,55 @@ static int mcp23s08_probe(struct spi_device *spi)
565 unsigned chips = 0; 611 unsigned chips = 0;
566 struct mcp23s08_driver_data *data; 612 struct mcp23s08_driver_data *data;
567 int status, type; 613 int status, type;
568 unsigned base; 614 unsigned base = -1,
569 615 ngpio = 0,
570 type = spi_get_device_id(spi)->driver_data; 616 pullups[ARRAY_SIZE(pdata->chip)];
571 617 const struct of_device_id *match;
572 pdata = spi->dev.platform_data; 618 u32 spi_present_mask = 0;
573 if (!pdata || !gpio_is_valid(pdata->base)) { 619
574 dev_dbg(&spi->dev, "invalid or missing platform data\n"); 620 match = of_match_device(of_match_ptr(mcp23s08_spi_of_match), &spi->dev);
575 return -EINVAL; 621 if (match) {
576 } 622 type = (int)match->data;
623 status = of_property_read_u32(spi->dev.of_node,
624 "mcp,spi-present-mask", &spi_present_mask);
625 if (status) {
626 dev_err(&spi->dev, "DT has no spi-present-mask\n");
627 return -ENODEV;
628 }
629 if ((spi_present_mask <= 0) || (spi_present_mask >= 256)) {
630 dev_err(&spi->dev, "invalid spi-present-mask\n");
631 return -ENODEV;
632 }
577 633
578 for (addr = 0; addr < ARRAY_SIZE(pdata->chip); addr++) { 634 for (addr = 0; addr < ARRAY_SIZE(pdata->chip); addr++)
579 if (!pdata->chip[addr].is_present) 635 pullups[addr] = 0;
580 continue; 636 } else {
581 chips++; 637 type = spi_get_device_id(spi)->driver_data;
582 if ((type == MCP_TYPE_S08) && (addr > 3)) { 638 pdata = spi->dev.platform_data;
583 dev_err(&spi->dev, 639 if (!pdata || !gpio_is_valid(pdata->base)) {
584 "mcp23s08 only supports address 0..3\n"); 640 dev_dbg(&spi->dev,
641 "invalid or missing platform data\n");
585 return -EINVAL; 642 return -EINVAL;
586 } 643 }
644
645 for (addr = 0; addr < ARRAY_SIZE(pdata->chip); addr++) {
646 if (!pdata->chip[addr].is_present)
647 continue;
648 chips++;
649 if ((type == MCP_TYPE_S08) && (addr > 3)) {
650 dev_err(&spi->dev,
651 "mcp23s08 only supports address 0..3\n");
652 return -EINVAL;
653 }
654 spi_present_mask |= 1 << addr;
655 pullups[addr] = pdata->chip[addr].pullups;
656 }
657
658 if (!chips)
659 return -ENODEV;
660
661 base = pdata->base;
587 } 662 }
588 if (!chips)
589 return -ENODEV;
590 663
591 data = kzalloc(sizeof *data + chips * sizeof(struct mcp23s08), 664 data = kzalloc(sizeof *data + chips * sizeof(struct mcp23s08),
592 GFP_KERNEL); 665 GFP_KERNEL);
@@ -594,21 +667,22 @@ static int mcp23s08_probe(struct spi_device *spi)
594 return -ENOMEM; 667 return -ENOMEM;
595 spi_set_drvdata(spi, data); 668 spi_set_drvdata(spi, data);
596 669
597 base = pdata->base;
598 for (addr = 0; addr < ARRAY_SIZE(pdata->chip); addr++) { 670 for (addr = 0; addr < ARRAY_SIZE(pdata->chip); addr++) {
599 if (!pdata->chip[addr].is_present) 671 if (!(spi_present_mask & (1 << addr)))
600 continue; 672 continue;
601 chips--; 673 chips--;
602 data->mcp[addr] = &data->chip[chips]; 674 data->mcp[addr] = &data->chip[chips];
603 status = mcp23s08_probe_one(data->mcp[addr], &spi->dev, spi, 675 status = mcp23s08_probe_one(data->mcp[addr], &spi->dev, spi,
604 0x40 | (addr << 1), type, base, 676 0x40 | (addr << 1), type, base,
605 pdata->chip[addr].pullups); 677 pullups[addr]);
606 if (status < 0) 678 if (status < 0)
607 goto fail; 679 goto fail;
608 680
609 base += (type == MCP_TYPE_S17) ? 16 : 8; 681 if (base != -1)
682 base += (type == MCP_TYPE_S17) ? 16 : 8;
683 ngpio += (type == MCP_TYPE_S17) ? 16 : 8;
610 } 684 }
611 data->ngpio = base - pdata->base; 685 data->ngpio = ngpio;
612 686
613 /* NOTE: these chips have a relatively sane IRQ framework, with 687 /* NOTE: these chips have a relatively sane IRQ framework, with
614 * per-signal masking and level/edge triggering. It's not yet 688 * per-signal masking and level/edge triggering. It's not yet
@@ -668,6 +742,7 @@ static struct spi_driver mcp23s08_driver = {
668 .driver = { 742 .driver = {
669 .name = "mcp23s08", 743 .name = "mcp23s08",
670 .owner = THIS_MODULE, 744 .owner = THIS_MODULE,
745 .of_match_table = of_match_ptr(mcp23s08_spi_of_match),
671 }, 746 },
672}; 747};
673 748
diff --git a/drivers/gpio/gpio-mvebu.c b/drivers/gpio/gpio-mvebu.c
index 61a6fde6c089..bf69a7eff370 100644
--- a/drivers/gpio/gpio-mvebu.c
+++ b/drivers/gpio/gpio-mvebu.c
@@ -117,7 +117,7 @@ static inline void __iomem *mvebu_gpioreg_edge_cause(struct mvebu_gpio_chip *mvc
117{ 117{
118 int cpu; 118 int cpu;
119 119
120 switch(mvchip->soc_variant) { 120 switch (mvchip->soc_variant) {
121 case MVEBU_GPIO_SOC_VARIANT_ORION: 121 case MVEBU_GPIO_SOC_VARIANT_ORION:
122 case MVEBU_GPIO_SOC_VARIANT_MV78200: 122 case MVEBU_GPIO_SOC_VARIANT_MV78200:
123 return mvchip->membase + GPIO_EDGE_CAUSE_OFF; 123 return mvchip->membase + GPIO_EDGE_CAUSE_OFF;
@@ -133,7 +133,7 @@ static inline void __iomem *mvebu_gpioreg_edge_mask(struct mvebu_gpio_chip *mvch
133{ 133{
134 int cpu; 134 int cpu;
135 135
136 switch(mvchip->soc_variant) { 136 switch (mvchip->soc_variant) {
137 case MVEBU_GPIO_SOC_VARIANT_ORION: 137 case MVEBU_GPIO_SOC_VARIANT_ORION:
138 return mvchip->membase + GPIO_EDGE_MASK_OFF; 138 return mvchip->membase + GPIO_EDGE_MASK_OFF;
139 case MVEBU_GPIO_SOC_VARIANT_MV78200: 139 case MVEBU_GPIO_SOC_VARIANT_MV78200:
@@ -151,7 +151,7 @@ static void __iomem *mvebu_gpioreg_level_mask(struct mvebu_gpio_chip *mvchip)
151{ 151{
152 int cpu; 152 int cpu;
153 153
154 switch(mvchip->soc_variant) { 154 switch (mvchip->soc_variant) {
155 case MVEBU_GPIO_SOC_VARIANT_ORION: 155 case MVEBU_GPIO_SOC_VARIANT_ORION:
156 return mvchip->membase + GPIO_LEVEL_MASK_OFF; 156 return mvchip->membase + GPIO_LEVEL_MASK_OFF;
157 case MVEBU_GPIO_SOC_VARIANT_MV78200: 157 case MVEBU_GPIO_SOC_VARIANT_MV78200:
@@ -401,7 +401,7 @@ static int mvebu_gpio_irq_set_type(struct irq_data *d, unsigned int type)
401 /* 401 /*
402 * Configure interrupt polarity. 402 * Configure interrupt polarity.
403 */ 403 */
404 switch(type) { 404 switch (type) {
405 case IRQ_TYPE_EDGE_RISING: 405 case IRQ_TYPE_EDGE_RISING:
406 case IRQ_TYPE_LEVEL_HIGH: 406 case IRQ_TYPE_LEVEL_HIGH:
407 u = readl_relaxed(mvebu_gpioreg_in_pol(mvchip)); 407 u = readl_relaxed(mvebu_gpioreg_in_pol(mvchip));
@@ -470,18 +470,76 @@ static void mvebu_gpio_irq_handler(unsigned int irq, struct irq_desc *desc)
470 } 470 }
471} 471}
472 472
473#ifdef CONFIG_DEBUG_FS
474#include <linux/seq_file.h>
475
476static void mvebu_gpio_dbg_show(struct seq_file *s, struct gpio_chip *chip)
477{
478 struct mvebu_gpio_chip *mvchip =
479 container_of(chip, struct mvebu_gpio_chip, chip);
480 u32 out, io_conf, blink, in_pol, data_in, cause, edg_msk, lvl_msk;
481 int i;
482
483 out = readl_relaxed(mvebu_gpioreg_out(mvchip));
484 io_conf = readl_relaxed(mvebu_gpioreg_io_conf(mvchip));
485 blink = readl_relaxed(mvebu_gpioreg_blink(mvchip));
486 in_pol = readl_relaxed(mvebu_gpioreg_in_pol(mvchip));
487 data_in = readl_relaxed(mvebu_gpioreg_data_in(mvchip));
488 cause = readl_relaxed(mvebu_gpioreg_edge_cause(mvchip));
489 edg_msk = readl_relaxed(mvebu_gpioreg_edge_mask(mvchip));
490 lvl_msk = readl_relaxed(mvebu_gpioreg_level_mask(mvchip));
491
492 for (i = 0; i < chip->ngpio; i++) {
493 const char *label;
494 u32 msk;
495 bool is_out;
496
497 label = gpiochip_is_requested(chip, i);
498 if (!label)
499 continue;
500
501 msk = 1 << i;
502 is_out = !(io_conf & msk);
503
504 seq_printf(s, " gpio-%-3d (%-20.20s)", chip->base + i, label);
505
506 if (is_out) {
507 seq_printf(s, " out %s %s\n",
508 out & msk ? "hi" : "lo",
509 blink & msk ? "(blink )" : "");
510 continue;
511 }
512
513 seq_printf(s, " in %s (act %s) - IRQ",
514 (data_in ^ in_pol) & msk ? "hi" : "lo",
515 in_pol & msk ? "lo" : "hi");
516 if (!((edg_msk | lvl_msk) & msk)) {
517 seq_printf(s, " disabled\n");
518 continue;
519 }
520 if (edg_msk & msk)
521 seq_printf(s, " edge ");
522 if (lvl_msk & msk)
523 seq_printf(s, " level");
524 seq_printf(s, " (%s)\n", cause & msk ? "pending" : "clear ");
525 }
526}
527#else
528#define mvebu_gpio_dbg_show NULL
529#endif
530
473static struct of_device_id mvebu_gpio_of_match[] = { 531static struct of_device_id mvebu_gpio_of_match[] = {
474 { 532 {
475 .compatible = "marvell,orion-gpio", 533 .compatible = "marvell,orion-gpio",
476 .data = (void*) MVEBU_GPIO_SOC_VARIANT_ORION, 534 .data = (void *) MVEBU_GPIO_SOC_VARIANT_ORION,
477 }, 535 },
478 { 536 {
479 .compatible = "marvell,mv78200-gpio", 537 .compatible = "marvell,mv78200-gpio",
480 .data = (void*) MVEBU_GPIO_SOC_VARIANT_MV78200, 538 .data = (void *) MVEBU_GPIO_SOC_VARIANT_MV78200,
481 }, 539 },
482 { 540 {
483 .compatible = "marvell,armadaxp-gpio", 541 .compatible = "marvell,armadaxp-gpio",
484 .data = (void*) MVEBU_GPIO_SOC_VARIANT_ARMADAXP, 542 .data = (void *) MVEBU_GPIO_SOC_VARIANT_ARMADAXP,
485 }, 543 },
486 { 544 {
487 /* sentinel */ 545 /* sentinel */
@@ -509,13 +567,13 @@ static int mvebu_gpio_probe(struct platform_device *pdev)
509 soc_variant = MVEBU_GPIO_SOC_VARIANT_ORION; 567 soc_variant = MVEBU_GPIO_SOC_VARIANT_ORION;
510 568
511 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 569 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
512 if (! res) { 570 if (!res) {
513 dev_err(&pdev->dev, "Cannot get memory resource\n"); 571 dev_err(&pdev->dev, "Cannot get memory resource\n");
514 return -ENODEV; 572 return -ENODEV;
515 } 573 }
516 574
517 mvchip = devm_kzalloc(&pdev->dev, sizeof(struct mvebu_gpio_chip), GFP_KERNEL); 575 mvchip = devm_kzalloc(&pdev->dev, sizeof(struct mvebu_gpio_chip), GFP_KERNEL);
518 if (! mvchip){ 576 if (!mvchip) {
519 dev_err(&pdev->dev, "Cannot allocate memory\n"); 577 dev_err(&pdev->dev, "Cannot allocate memory\n");
520 return -ENOMEM; 578 return -ENOMEM;
521 } 579 }
@@ -550,6 +608,7 @@ static int mvebu_gpio_probe(struct platform_device *pdev)
550 mvchip->chip.ngpio = ngpios; 608 mvchip->chip.ngpio = ngpios;
551 mvchip->chip.can_sleep = 0; 609 mvchip->chip.can_sleep = 0;
552 mvchip->chip.of_node = np; 610 mvchip->chip.of_node = np;
611 mvchip->chip.dbg_show = mvebu_gpio_dbg_show;
553 612
554 spin_lock_init(&mvchip->lock); 613 spin_lock_init(&mvchip->lock);
555 mvchip->membase = devm_ioremap_resource(&pdev->dev, res); 614 mvchip->membase = devm_ioremap_resource(&pdev->dev, res);
@@ -560,21 +619,21 @@ static int mvebu_gpio_probe(struct platform_device *pdev)
560 * per-CPU registers */ 619 * per-CPU registers */
561 if (soc_variant == MVEBU_GPIO_SOC_VARIANT_ARMADAXP) { 620 if (soc_variant == MVEBU_GPIO_SOC_VARIANT_ARMADAXP) {
562 res = platform_get_resource(pdev, IORESOURCE_MEM, 1); 621 res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
563 if (! res) { 622 if (!res) {
564 dev_err(&pdev->dev, "Cannot get memory resource\n"); 623 dev_err(&pdev->dev, "Cannot get memory resource\n");
565 return -ENODEV; 624 return -ENODEV;
566 } 625 }
567 626
568 mvchip->percpu_membase = devm_ioremap_resource(&pdev->dev, 627 mvchip->percpu_membase = devm_ioremap_resource(&pdev->dev,
569 res); 628 res);
570 if (IS_ERR(mvchip->percpu_membase)) 629 if (IS_ERR(mvchip->percpu_membase))
571 return PTR_ERR(mvchip->percpu_membase); 630 return PTR_ERR(mvchip->percpu_membase);
572 } 631 }
573 632
574 /* 633 /*
575 * Mask and clear GPIO interrupts. 634 * Mask and clear GPIO interrupts.
576 */ 635 */
577 switch(soc_variant) { 636 switch (soc_variant) {
578 case MVEBU_GPIO_SOC_VARIANT_ORION: 637 case MVEBU_GPIO_SOC_VARIANT_ORION:
579 writel_relaxed(0, mvchip->membase + GPIO_EDGE_CAUSE_OFF); 638 writel_relaxed(0, mvchip->membase + GPIO_EDGE_CAUSE_OFF);
580 writel_relaxed(0, mvchip->membase + GPIO_EDGE_MASK_OFF); 639 writel_relaxed(0, mvchip->membase + GPIO_EDGE_MASK_OFF);
@@ -632,7 +691,7 @@ static int mvebu_gpio_probe(struct platform_device *pdev)
632 691
633 gc = irq_alloc_generic_chip("mvebu_gpio_irq", 2, mvchip->irqbase, 692 gc = irq_alloc_generic_chip("mvebu_gpio_irq", 2, mvchip->irqbase,
634 mvchip->membase, handle_level_irq); 693 mvchip->membase, handle_level_irq);
635 if (! gc) { 694 if (!gc) {
636 dev_err(&pdev->dev, "Cannot allocate generic irq_chip\n"); 695 dev_err(&pdev->dev, "Cannot allocate generic irq_chip\n");
637 return -ENOMEM; 696 return -ENOMEM;
638 } 697 }
diff --git a/drivers/gpio/gpio-omap.c b/drivers/gpio/gpio-omap.c
index a612ea1c53cb..2050891d9c65 100644
--- a/drivers/gpio/gpio-omap.c
+++ b/drivers/gpio/gpio-omap.c
@@ -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 int irq_base;
56 struct irq_domain *domain; 55 struct irq_domain *domain;
57 u32 non_wakeup_gpios; 56 u32 non_wakeup_gpios;
58 u32 enabled_non_wakeup_gpios; 57 u32 enabled_non_wakeup_gpios;
@@ -88,7 +87,14 @@ struct gpio_bank {
88 87
89static int irq_to_gpio(struct gpio_bank *bank, unsigned int gpio_irq) 88static int irq_to_gpio(struct gpio_bank *bank, unsigned int gpio_irq)
90{ 89{
91 return gpio_irq - bank->irq_base + bank->chip.base; 90 return bank->chip.base + gpio_irq;
91}
92
93static int omap_gpio_to_irq(struct gpio_chip *chip, unsigned offset)
94{
95 struct gpio_bank *bank = container_of(chip, struct gpio_bank, chip);
96
97 return irq_find_mapping(bank->domain, offset);
92} 98}
93 99
94static void _set_gpio_direction(struct gpio_bank *bank, int gpio, int is_input) 100static void _set_gpio_direction(struct gpio_bank *bank, int gpio, int is_input)
@@ -420,13 +426,16 @@ static int gpio_irq_type(struct irq_data *d, unsigned type)
420 int retval; 426 int retval;
421 unsigned long flags; 427 unsigned long flags;
422 428
429 if (WARN_ON(!bank->mod_usage))
430 return -EINVAL;
431
423#ifdef CONFIG_ARCH_OMAP1 432#ifdef CONFIG_ARCH_OMAP1
424 if (d->irq > IH_MPUIO_BASE) 433 if (d->irq > IH_MPUIO_BASE)
425 gpio = OMAP_MPUIO(d->irq - IH_MPUIO_BASE); 434 gpio = OMAP_MPUIO(d->irq - IH_MPUIO_BASE);
426#endif 435#endif
427 436
428 if (!gpio) 437 if (!gpio)
429 gpio = irq_to_gpio(bank, d->irq); 438 gpio = irq_to_gpio(bank, d->hwirq);
430 439
431 if (type & ~IRQ_TYPE_SENSE_MASK) 440 if (type & ~IRQ_TYPE_SENSE_MASK)
432 return -EINVAL; 441 return -EINVAL;
@@ -579,7 +588,7 @@ static void _reset_gpio(struct gpio_bank *bank, int gpio)
579static int gpio_wake_enable(struct irq_data *d, unsigned int enable) 588static int gpio_wake_enable(struct irq_data *d, unsigned int enable)
580{ 589{
581 struct gpio_bank *bank = irq_data_get_irq_chip_data(d); 590 struct gpio_bank *bank = irq_data_get_irq_chip_data(d);
582 unsigned int gpio = irq_to_gpio(bank, d->irq); 591 unsigned int gpio = irq_to_gpio(bank, d->hwirq);
583 592
584 return _set_gpio_wakeup(bank, gpio, enable); 593 return _set_gpio_wakeup(bank, gpio, enable);
585} 594}
@@ -679,7 +688,7 @@ static void gpio_irq_handler(unsigned int irq, struct irq_desc *desc)
679{ 688{
680 void __iomem *isr_reg = NULL; 689 void __iomem *isr_reg = NULL;
681 u32 isr; 690 u32 isr;
682 unsigned int gpio_irq, gpio_index; 691 unsigned int bit;
683 struct gpio_bank *bank; 692 struct gpio_bank *bank;
684 int unmasked = 0; 693 int unmasked = 0;
685 struct irq_chip *chip = irq_desc_get_chip(desc); 694 struct irq_chip *chip = irq_desc_get_chip(desc);
@@ -693,7 +702,7 @@ static void gpio_irq_handler(unsigned int irq, struct irq_desc *desc)
693 if (WARN_ON(!isr_reg)) 702 if (WARN_ON(!isr_reg))
694 goto exit; 703 goto exit;
695 704
696 while(1) { 705 while (1) {
697 u32 isr_saved, level_mask = 0; 706 u32 isr_saved, level_mask = 0;
698 u32 enabled; 707 u32 enabled;
699 708
@@ -720,14 +729,9 @@ static void gpio_irq_handler(unsigned int irq, struct irq_desc *desc)
720 if (!isr) 729 if (!isr)
721 break; 730 break;
722 731
723 gpio_irq = bank->irq_base; 732 while (isr) {
724 for (; isr != 0; isr >>= 1, gpio_irq++) { 733 bit = __ffs(isr);
725 int gpio = irq_to_gpio(bank, gpio_irq); 734 isr &= ~(1 << bit);
726
727 if (!(isr & 1))
728 continue;
729
730 gpio_index = GPIO_INDEX(bank, gpio);
731 735
732 /* 736 /*
733 * Some chips can't respond to both rising and falling 737 * Some chips can't respond to both rising and falling
@@ -736,10 +740,10 @@ static void gpio_irq_handler(unsigned int irq, struct irq_desc *desc)
736 * to respond to the IRQ for the opposite direction. 740 * to respond to the IRQ for the opposite direction.
737 * This will be indicated in the bank toggle_mask. 741 * This will be indicated in the bank toggle_mask.
738 */ 742 */
739 if (bank->toggle_mask & (1 << gpio_index)) 743 if (bank->toggle_mask & (1 << bit))
740 _toggle_gpio_edge_triggering(bank, gpio_index); 744 _toggle_gpio_edge_triggering(bank, bit);
741 745
742 generic_handle_irq(gpio_irq); 746 generic_handle_irq(irq_find_mapping(bank->domain, bit));
743 } 747 }
744 } 748 }
745 /* if bank has any level sensitive GPIO pin interrupt 749 /* if bank has any level sensitive GPIO pin interrupt
@@ -755,7 +759,7 @@ exit:
755static void gpio_irq_shutdown(struct irq_data *d) 759static void gpio_irq_shutdown(struct irq_data *d)
756{ 760{
757 struct gpio_bank *bank = irq_data_get_irq_chip_data(d); 761 struct gpio_bank *bank = irq_data_get_irq_chip_data(d);
758 unsigned int gpio = irq_to_gpio(bank, d->irq); 762 unsigned int gpio = irq_to_gpio(bank, d->hwirq);
759 unsigned long flags; 763 unsigned long flags;
760 764
761 spin_lock_irqsave(&bank->lock, flags); 765 spin_lock_irqsave(&bank->lock, flags);
@@ -766,7 +770,7 @@ static void gpio_irq_shutdown(struct irq_data *d)
766static void gpio_ack_irq(struct irq_data *d) 770static void gpio_ack_irq(struct irq_data *d)
767{ 771{
768 struct gpio_bank *bank = irq_data_get_irq_chip_data(d); 772 struct gpio_bank *bank = irq_data_get_irq_chip_data(d);
769 unsigned int gpio = irq_to_gpio(bank, d->irq); 773 unsigned int gpio = irq_to_gpio(bank, d->hwirq);
770 774
771 _clear_gpio_irqstatus(bank, gpio); 775 _clear_gpio_irqstatus(bank, gpio);
772} 776}
@@ -774,7 +778,7 @@ static void gpio_ack_irq(struct irq_data *d)
774static void gpio_mask_irq(struct irq_data *d) 778static void gpio_mask_irq(struct irq_data *d)
775{ 779{
776 struct gpio_bank *bank = irq_data_get_irq_chip_data(d); 780 struct gpio_bank *bank = irq_data_get_irq_chip_data(d);
777 unsigned int gpio = irq_to_gpio(bank, d->irq); 781 unsigned int gpio = irq_to_gpio(bank, d->hwirq);
778 unsigned long flags; 782 unsigned long flags;
779 783
780 spin_lock_irqsave(&bank->lock, flags); 784 spin_lock_irqsave(&bank->lock, flags);
@@ -786,7 +790,7 @@ static void gpio_mask_irq(struct irq_data *d)
786static void gpio_unmask_irq(struct irq_data *d) 790static void gpio_unmask_irq(struct irq_data *d)
787{ 791{
788 struct gpio_bank *bank = irq_data_get_irq_chip_data(d); 792 struct gpio_bank *bank = irq_data_get_irq_chip_data(d);
789 unsigned int gpio = irq_to_gpio(bank, d->irq); 793 unsigned int gpio = irq_to_gpio(bank, d->hwirq);
790 unsigned int irq_mask = GPIO_BIT(bank, gpio); 794 unsigned int irq_mask = GPIO_BIT(bank, gpio);
791 u32 trigger = irqd_get_trigger_type(d); 795 u32 trigger = irqd_get_trigger_type(d);
792 unsigned long flags; 796 unsigned long flags;
@@ -952,14 +956,6 @@ static void gpio_set(struct gpio_chip *chip, unsigned offset, int value)
952 spin_unlock_irqrestore(&bank->lock, flags); 956 spin_unlock_irqrestore(&bank->lock, flags);
953} 957}
954 958
955static int gpio_2irq(struct gpio_chip *chip, unsigned offset)
956{
957 struct gpio_bank *bank;
958
959 bank = container_of(chip, struct gpio_bank, chip);
960 return bank->irq_base + offset;
961}
962
963/*---------------------------------------------------------------------*/ 959/*---------------------------------------------------------------------*/
964 960
965static void __init omap_gpio_show_rev(struct gpio_bank *bank) 961static void __init omap_gpio_show_rev(struct gpio_bank *bank)
@@ -1056,7 +1052,7 @@ static void omap_gpio_chip_init(struct gpio_bank *bank)
1056 bank->chip.direction_output = gpio_output; 1052 bank->chip.direction_output = gpio_output;
1057 bank->chip.set_debounce = gpio_debounce; 1053 bank->chip.set_debounce = gpio_debounce;
1058 bank->chip.set = gpio_set; 1054 bank->chip.set = gpio_set;
1059 bank->chip.to_irq = gpio_2irq; 1055 bank->chip.to_irq = omap_gpio_to_irq;
1060 if (bank->is_mpuio) { 1056 if (bank->is_mpuio) {
1061 bank->chip.label = "mpuio"; 1057 bank->chip.label = "mpuio";
1062 if (bank->regs->wkup_en) 1058 if (bank->regs->wkup_en)
@@ -1071,15 +1067,16 @@ static void omap_gpio_chip_init(struct gpio_bank *bank)
1071 1067
1072 gpiochip_add(&bank->chip); 1068 gpiochip_add(&bank->chip);
1073 1069
1074 for (j = bank->irq_base; j < bank->irq_base + bank->width; j++) { 1070 for (j = 0; j < bank->width; j++) {
1075 irq_set_lockdep_class(j, &gpio_lock_class); 1071 int irq = irq_create_mapping(bank->domain, j);
1076 irq_set_chip_data(j, bank); 1072 irq_set_lockdep_class(irq, &gpio_lock_class);
1073 irq_set_chip_data(irq, bank);
1077 if (bank->is_mpuio) { 1074 if (bank->is_mpuio) {
1078 omap_mpuio_alloc_gc(bank, j, bank->width); 1075 omap_mpuio_alloc_gc(bank, irq, bank->width);
1079 } else { 1076 } else {
1080 irq_set_chip(j, &gpio_irq_chip); 1077 irq_set_chip_and_handler(irq, &gpio_irq_chip,
1081 irq_set_handler(j, handle_simple_irq); 1078 handle_simple_irq);
1082 set_irq_flags(j, IRQF_VALID); 1079 set_irq_flags(irq, IRQF_VALID);
1083 } 1080 }
1084 } 1081 }
1085 irq_set_chained_handler(bank->irq, gpio_irq_handler); 1082 irq_set_chained_handler(bank->irq, gpio_irq_handler);
@@ -1096,7 +1093,6 @@ static int omap_gpio_probe(struct platform_device *pdev)
1096 const struct omap_gpio_platform_data *pdata; 1093 const struct omap_gpio_platform_data *pdata;
1097 struct resource *res; 1094 struct resource *res;
1098 struct gpio_bank *bank; 1095 struct gpio_bank *bank;
1099 int ret = 0;
1100 1096
1101 match = of_match_device(of_match_ptr(omap_gpio_match), dev); 1097 match = of_match_device(of_match_ptr(omap_gpio_match), dev);
1102 1098
@@ -1123,20 +1119,22 @@ static int omap_gpio_probe(struct platform_device *pdev)
1123 bank->width = pdata->bank_width; 1119 bank->width = pdata->bank_width;
1124 bank->is_mpuio = pdata->is_mpuio; 1120 bank->is_mpuio = pdata->is_mpuio;
1125 bank->non_wakeup_gpios = pdata->non_wakeup_gpios; 1121 bank->non_wakeup_gpios = pdata->non_wakeup_gpios;
1126 bank->loses_context = pdata->loses_context;
1127 bank->regs = pdata->regs; 1122 bank->regs = pdata->regs;
1128#ifdef CONFIG_OF_GPIO 1123#ifdef CONFIG_OF_GPIO
1129 bank->chip.of_node = of_node_get(node); 1124 bank->chip.of_node = of_node_get(node);
1130#endif 1125#endif
1131 1126 if (node) {
1132 bank->irq_base = irq_alloc_descs(-1, 0, bank->width, 0); 1127 if (!of_property_read_bool(node, "ti,gpio-always-on"))
1133 if (bank->irq_base < 0) { 1128 bank->loses_context = true;
1134 dev_err(dev, "Couldn't allocate IRQ numbers\n"); 1129 } else {
1135 return -ENODEV; 1130 bank->loses_context = pdata->loses_context;
1136 } 1131 }
1137 1132
1138 bank->domain = irq_domain_add_legacy(node, bank->width, bank->irq_base, 1133
1139 0, &irq_domain_simple_ops, NULL); 1134 bank->domain = irq_domain_add_linear(node, bank->width,
1135 &irq_domain_simple_ops, NULL);
1136 if (!bank->domain)
1137 return -ENODEV;
1140 1138
1141 if (bank->regs->set_dataout && bank->regs->clr_dataout) 1139 if (bank->regs->set_dataout && bank->regs->clr_dataout)
1142 bank->set_dataout = _set_gpio_dataout_reg; 1140 bank->set_dataout = _set_gpio_dataout_reg;
@@ -1149,18 +1147,21 @@ static int omap_gpio_probe(struct platform_device *pdev)
1149 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 1147 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1150 if (unlikely(!res)) { 1148 if (unlikely(!res)) {
1151 dev_err(dev, "Invalid mem resource\n"); 1149 dev_err(dev, "Invalid mem resource\n");
1150 irq_domain_remove(bank->domain);
1152 return -ENODEV; 1151 return -ENODEV;
1153 } 1152 }
1154 1153
1155 if (!devm_request_mem_region(dev, res->start, resource_size(res), 1154 if (!devm_request_mem_region(dev, res->start, resource_size(res),
1156 pdev->name)) { 1155 pdev->name)) {
1157 dev_err(dev, "Region already claimed\n"); 1156 dev_err(dev, "Region already claimed\n");
1157 irq_domain_remove(bank->domain);
1158 return -EBUSY; 1158 return -EBUSY;
1159 } 1159 }
1160 1160
1161 bank->base = devm_ioremap(dev, res->start, resource_size(res)); 1161 bank->base = devm_ioremap(dev, res->start, resource_size(res));
1162 if (!bank->base) { 1162 if (!bank->base) {
1163 dev_err(dev, "Could not ioremap\n"); 1163 dev_err(dev, "Could not ioremap\n");
1164 irq_domain_remove(bank->domain);
1164 return -ENOMEM; 1165 return -ENOMEM;
1165 } 1166 }
1166 1167
@@ -1184,7 +1185,7 @@ static int omap_gpio_probe(struct platform_device *pdev)
1184 1185
1185 list_add_tail(&bank->node, &omap_gpio_list); 1186 list_add_tail(&bank->node, &omap_gpio_list);
1186 1187
1187 return ret; 1188 return 0;
1188} 1189}
1189 1190
1190#ifdef CONFIG_ARCH_OMAP2PLUS 1191#ifdef CONFIG_ARCH_OMAP2PLUS
@@ -1262,9 +1263,9 @@ static int omap_gpio_runtime_resume(struct device *dev)
1262{ 1263{
1263 struct platform_device *pdev = to_platform_device(dev); 1264 struct platform_device *pdev = to_platform_device(dev);
1264 struct gpio_bank *bank = platform_get_drvdata(pdev); 1265 struct gpio_bank *bank = platform_get_drvdata(pdev);
1265 int context_lost_cnt_after;
1266 u32 l = 0, gen, gen0, gen1; 1266 u32 l = 0, gen, gen0, gen1;
1267 unsigned long flags; 1267 unsigned long flags;
1268 int c;
1268 1269
1269 spin_lock_irqsave(&bank->lock, flags); 1270 spin_lock_irqsave(&bank->lock, flags);
1270 _gpio_dbck_enable(bank); 1271 _gpio_dbck_enable(bank);
@@ -1280,14 +1281,17 @@ static int omap_gpio_runtime_resume(struct device *dev)
1280 __raw_writel(bank->context.risingdetect, 1281 __raw_writel(bank->context.risingdetect,
1281 bank->base + bank->regs->risingdetect); 1282 bank->base + bank->regs->risingdetect);
1282 1283
1283 if (bank->get_context_loss_count) { 1284 if (bank->loses_context) {
1284 context_lost_cnt_after = 1285 if (!bank->get_context_loss_count) {
1285 bank->get_context_loss_count(bank->dev);
1286 if (context_lost_cnt_after != bank->context_loss_count) {
1287 omap_gpio_restore_context(bank); 1286 omap_gpio_restore_context(bank);
1288 } else { 1287 } else {
1289 spin_unlock_irqrestore(&bank->lock, flags); 1288 c = bank->get_context_loss_count(bank->dev);
1290 return 0; 1289 if (c != bank->context_loss_count) {
1290 omap_gpio_restore_context(bank);
1291 } else {
1292 spin_unlock_irqrestore(&bank->lock, flags);
1293 return 0;
1294 }
1291 } 1295 }
1292 } 1296 }
1293 1297
@@ -1296,10 +1300,6 @@ static int omap_gpio_runtime_resume(struct device *dev)
1296 return 0; 1300 return 0;
1297 } 1301 }
1298 1302
1299 __raw_writel(bank->context.fallingdetect,
1300 bank->base + bank->regs->fallingdetect);
1301 __raw_writel(bank->context.risingdetect,
1302 bank->base + bank->regs->risingdetect);
1303 l = __raw_readl(bank->base + bank->regs->datain); 1303 l = __raw_readl(bank->base + bank->regs->datain);
1304 1304
1305 /* 1305 /*
diff --git a/drivers/gpio/gpio-pca953x.c b/drivers/gpio/gpio-pca953x.c
index 9391cf16e990..426c51dd420c 100644
--- a/drivers/gpio/gpio-pca953x.c
+++ b/drivers/gpio/gpio-pca953x.c
@@ -146,8 +146,7 @@ static int pca953x_write_regs(struct pca953x_chip *chip, int reg, u8 *val)
146 ret = i2c_smbus_write_i2c_block_data(chip->client, 146 ret = i2c_smbus_write_i2c_block_data(chip->client,
147 (reg << bank_shift) | REG_ADDR_AI, 147 (reg << bank_shift) | REG_ADDR_AI,
148 NBANK(chip), val); 148 NBANK(chip), val);
149 } 149 } else {
150 else {
151 switch (chip->chip_type) { 150 switch (chip->chip_type) {
152 case PCA953X_TYPE: 151 case PCA953X_TYPE:
153 ret = i2c_smbus_write_word_data(chip->client, 152 ret = i2c_smbus_write_word_data(chip->client,
diff --git a/drivers/gpio/gpio-pcf857x.c b/drivers/gpio/gpio-pcf857x.c
index a19b7457a726..e8faf53f3875 100644
--- a/drivers/gpio/gpio-pcf857x.c
+++ b/drivers/gpio/gpio-pcf857x.c
@@ -45,6 +45,7 @@ static const struct i2c_device_id pcf857x_id[] = {
45 { "pca9675", 16 }, 45 { "pca9675", 16 },
46 { "max7328", 8 }, 46 { "max7328", 8 },
47 { "max7329", 8 }, 47 { "max7329", 8 },
48 { "tca9554", 8 },
48 { } 49 { }
49}; 50};
50MODULE_DEVICE_TABLE(i2c, pcf857x_id); 51MODULE_DEVICE_TABLE(i2c, pcf857x_id);
@@ -267,7 +268,7 @@ static int pcf857x_probe(struct i2c_client *client,
267 } 268 }
268 269
269 /* Allocate, initialize, and register this gpio_chip. */ 270 /* Allocate, initialize, and register this gpio_chip. */
270 gpio = kzalloc(sizeof *gpio, GFP_KERNEL); 271 gpio = devm_kzalloc(&client->dev, sizeof(*gpio), GFP_KERNEL);
271 if (!gpio) 272 if (!gpio)
272 return -ENOMEM; 273 return -ENOMEM;
273 274
@@ -390,7 +391,6 @@ fail:
390 if (pdata && client->irq) 391 if (pdata && client->irq)
391 pcf857x_irq_domain_cleanup(gpio); 392 pcf857x_irq_domain_cleanup(gpio);
392 393
393 kfree(gpio);
394 return status; 394 return status;
395} 395}
396 396
@@ -415,9 +415,7 @@ static int pcf857x_remove(struct i2c_client *client)
415 pcf857x_irq_domain_cleanup(gpio); 415 pcf857x_irq_domain_cleanup(gpio);
416 416
417 status = gpiochip_remove(&gpio->chip); 417 status = gpiochip_remove(&gpio->chip);
418 if (status == 0) 418 if (status)
419 kfree(gpio);
420 else
421 dev_err(&client->dev, "%s --> %d\n", "remove", status); 419 dev_err(&client->dev, "%s --> %d\n", "remove", status);
422 return status; 420 return status;
423} 421}
diff --git a/drivers/gpio/gpio-pxa.c b/drivers/gpio/gpio-pxa.c
index d7a5c9d75525..df2199dd1499 100644
--- a/drivers/gpio/gpio-pxa.c
+++ b/drivers/gpio/gpio-pxa.c
@@ -628,7 +628,7 @@ static int pxa_gpio_probe(struct platform_device *pdev)
628 for_each_gpio_chip(gpio, c) { 628 for_each_gpio_chip(gpio, c) {
629 writel_relaxed(0, c->regbase + GFER_OFFSET); 629 writel_relaxed(0, c->regbase + GFER_OFFSET);
630 writel_relaxed(0, c->regbase + GRER_OFFSET); 630 writel_relaxed(0, c->regbase + GRER_OFFSET);
631 writel_relaxed(~0,c->regbase + GEDR_OFFSET); 631 writel_relaxed(~0, c->regbase + GEDR_OFFSET);
632 /* unmask GPIO edge detect for AP side */ 632 /* unmask GPIO edge detect for AP side */
633 if (gpio_is_mmp_type(gpio_type)) 633 if (gpio_is_mmp_type(gpio_type))
634 writel_relaxed(~0, c->regbase + ED_MASK_OFFSET); 634 writel_relaxed(~0, c->regbase + ED_MASK_OFFSET);
@@ -712,7 +712,7 @@ static void pxa_gpio_resume(void)
712 712
713 for_each_gpio_chip(gpio, c) { 713 for_each_gpio_chip(gpio, c) {
714 /* restore level with set/clear */ 714 /* restore level with set/clear */
715 writel_relaxed( c->saved_gplr, c->regbase + GPSR_OFFSET); 715 writel_relaxed(c->saved_gplr, c->regbase + GPSR_OFFSET);
716 writel_relaxed(~c->saved_gplr, c->regbase + GPCR_OFFSET); 716 writel_relaxed(~c->saved_gplr, c->regbase + GPCR_OFFSET);
717 717
718 writel_relaxed(c->saved_grer, c->regbase + GRER_OFFSET); 718 writel_relaxed(c->saved_grer, c->regbase + GRER_OFFSET);
diff --git a/drivers/gpio/gpio-samsung.c b/drivers/gpio/gpio-samsung.c
index 99e0fa49fcbd..b22ca7933745 100644
--- a/drivers/gpio/gpio-samsung.c
+++ b/drivers/gpio/gpio-samsung.c
@@ -3030,6 +3030,7 @@ static __init int samsung_gpiolib_init(void)
3030 { .compatible = "samsung,exynos4x12-pinctrl", }, 3030 { .compatible = "samsung,exynos4x12-pinctrl", },
3031 { .compatible = "samsung,exynos5250-pinctrl", }, 3031 { .compatible = "samsung,exynos5250-pinctrl", },
3032 { .compatible = "samsung,exynos5440-pinctrl", }, 3032 { .compatible = "samsung,exynos5440-pinctrl", },
3033 { }
3033 }; 3034 };
3034 for_each_matching_node(pctrl_np, exynos_pinctrl_ids) 3035 for_each_matching_node(pctrl_np, exynos_pinctrl_ids)
3035 if (pctrl_np && of_device_is_available(pctrl_np)) 3036 if (pctrl_np && of_device_is_available(pctrl_np))
diff --git a/drivers/gpio/gpio-sch.c b/drivers/gpio/gpio-sch.c
index edae963f4625..1e4de16ceb41 100644
--- a/drivers/gpio/gpio-sch.c
+++ b/drivers/gpio/gpio-sch.c
@@ -125,13 +125,17 @@ static int sch_gpio_resume_direction_in(struct gpio_chip *gc,
125 unsigned gpio_num) 125 unsigned gpio_num)
126{ 126{
127 u8 curr_dirs; 127 u8 curr_dirs;
128 unsigned short offset, bit;
128 129
129 spin_lock(&gpio_lock); 130 spin_lock(&gpio_lock);
130 131
131 curr_dirs = inb(gpio_ba + RGIO); 132 offset = RGIO + gpio_num / 8;
133 bit = gpio_num % 8;
134
135 curr_dirs = inb(gpio_ba + offset);
132 136
133 if (!(curr_dirs & (1 << gpio_num))) 137 if (!(curr_dirs & (1 << bit)))
134 outb(curr_dirs | (1 << gpio_num) , gpio_ba + RGIO); 138 outb(curr_dirs | (1 << bit), gpio_ba + offset);
135 139
136 spin_unlock(&gpio_lock); 140 spin_unlock(&gpio_lock);
137 return 0; 141 return 0;
@@ -139,22 +143,31 @@ static int sch_gpio_resume_direction_in(struct gpio_chip *gc,
139 143
140static int sch_gpio_resume_get(struct gpio_chip *gc, unsigned gpio_num) 144static int sch_gpio_resume_get(struct gpio_chip *gc, unsigned gpio_num)
141{ 145{
142 return !!(inb(gpio_ba + RGLV) & (1 << gpio_num)); 146 unsigned short offset, bit;
147
148 offset = RGLV + gpio_num / 8;
149 bit = gpio_num % 8;
150
151 return !!(inb(gpio_ba + offset) & (1 << bit));
143} 152}
144 153
145static void sch_gpio_resume_set(struct gpio_chip *gc, 154static void sch_gpio_resume_set(struct gpio_chip *gc,
146 unsigned gpio_num, int val) 155 unsigned gpio_num, int val)
147{ 156{
148 u8 curr_vals; 157 u8 curr_vals;
158 unsigned short offset, bit;
149 159
150 spin_lock(&gpio_lock); 160 spin_lock(&gpio_lock);
151 161
152 curr_vals = inb(gpio_ba + RGLV); 162 offset = RGLV + gpio_num / 8;
163 bit = gpio_num % 8;
164
165 curr_vals = inb(gpio_ba + offset);
153 166
154 if (val) 167 if (val)
155 outb(curr_vals | (1 << gpio_num), gpio_ba + RGLV); 168 outb(curr_vals | (1 << bit), gpio_ba + offset);
156 else 169 else
157 outb((curr_vals & ~(1 << gpio_num)), gpio_ba + RGLV); 170 outb((curr_vals & ~(1 << bit)), gpio_ba + offset);
158 171
159 spin_unlock(&gpio_lock); 172 spin_unlock(&gpio_lock);
160} 173}
@@ -163,14 +176,18 @@ static int sch_gpio_resume_direction_out(struct gpio_chip *gc,
163 unsigned gpio_num, int val) 176 unsigned gpio_num, int val)
164{ 177{
165 u8 curr_dirs; 178 u8 curr_dirs;
179 unsigned short offset, bit;
166 180
167 sch_gpio_resume_set(gc, gpio_num, val); 181 sch_gpio_resume_set(gc, gpio_num, val);
168 182
183 offset = RGIO + gpio_num / 8;
184 bit = gpio_num % 8;
185
169 spin_lock(&gpio_lock); 186 spin_lock(&gpio_lock);
170 187
171 curr_dirs = inb(gpio_ba + RGIO); 188 curr_dirs = inb(gpio_ba + offset);
172 if (curr_dirs & (1 << gpio_num)) 189 if (curr_dirs & (1 << bit))
173 outb(curr_dirs & ~(1 << gpio_num), gpio_ba + RGIO); 190 outb(curr_dirs & ~(1 << bit), gpio_ba + offset);
174 191
175 spin_unlock(&gpio_lock); 192 spin_unlock(&gpio_lock);
176 return 0; 193 return 0;
@@ -204,45 +221,41 @@ static int sch_gpio_probe(struct platform_device *pdev)
204 gpio_ba = res->start; 221 gpio_ba = res->start;
205 222
206 switch (id) { 223 switch (id) {
207 case PCI_DEVICE_ID_INTEL_SCH_LPC: 224 case PCI_DEVICE_ID_INTEL_SCH_LPC:
208 sch_gpio_core.base = 0; 225 sch_gpio_core.base = 0;
209 sch_gpio_core.ngpio = 10; 226 sch_gpio_core.ngpio = 10;
210 227 sch_gpio_resume.base = 10;
211 sch_gpio_resume.base = 10; 228 sch_gpio_resume.ngpio = 4;
212 sch_gpio_resume.ngpio = 4; 229 /*
213 230 * GPIO[6:0] enabled by default
214 /* 231 * GPIO7 is configured by the CMC as SLPIOVR
215 * GPIO[6:0] enabled by default 232 * Enable GPIO[9:8] core powered gpios explicitly
216 * GPIO7 is configured by the CMC as SLPIOVR 233 */
217 * Enable GPIO[9:8] core powered gpios explicitly 234 outb(0x3, gpio_ba + CGEN + 1);
218 */ 235 /*
219 outb(0x3, gpio_ba + CGEN + 1); 236 * SUS_GPIO[2:0] enabled by default
220 /* 237 * Enable SUS_GPIO3 resume powered gpio explicitly
221 * SUS_GPIO[2:0] enabled by default 238 */
222 * Enable SUS_GPIO3 resume powered gpio explicitly 239 outb(0x8, gpio_ba + RGEN);
223 */ 240 break;
224 outb(0x8, gpio_ba + RGEN); 241
225 break; 242 case PCI_DEVICE_ID_INTEL_ITC_LPC:
226 243 sch_gpio_core.base = 0;
227 case PCI_DEVICE_ID_INTEL_ITC_LPC: 244 sch_gpio_core.ngpio = 5;
228 sch_gpio_core.base = 0; 245 sch_gpio_resume.base = 5;
229 sch_gpio_core.ngpio = 5; 246 sch_gpio_resume.ngpio = 9;
230 247 break;
231 sch_gpio_resume.base = 5; 248
232 sch_gpio_resume.ngpio = 9; 249 case PCI_DEVICE_ID_INTEL_CENTERTON_ILB:
233 break; 250 sch_gpio_core.base = 0;
234 251 sch_gpio_core.ngpio = 21;
235 case PCI_DEVICE_ID_INTEL_CENTERTON_ILB: 252 sch_gpio_resume.base = 21;
236 sch_gpio_core.base = 0; 253 sch_gpio_resume.ngpio = 9;
237 sch_gpio_core.ngpio = 21; 254 break;
238 255
239 sch_gpio_resume.base = 21; 256 default:
240 sch_gpio_resume.ngpio = 9; 257 err = -ENODEV;
241 break; 258 goto err_sch_gpio_core;
242
243 default:
244 err = -ENODEV;
245 goto err_sch_gpio_core;
246 } 259 }
247 260
248 sch_gpio_core.dev = &pdev->dev; 261 sch_gpio_core.dev = &pdev->dev;
diff --git a/drivers/gpio/gpio-stp-xway.c b/drivers/gpio/gpio-stp-xway.c
index c20e05151212..04882a911b65 100644
--- a/drivers/gpio/gpio-stp-xway.c
+++ b/drivers/gpio/gpio-stp-xway.c
@@ -217,7 +217,7 @@ static int xway_stp_probe(struct platform_device *pdev)
217 chip->virt = devm_ioremap_resource(&pdev->dev, res); 217 chip->virt = devm_ioremap_resource(&pdev->dev, res);
218 if (IS_ERR(chip->virt)) 218 if (IS_ERR(chip->virt))
219 return PTR_ERR(chip->virt); 219 return PTR_ERR(chip->virt);
220 220
221 chip->gc.dev = &pdev->dev; 221 chip->gc.dev = &pdev->dev;
222 chip->gc.label = "stp-xway"; 222 chip->gc.label = "stp-xway";
223 chip->gc.direction_output = xway_stp_dir_out; 223 chip->gc.direction_output = xway_stp_dir_out;
diff --git a/drivers/gpio/gpio-tc3589x.c b/drivers/gpio/gpio-tc3589x.c
index c0595bbf3268..d34d80dfb083 100644
--- a/drivers/gpio/gpio-tc3589x.c
+++ b/drivers/gpio/gpio-tc3589x.c
@@ -282,9 +282,9 @@ static void tc3589x_gpio_irq_unmap(struct irq_domain *d, unsigned int virq)
282} 282}
283 283
284static struct irq_domain_ops tc3589x_irq_ops = { 284static struct irq_domain_ops tc3589x_irq_ops = {
285 .map = tc3589x_gpio_irq_map, 285 .map = tc3589x_gpio_irq_map,
286 .unmap = tc3589x_gpio_irq_unmap, 286 .unmap = tc3589x_gpio_irq_unmap,
287 .xlate = irq_domain_xlate_twocell, 287 .xlate = irq_domain_xlate_twocell,
288}; 288};
289 289
290static int tc3589x_gpio_irq_init(struct tc3589x_gpio *tc3589x_gpio, 290static int tc3589x_gpio_irq_init(struct tc3589x_gpio *tc3589x_gpio,
@@ -344,7 +344,7 @@ static int tc3589x_gpio_probe(struct platform_device *pdev)
344 tc3589x_gpio->chip.base = (pdata) ? pdata->gpio_base : -1; 344 tc3589x_gpio->chip.base = (pdata) ? pdata->gpio_base : -1;
345 345
346#ifdef CONFIG_OF_GPIO 346#ifdef CONFIG_OF_GPIO
347 tc3589x_gpio->chip.of_node = np; 347 tc3589x_gpio->chip.of_node = np;
348#endif 348#endif
349 349
350 tc3589x_gpio->irq_base = tc3589x->irq_base ? 350 tc3589x_gpio->irq_base = tc3589x->irq_base ?
diff --git a/drivers/gpio/gpio-tegra.c b/drivers/gpio/gpio-tegra.c
index dde0656ea951..da4cb5b0cb87 100644
--- a/drivers/gpio/gpio-tegra.c
+++ b/drivers/gpio/gpio-tegra.c
@@ -414,10 +414,11 @@ static int tegra_gpio_probe(struct platform_device *pdev)
414 int j; 414 int j;
415 415
416 match = of_match_device(tegra_gpio_of_match, &pdev->dev); 416 match = of_match_device(tegra_gpio_of_match, &pdev->dev);
417 if (match) 417 if (!match) {
418 config = (struct tegra_gpio_soc_config *)match->data; 418 dev_err(&pdev->dev, "Error: No device match found\n");
419 else 419 return -ENODEV;
420 config = &tegra20_gpio_config; 420 }
421 config = (struct tegra_gpio_soc_config *)match->data;
421 422
422 tegra_gpio_bank_stride = config->bank_stride; 423 tegra_gpio_bank_stride = config->bank_stride;
423 tegra_gpio_upper_offset = config->upper_offset; 424 tegra_gpio_upper_offset = config->upper_offset;
@@ -478,9 +479,7 @@ static int tegra_gpio_probe(struct platform_device *pdev)
478 } 479 }
479 } 480 }
480 481
481#ifdef CONFIG_OF_GPIO
482 tegra_gpio_chip.of_node = pdev->dev.of_node; 482 tegra_gpio_chip.of_node = pdev->dev.of_node;
483#endif
484 483
485 gpiochip_add(&tegra_gpio_chip); 484 gpiochip_add(&tegra_gpio_chip);
486 485
diff --git a/drivers/gpio/gpio-timberdale.c b/drivers/gpio/gpio-timberdale.c
index 702cca9284f1..43774058b693 100644
--- a/drivers/gpio/gpio-timberdale.c
+++ b/drivers/gpio/gpio-timberdale.c
@@ -167,8 +167,7 @@ static int timbgpio_irq_type(struct irq_data *d, unsigned trigger)
167 if (ver < 3) { 167 if (ver < 3) {
168 ret = -EINVAL; 168 ret = -EINVAL;
169 goto out; 169 goto out;
170 } 170 } else {
171 else {
172 flr |= 1 << offset; 171 flr |= 1 << offset;
173 bflr |= 1 << offset; 172 bflr |= 1 << offset;
174 } 173 }
diff --git a/drivers/gpio/gpio-tps65910.c b/drivers/gpio/gpio-tps65910.c
index 5083825a0348..06146219d9d2 100644
--- a/drivers/gpio/gpio-tps65910.c
+++ b/drivers/gpio/gpio-tps65910.c
@@ -133,7 +133,7 @@ static int tps65910_gpio_probe(struct platform_device *pdev)
133 tps65910_gpio->gpio_chip.owner = THIS_MODULE; 133 tps65910_gpio->gpio_chip.owner = THIS_MODULE;
134 tps65910_gpio->gpio_chip.label = tps65910->i2c_client->name; 134 tps65910_gpio->gpio_chip.label = tps65910->i2c_client->name;
135 135
136 switch(tps65910_chip_id(tps65910)) { 136 switch (tps65910_chip_id(tps65910)) {
137 case TPS65910: 137 case TPS65910:
138 tps65910_gpio->gpio_chip.ngpio = TPS65910_NUM_GPIO; 138 tps65910_gpio->gpio_chip.ngpio = TPS65910_NUM_GPIO;
139 break; 139 break;
diff --git a/drivers/gpio/gpio-viperboard.c b/drivers/gpio/gpio-viperboard.c
index 59d72391de26..095ab14cea4d 100644
--- a/drivers/gpio/gpio-viperboard.c
+++ b/drivers/gpio/gpio-viperboard.c
@@ -380,10 +380,6 @@ static int vprbrd_gpiob_direction_output(struct gpio_chip *chip,
380 struct vprbrd *vb = gpio->vb; 380 struct vprbrd *vb = gpio->vb;
381 381
382 gpio->gpiob_out |= (1 << offset); 382 gpio->gpiob_out |= (1 << offset);
383 if (value)
384 gpio->gpiob_val |= (1 << offset);
385 else
386 gpio->gpiob_val &= ~(1 << offset);
387 383
388 mutex_lock(&vb->lock); 384 mutex_lock(&vb->lock);
389 385
diff --git a/drivers/gpio/gpiolib-acpi.c b/drivers/gpio/gpiolib-acpi.c
index a063eb04b6ce..5c1ef2b3ef18 100644
--- a/drivers/gpio/gpiolib-acpi.c
+++ b/drivers/gpio/gpiolib-acpi.c
@@ -17,6 +17,13 @@
17#include <linux/acpi.h> 17#include <linux/acpi.h>
18#include <linux/interrupt.h> 18#include <linux/interrupt.h>
19 19
20struct acpi_gpio_evt_pin {
21 struct list_head node;
22 acpi_handle *evt_handle;
23 unsigned int pin;
24 unsigned int irq;
25};
26
20static int acpi_gpiochip_find(struct gpio_chip *gc, void *data) 27static int acpi_gpiochip_find(struct gpio_chip *gc, void *data)
21{ 28{
22 if (!gc->dev) 29 if (!gc->dev)
@@ -54,7 +61,6 @@ int acpi_get_gpio(char *path, int pin)
54} 61}
55EXPORT_SYMBOL_GPL(acpi_get_gpio); 62EXPORT_SYMBOL_GPL(acpi_get_gpio);
56 63
57
58static irqreturn_t acpi_gpio_irq_handler(int irq, void *data) 64static irqreturn_t acpi_gpio_irq_handler(int irq, void *data)
59{ 65{
60 acpi_handle handle = data; 66 acpi_handle handle = data;
@@ -64,6 +70,27 @@ static irqreturn_t acpi_gpio_irq_handler(int irq, void *data)
64 return IRQ_HANDLED; 70 return IRQ_HANDLED;
65} 71}
66 72
73static irqreturn_t acpi_gpio_irq_handler_evt(int irq, void *data)
74{
75 struct acpi_gpio_evt_pin *evt_pin = data;
76 struct acpi_object_list args;
77 union acpi_object arg;
78
79 arg.type = ACPI_TYPE_INTEGER;
80 arg.integer.value = evt_pin->pin;
81 args.count = 1;
82 args.pointer = &arg;
83
84 acpi_evaluate_object(evt_pin->evt_handle, NULL, &args, NULL);
85
86 return IRQ_HANDLED;
87}
88
89static void acpi_gpio_evt_dh(acpi_handle handle, void *data)
90{
91 /* The address of this function is used as a key. */
92}
93
67/** 94/**
68 * acpi_gpiochip_request_interrupts() - Register isr for gpio chip ACPI events 95 * acpi_gpiochip_request_interrupts() - Register isr for gpio chip ACPI events
69 * @chip: gpio chip 96 * @chip: gpio chip
@@ -73,15 +100,13 @@ static irqreturn_t acpi_gpio_irq_handler(int irq, void *data)
73 * chip's interrupt handler. acpi_gpiochip_request_interrupts finds out which 100 * chip's interrupt handler. acpi_gpiochip_request_interrupts finds out which
74 * gpio pins have acpi event methods and assigns interrupt handlers that calls 101 * gpio pins have acpi event methods and assigns interrupt handlers that calls
75 * the acpi event methods for those pins. 102 * the acpi event methods for those pins.
76 *
77 * Interrupts are automatically freed on driver detach
78 */ 103 */
79
80void acpi_gpiochip_request_interrupts(struct gpio_chip *chip) 104void acpi_gpiochip_request_interrupts(struct gpio_chip *chip)
81{ 105{
82 struct acpi_buffer buf = {ACPI_ALLOCATE_BUFFER, NULL}; 106 struct acpi_buffer buf = {ACPI_ALLOCATE_BUFFER, NULL};
83 struct acpi_resource *res; 107 struct acpi_resource *res;
84 acpi_handle handle, ev_handle; 108 acpi_handle handle, evt_handle;
109 struct list_head *evt_pins = NULL;
85 acpi_status status; 110 acpi_status status;
86 unsigned int pin; 111 unsigned int pin;
87 int irq, ret; 112 int irq, ret;
@@ -98,13 +123,30 @@ void acpi_gpiochip_request_interrupts(struct gpio_chip *chip)
98 if (ACPI_FAILURE(status)) 123 if (ACPI_FAILURE(status))
99 return; 124 return;
100 125
101 /* If a gpio interrupt has an acpi event handler method, then 126 status = acpi_get_handle(handle, "_EVT", &evt_handle);
102 * set up an interrupt handler that calls the acpi event handler 127 if (ACPI_SUCCESS(status)) {
103 */ 128 evt_pins = kzalloc(sizeof(*evt_pins), GFP_KERNEL);
129 if (evt_pins) {
130 INIT_LIST_HEAD(evt_pins);
131 status = acpi_attach_data(handle, acpi_gpio_evt_dh,
132 evt_pins);
133 if (ACPI_FAILURE(status)) {
134 kfree(evt_pins);
135 evt_pins = NULL;
136 }
137 }
138 }
104 139
140 /*
141 * If a GPIO interrupt has an ACPI event handler method, or _EVT is
142 * present, set up an interrupt handler that calls the ACPI event
143 * handler.
144 */
105 for (res = buf.pointer; 145 for (res = buf.pointer;
106 res && (res->type != ACPI_RESOURCE_TYPE_END_TAG); 146 res && (res->type != ACPI_RESOURCE_TYPE_END_TAG);
107 res = ACPI_NEXT_RESOURCE(res)) { 147 res = ACPI_NEXT_RESOURCE(res)) {
148 irq_handler_t handler = NULL;
149 void *data;
108 150
109 if (res->type != ACPI_RESOURCE_TYPE_GPIO || 151 if (res->type != ACPI_RESOURCE_TYPE_GPIO ||
110 res->data.gpio.connection_type != 152 res->data.gpio.connection_type !=
@@ -115,23 +157,42 @@ void acpi_gpiochip_request_interrupts(struct gpio_chip *chip)
115 if (pin > chip->ngpio) 157 if (pin > chip->ngpio)
116 continue; 158 continue;
117 159
118 sprintf(ev_name, "_%c%02X",
119 res->data.gpio.triggering ? 'E' : 'L', pin);
120
121 status = acpi_get_handle(handle, ev_name, &ev_handle);
122 if (ACPI_FAILURE(status))
123 continue;
124
125 irq = chip->to_irq(chip, pin); 160 irq = chip->to_irq(chip, pin);
126 if (irq < 0) 161 if (irq < 0)
127 continue; 162 continue;
128 163
164 if (pin <= 255) {
165 acpi_handle ev_handle;
166
167 sprintf(ev_name, "_%c%02X",
168 res->data.gpio.triggering ? 'E' : 'L', pin);
169 status = acpi_get_handle(handle, ev_name, &ev_handle);
170 if (ACPI_SUCCESS(status)) {
171 handler = acpi_gpio_irq_handler;
172 data = ev_handle;
173 }
174 }
175 if (!handler && evt_pins) {
176 struct acpi_gpio_evt_pin *evt_pin;
177
178 evt_pin = kzalloc(sizeof(*evt_pin), GFP_KERNEL);
179 if (!evt_pin)
180 continue;
181
182 list_add_tail(&evt_pin->node, evt_pins);
183 evt_pin->evt_handle = evt_handle;
184 evt_pin->pin = pin;
185 evt_pin->irq = irq;
186 handler = acpi_gpio_irq_handler_evt;
187 data = evt_pin;
188 }
189 if (!handler)
190 continue;
191
129 /* Assume BIOS sets the triggering, so no flags */ 192 /* Assume BIOS sets the triggering, so no flags */
130 ret = devm_request_threaded_irq(chip->dev, irq, NULL, 193 ret = devm_request_threaded_irq(chip->dev, irq, NULL, handler,
131 acpi_gpio_irq_handler, 194 0, "GPIO-signaled-ACPI-event",
132 0, 195 data);
133 "GPIO-signaled-ACPI-event",
134 ev_handle);
135 if (ret) 196 if (ret)
136 dev_err(chip->dev, 197 dev_err(chip->dev,
137 "Failed to request IRQ %d ACPI event handler\n", 198 "Failed to request IRQ %d ACPI event handler\n",
@@ -139,3 +200,119 @@ void acpi_gpiochip_request_interrupts(struct gpio_chip *chip)
139 } 200 }
140} 201}
141EXPORT_SYMBOL(acpi_gpiochip_request_interrupts); 202EXPORT_SYMBOL(acpi_gpiochip_request_interrupts);
203
204struct acpi_gpio_lookup {
205 struct acpi_gpio_info info;
206 int index;
207 int gpio;
208 int n;
209};
210
211static int acpi_find_gpio(struct acpi_resource *ares, void *data)
212{
213 struct acpi_gpio_lookup *lookup = data;
214
215 if (ares->type != ACPI_RESOURCE_TYPE_GPIO)
216 return 1;
217
218 if (lookup->n++ == lookup->index && lookup->gpio < 0) {
219 const struct acpi_resource_gpio *agpio = &ares->data.gpio;
220
221 lookup->gpio = acpi_get_gpio(agpio->resource_source.string_ptr,
222 agpio->pin_table[0]);
223 lookup->info.gpioint =
224 agpio->connection_type == ACPI_RESOURCE_GPIO_TYPE_INT;
225 }
226
227 return 1;
228}
229
230/**
231 * acpi_get_gpio_by_index() - get a GPIO number from device resources
232 * @dev: pointer to a device to get GPIO from
233 * @index: index of GpioIo/GpioInt resource (starting from %0)
234 * @info: info pointer to fill in (optional)
235 *
236 * Function goes through ACPI resources for @dev and based on @index looks
237 * up a GpioIo/GpioInt resource, translates it to the Linux GPIO number,
238 * and returns it. @index matches GpioIo/GpioInt resources only so if there
239 * are total %3 GPIO resources, the index goes from %0 to %2.
240 *
241 * If the GPIO cannot be translated or there is an error, negative errno is
242 * returned.
243 *
244 * Note: if the GPIO resource has multiple entries in the pin list, this
245 * function only returns the first.
246 */
247int acpi_get_gpio_by_index(struct device *dev, int index,
248 struct acpi_gpio_info *info)
249{
250 struct acpi_gpio_lookup lookup;
251 struct list_head resource_list;
252 struct acpi_device *adev;
253 acpi_handle handle;
254 int ret;
255
256 if (!dev)
257 return -EINVAL;
258
259 handle = ACPI_HANDLE(dev);
260 if (!handle || acpi_bus_get_device(handle, &adev))
261 return -ENODEV;
262
263 memset(&lookup, 0, sizeof(lookup));
264 lookup.index = index;
265 lookup.gpio = -ENODEV;
266
267 INIT_LIST_HEAD(&resource_list);
268 ret = acpi_dev_get_resources(adev, &resource_list, acpi_find_gpio,
269 &lookup);
270 if (ret < 0)
271 return ret;
272
273 acpi_dev_free_resource_list(&resource_list);
274
275 if (lookup.gpio >= 0 && info)
276 *info = lookup.info;
277
278 return lookup.gpio;
279}
280EXPORT_SYMBOL_GPL(acpi_get_gpio_by_index);
281
282/**
283 * acpi_gpiochip_free_interrupts() - Free GPIO _EVT ACPI event interrupts.
284 * @chip: gpio chip
285 *
286 * Free interrupts associated with the _EVT method for the given GPIO chip.
287 *
288 * The remaining ACPI event interrupts associated with the chip are freed
289 * automatically.
290 */
291void acpi_gpiochip_free_interrupts(struct gpio_chip *chip)
292{
293 acpi_handle handle;
294 acpi_status status;
295 struct list_head *evt_pins;
296 struct acpi_gpio_evt_pin *evt_pin, *ep;
297
298 if (!chip->dev || !chip->to_irq)
299 return;
300
301 handle = ACPI_HANDLE(chip->dev);
302 if (!handle)
303 return;
304
305 status = acpi_get_data(handle, acpi_gpio_evt_dh, (void **)&evt_pins);
306 if (ACPI_FAILURE(status))
307 return;
308
309 list_for_each_entry_safe_reverse(evt_pin, ep, evt_pins, node) {
310 devm_free_irq(chip->dev, evt_pin->irq, evt_pin);
311 list_del(&evt_pin->node);
312 kfree(evt_pin);
313 }
314
315 acpi_detach_data(handle, acpi_gpio_evt_dh);
316 kfree(evt_pins);
317}
318EXPORT_SYMBOL(acpi_gpiochip_free_interrupts);
diff --git a/drivers/gpio/gpiolib-of.c b/drivers/gpio/gpiolib-of.c
index 465f4ca57e80..665f9530c950 100644
--- a/drivers/gpio/gpiolib-of.c
+++ b/drivers/gpio/gpiolib-of.c
@@ -61,7 +61,7 @@ static int of_gpiochip_find_and_xlate(struct gpio_chip *gc, void *data)
61 * in flags for the GPIO. 61 * in flags for the GPIO.
62 */ 62 */
63int of_get_named_gpio_flags(struct device_node *np, const char *propname, 63int of_get_named_gpio_flags(struct device_node *np, const char *propname,
64 int index, enum of_gpio_flags *flags) 64 int index, enum of_gpio_flags *flags)
65{ 65{
66 /* Return -EPROBE_DEFER to support probe() functions to be called 66 /* Return -EPROBE_DEFER to support probe() functions to be called
67 * later when the GPIO actually becomes available 67 * later when the GPIO actually becomes available