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> 25*13dde818SNeil Zhang #include <asm/hardirq.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 1970f374561SHaojian Zhuang static asmlinkage void __exception_irq_entry 1980f374561SHaojian Zhuang mmp_handle_irq(struct pt_regs *regs) 1990f374561SHaojian Zhuang { 2000f374561SHaojian Zhuang int irq, hwirq; 2010f374561SHaojian Zhuang 2020f374561SHaojian Zhuang hwirq = readl_relaxed(mmp_icu_base + PJ1_INT_SEL); 2030f374561SHaojian Zhuang if (!(hwirq & SEL_INT_PENDING)) 2040f374561SHaojian Zhuang return; 2050f374561SHaojian Zhuang hwirq &= SEL_INT_NUM_MASK; 2060f374561SHaojian Zhuang irq = irq_find_mapping(icu_data[0].domain, hwirq); 2070f374561SHaojian Zhuang handle_IRQ(irq, regs); 2080f374561SHaojian Zhuang } 2090f374561SHaojian Zhuang 2100f374561SHaojian Zhuang static asmlinkage void __exception_irq_entry 2110f374561SHaojian Zhuang mmp2_handle_irq(struct pt_regs *regs) 2120f374561SHaojian Zhuang { 2130f374561SHaojian Zhuang int irq, hwirq; 2140f374561SHaojian Zhuang 2150f374561SHaojian Zhuang hwirq = readl_relaxed(mmp_icu_base + PJ4_INT_SEL); 2160f374561SHaojian Zhuang if (!(hwirq & SEL_INT_PENDING)) 2170f374561SHaojian Zhuang return; 2180f374561SHaojian Zhuang hwirq &= SEL_INT_NUM_MASK; 2190f374561SHaojian Zhuang irq = irq_find_mapping(icu_data[0].domain, hwirq); 2200f374561SHaojian Zhuang handle_IRQ(irq, regs); 2210f374561SHaojian Zhuang } 2220f374561SHaojian Zhuang 223c052d13cSHaojian Zhuang /* MMP (ARMv5) */ 224c052d13cSHaojian Zhuang void __init icu_init_irq(void) 225c052d13cSHaojian Zhuang { 226c052d13cSHaojian Zhuang int irq; 227c052d13cSHaojian Zhuang 228c052d13cSHaojian Zhuang max_icu_nr = 1; 229c052d13cSHaojian Zhuang mmp_icu_base = ioremap(0xd4282000, 0x1000); 230c052d13cSHaojian Zhuang icu_data[0].conf_enable = mmp_conf.conf_enable; 231c052d13cSHaojian Zhuang icu_data[0].conf_disable = mmp_conf.conf_disable; 232c052d13cSHaojian Zhuang icu_data[0].conf_mask = mmp_conf.conf_mask; 233c052d13cSHaojian Zhuang icu_data[0].nr_irqs = 64; 234c052d13cSHaojian Zhuang icu_data[0].virq_base = 0; 235c052d13cSHaojian Zhuang icu_data[0].domain = irq_domain_add_legacy(NULL, 64, 0, 0, 236c052d13cSHaojian Zhuang &irq_domain_simple_ops, 237c052d13cSHaojian Zhuang &icu_data[0]); 238c052d13cSHaojian Zhuang for (irq = 0; irq < 64; irq++) { 239c052d13cSHaojian Zhuang icu_mask_irq(irq_get_irq_data(irq)); 240c052d13cSHaojian Zhuang irq_set_chip_and_handler(irq, &icu_irq_chip, handle_level_irq); 241c052d13cSHaojian Zhuang set_irq_flags(irq, IRQF_VALID); 242c052d13cSHaojian Zhuang } 243c052d13cSHaojian Zhuang irq_set_default_host(icu_data[0].domain); 2440f374561SHaojian Zhuang set_handle_irq(mmp_handle_irq); 245c052d13cSHaojian Zhuang } 246c052d13cSHaojian Zhuang 247c052d13cSHaojian Zhuang /* MMP2 (ARMv7) */ 248c052d13cSHaojian Zhuang void __init mmp2_init_icu(void) 249c052d13cSHaojian Zhuang { 250942f4221SHaojian Zhuang int irq, end; 251c052d13cSHaojian Zhuang 252c052d13cSHaojian Zhuang max_icu_nr = 8; 253c052d13cSHaojian Zhuang mmp_icu_base = ioremap(0xd4282000, 0x1000); 254c052d13cSHaojian Zhuang icu_data[0].conf_enable = mmp2_conf.conf_enable; 255c052d13cSHaojian Zhuang icu_data[0].conf_disable = mmp2_conf.conf_disable; 256c052d13cSHaojian Zhuang icu_data[0].conf_mask = mmp2_conf.conf_mask; 257c052d13cSHaojian Zhuang icu_data[0].nr_irqs = 64; 258c052d13cSHaojian Zhuang icu_data[0].virq_base = 0; 259c052d13cSHaojian Zhuang icu_data[0].domain = irq_domain_add_legacy(NULL, 64, 0, 0, 260c052d13cSHaojian Zhuang &irq_domain_simple_ops, 261c052d13cSHaojian Zhuang &icu_data[0]); 262c052d13cSHaojian Zhuang icu_data[1].reg_status = mmp_icu_base + 0x150; 263c052d13cSHaojian Zhuang icu_data[1].reg_mask = mmp_icu_base + 0x168; 264942f4221SHaojian Zhuang icu_data[1].clr_mfp_irq_base = icu_data[0].virq_base + 265942f4221SHaojian Zhuang icu_data[0].nr_irqs; 266942f4221SHaojian Zhuang icu_data[1].clr_mfp_hwirq = 1; /* offset to IRQ_MMP2_PMIC_BASE */ 267c052d13cSHaojian Zhuang icu_data[1].nr_irqs = 2; 268c052d13cSHaojian Zhuang icu_data[1].cascade_irq = 4; 269942f4221SHaojian Zhuang icu_data[1].virq_base = icu_data[0].virq_base + icu_data[0].nr_irqs; 270c052d13cSHaojian Zhuang icu_data[1].domain = irq_domain_add_legacy(NULL, icu_data[1].nr_irqs, 271c052d13cSHaojian Zhuang icu_data[1].virq_base, 0, 272c052d13cSHaojian Zhuang &irq_domain_simple_ops, 273c052d13cSHaojian Zhuang &icu_data[1]); 274c052d13cSHaojian Zhuang icu_data[2].reg_status = mmp_icu_base + 0x154; 275c052d13cSHaojian Zhuang icu_data[2].reg_mask = mmp_icu_base + 0x16c; 276c052d13cSHaojian Zhuang icu_data[2].nr_irqs = 2; 277c052d13cSHaojian Zhuang icu_data[2].cascade_irq = 5; 278942f4221SHaojian Zhuang icu_data[2].virq_base = icu_data[1].virq_base + icu_data[1].nr_irqs; 279c052d13cSHaojian Zhuang icu_data[2].domain = irq_domain_add_legacy(NULL, icu_data[2].nr_irqs, 280c052d13cSHaojian Zhuang icu_data[2].virq_base, 0, 281c052d13cSHaojian Zhuang &irq_domain_simple_ops, 282c052d13cSHaojian Zhuang &icu_data[2]); 283c052d13cSHaojian Zhuang icu_data[3].reg_status = mmp_icu_base + 0x180; 284c052d13cSHaojian Zhuang icu_data[3].reg_mask = mmp_icu_base + 0x17c; 285c052d13cSHaojian Zhuang icu_data[3].nr_irqs = 3; 286c052d13cSHaojian Zhuang icu_data[3].cascade_irq = 9; 287942f4221SHaojian Zhuang icu_data[3].virq_base = icu_data[2].virq_base + icu_data[2].nr_irqs; 288c052d13cSHaojian Zhuang icu_data[3].domain = irq_domain_add_legacy(NULL, icu_data[3].nr_irqs, 289c052d13cSHaojian Zhuang icu_data[3].virq_base, 0, 290c052d13cSHaojian Zhuang &irq_domain_simple_ops, 291c052d13cSHaojian Zhuang &icu_data[3]); 292c052d13cSHaojian Zhuang icu_data[4].reg_status = mmp_icu_base + 0x158; 293c052d13cSHaojian Zhuang icu_data[4].reg_mask = mmp_icu_base + 0x170; 294c052d13cSHaojian Zhuang icu_data[4].nr_irqs = 5; 295c052d13cSHaojian Zhuang icu_data[4].cascade_irq = 17; 296942f4221SHaojian Zhuang icu_data[4].virq_base = icu_data[3].virq_base + icu_data[3].nr_irqs; 297c052d13cSHaojian Zhuang icu_data[4].domain = irq_domain_add_legacy(NULL, icu_data[4].nr_irqs, 298c052d13cSHaojian Zhuang icu_data[4].virq_base, 0, 299c052d13cSHaojian Zhuang &irq_domain_simple_ops, 300c052d13cSHaojian Zhuang &icu_data[4]); 301c052d13cSHaojian Zhuang icu_data[5].reg_status = mmp_icu_base + 0x15c; 302c052d13cSHaojian Zhuang icu_data[5].reg_mask = mmp_icu_base + 0x174; 303c052d13cSHaojian Zhuang icu_data[5].nr_irqs = 15; 304c052d13cSHaojian Zhuang icu_data[5].cascade_irq = 35; 305942f4221SHaojian Zhuang icu_data[5].virq_base = icu_data[4].virq_base + icu_data[4].nr_irqs; 306c052d13cSHaojian Zhuang icu_data[5].domain = irq_domain_add_legacy(NULL, icu_data[5].nr_irqs, 307c052d13cSHaojian Zhuang icu_data[5].virq_base, 0, 308c052d13cSHaojian Zhuang &irq_domain_simple_ops, 309c052d13cSHaojian Zhuang &icu_data[5]); 310c052d13cSHaojian Zhuang icu_data[6].reg_status = mmp_icu_base + 0x160; 311c052d13cSHaojian Zhuang icu_data[6].reg_mask = mmp_icu_base + 0x178; 312c052d13cSHaojian Zhuang icu_data[6].nr_irqs = 2; 313c052d13cSHaojian Zhuang icu_data[6].cascade_irq = 51; 314942f4221SHaojian Zhuang icu_data[6].virq_base = icu_data[5].virq_base + icu_data[5].nr_irqs; 315c052d13cSHaojian Zhuang icu_data[6].domain = irq_domain_add_legacy(NULL, icu_data[6].nr_irqs, 316c052d13cSHaojian Zhuang icu_data[6].virq_base, 0, 317c052d13cSHaojian Zhuang &irq_domain_simple_ops, 318c052d13cSHaojian Zhuang &icu_data[6]); 319c052d13cSHaojian Zhuang icu_data[7].reg_status = mmp_icu_base + 0x188; 320c052d13cSHaojian Zhuang icu_data[7].reg_mask = mmp_icu_base + 0x184; 321c052d13cSHaojian Zhuang icu_data[7].nr_irqs = 2; 322c052d13cSHaojian Zhuang icu_data[7].cascade_irq = 55; 323942f4221SHaojian Zhuang icu_data[7].virq_base = icu_data[6].virq_base + icu_data[6].nr_irqs; 324c052d13cSHaojian Zhuang icu_data[7].domain = irq_domain_add_legacy(NULL, icu_data[7].nr_irqs, 325c052d13cSHaojian Zhuang icu_data[7].virq_base, 0, 326c052d13cSHaojian Zhuang &irq_domain_simple_ops, 327c052d13cSHaojian Zhuang &icu_data[7]); 328942f4221SHaojian Zhuang end = icu_data[7].virq_base + icu_data[7].nr_irqs; 329942f4221SHaojian Zhuang for (irq = 0; irq < end; irq++) { 330c052d13cSHaojian Zhuang icu_mask_irq(irq_get_irq_data(irq)); 331942f4221SHaojian Zhuang if (irq == icu_data[1].cascade_irq || 332942f4221SHaojian Zhuang irq == icu_data[2].cascade_irq || 333942f4221SHaojian Zhuang irq == icu_data[3].cascade_irq || 334942f4221SHaojian Zhuang irq == icu_data[4].cascade_irq || 335942f4221SHaojian Zhuang irq == icu_data[5].cascade_irq || 336942f4221SHaojian Zhuang irq == icu_data[6].cascade_irq || 337942f4221SHaojian Zhuang irq == icu_data[7].cascade_irq) { 338c052d13cSHaojian Zhuang irq_set_chip(irq, &icu_irq_chip); 339c052d13cSHaojian Zhuang irq_set_chained_handler(irq, icu_mux_irq_demux); 340942f4221SHaojian Zhuang } else { 341c052d13cSHaojian Zhuang irq_set_chip_and_handler(irq, &icu_irq_chip, 342c052d13cSHaojian Zhuang handle_level_irq); 343c052d13cSHaojian Zhuang } 344c052d13cSHaojian Zhuang set_irq_flags(irq, IRQF_VALID); 345c052d13cSHaojian Zhuang } 346c052d13cSHaojian Zhuang irq_set_default_host(icu_data[0].domain); 3470f374561SHaojian Zhuang set_handle_irq(mmp2_handle_irq); 348c052d13cSHaojian Zhuang } 349c052d13cSHaojian Zhuang 350c052d13cSHaojian Zhuang #ifdef CONFIG_OF 3510f374561SHaojian Zhuang static int __init mmp_init_bases(struct device_node *node) 352c052d13cSHaojian Zhuang { 3530f374561SHaojian Zhuang int ret, nr_irqs, irq, i = 0; 354c052d13cSHaojian Zhuang 355c052d13cSHaojian Zhuang ret = of_property_read_u32(node, "mrvl,intc-nr-irqs", &nr_irqs); 356c052d13cSHaojian Zhuang if (ret) { 357c052d13cSHaojian Zhuang pr_err("Not found mrvl,intc-nr-irqs property\n"); 3580f374561SHaojian Zhuang return ret; 359c052d13cSHaojian Zhuang } 360c052d13cSHaojian Zhuang 361c052d13cSHaojian Zhuang mmp_icu_base = of_iomap(node, 0); 362c052d13cSHaojian Zhuang if (!mmp_icu_base) { 363c052d13cSHaojian Zhuang pr_err("Failed to get interrupt controller register\n"); 3640f374561SHaojian Zhuang return -ENOMEM; 365c052d13cSHaojian Zhuang } 366c052d13cSHaojian Zhuang 367c052d13cSHaojian Zhuang icu_data[0].virq_base = 0; 3680f374561SHaojian Zhuang icu_data[0].domain = irq_domain_add_linear(node, nr_irqs, 369c052d13cSHaojian Zhuang &mmp_irq_domain_ops, 370c052d13cSHaojian Zhuang &icu_data[0]); 3710f374561SHaojian Zhuang for (irq = 0; irq < nr_irqs; irq++) { 3720f374561SHaojian Zhuang ret = irq_create_mapping(icu_data[0].domain, irq); 3730f374561SHaojian Zhuang if (!ret) { 3740f374561SHaojian Zhuang pr_err("Failed to mapping hwirq\n"); 3750f374561SHaojian Zhuang goto err; 376c052d13cSHaojian Zhuang } 3770f374561SHaojian Zhuang if (!irq) 3780f374561SHaojian Zhuang icu_data[0].virq_base = ret; 3790f374561SHaojian Zhuang } 3800f374561SHaojian Zhuang icu_data[0].nr_irqs = nr_irqs; 3810f374561SHaojian Zhuang return 0; 3820f374561SHaojian Zhuang err: 3830f374561SHaojian Zhuang if (icu_data[0].virq_base) { 3840f374561SHaojian Zhuang for (i = 0; i < irq; i++) 3850f374561SHaojian Zhuang irq_dispose_mapping(icu_data[0].virq_base + i); 3860f374561SHaojian Zhuang } 3870f374561SHaojian Zhuang irq_domain_remove(icu_data[0].domain); 3880f374561SHaojian Zhuang iounmap(mmp_icu_base); 3890f374561SHaojian Zhuang return -EINVAL; 3900f374561SHaojian Zhuang } 3910f374561SHaojian Zhuang 3920f374561SHaojian Zhuang static int __init mmp_of_init(struct device_node *node, 3930f374561SHaojian Zhuang struct device_node *parent) 3940f374561SHaojian Zhuang { 3950f374561SHaojian Zhuang int ret; 3960f374561SHaojian Zhuang 3970f374561SHaojian Zhuang ret = mmp_init_bases(node); 3980f374561SHaojian Zhuang if (ret < 0) 3990f374561SHaojian Zhuang return ret; 4000f374561SHaojian Zhuang 4010f374561SHaojian Zhuang icu_data[0].conf_enable = mmp_conf.conf_enable; 4020f374561SHaojian Zhuang icu_data[0].conf_disable = mmp_conf.conf_disable; 4030f374561SHaojian Zhuang icu_data[0].conf_mask = mmp_conf.conf_mask; 4040f374561SHaojian Zhuang irq_set_default_host(icu_data[0].domain); 4050f374561SHaojian Zhuang set_handle_irq(mmp_handle_irq); 4060f374561SHaojian Zhuang max_icu_nr = 1; 4070f374561SHaojian Zhuang return 0; 4080f374561SHaojian Zhuang } 4090f374561SHaojian Zhuang IRQCHIP_DECLARE(mmp_intc, "mrvl,mmp-intc", mmp_of_init); 4100f374561SHaojian Zhuang 4110f374561SHaojian Zhuang static int __init mmp2_of_init(struct device_node *node, 4120f374561SHaojian Zhuang struct device_node *parent) 4130f374561SHaojian Zhuang { 4140f374561SHaojian Zhuang int ret; 4150f374561SHaojian Zhuang 4160f374561SHaojian Zhuang ret = mmp_init_bases(node); 4170f374561SHaojian Zhuang if (ret < 0) 4180f374561SHaojian Zhuang return ret; 4190f374561SHaojian Zhuang 4200f374561SHaojian Zhuang icu_data[0].conf_enable = mmp2_conf.conf_enable; 4210f374561SHaojian Zhuang icu_data[0].conf_disable = mmp2_conf.conf_disable; 4220f374561SHaojian Zhuang icu_data[0].conf_mask = mmp2_conf.conf_mask; 4230f374561SHaojian Zhuang irq_set_default_host(icu_data[0].domain); 4240f374561SHaojian Zhuang set_handle_irq(mmp2_handle_irq); 4250f374561SHaojian Zhuang max_icu_nr = 1; 4260f374561SHaojian Zhuang return 0; 4270f374561SHaojian Zhuang } 4280f374561SHaojian Zhuang IRQCHIP_DECLARE(mmp2_intc, "mrvl,mmp2-intc", mmp2_of_init); 4290f374561SHaojian Zhuang 4300f374561SHaojian Zhuang static int __init mmp2_mux_of_init(struct device_node *node, 4310f374561SHaojian Zhuang struct device_node *parent) 4320f374561SHaojian Zhuang { 4330f374561SHaojian Zhuang struct resource res; 4340f374561SHaojian Zhuang int i, ret, irq, j = 0; 4350f374561SHaojian Zhuang u32 nr_irqs, mfp_irq; 4360f374561SHaojian Zhuang 4370f374561SHaojian Zhuang if (!parent) 4380f374561SHaojian Zhuang return -ENODEV; 4390f374561SHaojian Zhuang 4400f374561SHaojian Zhuang i = max_icu_nr; 4410f374561SHaojian Zhuang ret = of_property_read_u32(node, "mrvl,intc-nr-irqs", 4420f374561SHaojian Zhuang &nr_irqs); 4430f374561SHaojian Zhuang if (ret) { 4440f374561SHaojian Zhuang pr_err("Not found mrvl,intc-nr-irqs property\n"); 4450f374561SHaojian Zhuang return -EINVAL; 4460f374561SHaojian Zhuang } 4470f374561SHaojian Zhuang ret = of_address_to_resource(node, 0, &res); 4480f374561SHaojian Zhuang if (ret < 0) { 4490f374561SHaojian Zhuang pr_err("Not found reg property\n"); 4500f374561SHaojian Zhuang return -EINVAL; 4510f374561SHaojian Zhuang } 4520f374561SHaojian Zhuang icu_data[i].reg_status = mmp_icu_base + res.start; 4530f374561SHaojian Zhuang ret = of_address_to_resource(node, 1, &res); 4540f374561SHaojian Zhuang if (ret < 0) { 4550f374561SHaojian Zhuang pr_err("Not found reg property\n"); 4560f374561SHaojian Zhuang return -EINVAL; 4570f374561SHaojian Zhuang } 4580f374561SHaojian Zhuang icu_data[i].reg_mask = mmp_icu_base + res.start; 4590f374561SHaojian Zhuang icu_data[i].cascade_irq = irq_of_parse_and_map(node, 0); 4600f374561SHaojian Zhuang if (!icu_data[i].cascade_irq) 4610f374561SHaojian Zhuang return -EINVAL; 4620f374561SHaojian Zhuang 4630f374561SHaojian Zhuang icu_data[i].virq_base = 0; 4640f374561SHaojian Zhuang icu_data[i].domain = irq_domain_add_linear(node, nr_irqs, 4650f374561SHaojian Zhuang &mmp_irq_domain_ops, 4660f374561SHaojian Zhuang &icu_data[i]); 4670f374561SHaojian Zhuang for (irq = 0; irq < nr_irqs; irq++) { 4680f374561SHaojian Zhuang ret = irq_create_mapping(icu_data[i].domain, irq); 4690f374561SHaojian Zhuang if (!ret) { 4700f374561SHaojian Zhuang pr_err("Failed to mapping hwirq\n"); 4710f374561SHaojian Zhuang goto err; 4720f374561SHaojian Zhuang } 4730f374561SHaojian Zhuang if (!irq) 4740f374561SHaojian Zhuang icu_data[i].virq_base = ret; 4750f374561SHaojian Zhuang } 4760f374561SHaojian Zhuang icu_data[i].nr_irqs = nr_irqs; 4770f374561SHaojian Zhuang if (!of_property_read_u32(node, "mrvl,clr-mfp-irq", 4780f374561SHaojian Zhuang &mfp_irq)) { 4790f374561SHaojian Zhuang icu_data[i].clr_mfp_irq_base = icu_data[i].virq_base; 4800f374561SHaojian Zhuang icu_data[i].clr_mfp_hwirq = mfp_irq; 4810f374561SHaojian Zhuang } 4820f374561SHaojian Zhuang irq_set_chained_handler(icu_data[i].cascade_irq, 4830f374561SHaojian Zhuang icu_mux_irq_demux); 4840f374561SHaojian Zhuang max_icu_nr++; 4850f374561SHaojian Zhuang return 0; 4860f374561SHaojian Zhuang err: 4870f374561SHaojian Zhuang if (icu_data[i].virq_base) { 4880f374561SHaojian Zhuang for (j = 0; j < irq; j++) 4890f374561SHaojian Zhuang irq_dispose_mapping(icu_data[i].virq_base + j); 4900f374561SHaojian Zhuang } 4910f374561SHaojian Zhuang irq_domain_remove(icu_data[i].domain); 4920f374561SHaojian Zhuang return -EINVAL; 4930f374561SHaojian Zhuang } 4940f374561SHaojian Zhuang IRQCHIP_DECLARE(mmp2_mux_intc, "mrvl,mmp2-mux-intc", mmp2_mux_of_init); 495c052d13cSHaojian Zhuang #endif 496