3 * Erik Theisen, Wave 7 Optics, etheisen@mindspring.com
5 * SPDX-License-Identifier: GPL-2.0+
15 #include <linux/bug.h>
17 #if defined CONFIG_DTT_SENSORS
18 static unsigned long sensor_initialized;
20 static void _initialize_dtt(void)
23 unsigned char sensors[] = CONFIG_DTT_SENSORS;
25 for (i = 0; i < sizeof(sensors); i++) {
26 if ((sensor_initialized & (1 << i)) == 0) {
27 if (dtt_init_one(sensors[i]) != 0) {
28 printf("DTT%d: Failed init!\n", i);
31 sensor_initialized |= (1 << i);
40 /* switch to correct I2C bus */
41 old_bus = I2C_GET_BUS();
42 I2C_SET_BUS(CONFIG_SYS_DTT_BUS_NUM);
46 /* switch back to original I2C bus */
53 #if defined CONFIG_DTT_SENSORS
55 unsigned char sensors[] = CONFIG_DTT_SENSORS;
58 /* Force a compilation error, if there are more then 32 sensors */
59 BUILD_BUG_ON(sizeof(sensors) > 32);
60 /* switch to correct I2C bus */
62 old_bus = i2c_get_bus_num();
63 i2c_set_bus_num(CONFIG_SYS_DTT_BUS_NUM);
65 old_bus = I2C_GET_BUS();
66 I2C_SET_BUS(CONFIG_SYS_DTT_BUS_NUM);
72 * Loop through sensors, read
73 * temperature, and output it.
75 for (i = 0; i < sizeof(sensors); i++)
76 printf("DTT%d: %i C\n", i + 1, dtt_get_temp(sensors[i]));
78 /* switch back to original I2C bus */
80 i2c_set_bus_num(old_bus);
91 #if defined CONFIG_TMU_CMD_DTT
94 /* Sense and return latest thermal info */
95 if (tmu_monitor(&cur_temp) == TMU_STATUS_INIT) {
96 puts("TMU is in unknown state, temperature is invalid\n");
99 printf("Current temperature: %u degrees Celsius\n", cur_temp);
104 int do_dtt(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
114 /***************************************************/
118 "Read temperature from Digital Thermometer and Thermostat",