1. 06 7月, 2016 3 次提交
    • L
      Revert "gpio: convince line to become input in irq helper" · 78456d6f
      Linus Walleij 提交于
      This reverts commit 7e7c059c.
      
      I was wrong about trying to do this, as it breaks the
      orthogonality between gpiochips and irqchips.
      Signed-off-by: NLinus Walleij <linus.walleij@linaro.org>
      78456d6f
    • L
      gpiolib: of_find_gpio(): Don't discard errors · da17f8a1
      Lars-Peter Clausen 提交于
      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
      cases.
      
      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: NLars-Peter Clausen <lars@metafoo.de>
      Signed-off-by: NLinus Walleij <linus.walleij@linaro.org>
      da17f8a1
    • T
      gpio: of: Allow overriding the device node · acc6e331
      Thierry Reding 提交于
      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: NThierry Reding <treding@nvidia.com>
      Acked-by: NAlexandre Courbot <acourbot@nvidia.com>
      Reviewed-by: NMasahiro Yamada <yamada.masahiro@socionext.com>
      Signed-off-by: NLinus Walleij <linus.walleij@linaro.org>
      acc6e331
  2. 04 7月, 2016 1 次提交
  3. 23 6月, 2016 1 次提交
  4. 18 6月, 2016 2 次提交
  5. 16 6月, 2016 1 次提交
    • A
      gpiolib: avoid uninitialized data in gpio kfifo · bc0207a5
      Arnd Bergmann 提交于
      gcc reports a theoretical case for returning uninitialized data in
      the kfifo when a GPIO interrupt happens and neither
      GPIOEVENT_REQUEST_RISING_EDGE nor GPIOEVENT_REQUEST_FALLING_EDGE
      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: NArnd Bergmann <arnd@arndb.de>
      Fixes: 61f922db ("gpio: userspace ABI for reading GPIO line events")
      Signed-off-by: NLinus Walleij <linus.walleij@linaro.org>
      bc0207a5
  6. 15 6月, 2016 2 次提交
    • L
      gpio: userspace ABI for reading GPIO line events · 61f922db
      Linus Walleij 提交于
      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
        line.
      
      - 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
        GPIOHANDLE_GET_LINE_VALUES_IOCTL as used by the
        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: NLinus Walleij <linus.walleij@linaro.org>
      61f922db
    • L
      gpio: userspace ABI for reading/writing GPIO lines · d7c51b47
      Linus Walleij 提交于
      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
        ioctl()
      - Use kmalloc() and kfree() for the linehandled, do not
        try to be fancy with devm_* it doesn't work the way I
        thought.
      - Fix const-correctness on the linehandle name field.
      Acked-by: NMichael Welling <mwelling@ieee.org>
      Signed-off-by: NLinus Walleij <linus.walleij@linaro.org>
      d7c51b47
  7. 30 5月, 2016 4 次提交
  8. 02 5月, 2016 1 次提交
  9. 30 4月, 2016 1 次提交
  10. 26 4月, 2016 1 次提交
  11. 14 4月, 2016 1 次提交
  12. 08 4月, 2016 3 次提交
    • G
      gpiolib: Defer gpio device setup until after gpiolib initialization · 159f3cd9
      Guenter Roeck 提交于
      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: NGuenter Roeck <linux@roeck-us.net>
      Signed-off-by: NLinus Walleij <linus.walleij@linaro.org>
      159f3cd9
    • G
      gpiolib: Do not use devm functions when registering gpio chip · 476e2fc5
      Guenter Roeck 提交于
      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: NGuenter Roeck <linux@roeck-us.net>
      Signed-off-by: NLinus Walleij <linus.walleij@linaro.org>
      476e2fc5
    • D
      gpio / ACPI: ignore GpioInt() GPIOs when requesting GPIO_OUT_* · 25487533
      Dmitry Torokhov 提交于
      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:
      
      Device (ETSA)
      {
      	Name (_HID, "ELAN0001")
      	...
      
      	Method(_CRS, 0x0, NotSerialized)
      	{
      		Name(BUF0,ResourceTemplate ()
      		{
      			I2CSerialBus(
      				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: NMika Westerberg <mika.westerberg@linux.intel.com>
      Signed-off-by: NDmitry Torokhov <dtor@chromium.org>
      Signed-off-by: NLinus Walleij <linus.walleij@linaro.org>
      25487533
  13. 05 4月, 2016 1 次提交
    • L
      gpio: support native single-ended hardware drivers · c663e5f5
      Linus Walleij 提交于
      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: NMichael Hennerich <michael.hennerich@analog.com>
      Signed-off-by: NLinus Walleij <linus.walleij@linaro.org>
      c663e5f5
  14. 16 3月, 2016 1 次提交
  15. 07 3月, 2016 1 次提交
  16. 26 2月, 2016 1 次提交
  17. 23 2月, 2016 1 次提交
  18. 22 2月, 2016 1 次提交
  19. 20 2月, 2016 1 次提交
    • B
      gpiolib: fix crash when gpiochip removed · bd203bd5
      Bamvor Jian Zhang 提交于
      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: NBamvor Jian Zhang <bamvor.zhangjian@linaro.org>
      Signed-off-by: NLinus Walleij <linus.walleij@linaro.org>
      bd203bd5
  20. 19 2月, 2016 3 次提交
  21. 16 2月, 2016 3 次提交
  22. 12 2月, 2016 6 次提交
    • L
      gpio: reference count the gpio device for each desc · 33a68e86
      Linus Walleij 提交于
      Every time a descriptor is retrieved from the gpiolib, we issue
      module_get() to reference count the module supplying the GPIOs.
      We also need to call device_get() and device_put() as we also
      reference the backing gpio_device when doing this.
      
      Since the sysfs GPIO interface is using gpiod_get() this will
      also reference count the sysfs requests until all GPIOs are
      unexported.
      Signed-off-by: NLinus Walleij <linus.walleij@linaro.org>
      33a68e86
    • L
      gpio: reflect base and ngpio into gpio_device · fdeb8e15
      Linus Walleij 提交于
      Some information about the GPIO chip need to stay around also
      after the gpio_chip has been removed and only the gpio_device
      persist. The base and ngpio are such things, for example we
      don't want a new chip arriving to overlap the number space
      of a dangling gpio_device, and the chardev may still query
      the device for the number of lines etc.
      
      Note that the code that assigns base and insert gpio_device
      into the global list no longer check for a missing gpio_chip:
      we respect the number space allocated by any other gpio_device.
      
      As a consequence of the gdev being referenced directly from
      the gpio_desc, we need to verify it differently from all
      in-kernel API calls that fall through to direct queries to
      the gpio_chip vtable: we first check that desc is !NULL, then
      that desc->gdev is !NULL, then, if desc->gdev->chip is NULL,
      we *BAIL OUT* without any error, so as to manage the case
      where operations are requested on a device that is gone.
      
      These checks were non-uniform and partly missing in the past:
      so to simplify: create the macros VALIDATE_DESC() that will
      return -EINVAL if the desc or desc->gdev is missing and just
      0 if the chip is gone, and conversely VALIDATE_DESC_VOID()
      for the case where the function does not return an error.
      By using these macros, we get warning messages about missing
      gdev with reference to the right function in the kernel log.
      
      Despite the macro business this simplifies the code and make
      it more readable than if we copy/paste the same descriptor
      checking code into all code ABI call sites (IMHO).
      Signed-off-by: NLinus Walleij <linus.walleij@linaro.org>
      fdeb8e15
    • L
      gpio/pinctrl: sunxi: stop poking around in private vars · 6cee3821
      Linus Walleij 提交于
      This kind of hacks disturbs the refactoring of the gpiolib.
      
      The descriptor table belongs to the gpiolib, if we want to know
      something about something in it, use or define the proper accessor
      functions. Let's add this gpiochip_lins_is_irq() to do what the
      sunxi driver is trying at so we can privatize the descriptors
      properly.
      
      Cc: Maxime Ripard <maxime.ripard@free-electrons.com>
      Cc: Chen-Yu Tsai <wens@csie.org>
      Signed-off-by: NLinus Walleij <linus.walleij@linaro.org>
      6cee3821
    • L
      gpio: move descriptors into gpio_device · 1c3cdb18
      Linus Walleij 提交于
      We need gpio_device to hold the descriptors so that they can
      be lifecycled with the struct gpio_device held from userspace.
      Move the descriptor array into gpio_device. Also rename it from
      "desc" (singularis) to "descs" (pluralis) to reflect the fact
      that it is an array.
      Signed-off-by: NLinus Walleij <linus.walleij@linaro.org>
      1c3cdb18
    • L
      gpio: move sysfs mock device to the gpio_device · afbc4f31
      Linus Walleij 提交于
      Since gpio_device is the struct that survives if the backing
      gpio_chip is removed, move the sysfs mock device to this state
      container so it becomes part of the dangling state of the
      GPIO device on removal.
      Signed-off-by: NLinus Walleij <linus.walleij@linaro.org>
      afbc4f31
    • L
      gpio: remember to finally free gpio_device · 9efd9e69
      Linus Walleij 提交于
      When the device core reference count for the device goes to
      0 and it calls .release() we free resources and so can also
      finally free up the GPIO state container, struct gpio_device.
      Signed-off-by: NLinus Walleij <linus.walleij@linaro.org>
      9efd9e69