irq_5477.c
上传用户:jlfgdled
上传日期:2013-04-10
资源大小:33168k
文件大小:4k
源码类别:

Linux/Unix编程

开发平台:

Unix_Linux

  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. hw_irq_controller vrc5477_irq_controller = {
  74. "vrc5477_irq",
  75. vrc5477_irq_startup,
  76. vrc5477_irq_shutdown,
  77. vrc5477_irq_enable,
  78. vrc5477_irq_disable,
  79. vrc5477_irq_ack,
  80. vrc5477_irq_end,
  81. NULL /* no affinity stuff for UP */
  82. };
  83. void
  84. vrc5477_irq_init(u32 irq_base)
  85. {
  86. extern irq_desc_t irq_desc[];
  87. u32 i;
  88. for (i= irq_base; i< irq_base+ NUM_5477_IRQ; i++) {
  89. irq_desc[i].status = IRQ_DISABLED;
  90. irq_desc[i].action = NULL;
  91. irq_desc[i].depth = 1;
  92. irq_desc[i].handler = &vrc5477_irq_controller;
  93. }
  94. vrc5477_irq_base = irq_base;
  95. }
  96. void ll_vrc5477_irq_route(int vrc5477_irq, int ip)
  97. {
  98. u32 reg_value;
  99. u32 reg_bitmask;
  100. u32 reg_index;
  101. db_assert(vrc5477_irq >= 0);
  102. db_assert(vrc5477_irq < NUM_5477_IRQ);
  103. db_assert(ip >= 0);
  104. db_assert((ip < 5) || (ip == 6));
  105. reg_index = DDB_INTCTRL0 + vrc5477_irq/8*4;
  106. reg_value = ddb_in32(reg_index);
  107. reg_bitmask = 7 << (vrc5477_irq % 8 * 4);
  108. reg_value &= ~reg_bitmask;
  109. reg_value |= ip << (vrc5477_irq % 8 * 4);
  110. ddb_out32(reg_index, reg_value);
  111. }
  112. void ll_vrc5477_irq_enable(int vrc5477_irq)
  113. {
  114. u32 reg_value;
  115. u32 reg_bitmask;
  116. u32 reg_index;
  117. db_assert(vrc5477_irq >= 0);
  118. db_assert(vrc5477_irq < NUM_5477_IRQ);
  119. reg_index = DDB_INTCTRL0 + vrc5477_irq/8*4;
  120. reg_value = ddb_in32(reg_index);
  121. reg_bitmask = 8 << (vrc5477_irq % 8 * 4);
  122. db_assert((reg_value & reg_bitmask) == 0);
  123. ddb_out32(reg_index, reg_value | reg_bitmask);
  124. }
  125. void ll_vrc5477_irq_disable(int vrc5477_irq)
  126. {
  127. u32 reg_value;
  128. u32 reg_bitmask;
  129. u32 reg_index;
  130. db_assert(vrc5477_irq >= 0);
  131. db_assert(vrc5477_irq < NUM_5477_IRQ);
  132. reg_index = DDB_INTCTRL0 + vrc5477_irq/8*4;
  133. reg_value = ddb_in32(reg_index);
  134. reg_bitmask = 8 << (vrc5477_irq % 8 * 4);
  135. /* we assert that the interrupt is enabled (perhaps over-zealous) */
  136. db_assert( (reg_value & reg_bitmask) != 0);
  137. ddb_out32(reg_index, reg_value & ~reg_bitmask);
  138. }