blob: 31031119d62b76bfce1fe2366d943aa627504313 [file] [log] [blame]
Sergey Solomin8dd39aa2016-08-17 18:02:10 -05001From 933e887fe2d9a0924a8e05efa6bc3b530b40976d Mon Sep 17 00:00:00 2001
2From: Sergey Solomin <sergey.solomin@us.ibm.com>
3Date: Tue, 6 Sep 2016 15:36:43 -0500
4Subject: [PATCH 1/1] 4 byte read support 466
5
6---
7 tools/i2cdump.c | 34 ++++++++++++++++++++++++++++++++++
8 1 file changed, 34 insertions(+)
9
10diff --git a/tools/i2cdump.c b/tools/i2cdump.c
11index a7bba72..99c79be 100644
12--- a/tools/i2cdump.c
13+++ b/tools/i2cdump.c
14@@ -25,6 +25,7 @@
15 #include <string.h>
16 #include <stdio.h>
17 #include <stdlib.h>
18+#include <stdint.h>
19 #include <unistd.h>
20 #include <linux/i2c.h>
21 #include <linux/i2c-dev.h>
22@@ -33,6 +34,8 @@
23 #include "util.h"
24 #include "../version.h"
25
26+#define I2C_SMBUS_DWORD 7
27+
28 static void help(void)
29 {
30 fprintf(stderr,
31@@ -46,6 +49,7 @@ static void help(void)
32 " s (SMBus block)\n"
33 " i (I2C block)\n"
34 " c (consecutive byte)\n"
35+ " d (double word)\n"
36 " Append p for SMBus PEC\n");
37 }
38
39@@ -184,6 +188,9 @@ int main(int argc, char *argv[])
40 } else if (!strncmp(argv[flags+3], "c", 1)) {
41 size = I2C_SMBUS_BYTE;
42 pec = argv[flags+3][1] == 'p';
43+ } else if (!strncmp(argv[flags+3], "d", 1)) {
44+ size = I2C_SMBUS_DWORD;
45+ pec = argv[flags+3][1] == 'p';
46 } else if (!strcmp(argv[flags+3], "i"))
47 size = I2C_SMBUS_I2C_BLOCK_DATA;
48 else {
49@@ -285,6 +292,7 @@ int main(int argc, char *argv[])
50 size == I2C_SMBUS_BLOCK_DATA ? "smbus block" :
51 size == I2C_SMBUS_I2C_BLOCK_DATA ? "i2c block" :
52 size == I2C_SMBUS_BYTE ? "byte consecutive read" :
53+ size == I2C_SMBUS_DWORD ? "double word" :
54 size == I2C_SMBUS_BYTE_DATA ? "byte" : "word");
55 if (pec)
56 fprintf(stderr, "PEC checking enabled.\n");
57@@ -313,6 +321,32 @@ int main(int argc, char *argv[])
58 }
59 }
60
61+ /* handle mode 'd' (double word read) */
62+ if (size == I2C_SMBUS_DWORD) {
63+ unsigned char buff[sizeof(uint32_t)];
64+ struct i2c_rdwr_ioctl_data msgset;
65+ struct i2c_msg msg[1];
66+
67+ msg[0].addr = address;
68+ msg[0].flags = I2C_M_RD;
69+ msg[0].len = sizeof(buff);
70+ msg[0].buf = buff;
71+
72+ msgset.msgs = msg;
73+ msgset.nmsgs = 1;
74+
75+ if (ioctl( file, I2C_RDWR, &msgset ) < 0) {
76+ fprintf(stderr, "Error: Could not read "
77+ "double word. %s\n", strerror(errno));
78+ exit(1);
79+ }
80+ for (uint8_t n = 0; n < sizeof(buff); n++) {
81+ printf ("%02x ", buff[n]);
82+ }
83+ printf ("\n");
84+ exit(0);
85+ }
86+
87 /* See Winbond w83781d data sheet for bank details */
88 if (bank && size != I2C_SMBUS_BLOCK_DATA) {
89 res = i2c_smbus_read_byte_data(file, bankreg);
90--
911.8.2.2
92