[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <CAKR-sGcgx4p_+k5tC0Z-5y+AQOp6GTQn7pq-WC3xirNiuA0f9g@mail.gmail.com>
Date: Sun, 5 Jan 2025 10:31:42 +0100
From: Álvaro Fernández Rojas <noltari@...il.com>
To: Jonas Gorski <jonas.gorski@...il.com>
Cc: Kyle Hendry <kylehendrydev@...il.com>, linus.walleij@...aro.org,
linux-gpio@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH v2] pinctrl: bcm63268: add gpio function
El sáb, 4 ene 2025 a las 20:32, Jonas Gorski
(<jonas.gorski@...il.com>) escribió:
>
> On Sat, Jan 4, 2025 at 6:02 PM Álvaro Fernández Rojas <noltari@...il.com> wrote:
> >
> > El sáb, 4 ene 2025 a las 16:44, Álvaro Fernández Rojas
> > (<noltari@...il.com>) escribió:
> > >
> > > El vie, 3 ene 2025 a las 4:04, Kyle Hendry (<kylehendrydev@...il.com>) escribió:
> > > >
> > > > On 2024-12-30 08:42, Jonas Gorski wrote:
> > > > > Hi,
> > > > >
> > > > > On Tue, Dec 24, 2024 at 11:41 AM Álvaro Fernández Rojas
> > > > > <noltari@...il.com> wrote:
> > > > >> From: Kyle Hendry <kylehendrydev@...il.com>
> > > > >>
> > > > >> There is no guarantee that the bootloader will leave the pin configuration
> > > > >> in a known default state, so pinctrl needs to be explicitly set in some
> > > > >> cases. This patch adds a gpio function for drivers that need it, i.e.
> > > > >> gpio-leds.
> > > > >>
> > > > >> Signed-off-by: Kyle Hendry <kylehendrydev@...il.com>
> > > > >> Signed-off-by: Álvaro Fernández Rojas <noltari@...il.com>
> > > > >
> > > > > bcm63268-pinctrl implements pinmux_ops::gpio_request_enable(), which
> > > > > should automatically set any requested GPIO pin to the GPIO function,
> > > > > so explicitly requesting the gpio function for a pin should not be
> > > > > needed. Is this not enough?
> > > > >
> > > > > Best Regards,
> > > > > Jonas
> > > > >
> > > > >
> > > > I assumed that as well, but nothing I tried worked with gpio-leds.
> > > > gpiochip_generic_request() does call gpio_request_enable(), but gpio-leds
> > > > uses devm_fwnode_gpiod_get() which looks like a different code path. The
> > > > only place it seems to be configuring the gpio is in create_gpio_led()
> > > > where it needs a pinctl node in the device tree. That's just my reading
> > > > of the code, though. I haven't set up a ftrace to verify it.
> > > >
> > > > Best Regards,
> > > > Kyle
> > >
> > > As Kyle pointed out it's not enough and gpio_request_enable() doesn't
> > > get called from gpio-leds.
> > > I will try to investigate this and report back.
> > >
> > > Best regards,
> > > Álvaro.
> >
> > I've performed some tests and so far I haven't been able to get
> > bcm63268_gpio_request_enable() called.
> >
> > Even exporting a gpio from userspace doesn't trigger that function,
> > which seems strange because in that case we won't have a "gpio"
> > function on the pinctrl for that gpio, even with this patch...
>
> On a first glance it looks like that regmap-gpio does not populate
> gpio_chip::request and gpio_chip:free, so the gpio subsystem is not
> aware that it needs to request anything. Not sure if just using
> gpiolib_generic_request() / gpiolib_generic_free() is fine. Currently
> on vacation, so no hardware to test anything at hand ;-)
>
> Best Regards,
> Jonas
You're totally right, after adding request() and free() functions to
gpio-regmap it's now working without this patch because
bcm63268_gpio_request_enable() is now properly called:
1. gpio-keys-polled
[ 4.052132] gpio_button_hotplug: loading out-of-tree module taints kernel.
[ 4.060657] bcm63268-pinctrl 100000d0.pinctrl: request pin 34
(gpio34) for 100000d0.pinctrl:546
[ 4.069704] bcm63268_gpio_request_enable: range=99a2e0ae offset=34
[ 4.076158] bcm63268-pinctrl 100000d0.pinctrl: request pin 35
(gpio35) for 100000d0.pinctrl:547
[ 4.085135] bcm63268_gpio_request_enable: range=99a2e0ae offset=35
2. gpio-leds
[ 4.480190] bcm63268-pinctrl 100000d0.pinctrl: request pin 0
(gpio0) for 100000d0.pinctrl:512
[ 4.489078] bcm63268_gpio_request_enable: range=99a2e0ae offset=0
[ 4.495747] bcm63268-pinctrl 100000d0.pinctrl: request pin 1
(gpio1) for 100000d0.pinctrl:513
[ 4.504600] bcm63268_gpio_request_enable: range=99a2e0ae offset=1
3. userspace gpio export
root@...nWrt:~# cat /sys/kernel/debug/gpio
gpiochip0: GPIOs 512-563, parent: platform/100000d0.pinctrl, 100000d0.pinctrl:
gpio-512 ( |red:mobile ) out lo
gpio-513 ( |green:mobile ) out lo
gpio-546 ( |wps ) in hi ACTIVE LOW
gpio-547 ( |reset ) in hi ACTIVE LOW
root@...nWrt:~# echo 545 > /sys/class/gpio/export
[ 33.437477] bcm63268-pinctrl 100000d0.pinctrl: request pin 33
(gpio33) for 100000d0.pinctrl:545
[ 33.446503] bcm63268_gpio_request_enable: range=99a2e0ae offset=33
root@...nWrt:~# cat /sys/kernel/debug/gpio
gpiochip0: GPIOs 512-563, parent: platform/100000d0.pinctrl, 100000d0.pinctrl:
gpio-512 ( |red:mobile ) out lo
gpio-513 ( |green:mobile ) out lo
gpio-545 ( |sysfs ) in hi
gpio-546 ( |wps ) in hi ACTIVE LOW
gpio-547 ( |reset ) in hi ACTIVE LOW
OpenWrt test source code:
https://github.com/Noltari/openwrt/commits/bmips-gpio-tests
https://github.com/Noltari/openwrt/commit/d3bc7610c8fe8f713a3e47ed8368b6aa220ae763
Linux test source code:
https://github.com/Noltari/linux/commits/gpio-regmap-pinctrl-request-free
https://github.com/Noltari/linux/commit/2d0ebb8cad8084e932f40f3f69d4e931b2316aa4
@Linus I assume that adding those functions may cause issues to other
drivers and maybe we need to add some logic to add them dynamically
based on a new gpio_regmap_config parameter?
Best regards,
Álvaro.
Powered by blists - more mailing lists