mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Hans de Goede <hansg@kernel.org>
To: Arnd Bergmann <arnd@arndb.de>,
	Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
	Arnd Bergmann <arnd@kernel.org>
Cc: "Bartosz Golaszewski" <brgl@bgdev.pl>,
	"Linus Walleij" <linus.walleij@linaro.org>,
	"open list:GPIO SUBSYSTEM" <linux-gpio@vger.kernel.org>,
	"Dmitry Torokhov" <dmitry.torokhov@gmail.com>,
	"Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>,
	"Lee Jones" <lee@kernel.org>,
	"Dzmitry Sankouski" <dsankouski@gmail.com>,
	"Heiko Stübner" <heiko@sntech.de>, linux <linux@treblig.org>,
	"Thomas Weißschuh" <linux@weissschuh.net>,
	"Guenter Roeck" <linux@roeck-us.net>,
	linux-input@vger.kernel.org, linux-kernel@vger.kernel.org,
	platform-driver-x86@vger.kernel.org
Subject: Re: [PATCH 05/21] x86/platform: select legacy gpiolib interfaces where used
Date: Sun, 10 Aug 2025 17:12:46 +0200	[thread overview]
Message-ID: <9bc69944-a34e-4a4e-9071-7d2049d12449@kernel.org> (raw)
In-Reply-To: <3190334c-538d-4e2d-80a4-6e24b255e844@app.fastmail.com>

