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