designware_i2c: Enhance DesignWare I2C driver address support
PATCH 1/1 designware_i2c: Enhance DesignWare I2C driver address support
Enhance the DesignWare I2C driver to support address length more than 1 byte. This enhancement is required as some I2C slave device such as EEPROM chip might have 16 bit address byte.
--- drivers/i2c/designware_i2c.c | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-)
drivers/i2c/designware_i2c.c +9 -15
@@ -205,27 +205,21 @@ static int check_params(uint addr, int alen, uchar *buffer, int len)return 1 ; } -if (alen >1 ) { -printf ("addr len %d not supported\n" , alen); -return 1 ; - } - -if (addr + len >256 ) { -printf ("address out of range\n" ); -return 1 ; - } -return 0 ; } -static int i2c_xfer_init (uchar chip,uint addr) +static int i2c_xfer_init (uchar chip,uint addr,int alen) {if (i2c_wait_for_bb ())return 1 ;i2c_setaddress (chip); -writel (addr, &i2c_regs_p->ic_cmd_data); - +while (alen) { + alen--; +/* high byte address going out first */ +writel ((addr >> (alen *8 )) &0xff , + &i2c_regs_p->ic_cmd_data); + }return 0 ; }
@@ -269,7 +263,7 @@ int i2c_read(uchar chip, uint addr, int alen, uchar *buffer, int len)if (check_params (addr, alen, buffer, len))return 1 ; -if (i2c_xfer_init (chip, addr)) +if (i2c_xfer_init (chip, addr, alen))return 1 ; start_time_rx =get_timer (0 );
@@ -310,7 +304,7 @@ int i2c_write(uchar chip, uint addr, int alen, uchar *buffer, int len)if (check_params (addr, alen, buffer, len))return 1 ; -if (i2c_xfer_init (chip, addr)) +if (i2c_xfer_init (chip, addr, alen))return 1 ; start_time_tx =get_timer (0 );
Signature · 1 line
1.7.9.5
PATCH 1/1 designware_i2c: Enhance DesignWare I2C driver address support
Quoted 13 lines · Chin Liang See
Enhance the DesignWare I2C driver to support address length more than 1 byte. This enhancement is required as some I2C slave device such as EEPROM chip might have 16 bit address byte.
drivers/i2c/designware_i2c.c +0
-2@@ -205,27 +205,21 @@ static int check_params(uint addr, int alen, uchar *buffer, int len)return 1 ; } -if (alen >1 ) { -printf ("addr len %d not supported\n" , alen);
drivers/i2c/designware_i2c.c static int check_params(uint addr, int alen, uchar *buffer, int len) · line 209
Quoted 10 lines
drivers/i2c/designware_i2c.c +0
-8-return 1 ; - } - -if (addr + len >256 ) { -printf ("address out of range\n" ); -return 1 ; - } -return 0 ; }
Hi Chin,
if you strip down functionality of "check_params()" to one single check I would recommend you to remove "check_params()" at all and do in-place check for "buffer" existence.
Moreover you may just use "assert" for this check because this buffer is passed by u-boot (no need to check every parameter passed to any function in run-time) so in production/release build it won't exist at all.
Regards,
Alexey
PATCH 1/1 designware_i2c: Enhance DesignWare I2C driver address support
Hi Alexey,
Quoted 27 lines · Alexey Brodkin
Quoted 13 lines · Chin Liang See
Enhance the DesignWare I2C driver to support address length more than 1 byte. This enhancement is required as some I2C slave device such as EEPROM chip might have 16 bit address byte.
drivers/i2c/designware_i2c.c +0
-2@@ -205,27 +205,21 @@ static int check_params(uint addr, int alen, uchar *buffer, int len)return 1 ; } -if (alen >1 ) { -printf ("addr len %d not supported\n" , alen);drivers/i2c/designware_i2c.c static int check_params(uint addr, int alen, uchar *buffer, int len) · line 209
Quoted 10 lines
drivers/i2c/designware_i2c.c +0
-8-return 1 ; - } - -if (addr + len >256 ) { -printf ("address out of range\n" ); -return 1 ; - } -return 0 ; }Hi Chin,
Quoted 8 lines
if you strip down functionality of "
check_params()" to one single check I would recommend you to remove "check_params()" at all and do in-place check for "buffer" existence.Moreover you may just use "assert" for this check because this buffer is passed by u-boot (no need to check every parameter passed to any function in run-time) so in production/release build it won't exist at all.
Good suggestion. I agreed that we can strip off the check_params. Let me send the v2 patch. Thanks and have a nice day!
Chin Liang
Quoted 5 lines
Regards,
Alexey