Re: [PATCH] support i2c 10-bit addressing

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



<sigh> gmail appears to have futzed w/ the attachment type.

2015-03-28 6:12 GMT-07:00 Peter Chang <dpf@xxxxxxxxxx>:
> the address parsing doesn't have the adapter's support bits yet, so it
> looks a little out of place.
>
> \p
Index: tools/i2cbusses.c
===================================================================
--- tools/i2cbusses.c	(revision 6278)
+++ tools/i2cbusses.c	(working copy)
@@ -364,9 +364,10 @@
 		fprintf(stderr, "Error: Chip address is not a number!\n");
 		return -1;
 	}
-	if (address < 0x03 || address > 0x77) {
+
+	if (address < 0x03 || address > 0x3ff) {
 		fprintf(stderr, "Error: Chip address out of range "
-			"(0x03-0x77)!\n");
+			"(0x03-0x3ff)!\n");
 		return -2;
 	}
 
@@ -402,8 +403,17 @@
 	return file;
 }
 
-int set_slave_addr(int file, int address, int force)
+int set_slave_addr(int file, int address, int force, unsigned long funcs)
 {
+	if (address > 0x77
+	 && (funcs & I2C_FUNC_10BIT_ADDR)
+	 && ioctl(file, I2C_TENBIT, 1) < 0) {
+		fprintf(stderr,
+			"Error: Could not set 10bit for 0x%02x: %s\n",
+			address, strerror(errno));
+		return -errno;
+	}
+
 	/* With force, let the user read from/write to the registers
 	   even when a driver is also running */
 	if (ioctl(file, force ? I2C_SLAVE_FORCE : I2C_SLAVE, address) < 0) {
Index: tools/i2cbusses.h
===================================================================
--- tools/i2cbusses.h	(revision 6278)
+++ tools/i2cbusses.h	(working copy)
@@ -37,7 +37,7 @@
 int lookup_i2c_bus(const char *i2cbus_arg);
 int parse_i2c_address(const char *address_arg);
 int open_i2c_dev(int i2cbus, char *filename, size_t size, int quiet);
-int set_slave_addr(int file, int address, int force);
+int set_slave_addr(int file, int address, int force, unsigned long funcs);
 
 #define MISSING_FUNC_FMT	"Error: Adapter does not have %s capability\n"
 
Index: tools/i2cdump.c
===================================================================
--- tools/i2cdump.c	(revision 6278)
+++ tools/i2cdump.c	(working copy)
@@ -49,12 +49,10 @@
 		"    Append p for SMBus PEC\n");
 }
 
