irq_5477.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. /*
  2. * Copyright 2001 MontaVista Software Inc.
  3. * Author: Jun Sun, jsun@mvista.com or jsun@junsun.net
  4. *
  5. * arch/mips/ddb5xxx/ddb5477/irq_5477.c
  6. * This file defines the irq handler for Vrc5477.
  7. *
  8. * This program is free software; you can redistribute it and/or modify it
  9. * under the terms of the GNU General Public License as published by the
  10. * Free Software Foundation; either version 2 of the License, or (at your
  11. * option) any later version.
  12. *
  13. */
  14. /*
  15. * Vrc5477 defines 32 IRQs.
  16. *
  17. * This file exports one function:
  18. * vrc5477_irq_init(u32 irq_base);
  19. */
  20. #include <linux/interrupt.h>
  21. #include <linux/types.h>
  22. #include <linux/ptrace.h>
  23. #include <asm/debug.h>
  24. #include <asm/ddb5xxx/ddb5xxx.h>
  25. /* number of total irqs supported by Vrc5477 */
  26. #define NUM_5477_IRQ 32
  27. static int vrc5477_irq_base = -1;
  28. static void
  29. vrc5477_irq_enable(unsigned int irq)
  30. {
  31. db_assert(vrc5477_irq_base != -1);
  32. db_assert(irq >= vrc5477_irq_base);
  33. db_assert(irq < vrc5477_irq_base+ NUM_5477_IRQ);
  34. ll_vrc5477_irq_enable(irq - vrc5477_irq_base);
  35. }
  36. static void
  37. vrc5477_irq_disable(unsigned int irq)
  38. {
  39. db_assert(vrc5477_irq_base != -1);
  40. db_assert(irq >= vrc5477_irq_base);
  41. db_assert(irq < vrc5477_irq_base + NUM_5477_IRQ);
  42. ll_vrc5477_irq_disable(irq - vrc5477_irq_base);
  43. }
  44. static unsigned int vrc5477_irq_startup(unsigned int irq)
  45. {
  46. vrc5477_irq_enable(irq);
  47. return 0;
  48. }
  49. #define vrc5477_irq_shutdown vrc5477_irq_disable
  50. static void
  51. vrc5477_irq_ack(unsigned int irq)
  52. {
  53. db_assert(vrc5477_irq_base != -1);
  54. db_assert(irq >= vrc5477_irq_base);
  55. db_assert(irq < vrc5477_irq_base+ NUM_5477_IRQ);
  56. /* clear the interrupt bit */
  57. /* some irqs require the driver to clear the sources */
  58. ddb_out32(DDB_INTCLR32, 1 << (irq - vrc5477_irq_base));
  59. /* disable interrupt - some handler will re-enable the irq
  60. * and if the interrupt is leveled, we will have infinite loop
  61. */
  62. ll_vrc5477_irq_disable(irq - vrc5477_irq_base);
  63. }
  64. static void
  65. vrc5477_irq_end(unsigned int irq)
  66. {
  67. db_assert(vrc5477_irq_base != -1);
  68. db_assert(irq >= vrc5477_irq_base);
  69. db_assert(irq < vrc5477_irq_base + NUM_5477_IRQ);
  70. if(!(irq_desc[irq].status & (IRQ_DISABLED | IRQ_INPROGRESS)))
  71. ll_vrc5477_irq_enable( irq - vrc5477_irq_base);
  72. }
  73. struct irq_chip vrc5477_irq_controller = {
  74. .typename = "vrc5477_irq",
  75. .startup = vrc5477_irq_startup,
  76. .shutdown = vrc5477_irq_shutdown,
  77. .enable = vrc5477_irq_enable,
  78. .disable = vrc5477_irq_disable,
  79. .ack = vrc5477_irq_ack,
  80. .end = vrc5477_irq_end
  81. };
  82. void __init vrc5477_irq_init(u32 irq_base)
  83. {
  84. u32 i;
  85. for (i= irq_base; i< irq_base+ NUM_5477_IRQ; i++) {
  86. irq_desc[i].status = IRQ_DISABLED;
  87. irq_desc[i].action = NULL;
  88. irq_desc[i].depth = 1;
  89. irq_desc[i].chip = &vrc5477_irq_controller;
  90. }
  91. vrc5477_irq_base = irq_base;
  92. }
  93. void ll_vrc5477_irq_route(int vrc5477_irq, int ip)
  94. {
  95. u32 reg_value;
  96. u32 reg_bitmask;
  97. u32 reg_index;
  98. db_assert(vrc5477_irq >= 0);
  99. db_assert(vrc5477_irq < NUM_5477_IRQ);
  100. db_assert(ip >= 0);
  101. db_assert((ip < 5) || (ip == 6));
  102. reg_index = DDB_INTCTRL0 + vrc5477_irq/8*4;
  103. reg_value = ddb_in32(reg_index);
  104. reg_bitmask = 7 << (vrc5477_irq % 8 * 4);
  105. reg_value &= ~reg_bitmask;
  106. reg_value |= ip << (vrc5477_irq % 8 * 4);
  107. ddb_out32(reg_index, reg_value);
  108. }
  109. void ll_vrc5477_irq_enable(int vrc5477_irq)
  110. {
  111. u32 reg_value;
  112. u32 reg_bitmask;
  113. u32 reg_index;
  114. db_assert(vrc5477_irq >= 0);
  115. db_assert(vrc5477_irq < NUM_5477_IRQ);
  116. reg_index = DDB_INTCTRL0 + vrc5477_irq/8*4;
  117. reg_value = ddb_in32(reg_index);
  118. reg_bitmask = 8 << (vrc5477_irq % 8 * 4);
  119. db_assert((reg_value & reg_bitmask) == 0);
  120. ddb_out32(reg_index, reg_value | reg_bitmask);
  121. }
  122. void ll_vrc5477_irq_disable(int vrc5477_irq)
  123. {
  124. u32 reg_value;
  125. u32 reg_bitmask;
  126. u32 reg_index;
  127. db_assert(vrc5477_irq >= 0);
  128. db_assert(vrc5477_irq < NUM_5477_IRQ);
  129. reg_index = DDB_INTCTRL0 + vrc5477_irq/8*4;
  130. reg_value = ddb_in32(reg_index);
  131. reg_bitmask = 8 << (vrc5477_irq % 8 * 4);
  132. /* we assert that the interrupt is enabled (perhaps over-zealous) */
  133. db_assert( (reg_value & reg_bitmask) != 0);
  134. ddb_out32(reg_index, reg_value & ~reg_bitmask);
  135. }