Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a strict_gpiod option #6117

Merged
merged 6 commits into from
Apr 22, 2024
Merged

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 :-)

drivers/pinctrl/pinctrl-rp1.c Outdated Show resolved Hide resolved
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
12 checks passed
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 May 20, 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 20, 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 20, 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 20, 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 28, 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 28, 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 28, 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 28, 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>
@lategoodbye
Copy link
Contributor

The upstream patch has been applied to 6.10-rc1, but there were comments after it has been applied:
https://lore.kernel.org/linux-gpio/Zjk-C0nLmlynqLAE@surfacebook.localdomain/

Does it makes sense to adjust the parameter persist_gpio_outputs via sysfs afterwards or should we make it readonly via sysfs?

I need to know your opinion before i send follow-up patches.

@pelwell
Copy link
Contributor Author

pelwell commented May 28, 2024

I think there are people who will want one value, and people who will want the other value, but likely nobody who wants a changeable global value (aside from the convenience of avoiding a reboot after it is set to the preferred value). Having said that, I have no problem with it being changeable at runtime.

@lategoodbye
Copy link
Contributor

I don't have a strong preference here. But i value the benefits of a readonly sysfs entry:

  • the module parameter would be equivalent to the DT parameter
  • possible applications can rely on the behavior by reading the sysfs entry once
  • comment easier to fix (no need to argue about locking)

So you actually don't have a problem with making this readonly?

@pelwell
Copy link
Contributor Author

pelwell commented May 29, 2024

So you actually don't have a problem with making this readonly?

That's correct. In the past it was never strict in the downstream world, and now users have the option of making it strict - that's enough.

popcornmix pushed a commit that referenced this pull request Jun 3, 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 Jun 3, 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 Jun 3, 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 Jun 3, 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 Jun 3, 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 Jun 10, 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 Jun 12, 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 Jun 12, 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 Jun 17, 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 Jun 17, 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 Jun 17, 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>
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.

None yet

3 participants