Skip to contentSkip to conversation

gpiod: Set pullup for Input Line

DISCUSSION Hans Kurscheidt 4 participants 16 messages Mar 21, 2022 – Mar 22, 2022 2 messages not in the archive GPIO

lore
Share & tools
lore
#0 lore raw

Despite deep searching, I cannot find any information, if gpiod allow specifying pull-ups to input lines and how to do/handle it.

RGDS

hk

#1 lore raw

Hello Hans,

Am Mon, Mar 21, 2022 at 11:43:45AM +0100 schrieb Hans Kurscheidt:

Quoted 2 lines

Despite deep searching, I cannot find any information, if gpiod allow specifying pull-ups to input lines and how to do/handle it.

This is usually something described in device tree. Or do you have a use case for changing it at runtime?

Greets
Alex

#3 lore raw

Hi thanks, that makes hope.

Unfortunately apt-get gpiod on my OrangePi Armbian board gives me version 1.2, while the dev is already at 1.6. I probably have to build it from source.

Keeping fingers crossed .

RGDS

hk

Am 21.03.2022 um 17:26 schrieb Andy Shevchenko:

Quoted 6 lines · Hans Kurscheidt
Quoted 2 lines

Despite deep searching, I cannot find any information, if gpiod allow specifying pull-ups to input lines and how to do/handle it.

Have you followed this code from libgpiod?
https://git.kernel.org/pub/scm/libs/libgpiod/libgpiod.git/tree/tools/gpioset.c#n44

#4 lore raw
Quoted 2 lines · Hans Kurscheidt

Hi thanks, that makes hope.

First of all, please do not top-post.

Quoted 5 lines

Unfortunately apt-get gpiod on my OrangePi Armbian board gives me version 1.2, while the dev is already at 1.6. I probably have to build it from source.

Keeping fingers crossed .

I don't remember the details of old versions of libgpiod (Bart? Kent?) I think it was available even there.

Quoted 6 lines

Am 21.03.2022 um 17:26 schrieb Andy Shevchenko:

Quoted 5 lines · Hans Kurscheidt
Quoted 2 lines

Despite deep searching, I cannot find any information, if gpiod allow specifying pull-ups to input lines and how to do/handle it.

Have you followed this code from libgpiod?
https://git.kernel.org/pub/scm/libs/libgpiod/libgpiod.git/tree/tools/gpioset.c#n44

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#5 lore raw

Am 21.03.2022 um 18:33 schrieb Andy Shevchenko:

Quoted 13 lines · Hans Kurscheidt
Quoted 1 line

Hi thanks, that makes hope.

First of all, please do not top-post.

Quoted 5 lines

Unfortunately apt-get gpiod on my OrangePi Armbian board gives me version 1.2, while the dev is already at 1.6. I probably have to build it from source.

Keeping fingers crossed .

I don't remember the details of old versions of libgpiod (Bart? Kent?) I think it was available even there.

Quoted 1 line

Am 21.03.2022 um 17:26 schrieb Andy Shevchenko:

Quoted 8 lines
Quoted 5 lines
Quoted 5 lines · Hans Kurscheidt
Quoted 2 lines

Despite deep searching, I cannot find any information, if gpiod allow specifying pull-ups to input lines and how to do/handle it.

Have you followed this code from libgpiod?
https://git.kernel.org/pub/scm/libs/libgpiod/libgpiod.git/tree/tools/gpioset.c#n44

I don't think that the Bias option is in 1.2.3, because help is mute about it

Trying to build it from source, doesn't work for me. I get:

