---
name: "gpio"
section: "4"
platform: "openbsd"
package: "man"
version: "8.0-current-20261101"
release: "OpenBSD 8.0-current (2026-11-01)"
platforms: ["freebsd", "openbsd"]
url: "https://new.carta.tech/gpio/4"
---

# gpio(4)

General Purpose Input/Output

## NAME

**gpio** – General Purpose Input/Output

## SYNOPSIS

**gpio\* at ath?** **gpio\* at bcmgpio?** (arm64, armv7) **gpio\* at glxpcib?** (i386) **gpio\* at gscpcib?** (i386) **gpio\* at isagpio?** **gpio\* at mpfgpio?** (riscv64) **gpio\* at nsclpcsio?** **gpio\* at omgpio?** (armv7) **gpio\* at pcagpio?** **gpio\* at pcaled?** **gpio\* at sfgpio?** (riscv64) **gpio\* at skgpio?** (amd64, i386) **gpio\* at smtgpio?** (riscv64) **gpio\* at sxipio?** (arm64, armv7) **gpio0 at voyager?** (loongson)

**#include \<sys/types.h\>**

**#include \<sys/gpio.h\>**

**#include \<sys/ioctl.h\>**

## DESCRIPTION

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)](/ioctl/2.md) 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.

## IOCTL INTERFACE

The following structures and constants are defined in the ⟨sys/gpio.h⟩ header file:

- GPIOINFO *struct gpio\_info*

  Returns information about the GPIO controller in the *gpio\_info* structure:

  ```
  struct gpio_info {
  	int gpio_npins;		/* total number of pins available */
  };
  ```

- GPIOPINREAD *struct gpio\_pin\_op*

  Returns the input pin value in the *gpio\_pin\_op* structure:

  ```
  #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\_op*

  Writes the output value to the pin. The value set in the *gp\_value* field must be either GPIO\_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\_op*

  Toggles the pin output value, i.e. changes it to the opposite. *gp\_value* field is ignored and on return contains the old pin state.

- GPIOPINSET *struct gpio\_pin\_set*

  Changes pin configuration flags with the new ones provided in the *gpio\_pin\_set* structure:

  ```
  #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

    input direction

  - GPIO\_PIN\_OUTPUT

    output direction

  - GPIO\_PIN\_INOUT

    bi-directional

  - GPIO\_PIN\_OPENDRAIN

    open-drain output

  - GPIO\_PIN\_PUSHPULL

    push-pull output

  - GPIO\_PIN\_TRISTATE

    output disabled

  - GPIO\_PIN\_PULLUP

    internal pull-up enabled

  - GPIO\_PIN\_PULLDOWN

    internal pull-down enabled

  - GPIO\_PIN\_INVIN

    invert input

  - GPIO\_PIN\_INVOUT

    invert output

    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\_set*

  Unset the specified pin, i.e. clear its name and make it inaccessible at securelevels greater than 0.

- GPIOATTACH *struct gpio\_attach*

  Attach the device described in the *gpio\_attach* structure on this gpio device.

  ```
  struct gpio_attach {
  	char ga_dvname[16];     /* device name */
  	int ga_offset;		/* pin number */
  	u_int32_t ga_mask;	/* binary mask */
  };
  ```

- GPIODETACH *struct gpio\_attach*

  Detach a device from this gpio device that was previously attached using the GPIOATTACH [ioctl(2)](/ioctl/2.md). The *ga\_offset* and *ga\_mask* fields of the *gpio\_attach* structure are ignored.

## FILES

- /dev/gpio*u*

  GPIO device unit *u* file.

## SEE ALSO

[ioctl(2)](/ioctl/2.md), [gpioctl(8)](/gpioctl/8.md)

## HISTORY

The **gpio** device first appeared in OpenBSD 3.6.

## AUTHORS

The **gpio** driver was written by Alexander Yurchenko ⟨*grange@openbsd.org*⟩. Runtime device attachment was added by Marc Balmer ⟨*mbalmer@openbsd.org*⟩.

## BUGS

Event capabilities are not supported.
