Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 21 Nov 2006 16:16:22 GMT
From:      Sam Leffler <sam@FreeBSD.org>
To:        Perforce Change Reviews <perforce@freebsd.org>
Subject:   PERFORCE change 110188 for review
Message-ID:  <200611211616.kALGGM8j045079@repoman.freebsd.org>

next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=110188

Change 110188 by sam@sam_ebb on 2006/11/18 06:07:56

	Interlock data updates to avoid scrambling i2c accesses.
	We remove the delay after a channel change as it doesn't
	seem needed and doing so insures we don't sleep (and release
	the mutex) while doing an update.  If we need to bring back
	the delay then we need to handle sleeping; probably by
	moving the update time setting up.

Affected files ...

.. //depot/projects/arm/src/sys/arm/xscale/ixp425/ad7418.c#2 edit

Differences ...

==== //depot/projects/arm/src/sys/arm/xscale/ixp425/ad7418.c#2 (text+ko) ====

@@ -67,6 +67,7 @@
 
 struct ad7418_softc {
 	device_t	sc_dev;
+	struct mtx	sc_mtx;
 	int		sc_curchan;	/* current channel */
 	int		sc_curtemp;
 	int		sc_curvolt;
@@ -116,6 +117,7 @@
 	int conf;
 
 	sc->sc_dev = dev;
+	mtx_init(&sc->sc_mtx, "ad7418", "ad7418", MTX_DEF);
 
 	SYSCTL_ADD_PROC(ctx, SYSCTL_CHILDREN(tree), OID_AUTO,
 		"temp", CTLTYPE_INT | CTLFLAG_RD, sc, 0,
@@ -165,7 +167,18 @@
 	ad7418_write_1(sc->sc_dev, AD7418_CONF, 
 	    (ad7418_read_1(sc->sc_dev, AD7418_CONF) &~ AD7418_CONF_CHAN)|chan);
 	sc->sc_curchan = chan;
-	tsleep(sc, 0, "ad7418", 1);	/* XXX 1 tick should be 'nuf */
+#if 0
+	/*
+	 * NB: Linux driver delays here but chip data sheet
+	 *     says nothing and things appear to work fine w/o
+	 *     a delay on channel change.  If this is enabled
+	 *     be sure to account for losing the mutex below
+	 *     in ad7418_update.
+	 */
+	mtx_assert(&sc->sc_mtx, MA_OWNED);
+	/* let channel change settle, 1 tick should be 'nuf (need ~1ms) */
+	msleep(sc, &sc->sc_mtx, 0, "ad7418", 1);
+#endif
 }
 
 static int
@@ -187,6 +200,7 @@
 {
 	int v;
 
+	mtx_lock(&sc->sc_mtx);
 	/* NB: no point in updating any faster than the chip */
 	if (ticks - sc->sc_lastupdate > hz) {
 		ad7418_set_channel(sc, AD7418_CHAN_TEMP);
@@ -199,6 +213,7 @@
 			sc->sc_curvolt = v;
 		sc->sc_lastupdate = ticks;
 	}
+	mtx_unlock(&sc->sc_mtx);
 }
 
 static device_method_t ad7418_methods[] = {



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200611211616.kALGGM8j045079>