1.\" $OpenBSD: gpio.4,v 1.11 2007/11/17 16:55:05 mbalmer Exp $ 2.\" 3.\" Copyright (c) 2004 Alexander Yurchenko <grange@openbsd.org> 4.\" 5.\" Permission to use, copy, modify, and distribute this software for any 6.\" purpose with or without fee is hereby granted, provided that the above 7.\" copyright notice and this permission notice appear in all copies. 8.\" 9.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 10.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 11.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 12.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 13.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 14.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 15.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 16.\" 17.Dd $Mdocdate: November 17 2007 $ 18.Dt GPIO 4 19.Os 20.Sh NAME 21.Nm gpio 22.Nd General Purpose Input/Output 23.Sh SYNOPSIS 24.Cd "gpio* at ath?" 25.Cd "gpio* at elansc?" Pq i386 26.Cd "gpio* ar glxpcib?" Pq i386 27.Cd "gpio* at gscpcib?" Pq i386 28.Cd "gpio* at isagpio?" 29.Cd "gpio* at nsclpcsio?" 30.Cd "gpio* at pcagpio?" 31.Cd "gpio* at pcaled?" 32.Pp 33.Fd #include <sys/types.h> 34.Fd #include <sys/gpio.h> 35.Fd #include <sys/ioctl.h> 36.Sh DESCRIPTION 37The 38.Nm 39device attaches to the 40.Tn GPIO 41controller and provides a uniform programming interface to its pins. 42.Pp 43Each 44.Tn GPIO 45controller with an attached 46.Nm 47device has an associated device file under the 48.Pa /dev 49directory, e.g.\& 50.Pa /dev/gpio0 . 51Access from userland is performed through 52.Xr ioctl 2 53calls on these devices. 54.Sh IOCTL INTERFACE 55The following structures and constants are defined in the 56.Aq Pa sys/gpio.h 57header file: 58.Pp 59.Bl -tag -width XXXX -compact 60.It Dv GPIOINFO (struct gpio_info) 61Returns information about the 62.Tn GPIO 63controller in the 64.Fa gpio_info 65structure: 66.Bd -literal 67struct gpio_info { 68 int gpio_npins; /* total number of pins available */ 69}; 70.Ed 71.Pp 72.It Dv GPIOPINREAD (struct gpio_pin_op) 73Returns the input pin value in the 74.Fa gpio_pin_op 75structure: 76.Bd -literal 77struct gpio_pin_op { 78 int gp_pin; /* pin number */ 79 int gp_value; /* value */ 80}; 81.Ed 82.Pp 83The 84.Fa gp_pin 85field must be set before calling. 86.Pp 87.It Dv GPIOPINWRITE (struct gpio_pin_op) 88Writes the output value to the pin. 89The value set in the 90.Fa gp_value 91field must be either 92.Dv GPIO_PIN_LOW 93(logical 0) or 94.Dv GPIO_PIN_HIGH 95(logical 1). 96On return, the 97.Fa gp_value 98field contains the old pin state. 99.Pp 100.It Dv GPIOPINTOGGLE (struct gpio_pin_op) 101Toggles the pin output value, i.e. changes it to the opposite. 102.Fa gp_value 103field is ignored and on return contains the old pin state. 104.Pp 105.It Dv GPIOPINCTL (struct gpio_pin_ctl) 106Changes pin configuration flags with the new ones provided in the 107.Fa gpio_pin_ctl 108structure: 109.Bd -literal 110struct gpio_pin_ctl { 111 int gp_pin; /* pin number */ 112 int gp_caps; /* pin capabilities (read-only) */ 113 int gp_flags; /* pin configuration flags */ 114}; 115.Ed 116.Pp 117The 118.Fa gp_flags 119field is a combination of the following flags: 120.Pp 121.Bl -tag -width GPIO_PIN_OPENDRAIN -compact 122.It Dv GPIO_PIN_INPUT 123input direction 124.It Dv GPIO_PIN_OUTPUT 125output direction 126.It Dv GPIO_PIN_INOUT 127bi-directional 128.It Dv GPIO_PIN_OPENDRAIN 129open-drain output 130.It Dv GPIO_PIN_PUSHPULL 131push-pull output 132.It Dv GPIO_PIN_TRISTATE 133output disabled 134.It Dv GPIO_PIN_PULLUP 135internal pull-up enabled 136.It Dv GPIO_PIN_PULLDOWN 137internal pull-down enabled 138.It Dv GPIO_PIN_INVIN 139invert input 140.It Dv GPIO_PIN_INVOUT 141invert output 142.El 143.Pp 144Note that the 145.Tn GPIO 146controller 147may not support all of these flags. 148On return the 149.Fa gp_caps 150field contains flags that are supported. 151If no flags are specified, the pin configuration stays unchanged. 152.El 153.Sh FILES 154.Bl -tag -width "/dev/gpiou" -compact 155.It /dev/gpio Ns Ar u 156GPIO device unit 157.Ar u 158file. 159.El 160.Sh SEE ALSO 161.Xr ioctl 2 , 162.Xr gpioctl 8 163.Sh HISTORY 164The 165.Nm 166device first appeared in 167.Ox 3.6 . 168.Sh AUTHORS 169The 170.Nm 171driver was written by 172.An Alexander Yurchenko Aq grange@openbsd.org . 173.Sh BUGS 174Event capabilities are not supported. 175