Skip to contentSkip to conversation

Add thermal management support for STi platform

PATCH Superseded Raphael Gallais-Pou 2 participants 5 messages Jul 14, 2024 – Jul 16, 2024

Subsystems (2)

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

v3 cover Add thermal management support for STi platform

This patch series enhances the st_thermal driver in order to enable support for thermal zones. The changes include:

1. Replace deprecated PM runtime macros with their updated counterparts.
2. Implementing devm_* based thermal of zone functions within the driver.
3. Updating the stih418 device-tree.

The device-tree patch depends on an earlier patch sent to the mailing list [1].

As it is currently implemented, an alert threshold of 85°C is set to trigger the CPU throttling, and when the temperature exceeds the critical threshold of 95°C, the system shuts down. There is for now no active cooling device on the platform, which explains the use of the cpufreq framework.

[1] https://lore.kernel.org/lkml/[email protected]

---
Changes in v3:
- Fix unmet dependency in [2/2]
- Remove no more used variable in [2/2]
- Remove already merged patch in soc tree
- Link to v2: https://lore.kernel.org/r/[email protected]

Changes in v2:
- Add Patrice's R-b
- Edit patch [2/3] to remove unused struct
- Link to v1: https://lore.kernel.org/r/[email protected]

---
Raphael Gallais-Pou (2):
thermal: st: switch from CONFIG_PM_SLEEP guards to pm_sleep_ptr()
thermal: sti: depend on THERMAL_OF subsystem

 drivers/thermal/st/Kconfig             |  2 ++
 drivers/thermal/st/st_thermal.c        | 32 +++++++++++---------------------
 drivers/thermal/st/st_thermal_memmap.c |  2 +-
 drivers/thermal/st/stm_thermal.c       |  8 +++-----
 4 files changed, 17 insertions(+), 27 deletions(-)

---
base-commit: 3fe121b622825ff8cc995a1e6b026181c48188db
change-id: 20240518-thermal-8f625428acf9

Best regards,

Signature · 1 line
Raphael Gallais-Pou <[email protected]>
#1 lore raw

PATCH v3 1/2 thermal: st: switch from CONFIG_PM_SLEEP guards to pm_sleep_ptr()

Letting the compiler remove these functions when the kernel is built without CONFIG_PM_SLEEP support is simpler and less error prone than the use of #ifdef based kernel configuration guards.

Remove those guards on every ST thermal related drivers.

---
 drivers/thermal/st/st_thermal.c        | 4 +---
 drivers/thermal/st/st_thermal_memmap.c | 2 +-
 drivers/thermal/st/stm_thermal.c       | 8 +++-----
 3 files changed, 5 insertions(+), 9 deletions(-)
drivers/thermal/st/st_thermal.c +1 -3
index 2a105409864e..5f33543a3a54 100644
@@ -236,7 +236,6 @@ void st_thermal_unregister(struct platform_device *pdev)
 }
 EXPORT_SYMBOL_GPL(st_thermal_unregister);
 
-#ifdef CONFIG_PM_SLEEP
 static int st_thermal_suspend(struct device *dev)
 {
 	struct st_thermal_sensor *sensor = dev_get_drvdata(dev);
@@ -265,9 +264,8 @@ static int st_thermal_resume(struct device *dev)
 
 	return 0;
 }
-#endif
 
-SIMPLE_DEV_PM_OPS(st_thermal_pm_ops, st_thermal_suspend, st_thermal_resume);
+DEFINE_SIMPLE_DEV_PM_OPS(st_thermal_pm_ops, st_thermal_suspend, st_thermal_resume);
 EXPORT_SYMBOL_GPL(st_thermal_pm_ops);
 
 MODULE_AUTHOR("STMicroelectronics (R&D) Limited <[email protected]>");
drivers/thermal/st/st_thermal_memmap.c +1 -1
index 29c2269b0fb3..28b380013956 100644
@@ -180,7 +180,7 @@ static void st_mmap_remove(struct platform_device *pdev)
 static struct platform_driver st_mmap_thermal_driver = {
 	.driver = {
 		.name	= "st_thermal_mmap",
-		.pm     = &st_thermal_pm_ops,
+		.pm     = pm_sleep_ptr(&st_thermal_pm_ops),
 		.of_match_table = st_mmap_thermal_of_match,
 	},
 	.probe		= st_mmap_probe,
drivers/thermal/st/stm_thermal.c +3 -5
index 34785b9276fc..ffd988600ed6 100644
@@ -440,7 +440,6 @@ static int stm_thermal_prepare(struct stm_thermal_sensor *sensor)
 	return ret;
 }
 
