Allow data-only i2c transfers
Modified the i2c_imx driver to support data-only transfers, without command byte. This allows to construct more complex i2c transfers and support non genuine devices like Atmel ATxx secure memory, where the master reads data after a write command. Signed-off-by: Rosen Kolev <rosen.kolev@amk-drives.bg> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
This commit is contained in:
parent
c7efd11b38
commit
502ecda2d1
|
@ -314,19 +314,21 @@ static int i2c_imx_write(struct i2c_adapter *adapter, struct i2c_msg *msgs)
|
||||||
void __iomem *base = i2c_imx->base;
|
void __iomem *base = i2c_imx->base;
|
||||||
int i, result;
|
int i, result;
|
||||||
|
|
||||||
dev_dbg(adapter->dev,
|
if ( !(msgs->flags & I2C_M_DATA_ONLY) ) {
|
||||||
"<%s> write slave address: addr=0x%02x\n",
|
dev_dbg(adapter->dev,
|
||||||
__func__, msgs->addr << 1);
|
"<%s> write slave address: addr=0x%02x\n",
|
||||||
|
__func__, msgs->addr << 1);
|
||||||
|
|
||||||
/* write slave address */
|
/* write slave address */
|
||||||
writeb(msgs->addr << 1, base + IMX_I2C_I2DR);
|
writeb(msgs->addr << 1, base + IMX_I2C_I2DR);
|
||||||
|
|
||||||
result = i2c_imx_trx_complete(adapter);
|
result = i2c_imx_trx_complete(adapter);
|
||||||
if (result)
|
if (result)
|
||||||
return result;
|
return result;
|
||||||
result = i2c_imx_acked(adapter);
|
result = i2c_imx_acked(adapter);
|
||||||
if (result)
|
if (result)
|
||||||
return result;
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
/* write data */
|
/* write data */
|
||||||
for (i = 0; i < msgs->len; i++) {
|
for (i = 0; i < msgs->len; i++) {
|
||||||
|
@ -352,22 +354,24 @@ static int i2c_imx_read(struct i2c_adapter *adapter, struct i2c_msg *msgs)
|
||||||
int i, result;
|
int i, result;
|
||||||
unsigned int temp;
|
unsigned int temp;
|
||||||
|
|
||||||
dev_dbg(adapter->dev,
|
|
||||||
"<%s> write slave address: addr=0x%02x\n",
|
|
||||||
__func__, (msgs->addr << 1) | 0x01);
|
|
||||||
|
|
||||||
/* clear IIF */
|
/* clear IIF */
|
||||||
writeb(0x0, base + IMX_I2C_I2SR);
|
writeb(0x0, base + IMX_I2C_I2SR);
|
||||||
|
|
||||||
/* write slave address */
|
if ( !(msgs->flags & I2C_M_DATA_ONLY) ) {
|
||||||
writeb((msgs->addr << 1) | 0x01, base + IMX_I2C_I2DR);
|
dev_dbg(adapter->dev,
|
||||||
|
"<%s> write slave address: addr=0x%02x\n",
|
||||||
|
__func__, (msgs->addr << 1) | 0x01);
|
||||||
|
|
||||||
result = i2c_imx_trx_complete(adapter);
|
/* write slave address */
|
||||||
if (result)
|
writeb((msgs->addr << 1) | 0x01, base + IMX_I2C_I2DR);
|
||||||
return result;
|
|
||||||
result = i2c_imx_acked(adapter);
|
result = i2c_imx_trx_complete(adapter);
|
||||||
if (result)
|
if (result)
|
||||||
return result;
|
return result;
|
||||||
|
result = i2c_imx_acked(adapter);
|
||||||
|
if (result)
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
/* setup bus to read data */
|
/* setup bus to read data */
|
||||||
temp = readb(base + IMX_I2C_I2CR);
|
temp = readb(base + IMX_I2C_I2CR);
|
||||||
|
@ -428,7 +432,7 @@ static int i2c_imx_xfer(struct i2c_adapter *adapter,
|
||||||
|
|
||||||
/* read/write data */
|
/* read/write data */
|
||||||
for (i = 0; i < num; i++) {
|
for (i = 0; i < num; i++) {
|
||||||
if (i) {
|
if (i && !(msgs[i].flags & I2C_M_DATA_ONLY)) {
|
||||||
temp = readb(base + IMX_I2C_I2CR);
|
temp = readb(base + IMX_I2C_I2CR);
|
||||||
temp |= I2CR_RSTA;
|
temp |= I2CR_RSTA;
|
||||||
writeb(temp, base + IMX_I2C_I2CR);
|
writeb(temp, base + IMX_I2C_I2CR);
|
||||||
|
|
|
@ -30,6 +30,7 @@ struct i2c_platform_data {
|
||||||
#define I2C_NAME_SIZE 20
|
#define I2C_NAME_SIZE 20
|
||||||
|
|
||||||
#define I2C_M_RD 0x0001 /* read data, from slave to master */
|
#define I2C_M_RD 0x0001 /* read data, from slave to master */
|
||||||
|
#define I2C_M_DATA_ONLY 0x0002 /* transfer data bytes only */
|
||||||
#define I2C_M_TEN 0x0010 /* this is a ten bit chip address */
|
#define I2C_M_TEN 0x0010 /* this is a ten bit chip address */
|
||||||
#define I2C_M_IGNORE_NAK 0x1000 /* if I2C_FUNC_PROTOCOL_MANGLING */
|
#define I2C_M_IGNORE_NAK 0x1000 /* if I2C_FUNC_PROTOCOL_MANGLING */
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue