From 28ed06f1c5f69972211ec432449bc6e628d0c444 Mon Sep 17 00:00:00 2001 From: Geert Uytterhoeven Date: Fri, 15 Jan 2021 11:22:02 +0100 Subject: [PATCH 1/2] software/bios/cmds/cmd_i2c: Fix i2c_scan output "i2c_scan" prints random data instead of the intended slave address: 0x70: 10001ebc -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- instead of: 0x70: 70 -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- Fix this by adding the missing printf() parameter. Fixes: ee1ea9baab8ae485 ("bios/cmd/cmd_i2c: make results similar to Linux's i2cdetect.") Signed-off-by: Geert Uytterhoeven --- litex/soc/software/bios/cmds/cmd_i2c.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/litex/soc/software/bios/cmds/cmd_i2c.c b/litex/soc/software/bios/cmds/cmd_i2c.c index c0f32a619..d4430d194 100644 --- a/litex/soc/software/bios/cmds/cmd_i2c.c +++ b/litex/soc/software/bios/cmds/cmd_i2c.c @@ -138,7 +138,7 @@ static void i2c_scan_handler(int nb_params, char **params) printf("\n0x%02x:", (slave_addr/0x10) * 0x10); } if (i2c_poll(slave_addr)) { - printf(" %02x"); + printf(" %02x", slave_addr); } else { printf(" --"); } From dc3306731c54d76bd743dd1ece932a3e24c83d81 Mon Sep 17 00:00:00 2001 From: Geert Uytterhoeven Date: Fri, 15 Jan 2021 11:26:45 +0100 Subject: [PATCH 2/2] software/bios/cmds/cmd_i2c: Simplify upper nibble calculation Use masking instead of division and multiplication. Signed-off-by: Geert Uytterhoeven --- litex/soc/software/bios/cmds/cmd_i2c.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/litex/soc/software/bios/cmds/cmd_i2c.c b/litex/soc/software/bios/cmds/cmd_i2c.c index d4430d194..2319f3762 100644 --- a/litex/soc/software/bios/cmds/cmd_i2c.c +++ b/litex/soc/software/bios/cmds/cmd_i2c.c @@ -135,7 +135,7 @@ static void i2c_scan_handler(int nb_params, char **params) printf(" 0 1 2 3 4 5 6 7 8 9 a b c d e f"); for (slave_addr = 0; slave_addr < 0x80; slave_addr++) { if (slave_addr % 0x10 == 0) { - printf("\n0x%02x:", (slave_addr/0x10) * 0x10); + printf("\n0x%02x:", slave_addr & 0x70); } if (i2c_poll(slave_addr)) { printf(" %02x", slave_addr);