diff options
Diffstat (limited to 'sys')
-rw-r--r-- | sys/dev/i2c/adt7460.c | 80 |
1 files changed, 35 insertions, 45 deletions
diff --git a/sys/dev/i2c/adt7460.c b/sys/dev/i2c/adt7460.c index c328ec0ad29..1b74d03514a 100644 --- a/sys/dev/i2c/adt7460.c +++ b/sys/dev/i2c/adt7460.c @@ -1,4 +1,4 @@ -/* $OpenBSD: adt7460.c,v 1.10 2006/04/10 17:30:38 deraadt Exp $ */ +/* $OpenBSD: adt7460.c,v 1.11 2006/04/13 05:30:24 deraadt Exp $ */ /* * Copyright (c) 2005 Mark Kettenis @@ -61,33 +61,30 @@ struct adt_chip { const char *name; - short v25, vccp, vcc, v5, v12; - short type; + short ratio[5]; + int type; + short vcc; } adt_chips[] = { /* register 0x20 0x21 0x22 0x23 0x24 type */ /* 2.5v vccp vcc 5v 12v */ - { "adt7460", 2500, 2700, 3300, 5000, 12000, 7460 }, - { "adt7467", 2500, 2700, 3300, 5000, 12000, 7467 }, - { "adt7476", 2500, 2700, 3300, 5000, 12000, 7467 }, - { "adm1027", 2500, 2250, 3300, 5000, 12000, 1027 }, - { "lm85", 2500, 2700, 3300, 5000, 12000, 7467 }, - { "emc6d100", 2500, 2700, 3300, 5000, 12000, 7460 }, - { "emc6w201", 2500, 2700, 3300, 5000, 12000, 7460 }, - { "lm96000", 2500, 2700, 3300, 5000, 12000, 7460 }, - { "sch5017", 2500, 2250, 3300, 5000, 12000, 7460 } + { "adt7460", { 2500, 0, 3300, 0, 0 }, 7460, 5000 }, + { "adt7467", { 2500, 2250, 3300, 5000, 12000 }, 7467, 5000 }, + { "adt7476", { 2500, 2250, 3300, 5000, 12000 }, 7476, 0 }, + { "adm1027", { 2500, 2250, 3300, 5000, 12000 }, 1027, 5000 }, + { "lm85", { 2500, 2250, 3300, 5000, 12000 }, 7467, 0 }, + { "emc6d100", { 2500, 2250, 3300, 5000, 12000 }, 6100, 0 }, + { "emc6w201", { 2500, 2250, 3300, 5000, 12000 }, 6201, 0 }, + { "lm96000", { 2500, 2250, 3300, 5000, 12000 }, 96000, 0 }, + { "sch5017", { 2500, 2250, 3300, 5000, 12000 }, 5017, 0 } }; -struct adt_chip adt_chips_adm1027_vcc5 = - { "adm1027", 2500, 2250, 5000, 5000, 12000, 7460 }; - - struct adt_softc { struct device sc_dev; i2c_tag_t sc_tag; i2c_addr_t sc_addr; int sc_chip; - u_int8_t sc_config; + u_int8_t sc_conf; struct adt_chip *chip; struct sensor sc_sensor[ADT_NUM_SENSORS]; @@ -123,7 +120,7 @@ adt_attach(struct device *parent, struct device *self, void *aux) { struct adt_softc *sc = (struct adt_softc *)self; struct i2c_attach_args *ia = aux; - u_int8_t cmd, rev, data, conf; + u_int8_t cmd, rev, data; int i; sc->sc_tag = ia->ia_tag; @@ -148,16 +145,12 @@ adt_attach(struct device *parent, struct device *self, void *aux) cmd = ADT7460_CONFIG; if (iic_exec(sc->sc_tag, I2C_OP_READ_WITH_STOP, - sc->sc_addr, &cmd, sizeof cmd, &conf, sizeof conf, 0)) { + sc->sc_addr, &cmd, sizeof cmd, &sc->sc_conf, sizeof sc->sc_conf, 0)) { iic_release_bus(sc->sc_tag, 0); printf(": cannot read config register\n"); return; } - /* check if adm1027 is running in V5 mode */ - if (sc->sc_chip == 1027 && (conf & ADT7460_CONFIG_Vcc)) - sc->chip = &adt_chips_adm1027_vcc5; - if (sc->sc_chip == 7460) { data = 1; cmd = ADT7460_CONFIG; @@ -231,8 +224,10 @@ adt_attach(struct device *parent, struct device *self, void *aux) return; } - for (i = 0; i < ADT_NUM_SENSORS; i++) + for (i = 0; i < ADT_NUM_SENSORS; i++) { + sc->sc_sensor[i].flags &= ~SENSOR_FINVALID; sensor_add(&sc->sc_sensor[i]); + } printf("\n"); } @@ -240,12 +235,13 @@ adt_attach(struct device *parent, struct device *self, void *aux) struct { char sensor; u_int8_t cmd; + u_char index; } worklist[] = { - { ADT_2_5V, ADT7460_2_5V }, - { ADT_VCCP, ADT7460_VCCP }, - { ADT_VCC, ADT7460_VCC }, - { ADT_V5, ADT7460_V5 }, - { ADT_V12, ADT7460_V12 }, + { ADT_2_5V, ADT7460_2_5V, 0 }, + { ADT_VCCP, ADT7460_VCCP, 1 }, + { ADT_VCC, ADT7460_VCC, 2 }, + { ADT_V5, ADT7460_V5, 3 }, + { ADT_V12, ADT7460_V12, 4 }, { ADT_REM1_TEMP, ADT7460_REM1_TEMP }, { ADT_LOCAL_TEMP, ADT7460_LOCAL_TEMP }, { ADT_REM2_TEMP, ADT7460_REM2_TEMP }, @@ -261,11 +257,14 @@ adt_refresh(void *arg) struct adt_softc *sc = arg; u_int8_t cmd, data, data2; u_int16_t fan; - int i; + int i, ratio; iic_acquire_bus(sc->sc_tag, 0); for (i = 0; i < sizeof worklist / sizeof(worklist[0]); i++) { + + if (sc->chip->ratio[worklist[i].index] == 0) + continue; cmd = worklist[i].cmd; if (iic_exec(sc->sc_tag, I2C_OP_READ_WITH_STOP, sc->sc_addr, &cmd, sizeof cmd, &data, sizeof data, 0)) { @@ -274,26 +273,17 @@ adt_refresh(void *arg) } sc->sc_sensor[i].flags &= ~SENSOR_FINVALID; + ratio = sc->chip->ratio[worklist[i].index]; switch (worklist[i].sensor) { + case ADT_VCC: + if (sc->chip->vcc && (sc->sc_conf & ADT7460_CONFIG_Vcc)) + ratio = sc->chip->vcc; + /* FALLTHROUGH */ case ADT_2_5V: - sc->sc_sensor[i].value = sc->chip->v25 * 1000 * - data / 192; - break; case ADT_VCCP: - sc->sc_sensor[i].value = sc->chip->vccp * 1000 * - data / 192; - break; - case ADT_VCC: - sc->sc_sensor[i].value = sc->chip->vcc * 1000 * - data / 192; - break; case ADT_V5: - sc->sc_sensor[i].value = sc->chip->v5 * 1000 * - data / 192; - break; case ADT_V12: - sc->sc_sensor[i].value = sc->chip->v12 * 1000 * - data / 192; + sc->sc_sensor[i].value = ratio * 1000 * data / 192; break; case ADT_LOCAL_TEMP: case ADT_REM1_TEMP: |