diff options
author | Wolfram Sang <wsa+renesas@sang-engineering.com> | 2019-04-03 14:40:09 +0200 |
---|---|---|
committer | Wolfram Sang <wsa@the-dreams.de> | 2019-04-16 13:08:11 +0200 |
commit | 83c42212d2544625b85f44a07d0ad96323e69250 (patch) | |
tree | f9fbca3a009f6e40eecce87ed42fc49eeef059dd /drivers/i2c/i2c-core.h | |
parent | bae1d3a05a8b99bd748168bbf8155a1d047c562e (diff) | |
download | linux-83c42212d2544625b85f44a07d0ad96323e69250.tar.bz2 |
i2c: core: use I2C locking behaviour also for SMBUS
If I2C transfers are executed in atomic contexts, trylock is used
instead of lock. This behaviour was missing for SMBUS, although a lot of
transfers are of SMBUS type, either emulated or direct. So, factor out
the locking routine into a helper and use it for I2C and SMBUS.
Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
Reviewed-by Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Wolfram Sang <wsa@the-dreams.de>
Diffstat (limited to 'drivers/i2c/i2c-core.h')
-rw-r--r-- | drivers/i2c/i2c-core.h | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/drivers/i2c/i2c-core.h b/drivers/i2c/i2c-core.h index 9d8526415b26..deea47c576e5 100644 --- a/drivers/i2c/i2c-core.h +++ b/drivers/i2c/i2c-core.h @@ -39,6 +39,18 @@ static inline bool i2c_in_atomic_xfer_mode(void) return system_state > SYSTEM_RUNNING && irqs_disabled(); } +static inline int __i2c_lock_bus_helper(struct i2c_adapter *adap) +{ + int ret = 0; + + if (i2c_in_atomic_xfer_mode()) + ret = i2c_trylock_bus(adap, I2C_LOCK_SEGMENT) ? 0 : -EAGAIN; + else + i2c_lock_bus(adap, I2C_LOCK_SEGMENT); + + return ret; +} + #ifdef CONFIG_ACPI const struct acpi_device_id * i2c_acpi_match_device(const struct acpi_device_id *matches, |