aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/gpio
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2011-07-22 17:50:57 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2011-07-22 17:50:57 -0400
commitc7c8518498e82591d7784452f5674c3aeb4d079c (patch)
tree790ff7e6b6741daf32ec686b9a302b957b07c0f4 /drivers/gpio
parentece236ce2fad9c27a6fd2530f899289025194bce (diff)
parent591567a5ea25852f20b7ef2953f6f72020121199 (diff)
Merge branch 'gpio/next' of git://git.secretlab.ca/git/linux-2.6
* 'gpio/next' of git://git.secretlab.ca/git/linux-2.6: (61 commits) gpio/mxc/mxs: fix build error introduced by the irq_gc_ack() renaming mcp23s08: add i2c support mcp23s08: isolate spi specific parts mcp23s08: get rid of setup/teardown callbacks gpio/tegra: dt: add binding for gpio polarity mcp23s08: remove unused work queue gpio/da9052: remove a redundant assignment for gpio->da9052 gpio/mxc: add device tree probe support ARM: mxc: use ARCH_NR_GPIOS to define gpio number gpio/mxc: get rid of the uses of cpu_is_mx() gpio/mxc: add missing initialization of basic_mmio_gpio shadow variables gpio: Move mpc5200 gpio driver to drivers/gpio GPIO: DA9052 GPIO module v3 gpio/tegra: Use engineering names in DT compatible property of/gpio: Add new method for getting gpios under different property names gpio/dt: Refine GPIO device tree binding gpio/ml-ioh: fix off-by-one for displaying variable i in dev_err gpio/pca953x: Deprecate meaningless device-tree bindings gpio/pca953x: Remove dynamic platform data pointer gpio/pca953x: Fix IRQ support. ...
Diffstat (limited to 'drivers/gpio')
-rw-r--r--drivers/gpio/Kconfig66
-rw-r--r--drivers/gpio/Makefile87
-rw-r--r--drivers/gpio/gpio-74x164.c (renamed from drivers/gpio/74x164.c)33
-rw-r--r--drivers/gpio/gpio-ab8500.c (renamed from drivers/gpio/ab8500-gpio.c)0
-rw-r--r--drivers/gpio/gpio-adp5520.c (renamed from drivers/gpio/adp5520-gpio.c)0
-rw-r--r--drivers/gpio/gpio-adp5588.c (renamed from drivers/gpio/adp5588-gpio.c)0
-rw-r--r--drivers/gpio/gpio-bt8xx.c (renamed from drivers/gpio/bt8xxgpio.c)0
-rw-r--r--drivers/gpio/gpio-cs5535.c (renamed from drivers/gpio/cs5535-gpio.c)0
-rw-r--r--drivers/gpio/gpio-da9052.c277
-rw-r--r--drivers/gpio/gpio-ep93xx.c405
-rw-r--r--drivers/gpio/gpio-exynos4.c5
-rw-r--r--drivers/gpio/gpio-generic.c (renamed from drivers/gpio/basic_mmio_gpio.c)6
-rw-r--r--drivers/gpio/gpio-it8761e.c (renamed from drivers/gpio/it8761e_gpio.c)2
-rw-r--r--drivers/gpio/gpio-janz-ttl.c (renamed from drivers/gpio/janz-ttl.c)0
-rw-r--r--drivers/gpio/gpio-langwell.c (renamed from drivers/gpio/langwell_gpio.c)4
-rw-r--r--drivers/gpio/gpio-max7300.c (renamed from drivers/gpio/max7300.c)2
-rw-r--r--drivers/gpio/gpio-max7301.c (renamed from drivers/gpio/max7301.c)2
-rw-r--r--drivers/gpio/gpio-max730x.c (renamed from drivers/gpio/max730x.c)2
-rw-r--r--drivers/gpio/gpio-max732x.c (renamed from drivers/gpio/max732x.c)2
-rw-r--r--drivers/gpio/gpio-mc33880.c (renamed from drivers/gpio/mc33880.c)2
-rw-r--r--drivers/gpio/gpio-mcp23s08.c (renamed from drivers/gpio/mcp23s08.c)291
-rw-r--r--drivers/gpio/gpio-ml-ioh.c (renamed from drivers/gpio/ml_ioh_gpio.c)2
-rw-r--r--drivers/gpio/gpio-mpc5200.c376
-rw-r--r--drivers/gpio/gpio-mxc.c460
-rw-r--r--drivers/gpio/gpio-mxs.c289
-rw-r--r--drivers/gpio/gpio-omap.c723
-rw-r--r--drivers/gpio/gpio-pca953x.c (renamed from drivers/gpio/pca953x.c)105
-rw-r--r--drivers/gpio/gpio-pcf857x.c (renamed from drivers/gpio/pcf857x.c)2
-rw-r--r--drivers/gpio/gpio-pch.c (renamed from drivers/gpio/pch_gpio.c)0
-rw-r--r--drivers/gpio/gpio-pl061.c (renamed from drivers/gpio/pl061.c)4
-rw-r--r--drivers/gpio/gpio-plat-samsung.c3
-rw-r--r--drivers/gpio/gpio-rdc321x.c (renamed from drivers/gpio/rdc321x-gpio.c)0
-rw-r--r--drivers/gpio/gpio-s5pc100.c5
-rw-r--r--drivers/gpio/gpio-s5pv210.c5
-rw-r--r--drivers/gpio/gpio-sch.c (renamed from drivers/gpio/sch_gpio.c)2
-rw-r--r--drivers/gpio/gpio-stmpe.c (renamed from drivers/gpio/stmpe-gpio.c)0
-rw-r--r--drivers/gpio/gpio-sx150x.c (renamed from drivers/gpio/sx150x.c)0
-rw-r--r--drivers/gpio/gpio-tc3589x.c (renamed from drivers/gpio/tc3589x-gpio.c)0
-rw-r--r--drivers/gpio/gpio-tegra.c441
-rw-r--r--drivers/gpio/gpio-timberdale.c (renamed from drivers/gpio/timbgpio.c)2
-rw-r--r--drivers/gpio/gpio-tps65910.c (renamed from drivers/gpio/tps65910-gpio.c)2
-rw-r--r--drivers/gpio/gpio-twl4030.c (renamed from drivers/gpio/twl4030-gpio.c)2
-rw-r--r--drivers/gpio/gpio-u300.c5
-rw-r--r--drivers/gpio/gpio-ucb1400.c (renamed from drivers/gpio/ucb1400_gpio.c)0
-rw-r--r--drivers/gpio/gpio-vr41xx.c (renamed from drivers/gpio/vr41xx_giu.c)2
-rw-r--r--drivers/gpio/gpio-vx855.c (renamed from drivers/gpio/vx855_gpio.c)0
-rw-r--r--drivers/gpio/gpio-wm831x.c (renamed from drivers/gpio/wm831x-gpio.c)2
-rw-r--r--drivers/gpio/gpio-wm8350.c (renamed from drivers/gpio/wm8350-gpiolib.c)2
-rw-r--r--drivers/gpio/gpio-wm8994.c (renamed from drivers/gpio/wm8994-gpio.c)2
-rw-r--r--drivers/gpio/gpio-xilinx.c (renamed from drivers/gpio/xilinx_gpio.c)0
50 files changed, 2820 insertions, 802 deletions
diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig
index 2967002a9f82..363498697c2c 100644
--- a/drivers/gpio/Kconfig
+++ b/drivers/gpio/Kconfig
@@ -63,33 +63,58 @@ config GPIO_SYSFS
63 Kernel drivers may also request that a particular GPIO be 63 Kernel drivers may also request that a particular GPIO be
64 exported to userspace; this can be useful when debugging. 64 exported to userspace; this can be useful when debugging.
65 65
66config GPIO_GENERIC
67 tristate
68
66# put drivers in the right section, in alphabetical order 69# put drivers in the right section, in alphabetical order
67 70
71config GPIO_DA9052
72 tristate "Dialog DA9052 GPIO"
73 depends on PMIC_DA9052
74 help
75 Say yes here to enable the GPIO driver for the DA9052 chip.
76
68config GPIO_MAX730X 77config GPIO_MAX730X
69 tristate 78 tristate
70 79
71comment "Memory mapped GPIO drivers:" 80comment "Memory mapped GPIO drivers:"
72 81
73config GPIO_BASIC_MMIO_CORE 82config GPIO_GENERIC_PLATFORM
74 tristate 83 tristate "Generic memory-mapped GPIO controller support (MMIO platform device)"
75 help 84 select GPIO_GENERIC
76 Provides core functionality for basic memory-mapped GPIO controllers.
77
78config GPIO_BASIC_MMIO
79 tristate "Basic memory-mapped GPIO controllers support"
80 select GPIO_BASIC_MMIO_CORE
81 help 85 help
82 Say yes here to support basic memory-mapped GPIO controllers. 86 Say yes here to support basic platform_device memory-mapped GPIO controllers.
83 87
84config GPIO_IT8761E 88config GPIO_IT8761E
85 tristate "IT8761E GPIO support" 89 tristate "IT8761E GPIO support"
86 help 90 help
87 Say yes here to support GPIO functionality of IT8761E super I/O chip. 91 Say yes here to support GPIO functionality of IT8761E super I/O chip.
88 92
93config GPIO_EP93XX
94 def_bool y
95 depends on ARCH_EP93XX
96 select GPIO_GENERIC
97
89config GPIO_EXYNOS4 98config GPIO_EXYNOS4
90 def_bool y 99 def_bool y
91 depends on CPU_EXYNOS4210 100 depends on CPU_EXYNOS4210
92 101
102config GPIO_MPC5200
103 def_bool y
104 depends on PPC_MPC52xx
105
106config GPIO_MXC
107 def_bool y
108 depends on ARCH_MXC
109 select GPIO_GENERIC
110 select GENERIC_IRQ_CHIP
111
112config GPIO_MXS
113 def_bool y
114 depends on ARCH_MXS
115 select GPIO_GENERIC
116 select GENERIC_IRQ_CHIP
117
93config GPIO_PLAT_SAMSUNG 118config GPIO_PLAT_SAMSUNG
94 def_bool y 119 def_bool y
95 depends on SAMSUNG_GPIOLIB_4BIT 120 depends on SAMSUNG_GPIOLIB_4BIT
@@ -137,9 +162,6 @@ config GPIO_SCH
137 The Intel Tunnel Creek processor has 5 GPIOs powered by the 162 The Intel Tunnel Creek processor has 5 GPIOs powered by the
138 core power rail and 9 from suspend power supply. 163 core power rail and 9 from suspend power supply.
139 164
140 This driver can also be built as a module. If so, the module
141 will be called sch-gpio.
142
143config GPIO_VX855 165config GPIO_VX855
144 tristate "VIA VX855/VX875 GPIO" 166 tristate "VIA VX855/VX875 GPIO"
145 depends on MFD_SUPPORT && PCI 167 depends on MFD_SUPPORT && PCI
@@ -202,9 +224,6 @@ config GPIO_PCA953X
202 224
203 16 bits: pca9535, pca9539, pca9555, tca6416 225 16 bits: pca9535, pca9539, pca9555, tca6416
204 226
205 This driver can also be built as a module. If so, the module
206 will be called pca953x.
207
208config GPIO_PCA953X_IRQ 227config GPIO_PCA953X_IRQ
209 bool "Interrupt controller support for PCA953x" 228 bool "Interrupt controller support for PCA953x"
210 depends on GPIO_PCA953X=y 229 depends on GPIO_PCA953X=y
@@ -296,17 +315,12 @@ config GPIO_ADP5520
296 This option enables support for on-chip GPIO found 315 This option enables support for on-chip GPIO found
297 on Analog Devices ADP5520 PMICs. 316 on Analog Devices ADP5520 PMICs.
298 317
299 To compile this driver as a module, choose M here: the module will
300 be called adp5520-gpio.
301
302config GPIO_ADP5588 318config GPIO_ADP5588
303 tristate "ADP5588 I2C GPIO expander" 319 tristate "ADP5588 I2C GPIO expander"
304 depends on I2C 320 depends on I2C
305 help 321 help
306 This option enables support for 18 GPIOs found 322 This option enables support for 18 GPIOs found
307 on Analog Devices ADP5588 GPIO Expanders. 323 on Analog Devices ADP5588 GPIO Expanders.
308 To compile this driver as a module, choose M here: the module will be
309 called adp5588-gpio.
310 324
311config GPIO_ADP5588_IRQ 325config GPIO_ADP5588_IRQ
312 bool "Interrupt controller support for ADP5588" 326 bool "Interrupt controller support for ADP5588"
@@ -398,10 +412,11 @@ config GPIO_MAX7301
398 GPIO driver for Maxim MAX7301 SPI-based GPIO expander. 412 GPIO driver for Maxim MAX7301 SPI-based GPIO expander.
399 413
400config GPIO_MCP23S08 414config GPIO_MCP23S08
401 tristate "Microchip MCP23Sxx I/O expander" 415 tristate "Microchip MCP23xxx I/O expander"
402 depends on SPI_MASTER 416 depends on SPI_MASTER || I2C
403 help 417 help
404 SPI driver for Microchip MCP23S08/MPC23S17 I/O expanders. 418 SPI/I2C driver for Microchip MCP23S08/MCP23S17/MCP23008/MCP23017
419 I/O expanders.
405 This provides a GPIO interface supporting inputs and outputs. 420 This provides a GPIO interface supporting inputs and outputs.
406 421
407config GPIO_MC33880 422config GPIO_MC33880
@@ -428,9 +443,6 @@ config GPIO_UCB1400
428 This enables support for the Philips UCB1400 GPIO pins. 443 This enables support for the Philips UCB1400 GPIO pins.
429 The UCB1400 is an AC97 audio codec. 444 The UCB1400 is an AC97 audio codec.
430 445
431 To compile this driver as a module, choose M here: the
432 module will be called ucb1400_gpio.
433
434comment "MODULbus GPIO expanders:" 446comment "MODULbus GPIO expanders:"
435 447
436config GPIO_JANZ_TTL 448config GPIO_JANZ_TTL
@@ -441,7 +453,7 @@ config GPIO_JANZ_TTL
441 This driver provides support for driving the pins in output 453 This driver provides support for driving the pins in output
442 mode only. Input mode is not supported. 454 mode only. Input mode is not supported.
443 455
444config AB8500_GPIO 456config GPIO_AB8500
445 bool "ST-Ericsson AB8500 Mixed Signal Circuit gpio functions" 457 bool "ST-Ericsson AB8500 Mixed Signal Circuit gpio functions"
446 depends on AB8500_CORE && BROKEN 458 depends on AB8500_CORE && BROKEN
447 help 459 help
diff --git a/drivers/gpio/Makefile b/drivers/gpio/Makefile
index b605f8ec6fbe..720711251391 100644
--- a/drivers/gpio/Makefile
+++ b/drivers/gpio/Makefile
@@ -4,47 +4,56 @@ ccflags-$(CONFIG_DEBUG_GPIO) += -DDEBUG
4 4
5obj-$(CONFIG_GPIOLIB) += gpiolib.o 5obj-$(CONFIG_GPIOLIB) += gpiolib.o
6 6
7obj-$(CONFIG_GPIO_ADP5520) += adp5520-gpio.o 7# Device drivers. Generally keep list sorted alphabetically
8obj-$(CONFIG_GPIO_ADP5588) += adp5588-gpio.o 8obj-$(CONFIG_GPIO_GENERIC) += gpio-generic.o
9obj-$(CONFIG_GPIO_BASIC_MMIO_CORE) += basic_mmio_gpio.o 9
10obj-$(CONFIG_GPIO_BASIC_MMIO) += basic_mmio_gpio.o 10obj-$(CONFIG_GPIO_74X164) += gpio-74x164.o
11obj-$(CONFIG_GPIO_AB8500) += gpio-ab8500.o
12obj-$(CONFIG_GPIO_ADP5520) += gpio-adp5520.o
13obj-$(CONFIG_GPIO_ADP5588) += gpio-adp5588.o
14obj-$(CONFIG_GPIO_BT8XX) += gpio-bt8xx.o
15obj-$(CONFIG_GPIO_CS5535) += gpio-cs5535.o
16obj-$(CONFIG_GPIO_DA9052) += gpio-da9052.o
17obj-$(CONFIG_GPIO_EP93XX) += gpio-ep93xx.o
11obj-$(CONFIG_GPIO_EXYNOS4) += gpio-exynos4.o 18obj-$(CONFIG_GPIO_EXYNOS4) += gpio-exynos4.o
19obj-$(CONFIG_GPIO_IT8761E) += gpio-it8761e.o
20obj-$(CONFIG_GPIO_JANZ_TTL) += gpio-janz-ttl.o
21obj-$(CONFIG_GPIO_LANGWELL) += gpio-langwell.o
22obj-$(CONFIG_GPIO_MAX730X) += gpio-max730x.o
23obj-$(CONFIG_GPIO_MAX7300) += gpio-max7300.o
24obj-$(CONFIG_GPIO_MAX7301) += gpio-max7301.o
25obj-$(CONFIG_GPIO_MAX732X) += gpio-max732x.o
26obj-$(CONFIG_GPIO_MC33880) += gpio-mc33880.o
27obj-$(CONFIG_GPIO_MCP23S08) += gpio-mcp23s08.o
28obj-$(CONFIG_GPIO_ML_IOH) += gpio-ml-ioh.o
29obj-$(CONFIG_GPIO_MPC5200) += gpio-mpc5200.o
30obj-$(CONFIG_GPIO_MXC) += gpio-mxc.o
31obj-$(CONFIG_GPIO_MXS) += gpio-mxs.o
32obj-$(CONFIG_PLAT_NOMADIK) += gpio-nomadik.o
33obj-$(CONFIG_ARCH_OMAP) += gpio-omap.o
34obj-$(CONFIG_GPIO_PCA953X) += gpio-pca953x.o
35obj-$(CONFIG_GPIO_PCF857X) += gpio-pcf857x.o
36obj-$(CONFIG_GPIO_PCH) += gpio-pch.o
37obj-$(CONFIG_GPIO_PL061) += gpio-pl061.o
38obj-$(CONFIG_GPIO_RDC321X) += gpio-rdc321x.o
39
12obj-$(CONFIG_GPIO_PLAT_SAMSUNG) += gpio-plat-samsung.o 40obj-$(CONFIG_GPIO_PLAT_SAMSUNG) += gpio-plat-samsung.o
13obj-$(CONFIG_GPIO_S5PC100) += gpio-s5pc100.o 41obj-$(CONFIG_GPIO_S5PC100) += gpio-s5pc100.o
14obj-$(CONFIG_GPIO_S5PV210) += gpio-s5pv210.o 42obj-$(CONFIG_GPIO_S5PV210) += gpio-s5pv210.o
15obj-$(CONFIG_GPIO_LANGWELL) += langwell_gpio.o 43
16obj-$(CONFIG_GPIO_MAX730X) += max730x.o 44obj-$(CONFIG_GPIO_SCH) += gpio-sch.o
17obj-$(CONFIG_GPIO_MAX7300) += max7300.o 45obj-$(CONFIG_GPIO_STMPE) += gpio-stmpe.o
18obj-$(CONFIG_GPIO_MAX7301) += max7301.o 46obj-$(CONFIG_GPIO_SX150X) += gpio-sx150x.o
19obj-$(CONFIG_GPIO_MAX732X) += max732x.o 47obj-$(CONFIG_GPIO_TC3589X) += gpio-tc3589x.o
20obj-$(CONFIG_GPIO_MC33880) += mc33880.o 48obj-$(CONFIG_ARCH_TEGRA) += gpio-tegra.o
21obj-$(CONFIG_GPIO_MCP23S08) += mcp23s08.o 49obj-$(CONFIG_GPIO_TIMBERDALE) += gpio-timberdale.o
22obj-$(CONFIG_GPIO_74X164) += 74x164.o 50obj-$(CONFIG_GPIO_TPS65910) += gpio-tps65910.o
23obj-$(CONFIG_ARCH_OMAP) += gpio-omap.o 51obj-$(CONFIG_GPIO_TWL4030) += gpio-twl4030.o
24obj-$(CONFIG_GPIO_PCA953X) += pca953x.o
25obj-$(CONFIG_GPIO_PCF857X) += pcf857x.o
26obj-$(CONFIG_GPIO_PCH) += pch_gpio.o
27obj-$(CONFIG_GPIO_PL061) += pl061.o
28obj-$(CONFIG_GPIO_STMPE) += stmpe-gpio.o
29obj-$(CONFIG_GPIO_TC3589X) += tc3589x-gpio.o
30obj-$(CONFIG_GPIO_TIMBERDALE) += timbgpio.o
31obj-$(CONFIG_GPIO_TWL4030) += twl4030-gpio.o
32obj-$(CONFIG_GPIO_UCB1400) += ucb1400_gpio.o
33obj-$(CONFIG_GPIO_XILINX) += xilinx_gpio.o
34obj-$(CONFIG_GPIO_CS5535) += cs5535-gpio.o
35obj-$(CONFIG_GPIO_BT8XX) += bt8xxgpio.o
36obj-$(CONFIG_GPIO_IT8761E) += it8761e_gpio.o
37obj-$(CONFIG_GPIO_VR41XX) += vr41xx_giu.o
38obj-$(CONFIG_GPIO_WM831X) += wm831x-gpio.o
39obj-$(CONFIG_GPIO_WM8350) += wm8350-gpiolib.o
40obj-$(CONFIG_GPIO_WM8994) += wm8994-gpio.o
41obj-$(CONFIG_GPIO_SCH) += sch_gpio.o
42obj-$(CONFIG_MACH_U300) += gpio-u300.o 52obj-$(CONFIG_MACH_U300) += gpio-u300.o
43obj-$(CONFIG_PLAT_NOMADIK) += gpio-nomadik.o 53obj-$(CONFIG_GPIO_UCB1400) += gpio-ucb1400.o
44obj-$(CONFIG_GPIO_RDC321X) += rdc321x-gpio.o 54obj-$(CONFIG_GPIO_VR41XX) += gpio-vr41xx.o
45obj-$(CONFIG_GPIO_JANZ_TTL) += janz-ttl.o 55obj-$(CONFIG_GPIO_VX855) += gpio-vx855.o
46obj-$(CONFIG_GPIO_SX150X) += sx150x.o 56obj-$(CONFIG_GPIO_WM831X) += gpio-wm831x.o
47obj-$(CONFIG_GPIO_VX855) += vx855_gpio.o 57obj-$(CONFIG_GPIO_WM8350) += gpio-wm8350.o
48obj-$(CONFIG_GPIO_ML_IOH) += ml_ioh_gpio.o 58obj-$(CONFIG_GPIO_WM8994) += gpio-wm8994.o
49obj-$(CONFIG_AB8500_GPIO) += ab8500-gpio.o 59obj-$(CONFIG_GPIO_XILINX) += gpio-xilinx.o
50obj-$(CONFIG_GPIO_TPS65910) += tps65910-gpio.o
diff --git a/drivers/gpio/74x164.c b/drivers/gpio/gpio-74x164.c
index 84e070219839..ff525c0958dd 100644
--- a/drivers/gpio/74x164.c
+++ b/drivers/gpio/gpio-74x164.c
@@ -16,9 +16,6 @@
16#include <linux/gpio.h> 16#include <linux/gpio.h>
17#include <linux/slab.h> 17#include <linux/slab.h>
18 18
19#define GEN_74X164_GPIO_COUNT 8
20
21
22struct gen_74x164_chip { 19struct gen_74x164_chip {
23 struct spi_device *spi; 20 struct spi_device *spi;
24 struct gpio_chip gpio_chip; 21 struct gpio_chip gpio_chip;
@@ -26,9 +23,7 @@ struct gen_74x164_chip {
26 u8 port_config; 23 u8 port_config;
27}; 24};
28 25
29static void gen_74x164_set_value(struct gpio_chip *, unsigned, int); 26static struct gen_74x164_chip *gpio_to_74x164_chip(struct gpio_chip *gc)
30
31static struct gen_74x164_chip *gpio_to_chip(struct gpio_chip *gc)
32{ 27{
33 return container_of(gc, struct gen_74x164_chip, gpio_chip); 28 return container_of(gc, struct gen_74x164_chip, gpio_chip);
34} 29}
@@ -39,16 +34,9 @@ static int __gen_74x164_write_config(struct gen_74x164_chip *chip)
39 &chip->port_config, sizeof(chip->port_config)); 34 &chip->port_config, sizeof(chip->port_config));
40} 35}
41 36
42static int gen_74x164_direction_output(struct gpio_chip *gc,
43 unsigned offset, int val)
44{
45 gen_74x164_set_value(gc, offset, val);
46 return 0;
47}
48
49static int gen_74x164_get_value(struct gpio_chip *gc, unsigned offset) 37static int gen_74x164_get_value(struct gpio_chip *gc, unsigned offset)
50{ 38{
51 struct gen_74x164_chip *chip = gpio_to_chip(gc); 39 struct gen_74x164_chip *chip = gpio_to_74x164_chip(gc);
52 int ret; 40 int ret;
53 41
54 mutex_lock(&chip->lock); 42 mutex_lock(&chip->lock);
@@ -61,7 +49,7 @@ static int gen_74x164_get_value(struct gpio_chip *gc, unsigned offset)
61static void gen_74x164_set_value(struct gpio_chip *gc, 49static void gen_74x164_set_value(struct gpio_chip *gc,
62 unsigned offset, int val) 50 unsigned offset, int val)
63{ 51{
64 struct gen_74x164_chip *chip = gpio_to_chip(gc); 52 struct gen_74x164_chip *chip = gpio_to_74x164_chip(gc);
65 53
66 mutex_lock(&chip->lock); 54 mutex_lock(&chip->lock);
67 if (val) 55 if (val)
@@ -73,6 +61,13 @@ static void gen_74x164_set_value(struct gpio_chip *gc,
73 mutex_unlock(&chip->lock); 61 mutex_unlock(&chip->lock);
74} 62}
75 63
64static int gen_74x164_direction_output(struct gpio_chip *gc,
65 unsigned offset, int val)
66{
67 gen_74x164_set_value(gc, offset, val);
68 return 0;
69}
70
76static int __devinit gen_74x164_probe(struct spi_device *spi) 71static int __devinit gen_74x164_probe(struct spi_device *spi)
77{ 72{
78 struct gen_74x164_chip *chip; 73 struct gen_74x164_chip *chip;
@@ -104,12 +99,12 @@ static int __devinit gen_74x164_probe(struct spi_device *spi)
104 99
105 chip->spi = spi; 100 chip->spi = spi;
106 101
107 chip->gpio_chip.label = GEN_74X164_DRIVER_NAME, 102 chip->gpio_chip.label = spi->modalias;
108 chip->gpio_chip.direction_output = gen_74x164_direction_output; 103 chip->gpio_chip.direction_output = gen_74x164_direction_output;
109 chip->gpio_chip.get = gen_74x164_get_value; 104 chip->gpio_chip.get = gen_74x164_get_value;
110 chip->gpio_chip.set = gen_74x164_set_value; 105 chip->gpio_chip.set = gen_74x164_set_value;
111 chip->gpio_chip.base = pdata->base; 106 chip->gpio_chip.base = pdata->base;
112 chip->gpio_chip.ngpio = GEN_74X164_GPIO_COUNT; 107 chip->gpio_chip.ngpio = 8;
113 chip->gpio_chip.can_sleep = 1; 108 chip->gpio_chip.can_sleep = 1;
114 chip->gpio_chip.dev = &spi->dev; 109 chip->gpio_chip.dev = &spi->dev;
115 chip->gpio_chip.owner = THIS_MODULE; 110 chip->gpio_chip.owner = THIS_MODULE;
@@ -157,7 +152,7 @@ static int __devexit gen_74x164_remove(struct spi_device *spi)
157 152
158static struct spi_driver gen_74x164_driver = { 153static struct spi_driver gen_74x164_driver = {
159 .driver = { 154 .driver = {
160 .name = GEN_74X164_DRIVER_NAME, 155 .name = "74x164",
161 .owner = THIS_MODULE, 156 .owner = THIS_MODULE,
162 }, 157 },
163 .probe = gen_74x164_probe, 158 .probe = gen_74x164_probe,
diff --git a/drivers/gpio/ab8500-gpio.c b/drivers/gpio/gpio-ab8500.c
index 970053c89ff7..970053c89ff7 100644
--- a/drivers/gpio/ab8500-gpio.c
+++ b/drivers/gpio/gpio-ab8500.c
diff --git a/drivers/gpio/adp5520-gpio.c b/drivers/gpio/gpio-adp5520.c
index 9f2781537001..9f2781537001 100644
--- a/drivers/gpio/adp5520-gpio.c
+++ b/drivers/gpio/gpio-adp5520.c
diff --git a/drivers/gpio/adp5588-gpio.c b/drivers/gpio/gpio-adp5588.c
index 3525ad918771..3525ad918771 100644
--- a/drivers/gpio/adp5588-gpio.c
+++ b/drivers/gpio/gpio-adp5588.c
diff --git a/drivers/gpio/bt8xxgpio.c b/drivers/gpio/gpio-bt8xx.c
index aa4f09ad3ced..aa4f09ad3ced 100644
--- a/drivers/gpio/bt8xxgpio.c
+++ b/drivers/gpio/gpio-bt8xx.c
diff --git a/drivers/gpio/cs5535-gpio.c b/drivers/gpio/gpio-cs5535.c
index 6e16cba56ad2..6e16cba56ad2 100644
--- a/drivers/gpio/cs5535-gpio.c
+++ b/drivers/gpio/gpio-cs5535.c
diff --git a/drivers/gpio/gpio-da9052.c b/drivers/gpio/gpio-da9052.c
new file mode 100644
index 000000000000..038f5eb8b13d
--- /dev/null
+++ b/drivers/gpio/gpio-da9052.c
@@ -0,0 +1,277 @@
1/*
2 * GPIO Driver for Dialog DA9052 PMICs.
3 *
4 * Copyright(c) 2011 Dialog Semiconductor Ltd.
5 *
6 * Author: David Dajun Chen <dchen@diasemi.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 */
14#include <linux/module.h>
15#include <linux/fs.h>
16#include <linux/uaccess.h>
17#include <linux/platform_device.h>
18#include <linux/gpio.h>
19#include <linux/syscalls.h>
20#include <linux/seq_file.h>
21
22#include <linux/mfd/da9052/da9052.h>
23#include <linux/mfd/da9052/reg.h>
24#include <linux/mfd/da9052/pdata.h>
25#include <linux/mfd/da9052/gpio.h>
26
27#define DA9052_INPUT 1
28#define DA9052_OUTPUT_OPENDRAIN 2
29#define DA9052_OUTPUT_PUSHPULL 3
30
31#define DA9052_SUPPLY_VDD_IO1 0
32
33#define DA9052_DEBOUNCING_OFF 0
34#define DA9052_DEBOUNCING_ON 1
35
36#define DA9052_OUTPUT_LOWLEVEL 0
37
38#define DA9052_ACTIVE_LOW 0
39#define DA9052_ACTIVE_HIGH 1
40
41#define DA9052_GPIO_MAX_PORTS_PER_REGISTER 8
42#define DA9052_GPIO_SHIFT_COUNT(no) (no%8)
43#define DA9052_GPIO_MASK_UPPER_NIBBLE 0xF0
44#define DA9052_GPIO_MASK_LOWER_NIBBLE 0x0F
45#define DA9052_GPIO_NIBBLE_SHIFT 4
46
47struct da9052_gpio {
48 struct da9052 *da9052;
49 struct gpio_chip gp;
50};
51
52static inline struct da9052_gpio *to_da9052_gpio(struct gpio_chip *chip)
53{
54 return container_of(chip, struct da9052_gpio, gp);
55}
56
57static unsigned char da9052_gpio_port_odd(unsigned offset)
58{
59 return offset % 2;
60}
61
62static int da9052_gpio_get(struct gpio_chip *gc, unsigned offset)
63{
64 struct da9052_gpio *gpio = to_da9052_gpio(gc);
65 int da9052_port_direction = 0;
66 int ret;
67
68 ret = da9052_reg_read(gpio->da9052,
69 DA9052_GPIO_0_1_REG + (offset >> 1));
70 if (ret < 0)
71 return ret;
72
73 if (da9052_gpio_port_odd(offset)) {
74 da9052_port_direction = ret & DA9052_GPIO_ODD_PORT_PIN;
75 da9052_port_direction >>= 4;
76 } else {
77 da9052_port_direction = ret & DA9052_GPIO_EVEN_PORT_PIN;
78 }
79
80 switch (da9052_port_direction) {
81 case DA9052_INPUT:
82 if (offset < DA9052_GPIO_MAX_PORTS_PER_REGISTER)
83 ret = da9052_reg_read(gpio->da9052,
84 DA9052_STATUS_C_REG);
85 else
86 ret = da9052_reg_read(gpio->da9052,
87 DA9052_STATUS_D_REG);
88 if (ret < 0)
89 return ret;
90 if (ret & (1 << DA9052_GPIO_SHIFT_COUNT(offset)))
91 return 1;
92 else
93 return 0;
94 case DA9052_OUTPUT_PUSHPULL:
95 if (da9052_gpio_port_odd(offset))
96 return ret & DA9052_GPIO_ODD_PORT_MODE;
97 else
98 return ret & DA9052_GPIO_EVEN_PORT_MODE;
99 default:
100 return -EINVAL;
101 }
102}
103
104static void da9052_gpio_set(struct gpio_chip *gc, unsigned offset, int value)
105{
106 struct da9052_gpio *gpio = to_da9052_gpio(gc);
107 unsigned char register_value = 0;
108 int ret;
109
110 if (da9052_gpio_port_odd(offset)) {
111 if (value) {
112 register_value = DA9052_GPIO_ODD_PORT_MODE;
113 ret = da9052_reg_update(gpio->da9052, (offset >> 1) +
114 DA9052_GPIO_0_1_REG,
115 DA9052_GPIO_ODD_PORT_MODE,
116 register_value);
117 if (ret != 0)
118 dev_err(gpio->da9052->dev,
119 "Failed to updated gpio odd reg,%d",
120 ret);
121 }
122 } else {
123 if (value) {
124 register_value = DA9052_GPIO_EVEN_PORT_MODE;
125 ret = da9052_reg_update(gpio->da9052, (offset >> 1) +
126 DA9052_GPIO_0_1_REG,
127 DA9052_GPIO_EVEN_PORT_MODE,
128 register_value);
129 if (ret != 0)
130 dev_err(gpio->da9052->dev,
131 "Failed to updated gpio even reg,%d",
132 ret);
133 }
134 }
135}
136
137static int da9052_gpio_direction_input(struct gpio_chip *gc, unsigned offset)
138{
139 struct da9052_gpio *gpio = to_da9052_gpio(gc);
140 unsigned char register_value;
141 int ret;
142
143 /* Format: function - 2 bits type - 1 bit mode - 1 bit */
144 register_value = DA9052_INPUT | DA9052_ACTIVE_LOW << 2 |
145 DA9052_DEBOUNCING_ON << 3;
146
147 if (da9052_gpio_port_odd(offset))
148 ret = da9052_reg_update(gpio->da9052, (offset >> 1) +
149 DA9052_GPIO_0_1_REG,
150 DA9052_GPIO_MASK_UPPER_NIBBLE,
151 (register_value <<
152 DA9052_GPIO_NIBBLE_SHIFT));
153 else
154 ret = da9052_reg_update(gpio->da9052, (offset >> 1) +
155 DA9052_GPIO_0_1_REG,
156 DA9052_GPIO_MASK_LOWER_NIBBLE,
157 register_value);
158
159 return ret;
160}
161
162static int da9052_gpio_direction_output(struct gpio_chip *gc,
163 unsigned offset, int value)
164{
165 struct da9052_gpio *gpio = to_da9052_gpio(gc);
166 unsigned char register_value;
167 int ret;
168
169 /* Format: Function - 2 bits Type - 1 bit Mode - 1 bit */
170 register_value = DA9052_OUTPUT_PUSHPULL | DA9052_SUPPLY_VDD_IO1 << 2 |
171 value << 3;
172
173 if (da9052_gpio_port_odd(offset))
174 ret = da9052_reg_update(gpio->da9052, (offset >> 1) +
175 DA9052_GPIO_0_1_REG,
176 DA9052_GPIO_MASK_UPPER_NIBBLE,
177 (register_value <<
178 DA9052_GPIO_NIBBLE_SHIFT));
179 else
180 ret = da9052_reg_update(gpio->da9052, (offset >> 1) +
181 DA9052_GPIO_0_1_REG,
182 DA9052_GPIO_MASK_LOWER_NIBBLE,
183 register_value);
184
185 return ret;
186}
187
188static int da9052_gpio_to_irq(struct gpio_chip *gc, u32 offset)
189{
190 struct da9052_gpio *gpio = to_da9052_gpio(gc);
191 struct da9052 *da9052 = gpio->da9052;
192
193 return da9052->irq_base + DA9052_IRQ_GPI0 + offset;
194}
195
196static struct gpio_chip reference_gp __devinitdata = {
197 .label = "da9052-gpio",
198 .owner = THIS_MODULE,
199 .get = da9052_gpio_get,
200 .set = da9052_gpio_set,
201 .direction_input = da9052_gpio_direction_input,
202 .direction_output = da9052_gpio_direction_output,
203 .to_irq = da9052_gpio_to_irq,
204 .can_sleep = 1;
205 .ngpio = 16;
206 .base = -1;
207};
208
209static int __devinit da9052_gpio_probe(struct platform_device *pdev)
210{
211 struct da9052_gpio *gpio;
212 struct da9052_pdata *pdata;
213 int ret;
214
215 gpio = kzalloc(sizeof(*gpio), GFP_KERNEL);
216 if (gpio == NULL)
217 return -ENOMEM;
218
219 gpio->da9052 = dev_get_drvdata(pdev->dev.parent);
220 pdata = gpio->da9052->dev->platform_data;
221
222 gpio->gp = reference_gp;
223 if (pdata && pdata->gpio_base)
224 gpio->gp.base = pdata->gpio_base;
225
226 ret = gpiochip_add(&gpio->gp);
227 if (ret < 0) {
228 dev_err(&pdev->dev, "Could not register gpiochip, %d\n", ret);
229 goto err_mem;
230 }
231
232 platform_set_drvdata(pdev, gpio);
233
234 return 0;
235
236err_mem:
237 kfree(gpio);
238 return ret;
239}
240
241static int __devexit da9052_gpio_remove(struct platform_device *pdev)
242{
243 struct da9052_gpio *gpio = platform_get_drvdata(pdev);
244 int ret;
245
246 ret = gpiochip_remove(&gpio->gp);
247 if (ret == 0)
248 kfree(gpio);
249
250 return ret;
251}
252
253static struct platform_driver da9052_gpio_driver = {
254 .probe = da9052_gpio_probe,
255 .remove = __devexit_p(da9052_gpio_remove),
256 .driver = {
257 .name = "da9052-gpio",
258 .owner = THIS_MODULE,
259 },
260};
261
262static int __init da9052_gpio_init(void)
263{
264 return platform_driver_register(&da9052_gpio_driver);
265}
266module_init(da9052_gpio_init);
267
268static void __exit da9052_gpio_exit(void)
269{
270 return platform_driver_unregister(&da9052_gpio_driver);
271}
272module_exit(da9052_gpio_exit);
273
274MODULE_AUTHOR("David Dajun Chen <dchen@diasemi.com>");
275MODULE_DESCRIPTION("DA9052 GPIO Device Driver");
276MODULE_LICENSE("GPL");
277MODULE_ALIAS("platform:da9052-gpio");
diff --git a/drivers/gpio/gpio-ep93xx.c b/drivers/gpio/gpio-ep93xx.c
new file mode 100644
index 000000000000..3bfd3417ab11
--- /dev/null
+++ b/drivers/gpio/gpio-ep93xx.c
@@ -0,0 +1,405 @@
1/*
2 * Generic EP93xx GPIO handling
3 *
4 * Copyright (c) 2008 Ryan Mallon <ryan@bluewatersys.com>
5 * Copyright (c) 2011 H Hartley Sweeten <hsweeten@visionengravers.com>
6 *
7 * Based on code originally from:
8 * linux/arch/arm/mach-ep93xx/core.c
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2 as
12 * published by the Free Software Foundation.
13 */
14
15#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
16
17#include <linux/init.h>
18#include <linux/platform_device.h>
19#include <linux/io.h>
20#include <linux/gpio.h>
21#include <linux/irq.h>
22#include <linux/slab.h>
23#include <linux/basic_mmio_gpio.h>
24
25#include <mach/hardware.h>
26
27struct ep93xx_gpio {
28 void __iomem *mmio_base;
29 struct bgpio_chip bgc[8];
30};
31
32/*************************************************************************
33 * Interrupt handling for EP93xx on-chip GPIOs
34 *************************************************************************/
35static unsigned char gpio_int_unmasked[3];
36static unsigned char gpio_int_enabled[3];
37static unsigned char gpio_int_type1[3];
38static unsigned char gpio_int_type2[3];
39static unsigned char gpio_int_debounce[3];
40
41/* Port ordering is: A B F */
42static const u8 int_type1_register_offset[3] = { 0x90, 0xac, 0x4c };
43static const u8 int_type2_register_offset[3] = { 0x94, 0xb0, 0x50 };
44static const u8 eoi_register_offset[3] = { 0x98, 0xb4, 0x54 };
45static const u8 int_en_register_offset[3] = { 0x9c, 0xb8, 0x58 };
46static const u8 int_debounce_register_offset[3] = { 0xa8, 0xc4, 0x64 };
47
48static void ep93xx_gpio_update_int_params(unsigned port)
49{
50 BUG_ON(port > 2);
51
52 __raw_writeb(0, EP93XX_GPIO_REG(int_en_register_offset[port]));
53
54 __raw_writeb(gpio_int_type2[port],
55 EP93XX_GPIO_REG(int_type2_register_offset[port]));
56
57 __raw_writeb(gpio_int_type1[port],
58 EP93XX_GPIO_REG(int_type1_register_offset[port]));
59
60 __raw_writeb(gpio_int_unmasked[port] & gpio_int_enabled[port],
61 EP93XX_GPIO_REG(int_en_register_offset[port]));
62}
63
64static inline void ep93xx_gpio_int_mask(unsigned line)
65{
66 gpio_int_unmasked[line >> 3] &= ~(1 << (line & 7));
67}
68
69static void ep93xx_gpio_int_debounce(unsigned int irq, bool enable)
70{
71 int line = irq_to_gpio(irq);
72 int port = line >> 3;
73 int port_mask = 1 << (line & 7);
74
75 if (enable)
76 gpio_int_debounce[port] |= port_mask;
77 else
78 gpio_int_debounce[port] &= ~port_mask;
79
80 __raw_writeb(gpio_int_debounce[port],
81 EP93XX_GPIO_REG(int_debounce_register_offset[port]));
82}
83
84static void ep93xx_gpio_ab_irq_handler(unsigned int irq, struct irq_desc *desc)
85{
86 unsigned char status;
87 int i;
88
89 status = __raw_readb(EP93XX_GPIO_A_INT_STATUS);
90 for (i = 0; i < 8; i++) {
91 if (status & (1 << i)) {
92 int gpio_irq = gpio_to_irq(EP93XX_GPIO_LINE_A(0)) + i;
93 generic_handle_irq(gpio_irq);
94 }
95 }
96
97 status = __raw_readb(EP93XX_GPIO_B_INT_STATUS);
98 for (i = 0; i < 8; i++) {
99 if (status & (1 << i)) {
100 int gpio_irq = gpio_to_irq(EP93XX_GPIO_LINE_B(0)) + i;
101 generic_handle_irq(gpio_irq);
102 }
103 }
104}
105
106static void ep93xx_gpio_f_irq_handler(unsigned int irq, struct irq_desc *desc)
107{
108 /*
109 * map discontiguous hw irq range to continuous sw irq range:
110 *
111 * IRQ_EP93XX_GPIO{0..7}MUX -> gpio_to_irq(EP93XX_GPIO_LINE_F({0..7})
112 */
113 int port_f_idx = ((irq + 1) & 7) ^ 4; /* {19..22,47..50} -> {0..7} */
114 int gpio_irq = gpio_to_irq(EP93XX_GPIO_LINE_F(0)) + port_f_idx;
115
116 generic_handle_irq(gpio_irq);
117}
118
119static void ep93xx_gpio_irq_ack(struct irq_data *d)
120{
121 int line = irq_to_gpio(d->irq);
122 int port = line >> 3;
123 int port_mask = 1 << (line & 7);
124
125 if (irqd_get_trigger_type(d) == IRQ_TYPE_EDGE_BOTH) {
126 gpio_int_type2[port] ^= port_mask; /* switch edge direction */
127 ep93xx_gpio_update_int_params(port);
128 }
129
130 __raw_writeb(port_mask, EP93XX_GPIO_REG(eoi_register_offset[port]));
131}
132
133static void ep93xx_gpio_irq_mask_ack(struct irq_data *d)
134{
135 int line = irq_to_gpio(d->irq);
136 int port = line >> 3;
137 int port_mask = 1 << (line & 7);
138
139 if (irqd_get_trigger_type(d) == IRQ_TYPE_EDGE_BOTH)
140 gpio_int_type2[port] ^= port_mask; /* switch edge direction */
141
142 gpio_int_unmasked[port] &= ~port_mask;
143 ep93xx_gpio_update_int_params(port);
144
145 __raw_writeb(port_mask, EP93XX_GPIO_REG(eoi_register_offset[port]));
146}
147
148static void ep93xx_gpio_irq_mask(struct irq_data *d)
149{
150 int line = irq_to_gpio(d->irq);
151 int port = line >> 3;
152
153 gpio_int_unmasked[port] &= ~(1 << (line & 7));
154 ep93xx_gpio_update_int_params(port);
155}
156
157static void ep93xx_gpio_irq_unmask(struct irq_data *d)
158{
159 int line = irq_to_gpio(d->irq);
160 int port = line >> 3;
161
162 gpio_int_unmasked[port] |= 1 << (line & 7);
163 ep93xx_gpio_update_int_params(port);
164}
165
166/*
167 * gpio_int_type1 controls whether the interrupt is level (0) or
168 * edge (1) triggered, while gpio_int_type2 controls whether it
169 * triggers on low/falling (0) or high/rising (1).
170 */
171static int ep93xx_gpio_irq_type(struct irq_data *d, unsigned int type)
172{
173 const int gpio = irq_to_gpio(d->irq);
174 const int port = gpio >> 3;
175 const int port_mask = 1 << (gpio & 7);
176 irq_flow_handler_t handler;
177
178 gpio_direction_input(gpio);
179
180 switch (type) {
181 case IRQ_TYPE_EDGE_RISING:
182 gpio_int_type1[port] |= port_mask;
183 gpio_int_type2[port] |= port_mask;
184 handler = handle_edge_irq;
185 break;
186 case IRQ_TYPE_EDGE_FALLING:
187 gpio_int_type1[port] |= port_mask;
188 gpio_int_type2[port] &= ~port_mask;
189 handler = handle_edge_irq;
190 break;
191 case IRQ_TYPE_LEVEL_HIGH:
192 gpio_int_type1[port] &= ~port_mask;
193 gpio_int_type2[port] |= port_mask;
194 handler = handle_level_irq;
195 break;
196 case IRQ_TYPE_LEVEL_LOW:
197 gpio_int_type1[port] &= ~port_mask;
198 gpio_int_type2[port] &= ~port_mask;
199 handler = handle_level_irq;
200 break;
201 case IRQ_TYPE_EDGE_BOTH:
202 gpio_int_type1[port] |= port_mask;
203 /* set initial polarity based on current input level */
204 if (gpio_get_value(gpio))
205 gpio_int_type2[port] &= ~port_mask; /* falling */
206 else
207 gpio_int_type2[port] |= port_mask; /* rising */
208 handler = handle_edge_irq;
209 break;
210 default:
211 pr_err("failed to set irq type %d for gpio %d\n", type, gpio);
212 return -EINVAL;
213 }
214
215 __irq_set_handler_locked(d->irq, handler);
216
217 gpio_int_enabled[port] |= port_mask;
218
219 ep93xx_gpio_update_int_params(port);
220
221 return 0;
222}
223
224static struct irq_chip ep93xx_gpio_irq_chip = {
225 .name = "GPIO",
226 .irq_ack = ep93xx_gpio_irq_ack,
227 .irq_mask_ack = ep93xx_gpio_irq_mask_ack,
228 .irq_mask = ep93xx_gpio_irq_mask,
229 .irq_unmask = ep93xx_gpio_irq_unmask,
230 .irq_set_type = ep93xx_gpio_irq_type,
231};
232
233static void ep93xx_gpio_init_irq(void)
234{
235 int gpio_irq;
236
237 for (gpio_irq = gpio_to_irq(0);
238 gpio_irq <= gpio_to_irq(EP93XX_GPIO_LINE_MAX_IRQ); ++gpio_irq) {
239 irq_set_chip_and_handler(gpio_irq, &ep93xx_gpio_irq_chip,
240 handle_level_irq);
241 set_irq_flags(gpio_irq, IRQF_VALID);
242 }
243
244 irq_set_chained_handler(IRQ_EP93XX_GPIO_AB,
245 ep93xx_gpio_ab_irq_handler);
246 irq_set_chained_handler(IRQ_EP93XX_GPIO0MUX,
247 ep93xx_gpio_f_irq_handler);
248 irq_set_chained_handler(IRQ_EP93XX_GPIO1MUX,
249 ep93xx_gpio_f_irq_handler);
250 irq_set_chained_handler(IRQ_EP93XX_GPIO2MUX,
251 ep93xx_gpio_f_irq_handler);
252 irq_set_chained_handler(IRQ_EP93XX_GPIO3MUX,
253 ep93xx_gpio_f_irq_handler);
254 irq_set_chained_handler(IRQ_EP93XX_GPIO4MUX,
255 ep93xx_gpio_f_irq_handler);
256 irq_set_chained_handler(IRQ_EP93XX_GPIO5MUX,
257 ep93xx_gpio_f_irq_handler);
258 irq_set_chained_handler(IRQ_EP93XX_GPIO6MUX,
259 ep93xx_gpio_f_irq_handler);
260 irq_set_chained_handler(IRQ_EP93XX_GPIO7MUX,
261 ep93xx_gpio_f_irq_handler);
262}
263
264
265/*************************************************************************
266 * gpiolib interface for EP93xx on-chip GPIOs
267 *************************************************************************/
268struct ep93xx_gpio_bank {
269 const char *label;
270 int data;
271 int dir;
272 int base;
273 bool has_debounce;
274};
275
276#define EP93XX_GPIO_BANK(_label, _data, _dir, _base, _debounce) \
277 { \
278 .label = _label, \
279 .data = _data, \
280 .dir = _dir, \
281 .base = _base, \
282 .has_debounce = _debounce, \
283 }
284
285static struct ep93xx_gpio_bank ep93xx_gpio_banks[] = {
286 EP93XX_GPIO_BANK("A", 0x00, 0x10, 0, true),
287 EP93XX_GPIO_BANK("B", 0x04, 0x14, 8, true),
288 EP93XX_GPIO_BANK("C", 0x08, 0x18, 40, false),
289 EP93XX_GPIO_BANK("D", 0x0c, 0x1c, 24, false),
290 EP93XX_GPIO_BANK("E", 0x20, 0x24, 32, false),
291 EP93XX_GPIO_BANK("F", 0x30, 0x34, 16, true),
292 EP93XX_GPIO_BANK("G", 0x38, 0x3c, 48, false),
293 EP93XX_GPIO_BANK("H", 0x40, 0x44, 56, false),
294};
295
296static int ep93xx_gpio_set_debounce(struct gpio_chip *chip,
297 unsigned offset, unsigned debounce)
298{
299 int gpio = chip->base + offset;
300 int irq = gpio_to_irq(gpio);
301
302 if (irq < 0)
303 return -EINVAL;
304
305 ep93xx_gpio_int_debounce(irq, debounce ? true : false);
306
307 return 0;
308}
309
310static int ep93xx_gpio_add_bank(struct bgpio_chip *bgc, struct device *dev,
311 void __iomem *mmio_base, struct ep93xx_gpio_bank *bank)
312{
313 void __iomem *data = mmio_base + bank->data;
314 void __iomem *dir = mmio_base + bank->dir;
315 int err;
316
317 err = bgpio_init(bgc, dev, 1, data, NULL, NULL, dir, NULL, false);
318 if (err)
319 return err;
320
321 bgc->gc.label = bank->label;
322 bgc->gc.base = bank->base;
323
324 if (bank->has_debounce)
325 bgc->gc.set_debounce = ep93xx_gpio_set_debounce;
326
327 return gpiochip_add(&bgc->gc);
328}
329
330static int __devinit ep93xx_gpio_probe(struct platform_device *pdev)
331{
332 struct ep93xx_gpio *ep93xx_gpio;
333 struct resource *res;
334 void __iomem *mmio;
335 int i;
336 int ret;
337
338 ep93xx_gpio = kzalloc(sizeof(*ep93xx_gpio), GFP_KERNEL);
339 if (!ep93xx_gpio)
340 return -ENOMEM;
341
342 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
343 if (!res) {
344 ret = -ENXIO;
345 goto exit_free;
346 }
347
348 if (!request_mem_region(res->start, resource_size(res), pdev->name)) {
349 ret = -EBUSY;
350 goto exit_free;
351 }
352
353 mmio = ioremap(res->start, resource_size(res));
354 if (!mmio) {
355 ret = -ENXIO;
356 goto exit_release;
357 }
358 ep93xx_gpio->mmio_base = mmio;
359
360 /* Default all ports to GPIO */
361 ep93xx_devcfg_set_bits(EP93XX_SYSCON_DEVCFG_KEYS |
362 EP93XX_SYSCON_DEVCFG_GONK |
363 EP93XX_SYSCON_DEVCFG_EONIDE |
364 EP93XX_SYSCON_DEVCFG_GONIDE |
365 EP93XX_SYSCON_DEVCFG_HONIDE);
366
367 for (i = 0; i < ARRAY_SIZE(ep93xx_gpio_banks); i++) {
368 struct bgpio_chip *bgc = &ep93xx_gpio->bgc[i];
369 struct ep93xx_gpio_bank *bank = &ep93xx_gpio_banks[i];
370
371 if (ep93xx_gpio_add_bank(bgc, &pdev->dev, mmio, bank))
372 dev_warn(&pdev->dev, "Unable to add gpio bank %s\n",
373 bank->label);
374 }
375
376 ep93xx_gpio_init_irq();
377
378 return 0;
379
380exit_release:
381 release_mem_region(res->start, resource_size(res));
382exit_free:
383 kfree(ep93xx_gpio);
384 dev_info(&pdev->dev, "%s failed with errno %d\n", __func__, ret);
385 return ret;
386}
387
388static struct platform_driver ep93xx_gpio_driver = {
389 .driver = {
390 .name = "gpio-ep93xx",
391 .owner = THIS_MODULE,
392 },
393 .probe = ep93xx_gpio_probe,
394};
395
396static int __init ep93xx_gpio_init(void)
397{
398 return platform_driver_register(&ep93xx_gpio_driver);
399}
400postcore_initcall(ep93xx_gpio_init);
401
402MODULE_AUTHOR("Ryan Mallon <ryan@bluewatersys.com> "
403 "H Hartley Sweeten <hsweeten@visionengravers.com>");
404MODULE_DESCRIPTION("EP93XX GPIO driver");
405MODULE_LICENSE("GPL");
diff --git a/drivers/gpio/gpio-exynos4.c b/drivers/gpio/gpio-exynos4.c
index 9029835112e7..d24b337cf1ac 100644
--- a/drivers/gpio/gpio-exynos4.c
+++ b/drivers/gpio/gpio-exynos4.c
@@ -1,10 +1,9 @@
1/* linux/arch/arm/mach-exynos4/gpiolib.c 1/*
2 * EXYNOS4 - GPIOlib support
2 * 3 *
3 * Copyright (c) 2010-2011 Samsung Electronics Co., Ltd. 4 * Copyright (c) 2010-2011 Samsung Electronics Co., Ltd.
4 * http://www.samsung.com 5 * http://www.samsung.com
5 * 6 *
6 * EXYNOS4 - GPIOlib support
7 *
8 * This program is free software; you can redistribute it and/or modify 7 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as 8 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation. 9 * published by the Free Software Foundation.
diff --git a/drivers/gpio/basic_mmio_gpio.c b/drivers/gpio/gpio-generic.c
index 8152e9f516b0..231714def4d2 100644
--- a/drivers/gpio/basic_mmio_gpio.c
+++ b/drivers/gpio/gpio-generic.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * Driver for basic memory-mapped GPIO controllers. 2 * Generic driver for memory-mapped GPIO controllers.
3 * 3 *
4 * Copyright 2008 MontaVista Software, Inc. 4 * Copyright 2008 MontaVista Software, Inc.
5 * Copyright 2008,2010 Anton Vorontsov <cbouatmailru@gmail.com> 5 * Copyright 2008,2010 Anton Vorontsov <cbouatmailru@gmail.com>
@@ -404,7 +404,7 @@ int __devinit bgpio_init(struct bgpio_chip *bgc,
404} 404}
405EXPORT_SYMBOL_GPL(bgpio_init); 405EXPORT_SYMBOL_GPL(bgpio_init);
406 406
407#ifdef CONFIG_GPIO_BASIC_MMIO 407#ifdef CONFIG_GPIO_GENERIC_PLATFORM
408 408
409static void __iomem *bgpio_map(struct platform_device *pdev, 409static void __iomem *bgpio_map(struct platform_device *pdev,
410 const char *name, 410 const char *name,
@@ -541,7 +541,7 @@ static void __exit bgpio_platform_exit(void)
541} 541}
542module_exit(bgpio_platform_exit); 542module_exit(bgpio_platform_exit);
543 543
544#endif /* CONFIG_GPIO_BASIC_MMIO */ 544#endif /* CONFIG_GPIO_GENERIC_PLATFORM */
545 545
546MODULE_DESCRIPTION("Driver for basic memory-mapped GPIO controllers"); 546MODULE_DESCRIPTION("Driver for basic memory-mapped GPIO controllers");
547MODULE_AUTHOR("Anton Vorontsov <cbouatmailru@gmail.com>"); 547MODULE_AUTHOR("Anton Vorontsov <cbouatmailru@gmail.com>");
diff --git a/drivers/gpio/it8761e_gpio.c b/drivers/gpio/gpio-it8761e.c
index 48fc43c4bdd1..278b81317010 100644
--- a/drivers/gpio/it8761e_gpio.c
+++ b/drivers/gpio/gpio-it8761e.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * it8761_gpio.c - GPIO interface for IT8761E Super I/O chip 2 * GPIO interface for IT8761E Super I/O chip
3 * 3 *
4 * Author: Denis Turischev <denis@compulab.co.il> 4 * Author: Denis Turischev <denis@compulab.co.il>
5 * 5 *
diff --git a/drivers/gpio/janz-ttl.c b/drivers/gpio/gpio-janz-ttl.c
index 813ac077e5d7..813ac077e5d7 100644
--- a/drivers/gpio/janz-ttl.c
+++ b/drivers/gpio/gpio-janz-ttl.c
diff --git a/drivers/gpio/langwell_gpio.c b/drivers/gpio/gpio-langwell.c
index 644ba1255d3c..d2eb57c60e0e 100644
--- a/drivers/gpio/langwell_gpio.c
+++ b/drivers/gpio/gpio-langwell.c
@@ -1,4 +1,6 @@
1/* langwell_gpio.c Moorestown platform Langwell chip GPIO driver 1/*
2 * Moorestown platform Langwell chip GPIO driver
3 *
2 * Copyright (c) 2008 - 2009, Intel Corporation. 4 * Copyright (c) 2008 - 2009, Intel Corporation.
3 * 5 *
4 * This program is free software; you can redistribute it and/or modify 6 * This program is free software; you can redistribute it and/or modify
diff --git a/drivers/gpio/max7300.c b/drivers/gpio/gpio-max7300.c
index 962f661c18c7..a5ca0ab1b372 100644
--- a/drivers/gpio/max7300.c
+++ b/drivers/gpio/gpio-max7300.c
@@ -1,6 +1,4 @@
1/* 1/*
2 * drivers/gpio/max7300.c
3 *
4 * Copyright (C) 2009 Wolfram Sang, Pengutronix 2 * Copyright (C) 2009 Wolfram Sang, Pengutronix
5 * 3 *
6 * This program is free software; you can redistribute it and/or modify 4 * This program is free software; you can redistribute it and/or modify
diff --git a/drivers/gpio/max7301.c b/drivers/gpio/gpio-max7301.c
index 92a100ddef6b..741acfcbe761 100644
--- a/drivers/gpio/max7301.c
+++ b/drivers/gpio/gpio-max7301.c
@@ -1,6 +1,4 @@
1/* 1/*
2 * drivers/gpio/max7301.c
3 *
4 * Copyright (C) 2006 Juergen Beisert, Pengutronix 2 * Copyright (C) 2006 Juergen Beisert, Pengutronix
5 * Copyright (C) 2008 Guennadi Liakhovetski, Pengutronix 3 * Copyright (C) 2008 Guennadi Liakhovetski, Pengutronix
6 * Copyright (C) 2009 Wolfram Sang, Pengutronix 4 * Copyright (C) 2009 Wolfram Sang, Pengutronix
diff --git a/drivers/gpio/max730x.c b/drivers/gpio/gpio-max730x.c
index 94ce773f95f8..05e2dac60b3b 100644
--- a/drivers/gpio/max730x.c
+++ b/drivers/gpio/gpio-max730x.c
@@ -1,6 +1,4 @@
1/** 1/**
2 * drivers/gpio/max7301.c
3 *
4 * Copyright (C) 2006 Juergen Beisert, Pengutronix 2 * Copyright (C) 2006 Juergen Beisert, Pengutronix
5 * Copyright (C) 2008 Guennadi Liakhovetski, Pengutronix 3 * Copyright (C) 2008 Guennadi Liakhovetski, Pengutronix
6 * Copyright (C) 2009 Wolfram Sang, Pengutronix 4 * Copyright (C) 2009 Wolfram Sang, Pengutronix
diff --git a/drivers/gpio/max732x.c b/drivers/gpio/gpio-max732x.c
index ad6951edc16c..9504120812a5 100644
--- a/drivers/gpio/max732x.c
+++ b/drivers/gpio/gpio-max732x.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * max732x.c - I2C Port Expander with 8/16 I/O 2 * MAX732x I2C Port Expander with 8/16 I/O
3 * 3 *
4 * Copyright (C) 2007 Marvell International Ltd. 4 * Copyright (C) 2007 Marvell International Ltd.
5 * Copyright (C) 2008 Jack Ren <jack.ren@marvell.com> 5 * Copyright (C) 2008 Jack Ren <jack.ren@marvell.com>
diff --git a/drivers/gpio/mc33880.c b/drivers/gpio/gpio-mc33880.c
index 4ec797593bdb..b3b4652e89ec 100644
--- a/drivers/gpio/mc33880.c
+++ b/drivers/gpio/gpio-mc33880.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * mc33880.c MC33880 high-side/low-side switch GPIO driver 2 * MC33880 high-side/low-side switch GPIO driver
3 * Copyright (c) 2009 Intel Corporation 3 * Copyright (c) 2009 Intel Corporation
4 * 4 *
5 * This program is free software; you can redistribute it and/or modify 5 * This program is free software; you can redistribute it and/or modify
diff --git a/drivers/gpio/mcp23s08.c b/drivers/gpio/gpio-mcp23s08.c
index 40e076083ec0..1ef46e6c2a2a 100644
--- a/drivers/gpio/mcp23s08.c
+++ b/drivers/gpio/gpio-mcp23s08.c
@@ -1,12 +1,12 @@
1/* 1/*
2 * mcp23s08.c - SPI gpio expander driver 2 * MCP23S08 SPI/GPIO gpio expander driver
3 */ 3 */
4 4
5#include <linux/kernel.h> 5#include <linux/kernel.h>
6#include <linux/device.h> 6#include <linux/device.h>
7#include <linux/workqueue.h>
8#include <linux/mutex.h> 7#include <linux/mutex.h>
9#include <linux/gpio.h> 8#include <linux/gpio.h>
9#include <linux/i2c.h>
10#include <linux/spi/spi.h> 10#include <linux/spi/spi.h>
11#include <linux/spi/mcp23s08.h> 11#include <linux/spi/mcp23s08.h>
12#include <linux/slab.h> 12#include <linux/slab.h>
@@ -17,13 +17,13 @@
17 */ 17 */
18#define MCP_TYPE_S08 0 18#define MCP_TYPE_S08 0
19#define MCP_TYPE_S17 1 19#define MCP_TYPE_S17 1
20#define MCP_TYPE_008 2
21#define MCP_TYPE_017 3
20 22
21/* Registers are all 8 bits wide. 23/* Registers are all 8 bits wide.
22 * 24 *
23 * The mcp23s17 has twice as many bits, and can be configured to work 25 * The mcp23s17 has twice as many bits, and can be configured to work
24 * with either 16 bit registers or with two adjacent 8 bit banks. 26 * with either 16 bit registers or with two adjacent 8 bit banks.
25 *
26 * Also, there are I2C versions of both chips.
27 */ 27 */
28#define MCP_IODIR 0x00 /* init/reset: all ones */ 28#define MCP_IODIR 0x00 /* init/reset: all ones */
29#define MCP_IPOL 0x01 29#define MCP_IPOL 0x01
@@ -51,7 +51,6 @@ struct mcp23s08_ops {
51}; 51};
52 52
53struct mcp23s08 { 53struct mcp23s08 {
54 struct spi_device *spi;
55 u8 addr; 54 u8 addr;
56 55
57 u16 cache[11]; 56 u16 cache[11];
@@ -60,9 +59,8 @@ struct mcp23s08 {
60 59
61 struct gpio_chip chip; 60 struct gpio_chip chip;
62 61
63 struct work_struct work;
64
65 const struct mcp23s08_ops *ops; 62 const struct mcp23s08_ops *ops;
63 void *data; /* ops specific data */
66}; 64};
67 65
68/* A given spi_device can represent up to eight mcp23sxx chips 66/* A given spi_device can represent up to eight mcp23sxx chips
@@ -76,6 +74,74 @@ struct mcp23s08_driver_data {
76 struct mcp23s08 chip[]; 74 struct mcp23s08 chip[];
77}; 75};
78 76
77/*----------------------------------------------------------------------*/
78
79#ifdef CONFIG_I2C
80
81static int mcp23008_read(struct mcp23s08 *mcp, unsigned reg)
82{
83 return i2c_smbus_read_byte_data(mcp->data, reg);
84}
85
86static int mcp23008_write(struct mcp23s08 *mcp, unsigned reg, unsigned val)
87{
88 return i2c_smbus_write_byte_data(mcp->data, reg, val);
89}
90
91static int
92mcp23008_read_regs(struct mcp23s08 *mcp, unsigned reg, u16 *vals, unsigned n)
93{
94 while (n--) {
95 int ret = mcp23008_read(mcp, reg++);
96 if (ret < 0)
97 return ret;
98 *vals++ = ret;
99 }
100
101 return 0;
102}
103
104static int mcp23017_read(struct mcp23s08 *mcp, unsigned reg)
105{
106 return i2c_smbus_read_word_data(mcp->data, reg << 1);
107}
108
109static int mcp23017_write(struct mcp23s08 *mcp, unsigned reg, unsigned val)
110{
111 return i2c_smbus_write_word_data(mcp->data, reg << 1, val);
112}
113
114static int
115mcp23017_read_regs(struct mcp23s08 *mcp, unsigned reg, u16 *vals, unsigned n)
116{
117 while (n--) {
118 int ret = mcp23017_read(mcp, reg++);
119 if (ret < 0)
120 return ret;
121 *vals++ = ret;
122 }
123
124 return 0;
125}
126
127static const struct mcp23s08_ops mcp23008_ops = {
128 .read = mcp23008_read,
129 .write = mcp23008_write,
130 .read_regs = mcp23008_read_regs,
131};
132
133static const struct mcp23s08_ops mcp23017_ops = {
134 .read = mcp23017_read,
135 .write = mcp23017_write,
136 .read_regs = mcp23017_read_regs,
137};
138
139#endif /* CONFIG_I2C */
140
141/*----------------------------------------------------------------------*/
142
143#ifdef CONFIG_SPI_MASTER
144
79static int mcp23s08_read(struct mcp23s08 *mcp, unsigned reg) 145static int mcp23s08_read(struct mcp23s08 *mcp, unsigned reg)
80{ 146{
81 u8 tx[2], rx[1]; 147 u8 tx[2], rx[1];
@@ -83,7 +149,7 @@ static int mcp23s08_read(struct mcp23s08 *mcp, unsigned reg)
83 149
84 tx[0] = mcp->addr | 0x01; 150 tx[0] = mcp->addr | 0x01;
85 tx[1] = reg; 151 tx[1] = reg;
86 status = spi_write_then_read(mcp->spi, tx, sizeof tx, rx, sizeof rx); 152 status = spi_write_then_read(mcp->data, tx, sizeof tx, rx, sizeof rx);
87 return (status < 0) ? status : rx[0]; 153 return (status < 0) ? status : rx[0];
88} 154}
89 155
@@ -94,7 +160,7 @@ static int mcp23s08_write(struct mcp23s08 *mcp, unsigned reg, unsigned val)
94 tx[0] = mcp->addr; 160 tx[0] = mcp->addr;
95 tx[1] = reg; 161 tx[1] = reg;
96 tx[2] = val; 162 tx[2] = val;
97 return spi_write_then_read(mcp->spi, tx, sizeof tx, NULL, 0); 163 return spi_write_then_read(mcp->data, tx, sizeof tx, NULL, 0);
98} 164}
99 165
100static int 166static int
@@ -109,7 +175,7 @@ mcp23s08_read_regs(struct mcp23s08 *mcp, unsigned reg, u16 *vals, unsigned n)
109 tx[1] = reg; 175 tx[1] = reg;
110 176
111 tmp = (u8 *)vals; 177 tmp = (u8 *)vals;
112 status = spi_write_then_read(mcp->spi, tx, sizeof tx, tmp, n); 178 status = spi_write_then_read(mcp->data, tx, sizeof tx, tmp, n);
113 if (status >= 0) { 179 if (status >= 0) {
114 while (n--) 180 while (n--)
115 vals[n] = tmp[n]; /* expand to 16bit */ 181 vals[n] = tmp[n]; /* expand to 16bit */
@@ -124,7 +190,7 @@ static int mcp23s17_read(struct mcp23s08 *mcp, unsigned reg)
124 190
125 tx[0] = mcp->addr | 0x01; 191 tx[0] = mcp->addr | 0x01;
126 tx[1] = reg << 1; 192 tx[1] = reg << 1;
127 status = spi_write_then_read(mcp->spi, tx, sizeof tx, rx, sizeof rx); 193 status = spi_write_then_read(mcp->data, tx, sizeof tx, rx, sizeof rx);
128 return (status < 0) ? status : (rx[0] | (rx[1] << 8)); 194 return (status < 0) ? status : (rx[0] | (rx[1] << 8));
129} 195}
130 196
@@ -136,7 +202,7 @@ static int mcp23s17_write(struct mcp23s08 *mcp, unsigned reg, unsigned val)
136 tx[1] = reg << 1; 202 tx[1] = reg << 1;
137 tx[2] = val; 203 tx[2] = val;
138 tx[3] = val >> 8; 204 tx[3] = val >> 8;
139 return spi_write_then_read(mcp->spi, tx, sizeof tx, NULL, 0); 205 return spi_write_then_read(mcp->data, tx, sizeof tx, NULL, 0);
140} 206}
141 207
142static int 208static int
@@ -150,7 +216,7 @@ mcp23s17_read_regs(struct mcp23s08 *mcp, unsigned reg, u16 *vals, unsigned n)
150 tx[0] = mcp->addr | 0x01; 216 tx[0] = mcp->addr | 0x01;
151 tx[1] = reg << 1; 217 tx[1] = reg << 1;
152 218
153 status = spi_write_then_read(mcp->spi, tx, sizeof tx, 219 status = spi_write_then_read(mcp->data, tx, sizeof tx,
154 (u8 *)vals, n * 2); 220 (u8 *)vals, n * 2);
155 if (status >= 0) { 221 if (status >= 0) {
156 while (n--) 222 while (n--)
@@ -172,6 +238,7 @@ static const struct mcp23s08_ops mcp23s17_ops = {
172 .read_regs = mcp23s17_read_regs, 238 .read_regs = mcp23s17_read_regs,
173}; 239};
174 240
241#endif /* CONFIG_SPI_MASTER */
175 242
176/*----------------------------------------------------------------------*/ 243/*----------------------------------------------------------------------*/
177 244
@@ -299,17 +366,16 @@ done:
299 366
300/*----------------------------------------------------------------------*/ 367/*----------------------------------------------------------------------*/
301 368
302static int mcp23s08_probe_one(struct spi_device *spi, unsigned addr, 369static int mcp23s08_probe_one(struct mcp23s08 *mcp, struct device *dev,
370 void *data, unsigned addr,
303 unsigned type, unsigned base, unsigned pullups) 371 unsigned type, unsigned base, unsigned pullups)
304{ 372{
305 struct mcp23s08_driver_data *data = spi_get_drvdata(spi); 373 int status;
306 struct mcp23s08 *mcp = data->mcp[addr];
307 int status;
308 374
309 mutex_init(&mcp->lock); 375 mutex_init(&mcp->lock);
310 376
311 mcp->spi = spi; 377 mcp->data = data;
312 mcp->addr = 0x40 | (addr << 1); 378 mcp->addr = addr;
313 379
314 mcp->chip.direction_input = mcp23s08_direction_input; 380 mcp->chip.direction_input = mcp23s08_direction_input;
315 mcp->chip.get = mcp23s08_get; 381 mcp->chip.get = mcp23s08_get;
@@ -317,18 +383,43 @@ static int mcp23s08_probe_one(struct spi_device *spi, unsigned addr,
317 mcp->chip.set = mcp23s08_set; 383 mcp->chip.set = mcp23s08_set;
318 mcp->chip.dbg_show = mcp23s08_dbg_show; 384 mcp->chip.dbg_show = mcp23s08_dbg_show;
319 385
320 if (type == MCP_TYPE_S17) { 386 switch (type) {
387#ifdef CONFIG_SPI_MASTER
388 case MCP_TYPE_S08:
389 mcp->ops = &mcp23s08_ops;
390 mcp->chip.ngpio = 8;
391 mcp->chip.label = "mcp23s08";
392 break;
393
394 case MCP_TYPE_S17:
321 mcp->ops = &mcp23s17_ops; 395 mcp->ops = &mcp23s17_ops;
322 mcp->chip.ngpio = 16; 396 mcp->chip.ngpio = 16;
323 mcp->chip.label = "mcp23s17"; 397 mcp->chip.label = "mcp23s17";
324 } else { 398 break;
325 mcp->ops = &mcp23s08_ops; 399#endif /* CONFIG_SPI_MASTER */
400
401#ifdef CONFIG_I2C
402 case MCP_TYPE_008:
403 mcp->ops = &mcp23008_ops;
326 mcp->chip.ngpio = 8; 404 mcp->chip.ngpio = 8;
327 mcp->chip.label = "mcp23s08"; 405 mcp->chip.label = "mcp23008";
406 break;
407
408 case MCP_TYPE_017:
409 mcp->ops = &mcp23017_ops;
410 mcp->chip.ngpio = 16;
411 mcp->chip.label = "mcp23017";
412 break;
413#endif /* CONFIG_I2C */
414
415 default:
416 dev_err(dev, "invalid device type (%d)\n", type);
417 return -EINVAL;
328 } 418 }
419
329 mcp->chip.base = base; 420 mcp->chip.base = base;
330 mcp->chip.can_sleep = 1; 421 mcp->chip.can_sleep = 1;
331 mcp->chip.dev = &spi->dev; 422 mcp->chip.dev = dev;
332 mcp->chip.owner = THIS_MODULE; 423 mcp->chip.owner = THIS_MODULE;
333 424
334 /* verify MCP_IOCON.SEQOP = 0, so sequential reads work, 425 /* verify MCP_IOCON.SEQOP = 0, so sequential reads work,
@@ -374,11 +465,98 @@ static int mcp23s08_probe_one(struct spi_device *spi, unsigned addr,
374 status = gpiochip_add(&mcp->chip); 465 status = gpiochip_add(&mcp->chip);
375fail: 466fail:
376 if (status < 0) 467 if (status < 0)
377 dev_dbg(&spi->dev, "can't setup chip %d, --> %d\n", 468 dev_dbg(dev, "can't setup chip %d, --> %d\n",
378 addr, status); 469 addr, status);
379 return status; 470 return status;
380} 471}
381 472
473/*----------------------------------------------------------------------*/
474
475#ifdef CONFIG_I2C
476
477static int __devinit mcp230xx_probe(struct i2c_client *client,
478 const struct i2c_device_id *id)
479{
480 struct mcp23s08_platform_data *pdata;
481 struct mcp23s08 *mcp;
482 int status;
483
484 pdata = client->dev.platform_data;
485 if (!pdata || !gpio_is_valid(pdata->base)) {
486 dev_dbg(&client->dev, "invalid or missing platform data\n");
487 return -EINVAL;
488 }
489
490 mcp = kzalloc(sizeof *mcp, GFP_KERNEL);
491 if (!mcp)
492 return -ENOMEM;
493
494 status = mcp23s08_probe_one(mcp, &client->dev, client, client->addr,
495 id->driver_data, pdata->base,
496 pdata->chip[0].pullups);
497 if (status)
498 goto fail;
499
500 i2c_set_clientdata(client, mcp);
501
502 return 0;
503
504fail:
505 kfree(mcp);
506
507 return status;
508}
509
510static int __devexit mcp230xx_remove(struct i2c_client *client)
511{
512 struct mcp23s08 *mcp = i2c_get_clientdata(client);
513 int status;
514
515 status = gpiochip_remove(&mcp->chip);
516 if (status == 0)
517 kfree(mcp);
518
519 return status;
520}
521
522static const struct i2c_device_id mcp230xx_id[] = {
523 { "mcp23008", MCP_TYPE_008 },
524 { "mcp23017", MCP_TYPE_017 },
525 { },
526};
527MODULE_DEVICE_TABLE(i2c, mcp230xx_id);
528
529static struct i2c_driver mcp230xx_driver = {
530 .driver = {
531 .name = "mcp230xx",
532 .owner = THIS_MODULE,
533 },
534 .probe = mcp230xx_probe,
535 .remove = __devexit_p(mcp230xx_remove),
536 .id_table = mcp230xx_id,
537};
538
539static int __init mcp23s08_i2c_init(void)
540{
541 return i2c_add_driver(&mcp230xx_driver);
542}
543
544static void mcp23s08_i2c_exit(void)
545{
546 i2c_del_driver(&mcp230xx_driver);
547}
548
549#else
550
551static int __init mcp23s08_i2c_init(void) { return 0; }
552static void mcp23s08_i2c_exit(void) { }
553
554#endif /* CONFIG_I2C */
555
556/*----------------------------------------------------------------------*/
557
558#ifdef CONFIG_SPI_MASTER
559
382static int mcp23s08_probe(struct spi_device *spi) 560static int mcp23s08_probe(struct spi_device *spi)
383{ 561{
384 struct mcp23s08_platform_data *pdata; 562 struct mcp23s08_platform_data *pdata;
@@ -421,7 +599,8 @@ static int mcp23s08_probe(struct spi_device *spi)
421 continue; 599 continue;
422 chips--; 600 chips--;
423 data->mcp[addr] = &data->chip[chips]; 601 data->mcp[addr] = &data->chip[chips];
424 status = mcp23s08_probe_one(spi, addr, type, base, 602 status = mcp23s08_probe_one(data->mcp[addr], &spi->dev, spi,
603 0x40 | (addr << 1), type, base,
425 pdata->chip[addr].pullups); 604 pdata->chip[addr].pullups);
426 if (status < 0) 605 if (status < 0)
427 goto fail; 606 goto fail;
@@ -435,14 +614,6 @@ static int mcp23s08_probe(struct spi_device *spi)
435 * handled here... 614 * handled here...
436 */ 615 */
437 616
438 if (pdata->setup) {
439 status = pdata->setup(spi,
440 pdata->base, data->ngpio,
441 pdata->context);
442 if (status < 0)
443 dev_dbg(&spi->dev, "setup --> %d\n", status);
444 }
445
446 return 0; 617 return 0;
447 618
448fail: 619fail:
@@ -462,20 +633,9 @@ fail:
462static int mcp23s08_remove(struct spi_device *spi) 633static int mcp23s08_remove(struct spi_device *spi)
463{ 634{
464 struct mcp23s08_driver_data *data = spi_get_drvdata(spi); 635 struct mcp23s08_driver_data *data = spi_get_drvdata(spi);
465 struct mcp23s08_platform_data *pdata = spi->dev.platform_data;
466 unsigned addr; 636 unsigned addr;
467 int status = 0; 637 int status = 0;
468 638
469 if (pdata->teardown) {
470 status = pdata->teardown(spi,
471 pdata->base, data->ngpio,
472 pdata->context);
473 if (status < 0) {
474 dev_err(&spi->dev, "%s --> %d\n", "teardown", status);
475 return status;
476 }
477 }
478
479 for (addr = 0; addr < ARRAY_SIZE(data->mcp); addr++) { 639 for (addr = 0; addr < ARRAY_SIZE(data->mcp); addr++) {
480 int tmp; 640 int tmp;
481 641
@@ -510,20 +670,53 @@ static struct spi_driver mcp23s08_driver = {
510 }, 670 },
511}; 671};
512 672
673static int __init mcp23s08_spi_init(void)
674{
675 return spi_register_driver(&mcp23s08_driver);
676}
677
678static void mcp23s08_spi_exit(void)
679{
680 spi_unregister_driver(&mcp23s08_driver);
681}
682
683#else
684
685static int __init mcp23s08_spi_init(void) { return 0; }
686static void mcp23s08_spi_exit(void) { }
687
688#endif /* CONFIG_SPI_MASTER */
689
513/*----------------------------------------------------------------------*/ 690/*----------------------------------------------------------------------*/
514 691
515static int __init mcp23s08_init(void) 692static int __init mcp23s08_init(void)
516{ 693{
517 return spi_register_driver(&mcp23s08_driver); 694 int ret;
695
696 ret = mcp23s08_spi_init();
697 if (ret)
698 goto spi_fail;
699
700 ret = mcp23s08_i2c_init();
701 if (ret)
702 goto i2c_fail;
703
704 return 0;
705
706 i2c_fail:
707 mcp23s08_spi_exit();
708 spi_fail:
709 return ret;
518} 710}
519/* register after spi postcore initcall and before 711/* register after spi/i2c postcore initcall and before
520 * subsys initcalls that may rely on these GPIOs 712 * subsys initcalls that may rely on these GPIOs
521 */ 713 */
522subsys_initcall(mcp23s08_init); 714subsys_initcall(mcp23s08_init);
523 715
524static void __exit mcp23s08_exit(void) 716static void __exit mcp23s08_exit(void)
525{ 717{
526 spi_unregister_driver(&mcp23s08_driver); 718 mcp23s08_spi_exit();
719 mcp23s08_i2c_exit();
527} 720}
528module_exit(mcp23s08_exit); 721module_exit(mcp23s08_exit);
529 722
diff --git a/drivers/gpio/ml_ioh_gpio.c b/drivers/gpio/gpio-ml-ioh.c
index 1bc621ac3536..a9016f56ed7e 100644
--- a/drivers/gpio/ml_ioh_gpio.c
+++ b/drivers/gpio/gpio-ml-ioh.c
@@ -233,7 +233,7 @@ static int __devinit ioh_gpio_probe(struct pci_dev *pdev,
233 return 0; 233 return 0;
234 234
235err_gpiochip_add: 235err_gpiochip_add:
236 for (; i != 0; i--) { 236 while (--i >= 0) {
237 chip--; 237 chip--;
238 ret = gpiochip_remove(&chip->gpio); 238 ret = gpiochip_remove(&chip->gpio);
239 if (ret) 239 if (ret)
diff --git a/drivers/gpio/gpio-mpc5200.c b/drivers/gpio/gpio-mpc5200.c
new file mode 100644
index 000000000000..52d3ed208105
--- /dev/null
+++ b/drivers/gpio/gpio-mpc5200.c
@@ -0,0 +1,376 @@
1/*
2 * MPC52xx gpio driver
3 *
4 * Copyright (c) 2008 Sascha Hauer <s.hauer@pengutronix.de>, Pengutronix
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2
8 * as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */
19
20#include <linux/of.h>
21#include <linux/kernel.h>
22#include <linux/slab.h>
23#include <linux/of_gpio.h>
24#include <linux/io.h>
25#include <linux/of_platform.h>
26
27#include <asm/gpio.h>
28#include <asm/mpc52xx.h>
29#include <sysdev/fsl_soc.h>
30
31static DEFINE_SPINLOCK(gpio_lock);
32
33struct mpc52xx_gpiochip {
34 struct of_mm_gpio_chip mmchip;
35 unsigned int shadow_dvo;
36 unsigned int shadow_gpioe;
37 unsigned int shadow_ddr;
38};
39
40/*
41 * GPIO LIB API implementation for wakeup GPIOs.
42 *
43 * There's a maximum of 8 wakeup GPIOs. Which of these are available
44 * for use depends on your board setup.
45 *
46 * 0 -> GPIO_WKUP_7
47 * 1 -> GPIO_WKUP_6
48 * 2 -> PSC6_1
49 * 3 -> PSC6_0
50 * 4 -> ETH_17
51 * 5 -> PSC3_9
52 * 6 -> PSC2_4
53 * 7 -> PSC1_4
54 *
55 */
56static int mpc52xx_wkup_gpio_get(struct gpio_chip *gc, unsigned int gpio)
57{
58 struct of_mm_gpio_chip *mm_gc = to_of_mm_gpio_chip(gc);
59 struct mpc52xx_gpio_wkup __iomem *regs = mm_gc->regs;
60 unsigned int ret;
61
62 ret = (in_8(&regs->wkup_ival) >> (7 - gpio)) & 1;
63
64 pr_debug("%s: gpio: %d ret: %d\n", __func__, gpio, ret);
65
66 return ret;
67}
68
69static inline void
70__mpc52xx_wkup_gpio_set(struct gpio_chip *gc, unsigned int gpio, int val)
71{
72 struct of_mm_gpio_chip *mm_gc = to_of_mm_gpio_chip(gc);
73 struct mpc52xx_gpiochip *chip = container_of(mm_gc,
74 struct mpc52xx_gpiochip, mmchip);
75 struct mpc52xx_gpio_wkup __iomem *regs = mm_gc->regs;
76
77 if (val)
78 chip->shadow_dvo |= 1 << (7 - gpio);
79 else
80 chip->shadow_dvo &= ~(1 << (7 - gpio));
81
82 out_8(&regs->wkup_dvo, chip->shadow_dvo);
83}
84
85static void
86mpc52xx_wkup_gpio_set(struct gpio_chip *gc, unsigned int gpio, int val)
87{
88 unsigned long flags;
89
90 spin_lock_irqsave(&gpio_lock, flags);
91
92 __mpc52xx_wkup_gpio_set(gc, gpio, val);
93
94 spin_unlock_irqrestore(&gpio_lock, flags);
95
96 pr_debug("%s: gpio: %d val: %d\n", __func__, gpio, val);
97}
98
99static int mpc52xx_wkup_gpio_dir_in(struct gpio_chip *gc, unsigned int gpio)
100{
101 struct of_mm_gpio_chip *mm_gc = to_of_mm_gpio_chip(gc);
102 struct mpc52xx_gpiochip *chip = container_of(mm_gc,
103 struct mpc52xx_gpiochip, mmchip);
104 struct mpc52xx_gpio_wkup __iomem *regs = mm_gc->regs;
105 unsigned long flags;
106
107 spin_lock_irqsave(&gpio_lock, flags);
108
109 /* set the direction */
110 chip->shadow_ddr &= ~(1 << (7 - gpio));
111 out_8(&regs->wkup_ddr, chip->shadow_ddr);
112
113 /* and enable the pin */
114 chip->shadow_gpioe |= 1 << (7 - gpio);
115 out_8(&regs->wkup_gpioe, chip->shadow_gpioe);
116
117 spin_unlock_irqrestore(&gpio_lock, flags);
118
119 return 0;
120}
121
122static int
123mpc52xx_wkup_gpio_dir_out(struct gpio_chip *gc, unsigned int gpio, int val)
124{
125 struct of_mm_gpio_chip *mm_gc = to_of_mm_gpio_chip(gc);
126 struct mpc52xx_gpio_wkup __iomem *regs = mm_gc->regs;
127 struct mpc52xx_gpiochip *chip = container_of(mm_gc,
128 struct mpc52xx_gpiochip, mmchip);
129 unsigned long flags;
130
131 spin_lock_irqsave(&gpio_lock, flags);
132
133 __mpc52xx_wkup_gpio_set(gc, gpio, val);
134
135 /* Then set direction */
136 chip->shadow_ddr |= 1 << (7 - gpio);
137 out_8(&regs->wkup_ddr, chip->shadow_ddr);
138
139 /* Finally enable the pin */
140 chip->shadow_gpioe |= 1 << (7 - gpio);
141 out_8(&regs->wkup_gpioe, chip->shadow_gpioe);
142
143 spin_unlock_irqrestore(&gpio_lock, flags);
144
145 pr_debug("%s: gpio: %d val: %d\n", __func__, gpio, val);
146
147 return 0;
148}
149
150static int __devinit mpc52xx_wkup_gpiochip_probe(struct platform_device *ofdev)
151{
152 struct mpc52xx_gpiochip *chip;
153 struct mpc52xx_gpio_wkup __iomem *regs;
154 struct gpio_chip *gc;
155 int ret;
156
157 chip = kzalloc(sizeof(*chip), GFP_KERNEL);
158 if (!chip)
159 return -ENOMEM;
160
161 gc = &chip->mmchip.gc;
162
163 gc->ngpio = 8;
164 gc->direction_input = mpc52xx_wkup_gpio_dir_in;
165 gc->direction_output = mpc52xx_wkup_gpio_dir_out;
166 gc->get = mpc52xx_wkup_gpio_get;
167 gc->set = mpc52xx_wkup_gpio_set;
168
169 ret = of_mm_gpiochip_add(ofdev->dev.of_node, &chip->mmchip);
170 if (ret)
171 return ret;
172
173 regs = chip->mmchip.regs;
174 chip->shadow_gpioe = in_8(&regs->wkup_gpioe);
175 chip->shadow_ddr = in_8(&regs->wkup_ddr);
176 chip->shadow_dvo = in_8(&regs->wkup_dvo);
177
178 return 0;
179}
180
181static int mpc52xx_gpiochip_remove(struct platform_device *ofdev)
182{
183 return -EBUSY;
184}
185
186static const struct of_device_id mpc52xx_wkup_gpiochip_match[] = {
187 { .compatible = "fsl,mpc5200-gpio-wkup", },
188 {}
189};
190
191static struct platform_driver mpc52xx_wkup_gpiochip_driver = {
192 .driver = {
193 .name = "mpc5200-gpio-wkup",
194 .owner = THIS_MODULE,
195 .of_match_table = mpc52xx_wkup_gpiochip_match,
196 },
197 .probe = mpc52xx_wkup_gpiochip_probe,
198 .remove = mpc52xx_gpiochip_remove,
199};
200
201/*
202 * GPIO LIB API implementation for simple GPIOs
203 *
204 * There's a maximum of 32 simple GPIOs. Which of these are available
205 * for use depends on your board setup.
206 * The numbering reflects the bit numbering in the port registers:
207 *
208 * 0..1 > reserved
209 * 2..3 > IRDA
210 * 4..7 > ETHR
211 * 8..11 > reserved
212 * 12..15 > USB
213 * 16..17 > reserved
214 * 18..23 > PSC3
215 * 24..27 > PSC2
216 * 28..31 > PSC1
217 */
218static int mpc52xx_simple_gpio_get(struct gpio_chip *gc, unsigned int gpio)
219{
220 struct of_mm_gpio_chip *mm_gc = to_of_mm_gpio_chip(gc);
221 struct mpc52xx_gpio __iomem *regs = mm_gc->regs;
222 unsigned int ret;
223
224 ret = (in_be32(&regs->simple_ival) >> (31 - gpio)) & 1;
225
226 return ret;
227}
228
229static inline void
230__mpc52xx_simple_gpio_set(struct gpio_chip *gc, unsigned int gpio, int val)
231{
232 struct of_mm_gpio_chip *mm_gc = to_of_mm_gpio_chip(gc);
233 struct mpc52xx_gpiochip *chip = container_of(mm_gc,
234 struct mpc52xx_gpiochip, mmchip);
235 struct mpc52xx_gpio __iomem *regs = mm_gc->regs;
236
237 if (val)
238 chip->shadow_dvo |= 1 << (31 - gpio);
239 else
240 chip->shadow_dvo &= ~(1 << (31 - gpio));
241 out_be32(&regs->simple_dvo, chip->shadow_dvo);
242}
243
244static void
245mpc52xx_simple_gpio_set(struct gpio_chip *gc, unsigned int gpio, int val)
246{
247 unsigned long flags;
248
249 spin_lock_irqsave(&gpio_lock, flags);
250
251 __mpc52xx_simple_gpio_set(gc, gpio, val);
252
253 spin_unlock_irqrestore(&gpio_lock, flags);
254
255 pr_debug("%s: gpio: %d val: %d\n", __func__, gpio, val);
256}
257
258static int mpc52xx_simple_gpio_dir_in(struct gpio_chip *gc, unsigned int gpio)
259{
260 struct of_mm_gpio_chip *mm_gc = to_of_mm_gpio_chip(gc);
261 struct mpc52xx_gpiochip *chip = container_of(mm_gc,
262 struct mpc52xx_gpiochip, mmchip);
263 struct mpc52xx_gpio __iomem *regs = mm_gc->regs;
264 unsigned long flags;
265
266 spin_lock_irqsave(&gpio_lock, flags);
267
268 /* set the direction */
269 chip->shadow_ddr &= ~(1 << (31 - gpio));
270 out_be32(&regs->simple_ddr, chip->shadow_ddr);
271
272 /* and enable the pin */
273 chip->shadow_gpioe |= 1 << (31 - gpio);
274 out_be32(&regs->simple_gpioe, chip->shadow_gpioe);
275
276 spin_unlock_irqrestore(&gpio_lock, flags);
277
278 return 0;
279}
280
281static int
282mpc52xx_simple_gpio_dir_out(struct gpio_chip *gc, unsigned int gpio, int val)
283{
284 struct of_mm_gpio_chip *mm_gc = to_of_mm_gpio_chip(gc);
285 struct mpc52xx_gpiochip *chip = container_of(mm_gc,
286 struct mpc52xx_gpiochip, mmchip);
287 struct mpc52xx_gpio __iomem *regs = mm_gc->regs;
288 unsigned long flags;
289
290 spin_lock_irqsave(&gpio_lock, flags);
291
292 /* First set initial value */
293 __mpc52xx_simple_gpio_set(gc, gpio, val);
294
295 /* Then set direction */
296 chip->shadow_ddr |= 1 << (31 - gpio);
297 out_be32(&regs->simple_ddr, chip->shadow_ddr);
298
299 /* Finally enable the pin */
300 chip->shadow_gpioe |= 1 << (31 - gpio);
301 out_be32(&regs->simple_gpioe, chip->shadow_gpioe);
302
303 spin_unlock_irqrestore(&gpio_lock, flags);
304
305 pr_debug("%s: gpio: %d val: %d\n", __func__, gpio, val);
306
307 return 0;
308}
309
310static int __devinit mpc52xx_simple_gpiochip_probe(struct platform_device *ofdev)
311{
312 struct mpc52xx_gpiochip *chip;
313 struct gpio_chip *gc;
314 struct mpc52xx_gpio __iomem *regs;
315 int ret;
316
317 chip = kzalloc(sizeof(*chip), GFP_KERNEL);
318 if (!chip)
319 return -ENOMEM;
320
321 gc = &chip->mmchip.gc;
322
323 gc->ngpio = 32;
324 gc->direction_input = mpc52xx_simple_gpio_dir_in;
325 gc->direction_output = mpc52xx_simple_gpio_dir_out;
326 gc->get = mpc52xx_simple_gpio_get;
327 gc->set = mpc52xx_simple_gpio_set;
328
329 ret = of_mm_gpiochip_add(ofdev->dev.of_node, &chip->mmchip);
330 if (ret)
331 return ret;
332
333 regs = chip->mmchip.regs;
334 chip->shadow_gpioe = in_be32(&regs->simple_gpioe);
335 chip->shadow_ddr = in_be32(&regs->simple_ddr);
336 chip->shadow_dvo = in_be32(&regs->simple_dvo);
337
338 return 0;
339}
340
341static const struct of_device_id mpc52xx_simple_gpiochip_match[] = {
342 { .compatible = "fsl,mpc5200-gpio", },
343 {}
344};
345
346static struct platform_driver mpc52xx_simple_gpiochip_driver = {
347 .driver = {
348 .name = "mpc5200-gpio",
349 .owner = THIS_MODULE,
350 .of_match_table = mpc52xx_simple_gpiochip_match,
351 },
352 .probe = mpc52xx_simple_gpiochip_probe,
353 .remove = mpc52xx_gpiochip_remove,
354};
355
356static int __init mpc52xx_gpio_init(void)
357{
358 if (platform_driver_register(&mpc52xx_wkup_gpiochip_driver))
359 printk(KERN_ERR "Unable to register wakeup GPIO driver\n");
360
361 if (platform_driver_register(&mpc52xx_simple_gpiochip_driver))
362 printk(KERN_ERR "Unable to register simple GPIO driver\n");
363
364 return 0;
365}
366
367
368/* Make sure we get initialised before anyone else tries to use us */
369subsys_initcall(mpc52xx_gpio_init);
370
371/* No exit call at the moment as we cannot unregister of gpio chips */
372
373MODULE_DESCRIPTION("Freescale MPC52xx gpio driver");
374MODULE_AUTHOR("Sascha Hauer <s.hauer@pengutronix.de");
375MODULE_LICENSE("GPL v2");
376
diff --git a/drivers/gpio/gpio-mxc.c b/drivers/gpio/gpio-mxc.c
new file mode 100644
index 000000000000..4340acae3bd3
--- /dev/null
+++ b/drivers/gpio/gpio-mxc.c
@@ -0,0 +1,460 @@
1/*
2 * MXC GPIO support. (c) 2008 Daniel Mack <daniel@caiaq.de>
3 * Copyright 2008 Juergen Beisert, kernel@pengutronix.de
4 *
5 * Based on code from Freescale,
6 * Copyright (C) 2004-2010 Freescale Semiconductor, Inc. All Rights Reserved.
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 */
21
22#include <linux/init.h>
23#include <linux/interrupt.h>
24#include <linux/io.h>
25#include <linux/irq.h>
26#include <linux/gpio.h>
27#include <linux/platform_device.h>
28#include <linux/slab.h>
29#include <linux/basic_mmio_gpio.h>
30#include <linux/of.h>
31#include <linux/of_device.h>
32#include <asm-generic/bug.h>
33
34enum mxc_gpio_hwtype {
35 IMX1_GPIO, /* runs on i.mx1 */
36 IMX21_GPIO, /* runs on i.mx21 and i.mx27 */
37 IMX31_GPIO, /* runs on all other i.mx */
38};
39
40/* device type dependent stuff */
41struct mxc_gpio_hwdata {
42 unsigned dr_reg;
43 unsigned gdir_reg;
44 unsigned psr_reg;
45 unsigned icr1_reg;
46 unsigned icr2_reg;
47 unsigned imr_reg;
48 unsigned isr_reg;
49 unsigned low_level;
50 unsigned high_level;
51 unsigned rise_edge;
52 unsigned fall_edge;
53};
54
55struct mxc_gpio_port {
56 struct list_head node;
57 void __iomem *base;
58 int irq;
59 int irq_high;
60 int virtual_irq_start;
61 struct bgpio_chip bgc;
62 u32 both_edges;
63};
64
65static struct mxc_gpio_hwdata imx1_imx21_gpio_hwdata = {
66 .dr_reg = 0x1c,
67 .gdir_reg = 0x00,
68 .psr_reg = 0x24,
69 .icr1_reg = 0x28,
70 .icr2_reg = 0x2c,
71 .imr_reg = 0x30,
72 .isr_reg = 0x34,
73 .low_level = 0x03,
74 .high_level = 0x02,
75 .rise_edge = 0x00,
76 .fall_edge = 0x01,
77};
78
79static struct mxc_gpio_hwdata imx31_gpio_hwdata = {
80 .dr_reg = 0x00,
81 .gdir_reg = 0x04,
82 .psr_reg = 0x08,
83 .icr1_reg = 0x0c,
84 .icr2_reg = 0x10,
85 .imr_reg = 0x14,
86 .isr_reg = 0x18,
87 .low_level = 0x00,
88 .high_level = 0x01,
89 .rise_edge = 0x02,
90 .fall_edge = 0x03,
91};
92
93static enum mxc_gpio_hwtype mxc_gpio_hwtype;
94static struct mxc_gpio_hwdata *mxc_gpio_hwdata;
95
96#define GPIO_DR (mxc_gpio_hwdata->dr_reg)
97#define GPIO_GDIR (mxc_gpio_hwdata->gdir_reg)
98#define GPIO_PSR (mxc_gpio_hwdata->psr_reg)
99#define GPIO_ICR1 (mxc_gpio_hwdata->icr1_reg)
100#define GPIO_ICR2 (mxc_gpio_hwdata->icr2_reg)
101#define GPIO_IMR (mxc_gpio_hwdata->imr_reg)
102#define GPIO_ISR (mxc_gpio_hwdata->isr_reg)
103
104#define GPIO_INT_LOW_LEV (mxc_gpio_hwdata->low_level)
105#define GPIO_INT_HIGH_LEV (mxc_gpio_hwdata->high_level)
106#define GPIO_INT_RISE_EDGE (mxc_gpio_hwdata->rise_edge)
107#define GPIO_INT_FALL_EDGE (mxc_gpio_hwdata->fall_edge)
108#define GPIO_INT_NONE 0x4
109
110static struct platform_device_id mxc_gpio_devtype[] = {
111 {
112 .name = "imx1-gpio",
113 .driver_data = IMX1_GPIO,
114 }, {
115 .name = "imx21-gpio",
116 .driver_data = IMX21_GPIO,
117 }, {
118 .name = "imx31-gpio",
119 .driver_data = IMX31_GPIO,
120 }, {
121 /* sentinel */
122 }
123};
124
125static const struct of_device_id mxc_gpio_dt_ids[] = {
126 { .compatible = "fsl,imx1-gpio", .data = &mxc_gpio_devtype[IMX1_GPIO], },
127 { .compatible = "fsl,imx21-gpio", .data = &mxc_gpio_devtype[IMX21_GPIO], },
128 { .compatible = "fsl,imx31-gpio", .data = &mxc_gpio_devtype[IMX31_GPIO], },
129 { /* sentinel */ }
130};
131
132/*
133 * MX2 has one interrupt *for all* gpio ports. The list is used
134 * to save the references to all ports, so that mx2_gpio_irq_handler
135 * can walk through all interrupt status registers.
136 */
137static LIST_HEAD(mxc_gpio_ports);
138
139/* Note: This driver assumes 32 GPIOs are handled in one register */
140
141static int gpio_set_irq_type(struct irq_data *d, u32 type)
142{
143 u32 gpio = irq_to_gpio(d->irq);
144 struct irq_chip_generic *gc = irq_data_get_irq_chip_data(d);
145 struct mxc_gpio_port *port = gc->private;
146 u32 bit, val;
147 int edge;
148 void __iomem *reg = port->base;
149
150 port->both_edges &= ~(1 << (gpio & 31));
151 switch (type) {
152 case IRQ_TYPE_EDGE_RISING:
153 edge = GPIO_INT_RISE_EDGE;
154 break;
155 case IRQ_TYPE_EDGE_FALLING:
156 edge = GPIO_INT_FALL_EDGE;
157 break;
158 case IRQ_TYPE_EDGE_BOTH:
159 val = gpio_get_value(gpio);
160 if (val) {
161 edge = GPIO_INT_LOW_LEV;
162 pr_debug("mxc: set GPIO %d to low trigger\n", gpio);
163 } else {
164 edge = GPIO_INT_HIGH_LEV;
165 pr_debug("mxc: set GPIO %d to high trigger\n", gpio);
166 }
167 port->both_edges |= 1 << (gpio & 31);
168 break;
169 case IRQ_TYPE_LEVEL_LOW:
170 edge = GPIO_INT_LOW_LEV;
171 break;
172 case IRQ_TYPE_LEVEL_HIGH:
173 edge = GPIO_INT_HIGH_LEV;
174 break;
175 default:
176 return -EINVAL;
177 }
178
179 reg += GPIO_ICR1 + ((gpio & 0x10) >> 2); /* lower or upper register */
180 bit = gpio & 0xf;
181 val = readl(reg) & ~(0x3 << (bit << 1));
182 writel(val | (edge << (bit << 1)), reg);
183 writel(1 << (gpio & 0x1f), port->base + GPIO_ISR);
184
185 return 0;
186}
187
188static void mxc_flip_edge(struct mxc_gpio_port *port, u32 gpio)
189{
190 void __iomem *reg = port->base;
191 u32 bit, val;
192 int edge;
193
194 reg += GPIO_ICR1 + ((gpio & 0x10) >> 2); /* lower or upper register */
195 bit = gpio & 0xf;
196 val = readl(reg);
197 edge = (val >> (bit << 1)) & 3;
198 val &= ~(0x3 << (bit << 1));
199 if (edge == GPIO_INT_HIGH_LEV) {
200 edge = GPIO_INT_LOW_LEV;
201 pr_debug("mxc: switch GPIO %d to low trigger\n", gpio);
202 } else if (edge == GPIO_INT_LOW_LEV) {
203 edge = GPIO_INT_HIGH_LEV;
204 pr_debug("mxc: switch GPIO %d to high trigger\n", gpio);
205 } else {
206 pr_err("mxc: invalid configuration for GPIO %d: %x\n",
207 gpio, edge);
208 return;
209 }
210 writel(val | (edge << (bit << 1)), reg);
211}
212
213/* handle 32 interrupts in one status register */
214static void mxc_gpio_irq_handler(struct mxc_gpio_port *port, u32 irq_stat)
215{
216 u32 gpio_irq_no_base = port->virtual_irq_start;
217
218 while (irq_stat != 0) {
219 int irqoffset = fls(irq_stat) - 1;
220
221 if (port->both_edges & (1 << irqoffset))
222 mxc_flip_edge(port, irqoffset);
223
224 generic_handle_irq(gpio_irq_no_base + irqoffset);
225
226 irq_stat &= ~(1 << irqoffset);
227 }
228}
229
230/* MX1 and MX3 has one interrupt *per* gpio port */
231static void mx3_gpio_irq_handler(u32 irq, struct irq_desc *desc)
232{
233 u32 irq_stat;
234 struct mxc_gpio_port *port = irq_get_handler_data(irq);
235
236 irq_stat = readl(port->base + GPIO_ISR) & readl(port->base + GPIO_IMR);
237
238 mxc_gpio_irq_handler(port, irq_stat);
239}
240
241/* MX2 has one interrupt *for all* gpio ports */
242static void mx2_gpio_irq_handler(u32 irq, struct irq_desc *desc)
243{
244 u32 irq_msk, irq_stat;
245 struct mxc_gpio_port *port;
246
247 /* walk through all interrupt status registers */
248 list_for_each_entry(port, &mxc_gpio_ports, node) {
249 irq_msk = readl(port->base + GPIO_IMR);
250 if (!irq_msk)
251 continue;
252
253 irq_stat = readl(port->base + GPIO_ISR) & irq_msk;
254 if (irq_stat)
255 mxc_gpio_irq_handler(port, irq_stat);
256 }
257}
258
259/*
260 * Set interrupt number "irq" in the GPIO as a wake-up source.
261 * While system is running, all registered GPIO interrupts need to have
262 * wake-up enabled. When system is suspended, only selected GPIO interrupts
263 * need to have wake-up enabled.
264 * @param irq interrupt source number
265 * @param enable enable as wake-up if equal to non-zero
266 * @return This function returns 0 on success.
267 */
268static int gpio_set_wake_irq(struct irq_data *d, u32 enable)
269{
270 u32 gpio = irq_to_gpio(d->irq);
271 u32 gpio_idx = gpio & 0x1F;
272 struct irq_chip_generic *gc = irq_data_get_irq_chip_data(d);
273 struct mxc_gpio_port *port = gc->private;
274
275 if (enable) {
276 if (port->irq_high && (gpio_idx >= 16))
277 enable_irq_wake(port->irq_high);
278 else
279 enable_irq_wake(port->irq);
280 } else {
281 if (port->irq_high && (gpio_idx >= 16))
282 disable_irq_wake(port->irq_high);
283 else
284 disable_irq_wake(port->irq);
285 }
286
287 return 0;
288}
289
290static void __init mxc_gpio_init_gc(struct mxc_gpio_port *port)
291{
292 struct irq_chip_generic *gc;
293 struct irq_chip_type *ct;
294
295 gc = irq_alloc_generic_chip("gpio-mxc", 1, port->virtual_irq_start,
296 port->base, handle_level_irq);
297 gc->private = port;
298
299 ct = gc->chip_types;
300 ct->chip.irq_ack = irq_gc_ack_set_bit;
301 ct->chip.irq_mask = irq_gc_mask_clr_bit;
302 ct->chip.irq_unmask = irq_gc_mask_set_bit;
303 ct->chip.irq_set_type = gpio_set_irq_type;
304 ct->chip.irq_set_wake = gpio_set_wake_irq;
305 ct->regs.ack = GPIO_ISR;
306 ct->regs.mask = GPIO_IMR;
307
308 irq_setup_generic_chip(gc, IRQ_MSK(32), IRQ_GC_INIT_NESTED_LOCK,
309 IRQ_NOREQUEST, 0);
310}
311
312static void __devinit mxc_gpio_get_hw(struct platform_device *pdev)
313{
314 const struct of_device_id *of_id =
315 of_match_device(mxc_gpio_dt_ids, &pdev->dev);
316 enum mxc_gpio_hwtype hwtype;
317
318 if (of_id)
319 pdev->id_entry = of_id->data;
320 hwtype = pdev->id_entry->driver_data;
321
322 if (mxc_gpio_hwtype) {
323 /*
324 * The driver works with a reasonable presupposition,
325 * that is all gpio ports must be the same type when
326 * running on one soc.
327 */
328 BUG_ON(mxc_gpio_hwtype != hwtype);
329 return;
330 }
331
332 if (hwtype == IMX31_GPIO)
333 mxc_gpio_hwdata = &imx31_gpio_hwdata;
334 else
335 mxc_gpio_hwdata = &imx1_imx21_gpio_hwdata;
336
337 mxc_gpio_hwtype = hwtype;
338}
339
340static int __devinit mxc_gpio_probe(struct platform_device *pdev)
341{
342 struct device_node *np = pdev->dev.of_node;
343 struct mxc_gpio_port *port;
344 struct resource *iores;
345 int err;
346
347 mxc_gpio_get_hw(pdev);
348
349 port = kzalloc(sizeof(struct mxc_gpio_port), GFP_KERNEL);
350 if (!port)
351 return -ENOMEM;
352
353 iores = platform_get_resource(pdev, IORESOURCE_MEM, 0);
354 if (!iores) {
355 err = -ENODEV;
356 goto out_kfree;
357 }
358
359 if (!request_mem_region(iores->start, resource_size(iores),
360 pdev->name)) {
361 err = -EBUSY;
362 goto out_kfree;
363 }
364
365 port->base = ioremap(iores->start, resource_size(iores));
366 if (!port->base) {
367 err = -ENOMEM;
368 goto out_release_mem;
369 }
370
371 port->irq_high = platform_get_irq(pdev, 1);
372 port->irq = platform_get_irq(pdev, 0);
373 if (port->irq < 0) {
374 err = -EINVAL;
375 goto out_iounmap;
376 }
377
378 /* disable the interrupt and clear the status */
379 writel(0, port->base + GPIO_IMR);
380 writel(~0, port->base + GPIO_ISR);
381
382 if (mxc_gpio_hwtype == IMX21_GPIO) {
383 /* setup one handler for all GPIO interrupts */
384 if (pdev->id == 0)
385 irq_set_chained_handler(port->irq,
386 mx2_gpio_irq_handler);
387 } else {
388 /* setup one handler for each entry */
389 irq_set_chained_handler(port->irq, mx3_gpio_irq_handler);
390 irq_set_handler_data(port->irq, port);
391 if (port->irq_high > 0) {
392 /* setup handler for GPIO 16 to 31 */
393 irq_set_chained_handler(port->irq_high,
394 mx3_gpio_irq_handler);
395 irq_set_handler_data(port->irq_high, port);
396 }
397 }
398
399 err = bgpio_init(&port->bgc, &pdev->dev, 4,
400 port->base + GPIO_PSR,
401 port->base + GPIO_DR, NULL,
402 port->base + GPIO_GDIR, NULL, false);
403 if (err)
404 goto out_iounmap;
405
406 port->bgc.gc.base = pdev->id * 32;
407 port->bgc.dir = port->bgc.read_reg(port->bgc.reg_dir);
408 port->bgc.data = port->bgc.read_reg(port->bgc.reg_set);
409
410 err = gpiochip_add(&port->bgc.gc);
411 if (err)
412 goto out_bgpio_remove;
413
414 /*
415 * In dt case, we use gpio number range dynamically
416 * allocated by gpio core.
417 */
418 port->virtual_irq_start = MXC_GPIO_IRQ_START + (np ? port->bgc.gc.base :
419 pdev->id * 32);
420
421 /* gpio-mxc can be a generic irq chip */
422 mxc_gpio_init_gc(port);
423
424 list_add_tail(&port->node, &mxc_gpio_ports);
425
426 return 0;
427
428out_bgpio_remove:
429 bgpio_remove(&port->bgc);
430out_iounmap:
431 iounmap(port->base);
432out_release_mem:
433 release_mem_region(iores->start, resource_size(iores));
434out_kfree:
435 kfree(port);
436 dev_info(&pdev->dev, "%s failed with errno %d\n", __func__, err);
437 return err;
438}
439
440static struct platform_driver mxc_gpio_driver = {
441 .driver = {
442 .name = "gpio-mxc",
443 .owner = THIS_MODULE,
444 .of_match_table = mxc_gpio_dt_ids,
445 },
446 .probe = mxc_gpio_probe,
447 .id_table = mxc_gpio_devtype,
448};
449
450static int __init gpio_mxc_init(void)
451{
452 return platform_driver_register(&mxc_gpio_driver);
453}
454postcore_initcall(gpio_mxc_init);
455
456MODULE_AUTHOR("Freescale Semiconductor, "
457 "Daniel Mack <danielncaiaq.de>, "
458 "Juergen Beisert <kernel@pengutronix.de>");
459MODULE_DESCRIPTION("Freescale MXC GPIO");
460MODULE_LICENSE("GPL");
diff --git a/drivers/gpio/gpio-mxs.c b/drivers/gpio/gpio-mxs.c
new file mode 100644
index 000000000000..af55a8577c2e
--- /dev/null
+++ b/drivers/gpio/gpio-mxs.c
@@ -0,0 +1,289 @@
1/*
2 * MXC GPIO support. (c) 2008 Daniel Mack <daniel@caiaq.de>
3 * Copyright 2008 Juergen Beisert, kernel@pengutronix.de
4 *
5 * Based on code from Freescale,
6 * Copyright (C) 2004-2010 Freescale Semiconductor, Inc. All Rights Reserved.
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
20 * MA 02110-1301, USA.
21 */
22
23#include <linux/init.h>
24#include <linux/interrupt.h>
25#include <linux/io.h>
26#include <linux/irq.h>
27#include <linux/gpio.h>
28#include <linux/platform_device.h>
29#include <linux/slab.h>
30#include <linux/basic_mmio_gpio.h>
31#include <mach/mxs.h>
32
33#define MXS_SET 0x4
34#define MXS_CLR 0x8
35
36#define PINCTRL_DOUT(n) ((cpu_is_mx23() ? 0x0500 : 0x0700) + (n) * 0x10)
37#define PINCTRL_DIN(n) ((cpu_is_mx23() ? 0x0600 : 0x0900) + (n) * 0x10)
38#define PINCTRL_DOE(n) ((cpu_is_mx23() ? 0x0700 : 0x0b00) + (n) * 0x10)
39#define PINCTRL_PIN2IRQ(n) ((cpu_is_mx23() ? 0x0800 : 0x1000) + (n) * 0x10)
40#define PINCTRL_IRQEN(n) ((cpu_is_mx23() ? 0x0900 : 0x1100) + (n) * 0x10)
41#define PINCTRL_IRQLEV(n) ((cpu_is_mx23() ? 0x0a00 : 0x1200) + (n) * 0x10)
42#define PINCTRL_IRQPOL(n) ((cpu_is_mx23() ? 0x0b00 : 0x1300) + (n) * 0x10)
43#define PINCTRL_IRQSTAT(n) ((cpu_is_mx23() ? 0x0c00 : 0x1400) + (n) * 0x10)
44
45#define GPIO_INT_FALL_EDGE 0x0
46#define GPIO_INT_LOW_LEV 0x1
47#define GPIO_INT_RISE_EDGE 0x2
48#define GPIO_INT_HIGH_LEV 0x3
49#define GPIO_INT_LEV_MASK (1 << 0)
50#define GPIO_INT_POL_MASK (1 << 1)
51
52struct mxs_gpio_port {
53 void __iomem *base;
54 int id;
55 int irq;
56 int virtual_irq_start;
57 struct bgpio_chip bgc;
58};
59
60/* Note: This driver assumes 32 GPIOs are handled in one register */
61
62static int mxs_gpio_set_irq_type(struct irq_data *d, unsigned int type)
63{
64 u32 gpio = irq_to_gpio(d->irq);
65 u32 pin_mask = 1 << (gpio & 31);
66 struct irq_chip_generic *gc = irq_data_get_irq_chip_data(d);
67 struct mxs_gpio_port *port = gc->private;
68 void __iomem *pin_addr;
69 int edge;
70
71 switch (type) {
72 case IRQ_TYPE_EDGE_RISING:
73 edge = GPIO_INT_RISE_EDGE;
74 break;
75 case IRQ_TYPE_EDGE_FALLING:
76 edge = GPIO_INT_FALL_EDGE;
77 break;
78 case IRQ_TYPE_LEVEL_LOW:
79 edge = GPIO_INT_LOW_LEV;
80 break;
81 case IRQ_TYPE_LEVEL_HIGH:
82 edge = GPIO_INT_HIGH_LEV;
83 break;
84 default:
85 return -EINVAL;
86 }
87
88 /* set level or edge */
89 pin_addr = port->base + PINCTRL_IRQLEV(port->id);
90 if (edge & GPIO_INT_LEV_MASK)
91 writel(pin_mask, pin_addr + MXS_SET);
92 else
93 writel(pin_mask, pin_addr + MXS_CLR);
94
95 /* set polarity */
96 pin_addr = port->base + PINCTRL_IRQPOL(port->id);
97 if (edge & GPIO_INT_POL_MASK)
98 writel(pin_mask, pin_addr + MXS_SET);
99 else
100 writel(pin_mask, pin_addr + MXS_CLR);
101
102 writel(1 << (gpio & 0x1f),
103 port->base + PINCTRL_IRQSTAT(port->id) + MXS_CLR);
104
105 return 0;
106}
107
108/* MXS has one interrupt *per* gpio port */
109static void mxs_gpio_irq_handler(u32 irq, struct irq_desc *desc)
110{
111 u32 irq_stat;
112 struct mxs_gpio_port *port = irq_get_handler_data(irq);
113 u32 gpio_irq_no_base = port->virtual_irq_start;
114
115 desc->irq_data.chip->irq_ack(&desc->irq_data);
116
117 irq_stat = readl(port->base + PINCTRL_IRQSTAT(port->id)) &
118 readl(port->base + PINCTRL_IRQEN(port->id));
119
120 while (irq_stat != 0) {
121 int irqoffset = fls(irq_stat) - 1;
122 generic_handle_irq(gpio_irq_no_base + irqoffset);
123 irq_stat &= ~(1 << irqoffset);
124 }
125}
126
127/*
128 * Set interrupt number "irq" in the GPIO as a wake-up source.
129 * While system is running, all registered GPIO interrupts need to have
130 * wake-up enabled. When system is suspended, only selected GPIO interrupts
131 * need to have wake-up enabled.
132 * @param irq interrupt source number
133 * @param enable enable as wake-up if equal to non-zero
134 * @return This function returns 0 on success.
135 */
136static int mxs_gpio_set_wake_irq(struct irq_data *d, unsigned int enable)
137{
138 struct irq_chip_generic *gc = irq_data_get_irq_chip_data(d);
139 struct mxs_gpio_port *port = gc->private;
140
141 if (enable)
142 enable_irq_wake(port->irq);
143 else
144 disable_irq_wake(port->irq);
145
146 return 0;
147}
148
149static void __init mxs_gpio_init_gc(struct mxs_gpio_port *port)
150{
151 struct irq_chip_generic *gc;
152 struct irq_chip_type *ct;
153
154 gc = irq_alloc_generic_chip("gpio-mxs", 1, port->virtual_irq_start,
155 port->base, handle_level_irq);
156 gc->private = port;
157
158 ct = gc->chip_types;
159 ct->chip.irq_ack = irq_gc_ack_set_bit;
160 ct->chip.irq_mask = irq_gc_mask_clr_bit;
161 ct->chip.irq_unmask = irq_gc_mask_set_bit;
162 ct->chip.irq_set_type = mxs_gpio_set_irq_type;
163 ct->chip.irq_set_wake = mxs_gpio_set_wake_irq;
164 ct->regs.ack = PINCTRL_IRQSTAT(port->id) + MXS_CLR;
165 ct->regs.mask = PINCTRL_IRQEN(port->id);
166
167 irq_setup_generic_chip(gc, IRQ_MSK(32), 0, IRQ_NOREQUEST, 0);
168}
169
170static int mxs_gpio_to_irq(struct gpio_chip *gc, unsigned offset)
171{
172 struct bgpio_chip *bgc = to_bgpio_chip(gc);
173 struct mxs_gpio_port *port =
174 container_of(bgc, struct mxs_gpio_port, bgc);
175
176 return port->virtual_irq_start + offset;
177}
178
179static int __devinit mxs_gpio_probe(struct platform_device *pdev)
180{
181 static void __iomem *base;
182 struct mxs_gpio_port *port;
183 struct resource *iores = NULL;
184 int err;
185
186 port = kzalloc(sizeof(struct mxs_gpio_port), GFP_KERNEL);
187 if (!port)
188 return -ENOMEM;
189
190 port->id = pdev->id;
191 port->virtual_irq_start = MXS_GPIO_IRQ_START + port->id * 32;
192
193 /*
194 * map memory region only once, as all the gpio ports
195 * share the same one
196 */
197 if (!base) {
198 iores = platform_get_resource(pdev, IORESOURCE_MEM, 0);
199 if (!iores) {
200 err = -ENODEV;
201 goto out_kfree;
202 }
203
204 if (!request_mem_region(iores->start, resource_size(iores),
205 pdev->name)) {
206 err = -EBUSY;
207 goto out_kfree;
208 }
209
210 base = ioremap(iores->start, resource_size(iores));
211 if (!base) {
212 err = -ENOMEM;
213 goto out_release_mem;
214 }
215 }
216 port->base = base;
217
218 port->irq = platform_get_irq(pdev, 0);
219 if (port->irq < 0) {
220 err = -EINVAL;
221 goto out_iounmap;
222 }
223
224 /*
225 * select the pin interrupt functionality but initially
226 * disable the interrupts
227 */
228 writel(~0U, port->base + PINCTRL_PIN2IRQ(port->id));
229 writel(0, port->base + PINCTRL_IRQEN(port->id));
230
231 /* clear address has to be used to clear IRQSTAT bits */
232 writel(~0U, port->base + PINCTRL_IRQSTAT(port->id) + MXS_CLR);
233
234 /* gpio-mxs can be a generic irq chip */
235 mxs_gpio_init_gc(port);
236
237 /* setup one handler for each entry */
238 irq_set_chained_handler(port->irq, mxs_gpio_irq_handler);
239 irq_set_handler_data(port->irq, port);
240
241 err = bgpio_init(&port->bgc, &pdev->dev, 4,
242 port->base + PINCTRL_DIN(port->id),
243 port->base + PINCTRL_DOUT(port->id), NULL,
244 port->base + PINCTRL_DOE(port->id), NULL, false);
245 if (err)
246 goto out_iounmap;
247
248 port->bgc.gc.to_irq = mxs_gpio_to_irq;
249 port->bgc.gc.base = port->id * 32;
250
251 err = gpiochip_add(&port->bgc.gc);
252 if (err)
253 goto out_bgpio_remove;
254
255 return 0;
256
257out_bgpio_remove:
258 bgpio_remove(&port->bgc);
259out_iounmap:
260 if (iores)
261 iounmap(port->base);
262out_release_mem:
263 if (iores)
264 release_mem_region(iores->start, resource_size(iores));
265out_kfree:
266 kfree(port);
267 dev_info(&pdev->dev, "%s failed with errno %d\n", __func__, err);
268 return err;
269}
270
271static struct platform_driver mxs_gpio_driver = {
272 .driver = {
273 .name = "gpio-mxs",
274 .owner = THIS_MODULE,
275 },
276 .probe = mxs_gpio_probe,
277};
278
279static int __init mxs_gpio_init(void)
280{
281 return platform_driver_register(&mxs_gpio_driver);
282}
283postcore_initcall(mxs_gpio_init);
284
285MODULE_AUTHOR("Freescale Semiconductor, "
286 "Daniel Mack <danielncaiaq.de>, "
287 "Juergen Beisert <kernel@pengutronix.de>");
288MODULE_DESCRIPTION("Freescale MXS GPIO");
289MODULE_LICENSE("GPL");
diff --git a/drivers/gpio/gpio-omap.c b/drivers/gpio/gpio-omap.c
index 35bebde23e83..0599854e2217 100644
--- a/drivers/gpio/gpio-omap.c
+++ b/drivers/gpio/gpio-omap.c
@@ -54,6 +54,11 @@ struct gpio_bank {
54 struct device *dev; 54 struct device *dev;
55 bool dbck_flag; 55 bool dbck_flag;
56 int stride; 56 int stride;
57 u32 width;
58
59 void (*set_dataout)(struct gpio_bank *bank, int gpio, int enable);
60
61 struct omap_gpio_reg_offs *regs;
57}; 62};
58 63
59#ifdef CONFIG_ARCH_OMAP3 64#ifdef CONFIG_ARCH_OMAP3
@@ -79,121 +84,18 @@ static struct omap3_gpio_regs gpio_context[OMAP34XX_NR_GPIOS];
79 */ 84 */
80static struct gpio_bank *gpio_bank; 85static struct gpio_bank *gpio_bank;
81 86
82static int bank_width;
83
84/* TODO: Analyze removing gpio_bank_count usage from driver code */ 87/* TODO: Analyze removing gpio_bank_count usage from driver code */
85int gpio_bank_count; 88int gpio_bank_count;
86 89
87static inline struct gpio_bank *get_gpio_bank(int gpio) 90#define GPIO_INDEX(bank, gpio) (gpio % bank->width)
88{ 91#define GPIO_BIT(bank, gpio) (1 << GPIO_INDEX(bank, gpio))
89 if (cpu_is_omap15xx()) {
90 if (OMAP_GPIO_IS_MPUIO(gpio))
91 return &gpio_bank[0];
92 return &gpio_bank[1];
93 }
94 if (cpu_is_omap16xx()) {
95 if (OMAP_GPIO_IS_MPUIO(gpio))
96 return &gpio_bank[0];
97 return &gpio_bank[1 + (gpio >> 4)];
98 }
99 if (cpu_is_omap7xx()) {
100 if (OMAP_GPIO_IS_MPUIO(gpio))
101 return &gpio_bank[0];
102 return &gpio_bank[1 + (gpio >> 5)];
103 }
104 if (cpu_is_omap24xx())
105 return &gpio_bank[gpio >> 5];
106 if (cpu_is_omap34xx() || cpu_is_omap44xx())
107 return &gpio_bank[gpio >> 5];
108 BUG();
109 return NULL;
110}
111
112static inline int get_gpio_index(int gpio)
113{
114 if (cpu_is_omap7xx())
115 return gpio & 0x1f;
116 if (cpu_is_omap24xx())
117 return gpio & 0x1f;
118 if (cpu_is_omap34xx() || cpu_is_omap44xx())
119 return gpio & 0x1f;
120 return gpio & 0x0f;
121}
122
123static inline int gpio_valid(int gpio)
124{
125 if (gpio < 0)
126 return -1;
127 if (cpu_class_is_omap1() && OMAP_GPIO_IS_MPUIO(gpio)) {
128 if (gpio >= OMAP_MAX_GPIO_LINES + 16)
129 return -1;
130 return 0;
131 }
132 if (cpu_is_omap15xx() && gpio < 16)
133 return 0;
134 if ((cpu_is_omap16xx()) && gpio < 64)
135 return 0;
136 if (cpu_is_omap7xx() && gpio < 192)
137 return 0;
138 if (cpu_is_omap2420() && gpio < 128)
139 return 0;
140 if (cpu_is_omap2430() && gpio < 160)
141 return 0;
142 if ((cpu_is_omap34xx() || cpu_is_omap44xx()) && gpio < 192)
143 return 0;
144 return -1;
145}
146
147static int check_gpio(int gpio)
148{
149 if (unlikely(gpio_valid(gpio) < 0)) {
150 printk(KERN_ERR "omap-gpio: invalid GPIO %d\n", gpio);
151 dump_stack();
152 return -1;
153 }
154 return 0;
155}
156 92
157static void _set_gpio_direction(struct gpio_bank *bank, int gpio, int is_input) 93static void _set_gpio_direction(struct gpio_bank *bank, int gpio, int is_input)
158{ 94{
159 void __iomem *reg = bank->base; 95 void __iomem *reg = bank->base;
160 u32 l; 96 u32 l;
161 97
162 switch (bank->method) { 98 reg += bank->regs->direction;
163#ifdef CONFIG_ARCH_OMAP1
164 case METHOD_MPUIO:
165 reg += OMAP_MPUIO_IO_CNTL / bank->stride;
166 break;
167#endif
168#ifdef CONFIG_ARCH_OMAP15XX
169 case METHOD_GPIO_1510:
170 reg += OMAP1510_GPIO_DIR_CONTROL;
171 break;
172#endif
173#ifdef CONFIG_ARCH_OMAP16XX
174 case METHOD_GPIO_1610:
175 reg += OMAP1610_GPIO_DIRECTION;
176 break;
177#endif
178#if defined(CONFIG_ARCH_OMAP730) || defined(CONFIG_ARCH_OMAP850)
179 case METHOD_GPIO_7XX:
180 reg += OMAP7XX_GPIO_DIR_CONTROL;
181 break;
182#endif
183#if defined(CONFIG_ARCH_OMAP2) || defined(CONFIG_ARCH_OMAP3)
184 case METHOD_GPIO_24XX:
185 reg += OMAP24XX_GPIO_OE;
186 break;
187#endif
188#if defined(CONFIG_ARCH_OMAP4)
189 case METHOD_GPIO_44XX:
190 reg += OMAP4_GPIO_OE;
191 break;
192#endif
193 default:
194 WARN_ON(1);
195 return;
196 }
197 l = __raw_readl(reg); 99 l = __raw_readl(reg);
198 if (is_input) 100 if (is_input)
199 l |= 1 << gpio; 101 l |= 1 << gpio;
@@ -202,165 +104,48 @@ static void _set_gpio_direction(struct gpio_bank *bank, int gpio, int is_input)
202 __raw_writel(l, reg); 104 __raw_writel(l, reg);
203} 105}
204 106
205static void _set_gpio_dataout(struct gpio_bank *bank, int gpio, int enable) 107
108/* set data out value using dedicate set/clear register */
109static void _set_gpio_dataout_reg(struct gpio_bank *bank, int gpio, int enable)
206{ 110{
207 void __iomem *reg = bank->base; 111 void __iomem *reg = bank->base;
208 u32 l = 0; 112 u32 l = GPIO_BIT(bank, gpio);
113
114 if (enable)
115 reg += bank->regs->set_dataout;
116 else
117 reg += bank->regs->clr_dataout;
209 118
210 switch (bank->method) {
211#ifdef CONFIG_ARCH_OMAP1
212 case METHOD_MPUIO:
213 reg += OMAP_MPUIO_OUTPUT / bank->stride;
214 l = __raw_readl(reg);
215 if (enable)
216 l |= 1 << gpio;
217 else
218 l &= ~(1 << gpio);
219 break;
220#endif
221#ifdef CONFIG_ARCH_OMAP15XX
222 case METHOD_GPIO_1510:
223 reg += OMAP1510_GPIO_DATA_OUTPUT;
224 l = __raw_readl(reg);
225 if (enable)
226 l |= 1 << gpio;
227 else
228 l &= ~(1 << gpio);
229 break;
230#endif
231#ifdef CONFIG_ARCH_OMAP16XX
232 case METHOD_GPIO_1610:
233 if (enable)
234 reg += OMAP1610_GPIO_SET_DATAOUT;
235 else
236 reg += OMAP1610_GPIO_CLEAR_DATAOUT;
237 l = 1 << gpio;
238 break;
239#endif
240#if defined(CONFIG_ARCH_OMAP730) || defined(CONFIG_ARCH_OMAP850)
241 case METHOD_GPIO_7XX:
242 reg += OMAP7XX_GPIO_DATA_OUTPUT;
243 l = __raw_readl(reg);
244 if (enable)
245 l |= 1 << gpio;
246 else
247 l &= ~(1 << gpio);
248 break;
249#endif
250#if defined(CONFIG_ARCH_OMAP2) || defined(CONFIG_ARCH_OMAP3)
251 case METHOD_GPIO_24XX:
252 if (enable)
253 reg += OMAP24XX_GPIO_SETDATAOUT;
254 else
255 reg += OMAP24XX_GPIO_CLEARDATAOUT;
256 l = 1 << gpio;
257 break;
258#endif
259#ifdef CONFIG_ARCH_OMAP4
260 case METHOD_GPIO_44XX:
261 if (enable)
262 reg += OMAP4_GPIO_SETDATAOUT;
263 else
264 reg += OMAP4_GPIO_CLEARDATAOUT;
265 l = 1 << gpio;
266 break;
267#endif
268 default:
269 WARN_ON(1);
270 return;
271 }
272 __raw_writel(l, reg); 119 __raw_writel(l, reg);
273} 120}
274 121
275static int _get_gpio_datain(struct gpio_bank *bank, int gpio) 122/* set data out value using mask register */
123static void _set_gpio_dataout_mask(struct gpio_bank *bank, int gpio, int enable)
276{ 124{
277 void __iomem *reg; 125 void __iomem *reg = bank->base + bank->regs->dataout;
126 u32 gpio_bit = GPIO_BIT(bank, gpio);
127 u32 l;
278 128
279 if (check_gpio(gpio) < 0) 129 l = __raw_readl(reg);
280 return -EINVAL; 130 if (enable)
281 reg = bank->base; 131 l |= gpio_bit;
282 switch (bank->method) { 132 else
283#ifdef CONFIG_ARCH_OMAP1 133 l &= ~gpio_bit;
284 case METHOD_MPUIO: 134 __raw_writel(l, reg);
285 reg += OMAP_MPUIO_INPUT_LATCH / bank->stride;
286 break;
287#endif
288#ifdef CONFIG_ARCH_OMAP15XX
289 case METHOD_GPIO_1510:
290 reg += OMAP1510_GPIO_DATA_INPUT;
291 break;
292#endif
293#ifdef CONFIG_ARCH_OMAP16XX
294 case METHOD_GPIO_1610:
295 reg += OMAP1610_GPIO_DATAIN;
296 break;
297#endif
298#if defined(CONFIG_ARCH_OMAP730) || defined(CONFIG_ARCH_OMAP850)
299 case METHOD_GPIO_7XX:
300 reg += OMAP7XX_GPIO_DATA_INPUT;
301 break;
302#endif
303#if defined(CONFIG_ARCH_OMAP2) || defined(CONFIG_ARCH_OMAP3)
304 case METHOD_GPIO_24XX:
305 reg += OMAP24XX_GPIO_DATAIN;
306 break;
307#endif
308#ifdef CONFIG_ARCH_OMAP4
309 case METHOD_GPIO_44XX:
310 reg += OMAP4_GPIO_DATAIN;
311 break;
312#endif
313 default:
314 return -EINVAL;
315 }
316 return (__raw_readl(reg)
317 & (1 << get_gpio_index(gpio))) != 0;
318} 135}
319 136
320static int _get_gpio_dataout(struct gpio_bank *bank, int gpio) 137static int _get_gpio_datain(struct gpio_bank *bank, int gpio)
321{ 138{
322 void __iomem *reg; 139 void __iomem *reg = bank->base + bank->regs->datain;
323 140
324 if (check_gpio(gpio) < 0) 141 return (__raw_readl(reg) & GPIO_BIT(bank, gpio)) != 0;
325 return -EINVAL; 142}
326 reg = bank->base;
327 143
328 switch (bank->method) { 144static int _get_gpio_dataout(struct gpio_bank *bank, int gpio)
329#ifdef CONFIG_ARCH_OMAP1 145{
330 case METHOD_MPUIO: 146 void __iomem *reg = bank->base + bank->regs->dataout;
331 reg += OMAP_MPUIO_OUTPUT / bank->stride;
332 break;
333#endif
334#ifdef CONFIG_ARCH_OMAP15XX
335 case METHOD_GPIO_1510:
336 reg += OMAP1510_GPIO_DATA_OUTPUT;
337 break;
338#endif
339#ifdef CONFIG_ARCH_OMAP16XX
340 case METHOD_GPIO_1610:
341 reg += OMAP1610_GPIO_DATAOUT;
342 break;
343#endif
344#if defined(CONFIG_ARCH_OMAP730) || defined(CONFIG_ARCH_OMAP850)
345 case METHOD_GPIO_7XX:
346 reg += OMAP7XX_GPIO_DATA_OUTPUT;
347 break;
348#endif
349#if defined(CONFIG_ARCH_OMAP2) || defined(CONFIG_ARCH_OMAP3)
350 case METHOD_GPIO_24XX:
351 reg += OMAP24XX_GPIO_DATAOUT;
352 break;
353#endif
354#ifdef CONFIG_ARCH_OMAP4
355 case METHOD_GPIO_44XX:
356 reg += OMAP4_GPIO_DATAOUT;
357 break;
358#endif
359 default:
360 return -EINVAL;
361 }
362 147
363 return (__raw_readl(reg) & (1 << get_gpio_index(gpio))) != 0; 148 return (__raw_readl(reg) & GPIO_BIT(bank, gpio)) != 0;
364} 149}
365 150
366#define MOD_REG_BIT(reg, bit_mask, set) \ 151#define MOD_REG_BIT(reg, bit_mask, set) \
@@ -383,7 +168,7 @@ do { \
383static void _set_gpio_debounce(struct gpio_bank *bank, unsigned gpio, 168static void _set_gpio_debounce(struct gpio_bank *bank, unsigned gpio,
384 unsigned debounce) 169 unsigned debounce)
385{ 170{
386 void __iomem *reg = bank->base; 171 void __iomem *reg;
387 u32 val; 172 u32 val;
388 u32 l; 173 u32 l;
389 174
@@ -397,21 +182,12 @@ static void _set_gpio_debounce(struct gpio_bank *bank, unsigned gpio,
397 else 182 else
398 debounce = (debounce / 0x1f) - 1; 183 debounce = (debounce / 0x1f) - 1;
399 184
400 l = 1 << get_gpio_index(gpio); 185 l = GPIO_BIT(bank, gpio);
401
402 if (bank->method == METHOD_GPIO_44XX)
403 reg += OMAP4_GPIO_DEBOUNCINGTIME;
404 else
405 reg += OMAP24XX_GPIO_DEBOUNCE_VAL;
406 186
187 reg = bank->base + bank->regs->debounce;
407 __raw_writel(debounce, reg); 188 __raw_writel(debounce, reg);
408 189
409 reg = bank->base; 190 reg = bank->base + bank->regs->debounce_en;
410 if (bank->method == METHOD_GPIO_44XX)
411 reg += OMAP4_GPIO_DEBOUNCENABLE;
412 else
413 reg += OMAP24XX_GPIO_DEBOUNCE_EN;
414
415 val = __raw_readl(reg); 191 val = __raw_readl(reg);
416 192
417 if (debounce) { 193 if (debounce) {
@@ -629,9 +405,6 @@ static int gpio_irq_type(struct irq_data *d, unsigned type)
629 else 405 else
630 gpio = d->irq - IH_GPIO_BASE; 406 gpio = d->irq - IH_GPIO_BASE;
631 407
632 if (check_gpio(gpio) < 0)
633 return -EINVAL;
634
635 if (type & ~IRQ_TYPE_SENSE_MASK) 408 if (type & ~IRQ_TYPE_SENSE_MASK)
636 return -EINVAL; 409 return -EINVAL;
637 410
@@ -642,7 +415,7 @@ static int gpio_irq_type(struct irq_data *d, unsigned type)
642 415
643 bank = irq_data_get_irq_chip_data(d); 416 bank = irq_data_get_irq_chip_data(d);
644 spin_lock_irqsave(&bank->lock, flags); 417 spin_lock_irqsave(&bank->lock, flags);
645 retval = _set_gpio_triggering(bank, get_gpio_index(gpio), type); 418 retval = _set_gpio_triggering(bank, GPIO_INDEX(bank, gpio), type);
646 spin_unlock_irqrestore(&bank->lock, flags); 419 spin_unlock_irqrestore(&bank->lock, flags);
647 420
648 if (type & (IRQ_TYPE_LEVEL_LOW | IRQ_TYPE_LEVEL_HIGH)) 421 if (type & (IRQ_TYPE_LEVEL_LOW | IRQ_TYPE_LEVEL_HIGH))
@@ -657,195 +430,81 @@ static void _clear_gpio_irqbank(struct gpio_bank *bank, int gpio_mask)
657{ 430{
658 void __iomem *reg = bank->base; 431 void __iomem *reg = bank->base;
659 432
660 switch (bank->method) { 433 reg += bank->regs->irqstatus;
661#ifdef CONFIG_ARCH_OMAP1
662 case METHOD_MPUIO:
663 /* MPUIO irqstatus is reset by reading the status register,
664 * so do nothing here */
665 return;
666#endif
667#ifdef CONFIG_ARCH_OMAP15XX
668 case METHOD_GPIO_1510:
669 reg += OMAP1510_GPIO_INT_STATUS;
670 break;
671#endif
672#ifdef CONFIG_ARCH_OMAP16XX
673 case METHOD_GPIO_1610:
674 reg += OMAP1610_GPIO_IRQSTATUS1;
675 break;
676#endif
677#if defined(CONFIG_ARCH_OMAP730) || defined(CONFIG_ARCH_OMAP850)
678 case METHOD_GPIO_7XX:
679 reg += OMAP7XX_GPIO_INT_STATUS;
680 break;
681#endif
682#if defined(CONFIG_ARCH_OMAP2) || defined(CONFIG_ARCH_OMAP3)
683 case METHOD_GPIO_24XX:
684 reg += OMAP24XX_GPIO_IRQSTATUS1;
685 break;
686#endif
687#if defined(CONFIG_ARCH_OMAP4)
688 case METHOD_GPIO_44XX:
689 reg += OMAP4_GPIO_IRQSTATUS0;
690 break;
691#endif
692 default:
693 WARN_ON(1);
694 return;
695 }
696 __raw_writel(gpio_mask, reg); 434 __raw_writel(gpio_mask, reg);
697 435
698 /* Workaround for clearing DSP GPIO interrupts to allow retention */ 436 /* Workaround for clearing DSP GPIO interrupts to allow retention */
699 if (cpu_is_omap24xx() || cpu_is_omap34xx()) 437 if (bank->regs->irqstatus2) {
700 reg = bank->base + OMAP24XX_GPIO_IRQSTATUS2; 438 reg = bank->base + bank->regs->irqstatus2;
701 else if (cpu_is_omap44xx())
702 reg = bank->base + OMAP4_GPIO_IRQSTATUS1;
703
704 if (cpu_is_omap24xx() || cpu_is_omap34xx() || cpu_is_omap44xx()) {
705 __raw_writel(gpio_mask, reg); 439 __raw_writel(gpio_mask, reg);
440 }
706 441
707 /* Flush posted write for the irq status to avoid spurious interrupts */ 442 /* Flush posted write for the irq status to avoid spurious interrupts */
708 __raw_readl(reg); 443 __raw_readl(reg);
709 }
710} 444}
711 445
712static inline void _clear_gpio_irqstatus(struct gpio_bank *bank, int gpio) 446static inline void _clear_gpio_irqstatus(struct gpio_bank *bank, int gpio)
713{ 447{
714 _clear_gpio_irqbank(bank, 1 << get_gpio_index(gpio)); 448 _clear_gpio_irqbank(bank, GPIO_BIT(bank, gpio));
715} 449}
716 450
717static u32 _get_gpio_irqbank_mask(struct gpio_bank *bank) 451static u32 _get_gpio_irqbank_mask(struct gpio_bank *bank)
718{ 452{
719 void __iomem *reg = bank->base; 453 void __iomem *reg = bank->base;
720 int inv = 0;
721 u32 l; 454 u32 l;
722 u32 mask; 455 u32 mask = (1 << bank->width) - 1;
723
724 switch (bank->method) {
725#ifdef CONFIG_ARCH_OMAP1
726 case METHOD_MPUIO:
727 reg += OMAP_MPUIO_GPIO_MASKIT / bank->stride;
728 mask = 0xffff;
729 inv = 1;
730 break;
731#endif
732#ifdef CONFIG_ARCH_OMAP15XX
733 case METHOD_GPIO_1510:
734 reg += OMAP1510_GPIO_INT_MASK;
735 mask = 0xffff;
736 inv = 1;
737 break;
738#endif
739#ifdef CONFIG_ARCH_OMAP16XX
740 case METHOD_GPIO_1610:
741 reg += OMAP1610_GPIO_IRQENABLE1;
742 mask = 0xffff;
743 break;
744#endif
745#if defined(CONFIG_ARCH_OMAP730) || defined(CONFIG_ARCH_OMAP850)
746 case METHOD_GPIO_7XX:
747 reg += OMAP7XX_GPIO_INT_MASK;
748 mask = 0xffffffff;
749 inv = 1;
750 break;
751#endif
752#if defined(CONFIG_ARCH_OMAP2) || defined(CONFIG_ARCH_OMAP3)
753 case METHOD_GPIO_24XX:
754 reg += OMAP24XX_GPIO_IRQENABLE1;
755 mask = 0xffffffff;
756 break;
757#endif
758#if defined(CONFIG_ARCH_OMAP4)
759 case METHOD_GPIO_44XX:
760 reg += OMAP4_GPIO_IRQSTATUSSET0;
761 mask = 0xffffffff;
762 break;
763#endif
764 default:
765 WARN_ON(1);
766 return 0;
767 }
768 456
457 reg += bank->regs->irqenable;
769 l = __raw_readl(reg); 458 l = __raw_readl(reg);
770 if (inv) 459 if (bank->regs->irqenable_inv)
771 l = ~l; 460 l = ~l;
772 l &= mask; 461 l &= mask;
773 return l; 462 return l;
774} 463}
775 464
776static void _enable_gpio_irqbank(struct gpio_bank *bank, int gpio_mask, int enable) 465static void _enable_gpio_irqbank(struct gpio_bank *bank, int gpio_mask)
777{ 466{
778 void __iomem *reg = bank->base; 467 void __iomem *reg = bank->base;
779 u32 l; 468 u32 l;
780 469
781 switch (bank->method) { 470 if (bank->regs->set_irqenable) {
782#ifdef CONFIG_ARCH_OMAP1 471 reg += bank->regs->set_irqenable;
783 case METHOD_MPUIO: 472 l = gpio_mask;
784 reg += OMAP_MPUIO_GPIO_MASKIT / bank->stride; 473 } else {
785 l = __raw_readl(reg); 474 reg += bank->regs->irqenable;
786 if (enable)
787 l &= ~(gpio_mask);
788 else
789 l |= gpio_mask;
790 break;
791#endif
792#ifdef CONFIG_ARCH_OMAP15XX
793 case METHOD_GPIO_1510:
794 reg += OMAP1510_GPIO_INT_MASK;
795 l = __raw_readl(reg); 475 l = __raw_readl(reg);
796 if (enable) 476 if (bank->regs->irqenable_inv)
797 l &= ~(gpio_mask); 477 l &= ~gpio_mask;
798 else 478 else
799 l |= gpio_mask; 479 l |= gpio_mask;
800 break; 480 }
801#endif 481
802#ifdef CONFIG_ARCH_OMAP16XX 482 __raw_writel(l, reg);
803 case METHOD_GPIO_1610: 483}
804 if (enable) 484
805 reg += OMAP1610_GPIO_SET_IRQENABLE1; 485static void _disable_gpio_irqbank(struct gpio_bank *bank, int gpio_mask)
806 else 486{
807 reg += OMAP1610_GPIO_CLEAR_IRQENABLE1; 487 void __iomem *reg = bank->base;
488 u32 l;
489
490 if (bank->regs->clr_irqenable) {
491 reg += bank->regs->clr_irqenable;
808 l = gpio_mask; 492 l = gpio_mask;
809 break; 493 } else {
810#endif 494 reg += bank->regs->irqenable;
811#if defined(CONFIG_ARCH_OMAP730) || defined(CONFIG_ARCH_OMAP850)
812 case METHOD_GPIO_7XX:
813 reg += OMAP7XX_GPIO_INT_MASK;
814 l = __raw_readl(reg); 495 l = __raw_readl(reg);
815 if (enable) 496 if (bank->regs->irqenable_inv)
816 l &= ~(gpio_mask);
817 else
818 l |= gpio_mask; 497 l |= gpio_mask;
819 break;
820#endif
821#if defined(CONFIG_ARCH_OMAP2) || defined(CONFIG_ARCH_OMAP3)
822 case METHOD_GPIO_24XX:
823 if (enable)
824 reg += OMAP24XX_GPIO_SETIRQENABLE1;
825 else
826 reg += OMAP24XX_GPIO_CLEARIRQENABLE1;
827 l = gpio_mask;
828 break;
829#endif
830#ifdef CONFIG_ARCH_OMAP4
831 case METHOD_GPIO_44XX:
832 if (enable)
833 reg += OMAP4_GPIO_IRQSTATUSSET0;
834 else 498 else
835 reg += OMAP4_GPIO_IRQSTATUSCLR0; 499 l &= ~gpio_mask;
836 l = gpio_mask;
837 break;
838#endif
839 default:
840 WARN_ON(1);
841 return;
842 } 500 }
501
843 __raw_writel(l, reg); 502 __raw_writel(l, reg);
844} 503}
845 504
846static inline void _set_gpio_irqenable(struct gpio_bank *bank, int gpio, int enable) 505static inline void _set_gpio_irqenable(struct gpio_bank *bank, int gpio, int enable)
847{ 506{
848 _enable_gpio_irqbank(bank, 1 << get_gpio_index(gpio), enable); 507 _enable_gpio_irqbank(bank, GPIO_BIT(bank, gpio));
849} 508}
850 509
851/* 510/*
@@ -858,50 +517,32 @@ static inline void _set_gpio_irqenable(struct gpio_bank *bank, int gpio, int ena
858 */ 517 */
859static int _set_gpio_wakeup(struct gpio_bank *bank, int gpio, int enable) 518static int _set_gpio_wakeup(struct gpio_bank *bank, int gpio, int enable)
860{ 519{
861 unsigned long uninitialized_var(flags); 520 u32 gpio_bit = GPIO_BIT(bank, gpio);
521 unsigned long flags;
862 522
863 switch (bank->method) { 523 if (bank->non_wakeup_gpios & gpio_bit) {
864#ifdef CONFIG_ARCH_OMAP16XX 524 dev_err(bank->dev,
865 case METHOD_MPUIO: 525 "Unable to modify wakeup on non-wakeup GPIO%d\n", gpio);
866 case METHOD_GPIO_1610:
867 spin_lock_irqsave(&bank->lock, flags);
868 if (enable)
869 bank->suspend_wakeup |= (1 << gpio);
870 else
871 bank->suspend_wakeup &= ~(1 << gpio);
872 spin_unlock_irqrestore(&bank->lock, flags);
873 return 0;
874#endif
875#ifdef CONFIG_ARCH_OMAP2PLUS
876 case METHOD_GPIO_24XX:
877 case METHOD_GPIO_44XX:
878 if (bank->non_wakeup_gpios & (1 << gpio)) {
879 printk(KERN_ERR "Unable to modify wakeup on "
880 "non-wakeup GPIO%d\n",
881 (bank - gpio_bank) * 32 + gpio);
882 return -EINVAL;
883 }
884 spin_lock_irqsave(&bank->lock, flags);
885 if (enable)
886 bank->suspend_wakeup |= (1 << gpio);
887 else
888 bank->suspend_wakeup &= ~(1 << gpio);
889 spin_unlock_irqrestore(&bank->lock, flags);
890 return 0;
891#endif
892 default:
893 printk(KERN_ERR "Can't enable GPIO wakeup for method %i\n",
894 bank->method);
895 return -EINVAL; 526 return -EINVAL;
896 } 527 }
528
529 spin_lock_irqsave(&bank->lock, flags);
530 if (enable)
531 bank->suspend_wakeup |= gpio_bit;
532 else
533 bank->suspend_wakeup &= ~gpio_bit;
534
535 spin_unlock_irqrestore(&bank->lock, flags);
536
537 return 0;
897} 538}
898 539
899static void _reset_gpio(struct gpio_bank *bank, int gpio) 540static void _reset_gpio(struct gpio_bank *bank, int gpio)
900{ 541{
901 _set_gpio_direction(bank, get_gpio_index(gpio), 1); 542 _set_gpio_direction(bank, GPIO_INDEX(bank, gpio), 1);
902 _set_gpio_irqenable(bank, gpio, 0); 543 _set_gpio_irqenable(bank, gpio, 0);
903 _clear_gpio_irqstatus(bank, gpio); 544 _clear_gpio_irqstatus(bank, gpio);
904 _set_gpio_triggering(bank, get_gpio_index(gpio), IRQ_TYPE_NONE); 545 _set_gpio_triggering(bank, GPIO_INDEX(bank, gpio), IRQ_TYPE_NONE);
905} 546}
906 547
907/* Use disable_irq_wake() and enable_irq_wake() functions from drivers */ 548/* Use disable_irq_wake() and enable_irq_wake() functions from drivers */
@@ -911,10 +552,8 @@ static int gpio_wake_enable(struct irq_data *d, unsigned int enable)
911 struct gpio_bank *bank; 552 struct gpio_bank *bank;
912 int retval; 553 int retval;
913 554
914 if (check_gpio(gpio) < 0)
915 return -ENODEV;
916 bank = irq_data_get_irq_chip_data(d); 555 bank = irq_data_get_irq_chip_data(d);
917 retval = _set_gpio_wakeup(bank, get_gpio_index(gpio), enable); 556 retval = _set_gpio_wakeup(bank, gpio, enable);
918 557
919 return retval; 558 return retval;
920} 559}
@@ -1030,31 +669,7 @@ static void gpio_irq_handler(unsigned int irq, struct irq_desc *desc)
1030 chained_irq_enter(chip, desc); 669 chained_irq_enter(chip, desc);
1031 670
1032 bank = irq_get_handler_data(irq); 671 bank = irq_get_handler_data(irq);
1033#ifdef CONFIG_ARCH_OMAP1 672 isr_reg = bank->base + bank->regs->irqstatus;
1034 if (bank->method == METHOD_MPUIO)
1035 isr_reg = bank->base +
1036 OMAP_MPUIO_GPIO_INT / bank->stride;
1037#endif
1038#ifdef CONFIG_ARCH_OMAP15XX
1039 if (bank->method == METHOD_GPIO_1510)
1040 isr_reg = bank->base + OMAP1510_GPIO_INT_STATUS;
1041#endif
1042#if defined(CONFIG_ARCH_OMAP16XX)
1043 if (bank->method == METHOD_GPIO_1610)
1044 isr_reg = bank->base + OMAP1610_GPIO_IRQSTATUS1;
1045#endif
1046#if defined(CONFIG_ARCH_OMAP730) || defined(CONFIG_ARCH_OMAP850)
1047 if (bank->method == METHOD_GPIO_7XX)
1048 isr_reg = bank->base + OMAP7XX_GPIO_INT_STATUS;
1049#endif
1050#if defined(CONFIG_ARCH_OMAP2) || defined(CONFIG_ARCH_OMAP3)
1051 if (bank->method == METHOD_GPIO_24XX)
1052 isr_reg = bank->base + OMAP24XX_GPIO_IRQSTATUS1;
1053#endif
1054#if defined(CONFIG_ARCH_OMAP4)
1055 if (bank->method == METHOD_GPIO_44XX)
1056 isr_reg = bank->base + OMAP4_GPIO_IRQSTATUS0;
1057#endif
1058 673
1059 if (WARN_ON(!isr_reg)) 674 if (WARN_ON(!isr_reg))
1060 goto exit; 675 goto exit;
@@ -1076,9 +691,9 @@ static void gpio_irq_handler(unsigned int irq, struct irq_desc *desc)
1076 /* clear edge sensitive interrupts before handler(s) are 691 /* clear edge sensitive interrupts before handler(s) are
1077 called so that we don't miss any interrupt occurred while 692 called so that we don't miss any interrupt occurred while
1078 executing them */ 693 executing them */
1079 _enable_gpio_irqbank(bank, isr_saved & ~level_mask, 0); 694 _disable_gpio_irqbank(bank, isr_saved & ~level_mask);
1080 _clear_gpio_irqbank(bank, isr_saved & ~level_mask); 695 _clear_gpio_irqbank(bank, isr_saved & ~level_mask);
1081 _enable_gpio_irqbank(bank, isr_saved & ~level_mask, 1); 696 _enable_gpio_irqbank(bank, isr_saved & ~level_mask);
1082 697
1083 /* if there is only edge sensitive GPIO pin interrupts 698 /* if there is only edge sensitive GPIO pin interrupts
1084 configured, we could unmask GPIO bank interrupt immediately */ 699 configured, we could unmask GPIO bank interrupt immediately */
@@ -1094,7 +709,7 @@ static void gpio_irq_handler(unsigned int irq, struct irq_desc *desc)
1094 709
1095 gpio_irq = bank->virtual_irq_start; 710 gpio_irq = bank->virtual_irq_start;
1096 for (; isr != 0; isr >>= 1, gpio_irq++) { 711 for (; isr != 0; isr >>= 1, gpio_irq++) {
1097 gpio_index = get_gpio_index(irq_to_gpio(gpio_irq)); 712 gpio_index = GPIO_INDEX(bank, irq_to_gpio(gpio_irq));
1098 713
1099 if (!(isr & 1)) 714 if (!(isr & 1))
1100 continue; 715 continue;
@@ -1150,7 +765,7 @@ static void gpio_mask_irq(struct irq_data *d)
1150 765
1151 spin_lock_irqsave(&bank->lock, flags); 766 spin_lock_irqsave(&bank->lock, flags);
1152 _set_gpio_irqenable(bank, gpio, 0); 767 _set_gpio_irqenable(bank, gpio, 0);
1153 _set_gpio_triggering(bank, get_gpio_index(gpio), IRQ_TYPE_NONE); 768 _set_gpio_triggering(bank, GPIO_INDEX(bank, gpio), IRQ_TYPE_NONE);
1154 spin_unlock_irqrestore(&bank->lock, flags); 769 spin_unlock_irqrestore(&bank->lock, flags);
1155} 770}
1156 771
@@ -1158,13 +773,13 @@ static void gpio_unmask_irq(struct irq_data *d)
1158{ 773{
1159 unsigned int gpio = d->irq - IH_GPIO_BASE; 774 unsigned int gpio = d->irq - IH_GPIO_BASE;
1160 struct gpio_bank *bank = irq_data_get_irq_chip_data(d); 775 struct gpio_bank *bank = irq_data_get_irq_chip_data(d);
1161 unsigned int irq_mask = 1 << get_gpio_index(gpio); 776 unsigned int irq_mask = GPIO_BIT(bank, gpio);
1162 u32 trigger = irqd_get_trigger_type(d); 777 u32 trigger = irqd_get_trigger_type(d);
1163 unsigned long flags; 778 unsigned long flags;
1164 779
1165 spin_lock_irqsave(&bank->lock, flags); 780 spin_lock_irqsave(&bank->lock, flags);
1166 if (trigger) 781 if (trigger)
1167 _set_gpio_triggering(bank, get_gpio_index(gpio), trigger); 782 _set_gpio_triggering(bank, GPIO_INDEX(bank, gpio), trigger);
1168 783
1169 /* For level-triggered GPIOs, the clearing must be done after 784 /* For level-triggered GPIOs, the clearing must be done after
1170 * the HW source is cleared, thus after the handler has run */ 785 * the HW source is cleared, thus after the handler has run */
@@ -1191,45 +806,8 @@ static struct irq_chip gpio_irq_chip = {
1191 806
1192#ifdef CONFIG_ARCH_OMAP1 807#ifdef CONFIG_ARCH_OMAP1
1193 808
1194/* MPUIO uses the always-on 32k clock */
1195
1196static void mpuio_ack_irq(struct irq_data *d)
1197{
1198 /* The ISR is reset automatically, so do nothing here. */
1199}
1200
1201static void mpuio_mask_irq(struct irq_data *d)
1202{
1203 unsigned int gpio = OMAP_MPUIO(d->irq - IH_MPUIO_BASE);
1204 struct gpio_bank *bank = irq_data_get_irq_chip_data(d);
1205
1206 _set_gpio_irqenable(bank, gpio, 0);
1207}
1208
1209static void mpuio_unmask_irq(struct irq_data *d)
1210{
1211 unsigned int gpio = OMAP_MPUIO(d->irq - IH_MPUIO_BASE);
1212 struct gpio_bank *bank = irq_data_get_irq_chip_data(d);
1213
1214 _set_gpio_irqenable(bank, gpio, 1);
1215}
1216
1217static struct irq_chip mpuio_irq_chip = {
1218 .name = "MPUIO",
1219 .irq_ack = mpuio_ack_irq,
1220 .irq_mask = mpuio_mask_irq,
1221 .irq_unmask = mpuio_unmask_irq,
1222 .irq_set_type = gpio_irq_type,
1223#ifdef CONFIG_ARCH_OMAP16XX
1224 /* REVISIT: assuming only 16xx supports MPUIO wake events */
1225 .irq_set_wake = gpio_wake_enable,
1226#endif
1227};
1228
1229
1230#define bank_is_mpuio(bank) ((bank)->method == METHOD_MPUIO) 809#define bank_is_mpuio(bank) ((bank)->method == METHOD_MPUIO)
1231 810
1232
1233#ifdef CONFIG_ARCH_OMAP16XX 811#ifdef CONFIG_ARCH_OMAP16XX
1234 812
1235#include <linux/platform_device.h> 813#include <linux/platform_device.h>
@@ -1289,7 +867,7 @@ static struct platform_device omap_mpuio_device = {
1289 867
1290static inline void mpuio_init(void) 868static inline void mpuio_init(void)
1291{ 869{
1292 struct gpio_bank *bank = get_gpio_bank(OMAP_MPUIO(0)); 870 struct gpio_bank *bank = &gpio_bank[0];
1293 platform_set_drvdata(&omap_mpuio_device, bank); 871 platform_set_drvdata(&omap_mpuio_device, bank);
1294 872
1295 if (platform_driver_register(&omap_mpuio_driver) == 0) 873 if (platform_driver_register(&omap_mpuio_driver) == 0)
@@ -1302,8 +880,6 @@ static inline void mpuio_init(void) {}
1302 880
1303#else 881#else
1304 882
1305extern struct irq_chip mpuio_irq_chip;
1306
1307#define bank_is_mpuio(bank) 0 883#define bank_is_mpuio(bank) 0
1308static inline void mpuio_init(void) {} 884static inline void mpuio_init(void) {}
1309 885
@@ -1329,31 +905,8 @@ static int gpio_input(struct gpio_chip *chip, unsigned offset)
1329 905
1330static int gpio_is_input(struct gpio_bank *bank, int mask) 906static int gpio_is_input(struct gpio_bank *bank, int mask)
1331{ 907{
1332 void __iomem *reg = bank->base; 908 void __iomem *reg = bank->base + bank->regs->direction;
1333 909
1334 switch (bank->method) {
1335 case METHOD_MPUIO:
1336 reg += OMAP_MPUIO_IO_CNTL / bank->stride;
1337 break;
1338 case METHOD_GPIO_1510:
1339 reg += OMAP1510_GPIO_DIR_CONTROL;
1340 break;
1341 case METHOD_GPIO_1610:
1342 reg += OMAP1610_GPIO_DIRECTION;
1343 break;
1344 case METHOD_GPIO_7XX:
1345 reg += OMAP7XX_GPIO_DIR_CONTROL;
1346 break;
1347 case METHOD_GPIO_24XX:
1348 reg += OMAP24XX_GPIO_OE;
1349 break;
1350 case METHOD_GPIO_44XX:
1351 reg += OMAP4_GPIO_OE;
1352 break;
1353 default:
1354 WARN_ONCE(1, "gpio_is_input: incorrect OMAP GPIO method");
1355 return -EINVAL;
1356 }
1357 return __raw_readl(reg) & mask; 910 return __raw_readl(reg) & mask;
1358} 911}
1359 912
@@ -1365,9 +918,9 @@ static int gpio_get(struct gpio_chip *chip, unsigned offset)
1365 u32 mask; 918 u32 mask;
1366 919
1367 gpio = chip->base + offset; 920 gpio = chip->base + offset;
1368 bank = get_gpio_bank(gpio); 921 bank = container_of(chip, struct gpio_bank, chip);
1369 reg = bank->base; 922 reg = bank->base;
1370 mask = 1 << get_gpio_index(gpio); 923 mask = GPIO_BIT(bank, gpio);
1371 924
1372 if (gpio_is_input(bank, mask)) 925 if (gpio_is_input(bank, mask))
1373 return _get_gpio_datain(bank, gpio); 926 return _get_gpio_datain(bank, gpio);
@@ -1382,7 +935,7 @@ static int gpio_output(struct gpio_chip *chip, unsigned offset, int value)
1382 935
1383 bank = container_of(chip, struct gpio_bank, chip); 936 bank = container_of(chip, struct gpio_bank, chip);
1384 spin_lock_irqsave(&bank->lock, flags); 937 spin_lock_irqsave(&bank->lock, flags);
1385 _set_gpio_dataout(bank, offset, value); 938 bank->set_dataout(bank, offset, value);
1386 _set_gpio_direction(bank, offset, 0); 939 _set_gpio_direction(bank, offset, 0);
1387 spin_unlock_irqrestore(&bank->lock, flags); 940 spin_unlock_irqrestore(&bank->lock, flags);
1388 return 0; 941 return 0;
@@ -1416,7 +969,7 @@ static void gpio_set(struct gpio_chip *chip, unsigned offset, int value)
1416 969
1417 bank = container_of(chip, struct gpio_bank, chip); 970 bank = container_of(chip, struct gpio_bank, chip);
1418 spin_lock_irqsave(&bank->lock, flags); 971 spin_lock_irqsave(&bank->lock, flags);
1419 _set_gpio_dataout(bank, offset, value); 972 bank->set_dataout(bank, offset, value);
1420 spin_unlock_irqrestore(&bank->lock, flags); 973 spin_unlock_irqrestore(&bank->lock, flags);
1421} 974}
1422 975
@@ -1432,19 +985,17 @@ static int gpio_2irq(struct gpio_chip *chip, unsigned offset)
1432 985
1433static void __init omap_gpio_show_rev(struct gpio_bank *bank) 986static void __init omap_gpio_show_rev(struct gpio_bank *bank)
1434{ 987{
988 static bool called;
1435 u32 rev; 989 u32 rev;
1436 990
1437 if (cpu_is_omap16xx() && !(bank->method != METHOD_MPUIO)) 991 if (called || bank->regs->revision == USHRT_MAX)
1438 rev = __raw_readw(bank->base + OMAP1610_GPIO_REVISION);
1439 else if (cpu_is_omap24xx() || cpu_is_omap34xx())
1440 rev = __raw_readl(bank->base + OMAP24XX_GPIO_REVISION);
1441 else if (cpu_is_omap44xx())
1442 rev = __raw_readl(bank->base + OMAP4_GPIO_REVISION);
1443 else
1444 return; 992 return;
1445 993
1446 printk(KERN_INFO "OMAP GPIO hardware version %d.%d\n", 994 rev = __raw_readw(bank->base + bank->regs->revision);
995 pr_info("OMAP GPIO hardware version %d.%d\n",
1447 (rev >> 4) & 0x0f, rev & 0x0f); 996 (rev >> 4) & 0x0f, rev & 0x0f);
997
998 called = true;
1448} 999}
1449 1000
1450/* This lock class tells lockdep that GPIO irqs are in a different 1001/* This lock class tells lockdep that GPIO irqs are in a different
@@ -1526,6 +1077,30 @@ static void omap_gpio_mod_init(struct gpio_bank *bank, int id)
1526 } 1077 }
1527} 1078}
1528 1079
1080static __init void
1081omap_mpuio_alloc_gc(struct gpio_bank *bank, unsigned int irq_start,
1082 unsigned int num)
1083{
1084 struct irq_chip_generic *gc;
1085 struct irq_chip_type *ct;
1086
1087 gc = irq_alloc_generic_chip("MPUIO", 1, irq_start, bank->base,
1088 handle_simple_irq);
1089 ct = gc->chip_types;
1090
1091 /* NOTE: No ack required, reading IRQ status clears it. */
1092 ct->chip.irq_mask = irq_gc_mask_set_bit;
1093 ct->chip.irq_unmask = irq_gc_mask_clr_bit;
1094 ct->chip.irq_set_type = gpio_irq_type;
1095 /* REVISIT: assuming only 16xx supports MPUIO wake events */
1096 if (cpu_is_omap16xx())
1097 ct->chip.irq_set_wake = gpio_wake_enable,
1098
1099 ct->regs.mask = OMAP_MPUIO_GPIO_INT / bank->stride;
1100 irq_setup_generic_chip(gc, IRQ_MSK(num), IRQ_GC_INIT_MASK_CACHE,
1101 IRQ_NOREQUEST | IRQ_NOPROBE, 0);
1102}
1103
1529static void __devinit omap_gpio_chip_init(struct gpio_bank *bank) 1104static void __devinit omap_gpio_chip_init(struct gpio_bank *bank)
1530{ 1105{
1531 int j; 1106 int j;
@@ -1553,22 +1128,23 @@ static void __devinit omap_gpio_chip_init(struct gpio_bank *bank)
1553 } else { 1128 } else {
1554 bank->chip.label = "gpio"; 1129 bank->chip.label = "gpio";
1555 bank->chip.base = gpio; 1130 bank->chip.base = gpio;
1556 gpio += bank_width; 1131 gpio += bank->width;
1557 } 1132 }
1558 bank->chip.ngpio = bank_width; 1133 bank->chip.ngpio = bank->width;
1559 1134
1560 gpiochip_add(&bank->chip); 1135 gpiochip_add(&bank->chip);
1561 1136
1562 for (j = bank->virtual_irq_start; 1137 for (j = bank->virtual_irq_start;
1563 j < bank->virtual_irq_start + bank_width; j++) { 1138 j < bank->virtual_irq_start + bank->width; j++) {
1564 irq_set_lockdep_class(j, &gpio_lock_class); 1139 irq_set_lockdep_class(j, &gpio_lock_class);
1565 irq_set_chip_data(j, bank); 1140 irq_set_chip_data(j, bank);
1566 if (bank_is_mpuio(bank)) 1141 if (bank_is_mpuio(bank)) {
1567 irq_set_chip(j, &mpuio_irq_chip); 1142 omap_mpuio_alloc_gc(bank, j, bank->width);
1568 else 1143 } else {
1569 irq_set_chip(j, &gpio_irq_chip); 1144 irq_set_chip(j, &gpio_irq_chip);
1570 irq_set_handler(j, handle_simple_irq); 1145 irq_set_handler(j, handle_simple_irq);
1571 set_irq_flags(j, IRQF_VALID); 1146 set_irq_flags(j, IRQF_VALID);
1147 }
1572 } 1148 }
1573 irq_set_chained_handler(bank->irq, gpio_irq_handler); 1149 irq_set_chained_handler(bank->irq, gpio_irq_handler);
1574 irq_set_handler_data(bank->irq, bank); 1150 irq_set_handler_data(bank->irq, bank);
@@ -1610,7 +1186,14 @@ static int __devinit omap_gpio_probe(struct platform_device *pdev)
1610 bank->dev = &pdev->dev; 1186 bank->dev = &pdev->dev;
1611 bank->dbck_flag = pdata->dbck_flag; 1187 bank->dbck_flag = pdata->dbck_flag;
1612 bank->stride = pdata->bank_stride; 1188 bank->stride = pdata->bank_stride;
1613 bank_width = pdata->bank_width; 1189 bank->width = pdata->bank_width;
1190
1191 bank->regs = pdata->regs;
1192
1193 if (bank->regs->set_dataout && bank->regs->clr_dataout)
1194 bank->set_dataout = _set_gpio_dataout_reg;
1195 else
1196 bank->set_dataout = _set_gpio_dataout_mask;
1614 1197
1615 spin_lock_init(&bank->lock); 1198 spin_lock_init(&bank->lock);
1616 1199
diff --git a/drivers/gpio/pca953x.c b/drivers/gpio/gpio-pca953x.c
index 0451d7ac94ac..c43b8ff626a7 100644
--- a/drivers/gpio/pca953x.c
+++ b/drivers/gpio/gpio-pca953x.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * pca953x.c - 4/8/16 bit I/O ports 2 * PCA953x 4/8/16 bit I/O ports
3 * 3 *
4 * Copyright (C) 2005 Ben Gardner <bgardner@wabtec.com> 4 * Copyright (C) 2005 Ben Gardner <bgardner@wabtec.com>
5 * Copyright (C) 2007 Marvell International Ltd. 5 * Copyright (C) 2007 Marvell International Ltd.
@@ -21,7 +21,6 @@
21#include <linux/slab.h> 21#include <linux/slab.h>
22#ifdef CONFIG_OF_GPIO 22#ifdef CONFIG_OF_GPIO
23#include <linux/of_platform.h> 23#include <linux/of_platform.h>
24#include <linux/of_gpio.h>
25#endif 24#endif
26 25
27#define PCA953X_INPUT 0 26#define PCA953X_INPUT 0
@@ -85,7 +84,6 @@ struct pca953x_chip {
85#endif 84#endif
86 85
87 struct i2c_client *client; 86 struct i2c_client *client;
88 struct pca953x_platform_data *dyn_pdata;
89 struct gpio_chip gpio_chip; 87 struct gpio_chip gpio_chip;
90 const char *const *names; 88 const char *const *names;
91 int chip_type; 89 int chip_type;
@@ -437,7 +435,7 @@ static irqreturn_t pca953x_irq_handler(int irq, void *devid)
437 435
438 do { 436 do {
439 level = __ffs(pending); 437 level = __ffs(pending);
440 generic_handle_irq(level + chip->irq_base); 438 handle_nested_irq(level + chip->irq_base);
441 439
442 pending &= ~(1 << level); 440 pending &= ~(1 << level);
443 } while (pending); 441 } while (pending);
@@ -446,13 +444,13 @@ static irqreturn_t pca953x_irq_handler(int irq, void *devid)
446} 444}
447 445
448static int pca953x_irq_setup(struct pca953x_chip *chip, 446static int pca953x_irq_setup(struct pca953x_chip *chip,
449 const struct i2c_device_id *id) 447 const struct i2c_device_id *id,
448 int irq_base)
450{ 449{
451 struct i2c_client *client = chip->client; 450 struct i2c_client *client = chip->client;
452 struct pca953x_platform_data *pdata = client->dev.platform_data;
453 int ret, offset = 0; 451 int ret, offset = 0;
454 452
455 if (pdata->irq_base != -1 453 if (irq_base != -1
456 && (id->driver_data & PCA_INT)) { 454 && (id->driver_data & PCA_INT)) {
457 int lvl; 455 int lvl;
458 456
@@ -474,15 +472,19 @@ static int pca953x_irq_setup(struct pca953x_chip *chip,
474 * this purpose. 472 * this purpose.
475 */ 473 */
476 chip->irq_stat &= chip->reg_direction; 474 chip->irq_stat &= chip->reg_direction;
477 chip->irq_base = pdata->irq_base;
478 mutex_init(&chip->irq_lock); 475 mutex_init(&chip->irq_lock);
479 476
477 chip->irq_base = irq_alloc_descs(-1, irq_base, chip->gpio_chip.ngpio, -1);
478 if (chip->irq_base < 0)
479 goto out_failed;
480
480 for (lvl = 0; lvl < chip->gpio_chip.ngpio; lvl++) { 481 for (lvl = 0; lvl < chip->gpio_chip.ngpio; lvl++) {
481 int irq = lvl + chip->irq_base; 482 int irq = lvl + chip->irq_base;
482 483
484 irq_clear_status_flags(irq, IRQ_NOREQUEST);
483 irq_set_chip_data(irq, chip); 485 irq_set_chip_data(irq, chip);
484 irq_set_chip_and_handler(irq, &pca953x_irq_chip, 486 irq_set_chip(irq, &pca953x_irq_chip);
485 handle_simple_irq); 487 irq_set_nested_thread(irq, true);
486#ifdef CONFIG_ARM 488#ifdef CONFIG_ARM
487 set_irq_flags(irq, IRQF_VALID); 489 set_irq_flags(irq, IRQF_VALID);
488#else 490#else
@@ -493,8 +495,7 @@ static int pca953x_irq_setup(struct pca953x_chip *chip,
493 ret = request_threaded_irq(client->irq, 495 ret = request_threaded_irq(client->irq,
494 NULL, 496 NULL,
495 pca953x_irq_handler, 497 pca953x_irq_handler,
496 IRQF_TRIGGER_RISING | 498 IRQF_TRIGGER_LOW | IRQF_ONESHOT,
497 IRQF_TRIGGER_FALLING | IRQF_ONESHOT,
498 dev_name(&client->dev), chip); 499 dev_name(&client->dev), chip);
499 if (ret) { 500 if (ret) {
500 dev_err(&client->dev, "failed to request irq %d\n", 501 dev_err(&client->dev, "failed to request irq %d\n",
@@ -514,17 +515,19 @@ out_failed:
514 515
515static void pca953x_irq_teardown(struct pca953x_chip *chip) 516static void pca953x_irq_teardown(struct pca953x_chip *chip)
516{ 517{
517 if (chip->irq_base != -1) 518 if (chip->irq_base != -1) {
519 irq_free_descs(chip->irq_base, chip->gpio_chip.ngpio);
518 free_irq(chip->client->irq, chip); 520 free_irq(chip->client->irq, chip);
521 }
519} 522}
520#else /* CONFIG_GPIO_PCA953X_IRQ */ 523#else /* CONFIG_GPIO_PCA953X_IRQ */
521static int pca953x_irq_setup(struct pca953x_chip *chip, 524static int pca953x_irq_setup(struct pca953x_chip *chip,
522 const struct i2c_device_id *id) 525 const struct i2c_device_id *id,
526 int irq_base)
523{ 527{
524 struct i2c_client *client = chip->client; 528 struct i2c_client *client = chip->client;
525 struct pca953x_platform_data *pdata = client->dev.platform_data;
526 529
527 if (pdata->irq_base != -1 && (id->driver_data & PCA_INT)) 530 if (irq_base != -1 && (id->driver_data & PCA_INT))
528 dev_warn(&client->dev, "interrupt support not compiled in\n"); 531 dev_warn(&client->dev, "interrupt support not compiled in\n");
529 532
530 return 0; 533 return 0;
@@ -541,46 +544,39 @@ static void pca953x_irq_teardown(struct pca953x_chip *chip)
541#ifdef CONFIG_OF_GPIO 544#ifdef CONFIG_OF_GPIO
542/* 545/*
543 * Translate OpenFirmware node properties into platform_data 546 * Translate OpenFirmware node properties into platform_data
547 * WARNING: This is DEPRECATED and will be removed eventually!
544 */ 548 */
545static struct pca953x_platform_data * 549void
546pca953x_get_alt_pdata(struct i2c_client *client) 550pca953x_get_alt_pdata(struct i2c_client *client, int *gpio_base, int *invert)
547{ 551{
548 struct pca953x_platform_data *pdata;
549 struct device_node *node; 552 struct device_node *node;
550 const __be32 *val; 553 const __be32 *val;
551 int size; 554 int size;
552 555
553 node = client->dev.of_node; 556 node = client->dev.of_node;
554 if (node == NULL) 557 if (node == NULL)
555 return NULL; 558 return;
556
557 pdata = kzalloc(sizeof(struct pca953x_platform_data), GFP_KERNEL);
558 if (pdata == NULL) {
559 dev_err(&client->dev, "Unable to allocate platform_data\n");
560 return NULL;
561 }
562 559
563 pdata->gpio_base = -1; 560 *gpio_base = -1;
564 val = of_get_property(node, "linux,gpio-base", &size); 561 val = of_get_property(node, "linux,gpio-base", &size);
562 WARN(val, "%s: device-tree property 'linux,gpio-base' is deprecated!", __func__);
565 if (val) { 563 if (val) {
566 if (size != sizeof(*val)) 564 if (size != sizeof(*val))
567 dev_warn(&client->dev, "%s: wrong linux,gpio-base\n", 565 dev_warn(&client->dev, "%s: wrong linux,gpio-base\n",
568 node->full_name); 566 node->full_name);
569 else 567 else
570 pdata->gpio_base = be32_to_cpup(val); 568 *gpio_base = be32_to_cpup(val);
571 } 569 }
572 570
573 val = of_get_property(node, "polarity", NULL); 571 val = of_get_property(node, "polarity", NULL);
572 WARN(val, "%s: device-tree property 'polarity' is deprecated!", __func__);
574 if (val) 573 if (val)
575 pdata->invert = *val; 574 *invert = *val;
576
577 return pdata;
578} 575}
579#else 576#else
580static struct pca953x_platform_data * 577void
581pca953x_get_alt_pdata(struct i2c_client *client) 578pca953x_get_alt_pdata(struct i2c_client *client, int *gpio_base, int *invert)
582{ 579{
583 return NULL;
584} 580}
585#endif 581#endif
586 582
@@ -642,6 +638,7 @@ static int __devinit pca953x_probe(struct i2c_client *client,
642{ 638{
643 struct pca953x_platform_data *pdata; 639 struct pca953x_platform_data *pdata;
644 struct pca953x_chip *chip; 640 struct pca953x_chip *chip;
641 int irq_base=0, invert=0;
645 int ret = 0; 642 int ret = 0;
646 643
647 chip = kzalloc(sizeof(struct pca953x_chip), GFP_KERNEL); 644 chip = kzalloc(sizeof(struct pca953x_chip), GFP_KERNEL);
@@ -649,26 +646,22 @@ static int __devinit pca953x_probe(struct i2c_client *client,
649 return -ENOMEM; 646 return -ENOMEM;
650 647
651 pdata = client->dev.platform_data; 648 pdata = client->dev.platform_data;
652 if (pdata == NULL) { 649 if (pdata) {
653 pdata = pca953x_get_alt_pdata(client); 650 irq_base = pdata->irq_base;
654 /* 651 chip->gpio_start = pdata->gpio_base;
655 * Unlike normal platform_data, this is allocated 652 invert = pdata->invert;
656 * dynamically and must be freed in the driver 653 chip->names = pdata->names;
657 */ 654 } else {
658 chip->dyn_pdata = pdata; 655 pca953x_get_alt_pdata(client, &chip->gpio_start, &invert);
659 } 656#ifdef CONFIG_OF_GPIO
660 657 /* If I2C node has no interrupts property, disable GPIO interrupts */
661 if (pdata == NULL) { 658 if (of_find_property(client->dev.of_node, "interrupts", NULL) == NULL)
662 dev_dbg(&client->dev, "no platform data\n"); 659 irq_base = -1;
663 ret = -EINVAL; 660#endif
664 goto out_failed;
665 } 661 }
666 662
667 chip->client = client; 663 chip->client = client;
668 664
669 chip->gpio_start = pdata->gpio_base;
670
671 chip->names = pdata->names;
672 chip->chip_type = id->driver_data & (PCA953X_TYPE | PCA957X_TYPE); 665 chip->chip_type = id->driver_data & (PCA953X_TYPE | PCA957X_TYPE);
673 666
674 mutex_init(&chip->i2c_lock); 667 mutex_init(&chip->i2c_lock);
@@ -679,13 +672,13 @@ static int __devinit pca953x_probe(struct i2c_client *client,
679 pca953x_setup_gpio(chip, id->driver_data & PCA_GPIO_MASK); 672 pca953x_setup_gpio(chip, id->driver_data & PCA_GPIO_MASK);
680 673
681 if (chip->chip_type == PCA953X_TYPE) 674 if (chip->chip_type == PCA953X_TYPE)
682 device_pca953x_init(chip, pdata->invert); 675 device_pca953x_init(chip, invert);
683 else if (chip->chip_type == PCA957X_TYPE) 676 else if (chip->chip_type == PCA957X_TYPE)
684 device_pca957x_init(chip, pdata->invert); 677 device_pca957x_init(chip, invert);
685 else 678 else
686 goto out_failed; 679 goto out_failed;
687 680
688 ret = pca953x_irq_setup(chip, id); 681 ret = pca953x_irq_setup(chip, id, irq_base);
689 if (ret) 682 if (ret)
690 goto out_failed; 683 goto out_failed;
691 684
@@ -693,7 +686,7 @@ static int __devinit pca953x_probe(struct i2c_client *client,
693 if (ret) 686 if (ret)
694 goto out_failed_irq; 687 goto out_failed_irq;
695 688
696 if (pdata->setup) { 689 if (pdata && pdata->setup) {
697 ret = pdata->setup(client, chip->gpio_chip.base, 690 ret = pdata->setup(client, chip->gpio_chip.base,
698 chip->gpio_chip.ngpio, pdata->context); 691 chip->gpio_chip.ngpio, pdata->context);
699 if (ret < 0) 692 if (ret < 0)
@@ -706,7 +699,6 @@ static int __devinit pca953x_probe(struct i2c_client *client,
706out_failed_irq: 699out_failed_irq:
707 pca953x_irq_teardown(chip); 700 pca953x_irq_teardown(chip);
708out_failed: 701out_failed:
709 kfree(chip->dyn_pdata);
710 kfree(chip); 702 kfree(chip);
711 return ret; 703 return ret;
712} 704}
@@ -717,7 +709,7 @@ static int pca953x_remove(struct i2c_client *client)
717 struct pca953x_chip *chip = i2c_get_clientdata(client); 709 struct pca953x_chip *chip = i2c_get_clientdata(client);
718 int ret = 0; 710 int ret = 0;
719 711
720 if (pdata->teardown) { 712 if (pdata && pdata->teardown) {
721 ret = pdata->teardown(client, chip->gpio_chip.base, 713 ret = pdata->teardown(client, chip->gpio_chip.base,
722 chip->gpio_chip.ngpio, pdata->context); 714 chip->gpio_chip.ngpio, pdata->context);
723 if (ret < 0) { 715 if (ret < 0) {
@@ -735,7 +727,6 @@ static int pca953x_remove(struct i2c_client *client)
735 } 727 }
736 728
737 pca953x_irq_teardown(chip); 729 pca953x_irq_teardown(chip);
738 kfree(chip->dyn_pdata);
739 kfree(chip); 730 kfree(chip);
740 return 0; 731 return 0;
741} 732}
diff --git a/drivers/gpio/pcf857x.c b/drivers/gpio/gpio-pcf857x.c
index 879b473aab5a..7369fdda92b0 100644
--- a/drivers/gpio/pcf857x.c
+++ b/drivers/gpio/gpio-pcf857x.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * pcf857x - driver for pcf857x, pca857x, and pca967x I2C GPIO expanders 2 * Driver for pcf857x, pca857x, and pca967x I2C GPIO expanders
3 * 3 *
4 * Copyright (C) 2007 David Brownell 4 * Copyright (C) 2007 David Brownell
5 * 5 *
diff --git a/drivers/gpio/pch_gpio.c b/drivers/gpio/gpio-pch.c
index 36919e77c495..36919e77c495 100644
--- a/drivers/gpio/pch_gpio.c
+++ b/drivers/gpio/gpio-pch.c
diff --git a/drivers/gpio/pl061.c b/drivers/gpio/gpio-pl061.c
index 6fcb28cdd862..2c5a18f32bf3 100644
--- a/drivers/gpio/pl061.c
+++ b/drivers/gpio/gpio-pl061.c
@@ -1,7 +1,5 @@
1/* 1/*
2 * linux/drivers/gpio/pl061.c 2 * Copyright (C) 2008, 2009 Provigent Ltd.
3 *
4 * Copyright (C) 2008, 2009 Provigent Ltd.
5 * 3 *
6 * This program is free software; you can redistribute it and/or modify 4 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as 5 * it under the terms of the GNU General Public License version 2 as
diff --git a/drivers/gpio/gpio-plat-samsung.c b/drivers/gpio/gpio-plat-samsung.c
index ea37c0461788..ef67f1952a72 100644
--- a/drivers/gpio/gpio-plat-samsung.c
+++ b/drivers/gpio/gpio-plat-samsung.c
@@ -1,5 +1,4 @@
1/* arch/arm/plat-samsung/gpiolib.c 1/*
2 *
3 * Copyright 2008 Openmoko, Inc. 2 * Copyright 2008 Openmoko, Inc.
4 * Copyright 2008 Simtec Electronics 3 * Copyright 2008 Simtec Electronics
5 * Ben Dooks <ben@simtec.co.uk> 4 * Ben Dooks <ben@simtec.co.uk>
diff --git a/drivers/gpio/rdc321x-gpio.c b/drivers/gpio/gpio-rdc321x.c
index 2762698e0204..2762698e0204 100644
--- a/drivers/gpio/rdc321x-gpio.c
+++ b/drivers/gpio/gpio-rdc321x.c
diff --git a/drivers/gpio/gpio-s5pc100.c b/drivers/gpio/gpio-s5pc100.c
index 2842394b28b5..7f87b0c76e0b 100644
--- a/drivers/gpio/gpio-s5pc100.c
+++ b/drivers/gpio/gpio-s5pc100.c
@@ -1,4 +1,5 @@
1/* linux/arch/arm/mach-s5pc100/gpiolib.c 1/*
2 * S5PC100 - GPIOlib support
2 * 3 *
3 * Copyright (c) 2010 Samsung Electronics Co., Ltd. 4 * Copyright (c) 2010 Samsung Electronics Co., Ltd.
4 * http://www.samsung.com 5 * http://www.samsung.com
@@ -6,8 +7,6 @@
6 * Copyright 2009 Samsung Electronics Co 7 * Copyright 2009 Samsung Electronics Co
7 * Kyungmin Park <kyungmin.park@samsung.com> 8 * Kyungmin Park <kyungmin.park@samsung.com>
8 * 9 *
9 * S5PC100 - GPIOlib support
10 *
11 * This program is free software; you can redistribute it and/or modify 10 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License version 2 as 11 * it under the terms of the GNU General Public License version 2 as
13 * published by the Free Software Foundation. 12 * published by the Free Software Foundation.
diff --git a/drivers/gpio/gpio-s5pv210.c b/drivers/gpio/gpio-s5pv210.c
index 1ba20a703e05..eb12f1602de9 100644
--- a/drivers/gpio/gpio-s5pv210.c
+++ b/drivers/gpio/gpio-s5pv210.c
@@ -1,10 +1,9 @@
1/* linux/arch/arm/mach-s5pv210/gpiolib.c 1/*
2 * S5PV210 - GPIOlib support
2 * 3 *
3 * Copyright (c) 2010 Samsung Electronics Co., Ltd. 4 * Copyright (c) 2010 Samsung Electronics Co., Ltd.
4 * http://www.samsung.com/ 5 * http://www.samsung.com/
5 * 6 *
6 * S5PV210 - GPIOlib support
7 *
8 * This program is free software; you can redistribute it and/or modify 7 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as 8 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation. 9 * published by the Free Software Foundation.
diff --git a/drivers/gpio/sch_gpio.c b/drivers/gpio/gpio-sch.c
index 56060421cdff..163515845494 100644
--- a/drivers/gpio/sch_gpio.c
+++ b/drivers/gpio/gpio-sch.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * sch_gpio.c - GPIO interface for Intel Poulsbo SCH 2 * GPIO interface for Intel Poulsbo SCH
3 * 3 *
4 * Copyright (c) 2010 CompuLab Ltd 4 * Copyright (c) 2010 CompuLab Ltd
5 * Author: Denis Turischev <denis@compulab.co.il> 5 * Author: Denis Turischev <denis@compulab.co.il>
diff --git a/drivers/gpio/stmpe-gpio.c b/drivers/gpio/gpio-stmpe.c
index 4c980b573328..4c980b573328 100644
--- a/drivers/gpio/stmpe-gpio.c
+++ b/drivers/gpio/gpio-stmpe.c
diff --git a/drivers/gpio/sx150x.c b/drivers/gpio/gpio-sx150x.c
index a4f73534394e..a4f73534394e 100644
--- a/drivers/gpio/sx150x.c
+++ b/drivers/gpio/gpio-sx150x.c
diff --git a/drivers/gpio/tc3589x-gpio.c b/drivers/gpio/gpio-tc3589x.c
index 2a82e8999a42..2a82e8999a42 100644
--- a/drivers/gpio/tc3589x-gpio.c
+++ b/drivers/gpio/gpio-tc3589x.c
diff --git a/drivers/gpio/gpio-tegra.c b/drivers/gpio/gpio-tegra.c
new file mode 100644
index 000000000000..747eb40e8afe
--- /dev/null
+++ b/drivers/gpio/gpio-tegra.c
@@ -0,0 +1,441 @@
1/*
2 * arch/arm/mach-tegra/gpio.c
3 *
4 * Copyright (c) 2010 Google, Inc
5 *
6 * Author:
7 * Erik Gilling <konkers@google.com>
8 *
9 * This software is licensed under the terms of the GNU General Public
10 * License version 2, as published by the Free Software Foundation, and
11 * may be copied, distributed, and modified under those terms.
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 */
19
20#include <linux/init.h>
21#include <linux/irq.h>
22#include <linux/interrupt.h>
23
24#include <linux/io.h>
25#include <linux/gpio.h>
26#include <linux/of.h>
27
28#include <asm/mach/irq.h>
29
30#include <mach/iomap.h>
31#include <mach/suspend.h>
32
33#define GPIO_BANK(x) ((x) >> 5)
34#define GPIO_PORT(x) (((x) >> 3) & 0x3)
35#define GPIO_BIT(x) ((x) & 0x7)
36
37#define GPIO_REG(x) (IO_TO_VIRT(TEGRA_GPIO_BASE) + \
38 GPIO_BANK(x) * 0x80 + \
39 GPIO_PORT(x) * 4)
40
41#define GPIO_CNF(x) (GPIO_REG(x) + 0x00)
42#define GPIO_OE(x) (GPIO_REG(x) + 0x10)
43#define GPIO_OUT(x) (GPIO_REG(x) + 0X20)
44#define GPIO_IN(x) (GPIO_REG(x) + 0x30)
45#define GPIO_INT_STA(x) (GPIO_REG(x) + 0x40)
46#define GPIO_INT_ENB(x) (GPIO_REG(x) + 0x50)
47#define GPIO_INT_LVL(x) (GPIO_REG(x) + 0x60)
48#define GPIO_INT_CLR(x) (GPIO_REG(x) + 0x70)
49
50#define GPIO_MSK_CNF(x) (GPIO_REG(x) + 0x800)
51#define GPIO_MSK_OE(x) (GPIO_REG(x) + 0x810)
52#define GPIO_MSK_OUT(x) (GPIO_REG(x) + 0X820)
53#define GPIO_MSK_INT_STA(x) (GPIO_REG(x) + 0x840)
54#define GPIO_MSK_INT_ENB(x) (GPIO_REG(x) + 0x850)
55#define GPIO_MSK_INT_LVL(x) (GPIO_REG(x) + 0x860)
56
57#define GPIO_INT_LVL_MASK 0x010101
58#define GPIO_INT_LVL_EDGE_RISING 0x000101
59#define GPIO_INT_LVL_EDGE_FALLING 0x000100
60#define GPIO_INT_LVL_EDGE_BOTH 0x010100
61#define GPIO_INT_LVL_LEVEL_HIGH 0x000001
62#define GPIO_INT_LVL_LEVEL_LOW 0x000000
63
64struct tegra_gpio_bank {
65 int bank;
66 int irq;
67 spinlock_t lvl_lock[4];
68#ifdef CONFIG_PM
69 u32 cnf[4];
70 u32 out[4];
71 u32 oe[4];
72 u32 int_enb[4];
73 u32 int_lvl[4];
74#endif
75};
76
77
78static struct tegra_gpio_bank tegra_gpio_banks[] = {
79 {.bank = 0, .irq = INT_GPIO1},
80 {.bank = 1, .irq = INT_GPIO2},
81 {.bank = 2, .irq = INT_GPIO3},
82 {.bank = 3, .irq = INT_GPIO4},
83 {.bank = 4, .irq = INT_GPIO5},
84 {.bank = 5, .irq = INT_GPIO6},
85 {.bank = 6, .irq = INT_GPIO7},
86};
87
88static int tegra_gpio_compose(int bank, int port, int bit)
89{
90 return (bank << 5) | ((port & 0x3) << 3) | (bit & 0x7);
91}
92
93static void tegra_gpio_mask_write(u32 reg, int gpio, int value)
94{
95 u32 val;
96
97 val = 0x100 << GPIO_BIT(gpio);
98 if (value)
99 val |= 1 << GPIO_BIT(gpio);
100 __raw_writel(val, reg);
101}
102
103void tegra_gpio_enable(int gpio)
104{
105 tegra_gpio_mask_write(GPIO_MSK_CNF(gpio), gpio, 1);
106}
107
108void tegra_gpio_disable(int gpio)
109{
110 tegra_gpio_mask_write(GPIO_MSK_CNF(gpio), gpio, 0);
111}
112
113static void tegra_gpio_set(struct gpio_chip *chip, unsigned offset, int value)
114{
115 tegra_gpio_mask_write(GPIO_MSK_OUT(offset), offset, value);
116}
117
118static int tegra_gpio_get(struct gpio_chip *chip, unsigned offset)
119{
120 return (__raw_readl(GPIO_IN(offset)) >> GPIO_BIT(offset)) & 0x1;
121}
122
123static int tegra_gpio_direction_input(struct gpio_chip *chip, unsigned offset)
124{
125 tegra_gpio_mask_write(GPIO_MSK_OE(offset), offset, 0);
126 return 0;
127}
128
129static int tegra_gpio_direction_output(struct gpio_chip *chip, unsigned offset,
130 int value)
131{
132 tegra_gpio_set(chip, offset, value);
133 tegra_gpio_mask_write(GPIO_MSK_OE(offset), offset, 1);
134 return 0;
135}
136
137
138
139static struct gpio_chip tegra_gpio_chip = {
140 .label = "tegra-gpio",
141 .direction_input = tegra_gpio_direction_input,
142 .get = tegra_gpio_get,
143 .direction_output = tegra_gpio_direction_output,
144 .set = tegra_gpio_set,
145 .base = 0,
146 .ngpio = TEGRA_NR_GPIOS,
147};
148
149static void tegra_gpio_irq_ack(struct irq_data *d)
150{
151 int gpio = d->irq - INT_GPIO_BASE;
152
153 __raw_writel(1 << GPIO_BIT(gpio), GPIO_INT_CLR(gpio));
154}
155
156static void tegra_gpio_irq_mask(struct irq_data *d)
157{
158 int gpio = d->irq - INT_GPIO_BASE;
159
160 tegra_gpio_mask_write(GPIO_MSK_INT_ENB(gpio), gpio, 0);
161}
162
163static void tegra_gpio_irq_unmask(struct irq_data *d)
164{
165 int gpio = d->irq - INT_GPIO_BASE;
166
167 tegra_gpio_mask_write(GPIO_MSK_INT_ENB(gpio), gpio, 1);
168}
169
170static int tegra_gpio_irq_set_type(struct irq_data *d, unsigned int type)
171{
172 int gpio = d->irq - INT_GPIO_BASE;
173 struct tegra_gpio_bank *bank = irq_data_get_irq_chip_data(d);
174 int port = GPIO_PORT(gpio);
175 int lvl_type;
176 int val;
177 unsigned long flags;
178
179 switch (type & IRQ_TYPE_SENSE_MASK) {
180 case IRQ_TYPE_EDGE_RISING:
181 lvl_type = GPIO_INT_LVL_EDGE_RISING;
182 break;
183
184 case IRQ_TYPE_EDGE_FALLING:
185 lvl_type = GPIO_INT_LVL_EDGE_FALLING;
186 break;
187
188 case IRQ_TYPE_EDGE_BOTH:
189 lvl_type = GPIO_INT_LVL_EDGE_BOTH;
190 break;
191
192 case IRQ_TYPE_LEVEL_HIGH:
193 lvl_type = GPIO_INT_LVL_LEVEL_HIGH;
194 break;
195
196 case IRQ_TYPE_LEVEL_LOW:
197 lvl_type = GPIO_INT_LVL_LEVEL_LOW;
198 break;
199
200 default:
201 return -EINVAL;
202 }
203
204 spin_lock_irqsave(&bank->lvl_lock[port], flags);
205
206 val = __raw_readl(GPIO_INT_LVL(gpio));
207 val &= ~(GPIO_INT_LVL_MASK << GPIO_BIT(gpio));
208 val |= lvl_type << GPIO_BIT(gpio);
209 __raw_writel(val, GPIO_INT_LVL(gpio));
210
211 spin_unlock_irqrestore(&bank->lvl_lock[port], flags);
212
213 if (type & (IRQ_TYPE_LEVEL_LOW | IRQ_TYPE_LEVEL_HIGH))
214 __irq_set_handler_locked(d->irq, handle_level_irq);
215 else if (type & (IRQ_TYPE_EDGE_FALLING | IRQ_TYPE_EDGE_RISING))
216 __irq_set_handler_locked(d->irq, handle_edge_irq);
217
218 return 0;
219}
220
221static void tegra_gpio_irq_handler(unsigned int irq, struct irq_desc *desc)
222{
223 struct tegra_gpio_bank *bank;
224 int port;
225 int pin;
226 int unmasked = 0;
227 struct irq_chip *chip = irq_desc_get_chip(desc);
228
229 chained_irq_enter(chip, desc);
230
231 bank = irq_get_handler_data(irq);
232
233 for (port = 0; port < 4; port++) {
234 int gpio = tegra_gpio_compose(bank->bank, port, 0);
235 unsigned long sta = __raw_readl(GPIO_INT_STA(gpio)) &
236 __raw_readl(GPIO_INT_ENB(gpio));
237 u32 lvl = __raw_readl(GPIO_INT_LVL(gpio));
238
239 for_each_set_bit(pin, &sta, 8) {
240 __raw_writel(1 << pin, GPIO_INT_CLR(gpio));
241
242 /* if gpio is edge triggered, clear condition
243 * before executing the hander so that we don't
244 * miss edges
245 */
246 if (lvl & (0x100 << pin)) {
247 unmasked = 1;
248 chained_irq_exit(chip, desc);
249 }
250
251 generic_handle_irq(gpio_to_irq(gpio + pin));
252 }
253 }
254
255 if (!unmasked)
256 chained_irq_exit(chip, desc);
257
258}
259
260#ifdef CONFIG_PM
261void tegra_gpio_resume(void)
262{
263 unsigned long flags;
264 int b;
265 int p;
266
267 local_irq_save(flags);
268
269 for (b = 0; b < ARRAY_SIZE(tegra_gpio_banks); b++) {
270 struct tegra_gpio_bank *bank = &tegra_gpio_banks[b];
271
272 for (p = 0; p < ARRAY_SIZE(bank->oe); p++) {
273 unsigned int gpio = (b<<5) | (p<<3);
274 __raw_writel(bank->cnf[p], GPIO_CNF(gpio));
275 __raw_writel(bank->out[p], GPIO_OUT(gpio));
276 __raw_writel(bank->oe[p], GPIO_OE(gpio));
277 __raw_writel(bank->int_lvl[p], GPIO_INT_LVL(gpio));
278 __raw_writel(bank->int_enb[p], GPIO_INT_ENB(gpio));
279 }
280 }
281
282 local_irq_restore(flags);
283}
284
285void tegra_gpio_suspend(void)
286{
287 unsigned long flags;
288 int b;
289 int p;
290
291 local_irq_save(flags);
292 for (b = 0; b < ARRAY_SIZE(tegra_gpio_banks); b++) {
293 struct tegra_gpio_bank *bank = &tegra_gpio_banks[b];
294
295 for (p = 0; p < ARRAY_SIZE(bank->oe); p++) {
296 unsigned int gpio = (b<<5) | (p<<3);
297 bank->cnf[p] = __raw_readl(GPIO_CNF(gpio));
298 bank->out[p] = __raw_readl(GPIO_OUT(gpio));
299 bank->oe[p] = __raw_readl(GPIO_OE(gpio));
300 bank->int_enb[p] = __raw_readl(GPIO_INT_ENB(gpio));
301 bank->int_lvl[p] = __raw_readl(GPIO_INT_LVL(gpio));
302 }
303 }
304 local_irq_restore(flags);
305}
306
307static int tegra_gpio_wake_enable(struct irq_data *d, unsigned int enable)
308{
309 struct tegra_gpio_bank *bank = irq_data_get_irq_chip_data(d);
310 return irq_set_irq_wake(bank->irq, enable);
311}
312#endif
313
314static struct irq_chip tegra_gpio_irq_chip = {
315 .name = "GPIO",
316 .irq_ack = tegra_gpio_irq_ack,
317 .irq_mask = tegra_gpio_irq_mask,
318 .irq_unmask = tegra_gpio_irq_unmask,
319 .irq_set_type = tegra_gpio_irq_set_type,
320#ifdef CONFIG_PM
321 .irq_set_wake = tegra_gpio_wake_enable,
322#endif
323};
324
325
326/* This lock class tells lockdep that GPIO irqs are in a different
327 * category than their parents, so it won't report false recursion.
328 */
329static struct lock_class_key gpio_lock_class;
330
331static int __init tegra_gpio_init(void)
332{
333 struct tegra_gpio_bank *bank;
334 int i;
335 int j;
336
337 for (i = 0; i < 7; i++) {
338 for (j = 0; j < 4; j++) {
339 int gpio = tegra_gpio_compose(i, j, 0);
340 __raw_writel(0x00, GPIO_INT_ENB(gpio));
341 }
342 }
343
344#ifdef CONFIG_OF_GPIO
345 /*
346 * This isn't ideal, but it gets things hooked up until this
347 * driver is converted into a platform_device
348 */
349 tegra_gpio_chip.of_node = of_find_compatible_node(NULL, NULL,
350 "nvidia,tegra20-gpio");
351#endif /* CONFIG_OF_GPIO */
352
353 gpiochip_add(&tegra_gpio_chip);
354
355 for (i = INT_GPIO_BASE; i < (INT_GPIO_BASE + TEGRA_NR_GPIOS); i++) {
356 bank = &tegra_gpio_banks[GPIO_BANK(irq_to_gpio(i))];
357
358 irq_set_lockdep_class(i, &gpio_lock_class);
359 irq_set_chip_data(i, bank);
360 irq_set_chip_and_handler(i, &tegra_gpio_irq_chip,
361 handle_simple_irq);
362 set_irq_flags(i, IRQF_VALID);
363 }
364
365 for (i = 0; i < ARRAY_SIZE(tegra_gpio_banks); i++) {
366 bank = &tegra_gpio_banks[i];
367
368 irq_set_chained_handler(bank->irq, tegra_gpio_irq_handler);
369 irq_set_handler_data(bank->irq, bank);
370
371 for (j = 0; j < 4; j++)
372 spin_lock_init(&bank->lvl_lock[j]);
373 }
374
375 return 0;
376}
377
378postcore_initcall(tegra_gpio_init);
379
380void __init tegra_gpio_config(struct tegra_gpio_table *table, int num)
381{
382 int i;
383
384 for (i = 0; i < num; i++) {
385 int gpio = table[i].gpio;
386
387 if (table[i].enable)
388 tegra_gpio_enable(gpio);
389 else
390 tegra_gpio_disable(gpio);
391 }
392}
393
394#ifdef CONFIG_DEBUG_FS
395
396#include <linux/debugfs.h>
397#include <linux/seq_file.h>
398
399static int dbg_gpio_show(struct seq_file *s, void *unused)
400{
401 int i;
402 int j;
403
404 for (i = 0; i < 7; i++) {
405 for (j = 0; j < 4; j++) {
406 int gpio = tegra_gpio_compose(i, j, 0);
407 seq_printf(s,
408 "%d:%d %02x %02x %02x %02x %02x %02x %06x\n",
409 i, j,
410 __raw_readl(GPIO_CNF(gpio)),
411 __raw_readl(GPIO_OE(gpio)),
412 __raw_readl(GPIO_OUT(gpio)),
413 __raw_readl(GPIO_IN(gpio)),
414 __raw_readl(GPIO_INT_STA(gpio)),
415 __raw_readl(GPIO_INT_ENB(gpio)),
416 __raw_readl(GPIO_INT_LVL(gpio)));
417 }
418 }
419 return 0;
420}
421
422static int dbg_gpio_open(struct inode *inode, struct file *file)
423{
424 return single_open(file, dbg_gpio_show, &inode->i_private);
425}
426
427static const struct file_operations debug_fops = {
428 .open = dbg_gpio_open,
429 .read = seq_read,
430 .llseek = seq_lseek,
431 .release = single_release,
432};
433
434static int __init tegra_gpio_debuginit(void)
435{
436 (void) debugfs_create_file("tegra_gpio", S_IRUGO,
437 NULL, NULL, &debug_fops);
438 return 0;
439}
440late_initcall(tegra_gpio_debuginit);
441#endif
diff --git a/drivers/gpio/timbgpio.c b/drivers/gpio/gpio-timberdale.c
index 0265872e57d1..c593bd46bfb6 100644
--- a/drivers/gpio/timbgpio.c
+++ b/drivers/gpio/gpio-timberdale.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * timbgpio.c timberdale FPGA GPIO driver 2 * Timberdale FPGA GPIO driver
3 * Copyright (c) 2009 Intel Corporation 3 * Copyright (c) 2009 Intel Corporation
4 * 4 *
5 * This program is free software; you can redistribute it and/or modify 5 * This program is free software; you can redistribute it and/or modify
diff --git a/drivers/gpio/tps65910-gpio.c b/drivers/gpio/gpio-tps65910.c
index 15097ca616d6..b9c1c297669e 100644
--- a/drivers/gpio/tps65910-gpio.c
+++ b/drivers/gpio/gpio-tps65910.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * tps65910-gpio.c -- TI TPS6591x 2 * TI TPS6591x GPIO driver
3 * 3 *
4 * Copyright 2010 Texas Instruments Inc. 4 * Copyright 2010 Texas Instruments Inc.
5 * 5 *
diff --git a/drivers/gpio/twl4030-gpio.c b/drivers/gpio/gpio-twl4030.c
index 57635ac35a73..b8b4f228757c 100644
--- a/drivers/gpio/twl4030-gpio.c
+++ b/drivers/gpio/gpio-twl4030.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * twl4030_gpio.c -- access to GPIOs on TWL4030/TPS659x0 chips 2 * Access to GPIOs on TWL4030/TPS659x0 chips
3 * 3 *
4 * Copyright (C) 2006-2007 Texas Instruments, Inc. 4 * Copyright (C) 2006-2007 Texas Instruments, Inc.
5 * Copyright (C) 2006 MontaVista Software, Inc. 5 * Copyright (C) 2006 MontaVista Software, Inc.
diff --git a/drivers/gpio/gpio-u300.c b/drivers/gpio/gpio-u300.c
index d92790140fe5..fd2dfeeefdf3 100644
--- a/drivers/gpio/gpio-u300.c
+++ b/drivers/gpio/gpio-u300.c
@@ -1,11 +1,8 @@
1/* 1/*
2 * 2 * U300 GPIO module.
3 * arch/arm/mach-u300/gpio.c
4 *
5 * 3 *
6 * Copyright (C) 2007-2009 ST-Ericsson AB 4 * Copyright (C) 2007-2009 ST-Ericsson AB
7 * License terms: GNU General Public License (GPL) version 2 5 * License terms: GNU General Public License (GPL) version 2
8 * U300 GPIO module.
9 * This can driver either of the two basic GPIO cores 6 * This can driver either of the two basic GPIO cores
10 * available in the U300 platforms: 7 * available in the U300 platforms:
11 * COH 901 335 - Used in DB3150 (U300 1.0) and DB3200 (U330 1.0) 8 * COH 901 335 - Used in DB3150 (U300 1.0) and DB3200 (U330 1.0)
diff --git a/drivers/gpio/ucb1400_gpio.c b/drivers/gpio/gpio-ucb1400.c
index 50e6bd1392ce..50e6bd1392ce 100644
--- a/drivers/gpio/ucb1400_gpio.c
+++ b/drivers/gpio/gpio-ucb1400.c
diff --git a/drivers/gpio/vr41xx_giu.c b/drivers/gpio/gpio-vr41xx.c
index a365be040b36..98723cb9ac68 100644
--- a/drivers/gpio/vr41xx_giu.c
+++ b/drivers/gpio/gpio-vr41xx.c
@@ -518,7 +518,7 @@ static int __devinit giu_probe(struct platform_device *pdev)
518 if (!res) 518 if (!res)
519 return -EBUSY; 519 return -EBUSY;
520 520
521 giu_base = ioremap(res->start, res->end - res->start + 1); 521 giu_base = ioremap(res->start, resource_size(res));
522 if (!giu_base) 522 if (!giu_base)
523 return -ENOMEM; 523 return -ENOMEM;
524 524
diff --git a/drivers/gpio/vx855_gpio.c b/drivers/gpio/gpio-vx855.c
index ef5aabd8b8b7..ef5aabd8b8b7 100644
--- a/drivers/gpio/vx855_gpio.c
+++ b/drivers/gpio/gpio-vx855.c
diff --git a/drivers/gpio/wm831x-gpio.c b/drivers/gpio/gpio-wm831x.c
index 2bcfb0be09ff..deb949e75ec1 100644
--- a/drivers/gpio/wm831x-gpio.c
+++ b/drivers/gpio/gpio-wm831x.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * wm831x-gpio.c -- gpiolib support for Wolfson WM831x PMICs 2 * gpiolib support for Wolfson WM831x PMICs
3 * 3 *
4 * Copyright 2009 Wolfson Microelectronics PLC. 4 * Copyright 2009 Wolfson Microelectronics PLC.
5 * 5 *
diff --git a/drivers/gpio/wm8350-gpiolib.c b/drivers/gpio/gpio-wm8350.c
index 359999290f55..a06af5154838 100644
--- a/drivers/gpio/wm8350-gpiolib.c
+++ b/drivers/gpio/gpio-wm8350.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * wm835x-gpiolib.c -- gpiolib support for Wolfson WM835x PMICs 2 * gpiolib support for Wolfson WM835x PMICs
3 * 3 *
4 * Copyright 2009 Wolfson Microelectronics PLC. 4 * Copyright 2009 Wolfson Microelectronics PLC.
5 * 5 *
diff --git a/drivers/gpio/wm8994-gpio.c b/drivers/gpio/gpio-wm8994.c
index c822baacd8fc..96198f3fab73 100644
--- a/drivers/gpio/wm8994-gpio.c
+++ b/drivers/gpio/gpio-wm8994.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * wm8994-gpio.c -- gpiolib support for Wolfson WM8994 2 * gpiolib support for Wolfson WM8994
3 * 3 *
4 * Copyright 2009 Wolfson Microelectronics PLC. 4 * Copyright 2009 Wolfson Microelectronics PLC.
5 * 5 *
diff --git a/drivers/gpio/xilinx_gpio.c b/drivers/gpio/gpio-xilinx.c
index 846fbd5e31bf..846fbd5e31bf 100644
--- a/drivers/gpio/xilinx_gpio.c
+++ b/drivers/gpio/gpio-xilinx.c