Changeset 1445
- Timestamp:
- 07/11/02 04:24:56 (11 years ago)
- Files:
-
- 1 modified
-
lm-sensors/trunk/prog/dump/i2cdump.c (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
-
lm-sensors/trunk/prog/dump/i2cdump.c
r1390 r1445 1 1 /* 2 2 i2cdump.c - Part of i2cdump, a user-space program to dump I2C registers 3 Copyright (c) 200 0Frodo Looijaard <frodol@dds.nl>, and3 Copyright (c) 2002 Frodo Looijaard <frodol@dds.nl>, and 4 4 Mark D. Studebaker <mdsxyz123@yahoo.com> 5 5 … … 38 38 #endif 39 39 40 #ifdef I2C_FUNC_SMBUS_BLOCK_DATA_PEC 41 #define HAVE_PEC 1 42 #endif 40 43 41 44 void help(void) … … 46 49 fprintf(stderr,"Syntax: i2cdump I2CBUS ADDRESS [MODE] [BANK [BANKREG]]\n"); 47 50 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"); 48 52 fprintf(stderr," I2CBUS is an integer\n"); 49 53 fprintf(stderr," ADDRESS is an integer 0x00 - 0x7f\n"); … … 71 75 unsigned char cblock[256]; 72 76 int block[256]; 77 int pec = 0; 73 78 74 79 if (argc < 2) { … … 106 111 107 112 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"); 109 114 size = I2C_SMBUS_BYTE_DATA; 110 } else if (!str cmp(argv[3],"b"))115 } else if (!strncmp(argv[3],"b",1)) { 111 116 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)) { 113 119 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)) { 115 122 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")) 117 125 size = I2C_SMBUS_I2C_BLOCK_DATA; 118 126 else { … … 214 222 switch(size) { 215 223 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 } 221 240 break; 222 241 223 242 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 } 229 259 break; 230 260 231 261 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 } 237 278 break; 238 279 … … 254 295 } 255 296 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 256 309 fprintf(stderr," WARNING! This program can confuse your I2C bus, " 257 310 "cause data loss and worse!\n"); … … 260 313 size == I2C_SMBUS_I2C_BLOCK_DATA ? "i2c block" : 261 314 size == I2C_SMBUS_BYTE_DATA ? "byte" : "word"); 262 if(bank) 315 if(pec) 316 fprintf(stderr," with PEC checking.\n", bank); 317 if(bank) { 263 318 if(size == I2C_SMBUS_BLOCK_DATA) 264 319 fprintf(stderr," Using command 0x%02x.\n", bank); … … 266 321 fprintf(stderr," Probing bank %d using bank register 0x%02x.\n", 267 322 bank, bankreg); 323 } 268 324 fprintf(stderr," You have five seconds to reconsider and press CTRL-C!\n\n"); 269 325 sleep(5);
