dtt: add ds620 support
authorAlbert ARIBAUD \(3ADEV\) <albert.aribaud@3adev.fr>
Tue, 31 Mar 2015 09:40:48 +0000 (11:40 +0200)
committerAlbert ARIBAUD <albert.u.boot@aribaud.net>
Fri, 10 Apr 2015 12:23:23 +0000 (14:23 +0200)
Signed-off-by: Albert ARIBAUD (3ADEV) <albert.aribaud@3adev.fr>
drivers/hwmon/Makefile
drivers/hwmon/ds620.c [new file with mode: 0644]
include/dtt.h

index 25b8e8a2d79f4490e246aa2b687a522523e11818..b4fb057c16a0dfed94c64390cab05e3b0e16e2fa 100644 (file)
@@ -15,6 +15,7 @@ obj-$(CONFIG_DTT_ADT7460) += adt7460.o
 obj-$(CONFIG_DTT_DS1621) += ds1621.o
 obj-$(CONFIG_DTT_DS1722) += ds1722.o
 obj-$(CONFIG_DTT_DS1775) += ds1775.o
+obj-$(CONFIG_DTT_DS620) += ds620.o
 obj-$(CONFIG_DTT_LM63) += lm63.o
 obj-$(CONFIG_DTT_LM73) += lm73.o
 obj-$(CONFIG_DTT_LM75) += lm75.o
diff --git a/drivers/hwmon/ds620.c b/drivers/hwmon/ds620.c
new file mode 100644 (file)
index 0000000..1ecc3da
--- /dev/null
@@ -0,0 +1,65 @@
+/*
+ * DS620 DTT support
+ *
+ * (C) Copyright 2014 3ADEV <http://www.3adev.com>
+ * Written-by: Albert ARIBAUD <albert.aribaud@3adev.fr>
+ *
+ * SPDX-License-Identifier:    GPL-2.0+
+ */
+
+/*
+ * Dallas Semiconductor's DS1621/1631 Digital Thermometer and Thermostat.
+ */
+
+#include <common.h>
+#include <i2c.h>
+#include <dtt.h>
+
+/*
+ * Device code
+ */
+#define DTT_I2C_DEV_CODE       0x48
+#define DTT_START_CONVERT      0x51
+#define DTT_TEMP               0xAA
+#define DTT_CONFIG             0xAC
+
+/*
+ * Config register MSB bits
+ */
+#define DTT_CONFIG_1SHOT       0x01
+#define DTT_CONFIG_AUTOC       0x02
+#define DTT_CONFIG_R0          0x04 /* always 1 */
+#define DTT_CONFIG_R1          0x08 /* always 1 */
+#define DTT_CONFIG_TLF 0x10
+#define DTT_CONFIG_THF 0x20
+#define DTT_CONFIG_NVB 0x40
+#define DTT_CONFIG_DONE        0x80
+
+#define CHIP(sensor) (DTT_I2C_DEV_CODE + (sensor & 0x07))
+
+int dtt_init_one(int sensor)
+{
+       uint8_t config = DTT_CONFIG_1SHOT
+                       | DTT_CONFIG_R0
+                       | DTT_CONFIG_R1;
+       return i2c_write(CHIP(sensor), DTT_CONFIG, 1, &config, 1);
+}
+
+int dtt_get_temp(int sensor)
+{
+       uint8_t status;
+       uint8_t temp[2];
+
+       /* Start a conversion, may take up to 1 second. */
+       i2c_write(CHIP(sensor), DTT_START_CONVERT, 1, NULL, 0);
+       do {
+               if (i2c_read(CHIP(sensor), DTT_CONFIG, 1, &status, 1))
+                       /* bail out if I2C error */
+                       status |= DTT_CONFIG_DONE;
+       } while (!(status & DTT_CONFIG_DONE));
+       if (i2c_read(CHIP(sensor), DTT_TEMP, 1, temp, 2))
+               /* bail out if I2C error */
+               return -274; /* below absolute zero == error */
+
+       return ((int16_t)(temp[1] | (temp[0] << 8))) >> 7;
+}
index 058bca4d5d6c0193e7e83bb1ab3714359cdd2a8c..173159dc6287552c56e492ae09bc3d243b922095 100644 (file)
 #define _DTT_H_
 
 #if defined(CONFIG_DTT_ADM1021)        || \
-    defined(CONFIG_DTT_ADT7460)        || \
-    defined(CONFIG_DTT_DS1621) || \
-    defined(CONFIG_DTT_DS1775) || \
-    defined(CONFIG_DTT_LM63)   || \
-    defined(CONFIG_DTT_LM73)   || \
-    defined(CONFIG_DTT_LM75)   || \
-    defined(CONFIG_DTT_LM81)
+       defined(CONFIG_DTT_ADT7460)     || \
+       defined(CONFIG_DTT_DS1621)      || \
+       defined(CONFIG_DTT_DS1775)      || \
+       defined(CONFIG_DTT_DS620)       || \
+       defined(CONFIG_DTT_LM63)        || \
+       defined(CONFIG_DTT_LM73)        || \
+       defined(CONFIG_DTT_LM75)        || \
+       defined(CONFIG_DTT_LM81)
 
 #define CONFIG_DTT                             /* We have a DTT */