1. 23 Sep, 2016 1 commit
    • Mika Westerberg's avatar
      gpiolib: Make it possible to exclude GPIOs from IRQ domain · 79b804cb
      Mika Westerberg authored
      When using GPIO irqchip helpers to setup irqchip for a gpiolib based
      driver, it is not possible to select which GPIOs to add to the IRQ domain.
      Instead it just adds all GPIOs which is not always desired. For example
      there might be GPIOs that for some reason cannot generated normal
      interrupts at all.
      To support this we add a flag irq_need_valid_mask to struct gpio_chip. When
      this flag is set the core allocates irq_valid_mask that holds one bit for
      each GPIO the chip has. By default all bits are set but drivers can
      manipulate this using set_bit() and clear_bit() accordingly.
      Then when gpiochip_irqchip_add() is called, this mask is checked and all
      GPIOs with bit is set are added to the IRQ domain created for the GPIO
      Suggested-by: Linus Walleij's avatarLinus Walleij <linus.walleij@linaro.org>
      Signed-off-by: Mika Westerberg's avatarMika Westerberg <mika.westerberg@linux.intel.com>
      Signed-off-by: Linus Walleij's avatarLinus Walleij <linus.walleij@linaro.org>
  2. 22 Jul, 2016 1 commit
  3. 06 Jul, 2016 3 commits
    • Linus Walleij's avatar
      Revert "gpio: convince line to become input in irq helper" · 78456d6f
      Linus Walleij authored
      This reverts commit 7e7c059c.
      I was wrong about trying to do this, as it breaks the
      orthogonality between gpiochips and irqchips.
      Signed-off-by: Linus Walleij's avatarLinus Walleij <linus.walleij@linaro.org>
    • Lars-Peter Clausen's avatar
      gpiolib: of_find_gpio(): Don't discard errors · da17f8a1
      Lars-Peter Clausen authored
      Since commit dd34c37a ("gpio: of: Allow -gpio suffix for property
      names") when requesting a GPIO from the devicetree gpiolib looks for
      properties with both the '-gpio' and the '-gpios' suffix. This was
      implemented by first searching for the property with the '-gpios' suffix
      and if that yields an error try the '-gpio' suffix. This approach has the
      issue that any error returned when looking for the '-gpios' suffix is
      silently discarded.
      Commit 06fc3b70 ("gpio: of: Fix handling for deferred probe for -gpio
      suffix") partially addressed the issue by treating the EPROBE_DEFER error
      as a special condition. This fixed the case when the property is specified,
      but the GPIO provider is not ready yet. But there are other cases in which
      of_get_named_gpiod_flags() returns an error even though the property is
      specified, e.g. if the specification is incorrect.
      of_find_gpio() should only try to look for the property with the '-gpio'
      suffix if no property with the '-gpios' suffix was found. If the property
      was not found of_get_named_gpiod_flags() will return -ENOENT, so update the
      condition to abort and propagate the error to the caller in all other
      This is important for gpiod_get_optinal() and friends to behave correctly
      in case the specifier contains errors. Without this patch they'll return
      NULL if the property uses the '-gpios' suffix and the specifier contains
      errors, which falsely indicates to the caller that no GPIO was specified.
      Signed-off-by: default avatarLars-Peter Clausen <lars@metafoo.de>
      Signed-off-by: Linus Walleij's avatarLinus Walleij <linus.walleij@linaro.org>
    • Thierry Reding's avatar
      gpio: of: Allow overriding the device node · acc6e331
      Thierry Reding authored
      When registering a GPIO chip, drivers can override the device tree node
      associated with the chip by setting the chip's ->of_node field. If set,
      this field is supposed to take precedence over the ->parent->of_node
      field, but the code doesn't actually do that.
      Commit 762c2e46 ("gpio: of: remove of_gpiochip_and_xlate() and
      struct gg_data") exposes this because it now no longer matches on the
      GPIO chip's ->of_node field, but the GPIO device's ->of_node field that
      is set using the procedure described above.
      Signed-off-by: default avatarThierry Reding <treding@nvidia.com>
      Acked-by: default avatarAlexandre Courbot <acourbot@nvidia.com>
      Reviewed-by: default avatarMasahiro Yamada <yamada.masahiro@socionext.com>
      Signed-off-by: Linus Walleij's avatarLinus Walleij <linus.walleij@linaro.org>
  4. 04 Jul, 2016 2 commits
    • Linus Walleij's avatar
      gpio: free handles in fringe cases · d932cd49
      Linus Walleij authored
      If we fail when copying the ioctl() struct to userspace we still
      need to clean up the cruft otherwise left behind or it will stay
      around until the issuing process terminates the file handle.
      Reported-by: default avatarAlexander Stein <alexander.stein@systec-electronic.com>
      Acked-by: default avatarAlexander Stein <alexander.stein@systec-electronic.com>
      Signed-off-by: Linus Walleij's avatarLinus Walleij <linus.walleij@linaro.org>
    • Johan Hovold's avatar
      Revert "gpiolib: Split GPIO flags parsing and GPIO configuration" · 85b03b30
      Johan Hovold authored
      This reverts commit 923b93e4.
      Make sure consumers do not overwrite gpio flags for pins that have
      already been claimed.
      While adding support for gpio drivers to refuse a request using
      unsupported flags, the order of when the requested flag was checked and
      the new flags were applied was reversed to that consumers could
      overwrite flags for already requested gpios.
      This not only affects device-tree setups where two drivers could request
      the same gpio using conflicting configurations, but also allowed user
      space to clear gpio flags for already claimed pins simply by attempting
      to export them through the sysfs interface. By for example clearing the
      FLAG_ACTIVE_LOW flag this way, user space could effectively change the
      polarity of a signal.
      Reverting this change obviously prevents gpio drivers from doing sanity
      checks on the flags in their request callbacks. Fortunately only one
      recently added driver (gpio-tps65218 in v4.6) appears to do this, and a
      follow up patch could restore this functionality through a different
      Cc: stable <stable@vger.kernel.org>	# 4.4
      Signed-off-by: default avatarJohan Hovold <johan@kernel.org>
      Signed-off-by: Linus Walleij's avatarLinus Walleij <linus.walleij@linaro.org>
  5. 23 Jun, 2016 1 commit
  6. 22 Jun, 2016 2 commits
  7. 18 Jun, 2016 2 commits
  8. 17 Jun, 2016 2 commits
  9. 16 Jun, 2016 1 commit
    • Arnd Bergmann's avatar
      gpiolib: avoid uninitialized data in gpio kfifo · bc0207a5
      Arnd Bergmann authored
      gcc reports a theoretical case for returning uninitialized data in
      the kfifo when a GPIO interrupt happens and neither
      are set:
      drivers/gpio/gpiolib.c: In function 'lineevent_irq_thread':
      drivers/gpio/gpiolib.c:683:87: error: 'ge.id' may be used uninitialized in this function [-Werror=maybe-uninitialized]
      This case should not happen, but to be on the safe side, let's
      return from the irq handler without adding data to the FIFO
      to ensure we can never leak stack data to user space.
      Signed-off-by: default avatarArnd Bergmann <arnd@arndb.de>
      Fixes: 61f922db ("gpio: userspace ABI for reading GPIO line events")
      Signed-off-by: Linus Walleij's avatarLinus Walleij <linus.walleij@linaro.org>
  10. 15 Jun, 2016 2 commits
    • Linus Walleij's avatar
      gpio: userspace ABI for reading GPIO line events · 61f922db
      Linus Walleij authored
      This adds an ABI for listening to events on GPIO lines.
      The mechanism returns an anonymous file handle to a request
      to listen to a specific offset on a specific gpiochip.
      To fetch the stream of events from the file handle, userspace
      simply reads an event.
      - Events can be requested with the same flags as ordinary
        handles, i.e. open drain or open source. An ioctl() call
        GPIO_GET_LINEEVENT_IOCTL is issued indicating the desired
      - Events can be requested for falling edge events, rising
        edge events, or both.
      - All events are timestamped using the kernel real time
        nanosecond timestamp (the same as is used by IIO).
      - The supplied consumer label will appear in "lsgpio"
        listings of the lines, and in /proc/interrupts as the
        mechanism will request an interrupt from the gpio chip.
      - Events are not supported on gpiochips that do not serve
        interrupts (no legal .to_irq() call). The event interrupt
        is threaded to avoid any realtime problems.
      - It is possible to also directly read the current value
        of the registered GPIO line by issuing the same
        line handles. Setting the value is not supported: we
        do not listen to events on output lines.
      This ABI is strongly influenced by Industrial I/O and surpasses
      the old sysfs ABI by providing proper precision timestamps,
      making it possible to set flags like open drain, and put
      consumer names on the GPIO lines.
      Signed-off-by: Linus Walleij's avatarLinus Walleij <linus.walleij@linaro.org>
    • 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>
  11. 08 Jun, 2016 2 commits
    • Ricardo Ribalda Delgado's avatar
      gpiolib: Fix unaligned used of reference counters · f4833b8c
      Ricardo Ribalda Delgado authored
      gpiolib relies on the reference counters to clean up the gpio_device
      Although the number of get/put is properly aligned on gpiolib.c
      itself, it does not take into consideration how the referece counters
      are affected by other external functions such as cdev_add and device_add.
      Because of this, after the last call to put_device, the reference counter
      has a value of +3, therefore never calling gpiodevice_release.
      Due to the fact that some of the device  has already been cleaned on
      gpiochip_remove, the library will end up OOPsing the kernel (e.g. a call
      to of_gpiochip_find_and_xlate).
      Cc: stable@vger.kernel.org
      Signed-off-by: Ricardo Ribalda Delgado's avatarRicardo Ribalda Delgado <ricardo.ribalda@gmail.com>
      Signed-off-by: Linus Walleij's avatarLinus Walleij <linus.walleij@linaro.org>
    • Ricardo Ribalda Delgado's avatar
      gpiolib: Fix NULL pointer deference · 11f33a6d
      Ricardo Ribalda Delgado authored
      Under some circumstances, a gpiochip might be half cleaned from the
      gpio_device list.
      This patch makes sure that the chip pointer is still valid, before
      calling the match function.
      [  104.088296] BUG: unable to handle kernel NULL pointer dereference at
      [  104.089772] IP: [<ffffffff813d2045>] of_gpiochip_find_and_xlate+0x15/0x80
      [  104.128273] Call Trace:
      [  104.129802]  [<ffffffff813d2030>] ? of_parse_own_gpio+0x1f0/0x1f0
      [  104.131353]  [<ffffffff813cd910>] gpiochip_find+0x60/0x90
      [  104.132868]  [<ffffffff813d21ba>] of_get_named_gpiod_flags+0x9a/0x120
      [  104.141586]  [<ffffffff8163d12b>] gpio_led_probe+0x11b/0x360
      Cc: stable@vger.kernel.org
      Signed-off-by: Ricardo Ribalda Delgado's avatarRicardo Ribalda Delgado <ricardo.ribalda@gmail.com>
      Signed-off-by: Linus Walleij's avatarLinus Walleij <linus.walleij@linaro.org>
  12. 30 May, 2016 4 commits
  13. 02 May, 2016 1 commit
  14. 30 Apr, 2016 1 commit
  15. 26 Apr, 2016 1 commit
  16. 14 Apr, 2016 1 commit
  17. 08 Apr, 2016 3 commits
    • Guenter Roeck's avatar
      gpiolib: Defer gpio device setup until after gpiolib initialization · 159f3cd9
      Guenter Roeck authored
      Since commit ff2b1359 ("gpio: make the gpiochip a real device"),
      attempts to add a gpio chip prior to gpiolib initialization cause
      the system to crash. This happens because gpio_bus_type has not been
      registered yet. Defer creating gpio devices until after gpiolib has
      been initialized to fix the problem.
      Cc: Greg Ungerer <gerg@uclinux.org>
      Cc: Alexandre Courbot <gnurou@gmail.com>
      Fixes: ff2b1359 ("gpio: make the gpiochip a real device")
      Signed-off-by: default avatarGuenter Roeck <linux@roeck-us.net>
      Signed-off-by: Linus Walleij's avatarLinus Walleij <linus.walleij@linaro.org>
    • Guenter Roeck's avatar
      gpiolib: Do not use devm functions when registering gpio chip · 476e2fc5
      Guenter Roeck authored
      It is possible that a gpio chip is registered before the gpiolib
      initialization code has run. This means we can not use devm_ functions
      to allocate memory at that time. Do it the old fashioned way.
      Cc: Alexandre Courbot <gnurou@gmail.com>
      Cc: Greg Ungerer <gerg@uclinux.org>
      Signed-off-by: default avatarGuenter Roeck <linux@roeck-us.net>
      Signed-off-by: Linus Walleij's avatarLinus Walleij <linus.walleij@linaro.org>
    • Dmitry Torokhov's avatar
      gpio / ACPI: ignore GpioInt() GPIOs when requesting GPIO_OUT_* · 25487533
      Dmitry Torokhov authored
      When firmware does not use _DSD properties that allow properly name GPIO
      resources, the kernel falls back on parsing _CRS resources, and will
      return entries described as GpioInt() as general purpose GPIOs even
      though they are meant to be used simply as interrupt sources for the
      Device (ETSA)
      	Name (_HID, "ELAN0001")
      	Method(_CRS, 0x0, NotSerialized)
      		Name(BUF0,ResourceTemplate ()
      				0x10,                     /* SlaveAddress */
      				ControllerInitiated,      /* SlaveMode */
      				400000,                   /* ConnectionSpeed */
      				AddressingMode7Bit,       /* AddressingMode */
      				"\\_SB.I2C1",             /* ResourceSource */
      			GpioInt (Edge, ActiveLow, ExclusiveAndWake, PullNone,,
      				 "\\_SB.GPSW") { BOARD_TOUCH_GPIO_INDEX }
      		} )
      		Return (BUF0)
      This gives troubles with drivers such as Elan Touchscreen driver
      (elants_i2c) that uses devm_gpiod_get to look up "reset" GPIO line and
      decide whether the driver is responsible for powering up and resetting
      the device, or firmware is. In the above case the lookup succeeds, we
      map GPIO as output and later fail to request client->irq interrupt that
      is mapped to the same GPIO.
      Let's ignore resources described as GpioInt() while parsing _CRS when
      requesting output GPIOs (but allow them when requesting GPIOD_ASIS or
      GPIOD_IN as some drivers, such as i2c-hid, do request GPIO as input and
      then map it to interrupt with gpiod_to_irq).
      Acked-by: Mika Westerberg's avatarMika Westerberg <mika.westerberg@linux.intel.com>
      Signed-off-by: default avatarDmitry Torokhov <dtor@chromium.org>
      Signed-off-by: Linus Walleij's avatarLinus Walleij <linus.walleij@linaro.org>
  18. 05 Apr, 2016 1 commit
    • Linus Walleij's avatar
      gpio: support native single-ended hardware drivers · c663e5f5
      Linus Walleij authored
      Some GPIO controllers has a special hardware bit we can flip
      to support open drain / source. This means that on these hardwares
      we do not need to emulate OD/OS by setting the line to input
      instead of actively driving it high/low. Add an optional vtable
      callback to the driver set_single_ended() so that driver can
      implement this in hardware if they have it.
      We may need a pinctrl_gpio_set_config() call at some point to
      propagate this down to a backing pin control device on systems
      with split GPIO/pin control.
      Reported-by: default avatarMichael Hennerich <michael.hennerich@analog.com>
      Signed-off-by: Linus Walleij's avatarLinus Walleij <linus.walleij@linaro.org>
  19. 16 Mar, 2016 1 commit
  20. 07 Mar, 2016 1 commit
  21. 25 Feb, 2016 1 commit
  22. 23 Feb, 2016 1 commit
  23. 22 Feb, 2016 1 commit
  24. 20 Feb, 2016 1 commit
    • Bamvor Jian Zhang's avatar
      gpiolib: fix crash when gpiochip removed · bd203bd5
      Bamvor Jian Zhang authored
      Commit cb464a88e1ed ("gpio: make the gpiochip a real device") call
      gpiochip_sysfs_unregister after the gpiochip is empty. It lead to the
      following crash:
      [  163.503994] Unable to handle kernel NULL pointer dereference at virtual address 0000007c
      [  163.525394] [<ffffffc0003719a0>] gpiochip_sysfs_unregister+0x44/0xa4
      [  163.525611] [<ffffffc00036f6a0>] gpiochip_remove+0x24/0x154
      [  163.525861] [<ffffffbffc00f0a4>] mockup_gpio_remove+0x38/0x64 [gpio_mockup]
      [  163.526101] [<ffffffc00042b4b4>] platform_drv_remove+0x24/0x64
      [  163.526313] [<ffffffc000429cc8>] __device_release_driver+0x7c/0xfc
      [  163.526525] [<ffffffc000429e54>] driver_detach+0xbc/0xc0
      [  163.526700] [<ffffffc000429014>] bus_remove_driver+0x58/0xac
      [  163.526883] [<ffffffc00042a4cc>] driver_unregister+0x2c/0x4c
      [  163.527067] [<ffffffc00042b5c0>] platform_driver_unregister+0x10/0x18
      [  163.527284] [<ffffffbffc00f340>] mock_device_exit+0x10/0x38 [gpio_mockup]
      [  163.527593] [<ffffffc00011cefc>] SyS_delete_module+0x1b8/0x1fc
      [  163.527799] [<ffffffc000085d8c>] __sys_trace_return+0x0/0x4
      [  163.528049] Code: 940d74b4 f9019abf aa1303e0 940d7439 (7940fac0)
      [  163.536273] ---[ end trace 3d1329be504af609 ]---
      This patch fix this by changing the code back.
      Signed-off-by: default avatarBamvor Jian Zhang <bamvor.zhangjian@linaro.org>
      Signed-off-by: Linus Walleij's avatarLinus Walleij <linus.walleij@linaro.org>
  25. 19 Feb, 2016 2 commits
    • Linus Walleij's avatar
      gpio: add userspace ABI for GPIO line information · 521a2ad6
      Linus Walleij authored
      This adds a GPIO line ABI for getting name, label and a few select
      flags from the kernel.
      This hides the kernel internals and only tells userspace what it
      may need to know: the different in-kernel consumers are masked
      behind the flag "kernel" and that is all userspace needs to know.
      However electric characteristics like active low, open drain etc
      are reflected to userspace, as this is important information.
      We provide information on all lines on all chips, later on we will
      likely add a flag for the chardev consumer so we can filter and
      display only the lines userspace actually uses in e.g. lsgpio,
      but then we first need an ABI for userspace to grab and use
      (get/set/select direction) a GPIO line.
      Sample output from "lsgpio" on ux500:
      GPIO chip: gpiochip7, "8011e000.gpio", 32 GPIO lines
              line 0: unnamed unlabeled
              line 1: unnamed unlabeled
              line 25: unnamed "SFH7741 Proximity Sensor" [kernel output open-drain]
              line 26: unnamed unlabeled
      Tested-by: default avatarMichael Welling <mwelling@ieee.org>
      Signed-off-by: Linus Walleij's avatarLinus Walleij <linus.walleij@linaro.org>
    • Linus Walleij's avatar
      gpio: store reflect the label to userspace · df4878e9
      Linus Walleij authored
      The gpio_chip label is useful for userspace to understand what
      kind of GPIO chip it is dealing with. Let's store a copy of this
      label in the gpio_device, add it to the struct passed to userspace
      for GPIO_GET_CHIPINFO_IOCTL and modify lsgpio to show it.
      Signed-off-by: Linus Walleij's avatarLinus Walleij <linus.walleij@linaro.org>
  26. 18 Feb, 2016 1 commit