Skip to content

Conversation

@pelwell
Copy link
Contributor

@pelwell pelwell commented Apr 19, 2024

This patch set addresses some of the comments on 022689f. The concern is that GPIOs should always be returned to being inputs when they are released so that, for example, a heater is switched off or a motor stops when the controlling application crashes. That is how the upstream pinctrl drivers work, but in the downstream RPi kernels this behaviour has been modified so that GPIO outputs remain as outputs with whatever drive they had, in order that changes from gpioset will persist without the need to keep gpioset as a background process.

Two of the patches add support for the strict_gpiod module parameter to the two pinctrl drivers. Another patch adds dtparams so that the change can be made in config.txt instead, and will apply to all models of Pi. The final patch adds a gpio-ranges property to Pi 5 - without it, the notification of a pin being released never reaches the pinctrl driver.

pelwell referenced this pull request Apr 19, 2024
Allowing GPIO state to persist allows the use of gpioset to control
GPIO levels without having to use the --mode=wait feature.

Signed-off-by: Phil Elwell <phil@raspberrypi.com>
Copy link
Contributor

@6by9 6by9 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm glad it's not just me that gets caught by the dtoverlaycheck failure :-)

pelwell added 6 commits April 19, 2024 16:43
gpio-ranges declares a relationship between pinctrl and GPIO
controllers. It is required for "strict" mode to work.

Signed-off-by: Phil Elwell <phil@raspberrypi.com>
Setting strict_gpiod to Y makes libgpiod and the gpiod utilities behave
as documented, i.e. pins are returned to being GPIO inputs when they are
released.
drivers/pinctrl/bcm/pinctrl-bcm2835.c
Signed-off-by: Phil Elwell <phil@raspberrypi.com>
Setting strict_gpiod to Y makes libgpiod and the gpiod utilities behave
as documented, i.e. pins are returned to being GPIO inputs when they are
released.

Signed-off-by: Phil Elwell <phil@raspberrypi.com>
Setting strict_gpiod disables the GPIO output persistence, such that
pins are returned to being inputs when they are released. Note that
this applies to the GPIO/pinctrl driver for the user-facing GPIOs,
not the SoC GPIOs on Pi 5.

Signed-off-by: Phil Elwell <phil@raspberrypi.com>
There are enough dtparams now that not having them in alphabetical
order makes them hard to find.

Signed-off-by: Phil Elwell <phil@raspberrypi.com>
Describe the function of the strict_gpiod dtparam.

Signed-off-by: Phil Elwell <phil@raspberrypi.com>
@lategoodbye
Copy link
Contributor

@pelwell pelwell merged commit 9577122 into raspberrypi:rpi-6.6.y Apr 22, 2024
popcornmix added a commit to raspberrypi/firmware that referenced this pull request Apr 26, 2024
See: raspberrypi/linux#6113

kernel: DRM: rp1: rp1-dsi: Fix escape clock divider and timeouts
See: raspberrypi/linux#6120

kernel: vc4/hdmi: Ignore hotplug interrupt with force_hotplug
See: raspberrypi/linux#6123

kernel: drivers: media: cfe: Add remap entries for mono formats
See: raspberrypi/linux#6122

kernel: dw-axi-dmac-platform: Avoid trampling with zero length buffer
See: raspberrypi/linux#6118

kernel: Add a strict_gpiod option
See: raspberrypi/linux#6117

kernel: Unicam FS/FE timing GPIO
See: raspberrypi/linux#6088
popcornmix added a commit to raspberrypi/rpi-firmware that referenced this pull request Apr 26, 2024
See: raspberrypi/linux#6113

kernel: DRM: rp1: rp1-dsi: Fix escape clock divider and timeouts
See: raspberrypi/linux#6120

kernel: vc4/hdmi: Ignore hotplug interrupt with force_hotplug
See: raspberrypi/linux#6123

kernel: drivers: media: cfe: Add remap entries for mono formats
See: raspberrypi/linux#6122

