diff mbox series

[v1,09/11] thermal/acpi: Convert the units to milli Celsuis

Message ID 20230203173331.3322089-10-daniel.lezcano@linaro.org
State Superseded
Headers show
Series Generic trip points for ACPI | expand

Commit Message

Daniel Lezcano Feb. 3, 2023, 5:33 p.m. UTC
From: Daniel Lezcano <daniel.lezcano@kernel.org>

The trip points are storing the temperature using the Deci Kelvin
units but the thermal framework expects milli Celsius.

In order to migrate to the generic trip points where the temperature
unit is millicelsius. Let's change the unit, so the resulting code
will be compatible with thermal framework used unit.

Signed-off-by: Daniel Lezcano <daniel.lezcano@kernel.org>
Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
---
 drivers/acpi/thermal.c | 56 ++++++++++++++++++------------------------
 1 file changed, 24 insertions(+), 32 deletions(-)
diff mbox series

Patch

diff --git a/drivers/acpi/thermal.c b/drivers/acpi/thermal.c
index 316a16ac1a09..9122d1c44777 100644
--- a/drivers/acpi/thermal.c
+++ b/drivers/acpi/thermal.c
@@ -177,9 +177,9 @@  static int acpi_thermal_get_temperature(struct acpi_thermal *tz)
 	if (ACPI_FAILURE(status))
 		return -ENODEV;
 
-	tz->temperature = tmp;
+	tz->temperature = deci_kelvin_to_millicelsius(tmp);
 
-	acpi_handle_debug(tz->device->handle, "Temperature is %lu dK\n",
+	acpi_handle_debug(tz->device->handle, "Temperature is %lu m°C\n",
 			  tz->temperature);
 
 	return 0;
@@ -250,7 +250,7 @@  static int acpi_thermal_trips_update_critical(struct acpi_thermal *tz, int flag)
 	unsigned long long tmp;
 
 	status = acpi_evaluate_integer(tz->device->handle, "_CRT", NULL, &tmp);
-	tz->trips[ACPI_THERMAL_TRIP_CRITICAL].temperature = tmp;
+	tz->trips[ACPI_THERMAL_TRIP_CRITICAL].temperature = deci_kelvin_to_millicelsius(tmp);
 	/*
 	 * Treat freezing temperatures as invalid as well; some
 	 * BIOSes return really low values and cause reboots at startup.
@@ -261,7 +261,7 @@  static int acpi_thermal_trips_update_critical(struct acpi_thermal *tz, int flag)
 		tz->trips[ACPI_THERMAL_TRIP_CRITICAL].flags.valid = 0;
 		acpi_handle_debug(tz->device->handle,
 				  "No critical threshold\n");
-	} else if (tmp <= 2732) {
+	} else if (tmp <= 0) {
 		pr_info(FW_BUG "Invalid critical threshold (%llu)\n", tmp);
 		tz->trips[ACPI_THERMAL_TRIP_CRITICAL].flags.valid = 0;
 	} else {
@@ -274,15 +274,15 @@  static int acpi_thermal_trips_update_critical(struct acpi_thermal *tz, int flag)
 		if (crt == -1) {
 			tz->trips[ACPI_THERMAL_TRIP_CRITICAL].flags.valid = 0;
 		} else if (crt > 0) {
-			unsigned long crt_k = celsius_to_deci_kelvin(crt);
+			crt *= MILLIDEGREE_PER_DEGREE;
 
 			/*
 			 * Allow override critical threshold
 			 */
-			if (crt_k > tz->trips[ACPI_THERMAL_TRIP_CRITICAL].temperature)
-				pr_info("Critical threshold %d C\n", crt);
+			if (crt > tz->trips[ACPI_THERMAL_TRIP_CRITICAL].temperature)
+				pr_info("Critical threshold %d m°C\n", crt);
 
-			tz->trips[ACPI_THERMAL_TRIP_CRITICAL].temperature = crt_k;
+			tz->trips[ACPI_THERMAL_TRIP_CRITICAL].temperature = crt;
 		}
 	}
 
@@ -325,10 +325,11 @@  static int acpi_thermal_trips_update_passive(struct acpi_thermal *tz, int flag)
 	if (psv == -1) {
 		status = AE_SUPPORT;
 	} else if (psv > 0) {
-		tmp = celsius_to_deci_kelvin(psv);
+		tmp = psv * MILLIDEGREE_PER_DEGREE;
 		status = AE_OK;
 	} else {
 		status = acpi_evaluate_integer(tz->device->handle, "_PSV", NULL, &tmp);
+		tmp = deci_kelvin_to_millicelsius(tmp);
 	}
 
 	if (ACPI_FAILURE(status))
