From mboxrd@z Thu Jan 1 00:00:00 1970 From: Heiko Schocher Date: Thu, 09 Dec 2010 16:45:15 +0100 Subject: [U-Boot] [PATCH][NEXT] hwmon: do not init sensors on startup In-Reply-To: <20101209142643.2D162D08A93@gemini.denx.de> References: <1291903238-29071-1-git-send-email-hs@denx.de> <20101209142643.2D162D08A93@gemini.denx.de> Message-ID: <4D00F98B.1010507@denx.de> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de Hello Wolfgang, Wolfgang Denk wrote: > In message <1291903238-29071-1-git-send-email-hs@denx.de> you wrote: >> --- a/common/cmd_dtt.c >> +++ b/common/cmd_dtt.c >> @@ -28,6 +28,8 @@ >> #include >> #include >> >> +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