gpio: chardev: Add function to retrieve sysfs base for a gpiochip
This allows to full mux structures which still need the sysfs GPIO numbers. In combination with mraa_find_gpio_line_by_name, this allows for platform setup that is independent of the gpiochip probing order. Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
This commit is contained in:
@@ -30,6 +30,7 @@ mraa_gpiod_chip_info* mraa_get_chip_info_by_path(const char* path);
|
||||
mraa_gpiod_chip_info* mraa_get_chip_info_by_name(const char* name);
|
||||
mraa_gpiod_chip_info* mraa_get_chip_info_by_label(const char* label);
|
||||
mraa_gpiod_chip_info* mraa_get_chip_info_by_number(unsigned number);
|
||||
int mraa_get_chip_base_by_number(unsigned number);
|
||||
|
||||
mraa_gpiod_line_info* mraa_get_line_info_from_descriptor(int chip_fd, unsigned line_number);
|
||||
mraa_gpiod_line_info* mraa_get_line_info_by_chip_number(unsigned chip_number, unsigned line_number);
|
||||
|
||||
@@ -244,6 +244,43 @@ mraa_get_chip_info_by_number(unsigned number)
|
||||
return cinfo;
|
||||
}
|
||||
|
||||
int
|
||||
mraa_get_chip_base_by_number(unsigned number)
|
||||
{
|
||||
#if defined(PERIPHERALMAN)
|
||||
return -1;
|
||||
#else
|
||||
char* glob;
|
||||
char* path;
|
||||
FILE* fh;
|
||||
int res;
|
||||
|
||||
glob = malloc(PATH_MAX);
|
||||
if (!glob) {
|
||||
syslog(LOG_ERR, "[GPIOD_INTERFACE]: malloc() fail");
|
||||
return -1;
|
||||
}
|
||||
|
||||
snprintf(glob, PATH_MAX, "/sys/bus/gpio/devices/gpiochip%d/../gpio/*/base", number);
|
||||
|
||||
path = mraa_file_unglob(glob);
|
||||
free(glob);
|
||||
if (!path) {
|
||||
syslog(LOG_ERR, "[GPIOD_INTERFACE]: invalid chip number");
|
||||
res = -1;
|
||||
} else {
|
||||
fh = fopen(path, "r");
|
||||
if (!fh || fscanf(fh, "%d", &res) != 1) {
|
||||
syslog(LOG_ERR, "[GPIOD_INTERFACE]: could not read from %s", path);
|
||||
res = -1;
|
||||
}
|
||||
}
|
||||
|
||||
free(path);
|
||||
return res;
|
||||
#endif
|
||||
}
|
||||
|
||||
mraa_gpiod_line_info*
|
||||
mraa_get_line_info_from_descriptor(int chip_fd, unsigned line_number)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user