summaryrefslogtreecommitdiffstats
path: root/drivers/gpio/gpio-pxa.c
diff options
context:
space:
mode:
authorRobert Jarzmik <robert.jarzmik@free.fr>2015-11-28 16:37:44 -0500
committerLinus Walleij <linus.walleij@linaro.org>2015-12-10 10:05:44 -0500
commit384ca3c6a28d27030ec971f20b775c596ff87ae5 (patch)
treed61d5f041a5ef12ce87b962a5871285a15a2ff09 /drivers/gpio/gpio-pxa.c
parent8852b2f7dbf69544fb2ea65896405e11d930e132 (diff)
gpio: pxa: change the interrupt management
The interrupt management is changed by this patch to rely on chip data instead of chained interrupts. The main goal is to loosen the dependency on the global pxa chip structure in favor of the passed chip data. The secondary goal is to better show in /proc/interrupts the difference between interrupts for gpio0 and gpio1 (directly wired to interrupt controller), and the other gpios (wired onto a third line in the interrupt controller). The last advantage of this patch is that the interrupt is actually requested, so that another driver cannot steal this line, or overwrite the handler. Signed-off-by: Robert Jarzmik <robert.jarzmik@free.fr> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Diffstat (limited to 'drivers/gpio/gpio-pxa.c')
-rw-r--r--drivers/gpio/gpio-pxa.c145
1 files changed, 82 insertions, 63 deletions
diff --git a/drivers/gpio/gpio-pxa.c b/drivers/gpio/gpio-pxa.c
index 69916c65f094..ccc83faf9275 100644
--- a/drivers/gpio/gpio-pxa.c
+++ b/drivers/gpio/gpio-pxa.c
@@ -64,11 +64,6 @@
64int pxa_last_gpio; 64int pxa_last_gpio;
65static int irq_base; 65static int irq_base;
66 66
67#ifdef CONFIG_OF
68static struct irq_domain *domain;
69static struct device_node *pxa_gpio_of_node;
70#endif
71
72struct pxa_gpio_bank { 67struct pxa_gpio_bank {
73 void __iomem *regbase; 68 void __iomem *regbase;
74 unsigned long irq_mask; 69 unsigned long irq_mask;
@@ -87,6 +82,7 @@ struct pxa_gpio_chip {
87 struct device *dev; 82 struct device *dev;
88 struct gpio_chip chip; 83 struct gpio_chip chip;
89 struct pxa_gpio_bank *banks; 84 struct pxa_gpio_bank *banks;
85 struct irq_domain *irqdomain;
90 86
91 int irq0; 87 int irq0;
92 int irq1; 88 int irq1;
@@ -231,14 +227,23 @@ static inline int __gpio_is_occupied(struct pxa_gpio_chip *pchip, unsigned gpio)
231 return ret; 227 return ret;
232} 228}
233 229
234static int pxa_gpio_to_irq(struct gpio_chip *chip, unsigned offset) 230int pxa_irq_to_gpio(int irq)
235{ 231{
236 return offset + irq_base; 232 struct pxa_gpio_chip *pchip = pxa_gpio_chip;
233 int irq_gpio0;
234
235 irq_gpio0 = irq_find_mapping(pchip->irqdomain, 0);
236 if (irq_gpio0 > 0)
237 return irq - irq_gpio0;
238
239 return irq_gpio0;
237} 240}
238 241
239int pxa_irq_to_gpio(int irq) 242static int pxa_gpio_to_irq(struct gpio_chip *chip, unsigned offset)
240{ 243{
241 return irq - irq_base; 244 struct pxa_gpio_chip *pchip = chip_to_pxachip(chip);
245
246 return irq_find_mapping(pchip->irqdomain, offset);
242} 247}
243 248
244static int pxa_gpio_direction_input(struct gpio_chip *chip, unsigned offset) 249static int pxa_gpio_direction_input(struct gpio_chip *chip, unsigned offset)
@@ -314,7 +319,7 @@ static int pxa_gpio_of_xlate(struct gpio_chip *gc,
314#endif 319#endif
315 320
316static int pxa_init_gpio_chip(struct pxa_gpio_chip *pchip, int ngpio, 321static int pxa_init_gpio_chip(struct pxa_gpio_chip *pchip, int ngpio,
317 void __iomem *regbase) 322 struct device_node *np, void __iomem *regbase)
318{ 323{
319 int i, gpio, nbanks = DIV_ROUND_UP(ngpio, 32); 324 int i, gpio, nbanks = DIV_ROUND_UP(ngpio, 32);
320 struct pxa_gpio_bank *bank; 325 struct pxa_gpio_bank *bank;
@@ -332,7 +337,7 @@ static int pxa_init_gpio_chip(struct pxa_gpio_chip *pchip, int ngpio,
332 pchip->chip.to_irq = pxa_gpio_to_irq; 337 pchip->chip.to_irq = pxa_gpio_to_irq;
333 pchip->chip.ngpio = ngpio; 338 pchip->chip.ngpio = ngpio;
334#ifdef CONFIG_OF_GPIO 339#ifdef CONFIG_OF_GPIO
335 pchip->chip.of_node = pxa_gpio_of_node; 340 pchip->chip.of_node = np;
336 pchip->chip.of_xlate = pxa_gpio_of_xlate; 341 pchip->chip.of_xlate = pxa_gpio_of_xlate;
337 pchip->chip.of_gpio_n_cells = 2; 342 pchip->chip.of_gpio_n_cells = 2;
338#endif 343#endif
@@ -362,8 +367,8 @@ static inline void update_edge_detect(struct pxa_gpio_bank *c)
362 367
363static int pxa_gpio_irq_type(struct irq_data *d, unsigned int type) 368static int pxa_gpio_irq_type(struct irq_data *d, unsigned int type)
364{ 369{
365 struct pxa_gpio_chip *pchip = pxa_gpio_chip; 370 struct pxa_gpio_chip *pchip = irq_data_get_irq_chip_data(d);
366 int gpio = pxa_irq_to_gpio(d->irq); 371 unsigned int gpio = irqd_to_hwirq(d);
367 struct pxa_gpio_bank *c = gpio_to_pxabank(&pchip->chip, gpio); 372 struct pxa_gpio_bank *c = gpio_to_pxabank(&pchip->chip, gpio);
368 unsigned long gpdr, mask = GPIO_bit(gpio); 373 unsigned long gpdr, mask = GPIO_bit(gpio);
369 374
@@ -405,16 +410,13 @@ static int pxa_gpio_irq_type(struct irq_data *d, unsigned int type)
405 return 0; 410 return 0;
406} 411}
407 412
408static void pxa_gpio_demux_handler(struct irq_desc *desc) 413static irqreturn_t pxa_gpio_demux_handler(int in_irq, void *d)
409{ 414{
410 int loop, gpio, n, handled = 0; 415 int loop, gpio, n, handled = 0;
411 unsigned long gedr; 416 unsigned long gedr;
412 struct irq_chip *chip = irq_desc_get_chip(desc); 417 struct pxa_gpio_chip *pchip = d;
413 struct pxa_gpio_chip *pchip = pxa_gpio_chip;
414 struct pxa_gpio_bank *c; 418 struct pxa_gpio_bank *c;
415 419
416 chained_irq_enter(chip, desc);
417
418 do { 420 do {
419 loop = 0; 421 loop = 0;
420 for_each_gpio_bank(gpio, c, pchip) { 422 for_each_gpio_bank(gpio, c, pchip) {
@@ -428,15 +430,31 @@ static void pxa_gpio_demux_handler(struct irq_desc *desc)
428 generic_handle_irq(gpio_to_irq(gpio + n)); 430 generic_handle_irq(gpio_to_irq(gpio + n));
429 } 431 }
430 } 432 }
433 handled += loop;
431 } while (loop); 434 } while (loop);
432 435
433 chained_irq_exit(chip, desc); 436 return handled ? IRQ_HANDLED : IRQ_NONE;
437}
438
439static irqreturn_t pxa_gpio_direct_handler(int in_irq, void *d)
440{
441 struct pxa_gpio_chip *pchip = d;
442
443 if (in_irq == pchip->irq0) {
444 generic_handle_irq(gpio_to_irq(0));
445 } else if (in_irq == pchip->irq1) {
446 generic_handle_irq(gpio_to_irq(1));
447 } else {
448 pr_err("%s() unknown irq %d\n", __func__, in_irq);
449 return IRQ_NONE;
450 }
451 return IRQ_HANDLED;
434} 452}
435 453
436static void pxa_ack_muxed_gpio(struct irq_data *d) 454static void pxa_ack_muxed_gpio(struct irq_data *d)
437{ 455{
438 struct pxa_gpio_chip *pchip = pxa_gpio_chip; 456 struct pxa_gpio_chip *pchip = irq_data_get_irq_chip_data(d);
439 int gpio = pxa_irq_to_gpio(d->irq); 457 unsigned int gpio = irqd_to_hwirq(d);
440 void __iomem *base = gpio_bank_base(&pchip->chip, gpio); 458 void __iomem *base = gpio_bank_base(&pchip->chip, gpio);
441 459
442 writel_relaxed(GPIO_bit(gpio), base + GEDR_OFFSET); 460 writel_relaxed(GPIO_bit(gpio), base + GEDR_OFFSET);
@@ -444,8 +462,8 @@ static void pxa_ack_muxed_gpio(struct irq_data *d)
444 462
445static void pxa_mask_muxed_gpio(struct irq_data *d) 463static void pxa_mask_muxed_gpio(struct irq_data *d)
446{ 464{
447 struct pxa_gpio_chip *pchip = pxa_gpio_chip; 465 struct pxa_gpio_chip *pchip = irq_data_get_irq_chip_data(d);
448 int gpio = pxa_irq_to_gpio(d->irq); 466 unsigned int gpio = irqd_to_hwirq(d);
449 struct pxa_gpio_bank *b = gpio_to_pxabank(&pchip->chip, gpio); 467 struct pxa_gpio_bank *b = gpio_to_pxabank(&pchip->chip, gpio);
450 void __iomem *base = gpio_bank_base(&pchip->chip, gpio); 468 void __iomem *base = gpio_bank_base(&pchip->chip, gpio);
451 uint32_t grer, gfer; 469 uint32_t grer, gfer;
@@ -460,8 +478,8 @@ static void pxa_mask_muxed_gpio(struct irq_data *d)
460 478
461static int pxa_gpio_set_wake(struct irq_data *d, unsigned int on) 479static int pxa_gpio_set_wake(struct irq_data *d, unsigned int on)
462{ 480{
463 int gpio = pxa_irq_to_gpio(d->irq); 481 struct pxa_gpio_chip *pchip = irq_data_get_irq_chip_data(d);
464 struct pxa_gpio_chip *pchip = pxa_gpio_chip; 482 unsigned int gpio = irqd_to_hwirq(d);
465 483
466 if (pchip->set_wake) 484 if (pchip->set_wake)
467 return pchip->set_wake(gpio, on); 485 return pchip->set_wake(gpio, on);
@@ -471,8 +489,8 @@ static int pxa_gpio_set_wake(struct irq_data *d, unsigned int on)
471 489
472static void pxa_unmask_muxed_gpio(struct irq_data *d) 490static void pxa_unmask_muxed_gpio(struct irq_data *d)
473{ 491{
474 struct pxa_gpio_chip *pchip = pxa_gpio_chip; 492 struct pxa_gpio_chip *pchip = irq_data_get_irq_chip_data(d);
475 int gpio = pxa_irq_to_gpio(d->irq); 493 unsigned int gpio = irqd_to_hwirq(d);
476 struct pxa_gpio_bank *c = gpio_to_pxabank(&pchip->chip, gpio); 494 struct pxa_gpio_bank *c = gpio_to_pxabank(&pchip->chip, gpio);
477 495
478 c->irq_mask |= GPIO_bit(gpio); 496 c->irq_mask |= GPIO_bit(gpio);
@@ -531,6 +549,7 @@ static int pxa_irq_domain_map(struct irq_domain *d, unsigned int irq,
531{ 549{
532 irq_set_chip_and_handler(irq, &pxa_muxed_gpio_chip, 550 irq_set_chip_and_handler(irq, &pxa_muxed_gpio_chip,
533 handle_edge_irq); 551 handle_edge_irq);
552 irq_set_chip_data(irq, d->host_data);
534 irq_set_noprobe(irq); 553 irq_set_noprobe(irq);
535 return 0; 554 return 0;
536} 555}
@@ -544,7 +563,6 @@ static int pxa_gpio_probe_dt(struct platform_device *pdev,
544 struct pxa_gpio_chip *pchip) 563 struct pxa_gpio_chip *pchip)
545{ 564{
546 int nr_gpios; 565 int nr_gpios;
547 struct device_node *np = pdev->dev.of_node;
548 const struct of_device_id *of_id = 566 const struct of_device_id *of_id =
549 of_match_device(pxa_gpio_dt_ids, &pdev->dev); 567 of_match_device(pxa_gpio_dt_ids, &pdev->dev);
550 const struct pxa_gpio_id *gpio_id; 568 const struct pxa_gpio_id *gpio_id;
@@ -564,10 +582,7 @@ static int pxa_gpio_probe_dt(struct platform_device *pdev,
564 dev_err(&pdev->dev, "Failed to allocate IRQ numbers\n"); 582 dev_err(&pdev->dev, "Failed to allocate IRQ numbers\n");
565 return irq_base; 583 return irq_base;
566 } 584 }
567 domain = irq_domain_add_legacy(np, nr_gpios, irq_base, 0, 585 return irq_base;
568 &pxa_irq_domain_ops, pchip);
569 pxa_gpio_of_node = np;
570 return 0;
571} 586}
572#else 587#else
573#define pxa_gpio_probe_dt(pdev, pchip) (-1) 588#define pxa_gpio_probe_dt(pdev, pchip) (-1)
@@ -581,7 +596,7 @@ static int pxa_gpio_probe(struct platform_device *pdev)
581 struct clk *clk; 596 struct clk *clk;
582 struct pxa_gpio_platform_data *info; 597 struct pxa_gpio_platform_data *info;
583 void __iomem *gpio_reg_base; 598 void __iomem *gpio_reg_base;
584 int gpio, irq, ret, use_of = 0; 599 int gpio, ret;
585 int irq0 = 0, irq1 = 0, irq_mux, gpio_offset = 0; 600 int irq0 = 0, irq1 = 0, irq_mux, gpio_offset = 0;
586 601
587 pchip = devm_kzalloc(&pdev->dev, sizeof(*pchip), GFP_KERNEL); 602 pchip = devm_kzalloc(&pdev->dev, sizeof(*pchip), GFP_KERNEL);
@@ -597,22 +612,29 @@ static int pxa_gpio_probe(struct platform_device *pdev)
597 pxa_last_gpio = pxa_gpio_nums(pdev); 612 pxa_last_gpio = pxa_gpio_nums(pdev);
598 pchip->set_wake = info->gpio_set_wake; 613 pchip->set_wake = info->gpio_set_wake;
599 } else { 614 } else {
600 irq_base = 0; 615 irq_base = pxa_gpio_probe_dt(pdev, pchip);
601 use_of = 1; 616 if (irq_base < 0)
602 ret = pxa_gpio_probe_dt(pdev, pchip);
603 if (ret < 0)
604 return -EINVAL; 617 return -EINVAL;
605 } 618 }
606 619
607 if (!pxa_last_gpio) 620 if (!pxa_last_gpio)
608 return -EINVAL; 621 return -EINVAL;
609 622
623 pchip->irqdomain = irq_domain_add_legacy(pdev->dev.of_node,
624 pxa_last_gpio + 1, irq_base,
625 0, &pxa_irq_domain_ops, pchip);
626 if (IS_ERR(pchip->irqdomain))
627 return PTR_ERR(pchip->irqdomain);
628
610 irq0 = platform_get_irq_byname(pdev, "gpio0"); 629 irq0 = platform_get_irq_byname(pdev, "gpio0");
611 irq1 = platform_get_irq_byname(pdev, "gpio1"); 630 irq1 = platform_get_irq_byname(pdev, "gpio1");
612 irq_mux = platform_get_irq_byname(pdev, "gpio_mux"); 631 irq_mux = platform_get_irq_byname(pdev, "gpio_mux");
613 if ((irq0 > 0 && irq1 <= 0) || (irq0 <= 0 && irq1 > 0) 632 if ((irq0 > 0 && irq1 <= 0) || (irq0 <= 0 && irq1 > 0)
614 || (irq_mux <= 0)) 633 || (irq_mux <= 0))
615 return -EINVAL; 634 return -EINVAL;
635
636 pchip->irq0 = irq0;
637 pchip->irq1 = irq1;
616 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 638 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
617 gpio_reg_base = devm_ioremap(&pdev->dev, res->start, 639 gpio_reg_base = devm_ioremap(&pdev->dev, res->start,
618 resource_size(res)); 640 resource_size(res));
@@ -635,7 +657,8 @@ static int pxa_gpio_probe(struct platform_device *pdev)
635 } 657 }
636 658
637 /* Initialize GPIO chips */ 659 /* Initialize GPIO chips */
638 ret = pxa_init_gpio_chip(pchip, pxa_last_gpio + 1, gpio_reg_base); 660 ret = pxa_init_gpio_chip(pchip, pxa_last_gpio + 1, pdev->dev.of_node,
661 gpio_reg_base);
639 if (ret) { 662 if (ret) {
640 clk_put(clk); 663 clk_put(clk);
641 return ret; 664 return ret;
@@ -651,35 +674,31 @@ static int pxa_gpio_probe(struct platform_device *pdev)
651 writel_relaxed(~0, c->regbase + ED_MASK_OFFSET); 674 writel_relaxed(~0, c->regbase + ED_MASK_OFFSET);
652 } 675 }
653 676
654 if (!use_of) { 677 if (irq0 > 0) {
655 if (irq0 > 0) { 678 ret = devm_request_irq(&pdev->dev,
656 irq = gpio_to_irq(0); 679 irq0, pxa_gpio_direct_handler, 0,
657 irq_set_chip_and_handler(irq, &pxa_muxed_gpio_chip, 680 "gpio-0", pchip);
658 handle_edge_irq); 681 if (ret)
659 irq_clear_status_flags(irq, IRQ_NOREQUEST | IRQ_NOPROBE); 682 dev_err(&pdev->dev, "request of gpio0 irq failed: %d\n",
660 } 683 ret);
661 if (irq1 > 0) {
662 irq = gpio_to_irq(1);
663 irq_set_chip_and_handler(irq, &pxa_muxed_gpio_chip,
664 handle_edge_irq);
665 irq_clear_status_flags(irq, IRQ_NOREQUEST | IRQ_NOPROBE);
666 }
667
668 for (irq = gpio_to_irq(gpio_offset);
669 irq <= gpio_to_irq(pxa_last_gpio); irq++) {
670 irq_set_chip_and_handler(irq, &pxa_muxed_gpio_chip,
671 handle_edge_irq);
672 irq_clear_status_flags(irq, IRQ_NOREQUEST | IRQ_NOPROBE);
673 }
674 } 684 }
685 if (irq1 > 0) {
686 ret = devm_request_irq(&pdev->dev,
687 irq1, pxa_gpio_direct_handler, 0,
688 "gpio-1", pchip);
689 if (ret)
690 dev_err(&pdev->dev, "request of gpio1 irq failed: %d\n",
691 ret);
692 }
693 ret = devm_request_irq(&pdev->dev,
694 irq_mux, pxa_gpio_demux_handler, 0,
695 "gpio-mux", pchip);
696 if (ret)
697 dev_err(&pdev->dev, "request of gpio-mux irq failed: %d\n",
698 ret);
675 699
676 if (irq0 > 0)
677 irq_set_chained_handler(irq0, pxa_gpio_demux_handler);
678 if (irq1 > 0)
679 irq_set_chained_handler(irq1, pxa_gpio_demux_handler);
680 pxa_gpio_chip = pchip; 700 pxa_gpio_chip = pchip;
681 701
682 irq_set_chained_handler(irq_mux, pxa_gpio_demux_handler);
683 return 0; 702 return 0;
684} 703}
685 704