gpio-aggregator.rst 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. .. SPDX-License-Identifier: GPL-2.0-only
  2. GPIO Aggregator
  3. ===============
  4. The GPIO Aggregator provides a mechanism to aggregate GPIOs, and expose them as
  5. a new gpio_chip. This supports the following use cases.
  6. Aggregating GPIOs using Sysfs
  7. -----------------------------
  8. GPIO controllers are exported to userspace using /dev/gpiochip* character
  9. devices. Access control to these devices is provided by standard UNIX file
  10. system permissions, on an all-or-nothing basis: either a GPIO controller is
  11. accessible for a user, or it is not.
  12. The GPIO Aggregator provides access control for a set of one or more GPIOs, by
  13. aggregating them into a new gpio_chip, which can be assigned to a group or user
  14. using standard UNIX file ownership and permissions. Furthermore, this
  15. simplifies and hardens exporting GPIOs to a virtual machine, as the VM can just
  16. grab the full GPIO controller, and no longer needs to care about which GPIOs to
  17. grab and which not, reducing the attack surface.
  18. Aggregated GPIO controllers are instantiated and destroyed by writing to
  19. write-only attribute files in sysfs.
  20. /sys/bus/platform/drivers/gpio-aggregator/
  21. "new_device" ...
  22. Userspace may ask the kernel to instantiate an aggregated GPIO
  23. controller by writing a string describing the GPIOs to
  24. aggregate to the "new_device" file, using the format
  25. .. code-block:: none
  26. [<gpioA>] [<gpiochipB> <offsets>] ...
  27. Where:
  28. "<gpioA>" ...
  29. is a GPIO line name,
  30. "<gpiochipB>" ...
  31. is a GPIO chip label, and
  32. "<offsets>" ...
  33. is a comma-separated list of GPIO offsets and/or
  34. GPIO offset ranges denoted by dashes.
  35. Example: Instantiate a new GPIO aggregator by aggregating GPIO
  36. line 19 of "e6052000.gpio" and GPIO lines 20-21 of
  37. "e6050000.gpio" into a new gpio_chip:
  38. .. code-block:: sh
  39. $ echo 'e6052000.gpio 19 e6050000.gpio 20-21' > new_device
  40. "delete_device" ...
  41. Userspace may ask the kernel to destroy an aggregated GPIO
  42. controller after use by writing its device name to the
  43. "delete_device" file.
  44. Example: Destroy the previously-created aggregated GPIO
  45. controller, assumed to be "gpio-aggregator.0":
  46. .. code-block:: sh
  47. $ echo gpio-aggregator.0 > delete_device
  48. Generic GPIO Driver
  49. -------------------
  50. The GPIO Aggregator can also be used as a generic driver for a simple
  51. GPIO-operated device described in DT, without a dedicated in-kernel driver.
  52. This is useful in industrial control, and is not unlike e.g. spidev, which
  53. allows the user to communicate with an SPI device from userspace.
  54. Binding a device to the GPIO Aggregator is performed either by modifying the
  55. gpio-aggregator driver, or by writing to the "driver_override" file in Sysfs.
  56. Example: If "door" is a GPIO-operated device described in DT, using its own
  57. compatible value::
  58. door {
  59. compatible = "myvendor,mydoor";
  60. gpios = <&gpio2 19 GPIO_ACTIVE_HIGH>,
  61. <&gpio2 20 GPIO_ACTIVE_LOW>;
  62. gpio-line-names = "open", "lock";
  63. };
  64. it can be bound to the GPIO Aggregator by either:
  65. 1. Adding its compatible value to ``gpio_aggregator_dt_ids[]``,
  66. 2. Binding manually using "driver_override":
  67. .. code-block:: sh
  68. $ echo gpio-aggregator > /sys/bus/platform/devices/door/driver_override
  69. $ echo door > /sys/bus/platform/drivers/gpio-aggregator/bind
  70. After that, a new gpiochip "door" has been created:
  71. .. code-block:: sh
  72. $ gpioinfo door
  73. gpiochip12 - 2 lines:
  74. line 0: "open" unused input active-high
  75. line 1: "lock" unused input active-high