summaryrefslogtreecommitdiff
path: root/sys/dev/i2c
diff options
context:
space:
mode:
authorTheo de Raadt <deraadt@cvs.openbsd.org>2005-11-28 17:58:21 +0000
committerTheo de Raadt <deraadt@cvs.openbsd.org>2005-11-28 17:58:21 +0000
commit4332d60c7bd575fa4a9f7e1f2c9f4c29a27e48e4 (patch)
tree10d43d438b49974ba6d6e707d22fc89f8d7f9130 /sys/dev/i2c
parentde2aee7defecdfc8a5a1fccce6d9cdd7d04d9e73 (diff)
attempt to cope with the other versions of the chips
try not to scan all the sensors every pass through, but do a few registers each time still not reading correct data on one machine i have, but this might be because apple did not connect them up. who knows, when they build machines with 50+ sensors..
Diffstat (limited to 'sys/dev/i2c')
-rw-r--r--sys/dev/i2c/ad741x.c79
1 files changed, 53 insertions, 26 deletions
diff --git a/sys/dev/i2c/ad741x.c b/sys/dev/i2c/ad741x.c
index da4828972f6..7db99c7e367 100644
--- a/sys/dev/i2c/ad741x.c
+++ b/sys/dev/i2c/ad741x.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ad741x.c,v 1.2 2005/11/15 22:15:09 deraadt Exp $ */
+/* $OpenBSD: ad741x.c,v 1.3 2005/11/28 17:58:20 deraadt Exp $ */
/*
* Copyright (c) 2005 Theo de Raadt
@@ -45,7 +45,8 @@ struct adc_softc {
struct device sc_dev;
i2c_tag_t sc_tag;
i2c_addr_t sc_addr;
- int sc_newchip;
+ int sc_chip;
+ u_int8_t sc_config;
struct sensor sc_sensor[ADC_MAX_SENSORS];
};
@@ -82,27 +83,20 @@ adc_attach(struct device *parent, struct device *self, void *aux)
struct adc_softc *sc = (struct adc_softc *)self;
struct i2c_attach_args *ia = aux;
u_int8_t cmd, data;
- int i;
+ int nsens = 0, i;
sc->sc_tag = ia->ia_tag;
sc->sc_addr = ia->ia_addr;
if (ia->ia_compat) {
- sc->sc_newchip = 0;
- if (strcmp(ia->ia_compat, "ad7417") == 0 ||
- strcmp(ia->ia_compat, "ad7418") == 0)
- sc->sc_newchip = 1;
- }
-
- cmd = AD741X_CONFIG;
- data = 0;
- if (iic_exec(sc->sc_tag, I2C_OP_WRITE_WITH_STOP,
- sc->sc_addr, &cmd, sizeof cmd, &data, sizeof data, 0)) {
- printf(", config reset failed\n");
- return;
+ sc->sc_chip = 0;
+ if (strcmp(ia->ia_compat, "ad7417") == 0)
+ sc->sc_chip = 7417;
+ if (strcmp(ia->ia_compat, "ad7418") == 0)
+ sc->sc_chip = 7418;
}
- if (sc->sc_newchip) {
+ if (sc->sc_chip != 0) {
cmd = AD741X_CONFIG2;
data = 0;
if (iic_exec(sc->sc_tag, I2C_OP_WRITE_WITH_STOP,
@@ -112,6 +106,20 @@ adc_attach(struct device *parent, struct device *self, void *aux)
}
}
+ cmd = AD741X_CONFIG;
+ if (iic_exec(sc->sc_tag, I2C_OP_READ_WITH_STOP,
+ sc->sc_addr, &cmd, sizeof cmd, &data, sizeof data, 0)) {
+ printf(", config reset failed\n");
+ return;
+ }
+ data &= 0xfe;
+ if (iic_exec(sc->sc_tag, I2C_OP_WRITE_WITH_STOP,
+ sc->sc_addr, &cmd, sizeof cmd, &data, sizeof data, 0)) {
+ printf(", config reset failed\n");
+ return;
+ }
+ sc->sc_config = data;
+
/* Initialize sensor data. */
for (i = 0; i < ADC_MAX_SENSORS; i++)
strlcpy(sc->sc_sensor[i].device, sc->sc_dev.dv_xname,
@@ -120,11 +128,15 @@ adc_attach(struct device *parent, struct device *self, void *aux)
sc->sc_sensor[ADC_TEMP].type = SENSOR_TEMP;
strlcpy(sc->sc_sensor[ADC_TEMP].desc, "Internal",
sizeof(sc->sc_sensor[ADC_TEMP].desc));
+ nsens = 1;
- if (sc->sc_newchip) {
+ if (sc->sc_chip == 7417 || sc->sc_chip == 7418) {
sc->sc_sensor[ADC_ADC0].type = SENSOR_INTEGER;
strlcpy(sc->sc_sensor[ADC_ADC0].desc, "adc0",
sizeof(sc->sc_sensor[ADC_ADC0].desc));
+ nsens++;
+ }
+ if (sc->sc_chip == 7417 || sc->sc_chip == 7418) {
sc->sc_sensor[ADC_ADC1].type = SENSOR_INTEGER;
strlcpy(sc->sc_sensor[ADC_ADC1].desc, "adc1",
sizeof(sc->sc_sensor[ADC_ADC1].desc));
@@ -134,6 +146,7 @@ adc_attach(struct device *parent, struct device *self, void *aux)
sc->sc_sensor[ADC_ADC3].type = SENSOR_INTEGER;
strlcpy(sc->sc_sensor[ADC_ADC3].desc, "adc3",
sizeof(sc->sc_sensor[ADC_ADC3].desc));
+ nsens += 3;
}
if (sensor_task_register(sc, adc_refresh, 5)) {
@@ -142,10 +155,11 @@ adc_attach(struct device *parent, struct device *self, void *aux)
}
SENSOR_ADD(&sc->sc_sensor[0]);
- if (sc->sc_newchip) {
- for (i = 1; i < ADC_MAX_SENSORS; i++)
+ if (sc->sc_chip == 7417 || sc->sc_chip == 7418)
+ SENSOR_ADD(&sc->sc_sensor[1]);
+ if (sc->sc_chip == 7417)
+ for (i = 2; i < nsens; i++)
SENSOR_ADD(&sc->sc_sensor[i]);
- }
printf("\n");
}
@@ -161,14 +175,11 @@ adc_refresh(void *arg)
iic_acquire_bus(sc->sc_tag, 0);
- cmd = AD741X_CONFIG;
- if (iic_exec(sc->sc_tag, I2C_OP_READ_WITH_STOP,
- sc->sc_addr, &cmd, sizeof cmd, &reg, sizeof reg, 0))
- goto done;
- reg = (reg & AD741X_CONFMASK) | (0 << 5);
+ reg = (sc->sc_config & AD741X_CONFMASK) | (0 << 5);
if (iic_exec(sc->sc_tag, I2C_OP_WRITE_WITH_STOP,
sc->sc_addr, &cmd, sizeof cmd, &reg, sizeof reg, 0))
goto done;
+ delay(1000);
cmd = AD741X_TEMP;
if (iic_exec(sc->sc_tag, I2C_OP_READ_WITH_STOP,
sc->sc_addr, &cmd, sizeof cmd, &data, sizeof data, 0))
@@ -176,14 +187,30 @@ adc_refresh(void *arg)
sc->sc_sensor[ADC_TEMP].value = 273150000 +
((data[0] << 8 | data[1]) >> 6) * 250000;
- if (sc->sc_newchip == 0)
+ if (sc->sc_chip == 0)
goto done;
+ if (sc->sc_chip == 7418) {
+ reg = (reg & AD741X_CONFMASK) | (4 << 5);
+ if (iic_exec(sc->sc_tag, I2C_OP_WRITE_WITH_STOP,
+ sc->sc_addr, &cmd, sizeof cmd, &reg, sizeof reg, 0))
+ goto done;
+ delay(1000);
+ cmd = AD741X_ADC;
+ if (iic_exec(sc->sc_tag, I2C_OP_READ_WITH_STOP,
+ sc->sc_addr, &cmd, sizeof cmd, &data, sizeof data, 0))
+ goto done;
+ sc->sc_sensor[ADC_ADC0].value =
+ (data[0] << 8 | data[1]) >> 6;
+ goto done;
+ }
+
for (i = 0; i < 4; i++) {
reg = (reg & AD741X_CONFMASK) | (i << 5);
if (iic_exec(sc->sc_tag, I2C_OP_WRITE_WITH_STOP,
sc->sc_addr, &cmd, sizeof cmd, &reg, sizeof reg, 0))
goto done;
+ delay(1000);
cmd = AD741X_ADC;
if (iic_exec(sc->sc_tag, I2C_OP_READ_WITH_STOP,
sc->sc_addr, &cmd, sizeof cmd, &data, sizeof data, 0))