kernel: dw-axi-dmac-platform: Avoid trampling with zero length buffer
See: raspberrypi/linux#6118

kernel: Add a strict_gpiod option
See: raspberrypi/linux#6117

kernel: Unicam FS/FE timing GPIO
See: raspberrypi/linux#6088
intel-lab-lkp pushed a commit to intel-lab-lkp/linux that referenced this pull request May 3, 2024
Until now after a bcm2835 pin was freed its pinmux was set to GPIO_IN.
So in case it was configured as GPIO_OUT before the configured output
level also get lost. As long as GPIO sysfs was used this wasn't
actually a problem because the pins and their possible output level
were kept by sysfs.

Since more and more Raspberry Pi users start using libgpiod they are
confused about this behavior. So make the pin freeing behavior of
GPIO_OUT configurable via module parameter. In case
pinctrl-bcm2835.persist_gpio_outputs is set to 1, the output level is
kept.

This patch based on the downstream work of Phil Elwell.

Link: raspberrypi/linux#6117
Signed-off-by: Stefan Wahren <wahrenst@gmx.net>
@lategoodbye
Copy link
Contributor

The second version with parameter name persist_gpio_outputs has been accepted mainline. Since i like to align the behavior between rpi and mainline, the question is how we should proceed here.
https://lore.kernel.org/linux-gpio/CACRpkdY5pbtCU=hFaQ0MmYqMy5xWCxV6HPcEoRMMNEDL657crQ@mail.gmail.com/T/#t

Can we adapt to the mainline parameter name or is it too late and we need to handle both parameter names?

srcres258 pushed a commit to srcres258/linux-doc that referenced this pull request May 7, 2024
Until now after a bcm2835 pin was freed its pinmux was set to GPIO_IN.
So in case it was configured as GPIO_OUT before the configured output
level also get lost. As long as GPIO sysfs was used this wasn't
actually a problem because the pins and their possible output level
were kept by sysfs.

Since more and more Raspberry Pi users start using libgpiod they are
confused about this behavior. So make the pin freeing behavior of
GPIO_OUT configurable via module parameter. In case
pinctrl-bcm2835.persist_gpio_outputs is set to 1, the output level is
kept.

This patch based on the downstream work of Phil Elwell.

Link: raspberrypi/linux#6117
Signed-off-by: Stefan Wahren <wahrenst@gmx.net>
Message-ID: <20240503062745.11298-1-wahrenst@gmx.net>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
@pelwell
Copy link
Contributor Author

pelwell commented May 7, 2024

The name change is easy enough - the abstraction through a dtparam helps. It's the inversion of the sense combined with the use of module parameters that is awkward/ugly, given that kernel updates are independent of changes to /etc/modprobe.d, etc.

pelwell pushed a commit to pelwell/linux that referenced this pull request May 7, 2024
commit 8ff0598 upstream.

Until now after a bcm2835 pin was freed its pinmux was set to GPIO_IN.
So in case it was configured as GPIO_OUT before the configured output
level also get lost. As long as GPIO sysfs was used this wasn't
actually a problem because the pins and their possible output level
were kept by sysfs.

Since more and more Raspberry Pi users start using libgpiod they are
confused about this behavior. So make the pin freeing behavior of
GPIO_OUT configurable via module parameter. In case
pinctrl-bcm2835.persist_gpio_outputs is set to 1, the output level is
kept.

This patch based on the downstream work of Phil Elwell.

Link: raspberrypi#6117
Signed-off-by: Stefan Wahren <wahrenst@gmx.net>
Message-ID: <20240503062745.11298-1-wahrenst@gmx.net>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
pelwell added a commit to pelwell/linux that referenced this pull request May 7, 2024
Having accepted the upstream change to add the persist_gpio_outputs
parameter, make it true by default.

See: raspberrypi#6117

Signed-off-by: Phil Elwell <phil@raspberrypi.com>
@pelwell
Copy link
Contributor Author

pelwell commented May 7, 2024

