Commit 24d528e3fa3a8370aa5263592c362b7d61642340
Committed by
Albert ARIBAUD
1 parent
981219eebe
Exists in
v2017.01-smarct4x
and in
37 other branches
dtt: add ds620 support
Signed-off-by: Albert ARIBAUD (3ADEV) <albert.aribaud@3adev.fr>
Showing 3 changed files with 74 additions and 7 deletions Side-by-side Diff
drivers/hwmon/Makefile
... | ... | @@ -15,6 +15,7 @@ |
15 | 15 | obj-$(CONFIG_DTT_DS1621) += ds1621.o |
16 | 16 | obj-$(CONFIG_DTT_DS1722) += ds1722.o |
17 | 17 | obj-$(CONFIG_DTT_DS1775) += ds1775.o |
18 | +obj-$(CONFIG_DTT_DS620) += ds620.o | |
18 | 19 | obj-$(CONFIG_DTT_LM63) += lm63.o |
19 | 20 | obj-$(CONFIG_DTT_LM73) += lm73.o |
20 | 21 | obj-$(CONFIG_DTT_LM75) += lm75.o |
drivers/hwmon/ds620.c
1 | +/* | |
2 | + * DS620 DTT support | |
3 | + * | |
4 | + * (C) Copyright 2014 3ADEV <http://www.3adev.com> | |
5 | + * Written-by: Albert ARIBAUD <albert.aribaud@3adev.fr> | |
6 | + * | |
7 | + * SPDX-License-Identifier: GPL-2.0+ | |
8 | + */ | |
9 | + | |
10 | +/* | |
11 | + * Dallas Semiconductor's DS1621/1631 Digital Thermometer and Thermostat. | |
12 | + */ | |
13 | + | |
14 | +#include <common.h> | |
15 | +#include <i2c.h> | |
16 | +#include <dtt.h> | |
17 | + | |
18 | +/* | |
19 | + * Device code | |
20 | + */ | |
21 | +#define DTT_I2C_DEV_CODE 0x48 | |
22 | +#define DTT_START_CONVERT 0x51 | |
23 | +#define DTT_TEMP 0xAA | |
24 | +#define DTT_CONFIG 0xAC | |
25 | + | |
26 | +/* | |
27 | + * Config register MSB bits | |
28 | + */ | |
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 | |
37 | + | |
38 | +#define CHIP(sensor) (DTT_I2C_DEV_CODE + (sensor & 0x07)) | |
39 | + | |
40 | +int dtt_init_one(int sensor) | |
41 | +{ | |
42 | + uint8_t config = DTT_CONFIG_1SHOT | |
43 | + | DTT_CONFIG_R0 | |
44 | + | DTT_CONFIG_R1; | |
45 | + return i2c_write(CHIP(sensor), DTT_CONFIG, 1, &config, 1); | |
46 | +} | |
47 | + | |
48 | +int dtt_get_temp(int sensor) | |
49 | +{ | |
50 | + uint8_t status; | |
51 | + uint8_t temp[2]; | |
52 | + | |
53 | + /* Start a conversion, may take up to 1 second. */ | |
54 | + i2c_write(CHIP(sensor), DTT_START_CONVERT, 1, NULL, 0); | |
55 | + do { | |
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 */ | |
63 | + | |
64 | + return ((int16_t)(temp[1] | (temp[0] << 8))) >> 7; | |
65 | +} |
include/dtt.h
... | ... | @@ -12,13 +12,14 @@ |
12 | 12 | #define _DTT_H_ |
13 | 13 | |
14 | 14 | #if defined(CONFIG_DTT_ADM1021) || \ |
15 | - defined(CONFIG_DTT_ADT7460) || \ | |
16 | - defined(CONFIG_DTT_DS1621) || \ | |
17 | - defined(CONFIG_DTT_DS1775) || \ | |
18 | - defined(CONFIG_DTT_LM63) || \ | |
19 | - defined(CONFIG_DTT_LM73) || \ | |
20 | - defined(CONFIG_DTT_LM75) || \ | |
21 | - defined(CONFIG_DTT_LM81) | |
15 | + defined(CONFIG_DTT_ADT7460) || \ | |
16 | + defined(CONFIG_DTT_DS1621) || \ | |
17 | + defined(CONFIG_DTT_DS1775) || \ | |
18 | + defined(CONFIG_DTT_DS620) || \ | |
19 | + defined(CONFIG_DTT_LM63) || \ | |
20 | + defined(CONFIG_DTT_LM73) || \ | |
21 | + defined(CONFIG_DTT_LM75) || \ | |
22 | + defined(CONFIG_DTT_LM81) | |
22 | 23 | |
23 | 24 | #define CONFIG_DTT /* We have a DTT */ |
24 | 25 |