irq.c 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370
  1. /*
  2. * Atheros AR71xx/AR724x/AR913x specific interrupt handling
  3. *
  4. * Copyright (C) 2010-2011 Jaiganesh Narayanan <jnarayanan@atheros.com>
  5. * Copyright (C) 2008-2011 Gabor Juhos <juhosg@openwrt.org>
  6. * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
  7. *
  8. * Parts of this file are based on Atheros' 2.6.15/2.6.31 BSP
  9. *
  10. * This program is free software; you can redistribute it and/or modify it
  11. * under the terms of the GNU General Public License version 2 as published
  12. * by the Free Software Foundation.
  13. */
  14. #include <linux/kernel.h>
  15. #include <linux/init.h>
  16. #include <linux/interrupt.h>
  17. #include <linux/irq.h>
  18. #include <asm/irq_cpu.h>
  19. #include <asm/mipsregs.h>
  20. #include <asm/mach-ath79/ath79.h>
  21. #include <asm/mach-ath79/ar71xx_regs.h>
  22. #include "common.h"
  23. static void (*ath79_ip2_handler)(void);
  24. static void (*ath79_ip3_handler)(void);
  25. static void ath79_misc_irq_handler(unsigned int irq, struct irq_desc *desc)
  26. {
  27. void __iomem *base = ath79_reset_base;
  28. u32 pending;
  29. pending = __raw_readl(base + AR71XX_RESET_REG_MISC_INT_STATUS) &
  30. __raw_readl(base + AR71XX_RESET_REG_MISC_INT_ENABLE);
  31. if (!pending) {
  32. spurious_interrupt();
  33. return;
  34. }
  35. while (pending) {
  36. int bit = __ffs(pending);
  37. generic_handle_irq(ATH79_MISC_IRQ(bit));
  38. pending &= ~BIT(bit);
  39. }
  40. }
  41. static void ar71xx_misc_irq_unmask(struct irq_data *d)
  42. {
  43. unsigned int irq = d->irq - ATH79_MISC_IRQ_BASE;
  44. void __iomem *base = ath79_reset_base;
  45. u32 t;
  46. t = __raw_readl(base + AR71XX_RESET_REG_MISC_INT_ENABLE);
  47. __raw_writel(t | (1 << irq), base + AR71XX_RESET_REG_MISC_INT_ENABLE);
  48. /* flush write */
  49. __raw_readl(base + AR71XX_RESET_REG_MISC_INT_ENABLE);
  50. }
  51. static void ar71xx_misc_irq_mask(struct irq_data *d)
  52. {
  53. unsigned int irq = d->irq - ATH79_MISC_IRQ_BASE;
  54. void __iomem *base = ath79_reset_base;
  55. u32 t;
  56. t = __raw_readl(base + AR71XX_RESET_REG_MISC_INT_ENABLE);
  57. __raw_writel(t & ~(1 << irq), base + AR71XX_RESET_REG_MISC_INT_ENABLE);
  58. /* flush write */
  59. __raw_readl(base + AR71XX_RESET_REG_MISC_INT_ENABLE);
  60. }
  61. static void ar724x_misc_irq_ack(struct irq_data *d)
  62. {
  63. unsigned int irq = d->irq - ATH79_MISC_IRQ_BASE;
  64. void __iomem *base = ath79_reset_base;
  65. u32 t;
  66. t = __raw_readl(base + AR71XX_RESET_REG_MISC_INT_STATUS);
  67. __raw_writel(t & ~(1 << irq), base + AR71XX_RESET_REG_MISC_INT_STATUS);
  68. /* flush write */
  69. __raw_readl(base + AR71XX_RESET_REG_MISC_INT_STATUS);
  70. }
  71. static struct irq_chip ath79_misc_irq_chip = {
  72. .name = "MISC",
  73. .irq_unmask = ar71xx_misc_irq_unmask,
  74. .irq_mask = ar71xx_misc_irq_mask,
  75. };
  76. static void __init ath79_misc_irq_init(void)
  77. {
  78. void __iomem *base = ath79_reset_base;
  79. int i;
  80. __raw_writel(0, base + AR71XX_RESET_REG_MISC_INT_ENABLE);
  81. __raw_writel(0, base + AR71XX_RESET_REG_MISC_INT_STATUS);
  82. if (soc_is_ar71xx() || soc_is_ar913x())
  83. ath79_misc_irq_chip.irq_mask_ack = ar71xx_misc_irq_mask;
  84. else if (soc_is_ar724x() ||
  85. soc_is_ar933x() ||
  86. soc_is_ar934x() ||
  87. soc_is_qca955x())
  88. ath79_misc_irq_chip.irq_ack = ar724x_misc_irq_ack;
  89. else
  90. BUG();
  91. for (i = ATH79_MISC_IRQ_BASE;
  92. i < ATH79_MISC_IRQ_BASE + ATH79_MISC_IRQ_COUNT; i++) {
  93. irq_set_chip_and_handler(i, &ath79_misc_irq_chip,
  94. handle_level_irq);
  95. }
  96. irq_set_chained_handler(ATH79_CPU_IRQ(6), ath79_misc_irq_handler);
  97. }
  98. static void ar934x_ip2_irq_dispatch(unsigned int irq, struct irq_desc *desc)
  99. {
  100. u32 status;
  101. disable_irq_nosync(irq);
  102. status = ath79_reset_rr(AR934X_RESET_REG_PCIE_WMAC_INT_STATUS);
  103. if (status & AR934X_PCIE_WMAC_INT_PCIE_ALL) {
  104. ath79_ddr_wb_flush(AR934X_DDR_REG_FLUSH_PCIE);
  105. generic_handle_irq(ATH79_IP2_IRQ(0));
  106. } else if (status & AR934X_PCIE_WMAC_INT_WMAC_ALL) {
  107. ath79_ddr_wb_flush(AR934X_DDR_REG_FLUSH_WMAC);
  108. generic_handle_irq(ATH79_IP2_IRQ(1));
  109. } else {
  110. spurious_interrupt();
  111. }
  112. enable_irq(irq);
  113. }
  114. static void ar934x_ip2_irq_init(void)
  115. {
  116. int i;
  117. for (i = ATH79_IP2_IRQ_BASE;
  118. i < ATH79_IP2_IRQ_BASE + ATH79_IP2_IRQ_COUNT; i++)
  119. irq_set_chip_and_handler(i, &dummy_irq_chip,
  120. handle_level_irq);
  121. irq_set_chained_handler(ATH79_CPU_IRQ(2), ar934x_ip2_irq_dispatch);
  122. }
  123. static void qca955x_ip2_irq_dispatch(unsigned int irq, struct irq_desc *desc)
  124. {
  125. u32 status;
  126. disable_irq_nosync(irq);
  127. status = ath79_reset_rr(QCA955X_RESET_REG_EXT_INT_STATUS);
  128. status &= QCA955X_EXT_INT_PCIE_RC1_ALL | QCA955X_EXT_INT_WMAC_ALL;
  129. if (status == 0) {
  130. spurious_interrupt();
  131. goto enable;
  132. }
  133. if (status & QCA955X_EXT_INT_PCIE_RC1_ALL) {
  134. /* TODO: flush DDR? */
  135. generic_handle_irq(ATH79_IP2_IRQ(0));
  136. }
  137. if (status & QCA955X_EXT_INT_WMAC_ALL) {
  138. /* TODO: flush DDR? */
  139. generic_handle_irq(ATH79_IP2_IRQ(1));
  140. }
  141. enable:
  142. enable_irq(irq);
  143. }
  144. static void qca955x_ip3_irq_dispatch(unsigned int irq, struct irq_desc *desc)
  145. {
  146. u32 status;
  147. disable_irq_nosync(irq);
  148. status = ath79_reset_rr(QCA955X_RESET_REG_EXT_INT_STATUS);
  149. status &= QCA955X_EXT_INT_PCIE_RC2_ALL |
  150. QCA955X_EXT_INT_USB1 |
  151. QCA955X_EXT_INT_USB2;
  152. if (status == 0) {
  153. spurious_interrupt();
  154. goto enable;
  155. }
  156. if (status & QCA955X_EXT_INT_USB1) {
  157. /* TODO: flush DDR? */
  158. generic_handle_irq(ATH79_IP3_IRQ(0));
  159. }
  160. if (status & QCA955X_EXT_INT_USB2) {
  161. /* TODO: flush DDR? */
  162. generic_handle_irq(ATH79_IP3_IRQ(1));
  163. }
  164. if (status & QCA955X_EXT_INT_PCIE_RC2_ALL) {
  165. /* TODO: flush DDR? */
  166. generic_handle_irq(ATH79_IP3_IRQ(2));
  167. }
  168. enable:
  169. enable_irq(irq);
  170. }
  171. static void qca955x_irq_init(void)
  172. {
  173. int i;
  174. for (i = ATH79_IP2_IRQ_BASE;
  175. i < ATH79_IP2_IRQ_BASE + ATH79_IP2_IRQ_COUNT; i++)
  176. irq_set_chip_and_handler(i, &dummy_irq_chip,
  177. handle_level_irq);
  178. irq_set_chained_handler(ATH79_CPU_IRQ(2), qca955x_ip2_irq_dispatch);
  179. for (i = ATH79_IP3_IRQ_BASE;
  180. i < ATH79_IP3_IRQ_BASE + ATH79_IP3_IRQ_COUNT; i++)
  181. irq_set_chip_and_handler(i, &dummy_irq_chip,
  182. handle_level_irq);
  183. irq_set_chained_handler(ATH79_CPU_IRQ(3), qca955x_ip3_irq_dispatch);
  184. }
  185. asmlinkage void plat_irq_dispatch(void)
  186. {
  187. unsigned long pending;
  188. pending = read_c0_status() & read_c0_cause() & ST0_IM;
  189. if (pending & STATUSF_IP7)
  190. do_IRQ(ATH79_CPU_IRQ(7));
  191. else if (pending & STATUSF_IP2)
  192. ath79_ip2_handler();
  193. else if (pending & STATUSF_IP4)
  194. do_IRQ(ATH79_CPU_IRQ(4));
  195. else if (pending & STATUSF_IP5)
  196. do_IRQ(ATH79_CPU_IRQ(5));
  197. else if (pending & STATUSF_IP3)
  198. ath79_ip3_handler();
  199. else if (pending & STATUSF_IP6)
  200. do_IRQ(ATH79_CPU_IRQ(6));
  201. else
  202. spurious_interrupt();
  203. }
  204. /*
  205. * The IP2/IP3 lines are tied to a PCI/WMAC/USB device. Drivers for
  206. * these devices typically allocate coherent DMA memory, however the
  207. * DMA controller may still have some unsynchronized data in the FIFO.
  208. * Issue a flush in the handlers to ensure that the driver sees
  209. * the update.
  210. */
  211. static void ath79_default_ip2_handler(void)
  212. {
  213. do_IRQ(ATH79_CPU_IRQ(2));
  214. }
  215. static void ath79_default_ip3_handler(void)
  216. {
  217. do_IRQ(ATH79_CPU_IRQ(3));
  218. }
  219. static void ar71xx_ip2_handler(void)
  220. {
  221. ath79_ddr_wb_flush(AR71XX_DDR_REG_FLUSH_PCI);
  222. do_IRQ(ATH79_CPU_IRQ(2));
  223. }
  224. static void ar724x_ip2_handler(void)
  225. {
  226. ath79_ddr_wb_flush(AR724X_DDR_REG_FLUSH_PCIE);
  227. do_IRQ(ATH79_CPU_IRQ(2));
  228. }
  229. static void ar913x_ip2_handler(void)
  230. {
  231. ath79_ddr_wb_flush(AR913X_DDR_REG_FLUSH_WMAC);
  232. do_IRQ(ATH79_CPU_IRQ(2));
  233. }
  234. static void ar933x_ip2_handler(void)
  235. {
  236. ath79_ddr_wb_flush(AR933X_DDR_REG_FLUSH_WMAC);
  237. do_IRQ(ATH79_CPU_IRQ(2));
  238. }
  239. static void ar71xx_ip3_handler(void)
  240. {
  241. ath79_ddr_wb_flush(AR71XX_DDR_REG_FLUSH_USB);
  242. do_IRQ(ATH79_CPU_IRQ(3));
  243. }
  244. static void ar724x_ip3_handler(void)
  245. {
  246. ath79_ddr_wb_flush(AR724X_DDR_REG_FLUSH_USB);
  247. do_IRQ(ATH79_CPU_IRQ(3));
  248. }
  249. static void ar913x_ip3_handler(void)
  250. {
  251. ath79_ddr_wb_flush(AR913X_DDR_REG_FLUSH_USB);
  252. do_IRQ(ATH79_CPU_IRQ(3));
  253. }
  254. static void ar933x_ip3_handler(void)
  255. {
  256. ath79_ddr_wb_flush(AR933X_DDR_REG_FLUSH_USB);
  257. do_IRQ(ATH79_CPU_IRQ(3));
  258. }
  259. static void ar934x_ip3_handler(void)
  260. {
  261. ath79_ddr_wb_flush(AR934X_DDR_REG_FLUSH_USB);
  262. do_IRQ(ATH79_CPU_IRQ(3));
  263. }
  264. void __init arch_init_irq(void)
  265. {
  266. if (soc_is_ar71xx()) {
  267. ath79_ip2_handler = ar71xx_ip2_handler;
  268. ath79_ip3_handler = ar71xx_ip3_handler;
  269. } else if (soc_is_ar724x()) {
  270. ath79_ip2_handler = ar724x_ip2_handler;
  271. ath79_ip3_handler = ar724x_ip3_handler;
  272. } else if (soc_is_ar913x()) {
  273. ath79_ip2_handler = ar913x_ip2_handler;
  274. ath79_ip3_handler = ar913x_ip3_handler;
  275. } else if (soc_is_ar933x()) {
  276. ath79_ip2_handler = ar933x_ip2_handler;
  277. ath79_ip3_handler = ar933x_ip3_handler;
  278. } else if (soc_is_ar934x()) {
  279. ath79_ip2_handler = ath79_default_ip2_handler;
  280. ath79_ip3_handler = ar934x_ip3_handler;
  281. } else if (soc_is_qca955x()) {
  282. ath79_ip2_handler = ath79_default_ip2_handler;
  283. ath79_ip3_handler = ath79_default_ip3_handler;
  284. } else {
  285. BUG();
  286. }
  287. cp0_perfcount_irq = ATH79_MISC_IRQ(5);
  288. mips_cpu_irq_init();
  289. ath79_misc_irq_init();
  290. if (soc_is_ar934x())
  291. ar934x_ip2_irq_init();
  292. else if (soc_is_qca955x())
  293. qca955x_irq_init();
  294. }