1d2912cb1SThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only 2c052d13cSHaojian Zhuang /* 3c052d13cSHaojian Zhuang * linux/arch/arm/mach-mmp/irq.c 4c052d13cSHaojian Zhuang * 5c052d13cSHaojian Zhuang * Generic IRQ handling, GPIO IRQ demultiplexing, etc. 6c052d13cSHaojian Zhuang * Copyright (C) 2008 - 2012 Marvell Technology Group Ltd. 7c052d13cSHaojian Zhuang * 8c052d13cSHaojian Zhuang * Author: Bin Yang <bin.yang@marvell.com> 9c052d13cSHaojian Zhuang * Haojian Zhuang <haojian.zhuang@gmail.com> 10c052d13cSHaojian Zhuang */ 11c052d13cSHaojian Zhuang 12c052d13cSHaojian Zhuang #include <linux/module.h> 13c052d13cSHaojian Zhuang #include <linux/init.h> 14c052d13cSHaojian Zhuang #include <linux/irq.h> 1541a83e06SJoel Porquet #include <linux/irqchip.h> 16c052d13cSHaojian Zhuang #include <linux/irqdomain.h> 17c052d13cSHaojian Zhuang #include <linux/io.h> 18c052d13cSHaojian Zhuang #include <linux/ioport.h> 19c052d13cSHaojian Zhuang #include <linux/of_address.h> 20c052d13cSHaojian Zhuang #include <linux/of_irq.h> 21c052d13cSHaojian Zhuang 220f374561SHaojian Zhuang #include <asm/exception.h> 2313dde818SNeil Zhang #include <asm/hardirq.h> 240f374561SHaojian Zhuang 25c052d13cSHaojian Zhuang #define MAX_ICU_NR 16 26c052d13cSHaojian Zhuang 270f374561SHaojian Zhuang #define PJ1_INT_SEL 0x10c 280f374561SHaojian Zhuang #define PJ4_INT_SEL 0x104 290f374561SHaojian Zhuang 300f374561SHaojian Zhuang /* bit fields in PJ1_INT_SEL and PJ4_INT_SEL */ 310f374561SHaojian Zhuang #define SEL_INT_PENDING (1 << 6) 320f374561SHaojian Zhuang #define SEL_INT_NUM_MASK 0x3f 330f374561SHaojian Zhuang 342380a22bSLubomir Rintel #define MMP2_ICU_INT_ROUTE_PJ4_IRQ (1 << 5) 352380a22bSLubomir Rintel #define MMP2_ICU_INT_ROUTE_PJ4_FIQ (1 << 6) 362380a22bSLubomir Rintel 37c052d13cSHaojian Zhuang struct icu_chip_data { 38c052d13cSHaojian Zhuang int nr_irqs; 39c052d13cSHaojian Zhuang unsigned int virq_base; 40c052d13cSHaojian Zhuang unsigned int cascade_irq; 41c052d13cSHaojian Zhuang void __iomem *reg_status; 42c052d13cSHaojian Zhuang void __iomem *reg_mask; 43c052d13cSHaojian Zhuang unsigned int conf_enable; 44c052d13cSHaojian Zhuang unsigned int conf_disable; 45c052d13cSHaojian Zhuang unsigned int conf_mask; 46c052d13cSHaojian Zhuang unsigned int clr_mfp_irq_base; 47c052d13cSHaojian Zhuang unsigned int clr_mfp_hwirq; 48c052d13cSHaojian Zhuang struct irq_domain *domain; 49c052d13cSHaojian Zhuang }; 50c052d13cSHaojian Zhuang 51c052d13cSHaojian Zhuang struct mmp_intc_conf { 52c052d13cSHaojian Zhuang unsigned int conf_enable; 53c052d13cSHaojian Zhuang unsigned int conf_disable; 54c052d13cSHaojian Zhuang unsigned int conf_mask; 55c052d13cSHaojian Zhuang }; 56c052d13cSHaojian Zhuang 570f374561SHaojian Zhuang static void __iomem *mmp_icu_base; 58c052d13cSHaojian Zhuang static struct icu_chip_data icu_data[MAX_ICU_NR]; 59c052d13cSHaojian Zhuang static int max_icu_nr; 60c052d13cSHaojian Zhuang 61c052d13cSHaojian Zhuang extern void mmp2_clear_pmic_int(void); 62c052d13cSHaojian Zhuang 63c052d13cSHaojian Zhuang static void icu_mask_ack_irq(struct irq_data *d) 64c052d13cSHaojian Zhuang { 65c052d13cSHaojian Zhuang struct irq_domain *domain = d->domain; 66c052d13cSHaojian Zhuang struct icu_chip_data *data = (struct icu_chip_data *)domain->host_data; 67c052d13cSHaojian Zhuang int hwirq; 68c052d13cSHaojian Zhuang u32 r; 69c052d13cSHaojian Zhuang 70c052d13cSHaojian Zhuang hwirq = d->irq - data->virq_base; 71c052d13cSHaojian Zhuang if (data == &icu_data[0]) { 72c052d13cSHaojian Zhuang r = readl_relaxed(mmp_icu_base + (hwirq << 2)); 73c052d13cSHaojian Zhuang r &= ~data->conf_mask; 74c052d13cSHaojian Zhuang r |= data->conf_disable; 75c052d13cSHaojian Zhuang writel_relaxed(r, mmp_icu_base + (hwirq << 2)); 76c052d13cSHaojian Zhuang } else { 77c052d13cSHaojian Zhuang #ifdef CONFIG_CPU_MMP2 78c052d13cSHaojian Zhuang if ((data->virq_base == data->clr_mfp_irq_base) 79c052d13cSHaojian Zhuang && (hwirq == data->clr_mfp_hwirq)) 80c052d13cSHaojian Zhuang mmp2_clear_pmic_int(); 81c052d13cSHaojian Zhuang #endif 82c052d13cSHaojian Zhuang r = readl_relaxed(data->reg_mask) | (1 << hwirq); 83c052d13cSHaojian Zhuang writel_relaxed(r, data->reg_mask); 84c052d13cSHaojian Zhuang } 85c052d13cSHaojian Zhuang } 86c052d13cSHaojian Zhuang 87c052d13cSHaojian Zhuang static void icu_mask_irq(struct irq_data *d) 88c052d13cSHaojian Zhuang { 89c052d13cSHaojian Zhuang struct irq_domain *domain = d->domain; 90c052d13cSHaojian Zhuang struct icu_chip_data *data = (struct icu_chip_data *)domain->host_data; 91c052d13cSHaojian Zhuang int hwirq; 92c052d13cSHaojian Zhuang u32 r; 93c052d13cSHaojian Zhuang 94c052d13cSHaojian Zhuang hwirq = d->irq - data->virq_base; 95c052d13cSHaojian Zhuang if (data == &icu_data[0]) { 96c052d13cSHaojian Zhuang r = readl_relaxed(mmp_icu_base + (hwirq << 2)); 97c052d13cSHaojian Zhuang r &= ~data->conf_mask; 98c052d13cSHaojian Zhuang r |= data->conf_disable; 99c052d13cSHaojian Zhuang writel_relaxed(r, mmp_icu_base + (hwirq << 2)); 100c052d13cSHaojian Zhuang } else { 101c052d13cSHaojian Zhuang r = readl_relaxed(data->reg_mask) | (1 << hwirq); 102c052d13cSHaojian Zhuang writel_relaxed(r, data->reg_mask); 103c052d13cSHaojian Zhuang } 104c052d13cSHaojian Zhuang } 105c052d13cSHaojian Zhuang 106c052d13cSHaojian Zhuang static void icu_unmask_irq(struct irq_data *d) 107c052d13cSHaojian Zhuang { 108c052d13cSHaojian Zhuang struct irq_domain *domain = d->domain; 109c052d13cSHaojian Zhuang struct icu_chip_data *data = (struct icu_chip_data *)domain->host_data; 110c052d13cSHaojian Zhuang int hwirq; 111c052d13cSHaojian Zhuang u32 r; 112c052d13cSHaojian Zhuang 113c052d13cSHaojian Zhuang hwirq = d->irq - data->virq_base; 114c052d13cSHaojian Zhuang if (data == &icu_data[0]) { 115c052d13cSHaojian Zhuang r = readl_relaxed(mmp_icu_base + (hwirq << 2)); 116c052d13cSHaojian Zhuang r &= ~data->conf_mask; 117c052d13cSHaojian Zhuang r |= data->conf_enable; 118c052d13cSHaojian Zhuang writel_relaxed(r, mmp_icu_base + (hwirq << 2)); 119c052d13cSHaojian Zhuang } else { 120c052d13cSHaojian Zhuang r = readl_relaxed(data->reg_mask) & ~(1 << hwirq); 121c052d13cSHaojian Zhuang writel_relaxed(r, data->reg_mask); 122c052d13cSHaojian Zhuang } 123c052d13cSHaojian Zhuang } 124c052d13cSHaojian Zhuang 1250f102b6cSHaojian Zhuang struct irq_chip icu_irq_chip = { 126c052d13cSHaojian Zhuang .name = "icu_irq", 127c052d13cSHaojian Zhuang .irq_mask = icu_mask_irq, 128c052d13cSHaojian Zhuang .irq_mask_ack = icu_mask_ack_irq, 129c052d13cSHaojian Zhuang .irq_unmask = icu_unmask_irq, 130c052d13cSHaojian Zhuang }; 131c052d13cSHaojian Zhuang 132bd0b9ac4SThomas Gleixner static void icu_mux_irq_demux(struct irq_desc *desc) 133c052d13cSHaojian Zhuang { 13414873aa1SThomas Gleixner unsigned int irq = irq_desc_get_irq(desc); 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 return 0; 168c052d13cSHaojian Zhuang } 169c052d13cSHaojian Zhuang 170c052d13cSHaojian Zhuang static int mmp_irq_domain_xlate(struct irq_domain *d, struct device_node *node, 171c052d13cSHaojian Zhuang const u32 *intspec, unsigned int intsize, 172c052d13cSHaojian Zhuang unsigned long *out_hwirq, 173c052d13cSHaojian Zhuang unsigned int *out_type) 174c052d13cSHaojian Zhuang { 175c052d13cSHaojian Zhuang *out_hwirq = intspec[0]; 176c052d13cSHaojian Zhuang return 0; 177c052d13cSHaojian Zhuang } 178c052d13cSHaojian Zhuang 179096048cbSYueHaibing static const struct irq_domain_ops mmp_irq_domain_ops = { 180c052d13cSHaojian Zhuang .map = mmp_irq_domain_map, 181c052d13cSHaojian Zhuang .xlate = mmp_irq_domain_xlate, 182c052d13cSHaojian Zhuang }; 183c052d13cSHaojian Zhuang 184c8c7d93dSBhumika Goyal static const struct mmp_intc_conf mmp_conf = { 185c052d13cSHaojian Zhuang .conf_enable = 0x51, 186c052d13cSHaojian Zhuang .conf_disable = 0x0, 187c052d13cSHaojian Zhuang .conf_mask = 0x7f, 188c052d13cSHaojian Zhuang }; 189c052d13cSHaojian Zhuang 190c8c7d93dSBhumika Goyal static const struct mmp_intc_conf mmp2_conf = { 191c052d13cSHaojian Zhuang .conf_enable = 0x20, 192c052d13cSHaojian Zhuang .conf_disable = 0x0, 1932380a22bSLubomir Rintel .conf_mask = MMP2_ICU_INT_ROUTE_PJ4_IRQ | 1942380a22bSLubomir Rintel MMP2_ICU_INT_ROUTE_PJ4_FIQ, 195c052d13cSHaojian Zhuang }; 196c052d13cSHaojian Zhuang 1978783dd3aSStephen Boyd static void __exception_irq_entry mmp_handle_irq(struct pt_regs *regs) 1980f374561SHaojian Zhuang { 199b918402cSMarc Zyngier int 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; 205b918402cSMarc Zyngier handle_domain_irq(icu_data[0].domain, hwirq, regs); 2060f374561SHaojian Zhuang } 2070f374561SHaojian Zhuang 2088783dd3aSStephen Boyd static void __exception_irq_entry mmp2_handle_irq(struct pt_regs *regs) 2090f374561SHaojian Zhuang { 210b918402cSMarc Zyngier int hwirq; 2110f374561SHaojian Zhuang 2120f374561SHaojian Zhuang hwirq = readl_relaxed(mmp_icu_base + PJ4_INT_SEL); 2130f374561SHaojian Zhuang if (!(hwirq & SEL_INT_PENDING)) 2140f374561SHaojian Zhuang return; 2150f374561SHaojian Zhuang hwirq &= SEL_INT_NUM_MASK; 216b918402cSMarc Zyngier handle_domain_irq(icu_data[0].domain, hwirq, regs); 2170f374561SHaojian Zhuang } 2180f374561SHaojian Zhuang 219c052d13cSHaojian Zhuang /* MMP (ARMv5) */ 220c052d13cSHaojian Zhuang void __init icu_init_irq(void) 221c052d13cSHaojian Zhuang { 222c052d13cSHaojian Zhuang int irq; 223c052d13cSHaojian Zhuang 224c052d13cSHaojian Zhuang max_icu_nr = 1; 225c052d13cSHaojian Zhuang mmp_icu_base = ioremap(0xd4282000, 0x1000); 226c052d13cSHaojian Zhuang icu_data[0].conf_enable = mmp_conf.conf_enable; 227c052d13cSHaojian Zhuang icu_data[0].conf_disable = mmp_conf.conf_disable; 228c052d13cSHaojian Zhuang icu_data[0].conf_mask = mmp_conf.conf_mask; 229c052d13cSHaojian Zhuang icu_data[0].nr_irqs = 64; 230c052d13cSHaojian Zhuang icu_data[0].virq_base = 0; 231c052d13cSHaojian Zhuang icu_data[0].domain = irq_domain_add_legacy(NULL, 64, 0, 0, 232c052d13cSHaojian Zhuang &irq_domain_simple_ops, 233c052d13cSHaojian Zhuang &icu_data[0]); 234c052d13cSHaojian Zhuang for (irq = 0; irq < 64; irq++) { 235c052d13cSHaojian Zhuang icu_mask_irq(irq_get_irq_data(irq)); 236c052d13cSHaojian Zhuang irq_set_chip_and_handler(irq, &icu_irq_chip, handle_level_irq); 237c052d13cSHaojian Zhuang } 238c052d13cSHaojian Zhuang irq_set_default_host(icu_data[0].domain); 2390f374561SHaojian Zhuang set_handle_irq(mmp_handle_irq); 240c052d13cSHaojian Zhuang } 241c052d13cSHaojian Zhuang 242c052d13cSHaojian Zhuang /* MMP2 (ARMv7) */ 243c052d13cSHaojian Zhuang void __init mmp2_init_icu(void) 244c052d13cSHaojian Zhuang { 245942f4221SHaojian Zhuang int irq, end; 246c052d13cSHaojian Zhuang 247c052d13cSHaojian Zhuang max_icu_nr = 8; 248c052d13cSHaojian Zhuang mmp_icu_base = ioremap(0xd4282000, 0x1000); 249c052d13cSHaojian Zhuang icu_data[0].conf_enable = mmp2_conf.conf_enable; 250c052d13cSHaojian Zhuang icu_data[0].conf_disable = mmp2_conf.conf_disable; 251c052d13cSHaojian Zhuang icu_data[0].conf_mask = mmp2_conf.conf_mask; 252c052d13cSHaojian Zhuang icu_data[0].nr_irqs = 64; 253c052d13cSHaojian Zhuang icu_data[0].virq_base = 0; 254c052d13cSHaojian Zhuang icu_data[0].domain = irq_domain_add_legacy(NULL, 64, 0, 0, 255c052d13cSHaojian Zhuang &irq_domain_simple_ops, 256c052d13cSHaojian Zhuang &icu_data[0]); 257c052d13cSHaojian Zhuang icu_data[1].reg_status = mmp_icu_base + 0x150; 258c052d13cSHaojian Zhuang icu_data[1].reg_mask = mmp_icu_base + 0x168; 259942f4221SHaojian Zhuang icu_data[1].clr_mfp_irq_base = icu_data[0].virq_base + 260942f4221SHaojian Zhuang icu_data[0].nr_irqs; 261942f4221SHaojian Zhuang icu_data[1].clr_mfp_hwirq = 1; /* offset to IRQ_MMP2_PMIC_BASE */ 262c052d13cSHaojian Zhuang icu_data[1].nr_irqs = 2; 263c052d13cSHaojian Zhuang icu_data[1].cascade_irq = 4; 264942f4221SHaojian Zhuang icu_data[1].virq_base = icu_data[0].virq_base + icu_data[0].nr_irqs; 265c052d13cSHaojian Zhuang icu_data[1].domain = irq_domain_add_legacy(NULL, icu_data[1].nr_irqs, 266c052d13cSHaojian Zhuang icu_data[1].virq_base, 0, 267c052d13cSHaojian Zhuang &irq_domain_simple_ops, 268c052d13cSHaojian Zhuang &icu_data[1]); 269c052d13cSHaojian Zhuang icu_data[2].reg_status = mmp_icu_base + 0x154; 270c052d13cSHaojian Zhuang icu_data[2].reg_mask = mmp_icu_base + 0x16c; 271c052d13cSHaojian Zhuang icu_data[2].nr_irqs = 2; 272c052d13cSHaojian Zhuang icu_data[2].cascade_irq = 5; 273942f4221SHaojian Zhuang icu_data[2].virq_base = icu_data[1].virq_base + icu_data[1].nr_irqs; 274c052d13cSHaojian Zhuang icu_data[2].domain = irq_domain_add_legacy(NULL, icu_data[2].nr_irqs, 275c052d13cSHaojian Zhuang icu_data[2].virq_base, 0, 276c052d13cSHaojian Zhuang &irq_domain_simple_ops, 277c052d13cSHaojian Zhuang &icu_data[2]); 278c052d13cSHaojian Zhuang icu_data[3].reg_status = mmp_icu_base + 0x180; 279c052d13cSHaojian Zhuang icu_data[3].reg_mask = mmp_icu_base + 0x17c; 280c052d13cSHaojian Zhuang icu_data[3].nr_irqs = 3; 281c052d13cSHaojian Zhuang icu_data[3].cascade_irq = 9; 282942f4221SHaojian Zhuang icu_data[3].virq_base = icu_data[2].virq_base + icu_data[2].nr_irqs; 283c052d13cSHaojian Zhuang icu_data[3].domain = irq_domain_add_legacy(NULL, icu_data[3].nr_irqs, 284c052d13cSHaojian Zhuang icu_data[3].virq_base, 0, 285c052d13cSHaojian Zhuang &irq_domain_simple_ops, 286c052d13cSHaojian Zhuang &icu_data[3]); 287c052d13cSHaojian Zhuang icu_data[4].reg_status = mmp_icu_base + 0x158; 288c052d13cSHaojian Zhuang icu_data[4].reg_mask = mmp_icu_base + 0x170; 289c052d13cSHaojian Zhuang icu_data[4].nr_irqs = 5; 290c052d13cSHaojian Zhuang icu_data[4].cascade_irq = 17; 291942f4221SHaojian Zhuang icu_data[4].virq_base = icu_data[3].virq_base + icu_data[3].nr_irqs; 292c052d13cSHaojian Zhuang icu_data[4].domain = irq_domain_add_legacy(NULL, icu_data[4].nr_irqs, 293c052d13cSHaojian Zhuang icu_data[4].virq_base, 0, 294c052d13cSHaojian Zhuang &irq_domain_simple_ops, 295c052d13cSHaojian Zhuang &icu_data[4]); 296c052d13cSHaojian Zhuang icu_data[5].reg_status = mmp_icu_base + 0x15c; 297c052d13cSHaojian Zhuang icu_data[5].reg_mask = mmp_icu_base + 0x174; 298c052d13cSHaojian Zhuang icu_data[5].nr_irqs = 15; 299c052d13cSHaojian Zhuang icu_data[5].cascade_irq = 35; 300942f4221SHaojian Zhuang icu_data[5].virq_base = icu_data[4].virq_base + icu_data[4].nr_irqs; 301c052d13cSHaojian Zhuang icu_data[5].domain = irq_domain_add_legacy(NULL, icu_data[5].nr_irqs, 302c052d13cSHaojian Zhuang icu_data[5].virq_base, 0, 303c052d13cSHaojian Zhuang &irq_domain_simple_ops, 304c052d13cSHaojian Zhuang &icu_data[5]); 305c052d13cSHaojian Zhuang icu_data[6].reg_status = mmp_icu_base + 0x160; 306c052d13cSHaojian Zhuang icu_data[6].reg_mask = mmp_icu_base + 0x178; 307c052d13cSHaojian Zhuang icu_data[6].nr_irqs = 2; 308c052d13cSHaojian Zhuang icu_data[6].cascade_irq = 51; 309942f4221SHaojian Zhuang icu_data[6].virq_base = icu_data[5].virq_base + icu_data[5].nr_irqs; 310c052d13cSHaojian Zhuang icu_data[6].domain = irq_domain_add_legacy(NULL, icu_data[6].nr_irqs, 311c052d13cSHaojian Zhuang icu_data[6].virq_base, 0, 312c052d13cSHaojian Zhuang &irq_domain_simple_ops, 313c052d13cSHaojian Zhuang &icu_data[6]); 314c052d13cSHaojian Zhuang icu_data[7].reg_status = mmp_icu_base + 0x188; 315c052d13cSHaojian Zhuang icu_data[7].reg_mask = mmp_icu_base + 0x184; 316c052d13cSHaojian Zhuang icu_data[7].nr_irqs = 2; 317c052d13cSHaojian Zhuang icu_data[7].cascade_irq = 55; 318942f4221SHaojian Zhuang icu_data[7].virq_base = icu_data[6].virq_base + icu_data[6].nr_irqs; 319c052d13cSHaojian Zhuang icu_data[7].domain = irq_domain_add_legacy(NULL, icu_data[7].nr_irqs, 320c052d13cSHaojian Zhuang icu_data[7].virq_base, 0, 321c052d13cSHaojian Zhuang &irq_domain_simple_ops, 322c052d13cSHaojian Zhuang &icu_data[7]); 323942f4221SHaojian Zhuang end = icu_data[7].virq_base + icu_data[7].nr_irqs; 324942f4221SHaojian Zhuang for (irq = 0; irq < end; irq++) { 325c052d13cSHaojian Zhuang icu_mask_irq(irq_get_irq_data(irq)); 326942f4221SHaojian Zhuang if (irq == icu_data[1].cascade_irq || 327942f4221SHaojian Zhuang irq == icu_data[2].cascade_irq || 328942f4221SHaojian Zhuang irq == icu_data[3].cascade_irq || 329942f4221SHaojian Zhuang irq == icu_data[4].cascade_irq || 330942f4221SHaojian Zhuang irq == icu_data[5].cascade_irq || 331942f4221SHaojian Zhuang irq == icu_data[6].cascade_irq || 332942f4221SHaojian Zhuang irq == icu_data[7].cascade_irq) { 333c052d13cSHaojian Zhuang irq_set_chip(irq, &icu_irq_chip); 334c052d13cSHaojian Zhuang irq_set_chained_handler(irq, icu_mux_irq_demux); 335942f4221SHaojian Zhuang } else { 336c052d13cSHaojian Zhuang irq_set_chip_and_handler(irq, &icu_irq_chip, 337c052d13cSHaojian Zhuang handle_level_irq); 338c052d13cSHaojian Zhuang } 339c052d13cSHaojian Zhuang } 340c052d13cSHaojian Zhuang irq_set_default_host(icu_data[0].domain); 3410f374561SHaojian Zhuang set_handle_irq(mmp2_handle_irq); 342c052d13cSHaojian Zhuang } 343c052d13cSHaojian Zhuang 344c052d13cSHaojian Zhuang #ifdef CONFIG_OF 3450f374561SHaojian Zhuang static int __init mmp_init_bases(struct device_node *node) 346c052d13cSHaojian Zhuang { 3470f374561SHaojian Zhuang int ret, nr_irqs, irq, i = 0; 348c052d13cSHaojian Zhuang 349c052d13cSHaojian Zhuang ret = of_property_read_u32(node, "mrvl,intc-nr-irqs", &nr_irqs); 350c052d13cSHaojian Zhuang if (ret) { 351c052d13cSHaojian Zhuang pr_err("Not found mrvl,intc-nr-irqs property\n"); 3520f374561SHaojian Zhuang return ret; 353c052d13cSHaojian Zhuang } 354c052d13cSHaojian Zhuang 355c052d13cSHaojian Zhuang mmp_icu_base = of_iomap(node, 0); 356c052d13cSHaojian Zhuang if (!mmp_icu_base) { 357c052d13cSHaojian Zhuang pr_err("Failed to get interrupt controller register\n"); 3580f374561SHaojian Zhuang return -ENOMEM; 359c052d13cSHaojian Zhuang } 360c052d13cSHaojian Zhuang 361c052d13cSHaojian Zhuang icu_data[0].virq_base = 0; 3620f374561SHaojian Zhuang icu_data[0].domain = irq_domain_add_linear(node, nr_irqs, 363c052d13cSHaojian Zhuang &mmp_irq_domain_ops, 364c052d13cSHaojian Zhuang &icu_data[0]); 3650f374561SHaojian Zhuang for (irq = 0; irq < nr_irqs; irq++) { 3660f374561SHaojian Zhuang ret = irq_create_mapping(icu_data[0].domain, irq); 3670f374561SHaojian Zhuang if (!ret) { 3680f374561SHaojian Zhuang pr_err("Failed to mapping hwirq\n"); 3690f374561SHaojian Zhuang goto err; 370c052d13cSHaojian Zhuang } 3710f374561SHaojian Zhuang if (!irq) 3720f374561SHaojian Zhuang icu_data[0].virq_base = ret; 3730f374561SHaojian Zhuang } 3740f374561SHaojian Zhuang icu_data[0].nr_irqs = nr_irqs; 3750f374561SHaojian Zhuang return 0; 3760f374561SHaojian Zhuang err: 3770f374561SHaojian Zhuang if (icu_data[0].virq_base) { 3780f374561SHaojian Zhuang for (i = 0; i < irq; i++) 3790f374561SHaojian Zhuang irq_dispose_mapping(icu_data[0].virq_base + i); 3800f374561SHaojian Zhuang } 3810f374561SHaojian Zhuang irq_domain_remove(icu_data[0].domain); 3820f374561SHaojian Zhuang iounmap(mmp_icu_base); 3830f374561SHaojian Zhuang return -EINVAL; 3840f374561SHaojian Zhuang } 3850f374561SHaojian Zhuang 3860f374561SHaojian Zhuang static int __init mmp_of_init(struct device_node *node, 3870f374561SHaojian Zhuang struct device_node *parent) 3880f374561SHaojian Zhuang { 3890f374561SHaojian Zhuang int ret; 3900f374561SHaojian Zhuang 3910f374561SHaojian Zhuang ret = mmp_init_bases(node); 3920f374561SHaojian Zhuang if (ret < 0) 3930f374561SHaojian Zhuang return ret; 3940f374561SHaojian Zhuang 3950f374561SHaojian Zhuang icu_data[0].conf_enable = mmp_conf.conf_enable; 3960f374561SHaojian Zhuang icu_data[0].conf_disable = mmp_conf.conf_disable; 3970f374561SHaojian Zhuang icu_data[0].conf_mask = mmp_conf.conf_mask; 3980f374561SHaojian Zhuang set_handle_irq(mmp_handle_irq); 3990f374561SHaojian Zhuang max_icu_nr = 1; 4000f374561SHaojian Zhuang return 0; 4010f374561SHaojian Zhuang } 4020f374561SHaojian Zhuang IRQCHIP_DECLARE(mmp_intc, "mrvl,mmp-intc", mmp_of_init); 4030f374561SHaojian Zhuang 4040f374561SHaojian Zhuang static int __init mmp2_of_init(struct device_node *node, 4050f374561SHaojian Zhuang struct device_node *parent) 4060f374561SHaojian Zhuang { 4070f374561SHaojian Zhuang int ret; 4080f374561SHaojian Zhuang 4090f374561SHaojian Zhuang ret = mmp_init_bases(node); 4100f374561SHaojian Zhuang if (ret < 0) 4110f374561SHaojian Zhuang return ret; 4120f374561SHaojian Zhuang 4130f374561SHaojian Zhuang icu_data[0].conf_enable = mmp2_conf.conf_enable; 4140f374561SHaojian Zhuang icu_data[0].conf_disable = mmp2_conf.conf_disable; 4150f374561SHaojian Zhuang icu_data[0].conf_mask = mmp2_conf.conf_mask; 4160f374561SHaojian Zhuang set_handle_irq(mmp2_handle_irq); 4170f374561SHaojian Zhuang max_icu_nr = 1; 4180f374561SHaojian Zhuang return 0; 4190f374561SHaojian Zhuang } 4200f374561SHaojian Zhuang IRQCHIP_DECLARE(mmp2_intc, "mrvl,mmp2-intc", mmp2_of_init); 4210f374561SHaojian Zhuang 4220f374561SHaojian Zhuang static int __init mmp2_mux_of_init(struct device_node *node, 4230f374561SHaojian Zhuang struct device_node *parent) 4240f374561SHaojian Zhuang { 4250f374561SHaojian Zhuang int i, ret, irq, j = 0; 4260f374561SHaojian Zhuang u32 nr_irqs, mfp_irq; 427*d6a95280SLubomir Rintel u32 reg[4]; 4280f374561SHaojian Zhuang 4290f374561SHaojian Zhuang if (!parent) 4300f374561SHaojian Zhuang return -ENODEV; 4310f374561SHaojian Zhuang 4320f374561SHaojian Zhuang i = max_icu_nr; 4330f374561SHaojian Zhuang ret = of_property_read_u32(node, "mrvl,intc-nr-irqs", 4340f374561SHaojian Zhuang &nr_irqs); 4350f374561SHaojian Zhuang if (ret) { 4360f374561SHaojian Zhuang pr_err("Not found mrvl,intc-nr-irqs property\n"); 4370f374561SHaojian Zhuang return -EINVAL; 4380f374561SHaojian Zhuang } 439*d6a95280SLubomir Rintel 440*d6a95280SLubomir Rintel /* 441*d6a95280SLubomir Rintel * For historical reasons, the "regs" property of the 442*d6a95280SLubomir Rintel * mrvl,mmp2-mux-intc is not a regular "regs" property containing 443*d6a95280SLubomir Rintel * addresses on the parent bus, but offsets from the intc's base. 444*d6a95280SLubomir Rintel * That is why we can't use of_address_to_resource() here. 445*d6a95280SLubomir Rintel */ 446*d6a95280SLubomir Rintel ret = of_property_read_variable_u32_array(node, "reg", reg, 447*d6a95280SLubomir Rintel ARRAY_SIZE(reg), 448*d6a95280SLubomir Rintel ARRAY_SIZE(reg)); 4490f374561SHaojian Zhuang if (ret < 0) { 4500f374561SHaojian Zhuang pr_err("Not found reg property\n"); 4510f374561SHaojian Zhuang return -EINVAL; 4520f374561SHaojian Zhuang } 453*d6a95280SLubomir Rintel icu_data[i].reg_status = mmp_icu_base + reg[0]; 454*d6a95280SLubomir Rintel icu_data[i].reg_mask = mmp_icu_base + reg[2]; 4550f374561SHaojian Zhuang icu_data[i].cascade_irq = irq_of_parse_and_map(node, 0); 4560f374561SHaojian Zhuang if (!icu_data[i].cascade_irq) 4570f374561SHaojian Zhuang return -EINVAL; 4580f374561SHaojian Zhuang 4590f374561SHaojian Zhuang icu_data[i].virq_base = 0; 4600f374561SHaojian Zhuang icu_data[i].domain = irq_domain_add_linear(node, nr_irqs, 4610f374561SHaojian Zhuang &mmp_irq_domain_ops, 4620f374561SHaojian Zhuang &icu_data[i]); 4630f374561SHaojian Zhuang for (irq = 0; irq < nr_irqs; irq++) { 4640f374561SHaojian Zhuang ret = irq_create_mapping(icu_data[i].domain, irq); 4650f374561SHaojian Zhuang if (!ret) { 4660f374561SHaojian Zhuang pr_err("Failed to mapping hwirq\n"); 4670f374561SHaojian Zhuang goto err; 4680f374561SHaojian Zhuang } 4690f374561SHaojian Zhuang if (!irq) 4700f374561SHaojian Zhuang icu_data[i].virq_base = ret; 4710f374561SHaojian Zhuang } 4720f374561SHaojian Zhuang icu_data[i].nr_irqs = nr_irqs; 4730f374561SHaojian Zhuang if (!of_property_read_u32(node, "mrvl,clr-mfp-irq", 4740f374561SHaojian Zhuang &mfp_irq)) { 4750f374561SHaojian Zhuang icu_data[i].clr_mfp_irq_base = icu_data[i].virq_base; 4760f374561SHaojian Zhuang icu_data[i].clr_mfp_hwirq = mfp_irq; 4770f374561SHaojian Zhuang } 4780f374561SHaojian Zhuang irq_set_chained_handler(icu_data[i].cascade_irq, 4790f374561SHaojian Zhuang icu_mux_irq_demux); 4800f374561SHaojian Zhuang max_icu_nr++; 4810f374561SHaojian Zhuang return 0; 4820f374561SHaojian Zhuang err: 4830f374561SHaojian Zhuang if (icu_data[i].virq_base) { 4840f374561SHaojian Zhuang for (j = 0; j < irq; j++) 4850f374561SHaojian Zhuang irq_dispose_mapping(icu_data[i].virq_base + j); 4860f374561SHaojian Zhuang } 4870f374561SHaojian Zhuang irq_domain_remove(icu_data[i].domain); 4880f374561SHaojian Zhuang return -EINVAL; 4890f374561SHaojian Zhuang } 4900f374561SHaojian Zhuang IRQCHIP_DECLARE(mmp2_mux_intc, "mrvl,mmp2-mux-intc", mmp2_mux_of_init); 491c052d13cSHaojian Zhuang #endif 492