aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/gpio
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/gpio')
-rw-r--r--drivers/gpio/Kconfig35
-rw-r--r--drivers/gpio/Makefile2
-rw-r--r--drivers/gpio/gpio-amd8111.c6
-rw-r--r--drivers/gpio/gpio-dln2.c1
-rw-r--r--drivers/gpio/gpio-dwapb.c53
-rw-r--r--drivers/gpio/gpio-ge.c98
-rw-r--r--drivers/gpio/gpio-generic.c76
-rw-r--r--drivers/gpio/gpio-grgpio.c2
-rw-r--r--drivers/gpio/gpio-max732x.c225
-rw-r--r--drivers/gpio/gpio-mb86s7x.c232
-rw-r--r--drivers/gpio/gpio-mm-lantiq.c42
-rw-r--r--drivers/gpio/gpio-moxart.c101
-rw-r--r--drivers/gpio/gpio-mpc5200.c23
-rw-r--r--drivers/gpio/gpio-mpc8xxx.c72
-rw-r--r--drivers/gpio/gpio-mvebu.c100
-rw-r--r--drivers/gpio/gpio-pxa.c55
-rw-r--r--drivers/gpio/gpio-rcar.c75
-rw-r--r--drivers/gpio/gpio-sa1100.c199
-rw-r--r--drivers/gpio/gpio-sch.c89
-rw-r--r--drivers/gpio/gpio-stmpe.c23
-rw-r--r--drivers/gpio/gpio-sx150x.c251
-rw-r--r--drivers/gpio/gpio-syscon.c2
-rw-r--r--drivers/gpio/gpio-tc3589x.c15
-rw-r--r--drivers/gpio/gpio-tps65912.c14
-rw-r--r--drivers/gpio/gpio-tz1090-pdc.c2
-rw-r--r--drivers/gpio/gpio-tz1090.c2
-rw-r--r--drivers/gpio/gpio-vf610.c1
-rw-r--r--drivers/gpio/gpio-vx855.c44
-rw-r--r--drivers/gpio/gpio-xgene-sb.c160
-rw-r--r--drivers/gpio/gpio-xilinx.c284
-rw-r--r--drivers/gpio/gpio-zevio.c12
-rw-r--r--drivers/gpio/gpiolib-acpi.c10
-rw-r--r--drivers/gpio/gpiolib-of.c26
-rw-r--r--drivers/gpio/gpiolib.c8
34 files changed, 1576 insertions, 764 deletions
diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig
index 633ec216e185..c1e2ca3d9a51 100644
--- a/drivers/gpio/Kconfig
+++ b/drivers/gpio/Kconfig
@@ -197,9 +197,16 @@ config GPIO_F7188X
197 To compile this driver as a module, choose M here: the module will 197 To compile this driver as a module, choose M here: the module will
198 be called f7188x-gpio. 198 be called f7188x-gpio.
199 199
200config GPIO_MB86S7X
201 bool "GPIO support for Fujitsu MB86S7x Platforms"
202 depends on ARCH_MB86S7X
203 help
204 Say yes here to support the GPIO controller in Fujitsu MB86S70 SoCs.
205
200config GPIO_MOXART 206config GPIO_MOXART
201 bool "MOXART GPIO support" 207 bool "MOXART GPIO support"
202 depends on ARCH_MOXART 208 depends on ARCH_MOXART
209 select GPIO_GENERIC
203 help 210 help
204 Select this option to enable GPIO driver for 211 Select this option to enable GPIO driver for
205 MOXA ART SoC devices. 212 MOXA ART SoC devices.
@@ -285,6 +292,7 @@ config GPIO_PXA
285config GPIO_RCAR 292config GPIO_RCAR
286 tristate "Renesas R-Car GPIO" 293 tristate "Renesas R-Car GPIO"
287 depends on ARM && (ARCH_SHMOBILE || COMPILE_TEST) 294 depends on ARM && (ARCH_SHMOBILE || COMPILE_TEST)
295 select GPIOLIB_IRQCHIP
288 help 296 help
289 Say yes here to support GPIO on Renesas R-Car SoCs. 297 Say yes here to support GPIO on Renesas R-Car SoCs.
290 298
@@ -365,9 +373,17 @@ config GPIO_XGENE
365 the generic flash controller's address and data pins. Say yes 373 the generic flash controller's address and data pins. Say yes
366 here to enable the GFC GPIO functionality. 374 here to enable the GFC GPIO functionality.
367 375
376config GPIO_XGENE_SB
377 tristate "APM X-Gene GPIO standby controller support"
378 depends on ARCH_XGENE && OF_GPIO
379 select GPIO_GENERIC
380 help
381 This driver supports the GPIO block within the APM X-Gene
382 Standby Domain. Say yes here to enable the GPIO functionality.
383
368config GPIO_XILINX 384config GPIO_XILINX
369 bool "Xilinx GPIO support" 385 tristate "Xilinx GPIO support"
370 depends on PPC_OF || MICROBLAZE || ARCH_ZYNQ 386 depends on OF_GPIO && (PPC || MICROBLAZE || ARCH_ZYNQ || X86)
371 help 387 help
372 Say yes here to support the Xilinx FPGA GPIO device 388 Say yes here to support the Xilinx FPGA GPIO device
373 389
@@ -394,25 +410,32 @@ config GPIO_VR41XX
394 Say yes here to support the NEC VR4100 series General-purpose I/O Uint 410 Say yes here to support the NEC VR4100 series General-purpose I/O Uint
395 411
396config GPIO_SCH 412config GPIO_SCH
397 tristate "Intel SCH/TunnelCreek/Centerton GPIO" 413 tristate "Intel SCH/TunnelCreek/Centerton/Quark X1000 GPIO"
398 depends on PCI && X86 414 depends on PCI && X86
399 select MFD_CORE 415 select MFD_CORE
400 select LPC_SCH 416 select LPC_SCH
401 help 417 help
402 Say yes here to support GPIO interface on Intel Poulsbo SCH, 418 Say yes here to support GPIO interface on Intel Poulsbo SCH,
403 Intel Tunnel Creek processor or Intel Centerton processor. 419 Intel Tunnel Creek processor, Intel Centerton processor or
420 Intel Quark X1000 SoC.
421
404 The Intel SCH contains a total of 14 GPIO pins. Ten GPIOs are 422 The Intel SCH contains a total of 14 GPIO pins. Ten GPIOs are
405 powered by the core power rail and are turned off during sleep 423 powered by the core power rail and are turned off during sleep
406 modes (S3 and higher). The remaining four GPIOs are powered by 424 modes (S3 and higher). The remaining four GPIOs are powered by
407 the Intel SCH suspend power supply. These GPIOs remain 425 the Intel SCH suspend power supply. These GPIOs remain
408 active during S3. The suspend powered GPIOs can be used to wake the 426 active during S3. The suspend powered GPIOs can be used to wake the
409 system from the Suspend-to-RAM state. 427 system from the Suspend-to-RAM state.
428
410 The Intel Tunnel Creek processor has 5 GPIOs powered by the 429 The Intel Tunnel Creek processor has 5 GPIOs powered by the
411 core power rail and 9 from suspend power supply. 430 core power rail and 9 from suspend power supply.
431
412 The Intel Centerton processor has a total of 30 GPIO pins. 432 The Intel Centerton processor has a total of 30 GPIO pins.
413 Twenty-one are powered by the core power rail and 9 from the 433 Twenty-one are powered by the core power rail and 9 from the
414 suspend power supply. 434 suspend power supply.
415 435
436 The Intel Quark X1000 SoC has 2 GPIOs powered by the core
437 power well and 6 from the suspend power well.
438
416config GPIO_ICH 439config GPIO_ICH
417 tristate "Intel ICH GPIO" 440 tristate "Intel ICH GPIO"
418 depends on PCI && X86 441 depends on PCI && X86
@@ -450,6 +473,7 @@ config GPIO_VX855
450config GPIO_GE_FPGA 473config GPIO_GE_FPGA
451 bool "GE FPGA based GPIO" 474 bool "GE FPGA based GPIO"
452 depends on GE_FPGA 475 depends on GE_FPGA
476 select GPIO_GENERIC
453 help 477 help
454 Support for common GPIO functionality provided on some GE Single Board 478 Support for common GPIO functionality provided on some GE Single Board
455 Computers. 479 Computers.
@@ -519,6 +543,7 @@ config GPIO_MAX7300
519config GPIO_MAX732X 543config GPIO_MAX732X
520 tristate "MAX7319, MAX7320-7327 I2C Port Expanders" 544 tristate "MAX7319, MAX7320-7327 I2C Port Expanders"
521 depends on I2C 545 depends on I2C
546 select IRQ_DOMAIN
522 help 547 help
523 Say yes here to support the MAX7319, MAX7320-7327 series of I2C 548 Say yes here to support the MAX7319, MAX7320-7327 series of I2C
524 Port Expanders. Each IO port on these chips has a fixed role of 549 Port Expanders. Each IO port on these chips has a fixed role of
@@ -613,6 +638,7 @@ config GPIO_RC5T583
613config GPIO_SX150X 638config GPIO_SX150X
614 bool "Semtech SX150x I2C GPIO expander" 639 bool "Semtech SX150x I2C GPIO expander"
615 depends on I2C=y 640 depends on I2C=y
641 select GPIOLIB_IRQCHIP
616 default n 642 default n
617 help 643 help
618 Say yes here to provide support for Semtech SX150-series I2C 644 Say yes here to provide support for Semtech SX150-series I2C
@@ -624,6 +650,7 @@ config GPIO_SX150X
624config GPIO_STMPE 650config GPIO_STMPE
625 bool "STMPE GPIOs" 651 bool "STMPE GPIOs"
626 depends on MFD_STMPE 652 depends on MFD_STMPE
653 depends on OF_GPIO
627 select GPIOLIB_IRQCHIP 654 select GPIOLIB_IRQCHIP
628 help 655 help
629 This enables support for the GPIOs found on the STMPE I/O 656 This enables support for the GPIOs found on the STMPE I/O
diff --git a/drivers/gpio/Makefile b/drivers/gpio/Makefile
index 81755f1305e6..bdda6a94d2cd 100644
--- a/drivers/gpio/Makefile
+++ b/drivers/gpio/Makefile
@@ -48,6 +48,7 @@ obj-$(CONFIG_GPIO_MAX730X) += gpio-max730x.o
48obj-$(CONFIG_GPIO_MAX7300) += gpio-max7300.o 48obj-$(CONFIG_GPIO_MAX7300) += gpio-max7300.o
49obj-$(CONFIG_GPIO_MAX7301) += gpio-max7301.o 49obj-$(CONFIG_GPIO_MAX7301) += gpio-max7301.o
50obj-$(CONFIG_GPIO_MAX732X) += gpio-max732x.o 50obj-$(CONFIG_GPIO_MAX732X) += gpio-max732x.o
51obj-$(CONFIG_GPIO_MB86S7X) += gpio-mb86s7x.o
51obj-$(CONFIG_GPIO_MC33880) += gpio-mc33880.o 52obj-$(CONFIG_GPIO_MC33880) += gpio-mc33880.o
52obj-$(CONFIG_GPIO_MC9S08DZ60) += gpio-mc9s08dz60.o 53obj-$(CONFIG_GPIO_MC9S08DZ60) += gpio-mc9s08dz60.o
53obj-$(CONFIG_GPIO_MCP23S08) += gpio-mcp23s08.o 54obj-$(CONFIG_GPIO_MCP23S08) += gpio-mcp23s08.o
@@ -105,6 +106,7 @@ obj-$(CONFIG_GPIO_WM831X) += gpio-wm831x.o
105obj-$(CONFIG_GPIO_WM8350) += gpio-wm8350.o 106obj-$(CONFIG_GPIO_WM8350) += gpio-wm8350.o
106obj-$(CONFIG_GPIO_WM8994) += gpio-wm8994.o 107obj-$(CONFIG_GPIO_WM8994) += gpio-wm8994.o
107obj-$(CONFIG_GPIO_XGENE) += gpio-xgene.o 108obj-$(CONFIG_GPIO_XGENE) += gpio-xgene.o
109obj-$(CONFIG_GPIO_XGENE_SB) += gpio-xgene-sb.o
108obj-$(CONFIG_GPIO_XILINX) += gpio-xilinx.o 110obj-$(CONFIG_GPIO_XILINX) += gpio-xilinx.o
109obj-$(CONFIG_GPIO_XTENSA) += gpio-xtensa.o 111obj-$(CONFIG_GPIO_XTENSA) += gpio-xtensa.o
110obj-$(CONFIG_GPIO_ZEVIO) += gpio-zevio.o 112obj-$(CONFIG_GPIO_ZEVIO) += gpio-zevio.o
diff --git a/drivers/gpio/gpio-amd8111.c b/drivers/gpio/gpio-amd8111.c
index d3d2d1099f64..d00d81928fe8 100644
--- a/drivers/gpio/gpio-amd8111.c
+++ b/drivers/gpio/gpio-amd8111.c
@@ -213,6 +213,12 @@ found:
213 goto out; 213 goto out;
214 } 214 }
215 gp.pm = ioport_map(gp.pmbase + PMBASE_OFFSET, PMBASE_SIZE); 215 gp.pm = ioport_map(gp.pmbase + PMBASE_OFFSET, PMBASE_SIZE);
216 if (!gp.pm) {
217 dev_err(&pdev->dev, "Couldn't map io port into io memory\n");
218 release_region(gp.pmbase + PMBASE_OFFSET, PMBASE_SIZE);
219 err = -ENOMEM;
220 goto out;
221 }
216 gp.pdev = pdev; 222 gp.pdev = pdev;
217 gp.chip.dev = &pdev->dev; 223 gp.chip.dev = &pdev->dev;
218 224
diff --git a/drivers/gpio/gpio-dln2.c b/drivers/gpio/gpio-dln2.c
index ce3c1558cb0a..dbdb4de82c6d 100644
--- a/drivers/gpio/gpio-dln2.c
+++ b/drivers/gpio/gpio-dln2.c
@@ -396,6 +396,7 @@ static void dln2_gpio_event(struct platform_device *pdev, u16 echo,
396 const void *data, int len) 396 const void *data, int len)
397{ 397{
398 int pin, irq; 398 int pin, irq;
399
399 const struct { 400 const struct {
400 __le16 count; 401 __le16 count;
401 __u8 type; 402 __u8 type;
diff --git a/drivers/gpio/gpio-dwapb.c b/drivers/gpio/gpio-dwapb.c
index b4eb6a657d34..58faf04fce5d 100644
--- a/drivers/gpio/gpio-dwapb.c
+++ b/drivers/gpio/gpio-dwapb.c
@@ -469,15 +469,13 @@ dwapb_gpio_get_pdata_of(struct device *dev)
469 if (nports == 0) 469 if (nports == 0)
470 return ERR_PTR(-ENODEV); 470 return ERR_PTR(-ENODEV);
471 471
472 pdata = kzalloc(sizeof(*pdata), GFP_KERNEL); 472 pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL);
473 if (!pdata) 473 if (!pdata)
474 return ERR_PTR(-ENOMEM); 474 return ERR_PTR(-ENOMEM);
475 475
476 pdata->properties = kcalloc(nports, sizeof(*pp), GFP_KERNEL); 476 pdata->properties = devm_kcalloc(dev, nports, sizeof(*pp), GFP_KERNEL);
477 if (!pdata->properties) { 477 if (!pdata->properties)
478 kfree(pdata);
479 return ERR_PTR(-ENOMEM); 478 return ERR_PTR(-ENOMEM);
480 }
481 479
482 pdata->nports = nports; 480 pdata->nports = nports;
483 481
@@ -490,8 +488,6 @@ dwapb_gpio_get_pdata_of(struct device *dev)
490 pp->idx >= DWAPB_MAX_PORTS) { 488 pp->idx >= DWAPB_MAX_PORTS) {
491 dev_err(dev, "missing/invalid port index for %s\n", 489 dev_err(dev, "missing/invalid port index for %s\n",
492 port_np->full_name); 490 port_np->full_name);
493 kfree(pdata->properties);
494 kfree(pdata);
495 return ERR_PTR(-EINVAL); 491 return ERR_PTR(-EINVAL);
496 } 492 }
497 493
@@ -523,15 +519,6 @@ dwapb_gpio_get_pdata_of(struct device *dev)
523 return pdata; 519 return pdata;
524} 520}
525 521
526static inline void dwapb_free_pdata_of(struct dwapb_platform_data *pdata)
527{
528 if (!IS_ENABLED(CONFIG_OF_GPIO) || !pdata)
529 return;
530
531 kfree(pdata->properties);
532 kfree(pdata);
533}
534
535static int dwapb_gpio_probe(struct platform_device *pdev) 522static int dwapb_gpio_probe(struct platform_device *pdev)
536{ 523{
537 unsigned int i; 524 unsigned int i;
@@ -540,40 +527,32 @@ static int dwapb_gpio_probe(struct platform_device *pdev)
540 int err; 527 int err;
541 struct device *dev = &pdev->dev; 528 struct device *dev = &pdev->dev;
542 struct dwapb_platform_data *pdata = dev_get_platdata(dev); 529 struct dwapb_platform_data *pdata = dev_get_platdata(dev);
543 bool is_pdata_alloc = !pdata;
544 530
545 if (is_pdata_alloc) { 531 if (!pdata) {
546 pdata = dwapb_gpio_get_pdata_of(dev); 532 pdata = dwapb_gpio_get_pdata_of(dev);
547 if (IS_ERR(pdata)) 533 if (IS_ERR(pdata))
548 return PTR_ERR(pdata); 534 return PTR_ERR(pdata);
549 } 535 }
550 536
551 if (!pdata->nports) { 537 if (!pdata->nports)
552 err = -ENODEV; 538 return -ENODEV;
553 goto out_err;
554 }
555 539
556 gpio = devm_kzalloc(&pdev->dev, sizeof(*gpio), GFP_KERNEL); 540 gpio = devm_kzalloc(&pdev->dev, sizeof(*gpio), GFP_KERNEL);
557 if (!gpio) { 541 if (!gpio)
558 err = -ENOMEM; 542 return -ENOMEM;
559 goto out_err; 543
560 }
561 gpio->dev = &pdev->dev; 544 gpio->dev = &pdev->dev;
562 gpio->nr_ports = pdata->nports; 545 gpio->nr_ports = pdata->nports;
563 546
564 gpio->ports = devm_kcalloc(&pdev->dev, gpio->nr_ports, 547 gpio->ports = devm_kcalloc(&pdev->dev, gpio->nr_ports,
565 sizeof(*gpio->ports), GFP_KERNEL); 548 sizeof(*gpio->ports), GFP_KERNEL);
566 if (!gpio->ports) { 549 if (!gpio->ports)
567 err = -ENOMEM; 550 return -ENOMEM;
568 goto out_err;
569 }
570 551
571 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 552 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
572 gpio->regs = devm_ioremap_resource(&pdev->dev, res); 553 gpio->regs = devm_ioremap_resource(&pdev->dev, res);
573 if (IS_ERR(gpio->regs)) { 554 if (IS_ERR(gpio->regs))
574 err = PTR_ERR(gpio->regs); 555 return PTR_ERR(gpio->regs);
575 goto out_err;
576 }
577 556
578 for (i = 0; i < gpio->nr_ports; i++) { 557 for (i = 0; i < gpio->nr_ports; i++) {
579 err = dwapb_gpio_add_port(gpio, &pdata->properties[i], i); 558 err = dwapb_gpio_add_port(gpio, &pdata->properties[i], i);
@@ -582,16 +561,12 @@ static int dwapb_gpio_probe(struct platform_device *pdev)
582 } 561 }
583 platform_set_drvdata(pdev, gpio); 562 platform_set_drvdata(pdev, gpio);
584 563
585 goto out_err; 564 return 0;
586 565
587out_unregister: 566out_unregister:
588 dwapb_gpio_unregister(gpio); 567 dwapb_gpio_unregister(gpio);
589 dwapb_irq_teardown(gpio); 568 dwapb_irq_teardown(gpio);
590 569
591out_err:
592 if (is_pdata_alloc)
593 dwapb_free_pdata_of(pdata);
594
595 return err; 570 return err;
596} 571}
597 572
diff --git a/drivers/gpio/gpio-ge.c b/drivers/gpio/gpio-ge.c
index aea5c2a53cc0..f9ac3f351753 100644
--- a/drivers/gpio/gpio-ge.c
+++ b/drivers/gpio/gpio-ge.c
@@ -19,9 +19,12 @@
19 19
20#include <linux/kernel.h> 20#include <linux/kernel.h>
21#include <linux/io.h> 21#include <linux/io.h>
22#include <linux/slab.h>
22#include <linux/of_device.h> 23#include <linux/of_device.h>
23#include <linux/of_gpio.h> 24#include <linux/of_gpio.h>
25#include <linux/of_address.h>
24#include <linux/module.h> 26#include <linux/module.h>
27#include <linux/basic_mmio_gpio.h>
25 28
26#define GEF_GPIO_DIRECT 0x00 29#define GEF_GPIO_DIRECT 0x00
27#define GEF_GPIO_IN 0x04 30#define GEF_GPIO_IN 0x04
@@ -33,53 +36,6 @@
33#define GEF_GPIO_OVERRUN 0x1C 36#define GEF_GPIO_OVERRUN 0x1C
34#define GEF_GPIO_MODE 0x20 37#define GEF_GPIO_MODE 0x20
35 38
36static void gef_gpio_set(struct gpio_chip *chip, unsigned offset, int value)
37{
38 struct of_mm_gpio_chip *mmchip = to_of_mm_gpio_chip(chip);
39 unsigned int data;
40
41 data = ioread32be(mmchip->regs + GEF_GPIO_OUT);
42 if (value)
43 data = data | BIT(offset);
44 else
45 data = data & ~BIT(offset);
46 iowrite32be(data, mmchip->regs + GEF_GPIO_OUT);
47}
48
49static int gef_gpio_dir_in(struct gpio_chip *chip, unsigned offset)
50{
51 unsigned int data;
52 struct of_mm_gpio_chip *mmchip = to_of_mm_gpio_chip(chip);
53
54 data = ioread32be(mmchip->regs + GEF_GPIO_DIRECT);
55 data = data | BIT(offset);
56 iowrite32be(data, mmchip->regs + GEF_GPIO_DIRECT);
57
58 return 0;
59}
60
61static int gef_gpio_dir_out(struct gpio_chip *chip, unsigned offset, int value)
62{
63 unsigned int data;
64 struct of_mm_gpio_chip *mmchip = to_of_mm_gpio_chip(chip);
65
66 /* Set value before switching to output */
67 gef_gpio_set(mmchip->regs + GEF_GPIO_OUT, offset, value);
68
69 data = ioread32be(mmchip->regs + GEF_GPIO_DIRECT);
70 data = data & ~BIT(offset);
71 iowrite32be(data, mmchip->regs + GEF_GPIO_DIRECT);
72
73 return 0;
74}
75
76static int gef_gpio_get(struct gpio_chip *chip, unsigned offset)
77{
78 struct of_mm_gpio_chip *mmchip = to_of_mm_gpio_chip(chip);
79
80 return !!(ioread32be(mmchip->regs + GEF_GPIO_IN) & BIT(offset));
81}
82
83static const struct of_device_id gef_gpio_ids[] = { 39static const struct of_device_id gef_gpio_ids[] = {
84 { 40 {
85 .compatible = "gef,sbc610-gpio", 41 .compatible = "gef,sbc610-gpio",
@@ -99,22 +55,50 @@ static int __init gef_gpio_probe(struct platform_device *pdev)
99{ 55{
100 const struct of_device_id *of_id = 56 const struct of_device_id *of_id =
101 of_match_device(gef_gpio_ids, &pdev->dev); 57 of_match_device(gef_gpio_ids, &pdev->dev);
102 struct of_mm_gpio_chip *mmchip; 58 struct bgpio_chip *bgc;
59 void __iomem *regs;
60 int ret;
103 61
104 mmchip = devm_kzalloc(&pdev->dev, sizeof(*mmchip), GFP_KERNEL); 62 bgc = devm_kzalloc(&pdev->dev, sizeof(*bgc), GFP_KERNEL);
105 if (!mmchip) 63 if (!bgc)
106 return -ENOMEM; 64 return -ENOMEM;
107 65
66 regs = of_iomap(pdev->dev.of_node, 0);
67 if (!regs)
68 return -ENOMEM;
69
70 ret = bgpio_init(bgc, &pdev->dev, 4, regs + GEF_GPIO_IN,
71 regs + GEF_GPIO_OUT, NULL, NULL,
72 regs + GEF_GPIO_DIRECT, BGPIOF_BIG_ENDIAN_BYTE_ORDER);
73 if (ret) {
74 dev_err(&pdev->dev, "bgpio_init failed\n");
75 goto err0;
76 }
77
108 /* Setup pointers to chip functions */ 78 /* Setup pointers to chip functions */
109 mmchip->gc.ngpio = (u16)(uintptr_t)of_id->data; 79 bgc->gc.label = devm_kstrdup(&pdev->dev, pdev->dev.of_node->full_name,
110 mmchip->gc.of_gpio_n_cells = 2; 80 GFP_KERNEL);
111 mmchip->gc.direction_input = gef_gpio_dir_in; 81 if (!bgc->gc.label) {
112 mmchip->gc.direction_output = gef_gpio_dir_out; 82 ret = -ENOMEM;
113 mmchip->gc.get = gef_gpio_get; 83 goto err0;
114 mmchip->gc.set = gef_gpio_set; 84 }
85
86 bgc->gc.base = -1;
87 bgc->gc.ngpio = (u16)(uintptr_t)of_id->data;
88 bgc->gc.of_gpio_n_cells = 2;
89 bgc->gc.of_node = pdev->dev.of_node;
115 90
116 /* This function adds a memory mapped GPIO chip */ 91 /* This function adds a memory mapped GPIO chip */
117 return of_mm_gpiochip_add(pdev->dev.of_node, mmchip); 92 ret = gpiochip_add(&bgc->gc);
93 if (ret)
94 goto err0;
95
96 return 0;
97err0:
98 iounmap(regs);
99 pr_err("%s: GPIO chip registration failed\n",
100 pdev->dev.of_node->full_name);
101 return ret;
118}; 102};
119 103
120static struct platform_driver gef_gpio_driver = { 104static struct platform_driver gef_gpio_driver = {
diff --git a/drivers/gpio/gpio-generic.c b/drivers/gpio/gpio-generic.c
index 16f6115e5bdb..b92a690f5765 100644
--- a/drivers/gpio/gpio-generic.c
+++ b/drivers/gpio/gpio-generic.c
@@ -190,6 +190,79 @@ static void bgpio_set_set(struct gpio_chip *gc, unsigned int gpio, int val)
190 spin_unlock_irqrestore(&bgc->lock, flags); 190 spin_unlock_irqrestore(&bgc->lock, flags);
191} 191}
192 192
193static void bgpio_multiple_get_masks(struct bgpio_chip *bgc,
194 unsigned long *mask, unsigned long *bits,
195 unsigned long *set_mask,
196 unsigned long *clear_mask)
197{
198 int i;
199
200 *set_mask = 0;
201 *clear_mask = 0;
202
203 for (i = 0; i < bgc->bits; i++) {
204 if (*mask == 0)
205 break;
206 if (__test_and_clear_bit(i, mask)) {
207 if (test_bit(i, bits))
208 *set_mask |= bgc->pin2mask(bgc, i);
209 else
210 *clear_mask |= bgc->pin2mask(bgc, i);
211 }
212 }
213}
214
215static void bgpio_set_multiple_single_reg(struct bgpio_chip *bgc,
216 unsigned long *mask,
217 unsigned long *bits,
218 void __iomem *reg)
219{
220 unsigned long flags;
221 unsigned long set_mask, clear_mask;
222
223 spin_lock_irqsave(&bgc->lock, flags);
224
225 bgpio_multiple_get_masks(bgc, mask, bits, &set_mask, &clear_mask);
226
227 bgc->data |= set_mask;
228 bgc->data &= ~clear_mask;
229
230 bgc->write_reg(reg, bgc->data);
231
232 spin_unlock_irqrestore(&bgc->lock, flags);
233}
234
235static void bgpio_set_multiple(struct gpio_chip *gc, unsigned long *mask,
236 unsigned long *bits)
237{
238 struct bgpio_chip *bgc = to_bgpio_chip(gc);
239
240 bgpio_set_multiple_single_reg(bgc, mask, bits, bgc->reg_dat);
241}
242
243static void bgpio_set_multiple_set(struct gpio_chip *gc, unsigned long *mask,
244 unsigned long *bits)
245{
246 struct bgpio_chip *bgc = to_bgpio_chip(gc);
247
248 bgpio_set_multiple_single_reg(bgc, mask, bits, bgc->reg_set);
249}
250
251static void bgpio_set_multiple_with_clear(struct gpio_chip *gc,
252 unsigned long *mask,
253 unsigned long *bits)
254{
255 struct bgpio_chip *bgc = to_bgpio_chip(gc);
256 unsigned long set_mask, clear_mask;
257
258 bgpio_multiple_get_masks(bgc, mask, bits, &set_mask, &clear_mask);
259
260 if (set_mask)
261 bgc->write_reg(bgc->reg_set, set_mask);
262 if (clear_mask)
263 bgc->write_reg(bgc->reg_clr, clear_mask);
264}
265
193static int bgpio_simple_dir_in(struct gpio_chip *gc, unsigned int gpio) 266static int bgpio_simple_dir_in(struct gpio_chip *gc, unsigned int gpio)
194{ 267{
195 return 0; 268 return 0;
@@ -354,11 +427,14 @@ static int bgpio_setup_io(struct bgpio_chip *bgc,
354 bgc->reg_set = set; 427 bgc->reg_set = set;
355 bgc->reg_clr = clr; 428 bgc->reg_clr = clr;
356 bgc->gc.set = bgpio_set_with_clear; 429 bgc->gc.set = bgpio_set_with_clear;
430 bgc->gc.set_multiple = bgpio_set_multiple_with_clear;
357 } else if (set && !clr) { 431 } else if (set && !clr) {
358 bgc->reg_set = set; 432 bgc->reg_set = set;
359 bgc->gc.set = bgpio_set_set; 433 bgc->gc.set = bgpio_set_set;
434 bgc->gc.set_multiple = bgpio_set_multiple_set;
360 } else { 435 } else {
361 bgc->gc.set = bgpio_set; 436 bgc->gc.set = bgpio_set;
437 bgc->gc.set_multiple = bgpio_set_multiple;
362 } 438 }
363 439
364 bgc->gc.get = bgpio_get; 440 bgc->gc.get = bgpio_get;
diff --git a/drivers/gpio/gpio-grgpio.c b/drivers/gpio/gpio-grgpio.c
index 3a5a71050559..35a02770c8b0 100644
--- a/drivers/gpio/gpio-grgpio.c
+++ b/drivers/gpio/gpio-grgpio.c
@@ -121,7 +121,7 @@ static int grgpio_to_irq(struct gpio_chip *gc, unsigned offset)
121{ 121{
122 struct grgpio_priv *priv = grgpio_gc_to_priv(gc); 122 struct grgpio_priv *priv = grgpio_gc_to_priv(gc);
123 123
124 if (offset > gc->ngpio) 124 if (offset >= gc->ngpio)
125 return -ENXIO; 125 return -ENXIO;
126 126
127 if (priv->lirqs[offset].index < 0) 127 if (priv->lirqs[offset].index < 0)
diff --git a/drivers/gpio/gpio-max732x.c b/drivers/gpio/gpio-max732x.c
index 6c676225b886..a095b2393fe9 100644
--- a/drivers/gpio/gpio-max732x.c
+++ b/drivers/gpio/gpio-max732x.c
@@ -19,8 +19,10 @@
19#include <linux/gpio.h> 19#include <linux/gpio.h>
20#include <linux/interrupt.h> 20#include <linux/interrupt.h>
21#include <linux/irq.h> 21#include <linux/irq.h>
22#include <linux/irqdomain.h>
22#include <linux/i2c.h> 23#include <linux/i2c.h>
23#include <linux/i2c/max732x.h> 24#include <linux/i2c/max732x.h>
25#include <linux/of.h>
24 26
25 27
26/* 28/*
@@ -116,6 +118,22 @@ static const struct i2c_device_id max732x_id[] = {
116}; 118};
117MODULE_DEVICE_TABLE(i2c, max732x_id); 119MODULE_DEVICE_TABLE(i2c, max732x_id);
118 120
121#ifdef CONFIG_OF
122static const struct of_device_id max732x_of_table[] = {
123 { .compatible = "maxim,max7319" },
124 { .compatible = "maxim,max7320" },
125 { .compatible = "maxim,max7321" },
126 { .compatible = "maxim,max7322" },
127 { .compatible = "maxim,max7323" },
128 { .compatible = "maxim,max7324" },
129 { .compatible = "maxim,max7325" },
130 { .compatible = "maxim,max7326" },
131 { .compatible = "maxim,max7327" },
132 { }
133};
134MODULE_DEVICE_TABLE(of, max732x_of_table);
135#endif
136
119struct max732x_chip { 137struct max732x_chip {
120 struct gpio_chip gpio_chip; 138 struct gpio_chip gpio_chip;
121 139
@@ -132,16 +150,22 @@ struct max732x_chip {
132 uint8_t reg_out[2]; 150 uint8_t reg_out[2];
133 151
134#ifdef CONFIG_GPIO_MAX732X_IRQ 152#ifdef CONFIG_GPIO_MAX732X_IRQ
135 struct mutex irq_lock; 153 struct irq_domain *irq_domain;
136 int irq_base; 154 struct mutex irq_lock;
137 uint8_t irq_mask; 155 int irq_base;
138 uint8_t irq_mask_cur; 156 uint8_t irq_mask;
139 uint8_t irq_trig_raise; 157 uint8_t irq_mask_cur;
140 uint8_t irq_trig_fall; 158 uint8_t irq_trig_raise;
141 uint8_t irq_features; 159 uint8_t irq_trig_fall;
160 uint8_t irq_features;
142#endif 161#endif
143}; 162};
144 163
164static inline struct max732x_chip *to_max732x(struct gpio_chip *gc)
165{
166 return container_of(gc, struct max732x_chip, gpio_chip);
167}
168
145static int max732x_writeb(struct max732x_chip *chip, int group_a, uint8_t val) 169static int max732x_writeb(struct max732x_chip *chip, int group_a, uint8_t val)
146{ 170{
147 struct i2c_client *client; 171 struct i2c_client *client;
@@ -180,12 +204,10 @@ static inline int is_group_a(struct max732x_chip *chip, unsigned off)
180 204
181static int max732x_gpio_get_value(struct gpio_chip *gc, unsigned off) 205static int max732x_gpio_get_value(struct gpio_chip *gc, unsigned off)
182{ 206{
183 struct max732x_chip *chip; 207 struct max732x_chip *chip = to_max732x(gc);
184 uint8_t reg_val; 208 uint8_t reg_val;
185 int ret; 209 int ret;
186 210
187 chip = container_of(gc, struct max732x_chip, gpio_chip);
188
189 ret = max732x_readb(chip, is_group_a(chip, off), &reg_val); 211 ret = max732x_readb(chip, is_group_a(chip, off), &reg_val);
190 if (ret < 0) 212 if (ret < 0)
191 return 0; 213 return 0;
@@ -193,18 +215,17 @@ static int max732x_gpio_get_value(struct gpio_chip *gc, unsigned off)
193 return reg_val & (1u << (off & 0x7)); 215 return reg_val & (1u << (off & 0x7));
194} 216}
195 217
196static void max732x_gpio_set_value(struct gpio_chip *gc, unsigned off, int val) 218static void max732x_gpio_set_mask(struct gpio_chip *gc, unsigned off, int mask,
219 int val)
197{ 220{
198 struct max732x_chip *chip; 221 struct max732x_chip *chip = to_max732x(gc);
199 uint8_t reg_out, mask = 1u << (off & 0x7); 222 uint8_t reg_out;
200 int ret; 223 int ret;
201 224
202 chip = container_of(gc, struct max732x_chip, gpio_chip);
203
204 mutex_lock(&chip->lock); 225 mutex_lock(&chip->lock);
205 226
206 reg_out = (off > 7) ? chip->reg_out[1] : chip->reg_out[0]; 227 reg_out = (off > 7) ? chip->reg_out[1] : chip->reg_out[0];
207 reg_out = (val) ? reg_out | mask : reg_out & ~mask; 228 reg_out = (reg_out & ~mask) | (val & mask);
208 229
209 ret = max732x_writeb(chip, is_group_a(chip, off), reg_out); 230 ret = max732x_writeb(chip, is_group_a(chip, off), reg_out);
210 if (ret < 0) 231 if (ret < 0)
@@ -219,13 +240,31 @@ out:
219 mutex_unlock(&chip->lock); 240 mutex_unlock(&chip->lock);
220} 241}
221 242
243static void max732x_gpio_set_value(struct gpio_chip *gc, unsigned off, int val)
244{
245 unsigned base = off & ~0x7;
246 uint8_t mask = 1u << (off & 0x7);
247
248 max732x_gpio_set_mask(gc, base, mask, val << (off & 0x7));
249}
250
251static void max732x_gpio_set_multiple(struct gpio_chip *gc,
252 unsigned long *mask, unsigned long *bits)
253{
254 unsigned mask_lo = mask[0] & 0xff;
255 unsigned mask_hi = (mask[0] >> 8) & 0xff;
256
257 if (mask_lo)
258 max732x_gpio_set_mask(gc, 0, mask_lo, bits[0] & 0xff);
259 if (mask_hi)
260 max732x_gpio_set_mask(gc, 8, mask_hi, (bits[0] >> 8) & 0xff);
261}
262
222static int max732x_gpio_direction_input(struct gpio_chip *gc, unsigned off) 263static int max732x_gpio_direction_input(struct gpio_chip *gc, unsigned off)
223{ 264{
224 struct max732x_chip *chip; 265 struct max732x_chip *chip = to_max732x(gc);
225 unsigned int mask = 1u << off; 266 unsigned int mask = 1u << off;
226 267
227 chip = container_of(gc, struct max732x_chip, gpio_chip);
228
229 if ((mask & chip->dir_input) == 0) { 268 if ((mask & chip->dir_input) == 0) {
230 dev_dbg(&chip->client->dev, "%s port %d is output only\n", 269 dev_dbg(&chip->client->dev, "%s port %d is output only\n",
231 chip->client->name, off); 270 chip->client->name, off);
@@ -245,11 +284,9 @@ static int max732x_gpio_direction_input(struct gpio_chip *gc, unsigned off)
245static int max732x_gpio_direction_output(struct gpio_chip *gc, 284static int max732x_gpio_direction_output(struct gpio_chip *gc,
246 unsigned off, int val) 285 unsigned off, int val)
247{ 286{
248 struct max732x_chip *chip; 287 struct max732x_chip *chip = to_max732x(gc);
249 unsigned int mask = 1u << off; 288 unsigned int mask = 1u << off;
250 289
251 chip = container_of(gc, struct max732x_chip, gpio_chip);
252
253 if ((mask & chip->dir_output) == 0) { 290 if ((mask & chip->dir_output) == 0) {
254 dev_dbg(&chip->client->dev, "%s port %d is input only\n", 291 dev_dbg(&chip->client->dev, "%s port %d is input only\n",
255 chip->client->name, off); 292 chip->client->name, off);
@@ -321,24 +358,28 @@ static void max732x_irq_update_mask(struct max732x_chip *chip)
321 358
322static int max732x_gpio_to_irq(struct gpio_chip *gc, unsigned off) 359static int max732x_gpio_to_irq(struct gpio_chip *gc, unsigned off)
323{ 360{
324 struct max732x_chip *chip; 361 struct max732x_chip *chip = to_max732x(gc);
325 362
326 chip = container_of(gc, struct max732x_chip, gpio_chip); 363 if (chip->irq_domain) {
327 return chip->irq_base + off; 364 return irq_create_mapping(chip->irq_domain,
365 chip->irq_base + off);
366 } else {
367 return -ENXIO;
368 }
328} 369}
329 370
330static void max732x_irq_mask(struct irq_data *d) 371static void max732x_irq_mask(struct irq_data *d)
331{ 372{
332 struct max732x_chip *chip = irq_data_get_irq_chip_data(d); 373 struct max732x_chip *chip = irq_data_get_irq_chip_data(d);
333 374
334 chip->irq_mask_cur &= ~(1 << (d->irq - chip->irq_base)); 375 chip->irq_mask_cur &= ~(1 << d->hwirq);
335} 376}
336 377
337static void max732x_irq_unmask(struct irq_data *d) 378static void max732x_irq_unmask(struct irq_data *d)
338{ 379{
339 struct max732x_chip *chip = irq_data_get_irq_chip_data(d); 380 struct max732x_chip *chip = irq_data_get_irq_chip_data(d);
340 381
341 chip->irq_mask_cur |= 1 << (d->irq - chip->irq_base); 382 chip->irq_mask_cur |= 1 << d->hwirq;
342} 383}
343 384
344static void max732x_irq_bus_lock(struct irq_data *d) 385static void max732x_irq_bus_lock(struct irq_data *d)
@@ -352,15 +393,25 @@ static void max732x_irq_bus_lock(struct irq_data *d)
352static void max732x_irq_bus_sync_unlock(struct irq_data *d) 393static void max732x_irq_bus_sync_unlock(struct irq_data *d)
353{ 394{
354 struct max732x_chip *chip = irq_data_get_irq_chip_data(d); 395 struct max732x_chip *chip = irq_data_get_irq_chip_data(d);
396 uint16_t new_irqs;
397 uint16_t level;
355 398
356 max732x_irq_update_mask(chip); 399 max732x_irq_update_mask(chip);
400
401 new_irqs = chip->irq_trig_fall | chip->irq_trig_raise;
402 while (new_irqs) {
403 level = __ffs(new_irqs);
404 max732x_gpio_direction_input(&chip->gpio_chip, level);
405 new_irqs &= ~(1 << level);
406 }
407
357 mutex_unlock(&chip->irq_lock); 408 mutex_unlock(&chip->irq_lock);
358} 409}
359 410
360static int max732x_irq_set_type(struct irq_data *d, unsigned int type) 411static int max732x_irq_set_type(struct irq_data *d, unsigned int type)
361{ 412{
362 struct max732x_chip *chip = irq_data_get_irq_chip_data(d); 413 struct max732x_chip *chip = irq_data_get_irq_chip_data(d);
363 uint16_t off = d->irq - chip->irq_base; 414 uint16_t off = d->hwirq;
364 uint16_t mask = 1 << off; 415 uint16_t mask = 1 << off;
365 416
366 if (!(mask & chip->dir_input)) { 417 if (!(mask & chip->dir_input)) {
@@ -385,7 +436,7 @@ static int max732x_irq_set_type(struct irq_data *d, unsigned int type)
385 else 436 else
386 chip->irq_trig_raise &= ~mask; 437 chip->irq_trig_raise &= ~mask;
387 438
388 return max732x_gpio_direction_input(&chip->gpio_chip, off); 439 return 0;
389} 440}
390 441
391static struct irq_chip max732x_irq_chip = { 442static struct irq_chip max732x_irq_chip = {
@@ -441,7 +492,7 @@ static irqreturn_t max732x_irq_handler(int irq, void *devid)
441 492
442 do { 493 do {
443 level = __ffs(pending); 494 level = __ffs(pending);
444 handle_nested_irq(level + chip->irq_base); 495 handle_nested_irq(irq_find_mapping(chip->irq_domain, level));
445 496
446 pending &= ~(1 << level); 497 pending &= ~(1 << level);
447 } while (pending); 498 } while (pending);
@@ -449,6 +500,44 @@ static irqreturn_t max732x_irq_handler(int irq, void *devid)
449 return IRQ_HANDLED; 500 return IRQ_HANDLED;
450} 501}
451 502
503static int max732x_irq_map(struct irq_domain *h, unsigned int virq,
504 irq_hw_number_t hw)
505{
506 struct max732x_chip *chip = h->host_data;
507
508 if (!(chip->dir_input & (1 << hw))) {
509 dev_err(&chip->client->dev,
510 "Attempt to map output line as IRQ line: %lu\n",
511 hw);
512 return -EPERM;
513 }
514
515 irq_set_chip_data(virq, chip);
516 irq_set_chip_and_handler(virq, &max732x_irq_chip,
517 handle_edge_irq);
518 irq_set_nested_thread(virq, 1);
519#ifdef CONFIG_ARM
520 /* ARM needs us to explicitly flag the IRQ as valid
521 * and will set them noprobe when we do so. */
522 set_irq_flags(virq, IRQF_VALID);
523#else
524 irq_set_noprobe(virq);
525#endif
526
527 return 0;
528}
529
530static struct irq_domain_ops max732x_irq_domain_ops = {
531 .map = max732x_irq_map,
532 .xlate = irq_domain_xlate_twocell,
533};
534
535static void max732x_irq_teardown(struct max732x_chip *chip)
536{
537 if (chip->client->irq && chip->irq_domain)
538 irq_domain_remove(chip->irq_domain);
539}
540
452static int max732x_irq_setup(struct max732x_chip *chip, 541static int max732x_irq_setup(struct max732x_chip *chip,
453 const struct i2c_device_id *id) 542 const struct i2c_device_id *id)
454{ 543{
@@ -457,28 +546,19 @@ static int max732x_irq_setup(struct max732x_chip *chip,
457 int has_irq = max732x_features[id->driver_data] >> 32; 546 int has_irq = max732x_features[id->driver_data] >> 32;
458 int ret; 547 int ret;
459 548
460 if (pdata->irq_base && has_irq != INT_NONE) { 549 if (((pdata && pdata->irq_base) || client->irq)
461 int lvl; 550 && has_irq != INT_NONE) {
462 551 if (pdata)
463 chip->irq_base = pdata->irq_base; 552 chip->irq_base = pdata->irq_base;
464 chip->irq_features = has_irq; 553 chip->irq_features = has_irq;
465 mutex_init(&chip->irq_lock); 554 mutex_init(&chip->irq_lock);
466 555
467 for (lvl = 0; lvl < chip->gpio_chip.ngpio; lvl++) { 556 chip->irq_domain = irq_domain_add_simple(client->dev.of_node,
468 int irq = lvl + chip->irq_base; 557 chip->gpio_chip.ngpio, chip->irq_base,
469 558 &max732x_irq_domain_ops, chip);
470 if (!(chip->dir_input & (1 << lvl))) 559 if (!chip->irq_domain) {
471 continue; 560 dev_err(&client->dev, "Failed to create IRQ domain\n");
472 561 return -ENOMEM;
473 irq_set_chip_data(irq, chip);
474 irq_set_chip_and_handler(irq, &max732x_irq_chip,
475 handle_edge_irq);
476 irq_set_nested_thread(irq, 1);
477#ifdef CONFIG_ARM
478 set_irq_flags(irq, IRQF_VALID);
479#else
480 irq_set_noprobe(irq);
481#endif
482 } 562 }
483 563
484 ret = request_threaded_irq(client->irq, 564 ret = request_threaded_irq(client->irq,
@@ -498,15 +578,10 @@ static int max732x_irq_setup(struct max732x_chip *chip,
498 return 0; 578 return 0;
499 579
500out_failed: 580out_failed:
501 chip->irq_base = 0; 581 max732x_irq_teardown(chip);
502 return ret; 582 return ret;
503} 583}
504 584
505static void max732x_irq_teardown(struct max732x_chip *chip)
506{
507 if (chip->irq_base)
508 free_irq(chip->client->irq, chip);
509}
510#else /* CONFIG_GPIO_MAX732X_IRQ */ 585#else /* CONFIG_GPIO_MAX732X_IRQ */
511static int max732x_irq_setup(struct max732x_chip *chip, 586static int max732x_irq_setup(struct max732x_chip *chip,
512 const struct i2c_device_id *id) 587 const struct i2c_device_id *id)
@@ -515,7 +590,7 @@ static int max732x_irq_setup(struct max732x_chip *chip,
515 struct max732x_platform_data *pdata = dev_get_platdata(&client->dev); 590 struct max732x_platform_data *pdata = dev_get_platdata(&client->dev);
516 int has_irq = max732x_features[id->driver_data] >> 32; 591 int has_irq = max732x_features[id->driver_data] >> 32;
517 592
518 if (pdata->irq_base && has_irq != INT_NONE) 593 if (((pdata && pdata->irq_base) || client->irq) && has_irq != INT_NONE)
519 dev_warn(&client->dev, "interrupt support not compiled in\n"); 594 dev_warn(&client->dev, "interrupt support not compiled in\n");
520 595
521 return 0; 596 return 0;
@@ -562,6 +637,7 @@ static int max732x_setup_gpio(struct max732x_chip *chip,
562 if (chip->dir_output) { 637 if (chip->dir_output) {
563 gc->direction_output = max732x_gpio_direction_output; 638 gc->direction_output = max732x_gpio_direction_output;
564 gc->set = max732x_gpio_set_value; 639 gc->set = max732x_gpio_set_value;
640 gc->set_multiple = max732x_gpio_set_multiple;
565 } 641 }
566 gc->get = max732x_gpio_get_value; 642 gc->get = max732x_gpio_get_value;
567 gc->can_sleep = true; 643 gc->can_sleep = true;
@@ -574,28 +650,47 @@ static int max732x_setup_gpio(struct max732x_chip *chip,
574 return port; 650 return port;
575} 651}
576 652
653static struct max732x_platform_data *of_gpio_max732x(struct device *dev)
654{
655 struct max732x_platform_data *pdata;
656
657 pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL);
658 if (!pdata)
659 return NULL;
660
661 pdata->gpio_base = -1;
662
663 return pdata;
664}
665
577static int max732x_probe(struct i2c_client *client, 666static int max732x_probe(struct i2c_client *client,
578 const struct i2c_device_id *id) 667 const struct i2c_device_id *id)
579{ 668{
580 struct max732x_platform_data *pdata; 669 struct max732x_platform_data *pdata;
670 struct device_node *node;
581 struct max732x_chip *chip; 671 struct max732x_chip *chip;
582 struct i2c_client *c; 672 struct i2c_client *c;
583 uint16_t addr_a, addr_b; 673 uint16_t addr_a, addr_b;
584 int ret, nr_port; 674 int ret, nr_port;
585 675
586 pdata = dev_get_platdata(&client->dev); 676 pdata = dev_get_platdata(&client->dev);
587 if (pdata == NULL) { 677 node = client->dev.of_node;
678
679 if (!pdata && node)
680 pdata = of_gpio_max732x(&client->dev);
681
682 if (!pdata) {
588 dev_dbg(&client->dev, "no platform data\n"); 683 dev_dbg(&client->dev, "no platform data\n");
589 return -EINVAL; 684 return -EINVAL;
590 } 685 }
591 686
592 chip = devm_kzalloc(&client->dev, sizeof(struct max732x_chip), 687 chip = devm_kzalloc(&client->dev, sizeof(*chip), GFP_KERNEL);
593 GFP_KERNEL);
594 if (chip == NULL) 688 if (chip == NULL)
595 return -ENOMEM; 689 return -ENOMEM;
596 chip->client = client; 690 chip->client = client;
597 691
598 nr_port = max732x_setup_gpio(chip, id, pdata->gpio_base); 692 nr_port = max732x_setup_gpio(chip, id, pdata->gpio_base);
693 chip->gpio_chip.dev = &client->dev;
599 694
600 addr_a = (client->addr & 0x0f) | 0x60; 695 addr_a = (client->addr & 0x0f) | 0x60;
601 addr_b = (client->addr & 0x0f) | 0x50; 696 addr_b = (client->addr & 0x0f) | 0x50;
@@ -643,7 +738,7 @@ static int max732x_probe(struct i2c_client *client,
643 if (ret) 738 if (ret)
644 goto out_failed; 739 goto out_failed;
645 740
646 if (pdata->setup) { 741 if (pdata && pdata->setup) {
647 ret = pdata->setup(client, chip->gpio_chip.base, 742 ret = pdata->setup(client, chip->gpio_chip.base,
648 chip->gpio_chip.ngpio, pdata->context); 743 chip->gpio_chip.ngpio, pdata->context);
649 if (ret < 0) 744 if (ret < 0)
@@ -664,9 +759,10 @@ static int max732x_remove(struct i2c_client *client)
664{ 759{
665 struct max732x_platform_data *pdata = dev_get_platdata(&client->dev); 760 struct max732x_platform_data *pdata = dev_get_platdata(&client->dev);
666 struct max732x_chip *chip = i2c_get_clientdata(client); 761 struct max732x_chip *chip = i2c_get_clientdata(client);
667 int ret;
668 762
669 if (pdata->teardown) { 763 if (pdata && pdata->teardown) {
764 int ret;
765
670 ret = pdata->teardown(client, chip->gpio_chip.base, 766 ret = pdata->teardown(client, chip->gpio_chip.base,
671 chip->gpio_chip.ngpio, pdata->context); 767 chip->gpio_chip.ngpio, pdata->context);
672 if (ret < 0) { 768 if (ret < 0) {
@@ -689,8 +785,9 @@ static int max732x_remove(struct i2c_client *client)
689 785
690static struct i2c_driver max732x_driver = { 786static struct i2c_driver max732x_driver = {
691 .driver = { 787 .driver = {
692 .name = "max732x", 788 .name = "max732x",
693 .owner = THIS_MODULE, 789 .owner = THIS_MODULE,
790 .of_match_table = of_match_ptr(max732x_of_table),
694 }, 791 },
695 .probe = max732x_probe, 792 .probe = max732x_probe,
696 .remove = max732x_remove, 793 .remove = max732x_remove,
diff --git a/drivers/gpio/gpio-mb86s7x.c b/drivers/gpio/gpio-mb86s7x.c
new file mode 100644
index 000000000000..21b1ce5abdfe
--- /dev/null
+++ b/drivers/gpio/gpio-mb86s7x.c
@@ -0,0 +1,232 @@
1/*
2 * linux/drivers/gpio/gpio-mb86s7x.c
3 *
4 * Copyright (C) 2015 Fujitsu Semiconductor Limited
5 * Copyright (C) 2015 Linaro Ltd.
6 *
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, version 2 of the License.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 */
16
17#include <linux/io.h>
18#include <linux/init.h>
19#include <linux/clk.h>
20#include <linux/module.h>
21#include <linux/err.h>
22#include <linux/errno.h>
23#include <linux/ioport.h>
24#include <linux/of_device.h>
25#include <linux/gpio/driver.h>
26#include <linux/platform_device.h>
27#include <linux/spinlock.h>
28#include <linux/slab.h>
29
30/*
31 * Only first 8bits of a register correspond to each pin,
32 * so there are 4 registers for 32 pins.
33 */
34#define PDR(x) (0x0 + x / 8 * 4)
35#define DDR(x) (0x10 + x / 8 * 4)
36#define PFR(x) (0x20 + x / 8 * 4)
37
38#define OFFSET(x) BIT((x) % 8)
39
40struct mb86s70_gpio_chip {
41 struct gpio_chip gc;
42 void __iomem *base;
43 struct clk *clk;
44 spinlock_t lock;
45};
46
47static inline struct mb86s70_gpio_chip *chip_to_mb86s70(struct gpio_chip *gc)
48{
49 return container_of(gc, struct mb86s70_gpio_chip, gc);
50}
51
52static int mb86s70_gpio_request(struct gpio_chip *gc, unsigned gpio)
53{
54 struct mb86s70_gpio_chip *gchip = chip_to_mb86s70(gc);
55 unsigned long flags;
56 u32 val;
57
58 spin_lock_irqsave(&gchip->lock, flags);
59
60 val = readl(gchip->base + PFR(gpio));
61 val &= ~OFFSET(gpio);
62 writel(val, gchip->base + PFR(gpio));
63
64 spin_unlock_irqrestore(&gchip->lock, flags);
65
66 return 0;
67}
68
69static void mb86s70_gpio_free(struct gpio_chip *gc, unsigned gpio)
70{
71 struct mb86s70_gpio_chip *gchip = chip_to_mb86s70(gc);
72 unsigned long flags;
73 u32 val;
74
75 spin_lock_irqsave(&gchip->lock, flags);
76
77 val = readl(gchip->base + PFR(gpio));
78 val |= OFFSET(gpio);
79 writel(val, gchip->base + PFR(gpio));
80
81 spin_unlock_irqrestore(&gchip->lock, flags);
82}
83
84static int mb86s70_gpio_direction_input(struct gpio_chip *gc, unsigned gpio)
85{
86 struct mb86s70_gpio_chip *gchip = chip_to_mb86s70(gc);
87 unsigned long flags;
88 unsigned char val;
89
90 spin_lock_irqsave(&gchip->lock, flags);
91
92 val = readl(gchip->base + DDR(gpio));
93 val &= ~OFFSET(gpio);
94 writel(val, gchip->base + DDR(gpio));
95
96 spin_unlock_irqrestore(&gchip->lock, flags);
97
98 return 0;
99}
100
101static int mb86s70_gpio_direction_output(struct gpio_chip *gc,
102 unsigned gpio, int value)
103{
104 struct mb86s70_gpio_chip *gchip = chip_to_mb86s70(gc);
105 unsigned long flags;
106 unsigned char val;
107
108 spin_lock_irqsave(&gchip->lock, flags);
109
110 val = readl(gchip->base + PDR(gpio));
111 if (value)
112 val |= OFFSET(gpio);
113 else
114 val &= ~OFFSET(gpio);
115 writel(val, gchip->base + PDR(gpio));
116
117 val = readl(gchip->base + DDR(gpio));
118 val |= OFFSET(gpio);
119 writel(val, gchip->base + DDR(gpio));
120
121 spin_unlock_irqrestore(&gchip->lock, flags);
122
123 return 0;
124}
125
126static int mb86s70_gpio_get(struct gpio_chip *gc, unsigned gpio)
127{
128 struct mb86s70_gpio_chip *gchip = chip_to_mb86s70(gc);
129
130 return !!(readl(gchip->base + PDR(gpio)) & OFFSET(gpio));
131}
132
133static void mb86s70_gpio_set(struct gpio_chip *gc, unsigned gpio, int value)
134{
135 struct mb86s70_gpio_chip *gchip = chip_to_mb86s70(gc);
136 unsigned long flags;
137 unsigned char val;
138
139 spin_lock_irqsave(&gchip->lock, flags);
140
141 val = readl(gchip->base + PDR(gpio));
142 if (value)
143 val |= OFFSET(gpio);
144 else
145 val &= ~OFFSET(gpio);
146 writel(val, gchip->base + PDR(gpio));
147
148 spin_unlock_irqrestore(&gchip->lock, flags);
149}
150
151static int mb86s70_gpio_probe(struct platform_device *pdev)
152{
153 struct mb86s70_gpio_chip *gchip;
154 struct resource *res;
155 int ret;
156
157 gchip = devm_kzalloc(&pdev->dev, sizeof(*gchip), GFP_KERNEL);
158 if (gchip == NULL)
159 return -ENOMEM;
160
161 platform_set_drvdata(pdev, gchip);
162
163 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
164 gchip->base = devm_ioremap_resource(&pdev->dev, res);
165 if (IS_ERR(gchip->base))
166 return PTR_ERR(gchip->base);
167
168 gchip->clk = devm_clk_get(&pdev->dev, NULL);
169 if (IS_ERR(gchip->clk))
170 return PTR_ERR(gchip->clk);
171
172 clk_prepare_enable(gchip->clk);
173
174 spin_lock_init(&gchip->lock);
175
176 gchip->gc.direction_output = mb86s70_gpio_direction_output;
177 gchip->gc.direction_input = mb86s70_gpio_direction_input;
178 gchip->gc.request = mb86s70_gpio_request;
179 gchip->gc.free = mb86s70_gpio_free;
180 gchip->gc.get = mb86s70_gpio_get;
181 gchip->gc.set = mb86s70_gpio_set;
182 gchip->gc.label = dev_name(&pdev->dev);
183 gchip->gc.ngpio = 32;
184 gchip->gc.owner = THIS_MODULE;
185 gchip->gc.dev = &pdev->dev;
186 gchip->gc.base = -1;
187
188 platform_set_drvdata(pdev, gchip);
189
190 ret = gpiochip_add(&gchip->gc);
191 if (ret) {
192 dev_err(&pdev->dev, "couldn't register gpio driver\n");
193 clk_disable_unprepare(gchip->clk);
194 }
195
196 return ret;
197}
198
199static int mb86s70_gpio_remove(struct platform_device *pdev)
200{
201 struct mb86s70_gpio_chip *gchip = platform_get_drvdata(pdev);
202
203 gpiochip_remove(&gchip->gc);
204 clk_disable_unprepare(gchip->clk);
205
206 return 0;
207}
208
209static const struct of_device_id mb86s70_gpio_dt_ids[] = {
210 { .compatible = "fujitsu,mb86s70-gpio" },
211 { /* sentinel */ }
212};
213MODULE_DEVICE_TABLE(of, mb86s70_gpio_dt_ids);
214
215static struct platform_driver mb86s70_gpio_driver = {
216 .driver = {
217 .name = "mb86s70-gpio",
218 .of_match_table = mb86s70_gpio_dt_ids,
219 },
220 .probe = mb86s70_gpio_probe,
221 .remove = mb86s70_gpio_remove,
222};
223
224static int __init mb86s70_gpio_init(void)
225{
226 return platform_driver_register(&mb86s70_gpio_driver);
227}
228module_init(mb86s70_gpio_init);
229
230MODULE_DESCRIPTION("MB86S7x GPIO Driver");
231MODULE_ALIAS("platform:mb86s70-gpio");
232MODULE_LICENSE("GPL");
diff --git a/drivers/gpio/gpio-mm-lantiq.c b/drivers/gpio/gpio-mm-lantiq.c
index f228b1ce0ce0..f67ef2283d64 100644
--- a/drivers/gpio/gpio-mm-lantiq.c
+++ b/drivers/gpio/gpio-mm-lantiq.c
@@ -104,35 +104,34 @@ static void ltq_mm_save_regs(struct of_mm_gpio_chip *mm_gc)
104 104
105static int ltq_mm_probe(struct platform_device *pdev) 105static int ltq_mm_probe(struct platform_device *pdev)
106{ 106{
107 struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
108 struct ltq_mm *chip; 107 struct ltq_mm *chip;
109 const __be32 *shadow; 108 u32 shadow;
110 int ret = 0;
111 109
112 if (!res) { 110 chip = devm_kzalloc(&pdev->dev, sizeof(*chip), GFP_KERNEL);
113 dev_err(&pdev->dev, "failed to get memory resource\n");
114 return -ENOENT;
115 }
116
117 chip = kzalloc(sizeof(*chip), GFP_KERNEL);
118 if (!chip) 111 if (!chip)
119 return -ENOMEM; 112 return -ENOMEM;
120 113
114 platform_set_drvdata(pdev, chip);
115
121 chip->mmchip.gc.ngpio = 16; 116 chip->mmchip.gc.ngpio = 16;
122 chip->mmchip.gc.label = "gpio-mm-ltq";
123 chip->mmchip.gc.direction_output = ltq_mm_dir_out; 117 chip->mmchip.gc.direction_output = ltq_mm_dir_out;
124 chip->mmchip.gc.set = ltq_mm_set; 118 chip->mmchip.gc.set = ltq_mm_set;
125 chip->mmchip.save_regs = ltq_mm_save_regs; 119 chip->mmchip.save_regs = ltq_mm_save_regs;
126 120
127 /* store the shadow value if one was passed by the devicetree */ 121 /* store the shadow value if one was passed by the devicetree */
128 shadow = of_get_property(pdev->dev.of_node, "lantiq,shadow", NULL); 122 if (!of_property_read_u32(pdev->dev.of_node, "lantiq,shadow", &shadow))
129 if (shadow) 123 chip->shadow = shadow;
130 chip->shadow = be32_to_cpu(*shadow); 124
131 125 return of_mm_gpiochip_add(pdev->dev.of_node, &chip->mmchip);
132 ret = of_mm_gpiochip_add(pdev->dev.of_node, &chip->mmchip); 126}
133 if (ret) 127
134 kfree(chip); 128static int ltq_mm_remove(struct platform_device *pdev)
135 return ret; 129{
130 struct ltq_mm *chip = platform_get_drvdata(pdev);
131
132 of_mm_gpiochip_remove(&chip->mmchip);
133
134 return 0;
136} 135}
137 136
138static const struct of_device_id ltq_mm_match[] = { 137static const struct of_device_id ltq_mm_match[] = {
@@ -143,6 +142,7 @@ MODULE_DEVICE_TABLE(of, ltq_mm_match);
143 142
144static struct platform_driver ltq_mm_driver = { 143static struct platform_driver ltq_mm_driver = {
145 .probe = ltq_mm_probe, 144 .probe = ltq_mm_probe,
145 .remove = ltq_mm_remove,
146 .driver = { 146 .driver = {
147 .name = "gpio-mm-ltq", 147 .name = "gpio-mm-ltq",
148 .of_match_table = ltq_mm_match, 148 .of_match_table = ltq_mm_match,
@@ -155,3 +155,9 @@ static int __init ltq_mm_init(void)
155} 155}
156 156
157subsys_initcall(ltq_mm_init); 157subsys_initcall(ltq_mm_init);
158
159static void __exit ltq_mm_exit(void)
160{
161 platform_driver_unregister(&ltq_mm_driver);
162}
163module_exit(ltq_mm_exit);
diff --git a/drivers/gpio/gpio-moxart.c b/drivers/gpio/gpio-moxart.c
index 31e2551ed903..c3ab46e595da 100644
--- a/drivers/gpio/gpio-moxart.c
+++ b/drivers/gpio/gpio-moxart.c
@@ -23,21 +23,12 @@
23#include <linux/delay.h> 23#include <linux/delay.h>
24#include <linux/timer.h> 24#include <linux/timer.h>
25#include <linux/bitops.h> 25#include <linux/bitops.h>
26#include <linux/basic_mmio_gpio.h>
26 27
27#define GPIO_DATA_OUT 0x00 28#define GPIO_DATA_OUT 0x00
28#define GPIO_DATA_IN 0x04 29#define GPIO_DATA_IN 0x04
29#define GPIO_PIN_DIRECTION 0x08 30#define GPIO_PIN_DIRECTION 0x08
30 31
31struct moxart_gpio_chip {
32 struct gpio_chip gpio;
33 void __iomem *base;
34};
35
36static inline struct moxart_gpio_chip *to_moxart_gpio(struct gpio_chip *chip)
37{
38 return container_of(chip, struct moxart_gpio_chip, gpio);
39}
40
41static int moxart_gpio_request(struct gpio_chip *chip, unsigned offset) 32static int moxart_gpio_request(struct gpio_chip *chip, unsigned offset)
42{ 33{
43 return pinctrl_request_gpio(offset); 34 return pinctrl_request_gpio(offset);
@@ -48,90 +39,60 @@ static void moxart_gpio_free(struct gpio_chip *chip, unsigned offset)
48 pinctrl_free_gpio(offset); 39 pinctrl_free_gpio(offset);
49} 40}
50 41
51static void moxart_gpio_set(struct gpio_chip *chip, unsigned offset, int value)
52{
53 struct moxart_gpio_chip *gc = to_moxart_gpio(chip);
54 void __iomem *ioaddr = gc->base + GPIO_DATA_OUT;
55 u32 reg = readl(ioaddr);
56
57 if (value)
58 reg = reg | BIT(offset);
59 else
60 reg = reg & ~BIT(offset);
61
62 writel(reg, ioaddr);
63}
64
65static int moxart_gpio_get(struct gpio_chip *chip, unsigned offset) 42static int moxart_gpio_get(struct gpio_chip *chip, unsigned offset)
66{ 43{
67 struct moxart_gpio_chip *gc = to_moxart_gpio(chip); 44 struct bgpio_chip *bgc = to_bgpio_chip(chip);
68 u32 ret = readl(gc->base + GPIO_PIN_DIRECTION); 45 u32 ret = bgc->read_reg(bgc->reg_dir);
69 46
70 if (ret & BIT(offset)) 47 if (ret & BIT(offset))
71 return !!(readl(gc->base + GPIO_DATA_OUT) & BIT(offset)); 48 return !!(bgc->read_reg(bgc->reg_set) & BIT(offset));
72 else 49 else
73 return !!(readl(gc->base + GPIO_DATA_IN) & BIT(offset)); 50 return !!(bgc->read_reg(bgc->reg_dat) & BIT(offset));
74}
75
76static int moxart_gpio_direction_input(struct gpio_chip *chip, unsigned offset)
77{
78 struct moxart_gpio_chip *gc = to_moxart_gpio(chip);
79 void __iomem *ioaddr = gc->base + GPIO_PIN_DIRECTION;
80
81 writel(readl(ioaddr) & ~BIT(offset), ioaddr);
82 return 0;
83}
84
85static int moxart_gpio_direction_output(struct gpio_chip *chip,
86 unsigned offset, int value)
87{
88 struct moxart_gpio_chip *gc = to_moxart_gpio(chip);
89 void __iomem *ioaddr = gc->base + GPIO_PIN_DIRECTION;
90
91 moxart_gpio_set(chip, offset, value);
92 writel(readl(ioaddr) | BIT(offset), ioaddr);
93 return 0;
94} 51}
95 52
96static struct gpio_chip moxart_template_chip = {
97 .label = "moxart-gpio",
98 .request = moxart_gpio_request,
99 .free = moxart_gpio_free,
100 .direction_input = moxart_gpio_direction_input,
101 .direction_output = moxart_gpio_direction_output,
102 .set = moxart_gpio_set,
103 .get = moxart_gpio_get,
104 .ngpio = 32,
105 .owner = THIS_MODULE,
106};
107
108static int moxart_gpio_probe(struct platform_device *pdev) 53static int moxart_gpio_probe(struct platform_device *pdev)
109{ 54{
110 struct device *dev = &pdev->dev; 55 struct device *dev = &pdev->dev;
111 struct resource *res; 56 struct resource *res;
112 struct moxart_gpio_chip *mgc; 57 struct bgpio_chip *bgc;
58 void __iomem *base;
113 int ret; 59 int ret;
114 60
115 mgc = devm_kzalloc(dev, sizeof(*mgc), GFP_KERNEL); 61 bgc = devm_kzalloc(dev, sizeof(*bgc), GFP_KERNEL);
116 if (!mgc) 62 if (!bgc)
117 return -ENOMEM; 63 return -ENOMEM;
118 mgc->gpio = moxart_template_chip;
119 64
120 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 65 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
121 mgc->base = devm_ioremap_resource(dev, res); 66 base = devm_ioremap_resource(dev, res);
122 if (IS_ERR(mgc->base)) 67 if (IS_ERR(base))
123 return PTR_ERR(mgc->base); 68 return PTR_ERR(base);
124 69
125 mgc->gpio.dev = dev; 70 ret = bgpio_init(bgc, dev, 4, base + GPIO_DATA_IN,
71 base + GPIO_DATA_OUT, NULL,
72 base + GPIO_PIN_DIRECTION, NULL, 0);
73 if (ret) {
74 dev_err(&pdev->dev, "bgpio_init failed\n");
75 return ret;
76 }
126 77
127 ret = gpiochip_add(&mgc->gpio); 78 bgc->gc.label = "moxart-gpio";
79 bgc->gc.request = moxart_gpio_request;
80 bgc->gc.free = moxart_gpio_free;
81 bgc->gc.get = moxart_gpio_get;
82 bgc->data = bgc->read_reg(bgc->reg_set);
83 bgc->gc.base = 0;
84 bgc->gc.ngpio = 32;
85 bgc->gc.dev = dev;
86 bgc->gc.owner = THIS_MODULE;
87
88 ret = gpiochip_add(&bgc->gc);
128 if (ret) { 89 if (ret) {
129 dev_err(dev, "%s: gpiochip_add failed\n", 90 dev_err(dev, "%s: gpiochip_add failed\n",
130 dev->of_node->full_name); 91 dev->of_node->full_name);
131 return ret; 92 return ret;
132 } 93 }
133 94
134 return 0; 95 return ret;
135} 96}
136 97
137static const struct of_device_id moxart_gpio_match[] = { 98static const struct of_device_id moxart_gpio_match[] = {
diff --git a/drivers/gpio/gpio-mpc5200.c b/drivers/gpio/gpio-mpc5200.c
index 8ce6c9510035..4c542153e923 100644
--- a/drivers/gpio/gpio-mpc5200.c
+++ b/drivers/gpio/gpio-mpc5200.c
@@ -155,10 +155,12 @@ static int mpc52xx_wkup_gpiochip_probe(struct platform_device *ofdev)
155 struct gpio_chip *gc; 155 struct gpio_chip *gc;
156 int ret; 156 int ret;
157 157
158 chip = kzalloc(sizeof(*chip), GFP_KERNEL); 158 chip = devm_kzalloc(&ofdev->dev, sizeof(*chip), GFP_KERNEL);
159 if (!chip) 159 if (!chip)
160 return -ENOMEM; 160 return -ENOMEM;
161 161
162 platform_set_drvdata(ofdev, chip);
163
162 gc = &chip->mmchip.gc; 164 gc = &chip->mmchip.gc;
163 165
164 gc->ngpio = 8; 166 gc->ngpio = 8;
@@ -181,7 +183,11 @@ static int mpc52xx_wkup_gpiochip_probe(struct platform_device *ofdev)
181 183
182static int mpc52xx_gpiochip_remove(struct platform_device *ofdev) 184static int mpc52xx_gpiochip_remove(struct platform_device *ofdev)
183{ 185{
184 return -EBUSY; 186 struct mpc52xx_gpiochip *chip = platform_get_drvdata(ofdev);
187
188 of_mm_gpiochip_remove(&chip->mmchip);
189
190 return 0;
185} 191}
186 192
187static const struct of_device_id mpc52xx_wkup_gpiochip_match[] = { 193static const struct of_device_id mpc52xx_wkup_gpiochip_match[] = {
@@ -314,10 +320,12 @@ static int mpc52xx_simple_gpiochip_probe(struct platform_device *ofdev)
314 struct mpc52xx_gpio __iomem *regs; 320 struct mpc52xx_gpio __iomem *regs;
315 int ret; 321 int ret;
316 322
317 chip = kzalloc(sizeof(*chip), GFP_KERNEL); 323 chip = devm_kzalloc(&ofdev->dev, sizeof(*chip), GFP_KERNEL);
318 if (!chip) 324 if (!chip)
319 return -ENOMEM; 325 return -ENOMEM;
320 326
327 platform_set_drvdata(ofdev, chip);
328
321 gc = &chip->mmchip.gc; 329 gc = &chip->mmchip.gc;
322 330
323 gc->ngpio = 32; 331 gc->ngpio = 32;
@@ -363,11 +371,16 @@ static int __init mpc52xx_gpio_init(void)
363 return 0; 371 return 0;
364} 372}
365 373
366
367/* Make sure we get initialised before anyone else tries to use us */ 374/* Make sure we get initialised before anyone else tries to use us */
368subsys_initcall(mpc52xx_gpio_init); 375subsys_initcall(mpc52xx_gpio_init);
369 376
370/* No exit call at the moment as we cannot unregister of gpio chips */ 377static void __exit mpc52xx_gpio_exit(void)
378{
379 platform_driver_unregister(&mpc52xx_wkup_gpiochip_driver);
380
381 platform_driver_unregister(&mpc52xx_simple_gpiochip_driver);
382}
383module_exit(mpc52xx_gpio_exit);
371 384
372MODULE_DESCRIPTION("Freescale MPC52xx gpio driver"); 385MODULE_DESCRIPTION("Freescale MPC52xx gpio driver");
373MODULE_AUTHOR("Sascha Hauer <s.hauer@pengutronix.de"); 386MODULE_AUTHOR("Sascha Hauer <s.hauer@pengutronix.de");
diff --git a/drivers/gpio/gpio-mpc8xxx.c b/drivers/gpio/gpio-mpc8xxx.c
index d1ff879e6ff2..a65b75161aa4 100644
--- a/drivers/gpio/gpio-mpc8xxx.c
+++ b/drivers/gpio/gpio-mpc8xxx.c
@@ -15,6 +15,7 @@
15#include <linux/of.h> 15#include <linux/of.h>
16#include <linux/of_gpio.h> 16#include <linux/of_gpio.h>
17#include <linux/of_irq.h> 17#include <linux/of_irq.h>
18#include <linux/of_platform.h>
18#include <linux/gpio.h> 19#include <linux/gpio.h>
19#include <linux/slab.h> 20#include <linux/slab.h>
20#include <linux/irq.h> 21#include <linux/irq.h>
@@ -39,6 +40,7 @@ struct mpc8xxx_gpio_chip {
39 */ 40 */
40 u32 data; 41 u32 data;
41 struct irq_domain *irq; 42 struct irq_domain *irq;
43 unsigned int irqn;
42 const void *of_dev_id_data; 44 const void *of_dev_id_data;
43}; 45};
44 46
@@ -332,7 +334,7 @@ static struct irq_domain_ops mpc8xxx_gpio_irq_ops = {
332 .xlate = irq_domain_xlate_twocell, 334 .xlate = irq_domain_xlate_twocell,
333}; 335};
334 336
335static struct of_device_id mpc8xxx_gpio_ids[] __initdata = { 337static struct of_device_id mpc8xxx_gpio_ids[] = {
336 { .compatible = "fsl,mpc8349-gpio", }, 338 { .compatible = "fsl,mpc8349-gpio", },
337 { .compatible = "fsl,mpc8572-gpio", }, 339 { .compatible = "fsl,mpc8572-gpio", },
338 { .compatible = "fsl,mpc8610-gpio", }, 340 { .compatible = "fsl,mpc8610-gpio", },
@@ -342,20 +344,20 @@ static struct of_device_id mpc8xxx_gpio_ids[] __initdata = {
342 {} 344 {}
343}; 345};
344 346
345static void __init mpc8xxx_add_controller(struct device_node *np) 347static int mpc8xxx_probe(struct platform_device *pdev)
346{ 348{
349 struct device_node *np = pdev->dev.of_node;
347 struct mpc8xxx_gpio_chip *mpc8xxx_gc; 350 struct mpc8xxx_gpio_chip *mpc8xxx_gc;
348 struct of_mm_gpio_chip *mm_gc; 351 struct of_mm_gpio_chip *mm_gc;
349 struct gpio_chip *gc; 352 struct gpio_chip *gc;
350 const struct of_device_id *id; 353 const struct of_device_id *id;
351 unsigned hwirq;
352 int ret; 354 int ret;
353 355
354 mpc8xxx_gc = kzalloc(sizeof(*mpc8xxx_gc), GFP_KERNEL); 356 mpc8xxx_gc = devm_kzalloc(&pdev->dev, sizeof(*mpc8xxx_gc), GFP_KERNEL);
355 if (!mpc8xxx_gc) { 357 if (!mpc8xxx_gc)
356 ret = -ENOMEM; 358 return -ENOMEM;
357 goto err; 359
358 } 360 platform_set_drvdata(pdev, mpc8xxx_gc);
359 361
360 spin_lock_init(&mpc8xxx_gc->lock); 362 spin_lock_init(&mpc8xxx_gc->lock);
361 363
@@ -375,16 +377,16 @@ static void __init mpc8xxx_add_controller(struct device_node *np)
375 377
376 ret = of_mm_gpiochip_add(np, mm_gc); 378 ret = of_mm_gpiochip_add(np, mm_gc);
377 if (ret) 379 if (ret)
378 goto err; 380 return ret;
379 381
380 hwirq = irq_of_parse_and_map(np, 0); 382 mpc8xxx_gc->irqn = irq_of_parse_and_map(np, 0);
381 if (hwirq == NO_IRQ) 383 if (mpc8xxx_gc->irqn == NO_IRQ)
382 goto skip_irq; 384 return 0;
383 385
384 mpc8xxx_gc->irq = irq_domain_add_linear(np, MPC8XXX_GPIO_PINS, 386 mpc8xxx_gc->irq = irq_domain_add_linear(np, MPC8XXX_GPIO_PINS,
385 &mpc8xxx_gpio_irq_ops, mpc8xxx_gc); 387 &mpc8xxx_gpio_irq_ops, mpc8xxx_gc);
386 if (!mpc8xxx_gc->irq) 388 if (!mpc8xxx_gc->irq)
387 goto skip_irq; 389 return 0;
388 390
389 id = of_match_node(mpc8xxx_gpio_ids, np); 391 id = of_match_node(mpc8xxx_gpio_ids, np);
390 if (id) 392 if (id)
@@ -394,27 +396,39 @@ static void __init mpc8xxx_add_controller(struct device_node *np)
394 out_be32(mm_gc->regs + GPIO_IER, 0xffffffff); 396 out_be32(mm_gc->regs + GPIO_IER, 0xffffffff);
395 out_be32(mm_gc->regs + GPIO_IMR, 0); 397 out_be32(mm_gc->regs + GPIO_IMR, 0);
396 398
397 irq_set_handler_data(hwirq, mpc8xxx_gc); 399 irq_set_handler_data(mpc8xxx_gc->irqn, mpc8xxx_gc);
398 irq_set_chained_handler(hwirq, mpc8xxx_gpio_irq_cascade); 400 irq_set_chained_handler(mpc8xxx_gc->irqn, mpc8xxx_gpio_irq_cascade);
399
400skip_irq:
401 return;
402
403err:
404 pr_err("%s: registration failed with status %d\n",
405 np->full_name, ret);
406 kfree(mpc8xxx_gc);
407 401
408 return; 402 return 0;
409} 403}
410 404
411static int __init mpc8xxx_add_gpiochips(void) 405static int mpc8xxx_remove(struct platform_device *pdev)
412{ 406{
413 struct device_node *np; 407 struct mpc8xxx_gpio_chip *mpc8xxx_gc = platform_get_drvdata(pdev);
408
409 if (mpc8xxx_gc->irq) {
410 irq_set_handler_data(mpc8xxx_gc->irqn, NULL);
411 irq_set_chained_handler(mpc8xxx_gc->irqn, NULL);
412 irq_domain_remove(mpc8xxx_gc->irq);
413 }
414 414
415 for_each_matching_node(np, mpc8xxx_gpio_ids) 415 of_mm_gpiochip_remove(&mpc8xxx_gc->mm_gc);
416 mpc8xxx_add_controller(np);
417 416
418 return 0; 417 return 0;
419} 418}
420arch_initcall(mpc8xxx_add_gpiochips); 419
420static struct platform_driver mpc8xxx_plat_driver = {
421 .probe = mpc8xxx_probe,
422 .remove = mpc8xxx_remove,
423 .driver = {
424 .name = "gpio-mpc8xxx",
425 .of_match_table = mpc8xxx_gpio_ids,
426 },
427};
428
429static int __init mpc8xxx_init(void)
430{
431 return platform_driver_register(&mpc8xxx_plat_driver);
432}
433
434arch_initcall(mpc8xxx_init);
diff --git a/drivers/gpio/gpio-mvebu.c b/drivers/gpio/gpio-mvebu.c
index 7bc3e9b288f3..d0bc123c7975 100644
--- a/drivers/gpio/gpio-mvebu.c
+++ b/drivers/gpio/gpio-mvebu.c
@@ -59,7 +59,7 @@
59#define GPIO_LEVEL_MASK_OFF 0x001c 59#define GPIO_LEVEL_MASK_OFF 0x001c
60 60
61/* The MV78200 has per-CPU registers for edge mask and level mask */ 61/* The MV78200 has per-CPU registers for edge mask and level mask */
62#define GPIO_EDGE_MASK_MV78200_OFF(cpu) ((cpu) ? 0x30 : 0x18) 62#define GPIO_EDGE_MASK_MV78200_OFF(cpu) ((cpu) ? 0x30 : 0x18)
63#define GPIO_LEVEL_MASK_MV78200_OFF(cpu) ((cpu) ? 0x34 : 0x1C) 63#define GPIO_LEVEL_MASK_MV78200_OFF(cpu) ((cpu) ? 0x34 : 0x1C)
64 64
65/* The Armada XP has per-CPU registers for interrupt cause, interrupt 65/* The Armada XP has per-CPU registers for interrupt cause, interrupt
@@ -69,11 +69,11 @@
69#define GPIO_EDGE_MASK_ARMADAXP_OFF(cpu) (0x10 + (cpu) * 0x4) 69#define GPIO_EDGE_MASK_ARMADAXP_OFF(cpu) (0x10 + (cpu) * 0x4)
70#define GPIO_LEVEL_MASK_ARMADAXP_OFF(cpu) (0x20 + (cpu) * 0x4) 70#define GPIO_LEVEL_MASK_ARMADAXP_OFF(cpu) (0x20 + (cpu) * 0x4)
71 71
72#define MVEBU_GPIO_SOC_VARIANT_ORION 0x1 72#define MVEBU_GPIO_SOC_VARIANT_ORION 0x1
73#define MVEBU_GPIO_SOC_VARIANT_MV78200 0x2 73#define MVEBU_GPIO_SOC_VARIANT_MV78200 0x2
74#define MVEBU_GPIO_SOC_VARIANT_ARMADAXP 0x3 74#define MVEBU_GPIO_SOC_VARIANT_ARMADAXP 0x3
75 75
76#define MVEBU_MAX_GPIO_PER_BANK 32 76#define MVEBU_MAX_GPIO_PER_BANK 32
77 77
78struct mvebu_gpio_chip { 78struct mvebu_gpio_chip {
79 struct gpio_chip chip; 79 struct gpio_chip chip;
@@ -82,9 +82,9 @@ struct mvebu_gpio_chip {
82 void __iomem *percpu_membase; 82 void __iomem *percpu_membase;
83 int irqbase; 83 int irqbase;
84 struct irq_domain *domain; 84 struct irq_domain *domain;
85 int soc_variant; 85 int soc_variant;
86 86
87 /* Used to preserve GPIO registers accross suspend/resume */ 87 /* Used to preserve GPIO registers across suspend/resume */
88 u32 out_reg; 88 u32 out_reg;
89 u32 io_conf_reg; 89 u32 io_conf_reg;
90 u32 blink_en_reg; 90 u32 blink_en_reg;
@@ -107,7 +107,8 @@ static inline void __iomem *mvebu_gpioreg_blink(struct mvebu_gpio_chip *mvchip)
107 return mvchip->membase + GPIO_BLINK_EN_OFF; 107 return mvchip->membase + GPIO_BLINK_EN_OFF;
108} 108}
109 109
110static inline void __iomem *mvebu_gpioreg_io_conf(struct mvebu_gpio_chip *mvchip) 110static inline void __iomem *
111mvebu_gpioreg_io_conf(struct mvebu_gpio_chip *mvchip)
111{ 112{
112 return mvchip->membase + GPIO_IO_CONF_OFF; 113 return mvchip->membase + GPIO_IO_CONF_OFF;
113} 114}
@@ -117,12 +118,14 @@ static inline void __iomem *mvebu_gpioreg_in_pol(struct mvebu_gpio_chip *mvchip)
117 return mvchip->membase + GPIO_IN_POL_OFF; 118 return mvchip->membase + GPIO_IN_POL_OFF;
118} 119}
119 120
120static inline void __iomem *mvebu_gpioreg_data_in(struct mvebu_gpio_chip *mvchip) 121static inline void __iomem *
122mvebu_gpioreg_data_in(struct mvebu_gpio_chip *mvchip)
121{ 123{
122 return mvchip->membase + GPIO_DATA_IN_OFF; 124 return mvchip->membase + GPIO_DATA_IN_OFF;
123} 125}
124 126
125static inline void __iomem *mvebu_gpioreg_edge_cause(struct mvebu_gpio_chip *mvchip) 127static inline void __iomem *
128mvebu_gpioreg_edge_cause(struct mvebu_gpio_chip *mvchip)
126{ 129{
127 int cpu; 130 int cpu;
128 131
@@ -132,13 +135,15 @@ static inline void __iomem *mvebu_gpioreg_edge_cause(struct mvebu_gpio_chip *mvc
132 return mvchip->membase + GPIO_EDGE_CAUSE_OFF; 135 return mvchip->membase + GPIO_EDGE_CAUSE_OFF;
133 case MVEBU_GPIO_SOC_VARIANT_ARMADAXP: 136 case MVEBU_GPIO_SOC_VARIANT_ARMADAXP:
134 cpu = smp_processor_id(); 137 cpu = smp_processor_id();
135 return mvchip->percpu_membase + GPIO_EDGE_CAUSE_ARMADAXP_OFF(cpu); 138 return mvchip->percpu_membase +
139 GPIO_EDGE_CAUSE_ARMADAXP_OFF(cpu);
136 default: 140 default:
137 BUG(); 141 BUG();
138 } 142 }
139} 143}
140 144
141static inline void __iomem *mvebu_gpioreg_edge_mask(struct mvebu_gpio_chip *mvchip) 145static inline void __iomem *
146mvebu_gpioreg_edge_mask(struct mvebu_gpio_chip *mvchip)
142{ 147{
143 int cpu; 148 int cpu;
144 149
@@ -150,7 +155,8 @@ static inline void __iomem *mvebu_gpioreg_edge_mask(struct mvebu_gpio_chip *mvch
150 return mvchip->membase + GPIO_EDGE_MASK_MV78200_OFF(cpu); 155 return mvchip->membase + GPIO_EDGE_MASK_MV78200_OFF(cpu);
151 case MVEBU_GPIO_SOC_VARIANT_ARMADAXP: 156 case MVEBU_GPIO_SOC_VARIANT_ARMADAXP:
152 cpu = smp_processor_id(); 157 cpu = smp_processor_id();
153 return mvchip->percpu_membase + GPIO_EDGE_MASK_ARMADAXP_OFF(cpu); 158 return mvchip->percpu_membase +
159 GPIO_EDGE_MASK_ARMADAXP_OFF(cpu);
154 default: 160 default:
155 BUG(); 161 BUG();
156 } 162 }
@@ -168,7 +174,8 @@ static void __iomem *mvebu_gpioreg_level_mask(struct mvebu_gpio_chip *mvchip)
168 return mvchip->membase + GPIO_LEVEL_MASK_MV78200_OFF(cpu); 174 return mvchip->membase + GPIO_LEVEL_MASK_MV78200_OFF(cpu);
169 case MVEBU_GPIO_SOC_VARIANT_ARMADAXP: 175 case MVEBU_GPIO_SOC_VARIANT_ARMADAXP:
170 cpu = smp_processor_id(); 176 cpu = smp_processor_id();
171 return mvchip->percpu_membase + GPIO_LEVEL_MASK_ARMADAXP_OFF(cpu); 177 return mvchip->percpu_membase +
178 GPIO_LEVEL_MASK_ARMADAXP_OFF(cpu);
172 default: 179 default:
173 BUG(); 180 BUG();
174 } 181 }
@@ -364,22 +371,22 @@ static void mvebu_gpio_level_irq_unmask(struct irq_data *d)
364 * value of the line or the opposite value. 371 * value of the line or the opposite value.
365 * 372 *
366 * Level IRQ handlers: DATA_IN is used directly as cause register. 373 * Level IRQ handlers: DATA_IN is used directly as cause register.
367 * Interrupt are masked by LEVEL_MASK registers. 374 * Interrupt are masked by LEVEL_MASK registers.
368 * Edge IRQ handlers: Change in DATA_IN are latched in EDGE_CAUSE. 375 * Edge IRQ handlers: Change in DATA_IN are latched in EDGE_CAUSE.
369 * Interrupt are masked by EDGE_MASK registers. 376 * Interrupt are masked by EDGE_MASK registers.
370 * Both-edge handlers: Similar to regular Edge handlers, but also swaps 377 * Both-edge handlers: Similar to regular Edge handlers, but also swaps
371 * the polarity to catch the next line transaction. 378 * the polarity to catch the next line transaction.
372 * This is a race condition that might not perfectly 379 * This is a race condition that might not perfectly
373 * work on some use cases. 380 * work on some use cases.
374 * 381 *
375 * Every eight GPIO lines are grouped (OR'ed) before going up to main 382 * Every eight GPIO lines are grouped (OR'ed) before going up to main
376 * cause register. 383 * cause register.
377 * 384 *
378 * EDGE cause mask 385 * EDGE cause mask
379 * data-in /--------| |-----| |----\ 386 * data-in /--------| |-----| |----\
380 * -----| |----- ---- to main cause reg 387 * -----| |----- ---- to main cause reg
381 * X \----------------| |----/ 388 * X \----------------| |----/
382 * polarity LEVEL mask 389 * polarity LEVEL mask
383 * 390 *
384 ****************************************************************************/ 391 ****************************************************************************/
385 392
@@ -394,9 +401,8 @@ static int mvebu_gpio_irq_set_type(struct irq_data *d, unsigned int type)
394 pin = d->hwirq; 401 pin = d->hwirq;
395 402
396 u = readl_relaxed(mvebu_gpioreg_io_conf(mvchip)) & (1 << pin); 403 u = readl_relaxed(mvebu_gpioreg_io_conf(mvchip)) & (1 << pin);
397 if (!u) { 404 if (!u)
398 return -EINVAL; 405 return -EINVAL;
399 }
400 406
401 type &= IRQ_TYPE_SENSE_MASK; 407 type &= IRQ_TYPE_SENSE_MASK;
402 if (type == IRQ_TYPE_NONE) 408 if (type == IRQ_TYPE_NONE)
@@ -529,13 +535,13 @@ static void mvebu_gpio_dbg_show(struct seq_file *s, struct gpio_chip *chip)
529 (data_in ^ in_pol) & msk ? "hi" : "lo", 535 (data_in ^ in_pol) & msk ? "hi" : "lo",
530 in_pol & msk ? "lo" : "hi"); 536 in_pol & msk ? "lo" : "hi");
531 if (!((edg_msk | lvl_msk) & msk)) { 537 if (!((edg_msk | lvl_msk) & msk)) {
532 seq_printf(s, " disabled\n"); 538 seq_puts(s, " disabled\n");
533 continue; 539 continue;
534 } 540 }
535 if (edg_msk & msk) 541 if (edg_msk & msk)
536 seq_printf(s, " edge "); 542 seq_puts(s, " edge ");
537 if (lvl_msk & msk) 543 if (lvl_msk & msk)
538 seq_printf(s, " level"); 544 seq_puts(s, " level");
539 seq_printf(s, " (%s)\n", cause & msk ? "pending" : "clear "); 545 seq_printf(s, " (%s)\n", cause & msk ? "pending" : "clear ");
540 } 546 }
541} 547}
@@ -546,15 +552,15 @@ static void mvebu_gpio_dbg_show(struct seq_file *s, struct gpio_chip *chip)
546static const struct of_device_id mvebu_gpio_of_match[] = { 552static const struct of_device_id mvebu_gpio_of_match[] = {
547 { 553 {
548 .compatible = "marvell,orion-gpio", 554 .compatible = "marvell,orion-gpio",
549 .data = (void *) MVEBU_GPIO_SOC_VARIANT_ORION, 555 .data = (void *) MVEBU_GPIO_SOC_VARIANT_ORION,
550 }, 556 },
551 { 557 {
552 .compatible = "marvell,mv78200-gpio", 558 .compatible = "marvell,mv78200-gpio",
553 .data = (void *) MVEBU_GPIO_SOC_VARIANT_MV78200, 559 .data = (void *) MVEBU_GPIO_SOC_VARIANT_MV78200,
554 }, 560 },
555 { 561 {
556 .compatible = "marvell,armadaxp-gpio", 562 .compatible = "marvell,armadaxp-gpio",
557 .data = (void *) MVEBU_GPIO_SOC_VARIANT_ARMADAXP, 563 .data = (void *) MVEBU_GPIO_SOC_VARIANT_ARMADAXP,
558 }, 564 },
559 { 565 {
560 /* sentinel */ 566 /* sentinel */
@@ -661,6 +667,7 @@ static int mvebu_gpio_probe(struct platform_device *pdev)
661 unsigned int ngpios; 667 unsigned int ngpios;
662 int soc_variant; 668 int soc_variant;
663 int i, cpu, id; 669 int i, cpu, id;
670 int err;
664 671
665 match = of_match_device(mvebu_gpio_of_match, &pdev->dev); 672 match = of_match_device(mvebu_gpio_of_match, &pdev->dev);
666 if (match) 673 if (match)
@@ -668,7 +675,8 @@ static int mvebu_gpio_probe(struct platform_device *pdev)
668 else 675 else
669 soc_variant = MVEBU_GPIO_SOC_VARIANT_ORION; 676 soc_variant = MVEBU_GPIO_SOC_VARIANT_ORION;
670 677
671 mvchip = devm_kzalloc(&pdev->dev, sizeof(struct mvebu_gpio_chip), GFP_KERNEL); 678 mvchip = devm_kzalloc(&pdev->dev, sizeof(struct mvebu_gpio_chip),
679 GFP_KERNEL);
672 if (!mvchip) 680 if (!mvchip)
673 return -ENOMEM; 681 return -ENOMEM;
674 682
@@ -767,8 +775,8 @@ static int mvebu_gpio_probe(struct platform_device *pdev)
767 * interrupt handlers, with each handler dealing with 8 GPIO 775 * interrupt handlers, with each handler dealing with 8 GPIO
768 * pins. */ 776 * pins. */
769 for (i = 0; i < 4; i++) { 777 for (i = 0; i < 4; i++) {
770 int irq; 778 int irq = platform_get_irq(pdev, i);
771 irq = platform_get_irq(pdev, i); 779
772 if (irq < 0) 780 if (irq < 0)
773 continue; 781 continue;
774 irq_set_handler_data(irq, mvchip); 782 irq_set_handler_data(irq, mvchip);
@@ -778,14 +786,16 @@ static int mvebu_gpio_probe(struct platform_device *pdev)
778 mvchip->irqbase = irq_alloc_descs(-1, 0, ngpios, -1); 786 mvchip->irqbase = irq_alloc_descs(-1, 0, ngpios, -1);
779 if (mvchip->irqbase < 0) { 787 if (mvchip->irqbase < 0) {
780 dev_err(&pdev->dev, "no irqs\n"); 788 dev_err(&pdev->dev, "no irqs\n");
781 return mvchip->irqbase; 789 err = mvchip->irqbase;
790 goto err_gpiochip_add;
782 } 791 }
783 792
784 gc = irq_alloc_generic_chip("mvebu_gpio_irq", 2, mvchip->irqbase, 793 gc = irq_alloc_generic_chip("mvebu_gpio_irq", 2, mvchip->irqbase,
785 mvchip->membase, handle_level_irq); 794 mvchip->membase, handle_level_irq);
786 if (!gc) { 795 if (!gc) {
787 dev_err(&pdev->dev, "Cannot allocate generic irq_chip\n"); 796 dev_err(&pdev->dev, "Cannot allocate generic irq_chip\n");
788 return -ENOMEM; 797 err = -ENOMEM;
798 goto err_gpiochip_add;
789 } 799 }
790 800
791 gc->private = mvchip; 801 gc->private = mvchip;
@@ -816,18 +826,26 @@ static int mvebu_gpio_probe(struct platform_device *pdev)
816 if (!mvchip->domain) { 826 if (!mvchip->domain) {
817 dev_err(&pdev->dev, "couldn't allocate irq domain %s (DT).\n", 827 dev_err(&pdev->dev, "couldn't allocate irq domain %s (DT).\n",
818 mvchip->chip.label); 828 mvchip->chip.label);
819 irq_remove_generic_chip(gc, IRQ_MSK(ngpios), IRQ_NOREQUEST, 829 err = -ENODEV;
820 IRQ_LEVEL | IRQ_NOPROBE); 830 goto err_generic_chip;
821 kfree(gc);
822 return -ENODEV;
823 } 831 }
824 832
825 return 0; 833 return 0;
834
835err_generic_chip:
836 irq_remove_generic_chip(gc, IRQ_MSK(ngpios), IRQ_NOREQUEST,
837 IRQ_LEVEL | IRQ_NOPROBE);
838 kfree(gc);
839
840err_gpiochip_add:
841 gpiochip_remove(&mvchip->chip);
842
843 return err;
826} 844}
827 845
828static struct platform_driver mvebu_gpio_driver = { 846static struct platform_driver mvebu_gpio_driver = {
829 .driver = { 847 .driver = {
830 .name = "mvebu-gpio", 848 .name = "mvebu-gpio",
831 .of_match_table = mvebu_gpio_of_match, 849 .of_match_table = mvebu_gpio_of_match,
832 }, 850 },
833 .probe = mvebu_gpio_probe, 851 .probe = mvebu_gpio_probe,
diff --git a/drivers/gpio/gpio-pxa.c b/drivers/gpio/gpio-pxa.c
index ad3feec0075e..2fdb04b6f101 100644
--- a/drivers/gpio/gpio-pxa.c
+++ b/drivers/gpio/gpio-pxa.c
@@ -17,6 +17,7 @@
17#include <linux/gpio.h> 17#include <linux/gpio.h>
18#include <linux/gpio-pxa.h> 18#include <linux/gpio-pxa.h>
19#include <linux/init.h> 19#include <linux/init.h>
20#include <linux/interrupt.h>
20#include <linux/irq.h> 21#include <linux/irq.h>
21#include <linux/irqdomain.h> 22#include <linux/irqdomain.h>
22#include <linux/irqchip/chained_irq.h> 23#include <linux/irqchip/chained_irq.h>
@@ -27,8 +28,6 @@
27#include <linux/syscore_ops.h> 28#include <linux/syscore_ops.h>
28#include <linux/slab.h> 29#include <linux/slab.h>
29 30
30#include <mach/irqs.h>
31
32/* 31/*
33 * We handle the GPIOs by banks, each bank covers up to 32 GPIOs with 32 * We handle the GPIOs by banks, each bank covers up to 32 GPIOs with
34 * one set of registers. The register offsets are organized below: 33 * one set of registers. The register offsets are organized below:
@@ -42,9 +41,12 @@
42 * BANK 4 - 0x0104 0x0110 0x011C 0x0128 0x0134 0x0140 0x014C 41 * BANK 4 - 0x0104 0x0110 0x011C 0x0128 0x0134 0x0140 0x014C
43 * BANK 5 - 0x0108 0x0114 0x0120 0x012C 0x0138 0x0144 0x0150 42 * BANK 5 - 0x0108 0x0114 0x0120 0x012C 0x0138 0x0144 0x0150
44 * 43 *
44 * BANK 6 - 0x0200 0x020C 0x0218 0x0224 0x0230 0x023C 0x0248
45 *
45 * NOTE: 46 * NOTE:
46 * BANK 3 is only available on PXA27x and later processors. 47 * BANK 3 is only available on PXA27x and later processors.
47 * BANK 4 and 5 are only available on PXA935 48 * BANK 4 and 5 are only available on PXA935, PXA1928
49 * BANK 6 is only available on PXA1928
48 */ 50 */
49 51
50#define GPLR_OFFSET 0x00 52#define GPLR_OFFSET 0x00
@@ -57,7 +59,8 @@
57#define GAFR_OFFSET 0x54 59#define GAFR_OFFSET 0x54
58#define ED_MASK_OFFSET 0x9C /* GPIO edge detection for AP side */ 60#define ED_MASK_OFFSET 0x9C /* GPIO edge detection for AP side */
59 61
60#define BANK_OFF(n) (((n) < 3) ? (n) << 2 : 0x100 + (((n) - 3) << 2)) 62#define BANK_OFF(n) (((n) < 3) ? (n) << 2 : ((n) > 5 ? 0x200 : 0x100) \
63 + (((n) % 3) << 2))
61 64
62int pxa_last_gpio; 65int pxa_last_gpio;
63static int irq_base; 66static int irq_base;
@@ -93,6 +96,7 @@ enum pxa_gpio_type {
93 PXA93X_GPIO, 96 PXA93X_GPIO,
94 MMP_GPIO = 0x10, 97 MMP_GPIO = 0x10,
95 MMP2_GPIO, 98 MMP2_GPIO,
99 PXA1928_GPIO,
96}; 100};
97 101
98struct pxa_gpio_id { 102struct pxa_gpio_id {
@@ -140,6 +144,11 @@ static struct pxa_gpio_id mmp2_id = {
140 .gpio_nums = 192, 144 .gpio_nums = 192,
141}; 145};
142 146
147static struct pxa_gpio_id pxa1928_id = {
148 .type = PXA1928_GPIO,
149 .gpio_nums = 224,
150};
151
143#define for_each_gpio_chip(i, c) \ 152#define for_each_gpio_chip(i, c) \
144 for (i = 0, c = &pxa_gpio_chips[0]; i <= pxa_last_gpio; i += 32, c++) 153 for (i = 0, c = &pxa_gpio_chips[0]; i <= pxa_last_gpio; i += 32, c++)
145 154
@@ -487,6 +496,7 @@ static int pxa_gpio_nums(struct platform_device *pdev)
487 case PXA93X_GPIO: 496 case PXA93X_GPIO:
488 case MMP_GPIO: 497 case MMP_GPIO:
489 case MMP2_GPIO: 498 case MMP2_GPIO:
499 case PXA1928_GPIO:
490 gpio_type = pxa_id->type; 500 gpio_type = pxa_id->type;
491 count = pxa_id->gpio_nums - 1; 501 count = pxa_id->gpio_nums - 1;
492 break; 502 break;
@@ -506,6 +516,7 @@ static const struct of_device_id pxa_gpio_dt_ids[] = {
506 { .compatible = "marvell,pxa93x-gpio", .data = &pxa93x_id, }, 516 { .compatible = "marvell,pxa93x-gpio", .data = &pxa93x_id, },
507 { .compatible = "marvell,mmp-gpio", .data = &mmp_id, }, 517 { .compatible = "marvell,mmp-gpio", .data = &mmp_id, },
508 { .compatible = "marvell,mmp2-gpio", .data = &mmp2_id, }, 518 { .compatible = "marvell,mmp2-gpio", .data = &mmp2_id, },
519 { .compatible = "marvell,pxa1928-gpio", .data = &pxa1928_id, },
509 {} 520 {}
510}; 521};
511 522
@@ -629,19 +640,18 @@ static int pxa_gpio_probe(struct platform_device *pdev)
629 } 640 }
630 641
631 if (!use_of) { 642 if (!use_of) {
632#ifdef CONFIG_ARCH_PXA 643 if (irq0 > 0) {
633 irq = gpio_to_irq(0); 644 irq = gpio_to_irq(0);
634 irq_set_chip_and_handler(irq, &pxa_muxed_gpio_chip, 645 irq_set_chip_and_handler(irq, &pxa_muxed_gpio_chip,
635 handle_edge_irq); 646 handle_edge_irq);
636 set_irq_flags(irq, IRQF_VALID | IRQF_PROBE); 647 set_irq_flags(irq, IRQF_VALID | IRQF_PROBE);
637 irq_set_chained_handler(IRQ_GPIO0, pxa_gpio_demux_handler); 648 }
638 649 if (irq1 > 0) {
639 irq = gpio_to_irq(1); 650 irq = gpio_to_irq(1);
640 irq_set_chip_and_handler(irq, &pxa_muxed_gpio_chip, 651 irq_set_chip_and_handler(irq, &pxa_muxed_gpio_chip,
641 handle_edge_irq); 652 handle_edge_irq);
642 set_irq_flags(irq, IRQF_VALID | IRQF_PROBE); 653 set_irq_flags(irq, IRQF_VALID | IRQF_PROBE);
643 irq_set_chained_handler(IRQ_GPIO1, pxa_gpio_demux_handler); 654 }
644#endif
645 655
646 for (irq = gpio_to_irq(gpio_offset); 656 for (irq = gpio_to_irq(gpio_offset);
647 irq <= gpio_to_irq(pxa_last_gpio); irq++) { 657 irq <= gpio_to_irq(pxa_last_gpio); irq++) {
@@ -649,13 +659,13 @@ static int pxa_gpio_probe(struct platform_device *pdev)
649 handle_edge_irq); 659 handle_edge_irq);
650 set_irq_flags(irq, IRQF_VALID | IRQF_PROBE); 660 set_irq_flags(irq, IRQF_VALID | IRQF_PROBE);
651 } 661 }
652 } else {
653 if (irq0 > 0)
654 irq_set_chained_handler(irq0, pxa_gpio_demux_handler);
655 if (irq1 > 0)
656 irq_set_chained_handler(irq1, pxa_gpio_demux_handler);
657 } 662 }
658 663
664 if (irq0 > 0)
665 irq_set_chained_handler(irq0, pxa_gpio_demux_handler);
666 if (irq1 > 0)
667 irq_set_chained_handler(irq1, pxa_gpio_demux_handler);
668
659 irq_set_chained_handler(irq_mux, pxa_gpio_demux_handler); 669 irq_set_chained_handler(irq_mux, pxa_gpio_demux_handler);
660 return 0; 670 return 0;
661} 671}
@@ -668,6 +678,7 @@ static const struct platform_device_id gpio_id_table[] = {
668 { "pxa93x-gpio", (unsigned long)&pxa93x_id }, 678 { "pxa93x-gpio", (unsigned long)&pxa93x_id },
669 { "mmp-gpio", (unsigned long)&mmp_id }, 679 { "mmp-gpio", (unsigned long)&mmp_id },
670 { "mmp2-gpio", (unsigned long)&mmp2_id }, 680 { "mmp2-gpio", (unsigned long)&mmp2_id },
681 { "pxa1928-gpio", (unsigned long)&pxa1928_id },
671 { }, 682 { },
672}; 683};
673 684
diff --git a/drivers/gpio/gpio-rcar.c b/drivers/gpio/gpio-rcar.c
index 584484e3f1e3..c49522efa7b3 100644
--- a/drivers/gpio/gpio-rcar.c
+++ b/drivers/gpio/gpio-rcar.c
@@ -21,7 +21,6 @@
21#include <linux/io.h> 21#include <linux/io.h>
22#include <linux/ioport.h> 22#include <linux/ioport.h>
23#include <linux/irq.h> 23#include <linux/irq.h>
24#include <linux/irqdomain.h>
25#include <linux/module.h> 24#include <linux/module.h>
26#include <linux/of.h> 25#include <linux/of.h>
27#include <linux/pinctrl/consumer.h> 26#include <linux/pinctrl/consumer.h>
@@ -38,7 +37,6 @@ struct gpio_rcar_priv {
38 struct platform_device *pdev; 37 struct platform_device *pdev;
39 struct gpio_chip gpio_chip; 38 struct gpio_chip gpio_chip;
40 struct irq_chip irq_chip; 39 struct irq_chip irq_chip;
41 struct irq_domain *irq_domain;
42}; 40};
43 41
44#define IOINTSEL 0x00 42#define IOINTSEL 0x00
@@ -82,14 +80,18 @@ static void gpio_rcar_modify_bit(struct gpio_rcar_priv *p, int offs,
82 80
83static void gpio_rcar_irq_disable(struct irq_data *d) 81static void gpio_rcar_irq_disable(struct irq_data *d)
84{ 82{
85 struct gpio_rcar_priv *p = irq_data_get_irq_chip_data(d); 83 struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
84 struct gpio_rcar_priv *p = container_of(gc, struct gpio_rcar_priv,
85 gpio_chip);
86 86
87 gpio_rcar_write(p, INTMSK, ~BIT(irqd_to_hwirq(d))); 87 gpio_rcar_write(p, INTMSK, ~BIT(irqd_to_hwirq(d)));
88} 88}
89 89
90static void gpio_rcar_irq_enable(struct irq_data *d) 90static void gpio_rcar_irq_enable(struct irq_data *d)
91{ 91{
92 struct gpio_rcar_priv *p = irq_data_get_irq_chip_data(d); 92 struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
93 struct gpio_rcar_priv *p = container_of(gc, struct gpio_rcar_priv,
94 gpio_chip);
93 95
94 gpio_rcar_write(p, MSKCLR, BIT(irqd_to_hwirq(d))); 96 gpio_rcar_write(p, MSKCLR, BIT(irqd_to_hwirq(d)));
95} 97}
@@ -131,7 +133,9 @@ static void gpio_rcar_config_interrupt_input_mode(struct gpio_rcar_priv *p,
131 133
132static int gpio_rcar_irq_set_type(struct irq_data *d, unsigned int type) 134static int gpio_rcar_irq_set_type(struct irq_data *d, unsigned int type)
133{ 135{
134 struct gpio_rcar_priv *p = irq_data_get_irq_chip_data(d); 136 struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
137 struct gpio_rcar_priv *p = container_of(gc, struct gpio_rcar_priv,
138 gpio_chip);
135 unsigned int hwirq = irqd_to_hwirq(d); 139 unsigned int hwirq = irqd_to_hwirq(d);
136 140
137 dev_dbg(&p->pdev->dev, "sense irq = %d, type = %d\n", hwirq, type); 141 dev_dbg(&p->pdev->dev, "sense irq = %d, type = %d\n", hwirq, type);
@@ -175,7 +179,8 @@ static irqreturn_t gpio_rcar_irq_handler(int irq, void *dev_id)
175 gpio_rcar_read(p, INTMSK))) { 179 gpio_rcar_read(p, INTMSK))) {
176 offset = __ffs(pending); 180 offset = __ffs(pending);
177 gpio_rcar_write(p, INTCLR, BIT(offset)); 181 gpio_rcar_write(p, INTCLR, BIT(offset));
178 generic_handle_irq(irq_find_mapping(p->irq_domain, offset)); 182 generic_handle_irq(irq_find_mapping(p->gpio_chip.irqdomain,
183 offset));
179 irqs_handled++; 184 irqs_handled++;
180 } 185 }
181 186
@@ -265,29 +270,6 @@ static int gpio_rcar_direction_output(struct gpio_chip *chip, unsigned offset,
265 return 0; 270 return 0;
266} 271}
267 272
268static int gpio_rcar_to_irq(struct gpio_chip *chip, unsigned offset)
269{
270 return irq_create_mapping(gpio_to_priv(chip)->irq_domain, offset);
271}
272
273static int gpio_rcar_irq_domain_map(struct irq_domain *h, unsigned int irq,
274 irq_hw_number_t hwirq)
275{
276 struct gpio_rcar_priv *p = h->host_data;
277
278 dev_dbg(&p->pdev->dev, "map hw irq = %d, irq = %d\n", (int)hwirq, irq);
279
280 irq_set_chip_data(irq, h->host_data);
281 irq_set_chip_and_handler(irq, &p->irq_chip, handle_level_irq);
282 set_irq_flags(irq, IRQF_VALID); /* kill me now */
283 return 0;
284}
285
286static struct irq_domain_ops gpio_rcar_irq_domain_ops = {
287 .map = gpio_rcar_irq_domain_map,
288 .xlate = irq_domain_xlate_twocell,
289};
290
291struct gpio_rcar_info { 273struct gpio_rcar_info {
292 bool has_both_edge_trigger; 274 bool has_both_edge_trigger;
293}; 275};
@@ -372,10 +354,8 @@ static int gpio_rcar_probe(struct platform_device *pdev)
372 int ret; 354 int ret;
373 355
374 p = devm_kzalloc(dev, sizeof(*p), GFP_KERNEL); 356 p = devm_kzalloc(dev, sizeof(*p), GFP_KERNEL);
375 if (!p) { 357 if (!p)
376 ret = -ENOMEM; 358 return -ENOMEM;
377 goto err0;
378 }
379 359
380 p->pdev = pdev; 360 p->pdev = pdev;
381 spin_lock_init(&p->lock); 361 spin_lock_init(&p->lock);
@@ -413,7 +393,6 @@ static int gpio_rcar_probe(struct platform_device *pdev)
413 gpio_chip->get = gpio_rcar_get; 393 gpio_chip->get = gpio_rcar_get;
414 gpio_chip->direction_output = gpio_rcar_direction_output; 394 gpio_chip->direction_output = gpio_rcar_direction_output;
415 gpio_chip->set = gpio_rcar_set; 395 gpio_chip->set = gpio_rcar_set;
416 gpio_chip->to_irq = gpio_rcar_to_irq;
417 gpio_chip->label = name; 396 gpio_chip->label = name;
418 gpio_chip->dev = dev; 397 gpio_chip->dev = dev;
419 gpio_chip->owner = THIS_MODULE; 398 gpio_chip->owner = THIS_MODULE;
@@ -428,16 +407,19 @@ static int gpio_rcar_probe(struct platform_device *pdev)
428 irq_chip->flags = IRQCHIP_SKIP_SET_WAKE | IRQCHIP_SET_TYPE_MASKED 407 irq_chip->flags = IRQCHIP_SKIP_SET_WAKE | IRQCHIP_SET_TYPE_MASKED
429 | IRQCHIP_MASK_ON_SUSPEND; 408 | IRQCHIP_MASK_ON_SUSPEND;
430 409
431 p->irq_domain = irq_domain_add_simple(pdev->dev.of_node, 410 ret = gpiochip_add(gpio_chip);
432 p->config.number_of_pins, 411 if (ret) {
433 p->config.irq_base, 412 dev_err(dev, "failed to add GPIO controller\n");
434 &gpio_rcar_irq_domain_ops, p);
435 if (!p->irq_domain) {
436 ret = -ENXIO;
437 dev_err(dev, "cannot initialize irq domain\n");
438 goto err0; 413 goto err0;
439 } 414 }
440 415
416 ret = gpiochip_irqchip_add(&p->gpio_chip, irq_chip, p->config.irq_base,
417 handle_level_irq, IRQ_TYPE_NONE);
418 if (ret) {
419 dev_err(dev, "cannot add irqchip\n");
420 goto err1;
421 }
422
441 if (devm_request_irq(dev, irq->start, gpio_rcar_irq_handler, 423 if (devm_request_irq(dev, irq->start, gpio_rcar_irq_handler,
442 IRQF_SHARED, name, p)) { 424 IRQF_SHARED, name, p)) {
443 dev_err(dev, "failed to request IRQ\n"); 425 dev_err(dev, "failed to request IRQ\n");
@@ -445,17 +427,11 @@ static int gpio_rcar_probe(struct platform_device *pdev)
445 goto err1; 427 goto err1;
446 } 428 }
447 429
448 ret = gpiochip_add(gpio_chip);
449 if (ret) {
450 dev_err(dev, "failed to add GPIO controller\n");
451 goto err1;
452 }
453
454 dev_info(dev, "driving %d GPIOs\n", p->config.number_of_pins); 430 dev_info(dev, "driving %d GPIOs\n", p->config.number_of_pins);
455 431
456 /* warn in case of mismatch if irq base is specified */ 432 /* warn in case of mismatch if irq base is specified */
457 if (p->config.irq_base) { 433 if (p->config.irq_base) {
458 ret = irq_find_mapping(p->irq_domain, 0); 434 ret = irq_find_mapping(p->gpio_chip.irqdomain, 0);
459 if (p->config.irq_base != ret) 435 if (p->config.irq_base != ret)
460 dev_warn(dev, "irq base mismatch (%u/%u)\n", 436 dev_warn(dev, "irq base mismatch (%u/%u)\n",
461 p->config.irq_base, ret); 437 p->config.irq_base, ret);
@@ -471,7 +447,7 @@ static int gpio_rcar_probe(struct platform_device *pdev)
471 return 0; 447 return 0;
472 448
473err1: 449err1:
474 irq_domain_remove(p->irq_domain); 450 gpiochip_remove(&p->gpio_chip);
475err0: 451err0:
476 pm_runtime_put(dev); 452 pm_runtime_put(dev);
477 pm_runtime_disable(dev); 453 pm_runtime_disable(dev);
@@ -484,7 +460,6 @@ static int gpio_rcar_remove(struct platform_device *pdev)
484 460
485 gpiochip_remove(&p->gpio_chip); 461 gpiochip_remove(&p->gpio_chip);
486 462
487 irq_domain_remove(p->irq_domain);
488 pm_runtime_put(&pdev->dev); 463 pm_runtime_put(&pdev->dev);
489 pm_runtime_disable(&pdev->dev); 464 pm_runtime_disable(&pdev->dev);
490 return 0; 465 return 0;
diff --git a/drivers/gpio/gpio-sa1100.c b/drivers/gpio/gpio-sa1100.c
index a90be34e4d5c..bec397a60204 100644
--- a/drivers/gpio/gpio-sa1100.c
+++ b/drivers/gpio/gpio-sa1100.c
@@ -11,6 +11,7 @@
11#include <linux/init.h> 11#include <linux/init.h>
12#include <linux/module.h> 12#include <linux/module.h>
13#include <linux/io.h> 13#include <linux/io.h>
14#include <linux/syscore_ops.h>
14#include <mach/hardware.h> 15#include <mach/hardware.h>
15#include <mach/irqs.h> 16#include <mach/irqs.h>
16 17
@@ -50,7 +51,7 @@ static int sa1100_direction_output(struct gpio_chip *chip, unsigned offset, int
50 51
51static int sa1100_to_irq(struct gpio_chip *chip, unsigned offset) 52static int sa1100_to_irq(struct gpio_chip *chip, unsigned offset)
52{ 53{
53 return offset < 11 ? (IRQ_GPIO0 + offset) : (IRQ_GPIO11 - 11 + offset); 54 return IRQ_GPIO0 + offset;
54} 55}
55 56
56static struct gpio_chip sa1100_gpio_chip = { 57static struct gpio_chip sa1100_gpio_chip = {
@@ -64,7 +65,203 @@ static struct gpio_chip sa1100_gpio_chip = {
64 .ngpio = GPIO_MAX + 1, 65 .ngpio = GPIO_MAX + 1,
65}; 66};
66 67
68/*
69 * SA1100 GPIO edge detection for IRQs:
70 * IRQs are generated on Falling-Edge, Rising-Edge, or both.
71 * Use this instead of directly setting GRER/GFER.
72 */
73static int GPIO_IRQ_rising_edge;
74static int GPIO_IRQ_falling_edge;
75static int GPIO_IRQ_mask;
76
77static int sa1100_gpio_type(struct irq_data *d, unsigned int type)
78{
79 unsigned int mask;
80
81 mask = BIT(d->hwirq);
82
83 if (type == IRQ_TYPE_PROBE) {
84 if ((GPIO_IRQ_rising_edge | GPIO_IRQ_falling_edge) & mask)
85 return 0;
86 type = IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING;
87 }
88
89 if (type & IRQ_TYPE_EDGE_RISING)
90 GPIO_IRQ_rising_edge |= mask;
91 else
92 GPIO_IRQ_rising_edge &= ~mask;
93 if (type & IRQ_TYPE_EDGE_FALLING)
94 GPIO_IRQ_falling_edge |= mask;
95 else
96 GPIO_IRQ_falling_edge &= ~mask;
97
98 GRER = GPIO_IRQ_rising_edge & GPIO_IRQ_mask;
99 GFER = GPIO_IRQ_falling_edge & GPIO_IRQ_mask;
100
101 return 0;
102}
103
104/*
105 * GPIO IRQs must be acknowledged.
106 */
107static void sa1100_gpio_ack(struct irq_data *d)
108{
109 GEDR = BIT(d->hwirq);
110}
111
112static void sa1100_gpio_mask(struct irq_data *d)
113{
114 unsigned int mask = BIT(d->hwirq);
115
116 GPIO_IRQ_mask &= ~mask;
117
118 GRER &= ~mask;
119 GFER &= ~mask;
120}
121
122static void sa1100_gpio_unmask(struct irq_data *d)
123{
124 unsigned int mask = BIT(d->hwirq);
125
126 GPIO_IRQ_mask |= mask;
127
128 GRER = GPIO_IRQ_rising_edge & GPIO_IRQ_mask;
129 GFER = GPIO_IRQ_falling_edge & GPIO_IRQ_mask;
130}
131
132static int sa1100_gpio_wake(struct irq_data *d, unsigned int on)
133{
134 if (on)
135 PWER |= BIT(d->hwirq);
136 else
137 PWER &= ~BIT(d->hwirq);
138 return 0;
139}
140
141/*
142 * This is for GPIO IRQs
143 */
144static struct irq_chip sa1100_gpio_irq_chip = {
145 .name = "GPIO",
146 .irq_ack = sa1100_gpio_ack,
147 .irq_mask = sa1100_gpio_mask,
148 .irq_unmask = sa1100_gpio_unmask,
149 .irq_set_type = sa1100_gpio_type,
150 .irq_set_wake = sa1100_gpio_wake,
151};
152
153static int sa1100_gpio_irqdomain_map(struct irq_domain *d,
154 unsigned int irq, irq_hw_number_t hwirq)
155{
156 irq_set_chip_and_handler(irq, &sa1100_gpio_irq_chip,
157 handle_edge_irq);
158 set_irq_flags(irq, IRQF_VALID | IRQF_PROBE);
159
160 return 0;
161}
162
163static struct irq_domain_ops sa1100_gpio_irqdomain_ops = {
164 .map = sa1100_gpio_irqdomain_map,
165 .xlate = irq_domain_xlate_onetwocell,
166};
167
168static struct irq_domain *sa1100_gpio_irqdomain;
169
170/*
171 * IRQ 0-11 (GPIO) handler. We enter here with the
172 * irq_controller_lock held, and IRQs disabled. Decode the IRQ
173 * and call the handler.
174 */
175static void
176sa1100_gpio_handler(unsigned int irq, struct irq_desc *desc)
177{
178 unsigned int mask;
179
180 mask = GEDR;
181 do {
182 /*
183 * clear down all currently active IRQ sources.
184 * We will be processing them all.
185 */
186 GEDR = mask;
187
188 irq = IRQ_GPIO0;
189 do {
190 if (mask & 1)
191 generic_handle_irq(irq);
192 mask >>= 1;
193 irq++;
194 } while (mask);
195
196 mask = GEDR;
197 } while (mask);
198}
199
200static int sa1100_gpio_suspend(void)
201{
202 /*
203 * Set the appropriate edges for wakeup.
204 */
205 GRER = PWER & GPIO_IRQ_rising_edge;
206 GFER = PWER & GPIO_IRQ_falling_edge;
207
208 /*
209 * Clear any pending GPIO interrupts.
210 */
211 GEDR = GEDR;
212
213 return 0;
214}
215
216static void sa1100_gpio_resume(void)
217{
218 GRER = GPIO_IRQ_rising_edge & GPIO_IRQ_mask;
219 GFER = GPIO_IRQ_falling_edge & GPIO_IRQ_mask;
220}
221
222static struct syscore_ops sa1100_gpio_syscore_ops = {
223 .suspend = sa1100_gpio_suspend,
224 .resume = sa1100_gpio_resume,
225};
226
227static int __init sa1100_gpio_init_devicefs(void)
228{
229 register_syscore_ops(&sa1100_gpio_syscore_ops);
230 return 0;
231}
232
233device_initcall(sa1100_gpio_init_devicefs);
234
67void __init sa1100_init_gpio(void) 235void __init sa1100_init_gpio(void)
68{ 236{
237 /* clear all GPIO edge detects */
238 GFER = 0;
239 GRER = 0;
240 GEDR = -1;
241
69 gpiochip_add(&sa1100_gpio_chip); 242 gpiochip_add(&sa1100_gpio_chip);
243
244 sa1100_gpio_irqdomain = irq_domain_add_simple(NULL,
245 28, IRQ_GPIO0,
246 &sa1100_gpio_irqdomain_ops, NULL);
247
248 /*
249 * Install handlers for GPIO 0-10 edge detect interrupts
250 */
251 irq_set_chained_handler(IRQ_GPIO0_SC, sa1100_gpio_handler);
252 irq_set_chained_handler(IRQ_GPIO1_SC, sa1100_gpio_handler);
253 irq_set_chained_handler(IRQ_GPIO2_SC, sa1100_gpio_handler);
254 irq_set_chained_handler(IRQ_GPIO3_SC, sa1100_gpio_handler);
255 irq_set_chained_handler(IRQ_GPIO4_SC, sa1100_gpio_handler);
256 irq_set_chained_handler(IRQ_GPIO5_SC, sa1100_gpio_handler);
257 irq_set_chained_handler(IRQ_GPIO6_SC, sa1100_gpio_handler);
258 irq_set_chained_handler(IRQ_GPIO7_SC, sa1100_gpio_handler);
259 irq_set_chained_handler(IRQ_GPIO8_SC, sa1100_gpio_handler);
260 irq_set_chained_handler(IRQ_GPIO9_SC, sa1100_gpio_handler);
261 irq_set_chained_handler(IRQ_GPIO10_SC, sa1100_gpio_handler);
262 /*
263 * Install handler for GPIO 11-27 edge detect interrupts
264 */
265 irq_set_chained_handler(IRQ_GPIO11_27, sa1100_gpio_handler);
266
70} 267}
diff --git a/drivers/gpio/gpio-sch.c b/drivers/gpio/gpio-sch.c
index 0a0cf1307d2f..b72906f5b999 100644
--- a/drivers/gpio/gpio-sch.c
+++ b/drivers/gpio/gpio-sch.c
@@ -41,7 +41,7 @@ struct sch_gpio {
41 unsigned short resume_base; 41 unsigned short resume_base;
42}; 42};
43 43
44#define to_sch_gpio(c) container_of(c, struct sch_gpio, chip) 44#define to_sch_gpio(gc) container_of(gc, struct sch_gpio, chip)
45 45
46static unsigned sch_gpio_offset(struct sch_gpio *sch, unsigned gpio, 46static unsigned sch_gpio_offset(struct sch_gpio *sch, unsigned gpio,
47 unsigned reg) 47 unsigned reg)
@@ -63,75 +63,59 @@ static unsigned sch_gpio_bit(struct sch_gpio *sch, unsigned gpio)
63 return gpio % 8; 63 return gpio % 8;
64} 64}
65 65
66static void sch_gpio_enable(struct sch_gpio *sch, unsigned gpio) 66static int sch_gpio_reg_get(struct gpio_chip *gc, unsigned gpio, unsigned reg)
67{ 67{
68 struct sch_gpio *sch = to_sch_gpio(gc);
68 unsigned short offset, bit; 69 unsigned short offset, bit;
69 u8 enable; 70 u8 reg_val;
70
71 spin_lock(&sch->lock);
72 71
73 offset = sch_gpio_offset(sch, gpio, GEN); 72 offset = sch_gpio_offset(sch, gpio, reg);
74 bit = sch_gpio_bit(sch, gpio); 73 bit = sch_gpio_bit(sch, gpio);
75 74
76 enable = inb(sch->iobase + offset); 75 reg_val = !!(inb(sch->iobase + offset) & BIT(bit));
77 if (!(enable & (1 << bit)))
78 outb(enable | (1 << bit), sch->iobase + offset);
79 76
80 spin_unlock(&sch->lock); 77 return reg_val;
81} 78}
82 79
83static int sch_gpio_direction_in(struct gpio_chip *gc, unsigned gpio_num) 80static void sch_gpio_reg_set(struct gpio_chip *gc, unsigned gpio, unsigned reg,
81 int val)
84{ 82{
85 struct sch_gpio *sch = to_sch_gpio(gc); 83 struct sch_gpio *sch = to_sch_gpio(gc);
86 u8 curr_dirs;
87 unsigned short offset, bit; 84 unsigned short offset, bit;
85 u8 reg_val;
88 86
89 spin_lock(&sch->lock); 87 offset = sch_gpio_offset(sch, gpio, reg);
88 bit = sch_gpio_bit(sch, gpio);
90 89
91 offset = sch_gpio_offset(sch, gpio_num, GIO); 90 reg_val = inb(sch->iobase + offset);
92 bit = sch_gpio_bit(sch, gpio_num);
93 91
94 curr_dirs = inb(sch->iobase + offset); 92 if (val)
93 outb(reg_val | BIT(bit), sch->iobase + offset);
94 else
95 outb((reg_val & ~BIT(bit)), sch->iobase + offset);
96}
95 97
96 if (!(curr_dirs & (1 << bit))) 98static int sch_gpio_direction_in(struct gpio_chip *gc, unsigned gpio_num)
97 outb(curr_dirs | (1 << bit), sch->iobase + offset); 99{
100 struct sch_gpio *sch = to_sch_gpio(gc);
98 101
102 spin_lock(&sch->lock);
103 sch_gpio_reg_set(gc, gpio_num, GIO, 1);
99 spin_unlock(&sch->lock); 104 spin_unlock(&sch->lock);
100 return 0; 105 return 0;
101} 106}
102 107
103static int sch_gpio_get(struct gpio_chip *gc, unsigned gpio_num) 108static int sch_gpio_get(struct gpio_chip *gc, unsigned gpio_num)
104{ 109{
105 struct sch_gpio *sch = to_sch_gpio(gc); 110 return sch_gpio_reg_get(gc, gpio_num, GLV);
106 int res;
107 unsigned short offset, bit;
108
109 offset = sch_gpio_offset(sch, gpio_num, GLV);
110 bit = sch_gpio_bit(sch, gpio_num);
111
112 res = !!(inb(sch->iobase + offset) & (1 << bit));
113
114 return res;
115} 111}
116 112
117static void sch_gpio_set(struct gpio_chip *gc, unsigned gpio_num, int val) 113static void sch_gpio_set(struct gpio_chip *gc, unsigned gpio_num, int val)
118{ 114{
119 struct sch_gpio *sch = to_sch_gpio(gc); 115 struct sch_gpio *sch = to_sch_gpio(gc);
120 u8 curr_vals;
121 unsigned short offset, bit;
122 116
123 spin_lock(&sch->lock); 117 spin_lock(&sch->lock);
124 118 sch_gpio_reg_set(gc, gpio_num, GLV, val);
125 offset = sch_gpio_offset(sch, gpio_num, GLV);
126 bit = sch_gpio_bit(sch, gpio_num);
127
128 curr_vals = inb(sch->iobase + offset);
129
130 if (val)
131 outb(curr_vals | (1 << bit), sch->iobase + offset);
132 else
133 outb((curr_vals & ~(1 << bit)), sch->iobase + offset);
134
135 spin_unlock(&sch->lock); 119 spin_unlock(&sch->lock);
136} 120}
137 121
@@ -139,18 +123,9 @@ static int sch_gpio_direction_out(struct gpio_chip *gc, unsigned gpio_num,
139 int val) 123 int val)
140{ 124{
141 struct sch_gpio *sch = to_sch_gpio(gc); 125 struct sch_gpio *sch = to_sch_gpio(gc);
142 u8 curr_dirs;
143 unsigned short offset, bit;
144 126
145 spin_lock(&sch->lock); 127 spin_lock(&sch->lock);
146 128 sch_gpio_reg_set(gc, gpio_num, GIO, 0);
147 offset = sch_gpio_offset(sch, gpio_num, GIO);
148 bit = sch_gpio_bit(sch, gpio_num);
149
150 curr_dirs = inb(sch->iobase + offset);
151 if (curr_dirs & (1 << bit))
152 outb(curr_dirs & ~(1 << bit), sch->iobase + offset);
153
154 spin_unlock(&sch->lock); 129 spin_unlock(&sch->lock);
155 130
156 /* 131 /*
@@ -209,13 +184,13 @@ static int sch_gpio_probe(struct platform_device *pdev)
209 * GPIO7 is configured by the CMC as SLPIOVR 184 * GPIO7 is configured by the CMC as SLPIOVR
210 * Enable GPIO[9:8] core powered gpios explicitly 185 * Enable GPIO[9:8] core powered gpios explicitly
211 */ 186 */
212 sch_gpio_enable(sch, 8); 187 sch_gpio_reg_set(&sch->chip, 8, GEN, 1);
213 sch_gpio_enable(sch, 9); 188 sch_gpio_reg_set(&sch->chip, 9, GEN, 1);
214 /* 189 /*
215 * SUS_GPIO[2:0] enabled by default 190 * SUS_GPIO[2:0] enabled by default
216 * Enable SUS_GPIO3 resume powered gpio explicitly 191 * Enable SUS_GPIO3 resume powered gpio explicitly
217 */ 192 */
218 sch_gpio_enable(sch, 13); 193 sch_gpio_reg_set(&sch->chip, 13, GEN, 1);
219 break; 194 break;
220 195
221 case PCI_DEVICE_ID_INTEL_ITC_LPC: 196 case PCI_DEVICE_ID_INTEL_ITC_LPC:
@@ -230,6 +205,12 @@ static int sch_gpio_probe(struct platform_device *pdev)
230 sch->chip.ngpio = 30; 205 sch->chip.ngpio = 30;
231 break; 206 break;
232 207
208 case PCI_DEVICE_ID_INTEL_QUARK_X1000_ILB:
209 sch->core_base = 0;
210 sch->resume_base = 2;
211 sch->chip.ngpio = 8;
212 break;
213
233 default: 214 default:
234 return -ENODEV; 215 return -ENODEV;
235 } 216 }
diff --git a/drivers/gpio/gpio-stmpe.c b/drivers/gpio/gpio-stmpe.c
index 85c5b1974294..dabfb99dddef 100644
--- a/drivers/gpio/gpio-stmpe.c
+++ b/drivers/gpio/gpio-stmpe.c
@@ -30,7 +30,7 @@ struct stmpe_gpio {
30 struct stmpe *stmpe; 30 struct stmpe *stmpe;
31 struct device *dev; 31 struct device *dev;
32 struct mutex irq_lock; 32 struct mutex irq_lock;
33 unsigned norequest_mask; 33 u32 norequest_mask;
34 /* Caches of interrupt control registers for bus_lock */ 34 /* Caches of interrupt control registers for bus_lock */
35 u8 regs[CACHE_NR_REGS][CACHE_NR_BANKS]; 35 u8 regs[CACHE_NR_REGS][CACHE_NR_BANKS];
36 u8 oldregs[CACHE_NR_REGS][CACHE_NR_BANKS]; 36 u8 oldregs[CACHE_NR_REGS][CACHE_NR_BANKS];
@@ -340,13 +340,10 @@ static int stmpe_gpio_probe(struct platform_device *pdev)
340{ 340{
341 struct stmpe *stmpe = dev_get_drvdata(pdev->dev.parent); 341 struct stmpe *stmpe = dev_get_drvdata(pdev->dev.parent);
342 struct device_node *np = pdev->dev.of_node; 342 struct device_node *np = pdev->dev.of_node;
343 struct stmpe_gpio_platform_data *pdata;
344 struct stmpe_gpio *stmpe_gpio; 343 struct stmpe_gpio *stmpe_gpio;
345 int ret; 344 int ret;
346 int irq = 0; 345 int irq = 0;
347 346
348 pdata = stmpe->pdata->gpio;
349
350 irq = platform_get_irq(pdev, 0); 347 irq = platform_get_irq(pdev, 0);
351 348
352 stmpe_gpio = kzalloc(sizeof(struct stmpe_gpio), GFP_KERNEL); 349 stmpe_gpio = kzalloc(sizeof(struct stmpe_gpio), GFP_KERNEL);
@@ -360,19 +357,14 @@ static int stmpe_gpio_probe(struct platform_device *pdev)
360 stmpe_gpio->chip = template_chip; 357 stmpe_gpio->chip = template_chip;
361 stmpe_gpio->chip.ngpio = stmpe->num_gpios; 358 stmpe_gpio->chip.ngpio = stmpe->num_gpios;
362 stmpe_gpio->chip.dev = &pdev->dev; 359 stmpe_gpio->chip.dev = &pdev->dev;
363#ifdef CONFIG_OF
364 stmpe_gpio->chip.of_node = np; 360 stmpe_gpio->chip.of_node = np;
365#endif
366 stmpe_gpio->chip.base = -1; 361 stmpe_gpio->chip.base = -1;
367 362
368 if (IS_ENABLED(CONFIG_DEBUG_FS)) 363 if (IS_ENABLED(CONFIG_DEBUG_FS))
369 stmpe_gpio->chip.dbg_show = stmpe_dbg_show; 364 stmpe_gpio->chip.dbg_show = stmpe_dbg_show;
370 365
371 if (pdata) 366 of_property_read_u32(np, "st,norequest-mask",
372 stmpe_gpio->norequest_mask = pdata->norequest_mask; 367 &stmpe_gpio->norequest_mask);
373 else if (np)
374 of_property_read_u32(np, "st,norequest-mask",
375 &stmpe_gpio->norequest_mask);
376 368
377 if (irq < 0) 369 if (irq < 0)
378 dev_info(&pdev->dev, 370 dev_info(&pdev->dev,
@@ -414,9 +406,6 @@ static int stmpe_gpio_probe(struct platform_device *pdev)
414 NULL); 406 NULL);
415 } 407 }
416 408
417 if (pdata && pdata->setup)
418 pdata->setup(stmpe, stmpe_gpio->chip.base);
419
420 platform_set_drvdata(pdev, stmpe_gpio); 409 platform_set_drvdata(pdev, stmpe_gpio);
421 410
422 return 0; 411 return 0;
@@ -433,15 +422,9 @@ static int stmpe_gpio_remove(struct platform_device *pdev)
433{ 422{
434 struct stmpe_gpio *stmpe_gpio = platform_get_drvdata(pdev); 423 struct stmpe_gpio *stmpe_gpio = platform_get_drvdata(pdev);
435 struct stmpe *stmpe = stmpe_gpio->stmpe; 424 struct stmpe *stmpe = stmpe_gpio->stmpe;
436 struct stmpe_gpio_platform_data *pdata = stmpe->pdata->gpio;
437
438 if (pdata && pdata->remove)
439 pdata->remove(stmpe, stmpe_gpio->chip.base);
440 425
441 gpiochip_remove(&stmpe_gpio->chip); 426 gpiochip_remove(&stmpe_gpio->chip);
442
443 stmpe_disable(stmpe, STMPE_BLOCK_GPIO); 427 stmpe_disable(stmpe, STMPE_BLOCK_GPIO);
444
445 kfree(stmpe_gpio); 428 kfree(stmpe_gpio);
446 429
447 return 0; 430 return 0;
diff --git a/drivers/gpio/gpio-sx150x.c b/drivers/gpio/gpio-sx150x.c
index bce6c6108f20..458d9d7952b8 100644
--- a/drivers/gpio/gpio-sx150x.c
+++ b/drivers/gpio/gpio-sx150x.c
@@ -23,23 +23,51 @@
23#include <linux/mutex.h> 23#include <linux/mutex.h>
24#include <linux/slab.h> 24#include <linux/slab.h>
25#include <linux/i2c/sx150x.h> 25#include <linux/i2c/sx150x.h>
26#include <linux/of.h>
27#include <linux/of_address.h>
28#include <linux/of_irq.h>
29#include <linux/of_gpio.h>
30#include <linux/of_device.h>
26 31
27#define NO_UPDATE_PENDING -1 32#define NO_UPDATE_PENDING -1
28 33
34/* The chip models of sx150x */
35#define SX150X_456 0
36#define SX150X_789 1
37
38struct sx150x_456_pri {
39 u8 reg_pld_mode;
40 u8 reg_pld_table0;
41 u8 reg_pld_table1;
42 u8 reg_pld_table2;
43 u8 reg_pld_table3;
44 u8 reg_pld_table4;
45 u8 reg_advance;
46};
47
48struct sx150x_789_pri {
49 u8 reg_drain;
50 u8 reg_polarity;
51 u8 reg_clock;
52 u8 reg_misc;
53 u8 reg_reset;
54 u8 ngpios;
55};
56
29struct sx150x_device_data { 57struct sx150x_device_data {
58 u8 model;
30 u8 reg_pullup; 59 u8 reg_pullup;
31 u8 reg_pulldn; 60 u8 reg_pulldn;
32 u8 reg_drain;
33 u8 reg_polarity;
34 u8 reg_dir; 61 u8 reg_dir;
35 u8 reg_data; 62 u8 reg_data;
36 u8 reg_irq_mask; 63 u8 reg_irq_mask;
37 u8 reg_irq_src; 64 u8 reg_irq_src;
38 u8 reg_sense; 65 u8 reg_sense;
39 u8 reg_clock;
40 u8 reg_misc;
41 u8 reg_reset;
42 u8 ngpios; 66 u8 ngpios;
67 union {
68 struct sx150x_456_pri x456;
69 struct sx150x_789_pri x789;
70 } pri;
43}; 71};
44 72
45struct sx150x_chip { 73struct sx150x_chip {
@@ -59,44 +87,79 @@ struct sx150x_chip {
59 87
60static const struct sx150x_device_data sx150x_devices[] = { 88static const struct sx150x_device_data sx150x_devices[] = {
61 [0] = { /* sx1508q */ 89 [0] = { /* sx1508q */
62 .reg_pullup = 0x03, 90 .model = SX150X_789,
63 .reg_pulldn = 0x04, 91 .reg_pullup = 0x03,
64 .reg_drain = 0x05, 92 .reg_pulldn = 0x04,
65 .reg_polarity = 0x06, 93 .reg_dir = 0x07,
66 .reg_dir = 0x07, 94 .reg_data = 0x08,
67 .reg_data = 0x08, 95 .reg_irq_mask = 0x09,
68 .reg_irq_mask = 0x09, 96 .reg_irq_src = 0x0c,
69 .reg_irq_src = 0x0c, 97 .reg_sense = 0x0b,
70 .reg_sense = 0x0b, 98 .pri.x789 = {
71 .reg_clock = 0x0f, 99 .reg_drain = 0x05,
72 .reg_misc = 0x10, 100 .reg_polarity = 0x06,
73 .reg_reset = 0x7d, 101 .reg_clock = 0x0f,
74 .ngpios = 8 102 .reg_misc = 0x10,
103 .reg_reset = 0x7d,
104 },
105 .ngpios = 8,
75 }, 106 },
76 [1] = { /* sx1509q */ 107 [1] = { /* sx1509q */
77 .reg_pullup = 0x07, 108 .model = SX150X_789,
78 .reg_pulldn = 0x09, 109 .reg_pullup = 0x07,
79 .reg_drain = 0x0b, 110 .reg_pulldn = 0x09,
80 .reg_polarity = 0x0d, 111 .reg_dir = 0x0f,
81 .reg_dir = 0x0f, 112 .reg_data = 0x11,
82 .reg_data = 0x11, 113 .reg_irq_mask = 0x13,
83 .reg_irq_mask = 0x13, 114 .reg_irq_src = 0x19,
84 .reg_irq_src = 0x19, 115 .reg_sense = 0x17,
85 .reg_sense = 0x17, 116 .pri.x789 = {
86 .reg_clock = 0x1e, 117 .reg_drain = 0x0b,
87 .reg_misc = 0x1f, 118 .reg_polarity = 0x0d,
88 .reg_reset = 0x7d, 119 .reg_clock = 0x1e,
89 .ngpios = 16 120 .reg_misc = 0x1f,
121 .reg_reset = 0x7d,
122 },
123 .ngpios = 16
124 },
125 [2] = { /* sx1506q */
126 .model = SX150X_456,
127 .reg_pullup = 0x05,
128 .reg_pulldn = 0x07,
129 .reg_dir = 0x03,
130 .reg_data = 0x01,
131 .reg_irq_mask = 0x09,
132 .reg_irq_src = 0x0f,
133 .reg_sense = 0x0d,
134 .pri.x456 = {
135 .reg_pld_mode = 0x21,
136 .reg_pld_table0 = 0x23,
137 .reg_pld_table1 = 0x25,
138 .reg_pld_table2 = 0x27,
139 .reg_pld_table3 = 0x29,
140 .reg_pld_table4 = 0x2b,
141 .reg_advance = 0xad,
142 },
143 .ngpios = 16
90 }, 144 },
91}; 145};
92 146
93static const struct i2c_device_id sx150x_id[] = { 147static const struct i2c_device_id sx150x_id[] = {
94 {"sx1508q", 0}, 148 {"sx1508q", 0},
95 {"sx1509q", 1}, 149 {"sx1509q", 1},
150 {"sx1506q", 2},
96 {} 151 {}
97}; 152};
98MODULE_DEVICE_TABLE(i2c, sx150x_id); 153MODULE_DEVICE_TABLE(i2c, sx150x_id);
99 154
155static const struct of_device_id sx150x_of_match[] = {
156 { .compatible = "semtech,sx1508q" },
157 { .compatible = "semtech,sx1509q" },
158 { .compatible = "semtech,sx1506q" },
159 {},
160};
161MODULE_DEVICE_TABLE(of, sx150x_of_match);
162
100static s32 sx150x_i2c_write(struct i2c_client *client, u8 reg, u8 val) 163static s32 sx150x_i2c_write(struct i2c_client *client, u8 reg, u8 val)
101{ 164{
102 s32 err = i2c_smbus_write_byte_data(client, reg, val); 165 s32 err = i2c_smbus_write_byte_data(client, reg, val);
@@ -191,7 +254,7 @@ static int sx150x_get_io(struct sx150x_chip *chip, unsigned offset)
191static void sx150x_set_oscio(struct sx150x_chip *chip, int val) 254static void sx150x_set_oscio(struct sx150x_chip *chip, int val)
192{ 255{
193 sx150x_i2c_write(chip->client, 256 sx150x_i2c_write(chip->client,
194 chip->dev_cfg->reg_clock, 257 chip->dev_cfg->pri.x789.reg_clock,
195 (val ? 0x1f : 0x10)); 258 (val ? 0x1f : 0x10));
196} 259}
197 260
@@ -293,27 +356,11 @@ static int sx150x_gpio_direction_output(struct gpio_chip *gc,
293 return status; 356 return status;
294} 357}
295 358
296static int sx150x_gpio_to_irq(struct gpio_chip *gc, unsigned offset)
297{
298 struct sx150x_chip *chip;
299
300 chip = container_of(gc, struct sx150x_chip, gpio_chip);
301
302 if (offset >= chip->dev_cfg->ngpios)
303 return -EINVAL;
304
305 if (chip->irq_base < 0)
306 return -EINVAL;
307
308 return chip->irq_base + offset;
309}
310
311static void sx150x_irq_mask(struct irq_data *d) 359static void sx150x_irq_mask(struct irq_data *d)
312{ 360{
313 struct sx150x_chip *chip = irq_data_get_irq_chip_data(d); 361 struct sx150x_chip *chip = irq_data_get_irq_chip_data(d);
314 unsigned n; 362 unsigned n = d->hwirq;
315 363
316 n = d->irq - chip->irq_base;
317 chip->irq_masked |= (1 << n); 364 chip->irq_masked |= (1 << n);
318 chip->irq_update = n; 365 chip->irq_update = n;
319} 366}
@@ -321,9 +368,8 @@ static void sx150x_irq_mask(struct irq_data *d)
321static void sx150x_irq_unmask(struct irq_data *d) 368static void sx150x_irq_unmask(struct irq_data *d)
322{ 369{
323 struct sx150x_chip *chip = irq_data_get_irq_chip_data(d); 370 struct sx150x_chip *chip = irq_data_get_irq_chip_data(d);
324 unsigned n; 371 unsigned n = d->hwirq;
325 372
326 n = d->irq - chip->irq_base;
327 chip->irq_masked &= ~(1 << n); 373 chip->irq_masked &= ~(1 << n);
328 chip->irq_update = n; 374 chip->irq_update = n;
329} 375}
@@ -336,7 +382,7 @@ static int sx150x_irq_set_type(struct irq_data *d, unsigned int flow_type)
336 if (flow_type & (IRQ_TYPE_LEVEL_HIGH | IRQ_TYPE_LEVEL_LOW)) 382 if (flow_type & (IRQ_TYPE_LEVEL_HIGH | IRQ_TYPE_LEVEL_LOW))
337 return -EINVAL; 383 return -EINVAL;
338 384
339 n = d->irq - chip->irq_base; 385 n = d->hwirq;
340 386
341 if (flow_type & IRQ_TYPE_EDGE_RISING) 387 if (flow_type & IRQ_TYPE_EDGE_RISING)
342 val |= 0x1; 388 val |= 0x1;
@@ -371,7 +417,9 @@ static irqreturn_t sx150x_irq_thread_fn(int irq, void *dev_id)
371 val); 417 val);
372 for (n = 0; n < 8; ++n) { 418 for (n = 0; n < 8; ++n) {
373 if (val & (1 << n)) { 419 if (val & (1 << n)) {
374 sub_irq = chip->irq_base + (i * 8) + n; 420 sub_irq = irq_find_mapping(
421 chip->gpio_chip.irqdomain,
422 (i * 8) + n);
375 handle_nested_irq(sub_irq); 423 handle_nested_irq(sub_irq);
376 ++nhandled; 424 ++nhandled;
377 } 425 }
@@ -401,7 +449,7 @@ static void sx150x_irq_bus_sync_unlock(struct irq_data *d)
401 449
402 /* Avoid updates if nothing changed */ 450 /* Avoid updates if nothing changed */
403 if (chip->dev_sense == chip->irq_sense && 451 if (chip->dev_sense == chip->irq_sense &&
404 chip->dev_sense == chip->irq_masked) 452 chip->dev_masked == chip->irq_masked)
405 goto out; 453 goto out;
406 454
407 chip->dev_sense = chip->irq_sense; 455 chip->dev_sense = chip->irq_sense;
@@ -428,15 +476,19 @@ static void sx150x_init_chip(struct sx150x_chip *chip,
428 476
429 chip->client = client; 477 chip->client = client;
430 chip->dev_cfg = &sx150x_devices[driver_data]; 478 chip->dev_cfg = &sx150x_devices[driver_data];
479 chip->gpio_chip.dev = &client->dev;
431 chip->gpio_chip.label = client->name; 480 chip->gpio_chip.label = client->name;
432 chip->gpio_chip.direction_input = sx150x_gpio_direction_input; 481 chip->gpio_chip.direction_input = sx150x_gpio_direction_input;
433 chip->gpio_chip.direction_output = sx150x_gpio_direction_output; 482 chip->gpio_chip.direction_output = sx150x_gpio_direction_output;
434 chip->gpio_chip.get = sx150x_gpio_get; 483 chip->gpio_chip.get = sx150x_gpio_get;
435 chip->gpio_chip.set = sx150x_gpio_set; 484 chip->gpio_chip.set = sx150x_gpio_set;
436 chip->gpio_chip.to_irq = sx150x_gpio_to_irq;
437 chip->gpio_chip.base = pdata->gpio_base; 485 chip->gpio_chip.base = pdata->gpio_base;
438 chip->gpio_chip.can_sleep = true; 486 chip->gpio_chip.can_sleep = true;
439 chip->gpio_chip.ngpio = chip->dev_cfg->ngpios; 487 chip->gpio_chip.ngpio = chip->dev_cfg->ngpios;
488#ifdef CONFIG_OF_GPIO
489 chip->gpio_chip.of_node = client->dev.of_node;
490 chip->gpio_chip.of_gpio_n_cells = 2;
491#endif
440 if (pdata->oscio_is_gpo) 492 if (pdata->oscio_is_gpo)
441 ++chip->gpio_chip.ngpio; 493 ++chip->gpio_chip.ngpio;
442 494
@@ -470,13 +522,13 @@ static int sx150x_reset(struct sx150x_chip *chip)
470 int err; 522 int err;
471 523
472 err = i2c_smbus_write_byte_data(chip->client, 524 err = i2c_smbus_write_byte_data(chip->client,
473 chip->dev_cfg->reg_reset, 525 chip->dev_cfg->pri.x789.reg_reset,
474 0x12); 526 0x12);
475 if (err < 0) 527 if (err < 0)
476 return err; 528 return err;
477 529
478 err = i2c_smbus_write_byte_data(chip->client, 530 err = i2c_smbus_write_byte_data(chip->client,
479 chip->dev_cfg->reg_reset, 531 chip->dev_cfg->pri.x789.reg_reset,
480 0x34); 532 0x34);
481 return err; 533 return err;
482} 534}
@@ -492,9 +544,14 @@ static int sx150x_init_hw(struct sx150x_chip *chip,
492 return err; 544 return err;
493 } 545 }
494 546
495 err = sx150x_i2c_write(chip->client, 547 if (chip->dev_cfg->model == SX150X_789)
496 chip->dev_cfg->reg_misc, 548 err = sx150x_i2c_write(chip->client,
497 0x01); 549 chip->dev_cfg->pri.x789.reg_misc,
550 0x01);
551 else
552 err = sx150x_i2c_write(chip->client,
553 chip->dev_cfg->pri.x456.reg_advance,
554 0x04);
498 if (err < 0) 555 if (err < 0)
499 return err; 556 return err;
500 557
@@ -508,15 +565,27 @@ static int sx150x_init_hw(struct sx150x_chip *chip,
508 if (err < 0) 565 if (err < 0)
509 return err; 566 return err;
510 567
511 err = sx150x_init_io(chip, chip->dev_cfg->reg_drain, 568 if (chip->dev_cfg->model == SX150X_789) {
512 pdata->io_open_drain_ena); 569 err = sx150x_init_io(chip,
513 if (err < 0) 570 chip->dev_cfg->pri.x789.reg_drain,
514 return err; 571 pdata->io_open_drain_ena);
572 if (err < 0)
573 return err;
574
575 err = sx150x_init_io(chip,
576 chip->dev_cfg->pri.x789.reg_polarity,
577 pdata->io_polarity);
578 if (err < 0)
579 return err;
580 } else {
581 /* Set all pins to work in normal mode */
582 err = sx150x_init_io(chip,
583 chip->dev_cfg->pri.x456.reg_pld_mode,
584 0);
585 if (err < 0)
586 return err;
587 }
515 588
516 err = sx150x_init_io(chip, chip->dev_cfg->reg_polarity,
517 pdata->io_polarity);
518 if (err < 0)
519 return err;
520 589
521 if (pdata->oscio_is_gpo) 590 if (pdata->oscio_is_gpo)
522 sx150x_set_oscio(chip, 0); 591 sx150x_set_oscio(chip, 0);
@@ -529,31 +598,24 @@ static int sx150x_install_irq_chip(struct sx150x_chip *chip,
529 int irq_base) 598 int irq_base)
530{ 599{
531 int err; 600 int err;
532 unsigned n;
533 unsigned irq;
534 601
535 chip->irq_summary = irq_summary; 602 chip->irq_summary = irq_summary;
536 chip->irq_base = irq_base; 603 chip->irq_base = irq_base;
537 604
538 for (n = 0; n < chip->dev_cfg->ngpios; ++n) { 605 /* Add gpio chip to irq subsystem */
539 irq = irq_base + n; 606 err = gpiochip_irqchip_add(&chip->gpio_chip,
540 irq_set_chip_data(irq, chip); 607 &chip->irq_chip, chip->irq_base,
541 irq_set_chip_and_handler(irq, &chip->irq_chip, handle_edge_irq); 608 handle_edge_irq, IRQ_TYPE_EDGE_BOTH);
542 irq_set_nested_thread(irq, 1); 609 if (err) {
543#ifdef CONFIG_ARM 610 dev_err(&chip->client->dev,
544 set_irq_flags(irq, IRQF_VALID); 611 "could not connect irqchip to gpiochip\n");
545#else 612 return err;
546 irq_set_noprobe(irq);
547#endif
548 } 613 }
549 614
550 err = devm_request_threaded_irq(&chip->client->dev, 615 err = devm_request_threaded_irq(&chip->client->dev,
551 irq_summary, 616 irq_summary, NULL, sx150x_irq_thread_fn,
552 NULL, 617 IRQF_ONESHOT | IRQF_SHARED | IRQF_TRIGGER_FALLING,
553 sx150x_irq_thread_fn, 618 chip->irq_chip.name, chip);
554 IRQF_SHARED | IRQF_TRIGGER_FALLING,
555 chip->irq_chip.name,
556 chip);
557 if (err < 0) { 619 if (err < 0) {
558 chip->irq_summary = -1; 620 chip->irq_summary = -1;
559 chip->irq_base = -1; 621 chip->irq_base = -1;
@@ -562,17 +624,6 @@ static int sx150x_install_irq_chip(struct sx150x_chip *chip,
562 return err; 624 return err;
563} 625}
564 626
565static void sx150x_remove_irq_chip(struct sx150x_chip *chip)
566{
567 unsigned n;
568 unsigned irq;
569
570 for (n = 0; n < chip->dev_cfg->ngpios; ++n) {
571 irq = chip->irq_base + n;
572 irq_set_chip_and_handler(irq, NULL, NULL);
573 }
574}
575
576static int sx150x_probe(struct i2c_client *client, 627static int sx150x_probe(struct i2c_client *client,
577 const struct i2c_device_id *id) 628 const struct i2c_device_id *id)
578{ 629{
@@ -626,16 +677,14 @@ static int sx150x_remove(struct i2c_client *client)
626 chip = i2c_get_clientdata(client); 677 chip = i2c_get_clientdata(client);
627 gpiochip_remove(&chip->gpio_chip); 678 gpiochip_remove(&chip->gpio_chip);
628 679
629 if (chip->irq_summary >= 0)
630 sx150x_remove_irq_chip(chip);
631
632 return 0; 680 return 0;
633} 681}
634 682
635static struct i2c_driver sx150x_driver = { 683static struct i2c_driver sx150x_driver = {
636 .driver = { 684 .driver = {
637 .name = "sx150x", 685 .name = "sx150x",
638 .owner = THIS_MODULE 686 .owner = THIS_MODULE,
687 .of_match_table = of_match_ptr(sx150x_of_match),
639 }, 688 },
640 .probe = sx150x_probe, 689 .probe = sx150x_probe,
641 .remove = sx150x_remove, 690 .remove = sx150x_remove,
diff --git a/drivers/gpio/gpio-syscon.c b/drivers/gpio/gpio-syscon.c
index 257e2989215c..045a952576c7 100644
--- a/drivers/gpio/gpio-syscon.c
+++ b/drivers/gpio/gpio-syscon.c
@@ -219,7 +219,7 @@ static int syscon_gpio_probe(struct platform_device *pdev)
219 ret = of_property_read_u32_index(np, "gpio,syscon-dev", 2, 219 ret = of_property_read_u32_index(np, "gpio,syscon-dev", 2,
220 &priv->dir_reg_offset); 220 &priv->dir_reg_offset);
221 if (ret) 221 if (ret)
222 dev_err(dev, "can't read the dir register offset!\n"); 222 dev_dbg(dev, "can't read the dir register offset!\n");
223 223
224 priv->dir_reg_offset <<= 3; 224 priv->dir_reg_offset <<= 3;
225 } 225 }
diff --git a/drivers/gpio/gpio-tc3589x.c b/drivers/gpio/gpio-tc3589x.c
index abdcf58935f5..11aed2671065 100644
--- a/drivers/gpio/gpio-tc3589x.c
+++ b/drivers/gpio/gpio-tc3589x.c
@@ -232,16 +232,13 @@ static irqreturn_t tc3589x_gpio_irq(int irq, void *dev)
232static int tc3589x_gpio_probe(struct platform_device *pdev) 232static int tc3589x_gpio_probe(struct platform_device *pdev)
233{ 233{
234 struct tc3589x *tc3589x = dev_get_drvdata(pdev->dev.parent); 234 struct tc3589x *tc3589x = dev_get_drvdata(pdev->dev.parent);
235 struct tc3589x_gpio_platform_data *pdata;
236 struct device_node *np = pdev->dev.of_node; 235 struct device_node *np = pdev->dev.of_node;
237 struct tc3589x_gpio *tc3589x_gpio; 236 struct tc3589x_gpio *tc3589x_gpio;
238 int ret; 237 int ret;
239 int irq; 238 int irq;
240 239
241 pdata = tc3589x->pdata->gpio; 240 if (!np) {
242 241 dev_err(&pdev->dev, "No Device Tree node found\n");
243 if (!(pdata || np)) {
244 dev_err(&pdev->dev, "No platform data or Device Tree found\n");
245 return -EINVAL; 242 return -EINVAL;
246 } 243 }
247 244
@@ -305,9 +302,6 @@ static int tc3589x_gpio_probe(struct platform_device *pdev)
305 irq, 302 irq,
306 NULL); 303 NULL);
307 304
308 if (pdata && pdata->setup)
309 pdata->setup(tc3589x, tc3589x_gpio->chip.base);
310
311 platform_set_drvdata(pdev, tc3589x_gpio); 305 platform_set_drvdata(pdev, tc3589x_gpio);
312 306
313 return 0; 307 return 0;
@@ -316,11 +310,6 @@ static int tc3589x_gpio_probe(struct platform_device *pdev)
316static int tc3589x_gpio_remove(struct platform_device *pdev) 310static int tc3589x_gpio_remove(struct platform_device *pdev)
317{ 311{
318 struct tc3589x_gpio *tc3589x_gpio = platform_get_drvdata(pdev); 312 struct tc3589x_gpio *tc3589x_gpio = platform_get_drvdata(pdev);
319 struct tc3589x *tc3589x = tc3589x_gpio->tc3589x;
320 struct tc3589x_gpio_platform_data *pdata = tc3589x->pdata->gpio;
321
322 if (pdata && pdata->remove)
323 pdata->remove(tc3589x, tc3589x_gpio->chip.base);
324 313
325 gpiochip_remove(&tc3589x_gpio->chip); 314 gpiochip_remove(&tc3589x_gpio->chip);
326 315
diff --git a/drivers/gpio/gpio-tps65912.c b/drivers/gpio/gpio-tps65912.c
index 472fb5b8779f..9cdbc0c9cb2d 100644
--- a/drivers/gpio/gpio-tps65912.c
+++ b/drivers/gpio/gpio-tps65912.c
@@ -26,9 +26,12 @@ struct tps65912_gpio_data {
26 struct gpio_chip gpio_chip; 26 struct gpio_chip gpio_chip;
27}; 27};
28 28
29#define to_tgd(gc) container_of(gc, struct tps65912_gpio_data, gpio_chip)
30
29static int tps65912_gpio_get(struct gpio_chip *gc, unsigned offset) 31static int tps65912_gpio_get(struct gpio_chip *gc, unsigned offset)
30{ 32{
31 struct tps65912 *tps65912 = container_of(gc, struct tps65912, gpio); 33 struct tps65912_gpio_data *tps65912_gpio = to_tgd(gc);
34 struct tps65912 *tps65912 = tps65912_gpio->tps65912;
32 int val; 35 int val;
33 36
34 val = tps65912_reg_read(tps65912, TPS65912_GPIO1 + offset); 37 val = tps65912_reg_read(tps65912, TPS65912_GPIO1 + offset);
@@ -42,7 +45,8 @@ static int tps65912_gpio_get(struct gpio_chip *gc, unsigned offset)
42static void tps65912_gpio_set(struct gpio_chip *gc, unsigned offset, 45static void tps65912_gpio_set(struct gpio_chip *gc, unsigned offset,
43 int value) 46 int value)
44{ 47{
45 struct tps65912 *tps65912 = container_of(gc, struct tps65912, gpio); 48 struct tps65912_gpio_data *tps65912_gpio = to_tgd(gc);
49 struct tps65912 *tps65912 = tps65912_gpio->tps65912;
46 50
47 if (value) 51 if (value)
48 tps65912_set_bits(tps65912, TPS65912_GPIO1 + offset, 52 tps65912_set_bits(tps65912, TPS65912_GPIO1 + offset,
@@ -55,7 +59,8 @@ static void tps65912_gpio_set(struct gpio_chip *gc, unsigned offset,
55static int tps65912_gpio_output(struct gpio_chip *gc, unsigned offset, 59static int tps65912_gpio_output(struct gpio_chip *gc, unsigned offset,
56 int value) 60 int value)
57{ 61{
58 struct tps65912 *tps65912 = container_of(gc, struct tps65912, gpio); 62 struct tps65912_gpio_data *tps65912_gpio = to_tgd(gc);
63 struct tps65912 *tps65912 = tps65912_gpio->tps65912;
59 64
60 /* Set the initial value */ 65 /* Set the initial value */
61 tps65912_gpio_set(gc, offset, value); 66 tps65912_gpio_set(gc, offset, value);
@@ -66,7 +71,8 @@ static int tps65912_gpio_output(struct gpio_chip *gc, unsigned offset,
66 71
67static int tps65912_gpio_input(struct gpio_chip *gc, unsigned offset) 72static int tps65912_gpio_input(struct gpio_chip *gc, unsigned offset)
68{ 73{
69 struct tps65912 *tps65912 = container_of(gc, struct tps65912, gpio); 74 struct tps65912_gpio_data *tps65912_gpio = to_tgd(gc);
75 struct tps65912 *tps65912 = tps65912_gpio->tps65912;
70 76
71 return tps65912_clear_bits(tps65912, TPS65912_GPIO1 + offset, 77 return tps65912_clear_bits(tps65912, TPS65912_GPIO1 + offset,
72 GPIO_CFG_MASK); 78 GPIO_CFG_MASK);
diff --git a/drivers/gpio/gpio-tz1090-pdc.c b/drivers/gpio/gpio-tz1090-pdc.c
index d7536226b847..ede7e403ffde 100644
--- a/drivers/gpio/gpio-tz1090-pdc.c
+++ b/drivers/gpio/gpio-tz1090-pdc.c
@@ -190,7 +190,7 @@ static int tz1090_pdc_gpio_probe(struct platform_device *pdev)
190 190
191 /* Ioremap the registers */ 191 /* Ioremap the registers */
192 priv->reg = devm_ioremap(&pdev->dev, res_regs->start, 192 priv->reg = devm_ioremap(&pdev->dev, res_regs->start,
193 res_regs->end - res_regs->start); 193 resource_size(res_regs));
194 if (!priv->reg) { 194 if (!priv->reg) {
195 dev_err(&pdev->dev, "unable to ioremap registers\n"); 195 dev_err(&pdev->dev, "unable to ioremap registers\n");
196 return -ENOMEM; 196 return -ENOMEM;
diff --git a/drivers/gpio/gpio-tz1090.c b/drivers/gpio/gpio-tz1090.c
index e3024bbba447..445660adc898 100644
--- a/drivers/gpio/gpio-tz1090.c
+++ b/drivers/gpio/gpio-tz1090.c
@@ -573,7 +573,7 @@ static int tz1090_gpio_probe(struct platform_device *pdev)
573 573
574 /* Ioremap the registers */ 574 /* Ioremap the registers */
575 priv.reg = devm_ioremap(&pdev->dev, res_regs->start, 575 priv.reg = devm_ioremap(&pdev->dev, res_regs->start,
576 res_regs->end - res_regs->start); 576 resource_size(res_regs));
577 if (!priv.reg) { 577 if (!priv.reg) {
578 dev_err(&pdev->dev, "unable to ioremap registers\n"); 578 dev_err(&pdev->dev, "unable to ioremap registers\n");
579 return -ENOMEM; 579 return -ENOMEM;
diff --git a/drivers/gpio/gpio-vf610.c b/drivers/gpio/gpio-vf610.c
index 4ee4cee832ec..971c73964ef1 100644
--- a/drivers/gpio/gpio-vf610.c
+++ b/drivers/gpio/gpio-vf610.c
@@ -278,7 +278,6 @@ static int vf610_gpio_probe(struct platform_device *pdev)
278static struct platform_driver vf610_gpio_driver = { 278static struct platform_driver vf610_gpio_driver = {
279 .driver = { 279 .driver = {
280 .name = "gpio-vf610", 280 .name = "gpio-vf610",
281 .owner = THIS_MODULE,
282 .of_match_table = vf610_gpio_dt_ids, 281 .of_match_table = vf610_gpio_dt_ids,
283 }, 282 },
284 .probe = vf610_gpio_probe, 283 .probe = vf610_gpio_probe,
diff --git a/drivers/gpio/gpio-vx855.c b/drivers/gpio/gpio-vx855.c
index 9d21d2fcc327..57b470d5b39e 100644
--- a/drivers/gpio/gpio-vx855.c
+++ b/drivers/gpio/gpio-vx855.c
@@ -52,8 +52,6 @@ struct vx855_gpio {
52 spinlock_t lock; 52 spinlock_t lock;
53 u32 io_gpi; 53 u32 io_gpi;
54 u32 io_gpo; 54 u32 io_gpo;
55 bool gpi_reserved;
56 bool gpo_reserved;
57}; 55};
58 56
59/* resolve a GPIx into the corresponding bit position */ 57/* resolve a GPIx into the corresponding bit position */
@@ -224,14 +222,13 @@ static int vx855gpio_probe(struct platform_device *pdev)
224 struct resource *res_gpi; 222 struct resource *res_gpi;
225 struct resource *res_gpo; 223 struct resource *res_gpo;
226 struct vx855_gpio *vg; 224 struct vx855_gpio *vg;
227 int ret;
228 225
229 res_gpi = platform_get_resource(pdev, IORESOURCE_IO, 0); 226 res_gpi = platform_get_resource(pdev, IORESOURCE_IO, 0);
230 res_gpo = platform_get_resource(pdev, IORESOURCE_IO, 1); 227 res_gpo = platform_get_resource(pdev, IORESOURCE_IO, 1);
231 if (!res_gpi || !res_gpo) 228 if (!res_gpi || !res_gpo)
232 return -EBUSY; 229 return -EBUSY;
233 230
234 vg = kzalloc(sizeof(*vg), GFP_KERNEL); 231 vg = devm_kzalloc(&pdev->dev, sizeof(*vg), GFP_KERNEL);
235 if (!vg) 232 if (!vg)
236 return -ENOMEM; 233 return -ENOMEM;
237 234
@@ -250,56 +247,27 @@ static int vx855gpio_probe(struct platform_device *pdev)
250 * succeed. Ignore and continue. 247 * succeed. Ignore and continue.
251 */ 248 */
252 249
253 if (!request_region(res_gpi->start, resource_size(res_gpi), 250 if (!devm_request_region(&pdev->dev, res_gpi->start,
254 MODULE_NAME "_gpi")) 251 resource_size(res_gpi), MODULE_NAME "_gpi"))
255 dev_warn(&pdev->dev, 252 dev_warn(&pdev->dev,
256 "GPI I/O resource busy, probably claimed by ACPI\n"); 253 "GPI I/O resource busy, probably claimed by ACPI\n");
257 else
258 vg->gpi_reserved = true;
259 254
260 if (!request_region(res_gpo->start, resource_size(res_gpo), 255 if (!devm_request_region(&pdev->dev, res_gpo->start,
261 MODULE_NAME "_gpo")) 256 resource_size(res_gpo), MODULE_NAME "_gpo"))
262 dev_warn(&pdev->dev, 257 dev_warn(&pdev->dev,
263 "GPO I/O resource busy, probably claimed by ACPI\n"); 258 "GPO I/O resource busy, probably claimed by ACPI\n");
264 else
265 vg->gpo_reserved = true;
266 259
267 vx855gpio_gpio_setup(vg); 260 vx855gpio_gpio_setup(vg);
268 261
269 ret = gpiochip_add(&vg->gpio); 262 return gpiochip_add(&vg->gpio);
270 if (ret) {
271 dev_err(&pdev->dev, "failed to register GPIOs\n");
272 goto out_release;
273 }
274
275 return 0;
276
277out_release:
278 if (vg->gpi_reserved)
279 release_region(res_gpi->start, resource_size(res_gpi));
280 if (vg->gpo_reserved)
281 release_region(res_gpi->start, resource_size(res_gpo));
282 kfree(vg);
283 return ret;
284} 263}
285 264
286static int vx855gpio_remove(struct platform_device *pdev) 265static int vx855gpio_remove(struct platform_device *pdev)
287{ 266{
288 struct vx855_gpio *vg = platform_get_drvdata(pdev); 267 struct vx855_gpio *vg = platform_get_drvdata(pdev);
289 struct resource *res;
290 268
291 gpiochip_remove(&vg->gpio); 269 gpiochip_remove(&vg->gpio);
292 270
293 if (vg->gpi_reserved) {
294 res = platform_get_resource(pdev, IORESOURCE_IO, 0);
295 release_region(res->start, resource_size(res));
296 }
297 if (vg->gpo_reserved) {
298 res = platform_get_resource(pdev, IORESOURCE_IO, 1);
299 release_region(res->start, resource_size(res));
300 }
301
302 kfree(vg);
303 return 0; 271 return 0;
304} 272}
305 273
diff --git a/drivers/gpio/gpio-xgene-sb.c b/drivers/gpio/gpio-xgene-sb.c
new file mode 100644
index 000000000000..b6a15c39293e
--- /dev/null
+++ b/drivers/gpio/gpio-xgene-sb.c
@@ -0,0 +1,160 @@
1/*
2 * AppliedMicro X-Gene SoC GPIO-Standby Driver
3 *
4 * Copyright (c) 2014, Applied Micro Circuits Corporation
5 * Author: Tin Huynh <tnhuynh@apm.com>.
6 * Y Vo <yvo@apm.com>.
7 *
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the
10 * Free Software Foundation; either version 2 of the License, or (at your
11 * option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 */
21
22#include <linux/module.h>
23#include <linux/io.h>
24#include <linux/platform_device.h>
25#include <linux/of_gpio.h>
26#include <linux/gpio.h>
27#include <linux/gpio/driver.h>
28#include <linux/basic_mmio_gpio.h>
29
30#define XGENE_MAX_GPIO_DS 22
31#define XGENE_MAX_GPIO_DS_IRQ 6
32
33#define GPIO_MASK(x) (1U << ((x) % 32))
34
35#define MPA_GPIO_INT_LVL 0x0290
36#define MPA_GPIO_OE_ADDR 0x029c
37#define MPA_GPIO_OUT_ADDR 0x02a0
38#define MPA_GPIO_IN_ADDR 0x02a4
39#define MPA_GPIO_SEL_LO 0x0294
40
41/**
42 * struct xgene_gpio_sb - GPIO-Standby private data structure.
43 * @bgc: memory-mapped GPIO controllers.
44 * @irq: Mapping GPIO pins and interrupt number
45 * nirq: Number of GPIO pins that supports interrupt
46 */
47struct xgene_gpio_sb {
48 struct bgpio_chip bgc;
49 u32 *irq;
50 u32 nirq;
51};
52
53static inline struct xgene_gpio_sb *to_xgene_gpio_sb(struct gpio_chip *gc)
54{
55 struct bgpio_chip *bgc = to_bgpio_chip(gc);
56
57 return container_of(bgc, struct xgene_gpio_sb, bgc);
58}
59
60static void xgene_gpio_set_bit(struct bgpio_chip *bgc, void __iomem *reg, u32 gpio, int val)
61{
62 u32 data;
63
64 data = bgc->read_reg(reg);
65 if (val)
66 data |= GPIO_MASK(gpio);
67 else
68 data &= ~GPIO_MASK(gpio);
69 bgc->write_reg(reg, data);
70}
71
72static int apm_gpio_sb_to_irq(struct gpio_chip *gc, u32 gpio)
73{
74 struct xgene_gpio_sb *priv = to_xgene_gpio_sb(gc);
75
76 if (priv->irq[gpio])
77 return priv->irq[gpio];
78
79 return -ENXIO;
80}
81
82static int xgene_gpio_sb_probe(struct platform_device *pdev)
83{
84 struct xgene_gpio_sb *priv;
85 u32 ret, i;
86 u32 default_lines[] = {0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D};
87 struct resource *res;
88 void __iomem *regs;
89
90 priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
91 if (!priv)
92 return -ENOMEM;
93
94 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
95 regs = devm_ioremap_resource(&pdev->dev, res);
96 if (!regs)
97 return PTR_ERR(regs);
98
99 ret = bgpio_init(&priv->bgc, &pdev->dev, 4,
100 regs + MPA_GPIO_IN_ADDR,
101 regs + MPA_GPIO_OUT_ADDR, NULL,
102 regs + MPA_GPIO_OE_ADDR, NULL, 0);
103 if (ret)
104 return ret;
105
106 priv->bgc.gc.to_irq = apm_gpio_sb_to_irq;
107 priv->bgc.gc.ngpio = XGENE_MAX_GPIO_DS;
108
109 priv->nirq = XGENE_MAX_GPIO_DS_IRQ;
110
111 priv->irq = devm_kzalloc(&pdev->dev, sizeof(u32) * XGENE_MAX_GPIO_DS,
112 GFP_KERNEL);
113 if (!priv->irq)
114 return -ENOMEM;
115 memset(priv->irq, 0, sizeof(u32) * XGENE_MAX_GPIO_DS);
116
117 for (i = 0; i < priv->nirq; i++) {
118 priv->irq[default_lines[i]] = platform_get_irq(pdev, i);
119 xgene_gpio_set_bit(&priv->bgc, regs + MPA_GPIO_SEL_LO,
120 default_lines[i] * 2, 1);
121 xgene_gpio_set_bit(&priv->bgc, regs + MPA_GPIO_INT_LVL, i, 1);
122 }
123
124 platform_set_drvdata(pdev, priv);
125
126 ret = gpiochip_add(&priv->bgc.gc);
127 if (ret)
128 dev_err(&pdev->dev, "failed to register X-Gene GPIO Standby driver\n");
129 else
130 dev_info(&pdev->dev, "X-Gene GPIO Standby driver registered\n");
131
132 return ret;
133}
134
135static int xgene_gpio_sb_remove(struct platform_device *pdev)
136{
137 struct xgene_gpio_sb *priv = platform_get_drvdata(pdev);
138
139 return bgpio_remove(&priv->bgc);
140}
141
142static const struct of_device_id xgene_gpio_sb_of_match[] = {
143 {.compatible = "apm,xgene-gpio-sb", },
144 {},
145};
146MODULE_DEVICE_TABLE(of, xgene_gpio_sb_of_match);
147
148static struct platform_driver xgene_gpio_sb_driver = {
149 .driver = {
150 .name = "xgene-gpio-sb",
151 .of_match_table = xgene_gpio_sb_of_match,
152 },
153 .probe = xgene_gpio_sb_probe,
154 .remove = xgene_gpio_sb_remove,
155};
156module_platform_driver(xgene_gpio_sb_driver);
157
158MODULE_AUTHOR("AppliedMicro");
159MODULE_DESCRIPTION("APM X-Gene GPIO Standby driver");
160MODULE_LICENSE("GPL");
diff --git a/drivers/gpio/gpio-xilinx.c b/drivers/gpio/gpio-xilinx.c
index ba18b06c9a21..61243d177740 100644
--- a/drivers/gpio/gpio-xilinx.c
+++ b/drivers/gpio/gpio-xilinx.c
@@ -30,7 +30,7 @@
30#define XGPIO_CHANNEL_OFFSET 0x8 30#define XGPIO_CHANNEL_OFFSET 0x8
31 31
32/* Read/Write access to the GPIO registers */ 32/* Read/Write access to the GPIO registers */
33#ifdef CONFIG_ARCH_ZYNQ 33#if defined(CONFIG_ARCH_ZYNQ) || defined(CONFIG_X86)
34# define xgpio_readreg(offset) readl(offset) 34# define xgpio_readreg(offset) readl(offset)
35# define xgpio_writereg(offset, val) writel(val, offset) 35# define xgpio_writereg(offset, val) writel(val, offset)
36#else 36#else
@@ -40,37 +40,66 @@
40 40
41/** 41/**
42 * struct xgpio_instance - Stores information about GPIO device 42 * struct xgpio_instance - Stores information about GPIO device
43 * struct of_mm_gpio_chip mmchip: OF GPIO chip for memory mapped banks 43 * @mmchip: OF GPIO chip for memory mapped banks
44 * gpio_state: GPIO state shadow register 44 * @gpio_state: GPIO state shadow register
45 * gpio_dir: GPIO direction shadow register 45 * @gpio_dir: GPIO direction shadow register
46 * offset: GPIO channel offset 46 * @gpio_lock: Lock used for synchronization
47 * gpio_lock: Lock used for synchronization 47 * @inited: True if the port has been inited
48 */ 48 */
49struct xgpio_instance { 49struct xgpio_instance {
50 struct of_mm_gpio_chip mmchip; 50 struct of_mm_gpio_chip mmchip;
51 u32 gpio_state; 51 unsigned int gpio_width[2];
52 u32 gpio_dir; 52 u32 gpio_state[2];
53 u32 offset; 53 u32 gpio_dir[2];
54 spinlock_t gpio_lock; 54 spinlock_t gpio_lock[2];
55}; 55};
56 56
57static inline int xgpio_index(struct xgpio_instance *chip, int gpio)
58{
59 if (gpio >= chip->gpio_width[0])
60 return 1;
61
62 return 0;
63}
64
65static inline int xgpio_regoffset(struct xgpio_instance *chip, int gpio)
66{
67 if (xgpio_index(chip, gpio))
68 return XGPIO_CHANNEL_OFFSET;
69
70 return 0;
71}
72
73static inline int xgpio_offset(struct xgpio_instance *chip, int gpio)
74{
75 if (xgpio_index(chip, gpio))
76 return gpio - chip->gpio_width[0];
77
78 return gpio;
79}
80
57/** 81/**
58 * xgpio_get - Read the specified signal of the GPIO device. 82 * xgpio_get - Read the specified signal of the GPIO device.
59 * @gc: Pointer to gpio_chip device structure. 83 * @gc: Pointer to gpio_chip device structure.
60 * @gpio: GPIO signal number. 84 * @gpio: GPIO signal number.
61 * 85 *
62 * This function reads the specified signal of the GPIO device. It returns 0 if 86 * This function reads the specified signal of the GPIO device.
63 * the signal clear, 1 if signal is set or negative value on error. 87 *
88 * Return:
89 * 0 if direction of GPIO signals is set as input otherwise it
90 * returns negative error value.
64 */ 91 */
65static int xgpio_get(struct gpio_chip *gc, unsigned int gpio) 92static int xgpio_get(struct gpio_chip *gc, unsigned int gpio)
66{ 93{
67 struct of_mm_gpio_chip *mm_gc = to_of_mm_gpio_chip(gc); 94 struct of_mm_gpio_chip *mm_gc = to_of_mm_gpio_chip(gc);
68 struct xgpio_instance *chip = 95 struct xgpio_instance *chip =
69 container_of(mm_gc, struct xgpio_instance, mmchip); 96 container_of(mm_gc, struct xgpio_instance, mmchip);
97 u32 val;
70 98
71 void __iomem *regs = mm_gc->regs + chip->offset; 99 val = xgpio_readreg(mm_gc->regs + XGPIO_DATA_OFFSET +
100 xgpio_regoffset(chip, gpio));
72 101
73 return !!(xgpio_readreg(regs + XGPIO_DATA_OFFSET) & BIT(gpio)); 102 return !!(val & BIT(xgpio_offset(chip, gpio)));
74} 103}
75 104
76/** 105/**
@@ -88,20 +117,21 @@ static void xgpio_set(struct gpio_chip *gc, unsigned int gpio, int val)
88 struct of_mm_gpio_chip *mm_gc = to_of_mm_gpio_chip(gc); 117 struct of_mm_gpio_chip *mm_gc = to_of_mm_gpio_chip(gc);
89 struct xgpio_instance *chip = 118 struct xgpio_instance *chip =
90 container_of(mm_gc, struct xgpio_instance, mmchip); 119 container_of(mm_gc, struct xgpio_instance, mmchip);
91 void __iomem *regs = mm_gc->regs; 120 int index = xgpio_index(chip, gpio);
121 int offset = xgpio_offset(chip, gpio);
92 122
93 spin_lock_irqsave(&chip->gpio_lock, flags); 123 spin_lock_irqsave(&chip->gpio_lock[index], flags);
94 124
95 /* Write to GPIO signal and set its direction to output */ 125 /* Write to GPIO signal and set its direction to output */
96 if (val) 126 if (val)
97 chip->gpio_state |= BIT(gpio); 127 chip->gpio_state[index] |= BIT(offset);
98 else 128 else
99 chip->gpio_state &= ~BIT(gpio); 129 chip->gpio_state[index] &= ~BIT(offset);
100 130
101 xgpio_writereg(regs + chip->offset + XGPIO_DATA_OFFSET, 131 xgpio_writereg(mm_gc->regs + XGPIO_DATA_OFFSET +
102 chip->gpio_state); 132 xgpio_regoffset(chip, gpio), chip->gpio_state[index]);
103 133
104 spin_unlock_irqrestore(&chip->gpio_lock, flags); 134 spin_unlock_irqrestore(&chip->gpio_lock[index], flags);
105} 135}
106 136
107/** 137/**
@@ -109,9 +139,9 @@ static void xgpio_set(struct gpio_chip *gc, unsigned int gpio, int val)
109 * @gc: Pointer to gpio_chip device structure. 139 * @gc: Pointer to gpio_chip device structure.
110 * @gpio: GPIO signal number. 140 * @gpio: GPIO signal number.
111 * 141 *
112 * This function sets the direction of specified GPIO signal as input. 142 * Return:
113 * It returns 0 if direction of GPIO signals is set as input otherwise it 143 * 0 - if direction of GPIO signals is set as input
114 * returns negative error value. 144 * otherwise it returns negative error value.
115 */ 145 */
116static int xgpio_dir_in(struct gpio_chip *gc, unsigned int gpio) 146static int xgpio_dir_in(struct gpio_chip *gc, unsigned int gpio)
117{ 147{
@@ -119,15 +149,17 @@ static int xgpio_dir_in(struct gpio_chip *gc, unsigned int gpio)
119 struct of_mm_gpio_chip *mm_gc = to_of_mm_gpio_chip(gc); 149 struct of_mm_gpio_chip *mm_gc = to_of_mm_gpio_chip(gc);
120 struct xgpio_instance *chip = 150 struct xgpio_instance *chip =
121 container_of(mm_gc, struct xgpio_instance, mmchip); 151 container_of(mm_gc, struct xgpio_instance, mmchip);
122 void __iomem *regs = mm_gc->regs; 152 int index = xgpio_index(chip, gpio);
153 int offset = xgpio_offset(chip, gpio);
123 154
124 spin_lock_irqsave(&chip->gpio_lock, flags); 155 spin_lock_irqsave(&chip->gpio_lock[index], flags);
125 156
126 /* Set the GPIO bit in shadow register and set direction as input */ 157 /* Set the GPIO bit in shadow register and set direction as input */
127 chip->gpio_dir |= BIT(gpio); 158 chip->gpio_dir[index] |= BIT(offset);
128 xgpio_writereg(regs + chip->offset + XGPIO_TRI_OFFSET, chip->gpio_dir); 159 xgpio_writereg(mm_gc->regs + XGPIO_TRI_OFFSET +
160 xgpio_regoffset(chip, gpio), chip->gpio_dir[index]);
129 161
130 spin_unlock_irqrestore(&chip->gpio_lock, flags); 162 spin_unlock_irqrestore(&chip->gpio_lock[index], flags);
131 163
132 return 0; 164 return 0;
133} 165}
@@ -138,8 +170,10 @@ static int xgpio_dir_in(struct gpio_chip *gc, unsigned int gpio)
138 * @gpio: GPIO signal number. 170 * @gpio: GPIO signal number.
139 * @val: Value to be written to specified signal. 171 * @val: Value to be written to specified signal.
140 * 172 *
141 * This function sets the direction of specified GPIO signal as output. If all 173 * This function sets the direction of specified GPIO signal as output.
142 * GPIO signals of GPIO chip is configured as input then it returns 174 *
175 * Return:
176 * If all GPIO signals of GPIO chip is configured as input then it returns
143 * error otherwise it returns 0. 177 * error otherwise it returns 0.
144 */ 178 */
145static int xgpio_dir_out(struct gpio_chip *gc, unsigned int gpio, int val) 179static int xgpio_dir_out(struct gpio_chip *gc, unsigned int gpio, int val)
@@ -148,80 +182,128 @@ static int xgpio_dir_out(struct gpio_chip *gc, unsigned int gpio, int val)
148 struct of_mm_gpio_chip *mm_gc = to_of_mm_gpio_chip(gc); 182 struct of_mm_gpio_chip *mm_gc = to_of_mm_gpio_chip(gc);
149 struct xgpio_instance *chip = 183 struct xgpio_instance *chip =
150 container_of(mm_gc, struct xgpio_instance, mmchip); 184 container_of(mm_gc, struct xgpio_instance, mmchip);
151 void __iomem *regs = mm_gc->regs; 185 int index = xgpio_index(chip, gpio);
186 int offset = xgpio_offset(chip, gpio);
152 187
153 spin_lock_irqsave(&chip->gpio_lock, flags); 188 spin_lock_irqsave(&chip->gpio_lock[index], flags);
154 189
155 /* Write state of GPIO signal */ 190 /* Write state of GPIO signal */
156 if (val) 191 if (val)
157 chip->gpio_state |= BIT(gpio); 192 chip->gpio_state[index] |= BIT(offset);
158 else 193 else
159 chip->gpio_state &= ~BIT(gpio); 194 chip->gpio_state[index] &= ~BIT(offset);
160 xgpio_writereg(regs + chip->offset + XGPIO_DATA_OFFSET, 195 xgpio_writereg(mm_gc->regs + XGPIO_DATA_OFFSET +
161 chip->gpio_state); 196 xgpio_regoffset(chip, gpio), chip->gpio_state[index]);
162 197
163 /* Clear the GPIO bit in shadow register and set direction as output */ 198 /* Clear the GPIO bit in shadow register and set direction as output */
164 chip->gpio_dir &= ~BIT(gpio); 199 chip->gpio_dir[index] &= ~BIT(offset);
165 xgpio_writereg(regs + chip->offset + XGPIO_TRI_OFFSET, chip->gpio_dir); 200 xgpio_writereg(mm_gc->regs + XGPIO_TRI_OFFSET +
201 xgpio_regoffset(chip, gpio), chip->gpio_dir[index]);
166 202
167 spin_unlock_irqrestore(&chip->gpio_lock, flags); 203 spin_unlock_irqrestore(&chip->gpio_lock[index], flags);
168 204
169 return 0; 205 return 0;
170} 206}
171 207
172/** 208/**
173 * xgpio_save_regs - Set initial values of GPIO pins 209 * xgpio_save_regs - Set initial values of GPIO pins
174 * @mm_gc: pointer to memory mapped GPIO chip structure 210 * @mm_gc: Pointer to memory mapped GPIO chip structure
175 */ 211 */
176static void xgpio_save_regs(struct of_mm_gpio_chip *mm_gc) 212static void xgpio_save_regs(struct of_mm_gpio_chip *mm_gc)
177{ 213{
178 struct xgpio_instance *chip = 214 struct xgpio_instance *chip =
179 container_of(mm_gc, struct xgpio_instance, mmchip); 215 container_of(mm_gc, struct xgpio_instance, mmchip);
180 216
181 xgpio_writereg(mm_gc->regs + chip->offset + XGPIO_DATA_OFFSET, 217 xgpio_writereg(mm_gc->regs + XGPIO_DATA_OFFSET, chip->gpio_state[0]);
182 chip->gpio_state); 218 xgpio_writereg(mm_gc->regs + XGPIO_TRI_OFFSET, chip->gpio_dir[0]);
183 xgpio_writereg(mm_gc->regs + chip->offset + XGPIO_TRI_OFFSET, 219
184 chip->gpio_dir); 220 if (!chip->gpio_width[1])
221 return;
222
223 xgpio_writereg(mm_gc->regs + XGPIO_DATA_OFFSET + XGPIO_TRI_OFFSET,
224 chip->gpio_state[1]);
225 xgpio_writereg(mm_gc->regs + XGPIO_TRI_OFFSET + XGPIO_TRI_OFFSET,
226 chip->gpio_dir[1]);
227}
228
229/**
230 * xgpio_remove - Remove method for the GPIO device.
231 * @pdev: pointer to the platform device
232 *
233 * This function remove gpiochips and frees all the allocated resources.
234 */
235static int xgpio_remove(struct platform_device *pdev)
236{
237 struct xgpio_instance *chip = platform_get_drvdata(pdev);
238
239 of_mm_gpiochip_remove(&chip->mmchip);
240
241 return 0;
185} 242}
186 243
187/** 244/**
188 * xgpio_of_probe - Probe method for the GPIO device. 245 * xgpio_of_probe - Probe method for the GPIO device.
189 * @np: pointer to device tree node 246 * @pdev: pointer to the platform device
190 * 247 *
191 * This function probes the GPIO device in the device tree. It initializes the 248 * Return:
192 * driver data structure. It returns 0, if the driver is bound to the GPIO 249 * It returns 0, if the driver is bound to the GPIO device, or
193 * device, or a negative value if there is an error. 250 * a negative value if there is an error.
194 */ 251 */
195static int xgpio_of_probe(struct device_node *np) 252static int xgpio_probe(struct platform_device *pdev)
196{ 253{
197 struct xgpio_instance *chip; 254 struct xgpio_instance *chip;
198 int status = 0; 255 int status = 0;
199 const u32 *tree_info; 256 struct device_node *np = pdev->dev.of_node;
200 u32 ngpio; 257 u32 is_dual;
201 258
202 chip = kzalloc(sizeof(*chip), GFP_KERNEL); 259 chip = devm_kzalloc(&pdev->dev, sizeof(*chip), GFP_KERNEL);
203 if (!chip) 260 if (!chip)
204 return -ENOMEM; 261 return -ENOMEM;
205 262
206 /* Update GPIO state shadow register with default value */ 263 platform_set_drvdata(pdev, chip);
207 of_property_read_u32(np, "xlnx,dout-default", &chip->gpio_state);
208 264
209 /* By default, all pins are inputs */ 265 /* Update GPIO state shadow register with default value */
210 chip->gpio_dir = 0xFFFFFFFF; 266 of_property_read_u32(np, "xlnx,dout-default", &chip->gpio_state[0]);
211 267
212 /* Update GPIO direction shadow register with default value */ 268 /* Update GPIO direction shadow register with default value */
213 of_property_read_u32(np, "xlnx,tri-default", &chip->gpio_dir); 269 if (of_property_read_u32(np, "xlnx,tri-default", &chip->gpio_dir[0]))
270 chip->gpio_dir[0] = 0xFFFFFFFF;
214 271
215 /* 272 /*
216 * Check device node and parent device node for device width 273 * Check device node and parent device node for device width
217 * and assume default width of 32 274 * and assume default width of 32
218 */ 275 */
219 if (of_property_read_u32(np, "xlnx,gpio-width", &ngpio)) 276 if (of_property_read_u32(np, "xlnx,gpio-width", &chip->gpio_width[0]))
220 ngpio = 32; 277 chip->gpio_width[0] = 32;
221 chip->mmchip.gc.ngpio = (u16)ngpio; 278
279 spin_lock_init(&chip->gpio_lock[0]);
280
281 if (of_property_read_u32(np, "xlnx,is-dual", &is_dual))
282 is_dual = 0;
283
284 if (is_dual) {
285 /* Update GPIO state shadow register with default value */
286 of_property_read_u32(np, "xlnx,dout-default-2",
287 &chip->gpio_state[1]);
222 288
223 spin_lock_init(&chip->gpio_lock); 289 /* Update GPIO direction shadow register with default value */
290 if (of_property_read_u32(np, "xlnx,tri-default-2",
291 &chip->gpio_dir[1]))
292 chip->gpio_dir[1] = 0xFFFFFFFF;
224 293
294 /*
295 * Check device node and parent device node for device width
296 * and assume default width of 32
297 */
298 if (of_property_read_u32(np, "xlnx,gpio2-width",
299 &chip->gpio_width[1]))
300 chip->gpio_width[1] = 32;
301
302 spin_lock_init(&chip->gpio_lock[1]);
303 }
304
305 chip->mmchip.gc.ngpio = chip->gpio_width[0] + chip->gpio_width[1];
306 chip->mmchip.gc.dev = &pdev->dev;
225 chip->mmchip.gc.direction_input = xgpio_dir_in; 307 chip->mmchip.gc.direction_input = xgpio_dir_in;
226 chip->mmchip.gc.direction_output = xgpio_dir_out; 308 chip->mmchip.gc.direction_output = xgpio_dir_out;
227 chip->mmchip.gc.get = xgpio_get; 309 chip->mmchip.gc.get = xgpio_get;
@@ -232,63 +314,11 @@ static int xgpio_of_probe(struct device_node *np)
232 /* Call the OF gpio helper to setup and register the GPIO device */ 314 /* Call the OF gpio helper to setup and register the GPIO device */
233 status = of_mm_gpiochip_add(np, &chip->mmchip); 315 status = of_mm_gpiochip_add(np, &chip->mmchip);
234 if (status) { 316 if (status) {
235 kfree(chip);
236 pr_err("%s: error in probe function with status %d\n", 317 pr_err("%s: error in probe function with status %d\n",
237 np->full_name, status); 318 np->full_name, status);
238 return status; 319 return status;
239 } 320 }
240 321
241 pr_info("XGpio: %s: registered, base is %d\n", np->full_name,
242 chip->mmchip.gc.base);
243
244 tree_info = of_get_property(np, "xlnx,is-dual", NULL);
245 if (tree_info && be32_to_cpup(tree_info)) {
246 chip = kzalloc(sizeof(*chip), GFP_KERNEL);
247 if (!chip)
248 return -ENOMEM;
249
250 /* Add dual channel offset */
251 chip->offset = XGPIO_CHANNEL_OFFSET;
252
253 /* Update GPIO state shadow register with default value */
254 of_property_read_u32(np, "xlnx,dout-default-2",
255 &chip->gpio_state);
256
257 /* By default, all pins are inputs */
258 chip->gpio_dir = 0xFFFFFFFF;
259
260 /* Update GPIO direction shadow register with default value */
261 of_property_read_u32(np, "xlnx,tri-default-2", &chip->gpio_dir);
262
263 /*
264 * Check device node and parent device node for device width
265 * and assume default width of 32
266 */
267 if (of_property_read_u32(np, "xlnx,gpio2-width", &ngpio))
268 ngpio = 32;
269 chip->mmchip.gc.ngpio = (u16)ngpio;
270
271 spin_lock_init(&chip->gpio_lock);
272
273 chip->mmchip.gc.direction_input = xgpio_dir_in;
274 chip->mmchip.gc.direction_output = xgpio_dir_out;
275 chip->mmchip.gc.get = xgpio_get;
276 chip->mmchip.gc.set = xgpio_set;
277
278 chip->mmchip.save_regs = xgpio_save_regs;
279
280 /* Call the OF gpio helper to setup and register the GPIO dev */
281 status = of_mm_gpiochip_add(np, &chip->mmchip);
282 if (status) {
283 kfree(chip);
284 pr_err("%s: error in probe function with status %d\n",
285 np->full_name, status);
286 return status;
287 }
288 pr_info("XGpio: %s: dual channel registered, base is %d\n",
289 np->full_name, chip->mmchip.gc.base);
290 }
291
292 return 0; 322 return 0;
293} 323}
294 324
@@ -297,19 +327,29 @@ static const struct of_device_id xgpio_of_match[] = {
297 { /* end of list */ }, 327 { /* end of list */ },
298}; 328};
299 329
300static int __init xgpio_init(void) 330MODULE_DEVICE_TABLE(of, xgpio_of_match);
301{
302 struct device_node *np;
303 331
304 for_each_matching_node(np, xgpio_of_match) 332static struct platform_driver xgpio_plat_driver = {
305 xgpio_of_probe(np); 333 .probe = xgpio_probe,
334 .remove = xgpio_remove,
335 .driver = {
336 .name = "gpio-xilinx",
337 .of_match_table = xgpio_of_match,
338 },
339};
306 340
307 return 0; 341static int __init xgpio_init(void)
342{
343 return platform_driver_register(&xgpio_plat_driver);
308} 344}
309 345
310/* Make sure we get initialized before anyone else tries to use us */
311subsys_initcall(xgpio_init); 346subsys_initcall(xgpio_init);
312/* No exit call at the moment as we cannot unregister of GPIO chips */ 347
348static void __exit xgpio_exit(void)
349{
350 platform_driver_unregister(&xgpio_plat_driver);
351}
352module_exit(xgpio_exit);
313 353
314MODULE_AUTHOR("Xilinx, Inc."); 354MODULE_AUTHOR("Xilinx, Inc.");
315MODULE_DESCRIPTION("Xilinx GPIO driver"); 355MODULE_DESCRIPTION("Xilinx GPIO driver");
diff --git a/drivers/gpio/gpio-zevio.c b/drivers/gpio/gpio-zevio.c
index f769cd53f4e4..6f02d7c4cc57 100644
--- a/drivers/gpio/gpio-zevio.c
+++ b/drivers/gpio/gpio-zevio.c
@@ -181,6 +181,8 @@ static int zevio_gpio_probe(struct platform_device *pdev)
181 if (!controller) 181 if (!controller)
182 return -ENOMEM; 182 return -ENOMEM;
183 183
184 platform_set_drvdata(pdev, controller);
185
184 /* Copy our reference */ 186 /* Copy our reference */
185 controller->chip.gc = zevio_gpio_chip; 187 controller->chip.gc = zevio_gpio_chip;
186 controller->chip.gc.dev = &pdev->dev; 188 controller->chip.gc.dev = &pdev->dev;
@@ -202,6 +204,15 @@ static int zevio_gpio_probe(struct platform_device *pdev)
202 return 0; 204 return 0;
203} 205}
204 206
207static int zevio_gpio_remove(struct platform_device *pdev)
208{
209 struct zevio_gpio *controller = platform_get_drvdata(pdev);
210
211 of_mm_gpiochip_remove(&controller->chip);
212
213 return 0;
214}
215
205static const struct of_device_id zevio_gpio_of_match[] = { 216static const struct of_device_id zevio_gpio_of_match[] = {
206 { .compatible = "lsi,zevio-gpio", }, 217 { .compatible = "lsi,zevio-gpio", },
207 { }, 218 { },
@@ -215,6 +226,7 @@ static struct platform_driver zevio_gpio_driver = {
215 .of_match_table = zevio_gpio_of_match, 226 .of_match_table = zevio_gpio_of_match,
216 }, 227 },
217 .probe = zevio_gpio_probe, 228 .probe = zevio_gpio_probe,
229 .remove = zevio_gpio_remove,
218}; 230};
219module_platform_driver(zevio_gpio_driver); 231module_platform_driver(zevio_gpio_driver);
220 232
diff --git a/drivers/gpio/gpiolib-acpi.c b/drivers/gpio/gpiolib-acpi.c
index c0929d938ced..df990f29757a 100644
--- a/drivers/gpio/gpiolib-acpi.c
+++ b/drivers/gpio/gpiolib-acpi.c
@@ -201,6 +201,10 @@ static acpi_status acpi_gpiochip_request_interrupt(struct acpi_resource *ares,
201 if (!handler) 201 if (!handler)
202 return AE_BAD_PARAMETER; 202 return AE_BAD_PARAMETER;
203 203
204 pin = acpi_gpiochip_pin_to_gpio_offset(chip, pin);
205 if (pin < 0)
206 return AE_BAD_PARAMETER;
207
204 desc = gpiochip_request_own_desc(chip, pin, "ACPI:Event"); 208 desc = gpiochip_request_own_desc(chip, pin, "ACPI:Event");
205 if (IS_ERR(desc)) { 209 if (IS_ERR(desc)) {
206 dev_err(chip->dev, "Failed to request GPIO\n"); 210 dev_err(chip->dev, "Failed to request GPIO\n");
@@ -551,6 +555,12 @@ acpi_gpio_adr_space_handler(u32 function, acpi_physical_address address,
551 struct gpio_desc *desc; 555 struct gpio_desc *desc;
552 bool found; 556 bool found;
553 557
558 pin = acpi_gpiochip_pin_to_gpio_offset(chip, pin);
559 if (pin < 0) {
560 status = AE_BAD_PARAMETER;
561 goto out;
562 }
563
554 mutex_lock(&achip->conn_lock); 564 mutex_lock(&achip->conn_lock);
555 565
556 found = false; 566 found = false;
diff --git a/drivers/gpio/gpiolib-of.c b/drivers/gpio/gpiolib-of.c
index 08261f2b3a82..4650bf830d6b 100644
--- a/drivers/gpio/gpiolib-of.c
+++ b/drivers/gpio/gpiolib-of.c
@@ -46,12 +46,13 @@ static int of_gpiochip_find_and_xlate(struct gpio_chip *gc, void *data)
46 46
47 ret = gc->of_xlate(gc, &gg_data->gpiospec, gg_data->flags); 47 ret = gc->of_xlate(gc, &gg_data->gpiospec, gg_data->flags);
48 if (ret < 0) { 48 if (ret < 0) {
49 /* We've found the gpio chip, but the translation failed. 49 /* We've found a gpio chip, but the translation failed.
50 * Return true to stop looking and return the translation 50 * Store translation error in out_gpio.
51 * error via out_gpio 51 * Return false to keep looking, as more than one gpio chip
52 * could be registered per of-node.
52 */ 53 */
53 gg_data->out_gpio = ERR_PTR(ret); 54 gg_data->out_gpio = ERR_PTR(ret);
54 return true; 55 return false;
55 } 56 }
56 57
57 gg_data->out_gpio = gpiochip_get_desc(gc, ret); 58 gg_data->out_gpio = gpiochip_get_desc(gc, ret);
@@ -210,6 +211,23 @@ err0:
210} 211}
211EXPORT_SYMBOL(of_mm_gpiochip_add); 212EXPORT_SYMBOL(of_mm_gpiochip_add);
212 213
214/**
215 * of_mm_gpiochip_remove - Remove memory mapped GPIO chip (bank)
216 * @mm_gc: pointer to the of_mm_gpio_chip allocated structure
217 */
218void of_mm_gpiochip_remove(struct of_mm_gpio_chip *mm_gc)
219{
220 struct gpio_chip *gc = &mm_gc->gc;
221
222 if (!mm_gc)
223 return;
224
225 gpiochip_remove(gc);
226 iounmap(mm_gc->regs);
227 kfree(gc->label);
228}
229EXPORT_SYMBOL(of_mm_gpiochip_remove);
230
213#ifdef CONFIG_PINCTRL 231#ifdef CONFIG_PINCTRL
214static void of_gpiochip_add_pin_range(struct gpio_chip *chip) 232static void of_gpiochip_add_pin_range(struct gpio_chip *chip)
215{ 233{
diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index 568aa2b6bdb0..1ca9295b2c10 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -1659,7 +1659,7 @@ static struct gpio_desc *of_find_gpio(struct device *dev, const char *con_id,
1659 unsigned int idx, 1659 unsigned int idx,
1660 enum gpio_lookup_flags *flags) 1660 enum gpio_lookup_flags *flags)
1661{ 1661{
1662 static const char *suffixes[] = { "gpios", "gpio" }; 1662 static const char * const suffixes[] = { "gpios", "gpio" };
1663 char prop_name[32]; /* 32 is max size of property name */ 1663 char prop_name[32]; /* 32 is max size of property name */
1664 enum of_gpio_flags of_flags; 1664 enum of_gpio_flags of_flags;
1665 struct gpio_desc *desc; 1665 struct gpio_desc *desc;
@@ -1667,9 +1667,11 @@ static struct gpio_desc *of_find_gpio(struct device *dev, const char *con_id,
1667 1667
1668 for (i = 0; i < ARRAY_SIZE(suffixes); i++) { 1668 for (i = 0; i < ARRAY_SIZE(suffixes); i++) {
1669 if (con_id) 1669 if (con_id)
1670 snprintf(prop_name, 32, "%s-%s", con_id, suffixes[i]); 1670 snprintf(prop_name, sizeof(prop_name), "%s-%s", con_id,
1671 suffixes[i]);
1671 else 1672 else
1672 snprintf(prop_name, 32, "%s", suffixes[i]); 1673 snprintf(prop_name, sizeof(prop_name), "%s",
1674 suffixes[i]);
1673 1675
1674 desc = of_get_named_gpiod_flags(dev->of_node, prop_name, idx, 1676 desc = of_get_named_gpiod_flags(dev->of_node, prop_name, idx,
1675 &of_flags); 1677 &of_flags);