Commit fe61e07e9ebc890c70d97a1f72ddaad4bee2d848
1 parent
d44f19d586
Exists in
master
and in
7 other branches
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>
Showing 2 changed files with 37 additions and 22 deletions Side-by-side Diff
drivers/i2c/i2c-core.c
... | ... | @@ -430,6 +430,35 @@ |
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 | 462 | * i2c_new_device - instantiate an i2c device |
434 | 463 | * @adap: the adapter managing the device |
435 | 464 | * @info: describes one I2C device; bus_num is ignored |
436 | 465 | |
... | ... | @@ -1238,12 +1267,12 @@ |
1238 | 1267 | #endif |
1239 | 1268 | |
1240 | 1269 | if (in_atomic() || irqs_disabled()) { |
1241 | - ret = rt_mutex_trylock(&adap->bus_lock); | |
1270 | + ret = i2c_trylock_adapter(adap); | |
1242 | 1271 | if (!ret) |
1243 | 1272 | /* I2C activity is ongoing. */ |
1244 | 1273 | return -EAGAIN; |
1245 | 1274 | } else { |
1246 | - rt_mutex_lock(&adap->bus_lock); | |
1275 | + i2c_lock_adapter(adap); | |
1247 | 1276 | } |
1248 | 1277 | |
1249 | 1278 | /* Retry automatically on arbitration loss */ |
... | ... | @@ -1255,7 +1284,7 @@ |
1255 | 1284 | if (time_after(jiffies, orig_jiffies + adap->timeout)) |
1256 | 1285 | break; |
1257 | 1286 | } |
1258 | - rt_mutex_unlock(&adap->bus_lock); | |
1287 | + i2c_unlock_adapter(adap); | |
1259 | 1288 | |
1260 | 1289 | return ret; |
1261 | 1290 | } else { |
... | ... | @@ -2013,7 +2042,7 @@ |
2013 | 2042 | flags &= I2C_M_TEN | I2C_CLIENT_PEC; |
2014 | 2043 | |
2015 | 2044 | if (adapter->algo->smbus_xfer) { |
2016 | - rt_mutex_lock(&adapter->bus_lock); | |
2045 | + i2c_lock_adapter(adapter); | |
2017 | 2046 | |
2018 | 2047 | /* Retry automatically on arbitration loss */ |
2019 | 2048 | orig_jiffies = jiffies; |
... | ... | @@ -2027,7 +2056,7 @@ |
2027 | 2056 | orig_jiffies + adapter->timeout)) |
2028 | 2057 | break; |
2029 | 2058 | } |
2030 | - rt_mutex_unlock(&adapter->bus_lock); | |
2059 | + i2c_unlock_adapter(adapter); | |
2031 | 2060 | } else |
2032 | 2061 | res = i2c_smbus_xfer_emulated(adapter, addr, flags, read_write, |
2033 | 2062 | command, protocol, data); |
include/linux/i2c.h
... | ... | @@ -382,23 +382,9 @@ |
382 | 382 | dev_set_drvdata(&dev->dev, data); |
383 | 383 | } |
384 | 384 | |
385 | -/** | |
386 | - * i2c_lock_adapter - Prevent access to an I2C bus segment | |
387 | - * @adapter: Target I2C bus segment | |
388 | - */ | |
389 | -static inline void i2c_lock_adapter(struct i2c_adapter *adapter) | |
390 | -{ | |
391 | - rt_mutex_lock(&adapter->bus_lock); | |
392 | -} | |
393 | - | |
394 | -/** | |
395 | - * i2c_unlock_adapter - Reauthorize access to an I2C bus segment | |
396 | - * @adapter: Target I2C bus segment | |
397 | - */ | |
398 | -static inline void i2c_unlock_adapter(struct i2c_adapter *adapter) | |
399 | -{ | |
400 | - rt_mutex_unlock(&adapter->bus_lock); | |
401 | -} | |
385 | +/* Adapter locking functions, exported for shared pin cases */ | |
386 | +void i2c_lock_adapter(struct i2c_adapter *); | |
387 | +void i2c_unlock_adapter(struct i2c_adapter *); | |
402 | 388 | |
403 | 389 | /*flags for the client struct: */ |
404 | 390 | #define I2C_CLIENT_PEC 0x04 /* Use Packet Error Checking */ |