sysfs-api.txt 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  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 focusses 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 callbacks.
  32. .bind: bind the thermal zone device with a thermal cooling device.
  33. .unbind: unbing 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 callbacks.
  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. /sys/class/thermal/
  87. Thermal zone device sys I/F, created once it's registered:
  88. |thermal_zone[0-*]:
  89. |-----type: Type of the thermal zone
  90. |-----temp: Current temperature
  91. |-----mode: Working mode of the thermal zone
  92. |-----trip_point_[0-*]_temp: Trip point temperature
  93. |-----trip_point_[0-*]_type: Trip point type
  94. Thermal cooling device sys I/F, created once it's registered:
  95. |cooling_device[0-*]:
  96. |-----type : Type of the cooling device(processor/fan/...)
  97. |-----max_state: Maximum cooling state of the cooling device
  98. |-----cur_state: Current cooling state of the cooling device
  99. These two dynamic attributes are created/removed in pairs.
  100. They represent the relationship between a thermal zone and its associated cooling device.
  101. They are created/removed for each
  102. thermal_zone_bind_cooling_device/thermal_zone_unbind_cooling_device successful exection.
  103. |thermal_zone[0-*]
  104. |-----cdev[0-*]: The [0-*]th cooling device in the current thermal zone
  105. |-----cdev[0-*]_trip_point: Trip point that cdev[0-*] is associated with
  106. ***************************
  107. * Thermal zone attributes *
  108. ***************************
  109. type Strings which represent the thermal zone type.
  110. This is given by thermal zone driver as part of registration.
  111. Eg: "ACPI thermal zone" indicates it's a ACPI thermal device
  112. RO
  113. Optional
  114. temp Current temperature as reported by thermal zone (sensor)
  115. Unit: degree celsius
  116. RO
  117. Required
  118. mode One of the predifned values in [kernel, user]
  119. This file gives information about the algorithm
  120. that is currently managing the thermal zone.
  121. It can be either default kernel based algorithm
  122. or user space application.
  123. RW
  124. Optional
  125. kernel = Thermal management in kernel thermal zone driver.
  126. user = Preventing kernel thermal zone driver actions upon
  127. trip points so that user application can take full
  128. charge of the thermal management.
  129. trip_point_[0-*]_temp The temperature above which trip point will be fired
  130. Unit: degree celsius
  131. RO
  132. Optional
  133. trip_point_[0-*]_type Strings which indicate the type of the trip point
  134. Eg. it can be one of critical, hot, passive,
  135. active[0-*] for ACPI thermal zone.
  136. RO
  137. Optional
  138. cdev[0-*] Sysfs link to the thermal cooling device node where the sys I/F
  139. for cooling device throttling control represents.
  140. RO
  141. Optional
  142. cdev[0-*]_trip_point The trip point with which cdev[0-*] is assocated in this thermal zone
  143. -1 means the cooling device is not associated with any trip point.
  144. RO
  145. Optional
  146. ******************************
  147. * Cooling device attributes *
  148. ******************************
  149. type String which represents the type of device
  150. eg: For generic ACPI: this should be "Fan",
  151. "Processor" or "LCD"
  152. eg. For memory controller device on intel_menlow platform:
  153. this should be "Memory controller"
  154. RO
  155. Optional
  156. max_state The maximum permissible cooling state of this cooling device.
  157. RO
  158. Required
  159. cur_state The current cooling state of this cooling device.
  160. the value can any integer numbers between 0 and max_state,
  161. cur_state == 0 means no cooling
  162. cur_state == max_state means the maximum cooling.
  163. RW
  164. Required
  165. 3. A simple implementation
  166. ACPI thermal zone may support multiple trip points like critical/hot/passive/active.
  167. If an ACPI thermal zone supports critical, passive, active[0] and active[1] at the same time,
  168. it may register itself as a thermale_zone_device (thermal_zone1) with 4 trip points in all.
  169. It has one processor and one fan, which are both registered as thermal_cooling_device.
  170. If the processor is listed in _PSL method, and the fan is listed in _AL0 method,
  171. the sys I/F structure will be built like this:
  172. /sys/class/thermal:
  173. |thermal_zone1:
  174. |-----type: ACPI thermal zone
  175. |-----temp: 37
  176. |-----mode: kernel
  177. |-----trip_point_0_temp: 100
  178. |-----trip_point_0_type: critical
  179. |-----trip_point_1_temp: 80
  180. |-----trip_point_1_type: passive
  181. |-----trip_point_2_temp: 70
  182. |-----trip_point_2_type: active[0]
  183. |-----trip_point_3_temp: 60
  184. |-----trip_point_3_type: active[1]
  185. |-----cdev0: --->/sys/class/thermal/cooling_device0
  186. |-----cdev0_trip_point: 1 /* cdev0 can be used for passive */
  187. |-----cdev1: --->/sys/class/thermal/cooling_device3
  188. |-----cdev1_trip_point: 2 /* cdev1 can be used for active[0]*/
  189. |cooling_device0:
  190. |-----type: Processor
  191. |-----max_state: 8
  192. |-----cur_state: 0
  193. |cooling_device3:
  194. |-----type: Fan
  195. |-----max_state: 2
  196. |-----cur_state: 0