• Linus Walleij's avatar
    gpio: userspace ABI for reading/writing GPIO lines · d7c51b47
    Linus Walleij authored
    This adds a userspace ABI for reading and writing GPIO lines.
    The mechanism returns an anonymous file handle to a request
    to read/write n offsets from a gpiochip. This file handle
    in turn accepts two ioctl()s: one that reads and one that
    writes values to the selected lines.
    - Handles can be requested as input/output, active low,
      open drain, open source, however when you issue a request
      for n lines with GPIO_GET_LINEHANDLE_IOCTL, they must all
      have the same flags, i.e. all inputs or all outputs, all
      open drain etc. If a granular control of the flags for
      each line is desired, they need to be requested
      individually, not in a batch.
    - The GPIOHANDLE_GET_LINE_VALUES_IOCTL read ioctl() can be
      issued also to output lines to verify that the hardware
      is in the expected state.
    - It reads and writes up to GPIOHANDLES_MAX lines at once,
      utilizing the .set_multiple() call in the driver if
      possible, making the call efficient if several lines
      can be written with a single register update.
    The limitation of GPIOHANDLES_MAX to 64 lines is done under
    the assumption that we may expect hardware that can issue a
    transaction updating 64 bits at an instant but unlikely
    anything larger than that.
    ChangeLog v2->v3:
    - Use gpiod_get_value_cansleep() so we support also slowpath
      GPIO drivers.
    - Fix up the UAPI docs kerneldoc.
    - Allocate the anonymous fd last, so that the release
      function don't get called until that point of something
      fails. After this point, skip the errorpath.
    ChangeLog v1->v2:
    - Handle ioctl_compat() properly based on a similar patch
      to the other ioctl() handling code.
    - Use _IOWR() as we pass pointers both in and out of the
    - Use kmalloc() and kfree() for the linehandled, do not
      try to be fancy with devm_* it doesn't work the way I
    - Fix const-correctness on the linehandle name field.
    Acked-by: default avatarMichael Welling <mwelling@ieee.org>
    Signed-off-by: Linus Walleij's avatarLinus Walleij <linus.walleij@linaro.org>
gpio.h 4.13 KB