]> git.ipfire.org Git - people/ms/u-boot.git/blame - cmd/dtt.c
cmd: Kconfig: Add a Kconfig options for a few CMD
[people/ms/u-boot.git] / cmd / dtt.c
CommitLineData
3863585b
WD
1/*
2 * (C) Copyright 2001
3 * Erik Theisen, Wave 7 Optics, etheisen@mindspring.com
4 *
3765b3e7 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>
84b8bf6d 15#include <linux/bug.h>
3863585b 16
bc5478b2 17#if defined CONFIG_DTT_SENSORS
780f13a9
HS
18static unsigned long sensor_initialized;
19
b88e7b3c
DE
20static void _initialize_dtt(void)
21{
22 int i;
23 unsigned char sensors[] = CONFIG_DTT_SENSORS;
24
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);
29 continue;
30 }
31 sensor_initialized |= (1 << i);
32 }
33 }
34}
35
36void dtt_init(void)
37{
38 int old_bus;
39
40 /* switch to correct I2C bus */
41 old_bus = I2C_GET_BUS();
42 I2C_SET_BUS(CONFIG_SYS_DTT_BUS_NUM);
43
44 _initialize_dtt();
45
46 /* switch back to original I2C bus */
47 I2C_SET_BUS(old_bus);
48}
bc5478b2 49#endif
b88e7b3c 50
bc5478b2 51int dtt_i2c(void)
3863585b 52{
bc5478b2 53#if defined CONFIG_DTT_SENSORS
3863585b
WD
54 int i;
55 unsigned char sensors[] = CONFIG_DTT_SENSORS;
0dc018ec
SR
56 int old_bus;
57
780f13a9
HS
58 /* Force a compilation error, if there are more then 32 sensors */
59 BUILD_BUG_ON(sizeof(sensors) > 32);
0dc018ec 60 /* switch to correct I2C bus */
3f4978c7
HS
61#ifdef CONFIG_SYS_I2C
62 old_bus = i2c_get_bus_num();
63 i2c_set_bus_num(CONFIG_SYS_DTT_BUS_NUM);
64#else
0dc018ec 65 old_bus = I2C_GET_BUS();
6d0f6bcf 66 I2C_SET_BUS(CONFIG_SYS_DTT_BUS_NUM);
3f4978c7 67#endif
3863585b 68
b88e7b3c
DE
69 _initialize_dtt();
70
3863585b
WD
71 /*
72 * Loop through sensors, read
73 * temperature, and output it.
74 */
b88e7b3c 75 for (i = 0; i < sizeof(sensors); i++)
780f13a9 76 printf("DTT%d: %i C\n", i + 1, dtt_get_temp(sensors[i]));
0dc018ec
SR
77
78 /* switch back to original I2C bus */
3f4978c7
HS
79#ifdef CONFIG_SYS_I2C
80 i2c_set_bus_num(old_bus);
81#else
0dc018ec 82 I2C_SET_BUS(old_bus);
3f4978c7 83#endif
bc5478b2 84#endif
3863585b
WD
85
86 return 0;
bc5478b2
AS
87}
88
89int dtt_tmu(void)
90{
91#if defined CONFIG_TMU_CMD_DTT
92 int cur_temp;
93
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");
97 return -1;
98 }
99 printf("Current temperature: %u degrees Celsius\n", cur_temp);
100#endif
101 return 0;
102}
103
104int do_dtt(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
105{
106 int err = 0;
107
108 err |= dtt_i2c();
109 err |= dtt_tmu();
110
111 return err;
3863585b
WD
112} /* do_dtt() */
113
8bde7f77
WD
114/***************************************************/
115
0d498393
WD
116U_BOOT_CMD(
117 dtt, 1, 1, do_dtt,
a89c33db
WD
118 "Read temperature from Digital Thermometer and Thermostat",
119 ""
8bde7f77 120);