diff options
author | Uwe Kleine-König <u.kleine-koenig@pengutronix.de> | 2013-06-26 03:18:48 -0400 |
---|---|---|
committer | Thomas Gleixner <tglx@linutronix.de> | 2013-06-26 05:29:38 -0400 |
commit | 292ec080491d87c888c29c5e161c10eb86e5961e (patch) | |
tree | f4e0bca3ed8c004b8d8687e1bee80c2f94a9b0f7 | |
parent | b06eb0173ef1d9366d14b4ca3e8e38dc72b03e8b (diff) |
irqchip: Add support for ARMv7-M NVIC
This interrupt controller is integrated in all Cortex-M3 and Cortex-M4
machines.
Support for this controller appeared in Catalin's Cortex tree based on
2.6.33 but was nearly completely rewritten.
Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Acked-by: Catalin Marinas <catalin.marinas@arm.com>
Acked-by: Arnd Bergmann <arnd@arndb.de>
Acked-by: Grant Likely <grant.likely@secretlab.ca>
Cc: linux-arm-kernel@lists.infradead.org
Cc: Jonathan Austin <jonathan.austin@arm.com>
Cc: kernel@pengutronix.de
Link: http://lkml.kernel.org/r/1372231128-11802-1-git-send-email-u.kleine-koenig@pengutronix.de
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
-rw-r--r-- | drivers/irqchip/Kconfig | 5 | ||||
-rw-r--r-- | drivers/irqchip/Makefile | 1 | ||||
-rw-r--r-- | drivers/irqchip/irq-nvic.c | 117 |
3 files changed, 123 insertions, 0 deletions
diff --git a/drivers/irqchip/Kconfig b/drivers/irqchip/Kconfig index d4d1f4bde10b..1fea003ed33f 100644 --- a/drivers/irqchip/Kconfig +++ b/drivers/irqchip/Kconfig | |||
@@ -10,6 +10,11 @@ config ARM_GIC | |||
10 | config GIC_NON_BANKED | 10 | config GIC_NON_BANKED |
11 | bool | 11 | bool |
12 | 12 | ||
13 | config ARM_NVIC | ||
14 | bool | ||
15 | select IRQ_DOMAIN | ||
16 | select GENERIC_IRQ_CHIP | ||
17 | |||
13 | config ARM_VIC | 18 | config ARM_VIC |
14 | bool | 19 | bool |
15 | select IRQ_DOMAIN | 20 | select IRQ_DOMAIN |
diff --git a/drivers/irqchip/Makefile b/drivers/irqchip/Makefile index 8fe6ad57ee4b..2065ef6a949c 100644 --- a/drivers/irqchip/Makefile +++ b/drivers/irqchip/Makefile | |||
@@ -11,6 +11,7 @@ obj-$(CONFIG_ORION_IRQCHIP) += irq-orion.o | |||
11 | obj-$(CONFIG_ARCH_SUNXI) += irq-sun4i.o | 11 | obj-$(CONFIG_ARCH_SUNXI) += irq-sun4i.o |
12 | obj-$(CONFIG_ARCH_SPEAR3XX) += spear-shirq.o | 12 | obj-$(CONFIG_ARCH_SPEAR3XX) += spear-shirq.o |
13 | obj-$(CONFIG_ARM_GIC) += irq-gic.o | 13 | obj-$(CONFIG_ARM_GIC) += irq-gic.o |
14 | obj-$(CONFIG_ARM_NVIC) += irq-nvic.o | ||
14 | obj-$(CONFIG_ARM_VIC) += irq-vic.o | 15 | obj-$(CONFIG_ARM_VIC) += irq-vic.o |
15 | obj-$(CONFIG_SIRF_IRQ) += irq-sirfsoc.o | 16 | obj-$(CONFIG_SIRF_IRQ) += irq-sirfsoc.o |
16 | obj-$(CONFIG_RENESAS_INTC_IRQPIN) += irq-renesas-intc-irqpin.o | 17 | obj-$(CONFIG_RENESAS_INTC_IRQPIN) += irq-renesas-intc-irqpin.o |
diff --git a/drivers/irqchip/irq-nvic.c b/drivers/irqchip/irq-nvic.c new file mode 100644 index 000000000000..8d0c8b3181c5 --- /dev/null +++ b/drivers/irqchip/irq-nvic.c | |||
@@ -0,0 +1,117 @@ | |||
1 | /* | ||
2 | * drivers/irq/irq-nvic.c | ||
3 | * | ||
4 | * Copyright (C) 2008 ARM Limited, All Rights Reserved. | ||
5 | * Copyright (C) 2013 Pengutronix | ||
6 | * | ||
7 | * This program is free software; you can redistribute it and/or modify | ||
8 | * it under the terms of the GNU General Public License version 2 as | ||
9 | * published by the Free Software Foundation. | ||
10 | * | ||
11 | * Support for the Nested Vectored Interrupt Controller found on the | ||
12 | * ARMv7-M CPUs (Cortex-M3/M4) | ||
13 | */ | ||
14 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt | ||
15 | |||
16 | #include <linux/init.h> | ||
17 | #include <linux/kernel.h> | ||
18 | #include <linux/slab.h> | ||
19 | #include <linux/err.h> | ||
20 | #include <linux/io.h> | ||
21 | #include <linux/of.h> | ||
22 | #include <linux/of_address.h> | ||
23 | #include <linux/irq.h> | ||
24 | #include <linux/irqdomain.h> | ||
25 | |||
26 | #include <asm/v7m.h> | ||
27 | #include <asm/exception.h> | ||
28 | |||
29 | #include "irqchip.h" | ||
30 | |||
31 | #define NVIC_ISER 0x000 | ||
32 | #define NVIC_ICER 0x080 | ||
33 | #define NVIC_IPR 0x300 | ||
34 | |||
35 | #define NVIC_MAX_BANKS 16 | ||
36 | /* | ||
37 | * Each bank handles 32 irqs. Only the 16th (= last) bank handles only | ||
38 | * 16 irqs. | ||
39 | */ | ||
40 | #define NVIC_MAX_IRQ ((NVIC_MAX_BANKS - 1) * 32 + 16) | ||
41 | |||
42 | static struct irq_domain *nvic_irq_domain; | ||
43 | |||
44 | asmlinkage void __exception_irq_entry | ||
45 | nvic_handle_irq(irq_hw_number_t hwirq, struct pt_regs *regs) | ||
46 | { | ||
47 | unsigned int irq = irq_linear_revmap(nvic_irq_domain, hwirq); | ||
48 | |||
49 | handle_IRQ(irq, regs); | ||
50 | } | ||
51 | |||
52 | static void nvic_eoi(struct irq_data *d) | ||
53 | { | ||
54 | /* | ||
55 | * This is a no-op as end of interrupt is signaled by the exception | ||
56 | * return sequence. | ||
57 | */ | ||
58 | } | ||
59 | |||
60 | static int __init nvic_of_init(struct device_node *node, | ||
61 | struct device_node *parent) | ||
62 | { | ||
63 | unsigned int clr = IRQ_NOREQUEST | IRQ_NOPROBE | IRQ_NOAUTOEN; | ||
64 | unsigned int irqs, i, ret, numbanks; | ||
65 | void __iomem *nvic_base; | ||
66 | |||
67 | numbanks = (readl_relaxed(V7M_SCS_ICTR) & | ||
68 | V7M_SCS_ICTR_INTLINESNUM_MASK) + 1; | ||
69 | |||
70 | nvic_base = of_iomap(node, 0); | ||
71 | if (!nvic_base) { | ||
72 | pr_warn("unable to map nvic registers\n"); | ||
73 | return -ENOMEM; | ||
74 | } | ||
75 | |||
76 | irqs = numbanks * 32; | ||
77 | if (irqs > NVIC_MAX_IRQ) | ||
78 | irqs = NVIC_MAX_IRQ; | ||
79 | |||
80 | nvic_irq_domain = | ||
81 | irq_domain_add_linear(node, irqs, &irq_generic_chip_ops, NULL); | ||
82 | if (!nvic_irq_domain) { | ||
83 | pr_warn("Failed to allocate irq domain\n"); | ||
84 | return -ENOMEM; | ||
85 | } | ||
86 | |||
87 | ret = irq_alloc_domain_generic_chips(nvic_irq_domain, 32, numbanks, | ||
88 | "nvic_irq", handle_fasteoi_irq, | ||
89 | clr, 0, IRQ_GC_INIT_MASK_CACHE); | ||
90 | if (ret) { | ||
91 | pr_warn("Failed to allocate irq chips\n"); | ||
92 | irq_domain_remove(nvic_irq_domain); | ||
93 | return ret; | ||
94 | } | ||
95 | |||
96 | for (i = 0; i < numbanks; ++i) { | ||
97 | struct irq_chip_generic *gc; | ||
98 | |||
99 | gc = irq_get_domain_generic_chip(nvic_irq_domain, 32 * i); | ||
100 | gc->reg_base = nvic_base + 4 * i; | ||
101 | gc->chip_types[0].regs.enable = NVIC_ISER; | ||
102 | gc->chip_types[0].regs.disable = NVIC_ICER; | ||
103 | gc->chip_types[0].chip.irq_mask = irq_gc_mask_disable_reg; | ||
104 | gc->chip_types[0].chip.irq_unmask = irq_gc_unmask_enable_reg; | ||
105 | gc->chip_types[0].chip.irq_eoi = nvic_eoi; | ||
106 | |||
107 | /* disable interrupts */ | ||
108 | writel_relaxed(~0, gc->reg_base + NVIC_ICER); | ||
109 | } | ||
110 | |||
111 | /* Set priority on all interrupts */ | ||
112 | for (i = 0; i < irqs; i += 4) | ||
113 | writel_relaxed(0, nvic_base + NVIC_IPR + i); | ||
114 | |||
115 | return 0; | ||
116 | } | ||
117 | IRQCHIP_DECLARE(armv7m_nvic, "arm,armv7m-nvic", nvic_of_init); | ||