Lines Matching full:scp

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.
31 * Return: Return NULL if failed. otherwise reference to SCP.
39 scp_node = of_parse_phandle(dev->of_node, "mediatek,scp", 0); in scp_get()
41 dev_err(dev, "can't get SCP node\n"); in scp_get()
49 dev_err(dev, "SCP pdev failed\n"); in scp_get()
58 * scp_put() - "free" the SCP
60 * @scp: mtk_scp structure from scp_get().
62 void scp_put(struct mtk_scp *scp) in scp_put() argument
64 put_device(scp->dev); in scp_put()
68 static void scp_wdt_handler(struct mtk_scp *scp, u32 scp_to_host) in scp_wdt_handler() argument
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()
82 struct mtk_scp *scp = priv; in scp_init_ipi_handler() local
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()
92 static void scp_ipi_handler(struct mtk_scp *scp) in scp_ipi_handler() argument
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()
101 scp_sizes = scp->data->scp_sizes; in scp_ipi_handler()
103 dev_err(scp->dev, "ipi message too long (len %d, max %zd)", len, in scp_ipi_handler()
108 dev_err(scp->dev, "No such ipi id = %d\n", id); in scp_ipi_handler()
112 scp_ipi_lock(scp, id); in scp_ipi_handler()
115 dev_err(scp->dev, "No handler for ipi id = %d\n", id); in scp_ipi_handler()
116 scp_ipi_unlock(scp, 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()
123 scp_ipi_unlock(scp, id); 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()
129 static int scp_elf_read_ipi_buf_addr(struct mtk_scp *scp,
133 static int scp_ipi_init(struct mtk_scp *scp, const struct firmware *fw) in scp_ipi_init() argument
141 ret = scp_elf_read_ipi_buf_addr(scp, fw, &offset); in scp_ipi_init()
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()
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()
171 static void mt8183_scp_reset_assert(struct mtk_scp *scp) in mt8183_scp_reset_assert() argument
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()
180 static void mt8183_scp_reset_deassert(struct mtk_scp *scp) in mt8183_scp_reset_deassert() argument
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()
189 static void mt8192_scp_reset_assert(struct mtk_scp *scp) in mt8192_scp_reset_assert() argument
191 writel(1, scp->cluster->reg_base + MT8192_CORE0_SW_RSTN_SET); in mt8192_scp_reset_assert()
194 static void mt8192_scp_reset_deassert(struct mtk_scp *scp) in mt8192_scp_reset_deassert() argument
196 writel(1, scp->cluster->reg_base + MT8192_CORE0_SW_RSTN_CLR); in mt8192_scp_reset_deassert()
199 static void mt8195_scp_c1_reset_assert(struct mtk_scp *scp) in mt8195_scp_c1_reset_assert() argument
201 writel(1, scp->cluster->reg_base + MT8195_CORE1_SW_RSTN_SET); in mt8195_scp_c1_reset_assert()
204 static void mt8195_scp_c1_reset_deassert(struct mtk_scp *scp) in mt8195_scp_c1_reset_deassert() argument
206 writel(1, scp->cluster->reg_base + MT8195_CORE1_SW_RSTN_CLR); in mt8195_scp_c1_reset_deassert()
209 static void mt8183_scp_irq_handler(struct mtk_scp *scp) in mt8183_scp_irq_handler() argument
213 scp_to_host = readl(scp->cluster->reg_base + MT8183_SCP_TO_HOST); in mt8183_scp_irq_handler()
215 scp_ipi_handler(scp); in mt8183_scp_irq_handler()
217 scp_wdt_handler(scp, scp_to_host); in mt8183_scp_irq_handler()
219 /* SCP won't send another interrupt until we set SCP_TO_HOST to 0. */ in mt8183_scp_irq_handler()
221 scp->cluster->reg_base + MT8183_SCP_TO_HOST); in mt8183_scp_irq_handler()
224 static void mt8192_scp_irq_handler(struct mtk_scp *scp) in mt8192_scp_irq_handler() argument
228 scp_to_host = readl(scp->cluster->reg_base + MT8192_SCP2APMCU_IPC_SET); in mt8192_scp_irq_handler()
231 scp_ipi_handler(scp); in mt8192_scp_irq_handler()
234 * SCP won't send another interrupt until we clear in mt8192_scp_irq_handler()
238 scp->cluster->reg_base + MT8192_SCP2APMCU_IPC_CLR); in mt8192_scp_irq_handler()
240 scp_wdt_handler(scp, scp_to_host); in mt8192_scp_irq_handler()
241 writel(1, scp->cluster->reg_base + MT8192_CORE0_WDT_IRQ); in mt8192_scp_irq_handler()
245 static void mt8195_scp_irq_handler(struct mtk_scp *scp) in mt8195_scp_irq_handler() argument
249 scp_to_host = readl(scp->cluster->reg_base + MT8192_SCP2APMCU_IPC_SET); in mt8195_scp_irq_handler()
252 scp_ipi_handler(scp); 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()
262 scp_wdt_handler(scp, reason); in mt8195_scp_irq_handler()
265 writel(scp_to_host, scp->cluster->reg_base + MT8192_SCP2APMCU_IPC_CLR); in mt8195_scp_irq_handler()
268 static void mt8195_scp_c1_irq_handler(struct mtk_scp *scp) in mt8195_scp_c1_irq_handler() argument
272 scp_to_host = readl(scp->cluster->reg_base + MT8195_SSHUB2APMCU_IPC_SET); in mt8195_scp_c1_irq_handler()
275 scp_ipi_handler(scp); 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()
282 struct mtk_scp *scp = priv; in scp_irq_handler() local
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()
354 static int scp_elf_read_ipi_buf_addr(struct mtk_scp *scp, in scp_elf_read_ipi_buf_addr() argument
380 static int mt8183_scp_clk_get(struct mtk_scp *scp) in mt8183_scp_clk_get() argument
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()
394 static int mt8192_scp_clk_get(struct mtk_scp *scp) in mt8192_scp_clk_get() argument
396 return mt8183_scp_clk_get(scp); in mt8192_scp_clk_get()
399 static int mt8195_scp_clk_get(struct mtk_scp *scp) in mt8195_scp_clk_get() argument
401 scp->clk = NULL; in mt8195_scp_clk_get()
406 static int mt8183_scp_before_load(struct mtk_scp *scp) in mt8183_scp_before_load() argument
408 /* Clear SCP to host interrupt */ in mt8183_scp_before_load()
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()
451 static int mt8186_scp_before_load(struct mtk_scp *scp) in mt8186_scp_before_load() argument
453 /* Clear SCP to host interrupt */ in mt8186_scp_before_load()
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()
480 static int mt8188_scp_l2tcm_on(struct mtk_scp *scp) in mt8188_scp_l2tcm_on() argument
482 struct mtk_scp_of_cluster *scp_cluster = scp->cluster; 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()
504 static int mt8188_scp_before_load(struct mtk_scp *scp) in mt8188_scp_before_load() argument
506 writel(1, scp->cluster->reg_base + MT8192_CORE0_SW_RSTN_SET); in mt8188_scp_before_load()
508 mt8188_scp_l2tcm_on(scp); 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()
518 static int mt8188_scp_c1_before_load(struct mtk_scp *scp) in mt8188_scp_c1_before_load() argument
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()
526 mt8188_scp_l2tcm_on(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()
537 * This configuration solves booting the SCP core 0 and core 1 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()
541 * The value of L2TCM_OFFSET_RANGE is from the viewpoint of SCP core 1. in mt8188_scp_c1_before_load()
542 * When SCP core 1 issues address within the range (L2TCM_OFFSET_RANGE), 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()
550 writel(scp->sram_phys - scp_c0->sram_phys, scp->cluster->reg_base + MT8195_L2TCM_OFFSET); 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()
560 static int mt8192_scp_before_load(struct mtk_scp *scp) in mt8192_scp_before_load() argument
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()
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()
580 static int mt8195_scp_l2tcm_on(struct mtk_scp *scp) in mt8195_scp_l2tcm_on() argument
582 struct mtk_scp_of_cluster *scp_cluster = scp->cluster; 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()
605 static int mt8195_scp_before_load(struct mtk_scp *scp) in mt8195_scp_before_load() argument
607 writel(1, scp->cluster->reg_base + MT8192_CORE0_SW_RSTN_SET); in mt8195_scp_before_load()
609 mt8195_scp_l2tcm_on(scp); 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()
619 static int mt8195_scp_c1_before_load(struct mtk_scp *scp) in mt8195_scp_c1_before_load() argument
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()
627 mt8195_scp_l2tcm_on(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()
638 * This configuration solves booting the SCP core 0 and core 1 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()
642 * The value of L2TCM_OFFSET_RANGE is from the viewpoint of SCP core 1. in mt8195_scp_c1_before_load()
643 * When SCP core 1 issues address within the range (L2TCM_OFFSET_RANGE), 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()
651 writel(scp->sram_phys - scp_c0->sram_phys, scp->cluster->reg_base + MT8195_L2TCM_OFFSET); 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() local
664 struct device *dev = scp->dev; in scp_load()
667 ret = clk_prepare_enable(scp->clk); in scp_load()
673 /* Hold SCP in reset while loading FW. */ 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() local
690 struct device *dev = scp->dev; in scp_parse_fw()
693 ret = clk_prepare_enable(scp->clk); in scp_parse_fw()
699 ret = scp_ipi_init(scp, fw); in scp_parse_fw()
700 clk_disable_unprepare(scp->clk); in scp_parse_fw()
706 struct mtk_scp *scp = rproc->priv; in scp_start() local
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()
719 scp->data->scp_reset_deassert(scp); in scp_start()
727 dev_err(dev, "wait SCP initialization timeout!\n"); in scp_start()
732 dev_err(dev, "wait SCP interrupted by a signal!\n"); 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()
747 static void *mt8183_scp_da_to_va(struct mtk_scp *scp, u64 da, size_t len) in mt8183_scp_da_to_va() argument
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()
758 offset = da - scp->dma_addr; in mt8183_scp_da_to_va()
760 return scp->cpu_addr + offset; in mt8183_scp_da_to_va()
766 static void *mt8192_scp_da_to_va(struct mtk_scp *scp, u64 da, size_t len) in mt8192_scp_da_to_va() argument
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()
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() local
801 return scp->data->scp_da_to_va(scp, da, len); in scp_da_to_va()
804 static void mt8183_scp_stop(struct mtk_scp *scp) in mt8183_scp_stop() argument
806 /* Disable SCP watchdog */ in mt8183_scp_stop()
807 writel(0, scp->cluster->reg_base + MT8183_WDT_CFG); in mt8183_scp_stop()
810 static void mt8188_scp_l2tcm_off(struct mtk_scp *scp) in mt8188_scp_l2tcm_off() argument
812 struct mtk_scp_of_cluster *scp_cluster = scp->cluster; 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()
830 static void mt8188_scp_stop(struct mtk_scp *scp) in mt8188_scp_stop() argument
832 mt8188_scp_l2tcm_off(scp); in mt8188_scp_stop()
834 scp_sram_power_off(scp->cluster->reg_base + MT8192_CPU0_SRAM_PD, 0); in mt8188_scp_stop()
836 /* Disable SCP watchdog */ in mt8188_scp_stop()
837 writel(0, scp->cluster->reg_base + MT8192_CORE0_WDT_CFG); in mt8188_scp_stop()
840 static void mt8188_scp_c1_stop(struct mtk_scp *scp) in mt8188_scp_c1_stop() argument
842 mt8188_scp_l2tcm_off(scp); in mt8188_scp_c1_stop()
845 scp_sram_power_off(scp->cluster->reg_base + MT8195_CPU1_SRAM_PD, 0); in mt8188_scp_c1_stop()
847 /* Disable SCP watchdog */ in mt8188_scp_c1_stop()
848 writel(0, scp->cluster->reg_base + MT8195_CORE1_WDT_CFG); in mt8188_scp_c1_stop()
851 static void mt8192_scp_stop(struct mtk_scp *scp) in mt8192_scp_stop() argument
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()
860 /* Disable SCP watchdog */ in mt8192_scp_stop()
861 writel(0, scp->cluster->reg_base + MT8192_CORE0_WDT_CFG); in mt8192_scp_stop()
864 static void mt8195_scp_l2tcm_off(struct mtk_scp *scp) in mt8195_scp_l2tcm_off() argument
866 struct mtk_scp_of_cluster *scp_cluster = scp->cluster; 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()
885 static void mt8195_scp_stop(struct mtk_scp *scp) in mt8195_scp_stop() argument
887 mt8195_scp_l2tcm_off(scp); in mt8195_scp_stop()
889 scp_sram_power_off(scp->cluster->reg_base + MT8192_CPU0_SRAM_PD, 0); in mt8195_scp_stop()
891 /* Disable SCP watchdog */ in mt8195_scp_stop()
892 writel(0, scp->cluster->reg_base + MT8192_CORE0_WDT_CFG); in mt8195_scp_stop()
895 static void mt8195_scp_c1_stop(struct mtk_scp *scp) in mt8195_scp_c1_stop() argument
897 mt8195_scp_l2tcm_off(scp); in mt8195_scp_c1_stop()
900 scp_sram_power_off(scp->cluster->reg_base + MT8195_CPU1_SRAM_PD, 0); in mt8195_scp_c1_stop()
902 /* Disable SCP watchdog */ 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() local
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
936 * @scp: mtk_scp structure
938 struct device *scp_get_device(struct mtk_scp *scp) in scp_get_device() argument
940 return scp->dev; in scp_get_device()
945 * scp_get_rproc() - get rproc struct of SCP
947 * @scp: mtk_scp structure
949 struct rproc *scp_get_rproc(struct mtk_scp *scp) in scp_get_rproc() argument
951 return scp->rproc; in scp_get_rproc()
958 * @scp: mtk_scp structure
962 unsigned int scp_get_vdec_hw_capa(struct mtk_scp *scp) in scp_get_vdec_hw_capa() argument
964 return scp->run.dec_capability; in scp_get_vdec_hw_capa()
971 * @scp: mtk_scp structure
975 unsigned int scp_get_venc_hw_capa(struct mtk_scp *scp) in scp_get_venc_hw_capa() argument
977 return scp->run.enc_capability; in scp_get_venc_hw_capa()
984 * @scp: mtk_scp structure
985 * @mem_addr: SCP views memory address
987 * Mapping the SCP's SRAM address /
995 void *scp_mapping_dm_addr(struct mtk_scp *scp, u32 mem_addr) in scp_mapping_dm_addr() argument
999 ptr = scp_da_to_va(scp->rproc, mem_addr, 0, NULL); in scp_mapping_dm_addr()
1007 static int scp_map_memory_region(struct mtk_scp *scp) in scp_map_memory_region() argument
1012 ret = of_reserved_mem_device_init(scp->dev); 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()
1025 /* Reserved SCP code size */ 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()
1035 static void scp_unmap_memory_region(struct mtk_scp *scp) in scp_unmap_memory_region() argument
1039 scp_sizes = scp->data->scp_sizes; 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()
1051 struct mtk_scp *scp = platform_get_drvdata(pdev); in scp_register_ipi() local
1053 return scp_ipi_register(scp, id, handler, priv); in scp_register_ipi()
1058 struct mtk_scp *scp = platform_get_drvdata(pdev); in scp_unregister_ipi() local
1060 scp_ipi_unregister(scp, id); in scp_unregister_ipi()
1066 struct mtk_scp *scp = platform_get_drvdata(pdev); in scp_send_ipi() local
1068 return scp_ipi_send(scp, id, buf, len, wait); in scp_send_ipi()
1078 static void scp_add_rpmsg_subdev(struct mtk_scp *scp) in scp_add_rpmsg_subdev() argument
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()
1087 static void scp_remove_rpmsg_subdev(struct mtk_scp *scp) in scp_remove_rpmsg_subdev() argument
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()
1102 struct mtk_scp *scp; in scp_rproc_init() local
1105 const char *fw_name = "scp.img"; in scp_rproc_init()
1113 rproc = devm_rproc_alloc(dev, np->name, &scp_ops, fw_name, sizeof(*scp)); 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()
1124 platform_set_drvdata(pdev, scp); 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()
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()
1140 ret = scp_map_memory_region(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()
1148 /* register SCP initialization IPI */ in scp_rproc_init()
1149 ret = scp_ipi_register(scp, SCP_IPI_INIT, scp_init_ipi_handler, scp); 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()
1163 init_waitqueue_head(&scp->run.wq); in scp_rproc_init()
1164 init_waitqueue_head(&scp->ack_wq); in scp_rproc_init()
1166 scp_add_rpmsg_subdev(scp); in scp_rproc_init()
1170 pdev->name, scp); in scp_rproc_init()
1177 return scp; in scp_rproc_init()
1180 scp_remove_rpmsg_subdev(scp); in scp_rproc_init()
1181 scp_ipi_unregister(scp, SCP_IPI_INIT); in scp_rproc_init()
1182 kfree(scp->share_buf); in scp_rproc_init()
1183 scp->share_buf = NULL; in scp_rproc_init()
1185 scp_unmap_memory_region(scp); 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()
1193 static void scp_free(struct mtk_scp *scp) in scp_free() argument
1197 scp_remove_rpmsg_subdev(scp); in scp_free()
1198 scp_ipi_unregister(scp, SCP_IPI_INIT); in scp_free()
1199 kfree(scp->share_buf); in scp_free()
1200 scp->share_buf = NULL; in scp_free()
1201 scp_unmap_memory_region(scp); in scp_free()
1203 mutex_destroy(&scp->ipi_desc[i].lock); in scp_free()
1204 mutex_destroy(&scp->send_lock); in scp_free()
1212 struct mtk_scp *scp; in scp_add_single_core() local
1215 scp = scp_rproc_init(pdev, scp_cluster, of_device_get_match_data(dev)); in scp_add_single_core()
1216 if (IS_ERR(scp)) in scp_add_single_core()
1217 return PTR_ERR(scp); in scp_add_single_core()
1219 ret = rproc_add(scp->rproc); in scp_add_single_core()
1222 scp_free(scp); in scp_add_single_core()
1226 list_add_tail(&scp->elem, scp_list); in scp_add_single_core()
1240 struct mtk_scp *scp, *temp; in scp_add_multi_core() local
1262 scp = scp_rproc_init(cpdev, scp_cluster, cluster_of_data[core_id]); in scp_add_multi_core()
1264 if (IS_ERR(scp)) { in scp_add_multi_core()
1265 ret = PTR_ERR(scp); in scp_add_multi_core()
1271 ret = rproc_add(scp->rproc); in scp_add_multi_core()
1275 scp_free(scp); 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()
1289 platform_set_drvdata(pdev, scp); in scp_add_multi_core()
1294 list_for_each_entry_safe_reverse(scp, temp, scp_list, elem) { 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()
1297 scp_free(scp); in scp_add_multi_core()
1311 if (of_device_is_compatible(child, "mediatek,scp-core")) in scp_is_single_core()
1373 struct mtk_scp *scp = platform_get_drvdata(pdev); in scp_remove() local
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()
1380 scp_free(scp); 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",
1534 MODULE_DESCRIPTION("MediaTek SCP control driver");