[U-Boot] [PATCH][NEXT] hwmon: do not init sensors on startup
Heiko Schocher
hs at denx.de
Thu Dec 9 16:45:15 CET 2010
Hello Wolfgang,
Wolfgang Denk wrote:
> In message <1291903238-29071-1-git-send-email-hs at denx.de> you wrote:
>> --- a/common/cmd_dtt.c
>> +++ b/common/cmd_dtt.c
>> @@ -28,6 +28,8 @@
>> #include <dtt.h>
>> #include <i2c.h>
>>
>> +static unsigned long sensors_init_done = 0;
>
> What if there are more then 32 sensors?
Ok, that would not work ... Hmm.. I can get the number of DTTs on a board
with ARRAY_SIZE(CONFIG_DTT_SENSORS) ... should I use this info to allocate
an array, which stores the info, if the DTTs are initialized?
>> int do_dtt (cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
>> {
>> int i;
>> @@ -42,8 +44,16 @@ int do_dtt (cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
>> * 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 ((sensors_init_done & (1 << i)) != (1 << i)) {
>> + if (dtt_init_one(sensors[i]) == 0)
>> + sensors_init_done |= (1 << i);
>> + else
>> + printf("DTT%d: Failed init!\n", i);
>> + }
>> + if ((sensors_init_done & (1 << i)) == (1 << i))
>> + printf ("DTT%d: %i C\n", i + 1, dtt_get_temp(sensors[i]));
>> + }
>
> This is overly complicated, it seems. Why not:
>
> for (i = 0; i < sizeof(sensors); i++) {
> if ((sensors_init_done & (1 << i)) == 0) {
> if (dtt_init_one(sensors[i]) != 0) {
> printf("DTT%d: init failed\n", i);
> continue;
> }
> sensors_init_done |= (1 << i);
> }
>
> printf("DTT%d: %i C\n", i + 1, dtt_get_temp(sensors[i]));
> }
Yep, that looks better, change this in v2.
bye,
Heiko
--
DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
More information about the U-Boot
mailing list