xref: /linux/include/uapi/linux/gpio.h (revision 100c85421b52e41269ada88f7d71a6b8a06c7a11)
150f9a6c2SBartosz Golaszewski /* SPDX-License-Identifier: GPL-2.0-only WITH Linux-syscall-note */
23c702e99SLinus Walleij /*
33c702e99SLinus Walleij  * <linux/gpio.h> - userspace ABI for the GPIO character devices
43c702e99SLinus Walleij  *
5d7c51b47SLinus Walleij  * Copyright (C) 2016 Linus Walleij
63c702e99SLinus Walleij  *
73c702e99SLinus Walleij  * This program is free software; you can redistribute it and/or modify it
83c702e99SLinus Walleij  * under the terms of the GNU General Public License version 2 as published by
93c702e99SLinus Walleij  * the Free Software Foundation.
103c702e99SLinus Walleij  */
113c702e99SLinus Walleij #ifndef _UAPI_GPIO_H_
123c702e99SLinus Walleij #define _UAPI_GPIO_H_
133c702e99SLinus Walleij 
14b53911aaSKent Gibson #include <linux/const.h>
153c702e99SLinus Walleij #include <linux/ioctl.h>
163c702e99SLinus Walleij #include <linux/types.h>
173c702e99SLinus Walleij 
18539430fbSKent Gibson /*
19539430fbSKent Gibson  * The maximum size of name and label arrays.
20b53911aaSKent Gibson  *
21b53911aaSKent Gibson  * Must be a multiple of 8 to ensure 32/64-bit alignment of structs.
22539430fbSKent Gibson  */
23539430fbSKent Gibson #define GPIO_MAX_NAME_SIZE 32
24539430fbSKent Gibson 
253c702e99SLinus Walleij /**
263c702e99SLinus Walleij  * struct gpiochip_info - Information about a certain GPIO chip
27214338e3SLinus Walleij  * @name: the Linux kernel name of this GPIO chip
28214338e3SLinus Walleij  * @label: a functional name for this GPIO chip, such as a product
292f84a2deSKent Gibson  * number, may be empty (i.e. label[0] == '\0')
303c702e99SLinus Walleij  * @lines: number of GPIO lines on this chip
313c702e99SLinus Walleij  */
323c702e99SLinus Walleij struct gpiochip_info {
33539430fbSKent Gibson 	char name[GPIO_MAX_NAME_SIZE];
34539430fbSKent Gibson 	char label[GPIO_MAX_NAME_SIZE];
353c702e99SLinus Walleij 	__u32 lines;
363c702e99SLinus Walleij };
373c702e99SLinus Walleij 
38b53911aaSKent Gibson /*
39b53911aaSKent Gibson  * Maximum number of requested lines.
40b53911aaSKent Gibson  *
41b53911aaSKent Gibson  * Must be no greater than 64, as bitmaps are restricted here to 64-bits
42b53911aaSKent Gibson  * for simplicity, and a multiple of 2 to ensure 32/64-bit alignment of
43b53911aaSKent Gibson  * structs.
44b53911aaSKent Gibson  */
45b53911aaSKent Gibson #define GPIO_V2_LINES_MAX 64
46b53911aaSKent Gibson 
47b53911aaSKent Gibson /*
48b53911aaSKent Gibson  * The maximum number of configuration attributes associated with a line
49b53911aaSKent Gibson  * request.
50b53911aaSKent Gibson  */
51b53911aaSKent Gibson #define GPIO_V2_LINE_NUM_ATTRS_MAX 10
52b53911aaSKent Gibson 
53b53911aaSKent Gibson /**
54b53911aaSKent Gibson  * enum gpio_v2_line_flag - &struct gpio_v2_line_attribute.flags values
55b53911aaSKent Gibson  * @GPIO_V2_LINE_FLAG_USED: line is not available for request
56b53911aaSKent Gibson  * @GPIO_V2_LINE_FLAG_ACTIVE_LOW: line active state is physical low
57b53911aaSKent Gibson  * @GPIO_V2_LINE_FLAG_INPUT: line is an input
58b53911aaSKent Gibson  * @GPIO_V2_LINE_FLAG_OUTPUT: line is an output
59b53911aaSKent Gibson  * @GPIO_V2_LINE_FLAG_EDGE_RISING: line detects rising (inactive to active)
60b53911aaSKent Gibson  * edges
61b53911aaSKent Gibson  * @GPIO_V2_LINE_FLAG_EDGE_FALLING: line detects falling (active to
62b53911aaSKent Gibson  * inactive) edges
63b53911aaSKent Gibson  * @GPIO_V2_LINE_FLAG_OPEN_DRAIN: line is an open drain output
64b53911aaSKent Gibson  * @GPIO_V2_LINE_FLAG_OPEN_SOURCE: line is an open source output
65b53911aaSKent Gibson  * @GPIO_V2_LINE_FLAG_BIAS_PULL_UP: line has pull-up bias enabled
66b53911aaSKent Gibson  * @GPIO_V2_LINE_FLAG_BIAS_PULL_DOWN: line has pull-down bias enabled
67b53911aaSKent Gibson  * @GPIO_V2_LINE_FLAG_BIAS_DISABLED: line has bias disabled
6826d060e4SKent Gibson  * @GPIO_V2_LINE_FLAG_EVENT_CLOCK_REALTIME: line events contain REALTIME timestamps
692068339aSDipen Patel  * @GPIO_V2_LINE_FLAG_EVENT_CLOCK_HTE: line events contain timestamps from
70f75d508eSKent Gibson  * the hardware timestamping engine (HTE) subsystem
71b53911aaSKent Gibson  */
72b53911aaSKent Gibson enum gpio_v2_line_flag {
73b53911aaSKent Gibson 	GPIO_V2_LINE_FLAG_USED			= _BITULL(0),
74b53911aaSKent Gibson 	GPIO_V2_LINE_FLAG_ACTIVE_LOW		= _BITULL(1),
75b53911aaSKent Gibson 	GPIO_V2_LINE_FLAG_INPUT			= _BITULL(2),
76b53911aaSKent Gibson 	GPIO_V2_LINE_FLAG_OUTPUT		= _BITULL(3),
77b53911aaSKent Gibson 	GPIO_V2_LINE_FLAG_EDGE_RISING		= _BITULL(4),
78b53911aaSKent Gibson 	GPIO_V2_LINE_FLAG_EDGE_FALLING		= _BITULL(5),
79b53911aaSKent Gibson 	GPIO_V2_LINE_FLAG_OPEN_DRAIN		= _BITULL(6),
80b53911aaSKent Gibson 	GPIO_V2_LINE_FLAG_OPEN_SOURCE		= _BITULL(7),
81b53911aaSKent Gibson 	GPIO_V2_LINE_FLAG_BIAS_PULL_UP		= _BITULL(8),
82b53911aaSKent Gibson 	GPIO_V2_LINE_FLAG_BIAS_PULL_DOWN	= _BITULL(9),
83b53911aaSKent Gibson 	GPIO_V2_LINE_FLAG_BIAS_DISABLED		= _BITULL(10),
8426d060e4SKent Gibson 	GPIO_V2_LINE_FLAG_EVENT_CLOCK_REALTIME	= _BITULL(11),
852068339aSDipen Patel 	GPIO_V2_LINE_FLAG_EVENT_CLOCK_HTE	= _BITULL(12),
86b53911aaSKent Gibson };
87b53911aaSKent Gibson 
88b53911aaSKent Gibson /**
89b53911aaSKent Gibson  * struct gpio_v2_line_values - Values of GPIO lines
90b53911aaSKent Gibson  * @bits: a bitmap containing the value of the lines, set to 1 for active
91a6beb0b4SKent Gibson  * and 0 for inactive
92b53911aaSKent Gibson  * @mask: a bitmap identifying the lines to get or set, with each bit
93b53911aaSKent Gibson  * number corresponding to the index into &struct
94a6beb0b4SKent Gibson  * gpio_v2_line_request.offsets
95b53911aaSKent Gibson  */
96b53911aaSKent Gibson struct gpio_v2_line_values {
97b53911aaSKent Gibson 	__aligned_u64 bits;
98b53911aaSKent Gibson 	__aligned_u64 mask;
99b53911aaSKent Gibson };
100b53911aaSKent Gibson 
101b53911aaSKent Gibson /**
102b53911aaSKent Gibson  * enum gpio_v2_line_attr_id - &struct gpio_v2_line_attribute.id values
103b53911aaSKent Gibson  * identifying which field of the attribute union is in use.
104b53911aaSKent Gibson  * @GPIO_V2_LINE_ATTR_ID_FLAGS: flags field is in use
105b53911aaSKent Gibson  * @GPIO_V2_LINE_ATTR_ID_OUTPUT_VALUES: values field is in use
106f2016021SKent Gibson  * @GPIO_V2_LINE_ATTR_ID_DEBOUNCE: debounce_period_us field is in use
107b53911aaSKent Gibson  */
108b53911aaSKent Gibson enum gpio_v2_line_attr_id {
109b53911aaSKent Gibson 	GPIO_V2_LINE_ATTR_ID_FLAGS		= 1,
110b53911aaSKent Gibson 	GPIO_V2_LINE_ATTR_ID_OUTPUT_VALUES	= 2,
111b53911aaSKent Gibson 	GPIO_V2_LINE_ATTR_ID_DEBOUNCE		= 3,
112b53911aaSKent Gibson };
113b53911aaSKent Gibson 
114b53911aaSKent Gibson /**
115b53911aaSKent Gibson  * struct gpio_v2_line_attribute - a configurable attribute of a line
116b53911aaSKent Gibson  * @id: attribute identifier with value from &enum gpio_v2_line_attr_id
117b53911aaSKent Gibson  * @padding: reserved for future use and must be zero filled
1182cc522d3SKent Gibson  * @flags: if id is %GPIO_V2_LINE_ATTR_ID_FLAGS, the flags for the GPIO
1192cc522d3SKent Gibson  * line, with values from &enum gpio_v2_line_flag, such as
1202cc522d3SKent Gibson  * %GPIO_V2_LINE_FLAG_ACTIVE_LOW, %GPIO_V2_LINE_FLAG_OUTPUT etc, added
121b53911aaSKent Gibson  * together.  This overrides the default flags contained in the &struct
122b53911aaSKent Gibson  * gpio_v2_line_config for the associated line.
1232cc522d3SKent Gibson  * @values: if id is %GPIO_V2_LINE_ATTR_ID_OUTPUT_VALUES, a bitmap
124b53911aaSKent Gibson  * containing the values to which the lines will be set, with each bit
125b53911aaSKent Gibson  * number corresponding to the index into &struct
126a6beb0b4SKent Gibson  * gpio_v2_line_request.offsets
1272cc522d3SKent Gibson  * @debounce_period_us: if id is %GPIO_V2_LINE_ATTR_ID_DEBOUNCE, the
1282cc522d3SKent Gibson  * desired debounce period, in microseconds
129b53911aaSKent Gibson  */
130b53911aaSKent Gibson struct gpio_v2_line_attribute {
131b53911aaSKent Gibson 	__u32 id;
132b53911aaSKent Gibson 	__u32 padding;
133b53911aaSKent Gibson 	union {
134b53911aaSKent Gibson 		__aligned_u64 flags;
135b53911aaSKent Gibson 		__aligned_u64 values;
136b53911aaSKent Gibson 		__u32 debounce_period_us;
137b53911aaSKent Gibson 	};
138b53911aaSKent Gibson };
139b53911aaSKent Gibson 
140b53911aaSKent Gibson /**
141b53911aaSKent Gibson  * struct gpio_v2_line_config_attribute - a configuration attribute
142b53911aaSKent Gibson  * associated with one or more of the requested lines.
143b53911aaSKent Gibson  * @attr: the configurable attribute
144b53911aaSKent Gibson  * @mask: a bitmap identifying the lines to which the attribute applies,
145b53911aaSKent Gibson  * with each bit number corresponding to the index into &struct
146a6beb0b4SKent Gibson  * gpio_v2_line_request.offsets
147b53911aaSKent Gibson  */
148b53911aaSKent Gibson struct gpio_v2_line_config_attribute {
149b53911aaSKent Gibson 	struct gpio_v2_line_attribute attr;
150b53911aaSKent Gibson 	__aligned_u64 mask;
151b53911aaSKent Gibson };
152b53911aaSKent Gibson 
153b53911aaSKent Gibson /**
154b53911aaSKent Gibson  * struct gpio_v2_line_config - Configuration for GPIO lines
1552cc522d3SKent Gibson  * @flags: flags for the GPIO lines, with values from &enum
1562cc522d3SKent Gibson  * gpio_v2_line_flag, such as %GPIO_V2_LINE_FLAG_ACTIVE_LOW,
1572cc522d3SKent Gibson  * %GPIO_V2_LINE_FLAG_OUTPUT etc, added together.  This is the default for
158b53911aaSKent Gibson  * all requested lines but may be overridden for particular lines using
1592cc522d3SKent Gibson  * @attrs.
1602cc522d3SKent Gibson  * @num_attrs: the number of attributes in @attrs
161b53911aaSKent Gibson  * @padding: reserved for future use and must be zero filled
162b53911aaSKent Gibson  * @attrs: the configuration attributes associated with the requested
163b53911aaSKent Gibson  * lines.  Any attribute should only be associated with a particular line
164b53911aaSKent Gibson  * once.  If an attribute is associated with a line multiple times then the
165b53911aaSKent Gibson  * first occurrence (i.e. lowest index) has precedence.
166b53911aaSKent Gibson  */
167b53911aaSKent Gibson struct gpio_v2_line_config {
168b53911aaSKent Gibson 	__aligned_u64 flags;
169b53911aaSKent Gibson 	__u32 num_attrs;
170b53911aaSKent Gibson 	/* Pad to fill implicit padding and reserve space for future use. */
171b53911aaSKent Gibson 	__u32 padding[5];
172b53911aaSKent Gibson 	struct gpio_v2_line_config_attribute attrs[GPIO_V2_LINE_NUM_ATTRS_MAX];
173b53911aaSKent Gibson };
174b53911aaSKent Gibson 
175b53911aaSKent Gibson /**
176b53911aaSKent Gibson  * struct gpio_v2_line_request - Information about a request for GPIO lines
177b53911aaSKent Gibson  * @offsets: an array of desired lines, specified by offset index for the
178b53911aaSKent Gibson  * associated GPIO chip
179b53911aaSKent Gibson  * @consumer: a desired consumer label for the selected GPIO lines such as
180b53911aaSKent Gibson  * "my-bitbanged-relay"
181a6beb0b4SKent Gibson  * @config: requested configuration for the lines
182b53911aaSKent Gibson  * @num_lines: number of lines requested in this request, i.e. the number
1832cc522d3SKent Gibson  * of valid fields in the %GPIO_V2_LINES_MAX sized arrays, set to 1 to
184b53911aaSKent Gibson  * request a single line
185b53911aaSKent Gibson  * @event_buffer_size: a suggested minimum number of line events that the
186b53911aaSKent Gibson  * kernel should buffer.  This is only relevant if edge detection is
187b53911aaSKent Gibson  * enabled in the configuration. Note that this is only a suggested value
188b53911aaSKent Gibson  * and the kernel may allocate a larger buffer or cap the size of the
189b53911aaSKent Gibson  * buffer. If this field is zero then the buffer size defaults to a minimum
1902cc522d3SKent Gibson  * of @num_lines * 16.
191b53911aaSKent Gibson  * @padding: reserved for future use and must be zero filled
1927889968eSKent Gibson  * @fd: after a successful %GPIO_V2_GET_LINE_IOCTL operation, contains
1937889968eSKent Gibson  * a valid anonymous file descriptor representing the request
194b53911aaSKent Gibson  */
195b53911aaSKent Gibson struct gpio_v2_line_request {
196b53911aaSKent Gibson 	__u32 offsets[GPIO_V2_LINES_MAX];
197b53911aaSKent Gibson 	char consumer[GPIO_MAX_NAME_SIZE];
198b53911aaSKent Gibson 	struct gpio_v2_line_config config;
199b53911aaSKent Gibson 	__u32 num_lines;
200b53911aaSKent Gibson 	__u32 event_buffer_size;
201b53911aaSKent Gibson 	/* Pad to fill implicit padding and reserve space for future use. */
202b53911aaSKent Gibson 	__u32 padding[5];
203b53911aaSKent Gibson 	__s32 fd;
204b53911aaSKent Gibson };
205b53911aaSKent Gibson 
206b53911aaSKent Gibson /**
207b53911aaSKent Gibson  * struct gpio_v2_line_info - Information about a certain GPIO line
208b53911aaSKent Gibson  * @name: the name of this GPIO line, such as the output pin of the line on
209b53911aaSKent Gibson  * the chip, a rail or a pin header name on a board, as specified by the
2102f84a2deSKent Gibson  * GPIO chip, may be empty (i.e. name[0] == '\0')
211b53911aaSKent Gibson  * @consumer: a functional name for the consumer of this GPIO line as set
212b53911aaSKent Gibson  * by whatever is using it, will be empty if there is no current user but
213b53911aaSKent Gibson  * may also be empty if the consumer doesn't set this up
214b53911aaSKent Gibson  * @offset: the local offset on this GPIO chip, fill this in when
215b53911aaSKent Gibson  * requesting the line information from the kernel
2162cc522d3SKent Gibson  * @num_attrs: the number of attributes in @attrs
217f61d3f0cSKent Gibson  * @flags: flags for this GPIO line, with values from &enum
2182cc522d3SKent Gibson  * gpio_v2_line_flag, such as %GPIO_V2_LINE_FLAG_ACTIVE_LOW,
219a6beb0b4SKent Gibson  * %GPIO_V2_LINE_FLAG_OUTPUT etc, added together
220b53911aaSKent Gibson  * @attrs: the configuration attributes associated with the line
221b53911aaSKent Gibson  * @padding: reserved for future use
222b53911aaSKent Gibson  */
223b53911aaSKent Gibson struct gpio_v2_line_info {
224b53911aaSKent Gibson 	char name[GPIO_MAX_NAME_SIZE];
225b53911aaSKent Gibson 	char consumer[GPIO_MAX_NAME_SIZE];
226b53911aaSKent Gibson 	__u32 offset;
227b53911aaSKent Gibson 	__u32 num_attrs;
228b53911aaSKent Gibson 	__aligned_u64 flags;
229b53911aaSKent Gibson 	struct gpio_v2_line_attribute attrs[GPIO_V2_LINE_NUM_ATTRS_MAX];
230b53911aaSKent Gibson 	/* Space reserved for future use. */
231b53911aaSKent Gibson 	__u32 padding[4];
232b53911aaSKent Gibson };
233b53911aaSKent Gibson 
234b53911aaSKent Gibson /**
235b53911aaSKent Gibson  * enum gpio_v2_line_changed_type - &struct gpio_v2_line_changed.event_type
236b53911aaSKent Gibson  * values
237b53911aaSKent Gibson  * @GPIO_V2_LINE_CHANGED_REQUESTED: line has been requested
238b53911aaSKent Gibson  * @GPIO_V2_LINE_CHANGED_RELEASED: line has been released
239b53911aaSKent Gibson  * @GPIO_V2_LINE_CHANGED_CONFIG: line has been reconfigured
240b53911aaSKent Gibson  */
241b53911aaSKent Gibson enum gpio_v2_line_changed_type {
242b53911aaSKent Gibson 	GPIO_V2_LINE_CHANGED_REQUESTED	= 1,
243b53911aaSKent Gibson 	GPIO_V2_LINE_CHANGED_RELEASED	= 2,
244b53911aaSKent Gibson 	GPIO_V2_LINE_CHANGED_CONFIG	= 3,
245b53911aaSKent Gibson };
246b53911aaSKent Gibson 
247b53911aaSKent Gibson /**
248b53911aaSKent Gibson  * struct gpio_v2_line_info_changed - Information about a change in status
249b53911aaSKent Gibson  * of a GPIO line
250b53911aaSKent Gibson  * @info: updated line information
251b53911aaSKent Gibson  * @timestamp_ns: estimate of time of status change occurrence, in nanoseconds
2522cc522d3SKent Gibson  * @event_type: the type of change with a value from &enum
253b53911aaSKent Gibson  * gpio_v2_line_changed_type
254b53911aaSKent Gibson  * @padding: reserved for future use
255b53911aaSKent Gibson  */
256b53911aaSKent Gibson struct gpio_v2_line_info_changed {
257b53911aaSKent Gibson 	struct gpio_v2_line_info info;
258b53911aaSKent Gibson 	__aligned_u64 timestamp_ns;
259b53911aaSKent Gibson 	__u32 event_type;
260b53911aaSKent Gibson 	/* Pad struct to 64-bit boundary and reserve space for future use. */
261b53911aaSKent Gibson 	__u32 padding[5];
262b53911aaSKent Gibson };
263b53911aaSKent Gibson 
264b53911aaSKent Gibson /**
265b53911aaSKent Gibson  * enum gpio_v2_line_event_id - &struct gpio_v2_line_event.id values
266b53911aaSKent Gibson  * @GPIO_V2_LINE_EVENT_RISING_EDGE: event triggered by a rising edge
267b53911aaSKent Gibson  * @GPIO_V2_LINE_EVENT_FALLING_EDGE: event triggered by a falling edge
268b53911aaSKent Gibson  */
269b53911aaSKent Gibson enum gpio_v2_line_event_id {
270b53911aaSKent Gibson 	GPIO_V2_LINE_EVENT_RISING_EDGE	= 1,
271b53911aaSKent Gibson 	GPIO_V2_LINE_EVENT_FALLING_EDGE	= 2,
272b53911aaSKent Gibson };
273b53911aaSKent Gibson 
274b53911aaSKent Gibson /**
275b53911aaSKent Gibson  * struct gpio_v2_line_event - The actual event being pushed to userspace
276a6beb0b4SKent Gibson  * @timestamp_ns: best estimate of time of event occurrence, in nanoseconds
2772cc522d3SKent Gibson  * @id: event identifier with value from &enum gpio_v2_line_event_id
278b53911aaSKent Gibson  * @offset: the offset of the line that triggered the event
279b53911aaSKent Gibson  * @seqno: the sequence number for this event in the sequence of events for
280b53911aaSKent Gibson  * all the lines in this line request
281b53911aaSKent Gibson  * @line_seqno: the sequence number for this event in the sequence of
282b53911aaSKent Gibson  * events on this particular line
283b53911aaSKent Gibson  * @padding: reserved for future use
28426d060e4SKent Gibson  *
28526d060e4SKent Gibson  * By default the @timestamp_ns is read from %CLOCK_MONOTONIC and is
28626d060e4SKent Gibson  * intended to allow the accurate measurement of the time between events.
28726d060e4SKent Gibson  * It does not provide the wall-clock time.
28826d060e4SKent Gibson  *
28926d060e4SKent Gibson  * If the %GPIO_V2_LINE_FLAG_EVENT_CLOCK_REALTIME flag is set then the
29026d060e4SKent Gibson  * @timestamp_ns is read from %CLOCK_REALTIME.
291f75d508eSKent Gibson  *
292f75d508eSKent Gibson  * If the %GPIO_V2_LINE_FLAG_EVENT_CLOCK_HTE flag is set then the
293f75d508eSKent Gibson  * @timestamp_ns is provided by the hardware timestamping engine (HTE)
294f75d508eSKent Gibson  * subsystem.
295b53911aaSKent Gibson  */
296b53911aaSKent Gibson struct gpio_v2_line_event {
297b53911aaSKent Gibson 	__aligned_u64 timestamp_ns;
298b53911aaSKent Gibson 	__u32 id;
299b53911aaSKent Gibson 	__u32 offset;
300b53911aaSKent Gibson 	__u32 seqno;
301b53911aaSKent Gibson 	__u32 line_seqno;
302b53911aaSKent Gibson 	/* Space reserved for future use. */
303b53911aaSKent Gibson 	__u32 padding[6];
304b53911aaSKent Gibson };
305b53911aaSKent Gibson 
306b53911aaSKent Gibson /*
307b53911aaSKent Gibson  * ABI v1
308b234d233SKent Gibson  *
309b234d233SKent Gibson  * This version of the ABI is deprecated.
310b234d233SKent Gibson  * Use the latest version of the ABI, defined above, instead.
311b53911aaSKent Gibson  */
312b53911aaSKent Gibson 
313d7c51b47SLinus Walleij /* Informational flags */
314d7c51b47SLinus Walleij #define GPIOLINE_FLAG_KERNEL		(1UL << 0) /* Line used by the kernel */
315521a2ad6SLinus Walleij #define GPIOLINE_FLAG_IS_OUT		(1UL << 1)
316521a2ad6SLinus Walleij #define GPIOLINE_FLAG_ACTIVE_LOW	(1UL << 2)
317521a2ad6SLinus Walleij #define GPIOLINE_FLAG_OPEN_DRAIN	(1UL << 3)
318521a2ad6SLinus Walleij #define GPIOLINE_FLAG_OPEN_SOURCE	(1UL << 4)
3199225d516SDrew Fustini #define GPIOLINE_FLAG_BIAS_PULL_UP	(1UL << 5)
3209225d516SDrew Fustini #define GPIOLINE_FLAG_BIAS_PULL_DOWN	(1UL << 6)
3212148ad77SKent Gibson #define GPIOLINE_FLAG_BIAS_DISABLE	(1UL << 7)
322521a2ad6SLinus Walleij 
323521a2ad6SLinus Walleij /**
324521a2ad6SLinus Walleij  * struct gpioline_info - Information about a certain GPIO line
325214338e3SLinus Walleij  * @line_offset: the local offset on this GPIO device, fill this in when
326214338e3SLinus Walleij  * requesting the line information from the kernel
327521a2ad6SLinus Walleij  * @flags: various flags for this line
328214338e3SLinus Walleij  * @name: the name of this GPIO line, such as the output pin of the line on the
329214338e3SLinus Walleij  * chip, a rail or a pin header name on a board, as specified by the gpio
3302f84a2deSKent Gibson  * chip, may be empty (i.e. name[0] == '\0')
331214338e3SLinus Walleij  * @consumer: a functional name for the consumer of this GPIO line as set by
33232f5f62dSJonathan Neuschäfer  * whatever is using it, will be empty if there is no current user but may
33332f5f62dSJonathan Neuschäfer  * also be empty if the consumer doesn't set this up
334b234d233SKent Gibson  *
3352cc522d3SKent Gibson  * Note: This struct is part of ABI v1 and is deprecated.
336b6747ef6SKent Gibson  * Use ABI v2 and &struct gpio_v2_line_info instead.
337521a2ad6SLinus Walleij  */
338521a2ad6SLinus Walleij struct gpioline_info {
339521a2ad6SLinus Walleij 	__u32 line_offset;
340521a2ad6SLinus Walleij 	__u32 flags;
341539430fbSKent Gibson 	char name[GPIO_MAX_NAME_SIZE];
342539430fbSKent Gibson 	char consumer[GPIO_MAX_NAME_SIZE];
343521a2ad6SLinus Walleij };
344521a2ad6SLinus Walleij 
345d7c51b47SLinus Walleij /* Maximum number of requested handles */
346d7c51b47SLinus Walleij #define GPIOHANDLES_MAX 64
347d7c51b47SLinus Walleij 
34851c1064eSBartosz Golaszewski /* Possible line status change events */
34951c1064eSBartosz Golaszewski enum {
35051c1064eSBartosz Golaszewski 	GPIOLINE_CHANGED_REQUESTED = 1,
35151c1064eSBartosz Golaszewski 	GPIOLINE_CHANGED_RELEASED,
35251c1064eSBartosz Golaszewski 	GPIOLINE_CHANGED_CONFIG,
35351c1064eSBartosz Golaszewski };
35451c1064eSBartosz Golaszewski 
35551c1064eSBartosz Golaszewski /**
35651c1064eSBartosz Golaszewski  * struct gpioline_info_changed - Information about a change in status
35751c1064eSBartosz Golaszewski  * of a GPIO line
35851c1064eSBartosz Golaszewski  * @info: updated line information
35951c1064eSBartosz Golaszewski  * @timestamp: estimate of time of status change occurrence, in nanoseconds
3602cc522d3SKent Gibson  * @event_type: one of %GPIOLINE_CHANGED_REQUESTED,
3612cc522d3SKent Gibson  * %GPIOLINE_CHANGED_RELEASED and %GPIOLINE_CHANGED_CONFIG
3625760648eSKent Gibson  * @padding: reserved for future use
36351c1064eSBartosz Golaszewski  *
3642cc522d3SKent Gibson  * The &struct gpioline_info embedded here has 32-bit alignment on its own,
36551c1064eSBartosz Golaszewski  * but it works fine with 64-bit alignment too. With its 72 byte size, we can
36651c1064eSBartosz Golaszewski  * guarantee there are no implicit holes between it and subsequent members.
36751c1064eSBartosz Golaszewski  * The 20-byte padding at the end makes sure we don't add any implicit padding
36851c1064eSBartosz Golaszewski  * at the end of the structure on 64-bit architectures.
369b234d233SKent Gibson  *
3702cc522d3SKent Gibson  * Note: This struct is part of ABI v1 and is deprecated.
371b6747ef6SKent Gibson  * Use ABI v2 and &struct gpio_v2_line_info_changed instead.
37251c1064eSBartosz Golaszewski  */
37351c1064eSBartosz Golaszewski struct gpioline_info_changed {
37451c1064eSBartosz Golaszewski 	struct gpioline_info info;
37551c1064eSBartosz Golaszewski 	__u64 timestamp;
37651c1064eSBartosz Golaszewski 	__u32 event_type;
37751c1064eSBartosz Golaszewski 	__u32 padding[5]; /* for future use */
37851c1064eSBartosz Golaszewski };
37951c1064eSBartosz Golaszewski 
38061f922dbSLinus Walleij /* Linerequest flags */
381d7c51b47SLinus Walleij #define GPIOHANDLE_REQUEST_INPUT	(1UL << 0)
382d7c51b47SLinus Walleij #define GPIOHANDLE_REQUEST_OUTPUT	(1UL << 1)
383d7c51b47SLinus Walleij #define GPIOHANDLE_REQUEST_ACTIVE_LOW	(1UL << 2)
384d7c51b47SLinus Walleij #define GPIOHANDLE_REQUEST_OPEN_DRAIN	(1UL << 3)
385d7c51b47SLinus Walleij #define GPIOHANDLE_REQUEST_OPEN_SOURCE	(1UL << 4)
3869225d516SDrew Fustini #define GPIOHANDLE_REQUEST_BIAS_PULL_UP	(1UL << 5)
3879225d516SDrew Fustini #define GPIOHANDLE_REQUEST_BIAS_PULL_DOWN	(1UL << 6)
3882148ad77SKent Gibson #define GPIOHANDLE_REQUEST_BIAS_DISABLE	(1UL << 7)
389d7c51b47SLinus Walleij 
390d7c51b47SLinus Walleij /**
391d7c51b47SLinus Walleij  * struct gpiohandle_request - Information about a GPIO handle request
3920b35cd7bSGeert Uytterhoeven  * @lineoffsets: an array of desired lines, specified by offset index for the
393d7c51b47SLinus Walleij  * associated GPIO device
394d7c51b47SLinus Walleij  * @flags: desired flags for the desired GPIO lines, such as
3952cc522d3SKent Gibson  * %GPIOHANDLE_REQUEST_OUTPUT, %GPIOHANDLE_REQUEST_ACTIVE_LOW etc, added
396d7c51b47SLinus Walleij  * together. Note that even if multiple lines are requested, the same flags
397d7c51b47SLinus Walleij  * must be applicable to all of them, if you want lines with individual
398d7c51b47SLinus Walleij  * flags set, request them one by one. It is possible to select
399d7c51b47SLinus Walleij  * a batch of input or output lines, but they must all have the same
400d7c51b47SLinus Walleij  * characteristics, i.e. all inputs or all outputs, all active low etc
4012cc522d3SKent Gibson  * @default_values: if the %GPIOHANDLE_REQUEST_OUTPUT is set for a requested
402*8ff0d55bSKent Gibson  * line, this specifies the default output value, should be 0 (inactive) or
403*8ff0d55bSKent Gibson  * 1 (active).  Anything other than 0 or 1 will be interpreted as active.
404d7c51b47SLinus Walleij  * @consumer_label: a desired consumer label for the selected GPIO line(s)
405d7c51b47SLinus Walleij  * such as "my-bitbanged-relay"
406d7c51b47SLinus Walleij  * @lines: number of lines requested in this request, i.e. the number of
407d7c51b47SLinus Walleij  * valid fields in the above arrays, set to 1 to request a single line
4087889968eSKent Gibson  * @fd: after a successful %GPIO_GET_LINEHANDLE_IOCTL operation, contains
4097889968eSKent Gibson  * a valid anonymous file descriptor representing the request
410b234d233SKent Gibson  *
4112cc522d3SKent Gibson  * Note: This struct is part of ABI v1 and is deprecated.
412b6747ef6SKent Gibson  * Use ABI v2 and &struct gpio_v2_line_request instead.
413d7c51b47SLinus Walleij  */
414d7c51b47SLinus Walleij struct gpiohandle_request {
415d7c51b47SLinus Walleij 	__u32 lineoffsets[GPIOHANDLES_MAX];
416d7c51b47SLinus Walleij 	__u32 flags;
417d7c51b47SLinus Walleij 	__u8 default_values[GPIOHANDLES_MAX];
418539430fbSKent Gibson 	char consumer_label[GPIO_MAX_NAME_SIZE];
419d7c51b47SLinus Walleij 	__u32 lines;
420d7c51b47SLinus Walleij 	int fd;
421d7c51b47SLinus Walleij };
422d7c51b47SLinus Walleij 
423d7c51b47SLinus Walleij /**
424e588bb1eSKent Gibson  * struct gpiohandle_config - Configuration for a GPIO handle request
425e588bb1eSKent Gibson  * @flags: updated flags for the requested GPIO lines, such as
4262cc522d3SKent Gibson  * %GPIOHANDLE_REQUEST_OUTPUT, %GPIOHANDLE_REQUEST_ACTIVE_LOW etc, added
427e588bb1eSKent Gibson  * together
4282cc522d3SKent Gibson  * @default_values: if the %GPIOHANDLE_REQUEST_OUTPUT is set in flags,
429*8ff0d55bSKent Gibson  * this specifies the default output value, should be 0 (inactive) or
430*8ff0d55bSKent Gibson  * 1 (active).  Anything other than 0 or 1 will be interpreted as active.
431e588bb1eSKent Gibson  * @padding: reserved for future use and should be zero filled
432b234d233SKent Gibson  *
4332cc522d3SKent Gibson  * Note: This struct is part of ABI v1 and is deprecated.
434b6747ef6SKent Gibson  * Use ABI v2 and &struct gpio_v2_line_config instead.
435e588bb1eSKent Gibson  */
436e588bb1eSKent Gibson struct gpiohandle_config {
437e588bb1eSKent Gibson 	__u32 flags;
438e588bb1eSKent Gibson 	__u8 default_values[GPIOHANDLES_MAX];
439e588bb1eSKent Gibson 	__u32 padding[4]; /* padding for future use */
440e588bb1eSKent Gibson };
441e588bb1eSKent Gibson 
442e588bb1eSKent Gibson /**
443d7c51b47SLinus Walleij  * struct gpiohandle_data - Information of values on a GPIO handle
444d7c51b47SLinus Walleij  * @values: when getting the state of lines this contains the current
445d7c51b47SLinus Walleij  * state of a line, when setting the state of lines these should contain
446*8ff0d55bSKent Gibson  * the desired target state.  States are 0 (inactive) or 1 (active).
447*8ff0d55bSKent Gibson  * When setting, anything other than 0 or 1 will be interpreted as active.
448b234d233SKent Gibson  *
4492cc522d3SKent Gibson  * Note: This struct is part of ABI v1 and is deprecated.
450b6747ef6SKent Gibson  * Use ABI v2 and &struct gpio_v2_line_values instead.
451d7c51b47SLinus Walleij  */
452d7c51b47SLinus Walleij struct gpiohandle_data {
453d7c51b47SLinus Walleij 	__u8 values[GPIOHANDLES_MAX];
454d7c51b47SLinus Walleij };
455d7c51b47SLinus Walleij 
45661f922dbSLinus Walleij /* Eventrequest flags */
45761f922dbSLinus Walleij #define GPIOEVENT_REQUEST_RISING_EDGE	(1UL << 0)
45861f922dbSLinus Walleij #define GPIOEVENT_REQUEST_FALLING_EDGE	(1UL << 1)
45961f922dbSLinus Walleij #define GPIOEVENT_REQUEST_BOTH_EDGES	((1UL << 0) | (1UL << 1))
46061f922dbSLinus Walleij 
46161f922dbSLinus Walleij /**
46261f922dbSLinus Walleij  * struct gpioevent_request - Information about a GPIO event request
46361f922dbSLinus Walleij  * @lineoffset: the desired line to subscribe to events from, specified by
46461f922dbSLinus Walleij  * offset index for the associated GPIO device
46561f922dbSLinus Walleij  * @handleflags: desired handle flags for the desired GPIO line, such as
4662cc522d3SKent Gibson  * %GPIOHANDLE_REQUEST_ACTIVE_LOW or %GPIOHANDLE_REQUEST_OPEN_DRAIN
46761f922dbSLinus Walleij  * @eventflags: desired flags for the desired GPIO event line, such as
4682cc522d3SKent Gibson  * %GPIOEVENT_REQUEST_RISING_EDGE or %GPIOEVENT_REQUEST_FALLING_EDGE
46961f922dbSLinus Walleij  * @consumer_label: a desired consumer label for the selected GPIO line(s)
47061f922dbSLinus Walleij  * such as "my-listener"
4717889968eSKent Gibson  * @fd: after a successful %GPIO_GET_LINEEVENT_IOCTL operation, contains a
4727889968eSKent Gibson  * valid anonymous file descriptor representing the request
473b234d233SKent Gibson  *
4742cc522d3SKent Gibson  * Note: This struct is part of ABI v1 and is deprecated.
475b6747ef6SKent Gibson  * Use ABI v2 and &struct gpio_v2_line_request instead.
47661f922dbSLinus Walleij  */
47761f922dbSLinus Walleij struct gpioevent_request {
47861f922dbSLinus Walleij 	__u32 lineoffset;
47961f922dbSLinus Walleij 	__u32 handleflags;
48061f922dbSLinus Walleij 	__u32 eventflags;
481539430fbSKent Gibson 	char consumer_label[GPIO_MAX_NAME_SIZE];
48261f922dbSLinus Walleij 	int fd;
48361f922dbSLinus Walleij };
48461f922dbSLinus Walleij 
4855760648eSKent Gibson /*
48661f922dbSLinus Walleij  * GPIO event types
48761f922dbSLinus Walleij  */
48861f922dbSLinus Walleij #define GPIOEVENT_EVENT_RISING_EDGE 0x01
48961f922dbSLinus Walleij #define GPIOEVENT_EVENT_FALLING_EDGE 0x02
49061f922dbSLinus Walleij 
49161f922dbSLinus Walleij /**
49261f922dbSLinus Walleij  * struct gpioevent_data - The actual event being pushed to userspace
49361f922dbSLinus Walleij  * @timestamp: best estimate of time of event occurrence, in nanoseconds
494ead7c581SKent Gibson  * @id: event identifier, one of %GPIOEVENT_EVENT_RISING_EDGE or
495ead7c581SKent Gibson  *  %GPIOEVENT_EVENT_FALLING_EDGE
496b234d233SKent Gibson  *
4972cc522d3SKent Gibson  * Note: This struct is part of ABI v1 and is deprecated.
498b6747ef6SKent Gibson  * Use ABI v2 and &struct gpio_v2_line_event instead.
49961f922dbSLinus Walleij  */
50061f922dbSLinus Walleij struct gpioevent_data {
50161f922dbSLinus Walleij 	__u64 timestamp;
50261f922dbSLinus Walleij 	__u32 id;
50361f922dbSLinus Walleij };
50461f922dbSLinus Walleij 
505b53911aaSKent Gibson /*
506b53911aaSKent Gibson  * v1 and v2 ioctl()s
507b53911aaSKent Gibson  */
50861f922dbSLinus Walleij #define GPIO_GET_CHIPINFO_IOCTL _IOR(0xB4, 0x01, struct gpiochip_info)
509b53911aaSKent Gibson #define GPIO_GET_LINEINFO_UNWATCH_IOCTL _IOWR(0xB4, 0x0C, __u32)
510b53911aaSKent Gibson 
511b53911aaSKent Gibson /*
512b53911aaSKent Gibson  * v2 ioctl()s
513b53911aaSKent Gibson  */
514b53911aaSKent Gibson #define GPIO_V2_GET_LINEINFO_IOCTL _IOWR(0xB4, 0x05, struct gpio_v2_line_info)
515b53911aaSKent Gibson #define GPIO_V2_GET_LINEINFO_WATCH_IOCTL _IOWR(0xB4, 0x06, struct gpio_v2_line_info)
516b53911aaSKent Gibson #define GPIO_V2_GET_LINE_IOCTL _IOWR(0xB4, 0x07, struct gpio_v2_line_request)
517b53911aaSKent Gibson #define GPIO_V2_LINE_SET_CONFIG_IOCTL _IOWR(0xB4, 0x0D, struct gpio_v2_line_config)
518b53911aaSKent Gibson #define GPIO_V2_LINE_GET_VALUES_IOCTL _IOWR(0xB4, 0x0E, struct gpio_v2_line_values)
519b53911aaSKent Gibson #define GPIO_V2_LINE_SET_VALUES_IOCTL _IOWR(0xB4, 0x0F, struct gpio_v2_line_values)
520b53911aaSKent Gibson 
521b53911aaSKent Gibson /*
522b53911aaSKent Gibson  * v1 ioctl()s
523b234d233SKent Gibson  *
524b234d233SKent Gibson  * These ioctl()s are deprecated.  Use the v2 equivalent instead.
525b53911aaSKent Gibson  */
52661f922dbSLinus Walleij #define GPIO_GET_LINEINFO_IOCTL _IOWR(0xB4, 0x02, struct gpioline_info)
52761f922dbSLinus Walleij #define GPIO_GET_LINEHANDLE_IOCTL _IOWR(0xB4, 0x03, struct gpiohandle_request)
52861f922dbSLinus Walleij #define GPIO_GET_LINEEVENT_IOCTL _IOWR(0xB4, 0x04, struct gpioevent_request)
529b53911aaSKent Gibson #define GPIOHANDLE_GET_LINE_VALUES_IOCTL _IOWR(0xB4, 0x08, struct gpiohandle_data)
530b53911aaSKent Gibson #define GPIOHANDLE_SET_LINE_VALUES_IOCTL _IOWR(0xB4, 0x09, struct gpiohandle_data)
531b53911aaSKent Gibson #define GPIOHANDLE_SET_CONFIG_IOCTL _IOWR(0xB4, 0x0A, struct gpiohandle_config)
532b53911aaSKent Gibson #define GPIO_GET_LINEINFO_WATCH_IOCTL _IOWR(0xB4, 0x0B, struct gpioline_info)
53361f922dbSLinus Walleij 
5343c702e99SLinus Walleij #endif /* _UAPI_GPIO_H_ */
535