i2c-tools - Mode 'd' for i2cdump - 4 byte read support.

Current 'i2c-tools' utilities appear to be insufficient
for one particular chip the Witherspoon lab team would
like to interact with. The chip in question requires a
4 consecutive byte read without initial write of the
regiser offset. Adding an enhancement to the existing
utilities seems to be a better option than creating a
brand new tool.

Resolves openbmc/openbmc#466.

Change-Id: Ifb7f68fb8f1112eaf494634b37dafb60d200fefd
Signed-off-by: Sergey Solomin <sergey.solomin@us.ibm.com>
diff --git a/common/recipes-devtools/i2c-tools/i2c-tools/0001-4-byte-read-support-466.patch b/common/recipes-devtools/i2c-tools/i2c-tools/0001-4-byte-read-support-466.patch
new file mode 100644
index 0000000..3103111
--- /dev/null
+++ b/common/recipes-devtools/i2c-tools/i2c-tools/0001-4-byte-read-support-466.patch
@@ -0,0 +1,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
+
diff --git a/common/recipes-devtools/i2c-tools/i2c-tools_%.bbappend b/common/recipes-devtools/i2c-tools/i2c-tools_%.bbappend
index 599394d..c26f3f0 100644
--- a/common/recipes-devtools/i2c-tools/i2c-tools_%.bbappend
+++ b/common/recipes-devtools/i2c-tools/i2c-tools_%.bbappend
@@ -1,5 +1,7 @@
 # Prefer the Yocto mirror over the direct lm-sensors download.
+FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"
 SRC_URI_remove = "http://dl.lm-sensors.org/i2c-tools/releases/${BP}.tar.bz2"
-SRC_URI =+ "http://downloads.yoctoproject.org/mirror/sources/${BP}.tar.bz2"
+SRC_URI =+ "http://downloads.yoctoproject.org/mirror/sources/${BP}.tar.bz2 \
+            file://0001-4-byte-read-support-466.patch"
 
 RDEPENDS_${PN}_remove = "${PN}-misc"