sysfs-api.txt 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  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
  8. devices (sensors) and thermal cooling devices (fan, processor...) to register
  9. with the thermal management solution and to be a part of it.
  10. This how-to focuses on enabling new thermal zone and cooling devices to
  11. participate in thermal management.
  12. This solution is platform independent and any type of thermal zone devices
  13. and 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
  15. as well as cooling device attributes to the user space.
  16. An intelligent thermal management application can make decisions based on
  17. inputs from thermal zone attributes (the current temperature and trip point
  18. temperature) 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,
  24. int trips, 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-*]. It tries to bind all the
  27. 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
  46. unbind all 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/...)
  51. to /sys/class/thermal/ folder as cooling_device[0-*]. It tries to bind itself
  52. 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
  62. unbind 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
  67. point 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
  76. trip point of a thermal zone device. This function is usually called in
  77. 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. Thermal sysfs attributes will be represented under /sys/class/thermal.
  86. Hwmon sysfs I/F extension is also available under /sys/class/hwmon
  87. if hwmon is compiled in or built as a module.
  88. Thermal zone device sys I/F, created once it's registered:
  89. /sys/class/thermal/thermal_zone[0-*]:
  90. |---type: Type of the thermal zone
  91. |---temp: Current temperature
  92. |---mode: Working mode of the thermal zone
  93. |---trip_point_[0-*]_temp: Trip point temperature
  94. |---trip_point_[0-*]_type: Trip point type
  95. Thermal cooling device sys I/F, created once it's registered:
  96. /sys/class/thermal/cooling_device[0-*]:
  97. |---type: Type of the cooling device(processor/fan/...)
  98. |---max_state: Maximum cooling state of the cooling device
  99. |---cur_state: Current cooling state of the cooling device
  100. Then next two dynamic attributes are created/removed in pairs. They represent
  101. the relationship between a thermal zone and its associated cooling device.
  102. They are created/removed for each successful execution of
  103. thermal_zone_bind_cooling_device/thermal_zone_unbind_cooling_device.
  104. /sys/class/thermal/thermal_zone[0-*]:
  105. |---cdev[0-*]: [0-*]th cooling device in current thermal zone
  106. |---cdev[0-*]_trip_point: Trip point that cdev[0-*] is associated with
  107. Besides the thermal zone device sysfs I/F and cooling device sysfs I/F,
  108. the generic thermal driver also creates a hwmon sysfs I/F for each _type_
  109. of thermal zone device. E.g. the generic thermal driver registers one hwmon
  110. class device and build the associated hwmon sysfs I/F for all the registered
  111. ACPI thermal zones.
  112. /sys/class/hwmon/hwmon[0-*]:
  113. |---name: The type of the thermal zone devices
  114. |---temp[1-*]_input: The current temperature of thermal zone [1-*]
  115. |---temp[1-*]_critical: The critical trip point of thermal zone [1-*]
  116. Please read Documentation/hwmon/sysfs-interface for additional information.
  117. ***************************
  118. * Thermal zone attributes *
  119. ***************************
  120. type
  121. Strings which represent the thermal zone type.
  122. This is given by thermal zone driver as part of registration.
  123. E.g: "acpitz" indicates it's an ACPI thermal device.
  124. In order to keep it consistent with hwmon sys attribute; this should
  125. be a short, lowercase string, not containing spaces nor dashes.
  126. RO, Required
  127. temp
  128. Current temperature as reported by thermal zone (sensor).
  129. Unit: millidegree Celsius
  130. RO, Required
  131. mode
  132. One of the predefined values in [kernel, user].
  133. This file gives information about the algorithm that is currently
  134. managing the thermal zone. It can be either default kernel based
  135. algorithm or user space application.
  136. kernel = Thermal management in kernel thermal zone driver.
  137. user = Preventing kernel thermal zone driver actions upon
  138. trip points so that user application can take full
  139. charge of the thermal management.
  140. RW, Optional
  141. trip_point_[0-*]_temp
  142. The temperature above which trip point will be fired.
  143. Unit: millidegree Celsius
  144. RO, Optional
  145. trip_point_[0-*]_type
  146. Strings which indicate the type of the trip point.
  147. E.g. it can be one of critical, hot, passive, active[0-*] for ACPI
  148. thermal zone.
  149. RO, Optional
  150. cdev[0-*]
  151. Sysfs link to the thermal cooling device node where the sys I/F
  152. for cooling device throttling control represents.
  153. RO, Optional
  154. cdev[0-*]_trip_point
  155. The trip point with which cdev[0-*] is associated in this thermal
  156. zone; -1 means the cooling device is not associated with any trip
  157. point.
  158. RO, Optional
  159. passive
  160. Attribute is only present for zones in which the passive cooling
  161. policy is not supported by native thermal driver. Default is zero
  162. and can be set to a temperature (in millidegrees) to enable a
  163. passive trip point for the zone. Activation is done by polling with
  164. an interval of 1 second.
  165. Unit: millidegrees Celsius
  166. Valid values: 0 (disabled) or greater than 1000
  167. RW, Optional
  168. *****************************
  169. * Cooling device attributes *
  170. *****************************
  171. type
  172. String which represents the type of device, e.g:
  173. - for generic ACPI: should be "Fan", "Processor" or "LCD"
  174. - for memory controller device on intel_menlow platform:
  175. should be "Memory controller".
  176. RO, Required
  177. max_state
  178. The maximum permissible cooling state of this cooling device.
  179. RO, Required
  180. cur_state
  181. The current cooling state of this cooling device.
  182. The value can any integer numbers between 0 and max_state:
  183. - cur_state == 0 means no cooling
  184. - cur_state == max_state means the maximum cooling.
  185. RW, Required
  186. 3. A simple implementation
  187. ACPI thermal zone may support multiple trip points like critical, hot,
  188. passive, active. If an ACPI thermal zone supports critical, passive,
  189. active[0] and active[1] at the same time, it may register itself as a
  190. thermal_zone_device (thermal_zone1) with 4 trip points in all.
  191. It has one processor and one fan, which are both registered as
  192. thermal_cooling_device.
  193. If the processor is listed in _PSL method, and the fan is listed in _AL0
  194. method, the sys I/F structure will be built like this:
  195. /sys/class/thermal:
  196. |thermal_zone1:
  197. |---type: acpitz
  198. |---temp: 37000
  199. |---mode: kernel
  200. |---trip_point_0_temp: 100000
  201. |---trip_point_0_type: critical
  202. |---trip_point_1_temp: 80000
  203. |---trip_point_1_type: passive
  204. |---trip_point_2_temp: 70000
  205. |---trip_point_2_type: active0
  206. |---trip_point_3_temp: 60000
  207. |---trip_point_3_type: active1
  208. |---cdev0: --->/sys/class/thermal/cooling_device0
  209. |---cdev0_trip_point: 1 /* cdev0 can be used for passive */
  210. |---cdev1: --->/sys/class/thermal/cooling_device3
  211. |---cdev1_trip_point: 2 /* cdev1 can be used for active[0]*/
  212. |cooling_device0:
  213. |---type: Processor
  214. |---max_state: 8
  215. |---cur_state: 0
  216. |cooling_device3:
  217. |---type: Fan
  218. |---max_state: 2
  219. |---cur_state: 0
  220. /sys/class/hwmon:
  221. |hwmon0:
  222. |---name: acpitz
  223. |---temp1_input: 37000
  224. |---temp1_crit: 100000
  225. 4. Event Notification
  226. The framework includes a simple notification mechanism, in the form of a
  227. netlink event. Netlink socket initialization is done during the _init_
  228. of the framework. Drivers which intend to use the notification mechanism
  229. just need to call thermal_generate_netlink_event() with two arguments viz
  230. (originator, event). Typically the originator will be an integer assigned
  231. to a thermal_zone_device when it registers itself with the framework. The
  232. event will be one of:{THERMAL_AUX0, THERMAL_AUX1, THERMAL_CRITICAL,
  233. THERMAL_DEV_FAULT}. Notification can be sent when the current temperature
  234. crosses any of the configured thresholds.