irq.c 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340
  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. static void __dispatch_internal(void) __maybe_unused;
  21. #ifndef BCMCPU_RUNTIME_DETECT
  22. #ifdef CONFIG_BCM63XX_CPU_6338
  23. #define irq_stat_reg PERF_IRQSTAT_6338_REG
  24. #define irq_mask_reg PERF_IRQMASK_6338_REG
  25. #define is_ext_irq_cascaded 0
  26. #define ext_irq_start 0
  27. #define ext_irq_end 0
  28. #endif
  29. #ifdef CONFIG_BCM63XX_CPU_6345
  30. #define irq_stat_reg PERF_IRQSTAT_6345_REG
  31. #define irq_mask_reg PERF_IRQMASK_6345_REG
  32. #define is_ext_irq_cascaded 0
  33. #define ext_irq_start 0
  34. #define ext_irq_end 0
  35. #endif
  36. #ifdef CONFIG_BCM63XX_CPU_6348
  37. #define irq_stat_reg PERF_IRQSTAT_6348_REG
  38. #define irq_mask_reg PERF_IRQMASK_6348_REG
  39. #define dispatch_internal __dispatch_internal
  40. #define is_ext_irq_cascaded 0
  41. #define ext_irq_start 0
  42. #define ext_irq_end 0
  43. #endif
  44. #ifdef CONFIG_BCM63XX_CPU_6358
  45. #define irq_stat_reg PERF_IRQSTAT_6358_REG
  46. #define irq_mask_reg PERF_IRQMASK_6358_REG
  47. #define dispatch_internal __dispatch_internal
  48. #define is_ext_irq_cascaded 1
  49. #define ext_irq_start (BCM_6358_EXT_IRQ0 - IRQ_INTERNAL_BASE)
  50. #define ext_irq_end (BCM_6358_EXT_IRQ3 - IRQ_INTERNAL_BASE)
  51. #endif
  52. #define dispatch_internal __dispatch_internal
  53. #define irq_stat_addr (bcm63xx_regset_address(RSET_PERF) + irq_stat_reg)
  54. #define irq_mask_addr (bcm63xx_regset_address(RSET_PERF) + irq_mask_reg)
  55. static inline void bcm63xx_init_irq(void)
  56. {
  57. }
  58. #else /* ! BCMCPU_RUNTIME_DETECT */
  59. static u32 irq_stat_addr, irq_mask_addr;
  60. static void (*dispatch_internal)(void);
  61. static int is_ext_irq_cascaded;
  62. static unsigned int ext_irq_start, ext_irq_end;
  63. static void bcm63xx_init_irq(void)
  64. {
  65. irq_stat_addr = bcm63xx_regset_address(RSET_PERF);
  66. irq_mask_addr = bcm63xx_regset_address(RSET_PERF);
  67. switch (bcm63xx_get_cpu_id()) {
  68. case BCM6338_CPU_ID:
  69. irq_stat_addr += PERF_IRQSTAT_6338_REG;
  70. irq_mask_addr += PERF_IRQMASK_6338_REG;
  71. break;
  72. case BCM6345_CPU_ID:
  73. irq_stat_addr += PERF_IRQSTAT_6345_REG;
  74. irq_mask_addr += PERF_IRQMASK_6345_REG;
  75. break;
  76. case BCM6348_CPU_ID:
  77. irq_stat_addr += PERF_IRQSTAT_6348_REG;
  78. irq_mask_addr += PERF_IRQMASK_6348_REG;
  79. break;
  80. case BCM6358_CPU_ID:
  81. irq_stat_addr += PERF_IRQSTAT_6358_REG;
  82. irq_mask_addr += PERF_IRQMASK_6358_REG;
  83. is_ext_irq_cascaded = 1;
  84. ext_irq_start = BCM_6358_EXT_IRQ0 - IRQ_INTERNAL_BASE;
  85. ext_irq_end = BCM_6358_EXT_IRQ3 - IRQ_INTERNAL_BASE;
  86. break;
  87. default:
  88. BUG();
  89. }
  90. dispatch_internal = __dispatch_internal;
  91. }
  92. #endif /* ! BCMCPU_RUNTIME_DETECT */
  93. static inline void handle_internal(int intbit)
  94. {
  95. if (is_ext_irq_cascaded &&
  96. intbit >= ext_irq_start && intbit <= ext_irq_end)
  97. do_IRQ(intbit - ext_irq_start + IRQ_EXTERNAL_BASE);
  98. else
  99. do_IRQ(intbit + IRQ_INTERNAL_BASE);
  100. }
  101. /*
  102. * dispatch internal devices IRQ (uart, enet, watchdog, ...). do not
  103. * prioritize any interrupt relatively to another. the static counter
  104. * will resume the loop where it ended the last time we left this
  105. * function.
  106. */
  107. static void __dispatch_internal(void)
  108. {
  109. u32 pending;
  110. static int i;
  111. pending = bcm_readl(irq_stat_addr) & bcm_readl(irq_mask_addr);
  112. if (!pending)
  113. return ;
  114. while (1) {
  115. int to_call = i;
  116. i = (i + 1) & 0x1f;
  117. if (pending & (1 << to_call)) {
  118. handle_internal(to_call);
  119. break;
  120. }
  121. }
  122. }
  123. asmlinkage void plat_irq_dispatch(void)
  124. {
  125. u32 cause;
  126. do {
  127. cause = read_c0_cause() & read_c0_status() & ST0_IM;
  128. if (!cause)
  129. break;
  130. if (cause & CAUSEF_IP7)
  131. do_IRQ(7);
  132. if (cause & CAUSEF_IP2)
  133. dispatch_internal();
  134. if (!is_ext_irq_cascaded) {
  135. if (cause & CAUSEF_IP3)
  136. do_IRQ(IRQ_EXT_0);
  137. if (cause & CAUSEF_IP4)
  138. do_IRQ(IRQ_EXT_1);
  139. if (cause & CAUSEF_IP5)
  140. do_IRQ(IRQ_EXT_2);
  141. if (cause & CAUSEF_IP6)
  142. do_IRQ(IRQ_EXT_3);
  143. }
  144. } while (1);
  145. }
  146. /*
  147. * internal IRQs operations: only mask/unmask on PERF irq mask
  148. * register.
  149. */
  150. static void internal_irq_mask(unsigned int irq)
  151. {
  152. u32 mask;
  153. mask = bcm_readl(irq_mask_addr);
  154. mask &= ~(1 << irq);
  155. bcm_writel(mask, irq_mask_addr);
  156. }
  157. static void internal_irq_unmask(unsigned int irq)
  158. {
  159. u32 mask;
  160. mask = bcm_readl(irq_mask_addr);
  161. mask |= (1 << irq);
  162. bcm_writel(mask, irq_mask_addr);
  163. }
  164. static void bcm63xx_internal_irq_mask(struct irq_data *d)
  165. {
  166. internal_irq_mask(d->irq - IRQ_INTERNAL_BASE);
  167. }
  168. static void bcm63xx_internal_irq_unmask(struct irq_data *d)
  169. {
  170. internal_irq_unmask(d->irq - IRQ_INTERNAL_BASE);
  171. }
  172. /*
  173. * external IRQs operations: mask/unmask and clear on PERF external
  174. * irq control register.
  175. */
  176. static void bcm63xx_external_irq_mask(struct irq_data *d)
  177. {
  178. unsigned int irq = d->irq - IRQ_EXTERNAL_BASE;
  179. u32 reg;
  180. reg = bcm_perf_readl(PERF_EXTIRQ_CFG_REG);
  181. reg &= ~EXTIRQ_CFG_MASK(irq);
  182. bcm_perf_writel(reg, PERF_EXTIRQ_CFG_REG);
  183. if (is_ext_irq_cascaded)
  184. internal_irq_mask(irq + ext_irq_start);
  185. }
  186. static void bcm63xx_external_irq_unmask(struct irq_data *d)
  187. {
  188. unsigned int irq = d->irq - IRQ_EXTERNAL_BASE;
  189. u32 reg;
  190. reg = bcm_perf_readl(PERF_EXTIRQ_CFG_REG);
  191. reg |= EXTIRQ_CFG_MASK(irq);
  192. bcm_perf_writel(reg, PERF_EXTIRQ_CFG_REG);
  193. if (is_ext_irq_cascaded)
  194. internal_irq_unmask(irq + ext_irq_start);
  195. }
  196. static void bcm63xx_external_irq_clear(struct irq_data *d)
  197. {
  198. unsigned int irq = d->irq - IRQ_EXTERNAL_BASE;
  199. u32 reg;
  200. reg = bcm_perf_readl(PERF_EXTIRQ_CFG_REG);
  201. reg |= EXTIRQ_CFG_CLEAR(irq);
  202. bcm_perf_writel(reg, PERF_EXTIRQ_CFG_REG);
  203. }
  204. static int bcm63xx_external_irq_set_type(struct irq_data *d,
  205. unsigned int flow_type)
  206. {
  207. unsigned int irq = d->irq - IRQ_EXTERNAL_BASE;
  208. u32 reg;
  209. flow_type &= IRQ_TYPE_SENSE_MASK;
  210. if (flow_type == IRQ_TYPE_NONE)
  211. flow_type = IRQ_TYPE_LEVEL_LOW;
  212. reg = bcm_perf_readl(PERF_EXTIRQ_CFG_REG);
  213. switch (flow_type) {
  214. case IRQ_TYPE_EDGE_BOTH:
  215. reg &= ~EXTIRQ_CFG_LEVELSENSE(irq);
  216. reg |= EXTIRQ_CFG_BOTHEDGE(irq);
  217. break;
  218. case IRQ_TYPE_EDGE_RISING:
  219. reg &= ~EXTIRQ_CFG_LEVELSENSE(irq);
  220. reg |= EXTIRQ_CFG_SENSE(irq);
  221. reg &= ~EXTIRQ_CFG_BOTHEDGE(irq);
  222. break;
  223. case IRQ_TYPE_EDGE_FALLING:
  224. reg &= ~EXTIRQ_CFG_LEVELSENSE(irq);
  225. reg &= ~EXTIRQ_CFG_SENSE(irq);
  226. reg &= ~EXTIRQ_CFG_BOTHEDGE(irq);
  227. break;
  228. case IRQ_TYPE_LEVEL_HIGH:
  229. reg |= EXTIRQ_CFG_LEVELSENSE(irq);
  230. reg |= EXTIRQ_CFG_SENSE(irq);
  231. break;
  232. case IRQ_TYPE_LEVEL_LOW:
  233. reg |= EXTIRQ_CFG_LEVELSENSE(irq);
  234. reg &= ~EXTIRQ_CFG_SENSE(irq);
  235. break;
  236. default:
  237. printk(KERN_ERR "bogus flow type combination given !\n");
  238. return -EINVAL;
  239. }
  240. bcm_perf_writel(reg, PERF_EXTIRQ_CFG_REG);
  241. irqd_set_trigger_type(d, flow_type);
  242. if (flow_type & (IRQ_TYPE_LEVEL_LOW | IRQ_TYPE_LEVEL_HIGH))
  243. __irq_set_handler_locked(d->irq, handle_level_irq);
  244. else
  245. __irq_set_handler_locked(d->irq, handle_edge_irq);
  246. return IRQ_SET_MASK_OK_NOCOPY;
  247. }
  248. static struct irq_chip bcm63xx_internal_irq_chip = {
  249. .name = "bcm63xx_ipic",
  250. .irq_mask = bcm63xx_internal_irq_mask,
  251. .irq_unmask = bcm63xx_internal_irq_unmask,
  252. };
  253. static struct irq_chip bcm63xx_external_irq_chip = {
  254. .name = "bcm63xx_epic",
  255. .irq_ack = bcm63xx_external_irq_clear,
  256. .irq_mask = bcm63xx_external_irq_mask,
  257. .irq_unmask = bcm63xx_external_irq_unmask,
  258. .irq_set_type = bcm63xx_external_irq_set_type,
  259. };
  260. static struct irqaction cpu_ip2_cascade_action = {
  261. .handler = no_action,
  262. .name = "cascade_ip2",
  263. .flags = IRQF_NO_THREAD,
  264. };
  265. static struct irqaction cpu_ext_cascade_action = {
  266. .handler = no_action,
  267. .name = "cascade_extirq",
  268. .flags = IRQF_NO_THREAD,
  269. };
  270. void __init arch_init_irq(void)
  271. {
  272. int i;
  273. bcm63xx_init_irq();
  274. mips_cpu_irq_init();
  275. for (i = IRQ_INTERNAL_BASE; i < NR_IRQS; ++i)
  276. irq_set_chip_and_handler(i, &bcm63xx_internal_irq_chip,
  277. handle_level_irq);
  278. for (i = IRQ_EXTERNAL_BASE; i < IRQ_EXTERNAL_BASE + 4; ++i)
  279. irq_set_chip_and_handler(i, &bcm63xx_external_irq_chip,
  280. handle_edge_irq);
  281. if (!is_ext_irq_cascaded) {
  282. for (i = 3; i < 7; ++i)
  283. setup_irq(MIPS_CPU_IRQ_BASE + i, &cpu_ext_cascade_action);
  284. }
  285. setup_irq(MIPS_CPU_IRQ_BASE + 2, &cpu_ip2_cascade_action);
  286. }