Commit graph

5886 commits

Author SHA1 Message Date
Stephen Boyd
57662cd437 gpiolib: Pass consumer device through to core in devm_fwnode_gpiod_get_index()
[ Upstream commit 0d776cfd5e ]

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: 8eb1f71e7a ("gpiolib: consolidate GPIO lookups")
Signed-off-by: Stephen Boyd <swboyd@chromium.org>
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2024-03-26 18:16:50 -04:00
Martin Kaiser
e4d29fecee gpio: vf610: allow disabling the vf610 driver
[ Upstream commit f575957882 ]

The vf610 gpio driver is enabled by default for all i.MX machines,
without any option to disable it in a board-specific config file.

Most i.MX chipsets have no hardware for this driver. Change the default
to enable GPIO_VF610 for SOC_VF610 and disable it otherwise.

Add a text description after the bool type, this makes the driver
selectable by make config etc.

Fixes: 30a35c07d9 ("gpio: vf610: drop the SOC_VF610 dependency for GPIO_VF610")
Signed-off-by: Martin Kaiser <martin@kaiser.cx>
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2024-03-26 18:16:37 -04:00
Bartosz Golaszewski
ec5c54a9d3 gpio: fix resource unwinding order in error path
Hogs are added *after* ACPI so should be removed *before* in error path.

Fixes: a411e81e61 ("gpiolib: add hogs support for machine code")
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
2024-03-01 09:33:30 +01:00
Andy Shevchenko
e4aec4daa8 gpiolib: Fix the error path order in gpiochip_add_data_with_key()
After shuffling the code, error path wasn't updated correctly.
Fix it here.

Fixes: 2f4133bb5f ("gpiolib: No need to call gpiochip_remove_pin_ranges() twice")
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2024-03-01 08:36:53 +01:00
Arturas Moskvinas
530b1dbd97 gpio: 74x164: Enable output pins after registers are reset
Chip outputs are enabled[1] before actual reset is performed[2] which might
cause pin output value to flip flop if previous pin value was set to 1.
Fix that behavior by making sure chip is fully reset before all outputs are
enabled.

Flip-flop can be noticed when module is removed and inserted again and one of
the pins was changed to 1 before removal. 100 microsecond flipping is
noticeable on oscilloscope (100khz SPI bus).

For a properly reset chip - output is enabled around 100 microseconds (on 100khz
SPI bus) later during probing process hence should be irrelevant behavioral
change.

Fixes: 7ebc194d0f (gpio: 74x164: Introduce 'enable-gpios' property)
Link: https://elixir.bootlin.com/linux/v6.7.4/source/drivers/gpio/gpio-74x164.c#L130 [1]
Link: https://elixir.bootlin.com/linux/v6.7.4/source/drivers/gpio/gpio-74x164.c#L150 [2]
Signed-off-by: Arturas Moskvinas <arturas.moskvinas@gmail.com>
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2024-03-01 08:23:08 +01:00
Emil Renner Berthing
ae366ba857 gpiolib: Handle no pin_ranges in gpiochip_generic_config()
Similar to gpiochip_generic_request() and gpiochip_generic_free() the
gpiochip_generic_config() function needs to handle the case where there
are no pinctrl pins mapped to the GPIOs, usually through the gpio-ranges
device tree property.

