Thomas Gleixner | d2912cb | 2019-06-04 10:11:33 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
Sricharan R | 96ca848 | 2013-12-03 15:57:23 +0530 | [diff] [blame] | 2 | /* |
| 3 | * drivers/irqchip/irq-crossbar.c |
| 4 | * |
| 5 | * Copyright (C) 2013 Texas Instruments Incorporated - http://www.ti.com |
| 6 | * Author: Sricharan R <r.sricharan@ti.com> |
Sricharan R | 96ca848 | 2013-12-03 15:57:23 +0530 | [diff] [blame] | 7 | */ |
| 8 | #include <linux/err.h> |
| 9 | #include <linux/io.h> |
Joel Porquet | 41a83e06 | 2015-07-07 17:11:46 -0400 | [diff] [blame] | 10 | #include <linux/irqchip.h> |
Marc Zyngier | 783d318 | 2015-03-11 15:43:44 +0000 | [diff] [blame] | 11 | #include <linux/irqdomain.h> |
Sricharan R | 96ca848 | 2013-12-03 15:57:23 +0530 | [diff] [blame] | 12 | #include <linux/of_address.h> |
| 13 | #include <linux/of_irq.h> |
| 14 | #include <linux/slab.h> |
Marc Zyngier | 783d318 | 2015-03-11 15:43:44 +0000 | [diff] [blame] | 15 | |
Sricharan R | 96ca848 | 2013-12-03 15:57:23 +0530 | [diff] [blame] | 16 | #define IRQ_FREE -1 |
Nishanth Menon | 1d50d2c | 2014-06-26 12:40:19 +0530 | [diff] [blame] | 17 | #define IRQ_RESERVED -2 |
Nishanth Menon | 64e0f8b | 2014-06-26 12:40:21 +0530 | [diff] [blame] | 18 | #define IRQ_SKIP -3 |
Sricharan R | 96ca848 | 2013-12-03 15:57:23 +0530 | [diff] [blame] | 19 | #define GIC_IRQ_START 32 |
| 20 | |
Nishanth Menon | e30ef8a | 2014-06-26 12:40:26 +0530 | [diff] [blame] | 21 | /** |
| 22 | * struct crossbar_device - crossbar device description |
Marc Zyngier | 783d318 | 2015-03-11 15:43:44 +0000 | [diff] [blame] | 23 | * @lock: spinlock serializing access to @irq_map |
Sricharan R | 96ca848 | 2013-12-03 15:57:23 +0530 | [diff] [blame] | 24 | * @int_max: maximum number of supported interrupts |
Nishanth Menon | a35057d | 2014-06-26 12:40:22 +0530 | [diff] [blame] | 25 | * @safe_map: safe default value to initialize the crossbar |
Nishanth Menon | 2f7d2fb | 2014-06-26 12:40:31 +0530 | [diff] [blame] | 26 | * @max_crossbar_sources: Maximum number of crossbar sources |
Sricharan R | 96ca848 | 2013-12-03 15:57:23 +0530 | [diff] [blame] | 27 | * @irq_map: array of interrupts to crossbar number mapping |
| 28 | * @crossbar_base: crossbar base address |
| 29 | * @register_offsets: offsets for each irq number |
Nishanth Menon | e30ef8a | 2014-06-26 12:40:26 +0530 | [diff] [blame] | 30 | * @write: register write function pointer |
Sricharan R | 96ca848 | 2013-12-03 15:57:23 +0530 | [diff] [blame] | 31 | */ |
| 32 | struct crossbar_device { |
Marc Zyngier | 783d318 | 2015-03-11 15:43:44 +0000 | [diff] [blame] | 33 | raw_spinlock_t lock; |
Sricharan R | 96ca848 | 2013-12-03 15:57:23 +0530 | [diff] [blame] | 34 | uint int_max; |
Nishanth Menon | a35057d | 2014-06-26 12:40:22 +0530 | [diff] [blame] | 35 | uint safe_map; |
Nishanth Menon | 2f7d2fb | 2014-06-26 12:40:31 +0530 | [diff] [blame] | 36 | uint max_crossbar_sources; |
Sricharan R | 96ca848 | 2013-12-03 15:57:23 +0530 | [diff] [blame] | 37 | uint *irq_map; |
| 38 | void __iomem *crossbar_base; |
| 39 | int *register_offsets; |
Nishanth Menon | a35057d | 2014-06-26 12:40:22 +0530 | [diff] [blame] | 40 | void (*write)(int, int); |
Sricharan R | 96ca848 | 2013-12-03 15:57:23 +0530 | [diff] [blame] | 41 | }; |
| 42 | |
| 43 | static struct crossbar_device *cb; |
| 44 | |
Marc Zyngier | 783d318 | 2015-03-11 15:43:44 +0000 | [diff] [blame] | 45 | static void crossbar_writel(int irq_no, int cb_no) |
Sricharan R | 96ca848 | 2013-12-03 15:57:23 +0530 | [diff] [blame] | 46 | { |
| 47 | writel(cb_no, cb->crossbar_base + cb->register_offsets[irq_no]); |
| 48 | } |
| 49 | |
Marc Zyngier | 783d318 | 2015-03-11 15:43:44 +0000 | [diff] [blame] | 50 | static void crossbar_writew(int irq_no, int cb_no) |
Sricharan R | 96ca848 | 2013-12-03 15:57:23 +0530 | [diff] [blame] | 51 | { |
| 52 | writew(cb_no, cb->crossbar_base + cb->register_offsets[irq_no]); |
| 53 | } |
| 54 | |
Marc Zyngier | 783d318 | 2015-03-11 15:43:44 +0000 | [diff] [blame] | 55 | static void crossbar_writeb(int irq_no, int cb_no) |
Sricharan R | 96ca848 | 2013-12-03 15:57:23 +0530 | [diff] [blame] | 56 | { |
| 57 | writeb(cb_no, cb->crossbar_base + cb->register_offsets[irq_no]); |
| 58 | } |
| 59 | |
Marc Zyngier | 783d318 | 2015-03-11 15:43:44 +0000 | [diff] [blame] | 60 | static struct irq_chip crossbar_chip = { |
| 61 | .name = "CBAR", |
| 62 | .irq_eoi = irq_chip_eoi_parent, |
| 63 | .irq_mask = irq_chip_mask_parent, |
| 64 | .irq_unmask = irq_chip_unmask_parent, |
| 65 | .irq_retrigger = irq_chip_retrigger_hierarchy, |
Grygorii Strashko | e269ec4 | 2015-08-14 15:20:27 +0300 | [diff] [blame] | 66 | .irq_set_type = irq_chip_set_type_parent, |
Grygorii Strashko | 8200fe4 | 2015-08-14 15:20:30 +0300 | [diff] [blame] | 67 | .flags = IRQCHIP_MASK_ON_SUSPEND | |
| 68 | IRQCHIP_SKIP_SET_WAKE, |
Marc Zyngier | 783d318 | 2015-03-11 15:43:44 +0000 | [diff] [blame] | 69 | #ifdef CONFIG_SMP |
| 70 | .irq_set_affinity = irq_chip_set_affinity_parent, |
| 71 | #endif |
| 72 | }; |
| 73 | |
| 74 | static int allocate_gic_irq(struct irq_domain *domain, unsigned virq, |
| 75 | irq_hw_number_t hwirq) |
Nishanth Menon | 6f16fc8 | 2014-06-26 12:40:20 +0530 | [diff] [blame] | 76 | { |
Marc Zyngier | f833f57 | 2015-10-13 12:51:33 +0100 | [diff] [blame] | 77 | struct irq_fwspec fwspec; |
Nishanth Menon | 6f16fc8 | 2014-06-26 12:40:20 +0530 | [diff] [blame] | 78 | int i; |
Marc Zyngier | 783d318 | 2015-03-11 15:43:44 +0000 | [diff] [blame] | 79 | int err; |
Nishanth Menon | 6f16fc8 | 2014-06-26 12:40:20 +0530 | [diff] [blame] | 80 | |
Marc Zyngier | f833f57 | 2015-10-13 12:51:33 +0100 | [diff] [blame] | 81 | if (!irq_domain_get_of_node(domain->parent)) |
| 82 | return -EINVAL; |
| 83 | |
Marc Zyngier | 783d318 | 2015-03-11 15:43:44 +0000 | [diff] [blame] | 84 | raw_spin_lock(&cb->lock); |
Nishanth Menon | ddee0fb | 2014-06-26 12:40:23 +0530 | [diff] [blame] | 85 | for (i = cb->int_max - 1; i >= 0; i--) { |
Sricharan R | 96ca848 | 2013-12-03 15:57:23 +0530 | [diff] [blame] | 86 | if (cb->irq_map[i] == IRQ_FREE) { |
Marc Zyngier | 783d318 | 2015-03-11 15:43:44 +0000 | [diff] [blame] | 87 | cb->irq_map[i] = hwirq; |
| 88 | break; |
Sricharan R | 96ca848 | 2013-12-03 15:57:23 +0530 | [diff] [blame] | 89 | } |
| 90 | } |
Marc Zyngier | 783d318 | 2015-03-11 15:43:44 +0000 | [diff] [blame] | 91 | raw_spin_unlock(&cb->lock); |
Sricharan R | 96ca848 | 2013-12-03 15:57:23 +0530 | [diff] [blame] | 92 | |
Marc Zyngier | 783d318 | 2015-03-11 15:43:44 +0000 | [diff] [blame] | 93 | if (i < 0) |
| 94 | return -ENODEV; |
| 95 | |
Marc Zyngier | f833f57 | 2015-10-13 12:51:33 +0100 | [diff] [blame] | 96 | fwspec.fwnode = domain->parent->fwnode; |
| 97 | fwspec.param_count = 3; |
| 98 | fwspec.param[0] = 0; /* SPI */ |
| 99 | fwspec.param[1] = i; |
| 100 | fwspec.param[2] = IRQ_TYPE_LEVEL_HIGH; |
Marc Zyngier | 783d318 | 2015-03-11 15:43:44 +0000 | [diff] [blame] | 101 | |
Marc Zyngier | f833f57 | 2015-10-13 12:51:33 +0100 | [diff] [blame] | 102 | err = irq_domain_alloc_irqs_parent(domain, virq, 1, &fwspec); |
Marc Zyngier | 783d318 | 2015-03-11 15:43:44 +0000 | [diff] [blame] | 103 | if (err) |
| 104 | cb->irq_map[i] = IRQ_FREE; |
| 105 | else |
| 106 | cb->write(i, hwirq); |
| 107 | |
| 108 | return err; |
Sricharan R | 96ca848 | 2013-12-03 15:57:23 +0530 | [diff] [blame] | 109 | } |
| 110 | |
Marc Zyngier | 783d318 | 2015-03-11 15:43:44 +0000 | [diff] [blame] | 111 | static int crossbar_domain_alloc(struct irq_domain *d, unsigned int virq, |
| 112 | unsigned int nr_irqs, void *data) |
Nishanth Menon | 29918b6 | 2014-06-26 12:40:32 +0530 | [diff] [blame] | 113 | { |
Marc Zyngier | f833f57 | 2015-10-13 12:51:33 +0100 | [diff] [blame] | 114 | struct irq_fwspec *fwspec = data; |
Marc Zyngier | 783d318 | 2015-03-11 15:43:44 +0000 | [diff] [blame] | 115 | irq_hw_number_t hwirq; |
| 116 | int i; |
Nishanth Menon | d360892 | 2014-06-26 12:40:34 +0530 | [diff] [blame] | 117 | |
Marc Zyngier | f833f57 | 2015-10-13 12:51:33 +0100 | [diff] [blame] | 118 | if (fwspec->param_count != 3) |
Marc Zyngier | 783d318 | 2015-03-11 15:43:44 +0000 | [diff] [blame] | 119 | return -EINVAL; /* Not GIC compliant */ |
Marc Zyngier | f833f57 | 2015-10-13 12:51:33 +0100 | [diff] [blame] | 120 | if (fwspec->param[0] != 0) |
Marc Zyngier | 783d318 | 2015-03-11 15:43:44 +0000 | [diff] [blame] | 121 | return -EINVAL; /* No PPI should point to this domain */ |
| 122 | |
Marc Zyngier | f833f57 | 2015-10-13 12:51:33 +0100 | [diff] [blame] | 123 | hwirq = fwspec->param[1]; |
Marc Zyngier | 783d318 | 2015-03-11 15:43:44 +0000 | [diff] [blame] | 124 | if ((hwirq + nr_irqs) > cb->max_crossbar_sources) |
| 125 | return -EINVAL; /* Can't deal with this */ |
| 126 | |
| 127 | for (i = 0; i < nr_irqs; i++) { |
| 128 | int err = allocate_gic_irq(d, virq + i, hwirq + i); |
| 129 | |
| 130 | if (err) |
| 131 | return err; |
| 132 | |
| 133 | irq_domain_set_hwirq_and_chip(d, virq + i, hwirq + i, |
| 134 | &crossbar_chip, NULL); |
Nishanth Menon | d360892 | 2014-06-26 12:40:34 +0530 | [diff] [blame] | 135 | } |
Nishanth Menon | 29918b6 | 2014-06-26 12:40:32 +0530 | [diff] [blame] | 136 | |
Sricharan R | 96ca848 | 2013-12-03 15:57:23 +0530 | [diff] [blame] | 137 | return 0; |
| 138 | } |
| 139 | |
Sricharan R | 8b09a45 | 2014-06-26 12:40:30 +0530 | [diff] [blame] | 140 | /** |
Marc Zyngier | 783d318 | 2015-03-11 15:43:44 +0000 | [diff] [blame] | 141 | * crossbar_domain_free - unmap/free a crossbar<->irq connection |
| 142 | * @domain: domain of irq to unmap |
| 143 | * @virq: virq number |
| 144 | * @nr_irqs: number of irqs to free |
Sricharan R | 8b09a45 | 2014-06-26 12:40:30 +0530 | [diff] [blame] | 145 | * |
| 146 | * We do not maintain a use count of total number of map/unmap |
| 147 | * calls for a particular irq to find out if a irq can be really |
| 148 | * unmapped. This is because unmap is called during irq_dispose_mapping(irq), |
| 149 | * after which irq is anyways unusable. So an explicit map has to be called |
| 150 | * after that. |
| 151 | */ |
Marc Zyngier | 783d318 | 2015-03-11 15:43:44 +0000 | [diff] [blame] | 152 | static void crossbar_domain_free(struct irq_domain *domain, unsigned int virq, |
| 153 | unsigned int nr_irqs) |
Sricharan R | 96ca848 | 2013-12-03 15:57:23 +0530 | [diff] [blame] | 154 | { |
Marc Zyngier | 783d318 | 2015-03-11 15:43:44 +0000 | [diff] [blame] | 155 | int i; |
Sricharan R | 96ca848 | 2013-12-03 15:57:23 +0530 | [diff] [blame] | 156 | |
Marc Zyngier | 783d318 | 2015-03-11 15:43:44 +0000 | [diff] [blame] | 157 | raw_spin_lock(&cb->lock); |
| 158 | for (i = 0; i < nr_irqs; i++) { |
| 159 | struct irq_data *d = irq_domain_get_irq_data(domain, virq + i); |
| 160 | |
| 161 | irq_domain_reset_irq_data(d); |
| 162 | cb->irq_map[d->hwirq] = IRQ_FREE; |
| 163 | cb->write(d->hwirq, cb->safe_map); |
Nishanth Menon | a35057d | 2014-06-26 12:40:22 +0530 | [diff] [blame] | 164 | } |
Marc Zyngier | 783d318 | 2015-03-11 15:43:44 +0000 | [diff] [blame] | 165 | raw_spin_unlock(&cb->lock); |
Sricharan R | 96ca848 | 2013-12-03 15:57:23 +0530 | [diff] [blame] | 166 | } |
| 167 | |
Marc Zyngier | f833f57 | 2015-10-13 12:51:33 +0100 | [diff] [blame] | 168 | static int crossbar_domain_translate(struct irq_domain *d, |
| 169 | struct irq_fwspec *fwspec, |
| 170 | unsigned long *hwirq, |
| 171 | unsigned int *type) |
Sricharan R | 96ca848 | 2013-12-03 15:57:23 +0530 | [diff] [blame] | 172 | { |
Marc Zyngier | f833f57 | 2015-10-13 12:51:33 +0100 | [diff] [blame] | 173 | if (is_of_node(fwspec->fwnode)) { |
| 174 | if (fwspec->param_count != 3) |
| 175 | return -EINVAL; |
Sricharan R | 96ca848 | 2013-12-03 15:57:23 +0530 | [diff] [blame] | 176 | |
Marc Zyngier | f833f57 | 2015-10-13 12:51:33 +0100 | [diff] [blame] | 177 | /* No PPI should point to this domain */ |
| 178 | if (fwspec->param[0] != 0) |
| 179 | return -EINVAL; |
| 180 | |
| 181 | *hwirq = fwspec->param[1]; |
Jon Hunter | a2a8fa5 | 2016-05-10 16:14:37 +0100 | [diff] [blame] | 182 | *type = fwspec->param[2] & IRQ_TYPE_SENSE_MASK; |
Marc Zyngier | f833f57 | 2015-10-13 12:51:33 +0100 | [diff] [blame] | 183 | return 0; |
| 184 | } |
| 185 | |
| 186 | return -EINVAL; |
Sricharan R | 96ca848 | 2013-12-03 15:57:23 +0530 | [diff] [blame] | 187 | } |
| 188 | |
Marc Zyngier | 783d318 | 2015-03-11 15:43:44 +0000 | [diff] [blame] | 189 | static const struct irq_domain_ops crossbar_domain_ops = { |
Marc Zyngier | f833f57 | 2015-10-13 12:51:33 +0100 | [diff] [blame] | 190 | .alloc = crossbar_domain_alloc, |
| 191 | .free = crossbar_domain_free, |
| 192 | .translate = crossbar_domain_translate, |
Sricharan R | 96ca848 | 2013-12-03 15:57:23 +0530 | [diff] [blame] | 193 | }; |
| 194 | |
| 195 | static int __init crossbar_of_init(struct device_node *node) |
| 196 | { |
Franck Demathieu | 4b9de5d | 2017-03-06 14:41:06 +0100 | [diff] [blame] | 197 | u32 max = 0, entry, reg_size; |
Franck Demathieu | b28ace1 | 2017-02-23 10:48:55 +0100 | [diff] [blame] | 198 | int i, size, reserved = 0; |
Sricharan R | 96ca848 | 2013-12-03 15:57:23 +0530 | [diff] [blame] | 199 | const __be32 *irqsr; |
Nishanth Menon | edb442d | 2014-06-26 12:40:27 +0530 | [diff] [blame] | 200 | int ret = -ENOMEM; |
Sricharan R | 96ca848 | 2013-12-03 15:57:23 +0530 | [diff] [blame] | 201 | |
Dan Carpenter | 3894e9e | 2014-04-03 10:21:34 +0300 | [diff] [blame] | 202 | cb = kzalloc(sizeof(*cb), GFP_KERNEL); |
Sricharan R | 96ca848 | 2013-12-03 15:57:23 +0530 | [diff] [blame] | 203 | |
| 204 | if (!cb) |
Nishanth Menon | edb442d | 2014-06-26 12:40:27 +0530 | [diff] [blame] | 205 | return ret; |
Sricharan R | 96ca848 | 2013-12-03 15:57:23 +0530 | [diff] [blame] | 206 | |
| 207 | cb->crossbar_base = of_iomap(node, 0); |
| 208 | if (!cb->crossbar_base) |
Nishanth Menon | 3c44d51 | 2014-06-26 12:40:28 +0530 | [diff] [blame] | 209 | goto err_cb; |
Sricharan R | 96ca848 | 2013-12-03 15:57:23 +0530 | [diff] [blame] | 210 | |
Nishanth Menon | 2f7d2fb | 2014-06-26 12:40:31 +0530 | [diff] [blame] | 211 | of_property_read_u32(node, "ti,max-crossbar-sources", |
| 212 | &cb->max_crossbar_sources); |
| 213 | if (!cb->max_crossbar_sources) { |
| 214 | pr_err("missing 'ti,max-crossbar-sources' property\n"); |
| 215 | ret = -EINVAL; |
| 216 | goto err_base; |
| 217 | } |
| 218 | |
Sricharan R | 96ca848 | 2013-12-03 15:57:23 +0530 | [diff] [blame] | 219 | of_property_read_u32(node, "ti,max-irqs", &max); |
Nishanth Menon | edb442d | 2014-06-26 12:40:27 +0530 | [diff] [blame] | 220 | if (!max) { |
| 221 | pr_err("missing 'ti,max-irqs' property\n"); |
| 222 | ret = -EINVAL; |
Nishanth Menon | 3c44d51 | 2014-06-26 12:40:28 +0530 | [diff] [blame] | 223 | goto err_base; |
Nishanth Menon | edb442d | 2014-06-26 12:40:27 +0530 | [diff] [blame] | 224 | } |
Nishanth Menon | 4dbf45e | 2014-06-26 12:40:25 +0530 | [diff] [blame] | 225 | cb->irq_map = kcalloc(max, sizeof(int), GFP_KERNEL); |
Sricharan R | 96ca848 | 2013-12-03 15:57:23 +0530 | [diff] [blame] | 226 | if (!cb->irq_map) |
Nishanth Menon | 3c44d51 | 2014-06-26 12:40:28 +0530 | [diff] [blame] | 227 | goto err_base; |
Sricharan R | 96ca848 | 2013-12-03 15:57:23 +0530 | [diff] [blame] | 228 | |
| 229 | cb->int_max = max; |
| 230 | |
| 231 | for (i = 0; i < max; i++) |
| 232 | cb->irq_map[i] = IRQ_FREE; |
| 233 | |
| 234 | /* Get and mark reserved irqs */ |
| 235 | irqsr = of_get_property(node, "ti,irqs-reserved", &size); |
| 236 | if (irqsr) { |
| 237 | size /= sizeof(__be32); |
| 238 | |
| 239 | for (i = 0; i < size; i++) { |
| 240 | of_property_read_u32_index(node, |
| 241 | "ti,irqs-reserved", |
| 242 | i, &entry); |
Dan Carpenter | 702f7e3 | 2014-08-07 18:28:21 +0300 | [diff] [blame] | 243 | if (entry >= max) { |
Sricharan R | 96ca848 | 2013-12-03 15:57:23 +0530 | [diff] [blame] | 244 | pr_err("Invalid reserved entry\n"); |
Nishanth Menon | edb442d | 2014-06-26 12:40:27 +0530 | [diff] [blame] | 245 | ret = -EINVAL; |
Nishanth Menon | 3c44d51 | 2014-06-26 12:40:28 +0530 | [diff] [blame] | 246 | goto err_irq_map; |
Sricharan R | 96ca848 | 2013-12-03 15:57:23 +0530 | [diff] [blame] | 247 | } |
Nishanth Menon | 1d50d2c | 2014-06-26 12:40:19 +0530 | [diff] [blame] | 248 | cb->irq_map[entry] = IRQ_RESERVED; |
Sricharan R | 96ca848 | 2013-12-03 15:57:23 +0530 | [diff] [blame] | 249 | } |
| 250 | } |
| 251 | |
Nishanth Menon | 64e0f8b | 2014-06-26 12:40:21 +0530 | [diff] [blame] | 252 | /* Skip irqs hardwired to bypass the crossbar */ |
| 253 | irqsr = of_get_property(node, "ti,irqs-skip", &size); |
| 254 | if (irqsr) { |
| 255 | size /= sizeof(__be32); |
| 256 | |
| 257 | for (i = 0; i < size; i++) { |
| 258 | of_property_read_u32_index(node, |
| 259 | "ti,irqs-skip", |
| 260 | i, &entry); |
Dan Carpenter | 702f7e3 | 2014-08-07 18:28:21 +0300 | [diff] [blame] | 261 | if (entry >= max) { |
Nishanth Menon | 64e0f8b | 2014-06-26 12:40:21 +0530 | [diff] [blame] | 262 | pr_err("Invalid skip entry\n"); |
| 263 | ret = -EINVAL; |
Nishanth Menon | 3c44d51 | 2014-06-26 12:40:28 +0530 | [diff] [blame] | 264 | goto err_irq_map; |
Nishanth Menon | 64e0f8b | 2014-06-26 12:40:21 +0530 | [diff] [blame] | 265 | } |
| 266 | cb->irq_map[entry] = IRQ_SKIP; |
| 267 | } |
| 268 | } |
| 269 | |
| 270 | |
Nishanth Menon | 4dbf45e | 2014-06-26 12:40:25 +0530 | [diff] [blame] | 271 | cb->register_offsets = kcalloc(max, sizeof(int), GFP_KERNEL); |
Sricharan R | 96ca848 | 2013-12-03 15:57:23 +0530 | [diff] [blame] | 272 | if (!cb->register_offsets) |
Nishanth Menon | 3c44d51 | 2014-06-26 12:40:28 +0530 | [diff] [blame] | 273 | goto err_irq_map; |
Sricharan R | 96ca848 | 2013-12-03 15:57:23 +0530 | [diff] [blame] | 274 | |
Franck Demathieu | 4b9de5d | 2017-03-06 14:41:06 +0100 | [diff] [blame] | 275 | of_property_read_u32(node, "ti,reg-size", ®_size); |
Sricharan R | 96ca848 | 2013-12-03 15:57:23 +0530 | [diff] [blame] | 276 | |
Franck Demathieu | 4b9de5d | 2017-03-06 14:41:06 +0100 | [diff] [blame] | 277 | switch (reg_size) { |
Sricharan R | 96ca848 | 2013-12-03 15:57:23 +0530 | [diff] [blame] | 278 | case 1: |
| 279 | cb->write = crossbar_writeb; |
| 280 | break; |
| 281 | case 2: |
| 282 | cb->write = crossbar_writew; |
| 283 | break; |
| 284 | case 4: |
| 285 | cb->write = crossbar_writel; |
| 286 | break; |
| 287 | default: |
| 288 | pr_err("Invalid reg-size property\n"); |
Nishanth Menon | edb442d | 2014-06-26 12:40:27 +0530 | [diff] [blame] | 289 | ret = -EINVAL; |
Nishanth Menon | 3c44d51 | 2014-06-26 12:40:28 +0530 | [diff] [blame] | 290 | goto err_reg_offset; |
Sricharan R | 96ca848 | 2013-12-03 15:57:23 +0530 | [diff] [blame] | 291 | break; |
| 292 | } |
| 293 | |
| 294 | /* |
| 295 | * Register offsets are not linear because of the |
| 296 | * reserved irqs. so find and store the offsets once. |
| 297 | */ |
| 298 | for (i = 0; i < max; i++) { |
Nishanth Menon | 1d50d2c | 2014-06-26 12:40:19 +0530 | [diff] [blame] | 299 | if (cb->irq_map[i] == IRQ_RESERVED) |
Sricharan R | 96ca848 | 2013-12-03 15:57:23 +0530 | [diff] [blame] | 300 | continue; |
| 301 | |
| 302 | cb->register_offsets[i] = reserved; |
Franck Demathieu | 4b9de5d | 2017-03-06 14:41:06 +0100 | [diff] [blame] | 303 | reserved += reg_size; |
Sricharan R | 96ca848 | 2013-12-03 15:57:23 +0530 | [diff] [blame] | 304 | } |
| 305 | |
Nishanth Menon | a35057d | 2014-06-26 12:40:22 +0530 | [diff] [blame] | 306 | of_property_read_u32(node, "ti,irqs-safe-map", &cb->safe_map); |
Nishanth Menon | a35057d | 2014-06-26 12:40:22 +0530 | [diff] [blame] | 307 | /* Initialize the crossbar with safe map to start with */ |
| 308 | for (i = 0; i < max; i++) { |
| 309 | if (cb->irq_map[i] == IRQ_RESERVED || |
| 310 | cb->irq_map[i] == IRQ_SKIP) |
| 311 | continue; |
| 312 | |
| 313 | cb->write(i, cb->safe_map); |
| 314 | } |
| 315 | |
Marc Zyngier | 783d318 | 2015-03-11 15:43:44 +0000 | [diff] [blame] | 316 | raw_spin_lock_init(&cb->lock); |
| 317 | |
Sricharan R | 96ca848 | 2013-12-03 15:57:23 +0530 | [diff] [blame] | 318 | return 0; |
| 319 | |
Nishanth Menon | 3c44d51 | 2014-06-26 12:40:28 +0530 | [diff] [blame] | 320 | err_reg_offset: |
Sricharan R | 96ca848 | 2013-12-03 15:57:23 +0530 | [diff] [blame] | 321 | kfree(cb->register_offsets); |
Nishanth Menon | 3c44d51 | 2014-06-26 12:40:28 +0530 | [diff] [blame] | 322 | err_irq_map: |
Sricharan R | 96ca848 | 2013-12-03 15:57:23 +0530 | [diff] [blame] | 323 | kfree(cb->irq_map); |
Nishanth Menon | 3c44d51 | 2014-06-26 12:40:28 +0530 | [diff] [blame] | 324 | err_base: |
Sricharan R | 96ca848 | 2013-12-03 15:57:23 +0530 | [diff] [blame] | 325 | iounmap(cb->crossbar_base); |
Nishanth Menon | 3c44d51 | 2014-06-26 12:40:28 +0530 | [diff] [blame] | 326 | err_cb: |
Sricharan R | 96ca848 | 2013-12-03 15:57:23 +0530 | [diff] [blame] | 327 | kfree(cb); |
Sricharan R | 99e37d0e | 2014-06-26 12:40:29 +0530 | [diff] [blame] | 328 | |
| 329 | cb = NULL; |
Nishanth Menon | edb442d | 2014-06-26 12:40:27 +0530 | [diff] [blame] | 330 | return ret; |
Sricharan R | 96ca848 | 2013-12-03 15:57:23 +0530 | [diff] [blame] | 331 | } |
| 332 | |
Marc Zyngier | 783d318 | 2015-03-11 15:43:44 +0000 | [diff] [blame] | 333 | static int __init irqcrossbar_init(struct device_node *node, |
| 334 | struct device_node *parent) |
Sricharan R | 96ca848 | 2013-12-03 15:57:23 +0530 | [diff] [blame] | 335 | { |
Marc Zyngier | 783d318 | 2015-03-11 15:43:44 +0000 | [diff] [blame] | 336 | struct irq_domain *parent_domain, *domain; |
| 337 | int err; |
Sricharan R | 96ca848 | 2013-12-03 15:57:23 +0530 | [diff] [blame] | 338 | |
Marc Zyngier | 783d318 | 2015-03-11 15:43:44 +0000 | [diff] [blame] | 339 | if (!parent) { |
Rob Herring | e81f54c | 2017-07-18 16:43:10 -0500 | [diff] [blame] | 340 | pr_err("%pOF: no parent, giving up\n", node); |
Marc Zyngier | 783d318 | 2015-03-11 15:43:44 +0000 | [diff] [blame] | 341 | return -ENODEV; |
| 342 | } |
| 343 | |
| 344 | parent_domain = irq_find_host(parent); |
| 345 | if (!parent_domain) { |
Rob Herring | e81f54c | 2017-07-18 16:43:10 -0500 | [diff] [blame] | 346 | pr_err("%pOF: unable to obtain parent domain\n", node); |
Marc Zyngier | 783d318 | 2015-03-11 15:43:44 +0000 | [diff] [blame] | 347 | return -ENXIO; |
| 348 | } |
| 349 | |
| 350 | err = crossbar_of_init(node); |
| 351 | if (err) |
| 352 | return err; |
| 353 | |
| 354 | domain = irq_domain_add_hierarchy(parent_domain, 0, |
| 355 | cb->max_crossbar_sources, |
| 356 | node, &crossbar_domain_ops, |
| 357 | NULL); |
| 358 | if (!domain) { |
Rob Herring | e81f54c | 2017-07-18 16:43:10 -0500 | [diff] [blame] | 359 | pr_err("%pOF: failed to allocated domain\n", node); |
Marc Zyngier | 783d318 | 2015-03-11 15:43:44 +0000 | [diff] [blame] | 360 | return -ENOMEM; |
| 361 | } |
| 362 | |
Sricharan R | 96ca848 | 2013-12-03 15:57:23 +0530 | [diff] [blame] | 363 | return 0; |
| 364 | } |
Marc Zyngier | 783d318 | 2015-03-11 15:43:44 +0000 | [diff] [blame] | 365 | |
| 366 | IRQCHIP_DECLARE(ti_irqcrossbar, "ti,irq-crossbar", irqcrossbar_init); |