Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 19 Aug 2012 19:31:37 +0000 (UTC)
From:      Andreas Tobler <andreast@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r239397 - head/sys/dev/iicbus
Message-ID:  <201208191931.q7JJVbAe026035@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: andreast
Date: Sun Aug 19 19:31:36 2012
New Revision: 239397
URL: http://svn.freebsd.org/changeset/base/239397

Log:
  Do the ADC init only at startup and not during every sensor read call.
  This reduces the number of interrupts.

Modified:
  head/sys/dev/iicbus/ad7417.c

Modified: head/sys/dev/iicbus/ad7417.c
==============================================================================
--- head/sys/dev/iicbus/ad7417.c	Sun Aug 19 19:17:54 2012	(r239396)
+++ head/sys/dev/iicbus/ad7417.c	Sun Aug 19 19:31:36 2012	(r239397)
@@ -104,6 +104,7 @@ struct ad7417_softc {
 	uint32_t                sc_addr;
 	struct ad7417_sensor    *sc_sensors;
 	int                     sc_nsensors;
+	int                     init_done;
 };
 static device_method_t  ad7417_methods[] = {
 	/* Device interface */
@@ -247,6 +248,9 @@ ad7417_init_adc(device_t dev, uint32_t a
 {
 	uint8_t buf;
 	int err;
+	struct ad7417_softc *sc;
+
+	sc = device_get_softc(dev);
 
 	adc741x_config = 0;
 	/* Clear Config2 */
@@ -267,6 +271,8 @@ ad7417_init_adc(device_t dev, uint32_t a
 	if (err < 0)
 		return (-1);
 
+	sc->init_done = 1;
+
 	return (0);
 
 }
@@ -430,10 +436,10 @@ ad7417_attach(device_t dev)
 
 		if (sc->sc_sensors[i].type == ADC7417_TEMP_SENSOR) {
 			unit = "temp";
-			desc = "Sensor temp in C";
+			desc = "sensor unit (C)";
 		} else {
 			unit = "volt";
-			desc = "Sensor Volt in V";
+			desc = "sensor unit (mV)";
 		}
 		/* I use i to pass the sensor id. */
 		SYSCTL_ADD_PROC(ctx, SYSCTL_CHILDREN(oid), OID_AUTO,
@@ -584,9 +590,10 @@ ad7417_sensor_read(struct ad7417_sensor 
 
 	sc = device_get_softc(sens->dev);
 
-	/* Init the ADC. */
-	if (ad7417_init_adc(sc->sc_dev, sc->sc_addr) < 0)
-		return (-1);
+	/* Init the ADC if not already done.*/
+	if (!sc->init_done)
+		if (ad7417_init_adc(sc->sc_dev, sc->sc_addr) < 0)
+			return (-1);
 
 	if (sens->type == ADC7417_TEMP_SENSOR) {
 		if (ad7417_get_temp(sc->sc_dev, sc->sc_addr, &temp) < 0)



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