2 * Copyright (C) 2014 Synopsys, Inc. (www.synopsys.com)
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
10 #include <linux/interrupt.h>
11 #include <linux/module.h>
13 #include <linux/irqdomain.h>
14 #include <linux/irqchip.h>
18 * Early Hardware specific Interrupt setup
19 * -Called very early (start_kernel -> setup_arch -> setup_processor)
20 * -Platform Independent (must for any ARC Core)
21 * -Needed for each CPU (hence not foldable into init_IRQ)
23 void arc_init_IRQ(void)
28 #ifdef CONFIG_CPU_BIG_ENDIAN
29 unsigned int res3
:18, save_idx_regs
:1, res2
:1,
30 save_u_to_u
:1, save_lp_regs
:1, save_blink
:1,
31 res
:4, save_nr_gpr_pairs
:5;
33 unsigned int save_nr_gpr_pairs
:5, res
:4,
34 save_blink
:1, save_lp_regs
:1, save_u_to_u
:1,
35 res2
:1, save_idx_regs
:1, res3
:18;
39 *(unsigned int *)&ictrl
= 0;
41 ictrl
.save_nr_gpr_pairs
= 6; /* r0 to r11 (r12 saved manually) */
43 ictrl
.save_lp_regs
= 1; /* LP_COUNT, LP_START, LP_END */
44 ictrl
.save_u_to_u
= 0; /* user ctxt saved on kernel stack */
45 ictrl
.save_idx_regs
= 1; /* JLI, LDI, EI */
47 WRITE_AUX(AUX_IRQ_CTRL
, ictrl
);
49 /* setup status32, don't enable intr yet as kernel doesn't want */
50 tmp
= read_aux_reg(0xa);
51 tmp
|= ISA_INIT_STATUS_BITS
;
52 tmp
&= ~STATUS_IE_MASK
;
53 asm volatile("flag %0 \n"::"r"(tmp
));
56 * ARCv2 core intc provides multiple interrupt priorities (upto 16).
57 * Typical builds though have only two levels (0-high, 1-low)
58 * Linux by default uses lower prio 1 for most irqs, reserving 0 for
59 * NMI style interrupts in future (say perf)
61 * Read the intc BCR to confirm that Linux default priority is avail
65 * IRQ_BCR[27..24] contains N-1 (for N priority levels) and prio level
68 tmp
= (read_aux_reg(ARC_REG_IRQ_BCR
) >> 24 ) & 0xF;
69 if (ARCV2_IRQ_DEF_PRIO
> tmp
)
70 panic("Linux default irq prio incorrect\n");
73 static void arcv2_irq_mask(struct irq_data
*data
)
75 write_aux_reg(AUX_IRQ_SELECT
, data
->irq
);
76 write_aux_reg(AUX_IRQ_ENABLE
, 0);
79 static void arcv2_irq_unmask(struct irq_data
*data
)
81 write_aux_reg(AUX_IRQ_SELECT
, data
->irq
);
82 write_aux_reg(AUX_IRQ_ENABLE
, 1);
85 void arcv2_irq_enable(struct irq_data
*data
)
87 /* set default priority */
88 write_aux_reg(AUX_IRQ_SELECT
, data
->irq
);
89 write_aux_reg(AUX_IRQ_PRIORITY
, ARCV2_IRQ_DEF_PRIO
);
92 * hw auto enables (linux unmask) all by default
93 * So no need to do IRQ_ENABLE here
94 * XXX: However OSCI LAN need it
96 write_aux_reg(AUX_IRQ_ENABLE
, 1);
99 static struct irq_chip arcv2_irq_chip
= {
100 .name
= "ARCv2 core Intc",
101 .irq_mask
= arcv2_irq_mask
,
102 .irq_unmask
= arcv2_irq_unmask
,
103 .irq_enable
= arcv2_irq_enable
106 static int arcv2_irq_map(struct irq_domain
*d
, unsigned int irq
,
110 * core intc IRQs [16, 23]:
111 * Statically assigned always private-per-core (Timers, WDT, IPI, PCT)
115 * A subsequent request_percpu_irq() fails if percpu_devid is
116 * not set. That in turns sets NOAUTOEN, meaning each core needs
117 * to call enable_percpu_irq()
119 irq_set_percpu_devid(irq
);
120 irq_set_chip_and_handler(irq
, &arcv2_irq_chip
, handle_percpu_irq
);
122 irq_set_chip_and_handler(irq
, &arcv2_irq_chip
, handle_level_irq
);
128 static const struct irq_domain_ops arcv2_irq_ops
= {
129 .xlate
= irq_domain_xlate_onecell
,
130 .map
= arcv2_irq_map
,
133 static struct irq_domain
*root_domain
;
136 init_onchip_IRQ(struct device_node
*intc
, struct device_node
*parent
)
139 panic("DeviceTree incore intc not a root irq controller\n");
141 root_domain
= irq_domain_add_legacy(intc
, NR_CPU_IRQS
, 0, 0,
142 &arcv2_irq_ops
, NULL
);
145 panic("root irq domain not avail\n");
147 /* with this we don't need to export root_domain */
148 irq_set_default_host(root_domain
);
153 IRQCHIP_DECLARE(arc_intc
, "snps,archs-intc", init_onchip_IRQ
);