gt-irq.c 5.5 KB

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