From 83c42212d2544625b85f44a07d0ad96323e69250 Mon Sep 17 00:00:00 2001 From: Wolfram Sang Date: Wed, 3 Apr 2019 14:40:09 +0200 Subject: 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 Reviewed-by Andy Shevchenko Signed-off-by: Wolfram Sang --- drivers/i2c/i2c-core.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'drivers/i2c/i2c-core.h') 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, -- cgit v1.2.3