irq.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  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 <linux/irq.h>
  22. #include <asm/irq_cpu.h>
  23. #include <asm/mipsregs.h>
  24. #include <asm/mach-ar7/ar7.h>
  25. #define EXCEPT_OFFSET 0x80
  26. #define PACE_OFFSET 0xA0
  27. #define CHNLS_OFFSET 0x200
  28. #define REG_OFFSET(irq, reg) ((irq) / 32 * 0x4 + reg * 0x10)
  29. #define SEC_REG_OFFSET(reg) (EXCEPT_OFFSET + reg * 0x8)
  30. #define SEC_SR_OFFSET (SEC_REG_OFFSET(0)) /* 0x80 */
  31. #define CR_OFFSET(irq) (REG_OFFSET(irq, 1)) /* 0x10 */
  32. #define SEC_CR_OFFSET (SEC_REG_OFFSET(1)) /* 0x88 */
  33. #define ESR_OFFSET(irq) (REG_OFFSET(irq, 2)) /* 0x20 */
  34. #define SEC_ESR_OFFSET (SEC_REG_OFFSET(2)) /* 0x90 */
  35. #define ECR_OFFSET(irq) (REG_OFFSET(irq, 3)) /* 0x30 */
  36. #define SEC_ECR_OFFSET (SEC_REG_OFFSET(3)) /* 0x98 */
  37. #define PIR_OFFSET (0x40)
  38. #define MSR_OFFSET (0x44)
  39. #define PM_OFFSET(irq) (REG_OFFSET(irq, 5)) /* 0x50 */
  40. #define TM_OFFSET(irq) (REG_OFFSET(irq, 6)) /* 0x60 */
  41. #define REG(addr) ((u32 *)(KSEG1ADDR(AR7_REGS_IRQ) + addr))
  42. #define CHNL_OFFSET(chnl) (CHNLS_OFFSET + (chnl * 4))
  43. static int ar7_irq_base;
  44. static void ar7_unmask_irq(struct irq_data *d)
  45. {
  46. writel(1 << ((d->irq - ar7_irq_base) % 32),
  47. REG(ESR_OFFSET(d->irq - ar7_irq_base)));
  48. }
  49. static void ar7_mask_irq(struct irq_data *d)
  50. {
  51. writel(1 << ((d->irq - ar7_irq_base) % 32),
  52. REG(ECR_OFFSET(d->irq - ar7_irq_base)));
  53. }
  54. static void ar7_ack_irq(struct irq_data *d)
  55. {
  56. writel(1 << ((d->irq - ar7_irq_base) % 32),
  57. REG(CR_OFFSET(d->irq - ar7_irq_base)));
  58. }
  59. static void ar7_unmask_sec_irq(struct irq_data *d)
  60. {
  61. writel(1 << (d->irq - ar7_irq_base - 40), REG(SEC_ESR_OFFSET));
  62. }
  63. static void ar7_mask_sec_irq(struct irq_data *d)
  64. {
  65. writel(1 << (d->irq - ar7_irq_base - 40), REG(SEC_ECR_OFFSET));
  66. }
  67. static void ar7_ack_sec_irq(struct irq_data *d)
  68. {
  69. writel(1 << (d->irq - ar7_irq_base - 40), REG(SEC_CR_OFFSET));
  70. }
  71. static struct irq_chip ar7_irq_type = {
  72. .name = "AR7",
  73. .irq_unmask = ar7_unmask_irq,
  74. .irq_mask = ar7_mask_irq,
  75. .irq_ack = ar7_ack_irq
  76. };
  77. static struct irq_chip ar7_sec_irq_type = {
  78. .name = "AR7",
  79. .irq_unmask = ar7_unmask_sec_irq,
  80. .irq_mask = ar7_mask_sec_irq,
  81. .irq_ack = ar7_ack_sec_irq,
  82. };
  83. static struct irqaction ar7_cascade_action = {
  84. .handler = no_action,
  85. .name = "AR7 cascade interrupt",
  86. .flags = IRQF_NO_THREAD,
  87. };
  88. static void __init ar7_irq_init(int base)
  89. {
  90. int i;
  91. /*
  92. * Disable interrupts and clear pending
  93. */
  94. writel(0xffffffff, REG(ECR_OFFSET(0)));
  95. writel(0xff, REG(ECR_OFFSET(32)));
  96. writel(0xffffffff, REG(SEC_ECR_OFFSET));
  97. writel(0xffffffff, REG(CR_OFFSET(0)));
  98. writel(0xff, REG(CR_OFFSET(32)));
  99. writel(0xffffffff, REG(SEC_CR_OFFSET));
  100. ar7_irq_base = base;
  101. for (i = 0; i < 40; i++) {
  102. writel(i, REG(CHNL_OFFSET(i)));
  103. /* Primary IRQ's */
  104. irq_set_chip_and_handler(base + i, &ar7_irq_type,
  105. handle_level_irq);
  106. /* Secondary IRQ's */
  107. if (i < 32)
  108. irq_set_chip_and_handler(base + i + 40,
  109. &ar7_sec_irq_type,
  110. handle_level_irq);
  111. }
  112. setup_irq(2, &ar7_cascade_action);
  113. setup_irq(ar7_irq_base, &ar7_cascade_action);
  114. set_c0_status(IE_IRQ0);
  115. }
  116. void __init arch_init_irq(void)
  117. {
  118. mips_cpu_irq_init();
  119. ar7_irq_init(8);
  120. }
  121. static void ar7_cascade(void)
  122. {
  123. u32 status;
  124. int i, irq;
  125. /* Primary IRQ's */
  126. irq = readl(REG(PIR_OFFSET)) & 0x3f;
  127. if (irq) {
  128. do_IRQ(ar7_irq_base + irq);
  129. return;
  130. }
  131. /* Secondary IRQ's are cascaded through primary '0' */
  132. writel(1, REG(CR_OFFSET(irq)));
  133. status = readl(REG(SEC_SR_OFFSET));
  134. for (i = 0; i < 32; i++) {
  135. if (status & 1) {
  136. do_IRQ(ar7_irq_base + i + 40);
  137. return;
  138. }
  139. status >>= 1;
  140. }
  141. spurious_interrupt();
  142. }
  143. asmlinkage void plat_irq_dispatch(void)
  144. {
  145. unsigned int pending = read_c0_status() & read_c0_cause() & ST0_IM;
  146. if (pending & STATUSF_IP7) /* cpu timer */
  147. do_IRQ(7);
  148. else if (pending & STATUSF_IP2) /* int0 hardware line */
  149. ar7_cascade();
  150. else
  151. spurious_interrupt();
  152. }