summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorkhali <khali@7894878c-1315-0410-8ee3-d5d059ff63e0>2008-11-20 08:22:18 +0000
committerkhali <khali@7894878c-1315-0410-8ee3-d5d059ff63e0>2008-11-20 08:22:18 +0000
commit1dbe271995c833170d9b1bc3965042ecb122c1a6 (patch)
treeb9308b8084ac6266a230f0c4744cac8672259fe9 /tools
parent96156182040021eb25cb0c0ea8419885762772ba (diff)
downloadi2c-tools-1dbe271995c833170d9b1bc3965042ecb122c1a6.tar.gz
Set the data value mask with -m. The old method is still supported for
compatibility, but is considered deprecated and is no longer documented. git-svn-id: http://lm-sensors.org/svn/i2c-tools/trunk@5390 7894878c-1315-0410-8ee3-d5d059ff63e0
Diffstat (limited to 'tools')
-rw-r--r--tools/i2cset.816
-rw-r--r--tools/i2cset.c22
2 files changed, 29 insertions, 9 deletions
diff --git a/tools/i2cset.8 b/tools/i2cset.8
index 136a9ea..d99dd55 100644
--- a/tools/i2cset.8
+++ b/tools/i2cset.8
@@ -1,4 +1,4 @@
-.TH I2CSET 8 "May 2008"
+.TH I2CSET 8 "November 2008"
.SH "NAME"
i2cset \- set I2C registers
@@ -6,10 +6,11 @@ i2cset \- set I2C registers
.B i2cset
.RB [ -f ]
.RB [ -y ]
+.RB [ "-m mask" ]
.I i2cbus
.I chip-address
.I data-address
-.RI [ "value " [ "mode " [ mask ]]]
+.RI [ "value " [ "mode" ]]
.br
.B i2cset
.B -V
@@ -36,6 +37,12 @@ Disable interactive mode. By default, i2cset 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 -m mask
+The \fImask\fR parameter, if specified, describes which bits of \fIvalue\fR
+will be actually written to \fIdata-address\fR. Bits set to 1 in the mask
+are taken from \fIvalue\fR, while bits set to 0 will be read from
+\fIdata-address\fR and thus preserved by the operation.
.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
@@ -57,11 +64,6 @@ respectively. A \fBp\fP can also be appended to the \fImode\fR parameter to
enable PEC. If the \fImode\fR parameter is omitted, i2cset defaults to byte
mode without PEC. The \fIvalue\fR provided must be within range for the
specified data type (0x00-0xFF for bytes, 0x0000-0xFFFF for words).
-.PP
-The \fImask\fR parameter, if specified, describes which bits of \fIvalue\fR
-will be actually written to \fIdata-address\fR. Bits set to 1 in the mask
-are taken from \fIvalue\fR, while bits set to 0 will be read from
-\fIdata-address\fR and thus preserved by the operation.
.SH WARNING
i2cset can be extremely dangerous if used improperly. It can confuse your
diff --git a/tools/i2cset.c b/tools/i2cset.c
index 7ae1e88..8d2f986 100644
--- a/tools/i2cset.c
+++ b/tools/i2cset.c
@@ -35,7 +35,7 @@ static void help(void) __attribute__ ((noreturn));
static void help(void)
{
fprintf(stderr,
- "Usage: i2cset [-f] [-y] I2CBUS CHIP-ADDRESS DATA-ADDRESS [VALUE [MODE [MASK]]]\n"
+ "Usage: i2cset [-f] [-y] [-m MASK] 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"
" MODE is one of:\n"
@@ -128,6 +128,7 @@ static int confirm(const char *filename, int address, int size, int daddress,
int main(int argc, char *argv[])
{
char *end;
+ const char *maskp = NULL;
int res, i2cbus, address, size, file;
int value, daddress, vmask = 0;
char filename[20];
@@ -141,6 +142,11 @@ int main(int argc, char *argv[])
case 'V': version = 1; break;
case 'f': force = 1; break;
case 'y': yes = 1; break;
+ case 'm':
+ if (2+flags < argc)
+ maskp = argv[2+flags];
+ flags++;
+ break;
default:
fprintf(stderr, "Error: Unsupported option "
"\"%s\"!\n", argv[1+flags]);
@@ -195,8 +201,20 @@ int main(int argc, char *argv[])
pec = argv[flags+5][1] == 'p';
}
+ /* Old method to provide the value mask, deprecated and no longer
+ documented but still supported for compatibility */
if (argc > flags + 6) {
- vmask = strtol(argv[flags+6], &end, 0);
+ if (maskp) {
+ fprintf(stderr, "Error: Data value mask provided twice!\n");
+ help();
+ }
+ fprintf(stderr, "Warning: Using deprecated way to set the data value mask!\n");
+ fprintf(stderr, " Please switch to using -m.\n");
+ maskp = argv[flags+6];
+ }
+
+ if (maskp && size != I2C_SMBUS_BYTE) {
+ vmask = strtol(maskp, &end, 0);
if (*end || vmask == 0) {
fprintf(stderr, "Error: Data value mask invalid!\n");
help();