Do not force the I2C slave address by default. It's only fair to let the

users know that they're doing something wrong. They can insist by using
the new -f option.


git-svn-id: http://lm-sensors.org/svn/lm-sensors/branches/lm-sensors-3.0.0@4431 7894878c-1315-0410-8ee3-d5d059ff63e0
This commit is contained in:
Jean Delvare committed 2007-06-04 17:54:46 +00:00
1 parent 2eb4a52e25
commit a46d7961d3
9 files changed
+58 -37

No files matched your search

+1
View File
@@ -14,6 +14,7 @@ SVN HEAD
Add dme1737 support
Delete support of non-sensor drivers (ddcmon, eeprom)
Man page sensors.conf.5: Update the chip statement section
Programs i2cdump, i2cget, i2cset: Do not force the slave address by default
Program i2cdump: Use the new I2C block read function
Program isadump: Detect when address bit 7 is a busy flag
Fix Super-I/O exit sequence for Winbond/Fintek chips
+14
View File
@@ -243,3 +243,17 @@ int open_i2c_dev(const int i2cbus, char *filename, const int quiet)
return file;
}
int set_slave_addr(int file, int address, int force)
{
/* With force, let the user read from/write to the registers
even when a driver is also running */
if (ioctl(file, force ? I2C_SLAVE_FORCE : I2C_SLAVE, address) < 0) {
fprintf(stderr,
"Error: Could not set address to 0x%02x: %s\n",
address, strerror(errno));
return -errno;
}
return 0;
}
+1
View File
@@ -24,5 +24,6 @@
void print_i2c_busses(int procfmt);
int open_i2c_dev(const int i2cbus, char *filename, const int quiet);
int set_slave_addr(int file, int address, int force);
#endif
+9 -1
View File
@@ -1,9 +1,10 @@
.TH I2CDUMP 8 "April 2006"
.TH I2CDUMP 8 "June 2007"
.SH NAME
i2cdump \- examine I2C registers
.SH SYNOPSIS
.B i2cdump
.RB [ -f ]
.RB [ -y ]
.I i2cbus
.I address
@@ -22,6 +23,13 @@ visible through the I2C bus.
.B -V
Display the version and exit.
.TP
.B -f
Force access to the device even if it is already busy. By default, i2cdump
will refuse to access a device which is already under the control of a
kernel driver. Using this flag is dangerous, it can seriously confuse the
kernel driver in question. It can also cause i2cdump to return invalid
results. So use at your own risk and only if you know what you're doing.
.TP
.B -y
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
+5 -9
View File
@@ -31,8 +31,8 @@
void help(void)
{
fprintf(stderr, "Syntax: i2cdump [-y] I2CBUS ADDRESS [MODE] [BANK "
"[BANKREG]]\n"
fprintf(stderr, "Syntax: i2cdump [-f] [-y] I2CBUS ADDRESS [MODE] "
"[BANK [BANKREG]]\n"
" i2cdump -V\n"
" MODE is one of:\n"
" b (byte, default)\n"
@@ -60,12 +60,13 @@ int main(int argc, char *argv[])
int block[256], s_length = 0;
int pec = 0, even = 0;
int flags = 0;
int yes = 0, version = 0;
int force = 0, yes = 0, version = 0;
/* handle (optional) flags first */
while (1+flags < argc && argv[1+flags][0] == '-') {
switch (argv[1+flags][1]) {
case 'V': version = 1; break;
case 'f': force = 1; break;
case 'y': yes = 1; break;
default:
fprintf(stderr, "Warning: Unsupported flag "
@@ -234,13 +235,8 @@ int main(int argc, char *argv[])
break;
}
/* use FORCE so that we can look at registers even when
a driver is also running */
if (ioctl(file, I2C_SLAVE_FORCE, address) < 0) {
fprintf(stderr, "Error: Could not set address to %d: %s\n",
address, strerror(errno));
if (set_slave_addr(file, address, force) < 0)
exit(1);
}
if (pec) {
if (ioctl(file, I2C_PEC, 1) < 0) {
+9 -1
View File
@@ -1,9 +1,10 @@
.TH I2CGET 8 "September 2005"
.TH I2CGET 8 "June 2007"
.SH "NAME"
i2cget \- read from I2C/SMBus chip registers
.SH SYNOPSIS
.B i2cget
.RB [ -f ]
.RB [ -y ]
.I i2cbus
.I chip-address
@@ -21,6 +22,13 @@ bus (or SMBus).
.B -V
Display the version and exit.
.TP
.B -f
Force access to the device even if it is already busy. By default, i2cget
will refuse to access a device which is already under the control of a
kernel driver. Using this flag is dangerous, it can seriously confuse the
kernel driver in question. It can also cause i2cget to return an invalid
value. So use at your own risk and only if you know what you're doing.
.TP
.B -y
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
+5 -17
View File
@@ -36,8 +36,8 @@ void help(void) __attribute__ ((noreturn));
void help(void)
{
fprintf(stderr, "Syntax: i2cget [-y] I2CBUS CHIP-ADDRESS [DATA-ADDRESS "
"[MODE]]\n"
fprintf(stderr, "Syntax: i2cget [-f] [-y] I2CBUS CHIP-ADDRESS "
"[DATA-ADDRESS [MODE]]\n"
" i2cget -V\n"
" MODE can be: 'b' (read byte data, default)\n"
" 'w' (read word data)\n"
@@ -102,19 +102,6 @@ int check_funcs(int file, int i2cbus, int size, int daddress, int pec)
return 0;
}
int set_slave(int file, int address)
{
/* use FORCE so that we can read registers even when
a driver is also running */
if (ioctl(file, I2C_SLAVE_FORCE, address) < 0) {
fprintf(stderr, "Error: Could not set address to %d: %s\n",
address, strerror(errno));
return -1;
}
return 0;
}
int confirm(const char *filename, int address, int size, int daddress, int pec)
{
int dont = 0;
@@ -173,12 +160,13 @@ int main(int argc, char *argv[])
char filename[20];
int pec = 0;
int flags = 0;
int yes = 0, version = 0;
int force = 0, yes = 0, version = 0;
/* handle (optional) flags first */
while (1+flags < argc && argv[1+flags][0] == '-') {
switch (argv[1+flags][1]) {
case 'V': version = 1; break;
case 'f': force = 1; break;
case 'y': yes = 1; break;
default:
fprintf(stderr, "Warning: Unsupported flag "
@@ -235,7 +223,7 @@ int main(int argc, char *argv[])
file = open_i2c_dev(i2cbus, filename, 0);
if (file < 0
|| check_funcs(file, i2cbus, size, daddress, pec)
|| set_slave(file, address))
|| set_slave_addr(file, address, force))
exit(1);
if (!yes && !confirm(filename, address, size, daddress, pec))
+10 -1
View File
@@ -1,9 +1,10 @@
.TH I2CSET 8 "September 2005"
.TH I2CSET 8 "June 2007"
.SH "NAME"
i2cset \- set I2C registers
.SH SYNOPSIS
.B i2cset
.RB [ -f ]
.RB [ -y ]
.I i2cbus
.I chip-address
@@ -24,6 +25,14 @@ bus.
.B -V
Display the version and exit.
.TP
.B -f
Force access to the device even if it is already busy. By default, i2cset
will refuse to access a device which is already under the control of a
kernel driver. Using this flag is dangerous, it can seriously confuse the
kernel driver in question. It can also cause i2cset to silently write to
the wrong register. So use at your own risk and only if you know what
you're doing.
.TP
.B -y
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
+4 -8
View File
@@ -33,7 +33,7 @@ void help(void) __attribute__ ((noreturn));
void help(void)
{
fprintf(stderr, "Syntax: i2cset [-y] I2CBUS CHIP-ADDRESS DATA-ADDRESS "
fprintf(stderr, "Syntax: i2cset [-f] [-y] I2CBUS CHIP-ADDRESS DATA-ADDRESS "
"VALUE [MODE] [MASK]\n"
" i2cset -V\n"
" MODE is 'b[yte]' or 'w[ord]' (default b)\n"
@@ -53,12 +53,13 @@ int main(int argc, char *argv[])
unsigned long funcs;
int pec = 0;
int flags = 0;
int yes = 0, version = 0;
int force = 0, yes = 0, version = 0;
/* handle (optional) flags first */
while (1+flags < argc && argv[1+flags][0] == '-') {
switch (argv[1+flags][1]) {
case 'V': version = 1; break;
case 'f': force = 1; break;
case 'y': yes = 1; break;
default:
fprintf(stderr, "Warning: Unsupported flag "
@@ -160,13 +161,8 @@ int main(int argc, char *argv[])
break;
}
/* use FORCE so that we can write registers even when
a driver is also running */
if (ioctl(file, I2C_SLAVE_FORCE, address) < 0) {
fprintf(stderr, "Error: Could not set address to %d: %s\n",
address, strerror(errno));
if (set_slave_addr(file, address, force) < 0)
exit(1);
}
if (!yes) {
int dont = 0;