2019-05-29 14:18:02 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
2015-01-16 23:59:03 +00:00
|
|
|
/*
|
|
|
|
* int340x_thermal_zone.c
|
|
|
|
* Copyright (c) 2015, Intel Corporation.
|
|
|
|
*/
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/acpi.h>
|
|
|
|
#include <linux/thermal.h>
|
2020-01-31 06:15:44 +00:00
|
|
|
#include <linux/units.h>
|
2015-01-16 23:59:03 +00:00
|
|
|
#include "int340x_thermal_zone.h"
|
|
|
|
|
|
|
|
static int int340x_thermal_get_zone_temp(struct thermal_zone_device *zone,
|
2015-07-24 06:12:54 +00:00
|
|
|
int *temp)
|
2015-01-16 23:59:03 +00:00
|
|
|
{
|
2023-03-01 20:14:30 +00:00
|
|
|
struct int34x_thermal_zone *d = thermal_zone_device_priv(zone);
|
2015-01-16 23:59:03 +00:00
|
|
|
unsigned long long tmp;
|
|
|
|
acpi_status status;
|
|
|
|
|
|
|
|
status = acpi_evaluate_integer(d->adev->handle, "_TMP", NULL, &tmp);
|
|
|
|
if (ACPI_FAILURE(status))
|
|
|
|
return -EIO;
|
|
|
|
|
2015-01-28 19:56:48 +00:00
|
|
|
if (d->lpat_table) {
|
|
|
|
int conv_temp;
|
|
|
|
|
|
|
|
conv_temp = acpi_lpat_raw_to_temp(d->lpat_table, (int)tmp);
|
|
|
|
if (conv_temp < 0)
|
|
|
|
return conv_temp;
|
|
|
|
|
2023-01-30 18:45:17 +00:00
|
|
|
*temp = conv_temp * 10;
|
2023-01-30 18:42:16 +00:00
|
|
|
} else {
|
2015-01-28 19:56:48 +00:00
|
|
|
/* _TMP returns the temperature in tenths of degrees Kelvin */
|
2020-01-31 06:15:44 +00:00
|
|
|
*temp = deci_kelvin_to_millicelsius(tmp);
|
2023-01-30 18:42:16 +00:00
|
|
|
}
|
2015-01-16 23:59:03 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int int340x_thermal_set_trip_temp(struct thermal_zone_device *zone,
|
2023-01-30 18:42:16 +00:00
|
|
|
int trip, int temp)
|
2015-01-16 23:59:03 +00:00
|
|
|
{
|
2023-03-01 20:14:30 +00:00
|
|
|
struct int34x_thermal_zone *d = thermal_zone_device_priv(zone);
|
2023-01-30 18:47:43 +00:00
|
|
|
char name[] = {'P', 'A', 'T', '0' + trip, '\0'};
|
2015-01-16 23:59:03 +00:00
|
|
|
acpi_status status;
|
|
|
|
|
2023-01-30 18:47:43 +00:00
|
|
|
if (trip > 9)
|
|
|
|
return -EINVAL;
|
|
|
|
|
2015-01-16 23:59:03 +00:00
|
|
|
status = acpi_execute_simple_method(d->adev->handle, name,
|
2023-01-30 18:42:16 +00:00
|
|
|
millicelsius_to_deci_kelvin(temp));
|
2015-01-16 23:59:03 +00:00
|
|
|
if (ACPI_FAILURE(status))
|
|
|
|
return -EIO;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
thermal: int340x: Fix unexpected shutdown at critical temperature
We are seeing thermal shutdown on Intel based mobile workstations, the
shutdown happens during the first trip handle in
thermal_zone_device_register():
kernel: thermal thermal_zone15: critical temperature reached (101 C), shutting down
However, we shouldn't do a thermal shutdown here, since
1) We may want to use a dedicated daemon, Intel's thermald in this case,
to handle thermal shutdown.
2) For ACPI based system, _CRT doesn't mean shutdown unless it's inside
ThermalZone namespace. ACPI Spec, 11.4.4 _CRT (Critical Temperature):
"... If this object it present under a device, the device’s driver
evaluates this object to determine the device’s critical cooling
temperature trip point. This value may then be used by the device’s
driver to program an internal device temperature sensor trip point."
So a "critical trip" here merely means we should take a more aggressive
cooling method.
As int340x device isn't present under ACPI ThermalZone, override the
default .critical callback to prevent surprising thermal shutdown.
Signed-off-by: Kai-Heng Feng <kai.heng.feng@canonical.com>
Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
Link: https://lore.kernel.org/r/20201221172345.36976-1-kai.heng.feng@canonical.com
2020-12-21 17:23:43 +00:00
|
|
|
static void int340x_thermal_critical(struct thermal_zone_device *zone)
|
|
|
|
{
|
|
|
|
dev_dbg(&zone->device, "%s: critical temperature reached\n", zone->type);
|
|
|
|
}
|
|
|
|
|
2015-01-16 23:59:03 +00:00
|
|
|
static struct thermal_zone_device_ops int340x_thermal_zone_ops = {
|
|
|
|
.get_temp = int340x_thermal_get_zone_temp,
|
|
|
|
.set_trip_temp = int340x_thermal_set_trip_temp,
|
thermal: int340x: Fix unexpected shutdown at critical temperature
We are seeing thermal shutdown on Intel based mobile workstations, the
shutdown happens during the first trip handle in
thermal_zone_device_register():
kernel: thermal thermal_zone15: critical temperature reached (101 C), shutting down
However, we shouldn't do a thermal shutdown here, since
1) We may want to use a dedicated daemon, Intel's thermald in this case,
to handle thermal shutdown.
2) For ACPI based system, _CRT doesn't mean shutdown unless it's inside
ThermalZone namespace. ACPI Spec, 11.4.4 _CRT (Critical Temperature):
"... If this object it present under a device, the device’s driver
evaluates this object to determine the device’s critical cooling
temperature trip point. This value may then be used by the device’s
driver to program an internal device temperature sensor trip point."
So a "critical trip" here merely means we should take a more aggressive
cooling method.
As int340x device isn't present under ACPI ThermalZone, override the
default .critical callback to prevent surprising thermal shutdown.
Signed-off-by: Kai-Heng Feng <kai.heng.feng@canonical.com>
Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
Link: https://lore.kernel.org/r/20201221172345.36976-1-kai.heng.feng@canonical.com
2020-12-21 17:23:43 +00:00
|
|
|
.critical = int340x_thermal_critical,
|
2015-01-16 23:59:03 +00:00
|
|
|
};
|
|
|
|
|
2023-10-03 13:26:35 +00:00
|
|
|
static inline void *int_to_trip_priv(int i)
|
|
|
|
{
|
|
|
|
return (void *)(long)i;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int trip_priv_to_int(const struct thermal_trip *trip)
|
|
|
|
{
|
|
|
|
return (long)trip->priv;
|
|
|
|
}
|
|
|
|
|
2023-01-25 14:55:24 +00:00
|
|
|
static int int340x_thermal_read_trips(struct acpi_device *zone_adev,
|
|
|
|
struct thermal_trip *zone_trips,
|
|
|
|
int trip_cnt)
|
2015-01-16 23:59:03 +00:00
|
|
|
{
|
2023-01-25 14:55:24 +00:00
|
|
|
int i, ret;
|
2015-01-16 23:59:03 +00:00
|
|
|
|
2023-01-27 18:17:03 +00:00
|
|
|
ret = thermal_acpi_critical_trip_temp(zone_adev,
|
|
|
|
&zone_trips[trip_cnt].temperature);
|
|
|
|
if (!ret) {
|
|
|
|
zone_trips[trip_cnt].type = THERMAL_TRIP_CRITICAL;
|
2023-01-25 14:55:24 +00:00
|
|
|
trip_cnt++;
|
2023-01-27 18:17:03 +00:00
|
|
|
}
|
2015-01-16 23:59:03 +00:00
|
|
|
|
2023-01-27 18:17:03 +00:00
|
|
|
ret = thermal_acpi_hot_trip_temp(zone_adev,
|
|
|
|
&zone_trips[trip_cnt].temperature);
|
|
|
|
if (!ret) {
|
|
|
|
zone_trips[trip_cnt].type = THERMAL_TRIP_HOT;
|
2023-01-25 14:55:24 +00:00
|
|
|
trip_cnt++;
|
2023-01-27 18:17:03 +00:00
|
|
|
}
|
2015-01-16 23:59:03 +00:00
|
|
|
|
2023-01-27 18:17:03 +00:00
|
|
|
ret = thermal_acpi_passive_trip_temp(zone_adev,
|
|
|
|
&zone_trips[trip_cnt].temperature);
|
|
|
|
if (!ret) {
|
|
|
|
zone_trips[trip_cnt].type = THERMAL_TRIP_PASSIVE;
|
2023-01-25 14:55:24 +00:00
|
|
|
trip_cnt++;
|
2023-01-27 18:17:03 +00:00
|
|
|
}
|
2016-08-26 23:21:18 +00:00
|
|
|
|
|
|
|
for (i = 0; i < INT340X_THERMAL_MAX_ACT_TRIP_COUNT; i++) {
|
2023-01-27 18:17:03 +00:00
|
|
|
ret = thermal_acpi_active_trip_temp(zone_adev, i,
|
|
|
|
&zone_trips[trip_cnt].temperature);
|
2023-01-25 14:55:24 +00:00
|
|
|
if (ret)
|
2016-08-26 23:21:18 +00:00
|
|
|
break;
|
|
|
|
|
2023-01-27 18:17:03 +00:00
|
|
|
zone_trips[trip_cnt].type = THERMAL_TRIP_ACTIVE;
|
2023-10-03 13:26:35 +00:00
|
|
|
zone_trips[trip_cnt].priv = int_to_trip_priv(i);
|
2023-01-25 14:55:24 +00:00
|
|
|
trip_cnt++;
|
2016-08-26 23:21:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return trip_cnt;
|
|
|
|
}
|
|
|
|
|
2015-01-16 23:59:03 +00:00
|
|
|
static struct thermal_zone_params int340x_thermal_params = {
|
|
|
|
.governor_name = "user_space",
|
|
|
|
.no_hwmon = true,
|
|
|
|
};
|
|
|
|
|
|
|
|
struct int34x_thermal_zone *int340x_thermal_zone_add(struct acpi_device *adev,
|
2022-10-03 09:26:01 +00:00
|
|
|
int (*get_temp) (struct thermal_zone_device *, int *))
|
2015-01-16 23:59:03 +00:00
|
|
|
{
|
2023-01-30 18:43:32 +00:00
|
|
|
struct int34x_thermal_zone *int34x_zone;
|
2023-01-25 14:55:24 +00:00
|
|
|
struct thermal_trip *zone_trips;
|
|
|
|
unsigned long long trip_cnt = 0;
|
|
|
|
unsigned long long hyst;
|
2016-08-26 23:21:18 +00:00
|
|
|
int trip_mask = 0;
|
2023-01-25 14:55:24 +00:00
|
|
|
acpi_status status;
|
|
|
|
int i, ret;
|
2015-01-16 23:59:03 +00:00
|
|
|
|
2023-01-30 18:43:32 +00:00
|
|
|
int34x_zone = kzalloc(sizeof(*int34x_zone), GFP_KERNEL);
|
|
|
|
if (!int34x_zone)
|
2015-01-16 23:59:03 +00:00
|
|
|
return ERR_PTR(-ENOMEM);
|
|
|
|
|
2023-01-30 18:43:32 +00:00
|
|
|
int34x_zone->adev = adev;
|
2022-10-03 09:26:01 +00:00
|
|
|
|
2023-01-30 18:43:32 +00:00
|
|
|
int34x_zone->ops = kmemdup(&int340x_thermal_zone_ops,
|
|
|
|
sizeof(int340x_thermal_zone_ops), GFP_KERNEL);
|
|
|
|
if (!int34x_zone->ops) {
|
2022-10-03 09:26:01 +00:00
|
|
|
ret = -ENOMEM;
|
|
|
|
goto err_ops_alloc;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (get_temp)
|
2023-01-30 18:43:32 +00:00
|
|
|
int34x_zone->ops->get_temp = get_temp;
|
2015-01-16 23:59:03 +00:00
|
|
|
|
|
|
|
status = acpi_evaluate_integer(adev->handle, "PATC", NULL, &trip_cnt);
|
2023-01-30 18:42:16 +00:00
|
|
|
if (ACPI_SUCCESS(status)) {
|
2023-01-30 18:43:32 +00:00
|
|
|
int34x_zone->aux_trip_nr = trip_cnt;
|
2023-01-25 14:55:24 +00:00
|
|
|
trip_mask = BIT(trip_cnt) - 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
zone_trips = kzalloc(sizeof(*zone_trips) * (trip_cnt + INT340X_THERMAL_MAX_TRIP_COUNT),
|
|
|
|
GFP_KERNEL);
|
|
|
|
if (!zone_trips) {
|
|
|
|
ret = -ENOMEM;
|
|
|
|
goto err_trips_alloc;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < trip_cnt; i++) {
|
|
|
|
zone_trips[i].type = THERMAL_TRIP_PASSIVE;
|
|
|
|
zone_trips[i].temperature = THERMAL_TEMP_INVALID;
|
2015-01-16 23:59:03 +00:00
|
|
|
}
|
|
|
|
|
2023-01-25 14:55:24 +00:00
|
|
|
trip_cnt = int340x_thermal_read_trips(adev, zone_trips, trip_cnt);
|
|
|
|
|
|
|
|
status = acpi_evaluate_integer(adev->handle, "GTSH", NULL, &hyst);
|
|
|
|
if (ACPI_SUCCESS(status))
|
|
|
|
hyst *= 100;
|
|
|
|
else
|
|
|
|
hyst = 0;
|
|
|
|
|
|
|
|
for (i = 0; i < trip_cnt; ++i)
|
|
|
|
zone_trips[i].hysteresis = hyst;
|
|
|
|
|
2023-01-30 18:43:32 +00:00
|
|
|
int34x_zone->trips = zone_trips;
|
2015-01-16 23:59:03 +00:00
|
|
|
|
2023-01-30 18:43:32 +00:00
|
|
|
int34x_zone->lpat_table = acpi_lpat_get_conversion_table(adev->handle);
|
2015-01-16 23:59:03 +00:00
|
|
|
|
2023-01-30 18:43:32 +00:00
|
|
|
int34x_zone->zone = thermal_zone_device_register_with_trips(
|
|
|
|
acpi_device_bid(adev),
|
|
|
|
zone_trips, trip_cnt,
|
|
|
|
trip_mask, int34x_zone,
|
|
|
|
int34x_zone->ops,
|
|
|
|
&int340x_thermal_params,
|
|
|
|
0, 0);
|
|
|
|
if (IS_ERR(int34x_zone->zone)) {
|
|
|
|
ret = PTR_ERR(int34x_zone->zone);
|
2015-03-02 21:12:07 +00:00
|
|
|
goto err_thermal_zone;
|
2015-01-16 23:59:03 +00:00
|
|
|
}
|
2023-01-30 18:43:32 +00:00
|
|
|
ret = thermal_zone_device_enable(int34x_zone->zone);
|
2020-06-29 12:29:22 +00:00
|
|
|
if (ret)
|
|
|
|
goto err_enable;
|
2015-01-16 23:59:03 +00:00
|
|
|
|
2023-01-30 18:43:32 +00:00
|
|
|
return int34x_zone;
|
2015-01-16 23:59:03 +00:00
|
|
|
|
2020-06-29 12:29:22 +00:00
|
|
|
err_enable:
|
2023-01-30 18:43:32 +00:00
|
|
|
thermal_zone_device_unregister(int34x_zone->zone);
|
2015-03-02 21:12:07 +00:00
|
|
|
err_thermal_zone:
|
2023-01-30 18:43:32 +00:00
|
|
|
kfree(int34x_zone->trips);
|
|
|
|
acpi_lpat_free_conversion_table(int34x_zone->lpat_table);
|
2023-01-25 14:55:24 +00:00
|
|
|
err_trips_alloc:
|
2023-01-30 18:43:32 +00:00
|
|
|
kfree(int34x_zone->ops);
|
2022-10-03 09:26:01 +00:00
|
|
|
err_ops_alloc:
|
2023-01-30 18:43:32 +00:00
|
|
|
kfree(int34x_zone);
|
2015-01-16 23:59:03 +00:00
|
|
|
return ERR_PTR(ret);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(int340x_thermal_zone_add);
|
|
|
|
|
2023-01-30 18:43:32 +00:00
|
|
|
void int340x_thermal_zone_remove(struct int34x_thermal_zone *int34x_zone)
|
2015-01-16 23:59:03 +00:00
|
|
|
{
|
2023-01-30 18:43:32 +00:00
|
|
|
thermal_zone_device_unregister(int34x_zone->zone);
|
|
|
|
acpi_lpat_free_conversion_table(int34x_zone->lpat_table);
|
|
|
|
kfree(int34x_zone->trips);
|
|
|
|
kfree(int34x_zone->ops);
|
|
|
|
kfree(int34x_zone);
|
2015-01-16 23:59:03 +00:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(int340x_thermal_zone_remove);
|
|
|
|
|
2023-10-03 13:26:35 +00:00
|
|
|
static int int340x_update_one_trip(struct thermal_trip *trip, void *arg)
|
2023-01-25 14:52:25 +00:00
|
|
|
{
|
2023-12-05 19:18:39 +00:00
|
|
|
struct int34x_thermal_zone *int34x_zone = arg;
|
|
|
|
struct acpi_device *zone_adev = int34x_zone->adev;
|
2023-10-03 13:26:35 +00:00
|
|
|
int temp, err;
|
|
|
|
|
|
|
|
switch (trip->type) {
|
|
|
|
case THERMAL_TRIP_CRITICAL:
|
|
|
|
err = thermal_acpi_critical_trip_temp(zone_adev, &temp);
|
|
|
|
break;
|
|
|
|
case THERMAL_TRIP_HOT:
|
|
|
|
err = thermal_acpi_hot_trip_temp(zone_adev, &temp);
|
|
|
|
break;
|
|
|
|
case THERMAL_TRIP_PASSIVE:
|
|
|
|
err = thermal_acpi_passive_trip_temp(zone_adev, &temp);
|
|
|
|
break;
|
|
|
|
case THERMAL_TRIP_ACTIVE:
|
|
|
|
err = thermal_acpi_active_trip_temp(zone_adev,
|
|
|
|
trip_priv_to_int(trip),
|
|
|
|
&temp);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
err = -ENODEV;
|
2023-01-25 14:52:25 +00:00
|
|
|
}
|
2023-10-03 13:26:35 +00:00
|
|
|
if (err)
|
|
|
|
temp = THERMAL_TEMP_INVALID;
|
2023-01-25 14:52:25 +00:00
|
|
|
|
2023-12-05 19:18:39 +00:00
|
|
|
thermal_zone_set_trip_temp(int34x_zone->zone, trip, temp);
|
|
|
|
|
2023-10-03 13:26:35 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void int340x_thermal_update_trips(struct int34x_thermal_zone *int34x_zone)
|
|
|
|
{
|
|
|
|
thermal_zone_for_each_trip(int34x_zone->zone, int340x_update_one_trip,
|
2023-12-05 19:18:39 +00:00
|
|
|
int34x_zone);
|
2023-01-25 14:52:25 +00:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(int340x_thermal_update_trips);
|
|
|
|
|
2015-01-16 23:59:03 +00:00
|
|
|
MODULE_AUTHOR("Aaron Lu <aaron.lu@intel.com>");
|
|
|
|
MODULE_AUTHOR("Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>");
|
|
|
|
MODULE_DESCRIPTION("Intel INT340x common thermal zone handler");
|
|
|
|
MODULE_LICENSE("GPL v2");
|