Commit fe61e07e authored by Jean Delvare's avatar Jean Delvare

i2c: Move adapter locking helpers to i2c-core

Uninline i2c adapter locking helper functions, move them to i2c-core,
and use them in i2c-core itself. The functions are still exported for
external users. This makes future updates to the locking model (which
will be needed for multiplexing support) possible and transparent.
Signed-off-by: default avatarJean Delvare <khali@linux-fr.org>
Cc: Michael Lawnick <ml.lawnick@gmx.de>
parent d44f19d5
...@@ -429,6 +429,35 @@ static int i2c_check_addr_busy(struct i2c_adapter *adapter, int addr) ...@@ -429,6 +429,35 @@ static int i2c_check_addr_busy(struct i2c_adapter *adapter, int addr)
__i2c_check_addr_busy); __i2c_check_addr_busy);
} }
/**
* i2c_lock_adapter - Get exclusive access to an I2C bus segment
* @adapter: Target I2C bus segment
*/
void i2c_lock_adapter(struct i2c_adapter *adapter)
{
rt_mutex_lock(&adapter->bus_lock);
}
EXPORT_SYMBOL_GPL(i2c_lock_adapter);
/**
* i2c_trylock_adapter - Try to get exclusive access to an I2C bus segment
* @adapter: Target I2C bus segment
*/
static int i2c_trylock_adapter(struct i2c_adapter *adapter)
{
return rt_mutex_trylock(&adapter->bus_lock);
}
/**
* i2c_unlock_adapter - Release exclusive access to an I2C bus segment
* @adapter: Target I2C bus segment
*/
void i2c_unlock_adapter(struct i2c_adapter *adapter)
{
rt_mutex_unlock(&adapter->bus_lock);
}
EXPORT_SYMBOL_GPL(i2c_unlock_adapter);
/** /**
* i2c_new_device - instantiate an i2c device * i2c_new_device - instantiate an i2c device
* @adap: the adapter managing the device * @adap: the adapter managing the device
...@@ -1238,12 +1267,12 @@ int i2c_transfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num) ...@@ -1238,12 +1267,12 @@ int i2c_transfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num)
#endif #endif
if (in_atomic() || irqs_disabled()) { if (in_atomic() || irqs_disabled()) {
ret = rt_mutex_trylock(&adap->bus_lock); ret = i2c_trylock_adapter(adap);
if (!ret) if (!ret)
/* I2C activity is ongoing. */ /* I2C activity is ongoing. */
return -EAGAIN; return -EAGAIN;
} else { } else {
rt_mutex_lock(&adap->bus_lock); i2c_lock_adapter(adap);
} }
/* Retry automatically on arbitration loss */ /* Retry automatically on arbitration loss */
...@@ -1255,7 +1284,7 @@ int i2c_transfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num) ...@@ -1255,7 +1284,7 @@ int i2c_transfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num)
if (time_after(jiffies, orig_jiffies + adap->timeout)) if (time_after(jiffies, orig_jiffies + adap->timeout))
break; break;
} }
rt_mutex_unlock(&adap->bus_lock); i2c_unlock_adapter(adap);
return ret; return ret;
} else { } else {
...@@ -2013,7 +2042,7 @@ s32 i2c_smbus_xfer(struct i2c_adapter *adapter, u16 addr, unsigned short flags, ...@@ -2013,7 +2042,7 @@ s32 i2c_smbus_xfer(struct i2c_adapter *adapter, u16 addr, unsigned short flags,
flags &= I2C_M_TEN | I2C_CLIENT_PEC; flags &= I2C_M_TEN | I2C_CLIENT_PEC;
if (adapter->algo->smbus_xfer) { if (adapter->algo->smbus_xfer) {
rt_mutex_lock(&adapter->bus_lock); i2c_lock_adapter(adapter);
/* Retry automatically on arbitration loss */ /* Retry automatically on arbitration loss */
orig_jiffies = jiffies; orig_jiffies = jiffies;
...@@ -2027,7 +2056,7 @@ s32 i2c_smbus_xfer(struct i2c_adapter *adapter, u16 addr, unsigned short flags, ...@@ -2027,7 +2056,7 @@ s32 i2c_smbus_xfer(struct i2c_adapter *adapter, u16 addr, unsigned short flags,
orig_jiffies + adapter->timeout)) orig_jiffies + adapter->timeout))
break; break;
} }
rt_mutex_unlock(&adapter->bus_lock); i2c_unlock_adapter(adapter);
} else } else
res = i2c_smbus_xfer_emulated(adapter, addr, flags, read_write, res = i2c_smbus_xfer_emulated(adapter, addr, flags, read_write,
command, protocol, data); command, protocol, data);
......
...@@ -382,23 +382,9 @@ static inline void i2c_set_adapdata(struct i2c_adapter *dev, void *data) ...@@ -382,23 +382,9 @@ static inline void i2c_set_adapdata(struct i2c_adapter *dev, void *data)
dev_set_drvdata(&dev->dev, data); dev_set_drvdata(&dev->dev, data);
} }
/** /* Adapter locking functions, exported for shared pin cases */
* i2c_lock_adapter - Prevent access to an I2C bus segment void i2c_lock_adapter(struct i2c_adapter *);
* @adapter: Target I2C bus segment void i2c_unlock_adapter(struct i2c_adapter *);
*/
static inline void i2c_lock_adapter(struct i2c_adapter *adapter)
{
rt_mutex_lock(&adapter->bus_lock);
}
/**
* i2c_unlock_adapter - Reauthorize access to an I2C bus segment
* @adapter: Target I2C bus segment
*/
static inline void i2c_unlock_adapter(struct i2c_adapter *adapter)
{
rt_mutex_unlock(&adapter->bus_lock);
}
/*flags for the client struct: */ /*flags for the client struct: */
#define I2C_CLIENT_PEC 0x04 /* Use Packet Error Checking */ #define I2C_CLIENT_PEC 0x04 /* Use Packet Error Checking */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment