question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Bias resistor kernel version check

See original GitHub issue

So I learned yesterday that bias resistor settings are a recent addition to the Linux kernel (v5.5). In all my digging to get to the bottom of the ambiguous error 22s I was getting, I found out that ioctl calls to pinctrl should allow control of bias resistors (I have not looked into how yet).

I was going to implement kernel version checks and have my downstream software decide when to use this alternate method, but then I thought why do that when I can contribute it upstream to the library!

For the cdev class it will be pretty easy to add branching to use the alternate method if a bias setting is specified, but I wanted your input on how to do it for sysfs or if it should be done. My thought is just to add a named arg bias to the sysfs class init function. That would maintain backwards compatibility and not break the logic that counts unnamed args to determine if the user is trying to get a sysfs or cdev instance. What are you thoughts on this?

Edit: using pinctrl we could actually expand the sysfs class to offer all of the settings that cdev does with the exception of edge and label.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:8 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
vsergeevcommented, Jan 22, 2021

I’ve already got the version into a tuple that can be compared like if KERNEL_VERSION < (5, 5):

I think it would still be best to register these checks (there will be one for line drive as well) once at the top of the class, e.g.

class CdevGPIO:
    ...
    _SUPPORTS_LINE_BIAS = KERNEL_VERSION > (...)
    _SUPPORTS_LINE_DRIVE = KERNEL_VERSION > (...)

and then use them below with if CdevGPIO._SUPPORTS_LINE_DRIVE: ....

For SPI do you know what version it was added? I’m only using the GPIO portion of this library (so far). Also do you want separate PRs for each module?

It looks like for SPI, MODE32 was added in v3.15. I can do the SPI one if you prefer, that one is a little tricky since it already tries to use mode32 opportunistically, which will probably need to get refactored with this check.

Actually, a safer way to do the version check would be:

try:
    KERNEL_VERSION = tuple([int(s) for s in platform.release().split(".")[:2]])
except ValueError:
    KERNEL_VERSION = (0, 0)

OK, looks good.

Should attempting to use a bias setting when they are not supported raise an error? There is no use of logging in the library so I’m not sure how else we tell the user. The other option is to silently clear the bias setting, but then should the bias property also silently be a noop or should it throw a ValueError?

There isn’t a great native Python error for unsupported features, so I think it should return a GPIOError with a message similar to the other peripheries: https://github.com/vsergeev/c-periphery/blob/master/src/gpio.c#L881 . Ideally, python-periphery would have more descriptive error types that subclass GPIOError, but that can be done in the future.

0reactions
vsergeevcommented, Feb 4, 2021

Cherry-picked in 9c1a4f3 in devel. This issue should auto-close in the next release to master.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Check Kernel Version in Linux in Command Line
Check your Linux kernel version in a few simple steps. Find which kernel is running on your system via Command Line using one...
Read more >
GPIO resistor setting has no effect · Issue #106 - GitHub
I will get the bias resistor problem fixed later today I hope. While digging around in the kernel I ... GPIO add Kernel...
Read more >
New Linux Kernel 5.5 – New Interfaces in gpiolib – MicroHobby
In this version we have new features in gpiolib, new interfaces for pin configuration. Now we can configure a pin as a pull-up...
Read more >
sysfs-bus-iio - The Linux Kernel Archives
What: /sys/bus/iio/devices/iio:deviceX/buffer KernelVersion: 2.6.35 Contact: ... linux-iio@vger.kernel.org Description: Raw (unscaled no bias removal etc.) ...
Read more >
How To Find Which Linux Kernel Version Is Installed On My ...
How to check kernel version on Linux server/desktop/laptop. You need to use then uname command to print certain system information including ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found