ar71xx: add separate handlers for IP3 interrupts
[openwrt.git] / target / linux / ar71xx / files / arch / mips / ar71xx / irq.c
index 4e1da16..585e8d8 100644 (file)
@@ -1,10 +1,12 @@
 /*
  *  Atheros AR71xx SoC specific interrupt handling
  *
+ *  Copyright (C) 2010-2011 Jaiganesh Narayanan <jnarayanan@atheros.com>
  *  Copyright (C) 2008-2010 Gabor Juhos <juhosg@openwrt.org>
  *  Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
  *
- *  Parts of this file are based on Atheros' 2.6.15 BSP
+ *  Parts of this file are based on Atheros 2.6.15 BSP
+ *  Parts of this file are based on Atheros 2.6.31 BSP
  *
  *  This program is free software; you can redistribute it and/or modify it
  *  under the terms of the GNU General Public License version 2 as published
@@ -21,8 +23,6 @@
 
 #include <asm/mach-ar71xx/ar71xx.h>
 
-static int ip2_flush_reg;
-
 static void ar71xx_gpio_irq_dispatch(void)
 {
        void __iomem *base = ar71xx_gpio_base;
@@ -88,7 +88,6 @@ static struct irqaction ar71xx_gpio_irqaction = {
        .name           = "cascade [AR71XX GPIO]",
 };
 
-#define GPIO_IRQ_INIT_STATUS (IRQ_LEVEL | IRQ_TYPE_LEVEL_HIGH | IRQ_DISABLED)
 #define GPIO_INT_ALL   0xffff
 
 static void __init ar71xx_gpio_irq_init(void)
@@ -106,11 +105,9 @@ static void __init ar71xx_gpio_irq_init(void)
        __raw_writel(GPIO_INT_ALL, base + GPIO_REG_INT_POLARITY);
 
        for (i = AR71XX_GPIO_IRQ_BASE;
-            i < AR71XX_GPIO_IRQ_BASE + AR71XX_GPIO_IRQ_COUNT; i++) {
-               irq_desc[i].status = GPIO_IRQ_INIT_STATUS;
+            i < AR71XX_GPIO_IRQ_BASE + AR71XX_GPIO_IRQ_COUNT; i++)
                set_irq_chip_and_handler(i, &ar71xx_gpio_irq_chip,
                                         handle_level_irq);
-       }
 
        setup_irq(AR71XX_MISC_IRQ_GPIO, &ar71xx_gpio_irqaction);
 }
@@ -146,6 +143,21 @@ static void ar71xx_misc_irq_dispatch(void)
        else if (pending & MISC_INT_WDOG)
                do_IRQ(AR71XX_MISC_IRQ_WDOG);
 
+       else if (pending & MISC_INT_TIMER2)
+               do_IRQ(AR71XX_MISC_IRQ_TIMER2);
+
+       else if (pending & MISC_INT_TIMER3)
+               do_IRQ(AR71XX_MISC_IRQ_TIMER3);
+
+       else if (pending & MISC_INT_TIMER4)
+               do_IRQ(AR71XX_MISC_IRQ_TIMER4);
+
+       else if (pending & MISC_INT_DDR_PERF)
+               do_IRQ(AR71XX_MISC_IRQ_DDR_PERF);
+
+       else if (pending & MISC_INT_ENET_LINK)
+               do_IRQ(AR71XX_MISC_IRQ_ENET_LINK);
+
        else
                spurious_interrupt();
 }
@@ -215,6 +227,11 @@ static void __init ar71xx_misc_irq_init(void)
        case AR71XX_SOC_AR7240:
        case AR71XX_SOC_AR7241:
        case AR71XX_SOC_AR7242:
+       case AR71XX_SOC_AR9330:
+       case AR71XX_SOC_AR9331:
+       case AR71XX_SOC_AR9341:
+       case AR71XX_SOC_AR9342:
+       case AR71XX_SOC_AR9344:
                ar71xx_misc_irq_chip.ack = ar724x_misc_irq_ack;
                break;
        default:
@@ -223,15 +240,82 @@ static void __init ar71xx_misc_irq_init(void)
        }
 
        for (i = AR71XX_MISC_IRQ_BASE;
-            i < AR71XX_MISC_IRQ_BASE + AR71XX_MISC_IRQ_COUNT; i++) {
-               irq_desc[i].status = IRQ_DISABLED;
+            i < AR71XX_MISC_IRQ_BASE + AR71XX_MISC_IRQ_COUNT; i++)
                set_irq_chip_and_handler(i, &ar71xx_misc_irq_chip,
                                         handle_level_irq);
-       }
 
        setup_irq(AR71XX_CPU_IRQ_MISC, &ar71xx_misc_irqaction);
 }
 
+/*
+ * The IP2/IP3 lines are tied to a PCI/WMAC/USB device. Drivers for
+ * these devices typically allocate coherent DMA memory, however the
+ * DMA controller may still have some unsynchronized data in the FIFO.
+ * Issue a flush in the handlers to ensure that the driver sees
+ * the update.
+ */
+static void ar71xx_ip2_handler(void)
+{
+       ar71xx_ddr_flush(AR71XX_DDR_REG_FLUSH_PCI);
+       do_IRQ(AR71XX_CPU_IRQ_IP2);
+}
+
+static void ar724x_ip2_handler(void)
+{
+       ar71xx_ddr_flush(AR724X_DDR_REG_FLUSH_PCIE);
+       do_IRQ(AR71XX_CPU_IRQ_IP2);
+}
+
+static void ar913x_ip2_handler(void)
+{
+       ar71xx_ddr_flush(AR91XX_DDR_REG_FLUSH_WMAC);
+       do_IRQ(AR71XX_CPU_IRQ_IP2);
+}
+
+static void ar933x_ip2_handler(void)
+{
+       ar71xx_ddr_flush(AR933X_DDR_REG_FLUSH_WMAC);
+       do_IRQ(AR71XX_CPU_IRQ_IP2);
+}
+
+static void ar934x_ip2_handler(void)
+{
+       ar71xx_ddr_flush(AR934X_DDR_REG_FLUSH_PCIE);
+       do_IRQ(AR71XX_CPU_IRQ_IP2);
+}
+
+static void ar71xx_ip3_handler(void)
+{
+       ar71xx_ddr_flush(AR71XX_DDR_REG_FLUSH_USB);
+       do_IRQ(AR71XX_CPU_IRQ_USB);
+}
+
+static void ar724x_ip3_handler(void)
+{
+       ar71xx_ddr_flush(AR724X_DDR_REG_FLUSH_USB);
+       do_IRQ(AR71XX_CPU_IRQ_USB);
+}
+
+static void ar913x_ip3_handler(void)
+{
+       ar71xx_ddr_flush(AR91XX_DDR_REG_FLUSH_USB);
+       do_IRQ(AR71XX_CPU_IRQ_USB);
+}
+
+static void ar933x_ip3_handler(void)
+{
+       ar71xx_ddr_flush(AR933X_DDR_REG_FLUSH_USB);
+       do_IRQ(AR71XX_CPU_IRQ_USB);
+}
+
+static void ar934x_ip3_handler(void)
+{
+       do_IRQ(AR71XX_CPU_IRQ_USB);
+}
+
+static void (*ip2_handler)(void);
+static void (*ip3_handler)(void);
+
 asmlinkage void plat_irq_dispatch(void)
 {
        unsigned long pending;
@@ -241,17 +325,8 @@ asmlinkage void plat_irq_dispatch(void)
        if (pending & STATUSF_IP7)
                do_IRQ(AR71XX_CPU_IRQ_TIMER);
 
-       else if (pending & STATUSF_IP2) {
-               /*
-                * This IRQ is meant for a PCI device. Drivers for PCI devices
-                * typically allocate coherent DMA memory for the descriptor
-                * ring, however the DMA controller may still have some
-                * unsynchronized data in the FIFO.
-                * Issue a flush here to ensure that the driver sees the update.
-                */
-               ar71xx_ddr_flush(ip2_flush_reg);
-               do_IRQ(AR71XX_CPU_IRQ_IP2);
-       }
+       else if (pending & STATUSF_IP2)
+               ip2_handler();
 
        else if (pending & STATUSF_IP4)
                do_IRQ(AR71XX_CPU_IRQ_GE0);
@@ -260,31 +335,54 @@ asmlinkage void plat_irq_dispatch(void)
                do_IRQ(AR71XX_CPU_IRQ_GE1);
 
        else if (pending & STATUSF_IP3)
-               do_IRQ(AR71XX_CPU_IRQ_USB);
+               ip3_handler();
 
        else if (pending & STATUSF_IP6)
                ar71xx_misc_irq_dispatch();
 
-       else
-               spurious_interrupt();
+       spurious_interrupt();
 }
 
 void __init arch_init_irq(void)
 {
-       switch(ar71xx_soc) {
+       switch (ar71xx_soc) {
+       case AR71XX_SOC_AR7130:
+       case AR71XX_SOC_AR7141:
+       case AR71XX_SOC_AR7161:
+               ip2_handler = ar71xx_ip2_handler;
+               ip3_handler = ar71xx_ip3_handler;
+               break;
+
        case AR71XX_SOC_AR7240:
        case AR71XX_SOC_AR7241:
        case AR71XX_SOC_AR7242:
-               ip2_flush_reg = AR724X_DDR_REG_FLUSH_PCIE;
+               ip2_handler = ar724x_ip2_handler;
+               ip3_handler = ar724x_ip3_handler;
                break;
+
        case AR71XX_SOC_AR9130:
        case AR71XX_SOC_AR9132:
-               ip2_flush_reg = AR91XX_DDR_REG_FLUSH_WMAC;
+               ip2_handler = ar913x_ip2_handler;
+               ip3_handler = ar913x_ip3_handler;
                break;
-       default:
-               ip2_flush_reg = AR71XX_DDR_REG_FLUSH_PCI;
+
+       case AR71XX_SOC_AR9330:
+       case AR71XX_SOC_AR9331:
+               ip2_handler = ar933x_ip2_handler;
+               ip3_handler = ar933x_ip3_handler;
+               break;
+
+       case AR71XX_SOC_AR9341:
+       case AR71XX_SOC_AR9342:
+       case AR71XX_SOC_AR9344:
+               ip2_handler = ar934x_ip2_handler;
+               ip3_handler = ar934x_ip3_handler;
                break;
+
+       default:
+               BUG();
        }
+
        mips_cpu_irq_init();
 
        ar71xx_misc_irq_init();