Module Name:    src
Committed By:   msaitoh
Date:           Thu Jul 28 09:11:14 UTC 2016

Modified Files:
        src/share/man/man4: sdtemp.4
        src/sys/dev/i2c: sdtemp.c sdtemp_reg.h

Log Message:
 Add JEDEC TSE2004av support. OK'ed by pgoyette. If a device conforms
TES2004av, it can be used without adding new entry into the matching
table.


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/share/man/man4/sdtemp.4
cvs rdiff -u -r1.30 -r1.31 src/sys/dev/i2c/sdtemp.c
cvs rdiff -u -r1.9 -r1.10 src/sys/dev/i2c/sdtemp_reg.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/share/man/man4/sdtemp.4
diff -u src/share/man/man4/sdtemp.4:1.5 src/share/man/man4/sdtemp.4:1.6
--- src/share/man/man4/sdtemp.4:1.5	Tue Jul 26 07:33:30 2016
+++ src/share/man/man4/sdtemp.4	Thu Jul 28 09:11:14 2016
@@ -1,4 +1,4 @@
-.\"	$NetBSD: sdtemp.4,v 1.5 2016/07/26 07:33:30 msaitoh Exp $
+.\"	$NetBSD: sdtemp.4,v 1.6 2016/07/28 09:11:14 msaitoh Exp $
 .\"
 .\" Copyright (c) 2008 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -27,7 +27,7 @@
 .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 .\" POSSIBILITY OF SUCH DAMAGE.
 .\"
-.Dd July 26, 2016
+.Dd July 28, 2016
 .Dt SDTEMP 4
 .Os
 .Sh NAME
@@ -61,7 +61,7 @@ supports temperature ranges from -256 to
 .Pp
 Chips supported by the
 .Nm
-driver include:
+driver include TSE2004av compliant devices and:
 .Pp
 .Bl -bullet -offset indent
 .It

Index: src/sys/dev/i2c/sdtemp.c
diff -u src/sys/dev/i2c/sdtemp.c:1.30 src/sys/dev/i2c/sdtemp.c:1.31
--- src/sys/dev/i2c/sdtemp.c:1.30	Wed Jul 27 09:11:44 2016
+++ src/sys/dev/i2c/sdtemp.c	Thu Jul 28 09:11:13 2016
@@ -1,4 +1,4 @@
-/*      $NetBSD: sdtemp.c,v 1.30 2016/07/27 09:11:44 msaitoh Exp $        */
+/*      $NetBSD: sdtemp.c,v 1.31 2016/07/28 09:11:13 msaitoh Exp $        */
 
 /*
  * Copyright (c) 2009 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: sdtemp.c,v 1.30 2016/07/27 09:11:44 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sdtemp.c,v 1.31 2016/07/28 09:11:13 msaitoh Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -159,6 +159,12 @@ sdtemp_dev_table[] = {
 	"Integrated Device Technology TS3000GB2" },
     { IDT_MANUFACTURER_ID,  IDT_TS3001GB2_DEVICE_ID, IDT_TS3001GB2_MASK,  CIDT,
 	"Integrated Device Technology TS3001GB2" },
+    /*
+     * Don't change the location of the following two entries. Device specific
+     * entry must be located at above.
+     */
+    { 0,		    TSE2004AV_ID,	     TSE2004AV_MASK,	  NULL,
+	"TSE2004av compliant device (generic driver)" },
     { 0, 0, 0, NULL, "Unknown" }
 };
 
@@ -184,6 +190,10 @@ sdtemp_lookup(uint16_t mfg, uint16_t dev
 		    sdtemp_dev_table[i].sdtemp_devrev)
 			break;
 	}
+	/* Check TSE2004av */
+	if ((sdtemp_dev_table[i].sdtemp_mfg_id == 0)
+	    && (SDTEMP_IS_TSE2004AV(devrev) == 0))
+			i++; /* Unknown */
 
 	return i;
 }
