Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.sbin/gpioctl gpioctl: implement support for "gpioctl gpi...
details: https://anonhg.NetBSD.org/src/rev/97d85e74381f
branches: trunk
changeset: 460381:97d85e74381f
user: tnn <tnn%NetBSD.org@localhost>
date: Sun Oct 20 09:41:53 2019 +0000
description:
gpioctl: implement support for "gpioctl gpioN list". Like pcictl(8).
For drivers that name their pins, this can be used to determine how the
logical pins are mapped to physical pins. Example from sunxigpio(4):
# gpioctl gpio0 list
0: PA0
1: PA1
2: PA2
...
diffstat:
usr.sbin/gpioctl/gpioctl.8 | 12 ++++++++++--
usr.sbin/gpioctl/gpioctl.c | 29 +++++++++++++++++++++++++++--
2 files changed, 37 insertions(+), 4 deletions(-)
diffs (111 lines):
diff -r 06c18fbb9b74 -r 97d85e74381f usr.sbin/gpioctl/gpioctl.8
--- a/usr.sbin/gpioctl/gpioctl.8 Sun Oct 20 09:35:18 2019 +0000
+++ b/usr.sbin/gpioctl/gpioctl.8 Sun Oct 20 09:41:53 2019 +0000
@@ -1,4 +1,4 @@
-.\" $NetBSD: gpioctl.8,v 1.22 2019/02/13 11:40:41 wiz Exp $
+.\" $NetBSD: gpioctl.8,v 1.23 2019/10/20 09:41:53 tnn Exp $
.\"
.\" Copyright (c) 2009, 2010, 2011, 2013 Marc Balmer <marc%msys.ch@localhost>
.\" Copyright (c) 2004 Alexander Yurchenko <grange%openbsd.org@localhost>
@@ -15,7 +15,7 @@
.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
.\"
-.Dd February 12, 2019
+.Dd October 20, 2019
.Dt GPIOCTL 8
.Os
.Sh NAME
@@ -55,6 +55,10 @@
.Ar device
.Ar pin
.Cm unset
+.Nm gpioctl
+.Op Fl q
+.Ar device
+.Ar list
.Sh DESCRIPTION
The
.Nm
@@ -203,6 +207,10 @@
Toggle the error_led:
.Pp
.Dl # gpioctl gpio0 error_led 2
+.Pp
+Enumerate all pins and display their symbolic names:
+.Pp
+.Dl # gpioctl gpio0 list
.Sh SEE ALSO
.Xr gpio 4 ,
.Xr drvctl 8
diff -r 06c18fbb9b74 -r 97d85e74381f usr.sbin/gpioctl/gpioctl.c
--- a/usr.sbin/gpioctl/gpioctl.c Sun Oct 20 09:35:18 2019 +0000
+++ b/usr.sbin/gpioctl/gpioctl.c Sun Oct 20 09:41:53 2019 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: gpioctl.c,v 1.26 2019/01/27 02:08:51 pgoyette Exp $ */
+/* $NetBSD: gpioctl.c,v 1.27 2019/10/20 09:41:53 tnn Exp $ */
/*
* Copyright (c) 2008, 2010, 2011, 2013 Marc Balmer <mbalmer%NetBSD.org@localhost>
@@ -17,7 +17,7 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include <sys/cdefs.h>
-__RCSID("$NetBSD: gpioctl.c,v 1.26 2019/01/27 02:08:51 pgoyette Exp $");
+__RCSID("$NetBSD: gpioctl.c,v 1.27 2019/10/20 09:41:53 tnn Exp $");
/*
* Program to control GPIO devices.
@@ -48,6 +48,7 @@
static void gpiowrite(int, char *, int);
static void gpioset(int pin, char *name, int flags, char *alias);
static void gpiounset(int pin, char *name);
+static void gpiolist(void);
static void devattach(char *, int, uint32_t, uint32_t);
__dead static void usage(void);
@@ -160,6 +161,9 @@
}
devattach(driver, ga_offset, ga_mask, ga_flags);
return EXIT_SUCCESS;
+ } else if (!strcmp(argv[1], "list")) {
+ gpiolist();
+ return EXIT_SUCCESS;
} else {
char *nm = NULL;
@@ -345,6 +349,26 @@
}
static void
+gpiolist()
+{
+ struct gpio_info info;
+ struct gpio_req req;
+ int i;
+
+ if (ioctl(devfd, GPIOINFO, &info) == -1)
+ err(EXIT_FAILURE, "GPIOINFO");
+
+ for (i = 0; i < info.gpio_npins; i++) {
+ memset(&req, 0, sizeof(req));
+ req.gp_pin = i;
+ if (ioctl(devfd, GPIOREAD, &req) == -1)
+ err(EXIT_FAILURE, "GPIOREAD");
+ if (!quiet)
+ printf("%d: %s\n", i, req.gp_name);
+ }
+}
+
+static void
devattach(char *dvname, int offset, uint32_t mask, uint32_t flags)
{
struct gpio_attach attach;
@@ -372,6 +396,7 @@
fprintf(stderr, " %s [-q] device attach device offset mask "
"[flag]\n",
progname);
+ fprintf(stderr, " %s [-q] device list\n", progname);
exit(EXIT_FAILURE);
}
Home |
Main Index |
Thread Index |
Old Index