Linux kernel and device drivers for NXP i.MX platforms
 help / color / mirror / Atom feed
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>,
	Jonathan Corbet <corbet@lwn.net>, "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>,
	Frank Li <frank.li@nxp.com>,
	"Sascha Hauer" <s.hauer@pengutronix.de>
Cc: Shuah Khan <skhan@linuxfoundation.org>,
	"linux-gpio@vger.kernel.org" <linux-gpio@vger.kernel.org>,
	"linux-doc@vger.kernel.org" <linux-doc@vger.kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	Pengutronix Kernel Team <kernel@pengutronix.de>,
	Fabio Estevam <festevam@gmail.com>, Peng Fan <peng.fan@nxp.com>,
	"devicetree@vger.kernel.org" <devicetree@vger.kernel.org>,
	"linux-remoteproc@vger.kernel.org"
	<linux-remoteproc@vger.kernel.org>,
	"imx@lists.linux.dev" <imx@lists.linux.dev>,
	"linux-arm-kernel@lists.infradead.org"
	<linux-arm-kernel@lists.infradead.org>,
	dl-linux-imx <linux-imx@nxp.com>,
	Bartosz Golaszewski <brgl@bgdev.pl>, Andrew Lunn <andrew@lunn.ch>
Subject: Re: [PATCH v8 3/4] gpio: rpmsg: add generic rpmsg GPIO driver
Date: Fri, 20 Feb 2026 10:32:39 +0100	[thread overview]
Message-ID: <fdbdfd15-1848-4d17-ab1c-53472ab6c817@foss.st.com> (raw)
In-Reply-To: <AS8PR04MB917654F40D80A2DBAD30ACD1896BA@AS8PR04MB9176.eurprd04.prod.outlook.com>



On 2/19/26 22:13, Shenwei Wang wrote:
> 
> 
>> -----Original Message-----
>> From: Arnaud POULIQUEN <arnaud.pouliquen@foss.st.com>
>> Sent: Thursday, February 19, 2026 3:21 AM
>> To: Shenwei Wang <shenwei.wang@nxp.com>; Linus Walleij
>> <linusw@kernel.org>; Bartosz Golaszewski <brgl@kernel.org>; Jonathan Corbet
>> <corbet@lwn.net>; 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>; Frank Li
>> <frank.li@nxp.com>; Sascha Hauer <s.hauer@pengutronix.de>
>> Cc: Shuah Khan <skhan@linuxfoundation.org>; linux-gpio@vger.kernel.org; linux-
>> doc@vger.kernel.org; linux-kernel@vger.kernel.org; Pengutronix Kernel Team
>> <kernel@pengutronix.de>; Fabio Estevam <festevam@gmail.com>; Peng Fan
>> <peng.fan@nxp.com>; devicetree@vger.kernel.org; linux-
>> remoteproc@vger.kernel.org; imx@lists.linux.dev; linux-arm-
>> kernel@lists.infradead.org; dl-linux-imx <linux-imx@nxp.com>; Bartosz
>> Golaszewski <brgl@bgdev.pl>; Andrew Lunn <andrew@lunn.ch>
>> Subject: [EXT] Re: [PATCH v8 3/4] gpio: rpmsg: add generic rpmsg GPIO driver
>>> +     rproc = rproc_get_by_child(&rpdev->dev);
>>> +     if (!rproc)
>>> +             return NULL;
>>> +
>>> +     np = of_node_get(rproc->dev.of_node);
>>> +     if (!np && rproc->dev.parent)
>>> +             np = of_node_get(rproc->dev.parent->of_node);
>>
>> Is a topology where they is no rproc->dev node but a parent node exist?
>>
> 
> If no rproc->dev, it should return NULL in the above check.

Regarding rproc_alloc, seems that rproc->dev.of_node is always NULL.
so probably test on it is useless.

