WATCHDOG_RESET ();
-#if defined(CONFIG_DTT) /* Digital Thermometers and Thermostats */
- dtt_init ();
-#endif
#if defined(CONFIG_CMD_SCSI)
WATCHDOG_RESET ();
puts ("SCSI: ");
#include <dtt.h>
#include <i2c.h>
+static unsigned long sensor_initialized;
+
int do_dtt (cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
{
int i;
unsigned char sensors[] = CONFIG_DTT_SENSORS;
int old_bus;
+ /* Force a compilation error, if there are more then 32 sensors */
+ BUILD_BUG_ON(sizeof(sensors) > 32);
/* switch to correct I2C bus */
old_bus = I2C_GET_BUS();
I2C_SET_BUS(CONFIG_SYS_DTT_BUS_NUM);
* Loop through sensors, read
* temperature, and output it.
*/
- for (i = 0; i < sizeof (sensors); i++)
- printf ("DTT%d: %i C\n", i + 1, dtt_get_temp (sensors[i]));
+ 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!\n", i);
+ continue;
+ }
+ sensor_initialized |= (1 << i);
+ }
+ printf("DTT%d: %i C\n", i + 1, dtt_get_temp(sensors[i]));
+ }
/* switch back to original I2C bus */
I2C_SET_BUS(old_bus);
return 0;
} /* dtt_write() */
-static int
-_dtt_init (int sensor)
+int
+dtt_init_one(int sensor)
{
dtt_cfg_t *dcp = &dttcfg[sensor >> 1];
int reg, val;
return 1;
return 0;
-} /* _dtt_init() */
-
-int
-dtt_init (void)
-{
- int i;
- unsigned char sensors[] = CONFIG_DTT_SENSORS;
- const char *const header = "DTT: ";
-
- /* switch to correct I2C bus */
- I2C_SET_BUS(CONFIG_SYS_DTT_BUS_NUM);
-
- for (i = 0; i < sizeof(sensors); i++) {
- if (_dtt_init(sensors[i]) != 0)
- printf ("%s%d FAILED INIT\n", header, i+1);
- else
- printf ("%s%d is %i C\n", header, i+1,
- dtt_get_temp(sensors[i]));
- }
-
- return (0);
-} /* dtt_init() */
+} /* dtt_init_one() */
int
dtt_get_temp (int sensor)
return 0;
}
-int dtt_init(void)
+int dtt_init_one(int sensor)
{
printf("ADT7460 at I2C address 0x%2x\n", ADT7460_ADDRESS);
}
-static int _dtt_init(int sensor)
+int dtt_init_one(int sensor)
{
int val;
return 0;
}
-
-int dtt_init (void)
-{
- int i;
- unsigned char sensors[] = CONFIG_DTT_SENSORS;
-
- for (i = 0; i < sizeof(sensors); i++) {
- if (_dtt_init(sensors[i]) != 0)
- printf("DTT%d: FAILED\n", i + 1);
- else
- printf("DTT%d: %i C\n", i + 1, dtt_get_temp(sensors[i]));
- }
-
- return (0);
-}
-
-
int dtt_get_temp(int sensor)
{
int i;
}
-static int _dtt_init(int sensor)
+int dtt_init_one(int sensor)
{
int val;
return 0;
}
-
-int dtt_init (void)
-{
- int i;
- unsigned char sensors[] = CONFIG_DTT_SENSORS;
-
- for (i = 0; i < sizeof(sensors); i++) {
- if (_dtt_init(sensors[i]) != 0)
- printf("DTT%d: FAILED\n", i+1);
- else
- printf("DTT%d: %i C\n", i+1, dtt_get_temp(sensors[i]));
- }
-
- return (0);
-}
-
-
int dtt_get_temp(int sensor)
{
return (dtt_read(sensor, DTT_READ_TEMP) / 256);
return sensor && (sensor != DTT_I2C_LM63_ADDR);
}
-static int _dtt_init(int sensor)
+int dtt_init_one(int sensor)
{
int i;
int val;
/* Ignore LSB for now, U-Boot only prints natural numbers */
return temp >> 8;
}
-
-int dtt_init(void)
-{
- int i;
- unsigned char sensors[] = CONFIG_DTT_SENSORS;
- const char *const header = "DTT: ";
-
- for (i = 0; i < sizeof(sensors); i++) {
- if (_dtt_init(sensors[i]) != 0)
- printf("%s%d FAILED INIT\n", header, i + 1);
- else
- printf("%s%d is %i C\n", header, i + 1,
- dtt_get_temp(sensors[i]));
- }
-
- return 0;
-}
dlen);
} /* dtt_write() */
-static int _dtt_init(int const sensor)
+int dtt_init_one(int const sensor)
{
int val;
dtt_read(sensor, DTT_CONTROL); /* clear temperature flags */
return 0;
-} /* _dtt_init() */
-
-int dtt_init(void)
-{
- int i;
- unsigned char sensors[] = CONFIG_DTT_SENSORS;
- const char *const header = "DTT: ";
-
- for (i = 0; i < sizeof(sensors); i++) {
- if (0 != _dtt_init(sensors[i]))
- printf("%s%d FAILED INIT\n", header, i + 1);
- else
- printf("%s%d is %i C\n", header, i + 1,
- dtt_get_temp(sensors[i]));
- }
- return 0;
-} /* dtt_init() */
+} /* dtt_init_one() */
int dtt_get_temp(int const sensor)
{
} /* dtt_write() */
-static int _dtt_init(int sensor)
+int dtt_init_one(int sensor)
{
int val;
return 1;
return 0;
-} /* _dtt_init() */
-
-
-int dtt_init (void)
-{
- int i;
- unsigned char sensors[] = CONFIG_DTT_SENSORS;
- const char *const header = "DTT: ";
- int old_bus;
-
- /* switch to correct I2C bus */
- old_bus = I2C_GET_BUS();
- I2C_SET_BUS(CONFIG_SYS_DTT_BUS_NUM);
-
- for (i = 0; i < sizeof(sensors); i++) {
- if (_dtt_init(sensors[i]) != 0)
- printf("%s%d FAILED INIT\n", header, i+1);
- else
- printf("%s%d is %i C\n", header, i+1,
- dtt_get_temp(sensors[i]));
- }
- /* switch back to original I2C bus */
- I2C_SET_BUS(old_bus);
-
- return (0);
-} /* dtt_init() */
+} /* dtt_init_one() */
int dtt_get_temp(int sensor)
{
#define DTT_CONFIG 0x40
#define DTT_ADR 0x48
-static int _dtt_init(int sensor)
+int dtt_init_one(int sensor)
{
int man;
int adr;
debug ("DTT: Found LM81@%x Rev: %d\n", adr, rev);
return 0;
-} /* _dtt_init() */
+} /* dtt_init_one() */
-int dtt_init (void)
-{
- int i;
- unsigned char sensors[] = CONFIG_DTT_SENSORS;
- const char *const header = "DTT: ";
-
- for (i = 0; i < sizeof(sensors); i++) {
- if (_dtt_init(sensors[i]) != 0)
- printf("%s%d FAILED INIT\n", header, i+1);
- else
- printf("%s%d is %i C\n", header, i+1,
- dtt_get_temp(sensors[i]));
- }
-
- return (0);
-} /* dtt_init() */
-
#define TEMP_FROM_REG(temp) \
((temp)<256?((((temp)&0x1fe) >> 1) * 10) + ((temp) & 1) * 5: \
((((temp)&0x1fe) >> 1) -255) * 10 - ((temp) & 1) * 5) \
#endif
#endif /* CONFIG_DTT_ADM1021 */
-extern int dtt_init (void);
+extern int dtt_init_one(int);
extern int dtt_read(int sensor, int reg);
extern int dtt_write(int sensor, int reg, int val);
extern int dtt_get_temp(int sensor);