1171bb2f1SJohn Crispin /* 2171bb2f1SJohn Crispin * This program is free software; you can redistribute it and/or modify it 3171bb2f1SJohn Crispin * under the terms of the GNU General Public License version 2 as published 4171bb2f1SJohn Crispin * by the Free Software Foundation. 5171bb2f1SJohn Crispin * 697b92108SJohn Crispin * Copyright (C) 2010 John Crispin <john@phrozen.org> 7171bb2f1SJohn Crispin * Copyright (C) 2010 Thomas Langer <thomas.langer@lantiq.com> 8171bb2f1SJohn Crispin */ 9171bb2f1SJohn Crispin 10171bb2f1SJohn Crispin #include <linux/interrupt.h> 11171bb2f1SJohn Crispin #include <linux/ioport.h> 123645da02SJohn Crispin #include <linux/sched.h> 133645da02SJohn Crispin #include <linux/irqdomain.h> 143645da02SJohn Crispin #include <linux/of_platform.h> 153645da02SJohn Crispin #include <linux/of_address.h> 163645da02SJohn Crispin #include <linux/of_irq.h> 17171bb2f1SJohn Crispin 18171bb2f1SJohn Crispin #include <asm/bootinfo.h> 19171bb2f1SJohn Crispin #include <asm/irq_cpu.h> 20171bb2f1SJohn Crispin 21171bb2f1SJohn Crispin #include <lantiq_soc.h> 22171bb2f1SJohn Crispin #include <irq.h> 23171bb2f1SJohn Crispin 243645da02SJohn Crispin /* register definitions - internal irqs */ 25171bb2f1SJohn Crispin #define LTQ_ICU_IM0_ISR 0x0000 26171bb2f1SJohn Crispin #define LTQ_ICU_IM0_IER 0x0008 27171bb2f1SJohn Crispin #define LTQ_ICU_IM0_IOSR 0x0010 28171bb2f1SJohn Crispin #define LTQ_ICU_IM0_IRSR 0x0018 29171bb2f1SJohn Crispin #define LTQ_ICU_IM0_IMR 0x0020 30171bb2f1SJohn Crispin #define LTQ_ICU_IM1_ISR 0x0028 31171bb2f1SJohn Crispin #define LTQ_ICU_OFFSET (LTQ_ICU_IM1_ISR - LTQ_ICU_IM0_ISR) 32171bb2f1SJohn Crispin 333645da02SJohn Crispin /* register definitions - external irqs */ 34171bb2f1SJohn Crispin #define LTQ_EIU_EXIN_C 0x0000 35171bb2f1SJohn Crispin #define LTQ_EIU_EXIN_INIC 0x0004 3626365625SJohn Crispin #define LTQ_EIU_EXIN_INC 0x0008 37171bb2f1SJohn Crispin #define LTQ_EIU_EXIN_INEN 0x000C 38171bb2f1SJohn Crispin 3926365625SJohn Crispin /* number of external interrupts */ 40171bb2f1SJohn Crispin #define MAX_EIU 6 41171bb2f1SJohn Crispin 4259c11579SJohn Crispin /* the performance counter */ 4359c11579SJohn Crispin #define LTQ_PERF_IRQ (INT_NUM_IM4_IRL0 + 31) 4459c11579SJohn Crispin 453645da02SJohn Crispin /* 463645da02SJohn Crispin * irqs generated by devices attached to the EBU need to be acked in 47171bb2f1SJohn Crispin * a special manner 48171bb2f1SJohn Crispin */ 49171bb2f1SJohn Crispin #define LTQ_ICU_EBU_IRQ 22 50171bb2f1SJohn Crispin 5161fa969fSJohn Crispin #define ltq_icu_w32(m, x, y) ltq_w32((x), ltq_icu_membase[m] + (y)) 5261fa969fSJohn Crispin #define ltq_icu_r32(m, x) ltq_r32(ltq_icu_membase[m] + (x)) 53171bb2f1SJohn Crispin 54171bb2f1SJohn Crispin #define ltq_eiu_w32(x, y) ltq_w32((x), ltq_eiu_membase + (y)) 55171bb2f1SJohn Crispin #define ltq_eiu_r32(x) ltq_r32(ltq_eiu_membase + (x)) 56171bb2f1SJohn Crispin 57a8d096efSJohn Crispin /* our 2 ipi interrupts for VSMP */ 58a8d096efSJohn Crispin #define MIPS_CPU_IPI_RESCHED_IRQ 0 59a8d096efSJohn Crispin #define MIPS_CPU_IPI_CALL_IRQ 1 60a8d096efSJohn Crispin 613645da02SJohn Crispin /* we have a cascade of 8 irqs */ 623645da02SJohn Crispin #define MIPS_CPU_IRQ_CASCADE 8 633645da02SJohn Crispin 64b633648cSRalf Baechle #ifdef CONFIG_MIPS_MT_SMP 65a8d096efSJohn Crispin int gic_present; 66a8d096efSJohn Crispin #endif 67a8d096efSJohn Crispin 683645da02SJohn Crispin static int exin_avail; 69fe46e503SJohn Crispin static u32 ltq_eiu_irq[MAX_EIU]; 7061fa969fSJohn Crispin static void __iomem *ltq_icu_membase[MAX_IM]; 71171bb2f1SJohn Crispin static void __iomem *ltq_eiu_membase; 72c2c9c788SJohn Crispin static struct irq_domain *ltq_domain; 73a669efc4SAndrew Bresticker static int ltq_perfcount_irq; 74171bb2f1SJohn Crispin 7526365625SJohn Crispin int ltq_eiu_get_irq(int exin) 7626365625SJohn Crispin { 7726365625SJohn Crispin if (exin < exin_avail) 78fe46e503SJohn Crispin return ltq_eiu_irq[exin]; 7926365625SJohn Crispin return -1; 8026365625SJohn Crispin } 8126365625SJohn Crispin 82171bb2f1SJohn Crispin void ltq_disable_irq(struct irq_data *d) 83171bb2f1SJohn Crispin { 84171bb2f1SJohn Crispin u32 ier = LTQ_ICU_IM0_IER; 853645da02SJohn Crispin int offset = d->hwirq - MIPS_CPU_IRQ_CASCADE; 8661fa969fSJohn Crispin int im = offset / INT_NUM_IM_OFFSET; 87171bb2f1SJohn Crispin 883645da02SJohn Crispin offset %= INT_NUM_IM_OFFSET; 8961fa969fSJohn Crispin ltq_icu_w32(im, ltq_icu_r32(im, ier) & ~BIT(offset), ier); 90171bb2f1SJohn Crispin } 91171bb2f1SJohn Crispin 92171bb2f1SJohn Crispin void ltq_mask_and_ack_irq(struct irq_data *d) 93171bb2f1SJohn Crispin { 94171bb2f1SJohn Crispin u32 ier = LTQ_ICU_IM0_IER; 95171bb2f1SJohn Crispin u32 isr = LTQ_ICU_IM0_ISR; 963645da02SJohn Crispin int offset = d->hwirq - MIPS_CPU_IRQ_CASCADE; 9761fa969fSJohn Crispin int im = offset / INT_NUM_IM_OFFSET; 98171bb2f1SJohn Crispin 993645da02SJohn Crispin offset %= INT_NUM_IM_OFFSET; 10061fa969fSJohn Crispin ltq_icu_w32(im, ltq_icu_r32(im, ier) & ~BIT(offset), ier); 10161fa969fSJohn Crispin ltq_icu_w32(im, BIT(offset), isr); 102171bb2f1SJohn Crispin } 103171bb2f1SJohn Crispin 104171bb2f1SJohn Crispin static void ltq_ack_irq(struct irq_data *d) 105171bb2f1SJohn Crispin { 106171bb2f1SJohn Crispin u32 isr = LTQ_ICU_IM0_ISR; 1073645da02SJohn Crispin int offset = d->hwirq - MIPS_CPU_IRQ_CASCADE; 10861fa969fSJohn Crispin int im = offset / INT_NUM_IM_OFFSET; 109171bb2f1SJohn Crispin 1103645da02SJohn Crispin offset %= INT_NUM_IM_OFFSET; 11161fa969fSJohn Crispin ltq_icu_w32(im, BIT(offset), isr); 112171bb2f1SJohn Crispin } 113171bb2f1SJohn Crispin 114171bb2f1SJohn Crispin void ltq_enable_irq(struct irq_data *d) 115171bb2f1SJohn Crispin { 116171bb2f1SJohn Crispin u32 ier = LTQ_ICU_IM0_IER; 1173645da02SJohn Crispin int offset = d->hwirq - MIPS_CPU_IRQ_CASCADE; 11861fa969fSJohn Crispin int im = offset / INT_NUM_IM_OFFSET; 119171bb2f1SJohn Crispin 1203645da02SJohn Crispin offset %= INT_NUM_IM_OFFSET; 12161fa969fSJohn Crispin ltq_icu_w32(im, ltq_icu_r32(im, ier) | BIT(offset), ier); 122171bb2f1SJohn Crispin } 123171bb2f1SJohn Crispin 12426365625SJohn Crispin static int ltq_eiu_settype(struct irq_data *d, unsigned int type) 12526365625SJohn Crispin { 12626365625SJohn Crispin int i; 12726365625SJohn Crispin 128f97e5e8eSJohn Crispin for (i = 0; i < exin_avail; i++) { 129fe46e503SJohn Crispin if (d->hwirq == ltq_eiu_irq[i]) { 13026365625SJohn Crispin int val = 0; 13126365625SJohn Crispin int edge = 0; 13226365625SJohn Crispin 13326365625SJohn Crispin switch (type) { 13426365625SJohn Crispin case IRQF_TRIGGER_NONE: 13526365625SJohn Crispin break; 13626365625SJohn Crispin case IRQF_TRIGGER_RISING: 13726365625SJohn Crispin val = 1; 13826365625SJohn Crispin edge = 1; 13926365625SJohn Crispin break; 14026365625SJohn Crispin case IRQF_TRIGGER_FALLING: 14126365625SJohn Crispin val = 2; 14226365625SJohn Crispin edge = 1; 14326365625SJohn Crispin break; 14426365625SJohn Crispin case IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING: 14526365625SJohn Crispin val = 3; 14626365625SJohn Crispin edge = 1; 14726365625SJohn Crispin break; 14826365625SJohn Crispin case IRQF_TRIGGER_HIGH: 14926365625SJohn Crispin val = 5; 15026365625SJohn Crispin break; 15126365625SJohn Crispin case IRQF_TRIGGER_LOW: 15226365625SJohn Crispin val = 6; 15326365625SJohn Crispin break; 15426365625SJohn Crispin default: 15526365625SJohn Crispin pr_err("invalid type %d for irq %ld\n", 15626365625SJohn Crispin type, d->hwirq); 15726365625SJohn Crispin return -EINVAL; 15826365625SJohn Crispin } 15926365625SJohn Crispin 16026365625SJohn Crispin if (edge) 16126365625SJohn Crispin irq_set_handler(d->hwirq, handle_edge_irq); 16226365625SJohn Crispin 16326365625SJohn Crispin ltq_eiu_w32(ltq_eiu_r32(LTQ_EIU_EXIN_C) | 16426365625SJohn Crispin (val << (i * 4)), LTQ_EIU_EXIN_C); 16526365625SJohn Crispin } 16626365625SJohn Crispin } 16726365625SJohn Crispin 16826365625SJohn Crispin return 0; 16926365625SJohn Crispin } 17026365625SJohn Crispin 171171bb2f1SJohn Crispin static unsigned int ltq_startup_eiu_irq(struct irq_data *d) 172171bb2f1SJohn Crispin { 173171bb2f1SJohn Crispin int i; 174171bb2f1SJohn Crispin 175171bb2f1SJohn Crispin ltq_enable_irq(d); 176f97e5e8eSJohn Crispin for (i = 0; i < exin_avail; i++) { 177fe46e503SJohn Crispin if (d->hwirq == ltq_eiu_irq[i]) { 17826365625SJohn Crispin /* by default we are low level triggered */ 17926365625SJohn Crispin ltq_eiu_settype(d, IRQF_TRIGGER_LOW); 180171bb2f1SJohn Crispin /* clear all pending */ 18126365625SJohn Crispin ltq_eiu_w32(ltq_eiu_r32(LTQ_EIU_EXIN_INC) & ~BIT(i), 18226365625SJohn Crispin LTQ_EIU_EXIN_INC); 183171bb2f1SJohn Crispin /* enable */ 1843645da02SJohn Crispin ltq_eiu_w32(ltq_eiu_r32(LTQ_EIU_EXIN_INEN) | BIT(i), 185171bb2f1SJohn Crispin LTQ_EIU_EXIN_INEN); 186171bb2f1SJohn Crispin break; 187171bb2f1SJohn Crispin } 188171bb2f1SJohn Crispin } 189171bb2f1SJohn Crispin 190171bb2f1SJohn Crispin return 0; 191171bb2f1SJohn Crispin } 192171bb2f1SJohn Crispin 193171bb2f1SJohn Crispin static void ltq_shutdown_eiu_irq(struct irq_data *d) 194171bb2f1SJohn Crispin { 195171bb2f1SJohn Crispin int i; 196171bb2f1SJohn Crispin 197171bb2f1SJohn Crispin ltq_disable_irq(d); 198f97e5e8eSJohn Crispin for (i = 0; i < exin_avail; i++) { 199fe46e503SJohn Crispin if (d->hwirq == ltq_eiu_irq[i]) { 200171bb2f1SJohn Crispin /* disable */ 2013645da02SJohn Crispin ltq_eiu_w32(ltq_eiu_r32(LTQ_EIU_EXIN_INEN) & ~BIT(i), 202171bb2f1SJohn Crispin LTQ_EIU_EXIN_INEN); 203171bb2f1SJohn Crispin break; 204171bb2f1SJohn Crispin } 205171bb2f1SJohn Crispin } 206171bb2f1SJohn Crispin } 207171bb2f1SJohn Crispin 208171bb2f1SJohn Crispin static struct irq_chip ltq_irq_type = { 209891ab064SSudip Mukherjee .name = "icu", 210171bb2f1SJohn Crispin .irq_enable = ltq_enable_irq, 211171bb2f1SJohn Crispin .irq_disable = ltq_disable_irq, 212171bb2f1SJohn Crispin .irq_unmask = ltq_enable_irq, 213171bb2f1SJohn Crispin .irq_ack = ltq_ack_irq, 214171bb2f1SJohn Crispin .irq_mask = ltq_disable_irq, 215171bb2f1SJohn Crispin .irq_mask_ack = ltq_mask_and_ack_irq, 216171bb2f1SJohn Crispin }; 217171bb2f1SJohn Crispin 218171bb2f1SJohn Crispin static struct irq_chip ltq_eiu_type = { 219891ab064SSudip Mukherjee .name = "eiu", 220171bb2f1SJohn Crispin .irq_startup = ltq_startup_eiu_irq, 221171bb2f1SJohn Crispin .irq_shutdown = ltq_shutdown_eiu_irq, 222171bb2f1SJohn Crispin .irq_enable = ltq_enable_irq, 223171bb2f1SJohn Crispin .irq_disable = ltq_disable_irq, 224171bb2f1SJohn Crispin .irq_unmask = ltq_enable_irq, 225171bb2f1SJohn Crispin .irq_ack = ltq_ack_irq, 226171bb2f1SJohn Crispin .irq_mask = ltq_disable_irq, 227171bb2f1SJohn Crispin .irq_mask_ack = ltq_mask_and_ack_irq, 22826365625SJohn Crispin .irq_set_type = ltq_eiu_settype, 229171bb2f1SJohn Crispin }; 230171bb2f1SJohn Crispin 231171bb2f1SJohn Crispin static void ltq_hw_irqdispatch(int module) 232171bb2f1SJohn Crispin { 233171bb2f1SJohn Crispin u32 irq; 234171bb2f1SJohn Crispin 23561fa969fSJohn Crispin irq = ltq_icu_r32(module, LTQ_ICU_IM0_IOSR); 236171bb2f1SJohn Crispin if (irq == 0) 237171bb2f1SJohn Crispin return; 238171bb2f1SJohn Crispin 2393645da02SJohn Crispin /* 2403645da02SJohn Crispin * silicon bug causes only the msb set to 1 to be valid. all 241171bb2f1SJohn Crispin * other bits might be bogus 242171bb2f1SJohn Crispin */ 243171bb2f1SJohn Crispin irq = __fls(irq); 2443645da02SJohn Crispin do_IRQ((int)irq + MIPS_CPU_IRQ_CASCADE + (INT_NUM_IM_OFFSET * module)); 245171bb2f1SJohn Crispin 246171bb2f1SJohn Crispin /* if this is a EBU irq, we need to ack it or get a deadlock */ 2473645da02SJohn Crispin if ((irq == LTQ_ICU_EBU_IRQ) && (module == 0) && LTQ_EBU_PCC_ISTAT) 248171bb2f1SJohn Crispin ltq_ebu_w32(ltq_ebu_r32(LTQ_EBU_PCC_ISTAT) | 0x10, 249171bb2f1SJohn Crispin LTQ_EBU_PCC_ISTAT); 250171bb2f1SJohn Crispin } 251171bb2f1SJohn Crispin 252171bb2f1SJohn Crispin #define DEFINE_HWx_IRQDISPATCH(x) \ 253171bb2f1SJohn Crispin static void ltq_hw ## x ## _irqdispatch(void) \ 254171bb2f1SJohn Crispin { \ 255171bb2f1SJohn Crispin ltq_hw_irqdispatch(x); \ 256171bb2f1SJohn Crispin } 257171bb2f1SJohn Crispin DEFINE_HWx_IRQDISPATCH(0) 258171bb2f1SJohn Crispin DEFINE_HWx_IRQDISPATCH(1) 259171bb2f1SJohn Crispin DEFINE_HWx_IRQDISPATCH(2) 260171bb2f1SJohn Crispin DEFINE_HWx_IRQDISPATCH(3) 261171bb2f1SJohn Crispin DEFINE_HWx_IRQDISPATCH(4) 262171bb2f1SJohn Crispin 263c2c9c788SJohn Crispin #if MIPS_CPU_TIMER_IRQ == 7 264171bb2f1SJohn Crispin static void ltq_hw5_irqdispatch(void) 265171bb2f1SJohn Crispin { 266171bb2f1SJohn Crispin do_IRQ(MIPS_CPU_TIMER_IRQ); 267171bb2f1SJohn Crispin } 268c2c9c788SJohn Crispin #else 269c2c9c788SJohn Crispin DEFINE_HWx_IRQDISPATCH(5) 270c2c9c788SJohn Crispin #endif 271171bb2f1SJohn Crispin 272*6c356edaSFelix Fietkau static void ltq_hw_irq_handler(struct irq_desc *desc) 273*6c356edaSFelix Fietkau { 274*6c356edaSFelix Fietkau ltq_hw_irqdispatch(irq_desc_get_irq(desc) - 2); 275*6c356edaSFelix Fietkau } 276*6c356edaSFelix Fietkau 277a8d096efSJohn Crispin #ifdef CONFIG_MIPS_MT_SMP 278a8d096efSJohn Crispin void __init arch_init_ipiirq(int irq, struct irqaction *action) 279a8d096efSJohn Crispin { 280a8d096efSJohn Crispin setup_irq(irq, action); 281a8d096efSJohn Crispin irq_set_handler(irq, handle_percpu_irq); 282a8d096efSJohn Crispin } 283a8d096efSJohn Crispin 284a8d096efSJohn Crispin static void ltq_sw0_irqdispatch(void) 285a8d096efSJohn Crispin { 286a8d096efSJohn Crispin do_IRQ(MIPS_CPU_IRQ_BASE + MIPS_CPU_IPI_RESCHED_IRQ); 287a8d096efSJohn Crispin } 288a8d096efSJohn Crispin 289a8d096efSJohn Crispin static void ltq_sw1_irqdispatch(void) 290a8d096efSJohn Crispin { 291a8d096efSJohn Crispin do_IRQ(MIPS_CPU_IRQ_BASE + MIPS_CPU_IPI_CALL_IRQ); 292a8d096efSJohn Crispin } 293a8d096efSJohn Crispin static irqreturn_t ipi_resched_interrupt(int irq, void *dev_id) 294a8d096efSJohn Crispin { 295a8d096efSJohn Crispin scheduler_ipi(); 296a8d096efSJohn Crispin return IRQ_HANDLED; 297a8d096efSJohn Crispin } 298a8d096efSJohn Crispin 299a8d096efSJohn Crispin static irqreturn_t ipi_call_interrupt(int irq, void *dev_id) 300a8d096efSJohn Crispin { 3014ace6139SAlex Smith generic_smp_call_function_interrupt(); 302a8d096efSJohn Crispin return IRQ_HANDLED; 303a8d096efSJohn Crispin } 304a8d096efSJohn Crispin 305a8d096efSJohn Crispin static struct irqaction irq_resched = { 306a8d096efSJohn Crispin .handler = ipi_resched_interrupt, 307a8d096efSJohn Crispin .flags = IRQF_PERCPU, 308a8d096efSJohn Crispin .name = "IPI_resched" 309a8d096efSJohn Crispin }; 310a8d096efSJohn Crispin 311a8d096efSJohn Crispin static struct irqaction irq_call = { 312a8d096efSJohn Crispin .handler = ipi_call_interrupt, 313a8d096efSJohn Crispin .flags = IRQF_PERCPU, 314a8d096efSJohn Crispin .name = "IPI_call" 315a8d096efSJohn Crispin }; 316a8d096efSJohn Crispin #endif 317a8d096efSJohn Crispin 318171bb2f1SJohn Crispin asmlinkage void plat_irq_dispatch(void) 319171bb2f1SJohn Crispin { 320171bb2f1SJohn Crispin unsigned int pending = read_c0_status() & read_c0_cause() & ST0_IM; 321*6c356edaSFelix Fietkau int irq; 322171bb2f1SJohn Crispin 323*6c356edaSFelix Fietkau if (!pending) { 324*6c356edaSFelix Fietkau spurious_interrupt(); 325171bb2f1SJohn Crispin return; 326171bb2f1SJohn Crispin } 327171bb2f1SJohn Crispin 328*6c356edaSFelix Fietkau pending >>= CAUSEB_IP; 329*6c356edaSFelix Fietkau while (pending) { 330*6c356edaSFelix Fietkau irq = fls(pending) - 1; 331*6c356edaSFelix Fietkau do_IRQ(MIPS_CPU_IRQ_BASE + irq); 332*6c356edaSFelix Fietkau pending &= ~BIT(irq); 333*6c356edaSFelix Fietkau } 334*6c356edaSFelix Fietkau } 335*6c356edaSFelix Fietkau 3363645da02SJohn Crispin static int icu_map(struct irq_domain *d, unsigned int irq, irq_hw_number_t hw) 3373645da02SJohn Crispin { 3383645da02SJohn Crispin struct irq_chip *chip = <q_irq_type; 3393645da02SJohn Crispin int i; 3403645da02SJohn Crispin 3419c1628b6SJohn Crispin if (hw < MIPS_CPU_IRQ_CASCADE) 3429c1628b6SJohn Crispin return 0; 3439c1628b6SJohn Crispin 3443645da02SJohn Crispin for (i = 0; i < exin_avail; i++) 345fe46e503SJohn Crispin if (hw == ltq_eiu_irq[i]) 3463645da02SJohn Crispin chip = <q_eiu_type; 3473645da02SJohn Crispin 3487bf0d5e8SHauke Mehrtens irq_set_chip_and_handler(irq, chip, handle_level_irq); 3493645da02SJohn Crispin 3503645da02SJohn Crispin return 0; 3513645da02SJohn Crispin } 3523645da02SJohn Crispin 3533645da02SJohn Crispin static const struct irq_domain_ops irq_domain_ops = { 3543645da02SJohn Crispin .xlate = irq_domain_xlate_onetwocell, 3553645da02SJohn Crispin .map = icu_map, 3563645da02SJohn Crispin }; 3573645da02SJohn Crispin 3583645da02SJohn Crispin int __init icu_of_init(struct device_node *node, struct device_node *parent) 359171bb2f1SJohn Crispin { 3603645da02SJohn Crispin struct device_node *eiu_node; 3613645da02SJohn Crispin struct resource res; 36226365625SJohn Crispin int i, ret; 363171bb2f1SJohn Crispin 36461fa969fSJohn Crispin for (i = 0; i < MAX_IM; i++) { 36561fa969fSJohn Crispin if (of_address_to_resource(node, i, &res)) 3663645da02SJohn Crispin panic("Failed to get icu memory range"); 367171bb2f1SJohn Crispin 3686e807852SHauke Mehrtens if (!request_mem_region(res.start, resource_size(&res), 3696e807852SHauke Mehrtens res.name)) 3703645da02SJohn Crispin pr_err("Failed to request icu memory"); 371171bb2f1SJohn Crispin 37261fa969fSJohn Crispin ltq_icu_membase[i] = ioremap_nocache(res.start, 37361fa969fSJohn Crispin resource_size(&res)); 37461fa969fSJohn Crispin if (!ltq_icu_membase[i]) 375ab75dc02SRalf Baechle panic("Failed to remap icu memory"); 37661fa969fSJohn Crispin } 377171bb2f1SJohn Crispin 37816f70b56SJohn Crispin /* turn off all irqs by default */ 37961fa969fSJohn Crispin for (i = 0; i < MAX_IM; i++) { 380171bb2f1SJohn Crispin /* make sure all irqs are turned off by default */ 38161fa969fSJohn Crispin ltq_icu_w32(i, 0, LTQ_ICU_IM0_IER); 382171bb2f1SJohn Crispin /* clear all possibly pending interrupts */ 38361fa969fSJohn Crispin ltq_icu_w32(i, ~0, LTQ_ICU_IM0_ISR); 38416f70b56SJohn Crispin } 385171bb2f1SJohn Crispin 386171bb2f1SJohn Crispin mips_cpu_irq_init(); 387171bb2f1SJohn Crispin 38861fa969fSJohn Crispin for (i = 0; i < MAX_IM; i++) 389*6c356edaSFelix Fietkau irq_set_chained_handler(i + 2, ltq_hw_irq_handler); 390171bb2f1SJohn Crispin 391171bb2f1SJohn Crispin if (cpu_has_vint) { 392171bb2f1SJohn Crispin pr_info("Setting up vectored interrupts\n"); 393171bb2f1SJohn Crispin set_vi_handler(2, ltq_hw0_irqdispatch); 394171bb2f1SJohn Crispin set_vi_handler(3, ltq_hw1_irqdispatch); 395171bb2f1SJohn Crispin set_vi_handler(4, ltq_hw2_irqdispatch); 396171bb2f1SJohn Crispin set_vi_handler(5, ltq_hw3_irqdispatch); 397171bb2f1SJohn Crispin set_vi_handler(6, ltq_hw4_irqdispatch); 398171bb2f1SJohn Crispin set_vi_handler(7, ltq_hw5_irqdispatch); 399171bb2f1SJohn Crispin } 400171bb2f1SJohn Crispin 401c2c9c788SJohn Crispin ltq_domain = irq_domain_add_linear(node, 40261fa969fSJohn Crispin (MAX_IM * INT_NUM_IM_OFFSET) + MIPS_CPU_IRQ_CASCADE, 4033645da02SJohn Crispin &irq_domain_ops, 0); 404171bb2f1SJohn Crispin 405a8d096efSJohn Crispin #if defined(CONFIG_MIPS_MT_SMP) 406a8d096efSJohn Crispin if (cpu_has_vint) { 407a8d096efSJohn Crispin pr_info("Setting up IPI vectored interrupts\n"); 408a8d096efSJohn Crispin set_vi_handler(MIPS_CPU_IPI_RESCHED_IRQ, ltq_sw0_irqdispatch); 409a8d096efSJohn Crispin set_vi_handler(MIPS_CPU_IPI_CALL_IRQ, ltq_sw1_irqdispatch); 410a8d096efSJohn Crispin } 411a8d096efSJohn Crispin arch_init_ipiirq(MIPS_CPU_IRQ_BASE + MIPS_CPU_IPI_RESCHED_IRQ, 412a8d096efSJohn Crispin &irq_resched); 413a8d096efSJohn Crispin arch_init_ipiirq(MIPS_CPU_IRQ_BASE + MIPS_CPU_IPI_CALL_IRQ, &irq_call); 414a8d096efSJohn Crispin #endif 415a8d096efSJohn Crispin 416b633648cSRalf Baechle #ifndef CONFIG_MIPS_MT_SMP 417171bb2f1SJohn Crispin set_c0_status(IE_IRQ0 | IE_IRQ1 | IE_IRQ2 | 418171bb2f1SJohn Crispin IE_IRQ3 | IE_IRQ4 | IE_IRQ5); 419171bb2f1SJohn Crispin #else 420171bb2f1SJohn Crispin set_c0_status(IE_SW0 | IE_SW1 | IE_IRQ0 | IE_IRQ1 | 421171bb2f1SJohn Crispin IE_IRQ2 | IE_IRQ3 | IE_IRQ4 | IE_IRQ5); 422171bb2f1SJohn Crispin #endif 42359c11579SJohn Crispin 42459c11579SJohn Crispin /* tell oprofile which irq to use */ 425a669efc4SAndrew Bresticker ltq_perfcount_irq = irq_create_mapping(ltq_domain, LTQ_PERF_IRQ); 426c2c9c788SJohn Crispin 427c2c9c788SJohn Crispin /* 428c2c9c788SJohn Crispin * if the timer irq is not one of the mips irqs we need to 429c2c9c788SJohn Crispin * create a mapping 430c2c9c788SJohn Crispin */ 431c2c9c788SJohn Crispin if (MIPS_CPU_TIMER_IRQ != 7) 432c2c9c788SJohn Crispin irq_create_mapping(ltq_domain, MIPS_CPU_TIMER_IRQ); 433c2c9c788SJohn Crispin 434d32caf94SJohn Crispin /* the external interrupts are optional and xway only */ 435d32caf94SJohn Crispin eiu_node = of_find_compatible_node(NULL, NULL, "lantiq,eiu-xway"); 436d32caf94SJohn Crispin if (eiu_node && !of_address_to_resource(eiu_node, 0, &res)) { 437d32caf94SJohn Crispin /* find out how many external irq sources we have */ 438fe46e503SJohn Crispin exin_avail = of_property_count_u32_elems(eiu_node, 439fe46e503SJohn Crispin "lantiq,eiu-irqs"); 440d32caf94SJohn Crispin 441d32caf94SJohn Crispin if (exin_avail > MAX_EIU) 442d32caf94SJohn Crispin exin_avail = MAX_EIU; 443d32caf94SJohn Crispin 444fe46e503SJohn Crispin ret = of_property_read_u32_array(eiu_node, "lantiq,eiu-irqs", 445d32caf94SJohn Crispin ltq_eiu_irq, exin_avail); 446fe46e503SJohn Crispin if (ret) 447d32caf94SJohn Crispin panic("failed to load external irq resources"); 448d32caf94SJohn Crispin 4496e807852SHauke Mehrtens if (!request_mem_region(res.start, resource_size(&res), 4506e807852SHauke Mehrtens res.name)) 451d32caf94SJohn Crispin pr_err("Failed to request eiu memory"); 452d32caf94SJohn Crispin 453d32caf94SJohn Crispin ltq_eiu_membase = ioremap_nocache(res.start, 454d32caf94SJohn Crispin resource_size(&res)); 455d32caf94SJohn Crispin if (!ltq_eiu_membase) 456d32caf94SJohn Crispin panic("Failed to remap eiu memory"); 457d32caf94SJohn Crispin } 458d32caf94SJohn Crispin 4593645da02SJohn Crispin return 0; 460171bb2f1SJohn Crispin } 461171bb2f1SJohn Crispin 462a669efc4SAndrew Bresticker int get_c0_perfcount_int(void) 463a669efc4SAndrew Bresticker { 464a669efc4SAndrew Bresticker return ltq_perfcount_irq; 465a669efc4SAndrew Bresticker } 4660cb0985fSFelix Fietkau EXPORT_SYMBOL_GPL(get_c0_perfcount_int); 467a669efc4SAndrew Bresticker 468078a55fcSPaul Gortmaker unsigned int get_c0_compare_int(void) 469171bb2f1SJohn Crispin { 470c2c9c788SJohn Crispin return MIPS_CPU_TIMER_IRQ; 471171bb2f1SJohn Crispin } 4723645da02SJohn Crispin 4733645da02SJohn Crispin static struct of_device_id __initdata of_irq_ids[] = { 4743645da02SJohn Crispin { .compatible = "lantiq,icu", .data = icu_of_init }, 4753645da02SJohn Crispin {}, 4763645da02SJohn Crispin }; 4773645da02SJohn Crispin 4783645da02SJohn Crispin void __init arch_init_irq(void) 4793645da02SJohn Crispin { 4803645da02SJohn Crispin of_irq_init(of_irq_ids); 4813645da02SJohn Crispin } 482