summaryrefslogtreecommitdiff
path: root/meta-phosphor/recipes-devtools/i2c-tools/i2c-tools/0001-4-byte-read-support-466.patch
blob: 31031119d62b76bfce1fe2366d943aa627504313 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
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