summaryrefslogtreecommitdiff
path: root/sys/dev/i2c
diff options
context:
space:
mode:
authorTheo de Raadt <deraadt@cvs.openbsd.org>2005-12-28 22:04:29 +0000
committerTheo de Raadt <deraadt@cvs.openbsd.org>2005-12-28 22:04:29 +0000
commit5e078371465e8940304c56163e5e6aab738c24d6 (patch)
tree7a8692662943831ef86cec3bbec438cb99ac9a3b /sys/dev/i2c
parent2181786877d4dc162a12e4a07a8441ac6d24a44b (diff)
I think this is better fan support
Diffstat (limited to 'sys/dev/i2c')
-rw-r--r--sys/dev/i2c/adm1024.c22
-rw-r--r--sys/dev/i2c/adm1026.c45
2 files changed, 44 insertions, 23 deletions
diff --git a/sys/dev/i2c/adm1024.c b/sys/dev/i2c/adm1024.c
index 9e63c248212..9108357df8e 100644
--- a/sys/dev/i2c/adm1024.c
+++ b/sys/dev/i2c/adm1024.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: adm1024.c,v 1.6 2005/12/28 20:35:42 deraadt Exp $ */
+/* $OpenBSD: adm1024.c,v 1.7 2005/12/28 22:04:28 deraadt Exp $ */
/*
* Copyright (c) 2005 Theo de Raadt
@@ -124,8 +124,8 @@ admlc_attach(struct device *parent, struct device *self, void *aux)
printf(", unable to read fan setting\n");
return;
}
- sc->sc_fan1mul = 8800 * (1 << (data >> 4) & 0x3);
- sc->sc_fan2mul = 8800 * (1 << (data >> 6) & 0x3);
+ sc->sc_fan1mul = (1 << (data >> 4) & 0x3);
+ sc->sc_fan2mul = (1 << (data >> 6) & 0x3);
iic_release_bus(sc->sc_tag, 0);
@@ -186,6 +186,17 @@ admlc_attach(struct device *parent, struct device *self, void *aux)
printf("\n");
}
+static void
+fanval(struct sensor *sens, int mul, u_int8_t data)
+{
+ int tmp = data * mul;
+
+ if (tmp == 0)
+ sens->flags |= SENSOR_FINVALID;
+ else
+ sens->value = 1350000 / tmp;
+}
+
void
admlc_refresh(void *arg)
{
@@ -247,12 +258,11 @@ admlc_refresh(void *arg)
cmd = ADM1024_FAN1;
if (iic_exec(sc->sc_tag, I2C_OP_READ_WITH_STOP,
sc->sc_addr, &cmd, sizeof cmd, &data, sizeof data, I2C_F_POLL) == 0)
- sc->sc_sensor[ADMLC_FAN1].value = sc->sc_fan1mul * data;
+ fanval(&sc->sc_sensor[ADMLC_FAN1], sc->sc_fan1mul, data);
cmd = ADM1024_FAN2;
if (iic_exec(sc->sc_tag, I2C_OP_READ_WITH_STOP,
sc->sc_addr, &cmd, sizeof cmd, &data, sizeof data, I2C_F_POLL) == 0)
- sc->sc_sensor[ADMLC_FAN2].value = sc->sc_fan2mul * data;
-
+ fanval(&sc->sc_sensor[ADMLC_FAN2], sc->sc_fan2mul, data);
iic_release_bus(sc->sc_tag, 0);
}
diff --git a/sys/dev/i2c/adm1026.c b/sys/dev/i2c/adm1026.c
index 264cd5ae4ab..18c0d2cf462 100644
--- a/sys/dev/i2c/adm1026.c
+++ b/sys/dev/i2c/adm1026.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: adm1026.c,v 1.2 2005/12/28 20:35:42 deraadt Exp $ */
+/* $OpenBSD: adm1026.c,v 1.3 2005/12/28 22:04:28 deraadt Exp $ */
/*
* Copyright (c) 2005 Theo de Raadt
@@ -141,10 +141,10 @@ admcts_attach(struct device *parent, struct device *self, void *aux)
printf(": cannot get fan0123div register\n");
return;
}
- sc->sc_fanmul[0] = 8800 * (1 << (data >> 0) & 0x3);
- sc->sc_fanmul[1] = 8800 * (1 << (data >> 2) & 0x3);
- sc->sc_fanmul[2] = 8800 * (1 << (data >> 4) & 0x3);
- sc->sc_fanmul[3] = 8800 * (1 << (data >> 6) & 0x3);
+ sc->sc_fanmul[0] = (1 << (data >> 0) & 0x3);
+ sc->sc_fanmul[1] = (1 << (data >> 2) & 0x3);
+ sc->sc_fanmul[2] = (1 << (data >> 4) & 0x3);
+ sc->sc_fanmul[3] = (1 << (data >> 6) & 0x3);
cmd = ADM1026_FAN4567DIV;
if (iic_exec(sc->sc_tag, I2C_OP_READ_WITH_STOP,
@@ -153,10 +153,10 @@ admcts_attach(struct device *parent, struct device *self, void *aux)
printf(": cannot get fan0123div register\n");
return;
}
- sc->sc_fanmul[4] = 8800 * (1 << (data >> 0) & 0x3);
- sc->sc_fanmul[5] = 8800 * (1 << (data >> 2) & 0x3);
- sc->sc_fanmul[6] = 8800 * (1 << (data >> 4) & 0x3);
- sc->sc_fanmul[7] = 8800 * (1 << (data >> 6) & 0x3);
+ sc->sc_fanmul[4] = (1 << (data >> 0) & 0x3);
+ sc->sc_fanmul[5] = (1 << (data >> 2) & 0x3);
+ sc->sc_fanmul[6] = (1 << (data >> 4) & 0x3);
+ sc->sc_fanmul[7] = (1 << (data >> 6) & 0x3);
iic_release_bus(sc->sc_tag, 0);
@@ -248,6 +248,17 @@ admcts_attach(struct device *parent, struct device *self, void *aux)
printf("\n");
}
+static void
+fanval(struct sensor *sens, int mul, u_int8_t data)
+{
+ int tmp = data * mul;
+
+ if (tmp == 0)
+ sens->flags |= SENSOR_FINVALID;
+ else
+ sens->value = 1350000 / tmp;
+}
+
void
admcts_refresh(void *arg)
{
@@ -310,42 +321,42 @@ admcts_refresh(void *arg)
cmd = ADM1026_FAN0;
if (iic_exec(sc->sc_tag, I2C_OP_READ_WITH_STOP,
sc->sc_addr, &cmd, sizeof cmd, &data, sizeof data, I2C_F_POLL) == 0)
- sc->sc_sensor[ADMCTS_FAN0].value = sc->sc_fanmul[0] * data;
+ fanval(&sc->sc_sensor[ADMCTS_FAN0], sc->sc_fanmul[0], data);
cmd = ADM1026_FAN1;
if (iic_exec(sc->sc_tag, I2C_OP_READ_WITH_STOP,
sc->sc_addr, &cmd, sizeof cmd, &data, sizeof data, I2C_F_POLL) == 0)
- sc->sc_sensor[ADMCTS_FAN1].value = sc->sc_fanmul[1] * data;
+ fanval(&sc->sc_sensor[ADMCTS_FAN1], sc->sc_fanmul[1], data);
cmd = ADM1026_FAN2;
if (iic_exec(sc->sc_tag, I2C_OP_READ_WITH_STOP,
sc->sc_addr, &cmd, sizeof cmd, &data, sizeof data, I2C_F_POLL) == 0)
- sc->sc_sensor[ADMCTS_FAN2].value = sc->sc_fanmul[2] * data;
+ fanval(&sc->sc_sensor[ADMCTS_FAN2], sc->sc_fanmul[2], data);
cmd = ADM1026_FAN3;
if (iic_exec(sc->sc_tag, I2C_OP_READ_WITH_STOP,
sc->sc_addr, &cmd, sizeof cmd, &data, sizeof data, I2C_F_POLL) == 0)
- sc->sc_sensor[ADMCTS_FAN3].value = sc->sc_fanmul[3] * data;
+ fanval(&sc->sc_sensor[ADMCTS_FAN3], sc->sc_fanmul[3], data);
cmd = ADM1026_FAN4;
if (iic_exec(sc->sc_tag, I2C_OP_READ_WITH_STOP,
sc->sc_addr, &cmd, sizeof cmd, &data, sizeof data, I2C_F_POLL) == 0)
- sc->sc_sensor[ADMCTS_FAN4].value = sc->sc_fanmul[4] * data;
+ fanval(&sc->sc_sensor[ADMCTS_FAN4], sc->sc_fanmul[4], data);
cmd = ADM1026_FAN5;
if (iic_exec(sc->sc_tag, I2C_OP_READ_WITH_STOP,
sc->sc_addr, &cmd, sizeof cmd, &data, sizeof data, I2C_F_POLL) == 0)
- sc->sc_sensor[ADMCTS_FAN5].value = sc->sc_fanmul[5] * data;
+ fanval(&sc->sc_sensor[ADMCTS_FAN5], sc->sc_fanmul[5], data);
cmd = ADM1026_FAN6;
if (iic_exec(sc->sc_tag, I2C_OP_READ_WITH_STOP,
sc->sc_addr, &cmd, sizeof cmd, &data, sizeof data, I2C_F_POLL) == 0)
- sc->sc_sensor[ADMCTS_FAN6].value = sc->sc_fanmul[6] * data;
+ fanval(&sc->sc_sensor[ADMCTS_FAN6], sc->sc_fanmul[6], data);
cmd = ADM1026_FAN7;
if (iic_exec(sc->sc_tag, I2C_OP_READ_WITH_STOP,
sc->sc_addr, &cmd, sizeof cmd, &data, sizeof data, I2C_F_POLL) == 0)
- sc->sc_sensor[ADMCTS_FAN7].value = sc->sc_fanmul[7] * data;
+ fanval(&sc->sc_sensor[ADMCTS_FAN7], sc->sc_fanmul[7], data);
iic_release_bus(sc->sc_tag, 0);
}