Changeset 1390

Show
Ignore:
Timestamp:
06/12/02 04:52:16 (12 years ago)
Author:
mds
Message:

add ability to specify the "command" on a smbus block read

(previously forced to zero). Limit smbus block read printout to 32 bytes.

Files:
1 modified

Legend:

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

    r1311 r1390  
    4747  fprintf(stderr,"  MODE is 'b[yte]', 'w[ord]', 's[mbusblock], or 'i[2cblock]' (default b)\n"); 
    4848  fprintf(stderr,"  I2CBUS is an integer\n"); 
     49  fprintf(stderr,"  ADDRESS is an integer 0x00 - 0x7f\n"); 
     50  fprintf(stderr,"  BANK and BANKREG are for byte and word accesses (default bank 0, reg 0x4e)\n"); 
     51  fprintf(stderr,"  BANK is the command for smbusblock accesses (default 0)\n"); 
    4952  if((fptr = fopen("/proc/bus/i2c", "r"))) { 
    5053    fprintf(stderr,"  Installed I2C busses:\n"); 
     
    121124  if(argc > 4) { 
    122125    bank = strtol(argv[4],&end,0); 
    123     if (*end) { 
     126    if (*end || size == I2C_SMBUS_I2C_BLOCK_DATA) { 
    124127      fprintf(stderr,"Error: Invalid bank number!\n"); 
    125128      help(); 
    126129      exit(1); 
    127130    } 
    128     if ((bank < 0) || (bank > 15)) { 
    129       fprintf(stderr,"Error: bank out of range (0-15)!\n"); 
     131    if (((size == I2C_SMBUS_BYTE_DATA) || (size == I2C_SMBUS_WORD_DATA)) && 
     132        ((bank < 0) || (bank > 15))) { 
     133      fprintf(stderr,"Error: bank out of range!\n"); 
    130134      help(); 
    131135      exit(1); 
    132136    } 
     137    if (((size == I2C_SMBUS_BLOCK_DATA)) && 
     138        ((bank < 0) || (bank > 0xff))) { 
     139      fprintf(stderr,"Error: block command out of range!\n"); 
     140      help(); 
     141      exit(1); 
     142    } 
    133143 
    134144    if(argc > 5) { 
    135145      bankreg = strtol(argv[5],&end,0); 
    136       if (*end) { 
     146      if (*end || size == I2C_SMBUS_BLOCK_DATA) { 
    137147        fprintf(stderr,"Error: Invalid bank register number!\n"); 
    138148        help(); 
     
    251261                           size == I2C_SMBUS_BYTE_DATA ? "byte" : "word"); 
    252262  if(bank)       
    253     fprintf(stderr,"  Probing bank %d using bank register 0x%02x.\n", 
    254             bank, bankreg); 
     263    if(size == I2C_SMBUS_BLOCK_DATA) 
     264      fprintf(stderr,"  Using command 0x%02x.\n", bank); 
     265    else 
     266      fprintf(stderr,"  Probing bank %d using bank register 0x%02x.\n", 
     267              bank, bankreg); 
    255268  fprintf(stderr,"  You have five seconds to reconsider and press CTRL-C!\n\n"); 
    256269  sleep(5); 
    257270 
    258271  /* See Winbond w83781d data sheet for bank details */ 
    259   if(bank) { 
     272  if(bank && size != I2C_SMBUS_BLOCK_DATA) { 
    260273    i2c_smbus_write_byte_data(file,bankreg,bank | 0x80); 
    261274  } 
     
    267280    if(size == I2C_SMBUS_BLOCK_DATA || size == I2C_SMBUS_I2C_BLOCK_DATA) { 
    268281      if(size == I2C_SMBUS_BLOCK_DATA) { 
    269         res = i2c_smbus_read_block_data(file,0,cblock); 
     282        res = i2c_smbus_read_block_data(file, bank, cblock); 
    270283      } else if(size == I2C_SMBUS_I2C_BLOCK_DATA) { 
    271284#if USE_I2C_BLOCK 
     
    321334      } 
    322335      printf("\n"); 
     336    if(size == I2C_SMBUS_BLOCK_DATA && i == 16) 
     337      break;             
    323338    } 
    324339  } else { 
     
    336351    } 
    337352  } 
    338   if(bank) { 
     353  if(bank && size != I2C_SMBUS_BLOCK_DATA) { 
    339354    i2c_smbus_write_byte_data(file,bankreg,0x80); 
    340355  }