blob: 304a20d0ad15fb50f52bcb5c1ae1d37a7574e578 [file] [log] [blame]
Thomas Petazzoni9ae6f742012-06-13 19:01:28 +02001/*
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>
Ezequiel Garciabc69b8a2014-02-10 17:00:02 -030021#include <linux/irqchip/chained_irq.h>
Thomas Petazzoni9ae6f742012-06-13 19:01:28 +020022#include <linux/io.h>
23#include <linux/of_address.h>
24#include <linux/of_irq.h>
Thomas Petazzoni31f614e2013-08-09 22:27:11 +020025#include <linux/of_pci.h>
Thomas Petazzoni9ae6f742012-06-13 19:01:28 +020026#include <linux/irqdomain.h>
Thomas Petazzoni31f614e2013-08-09 22:27:11 +020027#include <linux/slab.h>
28#include <linux/msi.h>
Thomas Petazzoni9ae6f742012-06-13 19:01:28 +020029#include <asm/mach/arch.h>
30#include <asm/exception.h>
Gregory CLEMENT344e8732012-08-02 11:19:12 +030031#include <asm/smp_plat.h>
Thomas Petazzoni9339d432013-04-09 23:26:15 +020032#include <asm/mach/irq.h>
33
34#include "irqchip.h"
Thomas Petazzoni9ae6f742012-06-13 19:01:28 +020035
36/* Interrupt Controller Registers Map */
37#define ARMADA_370_XP_INT_SET_MASK_OFFS (0x48)
38#define ARMADA_370_XP_INT_CLEAR_MASK_OFFS (0x4C)
39
Ben Dooksf3e16cc2012-06-04 18:50:12 +020040#define ARMADA_370_XP_INT_CONTROL (0x00)
Thomas Petazzoni9ae6f742012-06-13 19:01:28 +020041#define ARMADA_370_XP_INT_SET_ENABLE_OFFS (0x30)
42#define ARMADA_370_XP_INT_CLEAR_ENABLE_OFFS (0x34)
Gregory CLEMENT3202bf02012-12-05 21:43:23 +010043#define ARMADA_370_XP_INT_SOURCE_CTL(irq) (0x100 + irq*4)
Thomas Gleixner8cc3cfc2014-03-04 20:43:41 +000044#define ARMADA_370_XP_INT_SOURCE_CPU_MASK 0xF
Thomas Petazzoni9ae6f742012-06-13 19:01:28 +020045
46#define ARMADA_370_XP_CPU_INTACK_OFFS (0x44)
Ezequiel Garciabc69b8a2014-02-10 17:00:02 -030047#define ARMADA_375_PPI_CAUSE (0x10)
Thomas Petazzoni9ae6f742012-06-13 19:01:28 +020048
Gregory CLEMENT344e8732012-08-02 11:19:12 +030049#define ARMADA_370_XP_SW_TRIG_INT_OFFS (0x4)
50#define ARMADA_370_XP_IN_DRBEL_MSK_OFFS (0xc)
51#define ARMADA_370_XP_IN_DRBEL_CAUSE_OFFS (0x8)
52
Gregory CLEMENT3202bf02012-12-05 21:43:23 +010053#define ARMADA_370_XP_MAX_PER_CPU_IRQS (28)
54
Gregory CLEMENT7f23f622013-03-20 16:09:35 +010055#define ARMADA_370_XP_TIMER0_PER_CPU_IRQ (5)
56
Thomas Petazzoni5ec69012013-04-09 23:26:17 +020057#define IPI_DOORBELL_START (0)
58#define IPI_DOORBELL_END (8)
59#define IPI_DOORBELL_MASK 0xFF
Thomas Petazzoni31f614e2013-08-09 22:27:11 +020060#define PCI_MSI_DOORBELL_START (16)
61#define PCI_MSI_DOORBELL_NR (16)
62#define PCI_MSI_DOORBELL_END (32)
63#define PCI_MSI_DOORBELL_MASK 0xFFFF0000
Gregory CLEMENT344e8732012-08-02 11:19:12 +030064
Thomas Petazzoni9ae6f742012-06-13 19:01:28 +020065static void __iomem *per_cpu_int_base;
66static void __iomem *main_int_base;
67static struct irq_domain *armada_370_xp_mpic_domain;
Thomas Petazzoni31f614e2013-08-09 22:27:11 +020068#ifdef CONFIG_PCI_MSI
69static struct irq_domain *armada_370_xp_msi_domain;
70static DECLARE_BITMAP(msi_used, PCI_MSI_DOORBELL_NR);
71static DEFINE_MUTEX(msi_used_lock);
72static phys_addr_t msi_doorbell_addr;
73#endif
Thomas Petazzoni9ae6f742012-06-13 19:01:28 +020074
Gregory CLEMENT3202bf02012-12-05 21:43:23 +010075/*
76 * In SMP mode:
77 * For shared global interrupts, mask/unmask global enable bit
Marek Belisko097ef182013-03-15 23:34:04 +010078 * For CPU interrupts, mask/unmask the calling CPU's bit
Gregory CLEMENT3202bf02012-12-05 21:43:23 +010079 */
Thomas Petazzoni9ae6f742012-06-13 19:01:28 +020080static void armada_370_xp_irq_mask(struct irq_data *d)
81{
Gregory CLEMENT3202bf02012-12-05 21:43:23 +010082 irq_hw_number_t hwirq = irqd_to_hwirq(d);
83
Gregory CLEMENT7f23f622013-03-20 16:09:35 +010084 if (hwirq != ARMADA_370_XP_TIMER0_PER_CPU_IRQ)
Gregory CLEMENT3202bf02012-12-05 21:43:23 +010085 writel(hwirq, main_int_base +
86 ARMADA_370_XP_INT_CLEAR_ENABLE_OFFS);
87 else
88 writel(hwirq, per_cpu_int_base +
89 ARMADA_370_XP_INT_SET_MASK_OFFS);
Thomas Petazzoni9ae6f742012-06-13 19:01:28 +020090}
91
92static void armada_370_xp_irq_unmask(struct irq_data *d)
93{
Gregory CLEMENT3202bf02012-12-05 21:43:23 +010094 irq_hw_number_t hwirq = irqd_to_hwirq(d);
95
Gregory CLEMENT7f23f622013-03-20 16:09:35 +010096 if (hwirq != ARMADA_370_XP_TIMER0_PER_CPU_IRQ)
Gregory CLEMENT3202bf02012-12-05 21:43:23 +010097 writel(hwirq, main_int_base +
98 ARMADA_370_XP_INT_SET_ENABLE_OFFS);
99 else
100 writel(hwirq, per_cpu_int_base +
101 ARMADA_370_XP_INT_CLEAR_MASK_OFFS);
Thomas Petazzoni9ae6f742012-06-13 19:01:28 +0200102}
103
Thomas Petazzoni31f614e2013-08-09 22:27:11 +0200104#ifdef CONFIG_PCI_MSI
105
106static int armada_370_xp_alloc_msi(void)
107{
108 int hwirq;
109
110 mutex_lock(&msi_used_lock);
111 hwirq = find_first_zero_bit(&msi_used, PCI_MSI_DOORBELL_NR);
112 if (hwirq >= PCI_MSI_DOORBELL_NR)
113 hwirq = -ENOSPC;
114 else
115 set_bit(hwirq, msi_used);
116 mutex_unlock(&msi_used_lock);
117
118 return hwirq;
119}
120
121static void armada_370_xp_free_msi(int hwirq)
122{
123 mutex_lock(&msi_used_lock);
124 if (!test_bit(hwirq, msi_used))
125 pr_err("trying to free unused MSI#%d\n", hwirq);
126 else
127 clear_bit(hwirq, msi_used);
128 mutex_unlock(&msi_used_lock);
129}
130
131static int armada_370_xp_setup_msi_irq(struct msi_chip *chip,
132 struct pci_dev *pdev,
133 struct msi_desc *desc)
134{
135 struct msi_msg msg;
136 irq_hw_number_t hwirq;
137 int virq;
138
139 hwirq = armada_370_xp_alloc_msi();
140 if (hwirq < 0)
141 return hwirq;
142
143 virq = irq_create_mapping(armada_370_xp_msi_domain, hwirq);
144 if (!virq) {
145 armada_370_xp_free_msi(hwirq);
146 return -EINVAL;
147 }
148
149 irq_set_msi_desc(virq, desc);
150
151 msg.address_lo = msi_doorbell_addr;
152 msg.address_hi = 0;
153 msg.data = 0xf00 | (hwirq + 16);
154
155 write_msi_msg(virq, &msg);
156 return 0;
157}
158
159static void armada_370_xp_teardown_msi_irq(struct msi_chip *chip,
160 unsigned int irq)
161{
162 struct irq_data *d = irq_get_irq_data(irq);
163 irq_dispose_mapping(irq);
164 armada_370_xp_free_msi(d->hwirq);
165}
166
167static struct irq_chip armada_370_xp_msi_irq_chip = {
168 .name = "armada_370_xp_msi_irq",
169 .irq_enable = unmask_msi_irq,
170 .irq_disable = mask_msi_irq,
171 .irq_mask = mask_msi_irq,
172 .irq_unmask = unmask_msi_irq,
173};
174
175static int armada_370_xp_msi_map(struct irq_domain *domain, unsigned int virq,
176 irq_hw_number_t hw)
177{
178 irq_set_chip_and_handler(virq, &armada_370_xp_msi_irq_chip,
179 handle_simple_irq);
180 set_irq_flags(virq, IRQF_VALID);
181
182 return 0;
183}
184
185static const struct irq_domain_ops armada_370_xp_msi_irq_ops = {
186 .map = armada_370_xp_msi_map,
187};
188
189static int armada_370_xp_msi_init(struct device_node *node,
190 phys_addr_t main_int_phys_base)
191{
192 struct msi_chip *msi_chip;
193 u32 reg;
194 int ret;
195
196 msi_doorbell_addr = main_int_phys_base +
197 ARMADA_370_XP_SW_TRIG_INT_OFFS;
198
199 msi_chip = kzalloc(sizeof(*msi_chip), GFP_KERNEL);
200 if (!msi_chip)
201 return -ENOMEM;
202
203 msi_chip->setup_irq = armada_370_xp_setup_msi_irq;
204 msi_chip->teardown_irq = armada_370_xp_teardown_msi_irq;
205 msi_chip->of_node = node;
206
207 armada_370_xp_msi_domain =
208 irq_domain_add_linear(NULL, PCI_MSI_DOORBELL_NR,
209 &armada_370_xp_msi_irq_ops,
210 NULL);
211 if (!armada_370_xp_msi_domain) {
212 kfree(msi_chip);
213 return -ENOMEM;
214 }
215
216 ret = of_pci_msi_chip_add(msi_chip);
217 if (ret < 0) {
218 irq_domain_remove(armada_370_xp_msi_domain);
219 kfree(msi_chip);
220 return ret;
221 }
222
223 reg = readl(per_cpu_int_base + ARMADA_370_XP_IN_DRBEL_MSK_OFFS)
224 | PCI_MSI_DOORBELL_MASK;
225
226 writel(reg, per_cpu_int_base +
227 ARMADA_370_XP_IN_DRBEL_MSK_OFFS);
228
229 /* Unmask IPI interrupt */
230 writel(1, per_cpu_int_base + ARMADA_370_XP_INT_CLEAR_MASK_OFFS);
231
232 return 0;
233}
234#else
235static inline int armada_370_xp_msi_init(struct device_node *node,
236 phys_addr_t main_int_phys_base)
237{
238 return 0;
239}
240#endif
241
Gregory CLEMENT344e8732012-08-02 11:19:12 +0300242#ifdef CONFIG_SMP
Arnaud Ebalard19e61d42014-01-20 22:52:05 +0100243static DEFINE_RAW_SPINLOCK(irq_controller_lock);
244
Gregory CLEMENT344e8732012-08-02 11:19:12 +0300245static int armada_xp_set_affinity(struct irq_data *d,
246 const struct cpumask *mask_val, bool force)
247{
Gregory CLEMENT3202bf02012-12-05 21:43:23 +0100248 irq_hw_number_t hwirq = irqd_to_hwirq(d);
Thomas Gleixner8cc3cfc2014-03-04 20:43:41 +0000249 unsigned long reg, mask;
Gregory CLEMENT3202bf02012-12-05 21:43:23 +0100250 int cpu;
251
Thomas Gleixner8cc3cfc2014-03-04 20:43:41 +0000252 /* Select a single core from the affinity mask which is online */
253 cpu = cpumask_any_and(mask_val, cpu_online_mask);
254 mask = 1UL << cpu_logical_map(cpu);
Gregory CLEMENT3202bf02012-12-05 21:43:23 +0100255
256 raw_spin_lock(&irq_controller_lock);
Gregory CLEMENT3202bf02012-12-05 21:43:23 +0100257 reg = readl(main_int_base + ARMADA_370_XP_INT_SOURCE_CTL(hwirq));
Thomas Gleixner8cc3cfc2014-03-04 20:43:41 +0000258 reg = (reg & (~ARMADA_370_XP_INT_SOURCE_CPU_MASK)) | mask;
Gregory CLEMENT3202bf02012-12-05 21:43:23 +0100259 writel(reg, main_int_base + ARMADA_370_XP_INT_SOURCE_CTL(hwirq));
Gregory CLEMENT3202bf02012-12-05 21:43:23 +0100260 raw_spin_unlock(&irq_controller_lock);
261
Gregory CLEMENT344e8732012-08-02 11:19:12 +0300262 return 0;
263}
264#endif
265
Thomas Petazzoni9ae6f742012-06-13 19:01:28 +0200266static struct irq_chip armada_370_xp_irq_chip = {
267 .name = "armada_370_xp_irq",
268 .irq_mask = armada_370_xp_irq_mask,
269 .irq_mask_ack = armada_370_xp_irq_mask,
270 .irq_unmask = armada_370_xp_irq_unmask,
Gregory CLEMENT344e8732012-08-02 11:19:12 +0300271#ifdef CONFIG_SMP
272 .irq_set_affinity = armada_xp_set_affinity,
273#endif
Thomas Petazzoni9ae6f742012-06-13 19:01:28 +0200274};
275
276static int armada_370_xp_mpic_irq_map(struct irq_domain *h,
277 unsigned int virq, irq_hw_number_t hw)
278{
279 armada_370_xp_irq_mask(irq_get_irq_data(virq));
Gregory CLEMENT600468d2013-04-05 14:32:52 +0200280 if (hw != ARMADA_370_XP_TIMER0_PER_CPU_IRQ)
281 writel(hw, per_cpu_int_base +
282 ARMADA_370_XP_INT_CLEAR_MASK_OFFS);
283 else
284 writel(hw, main_int_base + ARMADA_370_XP_INT_SET_ENABLE_OFFS);
Thomas Petazzoni9ae6f742012-06-13 19:01:28 +0200285 irq_set_status_flags(virq, IRQ_LEVEL);
Gregory CLEMENT3a6f08a2013-01-25 18:32:41 +0100286
Gregory CLEMENT7f23f622013-03-20 16:09:35 +0100287 if (hw == ARMADA_370_XP_TIMER0_PER_CPU_IRQ) {
Gregory CLEMENT3a6f08a2013-01-25 18:32:41 +0100288 irq_set_percpu_devid(virq);
289 irq_set_chip_and_handler(virq, &armada_370_xp_irq_chip,
290 handle_percpu_devid_irq);
291
292 } else {
293 irq_set_chip_and_handler(virq, &armada_370_xp_irq_chip,
294 handle_level_irq);
295 }
Thomas Petazzoni9ae6f742012-06-13 19:01:28 +0200296 set_irq_flags(virq, IRQF_VALID | IRQF_PROBE);
297
298 return 0;
299}
300
Gregory CLEMENT344e8732012-08-02 11:19:12 +0300301#ifdef CONFIG_SMP
302void armada_mpic_send_doorbell(const struct cpumask *mask, unsigned int irq)
303{
304 int cpu;
305 unsigned long map = 0;
306
307 /* Convert our logical CPU mask into a physical one. */
308 for_each_cpu(cpu, mask)
309 map |= 1 << cpu_logical_map(cpu);
310
311 /*
312 * Ensure that stores to Normal memory are visible to the
313 * other CPUs before issuing the IPI.
314 */
315 dsb();
316
317 /* submit softirq */
318 writel((map << 8) | irq, main_int_base +
319 ARMADA_370_XP_SW_TRIG_INT_OFFS);
320}
321
322void armada_xp_mpic_smp_cpu_init(void)
323{
324 /* Clear pending IPIs */
325 writel(0, per_cpu_int_base + ARMADA_370_XP_IN_DRBEL_CAUSE_OFFS);
326
327 /* Enable first 8 IPIs */
Thomas Petazzoni5ec69012013-04-09 23:26:17 +0200328 writel(IPI_DOORBELL_MASK, per_cpu_int_base +
Gregory CLEMENT344e8732012-08-02 11:19:12 +0300329 ARMADA_370_XP_IN_DRBEL_MSK_OFFS);
330
331 /* Unmask IPI interrupt */
332 writel(0, per_cpu_int_base + ARMADA_370_XP_INT_CLEAR_MASK_OFFS);
333}
334#endif /* CONFIG_SMP */
335
Thomas Petazzoni9ae6f742012-06-13 19:01:28 +0200336static struct irq_domain_ops armada_370_xp_mpic_irq_ops = {
337 .map = armada_370_xp_mpic_irq_map,
338 .xlate = irq_domain_xlate_onecell,
339};
340
Ezequiel Garcia9b8cf772014-02-10 17:00:01 -0300341#ifdef CONFIG_PCI_MSI
Ezequiel Garciabc69b8a2014-02-10 17:00:02 -0300342static void armada_370_xp_handle_msi_irq(struct pt_regs *regs, bool is_chained)
Ezequiel Garcia9b8cf772014-02-10 17:00:01 -0300343{
344 u32 msimask, msinr;
345
346 msimask = readl_relaxed(per_cpu_int_base +
347 ARMADA_370_XP_IN_DRBEL_CAUSE_OFFS)
348 & PCI_MSI_DOORBELL_MASK;
349
350 writel(~msimask, per_cpu_int_base +
351 ARMADA_370_XP_IN_DRBEL_CAUSE_OFFS);
352
353 for (msinr = PCI_MSI_DOORBELL_START;
354 msinr < PCI_MSI_DOORBELL_END; msinr++) {
355 int irq;
356
357 if (!(msimask & BIT(msinr)))
358 continue;
359
360 irq = irq_find_mapping(armada_370_xp_msi_domain,
361 msinr - 16);
Ezequiel Garciabc69b8a2014-02-10 17:00:02 -0300362
363 if (is_chained)
364 generic_handle_irq(irq);
365 else
366 handle_IRQ(irq, regs);
Ezequiel Garcia9b8cf772014-02-10 17:00:01 -0300367 }
368}
369#else
Ezequiel Garciabc69b8a2014-02-10 17:00:02 -0300370static void armada_370_xp_handle_msi_irq(struct pt_regs *r, bool b) {}
Ezequiel Garcia9b8cf772014-02-10 17:00:01 -0300371#endif
372
Ezequiel Garciabc69b8a2014-02-10 17:00:02 -0300373static void armada_370_xp_mpic_handle_cascade_irq(unsigned int irq,
374 struct irq_desc *desc)
375{
376 struct irq_chip *chip = irq_get_chip(irq);
377 unsigned long irqmap, irqn;
378 unsigned int cascade_irq;
379
380 chained_irq_enter(chip, desc);
381
382 irqmap = readl_relaxed(per_cpu_int_base + ARMADA_375_PPI_CAUSE);
383
384 if (irqmap & BIT(0)) {
385 armada_370_xp_handle_msi_irq(NULL, true);
386 irqmap &= ~BIT(0);
387 }
388
389 for_each_set_bit(irqn, &irqmap, BITS_PER_LONG) {
390 cascade_irq = irq_find_mapping(armada_370_xp_mpic_domain, irqn);
391 generic_handle_irq(cascade_irq);
392 }
393
394 chained_irq_exit(chip, desc);
395}
396
Stephen Boyd8783dd32014-03-04 16:40:30 -0800397static void __exception_irq_entry
Thomas Petazzoni9339d432013-04-09 23:26:15 +0200398armada_370_xp_handle_irq(struct pt_regs *regs)
Thomas Petazzoni9ae6f742012-06-13 19:01:28 +0200399{
400 u32 irqstat, irqnr;
401
402 do {
403 irqstat = readl_relaxed(per_cpu_int_base +
404 ARMADA_370_XP_CPU_INTACK_OFFS);
405 irqnr = irqstat & 0x3FF;
406
Gregory CLEMENT344e8732012-08-02 11:19:12 +0300407 if (irqnr > 1022)
408 break;
409
Thomas Petazzoni31f614e2013-08-09 22:27:11 +0200410 if (irqnr > 1) {
Gregory CLEMENT344e8732012-08-02 11:19:12 +0300411 irqnr = irq_find_mapping(armada_370_xp_mpic_domain,
412 irqnr);
Thomas Petazzoni9ae6f742012-06-13 19:01:28 +0200413 handle_IRQ(irqnr, regs);
414 continue;
415 }
Thomas Petazzoni31f614e2013-08-09 22:27:11 +0200416
Thomas Petazzoni31f614e2013-08-09 22:27:11 +0200417 /* MSI handling */
Ezequiel Garcia9b8cf772014-02-10 17:00:01 -0300418 if (irqnr == 1)
Ezequiel Garciabc69b8a2014-02-10 17:00:02 -0300419 armada_370_xp_handle_msi_irq(regs, false);
Thomas Petazzoni31f614e2013-08-09 22:27:11 +0200420
Gregory CLEMENT344e8732012-08-02 11:19:12 +0300421#ifdef CONFIG_SMP
422 /* IPI Handling */
423 if (irqnr == 0) {
424 u32 ipimask, ipinr;
Thomas Petazzoni9ae6f742012-06-13 19:01:28 +0200425
Gregory CLEMENT344e8732012-08-02 11:19:12 +0300426 ipimask = readl_relaxed(per_cpu_int_base +
427 ARMADA_370_XP_IN_DRBEL_CAUSE_OFFS)
Thomas Petazzoni5ec69012013-04-09 23:26:17 +0200428 & IPI_DOORBELL_MASK;
Gregory CLEMENT344e8732012-08-02 11:19:12 +0300429
Lior Amsalema6f089e2013-11-25 17:26:44 +0100430 writel(~ipimask, per_cpu_int_base +
Gregory CLEMENT344e8732012-08-02 11:19:12 +0300431 ARMADA_370_XP_IN_DRBEL_CAUSE_OFFS);
432
433 /* Handle all pending doorbells */
Thomas Petazzoni5ec69012013-04-09 23:26:17 +0200434 for (ipinr = IPI_DOORBELL_START;
435 ipinr < IPI_DOORBELL_END; ipinr++) {
Gregory CLEMENT344e8732012-08-02 11:19:12 +0300436 if (ipimask & (0x1 << ipinr))
437 handle_IPI(ipinr, regs);
438 }
439 continue;
440 }
441#endif
442
Thomas Petazzoni9ae6f742012-06-13 19:01:28 +0200443 } while (1);
444}
445
Thomas Petazzoni9ae6f742012-06-13 19:01:28 +0200446static int __init armada_370_xp_mpic_of_init(struct device_node *node,
447 struct device_node *parent)
448{
Thomas Petazzoni627dfcc2013-08-09 22:27:10 +0200449 struct resource main_int_res, per_cpu_int_res;
Ezequiel Garciabc69b8a2014-02-10 17:00:02 -0300450 int parent_irq;
Thomas Petazzoni9ae6f742012-06-13 19:01:28 +0200451 u32 control;
452
Thomas Petazzoni627dfcc2013-08-09 22:27:10 +0200453 BUG_ON(of_address_to_resource(node, 0, &main_int_res));
454 BUG_ON(of_address_to_resource(node, 1, &per_cpu_int_res));
Thomas Petazzoni9ae6f742012-06-13 19:01:28 +0200455
Thomas Petazzoni627dfcc2013-08-09 22:27:10 +0200456 BUG_ON(!request_mem_region(main_int_res.start,
457 resource_size(&main_int_res),
458 node->full_name));
459 BUG_ON(!request_mem_region(per_cpu_int_res.start,
460 resource_size(&per_cpu_int_res),
461 node->full_name));
462
463 main_int_base = ioremap(main_int_res.start,
464 resource_size(&main_int_res));
Thomas Petazzoni9ae6f742012-06-13 19:01:28 +0200465 BUG_ON(!main_int_base);
Thomas Petazzoni627dfcc2013-08-09 22:27:10 +0200466
467 per_cpu_int_base = ioremap(per_cpu_int_res.start,
468 resource_size(&per_cpu_int_res));
Thomas Petazzoni9ae6f742012-06-13 19:01:28 +0200469 BUG_ON(!per_cpu_int_base);
Gregory CLEMENTd792b1e2012-09-26 18:02:48 +0200470
471 control = readl(main_int_base + ARMADA_370_XP_INT_CONTROL);
472
Thomas Petazzoni9ae6f742012-06-13 19:01:28 +0200473 armada_370_xp_mpic_domain =
474 irq_domain_add_linear(node, (control >> 2) & 0x3ff,
475 &armada_370_xp_mpic_irq_ops, NULL);
476
Thomas Petazzoni627dfcc2013-08-09 22:27:10 +0200477 BUG_ON(!armada_370_xp_mpic_domain);
Thomas Petazzoni9ae6f742012-06-13 19:01:28 +0200478
Thomas Petazzoni9ae6f742012-06-13 19:01:28 +0200479#ifdef CONFIG_SMP
480 armada_xp_mpic_smp_cpu_init();
Thomas Petazzoni9ae6f742012-06-13 19:01:28 +0200481#endif
482
Thomas Petazzoni31f614e2013-08-09 22:27:11 +0200483 armada_370_xp_msi_init(node, main_int_res.start);
484
Ezequiel Garciabc69b8a2014-02-10 17:00:02 -0300485 parent_irq = irq_of_parse_and_map(node, 0);
486 if (parent_irq <= 0) {
487 irq_set_default_host(armada_370_xp_mpic_domain);
488 set_handle_irq(armada_370_xp_handle_irq);
489 } else {
490 irq_set_chained_handler(parent_irq,
491 armada_370_xp_mpic_handle_cascade_irq);
492 }
Thomas Petazzonib313ada2013-04-09 23:26:16 +0200493
Thomas Petazzoni9ae6f742012-06-13 19:01:28 +0200494 return 0;
495}
496
Thomas Petazzoni9339d432013-04-09 23:26:15 +0200497IRQCHIP_DECLARE(armada_370_xp_mpic, "marvell,mpic", armada_370_xp_mpic_of_init);