Gabor Juhos | d4a67d9 | 2011-01-04 21:28:14 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Atheros AR71xx/AR724x/AR913x specific interrupt handling |
| 3 | * |
Gabor Juhos | fce5cc6 | 2012-03-14 10:45:25 +0100 | [diff] [blame] | 4 | * Copyright (C) 2010-2011 Jaiganesh Narayanan <jnarayanan@atheros.com> |
Gabor Juhos | 4dbcbdf | 2012-03-14 10:45:24 +0100 | [diff] [blame] | 5 | * Copyright (C) 2008-2011 Gabor Juhos <juhosg@openwrt.org> |
Gabor Juhos | d4a67d9 | 2011-01-04 21:28:14 +0100 | [diff] [blame] | 6 | * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org> |
| 7 | * |
Gabor Juhos | fce5cc6 | 2012-03-14 10:45:25 +0100 | [diff] [blame] | 8 | * Parts of this file are based on Atheros' 2.6.15/2.6.31 BSP |
Gabor Juhos | d4a67d9 | 2011-01-04 21:28:14 +0100 | [diff] [blame] | 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 | |
| 15 | #include <linux/kernel.h> |
| 16 | #include <linux/init.h> |
| 17 | #include <linux/interrupt.h> |
Alban Bedel | b29e8b8 | 2015-05-31 01:52:29 +0200 | [diff] [blame] | 18 | #include <linux/irqchip.h> |
| 19 | #include <linux/of_irq.h> |
Gabor Juhos | d4a67d9 | 2011-01-04 21:28:14 +0100 | [diff] [blame] | 20 | |
| 21 | #include <asm/irq_cpu.h> |
| 22 | #include <asm/mipsregs.h> |
| 23 | |
| 24 | #include <asm/mach-ath79/ath79.h> |
| 25 | #include <asm/mach-ath79/ar71xx_regs.h> |
| 26 | #include "common.h" |
Alban Bedel | b29e8b8 | 2015-05-31 01:52:29 +0200 | [diff] [blame] | 27 | #include "machtypes.h" |
Gabor Juhos | d4a67d9 | 2011-01-04 21:28:14 +0100 | [diff] [blame] | 28 | |
Gabor Juhos | d4a67d9 | 2011-01-04 21:28:14 +0100 | [diff] [blame] | 29 | |
Thomas Gleixner | bd0b9ac | 2015-09-14 10:42:37 +0200 | [diff] [blame] | 30 | static void ar934x_ip2_irq_dispatch(struct irq_desc *desc) |
Gabor Juhos | fce5cc6 | 2012-03-14 10:45:25 +0100 | [diff] [blame] | 31 | { |
| 32 | u32 status; |
| 33 | |
Gabor Juhos | fce5cc6 | 2012-03-14 10:45:25 +0100 | [diff] [blame] | 34 | status = ath79_reset_rr(AR934X_RESET_REG_PCIE_WMAC_INT_STATUS); |
| 35 | |
| 36 | if (status & AR934X_PCIE_WMAC_INT_PCIE_ALL) { |
Alban Bedel | 24b0e3e | 2015-04-19 14:30:03 +0200 | [diff] [blame] | 37 | ath79_ddr_wb_flush(3); |
Gabor Juhos | fce5cc6 | 2012-03-14 10:45:25 +0100 | [diff] [blame] | 38 | generic_handle_irq(ATH79_IP2_IRQ(0)); |
| 39 | } else if (status & AR934X_PCIE_WMAC_INT_WMAC_ALL) { |
Alban Bedel | 24b0e3e | 2015-04-19 14:30:03 +0200 | [diff] [blame] | 40 | ath79_ddr_wb_flush(4); |
Gabor Juhos | fce5cc6 | 2012-03-14 10:45:25 +0100 | [diff] [blame] | 41 | generic_handle_irq(ATH79_IP2_IRQ(1)); |
| 42 | } else { |
| 43 | spurious_interrupt(); |
| 44 | } |
Gabor Juhos | fce5cc6 | 2012-03-14 10:45:25 +0100 | [diff] [blame] | 45 | } |
| 46 | |
| 47 | static void ar934x_ip2_irq_init(void) |
| 48 | { |
| 49 | int i; |
| 50 | |
| 51 | for (i = ATH79_IP2_IRQ_BASE; |
| 52 | i < ATH79_IP2_IRQ_BASE + ATH79_IP2_IRQ_COUNT; i++) |
| 53 | irq_set_chip_and_handler(i, &dummy_irq_chip, |
| 54 | handle_level_irq); |
| 55 | |
Gabor Juhos | 7e69c10 | 2013-02-07 19:32:23 +0000 | [diff] [blame] | 56 | irq_set_chained_handler(ATH79_CPU_IRQ(2), ar934x_ip2_irq_dispatch); |
Gabor Juhos | fce5cc6 | 2012-03-14 10:45:25 +0100 | [diff] [blame] | 57 | } |
| 58 | |
Thomas Gleixner | bd0b9ac | 2015-09-14 10:42:37 +0200 | [diff] [blame] | 59 | static void qca955x_ip2_irq_dispatch(struct irq_desc *desc) |
Gabor Juhos | 5333033 | 2013-02-15 18:53:47 +0000 | [diff] [blame] | 60 | { |
| 61 | u32 status; |
| 62 | |
Gabor Juhos | 5333033 | 2013-02-15 18:53:47 +0000 | [diff] [blame] | 63 | status = ath79_reset_rr(QCA955X_RESET_REG_EXT_INT_STATUS); |
| 64 | status &= QCA955X_EXT_INT_PCIE_RC1_ALL | QCA955X_EXT_INT_WMAC_ALL; |
| 65 | |
| 66 | if (status == 0) { |
| 67 | spurious_interrupt(); |
Thomas Gleixner | 9d9a2fa | 2015-07-13 20:46:06 +0000 | [diff] [blame] | 68 | return; |
Gabor Juhos | 5333033 | 2013-02-15 18:53:47 +0000 | [diff] [blame] | 69 | } |
| 70 | |
| 71 | if (status & QCA955X_EXT_INT_PCIE_RC1_ALL) { |
| 72 | /* TODO: flush DDR? */ |
| 73 | generic_handle_irq(ATH79_IP2_IRQ(0)); |
| 74 | } |
| 75 | |
| 76 | if (status & QCA955X_EXT_INT_WMAC_ALL) { |
| 77 | /* TODO: flush DDR? */ |
| 78 | generic_handle_irq(ATH79_IP2_IRQ(1)); |
| 79 | } |
Gabor Juhos | 5333033 | 2013-02-15 18:53:47 +0000 | [diff] [blame] | 80 | } |
| 81 | |
Thomas Gleixner | bd0b9ac | 2015-09-14 10:42:37 +0200 | [diff] [blame] | 82 | static void qca955x_ip3_irq_dispatch(struct irq_desc *desc) |
Gabor Juhos | 5333033 | 2013-02-15 18:53:47 +0000 | [diff] [blame] | 83 | { |
| 84 | u32 status; |
| 85 | |
Gabor Juhos | 5333033 | 2013-02-15 18:53:47 +0000 | [diff] [blame] | 86 | status = ath79_reset_rr(QCA955X_RESET_REG_EXT_INT_STATUS); |
| 87 | status &= QCA955X_EXT_INT_PCIE_RC2_ALL | |
| 88 | QCA955X_EXT_INT_USB1 | |
| 89 | QCA955X_EXT_INT_USB2; |
| 90 | |
| 91 | if (status == 0) { |
| 92 | spurious_interrupt(); |
Thomas Gleixner | 9d9a2fa | 2015-07-13 20:46:06 +0000 | [diff] [blame] | 93 | return; |
Gabor Juhos | 5333033 | 2013-02-15 18:53:47 +0000 | [diff] [blame] | 94 | } |
| 95 | |
| 96 | if (status & QCA955X_EXT_INT_USB1) { |
| 97 | /* TODO: flush DDR? */ |
| 98 | generic_handle_irq(ATH79_IP3_IRQ(0)); |
| 99 | } |
| 100 | |
| 101 | if (status & QCA955X_EXT_INT_USB2) { |
| 102 | /* TODO: flush DDR? */ |
| 103 | generic_handle_irq(ATH79_IP3_IRQ(1)); |
| 104 | } |
| 105 | |
| 106 | if (status & QCA955X_EXT_INT_PCIE_RC2_ALL) { |
| 107 | /* TODO: flush DDR? */ |
| 108 | generic_handle_irq(ATH79_IP3_IRQ(2)); |
| 109 | } |
Gabor Juhos | 5333033 | 2013-02-15 18:53:47 +0000 | [diff] [blame] | 110 | } |
| 111 | |
| 112 | static void qca955x_irq_init(void) |
| 113 | { |
| 114 | int i; |
| 115 | |
| 116 | for (i = ATH79_IP2_IRQ_BASE; |
| 117 | i < ATH79_IP2_IRQ_BASE + ATH79_IP2_IRQ_COUNT; i++) |
| 118 | irq_set_chip_and_handler(i, &dummy_irq_chip, |
| 119 | handle_level_irq); |
| 120 | |
| 121 | irq_set_chained_handler(ATH79_CPU_IRQ(2), qca955x_ip2_irq_dispatch); |
| 122 | |
| 123 | for (i = ATH79_IP3_IRQ_BASE; |
| 124 | i < ATH79_IP3_IRQ_BASE + ATH79_IP3_IRQ_COUNT; i++) |
| 125 | irq_set_chip_and_handler(i, &dummy_irq_chip, |
| 126 | handle_level_irq); |
| 127 | |
| 128 | irq_set_chained_handler(ATH79_CPU_IRQ(3), qca955x_ip3_irq_dispatch); |
| 129 | } |
| 130 | |
Gabor Juhos | 4dbcbdf | 2012-03-14 10:45:24 +0100 | [diff] [blame] | 131 | /* |
| 132 | * The IP2/IP3 lines are tied to a PCI/WMAC/USB device. Drivers for |
| 133 | * these devices typically allocate coherent DMA memory, however the |
| 134 | * DMA controller may still have some unsynchronized data in the FIFO. |
| 135 | * Issue a flush in the handlers to ensure that the driver sees |
| 136 | * the update. |
Alban Bedel | 24b0e3e | 2015-04-19 14:30:03 +0200 | [diff] [blame] | 137 | * |
| 138 | * This array map the interrupt lines to the DDR write buffer channels. |
Gabor Juhos | 4dbcbdf | 2012-03-14 10:45:24 +0100 | [diff] [blame] | 139 | */ |
Gabor Juhos | 5333033 | 2013-02-15 18:53:47 +0000 | [diff] [blame] | 140 | |
Alban Bedel | 24b0e3e | 2015-04-19 14:30:03 +0200 | [diff] [blame] | 141 | static unsigned irq_wb_chan[8] = { |
| 142 | -1, -1, -1, -1, -1, -1, -1, -1, |
| 143 | }; |
Gabor Juhos | 5333033 | 2013-02-15 18:53:47 +0000 | [diff] [blame] | 144 | |
Alban Bedel | 24b0e3e | 2015-04-19 14:30:03 +0200 | [diff] [blame] | 145 | asmlinkage void plat_irq_dispatch(void) |
Gabor Juhos | 5333033 | 2013-02-15 18:53:47 +0000 | [diff] [blame] | 146 | { |
Alban Bedel | 24b0e3e | 2015-04-19 14:30:03 +0200 | [diff] [blame] | 147 | unsigned long pending; |
| 148 | int irq; |
Gabor Juhos | 5333033 | 2013-02-15 18:53:47 +0000 | [diff] [blame] | 149 | |
Alban Bedel | 24b0e3e | 2015-04-19 14:30:03 +0200 | [diff] [blame] | 150 | pending = read_c0_status() & read_c0_cause() & ST0_IM; |
Gabor Juhos | 4dbcbdf | 2012-03-14 10:45:24 +0100 | [diff] [blame] | 151 | |
Alban Bedel | 24b0e3e | 2015-04-19 14:30:03 +0200 | [diff] [blame] | 152 | if (!pending) { |
| 153 | spurious_interrupt(); |
| 154 | return; |
| 155 | } |
Gabor Juhos | 4dbcbdf | 2012-03-14 10:45:24 +0100 | [diff] [blame] | 156 | |
Alban Bedel | 24b0e3e | 2015-04-19 14:30:03 +0200 | [diff] [blame] | 157 | pending >>= CAUSEB_IP; |
| 158 | while (pending) { |
| 159 | irq = fls(pending) - 1; |
| 160 | if (irq < ARRAY_SIZE(irq_wb_chan) && irq_wb_chan[irq] != -1) |
| 161 | ath79_ddr_wb_flush(irq_wb_chan[irq]); |
| 162 | do_IRQ(MIPS_CPU_IRQ_BASE + irq); |
| 163 | pending &= ~BIT(irq); |
| 164 | } |
Gabor Juhos | fce5cc6 | 2012-03-14 10:45:25 +0100 | [diff] [blame] | 165 | } |
| 166 | |
Alban Bedel | b29e8b8 | 2015-05-31 01:52:29 +0200 | [diff] [blame] | 167 | static int __init ar79_cpu_intc_of_init( |
| 168 | struct device_node *node, struct device_node *parent) |
| 169 | { |
| 170 | int err, i, count; |
| 171 | |
| 172 | /* Fill the irq_wb_chan table */ |
| 173 | count = of_count_phandle_with_args( |
| 174 | node, "qca,ddr-wb-channels", "#qca,ddr-wb-channel-cells"); |
| 175 | |
| 176 | for (i = 0; i < count; i++) { |
| 177 | struct of_phandle_args args; |
| 178 | u32 irq = i; |
| 179 | |
| 180 | of_property_read_u32_index( |
| 181 | node, "qca,ddr-wb-channel-interrupts", i, &irq); |
| 182 | if (irq >= ARRAY_SIZE(irq_wb_chan)) |
| 183 | continue; |
| 184 | |
| 185 | err = of_parse_phandle_with_args( |
| 186 | node, "qca,ddr-wb-channels", |
| 187 | "#qca,ddr-wb-channel-cells", |
| 188 | i, &args); |
| 189 | if (err) |
| 190 | return err; |
| 191 | |
| 192 | irq_wb_chan[irq] = args.args[0]; |
| 193 | pr_info("IRQ: Set flush channel of IRQ%d to %d\n", |
| 194 | irq, args.args[0]); |
| 195 | } |
| 196 | |
| 197 | return mips_cpu_irq_of_init(node, parent); |
| 198 | } |
| 199 | IRQCHIP_DECLARE(ar79_cpu_intc, "qca,ar7100-cpu-intc", |
| 200 | ar79_cpu_intc_of_init); |
| 201 | |
Gabor Juhos | d4a67d9 | 2011-01-04 21:28:14 +0100 | [diff] [blame] | 202 | void __init arch_init_irq(void) |
| 203 | { |
Alban Bedel | 07ba4b0 | 2016-01-23 13:57:46 +0100 | [diff] [blame^] | 204 | bool misc_is_ar71xx; |
| 205 | |
Alban Bedel | b29e8b8 | 2015-05-31 01:52:29 +0200 | [diff] [blame] | 206 | if (mips_machtype == ATH79_MACH_GENERIC_OF) { |
| 207 | irqchip_init(); |
| 208 | return; |
| 209 | } |
| 210 | |
Alban Bedel | 24b0e3e | 2015-04-19 14:30:03 +0200 | [diff] [blame] | 211 | if (soc_is_ar71xx() || soc_is_ar724x() || |
| 212 | soc_is_ar913x() || soc_is_ar933x()) { |
| 213 | irq_wb_chan[2] = 3; |
| 214 | irq_wb_chan[3] = 2; |
Gabor Juhos | fce5cc6 | 2012-03-14 10:45:25 +0100 | [diff] [blame] | 215 | } else if (soc_is_ar934x()) { |
Alban Bedel | 24b0e3e | 2015-04-19 14:30:03 +0200 | [diff] [blame] | 216 | irq_wb_chan[3] = 2; |
Gabor Juhos | 4dbcbdf | 2012-03-14 10:45:24 +0100 | [diff] [blame] | 217 | } |
Gabor Juhos | d4a67d9 | 2011-01-04 21:28:14 +0100 | [diff] [blame] | 218 | |
Gabor Juhos | d4a67d9 | 2011-01-04 21:28:14 +0100 | [diff] [blame] | 219 | mips_cpu_irq_init(); |
Alban Bedel | 07ba4b0 | 2016-01-23 13:57:46 +0100 | [diff] [blame^] | 220 | |
| 221 | if (soc_is_ar71xx() || soc_is_ar913x()) |
| 222 | misc_is_ar71xx = true; |
| 223 | else if (soc_is_ar724x() || |
| 224 | soc_is_ar933x() || |
| 225 | soc_is_ar934x() || |
| 226 | soc_is_qca955x()) |
| 227 | misc_is_ar71xx = false; |
| 228 | else |
| 229 | BUG(); |
| 230 | ath79_misc_irq_init( |
| 231 | ath79_reset_base + AR71XX_RESET_REG_MISC_INT_STATUS, |
| 232 | ATH79_CPU_IRQ(6), ATH79_MISC_IRQ_BASE, misc_is_ar71xx); |
Gabor Juhos | fce5cc6 | 2012-03-14 10:45:25 +0100 | [diff] [blame] | 233 | |
| 234 | if (soc_is_ar934x()) |
| 235 | ar934x_ip2_irq_init(); |
Gabor Juhos | 5333033 | 2013-02-15 18:53:47 +0000 | [diff] [blame] | 236 | else if (soc_is_qca955x()) |
| 237 | qca955x_irq_init(); |
Gabor Juhos | d4a67d9 | 2011-01-04 21:28:14 +0100 | [diff] [blame] | 238 | } |