1d2912cb1SThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only 2171bb2f1SJohn Crispin /* 3171bb2f1SJohn Crispin * 497b92108SJohn Crispin * Copyright (C) 2010 John Crispin <john@phrozen.org> 5171bb2f1SJohn Crispin * Copyright (C) 2010 Thomas Langer <thomas.langer@lantiq.com> 6171bb2f1SJohn Crispin */ 7171bb2f1SJohn Crispin 8171bb2f1SJohn Crispin #include <linux/interrupt.h> 9171bb2f1SJohn Crispin #include <linux/ioport.h> 103645da02SJohn Crispin #include <linux/sched.h> 11e91fd6ddSMartin Blumenstingl #include <linux/irqchip.h> 123645da02SJohn Crispin #include <linux/irqdomain.h> 133645da02SJohn Crispin #include <linux/of_platform.h> 143645da02SJohn Crispin #include <linux/of_address.h> 153645da02SJohn Crispin #include <linux/of_irq.h> 16171bb2f1SJohn Crispin 17171bb2f1SJohn Crispin #include <asm/bootinfo.h> 18171bb2f1SJohn Crispin #include <asm/irq_cpu.h> 19171bb2f1SJohn Crispin 20171bb2f1SJohn Crispin #include <lantiq_soc.h> 21171bb2f1SJohn Crispin #include <irq.h> 22171bb2f1SJohn Crispin 233645da02SJohn Crispin /* register definitions - internal irqs */ 24f0dd3001SPetr Cvek #define LTQ_ICU_ISR 0x0000 25f0dd3001SPetr Cvek #define LTQ_ICU_IER 0x0008 26f0dd3001SPetr Cvek #define LTQ_ICU_IOSR 0x0010 27f0dd3001SPetr Cvek #define LTQ_ICU_IRSR 0x0018 28f0dd3001SPetr Cvek #define LTQ_ICU_IMR 0x0020 29171bb2f1SJohn Crispin 3085cf2c37SPetr Cvek #define LTQ_ICU_IM_SIZE 0x28 31171bb2f1SJohn Crispin 323645da02SJohn Crispin /* register definitions - external irqs */ 33171bb2f1SJohn Crispin #define LTQ_EIU_EXIN_C 0x0000 34171bb2f1SJohn Crispin #define LTQ_EIU_EXIN_INIC 0x0004 3526365625SJohn Crispin #define LTQ_EIU_EXIN_INC 0x0008 36171bb2f1SJohn Crispin #define LTQ_EIU_EXIN_INEN 0x000C 37171bb2f1SJohn Crispin 3826365625SJohn Crispin /* number of external interrupts */ 39171bb2f1SJohn Crispin #define MAX_EIU 6 40171bb2f1SJohn Crispin 4159c11579SJohn Crispin /* the performance counter */ 4259c11579SJohn Crispin #define LTQ_PERF_IRQ (INT_NUM_IM4_IRL0 + 31) 4359c11579SJohn Crispin 443645da02SJohn Crispin /* 453645da02SJohn Crispin * irqs generated by devices attached to the EBU need to be acked in 46171bb2f1SJohn Crispin * a special manner 47171bb2f1SJohn Crispin */ 48171bb2f1SJohn Crispin #define LTQ_ICU_EBU_IRQ 22 49171bb2f1SJohn Crispin 5085cf2c37SPetr Cvek #define ltq_icu_w32(vpe, m, x, y) \ 5185cf2c37SPetr Cvek ltq_w32((x), ltq_icu_membase[vpe] + m*LTQ_ICU_IM_SIZE + (y)) 5285cf2c37SPetr Cvek 5385cf2c37SPetr Cvek #define ltq_icu_r32(vpe, m, x) \ 5485cf2c37SPetr Cvek ltq_r32(ltq_icu_membase[vpe] + m*LTQ_ICU_IM_SIZE + (x)) 55171bb2f1SJohn Crispin 56171bb2f1SJohn Crispin #define ltq_eiu_w32(x, y) ltq_w32((x), ltq_eiu_membase + (y)) 57171bb2f1SJohn Crispin #define ltq_eiu_r32(x) ltq_r32(ltq_eiu_membase + (x)) 58171bb2f1SJohn Crispin 593645da02SJohn Crispin /* we have a cascade of 8 irqs */ 603645da02SJohn Crispin #define MIPS_CPU_IRQ_CASCADE 8 613645da02SJohn Crispin 623645da02SJohn Crispin static int exin_avail; 63fe46e503SJohn Crispin static u32 ltq_eiu_irq[MAX_EIU]; 6485cf2c37SPetr Cvek static void __iomem *ltq_icu_membase[NR_CPUS]; 65171bb2f1SJohn Crispin static void __iomem *ltq_eiu_membase; 66c2c9c788SJohn Crispin static struct irq_domain *ltq_domain; 6785cf2c37SPetr Cvek static DEFINE_SPINLOCK(ltq_eiu_lock); 6885cf2c37SPetr Cvek static DEFINE_RAW_SPINLOCK(ltq_icu_lock); 69a669efc4SAndrew Bresticker static int ltq_perfcount_irq; 70171bb2f1SJohn Crispin 7126365625SJohn Crispin int ltq_eiu_get_irq(int exin) 7226365625SJohn Crispin { 7326365625SJohn Crispin if (exin < exin_avail) 74fe46e503SJohn Crispin return ltq_eiu_irq[exin]; 7526365625SJohn Crispin return -1; 7626365625SJohn Crispin } 7726365625SJohn Crispin 78171bb2f1SJohn Crispin void ltq_disable_irq(struct irq_data *d) 79171bb2f1SJohn Crispin { 8039588164SPetr Cvek unsigned long offset = d->hwirq - MIPS_CPU_IRQ_CASCADE; 8139588164SPetr Cvek unsigned long im = offset / INT_NUM_IM_OFFSET; 8285cf2c37SPetr Cvek unsigned long flags; 8385cf2c37SPetr Cvek int vpe; 84171bb2f1SJohn Crispin 853645da02SJohn Crispin offset %= INT_NUM_IM_OFFSET; 8685cf2c37SPetr Cvek 8785cf2c37SPetr Cvek raw_spin_lock_irqsave(<q_icu_lock, flags); 8885cf2c37SPetr Cvek for_each_present_cpu(vpe) { 8985cf2c37SPetr Cvek ltq_icu_w32(vpe, im, 9085cf2c37SPetr Cvek ltq_icu_r32(vpe, im, LTQ_ICU_IER) & ~BIT(offset), 91f0dd3001SPetr Cvek LTQ_ICU_IER); 92171bb2f1SJohn Crispin } 9385cf2c37SPetr Cvek raw_spin_unlock_irqrestore(<q_icu_lock, flags); 94171bb2f1SJohn Crispin } 95171bb2f1SJohn Crispin 96171bb2f1SJohn Crispin void ltq_mask_and_ack_irq(struct irq_data *d) 97171bb2f1SJohn Crispin { 9839588164SPetr Cvek unsigned long offset = d->hwirq - MIPS_CPU_IRQ_CASCADE; 9939588164SPetr Cvek unsigned long im = offset / INT_NUM_IM_OFFSET; 10085cf2c37SPetr Cvek unsigned long flags; 10185cf2c37SPetr Cvek int vpe; 102171bb2f1SJohn Crispin 1033645da02SJohn Crispin offset %= INT_NUM_IM_OFFSET; 10485cf2c37SPetr Cvek 10585cf2c37SPetr Cvek raw_spin_lock_irqsave(<q_icu_lock, flags); 10685cf2c37SPetr Cvek for_each_present_cpu(vpe) { 10785cf2c37SPetr Cvek ltq_icu_w32(vpe, im, 10885cf2c37SPetr Cvek ltq_icu_r32(vpe, im, LTQ_ICU_IER) & ~BIT(offset), 109f0dd3001SPetr Cvek LTQ_ICU_IER); 11085cf2c37SPetr Cvek ltq_icu_w32(vpe, im, BIT(offset), LTQ_ICU_ISR); 11185cf2c37SPetr Cvek } 11285cf2c37SPetr Cvek raw_spin_unlock_irqrestore(<q_icu_lock, flags); 113171bb2f1SJohn Crispin } 114171bb2f1SJohn Crispin 115171bb2f1SJohn Crispin static void ltq_ack_irq(struct irq_data *d) 116171bb2f1SJohn Crispin { 11739588164SPetr Cvek unsigned long offset = d->hwirq - MIPS_CPU_IRQ_CASCADE; 11839588164SPetr Cvek unsigned long im = offset / INT_NUM_IM_OFFSET; 11985cf2c37SPetr Cvek unsigned long flags; 12085cf2c37SPetr Cvek int vpe; 121171bb2f1SJohn Crispin 1223645da02SJohn Crispin offset %= INT_NUM_IM_OFFSET; 12385cf2c37SPetr Cvek 12485cf2c37SPetr Cvek raw_spin_lock_irqsave(<q_icu_lock, flags); 12585cf2c37SPetr Cvek for_each_present_cpu(vpe) { 12685cf2c37SPetr Cvek ltq_icu_w32(vpe, im, BIT(offset), LTQ_ICU_ISR); 12785cf2c37SPetr Cvek } 12885cf2c37SPetr Cvek raw_spin_unlock_irqrestore(<q_icu_lock, flags); 129171bb2f1SJohn Crispin } 130171bb2f1SJohn Crispin 131171bb2f1SJohn Crispin void ltq_enable_irq(struct irq_data *d) 132171bb2f1SJohn Crispin { 13339588164SPetr Cvek unsigned long offset = d->hwirq - MIPS_CPU_IRQ_CASCADE; 13439588164SPetr Cvek unsigned long im = offset / INT_NUM_IM_OFFSET; 13585cf2c37SPetr Cvek unsigned long flags; 13685cf2c37SPetr Cvek int vpe; 137171bb2f1SJohn Crispin 1383645da02SJohn Crispin offset %= INT_NUM_IM_OFFSET; 13985cf2c37SPetr Cvek 14085cf2c37SPetr Cvek vpe = cpumask_first(irq_data_get_effective_affinity_mask(d)); 14185cf2c37SPetr Cvek 14285cf2c37SPetr Cvek /* This shouldn't be even possible, maybe during CPU hotplug spam */ 14385cf2c37SPetr Cvek if (unlikely(vpe >= nr_cpu_ids)) 14485cf2c37SPetr Cvek vpe = smp_processor_id(); 14585cf2c37SPetr Cvek 14685cf2c37SPetr Cvek raw_spin_lock_irqsave(<q_icu_lock, flags); 14785cf2c37SPetr Cvek 14885cf2c37SPetr Cvek ltq_icu_w32(vpe, im, ltq_icu_r32(vpe, im, LTQ_ICU_IER) | BIT(offset), 149f0dd3001SPetr Cvek LTQ_ICU_IER); 15085cf2c37SPetr Cvek 15185cf2c37SPetr Cvek raw_spin_unlock_irqrestore(<q_icu_lock, flags); 152171bb2f1SJohn Crispin } 153171bb2f1SJohn Crispin 15426365625SJohn Crispin static int ltq_eiu_settype(struct irq_data *d, unsigned int type) 15526365625SJohn Crispin { 15626365625SJohn Crispin int i; 15785cf2c37SPetr Cvek unsigned long flags; 15826365625SJohn Crispin 159f97e5e8eSJohn Crispin for (i = 0; i < exin_avail; i++) { 160fe46e503SJohn Crispin if (d->hwirq == ltq_eiu_irq[i]) { 16126365625SJohn Crispin int val = 0; 16226365625SJohn Crispin int edge = 0; 16326365625SJohn Crispin 16426365625SJohn Crispin switch (type) { 16526365625SJohn Crispin case IRQF_TRIGGER_NONE: 16626365625SJohn Crispin break; 16726365625SJohn Crispin case IRQF_TRIGGER_RISING: 16826365625SJohn Crispin val = 1; 16926365625SJohn Crispin edge = 1; 17026365625SJohn Crispin break; 17126365625SJohn Crispin case IRQF_TRIGGER_FALLING: 17226365625SJohn Crispin val = 2; 17326365625SJohn Crispin edge = 1; 17426365625SJohn Crispin break; 17526365625SJohn Crispin case IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING: 17626365625SJohn Crispin val = 3; 17726365625SJohn Crispin edge = 1; 17826365625SJohn Crispin break; 17926365625SJohn Crispin case IRQF_TRIGGER_HIGH: 18026365625SJohn Crispin val = 5; 18126365625SJohn Crispin break; 18226365625SJohn Crispin case IRQF_TRIGGER_LOW: 18326365625SJohn Crispin val = 6; 18426365625SJohn Crispin break; 18526365625SJohn Crispin default: 18626365625SJohn Crispin pr_err("invalid type %d for irq %ld\n", 18726365625SJohn Crispin type, d->hwirq); 18826365625SJohn Crispin return -EINVAL; 18926365625SJohn Crispin } 19026365625SJohn Crispin 19126365625SJohn Crispin if (edge) 19226365625SJohn Crispin irq_set_handler(d->hwirq, handle_edge_irq); 19326365625SJohn Crispin 19485cf2c37SPetr Cvek spin_lock_irqsave(<q_eiu_lock, flags); 195ba1bc0fcSPetr Cvek ltq_eiu_w32((ltq_eiu_r32(LTQ_EIU_EXIN_C) & 196ba1bc0fcSPetr Cvek (~(7 << (i * 4)))) | (val << (i * 4)), 197ba1bc0fcSPetr Cvek LTQ_EIU_EXIN_C); 19885cf2c37SPetr Cvek spin_unlock_irqrestore(<q_eiu_lock, flags); 19926365625SJohn Crispin } 20026365625SJohn Crispin } 20126365625SJohn Crispin 20226365625SJohn Crispin return 0; 20326365625SJohn Crispin } 20426365625SJohn Crispin 205171bb2f1SJohn Crispin static unsigned int ltq_startup_eiu_irq(struct irq_data *d) 206171bb2f1SJohn Crispin { 207171bb2f1SJohn Crispin int i; 208171bb2f1SJohn Crispin 209171bb2f1SJohn Crispin ltq_enable_irq(d); 210f97e5e8eSJohn Crispin for (i = 0; i < exin_avail; i++) { 211fe46e503SJohn Crispin if (d->hwirq == ltq_eiu_irq[i]) { 21226365625SJohn Crispin /* by default we are low level triggered */ 21326365625SJohn Crispin ltq_eiu_settype(d, IRQF_TRIGGER_LOW); 214171bb2f1SJohn Crispin /* clear all pending */ 21526365625SJohn Crispin ltq_eiu_w32(ltq_eiu_r32(LTQ_EIU_EXIN_INC) & ~BIT(i), 21626365625SJohn Crispin LTQ_EIU_EXIN_INC); 217171bb2f1SJohn Crispin /* enable */ 2183645da02SJohn Crispin ltq_eiu_w32(ltq_eiu_r32(LTQ_EIU_EXIN_INEN) | BIT(i), 219171bb2f1SJohn Crispin LTQ_EIU_EXIN_INEN); 220171bb2f1SJohn Crispin break; 221171bb2f1SJohn Crispin } 222171bb2f1SJohn Crispin } 223171bb2f1SJohn Crispin 224171bb2f1SJohn Crispin return 0; 225171bb2f1SJohn Crispin } 226171bb2f1SJohn Crispin 227171bb2f1SJohn Crispin static void ltq_shutdown_eiu_irq(struct irq_data *d) 228171bb2f1SJohn Crispin { 229171bb2f1SJohn Crispin int i; 230171bb2f1SJohn Crispin 231171bb2f1SJohn Crispin ltq_disable_irq(d); 232f97e5e8eSJohn Crispin for (i = 0; i < exin_avail; i++) { 233fe46e503SJohn Crispin if (d->hwirq == ltq_eiu_irq[i]) { 234171bb2f1SJohn Crispin /* disable */ 2353645da02SJohn Crispin ltq_eiu_w32(ltq_eiu_r32(LTQ_EIU_EXIN_INEN) & ~BIT(i), 236171bb2f1SJohn Crispin LTQ_EIU_EXIN_INEN); 237171bb2f1SJohn Crispin break; 238171bb2f1SJohn Crispin } 239171bb2f1SJohn Crispin } 240171bb2f1SJohn Crispin } 241171bb2f1SJohn Crispin 24285cf2c37SPetr Cvek #if defined(CONFIG_SMP) 24385cf2c37SPetr Cvek static int ltq_icu_irq_set_affinity(struct irq_data *d, 24485cf2c37SPetr Cvek const struct cpumask *cpumask, bool force) 24585cf2c37SPetr Cvek { 24685cf2c37SPetr Cvek struct cpumask tmask; 24785cf2c37SPetr Cvek 24885cf2c37SPetr Cvek if (!cpumask_and(&tmask, cpumask, cpu_online_mask)) 24985cf2c37SPetr Cvek return -EINVAL; 25085cf2c37SPetr Cvek 25185cf2c37SPetr Cvek irq_data_update_effective_affinity(d, &tmask); 25285cf2c37SPetr Cvek 25385cf2c37SPetr Cvek return IRQ_SET_MASK_OK; 25485cf2c37SPetr Cvek } 25585cf2c37SPetr Cvek #endif 25685cf2c37SPetr Cvek 257171bb2f1SJohn Crispin static struct irq_chip ltq_irq_type = { 258891ab064SSudip Mukherjee .name = "icu", 259171bb2f1SJohn Crispin .irq_enable = ltq_enable_irq, 260171bb2f1SJohn Crispin .irq_disable = ltq_disable_irq, 261171bb2f1SJohn Crispin .irq_unmask = ltq_enable_irq, 262171bb2f1SJohn Crispin .irq_ack = ltq_ack_irq, 263171bb2f1SJohn Crispin .irq_mask = ltq_disable_irq, 264171bb2f1SJohn Crispin .irq_mask_ack = ltq_mask_and_ack_irq, 26585cf2c37SPetr Cvek #if defined(CONFIG_SMP) 26685cf2c37SPetr Cvek .irq_set_affinity = ltq_icu_irq_set_affinity, 26785cf2c37SPetr Cvek #endif 268171bb2f1SJohn Crispin }; 269171bb2f1SJohn Crispin 270171bb2f1SJohn Crispin static struct irq_chip ltq_eiu_type = { 271891ab064SSudip Mukherjee .name = "eiu", 272171bb2f1SJohn Crispin .irq_startup = ltq_startup_eiu_irq, 273171bb2f1SJohn Crispin .irq_shutdown = ltq_shutdown_eiu_irq, 274171bb2f1SJohn Crispin .irq_enable = ltq_enable_irq, 275171bb2f1SJohn Crispin .irq_disable = ltq_disable_irq, 276171bb2f1SJohn Crispin .irq_unmask = ltq_enable_irq, 277171bb2f1SJohn Crispin .irq_ack = ltq_ack_irq, 278171bb2f1SJohn Crispin .irq_mask = ltq_disable_irq, 279171bb2f1SJohn Crispin .irq_mask_ack = ltq_mask_and_ack_irq, 28026365625SJohn Crispin .irq_set_type = ltq_eiu_settype, 28185cf2c37SPetr Cvek #if defined(CONFIG_SMP) 28285cf2c37SPetr Cvek .irq_set_affinity = ltq_icu_irq_set_affinity, 28385cf2c37SPetr Cvek #endif 284171bb2f1SJohn Crispin }; 285171bb2f1SJohn Crispin 2862b4dba55SHauke Mehrtens static void ltq_hw_irq_handler(struct irq_desc *desc) 287171bb2f1SJohn Crispin { 28839588164SPetr Cvek unsigned int module = irq_desc_get_irq(desc) - 2; 289171bb2f1SJohn Crispin u32 irq; 29039588164SPetr Cvek irq_hw_number_t hwirq; 29185cf2c37SPetr Cvek int vpe = smp_processor_id(); 292171bb2f1SJohn Crispin 29385cf2c37SPetr Cvek irq = ltq_icu_r32(vpe, module, LTQ_ICU_IOSR); 294171bb2f1SJohn Crispin if (irq == 0) 295171bb2f1SJohn Crispin return; 296171bb2f1SJohn Crispin 2973645da02SJohn Crispin /* 2983645da02SJohn Crispin * silicon bug causes only the msb set to 1 to be valid. all 299171bb2f1SJohn Crispin * other bits might be bogus 300171bb2f1SJohn Crispin */ 301171bb2f1SJohn Crispin irq = __fls(irq); 3022b4dba55SHauke Mehrtens hwirq = irq + MIPS_CPU_IRQ_CASCADE + (INT_NUM_IM_OFFSET * module); 3030661cb2aSMarc Zyngier generic_handle_domain_irq(ltq_domain, hwirq); 304171bb2f1SJohn Crispin 305171bb2f1SJohn Crispin /* if this is a EBU irq, we need to ack it or get a deadlock */ 306c6f2a9e1SNathan Chancellor if (irq == LTQ_ICU_EBU_IRQ && !module && LTQ_EBU_PCC_ISTAT != 0) 307171bb2f1SJohn Crispin ltq_ebu_w32(ltq_ebu_r32(LTQ_EBU_PCC_ISTAT) | 0x10, 308171bb2f1SJohn Crispin LTQ_EBU_PCC_ISTAT); 309171bb2f1SJohn Crispin } 310171bb2f1SJohn Crispin 3113645da02SJohn Crispin static int icu_map(struct irq_domain *d, unsigned int irq, irq_hw_number_t hw) 3123645da02SJohn Crispin { 3133645da02SJohn Crispin struct irq_chip *chip = <q_irq_type; 31485cf2c37SPetr Cvek struct irq_data *data; 3153645da02SJohn Crispin int i; 3163645da02SJohn Crispin 3179c1628b6SJohn Crispin if (hw < MIPS_CPU_IRQ_CASCADE) 3189c1628b6SJohn Crispin return 0; 3199c1628b6SJohn Crispin 3203645da02SJohn Crispin for (i = 0; i < exin_avail; i++) 321fe46e503SJohn Crispin if (hw == ltq_eiu_irq[i]) 3223645da02SJohn Crispin chip = <q_eiu_type; 3233645da02SJohn Crispin 32485cf2c37SPetr Cvek data = irq_get_irq_data(irq); 32585cf2c37SPetr Cvek 32685cf2c37SPetr Cvek irq_data_update_effective_affinity(data, cpumask_of(0)); 32785cf2c37SPetr Cvek 3287bf0d5e8SHauke Mehrtens irq_set_chip_and_handler(irq, chip, handle_level_irq); 3293645da02SJohn Crispin 3303645da02SJohn Crispin return 0; 3313645da02SJohn Crispin } 3323645da02SJohn Crispin 3333645da02SJohn Crispin static const struct irq_domain_ops irq_domain_ops = { 3343645da02SJohn Crispin .xlate = irq_domain_xlate_onetwocell, 3353645da02SJohn Crispin .map = icu_map, 3363645da02SJohn Crispin }; 3373645da02SJohn Crispin 3383645da02SJohn Crispin int __init icu_of_init(struct device_node *node, struct device_node *parent) 339171bb2f1SJohn Crispin { 3403645da02SJohn Crispin struct device_node *eiu_node; 3413645da02SJohn Crispin struct resource res; 34285cf2c37SPetr Cvek int i, ret, vpe; 343171bb2f1SJohn Crispin 34485cf2c37SPetr Cvek /* load register regions of available ICUs */ 34585cf2c37SPetr Cvek for_each_possible_cpu(vpe) { 34685cf2c37SPetr Cvek if (of_address_to_resource(node, vpe, &res)) 34785cf2c37SPetr Cvek panic("Failed to get icu%i memory range", vpe); 348171bb2f1SJohn Crispin 3496e807852SHauke Mehrtens if (!request_mem_region(res.start, resource_size(&res), 3506e807852SHauke Mehrtens res.name)) 35185cf2c37SPetr Cvek pr_err("Failed to request icu%i memory\n", vpe); 352171bb2f1SJohn Crispin 3534bdc0d67SChristoph Hellwig ltq_icu_membase[vpe] = ioremap(res.start, 35461fa969fSJohn Crispin resource_size(&res)); 35585cf2c37SPetr Cvek 35685cf2c37SPetr Cvek if (!ltq_icu_membase[vpe]) 35785cf2c37SPetr Cvek panic("Failed to remap icu%i memory", vpe); 35861fa969fSJohn Crispin } 359171bb2f1SJohn Crispin 36016f70b56SJohn Crispin /* turn off all irqs by default */ 36185cf2c37SPetr Cvek for_each_possible_cpu(vpe) { 36261fa969fSJohn Crispin for (i = 0; i < MAX_IM; i++) { 363171bb2f1SJohn Crispin /* make sure all irqs are turned off by default */ 36485cf2c37SPetr Cvek ltq_icu_w32(vpe, i, 0, LTQ_ICU_IER); 36585cf2c37SPetr Cvek 366171bb2f1SJohn Crispin /* clear all possibly pending interrupts */ 36785cf2c37SPetr Cvek ltq_icu_w32(vpe, i, ~0, LTQ_ICU_ISR); 36885cf2c37SPetr Cvek ltq_icu_w32(vpe, i, ~0, LTQ_ICU_IMR); 36985cf2c37SPetr Cvek 37085cf2c37SPetr Cvek /* clear resend */ 37185cf2c37SPetr Cvek ltq_icu_w32(vpe, i, 0, LTQ_ICU_IRSR); 37285cf2c37SPetr Cvek } 37316f70b56SJohn Crispin } 374171bb2f1SJohn Crispin 375171bb2f1SJohn Crispin mips_cpu_irq_init(); 376171bb2f1SJohn Crispin 37761fa969fSJohn Crispin for (i = 0; i < MAX_IM; i++) 3786c356edaSFelix Fietkau irq_set_chained_handler(i + 2, ltq_hw_irq_handler); 379171bb2f1SJohn Crispin 380c2c9c788SJohn Crispin ltq_domain = irq_domain_add_linear(node, 38161fa969fSJohn Crispin (MAX_IM * INT_NUM_IM_OFFSET) + MIPS_CPU_IRQ_CASCADE, 3823645da02SJohn Crispin &irq_domain_ops, 0); 383171bb2f1SJohn Crispin 38459c11579SJohn Crispin /* tell oprofile which irq to use */ 385a669efc4SAndrew Bresticker ltq_perfcount_irq = irq_create_mapping(ltq_domain, LTQ_PERF_IRQ); 386c2c9c788SJohn Crispin 387d32caf94SJohn Crispin /* the external interrupts are optional and xway only */ 388d32caf94SJohn Crispin eiu_node = of_find_compatible_node(NULL, NULL, "lantiq,eiu-xway"); 389d32caf94SJohn Crispin if (eiu_node && !of_address_to_resource(eiu_node, 0, &res)) { 390d32caf94SJohn Crispin /* find out how many external irq sources we have */ 391fe46e503SJohn Crispin exin_avail = of_property_count_u32_elems(eiu_node, 392fe46e503SJohn Crispin "lantiq,eiu-irqs"); 393d32caf94SJohn Crispin 394d32caf94SJohn Crispin if (exin_avail > MAX_EIU) 395d32caf94SJohn Crispin exin_avail = MAX_EIU; 396d32caf94SJohn Crispin 397fe46e503SJohn Crispin ret = of_property_read_u32_array(eiu_node, "lantiq,eiu-irqs", 398d32caf94SJohn Crispin ltq_eiu_irq, exin_avail); 399fe46e503SJohn Crispin if (ret) 400d32caf94SJohn Crispin panic("failed to load external irq resources"); 401d32caf94SJohn Crispin 4026e807852SHauke Mehrtens if (!request_mem_region(res.start, resource_size(&res), 4036e807852SHauke Mehrtens res.name)) 404d32caf94SJohn Crispin pr_err("Failed to request eiu memory"); 405d32caf94SJohn Crispin 4064bdc0d67SChristoph Hellwig ltq_eiu_membase = ioremap(res.start, 407d32caf94SJohn Crispin resource_size(&res)); 408d32caf94SJohn Crispin if (!ltq_eiu_membase) 409d32caf94SJohn Crispin panic("Failed to remap eiu memory"); 410d32caf94SJohn Crispin } 411*3748d218SLiang He of_node_put(eiu_node); 412d32caf94SJohn Crispin 4133645da02SJohn Crispin return 0; 414171bb2f1SJohn Crispin } 415171bb2f1SJohn Crispin 416a669efc4SAndrew Bresticker int get_c0_perfcount_int(void) 417a669efc4SAndrew Bresticker { 418a669efc4SAndrew Bresticker return ltq_perfcount_irq; 419a669efc4SAndrew Bresticker } 4200cb0985fSFelix Fietkau EXPORT_SYMBOL_GPL(get_c0_perfcount_int); 421a669efc4SAndrew Bresticker 422078a55fcSPaul Gortmaker unsigned int get_c0_compare_int(void) 423171bb2f1SJohn Crispin { 424390d1b46SHauke Mehrtens return CP0_LEGACY_COMPARE_IRQ; 425171bb2f1SJohn Crispin } 4263645da02SJohn Crispin 427e91fd6ddSMartin Blumenstingl IRQCHIP_DECLARE(lantiq_icu, "lantiq,icu", icu_of_init); 4283645da02SJohn Crispin 4293645da02SJohn Crispin void __init arch_init_irq(void) 4303645da02SJohn Crispin { 431e91fd6ddSMartin Blumenstingl irqchip_init(); 4323645da02SJohn Crispin } 433