linux/include/uapi/linux/gpio.h

/* SPDX-License-Identifier: GPL-2.0-only WITH Linux-syscall-note */
/*
 * <linux/gpio.h> - userspace ABI for the GPIO character devices
 *
 * Copyright (C) 2016 Linus Walleij
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License version 2 as published by
 * the Free Software Foundation.
 */
#ifndef _UAPI_GPIO_H_
#define _UAPI_GPIO_H_

#include <linux/const.h>
#include <linux/ioctl.h>
#include <linux/types.h>

/*
 * The maximum size of name and label arrays.
 *
 * Must be a multiple of 8 to ensure 32/64-bit alignment of structs.
 */
#define GPIO_MAX_NAME_SIZE

/**
 * struct gpiochip_info - Information about a certain GPIO chip
 * @name: the Linux kernel name of this GPIO chip
 * @label: a functional name for this GPIO chip, such as a product
 * number, may be empty (i.e. label[0] == '\0')
 * @lines: number of GPIO lines on this chip
 */
struct gpiochip_info {};

/*
 * Maximum number of requested lines.
 *
 * Must be no greater than 64, as bitmaps are restricted here to 64-bits
 * for simplicity, and a multiple of 2 to ensure 32/64-bit alignment of
 * structs.
 */
#define GPIO_V2_LINES_MAX

/*
 * The maximum number of configuration attributes associated with a line
 * request.
 */
#define GPIO_V2_LINE_NUM_ATTRS_MAX

/**
 * enum gpio_v2_line_flag - &struct gpio_v2_line_attribute.flags values
 * @GPIO_V2_LINE_FLAG_USED: line is not available for request
 * @GPIO_V2_LINE_FLAG_ACTIVE_LOW: line active state is physical low
 * @GPIO_V2_LINE_FLAG_INPUT: line is an input
 * @GPIO_V2_LINE_FLAG_OUTPUT: line is an output
 * @GPIO_V2_LINE_FLAG_EDGE_RISING: line detects rising (inactive to active)
 * edges
 * @GPIO_V2_LINE_FLAG_EDGE_FALLING: line detects falling (active to
 * inactive) edges
 * @GPIO_V2_LINE_FLAG_OPEN_DRAIN: line is an open drain output
 * @GPIO_V2_LINE_FLAG_OPEN_SOURCE: line is an open source output
 * @GPIO_V2_LINE_FLAG_BIAS_PULL_UP: line has pull-up bias enabled
 * @GPIO_V2_LINE_FLAG_BIAS_PULL_DOWN: line has pull-down bias enabled
 * @GPIO_V2_LINE_FLAG_BIAS_DISABLED: line has bias disabled
 * @GPIO_V2_LINE_FLAG_EVENT_CLOCK_REALTIME: line events contain REALTIME timestamps
 * @GPIO_V2_LINE_FLAG_EVENT_CLOCK_HTE: line events contain timestamps from
 * the hardware timestamping engine (HTE) subsystem
 */
enum gpio_v2_line_flag {};

/**
 * struct gpio_v2_line_values - Values of GPIO lines
 * @bits: a bitmap containing the value of the lines, set to 1 for active
 * and 0 for inactive
 * @mask: a bitmap identifying the lines to get or set, with each bit
 * number corresponding to the index into &struct
 * gpio_v2_line_request.offsets
 */
struct gpio_v2_line_values {};

/**
 * enum gpio_v2_line_attr_id - &struct gpio_v2_line_attribute.id values
 * identifying which field of the attribute union is in use.
 * @GPIO_V2_LINE_ATTR_ID_FLAGS: flags field is in use
 * @GPIO_V2_LINE_ATTR_ID_OUTPUT_VALUES: values field is in use
 * @GPIO_V2_LINE_ATTR_ID_DEBOUNCE: debounce_period_us field is in use
 */
enum gpio_v2_line_attr_id {};

