diff mbox series

[U-Boot,6/8] imx8: cpu: get temperature when print cpu desc

Message ID 20190412080741.32412-6-peng.fan@nxp.com
State Superseded
Delegated to: Stefano Babic
Headers show
Series [U-Boot,1/8] imx: sip: add call_imx_sip_ret2 | expand

Commit Message

Peng Fan April 12, 2019, 7:55 a.m. UTC
Read the temperature when print cpu inforation.

Signed-off-by: Peng Fan <peng.fan@nxp.com>
---
 arch/arm/mach-imx/imx8/cpu.c | 35 +++++++++++++++++++++++++++++++++--
 1 file changed, 33 insertions(+), 2 deletions(-)

Comments

Stefano Babic April 25, 2019, 10:35 a.m. UTC | #1
Hi Peng,

On 12/04/19 09:55, Peng Fan wrote:
> Read the temperature when print cpu inforation.
> 
> Signed-off-by: Peng Fan <peng.fan@nxp.com>
> ---
>  arch/arm/mach-imx/imx8/cpu.c | 35 +++++++++++++++++++++++++++++++++--
>  1 file changed, 33 insertions(+), 2 deletions(-)
> 
> diff --git a/arch/arm/mach-imx/imx8/cpu.c b/arch/arm/mach-imx/imx8/cpu.c
> index 4bbc956f9d..25b010489b 100644
> --- a/arch/arm/mach-imx/imx8/cpu.c
> +++ b/arch/arm/mach-imx/imx8/cpu.c
> @@ -11,6 +11,7 @@
>  #include <dm/lists.h>
>  #include <dm/uclass.h>
>  #include <errno.h>
> +#include <thermal.h>
>  #include <asm/arch/sci/sci.h>
>  #include <asm/arch/sys_proto.h>
>  #include <asm/arch-imx/cpu.h>
> @@ -571,15 +572,45 @@ const char *get_core_name(void)
>  		return "?";
>  }
>  
> +#if defined(CONFIG_IMX_SCU_THERMAL)
> +static int cpu_imx_get_temp(void)
> +{

This generates a warning when CONFIG_IMX_SCU_THERMAL is not set, because
it is called later:

> +	struct udevice *thermal_dev;
> +	int cpu_tmp, ret;
> +
> +	ret = uclass_get_device_by_name(UCLASS_THERMAL, "cpu-thermal0",
> +					&thermal_dev);
> +
> +	if (!ret) {
> +		ret = thermal_get_temp(thermal_dev, &cpu_tmp);
> +		if (ret)
> +			return 0xdeadbeef;
> +	} else {
> +		return 0xdeadbeef;
> +	}
> +
> +	return cpu_tmp;
> +}
> +#endif
> +
>  int cpu_imx_get_desc(struct udevice *dev, char *buf, int size)
>  {
>  	struct cpu_imx_platdata *plat = dev_get_platdata(dev);
> +	int ret;
>  
>  	if (size < 100)
>  		return -ENOSPC;
>  
> -	snprintf(buf, size, "NXP i.MX8%s Rev%s %s at %u MHz\n",
> -		 plat->type, plat->rev, plat->name, plat->freq_mhz);
> +	ret = snprintf(buf, size, "NXP i.MX8%s Rev%s %s at %u MHz",
> +		       plat->type, plat->rev, plat->name, plat->freq_mhz);
> +
> +	if (IS_ENABLED(CONFIG_IMX_SCU_THERMAL)) {
> +		buf = buf + ret;
> +		size = size - ret;
> +		ret = snprintf(buf, size, " at %dC", cpu_imx_get_temp());
                                                        ^--- here it is
referenced.

Regards,
Stefano

> +	}
> +
> +	snprintf(buf + ret, size - ret, "\n");
>  
>  	return 0;
>  }
>
Peng Fan April 25, 2019, 1:46 p.m. UTC | #2
Hi Stefano.

