[U-Boot] [PATCH 6/9 v7] TMU: Add TMU support in dtt command
Simon Glass
sjg at chromium.org
Mon Feb 4 22:14:13 CET 2013
Hi Akshay,
On Mon, Jan 28, 2013 at 3:26 AM, Akshay Saraswat <akshay.s at samsung.com> wrote:
> Add generic TMU support alongwith i2c sensors in dtt command
> to enable temperature reading in cases where TMU is present
> instead of i2c sensors.
>
> Signed-off-by: Akshay Saraswat <akshay.s at samsung.com>
This looks fine to me except for a minor issue - please see below.
> ---
> Changes since v6:
> - Integrated old code into one function to support both tmu and i2c-dtt.
>
> common/cmd_dtt.c | 72 +++++++++++++++++++++++++++++++-----------------------
> 1 file changed, 42 insertions(+), 30 deletions(-)
>
> diff --git a/common/cmd_dtt.c b/common/cmd_dtt.c
> index cd94423..c7d4ea4 100644
> --- a/common/cmd_dtt.c
> +++ b/common/cmd_dtt.c
> @@ -27,52 +27,51 @@
>
> #include <dtt.h>
> #include <i2c.h>
> +#include <tmu.h>
>
> -static unsigned long sensor_initialized;
> +#if ~defined CONFIG_SYS_DTT_BUS_NUM
> +#define CONFIG_DTT_SENSORS 0
> +#endif
>
> -static void _initialize_dtt(void)
> +int dtt_tmu(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!\n", i);
> - continue;
> - }
> - sensor_initialized |= (1 << i);
> - }
> + 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\n");
> + return -1;
> + } else {
> + printf("Current temperature: %u degrees Celsius\n", cur_temp);
> + return 0;
> }
> }
>
> -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);
> -}
> -
> -int do_dtt (cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
> +int dtt_init(void)
> {
> +#if CONFIG_DTT_SENSORS
> int i;
> - unsigned char sensors[] = CONFIG_DTT_SENSORS;
> int old_bus;
> + unsigned long sensor_initialized;
This should remain a static variable since otherwise it will not be
kept around, and also will be uninitialized. Also please make sure you
MAKEALL a board that uses this code.
> + unsigned char sensors[] = CONFIG_DTT_SENSORS;
>
> /* 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);
>
> - _initialize_dtt();
> + /* Initialize 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!\n", i);
> + continue;
> + }
> + sensor_initialized |= (1 << i);
> + }
> + }
>
> /*
> * Loop through sensors, read
> @@ -83,8 +82,21 @@ int do_dtt (cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
>
> /* switch back to original I2C bus */
> I2C_SET_BUS(old_bus);
> +#endif
>
> return 0;
> +}
> +
> +int do_dtt(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
> +{
> + int err = 0;
> +
> +#if defined CONFIG_TMU_CMD_DTT
> + err |= dtt_tmu();
> +#endif
> + err |= dtt_init();
> +
> + return err;
> } /* do_dtt() */
>
> /***************************************************/
> --
> 1.7.9.5
>
Regards,
Simon
More information about the U-Boot
mailing list