Thomas Gleixner | c942fdd | 2019-05-27 08:55:06 +0200 | [diff] [blame^] | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | /* |
| 3 | * acpi_thermal.c - ACPI Thermal Zone Driver ($Revision: 41 $) |
| 4 | * |
| 5 | * Copyright (C) 2001, 2002 Andy Grover <andrew.grover@intel.com> |
| 6 | * Copyright (C) 2001, 2002 Paul Diefenbaugh <paul.s.diefenbaugh@intel.com> |
| 7 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8 | * This driver fully implements the ACPI thermal policy as described in the |
| 9 | * ACPI 2.0 Specification. |
| 10 | * |
| 11 | * TBD: 1. Implement passive cooling hysteresis. |
| 12 | * 2. Enhance passive cooling (CPU) states/limit interface to support |
| 13 | * concepts of 'multiple limiters', upper/lower limits, etc. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14 | */ |
| 15 | |
| 16 | #include <linux/kernel.h> |
| 17 | #include <linux/module.h> |
Len Brown | 0b5bfa1 | 2007-08-12 00:13:02 -0400 | [diff] [blame] | 18 | #include <linux/dmi.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | #include <linux/init.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 20 | #include <linux/slab.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | #include <linux/types.h> |
Tim Schmielau | cd354f1 | 2007-02-14 00:33:14 -0800 | [diff] [blame] | 22 | #include <linux/jiffies.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | #include <linux/kmod.h> |
Jeremy Fitzhardinge | 10a0a8d | 2007-07-17 18:37:02 -0700 | [diff] [blame] | 24 | #include <linux/reboot.h> |
Stephen Rothwell | f6f5c45 | 2009-03-03 12:47:17 +1100 | [diff] [blame] | 25 | #include <linux/device.h> |
Zhang Rui | 3f655ef | 2008-01-17 15:51:11 +0800 | [diff] [blame] | 26 | #include <linux/thermal.h> |
Lv Zheng | 8b48463 | 2013-12-03 08:49:16 +0800 | [diff] [blame] | 27 | #include <linux/acpi.h> |
Aaron Lu | a59ffb2 | 2014-03-04 14:24:46 +0800 | [diff] [blame] | 28 | #include <linux/workqueue.h> |
Linus Torvalds | 7c0f6ba | 2016-12-24 11:46:01 -0800 | [diff] [blame] | 29 | #include <linux/uaccess.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | |
Len Brown | a192a95 | 2009-07-28 16:45:54 -0400 | [diff] [blame] | 31 | #define PREFIX "ACPI: " |
| 32 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | #define ACPI_THERMAL_CLASS "thermal_zone" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | #define ACPI_THERMAL_DEVICE_NAME "Thermal Zone" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | #define ACPI_THERMAL_NOTIFY_TEMPERATURE 0x80 |
| 36 | #define ACPI_THERMAL_NOTIFY_THRESHOLDS 0x81 |
| 37 | #define ACPI_THERMAL_NOTIFY_DEVICES 0x82 |
| 38 | #define ACPI_THERMAL_NOTIFY_CRITICAL 0xF0 |
| 39 | #define ACPI_THERMAL_NOTIFY_HOT 0xF1 |
| 40 | #define ACPI_THERMAL_MODE_ACTIVE 0x00 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | |
| 42 | #define ACPI_THERMAL_MAX_ACTIVE 10 |
| 43 | #define ACPI_THERMAL_MAX_LIMIT_STR_LEN 65 |
| 44 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | #define _COMPONENT ACPI_THERMAL_COMPONENT |
Len Brown | f52fd66 | 2007-02-12 22:42:12 -0500 | [diff] [blame] | 46 | ACPI_MODULE_NAME("thermal"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | |
Thomas Renninger | 1cbf4c5 | 2004-09-16 11:07:00 -0400 | [diff] [blame] | 48 | MODULE_AUTHOR("Paul Diefenbaugh"); |
Len Brown | 7cda93e | 2007-02-12 23:50:02 -0500 | [diff] [blame] | 49 | MODULE_DESCRIPTION("ACPI Thermal Zone Driver"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | MODULE_LICENSE("GPL"); |
| 51 | |
Len Brown | f8707ec | 2007-08-12 00:12:54 -0400 | [diff] [blame] | 52 | static int act; |
| 53 | module_param(act, int, 0644); |
Len Brown | 3c1d36d | 2007-08-14 15:12:56 -0400 | [diff] [blame] | 54 | MODULE_PARM_DESC(act, "Disable or override all lowest active trip points."); |
Len Brown | f8707ec | 2007-08-12 00:12:54 -0400 | [diff] [blame] | 55 | |
Len Brown | c52a741 | 2007-08-14 15:49:32 -0400 | [diff] [blame] | 56 | static int crt; |
| 57 | module_param(crt, int, 0644); |
| 58 | MODULE_PARM_DESC(crt, "Disable or lower all critical trip points."); |
| 59 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | static int tzp; |
Len Brown | 730ff34 | 2007-08-12 00:12:26 -0400 | [diff] [blame] | 61 | module_param(tzp, int, 0444); |
Len Brown | 3c1d36d | 2007-08-14 15:12:56 -0400 | [diff] [blame] | 62 | MODULE_PARM_DESC(tzp, "Thermal zone polling frequency, in 1/10 seconds."); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | |
Len Brown | f548714 | 2007-08-12 00:12:44 -0400 | [diff] [blame] | 64 | static int nocrt; |
| 65 | module_param(nocrt, int, 0); |
Len Brown | 8c99fdc | 2007-08-20 18:46:50 -0400 | [diff] [blame] | 66 | MODULE_PARM_DESC(nocrt, "Set to take no action upon ACPI thermal zone critical trips points."); |
Len Brown | f548714 | 2007-08-12 00:12:44 -0400 | [diff] [blame] | 67 | |
Len Brown | 72b33ef | 2007-08-12 00:12:17 -0400 | [diff] [blame] | 68 | static int off; |
| 69 | module_param(off, int, 0); |
Len Brown | 3c1d36d | 2007-08-14 15:12:56 -0400 | [diff] [blame] | 70 | MODULE_PARM_DESC(off, "Set to disable ACPI thermal support."); |
Len Brown | 72b33ef | 2007-08-12 00:12:17 -0400 | [diff] [blame] | 71 | |
Len Brown | a70cdc5 | 2007-08-12 00:12:35 -0400 | [diff] [blame] | 72 | static int psv; |
| 73 | module_param(psv, int, 0644); |
Len Brown | 3c1d36d | 2007-08-14 15:12:56 -0400 | [diff] [blame] | 74 | MODULE_PARM_DESC(psv, "Disable or override all passive trip points."); |
Len Brown | a70cdc5 | 2007-08-12 00:12:35 -0400 | [diff] [blame] | 75 | |
Aaron Lu | a59ffb2 | 2014-03-04 14:24:46 +0800 | [diff] [blame] | 76 | static struct workqueue_struct *acpi_thermal_pm_queue; |
| 77 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 78 | static int acpi_thermal_add(struct acpi_device *device); |
Rafael J. Wysocki | 51fac83 | 2013-01-24 00:24:48 +0100 | [diff] [blame] | 79 | static int acpi_thermal_remove(struct acpi_device *device); |
Bjorn Helgaas | 342d550 | 2009-04-07 15:37:06 +0000 | [diff] [blame] | 80 | static void acpi_thermal_notify(struct acpi_device *device, u32 event); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | |
Thomas Renninger | 1ba90e3 | 2007-07-23 14:44:41 +0200 | [diff] [blame] | 82 | static const struct acpi_device_id thermal_device_ids[] = { |
| 83 | {ACPI_THERMAL_HID, 0}, |
| 84 | {"", 0}, |
| 85 | }; |
| 86 | MODULE_DEVICE_TABLE(acpi, thermal_device_ids); |
| 87 | |
Rafael J. Wysocki | 9069240 | 2012-08-09 23:00:02 +0200 | [diff] [blame] | 88 | #ifdef CONFIG_PM_SLEEP |
Aaron Lu | a59ffb2 | 2014-03-04 14:24:46 +0800 | [diff] [blame] | 89 | static int acpi_thermal_suspend(struct device *dev); |
Rafael J. Wysocki | 167cffb | 2012-06-27 23:26:18 +0200 | [diff] [blame] | 90 | static int acpi_thermal_resume(struct device *dev); |
Shuah Khan | fae9e2a | 2014-02-12 20:19:10 -0700 | [diff] [blame] | 91 | #else |
Aaron Lu | a59ffb2 | 2014-03-04 14:24:46 +0800 | [diff] [blame] | 92 | #define acpi_thermal_suspend NULL |
Shuah Khan | fae9e2a | 2014-02-12 20:19:10 -0700 | [diff] [blame] | 93 | #define acpi_thermal_resume NULL |
Rafael J. Wysocki | 9069240 | 2012-08-09 23:00:02 +0200 | [diff] [blame] | 94 | #endif |
Aaron Lu | a59ffb2 | 2014-03-04 14:24:46 +0800 | [diff] [blame] | 95 | static SIMPLE_DEV_PM_OPS(acpi_thermal_pm, acpi_thermal_suspend, acpi_thermal_resume); |
Rafael J. Wysocki | 167cffb | 2012-06-27 23:26:18 +0200 | [diff] [blame] | 96 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | static struct acpi_driver acpi_thermal_driver = { |
Len Brown | c2b6705 | 2007-02-12 23:33:40 -0500 | [diff] [blame] | 98 | .name = "thermal", |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 99 | .class = ACPI_THERMAL_CLASS, |
Thomas Renninger | 1ba90e3 | 2007-07-23 14:44:41 +0200 | [diff] [blame] | 100 | .ids = thermal_device_ids, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 101 | .ops = { |
| 102 | .add = acpi_thermal_add, |
| 103 | .remove = acpi_thermal_remove, |
Bjorn Helgaas | 342d550 | 2009-04-07 15:37:06 +0000 | [diff] [blame] | 104 | .notify = acpi_thermal_notify, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 105 | }, |
Rafael J. Wysocki | 167cffb | 2012-06-27 23:26:18 +0200 | [diff] [blame] | 106 | .drv.pm = &acpi_thermal_pm, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | }; |
| 108 | |
| 109 | struct acpi_thermal_state { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 110 | u8 critical:1; |
| 111 | u8 hot:1; |
| 112 | u8 passive:1; |
| 113 | u8 active:1; |
| 114 | u8 reserved:4; |
| 115 | int active_index; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 116 | }; |
| 117 | |
| 118 | struct acpi_thermal_state_flags { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 119 | u8 valid:1; |
| 120 | u8 enabled:1; |
| 121 | u8 reserved:6; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | }; |
| 123 | |
| 124 | struct acpi_thermal_critical { |
| 125 | struct acpi_thermal_state_flags flags; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 126 | unsigned long temperature; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 127 | }; |
| 128 | |
| 129 | struct acpi_thermal_hot { |
| 130 | struct acpi_thermal_state_flags flags; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 131 | unsigned long temperature; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 132 | }; |
| 133 | |
| 134 | struct acpi_thermal_passive { |
| 135 | struct acpi_thermal_state_flags flags; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 136 | unsigned long temperature; |
| 137 | unsigned long tc1; |
| 138 | unsigned long tc2; |
| 139 | unsigned long tsp; |
| 140 | struct acpi_handle_list devices; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 141 | }; |
| 142 | |
| 143 | struct acpi_thermal_active { |
| 144 | struct acpi_thermal_state_flags flags; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 145 | unsigned long temperature; |
| 146 | struct acpi_handle_list devices; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 147 | }; |
| 148 | |
| 149 | struct acpi_thermal_trips { |
| 150 | struct acpi_thermal_critical critical; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 151 | struct acpi_thermal_hot hot; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 152 | struct acpi_thermal_passive passive; |
| 153 | struct acpi_thermal_active active[ACPI_THERMAL_MAX_ACTIVE]; |
| 154 | }; |
| 155 | |
| 156 | struct acpi_thermal_flags { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 157 | u8 cooling_mode:1; /* _SCP */ |
| 158 | u8 devices:1; /* _TZD */ |
| 159 | u8 reserved:6; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 160 | }; |
| 161 | |
| 162 | struct acpi_thermal { |
Patrick Mochel | 8348e1b | 2006-05-19 16:54:40 -0400 | [diff] [blame] | 163 | struct acpi_device * device; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 164 | acpi_bus_id name; |
| 165 | unsigned long temperature; |
| 166 | unsigned long last_temperature; |
| 167 | unsigned long polling_frequency; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 168 | volatile u8 zombie; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 169 | struct acpi_thermal_flags flags; |
| 170 | struct acpi_thermal_state state; |
| 171 | struct acpi_thermal_trips trips; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 172 | struct acpi_handle_list devices; |
Zhang Rui | 3f655ef | 2008-01-17 15:51:11 +0800 | [diff] [blame] | 173 | struct thermal_zone_device *thermal_zone; |
| 174 | int tz_enabled; |
Jean Delvare | 13614e3 | 2009-04-06 16:01:46 +0200 | [diff] [blame] | 175 | int kelvin_offset; |
Aaron Lu | a59ffb2 | 2014-03-04 14:24:46 +0800 | [diff] [blame] | 176 | struct work_struct thermal_check_work; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 177 | }; |
| 178 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 179 | /* -------------------------------------------------------------------------- |
| 180 | Thermal Zone Management |
| 181 | -------------------------------------------------------------------------- */ |
| 182 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 183 | static int acpi_thermal_get_temperature(struct acpi_thermal *tz) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 184 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 185 | acpi_status status = AE_OK; |
Matthew Wilcox | 27663c5 | 2008-10-10 02:22:59 -0400 | [diff] [blame] | 186 | unsigned long long tmp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 187 | |
| 188 | if (!tz) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 189 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 190 | |
| 191 | tz->last_temperature = tz->temperature; |
| 192 | |
Matthew Wilcox | 27663c5 | 2008-10-10 02:22:59 -0400 | [diff] [blame] | 193 | status = acpi_evaluate_integer(tz->device->handle, "_TMP", NULL, &tmp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 194 | if (ACPI_FAILURE(status)) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 195 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 196 | |
Matthew Wilcox | 27663c5 | 2008-10-10 02:22:59 -0400 | [diff] [blame] | 197 | tz->temperature = tmp; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 198 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Temperature is %lu dK\n", |
| 199 | tz->temperature)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 200 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 201 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 202 | } |
| 203 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 204 | static int acpi_thermal_get_polling_frequency(struct acpi_thermal *tz) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 205 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 206 | acpi_status status = AE_OK; |
Matthew Wilcox | 27663c5 | 2008-10-10 02:22:59 -0400 | [diff] [blame] | 207 | unsigned long long tmp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 208 | |
| 209 | if (!tz) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 210 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 211 | |
Matthew Wilcox | 27663c5 | 2008-10-10 02:22:59 -0400 | [diff] [blame] | 212 | status = acpi_evaluate_integer(tz->device->handle, "_TZP", NULL, &tmp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 213 | if (ACPI_FAILURE(status)) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 214 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 215 | |
Matthew Wilcox | 27663c5 | 2008-10-10 02:22:59 -0400 | [diff] [blame] | 216 | tz->polling_frequency = tmp; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 217 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Polling frequency is %lu dS\n", |
| 218 | tz->polling_frequency)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 219 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 220 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 221 | } |
| 222 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 223 | static int acpi_thermal_set_cooling_mode(struct acpi_thermal *tz, int mode) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 224 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 225 | if (!tz) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 226 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 227 | |
Jiang Liu | 0db9820 | 2013-06-29 00:24:39 +0800 | [diff] [blame] | 228 | if (!acpi_has_method(tz->device->handle, "_SCP")) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 229 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "_SCP not present\n")); |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 230 | return -ENODEV; |
Jiang Liu | 0db9820 | 2013-06-29 00:24:39 +0800 | [diff] [blame] | 231 | } else if (ACPI_FAILURE(acpi_execute_simple_method(tz->device->handle, |
| 232 | "_SCP", mode))) { |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 233 | return -ENODEV; |
Jiang Liu | 0db9820 | 2013-06-29 00:24:39 +0800 | [diff] [blame] | 234 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 235 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 236 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 237 | } |
| 238 | |
Zhang Rui | ce44e19 | 2008-01-17 15:51:25 +0800 | [diff] [blame] | 239 | #define ACPI_TRIPS_CRITICAL 0x01 |
| 240 | #define ACPI_TRIPS_HOT 0x02 |
| 241 | #define ACPI_TRIPS_PASSIVE 0x04 |
| 242 | #define ACPI_TRIPS_ACTIVE 0x08 |
| 243 | #define ACPI_TRIPS_DEVICES 0x10 |
| 244 | |
| 245 | #define ACPI_TRIPS_REFRESH_THRESHOLDS (ACPI_TRIPS_PASSIVE | ACPI_TRIPS_ACTIVE) |
| 246 | #define ACPI_TRIPS_REFRESH_DEVICES ACPI_TRIPS_DEVICES |
| 247 | |
| 248 | #define ACPI_TRIPS_INIT (ACPI_TRIPS_CRITICAL | ACPI_TRIPS_HOT | \ |
| 249 | ACPI_TRIPS_PASSIVE | ACPI_TRIPS_ACTIVE | \ |
| 250 | ACPI_TRIPS_DEVICES) |
| 251 | |
| 252 | /* |
| 253 | * This exception is thrown out in two cases: |
| 254 | * 1.An invalid trip point becomes invalid or a valid trip point becomes invalid |
| 255 | * when re-evaluating the AML code. |
| 256 | * 2.TODO: Devices listed in _PSL, _ALx, _TZD may change. |
| 257 | * We need to re-bind the cooling devices of a thermal zone when this occurs. |
| 258 | */ |
| 259 | #define ACPI_THERMAL_TRIPS_EXCEPTION(flags, str) \ |
| 260 | do { \ |
| 261 | if (flags != ACPI_TRIPS_INIT) \ |
| 262 | ACPI_EXCEPTION((AE_INFO, AE_ERROR, \ |
| 263 | "ACPI thermal trip point %s changed\n" \ |
Colin Ian King | 7e3cf24 | 2012-11-29 11:53:16 +0000 | [diff] [blame] | 264 | "Please send acpidump to linux-acpi@vger.kernel.org", str)); \ |
Zhang Rui | ce44e19 | 2008-01-17 15:51:25 +0800 | [diff] [blame] | 265 | } while (0) |
| 266 | |
| 267 | static int acpi_thermal_trips_update(struct acpi_thermal *tz, int flag) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 268 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 269 | acpi_status status = AE_OK; |
Matthew Wilcox | 27663c5 | 2008-10-10 02:22:59 -0400 | [diff] [blame] | 270 | unsigned long long tmp; |
Zhang Rui | ce44e19 | 2008-01-17 15:51:25 +0800 | [diff] [blame] | 271 | struct acpi_handle_list devices; |
| 272 | int valid = 0; |
| 273 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 274 | |
Thomas Renninger | fa80945 | 2010-02-20 11:44:27 +0100 | [diff] [blame] | 275 | /* Critical Shutdown */ |
Zhang Rui | ce44e19 | 2008-01-17 15:51:25 +0800 | [diff] [blame] | 276 | if (flag & ACPI_TRIPS_CRITICAL) { |
| 277 | status = acpi_evaluate_integer(tz->device->handle, |
Matthew Wilcox | 27663c5 | 2008-10-10 02:22:59 -0400 | [diff] [blame] | 278 | "_CRT", NULL, &tmp); |
| 279 | tz->trips.critical.temperature = tmp; |
Arjan van de Ven | a39a2d7 | 2008-05-19 15:55:15 -0700 | [diff] [blame] | 280 | /* |
| 281 | * Treat freezing temperatures as invalid as well; some |
| 282 | * BIOSes return really low values and cause reboots at startup. |
Adam Buchbinder | b731d7b | 2009-03-13 12:15:26 -0400 | [diff] [blame] | 283 | * Below zero (Celsius) values clearly aren't right for sure.. |
Arjan van de Ven | a39a2d7 | 2008-05-19 15:55:15 -0700 | [diff] [blame] | 284 | * ... so lets discard those as invalid. |
| 285 | */ |
Thomas Renninger | fa80945 | 2010-02-20 11:44:27 +0100 | [diff] [blame] | 286 | if (ACPI_FAILURE(status)) { |
Len Brown | c52a741 | 2007-08-14 15:49:32 -0400 | [diff] [blame] | 287 | tz->trips.critical.flags.valid = 0; |
Thomas Renninger | fa80945 | 2010-02-20 11:44:27 +0100 | [diff] [blame] | 288 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
| 289 | "No critical threshold\n")); |
| 290 | } else if (tmp <= 2732) { |
Andy Shevchenko | 766a8a6 | 2013-09-13 18:15:46 +0300 | [diff] [blame] | 291 | pr_warn(FW_BUG "Invalid critical threshold (%llu)\n", |
| 292 | tmp); |
Thomas Renninger | fa80945 | 2010-02-20 11:44:27 +0100 | [diff] [blame] | 293 | tz->trips.critical.flags.valid = 0; |
Zhang Rui | ce44e19 | 2008-01-17 15:51:25 +0800 | [diff] [blame] | 294 | } else { |
| 295 | tz->trips.critical.flags.valid = 1; |
| 296 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
Thomas Renninger | fa80945 | 2010-02-20 11:44:27 +0100 | [diff] [blame] | 297 | "Found critical threshold [%lu]\n", |
| 298 | tz->trips.critical.temperature)); |
Zhang Rui | ce44e19 | 2008-01-17 15:51:25 +0800 | [diff] [blame] | 299 | } |
| 300 | if (tz->trips.critical.flags.valid == 1) { |
| 301 | if (crt == -1) { |
| 302 | tz->trips.critical.flags.valid = 0; |
| 303 | } else if (crt > 0) { |
Rasmus Villemoes | e866a2e | 2015-10-01 23:45:31 +0200 | [diff] [blame] | 304 | unsigned long crt_k = CELSIUS_TO_DECI_KELVIN(crt); |
Zhang Rui | ce44e19 | 2008-01-17 15:51:25 +0800 | [diff] [blame] | 305 | /* |
Zhang Rui | 22a94d7 | 2008-10-17 02:41:20 -0400 | [diff] [blame] | 306 | * Allow override critical threshold |
Zhang Rui | ce44e19 | 2008-01-17 15:51:25 +0800 | [diff] [blame] | 307 | */ |
Zhang Rui | 22a94d7 | 2008-10-17 02:41:20 -0400 | [diff] [blame] | 308 | if (crt_k > tz->trips.critical.temperature) |
Andy Shevchenko | 766a8a6 | 2013-09-13 18:15:46 +0300 | [diff] [blame] | 309 | pr_warn(PREFIX "Critical threshold %d C\n", |
| 310 | crt); |
Zhang Rui | 22a94d7 | 2008-10-17 02:41:20 -0400 | [diff] [blame] | 311 | tz->trips.critical.temperature = crt_k; |
Zhang Rui | ce44e19 | 2008-01-17 15:51:25 +0800 | [diff] [blame] | 312 | } |
Len Brown | c52a741 | 2007-08-14 15:49:32 -0400 | [diff] [blame] | 313 | } |
| 314 | } |
| 315 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 316 | /* Critical Sleep (optional) */ |
Zhang Rui | ce44e19 | 2008-01-17 15:51:25 +0800 | [diff] [blame] | 317 | if (flag & ACPI_TRIPS_HOT) { |
Len Brown | a70cdc5 | 2007-08-12 00:12:35 -0400 | [diff] [blame] | 318 | status = acpi_evaluate_integer(tz->device->handle, |
Matthew Wilcox | 27663c5 | 2008-10-10 02:22:59 -0400 | [diff] [blame] | 319 | "_HOT", NULL, &tmp); |
Zhang Rui | ce44e19 | 2008-01-17 15:51:25 +0800 | [diff] [blame] | 320 | if (ACPI_FAILURE(status)) { |
| 321 | tz->trips.hot.flags.valid = 0; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 322 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
Zhang Rui | ce44e19 | 2008-01-17 15:51:25 +0800 | [diff] [blame] | 323 | "No hot threshold\n")); |
| 324 | } else { |
Matthew Wilcox | 27663c5 | 2008-10-10 02:22:59 -0400 | [diff] [blame] | 325 | tz->trips.hot.temperature = tmp; |
Zhang Rui | ce44e19 | 2008-01-17 15:51:25 +0800 | [diff] [blame] | 326 | tz->trips.hot.flags.valid = 1; |
| 327 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
| 328 | "Found hot threshold [%lu]\n", |
Zhihui Zhang | ee17fdf | 2014-03-29 09:25:47 -0400 | [diff] [blame] | 329 | tz->trips.hot.temperature)); |
Zhang Rui | ce44e19 | 2008-01-17 15:51:25 +0800 | [diff] [blame] | 330 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 331 | } |
| 332 | |
Zhang Rui | ce44e19 | 2008-01-17 15:51:25 +0800 | [diff] [blame] | 333 | /* Passive (optional) */ |
Zhang Rui | 0e4240d | 2009-01-16 12:53:42 -0500 | [diff] [blame] | 334 | if (((flag & ACPI_TRIPS_PASSIVE) && tz->trips.passive.flags.valid) || |
| 335 | (flag == ACPI_TRIPS_INIT)) { |
Zhang Rui | ce44e19 | 2008-01-17 15:51:25 +0800 | [diff] [blame] | 336 | valid = tz->trips.passive.flags.valid; |
| 337 | if (psv == -1) { |
| 338 | status = AE_SUPPORT; |
| 339 | } else if (psv > 0) { |
Rasmus Villemoes | e866a2e | 2015-10-01 23:45:31 +0200 | [diff] [blame] | 340 | tmp = CELSIUS_TO_DECI_KELVIN(psv); |
Zhang Rui | ce44e19 | 2008-01-17 15:51:25 +0800 | [diff] [blame] | 341 | status = AE_OK; |
| 342 | } else { |
| 343 | status = acpi_evaluate_integer(tz->device->handle, |
Matthew Wilcox | 27663c5 | 2008-10-10 02:22:59 -0400 | [diff] [blame] | 344 | "_PSV", NULL, &tmp); |
Zhang Rui | ce44e19 | 2008-01-17 15:51:25 +0800 | [diff] [blame] | 345 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 346 | |
Zhang Rui | ce44e19 | 2008-01-17 15:51:25 +0800 | [diff] [blame] | 347 | if (ACPI_FAILURE(status)) |
| 348 | tz->trips.passive.flags.valid = 0; |
| 349 | else { |
Matthew Wilcox | 27663c5 | 2008-10-10 02:22:59 -0400 | [diff] [blame] | 350 | tz->trips.passive.temperature = tmp; |
Zhang Rui | ce44e19 | 2008-01-17 15:51:25 +0800 | [diff] [blame] | 351 | tz->trips.passive.flags.valid = 1; |
| 352 | if (flag == ACPI_TRIPS_INIT) { |
| 353 | status = acpi_evaluate_integer( |
| 354 | tz->device->handle, "_TC1", |
Matthew Wilcox | 27663c5 | 2008-10-10 02:22:59 -0400 | [diff] [blame] | 355 | NULL, &tmp); |
Zhang Rui | ce44e19 | 2008-01-17 15:51:25 +0800 | [diff] [blame] | 356 | if (ACPI_FAILURE(status)) |
| 357 | tz->trips.passive.flags.valid = 0; |
Matthew Wilcox | 27663c5 | 2008-10-10 02:22:59 -0400 | [diff] [blame] | 358 | else |
| 359 | tz->trips.passive.tc1 = tmp; |
Zhang Rui | ce44e19 | 2008-01-17 15:51:25 +0800 | [diff] [blame] | 360 | status = acpi_evaluate_integer( |
| 361 | tz->device->handle, "_TC2", |
Matthew Wilcox | 27663c5 | 2008-10-10 02:22:59 -0400 | [diff] [blame] | 362 | NULL, &tmp); |
Zhang Rui | ce44e19 | 2008-01-17 15:51:25 +0800 | [diff] [blame] | 363 | if (ACPI_FAILURE(status)) |
| 364 | tz->trips.passive.flags.valid = 0; |
Matthew Wilcox | 27663c5 | 2008-10-10 02:22:59 -0400 | [diff] [blame] | 365 | else |
| 366 | tz->trips.passive.tc2 = tmp; |
Zhang Rui | ce44e19 | 2008-01-17 15:51:25 +0800 | [diff] [blame] | 367 | status = acpi_evaluate_integer( |
| 368 | tz->device->handle, "_TSP", |
Matthew Wilcox | 27663c5 | 2008-10-10 02:22:59 -0400 | [diff] [blame] | 369 | NULL, &tmp); |
Zhang Rui | ce44e19 | 2008-01-17 15:51:25 +0800 | [diff] [blame] | 370 | if (ACPI_FAILURE(status)) |
| 371 | tz->trips.passive.flags.valid = 0; |
Matthew Wilcox | 27663c5 | 2008-10-10 02:22:59 -0400 | [diff] [blame] | 372 | else |
| 373 | tz->trips.passive.tsp = tmp; |
Zhang Rui | ce44e19 | 2008-01-17 15:51:25 +0800 | [diff] [blame] | 374 | } |
| 375 | } |
| 376 | } |
| 377 | if ((flag & ACPI_TRIPS_DEVICES) && tz->trips.passive.flags.valid) { |
| 378 | memset(&devices, 0, sizeof(struct acpi_handle_list)); |
| 379 | status = acpi_evaluate_reference(tz->device->handle, "_PSL", |
| 380 | NULL, &devices); |
Zhang Rui | 0e4240d | 2009-01-16 12:53:42 -0500 | [diff] [blame] | 381 | if (ACPI_FAILURE(status)) { |
Andy Shevchenko | 766a8a6 | 2013-09-13 18:15:46 +0300 | [diff] [blame] | 382 | pr_warn(PREFIX "Invalid passive threshold\n"); |
Zhang Rui | ce44e19 | 2008-01-17 15:51:25 +0800 | [diff] [blame] | 383 | tz->trips.passive.flags.valid = 0; |
Zhang Rui | 0e4240d | 2009-01-16 12:53:42 -0500 | [diff] [blame] | 384 | } |
Zhang Rui | ce44e19 | 2008-01-17 15:51:25 +0800 | [diff] [blame] | 385 | else |
| 386 | tz->trips.passive.flags.valid = 1; |
| 387 | |
| 388 | if (memcmp(&tz->trips.passive.devices, &devices, |
| 389 | sizeof(struct acpi_handle_list))) { |
| 390 | memcpy(&tz->trips.passive.devices, &devices, |
| 391 | sizeof(struct acpi_handle_list)); |
| 392 | ACPI_THERMAL_TRIPS_EXCEPTION(flag, "device"); |
| 393 | } |
| 394 | } |
| 395 | if ((flag & ACPI_TRIPS_PASSIVE) || (flag & ACPI_TRIPS_DEVICES)) { |
| 396 | if (valid != tz->trips.passive.flags.valid) |
| 397 | ACPI_THERMAL_TRIPS_EXCEPTION(flag, "state"); |
| 398 | } |
| 399 | |
| 400 | /* Active (optional) */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 401 | for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 402 | char name[5] = { '_', 'A', 'C', ('0' + i), '\0' }; |
Zhang Rui | ce44e19 | 2008-01-17 15:51:25 +0800 | [diff] [blame] | 403 | valid = tz->trips.active[i].flags.valid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 404 | |
Len Brown | f8707ec | 2007-08-12 00:12:54 -0400 | [diff] [blame] | 405 | if (act == -1) |
Zhang Rui | ce44e19 | 2008-01-17 15:51:25 +0800 | [diff] [blame] | 406 | break; /* disable all active trip points */ |
Len Brown | f8707ec | 2007-08-12 00:12:54 -0400 | [diff] [blame] | 407 | |
Zhang Rui | 0e4240d | 2009-01-16 12:53:42 -0500 | [diff] [blame] | 408 | if ((flag == ACPI_TRIPS_INIT) || ((flag & ACPI_TRIPS_ACTIVE) && |
| 409 | tz->trips.active[i].flags.valid)) { |
Zhang Rui | ce44e19 | 2008-01-17 15:51:25 +0800 | [diff] [blame] | 410 | status = acpi_evaluate_integer(tz->device->handle, |
Matthew Wilcox | 27663c5 | 2008-10-10 02:22:59 -0400 | [diff] [blame] | 411 | name, NULL, &tmp); |
Zhang Rui | ce44e19 | 2008-01-17 15:51:25 +0800 | [diff] [blame] | 412 | if (ACPI_FAILURE(status)) { |
| 413 | tz->trips.active[i].flags.valid = 0; |
| 414 | if (i == 0) |
| 415 | break; |
| 416 | if (act <= 0) |
| 417 | break; |
| 418 | if (i == 1) |
| 419 | tz->trips.active[0].temperature = |
Rasmus Villemoes | e866a2e | 2015-10-01 23:45:31 +0200 | [diff] [blame] | 420 | CELSIUS_TO_DECI_KELVIN(act); |
Zhang Rui | ce44e19 | 2008-01-17 15:51:25 +0800 | [diff] [blame] | 421 | else |
| 422 | /* |
| 423 | * Don't allow override higher than |
| 424 | * the next higher trip point |
| 425 | */ |
| 426 | tz->trips.active[i - 1].temperature = |
| 427 | (tz->trips.active[i - 2].temperature < |
Rasmus Villemoes | e866a2e | 2015-10-01 23:45:31 +0200 | [diff] [blame] | 428 | CELSIUS_TO_DECI_KELVIN(act) ? |
Zhang Rui | ce44e19 | 2008-01-17 15:51:25 +0800 | [diff] [blame] | 429 | tz->trips.active[i - 2].temperature : |
Rasmus Villemoes | e866a2e | 2015-10-01 23:45:31 +0200 | [diff] [blame] | 430 | CELSIUS_TO_DECI_KELVIN(act)); |
Len Brown | f8707ec | 2007-08-12 00:12:54 -0400 | [diff] [blame] | 431 | break; |
Matthew Wilcox | 27663c5 | 2008-10-10 02:22:59 -0400 | [diff] [blame] | 432 | } else { |
| 433 | tz->trips.active[i].temperature = tmp; |
Zhang Rui | ce44e19 | 2008-01-17 15:51:25 +0800 | [diff] [blame] | 434 | tz->trips.active[i].flags.valid = 1; |
Matthew Wilcox | 27663c5 | 2008-10-10 02:22:59 -0400 | [diff] [blame] | 435 | } |
Len Brown | f8707ec | 2007-08-12 00:12:54 -0400 | [diff] [blame] | 436 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 437 | |
| 438 | name[2] = 'L'; |
Zhang Rui | ce44e19 | 2008-01-17 15:51:25 +0800 | [diff] [blame] | 439 | if ((flag & ACPI_TRIPS_DEVICES) && tz->trips.active[i].flags.valid ) { |
| 440 | memset(&devices, 0, sizeof(struct acpi_handle_list)); |
| 441 | status = acpi_evaluate_reference(tz->device->handle, |
| 442 | name, NULL, &devices); |
Zhang Rui | 0e4240d | 2009-01-16 12:53:42 -0500 | [diff] [blame] | 443 | if (ACPI_FAILURE(status)) { |
Andy Shevchenko | 766a8a6 | 2013-09-13 18:15:46 +0300 | [diff] [blame] | 444 | pr_warn(PREFIX "Invalid active%d threshold\n", |
| 445 | i); |
Zhang Rui | ce44e19 | 2008-01-17 15:51:25 +0800 | [diff] [blame] | 446 | tz->trips.active[i].flags.valid = 0; |
Zhang Rui | 0e4240d | 2009-01-16 12:53:42 -0500 | [diff] [blame] | 447 | } |
Zhang Rui | ce44e19 | 2008-01-17 15:51:25 +0800 | [diff] [blame] | 448 | else |
| 449 | tz->trips.active[i].flags.valid = 1; |
| 450 | |
| 451 | if (memcmp(&tz->trips.active[i].devices, &devices, |
| 452 | sizeof(struct acpi_handle_list))) { |
| 453 | memcpy(&tz->trips.active[i].devices, &devices, |
| 454 | sizeof(struct acpi_handle_list)); |
| 455 | ACPI_THERMAL_TRIPS_EXCEPTION(flag, "device"); |
| 456 | } |
| 457 | } |
| 458 | if ((flag & ACPI_TRIPS_ACTIVE) || (flag & ACPI_TRIPS_DEVICES)) |
| 459 | if (valid != tz->trips.active[i].flags.valid) |
| 460 | ACPI_THERMAL_TRIPS_EXCEPTION(flag, "state"); |
| 461 | |
| 462 | if (!tz->trips.active[i].flags.valid) |
| 463 | break; |
| 464 | } |
| 465 | |
Lan Tianyu | 668e020 | 2013-08-27 16:29:31 +0800 | [diff] [blame] | 466 | if ((flag & ACPI_TRIPS_DEVICES) |
| 467 | && acpi_has_method(tz->device->handle, "_TZD")) { |
| 468 | memset(&devices, 0, sizeof(devices)); |
Zhang Rui | ce44e19 | 2008-01-17 15:51:25 +0800 | [diff] [blame] | 469 | status = acpi_evaluate_reference(tz->device->handle, "_TZD", |
| 470 | NULL, &devices); |
Lan Tianyu | 668e020 | 2013-08-27 16:29:31 +0800 | [diff] [blame] | 471 | if (ACPI_SUCCESS(status) |
| 472 | && memcmp(&tz->devices, &devices, sizeof(devices))) { |
| 473 | tz->devices = devices; |
Zhang Rui | ce44e19 | 2008-01-17 15:51:25 +0800 | [diff] [blame] | 474 | ACPI_THERMAL_TRIPS_EXCEPTION(flag, "device"); |
| 475 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 476 | } |
| 477 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 478 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 479 | } |
| 480 | |
Zhang Rui | ce44e19 | 2008-01-17 15:51:25 +0800 | [diff] [blame] | 481 | static int acpi_thermal_get_trip_points(struct acpi_thermal *tz) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 482 | { |
Thomas Renninger | 8b7ef6d | 2010-02-16 22:55:51 +0100 | [diff] [blame] | 483 | int i, valid, ret = acpi_thermal_trips_update(tz, ACPI_TRIPS_INIT); |
| 484 | |
| 485 | if (ret) |
| 486 | return ret; |
| 487 | |
| 488 | valid = tz->trips.critical.flags.valid | |
| 489 | tz->trips.hot.flags.valid | |
| 490 | tz->trips.passive.flags.valid; |
| 491 | |
| 492 | for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) |
| 493 | valid |= tz->trips.active[i].flags.valid; |
| 494 | |
| 495 | if (!valid) { |
Andy Shevchenko | 766a8a6 | 2013-09-13 18:15:46 +0300 | [diff] [blame] | 496 | pr_warn(FW_BUG "No valid trip found\n"); |
Thomas Renninger | 8b7ef6d | 2010-02-16 22:55:51 +0100 | [diff] [blame] | 497 | return -ENODEV; |
| 498 | } |
| 499 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 500 | } |
| 501 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 502 | static void acpi_thermal_check(void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 503 | { |
Jan Engelhardt | 50dd096 | 2006-10-01 00:28:50 +0200 | [diff] [blame] | 504 | struct acpi_thermal *tz = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 505 | |
Srinivas Pandruvada | e994d71 | 2013-09-25 09:29:50 -0700 | [diff] [blame] | 506 | if (!tz->tz_enabled) |
Srinivas Pandruvada | ca4e713 | 2013-01-15 23:57:16 +0100 | [diff] [blame] | 507 | return; |
Srinivas Pandruvada | e994d71 | 2013-09-25 09:29:50 -0700 | [diff] [blame] | 508 | |
Srinivas Pandruvada | 0e70f46 | 2016-08-26 16:21:16 -0700 | [diff] [blame] | 509 | thermal_zone_device_update(tz->thermal_zone, |
| 510 | THERMAL_EVENT_UNSPECIFIED); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 511 | } |
| 512 | |
Zhang Rui | 3f655ef | 2008-01-17 15:51:11 +0800 | [diff] [blame] | 513 | /* sys I/F for generic thermal sysfs support */ |
Zhang, Rui | 5e01276 | 2008-02-28 07:51:30 +0800 | [diff] [blame] | 514 | |
Sascha Hauer | 17e8351 | 2015-07-24 08:12:54 +0200 | [diff] [blame] | 515 | static int thermal_get_temp(struct thermal_zone_device *thermal, int *temp) |
Zhang Rui | 3f655ef | 2008-01-17 15:51:11 +0800 | [diff] [blame] | 516 | { |
| 517 | struct acpi_thermal *tz = thermal->devdata; |
Zhang, Rui | 76ecb4f | 2008-04-10 16:20:23 +0800 | [diff] [blame] | 518 | int result; |
Zhang Rui | 3f655ef | 2008-01-17 15:51:11 +0800 | [diff] [blame] | 519 | |
| 520 | if (!tz) |
| 521 | return -EINVAL; |
| 522 | |
Zhang, Rui | 76ecb4f | 2008-04-10 16:20:23 +0800 | [diff] [blame] | 523 | result = acpi_thermal_get_temperature(tz); |
| 524 | if (result) |
| 525 | return result; |
| 526 | |
Aaron Lu | 7b83fd9 | 2014-03-25 10:40:09 +0800 | [diff] [blame] | 527 | *temp = DECI_KELVIN_TO_MILLICELSIUS_WITH_OFFSET(tz->temperature, |
| 528 | tz->kelvin_offset); |
Matthew Garrett | 6503e5d | 2008-11-27 17:48:13 +0000 | [diff] [blame] | 529 | return 0; |
Zhang Rui | 3f655ef | 2008-01-17 15:51:11 +0800 | [diff] [blame] | 530 | } |
| 531 | |
Zhang Rui | 3f655ef | 2008-01-17 15:51:11 +0800 | [diff] [blame] | 532 | static int thermal_get_mode(struct thermal_zone_device *thermal, |
Matthew Garrett | 6503e5d | 2008-11-27 17:48:13 +0000 | [diff] [blame] | 533 | enum thermal_device_mode *mode) |
Zhang Rui | 3f655ef | 2008-01-17 15:51:11 +0800 | [diff] [blame] | 534 | { |
| 535 | struct acpi_thermal *tz = thermal->devdata; |
| 536 | |
| 537 | if (!tz) |
| 538 | return -EINVAL; |
| 539 | |
Matthew Garrett | 6503e5d | 2008-11-27 17:48:13 +0000 | [diff] [blame] | 540 | *mode = tz->tz_enabled ? THERMAL_DEVICE_ENABLED : |
| 541 | THERMAL_DEVICE_DISABLED; |
| 542 | |
| 543 | return 0; |
Zhang Rui | 3f655ef | 2008-01-17 15:51:11 +0800 | [diff] [blame] | 544 | } |
| 545 | |
| 546 | static int thermal_set_mode(struct thermal_zone_device *thermal, |
Matthew Garrett | 6503e5d | 2008-11-27 17:48:13 +0000 | [diff] [blame] | 547 | enum thermal_device_mode mode) |
Zhang Rui | 3f655ef | 2008-01-17 15:51:11 +0800 | [diff] [blame] | 548 | { |
| 549 | struct acpi_thermal *tz = thermal->devdata; |
| 550 | int enable; |
| 551 | |
| 552 | if (!tz) |
| 553 | return -EINVAL; |
| 554 | |
| 555 | /* |
| 556 | * enable/disable thermal management from ACPI thermal driver |
| 557 | */ |
Matthew Garrett | 6503e5d | 2008-11-27 17:48:13 +0000 | [diff] [blame] | 558 | if (mode == THERMAL_DEVICE_ENABLED) |
Zhang Rui | 3f655ef | 2008-01-17 15:51:11 +0800 | [diff] [blame] | 559 | enable = 1; |
Srinivas Pandruvada | e994d71 | 2013-09-25 09:29:50 -0700 | [diff] [blame] | 560 | else if (mode == THERMAL_DEVICE_DISABLED) { |
Zhang Rui | 3f655ef | 2008-01-17 15:51:11 +0800 | [diff] [blame] | 561 | enable = 0; |
Srinivas Pandruvada | e994d71 | 2013-09-25 09:29:50 -0700 | [diff] [blame] | 562 | pr_warn("thermal zone will be disabled\n"); |
| 563 | } else |
Zhang Rui | 3f655ef | 2008-01-17 15:51:11 +0800 | [diff] [blame] | 564 | return -EINVAL; |
| 565 | |
| 566 | if (enable != tz->tz_enabled) { |
| 567 | tz->tz_enabled = enable; |
| 568 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
Zhang Rui | 8eaa8d6 | 2012-07-25 10:11:00 +0800 | [diff] [blame] | 569 | "%s kernel ACPI thermal control\n", |
| 570 | tz->tz_enabled ? "Enable" : "Disable")); |
Zhang Rui | 3f655ef | 2008-01-17 15:51:11 +0800 | [diff] [blame] | 571 | acpi_thermal_check(tz); |
| 572 | } |
| 573 | return 0; |
| 574 | } |
| 575 | |
| 576 | static int thermal_get_trip_type(struct thermal_zone_device *thermal, |
Matthew Garrett | 6503e5d | 2008-11-27 17:48:13 +0000 | [diff] [blame] | 577 | int trip, enum thermal_trip_type *type) |
Zhang Rui | 3f655ef | 2008-01-17 15:51:11 +0800 | [diff] [blame] | 578 | { |
| 579 | struct acpi_thermal *tz = thermal->devdata; |
| 580 | int i; |
| 581 | |
| 582 | if (!tz || trip < 0) |
| 583 | return -EINVAL; |
| 584 | |
| 585 | if (tz->trips.critical.flags.valid) { |
Matthew Garrett | 6503e5d | 2008-11-27 17:48:13 +0000 | [diff] [blame] | 586 | if (!trip) { |
| 587 | *type = THERMAL_TRIP_CRITICAL; |
| 588 | return 0; |
| 589 | } |
Zhang Rui | 3f655ef | 2008-01-17 15:51:11 +0800 | [diff] [blame] | 590 | trip--; |
| 591 | } |
| 592 | |
| 593 | if (tz->trips.hot.flags.valid) { |
Matthew Garrett | 6503e5d | 2008-11-27 17:48:13 +0000 | [diff] [blame] | 594 | if (!trip) { |
| 595 | *type = THERMAL_TRIP_HOT; |
| 596 | return 0; |
| 597 | } |
Zhang Rui | 3f655ef | 2008-01-17 15:51:11 +0800 | [diff] [blame] | 598 | trip--; |
| 599 | } |
| 600 | |
| 601 | if (tz->trips.passive.flags.valid) { |
Matthew Garrett | 6503e5d | 2008-11-27 17:48:13 +0000 | [diff] [blame] | 602 | if (!trip) { |
| 603 | *type = THERMAL_TRIP_PASSIVE; |
| 604 | return 0; |
| 605 | } |
Zhang Rui | 3f655ef | 2008-01-17 15:51:11 +0800 | [diff] [blame] | 606 | trip--; |
| 607 | } |
| 608 | |
| 609 | for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE && |
| 610 | tz->trips.active[i].flags.valid; i++) { |
Matthew Garrett | 6503e5d | 2008-11-27 17:48:13 +0000 | [diff] [blame] | 611 | if (!trip) { |
| 612 | *type = THERMAL_TRIP_ACTIVE; |
| 613 | return 0; |
| 614 | } |
Zhang Rui | 3f655ef | 2008-01-17 15:51:11 +0800 | [diff] [blame] | 615 | trip--; |
| 616 | } |
| 617 | |
| 618 | return -EINVAL; |
| 619 | } |
| 620 | |
| 621 | static int thermal_get_trip_temp(struct thermal_zone_device *thermal, |
Sascha Hauer | 17e8351 | 2015-07-24 08:12:54 +0200 | [diff] [blame] | 622 | int trip, int *temp) |
Zhang Rui | 3f655ef | 2008-01-17 15:51:11 +0800 | [diff] [blame] | 623 | { |
| 624 | struct acpi_thermal *tz = thermal->devdata; |
| 625 | int i; |
| 626 | |
| 627 | if (!tz || trip < 0) |
| 628 | return -EINVAL; |
| 629 | |
| 630 | if (tz->trips.critical.flags.valid) { |
Matthew Garrett | 6503e5d | 2008-11-27 17:48:13 +0000 | [diff] [blame] | 631 | if (!trip) { |
Aaron Lu | 7b83fd9 | 2014-03-25 10:40:09 +0800 | [diff] [blame] | 632 | *temp = DECI_KELVIN_TO_MILLICELSIUS_WITH_OFFSET( |
Jean Delvare | 13614e3 | 2009-04-06 16:01:46 +0200 | [diff] [blame] | 633 | tz->trips.critical.temperature, |
| 634 | tz->kelvin_offset); |
Matthew Garrett | 6503e5d | 2008-11-27 17:48:13 +0000 | [diff] [blame] | 635 | return 0; |
| 636 | } |
Zhang Rui | 3f655ef | 2008-01-17 15:51:11 +0800 | [diff] [blame] | 637 | trip--; |
| 638 | } |
| 639 | |
| 640 | if (tz->trips.hot.flags.valid) { |
Matthew Garrett | 6503e5d | 2008-11-27 17:48:13 +0000 | [diff] [blame] | 641 | if (!trip) { |
Aaron Lu | 7b83fd9 | 2014-03-25 10:40:09 +0800 | [diff] [blame] | 642 | *temp = DECI_KELVIN_TO_MILLICELSIUS_WITH_OFFSET( |
Jean Delvare | 13614e3 | 2009-04-06 16:01:46 +0200 | [diff] [blame] | 643 | tz->trips.hot.temperature, |
| 644 | tz->kelvin_offset); |
Matthew Garrett | 6503e5d | 2008-11-27 17:48:13 +0000 | [diff] [blame] | 645 | return 0; |
| 646 | } |
Zhang Rui | 3f655ef | 2008-01-17 15:51:11 +0800 | [diff] [blame] | 647 | trip--; |
| 648 | } |
| 649 | |
| 650 | if (tz->trips.passive.flags.valid) { |
Matthew Garrett | 6503e5d | 2008-11-27 17:48:13 +0000 | [diff] [blame] | 651 | if (!trip) { |
Aaron Lu | 7b83fd9 | 2014-03-25 10:40:09 +0800 | [diff] [blame] | 652 | *temp = DECI_KELVIN_TO_MILLICELSIUS_WITH_OFFSET( |
Jean Delvare | 13614e3 | 2009-04-06 16:01:46 +0200 | [diff] [blame] | 653 | tz->trips.passive.temperature, |
| 654 | tz->kelvin_offset); |
Matthew Garrett | 6503e5d | 2008-11-27 17:48:13 +0000 | [diff] [blame] | 655 | return 0; |
| 656 | } |
Zhang Rui | 3f655ef | 2008-01-17 15:51:11 +0800 | [diff] [blame] | 657 | trip--; |
| 658 | } |
| 659 | |
| 660 | for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE && |
| 661 | tz->trips.active[i].flags.valid; i++) { |
Matthew Garrett | 6503e5d | 2008-11-27 17:48:13 +0000 | [diff] [blame] | 662 | if (!trip) { |
Aaron Lu | 7b83fd9 | 2014-03-25 10:40:09 +0800 | [diff] [blame] | 663 | *temp = DECI_KELVIN_TO_MILLICELSIUS_WITH_OFFSET( |
Jean Delvare | 13614e3 | 2009-04-06 16:01:46 +0200 | [diff] [blame] | 664 | tz->trips.active[i].temperature, |
| 665 | tz->kelvin_offset); |
Matthew Garrett | 6503e5d | 2008-11-27 17:48:13 +0000 | [diff] [blame] | 666 | return 0; |
| 667 | } |
Zhang Rui | 3f655ef | 2008-01-17 15:51:11 +0800 | [diff] [blame] | 668 | trip--; |
| 669 | } |
| 670 | |
| 671 | return -EINVAL; |
| 672 | } |
| 673 | |
Zhang, Rui | 9ec732f | 2008-04-10 16:13:10 +0800 | [diff] [blame] | 674 | static int thermal_get_crit_temp(struct thermal_zone_device *thermal, |
Sascha Hauer | 17e8351 | 2015-07-24 08:12:54 +0200 | [diff] [blame] | 675 | int *temperature) |
| 676 | { |
Zhang, Rui | 9ec732f | 2008-04-10 16:13:10 +0800 | [diff] [blame] | 677 | struct acpi_thermal *tz = thermal->devdata; |
| 678 | |
| 679 | if (tz->trips.critical.flags.valid) { |
Aaron Lu | 7b83fd9 | 2014-03-25 10:40:09 +0800 | [diff] [blame] | 680 | *temperature = DECI_KELVIN_TO_MILLICELSIUS_WITH_OFFSET( |
Jean Delvare | 13614e3 | 2009-04-06 16:01:46 +0200 | [diff] [blame] | 681 | tz->trips.critical.temperature, |
| 682 | tz->kelvin_offset); |
Zhang, Rui | 9ec732f | 2008-04-10 16:13:10 +0800 | [diff] [blame] | 683 | return 0; |
| 684 | } else |
| 685 | return -EINVAL; |
| 686 | } |
| 687 | |
Zhang Rui | 601f3d4 | 2012-06-27 09:54:33 +0800 | [diff] [blame] | 688 | static int thermal_get_trend(struct thermal_zone_device *thermal, |
| 689 | int trip, enum thermal_trend *trend) |
| 690 | { |
| 691 | struct acpi_thermal *tz = thermal->devdata; |
| 692 | enum thermal_trip_type type; |
| 693 | int i; |
| 694 | |
| 695 | if (thermal_get_trip_type(thermal, trip, &type)) |
| 696 | return -EINVAL; |
| 697 | |
Zhang Rui | 4ae46be | 2012-06-27 10:05:39 +0800 | [diff] [blame] | 698 | if (type == THERMAL_TRIP_ACTIVE) { |
Sascha Hauer | 17e8351 | 2015-07-24 08:12:54 +0200 | [diff] [blame] | 699 | int trip_temp; |
| 700 | int temp = DECI_KELVIN_TO_MILLICELSIUS_WITH_OFFSET( |
Aaron Lu | 7b83fd9 | 2014-03-25 10:40:09 +0800 | [diff] [blame] | 701 | tz->temperature, tz->kelvin_offset); |
Zhang Rui | 94a4093 | 2013-04-26 09:19:53 +0000 | [diff] [blame] | 702 | if (thermal_get_trip_temp(thermal, trip, &trip_temp)) |
| 703 | return -EINVAL; |
| 704 | |
| 705 | if (temp > trip_temp) { |
| 706 | *trend = THERMAL_TREND_RAISING; |
| 707 | return 0; |
| 708 | } else { |
| 709 | /* Fall back on default trend */ |
| 710 | return -EINVAL; |
| 711 | } |
Zhang Rui | 4ae46be | 2012-06-27 10:05:39 +0800 | [diff] [blame] | 712 | } |
Zhang Rui | 601f3d4 | 2012-06-27 09:54:33 +0800 | [diff] [blame] | 713 | |
| 714 | /* |
| 715 | * tz->temperature has already been updated by generic thermal layer, |
| 716 | * before this callback being invoked |
| 717 | */ |
| 718 | i = (tz->trips.passive.tc1 * (tz->temperature - tz->last_temperature)) |
| 719 | + (tz->trips.passive.tc2 |
| 720 | * (tz->temperature - tz->trips.passive.temperature)); |
| 721 | |
| 722 | if (i > 0) |
| 723 | *trend = THERMAL_TREND_RAISING; |
| 724 | else if (i < 0) |
| 725 | *trend = THERMAL_TREND_DROPPING; |
| 726 | else |
| 727 | *trend = THERMAL_TREND_STABLE; |
| 728 | return 0; |
| 729 | } |
| 730 | |
| 731 | |
Matthew Garrett | b1569e9 | 2008-12-03 17:55:32 +0000 | [diff] [blame] | 732 | static int thermal_notify(struct thermal_zone_device *thermal, int trip, |
| 733 | enum thermal_trip_type trip_type) |
| 734 | { |
| 735 | u8 type = 0; |
| 736 | struct acpi_thermal *tz = thermal->devdata; |
| 737 | |
| 738 | if (trip_type == THERMAL_TRIP_CRITICAL) |
| 739 | type = ACPI_THERMAL_NOTIFY_CRITICAL; |
| 740 | else if (trip_type == THERMAL_TRIP_HOT) |
| 741 | type = ACPI_THERMAL_NOTIFY_HOT; |
| 742 | else |
| 743 | return 0; |
| 744 | |
Matthew Garrett | b1569e9 | 2008-12-03 17:55:32 +0000 | [diff] [blame] | 745 | acpi_bus_generate_netlink_event(tz->device->pnp.device_class, |
Stephen Rothwell | f6f5c45 | 2009-03-03 12:47:17 +1100 | [diff] [blame] | 746 | dev_name(&tz->device->dev), type, 1); |
Matthew Garrett | b1569e9 | 2008-12-03 17:55:32 +0000 | [diff] [blame] | 747 | |
| 748 | if (trip_type == THERMAL_TRIP_CRITICAL && nocrt) |
| 749 | return 1; |
| 750 | |
| 751 | return 0; |
| 752 | } |
| 753 | |
Zhang Rui | 3f655ef | 2008-01-17 15:51:11 +0800 | [diff] [blame] | 754 | static int acpi_thermal_cooling_device_cb(struct thermal_zone_device *thermal, |
| 755 | struct thermal_cooling_device *cdev, |
Zhang Rui | 9d99842 | 2012-06-26 16:35:57 +0800 | [diff] [blame] | 756 | bool bind) |
Zhang Rui | 3f655ef | 2008-01-17 15:51:11 +0800 | [diff] [blame] | 757 | { |
| 758 | struct acpi_device *device = cdev->devdata; |
| 759 | struct acpi_thermal *tz = thermal->devdata; |
Zhang Rui | 653a00c | 2008-01-17 15:51:18 +0800 | [diff] [blame] | 760 | struct acpi_device *dev; |
| 761 | acpi_status status; |
| 762 | acpi_handle handle; |
Zhang Rui | 3f655ef | 2008-01-17 15:51:11 +0800 | [diff] [blame] | 763 | int i; |
| 764 | int j; |
| 765 | int trip = -1; |
| 766 | int result = 0; |
| 767 | |
| 768 | if (tz->trips.critical.flags.valid) |
| 769 | trip++; |
| 770 | |
| 771 | if (tz->trips.hot.flags.valid) |
| 772 | trip++; |
| 773 | |
| 774 | if (tz->trips.passive.flags.valid) { |
| 775 | trip++; |
| 776 | for (i = 0; i < tz->trips.passive.devices.count; |
| 777 | i++) { |
Zhang Rui | 653a00c | 2008-01-17 15:51:18 +0800 | [diff] [blame] | 778 | handle = tz->trips.passive.devices.handles[i]; |
| 779 | status = acpi_bus_get_device(handle, &dev); |
Zhang Rui | 9d99842 | 2012-06-26 16:35:57 +0800 | [diff] [blame] | 780 | if (ACPI_FAILURE(status) || dev != device) |
| 781 | continue; |
| 782 | if (bind) |
| 783 | result = |
| 784 | thermal_zone_bind_cooling_device |
| 785 | (thermal, trip, cdev, |
Kapileshwar Singh | 6cd9e9f | 2015-02-18 16:04:21 +0000 | [diff] [blame] | 786 | THERMAL_NO_LIMIT, THERMAL_NO_LIMIT, |
| 787 | THERMAL_WEIGHT_DEFAULT); |
Zhang Rui | 9d99842 | 2012-06-26 16:35:57 +0800 | [diff] [blame] | 788 | else |
| 789 | result = |
| 790 | thermal_zone_unbind_cooling_device |
| 791 | (thermal, trip, cdev); |
| 792 | if (result) |
| 793 | goto failed; |
Zhang Rui | 3f655ef | 2008-01-17 15:51:11 +0800 | [diff] [blame] | 794 | } |
| 795 | } |
| 796 | |
| 797 | for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) { |
| 798 | if (!tz->trips.active[i].flags.valid) |
| 799 | break; |
| 800 | trip++; |
| 801 | for (j = 0; |
| 802 | j < tz->trips.active[i].devices.count; |
| 803 | j++) { |
Zhang Rui | 653a00c | 2008-01-17 15:51:18 +0800 | [diff] [blame] | 804 | handle = tz->trips.active[i].devices.handles[j]; |
| 805 | status = acpi_bus_get_device(handle, &dev); |
Zhang Rui | 9d99842 | 2012-06-26 16:35:57 +0800 | [diff] [blame] | 806 | if (ACPI_FAILURE(status) || dev != device) |
| 807 | continue; |
| 808 | if (bind) |
| 809 | result = thermal_zone_bind_cooling_device |
| 810 | (thermal, trip, cdev, |
Kapileshwar Singh | 6cd9e9f | 2015-02-18 16:04:21 +0000 | [diff] [blame] | 811 | THERMAL_NO_LIMIT, THERMAL_NO_LIMIT, |
| 812 | THERMAL_WEIGHT_DEFAULT); |
Zhang Rui | 9d99842 | 2012-06-26 16:35:57 +0800 | [diff] [blame] | 813 | else |
| 814 | result = thermal_zone_unbind_cooling_device |
| 815 | (thermal, trip, cdev); |
| 816 | if (result) |
| 817 | goto failed; |
Zhang Rui | 3f655ef | 2008-01-17 15:51:11 +0800 | [diff] [blame] | 818 | } |
| 819 | } |
| 820 | |
| 821 | for (i = 0; i < tz->devices.count; i++) { |
Zhang Rui | 653a00c | 2008-01-17 15:51:18 +0800 | [diff] [blame] | 822 | handle = tz->devices.handles[i]; |
| 823 | status = acpi_bus_get_device(handle, &dev); |
| 824 | if (ACPI_SUCCESS(status) && (dev == device)) { |
Zhang Rui | 9d99842 | 2012-06-26 16:35:57 +0800 | [diff] [blame] | 825 | if (bind) |
| 826 | result = thermal_zone_bind_cooling_device |
Lan Tianyu | 70f2903 | 2013-08-14 21:00:39 +0800 | [diff] [blame] | 827 | (thermal, THERMAL_TRIPS_NONE, |
| 828 | cdev, THERMAL_NO_LIMIT, |
Kapileshwar Singh | 6cd9e9f | 2015-02-18 16:04:21 +0000 | [diff] [blame] | 829 | THERMAL_NO_LIMIT, |
| 830 | THERMAL_WEIGHT_DEFAULT); |
Zhang Rui | 9d99842 | 2012-06-26 16:35:57 +0800 | [diff] [blame] | 831 | else |
| 832 | result = thermal_zone_unbind_cooling_device |
Lan Tianyu | 70f2903 | 2013-08-14 21:00:39 +0800 | [diff] [blame] | 833 | (thermal, THERMAL_TRIPS_NONE, |
| 834 | cdev); |
Zhang Rui | 653a00c | 2008-01-17 15:51:18 +0800 | [diff] [blame] | 835 | if (result) |
| 836 | goto failed; |
| 837 | } |
Zhang Rui | 3f655ef | 2008-01-17 15:51:11 +0800 | [diff] [blame] | 838 | } |
| 839 | |
| 840 | failed: |
| 841 | return result; |
| 842 | } |
| 843 | |
| 844 | static int |
| 845 | acpi_thermal_bind_cooling_device(struct thermal_zone_device *thermal, |
| 846 | struct thermal_cooling_device *cdev) |
| 847 | { |
Zhang Rui | 9d99842 | 2012-06-26 16:35:57 +0800 | [diff] [blame] | 848 | return acpi_thermal_cooling_device_cb(thermal, cdev, true); |
Zhang Rui | 3f655ef | 2008-01-17 15:51:11 +0800 | [diff] [blame] | 849 | } |
| 850 | |
| 851 | static int |
| 852 | acpi_thermal_unbind_cooling_device(struct thermal_zone_device *thermal, |
| 853 | struct thermal_cooling_device *cdev) |
| 854 | { |
Zhang Rui | 9d99842 | 2012-06-26 16:35:57 +0800 | [diff] [blame] | 855 | return acpi_thermal_cooling_device_cb(thermal, cdev, false); |
Zhang Rui | 3f655ef | 2008-01-17 15:51:11 +0800 | [diff] [blame] | 856 | } |
| 857 | |
Emil Goode | ec9c9c2 | 2014-01-07 17:24:55 +0100 | [diff] [blame] | 858 | static struct thermal_zone_device_ops acpi_thermal_zone_ops = { |
Zhang Rui | 3f655ef | 2008-01-17 15:51:11 +0800 | [diff] [blame] | 859 | .bind = acpi_thermal_bind_cooling_device, |
| 860 | .unbind = acpi_thermal_unbind_cooling_device, |
| 861 | .get_temp = thermal_get_temp, |
| 862 | .get_mode = thermal_get_mode, |
| 863 | .set_mode = thermal_set_mode, |
| 864 | .get_trip_type = thermal_get_trip_type, |
| 865 | .get_trip_temp = thermal_get_trip_temp, |
Zhang, Rui | 9ec732f | 2008-04-10 16:13:10 +0800 | [diff] [blame] | 866 | .get_crit_temp = thermal_get_crit_temp, |
Zhang Rui | 601f3d4 | 2012-06-27 09:54:33 +0800 | [diff] [blame] | 867 | .get_trend = thermal_get_trend, |
Matthew Garrett | b1569e9 | 2008-12-03 17:55:32 +0000 | [diff] [blame] | 868 | .notify = thermal_notify, |
Zhang Rui | 3f655ef | 2008-01-17 15:51:11 +0800 | [diff] [blame] | 869 | }; |
| 870 | |
| 871 | static int acpi_thermal_register_thermal_zone(struct acpi_thermal *tz) |
| 872 | { |
| 873 | int trips = 0; |
| 874 | int result; |
Zhang Rui | 2073393 | 2008-01-17 15:51:21 +0800 | [diff] [blame] | 875 | acpi_status status; |
Zhang Rui | 3f655ef | 2008-01-17 15:51:11 +0800 | [diff] [blame] | 876 | int i; |
| 877 | |
| 878 | if (tz->trips.critical.flags.valid) |
| 879 | trips++; |
| 880 | |
| 881 | if (tz->trips.hot.flags.valid) |
| 882 | trips++; |
| 883 | |
| 884 | if (tz->trips.passive.flags.valid) |
| 885 | trips++; |
| 886 | |
| 887 | for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE && |
| 888 | tz->trips.active[i].flags.valid; i++, trips++); |
Matthew Garrett | b1569e9 | 2008-12-03 17:55:32 +0000 | [diff] [blame] | 889 | |
| 890 | if (tz->trips.passive.flags.valid) |
| 891 | tz->thermal_zone = |
Durgadoss R | c56f5c0 | 2012-07-25 10:10:58 +0800 | [diff] [blame] | 892 | thermal_zone_device_register("acpitz", trips, 0, tz, |
Durgadoss R | 50125a9 | 2012-09-18 11:04:56 +0530 | [diff] [blame] | 893 | &acpi_thermal_zone_ops, NULL, |
Matthew Garrett | b1569e9 | 2008-12-03 17:55:32 +0000 | [diff] [blame] | 894 | tz->trips.passive.tsp*100, |
| 895 | tz->polling_frequency*100); |
| 896 | else |
| 897 | tz->thermal_zone = |
Durgadoss R | c56f5c0 | 2012-07-25 10:10:58 +0800 | [diff] [blame] | 898 | thermal_zone_device_register("acpitz", trips, 0, tz, |
Durgadoss R | 50125a9 | 2012-09-18 11:04:56 +0530 | [diff] [blame] | 899 | &acpi_thermal_zone_ops, NULL, |
| 900 | 0, tz->polling_frequency*100); |
Krzysztof Helt | bb070e4 | 2008-04-08 17:41:52 -0700 | [diff] [blame] | 901 | if (IS_ERR(tz->thermal_zone)) |
Zhang Rui | 3f655ef | 2008-01-17 15:51:11 +0800 | [diff] [blame] | 902 | return -ENODEV; |
| 903 | |
| 904 | result = sysfs_create_link(&tz->device->dev.kobj, |
| 905 | &tz->thermal_zone->device.kobj, "thermal_zone"); |
| 906 | if (result) |
| 907 | return result; |
| 908 | |
| 909 | result = sysfs_create_link(&tz->thermal_zone->device.kobj, |
| 910 | &tz->device->dev.kobj, "device"); |
| 911 | if (result) |
| 912 | return result; |
| 913 | |
Lan Tianyu | e6f8a4d | 2014-05-20 20:59:22 +0800 | [diff] [blame] | 914 | status = acpi_bus_attach_private_data(tz->device->handle, |
| 915 | tz->thermal_zone); |
| 916 | if (ACPI_FAILURE(status)) |
Zhang Rui | 2073393 | 2008-01-17 15:51:21 +0800 | [diff] [blame] | 917 | return -ENODEV; |
Zhang Rui | 2073393 | 2008-01-17 15:51:21 +0800 | [diff] [blame] | 918 | |
Zhang Rui | 3f655ef | 2008-01-17 15:51:11 +0800 | [diff] [blame] | 919 | tz->tz_enabled = 1; |
| 920 | |
Greg Kroah-Hartman | fc3a882 | 2008-05-02 06:02:41 +0200 | [diff] [blame] | 921 | dev_info(&tz->device->dev, "registered as thermal_zone%d\n", |
| 922 | tz->thermal_zone->id); |
Zhang Rui | 3f655ef | 2008-01-17 15:51:11 +0800 | [diff] [blame] | 923 | return 0; |
| 924 | } |
| 925 | |
| 926 | static void acpi_thermal_unregister_thermal_zone(struct acpi_thermal *tz) |
| 927 | { |
| 928 | sysfs_remove_link(&tz->device->dev.kobj, "thermal_zone"); |
| 929 | sysfs_remove_link(&tz->thermal_zone->device.kobj, "device"); |
| 930 | thermal_zone_device_unregister(tz->thermal_zone); |
| 931 | tz->thermal_zone = NULL; |
Lan Tianyu | e6f8a4d | 2014-05-20 20:59:22 +0800 | [diff] [blame] | 932 | acpi_bus_detach_private_data(tz->device->handle); |
Zhang Rui | 3f655ef | 2008-01-17 15:51:11 +0800 | [diff] [blame] | 933 | } |
| 934 | |
| 935 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 936 | /* -------------------------------------------------------------------------- |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 937 | Driver Interface |
| 938 | -------------------------------------------------------------------------- */ |
| 939 | |
Bjorn Helgaas | 342d550 | 2009-04-07 15:37:06 +0000 | [diff] [blame] | 940 | static void acpi_thermal_notify(struct acpi_device *device, u32 event) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 941 | { |
Bjorn Helgaas | 342d550 | 2009-04-07 15:37:06 +0000 | [diff] [blame] | 942 | struct acpi_thermal *tz = acpi_driver_data(device); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 943 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 944 | |
| 945 | if (!tz) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 946 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 947 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 948 | switch (event) { |
| 949 | case ACPI_THERMAL_NOTIFY_TEMPERATURE: |
| 950 | acpi_thermal_check(tz); |
| 951 | break; |
| 952 | case ACPI_THERMAL_NOTIFY_THRESHOLDS: |
Zhang Rui | ce44e19 | 2008-01-17 15:51:25 +0800 | [diff] [blame] | 953 | acpi_thermal_trips_update(tz, ACPI_TRIPS_REFRESH_THRESHOLDS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 954 | acpi_thermal_check(tz); |
Zhang Rui | 962ce8c | 2007-08-23 01:24:31 +0800 | [diff] [blame] | 955 | acpi_bus_generate_netlink_event(device->pnp.device_class, |
Kay Sievers | 0794469 | 2008-10-30 01:18:59 +0100 | [diff] [blame] | 956 | dev_name(&device->dev), event, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 957 | break; |
| 958 | case ACPI_THERMAL_NOTIFY_DEVICES: |
Zhang Rui | ce44e19 | 2008-01-17 15:51:25 +0800 | [diff] [blame] | 959 | acpi_thermal_trips_update(tz, ACPI_TRIPS_REFRESH_DEVICES); |
| 960 | acpi_thermal_check(tz); |
Zhang Rui | 962ce8c | 2007-08-23 01:24:31 +0800 | [diff] [blame] | 961 | acpi_bus_generate_netlink_event(device->pnp.device_class, |
Kay Sievers | 0794469 | 2008-10-30 01:18:59 +0100 | [diff] [blame] | 962 | dev_name(&device->dev), event, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 963 | break; |
| 964 | default: |
| 965 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 966 | "Unsupported event [0x%x]\n", event)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 967 | break; |
| 968 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 969 | } |
| 970 | |
Zhang Rui | 261cba2 | 2012-11-27 20:42:11 +0100 | [diff] [blame] | 971 | /* |
| 972 | * On some platforms, the AML code has dependency about |
| 973 | * the evaluating order of _TMP and _CRT/_HOT/_PSV/_ACx. |
| 974 | * 1. On HP Pavilion G4-1016tx, _TMP must be invoked after |
| 975 | * /_CRT/_HOT/_PSV/_ACx, or else system will be power off. |
| 976 | * 2. On HP Compaq 6715b/6715s, the return value of _PSV is 0 |
| 977 | * if _TMP has never been evaluated. |
| 978 | * |
| 979 | * As this dependency is totally transparent to OS, evaluate |
| 980 | * all of them once, in the order of _CRT/_HOT/_PSV/_ACx, |
| 981 | * _TMP, before they are actually used. |
| 982 | */ |
| 983 | static void acpi_thermal_aml_dependency_fix(struct acpi_thermal *tz) |
| 984 | { |
| 985 | acpi_handle handle = tz->device->handle; |
| 986 | unsigned long long value; |
| 987 | int i; |
| 988 | |
| 989 | acpi_evaluate_integer(handle, "_CRT", NULL, &value); |
| 990 | acpi_evaluate_integer(handle, "_HOT", NULL, &value); |
| 991 | acpi_evaluate_integer(handle, "_PSV", NULL, &value); |
| 992 | for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) { |
| 993 | char name[5] = { '_', 'A', 'C', ('0' + i), '\0' }; |
| 994 | acpi_status status; |
| 995 | |
| 996 | status = acpi_evaluate_integer(handle, name, NULL, &value); |
| 997 | if (status == AE_NOT_FOUND) |
| 998 | break; |
| 999 | } |
| 1000 | acpi_evaluate_integer(handle, "_TMP", NULL, &value); |
| 1001 | } |
| 1002 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1003 | static int acpi_thermal_get_info(struct acpi_thermal *tz) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1004 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1005 | int result = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1006 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1007 | |
| 1008 | if (!tz) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1009 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1010 | |
Zhang Rui | 261cba2 | 2012-11-27 20:42:11 +0100 | [diff] [blame] | 1011 | acpi_thermal_aml_dependency_fix(tz); |
| 1012 | |
Matthew Garrett | 9bcb811 | 2012-02-01 10:26:54 -0500 | [diff] [blame] | 1013 | /* Get trip points [_CRT, _PSV, etc.] (required) */ |
| 1014 | result = acpi_thermal_get_trip_points(tz); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1015 | if (result) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1016 | return result; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1017 | |
Matthew Garrett | 9bcb811 | 2012-02-01 10:26:54 -0500 | [diff] [blame] | 1018 | /* Get temperature [_TMP] (required) */ |
| 1019 | result = acpi_thermal_get_temperature(tz); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1020 | if (result) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1021 | return result; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1022 | |
| 1023 | /* Set the cooling mode [_SCP] to active cooling (default) */ |
| 1024 | result = acpi_thermal_set_cooling_mode(tz, ACPI_THERMAL_MODE_ACTIVE); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1025 | if (!result) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1026 | tz->flags.cooling_mode = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1027 | |
| 1028 | /* Get default polling frequency [_TZP] (optional) */ |
| 1029 | if (tzp) |
| 1030 | tz->polling_frequency = tzp; |
| 1031 | else |
| 1032 | acpi_thermal_get_polling_frequency(tz); |
| 1033 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1034 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1035 | } |
| 1036 | |
Jean Delvare | 13614e3 | 2009-04-06 16:01:46 +0200 | [diff] [blame] | 1037 | /* |
| 1038 | * The exact offset between Kelvin and degree Celsius is 273.15. However ACPI |
| 1039 | * handles temperature values with a single decimal place. As a consequence, |
| 1040 | * some implementations use an offset of 273.1 and others use an offset of |
| 1041 | * 273.2. Try to find out which one is being used, to present the most |
| 1042 | * accurate and visually appealing number. |
| 1043 | * |
| 1044 | * The heuristic below should work for all ACPI thermal zones which have a |
| 1045 | * critical trip point with a value being a multiple of 0.5 degree Celsius. |
| 1046 | */ |
| 1047 | static void acpi_thermal_guess_offset(struct acpi_thermal *tz) |
| 1048 | { |
| 1049 | if (tz->trips.critical.flags.valid && |
| 1050 | (tz->trips.critical.temperature % 5) == 1) |
| 1051 | tz->kelvin_offset = 2731; |
| 1052 | else |
| 1053 | tz->kelvin_offset = 2732; |
| 1054 | } |
| 1055 | |
Aaron Lu | a59ffb2 | 2014-03-04 14:24:46 +0800 | [diff] [blame] | 1056 | static void acpi_thermal_check_fn(struct work_struct *work) |
| 1057 | { |
| 1058 | struct acpi_thermal *tz = container_of(work, struct acpi_thermal, |
| 1059 | thermal_check_work); |
| 1060 | acpi_thermal_check(tz); |
| 1061 | } |
| 1062 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1063 | static int acpi_thermal_add(struct acpi_device *device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1064 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1065 | int result = 0; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1066 | struct acpi_thermal *tz = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1067 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1068 | |
| 1069 | if (!device) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1070 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1071 | |
Burman Yan | 36bcbec | 2006-12-19 12:56:11 -0800 | [diff] [blame] | 1072 | tz = kzalloc(sizeof(struct acpi_thermal), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1073 | if (!tz) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1074 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1075 | |
Patrick Mochel | 8348e1b | 2006-05-19 16:54:40 -0400 | [diff] [blame] | 1076 | tz->device = device; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1077 | strcpy(tz->name, device->pnp.bus_id); |
| 1078 | strcpy(acpi_device_name(device), ACPI_THERMAL_DEVICE_NAME); |
| 1079 | strcpy(acpi_device_class(device), ACPI_THERMAL_CLASS); |
Pavel Machek | db89b4f | 2008-09-22 14:37:34 -0700 | [diff] [blame] | 1080 | device->driver_data = tz; |
Zhang Rui | 3f655ef | 2008-01-17 15:51:11 +0800 | [diff] [blame] | 1081 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1082 | result = acpi_thermal_get_info(tz); |
| 1083 | if (result) |
Zhang Rui | 3f655ef | 2008-01-17 15:51:11 +0800 | [diff] [blame] | 1084 | goto free_memory; |
| 1085 | |
Jean Delvare | 13614e3 | 2009-04-06 16:01:46 +0200 | [diff] [blame] | 1086 | acpi_thermal_guess_offset(tz); |
| 1087 | |
Zhang Rui | 3f655ef | 2008-01-17 15:51:11 +0800 | [diff] [blame] | 1088 | result = acpi_thermal_register_thermal_zone(tz); |
| 1089 | if (result) |
| 1090 | goto free_memory; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1091 | |
Aaron Lu | a59ffb2 | 2014-03-04 14:24:46 +0800 | [diff] [blame] | 1092 | INIT_WORK(&tz->thermal_check_work, acpi_thermal_check_fn); |
| 1093 | |
Andy Shevchenko | 766a8a6 | 2013-09-13 18:15:46 +0300 | [diff] [blame] | 1094 | pr_info(PREFIX "%s [%s] (%ld C)\n", acpi_device_name(device), |
Rasmus Villemoes | e866a2e | 2015-10-01 23:45:31 +0200 | [diff] [blame] | 1095 | acpi_device_bid(device), DECI_KELVIN_TO_CELSIUS(tz->temperature)); |
Zhang Rui | 3f655ef | 2008-01-17 15:51:11 +0800 | [diff] [blame] | 1096 | goto end; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1097 | |
Zhang Rui | 3f655ef | 2008-01-17 15:51:11 +0800 | [diff] [blame] | 1098 | free_memory: |
| 1099 | kfree(tz); |
| 1100 | end: |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1101 | return result; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1102 | } |
| 1103 | |
Rafael J. Wysocki | 51fac83 | 2013-01-24 00:24:48 +0100 | [diff] [blame] | 1104 | static int acpi_thermal_remove(struct acpi_device *device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1105 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1106 | struct acpi_thermal *tz = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1107 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1108 | if (!device || !acpi_driver_data(device)) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1109 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1110 | |
Aaron Lu | a59ffb2 | 2014-03-04 14:24:46 +0800 | [diff] [blame] | 1111 | flush_workqueue(acpi_thermal_pm_queue); |
Jan Engelhardt | 50dd096 | 2006-10-01 00:28:50 +0200 | [diff] [blame] | 1112 | tz = acpi_driver_data(device); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1113 | |
Zhang Rui | 3f655ef | 2008-01-17 15:51:11 +0800 | [diff] [blame] | 1114 | acpi_thermal_unregister_thermal_zone(tz); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1115 | kfree(tz); |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1116 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1117 | } |
| 1118 | |
Rafael J. Wysocki | 9069240 | 2012-08-09 23:00:02 +0200 | [diff] [blame] | 1119 | #ifdef CONFIG_PM_SLEEP |
Aaron Lu | a59ffb2 | 2014-03-04 14:24:46 +0800 | [diff] [blame] | 1120 | static int acpi_thermal_suspend(struct device *dev) |
| 1121 | { |
| 1122 | /* Make sure the previously queued thermal check work has been done */ |
| 1123 | flush_workqueue(acpi_thermal_pm_queue); |
| 1124 | return 0; |
| 1125 | } |
| 1126 | |
Rafael J. Wysocki | 167cffb | 2012-06-27 23:26:18 +0200 | [diff] [blame] | 1127 | static int acpi_thermal_resume(struct device *dev) |
Konstantin Karasyov | 74ce1468 | 2006-05-08 08:32:00 -0400 | [diff] [blame] | 1128 | { |
Rafael J. Wysocki | 167cffb | 2012-06-27 23:26:18 +0200 | [diff] [blame] | 1129 | struct acpi_thermal *tz; |
Konstantin Karasyov | b1028c5 | 2007-02-16 02:23:07 -0500 | [diff] [blame] | 1130 | int i, j, power_state, result; |
| 1131 | |
Rafael J. Wysocki | 167cffb | 2012-06-27 23:26:18 +0200 | [diff] [blame] | 1132 | if (!dev) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1133 | return -EINVAL; |
Konstantin Karasyov | 74ce1468 | 2006-05-08 08:32:00 -0400 | [diff] [blame] | 1134 | |
Rafael J. Wysocki | 167cffb | 2012-06-27 23:26:18 +0200 | [diff] [blame] | 1135 | tz = acpi_driver_data(to_acpi_device(dev)); |
| 1136 | if (!tz) |
| 1137 | return -EINVAL; |
Konstantin Karasyov | 74ce1468 | 2006-05-08 08:32:00 -0400 | [diff] [blame] | 1138 | |
Konstantin Karasyov | bed936f | 2006-07-10 04:44:26 -0700 | [diff] [blame] | 1139 | for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) { |
Konstantin Karasyov | b1028c5 | 2007-02-16 02:23:07 -0500 | [diff] [blame] | 1140 | if (!(&tz->trips.active[i])) |
| 1141 | break; |
| 1142 | if (!tz->trips.active[i].flags.valid) |
| 1143 | break; |
| 1144 | tz->trips.active[i].flags.enabled = 1; |
| 1145 | for (j = 0; j < tz->trips.active[i].devices.count; j++) { |
Rafael J. Wysocki | 488a76c | 2010-11-25 00:11:24 +0100 | [diff] [blame] | 1146 | result = acpi_bus_update_power( |
| 1147 | tz->trips.active[i].devices.handles[j], |
| 1148 | &power_state); |
Konstantin Karasyov | b1028c5 | 2007-02-16 02:23:07 -0500 | [diff] [blame] | 1149 | if (result || (power_state != ACPI_STATE_D0)) { |
| 1150 | tz->trips.active[i].flags.enabled = 0; |
| 1151 | break; |
| 1152 | } |
Konstantin Karasyov | bed936f | 2006-07-10 04:44:26 -0700 | [diff] [blame] | 1153 | } |
Konstantin Karasyov | b1028c5 | 2007-02-16 02:23:07 -0500 | [diff] [blame] | 1154 | tz->state.active |= tz->trips.active[i].flags.enabled; |
Konstantin Karasyov | bed936f | 2006-07-10 04:44:26 -0700 | [diff] [blame] | 1155 | } |
| 1156 | |
Aaron Lu | a59ffb2 | 2014-03-04 14:24:46 +0800 | [diff] [blame] | 1157 | queue_work(acpi_thermal_pm_queue, &tz->thermal_check_work); |
Konstantin Karasyov | 74ce1468 | 2006-05-08 08:32:00 -0400 | [diff] [blame] | 1158 | |
| 1159 | return AE_OK; |
| 1160 | } |
Rafael J. Wysocki | 9069240 | 2012-08-09 23:00:02 +0200 | [diff] [blame] | 1161 | #endif |
Konstantin Karasyov | 74ce1468 | 2006-05-08 08:32:00 -0400 | [diff] [blame] | 1162 | |
Jeff Garzik | 1855256 | 2007-10-03 15:15:40 -0400 | [diff] [blame] | 1163 | static int thermal_act(const struct dmi_system_id *d) { |
Len Brown | 0b5bfa1 | 2007-08-12 00:13:02 -0400 | [diff] [blame] | 1164 | |
| 1165 | if (act == 0) { |
Andy Shevchenko | 766a8a6 | 2013-09-13 18:15:46 +0300 | [diff] [blame] | 1166 | pr_notice(PREFIX "%s detected: " |
| 1167 | "disabling all active thermal trip points\n", d->ident); |
Len Brown | 0b5bfa1 | 2007-08-12 00:13:02 -0400 | [diff] [blame] | 1168 | act = -1; |
| 1169 | } |
| 1170 | return 0; |
| 1171 | } |
Jeff Garzik | 1855256 | 2007-10-03 15:15:40 -0400 | [diff] [blame] | 1172 | static int thermal_nocrt(const struct dmi_system_id *d) { |
Len Brown | 8c99fdc | 2007-08-20 18:46:50 -0400 | [diff] [blame] | 1173 | |
Andy Shevchenko | 766a8a6 | 2013-09-13 18:15:46 +0300 | [diff] [blame] | 1174 | pr_notice(PREFIX "%s detected: " |
| 1175 | "disabling all critical thermal trip point actions.\n", d->ident); |
Len Brown | 8c99fdc | 2007-08-20 18:46:50 -0400 | [diff] [blame] | 1176 | nocrt = 1; |
| 1177 | return 0; |
| 1178 | } |
Jeff Garzik | 1855256 | 2007-10-03 15:15:40 -0400 | [diff] [blame] | 1179 | static int thermal_tzp(const struct dmi_system_id *d) { |
Len Brown | 0b5bfa1 | 2007-08-12 00:13:02 -0400 | [diff] [blame] | 1180 | |
| 1181 | if (tzp == 0) { |
Andy Shevchenko | 766a8a6 | 2013-09-13 18:15:46 +0300 | [diff] [blame] | 1182 | pr_notice(PREFIX "%s detected: " |
| 1183 | "enabling thermal zone polling\n", d->ident); |
Len Brown | 0b5bfa1 | 2007-08-12 00:13:02 -0400 | [diff] [blame] | 1184 | tzp = 300; /* 300 dS = 30 Seconds */ |
| 1185 | } |
| 1186 | return 0; |
| 1187 | } |
Jeff Garzik | 1855256 | 2007-10-03 15:15:40 -0400 | [diff] [blame] | 1188 | static int thermal_psv(const struct dmi_system_id *d) { |
Len Brown | 0b5bfa1 | 2007-08-12 00:13:02 -0400 | [diff] [blame] | 1189 | |
| 1190 | if (psv == 0) { |
Andy Shevchenko | 766a8a6 | 2013-09-13 18:15:46 +0300 | [diff] [blame] | 1191 | pr_notice(PREFIX "%s detected: " |
| 1192 | "disabling all passive thermal trip points\n", d->ident); |
Len Brown | 0b5bfa1 | 2007-08-12 00:13:02 -0400 | [diff] [blame] | 1193 | psv = -1; |
| 1194 | } |
| 1195 | return 0; |
| 1196 | } |
| 1197 | |
Christoph Hellwig | 6faadbb | 2017-09-14 11:59:30 +0200 | [diff] [blame] | 1198 | static const struct dmi_system_id thermal_dmi_table[] __initconst = { |
Len Brown | 0b5bfa1 | 2007-08-12 00:13:02 -0400 | [diff] [blame] | 1199 | /* |
| 1200 | * Award BIOS on this AOpen makes thermal control almost worthless. |
| 1201 | * http://bugzilla.kernel.org/show_bug.cgi?id=8842 |
| 1202 | */ |
| 1203 | { |
| 1204 | .callback = thermal_act, |
| 1205 | .ident = "AOpen i915GMm-HFS", |
| 1206 | .matches = { |
| 1207 | DMI_MATCH(DMI_BOARD_VENDOR, "AOpen"), |
| 1208 | DMI_MATCH(DMI_BOARD_NAME, "i915GMm-HFS"), |
| 1209 | }, |
| 1210 | }, |
| 1211 | { |
| 1212 | .callback = thermal_psv, |
| 1213 | .ident = "AOpen i915GMm-HFS", |
| 1214 | .matches = { |
| 1215 | DMI_MATCH(DMI_BOARD_VENDOR, "AOpen"), |
| 1216 | DMI_MATCH(DMI_BOARD_NAME, "i915GMm-HFS"), |
| 1217 | }, |
| 1218 | }, |
| 1219 | { |
| 1220 | .callback = thermal_tzp, |
| 1221 | .ident = "AOpen i915GMm-HFS", |
| 1222 | .matches = { |
| 1223 | DMI_MATCH(DMI_BOARD_VENDOR, "AOpen"), |
| 1224 | DMI_MATCH(DMI_BOARD_NAME, "i915GMm-HFS"), |
| 1225 | }, |
| 1226 | }, |
Len Brown | 8c99fdc | 2007-08-20 18:46:50 -0400 | [diff] [blame] | 1227 | { |
| 1228 | .callback = thermal_nocrt, |
| 1229 | .ident = "Gigabyte GA-7ZX", |
| 1230 | .matches = { |
| 1231 | DMI_MATCH(DMI_BOARD_VENDOR, "Gigabyte Technology Co., Ltd."), |
| 1232 | DMI_MATCH(DMI_BOARD_NAME, "7ZX"), |
| 1233 | }, |
| 1234 | }, |
Len Brown | 0b5bfa1 | 2007-08-12 00:13:02 -0400 | [diff] [blame] | 1235 | {} |
| 1236 | }; |
Len Brown | 0b5bfa1 | 2007-08-12 00:13:02 -0400 | [diff] [blame] | 1237 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1238 | static int __init acpi_thermal_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1239 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1240 | int result = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1241 | |
Len Brown | 0b5bfa1 | 2007-08-12 00:13:02 -0400 | [diff] [blame] | 1242 | dmi_check_system(thermal_dmi_table); |
| 1243 | |
Len Brown | 72b33ef | 2007-08-12 00:12:17 -0400 | [diff] [blame] | 1244 | if (off) { |
Andy Shevchenko | 766a8a6 | 2013-09-13 18:15:46 +0300 | [diff] [blame] | 1245 | pr_notice(PREFIX "thermal control disabled\n"); |
Len Brown | 72b33ef | 2007-08-12 00:12:17 -0400 | [diff] [blame] | 1246 | return -ENODEV; |
| 1247 | } |
Zhang Rui | 43d9f87 | 2010-07-15 10:46:44 +0800 | [diff] [blame] | 1248 | |
Bhaktipriya Shridhar | e053dc9 | 2016-06-07 08:45:40 +0530 | [diff] [blame] | 1249 | acpi_thermal_pm_queue = alloc_workqueue("acpi_thermal_pm", |
| 1250 | WQ_HIGHPRI | WQ_MEM_RECLAIM, 0); |
Aaron Lu | a59ffb2 | 2014-03-04 14:24:46 +0800 | [diff] [blame] | 1251 | if (!acpi_thermal_pm_queue) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1252 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1253 | |
Aaron Lu | a59ffb2 | 2014-03-04 14:24:46 +0800 | [diff] [blame] | 1254 | result = acpi_bus_register_driver(&acpi_thermal_driver); |
| 1255 | if (result < 0) { |
| 1256 | destroy_workqueue(acpi_thermal_pm_queue); |
| 1257 | return -ENODEV; |
| 1258 | } |
| 1259 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1260 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1261 | } |
| 1262 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1263 | static void __exit acpi_thermal_exit(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1264 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1265 | acpi_bus_unregister_driver(&acpi_thermal_driver); |
Aaron Lu | 2807bd1 | 2014-05-26 14:34:07 +0200 | [diff] [blame] | 1266 | destroy_workqueue(acpi_thermal_pm_queue); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1267 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1268 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1269 | } |
| 1270 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1271 | module_init(acpi_thermal_init); |
| 1272 | module_exit(acpi_thermal_exit); |