> Subject: Re: [PATCH 6/8] imx8: cpu: get temperature when print cpu desc
> 
> Hi Peng,
> 
> On 12/04/19 09:55, Peng Fan wrote:
> > Read the temperature when print cpu inforation.
> >
> > Signed-off-by: Peng Fan <peng.fan@nxp.com>
> > ---
> >  arch/arm/mach-imx/imx8/cpu.c | 35
> +++++++++++++++++++++++++++++++++--
> >  1 file changed, 33 insertions(+), 2 deletions(-)
> >
> > diff --git a/arch/arm/mach-imx/imx8/cpu.c
> > b/arch/arm/mach-imx/imx8/cpu.c index 4bbc956f9d..25b010489b 100644
> > --- a/arch/arm/mach-imx/imx8/cpu.c
> > +++ b/arch/arm/mach-imx/imx8/cpu.c
> > @@ -11,6 +11,7 @@
> >  #include <dm/lists.h>
> >  #include <dm/uclass.h>
> >  #include <errno.h>
> > +#include <thermal.h>
> >  #include <asm/arch/sci/sci.h>
> >  #include <asm/arch/sys_proto.h>
> >  #include <asm/arch-imx/cpu.h>
> > @@ -571,15 +572,45 @@ const char *get_core_name(void)
> >  		return "?";
> >  }
> >
> > +#if defined(CONFIG_IMX_SCU_THERMAL)
> > +static int cpu_imx_get_temp(void)
> > +{
> 
> This generates a warning when CONFIG_IMX_SCU_THERMAL is not set,
> because it is called later:
> 
> > +	struct udevice *thermal_dev;
> > +	int cpu_tmp, ret;
> > +
> > +	ret = uclass_get_device_by_name(UCLASS_THERMAL, "cpu-thermal0",
> > +					&thermal_dev);
> > +
> > +	if (!ret) {
> > +		ret = thermal_get_temp(thermal_dev, &cpu_tmp);
> > +		if (ret)
> > +			return 0xdeadbeef;
> > +	} else {
> > +		return 0xdeadbeef;
> > +	}
> > +
> > +	return cpu_tmp;
> > +}
> > +#endif
> > +
> >  int cpu_imx_get_desc(struct udevice *dev, char *buf, int size)  {
> >  	struct cpu_imx_platdata *plat = dev_get_platdata(dev);
> > +	int ret;
> >
> >  	if (size < 100)
> >  		return -ENOSPC;
> >
> > -	snprintf(buf, size, "NXP i.MX8%s Rev%s %s at %u MHz\n",
> > -		 plat->type, plat->rev, plat->name, plat->freq_mhz);
> > +	ret = snprintf(buf, size, "NXP i.MX8%s Rev%s %s at %u MHz",
> > +		       plat->type, plat->rev, plat->name, plat->freq_mhz);
> > +
> > +	if (IS_ENABLED(CONFIG_IMX_SCU_THERMAL)) {
> > +		buf = buf + ret;
> > +		size = size - ret;
> > +		ret = snprintf(buf, size, " at %dC", cpu_imx_get_temp());
>                                                         ^---

I not able to connect my PC to verify. But just thinking,
When CONFIG_IMX_SCU_THERMAL not enabled, the compiler
should optimize the if block? Because it is just "if (0)"

Regards,
Peng.

> here it is referenced.
> 
> Regards,
> Stefano
> 
> > +	}
> > +
> > +	snprintf(buf + ret, size - ret, "\n");
> >
> >  	return 0;
> >  }
> >
> 
> 
> --
> ==============================================================
> =======
> DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
> HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
> Phone: +49-8142-66989-53 Fax: +49-8142-66989-80 Email: sbabic@denx.de
> ==============================================================
> =======
Stefano Babic April 25, 2019, 2:23 p.m. UTC | #3
On 25/04/19 15:46, Peng Fan wrote:
> Hi Stefano.
> 
>> Subject: Re: [PATCH 6/8] imx8: cpu: get temperature when print cpu desc
>>
>> Hi Peng,
>>
>> On 12/04/19 09:55, Peng Fan wrote:
>>> Read the temperature when print cpu inforation.
>>>
>>> Signed-off-by: Peng Fan <peng.fan@nxp.com>
>>> ---
>>>  arch/arm/mach-imx/imx8/cpu.c | 35
>> +++++++++++++++++++++++++++++++++--
>>>  1 file changed, 33 insertions(+), 2 deletions(-)
>>>
>>> diff --git a/arch/arm/mach-imx/imx8/cpu.c
>>> b/arch/arm/mach-imx/imx8/cpu.c index 4bbc956f9d..25b010489b 100644
>>> --- a/arch/arm/mach-imx/imx8/cpu.c
>>> +++ b/arch/arm/mach-imx/imx8/cpu.c
>>> @@ -11,6 +11,7 @@
>>>  #include <dm/lists.h>
>>>  #include <dm/uclass.h>
>>>  #include <errno.h>
>>> +#include <thermal.h>
>>>  #include <asm/arch/sci/sci.h>
>>>  #include <asm/arch/sys_proto.h>
>>>  #include <asm/arch-imx/cpu.h>
>>> @@ -571,15 +572,45 @@ const char *get_core_name(void)
>>>  		return "?";
>>>  }
>>>
>>> +#if defined(CONFIG_IMX_SCU_THERMAL)
>>> +static int cpu_imx_get_temp(void)
>>> +{
>>
>> This generates a warning when CONFIG_IMX_SCU_THERMAL is not set,
>> because it is called later:
>>
>>> +	struct udevice *thermal_dev;
>>> +	int cpu_tmp, ret;
>>> +
>>> +	ret = uclass_get_device_by_name(UCLASS_THERMAL, "cpu-thermal0",
>>> +					&thermal_dev);
>>> +
>>> +	if (!ret) {
>>> +		ret = thermal_get_temp(thermal_dev, &cpu_tmp);
>>> +		if (ret)
>>> +			return 0xdeadbeef;
>>> +	} else {
>>> +		return 0xdeadbeef;
>>> +	}
>>> +
>>> +	return cpu_tmp;
>>> +}
>>> +#endif
>>> +
>>>  int cpu_imx_get_desc(struct udevice *dev, char *buf, int size)  {
>>>  	struct cpu_imx_platdata *plat = dev_get_platdata(dev);
>>> +	int ret;
>>>
>>>  	if (size < 100)
>>>  		return -ENOSPC;
>>>
>>> -	snprintf(buf, size, "NXP i.MX8%s Rev%s %s at %u MHz\n",
>>> -		 plat->type, plat->rev, plat->name, plat->freq_mhz);
>>> +	ret = snprintf(buf, size, "NXP i.MX8%s Rev%s %s at %u MHz",
>>> +		       plat->type, plat->rev, plat->name, plat->freq_mhz);
>>> +
>>> +	if (IS_ENABLED(CONFIG_IMX_SCU_THERMAL)) {
>>> +		buf = buf + ret;
>>> +		size = size - ret;
>>> +		ret = snprintf(buf, size, " at %dC", cpu_imx_get_temp());
>>                                                         ^---
> 
> I not able to connect my PC to verify. But just thinking,
> When CONFIG_IMX_SCU_THERMAL not enabled, the compiler
> should optimize the if block? Because it is just "if (0)"

But if compiler optimizes the block, I should not see the warning...

Regards,
Stefano
diff mbox series

Patch

diff --git a/arch/arm/mach-imx/imx8/cpu.c b/arch/arm/mach-imx/imx8/cpu.c
index 4bbc956f9d..25b010489b 100644
--- a/arch/arm/mach-imx/imx8/cpu.c
+++ b/arch/arm/mach-imx/imx8/cpu.c
@@ -11,6 +11,7 @@ 
 #include <dm/lists.h>
 #include <dm/uclass.h>
 #include <errno.h>
+#include <thermal.h>
 #include <asm/arch/sci/sci.h>
 #include <asm/arch/sys_proto.h>
 #include <asm/arch-imx/cpu.h>
@@ -571,15 +572,45 @@  const char *get_core_name(void)
 		return "?";
 }
 
+#if defined(CONFIG_IMX_SCU_THERMAL)
+static int cpu_imx_get_temp(void)
+{
+	struct udevice *thermal_dev;
+	int cpu_tmp, ret;
+
+	ret = uclass_get_device_by_name(UCLASS_THERMAL, "cpu-thermal0",
+					&thermal_dev);
+
+	if (!ret) {
+		ret = thermal_get_temp(thermal_dev, &cpu_tmp);
+		if (ret)
+			return 0xdeadbeef;
+	} else {
+		return 0xdeadbeef;
+	}
+
+	return cpu_tmp;
+}
+#endif
+
 int cpu_imx_get_desc(struct udevice *dev, char *buf, int size)
 {
 	struct cpu_imx_platdata *plat = dev_get_platdata(dev);
+	int ret;
 
 	if (size < 100)
 		return -ENOSPC;
 
-	snprintf(buf, size, "NXP i.MX8%s Rev%s %s at %u MHz\n",
-		 plat->type, plat->rev, plat->name, plat->freq_mhz);
+	ret = snprintf(buf, size, "NXP i.MX8%s Rev%s %s at %u MHz",
+		       plat->type, plat->rev, plat->name, plat->freq_mhz);
+
+	if (IS_ENABLED(CONFIG_IMX_SCU_THERMAL)) {
+		buf = buf + ret;
+		size = size - ret;
+		ret = snprintf(buf, size, " at %dC", cpu_imx_get_temp());
+	}
+
+	snprintf(buf + ret, size - ret, "\n");
 
 	return 0;
 }