public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
* [U-Boot] [PATCH] cmd_i2c: quit I2C commands immediately on error
@ 2015-02-05  4:50 Masahiro Yamada
  2015-02-06  5:45 ` Simon Glass
  2015-02-06  6:16 ` Heiko Schocher
  0 siblings, 2 replies; 3+ messages in thread
From: Masahiro Yamada @ 2015-02-05  4:50 UTC (permalink / raw)
  To: u-boot

If the i2c driver returns an error status, error out immediately.
Continuing the loop just results in printing error messages
again and again.

Signed-off-by: Masahiro Yamada <yamada.m@jp.panasonic.com>
Cc: Simon Glass <sjg@chromium.org>
Cc: Heiko Schocher <hs@denx.de>
---

 common/cmd_i2c.c | 26 +++++++++++++-------------
 1 file changed, 13 insertions(+), 13 deletions(-)

diff --git a/common/cmd_i2c.c b/common/cmd_i2c.c
index 7c3ad00..12ce3f3 100644
--- a/common/cmd_i2c.c
+++ b/common/cmd_i2c.c
@@ -518,7 +518,7 @@ static int do_i2c_md ( cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]
 		ret = i2c_read(chip, addr, alen, linebuf, linebytes);
 #endif
 		if (ret)
-			i2c_report_err(ret, I2C_ERR_READ);
+			return i2c_report_err(ret, I2C_ERR_READ);
 		else {
 			printf("%04x:", addr);
 			cp = linebuf;
@@ -616,7 +616,7 @@ static int do_i2c_mw ( cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]
 		ret = i2c_write(chip, addr++, alen, &byte, 1);
 #endif
 		if (ret)
-			i2c_report_err(ret, I2C_ERR_WRITE);
+			return i2c_report_err(ret, I2C_ERR_WRITE);
 		/*
 		 * Wait for the write to complete.  The write can take
 		 * up to 10mSec (we allow a little more time).
@@ -798,16 +798,15 @@ mod_i2c_mem(cmd_tbl_t *cmdtp, int incrflag, int flag, int argc, char * const arg
 		ret = i2c_read(chip, addr, alen, (uchar *)&data, size);
 #endif
 		if (ret)
-			i2c_report_err(ret, I2C_ERR_READ);
-		else {
-			data = cpu_to_be32(data);
-			if (size == 1)
-				printf(" %02lx", (data >> 24) & 0x000000FF);
-			else if (size == 2)
-				printf(" %04lx", (data >> 16) & 0x0000FFFF);
-			else
-				printf(" %08lx", data);
-		}
+			return i2c_report_err(ret, I2C_ERR_READ);
+
+		data = cpu_to_be32(data);
+		if (size == 1)
+			printf(" %02lx", (data >> 24) & 0x000000FF);
+		else if (size == 2)
+			printf(" %04lx", (data >> 16) & 0x0000FFFF);
+		else
+			printf(" %08lx", data);
 
 		nbytes = cli_readline(" ? ");
 		if (nbytes == 0) {
@@ -848,7 +847,8 @@ mod_i2c_mem(cmd_tbl_t *cmdtp, int incrflag, int flag, int argc, char * const arg
 						(uchar *)&data, size);
 #endif
 				if (ret)
-					i2c_report_err(ret, I2C_ERR_WRITE);
+					return i2c_report_err(ret,
+							      I2C_ERR_WRITE);
 #ifdef CONFIG_SYS_EEPROM_PAGE_WRITE_DELAY_MS
 				udelay(CONFIG_SYS_EEPROM_PAGE_WRITE_DELAY_MS * 1000);
 #endif
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [U-Boot] [PATCH] cmd_i2c: quit I2C commands immediately on error
  2015-02-05  4:50 [U-Boot] [PATCH] cmd_i2c: quit I2C commands immediately on error Masahiro Yamada
@ 2015-02-06  5:45 ` Simon Glass
  2015-02-06  6:16 ` Heiko Schocher
  1 sibling, 0 replies; 3+ messages in thread
From: Simon Glass @ 2015-02-06  5:45 UTC (permalink / raw)
  To: u-boot

On 4 February 2015 at 21:50, Masahiro Yamada <yamada.m@jp.panasonic.com> wrote:
> If the i2c driver returns an error status, error out immediately.
> Continuing the loop just results in printing error messages
> again and again.
>
> Signed-off-by: Masahiro Yamada <yamada.m@jp.panasonic.com>
> Cc: Simon Glass <sjg@chromium.org>
> Cc: Heiko Schocher <hs@denx.de>
> ---
>
>  common/cmd_i2c.c | 26 +++++++++++++-------------
>  1 file changed, 13 insertions(+), 13 deletions(-)

In any case the result of continuing is not likely to be correct.

Reviewed-by: Simon Glass <sjg@chromium.org>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [U-Boot] [PATCH] cmd_i2c: quit I2C commands immediately on error
  2015-02-05  4:50 [U-Boot] [PATCH] cmd_i2c: quit I2C commands immediately on error Masahiro Yamada
  2015-02-06  5:45 ` Simon Glass
@ 2015-02-06  6:16 ` Heiko Schocher
  1 sibling, 0 replies; 3+ messages in thread
From: Heiko Schocher @ 2015-02-06  6:16 UTC (permalink / raw)
  To: u-boot

Hello Masahiro,

Am 05.02.2015 05:50, schrieb Masahiro Yamada:
> If the i2c driver returns an error status, error out immediately.
> Continuing the loop just results in printing error messages
> again and again.
>
> Signed-off-by: Masahiro Yamada <yamada.m@jp.panasonic.com>
> Cc: Simon Glass <sjg@chromium.org>
> Cc: Heiko Schocher <hs@denx.de>
> ---
>
>   common/cmd_i2c.c | 26 +++++++++++++-------------
>   1 file changed, 13 insertions(+), 13 deletions(-)

Applied to u-boot-i2c.git, thanks!

bye,
Heiko
>
> diff --git a/common/cmd_i2c.c b/common/cmd_i2c.c
> index 7c3ad00..12ce3f3 100644
> --- a/common/cmd_i2c.c
> +++ b/common/cmd_i2c.c
> @@ -518,7 +518,7 @@ static int do_i2c_md ( cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]
>   		ret = i2c_read(chip, addr, alen, linebuf, linebytes);
>   #endif
>   		if (ret)
> -			i2c_report_err(ret, I2C_ERR_READ);
> +			return i2c_report_err(ret, I2C_ERR_READ);
>   		else {
>   			printf("%04x:", addr);
>   			cp = linebuf;
> @@ -616,7 +616,7 @@ static int do_i2c_mw ( cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]
>   		ret = i2c_write(chip, addr++, alen, &byte, 1);
>   #endif
>   		if (ret)
> -			i2c_report_err(ret, I2C_ERR_WRITE);
> +			return i2c_report_err(ret, I2C_ERR_WRITE);
>   		/*
>   		 * Wait for the write to complete.  The write can take
>   		 * up to 10mSec (we allow a little more time).
> @@ -798,16 +798,15 @@ mod_i2c_mem(cmd_tbl_t *cmdtp, int incrflag, int flag, int argc, char * const arg
>   		ret = i2c_read(chip, addr, alen, (uchar *)&data, size);
>   #endif
>   		if (ret)
> -			i2c_report_err(ret, I2C_ERR_READ);
> -		else {
> -			data = cpu_to_be32(data);
> -			if (size == 1)
> -				printf(" %02lx", (data >> 24) & 0x000000FF);
> -			else if (size == 2)
> -				printf(" %04lx", (data >> 16) & 0x0000FFFF);
> -			else
> -				printf(" %08lx", data);
> -		}
> +			return i2c_report_err(ret, I2C_ERR_READ);
> +
> +		data = cpu_to_be32(data);
> +		if (size == 1)
> +			printf(" %02lx", (data >> 24) & 0x000000FF);
> +		else if (size == 2)
> +			printf(" %04lx", (data >> 16) & 0x0000FFFF);
> +		else
> +			printf(" %08lx", data);
>
>   		nbytes = cli_readline(" ? ");
>   		if (nbytes == 0) {
> @@ -848,7 +847,8 @@ mod_i2c_mem(cmd_tbl_t *cmdtp, int incrflag, int flag, int argc, char * const arg
>   						(uchar *)&data, size);
>   #endif
>   				if (ret)
> -					i2c_report_err(ret, I2C_ERR_WRITE);
> +					return i2c_report_err(ret,
> +							      I2C_ERR_WRITE);
>   #ifdef CONFIG_SYS_EEPROM_PAGE_WRITE_DELAY_MS
>   				udelay(CONFIG_SYS_EEPROM_PAGE_WRITE_DELAY_MS * 1000);
>   #endif
>

-- 
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2015-02-06  6:16 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-02-05  4:50 [U-Boot] [PATCH] cmd_i2c: quit I2C commands immediately on error Masahiro Yamada
2015-02-06  5:45 ` Simon Glass
2015-02-06  6:16 ` Heiko Schocher

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox