Module Name:    src
Committed By:   martin
Date:           Sun Feb 28 11:36:27 UTC 2010

Modified Files:
        src/sys/dev/i2c: adm1021.c lm75.c spdmem.c

Log Message:
Add direct config support for a few devices


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/sys/dev/i2c/adm1021.c
cvs rdiff -u -r1.20 -r1.21 src/sys/dev/i2c/lm75.c
cvs rdiff -u -r1.16 -r1.17 src/sys/dev/i2c/spdmem.c

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

Modified files:

Index: src/sys/dev/i2c/adm1021.c
diff -u src/sys/dev/i2c/adm1021.c:1.3 src/sys/dev/i2c/adm1021.c:1.4
--- src/sys/dev/i2c/adm1021.c:1.3	Fri Jun  5 12:42:43 2009
+++ src/sys/dev/i2c/adm1021.c	Sun Feb 28 11:36:27 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: adm1021.c,v 1.3 2009/06/05 12:42:43 hubertf Exp $ */
+/*	$NetBSD: adm1021.c,v 1.4 2010/02/28 11:36:27 martin Exp $ */
 /*	$OpenBSD: adm1021.c,v 1.27 2007/06/24 05:34:35 dlg Exp $	*/
 
 /*
@@ -18,7 +18,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: adm1021.c,v 1.3 2009/06/05 12:42:43 hubertf Exp $");
+__KERNEL_RCSID(0, "$NetBSD: adm1021.c,v 1.4 2010/02/28 11:36:27 martin Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -62,18 +62,35 @@
 CFATTACH_DECL_NEW(admtemp, sizeof(struct admtemp_softc),
 	admtemp_match, admtemp_attach, NULL, NULL);
 
+static const char * admtemp_compats[] = {
+	"i2c-max1617",
+	NULL
+};
 
 int
 admtemp_match(device_t parent, cfdata_t match, void *aux)
 {
 	struct i2c_attach_args *ia = aux;
 
-	if (((ia->ia_addr >= 0x18) && (ia->ia_addr <= 0x1a)) ||
-	    ((ia->ia_addr >= 0x29) && (ia->ia_addr <= 0x2b)) ||
-	    ((ia->ia_addr >= 0x4c) && (ia->ia_addr <= 0x4e)))
-		return (1);
+	if (ia->ia_name == NULL) {
+		/*
+		 * Indirect config - not much we can do!
+		 * Check typical addresses.
+		 */
+		if (((ia->ia_addr >= 0x18) && (ia->ia_addr <= 0x1a)) ||
+		    ((ia->ia_addr >= 0x29) && (ia->ia_addr <= 0x2b)) ||
+		    ((ia->ia_addr >= 0x4c) && (ia->ia_addr <= 0x4e)))
+			return (1);
+	} else {
+		/*
+		 * Direct config - match via the list of compatible
+		 * hardware.
+		 */
+		if (iic_compat_match(ia, admtemp_compats))
+			return 1;
+	}
 
-	return (0);
+	return 0;
 }
 
 

Index: src/sys/dev/i2c/lm75.c
diff -u src/sys/dev/i2c/lm75.c:1.20 src/sys/dev/i2c/lm75.c:1.21
--- src/sys/dev/i2c/lm75.c:1.20	Fri Jan  9 17:20:31 2009
+++ src/sys/dev/i2c/lm75.c	Sun Feb 28 11:36:27 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: lm75.c,v 1.20 2009/01/09 17:20:31 briggs Exp $	*/
+/*	$NetBSD: lm75.c,v 1.21 2010/02/28 11:36:27 martin Exp $	*/
 
 /*
  * Copyright (c) 2003 Wasabi Systems, Inc.
@@ -36,7 +36,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: lm75.c,v 1.20 2009/01/09 17:20:31 briggs Exp $");
+__KERNEL_RCSID(0, "$NetBSD: lm75.c,v 1.21 2010/02/28 11:36:27 martin Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -71,6 +71,16 @@
 static uint32_t lmtemp_decode_ds75(const uint8_t *);
 static uint32_t lmtemp_decode_lm77(const uint8_t *);
 
+
+static const char * lmtemp_compats[] = {
+	"i2c-lm75",
+	/*
+	 * see XXX in _attach() below: add code once non-lm75 matches are
+	 * added here!
+	 */
+	NULL
+};
+
 enum {
 	lmtemp_lm75 = 0,
 	lmtemp_ds75,
@@ -100,15 +110,28 @@
 	struct i2c_attach_args *ia = aux;
 	int i;
 
-	for (i = 0; lmtemptbl[i].lmtemp_type != -1 ; i++)
-		if (lmtemptbl[i].lmtemp_type == cf->cf_flags)
-			break;
-	if (lmtemptbl[i].lmtemp_type == -1)
-		return 0;
-
-	if ((ia->ia_addr & lmtemptbl[i].lmtemp_addrmask) ==
-	    lmtemptbl[i].lmtemp_addr)
-		return 1;
+	if (ia->ia_name == NULL) {
+		/*
+		 * Indirect config - not much we can do!
+		 */
+		for (i = 0; lmtemptbl[i].lmtemp_type != -1 ; i++)
+			if (lmtemptbl[i].lmtemp_type == cf->cf_flags)
+				break;
+		if (lmtemptbl[i].lmtemp_type == -1)
+			return 0;
+
+		if ((ia->ia_addr & lmtemptbl[i].lmtemp_addrmask) ==
+		    lmtemptbl[i].lmtemp_addr)
+			return 1;
+	} else {
+		/*
+		 * Direct config - match via the list of compatible
+		 * hardware.
+		 */
+		if (iic_compat_match(ia, lmtemp_compats))
+			return 1;
+	}
+
 
 	return 0;
 }