Corresponding downstream changes can be found here: #6150

pelwell pushed a commit that referenced this pull request May 7, 2024
commit 8ff0598 upstream.

Until now after a bcm2835 pin was freed its pinmux was set to GPIO_IN.
So in case it was configured as GPIO_OUT before the configured output
level also get lost. As long as GPIO sysfs was used this wasn't
actually a problem because the pins and their possible output level
were kept by sysfs.

Since more and more Raspberry Pi users start using libgpiod they are
confused about this behavior. So make the pin freeing behavior of
GPIO_OUT configurable via module parameter. In case
pinctrl-bcm2835.persist_gpio_outputs is set to 1, the output level is
kept.

This patch based on the downstream work of Phil Elwell.

Link: #6117
Signed-off-by: Stefan Wahren <wahrenst@gmx.net>
Message-ID: <20240503062745.11298-1-wahrenst@gmx.net>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
pelwell added a commit that referenced this pull request May 7, 2024
Having accepted the upstream change to add the persist_gpio_outputs
parameter, make it true by default.

See: #6117

Signed-off-by: Phil Elwell <phil@raspberrypi.com>
pelwell pushed a commit that referenced this pull request May 7, 2024
commit 8ff0598 upstream.

Until now after a bcm2835 pin was freed its pinmux was set to GPIO_IN.
So in case it was configured as GPIO_OUT before the configured output
level also get lost. As long as GPIO sysfs was used this wasn't
actually a problem because the pins and their possible output level
were kept by sysfs.

Since more and more Raspberry Pi users start using libgpiod they are
confused about this behavior. So make the pin freeing behavior of
GPIO_OUT configurable via module parameter. In case
pinctrl-bcm2835.persist_gpio_outputs is set to 1, the output level is
kept.

This patch based on the downstream work of Phil Elwell.

Link: #6117
Signed-off-by: Stefan Wahren <wahrenst@gmx.net>
Message-ID: <20240503062745.11298-1-wahrenst@gmx.net>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
pelwell added a commit that referenced this pull request May 7, 2024
Having accepted the upstream change to add the persist_gpio_outputs
parameter, make it true by default.

See: #6117

Signed-off-by: Phil Elwell <phil@raspberrypi.com>
pelwell pushed a commit that referenced this pull request May 7, 2024
commit 8ff0598 upstream.

Until now after a bcm2835 pin was freed its pinmux was set to GPIO_IN.
So in case it was configured as GPIO_OUT before the configured output
level also get lost. As long as GPIO sysfs was used this wasn't
actually a problem because the pins and their possible output level
were kept by sysfs.

Since more and more Raspberry Pi users start using libgpiod they are
confused about this behavior. So make the pin freeing behavior of
GPIO_OUT configurable via module parameter. In case
pinctrl-bcm2835.persist_gpio_outputs is set to 1, the output level is
kept.

This patch based on the downstream work of Phil Elwell.

Link: #6117
Signed-off-by: Stefan Wahren <wahrenst@gmx.net>
Message-ID: <20240503062745.11298-1-wahrenst@gmx.net>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
pelwell added a commit that referenced this pull request May 7, 2024
Having accepted the upstream change to add the persist_gpio_outputs
parameter, make it true by default.

See: #6117

Signed-off-by: Phil Elwell <phil@raspberrypi.com>
popcornmix pushed a commit that referenced this pull request May 13, 2024
commit 8ff0598 upstream.

Until now after a bcm2835 pin was freed its pinmux was set to GPIO_IN.
So in case it was configured as GPIO_OUT before the configured output
level also get lost. As long as GPIO sysfs was used this wasn't
actually a problem because the pins and their possible output level
were kept by sysfs.

Since more and more Raspberry Pi users start using libgpiod they are
confused about this behavior. So make the pin freeing behavior of
GPIO_OUT configurable via module parameter. In case
pinctrl-bcm2835.persist_gpio_outputs is set to 1, the output level is
kept.

This patch based on the downstream work of Phil Elwell.

