irq-mv6434x.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. /*
  2. * Copyright 2002 Momentum Computer
  3. * Author: mdharm@momenco.com
  4. * Copyright (C) 2004 Ralf Baechle <ralf@linux-mips.org>
  5. *
  6. * This program is free software; you can redistribute it and/or modify it
  7. * under the terms of the GNU General Public License as published by the
  8. * Free Software Foundation; either version 2 of the License, or (at your
  9. * option) any later version.
  10. */
  11. #include <linux/module.h>
  12. #include <linux/interrupt.h>
  13. #include <linux/kernel.h>
  14. #include <asm/ptrace.h>
  15. #include <linux/sched.h>
  16. #include <linux/kernel_stat.h>
  17. #include <asm/io.h>
  18. #include <asm/irq.h>
  19. #include <linux/mv643xx.h>
  20. static unsigned int irq_base;
  21. static inline int ls1bit32(unsigned int x)
  22. {
  23. int b = 31, s;
  24. s = 16; if (x << 16 == 0) s = 0; b -= s; x <<= s;
  25. s = 8; if (x << 8 == 0) s = 0; b -= s; x <<= s;
  26. s = 4; if (x << 4 == 0) s = 0; b -= s; x <<= s;
  27. s = 2; if (x << 2 == 0) s = 0; b -= s; x <<= s;
  28. s = 1; if (x << 1 == 0) s = 0; b -= s;
  29. return b;
  30. }
  31. /* mask off an interrupt -- 1 is enable, 0 is disable */
  32. static inline void mask_mv64340_irq(unsigned int irq)
  33. {
  34. uint32_t value;
  35. if (irq < (irq_base + 32)) {
  36. value = MV_READ(MV64340_INTERRUPT0_MASK_0_LOW);
  37. value &= ~(1 << (irq - irq_base));
  38. MV_WRITE(MV64340_INTERRUPT0_MASK_0_LOW, value);
  39. } else {
  40. value = MV_READ(MV64340_INTERRUPT0_MASK_0_HIGH);
  41. value &= ~(1 << (irq - irq_base - 32));
  42. MV_WRITE(MV64340_INTERRUPT0_MASK_0_HIGH, value);
  43. }
  44. }
  45. /* unmask an interrupt -- 1 is enable, 0 is disable */
  46. static inline void unmask_mv64340_irq(unsigned int irq)
  47. {
  48. uint32_t value;
  49. if (irq < (irq_base + 32)) {
  50. value = MV_READ(MV64340_INTERRUPT0_MASK_0_LOW);
  51. value |= 1 << (irq - irq_base);
  52. MV_WRITE(MV64340_INTERRUPT0_MASK_0_LOW, value);
  53. } else {
  54. value = MV_READ(MV64340_INTERRUPT0_MASK_0_HIGH);
  55. value |= 1 << (irq - irq_base - 32);
  56. MV_WRITE(MV64340_INTERRUPT0_MASK_0_HIGH, value);
  57. }
  58. }
  59. /*
  60. * Enables the IRQ on Marvell Chip
  61. */
  62. static void enable_mv64340_irq(unsigned int irq)
  63. {
  64. unmask_mv64340_irq(irq);
  65. }
  66. /*
  67. * Initialize the IRQ on Marvell Chip
  68. */
  69. static unsigned int startup_mv64340_irq(unsigned int irq)
  70. {
  71. unmask_mv64340_irq(irq);
  72. return 0;
  73. }
  74. /*
  75. * Disables the IRQ on Marvell Chip
  76. */
  77. static void disable_mv64340_irq(unsigned int irq)
  78. {
  79. mask_mv64340_irq(irq);
  80. }
  81. /*
  82. * Masks and ACKs an IRQ
  83. */
  84. static void mask_and_ack_mv64340_irq(unsigned int irq)
  85. {
  86. mask_mv64340_irq(irq);
  87. }
  88. /*
  89. * End IRQ processing
  90. */
  91. static void end_mv64340_irq(unsigned int irq)
  92. {
  93. if (!(irq_desc[irq].status & (IRQ_DISABLED|IRQ_INPROGRESS)))
  94. unmask_mv64340_irq(irq);
  95. }
  96. /*
  97. * Interrupt handler for interrupts coming from the Marvell chip.
  98. * It could be built in ethernet ports etc...
  99. */
  100. void ll_mv64340_irq(struct pt_regs *regs)
  101. {
  102. unsigned int irq_src_low, irq_src_high;
  103. unsigned int irq_mask_low, irq_mask_high;
  104. /* read the interrupt status registers */
  105. irq_mask_low = MV_READ(MV64340_INTERRUPT0_MASK_0_LOW);
  106. irq_mask_high = MV_READ(MV64340_INTERRUPT0_MASK_0_HIGH);
  107. irq_src_low = MV_READ(MV64340_MAIN_INTERRUPT_CAUSE_LOW);
  108. irq_src_high = MV_READ(MV64340_MAIN_INTERRUPT_CAUSE_HIGH);
  109. /* mask for just the interrupts we want */
  110. irq_src_low &= irq_mask_low;
  111. irq_src_high &= irq_mask_high;
  112. if (irq_src_low)
  113. do_IRQ(ls1bit32(irq_src_low) + irq_base, regs);
  114. else
  115. do_IRQ(ls1bit32(irq_src_high) + irq_base + 32, regs);
  116. }
  117. #define shutdown_mv64340_irq disable_mv64340_irq
  118. struct hw_interrupt_type mv64340_irq_type = {
  119. "MV-64340",
  120. startup_mv64340_irq,
  121. shutdown_mv64340_irq,
  122. enable_mv64340_irq,
  123. disable_mv64340_irq,
  124. mask_and_ack_mv64340_irq,
  125. end_mv64340_irq,
  126. NULL
  127. };
  128. void __init mv64340_irq_init(unsigned int base)
  129. {
  130. int i;
  131. /* Reset irq handlers pointers to NULL */
  132. for (i = base; i < base + 64; i++) {
  133. irq_desc[i].status = IRQ_DISABLED;
  134. irq_desc[i].action = 0;
  135. irq_desc[i].depth = 2;
  136. irq_desc[i].handler = &mv64340_irq_type;
  137. }
  138. irq_base = base;
  139. }