[RFC PATCH 05/10] rpmsg: add sample client driver

Simon Glass sjg at chromium.org
Thu Jul 27 02:50:10 CEST 2023


Hi Tanmay,

On Tue, 25 Jul 2023 at 08:08, Tanmay Shah <tanmay.shah at amd.com> wrote:
>
> Add driver to demonstrate use of rpmsg framework.
>
> Signed-off-by: Tanmay Shah <tanmay.shah at 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

Reviewed-by: Simon Glass <sjg at chromium.org>

>
> 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.

enable a driver

demonstrates

> +         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>

Do you need those three?

> +#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
>

REgards,
SImon


More information about the U-Boot mailing list