GPIO(4) | Device Drivers Manual | GPIO(4) |
gpio
— General
Purpose Input/Output
gpio* at ath?
gpio* at elansc?
(i386)
gpio* at glxpcib?
(i386)
gpio* at gscpcib?
(i386)
gpio* at isagpio?
gpio* at nsclpcsio?
gpio* at omgpio?
(armv7)
gpio* at pcagpio?
gpio* at pcaled?
gpio* at skgpio?
(amd64, i386)
gpio* at sxipio?
(arm64, armv7)
gpio0 at voyager?
(loongson)
#include <sys/types.h>
#include <sys/gpio.h>
#include <sys/ioctl.h>
The gpio
device attaches to the GPIO
controller and provides a uniform programming interface to its pins.
Each GPIO controller with an attached gpio
device has an associated device file under the /dev
directory, e.g. /dev/gpio0. Access from userland is
performed through ioctl(2)
calls on these devices.
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 gpio
device at securelevel 0.
All other pins will not be accessible once the runlevel has been raised.
The following structures and constants are defined in the
<sys/gpio.h>
header
file:
GPIOINFO
struct gpio_infostruct gpio_info { int gpio_npins; /* total number of pins available */ };
GPIOPINREAD
struct gpio_pin_op#define GPIOPINMAXNAME 64 struct gpio_pin_op { char gp_name[GPIOPINMAXNAME]; /* pin name */ int gp_pin; /* pin number */ int gp_value; /* value */ };
The gp_name or gp_pin field must be set before calling.
GPIOPINWRITE
struct gpio_pin_opGPIO_PIN_LOW
(logical 0) or
GPIO_PIN_HIGH
(logical 1). On return, the
gp_value field contains the old pin state.GPIOPINTOGGLE
struct gpio_pin_opGPIOPINSET
struct gpio_pin_set#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 */ };
The gp_flags field is a combination of the following flags:
GPIO_PIN_INPUT
GPIO_PIN_OUTPUT
GPIO_PIN_INOUT
GPIO_PIN_OPENDRAIN
GPIO_PIN_PUSHPULL
GPIO_PIN_TRISTATE
GPIO_PIN_PULLUP
GPIO_PIN_PULLDOWN
GPIO_PIN_INVIN
GPIO_PIN_INVOUT
Note that the GPIO controller may not support all of these flags. On return the gp_caps field contains flags that are supported. If no flags are specified, the pin configuration stays unchanged.
Only GPIO pins that have been set using GPIOPINSET will be accessible at securelevels greater than 0.
GPIOPINUNSET
struct gpio_pin_setGPIOATTACH
struct gpio_attachstruct gpio_attach { char ga_dvname[16]; /* device name */ int ga_offset; /* pin number */ u_int32_t ga_mask; /* binary mask */ };
GPIODETACH
struct gpio_attachGPIOATTACH
ioctl(2). The
ga_offset and ga_mask fields
of the gpio_attach structure are ignored.The gpio
device first appeared in
OpenBSD 3.6.
The gpio
driver was written by
Alexander Yurchenko
<grange@openbsd.org>.
Runtime device attachment was added by Marc Balmer
<mbalmer@openbsd.org>.
Event capabilities are not supported.
September 12, 2017 | OpenBSD-6.4 |