summaryrefslogtreecommitdiff
path: root/sys/dev
diff options
context:
space:
mode:
authorMark Kettenis <kettenis@cvs.openbsd.org>2005-11-16 16:27:54 +0000
committerMark Kettenis <kettenis@cvs.openbsd.org>2005-11-16 16:27:54 +0000
commitc15a66bbd20038916f24acd0e84a8a72ca694bf9 (patch)
treed1df3439ba00e5420f1d40bbd0907fe3d2e1200b /sys/dev
parentea4e3efd88b8eefa2287e3f2a576f687618df636 (diff)
Add support for MAX6642.
ok deraadt@
Diffstat (limited to 'sys/dev')
-rw-r--r--sys/dev/i2c/maxim6690.c70
1 files changed, 46 insertions, 24 deletions
diff --git a/sys/dev/i2c/maxim6690.c b/sys/dev/i2c/maxim6690.c
index d39b2557e0c..8099c9d4110 100644
--- a/sys/dev/i2c/maxim6690.c
+++ b/sys/dev/i2c/maxim6690.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: maxim6690.c,v 1.1 2005/11/15 16:24:49 deraadt Exp $ */
+/* $OpenBSD: maxim6690.c,v 1.2 2005/11/16 16:27:53 kettenis Exp $ */
/*
* Copyright (c) 2005 Theo de Raadt
@@ -23,16 +23,20 @@
#include <dev/i2c/i2cvar.h>
-/* Maxim 6690 registers */
-#define MAXIM6690_INT_TEMP 0x00
-#define MAXIM6690_EXT_TEMP 0x01
-#define MAXIM6690_INT_TEMP2 0x10
-#define MAXIM6690_EXT_TEMP2 0x11
-#define MAXIM6690_STATUS 0x02
-#define MAXIM6690_DEVID 0xfe
-#define MAXIM6690_REVISION 0xff
+/* Maxim MAX6642/90 registers */
+#define MAX6690_INT_TEMP 0x00
+#define MAX6690_EXT_TEMP 0x01
+#define MAX6690_INT_TEMP2 0x10
+#define MAX6690_EXT_TEMP2 0x11
+#define MAX6690_STATUS 0x02
+#define MAX6690_DEVID 0xfe
+#define MAX6690_REVISION 0xff /* absent on MAX6642 */
-#define MAXIM6690_TEMP_INVALID 0x80 /* sensor disconnected */
+#define MAX6642_TEMP_INVALID 0xff /* sensor disconnected */
+#define MAX6690_TEMP_INVALID 0x80 /* sensor disconnected */
+
+#define MAX6642_TEMP2_MASK 0xc0 /* significant bits */
+#define MAX6690_TEMP2_MASK 0xe0 /* significant bits */
/* Sensors */
#define MAXTMP_INT 0
@@ -44,6 +48,9 @@ struct maxtmp_softc {
i2c_tag_t sc_tag;
i2c_addr_t sc_addr;
+ u_int8_t sc_temp_invalid;
+ u_int8_t sc_temp2_mask;
+
struct sensor sc_sensor[MAXTMP_NUM_SENSORS];
};
@@ -67,14 +74,14 @@ maxtmp_check(struct i2c_attach_args *ia, u_int8_t *idp, u_int8_t *revp)
iic_acquire_bus(ia->ia_tag, 0);
- cmd = MAXIM6690_DEVID;
+ cmd = MAX6690_DEVID;
if (iic_exec(ia->ia_tag, I2C_OP_READ_WITH_STOP,
ia->ia_addr, &cmd, sizeof cmd, &id, sizeof id, 0)) {
iic_release_bus(ia->ia_tag, 0);
return 0;
}
- cmd = MAXIM6690_REVISION;
+ cmd = MAX6690_REVISION;
if (iic_exec(ia->ia_tag, I2C_OP_READ_WITH_STOP,
ia->ia_addr, &cmd, sizeof cmd, &rev, sizeof rev, 0)) {
iic_release_bus(ia->ia_tag, 0);
@@ -83,15 +90,14 @@ maxtmp_check(struct i2c_attach_args *ia, u_int8_t *idp, u_int8_t *revp)
iic_release_bus(ia->ia_tag, 0);
- if (id == 0x4d && rev == 0x09) {
- *idp = id;
- *revp = rev;
+ *idp = id;
+ *revp = rev;
+
+ if (id == 0x4d)
return (1);
- }
return (0);
}
-
int
maxtmp_match(struct device *parent, void *match, void *aux)
{
@@ -99,7 +105,8 @@ maxtmp_match(struct device *parent, void *match, void *aux)
u_int8_t id, rev;
if (ia->ia_compat) {
- if (strcmp(ia->ia_compat, "max6690") == 0)
+ if (strcmp(ia->ia_compat, "max6642") == 0 ||
+ strcmp(ia->ia_compat, "max6690") == 0)
return (1);
return (0);
}
@@ -117,8 +124,20 @@ maxtmp_attach(struct device *parent, struct device *self, void *aux)
sc->sc_tag = ia->ia_tag;
sc->sc_addr = ia->ia_addr;
- rev = maxtmp_check(ia, &id, &rev);
- printf(": id 0x%x rev 0x%x", id, rev);
+ if (maxtmp_check(ia, &id, &rev) == 0) {
+ printf(": unknown Device ID 0x%x\n", id);
+ return;
+ }
+
+ if (ia->ia_compat && strcmp(ia->ia_compat, "max6642") == 0) {
+ sc->sc_temp_invalid = MAX6642_TEMP_INVALID;
+ sc->sc_temp2_mask = MAX6642_TEMP2_MASK;
+ printf(": MAX6642");
+ } else {
+ sc->sc_temp_invalid = MAX6690_TEMP_INVALID;
+ sc->sc_temp2_mask = MAX6690_TEMP2_MASK;
+ printf(": MAX6690 rev 0x%x", rev);
+ }
/* Initialize sensor data. */
for (i = 0; i < MAXTMP_NUM_SENSORS; i++)
@@ -155,14 +174,17 @@ maxtmp_readport(struct maxtmp_softc *sc, u_int8_t cmd1, u_int8_t cmd2,
if (iic_exec(sc->sc_tag, I2C_OP_READ_WITH_STOP,
sc->sc_addr, &cmd1, sizeof cmd1, &data, sizeof data, 0))
goto invalid;
- if (data == MAXIM6690_TEMP_INVALID)
+ if (data == sc->sc_temp_invalid)
goto invalid;
if (iic_exec(sc->sc_tag, I2C_OP_READ_WITH_STOP,
sc->sc_addr, &cmd2, sizeof cmd2, &data2, sizeof data2, 0))
goto invalid;
+ /* Set any meaningless bits to zero. */
+ data2 &= sc->sc_temp2_mask;
+
sc->sc_sensor[index].value = 273150000 +
- 1000000 * data + (data2 >> 5) * 1000000 / 16;
+ 1000000 * data + (data2 >> 5) * 1000000 / 8;
return;
invalid:
@@ -176,8 +198,8 @@ maxtmp_refresh(void *arg)
iic_acquire_bus(sc->sc_tag, 0);
- maxtmp_readport(sc, MAXIM6690_INT_TEMP, MAXIM6690_INT_TEMP2, MAXTMP_INT);
- maxtmp_readport(sc, MAXIM6690_EXT_TEMP, MAXIM6690_EXT_TEMP2, MAXTMP_EXT);
+ maxtmp_readport(sc, MAX6690_INT_TEMP, MAX6690_INT_TEMP2, MAXTMP_INT);
+ maxtmp_readport(sc, MAX6690_EXT_TEMP, MAX6690_EXT_TEMP2, MAXTMP_EXT);
iic_release_bus(sc->sc_tag, 0);
}