Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

arm: at91: at91sam9x5: fix gpio number per bank

On the at91sam9x5 SoC series, GPIO banks B and D only have 19 and 22
pins. So add a property to set this parameter.

Acked-by: Nicolas Ferre <nicolas.ferre@atmel.com>
Acked-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

+29 -11
+5
Documentation/devicetree/bindings/gpio/gpio_atmel.txt
··· 9 9 unused). 10 10 - gpio-controller: Marks the device node as a GPIO controller. 11 11 12 + optional properties: 13 + - #gpio-lines: Number of gpio if absent 32. 14 + 15 + 12 16 Example: 13 17 pioA: gpio@fffff200 { 14 18 compatible = "atmel,at91rm9200-gpio"; ··· 20 16 interrupts = <2 4>; 21 17 #gpio-cells = <2>; 22 18 gpio-controller; 19 + #gpio-lines = <19>; 23 20 }; 24 21
+2
arch/arm/boot/dts/at91sam9x5.dtsi
··· 133 133 interrupts = <2 4 1>; 134 134 #gpio-cells = <2>; 135 135 gpio-controller; 136 + #gpio-lines = <19>; 136 137 interrupt-controller; 137 138 #interrupt-cells = <2>; 138 139 }; ··· 154 153 interrupts = <3 4 1>; 155 154 #gpio-cells = <2>; 156 155 gpio-controller; 156 + #gpio-lines = <22>; 157 157 interrupt-controller; 158 158 #interrupt-cells = <2>; 159 159 };
+22 -11
arch/arm/mach-at91/gpio.c
··· 33 33 34 34 #include "generic.h" 35 35 36 + #define MAX_NB_GPIO_PER_BANK 32 37 + 36 38 struct at91_gpio_chip { 37 39 struct gpio_chip chip; 38 40 struct at91_gpio_chip *next; /* Bank sharing same clock */ ··· 58 56 unsigned offset); 59 57 static int at91_gpiolib_to_irq(struct gpio_chip *chip, unsigned offset); 60 58 61 - #define AT91_GPIO_CHIP(name, nr_gpio) \ 59 + #define AT91_GPIO_CHIP(name) \ 62 60 { \ 63 61 .chip = { \ 64 62 .label = name, \ ··· 69 67 .set = at91_gpiolib_set, \ 70 68 .dbg_show = at91_gpiolib_dbg_show, \ 71 69 .to_irq = at91_gpiolib_to_irq, \ 72 - .ngpio = nr_gpio, \ 70 + .ngpio = MAX_NB_GPIO_PER_BANK, \ 73 71 }, \ 74 72 } 75 73 76 74 static struct at91_gpio_chip gpio_chip[] = { 77 - AT91_GPIO_CHIP("pioA", 32), 78 - AT91_GPIO_CHIP("pioB", 32), 79 - AT91_GPIO_CHIP("pioC", 32), 80 - AT91_GPIO_CHIP("pioD", 32), 81 - AT91_GPIO_CHIP("pioE", 32), 75 + AT91_GPIO_CHIP("pioA"), 76 + AT91_GPIO_CHIP("pioB"), 77 + AT91_GPIO_CHIP("pioC"), 78 + AT91_GPIO_CHIP("pioD"), 79 + AT91_GPIO_CHIP("pioE"), 82 80 }; 83 81 84 82 static int gpio_banks; ··· 93 91 94 92 static inline void __iomem *pin_to_controller(unsigned pin) 95 93 { 96 - pin /= 32; 94 + pin /= MAX_NB_GPIO_PER_BANK; 97 95 if (likely(pin < gpio_banks)) 98 96 return gpio_chip[pin].regbase; 99 97 ··· 102 100 103 101 static inline unsigned pin_to_mask(unsigned pin) 104 102 { 105 - return 1 << (pin % 32); 103 + return 1 << (pin % MAX_NB_GPIO_PER_BANK); 106 104 } 107 105 108 106 ··· 994 992 { 995 993 int alias_idx; 996 994 struct at91_gpio_chip *at91_gpio; 995 + uint32_t ngpio; 997 996 998 997 if (!np) 999 998 return; ··· 1007 1004 } 1008 1005 1009 1006 at91_gpio = &gpio_chip[alias_idx]; 1010 - at91_gpio->chip.base = alias_idx * at91_gpio->chip.ngpio; 1007 + at91_gpio->chip.base = alias_idx * MAX_NB_GPIO_PER_BANK; 1011 1008 1012 1009 at91_gpio->regbase = of_iomap(np, 0); 1013 1010 if (!at91_gpio->regbase) { ··· 1026 1023 /* Get capabilities from compatibility property */ 1027 1024 if (of_device_is_compatible(np, "atmel,at91sam9x5-gpio")) 1028 1025 at91_gpio_caps |= AT91_GPIO_CAP_PIO3; 1026 + 1027 + if (!of_property_read_u32(np, "#gpio-lines", &ngpio)) { 1028 + if (ngpio >= MAX_NB_GPIO_PER_BANK) 1029 + pr_err("at91_gpio.%d, gpio-nb >= %d failback to %d\n", 1030 + alias_idx, MAX_NB_GPIO_PER_BANK, MAX_NB_GPIO_PER_BANK); 1031 + else 1032 + at91_gpio->chip.ngpio = ngpio; 1033 + } 1029 1034 1030 1035 /* Setup clock */ 1031 1036 if (at91_gpio_setup_clk(alias_idx)) ··· 1072 1061 { 1073 1062 struct at91_gpio_chip *at91_gpio = &gpio_chip[idx]; 1074 1063 1075 - at91_gpio->chip.base = idx * at91_gpio->chip.ngpio; 1064 + at91_gpio->chip.base = idx * MAX_NB_GPIO_PER_BANK; 1076 1065 at91_gpio->pioc_hwirq = pioc_hwirq; 1077 1066 at91_gpio->pioc_idx = idx; 1078 1067