xref: /openbsd-src/usr.sbin/gpioctl/gpioctl.8 (revision 4eb03a882dd3a5fe34b395c63c603d43afe2776c)
1*4eb03a88Sjmc.\"	$OpenBSD: gpioctl.8,v 1.25 2018/03/12 12:52:14 jmc Exp $
248e05255Sgrange.\"
348e05255Sgrange.\" Copyright (c) 2004 Alexander Yurchenko <grange@openbsd.org>
448e05255Sgrange.\"
548e05255Sgrange.\" Permission to use, copy, modify, and distribute this software for any
648e05255Sgrange.\" purpose with or without fee is hereby granted, provided that the above
748e05255Sgrange.\" copyright notice and this permission notice appear in all copies.
848e05255Sgrange.\"
948e05255Sgrange.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
1048e05255Sgrange.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
1148e05255Sgrange.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
1248e05255Sgrange.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
1348e05255Sgrange.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
1448e05255Sgrange.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
1548e05255Sgrange.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
1648e05255Sgrange.\"
17*4eb03a88Sjmc.Dd $Mdocdate: March 12 2018 $
1848e05255Sgrange.Dt GPIOCTL 8
1948e05255Sgrange.Os
2048e05255Sgrange.Sh NAME
2148e05255Sgrange.Nm gpioctl
2248e05255Sgrange.Nd control GPIO devices
2348e05255Sgrange.Sh SYNOPSIS
2448e05255Sgrange.Nm gpioctl
252a642902Sderaadt.Op Fl q
262e6ed72bSmbalmer.Ar device
273af2d23dSjmc.Ar pin
281bcf4e9fSschwarze.Op Cm 0 | 1 | 2 | on | off | toggle
293af2d23dSjmc.Nm gpioctl
303af2d23dSjmc.Op Fl q
313af2d23dSjmc.Ar device
323af2d23dSjmc.Ar pin
331bcf4e9fSschwarze.Cm set
343af2d23dSjmc.Op Ar flags
353af2d23dSjmc.Op Ar name
363af2d23dSjmc.Nm gpioctl
373af2d23dSjmc.Op Fl q
383af2d23dSjmc.Ar device
393af2d23dSjmc.Ar pin
401bcf4e9fSschwarze.Cm unset
413af2d23dSjmc.Nm gpioctl
423af2d23dSjmc.Op Fl q
433af2d23dSjmc.Ar device
441bcf4e9fSschwarze.Cm attach
452e6ed72bSmbalmer.Ar device
462e6ed72bSmbalmer.Ar offset
472e6ed72bSmbalmer.Ar mask
487d434456Smatthieu.Op Ar flag
492e6ed72bSmbalmer.Nm gpioctl
502e6ed72bSmbalmer.Op Fl q
512e6ed72bSmbalmer.Ar device
521bcf4e9fSschwarze.Cm detach
532e6ed72bSmbalmer.Ar device
5448e05255Sgrange.Sh DESCRIPTION
5548e05255SgrangeThe
5648e05255Sgrange.Nm
57212d975fSjmcprogram allows manipulation of GPIO
5853046763Sjmc(General Purpose Input/Output) device pins.
59212d975fSjmcSuch devices can be either part of the chipset or embedded CPU,
6053046763Sjmcor a separate chip.
61212d975fSjmcThe usual way of using GPIO
62212d975fSjmcis to connect some simple devices such as LEDs and 1-wire thermal sensors
63212d975fSjmcto its pins.
6448e05255Sgrange.Pp
65212d975fSjmcEach GPIO device has an associated device file in the
6648e05255Sgrange.Pa /dev
6748e05255Sgrangedirectory.
68098d1fb7Sstevesk.Ar device
69098d1fb7Ssteveskcan be specified with or without the
70098d1fb7Sstevesk.Pa /dev
71098d1fb7Ssteveskprefix.
72098d1fb7SsteveskFor example,
73098d1fb7Sstevesk.Pa /dev/gpio0
74098d1fb7Ssteveskor
75098d1fb7Sstevesk.Pa gpio0 .
7648e05255Sgrange.Pp
77212d975fSjmcGPIO pins can be either
7853046763Sjmc.Dq read
7953046763Sjmcor
8053046763Sjmc.Dq written
8153046763Sjmcwith the values of logical 0 or 1.
8253046763SjmcIf only a
8348e05255Sgrange.Ar pin
8453046763Sjmcnumber is specified on the command line, the pin state will be read
85212d975fSjmcfrom the GPIO controller and displayed.
8653046763SjmcTo write to a pin, a value must be specified after the
8748e05255Sgrange.Ar pin
8848e05255Sgrangenumber.
891bcf4e9fSschwarzeValues can be either
901bcf4e9fSschwarze.Cm 0
911bcf4e9fSschwarzeor
921bcf4e9fSschwarze.Cm 1 .
931bcf4e9fSschwarzeA value of
941bcf4e9fSschwarze.Cm 2
951bcf4e9fSschwarzehas a special meaning: it
9653046763Sjmc.Dq toggles
9753046763Sjmcthe pin, i.e. changes its state to the opposite.
9829712188SmbalmerInstead of the numerical values, the word
991bcf4e9fSschwarze.Cm on ,
1001bcf4e9fSschwarze.Cm off ,
10129712188Smbalmeror
1021bcf4e9fSschwarze.Cm toggle
10329712188Smbalmercan be used.
10448e05255Sgrange.Pp
1052e6ed72bSmbalmerOnly pins that have been configured at securelevel 0, typically during system
1062e6ed72bSmbalmerstartup, are accessible once the securelevel has been raised.
1072e6ed72bSmbalmerPins can be given symbolic names for easier use.
1082e6ed72bSmbalmerBesides using individual pins, device drivers that use GPIO pins can be
1092e6ed72bSmbalmerattached to a
1102e6ed72bSmbalmer.Xr gpio 4
1112e6ed72bSmbalmerdevice using the
1122e6ed72bSmbalmer.Nm
1132e6ed72bSmbalmercommand.
1142e6ed72bSmbalmer.Pp
1152c802b8dSjmcThe following configuration
1162c802b8dSjmc.Ar flags
1173af2d23dSjmcare supported by the GPIO framework.
1183af2d23dSjmcNote that not all the flags can be supported by the particular GPIO controller.
11948e05255Sgrange.Pp
1202c802b8dSjmc.Bl -tag -width Ds -offset indent -compact
12148e05255Sgrange.It in
12248e05255Sgrangeinput direction
12348e05255Sgrange.It out
12448e05255Sgrangeoutput direction
12548e05255Sgrange.It inout
12648e05255Sgrangebi-directional
12748e05255Sgrange.It od
12848e05255Sgrangeopen-drain output
12948e05255Sgrange.It pp
13048e05255Sgrangepush-pull output
13148e05255Sgrange.It tri
13248e05255Sgrangetri-state (output disabled)
13348e05255Sgrange.It pu
13448e05255Sgrangeinternal pull-up enabled
135017db7a3Smbalmer.It pd
136017db7a3Smbalmerinternal pull-down enabled
137c6dcffecSmbalmer.It iin
138c6dcffecSmbalmerinvert input
139c6dcffecSmbalmer.It iout
140c6dcffecSmbalmerinvert output
14148e05255Sgrange.El
14248e05255Sgrange.Pp
1433af2d23dSjmcWhen attaching an I2C device,
1443af2d23dSjmcif the
1453af2d23dSjmc.Ar flag
146*4eb03a88Sjmcargument is set to 1,
1473af2d23dSjmcthe order of the SDA and SCL signals is reversed
1483af2d23dSjmc(see
1493af2d23dSjmc.Xr gpioiic 4 ) .
1502c802b8dSjmc.Pp
1512e6ed72bSmbalmerWhen executed with only the
1522e6ed72bSmbalmer.Xr gpio 4
1532e6ed72bSmbalmerdevice name as argument,
1542c802b8dSjmc.Nm
155*4eb03a88Sjmcreads information about the GPIO device and displays it.
1562e6ed72bSmbalmerAt securelevel 0 the number of physically available pins is displayed,
1571bcf4e9fSschwarzeat higher securelevels the number of configured
1581bcf4e9fSschwarze.Pq Cm set
1591bcf4e9fSschwarzepins is displayed.
1602c802b8dSjmc.Pp
1612c802b8dSjmcThe options are as follows:
1622c802b8dSjmc.Bl -tag -width Ds
1632c802b8dSjmc.It Fl q
1642c802b8dSjmcOperate quietly i.e. nothing is printed to stdout.
1652c802b8dSjmc.El
16648e05255Sgrange.Sh FILES
16748e05255Sgrange.Bl -tag -width "/dev/gpiou" -compact
16848e05255Sgrange.It /dev/gpio Ns Ar u
16948e05255SgrangeGPIO device unit
17048e05255Sgrange.Ar u
17148e05255Sgrangefile.
17248e05255Sgrange.El
17348e05255Sgrange.Sh EXAMPLES
17453046763SjmcConfigure pin 20 to have push-pull output:
17548e05255Sgrange.Pp
176126b0dcdSstevesk.Dl # gpioctl gpio0 20 set out pp
17748e05255Sgrange.Pp
17853046763SjmcWrite logical 1 to pin 20:
17948e05255Sgrange.Pp
1802e6ed72bSmbalmer.Dl # gpioctl gpio0 20 1
181b9a1499cSmbalmer.Pp
182212d975fSjmcAttach a
183212d975fSjmc.Xr onewire 4
184212d975fSjmcbus on a
185212d975fSjmc.Xr gpioow 4
186212d975fSjmcdevice on pin 4:
187b9a1499cSmbalmer.Pp
1882e6ed72bSmbalmer.Dl # gpioctl gpio0 attach gpioow 4 0x01
189b9a1499cSmbalmer.Pp
190b9a1499cSmbalmerDetach the gpioow0 device:
191b9a1499cSmbalmer.Pp
1922e6ed72bSmbalmer.Dl # gpioctl gpio0 detach gpioow0
1932e6ed72bSmbalmer.Pp
1942e6ed72bSmbalmerConfigure pin 5 as output and name it error_led:
1952e6ed72bSmbalmer.Pp
1962e6ed72bSmbalmer.Dl # gpioctl gpio0 5 set out error_led
1972e6ed72bSmbalmer.Pp
1982e6ed72bSmbalmerToggle the error_led:
1992e6ed72bSmbalmer.Pp
2002e6ed72bSmbalmer.Dl # gpioctl gpio0 error_led 2
20148e05255Sgrange.Sh SEE ALSO
2027b61842fSjmc.Xr gpio 4
20348e05255Sgrange.Sh HISTORY
20448e05255SgrangeThe
20548e05255Sgrange.Nm
20648e05255Sgrangecommand first appeared in
20748e05255Sgrange.Ox 3.6 .
20848e05255Sgrange.Sh AUTHORS
2093633f95dSjmc.An -nosplit
21048e05255SgrangeThe
21148e05255Sgrange.Nm
21248e05255Sgrangeprogram was written by
21344e68d47Sschwarze.An Alexander Yurchenko Aq Mt grange@openbsd.org .
214b9a1499cSmbalmerDevice attachment was added by
21544e68d47Sschwarze.An Marc Balmer Aq Mt mbalmer@openbsd.org .
216