Blame view
common/cmd_dtt.c
2.22 KB
3863585bb Initial revision |
1 2 3 4 |
/* * (C) Copyright 2001 * Erik Theisen, Wave 7 Optics, etheisen@mindspring.com * |
3765b3e7b Coding Style clea... |
5 |
* SPDX-License-Identifier: GPL-2.0+ |
3863585bb Initial revision |
6 7 8 9 10 |
*/ #include <common.h> #include <config.h> #include <command.h> |
3863585bb Initial revision |
11 |
|
3863585bb Initial revision |
12 |
#include <dtt.h> |
0dc018ece [PATCH] I2C: Add ... |
13 |
#include <i2c.h> |
bc5478b27 TMU: Add TMU supp... |
14 |
#include <tmu.h> |
3863585bb Initial revision |
15 |
|
bc5478b27 TMU: Add TMU supp... |
16 |
#if defined CONFIG_DTT_SENSORS |
780f13a9e hwmon: do not ini... |
17 |
static unsigned long sensor_initialized; |
b88e7b3cc hwmon: Provide dt... |
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
static void _initialize_dtt(void) { int i; unsigned char sensors[] = CONFIG_DTT_SENSORS; for (i = 0; i < sizeof(sensors); i++) { if ((sensor_initialized & (1 << i)) == 0) { if (dtt_init_one(sensors[i]) != 0) { printf("DTT%d: Failed init! ", i); continue; } sensor_initialized |= (1 << i); } } } void dtt_init(void) { int old_bus; /* switch to correct I2C bus */ old_bus = I2C_GET_BUS(); I2C_SET_BUS(CONFIG_SYS_DTT_BUS_NUM); _initialize_dtt(); /* switch back to original I2C bus */ I2C_SET_BUS(old_bus); } |
bc5478b27 TMU: Add TMU supp... |
48 |
#endif |
b88e7b3cc hwmon: Provide dt... |
49 |
|
bc5478b27 TMU: Add TMU supp... |
50 |
int dtt_i2c(void) |
3863585bb Initial revision |
51 |
{ |
bc5478b27 TMU: Add TMU supp... |
52 |
#if defined CONFIG_DTT_SENSORS |
3863585bb Initial revision |
53 54 |
int i; unsigned char sensors[] = CONFIG_DTT_SENSORS; |
0dc018ece [PATCH] I2C: Add ... |
55 |
int old_bus; |
780f13a9e hwmon: do not ini... |
56 57 |
/* Force a compilation error, if there are more then 32 sensors */ BUILD_BUG_ON(sizeof(sensors) > 32); |
0dc018ece [PATCH] I2C: Add ... |
58 |
/* switch to correct I2C bus */ |
3f4978c71 i2c: common chang... |
59 60 61 62 |
#ifdef CONFIG_SYS_I2C old_bus = i2c_get_bus_num(); i2c_set_bus_num(CONFIG_SYS_DTT_BUS_NUM); #else |
0dc018ece [PATCH] I2C: Add ... |
63 |
old_bus = I2C_GET_BUS(); |
6d0f6bcf3 rename CFG_ macro... |
64 |
I2C_SET_BUS(CONFIG_SYS_DTT_BUS_NUM); |
3f4978c71 i2c: common chang... |
65 |
#endif |
3863585bb Initial revision |
66 |
|
b88e7b3cc hwmon: Provide dt... |
67 |
_initialize_dtt(); |
3863585bb Initial revision |
68 69 70 71 |
/* * Loop through sensors, read * temperature, and output it. */ |
b88e7b3cc hwmon: Provide dt... |
72 |
for (i = 0; i < sizeof(sensors); i++) |
780f13a9e hwmon: do not ini... |
73 74 |
printf("DTT%d: %i C ", i + 1, dtt_get_temp(sensors[i])); |
0dc018ece [PATCH] I2C: Add ... |
75 76 |
/* switch back to original I2C bus */ |
3f4978c71 i2c: common chang... |
77 78 79 |
#ifdef CONFIG_SYS_I2C i2c_set_bus_num(old_bus); #else |
0dc018ece [PATCH] I2C: Add ... |
80 |
I2C_SET_BUS(old_bus); |
bc5478b27 TMU: Add TMU supp... |
81 |
#endif |
3f4978c71 i2c: common chang... |
82 |
#endif |
3863585bb Initial revision |
83 84 |
return 0; |
bc5478b27 TMU: Add TMU supp... |
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
} int dtt_tmu(void) { #if defined CONFIG_TMU_CMD_DTT int cur_temp; /* Sense and return latest thermal info */ if (tmu_monitor(&cur_temp) == TMU_STATUS_INIT) { puts("TMU is in unknown state, temperature is invalid "); return -1; } printf("Current temperature: %u degrees Celsius ", cur_temp); #endif return 0; } int do_dtt(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[]) { int err = 0; err |= dtt_i2c(); err |= dtt_tmu(); return err; |
3863585bb Initial revision |
112 |
} /* do_dtt() */ |
8bde7f776 * Code cleanup: |
113 |
/***************************************************/ |
0d4983930 Patch by Kenneth ... |
114 115 |
U_BOOT_CMD( dtt, 1, 1, do_dtt, |
a89c33db9 General help mess... |
116 117 |
"Read temperature from Digital Thermometer and Thermostat", "" |
8bde7f776 * Code cleanup: |
118 |
); |