1*4882a593Smuzhiyun /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ 2*4882a593Smuzhiyun /* 3*4882a593Smuzhiyun * <linux/gpio.h> - userspace ABI for the GPIO character devices 4*4882a593Smuzhiyun * 5*4882a593Smuzhiyun * Copyright (C) 2016 Linus Walleij 6*4882a593Smuzhiyun * 7*4882a593Smuzhiyun * This program is free software; you can redistribute it and/or modify it 8*4882a593Smuzhiyun * under the terms of the GNU General Public License version 2 as published by 9*4882a593Smuzhiyun * the Free Software Foundation. 10*4882a593Smuzhiyun */ 11*4882a593Smuzhiyun #ifndef _UAPI_GPIO_H_ 12*4882a593Smuzhiyun #define _UAPI_GPIO_H_ 13*4882a593Smuzhiyun 14*4882a593Smuzhiyun #include <linux/const.h> 15*4882a593Smuzhiyun #include <linux/ioctl.h> 16*4882a593Smuzhiyun #include <linux/types.h> 17*4882a593Smuzhiyun 18*4882a593Smuzhiyun /* 19*4882a593Smuzhiyun * The maximum size of name and label arrays. 20*4882a593Smuzhiyun * 21*4882a593Smuzhiyun * Must be a multiple of 8 to ensure 32/64-bit alignment of structs. 22*4882a593Smuzhiyun */ 23*4882a593Smuzhiyun #define GPIO_MAX_NAME_SIZE 32 24*4882a593Smuzhiyun 25*4882a593Smuzhiyun /** 26*4882a593Smuzhiyun * struct gpiochip_info - Information about a certain GPIO chip 27*4882a593Smuzhiyun * @name: the Linux kernel name of this GPIO chip 28*4882a593Smuzhiyun * @label: a functional name for this GPIO chip, such as a product 29*4882a593Smuzhiyun * number, may be empty (i.e. label[0] == '\0') 30*4882a593Smuzhiyun * @lines: number of GPIO lines on this chip 31*4882a593Smuzhiyun */ 32*4882a593Smuzhiyun struct gpiochip_info { 33*4882a593Smuzhiyun char name[GPIO_MAX_NAME_SIZE]; 34*4882a593Smuzhiyun char label[GPIO_MAX_NAME_SIZE]; 35*4882a593Smuzhiyun __u32 lines; 36*4882a593Smuzhiyun }; 37*4882a593Smuzhiyun 38*4882a593Smuzhiyun /* 39*4882a593Smuzhiyun * Maximum number of requested lines. 40*4882a593Smuzhiyun * 41*4882a593Smuzhiyun * Must be no greater than 64, as bitmaps are restricted here to 64-bits 42*4882a593Smuzhiyun * for simplicity, and a multiple of 2 to ensure 32/64-bit alignment of 43*4882a593Smuzhiyun * structs. 44*4882a593Smuzhiyun */ 45*4882a593Smuzhiyun #define GPIO_V2_LINES_MAX 64 46*4882a593Smuzhiyun 47*4882a593Smuzhiyun /* 48*4882a593Smuzhiyun * The maximum number of configuration attributes associated with a line 49*4882a593Smuzhiyun * request. 50*4882a593Smuzhiyun */ 51*4882a593Smuzhiyun #define GPIO_V2_LINE_NUM_ATTRS_MAX 10 52*4882a593Smuzhiyun 53*4882a593Smuzhiyun /** 54*4882a593Smuzhiyun * enum gpio_v2_line_flag - &struct gpio_v2_line_attribute.flags values 55*4882a593Smuzhiyun * @GPIO_V2_LINE_FLAG_USED: line is not available for request 56*4882a593Smuzhiyun * @GPIO_V2_LINE_FLAG_ACTIVE_LOW: line active state is physical low 57*4882a593Smuzhiyun * @GPIO_V2_LINE_FLAG_INPUT: line is an input 58*4882a593Smuzhiyun * @GPIO_V2_LINE_FLAG_OUTPUT: line is an output 59*4882a593Smuzhiyun * @GPIO_V2_LINE_FLAG_EDGE_RISING: line detects rising (inactive to active) 60*4882a593Smuzhiyun * edges 61*4882a593Smuzhiyun * @GPIO_V2_LINE_FLAG_EDGE_FALLING: line detects falling (active to 62*4882a593Smuzhiyun * inactive) edges 63*4882a593Smuzhiyun * @GPIO_V2_LINE_FLAG_OPEN_DRAIN: line is an open drain output 64*4882a593Smuzhiyun * @GPIO_V2_LINE_FLAG_OPEN_SOURCE: line is an open source output 65*4882a593Smuzhiyun * @GPIO_V2_LINE_FLAG_BIAS_PULL_UP: line has pull-up bias enabled 66*4882a593Smuzhiyun * @GPIO_V2_LINE_FLAG_BIAS_PULL_DOWN: line has pull-down bias enabled 67*4882a593Smuzhiyun * @GPIO_V2_LINE_FLAG_BIAS_DISABLED: line has bias disabled 68*4882a593Smuzhiyun */ 69*4882a593Smuzhiyun enum gpio_v2_line_flag { 70*4882a593Smuzhiyun GPIO_V2_LINE_FLAG_USED = _BITULL(0), 71*4882a593Smuzhiyun GPIO_V2_LINE_FLAG_ACTIVE_LOW = _BITULL(1), 72*4882a593Smuzhiyun GPIO_V2_LINE_FLAG_INPUT = _BITULL(2), 73*4882a593Smuzhiyun GPIO_V2_LINE_FLAG_OUTPUT = _BITULL(3), 74*4882a593Smuzhiyun GPIO_V2_LINE_FLAG_EDGE_RISING = _BITULL(4), 75*4882a593Smuzhiyun GPIO_V2_LINE_FLAG_EDGE_FALLING = _BITULL(5), 76*4882a593Smuzhiyun GPIO_V2_LINE_FLAG_OPEN_DRAIN = _BITULL(6), 77*4882a593Smuzhiyun GPIO_V2_LINE_FLAG_OPEN_SOURCE = _BITULL(7), 78*4882a593Smuzhiyun GPIO_V2_LINE_FLAG_BIAS_PULL_UP = _BITULL(8), 79*4882a593Smuzhiyun GPIO_V2_LINE_FLAG_BIAS_PULL_DOWN = _BITULL(9), 80*4882a593Smuzhiyun GPIO_V2_LINE_FLAG_BIAS_DISABLED = _BITULL(10), 81*4882a593Smuzhiyun }; 82*4882a593Smuzhiyun 83*4882a593Smuzhiyun /** 84*4882a593Smuzhiyun * struct gpio_v2_line_values - Values of GPIO lines 85*4882a593Smuzhiyun * @bits: a bitmap containing the value of the lines, set to 1 for active 86*4882a593Smuzhiyun * and 0 for inactive. 87*4882a593Smuzhiyun * @mask: a bitmap identifying the lines to get or set, with each bit 88*4882a593Smuzhiyun * number corresponding to the index into &struct 89*4882a593Smuzhiyun * gpio_v2_line_request.offsets. 90*4882a593Smuzhiyun */ 91*4882a593Smuzhiyun struct gpio_v2_line_values { 92*4882a593Smuzhiyun __aligned_u64 bits; 93*4882a593Smuzhiyun __aligned_u64 mask; 94*4882a593Smuzhiyun }; 95*4882a593Smuzhiyun 96*4882a593Smuzhiyun /** 97*4882a593Smuzhiyun * enum gpio_v2_line_attr_id - &struct gpio_v2_line_attribute.id values 98*4882a593Smuzhiyun * identifying which field of the attribute union is in use. 99*4882a593Smuzhiyun * @GPIO_V2_LINE_ATTR_ID_FLAGS: flags field is in use 100*4882a593Smuzhiyun * @GPIO_V2_LINE_ATTR_ID_OUTPUT_VALUES: values field is in use 101*4882a593Smuzhiyun * @GPIO_V2_LINE_ATTR_ID_DEBOUNCE: debounce_period_us field is in use 102*4882a593Smuzhiyun */ 103*4882a593Smuzhiyun enum gpio_v2_line_attr_id { 104*4882a593Smuzhiyun GPIO_V2_LINE_ATTR_ID_FLAGS = 1, 105*4882a593Smuzhiyun GPIO_V2_LINE_ATTR_ID_OUTPUT_VALUES = 2, 106*4882a593Smuzhiyun GPIO_V2_LINE_ATTR_ID_DEBOUNCE = 3, 107*4882a593Smuzhiyun }; 108*4882a593Smuzhiyun 109*4882a593Smuzhiyun /** 110*4882a593Smuzhiyun * struct gpio_v2_line_attribute - a configurable attribute of a line 111*4882a593Smuzhiyun * @id: attribute identifier with value from &enum gpio_v2_line_attr_id 112*4882a593Smuzhiyun * @padding: reserved for future use and must be zero filled 113*4882a593Smuzhiyun * @flags: if id is %GPIO_V2_LINE_ATTR_ID_FLAGS, the flags for the GPIO 114*4882a593Smuzhiyun * line, with values from &enum gpio_v2_line_flag, such as 115*4882a593Smuzhiyun * %GPIO_V2_LINE_FLAG_ACTIVE_LOW, %GPIO_V2_LINE_FLAG_OUTPUT etc, added 116*4882a593Smuzhiyun * together. This overrides the default flags contained in the &struct 117*4882a593Smuzhiyun * gpio_v2_line_config for the associated line. 118*4882a593Smuzhiyun * @values: if id is %GPIO_V2_LINE_ATTR_ID_OUTPUT_VALUES, a bitmap 119*4882a593Smuzhiyun * containing the values to which the lines will be set, with each bit 120*4882a593Smuzhiyun * number corresponding to the index into &struct 121*4882a593Smuzhiyun * gpio_v2_line_request.offsets. 122*4882a593Smuzhiyun * @debounce_period_us: if id is %GPIO_V2_LINE_ATTR_ID_DEBOUNCE, the 123*4882a593Smuzhiyun * desired debounce period, in microseconds 124*4882a593Smuzhiyun */ 125*4882a593Smuzhiyun struct gpio_v2_line_attribute { 126*4882a593Smuzhiyun __u32 id; 127*4882a593Smuzhiyun __u32 padding; 128*4882a593Smuzhiyun union { 129*4882a593Smuzhiyun __aligned_u64 flags; 130*4882a593Smuzhiyun __aligned_u64 values; 131*4882a593Smuzhiyun __u32 debounce_period_us; 132*4882a593Smuzhiyun }; 133*4882a593Smuzhiyun }; 134*4882a593Smuzhiyun 135*4882a593Smuzhiyun /** 136*4882a593Smuzhiyun * struct gpio_v2_line_config_attribute - a configuration attribute 137*4882a593Smuzhiyun * associated with one or more of the requested lines. 138*4882a593Smuzhiyun * @attr: the configurable attribute 139*4882a593Smuzhiyun * @mask: a bitmap identifying the lines to which the attribute applies, 140*4882a593Smuzhiyun * with each bit number corresponding to the index into &struct 141*4882a593Smuzhiyun * gpio_v2_line_request.offsets. 142*4882a593Smuzhiyun */ 143*4882a593Smuzhiyun struct gpio_v2_line_config_attribute { 144*4882a593Smuzhiyun struct gpio_v2_line_attribute attr; 145*4882a593Smuzhiyun __aligned_u64 mask; 146*4882a593Smuzhiyun }; 147*4882a593Smuzhiyun 148*4882a593Smuzhiyun /** 149*4882a593Smuzhiyun * struct gpio_v2_line_config - Configuration for GPIO lines 150*4882a593Smuzhiyun * @flags: flags for the GPIO lines, with values from &enum 151*4882a593Smuzhiyun * gpio_v2_line_flag, such as %GPIO_V2_LINE_FLAG_ACTIVE_LOW, 152*4882a593Smuzhiyun * %GPIO_V2_LINE_FLAG_OUTPUT etc, added together. This is the default for 153*4882a593Smuzhiyun * all requested lines but may be overridden for particular lines using 154*4882a593Smuzhiyun * @attrs. 155*4882a593Smuzhiyun * @num_attrs: the number of attributes in @attrs 156*4882a593Smuzhiyun * @padding: reserved for future use and must be zero filled 157*4882a593Smuzhiyun * @attrs: the configuration attributes associated with the requested 158*4882a593Smuzhiyun * lines. Any attribute should only be associated with a particular line 159*4882a593Smuzhiyun * once. If an attribute is associated with a line multiple times then the 160*4882a593Smuzhiyun * first occurrence (i.e. lowest index) has precedence. 161*4882a593Smuzhiyun */ 162*4882a593Smuzhiyun struct gpio_v2_line_config { 163*4882a593Smuzhiyun __aligned_u64 flags; 164*4882a593Smuzhiyun __u32 num_attrs; 165*4882a593Smuzhiyun /* Pad to fill implicit padding and reserve space for future use. */ 166*4882a593Smuzhiyun __u32 padding[5]; 167*4882a593Smuzhiyun struct gpio_v2_line_config_attribute attrs[GPIO_V2_LINE_NUM_ATTRS_MAX]; 168*4882a593Smuzhiyun }; 169*4882a593Smuzhiyun 170*4882a593Smuzhiyun /** 171*4882a593Smuzhiyun * struct gpio_v2_line_request - Information about a request for GPIO lines 172*4882a593Smuzhiyun * @offsets: an array of desired lines, specified by offset index for the 173*4882a593Smuzhiyun * associated GPIO chip 174*4882a593Smuzhiyun * @consumer: a desired consumer label for the selected GPIO lines such as 175*4882a593Smuzhiyun * "my-bitbanged-relay" 176*4882a593Smuzhiyun * @config: requested configuration for the lines. 177*4882a593Smuzhiyun * @num_lines: number of lines requested in this request, i.e. the number 178*4882a593Smuzhiyun * of valid fields in the %GPIO_V2_LINES_MAX sized arrays, set to 1 to 179*4882a593Smuzhiyun * request a single line 180*4882a593Smuzhiyun * @event_buffer_size: a suggested minimum number of line events that the 181*4882a593Smuzhiyun * kernel should buffer. This is only relevant if edge detection is 182*4882a593Smuzhiyun * enabled in the configuration. Note that this is only a suggested value 183*4882a593Smuzhiyun * and the kernel may allocate a larger buffer or cap the size of the 184*4882a593Smuzhiyun * buffer. If this field is zero then the buffer size defaults to a minimum 185*4882a593Smuzhiyun * of @num_lines * 16. 186*4882a593Smuzhiyun * @padding: reserved for future use and must be zero filled 187*4882a593Smuzhiyun * @fd: if successful this field will contain a valid anonymous file handle 188*4882a593Smuzhiyun * after a %GPIO_GET_LINE_IOCTL operation, zero or negative value means 189*4882a593Smuzhiyun * error 190*4882a593Smuzhiyun */ 191*4882a593Smuzhiyun struct gpio_v2_line_request { 192*4882a593Smuzhiyun __u32 offsets[GPIO_V2_LINES_MAX]; 193*4882a593Smuzhiyun char consumer[GPIO_MAX_NAME_SIZE]; 194*4882a593Smuzhiyun struct gpio_v2_line_config config; 195*4882a593Smuzhiyun __u32 num_lines; 196*4882a593Smuzhiyun __u32 event_buffer_size; 197*4882a593Smuzhiyun /* Pad to fill implicit padding and reserve space for future use. */ 198*4882a593Smuzhiyun __u32 padding[5]; 199*4882a593Smuzhiyun __s32 fd; 200*4882a593Smuzhiyun }; 201*4882a593Smuzhiyun 202*4882a593Smuzhiyun /** 203*4882a593Smuzhiyun * struct gpio_v2_line_info - Information about a certain GPIO line 204*4882a593Smuzhiyun * @name: the name of this GPIO line, such as the output pin of the line on 205*4882a593Smuzhiyun * the chip, a rail or a pin header name on a board, as specified by the 206*4882a593Smuzhiyun * GPIO chip, may be empty (i.e. name[0] == '\0') 207*4882a593Smuzhiyun * @consumer: a functional name for the consumer of this GPIO line as set 208*4882a593Smuzhiyun * by whatever is using it, will be empty if there is no current user but 209*4882a593Smuzhiyun * may also be empty if the consumer doesn't set this up 210*4882a593Smuzhiyun * @offset: the local offset on this GPIO chip, fill this in when 211*4882a593Smuzhiyun * requesting the line information from the kernel 212*4882a593Smuzhiyun * @num_attrs: the number of attributes in @attrs 213*4882a593Smuzhiyun * @flags: flags for the GPIO lines, with values from &enum 214*4882a593Smuzhiyun * gpio_v2_line_flag, such as %GPIO_V2_LINE_FLAG_ACTIVE_LOW, 215*4882a593Smuzhiyun * %GPIO_V2_LINE_FLAG_OUTPUT etc, added together. 216*4882a593Smuzhiyun * @attrs: the configuration attributes associated with the line 217*4882a593Smuzhiyun * @padding: reserved for future use 218*4882a593Smuzhiyun */ 219*4882a593Smuzhiyun struct gpio_v2_line_info { 220*4882a593Smuzhiyun char name[GPIO_MAX_NAME_SIZE]; 221*4882a593Smuzhiyun char consumer[GPIO_MAX_NAME_SIZE]; 222*4882a593Smuzhiyun __u32 offset; 223*4882a593Smuzhiyun __u32 num_attrs; 224*4882a593Smuzhiyun __aligned_u64 flags; 225*4882a593Smuzhiyun struct gpio_v2_line_attribute attrs[GPIO_V2_LINE_NUM_ATTRS_MAX]; 226*4882a593Smuzhiyun /* Space reserved for future use. */ 227*4882a593Smuzhiyun __u32 padding[4]; 228*4882a593Smuzhiyun }; 229*4882a593Smuzhiyun 230*4882a593Smuzhiyun /** 231*4882a593Smuzhiyun * enum gpio_v2_line_changed_type - &struct gpio_v2_line_changed.event_type 232*4882a593Smuzhiyun * values 233*4882a593Smuzhiyun * @GPIO_V2_LINE_CHANGED_REQUESTED: line has been requested 234*4882a593Smuzhiyun * @GPIO_V2_LINE_CHANGED_RELEASED: line has been released 235*4882a593Smuzhiyun * @GPIO_V2_LINE_CHANGED_CONFIG: line has been reconfigured 236*4882a593Smuzhiyun */ 237*4882a593Smuzhiyun enum gpio_v2_line_changed_type { 238*4882a593Smuzhiyun GPIO_V2_LINE_CHANGED_REQUESTED = 1, 239*4882a593Smuzhiyun GPIO_V2_LINE_CHANGED_RELEASED = 2, 240*4882a593Smuzhiyun GPIO_V2_LINE_CHANGED_CONFIG = 3, 241*4882a593Smuzhiyun }; 242*4882a593Smuzhiyun 243*4882a593Smuzhiyun /** 244*4882a593Smuzhiyun * struct gpio_v2_line_info_changed - Information about a change in status 245*4882a593Smuzhiyun * of a GPIO line 246*4882a593Smuzhiyun * @info: updated line information 247*4882a593Smuzhiyun * @timestamp_ns: estimate of time of status change occurrence, in nanoseconds 248*4882a593Smuzhiyun * @event_type: the type of change with a value from &enum 249*4882a593Smuzhiyun * gpio_v2_line_changed_type 250*4882a593Smuzhiyun * @padding: reserved for future use 251*4882a593Smuzhiyun */ 252*4882a593Smuzhiyun struct gpio_v2_line_info_changed { 253*4882a593Smuzhiyun struct gpio_v2_line_info info; 254*4882a593Smuzhiyun __aligned_u64 timestamp_ns; 255*4882a593Smuzhiyun __u32 event_type; 256*4882a593Smuzhiyun /* Pad struct to 64-bit boundary and reserve space for future use. */ 257*4882a593Smuzhiyun __u32 padding[5]; 258*4882a593Smuzhiyun }; 259*4882a593Smuzhiyun 260*4882a593Smuzhiyun /** 261*4882a593Smuzhiyun * enum gpio_v2_line_event_id - &struct gpio_v2_line_event.id values 262*4882a593Smuzhiyun * @GPIO_V2_LINE_EVENT_RISING_EDGE: event triggered by a rising edge 263*4882a593Smuzhiyun * @GPIO_V2_LINE_EVENT_FALLING_EDGE: event triggered by a falling edge 264*4882a593Smuzhiyun */ 265*4882a593Smuzhiyun enum gpio_v2_line_event_id { 266*4882a593Smuzhiyun GPIO_V2_LINE_EVENT_RISING_EDGE = 1, 267*4882a593Smuzhiyun GPIO_V2_LINE_EVENT_FALLING_EDGE = 2, 268*4882a593Smuzhiyun }; 269*4882a593Smuzhiyun 270*4882a593Smuzhiyun /** 271*4882a593Smuzhiyun * struct gpio_v2_line_event - The actual event being pushed to userspace 272*4882a593Smuzhiyun * @timestamp_ns: best estimate of time of event occurrence, in nanoseconds. 273*4882a593Smuzhiyun * The @timestamp_ns is read from %CLOCK_MONOTONIC and is intended to allow 274*4882a593Smuzhiyun * the accurate measurement of the time between events. It does not provide 275*4882a593Smuzhiyun * the wall-clock time. 276*4882a593Smuzhiyun * @id: event identifier with value from &enum gpio_v2_line_event_id 277*4882a593Smuzhiyun * @offset: the offset of the line that triggered the event 278*4882a593Smuzhiyun * @seqno: the sequence number for this event in the sequence of events for 279*4882a593Smuzhiyun * all the lines in this line request 280*4882a593Smuzhiyun * @line_seqno: the sequence number for this event in the sequence of 281*4882a593Smuzhiyun * events on this particular line 282*4882a593Smuzhiyun * @padding: reserved for future use 283*4882a593Smuzhiyun */ 284*4882a593Smuzhiyun struct gpio_v2_line_event { 285*4882a593Smuzhiyun __aligned_u64 timestamp_ns; 286*4882a593Smuzhiyun __u32 id; 287*4882a593Smuzhiyun __u32 offset; 288*4882a593Smuzhiyun __u32 seqno; 289*4882a593Smuzhiyun __u32 line_seqno; 290*4882a593Smuzhiyun /* Space reserved for future use. */ 291*4882a593Smuzhiyun __u32 padding[6]; 292*4882a593Smuzhiyun }; 293*4882a593Smuzhiyun 294*4882a593Smuzhiyun /* 295*4882a593Smuzhiyun * ABI v1 296*4882a593Smuzhiyun * 297*4882a593Smuzhiyun * This version of the ABI is deprecated. 298*4882a593Smuzhiyun * Use the latest version of the ABI, defined above, instead. 299*4882a593Smuzhiyun */ 300*4882a593Smuzhiyun 301*4882a593Smuzhiyun /* Informational flags */ 302*4882a593Smuzhiyun #define GPIOLINE_FLAG_KERNEL (1UL << 0) /* Line used by the kernel */ 303*4882a593Smuzhiyun #define GPIOLINE_FLAG_IS_OUT (1UL << 1) 304*4882a593Smuzhiyun #define GPIOLINE_FLAG_ACTIVE_LOW (1UL << 2) 305*4882a593Smuzhiyun #define GPIOLINE_FLAG_OPEN_DRAIN (1UL << 3) 306*4882a593Smuzhiyun #define GPIOLINE_FLAG_OPEN_SOURCE (1UL << 4) 307*4882a593Smuzhiyun #define GPIOLINE_FLAG_BIAS_PULL_UP (1UL << 5) 308*4882a593Smuzhiyun #define GPIOLINE_FLAG_BIAS_PULL_DOWN (1UL << 6) 309*4882a593Smuzhiyun #define GPIOLINE_FLAG_BIAS_DISABLE (1UL << 7) 310*4882a593Smuzhiyun 311*4882a593Smuzhiyun /** 312*4882a593Smuzhiyun * struct gpioline_info - Information about a certain GPIO line 313*4882a593Smuzhiyun * @line_offset: the local offset on this GPIO device, fill this in when 314*4882a593Smuzhiyun * requesting the line information from the kernel 315*4882a593Smuzhiyun * @flags: various flags for this line 316*4882a593Smuzhiyun * @name: the name of this GPIO line, such as the output pin of the line on the 317*4882a593Smuzhiyun * chip, a rail or a pin header name on a board, as specified by the gpio 318*4882a593Smuzhiyun * chip, may be empty (i.e. name[0] == '\0') 319*4882a593Smuzhiyun * @consumer: a functional name for the consumer of this GPIO line as set by 320*4882a593Smuzhiyun * whatever is using it, will be empty if there is no current user but may 321*4882a593Smuzhiyun * also be empty if the consumer doesn't set this up 322*4882a593Smuzhiyun * 323*4882a593Smuzhiyun * Note: This struct is part of ABI v1 and is deprecated. 324*4882a593Smuzhiyun * Use &struct gpio_v2_line_info instead. 325*4882a593Smuzhiyun */ 326*4882a593Smuzhiyun struct gpioline_info { 327*4882a593Smuzhiyun __u32 line_offset; 328*4882a593Smuzhiyun __u32 flags; 329*4882a593Smuzhiyun char name[GPIO_MAX_NAME_SIZE]; 330*4882a593Smuzhiyun char consumer[GPIO_MAX_NAME_SIZE]; 331*4882a593Smuzhiyun }; 332*4882a593Smuzhiyun 333*4882a593Smuzhiyun /* Maximum number of requested handles */ 334*4882a593Smuzhiyun #define GPIOHANDLES_MAX 64 335*4882a593Smuzhiyun 336*4882a593Smuzhiyun /* Possible line status change events */ 337*4882a593Smuzhiyun enum { 338*4882a593Smuzhiyun GPIOLINE_CHANGED_REQUESTED = 1, 339*4882a593Smuzhiyun GPIOLINE_CHANGED_RELEASED, 340*4882a593Smuzhiyun GPIOLINE_CHANGED_CONFIG, 341*4882a593Smuzhiyun }; 342*4882a593Smuzhiyun 343*4882a593Smuzhiyun /** 344*4882a593Smuzhiyun * struct gpioline_info_changed - Information about a change in status 345*4882a593Smuzhiyun * of a GPIO line 346*4882a593Smuzhiyun * @info: updated line information 347*4882a593Smuzhiyun * @timestamp: estimate of time of status change occurrence, in nanoseconds 348*4882a593Smuzhiyun * @event_type: one of %GPIOLINE_CHANGED_REQUESTED, 349*4882a593Smuzhiyun * %GPIOLINE_CHANGED_RELEASED and %GPIOLINE_CHANGED_CONFIG 350*4882a593Smuzhiyun * @padding: reserved for future use 351*4882a593Smuzhiyun * 352*4882a593Smuzhiyun * The &struct gpioline_info embedded here has 32-bit alignment on its own, 353*4882a593Smuzhiyun * but it works fine with 64-bit alignment too. With its 72 byte size, we can 354*4882a593Smuzhiyun * guarantee there are no implicit holes between it and subsequent members. 355*4882a593Smuzhiyun * The 20-byte padding at the end makes sure we don't add any implicit padding 356*4882a593Smuzhiyun * at the end of the structure on 64-bit architectures. 357*4882a593Smuzhiyun * 358*4882a593Smuzhiyun * Note: This struct is part of ABI v1 and is deprecated. 359*4882a593Smuzhiyun * Use &struct gpio_v2_line_info_changed instead. 360*4882a593Smuzhiyun */ 361*4882a593Smuzhiyun struct gpioline_info_changed { 362*4882a593Smuzhiyun struct gpioline_info info; 363*4882a593Smuzhiyun __u64 timestamp; 364*4882a593Smuzhiyun __u32 event_type; 365*4882a593Smuzhiyun __u32 padding[5]; /* for future use */ 366*4882a593Smuzhiyun }; 367*4882a593Smuzhiyun 368*4882a593Smuzhiyun /* Linerequest flags */ 369*4882a593Smuzhiyun #define GPIOHANDLE_REQUEST_INPUT (1UL << 0) 370*4882a593Smuzhiyun #define GPIOHANDLE_REQUEST_OUTPUT (1UL << 1) 371*4882a593Smuzhiyun #define GPIOHANDLE_REQUEST_ACTIVE_LOW (1UL << 2) 372*4882a593Smuzhiyun #define GPIOHANDLE_REQUEST_OPEN_DRAIN (1UL << 3) 373*4882a593Smuzhiyun #define GPIOHANDLE_REQUEST_OPEN_SOURCE (1UL << 4) 374*4882a593Smuzhiyun #define GPIOHANDLE_REQUEST_BIAS_PULL_UP (1UL << 5) 375*4882a593Smuzhiyun #define GPIOHANDLE_REQUEST_BIAS_PULL_DOWN (1UL << 6) 376*4882a593Smuzhiyun #define GPIOHANDLE_REQUEST_BIAS_DISABLE (1UL << 7) 377*4882a593Smuzhiyun 378*4882a593Smuzhiyun /** 379*4882a593Smuzhiyun * struct gpiohandle_request - Information about a GPIO handle request 380*4882a593Smuzhiyun * @lineoffsets: an array of desired lines, specified by offset index for the 381*4882a593Smuzhiyun * associated GPIO device 382*4882a593Smuzhiyun * @flags: desired flags for the desired GPIO lines, such as 383*4882a593Smuzhiyun * %GPIOHANDLE_REQUEST_OUTPUT, %GPIOHANDLE_REQUEST_ACTIVE_LOW etc, added 384*4882a593Smuzhiyun * together. Note that even if multiple lines are requested, the same flags 385*4882a593Smuzhiyun * must be applicable to all of them, if you want lines with individual 386*4882a593Smuzhiyun * flags set, request them one by one. It is possible to select 387*4882a593Smuzhiyun * a batch of input or output lines, but they must all have the same 388*4882a593Smuzhiyun * characteristics, i.e. all inputs or all outputs, all active low etc 389*4882a593Smuzhiyun * @default_values: if the %GPIOHANDLE_REQUEST_OUTPUT is set for a requested 390*4882a593Smuzhiyun * line, this specifies the default output value, should be 0 (low) or 391*4882a593Smuzhiyun * 1 (high), anything else than 0 or 1 will be interpreted as 1 (high) 392*4882a593Smuzhiyun * @consumer_label: a desired consumer label for the selected GPIO line(s) 393*4882a593Smuzhiyun * such as "my-bitbanged-relay" 394*4882a593Smuzhiyun * @lines: number of lines requested in this request, i.e. the number of 395*4882a593Smuzhiyun * valid fields in the above arrays, set to 1 to request a single line 396*4882a593Smuzhiyun * @fd: if successful this field will contain a valid anonymous file handle 397*4882a593Smuzhiyun * after a %GPIO_GET_LINEHANDLE_IOCTL operation, zero or negative value 398*4882a593Smuzhiyun * means error 399*4882a593Smuzhiyun * 400*4882a593Smuzhiyun * Note: This struct is part of ABI v1 and is deprecated. 401*4882a593Smuzhiyun * Use &struct gpio_v2_line_request instead. 402*4882a593Smuzhiyun */ 403*4882a593Smuzhiyun struct gpiohandle_request { 404*4882a593Smuzhiyun __u32 lineoffsets[GPIOHANDLES_MAX]; 405*4882a593Smuzhiyun __u32 flags; 406*4882a593Smuzhiyun __u8 default_values[GPIOHANDLES_MAX]; 407*4882a593Smuzhiyun char consumer_label[GPIO_MAX_NAME_SIZE]; 408*4882a593Smuzhiyun __u32 lines; 409*4882a593Smuzhiyun int fd; 410*4882a593Smuzhiyun }; 411*4882a593Smuzhiyun 412*4882a593Smuzhiyun /** 413*4882a593Smuzhiyun * struct gpiohandle_config - Configuration for a GPIO handle request 414*4882a593Smuzhiyun * @flags: updated flags for the requested GPIO lines, such as 415*4882a593Smuzhiyun * %GPIOHANDLE_REQUEST_OUTPUT, %GPIOHANDLE_REQUEST_ACTIVE_LOW etc, added 416*4882a593Smuzhiyun * together 417*4882a593Smuzhiyun * @default_values: if the %GPIOHANDLE_REQUEST_OUTPUT is set in flags, 418*4882a593Smuzhiyun * this specifies the default output value, should be 0 (low) or 419*4882a593Smuzhiyun * 1 (high), anything else than 0 or 1 will be interpreted as 1 (high) 420*4882a593Smuzhiyun * @padding: reserved for future use and should be zero filled 421*4882a593Smuzhiyun * 422*4882a593Smuzhiyun * Note: This struct is part of ABI v1 and is deprecated. 423*4882a593Smuzhiyun * Use &struct gpio_v2_line_config instead. 424*4882a593Smuzhiyun */ 425*4882a593Smuzhiyun struct gpiohandle_config { 426*4882a593Smuzhiyun __u32 flags; 427*4882a593Smuzhiyun __u8 default_values[GPIOHANDLES_MAX]; 428*4882a593Smuzhiyun __u32 padding[4]; /* padding for future use */ 429*4882a593Smuzhiyun }; 430*4882a593Smuzhiyun 431*4882a593Smuzhiyun /** 432*4882a593Smuzhiyun * struct gpiohandle_data - Information of values on a GPIO handle 433*4882a593Smuzhiyun * @values: when getting the state of lines this contains the current 434*4882a593Smuzhiyun * state of a line, when setting the state of lines these should contain 435*4882a593Smuzhiyun * the desired target state 436*4882a593Smuzhiyun * 437*4882a593Smuzhiyun * Note: This struct is part of ABI v1 and is deprecated. 438*4882a593Smuzhiyun * Use &struct gpio_v2_line_values instead. 439*4882a593Smuzhiyun */ 440*4882a593Smuzhiyun struct gpiohandle_data { 441*4882a593Smuzhiyun __u8 values[GPIOHANDLES_MAX]; 442*4882a593Smuzhiyun }; 443*4882a593Smuzhiyun 444*4882a593Smuzhiyun /* Eventrequest flags */ 445*4882a593Smuzhiyun #define GPIOEVENT_REQUEST_RISING_EDGE (1UL << 0) 446*4882a593Smuzhiyun #define GPIOEVENT_REQUEST_FALLING_EDGE (1UL << 1) 447*4882a593Smuzhiyun #define GPIOEVENT_REQUEST_BOTH_EDGES ((1UL << 0) | (1UL << 1)) 448*4882a593Smuzhiyun 449*4882a593Smuzhiyun /** 450*4882a593Smuzhiyun * struct gpioevent_request - Information about a GPIO event request 451*4882a593Smuzhiyun * @lineoffset: the desired line to subscribe to events from, specified by 452*4882a593Smuzhiyun * offset index for the associated GPIO device 453*4882a593Smuzhiyun * @handleflags: desired handle flags for the desired GPIO line, such as 454*4882a593Smuzhiyun * %GPIOHANDLE_REQUEST_ACTIVE_LOW or %GPIOHANDLE_REQUEST_OPEN_DRAIN 455*4882a593Smuzhiyun * @eventflags: desired flags for the desired GPIO event line, such as 456*4882a593Smuzhiyun * %GPIOEVENT_REQUEST_RISING_EDGE or %GPIOEVENT_REQUEST_FALLING_EDGE 457*4882a593Smuzhiyun * @consumer_label: a desired consumer label for the selected GPIO line(s) 458*4882a593Smuzhiyun * such as "my-listener" 459*4882a593Smuzhiyun * @fd: if successful this field will contain a valid anonymous file handle 460*4882a593Smuzhiyun * after a %GPIO_GET_LINEEVENT_IOCTL operation, zero or negative value 461*4882a593Smuzhiyun * means error 462*4882a593Smuzhiyun * 463*4882a593Smuzhiyun * Note: This struct is part of ABI v1 and is deprecated. 464*4882a593Smuzhiyun * Use &struct gpio_v2_line_request instead. 465*4882a593Smuzhiyun */ 466*4882a593Smuzhiyun struct gpioevent_request { 467*4882a593Smuzhiyun __u32 lineoffset; 468*4882a593Smuzhiyun __u32 handleflags; 469*4882a593Smuzhiyun __u32 eventflags; 470*4882a593Smuzhiyun char consumer_label[GPIO_MAX_NAME_SIZE]; 471*4882a593Smuzhiyun int fd; 472*4882a593Smuzhiyun }; 473*4882a593Smuzhiyun 474*4882a593Smuzhiyun /* 475*4882a593Smuzhiyun * GPIO event types 476*4882a593Smuzhiyun */ 477*4882a593Smuzhiyun #define GPIOEVENT_EVENT_RISING_EDGE 0x01 478*4882a593Smuzhiyun #define GPIOEVENT_EVENT_FALLING_EDGE 0x02 479*4882a593Smuzhiyun 480*4882a593Smuzhiyun /** 481*4882a593Smuzhiyun * struct gpioevent_data - The actual event being pushed to userspace 482*4882a593Smuzhiyun * @timestamp: best estimate of time of event occurrence, in nanoseconds 483*4882a593Smuzhiyun * @id: event identifier 484*4882a593Smuzhiyun * 485*4882a593Smuzhiyun * Note: This struct is part of ABI v1 and is deprecated. 486*4882a593Smuzhiyun * Use &struct gpio_v2_line_event instead. 487*4882a593Smuzhiyun */ 488*4882a593Smuzhiyun struct gpioevent_data { 489*4882a593Smuzhiyun __u64 timestamp; 490*4882a593Smuzhiyun __u32 id; 491*4882a593Smuzhiyun }; 492*4882a593Smuzhiyun 493*4882a593Smuzhiyun /* 494*4882a593Smuzhiyun * v1 and v2 ioctl()s 495*4882a593Smuzhiyun */ 496*4882a593Smuzhiyun #define GPIO_GET_CHIPINFO_IOCTL _IOR(0xB4, 0x01, struct gpiochip_info) 497*4882a593Smuzhiyun #define GPIO_GET_LINEINFO_UNWATCH_IOCTL _IOWR(0xB4, 0x0C, __u32) 498*4882a593Smuzhiyun 499*4882a593Smuzhiyun /* 500*4882a593Smuzhiyun * v2 ioctl()s 501*4882a593Smuzhiyun */ 502*4882a593Smuzhiyun #define GPIO_V2_GET_LINEINFO_IOCTL _IOWR(0xB4, 0x05, struct gpio_v2_line_info) 503*4882a593Smuzhiyun #define GPIO_V2_GET_LINEINFO_WATCH_IOCTL _IOWR(0xB4, 0x06, struct gpio_v2_line_info) 504*4882a593Smuzhiyun #define GPIO_V2_GET_LINE_IOCTL _IOWR(0xB4, 0x07, struct gpio_v2_line_request) 505*4882a593Smuzhiyun #define GPIO_V2_LINE_SET_CONFIG_IOCTL _IOWR(0xB4, 0x0D, struct gpio_v2_line_config) 506*4882a593Smuzhiyun #define GPIO_V2_LINE_GET_VALUES_IOCTL _IOWR(0xB4, 0x0E, struct gpio_v2_line_values) 507*4882a593Smuzhiyun #define GPIO_V2_LINE_SET_VALUES_IOCTL _IOWR(0xB4, 0x0F, struct gpio_v2_line_values) 508*4882a593Smuzhiyun 509*4882a593Smuzhiyun /* 510*4882a593Smuzhiyun * v1 ioctl()s 511*4882a593Smuzhiyun * 512*4882a593Smuzhiyun * These ioctl()s are deprecated. Use the v2 equivalent instead. 513*4882a593Smuzhiyun */ 514*4882a593Smuzhiyun #define GPIO_GET_LINEINFO_IOCTL _IOWR(0xB4, 0x02, struct gpioline_info) 515*4882a593Smuzhiyun #define GPIO_GET_LINEHANDLE_IOCTL _IOWR(0xB4, 0x03, struct gpiohandle_request) 516*4882a593Smuzhiyun #define GPIO_GET_LINEEVENT_IOCTL _IOWR(0xB4, 0x04, struct gpioevent_request) 517*4882a593Smuzhiyun #define GPIOHANDLE_GET_LINE_VALUES_IOCTL _IOWR(0xB4, 0x08, struct gpiohandle_data) 518*4882a593Smuzhiyun #define GPIOHANDLE_SET_LINE_VALUES_IOCTL _IOWR(0xB4, 0x09, struct gpiohandle_data) 519*4882a593Smuzhiyun #define GPIOHANDLE_SET_CONFIG_IOCTL _IOWR(0xB4, 0x0A, struct gpiohandle_config) 520*4882a593Smuzhiyun #define GPIO_GET_LINEINFO_WATCH_IOCTL _IOWR(0xB4, 0x0B, struct gpioline_info) 521*4882a593Smuzhiyun 522*4882a593Smuzhiyun #endif /* _UAPI_GPIO_H_ */ 523