irq.c 5.6 KB

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