gpio-v2-get-line-ioctl.rst 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. .. SPDX-License-Identifier: GPL-2.0
  2. .. _GPIO_V2_GET_LINE_IOCTL:
  3. **********************
  4. GPIO_V2_GET_LINE_IOCTL
  5. **********************
  6. Name
  7. ====
  8. GPIO_V2_GET_LINE_IOCTL - Request a line or lines from the kernel.
  9. Synopsis
  10. ========
  11. .. c:macro:: GPIO_V2_GET_LINE_IOCTL
  12. ``int ioctl(int chip_fd, GPIO_V2_GET_LINE_IOCTL, struct gpio_v2_line_request *request)``
  13. Arguments
  14. =========
  15. ``chip_fd``
  16. The file descriptor of the GPIO character device returned by `open()`.
  17. ``request``
  18. The :c:type:`line_request<gpio_v2_line_request>` specifying the lines
  19. to request and their configuration.
  20. Description
  21. ===========
  22. On success, the requesting process is granted exclusive access to the line
  23. value, write access to the line configuration, and may receive events when
  24. edges are detected on the line, all of which are described in more detail in
  25. :ref:`gpio-v2-line-request`.
  26. A number of lines may be requested in the one line request, and request
  27. operations are performed on the requested lines by the kernel as atomically
  28. as possible. e.g. gpio-v2-line-get-values-ioctl.rst will read all the
  29. requested lines at once.
  30. The state of a line, including the value of output lines, is guaranteed to
  31. remain as requested until the returned file descriptor is closed. Once the
  32. file descriptor is closed, the state of the line becomes uncontrolled from
  33. the userspace perspective, and may revert to its default state.
  34. Requesting a line already in use is an error (**EBUSY**).
  35. Closing the ``chip_fd`` has no effect on existing line requests.
  36. .. _gpio-v2-get-line-config-rules:
  37. Configuration Rules
  38. -------------------
  39. For any given requested line, the following configuration rules apply:
  40. The direction flags, ``GPIO_V2_LINE_FLAG_INPUT`` and
  41. ``GPIO_V2_LINE_FLAG_OUTPUT``, cannot be combined. If neither are set then
  42. the only other flag that may be set is ``GPIO_V2_LINE_FLAG_ACTIVE_LOW``
  43. and the line is requested "as-is" to allow reading of the line value
  44. without altering the electrical configuration.
  45. The drive flags, ``GPIO_V2_LINE_FLAG_OPEN_xxx``, require the
  46. ``GPIO_V2_LINE_FLAG_OUTPUT`` to be set.
  47. Only one drive flag may be set.
  48. If none are set then the line is assumed push-pull.
  49. Only one bias flag, ``GPIO_V2_LINE_FLAG_BIAS_xxx``, may be set, and it
  50. requires a direction flag to also be set.
  51. If no bias flags are set then the bias configuration is not changed.
  52. The edge flags, ``GPIO_V2_LINE_FLAG_EDGE_xxx``, require
  53. ``GPIO_V2_LINE_FLAG_INPUT`` to be set and may be combined to detect both rising
  54. and falling edges. Requesting edge detection from a line that does not support
  55. it is an error (**ENXIO**).
  56. Only one event clock flag, ``GPIO_V2_LINE_FLAG_EVENT_CLOCK_xxx``, may be set.
  57. If none are set then the event clock defaults to ``CLOCK_MONOTONIC``.
  58. The ``GPIO_V2_LINE_FLAG_EVENT_CLOCK_HTE`` flag requires supporting hardware
  59. and a kernel with ``CONFIG_HTE`` set. Requesting HTE from a device that
  60. doesn't support it is an error (**EOPNOTSUPP**).
  61. The :c:type:`debounce_period_us<gpio_v2_line_attribute>` attribute may only
  62. be applied to lines with ``GPIO_V2_LINE_FLAG_INPUT`` set. When set, debounce
  63. applies to both the values returned by gpio-v2-line-get-values-ioctl.rst and
  64. the edges returned by gpio-v2-line-event-read.rst. If not
  65. supported directly by hardware, debouncing is emulated in software by the
  66. kernel. Requesting debounce on a line that supports neither debounce in
  67. hardware nor interrupts, as required for software emulation, is an error
  68. (**ENXIO**).
  69. Requesting an invalid configuration is an error (**EINVAL**).
  70. .. _gpio-v2-get-line-config-support:
  71. Configuration Support
  72. ---------------------
  73. Where the requested configuration is not directly supported by the underlying
  74. hardware and driver, the kernel applies one of these approaches:
  75. - reject the request
  76. - emulate the feature in software
  77. - treat the feature as best effort
  78. The approach applied depends on whether the feature can reasonably be emulated
  79. in software, and the impact on the hardware and userspace if the feature is not
  80. supported.
  81. The approach applied for each feature is as follows:
  82. ============== ===========
  83. Feature Approach
  84. ============== ===========
  85. Bias best effort
  86. Debounce emulate
  87. Direction reject
  88. Drive emulate
  89. Edge Detection reject
  90. ============== ===========
  91. Bias is treated as best effort to allow userspace to apply the same
  92. configuration for platforms that support internal bias as those that require
  93. external bias.
  94. Worst case the line floats rather than being biased as expected.
  95. Debounce is emulated by applying a filter to hardware interrupts on the line.
  96. An edge event is generated after an edge is detected and the line remains
  97. stable for the debounce period.
  98. The event timestamp corresponds to the end of the debounce period.
  99. Drive is emulated by switching the line to an input when the line should not
  100. be actively driven.
  101. Edge detection requires interrupt support, and is rejected if that is not
  102. supported. Emulation by polling can still be performed from userspace.
  103. In all cases, the configuration reported by gpio-v2-get-lineinfo-ioctl.rst
  104. is the requested configuration, not the resulting hardware configuration.
  105. Userspace cannot determine if a feature is supported in hardware, is
  106. emulated, or is best effort.
  107. Return Value
  108. ============
  109. On success 0 and the :c:type:`request.fd<gpio_v2_line_request>` contains the
  110. file descriptor for the request.
  111. On error -1 and the ``errno`` variable is set appropriately.
  112. Common error codes are described in error-codes.rst.