diff mbox series

[V2,8/9] cpu: imx_cpu: Print the CPU temperature for iMX8QM A72

Message ID 20200501134418.7319-8-peng.fan@nxp.com
State Superseded
Headers show
Series [V2,1/9] uclass: cpu: Add new API to get udevice for current CPU | expand

Commit Message

Peng Fan May 1, 2020, 1:44 p.m. UTC
From: Ye Li <ye.li at nxp.com>

iMX8QM registers two thermal devices for CPUs, get the temperature
from "cpu-thermal1" device for A72

Signed-off-by: Ye Li <ye.li at nxp.com>
Signed-off-by: Peng Fan <peng.fan at nxp.com>
---

V2:
 Per Simon's comments, use uclass_get_device

 drivers/cpu/imx8_cpu.c | 18 ++++++++++++------
 1 file changed, 12 insertions(+), 6 deletions(-)

Comments

Simon Glass May 3, 2020, 2:26 a.m. UTC | #1
Hi Peng,

On Fri, 1 May 2020 at 07:22, Peng Fan <peng.fan at nxp.com> wrote:
>
> From: Ye Li <ye.li at nxp.com>
>
> iMX8QM registers two thermal devices for CPUs, get the temperature
> from "cpu-thermal1" device for A72
>
> Signed-off-by: Ye Li <ye.li at nxp.com>
> Signed-off-by: Peng Fan <peng.fan at nxp.com>
> ---
>
> V2:
>  Per Simon's comments, use uclass_get_device
>
>  drivers/cpu/imx8_cpu.c | 18 ++++++++++++------
>  1 file changed, 12 insertions(+), 6 deletions(-)

Reviewed-by: Simon Glass <sjg at chromium.org>

This is still very strange code, but OK.
diff mbox series

Patch

diff --git a/drivers/cpu/imx8_cpu.c b/drivers/cpu/imx8_cpu.c
index c96a2d3563..817e0ffd01 100644
--- a/drivers/cpu/imx8_cpu.c
+++ b/drivers/cpu/imx8_cpu.c
@@ -61,13 +61,15 @@  const char *get_core_name(struct udevice *dev)
 }
 
 #if IS_ENABLED(CONFIG_IMX_SCU_THERMAL)
-static int cpu_imx_get_temp(void)
+static int cpu_imx_get_temp(struct cpu_imx_platdata *plat)
 {
 	struct udevice *thermal_dev;
 	int cpu_tmp, ret;
 
-	ret = uclass_get_device_by_name(UCLASS_THERMAL, "cpu-thermal0",
-					&thermal_dev);
+	if (!strcmp(plat->name, "A72"))
+		ret = uclass_get_device(UCLASS_THERMAL, 1, &thermal_dev);
+	else
+		ret = uclass_get_device(UCLASS_THERMAL, 0, &thermal_dev);
 
 	if (!ret) {
 		ret = thermal_get_temp(thermal_dev, &cpu_tmp);
@@ -80,7 +82,7 @@  static int cpu_imx_get_temp(void)
 	return cpu_tmp;
 }
 #else
-static int cpu_imx_get_temp(void)
+static int cpu_imx_get_temp(struct cpu_imx_platdata *plat)
 {
 	return 0;
 }
@@ -89,7 +91,7 @@  static int cpu_imx_get_temp(void)
 int cpu_imx_get_desc(struct udevice *dev, char *buf, int size)
 {
 	struct cpu_imx_platdata *plat = dev_get_platdata(dev);
-	int ret;
+	int ret, temp;
 
 	if (size < 100)
 		return -ENOSPC;
@@ -98,9 +100,13 @@  int cpu_imx_get_desc(struct udevice *dev, char *buf, int size)
 		       plat->type, plat->rev, plat->name, plat->freq_mhz);
 
 	if (IS_ENABLED(CONFIG_IMX_SCU_THERMAL)) {
+		temp = cpu_imx_get_temp(plat);
 		buf = buf + ret;
 		size = size - ret;
-		ret = snprintf(buf, size, " at %dC", cpu_imx_get_temp());
+		if (temp != 0xdeadbeef)
+			ret = snprintf(buf, size, " at %dC", temp);
+		else
+			ret = snprintf(buf, size, " - invalid sensor data");
 	}
 
 	snprintf(buf + ret, size - ret, "\n");