Changeset 4432

Show
Ignore:
Timestamp:
06/04/07 20:27:34 (8 years ago)
Author:
khali
Message:

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.

Location:
lm-sensors/trunk
Files:
9 modified

Legend:

Unmodified
Added
Removed
  • lm-sensors/trunk/CHANGES

    r4422 r4432  
    1111  Man page sensors.conf.5: Update the chip statement section 
    1212  Module i2c-nforce2: Add nForce MCP61, MCP65 support (2.6 backport) 
     13  Programs i2cdump, i2cget, i2cset: Do not force the slave address by default 
    1314  Program i2cdump: Use the new I2C block read function 
    1415  Program isadump: Detect when address bit 7 is a busy flag 
  • lm-sensors/trunk/prog/dump/i2cbusses.c

    r4240 r4432  
    244244        return file; 
    245245} 
     246 
     247int set_slave_addr(int file, int address, int force) 
     248{ 
     249        /* With force, let the user read from/write to the registers 
     250           even when a driver is also running */ 
     251        if (ioctl(file, force ? I2C_SLAVE_FORCE : I2C_SLAVE, address) < 0) { 
     252                fprintf(stderr, 
     253                        "Error: Could not set address to 0x%02x: %s\n", 
     254                        address, strerror(errno)); 
     255                return -errno; 
     256        } 
     257 
     258        return 0; 
     259} 
  • lm-sensors/trunk/prog/dump/i2cbusses.h

    r3077 r4432  
    2525 
    2626int open_i2c_dev(const int i2cbus, char *filename, const int quiet); 
     27int set_slave_addr(int file, int address, int force); 
    2728 
    2829#endif 
  • lm-sensors/trunk/prog/dump/i2cdump.8

    r4157 r4432  
    1 .TH I2CDUMP 8 "April 2006" 
     1.TH I2CDUMP 8 "June 2007" 
    22.SH NAME 
    33i2cdump \- examine I2C registers 
     
    55.SH SYNOPSIS 
    66.B i2cdump 
     7.RB [ -f ] 
    78.RB [ -y ] 
    89.I i2cbus 
     
    2223.B -V 
    2324Display the version and exit. 
     25.TP 
     26.B -f 
     27Force access to the device even if it is already busy. By default, i2cdump 
     28will refuse to access a device which is already under the control of a 
     29kernel driver. Using this flag is dangerous, it can seriously confuse the 
     30kernel driver in question. It can also cause i2cdump to return invalid 
     31results. So use at your own risk and only if you know what you're doing. 
    2432.TP 
    2533.B -y 
  • lm-sensors/trunk/prog/dump/i2cdump.c

    r4417 r4432  
    3232void help(void) 
    3333{ 
    34         fprintf(stderr, "Syntax: i2cdump [-y] I2CBUS ADDRESS [MODE] [BANK " 
    35                 "[BANKREG]]\n" 
     34        fprintf(stderr, "Syntax: i2cdump [-f] [-y] I2CBUS ADDRESS [MODE] " 
     35                "[BANK [BANKREG]]\n" 
    3636                "        i2cdump -V\n" 
    3737                "  MODE is one of:\n" 
     
    6161        int pec = 0, even = 0; 
    6262        int flags = 0; 
    63         int yes = 0, version = 0; 
     63        int force = 0, yes = 0, version = 0; 
    6464 
    6565        /* handle (optional) flags first */ 
     
    6767                switch (argv[1+flags][1]) { 
    6868                case 'V': version = 1; break; 
     69                case 'f': force = 1; break; 
    6970                case 'y': yes = 1; break; 
    7071                default: 
     
    235236        } 
    236237 
    237         /* use FORCE so that we can look at registers even when 
    238            a driver is also running */ 
    239         if (ioctl(file, I2C_SLAVE_FORCE, address) < 0) { 
    240                 fprintf(stderr, "Error: Could not set address to %d: %s\n", 
    241                         address, strerror(errno)); 
    242                 exit(1); 
    243         } 
     238        if (set_slave_addr(file, address, force) < 0) 
     239                exit(1); 
    244240 
    245241        if (pec) { 
  • lm-sensors/trunk/prog/dump/i2cget.8

    r4157 r4432  
    1 .TH I2CGET 8 "September 2005" 
     1.TH I2CGET 8 "June 2007" 
    22.SH "NAME" 
    33i2cget \- read from I2C/SMBus chip registers 
     
    55.SH SYNOPSIS 
    66.B i2cget 
     7.RB [ -f ] 
    78.RB [ -y ] 
    89.I i2cbus 
     
    2122.B -V 
    2223Display the version and exit. 
     24.TP 
     25.B -f 
     26Force access to the device even if it is already busy. By default, i2cget 
     27will refuse to access a device which is already under the control of a 
     28kernel driver. Using this flag is dangerous, it can seriously confuse the 
     29kernel driver in question. It can also cause i2cget to return an invalid 
     30value. So use at your own risk and only if you know what you're doing. 
    2331.TP 
    2432.B -y 
  • lm-sensors/trunk/prog/dump/i2cget.c

    r4256 r4432  
    3737void help(void) 
    3838{ 
    39         fprintf(stderr, "Syntax: i2cget [-y] I2CBUS CHIP-ADDRESS [DATA-ADDRESS " 
    40                 "[MODE]]\n" 
     39        fprintf(stderr, "Syntax: i2cget [-f] [-y] I2CBUS CHIP-ADDRESS " 
     40                "[DATA-ADDRESS [MODE]]\n" 
    4141                "        i2cget -V\n" 
    4242                "  MODE can be: 'b' (read byte data, default)\n" 
     
    9898                fprintf(stderr, "Warning: Adapter for i2c bus %d does " 
    9999                        "not seem to support PEC\n", i2cbus); 
    100         } 
    101  
    102         return 0; 
    103 } 
    104  
    105 int set_slave(int file, int address) 
    106 { 
    107         /* use FORCE so that we can read registers even when 
    108            a driver is also running */ 
    109         if (ioctl(file, I2C_SLAVE_FORCE, address) < 0) { 
    110                 fprintf(stderr, "Error: Could not set address to %d: %s\n", 
    111                         address, strerror(errno)); 
    112                 return -1; 
    113100        } 
    114101 
     
    174161        int pec = 0; 
    175162        int flags = 0; 
    176         int yes = 0, version = 0; 
     163        int force = 0, yes = 0, version = 0; 
    177164 
    178165        /* handle (optional) flags first */ 
     
    180167                switch (argv[1+flags][1]) { 
    181168                case 'V': version = 1; break; 
     169                case 'f': force = 1; break; 
    182170                case 'y': yes = 1; break; 
    183171                default: 
     
    236224        if (file < 0 
    237225         || check_funcs(file, i2cbus, size, daddress, pec) 
    238          || set_slave(file, address)) 
     226         || set_slave_addr(file, address, force)) 
    239227                exit(1); 
    240228 
  • lm-sensors/trunk/prog/dump/i2cset.8

    r4157 r4432  
    1 .TH I2CSET 8 "September 2005" 
     1.TH I2CSET 8 "June 2007" 
    22.SH "NAME" 
    33i2cset \- set I2C registers 
     
    55.SH SYNOPSIS 
    66.B i2cset 
     7.RB [ -f ] 
    78.RB [ -y ] 
    89.I i2cbus 
     
    2425.B -V 
    2526Display the version and exit. 
     27.TP 
     28.B -f 
     29Force access to the device even if it is already busy. By default, i2cset 
     30will refuse to access a device which is already under the control of a 
     31kernel driver. Using this flag is dangerous, it can seriously confuse the 
     32kernel driver in question. It can also cause i2cset to silently write to 
     33the wrong register. So use at your own risk and only if you know what 
     34you're doing. 
    2635.TP 
    2736.B -y 
  • lm-sensors/trunk/prog/dump/i2cset.c

    r4256 r4432  
    3434void help(void) 
    3535{ 
    36         fprintf(stderr, "Syntax: i2cset [-y] I2CBUS CHIP-ADDRESS DATA-ADDRESS " 
     36        fprintf(stderr, "Syntax: i2cset [-f] [-y] I2CBUS CHIP-ADDRESS DATA-ADDRESS " 
    3737                "VALUE [MODE] [MASK]\n" 
    3838                "        i2cset -V\n" 
     
    5454        int pec = 0; 
    5555        int flags = 0; 
    56         int yes = 0, version = 0; 
     56        int force = 0, yes = 0, version = 0; 
    5757 
    5858        /* handle (optional) flags first */ 
     
    6060                switch (argv[1+flags][1]) { 
    6161                case 'V': version = 1; break; 
     62                case 'f': force = 1; break; 
    6263                case 'y': yes = 1; break; 
    6364                default: 
     
    161162        } 
    162163 
    163         /* use FORCE so that we can write registers even when 
    164            a driver is also running */ 
    165         if (ioctl(file, I2C_SLAVE_FORCE, address) < 0) { 
    166                 fprintf(stderr, "Error: Could not set address to %d: %s\n", 
    167                         address, strerror(errno)); 
     164        if (set_slave_addr(file, address, force) < 0) 
    168165                exit(1); 
    169         } 
    170166 
    171167        if (!yes) {