1.\" $NetBSD: gpio.4,v 1.8 2009/02/27 03:13:55 kenh Exp $ 2.\" $OpenBSD: gpio.4,v 1.5 2004/11/23 09:39:29 reyk 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 GPIO 4 20.Os 21.Sh NAME 22.Nm gpio 23.Nd General Purpose Input/Output 24.Sh SYNOPSIS 25.Cd "gpio* at elansc?" 26.Cd "gpio* at gcscpcib?" 27.Cd "gpio* at gscpcib?" 28.Cd "gpio* at nsclpcsio?" 29.Cd "gpio* at ppbus?" 30.Cd "gpio* at epgpio?" 31.Pp 32.In sys/types.h 33.In sys/gpio.h 34.In sys/ioctl.h 35.Sh DESCRIPTION 36The 37.Nm 38device attaches to the 39.Tn GPIO 40controller and provides a uniform programming interface to its pins. 41.Pp 42Each 43.Tn GPIO 44controller with an attached 45.Nm 46device has an associated device file under the 47.Pa /dev 48directory, e.g.\& 49.Pa /dev/gpio0 . 50Access from userland is performed through 51.Xr ioctl 2 52calls on these devices. 53.Sh IOCTL INTERFACE 54The following structures and constants are defined in the 55.Aq Pa sys/gpio.h 56header file: 57.Pp 58.Bl -tag -width XXXX -compact 59.It Dv GPIOINFO (struct gpio_info) 60Returns information about the 61.Tn GPIO 62controller in the 63.Fa gpio_info 64structure: 65.Bd -literal 66struct gpio_info { 67 int gpio_npins; /* total number of pins available */ 68}; 69.Ed 70.Pp 71.It Dv GPIOPINREAD (struct gpio_pin_op) 72Returns the input pin value in the 73.Fa gpio_pin_op 74structure: 75.Bd -literal 76struct gpio_pin_op { 77 int gp_pin; /* pin number */ 78 int gp_value; /* value */ 79}; 80.Ed 81.Pp 82The 83.Fa gp_pin 84field must be set before calling. 85.Pp 86.It Dv GPIOPINWRITE (struct gpio_pin_op) 87Writes the output value to the pin. 88The value set in the 89.Fa gp_value 90field must be either 91.Dv GPIO_PIN_LOW 92(logical 0) or 93.Dv GPIO_PIN_HIGH 94(logical 1). 95On return, the 96.Fa gp_value 97field contains the old pin state. 98.Pp 99.It Dv GPIOPINTOGGLE (struct gpio_pin_op) 100Toggles the pin output value, i.e. changes it to the opposite. 101.Fa gp_value 102field is ignored and on return contains the old pin state. 103.Pp 104.It Dv GPIOPINCTL (struct gpio_pin_ctl) 105Changes pin configuration flags with the new ones provided in the 106.Fa gpio_pin_ctl 107structure: 108.Bd -literal 109struct gpio_pin_ctl { 110 int gp_pin; /* pin number */ 111 int gp_caps; /* pin capabilities (read-only) */ 112 int gp_flags; /* pin configuration flags */ 113}; 114.Ed 115.Pp 116The 117.Fa gp_flags 118field is a combination of the following flags: 119.Pp 120.Bl -tag -width GPIO_PIN_OPENDRAIN -compact 121.It Dv GPIO_PIN_INPUT 122input direction 123.It Dv GPIO_PIN_OUTPUT 124output direction 125.It Dv GPIO_PIN_INOUT 126bi-directional 127.It Dv GPIO_PIN_OPENDRAIN 128open-drain output 129.It Dv GPIO_PIN_PUSHPULL 130push-pull output 131.It Dv GPIO_PIN_TRISTATE 132output disabled 133.It Dv GPIO_PIN_PULLUP 134internal pull-up enabled 135.It Dv GPIO_PIN_PULLDOWN 136internal pull-down enabled 137.It Dv GPIO_PIN_INVIN 138invert input 139.It Dv GPIO_PIN_INVOUT 140invert output 141.El 142.Pp 143Note that the 144.Tn GPIO 145controller 146may not support all of these flags. 147On return the 148.Fa gp_caps 149field contains flags that are supported. 150If no flags are specified, the pin configuration stays unchanged. 151.El 152.Sh FILES 153.Bl -tag -width "/dev/gpiou" -compact 154.It /dev/gpio Ns Ar u 155GPIO device unit 156.Ar u 157file. 158.El 159.Sh SEE ALSO 160.Xr ioctl 2 , 161.Xr gpioctl 8 162.Sh HISTORY 163The 164.Nm 165device first appeared in 166.Ox 3.6 167and 168.Nx 4.0 . 169.Sh AUTHORS 170.An -nosplit 171The 172.Nm 173driver was written by 174.An Alexander Yurchenko Aq grange@openbsd.org . 175.Nm 176and was ported to 177.Nx 178by 179.An Jared D. McNeill Aq jmcneill@NetBSD.org . 180.Sh BUGS 181Event capabilities are not supported. 182