diff options
author | Jean Delvare <khali@linux-fr.org> | 2010-08-11 12:20:58 -0400 |
---|---|---|
committer | Jean Delvare <khali@linux-fr.org> | 2010-08-11 12:20:58 -0400 |
commit | fe61e07e9ebc890c70d97a1f72ddaad4bee2d848 (patch) | |
tree | e6ab84f0c09c555899884f2b730d205e3244dd8f /drivers/i2c | |
parent | d44f19d586b6113fb5db10e1a36457f0db3b01aa (diff) |
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: Jean Delvare <khali@linux-fr.org>
Cc: Michael Lawnick <ml.lawnick@gmx.de>
Diffstat (limited to 'drivers/i2c')
-rw-r--r-- | drivers/i2c/i2c-core.c | 39 |
1 files changed, 34 insertions, 5 deletions
diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c index 6e1c2f54d9cf..e09e143379b1 100644 --- a/drivers/i2c/i2c-core.c +++ b/drivers/i2c/i2c-core.c | |||
@@ -430,6 +430,35 @@ static int i2c_check_addr_busy(struct i2c_adapter *adapter, int addr) | |||
430 | } | 430 | } |
431 | 431 | ||
432 | /** | 432 | /** |
433 | * i2c_lock_adapter - Get exclusive access to an I2C bus segment | ||
434 | * @adapter: Target I2C bus segment | ||
435 | */ | ||
436 | void i2c_lock_adapter(struct i2c_adapter *adapter) | ||
437 | { | ||
438 | rt_mutex_lock(&adapter->bus_lock); | ||
439 | } | ||
440 | EXPORT_SYMBOL_GPL(i2c_lock_adapter); | ||
441 | |||
442 | /** | ||
443 | * i2c_trylock_adapter - Try to get exclusive access to an I2C bus segment | ||
444 | * @adapter: Target I2C bus segment | ||
445 | */ | ||
446 | static int i2c_trylock_adapter(struct i2c_adapter *adapter) | ||
447 | { | ||
448 | return rt_mutex_trylock(&adapter->bus_lock); | ||
449 | } | ||
450 | |||
451 | /** | ||
452 | * i2c_unlock_adapter - Release exclusive access to an I2C bus segment | ||
453 | * @adapter: Target I2C bus segment | ||
454 | */ | ||
455 | void i2c_unlock_adapter(struct i2c_adapter *adapter) | ||
456 | { | ||
457 | rt_mutex_unlock(&adapter->bus_lock); | ||
458 | } | ||
459 | EXPORT_SYMBOL_GPL(i2c_unlock_adapter); | ||
460 | |||
461 | /** | ||
433 | * i2c_new_device - instantiate an i2c device | 462 | * i2c_new_device - instantiate an i2c device |
434 | * @adap: the adapter managing the device | 463 | * @adap: the adapter managing the device |
435 | * @info: describes one I2C device; bus_num is ignored | 464 | * @info: describes one I2C device; bus_num is ignored |
@@ -1238,12 +1267,12 @@ int i2c_transfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num) | |||
1238 | #endif | 1267 | #endif |
1239 | 1268 | ||
1240 | if (in_atomic() || irqs_disabled()) { | 1269 | if (in_atomic() || irqs_disabled()) { |
1241 | ret = rt_mutex_trylock(&adap->bus_lock); | 1270 | ret = i2c_trylock_adapter(adap); |
1242 | if (!ret) | 1271 | if (!ret) |
1243 | /* I2C activity is ongoing. */ | 1272 | /* I2C activity is ongoing. */ |
1244 | return -EAGAIN; | 1273 | return -EAGAIN; |
1245 | } else { | 1274 | } else { |
1246 | rt_mutex_lock(&adap->bus_lock); | 1275 | i2c_lock_adapter(adap); |
1247 | } | 1276 | } |
1248 | 1277 | ||
1249 | /* Retry automatically on arbitration loss */ | 1278 | /* Retry automatically on arbitration loss */ |
@@ -1255,7 +1284,7 @@ int i2c_transfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num) | |||
1255 | if (time_after(jiffies, orig_jiffies + adap->timeout)) | 1284 | if (time_after(jiffies, orig_jiffies + adap->timeout)) |
1256 | break; | 1285 | break; |
1257 | } | 1286 | } |
1258 | rt_mutex_unlock(&adap->bus_lock); | 1287 | i2c_unlock_adapter(adap); |
1259 | 1288 | ||
1260 | return ret; | 1289 | return ret; |
1261 | } else { | 1290 | } else { |
@@ -2013,7 +2042,7 @@ s32 i2c_smbus_xfer(struct i2c_adapter *adapter, u16 addr, unsigned short flags, | |||
2013 | flags &= I2C_M_TEN | I2C_CLIENT_PEC; | 2042 | flags &= I2C_M_TEN | I2C_CLIENT_PEC; |
2014 | 2043 | ||
2015 | if (adapter->algo->smbus_xfer) { | 2044 | if (adapter->algo->smbus_xfer) { |
2016 | rt_mutex_lock(&adapter->bus_lock); | 2045 | i2c_lock_adapter(adapter); |
2017 | 2046 | ||
2018 | /* Retry automatically on arbitration loss */ | 2047 | /* Retry automatically on arbitration loss */ |
2019 | orig_jiffies = jiffies; | 2048 | orig_jiffies = jiffies; |
@@ -2027,7 +2056,7 @@ s32 i2c_smbus_xfer(struct i2c_adapter *adapter, u16 addr, unsigned short flags, | |||
2027 | orig_jiffies + adapter->timeout)) | 2056 | orig_jiffies + adapter->timeout)) |
2028 | break; | 2057 | break; |
2029 | } | 2058 | } |
2030 | rt_mutex_unlock(&adapter->bus_lock); | 2059 | i2c_unlock_adapter(adapter); |
2031 | } else | 2060 | } else |
2032 | res = i2c_smbus_xfer_emulated(adapter, addr, flags, read_write, | 2061 | res = i2c_smbus_xfer_emulated(adapter, addr, flags, read_write, |
2033 | command, protocol, data); | 2062 | command, protocol, data); |