@@ -120,16 +143,27 @@
 	struct i2c_attach_args *ia = aux;
 	int i;
 
-	for (i = 0; lmtemptbl[i].lmtemp_type != -1 ; i++)
-		if (lmtemptbl[i].lmtemp_type ==
-		    device_cfdata(self)->cf_flags)
-			break;
+	if (ia->ia_name == NULL) {
+		for (i = 0; lmtemptbl[i].lmtemp_type != -1 ; i++)
+			if (lmtemptbl[i].lmtemp_type ==
+			    device_cfdata(self)->cf_flags)
+				break;
+	} else {
+		/* XXX - add code when adding other direct matches! */
+		i = 0;
+	}
 
 	sc->sc_tag = ia->ia_tag;
 	sc->sc_address = ia->ia_addr;
 
 	aprint_naive(": Temperature Sensor\n");
-	aprint_normal(": %s Temperature Sensor\n", lmtemptbl[i].lmtemp_name);
+	if (ia->ia_name) {
+		aprint_normal(": %s %s Temperature Sensor\n", ia->ia_name,
+			lmtemptbl[i].lmtemp_name);
+	} else {
+		aprint_normal(": %s Temperature Sensor\n",
+			lmtemptbl[i].lmtemp_name);
+	}
 
 	/* Set the configuration of the LM75 to defaults. */
 	iic_acquire_bus(sc->sc_tag, I2C_F_POLL);
@@ -143,7 +177,8 @@
 	sc->sc_sme = sysmon_envsys_create();
 	/* Initialize sensor data. */
 	sc->sc_sensor.units =  ENVSYS_STEMP;
-	(void)strlcpy(sc->sc_sensor.desc, device_xname(self),
+	(void)strlcpy(sc->sc_sensor.desc,
+	    ia->ia_name? ia->ia_name : device_xname(self),
 	    sizeof(sc->sc_sensor.desc));
 	if (sysmon_envsys_sensor_attach(sc->sc_sme, &sc->sc_sensor)) {
 		sysmon_envsys_destroy(sc->sc_sme);

Index: src/sys/dev/i2c/spdmem.c
diff -u src/sys/dev/i2c/spdmem.c:1.16 src/sys/dev/i2c/spdmem.c:1.17
--- src/sys/dev/i2c/spdmem.c:1.16	Tue Feb 23 00:13:06 2010
+++ src/sys/dev/i2c/spdmem.c	Sun Feb 28 11:36:27 2010
@@ -1,4 +1,4 @@
-/* $NetBSD: spdmem.c,v 1.16 2010/02/23 00:13:06 pgoyette Exp $ */
+/* $NetBSD: spdmem.c,v 1.17 2010/02/28 11:36:27 martin Exp $ */
 
 /*
  * Copyright (c) 2007 Nicolas Joly
@@ -35,7 +35,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: spdmem.c,v 1.16 2010/02/23 00:13:06 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: spdmem.c,v 1.17 2010/02/28 11:36:27 martin Exp $");
 
 #include <sys/param.h>
 #include <sys/device.h>
@@ -155,6 +155,7 @@
 	}
 	return (crc & 0xFFFF);
 }
+
 static int
 spdmem_match(device_t parent, cfdata_t match, void *aux)
 {
@@ -165,8 +166,17 @@
 	int spd_len, spd_crc_cover;
 	uint16_t crc_calc, crc_spd;
 
-	if ((ia->ia_addr & SPDMEM_ADDRMASK) != SPDMEM_ADDR)
-		return 0;
+	if (ia->ia_name) {
+		/* add other names as we find more firmware variations */
+		if (strcmp(ia->ia_name, "dimm-spd"))
+			return 0;
+	}
+
+	/* only do this lame test when not using direct config */
+	if (ia->ia_name == NULL) {
+		if ((ia->ia_addr & SPDMEM_ADDRMASK) != SPDMEM_ADDR)
+			return 0;
+	}
 
 	sc.sc_tag = ia->ia_tag;
 	sc.sc_addr = ia->ia_addr;

Reply via email to