1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * GPIO character device helper for reading chip information.
5 * Copyright (C) 2021 Bartosz Golaszewski <brgl@bgdev.pl>
9 #include <linux/gpio.h>
13 #include <sys/ioctl.h>
14 #include <sys/types.h>
16 static void print_usage(void)
19 printf(" gpio-chip-info <chip path> [name|label|num-lines]\n");
22 int main(int argc
, char **argv
)
24 struct gpiochip_info info
;
32 fd
= open(argv
[1], O_RDWR
);
34 perror("unable to open the GPIO chip");
38 memset(&info
, 0, sizeof(info
));
39 ret
= ioctl(fd
, GPIO_GET_CHIPINFO_IOCTL
, &info
);
41 perror("chip info ioctl failed");
45 if (strcmp(argv
[2], "name") == 0) {
46 printf("%s\n", info
.name
);
47 } else if (strcmp(argv
[2], "label") == 0) {
48 printf("%s\n", info
.label
);
49 } else if (strcmp(argv
[2], "num-lines") == 0) {
50 printf("%u\n", info
.lines
);
52 fprintf(stderr
, "unknown command: %s\n", argv
[2]);