Lines Matching +full:irq +full:- +full:syscfg

1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (C) STMicroelectronics 2018 - All Rights Reserved
8 #include <linux/arm-smccc.h>
9 #include <linux/dma-mapping.h>
99 struct stm32_rproc *ddata = rproc->priv; in stm32_rproc_pa_to_da()
102 for (i = 0; i < ddata->nb_rmems; i++) { in stm32_rproc_pa_to_da()
103 p_mem = &ddata->rmems[i]; in stm32_rproc_pa_to_da()
105 if (pa < p_mem->bus_addr || in stm32_rproc_pa_to_da()
106 pa >= p_mem->bus_addr + p_mem->size) in stm32_rproc_pa_to_da()
108 *da = pa - p_mem->bus_addr + p_mem->dev_addr; in stm32_rproc_pa_to_da()
109 dev_dbg(rproc->dev.parent, "pa %pa to da %llx\n", &pa, *da); in stm32_rproc_pa_to_da()
113 return -EINVAL; in stm32_rproc_pa_to_da()
119 struct device *dev = rproc->dev.parent; in stm32_rproc_mem_alloc()
122 dev_dbg(dev, "map memory: %pad+%zx\n", &mem->dma, mem->len); in stm32_rproc_mem_alloc()
123 va = (__force void *)ioremap_wc(mem->dma, mem->len); in stm32_rproc_mem_alloc()
126 &mem->dma, mem->len); in stm32_rproc_mem_alloc()
127 return -ENOMEM; in stm32_rproc_mem_alloc()
131 mem->va = va; in stm32_rproc_mem_alloc()
139 dev_dbg(rproc->dev.parent, "unmap memory: %pa\n", &mem->dma); in stm32_rproc_mem_release()
140 iounmap((__force __iomem void *)mem->va); in stm32_rproc_mem_release()
148 struct device *parent, *dev = &pdev->dev; in stm32_rproc_of_memory_translations()
154 parent = dev->parent; in stm32_rproc_of_memory_translations()
155 np = parent->of_node; in stm32_rproc_of_memory_translations()
157 cnt = of_property_count_elems_of_size(np, "dma-ranges", in stm32_rproc_of_memory_translations()
160 dev_err(dev, "%s: dma-ranges property not defined\n", __func__); in stm32_rproc_of_memory_translations()
161 return -EINVAL; in stm32_rproc_of_memory_translations()
166 return -ENOMEM; in stm32_rproc_of_memory_translations()
169 return -ENOMEM; in stm32_rproc_of_memory_translations()
173 ret = of_property_read_u32_array(np, "dma-ranges", in stm32_rproc_of_memory_translations()
176 dev_err(dev, "error while get dma-ranges property: %x\n", ret); in stm32_rproc_of_memory_translations()
190 ddata->rmems = p_mems; in stm32_rproc_of_memory_translations()
191 ddata->nb_rmems = cnt; in stm32_rproc_of_memory_translations()
200 struct stm32_rproc *ddata = rproc->priv; in stm32_rproc_mbox_idx()
203 for (i = 0; i < ARRAY_SIZE(ddata->mb); i++) { in stm32_rproc_mbox_idx()
204 if (!strncmp(ddata->mb[i].name, name, strlen(name))) in stm32_rproc_mbox_idx()
207 dev_err(&rproc->dev, "mailbox %s not found\n", name); in stm32_rproc_mbox_idx()
209 return -EINVAL; in stm32_rproc_mbox_idx()
214 struct device *dev = rproc->dev.parent; in stm32_rproc_prepare()
215 struct device_node *np = dev->of_node; in stm32_rproc_prepare()
223 of_phandle_iterator_init(&it, np, "memory-region", NULL, 0); in stm32_rproc_prepare()
228 dev_err(dev, "unable to acquire memory-region\n"); in stm32_rproc_prepare()
229 return -EINVAL; in stm32_rproc_prepare()
232 if (stm32_rproc_pa_to_da(rproc, rmem->base, &da) < 0) { in stm32_rproc_prepare()
235 &rmem->base); in stm32_rproc_prepare()
236 return -EINVAL; in stm32_rproc_prepare()
240 if (strcmp(it.node->name, "vdev0buffer")) { in stm32_rproc_prepare()
243 (dma_addr_t)rmem->base, in stm32_rproc_prepare()
244 rmem->size, da, in stm32_rproc_prepare()
247 it.node->name); in stm32_rproc_prepare()
251 rmem->size); in stm32_rproc_prepare()
255 rmem->size, in stm32_rproc_prepare()
256 rmem->base, in stm32_rproc_prepare()
257 it.node->name); in stm32_rproc_prepare()
262 return -ENOMEM; in stm32_rproc_prepare()
275 dev_warn(&rproc->dev, "no resource table found for this firmware\n"); in stm32_rproc_parse_fw()
280 static irqreturn_t stm32_rproc_wdg(int irq, void *data) in stm32_rproc_wdg() argument
293 struct rproc *rproc = dev_get_drvdata(mb->client.dev); in stm32_rproc_mb_vq_work()
295 mutex_lock(&rproc->lock); in stm32_rproc_mb_vq_work()
297 if (rproc->state != RPROC_RUNNING && rproc->state != RPROC_ATTACHED) in stm32_rproc_mb_vq_work()
300 if (rproc_vq_interrupt(rproc, mb->vq_id) == IRQ_NONE) in stm32_rproc_mb_vq_work()
301 dev_dbg(&rproc->dev, "no message found in vq%d\n", mb->vq_id); in stm32_rproc_mb_vq_work()
304 mutex_unlock(&rproc->lock); in stm32_rproc_mb_vq_work()
309 struct rproc *rproc = dev_get_drvdata(cl->dev); in stm32_rproc_mb_callback()
311 struct stm32_rproc *ddata = rproc->priv; in stm32_rproc_mb_callback()
313 queue_work(ddata->workqueue, &mb->vq_work); in stm32_rproc_mb_callback()
318 struct stm32_rproc *ddata = rproc->priv; in stm32_rproc_free_mbox()
321 for (i = 0; i < ARRAY_SIZE(ddata->mb); i++) { in stm32_rproc_free_mbox()
322 if (ddata->mb[i].chan) in stm32_rproc_free_mbox()
323 mbox_free_channel(ddata->mb[i].chan); in stm32_rproc_free_mbox()
324 ddata->mb[i].chan = NULL; in stm32_rproc_free_mbox()
347 .vq_id = -1,
356 .vq_id = -1,
367 struct stm32_rproc *ddata = rproc->priv; in stm32_rproc_request_mbox()
368 struct device *dev = &rproc->dev; in stm32_rproc_request_mbox()
375 memcpy(ddata->mb, stm32_rproc_mbox, sizeof(stm32_rproc_mbox)); in stm32_rproc_request_mbox()
378 name = ddata->mb[i].name; in stm32_rproc_request_mbox()
380 cl = &ddata->mb[i].client; in stm32_rproc_request_mbox()
381 cl->dev = dev->parent; in stm32_rproc_request_mbox()
383 ddata->mb[i].chan = mbox_request_channel_byname(cl, name); in stm32_rproc_request_mbox()
384 if (IS_ERR(ddata->mb[i].chan)) { in stm32_rproc_request_mbox()
385 if (PTR_ERR(ddata->mb[i].chan) == -EPROBE_DEFER) { in stm32_rproc_request_mbox()
386 dev_err_probe(dev->parent, in stm32_rproc_request_mbox()
387 PTR_ERR(ddata->mb[i].chan), in stm32_rproc_request_mbox()
393 ddata->mb[i].chan = NULL; in stm32_rproc_request_mbox()
395 if (ddata->mb[i].vq_id >= 0) { in stm32_rproc_request_mbox()
396 INIT_WORK(&ddata->mb[i].vq_work, in stm32_rproc_request_mbox()
404 for (j = i - 1; j >= 0; j--) in stm32_rproc_request_mbox()
405 if (ddata->mb[j].chan) in stm32_rproc_request_mbox()
406 mbox_free_channel(ddata->mb[j].chan); in stm32_rproc_request_mbox()
407 return -EPROBE_DEFER; in stm32_rproc_request_mbox()
412 struct stm32_rproc *ddata = rproc->priv; in stm32_rproc_set_hold_boot()
413 struct stm32_syscon hold_boot = ddata->hold_boot; in stm32_rproc_set_hold_boot()
419 * - using SCMI: the hold boot is managed as a reset, in stm32_rproc_set_hold_boot()
420 * - using Linux(no SCMI): the hold boot is managed as a syscon register in stm32_rproc_set_hold_boot()
421 * - using SMC call (deprecated): use SMC reset interface in stm32_rproc_set_hold_boot()
426 if (ddata->hold_boot_rst) { in stm32_rproc_set_hold_boot()
429 err = reset_control_deassert(ddata->hold_boot_rst); in stm32_rproc_set_hold_boot()
431 err = reset_control_assert(ddata->hold_boot_rst); in stm32_rproc_set_hold_boot()
432 } else if (IS_ENABLED(CONFIG_HAVE_ARM_SMCCC) && ddata->hold_boot_smc) { in stm32_rproc_set_hold_boot()
444 dev_err(&rproc->dev, "failed to set hold boot\n"); in stm32_rproc_set_hold_boot()
455 list_for_each_entry(trace, &rproc->traces, node) { in stm32_rproc_add_coredump_trace()
458 list_for_each_entry(segment, &rproc->dump_segments, node) { in stm32_rproc_add_coredump_trace()
459 if (segment->da == trace->trace_mem.da) { in stm32_rproc_add_coredump_trace()
466 rproc_coredump_add_segment(rproc, trace->trace_mem.da, in stm32_rproc_add_coredump_trace()
467 trace->trace_mem.len); in stm32_rproc_add_coredump_trace()
473 struct stm32_rproc *ddata = rproc->priv; in stm32_rproc_start()
479 if (ddata->pdds.map) { in stm32_rproc_start()
480 err = regmap_update_bits(ddata->pdds.map, ddata->pdds.reg, in stm32_rproc_start()
481 ddata->pdds.mask, 0); in stm32_rproc_start()
483 dev_err(&rproc->dev, "failed to clear pdds\n"); in stm32_rproc_start()
504 struct stm32_rproc *ddata = rproc->priv; in stm32_rproc_detach()
509 if (idx >= 0 && ddata->mb[idx].chan) { in stm32_rproc_detach()
510 err = mbox_send_message(ddata->mb[idx].chan, "stop"); in stm32_rproc_detach()
512 dev_warn(&rproc->dev, "warning: remote FW detach without ack\n"); in stm32_rproc_detach()
515 /* Allow remote processor to auto-reboot */ in stm32_rproc_detach()
521 struct stm32_rproc *ddata = rproc->priv; in stm32_rproc_stop()
525 if (rproc->state != RPROC_OFFLINE && rproc->state != RPROC_CRASHED) { in stm32_rproc_stop()
527 if (idx >= 0 && ddata->mb[idx].chan) { in stm32_rproc_stop()
528 err = mbox_send_message(ddata->mb[idx].chan, "detach"); in stm32_rproc_stop()
530 dev_warn(&rproc->dev, "warning: remote FW shutdown without ack\n"); in stm32_rproc_stop()
538 err = reset_control_assert(ddata->rst); in stm32_rproc_stop()
540 dev_err(&rproc->dev, "failed to assert the reset\n"); in stm32_rproc_stop()
545 if (ddata->pdds.map) { in stm32_rproc_stop()
546 err = regmap_update_bits(ddata->pdds.map, ddata->pdds.reg, in stm32_rproc_stop()
547 ddata->pdds.mask, 1); in stm32_rproc_stop()
549 dev_err(&rproc->dev, "failed to set pdds\n"); in stm32_rproc_stop()
555 if (ddata->m4_state.map) { in stm32_rproc_stop()
556 err = regmap_update_bits(ddata->m4_state.map, in stm32_rproc_stop()
557 ddata->m4_state.reg, in stm32_rproc_stop()
558 ddata->m4_state.mask, in stm32_rproc_stop()
561 dev_err(&rproc->dev, "failed to set copro state\n"); in stm32_rproc_stop()
571 struct stm32_rproc *ddata = rproc->priv; in stm32_rproc_kick()
579 if (vqid != ddata->mb[i].vq_id) in stm32_rproc_kick()
581 if (!ddata->mb[i].chan) in stm32_rproc_kick()
583 err = mbox_send_message(ddata->mb[i].chan, "kick"); in stm32_rproc_kick()
585 dev_err(&rproc->dev, "%s: failed (%s, err:%d)\n", in stm32_rproc_kick()
586 __func__, ddata->mb[i].name, err); in stm32_rproc_kick()
594 struct stm32_rproc *ddata = rproc->priv; in stm32_rproc_da_to_pa()
595 struct device *dev = rproc->dev.parent; in stm32_rproc_da_to_pa()
599 for (i = 0; i < ddata->nb_rmems; i++) { in stm32_rproc_da_to_pa()
600 p_mem = &ddata->rmems[i]; in stm32_rproc_da_to_pa()
602 if (da < p_mem->dev_addr || in stm32_rproc_da_to_pa()
603 da >= p_mem->dev_addr + p_mem->size) in stm32_rproc_da_to_pa()
606 *pa = da - p_mem->dev_addr + p_mem->bus_addr; in stm32_rproc_da_to_pa()
614 return -EINVAL; in stm32_rproc_da_to_pa()
620 struct stm32_rproc *ddata = rproc->priv; in stm32_rproc_get_loaded_rsc_table()
621 struct device *dev = rproc->dev.parent; in stm32_rproc_get_loaded_rsc_table()
627 if (ddata->rsc_va) in stm32_rproc_get_loaded_rsc_table()
630 err = regmap_read(ddata->rsctbl.map, ddata->rsctbl.reg, &rsc_da); in stm32_rproc_get_loaded_rsc_table()
633 return ERR_PTR(-EINVAL); in stm32_rproc_get_loaded_rsc_table()
638 return ERR_PTR(-ENOENT); in stm32_rproc_get_loaded_rsc_table()
644 ddata->rsc_va = devm_ioremap_wc(dev, rsc_pa, RSC_TBL_SIZE); in stm32_rproc_get_loaded_rsc_table()
645 if (IS_ERR_OR_NULL(ddata->rsc_va)) { in stm32_rproc_get_loaded_rsc_table()
648 ddata->rsc_va = NULL; in stm32_rproc_get_loaded_rsc_table()
649 return ERR_PTR(-ENOMEM); in stm32_rproc_get_loaded_rsc_table()
656 * firmware for the resource table. On detach, the remoteproc core re-initializes this in stm32_rproc_get_loaded_rsc_table()
657 * entire area by overwriting it with the initial values stored in rproc->clean_table. in stm32_rproc_get_loaded_rsc_table()
660 return (__force struct resource_table *)ddata->rsc_va; in stm32_rproc_get_loaded_rsc_table()
679 { .compatible = "st,stm32mp1-m4" },
689 syscon->map = syscon_regmap_lookup_by_phandle(np, prop); in stm32_rproc_get_syscon()
690 if (IS_ERR(syscon->map)) { in stm32_rproc_get_syscon()
691 err = PTR_ERR(syscon->map); in stm32_rproc_get_syscon()
692 syscon->map = NULL; in stm32_rproc_get_syscon()
696 err = of_property_read_u32_index(np, prop, 1, &syscon->reg); in stm32_rproc_get_syscon()
700 err = of_property_read_u32_index(np, prop, 2, &syscon->mask); in stm32_rproc_get_syscon()
709 struct device *dev = &pdev->dev; in stm32_rproc_parse_dt()
710 struct device_node *np = dev->of_node; in stm32_rproc_parse_dt()
713 int err, irq; in stm32_rproc_parse_dt() local
715 irq = platform_get_irq_optional(pdev, 0); in stm32_rproc_parse_dt()
716 if (irq == -EPROBE_DEFER) in stm32_rproc_parse_dt()
717 return irq; in stm32_rproc_parse_dt()
719 if (irq > 0) { in stm32_rproc_parse_dt()
720 err = devm_request_irq(dev, irq, stm32_rproc_wdg, 0, in stm32_rproc_parse_dt()
724 "failed to request wdg irq\n"); in stm32_rproc_parse_dt()
726 ddata->wdg_irq = irq; in stm32_rproc_parse_dt()
728 if (of_property_read_bool(np, "wakeup-source")) { in stm32_rproc_parse_dt()
730 dev_pm_set_wake_irq(dev, irq); in stm32_rproc_parse_dt()
733 dev_info(dev, "wdg irq registered\n"); in stm32_rproc_parse_dt()
736 ddata->rst = devm_reset_control_get_optional(dev, "mcu_rst"); in stm32_rproc_parse_dt()
737 if (!ddata->rst) { in stm32_rproc_parse_dt()
739 ddata->rst = devm_reset_control_get_by_index(dev, 0); in stm32_rproc_parse_dt()
741 if (IS_ERR(ddata->rst)) in stm32_rproc_parse_dt()
742 return dev_err_probe(dev, PTR_ERR(ddata->rst), in stm32_rproc_parse_dt()
747 * - using SCMI: the hold boot is managed as a reset in stm32_rproc_parse_dt()
748 * The DT "reset-mames" property should be defined with 2 items: in stm32_rproc_parse_dt()
749 * reset-names = "mcu_rst", "hold_boot"; in stm32_rproc_parse_dt()
750 * - using SMC call (deprecated): use SMC reset interface in stm32_rproc_parse_dt()
751 * The DT "reset-mames" property is optional, "st,syscfg-tz" is required in stm32_rproc_parse_dt()
752 * - default(no SCMI, no SMC): the hold boot is managed as a syscon register in stm32_rproc_parse_dt()
753 * The DT "reset-mames" property is optional, "st,syscfg-holdboot" is required in stm32_rproc_parse_dt()
756 ddata->hold_boot_rst = devm_reset_control_get_optional(dev, "hold_boot"); in stm32_rproc_parse_dt()
757 if (IS_ERR(ddata->hold_boot_rst)) in stm32_rproc_parse_dt()
758 return dev_err_probe(dev, PTR_ERR(ddata->hold_boot_rst), in stm32_rproc_parse_dt()
761 if (!ddata->hold_boot_rst && IS_ENABLED(CONFIG_HAVE_ARM_SMCCC)) { in stm32_rproc_parse_dt()
763 err = stm32_rproc_get_syscon(np, "st,syscfg-tz", &tz); in stm32_rproc_parse_dt()
770 ddata->hold_boot_smc = tzen & tz.mask; in stm32_rproc_parse_dt()
774 if (!ddata->hold_boot_rst && !ddata->hold_boot_smc) { in stm32_rproc_parse_dt()
776 err = stm32_rproc_get_syscon(np, "st,syscfg-holdboot", in stm32_rproc_parse_dt()
777 &ddata->hold_boot); in stm32_rproc_parse_dt()
784 err = stm32_rproc_get_syscon(np, "st,syscfg-pdds", &ddata->pdds); in stm32_rproc_parse_dt()
788 *auto_boot = of_property_read_bool(np, "st,auto-boot"); in stm32_rproc_parse_dt()
794 err = stm32_rproc_get_syscon(np, "st,syscfg-m4-state", in stm32_rproc_parse_dt()
795 &ddata->m4_state); in stm32_rproc_parse_dt()
798 ddata->m4_state.map = NULL; in stm32_rproc_parse_dt()
807 err = stm32_rproc_get_syscon(np, "st,syscfg-rsc-tbl", in stm32_rproc_parse_dt()
808 &ddata->rsctbl); in stm32_rproc_parse_dt()
821 if (!ddata->m4_state.map) { in stm32_rproc_get_m4_status()
830 return regmap_read(ddata->m4_state.map, ddata->m4_state.reg, state); in stm32_rproc_get_m4_status()
835 struct device *dev = &pdev->dev; in stm32_rproc_probe()
837 struct device_node *np = dev->of_node; in stm32_rproc_probe()
846 rproc = devm_rproc_alloc(dev, np->name, &st_rproc_ops, NULL, sizeof(*ddata)); in stm32_rproc_probe()
848 return -ENOMEM; in stm32_rproc_probe()
850 ddata = rproc->priv; in stm32_rproc_probe()
854 ret = stm32_rproc_parse_dt(pdev, ddata, &rproc->auto_boot); in stm32_rproc_probe()
867 rproc->state = RPROC_DETACHED; in stm32_rproc_probe()
869 rproc->has_iommu = false; in stm32_rproc_probe()
870 ddata->workqueue = create_workqueue(dev_name(dev)); in stm32_rproc_probe()
871 if (!ddata->workqueue) { in stm32_rproc_probe()
873 ret = -ENOMEM; in stm32_rproc_probe()
892 destroy_workqueue(ddata->workqueue); in stm32_rproc_probe()
906 struct stm32_rproc *ddata = rproc->priv; in stm32_rproc_remove()
907 struct device *dev = &pdev->dev; in stm32_rproc_remove()
909 if (atomic_read(&rproc->power) > 0) in stm32_rproc_remove()
914 destroy_workqueue(ddata->workqueue); in stm32_rproc_remove()
925 struct stm32_rproc *ddata = rproc->priv; in stm32_rproc_suspend()
928 return enable_irq_wake(ddata->wdg_irq); in stm32_rproc_suspend()
936 struct stm32_rproc *ddata = rproc->priv; in stm32_rproc_resume()
939 return disable_irq_wake(ddata->wdg_irq); in stm32_rproc_resume()
951 .name = "stm32-rproc",