hk@orangepizeroplus:~/libgpiod$ ./autogen.sh --enable-tools=yes --prefix=/usr/bin
autoreconf: Entering directory `.'
autoreconf: configure.ac: not using Gettext
autoreconf: running: aclocal --force -I m4
aclocal: warning: couldn't open directory 'm4': No such file or directory
autoreconf: configure.ac: tracing
autoreconf: configure.ac: creating directory autostuff
autoreconf: configure.ac: not using Libtool
autoreconf: running: /usr/bin/autoconf --force
configure.ac:163: error: possibly undefined macro: AC_LIBTOOL_CXX
      If this token and others are legitimate, please use m4_pattern_allow.
      See the Autoconf documentation.
configure.ac:165: error: Unexpanded AX_ macro found. Please install GNU autoconf-archive.
configure.ac:179: error: Unexpanded AX_ macro found. Please install GNU autoconf-archive.
autoreconf: /usr/bin/autoconf failed with exit status: 1
hk@orangepizeroplus:~/libgpiod$

??

RGDS

#6 lore raw

Am 21.03.2022 um 18:33 schrieb Andy Shevchenko:

Quoted 13 lines · Hans Kurscheidt
Quoted 1 line

Hi thanks, that makes hope.

First of all, please do not top-post.

Quoted 5 lines

Unfortunately apt-get gpiod on my OrangePi Armbian board gives me version 1.2, while the dev is already at 1.6. I probably have to build it from source.

Keeping fingers crossed .

I don't remember the details of old versions of libgpiod (Bart? Kent?) I think it was available even there.

Quoted 1 line

Am 21.03.2022 um 17:26 schrieb Andy Shevchenko:

Quoted 8 lines
Quoted 5 lines
Quoted 5 lines · Hans Kurscheidt
Quoted 2 lines

Despite deep searching, I cannot find any information, if gpiod allow specifying pull-ups to input lines and how to do/handle it.

Have you followed this code from libgpiod?
https://git.kernel.org/pub/scm/libs/libgpiod/libgpiod.git/tree/tools/gpioset.c#n44

I don't think that the Bias option is in 1.2.3, because help is mute about it

Trying to build it from source, doesn't work for me. I get:

hk@orangepizeroplus:~/libgpiod$ ./autogen.sh --enable-tools=yes --prefix=/usr/bin
autoreconf: Entering directory `.'
autoreconf: configure.ac: not using Gettext
autoreconf: running: aclocal --force -I m4
aclocal: warning: couldn't open directory 'm4': No such file or directory
autoreconf: configure.ac: tracing
autoreconf: configure.ac: creating directory autostuff
autoreconf: configure.ac: not using Libtool
autoreconf: running: /usr/bin/autoconf --force
configure.ac:163: error: possibly undefined macro: AC_LIBTOOL_CXX
      If this token and others are legitimate, please use m4_pattern_allow.
      See the Autoconf documentation.
configure.ac:165: error: Unexpanded AX_ macro found. Please install GNU autoconf-archive.
configure.ac:179: error: Unexpanded AX_ macro found. Please install GNU autoconf-archive.
autoreconf: /usr/bin/autoconf failed with exit status: 1
hk@orangepizeroplus:~/libgpiod$

??

RGDS

Got it; needed to install libtools and (may be) create a directory m4 in libgpiod Its working now w/ Version 2.0 and I see the Bias Option

Thank you

#7 lore raw
In reply to Andy Shevchenko
Quoted 6 lines · Andy Shevchenko
Quoted 2 lines · Hans Kurscheidt

Hi thanks, that makes hope.

First of all, please do not top-post.

Quoted 9 lines
Quoted 5 lines

Unfortunately apt-get gpiod on my OrangePi Armbian board gives me version 1.2, while the dev is already at 1.6. I probably have to build it from source.

Keeping fingers crossed .

I don't remember the details of old versions of libgpiod (Bart? Kent?) I think it was available even there.

Bias support was added in libgpiod v1.5.
It wasn't even exposed in the uAPI prior to that - it wasn't added until kernel v5.5.

In this case building the latest stable, 1.6.3, is the way to go.

Cheers,
Kent.

Quoted 11 lines
Quoted 6 lines

Am 21.03.2022 um 17:26 schrieb Andy Shevchenko:

Quoted 5 lines · Hans Kurscheidt
Quoted 2 lines

Despite deep searching, I cannot find any information, if gpiod allow specifying pull-ups to input lines and how to do/handle it.

Have you followed this code from libgpiod?
https://git.kernel.org/pub/scm/libs/libgpiod/libgpiod.git/tree/tools/gpioset.c#n44

Signature · 2 lines
With Best Regards,
Andy Shevchenko

A message that is not in the archive (sent off-list or not yet received): [email protected]

#9 lore raw

Am 22.03.2022 um 09:36 schrieb Hans Kurscheidt:

Quoted 45 lines

Am 22.03.2022 um 01:59 schrieb Kent Gibson:

Quoted 13 lines · Andy Shevchenko
Quoted 12 lines · Hans Kurscheidt
Quoted 1 line

