Add driver to demonstrate use of rpmsg framework. Signed-off-by: Tanmay Shah <tanmay.s...@amd.com> --- drivers/rpmsg/Kconfig | 8 ++++ drivers/rpmsg/Makefile | 3 ++ drivers/rpmsg/rpmsg_sample_client.c | 63 +++++++++++++++++++++++++++++ 3 files changed, 74 insertions(+) create mode 100644 drivers/rpmsg/rpmsg_sample_client.c
diff --git a/drivers/rpmsg/Kconfig b/drivers/rpmsg/Kconfig index 4efb8dfcd7..808cd16275 100644 --- a/drivers/rpmsg/Kconfig +++ b/drivers/rpmsg/Kconfig @@ -28,4 +28,12 @@ config RPMSG_SANDBOX Say 'y' here to add sandbox driver for RPMsg framework used for dummy communication with remote processor on sandbox platform +config RPMSG_SAMPLE_CLIENT + bool "Sample RPMsg client driver" + depends on DM + select RPMSG + help + Say 'y' here to enable driver that demonstrate use of RPMsg framework. + This driver uses RPMsg APIs to communicate with remote processor. + endmenu diff --git a/drivers/rpmsg/Makefile b/drivers/rpmsg/Makefile index 21611725ea..53af0f7ea6 100644 --- a/drivers/rpmsg/Makefile +++ b/drivers/rpmsg/Makefile @@ -6,5 +6,8 @@ obj-$(CONFIG_RPMSG) += rpmsg-uclass.o obj-$(CONFIG_RPMSG_SANDBOX) += sandbox_test_rpmsg.o +# Sample driver demonstrate how to use rpmsg framework +obj-$(CONFIG_RPMSG_SAMPLE_CLIENT) += rpmsg_sample_client.o + # virtio driver for rpmsg obj-$(CONFIG_VIRTIO_RPMSG_BUS) += virtio_rpmsg_bus.o diff --git a/drivers/rpmsg/rpmsg_sample_client.c b/drivers/rpmsg/rpmsg_sample_client.c new file mode 100644 index 0000000000..ae591dbdde --- /dev/null +++ b/drivers/rpmsg/rpmsg_sample_client.c @@ -0,0 +1,63 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (C) 2011 Texas Instruments, Inc. + * Copyright (C) 2011 Google, Inc. + * Copyright (C) 2023, Advanced Micro Devices, Inc. + * + * Sample client that shows use of rpmsg APIs + */ + +#include <common.h> +#include <dm.h> +#include <errno.h> +#include <log.h> +#include <malloc.h> +#include <rpmsg.h> +#include <dm/device-internal.h> +#include <dm/uclass.h> +#include <dm/uclass-internal.h> +#include <linux/delay.h> + +static int rpmsg_rx_callback(void *buf, int msg_len, u32 msgs_received) +{ + printf("APU: rx: %s\n", (char *)buf); + + return 0; +} + +static int rpmsg_sample_client_probe(struct udevice *udev) +{ + char data[80] = {0}; + int i; + + /* Initialize rpmsg for core 0 */ + rpmsg_init(0); + + /* wait for RPU to initialize vdev */ + mdelay(20); + + /* assume rpmsg init is already done */ + for (i = 1; i < 5; i++) { + sprintf(data, "rpmsg buf %d", i); + printf("APU: tx: %s\n", data); + rpmsg_send(0, data, strlen(data)); + + /* 20ms delay before receiving the data */ + mdelay(20); + + rpmsg_recv(0, rpmsg_rx_callback); + printf("\n"); + } + return 0; +} + +U_BOOT_DRIVER(rpmsg_sample_client) = { + .name = "rpmsg-sample-client", + .id = UCLASS_MISC, + .probe = rpmsg_sample_client_probe, + .flags = DM_FLAG_PRE_RELOC, +}; + +U_BOOT_DRVINFO(rpmsg_sample_client) = { + .name = "rpmsg-sample-client", +}; -- 2.25.1