Skip to content

Commit

Permalink
i2c: Add an interface to lock/unlock an I2C bus segment
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Jean Delvare committed Nov 7, 2009
1 parent 3806e94 commit afa0897
Showing 2 changed files with 20 additions and 2 deletions.
4 changes: 2 additions & 2 deletions drivers/net/sfc/sfe4001.c
Original file line number Diff line number Diff line change
@@ -188,7 +188,7 @@ static int sfn4111t_reset(struct efx_nic *efx)
efx_oword_t reg;

/* GPIO 3 and the GPIO register are shared with I2C, so block that */
mutex_lock(&efx->i2c_adap.bus_lock);
i2c_lock_adapter(&efx->i2c_adap);

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

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

ssleep(1);
return 0;
18 changes: 18 additions & 0 deletions include/linux/i2c.h
Original file line number Diff line number Diff line change
@@ -361,6 +361,24 @@ static inline void i2c_set_adapdata(struct i2c_adapter *dev, void *data)
dev_set_drvdata(&dev->dev, data);
}

/**
* i2c_lock_adapter - Prevent access to an I2C bus segment
* @adapter: Target I2C bus segment
*/
static inline void i2c_lock_adapter(struct i2c_adapter *adapter)
{
mutex_lock(&adapter->bus_lock);
}

/**
* i2c_unlock_adapter - Reauthorize access to an I2C bus segment
* @adapter: Target I2C bus segment
*/
static inline void i2c_unlock_adapter(struct i2c_adapter *adapter)
{
mutex_unlock(&adapter->bus_lock);
}

/*flags for the client struct: */
#define I2C_CLIENT_PEC 0x04 /* Use Packet Error Checking */
#define I2C_CLIENT_TEN 0x10 /* we have a ten bit chip address */

0 comments on commit afa0897

Please sign in to comment.