Skip to content

Commit afa0897

Browse files
author
Jean Delvare
committed
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>
1 parent 3806e94 commit afa0897

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

drivers/net/sfc/sfe4001.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ static int sfn4111t_reset(struct efx_nic *efx)
188188
efx_oword_t reg;
189189

190190
/* 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);
192192

193193
/* Pull RST_N (GPIO 2) low then let it up again, setting the
194194
* FLASH_CFG_1 strap (GPIO 3) appropriately. Only change the
@@ -204,7 +204,7 @@ static int sfn4111t_reset(struct efx_nic *efx)
204204
falcon_write(efx, &reg, GPIO_CTL_REG_KER);
205205
msleep(1);
206206

207-
mutex_unlock(&efx->i2c_adap.bus_lock);
207+
i2c_unlock_adapter(&efx->i2c_adap);
208208

209209
ssleep(1);
210210
return 0;

include/linux/i2c.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,24 @@ static inline void i2c_set_adapdata(struct i2c_adapter *dev, void *data)
361361
dev_set_drvdata(&dev->dev, data);
362362
}
363363

364+
/**
365+
* i2c_lock_adapter - Prevent access to an I2C bus segment
366+
* @adapter: Target I2C bus segment
367+
*/
368+
static 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+
*/
377+
static inline void i2c_unlock_adapter(struct i2c_adapter *adapter)
378+
{
379+
mutex_unlock(&adapter->bus_lock);
380+
}
381+
364382
/*flags for the client struct: */
365383
#define I2C_CLIENT_PEC 0x04 /* Use Packet Error Checking */
366384
#define I2C_CLIENT_TEN 0x10 /* we have a ten bit chip address */

0 commit comments

Comments
 (0)