Skip to content

Commit 259f7d5

Browse files
committed
Merge tag 'thermal-6.9-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm
Pull thermal control updates from Rafael Wysocki: "These mostly change the thermal core in a few ways allowing thermal drivers to be simplified, in particular in their removal and failing probe handling parts that are notoriously prone to errors, and propagate the changes to several drivers. Apart from that, support for a new platform is added (Intel Lunar Lake-M), some bugs are fixed and some code is cleaned up, as usual. Specifics: - Store zone trips table and zone operations directly in struct thermal_zone_device (Rafael Wysocki) - Fix up flex array initialization during thermal zone device registration (Nathan Chancellor) - Rework writable trip points handling in the thermal core and several drivers (Rafael Wysocki) - Thermal core code cleanups (Dan Carpenter, Flavio Suligoi) - Use thermal zone accessor functions in the int340x Intel thermal driver (Rafael Wysocki) - Add Lunar Lake-M PCI ID to the int340x Intel thermal driver (Srinivas Pandruvada) - Minor fixes for thermal governors (Rafael Wysocki, Di Shen) - Trip point handling fixes for the iwlwifi wireless driver (Rafael Wysocki) - Code cleanups (Rafael J. Wysocki, AngeloGioacchino Del Regno)" * tag 'thermal-6.9-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm: (29 commits) thermal: core: remove unnecessary check in trip_point_hyst_store() thermal: intel: int340x_thermal: Use thermal zone accessor functions thermal: core: Remove excess empty line from a comment thermal: int340x: processor_thermal: Add Lunar Lake-M PCI ID thermal: core: Eliminate writable trip points masks thermal: of: Set THERMAL_TRIP_FLAG_RW_TEMP directly thermal: imx: Set THERMAL_TRIP_FLAG_RW_TEMP directly wifi: iwlwifi: mvm: Set THERMAL_TRIP_FLAG_RW_TEMP directly mlxsw: core_thermal: Set THERMAL_TRIP_FLAG_RW_TEMP directly thermal: intel: Set THERMAL_TRIP_FLAG_RW_TEMP directly thermal: core: Drop the .set_trip_hyst() thermal zone operation thermal: core: Add flags to struct thermal_trip thermal: core: Move initial num_trips assignment before memcpy() thermal: Get rid of CONFIG_THERMAL_WRITABLE_TRIPS thermal: intel: Adjust ops handling during thermal zone registration thermal: ACPI: Constify acpi_thermal_zone_ops thermal: core: Store zone ops in struct thermal_zone_device thermal: intel: Discard trip tables after zone registration thermal: ACPI: Discard trips table after zone registration thermal: core: Store zone trips table in struct thermal_zone_device ...
2 parents 9434467 + dcb497e commit 259f7d5

36 files changed

+282
-395
lines changed

arch/arm/configs/imx_v6_v7_defconfig

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,6 @@ CONFIG_SENSORS_IIO_HWMON=y
229229
CONFIG_SENSORS_PWM_FAN=y
230230
CONFIG_SENSORS_SY7636A=y
231231
CONFIG_THERMAL_STATISTICS=y
232-
CONFIG_THERMAL_WRITABLE_TRIPS=y
233232
CONFIG_CPU_THERMAL=y
234233
CONFIG_IMX_THERMAL=y
235234
CONFIG_WATCHDOG=y

drivers/acpi/thermal.c

Lines changed: 22 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@
4747

4848
#define ACPI_THERMAL_TRIP_PASSIVE (-1)
4949

50+
#define ACPI_THERMAL_MAX_NR_TRIPS (ACPI_THERMAL_MAX_ACTIVE + 3)
51+
5052
/*
5153
* This exception is thrown out in two cases:
5254
* 1.An invalid trip point becomes invalid or a valid trip point becomes invalid
@@ -112,7 +114,6 @@ struct acpi_thermal {
112114
unsigned long polling_frequency;
113115
volatile u8 zombie;
114116
struct acpi_thermal_trips trips;
115-
struct thermal_trip *trip_table;
116117
struct thermal_zone_device *thermal_zone;
117118
int kelvin_offset; /* in millidegrees */
118119
struct work_struct thermal_check_work;
@@ -451,26 +452,19 @@ static bool acpi_thermal_init_trip(struct acpi_thermal *tz, int index)
451452
return false;
452453
}
453454

