SAN People | 73a59c1 | 2006-01-09 17:05:41 +0000 | [diff] [blame] | 1 | /* |
Andrew Victor | 9d04126 | 2007-02-05 11:42:07 +0100 | [diff] [blame] | 2 | * linux/arch/arm/mach-at91/gpio.c |
SAN People | 73a59c1 | 2006-01-09 17:05:41 +0000 | [diff] [blame] | 3 | * |
| 4 | * Copyright (C) 2005 HP Labs |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; either version 2 of the License, or |
| 9 | * (at your option) any later version. |
| 10 | */ |
| 11 | |
Andrew Victor | f217383 | 2006-09-27 13:23:00 +0100 | [diff] [blame] | 12 | #include <linux/clk.h> |
SAN People | 73a59c1 | 2006-01-09 17:05:41 +0000 | [diff] [blame] | 13 | #include <linux/errno.h> |
Thomas Gleixner | 07d265d | 2006-07-01 23:01:50 +0100 | [diff] [blame] | 14 | #include <linux/interrupt.h> |
| 15 | #include <linux/irq.h> |
Andrew Victor | b66545e | 2007-11-23 16:09:10 +0100 | [diff] [blame] | 16 | #include <linux/debugfs.h> |
| 17 | #include <linux/seq_file.h> |
SAN People | 73a59c1 | 2006-01-09 17:05:41 +0000 | [diff] [blame] | 18 | #include <linux/kernel.h> |
| 19 | #include <linux/list.h> |
| 20 | #include <linux/module.h> |
| 21 | |
| 22 | #include <asm/io.h> |
Russell King | ea75ee9 | 2006-06-20 19:53:16 +0100 | [diff] [blame] | 23 | #include <asm/hardware.h> |
Andrew Victor | 55d8bae | 2006-11-30 17:16:43 +0100 | [diff] [blame] | 24 | #include <asm/arch/at91_pio.h> |
SAN People | 73a59c1 | 2006-01-09 17:05:41 +0000 | [diff] [blame] | 25 | #include <asm/arch/gpio.h> |
| 26 | |
Andrew Victor | f217383 | 2006-09-27 13:23:00 +0100 | [diff] [blame] | 27 | #include "generic.h" |
| 28 | |
| 29 | |
| 30 | static struct at91_gpio_bank *gpio; |
| 31 | static int gpio_banks; |
| 32 | |
SAN People | 73a59c1 | 2006-01-09 17:05:41 +0000 | [diff] [blame] | 33 | |
| 34 | static inline void __iomem *pin_to_controller(unsigned pin) |
| 35 | { |
| 36 | void __iomem *sys_base = (void __iomem *) AT91_VA_BASE_SYS; |
| 37 | |
| 38 | pin -= PIN_BASE; |
| 39 | pin /= 32; |
Andrew Victor | f217383 | 2006-09-27 13:23:00 +0100 | [diff] [blame] | 40 | if (likely(pin < gpio_banks)) |
| 41 | return sys_base + gpio[pin].offset; |
SAN People | 73a59c1 | 2006-01-09 17:05:41 +0000 | [diff] [blame] | 42 | |
| 43 | return NULL; |
| 44 | } |
| 45 | |
| 46 | static inline unsigned pin_to_mask(unsigned pin) |
| 47 | { |
| 48 | pin -= PIN_BASE; |
| 49 | return 1 << (pin % 32); |
| 50 | } |
| 51 | |
| 52 | |
| 53 | /*--------------------------------------------------------------------------*/ |
| 54 | |
| 55 | /* Not all hardware capabilities are exposed through these calls; they |
| 56 | * only encapsulate the most common features and modes. (So if you |
| 57 | * want to change signals in groups, do it directly.) |
| 58 | * |
| 59 | * Bootloaders will usually handle some of the pin multiplexing setup. |
| 60 | * The intent is certainly that by the time Linux is fully booted, all |
| 61 | * pins should have been fully initialized. These setup calls should |
| 62 | * only be used by board setup routines, or possibly in driver probe(). |
| 63 | * |
| 64 | * For bootloaders doing all that setup, these calls could be inlined |
| 65 | * as NOPs so Linux won't duplicate any setup code |
| 66 | */ |
| 67 | |
| 68 | |
| 69 | /* |
David Brownell | a31c4ee | 2007-02-12 00:53:13 -0800 | [diff] [blame] | 70 | * mux the pin to the "GPIO" peripheral role. |
| 71 | */ |
| 72 | int __init_or_module at91_set_GPIO_periph(unsigned pin, int use_pullup) |
| 73 | { |
| 74 | void __iomem *pio = pin_to_controller(pin); |
| 75 | unsigned mask = pin_to_mask(pin); |
| 76 | |
| 77 | if (!pio) |
| 78 | return -EINVAL; |
| 79 | __raw_writel(mask, pio + PIO_IDR); |
| 80 | __raw_writel(mask, pio + (use_pullup ? PIO_PUER : PIO_PUDR)); |
| 81 | __raw_writel(mask, pio + PIO_PER); |
| 82 | return 0; |
| 83 | } |
| 84 | EXPORT_SYMBOL(at91_set_GPIO_periph); |
| 85 | |
| 86 | |
| 87 | /* |
SAN People | 73a59c1 | 2006-01-09 17:05:41 +0000 | [diff] [blame] | 88 | * mux the pin to the "A" internal peripheral role. |
| 89 | */ |
| 90 | int __init_or_module at91_set_A_periph(unsigned pin, int use_pullup) |
| 91 | { |
| 92 | void __iomem *pio = pin_to_controller(pin); |
| 93 | unsigned mask = pin_to_mask(pin); |
| 94 | |
| 95 | if (!pio) |
| 96 | return -EINVAL; |
| 97 | |
| 98 | __raw_writel(mask, pio + PIO_IDR); |
| 99 | __raw_writel(mask, pio + (use_pullup ? PIO_PUER : PIO_PUDR)); |
| 100 | __raw_writel(mask, pio + PIO_ASR); |
| 101 | __raw_writel(mask, pio + PIO_PDR); |
| 102 | return 0; |
| 103 | } |
| 104 | EXPORT_SYMBOL(at91_set_A_periph); |
| 105 | |
| 106 | |
| 107 | /* |
| 108 | * mux the pin to the "B" internal peripheral role. |
| 109 | */ |
| 110 | int __init_or_module at91_set_B_periph(unsigned pin, int use_pullup) |
| 111 | { |
| 112 | void __iomem *pio = pin_to_controller(pin); |
| 113 | unsigned mask = pin_to_mask(pin); |
| 114 | |
| 115 | if (!pio) |
| 116 | return -EINVAL; |
| 117 | |
| 118 | __raw_writel(mask, pio + PIO_IDR); |
| 119 | __raw_writel(mask, pio + (use_pullup ? PIO_PUER : PIO_PUDR)); |
| 120 | __raw_writel(mask, pio + PIO_BSR); |
| 121 | __raw_writel(mask, pio + PIO_PDR); |
| 122 | return 0; |
| 123 | } |
| 124 | EXPORT_SYMBOL(at91_set_B_periph); |
| 125 | |
| 126 | |
| 127 | /* |
| 128 | * mux the pin to the gpio controller (instead of "A" or "B" peripheral), and |
| 129 | * configure it for an input. |
| 130 | */ |
| 131 | int __init_or_module at91_set_gpio_input(unsigned pin, int use_pullup) |
| 132 | { |
| 133 | void __iomem *pio = pin_to_controller(pin); |
| 134 | unsigned mask = pin_to_mask(pin); |
| 135 | |
| 136 | if (!pio) |
| 137 | return -EINVAL; |
| 138 | |
| 139 | __raw_writel(mask, pio + PIO_IDR); |
| 140 | __raw_writel(mask, pio + (use_pullup ? PIO_PUER : PIO_PUDR)); |
| 141 | __raw_writel(mask, pio + PIO_ODR); |
| 142 | __raw_writel(mask, pio + PIO_PER); |
| 143 | return 0; |
| 144 | } |
| 145 | EXPORT_SYMBOL(at91_set_gpio_input); |
| 146 | |
| 147 | |
| 148 | /* |
| 149 | * mux the pin to the gpio controller (instead of "A" or "B" peripheral), |
| 150 | * and configure it for an output. |
| 151 | */ |
| 152 | int __init_or_module at91_set_gpio_output(unsigned pin, int value) |
| 153 | { |
| 154 | void __iomem *pio = pin_to_controller(pin); |
| 155 | unsigned mask = pin_to_mask(pin); |
| 156 | |
| 157 | if (!pio) |
| 158 | return -EINVAL; |
| 159 | |
| 160 | __raw_writel(mask, pio + PIO_IDR); |
| 161 | __raw_writel(mask, pio + PIO_PUDR); |
| 162 | __raw_writel(mask, pio + (value ? PIO_SODR : PIO_CODR)); |
| 163 | __raw_writel(mask, pio + PIO_OER); |
| 164 | __raw_writel(mask, pio + PIO_PER); |
| 165 | return 0; |
| 166 | } |
| 167 | EXPORT_SYMBOL(at91_set_gpio_output); |
| 168 | |
| 169 | |
| 170 | /* |
| 171 | * enable/disable the glitch filter; mostly used with IRQ handling. |
| 172 | */ |
| 173 | int __init_or_module at91_set_deglitch(unsigned pin, int is_on) |
| 174 | { |
| 175 | void __iomem *pio = pin_to_controller(pin); |
| 176 | unsigned mask = pin_to_mask(pin); |
| 177 | |
| 178 | if (!pio) |
| 179 | return -EINVAL; |
| 180 | __raw_writel(mask, pio + (is_on ? PIO_IFER : PIO_IFDR)); |
| 181 | return 0; |
| 182 | } |
| 183 | EXPORT_SYMBOL(at91_set_deglitch); |
| 184 | |
Andrew Victor | df666b9 | 2006-02-22 21:23:35 +0000 | [diff] [blame] | 185 | /* |
| 186 | * enable/disable the multi-driver; This is only valid for output and |
| 187 | * allows the output pin to run as an open collector output. |
| 188 | */ |
| 189 | int __init_or_module at91_set_multi_drive(unsigned pin, int is_on) |
| 190 | { |
| 191 | void __iomem *pio = pin_to_controller(pin); |
| 192 | unsigned mask = pin_to_mask(pin); |
| 193 | |
| 194 | if (!pio) |
| 195 | return -EINVAL; |
| 196 | |
| 197 | __raw_writel(mask, pio + (is_on ? PIO_MDER : PIO_MDDR)); |
| 198 | return 0; |
| 199 | } |
| 200 | EXPORT_SYMBOL(at91_set_multi_drive); |
| 201 | |
SAN People | 73a59c1 | 2006-01-09 17:05:41 +0000 | [diff] [blame] | 202 | /*--------------------------------------------------------------------------*/ |
| 203 | |
David Brownell | a31c4ee | 2007-02-12 00:53:13 -0800 | [diff] [blame] | 204 | /* new-style GPIO calls; these expect at91_set_GPIO_periph to have been |
| 205 | * called, and maybe at91_set_multi_drive() for putout pins. |
| 206 | */ |
| 207 | |
| 208 | int gpio_direction_input(unsigned pin) |
| 209 | { |
| 210 | void __iomem *pio = pin_to_controller(pin); |
| 211 | unsigned mask = pin_to_mask(pin); |
| 212 | |
| 213 | if (!pio || !(__raw_readl(pio + PIO_PSR) & mask)) |
| 214 | return -EINVAL; |
Andrew Victor | 0ebffe3 | 2007-02-22 09:38:52 +0100 | [diff] [blame] | 215 | __raw_writel(mask, pio + PIO_ODR); |
David Brownell | a31c4ee | 2007-02-12 00:53:13 -0800 | [diff] [blame] | 216 | return 0; |
| 217 | } |
| 218 | EXPORT_SYMBOL(gpio_direction_input); |
| 219 | |
David Brownell | 28735a7 | 2007-03-16 13:38:14 -0800 | [diff] [blame] | 220 | int gpio_direction_output(unsigned pin, int value) |
David Brownell | a31c4ee | 2007-02-12 00:53:13 -0800 | [diff] [blame] | 221 | { |
| 222 | void __iomem *pio = pin_to_controller(pin); |
| 223 | unsigned mask = pin_to_mask(pin); |
| 224 | |
| 225 | if (!pio || !(__raw_readl(pio + PIO_PSR) & mask)) |
| 226 | return -EINVAL; |
David Brownell | 28735a7 | 2007-03-16 13:38:14 -0800 | [diff] [blame] | 227 | __raw_writel(mask, pio + (value ? PIO_SODR : PIO_CODR)); |
David Brownell | a31c4ee | 2007-02-12 00:53:13 -0800 | [diff] [blame] | 228 | __raw_writel(mask, pio + PIO_OER); |
| 229 | return 0; |
| 230 | } |
| 231 | EXPORT_SYMBOL(gpio_direction_output); |
| 232 | |
| 233 | /*--------------------------------------------------------------------------*/ |
| 234 | |
SAN People | 73a59c1 | 2006-01-09 17:05:41 +0000 | [diff] [blame] | 235 | /* |
| 236 | * assuming the pin is muxed as a gpio output, set its value. |
| 237 | */ |
| 238 | int at91_set_gpio_value(unsigned pin, int value) |
| 239 | { |
| 240 | void __iomem *pio = pin_to_controller(pin); |
| 241 | unsigned mask = pin_to_mask(pin); |
| 242 | |
| 243 | if (!pio) |
| 244 | return -EINVAL; |
| 245 | __raw_writel(mask, pio + (value ? PIO_SODR : PIO_CODR)); |
| 246 | return 0; |
| 247 | } |
| 248 | EXPORT_SYMBOL(at91_set_gpio_value); |
| 249 | |
| 250 | |
| 251 | /* |
| 252 | * read the pin's value (works even if it's not muxed as a gpio). |
| 253 | */ |
| 254 | int at91_get_gpio_value(unsigned pin) |
| 255 | { |
| 256 | void __iomem *pio = pin_to_controller(pin); |
| 257 | unsigned mask = pin_to_mask(pin); |
| 258 | u32 pdsr; |
| 259 | |
| 260 | if (!pio) |
| 261 | return -EINVAL; |
| 262 | pdsr = __raw_readl(pio + PIO_PDSR); |
| 263 | return (pdsr & mask) != 0; |
| 264 | } |
| 265 | EXPORT_SYMBOL(at91_get_gpio_value); |
| 266 | |
| 267 | /*--------------------------------------------------------------------------*/ |
| 268 | |
Andrew Victor | 814138f | 2006-06-19 15:26:54 +0100 | [diff] [blame] | 269 | #ifdef CONFIG_PM |
| 270 | |
Andrew Victor | f217383 | 2006-09-27 13:23:00 +0100 | [diff] [blame] | 271 | static u32 wakeups[MAX_GPIO_BANKS]; |
| 272 | static u32 backups[MAX_GPIO_BANKS]; |
Andrew Victor | 814138f | 2006-06-19 15:26:54 +0100 | [diff] [blame] | 273 | |
| 274 | static int gpio_irq_set_wake(unsigned pin, unsigned state) |
| 275 | { |
| 276 | unsigned mask = pin_to_mask(pin); |
Andrew Victor | 3ea163e | 2007-01-09 13:47:29 +0100 | [diff] [blame] | 277 | unsigned bank = (pin - PIN_BASE) / 32; |
Andrew Victor | 814138f | 2006-06-19 15:26:54 +0100 | [diff] [blame] | 278 | |
Andrew Victor | 3ea163e | 2007-01-09 13:47:29 +0100 | [diff] [blame] | 279 | if (unlikely(bank >= MAX_GPIO_BANKS)) |
Andrew Victor | 814138f | 2006-06-19 15:26:54 +0100 | [diff] [blame] | 280 | return -EINVAL; |
| 281 | |
| 282 | if (state) |
Andrew Victor | 3ea163e | 2007-01-09 13:47:29 +0100 | [diff] [blame] | 283 | wakeups[bank] |= mask; |
Andrew Victor | 814138f | 2006-06-19 15:26:54 +0100 | [diff] [blame] | 284 | else |
Andrew Victor | 3ea163e | 2007-01-09 13:47:29 +0100 | [diff] [blame] | 285 | wakeups[bank] &= ~mask; |
| 286 | |
| 287 | set_irq_wake(gpio[bank].id, state); |
Andrew Victor | 814138f | 2006-06-19 15:26:54 +0100 | [diff] [blame] | 288 | |
| 289 | return 0; |
| 290 | } |
| 291 | |
| 292 | void at91_gpio_suspend(void) |
| 293 | { |
| 294 | int i; |
| 295 | |
Andrew Victor | f217383 | 2006-09-27 13:23:00 +0100 | [diff] [blame] | 296 | for (i = 0; i < gpio_banks; i++) { |
| 297 | u32 pio = gpio[i].offset; |
Andrew Victor | 814138f | 2006-06-19 15:26:54 +0100 | [diff] [blame] | 298 | |
Andrew Victor | 814138f | 2006-06-19 15:26:54 +0100 | [diff] [blame] | 299 | backups[i] = at91_sys_read(pio + PIO_IMR); |
Andrew Victor | f217383 | 2006-09-27 13:23:00 +0100 | [diff] [blame] | 300 | at91_sys_write(pio + PIO_IDR, backups[i]); |
| 301 | at91_sys_write(pio + PIO_IER, wakeups[i]); |
Andrew Victor | 814138f | 2006-06-19 15:26:54 +0100 | [diff] [blame] | 302 | |
Andrew Victor | 3ea163e | 2007-01-09 13:47:29 +0100 | [diff] [blame] | 303 | if (!wakeups[i]) |
| 304 | clk_disable(gpio[i].clock); |
| 305 | else { |
Andrew Victor | 814138f | 2006-06-19 15:26:54 +0100 | [diff] [blame] | 306 | #ifdef CONFIG_PM_DEBUG |
Andrew Victor | 3ea163e | 2007-01-09 13:47:29 +0100 | [diff] [blame] | 307 | printk(KERN_DEBUG "GPIO-%c may wake for %08x\n", 'A'+i, wakeups[i]); |
Andrew Victor | 814138f | 2006-06-19 15:26:54 +0100 | [diff] [blame] | 308 | #endif |
| 309 | } |
| 310 | } |
| 311 | } |
| 312 | |
| 313 | void at91_gpio_resume(void) |
| 314 | { |
| 315 | int i; |
| 316 | |
Andrew Victor | f217383 | 2006-09-27 13:23:00 +0100 | [diff] [blame] | 317 | for (i = 0; i < gpio_banks; i++) { |
| 318 | u32 pio = gpio[i].offset; |
Andrew Victor | 814138f | 2006-06-19 15:26:54 +0100 | [diff] [blame] | 319 | |
Andrew Victor | 3ea163e | 2007-01-09 13:47:29 +0100 | [diff] [blame] | 320 | if (!wakeups[i]) |
| 321 | clk_enable(gpio[i].clock); |
| 322 | |
Andrew Victor | f217383 | 2006-09-27 13:23:00 +0100 | [diff] [blame] | 323 | at91_sys_write(pio + PIO_IDR, wakeups[i]); |
| 324 | at91_sys_write(pio + PIO_IER, backups[i]); |
Andrew Victor | f217383 | 2006-09-27 13:23:00 +0100 | [diff] [blame] | 325 | } |
Andrew Victor | 814138f | 2006-06-19 15:26:54 +0100 | [diff] [blame] | 326 | } |
| 327 | |
| 328 | #else |
| 329 | #define gpio_irq_set_wake NULL |
| 330 | #endif |
| 331 | |
SAN People | 73a59c1 | 2006-01-09 17:05:41 +0000 | [diff] [blame] | 332 | |
| 333 | /* Several AIC controller irqs are dispatched through this GPIO handler. |
| 334 | * To use any AT91_PIN_* as an externally triggered IRQ, first call |
| 335 | * at91_set_gpio_input() then maybe enable its glitch filter. |
| 336 | * Then just request_irq() with the pin ID; it works like any ARM IRQ |
| 337 | * handler, though it always triggers on rising and falling edges. |
| 338 | * |
| 339 | * Alternatively, certain pins may be used directly as IRQ0..IRQ6 after |
| 340 | * configuring them with at91_set_a_periph() or at91_set_b_periph(). |
| 341 | * IRQ0..IRQ6 should be configurable, e.g. level vs edge triggering. |
| 342 | */ |
| 343 | |
| 344 | static void gpio_irq_mask(unsigned pin) |
| 345 | { |
| 346 | void __iomem *pio = pin_to_controller(pin); |
| 347 | unsigned mask = pin_to_mask(pin); |
| 348 | |
| 349 | if (pio) |
| 350 | __raw_writel(mask, pio + PIO_IDR); |
| 351 | } |
| 352 | |
| 353 | static void gpio_irq_unmask(unsigned pin) |
| 354 | { |
| 355 | void __iomem *pio = pin_to_controller(pin); |
| 356 | unsigned mask = pin_to_mask(pin); |
| 357 | |
| 358 | if (pio) |
| 359 | __raw_writel(mask, pio + PIO_IER); |
| 360 | } |
| 361 | |
| 362 | static int gpio_irq_type(unsigned pin, unsigned type) |
| 363 | { |
| 364 | return (type == IRQT_BOTHEDGE) ? 0 : -EINVAL; |
| 365 | } |
| 366 | |
David Brownell | 38c677c | 2006-08-01 22:26:25 +0100 | [diff] [blame] | 367 | static struct irq_chip gpio_irqchip = { |
| 368 | .name = "GPIO", |
SAN People | 73a59c1 | 2006-01-09 17:05:41 +0000 | [diff] [blame] | 369 | .mask = gpio_irq_mask, |
| 370 | .unmask = gpio_irq_unmask, |
| 371 | .set_type = gpio_irq_type, |
Andrew Victor | 814138f | 2006-06-19 15:26:54 +0100 | [diff] [blame] | 372 | .set_wake = gpio_irq_set_wake, |
SAN People | 73a59c1 | 2006-01-09 17:05:41 +0000 | [diff] [blame] | 373 | }; |
| 374 | |
Russell King | 10dd5ce | 2006-11-23 11:41:32 +0000 | [diff] [blame] | 375 | static void gpio_irq_handler(unsigned irq, struct irq_desc *desc) |
SAN People | 73a59c1 | 2006-01-09 17:05:41 +0000 | [diff] [blame] | 376 | { |
| 377 | unsigned pin; |
Russell King | 10dd5ce | 2006-11-23 11:41:32 +0000 | [diff] [blame] | 378 | struct irq_desc *gpio; |
SAN People | 73a59c1 | 2006-01-09 17:05:41 +0000 | [diff] [blame] | 379 | void __iomem *pio; |
| 380 | u32 isr; |
| 381 | |
Thomas Gleixner | 07d265d | 2006-07-01 23:01:50 +0100 | [diff] [blame] | 382 | pio = get_irq_chip_data(irq); |
SAN People | 73a59c1 | 2006-01-09 17:05:41 +0000 | [diff] [blame] | 383 | |
| 384 | /* temporarily mask (level sensitive) parent IRQ */ |
| 385 | desc->chip->ack(irq); |
| 386 | for (;;) { |
Andrew Victor | 814138f | 2006-06-19 15:26:54 +0100 | [diff] [blame] | 387 | /* reading ISR acks the pending (edge triggered) GPIO interrupt */ |
SAN People | 73a59c1 | 2006-01-09 17:05:41 +0000 | [diff] [blame] | 388 | isr = __raw_readl(pio + PIO_ISR) & __raw_readl(pio + PIO_IMR); |
| 389 | if (!isr) |
| 390 | break; |
| 391 | |
Thomas Gleixner | 07d265d | 2006-07-01 23:01:50 +0100 | [diff] [blame] | 392 | pin = (unsigned) get_irq_data(irq); |
SAN People | 73a59c1 | 2006-01-09 17:05:41 +0000 | [diff] [blame] | 393 | gpio = &irq_desc[pin]; |
| 394 | |
| 395 | while (isr) { |
Andrew Victor | abbea71 | 2006-02-24 22:27:50 +0000 | [diff] [blame] | 396 | if (isr & 1) { |
Thomas Gleixner | 07d265d | 2006-07-01 23:01:50 +0100 | [diff] [blame] | 397 | if (unlikely(gpio->depth)) { |
Andrew Victor | abbea71 | 2006-02-24 22:27:50 +0000 | [diff] [blame] | 398 | /* |
| 399 | * The core ARM interrupt handler lazily disables IRQs so |
| 400 | * another IRQ must be generated before it actually gets |
| 401 | * here to be disabled on the GPIO controller. |
| 402 | */ |
| 403 | gpio_irq_mask(pin); |
| 404 | } |
| 405 | else |
Linus Torvalds | 0cd61b6 | 2006-10-06 10:53:39 -0700 | [diff] [blame] | 406 | desc_handle_irq(pin, gpio); |
Andrew Victor | abbea71 | 2006-02-24 22:27:50 +0000 | [diff] [blame] | 407 | } |
SAN People | 73a59c1 | 2006-01-09 17:05:41 +0000 | [diff] [blame] | 408 | pin++; |
| 409 | gpio++; |
| 410 | isr >>= 1; |
| 411 | } |
| 412 | } |
| 413 | desc->chip->unmask(irq); |
| 414 | /* now it may re-trigger */ |
| 415 | } |
| 416 | |
Andrew Victor | f217383 | 2006-09-27 13:23:00 +0100 | [diff] [blame] | 417 | /*--------------------------------------------------------------------------*/ |
SAN People | 73a59c1 | 2006-01-09 17:05:41 +0000 | [diff] [blame] | 418 | |
Andrew Victor | b66545e | 2007-11-23 16:09:10 +0100 | [diff] [blame] | 419 | #ifdef CONFIG_DEBUG_FS |
| 420 | |
| 421 | static int at91_gpio_show(struct seq_file *s, void *unused) |
| 422 | { |
| 423 | int bank, j; |
| 424 | |
| 425 | /* print heading */ |
| 426 | seq_printf(s, "Pin\t"); |
| 427 | for (bank = 0; bank < gpio_banks; bank++) { |
| 428 | seq_printf(s, "PIO%c\t", 'A' + bank); |
| 429 | }; |
| 430 | seq_printf(s, "\n\n"); |
| 431 | |
| 432 | /* print pin status */ |
| 433 | for (j = 0; j < 32; j++) { |
| 434 | seq_printf(s, "%i:\t", j); |
| 435 | |
| 436 | for (bank = 0; bank < gpio_banks; bank++) { |
| 437 | unsigned pin = PIN_BASE + (32 * bank) + j; |
| 438 | void __iomem *pio = pin_to_controller(pin); |
| 439 | unsigned mask = pin_to_mask(pin); |
| 440 | |
| 441 | if (__raw_readl(pio + PIO_PSR) & mask) |
| 442 | seq_printf(s, "GPIO:%s", __raw_readl(pio + PIO_PDSR) & mask ? "1" : "0"); |
| 443 | else |
| 444 | seq_printf(s, "%s", __raw_readl(pio + PIO_ABSR) & mask ? "B" : "A"); |
| 445 | |
| 446 | seq_printf(s, "\t"); |
| 447 | } |
| 448 | |
| 449 | seq_printf(s, "\n"); |
| 450 | } |
| 451 | |
| 452 | return 0; |
| 453 | } |
| 454 | |
| 455 | static int at91_gpio_open(struct inode *inode, struct file *file) |
| 456 | { |
| 457 | return single_open(file, at91_gpio_show, NULL); |
| 458 | } |
| 459 | |
| 460 | static const struct file_operations at91_gpio_operations = { |
| 461 | .open = at91_gpio_open, |
| 462 | .read = seq_read, |
| 463 | .llseek = seq_lseek, |
| 464 | .release = single_release, |
| 465 | }; |
| 466 | |
| 467 | static int __init at91_gpio_debugfs_init(void) |
| 468 | { |
| 469 | /* /sys/kernel/debug/at91_gpio */ |
| 470 | (void) debugfs_create_file("at91_gpio", S_IFREG | S_IRUGO, NULL, NULL, &at91_gpio_operations); |
| 471 | return 0; |
| 472 | } |
| 473 | postcore_initcall(at91_gpio_debugfs_init); |
| 474 | |
| 475 | #endif |
| 476 | |
| 477 | /*--------------------------------------------------------------------------*/ |
| 478 | |
Andrew Victor | f217383 | 2006-09-27 13:23:00 +0100 | [diff] [blame] | 479 | /* |
| 480 | * Called from the processor-specific init to enable GPIO interrupt support. |
| 481 | */ |
| 482 | void __init at91_gpio_irq_setup(void) |
| 483 | { |
| 484 | unsigned pioc, pin; |
| 485 | |
| 486 | for (pioc = 0, pin = PIN_BASE; |
| 487 | pioc < gpio_banks; |
| 488 | pioc++) { |
SAN People | 73a59c1 | 2006-01-09 17:05:41 +0000 | [diff] [blame] | 489 | void __iomem *controller; |
Andrew Victor | f217383 | 2006-09-27 13:23:00 +0100 | [diff] [blame] | 490 | unsigned id = gpio[pioc].id; |
SAN People | 73a59c1 | 2006-01-09 17:05:41 +0000 | [diff] [blame] | 491 | unsigned i; |
| 492 | |
Andrew Victor | f217383 | 2006-09-27 13:23:00 +0100 | [diff] [blame] | 493 | clk_enable(gpio[pioc].clock); /* enable PIO controller's clock */ |
| 494 | |
| 495 | controller = (void __iomem *) AT91_VA_BASE_SYS + gpio[pioc].offset; |
SAN People | 73a59c1 | 2006-01-09 17:05:41 +0000 | [diff] [blame] | 496 | __raw_writel(~0, controller + PIO_IDR); |
| 497 | |
| 498 | set_irq_data(id, (void *) pin); |
Russell King | 10dd5ce | 2006-11-23 11:41:32 +0000 | [diff] [blame] | 499 | set_irq_chip_data(id, controller); |
SAN People | 73a59c1 | 2006-01-09 17:05:41 +0000 | [diff] [blame] | 500 | |
| 501 | for (i = 0; i < 32; i++, pin++) { |
Andrew Victor | 814138f | 2006-06-19 15:26:54 +0100 | [diff] [blame] | 502 | /* |
| 503 | * Can use the "simple" and not "edge" handler since it's |
Robert P. J. Day | 3a4fa0a | 2007-10-19 23:10:43 +0200 | [diff] [blame] | 504 | * shorter, and the AIC handles interrupts sanely. |
Andrew Victor | 814138f | 2006-06-19 15:26:54 +0100 | [diff] [blame] | 505 | */ |
SAN People | 73a59c1 | 2006-01-09 17:05:41 +0000 | [diff] [blame] | 506 | set_irq_chip(pin, &gpio_irqchip); |
Russell King | 10dd5ce | 2006-11-23 11:41:32 +0000 | [diff] [blame] | 507 | set_irq_handler(pin, handle_simple_irq); |
SAN People | 73a59c1 | 2006-01-09 17:05:41 +0000 | [diff] [blame] | 508 | set_irq_flags(pin, IRQF_VALID); |
| 509 | } |
| 510 | |
| 511 | set_irq_chained_handler(id, gpio_irq_handler); |
SAN People | 73a59c1 | 2006-01-09 17:05:41 +0000 | [diff] [blame] | 512 | } |
Andrew Victor | f217383 | 2006-09-27 13:23:00 +0100 | [diff] [blame] | 513 | pr_info("AT91: %d gpio irqs in %d banks\n", pin - PIN_BASE, gpio_banks); |
| 514 | } |
| 515 | |
| 516 | /* |
| 517 | * Called from the processor-specific init to enable GPIO pin support. |
| 518 | */ |
| 519 | void __init at91_gpio_init(struct at91_gpio_bank *data, int nr_banks) |
| 520 | { |
| 521 | BUG_ON(nr_banks > MAX_GPIO_BANKS); |
| 522 | |
| 523 | gpio = data; |
| 524 | gpio_banks = nr_banks; |
SAN People | 73a59c1 | 2006-01-09 17:05:41 +0000 | [diff] [blame] | 525 | } |