/**
 * struct gpio_v2_line_attribute - a configurable attribute of a line
 * @id: attribute identifier with value from &enum gpio_v2_line_attr_id
 * @padding: reserved for future use and must be zero filled
 * @flags: if id is %GPIO_V2_LINE_ATTR_ID_FLAGS, the flags for the GPIO
 * line, with values from &enum gpio_v2_line_flag, such as
 * %GPIO_V2_LINE_FLAG_ACTIVE_LOW, %GPIO_V2_LINE_FLAG_OUTPUT etc, added
 * together.  This overrides the default flags contained in the &struct
 * gpio_v2_line_config for the associated line.
 * @values: if id is %GPIO_V2_LINE_ATTR_ID_OUTPUT_VALUES, a bitmap
 * containing the values to which the lines will be set, with each bit
 * number corresponding to the index into &struct
 * gpio_v2_line_request.offsets
 * @debounce_period_us: if id is %GPIO_V2_LINE_ATTR_ID_DEBOUNCE, the
 * desired debounce period, in microseconds
 */
struct gpio_v2_line_attribute {};

/**
 * struct gpio_v2_line_config_attribute - a configuration attribute
 * associated with one or more of the requested lines.
 * @attr: the configurable attribute
 * @mask: a bitmap identifying the lines to which the attribute applies,
 * with each bit number corresponding to the index into &struct
 * gpio_v2_line_request.offsets
 */
struct gpio_v2_line_config_attribute {};

/**
 * struct gpio_v2_line_config - Configuration for GPIO lines
 * @flags: flags for the GPIO lines, with values from &enum
 * gpio_v2_line_flag, such as %GPIO_V2_LINE_FLAG_ACTIVE_LOW,
 * %GPIO_V2_LINE_FLAG_OUTPUT etc, added together.  This is the default for
 * all requested lines but may be overridden for particular lines using
 * @attrs.
 * @num_attrs: the number of attributes in @attrs
 * @padding: reserved for future use and must be zero filled
 * @attrs: the configuration attributes associated with the requested
 * lines.  Any attribute should only be associated with a particular line
 * once.  If an attribute is associated with a line multiple times then the
 * first occurrence (i.e. lowest index) has precedence.
 */
struct gpio_v2_line_config {};

/**
 * struct gpio_v2_line_request - Information about a request for GPIO lines
 * @offsets: an array of desired lines, specified by offset index for the
 * associated GPIO chip
 * @consumer: a desired consumer label for the selected GPIO lines such as
 * "my-bitbanged-relay"
 * @config: requested configuration for the lines
 * @num_lines: number of lines requested in this request, i.e. the number
 * of valid fields in the %GPIO_V2_LINES_MAX sized arrays, set to 1 to
 * request a single line
 * @event_buffer_size: a suggested minimum number of line events that the
 * kernel should buffer.  This is only relevant if edge detection is
 * enabled in the configuration. Note that this is only a suggested value
 * and the kernel may allocate a larger buffer or cap the size of the
 * buffer. If this field is zero then the buffer size defaults to a minimum
 * of @num_lines * 16.
 * @padding: reserved for future use and must be zero filled
 * @fd: after a successful %GPIO_V2_GET_LINE_IOCTL operation, contains
 * a valid anonymous file descriptor representing the request
 */
struct gpio_v2_line_request {};

/**
 * struct gpio_v2_line_info - Information about a certain GPIO line
 * @name: 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
 * @offset: the local offset on this GPIO chip, fill this in when
 * requesting the line information from the kernel
 * @num_attrs: the number of attributes in @attrs
 * @flags: flags for this GPIO line, with values from &enum
 * gpio_v2_line_flag, such as %GPIO_V2_LINE_FLAG_ACTIVE_LOW,
 * %GPIO_V2_LINE_FLAG_OUTPUT etc, added together
 * @attrs: the configuration attributes associated with the line
 * @padding: reserved for future use
 */
struct gpio_v2_line_info {};

/**
 * enum gpio_v2_line_changed_type - &struct gpio_v2_line_changed.event_type
 * values
 * @GPIO_V2_LINE_CHANGED_REQUESTED: line has been requested
 * @GPIO_V2_LINE_CHANGED_RELEASED: line has been released
 * @GPIO_V2_LINE_CHANGED_CONFIG: line has been reconfigured
 */
