2023-04-26 09:14:39

by Tinghan Shen

[permalink] [raw]
Subject: [PATCH v10 00/11] Add support for MT8195 SCP 2nd core

The mediatek remoteproc driver currently only allows bringing up a
single core SCP, e.g. MT8183. It also only bringing up the 1st
core in SoCs with a dual-core SCP, e.g. MT8195. This series support
to bring-up the 2nd core of the dual-core SCP.

v9 -> v10:
1. move the global mtk_scp list into the platform device driver data structure
2. remove an unnecessary if() condition

v8 -> v9:
1. initialize l1tcm_size/l1tcm_phys at patchset 05/11
2. rewrite patchset 06/11 to unify the flow and remove hacks

v7 -> v8:
1. update the node name of mt8192 asurada SCP rpmsg subnode
2. squash register definitions into driver patches
3. initialize local variables on the declaration at patch v8 06/11

v6 -> v7:
1. merge the mtk_scp_cluster struct into the mtk_scp structure
at the "Probe multi-core SCP" patch

v5 -> v6:
1. move the mtk_scp_of_regs structure from mtk_common.h to mtk_scp.c
2. rename the SCP core 0 label from 'scp' to 'scp_c0'

v4 -> v5:
1. move resource release actions to the platform driver remove operation
2. fix dual-core watchdog handling

v3 -> v4:
1. change the representation of dual-core SCP in dts file and update SCP yaml
2. rewrite SCP driver to reflect the change of dts node
3. drop 'remove redundant call of rproc_boot for SCP' in v3 for further investigation

v2 -> v3:
1. change the representation of dual-core SCP in dts file and update SCP yaml
2. rewrite SCP driver to reflect the change of dts node
3. add SCP core 1 node to mt8195.dtsi
4. remove redundant call of rproc_boot for SCP
5. refine IPI error message

v1 -> v2:
1. update dt-binding property description
2. remove kconfig for scp dual driver
3. merge mtk_scp_dual.c and mtk_scp_subdev.c to mtk_scp.c

Tinghan Shen (11):
dt-bindings: remoteproc: mediatek: Improve the rpmsg subnode
definition
arm64: dts: mediatek: Update the node name of SCP rpmsg subnode
dt-bindings: remoteproc: mediatek: Support MT8195 dual-core SCP
remoteproc: mediatek: Add MT8195 SCP core 1 operations
remoteproc: mediatek: Extract remoteproc initialization flow
remoteproc: mediatek: Probe multi-core SCP
remoteproc: mediatek: Control SCP core 1 by rproc subdevice
remoteproc: mediatek: Setup MT8195 SCP core 1 SRAM offset
remoteproc: mediatek: Handle MT8195 SCP core 1 watchdog timeout
remoteproc: mediatek: Refine ipi handler error message
arm64: dts: mediatek: mt8195: Add SCP 2nd core

.../bindings/remoteproc/mtk,scp.yaml | 176 +++++++-
.../arm64/boot/dts/mediatek/mt8183-kukui.dtsi | 2 +-
.../boot/dts/mediatek/mt8192-asurada.dtsi | 2 +-
.../boot/dts/mediatek/mt8195-cherry.dtsi | 6 +-
arch/arm64/boot/dts/mediatek/mt8195.dtsi | 32 +-
drivers/remoteproc/mtk_common.h | 33 ++
drivers/remoteproc/mtk_scp.c | 415 ++++++++++++++++--
7 files changed, 604 insertions(+), 62 deletions(-)

--
2.18.0


2023-04-26 09:14:44

by Tinghan Shen

[permalink] [raw]
Subject: [PATCH v10 09/11] remoteproc: mediatek: Handle MT8195 SCP core 1 watchdog timeout

The MT8195 SCP core 1 watchdog timeout needs to be handled in the
SCP core 0 IRQ handler because the MT8195 SCP core 1 watchdog timeout
IRQ is wired on the same IRQ entry for core 0 watchdog timeout.
MT8195 SCP has a watchdog status register to identify the watchdog
timeout source when IRQ triggered.

Signed-off-by: Tinghan Shen <[email protected]>
Reviewed-by: AngeloGioacchino Del Regno <[email protected]>
---
drivers/remoteproc/mtk_common.h | 5 +++++
drivers/remoteproc/mtk_scp.c | 25 ++++++++++++++++++++++++-
2 files changed, 29 insertions(+), 1 deletion(-)

diff --git a/drivers/remoteproc/mtk_common.h b/drivers/remoteproc/mtk_common.h
index 6861543a0825..1e148cbad0fb 100644
--- a/drivers/remoteproc/mtk_common.h
+++ b/drivers/remoteproc/mtk_common.h
@@ -55,6 +55,10 @@
#define MT8192_CORE0_WDT_IRQ 0x10030
#define MT8192_CORE0_WDT_CFG 0x10034

+#define MT8195_SYS_STATUS 0x4004
+#define MT8195_CORE0_WDT BIT(16)
+#define MT8195_CORE1_WDT BIT(17)
+
#define MT8195_L1TCM_SRAM_PDN_RESERVED_RSI_BITS GENMASK(7, 4)

#define MT8195_CPU1_SRAM_PD 0x1084
@@ -63,6 +67,7 @@
#define MT8195_CORE1_SW_RSTN_CLR 0x20000
#define MT8195_CORE1_SW_RSTN_SET 0x20004
#define MT8195_CORE1_MEM_ATT_PREDEF 0x20008
+#define MT8195_CORE1_WDT_IRQ 0x20030
#define MT8195_CORE1_WDT_CFG 0x20034

#define MT8195_SEC_CTRL 0x85000
diff --git a/drivers/remoteproc/mtk_scp.c b/drivers/remoteproc/mtk_scp.c
index 12175ee55844..b9cac76b71fd 100644
--- a/drivers/remoteproc/mtk_scp.c
+++ b/drivers/remoteproc/mtk_scp.c
@@ -230,6 +230,29 @@ static void mt8192_scp_irq_handler(struct mtk_scp *scp)
}
}

