diff options
author | Linus Walleij <linus.walleij@linaro.org> | 2014-03-25 08:37:17 -0400 |
---|---|---|
committer | Linus Walleij <linus.walleij@linaro.org> | 2014-03-26 05:31:34 -0400 |
commit | 523dcce72c72e829b9d391f8020277038c6aab82 (patch) | |
tree | 0c94fa92b3ba1728ada4bad2be034dfec4d90b68 /drivers/pinctrl | |
parent | e0bc34a3dada03a48ff5501381ff7fdef885ed25 (diff) |
pinctrl: coh901: convert driver to use gpiolib irqchip
This converts the COH901 pin control driver to register its
chained irq handler and irqchip using the helpers in the
gpiolib core.
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Diffstat (limited to 'drivers/pinctrl')
-rw-r--r-- | drivers/pinctrl/Kconfig | 1 | ||||
-rw-r--r-- | drivers/pinctrl/pinctrl-coh901.c | 204 |
2 files changed, 54 insertions, 151 deletions
diff --git a/drivers/pinctrl/Kconfig b/drivers/pinctrl/Kconfig index a05087bd1955..0c6eb33daa87 100644 --- a/drivers/pinctrl/Kconfig +++ b/drivers/pinctrl/Kconfig | |||
@@ -324,6 +324,7 @@ config PINCTRL_U300 | |||
324 | config PINCTRL_COH901 | 324 | config PINCTRL_COH901 |
325 | bool "ST-Ericsson U300 COH 901 335/571 GPIO" | 325 | bool "ST-Ericsson U300 COH 901 335/571 GPIO" |
326 | depends on GPIOLIB && ARCH_U300 && PINCTRL_U300 | 326 | depends on GPIOLIB && ARCH_U300 && PINCTRL_U300 |
327 | select GPIOLIB_IRQCHIP | ||
327 | help | 328 | help |
328 | Say yes here to support GPIO interface on ST-Ericsson U300. | 329 | Say yes here to support GPIO interface on ST-Ericsson U300. |
329 | The names of the two IP block variants supported are | 330 | The names of the two IP block variants supported are |
diff --git a/drivers/pinctrl/pinctrl-coh901.c b/drivers/pinctrl/pinctrl-coh901.c index 749db595640c..d182fdd2e715 100644 --- a/drivers/pinctrl/pinctrl-coh901.c +++ b/drivers/pinctrl/pinctrl-coh901.c | |||
@@ -8,17 +8,14 @@ | |||
8 | * Author: Jonas Aaberg <jonas.aberg@stericsson.com> | 8 | * Author: Jonas Aaberg <jonas.aberg@stericsson.com> |
9 | */ | 9 | */ |
10 | #include <linux/module.h> | 10 | #include <linux/module.h> |
11 | #include <linux/irq.h> | ||
12 | #include <linux/interrupt.h> | 11 | #include <linux/interrupt.h> |
13 | #include <linux/delay.h> | 12 | #include <linux/delay.h> |
14 | #include <linux/errno.h> | 13 | #include <linux/errno.h> |
15 | #include <linux/io.h> | 14 | #include <linux/io.h> |
16 | #include <linux/irqdomain.h> | ||
17 | #include <linux/clk.h> | 15 | #include <linux/clk.h> |
18 | #include <linux/err.h> | 16 | #include <linux/err.h> |
19 | #include <linux/platform_device.h> | 17 | #include <linux/platform_device.h> |
20 | #include <linux/gpio.h> | 18 | #include <linux/gpio.h> |
21 | #include <linux/list.h> | ||
22 | #include <linux/slab.h> | 19 | #include <linux/slab.h> |
23 | #include <linux/pinctrl/consumer.h> | 20 | #include <linux/pinctrl/consumer.h> |
24 | #include <linux/pinctrl/pinconf-generic.h> | 21 | #include <linux/pinctrl/pinconf-generic.h> |
@@ -61,9 +58,17 @@ | |||
61 | #define U300_GPIO_PINS_PER_PORT 8 | 58 | #define U300_GPIO_PINS_PER_PORT 8 |
62 | #define U300_GPIO_MAX (U300_GPIO_PINS_PER_PORT * U300_GPIO_NUM_PORTS) | 59 | #define U300_GPIO_MAX (U300_GPIO_PINS_PER_PORT * U300_GPIO_NUM_PORTS) |
63 | 60 | ||
61 | struct u300_gpio_port { | ||
62 | struct u300_gpio *gpio; | ||
63 | char name[8]; | ||
64 | int irq; | ||
65 | int number; | ||
66 | u8 toggle_edge_mode; | ||
67 | }; | ||
68 | |||
64 | struct u300_gpio { | 69 | struct u300_gpio { |
65 | struct gpio_chip chip; | 70 | struct gpio_chip chip; |
66 | struct list_head port_list; | 71 | struct u300_gpio_port ports[U300_GPIO_NUM_PORTS]; |
67 | struct clk *clk; | 72 | struct clk *clk; |
68 | void __iomem *base; | 73 | void __iomem *base; |
69 | struct device *dev; | 74 | struct device *dev; |
@@ -78,16 +83,6 @@ struct u300_gpio { | |||
78 | u32 iev; | 83 | u32 iev; |
79 | }; | 84 | }; |
80 | 85 | ||
81 | struct u300_gpio_port { | ||
82 | struct list_head node; | ||
83 | struct u300_gpio *gpio; | ||
84 | char name[8]; | ||
85 | struct irq_domain *domain; | ||
86 | int irq; | ||
87 | int number; | ||
88 | u8 toggle_edge_mode; | ||
89 | }; | ||
90 | |||
91 | /* | 86 | /* |
92 | * Macro to expand to read a specific register found in the "gpio" | 87 | * Macro to expand to read a specific register found in the "gpio" |
93 | * struct. It requires the struct u300_gpio *gpio variable to exist in | 88 | * struct. It requires the struct u300_gpio *gpio variable to exist in |
@@ -308,39 +303,6 @@ static int u300_gpio_direction_output(struct gpio_chip *chip, unsigned offset, | |||
308 | return 0; | 303 | return 0; |
309 | } | 304 | } |
310 | 305 | ||
311 | static int u300_gpio_to_irq(struct gpio_chip *chip, unsigned offset) | ||
312 | { | ||
313 | struct u300_gpio *gpio = to_u300_gpio(chip); | ||
314 | int portno = offset >> 3; | ||
315 | struct u300_gpio_port *port = NULL; | ||
316 | struct list_head *p; | ||
317 | int retirq; | ||
318 | bool found = false; | ||
319 | |||
320 | list_for_each(p, &gpio->port_list) { | ||
321 | port = list_entry(p, struct u300_gpio_port, node); | ||
322 | if (port->number == portno) { | ||
323 | found = true; | ||
324 | break; | ||
325 | } | ||
326 | } | ||
327 | if (!found) { | ||
328 | dev_err(gpio->dev, "could not locate port for GPIO %d IRQ\n", | ||
329 | offset); | ||
330 | return -EINVAL; | ||
331 | } | ||
332 | |||
333 | /* | ||
334 | * The local hwirqs on the port are the lower three bits, there | ||
335 | * are exactly 8 IRQs per port since they are 8-bit | ||
336 | */ | ||
337 | retirq = irq_find_mapping(port->domain, (offset & 0x7)); | ||
338 | |||
339 | dev_dbg(gpio->dev, "request IRQ for GPIO %d, return %d from port %d\n", | ||
340 | offset, retirq, port->number); | ||
341 | return retirq; | ||
342 | } | ||
343 | |||
344 | /* Returning -EINVAL means "supported but not available" */ | 306 | /* Returning -EINVAL means "supported but not available" */ |
345 | int u300_gpio_config_get(struct gpio_chip *chip, | 307 | int u300_gpio_config_get(struct gpio_chip *chip, |
346 | unsigned offset, | 308 | unsigned offset, |
@@ -461,7 +423,6 @@ static struct gpio_chip u300_gpio_chip = { | |||
461 | .set = u300_gpio_set, | 423 | .set = u300_gpio_set, |
462 | .direction_input = u300_gpio_direction_input, | 424 | .direction_input = u300_gpio_direction_input, |
463 | .direction_output = u300_gpio_direction_output, | 425 | .direction_output = u300_gpio_direction_output, |
464 | .to_irq = u300_gpio_to_irq, | ||
465 | }; | 426 | }; |
466 | 427 | ||
467 | static void u300_toggle_trigger(struct u300_gpio *gpio, unsigned offset) | 428 | static void u300_toggle_trigger(struct u300_gpio *gpio, unsigned offset) |
@@ -485,9 +446,10 @@ static void u300_toggle_trigger(struct u300_gpio *gpio, unsigned offset) | |||
485 | 446 | ||
486 | static int u300_gpio_irq_type(struct irq_data *d, unsigned trigger) | 447 | static int u300_gpio_irq_type(struct irq_data *d, unsigned trigger) |
487 | { | 448 | { |
488 | struct u300_gpio_port *port = irq_data_get_irq_chip_data(d); | 449 | struct gpio_chip *chip = irq_data_get_irq_chip_data(d); |
489 | struct u300_gpio *gpio = port->gpio; | 450 | struct u300_gpio *gpio = to_u300_gpio(chip); |
490 | int offset = (port->number << 3) + d->hwirq; | 451 | struct u300_gpio_port *port = &gpio->ports[d->hwirq >> 3]; |
452 | int offset = d->hwirq; | ||
491 | u32 val; | 453 | u32 val; |
492 | 454 | ||
493 | if ((trigger & IRQF_TRIGGER_RISING) && | 455 | if ((trigger & IRQF_TRIGGER_RISING) && |
@@ -521,9 +483,10 @@ static int u300_gpio_irq_type(struct irq_data *d, unsigned trigger) | |||
521 | 483 | ||
522 | static void u300_gpio_irq_enable(struct irq_data *d) | 484 | static void u300_gpio_irq_enable(struct irq_data *d) |
523 | { | 485 | { |
524 | struct u300_gpio_port *port = irq_data_get_irq_chip_data(d); | 486 | struct gpio_chip *chip = irq_data_get_irq_chip_data(d); |
525 | struct u300_gpio *gpio = port->gpio; | 487 | struct u300_gpio *gpio = to_u300_gpio(chip); |
526 | int offset = (port->number << 3) + d->hwirq; | 488 | struct u300_gpio_port *port = &gpio->ports[d->hwirq >> 3]; |
489 | int offset = d->hwirq; | ||
527 | u32 val; | 490 | u32 val; |
528 | unsigned long flags; | 491 | unsigned long flags; |
529 | 492 | ||
@@ -537,9 +500,9 @@ static void u300_gpio_irq_enable(struct irq_data *d) | |||
537 | 500 | ||
538 | static void u300_gpio_irq_disable(struct irq_data *d) | 501 | static void u300_gpio_irq_disable(struct irq_data *d) |
539 | { | 502 | { |
540 | struct u300_gpio_port *port = irq_data_get_irq_chip_data(d); | 503 | struct gpio_chip *chip = irq_data_get_irq_chip_data(d); |
541 | struct u300_gpio *gpio = port->gpio; | 504 | struct u300_gpio *gpio = to_u300_gpio(chip); |
542 | int offset = (port->number << 3) + d->hwirq; | 505 | int offset = d->hwirq; |
543 | u32 val; | 506 | u32 val; |
544 | unsigned long flags; | 507 | unsigned long flags; |
545 | 508 | ||
@@ -549,45 +512,24 @@ static void u300_gpio_irq_disable(struct irq_data *d) | |||
549 | local_irq_restore(flags); | 512 | local_irq_restore(flags); |
550 | } | 513 | } |
551 | 514 | ||
552 | static int u300_gpio_irq_reqres(struct irq_data *d) | ||
553 | { | ||
554 | struct u300_gpio_port *port = irq_data_get_irq_chip_data(d); | ||
555 | struct u300_gpio *gpio = port->gpio; | ||
556 | |||
557 | if (gpio_lock_as_irq(&gpio->chip, d->hwirq)) { | ||
558 | dev_err(gpio->dev, | ||
559 | "unable to lock HW IRQ %lu for IRQ\n", | ||
560 | d->hwirq); | ||
561 | return -EINVAL; | ||
562 | } | ||
563 | return 0; | ||
564 | } | ||
565 | |||
566 | static void u300_gpio_irq_relres(struct irq_data *d) | ||
567 | { | ||
568 | struct u300_gpio_port *port = irq_data_get_irq_chip_data(d); | ||
569 | struct u300_gpio *gpio = port->gpio; | ||
570 | |||
571 | gpio_unlock_as_irq(&gpio->chip, d->hwirq); | ||
572 | } | ||
573 | |||
574 | static struct irq_chip u300_gpio_irqchip = { | 515 | static struct irq_chip u300_gpio_irqchip = { |
575 | .name = "u300-gpio-irqchip", | 516 | .name = "u300-gpio-irqchip", |
576 | .irq_enable = u300_gpio_irq_enable, | 517 | .irq_enable = u300_gpio_irq_enable, |
577 | .irq_disable = u300_gpio_irq_disable, | 518 | .irq_disable = u300_gpio_irq_disable, |
578 | .irq_set_type = u300_gpio_irq_type, | 519 | .irq_set_type = u300_gpio_irq_type, |
579 | .irq_request_resources = u300_gpio_irq_reqres, | ||
580 | .irq_release_resources = u300_gpio_irq_relres, | ||
581 | }; | 520 | }; |
582 | 521 | ||
583 | static void u300_gpio_irq_handler(unsigned irq, struct irq_desc *desc) | 522 | static void u300_gpio_irq_handler(unsigned irq, struct irq_desc *desc) |
584 | { | 523 | { |
585 | struct u300_gpio_port *port = irq_get_handler_data(irq); | 524 | struct irq_chip *parent_chip = irq_get_chip(irq); |
586 | struct u300_gpio *gpio = port->gpio; | 525 | struct gpio_chip *chip = irq_get_handler_data(irq); |
526 | struct u300_gpio *gpio = to_u300_gpio(chip); | ||
527 | struct u300_gpio_port *port = &gpio->ports[irq - chip->base]; | ||
587 | int pinoffset = port->number << 3; /* get the right stride */ | 528 | int pinoffset = port->number << 3; /* get the right stride */ |
588 | unsigned long val; | 529 | unsigned long val; |
589 | 530 | ||
590 | desc->irq_data.chip->irq_ack(&desc->irq_data); | 531 | chained_irq_enter(parent_chip, desc); |
532 | |||
591 | /* Read event register */ | 533 | /* Read event register */ |
592 | val = readl(U300_PIN_REG(pinoffset, iev)); | 534 | val = readl(U300_PIN_REG(pinoffset, iev)); |
593 | /* Mask relevant bits */ | 535 | /* Mask relevant bits */ |
@@ -600,8 +542,8 @@ static void u300_gpio_irq_handler(unsigned irq, struct irq_desc *desc) | |||
600 | int irqoffset; | 542 | int irqoffset; |
601 | 543 | ||
602 | for_each_set_bit(irqoffset, &val, U300_GPIO_PINS_PER_PORT) { | 544 | for_each_set_bit(irqoffset, &val, U300_GPIO_PINS_PER_PORT) { |
603 | int pin_irq = irq_find_mapping(port->domain, irqoffset); | ||
604 | int offset = pinoffset + irqoffset; | 545 | int offset = pinoffset + irqoffset; |
546 | int pin_irq = irq_find_mapping(chip->irqdomain, offset); | ||
605 | 547 | ||
606 | dev_dbg(gpio->dev, "GPIO IRQ %d on pin %d\n", | 548 | dev_dbg(gpio->dev, "GPIO IRQ %d on pin %d\n", |
607 | pin_irq, offset); | 549 | pin_irq, offset); |
@@ -615,7 +557,7 @@ static void u300_gpio_irq_handler(unsigned irq, struct irq_desc *desc) | |||
615 | } | 557 | } |
616 | } | 558 | } |
617 | 559 | ||
618 | desc->irq_data.chip->irq_unmask(&desc->irq_data); | 560 | chained_irq_exit(parent_chip, desc); |
619 | } | 561 | } |
620 | 562 | ||
621 | static void __init u300_gpio_init_pin(struct u300_gpio *gpio, | 563 | static void __init u300_gpio_init_pin(struct u300_gpio *gpio, |
@@ -666,20 +608,6 @@ static void __init u300_gpio_init_coh901571(struct u300_gpio *gpio) | |||
666 | } | 608 | } |
667 | } | 609 | } |
668 | 610 | ||
669 | static inline void u300_gpio_free_ports(struct u300_gpio *gpio) | ||
670 | { | ||
671 | struct u300_gpio_port *port; | ||
672 | struct list_head *p, *n; | ||
673 | |||
674 | list_for_each_safe(p, n, &gpio->port_list) { | ||
675 | port = list_entry(p, struct u300_gpio_port, node); | ||
676 | list_del(&port->node); | ||
677 | if (port->domain) | ||
678 | irq_domain_remove(port->domain); | ||
679 | kfree(port); | ||
680 | } | ||
681 | } | ||
682 | |||
683 | /* | 611 | /* |
684 | * Here we map a GPIO in the local gpio_chip pin space to a pin in | 612 | * Here we map a GPIO in the local gpio_chip pin space to a pin in |
685 | * the local pinctrl pin space. The pin controller used is | 613 | * the local pinctrl pin space. The pin controller used is |
@@ -770,17 +698,28 @@ static int __init u300_gpio_probe(struct platform_device *pdev) | |||
770 | gpio->base + U300_GPIO_CR); | 698 | gpio->base + U300_GPIO_CR); |
771 | u300_gpio_init_coh901571(gpio); | 699 | u300_gpio_init_coh901571(gpio); |
772 | 700 | ||
701 | #ifdef CONFIG_OF_GPIO | ||
702 | gpio->chip.of_node = pdev->dev.of_node; | ||
703 | #endif | ||
704 | err = gpiochip_add(&gpio->chip); | ||
705 | if (err) { | ||
706 | dev_err(gpio->dev, "unable to add gpiochip: %d\n", err); | ||
707 | goto err_no_chip; | ||
708 | } | ||
709 | |||
710 | err = gpiochip_irqchip_add(&gpio->chip, | ||
711 | &u300_gpio_irqchip, | ||
712 | 0, | ||
713 | handle_simple_irq, | ||
714 | IRQ_TYPE_EDGE_FALLING); | ||
715 | if (err) { | ||
716 | dev_err(gpio->dev, "no GPIO irqchip\n"); | ||
717 | goto err_no_irqchip; | ||
718 | } | ||
719 | |||
773 | /* Add each port with its IRQ separately */ | 720 | /* Add each port with its IRQ separately */ |
774 | INIT_LIST_HEAD(&gpio->port_list); | ||
775 | for (portno = 0 ; portno < U300_GPIO_NUM_PORTS; portno++) { | 721 | for (portno = 0 ; portno < U300_GPIO_NUM_PORTS; portno++) { |
776 | struct u300_gpio_port *port = | 722 | struct u300_gpio_port *port = &gpio->ports[portno]; |
777 | kmalloc(sizeof(struct u300_gpio_port), GFP_KERNEL); | ||
778 | |||
779 | if (!port) { | ||
780 | dev_err(gpio->dev, "out of memory\n"); | ||
781 | err = -ENOMEM; | ||
782 | goto err_no_port; | ||
783 | } | ||
784 | 723 | ||
785 | snprintf(port->name, 8, "gpio%d", portno); | 724 | snprintf(port->name, 8, "gpio%d", portno); |
786 | port->number = portno; | 725 | port->number = portno; |
@@ -788,50 +727,16 @@ static int __init u300_gpio_probe(struct platform_device *pdev) | |||
788 | 727 | ||
789 | port->irq = platform_get_irq(pdev, portno); | 728 | port->irq = platform_get_irq(pdev, portno); |
790 | 729 | ||
791 | dev_dbg(gpio->dev, "register IRQ %d for port %s\n", port->irq, | 730 | gpiochip_set_chained_irqchip(&gpio->chip, |
792 | port->name); | 731 | &u300_gpio_irqchip, |
793 | 732 | port->irq, | |
794 | port->domain = irq_domain_add_linear(pdev->dev.of_node, | 733 | u300_gpio_irq_handler); |
795 | U300_GPIO_PINS_PER_PORT, | ||
796 | &irq_domain_simple_ops, | ||
797 | port); | ||
798 | if (!port->domain) { | ||
799 | err = -ENOMEM; | ||
800 | goto err_no_domain; | ||
801 | } | ||
802 | |||
803 | irq_set_chained_handler(port->irq, u300_gpio_irq_handler); | ||
804 | irq_set_handler_data(port->irq, port); | ||
805 | |||
806 | /* For each GPIO pin set the unique IRQ handler */ | ||
807 | for (i = 0; i < U300_GPIO_PINS_PER_PORT; i++) { | ||
808 | int irqno = irq_create_mapping(port->domain, i); | ||
809 | |||
810 | dev_dbg(gpio->dev, "GPIO%d on port %s gets IRQ %d\n", | ||
811 | gpio->chip.base + (port->number << 3) + i, | ||
812 | port->name, irqno); | ||
813 | irq_set_chip_and_handler(irqno, &u300_gpio_irqchip, | ||
814 | handle_simple_irq); | ||
815 | set_irq_flags(irqno, IRQF_VALID); | ||
816 | irq_set_chip_data(irqno, port); | ||
817 | } | ||
818 | 734 | ||
819 | /* Turns off irq force (test register) for this port */ | 735 | /* Turns off irq force (test register) for this port */ |
820 | writel(0x0, gpio->base + portno * gpio->stride + ifr); | 736 | writel(0x0, gpio->base + portno * gpio->stride + ifr); |
821 | |||
822 | list_add_tail(&port->node, &gpio->port_list); | ||
823 | } | 737 | } |
824 | dev_dbg(gpio->dev, "initialized %d GPIO ports\n", portno); | 738 | dev_dbg(gpio->dev, "initialized %d GPIO ports\n", portno); |
825 | 739 | ||
826 | #ifdef CONFIG_OF_GPIO | ||
827 | gpio->chip.of_node = pdev->dev.of_node; | ||
828 | #endif | ||
829 | err = gpiochip_add(&gpio->chip); | ||
830 | if (err) { | ||
831 | dev_err(gpio->dev, "unable to add gpiochip: %d\n", err); | ||
832 | goto err_no_chip; | ||
833 | } | ||
834 | |||
835 | /* | 740 | /* |
836 | * Add pinctrl pin ranges, the pin controller must be registered | 741 | * Add pinctrl pin ranges, the pin controller must be registered |
837 | * at this point | 742 | * at this point |
@@ -850,12 +755,10 @@ static int __init u300_gpio_probe(struct platform_device *pdev) | |||
850 | return 0; | 755 | return 0; |
851 | 756 | ||
852 | err_no_range: | 757 | err_no_range: |
758 | err_no_irqchip: | ||
853 | if (gpiochip_remove(&gpio->chip)) | 759 | if (gpiochip_remove(&gpio->chip)) |
854 | dev_err(&pdev->dev, "failed to remove gpio chip\n"); | 760 | dev_err(&pdev->dev, "failed to remove gpio chip\n"); |
855 | err_no_chip: | 761 | err_no_chip: |
856 | err_no_domain: | ||
857 | err_no_port: | ||
858 | u300_gpio_free_ports(gpio); | ||
859 | clk_disable_unprepare(gpio->clk); | 762 | clk_disable_unprepare(gpio->clk); |
860 | dev_err(&pdev->dev, "module ERROR:%d\n", err); | 763 | dev_err(&pdev->dev, "module ERROR:%d\n", err); |
861 | return err; | 764 | return err; |
@@ -874,7 +777,6 @@ static int __exit u300_gpio_remove(struct platform_device *pdev) | |||
874 | dev_err(gpio->dev, "unable to remove gpiochip: %d\n", err); | 777 | dev_err(gpio->dev, "unable to remove gpiochip: %d\n", err); |
875 | return err; | 778 | return err; |
876 | } | 779 | } |
877 | u300_gpio_free_ports(gpio); | ||
878 | clk_disable_unprepare(gpio->clk); | 780 | clk_disable_unprepare(gpio->clk); |
879 | return 0; | 781 | return 0; |
880 | } | 782 | } |