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