irq_5477.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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 void
  45. vrc5477_irq_ack(unsigned int irq)
  46. {
  47. db_assert(vrc5477_irq_base != -1);
  48. db_assert(irq >= vrc5477_irq_base);
  49. db_assert(irq < vrc5477_irq_base+ NUM_5477_IRQ);
  50. /* clear the interrupt bit */
  51. /* some irqs require the driver to clear the sources */
  52. ddb_out32(DDB_INTCLR32, 1 << (irq - vrc5477_irq_base));
  53. /* disable interrupt - some handler will re-enable the irq
  54. * and if the interrupt is leveled, we will have infinite loop
  55. */
  56. ll_vrc5477_irq_disable(irq - vrc5477_irq_base);
  57. }
  58. static void
  59. vrc5477_irq_end(unsigned int irq)
  60. {
  61. db_assert(vrc5477_irq_base != -1);
  62. db_assert(irq >= vrc5477_irq_base);
  63. db_assert(irq < vrc5477_irq_base + NUM_5477_IRQ);
  64. if(!(irq_desc[irq].status & (IRQ_DISABLED | IRQ_INPROGRESS)))
  65. ll_vrc5477_irq_enable( irq - vrc5477_irq_base);
  66. }
  67. struct irq_chip vrc5477_irq_controller = {
  68. .name = "vrc5477_irq",
  69. .ack = vrc5477_irq_ack,
  70. .mask = vrc5477_irq_disable,
  71. .mask_ack = vrc5477_irq_ack,
  72. .unmask = vrc5477_irq_enable,
  73. .end = vrc5477_irq_end
  74. };
  75. void __init vrc5477_irq_init(u32 irq_base)
  76. {
  77. u32 i;
  78. for (i= irq_base; i< irq_base+ NUM_5477_IRQ; i++)
  79. set_irq_chip(i, &vrc5477_irq_controller);
  80. vrc5477_irq_base = irq_base;
  81. }
  82. void ll_vrc5477_irq_route(int vrc5477_irq, int ip)
  83. {
  84. u32 reg_value;
  85. u32 reg_bitmask;
  86. u32 reg_index;
  87. db_assert(vrc5477_irq >= 0);
  88. db_assert(vrc5477_irq < NUM_5477_IRQ);
  89. db_assert(ip >= 0);
  90. db_assert((ip < 5) || (ip == 6));
  91. reg_index = DDB_INTCTRL0 + vrc5477_irq/8*4;
  92. reg_value = ddb_in32(reg_index);
  93. reg_bitmask = 7 << (vrc5477_irq % 8 * 4);
  94. reg_value &= ~reg_bitmask;
  95. reg_value |= ip << (vrc5477_irq % 8 * 4);
  96. ddb_out32(reg_index, reg_value);
  97. }
  98. void ll_vrc5477_irq_enable(int vrc5477_irq)
  99. {
  100. u32 reg_value;
  101. u32 reg_bitmask;
  102. u32 reg_index;
  103. db_assert(vrc5477_irq >= 0);
  104. db_assert(vrc5477_irq < NUM_5477_IRQ);
  105. reg_index = DDB_INTCTRL0 + vrc5477_irq/8*4;
  106. reg_value = ddb_in32(reg_index);
  107. reg_bitmask = 8 << (vrc5477_irq % 8 * 4);
  108. db_assert((reg_value & reg_bitmask) == 0);
  109. ddb_out32(reg_index, reg_value | reg_bitmask);
  110. }
  111. void ll_vrc5477_irq_disable(int vrc5477_irq)
  112. {
  113. u32 reg_value;
  114. u32 reg_bitmask;
  115. u32 reg_index;
  116. db_assert(vrc5477_irq >= 0);
  117. db_assert(vrc5477_irq < NUM_5477_IRQ);
  118. reg_index = DDB_INTCTRL0 + vrc5477_irq/8*4;
  119. reg_value = ddb_in32(reg_index);
  120. reg_bitmask = 8 << (vrc5477_irq % 8 * 4);
  121. /* we assert that the interrupt is enabled (perhaps over-zealous) */
  122. db_assert( (reg_value & reg_bitmask) != 0);
  123. ddb_out32(reg_index, reg_value & ~reg_bitmask);
  124. }