irq.c 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376
  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/irqchip.h>
  18. #include <linux/of_irq.h>
  19. #include <asm/irq_cpu.h>
  20. #include <asm/mipsregs.h>
  21. #include <asm/mach-ath79/ath79.h>
  22. #include <asm/mach-ath79/ar71xx_regs.h>
  23. #include "common.h"
  24. #include "machtypes.h"
  25. static void ath79_misc_irq_handler(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(struct irq_desc *desc)
  99. {
  100. u32 status;
  101. status = ath79_reset_rr(AR934X_RESET_REG_PCIE_WMAC_INT_STATUS);
  102. if (status & AR934X_PCIE_WMAC_INT_PCIE_ALL) {
  103. ath79_ddr_wb_flush(3);
  104. generic_handle_irq(ATH79_IP2_IRQ(0));
  105. } else if (status & AR934X_PCIE_WMAC_INT_WMAC_ALL) {
  106. ath79_ddr_wb_flush(4);
  107. generic_handle_irq(ATH79_IP2_IRQ(1));
  108. } else {
  109. spurious_interrupt();
  110. }
  111. }
  112. static void ar934x_ip2_irq_init(void)
  113. {
  114. int i;
  115. for (i = ATH79_IP2_IRQ_BASE;
  116. i < ATH79_IP2_IRQ_BASE + ATH79_IP2_IRQ_COUNT; i++)
  117. irq_set_chip_and_handler(i, &dummy_irq_chip,
  118. handle_level_irq);
  119. irq_set_chained_handler(ATH79_CPU_IRQ(2), ar934x_ip2_irq_dispatch);
  120. }
  121. static void qca955x_ip2_irq_dispatch(struct irq_desc *desc)
  122. {
  123. u32 status;
  124. status = ath79_reset_rr(QCA955X_RESET_REG_EXT_INT_STATUS);
  125. status &= QCA955X_EXT_INT_PCIE_RC1_ALL | QCA955X_EXT_INT_WMAC_ALL;
  126. if (status == 0) {
  127. spurious_interrupt();
  128. return;
  129. }
  130. if (status & QCA955X_EXT_INT_PCIE_RC1_ALL) {
  131. /* TODO: flush DDR? */
  132. generic_handle_irq(ATH79_IP2_IRQ(0));
  133. }
  134. if (status & QCA955X_EXT_INT_WMAC_ALL) {
  135. /* TODO: flush DDR? */
  136. generic_handle_irq(ATH79_IP2_IRQ(1));
  137. }
  138. }
  139. static void qca955x_ip3_irq_dispatch(struct irq_desc *desc)
  140. {
  141. u32 status;
  142. status = ath79_reset_rr(QCA955X_RESET_REG_EXT_INT_STATUS);
  143. status &= QCA955X_EXT_INT_PCIE_RC2_ALL |
  144. QCA955X_EXT_INT_USB1 |
  145. QCA955X_EXT_INT_USB2;
  146. if (status == 0) {
  147. spurious_interrupt();
  148. return;
  149. }
  150. if (status & QCA955X_EXT_INT_USB1) {
  151. /* TODO: flush DDR? */
  152. generic_handle_irq(ATH79_IP3_IRQ(0));
  153. }
  154. if (status & QCA955X_EXT_INT_USB2) {
  155. /* TODO: flush DDR? */
  156. generic_handle_irq(ATH79_IP3_IRQ(1));
  157. }
  158. if (status & QCA955X_EXT_INT_PCIE_RC2_ALL) {
  159. /* TODO: flush DDR? */
  160. generic_handle_irq(ATH79_IP3_IRQ(2));
  161. }
  162. }
  163. static void qca955x_irq_init(void)
  164. {
  165. int i;
  166. for (i = ATH79_IP2_IRQ_BASE;
  167. i < ATH79_IP2_IRQ_BASE + ATH79_IP2_IRQ_COUNT; i++)
  168. irq_set_chip_and_handler(i, &dummy_irq_chip,
  169. handle_level_irq);
  170. irq_set_chained_handler(ATH79_CPU_IRQ(2), qca955x_ip2_irq_dispatch);
  171. for (i = ATH79_IP3_IRQ_BASE;
  172. i < ATH79_IP3_IRQ_BASE + ATH79_IP3_IRQ_COUNT; i++)
  173. irq_set_chip_and_handler(i, &dummy_irq_chip,
  174. handle_level_irq);
  175. irq_set_chained_handler(ATH79_CPU_IRQ(3), qca955x_ip3_irq_dispatch);
  176. }
  177. /*
  178. * The IP2/IP3 lines are tied to a PCI/WMAC/USB device. Drivers for
  179. * these devices typically allocate coherent DMA memory, however the
  180. * DMA controller may still have some unsynchronized data in the FIFO.
  181. * Issue a flush in the handlers to ensure that the driver sees
  182. * the update.
  183. *
  184. * This array map the interrupt lines to the DDR write buffer channels.
  185. */
  186. static unsigned irq_wb_chan[8] = {
  187. -1, -1, -1, -1, -1, -1, -1, -1,
  188. };
  189. asmlinkage void plat_irq_dispatch(void)
  190. {
  191. unsigned long pending;
  192. int irq;
  193. pending = read_c0_status() & read_c0_cause() & ST0_IM;
  194. if (!pending) {
  195. spurious_interrupt();
  196. return;
  197. }
  198. pending >>= CAUSEB_IP;
  199. while (pending) {
  200. irq = fls(pending) - 1;
  201. if (irq < ARRAY_SIZE(irq_wb_chan) && irq_wb_chan[irq] != -1)
  202. ath79_ddr_wb_flush(irq_wb_chan[irq]);
  203. do_IRQ(MIPS_CPU_IRQ_BASE + irq);
  204. pending &= ~BIT(irq);
  205. }
  206. }
  207. #ifdef CONFIG_IRQCHIP
  208. static int misc_map(struct irq_domain *d, unsigned int irq, irq_hw_number_t hw)
  209. {
  210. irq_set_chip_and_handler(irq, &ath79_misc_irq_chip, handle_level_irq);
  211. return 0;
  212. }
  213. static const struct irq_domain_ops misc_irq_domain_ops = {
  214. .xlate = irq_domain_xlate_onecell,
  215. .map = misc_map,
  216. };
  217. static int __init ath79_misc_intc_of_init(
  218. struct device_node *node, struct device_node *parent)
  219. {
  220. void __iomem *base = ath79_reset_base;
  221. struct irq_domain *domain;
  222. int irq;
  223. irq = irq_of_parse_and_map(node, 0);
  224. if (!irq)
  225. panic("Failed to get MISC IRQ");
  226. domain = irq_domain_add_legacy(node, ATH79_MISC_IRQ_COUNT,
  227. ATH79_MISC_IRQ_BASE, 0, &misc_irq_domain_ops, NULL);
  228. if (!domain)
  229. panic("Failed to add MISC irqdomain");
  230. /* Disable and clear all interrupts */
  231. __raw_writel(0, base + AR71XX_RESET_REG_MISC_INT_ENABLE);
  232. __raw_writel(0, base + AR71XX_RESET_REG_MISC_INT_STATUS);
  233. irq_set_chained_handler(irq, ath79_misc_irq_handler);
  234. return 0;
  235. }
  236. static int __init ar7100_misc_intc_of_init(
  237. struct device_node *node, struct device_node *parent)
  238. {
  239. ath79_misc_irq_chip.irq_mask_ack = ar71xx_misc_irq_mask;
  240. return ath79_misc_intc_of_init(node, parent);
  241. }
  242. IRQCHIP_DECLARE(ar7100_misc_intc, "qca,ar7100-misc-intc",
  243. ar7100_misc_intc_of_init);
  244. static int __init ar7240_misc_intc_of_init(
  245. struct device_node *node, struct device_node *parent)
  246. {
  247. ath79_misc_irq_chip.irq_ack = ar724x_misc_irq_ack;
  248. return ath79_misc_intc_of_init(node, parent);
  249. }
  250. IRQCHIP_DECLARE(ar7240_misc_intc, "qca,ar7240-misc-intc",
  251. ar7240_misc_intc_of_init);
  252. static int __init ar79_cpu_intc_of_init(
  253. struct device_node *node, struct device_node *parent)
  254. {
  255. int err, i, count;
  256. /* Fill the irq_wb_chan table */
  257. count = of_count_phandle_with_args(
  258. node, "qca,ddr-wb-channels", "#qca,ddr-wb-channel-cells");
  259. for (i = 0; i < count; i++) {
  260. struct of_phandle_args args;
  261. u32 irq = i;
  262. of_property_read_u32_index(
  263. node, "qca,ddr-wb-channel-interrupts", i, &irq);
  264. if (irq >= ARRAY_SIZE(irq_wb_chan))
  265. continue;
  266. err = of_parse_phandle_with_args(
  267. node, "qca,ddr-wb-channels",
  268. "#qca,ddr-wb-channel-cells",
  269. i, &args);
  270. if (err)
  271. return err;
  272. irq_wb_chan[irq] = args.args[0];
  273. pr_info("IRQ: Set flush channel of IRQ%d to %d\n",
  274. irq, args.args[0]);
  275. }
  276. return mips_cpu_irq_of_init(node, parent);
  277. }
  278. IRQCHIP_DECLARE(ar79_cpu_intc, "qca,ar7100-cpu-intc",
  279. ar79_cpu_intc_of_init);
  280. #endif
  281. void __init arch_init_irq(void)
  282. {
  283. if (mips_machtype == ATH79_MACH_GENERIC_OF) {
  284. irqchip_init();
  285. return;
  286. }
  287. if (soc_is_ar71xx() || soc_is_ar724x() ||
  288. soc_is_ar913x() || soc_is_ar933x()) {
  289. irq_wb_chan[2] = 3;
  290. irq_wb_chan[3] = 2;
  291. } else if (soc_is_ar934x()) {
  292. irq_wb_chan[3] = 2;
  293. }
  294. mips_cpu_irq_init();
  295. ath79_misc_irq_init();
  296. if (soc_is_ar934x())
  297. ar934x_ip2_irq_init();
  298. else if (soc_is_qca955x())
  299. qca955x_irq_init();
  300. }