Odroid C2: libgpiod with mainline kernel not working

This forum is for topics dealing with problems with software specifically in the AArch64 repo.

Odroid C2: libgpiod with mainline kernel not working

Postby pohl7452 » Wed Apr 22, 2020 6:03 am

Hi,

I have a momentary push button connected to pins 29 (+) and 30 (-) and event monitoring with libgpiod (1.4.3-1) on Odroid C2 with a mainline kernel (5.6.5-1-ARCH) doesn't seem to work as expected. I get an error message "Failed to issue GET EVENT IOCTL (-19)".

Steps to reproduce:
$this->bbcode_second_pass_code('', '$ sudo gpiodetect
gpiochip0 [aobus-banks] (15 lines)
gpiochip1 [periphs-banks] (119 lines)
gpiochip2 [ftdi-cbus] (4 lines)')
So there are three gpiochip devices.
$this->bbcode_second_pass_code('', '$ sudo gpioinfo
gpiochip1 - 119 lines:
...
line 92: "J2 Header Pin29" unused input active-high
...')
So pin 29 is connected to line offset 92.
$this->bbcode_second_pass_code('', '$sudo gpioget 1 92
1')
So the pin is currently pulled high, as the button is not pressed. So far so good, but now ...
$this->bbcode_second_pass_code('', '$ sudo gpio-event-mon -n gpiochip1 -o 92 -r -f
Failed to issue GET EVENT IOCTL (-19)')
The event monitoring is failing as the ioctl call gives error -19. I went to various kernel source codes but couldn't find what the errro -19 means.

Any idea why its not working?
pohl7452
 
Posts: 7
Joined: Wed Apr 22, 2020 5:47 am

Re: Odroid C2: libgpiod with mainline kernel not working

Postby pohl7452 » Tue Jun 09, 2020 12:04 pm

Hi,

I have investigated this issue a bit more.
$this->bbcode_second_pass_code('', '
$ sudo gpiomon /dev/gpiochip1 113
gpiomon: error waiting for events: No such device
')
Documentation and examples of the new libgpiod library are still a bit sparse. In case somebody is interested in a working example for interrupt driven event polling:
$this->bbcode_second_pass_code('', '
#include <gpiod.h>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>

int main(int argc, char *argv[])
{
int offset = 0;

if (argc != 3) {
fprintf(stderr, "usage: %s <controler> <offset>\n", argv[0]);
exit(EXIT_FAILURE);
}
if (sscanf(argv[2], "%d", &offset) != 1) {
fprintf(stderr, "invalid offset: %s\n", argv[2]);
exit(EXIT_FAILURE);
}

int ret = 0;
struct timespec ts = {0, 1000000};
struct gpiod_line_event event;
struct gpiod_chip *chip;
struct gpiod_line *line;

chip = gpiod_chip_open(argv[1]);
if (!chip) {
fprintf(stderr, "GPIO chip %s not found.\n", argv[1]);
exit(EXIT_FAILURE);
}

line = gpiod_chip_get_line(chip, offset);
if (!line) {
gpiod_chip_close(chip);
fprintf(stderr, "GPIO line %d could not be opened.\n", offset);
exit(EXIT_FAILURE);
}

ret = gpiod_line_request_both_edges_events(line, "event_test");
if (ret < 0) {
gpiod_chip_close(chip);
perror("Request events failed");
exit(EXIT_FAILURE);
}

for (;;) {
do {
ret = gpiod_line_event_wait(line, &ts);
} while (ret <= 0);

ret = gpiod_line_event_read(line, &event);
if (!ret) {
fprintf(stdout, "[%ld.%09ld] %s\n",
event.ts.tv_sec, event.ts.tv_nsec,
(event.event_type == GPIOD_CTXLESS_EVENT_RISING_EDGE) ? "rising" :
(event.event_type == GPIOD_CTXLESS_EVENT_FALLING_EDGE) ? "falling" : "??");
}
}
return EXIT_SUCCESS;
}
')
The program works as expected on a poor old Raspberry Pi B+ with Arch Linux ARM, but fails with the same "No such device" error on the Odroid C2.
$this->bbcode_second_pass_code('', '
$ gcc -o gpio_test gpio_test.c -lgpiod
$ sudo ./gpio_test /dev/gpiochip1 113
Request events failed: No such device
')
And running through strace:
$this->bbcode_second_pass_code('', '
# strace -Z ./gpio_test /dev/gpiochip1 113
ioctl(3, GPIO_GET_LINEEVENT_IOCTL, 0xfffff2b0f0f8) = -1 ENODEV (No such device)
Request events failed: No such device
')
Any ideas why the gpiochip device cannot be found?
Would this be working on the new Odroid C4?

Thanks for any help or comments.
pohl7452
 
Posts: 7
Joined: Wed Apr 22, 2020 5:47 am

Re: Odroid C2: libgpiod with mainline kernel not working

Postby pohl7452 » Sun Jun 28, 2020 9:37 am

Hi,

To answer my own question, the libgpiod interface works with the new Odroid C4 and the legacy kernel 4.9.218-1-ARCH from Odroid. I haven't figured out though what the difference is between the legacy and the mainline kernels for the C4 regarding the libgpiod interface (C2 legacy 3.16 is too old for the libgpiod interface as it was only introduced in 4.8). Same is true for Armbian and Ubuntu on the C4 (legacy kernels work, mainline kernels don't).

As the Odroid C4 is not officially supported by Arch Linux ARM yet, I used the PKGBUILDs from
Jefferson González at https://github.com/jgmdev/archlinux-odroid to install Arch Linux ARM on the Odroid C4. The kernel and uboot was replaced in an arch-chroot on the Odroid C2 starting with the generic Arch Linux ARM aarch64 image.

Although the manual installation procedure works ok and my C4 is running Arch Linux ARM, I wish that the Odroid C4 would be officially supported and a ready made basic image without a pre-installed desktop environment would be available for downloading.
pohl7452
 
Posts: 7
Joined: Wed Apr 22, 2020 5:47 am

Re: Odroid C2: libgpiod with mainline kernel not working

Postby erich » Sun Aug 09, 2020 4:59 am

The root problem is gpiod_to_irq() is not implemented in the gpiochip/irqchip driver code.
Supposedly there are some "historical reasons" it can't be done. I don't know what they are, they didn't tell me.
The same missing code also breaks the PPS code which was my issue.
erich
 
Posts: 6
Joined: Sun Jul 26, 2020 4:01 am


Return to ARMv8

Who is online

Users browsing this forum: No registered users and 5 guests