Skip to contentSkip to conversation

Enable Remote GPIO over RPMSG on i.MX Platform

PATCH Applied Shenwei Wang 6 participants 19 messages Oct 9, 2025 – Oct 22, 2025

Subsystems (5)

v3 of 13 Applied Latest is v13 →

lore
Share & tools
lore
#0 lore raw

v3 cover Enable Remote GPIO over RPMSG on i.MX Platform

Support the remote devices on the remote processor via the RPMSG bus on i.MX platform.

Changes in v3:
- fix various format issue and return value check per Peng 's review comments.
- add the logic to also populate the subnodes which are not in the device map per Arnaud's request. (in imx_rproc.c)
- update the yaml per Frank's review comments.

Changes in v2:
- re-implemented the gpio driver per Linus Walleij's feedback by using GPIOLIB_IRQCHIP helper library.
- fix various format issue per Mathieu/Peng 's review comments.
- update the yaml doc per Rob's feedback

Cc Mathieu Poirier <[email protected]>
Cc Arnaud POULIQUEN <[email protected]>
Cc Linus Walleij <[email protected]>

Shenwei Wang (4):
dt-bindings: remoteproc: imx_rproc: Add "rpmsg" subnode support
remoteproc: imx_rproc: Populate devices under "rpmsg" subnode
gpio: imx-rpmsg: add imx-rpmsg GPIO driver
arm64: dts: imx8ulp: Add rpmsg node under imx_rproc

 .../bindings/remoteproc/fsl,imx-rproc.yaml    | 123 +++++
 arch/arm64/boot/dts/freescale/imx8ulp.dtsi    |  27 +
 drivers/gpio/Kconfig                          |  17 +
 drivers/gpio/Makefile                         |   1 +
 drivers/gpio/gpio-imx-rpmsg.c                 | 486 ++++++++++++++++++
 drivers/remoteproc/imx_rproc.c                | 146 ++++++
 include/linux/rpmsg/imx_rpmsg.h               |  48 ++
 7 files changed, 848 insertions(+)
 create mode 100644 drivers/gpio/gpio-imx-rpmsg.c
 create mode 100644 include/linux/rpmsg/imx_rpmsg.h

--
2.43.0

#1 lore raw

PATCH v3 1/4 dt-bindings: remoteproc: imx_rproc: Add "rpmsg" subnode support

Remote processors may announce multiple devices (e.g., I2C, GPIO) over an RPMSG channel. These devices may require corresponding device tree nodes, especially when acting as providers, to supply phandles for their consumers.

Define an RPMSG node to work as a container for a group of RPMSG channels under the imx_rproc node.

Each subnode within "rpmsg" represents an individual RPMSG channel. The name of each subnode corresponds to the channel name as defined by the remote processor.

All remote devices associated with a given channel are defined as child nodes under the corresponding channel node.

---
 .../bindings/remoteproc/fsl,imx-rproc.yaml    | 123 ++++++++++++++++++
 1 file changed, 123 insertions(+)
Documentation/devicetree/bindings/remoteproc/fsl,imx-rproc.yaml +123 -0
index 57d75acb0b5e..897a16c4f7db 100644
@@ -84,6 +84,92 @@ properties:
       This property is to specify the resource id of the remote processor in SoC
       which supports SCFW
 
+  rpmsg:
+    type: object
+    additionalProperties: false
+    description:
+      Present a group of RPMSG channel devices.
+
+    properties:
+      rpmsg-io-channel:
+        type: object
+        additionalProperties: false
+        properties:
+          '#address-cells':
+            const: 1
+
+          '#size-cells':
+            const: 0
+
+        patternProperties:
+          "gpio@[0-9a-f]+$":
+            type: object
+            unevaluatedProperties: false
+            properties:
+              compatible:
+                enum:
+                  - fsl,imx-rpmsg-gpio
+
+              reg:
+                maxItems: 1
+
+              "#gpio-cells":
+                const: 2
+
+              gpio-controller: true
+
+              interrupt-controller: true
+
+              "#interrupt-cells":
+                const: 2
+
+            required:
+              - compatible
+              - reg
+              - "#gpio-cells"
+              - "#interrupt-cells"
+
+            allOf:
+              - $ref: /schemas/gpio/gpio.yaml#
+              - $ref: /schemas/interrupt-controller.yaml#
+
+        required:
+          - '#address-cells'
+          - '#size-cells'
+
+      rpmsg-i2c-channel:
+        type: object
+        unevaluatedProperties: false
+        properties:
+          '#address-cells':
+            const: 1
+
+          '#size-cells':
+            const: 0
+
+        patternProperties:
+          "i2c@[0-9a-f]+$":
+            type: object
+            unevaluatedProperties: false
+            properties:
+              compatible:
+                enum:
+                  - fsl,imx-rpmsg-i2c
+
+              reg:
+                maxItems: 1
+
+            required:
+              - compatible
+              - reg
+
+            allOf:
+              - $ref: /schemas/i2c/i2c-controller.yaml#
+
+        required:
+          - '#address-cells'
+          - '#size-cells'
+
 required:
   - compatible
 
