GPIO Character Device Userspace API (v1)
First added in 4.8.
The API is based around three major objects, the Chip, the Line Handle, and the Line Event.
Where "line event" is used in this document it refers to the request that can monitor a line for edge events, not the edge events themselves.
Chip #
The Chip represents a single GPIO chip and is exposed to userspace using device files of the form /dev/gpiochipX.
Each chip supports a number of GPIO lines, chip.lines<gpiochip_info>. Lines on the chip are identified by an offset in the range from 0 to chip.lines - 1, i.e. [0,chip.lines).
Lines are requested from the chip using either gpio-get-linehandle-ioctl.rst and the resulting line handle is used to access the GPIO chip's lines, or gpio-get-lineevent-ioctl.rst and the resulting line event is used to monitor a GPIO line for edge events.
Within this documentation, the file descriptor returned by calling open() on the GPIO device file is referred to as chip_fd.
Operations #
The following operations may be performed on the chip:
- Get Line Handle
- Get Line Event
- Get Chip Info
- Get Line Info
- Watch Line Info
- Unwatch Line Info
- Read Line Info Changed Events
Line Handle #
Line handles are created by gpio-get-linehandle-ioctl.rst and provide access to a set of requested lines. The line handle is exposed to userspace via the anonymous file descriptor returned in request.fd<gpiohandle_request> by gpio-get-linehandle-ioctl.rst.
Within this documentation, the line handle file descriptor is referred to as handle_fd.
Operations #
The following operations may be performed on the line handle:
Line Event #
Line events are created by gpio-get-lineevent-ioctl.rst and provide access to a requested line. The line event is exposed to userspace via the anonymous file descriptor returned in request.fd<gpioevent_request> by gpio-get-lineevent-ioctl.rst.
Within this documentation, the line event file descriptor is referred to as event_fd.
Operations #
The following operations may be performed on the line event:
Types #
This section contains the structs that are referenced by the ABI v1.
The struct gpiochip_info<gpiochip_info> is common to ABI v1 and v2.
struct gpioline_info #
Information about a certain GPIO line
Definition
;
Members
line_offset: the local offset on this GPIO device, fill this in when requesting the line information from the kernelflags: various flags for this linename: the name of this GPIO line, such as the output pin of the line on the chip, a rail or a pin header name on a board, as specified by the gpio chip, may be empty (i.e. name[0] == '\0')consumer: a functional name for the consumer of this GPIO line as set by whatever is using it, will be empty if there is no current user but may also be empty if the consumer doesn't set this up
Note
This struct is part of ABI v1 and is deprecated.
Use ABI v2 and struct gpio_v2_line_info instead.
struct gpioline_info_changed #
Information about a change in status of a GPIO line
Definition
;
Members
info: updated line informationtimestamp: estimate of time of status change occurrence, in nanosecondsevent_type: one ofGPIOLINE_CHANGED_REQUESTED,GPIOLINE_CHANGED_RELEASEDandGPIOLINE_CHANGED_CONFIGpadding: reserved for future use
Description
The struct gpioline_info embedded here has 32-bit alignment on its own,
but it works fine with 64-bit alignment too. With its 72 byte size, we can
guarantee there are no implicit holes between it and subsequent members.
The 20-byte padding at the end makes sure we don't add any implicit padding
at the end of the structure on 64-bit architectures.
Note
This struct is part of ABI v1 and is deprecated.
Use ABI v2 and struct gpio_v2_line_info_changed instead.
struct gpiohandle_request #
Information about a GPIO handle request
Definition
;
Members
lineoffsets: an array of desired lines, specified by offset index for the associated GPIO deviceflags: desired flags for the desired GPIO lines, such asGPIOHANDLE_REQUEST_OUTPUT,GPIOHANDLE_REQUEST_ACTIVE_LOWetc, added together. Note that even if multiple lines are requested, the same flags must be applicable to all of them, if you want lines with individual flags set, request them one by one. It is possible to select a batch of input or output lines, but they must all have the same characteristics, i.e. all inputs or all outputs, all active low etcdefault_values: if theGPIOHANDLE_REQUEST_OUTPUTis set for a requested line, this specifies the default output value, should be 0 (inactive) or 1 (active). Anything other than 0 or 1 will be interpreted as active.consumer_label: a desired consumer label for the selected GPIO line(s) such as "my-bitbanged-relay"lines: number of lines requested in this request, i.e. the number of valid fields in the above arrays, set to 1 to request a single linefd: after a successfulGPIO_GET_LINEHANDLE_IOCTLoperation, contains a valid anonymous file descriptor representing the request
Note
This struct is part of ABI v1 and is deprecated.
Use ABI v2 and struct gpio_v2_line_request instead.
struct gpiohandle_config #
Configuration for a GPIO handle request
Definition
;
Members
flags: updated flags for the requested GPIO lines, such asGPIOHANDLE_REQUEST_OUTPUT,GPIOHANDLE_REQUEST_ACTIVE_LOWetc, added togetherdefault_values: if theGPIOHANDLE_REQUEST_OUTPUTis set in flags, this specifies the default output value, should be 0 (inactive) or 1 (active). Anything other than 0 or 1 will be interpreted as active.padding: reserved for future use and should be zero filled
Note
This struct is part of ABI v1 and is deprecated.
Use ABI v2 and struct gpio_v2_line_config instead.
struct gpiohandle_data #
Information of values on a GPIO handle
Definition
;
Members
values: when getting the state of lines this contains the current state of a line, when setting the state of lines these should contain the desired target state. States are 0 (inactive) or 1 (active). When setting, anything other than 0 or 1 will be interpreted as active.
Note
This struct is part of ABI v1 and is deprecated.
Use ABI v2 and struct gpio_v2_line_values instead.
struct gpioevent_request #
Information about a GPIO event request
Definition
;
Members
lineoffset: the desired line to subscribe to events from, specified by offset index for the associated GPIO devicehandleflags: desired handle flags for the desired GPIO line, such asGPIOHANDLE_REQUEST_ACTIVE_LOWorGPIOHANDLE_REQUEST_OPEN_DRAINeventflags: desired flags for the desired GPIO event line, such asGPIOEVENT_REQUEST_RISING_EDGEorGPIOEVENT_REQUEST_FALLING_EDGEconsumer_label: a desired consumer label for the selected GPIO line(s) such as "my-listener"fd: after a successfulGPIO_GET_LINEEVENT_IOCTLoperation, contains a valid anonymous file descriptor representing the request
Note
This struct is part of ABI v1 and is deprecated.
Use ABI v2 and struct gpio_v2_line_request instead.
struct gpioevent_data #
The actual event being pushed to userspace
Definition
;
Members
timestamp: best estimate of time of event occurrence, in nanosecondsid: event identifier, one ofGPIOEVENT_EVENT_RISING_EDGEorGPIOEVENT_EVENT_FALLING_EDGE
Note
This struct is part of ABI v1 and is deprecated.
Use ABI v2 and struct gpio_v2_line_event instead.