1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25#include <linux/init.h>
26#include <linux/interrupt.h>
27#include <linux/of.h>
28
29static u32 ienable;
30
31asmlinkage 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
44static void chip_unmask(struct irq_data *d)
45{
46 ienable |= (1 << d->hwirq);
47 WRCTL(CTL_IENABLE, ienable);
48}
49
50static void chip_mask(struct irq_data *d)
51{
52 ienable &= ~(1 << d->hwirq);
53 WRCTL(CTL_IENABLE, ienable);
54}
55
56static struct irq_chip m_irq_chip = {
57 .name = "NIOS2-INTC",
58 .irq_unmask = chip_unmask,
59 .irq_mask = chip_mask,
60};
61
62static 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
70static const struct irq_domain_ops irq_ops = {
71 .map = irq_map,
72 .xlate = irq_domain_xlate_onecell,
73};
74
75void __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
92 ienable = RDCTL(CTL_IENABLE);
93}
94