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 NULL 22 * @lines: number of GPIO lines on this chip 23 */ 24 struct 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 NULL 48 * @consumer: a functional name for the consumer of this GPIO line as set by 49 * whatever is using it, will be NULL if there is no current user but may 50 * also be NULL if the consumer doesn't set this up 51 */ 52 struct 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 /* Linerequest flags */ 63 #define GPIOHANDLE_REQUEST_INPUT (1UL << 0) 64 #define GPIOHANDLE_REQUEST_OUTPUT (1UL << 1) 65 #define GPIOHANDLE_REQUEST_ACTIVE_LOW (1UL << 2) 66 #define GPIOHANDLE_REQUEST_OPEN_DRAIN (1UL << 3) 67 #define GPIOHANDLE_REQUEST_OPEN_SOURCE (1UL << 4) 68 #define GPIOHANDLE_REQUEST_BIAS_PULL_UP (1UL << 5) 69 #define GPIOHANDLE_REQUEST_BIAS_PULL_DOWN (1UL << 6) 70 #define GPIOHANDLE_REQUEST_BIAS_DISABLE (1UL << 7) 71 72 /** 73 * struct gpiohandle_request - Information about a GPIO handle request 74 * @lineoffsets: an array of desired lines, specified by offset index for the 75 * associated GPIO device 76 * @flags: desired flags for the desired GPIO lines, such as 77 * GPIOHANDLE_REQUEST_OUTPUT, GPIOHANDLE_REQUEST_ACTIVE_LOW etc, OR:ed 78 * together. Note that even if multiple lines are requested, the same flags 79 * must be applicable to all of them, if you want lines with individual 80 * flags set, request them one by one. It is possible to select 81 * a batch of input or output lines, but they must all have the same 82 * characteristics, i.e. all inputs or all outputs, all active low etc 83 * @default_values: if the GPIOHANDLE_REQUEST_OUTPUT is set for a requested 84 * line, this specifies the default output value, should be 0 (low) or 85 * 1 (high), anything else than 0 or 1 will be interpreted as 1 (high) 86 * @consumer_label: a desired consumer label for the selected GPIO line(s) 87 * such as "my-bitbanged-relay" 88 * @lines: number of lines requested in this request, i.e. the number of 89 * valid fields in the above arrays, set to 1 to request a single line 90 * @fd: if successful this field will contain a valid anonymous file handle 91 * after a GPIO_GET_LINEHANDLE_IOCTL operation, zero or negative value 92 * means error 93 */ 94 struct gpiohandle_request { 95 __u32 lineoffsets[GPIOHANDLES_MAX]; 96 __u32 flags; 97 __u8 default_values[GPIOHANDLES_MAX]; 98 char consumer_label[32]; 99 __u32 lines; 100 int fd; 101 }; 102 103 /** 104 * struct gpiohandle_data - Information of values on a GPIO handle 105 * @values: when getting the state of lines this contains the current 106 * state of a line, when setting the state of lines these should contain 107 * the desired target state 108 */ 109 struct gpiohandle_data { 110 __u8 values[GPIOHANDLES_MAX]; 111 }; 112 113 #define GPIOHANDLE_GET_LINE_VALUES_IOCTL _IOWR(0xB4, 0x08, struct gpiohandle_data) 114 #define GPIOHANDLE_SET_LINE_VALUES_IOCTL _IOWR(0xB4, 0x09, struct gpiohandle_data) 115 116 /* Eventrequest flags */ 117 #define GPIOEVENT_REQUEST_RISING_EDGE (1UL << 0) 118 #define GPIOEVENT_REQUEST_FALLING_EDGE (1UL << 1) 119 #define GPIOEVENT_REQUEST_BOTH_EDGES ((1UL << 0) | (1UL << 1)) 120 121 /** 122 * struct gpioevent_request - Information about a GPIO event request 123 * @lineoffset: the desired line to subscribe to events from, specified by 124 * offset index for the associated GPIO device 125 * @handleflags: desired handle flags for the desired GPIO line, such as 126 * GPIOHANDLE_REQUEST_ACTIVE_LOW or GPIOHANDLE_REQUEST_OPEN_DRAIN 127 * @eventflags: desired flags for the desired GPIO event line, such as 128 * GPIOEVENT_REQUEST_RISING_EDGE or GPIOEVENT_REQUEST_FALLING_EDGE 129 * @consumer_label: a desired consumer label for the selected GPIO line(s) 130 * such as "my-listener" 131 * @fd: if successful this field will contain a valid anonymous file handle 132 * after a GPIO_GET_LINEEVENT_IOCTL operation, zero or negative value 133 * means error 134 */ 135 struct gpioevent_request { 136 __u32 lineoffset; 137 __u32 handleflags; 138 __u32 eventflags; 139 char consumer_label[32]; 140 int fd; 141 }; 142 143 /** 144 * GPIO event types 145 */ 146 #define GPIOEVENT_EVENT_RISING_EDGE 0x01 147 #define GPIOEVENT_EVENT_FALLING_EDGE 0x02 148 149 /** 150 * struct gpioevent_data - The actual event being pushed to userspace 151 * @timestamp: best estimate of time of event occurrence, in nanoseconds 152 * @id: event identifier 153 */ 154 struct gpioevent_data { 155 __u64 timestamp; 156 __u32 id; 157 }; 158 159 #define GPIO_GET_CHIPINFO_IOCTL _IOR(0xB4, 0x01, struct gpiochip_info) 160 #define GPIO_GET_LINEINFO_IOCTL _IOWR(0xB4, 0x02, struct gpioline_info) 161 #define GPIO_GET_LINEHANDLE_IOCTL _IOWR(0xB4, 0x03, struct gpiohandle_request) 162 #define GPIO_GET_LINEEVENT_IOCTL _IOWR(0xB4, 0x04, struct gpioevent_request) 163 164 #endif /* _UAPI_GPIO_H_ */ 165