i2c: add i2c_trylock_bus wrapper, use it
authorPeter Rosin <peda@axentia.se>
Wed, 29 Jun 2016 13:04:03 +0000 (15:04 +0200)
committerWolfram Sang <wsa@the-dreams.de>
Thu, 25 Aug 2016 16:02:14 +0000 (18:02 +0200)
This unifies usage with i2c_lock_bus and i2c_unlock_bus, and paves the
way for the next patch which looks a bit saner with this preparatory
work taken care of beforehand.

Signed-off-by: Peter Rosin <peda@axentia.se>
Signed-off-by: Wolfram Sang <wsa@the-dreams.de>
drivers/i2c/i2c-core.c
drivers/i2c/i2c-mux.c
include/linux/i2c.h

index da3a02e..56e50ca 100644 (file)
@@ -2459,7 +2459,7 @@ int i2c_transfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num)
 #endif
 
                if (in_atomic() || irqs_disabled()) {
 #endif
 
                if (in_atomic() || irqs_disabled()) {
-                       ret = adap->trylock_bus(adap, I2C_LOCK_SEGMENT);
+                       ret = i2c_trylock_bus(adap, I2C_LOCK_SEGMENT);
                        if (!ret)
                                /* I2C activity is ongoing. */
                                return -EAGAIN;
                        if (!ret)
                                /* I2C activity is ongoing. */
                                return -EAGAIN;
index 8eee986..764f195 100644 (file)
@@ -159,7 +159,7 @@ static int i2c_mux_trylock_bus(struct i2c_adapter *adapter, unsigned int flags)
                return 0;       /* mux_lock not locked, failure */
        if (!(flags & I2C_LOCK_ROOT_ADAPTER))
                return 1;       /* we only want mux_lock, success */
                return 0;       /* mux_lock not locked, failure */
        if (!(flags & I2C_LOCK_ROOT_ADAPTER))
                return 1;       /* we only want mux_lock, success */
-       if (parent->trylock_bus(parent, flags))
+       if (i2c_trylock_bus(parent, flags))
                return 1;       /* parent locked too, success */
        rt_mutex_unlock(&parent->mux_lock);
        return 0;               /* parent not locked, failure */
                return 1;       /* parent locked too, success */
        rt_mutex_unlock(&parent->mux_lock);
        return 0;               /* parent not locked, failure */
@@ -193,7 +193,7 @@ static int i2c_parent_trylock_bus(struct i2c_adapter *adapter,
 
        if (!rt_mutex_trylock(&parent->mux_lock))
                return 0;       /* mux_lock not locked, failure */
 
        if (!rt_mutex_trylock(&parent->mux_lock))
                return 0;       /* mux_lock not locked, failure */
-       if (parent->trylock_bus(parent, flags))
+       if (i2c_trylock_bus(parent, flags))
                return 1;       /* parent locked too, success */
        rt_mutex_unlock(&parent->mux_lock);
        return 0;               /* parent not locked, failure */
                return 1;       /* parent locked too, success */
        rt_mutex_unlock(&parent->mux_lock);
        return 0;               /* parent not locked, failure */
index fffdc27..c1f60a3 100644 (file)
@@ -600,6 +600,20 @@ i2c_lock_bus(struct i2c_adapter *adapter, unsigned int flags)
        adapter->lock_bus(adapter, flags);
 }
 
        adapter->lock_bus(adapter, flags);
 }
 
+/**
+ * i2c_trylock_bus - Try to get exclusive access to an I2C bus segment
+ * @adapter: Target I2C bus segment
+ * @flags: I2C_LOCK_ROOT_ADAPTER tries to locks the root i2c adapter,
+ *     I2C_LOCK_SEGMENT tries to lock only this branch in the adapter tree
+ *
+ * Return: true if the I2C bus segment is locked, false otherwise
+ */
+static inline int
+i2c_trylock_bus(struct i2c_adapter *adapter, unsigned int flags)
+{
+       return adapter->trylock_bus(adapter, flags);
+}
+
 /**
  * i2c_unlock_bus - Release exclusive access to an I2C bus segment
  * @adapter: Target I2C bus segment
 /**
  * i2c_unlock_bus - Release exclusive access to an I2C bus segment
  * @adapter: Target I2C bus segment