1c052d13cSHaojian Zhuang /* 2c052d13cSHaojian Zhuang * linux/arch/arm/mach-mmp/irq.c 3c052d13cSHaojian Zhuang * 4c052d13cSHaojian Zhuang * Generic IRQ handling, GPIO IRQ demultiplexing, etc. 5c052d13cSHaojian Zhuang * Copyright (C) 2008 - 2012 Marvell Technology Group Ltd. 6c052d13cSHaojian Zhuang * 7c052d13cSHaojian Zhuang * Author: Bin Yang <bin.yang@marvell.com> 8c052d13cSHaojian Zhuang * Haojian Zhuang <haojian.zhuang@gmail.com> 9c052d13cSHaojian Zhuang * 10c052d13cSHaojian Zhuang * This program is free software; you can redistribute it and/or modify 11c052d13cSHaojian Zhuang * it under the terms of the GNU General Public License version 2 as 12c052d13cSHaojian Zhuang * published by the Free Software Foundation. 13c052d13cSHaojian Zhuang */ 14c052d13cSHaojian Zhuang 15c052d13cSHaojian Zhuang #include <linux/module.h> 16c052d13cSHaojian Zhuang #include <linux/init.h> 17c052d13cSHaojian Zhuang #include <linux/irq.h> 18c052d13cSHaojian Zhuang #include <linux/irqdomain.h> 19c052d13cSHaojian Zhuang #include <linux/io.h> 20c052d13cSHaojian Zhuang #include <linux/ioport.h> 21c052d13cSHaojian Zhuang #include <linux/of_address.h> 22c052d13cSHaojian Zhuang #include <linux/of_irq.h> 23c052d13cSHaojian Zhuang 240f374561SHaojian Zhuang #include <asm/exception.h> 250f374561SHaojian Zhuang #include <asm/mach/irq.h> 260f374561SHaojian Zhuang 270f374561SHaojian Zhuang #include "irqchip.h" 280f374561SHaojian Zhuang 29c052d13cSHaojian Zhuang #define MAX_ICU_NR 16 30c052d13cSHaojian Zhuang 310f374561SHaojian Zhuang #define PJ1_INT_SEL 0x10c 320f374561SHaojian Zhuang #define PJ4_INT_SEL 0x104 330f374561SHaojian Zhuang 340f374561SHaojian Zhuang /* bit fields in PJ1_INT_SEL and PJ4_INT_SEL */ 350f374561SHaojian Zhuang #define SEL_INT_PENDING (1 << 6) 360f374561SHaojian Zhuang #define SEL_INT_NUM_MASK 0x3f 370f374561SHaojian Zhuang 38c052d13cSHaojian Zhuang struct icu_chip_data { 39c052d13cSHaojian Zhuang int nr_irqs; 40c052d13cSHaojian Zhuang unsigned int virq_base; 41c052d13cSHaojian Zhuang unsigned int cascade_irq; 42c052d13cSHaojian Zhuang void __iomem *reg_status; 43c052d13cSHaojian Zhuang void __iomem *reg_mask; 44c052d13cSHaojian Zhuang unsigned int conf_enable; 45c052d13cSHaojian Zhuang unsigned int conf_disable; 46c052d13cSHaojian Zhuang unsigned int conf_mask; 47c052d13cSHaojian Zhuang unsigned int clr_mfp_irq_base; 48c052d13cSHaojian Zhuang unsigned int clr_mfp_hwirq; 49c052d13cSHaojian Zhuang struct irq_domain *domain; 50c052d13cSHaojian Zhuang }; 51c052d13cSHaojian Zhuang 52c052d13cSHaojian Zhuang struct mmp_intc_conf { 53c052d13cSHaojian Zhuang unsigned int conf_enable; 54c052d13cSHaojian Zhuang unsigned int conf_disable; 55c052d13cSHaojian Zhuang unsigned int conf_mask; 56c052d13cSHaojian Zhuang }; 57c052d13cSHaojian Zhuang 580f374561SHaojian Zhuang static void __iomem *mmp_icu_base; 59c052d13cSHaojian Zhuang static struct icu_chip_data icu_data[MAX_ICU_NR]; 60c052d13cSHaojian Zhuang static int max_icu_nr; 61c052d13cSHaojian Zhuang 62c052d13cSHaojian Zhuang extern void mmp2_clear_pmic_int(void); 63c052d13cSHaojian Zhuang 64c052d13cSHaojian Zhuang static void icu_mask_ack_irq(struct irq_data *d) 65c052d13cSHaojian Zhuang { 66c052d13cSHaojian Zhuang struct irq_domain *domain = d->domain; 67c052d13cSHaojian Zhuang struct icu_chip_data *data = (struct icu_chip_data *)domain->host_data; 68c052d13cSHaojian Zhuang int hwirq; 69c052d13cSHaojian Zhuang u32 r; 70c052d13cSHaojian Zhuang 71c052d13cSHaojian Zhuang hwirq = d->irq - data->virq_base; 72c052d13cSHaojian Zhuang if (data == &icu_data[0]) { 73c052d13cSHaojian Zhuang r = readl_relaxed(mmp_icu_base + (hwirq << 2)); 74c052d13cSHaojian Zhuang r &= ~data->conf_mask; 75c052d13cSHaojian Zhuang r |= data->conf_disable; 76c052d13cSHaojian Zhuang writel_relaxed(r, mmp_icu_base + (hwirq << 2)); 77c052d13cSHaojian Zhuang } else { 78c052d13cSHaojian Zhuang #ifdef CONFIG_CPU_MMP2 79c052d13cSHaojian Zhuang if ((data->virq_base == data->clr_mfp_irq_base) 80c052d13cSHaojian Zhuang && (hwirq == data->clr_mfp_hwirq)) 81c052d13cSHaojian Zhuang mmp2_clear_pmic_int(); 82c052d13cSHaojian Zhuang #endif 83c052d13cSHaojian Zhuang r = readl_relaxed(data->reg_mask) | (1 << hwirq); 84c052d13cSHaojian Zhuang writel_relaxed(r, data->reg_mask); 85c052d13cSHaojian Zhuang } 86c052d13cSHaojian Zhuang } 87c052d13cSHaojian Zhuang 88c052d13cSHaojian Zhuang static void icu_mask_irq(struct irq_data *d) 89c052d13cSHaojian Zhuang { 90c052d13cSHaojian Zhuang struct irq_domain *domain = d->domain; 91c052d13cSHaojian Zhuang struct icu_chip_data *data = (struct icu_chip_data *)domain->host_data; 92c052d13cSHaojian Zhuang int hwirq; 93c052d13cSHaojian Zhuang u32 r; 94c052d13cSHaojian Zhuang 95c052d13cSHaojian Zhuang hwirq = d->irq - data->virq_base; 96c052d13cSHaojian Zhuang if (data == &icu_data[0]) { 97c052d13cSHaojian Zhuang r = readl_relaxed(mmp_icu_base + (hwirq << 2)); 98c052d13cSHaojian Zhuang r &= ~data->conf_mask; 99c052d13cSHaojian Zhuang r |= data->conf_disable; 100c052d13cSHaojian Zhuang writel_relaxed(r, mmp_icu_base + (hwirq << 2)); 101c052d13cSHaojian Zhuang } else { 102c052d13cSHaojian Zhuang r = readl_relaxed(data->reg_mask) | (1 << hwirq); 103c052d13cSHaojian Zhuang writel_relaxed(r, data->reg_mask); 104c052d13cSHaojian Zhuang } 105c052d13cSHaojian Zhuang } 106c052d13cSHaojian Zhuang 107c052d13cSHaojian Zhuang static void icu_unmask_irq(struct irq_data *d) 108c052d13cSHaojian Zhuang { 109c052d13cSHaojian Zhuang struct irq_domain *domain = d->domain; 110c052d13cSHaojian Zhuang struct icu_chip_data *data = (struct icu_chip_data *)domain->host_data; 111c052d13cSHaojian Zhuang int hwirq; 112c052d13cSHaojian Zhuang u32 r; 113c052d13cSHaojian Zhuang 114c052d13cSHaojian Zhuang hwirq = d->irq - data->virq_base; 115c052d13cSHaojian Zhuang if (data == &icu_data[0]) { 116c052d13cSHaojian Zhuang r = readl_relaxed(mmp_icu_base + (hwirq << 2)); 117c052d13cSHaojian Zhuang r &= ~data->conf_mask; 118c052d13cSHaojian Zhuang r |= data->conf_enable; 119c052d13cSHaojian Zhuang writel_relaxed(r, mmp_icu_base + (hwirq << 2)); 120c052d13cSHaojian Zhuang } else { 121c052d13cSHaojian Zhuang r = readl_relaxed(data->reg_mask) & ~(1 << hwirq); 122c052d13cSHaojian Zhuang writel_relaxed(r, data->reg_mask); 123c052d13cSHaojian Zhuang } 124c052d13cSHaojian Zhuang } 125c052d13cSHaojian Zhuang 1260f102b6cSHaojian Zhuang struct irq_chip icu_irq_chip = { 127c052d13cSHaojian Zhuang .name = "icu_irq", 128c052d13cSHaojian Zhuang .irq_mask = icu_mask_irq, 129c052d13cSHaojian Zhuang .irq_mask_ack = icu_mask_ack_irq, 130c052d13cSHaojian Zhuang .irq_unmask = icu_unmask_irq, 131c052d13cSHaojian Zhuang }; 132c052d13cSHaojian Zhuang 133c052d13cSHaojian Zhuang static void icu_mux_irq_demux(unsigned int irq, struct irq_desc *desc) 134c052d13cSHaojian Zhuang { 135c052d13cSHaojian Zhuang struct irq_domain *domain; 136c052d13cSHaojian Zhuang struct icu_chip_data *data; 137c052d13cSHaojian Zhuang int i; 138c052d13cSHaojian Zhuang unsigned long mask, status, n; 139c052d13cSHaojian Zhuang 140c052d13cSHaojian Zhuang for (i = 1; i < max_icu_nr; i++) { 141c052d13cSHaojian Zhuang if (irq == icu_data[i].cascade_irq) { 142c052d13cSHaojian Zhuang domain = icu_data[i].domain; 143c052d13cSHaojian Zhuang data = (struct icu_chip_data *)domain->host_data; 144c052d13cSHaojian Zhuang break; 145c052d13cSHaojian Zhuang } 146c052d13cSHaojian Zhuang } 147c052d13cSHaojian Zhuang if (i >= max_icu_nr) { 148c052d13cSHaojian Zhuang pr_err("Spurious irq %d in MMP INTC\n", irq); 149c052d13cSHaojian Zhuang return; 150c052d13cSHaojian Zhuang } 151c052d13cSHaojian Zhuang 152c052d13cSHaojian Zhuang mask = readl_relaxed(data->reg_mask); 153c052d13cSHaojian Zhuang while (1) { 154c052d13cSHaojian Zhuang status = readl_relaxed(data->reg_status) & ~mask; 155c052d13cSHaojian Zhuang if (status == 0) 156c052d13cSHaojian Zhuang break; 157c052d13cSHaojian Zhuang for_each_set_bit(n, &status, BITS_PER_LONG) { 158c052d13cSHaojian Zhuang generic_handle_irq(icu_data[i].virq_base + n); 159c052d13cSHaojian Zhuang } 160c052d13cSHaojian Zhuang } 161c052d13cSHaojian Zhuang } 162c052d13cSHaojian Zhuang 163c052d13cSHaojian Zhuang static int mmp_irq_domain_map(struct irq_domain *d, unsigned int irq, 164c052d13cSHaojian Zhuang irq_hw_number_t hw) 165c052d13cSHaojian Zhuang { 166c052d13cSHaojian Zhuang irq_set_chip_and_handler(irq, &icu_irq_chip, handle_level_irq); 167c052d13cSHaojian Zhuang set_irq_flags(irq, IRQF_VALID); 168c052d13cSHaojian Zhuang return 0; 169c052d13cSHaojian Zhuang } 170c052d13cSHaojian Zhuang 171c052d13cSHaojian Zhuang static int mmp_irq_domain_xlate(struct irq_domain *d, struct device_node *node, 172c052d13cSHaojian Zhuang const u32 *intspec, unsigned int intsize, 173c052d13cSHaojian Zhuang unsigned long *out_hwirq, 174c052d13cSHaojian Zhuang unsigned int *out_type) 175c052d13cSHaojian Zhuang { 176c052d13cSHaojian Zhuang *out_hwirq = intspec[0]; 177c052d13cSHaojian Zhuang return 0; 178c052d13cSHaojian Zhuang } 179c052d13cSHaojian Zhuang 180c052d13cSHaojian Zhuang const struct irq_domain_ops mmp_irq_domain_ops = { 181c052d13cSHaojian Zhuang .map = mmp_irq_domain_map, 182c052d13cSHaojian Zhuang .xlate = mmp_irq_domain_xlate, 183c052d13cSHaojian Zhuang }; 184c052d13cSHaojian Zhuang 185c052d13cSHaojian Zhuang static struct mmp_intc_conf mmp_conf = { 186c052d13cSHaojian Zhuang .conf_enable = 0x51, 187c052d13cSHaojian Zhuang .conf_disable = 0x0, 188c052d13cSHaojian Zhuang .conf_mask = 0x7f, 189c052d13cSHaojian Zhuang }; 190c052d13cSHaojian Zhuang 191c052d13cSHaojian Zhuang static struct mmp_intc_conf mmp2_conf = { 192c052d13cSHaojian Zhuang .conf_enable = 0x20, 193c052d13cSHaojian Zhuang .conf_disable = 0x0, 194c052d13cSHaojian Zhuang .conf_mask = 0x7f, 195c052d13cSHaojian Zhuang }; 196c052d13cSHaojian Zhuang 197*8783dd3aSStephen Boyd static void __exception_irq_entry mmp_handle_irq(struct pt_regs *regs) 1980f374561SHaojian Zhuang { 1990f374561SHaojian Zhuang int irq, hwirq; 2000f374561SHaojian Zhuang 2010f374561SHaojian Zhuang hwirq = readl_relaxed(mmp_icu_base + PJ1_INT_SEL); 2020f374561SHaojian Zhuang if (!(hwirq & SEL_INT_PENDING)) 2030f374561SHaojian Zhuang return; 2040f374561SHaojian Zhuang hwirq &= SEL_INT_NUM_MASK; 2050f374561SHaojian Zhuang irq = irq_find_mapping(icu_data[0].domain, hwirq); 2060f374561SHaojian Zhuang handle_IRQ(irq, regs); 2070f374561SHaojian Zhuang } 2080f374561SHaojian Zhuang 209*8783dd3aSStephen Boyd static void __exception_irq_entry mmp2_handle_irq(struct pt_regs *regs) 2100f374561SHaojian Zhuang { 2110f374561SHaojian Zhuang int irq, hwirq; 2120f374561SHaojian Zhuang 2130f374561SHaojian Zhuang hwirq = readl_relaxed(mmp_icu_base + PJ4_INT_SEL); 2140f374561SHaojian Zhuang if (!(hwirq & SEL_INT_PENDING)) 2150f374561SHaojian Zhuang return; 2160f374561SHaojian Zhuang hwirq &= SEL_INT_NUM_MASK; 2170f374561SHaojian Zhuang irq = irq_find_mapping(icu_data[0].domain, hwirq); 2180f374561SHaojian Zhuang handle_IRQ(irq, regs); 2190f374561SHaojian Zhuang } 2200f374561SHaojian Zhuang 221c052d13cSHaojian Zhuang /* MMP (ARMv5) */ 222c052d13cSHaojian Zhuang void __init icu_init_irq(void) 223c052d13cSHaojian Zhuang { 224c052d13cSHaojian Zhuang int irq; 225c052d13cSHaojian Zhuang 226c052d13cSHaojian Zhuang max_icu_nr = 1; 227c052d13cSHaojian Zhuang mmp_icu_base = ioremap(0xd4282000, 0x1000); 228c052d13cSHaojian Zhuang icu_data[0].conf_enable = mmp_conf.conf_enable; 229c052d13cSHaojian Zhuang icu_data[0].conf_disable = mmp_conf.conf_disable; 230c052d13cSHaojian Zhuang icu_data[0].conf_mask = mmp_conf.conf_mask; 231c052d13cSHaojian Zhuang icu_data[0].nr_irqs = 64; 232c052d13cSHaojian Zhuang icu_data[0].virq_base = 0; 233c052d13cSHaojian Zhuang icu_data[0].domain = irq_domain_add_legacy(NULL, 64, 0, 0, 234c052d13cSHaojian Zhuang &irq_domain_simple_ops, 235c052d13cSHaojian Zhuang &icu_data[0]); 236c052d13cSHaojian Zhuang for (irq = 0; irq < 64; irq++) { 237c052d13cSHaojian Zhuang icu_mask_irq(irq_get_irq_data(irq)); 238c052d13cSHaojian Zhuang irq_set_chip_and_handler(irq, &icu_irq_chip, handle_level_irq); 239c052d13cSHaojian Zhuang set_irq_flags(irq, IRQF_VALID); 240c052d13cSHaojian Zhuang } 241c052d13cSHaojian Zhuang irq_set_default_host(icu_data[0].domain); 2420f374561SHaojian Zhuang set_handle_irq(mmp_handle_irq); 243c052d13cSHaojian Zhuang } 244c052d13cSHaojian Zhuang 245c052d13cSHaojian Zhuang /* MMP2 (ARMv7) */ 246c052d13cSHaojian Zhuang void __init mmp2_init_icu(void) 247c052d13cSHaojian Zhuang { 248942f4221SHaojian Zhuang int irq, end; 249c052d13cSHaojian Zhuang 250c052d13cSHaojian Zhuang max_icu_nr = 8; 251c052d13cSHaojian Zhuang mmp_icu_base = ioremap(0xd4282000, 0x1000); 252c052d13cSHaojian Zhuang icu_data[0].conf_enable = mmp2_conf.conf_enable; 253c052d13cSHaojian Zhuang icu_data[0].conf_disable = mmp2_conf.conf_disable; 254c052d13cSHaojian Zhuang icu_data[0].conf_mask = mmp2_conf.conf_mask; 255c052d13cSHaojian Zhuang icu_data[0].nr_irqs = 64; 256c052d13cSHaojian Zhuang icu_data[0].virq_base = 0; 257c052d13cSHaojian Zhuang icu_data[0].domain = irq_domain_add_legacy(NULL, 64, 0, 0, 258c052d13cSHaojian Zhuang &irq_domain_simple_ops, 259c052d13cSHaojian Zhuang &icu_data[0]); 260c052d13cSHaojian Zhuang icu_data[1].reg_status = mmp_icu_base + 0x150; 261c052d13cSHaojian Zhuang icu_data[1].reg_mask = mmp_icu_base + 0x168; 262942f4221SHaojian Zhuang icu_data[1].clr_mfp_irq_base = icu_data[0].virq_base + 263942f4221SHaojian Zhuang icu_data[0].nr_irqs; 264942f4221SHaojian Zhuang icu_data[1].clr_mfp_hwirq = 1; /* offset to IRQ_MMP2_PMIC_BASE */ 265c052d13cSHaojian Zhuang icu_data[1].nr_irqs = 2; 266c052d13cSHaojian Zhuang icu_data[1].cascade_irq = 4; 267942f4221SHaojian Zhuang icu_data[1].virq_base = icu_data[0].virq_base + icu_data[0].nr_irqs; 268c052d13cSHaojian Zhuang icu_data[1].domain = irq_domain_add_legacy(NULL, icu_data[1].nr_irqs, 269c052d13cSHaojian Zhuang icu_data[1].virq_base, 0, 270c052d13cSHaojian Zhuang &irq_domain_simple_ops, 271c052d13cSHaojian Zhuang &icu_data[1]); 272c052d13cSHaojian Zhuang icu_data[2].reg_status = mmp_icu_base + 0x154; 273c052d13cSHaojian Zhuang icu_data[2].reg_mask = mmp_icu_base + 0x16c; 274c052d13cSHaojian Zhuang icu_data[2].nr_irqs = 2; 275c052d13cSHaojian Zhuang icu_data[2].cascade_irq = 5; 276942f4221SHaojian Zhuang icu_data[2].virq_base = icu_data[1].virq_base + icu_data[1].nr_irqs; 277c052d13cSHaojian Zhuang icu_data[2].domain = irq_domain_add_legacy(NULL, icu_data[2].nr_irqs, 278c052d13cSHaojian Zhuang icu_data[2].virq_base, 0, 279c052d13cSHaojian Zhuang &irq_domain_simple_ops, 280c052d13cSHaojian Zhuang &icu_data[2]); 281c052d13cSHaojian Zhuang icu_data[3].reg_status = mmp_icu_base + 0x180; 282c052d13cSHaojian Zhuang icu_data[3].reg_mask = mmp_icu_base + 0x17c; 283c052d13cSHaojian Zhuang icu_data[3].nr_irqs = 3; 284c052d13cSHaojian Zhuang icu_data[3].cascade_irq = 9; 285942f4221SHaojian Zhuang icu_data[3].virq_base = icu_data[2].virq_base + icu_data[2].nr_irqs; 286c052d13cSHaojian Zhuang icu_data[3].domain = irq_domain_add_legacy(NULL, icu_data[3].nr_irqs, 287c052d13cSHaojian Zhuang icu_data[3].virq_base, 0, 288c052d13cSHaojian Zhuang &irq_domain_simple_ops, 289c052d13cSHaojian Zhuang &icu_data[3]); 290c052d13cSHaojian Zhuang icu_data[4].reg_status = mmp_icu_base + 0x158; 291c052d13cSHaojian Zhuang icu_data[4].reg_mask = mmp_icu_base + 0x170; 292c052d13cSHaojian Zhuang icu_data[4].nr_irqs = 5; 293c052d13cSHaojian Zhuang icu_data[4].cascade_irq = 17; 294942f4221SHaojian Zhuang icu_data[4].virq_base = icu_data[3].virq_base + icu_data[3].nr_irqs; 295c052d13cSHaojian Zhuang icu_data[4].domain = irq_domain_add_legacy(NULL, icu_data[4].nr_irqs, 296c052d13cSHaojian Zhuang icu_data[4].virq_base, 0, 297c052d13cSHaojian Zhuang &irq_domain_simple_ops, 298c052d13cSHaojian Zhuang &icu_data[4]); 299c052d13cSHaojian Zhuang icu_data[5].reg_status = mmp_icu_base + 0x15c; 300c052d13cSHaojian Zhuang icu_data[5].reg_mask = mmp_icu_base + 0x174; 301c052d13cSHaojian Zhuang icu_data[5].nr_irqs = 15; 302c052d13cSHaojian Zhuang icu_data[5].cascade_irq = 35; 303942f4221SHaojian Zhuang icu_data[5].virq_base = icu_data[4].virq_base + icu_data[4].nr_irqs; 304c052d13cSHaojian Zhuang icu_data[5].domain = irq_domain_add_legacy(NULL, icu_data[5].nr_irqs, 305c052d13cSHaojian Zhuang icu_data[5].virq_base, 0, 306c052d13cSHaojian Zhuang &irq_domain_simple_ops, 307c052d13cSHaojian Zhuang &icu_data[5]); 308c052d13cSHaojian Zhuang icu_data[6].reg_status = mmp_icu_base + 0x160; 309c052d13cSHaojian Zhuang icu_data[6].reg_mask = mmp_icu_base + 0x178; 310c052d13cSHaojian Zhuang icu_data[6].nr_irqs = 2; 311c052d13cSHaojian Zhuang icu_data[6].cascade_irq = 51; 312942f4221SHaojian Zhuang icu_data[6].virq_base = icu_data[5].virq_base + icu_data[5].nr_irqs; 313c052d13cSHaojian Zhuang icu_data[6].domain = irq_domain_add_legacy(NULL, icu_data[6].nr_irqs, 314c052d13cSHaojian Zhuang icu_data[6].virq_base, 0, 315c052d13cSHaojian Zhuang &irq_domain_simple_ops, 316c052d13cSHaojian Zhuang &icu_data[6]); 317c052d13cSHaojian Zhuang icu_data[7].reg_status = mmp_icu_base + 0x188; 318c052d13cSHaojian Zhuang icu_data[7].reg_mask = mmp_icu_base + 0x184; 319c052d13cSHaojian Zhuang icu_data[7].nr_irqs = 2; 320c052d13cSHaojian Zhuang icu_data[7].cascade_irq = 55; 321942f4221SHaojian Zhuang icu_data[7].virq_base = icu_data[6].virq_base + icu_data[6].nr_irqs; 322c052d13cSHaojian Zhuang icu_data[7].domain = irq_domain_add_legacy(NULL, icu_data[7].nr_irqs, 323c052d13cSHaojian Zhuang icu_data[7].virq_base, 0, 324c052d13cSHaojian Zhuang &irq_domain_simple_ops, 325c052d13cSHaojian Zhuang &icu_data[7]); 326942f4221SHaojian Zhuang end = icu_data[7].virq_base + icu_data[7].nr_irqs; 327942f4221SHaojian Zhuang for (irq = 0; irq < end; irq++) { 328c052d13cSHaojian Zhuang icu_mask_irq(irq_get_irq_data(irq)); 329942f4221SHaojian Zhuang if (irq == icu_data[1].cascade_irq || 330942f4221SHaojian Zhuang irq == icu_data[2].cascade_irq || 331942f4221SHaojian Zhuang irq == icu_data[3].cascade_irq || 332942f4221SHaojian Zhuang irq == icu_data[4].cascade_irq || 333942f4221SHaojian Zhuang irq == icu_data[5].cascade_irq || 334942f4221SHaojian Zhuang irq == icu_data[6].cascade_irq || 335942f4221SHaojian Zhuang irq == icu_data[7].cascade_irq) { 336c052d13cSHaojian Zhuang irq_set_chip(irq, &icu_irq_chip); 337c052d13cSHaojian Zhuang irq_set_chained_handler(irq, icu_mux_irq_demux); 338942f4221SHaojian Zhuang } else { 339c052d13cSHaojian Zhuang irq_set_chip_and_handler(irq, &icu_irq_chip, 340c052d13cSHaojian Zhuang handle_level_irq); 341c052d13cSHaojian Zhuang } 342c052d13cSHaojian Zhuang set_irq_flags(irq, IRQF_VALID); 343c052d13cSHaojian Zhuang } 344c052d13cSHaojian Zhuang irq_set_default_host(icu_data[0].domain); 3450f374561SHaojian Zhuang set_handle_irq(mmp2_handle_irq); 346c052d13cSHaojian Zhuang } 347c052d13cSHaojian Zhuang 348c052d13cSHaojian Zhuang #ifdef CONFIG_OF 3490f374561SHaojian Zhuang static int __init mmp_init_bases(struct device_node *node) 350c052d13cSHaojian Zhuang { 3510f374561SHaojian Zhuang int ret, nr_irqs, irq, i = 0; 352c052d13cSHaojian Zhuang 353c052d13cSHaojian Zhuang ret = of_property_read_u32(node, "mrvl,intc-nr-irqs", &nr_irqs); 354c052d13cSHaojian Zhuang if (ret) { 355c052d13cSHaojian Zhuang pr_err("Not found mrvl,intc-nr-irqs property\n"); 3560f374561SHaojian Zhuang return ret; 357c052d13cSHaojian Zhuang } 358c052d13cSHaojian Zhuang 359c052d13cSHaojian Zhuang mmp_icu_base = of_iomap(node, 0); 360c052d13cSHaojian Zhuang if (!mmp_icu_base) { 361c052d13cSHaojian Zhuang pr_err("Failed to get interrupt controller register\n"); 3620f374561SHaojian Zhuang return -ENOMEM; 363c052d13cSHaojian Zhuang } 364c052d13cSHaojian Zhuang 365c052d13cSHaojian Zhuang icu_data[0].virq_base = 0; 3660f374561SHaojian Zhuang icu_data[0].domain = irq_domain_add_linear(node, nr_irqs, 367c052d13cSHaojian Zhuang &mmp_irq_domain_ops, 368c052d13cSHaojian Zhuang &icu_data[0]); 3690f374561SHaojian Zhuang for (irq = 0; irq < nr_irqs; irq++) { 3700f374561SHaojian Zhuang ret = irq_create_mapping(icu_data[0].domain, irq); 3710f374561SHaojian Zhuang if (!ret) { 3720f374561SHaojian Zhuang pr_err("Failed to mapping hwirq\n"); 3730f374561SHaojian Zhuang goto err; 374c052d13cSHaojian Zhuang } 3750f374561SHaojian Zhuang if (!irq) 3760f374561SHaojian Zhuang icu_data[0].virq_base = ret; 3770f374561SHaojian Zhuang } 3780f374561SHaojian Zhuang icu_data[0].nr_irqs = nr_irqs; 3790f374561SHaojian Zhuang return 0; 3800f374561SHaojian Zhuang err: 3810f374561SHaojian Zhuang if (icu_data[0].virq_base) { 3820f374561SHaojian Zhuang for (i = 0; i < irq; i++) 3830f374561SHaojian Zhuang irq_dispose_mapping(icu_data[0].virq_base + i); 3840f374561SHaojian Zhuang } 3850f374561SHaojian Zhuang irq_domain_remove(icu_data[0].domain); 3860f374561SHaojian Zhuang iounmap(mmp_icu_base); 3870f374561SHaojian Zhuang return -EINVAL; 3880f374561SHaojian Zhuang } 3890f374561SHaojian Zhuang 3900f374561SHaojian Zhuang static int __init mmp_of_init(struct device_node *node, 3910f374561SHaojian Zhuang struct device_node *parent) 3920f374561SHaojian Zhuang { 3930f374561SHaojian Zhuang int ret; 3940f374561SHaojian Zhuang 3950f374561SHaojian Zhuang ret = mmp_init_bases(node); 3960f374561SHaojian Zhuang if (ret < 0) 3970f374561SHaojian Zhuang return ret; 3980f374561SHaojian Zhuang 3990f374561SHaojian Zhuang icu_data[0].conf_enable = mmp_conf.conf_enable; 4000f374561SHaojian Zhuang icu_data[0].conf_disable = mmp_conf.conf_disable; 4010f374561SHaojian Zhuang icu_data[0].conf_mask = mmp_conf.conf_mask; 4020f374561SHaojian Zhuang irq_set_default_host(icu_data[0].domain); 4030f374561SHaojian Zhuang set_handle_irq(mmp_handle_irq); 4040f374561SHaojian Zhuang max_icu_nr = 1; 4050f374561SHaojian Zhuang return 0; 4060f374561SHaojian Zhuang } 4070f374561SHaojian Zhuang IRQCHIP_DECLARE(mmp_intc, "mrvl,mmp-intc", mmp_of_init); 4080f374561SHaojian Zhuang 4090f374561SHaojian Zhuang static int __init mmp2_of_init(struct device_node *node, 4100f374561SHaojian Zhuang struct device_node *parent) 4110f374561SHaojian Zhuang { 4120f374561SHaojian Zhuang int ret; 4130f374561SHaojian Zhuang 4140f374561SHaojian Zhuang ret = mmp_init_bases(node); 4150f374561SHaojian Zhuang if (ret < 0) 4160f374561SHaojian Zhuang return ret; 4170f374561SHaojian Zhuang 4180f374561SHaojian Zhuang icu_data[0].conf_enable = mmp2_conf.conf_enable; 4190f374561SHaojian Zhuang icu_data[0].conf_disable = mmp2_conf.conf_disable; 4200f374561SHaojian Zhuang icu_data[0].conf_mask = mmp2_conf.conf_mask; 4210f374561SHaojian Zhuang irq_set_default_host(icu_data[0].domain); 4220f374561SHaojian Zhuang set_handle_irq(mmp2_handle_irq); 4230f374561SHaojian Zhuang max_icu_nr = 1; 4240f374561SHaojian Zhuang return 0; 4250f374561SHaojian Zhuang } 4260f374561SHaojian Zhuang IRQCHIP_DECLARE(mmp2_intc, "mrvl,mmp2-intc", mmp2_of_init); 4270f374561SHaojian Zhuang 4280f374561SHaojian Zhuang static int __init mmp2_mux_of_init(struct device_node *node, 4290f374561SHaojian Zhuang struct device_node *parent) 4300f374561SHaojian Zhuang { 4310f374561SHaojian Zhuang struct resource res; 4320f374561SHaojian Zhuang int i, ret, irq, j = 0; 4330f374561SHaojian Zhuang u32 nr_irqs, mfp_irq; 4340f374561SHaojian Zhuang 4350f374561SHaojian Zhuang if (!parent) 4360f374561SHaojian Zhuang return -ENODEV; 4370f374561SHaojian Zhuang 4380f374561SHaojian Zhuang i = max_icu_nr; 4390f374561SHaojian Zhuang ret = of_property_read_u32(node, "mrvl,intc-nr-irqs", 4400f374561SHaojian Zhuang &nr_irqs); 4410f374561SHaojian Zhuang if (ret) { 4420f374561SHaojian Zhuang pr_err("Not found mrvl,intc-nr-irqs property\n"); 4430f374561SHaojian Zhuang return -EINVAL; 4440f374561SHaojian Zhuang } 4450f374561SHaojian Zhuang ret = of_address_to_resource(node, 0, &res); 4460f374561SHaojian Zhuang if (ret < 0) { 4470f374561SHaojian Zhuang pr_err("Not found reg property\n"); 4480f374561SHaojian Zhuang return -EINVAL; 4490f374561SHaojian Zhuang } 4500f374561SHaojian Zhuang icu_data[i].reg_status = mmp_icu_base + res.start; 4510f374561SHaojian Zhuang ret = of_address_to_resource(node, 1, &res); 4520f374561SHaojian Zhuang if (ret < 0) { 4530f374561SHaojian Zhuang pr_err("Not found reg property\n"); 4540f374561SHaojian Zhuang return -EINVAL; 4550f374561SHaojian Zhuang } 4560f374561SHaojian Zhuang icu_data[i].reg_mask = mmp_icu_base + res.start; 4570f374561SHaojian Zhuang icu_data[i].cascade_irq = irq_of_parse_and_map(node, 0); 4580f374561SHaojian Zhuang if (!icu_data[i].cascade_irq) 4590f374561SHaojian Zhuang return -EINVAL; 4600f374561SHaojian Zhuang 4610f374561SHaojian Zhuang icu_data[i].virq_base = 0; 4620f374561SHaojian Zhuang icu_data[i].domain = irq_domain_add_linear(node, nr_irqs, 4630f374561SHaojian Zhuang &mmp_irq_domain_ops, 4640f374561SHaojian Zhuang &icu_data[i]); 4650f374561SHaojian Zhuang for (irq = 0; irq < nr_irqs; irq++) { 4660f374561SHaojian Zhuang ret = irq_create_mapping(icu_data[i].domain, irq); 4670f374561SHaojian Zhuang if (!ret) { 4680f374561SHaojian Zhuang pr_err("Failed to mapping hwirq\n"); 4690f374561SHaojian Zhuang goto err; 4700f374561SHaojian Zhuang } 4710f374561SHaojian Zhuang if (!irq) 4720f374561SHaojian Zhuang icu_data[i].virq_base = ret; 4730f374561SHaojian Zhuang } 4740f374561SHaojian Zhuang icu_data[i].nr_irqs = nr_irqs; 4750f374561SHaojian Zhuang if (!of_property_read_u32(node, "mrvl,clr-mfp-irq", 4760f374561SHaojian Zhuang &mfp_irq)) { 4770f374561SHaojian Zhuang icu_data[i].clr_mfp_irq_base = icu_data[i].virq_base; 4780f374561SHaojian Zhuang icu_data[i].clr_mfp_hwirq = mfp_irq; 4790f374561SHaojian Zhuang } 4800f374561SHaojian Zhuang irq_set_chained_handler(icu_data[i].cascade_irq, 4810f374561SHaojian Zhuang icu_mux_irq_demux); 4820f374561SHaojian Zhuang max_icu_nr++; 4830f374561SHaojian Zhuang return 0; 4840f374561SHaojian Zhuang err: 4850f374561SHaojian Zhuang if (icu_data[i].virq_base) { 4860f374561SHaojian Zhuang for (j = 0; j < irq; j++) 4870f374561SHaojian Zhuang irq_dispose_mapping(icu_data[i].virq_base + j); 4880f374561SHaojian Zhuang } 4890f374561SHaojian Zhuang irq_domain_remove(icu_data[i].domain); 4900f374561SHaojian Zhuang return -EINVAL; 4910f374561SHaojian Zhuang } 4920f374561SHaojian Zhuang IRQCHIP_DECLARE(mmp2_mux_intc, "mrvl,mmp2-mux-intc", mmp2_mux_of_init); 493c052d13cSHaojian Zhuang #endif 494