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