Lines Matching +full:imx93 +full:- +full:clock

1 // SPDX-License-Identifier: GPL-2.0-only
6 #include <linux/arm-smccc.h>
63 * struct imx_rproc_mem - slim internal memory structure
96 /* TCM CODE NON-SECURE */
104 /* TCM SYS NON-SECURE*/
132 /* QSPI Code - alias */
134 /* DDR (Code) - alias */
138 /* OCRAM_S - alias */
152 /* TCML - alias */
160 /* QSPI Code - alias */
162 /* DDR (Code) - alias */
194 /* OCRAM_S (M4 Boot code) - alias */
198 /* OCRAM (Code) - alias */
200 /* OCRAM_EPDC (Code) - alias */
202 /* OCRAM_PXP (Code) - alias */
206 /* DDR (Code) - alias, first part of DDR (Data) */
223 /* TCML (M4 Boot Code) - alias */
227 /* OCRAM_S (Code) - alias */
231 /* DDR (Code) - alias, first part of DDR (Data) */
236 /* OCRAM_S (Data) - alias? */
298 struct imx_rproc *priv = rproc->priv; in imx_rproc_start()
299 const struct imx_rproc_dcfg *dcfg = priv->dcfg; in imx_rproc_start()
300 struct device *dev = priv->dev; in imx_rproc_start()
304 switch (dcfg->method) { in imx_rproc_start()
306 ret = regmap_update_bits(priv->regmap, dcfg->src_reg, dcfg->src_mask, in imx_rproc_start()
307 dcfg->src_start); in imx_rproc_start()
314 return -EOPNOTSUPP; in imx_rproc_start()
325 struct imx_rproc *priv = rproc->priv; in imx_rproc_stop()
326 const struct imx_rproc_dcfg *dcfg = priv->dcfg; in imx_rproc_stop()
327 struct device *dev = priv->dev; in imx_rproc_stop()
331 switch (dcfg->method) { in imx_rproc_stop()
333 ret = regmap_update_bits(priv->regmap, dcfg->src_reg, dcfg->src_mask, in imx_rproc_stop()
334 dcfg->src_stop); in imx_rproc_stop()
343 return -EOPNOTSUPP; in imx_rproc_stop()
355 const struct imx_rproc_dcfg *dcfg = priv->dcfg; in imx_rproc_da_to_sys()
359 for (i = 0; i < dcfg->att_size; i++) { in imx_rproc_da_to_sys()
360 const struct imx_rproc_att *att = &dcfg->att[i]; in imx_rproc_da_to_sys()
362 if (da >= att->da && da + len < att->da + att->size) { in imx_rproc_da_to_sys()
363 unsigned int offset = da - att->da; in imx_rproc_da_to_sys()
365 *sys = att->sa + offset; in imx_rproc_da_to_sys()
367 *is_iomem = att->flags & ATT_IOMEM; in imx_rproc_da_to_sys()
372 dev_warn(priv->dev, "Translation failed: da = 0x%llx len = 0x%zx\n", in imx_rproc_da_to_sys()
374 return -ENOENT; in imx_rproc_da_to_sys()
379 struct imx_rproc *priv = rproc->priv; in imx_rproc_da_to_va()
395 if (sys >= priv->mem[i].sys_addr && sys + len < in imx_rproc_da_to_va()
396 priv->mem[i].sys_addr + priv->mem[i].size) { in imx_rproc_da_to_va()
397 unsigned int offset = sys - priv->mem[i].sys_addr; in imx_rproc_da_to_va()
399 va = (__force void *)(priv->mem[i].cpu_addr + offset); in imx_rproc_da_to_va()
404 dev_dbg(&rproc->dev, "da = 0x%llx len = 0x%zx va = 0x%p\n", in imx_rproc_da_to_va()
413 struct device *dev = rproc->dev.parent; in imx_rproc_mem_alloc()
416 dev_dbg(dev, "map memory: %p+%zx\n", &mem->dma, mem->len); in imx_rproc_mem_alloc()
417 va = ioremap_wc(mem->dma, mem->len); in imx_rproc_mem_alloc()
420 &mem->dma, mem->len); in imx_rproc_mem_alloc()
421 return -ENOMEM; in imx_rproc_mem_alloc()
425 mem->va = va; in imx_rproc_mem_alloc()
433 dev_dbg(rproc->dev.parent, "unmap memory: %pa\n", &mem->dma); in imx_rproc_mem_release()
434 iounmap(mem->va); in imx_rproc_mem_release()
441 struct imx_rproc *priv = rproc->priv; in imx_rproc_prepare()
442 struct device_node *np = priv->dev->of_node; in imx_rproc_prepare()
449 of_phandle_iterator_init(&it, np, "memory-region", NULL, 0); in imx_rproc_prepare()
455 if (!strcmp(it.node->name, "vdev0buffer")) in imx_rproc_prepare()
458 if (!strcmp(it.node->name, "rsc-table")) in imx_rproc_prepare()
463 dev_err(priv->dev, "unable to acquire memory-region\n"); in imx_rproc_prepare()
464 return -EINVAL; in imx_rproc_prepare()
468 da = rmem->base; in imx_rproc_prepare()
471 mem = rproc_mem_entry_init(priv->dev, NULL, (dma_addr_t)rmem->base, rmem->size, da, in imx_rproc_prepare()
473 it.node->name); in imx_rproc_prepare()
476 rproc_coredump_add_segment(rproc, da, rmem->size); in imx_rproc_prepare()
478 return -ENOMEM; in imx_rproc_prepare()
492 dev_info(&rproc->dev, "No resource table in elf\n"); in imx_rproc_parse_fw()
499 struct imx_rproc *priv = rproc->priv; in imx_rproc_kick()
503 if (!priv->tx_ch) { in imx_rproc_kick()
504 dev_err(priv->dev, "No initialized mbox tx channel\n"); in imx_rproc_kick()
514 err = mbox_send_message(priv->tx_ch, (void *)&mmsg); in imx_rproc_kick()
516 dev_err(priv->dev, "%s: failed (%d, err:%d)\n", in imx_rproc_kick()
527 struct imx_rproc *priv = rproc->priv; in imx_rproc_get_loaded_rsc_table()
530 if (!priv->rsc_table) in imx_rproc_get_loaded_rsc_table()
534 return (struct resource_table *)priv->rsc_table; in imx_rproc_get_loaded_rsc_table()
555 const struct imx_rproc_dcfg *dcfg = priv->dcfg; in imx_rproc_addr_init()
556 struct device *dev = &pdev->dev; in imx_rproc_addr_init()
557 struct device_node *np = dev->of_node; in imx_rproc_addr_init()
561 for (a = 0; a < dcfg->att_size; a++) { in imx_rproc_addr_init()
562 const struct imx_rproc_att *att = &dcfg->att[a]; in imx_rproc_addr_init()
564 if (!(att->flags & ATT_OWN)) in imx_rproc_addr_init()
570 if (att->flags & ATT_IOMEM) in imx_rproc_addr_init()
571 priv->mem[b].cpu_addr = devm_ioremap(&pdev->dev, in imx_rproc_addr_init()
572 att->sa, att->size); in imx_rproc_addr_init()
574 priv->mem[b].cpu_addr = devm_ioremap_wc(&pdev->dev, in imx_rproc_addr_init()
575 att->sa, att->size); in imx_rproc_addr_init()
576 if (!priv->mem[b].cpu_addr) { in imx_rproc_addr_init()
577 dev_err(dev, "failed to remap %#x bytes from %#x\n", att->size, att->sa); in imx_rproc_addr_init()
578 return -ENOMEM; in imx_rproc_addr_init()
580 priv->mem[b].sys_addr = att->sa; in imx_rproc_addr_init()
581 priv->mem[b].size = att->size; in imx_rproc_addr_init()
585 /* memory-region is optional property */ in imx_rproc_addr_init()
586 nph = of_count_phandle_with_args(np, "memory-region", NULL); in imx_rproc_addr_init()
595 node = of_parse_phandle(np, "memory-region", a); in imx_rproc_addr_init()
597 if (!strncmp(node->name, "vdev", strlen("vdev"))) { in imx_rproc_addr_init()
612 priv->mem[b].cpu_addr = devm_ioremap_wc(&pdev->dev, res.start, resource_size(&res)); in imx_rproc_addr_init()
613 if (!priv->mem[b].cpu_addr) { in imx_rproc_addr_init()
615 return -ENOMEM; in imx_rproc_addr_init()
617 priv->mem[b].sys_addr = res.start; in imx_rproc_addr_init()
618 priv->mem[b].size = resource_size(&res); in imx_rproc_addr_init()
619 if (!strcmp(node->name, "rsc-table")) in imx_rproc_addr_init()
620 priv->rsc_table = priv->mem[b].cpu_addr; in imx_rproc_addr_init()
632 rproc_vq_interrupt(priv->rproc, 0); in imx_rproc_vq_work()
633 rproc_vq_interrupt(priv->rproc, 1); in imx_rproc_vq_work()
638 struct rproc *rproc = dev_get_drvdata(cl->dev); in imx_rproc_rx_callback()
639 struct imx_rproc *priv = rproc->priv; in imx_rproc_rx_callback()
641 queue_work(priv->workqueue, &priv->rproc_work); in imx_rproc_rx_callback()
646 struct imx_rproc *priv = rproc->priv; in imx_rproc_xtr_mbox_init()
647 struct device *dev = priv->dev; in imx_rproc_xtr_mbox_init()
650 if (!of_get_property(dev->of_node, "mbox-names", NULL)) in imx_rproc_xtr_mbox_init()
653 cl = &priv->cl; in imx_rproc_xtr_mbox_init()
654 cl->dev = dev; in imx_rproc_xtr_mbox_init()
655 cl->tx_block = true; in imx_rproc_xtr_mbox_init()
656 cl->tx_tout = 100; in imx_rproc_xtr_mbox_init()
657 cl->knows_txdone = false; in imx_rproc_xtr_mbox_init()
658 cl->rx_callback = imx_rproc_rx_callback; in imx_rproc_xtr_mbox_init()
660 priv->tx_ch = mbox_request_channel_byname(cl, "tx"); in imx_rproc_xtr_mbox_init()
661 if (IS_ERR(priv->tx_ch)) in imx_rproc_xtr_mbox_init()
662 return dev_err_probe(cl->dev, PTR_ERR(priv->tx_ch), in imx_rproc_xtr_mbox_init()
665 priv->rx_ch = mbox_request_channel_byname(cl, "rx"); in imx_rproc_xtr_mbox_init()
666 if (IS_ERR(priv->rx_ch)) { in imx_rproc_xtr_mbox_init()
667 mbox_free_channel(priv->tx_ch); in imx_rproc_xtr_mbox_init()
668 return dev_err_probe(cl->dev, PTR_ERR(priv->rx_ch), in imx_rproc_xtr_mbox_init()
677 struct imx_rproc *priv = rproc->priv; in imx_rproc_free_mbox()
679 mbox_free_channel(priv->tx_ch); in imx_rproc_free_mbox()
680 mbox_free_channel(priv->rx_ch); in imx_rproc_free_mbox()
685 struct regmap_config config = { .name = "imx-rproc" }; in imx_rproc_detect_mode()
686 const struct imx_rproc_dcfg *dcfg = priv->dcfg; in imx_rproc_detect_mode()
687 struct device *dev = priv->dev; in imx_rproc_detect_mode()
693 switch (dcfg->method) { in imx_rproc_detect_mode()
695 priv->rproc->state = RPROC_DETACHED; in imx_rproc_detect_mode()
700 priv->rproc->state = RPROC_DETACHED; in imx_rproc_detect_mode()
706 regmap = syscon_regmap_lookup_by_phandle(dev->of_node, "syscon"); in imx_rproc_detect_mode()
712 priv->regmap = regmap; in imx_rproc_detect_mode()
715 ret = regmap_read(regmap, dcfg->src_reg, &val); in imx_rproc_detect_mode()
721 if ((val & dcfg->src_mask) != dcfg->src_stop) in imx_rproc_detect_mode()
722 priv->rproc->state = RPROC_DETACHED; in imx_rproc_detect_mode()
729 const struct imx_rproc_dcfg *dcfg = priv->dcfg; in imx_rproc_clk_enable()
730 struct device *dev = priv->dev; in imx_rproc_clk_enable()
734 if (dcfg->method == IMX_RPROC_NONE) in imx_rproc_clk_enable()
737 priv->clk = devm_clk_get(dev, NULL); in imx_rproc_clk_enable()
738 if (IS_ERR(priv->clk)) { in imx_rproc_clk_enable()
739 dev_err(dev, "Failed to get clock\n"); in imx_rproc_clk_enable()
740 return PTR_ERR(priv->clk); in imx_rproc_clk_enable()
747 ret = clk_prepare_enable(priv->clk); in imx_rproc_clk_enable()
749 dev_err(dev, "Failed to enable clock\n"); in imx_rproc_clk_enable()
758 struct device *dev = &pdev->dev; in imx_rproc_probe()
759 struct device_node *np = dev->of_node; in imx_rproc_probe()
766 rproc = rproc_alloc(dev, "imx-rproc", &imx_rproc_ops, in imx_rproc_probe()
769 return -ENOMEM; in imx_rproc_probe()
773 ret = -EINVAL; in imx_rproc_probe()
777 priv = rproc->priv; in imx_rproc_probe()
778 priv->rproc = rproc; in imx_rproc_probe()
779 priv->dcfg = dcfg; in imx_rproc_probe()
780 priv->dev = dev; in imx_rproc_probe()
783 priv->workqueue = create_workqueue(dev_name(dev)); in imx_rproc_probe()
784 if (!priv->workqueue) { in imx_rproc_probe()
786 ret = -ENOMEM; in imx_rproc_probe()
808 INIT_WORK(&priv->rproc_work, imx_rproc_vq_work); in imx_rproc_probe()
810 if (rproc->state != RPROC_DETACHED) in imx_rproc_probe()
811 rproc->auto_boot = of_property_read_bool(np, "fsl,auto-boot"); in imx_rproc_probe()
822 clk_disable_unprepare(priv->clk); in imx_rproc_probe()
826 destroy_workqueue(priv->workqueue); in imx_rproc_probe()
836 struct imx_rproc *priv = rproc->priv; in imx_rproc_remove()
838 clk_disable_unprepare(priv->clk); in imx_rproc_remove()
841 destroy_workqueue(priv->workqueue); in imx_rproc_remove()
848 { .compatible = "fsl,imx7ulp-cm4", .data = &imx_rproc_cfg_imx7ulp },
849 { .compatible = "fsl,imx7d-cm4", .data = &imx_rproc_cfg_imx7d },
850 { .compatible = "fsl,imx6sx-cm4", .data = &imx_rproc_cfg_imx6sx },
851 { .compatible = "fsl,imx8mq-cm4", .data = &imx_rproc_cfg_imx8mq },
852 { .compatible = "fsl,imx8mm-cm4", .data = &imx_rproc_cfg_imx8mq },
853 { .compatible = "fsl,imx8mn-cm7", .data = &imx_rproc_cfg_imx8mn },
854 { .compatible = "fsl,imx8mp-cm7", .data = &imx_rproc_cfg_imx8mn },
855 { .compatible = "fsl,imx8ulp-cm33", .data = &imx_rproc_cfg_imx8ulp },
856 { .compatible = "fsl,imx93-cm33", .data = &imx_rproc_cfg_imx93 },
865 .name = "imx-rproc",