irq.c 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. /*
  2. * linux/arch/arm/mach-at91/irq.c
  3. *
  4. * Copyright (C) 2004 SAN People
  5. * Copyright (C) 2004 ATMEL
  6. * Copyright (C) Rick Bronson
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  21. */
  22. #include <linux/init.h>
  23. #include <linux/module.h>
  24. #include <linux/mm.h>
  25. #include <linux/types.h>
  26. #include <linux/irq.h>
  27. #include <linux/of.h>
  28. #include <linux/of_address.h>
  29. #include <linux/of_irq.h>
  30. #include <linux/irqdomain.h>
  31. #include <linux/err.h>
  32. #include <mach/hardware.h>
  33. #include <asm/irq.h>
  34. #include <asm/setup.h>
  35. #include <asm/mach/arch.h>
  36. #include <asm/mach/irq.h>
  37. #include <asm/mach/map.h>
  38. void __iomem *at91_aic_base;
  39. static struct irq_domain *at91_aic_domain;
  40. static struct device_node *at91_aic_np;
  41. static void at91_aic_mask_irq(struct irq_data *d)
  42. {
  43. /* Disable interrupt on AIC */
  44. at91_aic_write(AT91_AIC_IDCR, 1 << d->hwirq);
  45. }
  46. static void at91_aic_unmask_irq(struct irq_data *d)
  47. {
  48. /* Enable interrupt on AIC */
  49. at91_aic_write(AT91_AIC_IECR, 1 << d->hwirq);
  50. }
  51. unsigned int at91_extern_irq;
  52. #define is_extern_irq(hwirq) ((1 << (hwirq)) & at91_extern_irq)
  53. static int at91_aic_set_type(struct irq_data *d, unsigned type)
  54. {
  55. unsigned int smr, srctype;
  56. switch (type) {
  57. case IRQ_TYPE_LEVEL_HIGH:
  58. srctype = AT91_AIC_SRCTYPE_HIGH;
  59. break;
  60. case IRQ_TYPE_EDGE_RISING:
  61. srctype = AT91_AIC_SRCTYPE_RISING;
  62. break;
  63. case IRQ_TYPE_LEVEL_LOW:
  64. if ((d->hwirq == AT91_ID_FIQ) || is_extern_irq(d->hwirq)) /* only supported on external interrupts */
  65. srctype = AT91_AIC_SRCTYPE_LOW;
  66. else
  67. return -EINVAL;
  68. break;
  69. case IRQ_TYPE_EDGE_FALLING:
  70. if ((d->hwirq == AT91_ID_FIQ) || is_extern_irq(d->hwirq)) /* only supported on external interrupts */
  71. srctype = AT91_AIC_SRCTYPE_FALLING;
  72. else
  73. return -EINVAL;
  74. break;
  75. default:
  76. return -EINVAL;
  77. }
  78. smr = at91_aic_read(AT91_AIC_SMR(d->hwirq)) & ~AT91_AIC_SRCTYPE;
  79. at91_aic_write(AT91_AIC_SMR(d->hwirq), smr | srctype);
  80. return 0;
  81. }
  82. #ifdef CONFIG_PM
  83. static u32 wakeups;
  84. static u32 backups;
  85. static int at91_aic_set_wake(struct irq_data *d, unsigned value)
  86. {
  87. if (unlikely(d->hwirq >= NR_AIC_IRQS))
  88. return -EINVAL;
  89. if (value)
  90. wakeups |= (1 << d->hwirq);
  91. else
  92. wakeups &= ~(1 << d->hwirq);
  93. return 0;
  94. }
  95. void at91_irq_suspend(void)
  96. {
  97. backups = at91_aic_read(AT91_AIC_IMR);
  98. at91_aic_write(AT91_AIC_IDCR, backups);
  99. at91_aic_write(AT91_AIC_IECR, wakeups);
  100. }
  101. void at91_irq_resume(void)
  102. {
  103. at91_aic_write(AT91_AIC_IDCR, wakeups);
  104. at91_aic_write(AT91_AIC_IECR, backups);
  105. }
  106. #else
  107. #define at91_aic_set_wake NULL
  108. #endif
  109. static struct irq_chip at91_aic_chip = {
  110. .name = "AIC",
  111. .irq_ack = at91_aic_mask_irq,
  112. .irq_mask = at91_aic_mask_irq,
  113. .irq_unmask = at91_aic_unmask_irq,
  114. .irq_set_type = at91_aic_set_type,
  115. .irq_set_wake = at91_aic_set_wake,
  116. };
  117. #if defined(CONFIG_OF)
  118. static int __init __at91_aic_of_init(struct device_node *node,
  119. struct device_node *parent)
  120. {
  121. at91_aic_base = of_iomap(node, 0);
  122. at91_aic_np = node;
  123. return 0;
  124. }
  125. static const struct of_device_id aic_ids[] __initconst = {
  126. { .compatible = "atmel,at91rm9200-aic", .data = __at91_aic_of_init },
  127. { /*sentinel*/ }
  128. };
  129. static void __init at91_aic_of_init(void)
  130. {
  131. of_irq_init(aic_ids);
  132. }
  133. #else
  134. static void __init at91_aic_of_init(void) {}
  135. #endif
  136. /*
  137. * Initialize the AIC interrupt controller.
  138. */
  139. void __init at91_aic_init(unsigned int priority[NR_AIC_IRQS])
  140. {
  141. unsigned int i;
  142. int irq_base;
  143. if (of_have_populated_dt())
  144. at91_aic_of_init();
  145. else
  146. at91_aic_base = ioremap(AT91_AIC, 512);
  147. if (!at91_aic_base)
  148. panic("Unable to ioremap AIC registers\n");
  149. /* Add irq domain for AIC */
  150. irq_base = irq_alloc_descs(-1, 0, NR_AIC_IRQS, 0);
  151. if (irq_base < 0) {
  152. WARN(1, "Cannot allocate irq_descs, assuming pre-allocated\n");
  153. irq_base = 0;
  154. }
  155. at91_aic_domain = irq_domain_add_legacy(at91_aic_np, NR_AIC_IRQS,
  156. irq_base, 0,
  157. &irq_domain_simple_ops, NULL);
  158. if (!at91_aic_domain)
  159. panic("Unable to add AIC irq domain\n");
  160. /*
  161. * The IVR is used by macro get_irqnr_and_base to read and verify.
  162. * The irq number is NR_AIC_IRQS when a spurious interrupt has occurred.
  163. */
  164. for (i = 0; i < NR_AIC_IRQS; i++) {
  165. /* Put hardware irq number in Source Vector Register: */
  166. at91_aic_write(AT91_AIC_SVR(i), i);
  167. /* Active Low interrupt, with the specified priority */
  168. at91_aic_write(AT91_AIC_SMR(i), AT91_AIC_SRCTYPE_LOW | priority[i]);
  169. irq_set_chip_and_handler(i, &at91_aic_chip, handle_level_irq);
  170. set_irq_flags(i, IRQF_VALID | IRQF_PROBE);
  171. /* Perform 8 End Of Interrupt Command to make sure AIC will not Lock out nIRQ */
  172. if (i < 8)
  173. at91_aic_write(AT91_AIC_EOICR, 0);
  174. }
  175. /*
  176. * Spurious Interrupt ID in Spurious Vector Register is NR_AIC_IRQS
  177. * When there is no current interrupt, the IRQ Vector Register reads the value stored in AIC_SPU
  178. */
  179. at91_aic_write(AT91_AIC_SPU, NR_AIC_IRQS);
  180. /* No debugging in AIC: Debug (Protect) Control Register */
  181. at91_aic_write(AT91_AIC_DCR, 0);
  182. /* Disable and clear all interrupts initially */
  183. at91_aic_write(AT91_AIC_IDCR, 0xFFFFFFFF);
  184. at91_aic_write(AT91_AIC_ICCR, 0xFFFFFFFF);
  185. }