thermal_core.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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. /* Initial state of a cooling device during binding */
  13. #define THERMAL_NO_TARGET -1UL
  14. /*
  15. * This structure is used to describe the behavior of
  16. * a certain cooling device on a certain trip point
  17. * in a certain thermal zone
  18. */
  19. struct thermal_instance {
  20. int id;
  21. char name[THERMAL_NAME_LENGTH];
  22. struct thermal_zone_device *tz;
  23. struct thermal_cooling_device *cdev;
  24. int trip;
  25. bool initialized;
  26. unsigned long upper; /* Highest cooling state for this trip point */
  27. unsigned long lower; /* Lowest cooling state for this trip point */
  28. unsigned long target; /* expected cooling state */
  29. char attr_name[THERMAL_NAME_LENGTH];
  30. struct device_attribute attr;
  31. char weight_attr_name[THERMAL_NAME_LENGTH];
  32. struct device_attribute weight_attr;
  33. struct list_head tz_node; /* node in tz->thermal_instances */
  34. struct list_head cdev_node; /* node in cdev->thermal_instances */
  35. unsigned int weight; /* The weight of the cooling device */
  36. };
  37. #define to_thermal_zone(_dev) \
  38. container_of(_dev, struct thermal_zone_device, device)
  39. #define to_cooling_device(_dev) \
  40. container_of(_dev, struct thermal_cooling_device, device)
  41. int thermal_register_governor(struct thermal_governor *);
  42. void thermal_unregister_governor(struct thermal_governor *);
  43. void thermal_zone_device_rebind_exception(struct thermal_zone_device *,
  44. const char *, size_t);
  45. void thermal_zone_device_unbind_exception(struct thermal_zone_device *,
  46. const char *, size_t);
  47. int thermal_zone_device_set_policy(struct thermal_zone_device *, char *);
  48. int thermal_build_list_of_policies(char *buf);
  49. /* sysfs I/F */
  50. int thermal_zone_create_device_groups(struct thermal_zone_device *, int);
  51. void thermal_zone_destroy_device_groups(struct thermal_zone_device *);
  52. void thermal_cooling_device_setup_sysfs(struct thermal_cooling_device *);
  53. void thermal_cooling_device_destroy_sysfs(struct thermal_cooling_device *cdev);
  54. /* used only at binding time */
  55. ssize_t trip_point_show(struct device *, struct device_attribute *, char *);
  56. ssize_t weight_show(struct device *, struct device_attribute *, char *);
  57. ssize_t weight_store(struct device *, struct device_attribute *, const char *,
  58. size_t);
  59. #ifdef CONFIG_THERMAL_STATISTICS
  60. void thermal_cooling_device_stats_update(struct thermal_cooling_device *cdev,
  61. unsigned long new_state);
  62. #else
  63. static inline void
  64. thermal_cooling_device_stats_update(struct thermal_cooling_device *cdev,
  65. unsigned long new_state) {}
  66. #endif /* CONFIG_THERMAL_STATISTICS */
  67. #ifdef CONFIG_THERMAL_GOV_STEP_WISE
  68. int thermal_gov_step_wise_register(void);
  69. void thermal_gov_step_wise_unregister(void);
  70. #else
  71. static inline int thermal_gov_step_wise_register(void) { return 0; }
  72. static inline void thermal_gov_step_wise_unregister(void) {}
  73. #endif /* CONFIG_THERMAL_GOV_STEP_WISE */
  74. #ifdef CONFIG_THERMAL_GOV_FAIR_SHARE
  75. int thermal_gov_fair_share_register(void);
  76. void thermal_gov_fair_share_unregister(void);
  77. #else
  78. static inline int thermal_gov_fair_share_register(void) { return 0; }
  79. static inline void thermal_gov_fair_share_unregister(void) {}
  80. #endif /* CONFIG_THERMAL_GOV_FAIR_SHARE */
  81. #ifdef CONFIG_THERMAL_GOV_BANG_BANG
  82. int thermal_gov_bang_bang_register(void);
  83. void thermal_gov_bang_bang_unregister(void);
  84. #else
  85. static inline int thermal_gov_bang_bang_register(void) { return 0; }
  86. static inline void thermal_gov_bang_bang_unregister(void) {}
  87. #endif /* CONFIG_THERMAL_GOV_BANG_BANG */
  88. #ifdef CONFIG_THERMAL_GOV_USER_SPACE
  89. int thermal_gov_user_space_register(void);
  90. void thermal_gov_user_space_unregister(void);
  91. #else
  92. static inline int thermal_gov_user_space_register(void) { return 0; }
  93. static inline void thermal_gov_user_space_unregister(void) {}
  94. #endif /* CONFIG_THERMAL_GOV_USER_SPACE */
  95. #ifdef CONFIG_THERMAL_GOV_POWER_ALLOCATOR
  96. int thermal_gov_power_allocator_register(void);
  97. void thermal_gov_power_allocator_unregister(void);
  98. #else
  99. static inline int thermal_gov_power_allocator_register(void) { return 0; }
  100. static inline void thermal_gov_power_allocator_unregister(void) {}
  101. #endif /* CONFIG_THERMAL_GOV_POWER_ALLOCATOR */
  102. /* device tree support */
  103. #ifdef CONFIG_THERMAL_OF
  104. int of_parse_thermal_zones(void);
  105. void of_thermal_destroy_zones(void);
  106. int of_thermal_get_ntrips(struct thermal_zone_device *);
  107. bool of_thermal_is_trip_valid(struct thermal_zone_device *, int);
  108. const struct thermal_trip *
  109. of_thermal_get_trip_points(struct thermal_zone_device *);
  110. #else
  111. static inline int of_parse_thermal_zones(void) { return 0; }
  112. static inline void of_thermal_destroy_zones(void) { }
  113. static inline int of_thermal_get_ntrips(struct thermal_zone_device *tz)
  114. {
  115. return 0;
  116. }
  117. static inline bool of_thermal_is_trip_valid(struct thermal_zone_device *tz,
  118. int trip)
  119. {
  120. return false;
  121. }
  122. static inline const struct thermal_trip *
  123. of_thermal_get_trip_points(struct thermal_zone_device *tz)
  124. {
  125. return NULL;
  126. }
  127. #endif
  128. #endif /* __THERMAL_CORE_H__ */