> 
>>> +
>>> +     if (np) {
>>> +             /* Balance the of_node_put() performed by of_find_node_by_name().
>> */
>>> +             of_node_get(np);
>>> +             np_chan = of_find_node_by_name(np, chan_name);
>>> +             of_node_put(np);
>>> +     }
>>> +
>>> +     return np_chan;
>>> +}
>>> +
>>> +static int
>>> +rpmsg_gpio_channel_callback(struct rpmsg_device *rpdev, void *data,
>>> +                         int len, void *priv, u32 src) {
>>> +     struct gpio_rpmsg_packet *msg = data;
>>> +     struct rpmsg_gpio_port *port = NULL;
>>> +     struct rpdev_drvdata *drvdata;
>>> +
>>> +     drvdata = dev_get_drvdata(&rpdev->dev);
>>> +     if (drvdata && msg && msg->port_idx < MAX_PORT_PER_CHANNEL)
>>> +             port = drvdata->channel_devices[msg->port_idx];
>>> +
>>> +     if (!port)
>>> +             return -ENODEV;
>>> +
>>> +     if (msg->header.type == GPIO_RPMSG_REPLY) {
>>> +             *port->info.reply_msg = *msg;
>>> +             complete(&port->info.cmd_complete);
>>
>> What happen if the remoteprocessor answer after the completion timeout?
>> Could it result in desynchronization between the request and the answer?
> 
> If the remote processor responds after the timeout, that late reply will be ignored. The current
> transfer should fail with TIMEOUT, and the state won’t be carried over because cmd_complete
> is reinitialized before each new request, so a stale completion won’t desynchronize the next
> transaction. Each command–reply cycle is isolated, so a delayed reply cannot corrupt or mix with
> a subsequent request.

I missed the reinit_completion. Indeed, that prevents issue if reply 
arrive after the time out.

That said a second request can be sent before the remote processor 
responds to the first one:
- resquest 1 sent to remoteprocessor.
- timeout occurs
- request 2 sent to remote processor
- reply of request 1 received

Wouldn't this lead to a desynchronization between requests and replies? 
I do not see a mechanism that would prevent this

> 
>>
>> Having a cmd_counter in gpio_rpmsg_head could help to identify current request
>> and answer
>>
>> the use of reinit_completion could be also needed
>>
>>> +     } else if (msg->header.type == GPIO_RPMSG_NOTIFY) {
>>> +             generic_handle_domain_irq_safe(port->gc.irq.domain, msg->pin_idx);
>>> +     } else
>>> +             dev_err(&rpdev->dev, "wrong command type!\n");
>>
>> Could you print the msg->header.type value to help for debug?
>>
> 
> Sure. Will add it in next version.
> 
>>> +
>>> +     return 0;
>>> +}
>>> +
>>> +static int rpmsg_gpio_channel_probe(struct rpmsg_device *rpdev) {
>>> +     struct device *dev = &rpdev->dev;
>>> +     struct rpdev_drvdata *drvdata;
>>> +     struct device_node *np;
>>> +     int ret;
>>> +
>>> +     if (!dev->of_node) {
>>> +             np = rpmsg_get_channel_ofnode(rpdev, rpdev->id.name);
>>> +             if (np) {
>>> +                     dev->of_node = np;
>>> +                     set_primary_fwnode(dev, of_fwnode_handle(np));
>>> +             }
>>> +             return -EPROBE_DEFER;
>>> +     }
>>> +
>>> +     drvdata = devm_kzalloc(dev, sizeof(*drvdata), GFP_KERNEL);
>>> +     if (!drvdata)
>>> +             return -ENOMEM;
>>> +
>>> +     drvdata->rproc_name = rpmsg_get_rproc_node_name(rpdev);
>>> +     dev_set_drvdata(dev, drvdata);
>>> +
>>> +     for_each_child_of_node_scoped(dev->of_node, child) {
>>> +             if (!of_device_is_available(child))
>>> +                     continue;
>>> +
>>> +             if (!of_match_node(dev->driver->of_match_table, child))
>>> +                     continue;
>>> +
>>> +             ret = rpmsg_gpiochip_register(rpdev, child);
>>> +             if (ret < 0)
>>> +                     dev_err(dev, "Failed to register: %pOF\n", child);
>>> +     }
>>> +
>>> +     return 0;
>>
>> return ret
>> or indicate why the return of rpmsg_gpiochip_register is not taken into account
>>
> 
> rpmsg_gpiochip_register() failing only affects whether the GPIO instance gets created. The
> rpmsg channel driver itself can still probe successfully and continue to operate for other features.

This is not safe, by default you have to exist with error if something 
fails, ensuring that all resources allocated during the probe are released.
If there is a strong reason to not do this you have to explain the 
exception in a comment.

> 
>>
>>> +}
>>> +
>>> +static void rpmsg_gpio_channel_remove(struct rpmsg_device *rpdev) {
>>> +     dev_info(&rpdev->dev, "rpmsg gpio channel driver is removed\n");
>>> +}
>>> +
>>> +static const struct of_device_id rpmsg_gpio_dt_ids[] = {
>>> +     { .compatible = "rpmsg-gpio" },
>>> +     { /* sentinel */ }
>>> +};
>>> +
>>> +static struct rpmsg_device_id rpmsg_gpio_channel_id_table[] = {
>>> +     { .name = "rpmsg-io-channel" },
>>
>> I would remove the "-channel" suffix to have similar naming than "rpmsg-tty" and
>> "rpmsg-raw"
>>
> 
> The channel name comes from the remote firmware, so we can’t freely rename it on the
> Linux side. On i.MX platforms the firmware follows its own naming conventions, and the *-channel
> suffix is part of that scheme.

As Andrew mentioned, in other words, you cannot expect to impose 
upstream constraints based on your downstream legacy. Your legacy 
firmware will continue to be supported by your legacy NXP rpmsg GPIO driver.

Moreover, changing the name of this rpmsg channel will help you have 
both drivers coexist in your downstream kernel.

Regards
Arnaud


> 
> Thanks,
> Shenwei
> 
>> Regards,
>> Arnaud
>>
>>> +     { },
>>> +};
>>> +MODULE_DEVICE_TABLE(rpmsg, rpmsg_gpio_channel_id_table);
>>> +
>>> +static struct rpmsg_driver rpmsg_gpio_channel_client = {
>>> +     .drv.name       = KBUILD_MODNAME,
>>> +     .drv.of_match_table = rpmsg_gpio_dt_ids,
>>> +     .id_table       = rpmsg_gpio_channel_id_table,
>>> +     .probe          = rpmsg_gpio_channel_probe,
>>> +     .callback       = rpmsg_gpio_channel_callback,
>>> +     .remove         = rpmsg_gpio_channel_remove,
>>> +};
>>> +module_rpmsg_driver(rpmsg_gpio_channel_client);
>>> +
>>> +MODULE_AUTHOR("Shenwei Wang <shenwei.wang@nxp.com>");
>>> +MODULE_DESCRIPTION("generic rpmsg gpio driver");
>>> +MODULE_LICENSE("GPL");
> 


  reply	other threads:[~2026-02-20  9:32 UTC|newest]