enum gpio_v2_line_changed_type {};

/**
 * struct gpio_v2_line_info_changed - Information about a change in status
 * of a GPIO line
 * @info: updated line information
 * @timestamp_ns: estimate of time of status change occurrence, in nanoseconds
 * @event_type: the type of change with a value from &enum
 * gpio_v2_line_changed_type
 * @padding: reserved for future use
 */
struct gpio_v2_line_info_changed {};

/**
 * enum gpio_v2_line_event_id - &struct gpio_v2_line_event.id values
 * @GPIO_V2_LINE_EVENT_RISING_EDGE: event triggered by a rising edge
 * @GPIO_V2_LINE_EVENT_FALLING_EDGE: event triggered by a falling edge
 */
enum gpio_v2_line_event_id {};

/**
 * struct gpio_v2_line_event - The actual event being pushed to userspace
 * @timestamp_ns: best estimate of time of event occurrence, in nanoseconds
 * @id: event identifier with value from &enum gpio_v2_line_event_id
 * @offset: the offset of the line that triggered the event
 * @seqno: the sequence number for this event in the sequence of events for
 * all the lines in this line request
 * @line_seqno: the sequence number for this event in the sequence of
 * events on this particular line
 * @padding: reserved for future use
 *
 * By default the @timestamp_ns is read from %CLOCK_MONOTONIC and is
 * intended to allow the accurate measurement of the time between events.
 * It does not provide the wall-clock time.
 *
 * If the %GPIO_V2_LINE_FLAG_EVENT_CLOCK_REALTIME flag is set then the
 * @timestamp_ns is read from %CLOCK_REALTIME.
 *
 * If the %GPIO_V2_LINE_FLAG_EVENT_CLOCK_HTE flag is set then the
 * @timestamp_ns is provided by the hardware timestamping engine (HTE)
 * subsystem.
 */
struct gpio_v2_line_event {};

/*
 * ABI v1
 *
 * This version of the ABI is deprecated.
 * Use the latest version of the ABI, defined above, instead.
 */

/* Informational flags */
#define GPIOLINE_FLAG_KERNEL
#define GPIOLINE_FLAG_IS_OUT
#define GPIOLINE_FLAG_ACTIVE_LOW
#define GPIOLINE_FLAG_OPEN_DRAIN
#define GPIOLINE_FLAG_OPEN_SOURCE
#define GPIOLINE_FLAG_BIAS_PULL_UP
#define GPIOLINE_FLAG_BIAS_PULL_DOWN
#define GPIOLINE_FLAG_BIAS_DISABLE

/**
 * struct gpioline_info - Information about a certain GPIO line
 * @line_offset: the local offset on this GPIO device, fill this in when
 * requesting the line information from the kernel
 * @flags: various flags for this line
 * @name: 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 {};

/* Maximum number of requested handles */
#define GPIOHANDLES_MAX

/* Possible line status change events */
enum {};

/**
 * struct gpioline_info_changed - Information about a change in status
 * of a GPIO line
 * @info: updated line information
 * @timestamp: estimate of time of status change occurrence, in nanoseconds
 * @event_type: one of %GPIOLINE_CHANGED_REQUESTED,
 * %GPIOLINE_CHANGED_RELEASED and %GPIOLINE_CHANGED_CONFIG
 * @padding: reserved for future use
 *
 * 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 gpioline_info_changed {};

/* Linerequest flags */
#define GPIOHANDLE_REQUEST_INPUT
#define GPIOHANDLE_REQUEST_OUTPUT
#define GPIOHANDLE_REQUEST_ACTIVE_LOW
#define GPIOHANDLE_REQUEST_OPEN_DRAIN
#define GPIOHANDLE_REQUEST_OPEN_SOURCE
#define GPIOHANDLE_REQUEST_BIAS_PULL_UP
#define GPIOHANDLE_REQUEST_BIAS_PULL_DOWN
#define GPIOHANDLE_REQUEST_BIAS_DISABLE

