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

Merge branches 'misc', 'soc', 'soc-eduardo' and 'int3404-thermal' of .git into next

Zhang Rui 201531c2 a116776f

+2212 -67
+7
Documentation/devicetree/bindings/cpufreq/cpufreq-cpu0.txt
··· 15 15 - clock-latency: Specify the possible maximum transition latency for clock, 16 16 in unit of nanoseconds. 17 17 - voltage-tolerance: Specify the CPU voltage tolerance in percentage. 18 + - #cooling-cells: 19 + - cooling-min-level: 20 + - cooling-max-level: 21 + Please refer to Documentation/devicetree/bindings/thermal/thermal.txt. 18 22 19 23 Examples: 20 24 ··· 37 33 198000 850000 38 34 >; 39 35 clock-latency = <61036>; /* two CLK32 periods */ 36 + #cooling-cells = <2>; 37 + cooling-min-level = <0>; 38 + cooling-max-level = <2>; 40 39 }; 41 40 42 41 cpu@1 {
+595
Documentation/devicetree/bindings/thermal/thermal.txt
··· 1 + * Thermal Framework Device Tree descriptor 2 + 3 + This file describes a generic binding to provide a way of 4 + defining hardware thermal structure using device tree. 5 + A thermal structure includes thermal zones and their components, 6 + such as trip points, polling intervals, sensors and cooling devices 7 + binding descriptors. 8 + 9 + The target of device tree thermal descriptors is to describe only 10 + the hardware thermal aspects. The thermal device tree bindings are 11 + not about how the system must control or which algorithm or policy 12 + must be taken in place. 13 + 14 + There are five types of nodes involved to describe thermal bindings: 15 + - thermal sensors: devices which may be used to take temperature 16 + measurements. 17 + - cooling devices: devices which may be used to dissipate heat. 18 + - trip points: describe key temperatures at which cooling is recommended. The 19 + set of points should be chosen based on hardware limits. 20 + - cooling maps: used to describe links between trip points and cooling devices; 21 + - thermal zones: used to describe thermal data within the hardware; 22 + 23 + The following is a description of each of these node types. 24 + 25 + * Thermal sensor devices 26 + 27 + Thermal sensor devices are nodes providing temperature sensing capabilities on 28 + thermal zones. Typical devices are I2C ADC converters and bandgaps. These are 29 + nodes providing temperature data to thermal zones. Thermal sensor devices may 30 + control one or more internal sensors. 31 + 32 + Required property: 33 + - #thermal-sensor-cells: Used to provide sensor device specific information 34 + Type: unsigned while referring to it. Typically 0 on thermal sensor 35 + Size: one cell nodes with only one sensor, and at least 1 on nodes 36 + with several internal sensors, in order 37 + to identify uniquely the sensor instances within 38 + the IC. See thermal zone binding for more details 39 + on how consumers refer to sensor devices. 40 + 41 + * Cooling device nodes 42 + 43 + Cooling devices are nodes providing control on power dissipation. There 44 + are essentially two ways to provide control on power dissipation. First 45 + is by means of regulating device performance, which is known as passive 46 + cooling. A typical passive cooling is a CPU that has dynamic voltage and 47 + frequency scaling (DVFS), and uses lower frequencies as cooling states. 48 + Second is by means of activating devices in order to remove 49 + the dissipated heat, which is known as active cooling, e.g. regulating 50 + fan speeds. In both cases, cooling devices shall have a way to determine 51 + the state of cooling in which the device is. 52 + 53 + Any cooling device has a range of cooling states (i.e. different levels 54 + of heat dissipation). For example a fan's cooling states correspond to 55 + the different fan speeds possible. Cooling states are referred to by 56 + single unsigned integers, where larger numbers mean greater heat 57 + dissipation. The precise set of cooling states associated with a device 58 + (as referred to be the cooling-min-state and cooling-max-state 59 + properties) should be defined in a particular device's binding. 60 + For more examples of cooling devices, refer to the example sections below. 61 + 62 + Required properties: 63 + - cooling-min-state: An integer indicating the smallest 64 + Type: unsigned cooling state accepted. Typically 0. 65 + Size: one cell 66 + 67 + - cooling-max-state: An integer indicating the largest 68 + Type: unsigned cooling state accepted. 69 + Size: one cell 70 + 71 + - #cooling-cells: Used to provide cooling device specific information 72 + Type: unsigned while referring to it. Must be at least 2, in order 73 + Size: one cell to specify minimum and maximum cooling state used 74 + in the reference. The first cell is the minimum 75 + cooling state requested and the second cell is 76 + the maximum cooling state requested in the reference. 77 + See Cooling device maps section below for more details 78 + on how consumers refer to cooling devices. 79 + 80 + * Trip points 81 + 82 + The trip node is a node to describe a point in the temperature domain 83 + in which the system takes an action. This node describes just the point, 84 + not the action. 85 + 86 + Required properties: 87 + - temperature: An integer indicating the trip temperature level, 88 + Type: signed in millicelsius. 89 + Size: one cell 90 + 91 + - hysteresis: A low hysteresis value on temperature property (above). 92 + Type: unsigned This is a relative value, in millicelsius. 93 + Size: one cell 94 + 95 + - type: a string containing the trip type. Expected values are: 96 + "active": A trip point to enable active cooling 97 + "passive": A trip point to enable passive cooling 98 + "hot": A trip point to notify emergency 99 + "critical": Hardware not reliable. 100 + Type: string 101 + 102 + * Cooling device maps 103 + 104 + The cooling device maps node is a node to describe how cooling devices 105 + get assigned to trip points of the zone. The cooling devices are expected 106 + to be loaded in the target system. 107 + 108 + Required properties: 109 + - cooling-device: A phandle of a cooling device with its specifier, 110 + Type: phandle + referring to which cooling device is used in this 111 + cooling specifier binding. In the cooling specifier, the first cell 112 + is the minimum cooling state and the second cell 113 + is the maximum cooling state used in this map. 114 + - trip: A phandle of a trip point node within the same thermal 115 + Type: phandle of zone. 116 + trip point node 117 + 118 + Optional property: 119 + - contribution: The cooling contribution to the thermal zone of the 120 + Type: unsigned referred cooling device at the referred trip point. 121 + Size: one cell The contribution is a ratio of the sum 122 + of all cooling contributions within a thermal zone. 123 + 124 + Note: Using the THERMAL_NO_LIMIT (-1UL) constant in the cooling-device phandle 125 + limit specifier means: 126 + (i) - minimum state allowed for minimum cooling state used in the reference. 127 + (ii) - maximum state allowed for maximum cooling state used in the reference. 128 + Refer to include/dt-bindings/thermal/thermal.h for definition of this constant. 129 + 130 + * Thermal zone nodes 131 + 132 + The thermal zone node is the node containing all the required info 133 + for describing a thermal zone, including its cooling device bindings. The 134 + thermal zone node must contain, apart from its own properties, one sub-node 135 + containing trip nodes and one sub-node containing all the zone cooling maps. 136 + 137 + Required properties: 138 + - polling-delay: The maximum number of milliseconds to wait between polls 139 + Type: unsigned when checking this thermal zone. 140 + Size: one cell 141 + 142 + - polling-delay-passive: The maximum number of milliseconds to wait 143 + Type: unsigned between polls when performing passive cooling. 144 + Size: one cell 145 + 146 + - thermal-sensors: A list of thermal sensor phandles and sensor specifier 147 + Type: list of used while monitoring the thermal zone. 148 + phandles + sensor 149 + specifier 150 + 151 + - trips: A sub-node which is a container of only trip point nodes 152 + Type: sub-node required to describe the thermal zone. 153 + 154 + - cooling-maps: A sub-node which is a container of only cooling device 155 + Type: sub-node map nodes, used to describe the relation between trips 156 + and cooling devices. 157 + 158 + Optional property: 159 + - coefficients: An array of integers (one signed cell) containing 160 + Type: array coefficients to compose a linear relation between 161 + Elem size: one cell the sensors listed in the thermal-sensors property. 162 + Elem type: signed Coefficients defaults to 1, in case this property 163 + is not specified. A simple linear polynomial is used: 164 + Z = c0 * x0 + c1 + x1 + ... + c(n-1) * x(n-1) + cn. 165 + 166 + The coefficients are ordered and they match with sensors 167 + by means of sensor ID. Additional coefficients are 168 + interpreted as constant offset. 169 + 170 + Note: The delay properties are bound to the maximum dT/dt (temperature 171 + derivative over time) in two situations for a thermal zone: 172 + (i) - when passive cooling is activated (polling-delay-passive); and 173 + (ii) - when the zone just needs to be monitored (polling-delay) or 174 + when active cooling is activated. 175 + 176 + The maximum dT/dt is highly bound to hardware power consumption and dissipation 177 + capability. The delays should be chosen to account for said max dT/dt, 178 + such that a device does not cross several trip boundaries unexpectedly 179 + between polls. Choosing the right polling delays shall avoid having the 180 + device in temperature ranges that may damage the silicon structures and 181 + reduce silicon lifetime. 182 + 183 + * The thermal-zones node 184 + 185 + The "thermal-zones" node is a container for all thermal zone nodes. It shall 186 + contain only sub-nodes describing thermal zones as in the section 187 + "Thermal zone nodes". The "thermal-zones" node appears under "/". 188 + 189 + * Examples 190 + 191 + Below are several examples on how to use thermal data descriptors 192 + using device tree bindings: 193 + 194 + (a) - CPU thermal zone 195 + 196 + The CPU thermal zone example below describes how to setup one thermal zone 197 + using one single sensor as temperature source and many cooling devices and 198 + power dissipation control sources. 199 + 200 + #include <dt-bindings/thermal/thermal.h> 201 + 202 + cpus { 203 + /* 204 + * Here is an example of describing a cooling device for a DVFS 205 + * capable CPU. The CPU node describes its four OPPs. 206 + * The cooling states possible are 0..3, and they are 207 + * used as OPP indexes. The minimum cooling state is 0, which means 208 + * all four OPPs can be available to the system. The maximum 209 + * cooling state is 3, which means only the lowest OPPs (198MHz@0.85V) 210 + * can be available in the system. 211 + */ 212 + cpu0: cpu@0 { 213 + ... 214 + operating-points = < 215 + /* kHz uV */ 216 + 970000 1200000 217 + 792000 1100000 218 + 396000 950000 219 + 198000 850000 220 + >; 221 + cooling-min-state = <0>; 222 + cooling-max-state = <3>; 223 + #cooling-cells = <2>; /* min followed by max */ 224 + }; 225 + ... 226 + }; 227 + 228 + &i2c1 { 229 + ... 230 + /* 231 + * A simple fan controller which supports 10 speeds of operation 232 + * (represented as 0-9). 233 + */ 234 + fan0: fan@0x48 { 235 + ... 236 + cooling-min-state = <0>; 237 + cooling-max-state = <9>; 238 + #cooling-cells = <2>; /* min followed by max */ 239 + }; 240 + }; 241 + 242 + ocp { 243 + ... 244 + /* 245 + * A simple IC with a single bandgap temperature sensor. 246 + */ 247 + bandgap0: bandgap@0x0000ED00 { 248 + ... 249 + #thermal-sensor-cells = <0>; 250 + }; 251 + }; 252 + 253 + thermal-zones { 254 + cpu-thermal: cpu-thermal { 255 + polling-delay-passive = <250>; /* milliseconds */ 256 + polling-delay = <1000>; /* milliseconds */ 257 + 258 + thermal-sensors = <&bandgap0>; 259 + 260 + trips { 261 + cpu-alert0: cpu-alert { 262 + temperature = <90000>; /* millicelsius */ 263 + hysteresis = <2000>; /* millicelsius */ 264 + type = "active"; 265 + }; 266 + cpu-alert1: cpu-alert { 267 + temperature = <100000>; /* millicelsius */ 268 + hysteresis = <2000>; /* millicelsius */ 269 + type = "passive"; 270 + }; 271 + cpu-crit: cpu-crit { 272 + temperature = <125000>; /* millicelsius */ 273 + hysteresis = <2000>; /* millicelsius */ 274 + type = "critical"; 275 + }; 276 + }; 277 + 278 + cooling-maps { 279 + map0 { 280 + trip = <&cpu-alert0>; 281 + cooling-device = <&fan0 THERMAL_NO_LIMITS 4>; 282 + }; 283 + map1 { 284 + trip = <&cpu-alert1>; 285 + cooling-device = <&fan0 5 THERMAL_NO_LIMITS>; 286 + }; 287 + map2 { 288 + trip = <&cpu-alert1>; 289 + cooling-device = 290 + <&cpu0 THERMAL_NO_LIMITS THERMAL_NO_LIMITS>; 291 + }; 292 + }; 293 + }; 294 + }; 295 + 296 + In the example above, the ADC sensor (bandgap0) at address 0x0000ED00 is 297 + used to monitor the zone 'cpu-thermal' using its sole sensor. A fan 298 + device (fan0) is controlled via I2C bus 1, at address 0x48, and has ten 299 + different cooling states 0-9. It is used to remove the heat out of 300 + the thermal zone 'cpu-thermal' using its cooling states 301 + from its minimum to 4, when it reaches trip point 'cpu-alert0' 302 + at 90C, as an example of active cooling. The same cooling device is used at 303 + 'cpu-alert1', but from 5 to its maximum state. The cpu@0 device is also 304 + linked to the same thermal zone, 'cpu-thermal', as a passive cooling device, 305 + using all its cooling states at trip point 'cpu-alert1', 306 + which is a trip point at 100C. On the thermal zone 'cpu-thermal', at the 307 + temperature of 125C, represented by the trip point 'cpu-crit', the silicon 308 + is not reliable anymore. 309 + 310 + (b) - IC with several internal sensors 311 + 312 + The example below describes how to deploy several thermal zones based off a 313 + single sensor IC, assuming it has several internal sensors. This is a common 314 + case on SoC designs with several internal IPs that may need different thermal 315 + requirements, and thus may have their own sensor to monitor or detect internal 316 + hotspots in their silicon. 317 + 318 + #include <dt-bindings/thermal/thermal.h> 319 + 320 + ocp { 321 + ... 322 + /* 323 + * A simple IC with several bandgap temperature sensors. 324 + */ 325 + bandgap0: bandgap@0x0000ED00 { 326 + ... 327 + #thermal-sensor-cells = <1>; 328 + }; 329 + }; 330 + 331 + thermal-zones { 332 + cpu-thermal: cpu-thermal { 333 + polling-delay-passive = <250>; /* milliseconds */ 334 + polling-delay = <1000>; /* milliseconds */ 335 + 336 + /* sensor ID */ 337 + thermal-sensors = <&bandgap0 0>; 338 + 339 + trips { 340 + /* each zone within the SoC may have its own trips */ 341 + cpu-alert: cpu-alert { 342 + temperature = <100000>; /* millicelsius */ 343 + hysteresis = <2000>; /* millicelsius */ 344 + type = "passive"; 345 + }; 346 + cpu-crit: cpu-crit { 347 + temperature = <125000>; /* millicelsius */ 348 + hysteresis = <2000>; /* millicelsius */ 349 + type = "critical"; 350 + }; 351 + }; 352 + 353 + cooling-maps { 354 + /* each zone within the SoC may have its own cooling */ 355 + ... 356 + }; 357 + }; 358 + 359 + gpu-thermal: gpu-thermal { 360 + polling-delay-passive = <120>; /* milliseconds */ 361 + polling-delay = <1000>; /* milliseconds */ 362 + 363 + /* sensor ID */ 364 + thermal-sensors = <&bandgap0 1>; 365 + 366 + trips { 367 + /* each zone within the SoC may have its own trips */ 368 + gpu-alert: gpu-alert { 369 + temperature = <90000>; /* millicelsius */ 370 + hysteresis = <2000>; /* millicelsius */ 371 + type = "passive"; 372 + }; 373 + gpu-crit: gpu-crit { 374 + temperature = <105000>; /* millicelsius */ 375 + hysteresis = <2000>; /* millicelsius */ 376 + type = "critical"; 377 + }; 378 + }; 379 + 380 + cooling-maps { 381 + /* each zone within the SoC may have its own cooling */ 382 + ... 383 + }; 384 + }; 385 + 386 + dsp-thermal: dsp-thermal { 387 + polling-delay-passive = <50>; /* milliseconds */ 388 + polling-delay = <1000>; /* milliseconds */ 389 + 390 + /* sensor ID */ 391 + thermal-sensors = <&bandgap0 2>; 392 + 393 + trips { 394 + /* each zone within the SoC may have its own trips */ 395 + dsp-alert: gpu-alert { 396 + temperature = <90000>; /* millicelsius */ 397 + hysteresis = <2000>; /* millicelsius */ 398 + type = "passive"; 399 + }; 400 + dsp-crit: gpu-crit { 401 + temperature = <135000>; /* millicelsius */ 402 + hysteresis = <2000>; /* millicelsius */ 403 + type = "critical"; 404 + }; 405 + }; 406 + 407 + cooling-maps { 408 + /* each zone within the SoC may have its own cooling */ 409 + ... 410 + }; 411 + }; 412 + }; 413 + 414 + In the example above, there is one bandgap IC which has the capability to 415 + monitor three sensors. The hardware has been designed so that sensors are 416 + placed on different places in the DIE to monitor different temperature 417 + hotspots: one for CPU thermal zone, one for GPU thermal zone and the 418 + other to monitor a DSP thermal zone. 419 + 420 + Thus, there is a need to assign each sensor provided by the bandgap IC 421 + to different thermal zones. This is achieved by means of using the 422 + #thermal-sensor-cells property and using the first cell of the sensor 423 + specifier as sensor ID. In the example, then, <bandgap 0> is used to 424 + monitor CPU thermal zone, <bandgap 1> is used to monitor GPU thermal 425 + zone and <bandgap 2> is used to monitor DSP thermal zone. Each zone 426 + may be uncorrelated, having its own dT/dt requirements, trips 427 + and cooling maps. 428 + 429 + 430 + (c) - Several sensors within one single thermal zone 431 + 432 + The example below illustrates how to use more than one sensor within 433 + one thermal zone. 434 + 435 + #include <dt-bindings/thermal/thermal.h> 436 + 437 + &i2c1 { 438 + ... 439 + /* 440 + * A simple IC with a single temperature sensor. 441 + */ 442 + adc: sensor@0x49 { 443 + ... 444 + #thermal-sensor-cells = <0>; 445 + }; 446 + }; 447 + 448 + ocp { 449 + ... 450 + /* 451 + * A simple IC with a single bandgap temperature sensor. 452 + */ 453 + bandgap0: bandgap@0x0000ED00 { 454 + ... 455 + #thermal-sensor-cells = <0>; 456 + }; 457 + }; 458 + 459 + thermal-zones { 460 + cpu-thermal: cpu-thermal { 461 + polling-delay-passive = <250>; /* milliseconds */ 462 + polling-delay = <1000>; /* milliseconds */ 463 + 464 + thermal-sensors = <&bandgap0>, /* cpu */ 465 + <&adc>; /* pcb north */ 466 + 467 + /* hotspot = 100 * bandgap - 120 * adc + 484 */ 468 + coefficients = <100 -120 484>; 469 + 470 + trips { 471 + ... 472 + }; 473 + 474 + cooling-maps { 475 + ... 476 + }; 477 + }; 478 + }; 479 + 480 + In some cases, there is a need to use more than one sensor to extrapolate 481 + a thermal hotspot in the silicon. The above example illustrates this situation. 482 + For instance, it may be the case that a sensor external to CPU IP may be placed 483 + close to CPU hotspot and together with internal CPU sensor, it is used 484 + to determine the hotspot. Assuming this is the case for the above example, 485 + the hypothetical extrapolation rule would be: 486 + hotspot = 100 * bandgap - 120 * adc + 484 487 + 488 + In other context, the same idea can be used to add fixed offset. For instance, 489 + consider the hotspot extrapolation rule below: 490 + hotspot = 1 * adc + 6000 491 + 492 + In the above equation, the hotspot is always 6C higher than what is read 493 + from the ADC sensor. The binding would be then: 494 + thermal-sensors = <&adc>; 495 + 496 + /* hotspot = 1 * adc + 6000 */ 497 + coefficients = <1 6000>; 498 + 499 + (d) - Board thermal 500 + 501 + The board thermal example below illustrates how to setup one thermal zone 502 + with many sensors and many cooling devices. 503 + 504 + #include <dt-bindings/thermal/thermal.h> 505 + 506 + &i2c1 { 507 + ... 508 + /* 509 + * An IC with several temperature sensor. 510 + */ 511 + adc-dummy: sensor@0x50 { 512 + ... 513 + #thermal-sensor-cells = <1>; /* sensor internal ID */ 514 + }; 515 + }; 516 + 517 + thermal-zones { 518 + batt-thermal { 519 + polling-delay-passive = <500>; /* milliseconds */ 520 + polling-delay = <2500>; /* milliseconds */ 521 + 522 + /* sensor ID */ 523 + thermal-sensors = <&adc-dummy 4>; 524 + 525 + trips { 526 + ... 527 + }; 528 + 529 + cooling-maps { 530 + ... 531 + }; 532 + }; 533 + 534 + board-thermal: board-thermal { 535 + polling-delay-passive = <1000>; /* milliseconds */ 536 + polling-delay = <2500>; /* milliseconds */ 537 + 538 + /* sensor ID */ 539 + thermal-sensors = <&adc-dummy 0>, /* pcb top edge */ 540 + <&adc-dummy 1>, /* lcd */ 541 + <&adc-dymmy 2>; /* back cover */ 542 + /* 543 + * An array of coefficients describing the sensor 544 + * linear relation. E.g.: 545 + * z = c1*x1 + c2*x2 + c3*x3 546 + */ 547 + coefficients = <1200 -345 890>; 548 + 549 + trips { 550 + /* Trips are based on resulting linear equation */ 551 + cpu-trip: cpu-trip { 552 + temperature = <60000>; /* millicelsius */ 553 + hysteresis = <2000>; /* millicelsius */ 554 + type = "passive"; 555 + }; 556 + gpu-trip: gpu-trip { 557 + temperature = <55000>; /* millicelsius */ 558 + hysteresis = <2000>; /* millicelsius */ 559 + type = "passive"; 560 + } 561 + lcd-trip: lcp-trip { 562 + temperature = <53000>; /* millicelsius */ 563 + hysteresis = <2000>; /* millicelsius */ 564 + type = "passive"; 565 + }; 566 + crit-trip: crit-trip { 567 + temperature = <68000>; /* millicelsius */ 568 + hysteresis = <2000>; /* millicelsius */ 569 + type = "critical"; 570 + }; 571 + }; 572 + 573 + cooling-maps { 574 + map0 { 575 + trip = <&cpu-trip>; 576 + cooling-device = <&cpu0 0 2>; 577 + contribution = <55>; 578 + }; 579 + map1 { 580 + trip = <&gpu-trip>; 581 + cooling-device = <&gpu0 0 2>; 582 + contribution = <20>; 583 + }; 584 + map2 { 585 + trip = <&lcd-trip>; 586 + cooling-device = <&lcd0 5 10>; 587 + contribution = <15>; 588 + }; 589 + }; 590 + }; 591 + }; 592 + 593 + The above example is a mix of previous examples, a sensor IP with several internal 594 + sensors used to monitor different zones, one of them is composed by several sensors and 595 + with different cooling devices.
+1
MAINTAINERS
··· 8501 8501 F: drivers/thermal/ 8502 8502 F: include/linux/thermal.h 8503 8503 F: include/linux/cpu_cooling.h 8504 + F: Documentation/devicetree/bindings/thermal/ 8504 8505 8505 8506 THINGM BLINK(1) USB RGB LED DRIVER 8506 8507 M: Vivien Didelot <vivien.didelot@savoirfairelinux.com>
+41
arch/arm/boot/dts/omap4-cpu-thermal.dtsi
··· 1 + /* 2 + * Device Tree Source for OMAP4/5 SoC CPU thermal 3 + * 4 + * Copyright (C) 2013 Texas Instruments Incorporated - http://www.ti.com/ 5 + * Contact: Eduardo Valentin <eduardo.valentin@ti.com> 6 + * 7 + * This file is licensed under the terms of the GNU General Public License 8 + * version 2. This program is licensed "as is" without any warranty of any 9 + * kind, whether express or implied. 10 + */ 11 + 12 + #include <dt-bindings/thermal/thermal.h> 13 + 14 + cpu_thermal: cpu_thermal { 15 + polling-delay-passive = <250>; /* milliseconds */ 16 + polling-delay = <1000>; /* milliseconds */ 17 + 18 + /* sensor ID */ 19 + thermal-sensors = <&bandgap 0>; 20 + 21 + trips { 22 + cpu_alert0: cpu_alert { 23 + temperature = <100000>; /* millicelsius */ 24 + hysteresis = <2000>; /* millicelsius */ 25 + type = "passive"; 26 + }; 27 + cpu_crit: cpu_crit { 28 + temperature = <125000>; /* millicelsius */ 29 + hysteresis = <2000>; /* millicelsius */ 30 + type = "critical"; 31 + }; 32 + }; 33 + 34 + cooling-maps { 35 + map0 { 36 + trip = <&cpu_alert0>; 37 + cooling-device = 38 + <&cpu0 THERMAL_NO_LIMIT THERMAL_NO_LIMIT>; 39 + }; 40 + }; 41 + };
+18 -5
arch/arm/boot/dts/omap443x.dtsi
··· 12 12 13 13 / { 14 14 cpus { 15 - cpu@0 { 15 + cpu0: cpu@0 { 16 16 /* OMAP443x variants OPP50-OPPNT */ 17 17 operating-points = < 18 18 /* kHz uV */ ··· 22 22 1008000 1375000 23 23 >; 24 24 clock-latency = <300000>; /* From legacy driver */ 25 + 26 + /* cooling options */ 27 + cooling-min-level = <0>; 28 + cooling-max-level = <3>; 29 + #cooling-cells = <2>; /* min followed by max */ 25 30 }; 26 31 }; 27 32 28 - bandgap { 29 - reg = <0x4a002260 0x4 30 - 0x4a00232C 0x4>; 31 - compatible = "ti,omap4430-bandgap"; 33 + thermal-zones { 34 + #include "omap4-cpu-thermal.dtsi" 35 + }; 36 + 37 + ocp { 38 + bandgap: bandgap { 39 + reg = <0x4a002260 0x4 40 + 0x4a00232C 0x4>; 41 + compatible = "ti,omap4430-bandgap"; 42 + 43 + #thermal-sensor-cells = <0>; 44 + }; 32 45 }; 33 46 };
+21 -8
arch/arm/boot/dts/omap4460.dtsi
··· 12 12 / { 13 13 cpus { 14 14 /* OMAP446x 'standard device' variants OPP50 to OPPTurbo */ 15 - cpu@0 { 15 + cpu0: cpu@0 { 16 16 operating-points = < 17 17 /* kHz uV */ 18 18 350000 1025000 ··· 20 20 920000 1313000 21 21 >; 22 22 clock-latency = <300000>; /* From legacy driver */ 23 + 24 + /* cooling options */ 25 + cooling-min-level = <0>; 26 + cooling-max-level = <2>; 27 + #cooling-cells = <2>; /* min followed by max */ 23 28 }; 24 29 }; 25 30 ··· 35 30 ti,hwmods = "debugss"; 36 31 }; 37 32 38 - bandgap { 39 - reg = <0x4a002260 0x4 40 - 0x4a00232C 0x4 41 - 0x4a002378 0x18>; 42 - compatible = "ti,omap4460-bandgap"; 43 - interrupts = <0 126 IRQ_TYPE_LEVEL_HIGH>; /* talert */ 44 - gpios = <&gpio3 22 0>; /* tshut */ 33 + thermal-zones { 34 + #include "omap4-cpu-thermal.dtsi" 35 + }; 36 + 37 + ocp { 38 + bandgap: bandgap { 39 + reg = <0x4a002260 0x4 40 + 0x4a00232C 0x4 41 + 0x4a002378 0x18>; 42 + compatible = "ti,omap4460-bandgap"; 43 + interrupts = <0 126 IRQ_TYPE_LEVEL_HIGH>; /* talert */ 44 + gpios = <&gpio3 22 0>; /* tshut */ 45 + 46 + #thermal-sensor-cells = <0>; 47 + }; 45 48 }; 46 49 };
+28
arch/arm/boot/dts/omap5-core-thermal.dtsi
··· 1 + /* 2 + * Device Tree Source for OMAP543x SoC CORE thermal 3 + * 4 + * Copyright (C) 2013 Texas Instruments Incorporated - http://www.ti.com/ 5 + * Contact: Eduardo Valentin <eduardo.valentin@ti.com> 6 + * 7 + * This file is licensed under the terms of the GNU General Public License 8 + * version 2. This program is licensed "as is" without any warranty of any 9 + * kind, whether express or implied. 10 + */ 11 + 12 + #include <dt-bindings/thermal/thermal.h> 13 + 14 + core_thermal: core_thermal { 15 + polling-delay-passive = <250>; /* milliseconds */ 16 + polling-delay = <1000>; /* milliseconds */ 17 + 18 + /* sensor ID */ 19 + thermal-sensors = <&bandgap 2>; 20 + 21 + trips { 22 + core_crit: core_crit { 23 + temperature = <125000>; /* milliCelsius */ 24 + hysteresis = <2000>; /* milliCelsius */ 25 + type = "critical"; 26 + }; 27 + }; 28 + };
+28
arch/arm/boot/dts/omap5-gpu-thermal.dtsi
··· 1 + /* 2 + * Device Tree Source for OMAP543x SoC GPU thermal 3 + * 4 + * Copyright (C) 2013 Texas Instruments Incorporated - http://www.ti.com/ 5 + * Contact: Eduardo Valentin <eduardo.valentin@ti.com> 6 + * 7 + * This file is licensed under the terms of the GNU General Public License 8 + * version 2. This program is licensed "as is" without any warranty of any 9 + * kind, whether express or implied. 10 + */ 11 + 12 + #include <dt-bindings/thermal/thermal.h> 13 + 14 + gpu_thermal: gpu_thermal { 15 + polling-delay-passive = <250>; /* milliseconds */ 16 + polling-delay = <1000>; /* milliseconds */ 17 + 18 + /* sensor ID */ 19 + thermal-sensors = <&bandgap 1>; 20 + 21 + trips { 22 + gpu_crit: gpu_crit { 23 + temperature = <125000>; /* milliCelsius */ 24 + hysteresis = <2000>; /* milliCelsius */ 25 + type = "critical"; 26 + }; 27 + }; 28 + };
+13 -1
arch/arm/boot/dts/omap5.dtsi
··· 49 49 1000000 1060000 50 50 1500000 1250000 51 51 >; 52 + /* cooling options */ 53 + cooling-min-level = <0>; 54 + cooling-max-level = <2>; 55 + #cooling-cells = <2>; /* min followed by max */ 52 56 }; 53 57 cpu@1 { 54 58 device_type = "cpu"; 55 59 compatible = "arm,cortex-a15"; 56 60 reg = <0x1>; 57 61 }; 62 + }; 63 + 64 + thermal-zones { 65 + #include "omap4-cpu-thermal.dtsi" 66 + #include "omap5-gpu-thermal.dtsi" 67 + #include "omap5-core-thermal.dtsi" 58 68 }; 59 69 60 70 timer { ··· 739 729 }; 740 730 }; 741 731 742 - bandgap@4a0021e0 { 732 + bandgap: bandgap@4a0021e0 { 743 733 reg = <0x4a0021e0 0xc 744 734 0x4a00232c 0xc 745 735 0x4a002380 0x2c 746 736 0x4a0023C0 0x3c>; 747 737 interrupts = <GIC_SPI 126 IRQ_TYPE_LEVEL_HIGH>; 748 738 compatible = "ti,omap5430-bandgap"; 739 + 740 + #thermal-sensor-cells = <1>; 749 741 }; 750 742 }; 751 743 };
+1 -1
drivers/cpufreq/Kconfig
··· 181 181 182 182 config GENERIC_CPUFREQ_CPU0 183 183 tristate "Generic CPU0 cpufreq driver" 184 - depends on HAVE_CLK && REGULATOR && PM_OPP && OF 184 + depends on HAVE_CLK && REGULATOR && PM_OPP && OF && THERMAL && CPU_THERMAL 185 185 help 186 186 This adds a generic cpufreq driver for CPU0 frequency management. 187 187 It supports both uniprocessor (UP) and symmetric multiprocessor (SMP)
+16
drivers/cpufreq/cpufreq-cpu0.c
··· 13 13 14 14 #include <linux/clk.h> 15 15 #include <linux/cpu.h> 16 + #include <linux/cpu_cooling.h> 16 17 #include <linux/cpufreq.h> 18 + #include <linux/cpumask.h> 17 19 #include <linux/err.h> 18 20 #include <linux/module.h> 19 21 #include <linux/of.h> ··· 23 21 #include <linux/platform_device.h> 24 22 #include <linux/regulator/consumer.h> 25 23 #include <linux/slab.h> 24 + #include <linux/thermal.h> 26 25 27 26 static unsigned int transition_latency; 28 27 static unsigned int voltage_tolerance; /* in percentage */ ··· 32 29 static struct clk *cpu_clk; 33 30 static struct regulator *cpu_reg; 34 31 static struct cpufreq_frequency_table *freq_table; 32 + static struct thermal_cooling_device *cdev; 35 33 36 34 static unsigned int cpu0_get_speed(unsigned int cpu) 37 35 { ··· 205 201 goto out_free_table; 206 202 } 207 203 204 + /* 205 + * For now, just loading the cooling device; 206 + * thermal DT code takes care of matching them. 207 + */ 208 + if (of_find_property(np, "#cooling-cells", NULL)) { 209 + cdev = of_cpufreq_cooling_register(np, cpu_present_mask); 210 + if (IS_ERR(cdev)) 211 + pr_err("running cpufreq without cooling device: %ld\n", 212 + PTR_ERR(cdev)); 213 + } 214 + 208 215 of_node_put(np); 209 216 return 0; 210 217 ··· 228 213 229 214 static int cpu0_cpufreq_remove(struct platform_device *pdev) 230 215 { 216 + cpufreq_cooling_unregister(cdev); 231 217 cpufreq_unregister_driver(&cpu0_cpufreq_driver); 232 218 dev_pm_opp_free_cpufreq_table(cpu_dev, &freq_table); 233 219
+30 -5
drivers/hwmon/lm75.c
··· 27 27 #include <linux/hwmon-sysfs.h> 28 28 #include <linux/err.h> 29 29 #include <linux/mutex.h> 30 + #include <linux/of.h> 31 + #include <linux/thermal.h> 30 32 #include "lm75.h" 31 33 32 34 ··· 73 71 /* Each client has this additional data */ 74 72 struct lm75_data { 75 73 struct device *hwmon_dev; 74 + struct thermal_zone_device *tz; 76 75 struct mutex update_lock; 77 76 u8 orig_conf; 78 77 u8 resolution; /* In bits, between 9 and 12 */ ··· 94 91 95 92 /*-----------------------------------------------------------------------*/ 96 93 94 + static inline long lm75_reg_to_mc(s16 temp, u8 resolution) 95 + { 96 + return ((temp >> (16 - resolution)) * 1000) >> (resolution - 8); 97 + } 98 + 97 99 /* sysfs attributes for hwmon */ 100 + 101 + static int lm75_read_temp(void *dev, long *temp) 102 + { 103 + struct lm75_data *data = lm75_update_device(dev); 104 + 105 + if (IS_ERR(data)) 106 + return PTR_ERR(data); 107 + 108 + *temp = lm75_reg_to_mc(data->temp[0], data->resolution); 109 + 110 + return 0; 111 + } 98 112 99 113 static ssize_t show_temp(struct device *dev, struct device_attribute *da, 100 114 char *buf) 101 115 { 102 116 struct sensor_device_attribute *attr = to_sensor_dev_attr(da); 103 117 struct lm75_data *data = lm75_update_device(dev); 104 - long temp; 105 118 106 119 if (IS_ERR(data)) 107 120 return PTR_ERR(data); 108 121 109 - temp = ((data->temp[attr->index] >> (16 - data->resolution)) * 1000) 110 - >> (data->resolution - 8); 111 - 112 - return sprintf(buf, "%ld\n", temp); 122 + return sprintf(buf, "%ld\n", lm75_reg_to_mc(data->temp[attr->index], 123 + data->resolution)); 113 124 } 114 125 115 126 static ssize_t set_temp(struct device *dev, struct device_attribute *da, ··· 290 273 goto exit_remove; 291 274 } 292 275 276 + data->tz = thermal_zone_of_sensor_register(&client->dev, 277 + 0, 278 + &client->dev, 279 + lm75_read_temp, NULL); 280 + if (IS_ERR(data->tz)) 281 + data->tz = NULL; 282 + 293 283 dev_info(&client->dev, "%s: sensor '%s'\n", 294 284 dev_name(data->hwmon_dev), client->name); 295 285 ··· 311 287 { 312 288 struct lm75_data *data = i2c_get_clientdata(client); 313 289 290 + thermal_zone_of_sensor_unregister(&client->dev, data->tz); 314 291 hwmon_device_unregister(data->hwmon_dev); 315 292 sysfs_remove_group(&client->dev.kobj, &lm75_group); 316 293 lm75_write_value(client, LM75_REG_CONF, data->orig_conf);
+19
drivers/hwmon/tmp102.c
··· 27 27 #include <linux/mutex.h> 28 28 #include <linux/device.h> 29 29 #include <linux/jiffies.h> 30 + #include <linux/thermal.h> 31 + #include <linux/of.h> 30 32 31 33 #define DRIVER_NAME "tmp102" 32 34 ··· 52 50 53 51 struct tmp102 { 54 52 struct device *hwmon_dev; 53 + struct thermal_zone_device *tz; 55 54 struct mutex lock; 56 55 u16 config_orig; 57 56 unsigned long last_update; ··· 94 91 } 95 92 mutex_unlock(&tmp102->lock); 96 93 return tmp102; 94 + } 95 + 96 + static int tmp102_read_temp(void *dev, long *temp) 97 + { 98 + struct tmp102 *tmp102 = tmp102_update_device(to_i2c_client(dev)); 99 + 100 + *temp = tmp102->temp[0]; 101 + 102 + return 0; 97 103 } 98 104 99 105 static ssize_t tmp102_show_temp(struct device *dev, ··· 216 204 goto fail_remove_sysfs; 217 205 } 218 206 207 + tmp102->tz = thermal_zone_of_sensor_register(&client->dev, 0, 208 + &client->dev, 209 + tmp102_read_temp, NULL); 210 + if (IS_ERR(tmp102->tz)) 211 + tmp102->tz = NULL; 212 + 219 213 dev_info(&client->dev, "initialized\n"); 220 214 221 215 return 0; ··· 238 220 { 239 221 struct tmp102 *tmp102 = i2c_get_clientdata(client); 240 222 223 + thermal_zone_of_sensor_unregister(&client->dev, tmp102->tz); 241 224 hwmon_device_unregister(tmp102->hwmon_dev); 242 225 sysfs_remove_group(&client->dev.kobj, &tmp102_attr_group); 243 226
+22 -1
drivers/thermal/Kconfig
··· 29 29 Say 'Y' here if you want all thermal sensors to 30 30 have hwmon sysfs interface too. 31 31 32 + config THERMAL_OF 33 + bool 34 + prompt "APIs to parse thermal data out of device tree" 35 + depends on OF 36 + default y 37 + help 38 + This options provides helpers to add the support to 39 + read and parse thermal data definitions out of the 40 + device tree blob. 41 + 42 + Say 'Y' here if you need to build thermal infrastructure 43 + based on device tree. 44 + 32 45 choice 33 46 prompt "Default Thermal governor" 34 47 default THERMAL_DEFAULT_GOV_STEP_WISE ··· 92 79 config CPU_THERMAL 93 80 bool "generic cpu cooling support" 94 81 depends on CPU_FREQ 82 + depends on THERMAL_OF 95 83 help 96 84 This implements the generic cpu cooling mechanism through frequency 97 85 reduction. An ACPI version of this already exists ··· 135 121 136 122 config RCAR_THERMAL 137 123 tristate "Renesas R-Car thermal driver" 138 - depends on ARCH_SHMOBILE 124 + depends on ARCH_SHMOBILE || COMPILE_TEST 139 125 help 140 126 Enable this to plug the R-Car thermal sensor driver into the Linux 141 127 thermal framework. ··· 205 191 thermal zone. Each package will have its own thermal zone. There are 206 192 two trip points which can be set by user to get notifications via thermal 207 193 notification methods. 194 + 195 + config ACPI_INT3403_THERMAL 196 + tristate "ACPI INT3403 thermal driver" 197 + depends on X86 && ACPI 198 + help 199 + This driver uses ACPI INT3403 device objects. If present, it will 200 + register each INT3403 thermal sensor as a thermal zone. 208 201 209 202 menu "Texas Instruments thermal drivers" 210 203 source "drivers/thermal/ti-soc-thermal/Kconfig"
+2
drivers/thermal/Makefile
··· 7 7 8 8 # interface to/from other layers providing sensors 9 9 thermal_sys-$(CONFIG_THERMAL_HWMON) += thermal_hwmon.o 10 + thermal_sys-$(CONFIG_THERMAL_OF) += of-thermal.o 10 11 11 12 # governors 12 13 thermal_sys-$(CONFIG_THERMAL_GOV_FAIR_SHARE) += fair_share.o ··· 30 29 obj-$(CONFIG_INTEL_POWERCLAMP) += intel_powerclamp.o 31 30 obj-$(CONFIG_X86_PKG_TEMP_THERMAL) += x86_pkg_temp_thermal.o 32 31 obj-$(CONFIG_TI_SOC_THERMAL) += ti-soc-thermal/ 32 + obj-$(CONFIG_ACPI_INT3403_THERMAL) += int3403_thermal.o
+50 -6
drivers/thermal/cpu_cooling.c
··· 424 424 }; 425 425 426 426 /** 427 - * cpufreq_cooling_register - function to create cpufreq cooling device. 427 + * __cpufreq_cooling_register - helper function to create cpufreq cooling device 428 + * @np: a valid struct device_node to the cooling device device tree node 428 429 * @clip_cpus: cpumask of cpus where the frequency constraints will happen. 429 430 * 430 431 * This interface function registers the cpufreq cooling device with the name 431 432 * "thermal-cpufreq-%x". This api can support multiple instances of cpufreq 432 - * cooling devices. 433 + * cooling devices. It also gives the opportunity to link the cooling device 434 + * with a device tree node, in order to bind it via the thermal DT code. 433 435 * 434 436 * Return: a valid struct thermal_cooling_device pointer on success, 435 437 * on failure, it returns a corresponding ERR_PTR(). 436 438 */ 437 - struct thermal_cooling_device * 438 - cpufreq_cooling_register(const struct cpumask *clip_cpus) 439 + static struct thermal_cooling_device * 440 + __cpufreq_cooling_register(struct device_node *np, 441 + const struct cpumask *clip_cpus) 439 442 { 440 443 struct thermal_cooling_device *cool_dev; 441 444 struct cpufreq_cooling_device *cpufreq_dev = NULL; ··· 477 474 snprintf(dev_name, sizeof(dev_name), "thermal-cpufreq-%d", 478 475 cpufreq_dev->id); 479 476 480 - cool_dev = thermal_cooling_device_register(dev_name, cpufreq_dev, 481 - &cpufreq_cooling_ops); 477 + cool_dev = thermal_of_cooling_device_register(np, dev_name, cpufreq_dev, 478 + &cpufreq_cooling_ops); 482 479 if (IS_ERR(cool_dev)) { 483 480 release_idr(&cpufreq_idr, cpufreq_dev->id); 484 481 kfree(cpufreq_dev); ··· 498 495 499 496 return cool_dev; 500 497 } 498 + 499 + /** 500 + * cpufreq_cooling_register - function to create cpufreq cooling device. 501 + * @clip_cpus: cpumask of cpus where the frequency constraints will happen. 502 + * 503 + * This interface function registers the cpufreq cooling device with the name 504 + * "thermal-cpufreq-%x". This api can support multiple instances of cpufreq 505 + * cooling devices. 506 + * 507 + * Return: a valid struct thermal_cooling_device pointer on success, 508 + * on failure, it returns a corresponding ERR_PTR(). 509 + */ 510 + struct thermal_cooling_device * 511 + cpufreq_cooling_register(const struct cpumask *clip_cpus) 512 + { 513 + return __cpufreq_cooling_register(NULL, clip_cpus); 514 + } 501 515 EXPORT_SYMBOL_GPL(cpufreq_cooling_register); 516 + 517 + /** 518 + * of_cpufreq_cooling_register - function to create cpufreq cooling device. 519 + * @np: a valid struct device_node to the cooling device device tree node 520 + * @clip_cpus: cpumask of cpus where the frequency constraints will happen. 521 + * 522 + * This interface function registers the cpufreq cooling device with the name 523 + * "thermal-cpufreq-%x". This api can support multiple instances of cpufreq 524 + * cooling devices. Using this API, the cpufreq cooling device will be 525 + * linked to the device tree node provided. 526 + * 527 + * Return: a valid struct thermal_cooling_device pointer on success, 528 + * on failure, it returns a corresponding ERR_PTR(). 529 + */ 530 + struct thermal_cooling_device * 531 + of_cpufreq_cooling_register(struct device_node *np, 532 + const struct cpumask *clip_cpus) 533 + { 534 + if (!np) 535 + return ERR_PTR(-EINVAL); 536 + 537 + return __cpufreq_cooling_register(np, clip_cpus); 538 + } 539 + EXPORT_SYMBOL_GPL(of_cpufreq_cooling_register); 502 540 503 541 /** 504 542 * cpufreq_cooling_unregister - function to remove cpufreq cooling device.
+18 -14
drivers/thermal/imx_thermal.c
··· 490 490 { 491 491 struct imx_thermal_data *data = dev_get_drvdata(dev); 492 492 struct regmap *map = data->tempmon; 493 - u32 val; 494 493 495 - regmap_read(map, TEMPSENSE0, &val); 496 - if ((val & TEMPSENSE0_POWER_DOWN) == 0) { 497 - /* 498 - * If a measurement is taking place, wait for a long enough 499 - * time for it to finish, and then check again. If it still 500 - * does not finish, something must go wrong. 501 - */ 502 - udelay(50); 503 - regmap_read(map, TEMPSENSE0, &val); 504 - if ((val & TEMPSENSE0_POWER_DOWN) == 0) 505 - return -ETIMEDOUT; 506 - } 494 + /* 495 + * Need to disable thermal sensor, otherwise, when thermal core 496 + * try to get temperature before thermal sensor resume, a wrong 497 + * temperature will be read as the thermal sensor is powered 498 + * down. 499 + */ 500 + regmap_write(map, TEMPSENSE0 + REG_CLR, TEMPSENSE0_MEASURE_TEMP); 501 + regmap_write(map, TEMPSENSE0 + REG_SET, TEMPSENSE0_POWER_DOWN); 502 + data->mode = THERMAL_DEVICE_DISABLED; 507 503 508 504 return 0; 509 505 } 510 506 511 507 static int imx_thermal_resume(struct device *dev) 512 508 { 513 - /* Nothing to do for now */ 509 + struct imx_thermal_data *data = dev_get_drvdata(dev); 510 + struct regmap *map = data->tempmon; 511 + 512 + /* Enabled thermal sensor after resume */ 513 + regmap_write(map, TEMPSENSE0 + REG_CLR, TEMPSENSE0_POWER_DOWN); 514 + regmap_write(map, TEMPSENSE0 + REG_SET, TEMPSENSE0_MEASURE_TEMP); 515 + data->mode = THERMAL_DEVICE_ENABLED; 516 + 514 517 return 0; 515 518 } 516 519 #endif ··· 525 522 { .compatible = "fsl,imx6q-tempmon", }, 526 523 { /* end */ } 527 524 }; 525 + MODULE_DEVICE_TABLE(of, of_imx_thermal_match); 528 526 529 527 static struct platform_driver imx_thermal = { 530 528 .driver = {
+237
drivers/thermal/int3403_thermal.c
··· 1 + /* 2 + * ACPI INT3403 thermal driver 3 + * Copyright (c) 2013, Intel Corporation. 4 + * 5 + * This program is free software; you can redistribute it and/or modify it 6 + * under the terms and conditions of the GNU General Public License, 7 + * version 2, as published by the Free Software Foundation. 8 + * 9 + * This program is distributed in the hope it will be useful, but WITHOUT 10 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 12 + * more details. 13 + */ 14 + 15 + #include <linux/kernel.h> 16 + #include <linux/module.h> 17 + #include <linux/init.h> 18 + #include <linux/types.h> 19 + #include <linux/acpi.h> 20 + #include <linux/thermal.h> 21 + 22 + #define INT3403_TYPE_SENSOR 0x03 23 + #define INT3403_PERF_CHANGED_EVENT 0x80 24 + #define INT3403_THERMAL_EVENT 0x90 25 + 26 + #define DECI_KELVIN_TO_MILLI_CELSIUS(t, off) (((t) - (off)) * 100) 27 + #define KELVIN_OFFSET 2732 28 + #define MILLI_CELSIUS_TO_DECI_KELVIN(t, off) (((t) / 100) + (off)) 29 + 30 + #define ACPI_INT3403_CLASS "int3403" 31 + #define ACPI_INT3403_FILE_STATE "state" 32 + 33 + struct int3403_sensor { 34 + struct thermal_zone_device *tzone; 35 + unsigned long *thresholds; 36 + }; 37 + 38 + static int sys_get_curr_temp(struct thermal_zone_device *tzone, 39 + unsigned long *temp) 40 + { 41 + struct acpi_device *device = tzone->devdata; 42 + unsigned long long tmp; 43 + acpi_status status; 44 + 45 + status = acpi_evaluate_integer(device->handle, "_TMP", NULL, &tmp); 46 + if (ACPI_FAILURE(status)) 47 + return -EIO; 48 + 49 + *temp = DECI_KELVIN_TO_MILLI_CELSIUS(tmp, KELVIN_OFFSET); 50 + 51 + return 0; 52 + } 53 + 54 + static int sys_get_trip_hyst(struct thermal_zone_device *tzone, 55 + int trip, unsigned long *temp) 56 + { 57 + struct acpi_device *device = tzone->devdata; 58 + unsigned long long hyst; 59 + acpi_status status; 60 + 61 + status = acpi_evaluate_integer(device->handle, "GTSH", NULL, &hyst); 62 + if (ACPI_FAILURE(status)) 63 + return -EIO; 64 + 65 + *temp = DECI_KELVIN_TO_MILLI_CELSIUS(hyst, KELVIN_OFFSET); 66 + 67 + return 0; 68 + } 69 + 70 + static int sys_get_trip_temp(struct thermal_zone_device *tzone, 71 + int trip, unsigned long *temp) 72 + { 73 + struct acpi_device *device = tzone->devdata; 74 + struct int3403_sensor *obj = acpi_driver_data(device); 75 + 76 + /* 77 + * get_trip_temp is a mandatory callback but 78 + * PATx method doesn't return any value, so return 79 + * cached value, which was last set from user space. 80 + */ 81 + *temp = obj->thresholds[trip]; 82 + 83 + return 0; 84 + } 85 + 86 + static int sys_get_trip_type(struct thermal_zone_device *thermal, 87 + int trip, enum thermal_trip_type *type) 88 + { 89 + /* Mandatory callback, may not mean much here */ 90 + *type = THERMAL_TRIP_PASSIVE; 91 + 92 + return 0; 93 + } 94 + 95 + int sys_set_trip_temp(struct thermal_zone_device *tzone, int trip, 96 + unsigned long temp) 97 + { 98 + struct acpi_device *device = tzone->devdata; 99 + acpi_status status; 100 + char name[10]; 101 + int ret = 0; 102 + struct int3403_sensor *obj = acpi_driver_data(device); 103 + 104 + snprintf(name, sizeof(name), "PAT%d", trip); 105 + if (acpi_has_method(device->handle, name)) { 106 + status = acpi_execute_simple_method(device->handle, name, 107 + MILLI_CELSIUS_TO_DECI_KELVIN(temp, 108 + KELVIN_OFFSET)); 109 + if (ACPI_FAILURE(status)) 110 + ret = -EIO; 111 + else 112 + obj->thresholds[trip] = temp; 113 + } else { 114 + ret = -EIO; 115 + dev_err(&device->dev, "sys_set_trip_temp: method not found\n"); 116 + } 117 + 118 + return ret; 119 + } 120 + 121 + static struct thermal_zone_device_ops tzone_ops = { 122 + .get_temp = sys_get_curr_temp, 123 + .get_trip_temp = sys_get_trip_temp, 124 + .get_trip_type = sys_get_trip_type, 125 + .set_trip_temp = sys_set_trip_temp, 126 + .get_trip_hyst = sys_get_trip_hyst, 127 + }; 128 + 129 + static void acpi_thermal_notify(struct acpi_device *device, u32 event) 130 + { 131 + struct int3403_sensor *obj; 132 + 133 + if (!device) 134 + return; 135 + 136 + obj = acpi_driver_data(device); 137 + if (!obj) 138 + return; 139 + 140 + switch (event) { 141 + case INT3403_PERF_CHANGED_EVENT: 142 + break; 143 + case INT3403_THERMAL_EVENT: 144 + thermal_zone_device_update(obj->tzone); 145 + break; 146 + default: 147 + dev_err(&device->dev, "Unsupported event [0x%x]\n", event); 148 + break; 149 + } 150 + } 151 + 152 + static int acpi_int3403_add(struct acpi_device *device) 153 + { 154 + int result = 0; 155 + unsigned long long ptyp; 156 + acpi_status status; 157 + struct int3403_sensor *obj; 158 + unsigned long long trip_cnt; 159 + int trip_mask = 0; 160 + 161 + if (!device) 162 + return -EINVAL; 163 + 164 + status = acpi_evaluate_integer(device->handle, "PTYP", NULL, &ptyp); 165 + if (ACPI_FAILURE(status)) 166 + return -EINVAL; 167 + 168 + if (ptyp != INT3403_TYPE_SENSOR) 169 + return -EINVAL; 170 + 171 + obj = devm_kzalloc(&device->dev, sizeof(*obj), GFP_KERNEL); 172 + if (!obj) 173 + return -ENOMEM; 174 + 175 + device->driver_data = obj; 176 + 177 + status = acpi_evaluate_integer(device->handle, "PATC", NULL, 178 + &trip_cnt); 179 + if (ACPI_FAILURE(status)) 180 + trip_cnt = 0; 181 + 182 + if (trip_cnt) { 183 + /* We have to cache, thresholds can't be readback */ 184 + obj->thresholds = devm_kzalloc(&device->dev, 185 + sizeof(*obj->thresholds) * trip_cnt, 186 + GFP_KERNEL); 187 + if (!obj->thresholds) 188 + return -ENOMEM; 189 + trip_mask = BIT(trip_cnt) - 1; 190 + } 191 + obj->tzone = thermal_zone_device_register(acpi_device_bid(device), 192 + trip_cnt, trip_mask, device, &tzone_ops, 193 + NULL, 0, 0); 194 + if (IS_ERR(obj->tzone)) { 195 + result = PTR_ERR(obj->tzone); 196 + return result; 197 + } 198 + 199 + strcpy(acpi_device_name(device), "INT3403"); 200 + strcpy(acpi_device_class(device), ACPI_INT3403_CLASS); 201 + 202 + return 0; 203 + } 204 + 205 + static int acpi_int3403_remove(struct acpi_device *device) 206 + { 207 + struct int3403_sensor *obj; 208 + 209 + obj = acpi_driver_data(device); 210 + thermal_zone_device_unregister(obj->tzone); 211 + 212 + return 0; 213 + } 214 + 215 + ACPI_MODULE_NAME("int3403"); 216 + static const struct acpi_device_id int3403_device_ids[] = { 217 + {"INT3403", 0}, 218 + {"", 0}, 219 + }; 220 + MODULE_DEVICE_TABLE(acpi, int3403_device_ids); 221 + 222 + static struct acpi_driver acpi_int3403_driver = { 223 + .name = "INT3403", 224 + .class = ACPI_INT3403_CLASS, 225 + .ids = int3403_device_ids, 226 + .ops = { 227 + .add = acpi_int3403_add, 228 + .remove = acpi_int3403_remove, 229 + .notify = acpi_thermal_notify, 230 + }, 231 + }; 232 + 233 + module_acpi_driver(acpi_int3403_driver); 234 + 235 + MODULE_AUTHOR("Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>"); 236 + MODULE_LICENSE("GPL v2"); 237 + MODULE_DESCRIPTION("ACPI INT3403 thermal driver");
+849
drivers/thermal/of-thermal.c
··· 1 + /* 2 + * of-thermal.c - Generic Thermal Management device tree support. 3 + * 4 + * Copyright (C) 2013 Texas Instruments 5 + * Copyright (C) 2013 Eduardo Valentin <eduardo.valentin@ti.com> 6 + * 7 + * 8 + * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 9 + * 10 + * This program is free software; you can redistribute it and/or modify 11 + * it under the terms of the GNU General Public License as published by 12 + * the Free Software Foundation; version 2 of the License. 13 + * 14 + * This program is distributed in the hope that it will be useful, but 15 + * WITHOUT ANY WARRANTY; without even the implied warranty of 16 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17 + * General Public License for more details. 18 + * 19 + * You should have received a copy of the GNU General Public License along 20 + * with this program; if not, write to the Free Software Foundation, Inc., 21 + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. 22 + * 23 + * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 24 + */ 25 + #include <linux/thermal.h> 26 + #include <linux/slab.h> 27 + #include <linux/types.h> 28 + #include <linux/of_device.h> 29 + #include <linux/of_platform.h> 30 + #include <linux/err.h> 31 + #include <linux/export.h> 32 + #include <linux/string.h> 33 + 34 + #include "thermal_core.h" 35 + 36 + /*** Private data structures to represent thermal device tree data ***/ 37 + 38 + /** 39 + * struct __thermal_trip - representation of a point in temperature domain 40 + * @np: pointer to struct device_node that this trip point was created from 41 + * @temperature: temperature value in miliCelsius 42 + * @hysteresis: relative hysteresis in miliCelsius 43 + * @type: trip point type 44 + */ 45 + 46 + struct __thermal_trip { 47 + struct device_node *np; 48 + unsigned long int temperature; 49 + unsigned long int hysteresis; 50 + enum thermal_trip_type type; 51 + }; 52 + 53 + /** 54 + * struct __thermal_bind_param - a match between trip and cooling device 55 + * @cooling_device: a pointer to identify the referred cooling device 56 + * @trip_id: the trip point index 57 + * @usage: the percentage (from 0 to 100) of cooling contribution 58 + * @min: minimum cooling state used at this trip point 59 + * @max: maximum cooling state used at this trip point 60 + */ 61 + 62 + struct __thermal_bind_params { 63 + struct device_node *cooling_device; 64 + unsigned int trip_id; 65 + unsigned int usage; 66 + unsigned long min; 67 + unsigned long max; 68 + }; 69 + 70 + /** 71 + * struct __thermal_zone - internal representation of a thermal zone 72 + * @mode: current thermal zone device mode (enabled/disabled) 73 + * @passive_delay: polling interval while passive cooling is activated 74 + * @polling_delay: zone polling interval 75 + * @ntrips: number of trip points 76 + * @trips: an array of trip points (0..ntrips - 1) 77 + * @num_tbps: number of thermal bind params 78 + * @tbps: an array of thermal bind params (0..num_tbps - 1) 79 + * @sensor_data: sensor private data used while reading temperature and trend 80 + * @get_temp: sensor callback to read temperature 81 + * @get_trend: sensor callback to read temperature trend 82 + */ 83 + 84 + struct __thermal_zone { 85 + enum thermal_device_mode mode; 86 + int passive_delay; 87 + int polling_delay; 88 + 89 + /* trip data */ 90 + int ntrips; 91 + struct __thermal_trip *trips; 92 + 93 + /* cooling binding data */ 94 + int num_tbps; 95 + struct __thermal_bind_params *tbps; 96 + 97 + /* sensor interface */ 98 + void *sensor_data; 99 + int (*get_temp)(void *, long *); 100 + int (*get_trend)(void *, long *); 101 + }; 102 + 103 + /*** DT thermal zone device callbacks ***/ 104 + 105 + static int of_thermal_get_temp(struct thermal_zone_device *tz, 106 + unsigned long *temp) 107 + { 108 + struct __thermal_zone *data = tz->devdata; 109 + 110 + if (!data->get_temp) 111 + return -EINVAL; 112 + 113 + return data->get_temp(data->sensor_data, temp); 114 + } 115 + 116 + static int of_thermal_get_trend(struct thermal_zone_device *tz, int trip, 117 + enum thermal_trend *trend) 118 + { 119 + struct __thermal_zone *data = tz->devdata; 120 + long dev_trend; 121 + int r; 122 + 123 + if (!data->get_trend) 124 + return -EINVAL; 125 + 126 + r = data->get_trend(data->sensor_data, &dev_trend); 127 + if (r) 128 + return r; 129 + 130 + /* TODO: These intervals might have some thresholds, but in core code */ 131 + if (dev_trend > 0) 132 + *trend = THERMAL_TREND_RAISING; 133 + else if (dev_trend < 0) 134 + *trend = THERMAL_TREND_DROPPING; 135 + else 136 + *trend = THERMAL_TREND_STABLE; 137 + 138 + return 0; 139 + } 140 + 141 + static int of_thermal_bind(struct thermal_zone_device *thermal, 142 + struct thermal_cooling_device *cdev) 143 + { 144 + struct __thermal_zone *data = thermal->devdata; 145 + int i; 146 + 147 + if (!data || IS_ERR(data)) 148 + return -ENODEV; 149 + 150 + /* find where to bind */ 151 + for (i = 0; i < data->num_tbps; i++) { 152 + struct __thermal_bind_params *tbp = data->tbps + i; 153 + 154 + if (tbp->cooling_device == cdev->np) { 155 + int ret; 156 + 157 + ret = thermal_zone_bind_cooling_device(thermal, 158 + tbp->trip_id, cdev, 159 + tbp->min, 160 + tbp->max); 161 + if (ret) 162 + return ret; 163 + } 164 + } 165 + 166 + return 0; 167 + } 168 + 169 + static int of_thermal_unbind(struct thermal_zone_device *thermal, 170 + struct thermal_cooling_device *cdev) 171 + { 172 + struct __thermal_zone *data = thermal->devdata; 173 + int i; 174 + 175 + if (!data || IS_ERR(data)) 176 + return -ENODEV; 177 + 178 + /* find where to unbind */ 179 + for (i = 0; i < data->num_tbps; i++) { 180 + struct __thermal_bind_params *tbp = data->tbps + i; 181 + 182 + if (tbp->cooling_device == cdev->np) { 183 + int ret; 184 + 185 + ret = thermal_zone_unbind_cooling_device(thermal, 186 + tbp->trip_id, cdev); 187 + if (ret) 188 + return ret; 189 + } 190 + } 191 + 192 + return 0; 193 + } 194 + 195 + static int of_thermal_get_mode(struct thermal_zone_device *tz, 196 + enum thermal_device_mode *mode) 197 + { 198 + struct __thermal_zone *data = tz->devdata; 199 + 200 + *mode = data->mode; 201 + 202 + return 0; 203 + } 204 + 205 + static int of_thermal_set_mode(struct thermal_zone_device *tz, 206 + enum thermal_device_mode mode) 207 + { 208 + struct __thermal_zone *data = tz->devdata; 209 + 210 + mutex_lock(&tz->lock); 211 + 212 + if (mode == THERMAL_DEVICE_ENABLED) 213 + tz->polling_delay = data->polling_delay; 214 + else 215 + tz->polling_delay = 0; 216 + 217 + mutex_unlock(&tz->lock); 218 + 219 + data->mode = mode; 220 + thermal_zone_device_update(tz); 221 + 222 + return 0; 223 + } 224 + 225 + static int of_thermal_get_trip_type(struct thermal_zone_device *tz, int trip, 226 + enum thermal_trip_type *type) 227 + { 228 + struct __thermal_zone *data = tz->devdata; 229 + 230 + if (trip >= data->ntrips || trip < 0) 231 + return -EDOM; 232 + 233 + *type = data->trips[trip].type; 234 + 235 + return 0; 236 + } 237 + 238 + static int of_thermal_get_trip_temp(struct thermal_zone_device *tz, int trip, 239 + unsigned long *temp) 240 + { 241 + struct __thermal_zone *data = tz->devdata; 242 + 243 + if (trip >= data->ntrips || trip < 0) 244 + return -EDOM; 245 + 246 + *temp = data->trips[trip].temperature; 247 + 248 + return 0; 249 + } 250 + 251 + static int of_thermal_set_trip_temp(struct thermal_zone_device *tz, int trip, 252 + unsigned long temp) 253 + { 254 + struct __thermal_zone *data = tz->devdata; 255 + 256 + if (trip >= data->ntrips || trip < 0) 257 + return -EDOM; 258 + 259 + /* thermal framework should take care of data->mask & (1 << trip) */ 260 + data->trips[trip].temperature = temp; 261 + 262 + return 0; 263 + } 264 + 265 + static int of_thermal_get_trip_hyst(struct thermal_zone_device *tz, int trip, 266 + unsigned long *hyst) 267 + { 268 + struct __thermal_zone *data = tz->devdata; 269 + 270 + if (trip >= data->ntrips || trip < 0) 271 + return -EDOM; 272 + 273 + *hyst = data->trips[trip].hysteresis; 274 + 275 + return 0; 276 + } 277 + 278 + static int of_thermal_set_trip_hyst(struct thermal_zone_device *tz, int trip, 279 + unsigned long hyst) 280 + { 281 + struct __thermal_zone *data = tz->devdata; 282 + 283 + if (trip >= data->ntrips || trip < 0) 284 + return -EDOM; 285 + 286 + /* thermal framework should take care of data->mask & (1 << trip) */ 287 + data->trips[trip].hysteresis = hyst; 288 + 289 + return 0; 290 + } 291 + 292 + static int of_thermal_get_crit_temp(struct thermal_zone_device *tz, 293 + unsigned long *temp) 294 + { 295 + struct __thermal_zone *data = tz->devdata; 296 + int i; 297 + 298 + for (i = 0; i < data->ntrips; i++) 299 + if (data->trips[i].type == THERMAL_TRIP_CRITICAL) { 300 + *temp = data->trips[i].temperature; 301 + return 0; 302 + } 303 + 304 + return -EINVAL; 305 + } 306 + 307 + static struct thermal_zone_device_ops of_thermal_ops = { 308 + .get_mode = of_thermal_get_mode, 309 + .set_mode = of_thermal_set_mode, 310 + 311 + .get_trip_type = of_thermal_get_trip_type, 312 + .get_trip_temp = of_thermal_get_trip_temp, 313 + .set_trip_temp = of_thermal_set_trip_temp, 314 + .get_trip_hyst = of_thermal_get_trip_hyst, 315 + .set_trip_hyst = of_thermal_set_trip_hyst, 316 + .get_crit_temp = of_thermal_get_crit_temp, 317 + 318 + .bind = of_thermal_bind, 319 + .unbind = of_thermal_unbind, 320 + }; 321 + 322 + /*** sensor API ***/ 323 + 324 + static struct thermal_zone_device * 325 + thermal_zone_of_add_sensor(struct device_node *zone, 326 + struct device_node *sensor, void *data, 327 + int (*get_temp)(void *, long *), 328 + int (*get_trend)(void *, long *)) 329 + { 330 + struct thermal_zone_device *tzd; 331 + struct __thermal_zone *tz; 332 + 333 + tzd = thermal_zone_get_zone_by_name(zone->name); 334 + if (IS_ERR(tzd)) 335 + return ERR_PTR(-EPROBE_DEFER); 336 + 337 + tz = tzd->devdata; 338 + 339 + mutex_lock(&tzd->lock); 340 + tz->get_temp = get_temp; 341 + tz->get_trend = get_trend; 342 + tz->sensor_data = data; 343 + 344 + tzd->ops->get_temp = of_thermal_get_temp; 345 + tzd->ops->get_trend = of_thermal_get_trend; 346 + mutex_unlock(&tzd->lock); 347 + 348 + return tzd; 349 + } 350 + 351 + /** 352 + * thermal_zone_of_sensor_register - registers a sensor to a DT thermal zone 353 + * @dev: a valid struct device pointer of a sensor device. Must contain 354 + * a valid .of_node, for the sensor node. 355 + * @sensor_id: a sensor identifier, in case the sensor IP has more 356 + * than one sensors 357 + * @data: a private pointer (owned by the caller) that will be passed 358 + * back, when a temperature reading is needed. 359 + * @get_temp: a pointer to a function that reads the sensor temperature. 360 + * @get_trend: a pointer to a function that reads the sensor temperature trend. 361 + * 362 + * This function will search the list of thermal zones described in device 363 + * tree and look for the zone that refer to the sensor device pointed by 364 + * @dev->of_node as temperature providers. For the zone pointing to the 365 + * sensor node, the sensor will be added to the DT thermal zone device. 366 + * 367 + * The thermal zone temperature is provided by the @get_temp function 368 + * pointer. When called, it will have the private pointer @data back. 369 + * 370 + * The thermal zone temperature trend is provided by the @get_trend function 371 + * pointer. When called, it will have the private pointer @data back. 372 + * 373 + * TODO: 374 + * 01 - This function must enqueue the new sensor instead of using 375 + * it as the only source of temperature values. 376 + * 377 + * 02 - There must be a way to match the sensor with all thermal zones 378 + * that refer to it. 379 + * 380 + * Return: On success returns a valid struct thermal_zone_device, 381 + * otherwise, it returns a corresponding ERR_PTR(). Caller must 382 + * check the return value with help of IS_ERR() helper. 383 + */ 384 + struct thermal_zone_device * 385 + thermal_zone_of_sensor_register(struct device *dev, int sensor_id, 386 + void *data, int (*get_temp)(void *, long *), 387 + int (*get_trend)(void *, long *)) 388 + { 389 + struct device_node *np, *child, *sensor_np; 390 + 391 + np = of_find_node_by_name(NULL, "thermal-zones"); 392 + if (!np) 393 + return ERR_PTR(-ENODEV); 394 + 395 + if (!dev || !dev->of_node) 396 + return ERR_PTR(-EINVAL); 397 + 398 + sensor_np = dev->of_node; 399 + 400 + for_each_child_of_node(np, child) { 401 + struct of_phandle_args sensor_specs; 402 + int ret, id; 403 + 404 + /* For now, thermal framework supports only 1 sensor per zone */ 405 + ret = of_parse_phandle_with_args(child, "thermal-sensors", 406 + "#thermal-sensor-cells", 407 + 0, &sensor_specs); 408 + if (ret) 409 + continue; 410 + 411 + if (sensor_specs.args_count >= 1) { 412 + id = sensor_specs.args[0]; 413 + WARN(sensor_specs.args_count > 1, 414 + "%s: too many cells in sensor specifier %d\n", 415 + sensor_specs.np->name, sensor_specs.args_count); 416 + } else { 417 + id = 0; 418 + } 419 + 420 + if (sensor_specs.np == sensor_np && id == sensor_id) { 421 + of_node_put(np); 422 + return thermal_zone_of_add_sensor(child, sensor_np, 423 + data, 424 + get_temp, 425 + get_trend); 426 + } 427 + } 428 + of_node_put(np); 429 + 430 + return ERR_PTR(-ENODEV); 431 + } 432 + EXPORT_SYMBOL_GPL(thermal_zone_of_sensor_register); 433 + 434 + /** 435 + * thermal_zone_of_sensor_unregister - unregisters a sensor from a DT thermal zone 436 + * @dev: a valid struct device pointer of a sensor device. Must contain 437 + * a valid .of_node, for the sensor node. 438 + * @tzd: a pointer to struct thermal_zone_device where the sensor is registered. 439 + * 440 + * This function removes the sensor callbacks and private data from the 441 + * thermal zone device registered with thermal_zone_of_sensor_register() 442 + * API. It will also silent the zone by remove the .get_temp() and .get_trend() 443 + * thermal zone device callbacks. 444 + * 445 + * TODO: When the support to several sensors per zone is added, this 446 + * function must search the sensor list based on @dev parameter. 447 + * 448 + */ 449 + void thermal_zone_of_sensor_unregister(struct device *dev, 450 + struct thermal_zone_device *tzd) 451 + { 452 + struct __thermal_zone *tz; 453 + 454 + if (!dev || !tzd || !tzd->devdata) 455 + return; 456 + 457 + tz = tzd->devdata; 458 + 459 + /* no __thermal_zone, nothing to be done */ 460 + if (!tz) 461 + return; 462 + 463 + mutex_lock(&tzd->lock); 464 + tzd->ops->get_temp = NULL; 465 + tzd->ops->get_trend = NULL; 466 + 467 + tz->get_temp = NULL; 468 + tz->get_trend = NULL; 469 + tz->sensor_data = NULL; 470 + mutex_unlock(&tzd->lock); 471 + } 472 + EXPORT_SYMBOL_GPL(thermal_zone_of_sensor_unregister); 473 + 474 + /*** functions parsing device tree nodes ***/ 475 + 476 + /** 477 + * thermal_of_populate_bind_params - parse and fill cooling map data 478 + * @np: DT node containing a cooling-map node 479 + * @__tbp: data structure to be filled with cooling map info 480 + * @trips: array of thermal zone trip points 481 + * @ntrips: number of trip points inside trips. 482 + * 483 + * This function parses a cooling-map type of node represented by 484 + * @np parameter and fills the read data into @__tbp data structure. 485 + * It needs the already parsed array of trip points of the thermal zone 486 + * in consideration. 487 + * 488 + * Return: 0 on success, proper error code otherwise 489 + */ 490 + static int thermal_of_populate_bind_params(struct device_node *np, 491 + struct __thermal_bind_params *__tbp, 492 + struct __thermal_trip *trips, 493 + int ntrips) 494 + { 495 + struct of_phandle_args cooling_spec; 496 + struct device_node *trip; 497 + int ret, i; 498 + u32 prop; 499 + 500 + /* Default weight. Usage is optional */ 501 + __tbp->usage = 0; 502 + ret = of_property_read_u32(np, "contribution", &prop); 503 + if (ret == 0) 504 + __tbp->usage = prop; 505 + 506 + trip = of_parse_phandle(np, "trip", 0); 507 + if (!trip) { 508 + pr_err("missing trip property\n"); 509 + return -ENODEV; 510 + } 511 + 512 + /* match using device_node */ 513 + for (i = 0; i < ntrips; i++) 514 + if (trip == trips[i].np) { 515 + __tbp->trip_id = i; 516 + break; 517 + } 518 + 519 + if (i == ntrips) { 520 + ret = -ENODEV; 521 + goto end; 522 + } 523 + 524 + ret = of_parse_phandle_with_args(np, "cooling-device", "#cooling-cells", 525 + 0, &cooling_spec); 526 + if (ret < 0) { 527 + pr_err("missing cooling_device property\n"); 528 + goto end; 529 + } 530 + __tbp->cooling_device = cooling_spec.np; 531 + if (cooling_spec.args_count >= 2) { /* at least min and max */ 532 + __tbp->min = cooling_spec.args[0]; 533 + __tbp->max = cooling_spec.args[1]; 534 + } else { 535 + pr_err("wrong reference to cooling device, missing limits\n"); 536 + } 537 + 538 + end: 539 + of_node_put(trip); 540 + 541 + return ret; 542 + } 543 + 544 + /** 545 + * It maps 'enum thermal_trip_type' found in include/linux/thermal.h 546 + * into the device tree binding of 'trip', property type. 547 + */ 548 + static const char * const trip_types[] = { 549 + [THERMAL_TRIP_ACTIVE] = "active", 550 + [THERMAL_TRIP_PASSIVE] = "passive", 551 + [THERMAL_TRIP_HOT] = "hot", 552 + [THERMAL_TRIP_CRITICAL] = "critical", 553 + }; 554 + 555 + /** 556 + * thermal_of_get_trip_type - Get phy mode for given device_node 557 + * @np: Pointer to the given device_node 558 + * @type: Pointer to resulting trip type 559 + * 560 + * The function gets trip type string from property 'type', 561 + * and store its index in trip_types table in @type, 562 + * 563 + * Return: 0 on success, or errno in error case. 564 + */ 565 + static int thermal_of_get_trip_type(struct device_node *np, 566 + enum thermal_trip_type *type) 567 + { 568 + const char *t; 569 + int err, i; 570 + 571 + err = of_property_read_string(np, "type", &t); 572 + if (err < 0) 573 + return err; 574 + 575 + for (i = 0; i < ARRAY_SIZE(trip_types); i++) 576 + if (!strcasecmp(t, trip_types[i])) { 577 + *type = i; 578 + return 0; 579 + } 580 + 581 + return -ENODEV; 582 + } 583 + 584 + /** 585 + * thermal_of_populate_trip - parse and fill one trip point data 586 + * @np: DT node containing a trip point node 587 + * @trip: trip point data structure to be filled up 588 + * 589 + * This function parses a trip point type of node represented by 590 + * @np parameter and fills the read data into @trip data structure. 591 + * 592 + * Return: 0 on success, proper error code otherwise 593 + */ 594 + static int thermal_of_populate_trip(struct device_node *np, 595 + struct __thermal_trip *trip) 596 + { 597 + int prop; 598 + int ret; 599 + 600 + ret = of_property_read_u32(np, "temperature", &prop); 601 + if (ret < 0) { 602 + pr_err("missing temperature property\n"); 603 + return ret; 604 + } 605 + trip->temperature = prop; 606 + 607 + ret = of_property_read_u32(np, "hysteresis", &prop); 608 + if (ret < 0) { 609 + pr_err("missing hysteresis property\n"); 610 + return ret; 611 + } 612 + trip->hysteresis = prop; 613 + 614 + ret = thermal_of_get_trip_type(np, &trip->type); 615 + if (ret < 0) { 616 + pr_err("wrong trip type property\n"); 617 + return ret; 618 + } 619 + 620 + /* Required for cooling map matching */ 621 + trip->np = np; 622 + 623 + return 0; 624 + } 625 + 626 + /** 627 + * thermal_of_build_thermal_zone - parse and fill one thermal zone data 628 + * @np: DT node containing a thermal zone node 629 + * 630 + * This function parses a thermal zone type of node represented by 631 + * @np parameter and fills the read data into a __thermal_zone data structure 632 + * and return this pointer. 633 + * 634 + * TODO: Missing properties to parse: thermal-sensor-names and coefficients 635 + * 636 + * Return: On success returns a valid struct __thermal_zone, 637 + * otherwise, it returns a corresponding ERR_PTR(). Caller must 638 + * check the return value with help of IS_ERR() helper. 639 + */ 640 + static struct __thermal_zone * 641 + thermal_of_build_thermal_zone(struct device_node *np) 642 + { 643 + struct device_node *child = NULL, *gchild; 644 + struct __thermal_zone *tz; 645 + int ret, i; 646 + u32 prop; 647 + 648 + if (!np) { 649 + pr_err("no thermal zone np\n"); 650 + return ERR_PTR(-EINVAL); 651 + } 652 + 653 + tz = kzalloc(sizeof(*tz), GFP_KERNEL); 654 + if (!tz) 655 + return ERR_PTR(-ENOMEM); 656 + 657 + ret = of_property_read_u32(np, "polling-delay-passive", &prop); 658 + if (ret < 0) { 659 + pr_err("missing polling-delay-passive property\n"); 660 + goto free_tz; 661 + } 662 + tz->passive_delay = prop; 663 + 664 + ret = of_property_read_u32(np, "polling-delay", &prop); 665 + if (ret < 0) { 666 + pr_err("missing polling-delay property\n"); 667 + goto free_tz; 668 + } 669 + tz->polling_delay = prop; 670 + 671 + /* trips */ 672 + child = of_get_child_by_name(np, "trips"); 673 + 674 + /* No trips provided */ 675 + if (!child) 676 + goto finish; 677 + 678 + tz->ntrips = of_get_child_count(child); 679 + if (tz->ntrips == 0) /* must have at least one child */ 680 + goto finish; 681 + 682 + tz->trips = kzalloc(tz->ntrips * sizeof(*tz->trips), GFP_KERNEL); 683 + if (!tz->trips) { 684 + ret = -ENOMEM; 685 + goto free_tz; 686 + } 687 + 688 + i = 0; 689 + for_each_child_of_node(child, gchild) { 690 + ret = thermal_of_populate_trip(gchild, &tz->trips[i++]); 691 + if (ret) 692 + goto free_trips; 693 + } 694 + 695 + of_node_put(child); 696 + 697 + /* cooling-maps */ 698 + child = of_get_child_by_name(np, "cooling-maps"); 699 + 700 + /* cooling-maps not provided */ 701 + if (!child) 702 + goto finish; 703 + 704 + tz->num_tbps = of_get_child_count(child); 705 + if (tz->num_tbps == 0) 706 + goto finish; 707 + 708 + tz->tbps = kzalloc(tz->num_tbps * sizeof(*tz->tbps), GFP_KERNEL); 709 + if (!tz->tbps) { 710 + ret = -ENOMEM; 711 + goto free_trips; 712 + } 713 + 714 + i = 0; 715 + for_each_child_of_node(child, gchild) 716 + ret = thermal_of_populate_bind_params(gchild, &tz->tbps[i++], 717 + tz->trips, tz->ntrips); 718 + if (ret) 719 + goto free_tbps; 720 + 721 + finish: 722 + of_node_put(child); 723 + tz->mode = THERMAL_DEVICE_DISABLED; 724 + 725 + return tz; 726 + 727 + free_tbps: 728 + kfree(tz->tbps); 729 + free_trips: 730 + kfree(tz->trips); 731 + free_tz: 732 + kfree(tz); 733 + of_node_put(child); 734 + 735 + return ERR_PTR(ret); 736 + } 737 + 738 + static inline void of_thermal_free_zone(struct __thermal_zone *tz) 739 + { 740 + kfree(tz->tbps); 741 + kfree(tz->trips); 742 + kfree(tz); 743 + } 744 + 745 + /** 746 + * of_parse_thermal_zones - parse device tree thermal data 747 + * 748 + * Initialization function that can be called by machine initialization 749 + * code to parse thermal data and populate the thermal framework 750 + * with hardware thermal zones info. This function only parses thermal zones. 751 + * Cooling devices and sensor devices nodes are supposed to be parsed 752 + * by their respective drivers. 753 + * 754 + * Return: 0 on success, proper error code otherwise 755 + * 756 + */ 757 + int __init of_parse_thermal_zones(void) 758 + { 759 + struct device_node *np, *child; 760 + struct __thermal_zone *tz; 761 + struct thermal_zone_device_ops *ops; 762 + 763 + np = of_find_node_by_name(NULL, "thermal-zones"); 764 + if (!np) { 765 + pr_debug("unable to find thermal zones\n"); 766 + return 0; /* Run successfully on systems without thermal DT */ 767 + } 768 + 769 + for_each_child_of_node(np, child) { 770 + struct thermal_zone_device *zone; 771 + struct thermal_zone_params *tzp; 772 + 773 + tz = thermal_of_build_thermal_zone(child); 774 + if (IS_ERR(tz)) { 775 + pr_err("failed to build thermal zone %s: %ld\n", 776 + child->name, 777 + PTR_ERR(tz)); 778 + continue; 779 + } 780 + 781 + ops = kmemdup(&of_thermal_ops, sizeof(*ops), GFP_KERNEL); 782 + if (!ops) 783 + goto exit_free; 784 + 785 + tzp = kzalloc(sizeof(*tzp), GFP_KERNEL); 786 + if (!tzp) { 787 + kfree(ops); 788 + goto exit_free; 789 + } 790 + 791 + /* No hwmon because there might be hwmon drivers registering */ 792 + tzp->no_hwmon = true; 793 + 794 + zone = thermal_zone_device_register(child->name, tz->ntrips, 795 + 0, tz, 796 + ops, tzp, 797 + tz->passive_delay, 798 + tz->polling_delay); 799 + if (IS_ERR(zone)) { 800 + pr_err("Failed to build %s zone %ld\n", child->name, 801 + PTR_ERR(zone)); 802 + kfree(tzp); 803 + kfree(ops); 804 + of_thermal_free_zone(tz); 805 + /* attempting to build remaining zones still */ 806 + } 807 + } 808 + 809 + return 0; 810 + 811 + exit_free: 812 + of_thermal_free_zone(tz); 813 + 814 + /* no memory available, so free what we have built */ 815 + of_thermal_destroy_zones(); 816 + 817 + return -ENOMEM; 818 + } 819 + 820 + /** 821 + * of_thermal_destroy_zones - remove all zones parsed and allocated resources 822 + * 823 + * Finds all zones parsed and added to the thermal framework and remove them 824 + * from the system, together with their resources. 825 + * 826 + */ 827 + void of_thermal_destroy_zones(void) 828 + { 829 + struct device_node *np, *child; 830 + 831 + np = of_find_node_by_name(NULL, "thermal-zones"); 832 + if (!np) { 833 + pr_err("unable to find thermal zones\n"); 834 + return; 835 + } 836 + 837 + for_each_child_of_node(np, child) { 838 + struct thermal_zone_device *zone; 839 + 840 + zone = thermal_zone_get_zone_by_name(child->name); 841 + if (IS_ERR(zone)) 842 + continue; 843 + 844 + thermal_zone_device_unregister(zone); 845 + kfree(zone->tzp); 846 + kfree(zone->ops); 847 + of_thermal_free_zone(zone->devdata); 848 + } 849 + }
+1 -1
drivers/thermal/samsung/exynos_thermal_common.c
··· 280 280 return 0; 281 281 } 282 282 /* Operation callback functions for thermal zone */ 283 - static struct thermal_zone_device_ops const exynos_dev_ops = { 283 + static struct thermal_zone_device_ops exynos_dev_ops = { 284 284 .bind = exynos_bind, 285 285 .unbind = exynos_unbind, 286 286 .get_temp = exynos_get_temp,
+1
drivers/thermal/samsung/exynos_tmu.c
··· 205 205 skip_calib_data: 206 206 if (pdata->max_trigger_level > MAX_THRESHOLD_LEVS) { 207 207 dev_err(&pdev->dev, "Invalid max trigger level\n"); 208 + ret = -EINVAL; 208 209 goto out; 209 210 } 210 211
+70 -7
drivers/thermal/thermal_core.c
··· 34 34 #include <linux/thermal.h> 35 35 #include <linux/reboot.h> 36 36 #include <linux/string.h> 37 + #include <linux/of.h> 37 38 #include <net/netlink.h> 38 39 #include <net/genetlink.h> 39 40 ··· 404 403 enum thermal_trip_type type; 405 404 #endif 406 405 407 - if (!tz || IS_ERR(tz)) 406 + if (!tz || IS_ERR(tz) || !tz->ops->get_temp) 408 407 goto exit; 409 408 410 409 mutex_lock(&tz->lock); ··· 459 458 void thermal_zone_device_update(struct thermal_zone_device *tz) 460 459 { 461 460 int count; 461 + 462 + if (!tz->ops->get_temp) 463 + return; 462 464 463 465 update_temperature(tz); 464 466 ··· 1059 1055 }; 1060 1056 1061 1057 /** 1062 - * thermal_cooling_device_register() - register a new thermal cooling device 1058 + * __thermal_cooling_device_register() - register a new thermal cooling device 1059 + * @np: a pointer to a device tree node. 1063 1060 * @type: the thermal cooling device type. 1064 1061 * @devdata: device private data. 1065 1062 * @ops: standard thermal cooling devices callbacks. ··· 1068 1063 * This interface function adds a new thermal cooling device (fan/processor/...) 1069 1064 * to /sys/class/thermal/ folder as cooling_device[0-*]. It tries to bind itself 1070 1065 * to all the thermal zone devices registered at the same time. 1066 + * It also gives the opportunity to link the cooling device to a device tree 1067 + * node, so that it can be bound to a thermal zone created out of device tree. 1071 1068 * 1072 1069 * Return: a pointer to the created struct thermal_cooling_device or an 1073 1070 * ERR_PTR. Caller must check return value with IS_ERR*() helpers. 1074 1071 */ 1075 - struct thermal_cooling_device * 1076 - thermal_cooling_device_register(char *type, void *devdata, 1077 - const struct thermal_cooling_device_ops *ops) 1072 + static struct thermal_cooling_device * 1073 + __thermal_cooling_device_register(struct device_node *np, 1074 + char *type, void *devdata, 1075 + const struct thermal_cooling_device_ops *ops) 1078 1076 { 1079 1077 struct thermal_cooling_device *cdev; 1080 1078 int result; ··· 1102 1094 strlcpy(cdev->type, type ? : "", sizeof(cdev->type)); 1103 1095 mutex_init(&cdev->lock); 1104 1096 INIT_LIST_HEAD(&cdev->thermal_instances); 1097 + cdev->np = np; 1105 1098 cdev->ops = ops; 1106 1099 cdev->updated = true; 1107 1100 cdev->device.class = &thermal_class; ··· 1145 1136 device_unregister(&cdev->device); 1146 1137 return ERR_PTR(result); 1147 1138 } 1139 + 1140 + /** 1141 + * thermal_cooling_device_register() - register a new thermal cooling device 1142 + * @type: the thermal cooling device type. 1143 + * @devdata: device private data. 1144 + * @ops: standard thermal cooling devices callbacks. 1145 + * 1146 + * This interface function adds a new thermal cooling device (fan/processor/...) 1147 + * to /sys/class/thermal/ folder as cooling_device[0-*]. It tries to bind itself 1148 + * to all the thermal zone devices registered at the same time. 1149 + * 1150 + * Return: a pointer to the created struct thermal_cooling_device or an 1151 + * ERR_PTR. Caller must check return value with IS_ERR*() helpers. 1152 + */ 1153 + struct thermal_cooling_device * 1154 + thermal_cooling_device_register(char *type, void *devdata, 1155 + const struct thermal_cooling_device_ops *ops) 1156 + { 1157 + return __thermal_cooling_device_register(NULL, type, devdata, ops); 1158 + } 1148 1159 EXPORT_SYMBOL_GPL(thermal_cooling_device_register); 1160 + 1161 + /** 1162 + * thermal_of_cooling_device_register() - register an OF thermal cooling device 1163 + * @np: a pointer to a device tree node. 1164 + * @type: the thermal cooling device type. 1165 + * @devdata: device private data. 1166 + * @ops: standard thermal cooling devices callbacks. 1167 + * 1168 + * This function will register a cooling device with device tree node reference. 1169 + * This interface function adds a new thermal cooling device (fan/processor/...) 1170 + * to /sys/class/thermal/ folder as cooling_device[0-*]. It tries to bind itself 1171 + * to all the thermal zone devices registered at the same time. 1172 + * 1173 + * Return: a pointer to the created struct thermal_cooling_device or an 1174 + * ERR_PTR. Caller must check return value with IS_ERR*() helpers. 1175 + */ 1176 + struct thermal_cooling_device * 1177 + thermal_of_cooling_device_register(struct device_node *np, 1178 + char *type, void *devdata, 1179 + const struct thermal_cooling_device_ops *ops) 1180 + { 1181 + return __thermal_cooling_device_register(np, type, devdata, ops); 1182 + } 1183 + EXPORT_SYMBOL_GPL(thermal_of_cooling_device_register); 1149 1184 1150 1185 /** 1151 1186 * thermal_cooling_device_unregister - removes the registered thermal cooling device ··· 1429 1376 */ 1430 1377 struct thermal_zone_device *thermal_zone_device_register(const char *type, 1431 1378 int trips, int mask, void *devdata, 1432 - const struct thermal_zone_device_ops *ops, 1379 + struct thermal_zone_device_ops *ops, 1433 1380 const struct thermal_zone_params *tzp, 1434 1381 int passive_delay, int polling_delay) 1435 1382 { ··· 1445 1392 if (trips > THERMAL_MAX_TRIPS || trips < 0 || mask >> trips) 1446 1393 return ERR_PTR(-EINVAL); 1447 1394 1448 - if (!ops || !ops->get_temp) 1395 + if (!ops) 1449 1396 return ERR_PTR(-EINVAL); 1450 1397 1451 1398 if (trips > 0 && (!ops->get_trip_type || !ops->get_trip_temp)) ··· 1548 1495 bind_tz(tz); 1549 1496 1550 1497 INIT_DELAYED_WORK(&(tz->poll_queue), thermal_zone_device_check); 1498 + 1499 + if (!tz->ops->get_temp) 1500 + thermal_zone_device_set_polling(tz, 0); 1551 1501 1552 1502 thermal_zone_device_update(tz); 1553 1503 ··· 1802 1746 if (result) 1803 1747 goto unregister_class; 1804 1748 1749 + result = of_parse_thermal_zones(); 1750 + if (result) 1751 + goto exit_netlink; 1752 + 1805 1753 return 0; 1806 1754 1755 + exit_netlink: 1756 + genetlink_exit(); 1807 1757 unregister_governors: 1808 1758 thermal_unregister_governors(); 1809 1759 unregister_class: ··· 1825 1763 1826 1764 static void __exit thermal_exit(void) 1827 1765 { 1766 + of_thermal_destroy_zones(); 1828 1767 genetlink_exit(); 1829 1768 class_unregister(&thermal_class); 1830 1769 thermal_unregister_governors();
+9
drivers/thermal/thermal_core.h
··· 77 77 static inline void thermal_gov_user_space_unregister(void) {} 78 78 #endif /* CONFIG_THERMAL_GOV_USER_SPACE */ 79 79 80 + /* device tree support */ 81 + #ifdef CONFIG_THERMAL_OF 82 + int of_parse_thermal_zones(void); 83 + void of_thermal_destroy_zones(void); 84 + #else 85 + static inline int of_parse_thermal_zones(void) { return 0; } 86 + static inline void of_thermal_destroy_zones(void) { } 87 + #endif 88 + 80 89 #endif /* __THERMAL_CORE_H__ */
+62 -15
drivers/thermal/ti-soc-thermal/ti-thermal-common.c
··· 31 31 #include <linux/cpufreq.h> 32 32 #include <linux/cpumask.h> 33 33 #include <linux/cpu_cooling.h> 34 + #include <linux/of.h> 34 35 35 36 #include "ti-thermal.h" 36 37 #include "ti-bandgap.h" ··· 45 44 enum thermal_device_mode mode; 46 45 struct work_struct thermal_wq; 47 46 int sensor_id; 47 + bool our_zone; 48 48 }; 49 49 50 50 static void ti_thermal_work(struct work_struct *work) ··· 77 75 78 76 /* thermal zone ops */ 79 77 /* Get temperature callback function for thermal zone*/ 80 - static inline int ti_thermal_get_temp(struct thermal_zone_device *thermal, 81 - unsigned long *temp) 78 + static inline int __ti_thermal_get_temp(void *devdata, long *temp) 82 79 { 83 80 struct thermal_zone_device *pcb_tz = NULL; 84 - struct ti_thermal_data *data = thermal->devdata; 81 + struct ti_thermal_data *data = devdata; 85 82 struct ti_bandgap *bgp; 86 83 const struct ti_temp_sensor *s; 87 84 int ret, tmp, slope, constant; ··· 117 116 *temp = ti_thermal_hotspot_temperature(tmp, slope, constant); 118 117 119 118 return ret; 119 + } 120 + 121 + static inline int ti_thermal_get_temp(struct thermal_zone_device *thermal, 122 + unsigned long *temp) 123 + { 124 + struct ti_thermal_data *data = thermal->devdata; 125 + 126 + return __ti_thermal_get_temp(data, temp); 120 127 } 121 128 122 129 /* Bind callback functions for thermal zone */ ··· 239 230 return 0; 240 231 } 241 232 242 - /* Get the temperature trend callback functions for thermal zone */ 243 - static int ti_thermal_get_trend(struct thermal_zone_device *thermal, 244 - int trip, enum thermal_trend *trend) 233 + static int __ti_thermal_get_trend(void *p, long *trend) 245 234 { 246 - struct ti_thermal_data *data = thermal->devdata; 235 + struct ti_thermal_data *data = p; 247 236 struct ti_bandgap *bgp; 248 237 int id, tr, ret = 0; 249 238 ··· 249 242 id = data->sensor_id; 250 243 251 244 ret = ti_bandgap_get_trend(bgp, id, &tr); 245 + if (ret) 246 + return ret; 247 + 248 + *trend = tr; 249 + 250 + return 0; 251 + } 252 + 253 + /* Get the temperature trend callback functions for thermal zone */ 254 + static int ti_thermal_get_trend(struct thermal_zone_device *thermal, 255 + int trip, enum thermal_trend *trend) 256 + { 257 + int ret; 258 + long tr; 259 + 260 + ret = __ti_thermal_get_trend(thermal->devdata, &tr); 252 261 if (ret) 253 262 return ret; 254 263 ··· 331 308 if (!data) 332 309 return -EINVAL; 333 310 334 - /* Create thermal zone */ 335 - data->ti_thermal = thermal_zone_device_register(domain, 311 + /* in case this is specified by DT */ 312 + data->ti_thermal = thermal_zone_of_sensor_register(bgp->dev, id, 313 + data, __ti_thermal_get_temp, 314 + __ti_thermal_get_trend); 315 + if (IS_ERR(data->ti_thermal)) { 316 + /* Create thermal zone */ 317 + data->ti_thermal = thermal_zone_device_register(domain, 336 318 OMAP_TRIP_NUMBER, 0, data, &ti_thermal_ops, 337 319 NULL, FAST_TEMP_MONITORING_RATE, 338 320 FAST_TEMP_MONITORING_RATE); 339 - if (IS_ERR(data->ti_thermal)) { 340 - dev_err(bgp->dev, "thermal zone device is NULL\n"); 341 - return PTR_ERR(data->ti_thermal); 321 + if (IS_ERR(data->ti_thermal)) { 322 + dev_err(bgp->dev, "thermal zone device is NULL\n"); 323 + return PTR_ERR(data->ti_thermal); 324 + } 325 + data->ti_thermal->polling_delay = FAST_TEMP_MONITORING_RATE; 326 + data->our_zone = true; 342 327 } 343 - data->ti_thermal->polling_delay = FAST_TEMP_MONITORING_RATE; 344 328 ti_bandgap_set_sensor_data(bgp, id, data); 345 329 ti_bandgap_write_update_interval(bgp, data->sensor_id, 346 330 data->ti_thermal->polling_delay); ··· 361 331 362 332 data = ti_bandgap_get_sensor_data(bgp, id); 363 333 364 - thermal_zone_device_unregister(data->ti_thermal); 334 + if (data && data->ti_thermal) { 335 + if (data->our_zone) 336 + thermal_zone_device_unregister(data->ti_thermal); 337 + else 338 + thermal_zone_of_sensor_unregister(bgp->dev, 339 + data->ti_thermal); 340 + } 365 341 366 342 return 0; 367 343 } ··· 386 350 int ti_thermal_register_cpu_cooling(struct ti_bandgap *bgp, int id) 387 351 { 388 352 struct ti_thermal_data *data; 353 + struct device_node *np = bgp->dev->of_node; 354 + 355 + /* 356 + * We are assuming here that if one deploys the zone 357 + * using DT, then it must be aware that the cooling device 358 + * loading has to happen via cpufreq driver. 359 + */ 360 + if (of_find_property(np, "#thermal-sensor-cells", NULL)) 361 + return 0; 389 362 390 363 data = ti_bandgap_get_sensor_data(bgp, id); 391 364 if (!data || IS_ERR(data)) ··· 425 380 struct ti_thermal_data *data; 426 381 427 382 data = ti_bandgap_get_sensor_data(bgp, id); 428 - cpufreq_cooling_unregister(data->cool_dev); 383 + 384 + if (data && data->cool_dev) 385 + cpufreq_cooling_unregister(data->cool_dev); 429 386 430 387 return 0; 431 388 }
+1 -1
drivers/thermal/x86_pkg_temp_thermal.c
··· 215 215 return 0; 216 216 } 217 217 218 - int sys_set_trip_temp(struct thermal_zone_device *tzd, int trip, 218 + static int sys_set_trip_temp(struct thermal_zone_device *tzd, int trip, 219 219 unsigned long temp) 220 220 { 221 221 u32 l, h;
+17
include/dt-bindings/thermal/thermal.h
··· 1 + /* 2 + * This header provides constants for most thermal bindings. 3 + * 4 + * Copyright (C) 2013 Texas Instruments 5 + * Eduardo Valentin <eduardo.valentin@ti.com> 6 + * 7 + * GPLv2 only 8 + */ 9 + 10 + #ifndef _DT_BINDINGS_THERMAL_THERMAL_H 11 + #define _DT_BINDINGS_THERMAL_THERMAL_H 12 + 13 + /* On cooling devices upper and lower limits */ 14 + #define THERMAL_NO_LIMIT (-1UL) 15 + 16 + #endif 17 +
+25
include/linux/cpu_cooling.h
··· 24 24 #ifndef __CPU_COOLING_H__ 25 25 #define __CPU_COOLING_H__ 26 26 27 + #include <linux/of.h> 27 28 #include <linux/thermal.h> 28 29 #include <linux/cpumask.h> 29 30 ··· 37 36 cpufreq_cooling_register(const struct cpumask *clip_cpus); 38 37 39 38 /** 39 + * of_cpufreq_cooling_register - create cpufreq cooling device based on DT. 40 + * @np: a valid struct device_node to the cooling device device tree node. 41 + * @clip_cpus: cpumask of cpus where the frequency constraints will happen 42 + */ 43 + #ifdef CONFIG_THERMAL_OF 44 + struct thermal_cooling_device * 45 + of_cpufreq_cooling_register(struct device_node *np, 46 + const struct cpumask *clip_cpus); 47 + #else 48 + static inline struct thermal_cooling_device * 49 + of_cpufreq_cooling_register(struct device_node *np, 50 + const struct cpumask *clip_cpus) 51 + { 52 + return NULL; 53 + } 54 + #endif 55 + 56 + /** 40 57 * cpufreq_cooling_unregister - function to remove cpufreq cooling device. 41 58 * @cdev: thermal cooling device pointer. 42 59 */ ··· 64 45 #else /* !CONFIG_CPU_THERMAL */ 65 46 static inline struct thermal_cooling_device * 66 47 cpufreq_cooling_register(const struct cpumask *clip_cpus) 48 + { 49 + return NULL; 50 + } 51 + static inline struct thermal_cooling_device * 52 + of_cpufreq_cooling_register(struct device_node *np, 53 + const struct cpumask *clip_cpus) 67 54 { 68 55 return NULL; 69 56 }
+30 -2
include/linux/thermal.h
··· 25 25 #ifndef __THERMAL_H__ 26 26 #define __THERMAL_H__ 27 27 28 + #include <linux/of.h> 28 29 #include <linux/idr.h> 29 30 #include <linux/device.h> 30 31 #include <linux/workqueue.h> ··· 144 143 int id; 145 144 char type[THERMAL_NAME_LENGTH]; 146 145 struct device device; 146 + struct device_node *np; 147 147 void *devdata; 148 148 const struct thermal_cooling_device_ops *ops; 149 149 bool updated; /* true if the cooling device does not need update */ ··· 174 172 int emul_temperature; 175 173 int passive; 176 174 unsigned int forced_passive; 177 - const struct thermal_zone_device_ops *ops; 175 + struct thermal_zone_device_ops *ops; 178 176 const struct thermal_zone_params *tzp; 179 177 struct thermal_governor *governor; 180 178 struct list_head thermal_instances; ··· 244 242 }; 245 243 246 244 /* Function declarations */ 245 + #ifdef CONFIG_THERMAL_OF 246 + struct thermal_zone_device * 247 + thermal_zone_of_sensor_register(struct device *dev, int id, 248 + void *data, int (*get_temp)(void *, long *), 249 + int (*get_trend)(void *, long *)); 250 + void thermal_zone_of_sensor_unregister(struct device *dev, 251 + struct thermal_zone_device *tz); 252 + #else 253 + static inline struct thermal_zone_device * 254 + thermal_zone_of_sensor_register(struct device *dev, int id, 255 + void *data, int (*get_temp)(void *, long *), 256 + int (*get_trend)(void *, long *)) 257 + { 258 + return NULL; 259 + } 260 + 261 + static inline 262 + void thermal_zone_of_sensor_unregister(struct device *dev, 263 + struct thermal_zone_device *tz) 264 + { 265 + } 266 + 267 + #endif 247 268 struct thermal_zone_device *thermal_zone_device_register(const char *, int, int, 248 - void *, const struct thermal_zone_device_ops *, 269 + void *, struct thermal_zone_device_ops *, 249 270 const struct thermal_zone_params *, int, int); 250 271 void thermal_zone_device_unregister(struct thermal_zone_device *); 251 272 ··· 281 256 282 257 struct thermal_cooling_device *thermal_cooling_device_register(char *, void *, 283 258 const struct thermal_cooling_device_ops *); 259 + struct thermal_cooling_device * 260 + thermal_of_cooling_device_register(struct device_node *np, char *, void *, 261 + const struct thermal_cooling_device_ops *); 284 262 void thermal_cooling_device_unregister(struct thermal_cooling_device *); 285 263 struct thermal_zone_device *thermal_zone_get_zone_by_name(const char *name); 286 264 int thermal_zone_get_temp(struct thermal_zone_device *tz, unsigned long *temp);