2011-10-06 15:05:42 +04:00
|
|
|
.\" $NetBSD: gpio.4,v 1.22 2011/10/06 11:05:42 wiz Exp $
|
2005-09-27 06:38:03 +04:00
|
|
|
.\" $OpenBSD: gpio.4,v 1.5 2004/11/23 09:39:29 reyk 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.
|
|
|
|
.\"
|
2011-10-03 15:16:47 +04:00
|
|
|
.Dd October 3, 2011
|
2005-09-27 06:38:03 +04:00
|
|
|
.Dt GPIO 4
|
|
|
|
.Os
|
|
|
|
.Sh NAME
|
|
|
|
.Nm gpio
|
|
|
|
.Nd General Purpose Input/Output
|
|
|
|
.Sh SYNOPSIS
|
2006-01-05 13:46:21 +03:00
|
|
|
.Cd "gpio* at elansc?"
|
2009-08-01 17:17:30 +04:00
|
|
|
.Cd "gpio* at epgpio?"
|
2008-01-09 18:51:47 +03:00
|
|
|
.Cd "gpio* at gcscpcib?"
|
2009-08-01 17:17:30 +04:00
|
|
|
.Cd "gpio* at gpiosim?"
|
2008-01-09 18:51:47 +03:00
|
|
|
.Cd "gpio* at gscpcib?"
|
2009-09-27 21:55:31 +04:00
|
|
|
.Cd "gpio* at ichlpcib?"
|
2008-01-09 18:51:47 +03:00
|
|
|
.Cd "gpio* at nsclpcsio?"
|
2008-04-29 18:07:36 +04:00
|
|
|
.Cd "gpio* at ppbus?"
|
2005-09-27 06:38:03 +04:00
|
|
|
.Pp
|
2005-09-27 13:13:00 +04:00
|
|
|
.In sys/types.h
|
|
|
|
.In sys/gpio.h
|
|
|
|
.In sys/ioctl.h
|
2005-09-27 06:38:03 +04:00
|
|
|
.Sh DESCRIPTION
|
|
|
|
The
|
|
|
|
.Nm
|
|
|
|
device attaches to the
|
|
|
|
.Tn GPIO
|
|
|
|
controller and provides a uniform programming interface to its pins.
|
|
|
|
.Pp
|
|
|
|
Each
|
|
|
|
.Tn 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.
|
2009-07-25 20:20:10 +04:00
|
|
|
.Pp
|
2009-08-23 14:20:41 +04:00
|
|
|
Whether the layout of the GPIO device can be configured is subject to
|
|
|
|
authorization by the
|
|
|
|
.Xr kauth 9
|
|
|
|
framework.
|
|
|
|
.Pp
|
2009-08-23 19:41:28 +04:00
|
|
|
If for example
|
2009-08-23 14:20:41 +04:00
|
|
|
.Xr secmodel_securelevel 9
|
2009-08-23 19:41:28 +04:00
|
|
|
is active, the layout of the GPIO device is defined at a securelevel
|
2009-08-23 14:20:41 +04:00
|
|
|
less than 1, i.e. typically during system boot, and cannot be changed later.
|
2009-07-25 20:20:10 +04:00
|
|
|
GPIO pins can be configured and given a symbolic name and device drivers
|
|
|
|
that use GPIO pins can be attached to the
|
|
|
|
.Nm
|
2009-07-26 01:16:35 +04:00
|
|
|
device at a securelevel less than 1.
|
2009-07-25 20:20:10 +04:00
|
|
|
All other pins will not be accessible once the runlevel has been raised.
|
2005-09-27 06:38:03 +04:00
|
|
|
.Sh IOCTL INTERFACE
|
|
|
|
The following structures and constants are defined in the
|
2010-03-22 21:58:31 +03:00
|
|
|
.In sys/gpio.h
|
2005-09-27 06:38:03 +04:00
|
|
|
header file:
|
|
|
|
.Pp
|
|
|
|
.Bl -tag -width XXXX -compact
|
|
|
|
.It Dv GPIOINFO (struct gpio_info)
|
|
|
|
Returns information about the
|
|
|
|
.Tn GPIO
|
|
|
|
controller in the
|
|
|
|
.Fa gpio_info
|
|
|
|
structure:
|
|
|
|
.Bd -literal
|
|
|
|
struct gpio_info {
|
|
|
|
int gpio_npins; /* total number of pins available */
|
|
|
|
};
|
|
|
|
.Ed
|
|
|
|
.Pp
|
2009-07-25 20:20:10 +04:00
|
|
|
.It Dv GPIOREAD (struct gpio_req)
|
2005-09-27 06:38:03 +04:00
|
|
|
Returns the input pin value in the
|
|
|
|
.Fa gpio_pin_op
|
|
|
|
structure:
|
|
|
|
.Bd -literal
|
2009-07-25 20:20:10 +04:00
|
|
|
#define GPIOMAXNAME 64
|
|
|
|
|
|
|
|
struct gpio_req {
|
|
|
|
char gp_name[GPIOMAXNAME]; /* pin name */
|
|
|
|
int gp_pin; /* pin number */
|
|
|
|
int gp_value; /* value */
|
2005-09-27 06:38:03 +04:00
|
|
|
};
|
|
|
|
.Ed
|
|
|
|
.Pp
|
|
|
|
The
|
2009-07-25 20:20:10 +04:00
|
|
|
.Fa gp_name
|
|
|
|
or
|
2005-09-27 06:38:03 +04:00
|
|
|
.Fa gp_pin
|
|
|
|
field must be set before calling.
|
|
|
|
.Pp
|
2009-07-25 20:20:10 +04:00
|
|
|
.It Dv GPIOWRITE (struct gpio_req)
|
2005-09-27 06:38:03 +04:00
|
|
|
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.
|
|
|
|
.Pp
|
2009-07-25 20:20:10 +04:00
|
|
|
.It Dv GPIOTOGGLE (struct gpio_req)
|
2005-09-27 06:38:03 +04:00
|
|
|
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.
|
|
|
|
.Pp
|
2011-08-28 11:48:50 +04:00
|
|
|
.It Dv GPIOPULSE (struct gpio_pulse)
|
|
|
|
Starts pulsing the pin:
|
|
|
|
.Bd -literal
|
|
|
|
/* GPIO pulse request */
|
|
|
|
struct gpio_pulse {
|
|
|
|
char gp_name[GPIOMAXNAME]; /* pin name */
|
|
|
|
int gp_pin; /* pin number */
|
|
|
|
struct timeval gp_pulse_on; /* "on" period */
|
|
|
|
struct timeval gp_pulse_off; /* "off" period */
|
|
|
|
};
|
|
|
|
.Ed
|
|
|
|
.Pp
|
|
|
|
The
|
|
|
|
.Fa gp_name
|
|
|
|
or
|
|
|
|
.Fa gp_pin
|
|
|
|
field must be set before calling.
|
|
|
|
If
|
|
|
|
.Fa gp_pulse_on
|
|
|
|
or
|
|
|
|
.Fa gp_pulse_off
|
|
|
|
is set to zero, a default of
|
|
|
|
.Xr hz 9 / 2
|
|
|
|
is assumed for both periods.
|
|
|
|
.Pp
|
2009-07-25 20:20:10 +04:00
|
|
|
.It Dv GPIOSET (struct gpio_set)
|
2005-09-27 06:38:03 +04:00
|
|
|
Changes pin configuration flags with the new ones provided in the
|
2009-07-25 20:20:10 +04:00
|
|
|
.Fa gpio_set
|
2005-09-27 06:38:03 +04:00
|
|
|
structure:
|
|
|
|
.Bd -literal
|
2009-07-25 20:20:10 +04:00
|
|
|
#define GPIOMAXNAME 64
|
|
|
|
|
|
|
|
struct gpio_set {
|
|
|
|
char gp_name[GPIOMAXNAME]; /* pin name */
|
|
|
|
int gp_pin; /* pin number */
|
|
|
|
int gp_caps; /* pin capabilities (ro) */
|
|
|
|
int gp_flags; /* pin configuration flags */
|
|
|
|
char gp_name2[GPIOMAXNAME]; /* new name */
|
2005-09-27 06:38:03 +04:00
|
|
|
};
|
|
|
|
.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
|
2008-01-09 19:15:41 +03:00
|
|
|
.It Dv GPIO_PIN_PULLDOWN
|
|
|
|
internal pull-down enabled
|
|
|
|
.It Dv GPIO_PIN_INVIN
|
|
|
|
invert input
|
|
|
|
.It Dv GPIO_PIN_INVOUT
|
|
|
|
invert output
|
2009-09-25 23:37:03 +04:00
|
|
|
.It Dv GPIO_PIN_PULSE
|
|
|
|
pulse output
|
2005-09-27 06:38:03 +04:00
|
|
|
.El
|
|
|
|
.Pp
|
2009-07-25 20:20:10 +04:00
|
|
|
Note that the GPIO controller
|
2005-09-27 06:38:03 +04:00
|
|
|
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.
|
2009-07-25 20:20:10 +04:00
|
|
|
.Pp
|
|
|
|
Only GPIO pins that have been set using
|
|
|
|
.Ar GPIOSET
|
|
|
|
will be accessible at securelevels greater than 0.
|
|
|
|
.Pp
|
|
|
|
.It Dv GPIOUNSET (struct gpio_set)
|
|
|
|
Unset the specified pin, i.e. clear its name and make it unaccessible
|
|
|
|
at securelevels greater than 0.
|
2009-08-01 19:52:55 +04:00
|
|
|
.Pp
|
2009-07-25 20:20:10 +04:00
|
|
|
.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 */
|
2011-10-02 13:33:18 +04:00
|
|
|
uint32_t ga_mask; /* binary mask */
|
|
|
|
uint32_t ga_flags; /* driver dependent */
|
2009-07-25 20:20:10 +04:00
|
|
|
};
|
|
|
|
.Ed
|
2011-10-03 15:16:47 +04:00
|
|
|
.Pp
|
2009-07-25 20:20:10 +04:00
|
|
|
The
|
2011-10-03 15:16:47 +04:00
|
|
|
.Xr drvctl 8
|
|
|
|
command can be used to detach a device from a gpio pin.
|
2005-09-27 06:38:03 +04:00
|
|
|
.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 ,
|
2011-10-06 15:05:42 +04:00
|
|
|
.Xr drvctl 8 ,
|
2005-09-27 06:38:03 +04:00
|
|
|
.Xr gpioctl 8
|
|
|
|
.Sh HISTORY
|
|
|
|
The
|
|
|
|
.Nm
|
|
|
|
device first appeared in
|
2005-09-27 13:13:00 +04:00
|
|
|
.Ox 3.6
|
|
|
|
and
|
|
|
|
.Nx 4.0 .
|
2005-09-27 06:38:03 +04:00
|
|
|
.Sh AUTHORS
|
2005-09-27 13:13:00 +04:00
|
|
|
.An -nosplit
|
2005-09-27 06:38:03 +04:00
|
|
|
The
|
|
|
|
.Nm
|
|
|
|
driver was written by
|
2005-09-27 13:13:00 +04:00
|
|
|
.An Alexander Yurchenko Aq grange@openbsd.org .
|
2005-09-27 06:38:03 +04:00
|
|
|
.Nm
|
2005-09-27 13:13:00 +04:00
|
|
|
and was ported to
|
|
|
|
.Nx
|
|
|
|
by
|
2005-09-27 06:38:03 +04:00
|
|
|
.An Jared D. McNeill Aq jmcneill@NetBSD.org .
|
2009-07-25 20:20:10 +04:00
|
|
|
Runtime device attachment was added by
|
|
|
|
.An Marc Balmer Aq marc@msys.ch .
|
2005-09-27 06:38:03 +04:00
|
|
|
.Sh BUGS
|
|
|
|
Event capabilities are not supported.
|