diff options
author | Olof Johansson <olof@lixom.net> | 2013-04-03 02:27:45 -0400 |
---|---|---|
committer | Olof Johansson <olof@lixom.net> | 2013-04-03 02:27:51 -0400 |
commit | 16eaaee4d87b2255797f94341bd442f1f93afd1b (patch) | |
tree | 616bf06039612355da8d3fcf6408701a7bb897e9 /drivers/gpio | |
parent | 8bb9660418e05bb1845ac1a2428444d78e322cc7 (diff) | |
parent | 00ae962f8051bb143fa1c43c6a9c8274c3a9c593 (diff) |
Merge tag 'renesas-boards3-for-v3.10' of git://git.kernel.org/pub/scm/linux/kernel/git/horms/renesas into next/boards2
Third round of Renesas ARM SoC board updates for v3.10
Highlights:
* Add Lager board support
* Add ape6evm board support
* Add Bock-W board support
* Mackerel MMCIF/SDHI clean ups
* Add ethernet support to kzm9g-reference
This pull request is based on a merge of:
git://git.kernel.org/pub/scm/linux/kernel/git/horms/renesas renesas-pinmux2-for-v3.10
git://git.kernel.org/pub/scm/linux/kernel/git/horms/renesas renesas-boards2-for-v3.10
The merge with renesas-pinmux2-for-v3.10 was made to provide
run-time dependencies for the following changes:
ARM: shmobile: APE6EVM LAN9220 support
ARM: shmobile: APE6EVM PFC support
* tag 'renesas-boards3-for-v3.10' of git://git.kernel.org/pub/scm/linux/kernel/git/horms/renesas: (307 commits)
ARM: shmobile: mackerel: clean up MMCIF vs. SDHI1 selection
ARM: shmobile: mackerel: add interrupt names for SDHI0
ARM: shmobile: mackerel: switch SDHI and MMCIF interfaces to slot-gpio
ARM: shmobile: mackerel: remove OCR masks, where regulators are used
ARM: shmobile: mackerel: SDHI resources do not have to be numbered
ARM: shmobile: Initial r8a7790 Lager board support
ARM: shmobile: APE6EVM LAN9220 support
ARM: shmobile: APE6EVM PFC support
ARM: shmobile: APE6EVM base support
ARM: shmobile: kzm9g-reference: add ethernet support
ARM: shmobile: add R-Car M1A Bock-W platform support
sh-pfc: r8a73a4: Remove unused GPIO bias data
ARM: shmobile: r8a73a4: Remove all GPIO enums
sh-pfc: r8a73a4: Remove function GPIOs
ARM: shmobile: r8a73a4: Remove IRQC function GPIOs
ARM: shmobile: r8a73a4: Remove SCIF function GPIOs
sh-pfc: r8a73a4: Remove IRQC function GPIOS
sh-pfc: r8a73a4: Remove SCIF function GPIOS
sh-pfc: r8a73a4: Add IRQC pin groups and functions
sh-pfc: r8a73a4: Add SCIF pin groups and functions
...
Signed-off-by: Olof Johansson <olof@lixom.net>
Diffstat (limited to 'drivers/gpio')
-rw-r--r-- | drivers/gpio/Kconfig | 6 | ||||
-rw-r--r-- | drivers/gpio/Makefile | 1 | ||||
-rw-r--r-- | drivers/gpio/gpio-pl061.c | 117 | ||||
-rw-r--r-- | drivers/gpio/gpio-rcar.c | 396 | ||||
-rw-r--r-- | drivers/gpio/gpiolib-of.c | 20 |
5 files changed, 485 insertions, 55 deletions
diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig index 93aaadf99f28..d766e3cbef18 100644 --- a/drivers/gpio/Kconfig +++ b/drivers/gpio/Kconfig | |||
@@ -204,6 +204,12 @@ config GPIO_PXA | |||
204 | help | 204 | help |
205 | Say yes here to support the PXA GPIO device | 205 | Say yes here to support the PXA GPIO device |
206 | 206 | ||
207 | config GPIO_RCAR | ||
208 | tristate "Renesas R-Car GPIO" | ||
209 | depends on ARM | ||
210 | help | ||
211 | Say yes here to support GPIO on Renesas R-Car SoCs. | ||
212 | |||
207 | config GPIO_SPEAR_SPICS | 213 | config GPIO_SPEAR_SPICS |
208 | bool "ST SPEAr13xx SPI Chip Select as GPIO support" | 214 | bool "ST SPEAr13xx SPI Chip Select as GPIO support" |
209 | depends on PLAT_SPEAR | 215 | depends on PLAT_SPEAR |
diff --git a/drivers/gpio/Makefile b/drivers/gpio/Makefile index 22e07bc9fcb5..b41c74d45287 100644 --- a/drivers/gpio/Makefile +++ b/drivers/gpio/Makefile | |||
@@ -57,6 +57,7 @@ obj-$(CONFIG_GPIO_PL061) += gpio-pl061.o | |||
57 | obj-$(CONFIG_GPIO_PXA) += gpio-pxa.o | 57 | obj-$(CONFIG_GPIO_PXA) += gpio-pxa.o |
58 | obj-$(CONFIG_GPIO_RC5T583) += gpio-rc5t583.o | 58 | obj-$(CONFIG_GPIO_RC5T583) += gpio-rc5t583.o |
59 | obj-$(CONFIG_GPIO_RDC321X) += gpio-rdc321x.o | 59 | obj-$(CONFIG_GPIO_RDC321X) += gpio-rdc321x.o |
60 | obj-$(CONFIG_GPIO_RCAR) += gpio-rcar.o | ||
60 | obj-$(CONFIG_PLAT_SAMSUNG) += gpio-samsung.o | 61 | obj-$(CONFIG_PLAT_SAMSUNG) += gpio-samsung.o |
61 | obj-$(CONFIG_ARCH_SA1100) += gpio-sa1100.o | 62 | obj-$(CONFIG_ARCH_SA1100) += gpio-sa1100.o |
62 | obj-$(CONFIG_GPIO_SCH) += gpio-sch.o | 63 | obj-$(CONFIG_GPIO_SCH) += gpio-sch.o |
diff --git a/drivers/gpio/gpio-pl061.c b/drivers/gpio/gpio-pl061.c index b820869ca93c..06ed257c5d31 100644 --- a/drivers/gpio/gpio-pl061.c +++ b/drivers/gpio/gpio-pl061.c | |||
@@ -15,6 +15,7 @@ | |||
15 | #include <linux/io.h> | 15 | #include <linux/io.h> |
16 | #include <linux/ioport.h> | 16 | #include <linux/ioport.h> |
17 | #include <linux/irq.h> | 17 | #include <linux/irq.h> |
18 | #include <linux/irqdomain.h> | ||
18 | #include <linux/bitops.h> | 19 | #include <linux/bitops.h> |
19 | #include <linux/workqueue.h> | 20 | #include <linux/workqueue.h> |
20 | #include <linux/gpio.h> | 21 | #include <linux/gpio.h> |
@@ -22,6 +23,7 @@ | |||
22 | #include <linux/amba/bus.h> | 23 | #include <linux/amba/bus.h> |
23 | #include <linux/amba/pl061.h> | 24 | #include <linux/amba/pl061.h> |
24 | #include <linux/slab.h> | 25 | #include <linux/slab.h> |
26 | #include <linux/pinctrl/consumer.h> | ||
25 | #include <linux/pm.h> | 27 | #include <linux/pm.h> |
26 | #include <asm/mach/irq.h> | 28 | #include <asm/mach/irq.h> |
27 | 29 | ||
@@ -51,8 +53,7 @@ struct pl061_gpio { | |||
51 | spinlock_t lock; | 53 | spinlock_t lock; |
52 | 54 | ||
53 | void __iomem *base; | 55 | void __iomem *base; |
54 | int irq_base; | 56 | struct irq_domain *domain; |
55 | struct irq_chip_generic *irq_gc; | ||
56 | struct gpio_chip gc; | 57 | struct gpio_chip gc; |
57 | 58 | ||
58 | #ifdef CONFIG_PM | 59 | #ifdef CONFIG_PM |
@@ -60,6 +61,17 @@ struct pl061_gpio { | |||
60 | #endif | 61 | #endif |
61 | }; | 62 | }; |
62 | 63 | ||
64 | static int pl061_gpio_request(struct gpio_chip *chip, unsigned offset) | ||
65 | { | ||
66 | /* | ||
67 | * Map back to global GPIO space and request muxing, the direction | ||
68 | * parameter does not matter for this controller. | ||
69 | */ | ||
70 | int gpio = chip->base + offset; | ||
71 | |||
72 | return pinctrl_request_gpio(gpio); | ||
73 | } | ||
74 | |||
63 | static int pl061_direction_input(struct gpio_chip *gc, unsigned offset) | 75 | static int pl061_direction_input(struct gpio_chip *gc, unsigned offset) |
64 | { | 76 | { |
65 | struct pl061_gpio *chip = container_of(gc, struct pl061_gpio, gc); | 77 | struct pl061_gpio *chip = container_of(gc, struct pl061_gpio, gc); |
@@ -122,24 +134,20 @@ static int pl061_to_irq(struct gpio_chip *gc, unsigned offset) | |||
122 | { | 134 | { |
123 | struct pl061_gpio *chip = container_of(gc, struct pl061_gpio, gc); | 135 | struct pl061_gpio *chip = container_of(gc, struct pl061_gpio, gc); |
124 | 136 | ||
125 | if (chip->irq_base <= 0) | 137 | return irq_create_mapping(chip->domain, offset); |
126 | return -EINVAL; | ||
127 | |||
128 | return chip->irq_base + offset; | ||
129 | } | 138 | } |
130 | 139 | ||
131 | static int pl061_irq_type(struct irq_data *d, unsigned trigger) | 140 | static int pl061_irq_type(struct irq_data *d, unsigned trigger) |
132 | { | 141 | { |
133 | struct irq_chip_generic *gc = irq_data_get_irq_chip_data(d); | 142 | struct pl061_gpio *chip = irq_data_get_irq_chip_data(d); |
134 | struct pl061_gpio *chip = gc->private; | 143 | int offset = irqd_to_hwirq(d); |
135 | int offset = d->irq - chip->irq_base; | ||
136 | unsigned long flags; | 144 | unsigned long flags; |
137 | u8 gpiois, gpioibe, gpioiev; | 145 | u8 gpiois, gpioibe, gpioiev; |
138 | 146 | ||
139 | if (offset < 0 || offset >= PL061_GPIO_NR) | 147 | if (offset < 0 || offset >= PL061_GPIO_NR) |
140 | return -EINVAL; | 148 | return -EINVAL; |
141 | 149 | ||
142 | raw_spin_lock_irqsave(&gc->lock, flags); | 150 | spin_lock_irqsave(&chip->lock, flags); |
143 | 151 | ||
144 | gpioiev = readb(chip->base + GPIOIEV); | 152 | gpioiev = readb(chip->base + GPIOIEV); |
145 | 153 | ||
@@ -168,7 +176,7 @@ static int pl061_irq_type(struct irq_data *d, unsigned trigger) | |||
168 | 176 | ||
169 | writeb(gpioiev, chip->base + GPIOIEV); | 177 | writeb(gpioiev, chip->base + GPIOIEV); |
170 | 178 | ||
171 | raw_spin_unlock_irqrestore(&gc->lock, flags); | 179 | spin_unlock_irqrestore(&chip->lock, flags); |
172 | 180 | ||
173 | return 0; | 181 | return 0; |
174 | } | 182 | } |
@@ -192,31 +200,61 @@ static void pl061_irq_handler(unsigned irq, struct irq_desc *desc) | |||
192 | chained_irq_exit(irqchip, desc); | 200 | chained_irq_exit(irqchip, desc); |
193 | } | 201 | } |
194 | 202 | ||
195 | static void __init pl061_init_gc(struct pl061_gpio *chip, int irq_base) | 203 | static void pl061_irq_mask(struct irq_data *d) |
196 | { | 204 | { |
197 | struct irq_chip_type *ct; | 205 | struct pl061_gpio *chip = irq_data_get_irq_chip_data(d); |
206 | u8 mask = 1 << (irqd_to_hwirq(d) % PL061_GPIO_NR); | ||
207 | u8 gpioie; | ||
208 | |||
209 | spin_lock(&chip->lock); | ||
210 | gpioie = readb(chip->base + GPIOIE) & ~mask; | ||
211 | writeb(gpioie, chip->base + GPIOIE); | ||
212 | spin_unlock(&chip->lock); | ||
213 | } | ||
214 | |||
215 | static void pl061_irq_unmask(struct irq_data *d) | ||
216 | { | ||
217 | struct pl061_gpio *chip = irq_data_get_irq_chip_data(d); | ||
218 | u8 mask = 1 << (irqd_to_hwirq(d) % PL061_GPIO_NR); | ||
219 | u8 gpioie; | ||
220 | |||
221 | spin_lock(&chip->lock); | ||
222 | gpioie = readb(chip->base + GPIOIE) | mask; | ||
223 | writeb(gpioie, chip->base + GPIOIE); | ||
224 | spin_unlock(&chip->lock); | ||
225 | } | ||
198 | 226 | ||
199 | chip->irq_gc = irq_alloc_generic_chip("gpio-pl061", 1, irq_base, | 227 | static struct irq_chip pl061_irqchip = { |
200 | chip->base, handle_simple_irq); | 228 | .name = "pl061 gpio", |
201 | chip->irq_gc->private = chip; | 229 | .irq_mask = pl061_irq_mask, |
230 | .irq_unmask = pl061_irq_unmask, | ||
231 | .irq_set_type = pl061_irq_type, | ||
232 | }; | ||
233 | |||
234 | static int pl061_irq_map(struct irq_domain *d, unsigned int virq, | ||
235 | irq_hw_number_t hw) | ||
236 | { | ||
237 | struct pl061_gpio *chip = d->host_data; | ||
202 | 238 | ||
203 | ct = chip->irq_gc->chip_types; | 239 | irq_set_chip_and_handler_name(virq, &pl061_irqchip, handle_simple_irq, |
204 | ct->chip.irq_mask = irq_gc_mask_clr_bit; | 240 | "pl061"); |
205 | ct->chip.irq_unmask = irq_gc_mask_set_bit; | 241 | irq_set_chip_data(virq, chip); |
206 | ct->chip.irq_set_type = pl061_irq_type; | 242 | irq_set_irq_type(virq, IRQ_TYPE_NONE); |
207 | ct->chip.irq_set_wake = irq_gc_set_wake; | ||
208 | ct->regs.mask = GPIOIE; | ||
209 | 243 | ||
210 | irq_setup_generic_chip(chip->irq_gc, IRQ_MSK(PL061_GPIO_NR), | 244 | return 0; |
211 | IRQ_GC_INIT_NESTED_LOCK, IRQ_NOREQUEST, 0); | ||
212 | } | 245 | } |
213 | 246 | ||
247 | static const struct irq_domain_ops pl061_domain_ops = { | ||
248 | .map = pl061_irq_map, | ||
249 | .xlate = irq_domain_xlate_twocell, | ||
250 | }; | ||
251 | |||
214 | static int pl061_probe(struct amba_device *adev, const struct amba_id *id) | 252 | static int pl061_probe(struct amba_device *adev, const struct amba_id *id) |
215 | { | 253 | { |
216 | struct device *dev = &adev->dev; | 254 | struct device *dev = &adev->dev; |
217 | struct pl061_platform_data *pdata = dev->platform_data; | 255 | struct pl061_platform_data *pdata = dev->platform_data; |
218 | struct pl061_gpio *chip; | 256 | struct pl061_gpio *chip; |
219 | int ret, irq, i; | 257 | int ret, irq, i, irq_base; |
220 | 258 | ||
221 | chip = devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL); | 259 | chip = devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL); |
222 | if (chip == NULL) | 260 | if (chip == NULL) |
@@ -224,24 +262,31 @@ static int pl061_probe(struct amba_device *adev, const struct amba_id *id) | |||
224 | 262 | ||
225 | if (pdata) { | 263 | if (pdata) { |
226 | chip->gc.base = pdata->gpio_base; | 264 | chip->gc.base = pdata->gpio_base; |
227 | chip->irq_base = pdata->irq_base; | 265 | irq_base = pdata->irq_base; |
228 | } else if (adev->dev.of_node) { | 266 | if (irq_base <= 0) |
267 | return -ENODEV; | ||
268 | } else { | ||
229 | chip->gc.base = -1; | 269 | chip->gc.base = -1; |
230 | chip->irq_base = 0; | 270 | irq_base = 0; |
231 | } else | 271 | } |
232 | return -ENODEV; | ||
233 | 272 | ||
234 | if (!devm_request_mem_region(dev, adev->res.start, | 273 | if (!devm_request_mem_region(dev, adev->res.start, |
235 | resource_size(&adev->res), "pl061")) | 274 | resource_size(&adev->res), "pl061")) |
236 | return -EBUSY; | 275 | return -EBUSY; |
237 | 276 | ||
238 | chip->base = devm_ioremap(dev, adev->res.start, | 277 | chip->base = devm_ioremap(dev, adev->res.start, |
239 | resource_size(&adev->res)); | 278 | resource_size(&adev->res)); |
240 | if (chip->base == NULL) | 279 | if (!chip->base) |
241 | return -ENOMEM; | 280 | return -ENOMEM; |
242 | 281 | ||
282 | chip->domain = irq_domain_add_simple(adev->dev.of_node, PL061_GPIO_NR, | ||
283 | irq_base, &pl061_domain_ops, chip); | ||
284 | if (!chip->domain) | ||
285 | return -ENODEV; | ||
286 | |||
243 | spin_lock_init(&chip->lock); | 287 | spin_lock_init(&chip->lock); |
244 | 288 | ||
289 | chip->gc.request = pl061_gpio_request; | ||
245 | chip->gc.direction_input = pl061_direction_input; | 290 | chip->gc.direction_input = pl061_direction_input; |
246 | chip->gc.direction_output = pl061_direction_output; | 291 | chip->gc.direction_output = pl061_direction_output; |
247 | chip->gc.get = pl061_get_value; | 292 | chip->gc.get = pl061_get_value; |
@@ -259,12 +304,6 @@ static int pl061_probe(struct amba_device *adev, const struct amba_id *id) | |||
259 | /* | 304 | /* |
260 | * irq_chip support | 305 | * irq_chip support |
261 | */ | 306 | */ |
262 | |||
263 | if (chip->irq_base <= 0) | ||
264 | return 0; | ||
265 | |||
266 | pl061_init_gc(chip, chip->irq_base); | ||
267 | |||
268 | writeb(0, chip->base + GPIOIE); /* disable irqs */ | 307 | writeb(0, chip->base + GPIOIE); /* disable irqs */ |
269 | irq = adev->irq[0]; | 308 | irq = adev->irq[0]; |
270 | if (irq < 0) | 309 | if (irq < 0) |
diff --git a/drivers/gpio/gpio-rcar.c b/drivers/gpio/gpio-rcar.c new file mode 100644 index 000000000000..b4ca450947b8 --- /dev/null +++ b/drivers/gpio/gpio-rcar.c | |||
@@ -0,0 +1,396 @@ | |||
1 | /* | ||
2 | * Renesas R-Car GPIO Support | ||
3 | * | ||
4 | * Copyright (C) 2013 Magnus Damm | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or modify | ||
7 | * it under the terms of the GNU General Public License as published by | ||
8 | * the Free Software Foundation; either version 2 of the License | ||
9 | * | ||
10 | * This program is distributed in the hope that it will be useful, | ||
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | * GNU General Public License for more details. | ||
14 | */ | ||
15 | |||
16 | #include <linux/err.h> | ||
17 | #include <linux/gpio.h> | ||
18 | #include <linux/init.h> | ||
19 | #include <linux/interrupt.h> | ||
20 | #include <linux/io.h> | ||
21 | #include <linux/ioport.h> | ||
22 | #include <linux/irq.h> | ||
23 | #include <linux/irqdomain.h> | ||
24 | #include <linux/module.h> | ||
25 | #include <linux/pinctrl/consumer.h> | ||
26 | #include <linux/platform_data/gpio-rcar.h> | ||
27 | #include <linux/platform_device.h> | ||
28 | #include <linux/spinlock.h> | ||
29 | #include <linux/slab.h> | ||
30 | |||
31 | struct gpio_rcar_priv { | ||
32 | void __iomem *base; | ||
33 | spinlock_t lock; | ||
34 | struct gpio_rcar_config config; | ||
35 | struct platform_device *pdev; | ||
36 | struct gpio_chip gpio_chip; | ||
37 | struct irq_chip irq_chip; | ||
38 | struct irq_domain *irq_domain; | ||
39 | }; | ||
40 | |||
41 | #define IOINTSEL 0x00 | ||
42 | #define INOUTSEL 0x04 | ||
43 | #define OUTDT 0x08 | ||
44 | #define INDT 0x0c | ||
45 | #define INTDT 0x10 | ||
46 | #define INTCLR 0x14 | ||
47 | #define INTMSK 0x18 | ||
48 | #define MSKCLR 0x1c | ||
49 | #define POSNEG 0x20 | ||
50 | #define EDGLEVEL 0x24 | ||
51 | #define FILONOFF 0x28 | ||
52 | |||
53 | static inline u32 gpio_rcar_read(struct gpio_rcar_priv *p, int offs) | ||
54 | { | ||
55 | return ioread32(p->base + offs); | ||
56 | } | ||
57 | |||
58 | static inline void gpio_rcar_write(struct gpio_rcar_priv *p, int offs, | ||
59 | u32 value) | ||
60 | { | ||
61 | iowrite32(value, p->base + offs); | ||
62 | } | ||
63 | |||
64 | static void gpio_rcar_modify_bit(struct gpio_rcar_priv *p, int offs, | ||
65 | int bit, bool value) | ||
66 | { | ||
67 | u32 tmp = gpio_rcar_read(p, offs); | ||
68 | |||
69 | if (value) | ||
70 | tmp |= BIT(bit); | ||
71 | else | ||
72 | tmp &= ~BIT(bit); | ||
73 | |||
74 | gpio_rcar_write(p, offs, tmp); | ||
75 | } | ||
76 | |||
77 | static void gpio_rcar_irq_disable(struct irq_data *d) | ||
78 | { | ||
79 | struct gpio_rcar_priv *p = irq_data_get_irq_chip_data(d); | ||
80 | |||
81 | gpio_rcar_write(p, INTMSK, ~BIT(irqd_to_hwirq(d))); | ||
82 | } | ||
83 | |||
84 | static void gpio_rcar_irq_enable(struct irq_data *d) | ||
85 | { | ||
86 | struct gpio_rcar_priv *p = irq_data_get_irq_chip_data(d); | ||
87 | |||
88 | gpio_rcar_write(p, MSKCLR, BIT(irqd_to_hwirq(d))); | ||
89 | } | ||
90 | |||
91 | static void gpio_rcar_config_interrupt_input_mode(struct gpio_rcar_priv *p, | ||
92 | unsigned int hwirq, | ||
93 | bool active_high_rising_edge, | ||
94 | bool level_trigger) | ||
95 | { | ||
96 | unsigned long flags; | ||
97 | |||
98 | /* follow steps in the GPIO documentation for | ||
99 | * "Setting Edge-Sensitive Interrupt Input Mode" and | ||
100 | * "Setting Level-Sensitive Interrupt Input Mode" | ||
101 | */ | ||
102 | |||
103 | spin_lock_irqsave(&p->lock, flags); | ||
104 | |||
105 | /* Configure postive or negative logic in POSNEG */ | ||
106 | gpio_rcar_modify_bit(p, POSNEG, hwirq, !active_high_rising_edge); | ||
107 | |||
108 | /* Configure edge or level trigger in EDGLEVEL */ | ||
109 | gpio_rcar_modify_bit(p, EDGLEVEL, hwirq, !level_trigger); | ||
110 | |||
111 | /* Select "Interrupt Input Mode" in IOINTSEL */ | ||
112 | gpio_rcar_modify_bit(p, IOINTSEL, hwirq, true); | ||
113 | |||
114 | /* Write INTCLR in case of edge trigger */ | ||
115 | if (!level_trigger) | ||
116 | gpio_rcar_write(p, INTCLR, BIT(hwirq)); | ||
117 | |||
118 | spin_unlock_irqrestore(&p->lock, flags); | ||
119 | } | ||
120 | |||
121 | static int gpio_rcar_irq_set_type(struct irq_data *d, unsigned int type) | ||
122 | { | ||
123 | struct gpio_rcar_priv *p = irq_data_get_irq_chip_data(d); | ||
124 | unsigned int hwirq = irqd_to_hwirq(d); | ||
125 | |||
126 | dev_dbg(&p->pdev->dev, "sense irq = %d, type = %d\n", hwirq, type); | ||
127 | |||
128 | switch (type & IRQ_TYPE_SENSE_MASK) { | ||
129 | case IRQ_TYPE_LEVEL_HIGH: | ||
130 | gpio_rcar_config_interrupt_input_mode(p, hwirq, true, true); | ||
131 | break; | ||
132 | case IRQ_TYPE_LEVEL_LOW: | ||
133 | gpio_rcar_config_interrupt_input_mode(p, hwirq, false, true); | ||
134 | break; | ||
135 | case IRQ_TYPE_EDGE_RISING: | ||
136 | gpio_rcar_config_interrupt_input_mode(p, hwirq, true, false); | ||
137 | break; | ||
138 | case IRQ_TYPE_EDGE_FALLING: | ||
139 | gpio_rcar_config_interrupt_input_mode(p, hwirq, false, false); | ||
140 | break; | ||
141 | default: | ||
142 | return -EINVAL; | ||
143 | } | ||
144 | return 0; | ||
145 | } | ||
146 | |||
147 | static irqreturn_t gpio_rcar_irq_handler(int irq, void *dev_id) | ||
148 | { | ||
149 | struct gpio_rcar_priv *p = dev_id; | ||
150 | u32 pending; | ||
151 | unsigned int offset, irqs_handled = 0; | ||
152 | |||
153 | while ((pending = gpio_rcar_read(p, INTDT))) { | ||
154 | offset = __ffs(pending); | ||
155 | gpio_rcar_write(p, INTCLR, BIT(offset)); | ||
156 | generic_handle_irq(irq_find_mapping(p->irq_domain, offset)); | ||
157 | irqs_handled++; | ||
158 | } | ||
159 | |||
160 | return irqs_handled ? IRQ_HANDLED : IRQ_NONE; | ||
161 | } | ||
162 | |||
163 | static inline struct gpio_rcar_priv *gpio_to_priv(struct gpio_chip *chip) | ||
164 | { | ||
165 | return container_of(chip, struct gpio_rcar_priv, gpio_chip); | ||
166 | } | ||
167 | |||
168 | static void gpio_rcar_config_general_input_output_mode(struct gpio_chip *chip, | ||
169 | unsigned int gpio, | ||
170 | bool output) | ||
171 | { | ||
172 | struct gpio_rcar_priv *p = gpio_to_priv(chip); | ||
173 | unsigned long flags; | ||
174 | |||
175 | /* follow steps in the GPIO documentation for | ||
176 | * "Setting General Output Mode" and | ||
177 | * "Setting General Input Mode" | ||
178 | */ | ||
179 | |||
180 | spin_lock_irqsave(&p->lock, flags); | ||
181 | |||
182 | /* Configure postive logic in POSNEG */ | ||
183 | gpio_rcar_modify_bit(p, POSNEG, gpio, false); | ||
184 | |||
185 | /* Select "General Input/Output Mode" in IOINTSEL */ | ||
186 | gpio_rcar_modify_bit(p, IOINTSEL, gpio, false); | ||
187 | |||
188 | /* Select Input Mode or Output Mode in INOUTSEL */ | ||
189 | gpio_rcar_modify_bit(p, INOUTSEL, gpio, output); | ||
190 | |||
191 | spin_unlock_irqrestore(&p->lock, flags); | ||
192 | } | ||
193 | |||
194 | static int gpio_rcar_request(struct gpio_chip *chip, unsigned offset) | ||
195 | { | ||
196 | return pinctrl_request_gpio(chip->base + offset); | ||
197 | } | ||
198 | |||
199 | static void gpio_rcar_free(struct gpio_chip *chip, unsigned offset) | ||
200 | { | ||
201 | pinctrl_free_gpio(chip->base + offset); | ||
202 | |||
203 | /* Set the GPIO as an input to ensure that the next GPIO request won't | ||
204 | * drive the GPIO pin as an output. | ||
205 | */ | ||
206 | gpio_rcar_config_general_input_output_mode(chip, offset, false); | ||
207 | } | ||
208 | |||
209 | static int gpio_rcar_direction_input(struct gpio_chip *chip, unsigned offset) | ||
210 | { | ||
211 | gpio_rcar_config_general_input_output_mode(chip, offset, false); | ||
212 | return 0; | ||
213 | } | ||
214 | |||
215 | static int gpio_rcar_get(struct gpio_chip *chip, unsigned offset) | ||
216 | { | ||
217 | return (int)(gpio_rcar_read(gpio_to_priv(chip), INDT) & BIT(offset)); | ||
218 | } | ||
219 | |||
220 | static void gpio_rcar_set(struct gpio_chip *chip, unsigned offset, int value) | ||
221 | { | ||
222 | struct gpio_rcar_priv *p = gpio_to_priv(chip); | ||
223 | unsigned long flags; | ||
224 | |||
225 | spin_lock_irqsave(&p->lock, flags); | ||
226 | gpio_rcar_modify_bit(p, OUTDT, offset, value); | ||
227 | spin_unlock_irqrestore(&p->lock, flags); | ||
228 | } | ||
229 | |||
230 | static int gpio_rcar_direction_output(struct gpio_chip *chip, unsigned offset, | ||
231 | int value) | ||
232 | { | ||
233 | /* write GPIO value to output before selecting output mode of pin */ | ||
234 | gpio_rcar_set(chip, offset, value); | ||
235 | gpio_rcar_config_general_input_output_mode(chip, offset, true); | ||
236 | return 0; | ||
237 | } | ||
238 | |||
239 | static int gpio_rcar_to_irq(struct gpio_chip *chip, unsigned offset) | ||
240 | { | ||
241 | return irq_create_mapping(gpio_to_priv(chip)->irq_domain, offset); | ||
242 | } | ||
243 | |||
244 | static int gpio_rcar_irq_domain_map(struct irq_domain *h, unsigned int virq, | ||
245 | irq_hw_number_t hw) | ||
246 | { | ||
247 | struct gpio_rcar_priv *p = h->host_data; | ||
248 | |||
249 | dev_dbg(&p->pdev->dev, "map hw irq = %d, virq = %d\n", (int)hw, virq); | ||
250 | |||
251 | irq_set_chip_data(virq, h->host_data); | ||
252 | irq_set_chip_and_handler(virq, &p->irq_chip, handle_level_irq); | ||
253 | set_irq_flags(virq, IRQF_VALID); /* kill me now */ | ||
254 | return 0; | ||
255 | } | ||
256 | |||
257 | static struct irq_domain_ops gpio_rcar_irq_domain_ops = { | ||
258 | .map = gpio_rcar_irq_domain_map, | ||
259 | }; | ||
260 | |||
261 | static int gpio_rcar_probe(struct platform_device *pdev) | ||
262 | { | ||
263 | struct gpio_rcar_config *pdata = pdev->dev.platform_data; | ||
264 | struct gpio_rcar_priv *p; | ||
265 | struct resource *io, *irq; | ||
266 | struct gpio_chip *gpio_chip; | ||
267 | struct irq_chip *irq_chip; | ||
268 | const char *name = dev_name(&pdev->dev); | ||
269 | int ret; | ||
270 | |||
271 | p = devm_kzalloc(&pdev->dev, sizeof(*p), GFP_KERNEL); | ||
272 | if (!p) { | ||
273 | dev_err(&pdev->dev, "failed to allocate driver data\n"); | ||
274 | ret = -ENOMEM; | ||
275 | goto err0; | ||
276 | } | ||
277 | |||
278 | /* deal with driver instance configuration */ | ||
279 | if (pdata) | ||
280 | p->config = *pdata; | ||
281 | |||
282 | p->pdev = pdev; | ||
283 | platform_set_drvdata(pdev, p); | ||
284 | spin_lock_init(&p->lock); | ||
285 | |||
286 | io = platform_get_resource(pdev, IORESOURCE_MEM, 0); | ||
287 | irq = platform_get_resource(pdev, IORESOURCE_IRQ, 0); | ||
288 | |||
289 | if (!io || !irq) { | ||
290 | dev_err(&pdev->dev, "missing IRQ or IOMEM\n"); | ||
291 | ret = -EINVAL; | ||
292 | goto err0; | ||
293 | } | ||
294 | |||
295 | p->base = devm_ioremap_nocache(&pdev->dev, io->start, | ||
296 | resource_size(io)); | ||
297 | if (!p->base) { | ||
298 | dev_err(&pdev->dev, "failed to remap I/O memory\n"); | ||
299 | ret = -ENXIO; | ||
300 | goto err0; | ||
301 | } | ||
302 | |||
303 | gpio_chip = &p->gpio_chip; | ||
304 | gpio_chip->request = gpio_rcar_request; | ||
305 | gpio_chip->free = gpio_rcar_free; | ||
306 | gpio_chip->direction_input = gpio_rcar_direction_input; | ||
307 | gpio_chip->get = gpio_rcar_get; | ||
308 | gpio_chip->direction_output = gpio_rcar_direction_output; | ||
309 | gpio_chip->set = gpio_rcar_set; | ||
310 | gpio_chip->to_irq = gpio_rcar_to_irq; | ||
311 | gpio_chip->label = name; | ||
312 | gpio_chip->owner = THIS_MODULE; | ||
313 | gpio_chip->base = p->config.gpio_base; | ||
314 | gpio_chip->ngpio = p->config.number_of_pins; | ||
315 | |||
316 | irq_chip = &p->irq_chip; | ||
317 | irq_chip->name = name; | ||
318 | irq_chip->irq_mask = gpio_rcar_irq_disable; | ||
319 | irq_chip->irq_unmask = gpio_rcar_irq_enable; | ||
320 | irq_chip->irq_enable = gpio_rcar_irq_enable; | ||
321 | irq_chip->irq_disable = gpio_rcar_irq_disable; | ||
322 | irq_chip->irq_set_type = gpio_rcar_irq_set_type; | ||
323 | irq_chip->flags = IRQCHIP_SKIP_SET_WAKE | IRQCHIP_SET_TYPE_MASKED; | ||
324 | |||
325 | p->irq_domain = irq_domain_add_simple(pdev->dev.of_node, | ||
326 | p->config.number_of_pins, | ||
327 | p->config.irq_base, | ||
328 | &gpio_rcar_irq_domain_ops, p); | ||
329 | if (!p->irq_domain) { | ||
330 | ret = -ENXIO; | ||
331 | dev_err(&pdev->dev, "cannot initialize irq domain\n"); | ||
332 | goto err1; | ||
333 | } | ||
334 | |||
335 | if (devm_request_irq(&pdev->dev, irq->start, | ||
336 | gpio_rcar_irq_handler, 0, name, p)) { | ||
337 | dev_err(&pdev->dev, "failed to request IRQ\n"); | ||
338 | ret = -ENOENT; | ||
339 | goto err1; | ||
340 | } | ||
341 | |||
342 | ret = gpiochip_add(gpio_chip); | ||
343 | if (ret) { | ||
344 | dev_err(&pdev->dev, "failed to add GPIO controller\n"); | ||
345 | goto err1; | ||
346 | } | ||
347 | |||
348 | dev_info(&pdev->dev, "driving %d GPIOs\n", p->config.number_of_pins); | ||
349 | |||
350 | /* warn in case of mismatch if irq base is specified */ | ||
351 | if (p->config.irq_base) { | ||
352 | ret = irq_find_mapping(p->irq_domain, 0); | ||
353 | if (p->config.irq_base != ret) | ||
354 | dev_warn(&pdev->dev, "irq base mismatch (%u/%u)\n", | ||
355 | p->config.irq_base, ret); | ||
356 | } | ||
357 | |||
358 | ret = gpiochip_add_pin_range(gpio_chip, p->config.pctl_name, 0, | ||
359 | gpio_chip->base, gpio_chip->ngpio); | ||
360 | if (ret < 0) | ||
361 | dev_warn(&pdev->dev, "failed to add pin range\n"); | ||
362 | |||
363 | return 0; | ||
364 | |||
365 | err1: | ||
366 | irq_domain_remove(p->irq_domain); | ||
367 | err0: | ||
368 | return ret; | ||
369 | } | ||
370 | |||
371 | static int gpio_rcar_remove(struct platform_device *pdev) | ||
372 | { | ||
373 | struct gpio_rcar_priv *p = platform_get_drvdata(pdev); | ||
374 | int ret; | ||
375 | |||
376 | ret = gpiochip_remove(&p->gpio_chip); | ||
377 | if (ret) | ||
378 | return ret; | ||
379 | |||
380 | irq_domain_remove(p->irq_domain); | ||
381 | return 0; | ||
382 | } | ||
383 | |||
384 | static struct platform_driver gpio_rcar_device_driver = { | ||
385 | .probe = gpio_rcar_probe, | ||
386 | .remove = gpio_rcar_remove, | ||
387 | .driver = { | ||
388 | .name = "gpio_rcar", | ||
389 | } | ||
390 | }; | ||
391 | |||
392 | module_platform_driver(gpio_rcar_device_driver); | ||
393 | |||
394 | MODULE_AUTHOR("Magnus Damm"); | ||
395 | MODULE_DESCRIPTION("Renesas R-Car GPIO Driver"); | ||
396 | MODULE_LICENSE("GPL v2"); | ||
diff --git a/drivers/gpio/gpiolib-of.c b/drivers/gpio/gpiolib-of.c index a71a54a3e3f7..465f4ca57e80 100644 --- a/drivers/gpio/gpiolib-of.c +++ b/drivers/gpio/gpiolib-of.c | |||
@@ -193,7 +193,7 @@ static void of_gpiochip_add_pin_range(struct gpio_chip *chip) | |||
193 | if (!np) | 193 | if (!np) |
194 | return; | 194 | return; |
195 | 195 | ||
196 | do { | 196 | for (;; index++) { |
197 | ret = of_parse_phandle_with_args(np, "gpio-ranges", | 197 | ret = of_parse_phandle_with_args(np, "gpio-ranges", |
198 | "#gpio-range-cells", index, &pinspec); | 198 | "#gpio-range-cells", index, &pinspec); |
199 | if (ret) | 199 | if (ret) |
@@ -203,27 +203,15 @@ static void of_gpiochip_add_pin_range(struct gpio_chip *chip) | |||
203 | if (!pctldev) | 203 | if (!pctldev) |
204 | break; | 204 | break; |
205 | 205 | ||
206 | /* | ||
207 | * This assumes that the n GPIO pins are consecutive in the | ||
208 | * GPIO number space, and that the pins are also consecutive | ||
209 | * in their local number space. Currently it is not possible | ||
210 | * to add different ranges for one and the same GPIO chip, | ||
211 | * as the code assumes that we have one consecutive range | ||
212 | * on both, mapping 1-to-1. | ||
213 | * | ||
214 | * TODO: make the OF bindings handle multiple sparse ranges | ||
215 | * on the same GPIO chip. | ||
216 | */ | ||
217 | ret = gpiochip_add_pin_range(chip, | 206 | ret = gpiochip_add_pin_range(chip, |
218 | pinctrl_dev_get_devname(pctldev), | 207 | pinctrl_dev_get_devname(pctldev), |
219 | 0, /* offset in gpiochip */ | ||
220 | pinspec.args[0], | 208 | pinspec.args[0], |
221 | pinspec.args[1]); | 209 | pinspec.args[1], |
210 | pinspec.args[2]); | ||
222 | 211 | ||
223 | if (ret) | 212 | if (ret) |
224 | break; | 213 | break; |
225 | 214 | } | |
226 | } while (index++); | ||
227 | } | 215 | } |
228 | 216 | ||
229 | #else | 217 | #else |