diff options
author | Thomas Petazzoni <thomas.petazzoni@free-electrons.com> | 2013-04-09 17:26:15 -0400 |
---|---|---|
committer | Jason Cooper <jason@lakedaemon.net> | 2013-04-15 15:34:36 -0400 |
commit | 9339d432fdf4b492d2209316791b6e54cdae0242 (patch) | |
tree | 7ae6520bbff2508776bb04c41ee48e15d9cb74e7 /drivers/irqchip/irq-armada-370-xp.c | |
parent | e33369cbf346a41daab7d2eaf23c7e5bb76ef67c (diff) |
irqchip: move IRQ driver for Armada 370/XP
When the Marvell Armada 370/XP support was included in the kernel, the
drivers/irqchip/ directory didn't exist and the minimal infrastructure
in it also didn't exist. Now that we have those things in place, we
move the Armada 370/XP IRQ controller driver from
arch/arm/mach-mvebu/irq-armada-370-xp.c to
drivers/irqchip/irq-armada-370-xp.c.
Note in order to reduce code movement and therefore ease the review of
this patch, we intentionally introduce a forward declaration of
armada_370_xp_handle_irq(). It is in fact not needed because this
handler can now simply be implemented before
armada_370_xp_mpic_of_init(). That will be done in the next commit.
Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
Tested-by: Ezequiel Garcia <ezequiel.garcia@free-electrons.com>
Signed-off-by: Jason Cooper <jason@lakedaemon.net>
Diffstat (limited to 'drivers/irqchip/irq-armada-370-xp.c')
-rw-r--r-- | drivers/irqchip/irq-armada-370-xp.c | 294 |
1 files changed, 294 insertions, 0 deletions
diff --git a/drivers/irqchip/irq-armada-370-xp.c b/drivers/irqchip/irq-armada-370-xp.c new file mode 100644 index 000000000000..d20a832ba86b --- /dev/null +++ b/drivers/irqchip/irq-armada-370-xp.c | |||
@@ -0,0 +1,294 @@ | |||
1 | /* | ||
2 | * Marvell Armada 370 and Armada XP SoC IRQ handling | ||
3 | * | ||
4 | * Copyright (C) 2012 Marvell | ||
5 | * | ||
6 | * Lior Amsalem <alior@marvell.com> | ||
7 | * Gregory CLEMENT <gregory.clement@free-electrons.com> | ||
8 | * Thomas Petazzoni <thomas.petazzoni@free-electrons.com> | ||
9 | * Ben Dooks <ben.dooks@codethink.co.uk> | ||
10 | * | ||
11 | * This file is licensed under the terms of the GNU General Public | ||
12 | * License version 2. This program is licensed "as is" without any | ||
13 | * warranty of any kind, whether express or implied. | ||
14 | */ | ||
15 | |||
16 | #include <linux/kernel.h> | ||
17 | #include <linux/module.h> | ||
18 | #include <linux/init.h> | ||
19 | #include <linux/irq.h> | ||
20 | #include <linux/interrupt.h> | ||
21 | #include <linux/io.h> | ||
22 | #include <linux/of_address.h> | ||
23 | #include <linux/of_irq.h> | ||
24 | #include <linux/irqdomain.h> | ||
25 | #include <asm/mach/arch.h> | ||
26 | #include <asm/exception.h> | ||
27 | #include <asm/smp_plat.h> | ||
28 | #include <asm/mach/irq.h> | ||
29 | |||
30 | #include "irqchip.h" | ||
31 | |||
32 | /* Interrupt Controller Registers Map */ | ||
33 | #define ARMADA_370_XP_INT_SET_MASK_OFFS (0x48) | ||
34 | #define ARMADA_370_XP_INT_CLEAR_MASK_OFFS (0x4C) | ||
35 | |||
36 | #define ARMADA_370_XP_INT_CONTROL (0x00) | ||
37 | #define ARMADA_370_XP_INT_SET_ENABLE_OFFS (0x30) | ||
38 | #define ARMADA_370_XP_INT_CLEAR_ENABLE_OFFS (0x34) | ||
39 | #define ARMADA_370_XP_INT_SOURCE_CTL(irq) (0x100 + irq*4) | ||
40 | |||
41 | #define ARMADA_370_XP_CPU_INTACK_OFFS (0x44) | ||
42 | |||
43 | #define ARMADA_370_XP_SW_TRIG_INT_OFFS (0x4) | ||
44 | #define ARMADA_370_XP_IN_DRBEL_MSK_OFFS (0xc) | ||
45 | #define ARMADA_370_XP_IN_DRBEL_CAUSE_OFFS (0x8) | ||
46 | |||
47 | #define ARMADA_370_XP_MAX_PER_CPU_IRQS (28) | ||
48 | |||
49 | #define ARMADA_370_XP_TIMER0_PER_CPU_IRQ (5) | ||
50 | |||
51 | #define ACTIVE_DOORBELLS (8) | ||
52 | |||
53 | static DEFINE_RAW_SPINLOCK(irq_controller_lock); | ||
54 | |||
55 | static void __iomem *per_cpu_int_base; | ||
56 | static void __iomem *main_int_base; | ||
57 | static struct irq_domain *armada_370_xp_mpic_domain; | ||
58 | |||
59 | /* | ||
60 | * In SMP mode: | ||
61 | * For shared global interrupts, mask/unmask global enable bit | ||
62 | * For CPU interrtups, mask/unmask the calling CPU's bit | ||
63 | */ | ||
64 | static void armada_370_xp_irq_mask(struct irq_data *d) | ||
65 | { | ||
66 | #ifdef CONFIG_SMP | ||
67 | irq_hw_number_t hwirq = irqd_to_hwirq(d); | ||
68 | |||
69 | if (hwirq != ARMADA_370_XP_TIMER0_PER_CPU_IRQ) | ||
70 | writel(hwirq, main_int_base + | ||
71 | ARMADA_370_XP_INT_CLEAR_ENABLE_OFFS); | ||
72 | else | ||
73 | writel(hwirq, per_cpu_int_base + | ||
74 | ARMADA_370_XP_INT_SET_MASK_OFFS); | ||
75 | #else | ||
76 | writel(irqd_to_hwirq(d), | ||
77 | per_cpu_int_base + ARMADA_370_XP_INT_SET_MASK_OFFS); | ||
78 | #endif | ||
79 | } | ||
80 | |||
81 | static void armada_370_xp_irq_unmask(struct irq_data *d) | ||
82 | { | ||
83 | #ifdef CONFIG_SMP | ||
84 | irq_hw_number_t hwirq = irqd_to_hwirq(d); | ||
85 | |||
86 | if (hwirq != ARMADA_370_XP_TIMER0_PER_CPU_IRQ) | ||
87 | writel(hwirq, main_int_base + | ||
88 | ARMADA_370_XP_INT_SET_ENABLE_OFFS); | ||
89 | else | ||
90 | writel(hwirq, per_cpu_int_base + | ||
91 | ARMADA_370_XP_INT_CLEAR_MASK_OFFS); | ||
92 | #else | ||
93 | writel(irqd_to_hwirq(d), | ||
94 | per_cpu_int_base + ARMADA_370_XP_INT_CLEAR_MASK_OFFS); | ||
95 | #endif | ||
96 | } | ||
97 | |||
98 | #ifdef CONFIG_SMP | ||
99 | static int armada_xp_set_affinity(struct irq_data *d, | ||
100 | const struct cpumask *mask_val, bool force) | ||
101 | { | ||
102 | unsigned long reg; | ||
103 | unsigned long new_mask = 0; | ||
104 | unsigned long online_mask = 0; | ||
105 | unsigned long count = 0; | ||
106 | irq_hw_number_t hwirq = irqd_to_hwirq(d); | ||
107 | int cpu; | ||
108 | |||
109 | for_each_cpu(cpu, mask_val) { | ||
110 | new_mask |= 1 << cpu_logical_map(cpu); | ||
111 | count++; | ||
112 | } | ||
113 | |||
114 | /* | ||
115 | * Forbid mutlicore interrupt affinity | ||
116 | * This is required since the MPIC HW doesn't limit | ||
117 | * several CPUs from acknowledging the same interrupt. | ||
118 | */ | ||
119 | if (count > 1) | ||
120 | return -EINVAL; | ||
121 | |||
122 | for_each_cpu(cpu, cpu_online_mask) | ||
123 | online_mask |= 1 << cpu_logical_map(cpu); | ||
124 | |||
125 | raw_spin_lock(&irq_controller_lock); | ||
126 | |||
127 | reg = readl(main_int_base + ARMADA_370_XP_INT_SOURCE_CTL(hwirq)); | ||
128 | reg = (reg & (~online_mask)) | new_mask; | ||
129 | writel(reg, main_int_base + ARMADA_370_XP_INT_SOURCE_CTL(hwirq)); | ||
130 | |||
131 | raw_spin_unlock(&irq_controller_lock); | ||
132 | |||
133 | return 0; | ||
134 | } | ||
135 | #endif | ||
136 | |||
137 | static struct irq_chip armada_370_xp_irq_chip = { | ||
138 | .name = "armada_370_xp_irq", | ||
139 | .irq_mask = armada_370_xp_irq_mask, | ||
140 | .irq_mask_ack = armada_370_xp_irq_mask, | ||
141 | .irq_unmask = armada_370_xp_irq_unmask, | ||
142 | #ifdef CONFIG_SMP | ||
143 | .irq_set_affinity = armada_xp_set_affinity, | ||
144 | #endif | ||
145 | }; | ||
146 | |||
147 | static int armada_370_xp_mpic_irq_map(struct irq_domain *h, | ||
148 | unsigned int virq, irq_hw_number_t hw) | ||
149 | { | ||
150 | armada_370_xp_irq_mask(irq_get_irq_data(virq)); | ||
151 | writel(hw, main_int_base + ARMADA_370_XP_INT_SET_ENABLE_OFFS); | ||
152 | irq_set_status_flags(virq, IRQ_LEVEL); | ||
153 | |||
154 | if (hw == ARMADA_370_XP_TIMER0_PER_CPU_IRQ) { | ||
155 | irq_set_percpu_devid(virq); | ||
156 | irq_set_chip_and_handler(virq, &armada_370_xp_irq_chip, | ||
157 | handle_percpu_devid_irq); | ||
158 | |||
159 | } else { | ||
160 | irq_set_chip_and_handler(virq, &armada_370_xp_irq_chip, | ||
161 | handle_level_irq); | ||
162 | } | ||
163 | set_irq_flags(virq, IRQF_VALID | IRQF_PROBE); | ||
164 | |||
165 | return 0; | ||
166 | } | ||
167 | |||
168 | #ifdef CONFIG_SMP | ||
169 | void armada_mpic_send_doorbell(const struct cpumask *mask, unsigned int irq) | ||
170 | { | ||
171 | int cpu; | ||
172 | unsigned long map = 0; | ||
173 | |||
174 | /* Convert our logical CPU mask into a physical one. */ | ||
175 | for_each_cpu(cpu, mask) | ||
176 | map |= 1 << cpu_logical_map(cpu); | ||
177 | |||
178 | /* | ||
179 | * Ensure that stores to Normal memory are visible to the | ||
180 | * other CPUs before issuing the IPI. | ||
181 | */ | ||
182 | dsb(); | ||
183 | |||
184 | /* submit softirq */ | ||
185 | writel((map << 8) | irq, main_int_base + | ||
186 | ARMADA_370_XP_SW_TRIG_INT_OFFS); | ||
187 | } | ||
188 | |||
189 | void armada_xp_mpic_smp_cpu_init(void) | ||
190 | { | ||
191 | /* Clear pending IPIs */ | ||
192 | writel(0, per_cpu_int_base + ARMADA_370_XP_IN_DRBEL_CAUSE_OFFS); | ||
193 | |||
194 | /* Enable first 8 IPIs */ | ||
195 | writel((1 << ACTIVE_DOORBELLS) - 1, per_cpu_int_base + | ||
196 | ARMADA_370_XP_IN_DRBEL_MSK_OFFS); | ||
197 | |||
198 | /* Unmask IPI interrupt */ | ||
199 | writel(0, per_cpu_int_base + ARMADA_370_XP_INT_CLEAR_MASK_OFFS); | ||
200 | } | ||
201 | #endif /* CONFIG_SMP */ | ||
202 | |||
203 | static struct irq_domain_ops armada_370_xp_mpic_irq_ops = { | ||
204 | .map = armada_370_xp_mpic_irq_map, | ||
205 | .xlate = irq_domain_xlate_onecell, | ||
206 | }; | ||
207 | |||
208 | static asmlinkage void __exception_irq_entry | ||
209 | armada_370_xp_handle_irq(struct pt_regs *regs); | ||
210 | |||
211 | static int __init armada_370_xp_mpic_of_init(struct device_node *node, | ||
212 | struct device_node *parent) | ||
213 | { | ||
214 | u32 control; | ||
215 | |||
216 | main_int_base = of_iomap(node, 0); | ||
217 | per_cpu_int_base = of_iomap(node, 1); | ||
218 | |||
219 | BUG_ON(!main_int_base); | ||
220 | BUG_ON(!per_cpu_int_base); | ||
221 | |||
222 | control = readl(main_int_base + ARMADA_370_XP_INT_CONTROL); | ||
223 | |||
224 | armada_370_xp_mpic_domain = | ||
225 | irq_domain_add_linear(node, (control >> 2) & 0x3ff, | ||
226 | &armada_370_xp_mpic_irq_ops, NULL); | ||
227 | |||
228 | if (!armada_370_xp_mpic_domain) | ||
229 | panic("Unable to add Armada_370_Xp MPIC irq domain (DT)\n"); | ||
230 | |||
231 | irq_set_default_host(armada_370_xp_mpic_domain); | ||
232 | |||
233 | #ifdef CONFIG_SMP | ||
234 | armada_xp_mpic_smp_cpu_init(); | ||
235 | |||
236 | /* | ||
237 | * Set the default affinity from all CPUs to the boot cpu. | ||
238 | * This is required since the MPIC doesn't limit several CPUs | ||
239 | * from acknowledging the same interrupt. | ||
240 | */ | ||
241 | cpumask_clear(irq_default_affinity); | ||
242 | cpumask_set_cpu(smp_processor_id(), irq_default_affinity); | ||
243 | |||
244 | #endif | ||
245 | |||
246 | set_handle_irq(armada_370_xp_handle_irq); | ||
247 | |||
248 | return 0; | ||
249 | } | ||
250 | |||
251 | static asmlinkage void __exception_irq_entry | ||
252 | armada_370_xp_handle_irq(struct pt_regs *regs) | ||
253 | { | ||
254 | u32 irqstat, irqnr; | ||
255 | |||
256 | do { | ||
257 | irqstat = readl_relaxed(per_cpu_int_base + | ||
258 | ARMADA_370_XP_CPU_INTACK_OFFS); | ||
259 | irqnr = irqstat & 0x3FF; | ||
260 | |||
261 | if (irqnr > 1022) | ||
262 | break; | ||
263 | |||
264 | if (irqnr > 0) { | ||
265 | irqnr = irq_find_mapping(armada_370_xp_mpic_domain, | ||
266 | irqnr); | ||
267 | handle_IRQ(irqnr, regs); | ||
268 | continue; | ||
269 | } | ||
270 | #ifdef CONFIG_SMP | ||
271 | /* IPI Handling */ | ||
272 | if (irqnr == 0) { | ||
273 | u32 ipimask, ipinr; | ||
274 | |||
275 | ipimask = readl_relaxed(per_cpu_int_base + | ||
276 | ARMADA_370_XP_IN_DRBEL_CAUSE_OFFS) | ||
277 | & 0xFF; | ||
278 | |||
279 | writel(0x0, per_cpu_int_base + | ||
280 | ARMADA_370_XP_IN_DRBEL_CAUSE_OFFS); | ||
281 | |||
282 | /* Handle all pending doorbells */ | ||
283 | for (ipinr = 0; ipinr < ACTIVE_DOORBELLS; ipinr++) { | ||
284 | if (ipimask & (0x1 << ipinr)) | ||
285 | handle_IPI(ipinr, regs); | ||
286 | } | ||
287 | continue; | ||
288 | } | ||
289 | #endif | ||
290 | |||
291 | } while (1); | ||
292 | } | ||
293 | |||
294 | IRQCHIP_DECLARE(armada_370_xp_mpic, "marvell,mpic", armada_370_xp_mpic_of_init); | ||