1. 16 9月, 2019 1 次提交
    • B
      gpio: don't WARN() on NULL descs if gpiolib is disabled · c9c90711
      Bartosz Golaszewski 提交于
      [ Upstream commit ffe0bbabb0cffceceae07484fde1ec2a63b1537c ]
      
      If gpiolib is disabled, we use the inline stubs from gpio/consumer.h
      instead of regular definitions of GPIO API. The stubs for 'optional'
      variants of gpiod_get routines return NULL in this case as if the
      relevant GPIO wasn't found. This is correct so far.
      
      Calling other (non-gpio_get) stubs from this header triggers a warning
      because the GPIO descriptor couldn't have been requested. The warning
      however is unconditional (WARN_ON(1)) and is emitted even if the passed
      descriptor pointer is NULL.
      
      We don't want to force the users of 'optional' gpio_get to check the
      returned pointer before calling e.g. gpiod_set_value() so let's only
      WARN on non-NULL descriptors.
      
      Cc: stable@vger.kernel.org
      Reported-by: NClaus H. Stovgaard <cst@phaseone.com>
      Signed-off-by: NBartosz Golaszewski <bgolaszewski@baylibre.com>
      Signed-off-by: NSasha Levin <sashal@kernel.org>
      c9c90711
  2. 13 2月, 2019 1 次提交
    • M
      gpiolib: Fix possible use after free on label · 3555de57
      Muchun Song 提交于
      [ Upstream commit 18534df419041e6c1f4b41af56ee7d41f757815c ]
      
      gpiod_request_commit() copies the pointer to the label passed as
      an argument only to be used later. But there's a chance the caller
      could immediately free the passed string(e.g., local variable).
      This could trigger a use after free when we use gpio label(e.g.,
      gpiochip_unlock_as_irq(), gpiochip_is_requested()).
      
      To be on the safe side: duplicate the string with kstrdup_const()
      so that if an unaware user passes an address to a stack-allocated
      buffer, we won't get the arbitrary label.
      
      Also fix gpiod_set_consumer_name().
      Signed-off-by: NMuchun Song <smuchun@gmail.com>
      Signed-off-by: NLinus Walleij <linus.walleij@linaro.org>
      Signed-off-by: NSasha Levin <sashal@kernel.org>
      3555de57
  3. 30 7月, 2018 1 次提交
  4. 18 6月, 2018 1 次提交
    • L
      gpio: Add API to explicitly name a consumer · 90b39402
      Linus Walleij 提交于
      The GPIO (descriptor) API registers a "label" naming what is
      currently using the GPIO line. Typically this is taken from
      things like the device tree node, so "reset-gpios" will result
      in he line being labeled "reset".
      
      The technical effect is pretty much zero: the use is for
      debug and introspection, such as "lsgpio" and debugfs files.
      
      However sometimes the user want this cuddly feeling of
      listing all GPIO lines and seeing exactly what they are for
      and it gives a very fulfilling sense of control. Especially
      in the cases when the device tree node doesn't provide a
      good name, or anonymous GPIO lines assigned just to
      "gpios" in the device tree because the usage is implicit.
      
      For these cases it may be nice to be able to label the
      line directly and explicitly.
      Signed-off-by: NLinus Walleij <linus.walleij@linaro.org>
      90b39402
  5. 23 5月, 2018 1 次提交
  6. 12 1月, 2018 1 次提交
    • L
      gpio: Export devm_gpiod_get_from_of_node() for consumers · 92542edc
      Linus Walleij 提交于
      We have been holding back on adding an API for fetching GPIO handles
      directly from device nodes, strongly preferring to get it from the
      spawn devices instead.
      
      The fwnode interface however already contains an API for doing this,
      as it is used for opaque device tree nodes or ACPI nodes for getting
      handles to LEDs and keys that use GPIO: those are specified as one
      child per LED/key in the device tree and are not individual devices.
      
      However regulators present a special problem as they already have
      helper functions to traverse the device tree from a regulator node
      and two levels down to fill in data, and as it already traverses
      GPIO nodes in its own way, and already holds a pointer to each
      regulators device tree node, it makes most sense to export an
      API to fetch the GPIO descriptor directly from the node.
      
      We only support the devm_* version for now, hopefully no non-devres
      version will be needed.
      Signed-off-by: NLinus Walleij <linus.walleij@linaro.org>
      92542edc
  7. 03 12月, 2017 1 次提交
    • A
      gpio: gpiolib: Generalise state persistence beyond sleep · e10f72bf
      Andrew Jeffery 提交于
      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: NAndrew Jeffery <andrew@aj.id.au>
      Reviewed-by: NCharles Keepax <ckeepax@opensource.cirrus.com>
      Acked-by: NRob Herring <robh@kernel.org>
      Signed-off-by: NLinus Walleij <linus.walleij@linaro.org>
      e10f72bf
  8. 02 11月, 2017 1 次提交
    • G
      License cleanup: add SPDX GPL-2.0 license identifier to files with no license · b2441318
      Greg Kroah-Hartman 提交于
      Many source files in the tree are missing licensing information, which
      makes it harder for compliance tools to determine the correct license.
      
      By default all files without license information are under the default
      license of the kernel, which is GPL version 2.
      
      Update the files which contain no license information with the 'GPL-2.0'
      SPDX license identifier.  The SPDX identifier is a legally binding
      shorthand, which can be used instead of the full boiler plate text.
      
      This patch is based on work done by Thomas Gleixner and Kate Stewart and
      Philippe Ombredanne.
      
      How this work was done:
      
      Patches were generated and checked against linux-4.14-rc6 for a subset of
      the use cases:
       - file had no licensing information it it.
       - file was a */uapi/* one with no licensing information in it,
       - file was a */uapi/* one with existing licensing information,
      
      Further patches will be generated in subsequent months to fix up cases
      where non-standard license headers were used, and references to license
      had to be inferred by heuristics based on keywords.
      
      The analysis to determine which SPDX License Identifier to be applied to
      a file was done in a spreadsheet of side by side results from of the
      output of two independent scanners (ScanCode & Windriver) producing SPDX
      tag:value files created by Philippe Ombredanne.  Philippe prepared the
      base worksheet, and did an initial spot review of a few 1000 files.
      
      The 4.13 kernel was the starting point of the analysis with 60,537 files
      assessed.  Kate Stewart did a file by file comparison of the scanner
      results in the spreadsheet to determine which SPDX license identifier(s)
      to be applied to the file. She confirmed any determination that was not
      immediately clear with lawyers working with the Linux Foundation.
      
      Criteria used to select files for SPDX license identifier tagging was:
       - Files considered eligible had to be source code files.
       - Make and config files were included as candidates if they contained >5
         lines of source
       - File already had some variant of a license header in it (even if <5
         lines).
      
      All documentation files were explicitly excluded.
      
      The following heuristics were used to determine which SPDX license
      identifiers to apply.
      
       - when both scanners couldn't find any license traces, file was
         considered to have no license information in it, and the top level
         COPYING file license applied.
      
         For non */uapi/* files that summary was:
      
         SPDX license identifier                            # files
         ---------------------------------------------------|-------
         GPL-2.0                                              11139
      
         and resulted in the first patch in this series.
      
         If that file was a */uapi/* path one, it was "GPL-2.0 WITH
         Linux-syscall-note" otherwise it was "GPL-2.0".  Results of that was:
      
         SPDX license identifier                            # files
         ---------------------------------------------------|-------
         GPL-2.0 WITH Linux-syscall-note                        930
      
         and resulted in the second patch in this series.
      
       - if a file had some form of licensing information in it, and was one
         of the */uapi/* ones, it was denoted with the Linux-syscall-note if
         any GPL family license was found in the file or had no licensing in
         it (per prior point).  Results summary:
      
         SPDX license identifier                            # files
         ---------------------------------------------------|------
         GPL-2.0 WITH Linux-syscall-note                       270
         GPL-2.0+ WITH Linux-syscall-note                      169
         ((GPL-2.0 WITH Linux-syscall-note) OR BSD-2-Clause)    21
         ((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause)    17
         LGPL-2.1+ WITH Linux-syscall-note                      15
         GPL-1.0+ WITH Linux-syscall-note                       14
         ((GPL-2.0+ WITH Linux-syscall-note) OR BSD-3-Clause)    5
         LGPL-2.0+ WITH Linux-syscall-note                       4
         LGPL-2.1 WITH Linux-syscall-note                        3
         ((GPL-2.0 WITH Linux-syscall-note) OR MIT)              3
         ((GPL-2.0 WITH Linux-syscall-note) AND MIT)             1
      
         and that resulted in the third patch in this series.
      
       - when the two scanners agreed on the detected license(s), that became
         the concluded license(s).
      
       - when there was disagreement between the two scanners (one detected a
         license but the other didn't, or they both detected different
         licenses) a manual inspection of the file occurred.
      
       - In most cases a manual inspection of the information in the file
         resulted in a clear resolution of the license that should apply (and
         which scanner probably needed to revisit its heuristics).
      
       - When it was not immediately clear, the license identifier was
         confirmed with lawyers working with the Linux Foundation.
      
       - If there was any question as to the appropriate license identifier,
         the file was flagged for further research and to be revisited later
         in time.
      
      In total, over 70 hours of logged manual review was done on the
      spreadsheet to determine the SPDX license identifiers to apply to the
      source files by Kate, Philippe, Thomas and, in some cases, confirmation
      by lawyers working with the Linux Foundation.
      
      Kate also obtained a third independent scan of the 4.13 code base from
      FOSSology, and compared selected files where the other two scanners
      disagreed against that SPDX file, to see if there was new insights.  The
      Windriver scanner is based on an older version of FOSSology in part, so
      they are related.
      
      Thomas did random spot checks in about 500 files from the spreadsheets
      for the uapi headers and agreed with SPDX license identifier in the
      files he inspected. For the non-uapi files Thomas did random spot checks
      in about 15000 files.
      
      In initial set of patches against 4.14-rc6, 3 files were found to have
      copy/paste license identifier errors, and have been fixed to reflect the
      correct identifier.
      
      Additionally Philippe spent 10 hours this week doing a detailed manual
      inspection and review of the 12,461 patched files from the initial patch
      version early this week with:
       - a full scancode scan run, collecting the matched texts, detected
         license ids and scores
       - reviewing anything where there was a license detected (about 500+
         files) to ensure that the applied SPDX license was correct
       - reviewing anything where there was no detection but the patch license
         was not GPL-2.0 WITH Linux-syscall-note to ensure that the applied
         SPDX license was correct
      
      This produced a worksheet with 20 files needing minor correction.  This
      worksheet was then exported into 3 different .csv files for the
      different types of files to be modified.
      
      These .csv files were then reviewed by Greg.  Thomas wrote a script to
      parse the csv files and add the proper SPDX tag to the file, in the
      format that the file expected.  This script was further refined by Greg
      based on the output to detect more types of files automatically and to
      distinguish between header and source .c files (which need different
      comment types.)  Finally Greg ran the script using the .csv files to
      generate the patches.
      Reviewed-by: NKate Stewart <kstewart@linuxfoundation.org>
      Reviewed-by: NPhilippe Ombredanne <pombredanne@nexb.com>
      Reviewed-by: NThomas Gleixner <tglx@linutronix.de>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      b2441318
  9. 30 10月, 2017 1 次提交
    • L
      gpio: Make it possible for consumers to enforce open drain · f926dfc1
      Linus Walleij 提交于
      Some busses, like I2C, strictly need to have the line handled
      as open drain, i.e. not actively driven high. For this reason
      the i2c-gpio.c bit-banged I2C driver is reimplementing open
      drain handling outside of gpiolib.
      
      This is not very optimal. Instead make it possible for a
      consumer to explcitly express that the line must be handled
      as open drain instead of allowing local hacks papering over
      this issue.
      
      The descriptor tables, whether DT, ACPI or board files, should
      of course have flagged these lines as open drain. E.g.:
      enum gpio_lookup_flags GPIO_OPEN_DRAIN for a board file, or
      gpios = <&foo 42 GPIO_ACTIVE_HIGH|GPIO_OPEN_DRAIN>; in a
      device tree using <dt-bindings/gpio/gpio.h>
      
      But more often than not, these descriptors are wrong. So
      we need to make it possible for consumers to enforce this
      open drain behaviour.
      
      We now have two new enumerated GPIO descriptor config flags:
      GPIOD_OUT_LOW_OPEN_DRAIN and GPIOD_OUT_HIGH_OPEN_DRAIN
      that will set up the lined enforced as open drain as output
      low or high, using open drain (if the driver supports it)
      or using open drain emulation (setting the line as input
      to drive it high) from the gpiolib core.
      
      Cc: linux-gpio@vger.kernel.org
      Tested-by: NGeert Uytterhoeven <geert+renesas@glider.be>
      Signed-off-by: NLinus Walleij <linus.walleij@linaro.org>
      f926dfc1
  10. 20 10月, 2017 1 次提交
    • L
      gpio: Introduce ->get_multiple callback · eec1d566
      Lukas Wunner 提交于
      SPI-attached GPIO controllers typically read out all inputs in one go.
      If callers desire the values of multipe inputs, ideally a single readout
      should take place to return the desired values.  However the current
      driver API only offers a ->get callback but no ->get_multiple (unlike
      ->set_multiple, which is present).  Thus, to read multiple inputs, a
      full readout needs to be performed for every single value (barring
      driver-internal caching), which is inefficient.
      
      In fact, the lack of a ->get_multiple callback has been bemoaned
      repeatedly by the gpio subsystem maintainer:
      http://www.spinics.net/lists/linux-gpio/msg10571.html
      http://www.spinics.net/lists/devicetree/msg121734.html
      
      Introduce the missing callback.  Add corresponding consumer functions
      such as gpiod_get_array_value().  Amend linehandle_ioctl() to take
      advantage of the newly added infrastructure.  Update the documentation.
      
      Cc: Rojhalat Ibrahim <imr@rtschenk.de>
      Signed-off-by: NLukas Wunner <lukas@wunner.de>
      Signed-off-by: NLinus Walleij <linus.walleij@linaro.org>
      eec1d566
  11. 15 3月, 2017 1 次提交
    • D
      gpio: return NULL from gpiod_get_optional when GPIOLIB is disabled · 22c40367
      Dmitry Torokhov 提交于
      Given the intent behind gpiod_get_optional() and friends it does not make
      sense to return -ENOSYS when GPIOLIB is disabled: the driver is expected to
      work just fine without gpio so let's behave as if gpio was not found.
      Otherwise we have to special-case -ENOSYS in drivers.
      
      Note that there was objection that someone might forget to enable GPIOLIB
      when dealing with a platform that has device that actually specifies
      optional gpio and we'll break it. I find this unconvincing as that would
      have to be the *only GPIO* in the system, which is extremely unlikely.
      Signed-off-by: NDmitry Torokhov <dmitry.torokhov@gmail.com>
      Signed-off-by: NLinus Walleij <linus.walleij@linaro.org>
      22c40367
  12. 14 3月, 2017 1 次提交
  13. 21 2月, 2017 1 次提交
  14. 05 2月, 2017 2 次提交
  15. 26 1月, 2017 2 次提交
  16. 25 9月, 2015 2 次提交
    • L
      gpio: keep the GPIO line names internal · f881bab0
      Linus Walleij 提交于
      This refactors the changes to the GPIO line naming mechanism to
      not have so widespread effects, instead we conclude the patch series
      by having created a name attribute in the GPIO descriptor, that need
      not be globally unique, and it will be initialized from the old
      .names array in struct gpio_chip if it exists, then used in the legacy
      sysfs code like the array was used previously.
      
      The associated changes to name lines from the device tree are
      controversial and need to stand alone from this. Resulting changes:
      
      1. Remove the export and the header for the gpio_name_to_desc() as so
      far the only use is inside gpiolib.c. Staticize gpio_name_to_desc()
      and move it above the only function using it.
      
      2. Only print a warning if there are two GPIO lines with the same name.
      The reason is to preserve current behaviour: before the previous
      changes to the naming mechanism this would not reject probing the
      driver, instead the error would occur when trying to export the line
      in sysfs, so restore this behaviour, but print a friendly warning
      if names collide.
      
      Cc: Johan Hovold <johan@kernel.org>
      Cc: Markus Pargmann <mpa@pengutronix.de>
      Signed-off-by: NLinus Walleij <linus.walleij@linaro.org>
      f881bab0
    • M
      gpio: Introduce gpio descriptor 'name' · c0017ed7
      Markus Pargmann 提交于
      The latest gpio hogging mechanism assigns each gpio a 'line-name' in the
      devicetree. The 'name' field is different from the 'label' field.
      'label' is only used for requested GPIOs to describe its current use by
      driver or userspace.
      
      The 'name' field describes the GPIO itself, not the use. This is most
      likely identical to the label in the schematic on the GPIO line and
      should help to find this particular GPIO.
      
      This is equivalent to the gpiochip->names array. However names should be
      stored in the GPIO descriptor. We will use gpiochip->names in the future
      only as initializer for the GPIO descriptors for drivers that assign
      GPIO names hardcoded. All other GPIO names will be parsed from DT and
      directly assigned to the GPIO descriptor.
      
      This patch adds a helper function to find gpio descriptors by name
      instead of gpio number.
      Signed-off-by: NMarkus Pargmann <mpa@pengutronix.de>
      Signed-off-by: NLinus Walleij <linus.walleij@linaro.org>
      c0017ed7
  17. 06 7月, 2015 1 次提交
  18. 01 6月, 2015 1 次提交
  19. 26 5月, 2015 1 次提交
  20. 12 5月, 2015 1 次提交
    • J
      gpio: remove gpiod_sysfs_set_active_low · 166a85e4
      Johan Hovold 提交于
      Remove gpiod_sysfs_set_active_low (and gpio_sysfs_set_active_low) which
      allowed code to change the polarity of a gpio line even after it had
      been exported through sysfs.
      
      Drivers should not care, and generally does not know, about gpio-line
      polarity which is a hardware feature that needs to be described by
      firmware.
      
      It is currently possible to define gpio-line polarity in device-tree and
      acpi firmware or using platform data. Userspace can also change the
      polarity through sysfs.
      
      Note that drivers using the legacy gpio interface could still use
      GPIOF_ACTIVE_LOW to change the polarity before exporting the gpio.
      
      There are no in-kernel users of this interface.
      
      Cc: Jonathan Corbet <corbet@lwn.net>
      Cc: Harry Wei <harryxiyou@gmail.com>
      Cc: Arnd Bergmann <arnd@arndb.de>
      Cc: linux-doc@vger.kernel.org
      Cc: linux-kernel@zh-kernel.org
      Cc: linux-arch@vger.kernel.org
      Signed-off-by: NJohan Hovold <johan@kernel.org>
      Reviewed-by: NAlexandre Courbot <acourbot@nvidia.com>
      Signed-off-by: NLinus Walleij <linus.walleij@linaro.org>
      166a85e4
  21. 05 3月, 2015 2 次提交
  22. 04 3月, 2015 1 次提交
  23. 16 1月, 2015 1 次提交
  24. 28 11月, 2014 1 次提交
  25. 27 11月, 2014 1 次提交
    • R
      gpiolib: allow simultaneous setting of multiple GPIO outputs · 5f424243
      Rojhalat Ibrahim 提交于
      Introduce new functions gpiod_set_array & gpiod_set_raw_array to the consumer
      interface which allow setting multiple outputs with just one function call.
      Also add an optional set_multiple function to the driver interface. Without an
      implementation of that function in the chip driver outputs are set
      sequentially.
      
      Implementing the set_multiple function in a chip driver allows for:
      - Improved performance for certain use cases. The original motivation for this
        was the task of configuring an FPGA. In that specific case, where 9 GPIO
        lines have to be set many times, configuration time goes down from 48 s to
        20 s when using the new function.
      - Simultaneous glitch-free setting of multiple pins on any kind of parallel
        bus attached to GPIOs provided they all reside on the same chip and bank.
      
      Limitations:
        Performance is only improved for normal high-low outputs. Open drain and
        open source outputs are always set separately from each other. Those kinds
        of outputs could probably be accelerated in a similar way if we could
        forgo the error checking when setting GPIO directions.
      
      Change log:
        v6: - rebase on current linux-gpio devel branch
        v5: - check can_sleep property per chip
            - remove superfluous checks
            - supplement documentation
        v4: - add gpiod_set_array function for setting logical values
            - change interface of the set_multiple driver function to use
              unsigned long as type for the bit fields
            - use generic bitops (which also use unsigned long for bit fields)
            - do not use ARCH_NR_GPIOS any more
        v3: - add documentation
            - change commit message
        v2: - use descriptor interface
            - allow arbitrary groups of GPIOs spanning multiple chips
      Signed-off-by: NRojhalat Ibrahim <imr@rtschenk.de>
      Reviewed-by: NAlexandre Courbot <acourbot@nvidia.com>
      Reviewed-by: NMark Brown <broonie@linaro.org>
      Signed-off-by: NLinus Walleij <linus.walleij@linaro.org>
      5f424243
  26. 05 11月, 2014 1 次提交
  27. 02 9月, 2014 1 次提交
  28. 21 8月, 2014 1 次提交
  29. 28 7月, 2014 1 次提交
    • A
      gpio: add flags argument to gpiod_get*() functions · 39b2bbe3
      Alexandre Courbot 提交于
      The huge majority of GPIOs have their direction and initial value set
      right after being obtained by one of the gpiod_get() functions. The
      integer GPIO API had gpio_request_one() that took a convenience flags
      parameter allowing to specify an direction and value applied to the
      returned GPIO. This feature greatly simplifies client code and ensures
      errors are always handled properly.
      
      A similar feature has been requested for the gpiod API. Since setting
      the direction of a GPIO is so often the very next action done after
      obtaining its descriptor, we prefer to extend the existing functions
      instead of introducing new functions that would raise the
      number of gpiod getters to 16 (!).
      
      The drawback of this approach is that all gpiod clients need to be
      updated. To limit the pain, temporary macros are introduced that allow
      gpiod_get*() to be called with or without the extra flags argument. They
      will be removed once all consumer code has been updated.
      Signed-off-by: NAlexandre Courbot <acourbot@nvidia.com>
      Reviewed-by: NMark Brown <broonie@linaro.org>
      Signed-off-by: NLinus Walleij <linus.walleij@linaro.org>
      39b2bbe3
  30. 16 5月, 2014 1 次提交
  31. 09 5月, 2014 1 次提交
    • T
      gpio: Add helpers for optional GPIOs · 29a1f233
      Thierry Reding 提交于
      Introduce gpiod_get_optional() and gpiod_get_index_optional() helpers
      that make it easier for drivers to handle optional GPIOs.
      
      Currently in order to handle optional GPIOs, a driver needs to special
      case error handling for -ENOENT, such as this:
      
      	gpio = gpiod_get(dev, "foo");
      	if (IS_ERR(gpio)) {
      		if (PTR_ERR(gpio) != -ENOENT)
      			return PTR_ERR(gpio);
      
      		gpio = NULL;
      	}
      
      	if (gpio) {
      		/* set up GPIO */
      	}
      
      With these new helpers the above is reduced to:
      
      	gpio = gpiod_get_optional(dev, "foo");
      	if (IS_ERR(gpio))
      		return PTR_ERR(gpio);
      
      	if (gpio) {
      		/* set up GPIO */
      	}
      
      While at it, device-managed variants of these functions are also
      provided.
      Signed-off-by: NThierry Reding <treding@nvidia.com>
      Reviewed-by: NAlexandre Courbot <acourbot@nvidia.com>
      Signed-off-by: NLinus Walleij <linus.walleij@linaro.org>
      29a1f233
  32. 13 2月, 2014 1 次提交
  33. 07 2月, 2014 1 次提交
  34. 06 2月, 2014 1 次提交
  35. 20 10月, 2013 2 次提交