Lines Matching +full:pruss +full:- +full:intc

1 // SPDX-License-Identifier: GPL-2.0-only
3 * PRU-ICSS INTC IRQChip driver for various TI SoCs
5 * Copyright (C) 2016-2020 Texas Instruments Incorporated - http://www.ti.com/
9 * Suman Anna <s-anna@ti.com>
24 * Number of host interrupts reaching the main MPU sub-system. Note that this
25 * is not the same as the total number of host interrupts supported by the PRUSS
26 * INTC instance
57 /* CMR register bit-field macros */
62 /* HMR register bit-field macros */
67 /* HIPIR register bit-fields */
74 * struct pruss_intc_map_record - keeps track of actual mapping state
84 * struct pruss_intc_match_data - match data to handle SoC variations
85 * @num_system_events: number of input system events handled by the PRUSS INTC
87 * channels) supported by the PRUSS INTC
95 * struct pruss_intc - PRUSS interrupt controller structure
98 * @irqs: kernel irq numbers corresponding to PRUSS host interrupts
99 * @base: base virtual address of INTC register space
101 * @soc_config: cached PRUSS INTC IP configuration data
102 * @dev: PRUSS INTC device pointer
113 struct mutex lock; /* PRUSS INTC lock */
117 * struct pruss_host_irq_data - PRUSS host irq data structure
118 * @intc: PRUSS interrupt controller pointer
122 struct pruss_intc *intc; member
126 static inline u32 pruss_intc_read_reg(struct pruss_intc *intc, unsigned int reg) in pruss_intc_read_reg() argument
128 return readl_relaxed(intc->base + reg); in pruss_intc_read_reg()
131 static inline void pruss_intc_write_reg(struct pruss_intc *intc, in pruss_intc_write_reg() argument
134 writel_relaxed(val, intc->base + reg); in pruss_intc_write_reg()
137 static void pruss_intc_update_cmr(struct pruss_intc *intc, unsigned int evt, in pruss_intc_update_cmr() argument
145 val = pruss_intc_read_reg(intc, PRU_INTC_CMR(idx)); in pruss_intc_update_cmr()
148 pruss_intc_write_reg(intc, PRU_INTC_CMR(idx), val); in pruss_intc_update_cmr()
150 dev_dbg(intc->dev, "SYSEV%u -> CH%d (CMR%d 0x%08x)\n", evt, ch, in pruss_intc_update_cmr()
151 idx, pruss_intc_read_reg(intc, PRU_INTC_CMR(idx))); in pruss_intc_update_cmr()
154 static void pruss_intc_update_hmr(struct pruss_intc *intc, u8 ch, u8 host) in pruss_intc_update_hmr() argument
161 val = pruss_intc_read_reg(intc, PRU_INTC_HMR(idx)); in pruss_intc_update_hmr()
164 pruss_intc_write_reg(intc, PRU_INTC_HMR(idx), val); in pruss_intc_update_hmr()
166 dev_dbg(intc->dev, "CH%d -> HOST%d (HMR%d 0x%08x)\n", ch, host, idx, in pruss_intc_update_hmr()
167 pruss_intc_read_reg(intc, PRU_INTC_HMR(idx))); in pruss_intc_update_hmr()
171 * pruss_intc_map() - configure the PRUSS INTC
172 * @intc: PRUSS interrupt controller pointer
175 * Configures the PRUSS INTC with the provided configuration from the one parsed
178 static void pruss_intc_map(struct pruss_intc *intc, unsigned long hwirq) in pruss_intc_map() argument
180 struct device *dev = intc->dev; in pruss_intc_map()
184 mutex_lock(&intc->lock); in pruss_intc_map()
186 intc->event_channel[hwirq].ref_count++; in pruss_intc_map()
188 ch = intc->event_channel[hwirq].value; in pruss_intc_map()
189 host = intc->channel_host[ch].value; in pruss_intc_map()
191 pruss_intc_update_cmr(intc, hwirq, ch); in pruss_intc_map()
197 pruss_intc_write_reg(intc, PRU_INTC_ESR(reg_idx), val); in pruss_intc_map()
198 pruss_intc_write_reg(intc, PRU_INTC_SECR(reg_idx), val); in pruss_intc_map()
200 if (++intc->channel_host[ch].ref_count == 1) { in pruss_intc_map()
201 pruss_intc_update_hmr(intc, ch, host); in pruss_intc_map()
204 pruss_intc_write_reg(intc, PRU_INTC_HIEISR, host); in pruss_intc_map()
210 mutex_unlock(&intc->lock); in pruss_intc_map()
214 * pruss_intc_unmap() - unconfigure the PRUSS INTC
215 * @intc: PRUSS interrupt controller pointer
222 static void pruss_intc_unmap(struct pruss_intc *intc, unsigned long hwirq) in pruss_intc_unmap() argument
227 mutex_lock(&intc->lock); in pruss_intc_unmap()
229 ch = intc->event_channel[hwirq].value; in pruss_intc_unmap()
230 host = intc->channel_host[ch].value; in pruss_intc_unmap()
232 if (--intc->channel_host[ch].ref_count == 0) { in pruss_intc_unmap()
234 pruss_intc_write_reg(intc, PRU_INTC_HIDISR, host); in pruss_intc_unmap()
237 pruss_intc_update_hmr(intc, ch, 0); in pruss_intc_unmap()
240 intc->event_channel[hwirq].ref_count--; in pruss_intc_unmap()
245 pruss_intc_write_reg(intc, PRU_INTC_ECR(reg_idx), val); in pruss_intc_unmap()
247 pruss_intc_write_reg(intc, PRU_INTC_SECR(reg_idx), val); in pruss_intc_unmap()
250 pruss_intc_update_cmr(intc, hwirq, 0); in pruss_intc_unmap()
252 dev_dbg(intc->dev, "unmapped system_event = %lu channel = %d host = %d\n", in pruss_intc_unmap()
255 mutex_unlock(&intc->lock); in pruss_intc_unmap()
258 static void pruss_intc_init(struct pruss_intc *intc) in pruss_intc_init() argument
260 const struct pruss_intc_match_data *soc_config = intc->soc_config; in pruss_intc_init()
263 num_chnl_map_regs = DIV_ROUND_UP(soc_config->num_system_events, in pruss_intc_init()
265 num_host_intr_regs = DIV_ROUND_UP(soc_config->num_host_events, in pruss_intc_init()
267 num_event_type_regs = DIV_ROUND_UP(soc_config->num_system_events, 32); in pruss_intc_init()
274 pruss_intc_write_reg(intc, PRU_INTC_SIPR(i), 0xffffffff); in pruss_intc_init()
275 pruss_intc_write_reg(intc, PRU_INTC_SITR(i), 0); in pruss_intc_init()
280 pruss_intc_write_reg(intc, PRU_INTC_CMR(i), 0); in pruss_intc_init()
284 pruss_intc_write_reg(intc, PRU_INTC_HMR(i), 0); in pruss_intc_init()
287 pruss_intc_write_reg(intc, PRU_INTC_GER, 1); in pruss_intc_init()
292 struct pruss_intc *intc = irq_data_get_irq_chip_data(data); in pruss_intc_irq_ack() local
293 unsigned int hwirq = data->hwirq; in pruss_intc_irq_ack()
295 pruss_intc_write_reg(intc, PRU_INTC_SICR, hwirq); in pruss_intc_irq_ack()
300 struct pruss_intc *intc = irq_data_get_irq_chip_data(data); in pruss_intc_irq_mask() local
301 unsigned int hwirq = data->hwirq; in pruss_intc_irq_mask()
303 pruss_intc_write_reg(intc, PRU_INTC_EICR, hwirq); in pruss_intc_irq_mask()
308 struct pruss_intc *intc = irq_data_get_irq_chip_data(data); in pruss_intc_irq_unmask() local
309 unsigned int hwirq = data->hwirq; in pruss_intc_irq_unmask()
311 pruss_intc_write_reg(intc, PRU_INTC_EISR, hwirq); in pruss_intc_irq_unmask()
317 return -ENODEV; in pruss_intc_irq_reqres()
331 struct pruss_intc *intc = irq_data_get_irq_chip_data(data); in pruss_intc_irq_get_irqchip_state() local
335 return -EINVAL; in pruss_intc_irq_get_irqchip_state()
337 reg = PRU_INTC_SRSR(data->hwirq / 32); in pruss_intc_irq_get_irqchip_state()
338 mask = BIT(data->hwirq % 32); in pruss_intc_irq_get_irqchip_state()
340 srsr = pruss_intc_read_reg(intc, reg); in pruss_intc_irq_get_irqchip_state()
351 struct pruss_intc *intc = irq_data_get_irq_chip_data(data); in pruss_intc_irq_set_irqchip_state() local
354 return -EINVAL; in pruss_intc_irq_set_irqchip_state()
357 pruss_intc_write_reg(intc, PRU_INTC_SISR, data->hwirq); in pruss_intc_irq_set_irqchip_state()
359 pruss_intc_write_reg(intc, PRU_INTC_SICR, data->hwirq); in pruss_intc_irq_set_irqchip_state()
365 .name = "pruss-intc",
375 static int pruss_intc_validate_mapping(struct pruss_intc *intc, int event, in pruss_intc_validate_mapping() argument
378 struct device *dev = intc->dev; in pruss_intc_validate_mapping()
381 mutex_lock(&intc->lock); in pruss_intc_validate_mapping()
384 if (intc->event_channel[event].ref_count > 0 && in pruss_intc_validate_mapping()
385 intc->event_channel[event].value != channel) { in pruss_intc_validate_mapping()
387 event, channel, intc->event_channel[event].value); in pruss_intc_validate_mapping()
388 ret = -EBUSY; in pruss_intc_validate_mapping()
393 if (intc->channel_host[channel].ref_count > 0 && in pruss_intc_validate_mapping()
394 intc->channel_host[channel].value != host) { in pruss_intc_validate_mapping()
396 channel, host, intc->channel_host[channel].value); in pruss_intc_validate_mapping()
397 ret = -EBUSY; in pruss_intc_validate_mapping()
401 intc->event_channel[event].value = channel; in pruss_intc_validate_mapping()
402 intc->channel_host[channel].value = host; in pruss_intc_validate_mapping()
405 mutex_unlock(&intc->lock); in pruss_intc_validate_mapping()
414 struct pruss_intc *intc = d->host_data; in pruss_intc_irq_domain_xlate() local
415 struct device *dev = intc->dev; in pruss_intc_irq_domain_xlate()
419 return -EINVAL; in pruss_intc_irq_domain_xlate()
422 if (sys_event < 0 || sys_event >= intc->soc_config->num_system_events) { in pruss_intc_irq_domain_xlate()
424 return -EINVAL; in pruss_intc_irq_domain_xlate()
428 if (channel < 0 || channel >= intc->soc_config->num_host_events) { in pruss_intc_irq_domain_xlate()
430 return -EINVAL; in pruss_intc_irq_domain_xlate()
434 if (host < 0 || host >= intc->soc_config->num_host_events) { in pruss_intc_irq_domain_xlate()
436 return -EINVAL; in pruss_intc_irq_domain_xlate()
440 ret = pruss_intc_validate_mapping(intc, sys_event, channel, host); in pruss_intc_irq_domain_xlate()
453 struct pruss_intc *intc = d->host_data; in pruss_intc_irq_domain_map() local
455 pruss_intc_map(intc, hw); in pruss_intc_irq_domain_map()
457 irq_set_chip_data(virq, intc); in pruss_intc_irq_domain_map()
465 struct pruss_intc *intc = d->host_data; in pruss_intc_irq_domain_unmap() local
470 pruss_intc_unmap(intc, hwirq); in pruss_intc_irq_domain_unmap()
484 struct pruss_intc *intc = host_irq_data->intc; in pruss_intc_irq_handler() local
485 u8 host_irq = host_irq_data->host_irq + FIRST_PRU_HOST_INT; in pruss_intc_irq_handler()
494 /* get highest priority pending PRUSS system event */ in pruss_intc_irq_handler()
495 hipir = pruss_intc_read_reg(intc, PRU_INTC_HIPIR(host_irq)); in pruss_intc_irq_handler()
500 virq = irq_find_mapping(intc->domain, hwirq); in pruss_intc_irq_handler()
507 pruss_intc_write_reg(intc, PRU_INTC_SICR, hwirq); in pruss_intc_irq_handler()
523 struct device *dev = &pdev->dev; in pruss_intc_probe()
524 struct pruss_intc *intc; in pruss_intc_probe() local
531 return -ENODEV; in pruss_intc_probe()
533 max_system_events = data->num_system_events; in pruss_intc_probe()
535 intc = devm_kzalloc(dev, sizeof(*intc), GFP_KERNEL); in pruss_intc_probe()
536 if (!intc) in pruss_intc_probe()
537 return -ENOMEM; in pruss_intc_probe()
539 intc->soc_config = data; in pruss_intc_probe()
540 intc->dev = dev; in pruss_intc_probe()
541 platform_set_drvdata(pdev, intc); in pruss_intc_probe()
543 intc->base = devm_platform_ioremap_resource(pdev, 0); in pruss_intc_probe()
544 if (IS_ERR(intc->base)) in pruss_intc_probe()
545 return PTR_ERR(intc->base); in pruss_intc_probe()
547 ret = of_property_read_u8(dev->of_node, "ti,irqs-reserved", in pruss_intc_probe()
551 * The irqs-reserved is used only for some SoC's therefore not having in pruss_intc_probe()
554 if (ret < 0 && ret != -EINVAL) in pruss_intc_probe()
557 pruss_intc_init(intc); in pruss_intc_probe()
559 mutex_init(&intc->lock); in pruss_intc_probe()
561 intc->domain = irq_domain_add_linear(dev->of_node, max_system_events, in pruss_intc_probe()
562 &pruss_intc_irq_domain_ops, intc); in pruss_intc_probe()
563 if (!intc->domain) in pruss_intc_probe()
564 return -ENOMEM; in pruss_intc_probe()
572 ret = (irq == 0) ? -EINVAL : irq; in pruss_intc_probe()
576 intc->irqs[i] = irq; in pruss_intc_probe()
580 ret = -ENOMEM; in pruss_intc_probe()
584 host_data->intc = intc; in pruss_intc_probe()
585 host_data->host_irq = i; in pruss_intc_probe()
594 while (--i >= 0) { in pruss_intc_probe()
595 if (intc->irqs[i]) in pruss_intc_probe()
596 irq_set_chained_handler_and_data(intc->irqs[i], NULL, in pruss_intc_probe()
600 irq_domain_remove(intc->domain); in pruss_intc_probe()
607 struct pruss_intc *intc = platform_get_drvdata(pdev); in pruss_intc_remove() local
608 u8 max_system_events = intc->soc_config->num_system_events; in pruss_intc_remove()
613 if (intc->irqs[i]) in pruss_intc_remove()
614 irq_set_chained_handler_and_data(intc->irqs[i], NULL, in pruss_intc_remove()
619 irq_dispose_mapping(irq_find_mapping(intc->domain, hwirq)); in pruss_intc_remove()
621 irq_domain_remove(intc->domain); in pruss_intc_remove()
638 .compatible = "ti,pruss-intc",
642 .compatible = "ti,icssg-intc",
651 .name = "pruss-intc",
661 MODULE_AUTHOR("Suman Anna <s-anna@ti.com>");
663 MODULE_DESCRIPTION("TI PRU-ICSS INTC Driver");