+static void mt8195_scp_irq_handler(struct mtk_scp *scp)
+{
+ u32 scp_to_host;
+
+ scp_to_host = readl(scp->reg_base + MT8192_SCP2APMCU_IPC_SET);
+
+ if (scp_to_host & MT8192_SCP_IPC_INT_BIT) {
+ scp_ipi_handler(scp);
+ } else {
+ u32 reason = readl(scp->reg_base + MT8195_SYS_STATUS);
+
+ if (reason & MT8195_CORE0_WDT)
+ writel(1, scp->reg_base + MT8192_CORE0_WDT_IRQ);
+
+ if (reason & MT8195_CORE1_WDT)
+ writel(1, scp->reg_base + MT8195_CORE1_WDT_IRQ);
+
+ scp_wdt_handler(scp, reason);
+ }
+
+ writel(scp_to_host, scp->reg_base + MT8192_SCP2APMCU_IPC_CLR);
+}
+
static void mt8195_scp_c1_irq_handler(struct mtk_scp *scp)
{
u32 scp_to_host;
@@ -1293,7 +1316,7 @@ static const struct mtk_scp_of_data mt8192_of_data = {
static const struct mtk_scp_of_data mt8195_of_data = {
.scp_clk_get = mt8195_scp_clk_get,
.scp_before_load = mt8195_scp_before_load,
- .scp_irq_handler = mt8192_scp_irq_handler,
+ .scp_irq_handler = mt8195_scp_irq_handler,
.scp_reset_assert = mt8192_scp_reset_assert,
.scp_reset_deassert = mt8192_scp_reset_deassert,
.scp_stop = mt8195_scp_stop,
--
2.18.0

2023-04-26 09:14:48

by Tinghan Shen

[permalink] [raw]
Subject: [PATCH v10 06/11] remoteproc: mediatek: Probe multi-core SCP

The difference of single-core SCP and multi-core SCP device tree is
the presence of child device nodes described SCP cores. The SCP
driver populates the platform device and checks the child nodes
to identify whether it's a single-core SCP or a multi-core SCP.

Add the remoteproc instances for single-core SCP and multi-core SCP to
the new added SCP cluster list. When the SCP driver is removed, it
cleanup resources by walking through the cluster list.

Signed-off-by: Tinghan Shen <[email protected]>
---
drivers/remoteproc/mtk_common.h | 3 +
drivers/remoteproc/mtk_scp.c | 188 ++++++++++++++++++++++++++++----
2 files changed, 172 insertions(+), 19 deletions(-)

diff --git a/drivers/remoteproc/mtk_common.h b/drivers/remoteproc/mtk_common.h
index c0905aec3b4b..b73b60c22ea1 100644
--- a/drivers/remoteproc/mtk_common.h
+++ b/drivers/remoteproc/mtk_common.h
@@ -128,6 +128,9 @@ struct mtk_scp {
size_t dram_size;

struct rproc_subdev *rpmsg_subdev;
+
+ struct list_head elem;
+ struct list_head *cluster;
};

/**
diff --git a/drivers/remoteproc/mtk_scp.c b/drivers/remoteproc/mtk_scp.c
index 5e4982f4d5dc..0b052b0acf2e 100644
--- a/drivers/remoteproc/mtk_scp.c
+++ b/drivers/remoteproc/mtk_scp.c
@@ -28,6 +28,7 @@ struct mtk_scp_of_cluster {
void __iomem *l1tcm_base;
size_t l1tcm_size;
phys_addr_t l1tcm_phys;
+ struct list_head mtk_scp_cluster;
};

/**
@@ -862,21 +863,31 @@ static void scp_remove_rpmsg_subdev(struct mtk_scp *scp)
}
}

-static int scp_rproc_init(struct platform_device *pdev)
+static int scp_rproc_init(struct platform_device *cluster_pdev,
+ struct platform_device *core_pdev,
+ const struct mtk_scp_of_data *of_data)
{
- struct device *dev = &pdev->dev;
- struct device_node *np = dev->of_node;
- struct mtk_scp_of_cluster *of_cluster = platform_get_drvdata(pdev);
+ struct platform_device *pdev;
+ struct device *dev;
+ struct device_node *np;
+ struct mtk_scp_of_cluster *of_cluster = platform_get_drvdata(cluster_pdev);
struct mtk_scp *scp;
struct rproc *rproc;
struct resource *res;
const char *fw_name = "scp.img";
int ret, i;

+ if (core_pdev)
+ pdev = core_pdev;
+ else
+ pdev = cluster_pdev;
+
+ dev = &pdev->dev;
ret = rproc_of_parse_firmware(dev, 0, &fw_name);
if (ret < 0 && ret != -EINVAL)
return ret;

+ np = dev->of_node;
rproc = devm_rproc_alloc(dev, np->name, &scp_ops, fw_name, sizeof(*scp));
if (!rproc)
return dev_err_probe(dev, -ENOMEM, "unable to allocate remoteproc\n");
@@ -884,7 +895,7 @@ static int scp_rproc_init(struct platform_device *pdev)
scp = rproc->priv;
scp->rproc = rproc;
scp->dev = dev;
- scp->data = of_device_get_match_data(dev);
+ scp->data = of_data;
platform_set_drvdata(pdev, scp);

scp->reg_base = of_cluster->reg_base;
@@ -934,10 +945,6 @@ static int scp_rproc_init(struct platform_device *pdev)
goto remove_subdev;
}

- ret = rproc_add(rproc);
- if (ret)
- goto remove_subdev;
-
return 0;

remove_subdev:
@@ -952,6 +959,121 @@ static int scp_rproc_init(struct platform_device *pdev)
return ret;
}

+static void scp_rproc_free(struct mtk_scp *scp)
+{
+ int i;
+
+ scp_remove_rpmsg_subdev(scp);
+ scp_ipi_unregister(scp, SCP_IPI_INIT);
+ scp_unmap_memory_region(scp);
+ for (i = 0; i < SCP_IPI_MAX; i++)
+ mutex_destroy(&scp->ipi_desc[i].lock);
+ mutex_destroy(&scp->send_lock);
+}
+
+static int scp_is_single_core(struct platform_device *pdev)
+{
+ struct device *dev = &pdev->dev;
+ struct device_node *np = dev_of_node(dev);
+ struct device_node *child;
+
+ child = of_get_next_available_child(np, NULL);
+ if (!child)
+ return dev_err_probe(dev, -ENODEV, "No child node\n");
+
+ of_node_put(child);
+ return of_node_name_eq(child, "cros-ec-rpmsg");
+}
+
+static int scp_cluster_init(struct platform_device *pdev)
+{
+ struct device *dev = &pdev->dev;
+ struct device_node *np = dev_of_node(dev);
+ struct platform_device *cpdev;
+ struct device_node *child;
+ struct mtk_scp_of_cluster *of_cluster = platform_get_drvdata(pdev);
+ const struct mtk_scp_of_data **cluster_of_data;
+ struct list_head *cluster = &of_cluster->mtk_scp_cluster;
+ struct mtk_scp *scp, *temp;
+ int core_id = 0;
+ int ret;
+
+ ret = scp_is_single_core(pdev);
+ if (ret < 0)
+ return ret;
+
+ if (ret) {
+ dev_dbg(dev, "single-core scp\n");
+
+ /* When using the SCP node phandle on exported SCP APIs, the drvdata
+ * is expected to be the mtk_scp object, and as a result, it is intended
+ * to be overwritten for single-core SCP usage.
+ */
+ ret = scp_rproc_init(pdev, NULL, of_device_get_match_data(dev));
+ if (ret)
+ return dev_err_probe(dev, ret, "Failed to initialize single-core scp\n");
+
+ scp = platform_get_drvdata(pdev);
+ list_add_tail(&scp->elem, cluster);
+ scp->cluster = cluster;
+ } else {
+ dev_dbg(dev, "multi-core scp\n");
+
+ cluster_of_data = (const struct mtk_scp_of_data **)of_device_get_match_data(dev);
+
+ for_each_available_child_of_node(np, child) {
+ if (!cluster_of_data[core_id]) {
+ ret = -EINVAL;
+ dev_err(dev, "Not support core %d\n", core_id);
+ of_node_put(child);
+ goto init_fail;
+ }
+
+ cpdev = of_find_device_by_node(child);
+ if (!cpdev) {
+ ret = -ENODEV;
+ dev_err(dev, "Not found platform device for core %d\n", core_id);
+ of_node_put(child);
+ goto init_fail;
+ }
+
+ ret = scp_rproc_init(pdev, cpdev, cluster_of_data[core_id]);
+ if (ret) {
+ dev_err(dev, "Failed to initialize core %d rproc\n", core_id);
+ put_device(&cpdev->dev);
+ of_node_put(child);
+ goto init_fail;
+ }
+ scp = platform_get_drvdata(cpdev);
+ list_add_tail(&scp->elem, cluster);
+ scp->cluster = cluster;
+ put_device(&cpdev->dev);
+
+ core_id++;
+ }
+ }
+
+ list_for_each_entry_safe_reverse(scp, temp, cluster, elem) {
+ ret = rproc_add(scp->rproc);
+ if (ret)
+ goto add_fail;
+ }
+
+ return 0;
+
+add_fail:
+ list_for_each_entry_continue(scp, cluster, elem) {
+ rproc_del(scp->rproc);
+ }
+init_fail:
+ list_for_each_entry_safe_reverse(scp, temp, cluster, elem) {
+ list_del(&scp->elem);
+ scp_rproc_free(scp);
+ }
+
+ return ret;
+}
+
static int scp_probe(struct platform_device *pdev)
{
struct device *dev = &pdev->dev;
@@ -983,23 +1105,44 @@ static int scp_probe(struct platform_device *pdev)
of_cluster->l1tcm_phys = res->start;
}

+ INIT_LIST_HEAD(&of_cluster->mtk_scp_cluster);
platform_set_drvdata(pdev, of_cluster);

- return scp_rproc_init(pdev);
+ ret = devm_of_platform_populate(dev);
+ if (ret)
+ return dev_err_probe(dev, ret, "Failed to populate platform devices\n");
+
+ ret = scp_cluster_init(pdev);
+ if (ret)
+ return dev_err_probe(dev, ret, "Failed to initialize scp cluster\n");
+
+ return 0;
}

