irq.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. /*
  2. * Copyright (C) 2006,2007 Felix Fietkau <nbd@openwrt.org>
  3. * Copyright (C) 2006,2007 Eugene Konev <ejka@openwrt.org>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  18. */
  19. #include <linux/interrupt.h>
  20. #include <linux/io.h>
  21. #include <asm/irq_cpu.h>
  22. #include <asm/mipsregs.h>
  23. #include <asm/mach-ar7/ar7.h>
  24. #define EXCEPT_OFFSET 0x80
  25. #define PACE_OFFSET 0xA0
  26. #define CHNLS_OFFSET 0x200
  27. #define REG_OFFSET(irq, reg) ((irq) / 32 * 0x4 + reg * 0x10)
  28. #define SEC_REG_OFFSET(reg) (EXCEPT_OFFSET + reg * 0x8)
  29. #define SEC_SR_OFFSET (SEC_REG_OFFSET(0)) /* 0x80 */
  30. #define CR_OFFSET(irq) (REG_OFFSET(irq, 1)) /* 0x10 */
  31. #define SEC_CR_OFFSET (SEC_REG_OFFSET(1)) /* 0x88 */
  32. #define ESR_OFFSET(irq) (REG_OFFSET(irq, 2)) /* 0x20 */
  33. #define SEC_ESR_OFFSET (SEC_REG_OFFSET(2)) /* 0x90 */
  34. #define ECR_OFFSET(irq) (REG_OFFSET(irq, 3)) /* 0x30 */
  35. #define SEC_ECR_OFFSET (SEC_REG_OFFSET(3)) /* 0x98 */
  36. #define PIR_OFFSET (0x40)
  37. #define MSR_OFFSET (0x44)
  38. #define PM_OFFSET(irq) (REG_OFFSET(irq, 5)) /* 0x50 */
  39. #define TM_OFFSET(irq) (REG_OFFSET(irq, 6)) /* 0x60 */
  40. #define REG(addr) ((u32 *)(KSEG1ADDR(AR7_REGS_IRQ) + addr))
  41. #define CHNL_OFFSET(chnl) (CHNLS_OFFSET + (chnl * 4))
  42. static int ar7_irq_base;
  43. static void ar7_unmask_irq(unsigned int irq)
  44. {
  45. writel(1 << ((irq - ar7_irq_base) % 32),
  46. REG(ESR_OFFSET(irq - ar7_irq_base)));
  47. }
  48. static void ar7_mask_irq(unsigned int irq)
  49. {
  50. writel(1 << ((irq - ar7_irq_base) % 32),
  51. REG(ECR_OFFSET(irq - ar7_irq_base)));
  52. }
  53. static void ar7_ack_irq(unsigned int irq)
  54. {
  55. writel(1 << ((irq - ar7_irq_base) % 32),
  56. REG(CR_OFFSET(irq - ar7_irq_base)));
  57. }
  58. static void ar7_unmask_sec_irq(unsigned int irq)
  59. {
  60. writel(1 << (irq - ar7_irq_base - 40), REG(SEC_ESR_OFFSET));
  61. }
  62. static void ar7_mask_sec_irq(unsigned int irq)
  63. {
  64. writel(1 << (irq - ar7_irq_base - 40), REG(SEC_ECR_OFFSET));
  65. }
  66. static void ar7_ack_sec_irq(unsigned int irq)
  67. {
  68. writel(1 << (irq - ar7_irq_base - 40), REG(SEC_CR_OFFSET));
  69. }
  70. static struct irq_chip ar7_irq_type = {
  71. .name = "AR7",
  72. .unmask = ar7_unmask_irq,
  73. .mask = ar7_mask_irq,
  74. .ack = ar7_ack_irq
  75. };
  76. static struct irq_chip ar7_sec_irq_type = {
  77. .name = "AR7",
  78. .unmask = ar7_unmask_sec_irq,
  79. .mask = ar7_mask_sec_irq,
  80. .ack = ar7_ack_sec_irq,
  81. };
  82. static struct irqaction ar7_cascade_action = {
  83. .handler = no_action,
  84. .name = "AR7 cascade interrupt"
  85. };
  86. static void __init ar7_irq_init(int base)
  87. {
  88. int i;
  89. /*
  90. * Disable interrupts and clear pending
  91. */
  92. writel(0xffffffff, REG(ECR_OFFSET(0)));
  93. writel(0xff, REG(ECR_OFFSET(32)));
  94. writel(0xffffffff, REG(SEC_ECR_OFFSET));
  95. writel(0xffffffff, REG(CR_OFFSET(0)));
  96. writel(0xff, REG(CR_OFFSET(32)));
  97. writel(0xffffffff, REG(SEC_CR_OFFSET));
  98. ar7_irq_base = base;
  99. for (i = 0; i < 40; i++) {
  100. writel(i, REG(CHNL_OFFSET(i)));
  101. /* Primary IRQ's */
  102. set_irq_chip_and_handler(base + i, &ar7_irq_type,
  103. handle_level_irq);
  104. /* Secondary IRQ's */
  105. if (i < 32)
  106. set_irq_chip_and_handler(base + i + 40,
  107. &ar7_sec_irq_type,
  108. handle_level_irq);
  109. }
  110. setup_irq(2, &ar7_cascade_action);
  111. setup_irq(ar7_irq_base, &ar7_cascade_action);
  112. set_c0_status(IE_IRQ0);
  113. }
  114. void __init arch_init_irq(void)
  115. {
  116. mips_cpu_irq_init();
  117. ar7_irq_init(8);
  118. }
  119. static void ar7_cascade(void)
  120. {
  121. u32 status;
  122. int i, irq;
  123. /* Primary IRQ's */
  124. irq = readl(REG(PIR_OFFSET)) & 0x3f;
  125. if (irq) {
  126. do_IRQ(ar7_irq_base + irq);
  127. return;
  128. }
  129. /* Secondary IRQ's are cascaded through primary '0' */
  130. writel(1, REG(CR_OFFSET(irq)));
  131. status = readl(REG(SEC_SR_OFFSET));
  132. for (i = 0; i < 32; i++) {
  133. if (status & 1) {
  134. do_IRQ(ar7_irq_base + i + 40);
  135. return;
  136. }
  137. status >>= 1;
  138. }
  139. spurious_interrupt();
  140. }
  141. asmlinkage void plat_irq_dispatch(void)
  142. {
  143. unsigned int pending = read_c0_status() & read_c0_cause() & ST0_IM;
  144. if (pending & STATUSF_IP7) /* cpu timer */
  145. do_IRQ(7);
  146. else if (pending & STATUSF_IP2) /* int0 hardware line */
  147. ar7_cascade();
  148. else
  149. spurious_interrupt();
  150. }