|
23 | 23 | #endif
|
24 | 24 |
|
25 | 25 | #define LIOINTC_CHIP_IRQ 32
|
26 |
| -#define LIOINTC_NUM_PARENT 4 |
| 26 | +#define LIOINTC_NUM_PARENT 4 |
27 | 27 | #define LIOINTC_NUM_CORES 4
|
28 | 28 |
|
29 | 29 | #define LIOINTC_INTC_CHIP_START 0x20
|
@@ -58,6 +58,8 @@ struct liointc_priv {
|
58 | 58 | bool has_lpc_irq_errata;
|
59 | 59 | };
|
60 | 60 |
|
| 61 | +struct fwnode_handle *liointc_handle; |
| 62 | + |
61 | 63 | static void liointc_chained_handle_irq(struct irq_desc *desc)
|
62 | 64 | {
|
63 | 65 | struct liointc_handler_data *handler = irq_desc_get_handler_data(desc);
|
@@ -153,97 +155,79 @@ static void liointc_resume(struct irq_chip_generic *gc)
|
153 | 155 | irq_gc_unlock_irqrestore(gc, flags);
|
154 | 156 | }
|
155 | 157 |
|
156 |
| -static const char * const parent_names[] = {"int0", "int1", "int2", "int3"}; |
157 |
| -static const char * const core_reg_names[] = {"isr0", "isr1", "isr2", "isr3"}; |
| 158 | +static int parent_irq[LIOINTC_NUM_PARENT]; |
| 159 | +static u32 parent_int_map[LIOINTC_NUM_PARENT]; |
| 160 | +static const char *const parent_names[] = {"int0", "int1", "int2", "int3"}; |
| 161 | +static const char *const core_reg_names[] = {"isr0", "isr1", "isr2", "isr3"}; |
158 | 162 |
|
159 |
| -static void __iomem *liointc_get_reg_byname(struct device_node *node, |
160 |
| - const char *name) |
| 163 | +static int liointc_domain_xlate(struct irq_domain *d, struct device_node *ctrlr, |
| 164 | + const u32 *intspec, unsigned int intsize, |
| 165 | + unsigned long *out_hwirq, unsigned int *out_type) |
161 | 166 | {
|
162 |
| - int index = of_property_match_string(node, "reg-names", name); |
163 |
| - |
164 |
| - if (index < 0) |
165 |
| - return NULL; |
166 |
| - |
167 |
| - return of_iomap(node, index); |
| 167 | + if (WARN_ON(intsize < 1)) |
| 168 | + return -EINVAL; |
| 169 | + *out_hwirq = intspec[0] - GSI_MIN_CPU_IRQ; |
| 170 | + *out_type = IRQ_TYPE_NONE; |
| 171 | + return 0; |
168 | 172 | }
|
169 | 173 |
|
170 |
| -static int __init liointc_of_init(struct device_node *node, |
171 |
| - struct device_node *parent) |
| 174 | +static const struct irq_domain_ops acpi_irq_gc_ops = { |
| 175 | + .map = irq_map_generic_chip, |
| 176 | + .unmap = irq_unmap_generic_chip, |
| 177 | + .xlate = liointc_domain_xlate, |
| 178 | +}; |
| 179 | + |
| 180 | +static int liointc_init(phys_addr_t addr, unsigned long size, int revision, |
| 181 | + struct fwnode_handle *domain_handle, struct device_node *node) |
172 | 182 | {
|
| 183 | + int i, err; |
| 184 | + void __iomem *base; |
| 185 | + struct irq_chip_type *ct; |
173 | 186 | struct irq_chip_generic *gc;
|
174 | 187 | struct irq_domain *domain;
|
175 |
| - struct irq_chip_type *ct; |
176 | 188 | struct liointc_priv *priv;
|
177 |
| - void __iomem *base; |
178 |
| - u32 of_parent_int_map[LIOINTC_NUM_PARENT]; |
179 |
| - int parent_irq[LIOINTC_NUM_PARENT]; |
180 |
| - bool have_parent = FALSE; |
181 |
| - int sz, i, err = 0; |
182 | 189 |
|
183 | 190 | priv = kzalloc(sizeof(*priv), GFP_KERNEL);
|
184 | 191 | if (!priv)
|
185 | 192 | return -ENOMEM;
|
186 | 193 |
|
187 |
| - if (of_device_is_compatible(node, "loongson,liointc-2.0")) { |
188 |
| - base = liointc_get_reg_byname(node, "main"); |
189 |
| - if (!base) { |
190 |
| - err = -ENODEV; |
191 |
| - goto out_free_priv; |
192 |
| - } |
| 194 | + base = ioremap(addr, size); |
| 195 | + if (!base) |
| 196 | + goto out_free_priv; |
193 | 197 |
|
194 |
| - for (i = 0; i < LIOINTC_NUM_CORES; i++) |
195 |
| - priv->core_isr[i] = liointc_get_reg_byname(node, core_reg_names[i]); |
196 |
| - if (!priv->core_isr[0]) { |
197 |
| - err = -ENODEV; |
198 |
| - goto out_iounmap_base; |
199 |
| - } |
200 |
| - } else { |
201 |
| - base = of_iomap(node, 0); |
202 |
| - if (!base) { |
203 |
| - err = -ENODEV; |
204 |
| - goto out_free_priv; |
205 |
| - } |
| 198 | + for (i = 0; i < LIOINTC_NUM_CORES; i++) |
| 199 | + priv->core_isr[i] = base + LIOINTC_REG_INTC_STATUS; |
206 | 200 |
|
207 |
| - for (i = 0; i < LIOINTC_NUM_CORES; i++) |
208 |
| - priv->core_isr[i] = base + LIOINTC_REG_INTC_STATUS; |
209 |
| - } |
| 201 | + for (i = 0; i < LIOINTC_NUM_PARENT; i++) |
| 202 | + priv->handler[i].parent_int_map = parent_int_map[i]; |
210 | 203 |
|
211 |
| - for (i = 0; i < LIOINTC_NUM_PARENT; i++) { |
212 |
| - parent_irq[i] = of_irq_get_byname(node, parent_names[i]); |
213 |
| - if (parent_irq[i] > 0) |
214 |
| - have_parent = TRUE; |
215 |
| - } |
216 |
| - if (!have_parent) { |
217 |
| - err = -ENODEV; |
218 |
| - goto out_iounmap_isr; |
219 |
| - } |
| 204 | + if (revision > 1) { |
| 205 | + for (i = 0; i < LIOINTC_NUM_CORES; i++) { |
| 206 | + int index = of_property_match_string(node, |
| 207 | + "reg-names", core_reg_names[i]); |
220 | 208 |
|
221 |
| - sz = of_property_read_variable_u32_array(node, |
222 |
| - "loongson,parent_int_map", |
223 |
| - &of_parent_int_map[0], |
224 |
| - LIOINTC_NUM_PARENT, |
225 |
| - LIOINTC_NUM_PARENT); |
226 |
| - if (sz < 4) { |
227 |
| - pr_err("loongson-liointc: No parent_int_map\n"); |
228 |
| - err = -ENODEV; |
229 |
| - goto out_iounmap_isr; |
230 |
| - } |
| 209 | + if (index < 0) |
| 210 | + return -EINVAL; |
231 | 211 |
|
232 |
| - for (i = 0; i < LIOINTC_NUM_PARENT; i++) |
233 |
| - priv->handler[i].parent_int_map = of_parent_int_map[i]; |
| 212 | + priv->core_isr[i] = of_iomap(node, index); |
| 213 | + } |
| 214 | + } |
234 | 215 |
|
235 | 216 | /* Setup IRQ domain */
|
236 |
| - domain = irq_domain_add_linear(node, 32, |
| 217 | + if (!acpi_disabled) |
| 218 | + domain = irq_domain_create_linear(domain_handle, LIOINTC_CHIP_IRQ, |
| 219 | + &acpi_irq_gc_ops, priv); |
| 220 | + else |
| 221 | + domain = irq_domain_create_linear(domain_handle, LIOINTC_CHIP_IRQ, |
237 | 222 | &irq_generic_chip_ops, priv);
|
238 | 223 | if (!domain) {
|
239 | 224 | pr_err("loongson-liointc: cannot add IRQ domain\n");
|
240 |
| - err = -EINVAL; |
241 |
| - goto out_iounmap_isr; |
| 225 | + goto out_iounmap; |
242 | 226 | }
|
243 | 227 |
|
244 |
| - err = irq_alloc_domain_generic_chips(domain, 32, 1, |
245 |
| - node->full_name, handle_level_irq, |
246 |
| - IRQ_NOPROBE, 0, 0); |
| 228 | + err = irq_alloc_domain_generic_chips(domain, LIOINTC_CHIP_IRQ, 1, |
| 229 | + (node ? node->full_name : "LIOINTC"), |
| 230 | + handle_level_irq, 0, IRQ_NOPROBE, 0); |
247 | 231 | if (err) {
|
248 | 232 | pr_err("loongson-liointc: unable to register IRQ domain\n");
|
249 | 233 | goto out_free_domain;
|
@@ -299,24 +283,93 @@ static int __init liointc_of_init(struct device_node *node,
|
299 | 283 | liointc_chained_handle_irq, &priv->handler[i]);
|
300 | 284 | }
|
301 | 285 |
|
| 286 | + liointc_handle = domain_handle; |
302 | 287 | return 0;
|
303 | 288 |
|
304 | 289 | out_free_domain:
|
305 | 290 | irq_domain_remove(domain);
|
306 |
| -out_iounmap_isr: |
307 |
| - for (i = 0; i < LIOINTC_NUM_CORES; i++) { |
308 |
| - if (!priv->core_isr[i]) |
309 |
| - continue; |
310 |
| - iounmap(priv->core_isr[i]); |
311 |
| - } |
312 |
| -out_iounmap_base: |
| 291 | +out_iounmap: |
313 | 292 | iounmap(base);
|
314 | 293 | out_free_priv:
|
315 | 294 | kfree(priv);
|
316 | 295 |
|
317 |
| - return err; |
| 296 | + return -EINVAL; |
| 297 | +} |
| 298 | + |
| 299 | +#ifdef CONFIG_OF |
| 300 | + |
| 301 | +static int __init liointc_of_init(struct device_node *node, |
| 302 | + struct device_node *parent) |
| 303 | +{ |
| 304 | + bool have_parent = FALSE; |
| 305 | + int sz, i, index, revision, err = 0; |
| 306 | + struct resource res; |
| 307 | + |
| 308 | + if (!of_device_is_compatible(node, "loongson,liointc-2.0")) { |
| 309 | + index = 0; |
| 310 | + revision = 1; |
| 311 | + } else { |
| 312 | + index = of_property_match_string(node, "reg-names", "main"); |
| 313 | + revision = 2; |
| 314 | + } |
| 315 | + |
| 316 | + if (of_address_to_resource(node, index, &res)) |
| 317 | + return -EINVAL; |
| 318 | + |
| 319 | + for (i = 0; i < LIOINTC_NUM_PARENT; i++) { |
| 320 | + parent_irq[i] = of_irq_get_byname(node, parent_names[i]); |
| 321 | + if (parent_irq[i] > 0) |
| 322 | + have_parent = TRUE; |
| 323 | + } |
| 324 | + if (!have_parent) |
| 325 | + return -ENODEV; |
| 326 | + |
| 327 | + sz = of_property_read_variable_u32_array(node, |
| 328 | + "loongson,parent_int_map", |
| 329 | + &parent_int_map[0], |
| 330 | + LIOINTC_NUM_PARENT, |
| 331 | + LIOINTC_NUM_PARENT); |
| 332 | + if (sz < 4) { |
| 333 | + pr_err("loongson-liointc: No parent_int_map\n"); |
| 334 | + return -ENODEV; |
| 335 | + } |
| 336 | + |
| 337 | + err = liointc_init(res.start, resource_size(&res), |
| 338 | + revision, of_node_to_fwnode(node), node); |
| 339 | + if (err < 0) |
| 340 | + return err; |
| 341 | + |
| 342 | + return 0; |
318 | 343 | }
|
319 | 344 |
|
320 | 345 | IRQCHIP_DECLARE(loongson_liointc_1_0, "loongson,liointc-1.0", liointc_of_init);
|
321 | 346 | IRQCHIP_DECLARE(loongson_liointc_1_0a, "loongson,liointc-1.0a", liointc_of_init);
|
322 | 347 | IRQCHIP_DECLARE(loongson_liointc_2_0, "loongson,liointc-2.0", liointc_of_init);
|
| 348 | + |
| 349 | +#endif |
| 350 | + |
| 351 | +#ifdef CONFIG_ACPI |
| 352 | +int __init liointc_acpi_init(struct irq_domain *parent, struct acpi_madt_lio_pic *acpi_liointc) |
| 353 | +{ |
| 354 | + int ret; |
| 355 | + struct fwnode_handle *domain_handle; |
| 356 | + |
| 357 | + parent_int_map[0] = acpi_liointc->cascade_map[0]; |
| 358 | + parent_int_map[1] = acpi_liointc->cascade_map[1]; |
| 359 | + |
| 360 | + parent_irq[0] = irq_create_mapping(parent, acpi_liointc->cascade[0]); |
| 361 | + parent_irq[1] = irq_create_mapping(parent, acpi_liointc->cascade[1]); |
| 362 | + |
| 363 | + domain_handle = irq_domain_alloc_fwnode((phys_addr_t *)acpi_liointc); |
| 364 | + if (!domain_handle) { |
| 365 | + pr_err("Unable to allocate domain handle\n"); |
| 366 | + return -ENOMEM; |
| 367 | + } |
| 368 | + ret = liointc_init(acpi_liointc->address, acpi_liointc->size, |
| 369 | + 1, domain_handle, NULL); |
| 370 | + if (ret) |
| 371 | + irq_domain_free_fwnode(domain_handle); |
| 372 | + |
| 373 | + return ret; |
| 374 | +} |
| 375 | +#endif |
0 commit comments