thermal_core.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * thermal_core.h
  4. *
  5. * Copyright (C) 2012 Intel Corp
  6. * Author: Durgadoss R <durgadoss.r@intel.com>
  7. */
  8. #ifndef __THERMAL_CORE_H__
  9. #define __THERMAL_CORE_H__
  10. #include <linux/device.h>
  11. #include <linux/thermal.h>
  12. #include "thermal_netlink.h"
  13. /* Default Thermal Governor */
  14. #if defined(CONFIG_THERMAL_DEFAULT_GOV_STEP_WISE)
  15. #define DEFAULT_THERMAL_GOVERNOR "step_wise"
  16. #elif defined(CONFIG_THERMAL_DEFAULT_GOV_FAIR_SHARE)
  17. #define DEFAULT_THERMAL_GOVERNOR "fair_share"
  18. #elif defined(CONFIG_THERMAL_DEFAULT_GOV_USER_SPACE)
  19. #define DEFAULT_THERMAL_GOVERNOR "user_space"
  20. #elif defined(CONFIG_THERMAL_DEFAULT_GOV_POWER_ALLOCATOR)
  21. #define DEFAULT_THERMAL_GOVERNOR "power_allocator"
  22. #endif
  23. /* Initial state of a cooling device during binding */
  24. #define THERMAL_NO_TARGET -1UL
  25. /* Init section thermal table */
  26. extern struct thermal_governor *__governor_thermal_table[];
  27. extern struct thermal_governor *__governor_thermal_table_end[];
  28. #define THERMAL_TABLE_ENTRY(table, name) \
  29. static typeof(name) *__thermal_table_entry_##name \
  30. __used __section("__" #table "_thermal_table") = &name
  31. #define THERMAL_GOVERNOR_DECLARE(name) THERMAL_TABLE_ENTRY(governor, name)
  32. #define for_each_governor_table(__governor) \
  33. for (__governor = __governor_thermal_table; \
  34. __governor < __governor_thermal_table_end; \
  35. __governor++)
  36. int for_each_thermal_zone(int (*cb)(struct thermal_zone_device *, void *),
  37. void *);
  38. int for_each_thermal_cooling_device(int (*cb)(struct thermal_cooling_device *,
  39. void *), void *);
  40. int for_each_thermal_governor(int (*cb)(struct thermal_governor *, void *),
  41. void *thermal_governor);
  42. struct thermal_zone_device *thermal_zone_get_by_id(int id);
  43. struct thermal_attr {
  44. struct device_attribute attr;
  45. char name[THERMAL_NAME_LENGTH];
  46. };
  47. static inline bool cdev_is_power_actor(struct thermal_cooling_device *cdev)
  48. {
  49. return cdev->ops->get_requested_power && cdev->ops->state2power &&
  50. cdev->ops->power2state;
  51. }
  52. int power_actor_get_max_power(struct thermal_cooling_device *cdev,
  53. u32 *max_power);
  54. int power_actor_get_min_power(struct thermal_cooling_device *cdev,
  55. u32 *min_power);
  56. int power_actor_set_power(struct thermal_cooling_device *cdev,
  57. struct thermal_instance *ti, u32 power);
  58. /**
  59. * struct thermal_trip - representation of a point in temperature domain
  60. * @np: pointer to struct device_node that this trip point was created from
  61. * @temperature: temperature value in miliCelsius
  62. * @hysteresis: relative hysteresis in miliCelsius
  63. * @type: trip point type
  64. */
  65. struct thermal_trip {
  66. struct device_node *np;
  67. int temperature;
  68. int hysteresis;
  69. enum thermal_trip_type type;
  70. };
  71. int get_tz_trend(struct thermal_zone_device *tz, int trip);
  72. struct thermal_instance *
  73. get_thermal_instance(struct thermal_zone_device *tz,
  74. struct thermal_cooling_device *cdev,
  75. int trip);
  76. /*
  77. * This structure is used to describe the behavior of
  78. * a certain cooling device on a certain trip point
  79. * in a certain thermal zone
  80. */
  81. struct thermal_instance {
  82. int id;
  83. char name[THERMAL_NAME_LENGTH];
  84. struct thermal_zone_device *tz;
  85. struct thermal_cooling_device *cdev;
  86. int trip;
  87. bool initialized;
  88. unsigned long upper; /* Highest cooling state for this trip point */
  89. unsigned long lower; /* Lowest cooling state for this trip point */
  90. unsigned long target; /* expected cooling state */
  91. char attr_name[THERMAL_NAME_LENGTH];
  92. struct device_attribute attr;
  93. char weight_attr_name[THERMAL_NAME_LENGTH];
  94. struct device_attribute weight_attr;
  95. struct list_head tz_node; /* node in tz->thermal_instances */
  96. struct list_head cdev_node; /* node in cdev->thermal_instances */
  97. unsigned int weight; /* The weight of the cooling device */
  98. };
  99. #define to_thermal_zone(_dev) \
  100. container_of(_dev, struct thermal_zone_device, device)
  101. #define to_cooling_device(_dev) \
  102. container_of(_dev, struct thermal_cooling_device, device)
  103. int thermal_register_governor(struct thermal_governor *);
  104. void thermal_unregister_governor(struct thermal_governor *);
  105. void thermal_zone_device_rebind_exception(struct thermal_zone_device *,
  106. const char *, size_t);
  107. void thermal_zone_device_unbind_exception(struct thermal_zone_device *,
  108. const char *, size_t);
  109. int thermal_zone_device_set_policy(struct thermal_zone_device *, char *);
  110. int thermal_build_list_of_policies(char *buf);
  111. /* Helpers */
  112. void thermal_zone_set_trips(struct thermal_zone_device *tz);
  113. /* sysfs I/F */
  114. int thermal_zone_create_device_groups(struct thermal_zone_device *, int);
  115. void thermal_zone_destroy_device_groups(struct thermal_zone_device *);
  116. void thermal_cooling_device_setup_sysfs(struct thermal_cooling_device *);
  117. void thermal_cooling_device_destroy_sysfs(struct thermal_cooling_device *cdev);
  118. /* used only at binding time */
  119. ssize_t trip_point_show(struct device *, struct device_attribute *, char *);
  120. ssize_t weight_show(struct device *, struct device_attribute *, char *);
  121. ssize_t weight_store(struct device *, struct device_attribute *, const char *,
  122. size_t);
  123. #ifdef CONFIG_THERMAL_STATISTICS
  124. void thermal_cooling_device_stats_update(struct thermal_cooling_device *cdev,
  125. unsigned long new_state);
  126. #else
  127. static inline void
  128. thermal_cooling_device_stats_update(struct thermal_cooling_device *cdev,
  129. unsigned long new_state) {}
  130. #endif /* CONFIG_THERMAL_STATISTICS */
  131. /* device tree support */
  132. #ifdef CONFIG_THERMAL_OF
  133. int of_parse_thermal_zones(void);
  134. int of_thermal_get_ntrips(struct thermal_zone_device *);
  135. bool of_thermal_is_trip_valid(struct thermal_zone_device *, int);
  136. const struct thermal_trip *
  137. of_thermal_get_trip_points(struct thermal_zone_device *);
  138. #else
  139. static inline int of_parse_thermal_zones(void) { return 0; }
  140. static inline int of_thermal_get_ntrips(struct thermal_zone_device *tz)
  141. {
  142. return 0;
  143. }
  144. static inline bool of_thermal_is_trip_valid(struct thermal_zone_device *tz,
  145. int trip)
  146. {
  147. return false;
  148. }
  149. static inline const struct thermal_trip *
  150. of_thermal_get_trip_points(struct thermal_zone_device *tz)
  151. {
  152. return NULL;
  153. }
  154. #endif
  155. #endif /* __THERMAL_CORE_H__ */