aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorGregory CLEMENT <gregory.clement@free-electrons.com>2013-01-25 11:59:27 -0500
committerLinus Walleij <linus.walleij@linaro.org>2013-01-28 05:15:31 -0500
commit0e8f2fdacf1d44651aa7e57063c76142d1f4988b (patch)
treef42a0e786de645bef0442959e633c89b966b1cff /drivers
parent6c7e660a27da7494c670bfba21cfeba30457656c (diff)
gpio: pca953x: use simple irqdomain
This switches the legacy irqdomain to the simple one, which will auto-allocate descriptors, and also make sure that we use irq_create_mapping() in the to_irq function. Also use the map function of irq_domain_ops to setup the irq configuration on demand and no more statically during the initialization of the driver. Based on a initial patch from Linus Walleij <linus.walleij@linaro.org> Signed-off-by: Gregory CLEMENT <gregory.clement@free-electrons.com> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/gpio/gpio-pca953x.c65
1 files changed, 28 insertions, 37 deletions
diff --git a/drivers/gpio/gpio-pca953x.c b/drivers/gpio/gpio-pca953x.c
index 3a68aed91114..1dc99062eb14 100644
--- a/drivers/gpio/gpio-pca953x.c
+++ b/drivers/gpio/gpio-pca953x.c
@@ -89,7 +89,6 @@ struct pca953x_chip {
89 u8 irq_stat[MAX_BANK]; 89 u8 irq_stat[MAX_BANK];
90 u8 irq_trig_raise[MAX_BANK]; 90 u8 irq_trig_raise[MAX_BANK];
91 u8 irq_trig_fall[MAX_BANK]; 91 u8 irq_trig_fall[MAX_BANK];
92 int irq_base;
93 struct irq_domain *domain; 92 struct irq_domain *domain;
94#endif 93#endif
95 94
@@ -372,7 +371,7 @@ static int pca953x_gpio_to_irq(struct gpio_chip *gc, unsigned off)
372 struct pca953x_chip *chip; 371 struct pca953x_chip *chip;
373 372
374 chip = container_of(gc, struct pca953x_chip, gpio_chip); 373 chip = container_of(gc, struct pca953x_chip, gpio_chip);
375 return chip->irq_base + off; 374 return irq_create_mapping(chip->domain, off);
376} 375}
377 376
378static void pca953x_irq_mask(struct irq_data *d) 377static void pca953x_irq_mask(struct irq_data *d)
@@ -520,6 +519,27 @@ static irqreturn_t pca953x_irq_handler(int irq, void *devid)
520 return IRQ_HANDLED; 519 return IRQ_HANDLED;
521} 520}
522 521
522static int pca953x_gpio_irq_map(struct irq_domain *d, unsigned int irq,
523 irq_hw_number_t hwirq)
524{
525 irq_clear_status_flags(irq, IRQ_NOREQUEST);
526 irq_set_chip_data(irq, d->host_data);
527 irq_set_chip(irq, &pca953x_irq_chip);
528 irq_set_nested_thread(irq, true);
529#ifdef CONFIG_ARM
530 set_irq_flags(irq, IRQF_VALID);
531#else
532 irq_set_noprobe(irq);
533#endif
534
535 return 0;
536}
537
538static const struct irq_domain_ops pca953x_irq_simple_ops = {
539 .map = pca953x_gpio_irq_map,
540 .xlate = irq_domain_xlate_twocell,
541};
542
523static int pca953x_irq_setup(struct pca953x_chip *chip, 543static int pca953x_irq_setup(struct pca953x_chip *chip,
524 const struct i2c_device_id *id, 544 const struct i2c_device_id *id,
525 int irq_base) 545 int irq_base)
@@ -529,7 +549,6 @@ static int pca953x_irq_setup(struct pca953x_chip *chip,
529 549
530 if (irq_base != -1 550 if (irq_base != -1
531 && (id->driver_data & PCA_INT)) { 551 && (id->driver_data & PCA_INT)) {
532 int lvl;
533 552
534 switch (chip->chip_type) { 553 switch (chip->chip_type) {
535 case PCA953X_TYPE: 554 case PCA953X_TYPE:
@@ -552,34 +571,13 @@ static int pca953x_irq_setup(struct pca953x_chip *chip,
552 chip->irq_stat[i] &= chip->reg_direction[i]; 571 chip->irq_stat[i] &= chip->reg_direction[i];
553 mutex_init(&chip->irq_lock); 572 mutex_init(&chip->irq_lock);
554 573
555 chip->irq_base = irq_alloc_descs(-1, irq_base, chip->gpio_chip.ngpio, -1); 574 chip->domain = irq_domain_add_simple(client->dev.of_node,
556 if (chip->irq_base < 0)
557 goto out_failed;
558
559 chip->domain = irq_domain_add_legacy(client->dev.of_node,
560 chip->gpio_chip.ngpio, 575 chip->gpio_chip.ngpio,
561 chip->irq_base, 576 irq_base,
562 0, 577 &pca953x_irq_simple_ops,
563 &irq_domain_simple_ops,
564 NULL); 578 NULL);
565 if (!chip->domain) { 579 if (!chip->domain)
566 ret = -ENODEV; 580 return -ENODEV;
567 goto out_irqdesc_free;
568 }
569
570 for (lvl = 0; lvl < chip->gpio_chip.ngpio; lvl++) {
571 int irq = lvl + chip->irq_base;
572
573 irq_clear_status_flags(irq, IRQ_NOREQUEST);
574 irq_set_chip_data(irq, chip);
575 irq_set_chip(irq, &pca953x_irq_chip);
576 irq_set_nested_thread(irq, true);
577#ifdef CONFIG_ARM
578 set_irq_flags(irq, IRQF_VALID);
579#else
580 irq_set_noprobe(irq);
581#endif
582 }
583 581
584 ret = request_threaded_irq(client->irq, 582 ret = request_threaded_irq(client->irq,
585 NULL, 583 NULL,
@@ -589,25 +587,18 @@ static int pca953x_irq_setup(struct pca953x_chip *chip,
589 if (ret) { 587 if (ret) {
590 dev_err(&client->dev, "failed to request irq %d\n", 588 dev_err(&client->dev, "failed to request irq %d\n",
591 client->irq); 589 client->irq);
592 goto out_irqdesc_free; 590 return ret;
593 } 591 }
594 592
595 chip->gpio_chip.to_irq = pca953x_gpio_to_irq; 593 chip->gpio_chip.to_irq = pca953x_gpio_to_irq;
596 } 594 }
597 595
598 return 0; 596 return 0;
599
600out_irqdesc_free:
601 irq_free_descs(chip->irq_base, chip->gpio_chip.ngpio);
602out_failed:
603 chip->irq_base = -1;
604 return ret;
605} 597}
606 598
607static void pca953x_irq_teardown(struct pca953x_chip *chip) 599static void pca953x_irq_teardown(struct pca953x_chip *chip)
608{ 600{
609 if (chip->irq_base != -1) { 601 if (chip->irq_base != -1) {
610 irq_free_descs(chip->irq_base, chip->gpio_chip.ngpio);
611 free_irq(chip->client->irq, chip); 602 free_irq(chip->client->irq, chip);
612 } 603 }
613} 604}