diff --git a/usr.sbin/gpioctl/gpioctl.8 b/usr.sbin/gpioctl/gpioctl.8 index a5fcbf9ccf76..3a9cb01823b0 100644 --- a/usr.sbin/gpioctl/gpioctl.8 +++ b/usr.sbin/gpioctl/gpioctl.8 @@ -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 .\" Copyright (c) 2004 Alexander Yurchenko @@ -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 error_led: 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 --git a/usr.sbin/gpioctl/gpioctl.c b/usr.sbin/gpioctl/gpioctl.c index 40eae03dcfb9..26c0f1000280 100644 --- a/usr.sbin/gpioctl/gpioctl.c +++ b/usr.sbin/gpioctl/gpioctl.c @@ -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 @@ -17,7 +17,7 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ #include -__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; @@ -344,6 +348,26 @@ gpiounset(int pin, char *name) err(EXIT_FAILURE, "GPIOUNSET"); } +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) { @@ -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); }