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