aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/gpio
diff options
context:
space:
mode:
authorLad, Prabhakar <prabhakar.csengg@gmail.com>2013-11-21 13:15:27 -0500
committerSekhar Nori <nsekhar@ti.com>2013-12-25 13:32:11 -0500
commit9211ff3140f24f6372f4627fc8b473aa08249104 (patch)
tree2317ac8ace11e1d5b2ef31e80fea0ddafc392ed3 /drivers/gpio
parentee89cf63a1274a597fc2616d575251f88b3072b6 (diff)
gpio: davinci: convert to use irqdomain support.
Convert the davinci gpio driver to use irqdomain support. Signed-off-by: Lad, Prabhakar <prabhakar.csengg@gmail.com> [grygorii.strashko@ti.com: - switch to use one irq-domain per all GPIO banks - keep irq_create_mapping() call in gpio_to_irq_banked() as it simply transformed to irq_find_mapping() if IRQ mapping exist already] Signed-off-by: Grygorii Strashko <grygorii.strashko@ti.com> Acked-by: Linus Walleij <linus.walleij@linaro.org> Signed-off-by: Sekhar Nori <nsekhar@ti.com>
Diffstat (limited to 'drivers/gpio')
-rw-r--r--drivers/gpio/gpio-davinci.c80
1 files changed, 47 insertions, 33 deletions
diff --git a/drivers/gpio/gpio-davinci.c b/drivers/gpio/gpio-davinci.c
index 23c187c01659..92d9922cfcc7 100644
--- a/drivers/gpio/gpio-davinci.c
+++ b/drivers/gpio/gpio-davinci.c
@@ -16,6 +16,7 @@
16#include <linux/err.h> 16#include <linux/err.h>
17#include <linux/io.h> 17#include <linux/io.h>
18#include <linux/irq.h> 18#include <linux/irq.h>
19#include <linux/irqdomain.h>
19#include <linux/platform_device.h> 20#include <linux/platform_device.h>
20#include <linux/platform_data/gpio-davinci.h> 21#include <linux/platform_data/gpio-davinci.h>
21 22
@@ -282,8 +283,7 @@ gpio_irq_handler(unsigned irq, struct irq_desc *desc)
282 desc->irq_data.chip->irq_ack(&desc->irq_data); 283 desc->irq_data.chip->irq_ack(&desc->irq_data);
283 while (1) { 284 while (1) {
284 u32 status; 285 u32 status;
285 int n; 286 int bit;
286 int res;
287 287
288 /* ack any irqs */ 288 /* ack any irqs */
289 status = readl_relaxed(&g->intstat) & mask; 289 status = readl_relaxed(&g->intstat) & mask;
@@ -292,17 +292,13 @@ gpio_irq_handler(unsigned irq, struct irq_desc *desc)
292 writel_relaxed(status, &g->intstat); 292 writel_relaxed(status, &g->intstat);
293 293
294 /* now demux them to the right lowlevel handler */ 294 /* now demux them to the right lowlevel handler */
295 n = d->irq_base;
296 if (irq & 1) {
297 n += 16;
298 status >>= 16;
299 }
300 295
301 while (status) { 296 while (status) {
302 res = ffs(status); 297 bit = __ffs(status);
303 n += res; 298 status &= ~BIT(bit);
304 generic_handle_irq(n - 1); 299 generic_handle_irq(
305 status >>= res; 300 irq_find_mapping(d->irq_domain,
301 d->chip.base + bit));
306 } 302 }
307 } 303 }
308 desc->irq_data.chip->irq_unmask(&desc->irq_data); 304 desc->irq_data.chip->irq_unmask(&desc->irq_data);
@@ -313,10 +309,7 @@ static int gpio_to_irq_banked(struct gpio_chip *chip, unsigned offset)
313{ 309{
314 struct davinci_gpio_controller *d = chip2controller(chip); 310 struct davinci_gpio_controller *d = chip2controller(chip);
315 311
316 if (d->irq_base >= 0) 312 return irq_create_mapping(d->irq_domain, d->chip.base + offset);
317 return d->irq_base + offset;
318 else
319 return -ENODEV;
320} 313}
321 314
322static int gpio_to_irq_unbanked(struct gpio_chip *chip, unsigned offset) 315static int gpio_to_irq_unbanked(struct gpio_chip *chip, unsigned offset)
@@ -354,6 +347,27 @@ static int gpio_irq_type_unbanked(struct irq_data *data, unsigned trigger)
354 return 0; 347 return 0;
355} 348}
356 349
350static int
351davinci_gpio_irq_map(struct irq_domain *d, unsigned int irq,
352 irq_hw_number_t hw)
353{
354 struct davinci_gpio_regs __iomem *g = gpio2regs(hw);
355
356 irq_set_chip_and_handler_name(irq, &gpio_irqchip, handle_simple_irq,
357 "davinci_gpio");
358 irq_set_irq_type(irq, IRQ_TYPE_NONE);
359 irq_set_chip_data(irq, (__force void *)g);
360 irq_set_handler_data(irq, (void *)__gpio_mask(hw));
361 set_irq_flags(irq, IRQF_VALID);
362
363 return 0;
364}
365
366static const struct irq_domain_ops davinci_gpio_irq_ops = {
367 .map = davinci_gpio_irq_map,
368 .xlate = irq_domain_xlate_onetwocell,
369};
370
357/* 371/*
358 * NOTE: for suspend/resume, probably best to make a platform_device with 372 * NOTE: for suspend/resume, probably best to make a platform_device with
359 * suspend_late/resume_resume calls hooking into results of the set_wake() 373 * suspend_late/resume_resume calls hooking into results of the set_wake()
@@ -373,6 +387,7 @@ static int davinci_gpio_irq_setup(struct platform_device *pdev)
373 struct davinci_gpio_controller *chips = platform_get_drvdata(pdev); 387 struct davinci_gpio_controller *chips = platform_get_drvdata(pdev);
374 struct davinci_gpio_platform_data *pdata = dev->platform_data; 388 struct davinci_gpio_platform_data *pdata = dev->platform_data;
375 struct davinci_gpio_regs __iomem *g; 389 struct davinci_gpio_regs __iomem *g;
390 struct irq_domain *irq_domain;
376 391
377 ngpio = pdata->ngpio; 392 ngpio = pdata->ngpio;
378 res = platform_get_resource(pdev, IORESOURCE_IRQ, 0); 393 res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
@@ -396,6 +411,20 @@ static int davinci_gpio_irq_setup(struct platform_device *pdev)
396 } 411 }
397 clk_prepare_enable(clk); 412 clk_prepare_enable(clk);
398 413
414 irq = irq_alloc_descs(-1, 0, ngpio, 0);
415 if (irq < 0) {
416 dev_err(dev, "Couldn't allocate IRQ numbers\n");
417 return irq;
418 }
419
420 irq_domain = irq_domain_add_legacy(NULL, ngpio, irq, 0,
421 &davinci_gpio_irq_ops,
422 chips);
423 if (!irq_domain) {
424 dev_err(dev, "Couldn't register an IRQ domain\n");
425 return -ENODEV;
426 }
427
399 /* 428 /*
400 * Arrange gpio_to_irq() support, handling either direct IRQs or 429 * Arrange gpio_to_irq() support, handling either direct IRQs or
401 * banked IRQs. Having GPIOs in the first GPIO bank use direct 430 * banked IRQs. Having GPIOs in the first GPIO bank use direct
@@ -404,9 +433,8 @@ static int davinci_gpio_irq_setup(struct platform_device *pdev)
404 */ 433 */
405 for (gpio = 0, bank = 0; gpio < ngpio; bank++, gpio += 32) { 434 for (gpio = 0, bank = 0; gpio < ngpio; bank++, gpio += 32) {
406 chips[bank].chip.to_irq = gpio_to_irq_banked; 435 chips[bank].chip.to_irq = gpio_to_irq_banked;
407 chips[bank].irq_base = pdata->gpio_unbanked 436 if (!pdata->gpio_unbanked)
408 ? -EINVAL 437 chips[bank].irq_domain = irq_domain;
409 : (pdata->intc_irq_num + gpio);
410 } 438 }
411 439
412 /* 440 /*
@@ -449,11 +477,7 @@ static int davinci_gpio_irq_setup(struct platform_device *pdev)
449 * Or, AINTC can handle IRQs for banks of 16 GPIO IRQs, which we 477 * Or, AINTC can handle IRQs for banks of 16 GPIO IRQs, which we
450 * then chain through our own handler. 478 * then chain through our own handler.
451 */ 479 */
452 for (gpio = 0, irq = gpio_to_irq(0), bank = 0; 480 for (gpio = 0, bank = 0; gpio < ngpio; bank++, bank_irq++, gpio += 16) {
453 gpio < ngpio;
454 bank++, bank_irq++) {
455 unsigned i;
456
457 /* disabled by default, enabled only as needed */ 481 /* disabled by default, enabled only as needed */
458 g = gpio2regs(gpio); 482 g = gpio2regs(gpio);
459 writel_relaxed(~0, &g->clr_falling); 483 writel_relaxed(~0, &g->clr_falling);
@@ -469,14 +493,6 @@ static int davinci_gpio_irq_setup(struct platform_device *pdev)
469 */ 493 */
470 irq_set_handler_data(bank_irq, &chips[gpio / 32]); 494 irq_set_handler_data(bank_irq, &chips[gpio / 32]);
471 495
472 for (i = 0; i < 16 && gpio < ngpio; i++, irq++, gpio++) {
473 irq_set_chip(irq, &gpio_irqchip);
474 irq_set_chip_data(irq, (__force void *)g);
475 irq_set_handler_data(irq, (void *)__gpio_mask(gpio));
476 irq_set_handler(irq, handle_simple_irq);
477 set_irq_flags(irq, IRQF_VALID);
478 }
479
480 binten |= BIT(bank); 496 binten |= BIT(bank);
481 } 497 }
482 498
@@ -487,8 +503,6 @@ done:
487 */ 503 */
488 writel_relaxed(binten, gpio_base + BINTEN); 504 writel_relaxed(binten, gpio_base + BINTEN);
489 505
490 printk(KERN_INFO "DaVinci: %d gpio irqs\n", irq - gpio_to_irq(0));
491
492 return 0; 506 return 0;
493} 507}
494 508