From 2ea4dccae03c5e9dd892f417a42386040219373d Mon Sep 17 00:00:00 2001 From: Jean Delvare Date: Thu, 17 Sep 2009 15:59:38 +0000 Subject: [PATCH] Add support for short writes with PEC. git-svn-id: http://lm-sensors.org/svn/i2c-tools/trunk@5771 7894878c-1315-0410-8ee3-d5d059ff63e0 --- CHANGES | 1 + tools/i2cset.8 | 6 +++++- tools/i2cset.c | 26 +++++++++++++++++--------- 3 files changed, 23 insertions(+), 10 deletions(-) diff --git a/CHANGES b/CHANGES index 753ccca..97ce013 100644 --- a/CHANGES +++ b/CHANGES @@ -14,6 +14,7 @@ SVN Decode voltage interface level of DDR SDRAM decode-xeon: Delete eepromer: Fix array initialization overrun + i2cset: Add support for short writes with PEC i2c-stub-from-dump: Use udev settle to speed up initialization 3.0.2 (2008-11-29) diff --git a/tools/i2cset.8 b/tools/i2cset.8 index 2b4ce3a..7e630c5 100644 --- a/tools/i2cset.8 +++ b/tools/i2cset.8 @@ -11,7 +11,8 @@ i2cset \- set I2C registers .I i2cbus .I chip-address .I data-address -.RI [ "value " [ "mode" ]] +.RI [ value ] +.RI [ mode ] .br .B i2cset .B -V @@ -73,6 +74,9 @@ 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). +Another possible mode is \fBc\fP, which doesn't write any value (so-called +short write). You usually don't have to specify this mode, as it is the +default when no value is provided, unless you also want to enable PEC. .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 296abe1..ff32a3d 100644 --- a/tools/i2cset.c +++ b/tools/i2cset.c @@ -2,7 +2,7 @@ i2cset.c - A user-space program to write an I2C register. Copyright (C) 2001-2003 Frodo Looijaard , and Mark D. Studebaker - Copyright (C) 2004-2008 Jean Delvare + Copyright (C) 2004-2009 Jean Delvare This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -35,12 +35,13 @@ static void help(void) __attribute__ ((noreturn)); static void help(void) { fprintf(stderr, - "Usage: i2cset [-f] [-y] [-m MASK] I2CBUS CHIP-ADDRESS DATA-ADDRESS [VALUE [MODE]]\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" - " b (byte, default)\n" - " w (word)\n" + " c (byte, no value)\n" + " b (byte data, default)\n" + " w (word data)\n" " Append p for SMBus PEC\n"); exit(1); } @@ -180,11 +181,18 @@ int main(int argc, char *argv[]) } if (argc > flags + 4) { - size = I2C_SMBUS_BYTE_DATA; - value = strtol(argv[flags+4], &end, 0); - if (*end || value < 0) { - fprintf(stderr, "Error: Data value invalid!\n"); - help(); + if (!strcmp(argv[flags+4], "c") + || !strcmp(argv[flags+4], "cp")) { + size = I2C_SMBUS_BYTE; + value = -1; + pec = argv[flags+4][1] == 'p'; + } else { + size = I2C_SMBUS_BYTE_DATA; + value = strtol(argv[flags+4], &end, 0); + if (*end || value < 0) { + fprintf(stderr, "Error: Data value invalid!\n"); + help(); + } } } else { size = I2C_SMBUS_BYTE;