1 .\" $NetBSD: gpio.4,v 1.16 2009/09/27 17:55:32 jakllsch Exp $
2 .\" $OpenBSD: gpio.4,v 1.5 2004/11/23 09:39:29 reyk Exp $
4 .\" Copyright (c) 2004 Alexander Yurchenko <grange@openbsd.org>
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.
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.
18 .Dd September 27, 2009
23 .Nd General Purpose Input/Output
25 .Cd "gpio* at elansc?"
26 .Cd "gpio* at epgpio?"
27 .Cd "gpio* at gcscpcib?"
28 .Cd "gpio* at gpiosim?"
29 .Cd "gpio* at gscpcib?"
30 .Cd "gpio* at ichlpcib?"
31 .Cd "gpio* at nsclpcsio?"
40 device attaches to the
42 controller and provides a uniform programming interface to its pins.
46 controller with an attached
48 device has an associated device file under the
52 Access from userland is performed through
54 calls on these devices.
56 Whether the layout of the GPIO device can be configured is subject to
62 .Xr secmodel_securelevel 9
63 is active, the layout of the GPIO device is defined at a securelevel
64 less than 1, i.e. typically during system boot, and cannot be changed later.
65 GPIO pins can be configured and given a symbolic name and device drivers
66 that use GPIO pins can be attached to the
68 device at a securelevel less than 1.
69 All other pins will not be accessible once the runlevel has been raised.
71 The following structures and constants are defined in the
75 .Bl -tag -width XXXX -compact
76 .It Dv GPIOINFO (struct gpio_info)
77 Returns information about the
84 int gpio_npins; /* total number of pins available */
88 .It Dv GPIOREAD (struct gpio_req)
89 Returns the input pin value in the
93 #define GPIOMAXNAME 64
96 char gp_name[GPIOMAXNAME]; /* pin name */
97 int gp_pin; /* pin number */
98 int gp_value; /* value */
106 field must be set before calling.
108 .It Dv GPIOWRITE (struct gpio_req)
109 Writes the output value to the pin.
119 field contains the old pin state.
121 .It Dv GPIOTOGGLE (struct gpio_req)
122 Toggles the pin output value, i.e. changes it to the opposite.
124 field is ignored and on return contains the old pin state.
126 .It Dv GPIOSET (struct gpio_set)
127 Changes pin configuration flags with the new ones provided in the
131 #define GPIOMAXNAME 64
134 char gp_name[GPIOMAXNAME]; /* pin name */
135 int gp_pin; /* pin number */
136 int gp_caps; /* pin capabilities (ro) */
137 int gp_flags; /* pin configuration flags */
138 char gp_name2[GPIOMAXNAME]; /* new name */
144 field is a combination of the following flags:
146 .Bl -tag -width GPIO_PIN_OPENDRAIN -compact
147 .It Dv GPIO_PIN_INPUT
149 .It Dv GPIO_PIN_OUTPUT
151 .It Dv GPIO_PIN_INOUT
153 .It Dv GPIO_PIN_OPENDRAIN
155 .It Dv GPIO_PIN_PUSHPULL
157 .It Dv GPIO_PIN_TRISTATE
159 .It Dv GPIO_PIN_PULLUP
160 internal pull-up enabled
161 .It Dv GPIO_PIN_PULLDOWN
162 internal pull-down enabled
163 .It Dv GPIO_PIN_INVIN
165 .It Dv GPIO_PIN_INVOUT
167 .It Dv GPIO_PIN_PULSE
171 Note that the GPIO controller
172 may not support all of these flags.
175 field contains flags that are supported.
176 If no flags are specified, the pin configuration stays unchanged.
178 Only GPIO pins that have been set using
180 will be accessible at securelevels greater than 0.
182 .It Dv GPIOUNSET (struct gpio_set)
183 Unset the specified pin, i.e. clear its name and make it unaccessible
184 at securelevels greater than 0.
186 .It Dv GPIOATTACH (struct gpio_attach)
187 Attach the device described in the
189 structure on this gpio device.
192 char ga_dvname[16]; /* device name */
193 int ga_offset; /* pin number */
194 u_int32_t ga_mask; /* binary mask */
198 .It Dv GPIODETACH (struct gpio_attach)
199 Detach a device from this gpio device that was previously attached using the
208 structure are ignored.
211 .Bl -tag -width "/dev/gpiou" -compact
212 .It /dev/gpio Ns Ar u
223 device first appeared in
231 driver was written by
232 .An Alexander Yurchenko Aq grange@openbsd.org .
237 .An Jared D. McNeill Aq jmcneill@NetBSD.org .
238 Runtime device attachment was added by
239 .An Marc Balmer Aq marc@msys.ch .
241 Event capabilities are not supported.