diff options
author | Frans Meulenbroeks <fransmeulenbroeks@gmail.com> | 2010-02-25 10:12:16 +0100 |
---|---|---|
committer | Wolfgang Denk <wd@denx.de> | 2010-03-21 22:44:43 +0100 |
commit | 652e53546b23c25f80756287eaf607b713afdc87 (patch) | |
tree | 209fd8d210066dbc825b790e12fca18eca88372a /common | |
parent | fb0070e9101a1f288d7054f7e80b3d808fd7ead2 (diff) | |
download | u-boot-imx-652e53546b23c25f80756287eaf607b713afdc87.zip u-boot-imx-652e53546b23c25f80756287eaf607b713afdc87.tar.gz u-boot-imx-652e53546b23c25f80756287eaf607b713afdc87.tar.bz2 |
cmd_i2c.c: added i2c read to memory function
Signed-off-by: Frans Meulenbroeks <fransmeulenbroeks@gmail.com>
Diffstat (limited to 'common')
-rw-r--r-- | common/cmd_i2c.c | 60 |
1 files changed, 59 insertions, 1 deletions
diff --git a/common/cmd_i2c.c b/common/cmd_i2c.c index b51d0c9..ee9577c 100644 --- a/common/cmd_i2c.c +++ b/common/cmd_i2c.c @@ -154,6 +154,63 @@ int i2c_set_bus_speed(unsigned int) */ #define DISP_LINE_LEN 16 +/* + * Syntax: + * i2c read {i2c_chip} {devaddr}{.0, .1, .2} {len} {memaddr} + */ + +int do_i2c_read ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) +{ + u_char chip; + uint devaddr, alen, length; + u_char *memaddr; + int j; + + if (argc != 5) { + cmd_usage(cmdtp); + return 1; + } + + /* + * I2C chip address + */ + chip = simple_strtoul(argv[1], NULL, 16); + + /* + * I2C data address within the chip. This can be 1 or + * 2 bytes long. Some day it might be 3 bytes long :-). + */ + devaddr = simple_strtoul(argv[2], NULL, 16); + alen = 1; + for (j = 0; j < 8; j++) { + if (argv[2][j] == '.') { + alen = argv[2][j+1] - '0'; + if (alen > 3) { + cmd_usage(cmdtp); + return 1; + } + break; + } else if (argv[2][j] == '\0') + break; + } + + /* + * Length is the number of objects, not number of bytes. + */ + length = simple_strtoul(argv[3], NULL, 16); + + /* + * memaddr is the address where to store things in memory + */ + memaddr = (u_char *)simple_strtoul(argv[4], NULL, 16); + + if (i2c_read(chip, devaddr, alen, memaddr, length) != 0) { + puts ("Error reading the chip.\n"); + return 1; + } + return 0; +} + int do_i2c_md ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) { u_char chip; @@ -1272,6 +1329,7 @@ static cmd_tbl_t cmd_i2c_sub[] = { U_BOOT_CMD_MKENT(mw, 3, 1, do_i2c_mw, "", ""), U_BOOT_CMD_MKENT(nm, 2, 1, do_i2c_nm, "", ""), U_BOOT_CMD_MKENT(probe, 0, 1, do_i2c_probe, "", ""), + U_BOOT_CMD_MKENT(read, 5, 1, do_i2c_read, "", ""), U_BOOT_CMD_MKENT(reset, 0, 1, do_i2c_reset, "", ""), #if defined(CONFIG_CMD_SDRAM) U_BOOT_CMD_MKENT(sdram, 1, 1, do_sdram, "", ""), @@ -1315,6 +1373,7 @@ U_BOOT_CMD( "i2c mw chip address[.0, .1, .2] value [count] - write to I2C device (fill)\n" "i2c nm chip address[.0, .1, .2] - write to I2C device (constant address)\n" "i2c probe - show devices on the I2C bus\n" + "i2c read chip address[.0, .1, .2] length memaddress - read to memory \n" "i2c reset - re-init the I2C Controller\n" #if defined(CONFIG_CMD_SDRAM) "i2c sdram chip - print SDRAM configuration information\n" @@ -1323,7 +1382,6 @@ U_BOOT_CMD( ); #if defined(CONFIG_I2C_MUX) - int i2c_mux_add_device(I2C_MUX_DEVICE *dev) { I2C_MUX_DEVICE *devtmp = i2c_mux_devices; |