summaryrefslogtreecommitdiff
path: root/sys/dev/onewire/owtemp.c
diff options
context:
space:
mode:
authorTodd T. Fries <todd@cvs.openbsd.org>2008-12-26 18:17:26 +0000
committerTodd T. Fries <todd@cvs.openbsd.org>2008-12-26 18:17:26 +0000
commitbf3b6f2384dfb5783abe569c9796e049014076e7 (patch)
tree2d545ca2527563f032e8a60856ec5027af70244f /sys/dev/onewire/owtemp.c
parenta05cf1cf173171bb9fe2f11155e0074f3afdd327 (diff)
implement support for another temperature sensor, DS18B20
from David Fries david(at)fries(dot)net ok grange@
Diffstat (limited to 'sys/dev/onewire/owtemp.c')
-rw-r--r--sys/dev/onewire/owtemp.c35
1 files changed, 23 insertions, 12 deletions
diff --git a/sys/dev/onewire/owtemp.c b/sys/dev/onewire/owtemp.c
index 204ed1e93f8..0016c9393db 100644
--- a/sys/dev/onewire/owtemp.c
+++ b/sys/dev/onewire/owtemp.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: owtemp.c,v 1.10 2008/10/25 00:27:09 deraadt Exp $ */
+/* $OpenBSD: owtemp.c,v 1.11 2008/12/26 18:17:25 todd Exp $ */
/*
* Copyright (c) 2006 Alexander Yurchenko <grange@openbsd.org>
@@ -41,6 +41,7 @@
#define DS1920_SP_TEMP_MSB 1
#define DS1920_SP_TH 2
#define DS1920_SP_TL 3
+#define DS18B20_SP_CONFIG 4
#define DS1920_SP_COUNT_REMAIN 6
#define DS1920_SP_COUNT_PERC 7
#define DS1920_SP_CRC 8
@@ -77,7 +78,8 @@ struct cfdriver owtemp_cd = {
};
static const struct onewire_matchfam owtemp_fams[] = {
- { ONEWIRE_FAMILY_DS1920 }
+ { ONEWIRE_FAMILY_DS1920 },
+ { ONEWIRE_FAMILY_DS18B20 }
};
int
@@ -172,17 +174,26 @@ owtemp_update(void *arg)
if (onewire_crc(data, 8) == data[DS1920_SP_CRC]) {
temp = data[DS1920_SP_TEMP_MSB] << 8 |
data[DS1920_SP_TEMP_LSB];
- count_perc = data[DS1920_SP_COUNT_PERC];
- count_remain = data[DS1920_SP_COUNT_REMAIN];
-
- if (count_perc != 0) {
- /* High resolution algorithm */
- temp &= ~0x0001;
- val = temp * 500000 - 250000 +
- ((count_perc - count_remain) * 1000000) /
- count_perc;
+ if (ONEWIRE_ROM_FAMILY(sc->sc_rom) == ONEWIRE_FAMILY_DS18B20) {
+ /*
+ * DS18B20 decoding
+ * default 12 bit 0.0625 C resolution
+ */
+ val = temp * (1000000 / 16);
} else {
- val = temp * 500000;
+ /* DS1920 decoding */
+ count_perc = data[DS1920_SP_COUNT_PERC];
+ count_remain = data[DS1920_SP_COUNT_REMAIN];
+
+ if (count_perc != 0) {
+ /* High resolution algorithm */
+ temp &= ~0x0001;
+ val = temp * 500000 - 250000 +
+ ((count_perc - count_remain) * 1000000) /
+ count_perc;
+ } else {
+ val = temp * 500000;
+ }
}
sc->sc_sensor.value = 273150000 + val;
}