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 ...
Unified · Split
| @@ -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 | + }; | |
| @@ -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 | − | |
| @@ -8,9 +8,9 @@ $schema: http://devicetree.org/meta-schemas/core.yaml# · 7 unmodified lines | ||
| 8 | 8 | title: Renesas R-Car Gen3 Thermal Sensor |
| 9 | 9 | |
| 10 | 10 | 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. | |
| 14 | 14 | |
| 15 | 15 | maintainers: |
| 16 | 16 | - Niklas Söderlund <niklas.soderlund@ragnatech.se> |
| @@ -27,6 +27,7 @@ properties: · 10 unmodified lines | ||
| 27 | 27 | - renesas,r8a77965-thermal # R-Car M3-N |
| 28 | 28 | - renesas,r8a77980-thermal # R-Car V3H |
| 29 | 29 | - renesas,r8a779a0-thermal # R-Car V3U |
| 30 | + - renesas,r8a779f0-thermal # R-Car S4-8 | |
| 30 | 31 | |
| 31 | 32 | reg: true |
| 32 | 33 | |
| @@ -57,31 +58,38 @@ required: · 24 unmodified lines | ||
| 57 | 58 | - "#thermal-sensor-cells" |
| 58 | 59 | |
| 59 | 60 | 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 | |
| 66 | 66 | then: |
| 67 | 67 | properties: |
| 68 | 68 | reg: |
| 69 | − minItems: 2 | |
| 70 | 69 | items: |
| 70 | + - description: TSC0 registers | |
| 71 | 71 | - description: TSC1 registers |
| 72 | 72 | - description: TSC2 registers |
| 73 | 73 | - description: TSC3 registers |
| 74 | − required: | |
| 75 | − - interrupts | |
| 74 | + - description: TSC4 registers | |
| 76 | 75 | else: |
| 77 | 76 | properties: |
| 78 | 77 | reg: |
| 78 | + minItems: 2 | |
| 79 | 79 | items: |
| 80 | − - description: TSC0 registers | |
| 81 | 80 | - description: TSC1 registers |
| 82 | 81 | - description: TSC2 registers |
| 83 | 82 | - 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 | |
| 85 | 93 | |
| 86 | 94 | additionalProperties: false |
| 87 | 95 | |
| @@ -19949,6 +19949,7 @@ F: Documentation/ABI/testing/sysfs-class-thermal · 19948 unmodified lines | ||
| 19949 | 19949 | F: Documentation/devicetree/bindings/thermal/ |
| 19950 | 19950 | F: Documentation/driver-api/thermal/ |
| 19951 | 19951 | F: drivers/thermal/ |
| 19952 | +F: include/dt-bindings/thermal/ | |
| 19952 | 19953 | F: include/linux/cpu_cooling.h |
| 19953 | 19954 | F: include/linux/thermal.h |
| 19954 | 19955 | F: include/uapi/linux/thermal.h |
| @@ -60,6 +60,7 @@ struct time_in_idle { · 59 unmodified lines | ||
| 60 | 60 | * @cdev: thermal_cooling_device pointer to keep track of the |
| 61 | 61 | * registered cooling device. |
| 62 | 62 | * @policy: cpufreq policy. |
| 63 | + * @cooling_ops: cpufreq callbacks to thermal cooling device ops | |
| 63 | 64 | * @idle_time: idle time stats |
| 64 | 65 | * @qos_req: PM QoS contraint to apply |
| 65 | 66 | * |
| @@ -72,6 +73,7 @@ struct cpufreq_cooling_device { · 6 unmodified lines | ||
| 72 | 73 | unsigned int max_level; |
| 73 | 74 | struct em_perf_domain *em; |
| 74 | 75 | struct cpufreq_policy *policy; |
| 76 | + struct thermal_cooling_device_ops cooling_ops; | |
| 75 | 77 | #ifndef CONFIG_SMP |
| 76 | 78 | struct time_in_idle *idle_time; |
| 77 | 79 | #endif |
| @@ -211,7 +213,7 @@ static u32 get_dynamic_power(struct cpufreq_cooling_device *cpufreq_cdev, · 133 unmodified lines | ||
| 211 | 213 | * complex code may be needed if experiments show that it's not |
| 212 | 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 | */ |
| 216 | 218 | static int cpufreq_get_requested_power(struct thermal_cooling_device *cdev, |
| 217 | 219 | u32 *power) |
| @@ -221,16 +223,9 @@ static int cpufreq_get_requested_power(struct thermal_cooling_device *cdev, · 3 unmodified lines | ||
| 221 | 223 | u32 total_load = 0; |
| 222 | 224 | struct cpufreq_cooling_device *cpufreq_cdev = cdev->devdata; |
| 223 | 225 | struct cpufreq_policy *policy = cpufreq_cdev->policy; |
| 224 | − u32 *load_cpu = NULL; | |
| 225 | 226 | |
| 226 | 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 | 229 | for_each_cpu(cpu, policy->related_cpus) { |
| 235 | 230 | u32 load; |
| 236 | 231 | |
| @@ -240,22 +235,13 @@ static int cpufreq_get_requested_power(struct thermal_cooling_device *cdev, · 3 unmodified lines | ||
| 240 | 235 | load = 0; |
| 241 | 236 | |
| 242 | 237 | total_load += load; |
| 243 | − if (load_cpu) | |
| 244 | − load_cpu[i] = load; | |
| 245 | − | |
| 246 | − i++; | |
| 247 | 238 | } |
| 248 | 239 | |
| 249 | 240 | cpufreq_cdev->last_load = total_load; |
| 250 | 241 | |
| 251 | 242 | *power = get_dynamic_power(cpufreq_cdev, freq); |
| 252 | 243 | |
| 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); | |
| 259 | 245 | |
| 260 | 246 | return 0; |
| 261 | 247 | } |
| @@ -270,9 +256,8 @@ static int cpufreq_get_requested_power(struct thermal_cooling_device *cdev, · 8 unmodified lines | ||
| 270 | 256 | * milliwatts assuming 100% load. Store the calculated power in |
| 271 | 257 | * @power. |
| 272 | 258 | * |
| 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. | |
| 276 | 261 | */ |
| 277 | 262 | static int cpufreq_state2power(struct thermal_cooling_device *cdev, |
| 278 | 263 | unsigned long state, u32 *power) |
| @@ -302,15 +287,11 @@ static int cpufreq_state2power(struct thermal_cooling_device *cdev, · 23 unmodified lines | ||
| 302 | 287 | * Calculate a cooling device state for the cpus described by @cdev |
| 303 | 288 | * that would allow them to consume at most @power mW and store it in |
| 304 | 289 | * @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. | |
| 314 | 295 | */ |
| 315 | 296 | static int cpufreq_power2state(struct thermal_cooling_device *cdev, |
| 316 | 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 | 403 | * Callback for the thermal cooling device to return the cpufreq |
| 423 | 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 | */ |
| 427 | 408 | static int cpufreq_get_max_state(struct thermal_cooling_device *cdev, |
| 428 | 409 | unsigned long *state) |
| @@ -441,7 +422,7 @@ static int cpufreq_get_max_state(struct thermal_cooling_device *cdev, · 12 unmodified lines | ||
| 441 | 422 | * Callback for the thermal cooling device to return the cpufreq |
| 442 | 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 | */ |
| 446 | 427 | static int cpufreq_get_cur_state(struct thermal_cooling_device *cdev, |
| 447 | 428 | unsigned long *state) |
| @@ -492,14 +473,6 @@ static int cpufreq_set_cur_state(struct thermal_cooling_device *cdev, · 44 unmodified lines | ||
| 492 | 473 | return ret; |
| 493 | 474 | } |
| 494 | 475 | |
| 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 | − | |
| 503 | 476 | /** |
| 504 | 477 | * __cpufreq_cooling_register - helper function to create cpufreq cooling device |
| 505 | 478 | * @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 | 481 | * @em: Energy Model of the cpufreq policy |
| 509 | 482 | * |
| 510 | 483 | * 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 | |
| 512 | 485 | * cooling devices. It also gives the opportunity to link the cooling device |
| 513 | 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 | 534 | /* max_level is an index, not a counter */ |
| 562 | 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 | 542 | #ifdef CONFIG_THERMAL_GOV_POWER_ALLOCATOR |
| 567 | 543 | if (em_is_sane(cpufreq_cdev, em)) { |
| @@ -616,8 +592,8 @@ free_cdev: · 48 unmodified lines | ||
| 616 | 592 | * @policy: cpufreq policy |
| 617 | 593 | * |
| 618 | 594 | * 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. | |
| 621 | 597 | * |
| 622 | 598 | * Return: a valid struct thermal_cooling_device pointer on success, |
| 623 | 599 | * on failure, it returns a corresponding ERR_PTR(). |
| @@ -634,17 +610,14 @@ EXPORT_SYMBOL_GPL(cpufreq_cooling_register); · 10 unmodified lines | ||
| 634 | 610 | * @policy: cpufreq policy |
| 635 | 611 | * |
| 636 | 612 | * 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. | |
| 640 | 616 | * |
| 641 | 617 | * 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 | |
| 643 | 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 | 621 | * Return: a valid struct thermal_cooling_device pointer on success, |
| 649 | 622 | * and NULL on failure. |
| 650 | 623 | */ |
| @@ -680,7 +653,7 @@ EXPORT_SYMBOL_GPL(of_cpufreq_cooling_register); · 29 unmodified lines | ||
| 680 | 653 | * cpufreq_cooling_unregister - function to remove cpufreq cooling device. |
| 681 | 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 | */ |
| 685 | 658 | void cpufreq_cooling_unregister(struct thermal_cooling_device *cdev) |
| 686 | 659 | { |
| @@ -53,7 +53,6 @@ static const unsigned long db8500_thermal_points[] = { · 52 unmodified lines | ||
| 53 | 53 | |
| 54 | 54 | struct db8500_thermal_zone { |
| 55 | 55 | struct thermal_zone_device *tz; |
| 56 | − enum thermal_trend trend; | |
| 57 | 56 | unsigned long interpolated_temp; |
| 58 | 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 | 72 | return 0; |
| 74 | 73 | } |
| 75 | 74 | |
| 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 | − | |
| 86 | 75 | static struct thermal_zone_of_device_ops thdev_ops = { |
| 87 | 76 | .get_temp = db8500_thermal_get_temp, |
| 88 | − .get_trend = db8500_thermal_get_trend, | |
| 89 | 77 | }; |
| 90 | 78 | |
| 91 | 79 | static void db8500_thermal_update_config(struct db8500_thermal_zone *th, |
| 92 | 80 | unsigned int idx, |
| 93 | − enum thermal_trend trend, | |
| 94 | 81 | unsigned long next_low, |
| 95 | 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 | 86 | th->cur_index = idx; |
| 100 | 87 | th->interpolated_temp = (next_low + next_high)/2; |
| 101 | − th->trend = trend; | |
| 102 | 88 | |
| 103 | 89 | /* |
| 104 | 90 | * 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 | 114 | idx -= 1; |
| 129 | 115 | |
| 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); | |
| 132 | 117 | dev_dbg(&th->tz->device, |
| 133 | 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 | 134 | next_low = db8500_thermal_points[idx]; |
| 150 | 135 | idx += 1; |
| 151 | 136 | |
| 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); | |
| 154 | 138 | |
| 155 | 139 | dev_dbg(&th->tz->device, |
| 156 | 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 | 158 | return -ENOMEM; |
| 175 | 159 | |
| 176 | 160 | 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) | |
| 179 | 162 | return low_irq; |
| 180 | − } | |
| 181 | 163 | |
| 182 | 164 | ret = devm_request_threaded_irq(dev, low_irq, NULL, |
| 183 | 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 | 172 | 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) | |
| 193 | 174 | return high_irq; |
| 194 | − } | |
| 195 | 175 | |
| 196 | 176 | ret = devm_request_threaded_irq(dev, high_irq, NULL, |
| 197 | 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 | 190 | dev_info(dev, "thermal zone sensor registered\n"); |
| 211 | 191 | |
| 212 | 192 | /* 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, | |
| 215 | 194 | db8500_thermal_points[0]); |
| 216 | 195 | |
| 217 | 196 | platform_set_drvdata(pdev, th); |
| @@ -232,8 +211,7 @@ static int db8500_thermal_resume(struct platform_device *pdev) · 14 unmodified lines | ||
| 232 | 211 | struct db8500_thermal_zone *th = platform_get_drvdata(pdev); |
| 233 | 212 | |
| 234 | 213 | /* 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, | |
| 237 | 215 | db8500_thermal_points[0]); |
| 238 | 216 | |
| 239 | 217 | return 0; |
| @@ -28,6 +28,7 @@ · 27 unmodified lines | ||
| 28 | 28 | * struct devfreq_cooling_device - Devfreq cooling device |
| 29 | 29 | * devfreq_cooling_device registered. |
| 30 | 30 | * @cdev: Pointer to associated thermal cooling device. |
| 31 | + * @cooling_ops: devfreq callbacks to thermal cooling device ops | |
| 31 | 32 | * @devfreq: Pointer to associated devfreq device. |
| 32 | 33 | * @cooling_state: Current cooling state. |
| 33 | 34 | * @freq_table: Pointer to a table with the frequencies sorted in descending |
| @@ -48,6 +49,7 @@ · 14 unmodified lines | ||
| 48 | 49 | */ |
| 49 | 50 | struct devfreq_cooling_device { |
| 50 | 51 | struct thermal_cooling_device *cdev; |
| 52 | + struct thermal_cooling_device_ops cooling_ops; | |
| 51 | 53 | struct devfreq *devfreq; |
| 52 | 54 | unsigned long cooling_state; |
| 53 | 55 | u32 *freq_table; |
| @@ -301,12 +303,6 @@ static int devfreq_cooling_power2state(struct thermal_cooling_device *cdev, · 247 unmodified lines | ||
| 301 | 303 | return 0; |
| 302 | 304 | } |
| 303 | 305 | |
| 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 | − | |
| 310 | 306 | /** |
| 311 | 307 | * devfreq_cooling_gen_tables() - Generate frequency table. |
| 312 | 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 | 370 | char *name; |
| 375 | 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 | 374 | 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); | |
| 386 | 377 | |
| 387 | 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 | 385 | em = em_pd_get(dev); |
| 390 | 386 | if (em && !em_is_artificial(em)) { |
| 391 | 387 | dfc->em_pd = em; |
| @@ -448,8 +444,6 @@ free_table: · 56 unmodified lines | ||
| 448 | 444 | kfree(dfc->freq_table); |
| 449 | 445 | free_dfc: |
| 450 | 446 | kfree(dfc); |
| 451 | −free_ops: | |
| 452 | − kfree(ops); | |
| 453 | 447 | |
| 454 | 448 | return ERR_PTR(err); |
| 455 | 449 | } |
| @@ -531,13 +525,11 @@ EXPORT_SYMBOL_GPL(devfreq_cooling_em_register); · 75 unmodified lines | ||
| 531 | 525 | void devfreq_cooling_unregister(struct thermal_cooling_device *cdev) |
| 532 | 526 | { |
| 533 | 527 | struct devfreq_cooling_device *dfc; |
| 534 | − const struct thermal_cooling_device_ops *ops; | |
| 535 | 528 | struct device *dev; |
| 536 | 529 | |
| 537 | 530 | if (IS_ERR_OR_NULL(cdev)) |
| 538 | 531 | return; |
| 539 | 532 | |
| 540 | − ops = cdev->ops; | |
| 541 | 533 | dfc = cdev->devdata; |
| 542 | 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 | 541 | kfree(dfc->freq_table); |
| 550 | 542 | kfree(dfc); |
| 551 | − kfree(ops); | |
| 552 | 543 | } |
| 553 | 544 | EXPORT_SYMBOL_GPL(devfreq_cooling_unregister); |
| @@ -25,10 +25,10 @@ static int get_trip_level(struct thermal_zone_device *tz) · 24 unmodified lines | ||
| 25 | 25 | int trip_temp; |
| 26 | 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 | 29 | return 0; |
| 30 | 30 | |
| 31 | − for (count = 0; count < tz->trips; count++) { | |
| 31 | + for (count = 0; count < tz->num_trips; count++) { | |
| 32 | 32 | tz->ops->get_trip_temp(tz, count, &trip_temp); |
| 33 | 33 | if (tz->temperature < trip_temp) |
| 34 | 34 | break; |
| @@ -53,7 +53,7 @@ static long get_target_state(struct thermal_zone_device *tz, · 18 unmodified lines | ||
| 53 | 53 | |
| 54 | 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 | /** |
| @@ -527,7 +527,7 @@ static void get_governor_trips(struct thermal_zone_device *tz, · 526 unmodified lines | ||
| 527 | 527 | last_active = INVALID_TRIP; |
| 528 | 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 | 531 | enum thermal_trip_type type; |
| 532 | 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 | 669 | get_governor_trips(tz, params); |
| 670 | 670 | |
| 671 | − if (tz->trips > 0) { | |
| 671 | + if (tz->num_trips > 0) { | |
| 672 | 672 | ret = tz->ops->get_trip_temp(tz, |
| 673 | 673 | params->trip_max_desired_temperature, |
| 674 | 674 | &control_temp); |
| @@ -11,6 +11,7 @@ · 10 unmodified lines | ||
| 11 | 11 | */ |
| 12 | 12 | |
| 13 | 13 | #include <linux/thermal.h> |
| 14 | +#include <linux/minmax.h> | |
| 14 | 15 | #include <trace/events/thermal.h> |
| 15 | 16 | |
| 16 | 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 | 54 | if (!instance->initialized) { |
| 54 | 55 | 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); | |
| 59 | 57 | } else { |
| 60 | 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 | 64 | switch (trend) { |
| 67 | 65 | case THERMAL_TREND_RAISING: |
| 68 | 66 | 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); | |
| 73 | 68 | } |
| 74 | 69 | break; |
| 75 | − case THERMAL_TREND_RAISE_FULL: | |
| 76 | − if (throttle) | |
| 77 | − next_target = instance->upper; | |
| 78 | − break; | |
| 79 | 70 | case THERMAL_TREND_DROPPING: |
| 80 | 71 | if (cur_state <= instance->lower) { |
| 81 | 72 | if (!throttle) |
| 82 | 73 | next_target = THERMAL_NO_TARGET; |
| 83 | 74 | } else { |
| 84 | 75 | 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); | |
| 88 | 77 | } |
| 89 | 78 | } |
| 90 | 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 | 80 | default: |
| 99 | 81 | break; |
| 100 | 82 | } |
| @@ -207,14 +207,6 @@ static int pch_wpt_suspend(struct pch_thermal_device *ptd) · 206 unmodified lines | ||
| 207 | 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 | 210 | /* Do not check temperature if it is not s2idle */ |
| 219 | 211 | if (pm_suspend_via_firmware()) |
| 220 | 212 | return 0; |
| @@ -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 this | |
| 108 | +* tj-max is interesting because threshold is set relative to this | |
| 109 | 109 | * temperature. |
| 110 | 110 | */ |
| 111 | 111 | static int get_tj_max(int cpu, u32 *tj_max) |
| @@ -151,8 +151,6 @@ static int prep_lookup_table(struct err_values *err_vals, int *ref_table) · 150 unmodified lines | ||
| 151 | 151 | /* 300 milli celsius steps */ |
| 152 | 152 | while (i--) |
| 153 | 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 | 431 | GFP_KERNEL); |
| 434 | 432 | if (!derived_table) { |
| 435 | 433 | ret = -ENOMEM; |
| 436 | − goto err_alloc; | |
| 434 | + goto err_free_ref_table; | |
| 437 | 435 | } |
| 438 | 436 | |
| 439 | 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 | 481 | if (IS_ERR(ti_thermal)) { |
| 484 | 482 | dev_err(bgp->dev, "thermal zone device is NULL\n"); |
| 485 | 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 | 513 | return 0; |
| 516 | 514 | |
| 515 | +err_free_ref_table: | |
| 516 | + kfree(ref_table); | |
| 517 | + | |
| 517 | 518 | err_alloc: |
| 518 | 519 | pm_runtime_put_sync(&pdev->dev); |
| 519 | 520 | pm_runtime_disable(&pdev->dev); |
| @@ -529,11 +530,11 @@ static int k3_j72xx_bandgap_remove(struct platform_device *pdev) · 9 unmodified lines | ||
| 529 | 530 | return 0; |
| 530 | 531 | } |
| 531 | 532 | |
| 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 = { | |
| 533 | 534 | .has_errata_i2128 = 1, |
| 534 | 535 | }; |
| 535 | 536 | |
| 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 = { | |
| 537 | 538 | .has_errata_i2128 = 0, |
| 538 | 539 | }; |
| 539 | 540 | |
| @@ -20,6 +20,8 @@ · 19 unmodified lines | ||
| 20 | 20 | #include <linux/thermal.h> |
| 21 | 21 | #include <asm-generic/unaligned.h> |
| 22 | 22 | |
| 23 | +#include "../thermal_hwmon.h" | |
| 24 | + | |
| 23 | 25 | /* |
| 24 | 26 | * Thermal monitoring block consists of 8 (ADC_TM5_NUM_CHANNELS) channels. Each |
| 25 | 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 | 689 | return PTR_ERR(tzd); |
| 688 | 690 | } |
| 689 | 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 | 697 | return 0; |
| @@ -16,6 +16,7 @@ · 15 unmodified lines | ||
| 16 | 16 | #include <linux/thermal.h> |
| 17 | 17 | |
| 18 | 18 | #include "../thermal_core.h" |
| 19 | +#include "../thermal_hwmon.h" | |
| 19 | 20 | |
| 20 | 21 | #define QPNP_TM_REG_DIG_MAJOR 0x01 |
| 21 | 22 | #define QPNP_TM_REG_TYPE 0x04 |
| @@ -458,6 +459,10 @@ static int qpnp_tm_probe(struct platform_device *pdev) · 436 unmodified lines | ||
| 458 | 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 | 466 | ret = devm_request_threaded_irq(&pdev->dev, irq, NULL, qpnp_tm_isr, |
| 462 | 467 | IRQF_ONESHOT, node->name, chip); |
| 463 | 468 | if (ret < 0) |
| @@ -933,17 +933,6 @@ static int tsens_get_temp(void *data, int *temp) · 932 unmodified lines | ||
| 933 | 933 | return priv->ops->get_temp(s, temp); |
| 934 | 934 | } |
| 935 | 935 | |
| 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 | − | |
| 947 | 936 | static int __maybe_unused tsens_suspend(struct device *dev) |
| 948 | 937 | { |
| 949 | 938 | struct tsens_priv *priv = dev_get_drvdata(dev); |
| @@ -1004,7 +993,6 @@ MODULE_DEVICE_TABLE(of, tsens_table); · 54 unmodified lines | ||
| 1004 | 993 | |
| 1005 | 994 | static const struct thermal_zone_of_device_ops tsens_of_ops = { |
| 1006 | 995 | .get_temp = tsens_get_temp, |
| 1007 | − .get_trend = tsens_get_trend, | |
| 1008 | 996 | .set_trips = tsens_set_trips, |
| 1009 | 997 | }; |
| 1010 | 998 | |
| @@ -65,7 +65,6 @@ struct tsens_sensor { · 64 unmodified lines | ||
| 65 | 65 | * @disable: Function to disable the tsens device |
| 66 | 66 | * @suspend: Function to suspend the tsens device |
| 67 | 67 | * @resume: Function to resume the tsens device |
| 68 | − * @get_trend: Function to get the thermal/temp trend | |
| 69 | 68 | */ |
| 70 | 69 | struct tsens_ops { |
| 71 | 70 | /* mandatory callbacks */ |
| @@ -77,7 +76,6 @@ struct tsens_ops { · 5 unmodified lines | ||
| 77 | 76 | void (*disable)(struct tsens_priv *priv); |
| 78 | 77 | int (*suspend)(struct tsens_priv *priv); |
| 79 | 78 | int (*resume)(struct tsens_priv *priv); |
| 80 | − int (*get_trend)(struct tsens_sensor *s, enum thermal_trend *trend); | |
| 81 | 79 | }; |
| 82 | 80 | |
| 83 | 81 | #define REG_FIELD_FOR_EACH_SENSOR11(_name, _offset, _startbit, _stopbit) \ |
| @@ -511,7 +511,7 @@ static int rcar_gen3_thermal_probe(struct platform_device *pdev) · 510 unmodified lines | ||
| 511 | 511 | zone = devm_thermal_zone_of_sensor_register(dev, i, tsc, |
| 512 | 512 | &rcar_gen3_tz_of_ops); |
| 513 | 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 | 515 | ret = PTR_ERR(zone); |
| 516 | 516 | goto error_unregister; |
| 517 | 517 | } |
| @@ -533,7 +533,7 @@ static int rcar_gen3_thermal_probe(struct platform_device *pdev) · 15 unmodified lines | ||
| 533 | 533 | if (ret < 0) |
| 534 | 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 | 539 | if (!priv->num_tscs) { |
| @@ -47,7 +47,7 @@ · 46 unmodified lines | ||
| 47 | 47 | |
| 48 | 48 | #define TS_CODE_AVE_SCALE(x) ((x) * 1000000) |
| 49 | 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 | 52 | #define RZG2L_THERMAL_GRAN 500 /* milli Celsius */ |
| 53 | 53 | #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 | 80 | int val, i; |
| 81 | 81 | |
| 82 | 82 | 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 | |
| 84 | 85 | * automatically updates the results of measurement. As per |
| 85 | 86 | * the HW manual for measuring temperature we need to read 8 |
| 86 | 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 | 94 | ts_code_ave = result / TS_CODE_CAP_TIMES; |
| 94 | 95 | |
| 95 | − /* Calculate actual sensor value by applying curvature correction formula | |
| 96 | + /* | |
| 97 | + * Calculate actual sensor value by applying curvature correction formula | |
| 96 | 98 | * dsensor = ts_code_ave / (1 + ts_code_ave * 0.000013). Here we are doing |
| 97 | 99 | * integer calculation by scaling all the values by 1000000. |
| 98 | 100 | */ |
| 99 | 101 | dsensor = TS_CODE_AVE_SCALE(ts_code_ave) / |
| 100 | 102 | (TS_CODE_AVE_SCALE(1) + (ts_code_ave * CURVATURE_CORRECTION_CONST)); |
| 101 | 103 | |
| 102 | − /* The temperature Tj is calculated by the formula | |
| 104 | + /* | |
| 105 | + * The temperature Tj is calculated by the formula | |
| 103 | 106 | * 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 | 109 | val = ((dsensor - priv->calib1) * (MCELSIUS(165) / |
| 107 | 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 | 125 | rzg2l_thermal_write(priv, TSU_SM, TSU_SM_NORMAL_MODE); |
| 123 | 126 | rzg2l_thermal_write(priv, TSU_ST, 0); |
| 124 | 127 | |
| 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 | |
| 126 | 130 | * mode. As per the HW manual, it will take 60 µs to place the TSU |
| 127 | 131 | * into normal operating mode. |
| 128 | 132 | */ |
| @@ -217,7 +221,7 @@ static int rzg2l_thermal_probe(struct platform_device *pdev) · 88 unmodified lines | ||
| 217 | 221 | if (ret) |
| 218 | 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 | 225 | rzg2l_thermal_read(priv, OTPTSUTRIM_REG(0)) ? "hw" : "sw"); |
| 222 | 226 | |
| 223 | 227 | return 0; |
| @@ -237,7 +237,7 @@ static int sun50i_h6_ths_calibrate(struct ths_device *tmdev, · 236 unmodified lines | ||
| 237 | 237 | * The calibration data on the H6 is the ambient temperature and |
| 238 | 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 | 242 | * We need to calculate a delta between measured and caluclated |
| 243 | 243 | * register values and this will become a calibration offset. |
| @@ -633,37 +633,6 @@ static int tegra_thermctl_set_trip_temp(void *data, int trip, int temp) · 632 unmodified lines | ||
| 633 | 633 | return 0; |
| 634 | 634 | } |
| 635 | 635 | |
| 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 | − | |
| 667 | 636 | static void thermal_irq_enable(struct tegra_thermctl_zone *zn) |
| 668 | 637 | { |
| 669 | 638 | u32 r; |
| @@ -716,7 +685,6 @@ static int tegra_thermctl_set_trips(void *data, int lo, int hi) · 46 unmodified lines | ||
| 716 | 685 | static const struct thermal_zone_of_device_ops tegra_of_thermal_ops = { |
| 717 | 686 | .get_temp = tegra_thermctl_get_temp, |
| 718 | 687 | .set_trip_temp = tegra_thermctl_set_trip_temp, |
| 719 | − .get_trend = tegra_thermctl_get_trend, | |
| 720 | 688 | .set_trips = tegra_thermctl_set_trips, |
| 721 | 689 | }; |
| 722 | 690 | |
| @@ -316,7 +316,7 @@ static void tegra_tsensor_get_hw_channel_trips(struct thermal_zone_device *tzd, · 315 unmodified lines | ||
| 316 | 316 | *hot_trip = 85000; |
| 317 | 317 | *crit_trip = 90000; |
| 318 | 318 | |
| 319 | − for (i = 0; i < tzd->trips; i++) { | |
| 319 | + for (i = 0; i < tzd->num_trips; i++) { | |
| 320 | 320 | enum thermal_trip_type type; |
| 321 | 321 | int trip_temp; |
| 322 | 322 | |
| @@ -340,12 +340,8 @@ void thermal_zone_device_critical(struct thermal_zone_device *tz) · 339 unmodified lines | ||
| 340 | 340 | EXPORT_SYMBOL(thermal_zone_device_critical); |
| 341 | 341 | |
| 342 | 342 | 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) | |
| 344 | 344 | { |
| 345 | − int trip_temp; | |
| 346 | − | |
| 347 | − tz->ops->get_trip_temp(tz, trip, &trip_temp); | |
| 348 | − | |
| 349 | 345 | /* If we have not crossed the trip_temp, we do not care. */ |
| 350 | 346 | if (trip_temp <= 0 || tz->temperature < trip_temp) |
| 351 | 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 | 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 | 384 | else |
| 389 | 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 | 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 | 505 | handle_thermal_trip(tz, count); |
| 510 | 506 | } |
| 511 | 507 | 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 | ||
| 630 | 626 | unsigned long max_state; |
| 631 | 627 | int result, ret; |
| 632 | 628 | |
| 633 | − if (trip >= tz->trips || trip < 0) | |
| 629 | + if (trip >= tz->num_trips || trip < 0) | |
| 634 | 630 | return -EINVAL; |
| 635 | 631 | |
| 636 | 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 | 663 | dev->target = THERMAL_NO_TARGET; |
| 668 | 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 | 667 | if (result < 0) |
| 672 | 668 | goto free_mem; |
| 673 | 669 | |
| @@ -721,7 +717,7 @@ remove_trip_file: · 47 unmodified lines | ||
| 721 | 717 | remove_symbol_link: |
| 722 | 718 | sysfs_remove_link(&tz->device.kobj, dev->name); |
| 723 | 719 | release_ida: |
| 724 | − ida_simple_remove(&tz->ida, dev->id); | |
| 720 | + ida_free(&tz->ida, dev->id); | |
| 725 | 721 | free_mem: |
| 726 | 722 | kfree(dev); |
| 727 | 723 | return result; |
| @@ -768,7 +764,7 @@ unbind: · 40 unmodified lines | ||
| 768 | 764 | device_remove_file(&tz->device, &pos->weight_attr); |
| 769 | 765 | device_remove_file(&tz->device, &pos->attr); |
| 770 | 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 | 768 | kfree(pos); |
| 773 | 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 | 808 | int i, ret; |
| 813 | 809 | |
| 814 | − for (i = 0; i < tz->trips; i++) { | |
| 810 | + for (i = 0; i < tz->num_trips; i++) { | |
| 815 | 811 | if (mask & (1 << i)) { |
| 816 | 812 | unsigned long upper, lower; |
| 817 | 813 | |
| @@ -901,7 +897,7 @@ __thermal_cooling_device_register(struct device_node *np, · 83 unmodified lines | ||
| 901 | 897 | if (!cdev) |
| 902 | 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 | 901 | if (ret < 0) |
| 906 | 902 | goto out_kfree_cdev; |
| 907 | 903 | cdev->id = ret; |
| @@ -952,7 +948,7 @@ out_kfree_type: · 44 unmodified lines | ||
| 952 | 948 | put_device(&cdev->device); |
| 953 | 949 | cdev = NULL; |
| 954 | 950 | out_ida_remove: |
| 955 | − ida_simple_remove(&thermal_cdev_ida, id); | |
| 951 | + ida_free(&thermal_cdev_ida, id); | |
| 956 | 952 | out_kfree_cdev: |
| 957 | 953 | kfree(cdev); |
| 958 | 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 | 1054 | int i; |
| 1059 | 1055 | |
| 1060 | − for (i = 0; i < tz->trips; i++) | |
| 1056 | + for (i = 0; i < tz->num_trips; i++) | |
| 1061 | 1057 | if (mask & (1 << i)) |
| 1062 | 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 | 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 | 1111 | device_del(&cdev->device); |
| 1116 | 1112 | thermal_cooling_device_destroy_sysfs(cdev); |
| 1117 | 1113 | kfree(cdev->type); |
| @@ -1159,10 +1155,18 @@ exit: · 41 unmodified lines | ||
| 1159 | 1155 | mutex_unlock(&thermal_list_lock); |
| 1160 | 1156 | } |
| 1161 | 1157 | |
| 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 | + | |
| 1162 | 1165 | /** |
| 1163 | − * thermal_zone_device_register() - register a new thermal zone device | |
| 1166 | + * thermal_zone_device_register_with_trips() - register a new thermal zone device | |
| 1164 | 1167 | * @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 | |
| 1166 | 1170 | * @mask: a bit string indicating the writeablility of trip points |
| 1167 | 1171 | * @devdata: private device data |
| 1168 | 1172 | * @ops: standard thermal zone device callbacks |
| @@ -1184,10 +1188,10 @@ exit: · 15 unmodified lines | ||
| 1184 | 1188 | * IS_ERR*() helpers. |
| 1185 | 1189 | */ |
| 1186 | 1190 | 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) | |
| 1191 | 1195 | { |
| 1192 | 1196 | struct thermal_zone_device *tz; |
| 1193 | 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 | 1202 | struct thermal_governor *governor; |
| 1199 | 1203 | |
| 1200 | 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 | 1206 | return ERR_PTR(-EINVAL); |
| 1203 | 1207 | } |
| 1204 | 1208 | |
| 1205 | 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 | 1211 | type, THERMAL_NAME_LENGTH); |
| 1208 | 1212 | return ERR_PTR(-EINVAL); |
| 1209 | 1213 | } |
| 1210 | 1214 | |
| 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"); | |
| 1213 | 1217 | return ERR_PTR(-EINVAL); |
| 1214 | 1218 | } |
| 1215 | 1219 | |
| 1216 | 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 | 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 | 1226 | return ERR_PTR(-EINVAL); |
| 1223 | 1227 | |
| 1224 | 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 | 1232 | INIT_LIST_HEAD(&tz->thermal_instances); |
| 1229 | 1233 | ida_init(&tz->ida); |
| 1230 | 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 | 1236 | if (id < 0) { |
| 1233 | 1237 | result = id; |
| 1234 | 1238 | goto free_tz; |
| @@ -1249,6 +1253,7 @@ thermal_zone_device_register(const char *type, int trips, int mask, · 14 unmodified lines | ||
| 1249 | 1253 | tz->device.class = &thermal_class; |
| 1250 | 1254 | tz->devdata = devdata; |
| 1251 | 1255 | tz->trips = trips; |
| 1256 | + tz->num_trips = num_trips; | |
| 1252 | 1257 | |
| 1253 | 1258 | thermal_set_delay_jiffies(&tz->passive_delay_jiffies, passive_delay); |
| 1254 | 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 | 1271 | if (result) |
| 1267 | 1272 | goto release_device; |
| 1268 | 1273 | |
| 1269 | − for (count = 0; count < trips; count++) { | |
| 1274 | + for (count = 0; count < num_trips; count++) { | |
| 1270 | 1275 | if (tz->ops->get_trip_type(tz, count, &trip_type) || |
| 1271 | 1276 | tz->ops->get_trip_temp(tz, count, &trip_temp) || |
| 1272 | 1277 | !trip_temp) |
| @@ -1319,11 +1324,21 @@ release_device: · 46 unmodified lines | ||
| 1319 | 1324 | put_device(&tz->device); |
| 1320 | 1325 | tz = NULL; |
| 1321 | 1326 | remove_id: |
| 1322 | − ida_simple_remove(&thermal_tz_ida, id); | |
| 1327 | + ida_free(&thermal_tz_ida, id); | |
| 1323 | 1328 | free_tz: |
| 1324 | 1329 | kfree(tz); |
| 1325 | 1330 | return ERR_PTR(result); |
| 1326 | 1331 | } |
| 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 | +} | |
| 1327 | 1342 | EXPORT_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 | 1394 | thermal_set_governor(tz, NULL); |
| 1380 | 1395 | |
| 1381 | 1396 | thermal_remove_hwmon_sysfs(tz); |
| 1382 | − ida_simple_remove(&thermal_tz_ida, tz->id); | |
| 1397 | + ida_free(&thermal_tz_ida, tz->id); | |
| 1383 | 1398 | ida_destroy(&tz->ida); |
| 1384 | 1399 | mutex_destroy(&tz->lock); |
| 1385 | 1400 | device_unregister(&tz->device); |
| @@ -68,20 +68,6 @@ static inline bool cdev_is_power_actor(struct thermal_cooling_device *cdev) · 67 unmodified lines | ||
| 68 | 68 | void thermal_cdev_update(struct thermal_cooling_device *); |
| 69 | 69 | void __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 | − */ | |
| 78 | −struct thermal_trip { | |
| 79 | − struct device_node *np; | |
| 80 | − int temperature; | |
| 81 | − int hysteresis; | |
| 82 | − enum thermal_trip_type type; | |
| 83 | −}; | |
| 84 | − | |
| 85 | 71 | int get_tz_trend(struct thermal_zone_device *tz, int trip); |
| 86 | 72 | |
| 87 | 73 | struct thermal_instance * |
| @@ -126,7 +112,6 @@ int thermal_build_list_of_policies(char *buf); · 38 unmodified lines | ||
| 126 | 112 | |
| 127 | 113 | /* Helpers */ |
| 128 | 114 | void thermal_zone_set_trips(struct thermal_zone_device *tz); |
| 129 | −void thermal_set_delay_jiffies(unsigned long *delay_jiffies, int delay_ms); | |
| 130 | 115 | |
| 131 | 116 | /* sysfs I/F */ |
| 132 | 117 | int thermal_zone_create_device_groups(struct thermal_zone_device *, int); |
| @@ -39,7 +39,6 @@ int get_tz_trend(struct thermal_zone_device *tz, int trip) · 38 unmodified lines | ||
| 39 | 39 | |
| 40 | 40 | return trend; |
| 41 | 41 | } |
| 42 | −EXPORT_SYMBOL(get_tz_trend); | |
| 43 | 42 | |
| 44 | 43 | struct thermal_instance * |
| 45 | 44 | 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 | ||
| 90 | 89 | ret = tz->ops->get_temp(tz, temp); |
| 91 | 90 | |
| 92 | 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 | 93 | ret = tz->ops->get_trip_type(tz, count, &type); |
| 95 | 94 | if (!ret && type == THERMAL_TRIP_CRITICAL) { |
| 96 | 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 | 137 | if (!tz->ops->set_trips || !tz->ops->get_trip_hyst) |
| 139 | 138 | goto exit; |
| 140 | 139 | |
| 141 | − for (i = 0; i < tz->trips; i++) { | |
| 140 | + for (i = 0; i < tz->num_trips; i++) { | |
| 142 | 141 | int trip_low; |
| 143 | 142 | |
| 144 | 143 | tz->ops->get_trip_temp(tz, i, &trip_temp); |
| @@ -175,13 +174,6 @@ exit: · 30 unmodified lines | ||
| 175 | 174 | mutex_unlock(&tz->lock); |
| 176 | 175 | } |
| 177 | 176 | |
| 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 | − | |
| 185 | 177 | static void thermal_cdev_set_cur_state(struct thermal_cooling_device *cdev, |
| 186 | 178 | int target) |
| 187 | 179 | { |
| @@ -228,7 +220,6 @@ void thermal_cdev_update(struct thermal_cooling_device *cdev) · 40 unmodified lines | ||
| 228 | 220 | } |
| 229 | 221 | mutex_unlock(&cdev->lock); |
| 230 | 222 | } |
| 231 | −EXPORT_SYMBOL(thermal_cdev_update); | |
| 232 | 223 | |
| 233 | 224 | /** |
| 234 | 225 | * thermal_zone_get_slope - return the slope attribute of the thermal zone |
| @@ -469,7 +469,7 @@ static int thermal_genl_cmd_tz_get_trip(struct param *p) · 468 unmodified lines | ||
| 469 | 469 | |
| 470 | 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 | 474 | enum thermal_trip_type type; |
| 475 | 475 | int temp, hyst = 0; |
| @@ -118,12 +118,7 @@ static int of_thermal_set_trips(struct thermal_zone_device *tz, · 117 unmodified lines | ||
| 118 | 118 | */ |
| 119 | 119 | int of_thermal_get_ntrips(struct thermal_zone_device *tz) |
| 120 | 120 | { |
| 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; | |
| 127 | 122 | } |
| 128 | 123 | EXPORT_SYMBOL_GPL(of_thermal_get_ntrips); |
| 129 | 124 | |
| @@ -139,9 +134,7 @@ EXPORT_SYMBOL_GPL(of_thermal_get_ntrips); · 9 unmodified lines | ||
| 139 | 134 | */ |
| 140 | 135 | bool of_thermal_is_trip_valid(struct thermal_zone_device *tz, int trip) |
| 141 | 136 | { |
| 142 | − struct __thermal_zone *data = tz->devdata; | |
| 143 | − | |
| 144 | − if (!data || trip >= data->ntrips || trip < 0) | |
| 137 | + if (trip >= tz->num_trips || trip < 0) | |
| 145 | 138 | return false; |
| 146 | 139 | |
| 147 | 140 | return true; |
| @@ -161,12 +154,7 @@ EXPORT_SYMBOL_GPL(of_thermal_is_trip_valid); · 13 unmodified lines | ||
| 161 | 154 | const struct thermal_trip * |
| 162 | 155 | of_thermal_get_trip_points(struct thermal_zone_device *tz) |
| 163 | 156 | { |
| 164 | − struct __thermal_zone *data = tz->devdata; | |
| 165 | − | |
| 166 | − if (!data) | |
| 167 | − return NULL; | |
| 168 | − | |
| 169 | − return data->trips; | |
| 157 | + return tz->trips; | |
| 170 | 158 | } |
| 171 | 159 | EXPORT_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 | ||
| 281 | 269 | static int of_thermal_get_trip_type(struct thermal_zone_device *tz, int trip, |
| 282 | 270 | enum thermal_trip_type *type) |
| 283 | 271 | { |
| 284 | − struct __thermal_zone *data = tz->devdata; | |
| 285 | − | |
| 286 | − if (trip >= data->ntrips || trip < 0) | |
| 272 | + if (trip >= tz->num_trips || trip < 0) | |
| 287 | 273 | return -EDOM; |
| 288 | 274 | |
| 289 | − *type = data->trips[trip].type; | |
| 275 | + *type = tz->trips[trip].type; | |
| 290 | 276 | |
| 291 | 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 | ||
| 294 | 280 | static int of_thermal_get_trip_temp(struct thermal_zone_device *tz, int trip, |
| 295 | 281 | int *temp) |
| 296 | 282 | { |
| 297 | − struct __thermal_zone *data = tz->devdata; | |
| 298 | − | |
| 299 | − if (trip >= data->ntrips || trip < 0) | |
| 283 | + if (trip >= tz->num_trips || trip < 0) | |
| 300 | 284 | return -EDOM; |
| 301 | 285 | |
| 302 | − *temp = data->trips[trip].temperature; | |
| 286 | + *temp = tz->trips[trip].temperature; | |
| 303 | 287 | |
| 304 | 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 | 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 | 297 | return -EDOM; |
| 314 | 298 | |
| 315 | 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 | 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 | 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 | ||
| 329 | 313 | static int of_thermal_get_trip_hyst(struct thermal_zone_device *tz, int trip, |
| 330 | 314 | int *hyst) |
| 331 | 315 | { |
| 332 | − struct __thermal_zone *data = tz->devdata; | |
| 333 | − | |
| 334 | − if (trip >= data->ntrips || trip < 0) | |
| 316 | + if (trip >= tz->num_trips || trip < 0) | |
| 335 | 317 | return -EDOM; |
| 336 | 318 | |
| 337 | − *hyst = data->trips[trip].hysteresis; | |
| 319 | + *hyst = tz->trips[trip].hysteresis; | |
| 338 | 320 | |
| 339 | 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 | ||
| 342 | 324 | static int of_thermal_set_trip_hyst(struct thermal_zone_device *tz, int trip, |
| 343 | 325 | int hyst) |
| 344 | 326 | { |
| 345 | − struct __thermal_zone *data = tz->devdata; | |
| 346 | − | |
| 347 | − if (trip >= data->ntrips || trip < 0) | |
| 327 | + if (trip >= tz->num_trips || trip < 0) | |
| 348 | 328 | return -EDOM; |
| 349 | 329 | |
| 350 | 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 | 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 | ||
| 356 | 336 | static int of_thermal_get_crit_temp(struct thermal_zone_device *tz, |
| 357 | 337 | int *temp) |
| 358 | 338 | { |
| 359 | − struct __thermal_zone *data = tz->devdata; | |
| 360 | 339 | int i; |
| 361 | 340 | |
| 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; | |
| 365 | 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 | 651 | /*** functions parsing device tree nodes ***/ |
| 673 | 652 | |
| 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 | + | |
| 674 | 682 | /** |
| 675 | 683 | * thermal_of_populate_bind_params - parse and fill cooling map data |
| 676 | 684 | * @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 | 694 | * Return: 0 on success, proper error code otherwise |
| 687 | 695 | */ |
| 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) | |
| 692 | 699 | { |
| 693 | 700 | struct of_phandle_args cooling_spec; |
| 694 | 701 | struct __thermal_cooling_bind_param *__tcbp; |
| 695 | 702 | struct device_node *trip; |
| 696 | 703 | int ret, i, count; |
| 704 | + int trip_id; | |
| 697 | 705 | u32 prop; |
| 698 | 706 | |
| 699 | 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 | 716 | return -ENODEV; |
| 709 | 717 | } |
| 710 | 718 | |
| 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; | |
| 720 | 722 | goto end; |
| 721 | 723 | } |
| 722 | 724 | |
| 725 | + __tbp->trip_id = trip_id; | |
| 726 | + | |
| 723 | 727 | count = of_count_phandle_with_args(np, "cooling-device", |
| 724 | 728 | "#cooling-cells"); |
| 725 | 729 | if (count <= 0) { |
| @@ -843,13 +847,56 @@ static int thermal_of_populate_trip(struct device_node *np, · 117 unmodified lines | ||
| 843 | 847 | return ret; |
| 844 | 848 | } |
| 845 | 849 | |
| 846 | − /* Required for cooling map matching */ | |
| 847 | − trip->np = np; | |
| 848 | − of_node_get(np); | |
| 849 | − | |
| 850 | 850 | return 0; |
| 851 | 851 | } |
| 852 | 852 | |
| 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 | + | |
| 853 | 900 | /** |
| 854 | 901 | * thermal_of_build_thermal_zone - parse and fill one thermal zone data |
| 855 | 902 | * @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 | 956 | tz->offset = 0; |
| 910 | 957 | } |
| 911 | 958 | |
| 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); | |
| 917 | 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 | 965 | /* cooling-maps */ |
| 939 | 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 | 982 | i = 0; |
| 956 | 983 | 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); | |
| 960 | 987 | goto free_tbps; |
| 988 | + } | |
| 961 | 989 | } |
| 962 | 990 | |
| 963 | 991 | finish: |
| @@ -978,10 +1006,7 @@ free_tbps: · 14 unmodified lines | ||
| 978 | 1006 | |
| 979 | 1007 | kfree(tz->tbps); |
| 980 | 1008 | free_trips: |
| 981 | − for (i = 0; i < tz->ntrips; i++) | |
| 982 | − of_node_put(tz->trips[i].np); | |
| 983 | 1009 | kfree(tz->trips); |
| 984 | − of_node_put(gchild); | |
| 985 | 1010 | free_tz: |
| 986 | 1011 | kfree(tz); |
| 987 | 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 | 1031 | kfree(tz->tbps); |
| 1007 | − for (i = 0; i < tz->ntrips; i++) | |
| 1008 | − of_node_put(tz->trips[i].np); | |
| 1009 | 1032 | kfree(tz->trips); |
| 1010 | 1033 | kfree(tz); |
| 1011 | 1034 | } |
| @@ -1103,11 +1126,9 @@ int __init of_parse_thermal_zones(void) · 91 unmodified lines | ||
| 1103 | 1126 | tzp->slope = tz->slope; |
| 1104 | 1127 | tzp->offset = tz->offset; |
| 1105 | 1128 | |
| 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); | |
| 1111 | 1132 | if (IS_ERR(zone)) { |
| 1112 | 1133 | pr_err("Failed to build %pOFn zone %ld\n", child, |
| 1113 | 1134 | PTR_ERR(zone)); |
| @@ -416,15 +416,15 @@ static int create_trip_attrs(struct thermal_zone_device *tz, int mask) · 415 unmodified lines | ||
| 416 | 416 | int indx; |
| 417 | 417 | |
| 418 | 418 | /* This function works only for zones with at least one trip */ |
| 419 | − if (tz->trips <= 0) | |
| 419 | + if (tz->num_trips <= 0) | |
| 420 | 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 | 423 | GFP_KERNEL); |
| 424 | 424 | if (!tz->trip_type_attrs) |
| 425 | 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 | 428 | GFP_KERNEL); |
| 429 | 429 | if (!tz->trip_temp_attrs) { |
| 430 | 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 | 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 | 436 | sizeof(*tz->trip_hyst_attrs), |
| 437 | 437 | GFP_KERNEL); |
| 438 | 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 | 446 | if (!attrs) { |
| 447 | 447 | kfree(tz->trip_type_attrs); |
| 448 | 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 | 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 | 455 | /* create trip type attribute */ |
| 456 | 456 | snprintf(tz->trip_type_attrs[indx].name, THERMAL_NAME_LENGTH, |
| 457 | 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 | 478 | tz->trip_temp_attrs[indx].attr.store = |
| 479 | 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 | 483 | /* create Optional trip hyst attribute */ |
| 484 | 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 | 496 | tz->trip_hyst_attrs[indx].attr.store = |
| 497 | 497 | trip_point_hyst_store; |
| 498 | 498 | } |
| 499 | − attrs[indx + tz->trips * 2] = | |
| 499 | + attrs[indx + tz->num_trips * 2] = | |
| 500 | 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 | 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 | 540 | for (i = 0; i < size - 2; i++) |
| 541 | 541 | groups[i] = thermal_zone_attribute_groups[i]; |
| 542 | 542 | |
| 543 | − if (tz->trips) { | |
| 543 | + if (tz->num_trips) { | |
| 544 | 544 | result = create_trip_attrs(tz, mask); |
| 545 | 545 | if (result) { |
| 546 | 546 | kfree(groups); |
| @@ -561,7 +561,7 @@ void thermal_zone_destroy_device_groups(struct thermal_zone_device *tz) · 14 unmodified lines | ||
| 561 | 561 | if (!tz) |
| 562 | 562 | return; |
| 563 | 563 | |
| 564 | − if (tz->trips) | |
| 564 | + if (tz->num_trips) | |
| 565 | 565 | destroy_trip_attrs(tz); |
| 566 | 566 | |
| 567 | 567 | kfree(tz->device.groups); |
| @@ -226,7 +226,7 @@ static irqreturn_t ti_bandgap_talert_irq_handler(int irq, void *data) · 225 unmodified lines | ||
| 226 | 226 | /* |
| 227 | 227 | * One TALERT interrupt: Two sources |
| 228 | 228 | * 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 | |
| 230 | 230 | */ |
| 231 | 231 | if (t_hot) { |
| 232 | 232 | ctrl &= ~tsr->mask_hot_mask; |
| @@ -40,8 +40,6 @@ enum thermal_trend { · 39 unmodified lines | ||
| 40 | 40 | THERMAL_TREND_STABLE, /* temperature is stable */ |
| 41 | 41 | THERMAL_TREND_RAISING, /* temperature is raising */ |
| 42 | 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 | 45 | /* Thermal notification reason */ |
| @@ -80,6 +78,18 @@ struct thermal_zone_device_ops { · 32 unmodified lines | ||
| 80 | 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 | + */ | |
| 87 | +struct thermal_trip { | |
| 88 | + int temperature; | |
| 89 | + int hysteresis; | |
| 90 | + enum thermal_trip_type type; | |
| 91 | +}; | |
| 92 | + | |
| 83 | 93 | struct thermal_cooling_device_ops { |
| 84 | 94 | int (*get_max_state) (struct thermal_cooling_device *, unsigned long *); |
| 85 | 95 | int (*get_cur_state) (struct thermal_cooling_device *, unsigned long *); |
| @@ -113,7 +123,8 @@ struct thermal_cooling_device { · 27 unmodified lines | ||
| 113 | 123 | * @trip_hyst_attrs: attributes for trip points for sysfs: trip hysteresis |
| 114 | 124 | * @mode: current mode of this thermal zone |
| 115 | 125 | * @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 | |
| 117 | 128 | * @trips_disabled; bitmap for disabled trips |
| 118 | 129 | * @passive_delay_jiffies: number of jiffies to wait between polls when |
| 119 | 130 | * performing passive cooling. |
| @@ -153,7 +164,8 @@ struct thermal_zone_device { · 33 unmodified lines | ||
| 153 | 164 | struct thermal_attr *trip_hyst_attrs; |
| 154 | 165 | enum thermal_device_mode mode; |
| 155 | 166 | void *devdata; |
| 156 | − int trips; | |
| 167 | + struct thermal_trip *trips; | |
| 168 | + int num_trips; | |
| 157 | 169 | unsigned long trips_disabled; /* bitmap for disabled trips */ |
| 158 | 170 | unsigned long passive_delay_jiffies; |
| 159 | 171 | unsigned long polling_delay_jiffies; |
| @@ -366,8 +378,14 @@ void devm_thermal_zone_of_sensor_unregister(struct device *dev, · 206 unmodified lines | ||
| 366 | 378 | struct thermal_zone_device *thermal_zone_device_register(const char *, int, int, |
| 367 | 379 | void *, struct thermal_zone_device_ops *, |
| 368 | 380 | struct thermal_zone_params *, int, int); |
| 381 | + | |
| 369 | 382 | void thermal_zone_device_unregister(struct thermal_zone_device *); |
| 370 | 383 | |
| 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 | + | |
| 371 | 389 | int thermal_zone_bind_cooling_device(struct thermal_zone_device *, int, |
| 372 | 390 | struct thermal_cooling_device *, |
| 373 | 391 | unsigned long, unsigned long, |
| @@ -92,34 +92,22 @@ TRACE_EVENT(thermal_zone_trip, · 91 unmodified lines | ||
| 92 | 92 | ); |
| 93 | 93 | |
| 94 | 94 | #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), | |
| 98 | 97 | |
| 99 | − TP_ARGS(cpus, freq, load, load_len, dynamic_power), | |
| 98 | + TP_ARGS(cpu, power), | |
| 100 | 99 | |
| 101 | 100 | 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) | |
| 107 | 103 | ), |
| 108 | 104 | |
| 109 | 105 | 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; | |
| 117 | 108 | ), |
| 118 | 109 | |
| 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) | |
| 123 | 111 | ); |
| 124 | 112 | |
| 125 | 113 | TRACE_EVENT(thermal_power_cpu_limit, |
| @@ -27,7 +27,7 @@ · 26 unmodified lines | ||
| 27 | 27 | |
| 28 | 28 | /************************************************************************** |
| 29 | 29 | * 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 | 31 | * G(s) = U(s)/E(s) |
| 32 | 32 | * kp = proportional gain |
| 33 | 33 | * ki = integral gain |
| @@ -27,6 +27,9 @@ · 26 unmodified lines | ||
| 27 | 27 | #define NR_LINES_TZDATA 1 |
| 28 | 28 | #define TMON_LOG_FILE "/var/tmp/tmon.log" |
| 29 | 29 | |
| 30 | +#include <sys/time.h> | |
| 31 | +#include <pthread.h> | |
| 32 | + | |
| 30 | 33 | extern unsigned long ticktime; |
| 31 | 34 | extern double time_elapsed; |
| 32 | 35 | extern unsigned long target_temp_user; |