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