gt-irq.c 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. /*
  2. *
  3. * Copyright 2002 Momentum Computer
  4. * Author: mdharm@momenco.com
  5. *
  6. * arch/mips/momentum/ocelot_g/gt_irq.c
  7. * Interrupt routines for gt64240. Currently it only handles timer irq.
  8. *
  9. * This program is free software; you can redistribute it and/or modify it
  10. * under the terms of the GNU General Public License as published by the
  11. * Free Software Foundation; either version 2 of the License, or (at your
  12. * option) any later version.
  13. */
  14. #include <linux/module.h>
  15. #include <linux/interrupt.h>
  16. #include <linux/kernel.h>
  17. #include <linux/sched.h>
  18. #include <linux/kernel_stat.h>
  19. #include <asm/gt64240.h>
  20. #include <asm/io.h>
  21. unsigned long bus_clock;
  22. /*
  23. * These are interrupt handlers for the GT on-chip interrupts. They
  24. * all come in to the MIPS on a single interrupt line, and have to
  25. * be handled and ack'ed differently than other MIPS interrupts.
  26. */
  27. #if CURRENTLY_UNUSED
  28. struct tq_struct irq_handlers[MAX_CAUSE_REGS][MAX_CAUSE_REG_WIDTH];
  29. void hook_irq_handler(int int_cause, int bit_num, void *isr_ptr);
  30. /*
  31. * Hooks IRQ handler to the system. When the system is interrupted
  32. * the interrupt service routine is called.
  33. *
  34. * Inputs :
  35. * int_cause - The interrupt cause number. In EVB64120 two parameters
  36. * are declared, INT_CAUSE_MAIN and INT_CAUSE_HIGH.
  37. * bit_num - Indicates which bit number in the cause register
  38. * isr_ptr - Pointer to the interrupt service routine
  39. */
  40. void hook_irq_handler(int int_cause, int bit_num, void *isr_ptr)
  41. {
  42. irq_handlers[int_cause][bit_num].routine = isr_ptr;
  43. }
  44. /*
  45. * Enables the IRQ on Galileo Chip
  46. *
  47. * Inputs :
  48. * int_cause - The interrupt cause number. In EVB64120 two parameters
  49. * are declared, INT_CAUSE_MAIN and INT_CAUSE_HIGH.
  50. * bit_num - Indicates which bit number in the cause register
  51. *
  52. * Outputs :
  53. * 1 if successful, 0 if failure
  54. */
  55. int enable_galileo_irq(int int_cause, int bit_num)
  56. {
  57. if (int_cause == INT_CAUSE_MAIN)
  58. SET_REG_BITS(CPU_INTERRUPT_MASK_REGISTER, (1 << bit_num));
  59. else if (int_cause == INT_CAUSE_HIGH)
  60. SET_REG_BITS(CPU_HIGH_INTERRUPT_MASK_REGISTER,
  61. (1 << bit_num));
  62. else
  63. return 0;
  64. return 1;
  65. }
  66. /*
  67. * Disables the IRQ on Galileo Chip
  68. *
  69. * Inputs :
  70. * int_cause - The interrupt cause number. In EVB64120 two parameters
  71. * are declared, INT_CAUSE_MAIN and INT_CAUSE_HIGH.
  72. * bit_num - Indicates which bit number in the cause register
  73. *
  74. * Outputs :
  75. * 1 if successful, 0 if failure
  76. */
  77. int disable_galileo_irq(int int_cause, int bit_num)
  78. {
  79. if (int_cause == INT_CAUSE_MAIN)
  80. RESET_REG_BITS(CPU_INTERRUPT_MASK_REGISTER,
  81. (1 << bit_num));
  82. else if (int_cause == INT_CAUSE_HIGH)
  83. RESET_REG_BITS(CPU_HIGH_INTERRUPT_MASK_REGISTER,
  84. (1 << bit_num));
  85. else
  86. return 0;
  87. return 1;
  88. }
  89. #endif /* UNUSED */
  90. /*
  91. * Interrupt handler for interrupts coming from the Galileo chip via P0_INT#.
  92. *
  93. * We route the timer interrupt to P0_INT# (IRQ 6), and that's all this
  94. * routine can handle, for now.
  95. *
  96. * In the future, we'll route more interrupts to this pin, and that's why
  97. * we keep this particular structure in the function.
  98. */
  99. static irqreturn_t gt64240_p0int_irq(int irq, void *dev)
  100. {
  101. uint32_t irq_src, irq_src_mask;
  102. int handled;
  103. /* get the low interrupt cause register */
  104. irq_src = MV_READ(LOW_INTERRUPT_CAUSE_REGISTER);
  105. /* get the mask register for this pin */
  106. irq_src_mask = MV_READ(PCI_0INTERRUPT_CAUSE_MASK_REGISTER_LOW);
  107. /* mask off only the interrupts we're interested in */
  108. irq_src = irq_src & irq_src_mask;
  109. handled = IRQ_NONE;
  110. /* Check for timer interrupt */
  111. if (irq_src & 0x00000100) {
  112. handled = IRQ_HANDLED;
  113. irq_src &= ~0x00000100;
  114. /* Clear any pending cause bits */
  115. MV_WRITE(TIMER_COUNTER_0_3_INTERRUPT_CAUSE, 0x0);
  116. /* handle the timer call */
  117. do_timer(1);
  118. #ifndef CONFIG_SMP
  119. update_process_times(user_mode(get_irq_regs()));
  120. #endif
  121. }
  122. if (irq_src) {
  123. printk(KERN_INFO
  124. "UNKNOWN P0_INT# interrupt received, irq_src=0x%x\n",
  125. irq_src);
  126. }
  127. return handled;
  128. }
  129. /*
  130. * Initializes timer using galileo's built in timer.
  131. */
  132. /*
  133. * This will ignore the standard MIPS timer interrupt handler
  134. * that is passed in as *irq (=irq0 in ../kernel/time.c).
  135. * We will do our own timer interrupt handling.
  136. */
  137. void gt64240_time_init(void)
  138. {
  139. static struct irqaction timer;
  140. /* Stop the timer -- we'll use timer #0 */
  141. MV_WRITE(TIMER_COUNTER_0_3_CONTROL, 0x0);
  142. /* Load timer value for 100 Hz */
  143. MV_WRITE(TIMER_COUNTER0, bus_clock / 100);
  144. /*
  145. * Create the IRQ structure entry for the timer. Since we're too early
  146. * in the boot process to use the "request_irq()" call, we'll hard-code
  147. * the values to the correct interrupt line.
  148. */
  149. timer.handler = &gt64240_p0int_irq;
  150. timer.flags = IRQF_SHARED | IRQF_DISABLED;
  151. timer.name = "timer";
  152. timer.dev_id = NULL;
  153. timer.next = NULL;
  154. timer.mask = CPU_MASK_NONE;
  155. irq_desc[6].action = &timer;
  156. enable_irq(6);
  157. /* Clear any pending cause bits */
  158. MV_WRITE(TIMER_COUNTER_0_3_INTERRUPT_CAUSE, 0x0);
  159. /* Enable the interrupt for timer 0 */
  160. MV_WRITE(TIMER_COUNTER_0_3_INTERRUPT_MASK, 0x1);
  161. /* Enable the timer interrupt for GT-64240 pin P0_INT# */
  162. MV_WRITE (PCI_0INTERRUPT_CAUSE_MASK_REGISTER_LOW, 0x100);
  163. /* Configure and start the timer */
  164. MV_WRITE(TIMER_COUNTER_0_3_CONTROL, 0x3);
  165. }
  166. void gt64240_irq_init(void)
  167. {
  168. #if CURRENTLY_UNUSED
  169. int i, j;
  170. /* Reset irq handlers pointers to NULL */
  171. for (i = 0; i < MAX_CAUSE_REGS; i++) {
  172. for (j = 0; j < MAX_CAUSE_REG_WIDTH; j++) {
  173. irq_handlers[i][j].next = NULL;
  174. irq_handlers[i][j].sync = 0;
  175. irq_handlers[i][j].routine = NULL;
  176. irq_handlers[i][j].data = NULL;
  177. }
  178. }
  179. #endif
  180. }