i2c: Fix chip address.0
PATCH 1/1 i2c: Fix chip address.0
According to the i2c command alen 0 should be allowed but this is not allowed in the implementation, fix. Also cleanup all cmd_usage cases while at it. It is cleaner to return cmd_usage(cmdtp); instead of
{
cmd_usage(cmdtp);
return 1;
}
--- common/cmd_i2c.c | 107 +++++++++++++++++++++--------------------------------- 1 files changed, 41 insertions(+), 66 deletions(-)
common/cmd_i2c.c +41 -66
@@ -88,7 +88,7 @@*/ static uchar i2c_dp_last_chip;static uint i2c_dp_last_addr; -static uint i2c_dp_last_alen; +static int i2c_dp_last_alen;static uint i2c_dp_last_length =0x10 ;static uchar i2c_mm_last_chip;
@@ -154,7 +154,7 @@ int i2c_set_bus_speed(unsigned int)* get_alen: small parser helper function to get address length * returns the address length,or 0 on error */ -static uint get_alen (char *arg) +static int get_alen (char *arg) {int j;int alen;
@@ -164,7 +164,7 @@ static uint get_alen(char *arg)if (arg[j] =='.' ) { alen = arg[j+1 ] -'0' ;if (alen >3 ) { -return 0 ; +return -1 ; }break ; }else if (arg[j] =='\0' )
@@ -181,13 +181,12 @@ static uint get_alen(char *arg)static int do_i2c_read (cmd_tbl_t *cmdtp,int flag,int argc,char *argv[]) {u_char chip; -uint devaddr, alen, length; +uint devaddr, length; +int alen;u_char *memaddr; -if (argc !=5 ) { -cmd_usage (cmdtp); -return 1 ; - } +if (argc !=5 ) +return cmd_usage (cmdtp);/* * I2C chip address
@@ -200,10 +199,8 @@ static int do_i2c_read ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])*/ devaddr =simple_strtoul (argv[2 ],NULL ,16 ); alen =get_alen (argv[2 ]); -if (alen ==0 ) { -cmd_usage (cmdtp); -return 1 ; - } +if (alen <0 ) +return cmd_usage (cmdtp);/* * Length is the number of objects, not number of bytes.
@@ -229,7 +226,8 @@ static int do_i2c_read ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])static int do_i2c_md (cmd_tbl_t *cmdtp,int flag,int argc,char *argv[]) {u_char chip; -uint addr, alen, length; +uint addr, length; +int alen;int j, nbytes, linebytes;/* We use the last specified parameters, unless new ones are
@@ -240,10 +238,8 @@ static int do_i2c_md ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) alen = i2c_dp_last_alen; length = i2c_dp_last_length; -if (argc <3 ) { -cmd_usage (cmdtp); -return 1 ; - } +if (argc <3 ) +return cmd_usage (cmdtp);if ((flag &CMD_FLAG_REPEAT ) ==0 ) {/*
@@ -261,10 +257,8 @@ static int do_i2c_md ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])*/ addr =simple_strtoul (argv[2 ],NULL ,16 ); alen =get_alen (argv[2 ]); -if (alen ==0 ) { -cmd_usage (cmdtp); -return 1 ; - } +if (alen <0 ) +return cmd_usage (cmdtp);/* * If another parameter, it is the length to display.
@@ -328,14 +322,12 @@ static int do_i2c_mw ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) {uchar chip;ulong addr; -uint alen; +int alen;uchar byte;int count; -if ((argc <4 ) || (argc >5 )) { -cmd_usage (cmdtp); -return 1 ; - } +if ((argc <4 ) || (argc >5 )) +return cmd_usage (cmdtp);/* * Chip is always specified.
@@ -347,10 +339,8 @@ static int do_i2c_mw ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])*/ addr =simple_strtoul (argv[2 ],NULL ,16 ); alen =get_alen (argv[2 ]); -if (alen ==0 ) { -cmd_usage (cmdtp); -return 1 ; - } +if (alen <0 ) +return cmd_usage (cmdtp);/* * Value to write is always specified.
@@ -392,16 +382,14 @@ static int do_i2c_crc (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) {uchar chip;ulong addr; -uint alen; +int alen;int count;uchar byte;ulong crc;ulong err; -if (argc <4 ) { -cmd_usage (cmdtp); -return 1 ; - } +if (argc <4 ) +return cmd_usage (cmdtp);/* * Chip is always specified.
@@ -413,10 +401,8 @@ static int do_i2c_crc (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])*/ addr =simple_strtoul (argv[2 ],NULL ,16 ); alen =get_alen (argv[2 ]); -if (alen ==0 ) { -cmd_usage (cmdtp); -return 1 ; - } +if (alen <0 ) +return cmd_usage (cmdtp);/* * Count is always specified
@@ -456,16 +442,14 @@ mod_i2c_mem(cmd_tbl_t *cmdtp, int incrflag, int flag, int argc, char *argv[]) {uchar chip;ulong addr; -uint alen; +int alen;ulong data;int size =1 ;int nbytes;extern char console_buffer[]; -if (argc !=3 ) { -cmd_usage (cmdtp); -return 1 ; - } +if (argc !=3 ) +return cmd_usage (cmdtp);#ifdef CONFIG_BOOT_RETRY_TIME reset_cmd_timeout ();/* got a good command to get here */
@@ -495,10 +479,8 @@ mod_i2c_mem(cmd_tbl_t *cmdtp, int incrflag, int flag, int argc, char *argv[])*/ addr =simple_strtoul (argv[2 ],NULL ,16 ); alen =get_alen (argv[2 ]); -if (alen ==0 ) { -cmd_usage (cmdtp); -return 1 ; - } +if (alen <0 ) +return cmd_usage (cmdtp); }/*
@@ -622,16 +604,14 @@ static int do_i2c_probe (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])static int do_i2c_loop (cmd_tbl_t *cmdtp,int flag,int argc,char *argv[]) {u_char chip; -ulong alen; +int alen;uint addr;uint length;u_char bytes[16 ];int delay; -if (argc <3 ) { -cmd_usage (cmdtp); -return 1 ; - } +if (argc <3 ) +return cmd_usage (cmdtp);/* * Chip is always specified.
@@ -643,10 +623,8 @@ static int do_i2c_loop(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])*/ addr =simple_strtoul (argv[2 ],NULL ,16 ); alen =get_alen (argv[2 ]); -if (alen ==0 ) { -cmd_usage (cmdtp); -return 1 ; - } +if (alen <0 ) +return cmd_usage (cmdtp);/* * Length is the number of objects, not number of bytes.
@@ -784,10 +762,9 @@ static int do_sdram (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[]) "32 MiB", "16 MiB", "8 MiB", "4 MiB" }; -if (argc <2 ) { -cmd_usage (cmdtp); -return 1 ; - } +if (argc <2 ) +return cmd_usage (cmdtp); +/* * Chip is always specified. */
@@ -1322,12 +1299,10 @@ static int do_i2c(cmd_tbl_t * cmdtp, int flag, int argc, char *argv[]) c =find_cmd_tbl (argv[0 ], &cmd_i2c_sub[0 ],ARRAY_SIZE (cmd_i2c_sub)); -if (c) { +if (c)return c->cmd (cmdtp, flag, argc, argv); - }else { -cmd_usage (cmdtp); -return 1 ; - } +else +return cmd_usage (cmdtp); }/***************************************************/
Signature · 1 line
1.7.3.4
PATCH 1/1 i2c: Fix chip address.0
Hello Joakim,
Joakim Tjernlund write:
Quoted 9 lines
According to the i2c command alen 0 should be allowed but this is not allowed in the implementation, fix. Also cleanup all
cmd_usagecases while at it. It is cleaner to returncmd_usage(cmdtp); instead of
{
cmd_usage(cmdtp);
return 1;
}
Quoted 4 lines
Signed-off-by Joakim Tjernlund <[email protected]>--- common/cmd_i2c.c | 107 +++++++++++++++++++++--------------------------------- 1 files changed, 41 insertions(+), 66 deletions(-)
Hmm... did you use actual top of tree?
Your patch didn;t apply, also I think the issues your patch try to fix, should be fixed in TOT:
- actual TOT common/cmd_i2c.c uses "return cmd_usage(cmdtp);"
- alen of 0 should also be possible, fixed in commit 7a92e53cd0d8164d518216bebd52679603d6ffe9 from Reinhard Meyer.
Please try actual TOT
bye,
Heiko
Signature · 2 lines
DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
PATCH 1/1 i2c: Fix chip address.0
Heiko Schocher <[email protected]> wrote on 2011/01/31 08:18:56:
Quoted 13 lines
Hello Joakim,
Joakim Tjernlund write:
Quoted 9 lines
According to the i2c command alen 0 should be allowed but this is not allowed in the implementation, fix. Also cleanup all
cmd_usagecases while at it. It is cleaner to returncmd_usage(cmdtp); instead of
{
cmd_usage(cmdtp);
return 1;
}
Quoted 6 lines
Quoted 4 lines
Signed-off-by Joakim Tjernlund <[email protected]>--- common/cmd_i2c.c | 107 +++++++++++++++++++++--------------------------------- 1 files changed, 41 insertions(+), 66 deletions(-)Hmm... did you use actual top of tree?
Ahh, I used my current tree and it is a little behind. I see it fixed in TOT.
Jocke