454-
static int acpi_thermal_get_trip_points(struct acpi_thermal *tz)
455+
static void acpi_thermal_get_trip_points(struct acpi_thermal *tz)
455456
{
456-
unsigned int count = 0;
457457
int i;
458458

459-
if (acpi_thermal_init_trip(tz, ACPI_THERMAL_TRIP_PASSIVE))
460-
count++;
459+
acpi_thermal_init_trip(tz, ACPI_THERMAL_TRIP_PASSIVE);
461460

462461
for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) {
463-
if (acpi_thermal_init_trip(tz, i))
464-
count++;
465-
else
462+
if (!acpi_thermal_init_trip(tz, i))
466463
break;
467-
468464
}
469465

470466
while (++i < ACPI_THERMAL_MAX_ACTIVE)
471467
tz->trips.active[i].trip.temp_dk = THERMAL_TEMP_INVALID;
472-
473-
return count;
474468
}
475469

476470
/* sys I/F for generic thermal sysfs support */
@@ -626,7 +620,7 @@ acpi_thermal_unbind_cooling_device(struct thermal_zone_device *thermal,
626620
return acpi_thermal_bind_unbind_cdev(thermal, cdev, false);
627621
}
628622

629-
static struct thermal_zone_device_ops acpi_thermal_zone_ops = {
623+
static const struct thermal_zone_device_ops acpi_thermal_zone_ops = {
630624
.bind = acpi_thermal_bind_cooling_device,
631625
.unbind = acpi_thermal_unbind_cooling_device,
632626
.get_temp = thermal_get_temp,
@@ -662,15 +656,16 @@ static void acpi_thermal_zone_sysfs_remove(struct acpi_thermal *tz)
662656
}
663657

664658
static int acpi_thermal_register_thermal_zone(struct acpi_thermal *tz,
659+
const struct thermal_trip *trip_table,
665660
unsigned int trip_count,
666661
int passive_delay)
667662
{
668663
int result;
669664

670665
tz->thermal_zone = thermal_zone_device_register_with_trips("acpitz",
671-
tz->trip_table,
666+
trip_table,
672667
trip_count,
673-
0, tz,
668+
tz,
674669
&acpi_thermal_zone_ops,
675670
NULL,
676671
passive_delay,
@@ -823,10 +818,10 @@ static void acpi_thermal_free_thermal_zone(struct acpi_thermal *tz)
823818

824819
static int acpi_thermal_add(struct acpi_device *device)
825820
{
821+
struct thermal_trip trip_table[ACPI_THERMAL_MAX_NR_TRIPS] = { 0 };
826822
struct acpi_thermal_trip *acpi_trip;
827823
struct thermal_trip *trip;
828824
struct acpi_thermal *tz;
829-
unsigned int trip_count;
830825
int crit_temp, hot_temp;
831826
int passive_delay = 0;
832827
int result;
@@ -848,21 +843,10 @@ static int acpi_thermal_add(struct acpi_device *device)
848843
acpi_thermal_aml_dependency_fix(tz);
849844

850845
/* Get trip points [_CRT, _PSV, etc.] (required). */
851-
trip_count = acpi_thermal_get_trip_points(tz);
846+
acpi_thermal_get_trip_points(tz);
852847

853848
crit_temp = acpi_thermal_get_critical_trip(tz);
854-
if (crit_temp != THERMAL_TEMP_INVALID)
855-
trip_count++;
856-
857849
hot_temp = acpi_thermal_get_hot_trip(tz);
858-
if (hot_temp != THERMAL_TEMP_INVALID)
859-
trip_count++;
860-
861-
if (!trip_count) {
862-
pr_warn(FW_BUG "No valid trip points!\n");
863-
result = -ENODEV;
864-
goto free_memory;
865-
}
866850

867851
/* Get temperature [_TMP] (required). */
868852
result = acpi_thermal_get_temperature(tz);
@@ -881,13 +865,7 @@ static int acpi_thermal_add(struct acpi_device *device)
881865

882866
acpi_thermal_guess_offset(tz, crit_temp);
883867

884-
trip = kcalloc(trip_count, sizeof(*trip), GFP_KERNEL);
885-
if (!trip) {
886-
result = -ENOMEM;
887-
goto free_memory;
888-
}
889-
890-
tz->trip_table = trip;
868+
trip = trip_table;
891869

892870
if (crit_temp != THERMAL_TEMP_INVALID) {
893871
trip->type = THERMAL_TRIP_CRITICAL;
@@ -923,9 +901,17 @@ static int acpi_thermal_add(struct acpi_device *device)
923901
trip++;
924902
}
925903

926-
result = acpi_thermal_register_thermal_zone(tz, trip_count, passive_delay);
904+
if (trip == trip_table) {
905+
pr_warn(FW_BUG "No valid trip points!\n");
906+
result = -ENODEV;
907+
goto free_memory;
908+
}
909+
910+
result = acpi_thermal_register_thermal_zone(tz, trip_table,
911+
trip - trip_table,
912+
passive_delay);
927913
if (result)
928-
goto free_trips;
914+
goto free_memory;
929915

930916
refcount_set(&tz->thermal_check_count, 3);
931917
mutex_init(&tz->thermal_check_lock);
@@ -944,8 +930,6 @@ static int acpi_thermal_add(struct acpi_device *device)
944930
flush_wq:
945931
flush_workqueue(acpi_thermal_pm_queue);
946932
acpi_thermal_unregister_thermal_zone(tz);
947-
free_trips:
948-
kfree(tz->trip_table);
949933
free_memory:
950934
acpi_thermal_free_thermal_zone(tz);
951935

@@ -966,7 +950,6 @@ static void acpi_thermal_remove(struct acpi_device *device)
966950

967951
flush_workqueue(acpi_thermal_pm_queue);
968952
acpi_thermal_unregister_thermal_zone(tz);
969-
kfree(tz->trip_table);
970953
acpi_thermal_free_thermal_zone(tz);
971954
}
972955

drivers/net/ethernet/chelsio/cxgb4/cxgb4_thermal.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ int cxgb4_thermal_init(struct adapter *adap)
6060

6161
snprintf(ch_tz_name, sizeof(ch_tz_name), "cxgb4_%s", adap->name);
6262
ch_thermal->tzdev = thermal_zone_device_register_with_trips(ch_tz_name, &trip, num_trip,
63-
0, adap,
63+
adap,
6464
&cxgb4_thermal_ops,
6565
NULL, 0, 0);
6666
if (IS_ERR(ch_thermal->tzdev)) {

drivers/net/ethernet/mellanox/mlxsw/core_thermal.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,16 +44,19 @@ static const struct thermal_trip default_thermal_trips[] = {
4444
.type = THERMAL_TRIP_ACTIVE,
4545
.temperature = MLXSW_THERMAL_ASIC_TEMP_NORM,
4646
.hysteresis = MLXSW_THERMAL_HYSTERESIS_TEMP,
47+
.flags = THERMAL_TRIP_FLAG_RW_TEMP,
4748
},
4849
{
4950
/* In range - 40-100% PWM */
5051
.type = THERMAL_TRIP_ACTIVE,
5152
.temperature = MLXSW_THERMAL_ASIC_TEMP_HIGH,
5253
.hysteresis = MLXSW_THERMAL_HYSTERESIS_TEMP,
54+
.flags = THERMAL_TRIP_FLAG_RW_TEMP,
5355
},
5456
{ /* Warning */
5557
.type = THERMAL_TRIP_HOT,
5658
.temperature = MLXSW_THERMAL_ASIC_TEMP_HOT,
59+
.flags = THERMAL_TRIP_FLAG_RW_TEMP,
5760
},
5861
};
5962

@@ -62,16 +65,19 @@ static const struct thermal_trip default_thermal_module_trips[] = {
6265
.type = THERMAL_TRIP_ACTIVE,
6366
.temperature = MLXSW_THERMAL_MODULE_TEMP_NORM,
6467
.hysteresis = MLXSW_THERMAL_HYSTERESIS_TEMP,
68+
.flags = THERMAL_TRIP_FLAG_RW_TEMP,
6569
},
6670
{
6771
/* In range - 40-100% PWM */
6872
.type = THERMAL_TRIP_ACTIVE,
6973
.temperature = MLXSW_THERMAL_MODULE_TEMP_HIGH,
7074
.hysteresis = MLXSW_THERMAL_HYSTERESIS_TEMP,
75+
.flags = THERMAL_TRIP_FLAG_RW_TEMP,
7176
},
7277
{ /* Warning */
7378
.type = THERMAL_TRIP_HOT,
7479
.temperature = MLXSW_THERMAL_MODULE_TEMP_HOT,
80+
.flags = THERMAL_TRIP_FLAG_RW_TEMP,
7581
},
7682
};
7783

@@ -92,9 +98,6 @@ static const struct mlxsw_cooling_states default_cooling_states[] = {
9298

9399
#define MLXSW_THERMAL_NUM_TRIPS ARRAY_SIZE(default_thermal_trips)
94100

95-
/* Make sure all trips are writable */
96-
#define MLXSW_THERMAL_TRIP_MASK (BIT(MLXSW_THERMAL_NUM_TRIPS) - 1)
97-
98101
struct mlxsw_thermal;
99102

100103
struct mlxsw_thermal_module {
@@ -420,7 +423,6 @@ mlxsw_thermal_module_tz_init(struct mlxsw_thermal_module *module_tz)
420423
module_tz->tzdev = thermal_zone_device_register_with_trips(tz_name,
421424
module_tz->trips,
422425
MLXSW_THERMAL_NUM_TRIPS,
423-
MLXSW_THERMAL_TRIP_MASK,
424426
module_tz,
425427
&mlxsw_thermal_module_ops,
426428
&mlxsw_thermal_params,
@@ -548,7 +550,6 @@ mlxsw_thermal_gearbox_tz_init(struct mlxsw_thermal_module *gearbox_tz)
548550
gearbox_tz->tzdev = thermal_zone_device_register_with_trips(tz_name,
549551
gearbox_tz->trips,
550552
MLXSW_THERMAL_NUM_TRIPS,
551-
MLXSW_THERMAL_TRIP_MASK,
552553
gearbox_tz,
553554
&mlxsw_thermal_gearbox_ops,
554555
&mlxsw_thermal_params, 0,
@@ -773,7 +774,6 @@ int mlxsw_thermal_init(struct mlxsw_core *core,
773774
thermal->tzdev = thermal_zone_device_register_with_trips("mlxsw",
774775
thermal->trips,
775776
MLXSW_THERMAL_NUM_TRIPS,
776-
MLXSW_THERMAL_TRIP_MASK,
777777
thermal,
778778
&mlxsw_thermal_ops,
779779
&mlxsw_thermal_params, 0,

drivers/net/wireless/intel/iwlwifi/mvm/mvm.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -543,12 +543,10 @@ struct iwl_mvm_tt_mgmt {
543543
/**
544544
* struct iwl_mvm_thermal_device - thermal zone related data
545545
* @trips: temperature thresholds for report
546-
* @fw_trips_index: keep indexes to original array - temp_trips
547546
* @tzone: thermal zone device data
548547
*/
549548
struct iwl_mvm_thermal_device {
550549
struct thermal_trip trips[IWL_MAX_DTS_TRIPS];
551-
u8 fw_trips_index[IWL_MAX_DTS_TRIPS];
552550
struct thermal_zone_device *tzone;
553551
};
554552

drivers/net/wireless/intel/iwlwifi/mvm/tt.c

Lines changed: 34 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -555,49 +555,48 @@ static int compare_temps(const void *a, const void *b)
555555
return ((s16)le16_to_cpu(*(__le16 *)a) -
556556
(s16)le16_to_cpu(*(__le16 *)b));
557557
}
558+
559+
struct iwl_trip_walk_data {
560+
__le16 *thresholds;
561+
int count;
562+
};
563+
564+
static int iwl_trip_temp_cb(struct thermal_trip *trip, void *arg)
565+
{
566+
struct iwl_trip_walk_data *twd = arg;
567+
568+
if (trip->temperature == THERMAL_TEMP_INVALID)
569+
return 0;
570+
571+
twd->thresholds[twd->count++] = cpu_to_le16((s16)(trip->temperature / 1000));
572+
return 0;
573+
}
558574
#endif
559575

560576
int iwl_mvm_send_temp_report_ths_cmd(struct iwl_mvm *mvm)
561577
{
562578
struct temp_report_ths_cmd cmd = {0};
563579
int ret;
564580
#ifdef CONFIG_THERMAL
565-
int i, j, idx = 0;
581+
struct iwl_trip_walk_data twd = { .thresholds = cmd.thresholds, .count = 0 };
566582

567583
lockdep_assert_held(&mvm->mutex);
568584

569585
if (!mvm->tz_device.tzone)
570586
goto send;
571587

572-
/* The driver holds array of temperature trips that are unsorted
573-
* and uncompressed, the FW should get it compressed and sorted
588+
/*
589+
* The thermal core holds an array of temperature trips that are
590+
* unsorted and uncompressed, the FW should get it compressed and
591+
* sorted.
574592
*/
575593

576594
/* compress trips to cmd array, remove uninitialized values*/
577-
for (i = 0; i < IWL_MAX_DTS_TRIPS; i++) {
578-
if (mvm->tz_device.trips[i].temperature != INT_MIN) {
579-
cmd.thresholds[idx++] =
580-
cpu_to_le16((s16)(mvm->tz_device.trips[i].temperature / 1000));
581-
}
582-
}
583-
cmd.num_temps = cpu_to_le32(idx);
584-
585-
if (!idx)
586-
goto send;
595+
for_each_thermal_trip(mvm->tz_device.tzone, iwl_trip_temp_cb, &twd);
587596

588-
/*sort cmd array*/
589-
sort(cmd.thresholds, idx, sizeof(s16), compare_temps, NULL);
590-
591-
/* we should save the indexes of trips because we sort
592-
* and compress the orginal array
593-
*/
594-
for (i = 0; i < idx; i++) {
595-
for (j = 0; j < IWL_MAX_DTS_TRIPS; j++) {
596-
if ((int)(le16_to_cpu(cmd.thresholds[i]) * 1000) ==
597-
mvm->tz_device.trips[j].temperature)
598-
mvm->tz_device.fw_trips_index[i] = j;
599-
}
600-
}
597+
cmd.num_temps = cpu_to_le32(twd.count);
598+
if (twd.count)
599+
sort(cmd.thresholds, twd.count, sizeof(s16), compare_temps, NULL);
601600

602601
send:
603602
#endif
@@ -668,9 +667,6 @@ static struct thermal_zone_device_ops tzone_ops = {
668667
.set_trip_temp = iwl_mvm_tzone_set_trip_temp,
669668
};
670669

671-
/* make all trips writable */
672-
#define IWL_WRITABLE_TRIPS_MSK (BIT(IWL_MAX_DTS_TRIPS) - 1)
673-
674670
static void iwl_mvm_thermal_zone_register(struct iwl_mvm *mvm)
675671
{
676672
int i, ret;
@@ -686,10 +682,18 @@ static void iwl_mvm_thermal_zone_register(struct iwl_mvm *mvm)
686682
BUILD_BUG_ON(ARRAY_SIZE(name) >= THERMAL_NAME_LENGTH);
687683

688684
sprintf(name, "iwlwifi_%u", atomic_inc_return(&counter) & 0xFF);
685+
/*
686+
* 0 is a valid temperature,
687+
* so initialize the array with S16_MIN which invalid temperature
688+
*/
689+
for (i = 0 ; i < IWL_MAX_DTS_TRIPS; i++) {
690+
mvm->tz_device.trips[i].temperature = THERMAL_TEMP_INVALID;
691+
mvm->tz_device.trips[i].type = THERMAL_TRIP_PASSIVE;
692+
mvm->tz_device.trips[i].flags = THERMAL_TRIP_FLAG_RW_TEMP;
693+
}
689694
mvm->tz_device.tzone = thermal_zone_device_register_with_trips(name,
690695
mvm->tz_device.trips,
691696
IWL_MAX_DTS_TRIPS,
692-
IWL_WRITABLE_TRIPS_MSK,
693697
mvm, &tzone_ops,
694698
NULL, 0, 0);
695699
if (IS_ERR(mvm->tz_device.tzone)) {
@@ -704,15 +708,6 @@ static void iwl_mvm_thermal_zone_register(struct iwl_mvm *mvm)
704708
if (ret) {
705709
IWL_DEBUG_TEMP(mvm, "Failed to enable thermal zone\n");
706710
thermal_zone_device_unregister(mvm->tz_device.tzone);
707-
return;
708-
}
709-
710-
/* 0 is a valid temperature,
711-
* so initialize the array with S16_MIN which invalid temperature
712-
*/
713-
for (i = 0 ; i < IWL_MAX_DTS_TRIPS; i++) {
714-
mvm->tz_device.trips[i].temperature = INT_MIN;
715-
mvm->tz_device.trips[i].type = THERMAL_TRIP_PASSIVE;
716711
}
717712
}
718713

drivers/platform/x86/acerhdf.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -678,7 +678,7 @@ static int __init acerhdf_register_thermal(void)
678678
return -EINVAL;
679679

680680
thz_dev = thermal_zone_device_register_with_trips("acerhdf", trips, ARRAY_SIZE(trips),
681-
0, NULL, &acerhdf_dev_ops,
681+
NULL, &acerhdf_dev_ops,
682682
&acerhdf_zone_params, 0,
683683
(kernelmode) ? interval*1000 : 0);
684684
if (IS_ERR(thz_dev))

0 commit comments

Comments
 (0)