PageRenderTime 303ms CodeModel.GetById 154ms RepoModel.GetById 1ms app.codeStats 0ms

/arch/mips/nxp/pnx8550/common/int.c

https://bitbucket.org/cresqo/cm7-p500-kernel
C | 236 lines | 153 code | 35 blank | 48 comment | 30 complexity | cc3dc4fc3cae495c6aa4618ec6c3937e MD5 | raw file
Possible License(s): LGPL-2.0, AGPL-1.0, GPL-2.0
  1. /*
  2. *
  3. * Copyright (C) 2005 Embedded Alley Solutions, Inc
  4. * Ported to 2.6.
  5. *
  6. * Per Hallsmark, per.hallsmark@mvista.com
  7. * Copyright (C) 2000, 2001 MIPS Technologies, Inc.
  8. * Copyright (C) 2001 Ralf Baechle
  9. *
  10. * Cleaned up and bug fixing: Pete Popov, ppopov@embeddedalley.com
  11. *
  12. * This program is free software; you can distribute it and/or modify it
  13. * under the terms of the GNU General Public License (Version 2) as
  14. * published by the Free Software Foundation.
  15. *
  16. * This program is distributed in the hope it will be useful, but WITHOUT
  17. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  18. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  19. * for more details.
  20. *
  21. * You should have received a copy of the GNU General Public License along
  22. * with this program; if not, write to the Free Software Foundation, Inc.,
  23. * 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
  24. *
  25. */
  26. #include <linux/compiler.h>
  27. #include <linux/init.h>
  28. #include <linux/irq.h>
  29. #include <linux/sched.h>
  30. #include <linux/interrupt.h>
  31. #include <linux/kernel_stat.h>
  32. #include <linux/random.h>
  33. #include <linux/module.h>
  34. #include <asm/io.h>
  35. #include <int.h>
  36. #include <uart.h>
  37. /* default prio for interrupts */
  38. /* first one is a no-no so therefore always prio 0 (disabled) */
  39. static char gic_prio[PNX8550_INT_GIC_TOTINT] = {
  40. 0, 1, 1, 1, 1, 15, 1, 1, 1, 1, // 0 - 9
  41. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 10 - 19
  42. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 20 - 29
  43. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 30 - 39
  44. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 40 - 49
  45. 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, // 50 - 59
  46. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 60 - 69
  47. 1 // 70
  48. };
  49. static void hw0_irqdispatch(int irq)
  50. {
  51. /* find out which interrupt */
  52. irq = PNX8550_GIC_VECTOR_0 >> 3;
  53. if (irq == 0) {
  54. printk("hw0_irqdispatch: irq 0, spurious interrupt?\n");
  55. return;
  56. }
  57. do_IRQ(PNX8550_INT_GIC_MIN + irq);
  58. }
  59. static void timer_irqdispatch(int irq)
  60. {
  61. irq = (0x01c0 & read_c0_config7()) >> 6;
  62. if (unlikely(irq == 0)) {
  63. printk("timer_irqdispatch: irq 0, spurious interrupt?\n");
  64. return;
  65. }
  66. if (irq & 0x1)
  67. do_IRQ(PNX8550_INT_TIMER1);
  68. if (irq & 0x2)
  69. do_IRQ(PNX8550_INT_TIMER2);
  70. if (irq & 0x4)
  71. do_IRQ(PNX8550_INT_TIMER3);
  72. }
  73. asmlinkage void plat_irq_dispatch(void)
  74. {
  75. unsigned int pending = read_c0_status() & read_c0_cause() & ST0_IM;
  76. if (pending & STATUSF_IP2)
  77. hw0_irqdispatch(2);
  78. else if (pending & STATUSF_IP7) {
  79. if (read_c0_config7() & 0x01c0)
  80. timer_irqdispatch(7);
  81. } else
  82. spurious_interrupt();
  83. }
  84. static inline void modify_cp0_intmask(unsigned clr_mask, unsigned set_mask)
  85. {
  86. unsigned long status = read_c0_status();
  87. status &= ~((clr_mask & 0xFF) << 8);
  88. status |= (set_mask & 0xFF) << 8;
  89. write_c0_status(status);
  90. }
  91. static inline void mask_gic_int(unsigned int irq_nr)
  92. {
  93. /* interrupt disabled, bit 26(WE_ENABLE)=1 and bit 16(enable)=0 */
  94. PNX8550_GIC_REQ(irq_nr) = 1<<28; /* set priority to 0 */
  95. }
  96. static inline void unmask_gic_int(unsigned int irq_nr)
  97. {
  98. /* set prio mask to lower four bits and enable interrupt */
  99. PNX8550_GIC_REQ(irq_nr) = (1<<26 | 1<<16) | (1<<28) | gic_prio[irq_nr];
  100. }
  101. static inline void mask_irq(unsigned int irq_nr)
  102. {
  103. if ((PNX8550_INT_CP0_MIN <= irq_nr) && (irq_nr <= PNX8550_INT_CP0_MAX)) {
  104. modify_cp0_intmask(1 << irq_nr, 0);
  105. } else if ((PNX8550_INT_GIC_MIN <= irq_nr) &&
  106. (irq_nr <= PNX8550_INT_GIC_MAX)) {
  107. mask_gic_int(irq_nr - PNX8550_INT_GIC_MIN);
  108. } else if ((PNX8550_INT_TIMER_MIN <= irq_nr) &&
  109. (irq_nr <= PNX8550_INT_TIMER_MAX)) {
  110. modify_cp0_intmask(1 << 7, 0);
  111. } else {
  112. printk("mask_irq: irq %d doesn't exist!\n", irq_nr);
  113. }
  114. }
  115. static inline void unmask_irq(unsigned int irq_nr)
  116. {
  117. if ((PNX8550_INT_CP0_MIN <= irq_nr) && (irq_nr <= PNX8550_INT_CP0_MAX)) {
  118. modify_cp0_intmask(0, 1 << irq_nr);
  119. } else if ((PNX8550_INT_GIC_MIN <= irq_nr) &&
  120. (irq_nr <= PNX8550_INT_GIC_MAX)) {
  121. unmask_gic_int(irq_nr - PNX8550_INT_GIC_MIN);
  122. } else if ((PNX8550_INT_TIMER_MIN <= irq_nr) &&
  123. (irq_nr <= PNX8550_INT_TIMER_MAX)) {
  124. modify_cp0_intmask(0, 1 << 7);
  125. } else {
  126. printk("mask_irq: irq %d doesn't exist!\n", irq_nr);
  127. }
  128. }
  129. int pnx8550_set_gic_priority(int irq, int priority)
  130. {
  131. int gic_irq = irq-PNX8550_INT_GIC_MIN;
  132. int prev_priority = PNX8550_GIC_REQ(gic_irq) & 0xf;
  133. gic_prio[gic_irq] = priority;
  134. PNX8550_GIC_REQ(gic_irq) |= (0x10000000 | gic_prio[gic_irq]);
  135. return prev_priority;
  136. }
  137. static struct irq_chip level_irq_type = {
  138. .name = "PNX Level IRQ",
  139. .ack = mask_irq,
  140. .mask = mask_irq,
  141. .mask_ack = mask_irq,
  142. .unmask = unmask_irq,
  143. };
  144. static struct irqaction gic_action = {
  145. .handler = no_action,
  146. .flags = IRQF_DISABLED,
  147. .name = "GIC",
  148. };
  149. static struct irqaction timer_action = {
  150. .handler = no_action,
  151. .flags = IRQF_DISABLED | IRQF_TIMER,
  152. .name = "Timer",
  153. };
  154. void __init arch_init_irq(void)
  155. {
  156. int i;
  157. int configPR;
  158. for (i = 0; i < PNX8550_INT_CP0_TOTINT; i++) {
  159. set_irq_chip_and_handler(i, &level_irq_type, handle_level_irq);
  160. mask_irq(i); /* mask the irq just in case */
  161. }
  162. /* init of GIC/IPC interrupts */
  163. /* should be done before cp0 since cp0 init enables the GIC int */
  164. for (i = PNX8550_INT_GIC_MIN; i <= PNX8550_INT_GIC_MAX; i++) {
  165. int gic_int_line = i - PNX8550_INT_GIC_MIN;
  166. if (gic_int_line == 0 )
  167. continue; // don't fiddle with int 0
  168. /*
  169. * enable change of TARGET, ENABLE and ACTIVE_LOW bits
  170. * set TARGET 0 to route through hw0 interrupt
  171. * set ACTIVE_LOW 0 active high (correct?)
  172. *
  173. * We really should setup an interrupt description table
  174. * to do this nicely.
  175. * Note, PCI INTA is active low on the bus, but inverted
  176. * in the GIC, so to us it's active high.
  177. */
  178. PNX8550_GIC_REQ(i - PNX8550_INT_GIC_MIN) = 0x1E000000;
  179. /* mask/priority is still 0 so we will not get any
  180. * interrupts until it is unmasked */
  181. set_irq_chip_and_handler(i, &level_irq_type, handle_level_irq);
  182. }
  183. /* Priority level 0 */
  184. PNX8550_GIC_PRIMASK_0 = PNX8550_GIC_PRIMASK_1 = 0;
  185. /* Set int vector table address */
  186. PNX8550_GIC_VECTOR_0 = PNX8550_GIC_VECTOR_1 = 0;
  187. set_irq_chip_and_handler(MIPS_CPU_GIC_IRQ, &level_irq_type,
  188. handle_level_irq);
  189. setup_irq(MIPS_CPU_GIC_IRQ, &gic_action);
  190. /* init of Timer interrupts */
  191. for (i = PNX8550_INT_TIMER_MIN; i <= PNX8550_INT_TIMER_MAX; i++)
  192. set_irq_chip_and_handler(i, &level_irq_type, handle_level_irq);
  193. /* Stop Timer 1-3 */
  194. configPR = read_c0_config7();
  195. configPR |= 0x00000038;
  196. write_c0_config7(configPR);
  197. set_irq_chip_and_handler(MIPS_CPU_TIMER_IRQ, &level_irq_type,
  198. handle_level_irq);
  199. setup_irq(MIPS_CPU_TIMER_IRQ, &timer_action);
  200. }
  201. EXPORT_SYMBOL(pnx8550_set_gic_priority);