$NetBSD: gpioctl.8,v 1.15 2011/11/13 13:20:02 mbalmer Exp $

Copyright (c) 2009, 2010, 2011 Marc Balmer <marc@msys.ch>
Copyright (c) 2004 Alexander Yurchenko <grange@openbsd.org>

Permission to use, copy, modify, and distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

.Dd November 13, 2011 .Dt GPIOCTL 8 .Os .Sh NAME .Nm gpioctl .Nd control GPIO devices .Sh SYNOPSIS .Nm gpioctl .Op Fl q .Ar device .Cm attach .Ar device .Ar offset .Ar mask .Op Ar flag .Nm gpioctl .Op Fl q .Ar device .Ar pin .Op Ar 0 | 1 | 2 .Nm gpioctl .Op Fl q .Ar device .Ar pin .Op Ar on | off | toggle .Nm gpioctl .Op Fl q .Ar device .Ar pin .Cm set .Op Ar flags .Op Ar name .Nm gpioctl .Op Fl q .Ar device .Ar pin .Cm unset .Sh DESCRIPTION The .Nm program allows manipulation of GPIO (General Purpose Input/Output) device pins. Such devices can be either part of the chipset or embedded CPU, or a separate chip. The usual way of using GPIO is to connect some simple devices such as LEDs and 1-wire thermal sensors to its pins.

p Each GPIO device has an associated device file in the

a /dev directory. .Ar device can be specified with or without the

a /dev prefix. For example,

a /dev/gpio0 or

a gpio0 .

p GPIO pins can be either .Dq read or .Dq written with the values of logical 0 or 1. If only a .Ar pin number is specified on the command line, the pin state will be read from the GPIO controller and displayed. To write to a pin, a value must be specified after the .Ar pin number. Values can be either 0 or 1. A value of 2 .Dq toggles the pin, i.e. changes its state to the opposite. Instead of the numerical values, the word .Ar on , .Ar off , or .Ar toggle can be used.

p To

p Only pins that have been configured at securelevel 0, typically during system startup, are accessible once the securelevel has been raised. Pins can be given symbolic names for easier use. Besides using individual pins, device drivers that use GPIO pins can be attached to a .Xr gpio 4 device using the .Nm command. Such drivers can be detached at runtime using the .Xr drvctl 8 command.

p The following configuration .Ar flags are supported by the GPIO framework:

p l -tag -width Ds -offset indent -compact t in input direction t out output direction t inout bi-directional t od open-drain output t pp push-pull output t tri tri-state (output disabled) t pu internal pull-up enabled t pd internal pull-down enabled t iin invert input t iout invert output t pulsate pulsate output at a hardware-defined frequency and duty cycle .El

p Note that not all the flags may be supported by the particular GPIO controller.

p When executed with only the .Xr gpio 4 device name as argument, .Nm reads information about the .Tn GPIO device and displays it. At securelevel 0 the number of physically available pins is displayed, at higher securelevels the number of configured (set) pins is displayed.

p The options are as follows: l -tag -width Ds t Fl q Operate quietly i.e. nothing is printed to stdout. .El .Sh FILES l -tag -width "/dev/gpiou" -compact t /dev/gpio Ns Ar u GPIO device unit .Ar u file. .El .Sh EXAMPLES Configure pin 20 to have push-pull output:

p .Dl # gpioctl gpio0 20 set out pp

p Write logical 1 to pin 20:

p .Dl # gpioctl gpio0 20 1

p Attach a .Xr onewire 4 bus on a .Xr gpioow 4 device on pin 4:

p .Dl # gpioctl gpio0 attach gpioow 4 0x01

p Detach the gpioow0 device:

p .Dl # drvctl -d gpioow0

p Configure pin 5 as output and name it error_led:

p .Dl # gpioctl gpio0 5 set out error_led

p Toggle the error_led:

p .Dl # gpioctl gpio0 error_led 2 .Sh SEE ALSO .Xr gpio 4 , .Xr drvctl 8 .Sh HISTORY The .Nm command first appeared in .Ox 3.6 and .Nx 4.0 . .Sh AUTHORS .An -nosplit The .Nm program was written by .An Alexander Yurchenko Aq grange@openbsd.org . Device attachment was added by .An Marc Balmer Aq marc@msys.ch .