gpioinfo: print bias flags if set
authorBartosz Golaszewski <bgolaszewski@baylibre.com>
Wed, 29 Apr 2020 12:38:23 +0000 (14:38 +0200)
committerBartosz Golaszewski <bgolaszewski@baylibre.com>
Mon, 4 May 2020 10:35:23 +0000 (12:35 +0200)
When printing line information: check the bias configuration and include
the current value in the 'flags' column of output.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
tools/gpioinfo.c

index 6f94b4eb16e3a5519b66bcfa7136ddc09d9ad2b7..67be379505217697b0f7e0c182dcd8b3c768ea15 100644 (file)
@@ -21,6 +21,21 @@ struct flag {
        is_set_func is_set;
 };
 
+static bool line_bias_is_pullup(struct gpiod_line *line)
+{
+       return gpiod_line_bias(line) == GPIOD_LINE_BIAS_PULL_UP;
+}
+
+static bool line_bias_is_pulldown(struct gpiod_line *line)
+{
+       return gpiod_line_bias(line) == GPIOD_LINE_BIAS_PULL_DOWN;
+}
+
+static bool line_bias_is_disabled(struct gpiod_line *line)
+{
+       return gpiod_line_bias(line) == GPIOD_LINE_BIAS_DISABLE;
+}
+
 static const struct flag flags[] = {
        {
                .name = "used",
@@ -34,6 +49,18 @@ static const struct flag flags[] = {
                .name = "open-source",
                .is_set = gpiod_line_is_open_source,
        },
+       {
+               .name = "pull-up",
+               .is_set = line_bias_is_pullup,
+       },
+       {
+               .name = "pull-down",
+               .is_set = line_bias_is_pulldown,
+       },
+       {
+               .name = "bias-disabled",
+               .is_set = line_bias_is_disabled,
+       },
 };
 
 static const struct option longopts[] = {