irq.c 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. /*
  2. * linux/arch/arm/mach-at91rm9200/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/config.h>
  23. #include <linux/init.h>
  24. #include <linux/module.h>
  25. #include <linux/mm.h>
  26. #include <linux/types.h>
  27. #include <asm/hardware.h>
  28. #include <asm/irq.h>
  29. #include <asm/mach-types.h>
  30. #include <asm/setup.h>
  31. #include <asm/mach/arch.h>
  32. #include <asm/mach/irq.h>
  33. #include <asm/mach/map.h>
  34. #include "generic.h"
  35. /*
  36. * The default interrupt priority levels (0 = lowest, 7 = highest).
  37. */
  38. static unsigned int at91rm9200_default_irq_priority[NR_AIC_IRQS] __initdata = {
  39. 7, /* Advanced Interrupt Controller */
  40. 7, /* System Peripheral */
  41. 0, /* Parallel IO Controller A */
  42. 0, /* Parallel IO Controller B */
  43. 0, /* Parallel IO Controller C */
  44. 0, /* Parallel IO Controller D */
  45. 6, /* USART 0 */
  46. 6, /* USART 1 */
  47. 6, /* USART 2 */
  48. 6, /* USART 3 */
  49. 0, /* Multimedia Card Interface */
  50. 4, /* USB Device Port */
  51. 0, /* Two-Wire Interface */
  52. 6, /* Serial Peripheral Interface */
  53. 5, /* Serial Synchronous Controller */
  54. 5, /* Serial Synchronous Controller */
  55. 5, /* Serial Synchronous Controller */
  56. 0, /* Timer Counter 0 */
  57. 0, /* Timer Counter 1 */
  58. 0, /* Timer Counter 2 */
  59. 0, /* Timer Counter 3 */
  60. 0, /* Timer Counter 4 */
  61. 0, /* Timer Counter 5 */
  62. 3, /* USB Host port */
  63. 3, /* Ethernet MAC */
  64. 0, /* Advanced Interrupt Controller */
  65. 0, /* Advanced Interrupt Controller */
  66. 0, /* Advanced Interrupt Controller */
  67. 0, /* Advanced Interrupt Controller */
  68. 0, /* Advanced Interrupt Controller */
  69. 0, /* Advanced Interrupt Controller */
  70. 0 /* Advanced Interrupt Controller */
  71. };
  72. static void at91rm9200_mask_irq(unsigned int irq)
  73. {
  74. /* Disable interrupt on AIC */
  75. at91_sys_write(AT91_AIC_IDCR, 1 << irq);
  76. }
  77. static void at91rm9200_unmask_irq(unsigned int irq)
  78. {
  79. /* Enable interrupt on AIC */
  80. at91_sys_write(AT91_AIC_IECR, 1 << irq);
  81. }
  82. static int at91rm9200_irq_type(unsigned irq, unsigned type)
  83. {
  84. unsigned int smr, srctype;
  85. switch (type) {
  86. case IRQT_HIGH:
  87. srctype = AT91_AIC_SRCTYPE_HIGH;
  88. break;
  89. case IRQT_RISING:
  90. srctype = AT91_AIC_SRCTYPE_RISING;
  91. break;
  92. case IRQT_LOW:
  93. if ((irq > AT91_ID_FIQ) && (irq < AT91_ID_IRQ0)) /* only supported on external interrupts */
  94. return -EINVAL;
  95. srctype = AT91_AIC_SRCTYPE_LOW;
  96. break;
  97. case IRQT_FALLING:
  98. if ((irq > AT91_ID_FIQ) && (irq < AT91_ID_IRQ0)) /* only supported on external interrupts */
  99. return -EINVAL;
  100. srctype = AT91_AIC_SRCTYPE_FALLING;
  101. break;
  102. default:
  103. return -EINVAL;
  104. }
  105. smr = at91_sys_read(AT91_AIC_SMR(irq)) & ~AT91_AIC_SRCTYPE;
  106. at91_sys_write(AT91_AIC_SMR(irq), smr | srctype);
  107. return 0;
  108. }
  109. #ifdef CONFIG_PM
  110. static u32 wakeups;
  111. static u32 backups;
  112. static int at91rm9200_irq_set_wake(unsigned irq, unsigned value)
  113. {
  114. if (unlikely(irq >= 32))
  115. return -EINVAL;
  116. if (value)
  117. wakeups |= (1 << irq);
  118. else
  119. wakeups &= ~(1 << irq);
  120. return 0;
  121. }
  122. void at91_irq_suspend(void)
  123. {
  124. backups = at91_sys_read(AT91_AIC_IMR);
  125. at91_sys_write(AT91_AIC_IDCR, backups);
  126. at91_sys_write(AT91_AIC_IECR, wakeups);
  127. }
  128. void at91_irq_resume(void)
  129. {
  130. at91_sys_write(AT91_AIC_IDCR, wakeups);
  131. at91_sys_write(AT91_AIC_IECR, backups);
  132. }
  133. #else
  134. #define at91rm9200_irq_set_wake NULL
  135. #endif
  136. static struct irqchip at91rm9200_irq_chip = {
  137. .ack = at91rm9200_mask_irq,
  138. .mask = at91rm9200_mask_irq,
  139. .unmask = at91rm9200_unmask_irq,
  140. .set_type = at91rm9200_irq_type,
  141. .set_wake = at91rm9200_irq_set_wake,
  142. };
  143. /*
  144. * Initialize the AIC interrupt controller.
  145. */
  146. void __init at91rm9200_init_irq(unsigned int priority[NR_AIC_IRQS])
  147. {
  148. unsigned int i;
  149. /* No priority list specified for this board -> use defaults */
  150. if (priority == NULL)
  151. priority = at91rm9200_default_irq_priority;
  152. /*
  153. * The IVR is used by macro get_irqnr_and_base to read and verify.
  154. * The irq number is NR_AIC_IRQS when a spurious interrupt has occurred.
  155. */
  156. for (i = 0; i < NR_AIC_IRQS; i++) {
  157. /* Put irq number in Source Vector Register: */
  158. at91_sys_write(AT91_AIC_SVR(i), i);
  159. /* Store the Source Mode Register as defined in table above */
  160. at91_sys_write(AT91_AIC_SMR(i), AT91_AIC_SRCTYPE_LOW | priority[i]);
  161. set_irq_chip(i, &at91rm9200_irq_chip);
  162. set_irq_handler(i, do_level_IRQ);
  163. set_irq_flags(i, IRQF_VALID | IRQF_PROBE);
  164. /* Perform 8 End Of Interrupt Command to make sure AIC will not Lock out nIRQ */
  165. if (i < 8)
  166. at91_sys_write(AT91_AIC_EOICR, 0);
  167. }
  168. /*
  169. * Spurious Interrupt ID in Spurious Vector Register is NR_AIC_IRQS
  170. * When there is no current interrupt, the IRQ Vector Register reads the value stored in AIC_SPU
  171. */
  172. at91_sys_write(AT91_AIC_SPU, NR_AIC_IRQS);
  173. /* No debugging in AIC: Debug (Protect) Control Register */
  174. at91_sys_write(AT91_AIC_DCR, 0);
  175. /* Disable and clear all interrupts initially */
  176. at91_sys_write(AT91_AIC_IDCR, 0xFFFFFFFF);
  177. at91_sys_write(AT91_AIC_ICCR, 0xFFFFFFFF);
  178. }