irq.c 9.0 KB

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