@@ -411,6 +412,7 @@  static int acpi_thermal_trips_update_active(struct acpi_thermal *tz, int flag)
 		if (flag & ACPI_TRIPS_ACTIVE)  {
 			status = acpi_evaluate_integer(tz->device->handle,
 						       name, NULL, &tmp);
+			tmp = deci_kelvin_to_millicelsius(tmp);
 			if (ACPI_FAILURE(status)) {
 				tz->trips[i].flags.valid = 0;
 				if (i == 0)
@@ -420,7 +422,7 @@  static int acpi_thermal_trips_update_active(struct acpi_thermal *tz, int flag)
 					break;
 
 				if (i == 1)
-					tz->trips[0].temperature = celsius_to_deci_kelvin(act);
+					tz->trips[0].temperature = act * MILLIDEGREE_PER_DEGREE;
 				else
 					/*
 					 * Don't allow override higher than
@@ -428,9 +430,9 @@  static int acpi_thermal_trips_update_active(struct acpi_thermal *tz, int flag)
 					 */
 					tz->trips[i - 1].temperature =
 						(tz->trips[i - 2].temperature <
-						celsius_to_deci_kelvin(act) ?
+						act * MILLIDEGREE_PER_DEGREE ?
 						tz->trips[i - 2].temperature :
-						celsius_to_deci_kelvin(act));
+						act * MILLIDEGREE_PER_DEGREE);
 
 				break;
 			} else {
@@ -546,8 +548,8 @@  static int thermal_get_temp(struct thermal_zone_device *thermal, int *temp)
 	if (result)
 		return result;
 
-	*temp = deci_kelvin_to_millicelsius_with_offset(tz->temperature,
-							tz->kelvin_offset);
+	*temp = tz->temperature;
+
 	return 0;
 }
 
@@ -606,9 +608,7 @@  static int thermal_get_trip_temp(struct thermal_zone_device *thermal,
 
 	if (tz->trips[ACPI_THERMAL_TRIP_CRITICAL].flags.valid) {
 		if (!trip) {
-			*temp = deci_kelvin_to_millicelsius_with_offset(
-					tz->trips[ACPI_THERMAL_TRIP_CRITICAL].temperature,
-					tz->kelvin_offset);
+			*temp = tz->trips[ACPI_THERMAL_TRIP_CRITICAL].temperature;
 			return 0;
 		}
 		trip--;
@@ -616,9 +616,7 @@  static int thermal_get_trip_temp(struct thermal_zone_device *thermal,
 
 	if (tz->trips[ACPI_THERMAL_TRIP_HOT].flags.valid) {
 		if (!trip) {
-			*temp = deci_kelvin_to_millicelsius_with_offset(
-					tz->trips[ACPI_THERMAL_TRIP_HOT].temperature,
-					tz->kelvin_offset);
+			*temp = tz->trips[ACPI_THERMAL_TRIP_HOT].temperature;
 			return 0;
 		}
 		trip--;
@@ -626,9 +624,7 @@  static int thermal_get_trip_temp(struct thermal_zone_device *thermal,
 
 	if (tz->trips[ACPI_THERMAL_TRIP_PASSIVE].flags.valid) {
 		if (!trip) {
-			*temp = deci_kelvin_to_millicelsius_with_offset(
-					tz->trips[ACPI_THERMAL_TRIP_PASSIVE].temperature,
-					tz->kelvin_offset);
+			*temp = tz->trips[ACPI_THERMAL_TRIP_PASSIVE].temperature;
 			return 0;
 		}
 		trip--;
@@ -637,9 +633,7 @@  static int thermal_get_trip_temp(struct thermal_zone_device *thermal,
 	for (i = ACPI_THERMAL_TRIP_ACTIVE; i < ACPI_THERMAL_MAX_ACTIVE &&
 		tz->trips[i].flags.valid; i++) {
 		if (!trip) {
-			*temp = deci_kelvin_to_millicelsius_with_offset(
-					tz->trips[i].temperature,
-					tz->kelvin_offset);
+			*temp = tz->trips[i].temperature;
 			return 0;
 		}
 		trip--;
@@ -654,9 +648,7 @@  static int thermal_get_crit_temp(struct thermal_zone_device *thermal,
 	struct acpi_thermal *tz = thermal->devdata;
 
 	if (tz->trips[ACPI_THERMAL_TRIP_CRITICAL].flags.valid) {
-		*temperature = deci_kelvin_to_millicelsius_with_offset(
-					tz->trips[ACPI_THERMAL_TRIP_CRITICAL].temperature,
-					tz->kelvin_offset);
+		*temperature = tz->trips[ACPI_THERMAL_TRIP_CRITICAL].temperature;
 		return 0;
 	}
 
@@ -675,8 +667,8 @@  static int thermal_get_trend(struct thermal_zone_device *thermal,
 
 	if (type == THERMAL_TRIP_ACTIVE) {
 		int trip_temp;
-		int temp = deci_kelvin_to_millicelsius_with_offset(
-					tz->temperature, tz->kelvin_offset);
+		int temp = tz->temperature;
+
 		if (thermal_get_trip_temp(thermal, trip, &trip_temp))
 			return -EINVAL;
 
@@ -1090,7 +1082,7 @@  static int acpi_thermal_add(struct acpi_device *device)
 	INIT_WORK(&tz->thermal_check_work, acpi_thermal_check_fn);
 
 	pr_info("%s [%s] (%ld C)\n", acpi_device_name(device),
-		acpi_device_bid(device), deci_kelvin_to_celsius(tz->temperature));
+		acpi_device_bid(device), tz->temperature);
 	goto end;
 
 free_memory: