Thomas Gleixner | d2912cb | 2019-06-04 10:11:33 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
Florian Fainelli | a5042de2 | 2014-09-09 17:44:21 -0700 | [diff] [blame] | 2 | /* |
| 3 | * Broadcom BCM7120 style Level 2 interrupt controller driver |
| 4 | * |
| 5 | * Copyright (C) 2014 Broadcom Corporation |
Florian Fainelli | a5042de2 | 2014-09-09 17:44:21 -0700 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 9 | |
| 10 | #include <linux/init.h> |
| 11 | #include <linux/slab.h> |
| 12 | #include <linux/module.h> |
Kevin Cernekee | 7b7230e | 2014-12-25 09:49:05 -0800 | [diff] [blame] | 13 | #include <linux/kernel.h> |
Florian Fainelli | a5042de2 | 2014-09-09 17:44:21 -0700 | [diff] [blame] | 14 | #include <linux/platform_device.h> |
| 15 | #include <linux/of.h> |
| 16 | #include <linux/of_irq.h> |
| 17 | #include <linux/of_address.h> |
| 18 | #include <linux/of_platform.h> |
| 19 | #include <linux/interrupt.h> |
| 20 | #include <linux/irq.h> |
| 21 | #include <linux/io.h> |
| 22 | #include <linux/irqdomain.h> |
| 23 | #include <linux/reboot.h> |
Kevin Cernekee | c76acf4 | 2014-11-06 22:44:26 -0800 | [diff] [blame] | 24 | #include <linux/bitops.h> |
Joel Porquet | 41a83e06 | 2015-07-07 17:11:46 -0400 | [diff] [blame] | 25 | #include <linux/irqchip.h> |
Florian Fainelli | a5042de2 | 2014-09-09 17:44:21 -0700 | [diff] [blame] | 26 | #include <linux/irqchip/chained_irq.h> |
| 27 | |
Florian Fainelli | a5042de2 | 2014-09-09 17:44:21 -0700 | [diff] [blame] | 28 | /* Register offset in the L2 interrupt controller */ |
| 29 | #define IRQEN 0x00 |
| 30 | #define IRQSTAT 0x04 |
| 31 | |
Kevin Cernekee | c76acf4 | 2014-11-06 22:44:26 -0800 | [diff] [blame] | 32 | #define MAX_WORDS 4 |
Kevin Cernekee | ca40f1b | 2014-12-25 09:49:04 -0800 | [diff] [blame] | 33 | #define MAX_MAPPINGS (MAX_WORDS * 2) |
Kevin Cernekee | c76acf4 | 2014-11-06 22:44:26 -0800 | [diff] [blame] | 34 | #define IRQS_PER_WORD 32 |
| 35 | |
Florian Fainelli | 0aef399 | 2015-07-23 15:52:21 -0700 | [diff] [blame] | 36 | struct bcm7120_l1_intc_data { |
| 37 | struct bcm7120_l2_intc_data *b; |
| 38 | u32 irq_map_mask[MAX_WORDS]; |
| 39 | }; |
| 40 | |
Florian Fainelli | a5042de2 | 2014-09-09 17:44:21 -0700 | [diff] [blame] | 41 | struct bcm7120_l2_intc_data { |
Kevin Cernekee | c76acf4 | 2014-11-06 22:44:26 -0800 | [diff] [blame] | 42 | unsigned int n_words; |
Kevin Cernekee | 5b5468c | 2014-12-25 09:49:03 -0800 | [diff] [blame] | 43 | void __iomem *map_base[MAX_MAPPINGS]; |
| 44 | void __iomem *pair_base[MAX_WORDS]; |
| 45 | int en_offset[MAX_WORDS]; |
| 46 | int stat_offset[MAX_WORDS]; |
Florian Fainelli | a5042de2 | 2014-09-09 17:44:21 -0700 | [diff] [blame] | 47 | struct irq_domain *domain; |
| 48 | bool can_wake; |
Kevin Cernekee | c76acf4 | 2014-11-06 22:44:26 -0800 | [diff] [blame] | 49 | u32 irq_fwd_mask[MAX_WORDS]; |
Florian Fainelli | 0aef399 | 2015-07-23 15:52:21 -0700 | [diff] [blame] | 50 | struct bcm7120_l1_intc_data *l1_data; |
Kevin Cernekee | ca40f1b | 2014-12-25 09:49:04 -0800 | [diff] [blame] | 51 | int num_parent_irqs; |
| 52 | const __be32 *map_mask_prop; |
Florian Fainelli | a5042de2 | 2014-09-09 17:44:21 -0700 | [diff] [blame] | 53 | }; |
| 54 | |
Thomas Gleixner | bd0b9ac | 2015-09-14 10:42:37 +0200 | [diff] [blame] | 55 | static void bcm7120_l2_intc_irq_handle(struct irq_desc *desc) |
Florian Fainelli | a5042de2 | 2014-09-09 17:44:21 -0700 | [diff] [blame] | 56 | { |
Florian Fainelli | 0aef399 | 2015-07-23 15:52:21 -0700 | [diff] [blame] | 57 | struct bcm7120_l1_intc_data *data = irq_desc_get_handler_data(desc); |
| 58 | struct bcm7120_l2_intc_data *b = data->b; |
Florian Fainelli | a5042de2 | 2014-09-09 17:44:21 -0700 | [diff] [blame] | 59 | struct irq_chip *chip = irq_desc_get_chip(desc); |
Kevin Cernekee | c76acf4 | 2014-11-06 22:44:26 -0800 | [diff] [blame] | 60 | unsigned int idx; |
Florian Fainelli | a5042de2 | 2014-09-09 17:44:21 -0700 | [diff] [blame] | 61 | |
| 62 | chained_irq_enter(chip, desc); |
| 63 | |
Kevin Cernekee | c76acf4 | 2014-11-06 22:44:26 -0800 | [diff] [blame] | 64 | for (idx = 0; idx < b->n_words; idx++) { |
| 65 | int base = idx * IRQS_PER_WORD; |
| 66 | struct irq_chip_generic *gc = |
| 67 | irq_get_domain_generic_chip(b->domain, base); |
| 68 | unsigned long pending; |
| 69 | int hwirq; |
Florian Fainelli | a5042de2 | 2014-09-09 17:44:21 -0700 | [diff] [blame] | 70 | |
Kevin Cernekee | c76acf4 | 2014-11-06 22:44:26 -0800 | [diff] [blame] | 71 | irq_gc_lock(gc); |
Kevin Cernekee | 5b5468c | 2014-12-25 09:49:03 -0800 | [diff] [blame] | 72 | pending = irq_reg_readl(gc, b->stat_offset[idx]) & |
Florian Fainelli | 0aef399 | 2015-07-23 15:52:21 -0700 | [diff] [blame] | 73 | gc->mask_cache & |
| 74 | data->irq_map_mask[idx]; |
Kevin Cernekee | c76acf4 | 2014-11-06 22:44:26 -0800 | [diff] [blame] | 75 | irq_gc_unlock(gc); |
| 76 | |
| 77 | for_each_set_bit(hwirq, &pending, IRQS_PER_WORD) { |
| 78 | generic_handle_irq(irq_find_mapping(b->domain, |
| 79 | base + hwirq)); |
| 80 | } |
Florian Fainelli | a5042de2 | 2014-09-09 17:44:21 -0700 | [diff] [blame] | 81 | } |
| 82 | |
Florian Fainelli | a5042de2 | 2014-09-09 17:44:21 -0700 | [diff] [blame] | 83 | chained_irq_exit(chip, desc); |
| 84 | } |
| 85 | |
Brian Norris | fd53776 | 2015-07-22 16:21:40 -0700 | [diff] [blame] | 86 | static void bcm7120_l2_intc_suspend(struct irq_chip_generic *gc) |
Florian Fainelli | a5042de2 | 2014-09-09 17:44:21 -0700 | [diff] [blame] | 87 | { |
Florian Fainelli | a5042de2 | 2014-09-09 17:44:21 -0700 | [diff] [blame] | 88 | struct bcm7120_l2_intc_data *b = gc->private; |
Brian Norris | fd53776 | 2015-07-22 16:21:40 -0700 | [diff] [blame] | 89 | struct irq_chip_type *ct = gc->chip_types; |
Florian Fainelli | a5042de2 | 2014-09-09 17:44:21 -0700 | [diff] [blame] | 90 | |
| 91 | irq_gc_lock(gc); |
Kevin Cernekee | c17261f | 2014-11-06 22:44:28 -0800 | [diff] [blame] | 92 | if (b->can_wake) |
Kevin Cernekee | 5b5468c | 2014-12-25 09:49:03 -0800 | [diff] [blame] | 93 | irq_reg_writel(gc, gc->mask_cache | gc->wake_active, |
| 94 | ct->regs.mask); |
Florian Fainelli | a5042de2 | 2014-09-09 17:44:21 -0700 | [diff] [blame] | 95 | irq_gc_unlock(gc); |
| 96 | } |
| 97 | |
Brian Norris | fd53776 | 2015-07-22 16:21:40 -0700 | [diff] [blame] | 98 | static void bcm7120_l2_intc_resume(struct irq_chip_generic *gc) |
Florian Fainelli | a5042de2 | 2014-09-09 17:44:21 -0700 | [diff] [blame] | 99 | { |
Brian Norris | fd53776 | 2015-07-22 16:21:40 -0700 | [diff] [blame] | 100 | struct irq_chip_type *ct = gc->chip_types; |
Florian Fainelli | a5042de2 | 2014-09-09 17:44:21 -0700 | [diff] [blame] | 101 | |
| 102 | /* Restore the saved mask */ |
| 103 | irq_gc_lock(gc); |
Kevin Cernekee | 5b5468c | 2014-12-25 09:49:03 -0800 | [diff] [blame] | 104 | irq_reg_writel(gc, gc->mask_cache, ct->regs.mask); |
Florian Fainelli | a5042de2 | 2014-09-09 17:44:21 -0700 | [diff] [blame] | 105 | irq_gc_unlock(gc); |
| 106 | } |
| 107 | |
| 108 | static int bcm7120_l2_intc_init_one(struct device_node *dn, |
| 109 | struct bcm7120_l2_intc_data *data, |
Florian Fainelli | 0aef399 | 2015-07-23 15:52:21 -0700 | [diff] [blame] | 110 | int irq, u32 *valid_mask) |
Florian Fainelli | a5042de2 | 2014-09-09 17:44:21 -0700 | [diff] [blame] | 111 | { |
Florian Fainelli | 0aef399 | 2015-07-23 15:52:21 -0700 | [diff] [blame] | 112 | struct bcm7120_l1_intc_data *l1_data = &data->l1_data[irq]; |
Florian Fainelli | a5042de2 | 2014-09-09 17:44:21 -0700 | [diff] [blame] | 113 | int parent_irq; |
Kevin Cernekee | c76acf4 | 2014-11-06 22:44:26 -0800 | [diff] [blame] | 114 | unsigned int idx; |
Florian Fainelli | a5042de2 | 2014-09-09 17:44:21 -0700 | [diff] [blame] | 115 | |
| 116 | parent_irq = irq_of_parse_and_map(dn, irq); |
Dmitry Torokhov | 714710e | 2014-11-14 14:16:14 -0800 | [diff] [blame] | 117 | if (!parent_irq) { |
Florian Fainelli | a5042de2 | 2014-09-09 17:44:21 -0700 | [diff] [blame] | 118 | pr_err("failed to map interrupt %d\n", irq); |
Dmitry Torokhov | 714710e | 2014-11-14 14:16:14 -0800 | [diff] [blame] | 119 | return -EINVAL; |
Florian Fainelli | a5042de2 | 2014-09-09 17:44:21 -0700 | [diff] [blame] | 120 | } |
| 121 | |
Kevin Cernekee | c76acf4 | 2014-11-06 22:44:26 -0800 | [diff] [blame] | 122 | /* For multiple parent IRQs with multiple words, this looks like: |
| 123 | * <irq0_w0 irq0_w1 irq1_w0 irq1_w1 ...> |
Florian Fainelli | 0aef399 | 2015-07-23 15:52:21 -0700 | [diff] [blame] | 124 | * |
| 125 | * We need to associate a given parent interrupt with its corresponding |
| 126 | * map_mask in order to mask the status register with it because we |
| 127 | * have the same handler being called for multiple parent interrupts. |
| 128 | * |
| 129 | * This is typically something needed on BCM7xxx (STB chips). |
Kevin Cernekee | c76acf4 | 2014-11-06 22:44:26 -0800 | [diff] [blame] | 130 | */ |
Kevin Cernekee | 7b7230e | 2014-12-25 09:49:05 -0800 | [diff] [blame] | 131 | for (idx = 0; idx < data->n_words; idx++) { |
| 132 | if (data->map_mask_prop) { |
Florian Fainelli | 0aef399 | 2015-07-23 15:52:21 -0700 | [diff] [blame] | 133 | l1_data->irq_map_mask[idx] |= |
Kevin Cernekee | 7b7230e | 2014-12-25 09:49:05 -0800 | [diff] [blame] | 134 | be32_to_cpup(data->map_mask_prop + |
| 135 | irq * data->n_words + idx); |
| 136 | } else { |
Florian Fainelli | 0aef399 | 2015-07-23 15:52:21 -0700 | [diff] [blame] | 137 | l1_data->irq_map_mask[idx] = 0xffffffff; |
Kevin Cernekee | 7b7230e | 2014-12-25 09:49:05 -0800 | [diff] [blame] | 138 | } |
Florian Fainelli | 0aef399 | 2015-07-23 15:52:21 -0700 | [diff] [blame] | 139 | valid_mask[idx] |= l1_data->irq_map_mask[idx]; |
Kevin Cernekee | 7b7230e | 2014-12-25 09:49:05 -0800 | [diff] [blame] | 140 | } |
Florian Fainelli | a5042de2 | 2014-09-09 17:44:21 -0700 | [diff] [blame] | 141 | |
Florian Fainelli | 0aef399 | 2015-07-23 15:52:21 -0700 | [diff] [blame] | 142 | l1_data->b = data; |
Florian Fainelli | a5042de2 | 2014-09-09 17:44:21 -0700 | [diff] [blame] | 143 | |
Florian Fainelli | 0aef399 | 2015-07-23 15:52:21 -0700 | [diff] [blame] | 144 | irq_set_chained_handler_and_data(parent_irq, |
| 145 | bcm7120_l2_intc_irq_handle, l1_data); |
Florian Fainelli | a5042de2 | 2014-09-09 17:44:21 -0700 | [diff] [blame] | 146 | return 0; |
| 147 | } |
| 148 | |
Kevin Cernekee | ca40f1b | 2014-12-25 09:49:04 -0800 | [diff] [blame] | 149 | static int __init bcm7120_l2_intc_iomap_7120(struct device_node *dn, |
| 150 | struct bcm7120_l2_intc_data *data) |
| 151 | { |
| 152 | int ret; |
| 153 | |
| 154 | data->map_base[0] = of_iomap(dn, 0); |
| 155 | if (!data->map_base[0]) { |
| 156 | pr_err("unable to map registers\n"); |
| 157 | return -ENOMEM; |
| 158 | } |
| 159 | |
| 160 | data->pair_base[0] = data->map_base[0]; |
| 161 | data->en_offset[0] = IRQEN; |
| 162 | data->stat_offset[0] = IRQSTAT; |
| 163 | data->n_words = 1; |
| 164 | |
| 165 | ret = of_property_read_u32_array(dn, "brcm,int-fwd-mask", |
| 166 | data->irq_fwd_mask, data->n_words); |
| 167 | if (ret != 0 && ret != -EINVAL) { |
| 168 | /* property exists but has the wrong number of words */ |
| 169 | pr_err("invalid brcm,int-fwd-mask property\n"); |
| 170 | return -EINVAL; |
| 171 | } |
| 172 | |
| 173 | data->map_mask_prop = of_get_property(dn, "brcm,int-map-mask", &ret); |
| 174 | if (!data->map_mask_prop || |
| 175 | (ret != (sizeof(__be32) * data->num_parent_irqs * data->n_words))) { |
| 176 | pr_err("invalid brcm,int-map-mask property\n"); |
| 177 | return -EINVAL; |
| 178 | } |
| 179 | |
| 180 | return 0; |
| 181 | } |
| 182 | |
Kevin Cernekee | 7b7230e | 2014-12-25 09:49:05 -0800 | [diff] [blame] | 183 | static int __init bcm7120_l2_intc_iomap_3380(struct device_node *dn, |
| 184 | struct bcm7120_l2_intc_data *data) |
| 185 | { |
| 186 | unsigned int gc_idx; |
| 187 | |
| 188 | for (gc_idx = 0; gc_idx < MAX_WORDS; gc_idx++) { |
| 189 | unsigned int map_idx = gc_idx * 2; |
| 190 | void __iomem *en = of_iomap(dn, map_idx + 0); |
| 191 | void __iomem *stat = of_iomap(dn, map_idx + 1); |
| 192 | void __iomem *base = min(en, stat); |
| 193 | |
| 194 | data->map_base[map_idx + 0] = en; |
| 195 | data->map_base[map_idx + 1] = stat; |
| 196 | |
| 197 | if (!base) |
| 198 | break; |
| 199 | |
| 200 | data->pair_base[gc_idx] = base; |
| 201 | data->en_offset[gc_idx] = en - base; |
| 202 | data->stat_offset[gc_idx] = stat - base; |
| 203 | } |
| 204 | |
| 205 | if (!gc_idx) { |
| 206 | pr_err("unable to map registers\n"); |
| 207 | return -EINVAL; |
| 208 | } |
| 209 | |
| 210 | data->n_words = gc_idx; |
| 211 | return 0; |
| 212 | } |
| 213 | |
Ben Dooks | dde7e6d1a | 2016-06-08 18:59:58 +0100 | [diff] [blame] | 214 | static int __init bcm7120_l2_intc_probe(struct device_node *dn, |
Kevin Cernekee | ca40f1b | 2014-12-25 09:49:04 -0800 | [diff] [blame] | 215 | struct device_node *parent, |
| 216 | int (*iomap_regs_fn)(struct device_node *, |
| 217 | struct bcm7120_l2_intc_data *), |
| 218 | const char *intc_name) |
Florian Fainelli | a5042de2 | 2014-09-09 17:44:21 -0700 | [diff] [blame] | 219 | { |
| 220 | unsigned int clr = IRQ_NOREQUEST | IRQ_NOPROBE | IRQ_NOAUTOEN; |
| 221 | struct bcm7120_l2_intc_data *data; |
| 222 | struct irq_chip_generic *gc; |
| 223 | struct irq_chip_type *ct; |
Kevin Cernekee | ca40f1b | 2014-12-25 09:49:04 -0800 | [diff] [blame] | 224 | int ret = 0; |
Kevin Cernekee | c17261f | 2014-11-06 22:44:28 -0800 | [diff] [blame] | 225 | unsigned int idx, irq, flags; |
Florian Fainelli | 0aef399 | 2015-07-23 15:52:21 -0700 | [diff] [blame] | 226 | u32 valid_mask[MAX_WORDS] = { }; |
Florian Fainelli | a5042de2 | 2014-09-09 17:44:21 -0700 | [diff] [blame] | 227 | |
| 228 | data = kzalloc(sizeof(*data), GFP_KERNEL); |
| 229 | if (!data) |
| 230 | return -ENOMEM; |
| 231 | |
Kevin Cernekee | ca40f1b | 2014-12-25 09:49:04 -0800 | [diff] [blame] | 232 | data->num_parent_irqs = of_irq_count(dn); |
| 233 | if (data->num_parent_irqs <= 0) { |
Florian Fainelli | a5042de2 | 2014-09-09 17:44:21 -0700 | [diff] [blame] | 234 | pr_err("invalid number of parent interrupts\n"); |
| 235 | ret = -ENOMEM; |
| 236 | goto out_unmap; |
| 237 | } |
| 238 | |
Florian Fainelli | 0aef399 | 2015-07-23 15:52:21 -0700 | [diff] [blame] | 239 | data->l1_data = kcalloc(data->num_parent_irqs, sizeof(*data->l1_data), |
| 240 | GFP_KERNEL); |
| 241 | if (!data->l1_data) { |
| 242 | ret = -ENOMEM; |
| 243 | goto out_free_l1_data; |
| 244 | } |
| 245 | |
Kevin Cernekee | ca40f1b | 2014-12-25 09:49:04 -0800 | [diff] [blame] | 246 | ret = iomap_regs_fn(dn, data); |
| 247 | if (ret < 0) |
Florian Fainelli | 0aef399 | 2015-07-23 15:52:21 -0700 | [diff] [blame] | 248 | goto out_free_l1_data; |
Kevin Cernekee | ca40f1b | 2014-12-25 09:49:04 -0800 | [diff] [blame] | 249 | |
Kevin Cernekee | ca40f1b | 2014-12-25 09:49:04 -0800 | [diff] [blame] | 250 | for (irq = 0; irq < data->num_parent_irqs; irq++) { |
Florian Fainelli | 0aef399 | 2015-07-23 15:52:21 -0700 | [diff] [blame] | 251 | ret = bcm7120_l2_intc_init_one(dn, data, irq, valid_mask); |
Florian Fainelli | a5042de2 | 2014-09-09 17:44:21 -0700 | [diff] [blame] | 252 | if (ret) |
Florian Fainelli | 0aef399 | 2015-07-23 15:52:21 -0700 | [diff] [blame] | 253 | goto out_free_l1_data; |
Florian Fainelli | a5042de2 | 2014-09-09 17:44:21 -0700 | [diff] [blame] | 254 | } |
| 255 | |
Kevin Cernekee | c76acf4 | 2014-11-06 22:44:26 -0800 | [diff] [blame] | 256 | data->domain = irq_domain_add_linear(dn, IRQS_PER_WORD * data->n_words, |
| 257 | &irq_generic_chip_ops, NULL); |
Florian Fainelli | a5042de2 | 2014-09-09 17:44:21 -0700 | [diff] [blame] | 258 | if (!data->domain) { |
| 259 | ret = -ENOMEM; |
Florian Fainelli | 0aef399 | 2015-07-23 15:52:21 -0700 | [diff] [blame] | 260 | goto out_free_l1_data; |
Florian Fainelli | a5042de2 | 2014-09-09 17:44:21 -0700 | [diff] [blame] | 261 | } |
| 262 | |
Kevin Cernekee | c17261f | 2014-11-06 22:44:28 -0800 | [diff] [blame] | 263 | /* MIPS chips strapped for BE will automagically configure the |
| 264 | * peripheral registers for CPU-native byte order. |
| 265 | */ |
| 266 | flags = IRQ_GC_INIT_MASK_CACHE; |
| 267 | if (IS_ENABLED(CONFIG_MIPS) && IS_ENABLED(CONFIG_CPU_BIG_ENDIAN)) |
| 268 | flags |= IRQ_GC_BE_IO; |
| 269 | |
Kevin Cernekee | c76acf4 | 2014-11-06 22:44:26 -0800 | [diff] [blame] | 270 | ret = irq_alloc_domain_generic_chips(data->domain, IRQS_PER_WORD, 1, |
Kevin Cernekee | c17261f | 2014-11-06 22:44:28 -0800 | [diff] [blame] | 271 | dn->full_name, handle_level_irq, clr, 0, flags); |
Florian Fainelli | a5042de2 | 2014-09-09 17:44:21 -0700 | [diff] [blame] | 272 | if (ret) { |
| 273 | pr_err("failed to allocate generic irq chip\n"); |
| 274 | goto out_free_domain; |
| 275 | } |
| 276 | |
Kevin Cernekee | c76acf4 | 2014-11-06 22:44:26 -0800 | [diff] [blame] | 277 | if (of_property_read_bool(dn, "brcm,irq-can-wake")) |
Florian Fainelli | a5042de2 | 2014-09-09 17:44:21 -0700 | [diff] [blame] | 278 | data->can_wake = true; |
Kevin Cernekee | c76acf4 | 2014-11-06 22:44:26 -0800 | [diff] [blame] | 279 | |
| 280 | for (idx = 0; idx < data->n_words; idx++) { |
| 281 | irq = idx * IRQS_PER_WORD; |
| 282 | gc = irq_get_domain_generic_chip(data->domain, irq); |
| 283 | |
Florian Fainelli | 0aef399 | 2015-07-23 15:52:21 -0700 | [diff] [blame] | 284 | gc->unused = 0xffffffff & ~valid_mask[idx]; |
Kevin Cernekee | c76acf4 | 2014-11-06 22:44:26 -0800 | [diff] [blame] | 285 | gc->private = data; |
| 286 | ct = gc->chip_types; |
| 287 | |
Kevin Cernekee | 5b5468c | 2014-12-25 09:49:03 -0800 | [diff] [blame] | 288 | gc->reg_base = data->pair_base[idx]; |
| 289 | ct->regs.mask = data->en_offset[idx]; |
| 290 | |
Florian Fainelli | b304605 | 2017-08-30 17:29:16 -0700 | [diff] [blame] | 291 | /* gc->reg_base is defined and so is gc->writel */ |
| 292 | irq_reg_writel(gc, data->irq_fwd_mask[idx], |
| 293 | data->en_offset[idx]); |
| 294 | |
Kevin Cernekee | c76acf4 | 2014-11-06 22:44:26 -0800 | [diff] [blame] | 295 | ct->chip.irq_mask = irq_gc_mask_clr_bit; |
| 296 | ct->chip.irq_unmask = irq_gc_mask_set_bit; |
| 297 | ct->chip.irq_ack = irq_gc_noop; |
Brian Norris | fd53776 | 2015-07-22 16:21:40 -0700 | [diff] [blame] | 298 | gc->suspend = bcm7120_l2_intc_suspend; |
| 299 | gc->resume = bcm7120_l2_intc_resume; |
| 300 | |
| 301 | /* |
| 302 | * Initialize mask-cache, in case we need it for |
| 303 | * saving/restoring fwd mask even w/o any child interrupts |
| 304 | * installed |
| 305 | */ |
| 306 | gc->mask_cache = irq_reg_readl(gc, ct->regs.mask); |
Kevin Cernekee | c76acf4 | 2014-11-06 22:44:26 -0800 | [diff] [blame] | 307 | |
| 308 | if (data->can_wake) { |
| 309 | /* This IRQ chip can wake the system, set all |
| 310 | * relevant child interupts in wake_enabled mask |
| 311 | */ |
| 312 | gc->wake_enabled = 0xffffffff; |
| 313 | gc->wake_enabled &= ~gc->unused; |
| 314 | ct->chip.irq_set_wake = irq_gc_set_wake; |
| 315 | } |
Florian Fainelli | a5042de2 | 2014-09-09 17:44:21 -0700 | [diff] [blame] | 316 | } |
| 317 | |
Florian Fainelli | 082ce27 | 2019-03-20 12:39:19 -0700 | [diff] [blame] | 318 | pr_info("registered %s intc (%pOF, parent IRQ(s): %d)\n", |
| 319 | intc_name, dn, data->num_parent_irqs); |
| 320 | |
Florian Fainelli | a5042de2 | 2014-09-09 17:44:21 -0700 | [diff] [blame] | 321 | return 0; |
| 322 | |
| 323 | out_free_domain: |
| 324 | irq_domain_remove(data->domain); |
Florian Fainelli | 0aef399 | 2015-07-23 15:52:21 -0700 | [diff] [blame] | 325 | out_free_l1_data: |
| 326 | kfree(data->l1_data); |
Florian Fainelli | a5042de2 | 2014-09-09 17:44:21 -0700 | [diff] [blame] | 327 | out_unmap: |
Kevin Cernekee | 5b5468c | 2014-12-25 09:49:03 -0800 | [diff] [blame] | 328 | for (idx = 0; idx < MAX_MAPPINGS; idx++) { |
| 329 | if (data->map_base[idx]) |
| 330 | iounmap(data->map_base[idx]); |
Kevin Cernekee | c76acf4 | 2014-11-06 22:44:26 -0800 | [diff] [blame] | 331 | } |
Florian Fainelli | a5042de2 | 2014-09-09 17:44:21 -0700 | [diff] [blame] | 332 | kfree(data); |
| 333 | return ret; |
| 334 | } |
Kevin Cernekee | ca40f1b | 2014-12-25 09:49:04 -0800 | [diff] [blame] | 335 | |
Ben Dooks | dde7e6d1a | 2016-06-08 18:59:58 +0100 | [diff] [blame] | 336 | static int __init bcm7120_l2_intc_probe_7120(struct device_node *dn, |
| 337 | struct device_node *parent) |
Kevin Cernekee | ca40f1b | 2014-12-25 09:49:04 -0800 | [diff] [blame] | 338 | { |
| 339 | return bcm7120_l2_intc_probe(dn, parent, bcm7120_l2_intc_iomap_7120, |
| 340 | "BCM7120 L2"); |
| 341 | } |
| 342 | |
Ben Dooks | dde7e6d1a | 2016-06-08 18:59:58 +0100 | [diff] [blame] | 343 | static int __init bcm7120_l2_intc_probe_3380(struct device_node *dn, |
| 344 | struct device_node *parent) |
Kevin Cernekee | 7b7230e | 2014-12-25 09:49:05 -0800 | [diff] [blame] | 345 | { |
| 346 | return bcm7120_l2_intc_probe(dn, parent, bcm7120_l2_intc_iomap_3380, |
| 347 | "BCM3380 L2"); |
| 348 | } |
| 349 | |
Kevin Cernekee | a4fcbb8 | 2014-11-06 22:44:27 -0800 | [diff] [blame] | 350 | IRQCHIP_DECLARE(bcm7120_l2_intc, "brcm,bcm7120-l2-intc", |
Kevin Cernekee | ca40f1b | 2014-12-25 09:49:04 -0800 | [diff] [blame] | 351 | bcm7120_l2_intc_probe_7120); |
Kevin Cernekee | 7b7230e | 2014-12-25 09:49:05 -0800 | [diff] [blame] | 352 | |
| 353 | IRQCHIP_DECLARE(bcm3380_l2_intc, "brcm,bcm3380-l2-intc", |
| 354 | bcm7120_l2_intc_probe_3380); |