Linux kernel mirror (for testing)
git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel
os
linux
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 */
24struct 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 */
52struct 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 */
94struct 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_config - Configuration for a GPIO handle request
105 * @flags: updated flags for the requested GPIO lines, such as
106 * GPIOHANDLE_REQUEST_OUTPUT, GPIOHANDLE_REQUEST_ACTIVE_LOW etc, OR:ed
107 * together
108 * @default_values: if the GPIOHANDLE_REQUEST_OUTPUT is set in flags,
109 * this specifies the default output value, should be 0 (low) or
110 * 1 (high), anything else than 0 or 1 will be interpreted as 1 (high)
111 * @padding: reserved for future use and should be zero filled
112 */
113struct gpiohandle_config {
114 __u32 flags;
115 __u8 default_values[GPIOHANDLES_MAX];
116 __u32 padding[4]; /* padding for future use */
117};
118
119#define GPIOHANDLE_SET_CONFIG_IOCTL _IOWR(0xB4, 0x0a, struct gpiohandle_config)
120
121/**
122 * struct gpiohandle_data - Information of values on a GPIO handle
123 * @values: when getting the state of lines this contains the current
124 * state of a line, when setting the state of lines these should contain
125 * the desired target state
126 */
127struct gpiohandle_data {
128 __u8 values[GPIOHANDLES_MAX];
129};
130
131#define GPIOHANDLE_GET_LINE_VALUES_IOCTL _IOWR(0xB4, 0x08, struct gpiohandle_data)
132#define GPIOHANDLE_SET_LINE_VALUES_IOCTL _IOWR(0xB4, 0x09, struct gpiohandle_data)
133
134/* Eventrequest flags */
135#define GPIOEVENT_REQUEST_RISING_EDGE (1UL << 0)
136#define GPIOEVENT_REQUEST_FALLING_EDGE (1UL << 1)
137#define GPIOEVENT_REQUEST_BOTH_EDGES ((1UL << 0) | (1UL << 1))
138
139/**
140 * struct gpioevent_request - Information about a GPIO event request
141 * @lineoffset: the desired line to subscribe to events from, specified by
142 * offset index for the associated GPIO device
143 * @handleflags: desired handle flags for the desired GPIO line, such as
144 * GPIOHANDLE_REQUEST_ACTIVE_LOW or GPIOHANDLE_REQUEST_OPEN_DRAIN
145 * @eventflags: desired flags for the desired GPIO event line, such as
146 * GPIOEVENT_REQUEST_RISING_EDGE or GPIOEVENT_REQUEST_FALLING_EDGE
147 * @consumer_label: a desired consumer label for the selected GPIO line(s)
148 * such as "my-listener"
149 * @fd: if successful this field will contain a valid anonymous file handle
150 * after a GPIO_GET_LINEEVENT_IOCTL operation, zero or negative value
151 * means error
152 */
153struct gpioevent_request {
154 __u32 lineoffset;
155 __u32 handleflags;
156 __u32 eventflags;
157 char consumer_label[32];
158 int fd;
159};
160
161/**
162 * GPIO event types
163 */
164#define GPIOEVENT_EVENT_RISING_EDGE 0x01
165#define GPIOEVENT_EVENT_FALLING_EDGE 0x02
166
167/**
168 * struct gpioevent_data - The actual event being pushed to userspace
169 * @timestamp: best estimate of time of event occurrence, in nanoseconds
170 * @id: event identifier
171 */
172struct gpioevent_data {
173 __u64 timestamp;
174 __u32 id;
175};
176
177#define GPIO_GET_CHIPINFO_IOCTL _IOR(0xB4, 0x01, struct gpiochip_info)
178#define GPIO_GET_LINEINFO_IOCTL _IOWR(0xB4, 0x02, struct gpioline_info)
179#define GPIO_GET_LINEHANDLE_IOCTL _IOWR(0xB4, 0x03, struct gpiohandle_request)
180#define GPIO_GET_LINEEVENT_IOCTL _IOWR(0xB4, 0x04, struct gpioevent_request)
181
182#endif /* _UAPI_GPIO_H_ */