diff options
Diffstat (limited to 'arch/arm/mach-at91/gpio.c')
-rw-r--r-- | arch/arm/mach-at91/gpio.c | 190 |
1 files changed, 29 insertions, 161 deletions
diff --git a/arch/arm/mach-at91/gpio.c b/arch/arm/mach-at91/gpio.c index be42cf0e74bd..c5d7e1e9d757 100644 --- a/arch/arm/mach-at91/gpio.c +++ b/arch/arm/mach-at91/gpio.c | |||
@@ -23,8 +23,6 @@ | |||
23 | #include <linux/io.h> | 23 | #include <linux/io.h> |
24 | #include <linux/irqdomain.h> | 24 | #include <linux/irqdomain.h> |
25 | #include <linux/of_address.h> | 25 | #include <linux/of_address.h> |
26 | #include <linux/of_irq.h> | ||
27 | #include <linux/of_gpio.h> | ||
28 | 26 | ||
29 | #include <asm/mach/irq.h> | 27 | #include <asm/mach/irq.h> |
30 | 28 | ||
@@ -33,6 +31,8 @@ | |||
33 | 31 | ||
34 | #include "generic.h" | 32 | #include "generic.h" |
35 | 33 | ||
34 | #define MAX_NB_GPIO_PER_BANK 32 | ||
35 | |||
36 | struct at91_gpio_chip { | 36 | struct at91_gpio_chip { |
37 | struct gpio_chip chip; | 37 | struct gpio_chip chip; |
38 | struct at91_gpio_chip *next; /* Bank sharing same clock */ | 38 | struct at91_gpio_chip *next; /* Bank sharing same clock */ |
@@ -46,6 +46,7 @@ struct at91_gpio_chip { | |||
46 | 46 | ||
47 | #define to_at91_gpio_chip(c) container_of(c, struct at91_gpio_chip, chip) | 47 | #define to_at91_gpio_chip(c) container_of(c, struct at91_gpio_chip, chip) |
48 | 48 | ||
49 | static int at91_gpiolib_request(struct gpio_chip *chip, unsigned offset); | ||
49 | static void at91_gpiolib_dbg_show(struct seq_file *s, struct gpio_chip *chip); | 50 | static void at91_gpiolib_dbg_show(struct seq_file *s, struct gpio_chip *chip); |
50 | static void at91_gpiolib_set(struct gpio_chip *chip, unsigned offset, int val); | 51 | static void at91_gpiolib_set(struct gpio_chip *chip, unsigned offset, int val); |
51 | static int at91_gpiolib_get(struct gpio_chip *chip, unsigned offset); | 52 | static int at91_gpiolib_get(struct gpio_chip *chip, unsigned offset); |
@@ -55,26 +56,27 @@ static int at91_gpiolib_direction_input(struct gpio_chip *chip, | |||
55 | unsigned offset); | 56 | unsigned offset); |
56 | static int at91_gpiolib_to_irq(struct gpio_chip *chip, unsigned offset); | 57 | static int at91_gpiolib_to_irq(struct gpio_chip *chip, unsigned offset); |
57 | 58 | ||
58 | #define AT91_GPIO_CHIP(name, nr_gpio) \ | 59 | #define AT91_GPIO_CHIP(name) \ |
59 | { \ | 60 | { \ |
60 | .chip = { \ | 61 | .chip = { \ |
61 | .label = name, \ | 62 | .label = name, \ |
63 | .request = at91_gpiolib_request, \ | ||
62 | .direction_input = at91_gpiolib_direction_input, \ | 64 | .direction_input = at91_gpiolib_direction_input, \ |
63 | .direction_output = at91_gpiolib_direction_output, \ | 65 | .direction_output = at91_gpiolib_direction_output, \ |
64 | .get = at91_gpiolib_get, \ | 66 | .get = at91_gpiolib_get, \ |
65 | .set = at91_gpiolib_set, \ | 67 | .set = at91_gpiolib_set, \ |
66 | .dbg_show = at91_gpiolib_dbg_show, \ | 68 | .dbg_show = at91_gpiolib_dbg_show, \ |
67 | .to_irq = at91_gpiolib_to_irq, \ | 69 | .to_irq = at91_gpiolib_to_irq, \ |
68 | .ngpio = nr_gpio, \ | 70 | .ngpio = MAX_NB_GPIO_PER_BANK, \ |
69 | }, \ | 71 | }, \ |
70 | } | 72 | } |
71 | 73 | ||
72 | static struct at91_gpio_chip gpio_chip[] = { | 74 | static struct at91_gpio_chip gpio_chip[] = { |
73 | AT91_GPIO_CHIP("pioA", 32), | 75 | AT91_GPIO_CHIP("pioA"), |
74 | AT91_GPIO_CHIP("pioB", 32), | 76 | AT91_GPIO_CHIP("pioB"), |
75 | AT91_GPIO_CHIP("pioC", 32), | 77 | AT91_GPIO_CHIP("pioC"), |
76 | AT91_GPIO_CHIP("pioD", 32), | 78 | AT91_GPIO_CHIP("pioD"), |
77 | AT91_GPIO_CHIP("pioE", 32), | 79 | AT91_GPIO_CHIP("pioE"), |
78 | }; | 80 | }; |
79 | 81 | ||
80 | static int gpio_banks; | 82 | static int gpio_banks; |
@@ -89,7 +91,7 @@ static unsigned long at91_gpio_caps; | |||
89 | 91 | ||
90 | static inline void __iomem *pin_to_controller(unsigned pin) | 92 | static inline void __iomem *pin_to_controller(unsigned pin) |
91 | { | 93 | { |
92 | pin /= 32; | 94 | pin /= MAX_NB_GPIO_PER_BANK; |
93 | if (likely(pin < gpio_banks)) | 95 | if (likely(pin < gpio_banks)) |
94 | return gpio_chip[pin].regbase; | 96 | return gpio_chip[pin].regbase; |
95 | 97 | ||
@@ -98,7 +100,7 @@ static inline void __iomem *pin_to_controller(unsigned pin) | |||
98 | 100 | ||
99 | static inline unsigned pin_to_mask(unsigned pin) | 101 | static inline unsigned pin_to_mask(unsigned pin) |
100 | { | 102 | { |
101 | return 1 << (pin % 32); | 103 | return 1 << (pin % MAX_NB_GPIO_PER_BANK); |
102 | } | 104 | } |
103 | 105 | ||
104 | 106 | ||
@@ -713,80 +715,6 @@ postcore_initcall(at91_gpio_debugfs_init); | |||
713 | */ | 715 | */ |
714 | static struct lock_class_key gpio_lock_class; | 716 | static struct lock_class_key gpio_lock_class; |
715 | 717 | ||
716 | #if defined(CONFIG_OF) | ||
717 | static int at91_gpio_irq_map(struct irq_domain *h, unsigned int virq, | ||
718 | irq_hw_number_t hw) | ||
719 | { | ||
720 | struct at91_gpio_chip *at91_gpio = h->host_data; | ||
721 | |||
722 | irq_set_lockdep_class(virq, &gpio_lock_class); | ||
723 | |||
724 | /* | ||
725 | * Can use the "simple" and not "edge" handler since it's | ||
726 | * shorter, and the AIC handles interrupts sanely. | ||
727 | */ | ||
728 | irq_set_chip_and_handler(virq, &gpio_irqchip, | ||
729 | handle_simple_irq); | ||
730 | set_irq_flags(virq, IRQF_VALID); | ||
731 | irq_set_chip_data(virq, at91_gpio); | ||
732 | |||
733 | return 0; | ||
734 | } | ||
735 | |||
736 | static struct irq_domain_ops at91_gpio_ops = { | ||
737 | .map = at91_gpio_irq_map, | ||
738 | .xlate = irq_domain_xlate_twocell, | ||
739 | }; | ||
740 | |||
741 | int __init at91_gpio_of_irq_setup(struct device_node *node, | ||
742 | struct device_node *parent) | ||
743 | { | ||
744 | struct at91_gpio_chip *prev = NULL; | ||
745 | int alias_idx = of_alias_get_id(node, "gpio"); | ||
746 | struct at91_gpio_chip *at91_gpio = &gpio_chip[alias_idx]; | ||
747 | |||
748 | /* Setup proper .irq_set_type function */ | ||
749 | if (has_pio3()) | ||
750 | gpio_irqchip.irq_set_type = alt_gpio_irq_type; | ||
751 | else | ||
752 | gpio_irqchip.irq_set_type = gpio_irq_type; | ||
753 | |||
754 | /* Disable irqs of this PIO controller */ | ||
755 | __raw_writel(~0, at91_gpio->regbase + PIO_IDR); | ||
756 | |||
757 | /* Setup irq domain */ | ||
758 | at91_gpio->domain = irq_domain_add_linear(node, at91_gpio->chip.ngpio, | ||
759 | &at91_gpio_ops, at91_gpio); | ||
760 | if (!at91_gpio->domain) | ||
761 | panic("at91_gpio.%d: couldn't allocate irq domain (DT).\n", | ||
762 | at91_gpio->pioc_idx); | ||
763 | |||
764 | /* Setup chained handler */ | ||
765 | if (at91_gpio->pioc_idx) | ||
766 | prev = &gpio_chip[at91_gpio->pioc_idx - 1]; | ||
767 | |||
768 | /* The toplevel handler handles one bank of GPIOs, except | ||
769 | * on some SoC it can handles up to three... | ||
770 | * We only set up the handler for the first of the list. | ||
771 | */ | ||
772 | if (prev && prev->next == at91_gpio) | ||
773 | return 0; | ||
774 | |||
775 | at91_gpio->pioc_virq = irq_create_mapping(irq_find_host(parent), | ||
776 | at91_gpio->pioc_hwirq); | ||
777 | irq_set_chip_data(at91_gpio->pioc_virq, at91_gpio); | ||
778 | irq_set_chained_handler(at91_gpio->pioc_virq, gpio_irq_handler); | ||
779 | |||
780 | return 0; | ||
781 | } | ||
782 | #else | ||
783 | int __init at91_gpio_of_irq_setup(struct device_node *node, | ||
784 | struct device_node *parent) | ||
785 | { | ||
786 | return -EINVAL; | ||
787 | } | ||
788 | #endif | ||
789 | |||
790 | /* | 718 | /* |
791 | * irqdomain initialization: pile up irqdomains on top of AIC range | 719 | * irqdomain initialization: pile up irqdomains on top of AIC range |
792 | */ | 720 | */ |
@@ -862,6 +790,16 @@ void __init at91_gpio_irq_setup(void) | |||
862 | } | 790 | } |
863 | 791 | ||
864 | /* gpiolib support */ | 792 | /* gpiolib support */ |
793 | static int at91_gpiolib_request(struct gpio_chip *chip, unsigned offset) | ||
794 | { | ||
795 | struct at91_gpio_chip *at91_gpio = to_at91_gpio_chip(chip); | ||
796 | void __iomem *pio = at91_gpio->regbase; | ||
797 | unsigned mask = 1 << offset; | ||
798 | |||
799 | __raw_writel(mask, pio + PIO_PER); | ||
800 | return 0; | ||
801 | } | ||
802 | |||
865 | static int at91_gpiolib_direction_input(struct gpio_chip *chip, | 803 | static int at91_gpiolib_direction_input(struct gpio_chip *chip, |
866 | unsigned offset) | 804 | unsigned offset) |
867 | { | 805 | { |
@@ -975,81 +913,11 @@ err: | |||
975 | return -EINVAL; | 913 | return -EINVAL; |
976 | } | 914 | } |
977 | 915 | ||
978 | #ifdef CONFIG_OF_GPIO | ||
979 | static void __init of_at91_gpio_init_one(struct device_node *np) | ||
980 | { | ||
981 | int alias_idx; | ||
982 | struct at91_gpio_chip *at91_gpio; | ||
983 | |||
984 | if (!np) | ||
985 | return; | ||
986 | |||
987 | alias_idx = of_alias_get_id(np, "gpio"); | ||
988 | if (alias_idx >= MAX_GPIO_BANKS) { | ||
989 | pr_err("at91_gpio, failed alias idx(%d) > MAX_GPIO_BANKS(%d), ignoring.\n", | ||
990 | alias_idx, MAX_GPIO_BANKS); | ||
991 | return; | ||
992 | } | ||
993 | |||
994 | at91_gpio = &gpio_chip[alias_idx]; | ||
995 | at91_gpio->chip.base = alias_idx * at91_gpio->chip.ngpio; | ||
996 | |||
997 | at91_gpio->regbase = of_iomap(np, 0); | ||
998 | if (!at91_gpio->regbase) { | ||
999 | pr_err("at91_gpio.%d, failed to map registers, ignoring.\n", | ||
1000 | alias_idx); | ||
1001 | return; | ||
1002 | } | ||
1003 | |||
1004 | /* Get the interrupts property */ | ||
1005 | if (of_property_read_u32(np, "interrupts", &at91_gpio->pioc_hwirq)) { | ||
1006 | pr_err("at91_gpio.%d, failed to get interrupts property, ignoring.\n", | ||
1007 | alias_idx); | ||
1008 | goto ioremap_err; | ||
1009 | } | ||
1010 | |||
1011 | /* Get capabilities from compatibility property */ | ||
1012 | if (of_device_is_compatible(np, "atmel,at91sam9x5-gpio")) | ||
1013 | at91_gpio_caps |= AT91_GPIO_CAP_PIO3; | ||
1014 | |||
1015 | /* Setup clock */ | ||
1016 | if (at91_gpio_setup_clk(alias_idx)) | ||
1017 | goto ioremap_err; | ||
1018 | |||
1019 | at91_gpio->chip.of_node = np; | ||
1020 | gpio_banks = max(gpio_banks, alias_idx + 1); | ||
1021 | at91_gpio->pioc_idx = alias_idx; | ||
1022 | return; | ||
1023 | |||
1024 | ioremap_err: | ||
1025 | iounmap(at91_gpio->regbase); | ||
1026 | } | ||
1027 | |||
1028 | static int __init of_at91_gpio_init(void) | ||
1029 | { | ||
1030 | struct device_node *np = NULL; | ||
1031 | |||
1032 | /* | ||
1033 | * This isn't ideal, but it gets things hooked up until this | ||
1034 | * driver is converted into a platform_device | ||
1035 | */ | ||
1036 | for_each_compatible_node(np, NULL, "atmel,at91rm9200-gpio") | ||
1037 | of_at91_gpio_init_one(np); | ||
1038 | |||
1039 | return gpio_banks > 0 ? 0 : -EINVAL; | ||
1040 | } | ||
1041 | #else | ||
1042 | static int __init of_at91_gpio_init(void) | ||
1043 | { | ||
1044 | return -EINVAL; | ||
1045 | } | ||
1046 | #endif | ||
1047 | |||
1048 | static void __init at91_gpio_init_one(int idx, u32 regbase, int pioc_hwirq) | 916 | static void __init at91_gpio_init_one(int idx, u32 regbase, int pioc_hwirq) |
1049 | { | 917 | { |
1050 | struct at91_gpio_chip *at91_gpio = &gpio_chip[idx]; | 918 | struct at91_gpio_chip *at91_gpio = &gpio_chip[idx]; |
1051 | 919 | ||
1052 | at91_gpio->chip.base = idx * at91_gpio->chip.ngpio; | 920 | at91_gpio->chip.base = idx * MAX_NB_GPIO_PER_BANK; |
1053 | at91_gpio->pioc_hwirq = pioc_hwirq; | 921 | at91_gpio->pioc_hwirq = pioc_hwirq; |
1054 | at91_gpio->pioc_idx = idx; | 922 | at91_gpio->pioc_idx = idx; |
1055 | 923 | ||
@@ -1079,11 +947,11 @@ void __init at91_gpio_init(struct at91_gpio_bank *data, int nr_banks) | |||
1079 | 947 | ||
1080 | BUG_ON(nr_banks > MAX_GPIO_BANKS); | 948 | BUG_ON(nr_banks > MAX_GPIO_BANKS); |
1081 | 949 | ||
1082 | if (of_at91_gpio_init() < 0) { | 950 | if (of_have_populated_dt()) |
1083 | /* No GPIO controller found in device tree */ | 951 | return; |
1084 | for (i = 0; i < nr_banks; i++) | 952 | |
1085 | at91_gpio_init_one(i, data[i].regbase, data[i].id); | 953 | for (i = 0; i < nr_banks; i++) |
1086 | } | 954 | at91_gpio_init_one(i, data[i].regbase, data[i].id); |
1087 | 955 | ||
1088 | for (i = 0; i < gpio_banks; i++) { | 956 | for (i = 0; i < gpio_banks; i++) { |
1089 | at91_gpio = &gpio_chip[i]; | 957 | at91_gpio = &gpio_chip[i]; |