@@ -146,5 +232,42 @@ examples:
                 &mu 3 1>;
       memory-region = <&vdev0buffer>, <&vdev0vring0>, <&vdev0vring1>, <&rsc_table>;
       syscon = <&src>;
+
+      rpmsg {
+        rpmsg-io-channel {
+          #address-cells = <1>;
+          #size-cells = <0>;
+
+          gpio@0 {
+            compatible = "fsl,imx-rpmsg-gpio";
+            reg = <0>;
+            gpio-controller;
+            #gpio-cells = <2>;
+            #interrupt-cells = <2>;
+            interrupt-controller;
+            interrupt-parent = <&rpmsg_gpioa>;
+          };
+
+          gpio@1 {
+            compatible = "fsl,imx-rpmsg-gpio";
+            reg = <1>;
+            gpio-controller;
+            #gpio-cells = <2>;
+            #interrupt-cells = <2>;
+            interrupt-controller;
+            interrupt-parent = <&rpmsg_gpiob>;
+          };
+        };
+
+        rpmsg-i2c-channel {
+          #address-cells = <1>;
+          #size-cells = <0>;
+
+          i2c@0 {
+            compatible = "fsl,imx-rpmsg-i2c";
+            reg = <0>;
+          };
+        };
+      };
     };
 ...
Signature · 1 line
2.43.0
#2 lore raw

Re: (subset) [PATCH v3 1/4] dt-bindings: remoteproc: imx_rproc: Add "rpmsg" subnode support

Quoted 9 lines · Shenwei Wang

Remote processors may announce multiple devices (e.g., I2C, GPIO) over an RPMSG channel. These devices may require corresponding device tree nodes, especially when acting as providers, to supply phandles for their consumers.

Define an RPMSG node to work as a container for a group of RPMSG channels under the imx_rproc node.

[...]

Applied, thanks!

[1/4] dt-bindings: remoteproc: imx_rproc: Add "rpmsg" subnode support
(no commit info)

Best regards,

Signature · 1 line
Krzysztof Kozlowski <[email protected]>
#3 lore raw

Re: (subset) [PATCH v3 1/4] dt-bindings: remoteproc: imx_rproc: Add "rpmsg" subnode support

Hello Krzysztof,

Quoted 7 lines · Krzysztof Kozlowski
Quoted 5 lines · Shenwei Wang

Remote processors may announce multiple devices (e.g., I2C, GPIO) over an RPMSG channel. These devices may require corresponding device tree nodes, especially when acting as providers, to supply phandles for their consumers.

Quoted 6 lines
Quoted 4 lines

Define an RPMSG node to work as a container for a group of RPMSG channels under the imx_rproc node.

[...]

Applied, thanks!

For your information, there are requirements to make the rpmsg-gpio driver generic [1]. This could impact these bindings.

Best Regards,
Arnaud

[1] https://lkml.org/lkml/2025/10/13/790

Quoted 5 lines

[1/4] dt-bindings: remoteproc: imx_rproc: Add "rpmsg" subnode support
(no commit info)

Best regards,

#4 lore raw

Re: (subset) [PATCH v3 1/4] dt-bindings: remoteproc: imx_rproc: Add "rpmsg" subnode support

In reply to Krzysztof Kozlowski
Quoted 10 lines · Krzysztof Kozlowski
Quoted 8 lines · Shenwei Wang

Remote processors may announce multiple devices (e.g., I2C, GPIO) over an RPMSG channel. These devices may require corresponding device tree nodes, especially when acting as providers, to supply phandles for their consumers.

Define an RPMSG node to work as a container for a group of RPMSG channels under the imx_rproc node.

Quoted 7 lines
Quoted 1 line

[...]

Applied, thanks!

[1/4] dt-bindings: remoteproc: imx_rproc: Add "rpmsg" subnode support
(no commit info)

This was not applied, I just b4-ty wrong patch.

Best regards,
Krzysztof

#5 lore raw

PATCH v3 2/4 remoteproc: imx_rproc: Populate devices under "rpmsg" subnode

In reply to Shenwei Wang

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>;
				};

				...
			};

			rpmsg-i2c-channel {
				i2c@0 {
					compatible = "fsl,imx-rpmsg-i2c";
					reg = <0>;
				};
			};

			...
		};
	};
