thermal.h 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  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. /* No upper/lower limit requirement */
  33. #define THERMAL_NO_LIMIT -1UL
  34. /* Unit conversion macros */
  35. #define KELVIN_TO_CELSIUS(t) (long)(((long)t-2732 >= 0) ? \
  36. ((long)t-2732+5)/10 : ((long)t-2732-5)/10)
  37. #define CELSIUS_TO_KELVIN(t) ((t)*10+2732)
  38. /* Adding event notification support elements */
  39. #define THERMAL_GENL_FAMILY_NAME "thermal_event"
  40. #define THERMAL_GENL_VERSION 0x01
  41. #define THERMAL_GENL_MCAST_GROUP_NAME "thermal_mc_group"
  42. /* Default Thermal Governor */
  43. #if defined(CONFIG_THERMAL_DEFAULT_GOV_STEP_WISE)
  44. #define DEFAULT_THERMAL_GOVERNOR "step_wise"
  45. #elif defined(CONFIG_THERMAL_DEFAULT_GOV_FAIR_SHARE)
  46. #define DEFAULT_THERMAL_GOVERNOR "fair_share"
  47. #elif defined(CONFIG_THERMAL_DEFAULT_GOV_USER_SPACE)
  48. #define DEFAULT_THERMAL_GOVERNOR "user_space"
  49. #endif
  50. struct thermal_zone_device;
  51. struct thermal_cooling_device;
  52. enum thermal_device_mode {
  53. THERMAL_DEVICE_DISABLED = 0,
  54. THERMAL_DEVICE_ENABLED,
  55. };
  56. enum thermal_trip_type {
  57. THERMAL_TRIP_ACTIVE = 0,
  58. THERMAL_TRIP_PASSIVE,
  59. THERMAL_TRIP_HOT,
  60. THERMAL_TRIP_CRITICAL,
  61. };
  62. enum thermal_trend {
  63. THERMAL_TREND_STABLE, /* temperature is stable */
  64. THERMAL_TREND_RAISING, /* temperature is raising */
  65. THERMAL_TREND_DROPPING, /* temperature is dropping */
  66. THERMAL_TREND_RAISE_FULL, /* apply highest cooling action */
  67. THERMAL_TREND_DROP_FULL, /* apply lowest cooling action */
  68. };
  69. /* Events supported by Thermal Netlink */
  70. enum events {
  71. THERMAL_AUX0,
  72. THERMAL_AUX1,
  73. THERMAL_CRITICAL,
  74. THERMAL_DEV_FAULT,
  75. };
  76. /* attributes of thermal_genl_family */
  77. enum {
  78. THERMAL_GENL_ATTR_UNSPEC,
  79. THERMAL_GENL_ATTR_EVENT,
  80. __THERMAL_GENL_ATTR_MAX,
  81. };
  82. #define THERMAL_GENL_ATTR_MAX (__THERMAL_GENL_ATTR_MAX - 1)
  83. /* commands supported by the thermal_genl_family */
  84. enum {
  85. THERMAL_GENL_CMD_UNSPEC,
  86. THERMAL_GENL_CMD_EVENT,
  87. __THERMAL_GENL_CMD_MAX,
  88. };
  89. #define THERMAL_GENL_CMD_MAX (__THERMAL_GENL_CMD_MAX - 1)
  90. struct thermal_zone_device_ops {
  91. int (*bind) (struct thermal_zone_device *,
  92. struct thermal_cooling_device *);
  93. int (*unbind) (struct thermal_zone_device *,
  94. struct thermal_cooling_device *);
  95. int (*get_temp) (struct thermal_zone_device *, unsigned long *);
  96. int (*get_mode) (struct thermal_zone_device *,
  97. enum thermal_device_mode *);
  98. int (*set_mode) (struct thermal_zone_device *,
  99. enum thermal_device_mode);
  100. int (*get_trip_type) (struct thermal_zone_device *, int,
  101. enum thermal_trip_type *);
  102. int (*get_trip_temp) (struct thermal_zone_device *, int,
  103. unsigned long *);
  104. int (*set_trip_temp) (struct thermal_zone_device *, int,
  105. unsigned long);
  106. int (*get_trip_hyst) (struct thermal_zone_device *, int,
  107. unsigned long *);
  108. int (*set_trip_hyst) (struct thermal_zone_device *, int,
  109. unsigned long);
  110. int (*get_crit_temp) (struct thermal_zone_device *, unsigned long *);
  111. int (*set_emul_temp) (struct thermal_zone_device *, unsigned long);
  112. int (*get_trend) (struct thermal_zone_device *, int,
  113. enum thermal_trend *);
  114. int (*notify) (struct thermal_zone_device *, int,
  115. enum thermal_trip_type);
  116. };
  117. struct thermal_cooling_device_ops {
  118. int (*get_max_state) (struct thermal_cooling_device *, unsigned long *);
  119. int (*get_cur_state) (struct thermal_cooling_device *, unsigned long *);
  120. int (*set_cur_state) (struct thermal_cooling_device *, unsigned long);
  121. };
  122. struct thermal_cooling_device {
  123. int id;
  124. char type[THERMAL_NAME_LENGTH];
  125. struct device device;
  126. void *devdata;
  127. const struct thermal_cooling_device_ops *ops;
  128. bool updated; /* true if the cooling device does not need update */
  129. struct mutex lock; /* protect thermal_instances list */
  130. struct list_head thermal_instances;
  131. struct list_head node;
  132. };
  133. struct thermal_attr {
  134. struct device_attribute attr;
  135. char name[THERMAL_NAME_LENGTH];
  136. };
  137. struct thermal_zone_device {
  138. int id;
  139. char type[THERMAL_NAME_LENGTH];
  140. struct device device;
  141. struct thermal_attr *trip_temp_attrs;
  142. struct thermal_attr *trip_type_attrs;
  143. struct thermal_attr *trip_hyst_attrs;
  144. void *devdata;
  145. int trips;
  146. int passive_delay;
  147. int polling_delay;
  148. int temperature;
  149. int last_temperature;
  150. int emul_temperature;
  151. int passive;
  152. unsigned int forced_passive;
  153. const struct thermal_zone_device_ops *ops;
  154. const struct thermal_zone_params *tzp;
  155. struct thermal_governor *governor;
  156. struct list_head thermal_instances;
  157. struct idr idr;
  158. struct mutex lock; /* protect thermal_instances list */
  159. struct list_head node;
  160. struct delayed_work poll_queue;
  161. };
  162. /* Structure that holds thermal governor information */
  163. struct thermal_governor {
  164. char name[THERMAL_NAME_LENGTH];
  165. int (*throttle)(struct thermal_zone_device *tz, int trip);
  166. struct list_head governor_list;
  167. struct module *owner;
  168. };
  169. /* Structure that holds binding parameters for a zone */
  170. struct thermal_bind_params {
  171. struct thermal_cooling_device *cdev;
  172. /*
  173. * This is a measure of 'how effectively these devices can
  174. * cool 'this' thermal zone. The shall be determined by platform
  175. * characterization. This is on a 'percentage' scale.
  176. * See Documentation/thermal/sysfs-api.txt for more information.
  177. */
  178. int weight;
  179. /*
  180. * This is a bit mask that gives the binding relation between this
  181. * thermal zone and cdev, for a particular trip point.
  182. * See Documentation/thermal/sysfs-api.txt for more information.
  183. */
  184. int trip_mask;
  185. int (*match) (struct thermal_zone_device *tz,
  186. struct thermal_cooling_device *cdev);
  187. };
  188. /* Structure to define Thermal Zone parameters */
  189. struct thermal_zone_params {
  190. char governor_name[THERMAL_NAME_LENGTH];
  191. int num_tbps; /* Number of tbp entries */
  192. struct thermal_bind_params *tbp;
  193. };
  194. struct thermal_genl_event {
  195. u32 orig;
  196. enum events event;
  197. };
  198. /* Function declarations */
  199. struct thermal_zone_device *thermal_zone_device_register(const char *, int, int,
  200. void *, const struct thermal_zone_device_ops *,
  201. const struct thermal_zone_params *, int, int);
  202. void thermal_zone_device_unregister(struct thermal_zone_device *);
  203. int thermal_zone_bind_cooling_device(struct thermal_zone_device *, int,
  204. struct thermal_cooling_device *,
  205. unsigned long, unsigned long);
  206. int thermal_zone_unbind_cooling_device(struct thermal_zone_device *, int,
  207. struct thermal_cooling_device *);
  208. void thermal_zone_device_update(struct thermal_zone_device *);
  209. struct thermal_cooling_device *thermal_cooling_device_register(char *, void *,
  210. const struct thermal_cooling_device_ops *);
  211. void thermal_cooling_device_unregister(struct thermal_cooling_device *);
  212. int get_tz_trend(struct thermal_zone_device *, int);
  213. struct thermal_instance *get_thermal_instance(struct thermal_zone_device *,
  214. struct thermal_cooling_device *, int);
  215. void thermal_cdev_update(struct thermal_cooling_device *);
  216. void notify_thermal_framework(struct thermal_zone_device *, int);
  217. int thermal_register_governor(struct thermal_governor *);
  218. void thermal_unregister_governor(struct thermal_governor *);
  219. #ifdef CONFIG_NET
  220. extern int thermal_generate_netlink_event(struct thermal_zone_device *tz,
  221. enum events event);
  222. #else
  223. static int thermal_generate_netlink_event(struct thermal_zone_device *tz,
  224. enum events event)
  225. {
  226. return 0;
  227. }
  228. #endif
  229. #endif /* __THERMAL_H__ */