Link: #6117
Signed-off-by: Stefan Wahren <wahrenst@gmx.net>
Message-ID: <20240503062745.11298-1-wahrenst@gmx.net>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
popcornmix pushed a commit that referenced this pull request May 13, 2024
Having accepted the upstream change to add the persist_gpio_outputs
parameter, make it true by default.

See: #6117

Signed-off-by: Phil Elwell <phil@raspberrypi.com>
popcornmix pushed a commit that referenced this pull request Aug 1, 2025
Having accepted the upstream change to add the persist_gpio_outputs
parameter, make it true by default.

See: #6117

Signed-off-by: Phil Elwell <phil@raspberrypi.com>
popcornmix pushed a commit that referenced this pull request Aug 19, 2025
Having accepted the upstream change to add the persist_gpio_outputs
parameter, make it true by default.

See: #6117

Signed-off-by: Phil Elwell <phil@raspberrypi.com>
popcornmix pushed a commit that referenced this pull request Aug 19, 2025
Having accepted the upstream change to add the persist_gpio_outputs
parameter, make it true by default.

See: #6117

Signed-off-by: Phil Elwell <phil@raspberrypi.com>
popcornmix pushed a commit that referenced this pull request Aug 19, 2025
Having accepted the upstream change to add the persist_gpio_outputs
parameter, make it true by default.

See: #6117

Signed-off-by: Phil Elwell <phil@raspberrypi.com>
popcornmix pushed a commit that referenced this pull request Aug 22, 2025
Having accepted the upstream change to add the persist_gpio_outputs
parameter, make it true by default.

See: #6117

Signed-off-by: Phil Elwell <phil@raspberrypi.com>
popcornmix pushed a commit that referenced this pull request Aug 25, 2025
Having accepted the upstream change to add the persist_gpio_outputs
parameter, make it true by default.

See: #6117

Signed-off-by: Phil Elwell <phil@raspberrypi.com>
popcornmix pushed a commit that referenced this pull request Aug 26, 2025
Having accepted the upstream change to add the persist_gpio_outputs
parameter, make it true by default.

See: #6117

Signed-off-by: Phil Elwell <phil@raspberrypi.com>
popcornmix pushed a commit that referenced this pull request Aug 26, 2025
Having accepted the upstream change to add the persist_gpio_outputs
parameter, make it true by default.

See: #6117

Signed-off-by: Phil Elwell <phil@raspberrypi.com>
popcornmix pushed a commit that referenced this pull request Aug 29, 2025
Having accepted the upstream change to add the persist_gpio_outputs
parameter, make it true by default.

See: #6117

Signed-off-by: Phil Elwell <phil@raspberrypi.com>
popcornmix pushed a commit that referenced this pull request Sep 3, 2025
Having accepted the upstream change to add the persist_gpio_outputs
parameter, make it true by default.

See: #6117

Signed-off-by: Phil Elwell <phil@raspberrypi.com>
popcornmix pushed a commit that referenced this pull request Sep 5, 2025
Having accepted the upstream change to add the persist_gpio_outputs
parameter, make it true by default.

See: #6117

Signed-off-by: Phil Elwell <phil@raspberrypi.com>
popcornmix pushed a commit that referenced this pull request Sep 15, 2025
Having accepted the upstream change to add the persist_gpio_outputs
parameter, make it true by default.

See: #6117

Signed-off-by: Phil Elwell <phil@raspberrypi.com>
popcornmix pushed a commit that referenced this pull request Sep 15, 2025
Having accepted the upstream change to add the persist_gpio_outputs
parameter, make it true by default.

See: #6117

Signed-off-by: Phil Elwell <phil@raspberrypi.com>
popcornmix pushed a commit that referenced this pull request Sep 22, 2025
Having accepted the upstream change to add the persist_gpio_outputs
parameter, make it true by default.

See: #6117

