Skip to contentSkip to conversation

Allow OF created trip points to be writablee

PATCH New Punit Agrawal 1 participant 3 messages Mar 3, 2015 Thermal

lore
Share & tools
lore
#0 lore raw

cover Allow OF created trip points to be writablee

Hi Eduardo,

I am re-sending the patch to enable writable-trips when using OF thermal along with the Kconfig change to allow disabling updatable trip points in the config.

The first patch adds a Kconfig option to disable writable trip points. The Kconfig option overrides the preference specified at thermal zone registration and should be enabled for trips to be writable.

The second patch defaults OF defined trip points to be writable. This is useful for system tuning, but also for production systems having a userspace component that can adjust trip points at runtime.

The requirement of root privileges to update trip points is not affected by these patches.

All comments welcome.

Cheers,
Punit

Punit Agrawal (2):
thermal: Default OF created trip points to writable
thermal: core: Add Kconfig option to enable writable trips

 drivers/thermal/Kconfig        | 11 +++++++++++
 drivers/thermal/of-thermal.c   |  6 +++++-
 drivers/thermal/thermal_core.c |  3 ++-
 3 files changed, 18 insertions(+), 2 deletions(-)
Signature · 1 line
2.1.4
#1 lore raw

PATCH 1/2 thermal: core: Add Kconfig option to enable writable trips

Add a Kconfig option to allow system integrators to control whether userspace tools can change trip temperatures. This option overrides the thermal zone setup in the driver code and must be enabled for platform specified writable trips to come into effect.

The original behaviour of requiring root privileges to change trip temperatures remains unchanged.

Cc Eduardo Valentin <[email protected]>
Cc Zhang Rui <[email protected]>
---
 drivers/thermal/Kconfig        | 11 +++++++++++
 drivers/thermal/thermal_core.c |  3 ++-
 2 files changed, 13 insertions(+), 1 deletion(-)
drivers/thermal/Kconfig +11 -0
index af40db0..5d2d39b 100644
@@ -42,6 +42,17 @@ config THERMAL_OF
 	  Say 'Y' here if you need to build thermal infrastructure
 	  based on device tree.
 
+config THERMAL_WRITABLE_TRIPS
+	bool "Enable writable trip points"
+	help
+	  This option allows the system integrator to choose whether
+	  trip temperatures can be changed from userspace. The
+	  writable trips need to be specified when setting up the
+	  thermal zone but the choice here takes precedence.
+
+	  Say 'Y' here if you would like to allow userspace tools to
+	  change trip temperatures.
+
 choice
 	prompt "Default Thermal governor"
 	default THERMAL_DEFAULT_GOV_STEP_WISE
drivers/thermal/thermal_core.c +2 -1
index 48491d1..15111c1 100644
@@ -1378,7 +1378,8 @@ static int create_trip_attrs(struct thermal_zone_device *tz, int mask)
 						tz->trip_temp_attrs[indx].name;
 		tz->trip_temp_attrs[indx].attr.attr.mode = S_IRUGO;
 		tz->trip_temp_attrs[indx].attr.show = trip_point_temp_show;
-		if (mask & (1 << indx)) {
+		if (IS_ENABLED(CONFIG_THERMAL_WRITABLE_TRIPS) &&
+		    mask & (1 << indx)) {
 			tz->trip_temp_attrs[indx].attr.attr.mode |= S_IWUSR;
 			tz->trip_temp_attrs[indx].attr.store =
 							trip_point_temp_store;
Signature · 1 line
2.1.4
#2 lore raw

PATCH 2/2 thermal: Default OF created trip points to writable

In reply to Punit Agrawal

When registering a thermal zone from device tree, default the trip points to writable. By default, only the root user can change these.

This allows the trip points to be tweaked after the system has booted.

Cc Eduardo Valentin <[email protected]>
Cc Zhang Rui <[email protected]>
---
 drivers/thermal/of-thermal.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/thermal/of-thermal.c +5 -1
index 668fb1b..b7ad5c0 100644
@@ -865,6 +865,7 @@ int __init of_parse_thermal_zones(void)
 	for_each_child_of_node(np, child) {
 		struct thermal_zone_device *zone;
 		struct thermal_zone_params *tzp;
+		int i, mask = 0;
 
 		/* Check whether child is enabled or not */
 		if (!of_device_is_available(child))
@@ -891,8 +892,11 @@ int __init of_parse_thermal_zones(void)
 		/* No hwmon because there might be hwmon drivers registering */
 		tzp->no_hwmon = true;
 
+		for (i = 0; i < tz->ntrips; i++)
+			mask |= 1 << i;
+
 		zone = thermal_zone_device_register(child->name, tz->ntrips,
-						    0, tz,
+						    mask, tz,
 						    ops, tzp,
 						    tz->passive_delay,
 						    tz->polling_delay);
Signature · 1 line
2.1.4