irq.c 8.8 KB

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