Skip to content

Commit c6eda63

Browse files
tinghan-shenmathieupoirier
authored andcommitted
remoteproc: mediatek: Remove dependency of MT8195 SCP L2TCM power control on dual-core SCP
Previously, SCP core 0 controlled the power of L2TCM and dictated that SCP core 1 could only boot after SCP core 0. To address this constraint, extracted the power control flow of L2TCM and made it shared between both cores, enabling support for arbitrary boot order. The flow for controlling L2TCM power has been incorporated into the mt8195_scp_before_load() and mt8195_scp_stop() APIs, which are respectively invoked during the rproc->ops->start() and rproc->ops->stop() operations. These APIs effectively serve the same purpose as the rproc prepare()/unprepare() APIs." Signed-off-by: Tinghan Shen <[email protected]> Reviewed-by: AngeloGioacchino Del Regno <[email protected]> Tested-by: AngeloGioacchino Del Regno <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Mathieu Poirier <[email protected]>
1 parent 1fdbf0c commit c6eda63

File tree

2 files changed

+59
-15
lines changed

2 files changed

+59
-15
lines changed

drivers/remoteproc/mtk_common.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,9 @@ struct mtk_scp_of_cluster {
106106
size_t l1tcm_size;
107107
phys_addr_t l1tcm_phys;
108108
struct list_head mtk_scp_list;
109+
/* Prevent concurrent operations of this structure and L2TCM power control. */
110+
struct mutex cluster_lock;
111+
u32 l2tcm_refcnt;
109112
};
110113

111114
struct mtk_scp {

drivers/remoteproc/mtk_scp.c

Lines changed: 56 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -454,19 +454,37 @@ static int mt8192_scp_before_load(struct mtk_scp *scp)
454454
return 0;
455455
}
456456

