irq-mv6434x.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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 <linux/kernel_stat.h>
  15. #include <linux/mv643xx.h>
  16. #include <linux/sched.h>
  17. #include <asm/ptrace.h>
  18. #include <asm/io.h>
  19. #include <asm/irq.h>
  20. #include <asm/marvell.h>
  21. static unsigned int irq_base;
  22. static inline int ls1bit32(unsigned int x)
  23. {
  24. int b = 31, s;
  25. s = 16; if (x << 16 == 0) s = 0; b -= s; x <<= s;
  26. s = 8; if (x << 8 == 0) s = 0; b -= s; x <<= s;
  27. s = 4; if (x << 4 == 0) s = 0; b -= s; x <<= s;
  28. s = 2; if (x << 2 == 0) s = 0; b -= s; x <<= s;
  29. s = 1; if (x << 1 == 0) s = 0; b -= s;
  30. return b;
  31. }
  32. /* mask off an interrupt -- 1 is enable, 0 is disable */
  33. static inline void mask_mv64340_irq(unsigned int irq)
  34. {
  35. uint32_t value;
  36. if (irq < (irq_base + 32)) {
  37. value = MV_READ(MV64340_INTERRUPT0_MASK_0_LOW);
  38. value &= ~(1 << (irq - irq_base));
  39. MV_WRITE(MV64340_INTERRUPT0_MASK_0_LOW, value);
  40. } else {
  41. value = MV_READ(MV64340_INTERRUPT0_MASK_0_HIGH);
  42. value &= ~(1 << (irq - irq_base - 32));
  43. MV_WRITE(MV64340_INTERRUPT0_MASK_0_HIGH, value);
  44. }
  45. }
  46. /* unmask an interrupt -- 1 is enable, 0 is disable */
  47. static inline void unmask_mv64340_irq(unsigned int irq)
  48. {
  49. uint32_t value;
  50. if (irq < (irq_base + 32)) {
  51. value = MV_READ(MV64340_INTERRUPT0_MASK_0_LOW);
  52. value |= 1 << (irq - irq_base);
  53. MV_WRITE(MV64340_INTERRUPT0_MASK_0_LOW, value);
  54. } else {
  55. value = MV_READ(MV64340_INTERRUPT0_MASK_0_HIGH);
  56. value |= 1 << (irq - irq_base - 32);
  57. MV_WRITE(MV64340_INTERRUPT0_MASK_0_HIGH, value);
  58. }
  59. }
  60. /*
  61. * Enables the IRQ on Marvell Chip
  62. */
  63. static void enable_mv64340_irq(unsigned int irq)
  64. {
  65. unmask_mv64340_irq(irq);
  66. }
  67. /*
  68. * Initialize the IRQ on Marvell Chip
  69. */
  70. static unsigned int startup_mv64340_irq(unsigned int irq)
  71. {
  72. unmask_mv64340_irq(irq);
  73. return 0;
  74. }
  75. /*
  76. * Disables the IRQ on Marvell Chip
  77. */
  78. static void disable_mv64340_irq(unsigned int irq)
  79. {
  80. mask_mv64340_irq(irq);
  81. }
  82. /*
  83. * Masks and ACKs an IRQ
  84. */
  85. static void mask_and_ack_mv64340_irq(unsigned int irq)
  86. {
  87. mask_mv64340_irq(irq);
  88. }
  89. /*
  90. * End IRQ processing
  91. */
  92. static void end_mv64340_irq(unsigned int irq)
  93. {
  94. if (!(irq_desc[irq].status & (IRQ_DISABLED|IRQ_INPROGRESS)))
  95. unmask_mv64340_irq(irq);
  96. }
  97. /*
  98. * Interrupt handler for interrupts coming from the Marvell chip.
  99. * It could be built in ethernet ports etc...
  100. */
  101. void ll_mv64340_irq(struct pt_regs *regs)
  102. {
  103. unsigned int irq_src_low, irq_src_high;
  104. unsigned int irq_mask_low, irq_mask_high;
  105. /* read the interrupt status registers */
  106. irq_mask_low = MV_READ(MV64340_INTERRUPT0_MASK_0_LOW);
  107. irq_mask_high = MV_READ(MV64340_INTERRUPT0_MASK_0_HIGH);
  108. irq_src_low = MV_READ(MV64340_MAIN_INTERRUPT_CAUSE_LOW);
  109. irq_src_high = MV_READ(MV64340_MAIN_INTERRUPT_CAUSE_HIGH);
  110. /* mask for just the interrupts we want */
  111. irq_src_low &= irq_mask_low;
  112. irq_src_high &= irq_mask_high;
  113. if (irq_src_low)
  114. do_IRQ(ls1bit32(irq_src_low) + irq_base, regs);
  115. else
  116. do_IRQ(ls1bit32(irq_src_high) + irq_base + 32, regs);
  117. }
  118. #define shutdown_mv64340_irq disable_mv64340_irq
  119. struct hw_interrupt_type mv64340_irq_type = {
  120. .typename = "MV-64340",
  121. .startup = startup_mv64340_irq,
  122. .shutdown = shutdown_mv64340_irq,
  123. .enable = enable_mv64340_irq,
  124. .disable = disable_mv64340_irq,
  125. .ack = mask_and_ack_mv64340_irq,
  126. .end = end_mv64340_irq,
  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. }