18c2ecf20Sopenharmony_ci=================================== 28c2ecf20Sopenharmony_ciGeneric Thermal Sysfs driver How To 38c2ecf20Sopenharmony_ci=================================== 48c2ecf20Sopenharmony_ci 58c2ecf20Sopenharmony_ciWritten by Sujith Thomas <sujith.thomas@intel.com>, Zhang Rui <rui.zhang@intel.com> 68c2ecf20Sopenharmony_ci 78c2ecf20Sopenharmony_ciUpdated: 2 January 2008 88c2ecf20Sopenharmony_ci 98c2ecf20Sopenharmony_ciCopyright (c) 2008 Intel Corporation 108c2ecf20Sopenharmony_ci 118c2ecf20Sopenharmony_ci 128c2ecf20Sopenharmony_ci0. Introduction 138c2ecf20Sopenharmony_ci=============== 148c2ecf20Sopenharmony_ci 158c2ecf20Sopenharmony_ciThe generic thermal sysfs provides a set of interfaces for thermal zone 168c2ecf20Sopenharmony_cidevices (sensors) and thermal cooling devices (fan, processor...) to register 178c2ecf20Sopenharmony_ciwith the thermal management solution and to be a part of it. 188c2ecf20Sopenharmony_ci 198c2ecf20Sopenharmony_ciThis how-to focuses on enabling new thermal zone and cooling devices to 208c2ecf20Sopenharmony_ciparticipate in thermal management. 218c2ecf20Sopenharmony_ciThis solution is platform independent and any type of thermal zone devices 228c2ecf20Sopenharmony_ciand cooling devices should be able to make use of the infrastructure. 238c2ecf20Sopenharmony_ci 248c2ecf20Sopenharmony_ciThe main task of the thermal sysfs driver is to expose thermal zone attributes 258c2ecf20Sopenharmony_cias well as cooling device attributes to the user space. 268c2ecf20Sopenharmony_ciAn intelligent thermal management application can make decisions based on 278c2ecf20Sopenharmony_ciinputs from thermal zone attributes (the current temperature and trip point 288c2ecf20Sopenharmony_citemperature) and throttle appropriate devices. 298c2ecf20Sopenharmony_ci 308c2ecf20Sopenharmony_ci- `[0-*]` denotes any positive number starting from 0 318c2ecf20Sopenharmony_ci- `[1-*]` denotes any positive number starting from 1 328c2ecf20Sopenharmony_ci 338c2ecf20Sopenharmony_ci1. thermal sysfs driver interface functions 348c2ecf20Sopenharmony_ci=========================================== 358c2ecf20Sopenharmony_ci 368c2ecf20Sopenharmony_ci1.1 thermal zone device interface 378c2ecf20Sopenharmony_ci--------------------------------- 388c2ecf20Sopenharmony_ci 398c2ecf20Sopenharmony_ci :: 408c2ecf20Sopenharmony_ci 418c2ecf20Sopenharmony_ci struct thermal_zone_device 428c2ecf20Sopenharmony_ci *thermal_zone_device_register(char *type, 438c2ecf20Sopenharmony_ci int trips, int mask, void *devdata, 448c2ecf20Sopenharmony_ci struct thermal_zone_device_ops *ops, 458c2ecf20Sopenharmony_ci const struct thermal_zone_params *tzp, 468c2ecf20Sopenharmony_ci int passive_delay, int polling_delay)) 478c2ecf20Sopenharmony_ci 488c2ecf20Sopenharmony_ci This interface function adds a new thermal zone device (sensor) to 498c2ecf20Sopenharmony_ci /sys/class/thermal folder as `thermal_zone[0-*]`. It tries to bind all the 508c2ecf20Sopenharmony_ci thermal cooling devices registered at the same time. 518c2ecf20Sopenharmony_ci 528c2ecf20Sopenharmony_ci type: 538c2ecf20Sopenharmony_ci the thermal zone type. 548c2ecf20Sopenharmony_ci trips: 558c2ecf20Sopenharmony_ci the total number of trip points this thermal zone supports. 568c2ecf20Sopenharmony_ci mask: 578c2ecf20Sopenharmony_ci Bit string: If 'n'th bit is set, then trip point 'n' is writeable. 588c2ecf20Sopenharmony_ci devdata: 598c2ecf20Sopenharmony_ci device private data 608c2ecf20Sopenharmony_ci ops: 618c2ecf20Sopenharmony_ci thermal zone device call-backs. 628c2ecf20Sopenharmony_ci 638c2ecf20Sopenharmony_ci .bind: 648c2ecf20Sopenharmony_ci bind the thermal zone device with a thermal cooling device. 658c2ecf20Sopenharmony_ci .unbind: 668c2ecf20Sopenharmony_ci unbind the thermal zone device with a thermal cooling device. 678c2ecf20Sopenharmony_ci .get_temp: 688c2ecf20Sopenharmony_ci get the current temperature of the thermal zone. 698c2ecf20Sopenharmony_ci .set_trips: 708c2ecf20Sopenharmony_ci set the trip points window. Whenever the current temperature 718c2ecf20Sopenharmony_ci is updated, the trip points immediately below and above the 728c2ecf20Sopenharmony_ci current temperature are found. 738c2ecf20Sopenharmony_ci .get_mode: 748c2ecf20Sopenharmony_ci get the current mode (enabled/disabled) of the thermal zone. 758c2ecf20Sopenharmony_ci 768c2ecf20Sopenharmony_ci - "enabled" means the kernel thermal management is 778c2ecf20Sopenharmony_ci enabled. 788c2ecf20Sopenharmony_ci - "disabled" will prevent kernel thermal driver action 798c2ecf20Sopenharmony_ci upon trip points so that user applications can take 808c2ecf20Sopenharmony_ci charge of thermal management. 818c2ecf20Sopenharmony_ci .set_mode: 828c2ecf20Sopenharmony_ci set the mode (enabled/disabled) of the thermal zone. 838c2ecf20Sopenharmony_ci .get_trip_type: 848c2ecf20Sopenharmony_ci get the type of certain trip point. 858c2ecf20Sopenharmony_ci .get_trip_temp: 868c2ecf20Sopenharmony_ci get the temperature above which the certain trip point 878c2ecf20Sopenharmony_ci will be fired. 888c2ecf20Sopenharmony_ci .set_emul_temp: 898c2ecf20Sopenharmony_ci set the emulation temperature which helps in debugging 908c2ecf20Sopenharmony_ci different threshold temperature points. 918c2ecf20Sopenharmony_ci tzp: 928c2ecf20Sopenharmony_ci thermal zone platform parameters. 938c2ecf20Sopenharmony_ci passive_delay: 948c2ecf20Sopenharmony_ci number of milliseconds to wait between polls when 958c2ecf20Sopenharmony_ci performing passive cooling. 968c2ecf20Sopenharmony_ci polling_delay: 978c2ecf20Sopenharmony_ci number of milliseconds to wait between polls when checking 988c2ecf20Sopenharmony_ci whether trip points have been crossed (0 for interrupt driven systems). 998c2ecf20Sopenharmony_ci 1008c2ecf20Sopenharmony_ci :: 1018c2ecf20Sopenharmony_ci 1028c2ecf20Sopenharmony_ci void thermal_zone_device_unregister(struct thermal_zone_device *tz) 1038c2ecf20Sopenharmony_ci 1048c2ecf20Sopenharmony_ci This interface function removes the thermal zone device. 1058c2ecf20Sopenharmony_ci It deletes the corresponding entry from /sys/class/thermal folder and 1068c2ecf20Sopenharmony_ci unbinds all the thermal cooling devices it uses. 1078c2ecf20Sopenharmony_ci 1088c2ecf20Sopenharmony_ci :: 1098c2ecf20Sopenharmony_ci 1108c2ecf20Sopenharmony_ci struct thermal_zone_device 1118c2ecf20Sopenharmony_ci *thermal_zone_of_sensor_register(struct device *dev, int sensor_id, 1128c2ecf20Sopenharmony_ci void *data, 1138c2ecf20Sopenharmony_ci const struct thermal_zone_of_device_ops *ops) 1148c2ecf20Sopenharmony_ci 1158c2ecf20Sopenharmony_ci This interface adds a new sensor to a DT thermal zone. 1168c2ecf20Sopenharmony_ci This function will search the list of thermal zones described in 1178c2ecf20Sopenharmony_ci device tree and look for the zone that refer to the sensor device 1188c2ecf20Sopenharmony_ci pointed by dev->of_node as temperature providers. For the zone 1198c2ecf20Sopenharmony_ci pointing to the sensor node, the sensor will be added to the DT 1208c2ecf20Sopenharmony_ci thermal zone device. 1218c2ecf20Sopenharmony_ci 1228c2ecf20Sopenharmony_ci The parameters for this interface are: 1238c2ecf20Sopenharmony_ci 1248c2ecf20Sopenharmony_ci dev: 1258c2ecf20Sopenharmony_ci Device node of sensor containing valid node pointer in 1268c2ecf20Sopenharmony_ci dev->of_node. 1278c2ecf20Sopenharmony_ci sensor_id: 1288c2ecf20Sopenharmony_ci a sensor identifier, in case the sensor IP has more 1298c2ecf20Sopenharmony_ci than one sensors 1308c2ecf20Sopenharmony_ci data: 1318c2ecf20Sopenharmony_ci a private pointer (owned by the caller) that will be 1328c2ecf20Sopenharmony_ci passed back, when a temperature reading is needed. 1338c2ecf20Sopenharmony_ci ops: 1348c2ecf20Sopenharmony_ci `struct thermal_zone_of_device_ops *`. 1358c2ecf20Sopenharmony_ci 1368c2ecf20Sopenharmony_ci ============== ======================================= 1378c2ecf20Sopenharmony_ci get_temp a pointer to a function that reads the 1388c2ecf20Sopenharmony_ci sensor temperature. This is mandatory 1398c2ecf20Sopenharmony_ci callback provided by sensor driver. 1408c2ecf20Sopenharmony_ci set_trips a pointer to a function that sets a 1418c2ecf20Sopenharmony_ci temperature window. When this window is 1428c2ecf20Sopenharmony_ci left the driver must inform the thermal 1438c2ecf20Sopenharmony_ci core via thermal_zone_device_update. 1448c2ecf20Sopenharmony_ci get_trend a pointer to a function that reads the 1458c2ecf20Sopenharmony_ci sensor temperature trend. 1468c2ecf20Sopenharmony_ci set_emul_temp a pointer to a function that sets 1478c2ecf20Sopenharmony_ci sensor emulated temperature. 1488c2ecf20Sopenharmony_ci ============== ======================================= 1498c2ecf20Sopenharmony_ci 1508c2ecf20Sopenharmony_ci The thermal zone temperature is provided by the get_temp() function 1518c2ecf20Sopenharmony_ci pointer of thermal_zone_of_device_ops. When called, it will 1528c2ecf20Sopenharmony_ci have the private pointer @data back. 1538c2ecf20Sopenharmony_ci 1548c2ecf20Sopenharmony_ci It returns error pointer if fails otherwise valid thermal zone device 1558c2ecf20Sopenharmony_ci handle. Caller should check the return handle with IS_ERR() for finding 1568c2ecf20Sopenharmony_ci whether success or not. 1578c2ecf20Sopenharmony_ci 1588c2ecf20Sopenharmony_ci :: 1598c2ecf20Sopenharmony_ci 1608c2ecf20Sopenharmony_ci void thermal_zone_of_sensor_unregister(struct device *dev, 1618c2ecf20Sopenharmony_ci struct thermal_zone_device *tzd) 1628c2ecf20Sopenharmony_ci 1638c2ecf20Sopenharmony_ci This interface unregisters a sensor from a DT thermal zone which was 1648c2ecf20Sopenharmony_ci successfully added by interface thermal_zone_of_sensor_register(). 1658c2ecf20Sopenharmony_ci This function removes the sensor callbacks and private data from the 1668c2ecf20Sopenharmony_ci thermal zone device registered with thermal_zone_of_sensor_register() 1678c2ecf20Sopenharmony_ci interface. It will also silent the zone by remove the .get_temp() and 1688c2ecf20Sopenharmony_ci get_trend() thermal zone device callbacks. 1698c2ecf20Sopenharmony_ci 1708c2ecf20Sopenharmony_ci :: 1718c2ecf20Sopenharmony_ci 1728c2ecf20Sopenharmony_ci struct thermal_zone_device 1738c2ecf20Sopenharmony_ci *devm_thermal_zone_of_sensor_register(struct device *dev, 1748c2ecf20Sopenharmony_ci int sensor_id, 1758c2ecf20Sopenharmony_ci void *data, 1768c2ecf20Sopenharmony_ci const struct thermal_zone_of_device_ops *ops) 1778c2ecf20Sopenharmony_ci 1788c2ecf20Sopenharmony_ci This interface is resource managed version of 1798c2ecf20Sopenharmony_ci thermal_zone_of_sensor_register(). 1808c2ecf20Sopenharmony_ci 1818c2ecf20Sopenharmony_ci All details of thermal_zone_of_sensor_register() described in 1828c2ecf20Sopenharmony_ci section 1.1.3 is applicable here. 1838c2ecf20Sopenharmony_ci 1848c2ecf20Sopenharmony_ci The benefit of using this interface to register sensor is that it 1858c2ecf20Sopenharmony_ci is not require to explicitly call thermal_zone_of_sensor_unregister() 1868c2ecf20Sopenharmony_ci in error path or during driver unbinding as this is done by driver 1878c2ecf20Sopenharmony_ci resource manager. 1888c2ecf20Sopenharmony_ci 1898c2ecf20Sopenharmony_ci :: 1908c2ecf20Sopenharmony_ci 1918c2ecf20Sopenharmony_ci void devm_thermal_zone_of_sensor_unregister(struct device *dev, 1928c2ecf20Sopenharmony_ci struct thermal_zone_device *tzd) 1938c2ecf20Sopenharmony_ci 1948c2ecf20Sopenharmony_ci This interface is resource managed version of 1958c2ecf20Sopenharmony_ci thermal_zone_of_sensor_unregister(). 1968c2ecf20Sopenharmony_ci All details of thermal_zone_of_sensor_unregister() described in 1978c2ecf20Sopenharmony_ci section 1.1.4 is applicable here. 1988c2ecf20Sopenharmony_ci Normally this function will not need to be called and the resource 1998c2ecf20Sopenharmony_ci management code will ensure that the resource is freed. 2008c2ecf20Sopenharmony_ci 2018c2ecf20Sopenharmony_ci :: 2028c2ecf20Sopenharmony_ci 2038c2ecf20Sopenharmony_ci int thermal_zone_get_slope(struct thermal_zone_device *tz) 2048c2ecf20Sopenharmony_ci 2058c2ecf20Sopenharmony_ci This interface is used to read the slope attribute value 2068c2ecf20Sopenharmony_ci for the thermal zone device, which might be useful for platform 2078c2ecf20Sopenharmony_ci drivers for temperature calculations. 2088c2ecf20Sopenharmony_ci 2098c2ecf20Sopenharmony_ci :: 2108c2ecf20Sopenharmony_ci 2118c2ecf20Sopenharmony_ci int thermal_zone_get_offset(struct thermal_zone_device *tz) 2128c2ecf20Sopenharmony_ci 2138c2ecf20Sopenharmony_ci This interface is used to read the offset attribute value 2148c2ecf20Sopenharmony_ci for the thermal zone device, which might be useful for platform 2158c2ecf20Sopenharmony_ci drivers for temperature calculations. 2168c2ecf20Sopenharmony_ci 2178c2ecf20Sopenharmony_ci1.2 thermal cooling device interface 2188c2ecf20Sopenharmony_ci------------------------------------ 2198c2ecf20Sopenharmony_ci 2208c2ecf20Sopenharmony_ci 2218c2ecf20Sopenharmony_ci :: 2228c2ecf20Sopenharmony_ci 2238c2ecf20Sopenharmony_ci struct thermal_cooling_device 2248c2ecf20Sopenharmony_ci *thermal_cooling_device_register(char *name, 2258c2ecf20Sopenharmony_ci void *devdata, struct thermal_cooling_device_ops *) 2268c2ecf20Sopenharmony_ci 2278c2ecf20Sopenharmony_ci This interface function adds a new thermal cooling device (fan/processor/...) 2288c2ecf20Sopenharmony_ci to /sys/class/thermal/ folder as `cooling_device[0-*]`. It tries to bind itself 2298c2ecf20Sopenharmony_ci to all the thermal zone devices registered at the same time. 2308c2ecf20Sopenharmony_ci 2318c2ecf20Sopenharmony_ci name: 2328c2ecf20Sopenharmony_ci the cooling device name. 2338c2ecf20Sopenharmony_ci devdata: 2348c2ecf20Sopenharmony_ci device private data. 2358c2ecf20Sopenharmony_ci ops: 2368c2ecf20Sopenharmony_ci thermal cooling devices call-backs. 2378c2ecf20Sopenharmony_ci 2388c2ecf20Sopenharmony_ci .get_max_state: 2398c2ecf20Sopenharmony_ci get the Maximum throttle state of the cooling device. 2408c2ecf20Sopenharmony_ci .get_cur_state: 2418c2ecf20Sopenharmony_ci get the Currently requested throttle state of the 2428c2ecf20Sopenharmony_ci cooling device. 2438c2ecf20Sopenharmony_ci .set_cur_state: 2448c2ecf20Sopenharmony_ci set the Current throttle state of the cooling device. 2458c2ecf20Sopenharmony_ci 2468c2ecf20Sopenharmony_ci :: 2478c2ecf20Sopenharmony_ci 2488c2ecf20Sopenharmony_ci void thermal_cooling_device_unregister(struct thermal_cooling_device *cdev) 2498c2ecf20Sopenharmony_ci 2508c2ecf20Sopenharmony_ci This interface function removes the thermal cooling device. 2518c2ecf20Sopenharmony_ci It deletes the corresponding entry from /sys/class/thermal folder and 2528c2ecf20Sopenharmony_ci unbinds itself from all the thermal zone devices using it. 2538c2ecf20Sopenharmony_ci 2548c2ecf20Sopenharmony_ci1.3 interface for binding a thermal zone device with a thermal cooling device 2558c2ecf20Sopenharmony_ci----------------------------------------------------------------------------- 2568c2ecf20Sopenharmony_ci 2578c2ecf20Sopenharmony_ci :: 2588c2ecf20Sopenharmony_ci 2598c2ecf20Sopenharmony_ci int thermal_zone_bind_cooling_device(struct thermal_zone_device *tz, 2608c2ecf20Sopenharmony_ci int trip, struct thermal_cooling_device *cdev, 2618c2ecf20Sopenharmony_ci unsigned long upper, unsigned long lower, unsigned int weight); 2628c2ecf20Sopenharmony_ci 2638c2ecf20Sopenharmony_ci This interface function binds a thermal cooling device to a particular trip 2648c2ecf20Sopenharmony_ci point of a thermal zone device. 2658c2ecf20Sopenharmony_ci 2668c2ecf20Sopenharmony_ci This function is usually called in the thermal zone device .bind callback. 2678c2ecf20Sopenharmony_ci 2688c2ecf20Sopenharmony_ci tz: 2698c2ecf20Sopenharmony_ci the thermal zone device 2708c2ecf20Sopenharmony_ci cdev: 2718c2ecf20Sopenharmony_ci thermal cooling device 2728c2ecf20Sopenharmony_ci trip: 2738c2ecf20Sopenharmony_ci indicates which trip point in this thermal zone the cooling device 2748c2ecf20Sopenharmony_ci is associated with. 2758c2ecf20Sopenharmony_ci upper: 2768c2ecf20Sopenharmony_ci the Maximum cooling state for this trip point. 2778c2ecf20Sopenharmony_ci THERMAL_NO_LIMIT means no upper limit, 2788c2ecf20Sopenharmony_ci and the cooling device can be in max_state. 2798c2ecf20Sopenharmony_ci lower: 2808c2ecf20Sopenharmony_ci the Minimum cooling state can be used for this trip point. 2818c2ecf20Sopenharmony_ci THERMAL_NO_LIMIT means no lower limit, 2828c2ecf20Sopenharmony_ci and the cooling device can be in cooling state 0. 2838c2ecf20Sopenharmony_ci weight: 2848c2ecf20Sopenharmony_ci the influence of this cooling device in this thermal 2858c2ecf20Sopenharmony_ci zone. See 1.4.1 below for more information. 2868c2ecf20Sopenharmony_ci 2878c2ecf20Sopenharmony_ci :: 2888c2ecf20Sopenharmony_ci 2898c2ecf20Sopenharmony_ci int thermal_zone_unbind_cooling_device(struct thermal_zone_device *tz, 2908c2ecf20Sopenharmony_ci int trip, struct thermal_cooling_device *cdev); 2918c2ecf20Sopenharmony_ci 2928c2ecf20Sopenharmony_ci This interface function unbinds a thermal cooling device from a particular 2938c2ecf20Sopenharmony_ci trip point of a thermal zone device. This function is usually called in 2948c2ecf20Sopenharmony_ci the thermal zone device .unbind callback. 2958c2ecf20Sopenharmony_ci 2968c2ecf20Sopenharmony_ci tz: 2978c2ecf20Sopenharmony_ci the thermal zone device 2988c2ecf20Sopenharmony_ci cdev: 2998c2ecf20Sopenharmony_ci thermal cooling device 3008c2ecf20Sopenharmony_ci trip: 3018c2ecf20Sopenharmony_ci indicates which trip point in this thermal zone the cooling device 3028c2ecf20Sopenharmony_ci is associated with. 3038c2ecf20Sopenharmony_ci 3048c2ecf20Sopenharmony_ci1.4 Thermal Zone Parameters 3058c2ecf20Sopenharmony_ci--------------------------- 3068c2ecf20Sopenharmony_ci 3078c2ecf20Sopenharmony_ci :: 3088c2ecf20Sopenharmony_ci 3098c2ecf20Sopenharmony_ci struct thermal_bind_params 3108c2ecf20Sopenharmony_ci 3118c2ecf20Sopenharmony_ci This structure defines the following parameters that are used to bind 3128c2ecf20Sopenharmony_ci a zone with a cooling device for a particular trip point. 3138c2ecf20Sopenharmony_ci 3148c2ecf20Sopenharmony_ci .cdev: 3158c2ecf20Sopenharmony_ci The cooling device pointer 3168c2ecf20Sopenharmony_ci .weight: 3178c2ecf20Sopenharmony_ci The 'influence' of a particular cooling device on this 3188c2ecf20Sopenharmony_ci zone. This is relative to the rest of the cooling 3198c2ecf20Sopenharmony_ci devices. For example, if all cooling devices have a 3208c2ecf20Sopenharmony_ci weight of 1, then they all contribute the same. You can 3218c2ecf20Sopenharmony_ci use percentages if you want, but it's not mandatory. A 3228c2ecf20Sopenharmony_ci weight of 0 means that this cooling device doesn't 3238c2ecf20Sopenharmony_ci contribute to the cooling of this zone unless all cooling 3248c2ecf20Sopenharmony_ci devices have a weight of 0. If all weights are 0, then 3258c2ecf20Sopenharmony_ci they all contribute the same. 3268c2ecf20Sopenharmony_ci .trip_mask: 3278c2ecf20Sopenharmony_ci This is a bit mask that gives the binding relation between 3288c2ecf20Sopenharmony_ci this thermal zone and cdev, for a particular trip point. 3298c2ecf20Sopenharmony_ci If nth bit is set, then the cdev and thermal zone are bound 3308c2ecf20Sopenharmony_ci for trip point n. 3318c2ecf20Sopenharmony_ci .binding_limits: 3328c2ecf20Sopenharmony_ci This is an array of cooling state limits. Must have 3338c2ecf20Sopenharmony_ci exactly 2 * thermal_zone.number_of_trip_points. It is an 3348c2ecf20Sopenharmony_ci array consisting of tuples <lower-state upper-state> of 3358c2ecf20Sopenharmony_ci state limits. Each trip will be associated with one state 3368c2ecf20Sopenharmony_ci limit tuple when binding. A NULL pointer means 3378c2ecf20Sopenharmony_ci <THERMAL_NO_LIMITS THERMAL_NO_LIMITS> on all trips. 3388c2ecf20Sopenharmony_ci These limits are used when binding a cdev to a trip point. 3398c2ecf20Sopenharmony_ci .match: 3408c2ecf20Sopenharmony_ci This call back returns success(0) if the 'tz and cdev' need to 3418c2ecf20Sopenharmony_ci be bound, as per platform data. 3428c2ecf20Sopenharmony_ci 3438c2ecf20Sopenharmony_ci :: 3448c2ecf20Sopenharmony_ci 3458c2ecf20Sopenharmony_ci struct thermal_zone_params 3468c2ecf20Sopenharmony_ci 3478c2ecf20Sopenharmony_ci This structure defines the platform level parameters for a thermal zone. 3488c2ecf20Sopenharmony_ci This data, for each thermal zone should come from the platform layer. 3498c2ecf20Sopenharmony_ci This is an optional feature where some platforms can choose not to 3508c2ecf20Sopenharmony_ci provide this data. 3518c2ecf20Sopenharmony_ci 3528c2ecf20Sopenharmony_ci .governor_name: 3538c2ecf20Sopenharmony_ci Name of the thermal governor used for this zone 3548c2ecf20Sopenharmony_ci .no_hwmon: 3558c2ecf20Sopenharmony_ci a boolean to indicate if the thermal to hwmon sysfs interface 3568c2ecf20Sopenharmony_ci is required. when no_hwmon == false, a hwmon sysfs interface 3578c2ecf20Sopenharmony_ci will be created. when no_hwmon == true, nothing will be done. 3588c2ecf20Sopenharmony_ci In case the thermal_zone_params is NULL, the hwmon interface 3598c2ecf20Sopenharmony_ci will be created (for backward compatibility). 3608c2ecf20Sopenharmony_ci .num_tbps: 3618c2ecf20Sopenharmony_ci Number of thermal_bind_params entries for this zone 3628c2ecf20Sopenharmony_ci .tbp: 3638c2ecf20Sopenharmony_ci thermal_bind_params entries 3648c2ecf20Sopenharmony_ci 3658c2ecf20Sopenharmony_ci2. sysfs attributes structure 3668c2ecf20Sopenharmony_ci============================= 3678c2ecf20Sopenharmony_ci 3688c2ecf20Sopenharmony_ci== ================ 3698c2ecf20Sopenharmony_ciRO read only value 3708c2ecf20Sopenharmony_ciWO write only value 3718c2ecf20Sopenharmony_ciRW read/write value 3728c2ecf20Sopenharmony_ci== ================ 3738c2ecf20Sopenharmony_ci 3748c2ecf20Sopenharmony_ciThermal sysfs attributes will be represented under /sys/class/thermal. 3758c2ecf20Sopenharmony_ciHwmon sysfs I/F extension is also available under /sys/class/hwmon 3768c2ecf20Sopenharmony_ciif hwmon is compiled in or built as a module. 3778c2ecf20Sopenharmony_ci 3788c2ecf20Sopenharmony_ciThermal zone device sys I/F, created once it's registered:: 3798c2ecf20Sopenharmony_ci 3808c2ecf20Sopenharmony_ci /sys/class/thermal/thermal_zone[0-*]: 3818c2ecf20Sopenharmony_ci |---type: Type of the thermal zone 3828c2ecf20Sopenharmony_ci |---temp: Current temperature 3838c2ecf20Sopenharmony_ci |---mode: Working mode of the thermal zone 3848c2ecf20Sopenharmony_ci |---policy: Thermal governor used for this zone 3858c2ecf20Sopenharmony_ci |---available_policies: Available thermal governors for this zone 3868c2ecf20Sopenharmony_ci |---trip_point_[0-*]_temp: Trip point temperature 3878c2ecf20Sopenharmony_ci |---trip_point_[0-*]_type: Trip point type 3888c2ecf20Sopenharmony_ci |---trip_point_[0-*]_hyst: Hysteresis value for this trip point 3898c2ecf20Sopenharmony_ci |---emul_temp: Emulated temperature set node 3908c2ecf20Sopenharmony_ci |---sustainable_power: Sustainable dissipatable power 3918c2ecf20Sopenharmony_ci |---k_po: Proportional term during temperature overshoot 3928c2ecf20Sopenharmony_ci |---k_pu: Proportional term during temperature undershoot 3938c2ecf20Sopenharmony_ci |---k_i: PID's integral term in the power allocator gov 3948c2ecf20Sopenharmony_ci |---k_d: PID's derivative term in the power allocator 3958c2ecf20Sopenharmony_ci |---integral_cutoff: Offset above which errors are accumulated 3968c2ecf20Sopenharmony_ci |---slope: Slope constant applied as linear extrapolation 3978c2ecf20Sopenharmony_ci |---offset: Offset constant applied as linear extrapolation 3988c2ecf20Sopenharmony_ci 3998c2ecf20Sopenharmony_ciThermal cooling device sys I/F, created once it's registered:: 4008c2ecf20Sopenharmony_ci 4018c2ecf20Sopenharmony_ci /sys/class/thermal/cooling_device[0-*]: 4028c2ecf20Sopenharmony_ci |---type: Type of the cooling device(processor/fan/...) 4038c2ecf20Sopenharmony_ci |---max_state: Maximum cooling state of the cooling device 4048c2ecf20Sopenharmony_ci |---cur_state: Current cooling state of the cooling device 4058c2ecf20Sopenharmony_ci |---stats: Directory containing cooling device's statistics 4068c2ecf20Sopenharmony_ci |---stats/reset: Writing any value resets the statistics 4078c2ecf20Sopenharmony_ci |---stats/time_in_state_ms: Time (msec) spent in various cooling states 4088c2ecf20Sopenharmony_ci |---stats/total_trans: Total number of times cooling state is changed 4098c2ecf20Sopenharmony_ci |---stats/trans_table: Cooing state transition table 4108c2ecf20Sopenharmony_ci 4118c2ecf20Sopenharmony_ci 4128c2ecf20Sopenharmony_ciThen next two dynamic attributes are created/removed in pairs. They represent 4138c2ecf20Sopenharmony_cithe relationship between a thermal zone and its associated cooling device. 4148c2ecf20Sopenharmony_ciThey are created/removed for each successful execution of 4158c2ecf20Sopenharmony_cithermal_zone_bind_cooling_device/thermal_zone_unbind_cooling_device. 4168c2ecf20Sopenharmony_ci 4178c2ecf20Sopenharmony_ci:: 4188c2ecf20Sopenharmony_ci 4198c2ecf20Sopenharmony_ci /sys/class/thermal/thermal_zone[0-*]: 4208c2ecf20Sopenharmony_ci |---cdev[0-*]: [0-*]th cooling device in current thermal zone 4218c2ecf20Sopenharmony_ci |---cdev[0-*]_trip_point: Trip point that cdev[0-*] is associated with 4228c2ecf20Sopenharmony_ci |---cdev[0-*]_weight: Influence of the cooling device in 4238c2ecf20Sopenharmony_ci this thermal zone 4248c2ecf20Sopenharmony_ci 4258c2ecf20Sopenharmony_ciBesides the thermal zone device sysfs I/F and cooling device sysfs I/F, 4268c2ecf20Sopenharmony_cithe generic thermal driver also creates a hwmon sysfs I/F for each _type_ 4278c2ecf20Sopenharmony_ciof thermal zone device. E.g. the generic thermal driver registers one hwmon 4288c2ecf20Sopenharmony_ciclass device and build the associated hwmon sysfs I/F for all the registered 4298c2ecf20Sopenharmony_ciACPI thermal zones. 4308c2ecf20Sopenharmony_ci 4318c2ecf20Sopenharmony_ci:: 4328c2ecf20Sopenharmony_ci 4338c2ecf20Sopenharmony_ci /sys/class/hwmon/hwmon[0-*]: 4348c2ecf20Sopenharmony_ci |---name: The type of the thermal zone devices 4358c2ecf20Sopenharmony_ci |---temp[1-*]_input: The current temperature of thermal zone [1-*] 4368c2ecf20Sopenharmony_ci |---temp[1-*]_critical: The critical trip point of thermal zone [1-*] 4378c2ecf20Sopenharmony_ci 4388c2ecf20Sopenharmony_ciPlease read Documentation/hwmon/sysfs-interface.rst for additional information. 4398c2ecf20Sopenharmony_ci 4408c2ecf20Sopenharmony_ciThermal zone attributes 4418c2ecf20Sopenharmony_ci----------------------- 4428c2ecf20Sopenharmony_ci 4438c2ecf20Sopenharmony_citype 4448c2ecf20Sopenharmony_ci Strings which represent the thermal zone type. 4458c2ecf20Sopenharmony_ci This is given by thermal zone driver as part of registration. 4468c2ecf20Sopenharmony_ci E.g: "acpitz" indicates it's an ACPI thermal device. 4478c2ecf20Sopenharmony_ci In order to keep it consistent with hwmon sys attribute; this should 4488c2ecf20Sopenharmony_ci be a short, lowercase string, not containing spaces nor dashes. 4498c2ecf20Sopenharmony_ci RO, Required 4508c2ecf20Sopenharmony_ci 4518c2ecf20Sopenharmony_citemp 4528c2ecf20Sopenharmony_ci Current temperature as reported by thermal zone (sensor). 4538c2ecf20Sopenharmony_ci Unit: millidegree Celsius 4548c2ecf20Sopenharmony_ci RO, Required 4558c2ecf20Sopenharmony_ci 4568c2ecf20Sopenharmony_cimode 4578c2ecf20Sopenharmony_ci One of the predefined values in [enabled, disabled]. 4588c2ecf20Sopenharmony_ci This file gives information about the algorithm that is currently 4598c2ecf20Sopenharmony_ci managing the thermal zone. It can be either default kernel based 4608c2ecf20Sopenharmony_ci algorithm or user space application. 4618c2ecf20Sopenharmony_ci 4628c2ecf20Sopenharmony_ci enabled 4638c2ecf20Sopenharmony_ci enable Kernel Thermal management. 4648c2ecf20Sopenharmony_ci disabled 4658c2ecf20Sopenharmony_ci Preventing kernel thermal zone driver actions upon 4668c2ecf20Sopenharmony_ci trip points so that user application can take full 4678c2ecf20Sopenharmony_ci charge of the thermal management. 4688c2ecf20Sopenharmony_ci 4698c2ecf20Sopenharmony_ci RW, Optional 4708c2ecf20Sopenharmony_ci 4718c2ecf20Sopenharmony_cipolicy 4728c2ecf20Sopenharmony_ci One of the various thermal governors used for a particular zone. 4738c2ecf20Sopenharmony_ci 4748c2ecf20Sopenharmony_ci RW, Required 4758c2ecf20Sopenharmony_ci 4768c2ecf20Sopenharmony_ciavailable_policies 4778c2ecf20Sopenharmony_ci Available thermal governors which can be used for a particular zone. 4788c2ecf20Sopenharmony_ci 4798c2ecf20Sopenharmony_ci RO, Required 4808c2ecf20Sopenharmony_ci 4818c2ecf20Sopenharmony_ci`trip_point_[0-*]_temp` 4828c2ecf20Sopenharmony_ci The temperature above which trip point will be fired. 4838c2ecf20Sopenharmony_ci 4848c2ecf20Sopenharmony_ci Unit: millidegree Celsius 4858c2ecf20Sopenharmony_ci 4868c2ecf20Sopenharmony_ci RO, Optional 4878c2ecf20Sopenharmony_ci 4888c2ecf20Sopenharmony_ci`trip_point_[0-*]_type` 4898c2ecf20Sopenharmony_ci Strings which indicate the type of the trip point. 4908c2ecf20Sopenharmony_ci 4918c2ecf20Sopenharmony_ci E.g. it can be one of critical, hot, passive, `active[0-*]` for ACPI 4928c2ecf20Sopenharmony_ci thermal zone. 4938c2ecf20Sopenharmony_ci 4948c2ecf20Sopenharmony_ci RO, Optional 4958c2ecf20Sopenharmony_ci 4968c2ecf20Sopenharmony_ci`trip_point_[0-*]_hyst` 4978c2ecf20Sopenharmony_ci The hysteresis value for a trip point, represented as an integer 4988c2ecf20Sopenharmony_ci Unit: Celsius 4998c2ecf20Sopenharmony_ci RW, Optional 5008c2ecf20Sopenharmony_ci 5018c2ecf20Sopenharmony_ci`cdev[0-*]` 5028c2ecf20Sopenharmony_ci Sysfs link to the thermal cooling device node where the sys I/F 5038c2ecf20Sopenharmony_ci for cooling device throttling control represents. 5048c2ecf20Sopenharmony_ci 5058c2ecf20Sopenharmony_ci RO, Optional 5068c2ecf20Sopenharmony_ci 5078c2ecf20Sopenharmony_ci`cdev[0-*]_trip_point` 5088c2ecf20Sopenharmony_ci The trip point in this thermal zone which `cdev[0-*]` is associated 5098c2ecf20Sopenharmony_ci with; -1 means the cooling device is not associated with any trip 5108c2ecf20Sopenharmony_ci point. 5118c2ecf20Sopenharmony_ci 5128c2ecf20Sopenharmony_ci RO, Optional 5138c2ecf20Sopenharmony_ci 5148c2ecf20Sopenharmony_ci`cdev[0-*]_weight` 5158c2ecf20Sopenharmony_ci The influence of `cdev[0-*]` in this thermal zone. This value 5168c2ecf20Sopenharmony_ci is relative to the rest of cooling devices in the thermal 5178c2ecf20Sopenharmony_ci zone. For example, if a cooling device has a weight double 5188c2ecf20Sopenharmony_ci than that of other, it's twice as effective in cooling the 5198c2ecf20Sopenharmony_ci thermal zone. 5208c2ecf20Sopenharmony_ci 5218c2ecf20Sopenharmony_ci RW, Optional 5228c2ecf20Sopenharmony_ci 5238c2ecf20Sopenharmony_cipassive 5248c2ecf20Sopenharmony_ci Attribute is only present for zones in which the passive cooling 5258c2ecf20Sopenharmony_ci policy is not supported by native thermal driver. Default is zero 5268c2ecf20Sopenharmony_ci and can be set to a temperature (in millidegrees) to enable a 5278c2ecf20Sopenharmony_ci passive trip point for the zone. Activation is done by polling with 5288c2ecf20Sopenharmony_ci an interval of 1 second. 5298c2ecf20Sopenharmony_ci 5308c2ecf20Sopenharmony_ci Unit: millidegrees Celsius 5318c2ecf20Sopenharmony_ci 5328c2ecf20Sopenharmony_ci Valid values: 0 (disabled) or greater than 1000 5338c2ecf20Sopenharmony_ci 5348c2ecf20Sopenharmony_ci RW, Optional 5358c2ecf20Sopenharmony_ci 5368c2ecf20Sopenharmony_ciemul_temp 5378c2ecf20Sopenharmony_ci Interface to set the emulated temperature method in thermal zone 5388c2ecf20Sopenharmony_ci (sensor). After setting this temperature, the thermal zone may pass 5398c2ecf20Sopenharmony_ci this temperature to platform emulation function if registered or 5408c2ecf20Sopenharmony_ci cache it locally. This is useful in debugging different temperature 5418c2ecf20Sopenharmony_ci threshold and its associated cooling action. This is write only node 5428c2ecf20Sopenharmony_ci and writing 0 on this node should disable emulation. 5438c2ecf20Sopenharmony_ci Unit: millidegree Celsius 5448c2ecf20Sopenharmony_ci 5458c2ecf20Sopenharmony_ci WO, Optional 5468c2ecf20Sopenharmony_ci 5478c2ecf20Sopenharmony_ci WARNING: 5488c2ecf20Sopenharmony_ci Be careful while enabling this option on production systems, 5498c2ecf20Sopenharmony_ci because userland can easily disable the thermal policy by simply 5508c2ecf20Sopenharmony_ci flooding this sysfs node with low temperature values. 5518c2ecf20Sopenharmony_ci 5528c2ecf20Sopenharmony_cisustainable_power 5538c2ecf20Sopenharmony_ci An estimate of the sustained power that can be dissipated by 5548c2ecf20Sopenharmony_ci the thermal zone. Used by the power allocator governor. For 5558c2ecf20Sopenharmony_ci more information see Documentation/driver-api/thermal/power_allocator.rst 5568c2ecf20Sopenharmony_ci 5578c2ecf20Sopenharmony_ci Unit: milliwatts 5588c2ecf20Sopenharmony_ci 5598c2ecf20Sopenharmony_ci RW, Optional 5608c2ecf20Sopenharmony_ci 5618c2ecf20Sopenharmony_cik_po 5628c2ecf20Sopenharmony_ci The proportional term of the power allocator governor's PID 5638c2ecf20Sopenharmony_ci controller during temperature overshoot. Temperature overshoot 5648c2ecf20Sopenharmony_ci is when the current temperature is above the "desired 5658c2ecf20Sopenharmony_ci temperature" trip point. For more information see 5668c2ecf20Sopenharmony_ci Documentation/driver-api/thermal/power_allocator.rst 5678c2ecf20Sopenharmony_ci 5688c2ecf20Sopenharmony_ci RW, Optional 5698c2ecf20Sopenharmony_ci 5708c2ecf20Sopenharmony_cik_pu 5718c2ecf20Sopenharmony_ci The proportional term of the power allocator governor's PID 5728c2ecf20Sopenharmony_ci controller during temperature undershoot. Temperature undershoot 5738c2ecf20Sopenharmony_ci is when the current temperature is below the "desired 5748c2ecf20Sopenharmony_ci temperature" trip point. For more information see 5758c2ecf20Sopenharmony_ci Documentation/driver-api/thermal/power_allocator.rst 5768c2ecf20Sopenharmony_ci 5778c2ecf20Sopenharmony_ci RW, Optional 5788c2ecf20Sopenharmony_ci 5798c2ecf20Sopenharmony_cik_i 5808c2ecf20Sopenharmony_ci The integral term of the power allocator governor's PID 5818c2ecf20Sopenharmony_ci controller. This term allows the PID controller to compensate 5828c2ecf20Sopenharmony_ci for long term drift. For more information see 5838c2ecf20Sopenharmony_ci Documentation/driver-api/thermal/power_allocator.rst 5848c2ecf20Sopenharmony_ci 5858c2ecf20Sopenharmony_ci RW, Optional 5868c2ecf20Sopenharmony_ci 5878c2ecf20Sopenharmony_cik_d 5888c2ecf20Sopenharmony_ci The derivative term of the power allocator governor's PID 5898c2ecf20Sopenharmony_ci controller. For more information see 5908c2ecf20Sopenharmony_ci Documentation/driver-api/thermal/power_allocator.rst 5918c2ecf20Sopenharmony_ci 5928c2ecf20Sopenharmony_ci RW, Optional 5938c2ecf20Sopenharmony_ci 5948c2ecf20Sopenharmony_ciintegral_cutoff 5958c2ecf20Sopenharmony_ci Temperature offset from the desired temperature trip point 5968c2ecf20Sopenharmony_ci above which the integral term of the power allocator 5978c2ecf20Sopenharmony_ci governor's PID controller starts accumulating errors. For 5988c2ecf20Sopenharmony_ci example, if integral_cutoff is 0, then the integral term only 5998c2ecf20Sopenharmony_ci accumulates error when temperature is above the desired 6008c2ecf20Sopenharmony_ci temperature trip point. For more information see 6018c2ecf20Sopenharmony_ci Documentation/driver-api/thermal/power_allocator.rst 6028c2ecf20Sopenharmony_ci 6038c2ecf20Sopenharmony_ci Unit: millidegree Celsius 6048c2ecf20Sopenharmony_ci 6058c2ecf20Sopenharmony_ci RW, Optional 6068c2ecf20Sopenharmony_ci 6078c2ecf20Sopenharmony_cislope 6088c2ecf20Sopenharmony_ci The slope constant used in a linear extrapolation model 6098c2ecf20Sopenharmony_ci to determine a hotspot temperature based off the sensor's 6108c2ecf20Sopenharmony_ci raw readings. It is up to the device driver to determine 6118c2ecf20Sopenharmony_ci the usage of these values. 6128c2ecf20Sopenharmony_ci 6138c2ecf20Sopenharmony_ci RW, Optional 6148c2ecf20Sopenharmony_ci 6158c2ecf20Sopenharmony_cioffset 6168c2ecf20Sopenharmony_ci The offset constant used in a linear extrapolation model 6178c2ecf20Sopenharmony_ci to determine a hotspot temperature based off the sensor's 6188c2ecf20Sopenharmony_ci raw readings. It is up to the device driver to determine 6198c2ecf20Sopenharmony_ci the usage of these values. 6208c2ecf20Sopenharmony_ci 6218c2ecf20Sopenharmony_ci RW, Optional 6228c2ecf20Sopenharmony_ci 6238c2ecf20Sopenharmony_ciCooling device attributes 6248c2ecf20Sopenharmony_ci------------------------- 6258c2ecf20Sopenharmony_ci 6268c2ecf20Sopenharmony_citype 6278c2ecf20Sopenharmony_ci String which represents the type of device, e.g: 6288c2ecf20Sopenharmony_ci 6298c2ecf20Sopenharmony_ci - for generic ACPI: should be "Fan", "Processor" or "LCD" 6308c2ecf20Sopenharmony_ci - for memory controller device on intel_menlow platform: 6318c2ecf20Sopenharmony_ci should be "Memory controller". 6328c2ecf20Sopenharmony_ci 6338c2ecf20Sopenharmony_ci RO, Required 6348c2ecf20Sopenharmony_ci 6358c2ecf20Sopenharmony_cimax_state 6368c2ecf20Sopenharmony_ci The maximum permissible cooling state of this cooling device. 6378c2ecf20Sopenharmony_ci 6388c2ecf20Sopenharmony_ci RO, Required 6398c2ecf20Sopenharmony_ci 6408c2ecf20Sopenharmony_cicur_state 6418c2ecf20Sopenharmony_ci The current cooling state of this cooling device. 6428c2ecf20Sopenharmony_ci The value can any integer numbers between 0 and max_state: 6438c2ecf20Sopenharmony_ci 6448c2ecf20Sopenharmony_ci - cur_state == 0 means no cooling 6458c2ecf20Sopenharmony_ci - cur_state == max_state means the maximum cooling. 6468c2ecf20Sopenharmony_ci 6478c2ecf20Sopenharmony_ci RW, Required 6488c2ecf20Sopenharmony_ci 6498c2ecf20Sopenharmony_cistats/reset 6508c2ecf20Sopenharmony_ci Writing any value resets the cooling device's statistics. 6518c2ecf20Sopenharmony_ci WO, Required 6528c2ecf20Sopenharmony_ci 6538c2ecf20Sopenharmony_cistats/time_in_state_ms: 6548c2ecf20Sopenharmony_ci The amount of time spent by the cooling device in various cooling 6558c2ecf20Sopenharmony_ci states. The output will have "<state> <time>" pair in each line, which 6568c2ecf20Sopenharmony_ci will mean this cooling device spent <time> msec of time at <state>. 6578c2ecf20Sopenharmony_ci Output will have one line for each of the supported states. usertime 6588c2ecf20Sopenharmony_ci units here is 10mS (similar to other time exported in /proc). 6598c2ecf20Sopenharmony_ci RO, Required 6608c2ecf20Sopenharmony_ci 6618c2ecf20Sopenharmony_ci 6628c2ecf20Sopenharmony_cistats/total_trans: 6638c2ecf20Sopenharmony_ci A single positive value showing the total number of times the state of a 6648c2ecf20Sopenharmony_ci cooling device is changed. 6658c2ecf20Sopenharmony_ci 6668c2ecf20Sopenharmony_ci RO, Required 6678c2ecf20Sopenharmony_ci 6688c2ecf20Sopenharmony_cistats/trans_table: 6698c2ecf20Sopenharmony_ci This gives fine grained information about all the cooling state 6708c2ecf20Sopenharmony_ci transitions. The cat output here is a two dimensional matrix, where an 6718c2ecf20Sopenharmony_ci entry <i,j> (row i, column j) represents the number of transitions from 6728c2ecf20Sopenharmony_ci State_i to State_j. If the transition table is bigger than PAGE_SIZE, 6738c2ecf20Sopenharmony_ci reading this will return an -EFBIG error. 6748c2ecf20Sopenharmony_ci RO, Required 6758c2ecf20Sopenharmony_ci 6768c2ecf20Sopenharmony_ci3. A simple implementation 6778c2ecf20Sopenharmony_ci========================== 6788c2ecf20Sopenharmony_ci 6798c2ecf20Sopenharmony_ciACPI thermal zone may support multiple trip points like critical, hot, 6808c2ecf20Sopenharmony_cipassive, active. If an ACPI thermal zone supports critical, passive, 6818c2ecf20Sopenharmony_ciactive[0] and active[1] at the same time, it may register itself as a 6828c2ecf20Sopenharmony_cithermal_zone_device (thermal_zone1) with 4 trip points in all. 6838c2ecf20Sopenharmony_ciIt has one processor and one fan, which are both registered as 6848c2ecf20Sopenharmony_cithermal_cooling_device. Both are considered to have the same 6858c2ecf20Sopenharmony_cieffectiveness in cooling the thermal zone. 6868c2ecf20Sopenharmony_ci 6878c2ecf20Sopenharmony_ciIf the processor is listed in _PSL method, and the fan is listed in _AL0 6888c2ecf20Sopenharmony_cimethod, the sys I/F structure will be built like this:: 6898c2ecf20Sopenharmony_ci 6908c2ecf20Sopenharmony_ci /sys/class/thermal: 6918c2ecf20Sopenharmony_ci |thermal_zone1: 6928c2ecf20Sopenharmony_ci |---type: acpitz 6938c2ecf20Sopenharmony_ci |---temp: 37000 6948c2ecf20Sopenharmony_ci |---mode: enabled 6958c2ecf20Sopenharmony_ci |---policy: step_wise 6968c2ecf20Sopenharmony_ci |---available_policies: step_wise fair_share 6978c2ecf20Sopenharmony_ci |---trip_point_0_temp: 100000 6988c2ecf20Sopenharmony_ci |---trip_point_0_type: critical 6998c2ecf20Sopenharmony_ci |---trip_point_1_temp: 80000 7008c2ecf20Sopenharmony_ci |---trip_point_1_type: passive 7018c2ecf20Sopenharmony_ci |---trip_point_2_temp: 70000 7028c2ecf20Sopenharmony_ci |---trip_point_2_type: active0 7038c2ecf20Sopenharmony_ci |---trip_point_3_temp: 60000 7048c2ecf20Sopenharmony_ci |---trip_point_3_type: active1 7058c2ecf20Sopenharmony_ci |---cdev0: --->/sys/class/thermal/cooling_device0 7068c2ecf20Sopenharmony_ci |---cdev0_trip_point: 1 /* cdev0 can be used for passive */ 7078c2ecf20Sopenharmony_ci |---cdev0_weight: 1024 7088c2ecf20Sopenharmony_ci |---cdev1: --->/sys/class/thermal/cooling_device3 7098c2ecf20Sopenharmony_ci |---cdev1_trip_point: 2 /* cdev1 can be used for active[0]*/ 7108c2ecf20Sopenharmony_ci |---cdev1_weight: 1024 7118c2ecf20Sopenharmony_ci 7128c2ecf20Sopenharmony_ci |cooling_device0: 7138c2ecf20Sopenharmony_ci |---type: Processor 7148c2ecf20Sopenharmony_ci |---max_state: 8 7158c2ecf20Sopenharmony_ci |---cur_state: 0 7168c2ecf20Sopenharmony_ci 7178c2ecf20Sopenharmony_ci |cooling_device3: 7188c2ecf20Sopenharmony_ci |---type: Fan 7198c2ecf20Sopenharmony_ci |---max_state: 2 7208c2ecf20Sopenharmony_ci |---cur_state: 0 7218c2ecf20Sopenharmony_ci 7228c2ecf20Sopenharmony_ci /sys/class/hwmon: 7238c2ecf20Sopenharmony_ci |hwmon0: 7248c2ecf20Sopenharmony_ci |---name: acpitz 7258c2ecf20Sopenharmony_ci |---temp1_input: 37000 7268c2ecf20Sopenharmony_ci |---temp1_crit: 100000 7278c2ecf20Sopenharmony_ci 7288c2ecf20Sopenharmony_ci4. Export Symbol APIs 7298c2ecf20Sopenharmony_ci===================== 7308c2ecf20Sopenharmony_ci 7318c2ecf20Sopenharmony_ci4.1. get_tz_trend 7328c2ecf20Sopenharmony_ci----------------- 7338c2ecf20Sopenharmony_ci 7348c2ecf20Sopenharmony_ciThis function returns the trend of a thermal zone, i.e the rate of change 7358c2ecf20Sopenharmony_ciof temperature of the thermal zone. Ideally, the thermal sensor drivers 7368c2ecf20Sopenharmony_ciare supposed to implement the callback. If they don't, the thermal 7378c2ecf20Sopenharmony_ciframework calculated the trend by comparing the previous and the current 7388c2ecf20Sopenharmony_citemperature values. 7398c2ecf20Sopenharmony_ci 7408c2ecf20Sopenharmony_ci4.2. get_thermal_instance 7418c2ecf20Sopenharmony_ci------------------------- 7428c2ecf20Sopenharmony_ci 7438c2ecf20Sopenharmony_ciThis function returns the thermal_instance corresponding to a given 7448c2ecf20Sopenharmony_ci{thermal_zone, cooling_device, trip_point} combination. Returns NULL 7458c2ecf20Sopenharmony_ciif such an instance does not exist. 7468c2ecf20Sopenharmony_ci 7478c2ecf20Sopenharmony_ci4.3. thermal_notify_framework 7488c2ecf20Sopenharmony_ci----------------------------- 7498c2ecf20Sopenharmony_ci 7508c2ecf20Sopenharmony_ciThis function handles the trip events from sensor drivers. It starts 7518c2ecf20Sopenharmony_cithrottling the cooling devices according to the policy configured. 7528c2ecf20Sopenharmony_ciFor CRITICAL and HOT trip points, this notifies the respective drivers, 7538c2ecf20Sopenharmony_ciand does actual throttling for other trip points i.e ACTIVE and PASSIVE. 7548c2ecf20Sopenharmony_ciThe throttling policy is based on the configured platform data; if no 7558c2ecf20Sopenharmony_ciplatform data is provided, this uses the step_wise throttling policy. 7568c2ecf20Sopenharmony_ci 7578c2ecf20Sopenharmony_ci4.4. thermal_cdev_update 7588c2ecf20Sopenharmony_ci------------------------ 7598c2ecf20Sopenharmony_ci 7608c2ecf20Sopenharmony_ciThis function serves as an arbitrator to set the state of a cooling 7618c2ecf20Sopenharmony_cidevice. It sets the cooling device to the deepest cooling state if 7628c2ecf20Sopenharmony_cipossible. 7638c2ecf20Sopenharmony_ci 7648c2ecf20Sopenharmony_ci5. thermal_emergency_poweroff 7658c2ecf20Sopenharmony_ci============================= 7668c2ecf20Sopenharmony_ci 7678c2ecf20Sopenharmony_ciOn an event of critical trip temperature crossing. Thermal framework 7688c2ecf20Sopenharmony_ciallows the system to shutdown gracefully by calling orderly_poweroff(). 7698c2ecf20Sopenharmony_ciIn the event of a failure of orderly_poweroff() to shut down the system 7708c2ecf20Sopenharmony_ciwe are in danger of keeping the system alive at undesirably high 7718c2ecf20Sopenharmony_citemperatures. To mitigate this high risk scenario we program a work 7728c2ecf20Sopenharmony_ciqueue to fire after a pre-determined number of seconds to start 7738c2ecf20Sopenharmony_cian emergency shutdown of the device using the kernel_power_off() 7748c2ecf20Sopenharmony_cifunction. In case kernel_power_off() fails then finally 7758c2ecf20Sopenharmony_ciemergency_restart() is called in the worst case. 7768c2ecf20Sopenharmony_ci 7778c2ecf20Sopenharmony_ciThe delay should be carefully profiled so as to give adequate time for 7788c2ecf20Sopenharmony_ciorderly_poweroff(). In case of failure of an orderly_poweroff() the 7798c2ecf20Sopenharmony_ciemergency poweroff kicks in after the delay has elapsed and shuts down 7808c2ecf20Sopenharmony_cithe system. 7818c2ecf20Sopenharmony_ci 7828c2ecf20Sopenharmony_ciIf set to 0 emergency poweroff will not be supported. So a carefully 7838c2ecf20Sopenharmony_ciprofiled non-zero positive value is a must for emergerncy poweroff to be 7848c2ecf20Sopenharmony_citriggered. 785