Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

+37 -22
+34 -5
drivers/i2c/i2c-core.c
··· 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 ··· 1267 1238 #endif 1268 1239 1269 1240 if (in_atomic() || irqs_disabled()) { 1270 - ret = rt_mutex_trylock(&adap->bus_lock); 1241 + ret = i2c_trylock_adapter(adap); 1271 1242 if (!ret) 1272 1243 /* I2C activity is ongoing. */ 1273 1244 return -EAGAIN; 1274 1245 } else { 1275 - rt_mutex_lock(&adap->bus_lock); 1246 + i2c_lock_adapter(adap); 1276 1247 } 1277 1248 1278 1249 /* Retry automatically on arbitration loss */ ··· 1284 1255 if (time_after(jiffies, orig_jiffies + adap->timeout)) 1285 1256 break; 1286 1257 } 1287 - rt_mutex_unlock(&adap->bus_lock); 1258 + i2c_unlock_adapter(adap); 1288 1259 1289 1260 return ret; 1290 1261 } else { ··· 2042 2013 flags &= I2C_M_TEN | I2C_CLIENT_PEC; 2043 2014 2044 2015 if (adapter->algo->smbus_xfer) { 2045 - rt_mutex_lock(&adapter->bus_lock); 2016 + i2c_lock_adapter(adapter); 2046 2017 2047 2018 /* Retry automatically on arbitration loss */ 2048 2019 orig_jiffies = jiffies; ··· 2056 2027 orig_jiffies + adapter->timeout)) 2057 2028 break; 2058 2029 } 2059 - rt_mutex_unlock(&adapter->bus_lock); 2030 + i2c_unlock_adapter(adapter); 2060 2031 } else 2061 2032 res = i2c_smbus_xfer_emulated(adapter, addr, flags, read_write, 2062 2033 command, protocol, data);
+3 -17
include/linux/i2c.h
··· 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 */