Hi thanks, that makes hope.

First of all, please do not top-post.

Quoted 5 lines

Unfortunately apt-get gpiod on my OrangePi Armbian board gives me version 1.2, while the dev is already at 1.6. I probably have to build it from source.

Keeping fingers crossed .

I don't remember the details of old versions of libgpiod (Bart? Kent?) I think it was available even there.

Quoted 18 lines

Bias support was added in libgpiod v1.5.
It wasn't even exposed in the uAPI prior to that - it wasn't added until kernel v5.5.

In this case building the latest stable, 1.6.3, is the way to go.

Cheers,
Kent.

Quoted 9 lines
Quoted 6 lines

Am 21.03.2022 um 17:26 schrieb Andy Shevchenko:

Quoted 5 lines · Hans Kurscheidt
Quoted 2 lines

Despite deep searching, I cannot find any information, if gpiod allow specifying pull-ups to input lines and how to do/handle it.

Have you followed this code from libgpiod?
https://git.kernel.org/pub/scm/libs/libgpiod/libgpiod.git/tree/tools/gpioset.c#n44

Signature · 2 lines
With Best Regards,
Andy Shevchenko

Thank-you Kent!

Still 1 more question. I understand the sense of a Pull-up in Input mode, but reading the code, I see that the Bias option exists as well for gpioset (Output). What is the sense of this, and what does it do?

WRT. building it, it wasn't that straight forward, as in the description. On the Armbian/Debian buster Kernel 5.10.60-sunxi64 #21.08.1 I had to create an M4 dir, install GNU-archives and install libtools in addition to succeed building it. Then doxygen and help2man were still missing.

All the best and thank you again, for solving my problem!

Hans

#10 lore raw
Quoted 2 lines · Hans Kurscheidt

Am 22.03.2022 um 09:36 schrieb Hans Kurscheidt:

Quoted 1 line

Am 22.03.2022 um 01:59 schrieb Kent Gibson:

...

Quoted 3 lines
Quoted 3 lines

Still 1 more question. I understand the sense of a Pull-up in Input mode, but reading the code, I see that the Bias option exists as well for gpioset (Output). What is the sense of this, and what does it do?

I guess we started providing OPEN SOURCE / DRAIN in libgpiod v2.0 (Bart or Kent may correct me), but you should get an idea why it may be useful.

On top of that, the pin can be reconfigured from input to output and vice versa at run-time. So, keeping a bias setting will allow not to think about it when pin direction is switched, although I agree this may not be a clean case to use.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#11 lore raw

Am 22.03.2022 um 09:50 schrieb Andy Shevchenko:

Quoted 8 lines · Hans Kurscheidt
Quoted 2 lines

Am 22.03.2022 um 09:36 schrieb Hans Kurscheidt:

Quoted 1 line

Am 22.03.2022 um 01:59 schrieb Kent Gibson:

...

Quoted 3 lines
Quoted 3 lines

Still 1 more question. I understand the sense of a Pull-up in Input mode, but reading the code, I see that the Bias option exists as well for gpioset (Output). What is the sense of this, and what does it do?

Quoted 8 lines

I guess we started providing OPEN SOURCE / DRAIN in libgpiod v2.0 (Bart or Kent may correct me), but you should get an idea why it may be useful.

On top of that, the pin can be reconfigured from input to output and vice versa at run-time. So, keeping a bias setting will allow not to think about it when pin direction is switched, although I agree this may not be a clean case to use.

Hi Andy,

Open Source/Drain is completely different from Pull_UP/DOWN! Open source/drain defines, which active element (transistor) is attached to the line, while pull_up/down defines, which passive element (resistor) is attached to the line. In some sense one could say, what pull_up/down is for input, open drain/source is the corresponding thing for output, but they are realized by different means. IMHO, "bias" (pull-up/down) should be an option for gpioget, while "drive" makes only sense for gpioset, because I understand them as mutually excluding, but may be, I'm overseeing something.

Unfortunately, this leads me to yet another question: Bias defines "as-is" and "pull-up/down" as options. Just to be sure, that would imply that one has to set the bias option to pull_up/down for the first call to gpioget and that subsequent readings from the input pin should/can run w/out the bias option, hence "as-is", or do you recommend to have the bias option specified for each read from the pin?

