History

Merge tag 'thermal-5.20-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm

Pull thermal control updates from Rafael Wysocki: "These start a rework of the handling of trip points in the thermal core, improve the cpufreq/devfreq cooling device handling, update some thermal control drivers and the tmon utility and clean up code. Specifics: - Consolidate the thermal core code by beginning to move the thermal trip structure from the thermal OF code as a generic structure to be used by the different sensors when registering a thermal zone (Daniel Lezcano). - Make per cpufreq / devfreq cooling device ops instead of using a global variable, fix comments and rework the trace information (Lukasz Luba). - Add the include/dt-bindings/thermal.h under the area covered by the thermal maintainer in the MAINTAINERS file (Lukas Bulwahn). - Improve the error output by giving the sensor identification when a thermal zone failed to initialize, the DT bindings by changing the positive logic and adding the r8a779f0 support on the rcar3 (Wolfram Sang). - Convert the QCom tsens DT binding to the dtsformat format (Krzysztof Kozlowski). - Remove the pointless get_trend() function in the QCom, Ux500 and tegra thermal drivers, along with the unused DROP_FULL and RAISE_FULL trends definitions. Simplify the code by using clamp() macros (Daniel Lezcano). - Fix ref_table memory leak at probe time on the k3_j72xx bandgap (Bryan Brattlof). - Fix array underflow in prep_lookup_table (Dan Carpenter). - Add static annotation to the k3_j72xx_bandgap_j7* data structure (Jin Xiaoyun). - Fix typos in comments detected on sun8i by Coccinelle (Julia Lawall). - Fix typos in comments on rzg2l (Biju Das). - Remove as unnecessary call to dev_err() as the error is already printed by the failing function on u8500 (Yang Li). - Register the thermal zones as hwmon sensors for the Qcom thermal sensors (Dmitry Baryshkov). - Fix 'tmon' tool compilation issue by adding phtread.h include (Markus Mayer). - Fix typo in the comments for the 'tmon' tool (Slark Xiao). - Make the thermal core use ida_alloc()/free() directly instead of ida_simple_get()/ida_simple_remove() that have been deprecated (keliu). - Drop ACPI_FADT_LOW_POWER_S0 check from the Intel PCH thermal control driver (Rafael Wysocki)" * tag 'thermal-5.20-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm: (39 commits) thermal/of: Initialize trip points separately thermal/of: Use thermal trips stored in the thermal zone thermal/core: Add thermal_trip in thermal_zone thermal/core: Rename 'trips' to 'num_trips' thermal/core: Move thermal_set_delay_jiffies to static thermal/core: Remove unneeded EXPORT_SYMBOLS thermal/of: Move thermal_trip structure to thermal.h thermal/of: Remove the device node pointer for thermal_trip thermal/of: Replace device node match with device node search thermal/core: Remove duplicate information when an error occurs thermal/core: Avoid calling ->get_trip_temp() unnecessarily thermal/tools/tmon: Fix typo 'the the' in comment thermal/tools/tmon: Include pthread and time headers in tmon.h thermal/ti-soc-thermal: Fix comment typo thermal/drivers/qcom/spmi-adc-tm5: Register thermal zones as hwmon sensors thermal/drivers/qcom/temp-alarm: Register thermal zones as hwmon sensors thermal/drivers/u8500: Remove unnecessary print function dev_err() thermal/drivers/rzg2l: Fix comments thermal/drivers/sun8i: Fix typo in comment thermal/drivers/k3_j72xx_bandgap: Make k3_j72xx_bandgap_j721e_data and k3_j72xx_bandgap_j7200_data static ...

Linus Torvalds committed 4 years ago

Commit c1dbe9a2 parents a771ea6 da9d01733 files · +397 −448Browse files

Unified · Split

33 files
  1. Documentation/devicetree/bindings/thermal/qcom,spmi-temp-alarm.yaml +85 −0
  2. Documentation/devicetree/bindings/thermal/qcom-spmi-temp-alarm.txt +0 −51
  3. Documentation/devicetree/bindings/thermal/rcar-gen3-thermal.yaml +22 −14
  4. MAINTAINERS +1 −0
  5. drivers/thermal/cpufreq_cooling.c +25 −52
  6. drivers/thermal/db8500_thermal.c +6 −28
  7. drivers/thermal/devfreq_cooling.c +9 −18
  8. drivers/thermal/gov_fair_share.c +3 −3
  9. drivers/thermal/gov_power_allocator.c +2 −2
  10. drivers/thermal/gov_step_wise.c +4 −22
  11. drivers/thermal/intel/intel_pch_thermal.c +0 −8
  12. drivers/thermal/intel/x86_pkg_temp_thermal.c +1 −1
  13. drivers/thermal/k3_j72xx_bandgap.c +7 −6
  14. drivers/thermal/qcom/qcom-spmi-adc-tm5.c +5 −0
  15. drivers/thermal/qcom/qcom-spmi-temp-alarm.c +5 −0
  16. drivers/thermal/qcom/tsens.c +0 −12
  17. drivers/thermal/qcom/tsens.h +0 −2
  18. drivers/thermal/rcar_gen3_thermal.c +2 −2
  19. drivers/thermal/rzg2l_thermal.c +11 −7
  20. drivers/thermal/sun8i_thermal.c +1 −1
  21. drivers/thermal/tegra/soctherm.c +0 −32
  22. drivers/thermal/tegra/tegra30-tsensor.c +1 −1
  23. drivers/thermal/thermal_core.c +47 −32
  24. drivers/thermal/thermal_core.h +0 −15
  25. drivers/thermal/thermal_helpers.c +2 −11
  26. drivers/thermal/thermal_netlink.c +1 −1
  27. drivers/thermal/thermal_of.c +111 −90
  28. drivers/thermal/thermal_sysfs.c +11 −11
  29. drivers/thermal/ti-soc-thermal/ti-bandgap.c +1 −1
  30. include/linux/thermal.h +22 −4
  31. include/trace/events/thermal.h +8 −20
  32. tools/thermal/tmon/pid.c +1 −1
  33. tools/thermal/tmon/tmon.h +3 −0
