Changeset 2676
- Timestamp:
- 08/29/04 23:22:00 (9 years ago)
- Location:
- lm-sensors/trunk/prog/dump
- Files:
-
- 2 modified
Legend:
- Unmodified
- Added
- Removed
-
lm-sensors/trunk/prog/dump/i2cset.8
r2647 r2676 1 .TH I2CSET 8 " July2004"1 .TH I2CSET 8 "August 2004" 2 2 .SH "NAME" 3 3 i2cset \- set I2C registers … … 5 5 .SH SYNOPSIS 6 6 .B i2cset 7 .RB [ -y ] 7 8 .I i2cbus 8 9 .I chip-address … … 10 11 .I value 11 12 .RI [ mode ] 13 .br 14 .B i2cset 15 .B -V 12 16 13 17 .SH DESCRIPTION … … 16 20 17 21 .SH OPTIONS 22 .TP 23 .B -v, -V 24 Display the version and exit. 25 .TP 26 .B -y 27 Disable interactive mode. By default, isaset will wait for a confirmation 28 from the user before messing with the ISA bus. When this flag is used, it 29 will perform the operation directly. This is mainly meant to be used in 30 scripts. 31 .PP 18 32 There are four required options to i2cset. \fIi2cbus\fR indicates the number 19 33 of the I2C bus to be scanned. This number should correspond to one of -
lm-sensors/trunk/prog/dump/i2cset.c
r2675 r2676 33 33 void help(void) 34 34 { 35 fprintf(stderr, "Syntax: i2cset I2CBUS CHIP-ADDRESS DATA-ADDRESS " 36 "VALUE [MODE]\n"); 35 fprintf(stderr, "Syntax: i2cset [-y] I2CBUS CHIP-ADDRESS DATA-ADDRESS " 36 "VALUE [MODE]\n" 37 " i2cset -V\n"); 37 38 fprintf(stderr, " MODE is 'b[yte]' or 'w[ord]' (default b)\n"); 38 39 fprintf(stderr, " I2CBUS is an integer\n"); … … 49 50 char filename[20]; 50 51 long funcs; 51 52 if (argc >= 2 && (!strcmp(argv[1], "-v") || !strcmp(argv[1], "-V"))) { 52 int flags = 0; 53 int yes = 0, version = 0; 54 55 /* handle (optional) flags first */ 56 while (1+flags < argc && argv[1+flags][0] == '-') { 57 switch (argv[1+flags][1]) { 58 case 'V': version = 1; break; 59 case 'y': yes = 1; break; 60 default: 61 fprintf(stderr, "Warning: Unsupported flag " 62 "\"-%c\"!\n", argv[1+flags][1]); 63 help(); 64 exit(1); 65 } 66 flags++; 67 } 68 69 if (version) { 53 70 fprintf(stderr, "i2cset version %s\n", LM_VERSION); 54 71 exit(1); 55 72 } 56 73 57 if (argc < 5)58 help(); 59 60 i2cbus = strtol(argv[ 1], &end, 0);74 if (argc + flags < 5) 75 help(); 76 77 i2cbus = strtol(argv[flags+1], &end, 0); 61 78 if (*end || i2cbus < 0 || i2cbus > 0x3f) { 62 79 fprintf(stderr, "Error: I2CBUS argument invalid!\n"); … … 64 81 } 65 82 66 address = strtol(argv[ 2], &end, 0);83 address = strtol(argv[flags+2], &end, 0); 67 84 if (*end || address < 0 || address > 0x7f) { 68 85 fprintf(stderr, "Error: Chip address invalid!\n"); … … 70 87 } 71 88 72 daddress = strtol(argv[ 3], &end, 0);89 daddress = strtol(argv[flags+3], &end, 0); 73 90 if (*end || daddress < 0 || daddress > 0xff) { 74 91 fprintf(stderr, "Error: Data address invalid!\n"); … … 76 93 } 77 94 78 value = strtol(argv[ 4], &end, 0);95 value = strtol(argv[flags+4], &end, 0); 79 96 if (*end) { 80 97 fprintf(stderr, "Error: Data value invalid!\n"); … … 82 99 } 83 100 84 if (argc < 6) {101 if (argc < flags + 6) { 85 102 fprintf(stderr, "No size specified (using byte-data access)\n"); 86 103 size = I2C_SMBUS_BYTE_DATA; 87 } else if (!strcmp(argv[ 5], "b"))104 } else if (!strcmp(argv[flags+5], "b")) 88 105 size = I2C_SMBUS_BYTE_DATA; 89 else if (!strcmp(argv[ 5], "w"))106 else if (!strcmp(argv[flags+5], "w")) 90 107 size = I2C_SMBUS_WORD_DATA; 91 108 else { … … 139 156 } 140 157 141 fprintf(stderr, "WARNING! This program can confuse your I2C bus, " 142 "cause data loss and worse!\n"); 143 if (address >= 0x50 && address <= 0x57) { 144 fprintf(stderr, "DANGEROUS!! Writing to a serial EEPROM on " 145 "a memory DIMM\nmay render your memory USELESS and " 146 "make your system UNBOOTABLE!!!\nAre you SURE that " 147 "you want to write to the chip at address 0x%02x? " 148 "(y/N) ", address); 149 res = getchar(); 150 if (res != 'y' && res != 'Y') 151 exit(1); 152 } 153 154 fprintf(stderr, "I will write to device file %s, chip address 0x%02x, " 155 "data address\n0x%02x, data 0x%02x, mode %s.\n", filename, 156 address, daddress, value, size == I2C_SMBUS_BYTE_DATA ? 157 "byte" : "word"); 158 fprintf(stderr, "You have five seconds to reconsider and press " 159 "CTRL-C!\n\n"); 160 sleep(5); 158 if (!yes) { 159 char s[2]; 160 int dont = 0; 161 162 fprintf(stderr, "WARNING! This program can confuse your I2C " 163 "bus, cause data loss and worse!\n"); 164 165 if (address >= 0x50 && address <= 0x57) { 166 fprintf(stderr, "DANGEROUS! Writing to a serial " 167 "EEPROM on a memory DIMM\nmay render your " 168 "memory USELESS and make your system " 169 "UNBOOTABLE!\n"); 170 dont = 1; 171 } 172 173 fprintf(stderr, "I will write to device file %s, chip address " 174 "0x%02x, data address\n0x%02x, data 0x%02x, mode " 175 "%s.\n", filename, address, daddress, value, 176 size == I2C_SMBUS_BYTE_DATA ? "byte" : "word"); 177 178 fprintf(stderr, "Continue? [%s] ", dont ? "y/N" : "Y/n"); 179 fflush(stderr); 180 fgets(s, 2, stdin); 181 if ((s[0] != '\n' || dont) && s[0] != 'y' && s[0] != 'Y') { 182 fprintf(stderr, "Aborting on user request.\n"); 183 exit(0); 184 } 185 } 161 186 162 187 e1 = 0;
