sysfs-api.txt 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. Generic Thermal Sysfs driver How To
  2. =========================
  3. Written by Sujith Thomas <sujith.thomas@intel.com>, Zhang Rui <rui.zhang@intel.com>
  4. Updated: 2 January 2008
  5. Copyright (c) 2008 Intel Corporation
  6. 0. Introduction
  7. The generic thermal sysfs provides a set of interfaces for thermal zone devices (sensors)
  8. and thermal cooling devices (fan, processor...) to register with the thermal management
  9. solution and to be a part of it.
  10. This how-to focuses on enabling new thermal zone and cooling devices to participate
  11. in thermal management.
  12. This solution is platform independent and any type of thermal zone devices and
  13. cooling devices should be able to make use of the infrastructure.
  14. The main task of the thermal sysfs driver is to expose thermal zone attributes as well
  15. as cooling device attributes to the user space.
  16. An intelligent thermal management application can make decisions based on inputs
  17. from thermal zone attributes (the current temperature and trip point temperature)
  18. and throttle appropriate devices.
  19. [0-*] denotes any positive number starting from 0
  20. [1-*] denotes any positive number starting from 1
  21. 1. thermal sysfs driver interface functions
  22. 1.1 thermal zone device interface
  23. 1.1.1 struct thermal_zone_device *thermal_zone_device_register(char *name, int trips,
  24. void *devdata, struct thermal_zone_device_ops *ops)
  25. This interface function adds a new thermal zone device (sensor) to
  26. /sys/class/thermal folder as thermal_zone[0-*].
  27. It tries to bind all the thermal cooling devices registered at the same time.
  28. name: the thermal zone name.
  29. trips: the total number of trip points this thermal zone supports.
  30. devdata: device private data
  31. ops: thermal zone device call-backs.
  32. .bind: bind the thermal zone device with a thermal cooling device.
  33. .unbind: unbind the thermal zone device with a thermal cooling device.
  34. .get_temp: get the current temperature of the thermal zone.
  35. .get_mode: get the current mode (user/kernel) of the thermal zone.
  36. "kernel" means thermal management is done in kernel.
  37. "user" will prevent kernel thermal driver actions upon trip points
  38. so that user applications can take charge of thermal management.
  39. .set_mode: set the mode (user/kernel) of the thermal zone.
  40. .get_trip_type: get the type of certain trip point.
  41. .get_trip_temp: get the temperature above which the certain trip point
  42. will be fired.
  43. 1.1.2 void thermal_zone_device_unregister(struct thermal_zone_device *tz)
  44. This interface function removes the thermal zone device.
  45. It deletes the corresponding entry form /sys/class/thermal folder and unbind all
  46. the thermal cooling devices it uses.
  47. 1.2 thermal cooling device interface
  48. 1.2.1 struct thermal_cooling_device *thermal_cooling_device_register(char *name,
  49. void *devdata, struct thermal_cooling_device_ops *)
  50. This interface function adds a new thermal cooling device (fan/processor/...) to
  51. /sys/class/thermal/ folder as cooling_device[0-*].
  52. It tries to bind itself to all the thermal zone devices register at the same time.
  53. name: the cooling device name.
  54. devdata: device private data.
  55. ops: thermal cooling devices call-backs.
  56. .get_max_state: get the Maximum throttle state of the cooling device.
  57. .get_cur_state: get the Current throttle state of the cooling device.
  58. .set_cur_state: set the Current throttle state of the cooling device.
  59. 1.2.2 void thermal_cooling_device_unregister(struct thermal_cooling_device *cdev)
  60. This interface function remove the thermal cooling device.
  61. It deletes the corresponding entry form /sys/class/thermal folder and unbind
  62. itself from all the thermal zone devices using it.
  63. 1.3 interface for binding a thermal zone device with a thermal cooling device
  64. 1.3.1 int thermal_zone_bind_cooling_device(struct thermal_zone_device *tz,
  65. int trip, struct thermal_cooling_device *cdev);
  66. This interface function bind a thermal cooling device to the certain trip point
  67. of a thermal zone device.
  68. This function is usually called in the thermal zone device .bind callback.
  69. tz: the thermal zone device
  70. cdev: thermal cooling device
  71. trip: indicates which trip point the cooling devices is associated with
  72. in this thermal zone.
  73. 1.3.2 int thermal_zone_unbind_cooling_device(struct thermal_zone_device *tz,
  74. int trip, struct thermal_cooling_device *cdev);
  75. This interface function unbind a thermal cooling device from the certain trip point
  76. of a thermal zone device.
  77. This function is usually called in the thermal zone device .unbind callback.
  78. tz: the thermal zone device
  79. cdev: thermal cooling device
  80. trip: indicates which trip point the cooling devices is associated with
  81. in this thermal zone.
  82. 2. sysfs attributes structure
  83. RO read only value
  84. RW read/write value
  85. All thermal sysfs attributes will be represented under /sys/class/thermal
  86. Thermal zone device sys I/F, created once it's registered:
  87. |thermal_zone[0-*]:
  88. |-----type: Type of the thermal zone
  89. |-----temp: Current temperature
  90. |-----mode: Working mode of the thermal zone
  91. |-----trip_point_[0-*]_temp: Trip point temperature
  92. |-----trip_point_[0-*]_type: Trip point type
  93. Thermal cooling device sys I/F, created once it's registered:
  94. |cooling_device[0-*]:
  95. |-----type : Type of the cooling device(processor/fan/...)
  96. |-----max_state: Maximum cooling state of the cooling device
  97. |-----cur_state: Current cooling state of the cooling device
  98. These two dynamic attributes are created/removed in pairs.
  99. They represent the relationship between a thermal zone and its associated cooling device.
  100. They are created/removed for each
  101. thermal_zone_bind_cooling_device/thermal_zone_unbind_cooling_device successful execution.
  102. |thermal_zone[0-*]
  103. |-----cdev[0-*]: The [0-*]th cooling device in the current thermal zone
  104. |-----cdev[0-*]_trip_point: Trip point that cdev[0-*] is associated with
  105. ***************************
  106. * Thermal zone attributes *
  107. ***************************
  108. type Strings which represent the thermal zone type.
  109. This is given by thermal zone driver as part of registration.
  110. Eg: "ACPI thermal zone" indicates it's a ACPI thermal device
  111. RO
  112. Optional
  113. temp Current temperature as reported by thermal zone (sensor)
  114. Unit: degree Celsius
  115. RO
  116. Required
  117. mode One of the predefined values in [kernel, user]
  118. This file gives information about the algorithm
  119. that is currently managing the thermal zone.
  120. It can be either default kernel based algorithm
  121. or user space application.
  122. RW
  123. Optional
  124. kernel = Thermal management in kernel thermal zone driver.
  125. user = Preventing kernel thermal zone driver actions upon
  126. trip points so that user application can take full
  127. charge of the thermal management.
  128. trip_point_[0-*]_temp The temperature above which trip point will be fired
  129. Unit: degree Celsius
  130. RO
  131. Optional
  132. trip_point_[0-*]_type Strings which indicate the type of the trip point
  133. E.g. it can be one of critical, hot, passive,
  134. active[0-*] for ACPI thermal zone.
  135. RO
  136. Optional
  137. cdev[0-*] Sysfs link to the thermal cooling device node where the sys I/F
  138. for cooling device throttling control represents.
  139. RO
  140. Optional
  141. cdev[0-*]_trip_point The trip point with which cdev[0-*] is associated in this thermal zone
  142. -1 means the cooling device is not associated with any trip point.
  143. RO
  144. Optional
  145. ******************************
  146. * Cooling device attributes *
  147. ******************************
  148. type String which represents the type of device
  149. eg: For generic ACPI: this should be "Fan",
  150. "Processor" or "LCD"
  151. eg. For memory controller device on intel_menlow platform:
  152. this should be "Memory controller"
  153. RO
  154. Optional
  155. max_state The maximum permissible cooling state of this cooling device.
  156. RO
  157. Required
  158. cur_state The current cooling state of this cooling device.
  159. the value can any integer numbers between 0 and max_state,
  160. cur_state == 0 means no cooling
  161. cur_state == max_state means the maximum cooling.
  162. RW
  163. Required
  164. 3. A simple implementation
  165. ACPI thermal zone may support multiple trip points like critical/hot/passive/active.
  166. If an ACPI thermal zone supports critical, passive, active[0] and active[1] at the same time,
  167. it may register itself as a thermal_zone_device (thermal_zone1) with 4 trip points in all.
  168. It has one processor and one fan, which are both registered as thermal_cooling_device.
  169. If the processor is listed in _PSL method, and the fan is listed in _AL0 method,
  170. the sys I/F structure will be built like this:
  171. /sys/class/thermal:
  172. |thermal_zone1:
  173. |-----type: ACPI thermal zone
  174. |-----temp: 37
  175. |-----mode: kernel
  176. |-----trip_point_0_temp: 100
  177. |-----trip_point_0_type: critical
  178. |-----trip_point_1_temp: 80
  179. |-----trip_point_1_type: passive
  180. |-----trip_point_2_temp: 70
  181. |-----trip_point_2_type: active[0]
  182. |-----trip_point_3_temp: 60
  183. |-----trip_point_3_type: active[1]
  184. |-----cdev0: --->/sys/class/thermal/cooling_device0
  185. |-----cdev0_trip_point: 1 /* cdev0 can be used for passive */
  186. |-----cdev1: --->/sys/class/thermal/cooling_device3
  187. |-----cdev1_trip_point: 2 /* cdev1 can be used for active[0]*/
  188. |cooling_device0:
  189. |-----type: Processor
  190. |-----max_state: 8
  191. |-----cur_state: 0
  192. |cooling_device3:
  193. |-----type: Fan
  194. |-----max_state: 2
  195. |-----cur_state: 0