Re: [PATCH v4 00/10] gpio: improve support for shared GPIOs

Linus Walleij
2025-11-19T14:29:57Z

On Wed, Nov 19, 2025 at 9:38 AM Geert Uytterhoeven <geert@linux-m68k.org> wrote:

> > For the input usecase the status of the LED is a byproduct and
> > should not reflect in software I think. It surely should not be
> > controllable and possible to set into output mode because
> > that sounds like a recipe for HW damage if you drive it
> > actively high and press the key at the same time.
>
> Suitable resistors are present to prevent hardware damage.

Aha, clever.

> > gpio_keys {
> > compatible = "gpio-keys";
> >
> > button-ok {
> > gpios = <&gpio 0 GPIO_OPEN_DRAIN | GPIO_PULL_UP>;
> > };
> > };
>
> But only one of the gpio-keys and gpio-leds drivers can bind to the
> GPIO, or am I missing something?
> So I do think I need a new combined key-and-led driver, like Bartosz
> suggested:
> - When the user turns the LED on, the GPIO is switched to input mode,
> and the switch works,
> - When the user turns the LED off, the GPIO is switched to output
> and driven low, and the switch does not work.

You will also have the byproduct that the LED being "on" in software
does not necessarily reflect the actual LED status, someone
may be pressing the key and then the LED is off even though
in sysfs it is clearly "on".

So the status in the LED classdevice also has to be forced to "off"
(brightness 0) anytime the input subsystem detects that the switch
is pressed.

It's going to be a lot of work I think, but I guess it can be done,
with a lot of special-casing and custom APIs.

Yours,
Linus Walleij