aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRomain Porte <romain.porte@nokia.com>2018-03-02 11:17:05 +0100
committerWolfram Sang <wsa@the-dreams.de>2018-03-24 15:04:09 +0100
commit702804251c366bd4e4af8036984c7bde6bd268a8 (patch)
treeef4874e5b5b9e98f633c631b42210dd88e87a5b3
parente1fcba6924a9a1b0a00829cdc5525391f278b51b (diff)
downloadi2c-tools-702804251c366bd4e4af8036984c7bde6bd268a8.tar.gz
tools: add all_addrs option for i2c tools
If the user is sure that the reserved 0x00 - 0x02 and 0x77 - 0x7f ranges are not needed by its devices, then the "-a" option can be passed for allowing all theorical addresses to be used. It is then possible to access devices in this address range. Signed-off-by: Romain Porte <romain.porte@nokia.com> Reviewed-by: Peter Rosin <peda@axentia.se> [wsa: imonr fixes to commit message] Signed-off-by: Wolfram Sang <wsa@the-dreams.de>
-rw-r--r--tools/i2cbusses.c14
-rw-r--r--tools/i2cbusses.h2
-rw-r--r--tools/i2cdump.84
-rw-r--r--tools/i2cdump.c9
-rw-r--r--tools/i2cget.84
-rw-r--r--tools/i2cget.c9
-rw-r--r--tools/i2cset.84
-rw-r--r--tools/i2cset.c9
-rw-r--r--tools/i2ctransfer.84
-rw-r--r--tools/i2ctransfer.c7
10 files changed, 47 insertions, 19 deletions
diff --git a/tools/i2cbusses.c b/tools/i2cbusses.c
index 41f5b6b..ad06332 100644
--- a/tools/i2cbusses.c
+++ b/tools/i2cbusses.c
@@ -377,19 +377,27 @@ int lookup_i2c_bus(const char *i2cbus_arg)
* Parse a CHIP-ADDRESS command line argument and return the corresponding
* chip address, or a negative value if the address is invalid.
*/
-int parse_i2c_address(const char *address_arg)
+int parse_i2c_address(const char *address_arg, int all_addrs)
{
long address;
char *end;
+ long min_addr = 0x03;
+ long max_addr = 0x77;
address = strtol(address_arg, &end, 0);
if (*end || !*address_arg) {
fprintf(stderr, "Error: Chip address is not a number!\n");
return -1;
}
- if (address < 0x03 || address > 0x77) {
+
+ if (all_addrs) {
+ min_addr = 0x00;
+ max_addr = 0x7f;
+ }
+
+ if (address < min_addr || address > max_addr) {
fprintf(stderr, "Error: Chip address out of range "
- "(0x03-0x77)!\n");
+ "(0x%02lx-0x%02lx)!\n", min_addr, max_addr);
return -2;
}
diff --git a/tools/i2cbusses.h b/tools/i2cbusses.h
index 26143a5..a192c7f 100644
--- a/tools/i2cbusses.h
+++ b/tools/i2cbusses.h
@@ -35,7 +35,7 @@ struct i2c_adap *gather_i2c_busses(void);
void free_adapters(struct i2c_adap *adapters);
int lookup_i2c_bus(const char *i2cbus_arg);
-int parse_i2c_address(const char *address_arg);
+int parse_i2c_address(const char *address_arg, int all_addrs);
int open_i2c_dev(int i2cbus, char *filename, size_t size, int quiet);
int set_slave_addr(int file, int address, int force);
diff --git a/tools/i2cdump.8 b/tools/i2cdump.8
index fb7217e..2240f3c 100644
--- a/tools/i2cdump.8
+++ b/tools/i2cdump.8
@@ -7,6 +7,7 @@ i2cdump \- examine I2C registers
.RB [ -f ]
.RB [ "-r first-last" ]
.RB [ -y ]
+.RB [ -a ]
.I i2cbus
.I address
.RI [ "mode " [ "bank " [ bankreg ]]]
@@ -40,6 +41,9 @@ Disable interactive mode. By default, i2cdump will wait for a confirmation
from the user before messing with the I2C bus. When this flag is used, it
will perform the operation directly. This is mainly meant to be used in
scripts.
+.TP
+.B -a
+Allow using addresses between 0x00 - 0x02 and 0x78 - 0x7f. Not recommended.
.PP
At least two options must be provided to i2cdump. \fIi2cbus\fR indicates the
number or name of the I2C bus to be scanned. This number should correspond to one
diff --git a/tools/i2cdump.c b/tools/i2cdump.c
index a7bba72..3bd2077 100644
--- a/tools/i2cdump.c
+++ b/tools/i2cdump.c
@@ -36,9 +36,9 @@
static void help(void)
{
fprintf(stderr,
- "Usage: i2cdump [-f] [-y] [-r first-last] I2CBUS ADDRESS [MODE [BANK [BANKREG]]]\n"
+ "Usage: i2cdump [-f] [-y] [-r first-last] [-a] I2CBUS ADDRESS [MODE [BANK [BANKREG]]]\n"
" I2CBUS is an integer or an I2C bus name\n"
- " ADDRESS is an integer (0x03 - 0x77)\n"
+ " ADDRESS is an integer (0x03 - 0x77, or 0x00 - 0x7f if -a is given)\n"
" MODE is one of:\n"
" b (byte, default)\n"
" w (word)\n"
@@ -119,7 +119,7 @@ int main(int argc, char *argv[])
int block[256], s_length = 0;
int pec = 0, even = 0;
int flags = 0;
- int force = 0, yes = 0, version = 0;
+ int force = 0, yes = 0, version = 0, all_addrs = 0;
const char *range = NULL;
int first = 0x00, last = 0xff;
@@ -130,6 +130,7 @@ int main(int argc, char *argv[])
case 'f': force = 1; break;
case 'r': range = argv[1+(++flags)]; break;
case 'y': yes = 1; break;
+ case 'a': all_addrs = 1; break;
default:
fprintf(stderr, "Error: Unsupported option "
"\"%s\"!\n", argv[1+flags]);
@@ -160,7 +161,7 @@ int main(int argc, char *argv[])
help();
exit(1);
}
- address = parse_i2c_address(argv[flags+2]);
+ address = parse_i2c_address(argv[flags+2], all_addrs);
if (address < 0) {
help();
exit(1);
diff --git a/tools/i2cget.8 b/tools/i2cget.8
index a1a1276..8b48ad7 100644
--- a/tools/i2cget.8
+++ b/tools/i2cget.8
@@ -6,6 +6,7 @@ i2cget \- read from I2C/SMBus chip registers
.B i2cget
.RB [ -f ]
.RB [ -y ]
+.RB [ -a ]
.I i2cbus
.I chip-address
.RI [ "data-address " [ mode ]]
@@ -34,6 +35,9 @@ Disable interactive mode. By default, i2cget will wait for a confirmation
from the user before messing with the I2C bus. When this flag is used, it
will perform the operation directly. This is mainly meant to be used in
scripts. Use with caution.
+.TP
+.B -a
+Allow using addresses between 0x00 - 0x02 and 0x78 - 0x7f. Not recommended.
.PP
There are two required options to i2cget. \fIi2cbus\fR indicates the number
or name of the I2C bus to be scanned. This number should correspond to one of
diff --git a/tools/i2cget.c b/tools/i2cget.c
index 2503942..d2ed56a 100644
--- a/tools/i2cget.c
+++ b/tools/i2cget.c
@@ -41,9 +41,9 @@ static void help(void) __attribute__ ((noreturn));
static void help(void)
{
fprintf(stderr,
- "Usage: i2cget [-f] [-y] I2CBUS CHIP-ADDRESS [DATA-ADDRESS [MODE]]\n"
+ "Usage: i2cget [-f] [-y] [-a] I2CBUS CHIP-ADDRESS [DATA-ADDRESS [MODE]]\n"
" I2CBUS is an integer or an I2C bus name\n"
- " ADDRESS is an integer (0x03 - 0x77)\n"
+ " ADDRESS is an integer (0x03 - 0x77, or 0x00 - 0x7f if -a is given)\n"
" MODE is one of:\n"
" b (read byte data, default)\n"
" w (read word data)\n"
@@ -158,7 +158,7 @@ int main(int argc, char *argv[])
char filename[20];
int pec = 0;
int flags = 0;
- int force = 0, yes = 0, version = 0;
+ int force = 0, yes = 0, version = 0, all_addrs = 0;
/* handle (optional) flags first */
while (1+flags < argc && argv[1+flags][0] == '-') {
@@ -166,6 +166,7 @@ int main(int argc, char *argv[])
case 'V': version = 1; break;
case 'f': force = 1; break;
case 'y': yes = 1; break;
+ case 'a': all_addrs = 1; break;
default:
fprintf(stderr, "Error: Unsupported option "
"\"%s\"!\n", argv[1+flags]);
@@ -187,7 +188,7 @@ int main(int argc, char *argv[])
if (i2cbus < 0)
help();
- address = parse_i2c_address(argv[flags+2]);
+ address = parse_i2c_address(argv[flags+2], all_addrs);
if (address < 0)
help();
diff --git a/tools/i2cset.8 b/tools/i2cset.8
index 19887bd..cd53aba 100644
--- a/tools/i2cset.8
+++ b/tools/i2cset.8
@@ -8,6 +8,7 @@ i2cset \- set I2C registers
.RB [ -y ]
.RB [ "-m mask" ]
.RB [ -r ]
+.RB [ -a ]
.I i2cbus
.I chip-address
.I data-address
@@ -54,6 +55,9 @@ be the case, as neither I2C nor SMBus guarantees this.
Read back the value right after writing it, and compare the result with the
value written. This used to be the default behavior. The same limitations
apply as those of option \fB-m\fR.
+.TP
+.B -a
+Allow using addresses between 0x00 - 0x02 and 0x78 - 0x7f. Not recommended.
.PP
There are three required options to i2cset. \fIi2cbus\fR indicates the number
or name of the I2C bus to be scanned. This number should correspond to one of
diff --git a/tools/i2cset.c b/tools/i2cset.c
index 0ccc1a0..e82dc52 100644
--- a/tools/i2cset.c
+++ b/tools/i2cset.c
@@ -38,9 +38,9 @@ static void help(void) __attribute__ ((noreturn));
static void help(void)
{
fprintf(stderr,
- "Usage: i2cset [-f] [-y] [-m MASK] [-r] I2CBUS CHIP-ADDRESS DATA-ADDRESS [VALUE] ... [MODE]\n"
+ "Usage: i2cset [-f] [-y] [-m MASK] [-r] [-a] I2CBUS CHIP-ADDRESS DATA-ADDRESS [VALUE] ... [MODE]\n"
" I2CBUS is an integer or an I2C bus name\n"
- " ADDRESS is an integer (0x03 - 0x77)\n"
+ " ADDRESS is an integer (0x03 - 0x77, or 0x00 - 0x7f if -a is given)\n"
" MODE is one of:\n"
" c (byte, no value)\n"
" b (byte data, default)\n"
@@ -163,7 +163,7 @@ int main(int argc, char *argv[])
char filename[20];
int pec = 0;
int flags = 0;
- int force = 0, yes = 0, version = 0, readback = 0;
+ int force = 0, yes = 0, version = 0, readback = 0, all_addrs = 0;
unsigned char block[I2C_SMBUS_BLOCK_MAX];
int len;
@@ -179,6 +179,7 @@ int main(int argc, char *argv[])
flags++;
break;
case 'r': readback = 1; break;
+ case 'a': all_addrs = 1; break;
default:
fprintf(stderr, "Error: Unsupported option "
"\"%s\"!\n", argv[1+flags]);
@@ -200,7 +201,7 @@ int main(int argc, char *argv[])
if (i2cbus < 0)
help();
- address = parse_i2c_address(argv[flags+2]);
+ address = parse_i2c_address(argv[flags+2], all_addrs);
if (address < 0)
help();
diff --git a/tools/i2ctransfer.8 b/tools/i2ctransfer.8
index 0dd43c9..99123fa 100644
--- a/tools/i2ctransfer.8
+++ b/tools/i2ctransfer.8
@@ -7,6 +7,7 @@ i2ctransfer \- send user-defined I2C messages in one transfer
.RB [ -f ]
.RB [ -y ]
.RB [ -v ]
+.RB [ -a ]
.I i2cbus desc
.RI [ data ]
.RI [ desc
@@ -61,6 +62,9 @@ It will print infos about all messages sent, i.e. not only for read messages but
.TP
.B -V
Display the version and exit.
+.TP
+.B -a
+Allow using addresses between 0x00 - 0x02 and 0x78 - 0x7f. Not recommended.
.SH ARGUMENTS
.PP
diff --git a/tools/i2ctransfer.c b/tools/i2ctransfer.c
index 38b6b4a..8e9ce63 100644
--- a/tools/i2ctransfer.c
+++ b/tools/i2ctransfer.c
@@ -42,7 +42,7 @@ enum parse_state {
static void help(void)
{
fprintf(stderr,
- "Usage: i2ctransfer [-f] [-y] [-v] [-V] I2CBUS DESC [DATA] [DESC [DATA]]...\n"
+ "Usage: i2ctransfer [-f] [-y] [-v] [-V] [-a] I2CBUS DESC [DATA] [DESC [DATA]]...\n"
" I2CBUS is an integer or an I2C bus name\n"
" DESC describes the transfer in the form: {r|w}LENGTH[@address]\n"
" 1) read/write-flag 2) LENGTH (range 0-65535) 3) I2C address (use last one if omitted)\n"
@@ -124,7 +124,7 @@ int main(int argc, char *argv[])
{
char filename[20];
int i2cbus, address = -1, file, arg_idx = 1, nmsgs = 0, nmsgs_sent, i;
- int force = 0, yes = 0, version = 0, verbose = 0;
+ int force = 0, yes = 0, version = 0, verbose = 0, all_addrs = 0;
struct i2c_msg msgs[I2C_RDRW_IOCTL_MAX_MSGS];
enum parse_state state = PARSE_GET_DESC;
unsigned buf_idx = 0;
@@ -139,6 +139,7 @@ int main(int argc, char *argv[])
case 'v': verbose = 1; break;
case 'f': force = 1; break;
case 'y': yes = 1; break;
+ case 'a': all_addrs = 1; break;
default:
fprintf(stderr, "Error: Unsupported option \"%s\"!\n",
argv[arg_idx]);
@@ -210,7 +211,7 @@ int main(int argc, char *argv[])
*/
if (!force) {
- address = parse_i2c_address(arg_ptr);
+ address = parse_i2c_address(arg_ptr, all_addrs);
if (address < 0)
goto err_out_with_arg;