static int scp_remove(struct platform_device *pdev)
{
- struct mtk_scp *scp = platform_get_drvdata(pdev);
- int i;
+ struct mtk_scp *scp, *temp;
+ struct mtk_scp_of_cluster *of_cluster;
+ struct list_head *cluster;
+ int ret;

- rproc_del(scp->rproc);
- scp_remove_rpmsg_subdev(scp);
- scp_ipi_unregister(scp, SCP_IPI_INIT);
- scp_unmap_memory_region(scp);
- for (i = 0; i < SCP_IPI_MAX; i++)
- mutex_destroy(&scp->ipi_desc[i].lock);
- mutex_destroy(&scp->send_lock);
+ ret = scp_is_single_core(pdev);
+ if (ret < 0)
+ return ret;
+
+ if (ret) {
+ scp = platform_get_drvdata(pdev);
+ cluster = scp->cluster;
+ } else {
+ of_cluster = platform_get_drvdata(pdev);
+ cluster = &of_cluster->mtk_scp_cluster;
+ }
+
+ list_for_each_entry_safe_reverse(scp, temp, cluster, elem) {
+ list_del(&scp->elem);
+ rproc_del(scp->rproc);
+ scp_rproc_free(scp);
+ }

return 0;
}
@@ -1078,12 +1221,19 @@ static const struct mtk_scp_of_data mt8195_of_data_c1 = {
.host_to_scp_int_bit = MT8195_CORE1_HOST_IPC_INT_BIT,
};

+static const struct mtk_scp_of_data *mt8195_of_data_cores[] = {
+ &mt8195_of_data,
+ &mt8195_of_data_c1,
+ NULL
+};
+
static const struct of_device_id mtk_scp_of_match[] = {
{ .compatible = "mediatek,mt8183-scp", .data = &mt8183_of_data },
{ .compatible = "mediatek,mt8186-scp", .data = &mt8186_of_data },
{ .compatible = "mediatek,mt8188-scp", .data = &mt8188_of_data },
{ .compatible = "mediatek,mt8192-scp", .data = &mt8192_of_data },
{ .compatible = "mediatek,mt8195-scp", .data = &mt8195_of_data },
+ { .compatible = "mediatek,mt8195-scp-dual", .data = &mt8195_of_data_cores },
{},
};
MODULE_DEVICE_TABLE(of, mtk_scp_of_match);
--
2.18.0

2023-04-26 09:14:53

by Tinghan Shen

[permalink] [raw]
Subject: [PATCH v10 11/11] arm64: dts: mediatek: mt8195: Add SCP 2nd core

Rewrite the MT8195 SCP device node as a cluster and
add the SCP 2nd core in it.

Since the SCP device node is changed to multi-core structure,
enable SCP cluster to enable probing SCP core 0.

Signed-off-by: Tinghan Shen <[email protected]>
Reviewed-by: AngeloGioacchino Del Regno <[email protected]>
---
.../boot/dts/mediatek/mt8195-cherry.dtsi | 6 +++-
arch/arm64/boot/dts/mediatek/mt8195.dtsi | 32 ++++++++++++++-----
2 files changed, 29 insertions(+), 9 deletions(-)

diff --git a/arch/arm64/boot/dts/mediatek/mt8195-cherry.dtsi b/arch/arm64/boot/dts/mediatek/mt8195-cherry.dtsi
index 8ac80a136c37..8addb94a24a1 100644
--- a/arch/arm64/boot/dts/mediatek/mt8195-cherry.dtsi
+++ b/arch/arm64/boot/dts/mediatek/mt8195-cherry.dtsi
@@ -962,7 +962,11 @@
interrupts-extended = <&pio 222 IRQ_TYPE_LEVEL_HIGH>;
};

