Skip to contentSkip to conversation

thermal: imx8mm: Allow reboot after critical temperature

PATCH Superseded Fabio Estevam 2 participants 3 messages Aug 24, 2023

Subsystems (2)

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Fabio Estevam

author reviewer
#0 lore raw

PATCH v2 1/1 thermal: imx8mm: Allow reboot after critical temperature

From: Fabio Estevam <[email protected]>

Currently, after the board reaches the critical temperature, the system goes through a poweroff mechanism.

In some cases, such behavior does not suit well, as the board may be unattended in the field and rebooting may be a better approach.

The bootloader may also check the temperature and only allow the boot to proceed when the temperature is below a certain threshold.

Introduce a reboot_on_critical parameter to indicate that the board will go through a reboot after the critical temperature is reached.

When this parameter is not selected, the default behavior of forcing a shutdown is preserved.

Tested on a imx8mm-evk board by passing 'imx8mm_thermal.reboot_on_critical' via kernel command line.

---
Changes since v1:
- Introduce a module_param() instead of a devicetree property.

 drivers/thermal/imx8mm_thermal.c | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)
drivers/thermal/imx8mm_thermal.c +19 -0
index e89b11b3f2b9..2427bd46ac6c 100644
@@ -10,9 +10,11 @@
 #include <linux/err.h>
 #include <linux/io.h>
 #include <linux/module.h>
+#include <linux/moduleparam.h>
 #include <linux/nvmem-consumer.h>
 #include <linux/of.h>
 #include <linux/platform_device.h>
+#include <linux/reboot.h>
 #include <linux/slab.h>
 #include <linux/thermal.h>
 
@@ -75,6 +77,11 @@
 #define TMU_VER1		0x1
 #define TMU_VER2		0x2
 
+static bool reboot_on_critical;
+module_param(reboot_on_critical, bool, 0444);
+MODULE_PARM_DESC(reboot_on_critical,
+		 "Reboot the system after the critical temperature is reached.");
+
 struct thermal_soc_data {
 	u32 num_sensors;
 	u32 version;
@@ -146,8 +153,20 @@ static int tmu_get_temp(struct thermal_zone_device *tz, int *temp)
 	return tmu->socdata->get_temp(sensor, temp);
 }
 
+static void tmu_critical(struct thermal_zone_device *tz)
+{
+	if (reboot_on_critical) {
+		dev_emerg(thermal_zone_device(tz), "%s: critical temperature reached\n",
+			  thermal_zone_device_type(tz));
+		kernel_restart(NULL);
+	} else {
+		thermal_zone_device_critical(tz);
+	}
+}
+
 static const struct thermal_zone_device_ops tmu_tz_ops = {
 	.get_temp = tmu_get_temp,
+	.critical = tmu_critical,
 };
 
 static void imx8mm_tmu_enable(struct imx8mm_tmu *tmu, bool enable)
Signature · 1 line
2.34.1
#1 lore raw

Hi Fabio,

Quoted 60 lines · Fabio Estevam

From: Fabio Estevam <[email protected]>

Currently, after the board reaches the critical temperature, the system goes through a poweroff mechanism.

In some cases, such behavior does not suit well, as the board may be unattended in the field and rebooting may be a better approach.

The bootloader may also check the temperature and only allow the boot to proceed when the temperature is below a certain threshold.

Introduce a reboot_on_critical parameter to indicate that the board will go through a reboot after the critical temperature is reached.

When this parameter is not selected, the default behavior of forcing a shutdown is preserved.

Tested on a imx8mm-evk board by passing 'imx8mm_thermal.reboot_on_critical' via kernel command line.

---
Changes since v1:
- Introduce a module_param() instead of a devicetree property.

  drivers/thermal/imx8mm_thermal.c | 19 +++++++++++++++++++
  1 file changed, 19 insertions(+)
drivers/thermal/imx8mm_thermal.c +7 -0
index e89b11b3f2b9..2427bd46ac6c 100644
@@ -10,9 +10,11 @@
  #include <linux/err.h>
  #include <linux/io.h>
  #include <linux/module.h>
+#include <linux/moduleparam.h>
  #include <linux/nvmem-consumer.h>
  #include <linux/of.h>
  #include <linux/platform_device.h>
+#include <linux/reboot.h>
  #include <linux/slab.h>
  #include <linux/thermal.h>
 
@@ -75,6 +77,11 @@
  #define TMU_VER1		0x1
  #define TMU_VER2		0x2
 
+static bool reboot_on_critical;
+module_param(reboot_on_critical, bool, 0444);
+MODULE_PARM_DESC(reboot_on_critical,
+		 "Reboot the system after the critical temperature is reached.");
+
  struct thermal_soc_data {
  	u32 num_sensors;
  	u32 version;
@@ -146,8 +153,20 @@ static int tmu_get_temp(struct thermal_zone_device *tz, int *temp)
  	return tmu->socdata->get_temp(sensor, temp);
  }
 

drivers/thermal/imx8mm_thermal.c static int tmu_get_temp(struct thermal_zone_device *tz, int *temp) · line 165

Quoted 10 lines
drivers/thermal/imx8mm_thermal.c +10 -0
+static void tmu_critical(struct thermal_zone_device *tz)
+{
+	if (reboot_on_critical) {
+		dev_emerg(thermal_zone_device(tz), "%s: critical temperature reached\n",
+			  thermal_zone_device_type(tz));
+		kernel_restart(NULL);
+	} else {
+		thermal_zone_device_critical(tz);
+	}
+}

Is it possible to set the .critical ops at init time instead and get rid of the thermal_zone_device_critical(tz) call ?

Quoted 6 lines
drivers/thermal/imx8mm_thermal.c +1 -0
  static const struct thermal_zone_device_ops tmu_tz_ops = {
  	.get_temp = tmu_get_temp,
+	.critical = tmu_critical,
  };
 
  static void imx8mm_tmu_enable(struct imx8mm_tmu *tmu, bool enable)
Signature · 5 lines
<http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs

Follow Linaro:  <http://www.facebook.com/pages/Linaro> Facebook |
<http://twitter.com/#!/linaroorg> Twitter |
<http://www.linaro.org/linaro-blog/> Blog
author reviewer
#2 lore raw

Hi Daniel,

Quoted 2 lines · Daniel Lezcano

Is it possible to set the .critical ops at init time instead and get rid of the thermal_zone_device_critical(tz) call ?

Yes, I have just tested your suggestion and it works.

It also looks better :-)

I will send a v3, thanks.