-#ifdef CONFIG_PM_SLEEP
 static int stm_thermal_suspend(struct device *dev)
 {
 	struct stm_thermal_sensor *sensor = dev_get_drvdata(dev);
@@ -466,10 +465,9 @@ static int stm_thermal_resume(struct device *dev)
 
 	return 0;
 }
-#endif /* CONFIG_PM_SLEEP */
 
-static SIMPLE_DEV_PM_OPS(stm_thermal_pm_ops,
-			 stm_thermal_suspend, stm_thermal_resume);
+static DEFINE_SIMPLE_DEV_PM_OPS(stm_thermal_pm_ops,
+				stm_thermal_suspend, stm_thermal_resume);
 
 static const struct thermal_zone_device_ops stm_tz_ops = {
 	.get_temp	= stm_thermal_get_temp,
@@ -580,7 +578,7 @@ static void stm_thermal_remove(struct platform_device *pdev)
 static struct platform_driver stm_thermal_driver = {
 	.driver = {
 		.name	= "stm_thermal",
-		.pm     = &stm_thermal_pm_ops,
+		.pm     = pm_sleep_ptr(&stm_thermal_pm_ops),
 		.of_match_table = stm_thermal_of_match,
 	},
 	.probe		= stm_thermal_probe,
Signature · 1 line
2.45.2
#2 lore raw

PATCH v3 2/2 thermal: sti: depend on THERMAL_OF subsystem

In reply to Raphael Gallais-Pou

Switch to thermal_of_zone to handle thermal-zones. Replace thermal_zone_device_register() by devm_thermal_of_zone_register() and remove ops st_thermal_get_trip_type, st_thermal_get_trip_temp.

---
Changes in v3:
- Fix unmet dependency when building with ARM64 compiler
https://lore.kernel.org/lkml/[email protected]/
- Remove no more used polling_delay variable detected by kernel robot
https://lore.kernel.org/lkml/[email protected]/
Changes in v2:
- Remove unused struct thermal_trip trip

---
 drivers/thermal/st/Kconfig      |  2 ++
 drivers/thermal/st/st_thermal.c | 28 ++++++++++------------------
 2 files changed, 12 insertions(+), 18 deletions(-)
drivers/thermal/st/Kconfig +2 -0
index ecbdf4ef00f4..95a634709a99 100644
@@ -5,12 +5,14 @@
 
 config ST_THERMAL
 	tristate "Thermal sensors on STMicroelectronics STi series of SoCs"
+	depends on THERMAL_OF
 	help
 	  Support for thermal sensors on STMicroelectronics STi series of SoCs.
 
 config ST_THERMAL_MEMMAP
 	select ST_THERMAL
 	tristate "STi series memory mapped access based thermal sensors"
+	depends on THERMAL_OF
 
 config STM32_THERMAL
 	tristate "Thermal framework support on STMicroelectronics STM32 series of SoCs"
drivers/thermal/st/st_thermal.c +10 -18
index 5f33543a3a54..23597819ce84 100644
@@ -12,6 +12,7 @@
 #include <linux/of_device.h>
 
 #include "st_thermal.h"
+#include "../thermal_hwmon.h"
 
 /* The Thermal Framework expects millidegrees */
 #define mcelsius(temp)			((temp) * 1000)
@@ -135,8 +136,6 @@ static struct thermal_zone_device_ops st_tz_ops = {
 	.get_temp	= st_thermal_get_temp,
 };
 
-static struct thermal_trip trip;
-
 int st_thermal_register(struct platform_device *pdev,
 			const struct of_device_id *st_thermal_of_match)
 {
@@ -145,7 +144,6 @@ int st_thermal_register(struct platform_device *pdev,
 	struct device_node *np = dev->of_node;
 	const struct of_device_id *match;
 
-	int polling_delay;
 	int ret;
 
 	if (!np) {
@@ -197,29 +195,22 @@ int st_thermal_register(struct platform_device *pdev,
 	if (ret)
 		goto sensor_off;
 
-	polling_delay = sensor->ops->register_enable_irq ? 0 : 1000;
-
-	trip.temperature = sensor->cdata->crit_temp;
-	trip.type = THERMAL_TRIP_CRITICAL;
-
 	sensor->thermal_dev =
-		thermal_zone_device_register_with_trips(dev_name(dev), &trip, 1, sensor,
-							&st_tz_ops, NULL, 0, polling_delay);
+		devm_thermal_of_zone_register(dev, 0, sensor, &st_tz_ops);
 	if (IS_ERR(sensor->thermal_dev)) {
-		dev_err(dev, "failed to register thermal zone device\n");
+		dev_err(dev, "failed to register thermal of zone\n");
 		ret = PTR_ERR(sensor->thermal_dev);
 		goto sensor_off;
 	}
-	ret = thermal_zone_device_enable(sensor->thermal_dev);
-	if (ret)
-		goto tzd_unregister;
 
 	platform_set_drvdata(pdev, sensor);
 
-	return 0;
+	/*
+	 * devm_thermal_of_zone_register() doesn't enable hwmon by default
+	 * Enable it here
+	 */
+	return devm_thermal_add_hwmon_sysfs(dev, sensor->thermal_dev);
 
-tzd_unregister:
-	thermal_zone_device_unregister(sensor->thermal_dev);
 sensor_off:
 	st_thermal_sensor_off(sensor);
 
@@ -232,7 +223,8 @@ void st_thermal_unregister(struct platform_device *pdev)
 	struct st_thermal_sensor *sensor = platform_get_drvdata(pdev);
 
 	st_thermal_sensor_off(sensor);
-	thermal_zone_device_unregister(sensor->thermal_dev);
+	thermal_remove_hwmon_sysfs(sensor->thermal_dev);
+	devm_thermal_of_zone_unregister(sensor->dev, sensor->thermal_dev);
 }
 EXPORT_SYMBOL_GPL(st_thermal_unregister);
 
Signature · 1 line
2.45.2
#3 lore raw

Re: [PATCH v3 2/2] thermal: sti: depend on THERMAL_OF subsystem

Quoted 24 lines · Raphael Gallais-Pou

Switch to thermal_of_zone to handle thermal-zones. Replace thermal_zone_device_register() by devm_thermal_of_zone_register() and remove ops st_thermal_get_trip_type, st_thermal_get_trip_temp.

---
Changes in v3:
- Fix unmet dependency when building with ARM64 compiler
https://lore.kernel.org/lkml/[email protected]/
- Remove no more used polling_delay variable detected by kernel robot
https://lore.kernel.org/lkml/[email protected]/
Changes in v2:
- Remove unused struct thermal_trip trip

---
  drivers/thermal/st/Kconfig      |  2 ++
  drivers/thermal/st/st_thermal.c | 28 ++++++++++------------------
  2 files changed, 12 insertions(+), 18 deletions(-)
drivers/thermal/st/Kconfig +0 -0
index ecbdf4ef00f4..95a634709a99 100644
@@ -5,12 +5,14 @@
 

drivers/thermal/st/Kconfig line 15

Quoted 10 lines
drivers/thermal/st/Kconfig +2 -0
  config ST_THERMAL
  	tristate "Thermal sensors on STMicroelectronics STi series of SoCs"
+	depends on THERMAL_OF
  	help
  	  Support for thermal sensors on STMicroelectronics STi series of SoCs.
 
  config ST_THERMAL_MEMMAP
  	select ST_THERMAL
  	tristate "STi series memory mapped access based thermal sensors"
+	depends on THERMAL_OF

Given the changes below it is possible to move this dependency in the upper Kconfig AFAICS:

drivers/thermal/Kconfig +1 -1
index ed16897584b4..b6b916e7e294 100644
@@ -429,7 +429,7 @@ source "drivers/thermal/samsung/Kconfig"
 endmenu
 
 menu "STMicroelectronics thermal drivers"
-depends on (ARCH_STI || ARCH_STM32) && OF
+depends on (ARCH_STI || ARCH_STM32) && THERMAL_OF
 source "drivers/thermal/st/Kconfig"
 endmenu
 

THERMAL_OF depends on OF

Quoted 52 lines
drivers/thermal/st/Kconfig +0 -0
  config STM32_THERMAL
  	tristate "Thermal framework support on STMicroelectronics STM32 series of SoCs"
drivers/thermal/st/st_thermal.c +3 -13
index 5f33543a3a54..23597819ce84 100644
@@ -12,6 +12,7 @@
  #include <linux/of_device.h>
 
  #include "st_thermal.h"
+#include "../thermal_hwmon.h"
 
  /* The Thermal Framework expects millidegrees */
  #define mcelsius(temp)			((temp) * 1000)
@@ -135,8 +136,6 @@ static struct thermal_zone_device_ops st_tz_ops = {
  	.get_temp	= st_thermal_get_temp,
  };
 
-static struct thermal_trip trip;
-
  int st_thermal_register(struct platform_device *pdev,
  			const struct of_device_id *st_thermal_of_match)
  {
@@ -145,7 +144,6 @@ int st_thermal_register(struct platform_device *pdev,
  	struct device_node *np = dev->of_node;
  	const struct of_device_id *match;
 
-	int polling_delay;
  	int ret;
 
  	if (!np) {
@@ -197,29 +195,22 @@ int st_thermal_register(struct platform_device *pdev,
  	if (ret)
  		goto sensor_off;
 
-	polling_delay = sensor->ops->register_enable_irq ? 0 : 1000;
-
-	trip.temperature = sensor->cdata->crit_temp;
-	trip.type = THERMAL_TRIP_CRITICAL;
-
  	sensor->thermal_dev =
-		thermal_zone_device_register_with_trips(dev_name(dev), &trip, 1, sensor,
-							&st_tz_ops, NULL, 0, polling_delay);
+		devm_thermal_of_zone_register(dev, 0, sensor, &st_tz_ops);
  	if (IS_ERR(sensor->thermal_dev)) {
-		dev_err(dev, "failed to register thermal zone device\n");
+		dev_err(dev, "failed to register thermal of zone\n");
  		ret = PTR_ERR(sensor->thermal_dev);
  		goto sensor_off;
  	}
-	ret = thermal_zone_device_enable(sensor->thermal_dev);
-	if (ret)

drivers/thermal/st/st_thermal.c int st_thermal_register(struct platform_device *pdev, · line 212

Quoted 10 lines
drivers/thermal/st/st_thermal.c +5 -2
-		goto tzd_unregister;
 
  	platform_set_drvdata(pdev, sensor);
 
-	return 0;
+	/*
+	 * devm_thermal_of_zone_register() doesn't enable hwmon by default
+	 * Enable it here
+	 */
+	return devm_thermal_add_hwmon_sysfs(dev, sensor->thermal_dev);

Other drivers ignore the return code or just print a message in case it is not zero. Otherwise, that makes the thermal driver to fail because of hwmon.

Quoted 16 lines
drivers/thermal/st/st_thermal.c +2 -3
-tzd_unregister:
-	thermal_zone_device_unregister(sensor->thermal_dev);
  sensor_off:
  	st_thermal_sensor_off(sensor);
 
@@ -232,7 +223,8 @@ void st_thermal_unregister(struct platform_device *pdev)
  	struct st_thermal_sensor *sensor = platform_get_drvdata(pdev);
 
  	st_thermal_sensor_off(sensor);
-	thermal_zone_device_unregister(sensor->thermal_dev);
+	thermal_remove_hwmon_sysfs(sensor->thermal_dev);
+	devm_thermal_of_zone_unregister(sensor->dev, sensor->thermal_dev);
  }
  EXPORT_SYMBOL_GPL(st_thermal_unregister);
 
Signature · 6 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
"
#4 lore raw

Re: [PATCH v3 2/2] thermal: sti: depend on THERMAL_OF subsystem

Le 16/07/2024 à 15:07, Daniel Lezcano a écrit :

Quoted 49 lines · Raphael Gallais-Pou
Quoted 24 lines

Switch to thermal_of_zone to handle thermal-zones. Replace thermal_zone_device_register() by devm_thermal_of_zone_register() and remove ops st_thermal_get_trip_type, st_thermal_get_trip_temp.

---
Changes in v3:
- Fix unmet dependency when building with ARM64 compiler
   https://lore.kernel.org/lkml/[email protected]/
- Remove no more used polling_delay variable detected by kernel robot
   https://lore.kernel.org/lkml/[email protected]/
Changes in v2:
- Remove unused struct thermal_trip trip
---
  drivers/thermal/st/Kconfig      |  2 ++ drivers/thermal/st/st_thermal.c | 28 ++++++++++------------------

  2 files changed, 12 insertions(+), 18 deletions(-)
drivers/thermal/st/Kconfig +0 -0
index ecbdf4ef00f4..95a634709a99 100644
@@ -5,12 +5,14 @@

  config ST_THERMAL

Quoted 8 lines

      tristate "Thermal sensors on STMicroelectronics STi series of SoCs" +    depends on THERMAL_OF
      help
        Support for thermal sensors on STMicroelectronics STi series of SoCs. config ST_THERMAL_MEMMAP
      select ST_THERMAL
      tristate "STi series memory mapped access based thermal sensors" +    depends on THERMAL_OF

Given the changes below it is possible to move this dependency in the upper Kconfig AFAICS:

drivers/thermal/Kconfig +1 -1
index ed16897584b4..b6b916e7e294 100644
@@ -429,7 +429,7 @@ source "drivers/thermal/samsung/Kconfig"
  endmenu
 
  menu "STMicroelectronics thermal drivers"
-depends on (ARCH_STI || ARCH_STM32) && OF
+depends on (ARCH_STI || ARCH_STM32) && THERMAL_OF
  source "drivers/thermal/st/Kconfig"
  endmenu
 
Quoted 1 line

THERMAL_OF depends on OF

Hi Daniel,

Thanks for your review.

Indeed, it makes more sense. I'll change this and remove the "depends on THERMAL_OF" on st/ level.

Quoted 51 lines
Quoted 51 lines

  config STM32_THERMAL
      tristate "Thermal framework support on STMicroelectronics STM32 series of SoCs"

drivers/thermal/st/st_thermal.c +1 -8
index 5f33543a3a54..23597819ce84 100644
@@ -12,6 +12,7 @@
   #include <linux/of_device.h>
   #include "st_thermal.h"
+#include "../thermal_hwmon.h"
   /* The Thermal Framework expects millidegrees */
   #define mcelsius(temp)            ((temp) * 1000)
@@ -135,8 +136,6 @@ static struct thermal_zone_device_ops st_tz_ops = {
       .get_temp    = st_thermal_get_temp,
   };
-static struct thermal_trip trip;
-
   int st_thermal_register(struct platform_device *pdev,
               const struct of_device_id *st_thermal_of_match)
   {
@@ -145,7 +144,6 @@ int st_thermal_register(struct platform_device *pdev,
       struct device_node *np = dev->of_node;
       const struct of_device_id *match;
-    int polling_delay;
       int ret;
       if (!np) {
@@ -197,29 +195,22 @@ int st_thermal_register(struct platform_device 
 *pdev,
       if (ret)
           goto sensor_off;
-    polling_delay = sensor->ops->register_enable_irq ? 0 : 1000;
-
-    trip.temperature = sensor->cdata->crit_temp;
-    trip.type = THERMAL_TRIP_CRITICAL;
-

      sensor->thermal_dev =
-        thermal_zone_device_register_with_trips(dev_name(dev), &trip, 1, sensor,
-                            &st_tz_ops, NULL, 0, polling_delay); +        devm_thermal_of_zone_register(dev, 0, sensor, &st_tz_ops); if (IS_ERR(sensor->thermal_dev)) {
-        dev_err(dev, "failed to register thermal zone device\n"); +        dev_err(dev, "failed to register thermal of zone\n"); ret = PTR_ERR(sensor->thermal_dev);
          goto sensor_off;
      }
-    ret = thermal_zone_device_enable(sensor->thermal_dev); -    if (ret)
-        goto tzd_unregister;
      platform_set_drvdata(pdev, sensor);

Quoted 8 lines
Quoted 6 lines

-    return 0;
+    /*
+     * devm_thermal_of_zone_register() doesn't enable hwmon by default +     * Enable it here
+     */
+    return devm_thermal_add_hwmon_sysfs(dev, sensor->thermal_dev);

Other drivers ignore the return code or just print a message in case it is not zero. Otherwise, that makes the thermal driver to fail because of hwmon.

Indeed. I figured that since an error code is yielded only by hwmon when it fails, it seems logical to make the thermal driver fail as well since it depends on hwmon. Maybe I understood something wrong.

Does tying thermal to hwmon is a bad practice ?

Regards,
Raphaël

Quoted 16 lines
Quoted 15 lines

-tzd_unregister:
-    thermal_zone_device_unregister(sensor->thermal_dev); sensor_off:
      st_thermal_sensor_off(sensor);

drivers/thermal/st/st_thermal.c +2 -1
@@ -232,7 +223,8 @@ void st_thermal_unregister(struct platform_device 
 *pdev)
       struct st_thermal_sensor *sensor = platform_get_drvdata(pdev);
       st_thermal_sensor_off(sensor);
-    thermal_zone_device_unregister(sensor->thermal_dev);
+    thermal_remove_hwmon_sysfs(sensor->thermal_dev);
+    devm_thermal_of_zone_unregister(sensor->dev, sensor->thermal_dev);
   }
   EXPORT_SYMBOL_GPL(st_thermal_unregister);