-&scp {
+&scp_cluster {
+ status = "okay";
+};
+
+&scp_c0 {
status = "okay";

firmware-name = "mediatek/mt8195/scp.img";
diff --git a/arch/arm64/boot/dts/mediatek/mt8195.dtsi b/arch/arm64/boot/dts/mediatek/mt8195.dtsi
index a44aae4ab953..10947b4b4707 100644
--- a/arch/arm64/boot/dts/mediatek/mt8195.dtsi
+++ b/arch/arm64/boot/dts/mediatek/mt8195.dtsi
@@ -916,14 +916,30 @@
clocks = <&infracfg_ao CLK_INFRA_AO_GCE2>;
};

- scp: scp@10500000 {
- compatible = "mediatek,mt8195-scp";
- reg = <0 0x10500000 0 0x100000>,
- <0 0x10720000 0 0xe0000>,
- <0 0x10700000 0 0x8000>;
- reg-names = "sram", "cfg", "l1tcm";
- interrupts = <GIC_SPI 462 IRQ_TYPE_LEVEL_HIGH 0>;
+ scp_cluster: scp@10500000 {
+ compatible = "mediatek,mt8195-scp-dual";
+ reg = <0 0x10720000 0 0xe0000>, <0 0x10700000 0 0x8000>;
+ reg-names = "cfg", "l1tcm";
+ #address-cells = <1>;
+ #size-cells = <1>;
+ ranges = <0 0 0x10500000 0x100000>;
status = "disabled";
+
+ scp_c0: scp@0 {
+ compatible = "mediatek,scp-core";
+ reg = <0x0 0xa0000>;
+ reg-names = "sram";
+ interrupts = <GIC_SPI 462 IRQ_TYPE_LEVEL_HIGH 0>;
+ status = "disabled";
+ };
+
+ scp_c1: scp@a0000 {
+ compatible = "mediatek,scp-core";
+ reg = <0xa0000 0x20000>;
+ reg-names = "sram";
+ interrupts = <GIC_SPI 463 IRQ_TYPE_LEVEL_HIGH 0>;
+ status = "disabled";
+ };
};

scp_adsp: clock-controller@10720000 {
@@ -2464,7 +2480,7 @@
<&iommu_vdo M4U_PORT_L19_VENC_REF_LUMA>,
<&iommu_vdo M4U_PORT_L19_VENC_REF_CHROMA>;
interrupts = <GIC_SPI 341 IRQ_TYPE_LEVEL_HIGH 0>;
- mediatek,scp = <&scp>;
+ mediatek,scp = <&scp_c0>;
clocks = <&vencsys CLK_VENC_VENC>;
clock-names = "venc_sel";
assigned-clocks = <&topckgen CLK_TOP_VENC>;
--
2.18.0

2023-04-26 09:15:12

by Tinghan Shen

[permalink] [raw]
Subject: [PATCH v10 04/11] remoteproc: mediatek: Add MT8195 SCP core 1 operations

The SCP rproc driver has a set of chip dependent callbacks for
boot sequence and IRQ handling. Implement these callbacks for MT8195
SCP core 1.

Signed-off-by: Tinghan Shen <[email protected]>
Reviewed-by: AngeloGioacchino Del Regno <[email protected]>
---
drivers/remoteproc/mtk_common.h | 9 ++++++
drivers/remoteproc/mtk_scp.c | 56 +++++++++++++++++++++++++++++++++
2 files changed, 65 insertions(+)

diff --git a/drivers/remoteproc/mtk_common.h b/drivers/remoteproc/mtk_common.h
index ea6fa1100a00..c0905aec3b4b 100644
--- a/drivers/remoteproc/mtk_common.h
+++ b/drivers/remoteproc/mtk_common.h
@@ -47,6 +47,7 @@
#define MT8192_SCP2SPM_IPC_CLR 0x4094
#define MT8192_GIPC_IN_SET 0x4098
#define MT8192_HOST_IPC_INT_BIT BIT(0)
+#define MT8195_CORE1_HOST_IPC_INT_BIT BIT(4)

#define MT8192_CORE0_SW_RSTN_CLR 0x10000
#define MT8192_CORE0_SW_RSTN_SET 0x10004
@@ -56,6 +57,14 @@

#define MT8195_L1TCM_SRAM_PDN_RESERVED_RSI_BITS GENMASK(7, 4)

+#define MT8195_CPU1_SRAM_PD 0x1084
+#define MT8195_SSHUB2APMCU_IPC_SET 0x4088
+#define MT8195_SSHUB2APMCU_IPC_CLR 0x408C
+#define MT8195_CORE1_SW_RSTN_CLR 0x20000
+#define MT8195_CORE1_SW_RSTN_SET 0x20004
+#define MT8195_CORE1_MEM_ATT_PREDEF 0x20008
+#define MT8195_CORE1_WDT_CFG 0x20034
+
#define SCP_FW_VER_LEN 32
#define SCP_SHARE_BUFFER_SIZE 288

diff --git a/drivers/remoteproc/mtk_scp.c b/drivers/remoteproc/mtk_scp.c
index e1d93e63d7df..2bf66b1a8d80 100644
--- a/drivers/remoteproc/mtk_scp.c
+++ b/drivers/remoteproc/mtk_scp.c
@@ -176,6 +176,16 @@ static void mt8192_scp_reset_deassert(struct mtk_scp *scp)
writel(1, scp->reg_base + MT8192_CORE0_SW_RSTN_CLR);
}

+static void mt8195_scp_c1_reset_assert(struct mtk_scp *scp)
+{
+ writel(1, scp->reg_base + MT8195_CORE1_SW_RSTN_SET);
+}
+
+static void mt8195_scp_c1_reset_deassert(struct mtk_scp *scp)
+{
+ writel(1, scp->reg_base + MT8195_CORE1_SW_RSTN_CLR);
+}
+
static void mt8183_scp_irq_handler(struct mtk_scp *scp)
{
u32 scp_to_host;
@@ -212,6 +222,18 @@ static void mt8192_scp_irq_handler(struct mtk_scp *scp)
}
}

+static void mt8195_scp_c1_irq_handler(struct mtk_scp *scp)
+{
+ u32 scp_to_host;
+
+ scp_to_host = readl(scp->reg_base + MT8195_SSHUB2APMCU_IPC_SET);
+
+ if (scp_to_host & MT8192_SCP_IPC_INT_BIT)
+ scp_ipi_handler(scp);
+
+ writel(scp_to_host, scp->reg_base + MT8195_SSHUB2APMCU_IPC_CLR);
+}
+
static irqreturn_t scp_irq_handler(int irq, void *priv)
{
struct mtk_scp *scp = priv;
@@ -453,6 +475,19 @@ static int mt8195_scp_before_load(struct mtk_scp *scp)
return 0;
}

+static int mt8195_scp_c1_before_load(struct mtk_scp *scp)
+{
+ scp_sram_power_on(scp->reg_base + MT8195_CPU1_SRAM_PD, 0);
+
+ /* hold SCP in reset while loading FW. */
+ scp->data->scp_reset_assert(scp);
+
+ /* enable MPU for all memory regions */
+ writel(0xff, scp->reg_base + MT8195_CORE1_MEM_ATT_PREDEF);
+
+ return 0;
+}
+
static int scp_load(struct rproc *rproc, const struct firmware *fw)
{
struct mtk_scp *scp = rproc->priv;
@@ -625,6 +660,15 @@ static void mt8195_scp_stop(struct mtk_scp *scp)
writel(0, scp->reg_base + MT8192_CORE0_WDT_CFG);
}

+static void mt8195_scp_c1_stop(struct mtk_scp *scp)
+{
+ /* Power off CPU SRAM */
+ scp_sram_power_off(scp->reg_base + MT8195_CPU1_SRAM_PD, 0);
+
+ /* Disable SCP watchdog */
+ writel(0, scp->reg_base + MT8195_CORE1_WDT_CFG);
+}
+
static int scp_stop(struct rproc *rproc)
{
struct mtk_scp *scp = rproc->priv;
@@ -991,6 +1035,18 @@ static const struct mtk_scp_of_data mt8195_of_data = {
.host_to_scp_int_bit = MT8192_HOST_IPC_INT_BIT,
};

+static const struct mtk_scp_of_data mt8195_of_data_c1 = {
+ .scp_clk_get = mt8195_scp_clk_get,
+ .scp_before_load = mt8195_scp_c1_before_load,
+ .scp_irq_handler = mt8195_scp_c1_irq_handler,
+ .scp_reset_assert = mt8195_scp_c1_reset_assert,
+ .scp_reset_deassert = mt8195_scp_c1_reset_deassert,
+ .scp_stop = mt8195_scp_c1_stop,
+ .scp_da_to_va = mt8192_scp_da_to_va,
+ .host_to_scp_reg = MT8192_GIPC_IN_SET,
+ .host_to_scp_int_bit = MT8195_CORE1_HOST_IPC_INT_BIT,
+};
+
static const struct of_device_id mtk_scp_of_match[] = {
{ .compatible = "mediatek,mt8183-scp", .data = &mt8183_of_data },
{ .compatible = "mediatek,mt8186-scp", .data = &mt8186_of_data },
--
2.18.0

2023-05-01 22:31:50

by Mathieu Poirier

[permalink] [raw]
Subject: Re: [PATCH v10 06/11] remoteproc: mediatek: Probe multi-core SCP

On Wed, Apr 26, 2023 at 05:12:06PM +0800, Tinghan Shen wrote:
> The difference of single-core SCP and multi-core SCP device tree is
> the presence of child device nodes described SCP cores. The SCP
> driver populates the platform device and checks the child nodes
> to identify whether it's a single-core SCP or a multi-core SCP.
>
> Add the remoteproc instances for single-core SCP and multi-core SCP to
> the new added SCP cluster list. When the SCP driver is removed, it
> cleanup resources by walking through the cluster list.
>
> Signed-off-by: Tinghan Shen <[email protected]>
> ---
> drivers/remoteproc/mtk_common.h | 3 +
> drivers/remoteproc/mtk_scp.c | 188 ++++++++++++++++++++++++++++----
> 2 files changed, 172 insertions(+), 19 deletions(-)
>
> diff --git a/drivers/remoteproc/mtk_common.h b/drivers/remoteproc/mtk_common.h
> index c0905aec3b4b..b73b60c22ea1 100644
> --- a/drivers/remoteproc/mtk_common.h
> +++ b/drivers/remoteproc/mtk_common.h
> @@ -128,6 +128,9 @@ struct mtk_scp {
> size_t dram_size;
>
> struct rproc_subdev *rpmsg_subdev;
> +
> + struct list_head elem;
> + struct list_head *cluster;
> };
>
> /**
> diff --git a/drivers/remoteproc/mtk_scp.c b/drivers/remoteproc/mtk_scp.c
> index 5e4982f4d5dc..0b052b0acf2e 100644
> --- a/drivers/remoteproc/mtk_scp.c
> +++ b/drivers/remoteproc/mtk_scp.c
> @@ -28,6 +28,7 @@ struct mtk_scp_of_cluster {
> void __iomem *l1tcm_base;
> size_t l1tcm_size;
> phys_addr_t l1tcm_phys;
> + struct list_head mtk_scp_cluster;
> };
>
> /**
> @@ -862,21 +863,31 @@ static void scp_remove_rpmsg_subdev(struct mtk_scp *scp)
> }
> }
>
> -static int scp_rproc_init(struct platform_device *pdev)
> +static int scp_rproc_init(struct platform_device *cluster_pdev,
> + struct platform_device *core_pdev,
> + const struct mtk_scp_of_data *of_data)
> {
> - struct device *dev = &pdev->dev;
> - struct device_node *np = dev->of_node;
> - struct mtk_scp_of_cluster *of_cluster = platform_get_drvdata(pdev);
> + struct platform_device *pdev;
> + struct device *dev;
> + struct device_node *np;
> + struct mtk_scp_of_cluster *of_cluster = platform_get_drvdata(cluster_pdev);
> struct mtk_scp *scp;
> struct rproc *rproc;
> struct resource *res;
> const char *fw_name = "scp.img";
> int ret, i;
>
> + if (core_pdev)
> + pdev = core_pdev;
> + else
> + pdev = cluster_pdev;

After following my comment from the previous patch, there won't be a need to do
this.

> +
> + dev = &pdev->dev;
> ret = rproc_of_parse_firmware(dev, 0, &fw_name);
> if (ret < 0 && ret != -EINVAL)
> return ret;
>
> + np = dev->of_node;
> rproc = devm_rproc_alloc(dev, np->name, &scp_ops, fw_name, sizeof(*scp));
> if (!rproc)
> return dev_err_probe(dev, -ENOMEM, "unable to allocate remoteproc\n");
> @@ -884,7 +895,7 @@ static int scp_rproc_init(struct platform_device *pdev)
> scp = rproc->priv;
> scp->rproc = rproc;
> scp->dev = dev;
> - scp->data = of_device_get_match_data(dev);
> + scp->data = of_data;
> platform_set_drvdata(pdev, scp);
>
> scp->reg_base = of_cluster->reg_base;
> @@ -934,10 +945,6 @@ static int scp_rproc_init(struct platform_device *pdev)
> goto remove_subdev;
> }
>
> - ret = rproc_add(rproc);
> - if (ret)
> - goto remove_subdev;
> -
> return 0;
>
> remove_subdev:
> @@ -952,6 +959,121 @@ static int scp_rproc_init(struct platform_device *pdev)
> return ret;
> }
>
> +static void scp_rproc_free(struct mtk_scp *scp)
> +{
> + int i;
> +
> + scp_remove_rpmsg_subdev(scp);
> + scp_ipi_unregister(scp, SCP_IPI_INIT);
> + scp_unmap_memory_region(scp);
> + for (i = 0; i < SCP_IPI_MAX; i++)
> + mutex_destroy(&scp->ipi_desc[i].lock);
> + mutex_destroy(&scp->send_lock);
> +}
> +
> +static int scp_is_single_core(struct platform_device *pdev)
> +{
> + struct device *dev = &pdev->dev;
> + struct device_node *np = dev_of_node(dev);
> + struct device_node *child;
> +
> + child = of_get_next_available_child(np, NULL);
> + if (!child)
> + return dev_err_probe(dev, -ENODEV, "No child node\n");
> +
> + of_node_put(child);
> + return of_node_name_eq(child, "cros-ec-rpmsg");
> +}
> +
> +static int scp_cluster_init(struct platform_device *pdev)
> +{
> + struct device *dev = &pdev->dev;
> + struct device_node *np = dev_of_node(dev);
> + struct platform_device *cpdev;
> + struct device_node *child;
> + struct mtk_scp_of_cluster *of_cluster = platform_get_drvdata(pdev);
> + const struct mtk_scp_of_data **cluster_of_data;
> + struct list_head *cluster = &of_cluster->mtk_scp_cluster;
> + struct mtk_scp *scp, *temp;
> + int core_id = 0;
> + int ret;
> +
> + ret = scp_is_single_core(pdev);
> + if (ret < 0)
> + return ret;
> +
> + if (ret) {
> + dev_dbg(dev, "single-core scp\n");
> +
> + /* When using the SCP node phandle on exported SCP APIs, the drvdata
> + * is expected to be the mtk_scp object, and as a result, it is intended
> + * to be overwritten for single-core SCP usage.
> + */
> + ret = scp_rproc_init(pdev, NULL, of_device_get_match_data(dev));
> + if (ret)
> + return dev_err_probe(dev, ret, "Failed to initialize single-core scp\n");
> +
> + scp = platform_get_drvdata(pdev);
> + list_add_tail(&scp->elem, cluster);
> + scp->cluster = cluster;
> + } else {
> + dev_dbg(dev, "multi-core scp\n");
> +
> + cluster_of_data = (const struct mtk_scp_of_data **)of_device_get_match_data(dev);
> +
> + for_each_available_child_of_node(np, child) {
> + if (!cluster_of_data[core_id]) {
> + ret = -EINVAL;
> + dev_err(dev, "Not support core %d\n", core_id);
> + of_node_put(child);
> + goto init_fail;
> + }
> +
> + cpdev = of_find_device_by_node(child);
> + if (!cpdev) {
> + ret = -ENODEV;
> + dev_err(dev, "Not found platform device for core %d\n", core_id);
> + of_node_put(child);
> + goto init_fail;
> + }
> +
> + ret = scp_rproc_init(pdev, cpdev, cluster_of_data[core_id]);
> + if (ret) {
> + dev_err(dev, "Failed to initialize core %d rproc\n", core_id);
> + put_device(&cpdev->dev);
> + of_node_put(child);
> + goto init_fail;
> + }
> + scp = platform_get_drvdata(cpdev);
> + list_add_tail(&scp->elem, cluster);
> + scp->cluster = cluster;
> + put_device(&cpdev->dev);
> +
> + core_id++;
> + }
> + }
> +
> + list_for_each_entry_safe_reverse(scp, temp, cluster, elem) {
> + ret = rproc_add(scp->rproc);
> + if (ret)
> + goto add_fail;
> + }
> +
> + return 0;
> +
> +add_fail:
> + list_for_each_entry_continue(scp, cluster, elem) {
> + rproc_del(scp->rproc);
> + }
> +init_fail:
> + list_for_each_entry_safe_reverse(scp, temp, cluster, elem) {
> + list_del(&scp->elem);
> + scp_rproc_free(scp);
> + }
> +
> + return ret;
> +}
> +
> static int scp_probe(struct platform_device *pdev)
> {
> struct device *dev = &pdev->dev;
> @@ -983,23 +1105,44 @@ static int scp_probe(struct platform_device *pdev)
> of_cluster->l1tcm_phys = res->start;
> }
>
> + INIT_LIST_HEAD(&of_cluster->mtk_scp_cluster);
> platform_set_drvdata(pdev, of_cluster);
>
> - return scp_rproc_init(pdev);
> + ret = devm_of_platform_populate(dev);
> + if (ret)
> + return dev_err_probe(dev, ret, "Failed to populate platform devices\n");
> +
> + ret = scp_cluster_init(pdev);
> + if (ret)
> + return dev_err_probe(dev, ret, "Failed to initialize scp cluster\n");
> +
> + return 0;
> }
>
> static int scp_remove(struct platform_device *pdev)
> {
> - struct mtk_scp *scp = platform_get_drvdata(pdev);
> - int i;
> + struct mtk_scp *scp, *temp;
> + struct mtk_scp_of_cluster *of_cluster;
> + struct list_head *cluster;
> + int ret;
>
> - rproc_del(scp->rproc);
> - scp_remove_rpmsg_subdev(scp);
> - scp_ipi_unregister(scp, SCP_IPI_INIT);
> - scp_unmap_memory_region(scp);
> - for (i = 0; i < SCP_IPI_MAX; i++)
> - mutex_destroy(&scp->ipi_desc[i].lock);
> - mutex_destroy(&scp->send_lock);
> + ret = scp_is_single_core(pdev);
> + if (ret < 0)
> + return ret;
> +
> + if (ret) {
> + scp = platform_get_drvdata(pdev);
> + cluster = scp->cluster;
> + } else {
> + of_cluster = platform_get_drvdata(pdev);
> + cluster = &of_cluster->mtk_scp_cluster;
> + }

If single and multi core systems were presented the same way, i.e with a cluster
and a list of SCPs, you wouldn't have to do this. I will stop here for this
revision.

Thanks,
Mathieu

> +
> + list_for_each_entry_safe_reverse(scp, temp, cluster, elem) {
> + list_del(&scp->elem);
> + rproc_del(scp->rproc);
> + scp_rproc_free(scp);
> + }
>
> return 0;
> }
> @@ -1078,12 +1221,19 @@ static const struct mtk_scp_of_data mt8195_of_data_c1 = {
> .host_to_scp_int_bit = MT8195_CORE1_HOST_IPC_INT_BIT,
> };
>
> +static const struct mtk_scp_of_data *mt8195_of_data_cores[] = {
> + &mt8195_of_data,
> + &mt8195_of_data_c1,
> + NULL
> +};
> +
> static const struct of_device_id mtk_scp_of_match[] = {
> { .compatible = "mediatek,mt8183-scp", .data = &mt8183_of_data },
> { .compatible = "mediatek,mt8186-scp", .data = &mt8186_of_data },
> { .compatible = "mediatek,mt8188-scp", .data = &mt8188_of_data },
> { .compatible = "mediatek,mt8192-scp", .data = &mt8192_of_data },
> { .compatible = "mediatek,mt8195-scp", .data = &mt8195_of_data },
> + { .compatible = "mediatek,mt8195-scp-dual", .data = &mt8195_of_data_cores },
> {},
> };
> MODULE_DEVICE_TABLE(of, mtk_scp_of_match);
> --
> 2.18.0
>

