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