chardev.rst 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. .. SPDX-License-Identifier: GPL-2.0
  2. ===================================
  3. GPIO Character Device Userspace API
  4. ===================================
  5. This is latest version (v2) of the character device API, as defined in
  6. ``include/uapi/linux/gpio.h.``
  7. First added in 5.10.
  8. .. note::
  9. Do NOT abuse userspace APIs to control hardware that has proper kernel
  10. drivers. There may already be a driver for your use case, and an existing
  11. kernel driver is sure to provide a superior solution to bitbashing
  12. from userspace.
  13. Read Documentation/driver-api/gpio/drivers-on-gpio.rst to avoid reinventing
  14. kernel wheels in userspace.
  15. Similarly, for multi-function lines there may be other subsystems, such as
  16. Documentation/spi/index.rst, Documentation/i2c/index.rst,
  17. Documentation/driver-api/pwm.rst, Documentation/w1/index.rst etc, that
  18. provide suitable drivers and APIs for your hardware.
  19. Basic examples using the character device API can be found in ``tools/gpio/*``.
  20. The API is based around two major objects, the :ref:`gpio-v2-chip` and the
  21. :ref:`gpio-v2-line-request`.
  22. .. _gpio-v2-chip:
  23. Chip
  24. ====
  25. The Chip represents a single GPIO chip and is exposed to userspace using device
  26. files of the form ``/dev/gpiochipX``.
  27. Each chip supports a number of GPIO lines,
  28. :c:type:`chip.lines<gpiochip_info>`. Lines on the chip are identified by an
  29. ``offset`` in the range from 0 to ``chip.lines - 1``, i.e. `[0,chip.lines)`.
  30. Lines are requested from the chip using gpio-v2-get-line-ioctl.rst
  31. and the resulting line request is used to access the GPIO chip's lines or
  32. monitor the lines for edge events.
  33. Within this documentation, the file descriptor returned by calling `open()`
  34. on the GPIO device file is referred to as ``chip_fd``.
  35. Operations
  36. ----------
  37. The following operations may be performed on the chip:
  38. .. toctree::
  39. :titlesonly:
  40. Get Line <gpio-v2-get-line-ioctl>
  41. Get Chip Info <gpio-get-chipinfo-ioctl>
  42. Get Line Info <gpio-v2-get-lineinfo-ioctl>
  43. Watch Line Info <gpio-v2-get-lineinfo-watch-ioctl>
  44. Unwatch Line Info <gpio-get-lineinfo-unwatch-ioctl>
  45. Read Line Info Changed Events <gpio-v2-lineinfo-changed-read>
  46. .. _gpio-v2-line-request:
  47. Line Request
  48. ============
  49. Line requests are created by gpio-v2-get-line-ioctl.rst and provide
  50. access to a set of requested lines. The line request is exposed to userspace
  51. via the anonymous file descriptor returned in
  52. :c:type:`request.fd<gpio_v2_line_request>` by gpio-v2-get-line-ioctl.rst.
  53. Within this documentation, the line request file descriptor is referred to
  54. as ``req_fd``.
  55. Operations
  56. ----------
  57. The following operations may be performed on the line request:
  58. .. toctree::
  59. :titlesonly:
  60. Get Line Values <gpio-v2-line-get-values-ioctl>
  61. Set Line Values <gpio-v2-line-set-values-ioctl>
  62. Read Line Edge Events <gpio-v2-line-event-read>
  63. Reconfigure Lines <gpio-v2-line-set-config-ioctl>
  64. Types
  65. =====
  66. This section contains the structs and enums that are referenced by the API v2,
  67. as defined in ``include/uapi/linux/gpio.h``.
  68. .. kernel-doc:: include/uapi/linux/gpio.h
  69. :identifiers:
  70. gpio_v2_line_attr_id
  71. gpio_v2_line_attribute
  72. gpio_v2_line_changed_type
  73. gpio_v2_line_config
  74. gpio_v2_line_config_attribute
  75. gpio_v2_line_event
  76. gpio_v2_line_event_id
  77. gpio_v2_line_flag
  78. gpio_v2_line_info
  79. gpio_v2_line_info_changed
  80. gpio_v2_line_request
  81. gpio_v2_line_values
  82. gpiochip_info
  83. .. toctree::
  84. :hidden:
  85. error-codes