Changeset 2695

Show
Ignore:
Timestamp:
09/19/04 21:44:46 (9 years ago)
Author:
khali
Message:

Mass reindent/coding-style update.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • lm-sensors/trunk/prog/detect/i2cdetect.c

    r2675 r2695  
    11/* 
    2     i2cdetect.c - Part of i2cdetect, a user-space program to scan for I2C  
    3                   devices. 
     2    i2cdetect.c - a user-space program to scan for I2C devices 
    43    Copyright (C) 1999-2004  Frodo Looijaard <frodol@dds.nl>, 
    54                             Mark D. Studebaker <mdsxyz123@yahoo.com> and 
     
    4039                "  I2CBUS is an integer\n" 
    4140                "  With -f, scans all addresses (NOT RECOMMENDED)\n" 
    42                 "  With -q, uses only quick write commands for probing (NOT RECOMMENDED)\n" 
    43                 "  With -r, uses only read byte commands for probing (NOT RECOMMENDED)\n" 
     41                "  With -q, uses only quick write commands for probing (NOT " 
     42                "RECOMMENDED)\n" 
     43                "  With -r, uses only read byte commands for probing (NOT " 
     44                "RECOMMENDED)\n" 
    4445                "  If provided, FIRST and LAST limit the probing range.\n" 
    4546                "  i2cdetect -l lists installed busses only\n"); 
    46  
    47         print_i2c_busses(0); 
    4847} 
    4948 
     
    7069                                        continue; 
    7170                                } else { 
    72                                         fprintf(stderr, 
    73                                                 "Error: Could not set address to 0x%02x: %s\n", 
    74                                                 i+j, strerror(errno)); 
     71                                        fprintf(stderr, "Error: Could not set " 
     72                                                "address to 0x%02x: %s\n", i+j, 
     73                                                strerror(errno)); 
    7574                                        return -1; 
    7675                                } 
     
    8079                        switch (mode) { 
    8180                        case MODE_QUICK: 
    82                                 /* This is known to corrupt the Atmel AT24RF08 EEPROM */ 
    83                                 res = i2c_smbus_write_quick(file, I2C_SMBUS_WRITE); 
     81                                /* This is known to corrupt the Atmel AT24RF08 
     82                                   EEPROM */ 
     83                                res = i2c_smbus_write_quick(file, 
     84                                      I2C_SMBUS_WRITE); 
    8485                                break; 
    8586                        case MODE_READ: 
    86                                 /* This is known to lock SMBus on various write-only chips 
    87                                 (mainly clock chips) */ 
     87                                /* This is known to lock SMBus on various 
     88                                   write-only chips (mainly clock chips) */ 
    8889                                res = i2c_smbus_read_byte(file); 
    8990                                break; 
     
    9394                                        res = i2c_smbus_read_byte(file); 
    9495                                else 
    95                                         res = i2c_smbus_write_quick(file, I2C_SMBUS_WRITE); 
     96                                        res = i2c_smbus_write_quick(file, 
     97                                              I2C_SMBUS_WRITE); 
    9698                        } 
    9799 
     
    109111int main(int argc, char *argv[]) 
    110112{ 
    111   char *end; 
    112   int i = 1, i2cbus = -1, file, res; 
    113   char filename[20]; 
    114   long funcs; 
    115   int mode = MODE_AUTO; 
    116   int first = 0x03, last = 0x77; 
    117    
    118  
    119   while(i2cbus == -1) { 
    120     if (i >= argc) { 
    121       fprintf(stderr,"Error: No i2c-bus specified!\n"); 
    122       help(); 
    123       exit(1); 
    124     } 
    125  
    126     if(!strcasecmp(argv[i], "-v")) { 
    127       fprintf(stderr,"i2cdetect version %s\n", LM_VERSION); 
    128       exit(0); 
    129     } 
    130  
    131     if(!strcmp(argv[i], "-l")) { 
    132       print_i2c_busses(1); 
    133       exit(0); 
    134     } 
    135  
    136     if(!strcmp(argv[i], "-f")) { 
    137       first = 0x00; 
    138       last = 0x7F; 
    139       i++; 
    140     } else 
    141     if(!strcmp(argv[i], "-q")) { 
    142       if (mode != MODE_AUTO) { 
    143         fprintf(stderr,"Error: Different modes specified!\n"); 
    144         exit(1); 
    145       } 
    146       mode = MODE_QUICK; 
    147       i++; 
    148     } else 
    149     if(!strcmp(argv[i], "-r")) { 
    150       if (mode != MODE_AUTO) { 
    151         fprintf(stderr,"Error: Different modes specified!\n"); 
    152         exit(1); 
    153       } 
    154       mode = MODE_READ; 
    155       i++; 
    156     } else { 
    157       i2cbus = strtol(argv[i],&end,0); 
    158       if (*end) { 
    159         fprintf(stderr,"Error: I2CBUS argument not a number!\n"); 
    160         help(); 
    161         exit(1); 
    162       } 
    163       if ((i2cbus < 0) || (i2cbus > 0xff)) { 
    164         fprintf(stderr, 
    165                 "Error: I2CBUS argument out of range (0-255)!\n"); 
    166         help(); 
    167         exit(1); 
    168       } 
    169       i++; 
    170     } 
    171   } 
    172  
    173   /* read address range if present */ 
    174   if (i+2 == argc) { 
    175     int tmp; 
    176    
    177     tmp = strtol(argv[i], &end, 0); 
    178     if (*end) { 
    179       fprintf(stderr, 
    180               "Error: FIRST argment not a number!\n"); 
    181       help(); 
    182       exit(1); 
    183     } 
    184     if (tmp < first || tmp > last) { 
    185       fprintf(stderr, 
    186               "Error: FIRST argument out of range (0x%02x-0x%02x)!\n", 
    187               first, last); 
    188       help(); 
    189       exit(1); 
    190     } 
    191     first = tmp; 
    192  
    193     tmp = strtol(argv[i+1], &end, 0); 
    194     if (*end) { 
    195       fprintf(stderr, 
    196               "Error: LAST argment not a number!\n"); 
    197       help(); 
    198       exit(1); 
    199     } 
    200     if (tmp < first || tmp > last) { 
    201       fprintf(stderr, 
    202               "Error: LAST argument out of range (0x%02x-0x%02x)!\n", 
    203               first, last); 
    204       help(); 
    205       exit(1); 
    206     } 
    207     last = tmp; 
    208   } else if (i != argc) { 
    209     help(); 
    210     exit(1); 
    211   } 
    212  
    213   file = open_i2c_dev(i2cbus, filename); 
    214   if (file < 0) { 
    215     exit(1); 
    216   } 
    217  
    218   if (ioctl(file,I2C_FUNCS,&funcs) < 0) { 
    219     fprintf(stderr, 
    220             "Error: Could not get the adapter functionality matrix: %s\n", 
    221             strerror(errno)); 
    222     close(file); 
    223     exit(1); 
    224   } 
    225   if (mode != MODE_READ && !(funcs & I2C_FUNC_SMBUS_QUICK)) { 
    226     fprintf(stderr, 
    227             "Error: Can't use SMBus Quick Write command " 
    228             "on this bus (ISA bus?)\n"); 
    229     close(file); 
    230     exit(1); 
    231   } 
    232   if (mode != MODE_QUICK && !(funcs & I2C_FUNC_SMBUS_READ_BYTE)) { 
    233     fprintf(stderr, 
    234             "Error: Can't use SMBus Read Byte command " 
    235             "on this bus (ISA bus?)\n"); 
    236     close(file); 
    237     exit(1); 
    238   } 
    239    
    240   fprintf(stderr,"  WARNING! This program can confuse your I2C bus, " 
    241           "cause data loss and worse!\n"); 
    242   fprintf(stderr, "  I will probe file %s%s.\n", filename, 
    243           mode==MODE_QUICK?" using quick write commands": 
    244           mode==MODE_READ?" using read byte commands":""); 
    245   fprintf(stderr, "  I will probe address range 0x%02x-0x%02x.\n", 
    246           first, last); 
    247   fprintf(stderr,"  You have five seconds to reconsider and press CTRL-C!\n\n"); 
    248   sleep(5); 
    249  
    250   res = scan_i2c_bus(file, mode, first, last); 
    251  
    252   close(file); 
    253  
    254   exit(res?1:0); 
     113        char *end; 
     114        int i = 1, i2cbus = -1, file, res; 
     115        char filename[20]; 
     116        long funcs; 
     117        int mode = MODE_AUTO; 
     118        int first = 0x03, last = 0x77; 
     119 
     120        while(i2cbus == -1) { 
     121                if (i >= argc) { 
     122                        fprintf(stderr, "Error: No i2c-bus specified!\n"); 
     123                        help(); 
     124                        exit(1); 
     125                } 
     126 
     127                if(!strcasecmp(argv[i], "-v")) { 
     128                        fprintf(stderr, "i2cdetect version %s\n", LM_VERSION); 
     129                        exit(0); 
     130                } 
     131 
     132                if(!strcmp(argv[i], "-l")) { 
     133                        print_i2c_busses(1); 
     134                        exit(0); 
     135                } 
     136 
     137                if(!strcmp(argv[i], "-f")) { 
     138                        first = 0x00; 
     139                        last = 0x7F; 
     140                        i++; 
     141                } else 
     142                if(!strcmp(argv[i], "-q")) { 
     143                        if (mode != MODE_AUTO) { 
     144                                fprintf(stderr, "Error: Different modes " 
     145                                        "specified!\n"); 
     146                                exit(1); 
     147                        } 
     148                        mode = MODE_QUICK; 
     149                        i++; 
     150                } else 
     151                if(!strcmp(argv[i], "-r")) { 
     152                        if (mode != MODE_AUTO) { 
     153                                fprintf(stderr, "Error: Different modes " 
     154                                        "specified!\n"); 
     155                                exit(1); 
     156                        } 
     157                        mode = MODE_READ; 
     158                        i++; 
     159                } else { 
     160                        i2cbus = strtol(argv[i],&end,0); 
     161                        if (*end) { 
     162                                fprintf(stderr, "Error: I2CBUS argument not a " 
     163                                        "number!\n"); 
     164                                help(); 
     165                                exit(1); 
     166                        } 
     167                        if ((i2cbus < 0) || (i2cbus > 0xff)) { 
     168                                fprintf(stderr, "Error: I2CBUS argument out " 
     169                                        "of range (0-255)!\n"); 
     170                                help(); 
     171                                exit(1); 
     172                        } 
     173                        i++; 
     174                } 
     175        } 
     176 
     177        /* read address range if present */ 
     178        if (i+2 == argc) { 
     179                int tmp; 
     180 
     181                tmp = strtol(argv[i], &end, 0); 
     182                if (*end) { 
     183                        fprintf(stderr, "Error: FIRST argment not a " 
     184                                "number!\n"); 
     185                        help(); 
     186                        exit(1); 
     187                } 
     188                if (tmp < first || tmp > last) { 
     189                        fprintf(stderr, "Error: FIRST argument out of range " 
     190                                "(0x%02x-0x%02x)!\n", first, last); 
     191                        help(); 
     192                        exit(1); 
     193                } 
     194                first = tmp; 
     195 
     196                tmp = strtol(argv[i+1], &end, 0); 
     197                if (*end) { 
     198                        fprintf(stderr, "Error: LAST argment not a " 
     199                                "number!\n"); 
     200                        help(); 
     201                        exit(1); 
     202                } 
     203                if (tmp < first || tmp > last) { 
     204                        fprintf(stderr, "Error: LAST argument out of range " 
     205                                "(0x%02x-0x%02x)!\n", first, last); 
     206                        help(); 
     207                        exit(1); 
     208                } 
     209                last = tmp; 
     210        } else if (i != argc) { 
     211                help(); 
     212                exit(1); 
     213        } 
     214 
     215        file = open_i2c_dev(i2cbus, filename); 
     216        if (file < 0) { 
     217                exit(1); 
     218        } 
     219 
     220        if (ioctl(file,I2C_FUNCS,&funcs) < 0) { 
     221                fprintf(stderr, "Error: Could not get the adapter " 
     222                        "functionality matrix: %s\n", strerror(errno)); 
     223                close(file); 
     224                exit(1); 
     225        } 
     226        if (mode != MODE_READ && !(funcs & I2C_FUNC_SMBUS_QUICK)) { 
     227                fprintf(stderr, "Error: Can't use SMBus Quick Write command " 
     228                        "on this bus (ISA bus?)\n"); 
     229                close(file); 
     230                exit(1); 
     231        } 
     232        if (mode != MODE_QUICK && !(funcs & I2C_FUNC_SMBUS_READ_BYTE)) { 
     233                fprintf(stderr, "Error: Can't use SMBus Read Byte command " 
     234                        "on this bus (ISA bus?)\n"); 
     235                close(file); 
     236                exit(1); 
     237        } 
     238 
     239        fprintf(stderr, "  WARNING! This program can confuse your I2C bus, " 
     240                "cause data loss and worse!\n"); 
     241        fprintf(stderr, "  I will probe file %s%s.\n", filename, 
     242                mode==MODE_QUICK?" using quick write commands": 
     243                mode==MODE_READ?" using read byte commands":""); 
     244        fprintf(stderr, "  I will probe address range 0x%02x-0x%02x.\n", 
     245                first, last); 
     246        fprintf(stderr, "  You have five seconds to reconsider and press " 
     247                "CTRL-C!\n\n"); 
     248        sleep(5); 
     249 
     250        res = scan_i2c_bus(file, mode, first, last); 
     251 
     252        close(file); 
     253 
     254        exit(res?1:0); 
    255255}