at v5.7 7.9 kB view raw
1/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ 2/* 3 * <linux/gpio.h> - userspace ABI for the GPIO character devices 4 * 5 * Copyright (C) 2016 Linus Walleij 6 * 7 * This program is free software; you can redistribute it and/or modify it 8 * under the terms of the GNU General Public License version 2 as published by 9 * the Free Software Foundation. 10 */ 11#ifndef _UAPI_GPIO_H_ 12#define _UAPI_GPIO_H_ 13 14#include <linux/ioctl.h> 15#include <linux/types.h> 16 17/** 18 * struct gpiochip_info - Information about a certain GPIO chip 19 * @name: the Linux kernel name of this GPIO chip 20 * @label: a functional name for this GPIO chip, such as a product 21 * number, may be empty 22 * @lines: number of GPIO lines on this chip 23 */ 24struct gpiochip_info { 25 char name[32]; 26 char label[32]; 27 __u32 lines; 28}; 29 30/* Informational flags */ 31#define GPIOLINE_FLAG_KERNEL (1UL << 0) /* Line used by the kernel */ 32#define GPIOLINE_FLAG_IS_OUT (1UL << 1) 33#define GPIOLINE_FLAG_ACTIVE_LOW (1UL << 2) 34#define GPIOLINE_FLAG_OPEN_DRAIN (1UL << 3) 35#define GPIOLINE_FLAG_OPEN_SOURCE (1UL << 4) 36#define GPIOLINE_FLAG_BIAS_PULL_UP (1UL << 5) 37#define GPIOLINE_FLAG_BIAS_PULL_DOWN (1UL << 6) 38#define GPIOLINE_FLAG_BIAS_DISABLE (1UL << 7) 39 40/** 41 * struct gpioline_info - Information about a certain GPIO line 42 * @line_offset: the local offset on this GPIO device, fill this in when 43 * requesting the line information from the kernel 44 * @flags: various flags for this line 45 * @name: the name of this GPIO line, such as the output pin of the line on the 46 * chip, a rail or a pin header name on a board, as specified by the gpio 47 * chip, may be empty 48 * @consumer: a functional name for the consumer of this GPIO line as set by 49 * whatever is using it, will be empty if there is no current user but may 50 * also be empty if the consumer doesn't set this up 51 */ 52struct gpioline_info { 53 __u32 line_offset; 54 __u32 flags; 55 char name[32]; 56 char consumer[32]; 57}; 58 59/* Maximum number of requested handles */ 60#define GPIOHANDLES_MAX 64 61 62/* Possible line status change events */ 63enum { 64 GPIOLINE_CHANGED_REQUESTED = 1, 65 GPIOLINE_CHANGED_RELEASED, 66 GPIOLINE_CHANGED_CONFIG, 67}; 68 69/** 70 * struct gpioline_info_changed - Information about a change in status 71 * of a GPIO line 72 * @info: updated line information 73 * @timestamp: estimate of time of status change occurrence, in nanoseconds 74 * and GPIOLINE_CHANGED_CONFIG 75 * @event_type: one of GPIOLINE_CHANGED_REQUESTED, GPIOLINE_CHANGED_RELEASED 76 * 77 * Note: struct gpioline_info embedded here has 32-bit alignment on its own, 78 * but it works fine with 64-bit alignment too. With its 72 byte size, we can 79 * guarantee there are no implicit holes between it and subsequent members. 80 * The 20-byte padding at the end makes sure we don't add any implicit padding 81 * at the end of the structure on 64-bit architectures. 82 */ 83struct gpioline_info_changed { 84 struct gpioline_info info; 85 __u64 timestamp; 86 __u32 event_type; 87 __u32 padding[5]; /* for future use */ 88}; 89 90/* Linerequest flags */ 91#define GPIOHANDLE_REQUEST_INPUT (1UL << 0) 92#define GPIOHANDLE_REQUEST_OUTPUT (1UL << 1) 93#define GPIOHANDLE_REQUEST_ACTIVE_LOW (1UL << 2) 94#define GPIOHANDLE_REQUEST_OPEN_DRAIN (1UL << 3) 95#define GPIOHANDLE_REQUEST_OPEN_SOURCE (1UL << 4) 96#define GPIOHANDLE_REQUEST_BIAS_PULL_UP (1UL << 5) 97#define GPIOHANDLE_REQUEST_BIAS_PULL_DOWN (1UL << 6) 98#define GPIOHANDLE_REQUEST_BIAS_DISABLE (1UL << 7) 99 100/** 101 * struct gpiohandle_request - Information about a GPIO handle request 102 * @lineoffsets: an array of desired lines, specified by offset index for the 103 * associated GPIO device 104 * @flags: desired flags for the desired GPIO lines, such as 105 * GPIOHANDLE_REQUEST_OUTPUT, GPIOHANDLE_REQUEST_ACTIVE_LOW etc, OR:ed 106 * together. Note that even if multiple lines are requested, the same flags 107 * must be applicable to all of them, if you want lines with individual 108 * flags set, request them one by one. It is possible to select 109 * a batch of input or output lines, but they must all have the same 110 * characteristics, i.e. all inputs or all outputs, all active low etc 111 * @default_values: if the GPIOHANDLE_REQUEST_OUTPUT is set for a requested 112 * line, this specifies the default output value, should be 0 (low) or 113 * 1 (high), anything else than 0 or 1 will be interpreted as 1 (high) 114 * @consumer_label: a desired consumer label for the selected GPIO line(s) 115 * such as "my-bitbanged-relay" 116 * @lines: number of lines requested in this request, i.e. the number of 117 * valid fields in the above arrays, set to 1 to request a single line 118 * @fd: if successful this field will contain a valid anonymous file handle 119 * after a GPIO_GET_LINEHANDLE_IOCTL operation, zero or negative value 120 * means error 121 */ 122struct gpiohandle_request { 123 __u32 lineoffsets[GPIOHANDLES_MAX]; 124 __u32 flags; 125 __u8 default_values[GPIOHANDLES_MAX]; 126 char consumer_label[32]; 127 __u32 lines; 128 int fd; 129}; 130 131/** 132 * struct gpiohandle_config - Configuration for a GPIO handle request 133 * @flags: updated flags for the requested GPIO lines, such as 134 * GPIOHANDLE_REQUEST_OUTPUT, GPIOHANDLE_REQUEST_ACTIVE_LOW etc, OR:ed 135 * together 136 * @default_values: if the GPIOHANDLE_REQUEST_OUTPUT is set in flags, 137 * this specifies the default output value, should be 0 (low) or 138 * 1 (high), anything else than 0 or 1 will be interpreted as 1 (high) 139 * @padding: reserved for future use and should be zero filled 140 */ 141struct gpiohandle_config { 142 __u32 flags; 143 __u8 default_values[GPIOHANDLES_MAX]; 144 __u32 padding[4]; /* padding for future use */ 145}; 146 147#define GPIOHANDLE_SET_CONFIG_IOCTL _IOWR(0xB4, 0x0a, struct gpiohandle_config) 148 149/** 150 * struct gpiohandle_data - Information of values on a GPIO handle 151 * @values: when getting the state of lines this contains the current 152 * state of a line, when setting the state of lines these should contain 153 * the desired target state 154 */ 155struct gpiohandle_data { 156 __u8 values[GPIOHANDLES_MAX]; 157}; 158 159#define GPIOHANDLE_GET_LINE_VALUES_IOCTL _IOWR(0xB4, 0x08, struct gpiohandle_data) 160#define GPIOHANDLE_SET_LINE_VALUES_IOCTL _IOWR(0xB4, 0x09, struct gpiohandle_data) 161 162/* Eventrequest flags */ 163#define GPIOEVENT_REQUEST_RISING_EDGE (1UL << 0) 164#define GPIOEVENT_REQUEST_FALLING_EDGE (1UL << 1) 165#define GPIOEVENT_REQUEST_BOTH_EDGES ((1UL << 0) | (1UL << 1)) 166 167/** 168 * struct gpioevent_request - Information about a GPIO event request 169 * @lineoffset: the desired line to subscribe to events from, specified by 170 * offset index for the associated GPIO device 171 * @handleflags: desired handle flags for the desired GPIO line, such as 172 * GPIOHANDLE_REQUEST_ACTIVE_LOW or GPIOHANDLE_REQUEST_OPEN_DRAIN 173 * @eventflags: desired flags for the desired GPIO event line, such as 174 * GPIOEVENT_REQUEST_RISING_EDGE or GPIOEVENT_REQUEST_FALLING_EDGE 175 * @consumer_label: a desired consumer label for the selected GPIO line(s) 176 * such as "my-listener" 177 * @fd: if successful this field will contain a valid anonymous file handle 178 * after a GPIO_GET_LINEEVENT_IOCTL operation, zero or negative value 179 * means error 180 */ 181struct gpioevent_request { 182 __u32 lineoffset; 183 __u32 handleflags; 184 __u32 eventflags; 185 char consumer_label[32]; 186 int fd; 187}; 188 189/** 190 * GPIO event types 191 */ 192#define GPIOEVENT_EVENT_RISING_EDGE 0x01 193#define GPIOEVENT_EVENT_FALLING_EDGE 0x02 194 195/** 196 * struct gpioevent_data - The actual event being pushed to userspace 197 * @timestamp: best estimate of time of event occurrence, in nanoseconds 198 * @id: event identifier 199 */ 200struct gpioevent_data { 201 __u64 timestamp; 202 __u32 id; 203}; 204 205#define GPIO_GET_CHIPINFO_IOCTL _IOR(0xB4, 0x01, struct gpiochip_info) 206#define GPIO_GET_LINEINFO_IOCTL _IOWR(0xB4, 0x02, struct gpioline_info) 207#define GPIO_GET_LINEINFO_WATCH_IOCTL _IOWR(0xB4, 0x0b, struct gpioline_info) 208#define GPIO_GET_LINEINFO_UNWATCH_IOCTL _IOWR(0xB4, 0x0c, __u32) 209#define GPIO_GET_LINEHANDLE_IOCTL _IOWR(0xB4, 0x03, struct gpiohandle_request) 210#define GPIO_GET_LINEEVENT_IOCTL _IOWR(0xB4, 0x04, struct gpioevent_request) 211 212#endif /* _UAPI_GPIO_H_ */