From: Arnaud POULIQUEN <arnaud.pouliquen@foss.st.com>
To: Shenwei Wang <shenwei.wang@nxp.com>,
Linus Walleij <linusw@kernel.org>,
Bartosz Golaszewski <brgl@kernel.org>,
Rob Herring <robh@kernel.org>,
Krzysztof Kozlowski <krzk+dt@kernel.org>,
Conor Dooley <conor+dt@kernel.org>,
Bjorn Andersson <andersson@kernel.org>,
Mathieu Poirier <mathieu.poirier@linaro.org>,
Shawn Guo <shawnguo@kernel.org>,
Sascha Hauer <s.hauer@pengutronix.de>,
Jonathan Corbet <corbet@lwn.net>
Cc: Pengutronix Kernel Team <kernel@pengutronix.de>,
Fabio Estevam <festevam@gmail.com>, Peng Fan <peng.fan@nxp.com>,
<linux-gpio@vger.kernel.org>, <devicetree@vger.kernel.org>,
<linux-kernel@vger.kernel.org>,
<linux-remoteproc@vger.kernel.org>, <imx@lists.linux.dev>,
<linux-arm-kernel@lists.infradead.org>,
<linux-doc@vger.kernel.org>, <linux-imx@nxp.com>
Subject: Re: [PATCH v6 2/5] remoteproc: imx_rproc: Populate devices under "rpmsg" subnode
Date: Thu, 18 Dec 2025 12:03:40 +0100 [thread overview]
Message-ID: <805c9dd5-50ca-4e2f-8fe8-b8a601fe4428@foss.st.com> (raw)
In-Reply-To: <20251212194341.966387-3-shenwei.wang@nxp.com>
Hello,
On 12/12/25 20:43, Shenwei Wang wrote:
> Register the RPMsg channel driver and populate remote devices defined
> under the "rpmsg" subnode upon receiving their notification messages.
>
> The following illustrates the expected DTS layout structure:
>
> cm33: remoteproc-cm33 {
> compatible = "fsl,imx8ulp-cm33";
>
> rpmsg {
> rpmsg-io-channel {
> gpio@0 {
> compatible = "fsl,imx-rpmsg-gpio";
> reg = <0>;
> };
>
> gpio@1 {
> compatible = "fsl,imx-rpmsg-gpio";
> reg = <1>;
> };
>
> ...
> };
>
> ...
> };
> };
>
> Signed-off-by: Shenwei Wang <shenwei.wang@nxp.com>
> ---
> drivers/remoteproc/imx_rproc.c | 143 +++++++++++++++++++++++++++++++
> include/linux/rpmsg/rpdev_info.h | 33 +++++++
> 2 files changed, 176 insertions(+)
> create mode 100644 include/linux/rpmsg/rpdev_info.h
>
> diff --git a/drivers/remoteproc/imx_rproc.c b/drivers/remoteproc/imx_rproc.c
> index 33f21ab24c92..65ee16fd66d1 100644
> --- a/drivers/remoteproc/imx_rproc.c
> +++ b/drivers/remoteproc/imx_rproc.c
> @@ -15,6 +15,8 @@
> #include <linux/module.h>
> #include <linux/of.h>
> #include <linux/of_address.h>
> +#include <linux/of_irq.h>
> +#include <linux/of_platform.h>
> #include <linux/of_reserved_mem.h>
> #include <linux/platform_device.h>
> #include <linux/pm_domain.h>
> @@ -22,6 +24,8 @@
> #include <linux/reboot.h>
> #include <linux/regmap.h>
> #include <linux/remoteproc.h>
> +#include <linux/rpmsg.h>
> +#include <linux/rpmsg/rpdev_info.h>
> #include <linux/workqueue.h>
>
> #include "imx_rproc.h"
> @@ -1016,6 +1020,141 @@ static void imx_rproc_destroy_workqueue(void *data)
> destroy_workqueue(workqueue);
> }
>
> +struct imx_rpmsg_driver {
> + struct rpmsg_driver rpdrv;
> + const char *compat;
> + void *driver_data;
> +};
> +
> +static const char *channel_device_map[][2] = {
> + {"rpmsg-io-channel", "rpmsg-gpio"},
> +};
> +
> +static int imx_rpmsg_endpoint_cb(struct rpmsg_device *rpdev, void *data,
> + int len, void *priv, u32 src)
> +{
> + struct rpdev_platform_info *drvdata;
> +
> + drvdata = dev_get_drvdata(&rpdev->dev);
> + if (drvdata && drvdata->rx_callback)
> + return drvdata->rx_callback(rpdev, data, len, priv, src);
> +
> + return 0;
> +}
> +
> +static void imx_rpmsg_endpoint_remove(struct rpmsg_device *rpdev)
> +{
> + of_platform_depopulate(&rpdev->dev);
> +}
> +
> +static int imx_rpmsg_endpoint_probe(struct rpmsg_device *rpdev)
> +{
> + struct rpdev_platform_info *drvdata;
> + struct imx_rpmsg_driver *imx_rpdrv;
> + struct device *dev = &rpdev->dev;
> + struct of_dev_auxdata *auxdata;
> + struct rpmsg_driver *rpdrv;
> +
> + rpdrv = container_of(dev->driver, struct rpmsg_driver, drv);
> + imx_rpdrv = container_of(rpdrv, struct imx_rpmsg_driver, rpdrv);
> +
> + if (!imx_rpdrv->driver_data)
> + return -EINVAL;
> +
> + drvdata = devm_kmemdup(dev, imx_rpdrv->driver_data, sizeof(*drvdata), GFP_KERNEL);
> + if (!drvdata)
> + return -ENOMEM;
> +
> + auxdata = devm_kzalloc(dev, sizeof(*auxdata) * 2, GFP_KERNEL);
> + if (!auxdata)
> + return -ENOMEM;
> +
> + drvdata->rpdev = rpdev;
> + auxdata[0].compatible = devm_kstrdup(dev, imx_rpdrv->compat, GFP_KERNEL);
> + auxdata[0].platform_data = drvdata;
> + dev_set_drvdata(dev, drvdata);
> +
> + of_platform_populate(drvdata->channel_node, NULL, auxdata, dev);
> +
> + return 0;
> +}
> +
> +static const char *imx_of_rpmsg_is_in_map(const char *name)
> +{
> + int i;
> +
> + for (i = 0; i < ARRAY_SIZE(channel_device_map); i++) {
> + if (strcmp(name, channel_device_map[i][0]) == 0)
> + return channel_device_map[i][1];
> + }
> +
> + return NULL;
> +}
> +
> +static int imx_of_rpmsg_register_rpdriver(struct device_node *channel,
> + struct device *dev,
> + const char *name,
> + const char *compat)
> +{
> + struct rpdev_platform_info *driver_data;
> + struct imx_rpmsg_driver *rp_driver;
> + struct rpmsg_device_id *rpdev_id;
> +
> + /* rpmsg_device_id is a NULL terminated array */
> + rpdev_id = devm_kzalloc(dev, sizeof(*rpdev_id) * 2, GFP_KERNEL);
> + if (!rpdev_id)
> + return -ENOMEM;
> +
> + strscpy(rpdev_id[0].name, name, RPMSG_NAME_SIZE);
> +
> + rp_driver = devm_kzalloc(dev, sizeof(*rp_driver), GFP_KERNEL);
> + if (!rp_driver)
> + return -ENOMEM;
> +
> + driver_data = devm_kzalloc(dev, sizeof(*driver_data), GFP_KERNEL);
> + if (!driver_data)
> + return -ENOMEM;
> +
> + driver_data->rproc_name = dev->of_node->name;
> + driver_data->channel_node = channel;
> +
> + rp_driver->rpdrv.drv.name = name;
> + rp_driver->rpdrv.id_table = rpdev_id;
> + rp_driver->rpdrv.probe = imx_rpmsg_endpoint_probe;
> + rp_driver->rpdrv.remove = imx_rpmsg_endpoint_remove;
> + rp_driver->rpdrv.callback = imx_rpmsg_endpoint_cb;
> + rp_driver->driver_data = driver_data;
> + rp_driver->compat = compat;
> +
> + register_rpmsg_driver(&rp_driver->rpdrv);
I still believe that creating a dependency between remoteproc and rpmsg
is not suitable.
Please correct me if I’m wrong, but since you define gpio@0 and gpio@1
in your device tree, you call register_rpmsg_driver() twice, creating
two instances of the same driver. To differentiate both, you fill the
rpdrv.id_table with the node names "gpio@0" and "gpio@1".
In a topology with two remote processors, each needing rpmsg-gpio, the
same situation would not work because you would have two "gpio@0" entries.
What about using the ns-announcement mechanism on the remote side to
address GPIO port/bank instances?
In the rpmsg-gpio driver, you could define:
static struct rpmsg_device_id rpmsg_gpio_id_table[] = {
{ .name = "rpmsg-gpio" },
{ .name = "rpmsg_gpio-0" },
{ .name = "rpmsg_gpio-1" },
{ .name = "rpmsg_gpio-2" },
{ .name = "rpmsg_gpio-3" },
{ },
};
Then the match between the device tree and the rpmsg bus could be done
in the rpmsg-gpio driver by matching the rpmsg name with the compatible
property plus the reg value.
Example device tree snippet:
cm33: remoteproc-cm33 {
compatible = "fsl,imx8ulp-cm33";
rpmsg {
rpmsg-io-channel {
gpio@0 {
compatible = "rpmsg_gpio";
reg = <0>;
};
gpio@1 {
compatible = "rpmsg_gpio";
reg = <1>;
};
...
};
...
};
};
With this approach, rpmsg management could be handled entirely within
the rpmsg-gpio driver, avoiding the need to register multiple instances
of the rpmsg_gpio driver.
Regards,
Arnaud
> +
> + return 0;
> +}
> +
> +static int rproc_of_rpmsg_node_init(struct platform_device *pdev)
> +{
> + struct device *dev = &pdev->dev;
> + const char *compat;
> + int ret;
> +
> + struct device_node *np __free(device_node) = of_get_child_by_name(dev->of_node, "rpmsg");
> + if (!np)
> + return 0;
> +
> + for_each_child_of_node_scoped(np, child) {
> + compat = imx_of_rpmsg_is_in_map(child->name);
> + if (!compat)
> + ret = of_platform_default_populate(child, NULL, dev);
> + else
> + ret = imx_of_rpmsg_register_rpdriver(child, dev, child->name, compat);
> +
> + if (ret < 0)
> + return ret;
> + }
> +
> + return 0;
> +}
> +
> static int imx_rproc_probe(struct platform_device *pdev)
> {
> struct device *dev = &pdev->dev;
> @@ -1114,6 +1253,10 @@ static int imx_rproc_probe(struct platform_device *pdev)
> goto err_put_pm;
> }
>
> + ret = rproc_of_rpmsg_node_init(pdev);
> + if (ret < 0)
> + dev_info(dev, "populating 'rpmsg' node failed\n");
> +
> return 0;
>
> err_put_pm:
> diff --git a/include/linux/rpmsg/rpdev_info.h b/include/linux/rpmsg/rpdev_info.h
> new file mode 100644
> index 000000000000..13e020cd028b
> --- /dev/null
> +++ b/include/linux/rpmsg/rpdev_info.h
> @@ -0,0 +1,33 @@
> +/* SPDX-License-Identifier: GPL-2.0 */
> +/* Copyright 2025 NXP */
> +
> +/*
> + * @file linux/rpdev_info.h
> + *
> + * @brief Global header file for RPDEV Info
> + *
> + * @ingroup RPMSG
> + */
> +#ifndef __LINUX_RPDEV_INFO_H__
> +#define __LINUX_RPDEV_INFO_H__
> +
> +#define MAX_DEV_PER_CHANNEL 10
> +
> +/**
> + * rpdev_platform_info - store the platform information of rpdev
> + * @rproc_name: the name of the remote proc.
> + * @rpdev: rpmsg channel device
> + * @device_node: pointer to the device node of the rpdev.
> + * @rx_callback: rx callback handler of the rpdev.
> + * @channel_devices: an array of the devices related to the rpdev.
> + */
> +struct rpdev_platform_info {
> + const char *rproc_name;
> + struct rpmsg_device *rpdev;
> + struct device_node *channel_node;
> + int (*rx_callback)(struct rpmsg_device *rpdev, void *data,
> + int len, void *priv, u32 src);
> + void *channel_devices[MAX_DEV_PER_CHANNEL];
> +};
> +
> +#endif /* __LINUX_RPDEV_INFO_H__ */
next prev parent reply other threads:[~2025-12-18 11:04 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-12-12 19:43 [PATCH v6 0/5] Enable Remote GPIO over RPMSG on i.MX Platform Shenwei Wang
2025-12-12 19:43 ` [PATCH v6 1/5] dt-bindings: remoteproc: imx_rproc: Add "rpmsg" subnode support Shenwei Wang
2025-12-17 0:57 ` Rob Herring
2025-12-17 19:45 ` Shenwei Wang
2025-12-18 10:29 ` Arnaud POULIQUEN
2025-12-18 14:53 ` Shenwei Wang
2025-12-12 19:43 ` [PATCH v6 2/5] remoteproc: imx_rproc: Populate devices under "rpmsg" subnode Shenwei Wang
2025-12-18 11:03 ` Arnaud POULIQUEN [this message]
2025-12-18 15:11 ` Shenwei Wang
2025-12-19 2:23 ` Bjorn Andersson
2025-12-23 19:47 ` Shenwei Wang
2025-12-24 0:15 ` Bjorn Andersson
2025-12-12 19:43 ` [PATCH v6 3/5] docs: driver-api: gpio: generic gpio driver over rpmsg bus Shenwei Wang
2025-12-18 10:45 ` Arnaud POULIQUEN
2025-12-18 15:36 ` Shenwei Wang
2025-12-12 19:43 ` [PATCH v6 4/5] gpio: rpmsg: add generic rpmsg GPIO driver Shenwei Wang
2025-12-18 15:58 ` Bjorn Andersson
2025-12-23 20:20 ` Shenwei Wang
2025-12-24 0:09 ` Bjorn Andersson
2025-12-12 19:43 ` [PATCH v6 5/5] arm64: dts: imx8ulp: Add rpmsg node under imx_rproc Shenwei Wang
2026-01-14 17:09 ` [PATCH v6 0/5] Enable Remote GPIO over RPMSG on i.MX Platform Mathieu Poirier
2026-02-07 21:08 ` Shenwei Wang
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=805c9dd5-50ca-4e2f-8fe8-b8a601fe4428@foss.st.com \
--to=arnaud.pouliquen@foss.st.com \
--cc=andersson@kernel.org \
--cc=brgl@kernel.org \
--cc=conor+dt@kernel.org \
--cc=corbet@lwn.net \
--cc=devicetree@vger.kernel.org \
--cc=festevam@gmail.com \
--cc=imx@lists.linux.dev \
--cc=kernel@pengutronix.de \
--cc=krzk+dt@kernel.org \
--cc=linusw@kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-doc@vger.kernel.org \
--cc=linux-gpio@vger.kernel.org \
--cc=linux-imx@nxp.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-remoteproc@vger.kernel.org \
--cc=mathieu.poirier@linaro.org \
--cc=peng.fan@nxp.com \
--cc=robh@kernel.org \
--cc=s.hauer@pengutronix.de \
--cc=shawnguo@kernel.org \
--cc=shenwei.wang@nxp.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