Thread overview: 69+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-02-12 21:36 [PATCH v8 0/4] Enable Remote GPIO over RPMSG on i.MX Platform Shenwei Wang
2026-02-12 21:36 ` [PATCH v8 1/4] docs: driver-api: gpio: rpmsg gpio driver over rpmsg bus Shenwei Wang
2026-02-12 21:36 ` [PATCH v8 2/4] dt-bindings: remoteproc: imx_rproc: Add "rpmsg" subnode support Shenwei Wang
2026-02-12 21:36 ` [PATCH v8 3/4] gpio: rpmsg: add generic rpmsg GPIO driver Shenwei Wang
2026-02-18 10:20   ` Bartosz Golaszewski
2026-02-18 16:28     ` Shenwei Wang
2026-02-19  9:20   ` Arnaud POULIQUEN
2026-02-19 13:26     ` Andrew Lunn
2026-02-19 14:17       ` Shenwei Wang
2026-02-19 15:25         ` Andrew Lunn
2026-02-19 16:42           ` Shenwei Wang
2026-02-19 13:42     ` Andrew Lunn
2026-02-20  9:16       ` Arnaud POULIQUEN
2026-02-20 13:48         ` Andrew Lunn
2026-02-20 16:36           ` Shenwei Wang
2026-02-20 17:45             ` Andrew Lunn
2026-02-20 18:57               ` Shenwei Wang
2026-02-20 20:21                 ` Mathieu Poirier
2026-02-20 20:59                 ` Andrew Lunn
2026-02-22 14:48                 ` Linus Walleij
2026-02-23 14:24                   ` Arnaud POULIQUEN
2026-02-23 14:42                     ` Bjorn Andersson
2026-02-24 15:56                       ` Shenwei Wang
2026-02-24 16:04                         ` Daniel Baluta
2026-02-24 16:56                           ` Shenwei Wang
2026-02-24 18:09                         ` Mathieu Poirier
2026-02-24 20:16                           ` Shenwei Wang
2026-02-24 20:41                             ` Mathieu Poirier
2026-02-24 21:12                               ` Shenwei Wang
2026-02-24 22:14                                 ` Andrew Lunn
2026-02-24 22:43                                   ` Shenwei Wang
2026-02-25 15:52                                     ` Bjorn Andersson
2026-02-25 17:54                                       ` Shenwei Wang
2026-02-25 19:43                                         ` Bjorn Andersson
2026-02-25 20:31                                           ` Shenwei Wang
2026-02-25 21:02                                             ` Bjorn Andersson
2026-02-27  0:00                                               ` Linus Walleij
2026-02-23 20:33                     ` Shenwei Wang
2026-02-24  8:46                       ` Arnaud POULIQUEN
2026-02-24 16:05                         ` Shenwei Wang
2026-02-24 17:31                           ` Andrew Lunn
2026-02-24 17:54                             ` Shenwei Wang
2026-02-24 18:18                               ` Andrew Lunn
2026-02-24 19:51                                 ` Shenwei Wang
2026-02-24 21:01                                   ` Andrew Lunn
2026-02-24 21:18                                     ` [EXT] " Shenwei Wang
2026-02-24 22:22                                       ` Andrew Lunn
2026-02-24 22:31                                         ` Shenwei Wang
2026-02-24 22:47                                           ` Mathieu Poirier
2026-02-25 15:18                                             ` Shenwei Wang
2026-02-24 18:26                               ` Andrew Lunn
2026-02-24 20:33                                 ` Shenwei Wang
2026-02-24  9:37                       ` Linus Walleij
2026-02-19 20:04     ` Shenwei Wang
2026-02-19 20:50       ` Andrew Lunn
2026-02-19 21:12         ` Shenwei Wang
2026-02-20  9:12       ` Arnaud POULIQUEN
2026-02-20 15:47         ` Shenwei Wang
2026-02-20 16:19           ` Andrew Lunn
2026-02-20 17:09             ` Shenwei Wang
2026-02-20 17:42               ` Andrew Lunn
2026-02-20 19:09                 ` Shenwei Wang
2026-02-20 20:41                   ` Andrew Lunn
2026-02-19 21:13     ` Shenwei Wang
2026-02-20  9:32       ` Arnaud POULIQUEN [this message]
2026-02-20 15:12         ` Shenwei Wang
2026-02-12 21:36 ` [PATCH v8 4/4] arm64: dts: imx8ulp: Add rpmsg node under imx_rproc Shenwei Wang
2026-02-20  9:18 ` [PATCH v8 0/4] Enable Remote GPIO over RPMSG on i.MX Platform Daniel Baluta
2026-02-20 15:24   ` 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=fdbdfd15-1848-4d17-ab1c-53472ab6c817@foss.st.com \
    --to=arnaud.pouliquen@foss.st.com \
    --cc=andersson@kernel.org \
    --cc=andrew@lunn.ch \
    --cc=brgl@bgdev.pl \
    --cc=brgl@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=corbet@lwn.net \
    --cc=devicetree@vger.kernel.org \
    --cc=festevam@gmail.com \
    --cc=frank.li@nxp.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=shenwei.wang@nxp.com \
    --cc=skhan@linuxfoundation.org \
    /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