[PATCH 05/21] x86/platform: select legacy gpiolib interfaces where used

Arnd Bergmann posted 21 patches 1 month, 3 weeks ago
[PATCH 05/21] x86/platform: select legacy gpiolib interfaces where used
Posted by Arnd Bergmann 1 month, 3 weeks ago
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.

Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
 drivers/input/misc/Kconfig                       | 3 +++
 drivers/platform/x86/Kconfig                     | 3 +++
 drivers/platform/x86/x86-android-tablets/Kconfig | 1 +
 3 files changed, 7 insertions(+)

diff --git a/drivers/input/misc/Kconfig b/drivers/input/misc/Kconfig
index 0fb21c99a5e3..681d4123ef2b 100644
--- a/drivers/input/misc/Kconfig
+++ b/drivers/input/misc/Kconfig
@@ -860,6 +860,9 @@ config INPUT_IDEAPAD_SLIDEBAR
 config INPUT_SOC_BUTTON_ARRAY
 	tristate "Windows-compatible SoC Button Array"
 	depends on KEYBOARD_GPIO && ACPI
+	depends on X86
+	depends on GPIOLIB
+	select GPIOLIB_LEGACY
 	help
 	  Say Y here if you have a SoC-based tablet that originally runs
 	  Windows 8 or a Microsoft Surface Book 2, Pro 5, Laptop 1 or later.
diff --git a/drivers/platform/x86/Kconfig b/drivers/platform/x86/Kconfig
index 6d238e120dce..979a2fce8fc1 100644
--- a/drivers/platform/x86/Kconfig
+++ b/drivers/platform/x86/Kconfig
@@ -309,6 +309,7 @@ config MERAKI_MX100
 	depends on GPIOLIB
 	depends on GPIO_ICH
 	depends on LEDS_CLASS
+	select GPIOLIB_LEGACY
 	select LEDS_GPIO
 	help
 	  This driver provides support for the front button and LEDs on
@@ -564,6 +565,7 @@ config PCENGINES_APU2
 	depends on INPUT && INPUT_KEYBOARD && GPIOLIB
 	depends on LEDS_CLASS
 	select GPIO_AMD_FCH
+	select GPIOLIB_LEGACY
 	select KEYBOARD_GPIO_POLLED
 	select LEDS_GPIO
 	help
@@ -591,6 +593,7 @@ config PORTWELL_EC
 config BARCO_P50_GPIO
 	tristate "Barco P50 GPIO driver for identify LED/button"
 	depends on GPIOLIB
+	select GPIOLIB_LEGACY
 	help
 	  This driver provides access to the GPIOs for the identify button
 	  and led present on Barco P50 board.
diff --git a/drivers/platform/x86/x86-android-tablets/Kconfig b/drivers/platform/x86/x86-android-tablets/Kconfig
index 193da15ee01c..54fa6112c9ea 100644
--- 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
-- 
2.39.5
Re: [PATCH 05/21] x86/platform: select legacy gpiolib interfaces where used
Posted by Andy Shevchenko 1 month, 3 weeks ago
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.

-- 
With Best Regards,
Andy Shevchenko
Re: [PATCH 05/21] x86/platform: select legacy gpiolib interfaces where used
Posted by Arnd Bergmann 1 month, 3 weeks ago
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.

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.

      Arnd
Re: [PATCH 05/21] x86/platform: select legacy gpiolib interfaces where used
Posted by Hans de Goede 1 month, 3 weeks ago
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.
Re: [PATCH 05/21] x86/platform: select legacy gpiolib interfaces where used
Posted by Dmitry Torokhov 1 month, 3 weeks ago
Hi Hans,

On Sun, Aug 10, 2025 at 05:12:46PM +0200, Hans de Goede wrote:
> 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.

I just sent out a v2 of my series from '23 converting
x86-android-tablets to use PROPERTY_ENTRY_GPIO(), including converting
buttons and switches:


https://lore.kernel.org/all/20250810-x86-andoroid-tablet-v2-0-9c7a1b3c32b2@gmail.com/

I do not have hardware so it probably is busted but if you could make it
work that would be great.

Thanks.

-- 
Dmitry