---
 drivers/remoteproc/imx_rproc.c  | 146 ++++++++++++++++++++++++++++++++
 include/linux/rpmsg/imx_rpmsg.h |  48 +++++++++++
 2 files changed, 194 insertions(+)
 create mode 100644 include/linux/rpmsg/imx_rpmsg.h
drivers/remoteproc/imx_rproc.c +146 -0
index a6eef0080ca9..e21a7980c490 100644
@@ -8,6 +8,7 @@
 #include <linux/clk.h>
 #include <linux/err.h>
 #include <linux/firmware/imx/sci.h>
+#include <linux/rpmsg/imx_rpmsg.h>
 #include <linux/interrupt.h>
 #include <linux/kernel.h>
 #include <linux/mailbox_client.h>
@@ -15,6 +16,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 +25,7 @@
 #include <linux/reboot.h>
 #include <linux/regmap.h>
 #include <linux/remoteproc.h>
+#include <linux/rpmsg.h>
 #include <linux/workqueue.h>
 
 #include "imx_rproc.h"
@@ -1084,6 +1088,144 @@ static int imx_rproc_sys_off_handler(struct sys_off_data *data)
 	return NOTIFY_DONE;
 }
 
+struct imx_rpmsg_driver {
+	struct rpmsg_driver rpdrv;
+	void *driver_data;
+};
+
+static char *channel_device_map[][2] = {
+	{"rpmsg-io-channel", "fsl,imx-rpmsg-gpio"},
+	{"rpmsg-i2c-channel", "fsl,imx-rpmsg-i2c"},
+};
+
+static int imx_rpmsg_endpoint_cb(struct rpmsg_device *rpdev, void *data,
+				 int len, void *priv, u32 src)
+{
+	struct imx_rpmsg_driver_data *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 imx_rpmsg_driver_data *drvdata;
+	struct imx_rpmsg_driver *imx_rpdrv;
+	struct device *dev = &rpdev->dev;
+	struct of_dev_auxdata *auxdata;
+	struct rpmsg_driver *rpdrv;
+	int i;
+
+	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;
+
+	i = drvdata->map_idx;
+	if (i >= ARRAY_SIZE(channel_device_map))
+		return -ENODEV;
+
+	auxdata = devm_kzalloc(dev, sizeof(*auxdata) * 2, GFP_KERNEL);
+	if (!auxdata)
+		return -ENOMEM;
+
+	drvdata->rpdev = rpdev;
+	auxdata[0].compatible = channel_device_map[i][1];
+	auxdata[0].platform_data = drvdata;
+	dev_set_drvdata(dev, drvdata);
+
+	of_platform_populate(drvdata->channel_node, NULL, auxdata, dev);
+	of_node_put(drvdata->channel_node);
+
+	return 0;
+}
+
+static int 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 i;
+	}
+
+	return -1;
+}
+
+static int imx_of_rpmsg_register_rpdriver(struct device_node *channel,
+					  struct device *dev, int idx)
+{
+	struct imx_rpmsg_driver_data *driver_data;
+	struct imx_rpmsg_driver *rp_driver;
+	struct rpmsg_device_id *rpdev_id;
+
+	rpdev_id = devm_kzalloc(dev, sizeof(*rpdev_id) * 2, GFP_KERNEL);
+	if (!rpdev_id)
+		return -ENOMEM;
+
+	strscpy(rpdev_id[0].name, channel_device_map[idx][0], 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;
+	driver_data->map_idx = idx;
+
+	rp_driver->rpdrv.drv.name = channel_device_map[idx][0];
+	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;
+
+	register_rpmsg_driver(&rp_driver->rpdrv);
+
+	return 0;
+}
+
+static int imx_of_rpmsg_node_init(struct platform_device *pdev)
+{
+	struct device_node *np __free(device_node);
+	struct device *dev = &pdev->dev;
+	int idx, ret;
+
+	np = of_get_child_by_name(dev->of_node, "rpmsg");
+	if (!np)
+		return 0;
+
+	for_each_child_of_node_scoped(np, child) {
+		idx = imx_of_rpmsg_is_in_map(child->name);
+		if (idx < 0)
+			ret = of_platform_default_populate(child, NULL, dev);
+		else
+			ret = imx_of_rpmsg_register_rpdriver(child, dev, idx);
+
+		if (ret < 0)
+			return ret;
+	}
+
+	return 0;
+}
+
 static int imx_rproc_probe(struct platform_device *pdev)
 {
 	struct device *dev = &pdev->dev;
@@ -1177,6 +1319,10 @@ static int imx_rproc_probe(struct platform_device *pdev)
 		goto err_put_clk;
 	}
 
+	ret = imx_of_rpmsg_node_init(pdev);
+	if (ret < 0)
+		dev_info(dev, "populating 'rpmsg' node failed\n");
+
 	return 0;
 
 err_put_clk:
include/linux/rpmsg/imx_rpmsg.h new file +48 -0

48 lines not on this page · raw message

Signature · 1 line
2.43.0
#6 lore raw

PATCH v3 3/4 gpio: imx-rpmsg: add imx-rpmsg GPIO driver

In reply to Shenwei Wang

On i.MX SoCs, the system may include two processors:
- An MCU running an RTOS
- An MPU running Linux

These processors communicate via the RPMSG protocol. The driver implements the standard GPIO interface, allowing the Linux side to control GPIO controllers which reside in the remote processor via RPMSG protocol.

---
 drivers/gpio/Kconfig          |  17 ++
 drivers/gpio/Makefile         |   1 +
 drivers/gpio/gpio-imx-rpmsg.c | 486 ++++++++++++++++++++++++++++++++++
 3 files changed, 504 insertions(+)
 create mode 100644 drivers/gpio/gpio-imx-rpmsg.c
drivers/gpio/Kconfig +17 -0
index a437fe652dbc..97eda94b0ba1 100644
@@ -1847,6 +1847,23 @@ config GPIO_SODAVILLE
 
 endmenu
 
+menu "RPMSG GPIO drivers"
+	depends on RPMSG
+
+config GPIO_IMX_RPMSG
+	tristate "NXP i.MX SoC RPMSG GPIO support"
+	depends on IMX_REMOTEPROC
+	select GPIOLIB_IRQCHIP
+	default IMX_REMOTEPROC
+	help
+	  Say yes here to support the RPMSG GPIO functions on i.MX SoC based
+	  platform.  Currently supported devices: i.MX7ULP, i.MX8ULP, i.MX8x,
+	  and i.MX9x.
+
+	  If unsure, say N.
+
+endmenu
+
 menu "SPI GPIO expanders"
 	depends on SPI_MASTER
 
drivers/gpio/Makefile +1 -0
index 379f55e9ed1e..e01465c03431 100644
@@ -83,6 +83,7 @@ obj-$(CONFIG_GPIO_I8255)		+= gpio-i8255.o
 obj-$(CONFIG_GPIO_ICH)			+= gpio-ich.o
 obj-$(CONFIG_GPIO_IDIO_16)		+= gpio-idio-16.o
 obj-$(CONFIG_GPIO_IDT3243X)		+= gpio-idt3243x.o
+obj-$(CONFIG_GPIO_IMX_RPMSG)		+= gpio-imx-rpmsg.o
 obj-$(CONFIG_GPIO_IMX_SCU)		+= gpio-imx-scu.o
 obj-$(CONFIG_GPIO_IT87)			+= gpio-it87.o
 obj-$(CONFIG_GPIO_IXP4XX)		+= gpio-ixp4xx.o
drivers/gpio/gpio-imx-rpmsg.c new file +486 -0

486 lines not on this page · raw message

Signature · 1 line
2.43.0
#7 lore raw

Re: [PATCH v3 3/4] gpio: imx-rpmsg: add imx-rpmsg GPIO driver

Quoted 8 lines · Shenwei Wang

On i.MX SoCs, the system may include two processors:
- An MCU running an RTOS
- An MPU running Linux

These processors communicate via the RPMSG protocol. The driver implements the standard GPIO interface, allowing the Linux side to control GPIO controllers which reside in the remote processor via RPMSG protocol.

I've not seen the discussion on earlier versions of this patchset, so i might be asking something already asked and answered. Sorry if i am.

Is there anything IMX specific in here? This appears to be the first RPMSG GPIO driver. Do we have the opportunity here to define a protocol for all future RPMSG GPIO drivers, which any/all vendors should follow, so we don't have lots of different implementations of basically they same thing? So this would become gpio-rpmsg.c and a Document somewhere describing the protocol?

Andrew

maintainer
#8 lore raw

Re: [PATCH v3 3/4] gpio: imx-rpmsg: add imx-rpmsg GPIO driver

Quoted 13 lines · Andrew Lunn
Quoted 8 lines · Shenwei Wang

On i.MX SoCs, the system may include two processors:
- An MCU running an RTOS
- An MPU running Linux

These processors communicate via the RPMSG protocol. The driver implements the standard GPIO interface, allowing the Linux side to control GPIO controllers which reside in the remote processor via RPMSG protocol.

I've not seen the discussion on earlier versions of this patchset, so i might be asking something already asked and answered. Sorry if i am.

Quoted 7 lines

Is there anything IMX specific in here? This appears to be the first RPMSG GPIO driver. Do we have the opportunity here to define a protocol for all future RPMSG GPIO drivers, which any/all vendors should follow, so we don't have lots of different implementations of basically they same thing? So this would become gpio-rpmsg.c and a Document somewhere describing the protocol?

I haven't looked at this patchset yet but I think Andrew's proposal has merit.

Quoted 1 line

Andrew

#9 lore raw

Re: [PATCH v3 3/4] gpio: imx-rpmsg: add imx-rpmsg GPIO driver

Quoted 22 lines · Mathieu Poirier
Quoted 13 lines · Andrew Lunn
Quoted 8 lines · Shenwei Wang

On i.MX SoCs, the system may include two processors:
- An MCU running an RTOS
- An MPU running Linux

These processors communicate via the RPMSG protocol. The driver implements the standard GPIO interface, allowing the Linux side to control GPIO controllers which reside in the remote processor via RPMSG protocol.

I've not seen the discussion on earlier versions of this patchset, so i might be asking something already asked and answered. Sorry if i am.

Quoted 7 lines

Is there anything IMX specific in here? This appears to be the first RPMSG GPIO driver. Do we have the opportunity here to define a protocol for all future RPMSG GPIO drivers, which any/all vendors should follow, so we don't have lots of different implementations of basically they same thing? So this would become gpio-rpmsg.c and a Document somewhere describing the protocol?

Quoted 1 line

I haven't looked at this patchset yet but I think Andrew's proposal has merit.

Yeah this was my comment on v2 as well :D

I even posted a bug to the AMP mailing list to elicit some attention from that camp. It worked because now Arnaud is on board reviewing the patch set from an ST PoV.

Maybe it is possible to split the driver in one generic part and one i.MX part, so it is easy to reuse for other SoCs?

Yours,
Linus Walleij

#10 lore raw

Re: [PATCH v3 3/4] gpio: imx-rpmsg: add imx-rpmsg GPIO driver

In reply to Andrew Lunn
Quoted 27 lines

-----Original Message-----
From: Andrew Lunn <[email protected]>
Sent: Thursday, October 9, 2025 5:59 PM
To: Shenwei Wang <[email protected]>
Cc: Bjorn Andersson <[email protected]>; Mathieu Poirier <[email protected]>; Rob Herring <[email protected]>; Krzysztof Kozlowski <[email protected]>; Conor Dooley <[email protected]>; Shawn Guo <[email protected]>; Sascha Hauer <[email protected]>; Linus Walleij <[email protected]>; Bartosz Golaszewski <[email protected]>; Pengutronix Kernel Team <[email protected]>; Fabio Estevam <[email protected]>; Peng Fan <[email protected]>; linux- [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; dl-linux-imx <[email protected]>
Subject: [EXT] Re: [PATCH v3 3/4] gpio: imx-rpmsg: add imx-rpmsg GPIO driver

Quoted 8 lines · Shenwei Wang

On i.MX SoCs, the system may include two processors:
- An MCU running an RTOS
- An MPU running Linux

These processors communicate via the RPMSG protocol.
The driver implements the standard GPIO interface, allowing the Linux side to control GPIO controllers which reside in the remote processor via RPMSG protocol.

Quoted 9 lines

I've not seen the discussion on earlier versions of this patchset, so i might be asking something already asked and answered. Sorry if i am.

Is there anything IMX specific in here? This appears to be the first RPMSG GPIO driver. Do we have the opportunity here to define a protocol for all future RPMSG GPIO drivers, which any/all vendors should follow, so we don't have lots of different implementations of basically they same thing? So this would become gpio-rpmsg.c and a Document somewhere describing the protocol?

The only platform-specific part is the message format exchanged between Linux and the remote processors. As long as the remote processor follows the same message protocol, the driver should work as expected.

Here's the layout of the message packets:

+--------+--------+--------+--------+--------+----------------+--------+--------+---------------+---------------+
|0x00    |0x01    |0x02    |0x03    |0x04    |0x05..0x09      |0x0A    |0x0B    |0x0C           |0x0D           |
|cate    |major   |minor   |type    |cmd     |reserved[5]     |pin_idx |port_idx|out:{evt/rc/v} |in:{wkup/val}  |
+--------+--------+--------+--------+--------+----------------+--------+--------+---------------+---------------+

Cate (Category field ): can be GPIO /I2C/PMIC/AUDIO ... etc Major : Major version number
Minor: Minor version number
Type (Message Type): Can be SETUP / REPLY /NOTIFY for GPIO category Cmd (Command): Can be Input INIT / Output INIT / Input GET for GPIO category
Pin_idx: The GPIO line index
Port_idx: The GPIO controller index

For Out packet:
if it is OUPUT INIT, the out field value is the gpio output level. If it is INPUT INIT, the out filed is 0.

For In packet:
If it is a REPLY message, the out field is return code. 0 means success.
If it is a REPLY of INPUT GET, the in field is the value of GPIO line level. If it is an NOTIFY type of message, it simulates an interrupt event from the remote processor.

I can add above comments in the commit log or the beginning of the driver source file.

Thanks,
Shenwei

Quoted 1 line

Andrew

#11 lore raw

Re: [PATCH v3 3/4] gpio: imx-rpmsg: add imx-rpmsg GPIO driver

Quoted 22 lines

The only platform-specific part is the message format exchanged between Linux and the remote processors. As long as the remote processor follows the same message protocol, the driver should work as expected.

Here's the layout of the message packets:

+--------+--------+--------+--------+--------+----------------+--------+--------+---------------+---------------+
|0x00    |0x01    |0x02    |0x03    |0x04    |0x05..0x09      |0x0A    |0x0B    |0x0C           |0x0D           |
|cate    |major   |minor   |type    |cmd     |reserved[5]     |pin_idx |port_idx|out:{evt/rc/v} |in:{wkup/val}  |
+--------+--------+--------+--------+--------+----------------+--------+--------+---------------+---------------+

Cate (Category field ): can be GPIO /I2C/PMIC/AUDIO ... etc Major : Major version number
Minor: Minor version number
Type (Message Type): Can be SETUP / REPLY /NOTIFY for GPIO category Cmd (Command): Can be Input INIT / Output INIT / Input GET for GPIO category
Pin_idx: The GPIO line index
Port_idx: The GPIO controller index

For Out packet:
if it is OUPUT INIT, the out field value is the gpio output level. If it is INPUT INIT, the out filed is 0.

Quoted 6 lines

For In packet:
If it is a REPLY message, the out field is return code. 0 means success.
If it is a REPLY of INPUT GET, the in field is the value of GPIO line level. If it is an NOTIFY type of message, it simulates an interrupt event from the remote processor.

I can add above comments in the commit log or the beginning of the driver source file.

Maybe Documentation/admin-guide/gpio-rpmsg.rst would be better. You should also document how to handle features the device does not support. e.g. i _think_ your hardware supports all 4 interrupt types. But maybe other hardware needs to return something meaning -EOPNOTSUP?

Andrew

#12 lore raw

Re: [PATCH v3 3/4] gpio: imx-rpmsg: add imx-rpmsg GPIO driver

Quoted 52 lines

-----Original Message-----
From: Andrew Lunn <[email protected]>
Sent: Friday, October 10, 2025 2:32 PM
To: Shenwei Wang <[email protected]>
Cc: Bjorn Andersson <[email protected]>; Mathieu Poirier <[email protected]>; Rob Herring <[email protected]>; Krzysztof Kozlowski <[email protected]>; Conor Dooley <[email protected]>; Shawn Guo <[email protected]>; Sascha Hauer <[email protected]>; Linus Walleij <[email protected]>; Bartosz Golaszewski <[email protected]>; Pengutronix Kernel Team <[email protected]>; Fabio Estevam <[email protected]>; Peng Fan <[email protected]>; linux- [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; dl-linux-imx <[email protected]>
Subject: [EXT] Re: [PATCH v3 3/4] gpio: imx-rpmsg: add imx-rpmsg GPIO driver

Quoted 1 line

The only platform-specific part is the message format exchanged between

Linux and the remote processors.

Quoted 1 line

As long as the remote processor follows the same message protocol, the driver

should work as expected.

Quoted 4 lines

Here's the layout of the message packets:

+--------+--------+--------+--------+--------+----------------+--------+--------+----------

-----+---------------+

Quoted 1 line

|0x00 |0x01 |0x02 |0x03 |0x04 |0x05..0x09 |0x0A |0x0B |0x0C

|0x0D           |
> |cate    |major   |minor   |type    |cmd     |reserved[5]     |pin_idx
|port_idx|out:{evt/rc/v} |in:{wkup/val}  |
Quoted 1 line

+--------+--------+--------+--------+--------+----------------+--------+--------+----------

-----+---------------+

Quoted 10 lines

Cate (Category field ): can be GPIO /I2C/PMIC/AUDIO ... etc Major :
Major version number
Minor: Minor version number
Type (Message Type): Can be SETUP / REPLY /NOTIFY for GPIO category Cmd (Command): Can be Input INIT / Output INIT / Input GET for GPIO category
Pin_idx: The GPIO line index
Port_idx: The GPIO controller index

Quoted 8 lines

For Out packet:
if it is OUPUT INIT, the out field value is the gpio output level. If it is INPUT INIT, the out filed is 0.

For In packet:
If it is a REPLY message, the out field is return code. 0 means success. If it is a REPLY of INPUT GET, the in field is the value of GPIO line level. If it is an NOTIFY type of message, it simulates an interrupt event from the

remote processor.

Quoted 1 line
Quoted 8 lines
Quoted 1 line

I can add above comments in the commit log or the beginning of the driver

source file.

Maybe Documentation/admin-guide/gpio-rpmsg.rst would be better. You should also document how to handle features the device does not support. e.g. i _think_ your hardware supports all 4 interrupt types. But maybe other hardware needs to return something meaning -EOPNOTSUP?

That should be one type of the error return code in the out field of REPLY message. The return code of 0 means success, and the others are error codes.

I will add a gpio-rpmsg.rst file in the next patches.

Thanks,
Shenwei

Quoted 1 line

Andrew

#13 lore raw

Re: [PATCH v3 3/4] gpio: imx-rpmsg: add imx-rpmsg GPIO driver

Quoted 8 lines
Quoted 5 lines

Maybe Documentation/admin-guide/gpio-rpmsg.rst would be better. You should also document how to handle features the device does not support. e.g. i _think_ your hardware supports all 4 interrupt types. But maybe other hardware needs to return something meaning -EOPNOTSUP?

That should be one type of the error return code in the out field of REPLY message. The return code of 0 means success, and the others are error codes.

You need to be careful of architecture code:

https://elixir.bootlin.com/linux/v6.17.1/A/ident/EOPNOTSUPP

Notice how ENOPNOTSUPP can be 45, 122, 223, or 95. Returning EL2NSYNC or EDQUOT to user space is going to cause confusion...

Andrew

#14 lore raw

Re: [PATCH v3 3/4] gpio: imx-rpmsg: add imx-rpmsg GPIO driver

Quoted 38 lines

-----Original Message-----
From: Andrew Lunn <[email protected]>
Sent: Monday, October 13, 2025 9:56 AM
To: Shenwei Wang <[email protected]>
Cc: Bjorn Andersson <[email protected]>; Mathieu Poirier <[email protected]>; Rob Herring <[email protected]>; Krzysztof Kozlowski <[email protected]>; Conor Dooley <[email protected]>; Shawn Guo <[email protected]>; Sascha Hauer <[email protected]>; Linus Walleij <[email protected]>; Bartosz Golaszewski <[email protected]>; Pengutronix Kernel Team <[email protected]>; Fabio Estevam <[email protected]>; Peng Fan <[email protected]>; linux- [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; dl-linux-imx <[email protected]>
Subject: [EXT] Re: [PATCH v3 3/4] gpio: imx-rpmsg: add imx-rpmsg GPIO driver

Quoted 4 lines
Quoted 4 lines

Maybe Documentation/admin-guide/gpio-rpmsg.rst would be better. You should also document how to handle features the device does not support. e.g. i _think_ your hardware supports all 4 interrupt types. But maybe other hardware needs to return something meaning -

EOPNOTSUP?

Quoted 3 lines
Quoted 1 line

That should be one type of the error return code in the out field of REPLY

message.

Quoted 1 line

The return code of 0 means success, and the others are error codes.

You need to be careful of architecture code:

https://elixir.bootl/
in.com%2Flinux%2Fv6.17.1%2FA%2Fident%2FEOPNOTSUPP&data=05%7C02%7 Cshenwei.wang%40nxp.com%7Ce2c6c89bb8cb41882a5208de0a68aa7b%7C686 ea1d3bc2b4c6fa92cd99c5c301635%7C0%7C0%7C638959641921284557%7CUn known%7CTWFpbGZsb3d8eyJFbXB0eU1hcGkiOnRydWUsIlYiOiIwLjAuMDAwMCIs IlAiOiJXaW4zMiIsIkFOIjoiTWFpbCIsIldUIjoyfQ%3D%3D%7C0%7C%7C%7C&sdata =Lx%2B8iM3d8flgUq8kn8bnaDmxZDea8pPp2wL5V7JT%2BDM%3D&reserved=0

Quoted 3 lines

Notice how ENOPNOTSUPP can be 45, 122, 223, or 95. Returning EL2NSYNC or EDQUOT to user space is going to cause confusion...

I think we should just follow the definitions in include/uapi/asm-generic/errno.h, right?

Thanks,
Shenwei

Quoted 1 line

Andrew

#15 lore raw

Re: [PATCH v3 3/4] gpio: imx-rpmsg: add imx-rpmsg GPIO driver

Quoted 7 lines
Quoted 3 lines

Notice how ENOPNOTSUPP can be 45, 122, 223, or 95. Returning EL2NSYNC or EDQUOT to user space is going to cause confusion...

I think we should just follow the definitions in
include/uapi/asm-generic/errno.h, right?

No.

Try a make for mips, and look at includes you end up with. You will find it goes something like:

# 1 "./arch/mips/include/asm/errno.h" 1
# 11 "./arch/mips/include/asm/errno.h"
# 1 "./arch/mips/include/uapi/asm/errno.h" 1
# 16 "./arch/mips/include/uapi/asm/errno.h"
# 1 "./include/uapi/asm-generic/errno-base.h" 1
# 17 "./arch/mips/include/uapi/asm/errno.h" 2

and this results in

#define EOPNOTSUPP 122 /* Operation not supported on transport endpoint */

not what you get from asm-generic/errno.h:

#define EOPNOTSUPP 95 /* Operation not supported on transport endpoint */

Andrew

#16 lore raw

Re: [PATCH v3 3/4] gpio: imx-rpmsg: add imx-rpmsg GPIO driver

Quoted 39 lines

-----Original Message-----
From: Andrew Lunn <[email protected]>
Sent: Monday, October 13, 2025 11:56 AM
To: Shenwei Wang <[email protected]>
Cc: Bjorn Andersson <[email protected]>; Mathieu Poirier <[email protected]>; Rob Herring <[email protected]>; Krzysztof Kozlowski <[email protected]>; Conor Dooley <[email protected]>; Shawn Guo <[email protected]>; Sascha Hauer <[email protected]>; Linus Walleij <[email protected]>; Bartosz Golaszewski <[email protected]>; Pengutronix Kernel Team <[email protected]>; Fabio Estevam <[email protected]>; Peng Fan <[email protected]>; linux- [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; dl-linux-imx <[email protected]>
Subject: [EXT] Re: [PATCH v3 3/4] gpio: imx-rpmsg: add imx-rpmsg GPIO driver

Quoted 7 lines
Quoted 3 lines

Notice how ENOPNOTSUPP can be 45, 122, 223, or 95. Returning EL2NSYNC or EDQUOT to user space is going to cause confusion...

I think we should just follow the definitions in
include/uapi/asm-generic/errno.h, right?

No.

Try a make for mips, and look at includes you end up with. You will find it goes something like:

# 1 "./arch/mips/include/asm/errno.h" 1
# 11 "./arch/mips/include/asm/errno.h"
# 1 "./arch/mips/include/uapi/asm/errno.h" 1 # 16 "./arch/mips/include/uapi/asm/errno.h"
# 1 "./include/uapi/asm-generic/errno-base.h" 1 # 17 "./arch/mips/include/uapi/asm/errno.h" 2

and this results in

Quoted 8 lines

#define EOPNOTSUPP 122 /* Operation not supported on transport
endpoint */

not what you get from asm-generic/errno.h:

#define EOPNOTSUPP 95 /* Operation not supported on transport endpoint
*/

That shouldn't be an issue in this case.
For instance, if we define the error code as 1 in the return message, the driver will interpret it and just return -EOPNOTSUPP, regardless of the architecture.

Thanks,
Shenwei

Quoted 1 line

Andrew

#17 lore raw

Re: [PATCH v3 3/4] gpio: imx-rpmsg: add imx-rpmsg GPIO driver

Quoted 3 lines

For instance, if we define the error code as 1 in the return message, the driver will interpret it and just return -EOPNOTSUPP, regardless of the architecture.

Yes, that is fine. Document the values the return code can take, and what the mean. What we don't want is the protocol directly returning errno values, because they are architecture specific.

Andrew

#18 lore raw

PATCH v3 4/4 arm64: dts: imx8ulp: Add rpmsg node under imx_rproc

In reply to Shenwei Wang

Add the RPMSG bus node along with its GPIO subnodes to the device tree.

Enable remote device communication and GPIO control via RPMSG on the i.MX platform.

---
 arch/arm64/boot/dts/freescale/imx8ulp.dtsi | 27 ++++++++++++++++++++++
 1 file changed, 27 insertions(+)
arch/arm64/boot/dts/freescale/imx8ulp.dtsi +27 -0
index 13b01f3aa2a4..6ab1c12a3bc1 100644
@@ -191,6 +191,33 @@ scmi_sensor: protocol@15 {
 	cm33: remoteproc-cm33 {
 		compatible = "fsl,imx8ulp-cm33";
 		status = "disabled";
+
+		rpmsg {
+			rpmsg-io-channel {
+				#address-cells = <1>;
+				#size-cells = <0>;
+
+				rpmsg_gpioa: gpio@0 {
+					compatible = "fsl,imx-rpmsg-gpio";
+					reg = <0>;
+					gpio-controller;
+					#gpio-cells = <2>;
+					#interrupt-cells = <2>;
+					interrupt-controller;
+					interrupt-parent = <&rpmsg_gpioa>;
+				};
+
+				rpmsg_gpiob: gpio@1 {
+					compatible = "fsl,imx-rpmsg-gpio";
+					reg = <1>;
+					gpio-controller;
+					#gpio-cells = <2>;
+					#interrupt-cells = <2>;
+					interrupt-controller;
+					interrupt-parent = <&rpmsg_gpiob>;
+				};
+			};
+		};
 	};
 
 	soc: soc@0 {
Signature · 1 line
2.43.0