tools: gpio: port lsgpio to v2 uAPI
Port the lsgpio tool to the latest GPIO uAPI. Signed-off-by: Kent Gibson <warthog618@gmail.com> Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com> Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
This commit is contained in:
parent
b234d233fe
commit
3c333c4704
|
@ -25,57 +25,73 @@
|
|||
|
||||
struct gpio_flag {
|
||||
char *name;
|
||||
unsigned long mask;
|
||||
unsigned long long mask;
|
||||
};
|
||||
|
||||
struct gpio_flag flagnames[] = {
|
||||
{
|
||||
.name = "kernel",
|
||||
.mask = GPIOLINE_FLAG_KERNEL,
|
||||
.name = "used",
|
||||
.mask = GPIO_V2_LINE_FLAG_USED,
|
||||
},
|
||||
{
|
||||
.name = "input",
|
||||
.mask = GPIO_V2_LINE_FLAG_INPUT,
|
||||
},
|
||||
{
|
||||
.name = "output",
|
||||
.mask = GPIOLINE_FLAG_IS_OUT,
|
||||
.mask = GPIO_V2_LINE_FLAG_OUTPUT,
|
||||
},
|
||||
{
|
||||
.name = "active-low",
|
||||
.mask = GPIOLINE_FLAG_ACTIVE_LOW,
|
||||
.mask = GPIO_V2_LINE_FLAG_ACTIVE_LOW,
|
||||
},
|
||||
{
|
||||
.name = "open-drain",
|
||||
.mask = GPIOLINE_FLAG_OPEN_DRAIN,
|
||||
.mask = GPIO_V2_LINE_FLAG_OPEN_DRAIN,
|
||||
},
|
||||
{
|
||||
.name = "open-source",
|
||||
.mask = GPIOLINE_FLAG_OPEN_SOURCE,
|
||||
.mask = GPIO_V2_LINE_FLAG_OPEN_SOURCE,
|
||||
},
|
||||
{
|
||||
.name = "pull-up",
|
||||
.mask = GPIOLINE_FLAG_BIAS_PULL_UP,
|
||||
.mask = GPIO_V2_LINE_FLAG_BIAS_PULL_UP,
|
||||
},
|
||||
{
|
||||
.name = "pull-down",
|
||||
.mask = GPIOLINE_FLAG_BIAS_PULL_DOWN,
|
||||
.mask = GPIO_V2_LINE_FLAG_BIAS_PULL_DOWN,
|
||||
},
|
||||
{
|
||||
.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 printed = 0;
|
||||
const char *field_format = "%s";
|
||||
|
||||
for (i = 0; i < ARRAY_SIZE(flagnames); i++) {
|
||||
if (flags & flagnames[i].mask) {
|
||||
if (printed)
|
||||
fprintf(stdout, " ");
|
||||
fprintf(stdout, "%s", flagnames[i].name);
|
||||
printed++;
|
||||
if (info->flags & flagnames[i].mask) {
|
||||
fprintf(stdout, field_format, flagnames[i].name);
|
||||
field_format = ", %s";
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
|
@ -109,18 +125,18 @@ int list_device(const char *device_name)
|
|||
|
||||
/* Loop over the lines and print info */
|
||||
for (i = 0; i < cinfo.lines; i++) {
|
||||
struct gpioline_info linfo;
|
||||
struct gpio_v2_line_info 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) {
|
||||
ret = -errno;
|
||||
perror("Failed to issue LINEINFO IOCTL\n");
|
||||
goto exit_close_error;
|
||||
}
|
||||
fprintf(stdout, "\tline %2d:", linfo.line_offset);
|
||||
fprintf(stdout, "\tline %2d:", linfo.offset);
|
||||
if (linfo.name[0])
|
||||
fprintf(stdout, " \"%s\"", linfo.name);
|
||||
else
|
||||
|
@ -131,7 +147,7 @@ int list_device(const char *device_name)
|
|||
fprintf(stdout, " unused");
|
||||
if (linfo.flags) {
|
||||
fprintf(stdout, " [");
|
||||
print_flags(linfo.flags);
|
||||
print_attributes(&linfo);
|
||||
fprintf(stdout, "]");
|
||||
}
|
||||
fprintf(stdout, "\n");
|
||||
|
|
Loading…
Reference in New Issue