4 * (C) Copyright 2014 3ADEV <http://www.3adev.com>
5 * Written-by: Albert ARIBAUD <albert.aribaud@3adev.fr>
7 * SPDX-License-Identifier: GPL-2.0+
11 * Dallas Semiconductor's DS1621/1631 Digital Thermometer and Thermostat.
21 #define DTT_I2C_DEV_CODE 0x48
22 #define DTT_START_CONVERT 0x51
24 #define DTT_CONFIG 0xAC
27 * Config register MSB bits
29 #define DTT_CONFIG_1SHOT 0x01
30 #define DTT_CONFIG_AUTOC 0x02
31 #define DTT_CONFIG_R0 0x04 /* always 1 */
32 #define DTT_CONFIG_R1 0x08 /* always 1 */
33 #define DTT_CONFIG_TLF 0x10
34 #define DTT_CONFIG_THF 0x20
35 #define DTT_CONFIG_NVB 0x40
36 #define DTT_CONFIG_DONE 0x80
38 #define CHIP(sensor) (DTT_I2C_DEV_CODE + (sensor & 0x07))
40 int dtt_init_one(int sensor)
42 uint8_t config = DTT_CONFIG_1SHOT
45 return i2c_write(CHIP(sensor), DTT_CONFIG, 1, &config, 1);
48 int dtt_get_temp(int sensor)
53 /* Start a conversion, may take up to 1 second. */
54 i2c_write(CHIP(sensor), DTT_START_CONVERT, 1, NULL, 0);
56 if (i2c_read(CHIP(sensor), DTT_CONFIG, 1, &status, 1))
57 /* bail out if I2C error */
58 status |= DTT_CONFIG_DONE;
59 } while (!(status & DTT_CONFIG_DONE));
60 if (i2c_read(CHIP(sensor), DTT_TEMP, 1, temp, 2))
61 /* bail out if I2C error */
62 return -274; /* below absolute zero == error */
64 return ((int16_t)(temp[1] | (temp[0] << 8))) >> 7;