aboutsummaryrefslogtreecommitdiff
path: root/usr.sbin
diff options
context:
space:
mode:
authorLuiz Otavio O Souza <loos@FreeBSD.org>2015-03-08 00:47:50 +0000
committerLuiz Otavio O Souza <loos@FreeBSD.org>2015-03-08 00:47:50 +0000
commitd752f0f69de80ecb93e4d64e8353218edbdbdccf (patch)
tree9ddab736a8f0c968e0fae8da4325fc5853cdb54d /usr.sbin
parentbf5d6cf0a970449cac82786a0dbd6c7e31adb181 (diff)
downloadsrc-d752f0f69de80ecb93e4d64e8353218edbdbdccf.tar.gz
src-d752f0f69de80ecb93e4d64e8353218edbdbdccf.zip
Add a new ioctl to allow the setting of GPIO pin names.
When a gpiobus child is added, use its name to identify the mapped pin names. Make the respective changes to libgpio. Add a new '-n' flag to gpioctl(8) to set the pin name. Differential Revision: https://reviews.freebsd.org/D2002 Reviewed by: rpaulo Requested by: many
Notes
Notes: svn path=/head/; revision=279761
Diffstat (limited to 'usr.sbin')
-rw-r--r--usr.sbin/gpioctl/gpioctl.815
-rw-r--r--usr.sbin/gpioctl/gpioctl.c26
2 files changed, 34 insertions, 7 deletions
diff --git a/usr.sbin/gpioctl/gpioctl.8 b/usr.sbin/gpioctl/gpioctl.8
index a0bf6536f8f3..31fb36f8d06f 100644
--- a/usr.sbin/gpioctl/gpioctl.8
+++ b/usr.sbin/gpioctl/gpioctl.8
@@ -27,7 +27,7 @@
.\"
.\" $FreeBSD$
.\"
-.Dd November 7, 2013
+.Dd March 7, 2015
.Dt GPIOCTL 1
.Os
.Sh NAME
@@ -35,20 +35,25 @@
.Nd GPIO control utility
.Sh SYNOPSIS
.Nm
-.Cm -l
.Op Fl f Ar ctldev
+.Cm -l
.Op Fl v
.Nm
-.Cm -t
.Op Fl f Ar ctldev
+.Cm -t
.Ar pin
.Nm
-.Cm -c
.Op Fl f Ar ctldev
+.Cm -c
.Ar pin
.Ar flag
.Op flag ...
.Nm
+.Op Fl f Ar ctldev
+.Cm -n
+.Ar pin
+.Ar pin-name
+.Nm
.Op Cm -f Ar ctldev
.Ar pin
.Ar [0|1]
@@ -87,6 +92,8 @@ If not specified, defaults to
.Pa /dev/gpioc0
.It Fl l
list available pins
+.It Fl n Ar pin Ar pin-name
+set the name used to describe the pin
.It Fl t Ar pin
toggle value of provided pin number
.It Fl v
diff --git a/usr.sbin/gpioctl/gpioctl.c b/usr.sbin/gpioctl/gpioctl.c
index 37f84fa16b90..38e53e7f2fee 100644
--- a/usr.sbin/gpioctl/gpioctl.c
+++ b/usr.sbin/gpioctl/gpioctl.c
@@ -68,6 +68,7 @@ usage(void)
fprintf(stderr, "\tgpioctl [-f ctldev] -l [-v]\n");
fprintf(stderr, "\tgpioctl [-f ctldev] -t pin\n");
fprintf(stderr, "\tgpioctl [-f ctldev] -c pin flag ...\n");
+ fprintf(stderr, "\tgpioctl [-f ctldev] -n pin pin-name\n");
fprintf(stderr, "\tgpioctl [-f ctldev] pin [0|1]\n");
exit(1);
}
@@ -182,11 +183,11 @@ main(int argc, char **argv)
char *ctlfile = NULL;
int pinn, pinv, ch;
int flags, flag, ok;
- int config, toggle, verbose, list;
+ int config, list, name, toggle, verbose;
- config = toggle = verbose = list = pinn = 0;
+ config = toggle = verbose = list = name = pinn = 0;
- while ((ch = getopt(argc, argv, "c:f:lt:v")) != -1) {
+ while ((ch = getopt(argc, argv, "c:f:ln:t:v")) != -1) {
switch (ch) {
case 'c':
config = 1;
@@ -200,6 +201,12 @@ main(int argc, char **argv)
case 'l':
list = 1;
break;
+ case 'n':
+ name = 1;
+ pinn = str2int(optarg, &ok);
+ if (!ok)
+ fail("Invalid pin number: %s\n", optarg);
+ break;
case 't':
toggle = 1;
pinn = str2int(optarg, &ok);
@@ -225,6 +232,19 @@ main(int argc, char **argv)
exit(1);
}
+ /* Set the pin name. */
+ if (name) {
+ if (argc == 0) {
+ usage();
+ exit(1);
+ }
+ if (gpio_pin_set_name(handle, pinn, argv[0]) < 0) {
+ perror("gpio_pin_set_name");
+ exit(1);
+ }
+ exit(0);
+ }
+
if (list) {
dump_pins(handle, verbose);
gpio_close(handle);