From: Tinghan Shen <tinghan.shen@mediatek.com>
To: Bjorn Andersson <bjorn.andersson@linaro.org>,
Mathieu Poirier <mathieu.poirier@linaro.org>,
Rob Herring <robh+dt@kernel.org>,
Krzysztof Kozlowski <krzk+dt@kernel.org>,
Matthias Brugger <matthias.bgg@gmail.com>,
Lee Jones <lee.jones@linaro.org>,
Benson Leung <bleung@chromium.org>,
Guenter Roeck <groeck@chromium.org>,
Sebastian Reichel <sebastian.reichel@collabora.com>,
Daisuke Nojiri <dnojiri@chromium.org>,
Kees Cook <keescook@chromium.org>,
Tinghan Shen <tinghan.shen@mediatek.com>,
"Gustavo A. R. Silva" <gustavoars@kernel.org>,
Prashant Malani <pmalani@chromium.org>,
Enric Balletbo i Serra <enric.balletbo@collabora.com>
Cc: <linux-remoteproc@vger.kernel.org>, <devicetree@vger.kernel.org>,
<linux-arm-kernel@lists.infradead.org>,
<linux-mediatek@lists.infradead.org>,
<linux-kernel@vger.kernel.org>, <chrome-platform@lists.linux.dev>,
<Project_Global_Chrome_Upstream_Group@mediatek.com>,
<weishunc@google.com>
Subject: [PATCH v2 7/9] remoteproc: mediatek: Add SCP core 1 as a rproc subdevice
Date: Wed, 8 Jun 2022 16:35:51 +0800 [thread overview]
Message-ID: <20220608083553.8697-8-tinghan.shen@mediatek.com> (raw)
In-Reply-To: <20220608083553.8697-1-tinghan.shen@mediatek.com>
Because the clock and SRAM power is controlled by SCP core 0, SCP core 1
has to be boot after SCP core 0. We use the rproc subdev to achieve this
purpose.
The watchdog timeout handler of SCP core 1 is added as part of the rproc
subdevice. This allows SCP core 0 to handle watchdog timeout coming from
SCP core 1.
Signed-off-by: Tinghan Shen <tinghan.shen@mediatek.com>
---
drivers/remoteproc/mtk_common.h | 9 +++
drivers/remoteproc/mtk_scp.c | 130 ++++++++++++++++++++++++++++++++
2 files changed, 139 insertions(+)
diff --git a/drivers/remoteproc/mtk_common.h b/drivers/remoteproc/mtk_common.h
index 5582f4207fbf..67b41866a100 100644
--- a/drivers/remoteproc/mtk_common.h
+++ b/drivers/remoteproc/mtk_common.h
@@ -99,6 +99,14 @@ struct scp_ipi_desc {
void *priv;
};
+struct scp_subdev_core {
+ struct rproc_subdev subdev;
+ struct mtk_scp *main_scp;
+ void (*scp_dual_wdt_timeout)(struct mtk_scp *scp, u32 scp_to_host);
+};
+
+#define to_subdev_core(d) container_of(d, struct scp_subdev_core, subdev)
+
struct mtk_scp;
struct mtk_scp_of_data {
@@ -144,6 +152,7 @@ struct mtk_scp {
size_t dram_size;
struct rproc_subdev *rpmsg_subdev;
+ struct rproc_subdev *dual_subdev;
};
/**
diff --git a/drivers/remoteproc/mtk_scp.c b/drivers/remoteproc/mtk_scp.c
index b8a4db581179..d0e9e19e251f 100644
--- a/drivers/remoteproc/mtk_scp.c
+++ b/drivers/remoteproc/mtk_scp.c
@@ -244,6 +244,13 @@ static void mt8195_scp_irq_handler(struct mtk_scp *scp)
} else {
if (readl(scp->reg_base + MT8195_SYS_STATUS) & MT8195_CORE1_WDT) {
writel(1, scp->reg_base + MT8195_CORE1_WDT_IRQ);
+
+ if (scp->dual_subdev) {
+ struct scp_subdev_core *subdev_core;
+
+ subdev_core = to_subdev_core(scp->dual_subdev);
+ subdev_core->scp_dual_wdt_timeout(scp, scp_to_host);
+ }
} else {
writel(1, scp->reg_base + MT8192_CORE0_WDT_IRQ);
scp_wdt_handler(scp, scp_to_host);
@@ -925,6 +932,118 @@ static void scp_remove_rpmsg_subdev(struct mtk_scp *scp)
}
}
+static struct mtk_scp *scp_dual_get(struct mtk_scp *scp)
+{
+ struct device *dev = scp->dev;
+ struct device_node *np;
+ struct platform_device *dual_pdev;
+
+ np = of_parse_phandle(dev->of_node, "mediatek,scp-core", 0);
+ dual_pdev = of_find_device_by_node(np);
+ of_node_put(np);
+
+ if (!dual_pdev) {
+ dev_err(dev, "No scp-dual pdev\n");
+ return NULL;
+ }
+
+ return platform_get_drvdata(dual_pdev);
+}
+
+static void scp_dual_put(struct mtk_scp *scp)
+{
+ put_device(scp->dev);
+}
+
+static int scp_dual_rproc_start(struct rproc_subdev *subdev)
+{
+ struct scp_subdev_core *subdev_core = to_subdev_core(subdev);
+ struct mtk_scp *scp_dual;
+
+ scp_dual = scp_dual_get(subdev_core->main_scp);
+ if (!scp_dual)
+ return -ENODEV;
+
+ rproc_boot(scp_dual->rproc);
+ scp_dual_put(scp_dual);
+
+ return 0;
+}
+
+static void scp_dual_rproc_stop(struct rproc_subdev *subdev, bool crashed)
+{
+ struct scp_subdev_core *subdev_core = to_subdev_core(subdev);
+ struct mtk_scp *scp_dual;
+
+ scp_dual = scp_dual_get(subdev_core->main_scp);
+ if (!scp_dual)
+ return;
+
+ rproc_shutdown(scp_dual->rproc);
+ scp_dual_put(scp_dual);
+}
+
+static void scp_dual_wdt_handler(struct mtk_scp *scp, u32 scp_to_host)
+{
+ struct mtk_scp *scp_dual;
+
+ scp_dual = scp_dual_get(scp);
+ if (!scp_dual)
+ return;
+
+ dev_err(scp_dual->dev, "SCP watchdog timeout! 0x%x\n", scp_to_host);
+ rproc_report_crash(scp_dual->rproc, RPROC_WATCHDOG);
+ scp_dual_put(scp_dual);
+}
+
+static struct rproc_subdev *scp_dual_create_subdev(struct mtk_scp *scp)
+{
+ struct device *dev = scp->dev;
+ struct scp_subdev_core *subdev_core;
+ struct device_node *np;
+
+ np = of_parse_phandle(dev->of_node, "mediatek,scp-core", 0);
+ if (!np)
+ return NULL;
+
+ of_node_put(np);
+
+ subdev_core = devm_kzalloc(dev, sizeof(*subdev_core), GFP_KERNEL);
+ if (!subdev_core)
+ return NULL;
+
+ subdev_core->main_scp = scp;
+ subdev_core->scp_dual_wdt_timeout = scp_dual_wdt_handler;
+ subdev_core->subdev.start = scp_dual_rproc_start;
+ subdev_core->subdev.stop = scp_dual_rproc_stop;
+
+ return &subdev_core->subdev;
+}
+
+static void scp_dual_destroy_subdev(struct rproc_subdev *subdev)
+{
+ struct scp_subdev_core *subdev_core = to_subdev_core(subdev);
+
+ devm_kfree(subdev_core->main_scp->dev, subdev_core);
+}
+
+static void scp_add_dual_subdev(struct mtk_scp *scp)
+{
+ scp->dual_subdev = scp_dual_create_subdev(scp);
+
+ if (scp->dual_subdev)
+ rproc_add_subdev(scp->rproc, scp->dual_subdev);
+}
+
+static void scp_remove_dual_subdev(struct mtk_scp *scp)
+{
+ if (scp->dual_subdev) {
+ rproc_remove_subdev(scp->rproc, scp->dual_subdev);
+ scp_dual_destroy_subdev(scp->dual_subdev);
+ scp->dual_subdev = NULL;
+ }
+}
+
static int scp_probe(struct platform_device *pdev)
{
struct device *dev = &pdev->dev;
@@ -1014,6 +1133,9 @@ static int scp_probe(struct platform_device *pdev)
scp_add_rpmsg_subdev(scp);
+ if (core_id == SCP_CORE_0)
+ scp_add_dual_subdev(scp);
+
ret = devm_request_threaded_irq(dev, platform_get_irq(pdev, 0), NULL,
scp_irq_handler, IRQF_ONESHOT,
pdev->name, scp);
@@ -1023,6 +1145,12 @@ static int scp_probe(struct platform_device *pdev)
goto remove_subdev;
}
+ /* disable auto boot before register rproc.
+ * scp core 1 is booted as a subdevice of scp core 0.
+ */
+ if (core_id == SCP_CORE_1)
+ rproc->auto_boot = false;
+
ret = rproc_add(rproc);
if (ret)
goto remove_subdev;
@@ -1030,6 +1158,7 @@ static int scp_probe(struct platform_device *pdev)
return 0;
remove_subdev:
+ scp_remove_dual_subdev(scp);
scp_remove_rpmsg_subdev(scp);
scp_ipi_unregister(scp, SCP_IPI_INIT);
release_dev_mem:
@@ -1047,6 +1176,7 @@ static int scp_remove(struct platform_device *pdev)
int i;
rproc_del(scp->rproc);
+ scp_remove_dual_subdev(scp);
scp_remove_rpmsg_subdev(scp);
scp_ipi_unregister(scp, SCP_IPI_INIT);
scp_unmap_memory_region(scp);
--
2.18.0
next prev parent reply other threads:[~2022-06-08 8:37 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-06-08 8:35 [PATCH v2 0/9] Add support for MT8195 SCP 2nd core Tinghan Shen
2022-06-08 8:35 ` [PATCH v2 1/9] dt-binding: remoteproc: mediatek: Support dual-core SCP Tinghan Shen
2022-06-09 20:51 ` Rob Herring
2022-06-08 8:35 ` [PATCH v2 2/9] remoteproc: mediatek: Support hanlding scp core 1 wdt timeout Tinghan Shen
2022-08-29 17:40 ` Mathieu Poirier
2022-09-08 10:38 ` Tinghan Shen
2022-06-08 8:35 ` [PATCH v2 3/9] remoteproc: mediatek: Add SCP core 1 register definitions Tinghan Shen
2022-08-29 17:46 ` Mathieu Poirier
2022-06-08 8:35 ` [PATCH v2 4/9] remoteproc: mediatek: Support probing for the 2nd core of dual-core SCP Tinghan Shen
2022-08-29 19:42 ` Mathieu Poirier
2022-09-08 11:17 ` Tinghan Shen
[not found] ` <CANLsYkx6kXk8u_ajFbnhdWTkZBLtrq_z02jryLBSVH0x--_ZFw@mail.gmail.com>
2022-09-16 11:59 ` TingHan Shen
2022-09-16 17:15 ` Mathieu Poirier
2022-09-19 9:46 ` TingHan Shen
2022-09-19 20:53 ` Mathieu Poirier
2022-09-23 7:12 ` Peng Fan
2022-06-08 8:35 ` [PATCH v2 5/9] remoteproc: mediatek: Add chip dependent operations for SCP core 1 Tinghan Shen
2022-06-08 8:35 ` [PATCH v2 6/9] remoteproc: mediatek: Add SCP core 1 SRAM offset Tinghan Shen
2022-06-08 8:35 ` Tinghan Shen [this message]
2022-06-08 8:35 ` [PATCH v2 8/9] remoteproc: mediatek: Wait SCP core 1 probe done Tinghan Shen
2022-06-08 8:35 ` [PATCH v2 9/9] mfd: cros_ec: Add SCP core 1 as a new CrOS EC MCU Tinghan Shen
2022-06-09 5:45 ` [PATCH v2 0/9] Add support for MT8195 SCP 2nd core Tinghan Shen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220608083553.8697-8-tinghan.shen@mediatek.com \
--to=tinghan.shen@mediatek.com \
--cc=Project_Global_Chrome_Upstream_Group@mediatek.com \
--cc=bjorn.andersson@linaro.org \
--cc=bleung@chromium.org \
--cc=chrome-platform@lists.linux.dev \
--cc=devicetree@vger.kernel.org \
--cc=dnojiri@chromium.org \
--cc=enric.balletbo@collabora.com \
--cc=groeck@chromium.org \
--cc=gustavoars@kernel.org \
--cc=keescook@chromium.org \
--cc=krzk+dt@kernel.org \
--cc=lee.jones@linaro.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mediatek@lists.infradead.org \
--cc=linux-remoteproc@vger.kernel.org \
--cc=mathieu.poirier@linaro.org \
--cc=matthias.bgg@gmail.com \
--cc=pmalani@chromium.org \
--cc=robh+dt@kernel.org \
--cc=sebastian.reichel@collabora.com \
--cc=weishunc@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox