JIRA: https://issues.redhat.com/browse/RHEL-57766
commit 7e92061f1e9d1f6d3bfa6113719534f2c773b041
Author: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Date: Wed Jun 12 20:48:21 2024 +0200
gpiolib: put gpio_suffixes in a single compilation unit
The gpio_suffixes array is defined in the gpiolib.h header. This means
the array is stored in .rodata of every compilation unit that includes
it. Put the definition for the array in gpiolib.c and export just the
symbol in the header. We need the size of the array so expose it too.
Reviewed-by: Mika Westerberg <mika.westerberg@linux.intel.com>
Link: https://lore.kernel.org/r/20240612184821.58053-1-brgl@bgdev.pl
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Signed-off-by: Izabela Bakollari <ibakolla@redhat.com>
JIRA: https://issues.redhat.com/browse/RHEL-57766
commit 0d776cfd5e5b559fdf2e38285c2aea4b7048acbd
Author: Stephen Boyd <swboyd@chromium.org>
Date: Thu Feb 22 22:52:53 2024 -0800
gpiolib: Pass consumer device through to core in devm_fwnode_gpiod_get_index()
This devm API takes a consumer device as an argument to setup the devm
action, but throws it away when calling further into gpiolib. This leads
to odd debug messages like this:
(NULL device *): using DT '/gpio-keys/switch-pen-insert' for '(null)' GPIO lookup
Let's pass the consumer device down, by directly calling what
fwnode_gpiod_get_index() calls but pass the device used for devm. This
changes the message to look like this instead:
gpio-keys gpio-keys: using DT '/gpio-keys/switch-pen-insert' for '(null)' GPIO lookup
Note that callers of fwnode_gpiod_get_index() will still see the NULL
device pointer debug message, but there's not much we can do about that
because the API doesn't take a struct device.
Cc: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Fixes: 8eb1f71e7acc ("gpiolib: consolidate GPIO lookups")
Signed-off-by: Stephen Boyd <swboyd@chromium.org>
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Signed-off-by: Izabela Bakollari <ibakolla@redhat.com>
JIRA: https://issues.redhat.com/browse/RHEL-57766
commit f42dafe3da0cd887c9d2aaa59576f2a92ee4d876
Author: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Date: Sun Sep 3 21:06:57 2023 +0200
gpiolib: unexport gpiod_set_transitory()
There are no and never have been any users of gpiod_set_transitory()
outside the core GPIOLIB code. Make it private.
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Izabela Bakollari <ibakolla@redhat.com>
JIRA: https://issues.redhat.com/browse/RHEL-56213
CVE: CVE-2024-44931
commit d795848ecce24a75dfd46481aee066ae6fe39775
Author: Hagar Hemdan <hagarhem@amazon.com>
Date: Thu May 23 08:53:32 2024 +0000
gpio: prevent potential speculation leaks in gpio_device_get_desc()
Userspace may trigger a speculative read of an address outside the gpio
descriptor array.
Users can do that by calling gpio_ioctl() with an offset out of range.
Offset is copied from user and then used as an array index to get
the gpio descriptor without sanitization in gpio_device_get_desc().
This change ensures that the offset is sanitized by using
array_index_nospec() to mitigate any possibility of speculative
information leaks.
This bug was discovered and resolved using Coverity Static Analysis
Security Testing (SAST) by Synopsys, Inc.
Signed-off-by: Hagar Hemdan <hagarhem@amazon.com>
Link: https://lore.kernel.org/r/20240523085332.1801-1-hagarhem@amazon.com
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Signed-off-by: CKI Backport Bot <cki-ci-bot+cki-gitlab-backport-bot@redhat.com>
JIRA: https://issues.redhat.com/browse/RHEL-26354
commit ee25fba76acd8324f9de6628872c8c612a684209
Author: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Date: Mon Dec 4 10:35:00 2023 +0100
gpiolib: provide gpiochip_dup_line_label()
gpiochip_is_requested() not only has a misleading name but it returns
a pointer to a string that is freed when the descriptor is released.
Provide a new helper meant to replace it, which returns a copy of the
label string instead.
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Acked-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: David Arcari <darcari@redhat.com>
JIRA: https://issues.redhat.com/browse/RHEL-26354
commit d1f7728259ef02ac20b7afb6e7eb5a9eb1696c25
Author: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Date: Wed Nov 15 17:49:59 2023 +0100
gpiolib: provide gpio_device_get_label()
Provide a getter for the GPIO device label string so that users don't
have to dereference struct gpio_chip directly.
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Signed-off-by: David Arcari <darcari@redhat.com>
JIRA: https://issues.redhat.com/browse/RHEL-26354
commit 8c85a102fc4e5c0c942c10677fa43f7a19baa92f
Author: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Date: Tue Sep 5 20:52:55 2023 +0200
gpiolib: provide gpio_device_get_base()
Let's start adding getters for the opaque struct gpio_device. Start with
a function allowing to retrieve the base GPIO number.
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Acked-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: David Arcari <darcari@redhat.com>
JIRA: https://issues.redhat.com/browse/RHEL-26354
commit 370232d096e3fe188e4596f77bc6560636bd40c1
Author: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Date: Wed Oct 11 15:02:03 2023 +0200
gpiolib: provide gpiod_to_gpio_device()
Accessing struct gpio_chip backing a GPIO device is only allowed for the
actual providers of that chip.
Similarly to how we introduced gpio_device_find() in order to replace
the abused gpiochip_find(), let's introduce a counterpart to
gpiod_to_chip() that returns a reference to the GPIO device owning the
descriptor. This is done in order to later remove gpiod_to_chip()
entirely.
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Reviewed-by: Peter Rosin <peda@axentia.se>
Acked-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: David Arcari <darcari@redhat.com>
JIRA: https://issues.redhat.com/browse/RHEL-26354
commit 36aa129f221c9070afd8dff03154ab49702a5b1b
Author: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Date: Wed Sep 27 16:29:21 2023 +0200
gpiolib: make gpio_device_get() and gpio_device_put() public
In order to start migrating away from accessing struct gpio_chip by
users other than their owners, let's first make the reference management
functions for the opaque struct gpio_device public in the driver.h
header.
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: David Arcari <darcari@redhat.com>
JIRA: https://issues.redhat.com/browse/RHEL-26354
commit acf2981b84c344428baa10dbc9234749c68dedae
Author: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Date: Tue Oct 3 12:01:01 2023 +0200
treewide: rename pinctrl_gpio_set_config_new()
Now that pinctrl_gpio_set_config() is no longer used, let's drop the
'_new' suffix from its improved variant.
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Acked-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: David Arcari <darcari@redhat.com>
JIRA: https://issues.redhat.com/browse/RHEL-26354
Conflicts: limited to files that are supported in RHEL
commit 4fccb263f3a0dc07b306213930e0c25d1c9002b0
Author: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Date: Tue Oct 3 11:57:17 2023 +0200
treewide: rename pinctrl_gpio_free_new()
Now that pinctrl_gpio_free()() is no longer used, let's drop the '_new'
suffix from its improved variant.
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Acked-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: David Arcari <darcari@redhat.com>
JIRA: https://issues.redhat.com/browse/RHEL-26354
Conflicts: limited to files that are supported on RHEL
commit acb38be654f9af05fe626b37ea83e119cd310c3c
Author: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Date: Tue Oct 3 11:56:03 2023 +0200
treewide: rename pinctrl_gpio_request_new()
Now that pinctrl_gpio_request() is no longer used, let's drop the '_new'
suffix from its improved variant.
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Acked-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: David Arcari <darcari@redhat.com>
JIRA: https://issues.redhat.com/browse/RHEL-26354
commit e3d3ab299ba63c61776f3579d8a58c486eba5044
Author: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Date: Tue Oct 3 09:25:29 2023 +0200
gpiolib: generic: use new pinctrl GPIO helpers
Replace the pinctrl helpers taking the global GPIO number as argument
with the improved variants that instead take a pointer to the GPIO chip
and the controller-relative offset.
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
Acked-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: David Arcari <darcari@redhat.com>
JIRA: https://issues.redhat.com/browse/RHEL-946
commit 9ce4ed5b4db13633f9934a4eac02c4cde04d5c63
Author: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Date: Mon Aug 21 16:18:27 2023 +0200
gpiolib: provide and use gpiod_line_state_notify()
Wrap the calls to blocking_notifier_call_chain() for the line state
notifier with a helper that allows us to use fewer lines of code and
simpler syntax.
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Izabela Bakollari <ibakolla@redhat.com>
JIRA: https://issues.redhat.com/browse/RHEL-946
commit a067419ba77da830939852758702388f0fba09a1
Author: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Date: Thu Aug 17 13:59:05 2023 +0200
gpiolib: add a second blocking notifier to struct gpio_device
Add a new blocking notifier to struct gpio_device and use it to notify
subscribers about the GPIO device being unregistered from the device
model.
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
Reviewed-by: Kent Gibson <warthog618@gmail.com>
Signed-off-by: Izabela Bakollari <ibakolla@redhat.com>
JIRA: https://issues.redhat.com/browse/RHEL-946
commit 17a7ca35890b411414a71fbeef13cb65fe9511df
Author: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Date: Thu Aug 17 10:52:28 2023 +0200
gpiolib: rename the gpio_device notifier
Change the generic "notifier" name to "line_state_notifier" in order to
reflect its purpose in preparation for adding a second notifier which
will be used to notify wait queues about device unregistering.
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
Reviewed-by: Kent Gibson <warthog618@gmail.com>
Signed-off-by: Izabela Bakollari <ibakolla@redhat.com>
JIRA: https://issues.redhat.com/browse/RHEL-946
bgpio_init() uses "sz" argument to populate ngpio, which is not
accurate. Instead, read the "ngpios" property from the DT and if it
doesn't exist, use the "sz" argument. With this change, drivers no
longer need to overwrite the ngpio variable after calling bgpio_init().
If the "ngpios" property is specified, bgpio_bits is calculated
as the round up value of ngpio. At the moment, the only requirement
specified is that the round up value must be a multiple of 8 but
it should also be a power of 2 because we provide accessors based
on the bank size in bgpio_setup_accessors().
Signed-off-by: Asmaa Mnebhi <asmaa@nvidia.com>
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
(cherry picked from commit 55b2395e4e92adc492c6b30ac109eb78250dcd9d)
Signed-off-by: Izabela Bakollari <ibakolla@redhat.com>
Bugzilla: https://bugzilla.redhat.com/2183344
commit 7dd3d9bd873f138675cb727eaa51a498d99f0e89
Author: Andreas Kemnade <andreas@kemnade.info>
Date: Thu May 4 08:04:21 2023 +0200
gpiolib: fix allocation of mixed dynamic/static GPIOs
If static allocation and dynamic allocation GPIOs are present,
dynamic allocation pollutes the numberspace for static allocation,
causing static allocation to fail.
Enforce dynamic allocation above GPIO_DYNAMIC_BASE.
Seen on a GTA04 when omap-gpio (static) and twl-gpio (dynamic)
raced:
[some successful registrations of omap_gpio instances]
[ 2.553833] twl4030_gpio twl4030-gpio: gpio (irq 145) chaining IRQs 161..178
[ 2.561401] gpiochip_find_base: found new base at 160
[ 2.564392] gpio gpiochip5: (twl4030): added GPIO chardev (254:5)
[ 2.564544] gpio gpiochip5: registered GPIOs 160 to 177 on twl4030
[...]
[ 2.692169] omap-gpmc 6e000000.gpmc: GPMC revision 5.0
[ 2.697357] gpmc_mem_init: disabling cs 0 mapped at 0x0-0x1000000
[ 2.703643] gpiochip_find_base: found new base at 178
[ 2.704376] gpio gpiochip6: (omap-gpmc): added GPIO chardev (254:6)
[ 2.704589] gpio gpiochip6: registered GPIOs 178 to 181 on omap-gpmc
[...]
[ 2.840393] gpio gpiochip7: Static allocation of GPIO base is deprecated, use dynamic allocation.
[ 2.849365] gpio gpiochip7: (gpio-160-191): GPIO integer space overlap, cannot add chip
[ 2.857513] gpiochip_add_data_with_key: GPIOs 160..191 (gpio-160-191) failed to register, -16
[ 2.866149] omap_gpio 48310000.gpio: error -EBUSY: Could not register gpio chip
On that device it is fixed invasively by
commit 92bf78b33b0b4 ("gpio: omap: use dynamic allocation of base")
but let's also fix that for devices where there is still
a mixture of static and dynamic allocation.
Fixes: 7b61212f2a07 ("gpiolib: Get rid of ARCH_NR_GPIOS")
Signed-off-by: Andreas Kemnade <andreas@kemnade.info>
Reviewed-by: <christophe.leroy@csgroup.eu>
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Signed-off-by: Shaoqin Huang <shahuang@redhat.com>
Bugzilla: https://bugzilla.redhat.com/2183344
commit 8a4adcf67a39b3f308bb8cf686e41c0e26aa12e8
Author: Linus Walleij <linus.walleij@linaro.org>
Date: Tue Apr 11 10:28:06 2023 +0200
gpio: gpiolib: Simplify gpiochip_add_data_with_key() fwnode
The code defaulting to the parents fwnode if no fwnode was assigned
is unnecessarily convoluted, probably due to refactoring. Simplify
it and make it more human-readable.
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Reviewed-by: Anders Roxell <anders.roxell@linaro.org>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Signed-off-by: Shaoqin Huang <shahuang@redhat.com>
Bugzilla: https://bugzilla.redhat.com/2183344
commit 7b59bdbc3965ca8add53e084af394c13a2be22a8
Author: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Date: Tue Mar 21 15:53:32 2023 +0200
gpiolib: Add gpiochip_set_data() helper
There are too many 'data' parameters here and there.
For the better maintenance keep access GPIO device data
via getter and setter.
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Signed-off-by: Shaoqin Huang <shahuang@redhat.com>
Bugzilla: https://bugzilla.redhat.com/2183344
commit 8deb779d36cb86c1c1c37d767317f5899b32fc76
Author: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Date: Tue Mar 21 15:53:31 2023 +0200
gpiolib: Move gpiochip_get_data() higher in the code
Move gpiochip_get_data() higher in the code as a preparation
for further refactoring.
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
[Bartosz: tweak the commit message]
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Signed-off-by: Shaoqin Huang <shahuang@redhat.com>
Bugzilla: https://bugzilla.redhat.com/2183344
commit 4ea0c97776bf8c63805eb0f8182d9c20072219d9
Author: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Date: Tue Mar 21 15:54:12 2023 +0200
gpiolib: Check array_info for NULL only once in gpiod_get_array()
gpiod_get_array() has a long if-else-if branching where each of them
tests for the same variable to be not NULL. Instead, check for NULL
before even going to that flow.
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Signed-off-by: Shaoqin Huang <shahuang@redhat.com>
Bugzilla: https://bugzilla.redhat.com/2183344
commit 79736429c97f517247645e73e75c956efd09ad03
Author: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Date: Tue Mar 21 15:54:11 2023 +0200
gpiolib: Replace open coded krealloc()
gpiod_get_array() does a new allocation in some cases, followed
by copying previously allocated placeholder for the descriptors.
Replace that with krealloc(__GFP_ZERO), since it was kzalloc()
originally.
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Signed-off-by: Shaoqin Huang <shahuang@redhat.com>
Bugzilla: https://bugzilla.redhat.com/2183344
commit db4064cc108214bf0912b89c7e660c7d9d6bba1d
Author: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Date: Thu Mar 9 20:58:19 2023 +0200
gpiolib: Use IRQ hardware number getter instead of direct access
IRQ framework provides special type and getter to transform
the Linux IRQ to the hardware pin. Use that type and getter
function instead of direct access.
While at it, amend an indentation in a couple of places.
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Signed-off-by: Shaoqin Huang <shahuang@redhat.com>
Bugzilla: https://bugzilla.redhat.com/2183344
commit c122f461ccac0e78e8e45d4f6de14e58942572f6
Author: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Date: Thu Mar 9 20:56:26 2023 +0200
gpiolib: Remove duplicative check in gpiod_find_and_request()
The gpiod_find_by_fwnode() already checks for NULL and returns
correct error code in case fwnode is invalid. Drop the respective
check and assignment in the gpiod_find_and_request().
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Signed-off-by: Shaoqin Huang <shahuang@redhat.com>
Bugzilla: https://bugzilla.redhat.com/2183344
commit 7aa90f9055c16c79c0ad174c726f95723d122fe6
Author: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Date: Tue Mar 7 20:25:57 2023 +0200
gpiolib: Move gpiodevice_*() to gpiodev namespace
The functions that operates on the same device object would
have the same namespace for better code understanding and
maintenance.
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Signed-off-by: Shaoqin Huang <shahuang@redhat.com>
Bugzilla: https://bugzilla.redhat.com/2183344
commit 0c5ebb4c03308c0a544b5c1e0a33f0a63c40bc7e
Author: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Date: Thu Mar 9 20:56:00 2023 +0200
gpiolib: Get rid of devprop prefix in one function
The devprop prefix in the devprop_gpiochip_set_names() adds confusion.
Get rid of it.
Note we have more than one function in the same module that handles
one or more device properties. This change will unify the naming schema
for all of them.
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Signed-off-by: Shaoqin Huang <shahuang@redhat.com>
Bugzilla: https://bugzilla.redhat.com/2183344
commit c135f401265ae1b8b15c8fd607a4a113c61d79f8
Author: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Date: Tue Mar 7 20:25:56 2023 +0200
gpiolib: Get rid of gpio_bus_match() forward declaration
There is nothing specific about gpio_bus_match(), so we may
simply move it to the top of the file and get rid of forward
declaration.
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Signed-off-by: Shaoqin Huang <shahuang@redhat.com>
Bugzilla: https://bugzilla.redhat.com/2183344
commit 380c7ba3923c6e471aff0f951a6cf42e8dec2c79
Author: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Date: Wed Feb 8 19:07:28 2023 +0200
gpiolib: Clean up headers
There is a few things done:
- include only the headers we are direct user of
- when pointer is in use, provide a forward declaration
- add missing headers
- group generic headers and subsystem headers
- sort each group alphabetically
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Shaoqin Huang <shahuang@redhat.com>
Bugzilla: https://bugzilla.redhat.com/2183344
commit 38dfa56b3db354b4bd399fc686c3e74ad32ffa57
Author: Saravana Kannan <saravanak@google.com>
Date: Mon Feb 6 17:41:56 2023 -0800
gpiolib: Clear the gpio_device's fwnode initialized flag before adding
Registering an irqdomain sets the flag for the fwnode. But having the
flag set when a device is added is interpreted by fw_devlink to mean the
device has already been initialized and will never probe. This prevents
fw_devlink from creating device links with the gpio_device as a
supplier. So, clear the flag before adding the device.
Signed-off-by: Saravana Kannan <saravanak@google.com>
Acked-by: Bartosz Golaszewski <brgl@bgdev.pl>
Tested-by: Colin Foster <colin.foster@in-advantage.com>
Tested-by: Sudeep Holla <sudeep.holla@arm.com>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Tested-by: Douglas Anderson <dianders@chromium.org>
Tested-by: Geert Uytterhoeven <geert+renesas@glider.be>
Tested-by: Luca Weiss <luca.weiss@fairphone.com> # qcom/sm7225-fairphone-fp4
Link: https://lore.kernel.org/r/20230207014207.1678715-5-saravanak@google.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Shaoqin Huang <shahuang@redhat.com>
Bugzilla: https://bugzilla.redhat.com/2183344
commit 70d0fc4288dabd65025fde7774b4f9262afa9034
Author: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Date: Wed Dec 28 11:20:44 2022 +0200
gpiolib: Get rid of not used of_node member
All new drivers should use fwnode and / or parent to provide the
necessary information to the GPIO library.
Cc: Thierry Reding <treding@nvidia.com>
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Signed-off-by: Shaoqin Huang <shahuang@redhat.com>
Bugzilla: https://bugzilla.redhat.com/2183344
commit 908334ab0be334cd268e2bf6a2384e7f5ffd4aa2
Author: Johan Hovold <johan+linaro@kernel.org>
Date: Tue Dec 13 14:52:27 2022 +0100
gpiolib: use irq_domain_alloc_irqs()
Use the irq_domain_alloc_irqs() wrapper instead of the full
__irq_domain_alloc_irqs() interface, which was only intended for some
legacy (x86) use cases.
Signed-off-by: Johan Hovold <johan+linaro@kernel.org>
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Signed-off-by: Shaoqin Huang <shahuang@redhat.com>
Bugzilla: https://bugzilla.redhat.com/2183344
commit c40aa80dd4569848ac89454321fa035a6ca26976
Author: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Date: Fri Jan 13 23:53:49 2023 +0200
gpiolib: Check "gpio-ranges" before calling ->add_pin_ranges()
The ->add_pin_ranges() is supposed to be called for the backward
compatiblity on Device Tree platforms or non-DT ones. Ensure that
by checking presense of the "gpio-ranges" property.
This allows to clean up a few existing drivers to avoid duplication
of the check.
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Tested-by: Stefan Wahren <stefan.wahren@i2se.com>
Tested-by: Florian Fainelli <f.fainelli@gmail.com>
Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
Acked-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Link: https://lore.kernel.org/r/20230113215352.44272-2-andriy.shevchenko@linux.intel.com
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Shaoqin Huang <shahuang@redhat.com>
Bugzilla: https://bugzilla.redhat.com/2183344
commit ba2dc1cb5491712a6946d0595cf11ba463f50e64
Author: Hans de Goede <hdegoede@redhat.com>
Date: Thu Dec 29 17:45:01 2022 +0100
gpiolib: Fix using uninitialized lookup-flags on ACPI platforms
Commit 8eb1f71e7acc ("gpiolib: consolidate GPIO lookups") refactors
fwnode_get_named_gpiod() and gpiod_get_index() into a unified
gpiod_find_and_request() helper.
The old functions both initialized their local lookupflags variable to
GPIO_LOOKUP_FLAGS_DEFAULT, but the new code leaves it uninitialized.
This is a problem for at least ACPI platforms, where acpi_find_gpio()
only does a bunch of *lookupflags |= GPIO_* statements and thus relies
on the variable being initialized.
The variable not being initialized leads to:
1. Potentially the wrong flags getting used
2. The check for conflicting lookup flags in gpiod_configure_flags():
"multiple pull-up, pull-down or pull-disable enabled, invalid config"
sometimes triggering, making the GPIO unavailable
Restore the initialization of lookupflags to GPIO_LOOKUP_FLAGS_DEFAULT
to fix this.
Fixes: 8eb1f71e7acc ("gpiolib: consolidate GPIO lookups")
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Signed-off-by: Shaoqin Huang <shahuang@redhat.com>
Bugzilla: https://bugzilla.redhat.com/2183344
commit bdbbae241a04f387ba910b8609f95fad5f1470c7
Author: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Date: Mon Dec 5 13:39:03 2022 +0100
gpiolib: protect the GPIO device against being dropped while in use by user-space
While any of the GPIO cdev syscalls is in progress, the kernel can call
gpiochip_remove() (for instance, when a USB GPIO expander is disconnected)
which will set gdev->chip to NULL after which any subsequent access will
cause a crash.
To avoid that: use an RW-semaphore in which the syscalls take it for
reading (so that we don't needlessly prohibit the user-space from calling
syscalls simultaneously) while gpiochip_remove() takes it for writing so
that it can only happen once all syscalls return.
Fixes: d7c51b47ac ("gpio: userspace ABI for reading/writing GPIO lines")
Fixes: 3c0d9c635a ("gpiolib: cdev: support GPIO_V2_GET_LINE_IOCTL and GPIO_V2_LINE_GET_VALUES_IOCTL")
Fixes: aad955842d ("gpiolib: cdev: support GPIO_V2_GET_LINEINFO_IOCTL and GPIO_V2_GET_LINEINFO_WATCH_IOCTL")
Fixes: a54756cb24 ("gpiolib: cdev: support GPIO_V2_LINE_SET_CONFIG_IOCTL")
Fixes: 7b8e00d981 ("gpiolib: cdev: support GPIO_V2_LINE_SET_VALUES_IOCTL")
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
[Nick: fixed a build failure with CDEV_V1 disabled]
Co-authored-by: Nick Hainke <vincent@systemli.org>
Reviewed-by: Kent Gibson <warthog618@gmail.com>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Shaoqin Huang <shahuang@redhat.com>
Bugzilla: https://bugzilla.redhat.com/2183344
commit 3b7c7478eda00945987d45f902bc3942c89243d3
Author: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Date: Mon Nov 28 21:00:54 2022 +0200
gpiolib: Provide to_gpio_device() helper
Provide to_gpio_device() helper which can be utilized in the existing
and future code.
While at it, make sure it becomes no-op at compilation time.
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Signed-off-by: Shaoqin Huang <shahuang@redhat.com>
Bugzilla: https://bugzilla.redhat.com/2183344
commit 4ef339bc053a62dac9017f80f7bb8cff0412bd29
Author: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Date: Wed Nov 16 16:17:28 2022 +0200
gpiolib: Unify access to the device properties
Some of the functions are using struct fwnode_handle, some struct device
pointer. In the GPIO library the firmware node of the GPIO device is the
same as GPIO node of the GPIO chip. Due to this fact we may use former
to access properties everywhere in the code.
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Reviewed-by: Brian Masney <bmasney@redhat.com>
Tested-by: Marijn Suijten <marijn.suijten@somainline.org>
[Bartosz: stick to the 80-char limit where it's not hurting readability]
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Signed-off-by: Shaoqin Huang <shahuang@redhat.com>
Bugzilla: https://bugzilla.redhat.com/2183344
commit ec851b23084b3a0af8bf0f5e51d33a8d678bdc49
Author: Zeng Heng <zengheng4@huawei.com>
Date: Fri Nov 25 22:07:57 2022 +0100
gpiolib: fix memory leak in gpiochip_setup_dev()
Here is a backtrace report about memory leak detected in
gpiochip_setup_dev():
unreferenced object 0xffff88810b406400 (size 512):
comm "python3", pid 1682, jiffies 4295346908 (age 24.090s)
backtrace:
kmalloc_trace
device_add device_private_init at drivers/base/core.c:3361
(inlined by) device_add at drivers/base/core.c:3411
cdev_device_add
gpiolib_cdev_register
gpiochip_setup_dev
gpiochip_add_data_with_key
gcdev_register() & gcdev_unregister() would call device_add() &
device_del() (no matter CONFIG_GPIO_CDEV is enabled or not) to
register/unregister device.
However, if device_add() succeeds, some resource (like
struct device_private allocated by device_private_init())
is not released by device_del().
Therefore, after device_add() succeeds by gcdev_register(), it
needs to call put_device() to release resource in the error handle
path.
Here we move forward the register of release function, and let it
release every piece of resource by put_device() instead of kfree().
While at it, fix another subtle issue, i.e. when gc->ngpio is equal
to 0, we still call kcalloc() and, in case of further error, kfree()
on the ZERO_PTR pointer, which is not NULL. It's not a bug per se,
but rather waste of the resources and potentially wrong expectation
about contents of the gdev->descs variable.
Fixes: 159f3cd92f ("gpiolib: Defer gpio device setup until after gpiolib initialization")
Signed-off-by: Zeng Heng <zengheng4@huawei.com>
Co-developed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Signed-off-by: Shaoqin Huang <shahuang@redhat.com>
Bugzilla: https://bugzilla.redhat.com/2183344
commit 24c94060fc9b4e0f19e6e018869db46db21d6bc7
Author: Brian Masney <bmasney@redhat.com>
Date: Mon Nov 14 15:29:43 2022 -0500
gpiolib: ensure that fwnode is properly set
Note that this is a RFC patch and not meant to be merged. I looked into
a problem with linux-next-20221110 on the Qualcomm SA8540P automotive
board (sc8280xp) where the UFS host controller would fail to probe due
to repeated probe deferrals when trying to get reset-gpios via
devm_gpiod_get_optional().
of_get_named_gpiod_flags() returns -EPROBE_DEFER, which is caused by
of_gpiochip_match_node_and_xlate() returning 0 since the of_xlate function
pointer is not set for the qcom,sc8280xp-tlmm pinctrl driver. The
pinctrl driver doesn't define one, so of_gpiochip_add() should
automatically setup of_gpio_simple_xlate() on it's behalf. This doesn't
happen since the fwnode member on the struct gpiochip is set to null
when of_gpiochip_add() is called. Let's work around this by ensuring
that it's set if available.
Note that this broke sometime within the last few weeks within
linux-next and I haven't bisected this. I'm posting this in the hopes
that someone may know offhand which patch(es) may have broken this.
Signed-off-by: Brian Masney <bmasney@redhat.com>
Tested-by: Marijn Suijten <marijn.suijten@somainline.org>
Tested-by: Konrad Dybcio <konrad.dybcio@linaro.org>
Tested-by: Steev Klimaszewski <steev@kali.org> #Lenovo Thinkpad X13s
Tested-by: Neil Armstrong <neil.armstrong@linaro.org>
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Signed-off-by: Shaoqin Huang <shahuang@redhat.com>
Bugzilla: https://bugzilla.redhat.com/2183344
commit e7f9ff5dc90c3826231343439c35c6b7e9e57378
Author: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Date: Fri Nov 11 14:19:08 2022 -0800
gpiolib: add support for software nodes
Now that static device properties understand notion of child nodes and
references, let's teach gpiolib to handle them:
- GPIOs are represented as a references to software nodes representing
gpiochip
- references must have 2 arguments - GPIO number within the chip and
GPIO flags (GPIO_ACTIVE_LOW/GPIO_ACTIVE_HIGH, etc)
- a new PROPERTY_ENTRY_GPIO() macro is supplied to ensure the above
- name of the software node representing gpiochip must match label of
the gpiochip, as we use it to locate gpiochip structure at runtime
The following illustrates use of software nodes to describe a "System"
button that is currently specified via use of gpio_keys_platform_data
in arch/mips/alchemy/board-mtx1.c. It follows bindings specified in
Documentation/devicetree/bindings/input/gpio-keys.yaml.
static const struct software_node mxt1_gpiochip2_node = {
.name = "alchemy-gpio2",
};
static const struct property_entry mtx1_gpio_button_props[] = {
PROPERTY_ENTRY_U32("linux,code", BTN_0),
PROPERTY_ENTRY_STRING("label", "System button"),
PROPERTY_ENTRY_GPIO("gpios", &mxt1_gpiochip2_node, 7, GPIO_ACTIVE_LOW),
{ }
};
Similarly, arch/arm/mach-tegra/board-paz00.c can be converted to:
static const struct software_node tegra_gpiochip_node = {
.name = "tegra-gpio",
};
static struct property_entry wifi_rfkill_prop[] __initdata = {
PROPERTY_ENTRY_STRING("name", "wifi_rfkill"),
PROPERTY_ENTRY_STRING("type", "wlan"),
PROPERTY_ENTRY_GPIO("reset-gpios",
&tegra_gpiochip_node, 25, GPIO_ACTIVE_HIGH);
PROPERTY_ENTRY_GPIO("shutdown-gpios",
&tegra_gpiochip_node, 85, GPIO_ACTIVE_HIGH);
{ },
};
static struct platform_device wifi_rfkill_device = {
.name = "rfkill_gpio",
.id = -1,
};
...
software_node_register(&tegra_gpiochip_node);
device_create_managed_software_node(&wifi_rfkill_device.dev,
wifi_rfkill_prop, NULL);
Acked-by: Linus Walleij <linus.walleij@linaro.org>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Signed-off-by: Shaoqin Huang <shahuang@redhat.com>
Bugzilla: https://bugzilla.redhat.com/2183344
commit 8eb1f71e7acca4f92cf9cf83030cbb8ec2524025
Author: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Date: Fri Nov 11 14:19:07 2022 -0800
gpiolib: consolidate GPIO lookups
Ensure that all paths to obtain/look up GPIOD from generic
consumer-visible APIs go through the new gpiod_find_and_request()
helper, so that we can easily extend it with support for new firmware
mechanisms.
The only exception is OF-specific [devm_]gpiod_get_from_of_node() API
that is still being used by a couple of drivers and will be removed as
soon as patches converting them to use generic fwnode/device APIs are
accepted.
Acked-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Signed-off-by: Shaoqin Huang <shahuang@redhat.com>
Bugzilla: https://bugzilla.redhat.com/2183344
commit b7452d670fdef8974e18754342fe6f68e20c2567
Author: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Date: Tue Nov 15 11:20:47 2022 +0100
gpiolib: acpi: avoid leaking ACPI details into upper gpiolib layers
There is no need for the generic parts of GPIOLIB to be aware of
implementation details of ACPI-bases lookups.
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Acked-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Signed-off-by: Shaoqin Huang <shahuang@redhat.com>
Bugzilla: https://bugzilla.redhat.com/2183344
commit 2b6bce80ae70b91134a5731d85076042ae90c300
Author: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Date: Fri Nov 11 14:19:04 2022 -0800
gpiolib: acpi: change acpi_find_gpio() to accept firmware node
In preparation of switching all ACPI-based GPIO lookups to go through
acpi_find_gpio() let's change it to accept device node as its argument
as we do not always have access to device structure.
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Acked-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Signed-off-by: Shaoqin Huang <shahuang@redhat.com>
Bugzilla: https://bugzilla.redhat.com/2183344
commit 07445ae1c26367928311e13f2a821ae94410da7e
Author: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Date: Tue Nov 15 11:16:24 2022 +0100
gpiolib: of: change of_find_gpio() to accept device node
In preparation of switching all OF-based GPIO lookups to go through
of_find_gpio() let's change it to accept device node as its argument as
we do not always have access to device structure.
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Acked-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Signed-off-by: Shaoqin Huang <shahuang@redhat.com>
Bugzilla: https://bugzilla.redhat.com/2183344
Conflicts:
arch/arm/include/asm/gpio.h
Contextual conflict due to lack of upstream commit 6fec92d9b2bf.
6fec92d9b2bf ("ARM: 9103/1: Drop ARCH_NR_GPIOS definition")
commit 7b61212f2a07a5afd213c8876e52b5c9946441e2
Author: Christophe Leroy <christophe.leroy@csgroup.eu>
Date: Fri Sep 2 14:42:05 2022 +0200
gpiolib: Get rid of ARCH_NR_GPIOS
Since commit 14e85c0e69 ("gpio: remove gpio_descs global array")
there is no limitation on the number of GPIOs that can be allocated
in the system since the allocation is fully dynamic.
ARCH_NR_GPIOS is today only used in order to provide downwards
gpiobase allocation from that value, while static allocation is
performed upwards from 0. However that has the disadvantage of
limiting the number of GPIOs that can be registered in the system.
To overcome this limitation without requiring each and every
platform to provide its 'best-guess' maximum number, rework the
allocation to allocate upwards, allowing approx 2 millions of
GPIOs.
In order to still allow static allocation for legacy drivers, define
GPIO_DYNAMIC_BASE with the value 512 as the start for dynamic
allocation. The 512 value is chosen because it is the end of
the current default range so all current static allocations are
expected to be below that value. Of course that's just a rough
estimate based on the default value, but assuming static
allocations come first, even if there are more static allocations
it should fit under the 512 value.
In the future, it is expected that all static allocations go away
and then dynamic allocation will be patched to start at 0.
Signed-off-by: Christophe Leroy <christophe.leroy@csgroup.eu>
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Signed-off-by: Shaoqin Huang <shahuang@redhat.com>
Bugzilla: https://bugzilla.redhat.com/2183344
commit 502df79b860563d79143be7a1453c2b3224cd836
Author: Christophe Leroy <christophe.leroy@csgroup.eu>
Date: Fri Sep 2 14:42:04 2022 +0200
gpiolib: Warn on drivers still using static gpiobase allocation
In the preparation of getting completely rid of static gpiobase
allocation in the future, emit a warning in drivers still doing so.
Signed-off-by: Christophe Leroy <christophe.leroy@csgroup.eu>
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Signed-off-by: Shaoqin Huang <shahuang@redhat.com>