hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/drivers/acpi/thermal.c
....@@ -1,22 +1,9 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 * acpi_thermal.c - ACPI Thermal Zone Driver ($Revision: 41 $)
34 *
45 * Copyright (C) 2001, 2002 Andy Grover <andrew.grover@intel.com>
56 * Copyright (C) 2001, 2002 Paul Diefenbaugh <paul.s.diefenbaugh@intel.com>
6
- *
7
- * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
8
- *
9
- * This program is free software; you can redistribute it and/or modify
10
- * it under the terms of the GNU General Public License as published by
11
- * the Free Software Foundation; either version 2 of the License, or (at
12
- * your option) any later version.
13
- *
14
- * This program is distributed in the hope that it will be useful, but
15
- * WITHOUT ANY WARRANTY; without even the implied warranty of
16
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17
- * General Public License for more details.
18
- *
19
- * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
207 *
218 * This driver fully implements the ACPI thermal policy as described in the
229 * ACPI 2.0 Specification.
....@@ -24,7 +11,6 @@
2411 * TBD: 1. Implement passive cooling hysteresis.
2512 * 2. Enhance passive cooling (CPU) states/limit interface to support
2613 * concepts of 'multiple limiters', upper/lower limits, etc.
27
- *
2814 */
2915
3016 #include <linux/kernel.h>
....@@ -41,6 +27,7 @@
4127 #include <linux/acpi.h>
4228 #include <linux/workqueue.h>
4329 #include <linux/uaccess.h>
30
+#include <linux/units.h>
4431
4532 #define PREFIX "ACPI: "
4633
....@@ -185,8 +172,7 @@
185172 struct acpi_thermal_trips trips;
186173 struct acpi_handle_list devices;
187174 struct thermal_zone_device *thermal_zone;
188
- int tz_enabled;
189
- int kelvin_offset;
175
+ int kelvin_offset; /* in millidegrees */
190176 struct work_struct thermal_check_work;
191177 struct mutex thermal_check_lock;
192178 refcount_t thermal_check_count;
....@@ -241,13 +227,9 @@
241227 if (!tz)
242228 return -EINVAL;
243229
244
- if (!acpi_has_method(tz->device->handle, "_SCP")) {
245
- ACPI_DEBUG_PRINT((ACPI_DB_INFO, "_SCP not present\n"));
230
+ if (ACPI_FAILURE(acpi_execute_simple_method(tz->device->handle,
231
+ "_SCP", mode)))
246232 return -ENODEV;
247
- } else if (ACPI_FAILURE(acpi_execute_simple_method(tz->device->handle,
248
- "_SCP", mode))) {
249
- return -ENODEV;
250
- }
251233
252234 return 0;
253235 }
....@@ -317,7 +299,8 @@
317299 if (crt == -1) {
318300 tz->trips.critical.flags.valid = 0;
319301 } else if (crt > 0) {
320
- unsigned long crt_k = CELSIUS_TO_DECI_KELVIN(crt);
302
+ unsigned long crt_k = celsius_to_deci_kelvin(crt);
303
+
321304 /*
322305 * Allow override critical threshold
323306 */
....@@ -353,7 +336,7 @@
353336 if (psv == -1) {
354337 status = AE_SUPPORT;
355338 } else if (psv > 0) {
356
- tmp = CELSIUS_TO_DECI_KELVIN(psv);
339
+ tmp = celsius_to_deci_kelvin(psv);
357340 status = AE_OK;
358341 } else {
359342 status = acpi_evaluate_integer(tz->device->handle,
....@@ -433,7 +416,7 @@
433416 break;
434417 if (i == 1)
435418 tz->trips.active[0].temperature =
436
- CELSIUS_TO_DECI_KELVIN(act);
419
+ celsius_to_deci_kelvin(act);
437420 else
438421 /*
439422 * Don't allow override higher than
....@@ -441,9 +424,9 @@
441424 */
442425 tz->trips.active[i - 1].temperature =
443426 (tz->trips.active[i - 2].temperature <
444
- CELSIUS_TO_DECI_KELVIN(act) ?
427
+ celsius_to_deci_kelvin(act) ?
445428 tz->trips.active[i - 2].temperature :
446
- CELSIUS_TO_DECI_KELVIN(act));
429
+ celsius_to_deci_kelvin(act));
447430 break;
448431 } else {
449432 tz->trips.active[i].temperature = tmp;
....@@ -479,8 +462,7 @@
479462 break;
480463 }
481464
482
- if ((flag & ACPI_TRIPS_DEVICES)
483
- && acpi_has_method(tz->device->handle, "_TZD")) {
465
+ if (flag & ACPI_TRIPS_DEVICES) {
484466 memset(&devices, 0, sizeof(devices));
485467 status = acpi_evaluate_reference(tz->device->handle, "_TZD",
486468 NULL, &devices);
....@@ -529,54 +511,8 @@
529511 if (result)
530512 return result;
531513
532
- *temp = DECI_KELVIN_TO_MILLICELSIUS_WITH_OFFSET(tz->temperature,
514
+ *temp = deci_kelvin_to_millicelsius_with_offset(tz->temperature,
533515 tz->kelvin_offset);
534
- return 0;
535
-}
536
-
537
-static int thermal_get_mode(struct thermal_zone_device *thermal,
538
- enum thermal_device_mode *mode)
539
-{
540
- struct acpi_thermal *tz = thermal->devdata;
541
-
542
- if (!tz)
543
- return -EINVAL;
544
-
545
- *mode = tz->tz_enabled ? THERMAL_DEVICE_ENABLED :
546
- THERMAL_DEVICE_DISABLED;
547
-
548
- return 0;
549
-}
550
-
551
-static void acpi_thermal_check_fn(struct work_struct *work);
552
-
553
-static int thermal_set_mode(struct thermal_zone_device *thermal,
554
- enum thermal_device_mode mode)
555
-{
556
- struct acpi_thermal *tz = thermal->devdata;
557
- int enable;
558
-
559
- if (!tz)
560
- return -EINVAL;
561
-
562
- /*
563
- * enable/disable thermal management from ACPI thermal driver
564
- */
565
- if (mode == THERMAL_DEVICE_ENABLED)
566
- enable = 1;
567
- else if (mode == THERMAL_DEVICE_DISABLED) {
568
- enable = 0;
569
- pr_warn("thermal zone will be disabled\n");
570
- } else
571
- return -EINVAL;
572
-
573
- if (enable != tz->tz_enabled) {
574
- tz->tz_enabled = enable;
575
- ACPI_DEBUG_PRINT((ACPI_DB_INFO,
576
- "%s kernel ACPI thermal control\n",
577
- tz->tz_enabled ? "Enable" : "Disable"));
578
- acpi_thermal_check_fn(&tz->thermal_check_work);
579
- }
580516 return 0;
581517 }
582518
....@@ -636,7 +572,7 @@
636572
637573 if (tz->trips.critical.flags.valid) {
638574 if (!trip) {
639
- *temp = DECI_KELVIN_TO_MILLICELSIUS_WITH_OFFSET(
575
+ *temp = deci_kelvin_to_millicelsius_with_offset(
640576 tz->trips.critical.temperature,
641577 tz->kelvin_offset);
642578 return 0;
....@@ -646,7 +582,7 @@
646582
647583 if (tz->trips.hot.flags.valid) {
648584 if (!trip) {
649
- *temp = DECI_KELVIN_TO_MILLICELSIUS_WITH_OFFSET(
585
+ *temp = deci_kelvin_to_millicelsius_with_offset(
650586 tz->trips.hot.temperature,
651587 tz->kelvin_offset);
652588 return 0;
....@@ -656,7 +592,7 @@
656592
657593 if (tz->trips.passive.flags.valid) {
658594 if (!trip) {
659
- *temp = DECI_KELVIN_TO_MILLICELSIUS_WITH_OFFSET(
595
+ *temp = deci_kelvin_to_millicelsius_with_offset(
660596 tz->trips.passive.temperature,
661597 tz->kelvin_offset);
662598 return 0;
....@@ -667,7 +603,7 @@
667603 for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE &&
668604 tz->trips.active[i].flags.valid; i++) {
669605 if (!trip) {
670
- *temp = DECI_KELVIN_TO_MILLICELSIUS_WITH_OFFSET(
606
+ *temp = deci_kelvin_to_millicelsius_with_offset(
671607 tz->trips.active[i].temperature,
672608 tz->kelvin_offset);
673609 return 0;
....@@ -684,7 +620,7 @@
684620 struct acpi_thermal *tz = thermal->devdata;
685621
686622 if (tz->trips.critical.flags.valid) {
687
- *temperature = DECI_KELVIN_TO_MILLICELSIUS_WITH_OFFSET(
623
+ *temperature = deci_kelvin_to_millicelsius_with_offset(
688624 tz->trips.critical.temperature,
689625 tz->kelvin_offset);
690626 return 0;
....@@ -704,7 +640,7 @@
704640
705641 if (type == THERMAL_TRIP_ACTIVE) {
706642 int trip_temp;
707
- int temp = DECI_KELVIN_TO_MILLICELSIUS_WITH_OFFSET(
643
+ int temp = deci_kelvin_to_millicelsius_with_offset(
708644 tz->temperature, tz->kelvin_offset);
709645 if (thermal_get_trip_temp(thermal, trip, &trip_temp))
710646 return -EINVAL;
....@@ -866,8 +802,6 @@
866802 .bind = acpi_thermal_bind_cooling_device,
867803 .unbind = acpi_thermal_unbind_cooling_device,
868804 .get_temp = thermal_get_temp,
869
- .get_mode = thermal_get_mode,
870
- .set_mode = thermal_set_mode,
871805 .get_trip_type = thermal_get_trip_type,
872806 .get_trip_temp = thermal_get_trip_temp,
873807 .get_crit_temp = thermal_get_crit_temp,
....@@ -911,23 +845,39 @@
911845 result = sysfs_create_link(&tz->device->dev.kobj,
912846 &tz->thermal_zone->device.kobj, "thermal_zone");
913847 if (result)
914
- return result;
848
+ goto unregister_tzd;
915849
916850 result = sysfs_create_link(&tz->thermal_zone->device.kobj,
917851 &tz->device->dev.kobj, "device");
918852 if (result)
919
- return result;
853
+ goto remove_tz_link;
920854
921855 status = acpi_bus_attach_private_data(tz->device->handle,
922856 tz->thermal_zone);
923
- if (ACPI_FAILURE(status))
924
- return -ENODEV;
857
+ if (ACPI_FAILURE(status)) {
858
+ result = -ENODEV;
859
+ goto remove_dev_link;
860
+ }
925861
926
- tz->tz_enabled = 1;
862
+ result = thermal_zone_device_enable(tz->thermal_zone);
863
+ if (result)
864
+ goto acpi_bus_detach;
927865
928866 dev_info(&tz->device->dev, "registered as thermal_zone%d\n",
929867 tz->thermal_zone->id);
868
+
930869 return 0;
870
+
871
+acpi_bus_detach:
872
+ acpi_bus_detach_private_data(tz->device->handle);
873
+remove_dev_link:
874
+ sysfs_remove_link(&tz->thermal_zone->device.kobj, "device");
875
+remove_tz_link:
876
+ sysfs_remove_link(&tz->device->dev.kobj, "thermal_zone");
877
+unregister_tzd:
878
+ thermal_zone_device_unregister(tz->thermal_zone);
879
+
880
+ return result;
931881 }
932882
933883 static void acpi_thermal_unregister_thermal_zone(struct acpi_thermal *tz)
....@@ -1061,9 +1011,9 @@
10611011 {
10621012 if (tz->trips.critical.flags.valid &&
10631013 (tz->trips.critical.temperature % 5) == 1)
1064
- tz->kelvin_offset = 2731;
1014
+ tz->kelvin_offset = 273100;
10651015 else
1066
- tz->kelvin_offset = 2732;
1016
+ tz->kelvin_offset = 273200;
10671017 }
10681018
10691019 static void acpi_thermal_check_fn(struct work_struct *work)
....@@ -1071,8 +1021,6 @@
10711021 struct acpi_thermal *tz = container_of(work, struct acpi_thermal,
10721022 thermal_check_work);
10731023
1074
- if (!tz->tz_enabled)
1075
- return;
10761024 /*
10771025 * In general, it is not sufficient to check the pending bit, because
10781026 * subsequent instances of this function may be queued after one of them
....@@ -1127,7 +1075,7 @@
11271075 INIT_WORK(&tz->thermal_check_work, acpi_thermal_check_fn);
11281076
11291077 pr_info(PREFIX "%s [%s] (%ld C)\n", acpi_device_name(device),
1130
- acpi_device_bid(device), DECI_KELVIN_TO_CELSIUS(tz->temperature));
1078
+ acpi_device_bid(device), deci_kelvin_to_celsius(tz->temperature));
11311079 goto end;
11321080
11331081 free_memory:
....@@ -1172,8 +1120,6 @@
11721120 return -EINVAL;
11731121
11741122 for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) {
1175
- if (!(&tz->trips.active[i]))
1176
- break;
11771123 if (!tz->trips.active[i].flags.valid)
11781124 break;
11791125 tz->trips.active[i].flags.enabled = 1;