Enable Remote GPIO over RPMSG on i.MX Platform
Subsystems (5)
v9 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 v9:
- Reuse the gpio-virtio design for command and IRQ type definitions.
- Remove msg_id, version, and vendor fields from the generic protocol.
- Add fixed-up handlers to support legacy firmware.
Changes in v8:
- Add "depends on REMOTEPROC" in Kconfig to fix the build error reported by the kernel test robot.
- Move the .rst patch before the .yaml patch.
- Handle the "ngpios" DT property based on Andrew's feedback.
Changes in v7:
- Reworked the driver to use the rpmsg_driver framework instead of platform_driver, based on feedback from Bjorn and Arnaud.
- Updated gpio-rpmsg.yaml and imx_rproc.yaml according to comments from Rob and Arnaud.
- Further refinements to gpio-rpmsg.yaml per Arnaud's feedback.
Changes in v6:
- make the driver more generic with the actions below:
rename the driver file to gpio-rpmsg.c
remove the imx related info in the function and variable names rename the imx_rpmsg.h to rpdev_info.h
create a gpio-rpmsg.yaml and refer it in imx_rproc.yaml
- update the gpio-rpmsg.rst according to the feedback from Andrew and move the source file to driver-api/gpio
- fix the bug reported by Zhongqiu Han
- remove the I2C related info
Changes in v5:
- move the gpio-rpmsg.rst from admin-guide to staging directory after discussion with Randy Dunlap.
- add include files with some code improvements per Bartosz's comments.
Changes in v4:
- add a documentation to describe the transport protocol per Andrew's comments.
- add a new handler to get the gpio direction.
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
Shenwei Wang (5):
docs: driver-api: gpio: rpmsg gpio driver over rpmsg bus
dt-bindings: remoteproc: imx_rproc: Add "rpmsg" subnode support
gpio: rpmsg: add generic rpmsg GPIO driver
gpio: rpmsg: add support for NXP legacy firmware protocol
arm64: dts: imx8ulp: Add rpmsg node under imx_rproc
.../devicetree/bindings/gpio/gpio-rpmsg.yaml | 55 ++ .../bindings/remoteproc/fsl,imx-rproc.yaml | 53 ++ Documentation/driver-api/gpio/gpio-rpmsg.rst | 258 ++++++ Documentation/driver-api/gpio/index.rst | 1 + arch/arm64/boot/dts/freescale/imx8ulp.dtsi | 25 + drivers/gpio/Kconfig | 17 + drivers/gpio/Makefile | 1 + drivers/gpio/gpio-rpmsg.c | 735 ++++++++++++++++++ 8 files changed, 1145 insertions(+) create mode 100644 Documentation/devicetree/bindings/gpio/gpio-rpmsg.yaml create mode 100644 Documentation/driver-api/gpio/gpio-rpmsg.rst create mode 100644 drivers/gpio/gpio-rpmsg.c
--
2.43.0
PATCH v9 1/5 docs: driver-api: gpio: rpmsg gpio driver over rpmsg bus
Describes the gpio rpmsg transport protocol over the rpmsg bus between the remote system and Linux.
--- Documentation/driver-api/gpio/gpio-rpmsg.rst | 258 +++++++++++++++++++ Documentation/driver-api/gpio/index.rst | 1 + 2 files changed, 259 insertions(+) create mode 100644 Documentation/driver-api/gpio/gpio-rpmsg.rst
Documentation/driver-api/gpio/gpio-rpmsg.rst new file +258 -0
@@ -0,0 +1,258 @@ +.. SPDX-License-Identifier: GPL-2.0-or-later + +GPIO RPMSG Protocol +=================== + +The GPIO RPMSG transport protocol is used for communication and interaction +with GPIO controllers located on remote cores on the RPMSG bus. + +Message Format +-------------- + +The RPMSG message consists of a 6-byte packet with the following layout: + +.. code-block:: none + + +-----+-----+-----+-----+-----+----+ + |0x00 |0x01 |0x02 |0x03 |0x04 |0x05| + |type |cmd |port |line | data | + +-----+-----+-----+-----+-----+----+ + +- **Type (Message Type)**: The message type can be one of: + + - 0: GPIO_RPMSG_SEND + - 1: GPIO_RPMSG_REPLY + - 2: GPIO_RPMSG_NOTIFY + +- **Cmd**: Command code, used for GPIO_RPMSG_SEND messages. + +- **line**: The GPIO line(pin) index of the port. + +- **port**: The GPIO port(bank) index. + +- **data**: See details in the command description below. + +- **reply err**: Error code from the remote core. + + - 0: Success + - 1: General error (Early remote software only returns this unclassified error) + - 2: Not supported (A command is not supported by the remote firmware) + - 3: Resource not available (The resource is not allocated to Linux) + - 4: Resource busy (The resource is already in use) + - 5: Parameter error + + +GPIO Commands +------------- + +Commands are specified in the **Cmd** field for **GPIO_RPMSG_SEND** (Type=0) messages. + +The SEND message is always sent from Linux to the remote firmware. Each +SEND corresponds to a single REPLY message. The GPIO driver should +serialize messages and determine whether a REPLY message is required. If a +REPLY message is expected but not received within the specified timeout +period (currently 1 second in the Linux driver), the driver should return +-ETIMEOUT. + +GET_DIRECTION (Cmd=2) +~~~~~~~~~~~~~~~~~~~~~ + +**Request:** + +.. code-block:: none + + +-----+-----+-----+-----+-----+----+ + |0x00 |0x01 |0x02 |0x03 |0x04 |0x05| + | 0 | 2 |port |line | 0 | 0 | + +-----+-----+-----+-----+-----+----+ + +**Reply:** + +.. code-block:: none + +-----+-----+-----+-----+-----+----+ + |0x00 |0x01 |0x02 |0x03 |0x04 |0x05| + | 1 | 2 |port |line | err | dir| + +-----+-----+-----+-----+-----+----+ + +- **err**: See above for definitions. + +- **dir**: Direction. + + - 0: Output + - 1: Input + +SET_DIRECTION (Cmd=3) +~~~~~~~~~~~~~~~~~~~~~ + +**Request:** + +.. code-block:: none + + +-----+-----+-----+-----+-----+----+ + |0x00 |0x01 |0x02 |0x03 |0x04 |0x05| + | 0 | 3 |port |line | dir | 0 | + +-----+-----+-----+-----+-----+----+ + +- **dir**: Direction. + + - 0: None + - 1: Output + - 2: Input + +**Reply:** + +.. code-block:: none + + +-----+-----+-----+-----+-----+----+ + |0x00 |0x01 |0x02 |0x03 |0x04 |0x05| + | 1 | 3 |port |line | err | 0 | + +-----+-----+-----+-----+-----+----+ + +- **err**: See above for definitions. + + +GET_VALUE (Cmd=4) +~~~~~~~~~~~~~~~~ + +**Request:** + +.. code-block:: none + + +-----+-----+-----+-----+-----+----+ + |0x00 |0x01 |0x02 |0x03 |0x04 |0x05| + | 0 | 4 |port |line | 0 | 0 | + +-----+-----+-----+-----+-----+----+ + +**Reply:** + +.. code-block:: none + +-----+-----+-----+-----+-----+----+ + |0x00 |0x01 |0x02 |0x03 |0x04 |0x05| + | 1 | 4 |port |line | err | val| + +-----+-----+-----+-----+-----+----+ + +- **err**: See above for definitions. + +- **val**: Direction. + + - 0: High + - 1: Low + +SET_VALUE (Cmd=5) +~~~~~~~~~~~~~~~~~ + +**Request:** + +.. code-block:: none + + +-----+-----+-----+-----+-----+----+ + |0x00 |0x01 |0x02 |0x03 |0x04 |0x05| + | 0 | 5 |port |line | val | 0 | + +-----+-----+-----+-----+-----+----+ + +- **val**: Output Level. + + - 0: High + - 1: Low + +**Reply:** + +.. code-block:: none + + +-----+-----+-----+-----+-----+----+ + |0x00 |0x01 |0x02 |0x03 |0x04 |0x05| + | 1 | 5 |port |line | err | 0 | + +-----+-----+-----+-----+-----+----+ + +- **err**: See above for definitions. + +SET_IRQ_TYPE (Cmd=6) +~~~~~~~~~~~~~~~~~~~~ + +**Request:** + +.. code-block:: none + + +-----+-----+-----+-----+-----+----+ + |0x00 |0x01 |0x02 |0x03 |0x04 |0x05| + | 0 | 6 |port |line | val | wk | + +-----+-----+-----+-----+-----+----+ + +- **val**: IRQ Types. + + - 0: Interrupt disabled + - 1: Rising edge trigger + - 2: Falling edge trigger + - 3: Both edge trigger + - 4: High level trigger + - 8: Low level trigger + +- **wk**: Wakeup enable. + + The remote system should always aim to stay in a power-efficient state by + shutting down or clock-gating the GPIO blocks that aren't in use. Since + the remoteproc driver is responsible for managing the power states of the + remote firmware, the GPIO driver does not require to know the firmware's + running states. + + When the wakeup bit is set, the remote firmware should configure the line + as a wakeup source. The firmware should send the notification message to + Linux after it is woken from the GPIO line. + + - 0: Disable wakeup from GPIO + - 1: Enable wakeup from GPIO + +**Reply:** + +.. code-block:: none + + +-----+-----+-----+-----+-----+----+ + |0x00 |0x01 |0x02 |0x03 |0x04 |0x05| + | 1 | 6 |port |line | err | 0 | + +-----+-----+-----+-----+-----+----+ + +- **err**: See above for definitions. + +NOTIFY_REPLY (Cmd=10) +~~~~~~~~~~~~~~~~~~~~ +The reply message for the notification is optional. The remote firmware can +implement it to simulate the interrupt acknowledgment behavior. + +**Request:** + +.. code-block:: none + + +-----+-----+-----+-----+-----+----+ + |0x00 |0x01 |0x02 |0x03 |0x04 |0x05| + | 0 | 10 |port |line |level| 0 | + +-----+-----+-----+-----+-----+----+ + +- **line**: The GPIO line(pin) index of the port. +- **port**: The GPIO port(bank) index. +- **level**: GPIO line status. + +Notification Message +-------------------- + +Notifications are sent with **Type=2 (GPIO_RPMSG_NOTIFY)**: + +When a GPIO line asserts an interrupt on the remote processor, the firmware +should immediately mask the corresponding interrupt source and send a +notification message to the Linux. Upon completion of the interrupt +handling on the Linux side, the driver should issue a +command **SET_IRQ_TYPE** to the firmware to unmask the interrupt. + +A Notification message can arrive between a SEND and its REPLY message, +and the driver is expected to handle this scenario. + +.. code-block:: none + + +-----+-----+-----+-----+-----+----+ + |0x00 |0x01 |0x02 |0x03 |0x04 |0x05| + | 2 | 0 |port |line |type | 0 | + +-----+-----+-----+-----+-----+----+ + +- **line**: The GPIO line(pin) index of the port. +- **port**: The GPIO port(bank) index. +- **type**: Optional parameter to indicate the trigger event type. +
Documentation/driver-api/gpio/index.rst +1 -0
@@ -16,6 +16,7 @@ Contents: drivers-on-gpio bt8xxgpio pca953x + gpio-rpmsg Core ====
Signature · 1 line
2.43.0
kernel test robot
build botRe: [PATCH v9 1/5] docs: driver-api: gpio: rpmsg gpio driver over rpmsg bus
kernel test robot noticed the following build warnings:
Hi Shenwei,
kernel test robot noticed the following build warnings:
[auto build test WARNING on brgl/gpio/for-next]
[also build test WARNING on remoteproc/rproc-next robh/for-next next-20260304] [cannot apply to linus/master v6.16-rc1]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Shenwei-Wang/docs-driver-api-gpio-rpmsg-gpio-driver-over-rpmsg-bus/20260305-052440 base: https://git.kernel.org/pub/scm/linux/kernel/git/brgl/linux.git gpio/for-next patch link: https://lore.kernel.org/r/20260304211808.1437846-2-shenwei.wang%40nxp.com patch subject: [PATCH v9 1/5] docs: driver-api: gpio: rpmsg gpio driver over rpmsg bus compiler: clang version 20.1.8 (https://github.com/llvm/llvm-project 87f0227cb60147a26a1eeb4fb06e3b505e9c7261) docutils: docutils (Docutils 0.21.2, Python 3.13.5, on linux) reproduce: (https://download.01.org/0day-ci/archive/20260305/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All warnings (new ones prefixed by >>):
.. code-block:: none
+-----+-----+-----+-----+-----+----+ |0x00 |0x01 |0x02 |0x03 |0x04 |0x05| | 1 | 2 |port |line | err | dir| +-----+-----+-----+-----+-----+----+ [docutils] >> Documentation/driver-api/gpio/gpio-rpmsg.rst:115: WARNING: Title underline too short.
vim +115 Documentation/driver-api/gpio/gpio-rpmsg.rst
112
113
114 GET_VALUE (Cmd=4)
> 115 ~~~~~~~~~~~~~~~~
116
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
Re: [PATCH v9 1/5] docs: driver-api: gpio: rpmsg gpio driver over rpmsg bus
In reply to Shenwei WangOn 3/4/26 23:18, Shenwei Wang wrote:
[...]
Quoted 13 lines
Documentation/driver-api/gpio/gpio-rpmsg.rst new file +13
-0+GPIO RPMSG Protocol +=================== + +The GPIO RPMSG transport protocol is used for communication and interaction +with GPIO controllers located on remote cores on the RPMSG bus. + +Message Format +-------------- + +The RPMSG message consists of a 6-byte packet with the following layout: + +.. code-block:: none +
Documentation/driver-api/gpio/gpio-rpmsg.rst line 25
Quoted 10 lines
Documentation/driver-api/gpio/gpio-rpmsg.rst new file +10
-0+ +-----+-----+-----+-----+-----+----+ + |0x00 |0x01 |0x02 |0x03 |0x04 |0x05| + |type |cmd |port |line | data | + +-----+-----+-----+-----+-----+----+ + +- **Type (Message Type)**: The message type can be one of: + + - 0: GPIO_RPMSG_SEND + - 1: GPIO_RPMSG_REPLY + - 2: GPIO_RPMSG_NOTIFY
I think would make sense to display the type in hexa. e.g : 0x00, 0x01, etc.
Also, would it make sense to display the byte index as follows outside of the boxes?
Quoted 2 lines
+
+- **Cmd**: Command code, used forGPIO_RPMSG_SENDmessages.
Are there any specific commands? Also please either use upper-case first
letter (e.g Type, Cmd) or lower-case letter (port, line) but do not mix them.
Quoted 2 lines
+
+- **line**: The GPIO line(pin) index of the port.
In message format line comes after port so switch the order here.
Documentation/driver-api/gpio/gpio-rpmsg.rst line 42
Quoted 13 lines
Documentation/driver-api/gpio/gpio-rpmsg.rst new file +13
-0+ +- **port**: The GPIO port(bank) index. + +- **data**: See details in the command description below. + +- **reply err**: Error code from the remote core. + + - 0: Success + - 1: General error (Early remote software only returns this unclassified error) + - 2: Not supported (A command is not supported by the remote firmware) + - 3: Resource not available (The resource is not allocated to Linux) + - 4: Resource busy (The resource is already in use) + - 5: Parameter error
Is this part of the 6-byte packet? Are these standard errors or you defined them as is?
Documentation/driver-api/gpio/gpio-rpmsg.rst line 51
Quoted 9 lines
Documentation/driver-api/gpio/gpio-rpmsg.rst new file +9
-0+ + +GPIO Commands +------------- + +Commands are specified in the **Cmd** field for **GPIO_RPMSG_SEND** (Type=0) messages. + +The SEND message is always sent from Linux to the remote firmware. Each +SEND corresponds to a single REPLY message. The GPIO driver should
Wouldn't be the other way around? Each REPLY corresponds to a single SEND msg?
Quoted 75 lines
Documentation/driver-api/gpio/gpio-rpmsg.rst new file +75
-0+serialize messages and determine whether a REPLY message is required. If a +REPLY message is expected but not received within the specified timeout +period (currently 1 second in the Linux driver), the driver should return +-ETIMEOUT. + +GET_DIRECTION (Cmd=2) +~~~~~~~~~~~~~~~~~~~~~ + +**Request:** + +.. code-block:: none + + +-----+-----+-----+-----+-----+----+ + |0x00 |0x01 |0x02 |0x03 |0x04 |0x05| + | 0 | 2 |port |line | 0 | 0 | + +-----+-----+-----+-----+-----+----+ + +**Reply:** + +.. code-block:: none + +-----+-----+-----+-----+-----+----+ + |0x00 |0x01 |0x02 |0x03 |0x04 |0x05| + | 1 | 2 |port |line | err | dir| + +-----+-----+-----+-----+-----+----+ + +- **err**: See above for definitions. + +- **dir**: Direction. + + - 0: Output + - 1: Input + +SET_DIRECTION (Cmd=3) +~~~~~~~~~~~~~~~~~~~~~ + +**Request:** + +.. code-block:: none + + +-----+-----+-----+-----+-----+----+ + |0x00 |0x01 |0x02 |0x03 |0x04 |0x05| + | 0 | 3 |port |line | dir | 0 | + +-----+-----+-----+-----+-----+----+ + +- **dir**: Direction. + + - 0: None + - 1: Output + - 2: Input + +**Reply:** + +.. code-block:: none + + +-----+-----+-----+-----+-----+----+ + |0x00 |0x01 |0x02 |0x03 |0x04 |0x05| + | 1 | 3 |port |line | err | 0 | + +-----+-----+-----+-----+-----+----+ + +- **err**: See above for definitions. + + +GET_VALUE (Cmd=4) +~~~~~~~~~~~~~~~~ + +**Request:** + +.. code-block:: none + + +-----+-----+-----+-----+-----+----+ + |0x00 |0x01 |0x02 |0x03 |0x04 |0x05| + | 0 | 4 |port |line | 0 | 0 | + +-----+-----+-----+-----+-----+----+ + +**Reply:**
Documentation/driver-api/gpio/gpio-rpmsg.rst line 136
Quoted 10 lines
Documentation/driver-api/gpio/gpio-rpmsg.rst new file +10
-0+ +.. code-block:: none + +-----+-----+-----+-----+-----+----+ + |0x00 |0x01 |0x02 |0x03 |0x04 |0x05| + | 1 | 4 |port |line | err | val| + +-----+-----+-----+-----+-----+----+ + +- **err**: See above for definitions. + +- **val**: Direction.
Why is direction High or Low? Or I'm missing something.
Quoted 5 lines
Documentation/driver-api/gpio/gpio-rpmsg.rst new file +5
-0+ + - 0: High + - 1: Low + +SET_VALUE (Cmd=5)
Documentation/driver-api/gpio/gpio-rpmsg.rst line 151
Quoted 10 lines
Documentation/driver-api/gpio/gpio-rpmsg.rst new file +10
-0+~~~~~~~~~~~~~~~~~ + +**Request:** + +.. code-block:: none + + +-----+-----+-----+-----+-----+----+ + |0x00 |0x01 |0x02 |0x03 |0x04 |0x05| + | 0 | 5 |port |line | val | 0 | + +-----+-----+-----+-----+-----+----+
So when getting replies val is at index 5, but when sending requests val is at index 4. Wonder
if we make this consistent? Or at least explain why did you choose this layout.
Quoted 8 lines
Documentation/driver-api/gpio/gpio-rpmsg.rst new file +8
-0+ +- **val**: Output Level. + + - 0: High + - 1: Low + +**Reply:** +
Documentation/driver-api/gpio/gpio-rpmsg.rst line 169
Quoted 10 lines
Documentation/driver-api/gpio/gpio-rpmsg.rst new file +10
-0+.. code-block:: none + + +-----+-----+-----+-----+-----+----+ + |0x00 |0x01 |0x02 |0x03 |0x04 |0x05| + | 1 | 5 |port |line | err | 0 | + +-----+-----+-----+-----+-----+----+ + +- **err**: See above for definitions. + +SET_IRQ_TYPE (Cmd=6)
Is there a cmd for gpio polarity?
[...]
Quoted 13 lines
Documentation/driver-api/gpio/gpio-rpmsg.rst new file +13
-0+ +NOTIFY_REPLY (Cmd=10) +~~~~~~~~~~~~~~~~~~~~ +The reply message for the notification is optional. The remote firmware can +implement it to simulate the interrupt acknowledgment behavior. + +**Request:** + +.. code-block:: none + + +-----+-----+-----+-----+-----+----+ + |0x00 |0x01 |0x02 |0x03 |0x04 |0x05| + | 0 | 10 |port |line |level| 0 |
Documentation/driver-api/gpio/gpio-rpmsg.rst line 237
Quoted 10 lines
Documentation/driver-api/gpio/gpio-rpmsg.rst new file +10
-0+ +-----+-----+-----+-----+-----+----+ + +- **line**: The GPIO line(pin) index of the port. +- **port**: The GPIO port(bank) index. +- **level**: GPIO line status. + +Notification Message +-------------------- + +Notifications are sent with **Type=2 (GPIO_RPMSG_NOTIFY)**:
Here you should clarify who sends the notification messages.
... Notifications are messages sent by the remote core and they have Type=0x02...
[..]
PATCH v9 2/5 dt-bindings: remoteproc: imx_rproc: Add "rpmsg" subnode support
In reply to Shenwei WangRemote processors may announce multiple GPIO controllers over an RPMSG channel. These GPIO controllers 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.
--- .../devicetree/bindings/gpio/gpio-rpmsg.yaml | 55 +++++++++++++++++++ .../bindings/remoteproc/fsl,imx-rproc.yaml | 53 ++++++++++++++++++ 2 files changed, 108 insertions(+) create mode 100644 Documentation/devicetree/bindings/gpio/gpio-rpmsg.yaml
Documentation/devicetree/bindings/gpio/gpio-rpmsg.yaml new file +55 -0
@@ -0,0 +1,55 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/gpio/gpio-rpmsg.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Generic RPMSG GPIO Controller + +maintainers: + - Shenwei Wang <[email protected]> + +description: + On an AMP platform, some GPIO controllers are exposed by the remote processor + through the RPMSG bus. The RPMSG GPIO transport protocol defines the packet + structure and communication flow between Linux and the remote firmware. Those + controllers are managed via this transport protocol. For more details of the + protocol, check the document below. + Documentation/driver-api/gpio/gpio-rpmsg.rst + +properties: + compatible: + oneOf: + - items: + - enum: + - fsl,rpmsg-gpio + - const: rpmsg-gpio + - const: rpmsg-gpio + + reg: + description: + The reg property represents the index of the GPIO controllers. Since + the driver manages controllers on a remote system, this index tells + the remote system which controller to operate. + 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# + +unevaluatedProperties: false
Documentation/devicetree/bindings/remoteproc/fsl,imx-rproc.yaml +53 -0
64 lines not on this page · raw message
Signature · 1 line
2.43.0
PATCH v9 3/5 gpio: rpmsg: add generic rpmsg GPIO driver
In reply to Shenwei WangOn an AMP platform, 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-rpmsg.c | 592 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 610 insertions(+) create mode 100644 drivers/gpio/gpio-rpmsg.c
drivers/gpio/Kconfig +17 -0
@@ -1892,6 +1892,23 @@ config GPIO_SODAVILLE endmenu +menu "RPMSG GPIO drivers" + depends on RPMSG + +config GPIO_RPMSG + tristate "Generic RPMSG GPIO support" + depends on OF && REMOTEPROC + select GPIOLIB_IRQCHIP + default REMOTEPROC + help + Say yes here to support the generic GPIO functions over the RPMSG + bus. 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
@@ -158,6 +158,7 @@ obj-$(CONFIG_GPIO_RDC321X) += gpio-rdc321x.o obj-$(CONFIG_GPIO_REALTEK_OTTO) += gpio-realtek-otto.o obj-$(CONFIG_GPIO_REG) += gpio-reg.o obj-$(CONFIG_GPIO_ROCKCHIP) += gpio-rockchip.o +obj-$(CONFIG_GPIO_RPMSG) += gpio-rpmsg.o obj-$(CONFIG_GPIO_RTD) += gpio-rtd.o obj-$(CONFIG_ARCH_SA1100) += gpio-sa1100.o obj-$(CONFIG_GPIO_SAMA5D2_PIOBU) += gpio-sama5d2-piobu.o
drivers/gpio/gpio-rpmsg.c new file +592 -0
592 lines not on this page · raw message
Signature · 1 line
2.43.0
PATCH v9 4/5 gpio: rpmsg: add support for NXP legacy firmware protocol
In reply to Shenwei WangImplement fixed-up message handlers to maintain compatibility with existing i.MX devices that rely on the NXP legacy RPMSG firmware and its transport protocol. This ensures backward compatibility and preserves functionality for deployed NXP systems.
--- drivers/gpio/gpio-rpmsg.c | 143 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 143 insertions(+)
drivers/gpio/gpio-rpmsg.c +143 -0
@@ -84,6 +84,145 @@ struct rpdev_drvdata {void *channel_devices[MAX_PORT_PER_CHANNEL ]; }; +/* NXP I.MX Legacy GPIO RPMSG protocol */ +#define IMX_RPMSG_CONFIG_INPUT 0 +#define IMX_RPMSG_CONFIG_OUTPUT 1 +#define IMX_RPMSG_GET_LEVEL 2 +#define IMX_RPMSG_GET_DIRECTION 3 +#define IMX_RPMSG_CMD_UNKNOWN 0x7F + +#define IMX_RPMSG_TRI_LOW_LEVEL 4 +#define IMX_RPMSG_TRI_HIGH_LEVEL 5 + +#define IMX_RPMSG_ID 5 +#define IMX_RPMSG_VENDOR 1 +#define IMX_RPMSG_VERSION 0 + +struct rpmsg_gpio_nxp_packet { +u8 id;/* Message ID Code */ +u8 vendor;/* Vendor ID number */ +u8 version;/* Protocol version number */ +u8 type;/* Message type */ +u8 cmd;/* Command code */ +u8 reserved[5 ]; +u8 line; +u8 port_idx; +u8 val1; +u8 val2; +}; + +static struct rpmsg_gpio_packet * +rpmsg_gpio_imx_recv_fixed_up (struct rpmsg_device *rpdev,void *data) +{ +struct rpmsg_gpio_nxp_packet *imx_msg = data; +struct rpmsg_gpio_packet *msg; +struct rpdev_drvdata *drvdata; + +if (!imx_msg) +return NULL ; + + drvdata =dev_get_drvdata (&rpdev->dev); +if (!drvdata->recv_pkt) + drvdata->recv_pkt =devm_kzalloc (&rpdev->dev,sizeof (*msg),GFP_KERNEL ); + +if (!drvdata->recv_pkt) +return NULL ; + + msg = drvdata->recv_pkt; + + msg->type = imx_msg->type; + msg->cmd = imx_msg->cmd; + msg->port_idx = imx_msg->port_idx; + msg->line = imx_msg->line; + msg->val1 = imx_msg->val1; + msg->val2 = imx_msg->val2; + +switch (imx_msg->cmd) { +case IMX_RPMSG_GET_LEVEL : + msg->cmd =VIRTIO_GPIO_MSG_GET_VALUE ; +break ; + +case IMX_RPMSG_GET_DIRECTION : + msg->cmd =VIRTIO_GPIO_MSG_GET_DIRECTION ; +break ; + +case IMX_RPMSG_CONFIG_OUTPUT : + msg->cmd =VIRTIO_GPIO_MSG_SET_DIRECTION ; + msg->val2 =VIRTIO_GPIO_DIRECTION_OUT ; +break ; + +case IMX_RPMSG_CONFIG_INPUT : + msg->cmd =VIRTIO_GPIO_MSG_SET_DIRECTION ; + msg->val2 =VIRTIO_GPIO_DIRECTION_IN ; +break ; + +default : +break ; + } + +return msg; +} + +static int imx_std_cmd_map[] = { +IMX_RPMSG_CMD_UNKNOWN , +IMX_RPMSG_CMD_UNKNOWN ,/* VIRTIO_GPIO_MSG_GET_NAMES */ +IMX_RPMSG_GET_DIRECTION ,/* VIRTIO_GPIO_MSG_GET_DIRECTION */ +IMX_RPMSG_CONFIG_INPUT ,/* VIRTIO_GPIO_MSG_SET_DIRECTION */ +IMX_RPMSG_GET_LEVEL ,/* VIRTIO_GPIO_MSG_GET_VALUE */ +IMX_RPMSG_CONFIG_OUTPUT ,/* VIRTIO_GPIO_MSG_SET_VALUE */ +IMX_RPMSG_CONFIG_INPUT /* VIRTIO_GPIO_MSG_IRQ_TYPE */ +}; + +static int rpmsg_gpio_imx_send_fixed_up (struct rpmsg_gpio_info *info, +struct rpmsg_gpio_packet *msg) +{ +struct rpmsg_gpio_nxp_packet imx_msg; + +if (msg->cmd >=sizeof (imx_std_cmd_map)) +return -EINVAL ; + + imx_msg.id =IMX_RPMSG_ID ; + imx_msg.vendor =IMX_RPMSG_VENDOR ; + imx_msg.version =IMX_RPMSG_VERSION ; + imx_msg.type = msg->type; + imx_msg.cmd = imx_std_cmd_map[msg->cmd]; + imx_msg.port_idx = msg->port_idx; + imx_msg.line = msg->line; + imx_msg.val1 = msg->val1; + imx_msg.val2 = msg->val2; + +switch (msg->cmd) { +case VIRTIO_GPIO_MSG_IRQ_TYPE : +switch (msg->val1) { +case VIRTIO_GPIO_IRQ_TYPE_LEVEL_HIGH : + imx_msg.val1 =IMX_RPMSG_TRI_HIGH_LEVEL ; +break ; +case VIRTIO_GPIO_IRQ_TYPE_LEVEL_LOW : + imx_msg.val1 =IMX_RPMSG_TRI_LOW_LEVEL ; +break ; +default : +break ; + } +break ; + +case VIRTIO_GPIO_MSG_SET_DIRECTION : + imx_msg.val1 =0 ; +if (msg->val1 ==VIRTIO_GPIO_DIRECTION_OUT ) + imx_msg.cmd =IMX_RPMSG_CONFIG_OUTPUT ; +break ; + +default : +break ; + } + +return rpmsg_send (info->rpdev->ept, &imx_msg,sizeof (imx_msg)); +} + +static struct rpmsg_gpio_fixed_up imx_fixed_up_data = { + .recv_fixed_up = rpmsg_gpio_imx_recv_fixed_up, + .send_fixed_up = rpmsg_gpio_imx_send_fixed_up, +}; +static int rpmsg_gpio_send_message (struct rpmsg_gpio_port *port,struct rpmsg_gpio_packet *msg,bool sync)
@@ -572,6 +711,10 @@ static const struct of_device_id rpmsg_gpio_dt_ids[] = {static struct rpmsg_device_id rpmsg_gpio_channel_id_table[] = { { .name ="rpmsg-io" }, + { + .name ="rpmsg-io-channel" , + .driver_data = (kernel_ulong_t)(uintptr_t)&imx_fixed_up_data + }, { }, };MODULE_DEVICE_TABLE (rpmsg, rpmsg_gpio_channel_id_table);
Signature · 1 line
2.43.0
Frank Li
maintainerRe: [PATCH v9 4/5] gpio: rpmsg: add support for NXP legacy firmware protocol
From: Frank Li (AI-BOT) <[email protected]>
Quoted 1 line
+static int imx_std_cmd_map[] = {
AI: Should be 'static const int' since this is a read-only lookup table.
drivers/gpio/gpio-rpmsg.c struct rpdev_drvdata { · line 181
Quoted 1 line
drivers/gpio/gpio-rpmsg.c +1
-0+if (msg->cmd >=sizeof (imx_std_cmd_map))
AI: Use ARRAY_SIZE(imx_std_cmd_map) instead of sizeof() for clarity.
because imx_std_cmd_map is array, AI most likely is correct.
Frank
Dan Carpenter
build botRe: [PATCH v9 4/5] gpio: rpmsg: add support for NXP legacy firmware protocol
In reply to Shenwei WangBCC: [email protected] CC: [email protected] In-Reply-To: <[email protected]> References: <[email protected]> TO: Shenwei Wang…
BCC: [email protected]
CC: [email protected]
In-Reply-To: <[email protected]>
References: <[email protected]>
TO: Shenwei Wang <[email protected]>
TO: Linus Walleij <[email protected]>
TO: Bartosz Golaszewski <[email protected]>
TO: Jonathan Corbet <[email protected]>
TO: Rob Herring <[email protected]>
TO: Krzysztof Kozlowski <[email protected]>
TO: Conor Dooley <[email protected]>
TO: Bjorn Andersson <[email protected]>
TO: Mathieu Poirier <[email protected]>
TO: Frank Li <[email protected]>
TO: Sascha Hauer <[email protected]>
TO: [email protected]
CC: Shuah Khan <[email protected]>
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: Pengutronix Kernel Team <[email protected]>
CC: Fabio Estevam <[email protected]>
CC: Shenwei Wang <[email protected]>
CC: Peng Fan <[email protected]>
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]
Hi Shenwei,
kernel test robot noticed the following build warnings:
[auto build test WARNING on brgl/gpio/for-next]
[also build test WARNING on remoteproc/rproc-next robh/for-next linus/master v7.0-rc2 next-20260305] [If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Shenwei-Wang/docs-driver-api-gpio-rpmsg-gpio-driver-over-rpmsg-bus/20260305-052440 base: https://git.kernel.org/pub/scm/linux/kernel/git/brgl/linux.git gpio/for-next patch link: https://lore.kernel.org/r/20260304211808.1437846-5-shenwei.wang%40nxp.com patch subject: [PATCH v9 4/5] gpio: rpmsg: add support for NXP legacy firmware protocol
:::::: branch date: 29 hours ago
:::::: commit date: 29 hours ago
config: x86_64-randconfig-161-20260306 (https://download.01.org/0day-ci/archive/20260306/[email protected]/config)
compiler: clang version 20.1.8 (https://github.com/llvm/llvm-project 87f0227cb60147a26a1eeb4fb06e3b505e9c7261)
smatch: v0.5.0-9004-gb810ac53
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]> | Reported-by: Dan Carpenter <[email protected]> | Closes: https://lore.kernel.org/r/[email protected]/
smatch warnings:drivers/gpio/gpio-rpmsg.c:188 rpmsg_gpio_imx_send_fixed_up() error: buffer overflow 'imx_std_cmd_map' 7 <= 27
vim +/imx_std_cmd_map +188 drivers/gpio/gpio-rpmsg.c
49a0cb20cd49a59 Shenwei Wang 2026-03-04 175
49a0cb20cd49a59 Shenwei Wang 2026-03-04 176 static int rpmsg_gpio_imx_send_fixed_up(struct rpmsg_gpio_info *info,
49a0cb20cd49a59 Shenwei Wang 2026-03-04 177 struct rpmsg_gpio_packet *msg)
49a0cb20cd49a59 Shenwei Wang 2026-03-04 178 {
49a0cb20cd49a59 Shenwei Wang 2026-03-04 179 struct rpmsg_gpio_nxp_packet imx_msg;
49a0cb20cd49a59 Shenwei Wang 2026-03-04 180
49a0cb20cd49a59 Shenwei Wang 2026-03-04 181 if (msg->cmd >= sizeof(imx_std_cmd_map))
49a0cb20cd49a59 Shenwei Wang 2026-03-04 182 return -EINVAL;
49a0cb20cd49a59 Shenwei Wang 2026-03-04 183
49a0cb20cd49a59 Shenwei Wang 2026-03-04 184 imx_msg.id = IMX_RPMSG_ID;
49a0cb20cd49a59 Shenwei Wang 2026-03-04 185 imx_msg.vendor = IMX_RPMSG_VENDOR;
49a0cb20cd49a59 Shenwei Wang 2026-03-04 186 imx_msg.version = IMX_RPMSG_VERSION;
49a0cb20cd49a59 Shenwei Wang 2026-03-04 187 imx_msg.type = msg->type;
49a0cb20cd49a59 Shenwei Wang 2026-03-04 @188 imx_msg.cmd = imx_std_cmd_map[msg->cmd];
49a0cb20cd49a59 Shenwei Wang 2026-03-04 189 imx_msg.port_idx = msg->port_idx;
49a0cb20cd49a59 Shenwei Wang 2026-03-04 190 imx_msg.line = msg->line;
49a0cb20cd49a59 Shenwei Wang 2026-03-04 191 imx_msg.val1 = msg->val1;
49a0cb20cd49a59 Shenwei Wang 2026-03-04 192 imx_msg.val2 = msg->val2;
49a0cb20cd49a59 Shenwei Wang 2026-03-04 193
49a0cb20cd49a59 Shenwei Wang 2026-03-04 194 switch (msg->cmd) {
49a0cb20cd49a59 Shenwei Wang 2026-03-04 195 case VIRTIO_GPIO_MSG_IRQ_TYPE:
49a0cb20cd49a59 Shenwei Wang 2026-03-04 196 switch (msg->val1) {
49a0cb20cd49a59 Shenwei Wang 2026-03-04 197 case VIRTIO_GPIO_IRQ_TYPE_LEVEL_HIGH:
49a0cb20cd49a59 Shenwei Wang 2026-03-04 198 imx_msg.val1 = IMX_RPMSG_TRI_HIGH_LEVEL;
49a0cb20cd49a59 Shenwei Wang 2026-03-04 199 break;
49a0cb20cd49a59 Shenwei Wang 2026-03-04 200 case VIRTIO_GPIO_IRQ_TYPE_LEVEL_LOW:
49a0cb20cd49a59 Shenwei Wang 2026-03-04 201 imx_msg.val1 = IMX_RPMSG_TRI_LOW_LEVEL;
49a0cb20cd49a59 Shenwei Wang 2026-03-04 202 break;
49a0cb20cd49a59 Shenwei Wang 2026-03-04 203 default:
49a0cb20cd49a59 Shenwei Wang 2026-03-04 204 break;
49a0cb20cd49a59 Shenwei Wang 2026-03-04 205 }
49a0cb20cd49a59 Shenwei Wang 2026-03-04 206 break;
49a0cb20cd49a59 Shenwei Wang 2026-03-04 207
49a0cb20cd49a59 Shenwei Wang 2026-03-04 208 case VIRTIO_GPIO_MSG_SET_DIRECTION:
49a0cb20cd49a59 Shenwei Wang 2026-03-04 209 imx_msg.val1 = 0;
49a0cb20cd49a59 Shenwei Wang 2026-03-04 210 if (msg->val1 == VIRTIO_GPIO_DIRECTION_OUT)
49a0cb20cd49a59 Shenwei Wang 2026-03-04 211 imx_msg.cmd = IMX_RPMSG_CONFIG_OUTPUT;
49a0cb20cd49a59 Shenwei Wang 2026-03-04 212 break;
49a0cb20cd49a59 Shenwei Wang 2026-03-04 213
49a0cb20cd49a59 Shenwei Wang 2026-03-04 214 default:
49a0cb20cd49a59 Shenwei Wang 2026-03-04 215 break;
49a0cb20cd49a59 Shenwei Wang 2026-03-04 216 }
49a0cb20cd49a59 Shenwei Wang 2026-03-04 217
49a0cb20cd49a59 Shenwei Wang 2026-03-04 218 return rpmsg_send(info->rpdev->ept, &imx_msg, sizeof(imx_msg));
49a0cb20cd49a59 Shenwei Wang 2026-03-04 219 }
49a0cb20cd49a59 Shenwei Wang 2026-03-04 220 Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
Re: [PATCH v9 4/5] gpio: rpmsg: add support for NXP legacy firmware protocol
In reply to Shenwei WangQuoted 9 lines
drivers/gpio/gpio-rpmsg.c +5
-0+static struct rpmsg_gpio_fixed_up imx_fixed_up_data = { + .recv_fixed_up = rpmsg_gpio_imx_recv_fixed_up, + .send_fixed_up = rpmsg_gpio_imx_send_fixed_up, +}; +static int rpmsg_gpio_send_message (struct rpmsg_gpio_port *port,struct rpmsg_gpio_packet *msg,bool sync)
drivers/gpio/gpio-rpmsg.c static const struct of_device_id rpmsg_gpio_dt_ids[] = { · line 717
Quoted 7 lines
drivers/gpio/gpio-rpmsg.c +4
-0@@ -572,6 +711,10 @@ static const struct of_device_id rpmsg_gpio_dt_ids[] = {static struct rpmsg_device_id rpmsg_gpio_channel_id_table[] = { { .name ="rpmsg-io" }, + { + .name ="rpmsg-io-channel" , + .driver_data = (kernel_ulong_t)(uintptr_t)&imx_fixed_up_data + },
Its not clear to me how this gets applied. Don't you need a different compatible? fsl,rpmsg-gpio-legacy or something?
I would also put it behind a CONFIG_ option, and in a different module. Nobody needs this code other than your legacy products. You don't need the bloat for your new devices and other vendors don't need it.
Andrew
Re: [PATCH v9 4/5] gpio: rpmsg: add support for NXP legacy firmware protocol
Quoted 29 lines
-----Original Message-----
From: Andrew Lunn <[email protected]>
Sent: Friday, March 6, 2026 8:24 AM
To: Shenwei Wang <[email protected]>
Cc: Linus Walleij <[email protected]>; Bartosz Golaszewski <[email protected]>; Jonathan Corbet <[email protected]>; Rob Herring <[email protected]>; Krzysztof Kozlowski <[email protected]>; Conor Dooley <[email protected]>; Bjorn Andersson <[email protected]>; Mathieu Poirier <[email protected]>; Frank Li <[email protected]>; Sascha Hauer <[email protected]>; [email protected]; Shuah Khan <[email protected]>; [email protected]; linux- [email protected]; [email protected]; Pengutronix Kernel Team <[email protected]>; Fabio Estevam <[email protected]>; Peng Fan <[email protected]>; [email protected]; linux- [email protected]; [email protected]; linux-arm- [email protected]; dl-linux-imx <[email protected]>
Subject: [EXT] Re: [PATCH v9 4/5] gpio: rpmsg: add support for NXP legacy firmware protocolQuoted 9 lines
drivers/gpio/gpio-rpmsg.c +4
-0+static struct rpmsg_gpio_fixed_up imx_fixed_up_data = { + .recv_fixed_up = rpmsg_gpio_imx_recv_fixed_up, + .send_fixed_up = rpmsg_gpio_imx_send_fixed_up, }; +static int rpmsg_gpio_send_message (struct rpmsg_gpio_port *port,struct rpmsg_gpio_packet *msg, bool sync) @@ -572,6 +711,10 @@static const struct
of_device_idrpmsg_gpio_dt_ids[] = {
Quoted 10 lines
drivers/gpio/gpio-rpmsg.c static const struct of_device_id rpmsg_gpio_dt_ids[] = { · line 717
Quoted 6 lines
static struct rpmsg_device_id rpmsg_gpio_channel_id_table[] = { { .name = "rpmsg-io" },drivers/gpio/gpio-rpmsg.c +4
-0+ { + .name = "rpmsg-io-channel", + .driver_data = (kernel_ulong_t)(uintptr_t)&imx_fixed_up_data + },Its not clear to me how this gets applied. Don't you need a different compatible? fsl,rpmsg-gpio-legacy or something?
This is not a compatible. It is the RPMSG channel name advertised by the remote processor. The generic implementation uses "rpmsg-io" as the channel name, and "rpmsg-io-channel" is used by NXP's existing firmware.
Quoted 4 lines
I would also put it behind a
CONFIG_option, and in a different module. Nobody needs this code other than your legacy products. You don't need the bloat for your new devices and other vendors don't need it.
Other vendors may add fixed up handlers in the same way to support their existing products.
Thanks,
Shenwei
Quoted 1 line
Andrew
Re: [PATCH v9 4/5] gpio: rpmsg: add support for NXP legacy firmware protocol
Quoted 2 lines
Other vendors may add fixed up handlers in the same way to support their existing products.
But that is exactly what we don't want. Why bother adding a generic protocol, if vendors then hack it around to make it compatible with whatever their legacy systems have? We want to discourage such bad behaviour.
How do we discourage this? We add the label 'legacy' everywhere we can, so it looks bad. We put the legacy code into a module, behind a symbol with LEGACY in its name, which is disabled by default.
The messaging i've seen from ST is that they will use the generic protocol. We reward them for doing this by not bloating the code they need with legacy support for other vendors...
Andrew
PATCH v9 5/5 arm64: dts: imx8ulp: Add rpmsg node under imx_rproc
In reply to Shenwei WangAdd 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 | 25 ++++++++++++++++++++++ 1 file changed, 25 insertions(+)
arch/arm64/boot/dts/freescale/imx8ulp.dtsi +25 -0
@@ -191,6 +191,31 @@ 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 = "rpmsg-gpio"; + reg = <0>; + gpio-controller; + #gpio-cells = <2>; + #interrupt-cells = <2>; + interrupt-controller; + }; + + rpmsg_gpiob: gpio@1 { + compatible = "rpmsg-gpio"; + reg = <1>; + gpio-controller; + #gpio-cells = <2>; + #interrupt-cells = <2>; + interrupt-controller; + }; + }; + }; }; soc: soc@0 {
Signature · 1 line
2.43.0