Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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
...

+282 -395
-1
arch/arm/configs/imx_v6_v7_defconfig
··· 229 229 CONFIG_SENSORS_PWM_FAN=y 230 230 CONFIG_SENSORS_SY7636A=y 231 231 CONFIG_THERMAL_STATISTICS=y 232 - CONFIG_THERMAL_WRITABLE_TRIPS=y 233 232 CONFIG_CPU_THERMAL=y 234 233 CONFIG_IMX_THERMAL=y 235 234 CONFIG_WATCHDOG=y
+22 -39
drivers/acpi/thermal.c
··· 47 47 48 48 #define ACPI_THERMAL_TRIP_PASSIVE (-1) 49 49 50 + #define ACPI_THERMAL_MAX_NR_TRIPS (ACPI_THERMAL_MAX_ACTIVE + 3) 51 + 50 52 /* 51 53 * This exception is thrown out in two cases: 52 54 * 1.An invalid trip point becomes invalid or a valid trip point becomes invalid ··· 114 112 unsigned long polling_frequency; 115 113 volatile u8 zombie; 116 114 struct acpi_thermal_trips trips; 117 - struct thermal_trip *trip_table; 118 115 struct thermal_zone_device *thermal_zone; 119 116 int kelvin_offset; /* in millidegrees */ 120 117 struct work_struct thermal_check_work; ··· 452 451 return false; 453 452 } 454 453 455 - static int acpi_thermal_get_trip_points(struct acpi_thermal *tz) 454 + static void acpi_thermal_get_trip_points(struct acpi_thermal *tz) 456 455 { 457 - unsigned int count = 0; 458 456 int i; 459 457 460 - if (acpi_thermal_init_trip(tz, ACPI_THERMAL_TRIP_PASSIVE)) 461 - count++; 458 + acpi_thermal_init_trip(tz, ACPI_THERMAL_TRIP_PASSIVE); 462 459 463 460 for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) { 464 - if (acpi_thermal_init_trip(tz, i)) 465 - count++; 466 - else 461 + if (!acpi_thermal_init_trip(tz, i)) 467 462 break; 468 - 469 463 } 470 464 471 465 while (++i < ACPI_THERMAL_MAX_ACTIVE) 472 466 tz->trips.active[i].trip.temp_dk = THERMAL_TEMP_INVALID; 473 - 474 - return count; 475 467 } 476 468 477 469 /* sys I/F for generic thermal sysfs support */ ··· 620 626 return acpi_thermal_bind_unbind_cdev(thermal, cdev, false); 621 627 } 622 628 623 - static struct thermal_zone_device_ops acpi_thermal_zone_ops = { 629 + static const struct thermal_zone_device_ops acpi_thermal_zone_ops = { 624 630 .bind = acpi_thermal_bind_cooling_device, 625 631 .unbind = acpi_thermal_unbind_cooling_device, 626 632 .get_temp = thermal_get_temp, ··· 656 662 } 657 663 658 664 static int acpi_thermal_register_thermal_zone(struct acpi_thermal *tz, 665 + const struct thermal_trip *trip_table, 659 666 unsigned int trip_count, 660 667 int passive_delay) 661 668 { 662 669 int result; 663 670 664 671 tz->thermal_zone = thermal_zone_device_register_with_trips("acpitz", 665 - tz->trip_table, 672 + trip_table, 666 673 trip_count, 667 - 0, tz, 674 + tz, 668 675 &acpi_thermal_zone_ops, 669 676 NULL, 670 677 passive_delay, ··· 818 823 819 824 static int acpi_thermal_add(struct acpi_device *device) 820 825 { 826 + struct thermal_trip trip_table[ACPI_THERMAL_MAX_NR_TRIPS] = { 0 }; 821 827 struct acpi_thermal_trip *acpi_trip; 822 828 struct thermal_trip *trip; 823 829 struct acpi_thermal *tz; 824 - unsigned int trip_count; 825 830 int crit_temp, hot_temp; 826 831 int passive_delay = 0; 827 832 int result; ··· 843 848 acpi_thermal_aml_dependency_fix(tz); 844 849 845 850 /* Get trip points [_CRT, _PSV, etc.] (required). */ 846 - trip_count = acpi_thermal_get_trip_points(tz); 851 + acpi_thermal_get_trip_points(tz); 847 852 848 853 crit_temp = acpi_thermal_get_critical_trip(tz); 849 - if (crit_temp != THERMAL_TEMP_INVALID) 850 - trip_count++; 851 - 852 854 hot_temp = acpi_thermal_get_hot_trip(tz); 853 - if (hot_temp != THERMAL_TEMP_INVALID) 854 - trip_count++; 855 - 856 - if (!trip_count) { 857 - pr_warn(FW_BUG "No valid trip points!\n"); 858 - result = -ENODEV; 859 - goto free_memory; 860 - } 861 855 862 856 /* Get temperature [_TMP] (required). */ 863 857 result = acpi_thermal_get_temperature(tz); ··· 865 881 866 882 acpi_thermal_guess_offset(tz, crit_temp); 867 883 868 - trip = kcalloc(trip_count, sizeof(*trip), GFP_KERNEL); 869 - if (!trip) { 870 - result = -ENOMEM; 871 - goto free_memory; 872 - } 873 - 874 - tz->trip_table = trip; 884 + trip = trip_table; 875 885 876 886 if (crit_temp != THERMAL_TEMP_INVALID) { 877 887 trip->type = THERMAL_TRIP_CRITICAL; ··· 901 923 trip++; 902 924 } 903 925 904 - result = acpi_thermal_register_thermal_zone(tz, trip_count, passive_delay); 926 + if (trip == trip_table) { 927 + pr_warn(FW_BUG "No valid trip points!\n"); 928 + result = -ENODEV; 929 + goto free_memory; 930 + } 931 + 932 + result = acpi_thermal_register_thermal_zone(tz, trip_table, 933 + trip - trip_table, 934 + passive_delay); 905 935 if (result) 906 - goto free_trips; 936 + goto free_memory; 907 937 908 938 refcount_set(&tz->thermal_check_count, 3); 909 939 mutex_init(&tz->thermal_check_lock); ··· 930 944 flush_wq: 931 945 flush_workqueue(acpi_thermal_pm_queue); 932 946 acpi_thermal_unregister_thermal_zone(tz); 933 - free_trips: 934 - kfree(tz->trip_table); 935 947 free_memory: 936 948 acpi_thermal_free_thermal_zone(tz); 937 949 ··· 950 966 951 967 flush_workqueue(acpi_thermal_pm_queue); 952 968 acpi_thermal_unregister_thermal_zone(tz); 953 - kfree(tz->trip_table); 954 969 acpi_thermal_free_thermal_zone(tz); 955 970 } 956 971
+1 -1
drivers/net/ethernet/chelsio/cxgb4/cxgb4_thermal.c
··· 60 60 61 61 snprintf(ch_tz_name, sizeof(ch_tz_name), "cxgb4_%s", adap->name); 62 62 ch_thermal->tzdev = thermal_zone_device_register_with_trips(ch_tz_name, &trip, num_trip, 63 - 0, adap, 63 + adap, 64 64 &cxgb4_thermal_ops, 65 65 NULL, 0, 0); 66 66 if (IS_ERR(ch_thermal->tzdev)) {
+6 -6
drivers/net/ethernet/mellanox/mlxsw/core_thermal.c
··· 44 44 .type = THERMAL_TRIP_ACTIVE, 45 45 .temperature = MLXSW_THERMAL_ASIC_TEMP_NORM, 46 46 .hysteresis = MLXSW_THERMAL_HYSTERESIS_TEMP, 47 + .flags = THERMAL_TRIP_FLAG_RW_TEMP, 47 48 }, 48 49 { 49 50 /* In range - 40-100% PWM */ 50 51 .type = THERMAL_TRIP_ACTIVE, 51 52 .temperature = MLXSW_THERMAL_ASIC_TEMP_HIGH, 52 53 .hysteresis = MLXSW_THERMAL_HYSTERESIS_TEMP, 54 + .flags = THERMAL_TRIP_FLAG_RW_TEMP, 53 55 }, 54 56 { /* Warning */ 55 57 .type = THERMAL_TRIP_HOT, 56 58 .temperature = MLXSW_THERMAL_ASIC_TEMP_HOT, 59 + .flags = THERMAL_TRIP_FLAG_RW_TEMP, 57 60 }, 58 61 }; 59 62 ··· 65 62 .type = THERMAL_TRIP_ACTIVE, 66 63 .temperature = MLXSW_THERMAL_MODULE_TEMP_NORM, 67 64 .hysteresis = MLXSW_THERMAL_HYSTERESIS_TEMP, 65 + .flags = THERMAL_TRIP_FLAG_RW_TEMP, 68 66 }, 69 67 { 70 68 /* In range - 40-100% PWM */ 71 69 .type = THERMAL_TRIP_ACTIVE, 72 70 .temperature = MLXSW_THERMAL_MODULE_TEMP_HIGH, 73 71 .hysteresis = MLXSW_THERMAL_HYSTERESIS_TEMP, 72 + .flags = THERMAL_TRIP_FLAG_RW_TEMP, 74 73 }, 75 74 { /* Warning */ 76 75 .type = THERMAL_TRIP_HOT, 77 76 .temperature = MLXSW_THERMAL_MODULE_TEMP_HOT, 77 + .flags = THERMAL_TRIP_FLAG_RW_TEMP, 78 78 }, 79 79 }; 80 80 ··· 97 91 }; 98 92 99 93 #define MLXSW_THERMAL_NUM_TRIPS ARRAY_SIZE(default_thermal_trips) 100 - 101 - /* Make sure all trips are writable */ 102 - #define MLXSW_THERMAL_TRIP_MASK (BIT(MLXSW_THERMAL_NUM_TRIPS) - 1) 103 94 104 95 struct mlxsw_thermal; 105 96 ··· 423 420 module_tz->tzdev = thermal_zone_device_register_with_trips(tz_name, 424 421 module_tz->trips, 425 422 MLXSW_THERMAL_NUM_TRIPS, 426 - MLXSW_THERMAL_TRIP_MASK, 427 423 module_tz, 428 424 &mlxsw_thermal_module_ops, 429 425 &mlxsw_thermal_params, ··· 550 548 gearbox_tz->tzdev = thermal_zone_device_register_with_trips(tz_name, 551 549 gearbox_tz->trips, 552 550 MLXSW_THERMAL_NUM_TRIPS, 553 - MLXSW_THERMAL_TRIP_MASK, 554 551 gearbox_tz, 555 552 &mlxsw_thermal_gearbox_ops, 556 553 &mlxsw_thermal_params, 0, ··· 774 773 thermal->tzdev = thermal_zone_device_register_with_trips("mlxsw", 775 774 thermal->trips, 776 775 MLXSW_THERMAL_NUM_TRIPS, 777 - MLXSW_THERMAL_TRIP_MASK, 778 776 thermal, 779 777 &mlxsw_thermal_ops, 780 778 &mlxsw_thermal_params, 0,
-2
drivers/net/wireless/intel/iwlwifi/mvm/mvm.h
··· 543 543 /** 544 544 * struct iwl_mvm_thermal_device - thermal zone related data 545 545 * @trips: temperature thresholds for report 546 - * @fw_trips_index: keep indexes to original array - temp_trips 547 546 * @tzone: thermal zone device data 548 547 */ 549 548 struct iwl_mvm_thermal_device { 550 549 struct thermal_trip trips[IWL_MAX_DTS_TRIPS]; 551 - u8 fw_trips_index[IWL_MAX_DTS_TRIPS]; 552 550 struct thermal_zone_device *tzone; 553 551 }; 554 552
+34 -39
drivers/net/wireless/intel/iwlwifi/mvm/tt.c
··· 555 555 return ((s16)le16_to_cpu(*(__le16 *)a) - 556 556 (s16)le16_to_cpu(*(__le16 *)b)); 557 557 } 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 + } 558 574 #endif 559 575 560 576 int iwl_mvm_send_temp_report_ths_cmd(struct iwl_mvm *mvm) ··· 578 562 struct temp_report_ths_cmd cmd = {0}; 579 563 int ret; 580 564 #ifdef CONFIG_THERMAL 581 - int i, j, idx = 0; 565 + struct iwl_trip_walk_data twd = { .thresholds = cmd.thresholds, .count = 0 }; 582 566 583 567 lockdep_assert_held(&mvm->mutex); 584 568 585 569 if (!mvm->tz_device.tzone) 586 570 goto send; 587 571 588 - /* The driver holds array of temperature trips that are unsorted 589 - * and uncompressed, the FW should get it compressed and sorted 572 + /* 573 + * The thermal core holds an array of temperature trips that are 574 + * unsorted and uncompressed, the FW should get it compressed and 575 + * sorted. 590 576 */ 591 577 592 578 /* compress trips to cmd array, remove uninitialized values*/ 593 - for (i = 0; i < IWL_MAX_DTS_TRIPS; i++) { 594 - if (mvm->tz_device.trips[i].temperature != INT_MIN) { 595 - cmd.thresholds[idx++] = 596 - cpu_to_le16((s16)(mvm->tz_device.trips[i].temperature / 1000)); 597 - } 598 - } 599 - cmd.num_temps = cpu_to_le32(idx); 579 + for_each_thermal_trip(mvm->tz_device.tzone, iwl_trip_temp_cb, &twd); 600 580 601 - if (!idx) 602 - goto send; 603 - 604 - /*sort cmd array*/ 605 - sort(cmd.thresholds, idx, sizeof(s16), compare_temps, NULL); 606 - 607 - /* we should save the indexes of trips because we sort 608 - * and compress the orginal array 609 - */ 610 - for (i = 0; i < idx; i++) { 611 - for (j = 0; j < IWL_MAX_DTS_TRIPS; j++) { 612 - if ((int)(le16_to_cpu(cmd.thresholds[i]) * 1000) == 613 - mvm->tz_device.trips[j].temperature) 614 - mvm->tz_device.fw_trips_index[i] = j; 615 - } 616 - } 581 + cmd.num_temps = cpu_to_le32(twd.count); 582 + if (twd.count) 583 + sort(cmd.thresholds, twd.count, sizeof(s16), compare_temps, NULL); 617 584 618 585 send: 619 586 #endif ··· 667 668 .set_trip_temp = iwl_mvm_tzone_set_trip_temp, 668 669 }; 669 670 670 - /* make all trips writable */ 671 - #define IWL_WRITABLE_TRIPS_MSK (BIT(IWL_MAX_DTS_TRIPS) - 1) 672 - 673 671 static void iwl_mvm_thermal_zone_register(struct iwl_mvm *mvm) 674 672 { 675 673 int i, ret; ··· 682 686 BUILD_BUG_ON(ARRAY_SIZE(name) >= THERMAL_NAME_LENGTH); 683 687 684 688 sprintf(name, "iwlwifi_%u", atomic_inc_return(&counter) & 0xFF); 689 + /* 690 + * 0 is a valid temperature, 691 + * so initialize the array with S16_MIN which invalid temperature 692 + */ 693 + for (i = 0 ; i < IWL_MAX_DTS_TRIPS; i++) { 694 + mvm->tz_device.trips[i].temperature = THERMAL_TEMP_INVALID; 695 + mvm->tz_device.trips[i].type = THERMAL_TRIP_PASSIVE; 696 + mvm->tz_device.trips[i].flags = THERMAL_TRIP_FLAG_RW_TEMP; 697 + } 685 698 mvm->tz_device.tzone = thermal_zone_device_register_with_trips(name, 686 699 mvm->tz_device.trips, 687 700 IWL_MAX_DTS_TRIPS, 688 - IWL_WRITABLE_TRIPS_MSK, 689 701 mvm, &tzone_ops, 690 702 NULL, 0, 0); 691 703 if (IS_ERR(mvm->tz_device.tzone)) { ··· 708 704 if (ret) { 709 705 IWL_DEBUG_TEMP(mvm, "Failed to enable thermal zone\n"); 710 706 thermal_zone_device_unregister(mvm->tz_device.tzone); 711 - return; 712 - } 713 - 714 - /* 0 is a valid temperature, 715 - * so initialize the array with S16_MIN which invalid temperature 716 - */ 717 - for (i = 0 ; i < IWL_MAX_DTS_TRIPS; i++) { 718 - mvm->tz_device.trips[i].temperature = INT_MIN; 719 - mvm->tz_device.trips[i].type = THERMAL_TRIP_PASSIVE; 720 707 } 721 708 } 722 709
+1 -1
drivers/platform/x86/acerhdf.c
··· 678 678 return -EINVAL; 679 679 680 680 thz_dev = thermal_zone_device_register_with_trips("acerhdf", trips, ARRAY_SIZE(trips), 681 - 0, NULL, &acerhdf_dev_ops, 681 + NULL, &acerhdf_dev_ops, 682 682 &acerhdf_zone_params, 0, 683 683 (kernelmode) ? interval*1000 : 0); 684 684 if (IS_ERR(thz_dev))
-11
drivers/thermal/Kconfig
··· 83 83 Say 'Y' here if you need to build thermal infrastructure 84 84 based on device tree. 85 85 86 - config THERMAL_WRITABLE_TRIPS 87 - bool "Enable writable trip points" 88 - help 89 - This option allows the system integrator to choose whether 90 - trip temperatures can be changed from userspace. The 91 - writable trips need to be specified when setting up the 92 - thermal zone but the choice here takes precedence. 93 - 94 - Say 'Y' here if you would like to allow userspace tools to 95 - change trip temperatures. 96 - 97 86 choice 98 87 prompt "Default Thermal governor" 99 88 default THERMAL_DEFAULT_GOV_STEP_WISE
+1 -1
drivers/thermal/da9062-thermal.c
··· 197 197 mutex_init(&thermal->lock); 198 198 199 199 thermal->zone = thermal_zone_device_register_with_trips(thermal->config->name, 200 - trips, ARRAY_SIZE(trips), 0, thermal, 200 + trips, ARRAY_SIZE(trips), thermal, 201 201 &da9062_thermal_ops, NULL, pp_tmp, 202 202 0); 203 203 if (IS_ERR(thermal->zone)) {
+1 -1
drivers/thermal/gov_bang_bang.c
··· 49 49 if (instance->target == 0 && tz->temperature >= trip->temperature) 50 50 instance->target = 1; 51 51 else if (instance->target == 1 && 52 - tz->temperature <= trip->temperature - trip->hysteresis) 52 + tz->temperature < trip->temperature - trip->hysteresis) 53 53 instance->target = 0; 54 54 55 55 dev_dbg(&instance->cdev->device, "target=%d\n",
+9 -7
drivers/thermal/gov_fair_share.c
··· 18 18 static int get_trip_level(struct thermal_zone_device *tz) 19 19 { 20 20 const struct thermal_trip *trip, *level_trip = NULL; 21 - int trip_level; 21 + int trip_level = -1; 22 22 23 23 for_each_trip(tz, trip) { 24 24 if (trip->temperature >= tz->temperature) 25 - break; 25 + continue; 26 26 27 - level_trip = trip; 27 + trip_level++; 28 + 29 + if (!level_trip || trip->temperature > level_trip->temperature) 30 + level_trip = trip; 28 31 } 29 32 30 33 /* Bail out if the temperature is not greater than any trips. */ 31 - if (!level_trip) 34 + if (trip_level < 0) 32 35 return 0; 33 36 34 - trip_level = thermal_zone_trip_id(tz, level_trip); 35 - 36 - trace_thermal_zone_trip(tz, trip_level, level_trip->type); 37 + trace_thermal_zone_trip(tz, thermal_zone_trip_id(tz, level_trip), 38 + level_trip->type); 37 39 38 40 return trip_level; 39 41 }
+2
drivers/thermal/gov_power_allocator.c
··· 711 711 712 712 if (!tz->tzp->sustainable_power) 713 713 dev_warn(&tz->device, "power_allocator: sustainable_power will be estimated\n"); 714 + else 715 + params->sustainable_power = tz->tzp->sustainable_power; 714 716 715 717 estimate_pid_constants(tz, tz->tzp->sustainable_power, 716 718 params->trip_switch_on,
+4 -2
drivers/thermal/imx_thermal.c
··· 115 115 }; 116 116 117 117 static struct thermal_trip trips[] = { 118 - [IMX_TRIP_PASSIVE] = { .type = THERMAL_TRIP_PASSIVE }, 118 + [IMX_TRIP_PASSIVE] = { .type = THERMAL_TRIP_PASSIVE, 119 + .flags = THERMAL_TRIP_FLAG_RW_TEMP }, 119 120 [IMX_TRIP_CRITICAL] = { .type = THERMAL_TRIP_CRITICAL }, 120 121 }; 121 122 ··· 355 354 return -EINVAL; 356 355 357 356 imx_set_alarm_temp(data, temp); 357 + trips[IMX_TRIP_PASSIVE].temperature = temp; 358 358 359 359 pm_runtime_put(data->dev); 360 360 ··· 701 699 data->tz = thermal_zone_device_register_with_trips("imx_thermal_zone", 702 700 trips, 703 701 ARRAY_SIZE(trips), 704 - BIT(IMX_TRIP_PASSIVE), data, 702 + data, 705 703 &imx_tz_ops, NULL, 706 704 IMX_PASSIVE_DELAY, 707 705 IMX_POLLING_DELAY);
-2
drivers/thermal/intel/Kconfig
··· 23 23 tristate "X86 package temperature thermal driver" 24 24 depends on X86_THERMAL_VECTOR 25 25 select THERMAL_GOV_USER_SPACE 26 - select THERMAL_WRITABLE_TRIPS 27 26 select INTEL_TCC 28 27 default m 29 28 help ··· 46 47 tristate "Intel SoCs DTS thermal driver" 47 48 depends on X86 && PCI && ACPI 48 49 select INTEL_SOC_DTS_IOSF_CORE 49 - select THERMAL_WRITABLE_TRIPS 50 50 help 51 51 Enable this to register Intel SoCs (e.g. Bay Trail) platform digital 52 52 temperature sensor (DTS). These SoCs have two additional DTSs in
+13 -30
drivers/thermal/intel/int340x_thermal/int340x_thermal_zone.c
··· 58 58 59 59 static void int340x_thermal_critical(struct thermal_zone_device *zone) 60 60 { 61 - dev_dbg(&zone->device, "%s: critical temperature reached\n", zone->type); 61 + dev_dbg(thermal_zone_device(zone), "%s: critical temperature reached\n", 62 + thermal_zone_device_type(zone)); 62 63 } 63 - 64 - static struct thermal_zone_device_ops int340x_thermal_zone_ops = { 65 - .get_temp = int340x_thermal_get_zone_temp, 66 - .set_trip_temp = int340x_thermal_set_trip_temp, 67 - .critical = int340x_thermal_critical, 68 - }; 69 64 70 65 static inline void *int_to_trip_priv(int i) 71 66 { ··· 121 126 struct int34x_thermal_zone *int340x_thermal_zone_add(struct acpi_device *adev, 122 127 int (*get_temp) (struct thermal_zone_device *, int *)) 123 128 { 129 + const struct thermal_zone_device_ops zone_ops = { 130 + .set_trip_temp = int340x_thermal_set_trip_temp, 131 + .critical = int340x_thermal_critical, 132 + .get_temp = get_temp ? get_temp : int340x_thermal_get_zone_temp, 133 + }; 124 134 struct int34x_thermal_zone *int34x_zone; 125 135 struct thermal_trip *zone_trips; 126 136 unsigned long long trip_cnt = 0; 127 137 unsigned long long hyst; 128 - int trip_mask = 0; 129 138 acpi_status status; 130 139 int i, ret; 131 140 ··· 139 140 140 141 int34x_zone->adev = adev; 141 142 142 - int34x_zone->ops = kmemdup(&int340x_thermal_zone_ops, 143 - sizeof(int340x_thermal_zone_ops), GFP_KERNEL); 144 - if (!int34x_zone->ops) { 145 - ret = -ENOMEM; 146 - goto err_ops_alloc; 147 - } 148 - 149 - if (get_temp) 150 - int34x_zone->ops->get_temp = get_temp; 151 - 152 143 status = acpi_evaluate_integer(adev->handle, "PATC", NULL, &trip_cnt); 153 - if (ACPI_SUCCESS(status)) { 144 + if (ACPI_SUCCESS(status)) 154 145 int34x_zone->aux_trip_nr = trip_cnt; 155 - trip_mask = BIT(trip_cnt) - 1; 156 - } 157 146 158 147 zone_trips = kzalloc(sizeof(*zone_trips) * (trip_cnt + INT340X_THERMAL_MAX_TRIP_COUNT), 159 148 GFP_KERNEL); ··· 153 166 for (i = 0; i < trip_cnt; i++) { 154 167 zone_trips[i].type = THERMAL_TRIP_PASSIVE; 155 168 zone_trips[i].temperature = THERMAL_TEMP_INVALID; 169 + zone_trips[i].flags |= THERMAL_TRIP_FLAG_RW_TEMP; 156 170 } 157 171 158 172 trip_cnt = int340x_thermal_read_trips(adev, zone_trips, trip_cnt); ··· 167 179 for (i = 0; i < trip_cnt; ++i) 168 180 zone_trips[i].hysteresis = hyst; 169 181 170 - int34x_zone->trips = zone_trips; 171 - 172 182 int34x_zone->lpat_table = acpi_lpat_get_conversion_table(adev->handle); 173 183 174 184 int34x_zone->zone = thermal_zone_device_register_with_trips( 175 185 acpi_device_bid(adev), 176 186 zone_trips, trip_cnt, 177 - trip_mask, int34x_zone, 178 - int34x_zone->ops, 187 + int34x_zone, 188 + &zone_ops, 179 189 &int340x_thermal_params, 180 190 0, 0); 191 + kfree(zone_trips); 192 + 181 193 if (IS_ERR(int34x_zone->zone)) { 182 194 ret = PTR_ERR(int34x_zone->zone); 183 195 goto err_thermal_zone; ··· 191 203 err_enable: 192 204 thermal_zone_device_unregister(int34x_zone->zone); 193 205 err_thermal_zone: 194 - kfree(int34x_zone->trips); 195 206 acpi_lpat_free_conversion_table(int34x_zone->lpat_table); 196 207 err_trips_alloc: 197 - kfree(int34x_zone->ops); 198 - err_ops_alloc: 199 208 kfree(int34x_zone); 200 209 return ERR_PTR(ret); 201 210 } ··· 202 217 { 203 218 thermal_zone_device_unregister(int34x_zone->zone); 204 219 acpi_lpat_free_conversion_table(int34x_zone->lpat_table); 205 - kfree(int34x_zone->trips); 206 - kfree(int34x_zone->ops); 207 220 kfree(int34x_zone); 208 221 } 209 222 EXPORT_SYMBOL_GPL(int340x_thermal_zone_remove);
-2
drivers/thermal/intel/int340x_thermal/int340x_thermal_zone.h
··· 20 20 21 21 struct int34x_thermal_zone { 22 22 struct acpi_device *adev; 23 - struct thermal_trip *trips; 24 23 int aux_trip_nr; 25 24 struct thermal_zone_device *zone; 26 - struct thermal_zone_device_ops *ops; 27 25 void *priv_data; 28 26 struct acpi_lpat_conversion_table *lpat_table; 29 27 };
+4 -4
drivers/thermal/intel/int340x_thermal/processor_thermal_device.c
··· 176 176 int *temp) 177 177 { 178 178 int cpu; 179 - int curr_temp; 179 + int curr_temp, ret; 180 180 181 181 *temp = 0; 182 182 183 183 for_each_online_cpu(cpu) { 184 - curr_temp = intel_tcc_get_temp(cpu, false); 185 - if (curr_temp < 0) 186 - return curr_temp; 184 + ret = intel_tcc_get_temp(cpu, &curr_temp, false); 185 + if (ret < 0) 186 + return ret; 187 187 if (!*temp || curr_temp > *temp) 188 188 *temp = curr_temp; 189 189 }
+1
drivers/thermal/intel/int340x_thermal/processor_thermal_device.h
··· 25 25 #define PCI_DEVICE_ID_INTEL_HSB_THERMAL 0x0A03 26 26 #define PCI_DEVICE_ID_INTEL_ICL_THERMAL 0x8a03 27 27 #define PCI_DEVICE_ID_INTEL_JSL_THERMAL 0x4E03 28 + #define PCI_DEVICE_ID_INTEL_LNLM_THERMAL 0x641D 28 29 #define PCI_DEVICE_ID_INTEL_MTLP_THERMAL 0x7D03 29 30 #define PCI_DEVICE_ID_INTEL_RPL_THERMAL 0xA71D 30 31 #define PCI_DEVICE_ID_INTEL_SKL_THERMAL 0x1903
+7 -6
drivers/thermal/intel/int340x_thermal/processor_thermal_device_pci.c
··· 233 233 return temp; 234 234 } 235 235 236 - static struct thermal_trip psv_trip = { 237 - .type = THERMAL_TRIP_PASSIVE, 238 - }; 239 - 240 - static struct thermal_zone_device_ops tzone_ops = { 236 + static const struct thermal_zone_device_ops tzone_ops = { 241 237 .get_temp = sys_get_curr_temp, 242 238 .set_trip_temp = sys_set_trip_temp, 243 239 }; ··· 247 251 { 248 252 struct proc_thermal_device *proc_priv; 249 253 struct proc_thermal_pci *pci_info; 254 + struct thermal_trip psv_trip = { 255 + .type = THERMAL_TRIP_PASSIVE, 256 + .flags = THERMAL_TRIP_FLAG_RW_TEMP, 257 + }; 250 258 int irq_flag = 0, irq, ret; 251 259 bool msi_irq = false; 252 260 ··· 290 290 psv_trip.temperature = get_trip_temp(pci_info); 291 291 292 292 pci_info->tzone = thermal_zone_device_register_with_trips("TCPU_PCI", &psv_trip, 293 - 1, 1, pci_info, 293 + 1, pci_info, 294 294 &tzone_ops, 295 295 &tzone_params, 0, 0); 296 296 if (IS_ERR(pci_info->tzone)) { ··· 407 407 static const struct pci_device_id proc_thermal_pci_ids[] = { 408 408 { PCI_DEVICE_DATA(INTEL, ADL_THERMAL, PROC_THERMAL_FEATURE_RAPL | 409 409 PROC_THERMAL_FEATURE_FIVR | PROC_THERMAL_FEATURE_DVFS | PROC_THERMAL_FEATURE_WT_REQ) }, 410 + { PCI_DEVICE_DATA(INTEL, LNLM_THERMAL, PROC_THERMAL_FEATURE_RAPL) }, 410 411 { PCI_DEVICE_DATA(INTEL, MTLP_THERMAL, PROC_THERMAL_FEATURE_RAPL | 411 412 PROC_THERMAL_FEATURE_FIVR | PROC_THERMAL_FEATURE_DVFS | PROC_THERMAL_FEATURE_DLVR | 412 413 PROC_THERMAL_FEATURE_WT_HINT | PROC_THERMAL_FEATURE_POWER_FLOOR) },
+15 -13
drivers/thermal/intel/intel_pch_thermal.c
··· 84 84 void __iomem *hw_base; 85 85 struct pci_dev *pdev; 86 86 struct thermal_zone_device *tzd; 87 - struct thermal_trip trips[PCH_MAX_TRIPS]; 88 87 bool bios_enabled; 89 88 }; 90 89 ··· 93 94 * passive trip temperature using _PSV method. There is no specific 94 95 * passive temperature setting in MMIO interface of this PCI device. 95 96 */ 96 - static int pch_wpt_add_acpi_psv_trip(struct pch_thermal_device *ptd, int trip) 97 + static int pch_wpt_add_acpi_psv_trip(struct pch_thermal_device *ptd, 98 + struct thermal_trip *trip) 97 99 { 98 100 struct acpi_device *adev; 99 101 int temp; ··· 106 106 if (thermal_acpi_passive_trip_temp(adev, &temp) || temp <= 0) 107 107 return 0; 108 108 109 - ptd->trips[trip].type = THERMAL_TRIP_PASSIVE; 110 - ptd->trips[trip].temperature = temp; 109 + trip->type = THERMAL_TRIP_PASSIVE; 110 + trip->temperature = temp; 111 111 return 1; 112 112 } 113 113 #else 114 - static int pch_wpt_add_acpi_psv_trip(struct pch_thermal_device *ptd, int trip) 114 + static int pch_wpt_add_acpi_psv_trip(struct pch_thermal_device *ptd, 115 + struct thermal_trip *trip) 115 116 { 116 117 return 0; 117 118 } ··· 132 131 thermal_zone_device_type(tzd)); 133 132 } 134 133 135 - static struct thermal_zone_device_ops tzd_ops = { 134 + static const struct thermal_zone_device_ops tzd_ops = { 136 135 .get_temp = pch_thermal_get_temp, 137 136 .critical = pch_critical, 138 137 }; ··· 160 159 static int intel_pch_thermal_probe(struct pci_dev *pdev, 161 160 const struct pci_device_id *id) 162 161 { 162 + struct thermal_trip ptd_trips[PCH_MAX_TRIPS] = { 0 }; 163 163 enum pch_board_ids board_id = id->driver_data; 164 164 struct pch_thermal_device *ptd; 165 165 int nr_trips = 0; ··· 222 220 trip_temp = readw(ptd->hw_base + WPT_CTT); 223 221 trip_temp &= 0x1FF; 224 222 if (trip_temp) { 225 - ptd->trips[nr_trips].temperature = GET_WPT_TEMP(trip_temp); 226 - ptd->trips[nr_trips++].type = THERMAL_TRIP_CRITICAL; 223 + ptd_trips[nr_trips].temperature = GET_WPT_TEMP(trip_temp); 224 + ptd_trips[nr_trips++].type = THERMAL_TRIP_CRITICAL; 227 225 } 228 226 229 227 trip_temp = readw(ptd->hw_base + WPT_PHL); 230 228 trip_temp &= 0x1FF; 231 229 if (trip_temp) { 232 - ptd->trips[nr_trips].temperature = GET_WPT_TEMP(trip_temp); 233 - ptd->trips[nr_trips++].type = THERMAL_TRIP_HOT; 230 + ptd_trips[nr_trips].temperature = GET_WPT_TEMP(trip_temp); 231 + ptd_trips[nr_trips++].type = THERMAL_TRIP_HOT; 234 232 } 235 233 236 - nr_trips += pch_wpt_add_acpi_psv_trip(ptd, nr_trips); 234 + nr_trips += pch_wpt_add_acpi_psv_trip(ptd, &ptd_trips[nr_trips]); 237 235 238 236 ptd->tzd = thermal_zone_device_register_with_trips(board_names[board_id], 239 - ptd->trips, nr_trips, 240 - 0, ptd, &tzd_ops, 237 + ptd_trips, nr_trips, 238 + ptd, &tzd_ops, 241 239 NULL, 0, 0); 242 240 if (IS_ERR(ptd->tzd)) { 243 241 dev_err(&pdev->dev, "Failed to register thermal zone %s\n",
+13 -21
drivers/thermal/intel/intel_quark_dts_thermal.c
··· 93 93 94 94 /* Quark DTS has 2 trip points: hot & catastrophic */ 95 95 #define QRK_MAX_DTS_TRIPS 2 96 - /* If DTS not locked, all trip points are configurable */ 97 - #define QRK_DTS_WR_MASK_SET 0x3 98 - /* If DTS locked, all trip points are not configurable */ 99 - #define QRK_DTS_WR_MASK_CLR 0 100 96 101 97 #define DEFAULT_POLL_DELAY 2000 102 98 ··· 101 105 u32 store_ptps; 102 106 u32 store_dts_enable; 103 107 struct thermal_zone_device *tzone; 104 - struct thermal_trip trips[QRK_MAX_DTS_TRIPS]; 105 108 }; 106 109 107 110 static struct soc_sensor_entry *soc_dts; ··· 288 293 return ret; 289 294 } 290 295 291 - static struct thermal_zone_device_ops tzone_ops = { 296 + static const struct thermal_zone_device_ops tzone_ops = { 292 297 .get_temp = sys_get_curr_temp, 293 298 .set_trip_temp = sys_set_trip_temp, 294 299 .change_mode = sys_change_mode, ··· 315 320 316 321 static struct soc_sensor_entry *alloc_soc_dts(void) 317 322 { 323 + struct thermal_trip trips[QRK_MAX_DTS_TRIPS] = { 0 }; 318 324 struct soc_sensor_entry *aux_entry; 319 325 int err; 320 326 u32 out; 321 - int wr_mask; 322 327 323 328 aux_entry = kzalloc(sizeof(*aux_entry), GFP_KERNEL); 324 329 if (!aux_entry) { ··· 332 337 if (err) 333 338 goto err_ret; 334 339 335 - if (out & QRK_DTS_LOCK_BIT) { 336 - aux_entry->locked = true; 337 - wr_mask = QRK_DTS_WR_MASK_CLR; 338 - } else { 339 - aux_entry->locked = false; 340 - wr_mask = QRK_DTS_WR_MASK_SET; 341 - } 340 + aux_entry->locked = !!(out & QRK_DTS_LOCK_BIT); 342 341 343 342 /* Store DTS default state if DTS registers are not locked */ 344 343 if (!aux_entry->locked) { ··· 349 360 &aux_entry->store_ptps); 350 361 if (err) 351 362 goto err_ret; 363 + 364 + trips[QRK_DTS_ID_TP_CRITICAL].flags |= THERMAL_TRIP_FLAG_RW_TEMP; 365 + trips[QRK_DTS_ID_TP_HOT].flags |= THERMAL_TRIP_FLAG_RW_TEMP; 352 366 } 353 367 354 - aux_entry->trips[QRK_DTS_ID_TP_CRITICAL].temperature = get_trip_temp(QRK_DTS_ID_TP_CRITICAL); 355 - aux_entry->trips[QRK_DTS_ID_TP_CRITICAL].type = THERMAL_TRIP_CRITICAL; 368 + trips[QRK_DTS_ID_TP_CRITICAL].temperature = get_trip_temp(QRK_DTS_ID_TP_CRITICAL); 369 + trips[QRK_DTS_ID_TP_CRITICAL].type = THERMAL_TRIP_CRITICAL; 356 370 357 - aux_entry->trips[QRK_DTS_ID_TP_HOT].temperature = get_trip_temp(QRK_DTS_ID_TP_HOT); 358 - aux_entry->trips[QRK_DTS_ID_TP_HOT].type = THERMAL_TRIP_HOT; 371 + trips[QRK_DTS_ID_TP_HOT].temperature = get_trip_temp(QRK_DTS_ID_TP_HOT); 372 + trips[QRK_DTS_ID_TP_HOT].type = THERMAL_TRIP_HOT; 359 373 360 374 aux_entry->tzone = thermal_zone_device_register_with_trips("quark_dts", 361 - aux_entry->trips, 375 + trips, 362 376 QRK_MAX_DTS_TRIPS, 363 - wr_mask, 364 - aux_entry, &tzone_ops, 377 + aux_entry, 378 + &tzone_ops, 365 379 NULL, 0, polling_delay); 366 380 if (IS_ERR(aux_entry->tzone)) { 367 381 err = PTR_ERR(aux_entry->tzone);
+31 -46
drivers/thermal/intel/intel_soc_dts_iosf.c
··· 129 129 return status; 130 130 } 131 131 132 - static int configure_trip(struct intel_soc_dts_sensor_entry *dts, 133 - int thres_index, enum thermal_trip_type trip_type, 134 - int temp) 135 - { 136 - int ret; 137 - 138 - ret = update_trip_temp(dts->sensors, thres_index, temp); 139 - if (ret) 140 - return ret; 141 - 142 - dts->trips[thres_index].temperature = temp; 143 - dts->trips[thres_index].type = trip_type; 144 - 145 - return 0; 146 - } 147 - 148 132 static int sys_set_trip_temp(struct thermal_zone_device *tzd, int trip, 149 133 int temp) 150 134 { ··· 168 184 return 0; 169 185 } 170 186 171 - static struct thermal_zone_device_ops tzone_ops = { 187 + static const struct thermal_zone_device_ops tzone_ops = { 172 188 .get_temp = sys_get_curr_temp, 173 189 .set_trip_temp = sys_set_trip_temp, 174 190 }; ··· 202 218 } 203 219 204 220 static int add_dts_thermal_zone(int id, struct intel_soc_dts_sensor_entry *dts, 205 - bool critical_trip) 221 + struct thermal_trip *trips) 206 222 { 207 - int writable_trip_cnt = SOC_MAX_DTS_TRIPS; 208 223 char name[10]; 209 - unsigned long trip; 210 - int trip_mask; 211 - unsigned long ptps; 212 224 u32 store_ptps; 213 - unsigned long i; 214 225 int ret; 215 226 216 227 /* Store status to restor on exit */ ··· 216 237 217 238 dts->id = id; 218 239 219 - if (critical_trip) 220 - writable_trip_cnt--; 221 - 222 - trip_mask = GENMASK(writable_trip_cnt - 1, 0); 223 - 224 240 /* Check if the writable trip we provide is not used by BIOS */ 225 241 ret = iosf_mbi_read(BT_MBI_UNIT_PMC, MBI_REG_READ, 226 242 SOC_DTS_OFFSET_PTPS, &store_ptps); 227 - if (ret) 228 - trip_mask = 0; 229 - else { 230 - ptps = store_ptps; 231 - for_each_set_clump8(i, trip, &ptps, writable_trip_cnt * 8) 232 - trip_mask &= ~BIT(i / 8); 243 + if (!ret) { 244 + int i; 245 + 246 + for (i = 0; i <= 1; i++) { 247 + if (store_ptps & (0xFFU << i * 8)) 248 + trips[i].flags &= ~THERMAL_TRIP_FLAG_RW_TEMP; 249 + } 233 250 } 234 - dts->trip_mask = trip_mask; 235 251 snprintf(name, sizeof(name), "soc_dts%d", id); 236 - dts->tzone = thermal_zone_device_register_with_trips(name, dts->trips, 252 + dts->tzone = thermal_zone_device_register_with_trips(name, trips, 237 253 SOC_MAX_DTS_TRIPS, 238 - trip_mask, 239 254 dts, &tzone_ops, 240 255 NULL, 0, 0); 241 256 if (IS_ERR(dts->tzone)) { ··· 288 315 289 316 static void dts_trips_reset(struct intel_soc_dts_sensors *sensors, int dts_index) 290 317 { 291 - configure_trip(&sensors->soc_dts[dts_index], 0, 0, 0); 292 - configure_trip(&sensors->soc_dts[dts_index], 1, 0, 0); 318 + update_trip_temp(sensors, 0, 0); 319 + update_trip_temp(sensors, 1, 0); 320 + } 321 + 322 + static void set_trip(struct thermal_trip *trip, enum thermal_trip_type type, 323 + u8 flags, int temp) 324 + { 325 + trip->type = type; 326 + trip->flags = flags; 327 + trip->temperature = temp; 293 328 } 294 329 295 330 struct intel_soc_dts_sensors * 296 331 intel_soc_dts_iosf_init(enum intel_soc_dts_interrupt_type intr_type, 297 332 bool critical_trip, int crit_offset) 298 333 { 334 + struct thermal_trip trips[SOC_MAX_DTS_SENSORS][SOC_MAX_DTS_TRIPS] = { 0 }; 299 335 struct intel_soc_dts_sensors *sensors; 300 336 int tj_max; 301 337 int ret; ··· 327 345 sensors->tj_max = tj_max * 1000; 328 346 329 347 for (i = 0; i < SOC_MAX_DTS_SENSORS; ++i) { 330 - enum thermal_trip_type trip_type; 331 348 int temp; 332 349 333 350 sensors->soc_dts[i].sensors = sensors; 334 351 335 - ret = configure_trip(&sensors->soc_dts[i], 0, 336 - THERMAL_TRIP_PASSIVE, 0); 352 + set_trip(&trips[i][0], THERMAL_TRIP_PASSIVE, 353 + THERMAL_TRIP_FLAG_RW_TEMP, 0); 354 + 355 + ret = update_trip_temp(sensors, 0, 0); 337 356 if (ret) 338 357 goto err_reset_trips; 339 358 340 359 if (critical_trip) { 341 - trip_type = THERMAL_TRIP_CRITICAL; 342 360 temp = sensors->tj_max - crit_offset; 361 + set_trip(&trips[i][1], THERMAL_TRIP_CRITICAL, 0, temp); 343 362 } else { 344 - trip_type = THERMAL_TRIP_PASSIVE; 363 + set_trip(&trips[i][1], THERMAL_TRIP_PASSIVE, 364 + THERMAL_TRIP_FLAG_RW_TEMP, 0); 345 365 temp = 0; 346 366 } 347 - ret = configure_trip(&sensors->soc_dts[i], 1, trip_type, temp); 367 + 368 + ret = update_trip_temp(sensors, 1, temp); 348 369 if (ret) 349 370 goto err_reset_trips; 350 371 } 351 372 352 373 for (i = 0; i < SOC_MAX_DTS_SENSORS; ++i) { 353 - ret = add_dts_thermal_zone(i, &sensors->soc_dts[i], critical_trip); 374 + ret = add_dts_thermal_zone(i, &sensors->soc_dts[i], trips[i]); 354 375 if (ret) 355 376 goto err_remove_zone; 356 377 }
-2
drivers/thermal/intel/intel_soc_dts_iosf.h
··· 28 28 struct intel_soc_dts_sensor_entry { 29 29 int id; 30 30 u32 store_status; 31 - u32 trip_mask; 32 - struct thermal_trip trips[SOC_MAX_DTS_TRIPS]; 33 31 struct thermal_zone_device *tzone; 34 32 struct intel_soc_dts_sensors *sensors; 35 33 };
+6 -6
drivers/thermal/intel/intel_tcc.c
··· 103 103 /** 104 104 * intel_tcc_get_temp() - returns the current temperature 105 105 * @cpu: cpu that the MSR should be run on, nagative value means any cpu. 106 + * @temp: pointer to the memory for saving cpu temperature. 106 107 * @pkg: true: Package Thermal Sensor. false: Core Thermal Sensor. 107 108 * 108 109 * Get the current temperature returned by the CPU core/package level 109 110 * thermal sensor, in degrees C. 110 111 * 111 - * Return: Temperature in degrees C on success, negative error code otherwise. 112 + * Return: 0 on success, negative error code otherwise. 112 113 */ 113 - int intel_tcc_get_temp(int cpu, bool pkg) 114 + int intel_tcc_get_temp(int cpu, int *temp, bool pkg) 114 115 { 115 116 u32 low, high; 116 117 u32 msr = pkg ? MSR_IA32_PACKAGE_THERM_STATUS : MSR_IA32_THERM_STATUS; 117 - int tjmax, temp, err; 118 + int tjmax, err; 118 119 119 120 tjmax = intel_tcc_get_tjmax(cpu); 120 121 if (tjmax < 0) ··· 132 131 if (!(low & BIT(31))) 133 132 return -ENODATA; 134 133 135 - temp = tjmax - ((low >> 16) & 0x7f); 134 + *temp = tjmax - ((low >> 16) & 0x7f); 136 135 137 - /* Do not allow negative CPU temperature */ 138 - return temp >= 0 ? temp : -ENODATA; 136 + return 0; 139 137 } 140 138 EXPORT_SYMBOL_NS_GPL(intel_tcc_get_temp, INTEL_TCC);
+18 -29
drivers/thermal/intel/x86_pkg_temp_thermal.c
··· 53 53 u32 msr_pkg_therm_high; 54 54 struct delayed_work work; 55 55 struct thermal_zone_device *tzone; 56 - struct thermal_trip *trips; 57 56 struct cpumask cpumask; 58 57 }; 59 58 ··· 107 108 static int sys_get_curr_temp(struct thermal_zone_device *tzd, int *temp) 108 109 { 109 110 struct zone_device *zonedev = thermal_zone_device_priv(tzd); 110 - int val; 111 + int val, ret; 111 112 112 - val = intel_tcc_get_temp(zonedev->cpu, true); 113 - if (val < 0) 114 - return val; 113 + ret = intel_tcc_get_temp(zonedev->cpu, &val, true); 114 + if (ret < 0) 115 + return ret; 115 116 116 117 *temp = val * 1000; 117 118 pr_debug("sys_get_curr_temp %d\n", *temp); ··· 166 167 } 167 168 168 169 /* Thermal zone callback registry */ 169 - static struct thermal_zone_device_ops tzone_ops = { 170 + static const struct thermal_zone_device_ops tzone_ops = { 170 171 .get_temp = sys_get_curr_temp, 171 172 .set_trip_temp = sys_set_trip_temp, 172 173 }; ··· 267 268 return 0; 268 269 } 269 270 270 - static struct thermal_trip *pkg_temp_thermal_trips_init(int cpu, int tj_max, int num_trips) 271 + static int pkg_temp_thermal_trips_init(int cpu, int tj_max, 272 + struct thermal_trip *trips, int num_trips) 271 273 { 272 - struct thermal_trip *trips; 273 274 unsigned long thres_reg_value; 274 275 u32 mask, shift, eax, edx; 275 276 int ret, i; 276 - 277 - trips = kzalloc(sizeof(*trips) * num_trips, GFP_KERNEL); 278 - if (!trips) 279 - return ERR_PTR(-ENOMEM); 280 277 281 278 for (i = 0; i < num_trips; i++) { 282 279 ··· 286 291 287 292 ret = rdmsr_on_cpu(cpu, MSR_IA32_PACKAGE_THERM_INTERRUPT, 288 293 &eax, &edx); 289 - if (ret < 0) { 290 - kfree(trips); 291 - return ERR_PTR(ret); 292 - } 294 + if (ret < 0) 295 + return ret; 293 296 294 297 thres_reg_value = (eax & mask) >> shift; 295 298 ··· 295 302 tj_max - thres_reg_value * 1000 : THERMAL_TEMP_INVALID; 296 303 297 304 trips[i].type = THERMAL_TRIP_PASSIVE; 305 + trips[i].flags |= THERMAL_TRIP_FLAG_RW_TEMP; 298 306 299 307 pr_debug("%s: cpu=%d, trip=%d, temp=%d\n", 300 308 __func__, cpu, i, trips[i].temperature); 301 309 } 302 310 303 - return trips; 311 + return 0; 304 312 } 305 313 306 314 static int pkg_temp_thermal_device_add(unsigned int cpu) 307 315 { 316 + struct thermal_trip trips[MAX_NUMBER_OF_TRIPS] = { 0 }; 308 317 int id = topology_logical_die_id(cpu); 309 318 u32 eax, ebx, ecx, edx; 310 319 struct zone_device *zonedev; ··· 331 336 if (!zonedev) 332 337 return -ENOMEM; 333 338 334 - zonedev->trips = pkg_temp_thermal_trips_init(cpu, tj_max, thres_count); 335 - if (IS_ERR(zonedev->trips)) { 336 - err = PTR_ERR(zonedev->trips); 339 + err = pkg_temp_thermal_trips_init(cpu, tj_max, trips, thres_count); 340 + if (err) 337 341 goto out_kfree_zonedev; 338 - } 339 342 340 343 INIT_DELAYED_WORK(&zonedev->work, pkg_temp_thermal_threshold_work_fn); 341 344 zonedev->cpu = cpu; 342 345 zonedev->tzone = thermal_zone_device_register_with_trips("x86_pkg_temp", 343 - zonedev->trips, thres_count, 344 - (thres_count == MAX_NUMBER_OF_TRIPS) ? 0x03 : 0x01, 346 + trips, thres_count, 345 347 zonedev, &tzone_ops, &pkg_temp_tz_params, 0, 0); 346 348 if (IS_ERR(zonedev->tzone)) { 347 349 err = PTR_ERR(zonedev->tzone); 348 - goto out_kfree_trips; 350 + goto out_kfree_zonedev; 349 351 } 350 352 err = thermal_zone_device_enable(zonedev->tzone); 351 353 if (err) ··· 361 369 362 370 out_unregister_tz: 363 371 thermal_zone_device_unregister(zonedev->tzone); 364 - out_kfree_trips: 365 - kfree(zonedev->trips); 366 372 out_kfree_zonedev: 367 373 kfree(zonedev); 368 374 return err; ··· 447 457 raw_spin_unlock_irq(&pkg_temp_lock); 448 458 449 459 /* Final cleanup if this is the last cpu */ 450 - if (lastcpu) { 451 - kfree(zonedev->trips); 460 + if (lastcpu) 452 461 kfree(zonedev); 453 - } 462 + 454 463 return 0; 455 464 } 456 465
+1 -1
drivers/thermal/rcar_thermal.c
··· 489 489 &rcar_thermal_zone_ops); 490 490 } else { 491 491 priv->zone = thermal_zone_device_register_with_trips( 492 - "rcar_thermal", trips, ARRAY_SIZE(trips), 0, priv, 492 + "rcar_thermal", trips, ARRAY_SIZE(trips), priv, 493 493 &rcar_thermal_zone_ops, NULL, 0, 494 494 idle); 495 495
+1 -1
drivers/thermal/st/st_thermal.c
··· 203 203 trip.type = THERMAL_TRIP_CRITICAL; 204 204 205 205 sensor->thermal_dev = 206 - thermal_zone_device_register_with_trips(dev_name(dev), &trip, 1, 0, sensor, 206 + thermal_zone_device_register_with_trips(dev_name(dev), &trip, 1, sensor, 207 207 &st_tz_ops, NULL, 0, polling_delay); 208 208 if (IS_ERR(sensor->thermal_dev)) { 209 209 dev_err(dev, "failed to register thermal zone device\n");
+30 -46
drivers/thermal/thermal_core.c
··· 273 273 274 274 /* 275 275 * Zone update section: main control loop applied to each zone while monitoring 276 - * 277 276 * in polling mode. The monitoring is done using a workqueue. 278 277 * Same update may be done on a zone by calling thermal_zone_device_update(). 279 278 * ··· 355 356 trace_thermal_zone_trip(tz, thermal_zone_trip_id(tz, trip), trip->type); 356 357 357 358 if (trip->type == THERMAL_TRIP_CRITICAL) 358 - tz->ops->critical(tz); 359 - else if (tz->ops->hot) 360 - tz->ops->hot(tz); 359 + tz->ops.critical(tz); 360 + else if (tz->ops.hot) 361 + tz->ops.hot(tz); 361 362 } 362 363 363 364 static void handle_thermal_trip(struct thermal_zone_device *tz, ··· 492 493 return ret; 493 494 } 494 495 495 - if (tz->ops->change_mode) 496 - ret = tz->ops->change_mode(tz, mode); 496 + if (tz->ops.change_mode) 497 + ret = tz->ops.change_mode(tz, mode); 497 498 498 499 if (!ret) 499 500 tz->mode = mode; ··· 866 867 struct thermal_zone_device *pos = NULL; 867 868 868 869 list_for_each_entry(pos, &thermal_tz_list, node) { 869 - if (pos->ops->bind) { 870 - ret = pos->ops->bind(pos, cdev); 870 + if (pos->ops.bind) { 871 + ret = pos->ops.bind(pos, cdev); 871 872 if (ret) 872 873 print_bind_err_msg(pos, cdev, ret); 873 874 } ··· 1183 1184 1184 1185 /* Unbind all thermal zones associated with 'this' cdev */ 1185 1186 list_for_each_entry(tz, &thermal_tz_list, node) { 1186 - if (tz->ops->unbind) 1187 - tz->ops->unbind(tz, cdev); 1187 + if (tz->ops.unbind) 1188 + tz->ops.unbind(tz, cdev); 1188 1189 } 1189 1190 1190 1191 mutex_unlock(&thermal_list_lock); ··· 1198 1199 int ret; 1199 1200 struct thermal_cooling_device *pos = NULL; 1200 1201 1201 - if (!tz->ops->bind) 1202 + if (!tz->ops.bind) 1202 1203 return; 1203 1204 1204 1205 mutex_lock(&thermal_list_lock); 1205 1206 1206 1207 list_for_each_entry(pos, &thermal_cdev_list, node) { 1207 - ret = tz->ops->bind(tz, pos); 1208 + ret = tz->ops.bind(tz, pos); 1208 1209 if (ret) 1209 1210 print_bind_err_msg(tz, pos, ret); 1210 1211 } ··· 1223 1224 { 1224 1225 int i, ret = -EINVAL; 1225 1226 1226 - if (tz->ops->get_crit_temp) 1227 - return tz->ops->get_crit_temp(tz, temp); 1228 - 1229 - if (!tz->trips) 1230 - return -EINVAL; 1227 + if (tz->ops.get_crit_temp) 1228 + return tz->ops.get_crit_temp(tz, temp); 1231 1229 1232 1230 mutex_lock(&tz->lock); 1233 1231 ··· 1247 1251 * @type: the thermal zone device type 1248 1252 * @trips: a pointer to an array of thermal trips 1249 1253 * @num_trips: the number of trip points the thermal zone support 1250 - * @mask: a bit string indicating the writeablility of trip points 1251 1254 * @devdata: private device data 1252 1255 * @ops: standard thermal zone device callbacks 1253 1256 * @tzp: thermal zone platform parameters ··· 1267 1272 * IS_ERR*() helpers. 1268 1273 */ 1269 1274 struct thermal_zone_device * 1270 - thermal_zone_device_register_with_trips(const char *type, struct thermal_trip *trips, int num_trips, int mask, 1271 - void *devdata, struct thermal_zone_device_ops *ops, 1272 - const struct thermal_zone_params *tzp, int passive_delay, 1273 - int polling_delay) 1275 + thermal_zone_device_register_with_trips(const char *type, 1276 + const struct thermal_trip *trips, 1277 + int num_trips, void *devdata, 1278 + const struct thermal_zone_device_ops *ops, 1279 + const struct thermal_zone_params *tzp, 1280 + int passive_delay, int polling_delay) 1274 1281 { 1275 1282 struct thermal_zone_device *tz; 1276 1283 int id; ··· 1290 1293 return ERR_PTR(-EINVAL); 1291 1294 } 1292 1295 1293 - /* 1294 - * Max trip count can't exceed 31 as the "mask >> num_trips" condition. 1295 - * For example, shifting by 32 will result in compiler warning: 1296 - * warning: right shift count >= width of type [-Wshift-count- overflow] 1297 - * 1298 - * Also "mask >> num_trips" will always be true with 32 bit shift. 1299 - * E.g. mask = 0x80000000 for trip id 31 to be RW. Then 1300 - * mask >> 32 = 0x80000000 1301 - * This will result in failure for the below condition. 1302 - * 1303 - * Check will be true when the bit 31 of the mask is set. 1304 - * 32 bit shift will cause overflow of 4 byte integer. 1305 - */ 1306 - if (num_trips > (BITS_PER_TYPE(int) - 1) || num_trips < 0 || mask >> num_trips) { 1296 + if (num_trips < 0) { 1307 1297 pr_err("Incorrect number of thermal trips\n"); 1308 1298 return ERR_PTR(-EINVAL); 1309 1299 } ··· 1306 1322 if (!thermal_class) 1307 1323 return ERR_PTR(-ENODEV); 1308 1324 1309 - tz = kzalloc(sizeof(*tz), GFP_KERNEL); 1325 + tz = kzalloc(struct_size(tz, trips, num_trips), GFP_KERNEL); 1310 1326 if (!tz) 1311 1327 return ERR_PTR(-ENOMEM); 1312 1328 ··· 1332 1348 tz->id = id; 1333 1349 strscpy(tz->type, type, sizeof(tz->type)); 1334 1350 1335 - if (!ops->critical) 1336 - ops->critical = thermal_zone_device_critical; 1351 + tz->ops = *ops; 1352 + if (!tz->ops.critical) 1353 + tz->ops.critical = thermal_zone_device_critical; 1337 1354 1338 - tz->ops = ops; 1339 1355 tz->device.class = thermal_class; 1340 1356 tz->devdata = devdata; 1341 - tz->trips = trips; 1342 1357 tz->num_trips = num_trips; 1358 + memcpy(tz->trips, trips, num_trips * sizeof(*trips)); 1343 1359 1344 1360 thermal_set_delay_jiffies(&tz->passive_delay_jiffies, passive_delay); 1345 1361 thermal_set_delay_jiffies(&tz->polling_delay_jiffies, polling_delay); 1346 1362 1347 1363 /* sys I/F */ 1348 1364 /* Add nodes that are always present via .groups */ 1349 - result = thermal_zone_create_device_groups(tz, mask); 1365 + result = thermal_zone_create_device_groups(tz); 1350 1366 if (result) 1351 1367 goto remove_id; 1352 1368 ··· 1421 1437 struct thermal_zone_device *thermal_tripless_zone_device_register( 1422 1438 const char *type, 1423 1439 void *devdata, 1424 - struct thermal_zone_device_ops *ops, 1440 + const struct thermal_zone_device_ops *ops, 1425 1441 const struct thermal_zone_params *tzp) 1426 1442 { 1427 - return thermal_zone_device_register_with_trips(type, NULL, 0, 0, devdata, 1443 + return thermal_zone_device_register_with_trips(type, NULL, 0, devdata, 1428 1444 ops, tzp, 0, 0); 1429 1445 } 1430 1446 EXPORT_SYMBOL_GPL(thermal_tripless_zone_device_register); ··· 1483 1499 1484 1500 /* Unbind all cdevs associated with 'this' thermal zone */ 1485 1501 list_for_each_entry(cdev, &thermal_cdev_list, node) 1486 - if (tz->ops->unbind) 1487 - tz->ops->unbind(tz, cdev); 1502 + if (tz->ops.unbind) 1503 + tz->ops.unbind(tz, cdev); 1488 1504 1489 1505 mutex_unlock(&thermal_list_lock); 1490 1506
+1 -1
drivers/thermal/thermal_core.h
··· 131 131 int __thermal_zone_get_temp(struct thermal_zone_device *tz, int *temp); 132 132 133 133 /* sysfs I/F */ 134 - int thermal_zone_create_device_groups(struct thermal_zone_device *, int); 134 + int thermal_zone_create_device_groups(struct thermal_zone_device *tz); 135 135 void thermal_zone_destroy_device_groups(struct thermal_zone_device *); 136 136 void thermal_cooling_device_setup_sysfs(struct thermal_cooling_device *); 137 137 void thermal_cooling_device_destroy_sysfs(struct thermal_cooling_device *cdev);
+5 -5
drivers/thermal/thermal_helpers.c
··· 26 26 { 27 27 enum thermal_trend trend; 28 28 29 - if (tz->emul_temperature || !tz->ops->get_trend || 30 - tz->ops->get_trend(tz, trip, &trend)) { 29 + if (tz->emul_temperature || !tz->ops.get_trend || 30 + tz->ops.get_trend(tz, trip, &trend)) { 31 31 if (tz->temperature > tz->last_temperature) 32 32 trend = THERMAL_TREND_RAISING; 33 33 else if (tz->temperature < tz->last_temperature) ··· 75 75 * temperature and fill @temp. 76 76 * 77 77 * Both tz and tz->ops must be valid pointers when calling this function, 78 - * and the tz->ops->get_temp callback must be provided. 78 + * and the tz->ops.get_temp callback must be provided. 79 79 * The function must be called under tz->lock. 80 80 * 81 81 * Return: On success returns 0, an error code otherwise ··· 88 88 89 89 lockdep_assert_held(&tz->lock); 90 90 91 - ret = tz->ops->get_temp(tz, temp); 91 + ret = tz->ops.get_temp(tz, temp); 92 92 93 93 if (IS_ENABLED(CONFIG_THERMAL_EMULATION) && tz->emul_temperature) { 94 94 for_each_trip(tz, trip) { ··· 132 132 133 133 mutex_lock(&tz->lock); 134 134 135 - if (!tz->ops->get_temp) { 135 + if (!tz->ops.get_temp) { 136 136 ret = -EINVAL; 137 137 goto unlock; 138 138 }
+2 -2
drivers/thermal/thermal_hwmon.c
··· 80 80 81 81 mutex_lock(&tz->lock); 82 82 83 - ret = tz->ops->get_crit_temp(tz, &temperature); 83 + ret = tz->ops.get_crit_temp(tz, &temperature); 84 84 85 85 mutex_unlock(&tz->lock); 86 86 ··· 132 132 static bool thermal_zone_crit_temp_valid(struct thermal_zone_device *tz) 133 133 { 134 134 int temp; 135 - return tz->ops->get_crit_temp && !tz->ops->get_crit_temp(tz, &temp); 135 + return tz->ops.get_crit_temp && !tz->ops.get_crit_temp(tz, &temp); 136 136 } 137 137 138 138 int thermal_add_hwmon_sysfs(struct thermal_zone_device *tz)
+13 -24
drivers/thermal/thermal_of.c
··· 117 117 return ret; 118 118 } 119 119 120 + trip->flags = THERMAL_TRIP_FLAG_RW_TEMP; 121 + 120 122 return 0; 121 123 } 122 124 ··· 440 438 */ 441 439 static void thermal_of_zone_unregister(struct thermal_zone_device *tz) 442 440 { 443 - struct thermal_trip *trips = tz->trips; 444 - struct thermal_zone_device_ops *ops = tz->ops; 445 - 446 441 thermal_zone_device_disable(tz); 447 442 thermal_zone_device_unregister(tz); 448 - kfree(trips); 449 - kfree(ops); 450 443 } 451 444 452 445 /** ··· 467 470 static struct thermal_zone_device *thermal_of_zone_register(struct device_node *sensor, int id, void *data, 468 471 const struct thermal_zone_device_ops *ops) 469 472 { 473 + struct thermal_zone_device_ops of_ops = *ops; 470 474 struct thermal_zone_device *tz; 471 475 struct thermal_trip *trips; 472 476 struct thermal_zone_params tzp = {}; 473 - struct thermal_zone_device_ops *of_ops; 474 477 struct device_node *np; 475 478 const char *action; 476 479 int delay, pdelay; 477 - int ntrips, mask; 480 + int ntrips; 478 481 int ret; 479 - 480 - of_ops = kmemdup(ops, sizeof(*ops), GFP_KERNEL); 481 - if (!of_ops) 482 - return ERR_PTR(-ENOMEM); 483 482 484 483 np = of_thermal_zone_find(sensor, id); 485 484 if (IS_ERR(np)) { 486 485 if (PTR_ERR(np) != -ENODEV) 487 486 pr_err("Failed to find thermal zone for %pOFn id=%d\n", sensor, id); 488 - ret = PTR_ERR(np); 489 - goto out_kfree_of_ops; 487 + return ERR_CAST(np); 490 488 } 491 489 492 490 trips = thermal_of_trips_init(np, &ntrips); 493 491 if (IS_ERR(trips)) { 494 492 pr_err("Failed to find trip points for %pOFn id=%d\n", sensor, id); 495 - ret = PTR_ERR(trips); 496 - goto out_kfree_of_ops; 493 + return ERR_CAST(trips); 497 494 } 498 495 499 496 ret = thermal_of_monitor_init(np, &delay, &pdelay); ··· 498 507 499 508 thermal_of_parameters_init(np, &tzp); 500 509 501 - of_ops->bind = thermal_of_bind; 502 - of_ops->unbind = thermal_of_unbind; 503 - 504 - mask = GENMASK_ULL((ntrips) - 1, 0); 510 + of_ops.bind = thermal_of_bind; 511 + of_ops.unbind = thermal_of_unbind; 505 512 506 513 ret = of_property_read_string(np, "critical-action", &action); 507 514 if (!ret) 508 - if (!of_ops->critical && !strcasecmp(action, "reboot")) 509 - of_ops->critical = thermal_zone_device_critical_reboot; 515 + if (!of_ops.critical && !strcasecmp(action, "reboot")) 516 + of_ops.critical = thermal_zone_device_critical_reboot; 510 517 511 518 tz = thermal_zone_device_register_with_trips(np->name, trips, ntrips, 512 - mask, data, of_ops, &tzp, 519 + data, &of_ops, &tzp, 513 520 pdelay, delay); 514 521 if (IS_ERR(tz)) { 515 522 ret = PTR_ERR(tz); 516 523 pr_err("Failed to register thermal zone %pOFn: %d\n", np, ret); 517 524 goto out_kfree_trips; 518 525 } 526 + 527 + kfree(trips); 519 528 520 529 ret = thermal_zone_device_enable(tz); 521 530 if (ret) { ··· 529 538 530 539 out_kfree_trips: 531 540 kfree(trips); 532 - out_kfree_of_ops: 533 - kfree(of_ops); 534 541 535 542 return ERR_PTR(ret); 536 543 }
+15 -23
drivers/thermal/thermal_sysfs.c
··· 123 123 trip = &tz->trips[trip_id]; 124 124 125 125 if (temp != trip->temperature) { 126 - if (tz->ops->set_trip_temp) { 127 - ret = tz->ops->set_trip_temp(tz, trip_id, temp); 126 + if (tz->ops.set_trip_temp) { 127 + ret = tz->ops.set_trip_temp(tz, trip_id, temp); 128 128 if (ret) 129 129 goto unlock; 130 130 } ··· 136 136 137 137 unlock: 138 138 mutex_unlock(&tz->lock); 139 - 139 + 140 140 return ret ? ret : count; 141 141 } 142 142 ··· 174 174 trip = &tz->trips[trip_id]; 175 175 176 176 if (hyst != trip->hysteresis) { 177 - if (tz->ops->set_trip_hyst) { 178 - ret = tz->ops->set_trip_hyst(tz, trip_id, hyst); 179 - if (ret) 180 - goto unlock; 181 - } 182 - 183 177 trip->hysteresis = hyst; 184 178 185 179 thermal_zone_trip_updated(tz, trip); 186 180 } 187 181 188 - unlock: 189 182 mutex_unlock(&tz->lock); 190 183 191 - return ret ? ret : count; 184 + return count; 192 185 } 193 186 194 187 static ssize_t ··· 243 250 244 251 mutex_lock(&tz->lock); 245 252 246 - if (!tz->ops->set_emul_temp) 253 + if (!tz->ops.set_emul_temp) 247 254 tz->emul_temperature = temperature; 248 255 else 249 - ret = tz->ops->set_emul_temp(tz, temperature); 256 + ret = tz->ops.set_emul_temp(tz, temperature); 250 257 251 258 if (!ret) 252 259 __thermal_zone_device_update(tz, THERMAL_EVENT_UNSPECIFIED); ··· 385 392 /** 386 393 * create_trip_attrs() - create attributes for trip points 387 394 * @tz: the thermal zone device 388 - * @mask: Writeable trip point bitmap. 389 395 * 390 396 * helper function to instantiate sysfs entries for every trip 391 397 * point and its properties of a struct thermal_zone_device. 392 398 * 393 399 * Return: 0 on success, the proper error value otherwise. 394 400 */ 395 - static int create_trip_attrs(struct thermal_zone_device *tz, int mask) 401 + static int create_trip_attrs(struct thermal_zone_device *tz) 396 402 { 403 + const struct thermal_trip *trip; 397 404 struct attribute **attrs; 398 - int indx; 399 405 400 406 /* This function works only for zones with at least one trip */ 401 407 if (tz->num_trips <= 0) ··· 429 437 return -ENOMEM; 430 438 } 431 439 432 - for (indx = 0; indx < tz->num_trips; indx++) { 440 + for_each_trip(tz, trip) { 441 + int indx = thermal_zone_trip_id(tz, trip); 442 + 433 443 /* create trip type attribute */ 434 444 snprintf(tz->trip_type_attrs[indx].name, THERMAL_NAME_LENGTH, 435 445 "trip_point_%d_type", indx); ··· 452 458 tz->trip_temp_attrs[indx].name; 453 459 tz->trip_temp_attrs[indx].attr.attr.mode = S_IRUGO; 454 460 tz->trip_temp_attrs[indx].attr.show = trip_point_temp_show; 455 - if (IS_ENABLED(CONFIG_THERMAL_WRITABLE_TRIPS) && 456 - mask & (1 << indx)) { 461 + if (trip->flags & THERMAL_TRIP_FLAG_RW_TEMP) { 457 462 tz->trip_temp_attrs[indx].attr.attr.mode |= S_IWUSR; 458 463 tz->trip_temp_attrs[indx].attr.store = 459 464 trip_point_temp_store; ··· 467 474 tz->trip_hyst_attrs[indx].name; 468 475 tz->trip_hyst_attrs[indx].attr.attr.mode = S_IRUGO; 469 476 tz->trip_hyst_attrs[indx].attr.show = trip_point_hyst_show; 470 - if (tz->ops->set_trip_hyst) { 477 + if (trip->flags & THERMAL_TRIP_FLAG_RW_HYST) { 471 478 tz->trip_hyst_attrs[indx].attr.attr.mode |= S_IWUSR; 472 479 tz->trip_hyst_attrs[indx].attr.store = 473 480 trip_point_hyst_store; ··· 499 506 kfree(tz->trips_attribute_group.attrs); 500 507 } 501 508 502 - int thermal_zone_create_device_groups(struct thermal_zone_device *tz, 503 - int mask) 509 + int thermal_zone_create_device_groups(struct thermal_zone_device *tz) 504 510 { 505 511 const struct attribute_group **groups; 506 512 int i, size, result; ··· 515 523 groups[i] = thermal_zone_attribute_groups[i]; 516 524 517 525 if (tz->num_trips) { 518 - result = create_trip_attrs(tz, mask); 526 + result = create_trip_attrs(tz); 519 527 if (result) { 520 528 kfree(groups); 521 529
+3 -3
drivers/thermal/thermal_trip.c
··· 70 70 71 71 lockdep_assert_held(&tz->lock); 72 72 73 - if (!tz->ops->set_trips) 73 + if (!tz->ops.set_trips) 74 74 return; 75 75 76 76 for_each_trip(tz, trip) { ··· 114 114 * Set a temperature window. When this window is left the driver 115 115 * must inform the thermal core via thermal_zone_device_update. 116 116 */ 117 - ret = tz->ops->set_trips(tz, low, high); 117 + ret = tz->ops.set_trips(tz, low, high); 118 118 if (ret) 119 119 dev_err(&tz->device, "Failed to set trips: %d\n", ret); 120 120 } ··· 122 122 int __thermal_zone_get_trip(struct thermal_zone_device *tz, int trip_id, 123 123 struct thermal_trip *trip) 124 124 { 125 - if (!tz || !tz->trips || trip_id < 0 || trip_id >= tz->num_trips || !trip) 125 + if (!tz || trip_id < 0 || trip_id >= tz->num_trips || !trip) 126 126 return -EINVAL; 127 127 128 128 *trip = tz->trips[trip_id];
+1 -1
include/linux/intel_tcc.h
··· 13 13 int intel_tcc_get_tjmax(int cpu); 14 14 int intel_tcc_get_offset(int cpu); 15 15 int intel_tcc_set_offset(int cpu, int offset); 16 - int intel_tcc_get_temp(int cpu, bool pkg); 16 + int intel_tcc_get_temp(int cpu, int *temp, bool pkg); 17 17 18 18 #endif /* __INTEL_TCC_H__ */
+21 -16
include/linux/thermal.h
··· 64 64 * @threshold: trip crossing notification threshold miliCelsius 65 65 * @type: trip point type 66 66 * @priv: pointer to driver data associated with this trip 67 + * @flags: flags representing binary properties of the trip 67 68 */ 68 69 struct thermal_trip { 69 70 int temperature; 70 71 int hysteresis; 71 72 int threshold; 72 73 enum thermal_trip_type type; 74 + u8 flags; 73 75 void *priv; 74 76 }; 77 + 78 + #define THERMAL_TRIP_FLAG_RW_TEMP BIT(0) 79 + #define THERMAL_TRIP_FLAG_RW_HYST BIT(1) 80 + 81 + #define THERMAL_TRIP_FLAG_RW (THERMAL_TRIP_FLAG_RW_TEMP | \ 82 + THERMAL_TRIP_FLAG_RW_HYST) 75 83 76 84 struct thermal_zone_device_ops { 77 85 int (*bind) (struct thermal_zone_device *, ··· 91 83 int (*change_mode) (struct thermal_zone_device *, 92 84 enum thermal_device_mode); 93 85 int (*set_trip_temp) (struct thermal_zone_device *, int, int); 94 - int (*set_trip_hyst) (struct thermal_zone_device *, int, int); 95 86 int (*get_crit_temp) (struct thermal_zone_device *, int *); 96 87 int (*set_emul_temp) (struct thermal_zone_device *, int); 97 88 int (*get_trend) (struct thermal_zone_device *, ··· 137 130 * @trip_hyst_attrs: attributes for trip points for sysfs: trip hysteresis 138 131 * @mode: current mode of this thermal zone 139 132 * @devdata: private pointer for device private data 140 - * @trips: an array of struct thermal_trip 141 133 * @num_trips: number of trip points the thermal zone supports 142 134 * @passive_delay_jiffies: number of jiffies to wait between polls when 143 135 * performing passive cooling. ··· 166 160 * @poll_queue: delayed work for polling 167 161 * @notify_event: Last notification event 168 162 * @suspended: thermal zone suspend indicator 163 + * @trips: array of struct thermal_trip objects 169 164 */ 170 165 struct thermal_zone_device { 171 166 int id; ··· 179 172 struct thermal_attr *trip_hyst_attrs; 180 173 enum thermal_device_mode mode; 181 174 void *devdata; 182 - struct thermal_trip *trips; 183 175 int num_trips; 184 176 unsigned long passive_delay_jiffies; 185 177 unsigned long polling_delay_jiffies; ··· 189 183 int prev_low_trip; 190 184 int prev_high_trip; 191 185 atomic_t need_update; 192 - struct thermal_zone_device_ops *ops; 186 + struct thermal_zone_device_ops ops; 193 187 struct thermal_zone_params *tzp; 194 188 struct thermal_governor *governor; 195 189 void *governor_data; ··· 199 193 struct list_head node; 200 194 struct delayed_work poll_queue; 201 195 enum thermal_notify_event notify_event; 196 + bool suspended; 202 197 #ifdef CONFIG_THERMAL_DEBUGFS 203 198 struct thermal_debugfs *debugfs; 204 199 #endif 205 - bool suspended; 200 + struct thermal_trip trips[] __counted_by(num_trips); 206 201 }; 207 202 208 203 /** ··· 221 214 * @governor_list: node in thermal_governor_list (in thermal_core.c) 222 215 */ 223 216 struct thermal_governor { 224 - char name[THERMAL_NAME_LENGTH]; 217 + const char *name; 225 218 int (*bind_to_tz)(struct thermal_zone_device *tz); 226 219 void (*unbind_from_tz)(struct thermal_zone_device *tz); 227 220 int (*throttle)(struct thermal_zone_device *tz, ··· 233 226 234 227 /* Structure to define Thermal Zone parameters */ 235 228 struct thermal_zone_params { 236 - char governor_name[THERMAL_NAME_LENGTH]; 229 + const char *governor_name; 237 230 238 231 /* 239 232 * a boolean to indicate if the thermal to hwmon sysfs interface ··· 322 315 #ifdef CONFIG_THERMAL 323 316 struct thermal_zone_device *thermal_zone_device_register_with_trips( 324 317 const char *type, 325 - struct thermal_trip *trips, 326 - int num_trips, int mask, 327 - void *devdata, 328 - struct thermal_zone_device_ops *ops, 318 + const struct thermal_trip *trips, 319 + int num_trips, void *devdata, 320 + const struct thermal_zone_device_ops *ops, 329 321 const struct thermal_zone_params *tzp, 330 322 int passive_delay, int polling_delay); 331 323 332 324 struct thermal_zone_device *thermal_tripless_zone_device_register( 333 325 const char *type, 334 326 void *devdata, 335 - struct thermal_zone_device_ops *ops, 327 + const struct thermal_zone_device_ops *ops, 336 328 const struct thermal_zone_params *tzp); 337 329 338 330 void thermal_zone_device_unregister(struct thermal_zone_device *tz); ··· 381 375 #else 382 376 static inline struct thermal_zone_device *thermal_zone_device_register_with_trips( 383 377 const char *type, 384 - struct thermal_trip *trips, 385 - int num_trips, int mask, 386 - void *devdata, 387 - struct thermal_zone_device_ops *ops, 378 + const struct thermal_trip *trips, 379 + int num_trips, void *devdata, 380 + const struct thermal_zone_device_ops *ops, 388 381 const struct thermal_zone_params *tzp, 389 382 int passive_delay, int polling_delay) 390 383 { return ERR_PTR(-ENODEV); }