1. 04 7月, 2016 1 次提交
    • J
      Revert "gpiolib: Split GPIO flags parsing and GPIO configuration" · 85b03b30
      Johan Hovold 提交于
      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
      interface.
      
      Cc: stable <stable@vger.kernel.org>	# 4.4
      Signed-off-by: NJohan Hovold <johan@kernel.org>
      Signed-off-by: NLinus Walleij <linus.walleij@linaro.org>
      85b03b30
  2. 23 6月, 2016 2 次提交
  3. 18 6月, 2016 2 次提交
  4. 08 6月, 2016 2 次提交
    • R
      gpiolib: Fix unaligned used of reference counters · f4833b8c
      Ricardo Ribalda Delgado 提交于
      gpiolib relies on the reference counters to clean up the gpio_device
      structure.
      
      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: NRicardo Ribalda Delgado <ricardo.ribalda@gmail.com>
      Signed-off-by: NLinus Walleij <linus.walleij@linaro.org>
      f4833b8c
    • R
      gpiolib: Fix NULL pointer deference · 11f33a6d
      Ricardo Ribalda Delgado 提交于
      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
      0000000000000090
      [  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: NRicardo Ribalda Delgado <ricardo.ribalda@gmail.com>
      Signed-off-by: NLinus Walleij <linus.walleij@linaro.org>
      11f33a6d
  5. 30 5月, 2016 4 次提交
  6. 02 5月, 2016 1 次提交
  7. 30 4月, 2016 1 次提交
  8. 26 4月, 2016 1 次提交
  9. 14 4月, 2016 1 次提交
  10. 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
  11. 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
  12. 16 3月, 2016 1 次提交
  13. 07 3月, 2016 1 次提交
  14. 26 2月, 2016 1 次提交
  15. 23 2月, 2016 1 次提交
  16. 22 2月, 2016 1 次提交
  17. 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
  18. 19 2月, 2016 3 次提交
  19. 16 2月, 2016 3 次提交
  20. 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
  21. 09 2月, 2016 3 次提交
    • L
      gpio: add a userspace chardev ABI for GPIOs · 3c702e99
      Linus Walleij 提交于
      A new chardev that is to be used for userspace GPIO access is
      added in this patch. It is intended to gradually replace the
      horribly broken sysfs ABI.
      
      Using a chardev has many upsides:
      
      - All operations are per-gpiochip, which is the actual
        device underlying the GPIOs, making us tie in to the
        kernel device model properly.
      
      - Hotpluggable GPIO controllers can come and go, as this
        kind of problem has been know to userspace for character
        devices since ages, and if a gpiochip handle is held in
        userspace we know we will break something, whereas the
        sysfs is stateless.
      
      - The one-value-per-file rule of sysfs is really hard to
        maintain when you want to twist more than one knob at a time,
        for example have in-kernel APIs to switch several GPIO
        lines at the same time, and this will be possible to do
        with a single ioctl() from userspace, saving a lot of
        context switching.
      
      We also need to add a new bus type for GPIO. This is
      necessary for example for userspace coldplug, where sysfs is
      traversed to find the boot-time device nodes and create the
      character devices in /dev.
      
      This new chardev ABI is *non* *optional* and can be counted
      on to be present in the future, emphasizing the preference
      of this ABI.
      
      The ABI only implements one single ioctl() to get the name
      and number of GPIO lines of a chip. Even this is debatable:
      see it as a minimal example for review. This ABI shall be
      ruthlessly reviewed and etched in stone.
      
      The old /sys/class/gpio is still optional to compile in,
      but will be deprecated.
      
      Unique device IDs are created using IDR, which is overkill
      and insanely scalable, but also well tested.
      
      Cc: Johan Hovold <johan@kernel.org>
      Cc: Michael Welling <mwelling@ieee.org>
      Cc: Markus Pargmann <mpa@pengutronix.de>
      Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
      Cc: Arnd Bergmann <arnd@arndb.de>
      Signed-off-by: NLinus Walleij <linus.walleij@linaro.org>
      3c702e99
    • L
      gpio: refer to gpio device in prints and debugfs · 34ffd85d
      Linus Walleij 提交于
      We use the new struct device inside gpio_chip to related debug
      prints and warnings, and we also add it to the debugfs dump.
      
      Cc: Johan Hovold <johan@kernel.org>
      Cc: Michael Welling <mwelling@ieee.org>
      Cc: Markus Pargmann <mpa@pengutronix.de>
      Signed-off-by: NLinus Walleij <linus.walleij@linaro.org>
      34ffd85d
    • L
      gpio: make the gpiochip a real device · ff2b1359
      Linus Walleij 提交于
      GPIO chips have been around for years, but were never real devices,
      instead they were piggy-backing on a parent device (such as a
      platform_device or amba_device) but this was always optional.
      GPIO chips could also exist without any device at all, with its
      struct device *parent (ex *dev) pointer being set to null.
      
      When sysfs was in use, a mock device would be created, with the
      optional parent assigned, or just floating orphaned with NULL
      as parent.
      
      If sysfs is active, it will use this device as parent.
      
      We now create a gpio_device struct containing a real
      struct device and move the subsystem over to using that. The
      list of struct gpio_chip:s is augmented to hold struct
      gpio_device:s and we find gpio_chips:s by first looking up
      the struct gpio_device.
      
      The struct gpio_device is designed to stay around even if the
      gpio_chip is removed, so as to satisfy users in userspace
      that need a backing data structure to hold the state of the
      session initiated with e.g. a character device even if there is
      no physical chip anymore.
      
      From this point on, gpiochips are devices.
      
      Cc: Johan Hovold <johan@kernel.org>
      Cc: Michael Welling <mwelling@ieee.org>
      Cc: Markus Pargmann <mpa@pengutronix.de>
      Signed-off-by: NLinus Walleij <linus.walleij@linaro.org>
      ff2b1359