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