aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJean Delvare <khali@linux-fr.org>2009-11-07 07:10:46 -0500
committerJean Delvare <khali@linux-fr.org>2009-11-07 07:10:46 -0500
commitafa08974fe80c198b8650f73ed8ab59135ca10d0 (patch)
treeb649e06dc4cb9fa10b87f1914f05c6ca2ba0d910
parent3806e94b0148350c72f9a3214274026b6ca03f49 (diff)
i2c: Add an interface to lock/unlock an I2C bus segment
Some drivers need to be able to prevent access to an I2C bus segment for a specific period of time. Add an interface for them to do so without twiddling with i2c-core internals. Signed-off-by: Jean Delvare <khali@linux-fr.org> Acked-by: Ben Hutchings <bhutchings@solarflare.com>
-rw-r--r--drivers/net/sfc/sfe4001.c4
-rw-r--r--include/linux/i2c.h18
2 files changed, 20 insertions, 2 deletions
diff --git a/drivers/net/sfc/sfe4001.c b/drivers/net/sfc/sfe4001.c
index cee00ad49b57..49eb91b5f50c 100644
--- a/drivers/net/sfc/sfe4001.c
+++ b/drivers/net/sfc/sfe4001.c
@@ -188,7 +188,7 @@ static int sfn4111t_reset(struct efx_nic *efx)
188 efx_oword_t reg; 188 efx_oword_t reg;
189 189
190 /* GPIO 3 and the GPIO register are shared with I2C, so block that */ 190 /* GPIO 3 and the GPIO register are shared with I2C, so block that */
191 mutex_lock(&efx->i2c_adap.bus_lock); 191 i2c_lock_adapter(&efx->i2c_adap);
192 192
193 /* Pull RST_N (GPIO 2) low then let it up again, setting the 193 /* Pull RST_N (GPIO 2) low then let it up again, setting the
194 * FLASH_CFG_1 strap (GPIO 3) appropriately. Only change the 194 * FLASH_CFG_1 strap (GPIO 3) appropriately. Only change the
@@ -204,7 +204,7 @@ static int sfn4111t_reset(struct efx_nic *efx)
204 falcon_write(efx, &reg, GPIO_CTL_REG_KER); 204 falcon_write(efx, &reg, GPIO_CTL_REG_KER);
205 msleep(1); 205 msleep(1);
206 206
207 mutex_unlock(&efx->i2c_adap.bus_lock); 207 i2c_unlock_adapter(&efx->i2c_adap);
208 208
209 ssleep(1); 209 ssleep(1);
210 return 0; 210 return 0;
diff --git a/include/linux/i2c.h b/include/linux/i2c.h
index 57d41b0abce2..7b40cda57a70 100644
--- a/include/linux/i2c.h
+++ b/include/linux/i2c.h
@@ -361,6 +361,24 @@ static inline void i2c_set_adapdata(struct i2c_adapter *dev, void *data)
361 dev_set_drvdata(&dev->dev, data); 361 dev_set_drvdata(&dev->dev, data);
362} 362}
363 363
364/**
365 * i2c_lock_adapter - Prevent access to an I2C bus segment
366 * @adapter: Target I2C bus segment
367 */
368static inline void i2c_lock_adapter(struct i2c_adapter *adapter)
369{
370 mutex_lock(&adapter->bus_lock);
371}
372
373/**
374 * i2c_unlock_adapter - Reauthorize access to an I2C bus segment
375 * @adapter: Target I2C bus segment
376 */
377static inline void i2c_unlock_adapter(struct i2c_adapter *adapter)
378{
379 mutex_unlock(&adapter->bus_lock);
380}
381
364/*flags for the client struct: */ 382/*flags for the client struct: */
365#define I2C_CLIENT_PEC 0x04 /* Use Packet Error Checking */ 383#define I2C_CLIENT_PEC 0x04 /* Use Packet Error Checking */
366#define I2C_CLIENT_TEN 0x10 /* we have a ten bit chip address */ 384#define I2C_CLIENT_TEN 0x10 /* we have a ten bit chip address */