2 * Atheros AR71xx SoC specific interrupt handling
4 * Copyright (C) 2010-2011 Jaiganesh Narayanan <jnarayanan@atheros.com>
5 * Copyright (C) 2008-2010 Gabor Juhos <juhosg@openwrt.org>
6 * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
8 * Parts of this file are based on Atheros 2.6.15 BSP
9 * Parts of this file are based on Atheros 2.6.31 BSP
11 * This program is free software; you can redistribute it and/or modify it
12 * under the terms of the GNU General Public License version 2 as published
13 * by the Free Software Foundation.
16 #include <linux/kernel.h>
17 #include <linux/init.h>
18 #include <linux/interrupt.h>
19 #include <linux/irq.h>
21 #include <asm/irq_cpu.h>
22 #include <asm/mipsregs.h>
24 #include <asm/mach-ar71xx/ar71xx.h>
26 static void ar71xx_gpio_irq_dispatch(void)
28 void __iomem
*base
= ar71xx_gpio_base
;
31 pending
= __raw_readl(base
+ GPIO_REG_INT_PENDING
) &
32 __raw_readl(base
+ GPIO_REG_INT_ENABLE
);
35 do_IRQ(AR71XX_GPIO_IRQ_BASE
+ fls(pending
) - 1);
40 static void ar71xx_gpio_irq_unmask(struct irq_data
*d
)
42 unsigned int irq
= d
->irq
- AR71XX_GPIO_IRQ_BASE
;
43 void __iomem
*base
= ar71xx_gpio_base
;
46 t
= __raw_readl(base
+ GPIO_REG_INT_ENABLE
);
47 __raw_writel(t
| (1 << irq
), base
+ GPIO_REG_INT_ENABLE
);
50 (void) __raw_readl(base
+ GPIO_REG_INT_ENABLE
);
53 static void ar71xx_gpio_irq_mask(struct irq_data
*d
)
55 unsigned int irq
= d
->irq
- AR71XX_GPIO_IRQ_BASE
;
56 void __iomem
*base
= ar71xx_gpio_base
;
59 t
= __raw_readl(base
+ GPIO_REG_INT_ENABLE
);
60 __raw_writel(t
& ~(1 << irq
), base
+ GPIO_REG_INT_ENABLE
);
63 (void) __raw_readl(base
+ GPIO_REG_INT_ENABLE
);
66 static struct irq_chip ar71xx_gpio_irq_chip
= {
67 .name
= "AR71XX GPIO",
68 .irq_unmask
= ar71xx_gpio_irq_unmask
,
69 .irq_mask
= ar71xx_gpio_irq_mask
,
70 .irq_mask_ack
= ar71xx_gpio_irq_mask
,
73 static struct irqaction ar71xx_gpio_irqaction
= {
75 .name
= "cascade [AR71XX GPIO]",
78 #define GPIO_INT_ALL 0xffff
80 static void __init
ar71xx_gpio_irq_init(void)
82 void __iomem
*base
= ar71xx_gpio_base
;
85 __raw_writel(0, base
+ GPIO_REG_INT_ENABLE
);
86 __raw_writel(0, base
+ GPIO_REG_INT_PENDING
);
88 /* setup type of all GPIO interrupts to level sensitive */
89 __raw_writel(GPIO_INT_ALL
, base
+ GPIO_REG_INT_TYPE
);
91 /* setup polarity of all GPIO interrupts to active high */
92 __raw_writel(GPIO_INT_ALL
, base
+ GPIO_REG_INT_POLARITY
);
94 for (i
= AR71XX_GPIO_IRQ_BASE
;
95 i
< AR71XX_GPIO_IRQ_BASE
+ AR71XX_GPIO_IRQ_COUNT
; i
++)
96 irq_set_chip_and_handler(i
, &ar71xx_gpio_irq_chip
,
99 setup_irq(AR71XX_MISC_IRQ_GPIO
, &ar71xx_gpio_irqaction
);
102 static void ar71xx_misc_irq_dispatch(void)
106 pending
= ar71xx_reset_rr(AR71XX_RESET_REG_MISC_INT_STATUS
)
107 & ar71xx_reset_rr(AR71XX_RESET_REG_MISC_INT_ENABLE
);
109 if (pending
& MISC_INT_UART
)
110 do_IRQ(AR71XX_MISC_IRQ_UART
);
112 else if (pending
& MISC_INT_DMA
)
113 do_IRQ(AR71XX_MISC_IRQ_DMA
);
115 else if (pending
& MISC_INT_PERFC
)
116 do_IRQ(AR71XX_MISC_IRQ_PERFC
);
118 else if (pending
& MISC_INT_TIMER
)
119 do_IRQ(AR71XX_MISC_IRQ_TIMER
);
121 else if (pending
& MISC_INT_OHCI
)
122 do_IRQ(AR71XX_MISC_IRQ_OHCI
);
124 else if (pending
& MISC_INT_ERROR
)
125 do_IRQ(AR71XX_MISC_IRQ_ERROR
);
127 else if (pending
& MISC_INT_GPIO
)
128 ar71xx_gpio_irq_dispatch();
130 else if (pending
& MISC_INT_WDOG
)
131 do_IRQ(AR71XX_MISC_IRQ_WDOG
);
133 else if (pending
& MISC_INT_TIMER2
)
134 do_IRQ(AR71XX_MISC_IRQ_TIMER2
);
136 else if (pending
& MISC_INT_TIMER3
)
137 do_IRQ(AR71XX_MISC_IRQ_TIMER3
);
139 else if (pending
& MISC_INT_TIMER4
)
140 do_IRQ(AR71XX_MISC_IRQ_TIMER4
);
142 else if (pending
& MISC_INT_DDR_PERF
)
143 do_IRQ(AR71XX_MISC_IRQ_DDR_PERF
);
145 else if (pending
& MISC_INT_ENET_LINK
)
146 do_IRQ(AR71XX_MISC_IRQ_ENET_LINK
);
149 spurious_interrupt();
152 static void ar71xx_misc_irq_unmask(struct irq_data
*d
)
154 unsigned int irq
= d
->irq
- AR71XX_MISC_IRQ_BASE
;
155 void __iomem
*base
= ar71xx_reset_base
;
158 t
= __raw_readl(base
+ AR71XX_RESET_REG_MISC_INT_ENABLE
);
159 __raw_writel(t
| (1 << irq
), base
+ AR71XX_RESET_REG_MISC_INT_ENABLE
);
162 (void) __raw_readl(base
+ AR71XX_RESET_REG_MISC_INT_ENABLE
);
165 static void ar71xx_misc_irq_mask(struct irq_data
*d
)
167 unsigned int irq
= d
->irq
- AR71XX_MISC_IRQ_BASE
;
168 void __iomem
*base
= ar71xx_reset_base
;
171 t
= __raw_readl(base
+ AR71XX_RESET_REG_MISC_INT_ENABLE
);
172 __raw_writel(t
& ~(1 << irq
), base
+ AR71XX_RESET_REG_MISC_INT_ENABLE
);
175 (void) __raw_readl(base
+ AR71XX_RESET_REG_MISC_INT_ENABLE
);
178 static void ar724x_misc_irq_ack(struct irq_data
*d
)
180 unsigned int irq
= d
->irq
- AR71XX_MISC_IRQ_BASE
;
181 void __iomem
*base
= ar71xx_reset_base
;
184 t
= __raw_readl(base
+ AR71XX_RESET_REG_MISC_INT_STATUS
);
185 __raw_writel(t
& ~(1 << irq
), base
+ AR71XX_RESET_REG_MISC_INT_STATUS
);
188 (void) __raw_readl(base
+ AR71XX_RESET_REG_MISC_INT_STATUS
);
191 static struct irq_chip ar71xx_misc_irq_chip
= {
192 .name
= "AR71XX MISC",
193 .irq_unmask
= ar71xx_misc_irq_unmask
,
194 .irq_mask
= ar71xx_misc_irq_mask
,
197 static struct irqaction ar71xx_misc_irqaction
= {
198 .handler
= no_action
,
199 .name
= "cascade [AR71XX MISC]",
202 static void __init
ar71xx_misc_irq_init(void)
204 void __iomem
*base
= ar71xx_reset_base
;
207 __raw_writel(0, base
+ AR71XX_RESET_REG_MISC_INT_ENABLE
);
208 __raw_writel(0, base
+ AR71XX_RESET_REG_MISC_INT_STATUS
);
210 switch (ar71xx_soc
) {
211 case AR71XX_SOC_AR7240
:
212 case AR71XX_SOC_AR7241
:
213 case AR71XX_SOC_AR7242
:
214 case AR71XX_SOC_AR9330
:
215 case AR71XX_SOC_AR9331
:
216 case AR71XX_SOC_AR9341
:
217 case AR71XX_SOC_AR9342
:
218 case AR71XX_SOC_AR9344
:
219 ar71xx_misc_irq_chip
.irq_ack
= ar724x_misc_irq_ack
;
222 ar71xx_misc_irq_chip
.irq_mask_ack
= ar71xx_misc_irq_mask
;
226 for (i
= AR71XX_MISC_IRQ_BASE
;
227 i
< AR71XX_MISC_IRQ_BASE
+ AR71XX_MISC_IRQ_COUNT
; i
++)
228 irq_set_chip_and_handler(i
, &ar71xx_misc_irq_chip
,
231 setup_irq(AR71XX_CPU_IRQ_MISC
, &ar71xx_misc_irqaction
);
235 * The IP2/IP3 lines are tied to a PCI/WMAC/USB device. Drivers for
236 * these devices typically allocate coherent DMA memory, however the
237 * DMA controller may still have some unsynchronized data in the FIFO.
238 * Issue a flush in the handlers to ensure that the driver sees
241 static void ar71xx_ip2_handler(void)
243 ar71xx_ddr_flush(AR71XX_DDR_REG_FLUSH_PCI
);
244 do_IRQ(AR71XX_CPU_IRQ_IP2
);
247 static void ar724x_ip2_handler(void)
249 ar71xx_ddr_flush(AR724X_DDR_REG_FLUSH_PCIE
);
250 do_IRQ(AR71XX_CPU_IRQ_IP2
);
253 static void ar913x_ip2_handler(void)
255 ar71xx_ddr_flush(AR91XX_DDR_REG_FLUSH_WMAC
);
256 do_IRQ(AR71XX_CPU_IRQ_IP2
);
259 static void ar933x_ip2_handler(void)
261 ar71xx_ddr_flush(AR933X_DDR_REG_FLUSH_WMAC
);
262 do_IRQ(AR71XX_CPU_IRQ_IP2
);
265 static void ar934x_ip2_handler(void)
267 ar71xx_ddr_flush(AR934X_DDR_REG_FLUSH_PCIE
);
268 do_IRQ(AR71XX_CPU_IRQ_IP2
);
271 static void ar71xx_ip3_handler(void)
273 ar71xx_ddr_flush(AR71XX_DDR_REG_FLUSH_USB
);
274 do_IRQ(AR71XX_CPU_IRQ_USB
);
277 static void ar724x_ip3_handler(void)
279 ar71xx_ddr_flush(AR724X_DDR_REG_FLUSH_USB
);
280 do_IRQ(AR71XX_CPU_IRQ_USB
);
283 static void ar913x_ip3_handler(void)
285 ar71xx_ddr_flush(AR91XX_DDR_REG_FLUSH_USB
);
286 do_IRQ(AR71XX_CPU_IRQ_USB
);
289 static void ar933x_ip3_handler(void)
291 ar71xx_ddr_flush(AR933X_DDR_REG_FLUSH_USB
);
292 do_IRQ(AR71XX_CPU_IRQ_USB
);
295 static void ar934x_ip3_handler(void)
297 do_IRQ(AR71XX_CPU_IRQ_USB
);
300 static void (*ip2_handler
)(void);
301 static void (*ip3_handler
)(void);
303 asmlinkage
void plat_irq_dispatch(void)
305 unsigned long pending
;
307 pending
= read_c0_status() & read_c0_cause() & ST0_IM
;
309 if (pending
& STATUSF_IP7
)
310 do_IRQ(AR71XX_CPU_IRQ_TIMER
);
312 else if (pending
& STATUSF_IP2
)
315 else if (pending
& STATUSF_IP4
)
316 do_IRQ(AR71XX_CPU_IRQ_GE0
);
318 else if (pending
& STATUSF_IP5
)
319 do_IRQ(AR71XX_CPU_IRQ_GE1
);
321 else if (pending
& STATUSF_IP3
)
324 else if (pending
& STATUSF_IP6
)
325 ar71xx_misc_irq_dispatch();
327 spurious_interrupt();
330 void __init
arch_init_irq(void)
332 switch (ar71xx_soc
) {
333 case AR71XX_SOC_AR7130
:
334 case AR71XX_SOC_AR7141
:
335 case AR71XX_SOC_AR7161
:
336 ip2_handler
= ar71xx_ip2_handler
;
337 ip3_handler
= ar71xx_ip3_handler
;
340 case AR71XX_SOC_AR7240
:
341 case AR71XX_SOC_AR7241
:
342 case AR71XX_SOC_AR7242
:
343 ip2_handler
= ar724x_ip2_handler
;
344 ip3_handler
= ar724x_ip3_handler
;
347 case AR71XX_SOC_AR9130
:
348 case AR71XX_SOC_AR9132
:
349 ip2_handler
= ar913x_ip2_handler
;
350 ip3_handler
= ar913x_ip3_handler
;
353 case AR71XX_SOC_AR9330
:
354 case AR71XX_SOC_AR9331
:
355 ip2_handler
= ar933x_ip2_handler
;
356 ip3_handler
= ar933x_ip3_handler
;
359 case AR71XX_SOC_AR9341
:
360 case AR71XX_SOC_AR9342
:
361 case AR71XX_SOC_AR9344
:
362 ip2_handler
= ar934x_ip2_handler
;
363 ip3_handler
= ar934x_ip3_handler
;
372 ar71xx_misc_irq_init();
374 cp0_perfcount_irq
= AR71XX_MISC_IRQ_PERFC
;
376 ar71xx_gpio_irq_init();