[-- Attachment #1: Type: text/plain, Size: 3900 bytes --]

Hi Arnd, Andy,

On 9-Aug-25 9:44 PM, Arnd Bergmann wrote:
> On Sat, Aug 9, 2025, at 12:00, Andy Shevchenko wrote:
>> On Fri, Aug 08, 2025 at 05:17:49PM +0200, Arnd Bergmann wrote:
>>> From: Arnd Bergmann <arnd@arndb.de>
>>>
>>> A few old machines have not been converted away from the old-style
>>> gpiolib interfaces. Make these select the new CONFIG_GPIOLIB_LEGACY
>>> symbol so the code still works where it is needed but can be left
>>> out otherwise.
>>
>>> --- a/drivers/platform/x86/x86-android-tablets/Kconfig
>>> +++ b/drivers/platform/x86/x86-android-tablets/Kconfig
>>> @@ -8,6 +8,7 @@ config X86_ANDROID_TABLETS
>>>  	depends on I2C && SPI && SERIAL_DEV_BUS
>>>  	depends on GPIOLIB && PMIC_OPREGION
>>>  	depends on ACPI && EFI && PCI
>>> +	select GPIOLIB_LEGACY
>>>  	select NEW_LEDS
>>>  	select LEDS_CLASS
>>>  	select POWER_SUPPLY
>>
>> Hmm... This is a surprising change. But I leave it to Hans.

Yes I was surprised by this myself since I explicitly removed
all legacy GPIO use from the x86-android-tablets code a while
ago (or so I thought).

> I think the only function that still needs it is
> x86_android_tablet_probe() doing
> 
> static struct gpio_keys_button *buttons;
> 
>                 for (i = 0; i < dev_info->gpio_button_count; i++) {
>                         ret = x86_android_tablet_get_gpiod(dev_info->gpio_button[i].chip,
>                                                            dev_info->gpio_button[i].pin,
>                                                            dev_info->gpio_button[i].button.desc,
>                                                            false, GPIOD_IN, &gpiod);
> 
>                         buttons[i] = dev_info->gpio_button[i].button;
>                         buttons[i].gpio = desc_to_gpio(gpiod);
>                         /* Release GPIO descriptor so that gpio-keys can request it */
>                         devm_gpiod_put(&x86_android_tablet_device->dev, gpiod);
>                 }
> 
> So the driver itself uses gpio descriptors, but it passes
> some of them into another driver by number. There is probably
> an easy workaround that I did not see.

Ah I see, so this is basically in the same boat as
drivers/input/misc/soc_button_array.c which also first
gets a gpio_desc and then calls desc_to_gpio() to store
the GPIO number in struct gpio_keys_button which is passed
as platform_data to drivers/input/keyboard/gpio_keys.c

The gpio_keys driver then converts things back
into a gpio_desc in gpio_keys_setup_key()
using devm_gpio_request_one() + gpio_to_desc()

So it looks like we need to add a gpiod member to
struct gpio_keys_button (include/linux/gpio_keys.h)
and modify gpio_keys.c to prefer that over using
button->gpio, something like the attached patch
basically.

I won't have time to work on this until September,
so if someone wants to take the attached patch and run
with it go for it.

Note the x86-android-tablets / soc_button_array code
will become responsible for requesting / releasing
the gpiod when using the new gpio_keys_button.gpiod
member.

For the x86-android-tablets code this is easy, just drop
these 2 lines:

                        /* Release GPIO descriptor so that gpio-keys can request it */
                        devm_gpiod_put(&x86_android_tablet_device->dev, gpiod);

And for soc_button_array.c it is _probably_ just a matter
of switching to devm_gpiod_get_index() and drop the
gpiod_put().

I have hardware to test both the x86-android-tablets
code as well as the soc_button_array code. I might be
able to do a quick test on August 22nd or 29th.

Regards,

Hans


p.s.

It looks like this will also help with:

drivers/platform/x86/meraki-mx100.c
drivers/platform/x86/pcengines-apuv2.c
drivers/platform/x86/barco-p50-gpio.c

I do not have hardware to test these, but if the changes
work for x86-android-tablets + soc_button_array then
hopefully they will be fine here too.

[-- Attachment #2: 0001-Input-gpio-keys-Allow-directly-passing-a-gpio_desc-i.patch --]
[-- Type: text/x-patch, Size: 2112 bytes --]

From 6fe4bd731db59bb01cc0ce3cbd2412434ea053c6 Mon Sep 17 00:00:00 2001
From: Hans de Goede <hansg@kernel.org>
Date: Sun, 10 Aug 2025 16:58:01 +0200
Subject: [PATCH] Input: gpio-keys - Allow directly passing a gpio_desc instead
 of a GPIO number

Using GPIO numbers is deprecated. Allow code passing GPIO-keys info through
platform-data (struct gpio_keys_button) to directly pass a gpio_desc
instead of a GPIO number.

Note requesting / releasing the gpio_desc will be the responsibility
of the code passing in the platform-data.

Signed-off-by: Hans de Goede <hansg@kernel.org>
---
 drivers/input/keyboard/gpio_keys.c | 2 ++
 include/linux/gpio_keys.h          | 5 ++++-
 2 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/drivers/input/keyboard/gpio_keys.c b/drivers/input/keyboard/gpio_keys.c
index f9db86da0818..323247f63a7e 100644
--- a/drivers/input/keyboard/gpio_keys.c
+++ b/drivers/input/keyboard/gpio_keys.c
@@ -528,6 +528,8 @@ static int gpio_keys_setup_key(struct platform_device *pdev,
 			 */
 			bdata->gpiod = NULL;
 		}
+	} else if (button->gpiod) {
+		bdata->gpiod = button->gpiod;
 	} else if (gpio_is_valid(button->gpio)) {
 		/*
 		 * Legacy GPIO number, so request the GPIO here and
diff --git a/include/linux/gpio_keys.h b/include/linux/gpio_keys.h
index 80fa930b04c6..7c32c3a0695f 100644
--- a/include/linux/gpio_keys.h
+++ b/include/linux/gpio_keys.h
@@ -5,11 +5,13 @@
 #include <linux/types.h>
 
 struct device;
+struct gpio_desc;
 
 /**
  * struct gpio_keys_button - configuration parameters
  * @code:		input event code (KEY_*, SW_*)
- * @gpio:		%-1 if this key does not support gpio
+ * @gpio:		%-1 if this key does not support gpio (deprecated use gpiod)
+ * @gpiod:		gpio_desc for the GPIO, NULL if this key does not support gpio
  * @active_low:		%true indicates that button is considered
  *			depressed when gpio is low
  * @desc:		label that will be attached to button's gpio
@@ -26,6 +28,7 @@ struct device;
 struct gpio_keys_button {
 	unsigned int code;
 	int gpio;
+	struct gpio_desc *gpiod;
 	int active_low;
 	const char *desc;
 	unsigned int type;
-- 
2.49.0


  reply	other threads:[~2025-08-10 15:12 UTC|newest]

Thread overview: 67+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-08-08 15:17 [PATCH 00/21] gpiolib: fence off legacy interfaces Arnd Bergmann
2025-08-08 15:17 ` [PATCH 01/21] ARM: select legacy gpiolib interfaces where used Arnd Bergmann
2025-08-11  8:49   ` Krzysztof Kozlowski
2025-08-08 15:17 ` [PATCH 02/21] m68k: coldfire: select legacy gpiolib interface for mcfqspi Arnd Bergmann
2025-08-08 15:17 ` [PATCH 03/21] mips: select legacy gpiolib interfaces where used Arnd Bergmann
2025-08-08 15:17 ` [PATCH 04/21] sh: select legacy gpiolib interface Arnd Bergmann
2025-08-12 18:28   ` Rob Landley
2025-08-12 21:28     ` Arnd Bergmann
2025-08-08 15:17 ` [PATCH 05/21] x86/platform: select legacy gpiolib interfaces where used Arnd Bergmann
2025-08-09 10:00   ` Andy Shevchenko
2025-08-09 19:44     ` Arnd Bergmann
2025-08-10 15:12       ` Hans de Goede [this message]
2025-08-11  2:27         ` Dmitry Torokhov
2025-08-08 15:17 ` [PATCH 06/21] x86/olpc: select GPIOLIB_LEGACY Arnd Bergmann
2025-08-12 17:01   ` Borislav Petkov
2025-08-08 15:17 ` [PATCH 07/21] mfd: wm8994: remove dead legacy-gpio code Arnd Bergmann
2025-08-11 13:14   ` Bartosz Golaszewski
2025-08-08 15:17 ` [PATCH 08/21] ASoC: add GPIOLIB_LEGACY dependency where needed Arnd Bergmann
2025-08-08 15:17 ` [PATCH 09/21] input: gpio-keys: make legacy gpiolib optional Arnd Bergmann
2025-08-11 10:34   ` Matti Vaittinen
2025-08-11 12:52     ` Andy Shevchenko
2025-08-11 19:21       ` Dmitry Torokhov
2025-08-11 20:09         ` Andy Shevchenko
2025-08-12  5:11           ` Matti Vaittinen
2025-08-08 15:17 ` [PATCH 10/21] leds: gpio: make legacy gpiolib interface optional Arnd Bergmann
2025-08-18 15:37   ` Linus Walleij
2025-08-19 12:19   ` Lee Jones
2025-08-19 12:59     ` Arnd Bergmann
2025-08-20  7:16       ` Lee Jones
2025-08-20 12:00         ` Arnd Bergmann
2025-08-20 13:15           ` Andy Shevchenko
2025-08-20 13:15             ` Andy Shevchenko
2025-08-08 15:17 ` [PATCH 11/21] media: em28xx: add special case for legacy gpiolib interface Arnd Bergmann
2025-08-08 15:17 ` [PATCH 12/21] mfd: arizona: make legacy gpiolib interface optional Arnd Bergmann
2025-09-02 12:44   ` Lee Jones
2025-09-02 13:47     ` Arnd Bergmann
2025-09-03  8:05       ` Lee Jones
2025-09-03  9:26         ` Arnd Bergmann
2025-08-08 15:17 ` [PATCH 13/21] mfd: si476x: add GPIOLIB_LEGACY dependency Arnd Bergmann
2025-08-08 15:17 ` [PATCH 14/21] mfd: aat2870: " Arnd Bergmann
2025-08-08 15:17 ` [PATCH 15/21] dsa: b53: hide legacy gpiolib usage on non-mips Arnd Bergmann
2025-08-09 10:01   ` Jonas Gorski
2025-08-09 20:55     ` Arnd Bergmann
2025-08-08 15:18 ` [PATCH 16/21] ath10k: remove gpio number assignment Arnd Bergmann
2025-09-18  5:22   ` Vasanthakumar Thiagarajan
2025-09-18 18:42     ` Jeff Johnson
2025-09-18  6:59   ` Baochen Qiang
2025-09-18 23:47   ` Jeff Johnson
2025-08-08 15:18 ` [PATCH 17/21] nfc: marvell: convert to gpio descriptors Arnd Bergmann
2025-08-09 10:09   ` Andy Shevchenko
2025-08-11 21:43     ` Dmitry Torokhov
2025-08-13 12:35       ` Andy Shevchenko
2025-08-11  7:49   ` Bartosz Golaszewski
2025-08-13  7:48   ` Krzysztof Kozlowski
2025-08-08 15:18 ` [PATCH 18/21] nfc: s3fwrn5: " Arnd Bergmann
2025-08-11 22:08   ` Dmitry Torokhov
2025-08-08 15:18 ` [PATCH 19/21] usb: udc: pxa: remove unused platform_data Arnd Bergmann
2025-08-09 10:15   ` Andy Shevchenko
2025-08-11 22:12   ` Dmitry Torokhov
2025-08-08 15:18 ` [PATCH 20/21] ASoC: pxa: add GPIOLIB_LEGACY dependency Arnd Bergmann
2025-08-08 15:18 ` [PATCH 21/21] gpiolib: turn off legacy interface by default Arnd Bergmann
2025-08-09 10:18   ` Andy Shevchenko
2025-08-09 19:47     ` Arnd Bergmann
2025-08-11 12:49       ` Andy Shevchenko
2025-08-11 13:10 ` [PATCH 00/21] gpiolib: fence off legacy interfaces Bartosz Golaszewski
2025-08-12 16:23 ` (subset) " Mark Brown
2025-09-02 12:56 ` Lee Jones

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=9bc69944-a34e-4a4e-9071-7d2049d12449@kernel.org \
    --to=hansg@kernel.org \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=arnd@arndb.de \
    --cc=arnd@kernel.org \
    --cc=brgl@bgdev.pl \
    --cc=dmitry.torokhov@gmail.com \
    --cc=dsankouski@gmail.com \
    --cc=heiko@sntech.de \
    --cc=ilpo.jarvinen@linux.intel.com \
    --cc=lee@kernel.org \
    --cc=linus.walleij@linaro.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-input@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@roeck-us.net \
    --cc=linux@treblig.org \
    --cc=linux@weissschuh.net \
    --cc=platform-driver-x86@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®