Lines Matching +full:device +full:- +full:sram

1 // SPDX-License-Identifier: GPL-2.0
7 #include <linux/dma-mapping.h>
26 * scp_get() - get a reference to SCP.
28 * @pdev: the platform device of the module requesting SCP platform
29 * device for using SCP API.
35 struct device *dev = &pdev->dev; in scp_get()
39 scp_node = of_parse_phandle(dev->of_node, "mediatek,scp", 0); in scp_get()
58 * scp_put() - "free" the SCP
64 put_device(scp->dev); in scp_put()
70 struct mtk_scp_of_cluster *scp_cluster = scp->cluster; in scp_wdt_handler()
73 dev_err(scp->dev, "SCP watchdog timeout! 0x%x", scp_to_host); in scp_wdt_handler()
76 list_for_each_entry(scp_node, &scp_cluster->mtk_scp_list, elem) in scp_wdt_handler()
77 rproc_report_crash(scp_node->rproc, RPROC_WATCHDOG); in scp_wdt_handler()
85 scp->run.signaled = run->signaled; in scp_init_ipi_handler()
86 strscpy(scp->run.fw_ver, run->fw_ver, SCP_FW_VER_LEN); in scp_init_ipi_handler()
87 scp->run.dec_capability = run->dec_capability; in scp_init_ipi_handler()
88 scp->run.enc_capability = run->enc_capability; in scp_init_ipi_handler()
89 wake_up_interruptible(&scp->run.wq); in scp_init_ipi_handler()
94 struct mtk_share_obj __iomem *rcv_obj = scp->recv_buf; in scp_ipi_handler()
95 struct scp_ipi_desc *ipi_desc = scp->ipi_desc; in scp_ipi_handler()
97 u32 id = readl(&rcv_obj->id); in scp_ipi_handler()
98 u32 len = readl(&rcv_obj->len); in scp_ipi_handler()
101 scp_sizes = scp->data->scp_sizes; in scp_ipi_handler()
102 if (len > scp_sizes->ipi_share_buffer_size) { in scp_ipi_handler()
103 dev_err(scp->dev, "ipi message too long (len %d, max %zd)", len, in scp_ipi_handler()
104 scp_sizes->ipi_share_buffer_size); in scp_ipi_handler()
108 dev_err(scp->dev, "No such ipi id = %d\n", id); in scp_ipi_handler()
115 dev_err(scp->dev, "No handler for ipi id = %d\n", id); in scp_ipi_handler()
120 memcpy_fromio(scp->share_buf, &rcv_obj->share_buf, len); in scp_ipi_handler()
121 memset(&scp->share_buf[len], 0, scp_sizes->ipi_share_buffer_size - len); in scp_ipi_handler()
122 handler(scp->share_buf, len, ipi_desc[id].priv); in scp_ipi_handler()
125 scp->ipi_id_ack[id] = true; in scp_ipi_handler()
126 wake_up(&scp->ack_wq); in scp_ipi_handler()
144 offset = scp->data->ipi_buf_offset; in scp_ipi_init()
148 dev_info(scp->dev, "IPI buf addr %#010zx\n", offset); in scp_ipi_init()
151 buf_sz = sizeof(*scp->recv_buf) + sizeof(*scp->send_buf); in scp_ipi_init()
153 if (scp->sram_size < buf_sz + offset) { in scp_ipi_init()
154 dev_err(scp->dev, "IPI buffer does not fit in SRAM.\n"); in scp_ipi_init()
155 return -EOVERFLOW; in scp_ipi_init()
158 scp_sizes = scp->data->scp_sizes; in scp_ipi_init()
159 scp->recv_buf = (struct mtk_share_obj __iomem *) in scp_ipi_init()
160 (scp->sram_base + offset); in scp_ipi_init()
161 share_buf_offset = sizeof(scp->recv_buf->id) in scp_ipi_init()
162 + sizeof(scp->recv_buf->len) + scp_sizes->ipi_share_buffer_size; in scp_ipi_init()
163 scp->send_buf = (struct mtk_share_obj __iomem *) in scp_ipi_init()
164 (scp->sram_base + offset + share_buf_offset); in scp_ipi_init()
165 memset_io(scp->recv_buf, 0, share_buf_offset); in scp_ipi_init()
166 memset_io(scp->send_buf, 0, share_buf_offset); in scp_ipi_init()
175 val = readl(scp->cluster->reg_base + MT8183_SW_RSTN); in mt8183_scp_reset_assert()
177 writel(val, scp->cluster->reg_base + MT8183_SW_RSTN); in mt8183_scp_reset_assert()
184 val = readl(scp->cluster->reg_base + MT8183_SW_RSTN); in mt8183_scp_reset_deassert()
186 writel(val, scp->cluster->reg_base + MT8183_SW_RSTN); in mt8183_scp_reset_deassert()
191 writel(1, scp->cluster->reg_base + MT8192_CORE0_SW_RSTN_SET); in mt8192_scp_reset_assert()
196 writel(1, scp->cluster->reg_base + MT8192_CORE0_SW_RSTN_CLR); in mt8192_scp_reset_deassert()
201 writel(1, scp->cluster->reg_base + MT8195_CORE1_SW_RSTN_SET); in mt8195_scp_c1_reset_assert()
206 writel(1, scp->cluster->reg_base + MT8195_CORE1_SW_RSTN_CLR); in mt8195_scp_c1_reset_deassert()
213 scp_to_host = readl(scp->cluster->reg_base + MT8183_SCP_TO_HOST); in mt8183_scp_irq_handler()
221 scp->cluster->reg_base + MT8183_SCP_TO_HOST); in mt8183_scp_irq_handler()
228 scp_to_host = readl(scp->cluster->reg_base + MT8192_SCP2APMCU_IPC_SET); in mt8192_scp_irq_handler()
238 scp->cluster->reg_base + MT8192_SCP2APMCU_IPC_CLR); in mt8192_scp_irq_handler()
241 writel(1, scp->cluster->reg_base + MT8192_CORE0_WDT_IRQ); in mt8192_scp_irq_handler()
249 scp_to_host = readl(scp->cluster->reg_base + MT8192_SCP2APMCU_IPC_SET); in mt8195_scp_irq_handler()
254 u32 reason = readl(scp->cluster->reg_base + MT8195_SYS_STATUS); in mt8195_scp_irq_handler()
257 writel(1, scp->cluster->reg_base + MT8192_CORE0_WDT_IRQ); in mt8195_scp_irq_handler()
260 writel(1, scp->cluster->reg_base + MT8195_CORE1_WDT_IRQ); in mt8195_scp_irq_handler()
265 writel(scp_to_host, scp->cluster->reg_base + MT8192_SCP2APMCU_IPC_CLR); in mt8195_scp_irq_handler()
272 scp_to_host = readl(scp->cluster->reg_base + MT8195_SSHUB2APMCU_IPC_SET); in mt8195_scp_c1_irq_handler()
277 writel(scp_to_host, scp->cluster->reg_base + MT8195_SSHUB2APMCU_IPC_CLR); in mt8195_scp_c1_irq_handler()
285 ret = clk_prepare_enable(scp->clk); in scp_irq_handler()
287 dev_err(scp->dev, "failed to enable clocks\n"); in scp_irq_handler()
291 scp->data->scp_irq_handler(scp); in scp_irq_handler()
293 clk_disable_unprepare(scp->clk); in scp_irq_handler()
300 struct device *dev = &rproc->dev; in scp_elf_load_segments()
304 const u8 *elf_data = fw->data; in scp_elf_load_segments()
307 phdr = (struct elf32_phdr *)(elf_data + ehdr->e_phoff); in scp_elf_load_segments()
310 for (i = 0; i < ehdr->e_phnum; i++, phdr++) { in scp_elf_load_segments()
311 u32 da = phdr->p_paddr; in scp_elf_load_segments()
312 u32 memsz = phdr->p_memsz; in scp_elf_load_segments()
313 u32 filesz = phdr->p_filesz; in scp_elf_load_segments()
314 u32 offset = phdr->p_offset; in scp_elf_load_segments()
318 phdr->p_type, da, memsz, filesz); in scp_elf_load_segments()
320 if (phdr->p_type != PT_LOAD) in scp_elf_load_segments()
328 ret = -EINVAL; in scp_elf_load_segments()
332 if (offset + filesz > fw->size) { in scp_elf_load_segments()
334 offset + filesz, fw->size); in scp_elf_load_segments()
335 ret = -EINVAL; in scp_elf_load_segments()
339 /* grab the kernel address for this device address */ in scp_elf_load_segments()
343 ret = -EINVAL; in scp_elf_load_segments()
348 scp_memcpy_aligned(ptr, elf_data + phdr->p_offset, filesz); in scp_elf_load_segments()
361 const u8 *elf_data = fw->data; in scp_elf_read_ipi_buf_addr()
365 shdr = (struct elf32_shdr *)(elf_data + ehdr->e_shoff); in scp_elf_read_ipi_buf_addr()
366 shdr_strtab = shdr + ehdr->e_shstrndx; in scp_elf_read_ipi_buf_addr()
367 strtab = (const char *)(elf_data + shdr_strtab->sh_offset); in scp_elf_read_ipi_buf_addr()
369 for (i = 0; i < ehdr->e_shnum; i++, shdr++) { in scp_elf_read_ipi_buf_addr()
370 if (strcmp(strtab + shdr->sh_name, in scp_elf_read_ipi_buf_addr()
372 *offset = shdr->sh_addr; in scp_elf_read_ipi_buf_addr()
377 return -ENOENT; in scp_elf_read_ipi_buf_addr()
382 struct device *dev = scp->dev; in mt8183_scp_clk_get()
385 scp->clk = devm_clk_get(dev, "main"); in mt8183_scp_clk_get()
386 if (IS_ERR(scp->clk)) { in mt8183_scp_clk_get()
388 ret = PTR_ERR(scp->clk); in mt8183_scp_clk_get()
401 scp->clk = NULL; in mt8195_scp_clk_get()
409 writel(MT8183_SCP_IPC_INT_BIT, scp->cluster->reg_base + MT8183_SCP_TO_HOST); in mt8183_scp_before_load()
412 writel(0x0, scp->cluster->reg_base + MT8183_SCP_CLK_SW_SEL); in mt8183_scp_before_load()
413 writel(0x0, scp->cluster->reg_base + MT8183_SCP_CLK_DIV_SEL); in mt8183_scp_before_load()
416 writel(0x0, scp->cluster->reg_base + MT8183_SCP_L1_SRAM_PD); in mt8183_scp_before_load()
417 writel(0x0, scp->cluster->reg_base + MT8183_SCP_TCM_TAIL_SRAM_PD); in mt8183_scp_before_load()
419 /* Turn on the power of SCP's SRAM before using it. */ in mt8183_scp_before_load()
420 writel(0x0, scp->cluster->reg_base + MT8183_SCP_SRAM_PDN); in mt8183_scp_before_load()
423 * Set I-cache and D-cache size before loading SCP FW. in mt8183_scp_before_load()
424 * SCP SRAM logical address may change when cache size setting differs. in mt8183_scp_before_load()
427 scp->cluster->reg_base + MT8183_SCP_CACHE_CON); in mt8183_scp_before_load()
428 writel(MT8183_SCP_CACHESIZE_8KB, scp->cluster->reg_base + MT8183_SCP_DCACHE_CON); in mt8183_scp_before_load()
437 for (i = 31; i >= 0; i--) in scp_sram_power_on()
454 writel(MT8183_SCP_IPC_INT_BIT, scp->cluster->reg_base + MT8183_SCP_TO_HOST); in mt8186_scp_before_load()
457 writel(0x0, scp->cluster->reg_base + MT8183_SCP_CLK_SW_SEL); in mt8186_scp_before_load()
458 writel(0x0, scp->cluster->reg_base + MT8183_SCP_CLK_DIV_SEL); in mt8186_scp_before_load()
460 /* Turn on the power of SCP's SRAM before using it. Enable 1 block per time*/ in mt8186_scp_before_load()
461 scp_sram_power_on(scp->cluster->reg_base + MT8183_SCP_SRAM_PDN, 0); in mt8186_scp_before_load()
464 writel(0x0, scp->cluster->reg_base + MT8183_SCP_L1_SRAM_PD); in mt8186_scp_before_load()
465 writel(0x0, scp->cluster->reg_base + MT8183_SCP_TCM_TAIL_SRAM_PD); in mt8186_scp_before_load()
466 writel(0x0, scp->cluster->reg_base + MT8186_SCP_L1_SRAM_PD_P1); in mt8186_scp_before_load()
467 writel(0x0, scp->cluster->reg_base + MT8186_SCP_L1_SRAM_PD_p2); in mt8186_scp_before_load()
470 * Set I-cache and D-cache size before loading SCP FW. in mt8186_scp_before_load()
471 * SCP SRAM logical address may change when cache size setting differs. in mt8186_scp_before_load()
474 scp->cluster->reg_base + MT8183_SCP_CACHE_CON); in mt8186_scp_before_load()
475 writel(MT8183_SCP_CACHESIZE_8KB, scp->cluster->reg_base + MT8183_SCP_DCACHE_CON); in mt8186_scp_before_load()
482 struct mtk_scp_of_cluster *scp_cluster = scp->cluster; in mt8188_scp_l2tcm_on()
484 mutex_lock(&scp_cluster->cluster_lock); in mt8188_scp_l2tcm_on()
486 if (scp_cluster->l2tcm_refcnt == 0) { in mt8188_scp_l2tcm_on()
488 writel(0xff, scp->cluster->reg_base + MT8192_SCP2SPM_IPC_CLR); in mt8188_scp_l2tcm_on()
491 scp_sram_power_on(scp->cluster->reg_base + MT8192_L2TCM_SRAM_PD_0, 0); in mt8188_scp_l2tcm_on()
492 scp_sram_power_on(scp->cluster->reg_base + MT8192_L2TCM_SRAM_PD_1, 0); in mt8188_scp_l2tcm_on()
493 scp_sram_power_on(scp->cluster->reg_base + MT8192_L2TCM_SRAM_PD_2, 0); in mt8188_scp_l2tcm_on()
494 scp_sram_power_on(scp->cluster->reg_base + MT8192_L1TCM_SRAM_PDN, 0); in mt8188_scp_l2tcm_on()
497 scp_cluster->l2tcm_refcnt += 1; in mt8188_scp_l2tcm_on()
499 mutex_unlock(&scp_cluster->cluster_lock); in mt8188_scp_l2tcm_on()
506 writel(1, scp->cluster->reg_base + MT8192_CORE0_SW_RSTN_SET); in mt8188_scp_before_load()
510 scp_sram_power_on(scp->cluster->reg_base + MT8192_CPU0_SRAM_PD, 0); in mt8188_scp_before_load()
513 writel(0xff, scp->cluster->reg_base + MT8192_CORE0_MEM_ATT_PREDEF); in mt8188_scp_before_load()
522 struct mtk_scp_of_cluster *scp_cluster = scp->cluster; in mt8188_scp_c1_before_load()
524 scp->data->scp_reset_assert(scp); in mt8188_scp_c1_before_load()
528 scp_sram_power_on(scp->cluster->reg_base + MT8195_CPU1_SRAM_PD, 0); in mt8188_scp_c1_before_load()
531 writel(0xff, scp->cluster->reg_base + MT8195_CORE1_MEM_ATT_PREDEF); in mt8188_scp_c1_before_load()
535 * on SRAM when SCP core 1 accesses SRAM. in mt8188_scp_c1_before_load()
538 * different SRAM address because core 0 and core 1 both boot from in mt8188_scp_c1_before_load()
539 * the head of SRAM by default. this must be configured before boot SCP core 1. in mt8188_scp_c1_before_load()
546 writel(0, scp->cluster->reg_base + MT8195_L2TCM_OFFSET_RANGE_0_LOW); in mt8188_scp_c1_before_load()
547 writel(scp->sram_size, scp->cluster->reg_base + MT8195_L2TCM_OFFSET_RANGE_0_HIGH); in mt8188_scp_c1_before_load()
549 scp_c0 = list_first_entry(&scp_cluster->mtk_scp_list, struct mtk_scp, elem); in mt8188_scp_c1_before_load()
550 writel(scp->sram_phys - scp_c0->sram_phys, scp->cluster->reg_base + MT8195_L2TCM_OFFSET); in mt8188_scp_c1_before_load()
552 /* enable SRAM offset when fetching instruction and data */ in mt8188_scp_c1_before_load()
553 sec_ctrl = readl(scp->cluster->reg_base + MT8195_SEC_CTRL); in mt8188_scp_c1_before_load()
555 writel(sec_ctrl, scp->cluster->reg_base + MT8195_SEC_CTRL); in mt8188_scp_c1_before_load()
563 writel(0xff, scp->cluster->reg_base + MT8192_SCP2SPM_IPC_CLR); in mt8192_scp_before_load()
565 writel(1, scp->cluster->reg_base + MT8192_CORE0_SW_RSTN_SET); in mt8192_scp_before_load()
567 /* enable SRAM clock */ in mt8192_scp_before_load()
568 scp_sram_power_on(scp->cluster->reg_base + MT8192_L2TCM_SRAM_PD_0, 0); in mt8192_scp_before_load()
569 scp_sram_power_on(scp->cluster->reg_base + MT8192_L2TCM_SRAM_PD_1, 0); in mt8192_scp_before_load()
570 scp_sram_power_on(scp->cluster->reg_base + MT8192_L2TCM_SRAM_PD_2, 0); in mt8192_scp_before_load()
571 scp_sram_power_on(scp->cluster->reg_base + MT8192_L1TCM_SRAM_PDN, 0); in mt8192_scp_before_load()
572 scp_sram_power_on(scp->cluster->reg_base + MT8192_CPU0_SRAM_PD, 0); in mt8192_scp_before_load()
575 writel(0xff, scp->cluster->reg_base + MT8192_CORE0_MEM_ATT_PREDEF); in mt8192_scp_before_load()
582 struct mtk_scp_of_cluster *scp_cluster = scp->cluster; in mt8195_scp_l2tcm_on()
584 mutex_lock(&scp_cluster->cluster_lock); in mt8195_scp_l2tcm_on()
586 if (scp_cluster->l2tcm_refcnt == 0) { in mt8195_scp_l2tcm_on()
588 writel(0xff, scp->cluster->reg_base + MT8192_SCP2SPM_IPC_CLR); in mt8195_scp_l2tcm_on()
591 scp_sram_power_on(scp->cluster->reg_base + MT8192_L2TCM_SRAM_PD_0, 0); in mt8195_scp_l2tcm_on()
592 scp_sram_power_on(scp->cluster->reg_base + MT8192_L2TCM_SRAM_PD_1, 0); in mt8195_scp_l2tcm_on()
593 scp_sram_power_on(scp->cluster->reg_base + MT8192_L2TCM_SRAM_PD_2, 0); in mt8195_scp_l2tcm_on()
594 scp_sram_power_on(scp->cluster->reg_base + MT8192_L1TCM_SRAM_PDN, in mt8195_scp_l2tcm_on()
598 scp_cluster->l2tcm_refcnt += 1; in mt8195_scp_l2tcm_on()
600 mutex_unlock(&scp_cluster->cluster_lock); in mt8195_scp_l2tcm_on()
607 writel(1, scp->cluster->reg_base + MT8192_CORE0_SW_RSTN_SET); in mt8195_scp_before_load()
611 scp_sram_power_on(scp->cluster->reg_base + MT8192_CPU0_SRAM_PD, 0); in mt8195_scp_before_load()
614 writel(0xff, scp->cluster->reg_base + MT8192_CORE0_MEM_ATT_PREDEF); in mt8195_scp_before_load()
623 struct mtk_scp_of_cluster *scp_cluster = scp->cluster; in mt8195_scp_c1_before_load()
625 scp->data->scp_reset_assert(scp); in mt8195_scp_c1_before_load()
629 scp_sram_power_on(scp->cluster->reg_base + MT8195_CPU1_SRAM_PD, 0); in mt8195_scp_c1_before_load()
632 writel(0xff, scp->cluster->reg_base + MT8195_CORE1_MEM_ATT_PREDEF); in mt8195_scp_c1_before_load()
636 * on SRAM when SCP core 1 accesses SRAM. in mt8195_scp_c1_before_load()
639 * different SRAM address because core 0 and core 1 both boot from in mt8195_scp_c1_before_load()
640 * the head of SRAM by default. this must be configured before boot SCP core 1. in mt8195_scp_c1_before_load()
647 writel(0, scp->cluster->reg_base + MT8195_L2TCM_OFFSET_RANGE_0_LOW); in mt8195_scp_c1_before_load()
648 writel(scp->sram_size, scp->cluster->reg_base + MT8195_L2TCM_OFFSET_RANGE_0_HIGH); in mt8195_scp_c1_before_load()
650 scp_c0 = list_first_entry(&scp_cluster->mtk_scp_list, struct mtk_scp, elem); in mt8195_scp_c1_before_load()
651 writel(scp->sram_phys - scp_c0->sram_phys, scp->cluster->reg_base + MT8195_L2TCM_OFFSET); in mt8195_scp_c1_before_load()
653 /* enable SRAM offset when fetching instruction and data */ in mt8195_scp_c1_before_load()
654 sec_ctrl = readl(scp->cluster->reg_base + MT8195_SEC_CTRL); in mt8195_scp_c1_before_load()
656 writel(sec_ctrl, scp->cluster->reg_base + MT8195_SEC_CTRL); in mt8195_scp_c1_before_load()
663 struct mtk_scp *scp = rproc->priv; in scp_load()
664 struct device *dev = scp->dev; in scp_load()
667 ret = clk_prepare_enable(scp->clk); in scp_load()
674 scp->data->scp_reset_assert(scp); in scp_load()
676 ret = scp->data->scp_before_load(scp); in scp_load()
682 clk_disable_unprepare(scp->clk); in scp_load()
689 struct mtk_scp *scp = rproc->priv; in scp_parse_fw()
690 struct device *dev = scp->dev; in scp_parse_fw()
693 ret = clk_prepare_enable(scp->clk); in scp_parse_fw()
700 clk_disable_unprepare(scp->clk); in scp_parse_fw()
706 struct mtk_scp *scp = rproc->priv; in scp_start()
707 struct device *dev = scp->dev; in scp_start()
708 struct scp_run *run = &scp->run; in scp_start()
711 ret = clk_prepare_enable(scp->clk); in scp_start()
717 run->signaled = false; in scp_start()
719 scp->data->scp_reset_deassert(scp); in scp_start()
722 run->wq, in scp_start()
723 run->signaled, in scp_start()
728 ret = -ETIME; in scp_start()
731 if (ret == -ERESTARTSYS) { in scp_start()
736 clk_disable_unprepare(scp->clk); in scp_start()
737 dev_info(dev, "SCP is ready. FW version %s\n", run->fw_ver); in scp_start()
742 scp->data->scp_reset_assert(scp); in scp_start()
743 clk_disable_unprepare(scp->clk); in scp_start()
752 scp_sizes = scp->data->scp_sizes; in mt8183_scp_da_to_va()
753 if (da < scp->sram_size) { in mt8183_scp_da_to_va()
755 if (offset >= 0 && (offset + len) <= scp->sram_size) in mt8183_scp_da_to_va()
756 return (void __force *)scp->sram_base + offset; in mt8183_scp_da_to_va()
757 } else if (scp_sizes->max_dram_size) { in mt8183_scp_da_to_va()
758 offset = da - scp->dma_addr; in mt8183_scp_da_to_va()
759 if (offset >= 0 && (offset + len) <= scp_sizes->max_dram_size) in mt8183_scp_da_to_va()
760 return scp->cpu_addr + offset; in mt8183_scp_da_to_va()
771 scp_sizes = scp->data->scp_sizes; in mt8192_scp_da_to_va()
772 if (da >= scp->sram_phys && in mt8192_scp_da_to_va()
773 (da + len) <= scp->sram_phys + scp->sram_size) { in mt8192_scp_da_to_va()
774 offset = da - scp->sram_phys; in mt8192_scp_da_to_va()
775 return (void __force *)scp->sram_base + offset; in mt8192_scp_da_to_va()
779 if (scp->cluster->l1tcm_size && in mt8192_scp_da_to_va()
780 da >= scp->cluster->l1tcm_phys && in mt8192_scp_da_to_va()
781 (da + len) <= scp->cluster->l1tcm_phys + scp->cluster->l1tcm_size) { in mt8192_scp_da_to_va()
782 offset = da - scp->cluster->l1tcm_phys; in mt8192_scp_da_to_va()
783 return (void __force *)scp->cluster->l1tcm_base + offset; in mt8192_scp_da_to_va()
787 if (scp_sizes->max_dram_size && in mt8192_scp_da_to_va()
788 da >= scp->dma_addr && in mt8192_scp_da_to_va()
789 (da + len) <= scp->dma_addr + scp_sizes->max_dram_size) { in mt8192_scp_da_to_va()
790 offset = da - scp->dma_addr; in mt8192_scp_da_to_va()
791 return scp->cpu_addr + offset; in mt8192_scp_da_to_va()
799 struct mtk_scp *scp = rproc->priv; in scp_da_to_va()
801 return scp->data->scp_da_to_va(scp, da, len); in scp_da_to_va()
807 writel(0, scp->cluster->reg_base + MT8183_WDT_CFG); in mt8183_scp_stop()
812 struct mtk_scp_of_cluster *scp_cluster = scp->cluster; in mt8188_scp_l2tcm_off()
814 mutex_lock(&scp_cluster->cluster_lock); in mt8188_scp_l2tcm_off()
816 if (scp_cluster->l2tcm_refcnt > 0) in mt8188_scp_l2tcm_off()
817 scp_cluster->l2tcm_refcnt -= 1; in mt8188_scp_l2tcm_off()
819 if (scp_cluster->l2tcm_refcnt == 0) { in mt8188_scp_l2tcm_off()
821 scp_sram_power_off(scp->cluster->reg_base + MT8192_L2TCM_SRAM_PD_0, 0); in mt8188_scp_l2tcm_off()
822 scp_sram_power_off(scp->cluster->reg_base + MT8192_L2TCM_SRAM_PD_1, 0); in mt8188_scp_l2tcm_off()
823 scp_sram_power_off(scp->cluster->reg_base + MT8192_L2TCM_SRAM_PD_2, 0); in mt8188_scp_l2tcm_off()
824 scp_sram_power_off(scp->cluster->reg_base + MT8192_L1TCM_SRAM_PDN, 0); in mt8188_scp_l2tcm_off()
827 mutex_unlock(&scp_cluster->cluster_lock); in mt8188_scp_l2tcm_off()
834 scp_sram_power_off(scp->cluster->reg_base + MT8192_CPU0_SRAM_PD, 0); in mt8188_scp_stop()
837 writel(0, scp->cluster->reg_base + MT8192_CORE0_WDT_CFG); in mt8188_scp_stop()
844 /* Power off CPU SRAM */ in mt8188_scp_c1_stop()
845 scp_sram_power_off(scp->cluster->reg_base + MT8195_CPU1_SRAM_PD, 0); in mt8188_scp_c1_stop()
848 writel(0, scp->cluster->reg_base + MT8195_CORE1_WDT_CFG); in mt8188_scp_c1_stop()
853 /* Disable SRAM clock */ in mt8192_scp_stop()
854 scp_sram_power_off(scp->cluster->reg_base + MT8192_L2TCM_SRAM_PD_0, 0); in mt8192_scp_stop()
855 scp_sram_power_off(scp->cluster->reg_base + MT8192_L2TCM_SRAM_PD_1, 0); in mt8192_scp_stop()
856 scp_sram_power_off(scp->cluster->reg_base + MT8192_L2TCM_SRAM_PD_2, 0); in mt8192_scp_stop()
857 scp_sram_power_off(scp->cluster->reg_base + MT8192_L1TCM_SRAM_PDN, 0); in mt8192_scp_stop()
858 scp_sram_power_off(scp->cluster->reg_base + MT8192_CPU0_SRAM_PD, 0); in mt8192_scp_stop()
861 writel(0, scp->cluster->reg_base + MT8192_CORE0_WDT_CFG); in mt8192_scp_stop()
866 struct mtk_scp_of_cluster *scp_cluster = scp->cluster; in mt8195_scp_l2tcm_off()
868 mutex_lock(&scp_cluster->cluster_lock); in mt8195_scp_l2tcm_off()
870 if (scp_cluster->l2tcm_refcnt > 0) in mt8195_scp_l2tcm_off()
871 scp_cluster->l2tcm_refcnt -= 1; in mt8195_scp_l2tcm_off()
873 if (scp_cluster->l2tcm_refcnt == 0) { in mt8195_scp_l2tcm_off()
875 scp_sram_power_off(scp->cluster->reg_base + MT8192_L2TCM_SRAM_PD_0, 0); in mt8195_scp_l2tcm_off()
876 scp_sram_power_off(scp->cluster->reg_base + MT8192_L2TCM_SRAM_PD_1, 0); in mt8195_scp_l2tcm_off()
877 scp_sram_power_off(scp->cluster->reg_base + MT8192_L2TCM_SRAM_PD_2, 0); in mt8195_scp_l2tcm_off()
878 scp_sram_power_off(scp->cluster->reg_base + MT8192_L1TCM_SRAM_PDN, in mt8195_scp_l2tcm_off()
882 mutex_unlock(&scp_cluster->cluster_lock); in mt8195_scp_l2tcm_off()
889 scp_sram_power_off(scp->cluster->reg_base + MT8192_CPU0_SRAM_PD, 0); in mt8195_scp_stop()
892 writel(0, scp->cluster->reg_base + MT8192_CORE0_WDT_CFG); in mt8195_scp_stop()
899 /* Power off CPU SRAM */ in mt8195_scp_c1_stop()
900 scp_sram_power_off(scp->cluster->reg_base + MT8195_CPU1_SRAM_PD, 0); in mt8195_scp_c1_stop()
903 writel(0, scp->cluster->reg_base + MT8195_CORE1_WDT_CFG); in mt8195_scp_c1_stop()
908 struct mtk_scp *scp = rproc->priv; in scp_stop()
911 ret = clk_prepare_enable(scp->clk); in scp_stop()
913 dev_err(scp->dev, "failed to enable clocks\n"); in scp_stop()
917 scp->data->scp_reset_assert(scp); in scp_stop()
918 scp->data->scp_stop(scp); in scp_stop()
919 clk_disable_unprepare(scp->clk); in scp_stop()
934 * scp_get_device() - get device struct of SCP
938 struct device *scp_get_device(struct mtk_scp *scp) in scp_get_device()
940 return scp->dev; in scp_get_device()
945 * scp_get_rproc() - get rproc struct of SCP
951 return scp->rproc; in scp_get_rproc()
956 * scp_get_vdec_hw_capa() - get video decoder hardware capability
964 return scp->run.dec_capability; in scp_get_vdec_hw_capa()
969 * scp_get_venc_hw_capa() - get video encoder hardware capability
977 return scp->run.enc_capability; in scp_get_venc_hw_capa()
982 * scp_mapping_dm_addr() - Mapping SRAM/DRAM to kernel virtual address
987 * Mapping the SCP's SRAM address /
992 * Return: Return ERR_PTR(-EINVAL) if mapping failed,
999 ptr = scp_da_to_va(scp->rproc, mem_addr, 0, NULL); in scp_mapping_dm_addr()
1001 return ERR_PTR(-EINVAL); in scp_mapping_dm_addr()
1012 ret = of_reserved_mem_device_init(scp->dev); in scp_map_memory_region()
1015 if (ret == -ENODEV) { in scp_map_memory_region()
1016 dev_info(scp->dev, "skipping reserved memory initialization."); in scp_map_memory_region()
1021 dev_err(scp->dev, "failed to assign memory-region: %d\n", ret); in scp_map_memory_region()
1022 return -ENOMEM; in scp_map_memory_region()
1026 scp_sizes = scp->data->scp_sizes; in scp_map_memory_region()
1027 scp->cpu_addr = dma_alloc_coherent(scp->dev, scp_sizes->max_dram_size, in scp_map_memory_region()
1028 &scp->dma_addr, GFP_KERNEL); in scp_map_memory_region()
1029 if (!scp->cpu_addr) in scp_map_memory_region()
1030 return -ENOMEM; in scp_map_memory_region()
1039 scp_sizes = scp->data->scp_sizes; in scp_unmap_memory_region()
1040 if (scp_sizes->max_dram_size == 0) in scp_unmap_memory_region()
1043 dma_free_coherent(scp->dev, scp_sizes->max_dram_size, scp->cpu_addr, in scp_unmap_memory_region()
1044 scp->dma_addr); in scp_unmap_memory_region()
1045 of_reserved_mem_device_release(scp->dev); in scp_unmap_memory_region()
1080 scp->rpmsg_subdev = in scp_add_rpmsg_subdev()
1081 mtk_rpmsg_create_rproc_subdev(to_platform_device(scp->dev), in scp_add_rpmsg_subdev()
1083 if (scp->rpmsg_subdev) in scp_add_rpmsg_subdev()
1084 rproc_add_subdev(scp->rproc, scp->rpmsg_subdev); in scp_add_rpmsg_subdev()
1089 if (scp->rpmsg_subdev) { in scp_remove_rpmsg_subdev()
1090 rproc_remove_subdev(scp->rproc, scp->rpmsg_subdev); in scp_remove_rpmsg_subdev()
1091 mtk_rpmsg_destroy_rproc_subdev(scp->rpmsg_subdev); in scp_remove_rpmsg_subdev()
1092 scp->rpmsg_subdev = NULL; in scp_remove_rpmsg_subdev()
1100 struct device *dev = &pdev->dev; in scp_rproc_init()
1101 struct device_node *np = dev->of_node; in scp_rproc_init()
1110 if (ret < 0 && ret != -EINVAL) in scp_rproc_init()
1113 rproc = devm_rproc_alloc(dev, np->name, &scp_ops, fw_name, sizeof(*scp)); in scp_rproc_init()
1116 return ERR_PTR(-ENOMEM); in scp_rproc_init()
1119 scp = rproc->priv; in scp_rproc_init()
1120 scp->rproc = rproc; in scp_rproc_init()
1121 scp->dev = dev; in scp_rproc_init()
1122 scp->data = of_data; in scp_rproc_init()
1123 scp->cluster = scp_cluster; in scp_rproc_init()
1126 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "sram"); in scp_rproc_init()
1127 scp->sram_base = devm_ioremap_resource(dev, res); in scp_rproc_init()
1128 if (IS_ERR(scp->sram_base)) { in scp_rproc_init()
1129 dev_err(dev, "Failed to parse and map sram memory\n"); in scp_rproc_init()
1130 return ERR_CAST(scp->sram_base); in scp_rproc_init()
1133 scp->sram_size = resource_size(res); in scp_rproc_init()
1134 scp->sram_phys = res->start; in scp_rproc_init()
1136 ret = scp->data->scp_clk_get(scp); in scp_rproc_init()
1144 mutex_init(&scp->send_lock); in scp_rproc_init()
1146 mutex_init(&scp->ipi_desc[i].lock); in scp_rproc_init()
1155 scp_sizes = scp->data->scp_sizes; in scp_rproc_init()
1156 scp->share_buf = kzalloc(scp_sizes->ipi_share_buffer_size, GFP_KERNEL); in scp_rproc_init()
1157 if (!scp->share_buf) { in scp_rproc_init()
1159 ret = -ENOMEM; in scp_rproc_init()
1163 init_waitqueue_head(&scp->run.wq); in scp_rproc_init()
1164 init_waitqueue_head(&scp->ack_wq); in scp_rproc_init()
1170 pdev->name, scp); in scp_rproc_init()
1182 kfree(scp->share_buf); in scp_rproc_init()
1183 scp->share_buf = NULL; in scp_rproc_init()
1187 mutex_destroy(&scp->ipi_desc[i].lock); in scp_rproc_init()
1188 mutex_destroy(&scp->send_lock); in scp_rproc_init()
1199 kfree(scp->share_buf); in scp_free()
1200 scp->share_buf = NULL; in scp_free()
1203 mutex_destroy(&scp->ipi_desc[i].lock); in scp_free()
1204 mutex_destroy(&scp->send_lock); in scp_free()
1210 struct device *dev = &pdev->dev; in scp_add_single_core()
1211 struct list_head *scp_list = &scp_cluster->mtk_scp_list; in scp_add_single_core()
1219 ret = rproc_add(scp->rproc); in scp_add_single_core()
1226 list_add_tail(&scp->elem, scp_list); in scp_add_single_core()
1234 struct device *dev = &pdev->dev; in scp_add_multi_core()
1238 struct list_head *scp_list = &scp_cluster->mtk_scp_list; in scp_add_multi_core()
1248 ret = -EINVAL; in scp_add_multi_core()
1256 ret = -ENODEV; in scp_add_multi_core()
1257 dev_err(dev, "Not found platform device for core %d\n", core_id); in scp_add_multi_core()
1263 put_device(&cpdev->dev); in scp_add_multi_core()
1271 ret = rproc_add(scp->rproc); in scp_add_multi_core()
1279 list_add_tail(&scp->elem, scp_list); in scp_add_multi_core()
1284 * Here we are setting the platform device for @pdev to the last @scp that was in scp_add_multi_core()
1295 list_del(&scp->elem); in scp_add_multi_core()
1296 rproc_del(scp->rproc); in scp_add_multi_core()
1305 struct device *dev = &pdev->dev; in scp_is_single_core()
1311 if (of_device_is_compatible(child, "mediatek,scp-core")) in scp_is_single_core()
1331 struct device *dev = &pdev->dev; in scp_probe()
1338 return -ENOMEM; in scp_probe()
1340 scp_cluster->reg_base = devm_platform_ioremap_resource_byname(pdev, "cfg"); in scp_probe()
1341 if (IS_ERR(scp_cluster->reg_base)) in scp_probe()
1342 return dev_err_probe(dev, PTR_ERR(scp_cluster->reg_base), in scp_probe()
1348 scp_cluster->l1tcm_base = devm_ioremap_resource(dev, res); in scp_probe()
1349 if (IS_ERR(scp_cluster->l1tcm_base)) in scp_probe()
1350 return dev_err_probe(dev, PTR_ERR(scp_cluster->l1tcm_base), in scp_probe()
1353 scp_cluster->l1tcm_size = resource_size(res); in scp_probe()
1354 scp_cluster->l1tcm_phys = res->start; in scp_probe()
1357 INIT_LIST_HEAD(&scp_cluster->mtk_scp_list); in scp_probe()
1358 mutex_init(&scp_cluster->cluster_lock); in scp_probe()
1374 struct mtk_scp_of_cluster *scp_cluster = scp->cluster; in scp_remove()
1377 list_for_each_entry_safe_reverse(scp, temp, &scp_cluster->mtk_scp_list, elem) { in scp_remove()
1378 list_del(&scp->elem); in scp_remove()
1379 rproc_del(scp->rproc); in scp_remove()
1382 mutex_destroy(&scp_cluster->cluster_lock); in scp_remove()
1511 { .compatible = "mediatek,mt8183-scp", .data = &mt8183_of_data },
1512 { .compatible = "mediatek,mt8186-scp", .data = &mt8186_of_data },
1513 { .compatible = "mediatek,mt8188-scp", .data = &mt8188_of_data },
1514 { .compatible = "mediatek,mt8188-scp-dual", .data = &mt8188_of_data_cores },
1515 { .compatible = "mediatek,mt8192-scp", .data = &mt8192_of_data },
1516 { .compatible = "mediatek,mt8195-scp", .data = &mt8195_of_data },
1517 { .compatible = "mediatek,mt8195-scp-dual", .data = &mt8195_of_data_cores },
1526 .name = "mtk-scp",