Linux-GPIO Archive on lore.kernel.org
 help / color / Atom feed
From: Kent Gibson <warthog618@gmail.com>
To: linux-kernel@vger.kernel.org, linux-gpio@vger.kernel.org,
	bgolaszewski@baylibre.com, linus.walleij@linaro.org
Cc: Kent Gibson <warthog618@gmail.com>
Subject: [PATCH v2 12/18] tools: gpio: port lsgpio to v2 uAPI
Date: Sat, 25 Jul 2020 12:19:49 +0800
Message-ID: <20200725041955.9985-13-warthog618@gmail.com> (raw)
In-Reply-To: <20200725041955.9985-1-warthog618@gmail.com>

Port the lsgpio tool to the latest GPIO uAPI.

Signed-off-by: Kent Gibson <warthog618@gmail.com>
---
 tools/gpio/lsgpio.c | 102 ++++++++++++++++++++------------------------
 1 file changed, 47 insertions(+), 55 deletions(-)

diff --git a/tools/gpio/lsgpio.c b/tools/gpio/lsgpio.c
index b08d7a5e779b..0a993d535707 100644
--- a/tools/gpio/lsgpio.c
+++ b/tools/gpio/lsgpio.c
@@ -23,58 +23,50 @@
 
 #include "gpio-utils.h"
 
