]>
Commit | Line | Data |
---|---|---|
3863585b WD |
1 | /* |
2 | * (C) Copyright 2001 | |
3 | * Erik Theisen, Wave 7 Optics, etheisen@mindspring.com | |
4 | * | |
1a459660 | 5 | * SPDX-License-Identifier: GPL-2.0+ |
3863585b WD |
6 | */ |
7 | ||
8 | #include <common.h> | |
9 | #include <config.h> | |
10 | #include <command.h> | |
3863585b | 11 | |
3863585b | 12 | #include <dtt.h> |
0dc018ec | 13 | #include <i2c.h> |
bc5478b2 | 14 | #include <tmu.h> |
3863585b | 15 | |
bc5478b2 | 16 | #if defined CONFIG_DTT_SENSORS |
780f13a9 HS |
17 | static unsigned long sensor_initialized; |
18 | ||
b88e7b3c DE |
19 | static void _initialize_dtt(void) |
20 | { | |
21 | int i; | |
22 | unsigned char sensors[] = CONFIG_DTT_SENSORS; | |
23 | ||
24 | for (i = 0; i < sizeof(sensors); i++) { | |
25 | if ((sensor_initialized & (1 << i)) == 0) { | |
26 | if (dtt_init_one(sensors[i]) != 0) { | |
27 | printf("DTT%d: Failed init!\n", i); | |
28 | continue; | |
29 | } | |
30 | sensor_initialized |= (1 << i); | |
31 | } | |
32 | } | |
33 | } | |
34 | ||
35 | void dtt_init(void) | |
36 | { | |
37 | int old_bus; | |
38 | ||
39 | /* switch to correct I2C bus */ | |
40 | old_bus = I2C_GET_BUS(); | |
41 | I2C_SET_BUS(CONFIG_SYS_DTT_BUS_NUM); | |
42 | ||
43 | _initialize_dtt(); | |
44 | ||
45 | /* switch back to original I2C bus */ | |
46 | I2C_SET_BUS(old_bus); | |
47 | } | |
bc5478b2 | 48 | #endif |
b88e7b3c | 49 | |
bc5478b2 | 50 | int dtt_i2c(void) |
3863585b | 51 | { |
bc5478b2 | 52 | #if defined CONFIG_DTT_SENSORS |
3863585b WD |
53 | int i; |
54 | unsigned char sensors[] = CONFIG_DTT_SENSORS; | |
0dc018ec SR |
55 | int old_bus; |
56 | ||
780f13a9 HS |
57 | /* Force a compilation error, if there are more then 32 sensors */ |
58 | BUILD_BUG_ON(sizeof(sensors) > 32); | |
0dc018ec SR |
59 | /* switch to correct I2C bus */ |
60 | old_bus = I2C_GET_BUS(); | |
6d0f6bcf | 61 | I2C_SET_BUS(CONFIG_SYS_DTT_BUS_NUM); |
3863585b | 62 | |
b88e7b3c DE |
63 | _initialize_dtt(); |
64 | ||
3863585b WD |
65 | /* |
66 | * Loop through sensors, read | |
67 | * temperature, and output it. | |
68 | */ | |
b88e7b3c | 69 | for (i = 0; i < sizeof(sensors); i++) |
780f13a9 | 70 | printf("DTT%d: %i C\n", i + 1, dtt_get_temp(sensors[i])); |
0dc018ec SR |
71 | |
72 | /* switch back to original I2C bus */ | |
73 | I2C_SET_BUS(old_bus); | |
bc5478b2 | 74 | #endif |
3863585b WD |
75 | |
76 | return 0; | |
bc5478b2 AS |
77 | } |
78 | ||
79 | int dtt_tmu(void) | |
80 | { | |
81 | #if defined CONFIG_TMU_CMD_DTT | |
82 | int cur_temp; | |
83 | ||
84 | /* Sense and return latest thermal info */ | |
85 | if (tmu_monitor(&cur_temp) == TMU_STATUS_INIT) { | |
86 | puts("TMU is in unknown state, temperature is invalid\n"); | |
87 | return -1; | |
88 | } | |
89 | printf("Current temperature: %u degrees Celsius\n", cur_temp); | |
90 | #endif | |
91 | return 0; | |
92 | } | |
93 | ||
94 | int do_dtt(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[]) | |
95 | { | |
96 | int err = 0; | |
97 | ||
98 | err |= dtt_i2c(); | |
99 | err |= dtt_tmu(); | |
100 | ||
101 | return err; | |
3863585b WD |
102 | } /* do_dtt() */ |
103 | ||
8bde7f77 WD |
104 | /***************************************************/ |
105 | ||
0d498393 WD |
106 | U_BOOT_CMD( |
107 | dtt, 1, 1, do_dtt, | |
a89c33db WD |
108 | "Read temperature from Digital Thermometer and Thermostat", |
109 | "" | |
8bde7f77 | 110 | ); |