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