thermal.h 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. /*
  2. * thermal.h ($Revision: 0 $)
  3. *
  4. * Copyright (C) 2008 Intel Corp
  5. * Copyright (C) 2008 Zhang Rui <rui.zhang@intel.com>
  6. * Copyright (C) 2008 Sujith Thomas <sujith.thomas@intel.com>
  7. *
  8. * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; version 2 of the License.
  12. *
  13. * This program is distributed in the hope that it will be useful, but
  14. * WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License along
  19. * with this program; if not, write to the Free Software Foundation, Inc.,
  20. * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
  21. *
  22. * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  23. */
  24. #ifndef __THERMAL_H__
  25. #define __THERMAL_H__
  26. #include <linux/idr.h>
  27. #include <linux/device.h>
  28. #include <linux/workqueue.h>
  29. #define THERMAL_TRIPS_NONE -1
  30. #define THERMAL_MAX_TRIPS 12
  31. #define THERMAL_NAME_LENGTH 20
  32. /* invalid cooling state */
  33. #define THERMAL_CSTATE_INVALID -1UL
  34. /* No upper/lower limit requirement */
  35. #define THERMAL_NO_LIMIT THERMAL_CSTATE_INVALID
  36. /* Unit conversion macros */
  37. #define KELVIN_TO_CELSIUS(t) (long)(((long)t-2732 >= 0) ? \
  38. ((long)t-2732+5)/10 : ((long)t-2732-5)/10)
  39. #define CELSIUS_TO_KELVIN(t) ((t)*10+2732)
  40. /* Adding event notification support elements */
  41. #define THERMAL_GENL_FAMILY_NAME "thermal_event"
  42. #define THERMAL_GENL_VERSION 0x01
  43. #define THERMAL_GENL_MCAST_GROUP_NAME "thermal_mc_group"
  44. /* Default Thermal Governor */
  45. #if defined(CONFIG_THERMAL_DEFAULT_GOV_STEP_WISE)
  46. #define DEFAULT_THERMAL_GOVERNOR "step_wise"
  47. #elif defined(CONFIG_THERMAL_DEFAULT_GOV_FAIR_SHARE)
  48. #define DEFAULT_THERMAL_GOVERNOR "fair_share"
  49. #elif defined(CONFIG_THERMAL_DEFAULT_GOV_USER_SPACE)
  50. #define DEFAULT_THERMAL_GOVERNOR "user_space"
  51. #endif
  52. struct thermal_zone_device;
  53. struct thermal_cooling_device;
  54. enum thermal_device_mode {
  55. THERMAL_DEVICE_DISABLED = 0,
  56. THERMAL_DEVICE_ENABLED,
  57. };
  58. enum thermal_trip_type {
  59. THERMAL_TRIP_ACTIVE = 0,
  60. THERMAL_TRIP_PASSIVE,
  61. THERMAL_TRIP_HOT,
  62. THERMAL_TRIP_CRITICAL,
  63. };
  64. enum thermal_trend {
  65. THERMAL_TREND_STABLE, /* temperature is stable */
  66. THERMAL_TREND_RAISING, /* temperature is raising */
  67. THERMAL_TREND_DROPPING, /* temperature is dropping */
  68. THERMAL_TREND_RAISE_FULL, /* apply highest cooling action */
  69. THERMAL_TREND_DROP_FULL, /* apply lowest cooling action */
  70. };
  71. /* Events supported by Thermal Netlink */
  72. enum events {
  73. THERMAL_AUX0,
  74. THERMAL_AUX1,
  75. THERMAL_CRITICAL,
  76. THERMAL_DEV_FAULT,
  77. };
  78. /* attributes of thermal_genl_family */
  79. enum {
  80. THERMAL_GENL_ATTR_UNSPEC,
  81. THERMAL_GENL_ATTR_EVENT,
  82. __THERMAL_GENL_ATTR_MAX,
  83. };
  84. #define THERMAL_GENL_ATTR_MAX (__THERMAL_GENL_ATTR_MAX - 1)
  85. /* commands supported by the thermal_genl_family */
  86. enum {
  87. THERMAL_GENL_CMD_UNSPEC,
  88. THERMAL_GENL_CMD_EVENT,
  89. __THERMAL_GENL_CMD_MAX,
  90. };
  91. #define THERMAL_GENL_CMD_MAX (__THERMAL_GENL_CMD_MAX - 1)
  92. struct thermal_zone_device_ops {
  93. int (*bind) (struct thermal_zone_device *,
  94. struct thermal_cooling_device *);
  95. int (*unbind) (struct thermal_zone_device *,
  96. struct thermal_cooling_device *);
  97. int (*get_temp) (struct thermal_zone_device *, unsigned long *);
  98. int (*get_mode) (struct thermal_zone_device *,
  99. enum thermal_device_mode *);
  100. int (*set_mode) (struct thermal_zone_device *,
  101. enum thermal_device_mode);
  102. int (*get_trip_type) (struct thermal_zone_device *, int,
  103. enum thermal_trip_type *);
  104. int (*get_trip_temp) (struct thermal_zone_device *, int,
  105. unsigned long *);
  106. int (*set_trip_temp) (struct thermal_zone_device *, int,
  107. unsigned long);
  108. int (*get_trip_hyst) (struct thermal_zone_device *, int,
  109. unsigned long *);
  110. int (*set_trip_hyst) (struct thermal_zone_device *, int,
  111. unsigned long);
  112. int (*get_crit_temp) (struct thermal_zone_device *, unsigned long *);
  113. int (*set_emul_temp) (struct thermal_zone_device *, unsigned long);
  114. int (*get_trend) (struct thermal_zone_device *, int,
  115. enum thermal_trend *);
  116. int (*notify) (struct thermal_zone_device *, int,
  117. enum thermal_trip_type);
  118. };
  119. struct thermal_cooling_device_ops {
  120. int (*get_max_state) (struct thermal_cooling_device *, unsigned long *);
  121. int (*get_cur_state) (struct thermal_cooling_device *, unsigned long *);
  122. int (*set_cur_state) (struct thermal_cooling_device *, unsigned long);
  123. };
  124. struct thermal_cooling_device {
  125. int id;
  126. char type[THERMAL_NAME_LENGTH];
  127. struct device device;
  128. void *devdata;
  129. const struct thermal_cooling_device_ops *ops;
  130. bool updated; /* true if the cooling device does not need update */
  131. struct mutex lock; /* protect thermal_instances list */
  132. struct list_head thermal_instances;
  133. struct list_head node;
  134. };
  135. struct thermal_attr {
  136. struct device_attribute attr;
  137. char name[THERMAL_NAME_LENGTH];
  138. };
  139. struct thermal_zone_device {
  140. int id;
  141. char type[THERMAL_NAME_LENGTH];
  142. struct device device;
  143. struct thermal_attr *trip_temp_attrs;
  144. struct thermal_attr *trip_type_attrs;
  145. struct thermal_attr *trip_hyst_attrs;
  146. void *devdata;
  147. int trips;
  148. int passive_delay;
  149. int polling_delay;
  150. int temperature;
  151. int last_temperature;
  152. int emul_temperature;
  153. int passive;
  154. unsigned int forced_passive;
  155. const struct thermal_zone_device_ops *ops;
  156. const struct thermal_zone_params *tzp;
  157. struct thermal_governor *governor;
  158. struct list_head thermal_instances;
  159. struct idr idr;
  160. struct mutex lock; /* protect thermal_instances list */
  161. struct list_head node;
  162. struct delayed_work poll_queue;
  163. };
  164. /* Structure that holds thermal governor information */
  165. struct thermal_governor {
  166. char name[THERMAL_NAME_LENGTH];
  167. int (*throttle)(struct thermal_zone_device *tz, int trip);
  168. struct list_head governor_list;
  169. struct module *owner;
  170. };
  171. /* Structure that holds binding parameters for a zone */
  172. struct thermal_bind_params {
  173. struct thermal_cooling_device *cdev;
  174. /*
  175. * This is a measure of 'how effectively these devices can
  176. * cool 'this' thermal zone. The shall be determined by platform
  177. * characterization. This is on a 'percentage' scale.
  178. * See Documentation/thermal/sysfs-api.txt for more information.
  179. */
  180. int weight;
  181. /*
  182. * This is a bit mask that gives the binding relation between this
  183. * thermal zone and cdev, for a particular trip point.
  184. * See Documentation/thermal/sysfs-api.txt for more information.
  185. */
  186. int trip_mask;
  187. int (*match) (struct thermal_zone_device *tz,
  188. struct thermal_cooling_device *cdev);
  189. };
  190. /* Structure to define Thermal Zone parameters */
  191. struct thermal_zone_params {
  192. char governor_name[THERMAL_NAME_LENGTH];
  193. int num_tbps; /* Number of tbp entries */
  194. struct thermal_bind_params *tbp;
  195. };
  196. struct thermal_genl_event {
  197. u32 orig;
  198. enum events event;
  199. };
  200. /* Function declarations */
  201. struct thermal_zone_device *thermal_zone_device_register(const char *, int, int,
  202. void *, const struct thermal_zone_device_ops *,
  203. const struct thermal_zone_params *, int, int);
  204. void thermal_zone_device_unregister(struct thermal_zone_device *);
  205. int thermal_zone_bind_cooling_device(struct thermal_zone_device *, int,
  206. struct thermal_cooling_device *,
  207. unsigned long, unsigned long);
  208. int thermal_zone_unbind_cooling_device(struct thermal_zone_device *, int,
  209. struct thermal_cooling_device *);
  210. void thermal_zone_device_update(struct thermal_zone_device *);
  211. struct thermal_cooling_device *thermal_cooling_device_register(char *, void *,
  212. const struct thermal_cooling_device_ops *);
  213. void thermal_cooling_device_unregister(struct thermal_cooling_device *);
  214. int get_tz_trend(struct thermal_zone_device *, int);
  215. struct thermal_instance *get_thermal_instance(struct thermal_zone_device *,
  216. struct thermal_cooling_device *, int);
  217. void thermal_cdev_update(struct thermal_cooling_device *);
  218. void notify_thermal_framework(struct thermal_zone_device *, int);
  219. int thermal_register_governor(struct thermal_governor *);
  220. void thermal_unregister_governor(struct thermal_governor *);
  221. #ifdef CONFIG_NET
  222. extern int thermal_generate_netlink_event(struct thermal_zone_device *tz,
  223. enum events event);
  224. #else
  225. static int thermal_generate_netlink_event(struct thermal_zone_device *tz,
  226. enum events event)
  227. {
  228. return 0;
  229. }
  230. #endif
  231. #endif /* __THERMAL_H__ */