irq.c 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  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(struct irq_data *d)
  69. {
  70. unsigned int irq = d->irq - IRQ_INTERNAL_BASE;
  71. u32 mask;
  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(struct irq_data *d)
  77. {
  78. unsigned int irq = d->irq - IRQ_INTERNAL_BASE;
  79. u32 mask;
  80. mask = bcm_perf_readl(PERF_IRQMASK_REG);
  81. mask |= (1 << irq);
  82. bcm_perf_writel(mask, PERF_IRQMASK_REG);
  83. }
  84. /*
  85. * external IRQs operations: mask/unmask and clear on PERF external
  86. * irq control register.
  87. */
  88. static void bcm63xx_external_irq_mask(struct irq_data *d)
  89. {
  90. unsigned int irq = d->irq - IRQ_EXT_BASE;
  91. u32 reg;
  92. reg = bcm_perf_readl(PERF_EXTIRQ_CFG_REG);
  93. reg &= ~EXTIRQ_CFG_MASK(irq);
  94. bcm_perf_writel(reg, PERF_EXTIRQ_CFG_REG);
  95. }
  96. static void bcm63xx_external_irq_unmask(struct irq_data *d)
  97. {
  98. unsigned int irq = d->irq - IRQ_EXT_BASE;
  99. u32 reg;
  100. reg = bcm_perf_readl(PERF_EXTIRQ_CFG_REG);
  101. reg |= EXTIRQ_CFG_MASK(irq);
  102. bcm_perf_writel(reg, PERF_EXTIRQ_CFG_REG);
  103. }
  104. static void bcm63xx_external_irq_clear(struct irq_data *d)
  105. {
  106. unsigned int irq = d->irq - IRQ_EXT_BASE;
  107. u32 reg;
  108. reg = bcm_perf_readl(PERF_EXTIRQ_CFG_REG);
  109. reg |= EXTIRQ_CFG_CLEAR(irq);
  110. bcm_perf_writel(reg, PERF_EXTIRQ_CFG_REG);
  111. }
  112. static unsigned int bcm63xx_external_irq_startup(struct irq_data *d)
  113. {
  114. set_c0_status(0x100 << (d->irq - IRQ_MIPS_BASE));
  115. irq_enable_hazard();
  116. bcm63xx_external_irq_unmask(d);
  117. return 0;
  118. }
  119. static void bcm63xx_external_irq_shutdown(struct irq_data *d)
  120. {
  121. bcm63xx_external_irq_mask(d);
  122. clear_c0_status(0x100 << (d->irq - IRQ_MIPS_BASE));
  123. irq_disable_hazard();
  124. }
  125. static int bcm63xx_external_irq_set_type(struct irq_data *d,
  126. unsigned int flow_type)
  127. {
  128. unsigned int irq = d->irq - IRQ_EXT_BASE;
  129. u32 reg;
  130. flow_type &= IRQ_TYPE_SENSE_MASK;
  131. if (flow_type == IRQ_TYPE_NONE)
  132. flow_type = IRQ_TYPE_LEVEL_LOW;
  133. reg = bcm_perf_readl(PERF_EXTIRQ_CFG_REG);
  134. switch (flow_type) {
  135. case IRQ_TYPE_EDGE_BOTH:
  136. reg &= ~EXTIRQ_CFG_LEVELSENSE(irq);
  137. reg |= EXTIRQ_CFG_BOTHEDGE(irq);
  138. break;
  139. case IRQ_TYPE_EDGE_RISING:
  140. reg &= ~EXTIRQ_CFG_LEVELSENSE(irq);
  141. reg |= EXTIRQ_CFG_SENSE(irq);
  142. reg &= ~EXTIRQ_CFG_BOTHEDGE(irq);
  143. break;
  144. case IRQ_TYPE_EDGE_FALLING:
  145. reg &= ~EXTIRQ_CFG_LEVELSENSE(irq);
  146. reg &= ~EXTIRQ_CFG_SENSE(irq);
  147. reg &= ~EXTIRQ_CFG_BOTHEDGE(irq);
  148. break;
  149. case IRQ_TYPE_LEVEL_HIGH:
  150. reg |= EXTIRQ_CFG_LEVELSENSE(irq);
  151. reg |= EXTIRQ_CFG_SENSE(irq);
  152. break;
  153. case IRQ_TYPE_LEVEL_LOW:
  154. reg |= EXTIRQ_CFG_LEVELSENSE(irq);
  155. reg &= ~EXTIRQ_CFG_SENSE(irq);
  156. break;
  157. default:
  158. printk(KERN_ERR "bogus flow type combination given !\n");
  159. return -EINVAL;
  160. }
  161. bcm_perf_writel(reg, PERF_EXTIRQ_CFG_REG);
  162. irqd_set_trigger_type(d, flow_type);
  163. if (flow_type & (IRQ_TYPE_LEVEL_LOW | IRQ_TYPE_LEVEL_HIGH))
  164. __irq_set_handler_locked(d->irq, handle_level_irq);
  165. else
  166. __irq_set_handler_locked(d->irq, handle_edge_irq);
  167. return IRQ_SET_MASK_OK_NOCOPY;
  168. }
  169. static struct irq_chip bcm63xx_internal_irq_chip = {
  170. .name = "bcm63xx_ipic",
  171. .irq_mask = bcm63xx_internal_irq_mask,
  172. .irq_unmask = bcm63xx_internal_irq_unmask,
  173. };
  174. static struct irq_chip bcm63xx_external_irq_chip = {
  175. .name = "bcm63xx_epic",
  176. .irq_startup = bcm63xx_external_irq_startup,
  177. .irq_shutdown = bcm63xx_external_irq_shutdown,
  178. .irq_ack = bcm63xx_external_irq_clear,
  179. .irq_mask = bcm63xx_external_irq_mask,
  180. .irq_unmask = bcm63xx_external_irq_unmask,
  181. .irq_set_type = bcm63xx_external_irq_set_type,
  182. };
  183. static struct irqaction cpu_ip2_cascade_action = {
  184. .handler = no_action,
  185. .name = "cascade_ip2",
  186. };
  187. void __init arch_init_irq(void)
  188. {
  189. int i;
  190. mips_cpu_irq_init();
  191. for (i = IRQ_INTERNAL_BASE; i < NR_IRQS; ++i)
  192. irq_set_chip_and_handler(i, &bcm63xx_internal_irq_chip,
  193. handle_level_irq);
  194. for (i = IRQ_EXT_BASE; i < IRQ_EXT_BASE + 4; ++i)
  195. irq_set_chip_and_handler(i, &bcm63xx_external_irq_chip,
  196. handle_edge_irq);
  197. setup_irq(IRQ_MIPS_BASE + 2, &cpu_ip2_cascade_action);
  198. }