Signed-off-by: Phil Elwell <phil@raspberrypi.com>
popcornmix pushed a commit that referenced this pull request Sep 22, 2025
Having accepted the upstream change to add the persist_gpio_outputs
parameter, make it true by default.

See: #6117

Signed-off-by: Phil Elwell <phil@raspberrypi.com>
popcornmix pushed a commit that referenced this pull request Sep 25, 2025
Having accepted the upstream change to add the persist_gpio_outputs
parameter, make it true by default.

See: #6117

Signed-off-by: Phil Elwell <phil@raspberrypi.com>
popcornmix pushed a commit that referenced this pull request Sep 29, 2025
Having accepted the upstream change to add the persist_gpio_outputs
parameter, make it true by default.

See: #6117

Signed-off-by: Phil Elwell <phil@raspberrypi.com>
popcornmix pushed a commit that referenced this pull request Oct 3, 2025
Having accepted the upstream change to add the persist_gpio_outputs
parameter, make it true by default.

See: #6117

Signed-off-by: Phil Elwell <phil@raspberrypi.com>
popcornmix pushed a commit that referenced this pull request Oct 6, 2025
Having accepted the upstream change to add the persist_gpio_outputs
parameter, make it true by default.

See: #6117

Signed-off-by: Phil Elwell <phil@raspberrypi.com>
popcornmix pushed a commit that referenced this pull request Oct 6, 2025
Having accepted the upstream change to add the persist_gpio_outputs
parameter, make it true by default.

See: #6117

Signed-off-by: Phil Elwell <phil@raspberrypi.com>
popcornmix pushed a commit that referenced this pull request Oct 14, 2025
Having accepted the upstream change to add the persist_gpio_outputs
parameter, make it true by default.

See: #6117

Signed-off-by: Phil Elwell <phil@raspberrypi.com>
popcornmix pushed a commit that referenced this pull request Oct 14, 2025
Having accepted the upstream change to add the persist_gpio_outputs
parameter, make it true by default.

See: #6117

Signed-off-by: Phil Elwell <phil@raspberrypi.com>
popcornmix pushed a commit that referenced this pull request Oct 15, 2025
Having accepted the upstream change to add the persist_gpio_outputs
parameter, make it true by default.

See: #6117

Signed-off-by: Phil Elwell <phil@raspberrypi.com>
popcornmix pushed a commit that referenced this pull request Oct 20, 2025
Having accepted the upstream change to add the persist_gpio_outputs
parameter, make it true by default.

See: #6117

Signed-off-by: Phil Elwell <phil@raspberrypi.com>
popcornmix pushed a commit that referenced this pull request Oct 20, 2025
Having accepted the upstream change to add the persist_gpio_outputs
parameter, make it true by default.

See: #6117

Signed-off-by: Phil Elwell <phil@raspberrypi.com>
popcornmix pushed a commit that referenced this pull request Oct 20, 2025
Having accepted the upstream change to add the persist_gpio_outputs
parameter, make it true by default.

See: #6117

Signed-off-by: Phil Elwell <phil@raspberrypi.com>
popcornmix pushed a commit that referenced this pull request Oct 24, 2025
Having accepted the upstream change to add the persist_gpio_outputs
parameter, make it true by default.

See: #6117

Signed-off-by: Phil Elwell <phil@raspberrypi.com>
popcornmix pushed a commit that referenced this pull request Oct 27, 2025
Having accepted the upstream change to add the persist_gpio_outputs
parameter, make it true by default.

See: #6117

Signed-off-by: Phil Elwell <phil@raspberrypi.com>
popcornmix pushed a commit that referenced this pull request Oct 27, 2025
Having accepted the upstream change to add the persist_gpio_outputs
parameter, make it true by default.

See: #6117

Signed-off-by: Phil Elwell <phil@raspberrypi.com>
popcornmix pushed a commit that referenced this pull request Oct 30, 2025
Having accepted the upstream change to add the persist_gpio_outputs
parameter, make it true by default.

See: #6117

Signed-off-by: Phil Elwell <phil@raspberrypi.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants