2c: modify i2c_read API to handle multi-bytes writes
PATCH 1/1 2c: modify i2c_read API to handle multi-bytes writes
Most of the I2C slaves support accesses in the typical style viz.read/write series of bytes at particular address offset. These transactions are currently supportd in the
i2c driver using i2c_read and i2c_write APIs. I2C EEPROMs, RTC, etc fall in this category.
The transactions look like:" START:Address:Tx:Offset:RESTART:Address[0..4]:Tx/Rx:data[0..n]:STOP"
However there are certain devices which support accesses in terms of the transactions as follows:
"START:Address:Tx:Txdata[0..n1]:Clock_stretching:
RESTART:Address:Rx:data[0..n2]"
The Txdata is typically a command and some associated data, similarly Rxdata could be command status plus some data received as a response to the command sent.i2c_read() function has been modified to handle
both types of transactions:
the one that writes only offset/address before read and other that writes some bytes(more than 4 bytes) before read
To handle the case:
Negative equivalent of length has been passed and interpreted accordinglt and txdata is being passed in rxdata buffer
--- drivers/i2c/fsl_i2c.c | 40 +++++++++++++++++++++++++++++++--------- 1 files changed, 31 insertions(+), 9 deletions(-)
drivers/i2c/fsl_i2c.c +31 -9
@@ -424,17 +424,39 @@ fsl_i2c_read(struct i2c_adapter *adap, u8 dev, uint addr, int alen, u8 *data,int i =-1 ;/* signal error */ u8 *a = (u8 *)&addr; -if (i2c_wait4bus (adap) <0 ) -return -1 ; +if (alen <0 ) { +int len = alen *-1 ; +if (i2c_wait4bus (adap) <0 ) +return -1 ; + +/* Generate a START and send the Address and +* the Tx Bytes to the slave. +* "START: Address: Write bytes wdata[wlength]" +* It supports writing any number of bytes in contrast +* to the else part, which supports writing address offset +* of upto 4 bytes only. +*/ +if (i2c_write_addr (adap, dev,I2C_WRITE_BIT ,0 ) !=0 ) + i =__i2c_write (adap, data, len); + +if (i != len) +return -1 ; + +if (length &&i2c_write_addr (adap, dev,I2C_READ_BIT ,1 ) !=0 ) + i =__i2c_read (adap, data, length); + }else { +if (i2c_wait4bus (adap) <0 ) +return -1 ; -if ((!length || alen >0 ) - &&i2c_write_addr (adap, dev,I2C_WRITE_BIT ,0 ) !=0 - &&__i2c_write (adap, &a[4 - alen], alen) == alen) - i =0 ;/* No error so far */ +if ((!length || alen >0 ) && +i2c_write_addr (adap, dev,I2C_WRITE_BIT ,0 ) !=0 && +__i2c_write (adap, &a[4 - alen], alen) == alen) + i =0 ;/* No error so far */ -if (length && -i2c_write_addr (adap, dev,I2C_READ_BIT , alen ?1 :0 ) !=0 ) - i =__i2c_read (adap, data, length); +if (length && +i2c_write_addr (adap, dev,I2C_READ_BIT , alen ?1 :0 ) !=0 ) + i =__i2c_read (adap, data, length); + }writeb (I2C_CR_MEN , &device->cr);
Signature · 1 line
1.7.6.GIT
PATCH 1/1 2c: modify i2c_read API to handle multi-bytes writes
Quoted 2 lines · Shaveta Leekha
Most of the I2C slaves support accesses in the typical style viz.read/write series of bytes at particular address offset.
viz?
Quoted 11 lines
These transactions are currently supportd in the
i2c driver usingi2c_readandi2c_writeAPIs. I2C EEPROMs, RTC, etc fall in this category.
The transactions look like:" START:Address:Tx:Offset:RESTART:Address[0..4]:Tx/Rx:data[0..n]:STOP"However there are certain devices which support accesses in terms of the transactions as follows:
"START:Address:Tx:Txdata[0..n1]:Clock_stretching:RESTART:Address:Rx:data[0..n2]"
Quoted 7 lines
The Txdata is typically a command and some associated data, similarly Rxdata could be command status plus some data received as a response to the command sent.
i2c_read()function has been modified to handle
both types of transactions:
the one that writes only offset/address before read and other that writes some bytes(more than 4 bytes) before read
Please rephrase this sentence. It is not very clear.
Quoted 5 lines
To handle the case:
Negative equivalent of length has been passed and interpreted accordinglt and txdata is being passed in rxdata buffer
This belongs to inline comments. You should explain more in detail in the comment. Commit message helps but it is hard to find in long term.
Quoted 12 lines
Signed-off-by Shaveta Leekha <[email protected]>Signed-off-by Poonam Aggrwal <[email protected]>--- drivers/i2c/fsl_i2c.c | 40 +++++++++++++++++++++++++++++++--------- 1 files changed, 31 insertions(+), 9 deletions(-)drivers/i2c/fsl_i2c.c +0
-0
drivers/i2c/fsl_i2c.c fsl_i2c_read(struct i2c_adapter *adap, u8 dev, uint addr, int alen, u8 *data, · line 428
Quoted 5 lines
drivers/i2c/fsl_i2c.c +0
-2@@ -424,17 +424,39 @@ fsl_i2c_read(struct i2c_adapter *adap, u8 dev, uint addr, int alen, u8 *data,int i =-1 ;/* signal error */ u8 *a = (u8 *)&addr; -if (i2c_wait4bus (adap) <0 ) -return -1 ;
You don't need to move these two lines.
drivers/i2c/fsl_i2c.c fsl_i2c_read(struct i2c_adapter *adap, u8 dev, uint addr, int alen, u8 *data, · line 427
Quoted 1 line
drivers/i2c/fsl_i2c.c +1
-0+if (alen <0 ) {
You need to put a lot of comment to explain here.
drivers/i2c/fsl_i2c.c fsl_i2c_read(struct i2c_adapter *adap, u8 dev, uint addr, int alen, u8 *data, · line 428
Quoted 1 line
drivers/i2c/fsl_i2c.c +1
-0+int len = alen *-1 ;
You don't really need a new variable here. Even you do, put the variable declaration to the beginning of the function.
drivers/i2c/fsl_i2c.c fsl_i2c_read(struct i2c_adapter *adap, u8 dev, uint addr, int alen, u8 *data, · line 440
Quoted 12 lines
drivers/i2c/fsl_i2c.c +12
-0+if (i2c_wait4bus (adap) <0 ) +return -1 ; + +/* Generate a START and send the Address and +* the Tx Bytes to the slave. +* "START: Address: Write bytes wdata[wlength]" +* It supports writing any number of bytes in contrast +* to the else part, which supports writing address offset +* of upto 4 bytes only. +*/ +if (i2c_write_addr (adap, dev,I2C_WRITE_BIT ,0 ) !=0 ) + i =__i2c_write (adap, data, len);
And explain how you use "data".
York