-static int check_funcs(int file, int size, int pec)
+static int check_funcs(int file, int size, int pec, unsigned long *funcs)
 {
-	unsigned long funcs;
-
 	/* check adapter functionality */
-	if (ioctl(file, I2C_FUNCS, &funcs) < 0) {
+	if (ioctl(file, I2C_FUNCS, funcs) < 0) {
 		fprintf(stderr, "Error: Could not get the adapter "
 			"functionality matrix: %s\n", strerror(errno));
 		return -1;
@@ -62,11 +60,11 @@
 
 	switch(size) {
 	case I2C_SMBUS_BYTE:
-		if (!(funcs & I2C_FUNC_SMBUS_READ_BYTE)) {
+		if (!(*funcs & I2C_FUNC_SMBUS_READ_BYTE)) {
 			fprintf(stderr, MISSING_FUNC_FMT, "SMBus receive byte");
 			return -1;
 		}
-		if (!(funcs & I2C_FUNC_SMBUS_WRITE_BYTE)) {
+		if (!(*funcs & I2C_FUNC_SMBUS_WRITE_BYTE)) {
 			fprintf(stderr, MISSING_FUNC_FMT, "SMBus send byte");
 			return -1;
 		}
@@ -73,7 +71,7 @@
 		break;
 
 	case I2C_SMBUS_BYTE_DATA:
-		if (!(funcs & I2C_FUNC_SMBUS_READ_BYTE_DATA)) {
+		if (!(*funcs & I2C_FUNC_SMBUS_READ_BYTE_DATA)) {
 			fprintf(stderr, MISSING_FUNC_FMT, "SMBus read byte");
 			return -1;
 		}
@@ -80,7 +78,7 @@
 		break;
 
 	case I2C_SMBUS_WORD_DATA:
-		if (!(funcs & I2C_FUNC_SMBUS_READ_WORD_DATA)) {
+		if (!(*funcs & I2C_FUNC_SMBUS_READ_WORD_DATA)) {
 			fprintf(stderr, MISSING_FUNC_FMT, "SMBus read word");
 			return -1;
 		}
@@ -87,7 +85,7 @@
 		break;
 
 	case I2C_SMBUS_BLOCK_DATA:
-		if (!(funcs & I2C_FUNC_SMBUS_READ_BLOCK_DATA)) {
+		if (!(*funcs & I2C_FUNC_SMBUS_READ_BLOCK_DATA)) {
 			fprintf(stderr, MISSING_FUNC_FMT, "SMBus block read");
 			return -1;
 		}
@@ -94,7 +92,7 @@
 		break;
 
 	case I2C_SMBUS_I2C_BLOCK_DATA:
-		if (!(funcs & I2C_FUNC_SMBUS_READ_I2C_BLOCK)) {
+		if (!(*funcs & I2C_FUNC_SMBUS_READ_I2C_BLOCK)) {
 			fprintf(stderr, MISSING_FUNC_FMT, "I2C block read");
 			return -1;
 		}
@@ -102,7 +100,7 @@
 	}
 
 	if (pec
-	 && !(funcs & (I2C_FUNC_SMBUS_PEC | I2C_FUNC_I2C))) {
+	 && !(*funcs & (I2C_FUNC_SMBUS_PEC | I2C_FUNC_I2C))) {
 		fprintf(stderr, "Warning: Adapter does "
 			"not seem to support PEC\n");
 	}
@@ -122,6 +120,7 @@
 	int force = 0, yes = 0, version = 0;
 	const char *range = NULL;
 	int first = 0x00, last = 0xff;
+	unsigned long funcs;
 
 	/* handle (optional) flags first */
 	while (1+flags < argc && argv[1+flags][0] == '-') {
@@ -264,8 +263,8 @@
 
 	file = open_i2c_dev(i2cbus, filename, sizeof(filename), 0);
 	if (file < 0
-	 || check_funcs(file, size, pec)
-	 || set_slave_addr(file, address, force))
+	 || check_funcs(file, size, pec, &funcs)
+	 || set_slave_addr(file, address, force, funcs))
 		exit(1);
 
 	if (pec) {
Index: tools/i2cget.c
===================================================================
--- tools/i2cget.c	(revision 6278)
+++ tools/i2cget.c	(working copy)
@@ -52,12 +52,11 @@
 	exit(1);
 }
 
-static int check_funcs(int file, int size, int daddress, int pec)
+static int check_funcs(int file, int size, int daddress, int pec,
+		       unsigned long *funcs)
 {
-	unsigned long funcs;
-
 	/* check adapter functionality */
-	if (ioctl(file, I2C_FUNCS, &funcs) < 0) {
+	if (ioctl(file, I2C_FUNCS, funcs) < 0) {
 		fprintf(stderr, "Error: Could not get the adapter "
 			"functionality matrix: %s\n", strerror(errno));
 		return -1;
@@ -65,12 +64,12 @@
 
 	switch (size) {
 	case I2C_SMBUS_BYTE:
-		if (!(funcs & I2C_FUNC_SMBUS_READ_BYTE)) {
+		if (!(*funcs & I2C_FUNC_SMBUS_READ_BYTE)) {
 			fprintf(stderr, MISSING_FUNC_FMT, "SMBus receive byte");
 			return -1;
 		}
 		if (daddress >= 0
-		 && !(funcs & I2C_FUNC_SMBUS_WRITE_BYTE)) {
+		 && !(*funcs & I2C_FUNC_SMBUS_WRITE_BYTE)) {
 			fprintf(stderr, MISSING_FUNC_FMT, "SMBus send byte");
 			return -1;
 		}
@@ -77,7 +76,7 @@
 		break;
 
 	case I2C_SMBUS_BYTE_DATA:
-		if (!(funcs & I2C_FUNC_SMBUS_READ_BYTE_DATA)) {
+		if (!(*funcs & I2C_FUNC_SMBUS_READ_BYTE_DATA)) {
 			fprintf(stderr, MISSING_FUNC_FMT, "SMBus read byte");
 			return -1;
 		}
@@ -84,7 +83,7 @@
 		break;
 
 	case I2C_SMBUS_WORD_DATA:
-		if (!(funcs & I2C_FUNC_SMBUS_READ_WORD_DATA)) {
+		if (!(*funcs & I2C_FUNC_SMBUS_READ_WORD_DATA)) {
 			fprintf(stderr, MISSING_FUNC_FMT, "SMBus read word");
 			return -1;
 		}
@@ -92,7 +91,7 @@
 	}
 
 	if (pec
-	 && !(funcs & (I2C_FUNC_SMBUS_PEC | I2C_FUNC_I2C))) {
+	 && !(*funcs & (I2C_FUNC_SMBUS_PEC | I2C_FUNC_I2C))) {
 		fprintf(stderr, "Warning: Adapter does "
 			"not seem to support PEC\n");
 	}
@@ -159,6 +158,7 @@
 	int pec = 0;
 	int flags = 0;
 	int force = 0, yes = 0, version = 0;
+	unsigned long funcs;
 
 	/* handle (optional) flags first */
 	while (1+flags < argc && argv[1+flags][0] == '-') {
@@ -217,8 +217,8 @@
 
 	file = open_i2c_dev(i2cbus, filename, sizeof(filename), 0);
 	if (file < 0
-	 || check_funcs(file, size, daddress, pec)
-	 || set_slave_addr(file, address, force))
+	 || check_funcs(file, size, daddress, pec, &funcs)
+	 || set_slave_addr(file, address, force, funcs))
 		exit(1);
 
 	if (!yes && !confirm(filename, address, size, daddress, pec))
Index: tools/i2cset.c
===================================================================
--- tools/i2cset.c	(revision 6278)
+++ tools/i2cset.c	(working copy)
@@ -51,12 +51,10 @@
 	exit(1);
 }
 
-static int check_funcs(int file, int size, int pec)
+static int check_funcs(int file, int size, int pec, unsigned long *funcs)
 {
-	unsigned long funcs;
-
 	/* check adapter functionality */
-	if (ioctl(file, I2C_FUNCS, &funcs) < 0) {
+	if (ioctl(file, I2C_FUNCS, funcs) < 0) {
 		fprintf(stderr, "Error: Could not get the adapter "
 			"functionality matrix: %s\n", strerror(errno));
 		return -1;
@@ -64,7 +62,7 @@
 
 	switch (size) {
 	case I2C_SMBUS_BYTE:
-		if (!(funcs & I2C_FUNC_SMBUS_WRITE_BYTE)) {
+		if (!(*funcs & I2C_FUNC_SMBUS_WRITE_BYTE)) {
 			fprintf(stderr, MISSING_FUNC_FMT, "SMBus send byte");
 			return -1;
 		}
@@ -71,7 +69,7 @@
 		break;
 
 	case I2C_SMBUS_BYTE_DATA:
-		if (!(funcs & I2C_FUNC_SMBUS_WRITE_BYTE_DATA)) {
+		if (!(*funcs & I2C_FUNC_SMBUS_WRITE_BYTE_DATA)) {
 			fprintf(stderr, MISSING_FUNC_FMT, "SMBus write byte");
 			return -1;
 		}
@@ -78,7 +76,7 @@
 		break;
 
 	case I2C_SMBUS_WORD_DATA:
-		if (!(funcs & I2C_FUNC_SMBUS_WRITE_WORD_DATA)) {
+		if (!(*funcs & I2C_FUNC_SMBUS_WRITE_WORD_DATA)) {
 			fprintf(stderr, MISSING_FUNC_FMT, "SMBus write word");
 			return -1;
 		}
@@ -85,13 +83,13 @@
 		break;
 
 	case I2C_SMBUS_BLOCK_DATA:
-		if (!(funcs & I2C_FUNC_SMBUS_WRITE_BLOCK_DATA)) {
+		if (!(*funcs & I2C_FUNC_SMBUS_WRITE_BLOCK_DATA)) {
 			fprintf(stderr, MISSING_FUNC_FMT, "SMBus block write");
 			return -1;
 		}
 		break;
 	case I2C_SMBUS_I2C_BLOCK_DATA:
-		if (!(funcs & I2C_FUNC_SMBUS_WRITE_I2C_BLOCK)) {
+		if (!(*funcs & I2C_FUNC_SMBUS_WRITE_I2C_BLOCK)) {
 			fprintf(stderr, MISSING_FUNC_FMT, "I2C block write");
 			return -1;
 		}
@@ -99,7 +97,7 @@
 	}
 
 	if (pec
-	 && !(funcs & (I2C_FUNC_SMBUS_PEC | I2C_FUNC_I2C))) {
+	 && !(*funcs & (I2C_FUNC_SMBUS_PEC | I2C_FUNC_I2C))) {
 		fprintf(stderr, "Warning: Adapter does "
 			"not seem to support PEC\n");
 	}
@@ -166,6 +164,7 @@
 	int force = 0, yes = 0, version = 0, readback = 0;
 	unsigned char block[I2C_SMBUS_BLOCK_MAX];
 	int len;
+	unsigned long funcs;
 
 	/* handle (optional) flags first */
 	while (1+flags < argc && argv[1+flags][0] == '-') {
@@ -312,8 +311,8 @@
 
 	file = open_i2c_dev(i2cbus, filename, sizeof(filename), 0);
 	if (file < 0
-	 || check_funcs(file, size, pec)
-	 || set_slave_addr(file, address, force))
+	 || check_funcs(file, size, pec, &funcs)
+	 || set_slave_addr(file, address, force, funcs))
 		exit(1);
 
 	if (!yes && !confirm(filename, address, size, daddress,
_______________________________________________
lm-sensors mailing list
lm-sensors@xxxxxxxxxxxxxx
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors

[Index of Archives]     [Linux Kernel]     [Linux Hardware Monitoring]     [Linux USB Devel]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Yosemite Backpacking]

  Powered by Linux