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 ...
This commit is contained in:
parent
9a3d6b2058
commit
bbae070d2b
@ -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>
|
||||
.\" Copyright (c) 2004 Alexander Yurchenko <grange@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 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
|
||||
|
@ -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>
|
||||
@ -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;
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user