From owner-p4-projects@FreeBSD.ORG Tue Nov 21 17:17:22 2006 Return-Path: X-Original-To: p4-projects@freebsd.org Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id E2BBC16A8E2; Tue, 21 Nov 2006 17:17:21 +0000 (UTC) X-Original-To: perforce@freebsd.org Delivered-To: perforce@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id C119C16A8CD for ; Tue, 21 Nov 2006 17:17:21 +0000 (UTC) (envelope-from sam@freebsd.org) Received: from repoman.freebsd.org (repoman.freebsd.org [69.147.83.41]) by mx1.FreeBSD.org (Postfix) with ESMTP id 34E01440E1 for ; Tue, 21 Nov 2006 17:08:02 +0000 (GMT) (envelope-from sam@freebsd.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.13.6/8.13.6) with ESMTP id kALH8HLo064527 for ; Tue, 21 Nov 2006 17:08:17 GMT (envelope-from sam@freebsd.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.13.6/8.13.4/Submit) id kALH8Hxl064519 for perforce@freebsd.org; Tue, 21 Nov 2006 17:08:17 GMT (envelope-from sam@freebsd.org) Date: Tue, 21 Nov 2006 17:08:17 GMT Message-Id: <200611211708.kALH8Hxl064519@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to sam@freebsd.org using -f From: Sam Leffler To: Perforce Change Reviews Cc: Subject: PERFORCE change 110188 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 21 Nov 2006 17:17:22 -0000 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[] = {