Module Name: src Committed By: tnn Date: Sun Oct 20 09:41:53 UTC 2019
Modified Files: src/usr.sbin/gpioctl: gpioctl.8 gpioctl.c Log Message: 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 ... To generate a diff of this commit: cvs rdiff -u -r1.22 -r1.23 src/usr.sbin/gpioctl/gpioctl.8 cvs rdiff -u -r1.26 -r1.27 src/usr.sbin/gpioctl/gpioctl.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/usr.sbin/gpioctl/gpioctl.8 diff -u src/usr.sbin/gpioctl/gpioctl.8:1.22 src/usr.sbin/gpioctl/gpioctl.8:1.23 --- src/usr.sbin/gpioctl/gpioctl.8:1.22 Wed Feb 13 11:40:41 2019 +++ src/usr.sbin/gpioctl/gpioctl.8 Sun Oct 20 09:41:53 2019 @@ -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 <m...@msys.ch> .\" Copyright (c) 2004 Alexander Yurchenko <gra...@openbsd.org> @@ -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 @@ Configure pin 5 as output and name it er 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 Index: src/usr.sbin/gpioctl/gpioctl.c diff -u src/usr.sbin/gpioctl/gpioctl.c:1.26 src/usr.sbin/gpioctl/gpioctl.c:1.27 --- src/usr.sbin/gpioctl/gpioctl.c:1.26 Sun Jan 27 02:08:51 2019 +++ src/usr.sbin/gpioctl/gpioctl.c Sun Oct 20 09:41:53 2019 @@ -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 <mbal...@netbsd.org> @@ -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 gpioread(int, char *); 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 @@ main(int argc, char *argv[]) } 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 @@ gpiounset(int pin, char *name) } 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 @@ usage(void) fprintf(stderr, " %s [-q] device attach device offset mask " "[flag]\n", progname); + fprintf(stderr, " %s [-q] device list\n", progname); exit(EXIT_FAILURE); }