#12 lore raw
Quoted 21 lines · Hans Kurscheidt

Am 22.03.2022 um 09:50 schrieb Andy Shevchenko:

Quoted 8 lines · Hans Kurscheidt
Quoted 2 lines

Am 22.03.2022 um 09:36 schrieb Hans Kurscheidt:

Quoted 1 line

Am 22.03.2022 um 01:59 schrieb Kent Gibson:

...

Quoted 3 lines
Quoted 3 lines

Still 1 more question. I understand the sense of a Pull-up in Input mode, but reading the code, I see that the Bias option exists as well for gpioset (Output). What is the sense of this, and what does it do?

Quoted 8 lines

I guess we started providing OPEN SOURCE / DRAIN in libgpiod v2.0 (Bart or Kent may correct me), but you should get an idea why it may be useful.

On top of that, the pin can be reconfigured from input to output and vice versa at run-time. So, keeping a bias setting will allow not to think about it when pin direction is switched, although I agree this may not be a clean case to use.

Hi Andy,

Quoted 9 lines

Open Source/Drain is completely different from Pull_UP/DOWN! Open source/drain defines, which active element (transistor) is attached to the line, while pull_up/down defines, which passive element (resistor) is attached to the line. In some sense one could say, what pull_up/down is for input, open drain/source is the corresponding thing for output, but they are realized by different means. IMHO, "bias" (pull-up/down) should be an option for gpioget, while "drive" makes only sense for gpioset, because I understand them as mutually excluding, but may be, I'm overseeing something.

You understand that with open drain/source there is one state where the line is not driven by the chip, but goes high impedance and is driven by the external circuit?
And the bias can be considered to be part of the external circuit? If so, not sure what your issue is here. You agree that drive and bias are totally independent, but take issue at being able to set them independently in gpioset? What am I missing?

And there IS a bias option for gpioget - as it makes sense there as well. And gpiomon as well.

Quoted 7 lines

Unfortunately, this leads me to yet another question: Bias defines "as-is" and "pull-up/down" as options. Just to be sure, that would imply that one has to set the bias option to pull_up/down for the first call to gpioget and that subsequent readings from the input pin should/can run w/out the bias option, hence "as-is", or do you recommend to have the bias option specified for each read from the pin?

The "as-is" is an unfortunate side-effect of bias being a late addition to the API, though it could be argued that it is useful in its own right, as Andy mentioned.
Its main purpose is for backwards compatibility and is the default for that reason.

If you need a bias then set it as needed. I would use options consistently, not have different options on subsequent calls.

I would also recommend using edge events, such as those provided by gpiomon, rather than polling with gpioget, but that depends on the complexity of your use case.

Cheers,
Kent.

#13 lore raw
In reply to Andy Shevchenko
Quoted 6 lines · Andy Shevchenko
Quoted 2 lines · Hans Kurscheidt

Am 22.03.2022 um 09:36 schrieb Hans Kurscheidt:

Quoted 1 line

Am 22.03.2022 um 01:59 schrieb Kent Gibson:

...

Quoted 8 lines
Quoted 3 lines
Quoted 3 lines

Still 1 more question. I understand the sense of a Pull-up in Input mode, but reading the code, I see that the Bias option exists as well for gpioset (Output). What is the sense of this, and what does it do?

I guess we started providing OPEN SOURCE / DRAIN in libgpiod v2.0 (Bart or Kent may correct me), but you should get an idea why it may be useful.

No - open drain/source is not new - it has been there since cdev was added AFAIAA.
The v2 ABI, which libgpiod v2 will support, adds debounce, event sequence numbers, events from multiple lines in one request, and a few other things, but the drive options have always been there - even before the bias options were added.

Quoted 5 lines

On top of that, the pin can be reconfigured from input to output and vice versa at run-time. So, keeping a bias setting will allow not to think about it when pin direction is switched, although I agree this may not be a clean case to use.

Agreed - I would set both the direction and bias in such a case.

Cheers,
Kent.

#14 lore raw
In reply to a message not in the archive
Quoted 35 lines · Hans Kurscheidt

Am 22.03.2022 um 01:59 schrieb Kent Gibson:

Quoted 13 lines · Andy Shevchenko
Quoted 12 lines · Hans Kurscheidt
Quoted 1 line

