diff mbox series

[RFC,v2,7/9] thermal: core: Monitor thermal zone after mode change

Message ID 20200414180105.20042-8-andrzej.p@collabora.com (mailing list archive)
State New, archived
Headers show
Series [RFC,v2,1/9] thermal: int3400_thermal: Statically initialize .get_mode()/.set_mode() ops | expand

Commit Message

Andrzej Pietrasiewicz April 14, 2020, 6:01 p.m. UTC
Mode changing might imply a need to stop/start polling the device.
monitor_thermal_zone() when mode changes.

Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com>
---
 drivers/thermal/thermal_core.c  | 2 +-
 drivers/thermal/thermal_core.h  | 2 ++
 drivers/thermal/thermal_sysfs.c | 7 +++++++
 3 files changed, 10 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c
index a59c3411fb9c..7637ddb79813 100644
--- a/drivers/thermal/thermal_core.c
+++ b/drivers/thermal/thermal_core.c
@@ -305,7 +305,7 @@  static void thermal_zone_device_set_polling(struct thermal_zone_device *tz,
 		cancel_delayed_work(&tz->poll_queue);
 }
 
-static void monitor_thermal_zone(struct thermal_zone_device *tz)
+void monitor_thermal_zone(struct thermal_zone_device *tz)
 {
 	mutex_lock(&tz->lock);
 
diff --git a/drivers/thermal/thermal_core.h b/drivers/thermal/thermal_core.h
index a9bf00e91d64..469258778161 100644
--- a/drivers/thermal/thermal_core.h
+++ b/drivers/thermal/thermal_core.h
@@ -89,6 +89,8 @@  thermal_cooling_device_stats_update(struct thermal_cooling_device *cdev,
 				    unsigned long new_state) {}
 #endif /* CONFIG_THERMAL_STATISTICS */
 
+void monitor_thermal_zone(struct thermal_zone_device *tz);
+
 /* device tree support */
 #ifdef CONFIG_THERMAL_OF
 int of_parse_thermal_zones(void);
diff --git a/drivers/thermal/thermal_sysfs.c b/drivers/thermal/thermal_sysfs.c
index cbb27b3c96d2..bc34d0f9768b 100644
--- a/drivers/thermal/thermal_sysfs.c
+++ b/drivers/thermal/thermal_sysfs.c
@@ -62,11 +62,14 @@  mode_store(struct device *dev, struct device_attribute *attr,
 	   const char *buf, size_t count)
 {
 	struct thermal_zone_device *tz = to_thermal_zone(dev);
+	enum thermal_device_mode old_mode, mode;
 	int result;
 
 	if (!tz->ops->set_mode)
 		return -EPERM;
 
+	old_mode = thermal_zone_device_get_mode(tz);
+
 	if (!strncmp(buf, "enabled", sizeof("enabled") - 1))
 		result = thermal_zone_device_enable(tz);
 	else if (!strncmp(buf, "disabled", sizeof("disabled") - 1))
@@ -77,6 +80,10 @@  mode_store(struct device *dev, struct device_attribute *attr,
 	if (result)
 		return result;
 
+	mode = thermal_zone_device_get_mode(tz);
+	if (mode != old_mode)
+		monitor_thermal_zone(tz);
+
 	return count;
 }