Thomas Gleixner | d2912cb | 2019-06-04 10:11:33 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
Haojian Zhuang | c24b311 | 2012-04-12 19:02:02 +0800 | [diff] [blame] | 2 | /* |
| 3 | * linux/arch/arm/mach-mmp/irq.c |
| 4 | * |
| 5 | * Generic IRQ handling, GPIO IRQ demultiplexing, etc. |
| 6 | * Copyright (C) 2008 - 2012 Marvell Technology Group Ltd. |
| 7 | * |
| 8 | * Author: Bin Yang <bin.yang@marvell.com> |
| 9 | * Haojian Zhuang <haojian.zhuang@gmail.com> |
Haojian Zhuang | c24b311 | 2012-04-12 19:02:02 +0800 | [diff] [blame] | 10 | */ |
| 11 | |
| 12 | #include <linux/module.h> |
| 13 | #include <linux/init.h> |
| 14 | #include <linux/irq.h> |
Joel Porquet | 41a83e06 | 2015-07-07 17:11:46 -0400 | [diff] [blame] | 15 | #include <linux/irqchip.h> |
Lubomir Rintel | a46bc5f | 2019-08-22 11:26:30 +0200 | [diff] [blame] | 16 | #include <linux/irqchip/chained_irq.h> |
Haojian Zhuang | c24b311 | 2012-04-12 19:02:02 +0800 | [diff] [blame] | 17 | #include <linux/irqdomain.h> |
| 18 | #include <linux/io.h> |
| 19 | #include <linux/ioport.h> |
| 20 | #include <linux/of_address.h> |
| 21 | #include <linux/of_irq.h> |
| 22 | |
Haojian Zhuang | 0f37456 | 2013-04-21 16:53:02 +0800 | [diff] [blame] | 23 | #include <asm/exception.h> |
Neil Zhang | 13dde81 | 2013-12-06 18:46:47 +0800 | [diff] [blame] | 24 | #include <asm/hardirq.h> |
Haojian Zhuang | 0f37456 | 2013-04-21 16:53:02 +0800 | [diff] [blame] | 25 | |
Haojian Zhuang | c24b311 | 2012-04-12 19:02:02 +0800 | [diff] [blame] | 26 | #define MAX_ICU_NR 16 |
| 27 | |
Haojian Zhuang | 0f37456 | 2013-04-21 16:53:02 +0800 | [diff] [blame] | 28 | #define PJ1_INT_SEL 0x10c |
| 29 | #define PJ4_INT_SEL 0x104 |
| 30 | |
| 31 | /* bit fields in PJ1_INT_SEL and PJ4_INT_SEL */ |
| 32 | #define SEL_INT_PENDING (1 << 6) |
| 33 | #define SEL_INT_NUM_MASK 0x3f |
| 34 | |
Lubomir Rintel | 2380a22 | 2019-01-28 16:59:35 +0100 | [diff] [blame] | 35 | #define MMP2_ICU_INT_ROUTE_PJ4_IRQ (1 << 5) |
| 36 | #define MMP2_ICU_INT_ROUTE_PJ4_FIQ (1 << 6) |
| 37 | |
Haojian Zhuang | c24b311 | 2012-04-12 19:02:02 +0800 | [diff] [blame] | 38 | struct icu_chip_data { |
| 39 | int nr_irqs; |
| 40 | unsigned int virq_base; |
| 41 | unsigned int cascade_irq; |
| 42 | void __iomem *reg_status; |
| 43 | void __iomem *reg_mask; |
| 44 | unsigned int conf_enable; |
| 45 | unsigned int conf_disable; |
| 46 | unsigned int conf_mask; |
Andres Salomon | 9e8e891 | 2019-08-22 11:26:31 +0200 | [diff] [blame] | 47 | unsigned int conf2_mask; |
Haojian Zhuang | c24b311 | 2012-04-12 19:02:02 +0800 | [diff] [blame] | 48 | unsigned int clr_mfp_irq_base; |
| 49 | unsigned int clr_mfp_hwirq; |
| 50 | struct irq_domain *domain; |
| 51 | }; |
| 52 | |
| 53 | struct mmp_intc_conf { |
| 54 | unsigned int conf_enable; |
| 55 | unsigned int conf_disable; |
| 56 | unsigned int conf_mask; |
Andres Salomon | 9e8e891 | 2019-08-22 11:26:31 +0200 | [diff] [blame] | 57 | unsigned int conf2_mask; |
Haojian Zhuang | c24b311 | 2012-04-12 19:02:02 +0800 | [diff] [blame] | 58 | }; |
| 59 | |
Haojian Zhuang | 0f37456 | 2013-04-21 16:53:02 +0800 | [diff] [blame] | 60 | static void __iomem *mmp_icu_base; |
Andres Salomon | 9e8e891 | 2019-08-22 11:26:31 +0200 | [diff] [blame] | 61 | static void __iomem *mmp_icu2_base; |
Haojian Zhuang | c24b311 | 2012-04-12 19:02:02 +0800 | [diff] [blame] | 62 | static struct icu_chip_data icu_data[MAX_ICU_NR]; |
| 63 | static int max_icu_nr; |
| 64 | |
| 65 | extern void mmp2_clear_pmic_int(void); |
| 66 | |
| 67 | static void icu_mask_ack_irq(struct irq_data *d) |
| 68 | { |
| 69 | struct irq_domain *domain = d->domain; |
| 70 | struct icu_chip_data *data = (struct icu_chip_data *)domain->host_data; |
| 71 | int hwirq; |
| 72 | u32 r; |
| 73 | |
| 74 | hwirq = d->irq - data->virq_base; |
| 75 | if (data == &icu_data[0]) { |
| 76 | r = readl_relaxed(mmp_icu_base + (hwirq << 2)); |
| 77 | r &= ~data->conf_mask; |
| 78 | r |= data->conf_disable; |
| 79 | writel_relaxed(r, mmp_icu_base + (hwirq << 2)); |
| 80 | } else { |
| 81 | #ifdef CONFIG_CPU_MMP2 |
| 82 | if ((data->virq_base == data->clr_mfp_irq_base) |
| 83 | && (hwirq == data->clr_mfp_hwirq)) |
| 84 | mmp2_clear_pmic_int(); |
| 85 | #endif |
| 86 | r = readl_relaxed(data->reg_mask) | (1 << hwirq); |
| 87 | writel_relaxed(r, data->reg_mask); |
| 88 | } |
| 89 | } |
| 90 | |
| 91 | static void icu_mask_irq(struct irq_data *d) |
| 92 | { |
| 93 | struct irq_domain *domain = d->domain; |
| 94 | struct icu_chip_data *data = (struct icu_chip_data *)domain->host_data; |
| 95 | int hwirq; |
| 96 | u32 r; |
| 97 | |
| 98 | hwirq = d->irq - data->virq_base; |
| 99 | if (data == &icu_data[0]) { |
| 100 | r = readl_relaxed(mmp_icu_base + (hwirq << 2)); |
| 101 | r &= ~data->conf_mask; |
| 102 | r |= data->conf_disable; |
| 103 | writel_relaxed(r, mmp_icu_base + (hwirq << 2)); |
Andres Salomon | 9e8e891 | 2019-08-22 11:26:31 +0200 | [diff] [blame] | 104 | |
| 105 | if (data->conf2_mask) { |
| 106 | /* |
| 107 | * ICU1 (above) only controls PJ4 MP1; if using SMP, |
| 108 | * we need to also mask the MP2 and MM cores via ICU2. |
| 109 | */ |
| 110 | r = readl_relaxed(mmp_icu2_base + (hwirq << 2)); |
| 111 | r &= ~data->conf2_mask; |
| 112 | writel_relaxed(r, mmp_icu2_base + (hwirq << 2)); |
| 113 | } |
Haojian Zhuang | c24b311 | 2012-04-12 19:02:02 +0800 | [diff] [blame] | 114 | } else { |
| 115 | r = readl_relaxed(data->reg_mask) | (1 << hwirq); |
| 116 | writel_relaxed(r, data->reg_mask); |
| 117 | } |
| 118 | } |
| 119 | |
| 120 | static void icu_unmask_irq(struct irq_data *d) |
| 121 | { |
| 122 | struct irq_domain *domain = d->domain; |
| 123 | struct icu_chip_data *data = (struct icu_chip_data *)domain->host_data; |
| 124 | int hwirq; |
| 125 | u32 r; |
| 126 | |
| 127 | hwirq = d->irq - data->virq_base; |
| 128 | if (data == &icu_data[0]) { |
| 129 | r = readl_relaxed(mmp_icu_base + (hwirq << 2)); |
| 130 | r &= ~data->conf_mask; |
| 131 | r |= data->conf_enable; |
| 132 | writel_relaxed(r, mmp_icu_base + (hwirq << 2)); |
| 133 | } else { |
| 134 | r = readl_relaxed(data->reg_mask) & ~(1 << hwirq); |
| 135 | writel_relaxed(r, data->reg_mask); |
| 136 | } |
| 137 | } |
| 138 | |
Haojian Zhuang | 0f102b6 | 2013-06-03 10:02:59 +0800 | [diff] [blame] | 139 | struct irq_chip icu_irq_chip = { |
Haojian Zhuang | c24b311 | 2012-04-12 19:02:02 +0800 | [diff] [blame] | 140 | .name = "icu_irq", |
| 141 | .irq_mask = icu_mask_irq, |
| 142 | .irq_mask_ack = icu_mask_ack_irq, |
| 143 | .irq_unmask = icu_unmask_irq, |
| 144 | }; |
| 145 | |
Thomas Gleixner | bd0b9ac | 2015-09-14 10:42:37 +0200 | [diff] [blame] | 146 | static void icu_mux_irq_demux(struct irq_desc *desc) |
Haojian Zhuang | c24b311 | 2012-04-12 19:02:02 +0800 | [diff] [blame] | 147 | { |
Thomas Gleixner | 14873aa | 2015-07-16 22:38:51 +0200 | [diff] [blame] | 148 | unsigned int irq = irq_desc_get_irq(desc); |
Lubomir Rintel | a46bc5f | 2019-08-22 11:26:30 +0200 | [diff] [blame] | 149 | struct irq_chip *chip = irq_desc_get_chip(desc); |
Haojian Zhuang | c24b311 | 2012-04-12 19:02:02 +0800 | [diff] [blame] | 150 | struct irq_domain *domain; |
| 151 | struct icu_chip_data *data; |
| 152 | int i; |
| 153 | unsigned long mask, status, n; |
| 154 | |
Lubomir Rintel | a46bc5f | 2019-08-22 11:26:30 +0200 | [diff] [blame] | 155 | chained_irq_enter(chip, desc); |
| 156 | |
Haojian Zhuang | c24b311 | 2012-04-12 19:02:02 +0800 | [diff] [blame] | 157 | for (i = 1; i < max_icu_nr; i++) { |
| 158 | if (irq == icu_data[i].cascade_irq) { |
| 159 | domain = icu_data[i].domain; |
| 160 | data = (struct icu_chip_data *)domain->host_data; |
| 161 | break; |
| 162 | } |
| 163 | } |
| 164 | if (i >= max_icu_nr) { |
| 165 | pr_err("Spurious irq %d in MMP INTC\n", irq); |
Lubomir Rintel | a46bc5f | 2019-08-22 11:26:30 +0200 | [diff] [blame] | 166 | goto out; |
Haojian Zhuang | c24b311 | 2012-04-12 19:02:02 +0800 | [diff] [blame] | 167 | } |
| 168 | |
| 169 | mask = readl_relaxed(data->reg_mask); |
| 170 | while (1) { |
| 171 | status = readl_relaxed(data->reg_status) & ~mask; |
| 172 | if (status == 0) |
| 173 | break; |
Wei Yongjun | 93d429a | 2012-09-14 10:30:59 +0800 | [diff] [blame] | 174 | for_each_set_bit(n, &status, BITS_PER_LONG) { |
Haojian Zhuang | c24b311 | 2012-04-12 19:02:02 +0800 | [diff] [blame] | 175 | generic_handle_irq(icu_data[i].virq_base + n); |
Haojian Zhuang | c24b311 | 2012-04-12 19:02:02 +0800 | [diff] [blame] | 176 | } |
| 177 | } |
Lubomir Rintel | a46bc5f | 2019-08-22 11:26:30 +0200 | [diff] [blame] | 178 | |
| 179 | out: |
| 180 | chained_irq_exit(chip, desc); |
Haojian Zhuang | c24b311 | 2012-04-12 19:02:02 +0800 | [diff] [blame] | 181 | } |
| 182 | |
| 183 | static int mmp_irq_domain_map(struct irq_domain *d, unsigned int irq, |
| 184 | irq_hw_number_t hw) |
| 185 | { |
| 186 | irq_set_chip_and_handler(irq, &icu_irq_chip, handle_level_irq); |
Haojian Zhuang | c24b311 | 2012-04-12 19:02:02 +0800 | [diff] [blame] | 187 | return 0; |
| 188 | } |
| 189 | |
| 190 | static int mmp_irq_domain_xlate(struct irq_domain *d, struct device_node *node, |
| 191 | const u32 *intspec, unsigned int intsize, |
| 192 | unsigned long *out_hwirq, |
| 193 | unsigned int *out_type) |
| 194 | { |
| 195 | *out_hwirq = intspec[0]; |
| 196 | return 0; |
| 197 | } |
| 198 | |
YueHaibing | 096048c | 2019-03-20 21:40:27 +0800 | [diff] [blame] | 199 | static const struct irq_domain_ops mmp_irq_domain_ops = { |
Haojian Zhuang | c24b311 | 2012-04-12 19:02:02 +0800 | [diff] [blame] | 200 | .map = mmp_irq_domain_map, |
| 201 | .xlate = mmp_irq_domain_xlate, |
| 202 | }; |
| 203 | |
Bhumika Goyal | c8c7d93 | 2017-08-24 15:56:21 +0530 | [diff] [blame] | 204 | static const struct mmp_intc_conf mmp_conf = { |
Haojian Zhuang | c24b311 | 2012-04-12 19:02:02 +0800 | [diff] [blame] | 205 | .conf_enable = 0x51, |
| 206 | .conf_disable = 0x0, |
| 207 | .conf_mask = 0x7f, |
| 208 | }; |
| 209 | |
Bhumika Goyal | c8c7d93 | 2017-08-24 15:56:21 +0530 | [diff] [blame] | 210 | static const struct mmp_intc_conf mmp2_conf = { |
Haojian Zhuang | c24b311 | 2012-04-12 19:02:02 +0800 | [diff] [blame] | 211 | .conf_enable = 0x20, |
| 212 | .conf_disable = 0x0, |
Lubomir Rintel | 2380a22 | 2019-01-28 16:59:35 +0100 | [diff] [blame] | 213 | .conf_mask = MMP2_ICU_INT_ROUTE_PJ4_IRQ | |
| 214 | MMP2_ICU_INT_ROUTE_PJ4_FIQ, |
Haojian Zhuang | c24b311 | 2012-04-12 19:02:02 +0800 | [diff] [blame] | 215 | }; |
| 216 | |
Andres Salomon | 9e8e891 | 2019-08-22 11:26:31 +0200 | [diff] [blame] | 217 | static struct mmp_intc_conf mmp3_conf = { |
| 218 | .conf_enable = 0x20, |
| 219 | .conf_disable = 0x0, |
| 220 | .conf_mask = MMP2_ICU_INT_ROUTE_PJ4_IRQ | |
| 221 | MMP2_ICU_INT_ROUTE_PJ4_FIQ, |
| 222 | .conf2_mask = 0xf0, |
| 223 | }; |
| 224 | |
Stephen Boyd | 8783dd3 | 2014-03-04 16:40:30 -0800 | [diff] [blame] | 225 | static void __exception_irq_entry mmp_handle_irq(struct pt_regs *regs) |
Haojian Zhuang | 0f37456 | 2013-04-21 16:53:02 +0800 | [diff] [blame] | 226 | { |
Marc Zyngier | b918402 | 2014-08-26 11:03:23 +0100 | [diff] [blame] | 227 | int hwirq; |
Haojian Zhuang | 0f37456 | 2013-04-21 16:53:02 +0800 | [diff] [blame] | 228 | |
| 229 | hwirq = readl_relaxed(mmp_icu_base + PJ1_INT_SEL); |
| 230 | if (!(hwirq & SEL_INT_PENDING)) |
| 231 | return; |
| 232 | hwirq &= SEL_INT_NUM_MASK; |
Marc Zyngier | b918402 | 2014-08-26 11:03:23 +0100 | [diff] [blame] | 233 | handle_domain_irq(icu_data[0].domain, hwirq, regs); |
Haojian Zhuang | 0f37456 | 2013-04-21 16:53:02 +0800 | [diff] [blame] | 234 | } |
| 235 | |
Stephen Boyd | 8783dd3 | 2014-03-04 16:40:30 -0800 | [diff] [blame] | 236 | static void __exception_irq_entry mmp2_handle_irq(struct pt_regs *regs) |
Haojian Zhuang | 0f37456 | 2013-04-21 16:53:02 +0800 | [diff] [blame] | 237 | { |
Marc Zyngier | b918402 | 2014-08-26 11:03:23 +0100 | [diff] [blame] | 238 | int hwirq; |
Haojian Zhuang | 0f37456 | 2013-04-21 16:53:02 +0800 | [diff] [blame] | 239 | |
| 240 | hwirq = readl_relaxed(mmp_icu_base + PJ4_INT_SEL); |
| 241 | if (!(hwirq & SEL_INT_PENDING)) |
| 242 | return; |
| 243 | hwirq &= SEL_INT_NUM_MASK; |
Marc Zyngier | b918402 | 2014-08-26 11:03:23 +0100 | [diff] [blame] | 244 | handle_domain_irq(icu_data[0].domain, hwirq, regs); |
Haojian Zhuang | 0f37456 | 2013-04-21 16:53:02 +0800 | [diff] [blame] | 245 | } |
| 246 | |
Haojian Zhuang | c24b311 | 2012-04-12 19:02:02 +0800 | [diff] [blame] | 247 | /* MMP (ARMv5) */ |
| 248 | void __init icu_init_irq(void) |
| 249 | { |
| 250 | int irq; |
| 251 | |
| 252 | max_icu_nr = 1; |
| 253 | mmp_icu_base = ioremap(0xd4282000, 0x1000); |
| 254 | icu_data[0].conf_enable = mmp_conf.conf_enable; |
| 255 | icu_data[0].conf_disable = mmp_conf.conf_disable; |
| 256 | icu_data[0].conf_mask = mmp_conf.conf_mask; |
| 257 | icu_data[0].nr_irqs = 64; |
| 258 | icu_data[0].virq_base = 0; |
| 259 | icu_data[0].domain = irq_domain_add_legacy(NULL, 64, 0, 0, |
| 260 | &irq_domain_simple_ops, |
| 261 | &icu_data[0]); |
| 262 | for (irq = 0; irq < 64; irq++) { |
| 263 | icu_mask_irq(irq_get_irq_data(irq)); |
| 264 | irq_set_chip_and_handler(irq, &icu_irq_chip, handle_level_irq); |
Haojian Zhuang | c24b311 | 2012-04-12 19:02:02 +0800 | [diff] [blame] | 265 | } |
| 266 | irq_set_default_host(icu_data[0].domain); |
Haojian Zhuang | 0f37456 | 2013-04-21 16:53:02 +0800 | [diff] [blame] | 267 | set_handle_irq(mmp_handle_irq); |
Haojian Zhuang | c24b311 | 2012-04-12 19:02:02 +0800 | [diff] [blame] | 268 | } |
| 269 | |
| 270 | /* MMP2 (ARMv7) */ |
| 271 | void __init mmp2_init_icu(void) |
| 272 | { |
Haojian Zhuang | 942f422 | 2013-06-03 10:26:47 +0800 | [diff] [blame] | 273 | int irq, end; |
Haojian Zhuang | c24b311 | 2012-04-12 19:02:02 +0800 | [diff] [blame] | 274 | |
| 275 | max_icu_nr = 8; |
| 276 | mmp_icu_base = ioremap(0xd4282000, 0x1000); |
| 277 | icu_data[0].conf_enable = mmp2_conf.conf_enable; |
| 278 | icu_data[0].conf_disable = mmp2_conf.conf_disable; |
| 279 | icu_data[0].conf_mask = mmp2_conf.conf_mask; |
| 280 | icu_data[0].nr_irqs = 64; |
| 281 | icu_data[0].virq_base = 0; |
| 282 | icu_data[0].domain = irq_domain_add_legacy(NULL, 64, 0, 0, |
| 283 | &irq_domain_simple_ops, |
| 284 | &icu_data[0]); |
| 285 | icu_data[1].reg_status = mmp_icu_base + 0x150; |
| 286 | icu_data[1].reg_mask = mmp_icu_base + 0x168; |
Haojian Zhuang | 942f422 | 2013-06-03 10:26:47 +0800 | [diff] [blame] | 287 | icu_data[1].clr_mfp_irq_base = icu_data[0].virq_base + |
| 288 | icu_data[0].nr_irqs; |
| 289 | icu_data[1].clr_mfp_hwirq = 1; /* offset to IRQ_MMP2_PMIC_BASE */ |
Haojian Zhuang | c24b311 | 2012-04-12 19:02:02 +0800 | [diff] [blame] | 290 | icu_data[1].nr_irqs = 2; |
Haojian Zhuang | 10bd21c | 2012-06-05 17:42:23 +0800 | [diff] [blame] | 291 | icu_data[1].cascade_irq = 4; |
Haojian Zhuang | 942f422 | 2013-06-03 10:26:47 +0800 | [diff] [blame] | 292 | icu_data[1].virq_base = icu_data[0].virq_base + icu_data[0].nr_irqs; |
Haojian Zhuang | c24b311 | 2012-04-12 19:02:02 +0800 | [diff] [blame] | 293 | icu_data[1].domain = irq_domain_add_legacy(NULL, icu_data[1].nr_irqs, |
| 294 | icu_data[1].virq_base, 0, |
| 295 | &irq_domain_simple_ops, |
| 296 | &icu_data[1]); |
| 297 | icu_data[2].reg_status = mmp_icu_base + 0x154; |
| 298 | icu_data[2].reg_mask = mmp_icu_base + 0x16c; |
| 299 | icu_data[2].nr_irqs = 2; |
Haojian Zhuang | 10bd21c | 2012-06-05 17:42:23 +0800 | [diff] [blame] | 300 | icu_data[2].cascade_irq = 5; |
Haojian Zhuang | 942f422 | 2013-06-03 10:26:47 +0800 | [diff] [blame] | 301 | icu_data[2].virq_base = icu_data[1].virq_base + icu_data[1].nr_irqs; |
Haojian Zhuang | c24b311 | 2012-04-12 19:02:02 +0800 | [diff] [blame] | 302 | icu_data[2].domain = irq_domain_add_legacy(NULL, icu_data[2].nr_irqs, |
| 303 | icu_data[2].virq_base, 0, |
| 304 | &irq_domain_simple_ops, |
| 305 | &icu_data[2]); |
| 306 | icu_data[3].reg_status = mmp_icu_base + 0x180; |
| 307 | icu_data[3].reg_mask = mmp_icu_base + 0x17c; |
| 308 | icu_data[3].nr_irqs = 3; |
Haojian Zhuang | 10bd21c | 2012-06-05 17:42:23 +0800 | [diff] [blame] | 309 | icu_data[3].cascade_irq = 9; |
Haojian Zhuang | 942f422 | 2013-06-03 10:26:47 +0800 | [diff] [blame] | 310 | icu_data[3].virq_base = icu_data[2].virq_base + icu_data[2].nr_irqs; |
Haojian Zhuang | c24b311 | 2012-04-12 19:02:02 +0800 | [diff] [blame] | 311 | icu_data[3].domain = irq_domain_add_legacy(NULL, icu_data[3].nr_irqs, |
| 312 | icu_data[3].virq_base, 0, |
| 313 | &irq_domain_simple_ops, |
| 314 | &icu_data[3]); |
| 315 | icu_data[4].reg_status = mmp_icu_base + 0x158; |
| 316 | icu_data[4].reg_mask = mmp_icu_base + 0x170; |
| 317 | icu_data[4].nr_irqs = 5; |
Haojian Zhuang | 10bd21c | 2012-06-05 17:42:23 +0800 | [diff] [blame] | 318 | icu_data[4].cascade_irq = 17; |
Haojian Zhuang | 942f422 | 2013-06-03 10:26:47 +0800 | [diff] [blame] | 319 | icu_data[4].virq_base = icu_data[3].virq_base + icu_data[3].nr_irqs; |
Haojian Zhuang | c24b311 | 2012-04-12 19:02:02 +0800 | [diff] [blame] | 320 | icu_data[4].domain = irq_domain_add_legacy(NULL, icu_data[4].nr_irqs, |
| 321 | icu_data[4].virq_base, 0, |
| 322 | &irq_domain_simple_ops, |
| 323 | &icu_data[4]); |
| 324 | icu_data[5].reg_status = mmp_icu_base + 0x15c; |
| 325 | icu_data[5].reg_mask = mmp_icu_base + 0x174; |
| 326 | icu_data[5].nr_irqs = 15; |
Haojian Zhuang | 10bd21c | 2012-06-05 17:42:23 +0800 | [diff] [blame] | 327 | icu_data[5].cascade_irq = 35; |
Haojian Zhuang | 942f422 | 2013-06-03 10:26:47 +0800 | [diff] [blame] | 328 | icu_data[5].virq_base = icu_data[4].virq_base + icu_data[4].nr_irqs; |
Haojian Zhuang | c24b311 | 2012-04-12 19:02:02 +0800 | [diff] [blame] | 329 | icu_data[5].domain = irq_domain_add_legacy(NULL, icu_data[5].nr_irqs, |
| 330 | icu_data[5].virq_base, 0, |
| 331 | &irq_domain_simple_ops, |
| 332 | &icu_data[5]); |
| 333 | icu_data[6].reg_status = mmp_icu_base + 0x160; |
| 334 | icu_data[6].reg_mask = mmp_icu_base + 0x178; |
| 335 | icu_data[6].nr_irqs = 2; |
Haojian Zhuang | 10bd21c | 2012-06-05 17:42:23 +0800 | [diff] [blame] | 336 | icu_data[6].cascade_irq = 51; |
Haojian Zhuang | 942f422 | 2013-06-03 10:26:47 +0800 | [diff] [blame] | 337 | icu_data[6].virq_base = icu_data[5].virq_base + icu_data[5].nr_irqs; |
Haojian Zhuang | c24b311 | 2012-04-12 19:02:02 +0800 | [diff] [blame] | 338 | icu_data[6].domain = irq_domain_add_legacy(NULL, icu_data[6].nr_irqs, |
| 339 | icu_data[6].virq_base, 0, |
| 340 | &irq_domain_simple_ops, |
| 341 | &icu_data[6]); |
| 342 | icu_data[7].reg_status = mmp_icu_base + 0x188; |
| 343 | icu_data[7].reg_mask = mmp_icu_base + 0x184; |
| 344 | icu_data[7].nr_irqs = 2; |
Haojian Zhuang | 10bd21c | 2012-06-05 17:42:23 +0800 | [diff] [blame] | 345 | icu_data[7].cascade_irq = 55; |
Haojian Zhuang | 942f422 | 2013-06-03 10:26:47 +0800 | [diff] [blame] | 346 | icu_data[7].virq_base = icu_data[6].virq_base + icu_data[6].nr_irqs; |
Haojian Zhuang | c24b311 | 2012-04-12 19:02:02 +0800 | [diff] [blame] | 347 | icu_data[7].domain = irq_domain_add_legacy(NULL, icu_data[7].nr_irqs, |
| 348 | icu_data[7].virq_base, 0, |
| 349 | &irq_domain_simple_ops, |
| 350 | &icu_data[7]); |
Haojian Zhuang | 942f422 | 2013-06-03 10:26:47 +0800 | [diff] [blame] | 351 | end = icu_data[7].virq_base + icu_data[7].nr_irqs; |
| 352 | for (irq = 0; irq < end; irq++) { |
Haojian Zhuang | c24b311 | 2012-04-12 19:02:02 +0800 | [diff] [blame] | 353 | icu_mask_irq(irq_get_irq_data(irq)); |
Haojian Zhuang | 942f422 | 2013-06-03 10:26:47 +0800 | [diff] [blame] | 354 | if (irq == icu_data[1].cascade_irq || |
| 355 | irq == icu_data[2].cascade_irq || |
| 356 | irq == icu_data[3].cascade_irq || |
| 357 | irq == icu_data[4].cascade_irq || |
| 358 | irq == icu_data[5].cascade_irq || |
| 359 | irq == icu_data[6].cascade_irq || |
| 360 | irq == icu_data[7].cascade_irq) { |
Haojian Zhuang | c24b311 | 2012-04-12 19:02:02 +0800 | [diff] [blame] | 361 | irq_set_chip(irq, &icu_irq_chip); |
| 362 | irq_set_chained_handler(irq, icu_mux_irq_demux); |
Haojian Zhuang | 942f422 | 2013-06-03 10:26:47 +0800 | [diff] [blame] | 363 | } else { |
Haojian Zhuang | c24b311 | 2012-04-12 19:02:02 +0800 | [diff] [blame] | 364 | irq_set_chip_and_handler(irq, &icu_irq_chip, |
| 365 | handle_level_irq); |
Haojian Zhuang | c24b311 | 2012-04-12 19:02:02 +0800 | [diff] [blame] | 366 | } |
Haojian Zhuang | c24b311 | 2012-04-12 19:02:02 +0800 | [diff] [blame] | 367 | } |
| 368 | irq_set_default_host(icu_data[0].domain); |
Haojian Zhuang | 0f37456 | 2013-04-21 16:53:02 +0800 | [diff] [blame] | 369 | set_handle_irq(mmp2_handle_irq); |
Haojian Zhuang | c24b311 | 2012-04-12 19:02:02 +0800 | [diff] [blame] | 370 | } |
| 371 | |
| 372 | #ifdef CONFIG_OF |
Haojian Zhuang | 0f37456 | 2013-04-21 16:53:02 +0800 | [diff] [blame] | 373 | static int __init mmp_init_bases(struct device_node *node) |
Haojian Zhuang | c24b311 | 2012-04-12 19:02:02 +0800 | [diff] [blame] | 374 | { |
Haojian Zhuang | 0f37456 | 2013-04-21 16:53:02 +0800 | [diff] [blame] | 375 | int ret, nr_irqs, irq, i = 0; |
Haojian Zhuang | c24b311 | 2012-04-12 19:02:02 +0800 | [diff] [blame] | 376 | |
| 377 | ret = of_property_read_u32(node, "mrvl,intc-nr-irqs", &nr_irqs); |
| 378 | if (ret) { |
| 379 | pr_err("Not found mrvl,intc-nr-irqs property\n"); |
Haojian Zhuang | 0f37456 | 2013-04-21 16:53:02 +0800 | [diff] [blame] | 380 | return ret; |
Haojian Zhuang | c24b311 | 2012-04-12 19:02:02 +0800 | [diff] [blame] | 381 | } |
| 382 | |
| 383 | mmp_icu_base = of_iomap(node, 0); |
| 384 | if (!mmp_icu_base) { |
| 385 | pr_err("Failed to get interrupt controller register\n"); |
Haojian Zhuang | 0f37456 | 2013-04-21 16:53:02 +0800 | [diff] [blame] | 386 | return -ENOMEM; |
Haojian Zhuang | c24b311 | 2012-04-12 19:02:02 +0800 | [diff] [blame] | 387 | } |
| 388 | |
Haojian Zhuang | c24b311 | 2012-04-12 19:02:02 +0800 | [diff] [blame] | 389 | icu_data[0].virq_base = 0; |
Haojian Zhuang | 0f37456 | 2013-04-21 16:53:02 +0800 | [diff] [blame] | 390 | icu_data[0].domain = irq_domain_add_linear(node, nr_irqs, |
Haojian Zhuang | c24b311 | 2012-04-12 19:02:02 +0800 | [diff] [blame] | 391 | &mmp_irq_domain_ops, |
| 392 | &icu_data[0]); |
Haojian Zhuang | 0f37456 | 2013-04-21 16:53:02 +0800 | [diff] [blame] | 393 | for (irq = 0; irq < nr_irqs; irq++) { |
| 394 | ret = irq_create_mapping(icu_data[0].domain, irq); |
| 395 | if (!ret) { |
| 396 | pr_err("Failed to mapping hwirq\n"); |
| 397 | goto err; |
| 398 | } |
| 399 | if (!irq) |
| 400 | icu_data[0].virq_base = ret; |
| 401 | } |
| 402 | icu_data[0].nr_irqs = nr_irqs; |
| 403 | return 0; |
Haojian Zhuang | c24b311 | 2012-04-12 19:02:02 +0800 | [diff] [blame] | 404 | err: |
Haojian Zhuang | 0f37456 | 2013-04-21 16:53:02 +0800 | [diff] [blame] | 405 | if (icu_data[0].virq_base) { |
| 406 | for (i = 0; i < irq; i++) |
| 407 | irq_dispose_mapping(icu_data[0].virq_base + i); |
| 408 | } |
| 409 | irq_domain_remove(icu_data[0].domain); |
Haojian Zhuang | c24b311 | 2012-04-12 19:02:02 +0800 | [diff] [blame] | 410 | iounmap(mmp_icu_base); |
Haojian Zhuang | 0f37456 | 2013-04-21 16:53:02 +0800 | [diff] [blame] | 411 | return -EINVAL; |
Haojian Zhuang | c24b311 | 2012-04-12 19:02:02 +0800 | [diff] [blame] | 412 | } |
Haojian Zhuang | 0f37456 | 2013-04-21 16:53:02 +0800 | [diff] [blame] | 413 | |
| 414 | static int __init mmp_of_init(struct device_node *node, |
| 415 | struct device_node *parent) |
| 416 | { |
| 417 | int ret; |
| 418 | |
| 419 | ret = mmp_init_bases(node); |
| 420 | if (ret < 0) |
| 421 | return ret; |
| 422 | |
| 423 | icu_data[0].conf_enable = mmp_conf.conf_enable; |
| 424 | icu_data[0].conf_disable = mmp_conf.conf_disable; |
| 425 | icu_data[0].conf_mask = mmp_conf.conf_mask; |
Haojian Zhuang | 0f37456 | 2013-04-21 16:53:02 +0800 | [diff] [blame] | 426 | set_handle_irq(mmp_handle_irq); |
| 427 | max_icu_nr = 1; |
| 428 | return 0; |
| 429 | } |
| 430 | IRQCHIP_DECLARE(mmp_intc, "mrvl,mmp-intc", mmp_of_init); |
| 431 | |
| 432 | static int __init mmp2_of_init(struct device_node *node, |
| 433 | struct device_node *parent) |
| 434 | { |
| 435 | int ret; |
| 436 | |
| 437 | ret = mmp_init_bases(node); |
| 438 | if (ret < 0) |
| 439 | return ret; |
| 440 | |
| 441 | icu_data[0].conf_enable = mmp2_conf.conf_enable; |
| 442 | icu_data[0].conf_disable = mmp2_conf.conf_disable; |
| 443 | icu_data[0].conf_mask = mmp2_conf.conf_mask; |
Haojian Zhuang | 0f37456 | 2013-04-21 16:53:02 +0800 | [diff] [blame] | 444 | set_handle_irq(mmp2_handle_irq); |
| 445 | max_icu_nr = 1; |
| 446 | return 0; |
| 447 | } |
| 448 | IRQCHIP_DECLARE(mmp2_intc, "mrvl,mmp2-intc", mmp2_of_init); |
| 449 | |
Andres Salomon | 9e8e891 | 2019-08-22 11:26:31 +0200 | [diff] [blame] | 450 | static int __init mmp3_of_init(struct device_node *node, |
| 451 | struct device_node *parent) |
| 452 | { |
| 453 | int ret; |
| 454 | |
| 455 | mmp_icu2_base = of_iomap(node, 1); |
| 456 | if (!mmp_icu2_base) { |
| 457 | pr_err("Failed to get interrupt controller register #2\n"); |
| 458 | return -ENODEV; |
| 459 | } |
| 460 | |
| 461 | ret = mmp_init_bases(node); |
| 462 | if (ret < 0) { |
| 463 | iounmap(mmp_icu2_base); |
| 464 | return ret; |
| 465 | } |
| 466 | |
| 467 | icu_data[0].conf_enable = mmp3_conf.conf_enable; |
| 468 | icu_data[0].conf_disable = mmp3_conf.conf_disable; |
| 469 | icu_data[0].conf_mask = mmp3_conf.conf_mask; |
| 470 | icu_data[0].conf2_mask = mmp3_conf.conf2_mask; |
Lubomir Rintel | 2178add | 2019-08-22 11:26:32 +0200 | [diff] [blame] | 471 | |
| 472 | if (!parent) { |
| 473 | /* This is the main interrupt controller. */ |
| 474 | set_handle_irq(mmp2_handle_irq); |
| 475 | } |
| 476 | |
Andres Salomon | 9e8e891 | 2019-08-22 11:26:31 +0200 | [diff] [blame] | 477 | max_icu_nr = 1; |
| 478 | return 0; |
| 479 | } |
| 480 | IRQCHIP_DECLARE(mmp3_intc, "marvell,mmp3-intc", mmp3_of_init); |
| 481 | |
Haojian Zhuang | 0f37456 | 2013-04-21 16:53:02 +0800 | [diff] [blame] | 482 | static int __init mmp2_mux_of_init(struct device_node *node, |
| 483 | struct device_node *parent) |
| 484 | { |
Haojian Zhuang | 0f37456 | 2013-04-21 16:53:02 +0800 | [diff] [blame] | 485 | int i, ret, irq, j = 0; |
| 486 | u32 nr_irqs, mfp_irq; |
Lubomir Rintel | d6a9528 | 2019-08-22 11:26:29 +0200 | [diff] [blame] | 487 | u32 reg[4]; |
Haojian Zhuang | 0f37456 | 2013-04-21 16:53:02 +0800 | [diff] [blame] | 488 | |
| 489 | if (!parent) |
| 490 | return -ENODEV; |
| 491 | |
| 492 | i = max_icu_nr; |
| 493 | ret = of_property_read_u32(node, "mrvl,intc-nr-irqs", |
| 494 | &nr_irqs); |
| 495 | if (ret) { |
| 496 | pr_err("Not found mrvl,intc-nr-irqs property\n"); |
| 497 | return -EINVAL; |
| 498 | } |
Lubomir Rintel | d6a9528 | 2019-08-22 11:26:29 +0200 | [diff] [blame] | 499 | |
| 500 | /* |
| 501 | * For historical reasons, the "regs" property of the |
| 502 | * mrvl,mmp2-mux-intc is not a regular "regs" property containing |
| 503 | * addresses on the parent bus, but offsets from the intc's base. |
| 504 | * That is why we can't use of_address_to_resource() here. |
| 505 | */ |
| 506 | ret = of_property_read_variable_u32_array(node, "reg", reg, |
| 507 | ARRAY_SIZE(reg), |
| 508 | ARRAY_SIZE(reg)); |
Haojian Zhuang | 0f37456 | 2013-04-21 16:53:02 +0800 | [diff] [blame] | 509 | if (ret < 0) { |
| 510 | pr_err("Not found reg property\n"); |
| 511 | return -EINVAL; |
| 512 | } |
Lubomir Rintel | d6a9528 | 2019-08-22 11:26:29 +0200 | [diff] [blame] | 513 | icu_data[i].reg_status = mmp_icu_base + reg[0]; |
| 514 | icu_data[i].reg_mask = mmp_icu_base + reg[2]; |
Haojian Zhuang | 0f37456 | 2013-04-21 16:53:02 +0800 | [diff] [blame] | 515 | icu_data[i].cascade_irq = irq_of_parse_and_map(node, 0); |
| 516 | if (!icu_data[i].cascade_irq) |
| 517 | return -EINVAL; |
| 518 | |
| 519 | icu_data[i].virq_base = 0; |
| 520 | icu_data[i].domain = irq_domain_add_linear(node, nr_irqs, |
| 521 | &mmp_irq_domain_ops, |
| 522 | &icu_data[i]); |
| 523 | for (irq = 0; irq < nr_irqs; irq++) { |
| 524 | ret = irq_create_mapping(icu_data[i].domain, irq); |
| 525 | if (!ret) { |
| 526 | pr_err("Failed to mapping hwirq\n"); |
| 527 | goto err; |
| 528 | } |
| 529 | if (!irq) |
| 530 | icu_data[i].virq_base = ret; |
| 531 | } |
| 532 | icu_data[i].nr_irqs = nr_irqs; |
| 533 | if (!of_property_read_u32(node, "mrvl,clr-mfp-irq", |
| 534 | &mfp_irq)) { |
| 535 | icu_data[i].clr_mfp_irq_base = icu_data[i].virq_base; |
| 536 | icu_data[i].clr_mfp_hwirq = mfp_irq; |
| 537 | } |
| 538 | irq_set_chained_handler(icu_data[i].cascade_irq, |
| 539 | icu_mux_irq_demux); |
| 540 | max_icu_nr++; |
| 541 | return 0; |
| 542 | err: |
| 543 | if (icu_data[i].virq_base) { |
| 544 | for (j = 0; j < irq; j++) |
| 545 | irq_dispose_mapping(icu_data[i].virq_base + j); |
| 546 | } |
| 547 | irq_domain_remove(icu_data[i].domain); |
| 548 | return -EINVAL; |
| 549 | } |
| 550 | IRQCHIP_DECLARE(mmp2_mux_intc, "mrvl,mmp2-mux-intc", mmp2_mux_of_init); |
Haojian Zhuang | c24b311 | 2012-04-12 19:02:02 +0800 | [diff] [blame] | 551 | #endif |