Hi thanks, that makes hope.

First of all, please do not top-post.

Quoted 5 lines

Unfortunately apt-get gpiod on my OrangePi Armbian board gives me version 1.2, while the dev is already at 1.6. I probably have to build it from source.

Keeping fingers crossed .

I don't remember the details of old versions of libgpiod (Bart? Kent?) I think it was available even there.

Quoted 19 lines

Bias support was added in libgpiod v1.5.
It wasn't even exposed in the uAPI prior to that - it wasn't added until kernel v5.5.

In this case building the latest stable, 1.6.3, is the way to go.

Cheers,
Kent.

Quoted 10 lines
Quoted 6 lines

Am 21.03.2022 um 17:26 schrieb Andy Shevchenko:

Quoted 5 lines · Hans Kurscheidt
Quoted 2 lines

Despite deep searching, I cannot find any information, if gpiod allow specifying pull-ups to input lines and how to do/handle it.

Have you followed this code from libgpiod?
https://git.kernel.org/pub/scm/libs/libgpiod/libgpiod.git/tree/tools/gpioset.c#n44

Signature · 2 lines
With Best Regards,
Andy Shevchenko
Quoted 6 lines

Thank-you Kent!

Still 1 more question. I understand the sense of a Pull-up in Input mode, but reading the code, I see that the Bias option exists as well for gpioset (Output). What is the sense of this, and what does it do?

As answered by Andy, drive and bias are orthogonal so gpioset supports setting them independently. Obviously setting bias with push-pull doesn't make much sense, but the case it is there for is combining open drain/source with a pull for when the line is not being driven. Granted that such a pull would usually be provided externally, but the option is there in case it isn't.

Quoted 5 lines

WRT. building it, it wasn't that straight forward, as in the description. On the Armbian/Debian buster Kernel 5.10.60-sunxi64 #21.08.1 I had to create an M4 dir, install GNU-archives and install libtools in addition to succeed building it. Then doxygen and help2man were still missing.

I defer to Bart on build issues, but you shouldn't need to create the m4 directory - you should install m4.
In fact all these packages:
apt_packages:
- autoconf
- autoconf-archive
- libtool
- m4
- doxygen
- graphviz

That list is drawn from a recent patch I submitted to build the documentation on a readthedocs Ubuntu VM, but it is probably the same or very similar for Armbian.
That is in addition to build-essential, but I assume you already have that.

Cheers,
Kent.

A message that is not in the archive (sent off-list or not yet received): [email protected]

#16 lore raw

Hi Alex,

sure, device trees are eventually overwritten w/ new kernels or "as is" on a new device. Hence my application won't work on a new installation/board, because it needs certain GPIO input pins w/pull ups. DTBs need to be disassembled and re-compiled, which is not for the average user to install & run an application!

RGDS

hk

Am 21.03.2022 um 14:34 schrieb Alexander Dahl:

Quoted 11 lines

Hello Hans,

Am Mon, Mar 21, 2022 at 11:43:45AM +0100 schrieb Hans Kurscheidt:

Quoted 2 lines

Despite deep searching, I cannot find any information, if gpiod allow specifying pull-ups to input lines and how to do/handle it.

This is usually something described in device tree. Or do you have a use case for changing it at runtime?

Greets
Alex

#17 lore raw

Hei hei,

Am Mon, Mar 21, 2022 at 02:48:02PM +0100 schrieb Hans Kurscheidt:

Quoted 2 lines

sure, device trees are eventually overwritten w/ new kernels or "as is" on a new device.

You would need a board specific dts or dt overlay anyways. Just compile that again with you new kernel. For a new board, you need to make a new dts anyways, I don't see the problem here.

Quoted 2 lines

Hence my application won't work on a new installation/board, because it needs certain GPIO input pins w/pull ups.

Well, and those pullups need to be in SoC, and can not be external?

Quoted 3 lines

DTBs need to be
disassembled and re-compiled, which is not for the average user to install & run an application!

Why disassemble dtb, just go with the dts and compile that.

For easier handling in your application and across different boards, you might want to checkout gpio line names. We successfully used that to let the same application work with different boards (even with SoCs of different vendors), without the need to modify the app at all if the hardware changes. That is much more convenient than putting pin numbers and knowledge about each and every possible board into the application.

HTH & Greets
Alex