using-gpio.rst 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. =========================
  2. Using GPIO Lines in Linux
  3. =========================
  4. The Linux kernel exists to abstract and present hardware to users. GPIO lines
  5. as such are normally not user facing abstractions. The most obvious, natural
  6. and preferred way to use GPIO lines is to let kernel hardware drivers deal
  7. with them.
  8. For examples of already existing generic drivers that will also be good
  9. examples for any other kernel drivers you want to author, refer to
  10. Documentation/driver-api/gpio/drivers-on-gpio.rst
  11. For any kind of mass produced system you want to support, such as servers,
  12. laptops, phones, tablets, routers, and any consumer or office or business goods
  13. using appropriate kernel drivers is paramount. Submit your code for inclusion
  14. in the upstream Linux kernel when you feel it is mature enough and you will get
  15. help to refine it, see Documentation/process/submitting-patches.rst.
  16. In Linux GPIO lines also have a userspace ABI.
  17. The userspace ABI is intended for one-off deployments. Examples are prototypes,
  18. factory lines, maker community projects, workshop specimen, production tools,
  19. industrial automation, PLC-type use cases, door controllers, in short a piece
  20. of specialized equipment that is not produced by the numbers, requiring
  21. operators to have a deep knowledge of the equipment and knows about the
  22. software-hardware interface to be set up. They should not have a natural fit
  23. to any existing kernel subsystem and not be a good fit for an operating system,
  24. because of not being reusable or abstract enough, or involving a lot of non
  25. computer hardware related policy.
  26. Applications that have a good reason to use the industrial I/O (IIO) subsystem
  27. from userspace will likely be a good fit for using GPIO lines from userspace as
  28. well.
  29. Do not under any circumstances abuse the GPIO userspace ABI to cut corners in
  30. any product development projects. If you use it for prototyping, then do not
  31. productify the prototype: rewrite it using proper kernel drivers. Do not under
  32. any circumstances deploy any uniform products using GPIO from userspace.
  33. The userspace ABI is a character device for each GPIO hardware unit (GPIO chip).
  34. These devices will appear on the system as ``/dev/gpiochip0`` thru
  35. ``/dev/gpiochipN``. Examples of how to directly use the userspace ABI can be
  36. found in the kernel tree ``tools/gpio`` subdirectory.
  37. For structured and managed applications, we recommend that you make use of the
  38. libgpiod_ library. This provides helper abstractions, command line utilities
  39. and arbitration for multiple simultaneous consumers on the same GPIO chip.
  40. .. _libgpiod: https://git.kernel.org/pub/scm/libs/libgpiod/libgpiod.git/