1.\" $NetBSD: gpioctl.8,v 1.4 2008/01/09 15:56:27 xtraeme Exp $ 2.\" $OpenBSD: gpioctl.8,v 1.5 2004/12/02 05:11:40 grange Exp $ 3.\" 4.\" Copyright (c) 2004 Alexander Yurchenko <grange@openbsd.org> 5.\" 6.\" Permission to use, copy, modify, and distribute this software for any 7.\" purpose with or without fee is hereby granted, provided that the above 8.\" copyright notice and this permission notice appear in all copies. 9.\" 10.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17.\" 18.Dd January 9, 2008 19.Dt GPIOCTL 8 20.Os 21.Sh NAME 22.Nm gpioctl 23.Nd control GPIO devices 24.Sh SYNOPSIS 25.Nm 26.Op Fl hq 27.Op Fl d Ar device 28.Op Ar pin 29.Op Ar 0 | 1 | 2 30.Nm 31.Op Fl hq 32.Op Fl d Ar device 33.Fl c 34.Ar pin 35.Op Ar flags 36.Sh DESCRIPTION 37The 38.Nm 39program allows manipulation of 40.Tn GPIO 41(General Purpose Input/Output) device pins. 42Such devices can be either part of the chipset or embedded 43.Tn CPU , 44or a separate chip. 45The usual way of using 46.Tn GPIO 47is to connect some simple devices such as LEDs, 1-wire thermal sensors, 48etc., to its pins. 49.Pp 50Each 51.Tn GPIO 52device has an associated device file in the 53.Pa /dev 54directory. 55By default 56.Nm 57uses 58.Pa /dev/gpio0 , 59which corresponds to the first found 60.Tn GPIO 61device in the system. 62If more than one 63.Tn GPIO 64device is present, an alternative device file can be specified with the 65.Fl d 66option in order to access a particular 67.Tn GPIO 68device. 69.Pp 70When executed without any arguments, 71.Nm 72reads information about the 73.Tn GPIO 74device and displays it. 75.Pp 76.Tn GPIO 77pins can be either 78.Dq read 79or 80.Dq written 81with the values of logical 0 or 1. 82If only a 83.Ar pin 84number is specified on the command line, the pin state will be read 85from the 86.Tn GPIO 87controller and displayed. 88To write to a pin, a value must be specified after the 89.Ar pin 90number. 91Values can be either 0 or 1. 92A value of 2 has a special meaning: it 93.Dq toggles 94the pin, i.e. changes its state to the opposite. 95.Pp 96Each pin can be configured with different flags with the 97.Fl c 98option. 99The following configuration flags are supported by the 100.Tn GPIO 101framework: 102.Pp 103.Bl -tag -width XXXXXXX -offset indent -compact 104.It in 105input direction 106.It out 107output direction 108.It inout 109bi-directional 110.It od 111open-drain output 112.It pp 113push-pull output 114.It tri 115tri-state (output disabled) 116.It pu 117internal pull-up enabled 118.It pd 119internal pull-down enabled 120.It iin 121invert input 122.It iout 123invert output 124.El 125.Pp 126Note that not all the flags can be supported by the particular 127.Tn GPIO 128controller. 129The list of supported flags is always displayed when executing 130.Nm 131with the 132.Fl c 133option. 134If only a 135.Ar pin 136number is specified on the command line, the current pin flags will be 137displayed. 138To change pin flags, a new flags set separated by spaces must be 139specified after the 140.Ar pin 141number. 142.Pp 143The 144.Fl q 145option causes 146.Nm 147to operate quietly i.e. nothing is printed to stdout. 148The 149.Fl h 150option displays a usage summary. 151.Sh FILES 152.Bl -tag -width "/dev/gpiou" -compact 153.It /dev/gpio Ns Ar u 154GPIO device unit 155.Ar u 156file. 157.El 158.Sh EXAMPLES 159Configure pin 20 to have push-pull output: 160.Pp 161.Dl # gpioctl -c 20 out pp 162.Pp 163Write logical 1 to pin 20: 164.Pp 165.Dl # gpioctl 20 1 166.Sh SEE ALSO 167.Xr elansc 4 , 168.Xr gcscpcib 4 , 169.Xr gpio 4 , 170.Xr gscpcib 4 , 171.Xr nsclpcsio 4 172.Sh HISTORY 173The 174.Nm 175command first appeared in 176.Ox 3.6 177and 178.Nx 4.0 . 179.Sh AUTHORS 180The 181.Nm 182program was written by 183.An Alexander Yurchenko Aq grange@openbsd.org . 184