1999-01-13 20:23:48 +00:00
|
|
|
/*
|
|
|
|
i2cdump.c - Part of i2cdump, a user-space program to dump I2C registers
|
2003-11-17 03:04:09 +00:00
|
|
|
Copyright (c) 2002-2003 Frodo Looijaard <frodol@dds.nl>, and
|
2000-08-12 19:16:00 +00:00
|
|
|
Mark D. Studebaker <mdsxyz123@yahoo.com>
|
1999-01-13 20:23:48 +00:00
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
*/
|
|
|
|
|
1999-01-14 00:41:44 +00:00
|
|
|
#include <errno.h>
|
|
|
|
#include <string.h>
|
1999-01-13 20:23:48 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <fcntl.h>
|
2003-01-21 20:01:27 +00:00
|
|
|
#include "i2c-dev.h"
|
2003-11-17 03:04:09 +00:00
|
|
|
#include "version.h"
|
1999-01-13 20:23:48 +00:00
|
|
|
|
2001-11-19 21:14:43 +00:00
|
|
|
/*
|
|
|
|
We don't use this #define but it was put into i2c.h at the same time as
|
|
|
|
i2c_smbus_read_i2c_block_data() was implemented (i2c 2.6.3),
|
|
|
|
so we use it as a version check.
|
|
|
|
*/
|
2001-12-04 00:30:55 +00:00
|
|
|
#ifdef I2C_FUNC_SMBUS_READ_I2C_BLOCK_2
|
2001-11-19 21:14:43 +00:00
|
|
|
#define USE_I2C_BLOCK 1
|
|
|
|
#else
|
|
|
|
#define USE_I2C_BLOCK 0
|
|
|
|
#endif
|
|
|
|
|
2002-07-11 02:24:56 +00:00
|
|
|
#ifdef I2C_FUNC_SMBUS_BLOCK_DATA_PEC
|
|
|
|
#define HAVE_PEC 1
|
|
|
|
#endif
|
2001-11-19 21:14:43 +00:00
|
|
|
|
2003-11-28 04:37:08 +00:00
|
|
|
void print_i2c_busses(int);
|
2003-11-17 03:04:09 +00:00
|
|
|
|
1999-01-13 20:23:48 +00:00
|
|
|
void help(void)
|
|
|
|
{
|
2000-05-12 00:16:08 +00:00
|
|
|
fprintf(stderr,"Syntax: i2cdump I2CBUS ADDRESS [MODE] [BANK [BANKREG]]\n");
|
2003-11-26 03:45:18 +00:00
|
|
|
fprintf(stderr," MODE is 'b[yte]', 'w[ord]', 's[mbusblock], 'i[2cblock]',\n");
|
2003-12-14 17:54:42 +00:00
|
|
|
fprintf(stderr," or 'c[onsecutive byte address mode]' (default b)\n");
|
2002-07-11 02:24:56 +00:00
|
|
|
fprintf(stderr," Append MODE with 'p' for PEC checking\n");
|
2000-01-09 22:45:57 +00:00
|
|
|
fprintf(stderr," I2CBUS is an integer\n");
|
2002-06-12 02:52:16 +00:00
|
|
|
fprintf(stderr," ADDRESS is an integer 0x00 - 0x7f\n");
|
|
|
|
fprintf(stderr," BANK and BANKREG are for byte and word accesses (default bank 0, reg 0x4e)\n");
|
|
|
|
fprintf(stderr," BANK is the command for smbusblock accesses (default 0)\n");
|
2003-11-28 04:37:08 +00:00
|
|
|
print_i2c_busses(0);
|
1999-01-13 20:23:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
char *end;
|
2001-12-04 00:30:55 +00:00
|
|
|
int i,j,res,res2,i2cbus,address,size,file;
|
2001-03-31 19:00:45 +00:00
|
|
|
int e1, e2, e3;
|
2000-05-12 00:16:08 +00:00
|
|
|
int bank = 0, bankreg = 0x4E;
|
2000-07-02 18:11:31 +00:00
|
|
|
char filename1[20];
|
|
|
|
char filename2[20];
|
2001-03-31 19:00:45 +00:00
|
|
|
char filename3[20];
|
2000-07-02 18:11:31 +00:00
|
|
|
char *filename;
|
2000-08-12 19:16:00 +00:00
|
|
|
long funcs;
|
|
|
|
unsigned char cblock[256];
|
|
|
|
int block[256];
|
2002-07-11 02:24:56 +00:00
|
|
|
int pec = 0;
|
1999-01-13 20:23:48 +00:00
|
|
|
|
|
|
|
if (argc < 2) {
|
|
|
|
fprintf(stderr,"Error: No i2c-bus specified!\n");
|
|
|
|
help();
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2003-11-17 03:04:09 +00:00
|
|
|
if((!strcmp(argv[1], "-v")) || (!strcmp(argv[1], "-V"))) {
|
|
|
|
fprintf(stderr,"i2cdump version %s\n", LM_VERSION);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
1999-01-13 20:23:48 +00:00
|
|
|
i2cbus = strtol(argv[1],&end,0);
|
|
|
|
if (*end) {
|
|
|
|
fprintf(stderr,"Error: First argument not a number!\n");
|
|
|
|
help();
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
if ((i2cbus < 0) || (i2cbus > 0xff)) {
|
|
|
|
fprintf(stderr,"Error: I2CBUS argument out of range!\n");
|
|
|
|
help();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (argc < 3) {
|
|
|
|
fprintf(stderr,"Error: No address specified!\n");
|
|
|
|
help();
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
address = strtol(argv[2],&end,0);
|
|
|
|
if (*end) {
|
|
|
|
fprintf(stderr,"Error: Second argument not a number!\n");
|
|
|
|
help();
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
if ((address < 0) || (address > 0x7f)) {
|
|
|
|
fprintf(stderr,"Error: Address out of range!\n");
|
|
|
|
help();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (argc < 4) {
|
2002-07-11 02:24:56 +00:00
|
|
|
fprintf(stderr,"No size specified (using byte-data access)\n");
|
1999-07-21 10:12:21 +00:00
|
|
|
size = I2C_SMBUS_BYTE_DATA;
|
2002-07-11 02:24:56 +00:00
|
|
|
} else if (!strncmp(argv[3],"b",1)) {
|
1999-07-21 10:12:21 +00:00
|
|
|
size = I2C_SMBUS_BYTE_DATA;
|
2002-07-11 02:24:56 +00:00
|
|
|
pec = argv[3][1] == 'p';
|
|
|
|
} else if (!strncmp(argv[3],"w",1)) {
|
1999-07-21 10:12:21 +00:00
|
|
|
size = I2C_SMBUS_WORD_DATA;
|
2002-07-11 02:24:56 +00:00
|
|
|
pec = argv[3][1] == 'p';
|
|
|
|
} else if (!strncmp(argv[3],"s",1)) {
|
2000-08-12 19:16:00 +00:00
|
|
|
size = I2C_SMBUS_BLOCK_DATA;
|
2002-07-11 02:24:56 +00:00
|
|
|
pec = argv[3][1] == 'p';
|
2003-11-26 03:45:18 +00:00
|
|
|
} else if (!strncmp(argv[3],"c",1)) {
|
|
|
|
size = I2C_SMBUS_BYTE;
|
|
|
|
pec = argv[3][1] == 'p';
|
2002-07-11 02:24:56 +00:00
|
|
|
} else if (!strcmp(argv[3],"i"))
|
2000-08-12 19:16:00 +00:00
|
|
|
size = I2C_SMBUS_I2C_BLOCK_DATA;
|
1999-01-13 20:23:48 +00:00
|
|
|
else {
|
2000-08-12 19:16:00 +00:00
|
|
|
fprintf(stderr,"Error: Invalid mode!\n");
|
1999-01-13 20:23:48 +00:00
|
|
|
help();
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2000-05-12 00:16:08 +00:00
|
|
|
if(argc > 4) {
|
|
|
|
bank = strtol(argv[4],&end,0);
|
2002-06-12 02:52:16 +00:00
|
|
|
if (*end || size == I2C_SMBUS_I2C_BLOCK_DATA) {
|
2000-05-12 00:16:08 +00:00
|
|
|
fprintf(stderr,"Error: Invalid bank number!\n");
|
|
|
|
help();
|
|
|
|
exit(1);
|
|
|
|
}
|
2002-06-12 02:52:16 +00:00
|
|
|
if (((size == I2C_SMBUS_BYTE_DATA) || (size == I2C_SMBUS_WORD_DATA)) &&
|
|
|
|
((bank < 0) || (bank > 15))) {
|
|
|
|
fprintf(stderr,"Error: bank out of range!\n");
|
|
|
|
help();
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
if (((size == I2C_SMBUS_BLOCK_DATA)) &&
|
|
|
|
((bank < 0) || (bank > 0xff))) {
|
|
|
|
fprintf(stderr,"Error: block command out of range!\n");
|
2000-05-12 00:16:08 +00:00
|
|
|
help();
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(argc > 5) {
|
|
|
|
bankreg = strtol(argv[5],&end,0);
|
2002-06-12 02:52:16 +00:00
|
|
|
if (*end || size == I2C_SMBUS_BLOCK_DATA) {
|
2000-05-12 00:16:08 +00:00
|
|
|
fprintf(stderr,"Error: Invalid bank register number!\n");
|
|
|
|
help();
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
if ((bankreg < 0) || (bankreg > 0xff)) {
|
|
|
|
fprintf(stderr,"Error: bank out of range (0-0xff)!\n");
|
|
|
|
help();
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-03-31 19:00:45 +00:00
|
|
|
/*
|
|
|
|
* Try all three variants and give the correct error message
|
|
|
|
* upon failure
|
|
|
|
*/
|
|
|
|
|
2000-07-02 18:11:31 +00:00
|
|
|
sprintf(filename1,"/dev/i2c-%d",i2cbus);
|
2000-07-04 01:42:30 +00:00
|
|
|
sprintf(filename2,"/dev/i2c%d",i2cbus);
|
2001-03-31 19:00:45 +00:00
|
|
|
sprintf(filename3,"/dev/i2c/%d",i2cbus);
|
2000-07-02 18:11:31 +00:00
|
|
|
if ((file = open(filename1,O_RDWR)) < 0) {
|
2000-07-16 22:54:41 +00:00
|
|
|
e1 = errno;
|
2000-07-04 01:42:30 +00:00
|
|
|
if ((file = open(filename2,O_RDWR)) < 0) {
|
2000-07-16 22:54:41 +00:00
|
|
|
e2 = errno;
|
2001-03-31 19:00:45 +00:00
|
|
|
if ((file = open(filename3,O_RDWR)) < 0) {
|
|
|
|
e3 = errno;
|
|
|
|
if(e1 == ENOENT && e2 == ENOENT && e3 == ENOENT) {
|
|
|
|
fprintf(stderr,"Error: Could not open file `%s', `%s', or `%s': %s\n",
|
|
|
|
filename1,filename2,filename3,strerror(ENOENT));
|
|
|
|
}
|
|
|
|
if (e1 != ENOENT) {
|
|
|
|
fprintf(stderr,"Error: Could not open file `%s' : %s\n",
|
|
|
|
filename1,strerror(e1));
|
|
|
|
if(e1 == EACCES)
|
|
|
|
fprintf(stderr,"Run as root?\n");
|
|
|
|
}
|
|
|
|
if (e2 != ENOENT) {
|
|
|
|
fprintf(stderr,"Error: Could not open file `%s' : %s\n",
|
|
|
|
filename2,strerror(e2));
|
|
|
|
if(e2 == EACCES)
|
|
|
|
fprintf(stderr,"Run as root?\n");
|
|
|
|
}
|
|
|
|
if (e3 != ENOENT) {
|
|
|
|
fprintf(stderr,"Error: Could not open file `%s' : %s\n",
|
|
|
|
filename3,strerror(e3));
|
|
|
|
if(e3 == EACCES)
|
|
|
|
fprintf(stderr,"Run as root?\n");
|
|
|
|
}
|
|
|
|
exit(1);
|
|
|
|
} else {
|
|
|
|
filename = filename3;
|
2000-07-16 22:54:41 +00:00
|
|
|
}
|
2000-07-02 18:11:31 +00:00
|
|
|
} else {
|
2001-03-31 19:00:45 +00:00
|
|
|
filename = filename2;
|
2000-07-02 18:11:31 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
filename = filename1;
|
1999-01-13 20:23:48 +00:00
|
|
|
}
|
|
|
|
|
2000-08-12 19:16:00 +00:00
|
|
|
/* check adapter functionality */
|
|
|
|
if (ioctl(file,I2C_FUNCS,&funcs) < 0) {
|
|
|
|
fprintf(stderr,
|
|
|
|
"Error: Could not get the adapter functionality matrix: %s\n",
|
|
|
|
strerror(errno));
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
switch(size) {
|
2003-11-26 03:45:18 +00:00
|
|
|
case I2C_SMBUS_BYTE:
|
|
|
|
#ifdef HAVE_PEC
|
|
|
|
if(pec) {
|
|
|
|
if (! (funcs & I2C_FUNC_SMBUS_READ_BYTE_PEC)) {
|
|
|
|
fprintf(stderr, "Error: Adapter for i2c bus %d", i2cbus);
|
|
|
|
fprintf(stderr, " does not have read w/ PEC capability\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
if (! (funcs & I2C_FUNC_SMBUS_READ_BYTE)) {
|
|
|
|
fprintf(stderr, "Error: Adapter for i2c bus %d", i2cbus);
|
|
|
|
fprintf(stderr, " does not have read capability\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2000-08-12 19:16:00 +00:00
|
|
|
case I2C_SMBUS_BYTE_DATA:
|
2002-07-11 02:24:56 +00:00
|
|
|
#ifdef HAVE_PEC
|
|
|
|
if(pec) {
|
|
|
|
if (! (funcs & I2C_FUNC_SMBUS_READ_BYTE_DATA_PEC)) {
|
|
|
|
fprintf(stderr, "Error: Adapter for i2c bus %d", i2cbus);
|
|
|
|
fprintf(stderr, " does not have byte read w/ PEC capability\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
if (! (funcs & I2C_FUNC_SMBUS_READ_BYTE_DATA)) {
|
|
|
|
fprintf(stderr, "Error: Adapter for i2c bus %d", i2cbus);
|
|
|
|
fprintf(stderr, " does not have byte read capability\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
2000-08-12 19:16:00 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case I2C_SMBUS_WORD_DATA:
|
2002-07-11 02:24:56 +00:00
|
|
|
#ifdef HAVE_PEC
|
|
|
|
if(pec) {
|
|
|
|
if (! (funcs & I2C_FUNC_SMBUS_READ_WORD_DATA_PEC)) {
|
|
|
|
fprintf(stderr, "Error: Adapter for i2c bus %d", i2cbus);
|
|
|
|
fprintf(stderr, " does not have word read w/ PEC capability\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
if (! (funcs & I2C_FUNC_SMBUS_READ_WORD_DATA)) {
|
|
|
|
fprintf(stderr, "Error: Adapter for i2c bus %d", i2cbus);
|
|
|
|
fprintf(stderr, " does not have word read capability\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
2000-08-12 19:16:00 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case I2C_SMBUS_BLOCK_DATA:
|
2002-07-11 02:24:56 +00:00
|
|
|
#ifdef HAVE_PEC
|
|
|
|
if(pec) {
|
|
|
|
if (! (funcs & I2C_FUNC_SMBUS_READ_BLOCK_DATA_PEC)) {
|
|
|
|
fprintf(stderr, "Error: Adapter for i2c bus %d", i2cbus);
|
|
|
|
fprintf(stderr, " does not have smbus block read capability\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
if (! (funcs & I2C_FUNC_SMBUS_READ_BLOCK_DATA)) {
|
|
|
|
fprintf(stderr, "Error: Adapter for i2c bus %d", i2cbus);
|
|
|
|
fprintf(stderr, " does not have smbus block read w/ PEC capability\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
2000-08-12 19:16:00 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case I2C_SMBUS_I2C_BLOCK_DATA:
|
|
|
|
if (! (funcs & I2C_FUNC_SMBUS_READ_I2C_BLOCK)) {
|
|
|
|
fprintf(stderr, "Error: Adapter for i2c bus %d", i2cbus);
|
|
|
|
fprintf(stderr, " does not have i2c block read capability\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
2000-01-09 22:45:57 +00:00
|
|
|
/* use FORCE so that we can look at registers even when
|
|
|
|
a driver is also running */
|
|
|
|
if (ioctl(file,I2C_SLAVE_FORCE,address) < 0) {
|
1999-01-13 20:23:48 +00:00
|
|
|
fprintf(stderr,"Error: Could not set address to %d: %s\n",address,
|
|
|
|
strerror(errno));
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2002-07-11 02:24:56 +00:00
|
|
|
if(pec) {
|
|
|
|
#ifdef HAVE_PEC
|
|
|
|
if (ioctl(file,I2C_PEC, 1) < 0) {
|
|
|
|
fprintf(stderr,"Error: Could not set PEC: %s\n", strerror(errno));
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
fprintf(stderr,"Error: PEC not supported in your kernel\n");
|
|
|
|
exit(1);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
1999-01-13 20:47:52 +00:00
|
|
|
fprintf(stderr," WARNING! This program can confuse your I2C bus, "
|
1999-01-13 20:23:48 +00:00
|
|
|
"cause data loss and worse!\n");
|
1999-01-13 21:00:04 +00:00
|
|
|
fprintf(stderr," I will probe file %s, address 0x%x, mode %s\n",
|
2000-08-12 19:16:00 +00:00
|
|
|
filename,address,size == I2C_SMBUS_BLOCK_DATA ? "smbus block" :
|
2001-03-31 01:55:54 +00:00
|
|
|
size == I2C_SMBUS_I2C_BLOCK_DATA ? "i2c block" :
|
2003-11-26 03:45:18 +00:00
|
|
|
size == I2C_SMBUS_BYTE ? "byte consecutive read" :
|
2001-03-31 01:55:54 +00:00
|
|
|
size == I2C_SMBUS_BYTE_DATA ? "byte" : "word");
|
2002-07-11 02:24:56 +00:00
|
|
|
if(pec)
|
2003-03-17 02:28:56 +00:00
|
|
|
fprintf(stderr," with PEC checking.\n");
|
2002-07-11 02:24:56 +00:00
|
|
|
if(bank) {
|
2002-06-12 02:52:16 +00:00
|
|
|
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);
|
2002-07-11 02:24:56 +00:00
|
|
|
}
|
1999-01-13 20:23:48 +00:00
|
|
|
fprintf(stderr," You have five seconds to reconsider and press CTRL-C!\n\n");
|
|
|
|
sleep(5);
|
|
|
|
|
2000-05-12 00:16:08 +00:00
|
|
|
/* See Winbond w83781d data sheet for bank details */
|
2002-06-12 02:52:16 +00:00
|
|
|
if(bank && size != I2C_SMBUS_BLOCK_DATA) {
|
2000-05-12 00:16:08 +00:00
|
|
|
i2c_smbus_write_byte_data(file,bankreg,bank | 0x80);
|
|
|
|
}
|
|
|
|
|
2000-08-12 19:16:00 +00:00
|
|
|
/* handle all but word data */
|
|
|
|
if (size != I2C_SMBUS_WORD_DATA) {
|
|
|
|
|
|
|
|
/* do the block transaction */
|
|
|
|
if(size == I2C_SMBUS_BLOCK_DATA || size == I2C_SMBUS_I2C_BLOCK_DATA) {
|
|
|
|
if(size == I2C_SMBUS_BLOCK_DATA) {
|
2002-06-12 02:52:16 +00:00
|
|
|
res = i2c_smbus_read_block_data(file, bank, cblock);
|
2003-06-16 17:19:10 +00:00
|
|
|
} else {
|
2001-11-19 21:14:43 +00:00
|
|
|
#if USE_I2C_BLOCK
|
2001-12-04 00:30:55 +00:00
|
|
|
res = 0;
|
|
|
|
for (i = 0; i < 256; i+=32) {
|
|
|
|
res2 = i2c_smbus_read_i2c_block_data(file, i, cblock+i);
|
|
|
|
if(res2 <= 0)
|
|
|
|
break;
|
|
|
|
res += res2;
|
|
|
|
}
|
2001-11-19 21:14:43 +00:00
|
|
|
#else
|
2002-02-09 16:34:13 +00:00
|
|
|
fprintf(stderr, "Error: I2C block read unsupported in i2c-core\n");
|
2000-08-12 19:16:00 +00:00
|
|
|
exit(1);
|
2001-11-19 21:14:43 +00:00
|
|
|
#endif
|
2000-08-12 19:16:00 +00:00
|
|
|
}
|
2001-11-19 21:14:43 +00:00
|
|
|
if(res <= 0) {
|
2000-08-12 19:16:00 +00:00
|
|
|
fprintf(stderr, "Error: Block read failed, return code %d\n", res);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
if(res >= 256)
|
|
|
|
res = 256;
|
|
|
|
for (i = 0; i < res; i++)
|
|
|
|
block[i] = cblock[i];
|
|
|
|
for (i = res; i < 256; i++)
|
|
|
|
block[i] = -1;
|
|
|
|
}
|
|
|
|
|
2003-11-26 03:45:18 +00:00
|
|
|
if(size == I2C_SMBUS_BYTE) {
|
|
|
|
res = i2c_smbus_write_byte(file, 0);
|
|
|
|
if(res != 0) {
|
|
|
|
fprintf(stderr, "Error: Write start address failed, return code %d\n", res);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
2002-02-09 16:34:13 +00:00
|
|
|
printf(" 0 1 2 3 4 5 6 7 8 9 a b c d e f 0123456789abcdef\n");
|
1999-01-13 20:23:48 +00:00
|
|
|
for (i = 0; i < 256; i+=16) {
|
|
|
|
printf("%02x: ",i);
|
|
|
|
for(j = 0; j < 16; j++) {
|
2002-02-09 16:34:13 +00:00
|
|
|
if(size == I2C_SMBUS_BYTE_DATA) {
|
2003-11-26 03:45:18 +00:00
|
|
|
block[i+j] = res = i2c_smbus_read_byte_data(file,i+j);
|
|
|
|
} else if(size == I2C_SMBUS_BYTE) {
|
|
|
|
block[i+j] = res = i2c_smbus_read_byte(file);
|
2002-02-09 16:34:13 +00:00
|
|
|
} else
|
2000-08-12 19:16:00 +00:00
|
|
|
res = block[i+j];
|
1999-01-13 20:23:48 +00:00
|
|
|
if (res < 0)
|
|
|
|
printf("XX ");
|
|
|
|
else
|
|
|
|
printf("%02x ",res & 0xff);
|
|
|
|
}
|
2002-02-09 16:34:13 +00:00
|
|
|
printf(" ");
|
|
|
|
for(j = 0; j < 16; j++) {
|
|
|
|
res = block[i+j];
|
|
|
|
if (res < 0)
|
|
|
|
printf("X");
|
|
|
|
else if (((res & 0xff) == 0x00) || ((res & 0xff) == 0xff))
|
|
|
|
printf(".");
|
|
|
|
else if (((res & 0xff) < 32) || ((res & 0xff) >= 127))
|
|
|
|
printf("?");
|
|
|
|
else
|
|
|
|
printf("%c",res & 0xff);
|
|
|
|
}
|
1999-01-13 20:23:48 +00:00
|
|
|
printf("\n");
|
2002-06-12 02:52:16 +00:00
|
|
|
if(size == I2C_SMBUS_BLOCK_DATA && i == 16)
|
|
|
|
break;
|
1999-01-13 20:23:48 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
printf(" 0,8 1,9 2,a 3,b 4,c 5,d 6,e 7,f\n");
|
|
|
|
for (i = 0; i < 256; i+=8) {
|
|
|
|
printf("%02x: ",i);
|
|
|
|
for(j = 0; j < 8; j++) {
|
1999-01-13 20:47:52 +00:00
|
|
|
res = i2c_smbus_read_word_data(file,i+j);
|
1999-01-13 20:23:48 +00:00
|
|
|
if (res < 0)
|
|
|
|
printf("XXXX ");
|
|
|
|
else
|
|
|
|
printf("%04x ",res & 0xffff);
|
|
|
|
}
|
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
}
|
2002-06-12 02:52:16 +00:00
|
|
|
if(bank && size != I2C_SMBUS_BLOCK_DATA) {
|
2000-05-12 00:16:08 +00:00
|
|
|
i2c_smbus_write_byte_data(file,bankreg,0x80);
|
|
|
|
}
|
1999-01-13 20:23:48 +00:00
|
|
|
exit(0);
|
|
|
|
}
|