Commit 3c333c47 authored by Kent Gibson's avatar Kent Gibson Committed by Bartosz Golaszewski

tools: gpio: port lsgpio to v2 uAPI

Port the lsgpio tool to the latest GPIO uAPI.
Signed-off-by: default avatarKent Gibson <warthog618@gmail.com>
Reviewed-by: default avatarAndy Shevchenko <andy.shevchenko@gmail.com>
Signed-off-by: default avatarBartosz Golaszewski <bgolaszewski@baylibre.com>
parent b234d233
...@@ -25,57 +25,73 @@ ...@@ -25,57 +25,73 @@
struct gpio_flag { struct gpio_flag {
char *name; char *name;
unsigned long mask; unsigned long long mask;
}; };
struct gpio_flag flagnames[] = { struct gpio_flag flagnames[] = {
{ {
.name = "kernel", .name = "used",
.mask = GPIOLINE_FLAG_KERNEL, .mask = GPIO_V2_LINE_FLAG_USED,
},
{
.name = "input",
.mask = GPIO_V2_LINE_FLAG_INPUT,
}, },
{ {
.name = "output", .name = "output",
.mask = GPIOLINE_FLAG_IS_OUT, .mask = GPIO_V2_LINE_FLAG_OUTPUT,
}, },
{ {
.name = "active-low", .name = "active-low",
.mask = GPIOLINE_FLAG_ACTIVE_LOW, .mask = GPIO_V2_LINE_FLAG_ACTIVE_LOW,
}, },
{ {
.name = "open-drain", .name = "open-drain",
.mask = GPIOLINE_FLAG_OPEN_DRAIN, .mask = GPIO_V2_LINE_FLAG_OPEN_DRAIN,
}, },
{ {
.name = "open-source", .name = "open-source",
.mask = GPIOLINE_FLAG_OPEN_SOURCE, .mask = GPIO_V2_LINE_FLAG_OPEN_SOURCE,
}, },
{ {
.name = "pull-up", .name = "pull-up",
.mask = GPIOLINE_FLAG_BIAS_PULL_UP, .mask = GPIO_V2_LINE_FLAG_BIAS_PULL_UP,
}, },
{ {
.name = "pull-down", .name = "pull-down",
.mask = GPIOLINE_FLAG_BIAS_PULL_DOWN, .mask = GPIO_V2_LINE_FLAG_BIAS_PULL_DOWN,
}, },
{ {
.name = "bias-disabled", .name = "bias-disabled",
.mask = GPIOLINE_FLAG_BIAS_DISABLE, .mask = GPIO_V2_LINE_FLAG_BIAS_DISABLED,
}, },
}; };
void print_flags(unsigned long flags) static void print_attributes(struct gpio_v2_line_info *info)
{ {
int i; int i;
int printed = 0; const char *field_format = "%s";
for (i = 0; i < ARRAY_SIZE(flagnames); i++) { for (i = 0; i < ARRAY_SIZE(flagnames); i++) {
if (flags & flagnames[i].mask) { if (info->flags & flagnames[i].mask) {
if (printed) fprintf(stdout, field_format, flagnames[i].name);
fprintf(stdout, " "); field_format = ", %s";
fprintf(stdout, "%s", flagnames[i].name);
printed++;
} }
} }
if ((info->flags & GPIO_V2_LINE_FLAG_EDGE_RISING) &&
(info->flags & GPIO_V2_LINE_FLAG_EDGE_FALLING))
fprintf(stdout, field_format, "both-edges");
else if (info->flags & GPIO_V2_LINE_FLAG_EDGE_RISING)
fprintf(stdout, field_format, "rising-edge");
else if (info->flags & GPIO_V2_LINE_FLAG_EDGE_FALLING)
fprintf(stdout, field_format, "falling-edge");
for (i = 0; i < info->num_attrs; i++) {
if (info->attrs[i].id == GPIO_V2_LINE_ATTR_ID_DEBOUNCE)
fprintf(stdout, ", debounce_period=%dusec",
info->attrs[0].debounce_period_us);
}
} }
int list_device(const char *device_name) int list_device(const char *device_name)
...@@ -109,18 +125,18 @@ int list_device(const char *device_name) ...@@ -109,18 +125,18 @@ int list_device(const char *device_name)
/* Loop over the lines and print info */ /* Loop over the lines and print info */
for (i = 0; i < cinfo.lines; i++) { for (i = 0; i < cinfo.lines; i++) {
struct gpioline_info linfo; struct gpio_v2_line_info linfo;
memset(&linfo, 0, sizeof(linfo)); memset(&linfo, 0, sizeof(linfo));
linfo.line_offset = i; linfo.offset = i;
ret = ioctl(fd, GPIO_GET_LINEINFO_IOCTL, &linfo); ret = ioctl(fd, GPIO_V2_GET_LINEINFO_IOCTL, &linfo);
if (ret == -1) { if (ret == -1) {
ret = -errno; ret = -errno;
perror("Failed to issue LINEINFO IOCTL\n"); perror("Failed to issue LINEINFO IOCTL\n");
goto exit_close_error; goto exit_close_error;
} }
fprintf(stdout, "\tline %2d:", linfo.line_offset); fprintf(stdout, "\tline %2d:", linfo.offset);
if (linfo.name[0]) if (linfo.name[0])
fprintf(stdout, " \"%s\"", linfo.name); fprintf(stdout, " \"%s\"", linfo.name);
else else
...@@ -131,7 +147,7 @@ int list_device(const char *device_name) ...@@ -131,7 +147,7 @@ int list_device(const char *device_name)
fprintf(stdout, " unused"); fprintf(stdout, " unused");
if (linfo.flags) { if (linfo.flags) {
fprintf(stdout, " ["); fprintf(stdout, " [");
print_flags(linfo.flags); print_attributes(&linfo);
fprintf(stdout, "]"); fprintf(stdout, "]");
} }
fprintf(stdout, "\n"); fprintf(stdout, "\n");
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment