gpio.h 5.6 KB

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