2023-05-02 09:09:41

by Tinghan Shen

[permalink] [raw]
Subject: Re: [PATCH v10 06/11] remoteproc: mediatek: Probe multi-core SCP

On Mon, 2023-05-01 at 16:31 -0600, Mathieu Poirier wrote:
> External email : Please do not click links or open attachments until you have verified the sender or the content.
>
>
> On Wed, Apr 26, 2023 at 05:12:06PM +0800, Tinghan Shen wrote:
> > The difference of single-core SCP and multi-core SCP device tree is
> > the presence of child device nodes described SCP cores. The SCP
> > driver populates the platform device and checks the child nodes
> > to identify whether it's a single-core SCP or a multi-core SCP.
> >
> > Add the remoteproc instances for single-core SCP and multi-core SCP to
> > the new added SCP cluster list. When the SCP driver is removed, it
> > cleanup resources by walking through the cluster list.
> >
> > Signed-off-by: Tinghan Shen <[email protected]>
> > ---
> > drivers/remoteproc/mtk_common.h | 3 +
> > drivers/remoteproc/mtk_scp.c | 188 ++++++++++++++++++++++++++++----
> > 2 files changed, 172 insertions(+), 19 deletions(-)
> >
> > diff --git a/drivers/remoteproc/mtk_common.h b/drivers/remoteproc/mtk_common.h
> > index c0905aec3b4b..b73b60c22ea1 100644
> > --- a/drivers/remoteproc/mtk_common.h
> > +++ b/drivers/remoteproc/mtk_common.h
> > @@ -128,6 +128,9 @@ struct mtk_scp {
> > size_t dram_size;
> >
> > struct rproc_subdev *rpmsg_subdev;
> > +
> > + struct list_head elem;
> > + struct list_head *cluster;
> > };
> >
> > /**
> > diff --git a/drivers/remoteproc/mtk_scp.c b/drivers/remoteproc/mtk_scp.c
> > index 5e4982f4d5dc..0b052b0acf2e 100644
> > --- a/drivers/remoteproc/mtk_scp.c
> > +++ b/drivers/remoteproc/mtk_scp.c
> > @@ -28,6 +28,7 @@ struct mtk_scp_of_cluster {
> > void __iomem *l1tcm_base;
> > size_t l1tcm_size;
> > phys_addr_t l1tcm_phys;
> > + struct list_head mtk_scp_cluster;
> > };
> >
> > /**
> > @@ -862,21 +863,31 @@ static void scp_remove_rpmsg_subdev(struct mtk_scp *scp)
> > }
> > }
> >
> > -static int scp_rproc_init(struct platform_device *pdev)
> > +static int scp_rproc_init(struct platform_device *cluster_pdev,
> > + struct platform_device *core_pdev,
> > + const struct mtk_scp_of_data *of_data)
> > {
> > - struct device *dev = &pdev->dev;
> > - struct device_node *np = dev->of_node;
> > - struct mtk_scp_of_cluster *of_cluster = platform_get_drvdata(pdev);
> > + struct platform_device *pdev;
> > + struct device *dev;
> > + struct device_node *np;
> > + struct mtk_scp_of_cluster *of_cluster = platform_get_drvdata(cluster_pdev);
> > struct mtk_scp *scp;
> > struct rproc *rproc;
> > struct resource *res;
> > const char *fw_name = "scp.img";
> > int ret, i;
> >
> > + if (core_pdev)
> > + pdev = core_pdev;
> > + else
> > + pdev = cluster_pdev;
>
> After following my comment from the previous patch, there won't be a need to do
> this.
>
> > +
> > + dev = &pdev->dev;
> > ret = rproc_of_parse_firmware(dev, 0, &fw_name);
> > if (ret < 0 && ret != -EINVAL)
> > return ret;
> >
> > + np = dev->of_node;
> > rproc = devm_rproc_alloc(dev, np->name, &scp_ops, fw_name, sizeof(*scp));
> > if (!rproc)
> > return dev_err_probe(dev, -ENOMEM, "unable to allocate remoteproc\n");
> > @@ -884,7 +895,7 @@ static int scp_rproc_init(struct platform_device *pdev)
> > scp = rproc->priv;
> > scp->rproc = rproc;
> > scp->dev = dev;
> > - scp->data = of_device_get_match_data(dev);
> > + scp->data = of_data;
> > platform_set_drvdata(pdev, scp);
> >
> > scp->reg_base = of_cluster->reg_base;
> > @@ -934,10 +945,6 @@ static int scp_rproc_init(struct platform_device *pdev)
> > goto remove_subdev;
> > }
> >
> > - ret = rproc_add(rproc);
> > - if (ret)
> > - goto remove_subdev;
> > -
> > return 0;
> >
> > remove_subdev:
> > @@ -952,6 +959,121 @@ static int scp_rproc_init(struct platform_device *pdev)
> > return ret;
> > }
> >
> > +static void scp_rproc_free(struct mtk_scp *scp)
> > +{
> > + int i;
> > +
> > + scp_remove_rpmsg_subdev(scp);
> > + scp_ipi_unregister(scp, SCP_IPI_INIT);
> > + scp_unmap_memory_region(scp);
> > + for (i = 0; i < SCP_IPI_MAX; i++)
> > + mutex_destroy(&scp->ipi_desc[i].lock);
> > + mutex_destroy(&scp->send_lock);
> > +}
> > +
> > +static int scp_is_single_core(struct platform_device *pdev)
> > +{
> > + struct device *dev = &pdev->dev;
> > + struct device_node *np = dev_of_node(dev);
> > + struct device_node *child;
> > +
> > + child = of_get_next_available_child(np, NULL);
> > + if (!child)
> > + return dev_err_probe(dev, -ENODEV, "No child node\n");
> > +
> > + of_node_put(child);
> > + return of_node_name_eq(child, "cros-ec-rpmsg");
> > +}
> > +
> > +static int scp_cluster_init(struct platform_device *pdev)
> > +{
> > + struct device *dev = &pdev->dev;
> > + struct device_node *np = dev_of_node(dev);
> > + struct platform_device *cpdev;
> > + struct device_node *child;
> > + struct mtk_scp_of_cluster *of_cluster = platform_get_drvdata(pdev);
> > + const struct mtk_scp_of_data **cluster_of_data;
> > + struct list_head *cluster = &of_cluster->mtk_scp_cluster;
> > + struct mtk_scp *scp, *temp;
> > + int core_id = 0;
> > + int ret;
> > +
> > + ret = scp_is_single_core(pdev);
> > + if (ret < 0)
> > + return ret;
> > +
> > + if (ret) {
> > + dev_dbg(dev, "single-core scp\n");
> > +
> > + /* When using the SCP node phandle on exported SCP APIs, the drvdata
> > + * is expected to be the mtk_scp object, and as a result, it is intended
> > + * to be overwritten for single-core SCP usage.
> > + */
> > + ret = scp_rproc_init(pdev, NULL, of_device_get_match_data(dev));
> > + if (ret)
> > + return dev_err_probe(dev, ret, "Failed to initialize single-core scp\n");
> > +
> > + scp = platform_get_drvdata(pdev);
> > + list_add_tail(&scp->elem, cluster);
> > + scp->cluster = cluster;
> > + } else {
> > + dev_dbg(dev, "multi-core scp\n");
> > +
> > + cluster_of_data = (const struct mtk_scp_of_data **)of_device_get_match_data(dev);
> > +
> > + for_each_available_child_of_node(np, child) {
> > + if (!cluster_of_data[core_id]) {
> > + ret = -EINVAL;
> > + dev_err(dev, "Not support core %d\n", core_id);
> > + of_node_put(child);
> > + goto init_fail;
> > + }
> > +
> > + cpdev = of_find_device_by_node(child);
> > + if (!cpdev) {
> > + ret = -ENODEV;
> > + dev_err(dev, "Not found platform device for core %d\n", core_id);
> > + of_node_put(child);
> > + goto init_fail;
> > + }
> > +
> > + ret = scp_rproc_init(pdev, cpdev, cluster_of_data[core_id]);
> > + if (ret) {
> > + dev_err(dev, "Failed to initialize core %d rproc\n", core_id);
> > + put_device(&cpdev->dev);
> > + of_node_put(child);
> > + goto init_fail;
> > + }
> > + scp = platform_get_drvdata(cpdev);
> > + list_add_tail(&scp->elem, cluster);
> > + scp->cluster = cluster;
> > + put_device(&cpdev->dev);
> > +
> > + core_id++;
> > + }
> > + }
> > +
> > + list_for_each_entry_safe_reverse(scp, temp, cluster, elem) {
> > + ret = rproc_add(scp->rproc);
> > + if (ret)
> > + goto add_fail;
> > + }
> > +
> > + return 0;
> > +
> > +add_fail:
> > + list_for_each_entry_continue(scp, cluster, elem) {
> > + rproc_del(scp->rproc);
> > + }
> > +init_fail:
> > + list_for_each_entry_safe_reverse(scp, temp, cluster, elem) {
> > + list_del(&scp->elem);
> > + scp_rproc_free(scp);
> > + }
> > +
> > + return ret;
> > +}
> > +
> > static int scp_probe(struct platform_device *pdev)
> > {
> > struct device *dev = &pdev->dev;
> > @@ -983,23 +1105,44 @@ static int scp_probe(struct platform_device *pdev)
> > of_cluster->l1tcm_phys = res->start;
> > }
> >
> > + INIT_LIST_HEAD(&of_cluster->mtk_scp_cluster);
> > platform_set_drvdata(pdev, of_cluster);
> >
> > - return scp_rproc_init(pdev);
> > + ret = devm_of_platform_populate(dev);
> > + if (ret)
> > + return dev_err_probe(dev, ret, "Failed to populate platform devices\n");
> > +
> > + ret = scp_cluster_init(pdev);
> > + if (ret)
> > + return dev_err_probe(dev, ret, "Failed to initialize scp cluster\n");
> > +
> > + return 0;
> > }
> >
> > static int scp_remove(struct platform_device *pdev)
> > {
> > - struct mtk_scp *scp = platform_get_drvdata(pdev);
> > - int i;
> > + struct mtk_scp *scp, *temp;
> > + struct mtk_scp_of_cluster *of_cluster;
> > + struct list_head *cluster;
> > + int ret;
> >
> > - rproc_del(scp->rproc);
> > - scp_remove_rpmsg_subdev(scp);
> > - scp_ipi_unregister(scp, SCP_IPI_INIT);
> > - scp_unmap_memory_region(scp);
> > - for (i = 0; i < SCP_IPI_MAX; i++)
> > - mutex_destroy(&scp->ipi_desc[i].lock);
> > - mutex_destroy(&scp->send_lock);
> > + ret = scp_is_single_core(pdev);
> > + if (ret < 0)
> > + return ret;
> > +
> > + if (ret) {
> > + scp = platform_get_drvdata(pdev);
> > + cluster = scp->cluster;
> > + } else {
> > + of_cluster = platform_get_drvdata(pdev);
> > + cluster = &of_cluster->mtk_scp_cluster;
> > + }
>
> If single and multi core systems were presented the same way, i.e with a cluster
> and a list of SCPs, you wouldn't have to do this. I will stop here for this
> revision.
>
> Thanks,
> Mathieu

I've been hesitant as to whether I can present the single and multi core systems
in the same way since version 1 of this series.

I was mad aware that the upstream kernel driver must retain compatibility with
the current device trees when introducing a new device tree format.

If it's acceptable, I'll adjust all the single-core SCP dts file and dt-bindings
conform to this format in the next version.


Best regards,
TingHan
>
> > +
> > + list_for_each_entry_safe_reverse(scp, temp, cluster, elem) {
> > + list_del(&scp->elem);
> > + rproc_del(scp->rproc);
> > + scp_rproc_free(scp);
> > + }
> >
> > return 0;
> > }
> > @@ -1078,12 +1221,19 @@ static const struct mtk_scp_of_data mt8195_of_data_c1 = {
> > .host_to_scp_int_bit = MT8195_CORE1_HOST_IPC_INT_BIT,
> > };
> >
> > +static const struct mtk_scp_of_data *mt8195_of_data_cores[] = {
> > + &mt8195_of_data,
> > + &mt8195_of_data_c1,
> > + NULL
> > +};
> > +
> > static const struct of_device_id mtk_scp_of_match[] = {
> > { .compatible = "mediatek,mt8183-scp", .data = &mt8183_of_data },
> > { .compatible = "mediatek,mt8186-scp", .data = &mt8186_of_data },
> > { .compatible = "mediatek,mt8188-scp", .data = &mt8188_of_data },
> > { .compatible = "mediatek,mt8192-scp", .data = &mt8192_of_data },
> > { .compatible = "mediatek,mt8195-scp", .data = &mt8195_of_data },
> > + { .compatible = "mediatek,mt8195-scp-dual", .data = &mt8195_of_data_cores },
> > {},
> > };
> > MODULE_DEVICE_TABLE(of, mtk_scp_of_match);
> > --
> > 2.18.0
> >