irq.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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 <mach/hardware.h>
  27. #include <asm/irq.h>
  28. #include <asm/setup.h>
  29. #include <asm/mach/arch.h>
  30. #include <asm/mach/irq.h>
  31. #include <asm/mach/map.h>
  32. static void at91_aic_mask_irq(struct irq_data *d)
  33. {
  34. /* Disable interrupt on AIC */
  35. at91_sys_write(AT91_AIC_IDCR, 1 << d->irq);
  36. }
  37. static void at91_aic_unmask_irq(struct irq_data *d)
  38. {
  39. /* Enable interrupt on AIC */
  40. at91_sys_write(AT91_AIC_IECR, 1 << d->irq);
  41. }
  42. unsigned int at91_extern_irq;
  43. #define is_extern_irq(irq) ((1 << (irq)) & at91_extern_irq)
  44. static int at91_aic_set_type(struct irq_data *d, unsigned type)
  45. {
  46. unsigned int smr, srctype;
  47. switch (type) {
  48. case IRQ_TYPE_LEVEL_HIGH:
  49. srctype = AT91_AIC_SRCTYPE_HIGH;
  50. break;
  51. case IRQ_TYPE_EDGE_RISING:
  52. srctype = AT91_AIC_SRCTYPE_RISING;
  53. break;
  54. case IRQ_TYPE_LEVEL_LOW:
  55. if ((d->irq == AT91_ID_FIQ) || is_extern_irq(d->irq)) /* only supported on external interrupts */
  56. srctype = AT91_AIC_SRCTYPE_LOW;
  57. else
  58. return -EINVAL;
  59. break;
  60. case IRQ_TYPE_EDGE_FALLING:
  61. if ((d->irq == AT91_ID_FIQ) || is_extern_irq(d->irq)) /* only supported on external interrupts */
  62. srctype = AT91_AIC_SRCTYPE_FALLING;
  63. else
  64. return -EINVAL;
  65. break;
  66. default:
  67. return -EINVAL;
  68. }
  69. smr = at91_sys_read(AT91_AIC_SMR(d->irq)) & ~AT91_AIC_SRCTYPE;
  70. at91_sys_write(AT91_AIC_SMR(d->irq), smr | srctype);
  71. return 0;
  72. }
  73. #ifdef CONFIG_PM
  74. static u32 wakeups;
  75. static u32 backups;
  76. static int at91_aic_set_wake(struct irq_data *d, unsigned value)
  77. {
  78. if (unlikely(d->irq >= 32))
  79. return -EINVAL;
  80. if (value)
  81. wakeups |= (1 << d->irq);
  82. else
  83. wakeups &= ~(1 << d->irq);
  84. return 0;
  85. }
  86. void at91_irq_suspend(void)
  87. {
  88. backups = at91_sys_read(AT91_AIC_IMR);
  89. at91_sys_write(AT91_AIC_IDCR, backups);
  90. at91_sys_write(AT91_AIC_IECR, wakeups);
  91. }
  92. void at91_irq_resume(void)
  93. {
  94. at91_sys_write(AT91_AIC_IDCR, wakeups);
  95. at91_sys_write(AT91_AIC_IECR, backups);
  96. }
  97. #else
  98. #define at91_aic_set_wake NULL
  99. #endif
  100. static struct irq_chip at91_aic_chip = {
  101. .name = "AIC",
  102. .irq_ack = at91_aic_mask_irq,
  103. .irq_mask = at91_aic_mask_irq,
  104. .irq_unmask = at91_aic_unmask_irq,
  105. .irq_set_type = at91_aic_set_type,
  106. .irq_set_wake = at91_aic_set_wake,
  107. };
  108. /*
  109. * Initialize the AIC interrupt controller.
  110. */
  111. void __init at91_aic_init(unsigned int priority[NR_AIC_IRQS])
  112. {
  113. unsigned int i;
  114. /*
  115. * The IVR is used by macro get_irqnr_and_base to read and verify.
  116. * The irq number is NR_AIC_IRQS when a spurious interrupt has occurred.
  117. */
  118. for (i = 0; i < NR_AIC_IRQS; i++) {
  119. /* Put irq number in Source Vector Register: */
  120. at91_sys_write(AT91_AIC_SVR(i), i);
  121. /* Active Low interrupt, with the specified priority */
  122. at91_sys_write(AT91_AIC_SMR(i), AT91_AIC_SRCTYPE_LOW | priority[i]);
  123. irq_set_chip_and_handler(i, &at91_aic_chip, handle_level_irq);
  124. set_irq_flags(i, IRQF_VALID | IRQF_PROBE);
  125. /* Perform 8 End Of Interrupt Command to make sure AIC will not Lock out nIRQ */
  126. if (i < 8)
  127. at91_sys_write(AT91_AIC_EOICR, 0);
  128. }
  129. /*
  130. * Spurious Interrupt ID in Spurious Vector Register is NR_AIC_IRQS
  131. * When there is no current interrupt, the IRQ Vector Register reads the value stored in AIC_SPU
  132. */
  133. at91_sys_write(AT91_AIC_SPU, NR_AIC_IRQS);
  134. /* No debugging in AIC: Debug (Protect) Control Register */
  135. at91_sys_write(AT91_AIC_DCR, 0);
  136. /* Disable and clear all interrupts initially */
  137. at91_sys_write(AT91_AIC_IDCR, 0xFFFFFFFF);
  138. at91_sys_write(AT91_AIC_ICCR, 0xFFFFFFFF);
  139. }