Commit Graph

207 Commits

Author SHA1 Message Date
CKI Backport Bot d07570e188 gpio: pca953x: fix pca953x_irq_bus_sync_unlock race
JIRA: https://issues.redhat.com/browse/RHEL-53831
CVE: CVE-2024-42253

commit bfc6444b57dc7186b6acc964705d7516cbaf3904
Author: Ian Ray <ian.ray@gehealthcare.com>
Date:   Thu Jun 20 07:29:15 2024 +0300

    gpio: pca953x: fix pca953x_irq_bus_sync_unlock race

    Ensure that `i2c_lock' is held when setting interrupt latch and mask in
    pca953x_irq_bus_sync_unlock() in order to avoid races.

    The other (non-probe) call site pca953x_gpio_set_multiple() ensures the
    lock is held before calling pca953x_write_regs().

    The problem occurred when a request raced against irq_bus_sync_unlock()
    approximately once per thousand reboots on an i.MX8MP based system.

     * Normal case

       0-0022: write register AI|3a {03,02,00,00,01} Input latch P0
       0-0022: write register AI|49 {fc,fd,ff,ff,fe} Interrupt mask P0
       0-0022: write register AI|08 {ff,00,00,00,00} Output P3
       0-0022: write register AI|12 {fc,00,00,00,00} Config P3

     * Race case

       0-0022: write register AI|08 {ff,00,00,00,00} Output P3
       0-0022: write register AI|08 {03,02,00,00,01} *** Wrong register ***
       0-0022: write register AI|12 {fc,00,00,00,00} Config P3
       0-0022: write register AI|49 {fc,fd,ff,ff,fe} Interrupt mask P0

    Signed-off-by: Ian Ray <ian.ray@gehealthcare.com>
    Link: https://lore.kernel.org/r/20240620042915.2173-1-ian.ray@gehealthcare.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>
2024-08-09 09:57:23 +00:00
Andrew Halaney 18068a6e8d gpio: pca953x: Drop unused fields in struct pca953x_platform_data
JIRA: https://issues.redhat.com/browse/RHEL-35606
Conflicts: Due to missing
           ed5c2f5fd10dd ("i2c: Make remove callback return void"),
           we must still return 0.

commit 2f4d3e293392571e02b106c8b431b638bd029276
Author: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Date:   Fri Sep 1 16:40:32 2023 +0300

    gpio: pca953x: Drop unused fields in struct pca953x_platform_data

    New code should solely use firmware nodes for the specifics and
    not any callbacks.

    Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
    Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>

Signed-off-by: Andrew Halaney <ahalaney@redhat.com>
2024-05-28 09:43:18 -05:00
Andrew Halaney f19e138210 gpio: pca953x: add support for TCA9538
JIRA: https://issues.redhat.com/browse/RHEL-35606

commit 3d0957b07e27abd3237b1fe0c7f06485ba80852f
Author: Liam Beguin <liambeguin@gmail.com>
Date:   Thu Aug 24 19:16:25 2023 -0400

    gpio: pca953x: add support for TCA9538

    The TCA9538 is an 8 bit version of the already supported TCA9539.
    This chip also has interrupt support.

    Signed-off-by: Liam Beguin <liambeguin@gmail.com>
    Reviewed-by: Andy Shevchenko <andy@kernel.org>
    Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>

Signed-off-by: Andrew Halaney <ahalaney@redhat.com>
2024-05-28 09:43:18 -05:00
Andrew Halaney 3e30c82814 gpio: pca953x: Remove unused PCAL953X_OUT_CONF from pcal6534_recalc_addr()
JIRA: https://issues.redhat.com/browse/RHEL-35606

commit 9eeaa60ead4b6dc84cef012aa9aee3eb48dc4930
Author: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Date:   Sun Dec 11 00:06:01 2022 +0200

    gpio: pca953x: Remove unused PCAL953X_OUT_CONF from pcal6534_recalc_addr()

    First of all, PCAL953X_OUT_CONF is not used in the driver.
    Second, it's not a per-bank register, it's a single for the
    chip and should be handled differently anyway.

    To avoid confusion, drop PCAL953X_OUT_CONF from pcal6534_recalc_addr().

    Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
    Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>

Signed-off-by: Andrew Halaney <ahalaney@redhat.com>
2024-05-28 09:43:18 -05:00
Andrew Halaney 169029e770 gpio: pca953x: Clean up pcal6534_check_register()
JIRA: https://issues.redhat.com/browse/RHEL-35606

commit a87f901b59326c12313dbf224cc4591ae2c63785
Author: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Date:   Sun Dec 11 00:06:00 2022 +0200

    gpio: pca953x: Clean up pcal6534_check_register()

    The pcal6534_check_register() is a bit too verbose.
    Clean up it, by deduplicating some operations and
    switching to the modulo operation as on some architectures
    / and % can become a single assembly instruction.

    Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
    Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>

Signed-off-by: Andrew Halaney <ahalaney@redhat.com>
2024-05-28 09:43:18 -05:00
Andrew Halaney 1a99fe7b32 gpio: pca953x: avoid logically dead code
JIRA: https://issues.redhat.com/browse/RHEL-35606

commit b1453d1eb93fd34848082fd181ff247f19c0ee86
Author: Haibo Chen <haibo.chen@nxp.com>
Date:   Sun Dec 11 00:05:59 2022 +0200

    gpio: pca953x: avoid logically dead code

    The current code logic make the condition "else if (reg >= 0x54)"
    can't be true, cause the dead code. So fix it to match the coder
    expectation. This is reported by Coverity.

    Fixes: 13c5d4ce8060 ("gpio: pca953x: Add support for PCAL6534")
    Signed-off-by: Haibo Chen <haibo.chen@nxp.com>
    Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
    Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>

Signed-off-by: Andrew Halaney <ahalaney@redhat.com>
2024-05-28 09:43:18 -05:00
Andrew Halaney d120953362 gpio: pca953x: avoid to use uninitialized value pinctrl
JIRA: https://issues.redhat.com/browse/RHEL-35606

commit 90fee3dd5bfc1b9f4c8c0ba6cd2a35c9d79ca4de
Author: Haibo Chen <haibo.chen@nxp.com>
Date:   Sun Dec 11 00:05:58 2022 +0200

    gpio: pca953x: avoid to use uninitialized value pinctrl

    There is a variable pinctrl declared without initializer. And then
    has the case (switch operation chose the default case) to directly
    use this uninitialized value, this is not a safe behavior. So here
    initialize the pinctrl as 0 to avoid this issue.
    This is reported by Coverity.

    Fixes: 13c5d4ce8060 ("gpio: pca953x: Add support for PCAL6534")
    Signed-off-by: Haibo Chen <haibo.chen@nxp.com>
    Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
    Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>

Signed-off-by: Andrew Halaney <ahalaney@redhat.com>
2024-05-28 09:43:18 -05:00
Andrew Halaney 39ce7afd95 gpio: pca953x: Convert to i2c's .probe_new()
JIRA: https://issues.redhat.com/browse/RHEL-35606

commit 1287341c1980e0cf9eb19bdd370405d755392f2f
Author: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Date:   Fri Nov 18 23:35:46 2022 +0100

    gpio: pca953x: Convert to i2c's .probe_new()

    .probe_new() doesn't get the i2c_device_id * parameter, so determine
    that explicitly in the probe function.

    Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
    Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>

Signed-off-by: Andrew Halaney <ahalaney@redhat.com>
2024-05-28 09:43:18 -05:00
Andrew Halaney 22908f2245 gpio: pca953x: Add missing header(s)
JIRA: https://issues.redhat.com/browse/RHEL-35606

commit c20a395f9bf939ef0587ce5fa14316ac26252e9b
Author: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Date:   Fri Oct 7 16:44:44 2022 +0300

    gpio: pca953x: Add missing header(s)

    Do not imply that some of the generic headers may be always included.
    Instead, include explicitly what we are direct user of.

    While at it, sort headers alphabetically.

    Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>

Signed-off-by: Andrew Halaney <ahalaney@redhat.com>
2024-05-28 09:43:18 -05:00
Andrew Halaney 4e0f986fe1 gpio: pca953x: Add support for PCAL6534
JIRA: https://issues.redhat.com/browse/RHEL-35606

commit 13c5d4ce806026a3d06efa2fcc1e5a0cb875df29
Author: Martyn Welch <martyn.welch@collabora.com>
Date:   Wed Sep 14 16:15:57 2022 +0100

    gpio: pca953x: Add support for PCAL6534

    Add support for the NXP PCAL6534. This device is broadly a 34-bit version
    of the PCAL6524. However, whilst the registers are broadly what you'd
    expect for a 34-bit version of the PCAL6524, the spacing of the registers
    has been compacted. This has the unfortunate effect of breaking the bit
    shift based mechanism that is employed to work out register locations used
    by the other chips supported by this driver. To accommodate ths, callback
    functions have been added to allow alterate implementations of
    pca953x_recalc_addr() and pca953x_check_register() for the PCAL6534.

    Datasheet: https://www.nxp.com/docs/en/data-sheet/PCAL6534.pdf
    Datasheet: https://www.diodes.com/assets/Datasheets/PI4IOE5V6534Q.pdf
    Signed-off-by: Martyn Welch <martyn.welch@collabora.com>
    Signed-off-by: Bartosz Golaszewski <brgl@bgdev.pl>

Signed-off-by: Andrew Halaney <ahalaney@redhat.com>
2024-05-28 09:43:18 -05:00
Andrew Halaney 70fc41d8c8 gpio: pca953x: Swap if statements to save later complexity
JIRA: https://issues.redhat.com/browse/RHEL-35606

commit 5faf9801d4be7a079062b2ece493ae6e9e38c828
Author: Martyn Welch <martyn.welch@collabora.com>
Date:   Wed Sep 14 16:15:56 2022 +0100

    gpio: pca953x: Swap if statements to save later complexity

    A later patch in the series adds support for a further chip type that
    shares some similarity with the PCA953X_TYPE. In order to keep the logic
    simple, swap over the if and else portions where checks are made against
    PCA953X_TYPE and instead check for PCA957X_TYPE.

    Signed-off-by: Martyn Welch <martyn.welch@collabora.com>
    Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
    Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
    Signed-off-by: Bartosz Golaszewski <brgl@bgdev.pl>

Signed-off-by: Andrew Halaney <ahalaney@redhat.com>
2024-05-28 09:43:18 -05:00
Andrew Halaney 97bb5441b5 gpio: pca953x: Fix pca953x_gpio_set_pull_up_down()
JIRA: https://issues.redhat.com/browse/RHEL-35606

commit b122624ab91705d30354f0397b1eea931c6b1933
Author: Martyn Welch <martyn.welch@collabora.com>
Date:   Wed Sep 14 16:15:55 2022 +0100

    gpio: pca953x: Fix pca953x_gpio_set_pull_up_down()

    A previous fix, commit dc87f6dd05 ("gpio: pca953x: Fix
    pca953x_gpio_set_config"), identified that pinconf_to_config_param() needed
    to be used to isolate the config_param from the pinconf in
    pca953x_gpio_set_config(). This fix however did not consider that this
    would also be needed in pca953x_gpio_set_pull_up_down() to which it passes
    this config.

    Perform a similar call in pca953x_gpio_set_pull_up_down() to isolate the
    configuration parameter there as well, rather than passing it from
    pca953x_gpio_set_config() as the configuration argument may also be needed
    in pca953x_gpio_set_pull_up_down() at a later date.

    Signed-off-by: Martyn Welch <martyn.welch@collabora.com>
    Acked-by: Linus Walleij <linus.walleij@linaro.org>
    Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
    Signed-off-by: Bartosz Golaszewski <brgl@bgdev.pl>

Signed-off-by: Andrew Halaney <ahalaney@redhat.com>
2024-05-28 09:43:18 -05:00
Andrew Halaney 287e0aac28 gpio: pca953x: introduce support for nxp,pcal6408
JIRA: https://issues.redhat.com/browse/RHEL-35606

commit 6d50b79051edc298aba7f60184d9b2fb673f0628
Author: Nate Drude <nate.d@variscite.com>
Date:   Tue Sep 13 13:24:36 2022 -0500

    gpio: pca953x: introduce support for nxp,pcal6408

    The NXP PCAL6408 is the 8-bit version of PCAL6416.

    Signed-off-by: Nate Drude <nate.d@variscite.com>
    Signed-off-by: Bartosz Golaszewski <brgl@bgdev.pl>

Signed-off-by: Andrew Halaney <ahalaney@redhat.com>
2024-05-28 09:43:18 -05:00
Andrew Halaney 4ff4a9856f gpio: pca953x: Add mutex_lock for regcache sync in PM
JIRA: https://issues.redhat.com/browse/RHEL-35606

commit 518e26f11af2fe4f5bebf9a0351595d508c7077f
Author: Haibo Chen <haibo.chen@nxp.com>
Date:   Wed Aug 31 18:37:35 2022 +0800

    gpio: pca953x: Add mutex_lock for regcache sync in PM

    The regcache sync will set the cache_bypass = true, at that
    time, when there is regmap write operation, it will bypass
    the regmap cache, then the regcache sync will write back the
    value from cache to register, which is not as our expectation.

    Though regmap already use its internal lock to avoid such issue,
    but this driver force disable the regmap internal lock in its
    regmap config: disable_locking = true

    To avoid this issue, use the driver's own lock to do the protect
    in system PM.

    Fixes: b765743005 ("gpio: pca953x: Restore registers after suspend/resume cycle")
    Signed-off-by: Haibo Chen <haibo.chen@nxp.com>
    Signed-off-by: Bartosz Golaszewski <brgl@bgdev.pl>

Signed-off-by: Andrew Halaney <ahalaney@redhat.com>
2024-05-28 09:43:18 -05:00
Andrew Halaney 0edfad5dc8 gpio: pca953x: Make platform teardown callback return void
JIRA: https://issues.redhat.com/browse/RHEL-35606

commit 6a8f359c3132e4f51bdb263ad74ec632c65e55fd
Author: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Date:   Mon Aug 15 10:02:29 2022 +0200

    gpio: pca953x: Make platform teardown callback return void

    All platforms that provide a teardown callback return 0. New users are
    supposed to not make use of platform support, so there is no
    functionality lost.

    This patch is a preparation for making i2c remove callbacks return void.

    Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
    Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
    Acked-by: Bartosz Golaszewski <brgl@bgdev.pl>
    Signed-off-by: Wolfram Sang <wsa@kernel.org>

Signed-off-by: Andrew Halaney <ahalaney@redhat.com>
2024-05-28 09:43:17 -05:00
Andrew Halaney da7c920dfa gpio: pca953x: use the correct register address when regcache sync during init
JIRA: https://issues.redhat.com/browse/RHEL-35606

commit b8c768ccdd8338504fb78370747728d5002b1b5a
Author: Haibo Chen <haibo.chen@nxp.com>
Date:   Mon Jul 18 16:31:43 2022 +0800

    gpio: pca953x: use the correct register address when regcache sync during init

    For regcache_sync_region, we need to use pca953x_recalc_addr() to get
    the real register address.

    Fixes: ec82d1eba3 ("gpio: pca953x: Zap ad-hoc reg_output cache")
    Fixes: 0f25fda840 ("gpio: pca953x: Zap ad-hoc reg_direction cache")
    Signed-off-by: Haibo Chen <haibo.chen@nxp.com>
    Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
    Signed-off-by: Bartosz Golaszewski <brgl@bgdev.pl>

Signed-off-by: Andrew Halaney <ahalaney@redhat.com>
2024-05-28 09:43:17 -05:00
Andrew Halaney cb42c251c7 gpio: pca953x: use the correct range when do regmap sync
JIRA: https://issues.redhat.com/browse/RHEL-35606

commit 2abc17a93867dc816f0ed9d32021dda8078e7330
Author: Haibo Chen <haibo.chen@nxp.com>
Date:   Mon Jul 18 16:31:42 2022 +0800

    gpio: pca953x: use the correct range when do regmap sync

    regmap will sync a range of registers, here use the correct range
    to make sure the sync do not touch other unexpected registers.

    Find on pca9557pw on imx8qxp/dxl evk board, this device support
    8 pin, so only need one register(8 bits) to cover all the 8 pins's
    property setting. But when sync the output, we find it actually
    update two registers, output register and the following register.

    Fixes: b765743005 ("gpio: pca953x: Restore registers after suspend/resume cycle")
    Fixes: ec82d1eba3 ("gpio: pca953x: Zap ad-hoc reg_output cache")
    Fixes: 0f25fda840 ("gpio: pca953x: Zap ad-hoc reg_direction cache")
    Signed-off-by: Haibo Chen <haibo.chen@nxp.com>
    Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
    Signed-off-by: Bartosz Golaszewski <brgl@bgdev.pl>

Signed-off-by: Andrew Halaney <ahalaney@redhat.com>
2024-05-28 09:43:17 -05:00
Andrew Halaney 531ff221f3 gpio: pca953x: only use single read/write for No AI mode
JIRA: https://issues.redhat.com/browse/RHEL-35606

commit db8edaa09d7461ec08672a92a2eef63d5882bb79
Author: Haibo Chen <haibo.chen@nxp.com>
Date:   Mon Jul 18 16:31:41 2022 +0800

    gpio: pca953x: only use single read/write for No AI mode

    For the device use NO AI mode(not support auto address increment),
    only use the single read/write when config the regmap.

    We meet issue on PCA9557PW on i.MX8QXP/DXL evk board, this device
    do not support AI mode, but when do the regmap sync, regmap will
    sync 3 byte data to register 1, logically this means write first
    data to register 1, write second data to register 2, write third data
    to register 3. But this device do not support AI mode, finally, these
    three data write only into register 1 one by one. the reault is the
    value of register 1 alway equal to the latest data, here is the third
    data, no operation happened on register 2 and register 3. This is
    not what we expect.

    Fixes: 4942723276 ("gpio: pca953x: Perform basic regmap conversion")
    Signed-off-by: Haibo Chen <haibo.chen@nxp.com>
    Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
    Signed-off-by: Bartosz Golaszewski <brgl@bgdev.pl>

Signed-off-by: Andrew Halaney <ahalaney@redhat.com>
2024-05-28 09:43:17 -05:00
Andrew Halaney c962a1e5c7 gpio: pca953x: use the correct register address to do regcache sync
JIRA: https://issues.redhat.com/browse/RHEL-35606

commit 43624eda86c98b0de726d0b6f2516ccc3ef7313f
Author: Haibo Chen <haibo.chen@nxp.com>
Date:   Mon May 30 18:48:48 2022 +0800

    gpio: pca953x: use the correct register address to do regcache sync

    For regcache_sync_region, need to use pca953x_recalc_addr() to get
    the real register address.

    Fixes: b765743005 ("gpio: pca953x: Restore registers after suspend/resume cycle")
    Signed-off-by: Haibo Chen <haibo.chen@nxp.com>
    Signed-off-by: Bartosz Golaszewski <brgl@bgdev.pl>

Signed-off-by: Andrew Halaney <ahalaney@redhat.com>
2024-05-28 09:43:17 -05:00
Andrew Halaney 49fc2ecb1d gpio: pca953x: Make the irqchip immutable
JIRA: https://issues.redhat.com/browse/RHEL-35606

commit ac2f6f9385aa27b9a73156885be9765299b8e11f
Author: Geert Uytterhoeven <geert+renesas@glider.be>
Date:   Fri May 20 12:21:54 2022 +0200

    gpio: pca953x: Make the irqchip immutable

    Commit 6c846d026d49 ("gpio: Don't fiddle with irqchips marked as
    immutable") added a warning to indicate if the gpiolib is altering the
    internals of irqchips.  Following this change the following warning is
    now observed for the pca953x driver:

        gpio gpiochip7: (0-0020): not an immutable chip, please consider fixing it!

    Fix this by making the irqchip in the pca953x driver immutable.

    Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
    Signed-off-by: Bartosz Golaszewski <brgl@bgdev.pl>

Signed-off-by: Andrew Halaney <ahalaney@redhat.com>
2024-05-28 09:43:17 -05:00
Andrew Halaney 17ee5bccbb gpio: pca953x: fix irq_stat not updated when irq is disabled (irq_mask not set)
JIRA: https://issues.redhat.com/browse/RHEL-35606

commit dba785798526a3282cc4d0f0ea751883715dbbb4
Author: Puyou Lu <puyou.lu@gmail.com>
Date:   Fri May 6 16:06:30 2022 +0800

    gpio: pca953x: fix irq_stat not updated when irq is disabled (irq_mask not set)

    When one port's input state get inverted (eg. from low to hight) after
    pca953x_irq_setup but before setting irq_mask (by some other driver such as
    "gpio-keys"), the next inversion of this port (eg. from hight to low) will not
    be triggered any more (because irq_stat is not updated at the first time). Issue
    should be fixed after this commit.

    Fixes: 89ea8bbe9c ("gpio: pca953x.c: add interrupt handling capability")
    Signed-off-by: Puyou Lu <puyou.lu@gmail.com>
    Signed-off-by: Bartosz Golaszewski <brgl@bgdev.pl>

Signed-off-by: Andrew Halaney <ahalaney@redhat.com>
2024-05-28 09:43:17 -05:00
Andrew Halaney 1f37efde74 gpio: pca953xx: Add support for pca6408
JIRA: https://issues.redhat.com/browse/RHEL-35606

commit a9e49635e263b5f304179ef537e0b056199c66d8
Author: Justin Chen <justinpopo6@gmail.com>
Date:   Wed May 4 15:29:16 2022 -0700

    gpio: pca953xx: Add support for pca6408

    Add support for pca6408 which is the 8-bit version of the pca6416.

    https://www.nxp.com/docs/en/data-sheet/PCA6408A.pdf

    Signed-off-by: Justin Chen <justinpopo6@gmail.com>
    Acked-by: Florian Fainelli <f.fainelli@gmail.com>
    Signed-off-by: Bartosz Golaszewski <brgl@bgdev.pl>

Signed-off-by: Andrew Halaney <ahalaney@redhat.com>
2024-05-28 09:43:17 -05:00
Andrew Halaney 3dcb83dd54 gpio: pca953x: Improve bias setting
JIRA: https://issues.redhat.com/browse/RHEL-35606

commit 55a9968c7e139209a9e93d4ca4321731bea5fc95
Author: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Date:   Fri Sep 24 01:46:40 2021 +0300

    gpio: pca953x: Improve bias setting

    The commit 15add06841 ("gpio: pca953x: add ->set_config implementation")
    introduced support for bias setting. However this, due to being half-baked,
    brought potential issues:
     - the turning bias via disabling makes the pin floating for a while;
     - once enabled, bias can't be disabled.

    Fix all these by adding support for bias disabling and move the disabling
    part under the corresponding conditional.

    While at it, add support for default setting, since it's cheap to add.

    Fixes: 15add06841 ("gpio: pca953x: add ->set_config implementation")
    Cc: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
    Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
    Signed-off-by: Bartosz Golaszewski <brgl@bgdev.pl>

Signed-off-by: Andrew Halaney <ahalaney@redhat.com>
2024-05-28 09:43:17 -05:00
Andrew Halaney c5eb242926 gpio: pca953x: do not ignore i2c errors
JIRA: https://issues.redhat.com/browse/RHEL-35606

commit 540cffbab8b8e6c52a4121666ca18d6e94586ed2
Author: Andrey Gusakov <andrey.gusakov@cogentembedded.com>
Date:   Thu Sep 23 20:22:16 2021 +0300

    gpio: pca953x: do not ignore i2c errors

    Per gpio_chip interface, error shall be proparated to the caller.

    Attempt to silent diagnostics by returning zero (as written in the
    comment) is plain wrong, because the zero return can be interpreted by
    the caller as the gpio value.

    Cc: stable@vger.kernel.org
    Signed-off-by: Andrey Gusakov <andrey.gusakov@cogentembedded.com>
    Signed-off-by: Nikita Yushchenko <nikita.yoush@cogentembedded.com>
    Signed-off-by: Bartosz Golaszewski <brgl@bgdev.pl>

Signed-off-by: Andrew Halaney <ahalaney@redhat.com>
2024-05-28 09:43:17 -05:00
Peter Robinson 6d49b3a0f3 gpio: pca953x: Add support for the On Semi pca9655
The On Semi pca9655 is a 16 bit variant of the On Semi pca9654 GPIO
expander, with 16 GPIOs and interrupt functionality.

Signed-off-by: Peter Robinson <pbrobinson@gmail.com>
[Bartosz: fixed indentation as noted by Andy]
Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
2021-06-16 21:26:35 +02:00
Andy Shevchenko eb441337c7 gpio: pca953x: Set IRQ type when handle Intel Galileo Gen 2
The commit 0ea683931a ("gpio: dwapb: Convert driver to using the
GPIO-lib-based IRQ-chip") indeliberately made a regression on how
IRQ line from GPIO I²C expander is handled. I.e. it reveals that
the quirk for Intel Galileo Gen 2 misses the part of setting IRQ type
which previously was predefined by gpio-dwapb driver. Now, we have to
reorganize the approach to call necessary parts, which can be done via
ACPI_GPIO_QUIRK_ABSOLUTE_NUMBER quirk.

Without this fix and with above mentioned change the kernel hangs
on the first IRQ event with:

    gpio gpiochip3: Persistence not supported for GPIO 1
    irq 32, desc: 62f8fb50, depth: 0, count: 0, unhandled: 0
    ->handle_irq():  41c7b0ab, handle_bad_irq+0x0/0x40
    ->irq_data.chip(): e03f1e72, 0xc2539218
    ->action(): 0ecc7e6f
    ->action->handler(): 8a3db21e, irq_default_primary_handler+0x0/0x10
       IRQ_NOPROBE set
    unexpected IRQ trap at vector 20

Fixes: ba8c90c618 ("gpio: pca953x: Override IRQ for one of the expanders on Galileo Gen 2")
Depends-on: 0ea683931a ("gpio: dwapb: Convert driver to using the GPIO-lib-based IRQ-chip")
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Acked-by: Mika Westerberg <mika.westerberg@linux.intel.com>
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
2021-03-08 11:59:17 +01:00
Uwe Kleine-König 1421b447ae gpio: pca953x: Add support for pca9506
According to the reference manual "The PCA9505 is identical to the
PCA9506 except that it includes 100 kΩ internal pull-up resistors on all
the I/Os." So the pca9506 device can be considered identical to the
pca9505 for the gpio driver.

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
2021-02-15 11:43:27 +01:00
Linus Torvalds 0486beaf88 GPIO bulk changes for the v5.10 kernel cycle:
Core changes:
 
 - The big core change is the updated (v2) userspace character
   device API. This corrects badly designed 64-bit alignment around
   the line events. We also add the debounce request feature.
   This echoes the often quotes passage from Frederick Brooks
   "The mythical man-month" to always throw one away, which we
   have seen before in things such as V4L2. So we put in a new
   one and deprecate and obsolete the old one.
 
 - All example tools in tools/gpio/* are migrated to the new API
   to set a good example. The libgpiod userspace library has been
   augmented to use this new API pretty much from day 1.
 
 - Some misc API hardening by using strn* function calls has been
   added as well.
 
 - Use the simpler IDA interface for GPIO chip instance enumeration.
 
 - Add device core function for counting string arrays in
   device properties.
 
 - Provide a generic library function kfree_strarray() that can
   be used throughout the kernel.
 
 Driver enhancements:
 
 - The DesignWare dwapb-gpio driver has been enhanced and now
   uses the IRQ handling in the gpiolib core.
 
 - The mockup and aggregator drivers have seen some substantial
   code clean-up and now use more of the core kernel
   inftrastructure.
 
 - Misc cleanups using dev_err_probe().
 
 - The MXC drivers (Freescale/NXP) can now be built modularized,
   which makes modularized GKI Android kernels happy.
 -----BEGIN PGP SIGNATURE-----
 
 iQIzBAABCAAdFiEElDRnuGcz/wPCXQWMQRCzN7AZXXMFAl+FdjkACgkQQRCzN7AZ
 XXMYgQ/+JgpHrp7yS1IkS1KiAxHdeIGnKzloTCQQo1JxYEymAnIeMwo/iWAk5wHu
 NeJIEVxD0YzZwoI3BXbnO5Qy/62g1z7Ik8ToIa0TiFMwYxz5a7lqsiHwpBgHa50h
 T2N8FRFdslVrhpUYBH4Q9wlfYxTki4FwdTD6aaoFFGcMwIVJXWyaYzE+o+qEUEne
 VaPsGoNhRKTdKASP3c6+zbbPonzpZW7s/wvIBQAyBgPxEizlL97RzzX3bSSraoCX
 i0NsDLHMe+9twqE064KN+CYu0Cy80etQSQsYcfnstVshMuY9+WC1YdyJqzYMciuQ
 CYUIQBeskft86IBlsEU/fNCbV+FeAgrxRW6TJK7Hn+sUWZ5+UGdpJ03UE1hA3jjO
 SniwG0vpqvZIkio49B6h51VdjNqVJn+AE8tN3hCzqpFknblXgJOVysD7RS7rNM6D
 flV1bCsUYtC6jN43qsGFiRYLE9ml2iUxFFoBQUaAEh+pXgUzPTQqD7aSjyzmE3x2
 uapKXgxN0dCNH+tFXij73Ro4bYf4ZTZhx3Z3XoEUNEyJpl8fE1bv1SZ2EykOmK8g
 c78fAmT0vG3xYZvK10WZj4zuHV6GlPAYVm/MlhB7QHsrF3wa9vervOuqhEPmp2th
 hTsVj/Zlz0SSDLncMQL64B7gbxOmzOYlVRxIkSrDEXUOFU7kiWE=
 =8CE2
 -----END PGP SIGNATURE-----

Merge tag 'gpio-v5.10-1' of git://git.kernel.org/pub/scm/linux/kernel/git/linusw/linux-gpio

Pull GPIO updates from Linus Walleij:
 "This time very little driver changes but lots of core changes.

  We have some interesting cooperative work for ARM and Intel alike,
  making the GPIO subsystem more and more suitable for industrial
  systems and the like, in addition to the in-kernel users.

  We touch driver core (device properties) and lib/* by adding one
  simple string array free function, these are authored by Andy
  Shevchenko who is a well known and recognized core helpers maintainers
  so this should be fine.

  We also see some Android GKI-related modularization in the MXC
  drivers.

  Core changes:

   - The big core change is the updated (v2) userspace character device
     API.

     This corrects badly designed 64-bit alignment around the line
     events. We also add the debounce request feature. This echoes the
     often quotes passage from Frederick Brooks "The mythical man-month"
     to always throw one away, which we have seen before in things such
     as V4L2. So we put in a new one and deprecate and obsolete the old
     one.

   - All example tools in tools/gpio/* are migrated to the new API to
     set a good example. The libgpiod userspace library has been
     augmented to use this new API pretty much from day 1.

   - Some misc API hardening by using strn* function calls has been
     added as well.

   - Use the simpler IDA interface for GPIO chip instance enumeration.

   - Add device core function for counting string arrays in device
     properties.

   - Provide a generic library function kfree_strarray() that can be
     used throughout the kernel.

  Driver enhancements:

   - The DesignWare dwapb-gpio driver has been enhanced and now uses the
     IRQ handling in the gpiolib core.

   - The mockup and aggregator drivers have seen some substantial code
     clean-up and now use more of the core kernel inftrastructure.

   - Misc cleanups using dev_err_probe().

   - The MXC drivers (Freescale/NXP) can now be built modularized, which
     makes modularized GKI Android kernels happy"

* tag 'gpio-v5.10-1' of git://git.kernel.org/pub/scm/linux/kernel/git/linusw/linux-gpio: (73 commits)
  gpiolib: Update header block in gpiolib-cdev.h
  gpiolib: cdev: switch from kstrdup() to kstrndup()
  docs: gpio: add a new document to its index.rst
  gpio: pca953x: Add support for the NXP PCAL9554B/C
  tools: gpio: add debounce support to gpio-event-mon
  tools: gpio: add multi-line monitoring to gpio-event-mon
  tools: gpio: port gpio-event-mon to v2 uAPI
  tools: gpio: port gpio-hammer to v2 uAPI
  tools: gpio: rename nlines to num_lines
  tools: gpio: port gpio-watch to v2 uAPI
  tools: gpio: port lsgpio to v2 uAPI
  gpio: uapi: document uAPI v1 as deprecated
  gpiolib: cdev: support setting debounce
  gpiolib: cdev: support GPIO_V2_LINE_SET_VALUES_IOCTL
  gpiolib: cdev: support GPIO_V2_LINE_SET_CONFIG_IOCTL
  gpiolib: cdev: support edge detection for uAPI v2
  gpiolib: cdev: support GPIO_V2_GET_LINEINFO_IOCTL and GPIO_V2_GET_LINEINFO_WATCH_IOCTL
  gpiolib: cdev: support GPIO_V2_GET_LINE_IOCTL and GPIO_V2_LINE_GET_VALUES_IOCTL
  gpiolib: add build option for CDEV v1 ABI
  gpiolib: make cdev a build option
  ...
2020-10-13 10:09:33 -07:00
Marc Zyngier 8b81edd80b gpio: pca953x: Survive spurious interrupts
The pca953x driver never checks the result of irq_find_mapping(),
which returns 0 when no mapping is found. When a spurious interrupt
is delivered (which can happen under obscure circumstances), the
kernel explodes as it still tries to handle the error code as
a real interrupt.

Handle this particular case and warn on spurious interrupts.

Signed-off-by: Marc Zyngier <maz@kernel.org>
Link: https://lore.kernel.org/r/20201005140217.1390851-1-maz@kernel.org
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
2020-10-07 11:47:41 +02:00
Andy Shevchenko 8c1f1c3477 gpio: pca953x: Correctly initialize registers 6 and 7 for PCA957x
When driver has been converted to the bitmap API the non-bitmap functions
started behaving differently on 32-bit BE architectures since the bytes in
two consequent unsigned longs are in different order in comparison to byte
array. Hence if the chip had had more than 32 lines the memset() call over
it would have not set up upper lines correctly.
Although it's currently a theoretical case (no supported chips of this type
has 32+ lines), it's better to provide a clean code to avoid people thinking
this is okay and potentially producing not fully working things.

Fixes: 35d13d9489 ("gpio: pca953x: convert to use bitmap API")
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Reviewed-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
Link: https://lore.kernel.org/r/20200930142013.59247-2-andriy.shevchenko@linux.intel.com
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
2020-10-01 10:00:18 +02:00
Andy Shevchenko e09e200e07 gpio: pca953x: Use bitmap API over implicit GCC extension
In IRQ handler we have to clear bitmap before use. Currently
the GCC extension has been used for that. For sake of the consistency
switch to bitmap API. As expected bloat-o-meter shows no difference
in the object size.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Reviewed-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
Link: https://lore.kernel.org/r/20200930142013.59247-1-andriy.shevchenko@linux.intel.com
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
2020-10-01 10:00:17 +02:00
Mike Looijmans 237d96164f gpio: pca953x: Add support for the NXP PCAL9554B/C
The NXP PCAL9554B is a variant of the PCA953x GPIO expander,
with 8 GPIOs, latched interrupts and some advanced configuration
options. The "C" version only differs in I2C address.

Signed-off-by: Mike Looijmans <mike.looijmans@topic.nl>
Reviewed-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
Link: https://lore.kernel.org/r/20200930092053.2114-2-mike.looijmans@topic.nl
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
2020-09-30 11:50:34 +02:00
Ye Li e43c26e12d gpio: pca953x: Fix uninitialized pending variable
When pca953x_irq_pending returns false, the pending parameter won't
be set. But pca953x_irq_handler continues using this uninitialized
variable as pending irqs and will cause problem.
Fix the issue by initializing pending to 0.

Fixes: 064c73afe7 ("gpio: pca953x: Synchronize interrupt handler properly")
Signed-off-by: Ye Li <ye.li@nxp.com>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
2020-09-24 15:06:44 +02:00
Krzysztof Kozlowski ca6a77eb34 gpio: pca953x: Simplify with dev_err_probe()
Common pattern of handling deferred probe can be simplified with
dev_err_probe().  Less code and also it prints the error value.

Signed-off-by: Krzysztof Kozlowski <krzk@kernel.org>
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
2020-08-28 20:15:34 +02:00
Andy Shevchenko 2a93a0da06 gpio: pca953x: Request IRQ after all initialisation done
There is logically better to request IRQ when we initialise all structures.
Align the driver with the rest on the same matter.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Link: https://lore.kernel.org/r/20200728125504.27786-1-andriy.shevchenko@linux.intel.com
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
2020-08-04 01:25:02 +02:00
Linus Walleij edee3bc658 gpio: pca953x: Use irqchip template
This makes the driver use the irqchip template to assign
properties to the gpio_irq_chip instead of using the
explicit calls to gpiochip_irqchip_add_nested() and
gpiochip_set_nested_irqchip(). The irqchip is instead
added while adding the gpiochip.

Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Tested-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Cc: Marek Vasut <marek.vasut@gmail.com>
Cc: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Cc: Adam Ford <aford173@gmail.com>
Cc: Vignesh Raghavendra <vigneshr@ti.com>
Link: https://lore.kernel.org/r/20200717144040.63253-1-linus.walleij@linaro.org
2020-07-20 16:05:57 +02:00
Linus Walleij 4672a4a9fb Merge branch 'devel' into for-next 2020-07-09 17:06:28 +02:00
Andy Shevchenko 5d8913504c gpio: pca953x: Fix GPIO resource leak on Intel Galileo Gen 2
When adding a quirk for IRQ on Intel Galileo Gen 2 the commit ba8c90c618
("gpio: pca953x: Override IRQ for one of the expanders on Galileo Gen 2")
missed GPIO resource release. We can safely do this in the same quirk, since
IRQ will be locked by GPIO framework when requested and unlocked on freeing.

Fixes: ba8c90c618 ("gpio: pca953x: Override IRQ for one of the expanders on Galileo Gen 2")
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Cc: Mika Westerberg <mika.westerberg@linux.intel.com>
Reviewed-by: Mika Westerberg <mika.westerberg@linux.intel.com>
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
2020-06-22 18:51:53 +02:00
Andy Shevchenko ec3decd213 gpio: pca953x: disable regmap locking for automatic address incrementing
It's a repetition of the commit aa58a21ae3
  ("gpio: pca953x: disable regmap locking")
which states the following:

  This driver uses its own locking but regmap silently uses
  a mutex for all operations too. Add the option to disable
  locking to the regmap config struct.

Fixes: bcf41dc480 ("gpio: pca953x: fix handling of automatic address incrementing")
Cc: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Reviewed-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
2020-06-16 11:22:56 +02:00
Andy Shevchenko 0b22c25e1b gpio: pca953x: Fix direction setting when configure an IRQ
The commit 0f25fda840 ("gpio: pca953x: Zap ad-hoc reg_direction cache")
seems inadvertently made a typo in pca953x_irq_bus_sync_unlock().

When the direction bit is 1 it means input, and the piece of code in question
was looking for output ones that should be turned to inputs.

Fix direction setting when configure an IRQ by injecting a bitmap complement
operation.

Fixes: 0f25fda840 ("gpio: pca953x: Zap ad-hoc reg_direction cache")
Depends-on: 35d13d9489 ("gpio: pca953x: convert to use bitmap API")
Cc: Marek Vasut <marek.vasut@gmail.com>
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
2020-06-16 11:22:41 +02:00
Andy Shevchenko ba8c90c618 gpio: pca953x: Override IRQ for one of the expanders on Galileo Gen 2
ACPI table on Intel Galileo Gen 2 has wrong pin number for IRQ resource
of one of the I²C GPIO expanders. Since we know what that number is and
luckily have GPIO bases fixed for SoC's controllers, we may use a simple
DMI quirk to match the platform and retrieve GpioInt() pin on it for
the expander in question.

Mika suggested the way to avoid a quirk in the GPIO ACPI library and
here is the second, almost rewritten version of it.

Fixes: f32517bf1a ("gpio: pca953x: support ACPI devices found on Galileo Gen2")
Depends-on: 25e3ef894e ("gpio: acpi: Split out acpi_gpio_get_irq_resource() helper")
Suggested-by: Mika Westerberg <mika.westerberg@linux.intel.com>
Reviewed-by: Mika Westerberg <mika.westerberg@linux.intel.com>
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
2020-06-16 11:22:20 +02:00
Andy Shevchenko 064c73afe7 gpio: pca953x: Synchronize interrupt handler properly
Since the commit aa58a21ae3 ("gpio: pca953x: disable regmap locking")
the locking of regmap is disabled and that immediately introduces
a synchronization issue. It's easy to see when we try to monitor
more than one interrupt from the same chip.

It seems that the problem exists from the day one and even commit
6e20fb1805 ("drivers/gpio/pca953x.c: add a mutex to fix race condition")
missed this.

Below are the traces and shell reproducers before and after proposed change.
Note duplicates in the IRQ events. /proc/interrupts also shows a deviation,
i.e. sum of children interrupts higher than parent's one.

When locking is disabled for regmap and no protection in IRQ handler
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 ...
 gpioset-194          regmap_hw_write_start: i2c-INT3491:02 reg=2 count=1
 irq/31-i2c-INT3-139  regmap_hw_read_start: i2c-INT3491:02 reg=4c count=2
 gpioset-194          regmap_hw_write_done: i2c-INT3491:02 reg=2 count=1
 gpioset-194          regmap_reg_read_cache: i2c-INT3491:02 reg=6 val=f5
 gpioset-194          regmap_reg_write: i2c-INT3491:02 reg=6 val=f5
 gpioset-194          regmap_hw_write_start: i2c-INT3491:02 reg=6 count=1
 irq/31-i2c-INT3-139  regmap_hw_read_done: i2c-INT3491:02 reg=4c count=2
 ...

 % gpiomon gpiochip3 0 &
 % gpioset gpiochip3 1=0
 % gpioset gpiochip3 1=1
 event:  RISING EDGE offset: 0 timestamp: [     302.782583765]
 % gpiomon gpiochip3 2 &
 % gpioset gpiochip3 1=0
 event:  RISING EDGE offset: 2 timestamp: [     312.033148829]
 event: FALLING EDGE offset: 0 timestamp: [     312.022757525]
 % gpioset gpiochip3 1=1
 event:  RISING EDGE offset: 2 timestamp: [     316.201148473]
 event:  RISING EDGE offset: 0 timestamp: [     316.191759599]

When locking is disabled for regmap and protection in IRQ handler
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 ...
 gpioset-202          regmap_hw_write_start: i2c-INT3491:02 reg=2 count=1
 gpioset-202          regmap_hw_write_done: i2c-INT3491:02 reg=2 count=1
 gpioset-202          regmap_reg_read_cache: i2c-INT3491:02 reg=6 val=fd
 gpioset-202          regmap_reg_write: i2c-INT3491:02 reg=6 val=fd
 gpioset-202          regmap_hw_write_start: i2c-INT3491:02 reg=6 count=1
 gpioset-202          regmap_hw_write_done: i2c-INT3491:02 reg=6 count=1
 irq/31-i2c-INT3-139  regmap_hw_read_start: i2c-INT3491:02 reg=4c count=2
 irq/31-i2c-INT3-139  regmap_hw_read_done: i2c-INT3491:02 reg=4c count=2
 ...

 % gpiomon gpiochip3 0 &
 % gpioset gpiochip3 1=0
 event: FALLING EDGE offset: 0 timestamp: [     531.330078107]
 % gpioset gpiochip3 1=1
 event:  RISING EDGE offset: 0 timestamp: [     532.912239128]
 % gpiomon gpiochip3 2 &
 % gpioset gpiochip3 1=0
 event: FALLING EDGE offset: 0 timestamp: [     539.633669484]
 % gpioset gpiochip3 1=1
 event:  RISING EDGE offset: 0 timestamp: [     542.256978461]

Fixes: 6e20fb1805 ("drivers/gpio/pca953x.c: add a mutex to fix race condition")
Depends-on: 35d13d9489 ("gpio: pca953x: convert to use bitmap API")
Depends-on: 4942723276 ("gpio: pca953x: Perform basic regmap conversion")
Cc: Marek Vasut <marek.vasut@gmail.com>
Cc: Roland Stigge <stigge@antcom.de>
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
2020-06-16 11:21:51 +02:00
Jan Kiszka 3ba3ff5c09 gpio: pca953x: Add support for the PCAL9535
The PCAL9535 is compatible to the PCA9535. Additionally, it comes with
interrupt support and input latching. Other features are not supported
by the GPIO subsystem.

Datasheet: https://www.nxp.com/docs/en/data-sheet/PCAL9535A.pdf
Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
2020-06-16 10:49:18 +02:00
Andy Shevchenko 74910e15ab gpio: pca953x: Drop unneeded ACPI_PTR()
ACPI_PTR() becomes a no-op when !CONFIG_ACPI. This is not needed since
we always have ID table enabled. Moreover, in the mentioned case compiler
will complain about defined but not used variable.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Link: https://lore.kernel.org/r/20200520211916.25727-3-andriy.shevchenko@linux.intel.com
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
2020-06-03 14:04:28 +02:00
Linus Walleij ce1d966a30 Linux 5.7-rc7
-----BEGIN PGP SIGNATURE-----
 
 iQFSBAABCAA8FiEEq68RxlopcLEwq+PEeb4+QwBBGIYFAl7K9iEeHHRvcnZhbGRz
 QGxpbnV4LWZvdW5kYXRpb24ub3JnAAoJEHm+PkMAQRiGzTAH/0ifZEG4BQ8x/WlB
 8YLSLE6QQTSXYi25nyExuJbFkkKY5Tik8M2HD/36xwY/HnZOlH9jH6m0ntqZxpaA
 3EU9lr1ct79nCBMYhiJssvz8d9AOZXlyogFW9y2y9pmPjlmUtseZ7yGh1xD465cj
 B5Ty2w2W34cs7zF3og2xn5agOJMtWWXLXZ5mRa9EOquKC5zeYyRicmd0T+plYQD6
 hbRYmxFfDfppVnBCBARPNN0+NU5JJD94H+8bOuf1tl48XNrLiZMOicmtohKNQ6+W
 rZNpJNEGEp7KMtqWH0Nl3hmy3yfZHMwe1DXM/AZDqR7jTHZY4mZ0GEpLyfI9AU4n
 34jVHwU=
 =SmJ9
 -----END PGP SIGNATURE-----

Merge tag 'v5.7-rc7' into devel

Linux 5.7-rc7
2020-05-27 16:15:52 +02:00
Uwe Kleine-König 6fdeb6cbe1 gpio: pca953x: drop unused parameters of pca953x_recalc_addr()
After the previous patch the two last parameters of
pca953x_recalc_addr() are unused and so can be dropped.

Tested-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
2020-04-29 13:20:28 +02:00
Uwe Kleine-König bcf41dc480 gpio: pca953x: fix handling of automatic address incrementing
Some of the chips supported by the pca953x driver need the most
significant bit in the address word set to automatically increment the
address pointer on subsequent reads and writes (example: PCA9505). With
this bit unset the same register is read multiple times on a multi-byte
read sequence. Other chips must not have this bit set and autoincrement
always (example: PCA9555).

Up to now this AI bit was interpreted to be part of the address, which
resulted in inconsistent regmap caching when a register was written with
AI set and then read without it. This happened for the PCA9505 in
pca953x_gpio_set_multiple() where pca953x_read_regs() bulk read from the
cache for registers 0x8-0xc and then wrote to registers 0x88-0x8c. (Side
note: reading 5 values from offset 0x8 yiels OP0 5 times because AI must
be set to get OP0-OP4, which is another bug that is resolved here as a
by-product.) The same problem happens when calls to gpio_set_value() and
gpio_set_array_value() were mixed.

With this patch the AI bit is always set for chips that support it. This
works as there are no code locations that make use of the behaviour with
AI unset (for the chips that support it).

Note that the call to pca953x_setup_gpio() had to be done a bit earlier
to make the NBANK macro work.

The history of this bug is a bit complicated. Commit b32cecb46b
("gpio: pca953x: Extract the register address mangling to single
function") changed which chips and functions are affected. Commit
3b00691cc4 ("gpio: pca953x: hack to fix 24 bit gpio expanders") used
some duct tape to make the driver at least appear to work. Commit
4942723276 ("gpio: pca953x: Perform basic regmap conversion")
introduced the caching. Commit b4818afeac ("gpio: pca953x: Add
set_multiple to allow multiple bits to be set in one write.") introduced
the .set_multiple() callback which didn't work for chips that need the
AI bit which was fixed later for some chips in 8958262af3 ("gpio:
pca953x: Repair multi-byte IO address increment on PCA9575"). So I'm
sorry, I don't know which commit I should pick for a Fixes: line.

Tested-by: Marcel Gudert <m.gudert@eckelmann.de>
Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Tested-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
2020-04-29 13:19:51 +02:00
Andy Shevchenko 6f793485fc gpio: pca953x: Rewrite ->get_multiple() function
The commit 96d7c7b3e6 ("gpio: gpio-pca953x, Add get_multiple function")
basically did everything wrong from style and code reuse perspective, i.e.
- it didn't utilize existing PCA953x internal helpers
- it didn't utilize bitmap API
- it misses the point that ilog2(), besides that BANK_SFT is useless,
  can be used in macros
- it has indentation issues.

Rewrite the function completely.

Cc: Paul Thomas <pthomas8589@gmail.com>
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
2020-04-29 13:19:38 +02:00
Adam Ford dc87f6dd05 gpio: pca953x: Fix pca953x_gpio_set_config
pca953x_gpio_set_config is setup to support pull-up/down
bias.  Currently the driver uses a variable called 'config' to
determine which options to use.  Unfortunately, this is incorrect.

This patch uses function pinconf_to_config_param(config), which
converts this 'config' parameter back to pinconfig to determine
which option to use.

Fixes: 15add06841 ("gpio: pca953x: add ->set_config implementation")
Signed-off-by: Adam Ford <aford173@gmail.com>
Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
2020-04-23 17:55:26 +02:00
Bartosz Golaszewski aa58a21ae3 gpio: pca953x: disable regmap locking
This driver uses its own locking but regmap silently uses a mutex for
all operations too. Add the option to disable locking to the regmap
config struct.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
Reviewed-by: Geert Uytterhoeven <geert+renesas@glider.be>
Tested-by: Geert Uytterhoeven <geert+renesas@glider.be>
Acked-by: Linus Walleij <linus.walleij@linaro.org>
2020-04-17 08:25:29 +02:00