summaryrefslogtreecommitdiff
path: root/drivers/acpi/thermal.c
diff options
context:
space:
mode:
authorRafael J. Wysocki <rafael.j.wysocki@intel.com>2023-10-03 15:24:12 +0200
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>2023-10-05 13:32:35 +0200
commitb251ab28caeb5a4a63d832dcd53d29ad2dd5318f (patch)
tree73b1ae138b421ed00a555e9e57d117995d2d5343 /drivers/acpi/thermal.c
parent4f9cf91e4102fe77ef3393febab72612b594172f (diff)
ACPI: thermal: Use thermal_zone_for_each_trip() for updating trips
Rearrange the code handling notifications from the platform firmware regarding trip point updates to carry out one loop over trip points instead of two of them by using thermal_zone_for_each_trip() for that, which is more straightforward than using a combination of thermal_zone_device_exec() and for_each_thermal_trip(), each with its own callback function. No intentional functional impact. Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com> Acked-by: Daniel Lezcano <daniel.lezcano@linaro.org>
Diffstat (limited to 'drivers/acpi/thermal.c')
-rw-r--r--drivers/acpi/thermal.c78
1 files changed, 37 insertions, 41 deletions
diff --git a/drivers/acpi/thermal.c b/drivers/acpi/thermal.c
index d527db0f1144..fb9da37a79d8 100644
--- a/drivers/acpi/thermal.c
+++ b/drivers/acpi/thermal.c
@@ -177,6 +177,15 @@ static bool acpi_thermal_trip_valid(struct acpi_thermal_trip *acpi_trip)
return acpi_trip->temp_dk != THERMAL_TEMP_INVALID;
}
+static int active_trip_index(struct acpi_thermal *tz,
+ struct acpi_thermal_trip *acpi_trip)
+{
+ struct acpi_thermal_active *active;
+
+ active = container_of(acpi_trip, struct acpi_thermal_active, trip);
+ return active - tz->trips.active;
+}
+
static long get_passive_temp(struct acpi_thermal *tz)
{
unsigned long long tmp;
@@ -213,21 +222,18 @@ static long get_active_temp(struct acpi_thermal *tz, int index)
}
static void acpi_thermal_update_trip(struct acpi_thermal *tz,
- int index)
+ const struct thermal_trip *trip)
{
- struct acpi_thermal_trip *acpi_trip;
-
- acpi_trip = index == ACPI_THERMAL_TRIP_PASSIVE ?
- &tz->trips.passive.trip : &tz->trips.active[index].trip;
- if (!acpi_thermal_trip_valid(acpi_trip))
- return;
+ struct acpi_thermal_trip *acpi_trip = trip->priv;
- if (index == ACPI_THERMAL_TRIP_PASSIVE) {
+ if (trip->type == THERMAL_TRIP_PASSIVE) {
if (psv > 0)
return;
acpi_trip->temp_dk = get_passive_temp(tz);
} else {
+ int index = active_trip_index(tz, acpi_trip);
+
acpi_trip->temp_dk = get_active_temp(tz, index);
}
@@ -264,31 +270,39 @@ static bool update_trip_devices(struct acpi_thermal *tz,
return true;
}
-static void acpi_thermal_update_trip_devices(struct acpi_thermal *tz, int index)
+static void acpi_thermal_update_trip_devices(struct acpi_thermal *tz,
+ const struct thermal_trip *trip)
{
- struct acpi_thermal_trip *acpi_trip;
-
- acpi_trip = index == ACPI_THERMAL_TRIP_PASSIVE ?
- &tz->trips.passive.trip : &tz->trips.active[index].trip;
- if (!acpi_thermal_trip_valid(acpi_trip))
- return;
+ struct acpi_thermal_trip *acpi_trip = trip->priv;
+ int index = trip->type == THERMAL_TRIP_PASSIVE ?
+ ACPI_THERMAL_TRIP_PASSIVE : active_trip_index(tz, acpi_trip);
- if (update_trip_devices(tz, acpi_trip, index, true)) {
+ if (update_trip_devices(tz, acpi_trip, index, true))
return;
- }
acpi_trip->temp_dk = THERMAL_TEMP_INVALID;
ACPI_THERMAL_TRIPS_EXCEPTION(tz, "state");
}
+struct adjust_trip_data {
+ struct acpi_thermal *tz;
+ u32 event;
+};
+
static int acpi_thermal_adjust_trip(struct thermal_trip *trip, void *data)
{
struct acpi_thermal_trip *acpi_trip = trip->priv;
- struct acpi_thermal *tz = data;
+ struct adjust_trip_data *atd = data;
+ struct acpi_thermal *tz = atd->tz;
- if (!acpi_trip)
+ if (!acpi_trip || !acpi_thermal_trip_valid(acpi_trip))
return 0;
+ if (atd->event == ACPI_THERMAL_NOTIFY_THRESHOLDS)
+ acpi_thermal_update_trip(tz, trip);
+ else
+ acpi_thermal_update_trip_devices(tz, trip);
+
if (acpi_thermal_trip_valid(acpi_trip))
trip->temperature = acpi_thermal_temp(tz, acpi_trip->temp_dk);
else
@@ -297,25 +311,6 @@ static int acpi_thermal_adjust_trip(struct thermal_trip *trip, void *data)
return 0;
}
-static void acpi_thermal_adjust_thermal_zone(struct thermal_zone_device *thermal,
- unsigned long data)
-{
- struct acpi_thermal *tz = thermal_zone_device_priv(thermal);
- int i;
-
- if (data == ACPI_THERMAL_NOTIFY_THRESHOLDS) {
- acpi_thermal_update_trip(tz, ACPI_THERMAL_TRIP_PASSIVE);
- for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++)
- acpi_thermal_update_trip(tz, i);
- } else {
- acpi_thermal_update_trip_devices(tz, ACPI_THERMAL_TRIP_PASSIVE);
- for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++)
- acpi_thermal_update_trip_devices(tz, i);
- }
-
- for_each_thermal_trip(tz->thermal_zone, acpi_thermal_adjust_trip, tz);
-}
-
static void acpi_queue_thermal_check(struct acpi_thermal *tz)
{
if (!work_pending(&tz->thermal_check_work))
@@ -324,17 +319,18 @@ static void acpi_queue_thermal_check(struct acpi_thermal *tz)
static void acpi_thermal_trips_update(struct acpi_thermal *tz, u32 event)
{
+ struct adjust_trip_data atd = { .tz = tz, .event = event };
struct acpi_device *adev = tz->device;
/*
- * Use thermal_zone_device_exec() to carry out the trip points
+ * Use thermal_zone_for_each_trip() to carry out the trip points
* update, so as to protect thermal_get_trend() from getting stale
* trip point temperatures and to prevent thermal_zone_device_update()
* invoked from acpi_thermal_check_fn() from producing inconsistent
* results.
*/
- thermal_zone_device_exec(tz->thermal_zone,
- acpi_thermal_adjust_thermal_zone, event);
+ thermal_zone_for_each_trip(tz->thermal_zone,
+ acpi_thermal_adjust_trip, &atd);
acpi_queue_thermal_check(tz);
acpi_bus_generate_netlink_event(adev->pnp.device_class,
dev_name(&adev->dev), event, 0);