Skip to content

Commit 7017996

Browse files
peter50216andersson
authored andcommitted
rpmsg: add rpmsg support for mt8183 SCP.
Add a simple rpmsg support for mt8183 SCP, that use IPI / IPC directly. Signed-off-by: Pi-Hsun Shih <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Bjorn Andersson <[email protected]>
1 parent 63c13d6 commit 7017996

File tree

9 files changed

+525
-5
lines changed

9 files changed

+525
-5
lines changed

drivers/remoteproc/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ config IMX_REMOTEPROC
2626
config MTK_SCP
2727
tristate "Mediatek SCP support"
2828
depends on ARCH_MEDIATEK
29+
select RPMSG_MTK_SCP
2930
help
3031
Say y here to support Mediatek's System Companion Processor (SCP) via
3132
the remote processor framework.

drivers/remoteproc/mtk_common.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ struct mtk_scp {
7070
void __iomem *cpu_addr;
7171
phys_addr_t phys_addr;
7272
size_t dram_size;
73+
74+
struct rproc_subdev *rpmsg_subdev;
7375
};
7476

7577
/**

drivers/remoteproc/mtk_scp.c

Lines changed: 57 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include <linux/platform_device.h>
1616
#include <linux/remoteproc.h>
1717
#include <linux/remoteproc/mtk_scp.h>
18+
#include <linux/rpmsg/mtk_rpmsg.h>
1819

1920
#include "mtk_common.h"
2021
#include "remoteproc_internal.h"
@@ -464,6 +465,54 @@ static void scp_unmap_memory_region(struct mtk_scp *scp)
464465
of_reserved_mem_device_release(scp->dev);
465466
}
466467

468+
static int scp_register_ipi(struct platform_device *pdev, u32 id,
469+
ipi_handler_t handler, void *priv)
470+
{
471+
struct mtk_scp *scp = platform_get_drvdata(pdev);
472+
473+
return scp_ipi_register(scp, id, handler, priv);
474+
}
475+
476+
static void scp_unregister_ipi(struct platform_device *pdev, u32 id)
477+
{
478+
struct mtk_scp *scp = platform_get_drvdata(pdev);
479+
480+
scp_ipi_unregister(scp, id);
481+
}
482+
483+
static int scp_send_ipi(struct platform_device *pdev, u32 id, void *buf,
484+
unsigned int len, unsigned int wait)
485+
{
486+
struct mtk_scp *scp = platform_get_drvdata(pdev);
487+
488+
return scp_ipi_send(scp, id, buf, len, wait);
489+
}
490+
491+
static struct mtk_rpmsg_info mtk_scp_rpmsg_info = {
492+
.send_ipi = scp_send_ipi,
493+
.register_ipi = scp_register_ipi,
494+
.unregister_ipi = scp_unregister_ipi,
495+
.ns_ipi_id = SCP_IPI_NS_SERVICE,
496+
};
497+
498+
static void scp_add_rpmsg_subdev(struct mtk_scp *scp)
499+
{
500+
scp->rpmsg_subdev =
501+
mtk_rpmsg_create_rproc_subdev(to_platform_device(scp->dev),
502+
&mtk_scp_rpmsg_info);
503+
if (scp->rpmsg_subdev)
504+
rproc_add_subdev(scp->rproc, scp->rpmsg_subdev);
505+
}
506+
507+
static void scp_remove_rpmsg_subdev(struct mtk_scp *scp)
508+
{
509+
if (scp->rpmsg_subdev) {
510+
rproc_remove_subdev(scp->rproc, scp->rpmsg_subdev);
511+
mtk_rpmsg_destroy_rproc_subdev(scp->rpmsg_subdev);
512+
scp->rpmsg_subdev = NULL;
513+
}
514+
}
515+
467516
static int scp_probe(struct platform_device *pdev)
468517
{
469518
struct device *dev = &pdev->dev;
@@ -544,22 +593,25 @@ static int scp_probe(struct platform_device *pdev)
544593
init_waitqueue_head(&scp->run.wq);
545594
init_waitqueue_head(&scp->ack_wq);
546595

596+
scp_add_rpmsg_subdev(scp);
597+
547598
ret = devm_request_threaded_irq(dev, platform_get_irq(pdev, 0), NULL,
548599
scp_irq_handler, IRQF_ONESHOT,
549600
pdev->name, scp);
550601

551602
if (ret) {
552603
dev_err(dev, "failed to request irq\n");
553-
goto unregister_ipi;
604+
goto remove_subdev;
554605
}
555606

556607
ret = rproc_add(rproc);
557608
if (ret)
558-
goto unregister_ipi;
609+
goto remove_subdev;
559610

560-
return ret;
611+
return 0;
561612

562-
unregister_ipi:
613+
remove_subdev:
614+
scp_remove_rpmsg_subdev(scp);
563615
scp_ipi_unregister(scp, SCP_IPI_INIT);
564616
release_dev_mem:
565617
scp_unmap_memory_region(scp);
@@ -579,6 +631,7 @@ static int scp_remove(struct platform_device *pdev)
579631
int i;
580632

581633
rproc_del(scp->rproc);
634+
scp_remove_rpmsg_subdev(scp);
582635
scp_ipi_unregister(scp, SCP_IPI_INIT);
583636
scp_unmap_memory_region(scp);
584637
for (i = 0; i < SCP_IPI_MAX; i++)

drivers/remoteproc/mtk_scp_ipi.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ int scp_ipi_send(struct mtk_scp *scp, u32 id, void *buf, unsigned int len,
162162
int ret;
163163

164164
if (WARN_ON(id <= SCP_IPI_INIT) || WARN_ON(id >= SCP_IPI_MAX) ||
165+
WARN_ON(id == SCP_IPI_NS_SERVICE) ||
165166
WARN_ON(len > sizeof(send_obj->share_buf)) || WARN_ON(!buf))
166167
return -EINVAL;
167168

drivers/rpmsg/Kconfig

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,15 @@ config RPMSG_CHAR
1515
in /dev. They make it possible for user-space programs to send and
1616
receive rpmsg packets.
1717

18+
config RPMSG_MTK_SCP
19+
tristate "MediaTek SCP"
20+
depends on MTK_SCP
21+
select RPMSG
22+
help
23+
Say y here to enable support providing communication channels to
24+
remote processors in MediaTek platforms.
25+
This use IPI and IPC to communicate with remote processors.
26+
1827
config RPMSG_QCOM_GLINK_NATIVE
1928
tristate
2029
select RPMSG

drivers/rpmsg/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# SPDX-License-Identifier: GPL-2.0
22
obj-$(CONFIG_RPMSG) += rpmsg_core.o
33
obj-$(CONFIG_RPMSG_CHAR) += rpmsg_char.o
4+
obj-$(CONFIG_RPMSG_MTK_SCP) += mtk_rpmsg.o
45
obj-$(CONFIG_RPMSG_QCOM_GLINK_RPM) += qcom_glink_rpm.o
56
obj-$(CONFIG_RPMSG_QCOM_GLINK_NATIVE) += qcom_glink_native.o
67
obj-$(CONFIG_RPMSG_QCOM_GLINK_SMEM) += qcom_glink_smem.o

0 commit comments

Comments
 (0)