Changeset 1445

Show
Ignore:
Timestamp:
07/11/02 04:24:56 (12 years ago)
Author:
mds
Message:

add PEC support

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • lm-sensors/trunk/prog/dump/i2cdump.c

    r1390 r1445  
    11/* 
    22    i2cdump.c - Part of i2cdump, a user-space program to dump I2C registers 
    3     Copyright (c) 2000  Frodo Looijaard <frodol@dds.nl>, and 
     3    Copyright (c) 2002  Frodo Looijaard <frodol@dds.nl>, and 
    44    Mark D. Studebaker <mdsxyz123@yahoo.com> 
    55 
     
    3838#endif 
    3939 
     40#ifdef I2C_FUNC_SMBUS_BLOCK_DATA_PEC 
     41#define HAVE_PEC 1 
     42#endif 
    4043 
    4144void help(void) 
     
    4649  fprintf(stderr,"Syntax: i2cdump I2CBUS ADDRESS [MODE] [BANK [BANKREG]]\n"); 
    4750  fprintf(stderr,"  MODE is 'b[yte]', 'w[ord]', 's[mbusblock], or 'i[2cblock]' (default b)\n"); 
     51  fprintf(stderr,"  Append MODE with 'p' for PEC checking\n"); 
    4852  fprintf(stderr,"  I2CBUS is an integer\n"); 
    4953  fprintf(stderr,"  ADDRESS is an integer 0x00 - 0x7f\n"); 
     
    7175  unsigned char cblock[256];   
    7276  int block[256];   
     77  int pec = 0; 
    7378 
    7479  if (argc < 2) { 
     
    106111 
    107112  if (argc < 4) { 
    108     fprintf(stderr,"Warning: no size specified (using byte-data access)\n"); 
     113    fprintf(stderr,"No size specified (using byte-data access)\n"); 
    109114    size = I2C_SMBUS_BYTE_DATA; 
    110   } else if (!strcmp(argv[3],"b")) 
     115  } else if (!strncmp(argv[3],"b",1)) { 
    111116    size = I2C_SMBUS_BYTE_DATA; 
    112   else if (!strcmp(argv[3],"w")) 
     117    pec = argv[3][1] == 'p'; 
     118  } else if (!strncmp(argv[3],"w",1)) { 
    113119    size = I2C_SMBUS_WORD_DATA; 
    114   else if (!strcmp(argv[3],"s")) 
     120    pec = argv[3][1] == 'p'; 
     121  } else if (!strncmp(argv[3],"s",1)) { 
    115122    size = I2C_SMBUS_BLOCK_DATA; 
    116   else if (!strcmp(argv[3],"i")) 
     123    pec = argv[3][1] == 'p'; 
     124  } else if (!strcmp(argv[3],"i")) 
    117125    size = I2C_SMBUS_I2C_BLOCK_DATA; 
    118126  else { 
     
    214222  switch(size) { 
    215223     case I2C_SMBUS_BYTE_DATA: 
    216         if (! (funcs & I2C_FUNC_SMBUS_READ_BYTE_DATA)) { 
    217            fprintf(stderr, "Error: Adapter for i2c bus %d", i2cbus); 
    218            fprintf(stderr, " does not have byte read capability\n"); 
    219            exit(1); 
    220         }        
     224#ifdef HAVE_PEC 
     225        if(pec) { 
     226          if (! (funcs & I2C_FUNC_SMBUS_READ_BYTE_DATA_PEC)) { 
     227             fprintf(stderr, "Error: Adapter for i2c bus %d", i2cbus); 
     228             fprintf(stderr, " does not have byte read w/ PEC capability\n"); 
     229             exit(1); 
     230          }        
     231        } else 
     232#endif 
     233        { 
     234          if (! (funcs & I2C_FUNC_SMBUS_READ_BYTE_DATA)) { 
     235             fprintf(stderr, "Error: Adapter for i2c bus %d", i2cbus); 
     236             fprintf(stderr, " does not have byte read capability\n"); 
     237             exit(1); 
     238          }        
     239        } 
    221240        break; 
    222241 
    223242     case I2C_SMBUS_WORD_DATA: 
    224         if (! (funcs & I2C_FUNC_SMBUS_READ_WORD_DATA)) { 
    225            fprintf(stderr, "Error: Adapter for i2c bus %d", i2cbus); 
    226            fprintf(stderr, " does not have word read capability\n"); 
    227            exit(1); 
    228         }        
     243#ifdef HAVE_PEC 
     244        if(pec) { 
     245          if (! (funcs & I2C_FUNC_SMBUS_READ_WORD_DATA_PEC)) { 
     246             fprintf(stderr, "Error: Adapter for i2c bus %d", i2cbus); 
     247             fprintf(stderr, " does not have word read w/ PEC capability\n"); 
     248             exit(1); 
     249          }        
     250        } else 
     251#endif 
     252        { 
     253          if (! (funcs & I2C_FUNC_SMBUS_READ_WORD_DATA)) { 
     254             fprintf(stderr, "Error: Adapter for i2c bus %d", i2cbus); 
     255             fprintf(stderr, " does not have word read capability\n"); 
     256             exit(1); 
     257          }        
     258        } 
    229259        break; 
    230260 
    231261     case I2C_SMBUS_BLOCK_DATA: 
    232         if (! (funcs & I2C_FUNC_SMBUS_READ_BLOCK_DATA)) { 
    233            fprintf(stderr, "Error: Adapter for i2c bus %d", i2cbus); 
    234            fprintf(stderr, " does not have smbus block read capability\n"); 
    235            exit(1); 
    236         }        
     262#ifdef HAVE_PEC 
     263        if(pec) { 
     264          if (! (funcs & I2C_FUNC_SMBUS_READ_BLOCK_DATA_PEC)) { 
     265             fprintf(stderr, "Error: Adapter for i2c bus %d", i2cbus); 
     266             fprintf(stderr, " does not have smbus block read capability\n"); 
     267             exit(1); 
     268          }        
     269        } else 
     270#endif 
     271        { 
     272          if (! (funcs & I2C_FUNC_SMBUS_READ_BLOCK_DATA)) { 
     273             fprintf(stderr, "Error: Adapter for i2c bus %d", i2cbus); 
     274             fprintf(stderr, " does not have smbus block read w/ PEC capability\n"); 
     275             exit(1); 
     276          }        
     277        } 
    237278        break; 
    238279 
     
    254295  } 
    255296  
     297  if(pec) { 
     298#ifdef HAVE_PEC 
     299    if (ioctl(file,I2C_PEC, 1) < 0) { 
     300      fprintf(stderr,"Error: Could not set PEC: %s\n", strerror(errno)); 
     301      exit(1); 
     302    } 
     303#else 
     304    fprintf(stderr,"Error: PEC not supported in your kernel\n"); 
     305    exit(1); 
     306#endif 
     307  } 
     308 
    256309  fprintf(stderr,"  WARNING! This program can confuse your I2C bus, " 
    257310          "cause data loss and worse!\n"); 
     
    260313                           size == I2C_SMBUS_I2C_BLOCK_DATA ? "i2c block" : 
    261314                           size == I2C_SMBUS_BYTE_DATA ? "byte" : "word"); 
    262   if(bank)       
     315  if(pec) 
     316    fprintf(stderr,"  with PEC checking.\n", bank); 
     317  if(bank) {     
    263318    if(size == I2C_SMBUS_BLOCK_DATA) 
    264319      fprintf(stderr,"  Using command 0x%02x.\n", bank); 
     
    266321      fprintf(stderr,"  Probing bank %d using bank register 0x%02x.\n", 
    267322              bank, bankreg); 
     323  } 
    268324  fprintf(stderr,"  You have five seconds to reconsider and press CTRL-C!\n\n"); 
    269325  sleep(5);