gpio.h 5.6 KB

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