irq.c 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. /*
  2. * This file is subject to the terms and conditions of the GNU General Public
  3. * License. See the file "COPYING" in the main directory of this archive
  4. * for more details.
  5. *
  6. * Copyright (C) 2008 Maxime Bizon <mbizon@freebox.fr>
  7. * Copyright (C) 2008 Nicolas Schichan <nschichan@freebox.fr>
  8. */
  9. #include <linux/kernel.h>
  10. #include <linux/init.h>
  11. #include <linux/interrupt.h>
  12. #include <linux/module.h>
  13. #include <asm/irq_cpu.h>
  14. #include <asm/mipsregs.h>
  15. #include <bcm63xx_cpu.h>
  16. #include <bcm63xx_regs.h>
  17. #include <bcm63xx_io.h>
  18. #include <bcm63xx_irq.h>
  19. /*
  20. * dispatch internal devices IRQ (uart, enet, watchdog, ...). do not
  21. * prioritize any interrupt relatively to another. the static counter
  22. * will resume the loop where it ended the last time we left this
  23. * function.
  24. */
  25. static void bcm63xx_irq_dispatch_internal(void)
  26. {
  27. u32 pending;
  28. static int i;
  29. pending = bcm_perf_readl(PERF_IRQMASK_REG) &
  30. bcm_perf_readl(PERF_IRQSTAT_REG);
  31. if (!pending)
  32. return ;
  33. while (1) {
  34. int to_call = i;
  35. i = (i + 1) & 0x1f;
  36. if (pending & (1 << to_call)) {
  37. do_IRQ(to_call + IRQ_INTERNAL_BASE);
  38. break;
  39. }
  40. }
  41. }
  42. asmlinkage void plat_irq_dispatch(void)
  43. {
  44. u32 cause;
  45. do {
  46. cause = read_c0_cause() & read_c0_status() & ST0_IM;
  47. if (!cause)
  48. break;
  49. if (cause & CAUSEF_IP7)
  50. do_IRQ(7);
  51. if (cause & CAUSEF_IP2)
  52. bcm63xx_irq_dispatch_internal();
  53. if (cause & CAUSEF_IP3)
  54. do_IRQ(IRQ_EXT_0);
  55. if (cause & CAUSEF_IP4)
  56. do_IRQ(IRQ_EXT_1);
  57. if (cause & CAUSEF_IP5)
  58. do_IRQ(IRQ_EXT_2);
  59. if (cause & CAUSEF_IP6)
  60. do_IRQ(IRQ_EXT_3);
  61. } while (1);
  62. }
  63. /*
  64. * internal IRQs operations: only mask/unmask on PERF irq mask
  65. * register.
  66. */
  67. static inline void bcm63xx_internal_irq_mask(unsigned int irq)
  68. {
  69. u32 mask;
  70. irq -= IRQ_INTERNAL_BASE;
  71. mask = bcm_perf_readl(PERF_IRQMASK_REG);
  72. mask &= ~(1 << irq);
  73. bcm_perf_writel(mask, PERF_IRQMASK_REG);
  74. }
  75. static void bcm63xx_internal_irq_unmask(unsigned int irq)
  76. {
  77. u32 mask;
  78. irq -= IRQ_INTERNAL_BASE;
  79. mask = bcm_perf_readl(PERF_IRQMASK_REG);
  80. mask |= (1 << irq);
  81. bcm_perf_writel(mask, PERF_IRQMASK_REG);
  82. }
  83. static unsigned int bcm63xx_internal_irq_startup(unsigned int irq)
  84. {
  85. bcm63xx_internal_irq_unmask(irq);
  86. return 0;
  87. }
  88. /*
  89. * external IRQs operations: mask/unmask and clear on PERF external
  90. * irq control register.
  91. */
  92. static void bcm63xx_external_irq_mask(unsigned int irq)
  93. {
  94. u32 reg;
  95. irq -= IRQ_EXT_BASE;
  96. reg = bcm_perf_readl(PERF_EXTIRQ_CFG_REG);
  97. reg &= ~EXTIRQ_CFG_MASK(irq);
  98. bcm_perf_writel(reg, PERF_EXTIRQ_CFG_REG);
  99. }
  100. static void bcm63xx_external_irq_unmask(unsigned int irq)
  101. {
  102. u32 reg;
  103. irq -= IRQ_EXT_BASE;
  104. reg = bcm_perf_readl(PERF_EXTIRQ_CFG_REG);
  105. reg |= EXTIRQ_CFG_MASK(irq);
  106. bcm_perf_writel(reg, PERF_EXTIRQ_CFG_REG);
  107. }
  108. static void bcm63xx_external_irq_clear(unsigned int irq)
  109. {
  110. u32 reg;
  111. irq -= IRQ_EXT_BASE;
  112. reg = bcm_perf_readl(PERF_EXTIRQ_CFG_REG);
  113. reg |= EXTIRQ_CFG_CLEAR(irq);
  114. bcm_perf_writel(reg, PERF_EXTIRQ_CFG_REG);
  115. }
  116. static unsigned int bcm63xx_external_irq_startup(unsigned int irq)
  117. {
  118. set_c0_status(0x100 << (irq - IRQ_MIPS_BASE));
  119. irq_enable_hazard();
  120. bcm63xx_external_irq_unmask(irq);
  121. return 0;
  122. }
  123. static void bcm63xx_external_irq_shutdown(unsigned int irq)
  124. {
  125. bcm63xx_external_irq_mask(irq);
  126. clear_c0_status(0x100 << (irq - IRQ_MIPS_BASE));
  127. irq_disable_hazard();
  128. }
  129. static int bcm63xx_external_irq_set_type(unsigned int irq,
  130. unsigned int flow_type)
  131. {
  132. u32 reg;
  133. struct irq_desc *desc = irq_desc + irq;
  134. irq -= IRQ_EXT_BASE;
  135. flow_type &= IRQ_TYPE_SENSE_MASK;
  136. if (flow_type == IRQ_TYPE_NONE)
  137. flow_type = IRQ_TYPE_LEVEL_LOW;
  138. reg = bcm_perf_readl(PERF_EXTIRQ_CFG_REG);
  139. switch (flow_type) {
  140. case IRQ_TYPE_EDGE_BOTH:
  141. reg &= ~EXTIRQ_CFG_LEVELSENSE(irq);
  142. reg |= EXTIRQ_CFG_BOTHEDGE(irq);
  143. break;
  144. case IRQ_TYPE_EDGE_RISING:
  145. reg &= ~EXTIRQ_CFG_LEVELSENSE(irq);
  146. reg |= EXTIRQ_CFG_SENSE(irq);
  147. reg &= ~EXTIRQ_CFG_BOTHEDGE(irq);
  148. break;
  149. case IRQ_TYPE_EDGE_FALLING:
  150. reg &= ~EXTIRQ_CFG_LEVELSENSE(irq);
  151. reg &= ~EXTIRQ_CFG_SENSE(irq);
  152. reg &= ~EXTIRQ_CFG_BOTHEDGE(irq);
  153. break;
  154. case IRQ_TYPE_LEVEL_HIGH:
  155. reg |= EXTIRQ_CFG_LEVELSENSE(irq);
  156. reg |= EXTIRQ_CFG_SENSE(irq);
  157. break;
  158. case IRQ_TYPE_LEVEL_LOW:
  159. reg |= EXTIRQ_CFG_LEVELSENSE(irq);
  160. reg &= ~EXTIRQ_CFG_SENSE(irq);
  161. break;
  162. default:
  163. printk(KERN_ERR "bogus flow type combination given !\n");
  164. return -EINVAL;
  165. }
  166. bcm_perf_writel(reg, PERF_EXTIRQ_CFG_REG);
  167. if (flow_type & (IRQ_TYPE_LEVEL_LOW | IRQ_TYPE_LEVEL_HIGH)) {
  168. desc->status |= IRQ_LEVEL;
  169. desc->handle_irq = handle_level_irq;
  170. } else {
  171. desc->handle_irq = handle_edge_irq;
  172. }
  173. return 0;
  174. }
  175. static struct irq_chip bcm63xx_internal_irq_chip = {
  176. .name = "bcm63xx_ipic",
  177. .startup = bcm63xx_internal_irq_startup,
  178. .shutdown = bcm63xx_internal_irq_mask,
  179. .mask = bcm63xx_internal_irq_mask,
  180. .mask_ack = bcm63xx_internal_irq_mask,
  181. .unmask = bcm63xx_internal_irq_unmask,
  182. };
  183. static struct irq_chip bcm63xx_external_irq_chip = {
  184. .name = "bcm63xx_epic",
  185. .startup = bcm63xx_external_irq_startup,
  186. .shutdown = bcm63xx_external_irq_shutdown,
  187. .ack = bcm63xx_external_irq_clear,
  188. .mask = bcm63xx_external_irq_mask,
  189. .unmask = bcm63xx_external_irq_unmask,
  190. .set_type = bcm63xx_external_irq_set_type,
  191. };
  192. static struct irqaction cpu_ip2_cascade_action = {
  193. .handler = no_action,
  194. .name = "cascade_ip2",
  195. };
  196. void __init arch_init_irq(void)
  197. {
  198. int i;
  199. mips_cpu_irq_init();
  200. for (i = IRQ_INTERNAL_BASE; i < NR_IRQS; ++i)
  201. set_irq_chip_and_handler(i, &bcm63xx_internal_irq_chip,
  202. handle_level_irq);
  203. for (i = IRQ_EXT_BASE; i < IRQ_EXT_BASE + 4; ++i)
  204. set_irq_chip_and_handler(i, &bcm63xx_external_irq_chip,
  205. handle_edge_irq);
  206. setup_irq(IRQ_MIPS_BASE + 2, &cpu_ip2_cascade_action);
  207. }