1. 25 Sep, 2018 1 commit
  2. 17 Sep, 2018 1 commit
    • Linus Walleij's avatar
      gpio: Get rid of legacy header · f13a0b0b
      Linus Walleij authored
      A bunch of core gpiolib files still include the <linux/gpio.h>
      legacy API header for no good reason. After this only the
      gpiolib-legacy.c file includes it, which is fine.
      
      The sysfs ABI code has a pointless wrapper function around
      gpio_to_desc() we can just loose.
      Signed-off-by: default avatarLinus Walleij <linus.walleij@linaro.org>
      f13a0b0b
  3. 20 Dec, 2017 4 commits
    • Christophe Leroy's avatar
      gpio: sysfs: avoid using kstrtol() in 'value' attribute write · 1efba35a
      Christophe Leroy authored
      A 'perf record' on an app continuously writing in the 'value'
      attribute show that most of the time is spent in kstrtol()
      
      --17.99%--value_store
                |
                |--10.17%--kstrtoint
                |          |
                |          |--8.82%--kstrtoll
                |
                |--2.50%--gpiod_set_value_cansleep
                |
                |--1.82%--u16_gpio_set
                |
                |--1.46%--value_store
      
      The normal case is to write 0 or 1 in the attribute, therefore
      this patch avoids the call to kstrtol() in the most common cases
      
      Then 'perf record' shows
      
      --7.21%--value_store
                |
                |--2.69%--u16_gpio_set
                |
                |--1.47%--value_store
                |
                |--1.08%--gpiod_set_value_cansleep
                |
                |--0.60%--mutex_lock
                |
                 --0.58%--mutex_unlock
      Signed-off-by: default avatarChristophe Leroy <christophe.leroy@c-s.fr>
      Signed-off-by: default avatarLinus Walleij <linus.walleij@linaro.org>
      1efba35a
    • Christophe Leroy's avatar
      gpio: sysfs: don't use sprintf() for 'value' attribute · 7a94b88c
      Christophe Leroy authored
      A bench with 'perf record' shows that most of time spent in value_show()
      is spent in sprintf()
      
      --42.41%--sysfs_kf_read
                |
                |--39.73%--dev_attr_show
                |          |
                |          |--38.23%--value_show
                |          |          |
                |          |          |--29.22%--sprintf
                |          |          |
                |          |          |--2.94%--gpiod_get_value_cansleep
                |          |          |
      
      value_show() only returns "0\n" or "1\n", therefore the use of
      sprintf() can be avoided
      
      With this patch we get the following result with 'perf record'
      
      --13.89%--sysfs_kf_read
                |
                |--10.72%--dev_attr_show
                |          |
                |          |--9.44%--value_show
                |          |          |
                |          |          |--4.61%--gpiod_get_value_cansleep
      Signed-off-by: default avatarChristophe Leroy <christophe.leroy@c-s.fr>
      Signed-off-by: default avatarLinus Walleij <linus.walleij@linaro.org>
      7a94b88c
    • Christophe Leroy's avatar
      gpio: sysfs: correct error handling on 'value' attribute read. · 9295c012
      Christophe Leroy authored
      'value' attribute is supposed to only return 0 or 1 according to
      the documentation.
      With today's implementation, if gpiod_get_value_cansleep() fails
      the printed 'value' is a negative value.
      
      This patch ensures that an error is returned on read instead.
      Signed-off-by: default avatarChristophe Leroy <christophe.leroy@c-s.fr>
      Signed-off-by: default avatarLinus Walleij <linus.walleij@linaro.org>
      9295c012
    • Christophe Leroy's avatar
      gpio: sysfs: change 'value' attribute to prealloc · 7fda9100
      Christophe Leroy authored
      The GPIO 'value' attribute is time critical. A small bench with
      'perf record' on the app below shows that 80% of the time spent in
      sysfs_kf_seq_show() is spent in memset() for zeroising the buffer.
      
      |--67.48%--sysfs_kf_seq_show
      |          |
      |          |--54.40%--memset
      |          |
      |          |--11.49%--dev_attr_show
      |          |          |
      |          |          |--10.06%--value_show
      |          |          |          |
      |          |          |          |--4.75%--sprintf
      |          |          |          |          |
      
      This patch changes the attribute type to prealloc, eliminating the
      need to zeroise the buffer at each read. 'perf record' gives the
      following result.
      
      |--42.41%--sysfs_kf_read
      |          |
      |          |--39.73%--dev_attr_show
      |          |          |
      |          |          |--38.23%--value_show
      |          |          |          |
      |          |          |          |--29.22%--sprintf
      |          |          |          |          |
      
      Test done with the following small app:
      
      int main(int argc, char **argv)
      {
      	int fd = open(argv[1], O_RDONLY);
      
      	for (;;) {
      		int buf[512];
      
      		read(fd, buf, 512);
      		lseek(fd, 0, SEEK_SET);
      	}
      	exit(0);
      }
      Signed-off-by: default avatarChristophe Leroy <christophe.leroy@c-s.fr>
      Signed-off-by: default avatarLinus Walleij <linus.walleij@linaro.org>
      7fda9100
  4. 02 Dec, 2017 1 commit
    • Andrew Jeffery's avatar
      gpio: gpiolib: Generalise state persistence beyond sleep · e10f72bf
      Andrew Jeffery authored
      General support for state persistence is added to gpiolib with the
      introduction of a new pinconf parameter to propagate the request to
      hardware. The existing persistence support for sleep is adapted to
      include hardware support if the GPIO driver provides it. Persistence
      continues to be enabled by default; in-kernel consumers can opt out, but
      userspace (currently) does not have a choice.
      
      The *_SLEEP_MAY_LOSE_VALUE and *_SLEEP_MAINTAIN_VALUE symbols are
      renamed, dropping the SLEEP prefix to reflect that the concept is no
      longer sleep-specific.  I feel that renaming to just *_MAY_LOSE_VALUE
      could initially be misinterpreted, so I've further changed the symbols
      to *_TRANSITORY and *_PERSISTENT to address this.
      
      The sysfs interface is modified only to keep consistency with the
      chardev interface in enforcing persistence for userspace exports.
      Signed-off-by: default avatarAndrew Jeffery <andrew@aj.id.au>
      Reviewed-by: default avatarCharles Keepax <ckeepax@opensource.cirrus.com>
      Acked-by: default avatarRob Herring <robh@kernel.org>
      Signed-off-by: default avatarLinus Walleij <linus.walleij@linaro.org>
      e10f72bf
  5. 14 Aug, 2017 2 commits
  6. 09 Jun, 2017 1 commit
  7. 12 Sep, 2016 1 commit
  8. 25 Feb, 2016 1 commit
  9. 11 Feb, 2016 3 commits
    • Linus Walleij's avatar
      gpio: reflect base and ngpio into gpio_device · fdeb8e15
      Linus Walleij authored
      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: default avatarLinus Walleij <linus.walleij@linaro.org>
      fdeb8e15
    • Linus Walleij's avatar
      gpio: move descriptors into gpio_device · 1c3cdb18
      Linus Walleij authored
      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: default avatarLinus Walleij <linus.walleij@linaro.org>
      1c3cdb18
    • Linus Walleij's avatar
      gpio: move sysfs mock device to the gpio_device · afbc4f31
      Linus Walleij authored
      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: default avatarLinus Walleij <linus.walleij@linaro.org>
      afbc4f31
  10. 09 Feb, 2016 1 commit
    • Linus Walleij's avatar
      gpio: make the gpiochip a real device · ff2b1359
      Linus Walleij authored
      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: default avatarLinus Walleij <linus.walleij@linaro.org>
      ff2b1359
  11. 19 Nov, 2015 1 commit
    • Linus Walleij's avatar
      gpio: change member .dev to .parent · 58383c78
      Linus Walleij authored
      The name .dev in a struct is normally reserved for a struct device
      that is let us say a superclass to the thing described by the struct.
      struct gpio_chip stands out by confusingly using a struct device *dev
      to point to the parent device (such as a platform_device) that
      represents the hardware. As we want to give gpio_chip:s real devices,
      this is not working. We need to rename this member to parent.
      
      This was done by two coccinelle scripts, I guess it is possible to
      combine them into one, but I don't know such stuff. They look like
      this:
      
      @@
      struct gpio_chip *var;
      @@
      -var->dev
      +var->parent
      
      and:
      
      @@
      struct gpio_chip var;
      @@
      -var.dev
      +var.parent
      
      and:
      
      @@
      struct bgpio_chip *var;
      @@
      -var->gc.dev
      +var->gc.parent
      
      Plus a few instances of bgpio that I couldn't figure out how
      to teach Coccinelle to rewrite.
      
      This patch hits all over the place, but I *strongly* prefer this
      solution to any piecemal approaches that just exercise patch
      mechanics all over the place. It mainly hits drivers/gpio and
      drivers/pinctrl which is my own backyard anyway.
      
      Cc: Haavard Skinnemoen <hskinnemoen@gmail.com>
      Cc: Rafał Miłecki <zajec5@gmail.com>
      Cc: Richard Purdie <rpurdie@rpsys.net>
      Cc: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
      Cc: Alek Du <alek.du@intel.com>
      Cc: Jaroslav Kysela <perex@perex.cz>
      Cc: Takashi Iwai <tiwai@suse.com>
      Acked-by: default avatarDmitry Torokhov <dmitry.torokhov@gmail.com>
      Acked-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      Acked-by: default avatarLee Jones <lee.jones@linaro.org>
      Acked-by: default avatarJiri Kosina <jkosina@suse.cz>
      Acked-by: default avatarHans-Christian Egtvedt <egtvedt@samfundet.no>
      Acked-by: default avatarJacek Anaszewski <j.anaszewski@samsung.com>
      Signed-off-by: default avatarLinus Walleij <linus.walleij@linaro.org>
      58383c78
  12. 05 Oct, 2015 1 commit
  13. 24 Sep, 2015 1 commit
  14. 12 May, 2015 21 commits