irq.c 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  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. static void __init at91_aic_hw_init(unsigned int spu_vector)
  118. {
  119. int i;
  120. /*
  121. * Perform 8 End Of Interrupt Command to make sure AIC
  122. * will not Lock out nIRQ
  123. */
  124. for (i = 0; i < 8; i++)
  125. at91_aic_write(AT91_AIC_EOICR, 0);
  126. /*
  127. * Spurious Interrupt ID in Spurious Vector Register.
  128. * When there is no current interrupt, the IRQ Vector Register
  129. * reads the value stored in AIC_SPU
  130. */
  131. at91_aic_write(AT91_AIC_SPU, spu_vector);
  132. /* No debugging in AIC: Debug (Protect) Control Register */
  133. at91_aic_write(AT91_AIC_DCR, 0);
  134. /* Disable and clear all interrupts initially */
  135. at91_aic_write(AT91_AIC_IDCR, 0xFFFFFFFF);
  136. at91_aic_write(AT91_AIC_ICCR, 0xFFFFFFFF);
  137. }
  138. #if defined(CONFIG_OF)
  139. static int at91_aic_irq_map(struct irq_domain *h, unsigned int virq,
  140. irq_hw_number_t hw)
  141. {
  142. /* Put virq number in Source Vector Register */
  143. at91_aic_write(AT91_AIC_SVR(hw), virq);
  144. /* Active Low interrupt, without priority */
  145. at91_aic_write(AT91_AIC_SMR(hw), AT91_AIC_SRCTYPE_LOW);
  146. irq_set_chip_and_handler(virq, &at91_aic_chip, handle_level_irq);
  147. set_irq_flags(virq, IRQF_VALID | IRQF_PROBE);
  148. return 0;
  149. }
  150. static struct irq_domain_ops at91_aic_irq_ops = {
  151. .map = at91_aic_irq_map,
  152. .xlate = irq_domain_xlate_twocell,
  153. };
  154. int __init at91_aic_of_init(struct device_node *node,
  155. struct device_node *parent)
  156. {
  157. at91_aic_base = of_iomap(node, 0);
  158. at91_aic_np = node;
  159. at91_aic_domain = irq_domain_add_linear(at91_aic_np, NR_AIC_IRQS,
  160. &at91_aic_irq_ops, NULL);
  161. if (!at91_aic_domain)
  162. panic("Unable to add AIC irq domain (DT)\n");
  163. irq_set_default_host(at91_aic_domain);
  164. at91_aic_hw_init(NR_AIC_IRQS);
  165. return 0;
  166. }
  167. #endif
  168. /*
  169. * Initialize the AIC interrupt controller.
  170. */
  171. void __init at91_aic_init(unsigned int priority[NR_AIC_IRQS])
  172. {
  173. unsigned int i;
  174. int irq_base;
  175. at91_aic_base = ioremap(AT91_AIC, 512);
  176. if (!at91_aic_base)
  177. panic("Unable to ioremap AIC registers\n");
  178. /* Add irq domain for AIC */
  179. irq_base = irq_alloc_descs(-1, 0, NR_AIC_IRQS, 0);
  180. if (irq_base < 0) {
  181. WARN(1, "Cannot allocate irq_descs, assuming pre-allocated\n");
  182. irq_base = 0;
  183. }
  184. at91_aic_domain = irq_domain_add_legacy(at91_aic_np, NR_AIC_IRQS,
  185. irq_base, 0,
  186. &irq_domain_simple_ops, NULL);
  187. if (!at91_aic_domain)
  188. panic("Unable to add AIC irq domain\n");
  189. irq_set_default_host(at91_aic_domain);
  190. /*
  191. * The IVR is used by macro get_irqnr_and_base to read and verify.
  192. * The irq number is NR_AIC_IRQS when a spurious interrupt has occurred.
  193. */
  194. for (i = 0; i < NR_AIC_IRQS; i++) {
  195. /* Put hardware irq number in Source Vector Register: */
  196. at91_aic_write(AT91_AIC_SVR(i), i);
  197. /* Active Low interrupt, with the specified priority */
  198. at91_aic_write(AT91_AIC_SMR(i), AT91_AIC_SRCTYPE_LOW | priority[i]);
  199. irq_set_chip_and_handler(i, &at91_aic_chip, handle_level_irq);
  200. set_irq_flags(i, IRQF_VALID | IRQF_PROBE);
  201. }
  202. at91_aic_hw_init(NR_AIC_IRQS);
  203. }