Skip to contentSkip to conversation

cpu: imx8: fix type and rate detection

PATCH New Anatolij Gustschin 4 participants 22 messages May 16, 2020 – May 22, 2020

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/2 cpu: imx8: fix type and rate detection

CPU type and rate detection is broken, for A35 cpu we get A53:
...
sc_pm_get_clock_rate: resource:0 clk:2: res:3
Could not read CPU frequency: -22
CPU: NXP i.MX8QXP RevB A53 at 0 MHz at 47C

Fixes 55bc96f3b675 ("cpu: imx8: fix get core name and rate")
---
 drivers/cpu/imx8_cpu.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
drivers/cpu/imx8_cpu.c +6 -6
index 95c14c98d8..896e1ac776 100644
@@ -52,11 +52,11 @@ const char *get_imx8_rev(u32 rev)
 
 const char *get_core_name(struct udevice *dev)
 {
-	if (!device_is_compatible(dev, "arm,cortex-a35"))
+	if (device_is_compatible(dev, "arm,cortex-a35"))
 		return "A35";
-	else if (!device_is_compatible(dev, "arm,cortex-a53"))
+	else if (device_is_compatible(dev, "arm,cortex-a53"))
 		return "A53";
-	else if (!device_is_compatible(dev, "arm,cortex-a72"))
+	else if (device_is_compatible(dev, "arm,cortex-a72"))
 		return "A72";
 	else
 		return "?";
@@ -183,11 +183,11 @@ static ulong imx8_get_cpu_rate(struct udevice *dev)
 	ulong rate;
 	int ret, type;
 
-	if (!device_is_compatible(dev, "arm,cortex-a35"))
+	if (device_is_compatible(dev, "arm,cortex-a35"))
 		type = SC_R_A35;
-	else if (!device_is_compatible(dev, "arm,cortex-a53"))
+	else if (device_is_compatible(dev, "arm,cortex-a53"))
 		type = SC_R_A53;
-	else if (!device_is_compatible(dev, "arm,cortex-a72"))
+	else if (device_is_compatible(dev, "arm,cortex-a72"))
 		type = SC_R_A72;
 	else
 		return 0;
Signature · 1 line
2.17.1
author Applied
#1 lore raw

PATCH 1/2 cpu: imx8: fix type and rate detection

Quoted 11 lines · On Sat, 16 May 2020 22:34:19 +0200 Anatolij Gustschin agust at denx.de wrote:

CPU type and rate detection is broken, for A35 cpu we get A53:
...
sc_pm_get_clock_rate: resource:0 clk:2: res:3
Could not read CPU frequency: -22
CPU: NXP i.MX8QXP RevB A53 at 0 MHz at 47C

Fixes 55bc96f3b675 ("cpu: imx8: fix get core name and rate")
---
 drivers/cpu/imx8_cpu.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

Applied.

--
Anatolij

#2 lore raw

PATCH 1/2 cpu: imx8: fix type and rate detection

In reply to Anatolij Gustschin
Quoted 47 lines

Subject: [PATCH 1/2] cpu: imx8: fix type and rate detection

CPU type and rate detection is broken, for A35 cpu we get A53:
...
sc_pm_get_clock_rate: resource:0 clk:2: res:3 Could not read CPU frequency:
-22
CPU: NXP i.MX8QXP RevB A53 at 0 MHz at 47C

Fixes 55bc96f3b675 ("cpu: imx8: fix get core name and rate")
---
 drivers/cpu/imx8_cpu.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
drivers/cpu/imx8_cpu.c index renamed from drivers/cpu/imx8_cpu.c +0 -0

95c14c98d8..896e1ac776 100644

drivers/cpu/imx8_cpu.c +6 -6
@@ -52,11 +52,11 @@ const char *get_imx8_rev(u32 rev)
 
 const char *get_core_name(struct udevice *dev)  {
-	if (!device_is_compatible(dev, "arm,cortex-a35"))
+	if (device_is_compatible(dev, "arm,cortex-a35"))
 		return "A35";
-	else if (!device_is_compatible(dev, "arm,cortex-a53"))
+	else if (device_is_compatible(dev, "arm,cortex-a53"))
 		return "A53";
-	else if (!device_is_compatible(dev, "arm,cortex-a72"))
+	else if (device_is_compatible(dev, "arm,cortex-a72"))
 		return "A72";
 	else
 		return "?";
@@ -183,11 +183,11 @@ static ulong imx8_get_cpu_rate(struct udevice
 *dev)
 	ulong rate;
 	int ret, type;
 
-	if (!device_is_compatible(dev, "arm,cortex-a35"))
+	if (device_is_compatible(dev, "arm,cortex-a35"))
 		type = SC_R_A35;
-	else if (!device_is_compatible(dev, "arm,cortex-a53"))
+	else if (device_is_compatible(dev, "arm,cortex-a53"))
 		type = SC_R_A53;
-	else if (!device_is_compatible(dev, "arm,cortex-a72"))
+	else if (device_is_compatible(dev, "arm,cortex-a72"))
 		type = SC_R_A72;
 	else
Quoted 3 lines

return 0;
--
2.17.1

#3 lore raw

PATCH 2/2 thermal: imx_scu_thermal: fix getting DT alert property value

In reply to Anatolij Gustschin

Fix boot hang with endless loop outputting:
CPU Temperature (47200C) has beyond alert (0C), close to critical (0C) waiting...

---
i.MX8QXP is broken again, this should be appied ASAP!

 drivers/thermal/imx_scu_thermal.c | 101 ++++++++++++------------------
 1 file changed, 41 insertions(+), 60 deletions(-)
drivers/thermal/imx_scu_thermal.c +41 -60
index da13121a09..679ce4e244 100644
@@ -57,7 +57,7 @@ int imx_sc_thermal_get_temp(struct udevice *dev, int *temp)
 	if (ret)
 		return ret;
 
-	while (cpu_temp >= pdata->alert) {
+	while (cpu_temp >= pdata->alert && pdata->alert) {
 		printf("CPU Temperature (%dC) has beyond alert (%dC), close to critical (%dC)",
 		       cpu_temp, pdata->alert, pdata->critical);
 		puts(" waiting...\n");
@@ -78,7 +78,47 @@ static const struct dm_thermal_ops imx_sc_thermal_ops = {
 
 static int imx_sc_thermal_probe(struct udevice *dev)
 {
+	struct imx_sc_thermal_plat *pdata = dev_get_platdata(dev);
+	struct fdtdec_phandle_args args;
+	ofnode node, trips_np;
+	int ret;
+
 	debug("%s dev name %s\n", __func__, dev->name);
+
+	trips_np = ofnode_path("/thermal-zones/cpu-thermal0/trips");
+	node = ofnode_get_parent(trips_np);
+	ret = fdtdec_parse_phandle_with_args(gd->fdt_blob, node.of_offset,
+					     "thermal-sensors",
+					     "#thermal-sensor-cells",
+					     0, 0, &args);
+	if (ret)
+		return ret;
+
+	if (args.args_count >= 1)
+		pdata->id = args.args[0];
+	else
+		pdata->id = 0;
+
+	debug("args.args_count %d, id %d\n", args.args_count, pdata->id);
+
+	pdata->polling_delay = ofnode_read_u32_default(node, "polling-delay",
+						       1000);
+	ofnode_for_each_subnode(trips_np, trips_np) {
+		const char *type;
+
+		type = ofnode_get_property(trips_np, "type", NULL);
+		if (!type)
+			continue;
+		if (!strcmp(type, "critical"))
+			pdata->critical =
+			ofnode_read_u32_default(trips_np, "temperature", 85);
+		else if (!strcmp(type, "passive"))
+			pdata->alert =
+			ofnode_read_u32_default(trips_np, "temperature", 80);
+	}
+
+	debug("id %d polling_delay %d, critical %d, alert %d\n",
+	      pdata->id, pdata->polling_delay, pdata->critical, pdata->alert);
 	return 0;
 }
 
@@ -121,64 +161,6 @@ static int imx_sc_thermal_bind(struct udevice *dev)
 	return 0;
 }
 
-static int imx_sc_thermal_ofdata_to_platdata(struct udevice *dev)
-{
-	struct imx_sc_thermal_plat *pdata = dev_get_platdata(dev);
-	struct fdtdec_phandle_args args;
-	const char *type;
-	int ret;
-	int trips_np;
-
-	debug("%s dev name %s\n", __func__, dev->name);
-
-	if (pdata->zone_node)
-		return 0;
-
-	ret = fdtdec_parse_phandle_with_args(gd->fdt_blob, dev_of_offset(dev),
-					     "thermal-sensors",
-					     "#thermal-sensor-cells",
-					     0, 0, &args);
-	if (ret)
-		return ret;
-
-	if (args.node != dev_of_offset(dev->parent))
-		return -EFAULT;
-
-	if (args.args_count >= 1)
-		pdata->id = args.args[0];
-	else
-		pdata->id = 0;
-
-	debug("args.args_count %d, id %d\n", args.args_count, pdata->id);
-
-	pdata->polling_delay = fdtdec_get_int(gd->fdt_blob, dev_of_offset(dev),
-					      "polling-delay", 1000);
-
-	trips_np = fdt_subnode_offset(gd->fdt_blob, dev_of_offset(dev),
-				      "trips");
-	fdt_for_each_subnode(trips_np, gd->fdt_blob, trips_np) {
-		type = fdt_getprop(gd->fdt_blob, trips_np, "type", NULL);
-		if (type) {
-			if (strcmp(type, "critical") == 0) {
-				pdata->critical = fdtdec_get_int(gd->fdt_blob,
-								 trips_np,
-								 "temperature",
-								 85);
-			} else if (strcmp(type, "passive") == 0) {
-				pdata->alert = fdtdec_get_int(gd->fdt_blob,
-							      trips_np,
-							      "temperature",
-							      80);
-			}
-		}
-	}
-
-	debug("id %d polling_delay %d, critical %d, alert %d\n", pdata->id,
-	      pdata->polling_delay, pdata->critical, pdata->alert);
-
-	return 0;
-}
-
 static const sc_rsrc_t imx8qm_sensor_rsrc[] = {
 	SC_R_A53, SC_R_A72, SC_R_GPU_0_PID0, SC_R_GPU_1_PID0,
 	SC_R_DRC_0, SC_R_DRC_1, SC_R_VPU_PID0, SC_R_PMIC_0,
@@ -205,7 +187,6 @@ U_BOOT_DRIVER(imx_sc_thermal) = {
 	.of_match = imx_sc_thermal_ids,
 	.bind = imx_sc_thermal_bind,
 	.probe	= imx_sc_thermal_probe,
-	.ofdata_to_platdata = imx_sc_thermal_ofdata_to_platdata,
 	.platdata_auto_alloc_size = sizeof(struct imx_sc_thermal_plat),
 	.flags  = DM_FLAG_PRE_RELOC,
 };
Signature · 1 line
2.17.1
#4 lore raw

PATCH 2/2 thermal: imx_scu_thermal: fix getting DT alert property value

Hi Anatolij,

Quoted 6 lines

Subject: [PATCH 2/2] thermal: imx_scu_thermal: fix getting DT alert property value

Fix boot hang with endless loop outputting:
CPU Temperature (47200C) has beyond alert (0C), close to critical (0C) waiting...

Could you share more info which part was broken?

Thanks,
Peng.

Quoted 146 lines

---
i.MX8QXP is broken again, this should be appied ASAP!

 drivers/thermal/imx_scu_thermal.c | 101 ++++++++++++------------------
 1 file changed, 41 insertions(+), 60 deletions(-)
drivers/thermal/imx_scu_thermal.c +1 -1
index da13121a09..679ce4e244 100644
@@ -57,7 +57,7 @@ int imx_sc_thermal_get_temp(struct udevice *dev, int
 *temp)
 	if (ret)
 		return ret;
 
-	while (cpu_temp >= pdata->alert) {
+	while (cpu_temp >= pdata->alert && pdata->alert) {
 		printf("CPU Temperature (%dC) has beyond alert (%dC), close to
 critical (%dC)",
drivers/thermal/imx_scu_thermal.c +40 -58
 		       cpu_temp, pdata->alert, pdata->critical);
 		puts(" waiting...\n");
@@ -78,7 +78,47 @@ static const struct dm_thermal_ops
 imx_sc_thermal_ops = {
 
 static int imx_sc_thermal_probe(struct udevice *dev)  {
+	struct imx_sc_thermal_plat *pdata = dev_get_platdata(dev);
+	struct fdtdec_phandle_args args;
+	ofnode node, trips_np;
+	int ret;
+
 	debug("%s dev name %s\n", __func__, dev->name);
+
+	trips_np = ofnode_path("/thermal-zones/cpu-thermal0/trips");
+	node = ofnode_get_parent(trips_np);
+	ret = fdtdec_parse_phandle_with_args(gd->fdt_blob, node.of_offset,
+					     "thermal-sensors",
+					     "#thermal-sensor-cells",
+					     0, 0, &args);
+	if (ret)
+		return ret;
+
+	if (args.args_count >= 1)
+		pdata->id = args.args[0];
+	else
+		pdata->id = 0;
+
+	debug("args.args_count %d, id %d\n", args.args_count, pdata->id);
+
+	pdata->polling_delay = ofnode_read_u32_default(node, "polling-delay",
+						       1000);
+	ofnode_for_each_subnode(trips_np, trips_np) {
+		const char *type;
+
+		type = ofnode_get_property(trips_np, "type", NULL);
+		if (!type)
+			continue;
+		if (!strcmp(type, "critical"))
+			pdata->critical =
+			ofnode_read_u32_default(trips_np, "temperature", 85);
+		else if (!strcmp(type, "passive"))
+			pdata->alert =
+			ofnode_read_u32_default(trips_np, "temperature", 80);
+	}
+
+	debug("id %d polling_delay %d, critical %d, alert %d\n",
+	      pdata->id, pdata->polling_delay, pdata->critical, pdata->alert);
 	return 0;
 }
 
@@ -121,64 +161,6 @@ static int imx_sc_thermal_bind(struct udevice *dev)
 	return 0;
 }
 
-static int imx_sc_thermal_ofdata_to_platdata(struct udevice *dev) -{
-	struct imx_sc_thermal_plat *pdata = dev_get_platdata(dev);
-	struct fdtdec_phandle_args args;
-	const char *type;
-	int ret;
-	int trips_np;
-
-	debug("%s dev name %s\n", __func__, dev->name);
-
-	if (pdata->zone_node)
-		return 0;
-
-	ret = fdtdec_parse_phandle_with_args(gd->fdt_blob, dev_of_offset(dev),
-					     "thermal-sensors",
-					     "#thermal-sensor-cells",
-					     0, 0, &args);
-	if (ret)
-		return ret;
-
-	if (args.node != dev_of_offset(dev->parent))
-		return -EFAULT;
-
-	if (args.args_count >= 1)
-		pdata->id = args.args[0];
-	else
-		pdata->id = 0;
-
-	debug("args.args_count %d, id %d\n", args.args_count, pdata->id);
-
-	pdata->polling_delay = fdtdec_get_int(gd->fdt_blob, dev_of_offset(dev),
-					      "polling-delay", 1000);
-
-	trips_np = fdt_subnode_offset(gd->fdt_blob, dev_of_offset(dev),
-				      "trips");
-	fdt_for_each_subnode(trips_np, gd->fdt_blob, trips_np) {
-		type = fdt_getprop(gd->fdt_blob, trips_np, "type", NULL);
-		if (type) {
-			if (strcmp(type, "critical") == 0) {
-				pdata->critical = fdtdec_get_int(gd->fdt_blob,
-								 trips_np,
-								 "temperature",
-								 85);
-			} else if (strcmp(type, "passive") == 0) {
-				pdata->alert = fdtdec_get_int(gd->fdt_blob,
-							      trips_np,
-							      "temperature",
-							      80);
-			}
-		}
-	}
-
-	debug("id %d polling_delay %d, critical %d, alert %d\n", pdata->id,
-	      pdata->polling_delay, pdata->critical, pdata->alert);
-
-	return 0;
-}
-
 static const sc_rsrc_t imx8qm_sensor_rsrc[] = {
 	SC_R_A53, SC_R_A72, SC_R_GPU_0_PID0, SC_R_GPU_1_PID0,
 	SC_R_DRC_0, SC_R_DRC_1, SC_R_VPU_PID0, SC_R_PMIC_0, @@
-205,7 +187,6 @@ U_BOOT_DRIVER(imx_sc_thermal) = {
drivers/thermal/imx_scu_thermal.c +0 -2
 	.of_match = imx_sc_thermal_ids,
 	.bind = imx_sc_thermal_bind,
 	.probe	= imx_sc_thermal_probe,
-	.ofdata_to_platdata = imx_sc_thermal_ofdata_to_platdata,
 	.platdata_auto_alloc_size = sizeof(struct imx_sc_thermal_plat),
 	.flags  = DM_FLAG_PRE_RELOC,
 };
--

2.17.1

#5 lore raw

PATCH 2/2 thermal: imx_scu_thermal: fix getting DT alert property value

Hi Peng,

Quoted 10 lines · On Sun, 17 May 2020 10:04:58 +0000 Peng Fan peng.fan at nxp.com wrote:

Hi Anatolij,

Quoted 6 lines

Subject: [PATCH 2/2] thermal: imx_scu_thermal: fix getting DT alert property value

Fix boot hang with endless loop outputting:
CPU Temperature (47200C) has beyond alert (0C), close to critical (0C) waiting...

Could you share more info which part was broken?

I've tested i.MX8QXP based capricorn/giedi board (giedi_defconfig, imx8-giedi.dts) and it was not booting:

U-Boot SPL 2020.07-rc2-00124-g515f613253 (May 16 2020 - 09:22:49 +0200) Trying to boot from MMC1
Load image from MMC/SD 0x3ec00

U-Boot 2020.07-rc2-00124-g515f613253 (May 16 2020 - 09:22:49 +0200) ##v01.07

sc_pm_get_clock_rate: resource:0 clk:2: res:3
Could not read CPU frequency: -22
CPU Temperature (34800C) has beyond alert (0C), close to critical (0C) waiting... CPU Temperature (35000C) has beyond alert (0C), close to critical (0C) waiting... CPU Temperature (35000C) has beyond alert (0C), close to critical (0C) waiting... CPU Temperature (34800C) has beyond alert (0C), close to critical (0C) waiting... CPU Temperature (34600C) has beyond alert (0C), close to critical (0C) waiting... CPU Temperature (35000C) has beyond alert (0C), close to critical (0C) waiting...
...

Other i.MX8QXP based boards might be broken as well.

--
Anatolij

#6 lore raw

PATCH 2/2 thermal: imx_scu_thermal: fix getting DT alert property value

Quoted 30 lines

Subject: Re: [PATCH 2/2] thermal: imx_scu_thermal: fix getting DT alert property value

Hi Peng,

Quoted 10 lines · On Sun, 17 May 2020 10:04:58 +0000 Peng Fan peng.fan at nxp.com wrote:

Hi Anatolij,

Quoted 6 lines

Subject: [PATCH 2/2] thermal: imx_scu_thermal: fix getting DT alert property value

Fix boot hang with endless loop outputting:
CPU Temperature (47200C) has beyond alert (0C), close to critical (0C) waiting...

Could you share more info which part was broken?

I've tested i.MX8QXP based capricorn/giedi board (giedi_defconfig, imx8-giedi.dts) and it was not booting:

U-Boot SPL 2020.07-rc2-00124-g515f613253 (May 16 2020 - 09:22:49 +0200) Trying to boot from MMC1 Load image from MMC/SD 0x3ec00

U-Boot 2020.07-rc2-00124-g515f613253 (May 16 2020 - 09:22:49 +0200) ##v01.07

Quoted 13 lines

sc_pm_get_clock_rate: resource:0 clk:2: res:3 Could not read CPU frequency:
-22 CPU Temperature (34800C) has beyond alert (0C), close to critical (0C) waiting...
CPU Temperature (35000C) has beyond alert (0C), close to critical (0C) waiting...
CPU Temperature (35000C) has beyond alert (0C), close to critical (0C) waiting...
CPU Temperature (34800C) has beyond alert (0C), close to critical (0C) waiting...
CPU Temperature (34600C) has beyond alert (0C), close to critical (0C) waiting...
CPU Temperature (35000C) has beyond alert (0C), close to critical (0C) waiting...

Sorry for not be clear, I mean which code change breaks the boot?

Thanks,
Peng.

Quoted 6 lines

...

Other i.MX8QXP based boards might be broken as well.

--
Anatolij

#7 lore raw

PATCH 2/2 thermal: imx_scu_thermal: fix getting DT alert property value

On Sun, 17 May 2020 14:43:39 +0000
Peng Fan peng.fan at nxp.com wrote:
...

Quoted 4 lines
Quoted 2 lines

CPU Temperature (35000C) has beyond alert (0C), close to critical (0C) waiting...

Sorry for not be clear, I mean which code change breaks the boot?

I didn't bisect this, so I do not know exactly. Last working revision installed on the board before was d202f67db077 ("Merge branch '2020-04-25-master-imports'"). Will try to bisect later.

--
Anatolij

#8 lore raw

PATCH 2/2 thermal: imx_scu_thermal: fix getting DT alert property value

Hi Peng,

On Sun, 17 May 2020 16:53:17 +0200
Anatolij Gustschin agust at denx.de wrote:
...

Quoted 1 line

Will try to bisect later.

bisecting leads to:

# first bad commit: [3ee6ea443eb466399ab325a58b377326ac5c57b5]
cpu: imx_cpu: Print the CPU temperature for iMX8QM A72

--
Anatolij

#9 lore raw

PATCH 2/2 thermal: imx_scu_thermal: fix getting DT alert property value

Quoted 5 lines

Subject: Re: [PATCH 2/2] thermal: imx_scu_thermal: fix getting DT alert property value

Hi Peng,

Quoted 8 lines

On Sun, 17 May 2020 16:53:17 +0200
Anatolij Gustschin agust at denx.de wrote:
...

Quoted 1 line

Will try to bisect later.

bisecting leads to:

# first bad commit: [3ee6ea443eb466399ab325a58b377326ac5c57b5]
cpu: imx_cpu: Print the CPU temperature for iMX8QM A72

Would this help?

drivers/cpu/imx8_cpu.c +7 -4
index 95c14c98d8..6c949ccbd4 100644
@@ -68,10 +68,13 @@ static int cpu_imx_get_temp(struct cpu_imx_platdata *plat)
        struct udevice *thermal_dev;
        int cpu_tmp, ret;
 
-       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 (!strcmp(plat->name, "A72")) {
+               ret = uclass_get_device_by_name(UCLASS_THERMAL, "cpu-thermal1",
+                                               &thermal_dev);
+       } else {
+               ret = uclass_get_device_by_name(UCLASS_THERMAL, "cpu-thermal0",
+                                               &thermal_dev);
+       }
 
        if (!ret) {
                ret = thermal_get_temp(thermal_dev, &cpu_tmp);

Thanks,
Peng.

Quoted 3 lines

--
Anatolij

#10 lore raw

PATCH 2/2 thermal: imx_scu_thermal: fix getting DT alert property value

On Tue, 19 May 2020 10:05:21 +0000
Peng Fan peng.fan at nxp.com wrote:
...

Quoted 14 lines

Would this help?

drivers/cpu/imx8_cpu.c +0 -4
index 95c14c98d8..6c949ccbd4 100644
@@ -68,10 +68,13 @@ static int cpu_imx_get_temp(struct cpu_imx_platdata *plat)
        struct udevice *thermal_dev;
        int cpu_tmp, ret;
 
-       if (!strcmp(plat->name, "A72"))
-               ret = uclass_get_device(UCLASS_THERMAL, 1, &thermal_dev);
-       else
-               ret = uclass_get_device(UCLASS_THERMAL, 0, &thermal_dev);

drivers/cpu/imx8_cpu.c static int cpu_imx_get_temp(struct cpu_imx_platdata *plat) · line 80

Quoted 10 lines
drivers/cpu/imx8_cpu.c +7 -0
+       if (!strcmp(plat->name, "A72")) {
+               ret = uclass_get_device_by_name(UCLASS_THERMAL, "cpu-thermal1",
+                                               &thermal_dev);
+       } else {
+               ret = uclass_get_device_by_name(UCLASS_THERMAL, "cpu-thermal0",
+                                               &thermal_dev);
+       }
 
        if (!ret) {
                ret = thermal_get_temp(thermal_dev, &cpu_tmp);

Yes, this fixes the problem, thanks!

--
Anatolij

#11 lore raw

PATCH 2/2 thermal: imx_scu_thermal: fix getting DT alert property value

+Simon

Quoted 35 lines

-----Original Message-----
From: Anatolij Gustschin <[email protected]>
Sent: 2020?5?19? 18:27
To: Peng Fan <[email protected]>
Cc: u-boot at lists.denx.de; Ye Li <[email protected]>; Frank Li <[email protected]>; sbabic at denx.de
Subject: Re: [PATCH 2/2] thermal: imx_scu_thermal: fix getting DT alert property value

On Tue, 19 May 2020 10:05:21 +0000
Peng Fan peng.fan at nxp.com wrote:
...

drivers/cpu/imx8_cpu.c static int cpu_imx_get_temp(struct

Quoted 7 lines

Would this help?

drivers/cpu/imx8_cpu.c index renamed from drivers/cpu/imx8_cpu.c +0 -0

95c14c98d8..6c949ccbd4 100644

drivers/cpu/imx8_cpu.c +0 -0
@@ -68,10 +68,13 @@ static int cpu_imx_get_temp(struct

cpu_imx_platdata *plat)

drivers/cpu/imx8_cpu.c static int cpu_imx_get_temp(struct cpu_imx_platdata *plat)

Quoted 5 lines
drivers/cpu/imx8_cpu.c +0 -2
        struct udevice *thermal_dev;
        int cpu_tmp, ret;
 
-       if (!strcmp(plat->name, "A72"))
-               ret = uclass_get_device(UCLASS_THERMAL, 1,

&thermal_dev);

drivers/cpu/imx8_cpu.c static int cpu_imx_get_temp(struct · line 74

Quoted 2 lines
drivers/cpu/imx8_cpu.c +0 -2
-       else
-               ret = uclass_get_device(UCLASS_THERMAL, 0,

&thermal_dev);

drivers/cpu/imx8_cpu.c static int cpu_imx_get_temp(struct · line 72

Quoted 2 lines
drivers/cpu/imx8_cpu.c +2 -0
+       if (!strcmp(plat->name, "A72")) {
+               ret = uclass_get_device_by_name(UCLASS_THERMAL,

"cpu-thermal1",

drivers/cpu/imx8_cpu.c static int cpu_imx_get_temp(struct cpu_imx_platdata *plat)

Quoted 3 lines
drivers/cpu/imx8_cpu.c +3 -0
+                                               &thermal_dev);
+       } else {
+               ret = uclass_get_device_by_name(UCLASS_THERMAL,
Quoted 8 lines

"cpu-thermal0",

drivers/cpu/imx8_cpu.c static int cpu_imx_get_temp(struct cpu_imx_platdata *plat) · line 80

Quoted 5 lines
drivers/cpu/imx8_cpu.c +2 -0
+                                               &thermal_dev);
+       }
 
        if (!ret) {
                ret = thermal_get_temp(thermal_dev, &cpu_tmp);

Yes, this fixes the problem, thanks!

Do you have more insights about uclass_get_device and uclass_get_device_byname? uclass_get_device not work, but uclass_get_device_byname work.

Thanks,
Peng.

Quoted 3 lines

--
Anatolij

#12 lore raw

PATCH 2/2 thermal: imx_scu_thermal: fix getting DT alert property value

On Tue, 19 May 2020 11:45:55 +0000
Peng Fan peng.fan at nxp.com wrote:
...

Quoted 2 lines

Do you have more insights about uclass_get_device and uclass_get_device_byname? uclass_get_device not work, but uclass_get_device_byname work.

well, we have three thermal uclass devices on i.MX8QXP:

 thermal       0  [   ]   imx_sc_thermal        |-- thermal-sensor
 thermal       1  [   ]   imx_sc_thermal        |   |-- cpu-thermal0
 thermal       2  [   ]   imx_sc_thermal        |   `-- drc-thermal0

when using uclass_get_device(UCLASS_THERMAL, 0, &thermal_dev), the first device ("thermal-sensor") is matching and for this device imx_sc_thermal_ofdata_to_platdata() will be called, it then tries to get the "thermal-sensors" list in the node of "thermal-sensor" device (dev_of_offset(dev)), but this is wrong, since this list is a property of the "cpu-thermal0" node according to bindings.

Therefore ofdata_to_platdata() can't find the "thermal-sensors" list and does not initialize alert/critical pdata values.

When uclass_get_device_by_name() is used, then imx_sc_thermal_ofdata_to_platdata() is called for "cpu-thermal0" device, here getting the list works
and alert/critical pdata values are initialized properly.

--
Anatolij

#13 lore raw

PATCH 2/2 thermal: imx_scu_thermal: fix getting DT alert property value

On Wed, 20 May 2020 00:05:01 +0200
Anatolij Gustschin agust at denx.de wrote:
...

Quoted 3 lines

When uclass_get_device_by_name() is used, then imx_sc_thermal_ofdata_to_platdata() is called for "cpu-thermal0" device, here getting the list works
and alert/critical pdata values are initialized properly.

This 2/2 patch can be superseded by patch:
http://patchwork.ozlabs.org/project/uboot/patch/20200519233144.2426-1-agust at denx.de

--
Anatolij

reviewer
#14 lore raw

PATCH 2/2 thermal: imx_scu_thermal: fix getting DT alert property value

In reply to Anatolij Gustschin

Hi Anatolij and Heiko,

Quoted 20 lines · Anatolij Gustschin

I've tested i.MX8QXP based capricorn/giedi board (giedi_defconfig, imx8-giedi.dts) and it was not booting:

U-Boot SPL 2020.07-rc2-00124-g515f613253 (May 16 2020 - 09:22:49 +0200) Trying to boot from MMC1
Load image from MMC/SD 0x3ec00

U-Boot 2020.07-rc2-00124-g515f613253 (May 16 2020 - 09:22:49 +0200) ##v01.07

sc_pm_get_clock_rate: resource:0 clk:2: res:3
Could not read CPU frequency: -22
CPU Temperature (34800C) has beyond alert (0C), close to critical (0C) waiting... CPU Temperature (35000C) has beyond alert (0C), close to critical (0C) waiting... CPU Temperature (35000C) has beyond alert (0C), close to critical (0C) waiting... CPU Temperature (34800C) has beyond alert (0C), close to critical (0C) waiting... CPU Temperature (34600C) has beyond alert (0C), close to critical (0C) waiting... CPU Temperature (35000C) has beyond alert (0C), close to critical (0C) waiting...
...

Quoted 1 line

Other i.MX8QXP based boards might be broken as well.

Would it be possible to add this i.MX8QXP capricorn/giedi board into Heiko's boot farm?

Thanks

#15 lore raw

PATCH 2/2 thermal: imx_scu_thermal: fix getting DT alert property value

Hello Fabio, Anatolij,

Am 19.05.2020 um 01:32 schrieb Fabio Estevam:

Quoted 24 lines

Hi Anatolij and Heiko,

Quoted 20 lines · Anatolij Gustschin

I've tested i.MX8QXP based capricorn/giedi board (giedi_defconfig, imx8-giedi.dts) and it was not booting:

U-Boot SPL 2020.07-rc2-00124-g515f613253 (May 16 2020 - 09:22:49 +0200) Trying to boot from MMC1
Load image from MMC/SD 0x3ec00

U-Boot 2020.07-rc2-00124-g515f613253 (May 16 2020 - 09:22:49 +0200) ##v01.07

sc_pm_get_clock_rate: resource:0 clk:2: res:3
Could not read CPU frequency: -22
CPU Temperature (34800C) has beyond alert (0C), close to critical (0C) waiting... CPU Temperature (35000C) has beyond alert (0C), close to critical (0C) waiting... CPU Temperature (35000C) has beyond alert (0C), close to critical (0C) waiting... CPU Temperature (34800C) has beyond alert (0C), close to critical (0C) waiting... CPU Temperature (34600C) has beyond alert (0C), close to critical (0C) waiting... CPU Temperature (35000C) has beyond alert (0C), close to critical (0C) waiting...
...

Quoted 4 lines
Quoted 1 line

Other i.MX8QXP based boards might be broken as well.

Would it be possible to add this i.MX8QXP capricorn/giedi board into Heiko's boot farm?

I am happy to add boards!

@Anatolij: Do we have this board in our vlab? Or somehow remote accessible?

@Fabio: I am sure you have some boards for testing, do you have a CI
setup for them? With the approach to report testresults you can run tbot also just locally and report results... just an idea...

If you need help to setup tbot, feel free to contact me.

You do not need to use tbot (I recommend it only, as it makes all for you once setup, and you can use it for your daily developers work too)

You can test your boards however you want and report results without tbot. Therefore I wrote an example:

https://github.com/EmbLux-Kft/uboot_results/blob/master/src/client.py

Of course, you have to fill real values for the report into:

https://github.com/EmbLux-Kft/uboot_results/blob/master/src/client.py#L88

I only have to add an useracount...

And be aware it is just a Proof of concept, so there are for sure bugs, missing documentation, ugly code ...

Testers, ideas and patches welcome.

bye,
Heiko

Signature · 3 lines
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-52   Fax: +49-8142-66989-80   Email: hs at denx.de
#16 lore raw

PATCH 2/2 thermal: imx_scu_thermal: fix getting DT alert property value

Hi Heiko,

On Tue, 19 May 2020 06:17:58 +0200
Heiko Schocher hs at denx.de wrote:
...

Quoted 6 lines
Quoted 2 lines

Would it be possible to add this i.MX8QXP capricorn/giedi board into Heiko's boot farm?

I am happy to add boards!

@Anatolij: Do we have this board in our vlab? Or somehow remote accessible?

No, it is on my table and not remote accessible. I'd like to make it remote accessible, but the problem currently is that I have only one serial console adapter (special box with FFC cable required to get the serial output, and I have only one such unit). I have another baseboard with giedi SoM and here the special console adapter is not required, but this baseboard has issues with its power supply circuit and requires a very stable power source before turning it on. Otherwise the SoM can be damaged and is not recoverable any more. I already have damaged two SoMs here when remote powering and do not want to experiment with remaining working SoMs.

--
Anatolij

reviewer
#17 lore raw

PATCH 2/2 thermal: imx_scu_thermal: fix getting DT alert property value

In reply to Heiko Schocher

Hi Heiko,

Quoted 6 lines · Heiko Schocher

I am happy to add boards!

@Anatolij: Do we have this board in our vlab? Or somehow remote accessible?

@Fabio: I am sure you have some boards for testing, do you have a CI
setup for them? With the approach to report testresults you can run

It is in my wish list for quite some time, but currently I don't have a CI setup.

Quoted 14 lines

tbot also just locally and report results... just an idea...

If you need help to setup tbot, feel free to contact me.

You do not need to use tbot (I recommend it only, as it makes all for you once setup, and you can use it for your daily developers work too)

You can test your boards however you want and report results without tbot. Therefore I wrote an example:

https://github.com/EmbLux-Kft/uboot_results/blob/master/src/client.py

Of course, you have to fill real values for the report into:

Quoted 8 lines

https://github.com/EmbLux-Kft/uboot_results/blob/master/src/client.py#L88

I only have to add an useracount...

And be aware it is just a Proof of concept, so there are for sure bugs, missing documentation, ugly code ...

Testers, ideas and patches welcome.

Thanks for your help!

#18 lore raw

PATCH 2/2 thermal: imx_scu_thermal: fix getting DT alert property value

In reply to Fabio Estevam

Hi Fabio,

On Mon, 18 May 2020 20:32:06 -0300
Fabio Estevam festevam at gmail.com wrote:
...

Quoted 2 lines

Would it be possible to add this i.MX8QXP capricorn/giedi board into Heiko's boot farm?

this board requires a very special power supply and I have only one power supply unit of that type and can't share it.

--
Anatolij

#19 lore raw

PATCH 1/1 cpu: imx8: use intended cpu-thermal device when getting temp value

In reply to Anatolij Gustschin

This fixes getting DT alert and critical pdata values in imx_scu_thermal driver. On i.MX8QXP using not initialized alert pdata value resulted in boot hang and endless loop outputting:
CPU Temperature (47200C) has beyond alert (0C), close to critical (0C) waiting...

While at it, preset CPU type values once to avoid multiple calls of device_is_compatible() for same property.

Fixes 3ee6ea443eb4 ("cpu: imx_cpu: Print the CPU temperature for iMX8QM A72")

---
This one supersedes the older patch here:
http://patchwork.ozlabs.org/project/uboot/patch/20200516203420.24409-2-agust at denx.de

 drivers/cpu/imx8_cpu.c | 50 +++++++++++++++++++++---------------------
 1 file changed, 25 insertions(+), 25 deletions(-)
drivers/cpu/imx8_cpu.c +25 -25
index 896e1ac776..adc4919d9e 100644
@@ -18,6 +18,7 @@ struct cpu_imx_platdata {
 	const char *name;
 	const char *rev;
 	const char *type;
+	u32 cpu_rsrc;
 	u32 cpurev;
 	u32 freq_mhz;
 	u32 mpidr;
@@ -50,16 +51,23 @@ const char *get_imx8_rev(u32 rev)
 	}
 }
 
-const char *get_core_name(struct udevice *dev)
+static void set_core_data(struct udevice *dev)
 {
-	if (device_is_compatible(dev, "arm,cortex-a35"))
-		return "A35";
-	else if (device_is_compatible(dev, "arm,cortex-a53"))
-		return "A53";
-	else if (device_is_compatible(dev, "arm,cortex-a72"))
-		return "A72";
-	else
-		return "?";
+	struct cpu_imx_platdata *plat = dev_get_platdata(dev);
+
+	if (device_is_compatible(dev, "arm,cortex-a35")) {
+		plat->cpu_rsrc = SC_R_A35;
+		plat->name = "A35";
+	} else if (device_is_compatible(dev, "arm,cortex-a53")) {
+		plat->cpu_rsrc = SC_R_A53;
+		plat->name = "A53";
+	} else if (device_is_compatible(dev, "arm,cortex-a72")) {
+		plat->cpu_rsrc = SC_R_A72;
+		plat->name = "A72";
+	} else {
+		plat->cpu_rsrc = SC_R_A53;
+		plat->name = "?";
+	}
 }
 
 #if IS_ENABLED(CONFIG_IMX_SCU_THERMAL)
@@ -67,12 +75,12 @@ static int cpu_imx_get_temp(struct cpu_imx_platdata *plat)
 {
 	struct udevice *thermal_dev;
 	int cpu_tmp, ret;
+	int idx = 1; /* use "cpu-thermal0" device */
 
-	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 (plat->cpu_rsrc == SC_R_A72)
+		idx = 2; /* use "cpu-thermal1" device */
 
+	ret = uclass_get_device(UCLASS_THERMAL, idx, &thermal_dev);
 	if (!ret) {
 		ret = thermal_get_temp(thermal_dev, &cpu_tmp);
 		if (ret)
@@ -180,19 +188,11 @@ static const struct udevice_id cpu_imx8_ids[] = {
 
 static ulong imx8_get_cpu_rate(struct udevice *dev)
 {
+	struct cpu_imx_platdata *plat = dev_get_platdata(dev);
 	ulong rate;
-	int ret, type;
-
-	if (device_is_compatible(dev, "arm,cortex-a35"))
-		type = SC_R_A35;
-	else if (device_is_compatible(dev, "arm,cortex-a53"))
-		type = SC_R_A53;
-	else if (device_is_compatible(dev, "arm,cortex-a72"))
-		type = SC_R_A72;
-	else
-		return 0;
+	int ret;
 
-	ret = sc_pm_get_clock_rate(-1, type, SC_PM_CLK_CPU,
+	ret = sc_pm_get_clock_rate(-1, plat->cpu_rsrc, SC_PM_CLK_CPU,
 				   (sc_pm_clock_rate_t *)&rate);
 	if (ret) {
 		printf("Could not read CPU frequency: %d\n", ret);
@@ -207,9 +207,9 @@ static int imx8_cpu_probe(struct udevice *dev)
 	struct cpu_imx_platdata *plat = dev_get_platdata(dev);
 	u32 cpurev;
 
+	set_core_data(dev);
 	cpurev = get_cpu_rev();
 	plat->cpurev = cpurev;
-	plat->name = get_core_name(dev);
 	plat->rev = get_imx8_rev(cpurev & 0xFFF);
 	plat->type = get_imx8_type((cpurev & 0xFF000) >> 12);
 	plat->freq_mhz = imx8_get_cpu_rate(dev) / 1000000;
Signature · 1 line
2.17.1
#20 lore raw

PATCH 1/1 cpu: imx8: use intended cpu-thermal device when getting temp value

Quoted 124 lines

Subject: [PATCH] cpu: imx8: use intended cpu-thermal device when getting temp value

This fixes getting DT alert and critical pdata values in imx_scu_thermal driver. On i.MX8QXP using not initialized alert pdata value resulted in boot hang and endless loop outputting:
CPU Temperature (47200C) has beyond alert (0C), close to critical (0C) waiting...

While at it, preset CPU type values once to avoid multiple calls of device_is_compatible() for same property.

Fixes 3ee6ea443eb4 ("cpu: imx_cpu: Print the CPU temperature for iMX8QM

A72")

---
This one supersedes the older patch here:

https://eur01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fpatchw
ork.ozlabs.org%2Fproject%2Fuboot%2Fpatch%2F20200516203420.24409-2-a gust%40denx.de&amp;data=02%7C01%7Cpeng.fan%40nxp.com%7C3a05de6 b676d4479832a08d7fc4ccc4d%7C686ea1d3bc2b4c6fa92cd99c5c301635%7C 0%7C0%7C637255279084654887&amp;sdata=W7kv5XqeSrcxcOHNgE0TgcR8 POPyt3VR4EsWszlFXLI%3D&amp;reserved=0

 drivers/cpu/imx8_cpu.c | 50 +++++++++++++++++++++---------------------
 1 file changed, 25 insertions(+), 25 deletions(-)
drivers/cpu/imx8_cpu.c index renamed from drivers/cpu/imx8_cpu.c +0 -0

896e1ac776..adc4919d9e 100644

drivers/cpu/imx8_cpu.c +26 -26
@@ -18,6 +18,7 @@ struct cpu_imx_platdata {
 	const char *name;
 	const char *rev;
 	const char *type;
+	u32 cpu_rsrc;
 	u32 cpurev;
 	u32 freq_mhz;
 	u32 mpidr;
@@ -50,16 +51,23 @@ const char *get_imx8_rev(u32 rev)
 	}
 }
 
-const char *get_core_name(struct udevice *dev)
+static void set_core_data(struct udevice *dev)
 {
-	if (device_is_compatible(dev, "arm,cortex-a35"))
-		return "A35";
-	else if (device_is_compatible(dev, "arm,cortex-a53"))
-		return "A53";
-	else if (device_is_compatible(dev, "arm,cortex-a72"))
-		return "A72";
-	else
-		return "?";
+	struct cpu_imx_platdata *plat = dev_get_platdata(dev);
+
+	if (device_is_compatible(dev, "arm,cortex-a35")) {
+		plat->cpu_rsrc = SC_R_A35;
+		plat->name = "A35";
+	} else if (device_is_compatible(dev, "arm,cortex-a53")) {
+		plat->cpu_rsrc = SC_R_A53;
+		plat->name = "A53";
+	} else if (device_is_compatible(dev, "arm,cortex-a72")) {
+		plat->cpu_rsrc = SC_R_A72;
+		plat->name = "A72";
+	} else {
+		plat->cpu_rsrc = SC_R_A53;
+		plat->name = "?";
+	}
 }
 
 #if IS_ENABLED(CONFIG_IMX_SCU_THERMAL)
@@ -67,12 +75,12 @@ static int cpu_imx_get_temp(struct cpu_imx_platdata
 *plat)  {
 	struct udevice *thermal_dev;
 	int cpu_tmp, ret;
+	int idx = 1; /* use "cpu-thermal0" device */
 
-	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 (plat->cpu_rsrc == SC_R_A72)
+		idx = 2; /* use "cpu-thermal1" device */
 
+	ret = uclass_get_device(UCLASS_THERMAL, idx, &thermal_dev);
 	if (!ret) {
 		ret = thermal_get_temp(thermal_dev, &cpu_tmp);
 		if (ret)
@@ -180,19 +188,11 @@ static const struct udevice_id cpu_imx8_ids[] = {
 
 static ulong imx8_get_cpu_rate(struct udevice *dev)  {
+	struct cpu_imx_platdata *plat = dev_get_platdata(dev);
 	ulong rate;
-	int ret, type;
-
-	if (device_is_compatible(dev, "arm,cortex-a35"))
-		type = SC_R_A35;
-	else if (device_is_compatible(dev, "arm,cortex-a53"))
-		type = SC_R_A53;
-	else if (device_is_compatible(dev, "arm,cortex-a72"))
-		type = SC_R_A72;
-	else
-		return 0;
+	int ret;
 
-	ret = sc_pm_get_clock_rate(-1, type, SC_PM_CLK_CPU,
+	ret = sc_pm_get_clock_rate(-1, plat->cpu_rsrc, SC_PM_CLK_CPU,
 				   (sc_pm_clock_rate_t *)&rate);
 	if (ret) {
 		printf("Could not read CPU frequency: %d\n", ret); @@ -207,9
+207,9 @@ static int imx8_cpu_probe(struct udevice *dev)
 	struct cpu_imx_platdata *plat = dev_get_platdata(dev);
 	u32 cpurev;
 
+	set_core_data(dev);
 	cpurev = get_cpu_rev();
 	plat->cpurev = cpurev;
-	plat->name = get_core_name(dev);
 	plat->rev = get_imx8_rev(cpurev & 0xFFF);
 	plat->type = get_imx8_type((cpurev & 0xFF000) >> 12);
 	plat->freq_mhz = imx8_get_cpu_rate(dev) / 1000000;
--
Quoted 1 line

2.17.1

author Applied
#21 lore raw

PATCH 1/1 cpu: imx8: use intended cpu-thermal device when getting temp value

In reply to Anatolij Gustschin
Quoted 8 lines · On Wed, 20 May 2020 01:31:44 +0200 Anatolij Gustschin agust at denx.de wrote:

This fixes getting DT alert and critical pdata values in imx_scu_thermal driver. On i.MX8QXP using not initialized alert pdata value resulted in boot hang and endless loop outputting:
CPU Temperature (47200C) has beyond alert (0C), close to critical (0C) waiting...

While at it, preset CPU type values once to avoid multiple calls of device_is_compatible() for same property.

Quoted 8 lines
Fixes 3ee6ea443eb4 ("cpu: imx_cpu: Print the CPU temperature for iMX8QM A72")

---
This one supersedes the older patch here:
http://patchwork.ozlabs.org/project/uboot/patch/20200516203420.24409-2-agust at denx.de

 drivers/cpu/imx8_cpu.c | 50 +++++++++++++++++++++---------------------
 1 file changed, 25 insertions(+), 25 deletions(-)

Applied.

--
Anatolij