Patchwork [U-Boot,6/9,v8] TMU: Add TMU support in dtt command

login
register
mail settings
Submitter Akshay Saraswat
Date Feb. 5, 2013, 11:57 a.m.
Message ID <1360065437-4517-7-git-send-email-akshay.s@samsung.com>
Download mbox | patch
Permalink /patch/218248/
State Superseded
Delegated to: Minkyu Kang
Headers show

Comments

Akshay Saraswat - Feb. 5, 2013, 11:57 a.m.
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@samsung.com>
---
Changes since v7:
	- Made sensor_initialized static again.
	- Changed return type to int in dtt_init declaration.

 common/cmd_dtt.c |   63 ++++++++++++++++++++++++++++++++----------------------
 include/dtt.h    |    2 +-
 2 files changed, 38 insertions(+), 27 deletions(-)
Simon Glass - Feb. 5, 2013, 4:55 p.m.
Hi Akshay,

On Tue, Feb 5, 2013 at 3:57 AM, Akshay Saraswat <akshay.s@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@samsung.com>
> ---
> Changes since v7:
>         - Made sensor_initialized static again.
>         - Changed return type to int in dtt_init declaration.
>
>  common/cmd_dtt.c |   63 ++++++++++++++++++++++++++++++++----------------------
>  include/dtt.h    |    2 +-
>  2 files changed, 38 insertions(+), 27 deletions(-)
>
> diff --git a/common/cmd_dtt.c b/common/cmd_dtt.c
> index cd94423..799e1c7 100644
> --- a/common/cmd_dtt.c
> +++ b/common/cmd_dtt.c
> @@ -27,52 +27,52 @@
>
>  #include <dtt.h>
>  #include <i2c.h>
> +#include <tmu.h>
>
> +#if defined CONFIG_DTT_SENSORS
>  static unsigned long sensor_initialized;
> +#endif
>
> -static void _initialize_dtt(void)
> +int dtt_tmu(void)
>  {
> -       int i;
> -       unsigned char sensors[] = CONFIG_DTT_SENSORS;
> +#if defined CONFIG_TMU_CMD_DTT
> +       int cur_temp;
>
> -       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);
> -               }
> +       /* 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;
>         }
> -}
> -
> -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();
> +       printf("Current temperature: %u degrees Celsius\n", cur_temp);
> +#endif
>
> -       /* switch back to original I2C bus */
> -       I2C_SET_BUS(old_bus);
> +       return 0;
>  }
>
> -int do_dtt (cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
> +int dtt_init(void)

I think this function is supposed to initialize the sensors but you
have changed it to print them out. Other places call this function and
likely rely on the current behaviour.

I think all you need to do is:

- leave the two _initialize_dtt() and init_dtt() functions as they were
- put the code for the old dtt command into a function, like
dtt_i2c(), but leave it largely as is

Really then all you are doing is putting the current code in do_dtt()
into a dtt_i2c() function, and adding calls to dtt_i2c() and dtt_tmu()
from the now-empty do_dtt(). You actually have do_dtt() correct below,
although I suggest dtt_i2c() is a better name for the function than
dtt_init().

It is unfortunate that the existing code is so fixed-purpose, and not
particularly clean, but this approach should allow you to do what you
need.

>  {
> +#if defined CONFIG_DTT_SENSORS
>         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);
>
> -       _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 +83,19 @@ 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;
> +
> +       err |= dtt_init();
> +       err |= dtt_tmu();
> +
> +       return err;
>  }      /* do_dtt() */
>
>  /***************************************************/
> diff --git a/include/dtt.h b/include/dtt.h
> index 6d5534d..94fbce3 100644
> --- a/include/dtt.h
> +++ b/include/dtt.h
> @@ -52,7 +52,7 @@
>  #endif
>  #endif /* CONFIG_DTT_ADM1021 */
>
> -extern void dtt_init(void);
> +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);
> --
> 1.7.9.5
>

Regards,
Simon

Patch

diff --git a/common/cmd_dtt.c b/common/cmd_dtt.c
index cd94423..799e1c7 100644
--- a/common/cmd_dtt.c
+++ b/common/cmd_dtt.c
@@ -27,52 +27,52 @@ 
 
 #include <dtt.h>
 #include <i2c.h>
+#include <tmu.h>
 
+#if defined CONFIG_DTT_SENSORS
 static unsigned long sensor_initialized;
+#endif
 
-static void _initialize_dtt(void)
+int dtt_tmu(void)
 {
-	int i;
-	unsigned char sensors[] = CONFIG_DTT_SENSORS;
+#if defined CONFIG_TMU_CMD_DTT
+	int cur_temp;
 
-	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);
-		}
+	/* 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;
 	}
-}
-
-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();
+	printf("Current temperature: %u degrees Celsius\n", cur_temp);
+#endif
 
-	/* switch back to original I2C bus */
-	I2C_SET_BUS(old_bus);
+	return 0;
 }
 
-int do_dtt (cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
+int dtt_init(void)
 {
+#if defined CONFIG_DTT_SENSORS
 	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);
 
-	_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 +83,19 @@  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;
+
+	err |= dtt_init();
+	err |= dtt_tmu();
+
+	return err;
 }	/* do_dtt() */
 
 /***************************************************/
diff --git a/include/dtt.h b/include/dtt.h
index 6d5534d..94fbce3 100644
--- a/include/dtt.h
+++ b/include/dtt.h
@@ -52,7 +52,7 @@ 
 #endif
 #endif /* CONFIG_DTT_ADM1021 */
 
-extern void dtt_init(void);
+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);