Message ID | 20200625002736.GA24954@x1 (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | gpio-omap: handle bias flag for gpio line | expand |
On Thu, Jun 25, 2020 at 2:27 AM Drew Fustini <drew@beagleboard.org> wrote: > Tony and Linus - > > I'm hoping you could give me some feedback on this approach. My goal is > to allow a userspace library (like libgpiod) to be able to set pull-up > and pull-downs on the AM3358. I'm lost on any pinctrl-single specifics, sorry... Generic questions about pinctrl I can maybe answer. Yours, Linus Walleij
On Tue, Jul 07, 2020 at 02:38:36PM +0200, Linus Walleij wrote: > On Thu, Jun 25, 2020 at 2:27 AM Drew Fustini <drew@beagleboard.org> wrote: > > > Tony and Linus - > > > > I'm hoping you could give me some feedback on this approach. My goal is > > to allow a userspace library (like libgpiod) to be able to set pull-up > > and pull-downs on the AM3358. > > I'm lost on any pinctrl-single specifics, sorry... Generic questions about > pinctrl I can maybe answer. > > Yours, > Linus Walleij I now have a way to set bias with libgpiod on the AM3358 (BeagleBone and PocketBeagle) with these two patches: [PATCH] gpio: omap: handle pin config bias flags [0] ------------------------------------------------ Modify omap_gpio_set_config() to handle pin config bias flags by calling gpiochip_generic_config(). The pin group for the gpio line must have the corresponding pinconf properties: PIN_CONFIG_BIAS_PULL_UP requires "pinctrl-single,bias-pullup" PIN_CONFIG_BIAS_PULL_DOWN requires "pinctrl-single,bias-pulldown This means the ability to set bias from userspace is controlled from device tree. If there is concern about potiental damage caused by userspace setting bias to an unsafe value then those pins should not have the bias property in the dts. [PATCH] ARM: dts: am335x-pocketbeagle: set default mux for gpio pins [1] -------------------------------------------------------------------- These pins on the PocketBeagle P1 and P2 headers are connected to AM3358 balls with gpio lines, and these pins are not used for any other peripherals by default. This patch adds "pinctrl-single,bias-pullup" and "pinctrl-single,bias-pulldown" pinconf properties for each pin per the ball reset state in the datasheet. Here is an example for P2.03 header pin on the PocketBeagle: /* P2_03 (ZCZ ball T10) gpio0_23 0x824 PIN 9 */ P2_03_gpio: pinmux_P2_03_gpio { pinctrl-single,pins = < AM33XX_PADCONF(AM335X_PIN_GPMC_AD9, PIN_INPUT_PULLUP, MUX_MODE7) >; pinctrl-single,bias-pullup = < 0x10 0x10 0x00 0x18>; pinctrl-single,bias-pulldown = < 0x10 0x00 0x10 0x18>; }; P2.03 header pin on PocketBeagle maps to gpiochip 0 line 23. It is PIN9 which value on boot: 0x37 (input [0x20] pull-up [0x10] gpio mode [0x7]) $ cat /sys/kernel/debug/pinctrl/44e10800.pinmux-pinctrl-single/pins |grep ^'pin 9' |head -1 pin 9 (PIN9) 44e10824 00000037 pinctrl-single $ gpiomon -B pull-down 0 23 ^C Value 0x27 means it switched to pull-down [0x0] but still input [0x20] and gpio mode [0x7]: $ cat /sys/kernel/debug/pinctrl/44e10800.pinmux-pinctrl-single/pins |grep ^'pin 9' |head -1 pin 9 (PIN9) 44e10824 00000027 pinctrl-single Now switch it back to pull-up: $ gpiomon -B pull-up 0 23 ^C Value 0x37 means it switched to pull-up [0x10] and is still input [0x20] and gpio mode [0x7]: $ cat /sys/kernel/debug/pinctrl/44e10800.pinmux-pinctrl-single/pins |grep ^'pin 9' |head -1 pin 9 (PIN9) 44e10824 00000037 pinctrl-single Question: does this seem like a reasonable solution? Thanks, Drew [0] https://lore.kernel.org/linux-omap/20200712103717.1219765-1-drew@beagleboard.org/ [1] https://lore.kernel.org/linux-omap/20200709223401.780051-1-drew@beagleboard.org/
Hi, * Drew Fustini <drew@beagleboard.org> [200712 21:56]: > P2.03 header pin on PocketBeagle maps to gpiochip 0 line 23. It is PIN9 > which value on boot: 0x37 (input [0x20] pull-up [0x10] gpio mode [0x7]) > > $ cat /sys/kernel/debug/pinctrl/44e10800.pinmux-pinctrl-single/pins |grep ^'pin 9' |head -1 > pin 9 (PIN9) 44e10824 00000037 pinctrl-single > > $ gpiomon -B pull-down 0 23 Nice it's getting quite close to a user usable feature :) I think we really should have an easy way to use the dts configured GPIO line names here though. Can we make the dts configured GPIO line name show up in the pinctrl output directly? This would allow grepping for the device specific GPIO line name directly in from the debugfs "pins" output. But Ideally this should be done with the gpio sysfs interface though somehow rather than rely on pinctrl debugfs. The debugfs interface should be optional, and can change. Regards, Tony
On Mon, Jul 13, 2020 at 08:02:20AM -0700, Tony Lindgren wrote: > Hi, > > * Drew Fustini <drew@beagleboard.org> [200712 21:56]: > > P2.03 header pin on PocketBeagle maps to gpiochip 0 line 23. It is PIN9 > > which value on boot: 0x37 (input [0x20] pull-up [0x10] gpio mode [0x7]) > > > > $ cat /sys/kernel/debug/pinctrl/44e10800.pinmux-pinctrl-single/pins |grep ^'pin 9' |head -1 > > pin 9 (PIN9) 44e10824 00000037 pinctrl-single > > > > $ gpiomon -B pull-down 0 23 > > Nice it's getting quite close to a user usable feature :) > > I think we really should have an easy way to use the dts configured > GPIO line names here though. Can we make the dts configured GPIO > line name show up in the pinctrl output directly? > > This would allow grepping for the device specific GPIO line name > directly in from the debugfs "pins" output. > > But Ideally this should be done with the gpio sysfs interface though > somehow rather than rely on pinctrl debugfs. The debugfs interface > should be optional, and can change. > > Regards, > > Tony There is gpio-ranges for pinctrl-single in debugfs: debian@beaglebone:~$ sudo more /sys/kernel/debug/pinctrl/44e10800.pinmux-pinctrl-single/gpio-ranges GPIO ranges handled: 0: gpio-0-31 GPIOS [0 - 7] PINS [82 - 89] 8: gpio-0-31 GPIOS [8 - 11] PINS [52 - 55] 12: gpio-0-31 GPIOS [12 - 15] PINS [94 - 97] 16: gpio-0-31 GPIOS [16 - 17] PINS [71 - 72] 18: gpio-0-31 GPIOS [18 - 18] PINS [135 - 135] 19: gpio-0-31 GPIOS [19 - 20] PINS [108 - 109] 21: gpio-0-31 GPIOS [21 - 21] PINS [73 - 73] 22: gpio-0-31 GPIOS [22 - 23] PINS [8 - 9] 26: gpio-0-31 GPIOS [26 - 27] PINS [10 - 11] 28: gpio-0-31 GPIOS [28 - 28] PINS [74 - 74] 29: gpio-0-31 GPIOS [29 - 29] PINS [81 - 81] 30: gpio-0-31 GPIOS [30 - 31] PINS [28 - 29] 0: gpio-32-63 GPIOS [32 - 39] PINS [0 - 7] 8: gpio-32-63 GPIOS [40 - 43] PINS [90 - 93] 12: gpio-32-63 GPIOS [44 - 59] PINS [12 - 27] 28: gpio-32-63 GPIOS [60 - 63] PINS [30 - 33] 0: gpio-64-95 GPIOS [64 - 81] PINS [34 - 51] 18: gpio-64-95 GPIOS [82 - 85] PINS [77 - 80] 22: gpio-64-95 GPIOS [86 - 95] PINS [56 - 65] 0: gpio-96-127 GPIOS [96 - 100] PINS [66 - 70] 5: gpio-96-127 GPIOS [101 - 102] PINS [98 - 99] 7: gpio-96-127 GPIOS [103 - 104] PINS [75 - 76] 13: gpio-96-127 GPIOS [109 - 109] PINS [141 - 141] 14: gpio-96-127 GPIOS [110 - 117] PINS [100 - 107] Do you mean you would like to see the mapping added as a column in the pins file? debian@beaglebone:~$ sudo cat /sys/kernel/debug/pinctrl/44e10800.pinmux-pinctrl-single/pins |head registered pins: 142 pin 0 (PIN0) 44e10800 00000027 pinctrl-single pin 1 (PIN1) 44e10804 00000027 pinctrl-single pin 2 (PIN2) 44e10808 00000027 pinctrl-single pin 3 (PIN3) 44e1080c 00000027 pinctrl-single pin 4 (PIN4) 44e10810 00000027 pinctrl-single pin 5 (PIN5) 44e10814 00000027 pinctrl-single pin 6 (PIN6) 44e10818 00000027 pinctrl-single pin 7 (PIN7) 44e1081c 00000027 pinctrl-single pin 8 (PIN8) 44e10820 00000027 pinctrl-single So that could be: debian@beaglebone:~$ sudo cat /sys/kernel/debug/pinctrl/44e10800.pinmux-pinctrl-single/pins |head registered pins: 142 pin 0 (PIN0) 44e10800 00000027 pinctrl-single GPIO-32 pin 1 (PIN1) 44e10804 00000027 pinctrl-single GPIO-33 pin 2 (PIN2) 44e10808 00000027 pinctrl-single GPIO-34 pin 3 (PIN3) 44e1080c 00000027 pinctrl-single GPIO-35 pin 4 (PIN4) 44e10810 00000027 pinctrl-single GPIO-36 pin 5 (PIN5) 44e10814 00000027 pinctrl-single GPIO-37 pin 6 (PIN6) 44e10818 00000027 pinctrl-single GPIO-38 pin 7 (PIN7) 44e1081c 00000027 pinctrl-single GPIO-39 pin 8 (PIN8) 44e10820 00000027 pinctrl-single GPIO-22 Should I try to add that in pcs_pin_dbg_show()? It currently prints: seq_printf(s, "%zx %08x %s ", pa, val, DRIVER_NAME); so I could change that to include the GPIO number if mapping exists. thanks, drew
* Drew Fustini <drew@beagleboard.org> [200713 17:47]: > Do you mean you would like to see the mapping added as a column in the pins file? > > debian@beaglebone:~$ sudo cat /sys/kernel/debug/pinctrl/44e10800.pinmux-pinctrl-single/pins |head > registered pins: 142 > pin 0 (PIN0) 44e10800 00000027 pinctrl-single > pin 1 (PIN1) 44e10804 00000027 pinctrl-single > pin 2 (PIN2) 44e10808 00000027 pinctrl-single > pin 3 (PIN3) 44e1080c 00000027 pinctrl-single > pin 4 (PIN4) 44e10810 00000027 pinctrl-single > pin 5 (PIN5) 44e10814 00000027 pinctrl-single > pin 6 (PIN6) 44e10818 00000027 pinctrl-single > pin 7 (PIN7) 44e1081c 00000027 pinctrl-single > pin 8 (PIN8) 44e10820 00000027 pinctrl-single > > So that could be: > > debian@beaglebone:~$ sudo cat /sys/kernel/debug/pinctrl/44e10800.pinmux-pinctrl-single/pins |head > registered pins: 142 > pin 0 (PIN0) 44e10800 00000027 pinctrl-single GPIO-32 > pin 1 (PIN1) 44e10804 00000027 pinctrl-single GPIO-33 > pin 2 (PIN2) 44e10808 00000027 pinctrl-single GPIO-34 > pin 3 (PIN3) 44e1080c 00000027 pinctrl-single GPIO-35 > pin 4 (PIN4) 44e10810 00000027 pinctrl-single GPIO-36 > pin 5 (PIN5) 44e10814 00000027 pinctrl-single GPIO-37 > pin 6 (PIN6) 44e10818 00000027 pinctrl-single GPIO-38 > pin 7 (PIN7) 44e1081c 00000027 pinctrl-single GPIO-39 > pin 8 (PIN8) 44e10820 00000027 pinctrl-single GPIO-22 Yes that would make the debugfs output more understandable and easier to use. > Should I try to add that in pcs_pin_dbg_show()? > > It currently prints: > > seq_printf(s, "%zx %08x %s ", pa, val, DRIVER_NAME); > > so I could change that to include the GPIO number if mapping exists. Sounds good to me yeah :) However, the issue of relying on debugfs for this still remains unsolved. But seems that probably should be done with the existing GPIO related API instead and a different issue from the pinctrl changes. Regards, Tony
On Mon, Jul 13, 2020 at 11:05:19AM -0700, Tony Lindgren wrote: > * Drew Fustini <drew@beagleboard.org> [200713 17:47]: > > Do you mean you would like to see the mapping added as a column in the pins file? > > > > debian@beaglebone:~$ sudo cat /sys/kernel/debug/pinctrl/44e10800.pinmux-pinctrl-single/pins |head > > registered pins: 142 > > pin 0 (PIN0) 44e10800 00000027 pinctrl-single > > pin 1 (PIN1) 44e10804 00000027 pinctrl-single > > pin 2 (PIN2) 44e10808 00000027 pinctrl-single > > pin 3 (PIN3) 44e1080c 00000027 pinctrl-single > > pin 4 (PIN4) 44e10810 00000027 pinctrl-single > > pin 5 (PIN5) 44e10814 00000027 pinctrl-single > > pin 6 (PIN6) 44e10818 00000027 pinctrl-single > > pin 7 (PIN7) 44e1081c 00000027 pinctrl-single > > pin 8 (PIN8) 44e10820 00000027 pinctrl-single > > > > So that could be: > > > > debian@beaglebone:~$ sudo cat /sys/kernel/debug/pinctrl/44e10800.pinmux-pinctrl-single/pins |head > > registered pins: 142 > > pin 0 (PIN0) 44e10800 00000027 pinctrl-single GPIO-32 > > pin 1 (PIN1) 44e10804 00000027 pinctrl-single GPIO-33 > > pin 2 (PIN2) 44e10808 00000027 pinctrl-single GPIO-34 > > pin 3 (PIN3) 44e1080c 00000027 pinctrl-single GPIO-35 > > pin 4 (PIN4) 44e10810 00000027 pinctrl-single GPIO-36 > > pin 5 (PIN5) 44e10814 00000027 pinctrl-single GPIO-37 > > pin 6 (PIN6) 44e10818 00000027 pinctrl-single GPIO-38 > > pin 7 (PIN7) 44e1081c 00000027 pinctrl-single GPIO-39 > > pin 8 (PIN8) 44e10820 00000027 pinctrl-single GPIO-22 > > Yes that would make the debugfs output more understandable and > easier to use. I have posted a patch [0] to add the GPIO-xx column to the pins file. Thanks, Drew [0] https://lore.kernel.org/linux-gpio/20200717013338.1741659-1-drew@beagleboard.org/
diff --git a/arch/arm/boot/dts/am335x-pocketbeagle.dts b/arch/arm/boot/dts/am335x-pocketbeagle.dts index 22d52516b7fc..f6de2028ba53 100644 --- a/arch/arm/boot/dts/am335x-pocketbeagle.dts +++ b/arch/arm/boot/dts/am335x-pocketbeagle.dts @@ -221,6 +221,8 @@ ehrpwm1_pins: pinmux-ehrpwm1-pins { pinctrl-single,pins = < AM33XX_PADCONF(AM335X_PIN_GPMC_A2, PIN_OUTPUT_PULLDOWN, MUX_MODE6) /* (U14) gpmc_a2.ehrpwm1A */ >; + pinctrl-single,bias-pulldown = <8 8 0 24>; + /*pinctrl-single,bias-pullup = <24 24 0 24>;*/ }; mmc0_pins: pinmux-mmc0-pins { diff --git a/arch/arm/boot/dts/am33xx-l4.dtsi b/arch/arm/boot/dts/am33xx-l4.dtsi index 903338015a68..cb8a57ed13c1 100644 --- a/arch/arm/boot/dts/am33xx-l4.dtsi +++ b/arch/arm/boot/dts/am33xx-l4.dtsi @@ -288,7 +288,7 @@ scm: scm@0 { ranges = <0 0 0x2000>; am33xx_pinmux: pinmux@800 { - compatible = "pinctrl-single"; + compatible = "pinconf-single"; reg = <0x800 0x238>; #pinctrl-cells = <2>; pinctrl-single,register-width = <32>; diff --git a/drivers/gpio/Makefile b/drivers/gpio/Makefile index 1e4894e0bf0f..c55a5c167c43 100644 --- a/drivers/gpio/Makefile +++ b/drivers/gpio/Makefile @@ -1,7 +1,7 @@ # SPDX-License-Identifier: GPL-2.0 # generic gpio support: platform drivers, dedicated expander chips, etc -ccflags-$(CONFIG_DEBUG_GPIO) += -DDEBUG +ccflags-$(CONFIG_DEBUG_GPIO) += -DDEBUG -fno-inline obj-$(CONFIG_GPIOLIB) += gpiolib.o obj-$(CONFIG_GPIOLIB) += gpiolib-devres.o diff --git a/drivers/gpio/gpio-omap.c b/drivers/gpio/gpio-omap.c index b8e2ecc3eade..972629d69917 100644 --- a/drivers/gpio/gpio-omap.c +++ b/drivers/gpio/gpio-omap.c @@ -871,6 +871,21 @@ static int omap_gpio_get_multiple(struct gpio_chip *chip, unsigned long *mask, return 0; } +/** + * omap_gpio_bias() - apply configuration for a pin + * @gc: the gpiochip owning the GPIO + * @offset: the offset of the GPIO to apply the configuration + * @config: the configuration to be applied + */ +static int omap_gpio_bias(struct gpio_chip *gc, unsigned offset, unsigned long config) +{ + int ret = 0; + + ret = gpiochip_generic_config(gc, offset, config); + return ret; +} + + static int omap_gpio_debounce(struct gpio_chip *chip, unsigned offset, unsigned debounce) { @@ -896,12 +911,26 @@ static int omap_gpio_set_config(struct gpio_chip *chip, unsigned offset, unsigned long config) { u32 debounce; + u32 config_arg; + int ret; - if (pinconf_to_config_param(config) != PIN_CONFIG_INPUT_DEBOUNCE) - return -ENOTSUPP; + if ((pinconf_to_config_param(config) == PIN_CONFIG_BIAS_DISABLE) || + (pinconf_to_config_param(config) == PIN_CONFIG_BIAS_PULL_UP) || + (pinconf_to_config_param(config) == PIN_CONFIG_BIAS_PULL_DOWN)) + { + ret = omap_gpio_bias(chip, offset, config); + } + else if (pinconf_to_config_param(config) == PIN_CONFIG_INPUT_DEBOUNCE) + { + debounce = pinconf_to_config_argument(config); + ret = omap_gpio_debounce(chip, offset, debounce); + } + else + { + ret = -ENOTSUPP; + } - debounce = pinconf_to_config_argument(config); - return omap_gpio_debounce(chip, offset, debounce); + return ret; } static void omap_gpio_set(struct gpio_chip *chip, unsigned offset, int value) diff --git a/drivers/pinctrl/Makefile b/drivers/pinctrl/Makefile index 1731b2154df9..fc62c20702c6 100644 --- a/drivers/pinctrl/Makefile +++ b/drivers/pinctrl/Makefile @@ -1,7 +1,7 @@ # SPDX-License-Identifier: GPL-2.0 # generic pinmux support -subdir-ccflags-$(CONFIG_DEBUG_PINCTRL) += -DDEBUG +subdir-ccflags-$(CONFIG_DEBUG_PINCTRL) += -DDEBUG -fno-inline obj-y += core.o pinctrl-utils.o obj-$(CONFIG_PINMUX) += pinmux.o