457-
static int mt8195_scp_before_load(struct mtk_scp *scp)
457+
static int mt8195_scp_l2tcm_on(struct mtk_scp *scp)
458458
{
459-
/* clear SPM interrupt, SCP2SPM_IPC_CLR */
460-
writel(0xff, scp->cluster->reg_base + MT8192_SCP2SPM_IPC_CLR);
459+
struct mtk_scp_of_cluster *scp_cluster = scp->cluster;
460+
461+
mutex_lock(&scp_cluster->cluster_lock);
462+
463+
if (scp_cluster->l2tcm_refcnt == 0) {
464+
/* clear SPM interrupt, SCP2SPM_IPC_CLR */
465+
writel(0xff, scp->cluster->reg_base + MT8192_SCP2SPM_IPC_CLR);
466+
467+
/* Power on L2TCM */
468+
scp_sram_power_on(scp->cluster->reg_base + MT8192_L2TCM_SRAM_PD_0, 0);
469+
scp_sram_power_on(scp->cluster->reg_base + MT8192_L2TCM_SRAM_PD_1, 0);
470+
scp_sram_power_on(scp->cluster->reg_base + MT8192_L2TCM_SRAM_PD_2, 0);
471+
scp_sram_power_on(scp->cluster->reg_base + MT8192_L1TCM_SRAM_PDN,
472+
MT8195_L1TCM_SRAM_PDN_RESERVED_RSI_BITS);
473+
}
474+
475+
scp_cluster->l2tcm_refcnt += 1;
461476

477+
mutex_unlock(&scp_cluster->cluster_lock);
478+
479+
return 0;
480+
}
481+
482+
static int mt8195_scp_before_load(struct mtk_scp *scp)
483+
{
462484
writel(1, scp->cluster->reg_base + MT8192_CORE0_SW_RSTN_SET);
463485

464-
/* enable SRAM clock */
465-
scp_sram_power_on(scp->cluster->reg_base + MT8192_L2TCM_SRAM_PD_0, 0);
466-
scp_sram_power_on(scp->cluster->reg_base + MT8192_L2TCM_SRAM_PD_1, 0);
467-
scp_sram_power_on(scp->cluster->reg_base + MT8192_L2TCM_SRAM_PD_2, 0);
468-
scp_sram_power_on(scp->cluster->reg_base + MT8192_L1TCM_SRAM_PDN,
469-
MT8195_L1TCM_SRAM_PDN_RESERVED_RSI_BITS);
486+
mt8195_scp_l2tcm_on(scp);
487+
470488
scp_sram_power_on(scp->cluster->reg_base + MT8192_CPU0_SRAM_PD, 0);
471489

472490
/* enable MPU for all memory regions */
@@ -479,6 +497,8 @@ static int mt8195_scp_c1_before_load(struct mtk_scp *scp)
479497
{
480498
scp->data->scp_reset_assert(scp);
481499

500+
mt8195_scp_l2tcm_on(scp);
501+
482502
scp_sram_power_on(scp->cluster->reg_base + MT8195_CPU1_SRAM_PD, 0);
483503

484504
/* enable MPU for all memory regions */
@@ -645,14 +665,31 @@ static void mt8192_scp_stop(struct mtk_scp *scp)
645665
writel(0, scp->cluster->reg_base + MT8192_CORE0_WDT_CFG);
646666
}
647667

668+
static void mt8195_scp_l2tcm_off(struct mtk_scp *scp)
669+
{
670+
struct mtk_scp_of_cluster *scp_cluster = scp->cluster;
671+
672+
mutex_lock(&scp_cluster->cluster_lock);
673+
674+
if (scp_cluster->l2tcm_refcnt > 0)
675+
scp_cluster->l2tcm_refcnt -= 1;
676+
677+
if (scp_cluster->l2tcm_refcnt == 0) {
678+
/* Power off L2TCM */
679+
scp_sram_power_off(scp->cluster->reg_base + MT8192_L2TCM_SRAM_PD_0, 0);
680+
scp_sram_power_off(scp->cluster->reg_base + MT8192_L2TCM_SRAM_PD_1, 0);
681+
scp_sram_power_off(scp->cluster->reg_base + MT8192_L2TCM_SRAM_PD_2, 0);
682+
scp_sram_power_off(scp->cluster->reg_base + MT8192_L1TCM_SRAM_PDN,
683+
MT8195_L1TCM_SRAM_PDN_RESERVED_RSI_BITS);
684+
}
685+
686+
mutex_unlock(&scp_cluster->cluster_lock);
687+
}
688+
648689
static void mt8195_scp_stop(struct mtk_scp *scp)
649690
{
650-
/* Disable SRAM clock */
651-
scp_sram_power_off(scp->cluster->reg_base + MT8192_L2TCM_SRAM_PD_0, 0);
652-
scp_sram_power_off(scp->cluster->reg_base + MT8192_L2TCM_SRAM_PD_1, 0);
653-
scp_sram_power_off(scp->cluster->reg_base + MT8192_L2TCM_SRAM_PD_2, 0);
654-
scp_sram_power_off(scp->cluster->reg_base + MT8192_L1TCM_SRAM_PDN,
655-
MT8195_L1TCM_SRAM_PDN_RESERVED_RSI_BITS);
691+
mt8195_scp_l2tcm_off(scp);
692+
656693
scp_sram_power_off(scp->cluster->reg_base + MT8192_CPU0_SRAM_PD, 0);
657694

658695
/* Disable SCP watchdog */
@@ -661,6 +698,8 @@ static void mt8195_scp_stop(struct mtk_scp *scp)
661698

662699
static void mt8195_scp_c1_stop(struct mtk_scp *scp)
663700
{
701+
mt8195_scp_l2tcm_off(scp);
702+
664703
/* Power off CPU SRAM */
665704
scp_sram_power_off(scp->cluster->reg_base + MT8195_CPU1_SRAM_PD, 0);
666705

@@ -1109,6 +1148,7 @@ static int scp_probe(struct platform_device *pdev)
11091148
}
11101149

11111150
INIT_LIST_HEAD(&scp_cluster->mtk_scp_list);
1151+
mutex_init(&scp_cluster->cluster_lock);
11121152

11131153
ret = devm_of_platform_populate(dev);
11141154
if (ret)
@@ -1132,6 +1172,7 @@ static void scp_remove(struct platform_device *pdev)
11321172
rproc_del(scp->rproc);
11331173
scp_free(scp);
11341174
}
1175+
mutex_destroy(&scp_cluster->cluster_lock);
11351176
}
11361177

11371178
static const struct mtk_scp_of_data mt8183_of_data = {

0 commit comments

Comments
 (0)