diff options
author | Simon Glass <sjg@chromium.org> | 2015-08-22 18:31:33 -0600 |
---|---|---|
committer | Simon Glass <sjg@chromium.org> | 2015-08-31 07:57:28 -0600 |
commit | c10c8e313c836eb193f49c6f782a2e5a6e2f21d0 (patch) | |
tree | dffafa3ce083fe563ea23b9171e4c78485b5a200 /common | |
parent | c8a8c51039d83149a93fccb6e325bfdb8f63fa66 (diff) | |
download | u-boot-c10c8e313c836eb193f49c6f782a2e5a6e2f21d0.tar.gz |
dm: i2c: Add a command to adjust the offset length
I2C chips can support a register offset, with registers accessible by
sending this offset as the first part of any read or write transaction.
Most I2C chips have a single byte offset, thus the offset length is 1.
This provides access for up 256 registers.
However other offset lengths are supported, including 0.
Add a command to provide access to the offset length from the command
line. This allows the offset length to be read or written.
Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Christophe Ricard<christophe-h.ricard@st.com>
Reviewed-by: Heiko Schocher <hs@denx.de>
Diffstat (limited to 'common')
-rw-r--r-- | common/cmd_i2c.c | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/common/cmd_i2c.c b/common/cmd_i2c.c index 1bc0db860c..864b2596cc 100644 --- a/common/cmd_i2c.c +++ b/common/cmd_i2c.c @@ -453,6 +453,37 @@ static int do_i2c_flags(cmd_tbl_t *cmdtp, int flag, int argc, return 0; } + +static int do_i2c_olen(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[]) +{ + struct udevice *dev; + uint olen; + int chip; + int ret; + + if (argc < 2) + return CMD_RET_USAGE; + + chip = simple_strtoul(argv[1], NULL, 16); + ret = i2c_get_cur_bus_chip(chip, &dev); + if (ret) + return i2c_report_err(ret, I2C_ERR_READ); + + if (argc > 2) { + olen = simple_strtoul(argv[2], NULL, 16); + ret = i2c_set_chip_offset_len(dev, olen); + } else { + ret = i2c_get_chip_offset_len(dev); + if (ret >= 0) { + printf("%x\n", ret); + ret = 0; + } + } + if (ret) + return i2c_report_err(ret, I2C_ERR_READ); + + return 0; +} #endif /** @@ -1903,6 +1934,7 @@ static cmd_tbl_t cmd_i2c_sub[] = { U_BOOT_CMD_MKENT(write, 6, 0, do_i2c_write, "", ""), #ifdef CONFIG_DM_I2C U_BOOT_CMD_MKENT(flags, 2, 1, do_i2c_flags, "", ""), + U_BOOT_CMD_MKENT(olen, 2, 1, do_i2c_olen, "", ""), #endif U_BOOT_CMD_MKENT(reset, 0, 1, do_i2c_reset, "", ""), #if defined(CONFIG_CMD_SDRAM) @@ -1971,6 +2003,7 @@ static char i2c_help_text[] = " to I2C; the -s option selects bulk write in a single transaction\n" #ifdef CONFIG_DM_I2C "i2c flags chip [flags] - set or get chip flags\n" + "i2c olen chip [offset_length] - set or get chip offset length\n" #endif "i2c reset - re-init the I2C Controller\n" #if defined(CONFIG_CMD_SDRAM) |