Commit f34fd6ee1b ("gpio: dwapb: Use generic request, free and
set_config") set the .set_config callback to gpiochip_generic_config()
in the dwapb GPIO driver so the GPIO API can set pinctrl configuration
for the corresponding pins. Most boards using the dwapb driver do not
set the gpio-ranges device tree property though, and in this case
gpiochip_generic_config() would return -EPROPE_DEFER rather than the
previous -ENOTSUPP return value. This in turn makes
gpio_set_config_with_argument_optional() fail and propagate the error to
any driver requesting GPIOs.

Fixes: 2956b5d94a ("pinctrl / gpio: Introduce .set_config() callback for GPIO chips")
Reported-by: Jisheng Zhang <jszhang@kernel.org>
Closes: https://lore.kernel.org/linux-gpio/ZdC_g3U4l0CJIWzh@xhacker/
Tested-by: Jisheng Zhang <jszhang@kernel.org>
Signed-off-by: Emil Renner Berthing <emil.renner.berthing@canonical.com>
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2024-02-20 12:49:14 +01:00
Bartosz Golaszewski
2526dffc6d gpio: remove GPIO device from the list unconditionally in error path
Since commit 48e1b4d369 ("gpiolib: remove the GPIO device from the list
when it's unregistered") we remove the GPIO device entry from the global
list (used to order devices by their GPIO ranges) when unregistering the
chip, not when releasing the device. It will not happen when the last
reference is put anymore. This means, we need to remove it in error path
in gpiochip_add_data_with_key() unconditionally, without checking if the
device's .release() callback is set.

Fixes: 48e1b4d369 ("gpiolib: remove the GPIO device from the list when it's unregistered")
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2024-02-08 10:33:03 +01:00
Wenhua Lin
84aef4ed59 gpio: eic-sprd: Clear interrupt after set the interrupt type
The raw interrupt status of eic maybe set before the interrupt is enabled,
since the eic interrupt has a latch function, which would trigger the
interrupt event once enabled it from user side. To solve this problem,
interrupts generated before setting the interrupt trigger type are ignored.

Fixes: 25518e024e ("gpio: Add Spreadtrum EIC driver support")
Acked-by: Chunyan Zhang <zhang.lyra@gmail.com>
Signed-off-by: Wenhua Lin <Wenhua.Lin@unisoc.com>
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2024-01-22 11:38:08 +01:00
Mario Limonciello
805c74eac8 gpiolib: acpi: Ignore touchpad wakeup on GPD G1619-04
Spurious wakeups are reported on the GPD G1619-04 which
can be absolved by programming the GPIO to ignore wakeups.

Cc: stable@vger.kernel.org
Reported-and-tested-by: George Melikov <mail@gmelikov.ru>
Closes: https://gitlab.freedesktop.org/drm/amd/-/issues/3073
Signed-off-by: Mario Limonciello <mario.limonciello@amd.com>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2024-01-22 10:05:44 +01:00
Linus Torvalds
3455135839 gpio fixes for v6.8-rc1
- revert the changes aiming to use a read-write semaphore to protect the
   list of GPIO devices due to calls to legacy API taking that lock from
   atomic context in old code
 - fix inverted logic in DEFINE_FREE() for GPIO device references
 - check the return value of bgpio_init() in gpio-mlxbf3
 - fix node address in the DT bindings example for gpio-xilinx
 - fix signedness bug in gpio-rtd
 - fix kernel-doc warnings in gpio-en7523
 -----BEGIN PGP SIGNATURE-----
 
 iQIzBAABCgAdFiEEFp3rbAvDxGAT0sefEacuoBRx13IFAmWpGfgACgkQEacuoBRx
 13K92A//TonLW0SmSJ5OM0jn9pqUhYLsSxbknu9M9RVmX+GTIq9YK+S5SiCbRS50
 rXn4q3WSqbocM+9R0MUlJJJK8UkGT+JU330vPlJl4gZAy0bK8aoeOqg7vb7nY12e
 0/PvroMpTHoBEIp5XloK4Wjxp3dnc1mGfozSJ7af9FXuY9i1cv8KhnrI8krKbszr
 quuWlZRrtMxKeR3FnsZVn8WNvEWqB5gAN1QJrX0h4sOe0/ZFVfdpZaCW4j1YZtux
 aF6d/9XyEnoR/yJpAE/Rt5Wy727RkilRvSiihnijnJd5JqdMU89CdXdgUF2oFOZ6
 rTAh6XrXiJaaAst4H+5rRe37PR0FOBEAwY1pWUlk9caikfPujNhzPmjvXbdAW7N9
 xe8J+2hTxYfOPYPNtSD/yjcWOudgOb8iiaRREWcRzR96vX/K6R94nF/8hOOEnm+F
 q/xbon1Rt8zhtjZ5lylGsmKoBlKDHlch+c3BXSBf4AxahMNgkebgx8pbkl3jUfg8
 30k+Z5wl08t7oRgeydBKfw7Y42LElBMqAFikjEK8ACyhEGC/e5XD8H0xlWGaKqU5
 sGhd5VS5Y2BQjsrpWkpdQGyOGquz86z5AjwDAAQp3nLgCNrs1UJ8imMPn5c2MPXl
 JAQhMg+zM1NlUhLrXwChYpQ08vypgFUsbGVQ+SDnEbFUo9DbHpg=
 =g2QY
 -----END PGP SIGNATURE-----

Merge tag 'gpio-fixes-for-v6.8-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/brgl/linux

Pull gpio fixes from Bartosz Golaszewski:
 "Apart from some regular driver fixes there's a relatively big revert
  of the locking changes that were introduced to GPIOLIB in this merge
  window.

  This is because it turned out that some legacy GPIO interfaces - that
  need to translate a number from the global GPIO numberspace to the
  address of the relevant descriptor, thus running a GPIO device lookup
  and taking the GPIO device list lock - are still used in old code from
  atomic context resulting in "scheduling while atomic" errors.

  I'll try to make the read-only part of the list access entirely
  lockless using SRCU but this will take some time so let's go back to
  the old global spinlock for now.

  Summary:

   - revert the changes aiming to use a read-write semaphore to protect
     the list of GPIO devices due to calls to legacy API taking that
     lock from atomic context in old code

   - fix inverted logic in DEFINE_FREE() for GPIO device references

   - check the return value of bgpio_init() in gpio-mlxbf3

   - fix node address in the DT bindings example for gpio-xilinx

   - fix signedness bug in gpio-rtd

   - fix kernel-doc warnings in gpio-en7523"

* tag 'gpio-fixes-for-v6.8-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/brgl/linux:
  gpiolib: revert the attempt to protect the GPIO device list with an rwsem
  gpio: EN7523: fix kernel-doc warnings
  gpiolib: Fix scope-based gpio_device refcounting
  gpio: mlxbf3: add an error code check in mlxbf3_gpio_probe
  dt-bindings: gpio: xilinx: Fix node address in gpio
  gpio: rtd: Fix signedness bug in probe
2024-01-18 17:03:51 -08:00
Linus Torvalds
21c91bb936 - New Drivers
- Add support for Monolithic Power Systems MP3309C WLED Step-up Converter
 
  - Fix-ups
    - Use/convert to new/better APIs/helpers/MACROs instead of hand-rolling implementations
    - Device Tree Binding updates
    - Demote non-kerneldoc header comments
    - Improve error handling; return proper error values, simplify, avoid duplicates, etc
    - Convert over to the new (kinda) GPIOD API
 
  - Bug Fixes
    - Fix uninitialised local variable
 -----BEGIN PGP SIGNATURE-----
 
 iQIzBAABCgAdFiEEdrbJNaO+IJqU8IdIUa+KL4f8d2EFAmWmsY8ACgkQUa+KL4f8
 d2E+PQ/+LP2TiwChRYvz5jKA0ys4N4yR63dQU1s9dcp49D3RjMLgokevDjSswVEJ
 vGlSc3Ld50cuT6oLObI7z/ezK9/QMJ7yMFraSy+QnTOit8xdDAfJAgC6cM8GGoFU
 XKLT4JkkNyhc2NypHKG/hRkMMA6EoBPr+wZTBRpQvbbFOkalTDVtcQNUgsYNr4W6
 0fPT97oKgAmvzK/2KaihmfxtTE0vXon5XyZVpnTu28bqXQbQvbOgzKr5KWom022Y
 XxoMVUaobZn0v/WUC1KqPY1N0tM+xH2PoOD+4jss26oV0TyxYWH9nDorF46gcJpk
 CQkp5jCCra/WHR50fJx7y01GVswfKCNp2fjx9aRnhFsWfW9cu2Kdws3GfGRazPSW
 AN9MJ9Eyv9Xu689hcq0wYZspfMeJe7fyDdEyeUWHCD8mF4BZHiOjeiksz2eKIuTT
 Q4OykhGoh7svw2cA9EPWRvDFu4xyPA2usrDq/ClBEKVL6jE2gfSZjVmvLGGZ2Xmq
 oHRHiE0qK8kWOf3n6ModbMWTZA7D9Y6tGd+rpFe7GdOfPeH1A9uYXfxoJwaUaEAr
 TvcyyrsePUvHJHADwRx1SzHFuwfuNU1PgflkkdhnUopKLeDfeom0CA5a+YjP1M4Z
 lHongOEdL4xAssFZU2ZXgNZiYx8su2AcUfGgnkHF1frMuoxt5Gk=
 =SXS0
 -----END PGP SIGNATURE-----

Merge tag 'backlight-next-6.8' of git://git.kernel.org/pub/scm/linux/kernel/git/lee/backlight

Pull backlight updates from Lee Jones:
 "New Drivers:
   - Add support for Monolithic Power Systems MP3309C WLED Step-up Converter

  Fix-ups:
   - Use/convert to new/better APIs/helpers/MACROs instead of
     hand-rolling implementations
   - Device Tree Binding updates
   - Demote non-kerneldoc header comments
   - Improve error handling; return proper error values, simplify, avoid
     duplicates, etc
   - Convert over to the new (kinda) GPIOD API

  Bug Fixes:
   - Fix uninitialised local variable"

* tag 'backlight-next-6.8' of git://git.kernel.org/pub/scm/linux/kernel/git/lee/backlight:
  backlight: hx8357: Convert to agnostic GPIO API
  backlight: ili922x: Add an error code check in ili922x_write()
  backlight: ili922x: Drop kernel-doc for local macros
  backlight: mp3309c: Fix uninitialized local variable
  backlight: pwm_bl: Use dev_err_probe
  backlight: mp3309c: Add support for MPS MP3309C
  dt-bindings: backlight: mp3309c: Remove two required properties
2024-01-18 16:53:35 -08:00
Bartosz Golaszewski
efb8235bfd gpiolib: revert the attempt to protect the GPIO device list with an rwsem
This reverts commits 1979a28075 ("gpiolib: replace the GPIO device
mutex with a read-write semaphore") and 65a828bab1 ("gpiolib: use
a mutex to protect the list of GPIO devices").

Unfortunately the legacy GPIO API that's still used in older code has to
translate numbers from the global GPIO numberspace to descriptors. This
results in a GPIO device lookup in every call to legacy functions. Some
of those functions - like gpio_set/get_value() - can be called from
atomic context so taking a sleeping lock that is an RW semaphore results
in an error.

We'll probably have to protect this list with SRCU.

Reported-by: Dan Carpenter <dan.carpenter@linaro.org>
Closes: https://lore.kernel.org/linux-wireless/f7b5ff1e-8f34-4d98-a7be-b826cb897dc8@moroto.mountain/
Fixes: 1979a28075 ("gpiolib: replace the GPIO device mutex with a read-write semaphore")
Fixes: 65a828bab1 ("gpiolib: use a mutex to protect the list of GPIO devices")
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2024-01-17 09:52:37 +01:00
Randy Dunlap
62b38f30a0 gpio: EN7523: fix kernel-doc warnings
Add "struct" keyword and explain the @dir array differently to
prevent kernel-doc warnings:

gpio-en7523.c:22: warning: cannot understand function prototype: 'struct airoha_gpio_ctrl '
gpio-en7523.c:27: warning: Function parameter or struct member 'dir' not described in 'airoha_gpio_ctrl'
gpio-en7523.c:27: warning: Excess struct member 'dir0' description in 'airoha_gpio_ctrl'
gpio-en7523.c:27: warning: Excess struct member 'dir1' description in 'airoha_gpio_ctrl'

Fixes: 0868ad385a ("gpio: Add support for Airoha EN7523 GPIO controller")
Signed-off-by: Randy Dunlap <rdunlap@infradead.org>
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2024-01-15 23:15:35 +01:00
Su Hui
d460e9c207 gpio: mlxbf3: add an error code check in mlxbf3_gpio_probe
Clang static checker warning: Value stored to 'ret' is never read.
bgpio_init() returns error code if failed, it's better to add this
check.

Fixes: cd33f216d2 ("gpio: mlxbf3: Add gpio driver support")
Signed-off-by: Su Hui <suhui@nfschina.com>
[Bartosz: add the Fixes: tag]
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2024-01-15 11:11:29 +01:00
Dan Carpenter
c8fb5a52b9 gpio: rtd: Fix signedness bug in probe
The "data->irqs[]" array holds unsigned int so this error handling will
not work correctly.

Fixes: eee636bff0 ("gpio: rtd: Add support for Realtek DHC(Digital Home Center) RTD SoCs")
Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2024-01-15 11:07:46 +01:00
Bartosz Golaszewski
1979a28075 gpiolib: replace the GPIO device mutex with a read-write semaphore
There are only two spots where we modify (add to or remove objects from)
the GPIO device list. Readers should be able to access it concurrently.
Replace the mutex with a read-write semaphore and adjust the locking
operations accordingly.

Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
2024-01-04 10:29:16 +01:00
Bartosz Golaszewski
48e1b4d369 gpiolib: remove the GPIO device from the list when it's unregistered
If we wait until the GPIO device's .release() callback gets invoked
before we remove it from the global device list, then we risk that
someone will look it up using gpio_device_find() between where we
dropped the last reference and before .release() is done taking a
reference again to an object that's being released.

The device must be removed when it's being unregistered - just like how
we remove it from the GPIO bus.

Fixes: ff2b135922 ("gpio: make the gpiochip a real device")
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
2024-01-04 10:29:16 +01:00
Jim Liu
c4f8457d17 gpio: nuvoton: Add Nuvoton NPCM sgpio driver
Add Nuvoton BMC NPCM7xx/NPCM8xx sgpio driver support.
Nuvoton NPCM SGPIO module is combine serial to parallel IC (HC595)
and parallel to serial IC (HC165), and use APB3 clock to control it.
This interface has 4 pins  (D_out , D_in, S_CLK, LDSH).
BMC can use this driver to increase 64 GPI pins and 64 GPO pins to use.

Signed-off-by: Jim Liu <JJLIU0@nuvoton.com>
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2024-01-03 11:25:41 +01:00
Tzuyi Chang
eee636bff0 gpio: rtd: Add support for Realtek DHC(Digital Home Center) RTD SoCs
This driver enables configuration of GPIO direction, GPIO values, GPIO
debounce settings and handles GPIO interrupts.

Signed-off-by: Tzuyi Chang <tychang@realtek.com>
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2024-01-03 10:46:21 +01:00
Wenhua Lin
0f57b21300 gpio: pmic-eic-sprd: Configure the bit corresponding to the EIC through offset
A bank PMIC EIC contains 16 EICs, and the operating registers
are BIT0-BIT15, such as BIT0 of the register operated by EIC0.
Using the one-dimensional array reg[CACHE_NR_REGS] for maintenance
will cause the configuration of other EICs to be affected when
operating a certain EIC. In order to solve this problem, configure
the bit corresponding to the EIC through offset.

Signed-off-by: Wenhua Lin <Wenhua.Lin@unisoc.com>
Reviewed-by: Chunyan Zhang <zhang.lyra@gmail.com>
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2024-01-03 09:50:47 +01:00
Emil Renner Berthing
f34fd6ee1b gpio: dwapb: Use generic request, free and set_config
This way GPIO will be denied on pins already claimed by other devices
and basic pin configuration (pull-up, pull-down etc.) can be done
through the userspace GPIO API.

Signed-off-by: Emil Renner Berthing <emil.renner.berthing@canonical.com>
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
Acked-by: Serge Semin <fancer.lancer@gmail.com>
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2024-01-02 14:16:17 +01:00
Bartosz Golaszewski
513246a34b gpio: sysfs: drop tabs from local variable declarations
Older code has an annoying habit of putting tabs between the type and the
name of the variable. This doesn't really add to readability and newer
code doesn't do it so make the entire file consistent.

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>
2023-12-27 16:01:37 +01:00
Bartosz Golaszewski
0338f6a6fb gpiolib: drop tabs from local variable declarations
Older code has an annoying habit of putting tabs between the type and the
name of the variable. This doesn't really add to readability and newer
code doesn't do it so make the entire file consistent.

While at it: convert 'unsigned' to 'unsigned int'.

Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
2023-12-27 16:00:17 +01:00
Bartosz Golaszewski
5d5dfc50e5 gpiolib: remove extra_checks
extra_checks is only used in a few places. It also depends on
a non-standard DEBUG define one needs to add to the source file. The
overhead of removing it should be minimal (we already use pure
might_sleep() in the code anyway) so drop it.

Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
2023-12-27 15:58:39 +01:00
Bartosz Golaszewski
7dd1871e50 gpio: tps65219: don't use CONFIG_DEBUG_GPIO
CONFIG_DEBUG_GPIO should only be used to enable debug log messages and
for core GPIOLIB debugging. Don't use it to control the execution of
potentially buggy code. Just put it under an always-false #if.

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>
2023-12-27 15:56:48 +01:00
Kent Gibson
20bddcb40b gpiolib: cdev: replace locking wrappers for gpio_device with guards
Replace the wrapping functions that inhibit removal of the gpio chip
with equivalent guards.

Signed-off-by: Kent Gibson <warthog618@gmail.com>
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2023-12-27 15:45:45 +01:00
Kent Gibson
32d8e3b645 gpiolib: cdev: replace locking wrappers for config_mutex with guards
After the adoption of guard(), the locking wrappers that hold the
config_mutex for linereq_set_values() and linereq_set_config() no
longer add value, so combine them into the functions they wrap.

Signed-off-by: Kent Gibson <warthog618@gmail.com>
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2023-12-27 15:45:30 +01:00
Kent Gibson
b718fbfea9 gpiolib: cdev: allocate linereq using kvzalloc()
The size of struct linereq may exceed a page, so allocate space for
it using kvzalloc() instead of kzalloc() to handle the case where
memory is heavily fragmented and kzalloc() cannot find a sufficient
contiguous region.

Signed-off-by: Kent Gibson <warthog618@gmail.com>
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2023-12-27 15:43:56 +01:00
Kent Gibson
ede7511e7c gpiolib: cdev: include overflow.h
struct_size() is used to calculate struct linereq size, so explicitly
include overflow.h.

Signed-off-by: Kent Gibson <warthog618@gmail.com>
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2023-12-27 15:43:40 +01:00
Bartosz Golaszewski
4ccdaba5ab Linux 6.7-rc7
-----BEGIN PGP SIGNATURE-----
 
 iQFSBAABCAA8FiEEq68RxlopcLEwq+PEeb4+QwBBGIYFAmWHepQeHHRvcnZhbGRz
 QGxpbnV4LWZvdW5kYXRpb24ub3JnAAoJEHm+PkMAQRiGm6YH/0b9hMQ1f2DbMjEq
 w8h0bIMkc+Jv9fLVgCMA8nTuAQsYNp+MJ8PKA9t8CCtG1BTs+lXr6DsN2GpoODEj
 fMCXzyHTlMgg5S0iXAXHcxX1t1gRDgxoOeBvUY8YZw1JZriNsO+dF3U7rRdrmg1n
 7jq6WFxJfuB2NMlmys7vk/0c3t193AKxkWyDFBmiim3MX0IYxGlD5DVadaxA6Vx7
 Pqjt9ljVG11jJWeQ9ZFLd5RmZkdmY/JVlPagEr5rPDsJrbL23sLUu4bRHGBWcipU
 BgBUdj7K6tahuwKeg2KENxCGjvQOaFIti1l1CvHMWKPgFFlhE30DD6x7nZldPSj6
 m52I1xE=
 =tLIr
 -----END PGP SIGNATURE-----

Merge tag 'v6.7-rc7' into gpio/for-next

Linux 6.7-rc7
2023-12-27 15:41:04 +01:00
xiongxin
1cc3542c76 gpio: dwapb: mask/unmask IRQ when disable/enale it
In the hardware implementation of the I2C HID driver based on DesignWare
GPIO IRQ chip, when the user continues to use the I2C HID device in the
suspend process, the I2C HID interrupt will be masked after the resume
process is finished.

This is because the disable_irq()/enable_irq() of the DesignWare GPIO
driver does not synchronize the IRQ mask register state. In normal use
of the I2C HID procedure, the GPIO IRQ irq_mask()/irq_unmask() functions
are called in pairs. In case of an exception, i2c_hid_core_suspend()
calls disable_irq() to disable the GPIO IRQ. With low probability, this
causes irq_unmask() to not be called, which causes the GPIO IRQ to be
masked and not unmasked in enable_irq(), raising an exception.

Add synchronization to the masked register state in the
dwapb_irq_enable()/dwapb_irq_disable() function. mask the GPIO IRQ
before disabling it. After enabling the GPIO IRQ, unmask the IRQ.

Fixes: 7779b34556 ("gpio: add a driver for the Synopsys DesignWare APB GPIO block")
Cc: stable@kernel.org
Co-developed-by: Riwen Lu <luriwen@kylinos.cn>
Signed-off-by: Riwen Lu <luriwen@kylinos.cn>
Signed-off-by: xiongxin <xiongxin@kylinos.cn>
Acked-by: Serge Semin <fancer.lancer@gmail.com>
Reviewed-by: Andy Shevchenko <andy@kernel.org>
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2023-12-21 11:19:01 +01:00
Kent Gibson
1d656bd259 gpiolib: cdev: add gpio_device locking wrapper around gpio_ioctl()
While the GPIO cdev gpio_ioctl() call is in progress, the kernel can
call gpiochip_remove() which will set gdev->chip to NULL, after which
any subsequent access will cause a crash.

gpio_ioctl() was overlooked by the previous fix to protect syscalls
(bdbbae241a), so add protection for that.

Fixes: bdbbae241a ("gpiolib: protect the GPIO device against being dropped while in use by user-space")
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")
Signed-off-by: Kent Gibson <warthog618@gmail.com>
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2023-12-21 10:27:07 +01:00
Kent Gibson
1cdc605c7d gpiolib: cdev: reduce locking in gpio_desc_to_lineinfo()
Reduce the time holding the gpio_lock by snapshotting the desc flags,
rather than testing them individually while holding the lock.

Accept that the calculation of the used field is inherently racy, and
only check the availability of the line from pinctrl if other checks
pass, so avoiding the check for lines that are otherwise in use.

Signed-off-by: Kent Gibson <warthog618@gmail.com>
Reviewed-by: Andy Shevchenko <andy@kernel.org>
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2023-12-19 10:32:52 +01:00
Kent Gibson
193b6b0902 gpiolib: cdev: improve documentation of get/set values
Add documentation of the algorithm used to perform scatter/gather
of the requested lines and values in linereq_get_values() and
linereq_set_values_unlocked() to improve maintainability.

Signed-off-by: Kent Gibson <warthog618@gmail.com>
Reviewed-by: Andy Shevchenko <andy@kernel.org>
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2023-12-19 10:18:49 +01:00
Kent Gibson
0ebeaab4d5 gpiolib: cdev: fully adopt guard() and scoped_guard()
Use guard() or scoped_guard() for critical sections rather than
discrete lock/unlock pairs.

Signed-off-by: Kent Gibson <warthog618@gmail.com>
Reviewed-by: Andy Shevchenko <andy@kernel.org>
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2023-12-19 10:18:42 +01:00
Kent Gibson
d8543cbaf9 gpiolib: remove debounce_period_us from struct gpio_desc
cdev is the only user of the debounce_period_us field in
struct gpio_desc, and it no longer uses it, so remove it.

Signed-off-by: Kent Gibson <warthog618@gmail.com>
Reviewed-by: Andy Shevchenko <andy@kernel.org>
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2023-12-19 09:45:45 +01:00
Kent Gibson
9344e34e79 gpiolib: cdev: relocate debounce_period_us from struct gpio_desc
Store the debounce period for a requested line locally, rather than in
the debounce_period_us field in the gpiolib struct gpio_desc.

Add a global tree of lines containing supplemental line information
to make the debounce period available to be reported by the
GPIO_V2_GET_LINEINFO_IOCTL and the line change notifier.

Signed-off-by: Kent Gibson <warthog618@gmail.com>
Reviewed-by: Andy Shevchenko <andy@kernel.org>
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2023-12-19 09:45:35 +01:00
Bartosz Golaszewski
40aa7e290b intel-gpio for v6.8-1
* Use RAII for locking in the Tangier family of drivers (Raag)
 * Update Tangier family of drivers to use new PM helpers (Raag)
 
 The following is an automated git shortlog grouped by driver:
 
 elkhartlake:
  -  reuse pm_ops from Intel Tangier driver
 
 tangier:
  -  simplify locking using cleanup helpers
  -  unexport suspend/resume handles
  -  use EXPORT_NS_GPL_SIMPLE_DEV_PM_OPS() helper
 -----BEGIN PGP SIGNATURE-----
 
 iQIzBAABCgAdFiEEqaflIX74DDDzMJJtb7wzTHR8rCgFAmWAKJYACgkQb7wzTHR8
 rCjgSA//dMmLE4gqJazEtqZd0T0XWwEeJfDpESebxnHaBMbleryosEaS6TLF5sFY
 Dstwmcn1bt1OEB+i1ALjh6X2YuVbYXx8i+XxpQ6nVBh9UIxt6jaN7IsGLdx4Yzcd
 NFWX+DKYBUV7kCtFDVjFeLGobLHr3fLV8UgSKqg82rLAmDBHixmtkTqYNtfZXZQI
 4wfthz2KD++jceV6jG/5TllPKgqNZDIg8TvZqtpopaNju/Fmk5bQLUfIA/LtOUly
 K3kQsXq1lro4S4TTMpAsKzboC1vfORTzOyB8bQxCCQ+UvEYDe6QbJHooU7PoIQGN
 2+liVgWr9uWFZcXEgziBm2UqtIS4WOk/4Qfvz4Dodw3v8UtACA9ajItNYw6sgx8j
 GzbU/3gnIq1U1OHESH/+1puxg0HKAHtJ4rnnFtJBTnuy/pM+nemRYumFzg0okGNx
 cw6aGuu3v3IxIZGzkCUdAABjE49QzQ8LYwafEa5dyKmONIm5O6zWR7gmNDoWKN1n
 boLlUfm+agf1fXy+rgEPw/MBKacJnLVr2B3XIScD+ZXUCTicbQRPBndgGE+Cvxcz
 1hVUcQh5It1w5H/9Gwt1xivMo+hpe1vHLipa5mWkKT9F87SIKQpT2Y05CvoKernO
 wL2jJnnc7z58fIOgy0EQFhm25Lc9cSPGvJnuQGULdPh57y/y6fo=
 =TW/S
 -----END PGP SIGNATURE-----

Merge tag 'intel-gpio-v6.8-1' of git://git.kernel.org/pub/scm/linux/kernel/git/andy/linux-gpio-intel into gpio/for-next

intel-gpio for v6.8-1

* Use RAII for locking in the Tangier family of drivers (Raag)
* Update Tangier family of drivers to use new PM helpers (Raag)

The following is an automated git shortlog grouped by driver:

elkhartlake:
 -  reuse pm_ops from Intel Tangier driver

tangier:
 -  simplify locking using cleanup helpers
 -  unexport suspend/resume handles
 -  use EXPORT_NS_GPL_SIMPLE_DEV_PM_OPS() helper
2023-12-18 16:26:26 +01:00
Andy Shevchenko
c9bd27c880 gpio: mmio: Clean up headers
There is a few things done:
- include only the headers we are direct user of
- add missing headers
- group generic headers and subsystem headers
- sort each group alphabetically

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>
2023-12-18 13:43:06 +01:00
Andy Shevchenko
001cf2dec3 gpio: mmio: Make use of device properties
Convert the module to be property provider agnostic and allow
it to be used on non-OF platforms.

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>
2023-12-18 13:42:45 +01:00
Bartosz Golaszewski
65a828bab1 gpiolib: use a mutex to protect the list of GPIO devices
The global list of GPIO devices is never modified or accessed from
atomic context so it's fine to protect it using a mutex. Add a new
global lock dedicated to the gpio_devices list and use it whenever
accessing or modifying it.

Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
2023-12-18 10:00:43 +01:00
Bartosz Golaszewski
f95fd4ac15 gpiolib: rename static functions that are called with the lock taken
Rename two functions that read or modify the global GPIO device list but
don't take the lock themselves (and need to be called with it already
acquired). Use the _unlocked() suffix which seems to be used quite
consistently across the kernel despite there also existing the _locked()
suffix for the same purpose.

Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
2023-12-18 09:59:20 +01:00
Bartosz Golaszewski
4c7fcbf507 gpio: xilinx: remove excess kernel doc
The irqchip field has been removed from struct xgpio_instance so remove
the doc as well.

Fixes: b4510f8fd5 ("gpio: xilinx: Convert to immutable irq_chip")
Reported-by: kernel test robot <lkp@intel.com>
Closes: https://lore.kernel.org/oe-kbuild-all/202312150239.IyuTVvrL-lkp@intel.com/
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Reviewed-by: Michal Simek <michal.simek@amd.com>
Reviewed-by: Randy Dunlap <rdunlap@infradead.org>
2023-12-18 09:56:21 +01:00
Bartosz Golaszewski
0a10d10781 gpiolib: allocate memory atomically with a spinlock held
We will eventually switch to protecting the GPIO descriptors with a mutex
but until then, we need to allocate memory for the label copy atomically
while we're holding the global spinlock.

Reported-by: Dan Carpenter <dan.carpenter@linaro.org>
Closes: https://lore.kernel.org/linux-gpio/62588146-eed6-42f7-ba26-160226b109fe@moroto.mountain/T/#u
Fixes: f8d05e276b ("gpiolib: remove gpiochip_is_requested()")
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
2023-12-15 16:43:24 +01:00
Andy Shevchenko
7d84a63a39 backlight: hx8357: Convert to agnostic GPIO API
The of_gpio.h is going to be removed. In preparation of that convert
the driver to the agnostic API.

Fixes: fbbbcd177a ("gpiolib: of: add quirk for locating reset lines with legacy bindings")
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Reviewed-by: Daniel Thompson <daniel.thompson@linaro.org>
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
Link: https://lore.kernel.org/r/20231207161513.3195509-2-andriy.shevchenko@linux.intel.com
Signed-off-by: Lee Jones <lee@kernel.org>
2023-12-13 15:41:59 +00:00
Bartosz Golaszewski
d22f93c6a0 gpio: sim: implement the dbg_show() callback
Provide a custom implementation of the dbg_show() callback that prints
all requested lines together with their label, direction, value and
bias. This improves the code coverage of GPIOLIB.

Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2023-12-08 09:37:30 +01:00
Bartosz Golaszewski
11a94a335a gpio: remove gpiochip_is_requested()
- provide a safer alternative to gpiochip_is_requested()
 - convert all existing users
 - remove gpiochip_is_requested()
 -----BEGIN PGP SIGNATURE-----
 
 iQIzBAABCgAdFiEEFp3rbAvDxGAT0sefEacuoBRx13IFAmVy01QACgkQEacuoBRx
 13LcZhAAyJlx3u3snkGjMc8O//2Se5YYhWMuUV37oNjTK5P+ahvq5T+DWSTVtNJz
 uJS4rdx4n4TXsbPJKPu8TAyIYhBZGmFAYmfJ4O3IgSrqEieRCp1TfUDI3q+iEHJ2
 APdLFF1OqYXpz1lqz/nMyyJaEyRmRrS09gMo9CSPgjh66oHAd+epN5pJTYffJ9yZ
 aAxKMIL8CBpLzfNlz4gqwsvObQZOTTM4L7BkH9JaXXnDTAtyQ+HpdlwwwJxTkkzy
 YEKrs06/quAoM8Re724l1EmCcgbZzbCkFnTLB/xSFgnV35L2MAvyFEOtd9Jnd8XP
 jeWV7hzPYrWKeSKCEOH042ILlyBkNfN/A6MDmF3B/3/D+eM1k/rXfSKA064plMl8
 BzSSzb1ylPOPLQp4idlV4qA3WY1AemAQZTOmQmV9C3/OaqdgcXLgyBXaARz2gOM4
 u0L+WybwjgmHd/4WuDLtuJ95gaU/YEpURtCGFWaKWQraaSQFDT2EV3nQf/hZ9WgM
 2SGqT0sVnmu2K0n0+EW5M4PZyForOwSM9tzqtYmTmal9s1adnL6yx9YH62ON3TV4
 Yazi+QpAo+lZ4zfzWV0JODE5ENOn0g9WTmGPLOBfYG7HiqK58WOCz2gwZpqX+xv6
 y6JppF7KD5k5xacpMFYHlE92HUyO8VqmTid92Q+97e7JG9xGDG4=
 =PlCm
 -----END PGP SIGNATURE-----

Merge tag 'gpio-remove-gpiochip_is_requested-for-v6.8-rc1' into gpio/for-next

gpio: remove gpiochip_is_requested()

- provide a safer alternative to gpiochip_is_requested()
- convert all existing users
- remove gpiochip_is_requested()
2023-12-08 09:37:12 +01:00
Bartosz Golaszewski
f8d05e276b gpiolib: remove gpiochip_is_requested()
We have no external users of gpiochip_is_requested(). Let's remove it
and replace its internal calls with direct testing of the REQUESTED flag.

Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Acked-by: Linus Walleij <linus.walleij@linaro.org>
2023-12-08 09:26:43 +01:00
Bartosz Golaszewski
f1b33ce48a gpio: stmpe: use gpiochip_dup_line_label()
Use the new gpiochip_dup_line_label() helper to safely retrieve the
descriptor label.

Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Acked-by: Linus Walleij <linus.walleij@linaro.org>
2023-12-08 09:26:28 +01:00
Bartosz Golaszewski
abeec1ad51 gpio: wm8994: use gpiochip_dup_line_label()
Use the new gpiochip_dup_line_label() helper to safely retrieve the
descriptor label.

Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Acked-by: Linus Walleij <linus.walleij@linaro.org>
2023-12-08 09:26:25 +01:00