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+
7+title: Qualcomm QPNP PMIC Temperature Alarm
8+
9+maintainers:
10+ - Bjorn Andersson <bjorn.andersson@linaro.org>
11+
12+description:
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+
17+allOf:
18+ - $ref: thermal-sensor.yaml#
19+
20+properties:
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+
41+required:
42+ - compatible
43+ - reg
44+ - interrupts
45+ - '#thermal-sensor-cells'
46+
47+additionalProperties: false
48+
49+examples:
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 @@
1−Qualcomm QPNP PMIC Temperature Alarm
2−
3−QPNP temperature alarm peripherals are found inside of Qualcomm PMIC chips
4−that utilize the Qualcomm SPMI implementation. These peripherals provide an
5−interrupt signal and status register to identify high PMIC die temperature.
6−
7−Required 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−
13−Optional 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−
18−Example:
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
88 title: Renesas R-Car Gen3 Thermal Sensor
99
1010 description:
11− On R-Car Gen3 SoCs, the thermal sensor controllers (TSC) control the thermal
12− sensors (THS) which are the analog circuits for measuring temperature (Tj)
13− inside the LSI.
11+ On most R-Car Gen3 and later SoCs, the thermal sensor controllers (TSC)
12+ control the thermal sensors (THS) which are the analog circuits for
13+ measuring temperature (Tj) inside the LSI.
1414
1515 maintainers:
1616 - Niklas Söderlund <niklas.soderlund@ragnatech.se>
@@ -27,6 +27,7 @@ properties: · 10 unmodified lines
2727 - renesas,r8a77965-thermal # R-Car M3-N
2828 - renesas,r8a77980-thermal # R-Car V3H
2929 - renesas,r8a779a0-thermal # R-Car V3U
30+ - renesas,r8a779f0-thermal # R-Car S4-8
3031
3132 reg: true
3233
@@ -57,31 +58,38 @@ required: · 24 unmodified lines
5758 - "#thermal-sensor-cells"
5859
5960 if:
60− not:
61− properties:
62− compatible:
63− contains:
64− enum:
65− - renesas,r8a779a0-thermal
61+ properties:
62+ compatible:
63+ contains:
64+ enum:
65+ - renesas,r8a779a0-thermal
6666 then:
6767 properties:
6868 reg:
69− minItems: 2
7069 items:
70+ - description: TSC0 registers
7171 - description: TSC1 registers
7272 - description: TSC2 registers
7373 - description: TSC3 registers
74− required:
75− - interrupts
74+ - description: TSC4 registers
7675 else:
7776 properties:
7877 reg:
78+ minItems: 2
7979 items:
80− - description: TSC0 registers
8180 - description: TSC1 registers
8281 - description: TSC2 registers
8382 - description: TSC3 registers
84− - description: TSC4 registers
83+ if:
84+ not:
85+ properties:
86+ compatible:
87+ contains:
88+ enum:
89+ - renesas,r8a779f0-thermal
90+ then:
91+ required:
92+ - interrupts
8593
8694 additionalProperties: false
8795
MAINTAINERS+1−0
@@ -19949,6 +19949,7 @@ F: Documentation/ABI/testing/sysfs-class-thermal · 19948 unmodified lines
1994919949 F: Documentation/devicetree/bindings/thermal/
1995019950 F: Documentation/driver-api/thermal/
1995119951 F: drivers/thermal/
19952+F: include/dt-bindings/thermal/
1995219953 F: include/linux/cpu_cooling.h
1995319954 F: include/linux/thermal.h
1995419955 F: include/uapi/linux/thermal.h
drivers/thermal/cpufreq_cooling.c+25−52
@@ -60,6 +60,7 @@ struct time_in_idle { · 59 unmodified lines
6060 * @cdev: thermal_cooling_device pointer to keep track of the
6161 * registered cooling device.
6262 * @policy: cpufreq policy.
63+ * @cooling_ops: cpufreq callbacks to thermal cooling device ops
6364 * @idle_time: idle time stats
6465 * @qos_req: PM QoS contraint to apply
6566 *
@@ -72,6 +73,7 @@ struct cpufreq_cooling_device { · 6 unmodified lines
7273 unsigned int max_level;
7374 struct em_perf_domain *em;
7475 struct cpufreq_policy *policy;
76+ struct thermal_cooling_device_ops cooling_ops;
7577 #ifndef CONFIG_SMP
7678 struct time_in_idle *idle_time;
7779 #endif
@@ -211,7 +213,7 @@ static u32 get_dynamic_power(struct cpufreq_cooling_device *cpufreq_cdev, · 133 unmodified lines
211213 * complex code may be needed if experiments show that it's not
212214 * accurate enough.
213215 *
214− * Return: 0 on success, -E* if getting the static power failed.
216+ * Return: 0 on success, this function doesn't fail.
215217 */
216218 static int cpufreq_get_requested_power(struct thermal_cooling_device *cdev,
217219 u32 *power)
@@ -221,16 +223,9 @@ static int cpufreq_get_requested_power(struct thermal_cooling_device *cdev, · 3 unmodified lines
221223 u32 total_load = 0;
222224 struct cpufreq_cooling_device *cpufreq_cdev = cdev->devdata;
223225 struct cpufreq_policy *policy = cpufreq_cdev->policy;
224− u32 *load_cpu = NULL;
225226
226227 freq = cpufreq_quick_get(policy->cpu);
227228
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−
234229 for_each_cpu(cpu, policy->related_cpus) {
235230 u32 load;
236231
@@ -240,22 +235,13 @@ static int cpufreq_get_requested_power(struct thermal_cooling_device *cdev, · 3 unmodified lines
240235 load = 0;
241236
242237 total_load += load;
243− if (load_cpu)
244− load_cpu[i] = load;
245−
246− i++;
247238 }
248239
249240 cpufreq_cdev->last_load = total_load;
250241
251242 *power = get_dynamic_power(cpufreq_cdev, freq);
252243
253− if (load_cpu) {
254− trace_thermal_power_cpu_get_power(policy->related_cpus, freq,
255− load_cpu, i, *power);
256−
257− kfree(load_cpu);
258− }
244+ trace_thermal_power_cpu_get_power_simple(policy->cpu, *power);
259245
260246 return 0;
261247 }
@@ -270,9 +256,8 @@ static int cpufreq_get_requested_power(struct thermal_cooling_device *cdev, · 8 unmodified lines
270256 * milliwatts assuming 100% load. Store the calculated power in
271257 * @power.
272258 *
273− * Return: 0 on success, -EINVAL if the cooling device state could not
274− * be converted into a frequency or other -E* if there was an error
275− * when calculating the static power.
259+ * Return: 0 on success, -EINVAL if the cooling device state is bigger
260+ * than maximum allowed.
276261 */
277262 static int cpufreq_state2power(struct thermal_cooling_device *cdev,
278263 unsigned long state, u32 *power)
@@ -302,15 +287,11 @@ static int cpufreq_state2power(struct thermal_cooling_device *cdev, · 23 unmodified lines
302287 * Calculate a cooling device state for the cpus described by @cdev
303288 * that would allow them to consume at most @power mW and store it in
304289 * @state. Note that this calculation depends on external factors
305− * such as the cpu load or the current static power. Calling this
306− * function with the same power as input can yield different cooling
307− * device states depending on those external factors.
308− *
309− * Return: 0 on success, -ENODEV if no cpus are online or -EINVAL if
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.
290+ * such as the CPUs load. Calling this function with the same power
291+ * as input can yield different cooling device states depending on those
292+ * external factors.
293+ *
294+ * Return: 0 on success, this function doesn't fail.
314295 */
315296 static int cpufreq_power2state(struct thermal_cooling_device *cdev,
316297 u32 power, unsigned long *state)
@@ -422,7 +403,7 @@ static unsigned int get_state_freq(struct cpufreq_cooling_device *cpufreq_cdev, · 105 unmodified lines
422403 * Callback for the thermal cooling device to return the cpufreq
423404 * max cooling state.
424405 *
425− * Return: 0 on success, an error code otherwise.
406+ * Return: 0 on success, this function doesn't fail.
426407 */
427408 static int cpufreq_get_max_state(struct thermal_cooling_device *cdev,
428409 unsigned long *state)
@@ -441,7 +422,7 @@ static int cpufreq_get_max_state(struct thermal_cooling_device *cdev, · 12 unmodified lines
441422 * Callback for the thermal cooling device to return the cpufreq
442423 * current cooling state.
443424 *
444− * Return: 0 on success, an error code otherwise.
425+ * Return: 0 on success, this function doesn't fail.
445426 */
446427 static int cpufreq_get_cur_state(struct thermal_cooling_device *cdev,
447428 unsigned long *state)
@@ -492,14 +473,6 @@ static int cpufreq_set_cur_state(struct thermal_cooling_device *cdev, · 44 unmodified lines
492473 return ret;
493474 }
494475
495−/* Bind cpufreq callbacks to thermal cooling device ops */
496−
497−static 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−
503476 /**
504477 * __cpufreq_cooling_register - helper function to create cpufreq cooling device
505478 * @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
508481 * @em: Energy Model of the cpufreq policy
509482 *
510483 * This interface function registers the cpufreq cooling device with the name
511− * "thermal-cpufreq-%x". This api can support multiple instances of cpufreq
484+ * "cpufreq-%s". This API can support multiple instances of cpufreq
512485 * cooling devices. It also gives the opportunity to link the cooling device
513486 * with a device tree node, in order to bind it via the thermal DT code.
514487 *
@@ -561,7 +534,10 @@ __cpufreq_cooling_register(struct device_node *np, · 46 unmodified lines
561534 /* max_level is an index, not a counter */
562535 cpufreq_cdev->max_level = i - 1;
563536
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;
565541
566542 #ifdef CONFIG_THERMAL_GOV_POWER_ALLOCATOR
567543 if (em_is_sane(cpufreq_cdev, em)) {
@@ -616,8 +592,8 @@ free_cdev: · 48 unmodified lines
616592 * @policy: cpufreq policy
617593 *
618594 * This interface function registers the cpufreq cooling device with the name
619− * "thermal-cpufreq-%x". This api can support multiple instances of cpufreq
620− * cooling devices.
595+ * "cpufreq-%s". This API can support multiple instances of cpufreq cooling
596+ * devices.
621597 *
622598 * Return: a valid struct thermal_cooling_device pointer on success,
623599 * on failure, it returns a corresponding ERR_PTR().
@@ -634,17 +610,14 @@ EXPORT_SYMBOL_GPL(cpufreq_cooling_register); · 10 unmodified lines
634610 * @policy: cpufreq policy
635611 *
636612 * This interface function registers the cpufreq cooling device with the name
637− * "thermal-cpufreq-%x". This api can support multiple instances of cpufreq
638− * cooling devices. Using this API, the cpufreq cooling device will be
639− * linked to the device tree node provided.
613+ * "cpufreq-%s". This API can support multiple instances of cpufreq cooling
614+ * devices. Using this API, the cpufreq cooling device will be linked to the
615+ * device tree node provided.
640616 *
641617 * Using this function, the cooling device will implement the power
642− * extensions by using a simple cpu power model. The cpus must have
618+ * extensions by using the Energy Model (if present). The cpus must have
643619 * registered their OPPs using the OPP library.
644620 *
645− * It also takes into account, if property present in policy CPU node, the
646− * static power consumed by the cpu.
647− *
648621 * Return: a valid struct thermal_cooling_device pointer on success,
649622 * and NULL on failure.
650623 */
@@ -680,7 +653,7 @@ EXPORT_SYMBOL_GPL(of_cpufreq_cooling_register); · 29 unmodified lines
680653 * cpufreq_cooling_unregister - function to remove cpufreq cooling device.
681654 * @cdev: thermal cooling device pointer.
682655 *
683− * This interface function unregisters the "thermal-cpufreq-%x" cooling device.
656+ * This interface function unregisters the "cpufreq-%x" cooling device.
684657 */
685658 void cpufreq_cooling_unregister(struct thermal_cooling_device *cdev)
686659 {
drivers/thermal/db8500_thermal.c+6−28
@@ -53,7 +53,6 @@ static const unsigned long db8500_thermal_points[] = { · 52 unmodified lines
5353
5454 struct db8500_thermal_zone {
5555 struct thermal_zone_device *tz;
56− enum thermal_trend trend;
5756 unsigned long interpolated_temp;
5857 unsigned int cur_index;
5958 };
@@ -73,24 +72,12 @@ static int db8500_thermal_get_temp(void *data, int *temp) · 13 unmodified lines
7372 return 0;
7473 }
7574
76−/* Callback to get temperature changing trend */
77−static 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−
8675 static struct thermal_zone_of_device_ops thdev_ops = {
8776 .get_temp = db8500_thermal_get_temp,
88− .get_trend = db8500_thermal_get_trend,
8977 };
9078
9179 static void db8500_thermal_update_config(struct db8500_thermal_zone *th,
9280 unsigned int idx,
93− enum thermal_trend trend,
9481 unsigned long next_low,
9582 unsigned long next_high)
9683 {
@@ -98,7 +85,6 @@ static void db8500_thermal_update_config(struct db8500_thermal_zone *th, · 1 unmodified line
9885
9986 th->cur_index = idx;
10087 th->interpolated_temp = (next_low + next_high)/2;
101− th->trend = trend;
10288
10389 /*
10490 * 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
127113 }
128114 idx -= 1;
129115
130− db8500_thermal_update_config(th, idx, THERMAL_TREND_DROPPING,
131− next_low, next_high);
116+ db8500_thermal_update_config(th, idx, next_low, next_high);
132117 dev_dbg(&th->tz->device,
133118 "PRCMU set max %ld, min %ld\n", next_high, next_low);
134119
@@ -149,8 +134,7 @@ static irqreturn_t prcmu_high_irq_handler(int irq, void *irq_data) · 14 unmodified lines
149134 next_low = db8500_thermal_points[idx];
150135 idx += 1;
151136
152− db8500_thermal_update_config(th, idx, THERMAL_TREND_RAISING,
153− next_low, next_high);
137+ db8500_thermal_update_config(th, idx, next_low, next_high);
154138
155139 dev_dbg(&th->tz->device,
156140 "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
174158 return -ENOMEM;
175159
176160 low_irq = platform_get_irq_byname(pdev, "IRQ_HOTMON_LOW");
177− if (low_irq < 0) {
178− dev_err(dev, "Get IRQ_HOTMON_LOW failed\n");
161+ if (low_irq < 0)
179162 return low_irq;
180− }
181163
182164 ret = devm_request_threaded_irq(dev, low_irq, NULL,
183165 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
188170 }
189171
190172 high_irq = platform_get_irq_byname(pdev, "IRQ_HOTMON_HIGH");
191− if (high_irq < 0) {
192− dev_err(dev, "Get IRQ_HOTMON_HIGH failed\n");
173+ if (high_irq < 0)
193174 return high_irq;
194− }
195175
196176 ret = devm_request_threaded_irq(dev, high_irq, NULL,
197177 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
210190 dev_info(dev, "thermal zone sensor registered\n");
211191
212192 /* Start measuring at the lowest point */
213− db8500_thermal_update_config(th, 0, THERMAL_TREND_STABLE,
214− PRCMU_DEFAULT_LOW_TEMP,
193+ db8500_thermal_update_config(th, 0, PRCMU_DEFAULT_LOW_TEMP,
215194 db8500_thermal_points[0]);
216195
217196 platform_set_drvdata(pdev, th);
@@ -232,8 +211,7 @@ static int db8500_thermal_resume(struct platform_device *pdev) · 14 unmodified lines
232211 struct db8500_thermal_zone *th = platform_get_drvdata(pdev);
233212
234213 /* Resume and start measuring at the lowest point */
235− db8500_thermal_update_config(th, 0, THERMAL_TREND_STABLE,
236− PRCMU_DEFAULT_LOW_TEMP,
214+ db8500_thermal_update_config(th, 0, PRCMU_DEFAULT_LOW_TEMP,
237215 db8500_thermal_points[0]);
238216
239217 return 0;
drivers/thermal/devfreq_cooling.c+9−18
@@ -28,6 +28,7 @@ · 27 unmodified lines
2828 * struct devfreq_cooling_device - Devfreq cooling device
2929 * devfreq_cooling_device registered.
3030 * @cdev: Pointer to associated thermal cooling device.
31+ * @cooling_ops: devfreq callbacks to thermal cooling device ops
3132 * @devfreq: Pointer to associated devfreq device.
3233 * @cooling_state: Current cooling state.
3334 * @freq_table: Pointer to a table with the frequencies sorted in descending
@@ -48,6 +49,7 @@ · 14 unmodified lines
4849 */
4950 struct devfreq_cooling_device {
5051 struct thermal_cooling_device *cdev;
52+ struct thermal_cooling_device_ops cooling_ops;
5153 struct devfreq *devfreq;
5254 unsigned long cooling_state;
5355 u32 *freq_table;
@@ -301,12 +303,6 @@ static int devfreq_cooling_power2state(struct thermal_cooling_device *cdev, · 247 unmodified lines
301303 return 0;
302304 }
303305
304−static 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−
310306 /**
311307 * devfreq_cooling_gen_tables() - Generate frequency table.
312308 * @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
374370 char *name;
375371 int err, num_opps;
376372
377− ops = kmemdup(&devfreq_cooling_ops, sizeof(*ops), GFP_KERNEL);
378− if (!ops)
379− return ERR_PTR(-ENOMEM);
380373
381374 dfc = kzalloc(sizeof(*dfc), GFP_KERNEL);
382− if (!dfc) {
383− err = -ENOMEM;
384− goto free_ops;
385− }
375+ if (!dfc)
376+ return ERR_PTR(-ENOMEM);
386377
387378 dfc->devfreq = df;
388379
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+
389385 em = em_pd_get(dev);
390386 if (em && !em_is_artificial(em)) {
391387 dfc->em_pd = em;
@@ -448,8 +444,6 @@ free_table: · 56 unmodified lines
448444 kfree(dfc->freq_table);
449445 free_dfc:
450446 kfree(dfc);
451−free_ops:
452− kfree(ops);
453447
454448 return ERR_PTR(err);
455449 }
@@ -531,13 +525,11 @@ EXPORT_SYMBOL_GPL(devfreq_cooling_em_register); · 75 unmodified lines
531525 void devfreq_cooling_unregister(struct thermal_cooling_device *cdev)
532526 {
533527 struct devfreq_cooling_device *dfc;
534− const struct thermal_cooling_device_ops *ops;
535528 struct device *dev;
536529
537530 if (IS_ERR_OR_NULL(cdev))
538531 return;
539532
540− ops = cdev->ops;
541533 dfc = cdev->devdata;
542534 dev = dfc->devfreq->dev.parent;
543535
@@ -548,6 +540,5 @@ void devfreq_cooling_unregister(struct thermal_cooling_device *cdev) · 4 unmodified lines
548540
549541 kfree(dfc->freq_table);
550542 kfree(dfc);
551− kfree(ops);
552543 }
553544 EXPORT_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
2525 int trip_temp;
2626 enum thermal_trip_type trip_type;
2727
28− if (tz->trips == 0 || !tz->ops->get_trip_temp)
28+ if (tz->num_trips == 0 || !tz->ops->get_trip_temp)
2929 return 0;
3030
31− for (count = 0; count < tz->trips; count++) {
31+ for (count = 0; count < tz->num_trips; count++) {
3232 tz->ops->get_trip_temp(tz, count, &trip_temp);
3333 if (tz->temperature < trip_temp)
3434 break;
@@ -53,7 +53,7 @@ static long get_target_state(struct thermal_zone_device *tz, · 18 unmodified lines
5353
5454 cdev->ops->get_max_state(cdev, &max_state);
5555
56− return (long)(percentage * level * max_state) / (100 * tz->trips);
56+ return (long)(percentage * level * max_state) / (100 * tz->num_trips);
5757 }
5858
5959 /**
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
527527 last_active = INVALID_TRIP;
528528 last_passive = INVALID_TRIP;
529529
530− for (i = 0; i < tz->trips; i++) {
530+ for (i = 0; i < tz->num_trips; i++) {
531531 enum thermal_trip_type type;
532532 int ret;
533533
@@ -668,7 +668,7 @@ static int power_allocator_bind(struct thermal_zone_device *tz) · 134 unmodified lines
668668
669669 get_governor_trips(tz, params);
670670
671− if (tz->trips > 0) {
671+ if (tz->num_trips > 0) {
672672 ret = tz->ops->get_trip_temp(tz,
673673 params->trip_max_desired_temperature,
674674 &control_temp);
drivers/thermal/gov_step_wise.c+4−22
@@ -11,6 +11,7 @@ · 10 unmodified lines
1111 */
1212
1313 #include <linux/thermal.h>
14+#include <linux/minmax.h>
1415 #include <trace/events/thermal.h>
1516
1617 #include "thermal_core.h"
@@ -52,10 +53,7 @@ static unsigned long get_target_state(struct thermal_instance *instance, · 35 unmodified lines
5253
5354 if (!instance->initialized) {
5455 if (throttle) {
55− next_target = (cur_state + 1) >= instance->upper ?
56− instance->upper :
57− ((cur_state + 1) < instance->lower ?
58− instance->lower : (cur_state + 1));
56+ next_target = clamp((cur_state + 1), instance->lower, instance->upper);
5957 } else {
6058 next_target = THERMAL_NO_TARGET;
6159 }
@@ -66,35 +64,19 @@ static unsigned long get_target_state(struct thermal_instance *instance, · 4 unmodified lines
6664 switch (trend) {
6765 case THERMAL_TREND_RAISING:
6866 if (throttle) {
69− next_target = cur_state < instance->upper ?
70− (cur_state + 1) : instance->upper;
71− if (next_target < instance->lower)
72− next_target = instance->lower;
67+ next_target = clamp((cur_state + 1), instance->lower, instance->upper);
7368 }
7469 break;
75− case THERMAL_TREND_RAISE_FULL:
76− if (throttle)
77− next_target = instance->upper;
78− break;
7970 case THERMAL_TREND_DROPPING:
8071 if (cur_state <= instance->lower) {
8172 if (!throttle)
8273 next_target = THERMAL_NO_TARGET;
8374 } else {
8475 if (!throttle) {
85− next_target = cur_state - 1;
86− if (next_target > instance->upper)
87− next_target = instance->upper;
76+ next_target = clamp((cur_state - 1), instance->lower, instance->upper);
8877 }
8978 }
9079 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;
9880 default:
9981 break;
10082 }
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
207207 return 0;
208208 }
209209
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−
218210 /* Do not check temperature if it is not s2idle */
219211 if (pm_suspend_via_firmware())
220212 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
105105 }
106106
107107 /*
108−* tj-max is is interesting because threshold is set relative to this
108+* tj-max is interesting because threshold is set relative to this
109109 * temperature.
110110 */
111111 static 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
151151 /* 300 milli celsius steps */
152152 while (i--)
153153 derived_table[i] = derived_table[i + 1] - 300;
154− /* case 0 */
155− derived_table[i] = derived_table[i + 1] - 300;
156154 }
157155
158156 /*
@@ -433,7 +431,7 @@ static int k3_j72xx_bandgap_probe(struct platform_device *pdev) · 274 unmodified lines
433431 GFP_KERNEL);
434432 if (!derived_table) {
435433 ret = -ENOMEM;
436− goto err_alloc;
434+ goto err_free_ref_table;
437435 }
438436
439437 /* 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
483481 if (IS_ERR(ti_thermal)) {
484482 dev_err(bgp->dev, "thermal zone device is NULL\n");
485483 ret = PTR_ERR(ti_thermal);
486− goto err_alloc;
484+ goto err_free_ref_table;
487485 }
488486 }
489487
@@ -514,6 +512,9 @@ static int k3_j72xx_bandgap_probe(struct platform_device *pdev) · 24 unmodified lines
514512
515513 return 0;
516514
515+err_free_ref_table:
516+ kfree(ref_table);
517+
517518 err_alloc:
518519 pm_runtime_put_sync(&pdev->dev);
519520 pm_runtime_disable(&pdev->dev);
@@ -529,11 +530,11 @@ static int k3_j72xx_bandgap_remove(struct platform_device *pdev) · 9 unmodified lines
529530 return 0;
530531 }
531532
532−const struct k3_j72xx_bandgap_data k3_j72xx_bandgap_j721e_data = {
533+static const struct k3_j72xx_bandgap_data k3_j72xx_bandgap_j721e_data = {
533534 .has_errata_i2128 = 1,
534535 };
535536
536−const struct k3_j72xx_bandgap_data k3_j72xx_bandgap_j7200_data = {
537+static const struct k3_j72xx_bandgap_data k3_j72xx_bandgap_j7200_data = {
537538 .has_errata_i2128 = 0,
538539 };
539540
drivers/thermal/qcom/qcom-spmi-adc-tm5.c+5−0
@@ -20,6 +20,8 @@ · 19 unmodified lines
2020 #include <linux/thermal.h>
2121 #include <asm-generic/unaligned.h>
2222
23+#include "../thermal_hwmon.h"
24+
2325 /*
2426 * Thermal monitoring block consists of 8 (ADC_TM5_NUM_CHANNELS) channels. Each
2527 * 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
687689 return PTR_ERR(tzd);
688690 }
689691 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");
690695 }
691696
692697 return 0;
drivers/thermal/qcom/qcom-spmi-temp-alarm.c+5−0
@@ -16,6 +16,7 @@ · 15 unmodified lines
1616 #include <linux/thermal.h>
1717
1818 #include "../thermal_core.h"
19+#include "../thermal_hwmon.h"
1920
2021 #define QPNP_TM_REG_DIG_MAJOR 0x01
2122 #define QPNP_TM_REG_TYPE 0x04
@@ -458,6 +459,10 @@ static int qpnp_tm_probe(struct platform_device *pdev) · 436 unmodified lines
458459 return ret;
459460 }
460461
462+ if (devm_thermal_add_hwmon_sysfs(chip->tz_dev))
463+ dev_warn(&pdev->dev,
464+ "Failed to add hwmon sysfs attributes\n");
465+
461466 ret = devm_request_threaded_irq(&pdev->dev, irq, NULL, qpnp_tm_isr,
462467 IRQF_ONESHOT, node->name, chip);
463468 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
933933 return priv->ops->get_temp(s, temp);
934934 }
935935
936−static 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−
947936 static int __maybe_unused tsens_suspend(struct device *dev)
948937 {
949938 struct tsens_priv *priv = dev_get_drvdata(dev);
@@ -1004,7 +993,6 @@ MODULE_DEVICE_TABLE(of, tsens_table); · 54 unmodified lines
1004993
1005994 static const struct thermal_zone_of_device_ops tsens_of_ops = {
1006995 .get_temp = tsens_get_temp,
1007− .get_trend = tsens_get_trend,
1008996 .set_trips = tsens_set_trips,
1009997 };
1010998
drivers/thermal/qcom/tsens.h+0−2
@@ -65,7 +65,6 @@ struct tsens_sensor { · 64 unmodified lines
6565 * @disable: Function to disable the tsens device
6666 * @suspend: Function to suspend the tsens device
6767 * @resume: Function to resume the tsens device
68− * @get_trend: Function to get the thermal/temp trend
6968 */
7069 struct tsens_ops {
7170 /* mandatory callbacks */
@@ -77,7 +76,6 @@ struct tsens_ops { · 5 unmodified lines
7776 void (*disable)(struct tsens_priv *priv);
7877 int (*suspend)(struct tsens_priv *priv);
7978 int (*resume)(struct tsens_priv *priv);
80− int (*get_trend)(struct tsens_sensor *s, enum thermal_trend *trend);
8179 };
8280
8381 #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
511511 zone = devm_thermal_zone_of_sensor_register(dev, i, tsc,
512512 &rcar_gen3_tz_of_ops);
513513 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);
515515 ret = PTR_ERR(zone);
516516 goto error_unregister;
517517 }
@@ -533,7 +533,7 @@ static int rcar_gen3_thermal_probe(struct platform_device *pdev) · 15 unmodified lines
533533 if (ret < 0)
534534 goto error_unregister;
535535
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);
537537 }
538538
539539 if (!priv->num_tscs) {
drivers/thermal/rzg2l_thermal.c+11−7
@@ -47,7 +47,7 @@ · 46 unmodified lines
4747
4848 #define TS_CODE_AVE_SCALE(x) ((x) * 1000000)
4949 #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 */
5151
5252 #define RZG2L_THERMAL_GRAN 500 /* milli Celsius */
5353 #define RZG2L_TSU_SS_TIMEOUT_US 1000
@@ -80,7 +80,8 @@ static int rzg2l_thermal_get_temp(void *devdata, int *temp) · 26 unmodified lines
8080 int val, i;
8181
8282 for (i = 0; i < TS_CODE_CAP_TIMES ; i++) {
83− /* TSU repeats measurement at 20 microseconds intervals and
83+ /*
84+ * TSU repeats measurement at 20 microseconds intervals and
8485 * automatically updates the results of measurement. As per
8586 * the HW manual for measuring temperature we need to read 8
8687 * values consecutively and then take the average.
@@ -92,16 +93,18 @@ static int rzg2l_thermal_get_temp(void *devdata, int *temp) · 5 unmodified lines
9293
9394 ts_code_ave = result / TS_CODE_CAP_TIMES;
9495
95− /* Calculate actual sensor value by applying curvature correction formula
96+ /*
97+ * Calculate actual sensor value by applying curvature correction formula
9698 * dsensor = ts_code_ave / (1 + ts_code_ave * 0.000013). Here we are doing
9799 * integer calculation by scaling all the values by 1000000.
98100 */
99101 dsensor = TS_CODE_AVE_SCALE(ts_code_ave) /
100102 (TS_CODE_AVE_SCALE(1) + (ts_code_ave * CURVATURE_CORRECTION_CONST));
101103
102− /* The temperature Tj is calculated by the formula
104+ /*
105+ * The temperature Tj is calculated by the formula
103106 * 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.
105108 */
106109 val = ((dsensor - priv->calib1) * (MCELSIUS(165) /
107110 (priv->calib0 - priv->calib1))) - MCELSIUS(40);
@@ -122,7 +125,8 @@ static int rzg2l_thermal_init(struct rzg2l_thermal_priv *priv) · 14 unmodified lines
122125 rzg2l_thermal_write(priv, TSU_SM, TSU_SM_NORMAL_MODE);
123126 rzg2l_thermal_write(priv, TSU_ST, 0);
124127
125− /* Before setting the START bit, TSU should be in normal operating
128+ /*
129+ * Before setting the START bit, TSU should be in normal operating
126130 * mode. As per the HW manual, it will take 60 µs to place the TSU
127131 * into normal operating mode.
128132 */
@@ -217,7 +221,7 @@ static int rzg2l_thermal_probe(struct platform_device *pdev) · 88 unmodified lines
217221 if (ret)
218222 goto err;
219223
220− dev_dbg(dev, "TSU probed with %s caliberation values",
224+ dev_dbg(dev, "TSU probed with %s calibration values",
221225 rzg2l_thermal_read(priv, OTPTSUTRIM_REG(0)) ? "hw" : "sw");
222226
223227 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
237237 * The calibration data on the H6 is the ambient temperature and
238238 * sensor values that are filled during the factory test stage.
239239 *
240− * The unit of stored FT temperature is 0.1 degreee celusis.
240+ * The unit of stored FT temperature is 0.1 degree celsius.
241241 *
242242 * We need to calculate a delta between measured and caluclated
243243 * 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
633633 return 0;
634634 }
635635
636−static 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−
667636 static void thermal_irq_enable(struct tegra_thermctl_zone *zn)
668637 {
669638 u32 r;
@@ -716,7 +685,6 @@ static int tegra_thermctl_set_trips(void *data, int lo, int hi) · 46 unmodified lines
716685 static const struct thermal_zone_of_device_ops tegra_of_thermal_ops = {
717686 .get_temp = tegra_thermctl_get_temp,
718687 .set_trip_temp = tegra_thermctl_set_trip_temp,
719− .get_trend = tegra_thermctl_get_trend,
720688 .set_trips = tegra_thermctl_set_trips,
721689 };
722690
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
316316 *hot_trip = 85000;
317317 *crit_trip = 90000;
318318
319− for (i = 0; i < tzd->trips; i++) {
319+ for (i = 0; i < tzd->num_trips; i++) {
320320 enum thermal_trip_type type;
321321 int trip_temp;
322322
drivers/thermal/thermal_core.c+47−32
@@ -340,12 +340,8 @@ void thermal_zone_device_critical(struct thermal_zone_device *tz) · 339 unmodified lines
340340 EXPORT_SYMBOL(thermal_zone_device_critical);
341341
342342 static 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)
344344 {
345− int trip_temp;
346−
347− tz->ops->get_trip_temp(tz, trip, &trip_temp);
348−
349345 /* If we have not crossed the trip_temp, we do not care. */
350346 if (trip_temp <= 0 || tz->temperature < trip_temp)
351347 return;
@@ -384,7 +380,7 @@ static void handle_thermal_trip(struct thermal_zone_device *tz, int trip) · 32 unmodified lines
384380 }
385381
386382 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);
388384 else
389385 handle_non_critical_trips(tz, trip);
390386 /*
@@ -505,7 +501,7 @@ void thermal_zone_device_update(struct thermal_zone_device *tz, · 114 unmodified lines
505501
506502 tz->notify_event = event;
507503
508− for (count = 0; count < tz->trips; count++)
504+ for (count = 0; count < tz->num_trips; count++)
509505 handle_thermal_trip(tz, count);
510506 }
511507 EXPORT_SYMBOL_GPL(thermal_zone_device_update);
@@ -630,7 +626,7 @@ int thermal_zone_bind_cooling_device(struct thermal_zone_device *tz, · 118 unmodified lines
630626 unsigned long max_state;
631627 int result, ret;
632628
633− if (trip >= tz->trips || trip < 0)
629+ if (trip >= tz->num_trips || trip < 0)
634630 return -EINVAL;
635631
636632 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
667663 dev->target = THERMAL_NO_TARGET;
668664 dev->weight = weight;
669665
670− result = ida_simple_get(&tz->ida, 0, 0, GFP_KERNEL);
666+ result = ida_alloc(&tz->ida, GFP_KERNEL);
671667 if (result < 0)
672668 goto free_mem;
673669
@@ -721,7 +717,7 @@ remove_trip_file: · 47 unmodified lines
721717 remove_symbol_link:
722718 sysfs_remove_link(&tz->device.kobj, dev->name);
723719 release_ida:
724− ida_simple_remove(&tz->ida, dev->id);
720+ ida_free(&tz->ida, dev->id);
725721 free_mem:
726722 kfree(dev);
727723 return result;
@@ -768,7 +764,7 @@ unbind: · 40 unmodified lines
768764 device_remove_file(&tz->device, &pos->weight_attr);
769765 device_remove_file(&tz->device, &pos->attr);
770766 sysfs_remove_link(&tz->device.kobj, pos->name);
771− ida_simple_remove(&tz->ida, pos->id);
767+ ida_free(&tz->ida, pos->id);
772768 kfree(pos);
773769 return 0;
774770 }
@@ -811,7 +807,7 @@ static void __bind(struct thermal_zone_device *tz, int mask, · 36 unmodified lines
811807 {
812808 int i, ret;
813809
814− for (i = 0; i < tz->trips; i++) {
810+ for (i = 0; i < tz->num_trips; i++) {
815811 if (mask & (1 << i)) {
816812 unsigned long upper, lower;
817813
@@ -901,7 +897,7 @@ __thermal_cooling_device_register(struct device_node *np, · 83 unmodified lines
901897 if (!cdev)
902898 return ERR_PTR(-ENOMEM);
903899
904− ret = ida_simple_get(&thermal_cdev_ida, 0, 0, GFP_KERNEL);
900+ ret = ida_alloc(&thermal_cdev_ida, GFP_KERNEL);
905901 if (ret < 0)
906902 goto out_kfree_cdev;
907903 cdev->id = ret;
@@ -952,7 +948,7 @@ out_kfree_type: · 44 unmodified lines
952948 put_device(&cdev->device);
953949 cdev = NULL;
954950 out_ida_remove:
955− ida_simple_remove(&thermal_cdev_ida, id);
951+ ida_free(&thermal_cdev_ida, id);
956952 out_kfree_cdev:
957953 kfree(cdev);
958954 return ERR_PTR(ret);
@@ -1057,7 +1053,7 @@ static void __unbind(struct thermal_zone_device *tz, int mask, · 98 unmodified lines
10571053 {
10581054 int i;
10591055
1060− for (i = 0; i < tz->trips; i++)
1056+ for (i = 0; i < tz->num_trips; i++)
10611057 if (mask & (1 << i))
10621058 thermal_zone_unbind_cooling_device(tz, i, cdev);
10631059 }
@@ -1111,7 +1107,7 @@ void thermal_cooling_device_unregister(struct thermal_cooling_device *cdev) · 47 unmodified lines
11111107
11121108 mutex_unlock(&thermal_list_lock);
11131109
1114− ida_simple_remove(&thermal_cdev_ida, cdev->id);
1110+ ida_free(&thermal_cdev_ida, cdev->id);
11151111 device_del(&cdev->device);
11161112 thermal_cooling_device_destroy_sysfs(cdev);
11171113 kfree(cdev->type);
@@ -1159,10 +1155,18 @@ exit: · 41 unmodified lines
11591155 mutex_unlock(&thermal_list_lock);
11601156 }
11611157
1158+static 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+
11621165 /**
1163− * thermal_zone_device_register() - register a new thermal zone device
1166+ * thermal_zone_device_register_with_trips() - register a new thermal zone device
11641167 * @type: the thermal zone device type
1165− * @trips: the number of trip points the thermal zone support
1168+ * @trips: a pointer to an array of thermal trips
1169+ * @num_trips: the number of trip points the thermal zone support
11661170 * @mask: a bit string indicating the writeablility of trip points
11671171 * @devdata: private device data
11681172 * @ops: standard thermal zone device callbacks
@@ -1184,10 +1188,10 @@ exit: · 15 unmodified lines
11841188 * IS_ERR*() helpers.
11851189 */
11861190 struct thermal_zone_device *
1187−thermal_zone_device_register(const char *type, int trips, int mask,
1188− void *devdata, struct thermal_zone_device_ops *ops,
1189− struct thermal_zone_params *tzp, int passive_delay,
1190− int polling_delay)
1191+thermal_zone_device_register_with_trips(const char *type, struct thermal_trip *trips, int num_trips, int mask,
1192+ void *devdata, struct thermal_zone_device_ops *ops,
1193+ struct thermal_zone_params *tzp, int passive_delay,
1194+ int polling_delay)
11911195 {
11921196 struct thermal_zone_device *tz;
11931197 enum thermal_trip_type trip_type;
@@ -1198,27 +1202,27 @@ thermal_zone_device_register(const char *type, int trips, int mask, · 4 unmodified lines
11981202 struct thermal_governor *governor;
11991203
12001204 if (!type || strlen(type) == 0) {
1201− pr_err("Error: No thermal zone type defined\n");
1205+ pr_err("No thermal zone type defined\n");
12021206 return ERR_PTR(-EINVAL);
12031207 }
12041208
12051209 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",
12071211 type, THERMAL_NAME_LENGTH);
12081212 return ERR_PTR(-EINVAL);
12091213 }
12101214
1211− if (trips > THERMAL_MAX_TRIPS || trips < 0 || mask >> trips) {
1212− pr_err("Error: Incorrect number of thermal trips\n");
1215+ if (num_trips > THERMAL_MAX_TRIPS || num_trips < 0 || mask >> num_trips) {
1216+ pr_err("Incorrect number of thermal trips\n");
12131217 return ERR_PTR(-EINVAL);
12141218 }
12151219
12161220 if (!ops) {
1217− pr_err("Error: Thermal zone device ops not defined\n");
1221+ pr_err("Thermal zone device ops not defined\n");
12181222 return ERR_PTR(-EINVAL);
12191223 }
12201224
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))
12221226 return ERR_PTR(-EINVAL);
12231227
12241228 tz = kzalloc(sizeof(*tz), GFP_KERNEL);
@@ -1228,7 +1232,7 @@ thermal_zone_device_register(const char *type, int trips, int mask, · 3 unmodified lines
12281232 INIT_LIST_HEAD(&tz->thermal_instances);
12291233 ida_init(&tz->ida);
12301234 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);
12321236 if (id < 0) {
12331237 result = id;
12341238 goto free_tz;
@@ -1249,6 +1253,7 @@ thermal_zone_device_register(const char *type, int trips, int mask, · 14 unmodified lines
12491253 tz->device.class = &thermal_class;
12501254 tz->devdata = devdata;
12511255 tz->trips = trips;
1256+ tz->num_trips = num_trips;
12521257
12531258 thermal_set_delay_jiffies(&tz->passive_delay_jiffies, passive_delay);
12541259 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
12661271 if (result)
12671272 goto release_device;
12681273
1269− for (count = 0; count < trips; count++) {
1274+ for (count = 0; count < num_trips; count++) {
12701275 if (tz->ops->get_trip_type(tz, count, &trip_type) ||
12711276 tz->ops->get_trip_temp(tz, count, &trip_temp) ||
12721277 !trip_temp)
@@ -1319,11 +1324,21 @@ release_device: · 46 unmodified lines
13191324 put_device(&tz->device);
13201325 tz = NULL;
13211326 remove_id:
1322− ida_simple_remove(&thermal_tz_ida, id);
1327+ ida_free(&thermal_tz_ida, id);
13231328 free_tz:
13241329 kfree(tz);
13251330 return ERR_PTR(result);
13261331 }
1332+
1333+struct 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+}
13271342 EXPORT_SYMBOL_GPL(thermal_zone_device_register);
13281343
13291344 /**
@@ -1379,7 +1394,7 @@ void thermal_zone_device_unregister(struct thermal_zone_device *tz) · 49 unmodified lines
13791394 thermal_set_governor(tz, NULL);
13801395
13811396 thermal_remove_hwmon_sysfs(tz);
1382− ida_simple_remove(&thermal_tz_ida, tz->id);
1397+ ida_free(&thermal_tz_ida, tz->id);
13831398 ida_destroy(&tz->ida);
13841399 mutex_destroy(&tz->lock);
13851400 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
6868 void thermal_cdev_update(struct thermal_cooling_device *);
6969 void __thermal_cdev_update(struct thermal_cooling_device *cdev);
7070
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− */
78−struct thermal_trip {
79− struct device_node *np;
80− int temperature;
81− int hysteresis;
82− enum thermal_trip_type type;
83−};
84−
8571 int get_tz_trend(struct thermal_zone_device *tz, int trip);
8672
8773 struct thermal_instance *
@@ -126,7 +112,6 @@ int thermal_build_list_of_policies(char *buf); · 38 unmodified lines
126112
127113 /* Helpers */
128114 void thermal_zone_set_trips(struct thermal_zone_device *tz);
129−void thermal_set_delay_jiffies(unsigned long *delay_jiffies, int delay_ms);
130115
131116 /* sysfs I/F */
132117 int 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
3939
4040 return trend;
4141 }
42−EXPORT_SYMBOL(get_tz_trend);
4342
4443 struct thermal_instance *
4544 get_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
9089 ret = tz->ops->get_temp(tz, temp);
9190
9291 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++) {
9493 ret = tz->ops->get_trip_type(tz, count, &type);
9594 if (!ret && type == THERMAL_TRIP_CRITICAL) {
9695 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
138137 if (!tz->ops->set_trips || !tz->ops->get_trip_hyst)
139138 goto exit;
140139
141− for (i = 0; i < tz->trips; i++) {
140+ for (i = 0; i < tz->num_trips; i++) {
142141 int trip_low;
143142
144143 tz->ops->get_trip_temp(tz, i, &trip_temp);
@@ -175,13 +174,6 @@ exit: · 30 unmodified lines
175174 mutex_unlock(&tz->lock);
176175 }
177176
178−void 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−
185177 static void thermal_cdev_set_cur_state(struct thermal_cooling_device *cdev,
186178 int target)
187179 {
@@ -228,7 +220,6 @@ void thermal_cdev_update(struct thermal_cooling_device *cdev) · 40 unmodified lines
228220 }
229221 mutex_unlock(&cdev->lock);
230222 }
231−EXPORT_SYMBOL(thermal_cdev_update);
232223
233224 /**
234225 * 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
469469
470470 mutex_lock(&tz->lock);
471471
472− for (i = 0; i < tz->trips; i++) {
472+ for (i = 0; i < tz->num_trips; i++) {
473473
474474 enum thermal_trip_type type;
475475 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
118118 */
119119 int of_thermal_get_ntrips(struct thermal_zone_device *tz)
120120 {
121− struct __thermal_zone *data = tz->devdata;
122−
123− if (!data || IS_ERR(data))
124− return -ENODEV;
125−
126− return data->ntrips;
121+ return tz->num_trips;
127122 }
128123 EXPORT_SYMBOL_GPL(of_thermal_get_ntrips);
129124
@@ -139,9 +134,7 @@ EXPORT_SYMBOL_GPL(of_thermal_get_ntrips); · 9 unmodified lines
139134 */
140135 bool of_thermal_is_trip_valid(struct thermal_zone_device *tz, int trip)
141136 {
142− struct __thermal_zone *data = tz->devdata;
143−
144− if (!data || trip >= data->ntrips || trip < 0)
137+ if (trip >= tz->num_trips || trip < 0)
145138 return false;
146139
147140 return true;
@@ -161,12 +154,7 @@ EXPORT_SYMBOL_GPL(of_thermal_is_trip_valid); · 13 unmodified lines
161154 const struct thermal_trip *
162155 of_thermal_get_trip_points(struct thermal_zone_device *tz)
163156 {
164− struct __thermal_zone *data = tz->devdata;
165−
166− if (!data)
167− return NULL;
168−
169− return data->trips;
157+ return tz->trips;
170158 }
171159 EXPORT_SYMBOL_GPL(of_thermal_get_trip_points);
172160
@@ -281,12 +269,10 @@ static int of_thermal_unbind(struct thermal_zone_device *thermal, · 108 unmodified lines
281269 static int of_thermal_get_trip_type(struct thermal_zone_device *tz, int trip,
282270 enum thermal_trip_type *type)
283271 {
284− struct __thermal_zone *data = tz->devdata;
285−
286− if (trip >= data->ntrips || trip < 0)
272+ if (trip >= tz->num_trips || trip < 0)
287273 return -EDOM;
288274
289− *type = data->trips[trip].type;
275+ *type = tz->trips[trip].type;
290276
291277 return 0;
292278 }
@@ -294,12 +280,10 @@ static int of_thermal_get_trip_type(struct thermal_zone_device *tz, int trip, · 1 unmodified line
294280 static int of_thermal_get_trip_temp(struct thermal_zone_device *tz, int trip,
295281 int *temp)
296282 {
297− struct __thermal_zone *data = tz->devdata;
298−
299− if (trip >= data->ntrips || trip < 0)
283+ if (trip >= tz->num_trips || trip < 0)
300284 return -EDOM;
301285
302− *temp = data->trips[trip].temperature;
286+ *temp = tz->trips[trip].temperature;
303287
304288 return 0;
305289 }
@@ -309,7 +293,7 @@ static int of_thermal_set_trip_temp(struct thermal_zone_device *tz, int trip, · 3 unmodified lines
309293 {
310294 struct __thermal_zone *data = tz->devdata;
311295
312− if (trip >= data->ntrips || trip < 0)
296+ if (trip >= tz->num_trips || trip < 0)
313297 return -EDOM;
314298
315299 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
321305 }
322306
323307 /* thermal framework should take care of data->mask & (1 << trip) */
324− data->trips[trip].temperature = temp;
308+ tz->trips[trip].temperature = temp;
325309
326310 return 0;
327311 }
@@ -329,12 +313,10 @@ static int of_thermal_set_trip_temp(struct thermal_zone_device *tz, int trip, · 1 unmodified line
329313 static int of_thermal_get_trip_hyst(struct thermal_zone_device *tz, int trip,
330314 int *hyst)
331315 {
332− struct __thermal_zone *data = tz->devdata;
333−
334− if (trip >= data->ntrips || trip < 0)
316+ if (trip >= tz->num_trips || trip < 0)
335317 return -EDOM;
336318
337− *hyst = data->trips[trip].hysteresis;
319+ *hyst = tz->trips[trip].hysteresis;
338320
339321 return 0;
340322 }
@@ -342,13 +324,11 @@ static int of_thermal_get_trip_hyst(struct thermal_zone_device *tz, int trip, · 1 unmodified line
342324 static int of_thermal_set_trip_hyst(struct thermal_zone_device *tz, int trip,
343325 int hyst)
344326 {
345− struct __thermal_zone *data = tz->devdata;
346−
347− if (trip >= data->ntrips || trip < 0)
327+ if (trip >= tz->num_trips || trip < 0)
348328 return -EDOM;
349329
350330 /* thermal framework should take care of data->mask & (1 << trip) */
351− data->trips[trip].hysteresis = hyst;
331+ tz->trips[trip].hysteresis = hyst;
352332
353333 return 0;
354334 }
@@ -356,12 +336,11 @@ static int of_thermal_set_trip_hyst(struct thermal_zone_device *tz, int trip, · 1 unmodified line
356336 static int of_thermal_get_crit_temp(struct thermal_zone_device *tz,
357337 int *temp)
358338 {
359− struct __thermal_zone *data = tz->devdata;
360339 int i;
361340
362− for (i = 0; i < data->ntrips; i++)
363− if (data->trips[i].type == THERMAL_TRIP_CRITICAL) {
364− *temp = data->trips[i].temperature;
341+ for (i = 0; i < tz->num_trips; i++)
342+ if (tz->trips[i].type == THERMAL_TRIP_CRITICAL) {
343+ *temp = tz->trips[i].temperature;
365344 return 0;
366345 }
367346
@@ -671,6 +650,35 @@ EXPORT_SYMBOL_GPL(devm_thermal_zone_of_sensor_unregister); · 303 unmodified lines
671650
672651 /*** functions parsing device tree nodes ***/
673652
653+static 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;
676+out:
677+ of_node_put(trips);
678+
679+ return i;
680+}
681+
674682 /**
675683 * thermal_of_populate_bind_params - parse and fill cooling map data
676684 * @np: DT node containing a cooling-map node
@@ -685,15 +693,15 @@ EXPORT_SYMBOL_GPL(devm_thermal_zone_of_sensor_unregister); · 8 unmodified lines
685693 *
686694 * Return: 0 on success, proper error code otherwise
687695 */
688−static int thermal_of_populate_bind_params(struct device_node *np,
689− struct __thermal_bind_params *__tbp,
690− struct thermal_trip *trips,
691− int ntrips)
696+static int thermal_of_populate_bind_params(struct device_node *tz_np,
697+ struct device_node *np,
698+ struct __thermal_bind_params *__tbp)
692699 {
693700 struct of_phandle_args cooling_spec;
694701 struct __thermal_cooling_bind_param *__tcbp;
695702 struct device_node *trip;
696703 int ret, i, count;
704+ int trip_id;
697705 u32 prop;
698706
699707 /* Default weight. Usage is optional */
@@ -708,18 +716,14 @@ static int thermal_of_populate_bind_params(struct device_node *np, · 8 unmodified lines
708716 return -ENODEV;
709717 }
710718
711− /* match using device_node */
712− for (i = 0; i < ntrips; i++)
713− if (trip == trips[i].np) {
714− __tbp->trip_id = i;
715− break;
716− }
717−
718− if (i == ntrips) {
719− ret = -ENODEV;
719+ trip_id = of_find_trip_id(tz_np, trip);
720+ if (trip_id < 0) {
721+ ret = trip_id;
720722 goto end;
721723 }
722724
725+ __tbp->trip_id = trip_id;
726+
723727 count = of_count_phandle_with_args(np, "cooling-device",
724728 "#cooling-cells");
725729 if (count <= 0) {
@@ -843,13 +847,56 @@ static int thermal_of_populate_trip(struct device_node *np, · 117 unmodified lines
843847 return ret;
844848 }
845849
846− /* Required for cooling map matching */
847− trip->np = np;
848− of_node_get(np);
849−
850850 return 0;
851851 }
852852
853+static 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+
891+out_kfree:
892+ kfree(tt);
893+ *ntrips = 0;
894+out_of_node_put:
895+ of_node_put(trips);
896+
897+ return ERR_PTR(ret);
898+}
899+
853900 /**
854901 * thermal_of_build_thermal_zone - parse and fill one thermal zone data
855902 * @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
909956 tz->offset = 0;
910957 }
911958
912− /* trips */
913− child = of_get_child_by_name(np, "trips");
914−
915− /* No trips provided */
916− if (!child)
959+ tz->trips = thermal_of_trips_init(np, &tz->ntrips);
960+ if (IS_ERR(tz->trips)) {
961+ ret = PTR_ERR(tz->trips);
917962 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;
927963 }
928964
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−
938965 /* cooling-maps */
939966 child = of_get_child_by_name(np, "cooling-maps");
940967
@@ -954,10 +981,11 @@ __init *thermal_of_build_thermal_zone(struct device_node *np) · 13 unmodified lines
954981
955982 i = 0;
956983 for_each_child_of_node(child, gchild) {
957− ret = thermal_of_populate_bind_params(gchild, &tz->tbps[i++],
958− tz->trips, tz->ntrips);
959− if (ret)
984+ ret = thermal_of_populate_bind_params(np, gchild, &tz->tbps[i++]);
985+ if (ret) {
986+ of_node_put(gchild);
960987 goto free_tbps;
988+ }
961989 }
962990
963991 finish:
@@ -978,10 +1006,7 @@ free_tbps: · 14 unmodified lines
9781006
9791007 kfree(tz->tbps);
9801008 free_trips:
981− for (i = 0; i < tz->ntrips; i++)
982− of_node_put(tz->trips[i].np);
9831009 kfree(tz->trips);
984− of_node_put(gchild);
9851010 free_tz:
9861011 kfree(tz);
9871012 of_node_put(child);
@@ -1004,8 +1029,6 @@ static __init void of_thermal_free_zone(struct __thermal_zone *tz) · 16 unmodified lines
10041029 }
10051030
10061031 kfree(tz->tbps);
1007− for (i = 0; i < tz->ntrips; i++)
1008− of_node_put(tz->trips[i].np);
10091032 kfree(tz->trips);
10101033 kfree(tz);
10111034 }
@@ -1103,11 +1126,9 @@ int __init of_parse_thermal_zones(void) · 91 unmodified lines
11031126 tzp->slope = tz->slope;
11041127 tzp->offset = tz->offset;
11051128
1106− zone = thermal_zone_device_register(child->name, tz->ntrips,
1107− mask, tz,
1108− ops, tzp,
1109− tz->passive_delay,
1110− tz->polling_delay);
1129+ zone = thermal_zone_device_register_with_trips(child->name, tz->trips, tz->ntrips,
1130+ mask, tz, ops, tzp, tz->passive_delay,
1131+ tz->polling_delay);
11111132 if (IS_ERR(zone)) {
11121133 pr_err("Failed to build %pOFn zone %ld\n", child,
11131134 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
416416 int indx;
417417
418418 /* This function works only for zones with at least one trip */
419− if (tz->trips <= 0)
419+ if (tz->num_trips <= 0)
420420 return -EINVAL;
421421
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),
423423 GFP_KERNEL);
424424 if (!tz->trip_type_attrs)
425425 return -ENOMEM;
426426
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),
428428 GFP_KERNEL);
429429 if (!tz->trip_temp_attrs) {
430430 kfree(tz->trip_type_attrs);
@@ -432,7 +432,7 @@ static int create_trip_attrs(struct thermal_zone_device *tz, int mask) · 1 unmodified line
432432 }
433433
434434 if (tz->ops->get_trip_hyst) {
435− tz->trip_hyst_attrs = kcalloc(tz->trips,
435+ tz->trip_hyst_attrs = kcalloc(tz->num_trips,
436436 sizeof(*tz->trip_hyst_attrs),
437437 GFP_KERNEL);
438438 if (!tz->trip_hyst_attrs) {
@@ -442,7 +442,7 @@ static int create_trip_attrs(struct thermal_zone_device *tz, int mask) · 3 unmodified lines
442442 }
443443 }
444444
445− attrs = kcalloc(tz->trips * 3 + 1, sizeof(*attrs), GFP_KERNEL);
445+ attrs = kcalloc(tz->num_trips * 3 + 1, sizeof(*attrs), GFP_KERNEL);
446446 if (!attrs) {
447447 kfree(tz->trip_type_attrs);
448448 kfree(tz->trip_temp_attrs);
@@ -451,7 +451,7 @@ static int create_trip_attrs(struct thermal_zone_device *tz, int mask) · 2 unmodified lines
451451 return -ENOMEM;
452452 }
453453
454− for (indx = 0; indx < tz->trips; indx++) {
454+ for (indx = 0; indx < tz->num_trips; indx++) {
455455 /* create trip type attribute */
456456 snprintf(tz->trip_type_attrs[indx].name, THERMAL_NAME_LENGTH,
457457 "trip_point_%d_type", indx);
@@ -478,7 +478,7 @@ static int create_trip_attrs(struct thermal_zone_device *tz, int mask) · 20 unmodified lines
478478 tz->trip_temp_attrs[indx].attr.store =
479479 trip_point_temp_store;
480480 }
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;
482482
483483 /* create Optional trip hyst attribute */
484484 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
496496 tz->trip_hyst_attrs[indx].attr.store =
497497 trip_point_hyst_store;
498498 }
499− attrs[indx + tz->trips * 2] =
499+ attrs[indx + tz->num_trips * 2] =
500500 &tz->trip_hyst_attrs[indx].attr.attr;
501501 }
502− attrs[tz->trips * 3] = NULL;
502+ attrs[tz->num_trips * 3] = NULL;
503503
504504 tz->trips_attribute_group.attrs = attrs;
505505
@@ -540,7 +540,7 @@ int thermal_zone_create_device_groups(struct thermal_zone_device *tz, · 34 unmodified lines
540540 for (i = 0; i < size - 2; i++)
541541 groups[i] = thermal_zone_attribute_groups[i];
542542
543− if (tz->trips) {
543+ if (tz->num_trips) {
544544 result = create_trip_attrs(tz, mask);
545545 if (result) {
546546 kfree(groups);
@@ -561,7 +561,7 @@ void thermal_zone_destroy_device_groups(struct thermal_zone_device *tz) · 14 unmodified lines
561561 if (!tz)
562562 return;
563563
564− if (tz->trips)
564+ if (tz->num_trips)
565565 destroy_trip_attrs(tz);
566566
567567 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
226226 /*
227227 * One TALERT interrupt: Two sources
228228 * 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_hot
229+ * unmask t_cold else mask t_cold and unmask t_hot
230230 */
231231 if (t_hot) {
232232 ctrl &= ~tsr->mask_hot_mask;
include/linux/thermal.h+22−4
@@ -40,8 +40,6 @@ enum thermal_trend { · 39 unmodified lines
4040 THERMAL_TREND_STABLE, /* temperature is stable */
4141 THERMAL_TREND_RAISING, /* temperature is raising */
4242 THERMAL_TREND_DROPPING, /* temperature is dropping */
43− THERMAL_TREND_RAISE_FULL, /* apply highest cooling action */
44− THERMAL_TREND_DROP_FULL, /* apply lowest cooling action */
4543 };
4644
4745 /* Thermal notification reason */
@@ -80,6 +78,18 @@ struct thermal_zone_device_ops { · 32 unmodified lines
8078 void (*critical)(struct thermal_zone_device *);
8179 };
8280
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+ */
87+struct thermal_trip {
88+ int temperature;
89+ int hysteresis;
90+ enum thermal_trip_type type;
91+};
92+
8393 struct thermal_cooling_device_ops {
8494 int (*get_max_state) (struct thermal_cooling_device *, unsigned long *);
8595 int (*get_cur_state) (struct thermal_cooling_device *, unsigned long *);
@@ -113,7 +123,8 @@ struct thermal_cooling_device { · 27 unmodified lines
113123 * @trip_hyst_attrs: attributes for trip points for sysfs: trip hysteresis
114124 * @mode: current mode of this thermal zone
115125 * @devdata: private pointer for device private data
116− * @trips: number of trip points the thermal zone supports
126+ * @trips: an array of struct thermal_trip
127+ * @num_trips: number of trip points the thermal zone supports
117128 * @trips_disabled; bitmap for disabled trips
118129 * @passive_delay_jiffies: number of jiffies to wait between polls when
119130 * performing passive cooling.
@@ -153,7 +164,8 @@ struct thermal_zone_device { · 33 unmodified lines
153164 struct thermal_attr *trip_hyst_attrs;
154165 enum thermal_device_mode mode;
155166 void *devdata;
156− int trips;
167+ struct thermal_trip *trips;
168+ int num_trips;
157169 unsigned long trips_disabled; /* bitmap for disabled trips */
158170 unsigned long passive_delay_jiffies;
159171 unsigned long polling_delay_jiffies;
@@ -366,8 +378,14 @@ void devm_thermal_zone_of_sensor_unregister(struct device *dev, · 206 unmodified lines
366378 struct thermal_zone_device *thermal_zone_device_register(const char *, int, int,
367379 void *, struct thermal_zone_device_ops *,
368380 struct thermal_zone_params *, int, int);
381+
369382 void thermal_zone_device_unregister(struct thermal_zone_device *);
370383
384+struct thermal_zone_device *
385+thermal_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+
371389 int thermal_zone_bind_cooling_device(struct thermal_zone_device *, int,
372390 struct thermal_cooling_device *,
373391 unsigned long, unsigned long,
include/trace/events/thermal.h+8−20
@@ -92,34 +92,22 @@ TRACE_EVENT(thermal_zone_trip, · 91 unmodified lines
9292 );
9393
9494 #ifdef CONFIG_CPU_THERMAL
95−TRACE_EVENT(thermal_power_cpu_get_power,
96− TP_PROTO(const struct cpumask *cpus, unsigned long freq, u32 *load,
97− size_t load_len, u32 dynamic_power),
95+TRACE_EVENT(thermal_power_cpu_get_power_simple,
96+ TP_PROTO(int cpu, u32 power),
9897
99− TP_ARGS(cpus, freq, load, load_len, dynamic_power),
98+ TP_ARGS(cpu, power),
10099
101100 TP_STRUCT__entry(
102− __bitmask(cpumask, num_possible_cpus())
103− __field(unsigned long, freq )
104− __dynamic_array(u32, load, load_len)
105− __field(size_t, load_len )
106− __field(u32, dynamic_power )
101+ __field(int, cpu)
102+ __field(u32, power)
107103 ),
108104
109105 TP_fast_assign(
110− __assign_bitmask(cpumask, cpumask_bits(cpus),
111− num_possible_cpus());
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;
106+ __entry->cpu = cpu;
107+ __entry->power = power;
117108 ),
118109
119− TP_printk("cpus=%s freq=%lu load={%s} dynamic_power=%d",
120− __get_bitmask(cpumask), __entry->freq,
121− __print_array(__get_dynamic_array(load), __entry->load_len, 4),
122− __entry->dynamic_power)
110+ TP_printk("cpu=%d power=%u", __entry->cpu, __entry->power)
123111 );
124112
125113 TRACE_EVENT(thermal_power_cpu_limit,
tools/thermal/tmon/pid.c+1−1
@@ -27,7 +27,7 @@ · 26 unmodified lines
2727
2828 /**************************************************************************
2929 * PID (Proportional-Integral-Derivative) controller is commonly used in
30− * linear control system, consider the the process.
30+ * linear control system, consider the process.
3131 * G(s) = U(s)/E(s)
3232 * kp = proportional gain
3333 * ki = integral gain
tools/thermal/tmon/tmon.h+3−0
@@ -27,6 +27,9 @@ · 26 unmodified lines
2727 #define NR_LINES_TZDATA 1
2828 #define TMON_LOG_FILE "/var/tmp/tmon.log"
2929
30+#include <sys/time.h>
31+#include <pthread.h>
32+
3033 extern unsigned long ticktime;
3134 extern double time_elapsed;
3235 extern 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