Linus Walleij | 3c702e9 | 2015-10-21 15:29:53 +0200 | [diff] [blame] | 1 | /* |
| 2 | * <linux/gpio.h> - userspace ABI for the GPIO character devices |
| 3 | * |
Linus Walleij | d7c51b4 | 2016-04-26 10:35:29 +0200 | [diff] [blame] | 4 | * Copyright (C) 2016 Linus Walleij |
Linus Walleij | 3c702e9 | 2015-10-21 15:29:53 +0200 | [diff] [blame] | 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify it |
| 7 | * under the terms of the GNU General Public License version 2 as published by |
| 8 | * the Free Software Foundation. |
| 9 | */ |
| 10 | #ifndef _UAPI_GPIO_H_ |
| 11 | #define _UAPI_GPIO_H_ |
| 12 | |
| 13 | #include <linux/ioctl.h> |
| 14 | #include <linux/types.h> |
| 15 | |
| 16 | /** |
| 17 | * struct gpiochip_info - Information about a certain GPIO chip |
Linus Walleij | 214338e | 2016-02-25 21:01:48 +0100 | [diff] [blame] | 18 | * @name: the Linux kernel name of this GPIO chip |
| 19 | * @label: a functional name for this GPIO chip, such as a product |
| 20 | * number, may be NULL |
Linus Walleij | 3c702e9 | 2015-10-21 15:29:53 +0200 | [diff] [blame] | 21 | * @lines: number of GPIO lines on this chip |
| 22 | */ |
| 23 | struct gpiochip_info { |
| 24 | char name[32]; |
Linus Walleij | df4878e | 2016-02-12 14:48:23 +0100 | [diff] [blame] | 25 | char label[32]; |
Linus Walleij | 3c702e9 | 2015-10-21 15:29:53 +0200 | [diff] [blame] | 26 | __u32 lines; |
| 27 | }; |
| 28 | |
Linus Walleij | d7c51b4 | 2016-04-26 10:35:29 +0200 | [diff] [blame] | 29 | /* Informational flags */ |
| 30 | #define GPIOLINE_FLAG_KERNEL (1UL << 0) /* Line used by the kernel */ |
Linus Walleij | 521a2ad | 2016-02-12 22:25:22 +0100 | [diff] [blame] | 31 | #define GPIOLINE_FLAG_IS_OUT (1UL << 1) |
| 32 | #define GPIOLINE_FLAG_ACTIVE_LOW (1UL << 2) |
| 33 | #define GPIOLINE_FLAG_OPEN_DRAIN (1UL << 3) |
| 34 | #define GPIOLINE_FLAG_OPEN_SOURCE (1UL << 4) |
| 35 | |
| 36 | /** |
| 37 | * struct gpioline_info - Information about a certain GPIO line |
Linus Walleij | 214338e | 2016-02-25 21:01:48 +0100 | [diff] [blame] | 38 | * @line_offset: the local offset on this GPIO device, fill this in when |
| 39 | * requesting the line information from the kernel |
Linus Walleij | 521a2ad | 2016-02-12 22:25:22 +0100 | [diff] [blame] | 40 | * @flags: various flags for this line |
Linus Walleij | 214338e | 2016-02-25 21:01:48 +0100 | [diff] [blame] | 41 | * @name: the name of this GPIO line, such as the output pin of the line on the |
| 42 | * chip, a rail or a pin header name on a board, as specified by the gpio |
| 43 | * chip, may be NULL |
| 44 | * @consumer: a functional name for the consumer of this GPIO line as set by |
| 45 | * whatever is using it, will be NULL if there is no current user but may |
| 46 | * also be NULL if the consumer doesn't set this up |
Linus Walleij | 521a2ad | 2016-02-12 22:25:22 +0100 | [diff] [blame] | 47 | */ |
| 48 | struct gpioline_info { |
| 49 | __u32 line_offset; |
| 50 | __u32 flags; |
| 51 | char name[32]; |
Linus Walleij | 214338e | 2016-02-25 21:01:48 +0100 | [diff] [blame] | 52 | char consumer[32]; |
Linus Walleij | 521a2ad | 2016-02-12 22:25:22 +0100 | [diff] [blame] | 53 | }; |
| 54 | |
Linus Walleij | d7c51b4 | 2016-04-26 10:35:29 +0200 | [diff] [blame] | 55 | /* Maximum number of requested handles */ |
| 56 | #define GPIOHANDLES_MAX 64 |
| 57 | |
Linus Walleij | 61f922d | 2016-06-02 11:30:15 +0200 | [diff] [blame] | 58 | /* Linerequest flags */ |
Linus Walleij | d7c51b4 | 2016-04-26 10:35:29 +0200 | [diff] [blame] | 59 | #define GPIOHANDLE_REQUEST_INPUT (1UL << 0) |
| 60 | #define GPIOHANDLE_REQUEST_OUTPUT (1UL << 1) |
| 61 | #define GPIOHANDLE_REQUEST_ACTIVE_LOW (1UL << 2) |
| 62 | #define GPIOHANDLE_REQUEST_OPEN_DRAIN (1UL << 3) |
| 63 | #define GPIOHANDLE_REQUEST_OPEN_SOURCE (1UL << 4) |
| 64 | |
| 65 | /** |
| 66 | * struct gpiohandle_request - Information about a GPIO handle request |
| 67 | * @lineoffsets: an array desired lines, specified by offset index for the |
| 68 | * associated GPIO device |
| 69 | * @flags: desired flags for the desired GPIO lines, such as |
| 70 | * GPIOHANDLE_REQUEST_OUTPUT, GPIOHANDLE_REQUEST_ACTIVE_LOW etc, OR:ed |
| 71 | * together. Note that even if multiple lines are requested, the same flags |
| 72 | * must be applicable to all of them, if you want lines with individual |
| 73 | * flags set, request them one by one. It is possible to select |
| 74 | * a batch of input or output lines, but they must all have the same |
| 75 | * characteristics, i.e. all inputs or all outputs, all active low etc |
| 76 | * @default_values: if the GPIOHANDLE_REQUEST_OUTPUT is set for a requested |
| 77 | * line, this specifies the default output value, should be 0 (low) or |
| 78 | * 1 (high), anything else than 0 or 1 will be interpreted as 1 (high) |
| 79 | * @consumer_label: a desired consumer label for the selected GPIO line(s) |
| 80 | * such as "my-bitbanged-relay" |
| 81 | * @lines: number of lines requested in this request, i.e. the number of |
| 82 | * valid fields in the above arrays, set to 1 to request a single line |
| 83 | * @fd: if successful this field will contain a valid anonymous file handle |
| 84 | * after a GPIO_GET_LINEHANDLE_IOCTL operation, zero or negative value |
| 85 | * means error |
| 86 | */ |
| 87 | struct gpiohandle_request { |
| 88 | __u32 lineoffsets[GPIOHANDLES_MAX]; |
| 89 | __u32 flags; |
| 90 | __u8 default_values[GPIOHANDLES_MAX]; |
| 91 | char consumer_label[32]; |
| 92 | __u32 lines; |
| 93 | int fd; |
| 94 | }; |
| 95 | |
Linus Walleij | d7c51b4 | 2016-04-26 10:35:29 +0200 | [diff] [blame] | 96 | /** |
| 97 | * struct gpiohandle_data - Information of values on a GPIO handle |
| 98 | * @values: when getting the state of lines this contains the current |
| 99 | * state of a line, when setting the state of lines these should contain |
| 100 | * the desired target state |
| 101 | */ |
| 102 | struct gpiohandle_data { |
| 103 | __u8 values[GPIOHANDLES_MAX]; |
| 104 | }; |
| 105 | |
| 106 | #define GPIOHANDLE_GET_LINE_VALUES_IOCTL _IOWR(0xB4, 0x08, struct gpiohandle_data) |
| 107 | #define GPIOHANDLE_SET_LINE_VALUES_IOCTL _IOWR(0xB4, 0x09, struct gpiohandle_data) |
Linus Walleij | 3c702e9 | 2015-10-21 15:29:53 +0200 | [diff] [blame] | 108 | |
Linus Walleij | 61f922d | 2016-06-02 11:30:15 +0200 | [diff] [blame] | 109 | /* Eventrequest flags */ |
| 110 | #define GPIOEVENT_REQUEST_RISING_EDGE (1UL << 0) |
| 111 | #define GPIOEVENT_REQUEST_FALLING_EDGE (1UL << 1) |
| 112 | #define GPIOEVENT_REQUEST_BOTH_EDGES ((1UL << 0) | (1UL << 1)) |
| 113 | |
| 114 | /** |
| 115 | * struct gpioevent_request - Information about a GPIO event request |
| 116 | * @lineoffset: the desired line to subscribe to events from, specified by |
| 117 | * offset index for the associated GPIO device |
| 118 | * @handleflags: desired handle flags for the desired GPIO line, such as |
| 119 | * GPIOHANDLE_REQUEST_ACTIVE_LOW or GPIOHANDLE_REQUEST_OPEN_DRAIN |
| 120 | * @eventflags: desired flags for the desired GPIO event line, such as |
| 121 | * GPIOEVENT_REQUEST_RISING_EDGE or GPIOEVENT_REQUEST_FALLING_EDGE |
| 122 | * @consumer_label: a desired consumer label for the selected GPIO line(s) |
| 123 | * such as "my-listener" |
| 124 | * @fd: if successful this field will contain a valid anonymous file handle |
| 125 | * after a GPIO_GET_LINEEVENT_IOCTL operation, zero or negative value |
| 126 | * means error |
| 127 | */ |
| 128 | struct gpioevent_request { |
| 129 | __u32 lineoffset; |
| 130 | __u32 handleflags; |
| 131 | __u32 eventflags; |
| 132 | char consumer_label[32]; |
| 133 | int fd; |
| 134 | }; |
| 135 | |
| 136 | /** |
| 137 | * GPIO event types |
| 138 | */ |
| 139 | #define GPIOEVENT_EVENT_RISING_EDGE 0x01 |
| 140 | #define GPIOEVENT_EVENT_FALLING_EDGE 0x02 |
| 141 | |
| 142 | /** |
| 143 | * struct gpioevent_data - The actual event being pushed to userspace |
| 144 | * @timestamp: best estimate of time of event occurrence, in nanoseconds |
| 145 | * @id: event identifier |
| 146 | */ |
| 147 | struct gpioevent_data { |
| 148 | __u64 timestamp; |
| 149 | __u32 id; |
| 150 | }; |
| 151 | |
| 152 | #define GPIO_GET_CHIPINFO_IOCTL _IOR(0xB4, 0x01, struct gpiochip_info) |
| 153 | #define GPIO_GET_LINEINFO_IOCTL _IOWR(0xB4, 0x02, struct gpioline_info) |
| 154 | #define GPIO_GET_LINEHANDLE_IOCTL _IOWR(0xB4, 0x03, struct gpiohandle_request) |
| 155 | #define GPIO_GET_LINEEVENT_IOCTL _IOWR(0xB4, 0x04, struct gpioevent_request) |
| 156 | |
Linus Walleij | 3c702e9 | 2015-10-21 15:29:53 +0200 | [diff] [blame] | 157 | #endif /* _UAPI_GPIO_H_ */ |