| From 933e887fe2d9a0924a8e05efa6bc3b530b40976d Mon Sep 17 00:00:00 2001 |
| From: Sergey Solomin <sergey.solomin@us.ibm.com> |
| Date: Tue, 6 Sep 2016 15:36:43 -0500 |
| Subject: [PATCH 1/1] 4 byte read support 466 |
| |
| --- |
| tools/i2cdump.c | 34 ++++++++++++++++++++++++++++++++++ |
| 1 file changed, 34 insertions(+) |
| |
| diff --git a/tools/i2cdump.c b/tools/i2cdump.c |
| index a7bba72..99c79be 100644 |
| --- a/tools/i2cdump.c |
| +++ b/tools/i2cdump.c |
| @@ -25,6 +25,7 @@ |
| #include <string.h> |
| #include <stdio.h> |
| #include <stdlib.h> |
| +#include <stdint.h> |
| #include <unistd.h> |
| #include <linux/i2c.h> |
| #include <linux/i2c-dev.h> |
| @@ -33,6 +34,8 @@ |
| #include "util.h" |
| #include "../version.h" |
| |
| +#define I2C_SMBUS_DWORD 7 |
| + |
| static void help(void) |
| { |
| fprintf(stderr, |
| @@ -46,6 +49,7 @@ static void help(void) |
| " s (SMBus block)\n" |
| " i (I2C block)\n" |
| " c (consecutive byte)\n" |
| + " d (double word)\n" |
| " Append p for SMBus PEC\n"); |
| } |
| |
| @@ -184,6 +188,9 @@ int main(int argc, char *argv[]) |
| } else if (!strncmp(argv[flags+3], "c", 1)) { |
| size = I2C_SMBUS_BYTE; |
| pec = argv[flags+3][1] == 'p'; |
| + } else if (!strncmp(argv[flags+3], "d", 1)) { |
| + size = I2C_SMBUS_DWORD; |
| + pec = argv[flags+3][1] == 'p'; |
| } else if (!strcmp(argv[flags+3], "i")) |
| size = I2C_SMBUS_I2C_BLOCK_DATA; |
| else { |
| @@ -285,6 +292,7 @@ int main(int argc, char *argv[]) |
| size == I2C_SMBUS_BLOCK_DATA ? "smbus block" : |
| size == I2C_SMBUS_I2C_BLOCK_DATA ? "i2c block" : |
| size == I2C_SMBUS_BYTE ? "byte consecutive read" : |
| + size == I2C_SMBUS_DWORD ? "double word" : |
| size == I2C_SMBUS_BYTE_DATA ? "byte" : "word"); |
| if (pec) |
| fprintf(stderr, "PEC checking enabled.\n"); |
| @@ -313,6 +321,32 @@ int main(int argc, char *argv[]) |
| } |
| } |
| |
| + /* handle mode 'd' (double word read) */ |
| + if (size == I2C_SMBUS_DWORD) { |
| + unsigned char buff[sizeof(uint32_t)]; |
| + struct i2c_rdwr_ioctl_data msgset; |
| + struct i2c_msg msg[1]; |
| + |
| + msg[0].addr = address; |
| + msg[0].flags = I2C_M_RD; |
| + msg[0].len = sizeof(buff); |
| + msg[0].buf = buff; |
| + |
| + msgset.msgs = msg; |
| + msgset.nmsgs = 1; |
| + |
| + if (ioctl( file, I2C_RDWR, &msgset ) < 0) { |
| + fprintf(stderr, "Error: Could not read " |
| + "double word. %s\n", strerror(errno)); |
| + exit(1); |
| + } |
| + for (uint8_t n = 0; n < sizeof(buff); n++) { |
| + printf ("%02x ", buff[n]); |
| + } |
| + printf ("\n"); |
| + exit(0); |
| + } |
| + |
| /* See Winbond w83781d data sheet for bank details */ |
| if (bank && size != I2C_SMBUS_BLOCK_DATA) { |
| res = i2c_smbus_read_byte_data(file, bankreg); |
| -- |
| 1.8.2.2 |
| |