summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorandreast <andreast@FreeBSD.org>2012-08-19 19:31:36 +0000
committerandreast <andreast@FreeBSD.org>2012-08-19 19:31:36 +0000
commitef016efdbc8371041fd053eb74d109c086602e04 (patch)
tree59251fce27e1047c27fed56eb0203fc47acd1247
parent7f10a4b817085256cded571619442708e0eeb512 (diff)
downloadFreeBSD-src-ef016efdbc8371041fd053eb74d109c086602e04.zip
FreeBSD-src-ef016efdbc8371041fd053eb74d109c086602e04.tar.gz
Do the ADC init only at startup and not during every sensor read call.
This reduces the number of interrupts.
-rw-r--r--sys/dev/iicbus/ad7417.c17
1 files changed, 12 insertions, 5 deletions
diff --git a/sys/dev/iicbus/ad7417.c b/sys/dev/iicbus/ad7417.c
index acd2d89..ac84ffe 100644
--- a/sys/dev/iicbus/ad7417.c
+++ b/sys/dev/iicbus/ad7417.c
@@ -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 addr)
{
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 addr)
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 *sens)
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)
OpenPOWER on IntegriCloud