/**
 * struct gpiohandle_request - Information about a GPIO handle request
 * @lineoffsets: an array of desired lines, specified by offset index for the
 * associated GPIO device
 * @flags: desired flags for the desired GPIO lines, such as
 * %GPIOHANDLE_REQUEST_OUTPUT, %GPIOHANDLE_REQUEST_ACTIVE_LOW etc, 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 etc
 * @default_values: if the %GPIOHANDLE_REQUEST_OUTPUT is 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 line
 * @fd: after a successful %GPIO_GET_LINEHANDLE_IOCTL operation, 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_request {};

/**
 * struct gpiohandle_config - Configuration for a GPIO handle request
 * @flags: updated flags for the requested GPIO lines, such as
 * %GPIOHANDLE_REQUEST_OUTPUT, %GPIOHANDLE_REQUEST_ACTIVE_LOW etc, added
 * together
 * @default_values: if the %GPIOHANDLE_REQUEST_OUTPUT is 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_config {};

/**
 * struct gpiohandle_data - Information of values on a GPIO handle
 * @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 gpiohandle_data {};

/* Eventrequest flags */
#define GPIOEVENT_REQUEST_RISING_EDGE
#define GPIOEVENT_REQUEST_FALLING_EDGE
#define GPIOEVENT_REQUEST_BOTH_EDGES

/**
 * struct gpioevent_request - Information about a GPIO event request
 * @lineoffset: the desired line to subscribe to events from, specified by
 * offset index for the associated GPIO device
 * @handleflags: desired handle flags for the desired GPIO line, such as
 * %GPIOHANDLE_REQUEST_ACTIVE_LOW or %GPIOHANDLE_REQUEST_OPEN_DRAIN
 * @eventflags: desired flags for the desired GPIO event line, such as
 * %GPIOEVENT_REQUEST_RISING_EDGE or %GPIOEVENT_REQUEST_FALLING_EDGE
 * @consumer_label: a desired consumer label for the selected GPIO line(s)
 * such as "my-listener"
 * @fd: after a successful %GPIO_GET_LINEEVENT_IOCTL operation, 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_request {};

/*
 * GPIO event types
 */
#define GPIOEVENT_EVENT_RISING_EDGE
#define GPIOEVENT_EVENT_FALLING_EDGE

/**
 * struct gpioevent_data - The actual event being pushed to userspace
 * @timestamp: best estimate of time of event occurrence, in nanoseconds
 * @id: event identifier, one of %GPIOEVENT_EVENT_RISING_EDGE or
 *  %GPIOEVENT_EVENT_FALLING_EDGE
 *
 * Note: This struct is part of ABI v1 and is deprecated.
 * Use ABI v2 and &struct gpio_v2_line_event instead.
 */
struct gpioevent_data {};

/*
 * v1 and v2 ioctl()s
 */
#define GPIO_GET_CHIPINFO_IOCTL
#define GPIO_GET_LINEINFO_UNWATCH_IOCTL

/*
 * v2 ioctl()s
 */
#define GPIO_V2_GET_LINEINFO_IOCTL
#define GPIO_V2_GET_LINEINFO_WATCH_IOCTL
#define GPIO_V2_GET_LINE_IOCTL
#define GPIO_V2_LINE_SET_CONFIG_IOCTL
#define GPIO_V2_LINE_GET_VALUES_IOCTL
#define GPIO_V2_LINE_SET_VALUES_IOCTL

/*
 * v1 ioctl()s
 *
 * These ioctl()s are deprecated.  Use the v2 equivalent instead.
 */
#define GPIO_GET_LINEINFO_IOCTL
#define GPIO_GET_LINEHANDLE_IOCTL
#define GPIO_GET_LINEEVENT_IOCTL
#define GPIOHANDLE_GET_LINE_VALUES_IOCTL
#define GPIOHANDLE_SET_LINE_VALUES_IOCTL
#define GPIOHANDLE_SET_CONFIG_IOCTL
#define GPIO_GET_LINEINFO_WATCH_IOCTL

#endif /* _UAPI_GPIO_H_ */