From: Daniel Lezcano <daniel.lezcano@linaro.org>
To: rjw@rjwysocki.net
Cc: daniel.lezcano@linaro.org, linux-acpi@vger.kernel.org,
linux-pm@vger.kernel.org,
Daniel Lezcano <daniel.lezcano@kernel.org>,
"Rafael J. Wysocki" <rafael@kernel.org>,
Zhang Rui <rui.zhang@intel.com>, Len Brown <lenb@kernel.org>,
linux-kernel@vger.kernel.org (open list)
Subject: [PATCH v2 09/11] thermal/acpi: Convert the units to milli Celsuis
Date: Fri, 3 Feb 2023 18:44:27 +0100 [thread overview]
Message-ID: <20230203174429.3375691-10-daniel.lezcano@linaro.org> (raw)
In-Reply-To: <20230203174429.3375691-1-daniel.lezcano@linaro.org>
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 --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:
--
2.34.1
next prev parent reply other threads:[~2023-02-03 17:45 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20230203174429.3375691-1-daniel.lezcano@linaro.org>
2023-02-03 17:44 ` [PATCH v2 01/11] thermal/acpi: Remove the intermediate acpi_thermal_trip structure Daniel Lezcano
2023-02-03 17:44 ` [PATCH v2 02/11] thermal/acpi: Change to a common " Daniel Lezcano
2023-02-03 17:44 ` [PATCH v2 03/11] thermal/acpi: Convert the acpi thermal trips to an array Daniel Lezcano
2023-02-03 17:44 ` [PATCH v2 04/11] thermal/acpi: Move the active trip points to the same array Daniel Lezcano
2023-02-03 17:44 ` [PATCH v2 05/11] thermal/acpi: Optimize get_trip_points() Daniel Lezcano
2023-02-03 17:44 ` [PATCH v2 06/11] thermal/acpi: Encapsulate in functions the trip initialization Daniel Lezcano
2023-02-03 17:44 ` [PATCH v2 07/11] thermal/acpi: Simplifify the condition check Daniel Lezcano
2023-02-03 17:44 ` [PATCH v2 08/11] thermal/acpi: Remove active and enabled flags Daniel Lezcano
2023-02-03 17:44 ` Daniel Lezcano [this message]
2023-02-03 17:44 ` [PATCH v2 10/11] thermal/acpi: Rewrite the trip point intialization to use the generic thermal trip Daniel Lezcano
2023-02-03 17:44 ` [PATCH v2 11/11] thermal/acpi: Use the thermal framework ACPI API Daniel Lezcano
2023-02-04 5:10 ` kernel test robot
2023-02-04 7:54 ` kernel test robot
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230203174429.3375691-10-daniel.lezcano@linaro.org \
--to=daniel.lezcano@linaro.org \
--cc=daniel.lezcano@kernel.org \
--cc=lenb@kernel.org \
--cc=linux-acpi@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=rafael@kernel.org \
--cc=rjw@rjwysocki.net \
--cc=rui.zhang@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®