xref: /linux/include/uapi/linux/gpio.h (revision 61f922db72216b00386581c851db9c9095961522)
13c702e99SLinus Walleij /*
23c702e99SLinus Walleij  * <linux/gpio.h> - userspace ABI for the GPIO character devices
33c702e99SLinus Walleij  *
4d7c51b47SLinus Walleij  * Copyright (C) 2016 Linus Walleij
53c702e99SLinus Walleij  *
63c702e99SLinus Walleij  * This program is free software; you can redistribute it and/or modify it
73c702e99SLinus Walleij  * under the terms of the GNU General Public License version 2 as published by
83c702e99SLinus Walleij  * the Free Software Foundation.
93c702e99SLinus Walleij  */
103c702e99SLinus Walleij #ifndef _UAPI_GPIO_H_
113c702e99SLinus Walleij #define _UAPI_GPIO_H_
123c702e99SLinus Walleij 
133c702e99SLinus Walleij #include <linux/ioctl.h>
143c702e99SLinus Walleij #include <linux/types.h>
153c702e99SLinus Walleij 
163c702e99SLinus Walleij /**
173c702e99SLinus Walleij  * struct gpiochip_info - Information about a certain GPIO chip
18214338e3SLinus Walleij  * @name: the Linux kernel name of this GPIO chip
19214338e3SLinus Walleij  * @label: a functional name for this GPIO chip, such as a product
20214338e3SLinus Walleij  * number, may be NULL
213c702e99SLinus Walleij  * @lines: number of GPIO lines on this chip
223c702e99SLinus Walleij  */
233c702e99SLinus Walleij struct gpiochip_info {
243c702e99SLinus Walleij 	char name[32];
25df4878e9SLinus Walleij 	char label[32];
263c702e99SLinus Walleij 	__u32 lines;
273c702e99SLinus Walleij };
283c702e99SLinus Walleij 
29d7c51b47SLinus Walleij /* Informational flags */
30d7c51b47SLinus Walleij #define GPIOLINE_FLAG_KERNEL		(1UL << 0) /* Line used by the kernel */
31521a2ad6SLinus Walleij #define GPIOLINE_FLAG_IS_OUT		(1UL << 1)
32521a2ad6SLinus Walleij #define GPIOLINE_FLAG_ACTIVE_LOW	(1UL << 2)
33521a2ad6SLinus Walleij #define GPIOLINE_FLAG_OPEN_DRAIN	(1UL << 3)
34521a2ad6SLinus Walleij #define GPIOLINE_FLAG_OPEN_SOURCE	(1UL << 4)
35521a2ad6SLinus Walleij 
36521a2ad6SLinus Walleij /**
37521a2ad6SLinus Walleij  * struct gpioline_info - Information about a certain GPIO line
38214338e3SLinus Walleij  * @line_offset: the local offset on this GPIO device, fill this in when
39214338e3SLinus Walleij  * requesting the line information from the kernel
40521a2ad6SLinus Walleij  * @flags: various flags for this line
41214338e3SLinus Walleij  * @name: the name of this GPIO line, such as the output pin of the line on the
42214338e3SLinus Walleij  * chip, a rail or a pin header name on a board, as specified by the gpio
43214338e3SLinus Walleij  * chip, may be NULL
44214338e3SLinus Walleij  * @consumer: a functional name for the consumer of this GPIO line as set by
45214338e3SLinus Walleij  * whatever is using it, will be NULL if there is no current user but may
46214338e3SLinus Walleij  * also be NULL if the consumer doesn't set this up
47521a2ad6SLinus Walleij  */
48521a2ad6SLinus Walleij struct gpioline_info {
49521a2ad6SLinus Walleij 	__u32 line_offset;
50521a2ad6SLinus Walleij 	__u32 flags;
51521a2ad6SLinus Walleij 	char name[32];
52214338e3SLinus Walleij 	char consumer[32];
53521a2ad6SLinus Walleij };
54521a2ad6SLinus Walleij 
55d7c51b47SLinus Walleij /* Maximum number of requested handles */
56d7c51b47SLinus Walleij #define GPIOHANDLES_MAX 64
57d7c51b47SLinus Walleij 
58*61f922dbSLinus Walleij /* Linerequest flags */
59d7c51b47SLinus Walleij #define GPIOHANDLE_REQUEST_INPUT	(1UL << 0)
60d7c51b47SLinus Walleij #define GPIOHANDLE_REQUEST_OUTPUT	(1UL << 1)
61d7c51b47SLinus Walleij #define GPIOHANDLE_REQUEST_ACTIVE_LOW	(1UL << 2)
62d7c51b47SLinus Walleij #define GPIOHANDLE_REQUEST_OPEN_DRAIN	(1UL << 3)
63d7c51b47SLinus Walleij #define GPIOHANDLE_REQUEST_OPEN_SOURCE	(1UL << 4)
64d7c51b47SLinus Walleij 
65d7c51b47SLinus Walleij /**
66d7c51b47SLinus Walleij  * struct gpiohandle_request - Information about a GPIO handle request
67d7c51b47SLinus Walleij  * @lineoffsets: an array desired lines, specified by offset index for the
68d7c51b47SLinus Walleij  * associated GPIO device
69d7c51b47SLinus Walleij  * @flags: desired flags for the desired GPIO lines, such as
70d7c51b47SLinus Walleij  * GPIOHANDLE_REQUEST_OUTPUT, GPIOHANDLE_REQUEST_ACTIVE_LOW etc, OR:ed
71d7c51b47SLinus Walleij  * together. Note that even if multiple lines are requested, the same flags
72d7c51b47SLinus Walleij  * must be applicable to all of them, if you want lines with individual
73d7c51b47SLinus Walleij  * flags set, request them one by one. It is possible to select
74d7c51b47SLinus Walleij  * a batch of input or output lines, but they must all have the same
75d7c51b47SLinus Walleij  * characteristics, i.e. all inputs or all outputs, all active low etc
76d7c51b47SLinus Walleij  * @default_values: if the GPIOHANDLE_REQUEST_OUTPUT is set for a requested
77d7c51b47SLinus Walleij  * line, this specifies the default output value, should be 0 (low) or
78d7c51b47SLinus Walleij  * 1 (high), anything else than 0 or 1 will be interpreted as 1 (high)
79d7c51b47SLinus Walleij  * @consumer_label: a desired consumer label for the selected GPIO line(s)
80d7c51b47SLinus Walleij  * such as "my-bitbanged-relay"
81d7c51b47SLinus Walleij  * @lines: number of lines requested in this request, i.e. the number of
82d7c51b47SLinus Walleij  * valid fields in the above arrays, set to 1 to request a single line
83d7c51b47SLinus Walleij  * @fd: if successful this field will contain a valid anonymous file handle
84d7c51b47SLinus Walleij  * after a GPIO_GET_LINEHANDLE_IOCTL operation, zero or negative value
85d7c51b47SLinus Walleij  * means error
86d7c51b47SLinus Walleij  */
87d7c51b47SLinus Walleij struct gpiohandle_request {
88d7c51b47SLinus Walleij 	__u32 lineoffsets[GPIOHANDLES_MAX];
89d7c51b47SLinus Walleij 	__u32 flags;
90d7c51b47SLinus Walleij 	__u8 default_values[GPIOHANDLES_MAX];
91d7c51b47SLinus Walleij 	char consumer_label[32];
92d7c51b47SLinus Walleij 	__u32 lines;
93d7c51b47SLinus Walleij 	int fd;
94d7c51b47SLinus Walleij };
95d7c51b47SLinus Walleij 
96d7c51b47SLinus Walleij /**
97d7c51b47SLinus Walleij  * struct gpiohandle_data - Information of values on a GPIO handle
98d7c51b47SLinus Walleij  * @values: when getting the state of lines this contains the current
99d7c51b47SLinus Walleij  * state of a line, when setting the state of lines these should contain
100d7c51b47SLinus Walleij  * the desired target state
101d7c51b47SLinus Walleij  */
102d7c51b47SLinus Walleij struct gpiohandle_data {
103d7c51b47SLinus Walleij 	__u8 values[GPIOHANDLES_MAX];
104d7c51b47SLinus Walleij };
105d7c51b47SLinus Walleij 
106d7c51b47SLinus Walleij #define GPIOHANDLE_GET_LINE_VALUES_IOCTL _IOWR(0xB4, 0x08, struct gpiohandle_data)
107d7c51b47SLinus Walleij #define GPIOHANDLE_SET_LINE_VALUES_IOCTL _IOWR(0xB4, 0x09, struct gpiohandle_data)
1083c702e99SLinus Walleij 
109*61f922dbSLinus Walleij /* Eventrequest flags */
110*61f922dbSLinus Walleij #define GPIOEVENT_REQUEST_RISING_EDGE	(1UL << 0)
111*61f922dbSLinus Walleij #define GPIOEVENT_REQUEST_FALLING_EDGE	(1UL << 1)
112*61f922dbSLinus Walleij #define GPIOEVENT_REQUEST_BOTH_EDGES	((1UL << 0) | (1UL << 1))
113*61f922dbSLinus Walleij 
114*61f922dbSLinus Walleij /**
115*61f922dbSLinus Walleij  * struct gpioevent_request - Information about a GPIO event request
116*61f922dbSLinus Walleij  * @lineoffset: the desired line to subscribe to events from, specified by
117*61f922dbSLinus Walleij  * offset index for the associated GPIO device
118*61f922dbSLinus Walleij  * @handleflags: desired handle flags for the desired GPIO line, such as
119*61f922dbSLinus Walleij  * GPIOHANDLE_REQUEST_ACTIVE_LOW or GPIOHANDLE_REQUEST_OPEN_DRAIN
120*61f922dbSLinus Walleij  * @eventflags: desired flags for the desired GPIO event line, such as
121*61f922dbSLinus Walleij  * GPIOEVENT_REQUEST_RISING_EDGE or GPIOEVENT_REQUEST_FALLING_EDGE
122*61f922dbSLinus Walleij  * @consumer_label: a desired consumer label for the selected GPIO line(s)
123*61f922dbSLinus Walleij  * such as "my-listener"
124*61f922dbSLinus Walleij  * @fd: if successful this field will contain a valid anonymous file handle
125*61f922dbSLinus Walleij  * after a GPIO_GET_LINEEVENT_IOCTL operation, zero or negative value
126*61f922dbSLinus Walleij  * means error
127*61f922dbSLinus Walleij  */
128*61f922dbSLinus Walleij struct gpioevent_request {
129*61f922dbSLinus Walleij 	__u32 lineoffset;
130*61f922dbSLinus Walleij 	__u32 handleflags;
131*61f922dbSLinus Walleij 	__u32 eventflags;
132*61f922dbSLinus Walleij 	char consumer_label[32];
133*61f922dbSLinus Walleij 	int fd;
134*61f922dbSLinus Walleij };
135*61f922dbSLinus Walleij 
136*61f922dbSLinus Walleij /**
137*61f922dbSLinus Walleij  * GPIO event types
138*61f922dbSLinus Walleij  */
139*61f922dbSLinus Walleij #define GPIOEVENT_EVENT_RISING_EDGE 0x01
140*61f922dbSLinus Walleij #define GPIOEVENT_EVENT_FALLING_EDGE 0x02
141*61f922dbSLinus Walleij 
142*61f922dbSLinus Walleij /**
143*61f922dbSLinus Walleij  * struct gpioevent_data - The actual event being pushed to userspace
144*61f922dbSLinus Walleij  * @timestamp: best estimate of time of event occurrence, in nanoseconds
145*61f922dbSLinus Walleij  * @id: event identifier
146*61f922dbSLinus Walleij  */
147*61f922dbSLinus Walleij struct gpioevent_data {
148*61f922dbSLinus Walleij 	__u64 timestamp;
149*61f922dbSLinus Walleij 	__u32 id;
150*61f922dbSLinus Walleij };
151*61f922dbSLinus Walleij 
152*61f922dbSLinus Walleij #define GPIO_GET_CHIPINFO_IOCTL _IOR(0xB4, 0x01, struct gpiochip_info)
153*61f922dbSLinus Walleij #define GPIO_GET_LINEINFO_IOCTL _IOWR(0xB4, 0x02, struct gpioline_info)
154*61f922dbSLinus Walleij #define GPIO_GET_LINEHANDLE_IOCTL _IOWR(0xB4, 0x03, struct gpiohandle_request)
155*61f922dbSLinus Walleij #define GPIO_GET_LINEEVENT_IOCTL _IOWR(0xB4, 0x04, struct gpioevent_request)
156*61f922dbSLinus Walleij 
1573c702e99SLinus Walleij #endif /* _UAPI_GPIO_H_ */
158