diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2012-10-02 19:05:10 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2012-10-02 19:05:10 -0400 |
commit | dff8360a4a079692e65e55fbaa6c5dc605528403 (patch) | |
tree | 0ab8ef7595cdfb918b3fd9a8364c6ea6c9c2798f | |
parent | 916082b073ebb7f4e064cebce0768e34cacde508 (diff) | |
parent | 901acf5b2910434501c221a363bb3486b647b5c4 (diff) |
Merge tag 'gpio-for-v3.7' of git://git.kernel.org/pub/scm/linux/kernel/git/linusw/linux-gpio
Pull GPIO changes from Linus Walleij:
"So this is the LW GPIO patch stack for v3.7:
- refactoring from Thierry Redding at Arnd Bergmann's request to use
the seq_file iterator interface in gpiolib.
- A new driver for Avionic Design's N-bit GPIO expander.
- Two instances of mutexes replaced by spinlocks from Axel Lin to
code that is supposed to be fastpath compliant.
- IRQ demuxer and gpio_to_irq() support for pcf857x by Kuninori
Morimoto.
- Dynamic GPIO numbers, device tree support, daisy chaining and some
other fixes for the 74x164 driver by Maxime Ripard.
- IRQ domain and device tree support for the tc3589x driver by Lee
Jones.
- Some conversion to use managed resources devm_* code.
- Some instances of clk_prepare() or clk_prepare_enable() added to
support the new, stricter common clock framework.
- Some for_each_set_bit() simplifications.
- Then a lot of fixes as we fixed up all of the above tripping over
our own shoelaces and that kind of thing."
* tag 'gpio-for-v3.7' of git://git.kernel.org/pub/scm/linux/kernel/git/linusw/linux-gpio: (34 commits)
gpio: pcf857x: select IRQ_DOMAIN
gpio: Document device_node's det_debounce
gpio-lpc32xx: Add GPI_28
gpio: adnp: dt: Reference generic interrupt binding
gpio: Add Avionic Design N-bit GPIO expander support
gpio: pxa: using for_each_set_bit to simplify the code
gpio_msm: using for_each_set_bit to simplify the code
gpio: Enable the tc3298x GPIO expander driver for Device Tree
gpio: Provide the tc3589x GPIO expander driver with an IRQ domain
ARM: shmobile: kzm9g: use gpio-keys instead of gpio-keys-polled
gpio: pcf857x: fixup smatch WARNING
gpio: 74x164: Add support for the daisy-chaining
gpio: 74x164: dts: Add documentation for the dt binding
dt: Fix incorrect reference in gpio-led documentation
gpio: 74x164: Add device tree support
gpio: 74x164: Use dynamic gpio number assignment if no pdata is present
gpio: 74x164: Use devm_kzalloc
gpio: 74x164: Use module_spi_driver boiler plate function
gpio: sx150x: Use irq_data_get_irq_chip_data() at appropriate places
gpio: em: Use irq_data_get_irq_chip_data() at appropriate places
...
30 files changed, 1104 insertions, 248 deletions
diff --git a/Documentation/devicetree/bindings/gpio/gpio-74x164.txt b/Documentation/devicetree/bindings/gpio/gpio-74x164.txt new file mode 100644 index 00000000000..cc2608021f2 --- /dev/null +++ b/Documentation/devicetree/bindings/gpio/gpio-74x164.txt | |||
@@ -0,0 +1,22 @@ | |||
1 | * Generic 8-bits shift register GPIO driver | ||
2 | |||
3 | Required properties: | ||
4 | - compatible : Should be "fairchild,74hc595" | ||
5 | - reg : chip select number | ||
6 | - gpio-controller : Marks the device node as a gpio controller. | ||
7 | - #gpio-cells : Should be two. The first cell is the pin number and | ||
8 | the second cell is used to specify the gpio polarity: | ||
9 | 0 = active high | ||
10 | 1 = active low | ||
11 | - registers-number: Number of daisy-chained shift registers | ||
12 | |||
13 | Example: | ||
14 | |||
15 | gpio5: gpio5@0 { | ||
16 | compatible = "fairchild,74hc595"; | ||
17 | reg = <0>; | ||
18 | gpio-controller; | ||
19 | #gpio-cells = <2>; | ||
20 | registers-number = <4>; | ||
21 | spi-max-frequency = <100000>; | ||
22 | }; | ||
diff --git a/Documentation/devicetree/bindings/gpio/gpio-adnp.txt b/Documentation/devicetree/bindings/gpio/gpio-adnp.txt new file mode 100644 index 00000000000..af66b272483 --- /dev/null +++ b/Documentation/devicetree/bindings/gpio/gpio-adnp.txt | |||
@@ -0,0 +1,34 @@ | |||
1 | Avionic Design N-bit GPIO expander bindings | ||
2 | |||
3 | Required properties: | ||
4 | - compatible: should be "ad,gpio-adnp" | ||
5 | - reg: The I2C slave address for this device. | ||
6 | - interrupt-parent: phandle of the parent interrupt controller. | ||
7 | - interrupts: Interrupt specifier for the controllers interrupt. | ||
8 | - #gpio-cells: Should be 2. The first cell is the GPIO number and the | ||
9 | second cell is used to specify optional parameters: | ||
10 | - bit 0: polarity (0: normal, 1: inverted) | ||
11 | - gpio-controller: Marks the device as a GPIO controller | ||
12 | - nr-gpios: The number of pins supported by the controller. | ||
13 | |||
14 | The GPIO expander can optionally be used as an interrupt controller, in | ||
15 | which case it uses the default two cell specifier as described in | ||
16 | Documentation/devicetree/bindings/interrupt-controller/interrupts.txt. | ||
17 | |||
18 | Example: | ||
19 | |||
20 | gpioext: gpio-controller@41 { | ||
21 | compatible = "ad,gpio-adnp"; | ||
22 | reg = <0x41>; | ||
23 | |||
24 | interrupt-parent = <&gpio>; | ||
25 | interrupts = <160 1>; | ||
26 | |||
27 | gpio-controller; | ||
28 | #gpio-cells = <2>; | ||
29 | |||
30 | interrupt-controller; | ||
31 | #interrupt-cells = <2>; | ||
32 | |||
33 | nr-gpios = <64>; | ||
34 | }; | ||
diff --git a/Documentation/devicetree/bindings/gpio/led.txt b/Documentation/devicetree/bindings/gpio/led.txt index 9bb308abd22..edc83c1c0d5 100644 --- a/Documentation/devicetree/bindings/gpio/led.txt +++ b/Documentation/devicetree/bindings/gpio/led.txt | |||
@@ -8,7 +8,7 @@ node's name represents the name of the corresponding LED. | |||
8 | 8 | ||
9 | LED sub-node properties: | 9 | LED sub-node properties: |
10 | - gpios : Should specify the LED's GPIO, see "gpios property" in | 10 | - gpios : Should specify the LED's GPIO, see "gpios property" in |
11 | Documentation/devicetree/gpio.txt. Active low LEDs should be | 11 | Documentation/devicetree/bindings/gpio/gpio.txt. Active low LEDs should be |
12 | indicated using flags in the GPIO specifier. | 12 | indicated using flags in the GPIO specifier. |
13 | - label : (optional) The label for this LED. If omitted, the label is | 13 | - label : (optional) The label for this LED. If omitted, the label is |
14 | taken from the node name (excluding the unit address). | 14 | taken from the node name (excluding the unit address). |
diff --git a/arch/arm/configs/kzm9g_defconfig b/arch/arm/configs/kzm9g_defconfig index 5d0c6670896..c88b57886e7 100644 --- a/arch/arm/configs/kzm9g_defconfig +++ b/arch/arm/configs/kzm9g_defconfig | |||
@@ -23,7 +23,6 @@ CONFIG_MODULE_UNLOAD=y | |||
23 | # CONFIG_IOSCHED_DEADLINE is not set | 23 | # CONFIG_IOSCHED_DEADLINE is not set |
24 | # CONFIG_IOSCHED_CFQ is not set | 24 | # CONFIG_IOSCHED_CFQ is not set |
25 | CONFIG_ARCH_SHMOBILE=y | 25 | CONFIG_ARCH_SHMOBILE=y |
26 | CONFIG_KEYBOARD_GPIO_POLLED=y | ||
27 | CONFIG_ARCH_SH73A0=y | 26 | CONFIG_ARCH_SH73A0=y |
28 | CONFIG_MACH_KZM9G=y | 27 | CONFIG_MACH_KZM9G=y |
29 | CONFIG_MEMORY_START=0x41000000 | 28 | CONFIG_MEMORY_START=0x41000000 |
@@ -71,6 +70,7 @@ CONFIG_INPUT_SPARSEKMAP=y | |||
71 | # CONFIG_INPUT_MOUSEDEV is not set | 70 | # CONFIG_INPUT_MOUSEDEV is not set |
72 | CONFIG_INPUT_EVDEV=y | 71 | CONFIG_INPUT_EVDEV=y |
73 | # CONFIG_KEYBOARD_ATKBD is not set | 72 | # CONFIG_KEYBOARD_ATKBD is not set |
73 | CONFIG_KEYBOARD_GPIO=y | ||
74 | # CONFIG_INPUT_MOUSE is not set | 74 | # CONFIG_INPUT_MOUSE is not set |
75 | CONFIG_INPUT_TOUCHSCREEN=y | 75 | CONFIG_INPUT_TOUCHSCREEN=y |
76 | CONFIG_TOUCHSCREEN_ST1232=y | 76 | CONFIG_TOUCHSCREEN_ST1232=y |
diff --git a/arch/arm/mach-shmobile/board-kzm9g.c b/arch/arm/mach-shmobile/board-kzm9g.c index 773a2b95a4e..0a43f3189c2 100644 --- a/arch/arm/mach-shmobile/board-kzm9g.c +++ b/arch/arm/mach-shmobile/board-kzm9g.c | |||
@@ -482,12 +482,10 @@ static struct gpio_keys_button gpio_buttons[] = { | |||
482 | static struct gpio_keys_platform_data gpio_key_info = { | 482 | static struct gpio_keys_platform_data gpio_key_info = { |
483 | .buttons = gpio_buttons, | 483 | .buttons = gpio_buttons, |
484 | .nbuttons = ARRAY_SIZE(gpio_buttons), | 484 | .nbuttons = ARRAY_SIZE(gpio_buttons), |
485 | .poll_interval = 250, /* poling at this point */ | ||
486 | }; | 485 | }; |
487 | 486 | ||
488 | static struct platform_device gpio_keys_device = { | 487 | static struct platform_device gpio_keys_device = { |
489 | /* gpio-pcf857x.c driver doesn't support gpio_to_irq() */ | 488 | .name = "gpio-keys", |
490 | .name = "gpio-keys-polled", | ||
491 | .dev = { | 489 | .dev = { |
492 | .platform_data = &gpio_key_info, | 490 | .platform_data = &gpio_key_info, |
493 | }, | 491 | }, |
@@ -550,6 +548,7 @@ static struct platform_device fsi_ak4648_device = { | |||
550 | /* I2C */ | 548 | /* I2C */ |
551 | static struct pcf857x_platform_data pcf8575_pdata = { | 549 | static struct pcf857x_platform_data pcf8575_pdata = { |
552 | .gpio_base = GPIO_PCF8575_BASE, | 550 | .gpio_base = GPIO_PCF8575_BASE, |
551 | .irq = intcs_evt2irq(0x3260), /* IRQ19 */ | ||
553 | }; | 552 | }; |
554 | 553 | ||
555 | static struct i2c_board_info i2c0_devices[] = { | 554 | static struct i2c_board_info i2c0_devices[] = { |
diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig index a00b828b164..8382dc83292 100644 --- a/drivers/gpio/Kconfig +++ b/drivers/gpio/Kconfig | |||
@@ -82,7 +82,7 @@ config GPIO_GENERIC | |||
82 | 82 | ||
83 | config GPIO_DA9052 | 83 | config GPIO_DA9052 |
84 | tristate "Dialog DA9052 GPIO" | 84 | tristate "Dialog DA9052 GPIO" |
85 | depends on PMIC_DA9052 && BROKEN | 85 | depends on PMIC_DA9052 |
86 | help | 86 | help |
87 | Say yes here to enable the GPIO driver for the DA9052 chip. | 87 | Say yes here to enable the GPIO driver for the DA9052 chip. |
88 | 88 | ||
@@ -330,6 +330,7 @@ config GPIO_PCA953X_IRQ | |||
330 | config GPIO_PCF857X | 330 | config GPIO_PCF857X |
331 | tristate "PCF857x, PCA{85,96}7x, and MAX732[89] I2C GPIO expanders" | 331 | tristate "PCF857x, PCA{85,96}7x, and MAX732[89] I2C GPIO expanders" |
332 | depends on I2C | 332 | depends on I2C |
333 | select IRQ_DOMAIN | ||
333 | help | 334 | help |
334 | Say yes here to provide access to most "quasi-bidirectional" I2C | 335 | Say yes here to provide access to most "quasi-bidirectional" I2C |
335 | GPIO expanders used for additional digital outputs or inputs. | 336 | GPIO expanders used for additional digital outputs or inputs. |
@@ -450,6 +451,17 @@ config GPIO_ADP5588_IRQ | |||
450 | Say yes here to enable the adp5588 to be used as an interrupt | 451 | Say yes here to enable the adp5588 to be used as an interrupt |
451 | controller. It requires the driver to be built in the kernel. | 452 | controller. It requires the driver to be built in the kernel. |
452 | 453 | ||
454 | config GPIO_ADNP | ||
455 | tristate "Avionic Design N-bit GPIO expander" | ||
456 | depends on I2C && OF | ||
457 | help | ||
458 | This option enables support for N GPIOs found on Avionic Design | ||
459 | I2C GPIO expanders. The register space will be extended by powers | ||
460 | of two, so the controller will need to accomodate for that. For | ||
461 | example: if a controller provides 48 pins, 6 registers will be | ||
462 | enough to represent all pins, but the driver will assume a | ||
463 | register layout for 64 pins (8 registers). | ||
464 | |||
453 | comment "PCI GPIO expanders:" | 465 | comment "PCI GPIO expanders:" |
454 | 466 | ||
455 | config GPIO_CS5535 | 467 | config GPIO_CS5535 |
diff --git a/drivers/gpio/Makefile b/drivers/gpio/Makefile index a288142ad99..0ffaa8423e8 100644 --- a/drivers/gpio/Makefile +++ b/drivers/gpio/Makefile | |||
@@ -10,6 +10,7 @@ obj-$(CONFIG_GPIO_GENERIC) += gpio-generic.o | |||
10 | 10 | ||
11 | obj-$(CONFIG_GPIO_74X164) += gpio-74x164.o | 11 | obj-$(CONFIG_GPIO_74X164) += gpio-74x164.o |
12 | obj-$(CONFIG_GPIO_AB8500) += gpio-ab8500.o | 12 | obj-$(CONFIG_GPIO_AB8500) += gpio-ab8500.o |
13 | obj-$(CONFIG_GPIO_ADNP) += gpio-adnp.o | ||
13 | obj-$(CONFIG_GPIO_ADP5520) += gpio-adp5520.o | 14 | obj-$(CONFIG_GPIO_ADP5520) += gpio-adp5520.o |
14 | obj-$(CONFIG_GPIO_ADP5588) += gpio-adp5588.o | 15 | obj-$(CONFIG_GPIO_ADP5588) += gpio-adp5588.o |
15 | obj-$(CONFIG_GPIO_AMD8111) += gpio-amd8111.o | 16 | obj-$(CONFIG_GPIO_AMD8111) += gpio-amd8111.o |
diff --git a/drivers/gpio/gpio-74x164.c b/drivers/gpio/gpio-74x164.c index a31ad6f5d91..ed3e55161bd 100644 --- a/drivers/gpio/gpio-74x164.c +++ b/drivers/gpio/gpio-74x164.c | |||
@@ -14,14 +14,18 @@ | |||
14 | #include <linux/spi/spi.h> | 14 | #include <linux/spi/spi.h> |
15 | #include <linux/spi/74x164.h> | 15 | #include <linux/spi/74x164.h> |
16 | #include <linux/gpio.h> | 16 | #include <linux/gpio.h> |
17 | #include <linux/of_gpio.h> | ||
17 | #include <linux/slab.h> | 18 | #include <linux/slab.h> |
18 | #include <linux/module.h> | 19 | #include <linux/module.h> |
19 | 20 | ||
21 | #define GEN_74X164_NUMBER_GPIOS 8 | ||
22 | |||
20 | struct gen_74x164_chip { | 23 | struct gen_74x164_chip { |
21 | struct spi_device *spi; | 24 | struct spi_device *spi; |
25 | u8 *buffer; | ||
22 | struct gpio_chip gpio_chip; | 26 | struct gpio_chip gpio_chip; |
23 | struct mutex lock; | 27 | struct mutex lock; |
24 | u8 port_config; | 28 | u32 registers; |
25 | }; | 29 | }; |
26 | 30 | ||
27 | static struct gen_74x164_chip *gpio_to_74x164_chip(struct gpio_chip *gc) | 31 | static struct gen_74x164_chip *gpio_to_74x164_chip(struct gpio_chip *gc) |
@@ -31,17 +35,47 @@ static struct gen_74x164_chip *gpio_to_74x164_chip(struct gpio_chip *gc) | |||
31 | 35 | ||
32 | static int __gen_74x164_write_config(struct gen_74x164_chip *chip) | 36 | static int __gen_74x164_write_config(struct gen_74x164_chip *chip) |
33 | { | 37 | { |
34 | return spi_write(chip->spi, | 38 | struct spi_message message; |
35 | &chip->port_config, sizeof(chip->port_config)); | 39 | struct spi_transfer *msg_buf; |
40 | int i, ret = 0; | ||
41 | |||
42 | msg_buf = kzalloc(chip->registers * sizeof(struct spi_transfer), | ||
43 | GFP_KERNEL); | ||
44 | if (!msg_buf) | ||
45 | return -ENOMEM; | ||
46 | |||
47 | spi_message_init(&message); | ||
48 | |||
49 | /* | ||
50 | * Since the registers are chained, every byte sent will make | ||
51 | * the previous byte shift to the next register in the | ||
52 | * chain. Thus, the first byte send will end up in the last | ||
53 | * register at the end of the transfer. So, to have a logical | ||
54 | * numbering, send the bytes in reverse order so that the last | ||
55 | * byte of the buffer will end up in the last register. | ||
56 | */ | ||
57 | for (i = chip->registers - 1; i >= 0; i--) { | ||
58 | msg_buf[i].tx_buf = chip->buffer +i; | ||
59 | msg_buf[i].len = sizeof(u8); | ||
60 | spi_message_add_tail(msg_buf + i, &message); | ||
61 | } | ||
62 | |||
63 | ret = spi_sync(chip->spi, &message); | ||
64 | |||
65 | kfree(msg_buf); | ||
66 | |||
67 | return ret; | ||
36 | } | 68 | } |
37 | 69 | ||
38 | static int gen_74x164_get_value(struct gpio_chip *gc, unsigned offset) | 70 | static int gen_74x164_get_value(struct gpio_chip *gc, unsigned offset) |
39 | { | 71 | { |
40 | struct gen_74x164_chip *chip = gpio_to_74x164_chip(gc); | 72 | struct gen_74x164_chip *chip = gpio_to_74x164_chip(gc); |
73 | u8 bank = offset / 8; | ||
74 | u8 pin = offset % 8; | ||
41 | int ret; | 75 | int ret; |
42 | 76 | ||
43 | mutex_lock(&chip->lock); | 77 | mutex_lock(&chip->lock); |
44 | ret = (chip->port_config >> offset) & 0x1; | 78 | ret = (chip->buffer[bank] >> pin) & 0x1; |
45 | mutex_unlock(&chip->lock); | 79 | mutex_unlock(&chip->lock); |
46 | 80 | ||
47 | return ret; | 81 | return ret; |
@@ -51,12 +85,14 @@ static void gen_74x164_set_value(struct gpio_chip *gc, | |||
51 | unsigned offset, int val) | 85 | unsigned offset, int val) |
52 | { | 86 | { |
53 | struct gen_74x164_chip *chip = gpio_to_74x164_chip(gc); | 87 | struct gen_74x164_chip *chip = gpio_to_74x164_chip(gc); |
88 | u8 bank = offset / 8; | ||
89 | u8 pin = offset % 8; | ||
54 | 90 | ||
55 | mutex_lock(&chip->lock); | 91 | mutex_lock(&chip->lock); |
56 | if (val) | 92 | if (val) |
57 | chip->port_config |= (1 << offset); | 93 | chip->buffer[bank] |= (1 << pin); |
58 | else | 94 | else |
59 | chip->port_config &= ~(1 << offset); | 95 | chip->buffer[bank] &= ~(1 << pin); |
60 | 96 | ||
61 | __gen_74x164_write_config(chip); | 97 | __gen_74x164_write_config(chip); |
62 | mutex_unlock(&chip->lock); | 98 | mutex_unlock(&chip->lock); |
@@ -75,9 +111,8 @@ static int __devinit gen_74x164_probe(struct spi_device *spi) | |||
75 | struct gen_74x164_chip_platform_data *pdata; | 111 | struct gen_74x164_chip_platform_data *pdata; |
76 | int ret; | 112 | int ret; |
77 | 113 | ||
78 | pdata = spi->dev.platform_data; | 114 | if (!spi->dev.of_node) { |
79 | if (!pdata || !pdata->base) { | 115 | dev_err(&spi->dev, "No device tree data available.\n"); |
80 | dev_dbg(&spi->dev, "incorrect or missing platform data\n"); | ||
81 | return -EINVAL; | 116 | return -EINVAL; |
82 | } | 117 | } |
83 | 118 | ||
@@ -90,10 +125,16 @@ static int __devinit gen_74x164_probe(struct spi_device *spi) | |||
90 | if (ret < 0) | 125 | if (ret < 0) |
91 | return ret; | 126 | return ret; |
92 | 127 | ||
93 | chip = kzalloc(sizeof(*chip), GFP_KERNEL); | 128 | chip = devm_kzalloc(&spi->dev, sizeof(*chip), GFP_KERNEL); |
94 | if (!chip) | 129 | if (!chip) |
95 | return -ENOMEM; | 130 | return -ENOMEM; |
96 | 131 | ||
132 | pdata = spi->dev.platform_data; | ||
133 | if (pdata && pdata->base) | ||
134 | chip->gpio_chip.base = pdata->base; | ||
135 | else | ||
136 | chip->gpio_chip.base = -1; | ||
137 | |||
97 | mutex_init(&chip->lock); | 138 | mutex_init(&chip->lock); |
98 | 139 | ||
99 | dev_set_drvdata(&spi->dev, chip); | 140 | dev_set_drvdata(&spi->dev, chip); |
@@ -104,8 +145,20 @@ static int __devinit gen_74x164_probe(struct spi_device *spi) | |||
104 | chip->gpio_chip.direction_output = gen_74x164_direction_output; | 145 | chip->gpio_chip.direction_output = gen_74x164_direction_output; |
105 | chip->gpio_chip.get = gen_74x164_get_value; | 146 | chip->gpio_chip.get = gen_74x164_get_value; |
106 | chip->gpio_chip.set = gen_74x164_set_value; | 147 | chip->gpio_chip.set = gen_74x164_set_value; |
107 | chip->gpio_chip.base = pdata->base; | 148 | |
108 | chip->gpio_chip.ngpio = 8; | 149 | if (of_property_read_u32(spi->dev.of_node, "registers-number", &chip->registers)) { |
150 | dev_err(&spi->dev, "Missing registers-number property in the DT.\n"); | ||
151 | ret = -EINVAL; | ||
152 | goto exit_destroy; | ||
153 | } | ||
154 | |||
155 | chip->gpio_chip.ngpio = GEN_74X164_NUMBER_GPIOS * chip->registers; | ||
156 | chip->buffer = devm_kzalloc(&spi->dev, chip->gpio_chip.ngpio, GFP_KERNEL); | ||
157 | if (!chip->buffer) { | ||
158 | ret = -ENOMEM; | ||
159 | goto exit_destroy; | ||
160 | } | ||
161 | |||
109 | chip->gpio_chip.can_sleep = 1; | 162 | chip->gpio_chip.can_sleep = 1; |
110 | chip->gpio_chip.dev = &spi->dev; | 163 | chip->gpio_chip.dev = &spi->dev; |
111 | chip->gpio_chip.owner = THIS_MODULE; | 164 | chip->gpio_chip.owner = THIS_MODULE; |
@@ -125,7 +178,6 @@ static int __devinit gen_74x164_probe(struct spi_device *spi) | |||
125 | exit_destroy: | 178 | exit_destroy: |
126 | dev_set_drvdata(&spi->dev, NULL); | 179 | dev_set_drvdata(&spi->dev, NULL); |
127 | mutex_destroy(&chip->lock); | 180 | mutex_destroy(&chip->lock); |
128 | kfree(chip); | ||
129 | return ret; | 181 | return ret; |
130 | } | 182 | } |
131 | 183 | ||
@@ -141,36 +193,31 @@ static int __devexit gen_74x164_remove(struct spi_device *spi) | |||
141 | dev_set_drvdata(&spi->dev, NULL); | 193 | dev_set_drvdata(&spi->dev, NULL); |
142 | 194 | ||
143 | ret = gpiochip_remove(&chip->gpio_chip); | 195 | ret = gpiochip_remove(&chip->gpio_chip); |
144 | if (!ret) { | 196 | if (!ret) |
145 | mutex_destroy(&chip->lock); | 197 | mutex_destroy(&chip->lock); |
146 | kfree(chip); | 198 | else |
147 | } else | ||
148 | dev_err(&spi->dev, "Failed to remove the GPIO controller: %d\n", | 199 | dev_err(&spi->dev, "Failed to remove the GPIO controller: %d\n", |
149 | ret); | 200 | ret); |
150 | 201 | ||
151 | return ret; | 202 | return ret; |
152 | } | 203 | } |
153 | 204 | ||
205 | static const struct of_device_id gen_74x164_dt_ids[] = { | ||
206 | { .compatible = "fairchild,74hc595" }, | ||
207 | {}, | ||
208 | }; | ||
209 | MODULE_DEVICE_TABLE(of, gen_74x164_dt_ids); | ||
210 | |||
154 | static struct spi_driver gen_74x164_driver = { | 211 | static struct spi_driver gen_74x164_driver = { |
155 | .driver = { | 212 | .driver = { |
156 | .name = "74x164", | 213 | .name = "74x164", |
157 | .owner = THIS_MODULE, | 214 | .owner = THIS_MODULE, |
215 | .of_match_table = of_match_ptr(gen_74x164_dt_ids), | ||
158 | }, | 216 | }, |
159 | .probe = gen_74x164_probe, | 217 | .probe = gen_74x164_probe, |
160 | .remove = __devexit_p(gen_74x164_remove), | 218 | .remove = __devexit_p(gen_74x164_remove), |
161 | }; | 219 | }; |
162 | 220 | module_spi_driver(gen_74x164_driver); | |
163 | static int __init gen_74x164_init(void) | ||
164 | { | ||
165 | return spi_register_driver(&gen_74x164_driver); | ||
166 | } | ||
167 | subsys_initcall(gen_74x164_init); | ||
168 | |||
169 | static void __exit gen_74x164_exit(void) | ||
170 | { | ||
171 | spi_unregister_driver(&gen_74x164_driver); | ||
172 | } | ||
173 | module_exit(gen_74x164_exit); | ||
174 | 221 | ||
175 | MODULE_AUTHOR("Gabor Juhos <juhosg@openwrt.org>"); | 222 | MODULE_AUTHOR("Gabor Juhos <juhosg@openwrt.org>"); |
176 | MODULE_AUTHOR("Miguel Gaio <miguel.gaio@efixo.com>"); | 223 | MODULE_AUTHOR("Miguel Gaio <miguel.gaio@efixo.com>"); |
diff --git a/drivers/gpio/gpio-adnp.c b/drivers/gpio/gpio-adnp.c new file mode 100644 index 00000000000..3df88336415 --- /dev/null +++ b/drivers/gpio/gpio-adnp.c | |||
@@ -0,0 +1,611 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2011-2012 Avionic Design GmbH | ||
3 | * | ||
4 | * This program is free software; you can redistribute it and/or modify | ||
5 | * it under the terms of the GNU General Public License version 2 as | ||
6 | * published by the Free Software Foundation. | ||
7 | */ | ||
8 | |||
9 | #include <linux/gpio.h> | ||
10 | #include <linux/i2c.h> | ||
11 | #include <linux/interrupt.h> | ||
12 | #include <linux/irqdomain.h> | ||
13 | #include <linux/module.h> | ||
14 | #include <linux/of_irq.h> | ||
15 | #include <linux/seq_file.h> | ||
16 | #include <linux/slab.h> | ||
17 | |||
18 | #define GPIO_DDR(gpio) (0x00 << (gpio)->reg_shift) | ||
19 | #define GPIO_PLR(gpio) (0x01 << (gpio)->reg_shift) | ||
20 | #define GPIO_IER(gpio) (0x02 << (gpio)->reg_shift) | ||
21 | #define GPIO_ISR(gpio) (0x03 << (gpio)->reg_shift) | ||
22 | #define GPIO_PTR(gpio) (0x04 << (gpio)->reg_shift) | ||
23 | |||
24 | struct adnp { | ||
25 | struct i2c_client *client; | ||
26 | struct gpio_chip gpio; | ||
27 | unsigned int reg_shift; | ||
28 | |||
29 | struct mutex i2c_lock; | ||
30 | |||
31 | struct irq_domain *domain; | ||
32 | struct mutex irq_lock; | ||
33 | |||
34 | u8 *irq_enable; | ||
35 | u8 *irq_level; | ||
36 | u8 *irq_rise; | ||
37 | u8 *irq_fall; | ||
38 | u8 *irq_high; | ||
39 | u8 *irq_low; | ||
40 | }; | ||
41 | |||
42 | static inline struct adnp *to_adnp(struct gpio_chip *chip) | ||
43 | { | ||
44 | return container_of(chip, struct adnp, gpio); | ||
45 | } | ||
46 | |||
47 | static int adnp_read(struct adnp *adnp, unsigned offset, uint8_t *value) | ||
48 | { | ||
49 | int err; | ||
50 | |||
51 | err = i2c_smbus_read_byte_data(adnp->client, offset); | ||
52 | if (err < 0) { | ||
53 | dev_err(adnp->gpio.dev, "%s failed: %d\n", | ||
54 | "i2c_smbus_read_byte_data()", err); | ||
55 | return err; | ||
56 | } | ||
57 | |||
58 | *value = err; | ||
59 | return 0; | ||
60 | } | ||
61 | |||
62 | static int adnp_write(struct adnp *adnp, unsigned offset, uint8_t value) | ||
63 | { | ||
64 | int err; | ||
65 | |||
66 | err = i2c_smbus_write_byte_data(adnp->client, offset, value); | ||
67 | if (err < 0) { | ||
68 | dev_err(adnp->gpio.dev, "%s failed: %d\n", | ||
69 | "i2c_smbus_write_byte_data()", err); | ||
70 | return err; | ||
71 | } | ||
72 | |||
73 | return 0; | ||
74 | } | ||
75 | |||
76 | static int adnp_gpio_get(struct gpio_chip *chip, unsigned offset) | ||
77 | { | ||
78 | struct adnp *adnp = to_adnp(chip); | ||
79 | unsigned int reg = offset >> adnp->reg_shift; | ||
80 | unsigned int pos = offset & 7; | ||
81 | u8 value; | ||
82 | int err; | ||
83 | |||
84 | err = adnp_read(adnp, GPIO_PLR(adnp) + reg, &value); | ||
85 | if (err < 0) | ||
86 | return err; | ||
87 | |||
88 | return (value & BIT(pos)) ? 1 : 0; | ||
89 | } | ||
90 | |||
91 | static void __adnp_gpio_set(struct adnp *adnp, unsigned offset, int value) | ||
92 | { | ||
93 | unsigned int reg = offset >> adnp->reg_shift; | ||
94 | unsigned int pos = offset & 7; | ||
95 | int err; | ||
96 | u8 val; | ||
97 | |||
98 | err = adnp_read(adnp, GPIO_PLR(adnp) + reg, &val); | ||
99 | if (err < 0) | ||
100 | return; | ||
101 | |||
102 | if (value) | ||
103 | val |= BIT(pos); | ||
104 | else | ||
105 | val &= ~BIT(pos); | ||
106 | |||
107 | adnp_write(adnp, GPIO_PLR(adnp) + reg, val); | ||
108 | } | ||
109 | |||
110 | static void adnp_gpio_set(struct gpio_chip *chip, unsigned offset, int value) | ||
111 | { | ||
112 | struct adnp *adnp = to_adnp(chip); | ||
113 | |||
114 | mutex_lock(&adnp->i2c_lock); | ||
115 | __adnp_gpio_set(adnp, offset, value); | ||
116 | mutex_unlock(&adnp->i2c_lock); | ||
117 | } | ||
118 | |||
119 | static int adnp_gpio_direction_input(struct gpio_chip *chip, unsigned offset) | ||
120 | { | ||
121 | struct adnp *adnp = to_adnp(chip); | ||
122 | unsigned int reg = offset >> adnp->reg_shift; | ||
123 | unsigned int pos = offset & 7; | ||
124 | u8 value; | ||
125 | int err; | ||
126 | |||
127 | mutex_lock(&adnp->i2c_lock); | ||
128 | |||
129 | err = adnp_read(adnp, GPIO_DDR(adnp) + reg, &value); | ||
130 | if (err < 0) | ||
131 | goto out; | ||
132 | |||
133 | value &= ~BIT(pos); | ||
134 | |||
135 | err = adnp_write(adnp, GPIO_DDR(adnp) + reg, value); | ||
136 | if (err < 0) | ||
137 | goto out; | ||
138 | |||
139 | err = adnp_read(adnp, GPIO_DDR(adnp) + reg, &value); | ||
140 | if (err < 0) | ||
141 | goto out; | ||
142 | |||
143 | if (err & BIT(pos)) | ||
144 | err = -EACCES; | ||
145 | |||
146 | err = 0; | ||
147 | |||
148 | out: | ||
149 | mutex_unlock(&adnp->i2c_lock); | ||
150 | return err; | ||
151 | } | ||
152 | |||
153 | static int adnp_gpio_direction_output(struct gpio_chip *chip, unsigned offset, | ||
154 | int value) | ||
155 | { | ||
156 | struct adnp *adnp = to_adnp(chip); | ||
157 | unsigned int reg = offset >> adnp->reg_shift; | ||
158 | unsigned int pos = offset & 7; | ||
159 | int err; | ||
160 | u8 val; | ||
161 | |||
162 | mutex_lock(&adnp->i2c_lock); | ||
163 | |||
164 | err = adnp_read(adnp, GPIO_DDR(adnp) + reg, &val); | ||
165 | if (err < 0) | ||
166 | goto out; | ||
167 | |||
168 | val |= BIT(pos); | ||
169 | |||
170 | err = adnp_write(adnp, GPIO_DDR(adnp) + reg, val); | ||
171 | if (err < 0) | ||
172 | goto out; | ||
173 | |||
174 | err = adnp_read(adnp, GPIO_DDR(adnp) + reg, &val); | ||
175 | if (err < 0) | ||
176 | goto out; | ||
177 | |||
178 | if (!(val & BIT(pos))) { | ||
179 | err = -EPERM; | ||
180 | goto out; | ||
181 | } | ||
182 | |||
183 | __adnp_gpio_set(adnp, offset, value); | ||
184 | err = 0; | ||
185 | |||
186 | out: | ||
187 | mutex_unlock(&adnp->i2c_lock); | ||
188 | return err; | ||
189 | } | ||
190 | |||
191 | static void adnp_gpio_dbg_show(struct seq_file *s, struct gpio_chip *chip) | ||
192 | { | ||
193 | struct adnp *adnp = to_adnp(chip); | ||
194 | unsigned int num_regs = 1 << adnp->reg_shift, i, j; | ||
195 | int err; | ||
196 | |||
197 | for (i = 0; i < num_regs; i++) { | ||
198 | u8 ddr, plr, ier, isr; | ||
199 | |||
200 | mutex_lock(&adnp->i2c_lock); | ||
201 | |||
202 | err = adnp_read(adnp, GPIO_DDR(adnp) + i, &ddr); | ||
203 | if (err < 0) { | ||
204 | mutex_unlock(&adnp->i2c_lock); | ||
205 | return; | ||
206 | } | ||
207 | |||
208 | err = adnp_read(adnp, GPIO_PLR(adnp) + i, &plr); | ||
209 | if (err < 0) { | ||
210 | mutex_unlock(&adnp->i2c_lock); | ||
211 | return; | ||
212 | } | ||
213 | |||
214 | err = adnp_read(adnp, GPIO_IER(adnp) + i, &ier); | ||
215 | if (err < 0) { | ||
216 | mutex_unlock(&adnp->i2c_lock); | ||
217 | return; | ||
218 | } | ||
219 | |||
220 | err = adnp_read(adnp, GPIO_ISR(adnp) + i, &isr); | ||
221 | if (err < 0) { | ||
222 | mutex_unlock(&adnp->i2c_lock); | ||
223 | return; | ||
224 | } | ||
225 | |||
226 | mutex_unlock(&adnp->i2c_lock); | ||
227 | |||
228 | for (j = 0; j < 8; j++) { | ||
229 | unsigned int bit = (i << adnp->reg_shift) + j; | ||
230 | const char *direction = "input "; | ||
231 | const char *level = "low "; | ||
232 | const char *interrupt = "disabled"; | ||
233 | const char *pending = ""; | ||
234 | |||
235 | if (ddr & BIT(j)) | ||
236 | direction = "output"; | ||
237 | |||
238 | if (plr & BIT(j)) | ||
239 | level = "high"; | ||
240 | |||
241 | if (ier & BIT(j)) | ||
242 | interrupt = "enabled "; | ||
243 | |||
244 | if (isr & BIT(j)) | ||
245 | pending = "pending"; | ||
246 | |||
247 | seq_printf(s, "%2u: %s %s IRQ %s %s\n", bit, | ||
248 | direction, level, interrupt, pending); | ||
249 | } | ||
250 | } | ||
251 | } | ||
252 | |||
253 | static int adnp_gpio_setup(struct adnp *adnp, unsigned int num_gpios) | ||
254 | { | ||
255 | struct gpio_chip *chip = &adnp->gpio; | ||
256 | |||
257 | adnp->reg_shift = get_count_order(num_gpios) - 3; | ||
258 | |||
259 | chip->direction_input = adnp_gpio_direction_input; | ||
260 | chip->direction_output = adnp_gpio_direction_output; | ||
261 | chip->get = adnp_gpio_get; | ||
262 | chip->set = adnp_gpio_set; | ||
263 | chip->can_sleep = 1; | ||
264 | |||
265 | if (IS_ENABLED(CONFIG_DEBUG_FS)) | ||
266 | chip->dbg_show = adnp_gpio_dbg_show; | ||
267 | |||
268 | chip->base = -1; | ||
269 | chip->ngpio = num_gpios; | ||
270 | chip->label = adnp->client->name; | ||
271 | chip->dev = &adnp->client->dev; | ||
272 | chip->of_node = chip->dev->of_node; | ||
273 | chip->owner = THIS_MODULE; | ||
274 | |||
275 | return 0; | ||
276 | } | ||
277 | |||
278 | static irqreturn_t adnp_irq(int irq, void *data) | ||
279 | { | ||
280 | struct adnp *adnp = data; | ||
281 | unsigned int num_regs, i; | ||
282 | |||
283 | num_regs = 1 << adnp->reg_shift; | ||
284 | |||
285 | for (i = 0; i < num_regs; i++) { | ||
286 | unsigned int base = i << adnp->reg_shift, bit; | ||
287 | u8 changed, level, isr, ier; | ||
288 | unsigned long pending; | ||
289 | int err; | ||
290 | |||
291 | mutex_lock(&adnp->i2c_lock); | ||
292 | |||
293 | err = adnp_read(adnp, GPIO_PLR(adnp) + i, &level); | ||
294 | if (err < 0) { | ||
295 | mutex_unlock(&adnp->i2c_lock); | ||
296 | continue; | ||
297 | } | ||
298 | |||
299 | err = adnp_read(adnp, GPIO_ISR(adnp) + i, &isr); | ||
300 | if (err < 0) { | ||
301 | mutex_unlock(&adnp->i2c_lock); | ||
302 | continue; | ||
303 | } | ||
304 | |||
305 | err = adnp_read(adnp, GPIO_IER(adnp) + i, &ier); | ||
306 | if (err < 0) { | ||
307 | mutex_unlock(&adnp->i2c_lock); | ||
308 | continue; | ||
309 | } | ||
310 | |||
311 | mutex_unlock(&adnp->i2c_lock); | ||
312 | |||
313 | /* determine pins that changed levels */ | ||
314 | changed = level ^ adnp->irq_level[i]; | ||
315 | |||
316 | /* compute edge-triggered interrupts */ | ||
317 | pending = changed & ((adnp->irq_fall[i] & ~level) | | ||
318 | (adnp->irq_rise[i] & level)); | ||
319 | |||
320 | /* add in level-triggered interrupts */ | ||
321 | pending |= (adnp->irq_high[i] & level) | | ||
322 | (adnp->irq_low[i] & ~level); | ||
323 | |||
324 | /* mask out non-pending and disabled interrupts */ | ||
325 | pending &= isr & ier; | ||
326 | |||
327 | for_each_set_bit(bit, &pending, 8) { | ||
328 | unsigned int virq; | ||
329 | virq = irq_find_mapping(adnp->domain, base + bit); | ||
330 | handle_nested_irq(virq); | ||
331 | } | ||
332 | } | ||
333 | |||
334 | return IRQ_HANDLED; | ||
335 | } | ||
336 | |||
337 | static int adnp_gpio_to_irq(struct gpio_chip *chip, unsigned offset) | ||
338 | { | ||
339 | struct adnp *adnp = to_adnp(chip); | ||
340 | return irq_create_mapping(adnp->domain, offset); | ||
341 | } | ||
342 | |||
343 | static void adnp_irq_mask(struct irq_data *data) | ||
344 | { | ||
345 | struct adnp *adnp = irq_data_get_irq_chip_data(data); | ||
346 | unsigned int reg = data->hwirq >> adnp->reg_shift; | ||
347 | unsigned int pos = data->hwirq & 7; | ||
348 | |||
349 | adnp->irq_enable[reg] &= ~BIT(pos); | ||
350 | } | ||
351 | |||
352 | static void adnp_irq_unmask(struct irq_data *data) | ||
353 | { | ||
354 | struct adnp *adnp = irq_data_get_irq_chip_data(data); | ||
355 | unsigned int reg = data->hwirq >> adnp->reg_shift; | ||
356 | unsigned int pos = data->hwirq & 7; | ||
357 | |||
358 | adnp->irq_enable[reg] |= BIT(pos); | ||
359 | } | ||
360 | |||
361 | static int adnp_irq_set_type(struct irq_data *data, unsigned int type) | ||
362 | { | ||
363 | struct adnp *adnp = irq_data_get_irq_chip_data(data); | ||
364 | unsigned int reg = data->hwirq >> adnp->reg_shift; | ||
365 | unsigned int pos = data->hwirq & 7; | ||
366 | |||
367 | if (type & IRQ_TYPE_EDGE_RISING) | ||
368 | adnp->irq_rise[reg] |= BIT(pos); | ||
369 | else | ||
370 | adnp->irq_rise[reg] &= ~BIT(pos); | ||
371 | |||
372 | if (type & IRQ_TYPE_EDGE_FALLING) | ||
373 | adnp->irq_fall[reg] |= BIT(pos); | ||
374 | else | ||
375 | adnp->irq_fall[reg] &= ~BIT(pos); | ||
376 | |||
377 | if (type & IRQ_TYPE_LEVEL_HIGH) | ||
378 | adnp->irq_high[reg] |= BIT(pos); | ||
379 | else | ||
380 | adnp->irq_high[reg] &= ~BIT(pos); | ||
381 | |||
382 | if (type & IRQ_TYPE_LEVEL_LOW) | ||
383 | adnp->irq_low[reg] |= BIT(pos); | ||
384 | else | ||
385 | adnp->irq_low[reg] &= ~BIT(pos); | ||
386 | |||
387 | return 0; | ||
388 | } | ||
389 | |||
390 | static void adnp_irq_bus_lock(struct irq_data *data) | ||
391 | { | ||
392 | struct adnp *adnp = irq_data_get_irq_chip_data(data); | ||
393 | |||
394 | mutex_lock(&adnp->irq_lock); | ||
395 | } | ||
396 | |||
397 | static void adnp_irq_bus_unlock(struct irq_data *data) | ||
398 | { | ||
399 | struct adnp *adnp = irq_data_get_irq_chip_data(data); | ||
400 | unsigned int num_regs = 1 << adnp->reg_shift, i; | ||
401 | |||
402 | mutex_lock(&adnp->i2c_lock); | ||
403 | |||
404 | for (i = 0; i < num_regs; i++) | ||
405 | adnp_write(adnp, GPIO_IER(adnp) + i, adnp->irq_enable[i]); | ||
406 | |||
407 | mutex_unlock(&adnp->i2c_lock); | ||
408 | mutex_unlock(&adnp->irq_lock); | ||
409 | } | ||
410 | |||
411 | static struct irq_chip adnp_irq_chip = { | ||
412 | .name = "gpio-adnp", | ||
413 | .irq_mask = adnp_irq_mask, | ||
414 | .irq_unmask = adnp_irq_unmask, | ||
415 | .irq_set_type = adnp_irq_set_type, | ||
416 | .irq_bus_lock = adnp_irq_bus_lock, | ||
417 | .irq_bus_sync_unlock = adnp_irq_bus_unlock, | ||
418 | }; | ||
419 | |||
420 | static int adnp_irq_map(struct irq_domain *domain, unsigned int irq, | ||
421 | irq_hw_number_t hwirq) | ||
422 | { | ||
423 | irq_set_chip_data(irq, domain->host_data); | ||
424 | irq_set_chip(irq, &adnp_irq_chip); | ||
425 | irq_set_nested_thread(irq, true); | ||
426 | |||
427 | #ifdef CONFIG_ARM | ||
428 | set_irq_flags(irq, IRQF_VALID); | ||
429 | #else | ||
430 | irq_set_noprobe(irq); | ||
431 | #endif | ||
432 | |||
433 | return 0; | ||
434 | } | ||
435 | |||
436 | static const struct irq_domain_ops adnp_irq_domain_ops = { | ||
437 | .map = adnp_irq_map, | ||
438 | .xlate = irq_domain_xlate_twocell, | ||
439 | }; | ||
440 | |||
441 | static int adnp_irq_setup(struct adnp *adnp) | ||
442 | { | ||
443 | unsigned int num_regs = 1 << adnp->reg_shift, i; | ||
444 | struct gpio_chip *chip = &adnp->gpio; | ||
445 | int err; | ||
446 | |||
447 | mutex_init(&adnp->irq_lock); | ||
448 | |||
449 | /* | ||
450 | * Allocate memory to keep track of the current level and trigger | ||
451 | * modes of the interrupts. To avoid multiple allocations, a single | ||
452 | * large buffer is allocated and pointers are setup to point at the | ||
453 | * corresponding offsets. For consistency, the layout of the buffer | ||
454 | * is chosen to match the register layout of the hardware in that | ||
455 | * each segment contains the corresponding bits for all interrupts. | ||
456 | */ | ||
457 | adnp->irq_enable = devm_kzalloc(chip->dev, num_regs * 6, GFP_KERNEL); | ||
458 | if (!adnp->irq_enable) | ||
459 | return -ENOMEM; | ||
460 | |||
461 | adnp->irq_level = adnp->irq_enable + (num_regs * 1); | ||
462 | adnp->irq_rise = adnp->irq_enable + (num_regs * 2); | ||
463 | adnp->irq_fall = adnp->irq_enable + (num_regs * 3); | ||
464 | adnp->irq_high = adnp->irq_enable + (num_regs * 4); | ||
465 | adnp->irq_low = adnp->irq_enable + (num_regs * 5); | ||
466 | |||
467 | for (i = 0; i < num_regs; i++) { | ||
468 | /* | ||
469 | * Read the initial level of all pins to allow the emulation | ||
470 | * of edge triggered interrupts. | ||
471 | */ | ||
472 | err = adnp_read(adnp, GPIO_PLR(adnp) + i, &adnp->irq_level[i]); | ||
473 | if (err < 0) | ||
474 | return err; | ||
475 | |||
476 | /* disable all interrupts */ | ||
477 | err = adnp_write(adnp, GPIO_IER(adnp) + i, 0); | ||
478 | if (err < 0) | ||
479 | return err; | ||
480 | |||
481 | adnp->irq_enable[i] = 0x00; | ||
482 | } | ||
483 | |||
484 | adnp->domain = irq_domain_add_linear(chip->of_node, chip->ngpio, | ||
485 | &adnp_irq_domain_ops, adnp); | ||
486 | |||
487 | err = request_threaded_irq(adnp->client->irq, NULL, adnp_irq, | ||
488 | IRQF_TRIGGER_RISING | IRQF_ONESHOT, | ||
489 | dev_name(chip->dev), adnp); | ||
490 | if (err != 0) { | ||
491 | dev_err(chip->dev, "can't request IRQ#%d: %d\n", | ||
492 | adnp->client->irq, err); | ||
493 | goto error; | ||
494 | } | ||
495 | |||
496 | chip->to_irq = adnp_gpio_to_irq; | ||
497 | return 0; | ||
498 | |||
499 | error: | ||
500 | irq_domain_remove(adnp->domain); | ||
501 | return err; | ||
502 | } | ||
503 | |||
504 | static void adnp_irq_teardown(struct adnp *adnp) | ||
505 | { | ||
506 | unsigned int irq, i; | ||
507 | |||
508 | free_irq(adnp->client->irq, adnp); | ||
509 | |||
510 | for (i = 0; i < adnp->gpio.ngpio; i++) { | ||
511 | irq = irq_find_mapping(adnp->domain, i); | ||
512 | if (irq > 0) | ||
513 | irq_dispose_mapping(irq); | ||
514 | } | ||
515 | |||
516 | irq_domain_remove(adnp->domain); | ||
517 | } | ||
518 | |||
519 | static __devinit int adnp_i2c_probe(struct i2c_client *client, | ||
520 | const struct i2c_device_id *id) | ||
521 | { | ||
522 | struct device_node *np = client->dev.of_node; | ||
523 | struct adnp *adnp; | ||
524 | u32 num_gpios; | ||
525 | int err; | ||
526 | |||
527 | err = of_property_read_u32(np, "nr-gpios", &num_gpios); | ||
528 | if (err < 0) | ||
529 | return err; | ||
530 | |||
531 | client->irq = irq_of_parse_and_map(np, 0); | ||
532 | if (!client->irq) | ||
533 | return -EPROBE_DEFER; | ||
534 | |||
535 | adnp = devm_kzalloc(&client->dev, sizeof(*adnp), GFP_KERNEL); | ||
536 | if (!adnp) | ||
537 | return -ENOMEM; | ||
538 | |||
539 | mutex_init(&adnp->i2c_lock); | ||
540 | adnp->client = client; | ||
541 | |||
542 | err = adnp_gpio_setup(adnp, num_gpios); | ||
543 | if (err < 0) | ||
544 | return err; | ||
545 | |||
546 | if (of_find_property(np, "interrupt-controller", NULL)) { | ||
547 | err = adnp_irq_setup(adnp); | ||
548 | if (err < 0) | ||
549 | goto teardown; | ||
550 | } | ||
551 | |||
552 | err = gpiochip_add(&adnp->gpio); | ||
553 | if (err < 0) | ||
554 | goto teardown; | ||
555 | |||
556 | i2c_set_clientdata(client, adnp); | ||
557 | return 0; | ||
558 | |||
559 | teardown: | ||
560 | if (of_find_property(np, "interrupt-controller", NULL)) | ||
561 | adnp_irq_teardown(adnp); | ||
562 | |||
563 | return err; | ||
564 | } | ||
565 | |||
566 | static __devexit int adnp_i2c_remove(struct i2c_client *client) | ||
567 | { | ||
568 | struct adnp *adnp = i2c_get_clientdata(client); | ||
569 | struct device_node *np = client->dev.of_node; | ||
570 | int err; | ||
571 | |||
572 | err = gpiochip_remove(&adnp->gpio); | ||
573 | if (err < 0) { | ||
574 | dev_err(&client->dev, "%s failed: %d\n", "gpiochip_remove()", | ||
575 | err); | ||
576 | return err; | ||
577 | } | ||
578 | |||
579 | if (of_find_property(np, "interrupt-controller", NULL)) | ||
580 | adnp_irq_teardown(adnp); | ||
581 | |||
582 | return 0; | ||
583 | } | ||
584 | |||
585 | static const struct i2c_device_id adnp_i2c_id[] __devinitconst = { | ||
586 | { "gpio-adnp" }, | ||
587 | { }, | ||
588 | }; | ||
589 | MODULE_DEVICE_TABLE(i2c, adnp_i2c_id); | ||
590 | |||
591 | static const struct of_device_id adnp_of_match[] __devinitconst = { | ||
592 | { .compatible = "ad,gpio-adnp", }, | ||
593 | { }, | ||
594 | }; | ||
595 | MODULE_DEVICE_TABLE(of, adnp_of_match); | ||
596 | |||
597 | static struct i2c_driver adnp_i2c_driver = { | ||
598 | .driver = { | ||
599 | .name = "gpio-adnp", | ||
600 | .owner = THIS_MODULE, | ||
601 | .of_match_table = of_match_ptr(adnp_of_match), | ||
602 | }, | ||
603 | .probe = adnp_i2c_probe, | ||
604 | .remove = __devexit_p(adnp_i2c_remove), | ||
605 | .id_table = adnp_i2c_id, | ||
606 | }; | ||
607 | module_i2c_driver(adnp_i2c_driver); | ||
608 | |||
609 | MODULE_DESCRIPTION("Avionic Design N-bit GPIO expander"); | ||
610 | MODULE_AUTHOR("Thierry Reding <thierry.reding@avionic-design.de>"); | ||
611 | MODULE_LICENSE("GPL"); | ||
diff --git a/drivers/gpio/gpio-adp5588.c b/drivers/gpio/gpio-adp5588.c index ae5d7f12ce6..eeedad42913 100644 --- a/drivers/gpio/gpio-adp5588.c +++ b/drivers/gpio/gpio-adp5588.c | |||
@@ -483,19 +483,7 @@ static struct i2c_driver adp5588_gpio_driver = { | |||
483 | .id_table = adp5588_gpio_id, | 483 | .id_table = adp5588_gpio_id, |
484 | }; | 484 | }; |
485 | 485 | ||
486 | static int __init adp5588_gpio_init(void) | 486 | module_i2c_driver(adp5588_gpio_driver); |
487 | { | ||
488 | return i2c_add_driver(&adp5588_gpio_driver); | ||
489 | } | ||
490 | |||
491 | module_init(adp5588_gpio_init); | ||
492 | |||
493 | static void __exit adp5588_gpio_exit(void) | ||
494 | { | ||
495 | i2c_del_driver(&adp5588_gpio_driver); | ||
496 | } | ||
497 | |||
498 | module_exit(adp5588_gpio_exit); | ||
499 | 487 | ||
500 | MODULE_AUTHOR("Michael Hennerich <hennerich@blackfin.uclinux.org>"); | 488 | MODULE_AUTHOR("Michael Hennerich <hennerich@blackfin.uclinux.org>"); |
501 | MODULE_DESCRIPTION("GPIO ADP5588 Driver"); | 489 | MODULE_DESCRIPTION("GPIO ADP5588 Driver"); |
diff --git a/drivers/gpio/gpio-bt8xx.c b/drivers/gpio/gpio-bt8xx.c index e4cc7eb69bb..aba97abda77 100644 --- a/drivers/gpio/gpio-bt8xx.c +++ b/drivers/gpio/gpio-bt8xx.c | |||
@@ -310,7 +310,7 @@ static int bt8xxgpio_resume(struct pci_dev *pdev) | |||
310 | #define bt8xxgpio_resume NULL | 310 | #define bt8xxgpio_resume NULL |
311 | #endif /* CONFIG_PM */ | 311 | #endif /* CONFIG_PM */ |
312 | 312 | ||
313 | static struct pci_device_id bt8xxgpio_pci_tbl[] = { | 313 | static DEFINE_PCI_DEVICE_TABLE(bt8xxgpio_pci_tbl) = { |
314 | { PCI_DEVICE(PCI_VENDOR_ID_BROOKTREE, PCI_DEVICE_ID_BT848) }, | 314 | { PCI_DEVICE(PCI_VENDOR_ID_BROOKTREE, PCI_DEVICE_ID_BT848) }, |
315 | { PCI_DEVICE(PCI_VENDOR_ID_BROOKTREE, PCI_DEVICE_ID_BT849) }, | 315 | { PCI_DEVICE(PCI_VENDOR_ID_BROOKTREE, PCI_DEVICE_ID_BT849) }, |
316 | { PCI_DEVICE(PCI_VENDOR_ID_BROOKTREE, PCI_DEVICE_ID_BT878) }, | 316 | { PCI_DEVICE(PCI_VENDOR_ID_BROOKTREE, PCI_DEVICE_ID_BT878) }, |
diff --git a/drivers/gpio/gpio-da9052.c b/drivers/gpio/gpio-da9052.c index 56dd047d584..24b8c297404 100644 --- a/drivers/gpio/gpio-da9052.c +++ b/drivers/gpio/gpio-da9052.c | |||
@@ -207,7 +207,7 @@ static int __devinit da9052_gpio_probe(struct platform_device *pdev) | |||
207 | struct da9052_pdata *pdata; | 207 | struct da9052_pdata *pdata; |
208 | int ret; | 208 | int ret; |
209 | 209 | ||
210 | gpio = kzalloc(sizeof(*gpio), GFP_KERNEL); | 210 | gpio = devm_kzalloc(&pdev->dev, sizeof(*gpio), GFP_KERNEL); |
211 | if (gpio == NULL) | 211 | if (gpio == NULL) |
212 | return -ENOMEM; | 212 | return -ENOMEM; |
213 | 213 | ||
@@ -221,28 +221,19 @@ static int __devinit da9052_gpio_probe(struct platform_device *pdev) | |||
221 | ret = gpiochip_add(&gpio->gp); | 221 | ret = gpiochip_add(&gpio->gp); |
222 | if (ret < 0) { | 222 | if (ret < 0) { |
223 | dev_err(&pdev->dev, "Could not register gpiochip, %d\n", ret); | 223 | dev_err(&pdev->dev, "Could not register gpiochip, %d\n", ret); |
224 | goto err_mem; | 224 | return ret; |
225 | } | 225 | } |
226 | 226 | ||
227 | platform_set_drvdata(pdev, gpio); | 227 | platform_set_drvdata(pdev, gpio); |
228 | 228 | ||
229 | return 0; | 229 | return 0; |
230 | |||
231 | err_mem: | ||
232 | kfree(gpio); | ||
233 | return ret; | ||
234 | } | 230 | } |
235 | 231 | ||
236 | static int __devexit da9052_gpio_remove(struct platform_device *pdev) | 232 | static int __devexit da9052_gpio_remove(struct platform_device *pdev) |
237 | { | 233 | { |
238 | struct da9052_gpio *gpio = platform_get_drvdata(pdev); | 234 | struct da9052_gpio *gpio = platform_get_drvdata(pdev); |
239 | int ret; | ||
240 | |||
241 | ret = gpiochip_remove(&gpio->gp); | ||
242 | if (ret == 0) | ||
243 | kfree(gpio); | ||
244 | 235 | ||
245 | return ret; | 236 | return gpiochip_remove(&gpio->gp); |
246 | } | 237 | } |
247 | 238 | ||
248 | static struct platform_driver da9052_gpio_driver = { | 239 | static struct platform_driver da9052_gpio_driver = { |
diff --git a/drivers/gpio/gpio-davinci.c b/drivers/gpio/gpio-davinci.c index 3d000169285..17df6db5dca 100644 --- a/drivers/gpio/gpio-davinci.c +++ b/drivers/gpio/gpio-davinci.c | |||
@@ -366,7 +366,7 @@ static int __init davinci_gpio_irq_setup(void) | |||
366 | PTR_ERR(clk)); | 366 | PTR_ERR(clk)); |
367 | return PTR_ERR(clk); | 367 | return PTR_ERR(clk); |
368 | } | 368 | } |
369 | clk_enable(clk); | 369 | clk_prepare_enable(clk); |
370 | 370 | ||
371 | /* Arrange gpio_to_irq() support, handling either direct IRQs or | 371 | /* Arrange gpio_to_irq() support, handling either direct IRQs or |
372 | * banked IRQs. Having GPIOs in the first GPIO bank use direct | 372 | * banked IRQs. Having GPIOs in the first GPIO bank use direct |
diff --git a/drivers/gpio/gpio-em.c b/drivers/gpio/gpio-em.c index ec48ed51262..efb4c2d0d13 100644 --- a/drivers/gpio/gpio-em.c +++ b/drivers/gpio/gpio-em.c | |||
@@ -85,22 +85,16 @@ static inline void em_gio_write(struct em_gio_priv *p, int offs, | |||
85 | iowrite32(value, p->base1 + (offs - GIO_IDT0)); | 85 | iowrite32(value, p->base1 + (offs - GIO_IDT0)); |
86 | } | 86 | } |
87 | 87 | ||
88 | static inline struct em_gio_priv *irq_to_priv(struct irq_data *d) | ||
89 | { | ||
90 | struct irq_chip *chip = irq_data_get_irq_chip(d); | ||
91 | return container_of(chip, struct em_gio_priv, irq_chip); | ||
92 | } | ||
93 | |||
94 | static void em_gio_irq_disable(struct irq_data *d) | 88 | static void em_gio_irq_disable(struct irq_data *d) |
95 | { | 89 | { |
96 | struct em_gio_priv *p = irq_to_priv(d); | 90 | struct em_gio_priv *p = irq_data_get_irq_chip_data(d); |
97 | 91 | ||
98 | em_gio_write(p, GIO_IDS, BIT(irqd_to_hwirq(d))); | 92 | em_gio_write(p, GIO_IDS, BIT(irqd_to_hwirq(d))); |
99 | } | 93 | } |
100 | 94 | ||
101 | static void em_gio_irq_enable(struct irq_data *d) | 95 | static void em_gio_irq_enable(struct irq_data *d) |
102 | { | 96 | { |
103 | struct em_gio_priv *p = irq_to_priv(d); | 97 | struct em_gio_priv *p = irq_data_get_irq_chip_data(d); |
104 | 98 | ||
105 | em_gio_write(p, GIO_IEN, BIT(irqd_to_hwirq(d))); | 99 | em_gio_write(p, GIO_IEN, BIT(irqd_to_hwirq(d))); |
106 | } | 100 | } |
@@ -118,7 +112,7 @@ static unsigned char em_gio_sense_table[IRQ_TYPE_SENSE_MASK + 1] = { | |||
118 | static int em_gio_irq_set_type(struct irq_data *d, unsigned int type) | 112 | static int em_gio_irq_set_type(struct irq_data *d, unsigned int type) |
119 | { | 113 | { |
120 | unsigned char value = em_gio_sense_table[type & IRQ_TYPE_SENSE_MASK]; | 114 | unsigned char value = em_gio_sense_table[type & IRQ_TYPE_SENSE_MASK]; |
121 | struct em_gio_priv *p = irq_to_priv(d); | 115 | struct em_gio_priv *p = irq_data_get_irq_chip_data(d); |
122 | unsigned int reg, offset, shift; | 116 | unsigned int reg, offset, shift; |
123 | unsigned long flags; | 117 | unsigned long flags; |
124 | unsigned long tmp; | 118 | unsigned long tmp; |
diff --git a/drivers/gpio/gpio-lpc32xx.c b/drivers/gpio/gpio-lpc32xx.c index ed94b4ea72e..3644e0dcb3d 100644 --- a/drivers/gpio/gpio-lpc32xx.c +++ b/drivers/gpio/gpio-lpc32xx.c | |||
@@ -113,7 +113,8 @@ static const char *gpi_p3_names[LPC32XX_GPI_P3_MAX] = { | |||
113 | NULL, NULL, NULL, "gpi15", | 113 | NULL, NULL, NULL, "gpi15", |
114 | "gpi16", "gpi17", "gpi18", "gpi19", | 114 | "gpi16", "gpi17", "gpi18", "gpi19", |
115 | "gpi20", "gpi21", "gpi22", "gpi23", | 115 | "gpi20", "gpi21", "gpi22", "gpi23", |
116 | "gpi24", "gpi25", "gpi26", "gpi27" | 116 | "gpi24", "gpi25", "gpi26", "gpi27", |
117 | "gpi28" | ||
117 | }; | 118 | }; |
118 | 119 | ||
119 | static const char *gpo_p3_names[LPC32XX_GPO_P3_MAX] = { | 120 | static const char *gpo_p3_names[LPC32XX_GPO_P3_MAX] = { |
diff --git a/drivers/gpio/gpio-mc9s08dz60.c b/drivers/gpio/gpio-mc9s08dz60.c index 2738cc44d63..0ab700046a2 100644 --- a/drivers/gpio/gpio-mc9s08dz60.c +++ b/drivers/gpio/gpio-mc9s08dz60.c | |||
@@ -91,10 +91,9 @@ static int mc9s08dz60_direction_output(struct gpio_chip *gc, | |||
91 | static int mc9s08dz60_probe(struct i2c_client *client, | 91 | static int mc9s08dz60_probe(struct i2c_client *client, |
92 | const struct i2c_device_id *id) | 92 | const struct i2c_device_id *id) |
93 | { | 93 | { |
94 | int ret = 0; | ||
95 | struct mc9s08dz60 *mc9s; | 94 | struct mc9s08dz60 *mc9s; |
96 | 95 | ||
97 | mc9s = kzalloc(sizeof(*mc9s), GFP_KERNEL); | 96 | mc9s = devm_kzalloc(&client->dev, sizeof(*mc9s), GFP_KERNEL); |
98 | if (!mc9s) | 97 | if (!mc9s) |
99 | return -ENOMEM; | 98 | return -ENOMEM; |
100 | 99 | ||
@@ -110,30 +109,16 @@ static int mc9s08dz60_probe(struct i2c_client *client, | |||
110 | mc9s->client = client; | 109 | mc9s->client = client; |
111 | i2c_set_clientdata(client, mc9s); | 110 | i2c_set_clientdata(client, mc9s); |
112 | 111 | ||
113 | ret = gpiochip_add(&mc9s->chip); | 112 | return gpiochip_add(&mc9s->chip); |
114 | if (ret) | ||
115 | goto error; | ||
116 | |||
117 | return 0; | ||
118 | |||
119 | error: | ||
120 | kfree(mc9s); | ||
121 | return ret; | ||
122 | } | 113 | } |
123 | 114 | ||
124 | static int mc9s08dz60_remove(struct i2c_client *client) | 115 | static int mc9s08dz60_remove(struct i2c_client *client) |
125 | { | 116 | { |
126 | struct mc9s08dz60 *mc9s; | 117 | struct mc9s08dz60 *mc9s; |
127 | int ret; | ||
128 | 118 | ||
129 | mc9s = i2c_get_clientdata(client); | 119 | mc9s = i2c_get_clientdata(client); |
130 | 120 | ||
131 | ret = gpiochip_remove(&mc9s->chip); | 121 | return gpiochip_remove(&mc9s->chip); |
132 | if (!ret) | ||
133 | kfree(mc9s); | ||
134 | |||
135 | return ret; | ||
136 | |||
137 | } | 122 | } |
138 | 123 | ||
139 | static const struct i2c_device_id mc9s08dz60_id[] = { | 124 | static const struct i2c_device_id mc9s08dz60_id[] = { |
diff --git a/drivers/gpio/gpio-ml-ioh.c b/drivers/gpio/gpio-ml-ioh.c index db01f151d41..6a29ee1847b 100644 --- a/drivers/gpio/gpio-ml-ioh.c +++ b/drivers/gpio/gpio-ml-ioh.c | |||
@@ -87,8 +87,7 @@ struct ioh_gpio_reg_data { | |||
87 | * @gpio_use_sel: Save GPIO_USE_SEL1~4 register for PM | 87 | * @gpio_use_sel: Save GPIO_USE_SEL1~4 register for PM |
88 | * @ch: Indicate GPIO channel | 88 | * @ch: Indicate GPIO channel |
89 | * @irq_base: Save base of IRQ number for interrupt | 89 | * @irq_base: Save base of IRQ number for interrupt |
90 | * @spinlock: Used for register access protection in | 90 | * @spinlock: Used for register access protection |
91 | * interrupt context ioh_irq_type and PM; | ||
92 | */ | 91 | */ |
93 | struct ioh_gpio { | 92 | struct ioh_gpio { |
94 | void __iomem *base; | 93 | void __iomem *base; |
@@ -97,7 +96,6 @@ struct ioh_gpio { | |||
97 | struct gpio_chip gpio; | 96 | struct gpio_chip gpio; |
98 | struct ioh_gpio_reg_data ioh_gpio_reg; | 97 | struct ioh_gpio_reg_data ioh_gpio_reg; |
99 | u32 gpio_use_sel; | 98 | u32 gpio_use_sel; |
100 | struct mutex lock; | ||
101 | int ch; | 99 | int ch; |
102 | int irq_base; | 100 | int irq_base; |
103 | spinlock_t spinlock; | 101 | spinlock_t spinlock; |
@@ -109,8 +107,9 @@ static void ioh_gpio_set(struct gpio_chip *gpio, unsigned nr, int val) | |||
109 | { | 107 | { |
110 | u32 reg_val; | 108 | u32 reg_val; |
111 | struct ioh_gpio *chip = container_of(gpio, struct ioh_gpio, gpio); | 109 | struct ioh_gpio *chip = container_of(gpio, struct ioh_gpio, gpio); |
110 | unsigned long flags; | ||
112 | 111 | ||
113 | mutex_lock(&chip->lock); | 112 | spin_lock_irqsave(&chip->spinlock, flags); |
114 | reg_val = ioread32(&chip->reg->regs[chip->ch].po); | 113 | reg_val = ioread32(&chip->reg->regs[chip->ch].po); |
115 | if (val) | 114 | if (val) |
116 | reg_val |= (1 << nr); | 115 | reg_val |= (1 << nr); |
@@ -118,7 +117,7 @@ static void ioh_gpio_set(struct gpio_chip *gpio, unsigned nr, int val) | |||
118 | reg_val &= ~(1 << nr); | 117 | reg_val &= ~(1 << nr); |
119 | 118 | ||
120 | iowrite32(reg_val, &chip->reg->regs[chip->ch].po); | 119 | iowrite32(reg_val, &chip->reg->regs[chip->ch].po); |
121 | mutex_unlock(&chip->lock); | 120 | spin_unlock_irqrestore(&chip->spinlock, flags); |
122 | } | 121 | } |
123 | 122 | ||
124 | static int ioh_gpio_get(struct gpio_chip *gpio, unsigned nr) | 123 | static int ioh_gpio_get(struct gpio_chip *gpio, unsigned nr) |
@@ -134,8 +133,9 @@ static int ioh_gpio_direction_output(struct gpio_chip *gpio, unsigned nr, | |||
134 | struct ioh_gpio *chip = container_of(gpio, struct ioh_gpio, gpio); | 133 | struct ioh_gpio *chip = container_of(gpio, struct ioh_gpio, gpio); |
135 | u32 pm; | 134 | u32 pm; |
136 | u32 reg_val; | 135 | u32 reg_val; |
136 | unsigned long flags; | ||
137 | 137 | ||
138 | mutex_lock(&chip->lock); | 138 | spin_lock_irqsave(&chip->spinlock, flags); |
139 | pm = ioread32(&chip->reg->regs[chip->ch].pm) & | 139 | pm = ioread32(&chip->reg->regs[chip->ch].pm) & |
140 | ((1 << num_ports[chip->ch]) - 1); | 140 | ((1 << num_ports[chip->ch]) - 1); |
141 | pm |= (1 << nr); | 141 | pm |= (1 << nr); |
@@ -148,7 +148,7 @@ static int ioh_gpio_direction_output(struct gpio_chip *gpio, unsigned nr, | |||
148 | reg_val &= ~(1 << nr); | 148 | reg_val &= ~(1 << nr); |
149 | iowrite32(reg_val, &chip->reg->regs[chip->ch].po); | 149 | iowrite32(reg_val, &chip->reg->regs[chip->ch].po); |
150 | 150 | ||
151 | mutex_unlock(&chip->lock); | 151 | spin_unlock_irqrestore(&chip->spinlock, flags); |
152 | 152 | ||
153 | return 0; | 153 | return 0; |
154 | } | 154 | } |
@@ -157,13 +157,14 @@ static int ioh_gpio_direction_input(struct gpio_chip *gpio, unsigned nr) | |||
157 | { | 157 | { |
158 | struct ioh_gpio *chip = container_of(gpio, struct ioh_gpio, gpio); | 158 | struct ioh_gpio *chip = container_of(gpio, struct ioh_gpio, gpio); |
159 | u32 pm; | 159 | u32 pm; |
160 | unsigned long flags; | ||
160 | 161 | ||
161 | mutex_lock(&chip->lock); | 162 | spin_lock_irqsave(&chip->spinlock, flags); |
162 | pm = ioread32(&chip->reg->regs[chip->ch].pm) & | 163 | pm = ioread32(&chip->reg->regs[chip->ch].pm) & |
163 | ((1 << num_ports[chip->ch]) - 1); | 164 | ((1 << num_ports[chip->ch]) - 1); |
164 | pm &= ~(1 << nr); | 165 | pm &= ~(1 << nr); |
165 | iowrite32(pm, &chip->reg->regs[chip->ch].pm); | 166 | iowrite32(pm, &chip->reg->regs[chip->ch].pm); |
166 | mutex_unlock(&chip->lock); | 167 | spin_unlock_irqrestore(&chip->spinlock, flags); |
167 | 168 | ||
168 | return 0; | 169 | return 0; |
169 | } | 170 | } |
@@ -447,7 +448,6 @@ static int __devinit ioh_gpio_probe(struct pci_dev *pdev, | |||
447 | chip->base = base; | 448 | chip->base = base; |
448 | chip->reg = chip->base; | 449 | chip->reg = chip->base; |
449 | chip->ch = i; | 450 | chip->ch = i; |
450 | mutex_init(&chip->lock); | ||
451 | spin_lock_init(&chip->spinlock); | 451 | spin_lock_init(&chip->spinlock); |
452 | ioh_gpio_setup(chip, num_ports[i]); | 452 | ioh_gpio_setup(chip, num_ports[i]); |
453 | ret = gpiochip_add(&chip->gpio); | 453 | ret = gpiochip_add(&chip->gpio); |
diff --git a/drivers/gpio/gpio-msm-v2.c b/drivers/gpio/gpio-msm-v2.c index 5cb1227d69c..38305beb437 100644 --- a/drivers/gpio/gpio-msm-v2.c +++ b/drivers/gpio/gpio-msm-v2.c | |||
@@ -317,9 +317,7 @@ static void msm_summary_irq_handler(unsigned int irq, struct irq_desc *desc) | |||
317 | 317 | ||
318 | chained_irq_enter(chip, desc); | 318 | chained_irq_enter(chip, desc); |
319 | 319 | ||
320 | for (i = find_first_bit(msm_gpio.enabled_irqs, NR_GPIO_IRQS); | 320 | for_each_set_bit(i, msm_gpio.enabled_irqs, NR_GPIO_IRQS) { |
321 | i < NR_GPIO_IRQS; | ||
322 | i = find_next_bit(msm_gpio.enabled_irqs, NR_GPIO_IRQS, i + 1)) { | ||
323 | if (readl(GPIO_INTR_STATUS(i)) & BIT(INTR_STATUS)) | 321 | if (readl(GPIO_INTR_STATUS(i)) & BIT(INTR_STATUS)) |
324 | generic_handle_irq(msm_gpio_to_irq(&msm_gpio.gpio_chip, | 322 | generic_handle_irq(msm_gpio_to_irq(&msm_gpio.gpio_chip, |
325 | i)); | 323 | i)); |
diff --git a/drivers/gpio/gpio-pcf857x.c b/drivers/gpio/gpio-pcf857x.c index 076e236d0da..16af35cd2b1 100644 --- a/drivers/gpio/gpio-pcf857x.c +++ b/drivers/gpio/gpio-pcf857x.c | |||
@@ -23,7 +23,12 @@ | |||
23 | #include <linux/gpio.h> | 23 | #include <linux/gpio.h> |
24 | #include <linux/i2c.h> | 24 | #include <linux/i2c.h> |
25 | #include <linux/i2c/pcf857x.h> | 25 | #include <linux/i2c/pcf857x.h> |
26 | #include <linux/interrupt.h> | ||
27 | #include <linux/irq.h> | ||
28 | #include <linux/irqdomain.h> | ||
26 | #include <linux/module.h> | 29 | #include <linux/module.h> |
30 | #include <linux/spinlock.h> | ||
31 | #include <linux/workqueue.h> | ||
27 | 32 | ||
28 | 33 | ||
29 | static const struct i2c_device_id pcf857x_id[] = { | 34 | static const struct i2c_device_id pcf857x_id[] = { |
@@ -60,7 +65,12 @@ struct pcf857x { | |||
60 | struct gpio_chip chip; | 65 | struct gpio_chip chip; |
61 | struct i2c_client *client; | 66 | struct i2c_client *client; |
62 | struct mutex lock; /* protect 'out' */ | 67 | struct mutex lock; /* protect 'out' */ |
68 | struct work_struct work; /* irq demux work */ | ||
69 | struct irq_domain *irq_domain; /* for irq demux */ | ||
70 | spinlock_t slock; /* protect irq demux */ | ||
63 | unsigned out; /* software latch */ | 71 | unsigned out; /* software latch */ |
72 | unsigned status; /* current status */ | ||
73 | int irq; /* real irq number */ | ||
64 | 74 | ||
65 | int (*write)(struct i2c_client *client, unsigned data); | 75 | int (*write)(struct i2c_client *client, unsigned data); |
66 | int (*read)(struct i2c_client *client); | 76 | int (*read)(struct i2c_client *client); |
@@ -150,6 +160,100 @@ static void pcf857x_set(struct gpio_chip *chip, unsigned offset, int value) | |||
150 | 160 | ||
151 | /*-------------------------------------------------------------------------*/ | 161 | /*-------------------------------------------------------------------------*/ |
152 | 162 | ||
163 | static int pcf857x_to_irq(struct gpio_chip *chip, unsigned offset) | ||
164 | { | ||
165 | struct pcf857x *gpio = container_of(chip, struct pcf857x, chip); | ||
166 | |||
167 | return irq_create_mapping(gpio->irq_domain, offset); | ||
168 | } | ||
169 | |||
170 | static void pcf857x_irq_demux_work(struct work_struct *work) | ||
171 | { | ||
172 | struct pcf857x *gpio = container_of(work, | ||
173 | struct pcf857x, | ||
174 | work); | ||
175 | unsigned long change, i, status, flags; | ||
176 | |||
177 | status = gpio->read(gpio->client); | ||
178 | |||
179 | spin_lock_irqsave(&gpio->slock, flags); | ||
180 | |||
181 | change = gpio->status ^ status; | ||
182 | for_each_set_bit(i, &change, gpio->chip.ngpio) | ||
183 | generic_handle_irq(irq_find_mapping(gpio->irq_domain, i)); | ||
184 | gpio->status = status; | ||
185 | |||
186 | spin_unlock_irqrestore(&gpio->slock, flags); | ||
187 | } | ||
188 | |||
189 | static irqreturn_t pcf857x_irq_demux(int irq, void *data) | ||
190 | { | ||
191 | struct pcf857x *gpio = data; | ||
192 | |||
193 | /* | ||
194 | * pcf857x can't read/write data here, | ||
195 | * since i2c data access might go to sleep. | ||
196 | */ | ||
197 | schedule_work(&gpio->work); | ||
198 | |||
199 | return IRQ_HANDLED; | ||
200 | } | ||
201 | |||
202 | static int pcf857x_irq_domain_map(struct irq_domain *domain, unsigned int virq, | ||
203 | irq_hw_number_t hw) | ||
204 | { | ||
205 | irq_set_chip_and_handler(virq, | ||
206 | &dummy_irq_chip, | ||
207 | handle_level_irq); | ||
208 | return 0; | ||
209 | } | ||
210 | |||
211 | static struct irq_domain_ops pcf857x_irq_domain_ops = { | ||
212 | .map = pcf857x_irq_domain_map, | ||
213 | }; | ||
214 | |||
215 | static void pcf857x_irq_domain_cleanup(struct pcf857x *gpio) | ||
216 | { | ||
217 | if (gpio->irq_domain) | ||
218 | irq_domain_remove(gpio->irq_domain); | ||
219 | |||
220 | if (gpio->irq) | ||
221 | free_irq(gpio->irq, gpio); | ||
222 | } | ||
223 | |||
224 | static int pcf857x_irq_domain_init(struct pcf857x *gpio, | ||
225 | struct pcf857x_platform_data *pdata, | ||
226 | struct device *dev) | ||
227 | { | ||
228 | int status; | ||
229 | |||
230 | gpio->irq_domain = irq_domain_add_linear(dev->of_node, | ||
231 | gpio->chip.ngpio, | ||
232 | &pcf857x_irq_domain_ops, | ||
233 | NULL); | ||
234 | if (!gpio->irq_domain) | ||
235 | goto fail; | ||
236 | |||
237 | /* enable real irq */ | ||
238 | status = request_irq(pdata->irq, pcf857x_irq_demux, 0, | ||
239 | dev_name(dev), gpio); | ||
240 | if (status) | ||
241 | goto fail; | ||
242 | |||
243 | /* enable gpio_to_irq() */ | ||
244 | INIT_WORK(&gpio->work, pcf857x_irq_demux_work); | ||
245 | gpio->chip.to_irq = pcf857x_to_irq; | ||
246 | gpio->irq = pdata->irq; | ||
247 | |||
248 | return 0; | ||
249 | |||
250 | fail: | ||
251 | pcf857x_irq_domain_cleanup(gpio); | ||
252 | return -EINVAL; | ||
253 | } | ||
254 | |||
255 | /*-------------------------------------------------------------------------*/ | ||
256 | |||
153 | static int pcf857x_probe(struct i2c_client *client, | 257 | static int pcf857x_probe(struct i2c_client *client, |
154 | const struct i2c_device_id *id) | 258 | const struct i2c_device_id *id) |
155 | { | 259 | { |
@@ -168,6 +272,7 @@ static int pcf857x_probe(struct i2c_client *client, | |||
168 | return -ENOMEM; | 272 | return -ENOMEM; |
169 | 273 | ||
170 | mutex_init(&gpio->lock); | 274 | mutex_init(&gpio->lock); |
275 | spin_lock_init(&gpio->slock); | ||
171 | 276 | ||
172 | gpio->chip.base = pdata ? pdata->gpio_base : -1; | 277 | gpio->chip.base = pdata ? pdata->gpio_base : -1; |
173 | gpio->chip.can_sleep = 1; | 278 | gpio->chip.can_sleep = 1; |
@@ -179,6 +284,15 @@ static int pcf857x_probe(struct i2c_client *client, | |||
179 | gpio->chip.direction_output = pcf857x_output; | 284 | gpio->chip.direction_output = pcf857x_output; |
180 | gpio->chip.ngpio = id->driver_data; | 285 | gpio->chip.ngpio = id->driver_data; |
181 | 286 | ||
287 | /* enable gpio_to_irq() if platform has settings */ | ||
288 | if (pdata && pdata->irq) { | ||
289 | status = pcf857x_irq_domain_init(gpio, pdata, &client->dev); | ||
290 | if (status < 0) { | ||
291 | dev_err(&client->dev, "irq_domain init failed\n"); | ||
292 | goto fail; | ||
293 | } | ||
294 | } | ||
295 | |||
182 | /* NOTE: the OnSemi jlc1562b is also largely compatible with | 296 | /* NOTE: the OnSemi jlc1562b is also largely compatible with |
183 | * these parts, notably for output. It has a low-resolution | 297 | * these parts, notably for output. It has a low-resolution |
184 | * DAC instead of pin change IRQs; and its inputs can be the | 298 | * DAC instead of pin change IRQs; and its inputs can be the |
@@ -248,6 +362,7 @@ static int pcf857x_probe(struct i2c_client *client, | |||
248 | * all-ones reset state. Otherwise it flags pins to be driven low. | 362 | * all-ones reset state. Otherwise it flags pins to be driven low. |
249 | */ | 363 | */ |
250 | gpio->out = pdata ? ~pdata->n_latch : ~0; | 364 | gpio->out = pdata ? ~pdata->n_latch : ~0; |
365 | gpio->status = gpio->out; | ||
251 | 366 | ||
252 | status = gpiochip_add(&gpio->chip); | 367 | status = gpiochip_add(&gpio->chip); |
253 | if (status < 0) | 368 | if (status < 0) |
@@ -278,6 +393,10 @@ static int pcf857x_probe(struct i2c_client *client, | |||
278 | fail: | 393 | fail: |
279 | dev_dbg(&client->dev, "probe error %d for '%s'\n", | 394 | dev_dbg(&client->dev, "probe error %d for '%s'\n", |
280 | status, client->name); | 395 | status, client->name); |
396 | |||
397 | if (pdata && pdata->irq) | ||
398 | pcf857x_irq_domain_cleanup(gpio); | ||
399 | |||
281 | kfree(gpio); | 400 | kfree(gpio); |
282 | return status; | 401 | return status; |
283 | } | 402 | } |
@@ -299,6 +418,9 @@ static int pcf857x_remove(struct i2c_client *client) | |||
299 | } | 418 | } |
300 | } | 419 | } |
301 | 420 | ||
421 | if (pdata && pdata->irq) | ||
422 | pcf857x_irq_domain_cleanup(gpio); | ||
423 | |||
302 | status = gpiochip_remove(&gpio->chip); | 424 | status = gpiochip_remove(&gpio->chip); |
303 | if (status == 0) | 425 | if (status == 0) |
304 | kfree(gpio); | 426 | kfree(gpio); |
diff --git a/drivers/gpio/gpio-pch.c b/drivers/gpio/gpio-pch.c index 139ad3e2001..4ad0c4f9171 100644 --- a/drivers/gpio/gpio-pch.c +++ b/drivers/gpio/gpio-pch.c | |||
@@ -92,9 +92,7 @@ struct pch_gpio_reg_data { | |||
92 | * @lock: Used for register access protection | 92 | * @lock: Used for register access protection |
93 | * @irq_base: Save base of IRQ number for interrupt | 93 | * @irq_base: Save base of IRQ number for interrupt |
94 | * @ioh: IOH ID | 94 | * @ioh: IOH ID |
95 | * @spinlock: Used for register access protection in | 95 | * @spinlock: Used for register access protection |
96 | * interrupt context pch_irq_mask, | ||
97 | * pch_irq_unmask and pch_irq_type; | ||
98 | */ | 96 | */ |
99 | struct pch_gpio { | 97 | struct pch_gpio { |
100 | void __iomem *base; | 98 | void __iomem *base; |
@@ -102,7 +100,6 @@ struct pch_gpio { | |||
102 | struct device *dev; | 100 | struct device *dev; |
103 | struct gpio_chip gpio; | 101 | struct gpio_chip gpio; |
104 | struct pch_gpio_reg_data pch_gpio_reg; | 102 | struct pch_gpio_reg_data pch_gpio_reg; |
105 | struct mutex lock; | ||
106 | int irq_base; | 103 | int irq_base; |
107 | enum pch_type_t ioh; | 104 | enum pch_type_t ioh; |
108 | spinlock_t spinlock; | 105 | spinlock_t spinlock; |
@@ -112,8 +109,9 @@ static void pch_gpio_set(struct gpio_chip *gpio, unsigned nr, int val) | |||
112 | { | 109 | { |
113 | u32 reg_val; | 110 | u32 reg_val; |
114 | struct pch_gpio *chip = container_of(gpio, struct pch_gpio, gpio); | 111 | struct pch_gpio *chip = container_of(gpio, struct pch_gpio, gpio); |
112 | unsigned long flags; | ||
115 | 113 | ||
116 | mutex_lock(&chip->lock); | 114 | spin_lock_irqsave(&chip->spinlock, flags); |
117 | reg_val = ioread32(&chip->reg->po); | 115 | reg_val = ioread32(&chip->reg->po); |
118 | if (val) | 116 | if (val) |
119 | reg_val |= (1 << nr); | 117 | reg_val |= (1 << nr); |
@@ -121,7 +119,7 @@ static void pch_gpio_set(struct gpio_chip *gpio, unsigned nr, int val) | |||
121 | reg_val &= ~(1 << nr); | 119 | reg_val &= ~(1 << nr); |
122 | 120 | ||
123 | iowrite32(reg_val, &chip->reg->po); | 121 | iowrite32(reg_val, &chip->reg->po); |
124 | mutex_unlock(&chip->lock); | 122 | spin_unlock_irqrestore(&chip->spinlock, flags); |
125 | } | 123 | } |
126 | 124 | ||
127 | static int pch_gpio_get(struct gpio_chip *gpio, unsigned nr) | 125 | static int pch_gpio_get(struct gpio_chip *gpio, unsigned nr) |
@@ -137,8 +135,9 @@ static int pch_gpio_direction_output(struct gpio_chip *gpio, unsigned nr, | |||
137 | struct pch_gpio *chip = container_of(gpio, struct pch_gpio, gpio); | 135 | struct pch_gpio *chip = container_of(gpio, struct pch_gpio, gpio); |
138 | u32 pm; | 136 | u32 pm; |
139 | u32 reg_val; | 137 | u32 reg_val; |
138 | unsigned long flags; | ||
140 | 139 | ||
141 | mutex_lock(&chip->lock); | 140 | spin_lock_irqsave(&chip->spinlock, flags); |
142 | pm = ioread32(&chip->reg->pm) & ((1 << gpio_pins[chip->ioh]) - 1); | 141 | pm = ioread32(&chip->reg->pm) & ((1 << gpio_pins[chip->ioh]) - 1); |
143 | pm |= (1 << nr); | 142 | pm |= (1 << nr); |
144 | iowrite32(pm, &chip->reg->pm); | 143 | iowrite32(pm, &chip->reg->pm); |
@@ -149,8 +148,7 @@ static int pch_gpio_direction_output(struct gpio_chip *gpio, unsigned nr, | |||
149 | else | 148 | else |
150 | reg_val &= ~(1 << nr); | 149 | reg_val &= ~(1 << nr); |
151 | iowrite32(reg_val, &chip->reg->po); | 150 | iowrite32(reg_val, &chip->reg->po); |
152 | 151 | spin_unlock_irqrestore(&chip->spinlock, flags); | |
153 | mutex_unlock(&chip->lock); | ||
154 | 152 | ||
155 | return 0; | 153 | return 0; |
156 | } | 154 | } |
@@ -159,12 +157,13 @@ static int pch_gpio_direction_input(struct gpio_chip *gpio, unsigned nr) | |||
159 | { | 157 | { |
160 | struct pch_gpio *chip = container_of(gpio, struct pch_gpio, gpio); | 158 | struct pch_gpio *chip = container_of(gpio, struct pch_gpio, gpio); |
161 | u32 pm; | 159 | u32 pm; |
160 | unsigned long flags; | ||
162 | 161 | ||
163 | mutex_lock(&chip->lock); | 162 | spin_lock_irqsave(&chip->spinlock, flags); |
164 | pm = ioread32(&chip->reg->pm) & ((1 << gpio_pins[chip->ioh]) - 1); | 163 | pm = ioread32(&chip->reg->pm) & ((1 << gpio_pins[chip->ioh]) - 1); |
165 | pm &= ~(1 << nr); | 164 | pm &= ~(1 << nr); |
166 | iowrite32(pm, &chip->reg->pm); | 165 | iowrite32(pm, &chip->reg->pm); |
167 | mutex_unlock(&chip->lock); | 166 | spin_unlock_irqrestore(&chip->spinlock, flags); |
168 | 167 | ||
169 | return 0; | 168 | return 0; |
170 | } | 169 | } |
@@ -387,7 +386,6 @@ static int __devinit pch_gpio_probe(struct pci_dev *pdev, | |||
387 | 386 | ||
388 | chip->reg = chip->base; | 387 | chip->reg = chip->base; |
389 | pci_set_drvdata(pdev, chip); | 388 | pci_set_drvdata(pdev, chip); |
390 | mutex_init(&chip->lock); | ||
391 | spin_lock_init(&chip->spinlock); | 389 | spin_lock_init(&chip->spinlock); |
392 | pch_gpio_setup(chip); | 390 | pch_gpio_setup(chip); |
393 | ret = gpiochip_add(&chip->gpio); | 391 | ret = gpiochip_add(&chip->gpio); |
diff --git a/drivers/gpio/gpio-pxa.c b/drivers/gpio/gpio-pxa.c index 9528779ca46..98d52cb3fd1 100644 --- a/drivers/gpio/gpio-pxa.c +++ b/drivers/gpio/gpio-pxa.c | |||
@@ -370,12 +370,10 @@ static void pxa_gpio_demux_handler(unsigned int irq, struct irq_desc *desc) | |||
370 | gedr = gedr & c->irq_mask; | 370 | gedr = gedr & c->irq_mask; |
371 | writel_relaxed(gedr, c->regbase + GEDR_OFFSET); | 371 | writel_relaxed(gedr, c->regbase + GEDR_OFFSET); |
372 | 372 | ||
373 | n = find_first_bit(&gedr, BITS_PER_LONG); | 373 | for_each_set_bit(n, &gedr, BITS_PER_LONG) { |
374 | while (n < BITS_PER_LONG) { | ||
375 | loop = 1; | 374 | loop = 1; |
376 | 375 | ||
377 | generic_handle_irq(gpio_to_irq(gpio_base + n)); | 376 | generic_handle_irq(gpio_to_irq(gpio_base + n)); |
378 | n = find_next_bit(&gedr, BITS_PER_LONG, n + 1); | ||
379 | } | 377 | } |
380 | } | 378 | } |
381 | } while (loop); | 379 | } while (loop); |
@@ -589,19 +587,12 @@ static int __devinit pxa_gpio_probe(struct platform_device *pdev) | |||
589 | iounmap(gpio_reg_base); | 587 | iounmap(gpio_reg_base); |
590 | return PTR_ERR(clk); | 588 | return PTR_ERR(clk); |
591 | } | 589 | } |
592 | ret = clk_prepare(clk); | 590 | ret = clk_prepare_enable(clk); |
593 | if (ret) { | 591 | if (ret) { |
594 | clk_put(clk); | 592 | clk_put(clk); |
595 | iounmap(gpio_reg_base); | 593 | iounmap(gpio_reg_base); |
596 | return ret; | 594 | return ret; |
597 | } | 595 | } |
598 | ret = clk_enable(clk); | ||
599 | if (ret) { | ||
600 | clk_unprepare(clk); | ||
601 | clk_put(clk); | ||
602 | iounmap(gpio_reg_base); | ||
603 | return ret; | ||
604 | } | ||
605 | 596 | ||
606 | /* Initialize GPIO chips */ | 597 | /* Initialize GPIO chips */ |
607 | info = dev_get_platdata(&pdev->dev); | 598 | info = dev_get_platdata(&pdev->dev); |
diff --git a/drivers/gpio/gpio-sodaville.c b/drivers/gpio/gpio-sodaville.c index 9d9891f7a60..e25f73130b4 100644 --- a/drivers/gpio/gpio-sodaville.c +++ b/drivers/gpio/gpio-sodaville.c | |||
@@ -270,7 +270,7 @@ static void sdv_gpio_remove(struct pci_dev *pdev) | |||
270 | kfree(sd); | 270 | kfree(sd); |
271 | } | 271 | } |
272 | 272 | ||
273 | static struct pci_device_id sdv_gpio_pci_ids[] __devinitdata = { | 273 | static DEFINE_PCI_DEVICE_TABLE(sdv_gpio_pci_ids) = { |
274 | { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_SDV_GPIO) }, | 274 | { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_SDV_GPIO) }, |
275 | { 0, }, | 275 | { 0, }, |
276 | }; | 276 | }; |
diff --git a/drivers/gpio/gpio-sx150x.c b/drivers/gpio/gpio-sx150x.c index a4f73534394..eb3e215d239 100644 --- a/drivers/gpio/gpio-sx150x.c +++ b/drivers/gpio/gpio-sx150x.c | |||
@@ -311,11 +311,9 @@ static int sx150x_gpio_to_irq(struct gpio_chip *gc, unsigned offset) | |||
311 | 311 | ||
312 | static void sx150x_irq_mask(struct irq_data *d) | 312 | static void sx150x_irq_mask(struct irq_data *d) |
313 | { | 313 | { |
314 | struct irq_chip *ic = irq_data_get_irq_chip(d); | 314 | struct sx150x_chip *chip = irq_data_get_irq_chip_data(d); |
315 | struct sx150x_chip *chip; | ||
316 | unsigned n; | 315 | unsigned n; |
317 | 316 | ||
318 | chip = container_of(ic, struct sx150x_chip, irq_chip); | ||
319 | n = d->irq - chip->irq_base; | 317 | n = d->irq - chip->irq_base; |
320 | chip->irq_masked |= (1 << n); | 318 | chip->irq_masked |= (1 << n); |
321 | chip->irq_update = n; | 319 | chip->irq_update = n; |
@@ -323,27 +321,22 @@ static void sx150x_irq_mask(struct irq_data *d) | |||
323 | 321 | ||
324 | static void sx150x_irq_unmask(struct irq_data *d) | 322 | static void sx150x_irq_unmask(struct irq_data *d) |
325 | { | 323 | { |
326 | struct irq_chip *ic = irq_data_get_irq_chip(d); | 324 | struct sx150x_chip *chip = irq_data_get_irq_chip_data(d); |
327 | struct sx150x_chip *chip; | ||
328 | unsigned n; | 325 | unsigned n; |
329 | 326 | ||
330 | chip = container_of(ic, struct sx150x_chip, irq_chip); | ||
331 | n = d->irq - chip->irq_base; | 327 | n = d->irq - chip->irq_base; |
332 | |||
333 | chip->irq_masked &= ~(1 << n); | 328 | chip->irq_masked &= ~(1 << n); |
334 | chip->irq_update = n; | 329 | chip->irq_update = n; |
335 | } | 330 | } |
336 | 331 | ||
337 | static int sx150x_irq_set_type(struct irq_data *d, unsigned int flow_type) | 332 | static int sx150x_irq_set_type(struct irq_data *d, unsigned int flow_type) |
338 | { | 333 | { |
339 | struct irq_chip *ic = irq_data_get_irq_chip(d); | 334 | struct sx150x_chip *chip = irq_data_get_irq_chip_data(d); |
340 | struct sx150x_chip *chip; | ||
341 | unsigned n, val = 0; | 335 | unsigned n, val = 0; |
342 | 336 | ||
343 | if (flow_type & (IRQ_TYPE_LEVEL_HIGH | IRQ_TYPE_LEVEL_LOW)) | 337 | if (flow_type & (IRQ_TYPE_LEVEL_HIGH | IRQ_TYPE_LEVEL_LOW)) |
344 | return -EINVAL; | 338 | return -EINVAL; |
345 | 339 | ||
346 | chip = container_of(ic, struct sx150x_chip, irq_chip); | ||
347 | n = d->irq - chip->irq_base; | 340 | n = d->irq - chip->irq_base; |
348 | 341 | ||
349 | if (flow_type & IRQ_TYPE_EDGE_RISING) | 342 | if (flow_type & IRQ_TYPE_EDGE_RISING) |
@@ -391,22 +384,16 @@ static irqreturn_t sx150x_irq_thread_fn(int irq, void *dev_id) | |||
391 | 384 | ||
392 | static void sx150x_irq_bus_lock(struct irq_data *d) | 385 | static void sx150x_irq_bus_lock(struct irq_data *d) |
393 | { | 386 | { |
394 | struct irq_chip *ic = irq_data_get_irq_chip(d); | 387 | struct sx150x_chip *chip = irq_data_get_irq_chip_data(d); |
395 | struct sx150x_chip *chip; | ||
396 | |||
397 | chip = container_of(ic, struct sx150x_chip, irq_chip); | ||
398 | 388 | ||
399 | mutex_lock(&chip->lock); | 389 | mutex_lock(&chip->lock); |
400 | } | 390 | } |
401 | 391 | ||
402 | static void sx150x_irq_bus_sync_unlock(struct irq_data *d) | 392 | static void sx150x_irq_bus_sync_unlock(struct irq_data *d) |
403 | { | 393 | { |
404 | struct irq_chip *ic = irq_data_get_irq_chip(d); | 394 | struct sx150x_chip *chip = irq_data_get_irq_chip_data(d); |
405 | struct sx150x_chip *chip; | ||
406 | unsigned n; | 395 | unsigned n; |
407 | 396 | ||
408 | chip = container_of(ic, struct sx150x_chip, irq_chip); | ||
409 | |||
410 | if (chip->irq_update == NO_UPDATE_PENDING) | 397 | if (chip->irq_update == NO_UPDATE_PENDING) |
411 | goto out; | 398 | goto out; |
412 | 399 | ||
@@ -551,6 +538,7 @@ static int sx150x_install_irq_chip(struct sx150x_chip *chip, | |||
551 | 538 | ||
552 | for (n = 0; n < chip->dev_cfg->ngpios; ++n) { | 539 | for (n = 0; n < chip->dev_cfg->ngpios; ++n) { |
553 | irq = irq_base + n; | 540 | irq = irq_base + n; |
541 | irq_set_chip_data(irq, chip); | ||
554 | irq_set_chip_and_handler(irq, &chip->irq_chip, handle_edge_irq); | 542 | irq_set_chip_and_handler(irq, &chip->irq_chip, handle_edge_irq); |
555 | irq_set_nested_thread(irq, 1); | 543 | irq_set_nested_thread(irq, 1); |
556 | #ifdef CONFIG_ARM | 544 | #ifdef CONFIG_ARM |
diff --git a/drivers/gpio/gpio-tc3589x.c b/drivers/gpio/gpio-tc3589x.c index 2a82e8999a4..1e48317e70f 100644 --- a/drivers/gpio/gpio-tc3589x.c +++ b/drivers/gpio/gpio-tc3589x.c | |||
@@ -11,7 +11,9 @@ | |||
11 | #include <linux/platform_device.h> | 11 | #include <linux/platform_device.h> |
12 | #include <linux/slab.h> | 12 | #include <linux/slab.h> |
13 | #include <linux/gpio.h> | 13 | #include <linux/gpio.h> |
14 | #include <linux/of.h> | ||
14 | #include <linux/irq.h> | 15 | #include <linux/irq.h> |
16 | #include <linux/irqdomain.h> | ||
15 | #include <linux/interrupt.h> | 17 | #include <linux/interrupt.h> |
16 | #include <linux/mfd/tc3589x.h> | 18 | #include <linux/mfd/tc3589x.h> |
17 | 19 | ||
@@ -29,6 +31,7 @@ struct tc3589x_gpio { | |||
29 | struct tc3589x *tc3589x; | 31 | struct tc3589x *tc3589x; |
30 | struct device *dev; | 32 | struct device *dev; |
31 | struct mutex irq_lock; | 33 | struct mutex irq_lock; |
34 | struct irq_domain *domain; | ||
32 | 35 | ||
33 | int irq_base; | 36 | int irq_base; |
34 | 37 | ||
@@ -92,11 +95,28 @@ static int tc3589x_gpio_direction_input(struct gpio_chip *chip, | |||
92 | return tc3589x_set_bits(tc3589x, reg, 1 << pos, 0); | 95 | return tc3589x_set_bits(tc3589x, reg, 1 << pos, 0); |
93 | } | 96 | } |
94 | 97 | ||
98 | /** | ||
99 | * tc3589x_gpio_irq_get_virq(): Map an interrupt on a chip to a virtual IRQ | ||
100 | * | ||
101 | * @tc3589x_gpio: tc3589x_gpio_irq controller to operate on. | ||
102 | * @irq: index of the interrupt requested in the chip IRQs | ||
103 | * | ||
104 | * Useful for drivers to request their own IRQs. | ||
105 | */ | ||
106 | static int tc3589x_gpio_irq_get_virq(struct tc3589x_gpio *tc3589x_gpio, | ||
107 | int irq) | ||
108 | { | ||
109 | if (!tc3589x_gpio) | ||
110 | return -EINVAL; | ||
111 | |||
112 | return irq_create_mapping(tc3589x_gpio->domain, irq); | ||
113 | } | ||
114 | |||
95 | static int tc3589x_gpio_to_irq(struct gpio_chip *chip, unsigned offset) | 115 | static int tc3589x_gpio_to_irq(struct gpio_chip *chip, unsigned offset) |
96 | { | 116 | { |
97 | struct tc3589x_gpio *tc3589x_gpio = to_tc3589x_gpio(chip); | 117 | struct tc3589x_gpio *tc3589x_gpio = to_tc3589x_gpio(chip); |
98 | 118 | ||
99 | return tc3589x_gpio->irq_base + offset; | 119 | return tc3589x_gpio_irq_get_virq(tc3589x_gpio, offset); |
100 | } | 120 | } |
101 | 121 | ||
102 | static struct gpio_chip template_chip = { | 122 | static struct gpio_chip template_chip = { |
@@ -113,7 +133,7 @@ static struct gpio_chip template_chip = { | |||
113 | static int tc3589x_gpio_irq_set_type(struct irq_data *d, unsigned int type) | 133 | static int tc3589x_gpio_irq_set_type(struct irq_data *d, unsigned int type) |
114 | { | 134 | { |
115 | struct tc3589x_gpio *tc3589x_gpio = irq_data_get_irq_chip_data(d); | 135 | struct tc3589x_gpio *tc3589x_gpio = irq_data_get_irq_chip_data(d); |
116 | int offset = d->irq - tc3589x_gpio->irq_base; | 136 | int offset = d->hwirq; |
117 | int regoffset = offset / 8; | 137 | int regoffset = offset / 8; |
118 | int mask = 1 << (offset % 8); | 138 | int mask = 1 << (offset % 8); |
119 | 139 | ||
@@ -175,7 +195,7 @@ static void tc3589x_gpio_irq_sync_unlock(struct irq_data *d) | |||
175 | static void tc3589x_gpio_irq_mask(struct irq_data *d) | 195 | static void tc3589x_gpio_irq_mask(struct irq_data *d) |
176 | { | 196 | { |
177 | struct tc3589x_gpio *tc3589x_gpio = irq_data_get_irq_chip_data(d); | 197 | struct tc3589x_gpio *tc3589x_gpio = irq_data_get_irq_chip_data(d); |
178 | int offset = d->irq - tc3589x_gpio->irq_base; | 198 | int offset = d->hwirq; |
179 | int regoffset = offset / 8; | 199 | int regoffset = offset / 8; |
180 | int mask = 1 << (offset % 8); | 200 | int mask = 1 << (offset % 8); |
181 | 201 | ||
@@ -185,7 +205,7 @@ static void tc3589x_gpio_irq_mask(struct irq_data *d) | |||
185 | static void tc3589x_gpio_irq_unmask(struct irq_data *d) | 205 | static void tc3589x_gpio_irq_unmask(struct irq_data *d) |
186 | { | 206 | { |
187 | struct tc3589x_gpio *tc3589x_gpio = irq_data_get_irq_chip_data(d); | 207 | struct tc3589x_gpio *tc3589x_gpio = irq_data_get_irq_chip_data(d); |
188 | int offset = d->irq - tc3589x_gpio->irq_base; | 208 | int offset = d->hwirq; |
189 | int regoffset = offset / 8; | 209 | int regoffset = offset / 8; |
190 | int mask = 1 << (offset % 8); | 210 | int mask = 1 << (offset % 8); |
191 | 211 | ||
@@ -222,8 +242,9 @@ static irqreturn_t tc3589x_gpio_irq(int irq, void *dev) | |||
222 | while (stat) { | 242 | while (stat) { |
223 | int bit = __ffs(stat); | 243 | int bit = __ffs(stat); |
224 | int line = i * 8 + bit; | 244 | int line = i * 8 + bit; |
245 | int virq = tc3589x_gpio_irq_get_virq(tc3589x_gpio, line); | ||
225 | 246 | ||
226 | handle_nested_irq(tc3589x_gpio->irq_base + line); | 247 | handle_nested_irq(virq); |
227 | stat &= ~(1 << bit); | 248 | stat &= ~(1 << bit); |
228 | } | 249 | } |
229 | 250 | ||
@@ -233,51 +254,78 @@ static irqreturn_t tc3589x_gpio_irq(int irq, void *dev) | |||
233 | return IRQ_HANDLED; | 254 | return IRQ_HANDLED; |
234 | } | 255 | } |
235 | 256 | ||
236 | static int tc3589x_gpio_irq_init(struct tc3589x_gpio *tc3589x_gpio) | 257 | static int tc3589x_gpio_irq_map(struct irq_domain *d, unsigned int virq, |
258 | irq_hw_number_t hwirq) | ||
237 | { | 259 | { |
238 | int base = tc3589x_gpio->irq_base; | 260 | struct tc3589x *tc3589x_gpio = d->host_data; |
239 | int irq; | ||
240 | 261 | ||
241 | for (irq = base; irq < base + tc3589x_gpio->chip.ngpio; irq++) { | 262 | irq_set_chip_data(virq, tc3589x_gpio); |
242 | irq_set_chip_data(irq, tc3589x_gpio); | 263 | irq_set_chip_and_handler(virq, &tc3589x_gpio_irq_chip, |
243 | irq_set_chip_and_handler(irq, &tc3589x_gpio_irq_chip, | 264 | handle_simple_irq); |
244 | handle_simple_irq); | 265 | irq_set_nested_thread(virq, 1); |
245 | irq_set_nested_thread(irq, 1); | ||
246 | #ifdef CONFIG_ARM | 266 | #ifdef CONFIG_ARM |
247 | set_irq_flags(irq, IRQF_VALID); | 267 | set_irq_flags(virq, IRQF_VALID); |
248 | #else | 268 | #else |
249 | irq_set_noprobe(irq); | 269 | irq_set_noprobe(virq); |
250 | #endif | 270 | #endif |
251 | } | ||
252 | 271 | ||
253 | return 0; | 272 | return 0; |
254 | } | 273 | } |
255 | 274 | ||
256 | static void tc3589x_gpio_irq_remove(struct tc3589x_gpio *tc3589x_gpio) | 275 | static void tc3589x_gpio_irq_unmap(struct irq_domain *d, unsigned int virq) |
257 | { | 276 | { |
258 | int base = tc3589x_gpio->irq_base; | ||
259 | int irq; | ||
260 | |||
261 | for (irq = base; irq < base + tc3589x_gpio->chip.ngpio; irq++) { | ||
262 | #ifdef CONFIG_ARM | 277 | #ifdef CONFIG_ARM |
263 | set_irq_flags(irq, 0); | 278 | set_irq_flags(virq, 0); |
264 | #endif | 279 | #endif |
265 | irq_set_chip_and_handler(irq, NULL, NULL); | 280 | irq_set_chip_and_handler(virq, NULL, NULL); |
266 | irq_set_chip_data(irq, NULL); | 281 | irq_set_chip_data(virq, NULL); |
282 | } | ||
283 | |||
284 | static struct irq_domain_ops tc3589x_irq_ops = { | ||
285 | .map = tc3589x_gpio_irq_map, | ||
286 | .unmap = tc3589x_gpio_irq_unmap, | ||
287 | .xlate = irq_domain_xlate_twocell, | ||
288 | }; | ||
289 | |||
290 | static int tc3589x_gpio_irq_init(struct tc3589x_gpio *tc3589x_gpio, | ||
291 | struct device_node *np) | ||
292 | { | ||
293 | int base = tc3589x_gpio->irq_base; | ||
294 | |||
295 | if (base) { | ||
296 | tc3589x_gpio->domain = irq_domain_add_legacy( | ||
297 | NULL, tc3589x_gpio->chip.ngpio, base, | ||
298 | 0, &tc3589x_irq_ops, tc3589x_gpio); | ||
299 | } | ||
300 | else { | ||
301 | tc3589x_gpio->domain = irq_domain_add_linear( | ||
302 | np, tc3589x_gpio->chip.ngpio, | ||
303 | &tc3589x_irq_ops, tc3589x_gpio); | ||
304 | } | ||
305 | |||
306 | if (!tc3589x_gpio->domain) { | ||
307 | dev_err(tc3589x_gpio->dev, "Failed to create irqdomain\n"); | ||
308 | return -ENOSYS; | ||
267 | } | 309 | } |
310 | |||
311 | return 0; | ||
268 | } | 312 | } |
269 | 313 | ||
270 | static int __devinit tc3589x_gpio_probe(struct platform_device *pdev) | 314 | static int __devinit tc3589x_gpio_probe(struct platform_device *pdev) |
271 | { | 315 | { |
272 | struct tc3589x *tc3589x = dev_get_drvdata(pdev->dev.parent); | 316 | struct tc3589x *tc3589x = dev_get_drvdata(pdev->dev.parent); |
273 | struct tc3589x_gpio_platform_data *pdata; | 317 | struct tc3589x_gpio_platform_data *pdata; |
318 | struct device_node *np = pdev->dev.of_node; | ||
274 | struct tc3589x_gpio *tc3589x_gpio; | 319 | struct tc3589x_gpio *tc3589x_gpio; |
275 | int ret; | 320 | int ret; |
276 | int irq; | 321 | int irq; |
277 | 322 | ||
278 | pdata = tc3589x->pdata->gpio; | 323 | pdata = tc3589x->pdata->gpio; |
279 | if (!pdata) | 324 | |
280 | return -ENODEV; | 325 | if (!(pdata || np)) { |
326 | dev_err(&pdev->dev, "No platform data or Device Tree found\n"); | ||
327 | return -EINVAL; | ||
328 | } | ||
281 | 329 | ||
282 | irq = platform_get_irq(pdev, 0); | 330 | irq = platform_get_irq(pdev, 0); |
283 | if (irq < 0) | 331 | if (irq < 0) |
@@ -295,9 +343,14 @@ static int __devinit tc3589x_gpio_probe(struct platform_device *pdev) | |||
295 | tc3589x_gpio->chip = template_chip; | 343 | tc3589x_gpio->chip = template_chip; |
296 | tc3589x_gpio->chip.ngpio = tc3589x->num_gpio; | 344 | tc3589x_gpio->chip.ngpio = tc3589x->num_gpio; |
297 | tc3589x_gpio->chip.dev = &pdev->dev; | 345 | tc3589x_gpio->chip.dev = &pdev->dev; |
298 | tc3589x_gpio->chip.base = pdata->gpio_base; | 346 | tc3589x_gpio->chip.base = (pdata) ? pdata->gpio_base : -1; |
299 | 347 | ||
300 | tc3589x_gpio->irq_base = tc3589x->irq_base + TC3589x_INT_GPIO(0); | 348 | #ifdef CONFIG_OF_GPIO |
349 | tc3589x_gpio->chip.of_node = np; | ||
350 | #endif | ||
351 | |||
352 | tc3589x_gpio->irq_base = tc3589x->irq_base ? | ||
353 | tc3589x->irq_base + TC3589x_INT_GPIO(0) : 0; | ||
301 | 354 | ||
302 | /* Bring the GPIO module out of reset */ | 355 | /* Bring the GPIO module out of reset */ |
303 | ret = tc3589x_set_bits(tc3589x, TC3589x_RSTCTRL, | 356 | ret = tc3589x_set_bits(tc3589x, TC3589x_RSTCTRL, |
@@ -305,7 +358,7 @@ static int __devinit tc3589x_gpio_probe(struct platform_device *pdev) | |||
305 | if (ret < 0) | 358 | if (ret < 0) |
306 | goto out_free; | 359 | goto out_free; |
307 | 360 | ||
308 | ret = tc3589x_gpio_irq_init(tc3589x_gpio); | 361 | ret = tc3589x_gpio_irq_init(tc3589x_gpio, np); |
309 | if (ret) | 362 | if (ret) |
310 | goto out_free; | 363 | goto out_free; |
311 | 364 | ||
@@ -313,7 +366,7 @@ static int __devinit tc3589x_gpio_probe(struct platform_device *pdev) | |||
313 | "tc3589x-gpio", tc3589x_gpio); | 366 | "tc3589x-gpio", tc3589x_gpio); |
314 | if (ret) { | 367 | if (ret) { |
315 | dev_err(&pdev->dev, "unable to get irq: %d\n", ret); | 368 | dev_err(&pdev->dev, "unable to get irq: %d\n", ret); |
316 | goto out_removeirq; | 369 | goto out_free; |
317 | } | 370 | } |
318 | 371 | ||
319 | ret = gpiochip_add(&tc3589x_gpio->chip); | 372 | ret = gpiochip_add(&tc3589x_gpio->chip); |
@@ -322,7 +375,7 @@ static int __devinit tc3589x_gpio_probe(struct platform_device *pdev) | |||
322 | goto out_freeirq; | 375 | goto out_freeirq; |
323 | } | 376 | } |
324 | 377 | ||
325 | if (pdata->setup) | 378 | if (pdata && pdata->setup) |
326 | pdata->setup(tc3589x, tc3589x_gpio->chip.base); | 379 | pdata->setup(tc3589x, tc3589x_gpio->chip.base); |
327 | 380 | ||
328 | platform_set_drvdata(pdev, tc3589x_gpio); | 381 | platform_set_drvdata(pdev, tc3589x_gpio); |
@@ -331,8 +384,6 @@ static int __devinit tc3589x_gpio_probe(struct platform_device *pdev) | |||
331 | 384 | ||
332 | out_freeirq: | 385 | out_freeirq: |
333 | free_irq(irq, tc3589x_gpio); | 386 | free_irq(irq, tc3589x_gpio); |
334 | out_removeirq: | ||
335 | tc3589x_gpio_irq_remove(tc3589x_gpio); | ||
336 | out_free: | 387 | out_free: |
337 | kfree(tc3589x_gpio); | 388 | kfree(tc3589x_gpio); |
338 | return ret; | 389 | return ret; |
@@ -346,7 +397,7 @@ static int __devexit tc3589x_gpio_remove(struct platform_device *pdev) | |||
346 | int irq = platform_get_irq(pdev, 0); | 397 | int irq = platform_get_irq(pdev, 0); |
347 | int ret; | 398 | int ret; |
348 | 399 | ||
349 | if (pdata->remove) | 400 | if (pdata && pdata->remove) |
350 | pdata->remove(tc3589x, tc3589x_gpio->chip.base); | 401 | pdata->remove(tc3589x, tc3589x_gpio->chip.base); |
351 | 402 | ||
352 | ret = gpiochip_remove(&tc3589x_gpio->chip); | 403 | ret = gpiochip_remove(&tc3589x_gpio->chip); |
@@ -357,7 +408,6 @@ static int __devexit tc3589x_gpio_remove(struct platform_device *pdev) | |||
357 | } | 408 | } |
358 | 409 | ||
359 | free_irq(irq, tc3589x_gpio); | 410 | free_irq(irq, tc3589x_gpio); |
360 | tc3589x_gpio_irq_remove(tc3589x_gpio); | ||
361 | 411 | ||
362 | platform_set_drvdata(pdev, NULL); | 412 | platform_set_drvdata(pdev, NULL); |
363 | kfree(tc3589x_gpio); | 413 | kfree(tc3589x_gpio); |
diff --git a/drivers/gpio/gpio-tps65912.c b/drivers/gpio/gpio-tps65912.c index 79e66c00235..99106d1e2e5 100644 --- a/drivers/gpio/gpio-tps65912.c +++ b/drivers/gpio/gpio-tps65912.c | |||
@@ -70,7 +70,6 @@ static int tps65912_gpio_input(struct gpio_chip *gc, unsigned offset) | |||
70 | 70 | ||
71 | return tps65912_clear_bits(tps65912, TPS65912_GPIO1 + offset, | 71 | return tps65912_clear_bits(tps65912, TPS65912_GPIO1 + offset, |
72 | GPIO_CFG_MASK); | 72 | GPIO_CFG_MASK); |
73 | |||
74 | } | 73 | } |
75 | 74 | ||
76 | static struct gpio_chip template_chip = { | 75 | static struct gpio_chip template_chip = { |
@@ -92,7 +91,8 @@ static int __devinit tps65912_gpio_probe(struct platform_device *pdev) | |||
92 | struct tps65912_gpio_data *tps65912_gpio; | 91 | struct tps65912_gpio_data *tps65912_gpio; |
93 | int ret; | 92 | int ret; |
94 | 93 | ||
95 | tps65912_gpio = kzalloc(sizeof(*tps65912_gpio), GFP_KERNEL); | 94 | tps65912_gpio = devm_kzalloc(&pdev->dev, sizeof(*tps65912_gpio), |
95 | GFP_KERNEL); | ||
96 | if (tps65912_gpio == NULL) | 96 | if (tps65912_gpio == NULL) |
97 | return -ENOMEM; | 97 | return -ENOMEM; |
98 | 98 | ||
@@ -105,28 +105,19 @@ static int __devinit tps65912_gpio_probe(struct platform_device *pdev) | |||
105 | ret = gpiochip_add(&tps65912_gpio->gpio_chip); | 105 | ret = gpiochip_add(&tps65912_gpio->gpio_chip); |
106 | if (ret < 0) { | 106 | if (ret < 0) { |
107 | dev_err(&pdev->dev, "Failed to register gpiochip, %d\n", ret); | 107 | dev_err(&pdev->dev, "Failed to register gpiochip, %d\n", ret); |
108 | goto err; | 108 | return ret; |
109 | } | 109 | } |
110 | 110 | ||
111 | platform_set_drvdata(pdev, tps65912_gpio); | 111 | platform_set_drvdata(pdev, tps65912_gpio); |
112 | 112 | ||
113 | return ret; | 113 | return ret; |
114 | |||
115 | err: | ||
116 | kfree(tps65912_gpio); | ||
117 | return ret; | ||
118 | } | 114 | } |
119 | 115 | ||
120 | static int __devexit tps65912_gpio_remove(struct platform_device *pdev) | 116 | static int __devexit tps65912_gpio_remove(struct platform_device *pdev) |
121 | { | 117 | { |
122 | struct tps65912_gpio_data *tps65912_gpio = platform_get_drvdata(pdev); | 118 | struct tps65912_gpio_data *tps65912_gpio = platform_get_drvdata(pdev); |
123 | int ret; | ||
124 | |||
125 | ret = gpiochip_remove(&tps65912_gpio->gpio_chip); | ||
126 | if (ret == 0) | ||
127 | kfree(tps65912_gpio); | ||
128 | 119 | ||
129 | return ret; | 120 | return gpiochip_remove(&tps65912_gpio->gpio_chip); |
130 | } | 121 | } |
131 | 122 | ||
132 | static struct platform_driver tps65912_gpio_driver = { | 123 | static struct platform_driver tps65912_gpio_driver = { |
diff --git a/drivers/gpio/gpio-wm831x.c b/drivers/gpio/gpio-wm831x.c index e56a2165641..b6eda35089d 100644 --- a/drivers/gpio/gpio-wm831x.c +++ b/drivers/gpio/gpio-wm831x.c | |||
@@ -250,7 +250,8 @@ static int __devinit wm831x_gpio_probe(struct platform_device *pdev) | |||
250 | struct wm831x_gpio *wm831x_gpio; | 250 | struct wm831x_gpio *wm831x_gpio; |
251 | int ret; | 251 | int ret; |
252 | 252 | ||
253 | wm831x_gpio = kzalloc(sizeof(*wm831x_gpio), GFP_KERNEL); | 253 | wm831x_gpio = devm_kzalloc(&pdev->dev, sizeof(*wm831x_gpio), |
254 | GFP_KERNEL); | ||
254 | if (wm831x_gpio == NULL) | 255 | if (wm831x_gpio == NULL) |
255 | return -ENOMEM; | 256 | return -ENOMEM; |
256 | 257 | ||
@@ -265,30 +266,20 @@ static int __devinit wm831x_gpio_probe(struct platform_device *pdev) | |||
265 | 266 | ||
266 | ret = gpiochip_add(&wm831x_gpio->gpio_chip); | 267 | ret = gpiochip_add(&wm831x_gpio->gpio_chip); |
267 | if (ret < 0) { | 268 | if (ret < 0) { |
268 | dev_err(&pdev->dev, "Could not register gpiochip, %d\n", | 269 | dev_err(&pdev->dev, "Could not register gpiochip, %d\n", ret); |
269 | ret); | 270 | return ret; |
270 | goto err; | ||
271 | } | 271 | } |
272 | 272 | ||
273 | platform_set_drvdata(pdev, wm831x_gpio); | 273 | platform_set_drvdata(pdev, wm831x_gpio); |
274 | 274 | ||
275 | return ret; | 275 | return ret; |
276 | |||
277 | err: | ||
278 | kfree(wm831x_gpio); | ||
279 | return ret; | ||
280 | } | 276 | } |
281 | 277 | ||
282 | static int __devexit wm831x_gpio_remove(struct platform_device *pdev) | 278 | static int __devexit wm831x_gpio_remove(struct platform_device *pdev) |
283 | { | 279 | { |
284 | struct wm831x_gpio *wm831x_gpio = platform_get_drvdata(pdev); | 280 | struct wm831x_gpio *wm831x_gpio = platform_get_drvdata(pdev); |
285 | int ret; | ||
286 | |||
287 | ret = gpiochip_remove(&wm831x_gpio->gpio_chip); | ||
288 | if (ret == 0) | ||
289 | kfree(wm831x_gpio); | ||
290 | 281 | ||
291 | return ret; | 282 | return gpiochip_remove(&wm831x_gpio->gpio_chip); |
292 | } | 283 | } |
293 | 284 | ||
294 | static struct platform_driver wm831x_gpio_driver = { | 285 | static struct platform_driver wm831x_gpio_driver = { |
diff --git a/drivers/gpio/gpio-wm8350.c b/drivers/gpio/gpio-wm8350.c index a06af515483..fb429388939 100644 --- a/drivers/gpio/gpio-wm8350.c +++ b/drivers/gpio/gpio-wm8350.c | |||
@@ -116,7 +116,8 @@ static int __devinit wm8350_gpio_probe(struct platform_device *pdev) | |||
116 | struct wm8350_gpio_data *wm8350_gpio; | 116 | struct wm8350_gpio_data *wm8350_gpio; |
117 | int ret; | 117 | int ret; |
118 | 118 | ||
119 | wm8350_gpio = kzalloc(sizeof(*wm8350_gpio), GFP_KERNEL); | 119 | wm8350_gpio = devm_kzalloc(&pdev->dev, sizeof(*wm8350_gpio), |
120 | GFP_KERNEL); | ||
120 | if (wm8350_gpio == NULL) | 121 | if (wm8350_gpio == NULL) |
121 | return -ENOMEM; | 122 | return -ENOMEM; |
122 | 123 | ||
@@ -131,30 +132,20 @@ static int __devinit wm8350_gpio_probe(struct platform_device *pdev) | |||
131 | 132 | ||
132 | ret = gpiochip_add(&wm8350_gpio->gpio_chip); | 133 | ret = gpiochip_add(&wm8350_gpio->gpio_chip); |
133 | if (ret < 0) { | 134 | if (ret < 0) { |
134 | dev_err(&pdev->dev, "Could not register gpiochip, %d\n", | 135 | dev_err(&pdev->dev, "Could not register gpiochip, %d\n", ret); |
135 | ret); | 136 | return ret; |
136 | goto err; | ||
137 | } | 137 | } |
138 | 138 | ||
139 | platform_set_drvdata(pdev, wm8350_gpio); | 139 | platform_set_drvdata(pdev, wm8350_gpio); |
140 | 140 | ||
141 | return ret; | 141 | return ret; |
142 | |||
143 | err: | ||
144 | kfree(wm8350_gpio); | ||
145 | return ret; | ||
146 | } | 142 | } |
147 | 143 | ||
148 | static int __devexit wm8350_gpio_remove(struct platform_device *pdev) | 144 | static int __devexit wm8350_gpio_remove(struct platform_device *pdev) |
149 | { | 145 | { |
150 | struct wm8350_gpio_data *wm8350_gpio = platform_get_drvdata(pdev); | 146 | struct wm8350_gpio_data *wm8350_gpio = platform_get_drvdata(pdev); |
151 | int ret; | ||
152 | |||
153 | ret = gpiochip_remove(&wm8350_gpio->gpio_chip); | ||
154 | if (ret == 0) | ||
155 | kfree(wm8350_gpio); | ||
156 | 147 | ||
157 | return ret; | 148 | return gpiochip_remove(&wm8350_gpio->gpio_chip); |
158 | } | 149 | } |
159 | 150 | ||
160 | static struct platform_driver wm8350_gpio_driver = { | 151 | static struct platform_driver wm8350_gpio_driver = { |
diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index de0213c9d11..5d6c71edc73 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c | |||
@@ -1773,56 +1773,102 @@ static void gpiolib_dbg_show(struct seq_file *s, struct gpio_chip *chip) | |||
1773 | } | 1773 | } |
1774 | } | 1774 | } |
1775 | 1775 | ||
1776 | static int gpiolib_show(struct seq_file *s, void *unused) | 1776 | static void *gpiolib_seq_start(struct seq_file *s, loff_t *pos) |
1777 | { | 1777 | { |
1778 | struct gpio_chip *chip = NULL; | 1778 | struct gpio_chip *chip = NULL; |
1779 | unsigned gpio; | 1779 | unsigned int gpio; |
1780 | int started = 0; | 1780 | void *ret = NULL; |
1781 | loff_t index = 0; | ||
1781 | 1782 | ||
1782 | /* REVISIT this isn't locked against gpio_chip removal ... */ | 1783 | /* REVISIT this isn't locked against gpio_chip removal ... */ |
1783 | 1784 | ||
1784 | for (gpio = 0; gpio_is_valid(gpio); gpio++) { | 1785 | for (gpio = 0; gpio_is_valid(gpio); gpio++) { |
1785 | struct device *dev; | 1786 | if (gpio_desc[gpio].chip == chip) |
1786 | |||
1787 | if (chip == gpio_desc[gpio].chip) | ||
1788 | continue; | 1787 | continue; |
1788 | |||
1789 | chip = gpio_desc[gpio].chip; | 1789 | chip = gpio_desc[gpio].chip; |
1790 | if (!chip) | 1790 | if (!chip) |
1791 | continue; | 1791 | continue; |
1792 | 1792 | ||
1793 | seq_printf(s, "%sGPIOs %d-%d", | 1793 | if (index++ >= *pos) { |
1794 | started ? "\n" : "", | 1794 | ret = chip; |
1795 | chip->base, chip->base + chip->ngpio - 1); | 1795 | break; |
1796 | dev = chip->dev; | 1796 | } |
1797 | if (dev) | ||
1798 | seq_printf(s, ", %s/%s", | ||
1799 | dev->bus ? dev->bus->name : "no-bus", | ||
1800 | dev_name(dev)); | ||
1801 | if (chip->label) | ||
1802 | seq_printf(s, ", %s", chip->label); | ||
1803 | if (chip->can_sleep) | ||
1804 | seq_printf(s, ", can sleep"); | ||
1805 | seq_printf(s, ":\n"); | ||
1806 | |||
1807 | started = 1; | ||
1808 | if (chip->dbg_show) | ||
1809 | chip->dbg_show(s, chip); | ||
1810 | else | ||
1811 | gpiolib_dbg_show(s, chip); | ||
1812 | } | 1797 | } |
1798 | |||
1799 | s->private = ""; | ||
1800 | |||
1801 | return ret; | ||
1802 | } | ||
1803 | |||
1804 | static void *gpiolib_seq_next(struct seq_file *s, void *v, loff_t *pos) | ||
1805 | { | ||
1806 | struct gpio_chip *chip = v; | ||
1807 | unsigned int gpio; | ||
1808 | void *ret = NULL; | ||
1809 | |||
1810 | /* skip GPIOs provided by the current chip */ | ||
1811 | for (gpio = chip->base + chip->ngpio; gpio_is_valid(gpio); gpio++) { | ||
1812 | chip = gpio_desc[gpio].chip; | ||
1813 | if (chip) { | ||
1814 | ret = chip; | ||
1815 | break; | ||
1816 | } | ||
1817 | } | ||
1818 | |||
1819 | s->private = "\n"; | ||
1820 | ++*pos; | ||
1821 | |||
1822 | return ret; | ||
1823 | } | ||
1824 | |||
1825 | static void gpiolib_seq_stop(struct seq_file *s, void *v) | ||
1826 | { | ||
1827 | } | ||
1828 | |||
1829 | static int gpiolib_seq_show(struct seq_file *s, void *v) | ||
1830 | { | ||
1831 | struct gpio_chip *chip = v; | ||
1832 | struct device *dev; | ||
1833 | |||
1834 | seq_printf(s, "%sGPIOs %d-%d", (char *)s->private, | ||
1835 | chip->base, chip->base + chip->ngpio - 1); | ||
1836 | dev = chip->dev; | ||
1837 | if (dev) | ||
1838 | seq_printf(s, ", %s/%s", dev->bus ? dev->bus->name : "no-bus", | ||
1839 | dev_name(dev)); | ||
1840 | if (chip->label) | ||
1841 | seq_printf(s, ", %s", chip->label); | ||
1842 | if (chip->can_sleep) | ||
1843 | seq_printf(s, ", can sleep"); | ||
1844 | seq_printf(s, ":\n"); | ||
1845 | |||
1846 | if (chip->dbg_show) | ||
1847 | chip->dbg_show(s, chip); | ||
1848 | else | ||
1849 | gpiolib_dbg_show(s, chip); | ||
1850 | |||
1813 | return 0; | 1851 | return 0; |
1814 | } | 1852 | } |
1815 | 1853 | ||
1854 | static const struct seq_operations gpiolib_seq_ops = { | ||
1855 | .start = gpiolib_seq_start, | ||
1856 | .next = gpiolib_seq_next, | ||
1857 | .stop = gpiolib_seq_stop, | ||
1858 | .show = gpiolib_seq_show, | ||
1859 | }; | ||
1860 | |||
1816 | static int gpiolib_open(struct inode *inode, struct file *file) | 1861 | static int gpiolib_open(struct inode *inode, struct file *file) |
1817 | { | 1862 | { |
1818 | return single_open(file, gpiolib_show, NULL); | 1863 | return seq_open(file, &gpiolib_seq_ops); |
1819 | } | 1864 | } |
1820 | 1865 | ||
1821 | static const struct file_operations gpiolib_operations = { | 1866 | static const struct file_operations gpiolib_operations = { |
1867 | .owner = THIS_MODULE, | ||
1822 | .open = gpiolib_open, | 1868 | .open = gpiolib_open, |
1823 | .read = seq_read, | 1869 | .read = seq_read, |
1824 | .llseek = seq_lseek, | 1870 | .llseek = seq_lseek, |
1825 | .release = single_release, | 1871 | .release = seq_release, |
1826 | }; | 1872 | }; |
1827 | 1873 | ||
1828 | static int __init gpiolib_debugfs_init(void) | 1874 | static int __init gpiolib_debugfs_init(void) |
diff --git a/include/asm-generic/gpio.h b/include/asm-generic/gpio.h index 365ea09ed3b..a9432fc6b8b 100644 --- a/include/asm-generic/gpio.h +++ b/include/asm-generic/gpio.h | |||
@@ -60,6 +60,8 @@ struct device_node; | |||
60 | * @get: returns value for signal "offset"; for output signals this | 60 | * @get: returns value for signal "offset"; for output signals this |
61 | * returns either the value actually sensed, or zero | 61 | * returns either the value actually sensed, or zero |
62 | * @direction_output: configures signal "offset" as output, or returns error | 62 | * @direction_output: configures signal "offset" as output, or returns error |
63 | * @set_debounce: optional hook for setting debounce time for specified gpio in | ||
64 | * interrupt triggered gpio chips | ||
63 | * @set: assigns output value for signal "offset" | 65 | * @set: assigns output value for signal "offset" |
64 | * @to_irq: optional hook supporting non-static gpio_to_irq() mappings; | 66 | * @to_irq: optional hook supporting non-static gpio_to_irq() mappings; |
65 | * implementation may not sleep | 67 | * implementation may not sleep |
diff --git a/include/linux/i2c/pcf857x.h b/include/linux/i2c/pcf857x.h index 0767a2a6b2f..781e6bd06c3 100644 --- a/include/linux/i2c/pcf857x.h +++ b/include/linux/i2c/pcf857x.h | |||
@@ -10,6 +10,7 @@ | |||
10 | * @setup: optional callback issued once the GPIOs are valid | 10 | * @setup: optional callback issued once the GPIOs are valid |
11 | * @teardown: optional callback issued before the GPIOs are invalidated | 11 | * @teardown: optional callback issued before the GPIOs are invalidated |
12 | * @context: optional parameter passed to setup() and teardown() | 12 | * @context: optional parameter passed to setup() and teardown() |
13 | * @irq: optional interrupt number | ||
13 | * | 14 | * |
14 | * In addition to the I2C_BOARD_INFO() state appropriate to each chip, | 15 | * In addition to the I2C_BOARD_INFO() state appropriate to each chip, |
15 | * the i2c_board_info used with the pcf875x driver must provide its | 16 | * the i2c_board_info used with the pcf875x driver must provide its |
@@ -39,6 +40,8 @@ struct pcf857x_platform_data { | |||
39 | int gpio, unsigned ngpio, | 40 | int gpio, unsigned ngpio, |
40 | void *context); | 41 | void *context); |
41 | void *context; | 42 | void *context; |
43 | |||
44 | int irq; | ||
42 | }; | 45 | }; |
43 | 46 | ||
44 | #endif /* __LINUX_PCF857X_H */ | 47 | #endif /* __LINUX_PCF857X_H */ |