diff options
author | Ley Foon Tan <lftan@altera.com> | 2014-11-06 02:19:52 -0500 |
---|---|---|
committer | Ley Foon Tan <lftan@altera.com> | 2014-12-07 23:55:55 -0500 |
commit | f27ffc751ca5d216a347084996c70452a4e185a4 (patch) | |
tree | 11ba83ebdd3837f00a2ebfca4d7528aa75f80793 /arch/nios2 | |
parent | c983e92fcba7c7e54c796941f42514d94dd6cccc (diff) |
nios2: Interrupt handling
This patch adds the support for IRQ handling.
Signed-off-by: Ley Foon Tan <lftan@altera.com>
Reviewed-by: Thomas Gleixner <tglx@linutronix.de>
Diffstat (limited to 'arch/nios2')
-rw-r--r-- | arch/nios2/include/asm/irq.h | 28 | ||||
-rw-r--r-- | arch/nios2/include/asm/irqflags.h | 72 | ||||
-rw-r--r-- | arch/nios2/kernel/irq.c | 93 |
3 files changed, 193 insertions, 0 deletions
diff --git a/arch/nios2/include/asm/irq.h b/arch/nios2/include/asm/irq.h new file mode 100644 index 000000000000..8e40fd94a36c --- /dev/null +++ b/arch/nios2/include/asm/irq.h | |||
@@ -0,0 +1,28 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2013 Altera Corporation | ||
3 | * Copyright (C) 2011 Tobias Klauser <tklauser@distanz.ch> | ||
4 | * | ||
5 | * This program is free software; you can redistribute it and/or modify | ||
6 | * it under the terms of the GNU General Public License as published by | ||
7 | * the Free Software Foundation; either version 2 of the License, or | ||
8 | * (at your option) any later version. | ||
9 | * | ||
10 | * This program is distributed in the hope that it will be useful, | ||
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | * GNU General Public License for more details. | ||
14 | * | ||
15 | * You should have received a copy of the GNU General Public License | ||
16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
17 | * | ||
18 | */ | ||
19 | |||
20 | #ifndef _ASM_NIOS2_IRQ_H | ||
21 | #define _ASM_NIOS2_IRQ_H | ||
22 | |||
23 | #define NIOS2_CPU_NR_IRQS 32 | ||
24 | |||
25 | #include <asm-generic/irq.h> | ||
26 | #include <linux/irqdomain.h> | ||
27 | |||
28 | #endif | ||
diff --git a/arch/nios2/include/asm/irqflags.h b/arch/nios2/include/asm/irqflags.h new file mode 100644 index 000000000000..75ab92e639f8 --- /dev/null +++ b/arch/nios2/include/asm/irqflags.h | |||
@@ -0,0 +1,72 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2010 Thomas Chou <thomas@wytron.com.tw> | ||
3 | * | ||
4 | * This program is free software; you can redistribute it and/or modify | ||
5 | * it under the terms of the GNU General Public License as published by | ||
6 | * the Free Software Foundation; either version 2 of the License, or | ||
7 | * (at your option) any later version. | ||
8 | * | ||
9 | * This program is distributed in the hope that it will be useful, | ||
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | * GNU General Public License for more details. | ||
13 | * | ||
14 | * You should have received a copy of the GNU General Public License | ||
15 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
16 | * | ||
17 | */ | ||
18 | #ifndef _ASM_IRQFLAGS_H | ||
19 | #define _ASM_IRQFLAGS_H | ||
20 | |||
21 | #include <asm/registers.h> | ||
22 | |||
23 | static inline unsigned long arch_local_save_flags(void) | ||
24 | { | ||
25 | return RDCTL(CTL_STATUS); | ||
26 | } | ||
27 | |||
28 | /* | ||
29 | * This will restore ALL status register flags, not only the interrupt | ||
30 | * mask flag. | ||
31 | */ | ||
32 | static inline void arch_local_irq_restore(unsigned long flags) | ||
33 | { | ||
34 | WRCTL(CTL_STATUS, flags); | ||
35 | } | ||
36 | |||
37 | static inline void arch_local_irq_disable(void) | ||
38 | { | ||
39 | unsigned long flags; | ||
40 | |||
41 | flags = arch_local_save_flags(); | ||
42 | arch_local_irq_restore(flags & ~STATUS_PIE); | ||
43 | } | ||
44 | |||
45 | static inline void arch_local_irq_enable(void) | ||
46 | { | ||
47 | unsigned long flags; | ||
48 | |||
49 | flags = arch_local_save_flags(); | ||
50 | arch_local_irq_restore(flags | STATUS_PIE); | ||
51 | } | ||
52 | |||
53 | static inline int arch_irqs_disabled_flags(unsigned long flags) | ||
54 | { | ||
55 | return (flags & STATUS_PIE) == 0; | ||
56 | } | ||
57 | |||
58 | static inline int arch_irqs_disabled(void) | ||
59 | { | ||
60 | return arch_irqs_disabled_flags(arch_local_save_flags()); | ||
61 | } | ||
62 | |||
63 | static inline unsigned long arch_local_irq_save(void) | ||
64 | { | ||
65 | unsigned long flags; | ||
66 | |||
67 | flags = arch_local_save_flags(); | ||
68 | arch_local_irq_restore(flags & ~STATUS_PIE); | ||
69 | return flags; | ||
70 | } | ||
71 | |||
72 | #endif /* _ASM_IRQFLAGS_H */ | ||
diff --git a/arch/nios2/kernel/irq.c b/arch/nios2/kernel/irq.c new file mode 100644 index 000000000000..f5b74ae69b5b --- /dev/null +++ b/arch/nios2/kernel/irq.c | |||
@@ -0,0 +1,93 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2013 Altera Corporation | ||
3 | * Copyright (C) 2011 Tobias Klauser <tklauser@distanz.ch> | ||
4 | * Copyright (C) 2008 Thomas Chou <thomas@wytron.com.tw> | ||
5 | * | ||
6 | * based on irq.c from m68k which is: | ||
7 | * | ||
8 | * Copyright (C) 2007 Greg Ungerer <gerg@snapgear.com> | ||
9 | * | ||
10 | * This program is free software; you can redistribute it and/or modify | ||
11 | * it under the terms of the GNU General Public License as published by | ||
12 | * the Free Software Foundation; either version 2 of the License, or | ||
13 | * (at your option) any later version. | ||
14 | * | ||
15 | * This program is distributed in the hope that it will be useful, | ||
16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
18 | * GNU General Public License for more details. | ||
19 | * | ||
20 | * You should have received a copy of the GNU General Public License | ||
21 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
22 | * | ||
23 | */ | ||
24 | |||
25 | #include <linux/init.h> | ||
26 | #include <linux/interrupt.h> | ||
27 | #include <linux/of.h> | ||
28 | |||
29 | static u32 ienable; | ||
30 | |||
31 | asmlinkage void do_IRQ(int hwirq, struct pt_regs *regs) | ||
32 | { | ||
33 | struct pt_regs *oldregs = set_irq_regs(regs); | ||
34 | int irq; | ||
35 | |||
36 | irq_enter(); | ||
37 | irq = irq_find_mapping(NULL, hwirq); | ||
38 | generic_handle_irq(irq); | ||
39 | irq_exit(); | ||
40 | |||
41 | set_irq_regs(oldregs); | ||
42 | } | ||
43 | |||
44 | static void chip_unmask(struct irq_data *d) | ||
45 | { | ||
46 | ienable |= (1 << d->hwirq); | ||
47 | WRCTL(CTL_IENABLE, ienable); | ||
48 | } | ||
49 | |||
50 | static void chip_mask(struct irq_data *d) | ||
51 | { | ||
52 | ienable &= ~(1 << d->hwirq); | ||
53 | WRCTL(CTL_IENABLE, ienable); | ||
54 | } | ||
55 | |||
56 | static struct irq_chip m_irq_chip = { | ||
57 | .name = "NIOS2-INTC", | ||
58 | .irq_unmask = chip_unmask, | ||
59 | .irq_mask = chip_mask, | ||
60 | }; | ||
61 | |||
62 | static int irq_map(struct irq_domain *h, unsigned int virq, | ||
63 | irq_hw_number_t hw_irq_num) | ||
64 | { | ||
65 | irq_set_chip_and_handler(virq, &m_irq_chip, handle_level_irq); | ||
66 | |||
67 | return 0; | ||
68 | } | ||
69 | |||
70 | static struct irq_domain_ops irq_ops = { | ||
71 | .map = irq_map, | ||
72 | .xlate = irq_domain_xlate_onecell, | ||
73 | }; | ||
74 | |||
75 | void __init init_IRQ(void) | ||
76 | { | ||
77 | struct irq_domain *domain; | ||
78 | struct device_node *node; | ||
79 | |||
80 | node = of_find_compatible_node(NULL, NULL, "altr,nios2-1.0"); | ||
81 | if (!node) | ||
82 | node = of_find_compatible_node(NULL, NULL, "altr,nios2-1.1"); | ||
83 | |||
84 | BUG_ON(!node); | ||
85 | |||
86 | domain = irq_domain_add_linear(node, NIOS2_CPU_NR_IRQS, &irq_ops, NULL); | ||
87 | BUG_ON(!domain); | ||
88 | |||
89 | irq_set_default_host(domain); | ||
90 | of_node_put(node); | ||
91 | /* Load the initial ienable value */ | ||
92 | ienable = RDCTL(CTL_IENABLE); | ||
93 | } | ||