aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/gpio/gpio-stmpe.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/gpio/gpio-stmpe.c')
-rw-r--r--drivers/gpio/gpio-stmpe.c88
1 files changed, 55 insertions, 33 deletions
diff --git a/drivers/gpio/gpio-stmpe.c b/drivers/gpio/gpio-stmpe.c
index dce34727bbf8..3e1d39895cef 100644
--- a/drivers/gpio/gpio-stmpe.c
+++ b/drivers/gpio/gpio-stmpe.c
@@ -11,7 +11,9 @@
11#include <linux/slab.h> 11#include <linux/slab.h>
12#include <linux/gpio.h> 12#include <linux/gpio.h>
13#include <linux/irq.h> 13#include <linux/irq.h>
14#include <linux/irqdomain.h>
14#include <linux/interrupt.h> 15#include <linux/interrupt.h>
16#include <linux/of.h>
15#include <linux/mfd/stmpe.h> 17#include <linux/mfd/stmpe.h>
16 18
17/* 19/*
@@ -28,6 +30,7 @@ struct stmpe_gpio {
28 struct stmpe *stmpe; 30 struct stmpe *stmpe;
29 struct device *dev; 31 struct device *dev;
30 struct mutex irq_lock; 32 struct mutex irq_lock;
33 struct irq_domain *domain;
31 34
32 int irq_base; 35 int irq_base;
33 unsigned norequest_mask; 36 unsigned norequest_mask;
@@ -103,7 +106,7 @@ static int stmpe_gpio_to_irq(struct gpio_chip *chip, unsigned offset)
103{ 106{
104 struct stmpe_gpio *stmpe_gpio = to_stmpe_gpio(chip); 107 struct stmpe_gpio *stmpe_gpio = to_stmpe_gpio(chip);
105 108
106 return stmpe_gpio->irq_base + offset; 109 return irq_create_mapping(stmpe_gpio->domain, offset);
107} 110}
108 111
109static int stmpe_gpio_request(struct gpio_chip *chip, unsigned offset) 112static int stmpe_gpio_request(struct gpio_chip *chip, unsigned offset)
@@ -132,7 +135,7 @@ static struct gpio_chip template_chip = {
132static int stmpe_gpio_irq_set_type(struct irq_data *d, unsigned int type) 135static int stmpe_gpio_irq_set_type(struct irq_data *d, unsigned int type)
133{ 136{
134 struct stmpe_gpio *stmpe_gpio = irq_data_get_irq_chip_data(d); 137 struct stmpe_gpio *stmpe_gpio = irq_data_get_irq_chip_data(d);
135 int offset = d->irq - stmpe_gpio->irq_base; 138 int offset = d->hwirq;
136 int regoffset = offset / 8; 139 int regoffset = offset / 8;
137 int mask = 1 << (offset % 8); 140 int mask = 1 << (offset % 8);
138 141
@@ -199,7 +202,7 @@ static void stmpe_gpio_irq_sync_unlock(struct irq_data *d)
199static void stmpe_gpio_irq_mask(struct irq_data *d) 202static void stmpe_gpio_irq_mask(struct irq_data *d)
200{ 203{
201 struct stmpe_gpio *stmpe_gpio = irq_data_get_irq_chip_data(d); 204 struct stmpe_gpio *stmpe_gpio = irq_data_get_irq_chip_data(d);
202 int offset = d->irq - stmpe_gpio->irq_base; 205 int offset = d->hwirq;
203 int regoffset = offset / 8; 206 int regoffset = offset / 8;
204 int mask = 1 << (offset % 8); 207 int mask = 1 << (offset % 8);
205 208
@@ -209,7 +212,7 @@ static void stmpe_gpio_irq_mask(struct irq_data *d)
209static void stmpe_gpio_irq_unmask(struct irq_data *d) 212static void stmpe_gpio_irq_unmask(struct irq_data *d)
210{ 213{
211 struct stmpe_gpio *stmpe_gpio = irq_data_get_irq_chip_data(d); 214 struct stmpe_gpio *stmpe_gpio = irq_data_get_irq_chip_data(d);
212 int offset = d->irq - stmpe_gpio->irq_base; 215 int offset = d->hwirq;
213 int regoffset = offset / 8; 216 int regoffset = offset / 8;
214 int mask = 1 << (offset % 8); 217 int mask = 1 << (offset % 8);
215 218
@@ -251,8 +254,9 @@ static irqreturn_t stmpe_gpio_irq(int irq, void *dev)
251 while (stat) { 254 while (stat) {
252 int bit = __ffs(stat); 255 int bit = __ffs(stat);
253 int line = bank * 8 + bit; 256 int line = bank * 8 + bit;
257 int virq = irq_find_mapping(stmpe_gpio->domain, line);
254 258
255 handle_nested_irq(stmpe_gpio->irq_base + line); 259 handle_nested_irq(virq);
256 stat &= ~(1 << bit); 260 stat &= ~(1 << bit);
257 } 261 }
258 262
@@ -267,43 +271,61 @@ static irqreturn_t stmpe_gpio_irq(int irq, void *dev)
267 return IRQ_HANDLED; 271 return IRQ_HANDLED;
268} 272}
269 273
270static int __devinit stmpe_gpio_irq_init(struct stmpe_gpio *stmpe_gpio) 274int stmpe_gpio_irq_map(struct irq_domain *d, unsigned int virq,
275 irq_hw_number_t hwirq)
271{ 276{
272 int base = stmpe_gpio->irq_base; 277 struct stmpe_gpio *stmpe_gpio = d->host_data;
273 int irq;
274 278
275 for (irq = base; irq < base + stmpe_gpio->chip.ngpio; irq++) { 279 if (!stmpe_gpio)
276 irq_set_chip_data(irq, stmpe_gpio); 280 return -EINVAL;
277 irq_set_chip_and_handler(irq, &stmpe_gpio_irq_chip, 281
278 handle_simple_irq); 282 irq_set_chip_data(hwirq, stmpe_gpio);
279 irq_set_nested_thread(irq, 1); 283 irq_set_chip_and_handler(hwirq, &stmpe_gpio_irq_chip,
284 handle_simple_irq);
285 irq_set_nested_thread(hwirq, 1);
280#ifdef CONFIG_ARM 286#ifdef CONFIG_ARM
281 set_irq_flags(irq, IRQF_VALID); 287 set_irq_flags(hwirq, IRQF_VALID);
282#else 288#else
283 irq_set_noprobe(irq); 289 irq_set_noprobe(hwirq);
284#endif 290#endif
285 }
286 291
287 return 0; 292 return 0;
288} 293}
289 294
290static void stmpe_gpio_irq_remove(struct stmpe_gpio *stmpe_gpio) 295void stmpe_gpio_irq_unmap(struct irq_domain *d, unsigned int virq)
291{ 296{
292 int base = stmpe_gpio->irq_base;
293 int irq;
294
295 for (irq = base; irq < base + stmpe_gpio->chip.ngpio; irq++) {
296#ifdef CONFIG_ARM 297#ifdef CONFIG_ARM
297 set_irq_flags(irq, 0); 298 set_irq_flags(virq, 0);
298#endif 299#endif
299 irq_set_chip_and_handler(irq, NULL, NULL); 300 irq_set_chip_and_handler(virq, NULL, NULL);
300 irq_set_chip_data(irq, NULL); 301 irq_set_chip_data(virq, NULL);
302}
303
304static const struct irq_domain_ops stmpe_gpio_irq_simple_ops = {
305 .unmap = stmpe_gpio_irq_unmap,
306 .map = stmpe_gpio_irq_map,
307 .xlate = irq_domain_xlate_twocell,
308};
309
310static int __devinit stmpe_gpio_irq_init(struct stmpe_gpio *stmpe_gpio)
311{
312 int base = stmpe_gpio->irq_base;
313
314 stmpe_gpio->domain = irq_domain_add_simple(NULL,
315 stmpe_gpio->chip.ngpio, base,
316 &stmpe_gpio_irq_simple_ops, stmpe_gpio);
317 if (!stmpe_gpio->domain) {
318 dev_err(stmpe_gpio->dev, "failed to create irqdomain\n");
319 return -ENOSYS;
301 } 320 }
321
322 return 0;
302} 323}
303 324
304static int __devinit stmpe_gpio_probe(struct platform_device *pdev) 325static int __devinit stmpe_gpio_probe(struct platform_device *pdev)
305{ 326{
306 struct stmpe *stmpe = dev_get_drvdata(pdev->dev.parent); 327 struct stmpe *stmpe = dev_get_drvdata(pdev->dev.parent);
328 struct device_node *np = pdev->dev.of_node;
307 struct stmpe_gpio_platform_data *pdata; 329 struct stmpe_gpio_platform_data *pdata;
308 struct stmpe_gpio *stmpe_gpio; 330 struct stmpe_gpio *stmpe_gpio;
309 int ret; 331 int ret;
@@ -321,13 +343,17 @@ static int __devinit stmpe_gpio_probe(struct platform_device *pdev)
321 343
322 stmpe_gpio->dev = &pdev->dev; 344 stmpe_gpio->dev = &pdev->dev;
323 stmpe_gpio->stmpe = stmpe; 345 stmpe_gpio->stmpe = stmpe;
324 stmpe_gpio->norequest_mask = pdata ? pdata->norequest_mask : 0;
325
326 stmpe_gpio->chip = template_chip; 346 stmpe_gpio->chip = template_chip;
327 stmpe_gpio->chip.ngpio = stmpe->num_gpios; 347 stmpe_gpio->chip.ngpio = stmpe->num_gpios;
328 stmpe_gpio->chip.dev = &pdev->dev; 348 stmpe_gpio->chip.dev = &pdev->dev;
329 stmpe_gpio->chip.base = pdata ? pdata->gpio_base : -1; 349 stmpe_gpio->chip.base = pdata ? pdata->gpio_base : -1;
330 350
351 if (pdata)
352 stmpe_gpio->norequest_mask = pdata->norequest_mask;
353 else if (np)
354 of_property_read_u32(np, "st,norequest-mask",
355 &stmpe_gpio->norequest_mask);
356
331 if (irq >= 0) 357 if (irq >= 0)
332 stmpe_gpio->irq_base = stmpe->irq_base + STMPE_INT_GPIO(0); 358 stmpe_gpio->irq_base = stmpe->irq_base + STMPE_INT_GPIO(0);
333 else 359 else
@@ -348,7 +374,7 @@ static int __devinit stmpe_gpio_probe(struct platform_device *pdev)
348 IRQF_ONESHOT, "stmpe-gpio", stmpe_gpio); 374 IRQF_ONESHOT, "stmpe-gpio", stmpe_gpio);
349 if (ret) { 375 if (ret) {
350 dev_err(&pdev->dev, "unable to get irq: %d\n", ret); 376 dev_err(&pdev->dev, "unable to get irq: %d\n", ret);
351 goto out_removeirq; 377 goto out_disable;
352 } 378 }
353 } 379 }
354 380
@@ -368,9 +394,6 @@ static int __devinit stmpe_gpio_probe(struct platform_device *pdev)
368out_freeirq: 394out_freeirq:
369 if (irq >= 0) 395 if (irq >= 0)
370 free_irq(irq, stmpe_gpio); 396 free_irq(irq, stmpe_gpio);
371out_removeirq:
372 if (irq >= 0)
373 stmpe_gpio_irq_remove(stmpe_gpio);
374out_disable: 397out_disable:
375 stmpe_disable(stmpe, STMPE_BLOCK_GPIO); 398 stmpe_disable(stmpe, STMPE_BLOCK_GPIO);
376out_free: 399out_free:
@@ -398,10 +421,9 @@ static int __devexit stmpe_gpio_remove(struct platform_device *pdev)
398 421
399 stmpe_disable(stmpe, STMPE_BLOCK_GPIO); 422 stmpe_disable(stmpe, STMPE_BLOCK_GPIO);
400 423
401 if (irq >= 0) { 424 if (irq >= 0)
402 free_irq(irq, stmpe_gpio); 425 free_irq(irq, stmpe_gpio);
403 stmpe_gpio_irq_remove(stmpe_gpio); 426
404 }
405 platform_set_drvdata(pdev, NULL); 427 platform_set_drvdata(pdev, NULL);
406 kfree(stmpe_gpio); 428 kfree(stmpe_gpio);
407 429