sysfs-api.txt 12 KB

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