@@ -192,7 +202,7 @@ static int
 sdtemp_match(device_t parent, cfdata_t cf, void *aux)
 {
 	struct i2c_attach_args *ia = aux;
-	uint16_t mfgid, devid;
+	uint16_t mfgid, devid, cap;
 	struct sdtemp_softc sc;
 	int i, error;
 
@@ -202,23 +212,32 @@ sdtemp_match(device_t parent, cfdata_t c
 	if ((ia->ia_addr & SDTEMP_ADDRMASK) != SDTEMP_ADDR)
 		return 0;
 
-	/* Verify that we can read the manufacturer ID  & Device ID */
+	/* Verify that we can read the manufacturer ID, Device ID and the capability */
 	iic_acquire_bus(sc.sc_tag, 0);
 	error = sdtemp_read_16(&sc, SDTEMP_REG_MFG_ID,  &mfgid) |
-		sdtemp_read_16(&sc, SDTEMP_REG_DEV_REV, &devid);
+		sdtemp_read_16(&sc, SDTEMP_REG_DEV_REV, &devid) |
+		sdtemp_read_16(&sc, SDTEMP_REG_CAPABILITY, &cap);
 	iic_release_bus(sc.sc_tag, 0);
 
 	if (error)
 		return 0;
 
 	i = sdtemp_lookup(mfgid, devid);
-	if (sdtemp_dev_table[i].sdtemp_mfg_id == 0) {
+	if ((sdtemp_dev_table[i].sdtemp_mfg_id == 0) &&
+	    (sdtemp_dev_table[i].sdtemp_devrev == 0)) {
 		aprint_debug("sdtemp: No match for mfg 0x%04x dev 0x%02x "
 		    "rev 0x%02x at address 0x%02x\n", mfgid, devid >> 8,
 		    devid & 0xff, sc.sc_address);
 		return 0;
 	}
 
+	/*
+	 * Check by SDTEMP_IS_TSE2004AV() might not be enough, so check the alarm
+	 * capability, too.
+	 */
+	if ((cap & SDTEMP_CAP_HAS_ALARM) == 0)
+		return 0;
+
 	return 1;
 }
 
@@ -249,10 +268,21 @@ sdtemp_attach(device_t parent, device_t 
 	aprint_naive(": Temp Sensor\n");
 	aprint_normal(": %s Temp Sensor\n", sdtemp_dev_table[i].sdtemp_desc);
 
-	if (sdtemp_dev_table[i].sdtemp_mfg_id == 0)
-		aprint_debug_dev(self,
-		    "mfg 0x%04x dev 0x%02x rev 0x%02x at addr 0x%02x\n",
-		    mfgid, devid >> 8, devid & 0xff, ia->ia_addr);
+	if (sdtemp_dev_table[i].sdtemp_mfg_id == 0) {
+		if (SDTEMP_IS_TSE2004AV(devid))
+			aprint_normal_dev(self, "TSE2004av compliant. "
+			    "Manufacturer ID 0x%04hx, Device revision 0x%02x\n",
+			    mfgid, devid & TSE2004AV_REV);
+		else {
+			aprint_error_dev(self,
+			    "mfg 0x%04x dev 0x%02x rev 0x%02x at addr 0x%02x\n",
+			    mfgid, devid >> 8, devid & 0xff, ia->ia_addr);
+			iic_release_bus(sc->sc_tag, 0);
+			aprint_error_dev(self, "It should no happen. "
+			    "Why attach() found me?\n");
+			return;
+		}
+	}
 
 	error = sdtemp_read_16(sc, SDTEMP_REG_CAPABILITY, &sc->sc_capability);
 	aprint_debug_dev(self, "capability reg = %04x\n", sc->sc_capability);

Index: src/sys/dev/i2c/sdtemp_reg.h
diff -u src/sys/dev/i2c/sdtemp_reg.h:1.9 src/sys/dev/i2c/sdtemp_reg.h:1.10
--- src/sys/dev/i2c/sdtemp_reg.h:1.9	Tue Jul 26 07:30:16 2016
+++ src/sys/dev/i2c/sdtemp_reg.h	Thu Jul 28 09:11:13 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: sdtemp_reg.h,v 1.9 2016/07/26 07:30:16 msaitoh Exp $	*/
+/*	$NetBSD: sdtemp_reg.h,v 1.10 2016/07/28 09:11:13 msaitoh Exp $	*/
 
 /*
  * Copyright (c) 2009 The NetBSD Foundation, Inc.
@@ -95,6 +95,12 @@
  * Devices known to conform to JEDEC JC42.4
  */
 
+/* TSE2004av definitions (JEDEC Standard No. 21-C Page 4.1.6) */
+#define TSE2004AV_ID			0x2200
+#define TSE2004AV_MASK			0xff00	/* ID is upper 8bits */
+#define TSE2004AV_REV			0x00ff	/* Revision is lower 8bits */
+#define SDTEMP_IS_TSE2004AV(dev)	(((dev) & TSE2004AV_MASK) == TSE2004AV_ID)
+
 /* Atmel */
 #define	AT_MANUFACTURER_ID		0x001f
 #define	AT_30TS00_DEVICE_ID		0x8201 /* Also matches 002A and 002B */

Reply via email to