Documentation/devicetree/bindings/thermal/qcom,spmi-temp-alarm.yaml+85−0
@@ -0,0 +1,85 @@
1# SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause
2%YAML 1.2
3---
4$id: http://devicetree.org/schemas/thermal/qcom,spmi-temp-alarm.yaml#
5$schema: http://devicetree.org/meta-schemas/core.yaml#
6
7title: Qualcomm QPNP PMIC Temperature Alarm
8
9maintainers:
10 - Bjorn Andersson <bjorn.andersson@linaro.org>
11
12description:
13 QPNP temperature alarm peripherals are found inside of Qualcomm PMIC chips
14 that utilize the Qualcomm SPMI implementation. These peripherals provide an
15 interrupt signal and status register to identify high PMIC die temperature.
16
17allOf:
18 - $ref: thermal-sensor.yaml#
19
20properties:
21 compatible:
22 const: qcom,spmi-temp-alarm
23
24 reg:
25 maxItems: 1
26
27 interrupts:
28 maxItems: 1
29
30 io-channels:
31 items:
32 - description: ADC channel, which reports chip die temperature
33
34 io-channel-names:
35 items:
36 - const: thermal
37
38 '#thermal-sensor-cells':
39 const: 0
40
41required:
42 - compatible
43 - reg
44 - interrupts
45 - '#thermal-sensor-cells'
46
47additionalProperties: false
48
49examples:
50 - |
51 #include <dt-bindings/interrupt-controller/arm-gic.h>
52
53 pmic {
54 #address-cells = <1>;
55 #size-cells = <0>;
56
57 pm8350_temp_alarm: temperature-sensor@a00 {
58 compatible = "qcom,spmi-temp-alarm";
59 reg = <0xa00>;
60 interrupts = <0x1 0xa 0x0 IRQ_TYPE_EDGE_BOTH>;
61 #thermal-sensor-cells = <0>;
62 };
63 };
64
65 thermal-zones {
66 pm8350_thermal: pm8350c-thermal {
67 polling-delay-passive = <100>;
68 polling-delay = <0>;
69 thermal-sensors = <&pm8350_temp_alarm>;
70
71 trips {
72 pm8350_trip0: trip0 {
73 temperature = <95000>;
74 hysteresis = <0>;
75 type = "passive";
76 };
77
78 pm8350_crit: pm8350c-crit {
79 temperature = <115000>;
80 hysteresis = <0>;
81 type = "critical";
82 };
83 };
84 };
85 };
Documentation/devicetree/bindings/thermal/qcom-spmi-temp-alarm.txt+0−51
@@ -1,51 +0,0 @@
1Qualcomm QPNP PMIC Temperature Alarm
2
3QPNP temperature alarm peripherals are found inside of Qualcomm PMIC chips
4that utilize the Qualcomm SPMI implementation. These peripherals provide an
5interrupt signal and status register to identify high PMIC die temperature.
6
7Required properties:
8- compatible: Should contain "qcom,spmi-temp-alarm".
9- reg: Specifies the SPMI address.
10- interrupts: PMIC temperature alarm interrupt.
11- #thermal-sensor-cells: Should be 0. See Documentation/devicetree/bindings/thermal/thermal-sensor.yaml for a description.
12
13Optional properties:
14- io-channels: Should contain IIO channel specifier for the ADC channel,
15 which report chip die temperature.
16- io-channel-names: Should contain "thermal".
17
18Example:
19
20 pm8941_temp: thermal-alarm@2400 {
21 compatible = "qcom,spmi-temp-alarm";
22 reg = <0x2400>;
23 interrupts = <0 0x24 0 IRQ_TYPE_EDGE_RISING>;
24 #thermal-sensor-cells = <0>;
25
26 io-channels = <&pm8941_vadc VADC_DIE_TEMP>;
27 io-channel-names = "thermal";
28 };
29
30 thermal-zones {
31 pm8941 {
32 polling-delay-passive = <250>;
33 polling-delay = <1000>;
34
35 thermal-sensors = <&pm8941_temp>;
36
37 trips {
38 stage1 {
39 temperature = <105000>;
40 hysteresis = <2000>;
41 type = "passive";
42 };
43 stage2 {
44 temperature = <125000>;
45 hysteresis = <2000>;
46 type = "critical";
47 };
48 };
49 };
50 };
51
Documentation/devicetree/bindings/thermal/rcar-gen3-thermal.yaml+22−14
@@ -8,9 +8,9 @@ $schema: http://devicetree.org/meta-schemas/core.yaml# · 7 unmodified lines
8title: Renesas R-Car Gen3 Thermal Sensor8title: Renesas R-Car Gen3 Thermal Sensor
9 9
10description:10description:
11 On R-Car Gen3 SoCs, the thermal sensor controllers (TSC) control the thermal11 On most R-Car Gen3 and later SoCs, the thermal sensor controllers (TSC)
12 sensors (THS) which are the analog circuits for measuring temperature (Tj)12 control the thermal sensors (THS) which are the analog circuits for
13 inside the LSI.13 measuring temperature (Tj) inside the LSI.
14 14
15maintainers:15maintainers:
16 - Niklas Söderlund <niklas.soderlund@ragnatech.se>16 - Niklas Söderlund <niklas.soderlund@ragnatech.se>
@@ -27,6 +27,7 @@ properties: · 10 unmodified lines
27 - renesas,r8a77965-thermal # R-Car M3-N27 - renesas,r8a77965-thermal # R-Car M3-N
28 - renesas,r8a77980-thermal # R-Car V3H28 - renesas,r8a77980-thermal # R-Car V3H
29 - renesas,r8a779a0-thermal # R-Car V3U29 - renesas,r8a779a0-thermal # R-Car V3U
30 - renesas,r8a779f0-thermal # R-Car S4-8
30 31
31 reg: true32 reg: true
32 33
@@ -57,31 +58,38 @@ required: · 24 unmodified lines
57 - "#thermal-sensor-cells"58 - "#thermal-sensor-cells"
58 59
59if:60if:
60 not:61 properties:
61 properties:62 compatible:
62 compatible:63 contains:
63 contains:64 enum:
64 enum:65 - renesas,r8a779a0-thermal
65 - renesas,r8a779a0-thermal
66then:66then:
67 properties:67 properties:
68 reg:68 reg:
69 minItems: 2
70 items:69 items:
70 - description: TSC0 registers
71 - description: TSC1 registers71 - description: TSC1 registers
72 - description: TSC2 registers72 - description: TSC2 registers
73 - description: TSC3 registers73 - description: TSC3 registers
74 required:74 - description: TSC4 registers
75 - interrupts
76else:75else:
77 properties:76 properties:
78 reg:77 reg:
78 minItems: 2
79 items:79 items:
80 - description: TSC0 registers
81 - description: TSC1 registers80 - description: TSC1 registers
82 - description: TSC2 registers81 - description: TSC2 registers
83 - description: TSC3 registers82 - description: TSC3 registers
84 - description: TSC4 registers83 if:
84 not:
85 properties:
86 compatible:
87 contains:
88 enum:
89 - renesas,r8a779f0-thermal
90 then:
91 required:
92 - interrupts
85 93
86additionalProperties: false94additionalProperties: false
87 95
MAINTAINERS+1−0
@@ -19949,6 +19949,7 @@ F: Documentation/ABI/testing/sysfs-class-thermal · 19948 unmodified lines
19949F: Documentation/devicetree/bindings/thermal/19949F: Documentation/devicetree/bindings/thermal/
19950F: Documentation/driver-api/thermal/19950F: Documentation/driver-api/thermal/
19951F: drivers/thermal/19951F: drivers/thermal/
19952F: include/dt-bindings/thermal/
19952F: include/linux/cpu_cooling.h19953F: include/linux/cpu_cooling.h
19953F: include/linux/thermal.h19954F: include/linux/thermal.h
19954F: include/uapi/linux/thermal.h19955F: include/uapi/linux/thermal.h
drivers/thermal/cpufreq_cooling.c+25−52
@@ -60,6 +60,7 @@ struct time_in_idle { · 59 unmodified lines
60 * @cdev: thermal_cooling_device pointer to keep track of the60 * @cdev: thermal_cooling_device pointer to keep track of the
61 * registered cooling device.61 * registered cooling device.
62 * @policy: cpufreq policy.62 * @policy: cpufreq policy.
63 * @cooling_ops: cpufreq callbacks to thermal cooling device ops
63 * @idle_time: idle time stats64 * @idle_time: idle time stats
64 * @qos_req: PM QoS contraint to apply65 * @qos_req: PM QoS contraint to apply
65 *66 *
@@ -72,6 +73,7 @@ struct cpufreq_cooling_device { · 6 unmodified lines
72 unsigned int max_level;73 unsigned int max_level;
73 struct em_perf_domain *em;74 struct em_perf_domain *em;
74 struct cpufreq_policy *policy;75 struct cpufreq_policy *policy;
76 struct thermal_cooling_device_ops cooling_ops;
75#ifndef CONFIG_SMP77#ifndef CONFIG_SMP
76 struct time_in_idle *idle_time;78 struct time_in_idle *idle_time;
77#endif79#endif
@@ -211,7 +213,7 @@ static u32 get_dynamic_power(struct cpufreq_cooling_device *cpufreq_cdev, · 133 unmodified lines
211 * complex code may be needed if experiments show that it's not213 * complex code may be needed if experiments show that it's not
212 * accurate enough.214 * accurate enough.
213 *215 *
214 * Return: 0 on success, -E* if getting the static power failed.216 * Return: 0 on success, this function doesn't fail.
215 */217 */
216static int cpufreq_get_requested_power(struct thermal_cooling_device *cdev,218static int cpufreq_get_requested_power(struct thermal_cooling_device *cdev,
217 u32 *power)219 u32 *power)
@@ -221,16 +223,9 @@ static int cpufreq_get_requested_power(struct thermal_cooling_device *cdev, · 3 unmodified lines
221 u32 total_load = 0;223 u32 total_load = 0;
222 struct cpufreq_cooling_device *cpufreq_cdev = cdev->devdata;224 struct cpufreq_cooling_device *cpufreq_cdev = cdev->devdata;
223 struct cpufreq_policy *policy = cpufreq_cdev->policy;225 struct cpufreq_policy *policy = cpufreq_cdev->policy;
224 u32 *load_cpu = NULL;
225 226
226 freq = cpufreq_quick_get(policy->cpu);227 freq = cpufreq_quick_get(policy->cpu);
227 228
228 if (trace_thermal_power_cpu_get_power_enabled()) {
229 u32 ncpus = cpumask_weight(policy->related_cpus);
230
231 load_cpu = kcalloc(ncpus, sizeof(*load_cpu), GFP_KERNEL);
232 }
233
234 for_each_cpu(cpu, policy->related_cpus) {229 for_each_cpu(cpu, policy->related_cpus) {
235 u32 load;230 u32 load;
236 231
@@ -240,22 +235,13 @@ static int cpufreq_get_requested_power(struct thermal_cooling_device *cdev, · 3 unmodified lines
240 load = 0;235 load = 0;
241 236
242 total_load += load;237 total_load += load;
243 if (load_cpu)
244 load_cpu[i] = load;
245
246 i++;
247 }238 }
248 239
249 cpufreq_cdev->last_load = total_load;240 cpufreq_cdev->last_load = total_load;
250 241
251 *power = get_dynamic_power(cpufreq_cdev, freq);242 *power = get_dynamic_power(cpufreq_cdev, freq);
252 243
253 if (load_cpu) {244 trace_thermal_power_cpu_get_power_simple(policy->cpu, *power);
254 trace_thermal_power_cpu_get_power(policy->related_cpus, freq,
255 load_cpu, i, *power);
256
257 kfree(load_cpu);
258 }
259 245
260 return 0;246 return 0;
261}247}
@@ -270,9 +256,8 @@ static int cpufreq_get_requested_power(struct thermal_cooling_device *cdev, · 8 unmodified lines
270 * milliwatts assuming 100% load. Store the calculated power in256 * milliwatts assuming 100% load. Store the calculated power in
271 * @power.257 * @power.
272 *258 *
273 * Return: 0 on success, -EINVAL if the cooling device state could not259 * Return: 0 on success, -EINVAL if the cooling device state is bigger
274 * be converted into a frequency or other -E* if there was an error260 * than maximum allowed.
275 * when calculating the static power.
276 */261 */
277static int cpufreq_state2power(struct thermal_cooling_device *cdev,262static int cpufreq_state2power(struct thermal_cooling_device *cdev,
278 unsigned long state, u32 *power)263 unsigned long state, u32 *power)
@@ -302,15 +287,11 @@ static int cpufreq_state2power(struct thermal_cooling_device *cdev, · 23 unmodified lines
302 * Calculate a cooling device state for the cpus described by @cdev287 * Calculate a cooling device state for the cpus described by @cdev
303 * that would allow them to consume at most @power mW and store it in288 * that would allow them to consume at most @power mW and store it in
304 * @state. Note that this calculation depends on external factors289 * @state. Note that this calculation depends on external factors
305 * such as the cpu load or the current static power. Calling this290 * such as the CPUs load. Calling this function with the same power
306 * function with the same power as input can yield different cooling291 * as input can yield different cooling device states depending on those
307 * device states depending on those external factors.292 * external factors.
308 *293 *
309 * Return: 0 on success, -ENODEV if no cpus are online or -EINVAL if294 * Return: 0 on success, this function doesn't fail.
310 * the calculated frequency could not be converted to a valid state.
311 * The latter should not happen unless the frequencies available to
312 * cpufreq have changed since the initialization of the cpu cooling
313 * device.
314 */295 */
315static int cpufreq_power2state(struct thermal_cooling_device *cdev,296static int cpufreq_power2state(struct thermal_cooling_device *cdev,
316 u32 power, unsigned long *state)297 u32 power, unsigned long *state)
@@ -422,7 +403,7 @@ static unsigned int get_state_freq(struct cpufreq_cooling_device *cpufreq_cdev, · 105 unmodified lines
422 * Callback for the thermal cooling device to return the cpufreq403 * Callback for the thermal cooling device to return the cpufreq
423 * max cooling state.404 * max cooling state.
424 *405 *
425 * Return: 0 on success, an error code otherwise.406 * Return: 0 on success, this function doesn't fail.
426 */407 */
427static int cpufreq_get_max_state(struct thermal_cooling_device *cdev,408static int cpufreq_get_max_state(struct thermal_cooling_device *cdev,
428 unsigned long *state)409 unsigned long *state)
@@ -441,7 +422,7 @@ static int cpufreq_get_max_state(struct thermal_cooling_device *cdev, · 12 unmodified lines
441 * Callback for the thermal cooling device to return the cpufreq422 * Callback for the thermal cooling device to return the cpufreq
442 * current cooling state.423 * current cooling state.
443 *424 *
444 * Return: 0 on success, an error code otherwise.425 * Return: 0 on success, this function doesn't fail.
445 */426 */
446static int cpufreq_get_cur_state(struct thermal_cooling_device *cdev,427static int cpufreq_get_cur_state(struct thermal_cooling_device *cdev,
447 unsigned long *state)428 unsigned long *state)
@@ -492,14 +473,6 @@ static int cpufreq_set_cur_state(struct thermal_cooling_device *cdev, · 44 unmodified lines
492 return ret;473 return ret;
493}474}
494 475
495/* Bind cpufreq callbacks to thermal cooling device ops */
496
497static struct thermal_cooling_device_ops cpufreq_cooling_ops = {
498 .get_max_state = cpufreq_get_max_state,
499 .get_cur_state = cpufreq_get_cur_state,
500 .set_cur_state = cpufreq_set_cur_state,
501};
502
503/**476/**
504 * __cpufreq_cooling_register - helper function to create cpufreq cooling device477 * __cpufreq_cooling_register - helper function to create cpufreq cooling device
505 * @np: a valid struct device_node to the cooling device device tree node478 * @np: a valid struct device_node to the cooling device device tree node
@@ -508,7 +481,7 @@ static struct thermal_cooling_device_ops cpufreq_cooling_ops = { · 2 unmodified lines
508 * @em: Energy Model of the cpufreq policy481 * @em: Energy Model of the cpufreq policy
509 *482 *
510 * This interface function registers the cpufreq cooling device with the name483 * This interface function registers the cpufreq cooling device with the name
511 * "thermal-cpufreq-%x". This api can support multiple instances of cpufreq484 * "cpufreq-%s". This API can support multiple instances of cpufreq
512 * cooling devices. It also gives the opportunity to link the cooling device485 * cooling devices. It also gives the opportunity to link the cooling device
513 * with a device tree node, in order to bind it via the thermal DT code.486 * with a device tree node, in order to bind it via the thermal DT code.
514 *487 *
@@ -561,7 +534,10 @@ __cpufreq_cooling_register(struct device_node *np, · 46 unmodified lines
561 /* max_level is an index, not a counter */534 /* max_level is an index, not a counter */
562 cpufreq_cdev->max_level = i - 1;535 cpufreq_cdev->max_level = i - 1;
563 536
564 cooling_ops = &cpufreq_cooling_ops;537 cooling_ops = &cpufreq_cdev->cooling_ops;
538 cooling_ops->get_max_state = cpufreq_get_max_state;
539 cooling_ops->get_cur_state = cpufreq_get_cur_state;
540 cooling_ops->set_cur_state = cpufreq_set_cur_state;
565 541
566#ifdef CONFIG_THERMAL_GOV_POWER_ALLOCATOR542#ifdef CONFIG_THERMAL_GOV_POWER_ALLOCATOR
567 if (em_is_sane(cpufreq_cdev, em)) {543 if (em_is_sane(cpufreq_cdev, em)) {
@@ -616,8 +592,8 @@ free_cdev: · 48 unmodified lines
616 * @policy: cpufreq policy592 * @policy: cpufreq policy
617 *593 *
618 * This interface function registers the cpufreq cooling device with the name594 * This interface function registers the cpufreq cooling device with the name
619 * "thermal-cpufreq-%x". This api can support multiple instances of cpufreq595 * "cpufreq-%s". This API can support multiple instances of cpufreq cooling
620 * cooling devices.596 * devices.
621 *597 *
622 * Return: a valid struct thermal_cooling_device pointer on success,598 * Return: a valid struct thermal_cooling_device pointer on success,
623 * on failure, it returns a corresponding ERR_PTR().599 * on failure, it returns a corresponding ERR_PTR().
@@ -634,17 +610,14 @@ EXPORT_SYMBOL_GPL(cpufreq_cooling_register); · 10 unmodified lines
634 * @policy: cpufreq policy610 * @policy: cpufreq policy
635 *611 *
636 * This interface function registers the cpufreq cooling device with the name612 * This interface function registers the cpufreq cooling device with the name
637 * "thermal-cpufreq-%x". This api can support multiple instances of cpufreq613 * "cpufreq-%s". This API can support multiple instances of cpufreq cooling
638 * cooling devices. Using this API, the cpufreq cooling device will be614 * devices. Using this API, the cpufreq cooling device will be linked to the
639 * linked to the device tree node provided.615 * device tree node provided.
640 *616 *
641 * Using this function, the cooling device will implement the power617 * Using this function, the cooling device will implement the power
642 * extensions by using a simple cpu power model. The cpus must have618 * extensions by using the Energy Model (if present). The cpus must have
643 * registered their OPPs using the OPP library.619 * registered their OPPs using the OPP library.
644 *620 *
645 * It also takes into account, if property present in policy CPU node, the
646 * static power consumed by the cpu.
647 *
648 * Return: a valid struct thermal_cooling_device pointer on success,621 * Return: a valid struct thermal_cooling_device pointer on success,
649 * and NULL on failure.622 * and NULL on failure.
650 */623 */
@@ -680,7 +653,7 @@ EXPORT_SYMBOL_GPL(of_cpufreq_cooling_register); · 29 unmodified lines
680 * cpufreq_cooling_unregister - function to remove cpufreq cooling device.653 * cpufreq_cooling_unregister - function to remove cpufreq cooling device.
681 * @cdev: thermal cooling device pointer.654 * @cdev: thermal cooling device pointer.
682 *655 *
683 * This interface function unregisters the "thermal-cpufreq-%x" cooling device.656 * This interface function unregisters the "cpufreq-%x" cooling device.
684 */657 */
685void cpufreq_cooling_unregister(struct thermal_cooling_device *cdev)658void cpufreq_cooling_unregister(struct thermal_cooling_device *cdev)
686{659{
drivers/thermal/db8500_thermal.c+6−28
@@ -53,7 +53,6 @@ static const unsigned long db8500_thermal_points[] = { · 52 unmodified lines
53 53
54struct db8500_thermal_zone {54struct db8500_thermal_zone {
55 struct thermal_zone_device *tz;55 struct thermal_zone_device *tz;
56 enum thermal_trend trend;
57 unsigned long interpolated_temp;56 unsigned long interpolated_temp;
58 unsigned int cur_index;57 unsigned int cur_index;
59};58};
@@ -73,24 +72,12 @@ static int db8500_thermal_get_temp(void *data, int *temp) · 13 unmodified lines
73 return 0;72 return 0;
74}73}
75 74
76/* Callback to get temperature changing trend */
77static int db8500_thermal_get_trend(void *data, int trip, enum thermal_trend *trend)
78{
79 struct db8500_thermal_zone *th = data;
80
81 *trend = th->trend;
82
83 return 0;
84}
85
86static struct thermal_zone_of_device_ops thdev_ops = {75static struct thermal_zone_of_device_ops thdev_ops = {
87 .get_temp = db8500_thermal_get_temp,76 .get_temp = db8500_thermal_get_temp,
88 .get_trend = db8500_thermal_get_trend,
89};77};
90 78
91static void db8500_thermal_update_config(struct db8500_thermal_zone *th,79static void db8500_thermal_update_config(struct db8500_thermal_zone *th,
92 unsigned int idx,80 unsigned int idx,
93 enum thermal_trend trend,
94 unsigned long next_low,81 unsigned long next_low,
95 unsigned long next_high)82 unsigned long next_high)
96{83{
@@ -98,7 +85,6 @@ static void db8500_thermal_update_config(struct db8500_thermal_zone *th, · 1 unmodified line
98 85
99 th->cur_index = idx;86 th->cur_index = idx;
100 th->interpolated_temp = (next_low + next_high)/2;87 th->interpolated_temp = (next_low + next_high)/2;
101 th->trend = trend;
102 88
103 /*89 /*
104 * The PRCMU accept absolute temperatures in celsius so divide90 * The PRCMU accept absolute temperatures in celsius so divide
@@ -127,8 +113,7 @@ static irqreturn_t prcmu_low_irq_handler(int irq, void *irq_data) · 22 unmodified lines
127 }113 }
128 idx -= 1;114 idx -= 1;
129 115
130 db8500_thermal_update_config(th, idx, THERMAL_TREND_DROPPING,116 db8500_thermal_update_config(th, idx, next_low, next_high);
131 next_low, next_high);
132 dev_dbg(&th->tz->device,117 dev_dbg(&th->tz->device,
133 "PRCMU set max %ld, min %ld\n", next_high, next_low);118 "PRCMU set max %ld, min %ld\n", next_high, next_low);
134 119
@@ -149,8 +134,7 @@ static irqreturn_t prcmu_high_irq_handler(int irq, void *irq_data) · 14 unmodified lines
149 next_low = db8500_thermal_points[idx];134 next_low = db8500_thermal_points[idx];
150 idx += 1;135 idx += 1;
151 136
152 db8500_thermal_update_config(th, idx, THERMAL_TREND_RAISING,137 db8500_thermal_update_config(th, idx, next_low, next_high);
153 next_low, next_high);
154 138
155 dev_dbg(&th->tz->device,139 dev_dbg(&th->tz->device,
156 "PRCMU set max %ld, min %ld\n", next_high, next_low);140 "PRCMU set max %ld, min %ld\n", next_high, next_low);
@@ -174,10 +158,8 @@ static int db8500_thermal_probe(struct platform_device *pdev) · 17 unmodified lines
174 return -ENOMEM;158 return -ENOMEM;
175 159
176 low_irq = platform_get_irq_byname(pdev, "IRQ_HOTMON_LOW");160 low_irq = platform_get_irq_byname(pdev, "IRQ_HOTMON_LOW");
177 if (low_irq < 0) {161 if (low_irq < 0)
178 dev_err(dev, "Get IRQ_HOTMON_LOW failed\n");
179 return low_irq;162 return low_irq;
180 }
181 163
182 ret = devm_request_threaded_irq(dev, low_irq, NULL,164 ret = devm_request_threaded_irq(dev, low_irq, NULL,
183 prcmu_low_irq_handler, IRQF_NO_SUSPEND | IRQF_ONESHOT,165 prcmu_low_irq_handler, IRQF_NO_SUSPEND | IRQF_ONESHOT,
@@ -188,10 +170,8 @@ static int db8500_thermal_probe(struct platform_device *pdev) · 4 unmodified lines
188 }170 }
189 171
190 high_irq = platform_get_irq_byname(pdev, "IRQ_HOTMON_HIGH");172 high_irq = platform_get_irq_byname(pdev, "IRQ_HOTMON_HIGH");
191 if (high_irq < 0) {173 if (high_irq < 0)
192 dev_err(dev, "Get IRQ_HOTMON_HIGH failed\n");
193 return high_irq;174 return high_irq;
194 }
195 175
196 ret = devm_request_threaded_irq(dev, high_irq, NULL,176 ret = devm_request_threaded_irq(dev, high_irq, NULL,
197 prcmu_high_irq_handler, IRQF_NO_SUSPEND | IRQF_ONESHOT,177 prcmu_high_irq_handler, IRQF_NO_SUSPEND | IRQF_ONESHOT,
@@ -210,8 +190,7 @@ static int db8500_thermal_probe(struct platform_device *pdev) · 12 unmodified lines
210 dev_info(dev, "thermal zone sensor registered\n");190 dev_info(dev, "thermal zone sensor registered\n");
211 191
212 /* Start measuring at the lowest point */192 /* Start measuring at the lowest point */
213 db8500_thermal_update_config(th, 0, THERMAL_TREND_STABLE,193 db8500_thermal_update_config(th, 0, PRCMU_DEFAULT_LOW_TEMP,
214 PRCMU_DEFAULT_LOW_TEMP,
215 db8500_thermal_points[0]);194 db8500_thermal_points[0]);
216 195
217 platform_set_drvdata(pdev, th);196 platform_set_drvdata(pdev, th);
@@ -232,8 +211,7 @@ static int db8500_thermal_resume(struct platform_device *pdev) · 14 unmodified lines
232 struct db8500_thermal_zone *th = platform_get_drvdata(pdev);211 struct db8500_thermal_zone *th = platform_get_drvdata(pdev);
233 212
234 /* Resume and start measuring at the lowest point */213 /* Resume and start measuring at the lowest point */
235 db8500_thermal_update_config(th, 0, THERMAL_TREND_STABLE,214 db8500_thermal_update_config(th, 0, PRCMU_DEFAULT_LOW_TEMP,
236 PRCMU_DEFAULT_LOW_TEMP,
237 db8500_thermal_points[0]);215 db8500_thermal_points[0]);
238 216
239 return 0;217 return 0;
drivers/thermal/devfreq_cooling.c+9−18
@@ -28,6 +28,7 @@ · 27 unmodified lines
28 * struct devfreq_cooling_device - Devfreq cooling device28 * struct devfreq_cooling_device - Devfreq cooling device
29 * devfreq_cooling_device registered.29 * devfreq_cooling_device registered.
30 * @cdev: Pointer to associated thermal cooling device.30 * @cdev: Pointer to associated thermal cooling device.
31 * @cooling_ops: devfreq callbacks to thermal cooling device ops
31 * @devfreq: Pointer to associated devfreq device.32 * @devfreq: Pointer to associated devfreq device.
32 * @cooling_state: Current cooling state.33 * @cooling_state: Current cooling state.
33 * @freq_table: Pointer to a table with the frequencies sorted in descending34 * @freq_table: Pointer to a table with the frequencies sorted in descending
@@ -48,6 +49,7 @@ · 14 unmodified lines
48 */49 */
49struct devfreq_cooling_device {50struct devfreq_cooling_device {
50 struct thermal_cooling_device *cdev;51 struct thermal_cooling_device *cdev;
52 struct thermal_cooling_device_ops cooling_ops;
51 struct devfreq *devfreq;53 struct devfreq *devfreq;
52 unsigned long cooling_state;54 unsigned long cooling_state;
53 u32 *freq_table;55 u32 *freq_table;
@@ -301,12 +303,6 @@ static int devfreq_cooling_power2state(struct thermal_cooling_device *cdev, · 247 unmodified lines
301 return 0;303 return 0;
302}304}
303 305
304static struct thermal_cooling_device_ops devfreq_cooling_ops = {
305 .get_max_state = devfreq_cooling_get_max_state,
306 .get_cur_state = devfreq_cooling_get_cur_state,
307 .set_cur_state = devfreq_cooling_set_cur_state,
308};
309
310/**306/**
311 * devfreq_cooling_gen_tables() - Generate frequency table.307 * devfreq_cooling_gen_tables() - Generate frequency table.
312 * @dfc: Pointer to devfreq cooling device.308 * @dfc: Pointer to devfreq cooling device.
@@ -374,18 +370,18 @@ of_devfreq_cooling_register_power(struct device_node *np, struct devfreq *df, · 61 unmodified lines
374 char *name;370 char *name;
375 int err, num_opps;371 int err, num_opps;
376 372
377 ops = kmemdup(&devfreq_cooling_ops, sizeof(*ops), GFP_KERNEL);
378 if (!ops)
379 return ERR_PTR(-ENOMEM);
380 373
381 dfc = kzalloc(sizeof(*dfc), GFP_KERNEL);374 dfc = kzalloc(sizeof(*dfc), GFP_KERNEL);
382 if (!dfc) {375 if (!dfc)
383 err = -ENOMEM;376 return ERR_PTR(-ENOMEM);
384 goto free_ops;
385 }
386 377
387 dfc->devfreq = df;378 dfc->devfreq = df;
388 379
380 ops = &dfc->cooling_ops;
381 ops->get_max_state = devfreq_cooling_get_max_state;
382 ops->get_cur_state = devfreq_cooling_get_cur_state;
383 ops->set_cur_state = devfreq_cooling_set_cur_state;
384
389 em = em_pd_get(dev);385 em = em_pd_get(dev);
390 if (em && !em_is_artificial(em)) {386 if (em && !em_is_artificial(em)) {
391 dfc->em_pd = em;387 dfc->em_pd = em;
@@ -448,8 +444,6 @@ free_table: · 56 unmodified lines
448 kfree(dfc->freq_table);444 kfree(dfc->freq_table);
449free_dfc:445free_dfc:
450 kfree(dfc);446 kfree(dfc);
451free_ops:
452 kfree(ops);
453 447
454 return ERR_PTR(err);448 return ERR_PTR(err);
455}449}
@@ -531,13 +525,11 @@ EXPORT_SYMBOL_GPL(devfreq_cooling_em_register); · 75 unmodified lines
531void devfreq_cooling_unregister(struct thermal_cooling_device *cdev)525void devfreq_cooling_unregister(struct thermal_cooling_device *cdev)
532{526{
533 struct devfreq_cooling_device *dfc;527 struct devfreq_cooling_device *dfc;
534 const struct thermal_cooling_device_ops *ops;
535 struct device *dev;528 struct device *dev;
536 529
537 if (IS_ERR_OR_NULL(cdev))530 if (IS_ERR_OR_NULL(cdev))
538 return;531 return;
539 532
540 ops = cdev->ops;
541 dfc = cdev->devdata;533 dfc = cdev->devdata;
542 dev = dfc->devfreq->dev.parent;534 dev = dfc->devfreq->dev.parent;
543 535
@@ -548,6 +540,5 @@ void devfreq_cooling_unregister(struct thermal_cooling_device *cdev) · 4 unmodified lines
548 540
549 kfree(dfc->freq_table);541 kfree(dfc->freq_table);
550 kfree(dfc);542 kfree(dfc);
551 kfree(ops);
552}543}
553EXPORT_SYMBOL_GPL(devfreq_cooling_unregister);544EXPORT_SYMBOL_GPL(devfreq_cooling_unregister);
drivers/thermal/gov_fair_share.c+3−3
@@ -25,10 +25,10 @@ static int get_trip_level(struct thermal_zone_device *tz) · 24 unmodified lines
25 int trip_temp;25 int trip_temp;
26 enum thermal_trip_type trip_type;26 enum thermal_trip_type trip_type;
27 27
28 if (tz->trips == 0 || !tz->ops->get_trip_temp)28 if (tz->num_trips == 0 || !tz->ops->get_trip_temp)
29 return 0;29 return 0;
30 30
31 for (count = 0; count < tz->trips; count++) {31 for (count = 0; count < tz->num_trips; count++) {
32 tz->ops->get_trip_temp(tz, count, &trip_temp);32 tz->ops->get_trip_temp(tz, count, &trip_temp);
33 if (tz->temperature < trip_temp)33 if (tz->temperature < trip_temp)
34 break;34 break;
@@ -53,7 +53,7 @@ static long get_target_state(struct thermal_zone_device *tz, · 18 unmodified lines
53 53
54 cdev->ops->get_max_state(cdev, &max_state);54 cdev->ops->get_max_state(cdev, &max_state);
55 55
56 return (long)(percentage * level * max_state) / (100 * tz->trips);56 return (long)(percentage * level * max_state) / (100 * tz->num_trips);
57}57}
58 58
59/**59/**
drivers/thermal/gov_power_allocator.c+2−2
@@ -527,7 +527,7 @@ static void get_governor_trips(struct thermal_zone_device *tz, · 526 unmodified lines
527 last_active = INVALID_TRIP;527 last_active = INVALID_TRIP;
528 last_passive = INVALID_TRIP;528 last_passive = INVALID_TRIP;
529 529
530 for (i = 0; i < tz->trips; i++) {530 for (i = 0; i < tz->num_trips; i++) {
531 enum thermal_trip_type type;531 enum thermal_trip_type type;
532 int ret;532 int ret;
533 533
@@ -668,7 +668,7 @@ static int power_allocator_bind(struct thermal_zone_device *tz) · 134 unmodified lines
668 668
669 get_governor_trips(tz, params);669 get_governor_trips(tz, params);
670 670
671 if (tz->trips > 0) {671 if (tz->num_trips > 0) {
672 ret = tz->ops->get_trip_temp(tz,672 ret = tz->ops->get_trip_temp(tz,
673 params->trip_max_desired_temperature,673 params->trip_max_desired_temperature,
674 &control_temp);674 &control_temp);
drivers/thermal/gov_step_wise.c+4−22
@@ -11,6 +11,7 @@ · 10 unmodified lines
11 */11 */
12 12
13#include <linux/thermal.h>13#include <linux/thermal.h>
14#include <linux/minmax.h>
14#include <trace/events/thermal.h>15#include <trace/events/thermal.h>
15 16
16#include "thermal_core.h"17#include "thermal_core.h"
@@ -52,10 +53,7 @@ static unsigned long get_target_state(struct thermal_instance *instance, · 35 unmodified lines
52 53
53 if (!instance->initialized) {54 if (!instance->initialized) {
54 if (throttle) {55 if (throttle) {
55 next_target = (cur_state + 1) >= instance->upper ?56 next_target = clamp((cur_state + 1), instance->lower, instance->upper);
56 instance->upper :
57 ((cur_state + 1) < instance->lower ?
58 instance->lower : (cur_state + 1));
59 } else {57 } else {
60 next_target = THERMAL_NO_TARGET;58 next_target = THERMAL_NO_TARGET;
61 }59 }
@@ -66,35 +64,19 @@ static unsigned long get_target_state(struct thermal_instance *instance, · 4 unmodified lines
66 switch (trend) {64 switch (trend) {
67 case THERMAL_TREND_RAISING:65 case THERMAL_TREND_RAISING:
68 if (throttle) {66 if (throttle) {
69 next_target = cur_state < instance->upper ?67 next_target = clamp((cur_state + 1), instance->lower, instance->upper);
70 (cur_state + 1) : instance->upper;
71 if (next_target < instance->lower)
72 next_target = instance->lower;
73 }68 }
74 break;69 break;
75 case THERMAL_TREND_RAISE_FULL:
76 if (throttle)
77 next_target = instance->upper;
78 break;
79 case THERMAL_TREND_DROPPING:70 case THERMAL_TREND_DROPPING:
80 if (cur_state <= instance->lower) {71 if (cur_state <= instance->lower) {
81 if (!throttle)72 if (!throttle)
82 next_target = THERMAL_NO_TARGET;73 next_target = THERMAL_NO_TARGET;
83 } else {74 } else {
84 if (!throttle) {75 if (!throttle) {
85 next_target = cur_state - 1;76 next_target = clamp((cur_state - 1), instance->lower, instance->upper);
86 if (next_target > instance->upper)
87 next_target = instance->upper;
88 }77 }
89 }78 }
90 break;79 break;
91 case THERMAL_TREND_DROP_FULL:
92 if (cur_state == instance->lower) {
93 if (!throttle)
94 next_target = THERMAL_NO_TARGET;
95 } else
96 next_target = instance->lower;
97 break;
98 default:80 default:
99 break;81 break;
100 }82 }
drivers/thermal/intel/intel_pch_thermal.c+0−8
@@ -207,14 +207,6 @@ static int pch_wpt_suspend(struct pch_thermal_device *ptd) · 206 unmodified lines
207 return 0;207 return 0;
208 }208 }
209 209
210 /* Do not check temperature if it is not a S0ix capable platform */
211#ifdef CONFIG_ACPI
212 if (!(acpi_gbl_FADT.flags & ACPI_FADT_LOW_POWER_S0))
213 return 0;
214#else
215 return 0;
216#endif
217
218 /* Do not check temperature if it is not s2idle */210 /* Do not check temperature if it is not s2idle */
219 if (pm_suspend_via_firmware())211 if (pm_suspend_via_firmware())
220 return 0;212 return 0;
drivers/thermal/intel/x86_pkg_temp_thermal.c+1−1
@@ -105,7 +105,7 @@ static struct zone_device *pkg_temp_thermal_get_dev(unsigned int cpu) · 104 unmodified lines
105}105}
106 106
107/*107/*
108* tj-max is is interesting because threshold is set relative to this108* tj-max is interesting because threshold is set relative to this
109* temperature.109* temperature.
110*/110*/
111static int get_tj_max(int cpu, u32 *tj_max)111static int get_tj_max(int cpu, u32 *tj_max)
drivers/thermal/k3_j72xx_bandgap.c+7−6
@@ -151,8 +151,6 @@ static int prep_lookup_table(struct err_values *err_vals, int *ref_table) · 150 unmodified lines
151 /* 300 milli celsius steps */151 /* 300 milli celsius steps */
152 while (i--)152 while (i--)
153 derived_table[i] = derived_table[i + 1] - 300;153 derived_table[i] = derived_table[i + 1] - 300;
154 /* case 0 */
155 derived_table[i] = derived_table[i + 1] - 300;
156 }154 }
157 155
158 /*156 /*
@@ -433,7 +431,7 @@ static int k3_j72xx_bandgap_probe(struct platform_device *pdev) · 274 unmodified lines
433 GFP_KERNEL);431 GFP_KERNEL);
434 if (!derived_table) {432 if (!derived_table) {
435 ret = -ENOMEM;433 ret = -ENOMEM;
436 goto err_alloc;434 goto err_free_ref_table;
437 }435 }
438 436
439 /* Workaround not needed if bit30/bit31 is set even for J721e */437 /* Workaround not needed if bit30/bit31 is set even for J721e */
@@ -483,7 +481,7 @@ static int k3_j72xx_bandgap_probe(struct platform_device *pdev) · 43 unmodified lines
483 if (IS_ERR(ti_thermal)) {481 if (IS_ERR(ti_thermal)) {
484 dev_err(bgp->dev, "thermal zone device is NULL\n");482 dev_err(bgp->dev, "thermal zone device is NULL\n");
485 ret = PTR_ERR(ti_thermal);483 ret = PTR_ERR(ti_thermal);
486 goto err_alloc;484 goto err_free_ref_table;
487 }485 }
488 }486 }
489 487
@@ -514,6 +512,9 @@ static int k3_j72xx_bandgap_probe(struct platform_device *pdev) · 24 unmodified lines
514 512
515 return 0;513 return 0;
516 514
515err_free_ref_table:
516 kfree(ref_table);
517
517err_alloc:518err_alloc:
518 pm_runtime_put_sync(&pdev->dev);519 pm_runtime_put_sync(&pdev->dev);
519 pm_runtime_disable(&pdev->dev);520 pm_runtime_disable(&pdev->dev);
@@ -529,11 +530,11 @@ static int k3_j72xx_bandgap_remove(struct platform_device *pdev) · 9 unmodified lines
529 return 0;530 return 0;
530}531}
531 532
532const struct k3_j72xx_bandgap_data k3_j72xx_bandgap_j721e_data = {533static const struct k3_j72xx_bandgap_data k3_j72xx_bandgap_j721e_data = {
533 .has_errata_i2128 = 1,534 .has_errata_i2128 = 1,
534};535};
535 536
536const struct k3_j72xx_bandgap_data k3_j72xx_bandgap_j7200_data = {537static const struct k3_j72xx_bandgap_data k3_j72xx_bandgap_j7200_data = {
537 .has_errata_i2128 = 0,538 .has_errata_i2128 = 0,
538};539};
539 540
drivers/thermal/qcom/qcom-spmi-adc-tm5.c+5−0
@@ -20,6 +20,8 @@ · 19 unmodified lines
20#include <linux/thermal.h>20#include <linux/thermal.h>
21#include <asm-generic/unaligned.h>21#include <asm-generic/unaligned.h>
22 22
23#include "../thermal_hwmon.h"
24
23/*25/*
24 * Thermal monitoring block consists of 8 (ADC_TM5_NUM_CHANNELS) channels. Each26 * Thermal monitoring block consists of 8 (ADC_TM5_NUM_CHANNELS) channels. Each
25 * channel is programmed to use one of ADC channels for voltage comparison.27 * channel is programmed to use one of ADC channels for voltage comparison.
@@ -687,6 +689,9 @@ static int adc_tm5_register_tzd(struct adc_tm5_chip *adc_tm) · 661 unmodified lines
687 return PTR_ERR(tzd);689 return PTR_ERR(tzd);
688 }690 }
689 adc_tm->channels[i].tzd = tzd;691 adc_tm->channels[i].tzd = tzd;
692 if (devm_thermal_add_hwmon_sysfs(tzd))
693 dev_warn(adc_tm->dev,
694 "Failed to add hwmon sysfs attributes\n");
690 }695 }
691 696
692 return 0;697 return 0;
drivers/thermal/qcom/qcom-spmi-temp-alarm.c+5−0
@@ -16,6 +16,7 @@ · 15 unmodified lines
16#include <linux/thermal.h>16#include <linux/thermal.h>
17 17
18#include "../thermal_core.h"18#include "../thermal_core.h"
19#include "../thermal_hwmon.h"
19 20
20#define QPNP_TM_REG_DIG_MAJOR 0x0121#define QPNP_TM_REG_DIG_MAJOR 0x01
21#define QPNP_TM_REG_TYPE 0x0422#define QPNP_TM_REG_TYPE 0x04
@@ -458,6 +459,10 @@ static int qpnp_tm_probe(struct platform_device *pdev) · 436 unmodified lines
458 return ret;459 return ret;
459 }460 }
460 461
462 if (devm_thermal_add_hwmon_sysfs(chip->tz_dev))
463 dev_warn(&pdev->dev,
464 "Failed to add hwmon sysfs attributes\n");
465
461 ret = devm_request_threaded_irq(&pdev->dev, irq, NULL, qpnp_tm_isr,466 ret = devm_request_threaded_irq(&pdev->dev, irq, NULL, qpnp_tm_isr,
462 IRQF_ONESHOT, node->name, chip);467 IRQF_ONESHOT, node->name, chip);
463 if (ret < 0)468 if (ret < 0)
drivers/thermal/qcom/tsens.c+0−12
@@ -933,17 +933,6 @@ static int tsens_get_temp(void *data, int *temp) · 932 unmodified lines
933 return priv->ops->get_temp(s, temp);933 return priv->ops->get_temp(s, temp);
934}934}
935 935
936static int tsens_get_trend(void *data, int trip, enum thermal_trend *trend)
937{
938 struct tsens_sensor *s = data;
939 struct tsens_priv *priv = s->priv;
940
941 if (priv->ops->get_trend)
942 return priv->ops->get_trend(s, trend);
943
944 return -ENOTSUPP;
945}
946
947static int __maybe_unused tsens_suspend(struct device *dev)936static int __maybe_unused tsens_suspend(struct device *dev)
948{937{
949 struct tsens_priv *priv = dev_get_drvdata(dev);938 struct tsens_priv *priv = dev_get_drvdata(dev);
@@ -1004,7 +993,6 @@ MODULE_DEVICE_TABLE(of, tsens_table); · 54 unmodified lines
1004 993
1005static const struct thermal_zone_of_device_ops tsens_of_ops = {994static const struct thermal_zone_of_device_ops tsens_of_ops = {
1006 .get_temp = tsens_get_temp,995 .get_temp = tsens_get_temp,
1007 .get_trend = tsens_get_trend,
1008 .set_trips = tsens_set_trips,996 .set_trips = tsens_set_trips,
1009};997};
1010 998
drivers/thermal/qcom/tsens.h+0−2
@@ -65,7 +65,6 @@ struct tsens_sensor { · 64 unmodified lines
65 * @disable: Function to disable the tsens device65 * @disable: Function to disable the tsens device
66 * @suspend: Function to suspend the tsens device66 * @suspend: Function to suspend the tsens device
67 * @resume: Function to resume the tsens device67 * @resume: Function to resume the tsens device
68 * @get_trend: Function to get the thermal/temp trend
69 */68 */
70struct tsens_ops {69struct tsens_ops {
71 /* mandatory callbacks */70 /* mandatory callbacks */
@@ -77,7 +76,6 @@ struct tsens_ops { · 5 unmodified lines
77 void (*disable)(struct tsens_priv *priv);76 void (*disable)(struct tsens_priv *priv);
78 int (*suspend)(struct tsens_priv *priv);77 int (*suspend)(struct tsens_priv *priv);
79 int (*resume)(struct tsens_priv *priv);78 int (*resume)(struct tsens_priv *priv);
80 int (*get_trend)(struct tsens_sensor *s, enum thermal_trend *trend);
81};79};
82 80
83#define REG_FIELD_FOR_EACH_SENSOR11(_name, _offset, _startbit, _stopbit) \81#define REG_FIELD_FOR_EACH_SENSOR11(_name, _offset, _startbit, _stopbit) \
drivers/thermal/rcar_gen3_thermal.c+2−2
@@ -511,7 +511,7 @@ static int rcar_gen3_thermal_probe(struct platform_device *pdev) · 510 unmodified lines
511 zone = devm_thermal_zone_of_sensor_register(dev, i, tsc,511 zone = devm_thermal_zone_of_sensor_register(dev, i, tsc,
512 &rcar_gen3_tz_of_ops);512 &rcar_gen3_tz_of_ops);
513 if (IS_ERR(zone)) {513 if (IS_ERR(zone)) {
514 dev_err(dev, "Can't register thermal zone\n");514 dev_err(dev, "Sensor %u: Can't register thermal zone\n", i);
515 ret = PTR_ERR(zone);515 ret = PTR_ERR(zone);
516 goto error_unregister;516 goto error_unregister;
517 }517 }
@@ -533,7 +533,7 @@ static int rcar_gen3_thermal_probe(struct platform_device *pdev) · 15 unmodified lines
533 if (ret < 0)533 if (ret < 0)
534 goto error_unregister;534 goto error_unregister;
535 535
536 dev_info(dev, "TSC%u: Loaded %d trip points\n", i, ret);536 dev_info(dev, "Sensor %u: Loaded %d trip points\n", i, ret);
537 }537 }
538 538
539 if (!priv->num_tscs) {539 if (!priv->num_tscs) {
drivers/thermal/rzg2l_thermal.c+11−7
@@ -47,7 +47,7 @@ · 46 unmodified lines
47 47
48#define TS_CODE_AVE_SCALE(x) ((x) * 1000000)48#define TS_CODE_AVE_SCALE(x) ((x) * 1000000)
49#define MCELSIUS(temp) ((temp) * MILLIDEGREE_PER_DEGREE)49#define MCELSIUS(temp) ((temp) * MILLIDEGREE_PER_DEGREE)
50#define TS_CODE_CAP_TIMES 8 /* Capture times */50#define TS_CODE_CAP_TIMES 8 /* Total number of ADC data samples */
51 51
52#define RZG2L_THERMAL_GRAN 500 /* milli Celsius */52#define RZG2L_THERMAL_GRAN 500 /* milli Celsius */
53#define RZG2L_TSU_SS_TIMEOUT_US 100053#define RZG2L_TSU_SS_TIMEOUT_US 1000
@@ -80,7 +80,8 @@ static int rzg2l_thermal_get_temp(void *devdata, int *temp) · 26 unmodified lines
80 int val, i;80 int val, i;
81 81
82 for (i = 0; i < TS_CODE_CAP_TIMES ; i++) {82 for (i = 0; i < TS_CODE_CAP_TIMES ; i++) {
83 /* TSU repeats measurement at 20 microseconds intervals and83 /*
84 * TSU repeats measurement at 20 microseconds intervals and
84 * automatically updates the results of measurement. As per85 * automatically updates the results of measurement. As per
85 * the HW manual for measuring temperature we need to read 886 * the HW manual for measuring temperature we need to read 8
86 * values consecutively and then take the average.87 * values consecutively and then take the average.
@@ -92,16 +93,18 @@ static int rzg2l_thermal_get_temp(void *devdata, int *temp) · 5 unmodified lines
92 93
93 ts_code_ave = result / TS_CODE_CAP_TIMES;94 ts_code_ave = result / TS_CODE_CAP_TIMES;
94 95
95 /* Calculate actual sensor value by applying curvature correction formula96 /*
97 * Calculate actual sensor value by applying curvature correction formula
96 * dsensor = ts_code_ave / (1 + ts_code_ave * 0.000013). Here we are doing98 * dsensor = ts_code_ave / (1 + ts_code_ave * 0.000013). Here we are doing
97 * integer calculation by scaling all the values by 1000000.99 * integer calculation by scaling all the values by 1000000.
98 */100 */
99 dsensor = TS_CODE_AVE_SCALE(ts_code_ave) /101 dsensor = TS_CODE_AVE_SCALE(ts_code_ave) /
100 (TS_CODE_AVE_SCALE(1) + (ts_code_ave * CURVATURE_CORRECTION_CONST));102 (TS_CODE_AVE_SCALE(1) + (ts_code_ave * CURVATURE_CORRECTION_CONST));
101 103
102 /* The temperature Tj is calculated by the formula104 /*
105 * The temperature Tj is calculated by the formula
103 * Tj = (dsensor − calib1) * 165/ (calib0 − calib1) − 40106 * Tj = (dsensor − calib1) * 165/ (calib0 − calib1) − 40
104 * where calib0 and calib1 are the caliberation values.107 * where calib0 and calib1 are the calibration values.
105 */108 */
106 val = ((dsensor - priv->calib1) * (MCELSIUS(165) /109 val = ((dsensor - priv->calib1) * (MCELSIUS(165) /
107 (priv->calib0 - priv->calib1))) - MCELSIUS(40);110 (priv->calib0 - priv->calib1))) - MCELSIUS(40);
@@ -122,7 +125,8 @@ static int rzg2l_thermal_init(struct rzg2l_thermal_priv *priv) · 14 unmodified lines
122 rzg2l_thermal_write(priv, TSU_SM, TSU_SM_NORMAL_MODE);125 rzg2l_thermal_write(priv, TSU_SM, TSU_SM_NORMAL_MODE);
123 rzg2l_thermal_write(priv, TSU_ST, 0);126 rzg2l_thermal_write(priv, TSU_ST, 0);
124 127
125 /* Before setting the START bit, TSU should be in normal operating128 /*
129 * Before setting the START bit, TSU should be in normal operating
126 * mode. As per the HW manual, it will take 60 µs to place the TSU130 * mode. As per the HW manual, it will take 60 µs to place the TSU
127 * into normal operating mode.131 * into normal operating mode.
128 */132 */
@@ -217,7 +221,7 @@ static int rzg2l_thermal_probe(struct platform_device *pdev) · 88 unmodified lines
217 if (ret)221 if (ret)
218 goto err;222 goto err;
219 223
220 dev_dbg(dev, "TSU probed with %s caliberation values",224 dev_dbg(dev, "TSU probed with %s calibration values",
221 rzg2l_thermal_read(priv, OTPTSUTRIM_REG(0)) ? "hw" : "sw");225 rzg2l_thermal_read(priv, OTPTSUTRIM_REG(0)) ? "hw" : "sw");
222 226
223 return 0;227 return 0;
drivers/thermal/sun8i_thermal.c+1−1
@@ -237,7 +237,7 @@ static int sun50i_h6_ths_calibrate(struct ths_device *tmdev, · 236 unmodified lines
237 * The calibration data on the H6 is the ambient temperature and237 * The calibration data on the H6 is the ambient temperature and
238 * sensor values that are filled during the factory test stage.238 * sensor values that are filled during the factory test stage.
239 *239 *
240 * The unit of stored FT temperature is 0.1 degreee celusis.240 * The unit of stored FT temperature is 0.1 degree celsius.
241 *241 *
242 * We need to calculate a delta between measured and caluclated242 * We need to calculate a delta between measured and caluclated
243 * register values and this will become a calibration offset.243 * register values and this will become a calibration offset.
drivers/thermal/tegra/soctherm.c+0−32
@@ -633,37 +633,6 @@ static int tegra_thermctl_set_trip_temp(void *data, int trip, int temp) · 632 unmodified lines
633 return 0;633 return 0;
634}634}
635 635
636static int tegra_thermctl_get_trend(void *data, int trip,
637 enum thermal_trend *trend)
638{
639 struct tegra_thermctl_zone *zone = data;
640 struct thermal_zone_device *tz = zone->tz;
641 int trip_temp, temp, last_temp, ret;
642
643 if (!tz)
644 return -EINVAL;
645
646 ret = tz->ops->get_trip_temp(zone->tz, trip, &trip_temp);
647 if (ret)
648 return ret;
649
650 temp = READ_ONCE(tz->temperature);
651 last_temp = READ_ONCE(tz->last_temperature);
652
653 if (temp > trip_temp) {
654 if (temp >= last_temp)
655 *trend = THERMAL_TREND_RAISING;
656 else
657 *trend = THERMAL_TREND_STABLE;
658 } else if (temp < trip_temp) {
659 *trend = THERMAL_TREND_DROPPING;
660 } else {
661 *trend = THERMAL_TREND_STABLE;
662 }
663
664 return 0;
665}
666
667static void thermal_irq_enable(struct tegra_thermctl_zone *zn)636static void thermal_irq_enable(struct tegra_thermctl_zone *zn)
668{637{
669 u32 r;638 u32 r;
@@ -716,7 +685,6 @@ static int tegra_thermctl_set_trips(void *data, int lo, int hi) · 46 unmodified lines
716static const struct thermal_zone_of_device_ops tegra_of_thermal_ops = {685static const struct thermal_zone_of_device_ops tegra_of_thermal_ops = {
717 .get_temp = tegra_thermctl_get_temp,686 .get_temp = tegra_thermctl_get_temp,
718 .set_trip_temp = tegra_thermctl_set_trip_temp,687 .set_trip_temp = tegra_thermctl_set_trip_temp,
719 .get_trend = tegra_thermctl_get_trend,
720 .set_trips = tegra_thermctl_set_trips,688 .set_trips = tegra_thermctl_set_trips,
721};689};
722 690
drivers/thermal/tegra/tegra30-tsensor.c+1−1
@@ -316,7 +316,7 @@ static void tegra_tsensor_get_hw_channel_trips(struct thermal_zone_device *tzd, · 315 unmodified lines
316 *hot_trip = 85000;316 *hot_trip = 85000;
317 *crit_trip = 90000;317 *crit_trip = 90000;
318 318
319 for (i = 0; i < tzd->trips; i++) {319 for (i = 0; i < tzd->num_trips; i++) {
320 enum thermal_trip_type type;320 enum thermal_trip_type type;
321 int trip_temp;321 int trip_temp;
322 322
drivers/thermal/thermal_core.c+47−32
@@ -340,12 +340,8 @@ void thermal_zone_device_critical(struct thermal_zone_device *tz) · 339 unmodified lines
340EXPORT_SYMBOL(thermal_zone_device_critical);340EXPORT_SYMBOL(thermal_zone_device_critical);
341 341
342static void handle_critical_trips(struct thermal_zone_device *tz,342static void handle_critical_trips(struct thermal_zone_device *tz,
343 int trip, enum thermal_trip_type trip_type)343 int trip, int trip_temp, enum thermal_trip_type trip_type)
344{344{
345 int trip_temp;
346
347 tz->ops->get_trip_temp(tz, trip, &trip_temp);
348
349 /* If we have not crossed the trip_temp, we do not care. */345 /* If we have not crossed the trip_temp, we do not care. */
350 if (trip_temp <= 0 || tz->temperature < trip_temp)346 if (trip_temp <= 0 || tz->temperature < trip_temp)
351 return;347 return;
@@ -384,7 +380,7 @@ static void handle_thermal_trip(struct thermal_zone_device *tz, int trip) · 32 unmodified lines
384 }380 }
385 381
386 if (type == THERMAL_TRIP_CRITICAL || type == THERMAL_TRIP_HOT)382 if (type == THERMAL_TRIP_CRITICAL || type == THERMAL_TRIP_HOT)
387 handle_critical_trips(tz, trip, type);383 handle_critical_trips(tz, trip, trip_temp, type);
388 else384 else
389 handle_non_critical_trips(tz, trip);385 handle_non_critical_trips(tz, trip);
390 /*386 /*
@@ -505,7 +501,7 @@ void thermal_zone_device_update(struct thermal_zone_device *tz, · 114 unmodified lines
505 501
506 tz->notify_event = event;502 tz->notify_event = event;
507 503
508 for (count = 0; count < tz->trips; count++)504 for (count = 0; count < tz->num_trips; count++)
509 handle_thermal_trip(tz, count);505 handle_thermal_trip(tz, count);
510}506}
511EXPORT_SYMBOL_GPL(thermal_zone_device_update);507EXPORT_SYMBOL_GPL(thermal_zone_device_update);
@@ -630,7 +626,7 @@ int thermal_zone_bind_cooling_device(struct thermal_zone_device *tz, · 118 unmodified lines
630 unsigned long max_state;626 unsigned long max_state;
631 int result, ret;627 int result, ret;
632 628
633 if (trip >= tz->trips || trip < 0)629 if (trip >= tz->num_trips || trip < 0)
634 return -EINVAL;630 return -EINVAL;
635 631
636 list_for_each_entry(pos1, &thermal_tz_list, node) {632 list_for_each_entry(pos1, &thermal_tz_list, node) {
@@ -667,7 +663,7 @@ int thermal_zone_bind_cooling_device(struct thermal_zone_device *tz, · 30 unmodified lines
667 dev->target = THERMAL_NO_TARGET;663 dev->target = THERMAL_NO_TARGET;
668 dev->weight = weight;664 dev->weight = weight;
669 665
670 result = ida_simple_get(&tz->ida, 0, 0, GFP_KERNEL);666 result = ida_alloc(&tz->ida, GFP_KERNEL);
671 if (result < 0)667 if (result < 0)
672 goto free_mem;668 goto free_mem;
673 669
@@ -721,7 +717,7 @@ remove_trip_file: · 47 unmodified lines
721remove_symbol_link:717remove_symbol_link:
722 sysfs_remove_link(&tz->device.kobj, dev->name);718 sysfs_remove_link(&tz->device.kobj, dev->name);
723release_ida:719release_ida:
724 ida_simple_remove(&tz->ida, dev->id);720 ida_free(&tz->ida, dev->id);
725free_mem:721free_mem:
726 kfree(dev);722 kfree(dev);
727 return result;723 return result;
@@ -768,7 +764,7 @@ unbind: · 40 unmodified lines
768 device_remove_file(&tz->device, &pos->weight_attr);764 device_remove_file(&tz->device, &pos->weight_attr);
769 device_remove_file(&tz->device, &pos->attr);765 device_remove_file(&tz->device, &pos->attr);
770 sysfs_remove_link(&tz->device.kobj, pos->name);766 sysfs_remove_link(&tz->device.kobj, pos->name);
771 ida_simple_remove(&tz->ida, pos->id);767 ida_free(&tz->ida, pos->id);
772 kfree(pos);768 kfree(pos);
773 return 0;769 return 0;
774}770}
@@ -811,7 +807,7 @@ static void __bind(struct thermal_zone_device *tz, int mask, · 36 unmodified lines
811{807{
812 int i, ret;808 int i, ret;
813 809
814 for (i = 0; i < tz->trips; i++) {810 for (i = 0; i < tz->num_trips; i++) {
815 if (mask & (1 << i)) {811 if (mask & (1 << i)) {
816 unsigned long upper, lower;812 unsigned long upper, lower;
817 813
@@ -901,7 +897,7 @@ __thermal_cooling_device_register(struct device_node *np, · 83 unmodified lines
901 if (!cdev)897 if (!cdev)
902 return ERR_PTR(-ENOMEM);898 return ERR_PTR(-ENOMEM);
903 899
904 ret = ida_simple_get(&thermal_cdev_ida, 0, 0, GFP_KERNEL);900 ret = ida_alloc(&thermal_cdev_ida, GFP_KERNEL);
905 if (ret < 0)901 if (ret < 0)
906 goto out_kfree_cdev;902 goto out_kfree_cdev;
907 cdev->id = ret;903 cdev->id = ret;
@@ -952,7 +948,7 @@ out_kfree_type: · 44 unmodified lines
952 put_device(&cdev->device);948 put_device(&cdev->device);
953 cdev = NULL;949 cdev = NULL;
954out_ida_remove:950out_ida_remove:
955 ida_simple_remove(&thermal_cdev_ida, id);951 ida_free(&thermal_cdev_ida, id);
956out_kfree_cdev:952out_kfree_cdev:
957 kfree(cdev);953 kfree(cdev);
958 return ERR_PTR(ret);954 return ERR_PTR(ret);
@@ -1057,7 +1053,7 @@ static void __unbind(struct thermal_zone_device *tz, int mask, · 98 unmodified lines
1057{1053{
1058 int i;1054 int i;
1059 1055
1060 for (i = 0; i < tz->trips; i++)1056 for (i = 0; i < tz->num_trips; i++)
1061 if (mask & (1 << i))1057 if (mask & (1 << i))
1062 thermal_zone_unbind_cooling_device(tz, i, cdev);1058 thermal_zone_unbind_cooling_device(tz, i, cdev);
1063}1059}
@@ -1111,7 +1107,7 @@ void thermal_cooling_device_unregister(struct thermal_cooling_device *cdev) · 47 unmodified lines
1111 1107
1112 mutex_unlock(&thermal_list_lock);1108 mutex_unlock(&thermal_list_lock);
1113 1109
1114 ida_simple_remove(&thermal_cdev_ida, cdev->id);1110 ida_free(&thermal_cdev_ida, cdev->id);
1115 device_del(&cdev->device);1111 device_del(&cdev->device);
1116 thermal_cooling_device_destroy_sysfs(cdev);1112 thermal_cooling_device_destroy_sysfs(cdev);
1117 kfree(cdev->type);1113 kfree(cdev->type);
@@ -1159,10 +1155,18 @@ exit: · 41 unmodified lines
1159 mutex_unlock(&thermal_list_lock);1155 mutex_unlock(&thermal_list_lock);
1160}1156}
1161 1157
1158static void thermal_set_delay_jiffies(unsigned long *delay_jiffies, int delay_ms)
1159{
1160 *delay_jiffies = msecs_to_jiffies(delay_ms);
1161 if (delay_ms > 1000)
1162 *delay_jiffies = round_jiffies(*delay_jiffies);
1163}
1164
1162/**1165/**
1163 * thermal_zone_device_register() - register a new thermal zone device1166 * thermal_zone_device_register_with_trips() - register a new thermal zone device
1164 * @type: the thermal zone device type1167 * @type: the thermal zone device type
1165 * @trips: the number of trip points the thermal zone support1168 * @trips: a pointer to an array of thermal trips
1169 * @num_trips: the number of trip points the thermal zone support
1166 * @mask: a bit string indicating the writeablility of trip points1170 * @mask: a bit string indicating the writeablility of trip points
1167 * @devdata: private device data1171 * @devdata: private device data
1168 * @ops: standard thermal zone device callbacks1172 * @ops: standard thermal zone device callbacks
@@ -1184,10 +1188,10 @@ exit: · 15 unmodified lines
1184 * IS_ERR*() helpers.1188 * IS_ERR*() helpers.
1185 */1189 */
1186struct thermal_zone_device *1190struct thermal_zone_device *
1187thermal_zone_device_register(const char *type, int trips, int mask,1191thermal_zone_device_register_with_trips(const char *type, struct thermal_trip *trips, int num_trips, int mask,
1188 void *devdata, struct thermal_zone_device_ops *ops,1192 void *devdata, struct thermal_zone_device_ops *ops,
1189 struct thermal_zone_params *tzp, int passive_delay,1193 struct thermal_zone_params *tzp, int passive_delay,
1190 int polling_delay)1194 int polling_delay)
1191{1195{
1192 struct thermal_zone_device *tz;1196 struct thermal_zone_device *tz;
1193 enum thermal_trip_type trip_type;1197 enum thermal_trip_type trip_type;
@@ -1198,27 +1202,27 @@ thermal_zone_device_register(const char *type, int trips, int mask, · 4 unmodified lines
1198 struct thermal_governor *governor;1202 struct thermal_governor *governor;
1199 1203
1200 if (!type || strlen(type) == 0) {1204 if (!type || strlen(type) == 0) {
1201 pr_err("Error: No thermal zone type defined\n");1205 pr_err("No thermal zone type defined\n");
1202 return ERR_PTR(-EINVAL);1206 return ERR_PTR(-EINVAL);
1203 }1207 }
1204 1208
1205 if (type && strlen(type) >= THERMAL_NAME_LENGTH) {1209 if (type && strlen(type) >= THERMAL_NAME_LENGTH) {
1206 pr_err("Error: Thermal zone name (%s) too long, should be under %d chars\n",1210 pr_err("Thermal zone name (%s) too long, should be under %d chars\n",
1207 type, THERMAL_NAME_LENGTH);1211 type, THERMAL_NAME_LENGTH);
1208 return ERR_PTR(-EINVAL);1212 return ERR_PTR(-EINVAL);
1209 }1213 }
1210 1214
1211 if (trips > THERMAL_MAX_TRIPS || trips < 0 || mask >> trips) {1215 if (num_trips > THERMAL_MAX_TRIPS || num_trips < 0 || mask >> num_trips) {
1212 pr_err("Error: Incorrect number of thermal trips\n");1216 pr_err("Incorrect number of thermal trips\n");
1213 return ERR_PTR(-EINVAL);1217 return ERR_PTR(-EINVAL);
1214 }1218 }
1215 1219
1216 if (!ops) {1220 if (!ops) {
1217 pr_err("Error: Thermal zone device ops not defined\n");1221 pr_err("Thermal zone device ops not defined\n");
1218 return ERR_PTR(-EINVAL);1222 return ERR_PTR(-EINVAL);
1219 }1223 }
1220 1224
1221 if (trips > 0 && (!ops->get_trip_type || !ops->get_trip_temp))1225 if (num_trips > 0 && (!ops->get_trip_type || !ops->get_trip_temp))
1222 return ERR_PTR(-EINVAL);1226 return ERR_PTR(-EINVAL);
1223 1227
1224 tz = kzalloc(sizeof(*tz), GFP_KERNEL);1228 tz = kzalloc(sizeof(*tz), GFP_KERNEL);
@@ -1228,7 +1232,7 @@ thermal_zone_device_register(const char *type, int trips, int mask, · 3 unmodified lines
1228 INIT_LIST_HEAD(&tz->thermal_instances);1232 INIT_LIST_HEAD(&tz->thermal_instances);
1229 ida_init(&tz->ida);1233 ida_init(&tz->ida);
1230 mutex_init(&tz->lock);1234 mutex_init(&tz->lock);
1231 id = ida_simple_get(&thermal_tz_ida, 0, 0, GFP_KERNEL);1235 id = ida_alloc(&thermal_tz_ida, GFP_KERNEL);
1232 if (id < 0) {1236 if (id < 0) {
1233 result = id;1237 result = id;
1234 goto free_tz;1238 goto free_tz;
@@ -1249,6 +1253,7 @@ thermal_zone_device_register(const char *type, int trips, int mask, · 14 unmodified lines
1249 tz->device.class = &thermal_class;1253 tz->device.class = &thermal_class;
1250 tz->devdata = devdata;1254 tz->devdata = devdata;
1251 tz->trips = trips;1255 tz->trips = trips;
1256 tz->num_trips = num_trips;
1252 1257
1253 thermal_set_delay_jiffies(&tz->passive_delay_jiffies, passive_delay);1258 thermal_set_delay_jiffies(&tz->passive_delay_jiffies, passive_delay);
1254 thermal_set_delay_jiffies(&tz->polling_delay_jiffies, polling_delay);1259 thermal_set_delay_jiffies(&tz->polling_delay_jiffies, polling_delay);
@@ -1266,7 +1271,7 @@ thermal_zone_device_register(const char *type, int trips, int mask, · 11 unmodified lines
1266 if (result)1271 if (result)
1267 goto release_device;1272 goto release_device;
1268 1273
1269 for (count = 0; count < trips; count++) {1274 for (count = 0; count < num_trips; count++) {
1270 if (tz->ops->get_trip_type(tz, count, &trip_type) ||1275 if (tz->ops->get_trip_type(tz, count, &trip_type) ||
1271 tz->ops->get_trip_temp(tz, count, &trip_temp) ||1276 tz->ops->get_trip_temp(tz, count, &trip_temp) ||
1272 !trip_temp)1277 !trip_temp)
@@ -1319,11 +1324,21 @@ release_device: · 46 unmodified lines
1319 put_device(&tz->device);1324 put_device(&tz->device);
1320 tz = NULL;1325 tz = NULL;
1321remove_id:1326remove_id:
1322 ida_simple_remove(&thermal_tz_ida, id);1327 ida_free(&thermal_tz_ida, id);
1323free_tz:1328free_tz:
1324 kfree(tz);1329 kfree(tz);
1325 return ERR_PTR(result);1330 return ERR_PTR(result);
1326}1331}
1332
1333struct thermal_zone_device *thermal_zone_device_register(const char *type, int ntrips, int mask,
1334 void *devdata, struct thermal_zone_device_ops *ops,
1335 struct thermal_zone_params *tzp, int passive_delay,
1336 int polling_delay)
1337{
1338 return thermal_zone_device_register_with_trips(type, NULL, ntrips, mask,
1339 devdata, ops, tzp,
1340 passive_delay, polling_delay);
1341}
1327EXPORT_SYMBOL_GPL(thermal_zone_device_register);1342EXPORT_SYMBOL_GPL(thermal_zone_device_register);
1328 1343
1329/**1344/**
@@ -1379,7 +1394,7 @@ void thermal_zone_device_unregister(struct thermal_zone_device *tz) · 49 unmodified lines
1379 thermal_set_governor(tz, NULL);1394 thermal_set_governor(tz, NULL);
1380 1395
1381 thermal_remove_hwmon_sysfs(tz);1396 thermal_remove_hwmon_sysfs(tz);
1382 ida_simple_remove(&thermal_tz_ida, tz->id);1397 ida_free(&thermal_tz_ida, tz->id);
1383 ida_destroy(&tz->ida);1398 ida_destroy(&tz->ida);
1384 mutex_destroy(&tz->lock);1399 mutex_destroy(&tz->lock);
1385 device_unregister(&tz->device);1400 device_unregister(&tz->device);
drivers/thermal/thermal_core.h+0−15
@@ -68,20 +68,6 @@ static inline bool cdev_is_power_actor(struct thermal_cooling_device *cdev) · 67 unmodified lines
68void thermal_cdev_update(struct thermal_cooling_device *);68void thermal_cdev_update(struct thermal_cooling_device *);
69void __thermal_cdev_update(struct thermal_cooling_device *cdev);69void __thermal_cdev_update(struct thermal_cooling_device *cdev);
70 70
71/**
72 * struct thermal_trip - representation of a point in temperature domain
73 * @np: pointer to struct device_node that this trip point was created from
74 * @temperature: temperature value in miliCelsius
75 * @hysteresis: relative hysteresis in miliCelsius
76 * @type: trip point type
77 */
78struct thermal_trip {
79 struct device_node *np;
80 int temperature;
81 int hysteresis;
82 enum thermal_trip_type type;
83};
84
85int get_tz_trend(struct thermal_zone_device *tz, int trip);71int get_tz_trend(struct thermal_zone_device *tz, int trip);
86 72
87struct thermal_instance *73struct thermal_instance *
@@ -126,7 +112,6 @@ int thermal_build_list_of_policies(char *buf); · 38 unmodified lines
126 112
127/* Helpers */113/* Helpers */
128void thermal_zone_set_trips(struct thermal_zone_device *tz);114void thermal_zone_set_trips(struct thermal_zone_device *tz);
129void thermal_set_delay_jiffies(unsigned long *delay_jiffies, int delay_ms);
130 115
131/* sysfs I/F */116/* sysfs I/F */
132int thermal_zone_create_device_groups(struct thermal_zone_device *, int);117int thermal_zone_create_device_groups(struct thermal_zone_device *, int);
drivers/thermal/thermal_helpers.c+2−11
@@ -39,7 +39,6 @@ int get_tz_trend(struct thermal_zone_device *tz, int trip) · 38 unmodified lines
39 39
40 return trend;40 return trend;
41}41}
42EXPORT_SYMBOL(get_tz_trend);
43 42
44struct thermal_instance *43struct thermal_instance *
45get_thermal_instance(struct thermal_zone_device *tz,44get_thermal_instance(struct thermal_zone_device *tz,
@@ -90,7 +89,7 @@ int thermal_zone_get_temp(struct thermal_zone_device *tz, int *temp) · 44 unmodified lines
90 ret = tz->ops->get_temp(tz, temp);89 ret = tz->ops->get_temp(tz, temp);
91 90
92 if (IS_ENABLED(CONFIG_THERMAL_EMULATION) && tz->emul_temperature) {91 if (IS_ENABLED(CONFIG_THERMAL_EMULATION) && tz->emul_temperature) {
93 for (count = 0; count < tz->trips; count++) {92 for (count = 0; count < tz->num_trips; count++) {
94 ret = tz->ops->get_trip_type(tz, count, &type);93 ret = tz->ops->get_trip_type(tz, count, &type);
95 if (!ret && type == THERMAL_TRIP_CRITICAL) {94 if (!ret && type == THERMAL_TRIP_CRITICAL) {
96 ret = tz->ops->get_trip_temp(tz, count,95 ret = tz->ops->get_trip_temp(tz, count,
@@ -138,7 +137,7 @@ void thermal_zone_set_trips(struct thermal_zone_device *tz) · 41 unmodified lines
138 if (!tz->ops->set_trips || !tz->ops->get_trip_hyst)137 if (!tz->ops->set_trips || !tz->ops->get_trip_hyst)
139 goto exit;138 goto exit;
140 139
141 for (i = 0; i < tz->trips; i++) {140 for (i = 0; i < tz->num_trips; i++) {
142 int trip_low;141 int trip_low;
143 142
144 tz->ops->get_trip_temp(tz, i, &trip_temp);143 tz->ops->get_trip_temp(tz, i, &trip_temp);
@@ -175,13 +174,6 @@ exit: · 30 unmodified lines
175 mutex_unlock(&tz->lock);174 mutex_unlock(&tz->lock);
176}175}
177 176
178void thermal_set_delay_jiffies(unsigned long *delay_jiffies, int delay_ms)
179{
180 *delay_jiffies = msecs_to_jiffies(delay_ms);
181 if (delay_ms > 1000)
182 *delay_jiffies = round_jiffies(*delay_jiffies);
183}
184
185static void thermal_cdev_set_cur_state(struct thermal_cooling_device *cdev,177static void thermal_cdev_set_cur_state(struct thermal_cooling_device *cdev,
186 int target)178 int target)
187{179{
@@ -228,7 +220,6 @@ void thermal_cdev_update(struct thermal_cooling_device *cdev) · 40 unmodified lines
228 }220 }
229 mutex_unlock(&cdev->lock);221 mutex_unlock(&cdev->lock);
230}222}
231EXPORT_SYMBOL(thermal_cdev_update);
232 223
233/**224/**
234 * thermal_zone_get_slope - return the slope attribute of the thermal zone225 * thermal_zone_get_slope - return the slope attribute of the thermal zone
drivers/thermal/thermal_netlink.c+1−1
@@ -469,7 +469,7 @@ static int thermal_genl_cmd_tz_get_trip(struct param *p) · 468 unmodified lines
469 469
470 mutex_lock(&tz->lock);470 mutex_lock(&tz->lock);
471 471
472 for (i = 0; i < tz->trips; i++) {472 for (i = 0; i < tz->num_trips; i++) {
473 473
474 enum thermal_trip_type type;474 enum thermal_trip_type type;
475 int temp, hyst = 0;475 int temp, hyst = 0;
drivers/thermal/thermal_of.c+111−90
@@ -118,12 +118,7 @@ static int of_thermal_set_trips(struct thermal_zone_device *tz, · 117 unmodified lines
118 */118 */
119int of_thermal_get_ntrips(struct thermal_zone_device *tz)119int of_thermal_get_ntrips(struct thermal_zone_device *tz)
120{120{
121 struct __thermal_zone *data = tz->devdata;121 return tz->num_trips;
122
123 if (!data || IS_ERR(data))
124 return -ENODEV;
125
126 return data->ntrips;
127}122}
128EXPORT_SYMBOL_GPL(of_thermal_get_ntrips);123EXPORT_SYMBOL_GPL(of_thermal_get_ntrips);
129 124
@@ -139,9 +134,7 @@ EXPORT_SYMBOL_GPL(of_thermal_get_ntrips); · 9 unmodified lines
139 */134 */
140bool of_thermal_is_trip_valid(struct thermal_zone_device *tz, int trip)135bool of_thermal_is_trip_valid(struct thermal_zone_device *tz, int trip)
141{136{
142 struct __thermal_zone *data = tz->devdata;137 if (trip >= tz->num_trips || trip < 0)
143
144 if (!data || trip >= data->ntrips || trip < 0)
145 return false;138 return false;
146 139
147 return true;140 return true;
@@ -161,12 +154,7 @@ EXPORT_SYMBOL_GPL(of_thermal_is_trip_valid); · 13 unmodified lines
161const struct thermal_trip *154const struct thermal_trip *
162of_thermal_get_trip_points(struct thermal_zone_device *tz)155of_thermal_get_trip_points(struct thermal_zone_device *tz)
163{156{
164 struct __thermal_zone *data = tz->devdata;157 return tz->trips;
165
166 if (!data)
167 return NULL;
168
169 return data->trips;
170}158}
171EXPORT_SYMBOL_GPL(of_thermal_get_trip_points);159EXPORT_SYMBOL_GPL(of_thermal_get_trip_points);
172 160
@@ -281,12 +269,10 @@ static int of_thermal_unbind(struct thermal_zone_device *thermal, · 108 unmodified lines
281static int of_thermal_get_trip_type(struct thermal_zone_device *tz, int trip,269static int of_thermal_get_trip_type(struct thermal_zone_device *tz, int trip,
282 enum thermal_trip_type *type)270 enum thermal_trip_type *type)
283{271{
284 struct __thermal_zone *data = tz->devdata;272 if (trip >= tz->num_trips || trip < 0)
285
286 if (trip >= data->ntrips || trip < 0)
287 return -EDOM;273 return -EDOM;
288 274
289 *type = data->trips[trip].type;275 *type = tz->trips[trip].type;
290 276
291 return 0;277 return 0;
292}278}
@@ -294,12 +280,10 @@ static int of_thermal_get_trip_type(struct thermal_zone_device *tz, int trip, · 1 unmodified line
294static int of_thermal_get_trip_temp(struct thermal_zone_device *tz, int trip,280static int of_thermal_get_trip_temp(struct thermal_zone_device *tz, int trip,
295 int *temp)281 int *temp)
296{282{
297 struct __thermal_zone *data = tz->devdata;283 if (trip >= tz->num_trips || trip < 0)
298
299 if (trip >= data->ntrips || trip < 0)
300 return -EDOM;284 return -EDOM;
301 285
302 *temp = data->trips[trip].temperature;286 *temp = tz->trips[trip].temperature;
303 287
304 return 0;288 return 0;
305}289}
@@ -309,7 +293,7 @@ static int of_thermal_set_trip_temp(struct thermal_zone_device *tz, int trip, · 3 unmodified lines
309{293{
310 struct __thermal_zone *data = tz->devdata;294 struct __thermal_zone *data = tz->devdata;
311 295
312 if (trip >= data->ntrips || trip < 0)296 if (trip >= tz->num_trips || trip < 0)
313 return -EDOM;297 return -EDOM;
314 298
315 if (data->ops && data->ops->set_trip_temp) {299 if (data->ops && data->ops->set_trip_temp) {
@@ -321,7 +305,7 @@ static int of_thermal_set_trip_temp(struct thermal_zone_device *tz, int trip, · 5 unmodified lines
321 }305 }
322 306
323 /* thermal framework should take care of data->mask & (1 << trip) */307 /* thermal framework should take care of data->mask & (1 << trip) */
324 data->trips[trip].temperature = temp;308 tz->trips[trip].temperature = temp;
325 309
326 return 0;310 return 0;
327}311}
@@ -329,12 +313,10 @@ static int of_thermal_set_trip_temp(struct thermal_zone_device *tz, int trip, · 1 unmodified line
329static int of_thermal_get_trip_hyst(struct thermal_zone_device *tz, int trip,313static int of_thermal_get_trip_hyst(struct thermal_zone_device *tz, int trip,
330 int *hyst)314 int *hyst)
331{315{
332 struct __thermal_zone *data = tz->devdata;316 if (trip >= tz->num_trips || trip < 0)
333
334 if (trip >= data->ntrips || trip < 0)
335 return -EDOM;317 return -EDOM;
336 318
337 *hyst = data->trips[trip].hysteresis;319 *hyst = tz->trips[trip].hysteresis;
338 320
339 return 0;321 return 0;
340}322}
@@ -342,13 +324,11 @@ static int of_thermal_get_trip_hyst(struct thermal_zone_device *tz, int trip, · 1 unmodified line
342static int of_thermal_set_trip_hyst(struct thermal_zone_device *tz, int trip,324static int of_thermal_set_trip_hyst(struct thermal_zone_device *tz, int trip,
343 int hyst)325 int hyst)
344{326{
345 struct __thermal_zone *data = tz->devdata;327 if (trip >= tz->num_trips || trip < 0)
346
347 if (trip >= data->ntrips || trip < 0)
348 return -EDOM;328 return -EDOM;
349 329
350 /* thermal framework should take care of data->mask & (1 << trip) */330 /* thermal framework should take care of data->mask & (1 << trip) */
351 data->trips[trip].hysteresis = hyst;331 tz->trips[trip].hysteresis = hyst;
352 332
353 return 0;333 return 0;
354}334}
@@ -356,12 +336,11 @@ static int of_thermal_set_trip_hyst(struct thermal_zone_device *tz, int trip, · 1 unmodified line
356static int of_thermal_get_crit_temp(struct thermal_zone_device *tz,336static int of_thermal_get_crit_temp(struct thermal_zone_device *tz,
357 int *temp)337 int *temp)
358{338{
359 struct __thermal_zone *data = tz->devdata;
360 int i;339 int i;
361 340
362 for (i = 0; i < data->ntrips; i++)341 for (i = 0; i < tz->num_trips; i++)
363 if (data->trips[i].type == THERMAL_TRIP_CRITICAL) {342 if (tz->trips[i].type == THERMAL_TRIP_CRITICAL) {
364 *temp = data->trips[i].temperature;343 *temp = tz->trips[i].temperature;
365 return 0;344 return 0;
366 }345 }
367 346
@@ -671,6 +650,35 @@ EXPORT_SYMBOL_GPL(devm_thermal_zone_of_sensor_unregister); · 303 unmodified lines
671 650
672/*** functions parsing device tree nodes ***/651/*** functions parsing device tree nodes ***/
673 652
653static int of_find_trip_id(struct device_node *np, struct device_node *trip)
654{
655 struct device_node *trips;
656 struct device_node *t;
657 int i = 0;
658
659 trips = of_get_child_by_name(np, "trips");
660 if (!trips) {
661 pr_err("Failed to find 'trips' node\n");
662 return -EINVAL;
663 }
664
665 /*
666 * Find the trip id point associated with the cooling device map
667 */
668 for_each_child_of_node(trips, t) {
669
670 if (t == trip)
671 goto out;
672 i++;
673 }
674
675 i = -ENXIO;
676out:
677 of_node_put(trips);
678
679 return i;
680}
681
674/**682/**
675 * thermal_of_populate_bind_params - parse and fill cooling map data683 * thermal_of_populate_bind_params - parse and fill cooling map data
676 * @np: DT node containing a cooling-map node684 * @np: DT node containing a cooling-map node
@@ -685,15 +693,15 @@ EXPORT_SYMBOL_GPL(devm_thermal_zone_of_sensor_unregister); · 8 unmodified lines
685 *693 *
686 * Return: 0 on success, proper error code otherwise694 * Return: 0 on success, proper error code otherwise
687 */695 */
688static int thermal_of_populate_bind_params(struct device_node *np,696static int thermal_of_populate_bind_params(struct device_node *tz_np,
689 struct __thermal_bind_params *__tbp,697 struct device_node *np,
690 struct thermal_trip *trips,698 struct __thermal_bind_params *__tbp)
691 int ntrips)
692{699{
693 struct of_phandle_args cooling_spec;700 struct of_phandle_args cooling_spec;
694 struct __thermal_cooling_bind_param *__tcbp;701 struct __thermal_cooling_bind_param *__tcbp;
695 struct device_node *trip;702 struct device_node *trip;
696 int ret, i, count;703 int ret, i, count;
704 int trip_id;
697 u32 prop;705 u32 prop;
698 706
699 /* Default weight. Usage is optional */707 /* Default weight. Usage is optional */
@@ -708,18 +716,14 @@ static int thermal_of_populate_bind_params(struct device_node *np, · 8 unmodified lines
708 return -ENODEV;716 return -ENODEV;
709 }717 }
710 718
711 /* match using device_node */719 trip_id = of_find_trip_id(tz_np, trip);
712 for (i = 0; i < ntrips; i++)720 if (trip_id < 0) {
713 if (trip == trips[i].np) {721 ret = trip_id;
714 __tbp->trip_id = i;
715 break;
716 }
717
718 if (i == ntrips) {
719 ret = -ENODEV;
720 goto end;722 goto end;
721 }723 }
722 724
725 __tbp->trip_id = trip_id;
726
723 count = of_count_phandle_with_args(np, "cooling-device",727 count = of_count_phandle_with_args(np, "cooling-device",
724 "#cooling-cells");728 "#cooling-cells");
725 if (count <= 0) {729 if (count <= 0) {
@@ -843,13 +847,56 @@ static int thermal_of_populate_trip(struct device_node *np, · 117 unmodified lines
843 return ret;847 return ret;
844 }848 }
845 849
846 /* Required for cooling map matching */
847 trip->np = np;
848 of_node_get(np);
849
850 return 0;850 return 0;
851}851}
852 852
853static struct thermal_trip *thermal_of_trips_init(struct device_node *np, int *ntrips)
854{
855 struct thermal_trip *tt;
856 struct device_node *trips, *trip;
857 int ret, count;
858
859 trips = of_get_child_by_name(np, "trips");
860 if (!trips) {
861 pr_err("Failed to find 'trips' node\n");
862 return ERR_PTR(-EINVAL);
863 }
864
865 count = of_get_child_count(trips);
866 if (!count) {
867 pr_err("No trip point defined\n");
868 ret = -EINVAL;
869 goto out_of_node_put;
870 }
871
872 tt = kzalloc(sizeof(*tt) * count, GFP_KERNEL);
873 if (!tt) {
874 ret = -ENOMEM;
875 goto out_of_node_put;
876 }
877
878 *ntrips = count;
879
880 count = 0;
881 for_each_child_of_node(trips, trip) {
882 ret = thermal_of_populate_trip(trip, &tt[count++]);
883 if (ret)
884 goto out_kfree;
885 }
886
887 of_node_put(trips);
888
889 return tt;
890
891out_kfree:
892 kfree(tt);
893 *ntrips = 0;
894out_of_node_put:
895 of_node_put(trips);
896
897 return ERR_PTR(ret);
898}
899
853/**900/**
854 * thermal_of_build_thermal_zone - parse and fill one thermal zone data901 * thermal_of_build_thermal_zone - parse and fill one thermal zone data
855 * @np: DT node containing a thermal zone node902 * @np: DT node containing a thermal zone node
@@ -909,32 +956,12 @@ __init *thermal_of_build_thermal_zone(struct device_node *np) · 53 unmodified lines
909 tz->offset = 0;956 tz->offset = 0;
910 }957 }
911 958
912 /* trips */959 tz->trips = thermal_of_trips_init(np, &tz->ntrips);
913 child = of_get_child_by_name(np, "trips");960 if (IS_ERR(tz->trips)) {
914 961 ret = PTR_ERR(tz->trips);
915 /* No trips provided */
916 if (!child)
917 goto finish;962 goto finish;
918
919 tz->ntrips = of_get_child_count(child);
920 if (tz->ntrips == 0) /* must have at least one child */
921 goto finish;
922
923 tz->trips = kcalloc(tz->ntrips, sizeof(*tz->trips), GFP_KERNEL);
924 if (!tz->trips) {
925 ret = -ENOMEM;
926 goto free_tz;
927 }963 }
928 964
929 i = 0;
930 for_each_child_of_node(child, gchild) {
931 ret = thermal_of_populate_trip(gchild, &tz->trips[i++]);
932 if (ret)
933 goto free_trips;
934 }
935
936 of_node_put(child);
937
938 /* cooling-maps */965 /* cooling-maps */
939 child = of_get_child_by_name(np, "cooling-maps");966 child = of_get_child_by_name(np, "cooling-maps");
940 967
@@ -954,10 +981,11 @@ __init *thermal_of_build_thermal_zone(struct device_node *np) · 13 unmodified lines
954 981
955 i = 0;982 i = 0;
956 for_each_child_of_node(child, gchild) {983 for_each_child_of_node(child, gchild) {
957 ret = thermal_of_populate_bind_params(gchild, &tz->tbps[i++],984 ret = thermal_of_populate_bind_params(np, gchild, &tz->tbps[i++]);
958 tz->trips, tz->ntrips);985 if (ret) {
959 if (ret)986 of_node_put(gchild);
960 goto free_tbps;987 goto free_tbps;
988 }
961 }989 }
962 990
963finish:991finish:
@@ -978,10 +1006,7 @@ free_tbps: · 14 unmodified lines
978 1006
979 kfree(tz->tbps);1007 kfree(tz->tbps);
980free_trips:1008free_trips:
981 for (i = 0; i < tz->ntrips; i++)
982 of_node_put(tz->trips[i].np);
983 kfree(tz->trips);1009 kfree(tz->trips);
984 of_node_put(gchild);
985free_tz:1010free_tz:
986 kfree(tz);1011 kfree(tz);
987 of_node_put(child);1012 of_node_put(child);
@@ -1004,8 +1029,6 @@ static __init void of_thermal_free_zone(struct __thermal_zone *tz) · 16 unmodified lines
1004 }1029 }
1005 1030
1006 kfree(tz->tbps);1031 kfree(tz->tbps);
1007 for (i = 0; i < tz->ntrips; i++)
1008 of_node_put(tz->trips[i].np);
1009 kfree(tz->trips);1032 kfree(tz->trips);
1010 kfree(tz);1033 kfree(tz);
1011}1034}
@@ -1103,11 +1126,9 @@ int __init of_parse_thermal_zones(void) · 91 unmodified lines
1103 tzp->slope = tz->slope;1126 tzp->slope = tz->slope;
1104 tzp->offset = tz->offset;1127 tzp->offset = tz->offset;
1105 1128
1106 zone = thermal_zone_device_register(child->name, tz->ntrips,1129 zone = thermal_zone_device_register_with_trips(child->name, tz->trips, tz->ntrips,
1107 mask, tz,1130 mask, tz, ops, tzp, tz->passive_delay,
1108 ops, tzp,1131 tz->polling_delay);
1109 tz->passive_delay,
1110 tz->polling_delay);
1111 if (IS_ERR(zone)) {1132 if (IS_ERR(zone)) {
1112 pr_err("Failed to build %pOFn zone %ld\n", child,1133 pr_err("Failed to build %pOFn zone %ld\n", child,
1113 PTR_ERR(zone));1134 PTR_ERR(zone));
drivers/thermal/thermal_sysfs.c+11−11
@@ -416,15 +416,15 @@ static int create_trip_attrs(struct thermal_zone_device *tz, int mask) · 415 unmodified lines
416 int indx;416 int indx;
417 417
418 /* This function works only for zones with at least one trip */418 /* This function works only for zones with at least one trip */
419 if (tz->trips <= 0)419 if (tz->num_trips <= 0)
420 return -EINVAL;420 return -EINVAL;
421 421
422 tz->trip_type_attrs = kcalloc(tz->trips, sizeof(*tz->trip_type_attrs),422 tz->trip_type_attrs = kcalloc(tz->num_trips, sizeof(*tz->trip_type_attrs),
423 GFP_KERNEL);423 GFP_KERNEL);
424 if (!tz->trip_type_attrs)424 if (!tz->trip_type_attrs)
425 return -ENOMEM;425 return -ENOMEM;
426 426
427 tz->trip_temp_attrs = kcalloc(tz->trips, sizeof(*tz->trip_temp_attrs),427 tz->trip_temp_attrs = kcalloc(tz->num_trips, sizeof(*tz->trip_temp_attrs),
428 GFP_KERNEL);428 GFP_KERNEL);
429 if (!tz->trip_temp_attrs) {429 if (!tz->trip_temp_attrs) {
430 kfree(tz->trip_type_attrs);430 kfree(tz->trip_type_attrs);
@@ -432,7 +432,7 @@ static int create_trip_attrs(struct thermal_zone_device *tz, int mask) · 1 unmodified line
432 }432 }
433 433
434 if (tz->ops->get_trip_hyst) {434 if (tz->ops->get_trip_hyst) {
435 tz->trip_hyst_attrs = kcalloc(tz->trips,435 tz->trip_hyst_attrs = kcalloc(tz->num_trips,
436 sizeof(*tz->trip_hyst_attrs),436 sizeof(*tz->trip_hyst_attrs),
437 GFP_KERNEL);437 GFP_KERNEL);
438 if (!tz->trip_hyst_attrs) {438 if (!tz->trip_hyst_attrs) {
@@ -442,7 +442,7 @@ static int create_trip_attrs(struct thermal_zone_device *tz, int mask) · 3 unmodified lines
442 }442 }
443 }443 }
444 444
445 attrs = kcalloc(tz->trips * 3 + 1, sizeof(*attrs), GFP_KERNEL);445 attrs = kcalloc(tz->num_trips * 3 + 1, sizeof(*attrs), GFP_KERNEL);
446 if (!attrs) {446 if (!attrs) {
447 kfree(tz->trip_type_attrs);447 kfree(tz->trip_type_attrs);
448 kfree(tz->trip_temp_attrs);448 kfree(tz->trip_temp_attrs);
@@ -451,7 +451,7 @@ static int create_trip_attrs(struct thermal_zone_device *tz, int mask) · 2 unmodified lines
451 return -ENOMEM;451 return -ENOMEM;
452 }452 }
453 453
454 for (indx = 0; indx < tz->trips; indx++) {454 for (indx = 0; indx < tz->num_trips; indx++) {
455 /* create trip type attribute */455 /* create trip type attribute */
456 snprintf(tz->trip_type_attrs[indx].name, THERMAL_NAME_LENGTH,456 snprintf(tz->trip_type_attrs[indx].name, THERMAL_NAME_LENGTH,
457 "trip_point_%d_type", indx);457 "trip_point_%d_type", indx);
@@ -478,7 +478,7 @@ static int create_trip_attrs(struct thermal_zone_device *tz, int mask) · 20 unmodified lines
478 tz->trip_temp_attrs[indx].attr.store =478 tz->trip_temp_attrs[indx].attr.store =
479 trip_point_temp_store;479 trip_point_temp_store;
480 }480 }
481 attrs[indx + tz->trips] = &tz->trip_temp_attrs[indx].attr.attr;481 attrs[indx + tz->num_trips] = &tz->trip_temp_attrs[indx].attr.attr;
482 482
483 /* create Optional trip hyst attribute */483 /* create Optional trip hyst attribute */
484 if (!tz->ops->get_trip_hyst)484 if (!tz->ops->get_trip_hyst)
@@ -496,10 +496,10 @@ static int create_trip_attrs(struct thermal_zone_device *tz, int mask) · 11 unmodified lines
496 tz->trip_hyst_attrs[indx].attr.store =496 tz->trip_hyst_attrs[indx].attr.store =
497 trip_point_hyst_store;497 trip_point_hyst_store;
498 }498 }
499 attrs[indx + tz->trips * 2] =499 attrs[indx + tz->num_trips * 2] =
500 &tz->trip_hyst_attrs[indx].attr.attr;500 &tz->trip_hyst_attrs[indx].attr.attr;
501 }501 }
502 attrs[tz->trips * 3] = NULL;502 attrs[tz->num_trips * 3] = NULL;
503 503
504 tz->trips_attribute_group.attrs = attrs;504 tz->trips_attribute_group.attrs = attrs;
505 505
@@ -540,7 +540,7 @@ int thermal_zone_create_device_groups(struct thermal_zone_device *tz, · 34 unmodified lines
540 for (i = 0; i < size - 2; i++)540 for (i = 0; i < size - 2; i++)
541 groups[i] = thermal_zone_attribute_groups[i];541 groups[i] = thermal_zone_attribute_groups[i];
542 542
543 if (tz->trips) {543 if (tz->num_trips) {
544 result = create_trip_attrs(tz, mask);544 result = create_trip_attrs(tz, mask);
545 if (result) {545 if (result) {
546 kfree(groups);546 kfree(groups);
@@ -561,7 +561,7 @@ void thermal_zone_destroy_device_groups(struct thermal_zone_device *tz) · 14 unmodified lines
561 if (!tz)561 if (!tz)
562 return;562 return;
563 563
564 if (tz->trips)564 if (tz->num_trips)
565 destroy_trip_attrs(tz);565 destroy_trip_attrs(tz);
566 566
567 kfree(tz->device.groups);567 kfree(tz->device.groups);
drivers/thermal/ti-soc-thermal/ti-bandgap.c+1−1
@@ -226,7 +226,7 @@ static irqreturn_t ti_bandgap_talert_irq_handler(int irq, void *data) · 225 unmodified lines
226 /*226 /*
227 * One TALERT interrupt: Two sources227 * One TALERT interrupt: Two sources
228 * If the interrupt is due to t_hot then mask t_hot and228 * If the interrupt is due to t_hot then mask t_hot and
229 * and unmask t_cold else mask t_cold and unmask t_hot229 * unmask t_cold else mask t_cold and unmask t_hot
230 */230 */
231 if (t_hot) {231 if (t_hot) {
232 ctrl &= ~tsr->mask_hot_mask;232 ctrl &= ~tsr->mask_hot_mask;
include/linux/thermal.h+22−4
@@ -40,8 +40,6 @@ enum thermal_trend { · 39 unmodified lines
40 THERMAL_TREND_STABLE, /* temperature is stable */40 THERMAL_TREND_STABLE, /* temperature is stable */
41 THERMAL_TREND_RAISING, /* temperature is raising */41 THERMAL_TREND_RAISING, /* temperature is raising */
42 THERMAL_TREND_DROPPING, /* temperature is dropping */42 THERMAL_TREND_DROPPING, /* temperature is dropping */
43 THERMAL_TREND_RAISE_FULL, /* apply highest cooling action */
44 THERMAL_TREND_DROP_FULL, /* apply lowest cooling action */
45};43};
46 44
47/* Thermal notification reason */45/* Thermal notification reason */
@@ -80,6 +78,18 @@ struct thermal_zone_device_ops { · 32 unmodified lines
80 void (*critical)(struct thermal_zone_device *);78 void (*critical)(struct thermal_zone_device *);
81};79};
82 80
81/**
82 * struct thermal_trip - representation of a point in temperature domain
83 * @temperature: temperature value in miliCelsius
84 * @hysteresis: relative hysteresis in miliCelsius
85 * @type: trip point type
86 */
87struct thermal_trip {
88 int temperature;
89 int hysteresis;
90 enum thermal_trip_type type;
91};
92
83struct thermal_cooling_device_ops {93struct thermal_cooling_device_ops {
84 int (*get_max_state) (struct thermal_cooling_device *, unsigned long *);94 int (*get_max_state) (struct thermal_cooling_device *, unsigned long *);
85 int (*get_cur_state) (struct thermal_cooling_device *, unsigned long *);95 int (*get_cur_state) (struct thermal_cooling_device *, unsigned long *);
@@ -113,7 +123,8 @@ struct thermal_cooling_device { · 27 unmodified lines
113 * @trip_hyst_attrs: attributes for trip points for sysfs: trip hysteresis123 * @trip_hyst_attrs: attributes for trip points for sysfs: trip hysteresis
114 * @mode: current mode of this thermal zone124 * @mode: current mode of this thermal zone
115 * @devdata: private pointer for device private data125 * @devdata: private pointer for device private data
116 * @trips: number of trip points the thermal zone supports126 * @trips: an array of struct thermal_trip
127 * @num_trips: number of trip points the thermal zone supports
117 * @trips_disabled; bitmap for disabled trips128 * @trips_disabled; bitmap for disabled trips
118 * @passive_delay_jiffies: number of jiffies to wait between polls when129 * @passive_delay_jiffies: number of jiffies to wait between polls when
119 * performing passive cooling.130 * performing passive cooling.
@@ -153,7 +164,8 @@ struct thermal_zone_device { · 33 unmodified lines
153 struct thermal_attr *trip_hyst_attrs;164 struct thermal_attr *trip_hyst_attrs;
154 enum thermal_device_mode mode;165 enum thermal_device_mode mode;
155 void *devdata;166 void *devdata;
156 int trips;167 struct thermal_trip *trips;
168 int num_trips;
157 unsigned long trips_disabled; /* bitmap for disabled trips */169 unsigned long trips_disabled; /* bitmap for disabled trips */
158 unsigned long passive_delay_jiffies;170 unsigned long passive_delay_jiffies;
159 unsigned long polling_delay_jiffies;171 unsigned long polling_delay_jiffies;
@@ -366,8 +378,14 @@ void devm_thermal_zone_of_sensor_unregister(struct device *dev, · 206 unmodified lines
366struct thermal_zone_device *thermal_zone_device_register(const char *, int, int,378struct thermal_zone_device *thermal_zone_device_register(const char *, int, int,
367 void *, struct thermal_zone_device_ops *,379 void *, struct thermal_zone_device_ops *,
368 struct thermal_zone_params *, int, int);380 struct thermal_zone_params *, int, int);
381
369void thermal_zone_device_unregister(struct thermal_zone_device *);382void thermal_zone_device_unregister(struct thermal_zone_device *);
370 383
384struct thermal_zone_device *
385thermal_zone_device_register_with_trips(const char *, struct thermal_trip *, int, int,
386 void *, struct thermal_zone_device_ops *,
387 struct thermal_zone_params *, int, int);
388
371int thermal_zone_bind_cooling_device(struct thermal_zone_device *, int,389int thermal_zone_bind_cooling_device(struct thermal_zone_device *, int,
372 struct thermal_cooling_device *,390 struct thermal_cooling_device *,
373 unsigned long, unsigned long,391 unsigned long, unsigned long,
include/trace/events/thermal.h+8−20
@@ -92,34 +92,22 @@ TRACE_EVENT(thermal_zone_trip, · 91 unmodified lines
92);92);
93 93
94#ifdef CONFIG_CPU_THERMAL94#ifdef CONFIG_CPU_THERMAL
95TRACE_EVENT(thermal_power_cpu_get_power,95TRACE_EVENT(thermal_power_cpu_get_power_simple,
96 TP_PROTO(const struct cpumask *cpus, unsigned long freq, u32 *load,96 TP_PROTO(int cpu, u32 power),
97 size_t load_len, u32 dynamic_power),
98 97
99 TP_ARGS(cpus, freq, load, load_len, dynamic_power),98 TP_ARGS(cpu, power),
100 99
101 TP_STRUCT__entry(100 TP_STRUCT__entry(
102 __bitmask(cpumask, num_possible_cpus())101 __field(int, cpu)
103 __field(unsigned long, freq )102 __field(u32, power)
104 __dynamic_array(u32, load, load_len)
105 __field(size_t, load_len )
106 __field(u32, dynamic_power )
107 ),103 ),
108 104
109 TP_fast_assign(105 TP_fast_assign(
110 __assign_bitmask(cpumask, cpumask_bits(cpus),106 __entry->cpu = cpu;
111 num_possible_cpus());107 __entry->power = power;
112 __entry->freq = freq;
113 memcpy(__get_dynamic_array(load), load,
114 load_len * sizeof(*load));
115 __entry->load_len = load_len;
116 __entry->dynamic_power = dynamic_power;
117 ),108 ),
118 109
119 TP_printk("cpus=%s freq=%lu load={%s} dynamic_power=%d",110 TP_printk("cpu=%d power=%u", __entry->cpu, __entry->power)
120 __get_bitmask(cpumask), __entry->freq,
121 __print_array(__get_dynamic_array(load), __entry->load_len, 4),
122 __entry->dynamic_power)
123);111);
124 112
125TRACE_EVENT(thermal_power_cpu_limit,113TRACE_EVENT(thermal_power_cpu_limit,
tools/thermal/tmon/pid.c+1−1
@@ -27,7 +27,7 @@ · 26 unmodified lines
27 27
28/**************************************************************************28/**************************************************************************
29 * PID (Proportional-Integral-Derivative) controller is commonly used in29 * PID (Proportional-Integral-Derivative) controller is commonly used in
30 * linear control system, consider the the process.30 * linear control system, consider the process.
31 * G(s) = U(s)/E(s)31 * G(s) = U(s)/E(s)
32 * kp = proportional gain32 * kp = proportional gain
33 * ki = integral gain33 * ki = integral gain
tools/thermal/tmon/tmon.h+3−0
@@ -27,6 +27,9 @@ · 26 unmodified lines
27#define NR_LINES_TZDATA 127#define NR_LINES_TZDATA 1
28#define TMON_LOG_FILE "/var/tmp/tmon.log"28#define TMON_LOG_FILE "/var/tmp/tmon.log"
29 29
30#include <sys/time.h>
31#include <pthread.h>
32
30extern unsigned long ticktime;33extern unsigned long ticktime;
31extern double time_elapsed;34extern double time_elapsed;
32extern unsigned long target_temp_user;35extern unsigned long target_temp_user;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t