-struct gpio_flag {
-	char *name;
-	unsigned long mask;
-};
-
-struct gpio_flag flagnames[] = {
-	{
-		.name = "kernel",
-		.mask = GPIOLINE_FLAG_KERNEL,
-	},
-	{
-		.name = "output",
-		.mask = GPIOLINE_FLAG_IS_OUT,
-	},
-	{
-		.name = "active-low",
-		.mask = GPIOLINE_FLAG_ACTIVE_LOW,
-	},
-	{
-		.name = "open-drain",
-		.mask = GPIOLINE_FLAG_OPEN_DRAIN,
-	},
-	{
-		.name = "open-source",
-		.mask = GPIOLINE_FLAG_OPEN_SOURCE,
-	},
-	{
-		.name = "pull-up",
-		.mask = GPIOLINE_FLAG_BIAS_PULL_UP,
-	},
-	{
-		.name = "pull-down",
-		.mask = GPIOLINE_FLAG_BIAS_PULL_DOWN,
-	},
-	{
-		.name = "bias-disabled",
-		.mask = GPIOLINE_FLAG_BIAS_DISABLE,
-	},
-};
-
-void print_flags(unsigned long flags)
+static void print_attributes(struct gpioline_info_v2 *info)
 {
 	int i;
-	int printed = 0;
-
-	for (i = 0; i < ARRAY_SIZE(flagnames); i++) {
-		if (flags & flagnames[i].mask) {
-			if (printed)
-				fprintf(stdout, " ");
-			fprintf(stdout, "%s", flagnames[i].name);
-			printed++;
-		}
+	const char *field_format = "%s";
+
+	if (info->flags & GPIOLINE_FLAG_V2_USED) {
+		fprintf(stdout, field_format, "used");
+		field_format = ", %s";
+	}
+
+	if (info->flags & GPIOLINE_FLAG_V2_OUTPUT)
+		fprintf(stdout, field_format, "output");
+	else
+		fprintf(stdout, field_format, "input");
+
+	field_format = ", %s";
+
+	if (info->flags & GPIOLINE_FLAG_V2_ACTIVE_LOW)
+		fprintf(stdout, field_format, "active-low");
+
+	if (info->flags & GPIOLINE_FLAG_V2_OPEN_DRAIN)
+		fprintf(stdout, field_format, "open-drain");
+	if (info->flags & GPIOLINE_FLAG_V2_OPEN_SOURCE)
+		fprintf(stdout, field_format, "open-source");
+
+	if (info->flags & GPIOLINE_FLAG_V2_BIAS_DISABLED)
+		fprintf(stdout, field_format, "bias-disabled");
+	if (info->flags == GPIOLINE_FLAG_V2_BIAS_PULL_UP)
+		fprintf(stdout, field_format, "pull-up");
+	if (info->flags == GPIOLINE_FLAG_V2_BIAS_PULL_DOWN)
+		fprintf(stdout, field_format, "pull-down");
+
+	if ((info->flags & GPIOLINE_FLAG_V2_EDGE_RISING) &&
+	    (info->flags & GPIOLINE_FLAG_V2_EDGE_FALLING))
+		fprintf(stdout, field_format, "both-edges");
+	else if (info->flags & GPIOLINE_FLAG_V2_EDGE_RISING)
+		fprintf(stdout, field_format, "rising-edge");
+	else if (info->flags & GPIOLINE_FLAG_V2_EDGE_FALLING)
+		fprintf(stdout, field_format, "falling-edge");
+
+	for (i = 0; i < info->num_attrs; i++) {
+		if (info->attrs[i].id == GPIOLINE_ATTR_ID_DEBOUNCE)
+			fprintf(stdout, ", debounce_period=%dusec",
+				info->attrs[0].debounce_period);
 	}
 }
 
@@ -109,18 +101,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 gpioline_info_v2 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_GET_LINEINFO_V2_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 +123,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");
-- 
2.27.0


  parent reply index

Thread overview: 46+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-25  4:19 [PATCH v2 00/18] gpio: cdev: add uAPI V2 Kent Gibson
2020-07-25  4:19 ` [PATCH v2 01/18] gpio: uapi: define GPIO_MAX_NAME_SIZE for array sizes Kent Gibson
2020-07-25  4:19 ` [PATCH v2 02/18] gpio: uapi: define uAPI v2 Kent Gibson
2020-08-04 17:42   ` Bartosz Golaszewski
2020-08-05  5:18     ` Kent Gibson
2020-08-05 17:47       ` Bartosz Golaszewski
2020-08-06  1:03         ` Kent Gibson
2020-08-06  1:15       ` Kent Gibson
2020-08-06 15:53         ` Bartosz Golaszewski
2020-07-25  4:19 ` [PATCH v2 03/18] gpiolib: make cdev a build option Kent Gibson
2020-07-25 20:29   ` Andy Shevchenko
2020-07-26 22:25   ` Linus Walleij
2020-07-27  1:46     ` Kent Gibson
2020-07-27  5:57       ` Kent Gibson
2020-07-27  8:15         ` Linus Walleij
2020-07-25  4:19 ` [PATCH v2 04/18] gpiolib: add build option for CDEV v1 ABI Kent Gibson
2020-07-25  4:19 ` [PATCH v2 05/18] gpiolib: cdev: support GPIO_GET_LINE_IOCTL and GPIOLINE_GET_VALUES_IOCTL Kent Gibson
2020-07-25 20:51   ` Andy Shevchenko
2020-07-26  1:12     ` Kent Gibson
2020-07-26  3:24       ` Kent Gibson
2020-07-29  2:28       ` Kent Gibson
2020-07-29  8:05         ` Andy Shevchenko
2020-07-29 10:01           ` Kent Gibson
2020-07-31 16:05       ` Bartosz Golaszewski
2020-08-02  3:31         ` Kent Gibson
2020-08-02  9:32           ` Kent Gibson
2020-08-03 19:59             ` Bartosz Golaszewski
2020-08-03 20:02           ` Bartosz Golaszewski
2020-08-03 23:01             ` Kent Gibson
2020-08-04 17:47               ` Bartosz Golaszewski
2020-08-05  3:06                 ` Kent Gibson
2020-07-25  4:19 ` [PATCH v2 06/18] gpiolib: cdev: support GPIO_GET_LINEINFO_V2_IOCTL and GPIO_GET_LINEINFO_WATCH_V2_IOCTL Kent Gibson
2020-07-25  4:19 ` [PATCH v2 07/18] gpiolib: cdev: support edge detection for uAPI v2 Kent Gibson
2020-08-04 19:28   ` Bartosz Golaszewski
2020-07-25  4:19 ` [PATCH v2 08/18] gpiolib: cdev: support GPIOLINE_SET_CONFIG_IOCTL Kent Gibson
2020-07-25  4:19 ` [PATCH v2 09/18] gpiolib: cdev: support GPIOLINE_SET_VALUES_IOCTL Kent Gibson
2020-07-25  4:19 ` [PATCH v2 10/18] gpiolib: cdev: support setting debounce Kent Gibson
2020-07-25  4:19 ` [PATCH v2 11/18] gpio: uapi: document uAPI v1 as deprecated Kent Gibson
2020-08-04 19:43   ` Bartosz Golaszewski
2020-07-25  4:19 ` Kent Gibson [this message]
2020-07-25  4:19 ` [PATCH v2 13/18] tools: gpio: port gpio-watch to v2 uAPI Kent Gibson
2020-07-25  4:19 ` [PATCH v2 14/18] tools: gpio: rename nlines to num_lines Kent Gibson
2020-07-25  4:19 ` [PATCH v2 15/18] tools: gpio: port gpio-hammer to v2 uAPI Kent Gibson
2020-07-25  4:19 ` [PATCH v2 16/18] tools: gpio: port gpio-event-mon " Kent Gibson
2020-07-25  4:19 ` [PATCH v2 17/18] tools: gpio: add debounce support to gpio-event-mon Kent Gibson
2020-07-25  4:19 ` [PATCH v2 18/18] tools: gpio: add multi-line monitoring " Kent Gibson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200725041955.9985-13-warthog618@gmail.com \
    --to=warthog618@gmail.com \
    --cc=bgolaszewski@baylibre.com \
    --cc=linus.walleij@linaro.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Linux-GPIO Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-gpio/0 linux-gpio/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-gpio linux-gpio/ https://lore.kernel.org/linux-gpio \
		linux-gpio@vger.kernel.org
	public-inbox-index linux-gpio

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-gpio


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git