Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kernel 6.6.47 changed the GPIO chip definition on Raspberry 5 and broke Seatalk1 #1788

Closed
sailoog opened this issue Sep 10, 2024 · 12 comments
Closed

Comments

@sailoog
Copy link
Contributor

sailoog commented Sep 10, 2024

In previous kernels the GPIO chip definition was "gpiochip0" for Raspberry Pi 4 and "gpiochip4" for Raspberry Pi 5. Now both are "gpiochip0" in latest kernel. Seatalk1 in Signal K is broken for Raspberry Pi 5 right now. We should just change this to get it working again:

gpio_chip = "gpiochip4"

Waiting for @astuder to wake up to confirm :)

@astuder
Copy link
Contributor

astuder commented Sep 10, 2024

Grrr :(

I will add a check for kernel version (/proc/version, or Python's platform.version from a quick search).

@sbender9
Copy link
Member

Why not make that configurable?

@astuder
Copy link
Contributor

astuder commented Sep 10, 2024

IMO the issue is a bit too low-level to confront users with.. even having to select the GPIO library is already border-line.

Seeing the error message reported in the OpenMarine forum, I think the simplest approach is to check for the file gpiochip4 and fall back to gpiochip0 if not present. That should keep working if Raspberry Pi foundation is flip-flopping on this change.

I will verify that with my Pi 5 later today.

@astuder
Copy link
Contributor

astuder commented Sep 10, 2024

Ok, looks a bit more complicated.
https://forums.raspberrypi.com/viewtopic.php?t=364196
I will investigate the method discussed in the PDF linked in the second post of that thread.

@sailoog
Copy link
Contributor Author

sailoog commented Sep 10, 2024

Agree, this is a lot to ask to users because there is not much information documenting this.

It seems that there is a symlink /dev/gpiochip-rpi I will test this in different scenarios too.

@astuder
Copy link
Contributor

astuder commented Sep 10, 2024

Unless they just introduced it, I don't think /dev/gpiochip-rpi is available on a stock Pi image. At least its not present on my non-updated Pi 5.

@astuder
Copy link
Contributor

astuder commented Sep 10, 2024

@sailoog can you run this script on a system with the update?

import gpiod
c = 0
while gpiod.is_gpiochip_device(f"/dev/gpiochip{c}"):
  with gpiod.Chip(f"/dev/gpiochip{c}") as chip:
    info = chip.get_info()
    print(f"{info.name} [{info.label}] ({info.num_lines} lines)")
  c += 1

on my non-updated Pi 5 it returns

gpiochip0 [gpio-brcmstb@107d508500] (32 lines)
gpiochip1 [gpio-brcmstb@107d508520] (4 lines)
gpiochip2 [gpio-brcmstb@107d517c00] (17 lines)
gpiochip3 [gpio-brcmstb@107d517c20] (6 lines)
gpiochip4 [pinctrl-rp1] (54 lines)

@astuder
Copy link
Contributor

astuder commented Sep 10, 2024

I made a new image for the Pi 5. Of course, the script above doesn't work with gpiod v1.x. Here's the same script for v1.x:

import gpiod
print(f"gpiod v{gpiod.__version__}")
for chip in gpiod.ChipIter():
  print(f"{chip.name()} [{chip.label()}] ({chip.num_lines()} lines)")

on fresh new image, GPIO still is on gpiochip4:

gpiod v1.6.3
gpiochip0 [gpio-brcmstb@107d508500] (32 lines)
gpiochip1 [gpio-brcmstb@107d508520] (4 lines)
gpiochip2 [gpio-brcmstb@107d517c00] (17 lines)
gpiochip3 [gpio-brcmstb@107d517c20] (6 lines)
gpiochip4 [pinctrl-rp1] (54 lines)

My kernel version is 6.6.31.. will try to update that after lunch

@astuder
Copy link
Contributor

astuder commented Sep 10, 2024

Ok, that was quicker than expected. After running rpi-update I'm on kernel 6.6.50, and pinctrl-rp1 is now on gpiochip0:

gpiod v1.6.3
gpiochip0 [pinctrl-rp1] (54 lines)
gpiochip10 [gpio-brcmstb@107d508500] (32 lines)
gpiochip11 [gpio-brcmstb@107d508520] (4 lines)
gpiochip12 [gpio-brcmstb@107d517c00] (17 lines)
gpiochip13 [gpio-brcmstb@107d517c20] (6 lines)

So yes, I can reproduce.

@astuder
Copy link
Contributor

astuder commented Sep 10, 2024

Updated the gist to automatically detect gpiochip on Raspberry Pi 5.

@sailoog can you test this please?

@sailoog
Copy link
Contributor Author

sailoog commented Sep 11, 2024

Tested on Raspberry 4 and 5, kernel 6.6.47 (stable), gpiod 1 and 2. No issues.

@tkurki
Copy link
Member

tkurki commented Sep 12, 2024

Fixed by #1789

@tkurki tkurki closed this as completed Sep 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants