mirror of
https://github.com/lm-sensors/lm-sensors
synced 2025-08-29 21:38:17 +00:00
Wait for user input to continue (as opposed to 5 sec delay).
Can be skipped using -y. git-svn-id: http://lm-sensors.org/svn/lm-sensors/trunk@2680 7894878c-1315-0410-8ee3-d5d059ff63e0
This commit is contained in:
parent
7c969daeb5
commit
657ffe4e9c
@ -1,19 +1,33 @@
|
|||||||
.TH I2CDUMP 8 "July 2004"
|
.TH I2CDUMP 8 "August 2004"
|
||||||
.SH NAME
|
.SH NAME
|
||||||
i2cdump \- examine I2C registers
|
i2cdump \- examine I2C registers
|
||||||
|
|
||||||
.SH SYNOPSIS
|
.SH SYNOPSIS
|
||||||
.B i2cdump
|
.B i2cdump
|
||||||
|
.RB [ -y ]
|
||||||
.I i2cbus
|
.I i2cbus
|
||||||
.I address
|
.I address
|
||||||
.RI [ mode ]
|
.RI [ mode ]
|
||||||
.RI [ "bank " [ bankreg ]]
|
.RI [ "bank " [ bankreg ]]
|
||||||
|
.br
|
||||||
|
.B i2cdump
|
||||||
|
.B -V
|
||||||
|
|
||||||
.SH DESCRIPTION
|
.SH DESCRIPTION
|
||||||
i2cdump is a small helper program to examine registers
|
i2cdump is a small helper program to examine registers
|
||||||
visible through the I2C bus.
|
visible through the I2C bus.
|
||||||
|
|
||||||
.SH OPTIONS
|
.SH OPTIONS
|
||||||
|
.TP
|
||||||
|
.B -V
|
||||||
|
Display the version and exit.
|
||||||
|
.TP
|
||||||
|
.B -y
|
||||||
|
Disable interactive mode. By default, i2cdump will wait for a confirmation
|
||||||
|
from the user before messing with the I2C bus. When this flag is used, it
|
||||||
|
will perform the operation directly. This is mainly meant to be used in
|
||||||
|
scripts.
|
||||||
|
.PP
|
||||||
At least two options must be provided to i2cdump. \fIi2cbus\fR indicates the
|
At least two options must be provided to i2cdump. \fIi2cbus\fR indicates the
|
||||||
number of the I2C bus to be scanned. This number should correspond to one
|
number of the I2C bus to be scanned. This number should correspond to one
|
||||||
of the busses listed by \fIi2cdetect -l\fR. \fIaddress\fR indicates the
|
of the busses listed by \fIi2cdetect -l\fR. \fIaddress\fR indicates the
|
||||||
|
@ -45,8 +45,9 @@
|
|||||||
|
|
||||||
void help(void)
|
void help(void)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "Syntax: i2cdump I2CBUS ADDRESS [MODE] [BANK "
|
fprintf(stderr, "Syntax: i2cdump [-y] I2CBUS ADDRESS [MODE] [BANK "
|
||||||
"[BANKREG]]\n"
|
"[BANKREG]]\n"
|
||||||
|
" i2cdump -V\n"
|
||||||
" MODE is 'b[yte]', 'w[ord]', 's[mbusblock], 'i[2cblock]',\n"
|
" MODE is 'b[yte]', 'w[ord]', 's[mbusblock], 'i[2cblock]',\n"
|
||||||
" or 'c[onsecutive byte address mode]' (default b)\n"
|
" or 'c[onsecutive byte address mode]' (default b)\n"
|
||||||
" Append MODE with 'p' for PEC checking\n"
|
" Append MODE with 'p' for PEC checking\n"
|
||||||
@ -68,19 +69,34 @@ int main(int argc, char *argv[])
|
|||||||
unsigned char cblock[256];
|
unsigned char cblock[256];
|
||||||
int block[256];
|
int block[256];
|
||||||
int pec = 0;
|
int pec = 0;
|
||||||
|
int flags = 0;
|
||||||
|
int yes = 0, version = 0;
|
||||||
|
|
||||||
if (argc < 2) {
|
/* handle (optional) flags first */
|
||||||
fprintf(stderr, "Error: No i2c-bus specified!\n");
|
while (1+flags < argc && argv[1+flags][0] == '-') {
|
||||||
help();
|
switch (argv[1+flags][1]) {
|
||||||
exit(1);
|
case 'V': version = 1; break;
|
||||||
|
case 'y': yes = 1; break;
|
||||||
|
default:
|
||||||
|
fprintf(stderr, "Warning: Unsupported flag "
|
||||||
|
"\"-%c\"!\n", argv[1+flags][1]);
|
||||||
|
help();
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
flags++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!strcmp(argv[1], "-v") || !strcmp(argv[1], "-V")) {
|
if (version) {
|
||||||
fprintf(stderr, "i2cdump version %s\n", LM_VERSION);
|
fprintf(stderr, "i2cdump version %s\n", LM_VERSION);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
i2cbus = strtol(argv[1], &end, 0);
|
if (argc < flags + 2) {
|
||||||
|
fprintf(stderr, "Error: No i2c-bus specified!\n");
|
||||||
|
help();
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
i2cbus = strtol(argv[flags+1], &end, 0);
|
||||||
if (*end) {
|
if (*end) {
|
||||||
fprintf(stderr, "Error: First argument not a number!\n");
|
fprintf(stderr, "Error: First argument not a number!\n");
|
||||||
help();
|
help();
|
||||||
@ -92,12 +108,12 @@ int main(int argc, char *argv[])
|
|||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (argc < 3) {
|
if (argc < flags + 3) {
|
||||||
fprintf(stderr, "Error: No address specified!\n");
|
fprintf(stderr, "Error: No address specified!\n");
|
||||||
help();
|
help();
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
address = strtol(argv[2], &end, 0);
|
address = strtol(argv[flags+2], &end, 0);
|
||||||
if (*end) {
|
if (*end) {
|
||||||
fprintf(stderr, "Error: Second argument not a number!\n");
|
fprintf(stderr, "Error: Second argument not a number!\n");
|
||||||
help();
|
help();
|
||||||
@ -109,22 +125,22 @@ int main(int argc, char *argv[])
|
|||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (argc < 4) {
|
if (argc < flags + 4) {
|
||||||
fprintf(stderr, "No size specified (using byte-data access)\n");
|
fprintf(stderr, "No size specified (using byte-data access)\n");
|
||||||
size = I2C_SMBUS_BYTE_DATA;
|
size = I2C_SMBUS_BYTE_DATA;
|
||||||
} else if (!strncmp(argv[3], "b", 1)) {
|
} else if (!strncmp(argv[flags+3], "b", 1)) {
|
||||||
size = I2C_SMBUS_BYTE_DATA;
|
size = I2C_SMBUS_BYTE_DATA;
|
||||||
pec = argv[3][1] == 'p';
|
pec = argv[flags+3][1] == 'p';
|
||||||
} else if (!strncmp(argv[3], "w", 1)) {
|
} else if (!strncmp(argv[flags+3], "w", 1)) {
|
||||||
size = I2C_SMBUS_WORD_DATA;
|
size = I2C_SMBUS_WORD_DATA;
|
||||||
pec = argv[3][1] == 'p';
|
pec = argv[flags+3][1] == 'p';
|
||||||
} else if (!strncmp(argv[3], "s", 1)) {
|
} else if (!strncmp(argv[flags+3], "s", 1)) {
|
||||||
size = I2C_SMBUS_BLOCK_DATA;
|
size = I2C_SMBUS_BLOCK_DATA;
|
||||||
pec = argv[3][1] == 'p';
|
pec = argv[flags+3][1] == 'p';
|
||||||
} else if (!strncmp(argv[3], "c", 1)) {
|
} else if (!strncmp(argv[flags+3], "c", 1)) {
|
||||||
size = I2C_SMBUS_BYTE;
|
size = I2C_SMBUS_BYTE;
|
||||||
pec = argv[3][1] == 'p';
|
pec = argv[flags+3][1] == 'p';
|
||||||
} else if (!strcmp(argv[3], "i"))
|
} else if (!strcmp(argv[flags+3], "i"))
|
||||||
size = I2C_SMBUS_I2C_BLOCK_DATA;
|
size = I2C_SMBUS_I2C_BLOCK_DATA;
|
||||||
else {
|
else {
|
||||||
fprintf(stderr, "Error: Invalid mode!\n");
|
fprintf(stderr, "Error: Invalid mode!\n");
|
||||||
@ -132,8 +148,8 @@ int main(int argc, char *argv[])
|
|||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (argc > 4) {
|
if (argc > flags + 4) {
|
||||||
bank = strtol(argv[4], &end, 0);
|
bank = strtol(argv[flags+4], &end, 0);
|
||||||
if (*end || size == I2C_SMBUS_I2C_BLOCK_DATA) {
|
if (*end || size == I2C_SMBUS_I2C_BLOCK_DATA) {
|
||||||
fprintf(stderr, "Error: Invalid bank number!\n");
|
fprintf(stderr, "Error: Invalid bank number!\n");
|
||||||
help();
|
help();
|
||||||
@ -152,8 +168,8 @@ int main(int argc, char *argv[])
|
|||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (argc > 5) {
|
if (argc > flags + 5) {
|
||||||
bankreg = strtol(argv[5], &end, 0);
|
bankreg = strtol(argv[flags+5], &end, 0);
|
||||||
if (*end || size == I2C_SMBUS_BLOCK_DATA) {
|
if (*end || size == I2C_SMBUS_BLOCK_DATA) {
|
||||||
fprintf(stderr, "Error: Invalid bank register "
|
fprintf(stderr, "Error: Invalid bank register "
|
||||||
"number!\n");
|
"number!\n");
|
||||||
@ -297,26 +313,37 @@ int main(int argc, char *argv[])
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
fprintf(stderr, "WARNING! This program can confuse your I2C bus, "
|
if (!yes) {
|
||||||
"cause data loss and worse!\n");
|
char s[2];
|
||||||
fprintf(stderr, "I will probe file %s, address 0x%x, mode %s\n",
|
|
||||||
filename, address,
|
fprintf(stderr, "WARNING! This program can confuse your I2C "
|
||||||
size == I2C_SMBUS_BLOCK_DATA ? "smbus block" :
|
"bus, cause data loss and worse!\n");
|
||||||
size == I2C_SMBUS_I2C_BLOCK_DATA ? "i2c block" :
|
|
||||||
size == I2C_SMBUS_BYTE ? "byte consecutive read" :
|
fprintf(stderr, "I will probe file %s, address 0x%x, mode "
|
||||||
size == I2C_SMBUS_BYTE_DATA ? "byte" : "word");
|
"%s\n", filename, address,
|
||||||
if (pec)
|
size == I2C_SMBUS_BLOCK_DATA ? "smbus block" :
|
||||||
fprintf(stderr, "PEC checking enabled.\n");
|
size == I2C_SMBUS_I2C_BLOCK_DATA ? "i2c block" :
|
||||||
if (bank) {
|
size == I2C_SMBUS_BYTE ? "byte consecutive read" :
|
||||||
if (size == I2C_SMBUS_BLOCK_DATA)
|
size == I2C_SMBUS_BYTE_DATA ? "byte" : "word");
|
||||||
fprintf(stderr, "Using command 0x%02x.\n", bank);
|
if (pec)
|
||||||
else
|
fprintf(stderr, "PEC checking enabled.\n");
|
||||||
fprintf(stderr, "Probing bank %d using bank register "
|
if (bank) {
|
||||||
"0x%02x.\n", bank, bankreg);
|
if (size == I2C_SMBUS_BLOCK_DATA)
|
||||||
|
fprintf(stderr, "Using command 0x%02x.\n",
|
||||||
|
bank);
|
||||||
|
else
|
||||||
|
fprintf(stderr, "Probing bank %d using bank "
|
||||||
|
"register 0x%02x.\n", bank, bankreg);
|
||||||
|
}
|
||||||
|
|
||||||
|
fprintf(stderr, "Continue? [Y/n] ");
|
||||||
|
fflush(stderr);
|
||||||
|
fgets(s, 2, stdin);
|
||||||
|
if (s[0] != '\n' && s[0] != 'y' && s[0] != 'Y') {
|
||||||
|
fprintf(stderr, "Aborting on user request.\n");
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
fprintf(stderr, "You have five seconds to reconsider and press "
|
|
||||||
"CTRL-C!\n\n");
|
|
||||||
sleep(5);
|
|
||||||
|
|
||||||
/* See Winbond w83781d data sheet for bank details */
|
/* See Winbond w83781d data sheet for bank details */
|
||||||
if (bank && size != I2C_SMBUS_BLOCK_DATA) {
|
if (bank && size != I2C_SMBUS_BLOCK_DATA) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user