sysfs-api.txt 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  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, int mask, void *devdata,
  25. struct thermal_zone_device_ops *ops)
  26. This interface function adds a new thermal zone device (sensor) to
  27. /sys/class/thermal folder as thermal_zone[0-*]. It tries to bind all the
  28. thermal cooling devices registered at the same time.
  29. name: the thermal zone name.
  30. trips: the total number of trip points this thermal zone supports.
  31. mask: Bit string: If 'n'th bit is set, then trip point 'n' is writeable.
  32. devdata: device private data
  33. ops: thermal zone device call-backs.
  34. .bind: bind the thermal zone device with a thermal cooling device.
  35. .unbind: unbind the thermal zone device with a thermal cooling device.
  36. .get_temp: get the current temperature of the thermal zone.
  37. .get_mode: get the current mode (enabled/disabled) of the thermal zone.
  38. - "enabled" means the kernel thermal management is enabled.
  39. - "disabled" will prevent kernel thermal driver action upon trip points
  40. so that user applications can take charge of thermal management.
  41. .set_mode: set the mode (enabled/disabled) of the thermal zone.
  42. .get_trip_type: get the type of certain trip point.
  43. .get_trip_temp: get the temperature above which the certain trip point
  44. will be fired.
  45. 1.1.2 void thermal_zone_device_unregister(struct thermal_zone_device *tz)
  46. This interface function removes the thermal zone device.
  47. It deletes the corresponding entry form /sys/class/thermal folder and
  48. unbind all the thermal cooling devices it uses.
  49. 1.2 thermal cooling device interface
  50. 1.2.1 struct thermal_cooling_device *thermal_cooling_device_register(char *name,
  51. void *devdata, struct thermal_cooling_device_ops *)
  52. This interface function adds a new thermal cooling device (fan/processor/...)
  53. to /sys/class/thermal/ folder as cooling_device[0-*]. It tries to bind itself
  54. to all the thermal zone devices register at the same time.
  55. name: the cooling device name.
  56. devdata: device private data.
  57. ops: thermal cooling devices call-backs.
  58. .get_max_state: get the Maximum throttle state of the cooling device.
  59. .get_cur_state: get the Current throttle state of the cooling device.
  60. .set_cur_state: set the Current throttle state of the cooling device.
  61. 1.2.2 void thermal_cooling_device_unregister(struct thermal_cooling_device *cdev)
  62. This interface function remove the thermal cooling device.
  63. It deletes the corresponding entry form /sys/class/thermal folder and
  64. unbind itself from all the thermal zone devices using it.
  65. 1.3 interface for binding a thermal zone device with a thermal cooling device
  66. 1.3.1 int thermal_zone_bind_cooling_device(struct thermal_zone_device *tz,
  67. int trip, struct thermal_cooling_device *cdev);
  68. This interface function bind a thermal cooling device to the certain trip
  69. point of a thermal zone device.
  70. This function is usually called in the thermal zone device .bind callback.
  71. tz: the thermal zone device
  72. cdev: thermal cooling device
  73. trip: indicates which trip point the cooling devices is associated with
  74. in this thermal zone.
  75. 1.3.2 int thermal_zone_unbind_cooling_device(struct thermal_zone_device *tz,
  76. int trip, struct thermal_cooling_device *cdev);
  77. This interface function unbind a thermal cooling device from the certain
  78. trip point of a thermal zone device. This function is usually called in
  79. the thermal zone device .unbind callback.
  80. tz: the thermal zone device
  81. cdev: thermal cooling device
  82. trip: indicates which trip point the cooling devices is associated with
  83. in this thermal zone.
  84. 2. sysfs attributes structure
  85. RO read only value
  86. RW read/write value
  87. Thermal sysfs attributes will be represented under /sys/class/thermal.
  88. Hwmon sysfs I/F extension is also available under /sys/class/hwmon
  89. if hwmon is compiled in or built as a module.
  90. Thermal zone device sys I/F, created once it's registered:
  91. /sys/class/thermal/thermal_zone[0-*]:
  92. |---type: Type of the thermal zone
  93. |---temp: Current temperature
  94. |---mode: Working mode of the thermal zone
  95. |---trip_point_[0-*]_temp: Trip point temperature
  96. |---trip_point_[0-*]_type: Trip point type
  97. |---trip_point_[0-*]_hyst: Hysteresis value for this trip point
  98. Thermal cooling device sys I/F, created once it's registered:
  99. /sys/class/thermal/cooling_device[0-*]:
  100. |---type: Type of the cooling device(processor/fan/...)
  101. |---max_state: Maximum cooling state of the cooling device
  102. |---cur_state: Current cooling state of the cooling device
  103. Then next two dynamic attributes are created/removed in pairs. They represent
  104. the relationship between a thermal zone and its associated cooling device.
  105. They are created/removed for each successful execution of
  106. thermal_zone_bind_cooling_device/thermal_zone_unbind_cooling_device.
  107. /sys/class/thermal/thermal_zone[0-*]:
  108. |---cdev[0-*]: [0-*]th cooling device in current thermal zone
  109. |---cdev[0-*]_trip_point: Trip point that cdev[0-*] is associated with
  110. Besides the thermal zone device sysfs I/F and cooling device sysfs I/F,
  111. the generic thermal driver also creates a hwmon sysfs I/F for each _type_
  112. of thermal zone device. E.g. the generic thermal driver registers one hwmon
  113. class device and build the associated hwmon sysfs I/F for all the registered
  114. ACPI thermal zones.
  115. /sys/class/hwmon/hwmon[0-*]:
  116. |---name: The type of the thermal zone devices
  117. |---temp[1-*]_input: The current temperature of thermal zone [1-*]
  118. |---temp[1-*]_critical: The critical trip point of thermal zone [1-*]
  119. Please read Documentation/hwmon/sysfs-interface for additional information.
  120. ***************************
  121. * Thermal zone attributes *
  122. ***************************
  123. type
  124. Strings which represent the thermal zone type.
  125. This is given by thermal zone driver as part of registration.
  126. E.g: "acpitz" indicates it's an ACPI thermal device.
  127. In order to keep it consistent with hwmon sys attribute; this should
  128. be a short, lowercase string, not containing spaces nor dashes.
  129. RO, Required
  130. temp
  131. Current temperature as reported by thermal zone (sensor).
  132. Unit: millidegree Celsius
  133. RO, Required
  134. mode
  135. One of the predefined values in [enabled, disabled].
  136. This file gives information about the algorithm that is currently
  137. managing the thermal zone. It can be either default kernel based
  138. algorithm or user space application.
  139. enabled = enable Kernel Thermal management.
  140. disabled = Preventing kernel thermal zone driver actions upon
  141. trip points so that user application can take full
  142. charge of the thermal management.
  143. RW, Optional
  144. trip_point_[0-*]_temp
  145. The temperature above which trip point will be fired.
  146. Unit: millidegree Celsius
  147. RO, Optional
  148. trip_point_[0-*]_type
  149. Strings which indicate the type of the trip point.
  150. E.g. it can be one of critical, hot, passive, active[0-*] for ACPI
  151. thermal zone.
  152. RO, Optional
  153. trip_point_[0-*]_hyst
  154. The hysteresis value for a trip point, represented as an integer
  155. Unit: Celsius
  156. RW, Optional
  157. cdev[0-*]
  158. Sysfs link to the thermal cooling device node where the sys I/F
  159. for cooling device throttling control represents.
  160. RO, Optional
  161. cdev[0-*]_trip_point
  162. The trip point with which cdev[0-*] is associated in this thermal
  163. zone; -1 means the cooling device is not associated with any trip
  164. point.
  165. RO, Optional
  166. passive
  167. Attribute is only present for zones in which the passive cooling
  168. policy is not supported by native thermal driver. Default is zero
  169. and can be set to a temperature (in millidegrees) to enable a
  170. passive trip point for the zone. Activation is done by polling with
  171. an interval of 1 second.
  172. Unit: millidegrees Celsius
  173. Valid values: 0 (disabled) or greater than 1000
  174. RW, Optional
  175. *****************************
  176. * Cooling device attributes *
  177. *****************************
  178. type
  179. String which represents the type of device, e.g:
  180. - for generic ACPI: should be "Fan", "Processor" or "LCD"
  181. - for memory controller device on intel_menlow platform:
  182. should be "Memory controller".
  183. RO, Required
  184. max_state
  185. The maximum permissible cooling state of this cooling device.
  186. RO, Required
  187. cur_state
  188. The current cooling state of this cooling device.
  189. The value can any integer numbers between 0 and max_state:
  190. - cur_state == 0 means no cooling
  191. - cur_state == max_state means the maximum cooling.
  192. RW, Required
  193. 3. A simple implementation
  194. ACPI thermal zone may support multiple trip points like critical, hot,
  195. passive, active. If an ACPI thermal zone supports critical, passive,
  196. active[0] and active[1] at the same time, it may register itself as a
  197. thermal_zone_device (thermal_zone1) with 4 trip points in all.
  198. It has one processor and one fan, which are both registered as
  199. thermal_cooling_device.
  200. If the processor is listed in _PSL method, and the fan is listed in _AL0
  201. method, the sys I/F structure will be built like this:
  202. /sys/class/thermal:
  203. |thermal_zone1:
  204. |---type: acpitz
  205. |---temp: 37000
  206. |---mode: enabled
  207. |---trip_point_0_temp: 100000
  208. |---trip_point_0_type: critical
  209. |---trip_point_1_temp: 80000
  210. |---trip_point_1_type: passive
  211. |---trip_point_2_temp: 70000
  212. |---trip_point_2_type: active0
  213. |---trip_point_3_temp: 60000
  214. |---trip_point_3_type: active1
  215. |---cdev0: --->/sys/class/thermal/cooling_device0
  216. |---cdev0_trip_point: 1 /* cdev0 can be used for passive */
  217. |---cdev1: --->/sys/class/thermal/cooling_device3
  218. |---cdev1_trip_point: 2 /* cdev1 can be used for active[0]*/
  219. |cooling_device0:
  220. |---type: Processor
  221. |---max_state: 8
  222. |---cur_state: 0
  223. |cooling_device3:
  224. |---type: Fan
  225. |---max_state: 2
  226. |---cur_state: 0
  227. /sys/class/hwmon:
  228. |hwmon0:
  229. |---name: acpitz
  230. |---temp1_input: 37000
  231. |---temp1_crit: 100000
  232. 4. Event Notification
  233. The framework includes a simple notification mechanism, in the form of a
  234. netlink event. Netlink socket initialization is done during the _init_
  235. of the framework. Drivers which intend to use the notification mechanism
  236. just need to call thermal_generate_netlink_event() with two arguments viz
  237. (originator, event). Typically the originator will be an integer assigned
  238. to a thermal_zone_device when it registers itself with the framework. The
  239. event will be one of:{THERMAL_AUX0, THERMAL_AUX1, THERMAL_CRITICAL,
  240. THERMAL_DEV_FAULT}. Notification can be sent when the current temperature
  241. crosses any of the configured thresholds.