blob: 15ecb4831e125838477a4805810381e1f1bb6725 [file] [log] [blame]
Gabor Juhosd4a67d92011-01-04 21:28:14 +01001/*
2 * Atheros AR71xx/AR724x/AR913x specific interrupt handling
3 *
Gabor Juhosfce5cc62012-03-14 10:45:25 +01004 * Copyright (C) 2010-2011 Jaiganesh Narayanan <jnarayanan@atheros.com>
Gabor Juhos4dbcbdf2012-03-14 10:45:24 +01005 * Copyright (C) 2008-2011 Gabor Juhos <juhosg@openwrt.org>
Gabor Juhosd4a67d92011-01-04 21:28:14 +01006 * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
7 *
Gabor Juhosfce5cc62012-03-14 10:45:25 +01008 * Parts of this file are based on Atheros' 2.6.15/2.6.31 BSP
Gabor Juhosd4a67d92011-01-04 21:28:14 +01009 *
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 Bedelb29e8b82015-05-31 01:52:29 +020018#include <linux/irqchip.h>
19#include <linux/of_irq.h>
Gabor Juhosd4a67d92011-01-04 21:28:14 +010020
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 Bedelb29e8b82015-05-31 01:52:29 +020027#include "machtypes.h"
Gabor Juhosd4a67d92011-01-04 21:28:14 +010028
Thomas Gleixnerbd0b9ac2015-09-14 10:42:37 +020029static void ath79_misc_irq_handler(struct irq_desc *desc)
Gabor Juhosd4a67d92011-01-04 21:28:14 +010030{
31 void __iomem *base = ath79_reset_base;
32 u32 pending;
33
34 pending = __raw_readl(base + AR71XX_RESET_REG_MISC_INT_STATUS) &
35 __raw_readl(base + AR71XX_RESET_REG_MISC_INT_ENABLE);
36
Gabor Juhos9c099c42013-01-29 16:13:17 +000037 if (!pending) {
Gabor Juhosd4a67d92011-01-04 21:28:14 +010038 spurious_interrupt();
Gabor Juhos9c099c42013-01-29 16:13:17 +000039 return;
40 }
41
42 while (pending) {
43 int bit = __ffs(pending);
44
45 generic_handle_irq(ATH79_MISC_IRQ(bit));
46 pending &= ~BIT(bit);
47 }
Gabor Juhosd4a67d92011-01-04 21:28:14 +010048}
49
Thomas Gleixner3fb88182011-03-23 21:08:47 +000050static void ar71xx_misc_irq_unmask(struct irq_data *d)
Gabor Juhosd4a67d92011-01-04 21:28:14 +010051{
Thomas Gleixner3fb88182011-03-23 21:08:47 +000052 unsigned int irq = d->irq - ATH79_MISC_IRQ_BASE;
Gabor Juhosd4a67d92011-01-04 21:28:14 +010053 void __iomem *base = ath79_reset_base;
54 u32 t;
55
Gabor Juhosd4a67d92011-01-04 21:28:14 +010056 t = __raw_readl(base + AR71XX_RESET_REG_MISC_INT_ENABLE);
57 __raw_writel(t | (1 << irq), base + AR71XX_RESET_REG_MISC_INT_ENABLE);
58
59 /* flush write */
60 __raw_readl(base + AR71XX_RESET_REG_MISC_INT_ENABLE);
61}
62
Thomas Gleixner3fb88182011-03-23 21:08:47 +000063static void ar71xx_misc_irq_mask(struct irq_data *d)
Gabor Juhosd4a67d92011-01-04 21:28:14 +010064{
Thomas Gleixner3fb88182011-03-23 21:08:47 +000065 unsigned int irq = d->irq - ATH79_MISC_IRQ_BASE;
Gabor Juhosd4a67d92011-01-04 21:28:14 +010066 void __iomem *base = ath79_reset_base;
67 u32 t;
68
Gabor Juhosd4a67d92011-01-04 21:28:14 +010069 t = __raw_readl(base + AR71XX_RESET_REG_MISC_INT_ENABLE);
70 __raw_writel(t & ~(1 << irq), base + AR71XX_RESET_REG_MISC_INT_ENABLE);
71
72 /* flush write */
73 __raw_readl(base + AR71XX_RESET_REG_MISC_INT_ENABLE);
74}
75
Thomas Gleixner3fb88182011-03-23 21:08:47 +000076static void ar724x_misc_irq_ack(struct irq_data *d)
Gabor Juhosd4a67d92011-01-04 21:28:14 +010077{
Thomas Gleixner3fb88182011-03-23 21:08:47 +000078 unsigned int irq = d->irq - ATH79_MISC_IRQ_BASE;
Gabor Juhosd4a67d92011-01-04 21:28:14 +010079 void __iomem *base = ath79_reset_base;
80 u32 t;
81
Gabor Juhosd4a67d92011-01-04 21:28:14 +010082 t = __raw_readl(base + AR71XX_RESET_REG_MISC_INT_STATUS);
83 __raw_writel(t & ~(1 << irq), base + AR71XX_RESET_REG_MISC_INT_STATUS);
84
85 /* flush write */
86 __raw_readl(base + AR71XX_RESET_REG_MISC_INT_STATUS);
87}
88
89static struct irq_chip ath79_misc_irq_chip = {
90 .name = "MISC",
Thomas Gleixner3fb88182011-03-23 21:08:47 +000091 .irq_unmask = ar71xx_misc_irq_unmask,
92 .irq_mask = ar71xx_misc_irq_mask,
Gabor Juhosd4a67d92011-01-04 21:28:14 +010093};
94
95static void __init ath79_misc_irq_init(void)
96{
97 void __iomem *base = ath79_reset_base;
98 int i;
99
100 __raw_writel(0, base + AR71XX_RESET_REG_MISC_INT_ENABLE);
101 __raw_writel(0, base + AR71XX_RESET_REG_MISC_INT_STATUS);
102
103 if (soc_is_ar71xx() || soc_is_ar913x())
Thomas Gleixner3fb88182011-03-23 21:08:47 +0000104 ath79_misc_irq_chip.irq_mask_ack = ar71xx_misc_irq_mask;
Gabor Juhos53330332013-02-15 18:53:47 +0000105 else if (soc_is_ar724x() ||
106 soc_is_ar933x() ||
107 soc_is_ar934x() ||
108 soc_is_qca955x())
Thomas Gleixner3fb88182011-03-23 21:08:47 +0000109 ath79_misc_irq_chip.irq_ack = ar724x_misc_irq_ack;
Gabor Juhosd4a67d92011-01-04 21:28:14 +0100110 else
111 BUG();
112
113 for (i = ATH79_MISC_IRQ_BASE;
114 i < ATH79_MISC_IRQ_BASE + ATH79_MISC_IRQ_COUNT; i++) {
Thomas Gleixnere4ec7982011-03-27 15:19:28 +0200115 irq_set_chip_and_handler(i, &ath79_misc_irq_chip,
Gabor Juhosd4a67d92011-01-04 21:28:14 +0100116 handle_level_irq);
117 }
118
Gabor Juhos7e69c102013-02-07 19:32:23 +0000119 irq_set_chained_handler(ATH79_CPU_IRQ(6), ath79_misc_irq_handler);
Gabor Juhosd4a67d92011-01-04 21:28:14 +0100120}
121
Thomas Gleixnerbd0b9ac2015-09-14 10:42:37 +0200122static void ar934x_ip2_irq_dispatch(struct irq_desc *desc)
Gabor Juhosfce5cc62012-03-14 10:45:25 +0100123{
124 u32 status;
125
Gabor Juhosfce5cc62012-03-14 10:45:25 +0100126 status = ath79_reset_rr(AR934X_RESET_REG_PCIE_WMAC_INT_STATUS);
127
128 if (status & AR934X_PCIE_WMAC_INT_PCIE_ALL) {
Alban Bedel24b0e3e2015-04-19 14:30:03 +0200129 ath79_ddr_wb_flush(3);
Gabor Juhosfce5cc62012-03-14 10:45:25 +0100130 generic_handle_irq(ATH79_IP2_IRQ(0));
131 } else if (status & AR934X_PCIE_WMAC_INT_WMAC_ALL) {
Alban Bedel24b0e3e2015-04-19 14:30:03 +0200132 ath79_ddr_wb_flush(4);
Gabor Juhosfce5cc62012-03-14 10:45:25 +0100133 generic_handle_irq(ATH79_IP2_IRQ(1));
134 } else {
135 spurious_interrupt();
136 }
Gabor Juhosfce5cc62012-03-14 10:45:25 +0100137}
138
139static void ar934x_ip2_irq_init(void)
140{
141 int i;
142
143 for (i = ATH79_IP2_IRQ_BASE;
144 i < ATH79_IP2_IRQ_BASE + ATH79_IP2_IRQ_COUNT; i++)
145 irq_set_chip_and_handler(i, &dummy_irq_chip,
146 handle_level_irq);
147
Gabor Juhos7e69c102013-02-07 19:32:23 +0000148 irq_set_chained_handler(ATH79_CPU_IRQ(2), ar934x_ip2_irq_dispatch);
Gabor Juhosfce5cc62012-03-14 10:45:25 +0100149}
150
Thomas Gleixnerbd0b9ac2015-09-14 10:42:37 +0200151static void qca955x_ip2_irq_dispatch(struct irq_desc *desc)
Gabor Juhos53330332013-02-15 18:53:47 +0000152{
153 u32 status;
154
Gabor Juhos53330332013-02-15 18:53:47 +0000155 status = ath79_reset_rr(QCA955X_RESET_REG_EXT_INT_STATUS);
156 status &= QCA955X_EXT_INT_PCIE_RC1_ALL | QCA955X_EXT_INT_WMAC_ALL;
157
158 if (status == 0) {
159 spurious_interrupt();
Thomas Gleixner9d9a2fa2015-07-13 20:46:06 +0000160 return;
Gabor Juhos53330332013-02-15 18:53:47 +0000161 }
162
163 if (status & QCA955X_EXT_INT_PCIE_RC1_ALL) {
164 /* TODO: flush DDR? */
165 generic_handle_irq(ATH79_IP2_IRQ(0));
166 }
167
168 if (status & QCA955X_EXT_INT_WMAC_ALL) {
169 /* TODO: flush DDR? */
170 generic_handle_irq(ATH79_IP2_IRQ(1));
171 }
Gabor Juhos53330332013-02-15 18:53:47 +0000172}
173
Thomas Gleixnerbd0b9ac2015-09-14 10:42:37 +0200174static void qca955x_ip3_irq_dispatch(struct irq_desc *desc)
Gabor Juhos53330332013-02-15 18:53:47 +0000175{
176 u32 status;
177
Gabor Juhos53330332013-02-15 18:53:47 +0000178 status = ath79_reset_rr(QCA955X_RESET_REG_EXT_INT_STATUS);
179 status &= QCA955X_EXT_INT_PCIE_RC2_ALL |
180 QCA955X_EXT_INT_USB1 |
181 QCA955X_EXT_INT_USB2;
182
183 if (status == 0) {
184 spurious_interrupt();
Thomas Gleixner9d9a2fa2015-07-13 20:46:06 +0000185 return;
Gabor Juhos53330332013-02-15 18:53:47 +0000186 }
187
188 if (status & QCA955X_EXT_INT_USB1) {
189 /* TODO: flush DDR? */
190 generic_handle_irq(ATH79_IP3_IRQ(0));
191 }
192
193 if (status & QCA955X_EXT_INT_USB2) {
194 /* TODO: flush DDR? */
195 generic_handle_irq(ATH79_IP3_IRQ(1));
196 }
197
198 if (status & QCA955X_EXT_INT_PCIE_RC2_ALL) {
199 /* TODO: flush DDR? */
200 generic_handle_irq(ATH79_IP3_IRQ(2));
201 }
Gabor Juhos53330332013-02-15 18:53:47 +0000202}
203
204static void qca955x_irq_init(void)
205{
206 int i;
207
208 for (i = ATH79_IP2_IRQ_BASE;
209 i < ATH79_IP2_IRQ_BASE + ATH79_IP2_IRQ_COUNT; i++)
210 irq_set_chip_and_handler(i, &dummy_irq_chip,
211 handle_level_irq);
212
213 irq_set_chained_handler(ATH79_CPU_IRQ(2), qca955x_ip2_irq_dispatch);
214
215 for (i = ATH79_IP3_IRQ_BASE;
216 i < ATH79_IP3_IRQ_BASE + ATH79_IP3_IRQ_COUNT; i++)
217 irq_set_chip_and_handler(i, &dummy_irq_chip,
218 handle_level_irq);
219
220 irq_set_chained_handler(ATH79_CPU_IRQ(3), qca955x_ip3_irq_dispatch);
221}
222
Gabor Juhos4dbcbdf2012-03-14 10:45:24 +0100223/*
224 * The IP2/IP3 lines are tied to a PCI/WMAC/USB device. Drivers for
225 * these devices typically allocate coherent DMA memory, however the
226 * DMA controller may still have some unsynchronized data in the FIFO.
227 * Issue a flush in the handlers to ensure that the driver sees
228 * the update.
Alban Bedel24b0e3e2015-04-19 14:30:03 +0200229 *
230 * This array map the interrupt lines to the DDR write buffer channels.
Gabor Juhos4dbcbdf2012-03-14 10:45:24 +0100231 */
Gabor Juhos53330332013-02-15 18:53:47 +0000232
Alban Bedel24b0e3e2015-04-19 14:30:03 +0200233static unsigned irq_wb_chan[8] = {
234 -1, -1, -1, -1, -1, -1, -1, -1,
235};
Gabor Juhos53330332013-02-15 18:53:47 +0000236
Alban Bedel24b0e3e2015-04-19 14:30:03 +0200237asmlinkage void plat_irq_dispatch(void)
Gabor Juhos53330332013-02-15 18:53:47 +0000238{
Alban Bedel24b0e3e2015-04-19 14:30:03 +0200239 unsigned long pending;
240 int irq;
Gabor Juhos53330332013-02-15 18:53:47 +0000241
Alban Bedel24b0e3e2015-04-19 14:30:03 +0200242 pending = read_c0_status() & read_c0_cause() & ST0_IM;
Gabor Juhos4dbcbdf2012-03-14 10:45:24 +0100243
Alban Bedel24b0e3e2015-04-19 14:30:03 +0200244 if (!pending) {
245 spurious_interrupt();
246 return;
247 }
Gabor Juhos4dbcbdf2012-03-14 10:45:24 +0100248
Alban Bedel24b0e3e2015-04-19 14:30:03 +0200249 pending >>= CAUSEB_IP;
250 while (pending) {
251 irq = fls(pending) - 1;
252 if (irq < ARRAY_SIZE(irq_wb_chan) && irq_wb_chan[irq] != -1)
253 ath79_ddr_wb_flush(irq_wb_chan[irq]);
254 do_IRQ(MIPS_CPU_IRQ_BASE + irq);
255 pending &= ~BIT(irq);
256 }
Gabor Juhosfce5cc62012-03-14 10:45:25 +0100257}
258
Alban Bedelb29e8b82015-05-31 01:52:29 +0200259#ifdef CONFIG_IRQCHIP
260static int misc_map(struct irq_domain *d, unsigned int irq, irq_hw_number_t hw)
261{
262 irq_set_chip_and_handler(irq, &ath79_misc_irq_chip, handle_level_irq);
263 return 0;
264}
265
266static const struct irq_domain_ops misc_irq_domain_ops = {
267 .xlate = irq_domain_xlate_onecell,
268 .map = misc_map,
269};
270
271static int __init ath79_misc_intc_of_init(
272 struct device_node *node, struct device_node *parent)
273{
274 void __iomem *base = ath79_reset_base;
275 struct irq_domain *domain;
276 int irq;
277
278 irq = irq_of_parse_and_map(node, 0);
279 if (!irq)
280 panic("Failed to get MISC IRQ");
281
282 domain = irq_domain_add_legacy(node, ATH79_MISC_IRQ_COUNT,
283 ATH79_MISC_IRQ_BASE, 0, &misc_irq_domain_ops, NULL);
284 if (!domain)
285 panic("Failed to add MISC irqdomain");
286
287 /* Disable and clear all interrupts */
288 __raw_writel(0, base + AR71XX_RESET_REG_MISC_INT_ENABLE);
289 __raw_writel(0, base + AR71XX_RESET_REG_MISC_INT_STATUS);
290
291
292 irq_set_chained_handler(irq, ath79_misc_irq_handler);
293
294 return 0;
295}
296IRQCHIP_DECLARE(ath79_misc_intc, "qca,ar7100-misc-intc",
297 ath79_misc_intc_of_init);
298
299static int __init ar79_cpu_intc_of_init(
300 struct device_node *node, struct device_node *parent)
301{
302 int err, i, count;
303
304 /* Fill the irq_wb_chan table */
305 count = of_count_phandle_with_args(
306 node, "qca,ddr-wb-channels", "#qca,ddr-wb-channel-cells");
307
308 for (i = 0; i < count; i++) {
309 struct of_phandle_args args;
310 u32 irq = i;
311
312 of_property_read_u32_index(
313 node, "qca,ddr-wb-channel-interrupts", i, &irq);
314 if (irq >= ARRAY_SIZE(irq_wb_chan))
315 continue;
316
317 err = of_parse_phandle_with_args(
318 node, "qca,ddr-wb-channels",
319 "#qca,ddr-wb-channel-cells",
320 i, &args);
321 if (err)
322 return err;
323
324 irq_wb_chan[irq] = args.args[0];
325 pr_info("IRQ: Set flush channel of IRQ%d to %d\n",
326 irq, args.args[0]);
327 }
328
329 return mips_cpu_irq_of_init(node, parent);
330}
331IRQCHIP_DECLARE(ar79_cpu_intc, "qca,ar7100-cpu-intc",
332 ar79_cpu_intc_of_init);
333
334#endif
335
Gabor Juhosd4a67d92011-01-04 21:28:14 +0100336void __init arch_init_irq(void)
337{
Alban Bedelb29e8b82015-05-31 01:52:29 +0200338 if (mips_machtype == ATH79_MACH_GENERIC_OF) {
339 irqchip_init();
340 return;
341 }
342
Alban Bedel24b0e3e2015-04-19 14:30:03 +0200343 if (soc_is_ar71xx() || soc_is_ar724x() ||
344 soc_is_ar913x() || soc_is_ar933x()) {
345 irq_wb_chan[2] = 3;
346 irq_wb_chan[3] = 2;
Gabor Juhosfce5cc62012-03-14 10:45:25 +0100347 } else if (soc_is_ar934x()) {
Alban Bedel24b0e3e2015-04-19 14:30:03 +0200348 irq_wb_chan[3] = 2;
Gabor Juhos4dbcbdf2012-03-14 10:45:24 +0100349 }
Gabor Juhosd4a67d92011-01-04 21:28:14 +0100350
Gabor Juhosd4a67d92011-01-04 21:28:14 +0100351 mips_cpu_irq_init();
352 ath79_misc_irq_init();
Gabor Juhosfce5cc62012-03-14 10:45:25 +0100353
354 if (soc_is_ar934x())
355 ar934x_ip2_irq_init();
Gabor Juhos53330332013-02-15 18:53:47 +0000356 else if (soc_is_qca955x())
357 qca955x_irq_init();
Gabor Juhosd4a67d92011-01-04 21:28:14 +0100358}