]>
Commit | Line | Data |
---|---|---|
7e3c0381 | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
71350db4 D |
2 | /* |
3 | * thermal_core.h | |
4 | * | |
5 | * Copyright (C) 2012 Intel Corp | |
6 | * Author: Durgadoss R <durgadoss.r@intel.com> | |
71350db4 D |
7 | */ |
8 | ||
9 | #ifndef __THERMAL_CORE_H__ | |
10 | #define __THERMAL_CORE_H__ | |
11 | ||
12 | #include <linux/device.h> | |
13 | #include <linux/thermal.h> | |
14 | ||
5b8583d3 DL |
15 | #include "thermal_netlink.h" |
16 | ||
8097db40 DL |
17 | /* Default Thermal Governor */ |
18 | #if defined(CONFIG_THERMAL_DEFAULT_GOV_STEP_WISE) | |
19 | #define DEFAULT_THERMAL_GOVERNOR "step_wise" | |
20 | #elif defined(CONFIG_THERMAL_DEFAULT_GOV_FAIR_SHARE) | |
21 | #define DEFAULT_THERMAL_GOVERNOR "fair_share" | |
22 | #elif defined(CONFIG_THERMAL_DEFAULT_GOV_USER_SPACE) | |
23 | #define DEFAULT_THERMAL_GOVERNOR "user_space" | |
24 | #elif defined(CONFIG_THERMAL_DEFAULT_GOV_POWER_ALLOCATOR) | |
25 | #define DEFAULT_THERMAL_GOVERNOR "power_allocator" | |
26 | #endif | |
27 | ||
71350db4 D |
28 | /* Initial state of a cooling device during binding */ |
29 | #define THERMAL_NO_TARGET -1UL | |
30 | ||
980af75e DL |
31 | /* Init section thermal table */ |
32 | extern struct thermal_governor *__governor_thermal_table[]; | |
33 | extern struct thermal_governor *__governor_thermal_table_end[]; | |
34 | ||
35 | #define THERMAL_TABLE_ENTRY(table, name) \ | |
36 | static typeof(name) *__thermal_table_entry_##name \ | |
33def849 | 37 | __used __section("__" #table "_thermal_table") = &name |
980af75e DL |
38 | |
39 | #define THERMAL_GOVERNOR_DECLARE(name) THERMAL_TABLE_ENTRY(governor, name) | |
40 | ||
41 | #define for_each_governor_table(__governor) \ | |
42 | for (__governor = __governor_thermal_table; \ | |
43 | __governor < __governor_thermal_table_end; \ | |
44 | __governor++) | |
45 | ||
3d44a509 DL |
46 | int for_each_thermal_zone(int (*cb)(struct thermal_zone_device *, void *), |
47 | void *); | |
48 | ||
49 | int for_each_thermal_cooling_device(int (*cb)(struct thermal_cooling_device *, | |
50 | void *), void *); | |
51 | ||
52 | int for_each_thermal_governor(int (*cb)(struct thermal_governor *, void *), | |
53 | void *thermal_governor); | |
54 | ||
329b064f DL |
55 | struct thermal_zone_device *thermal_zone_get_by_id(int id); |
56 | ||
c68df440 DL |
57 | struct thermal_attr { |
58 | struct device_attribute attr; | |
59 | char name[THERMAL_NAME_LENGTH]; | |
60 | }; | |
61 | ||
33a88af1 DL |
62 | static inline bool cdev_is_power_actor(struct thermal_cooling_device *cdev) |
63 | { | |
64 | return cdev->ops->get_requested_power && cdev->ops->state2power && | |
65 | cdev->ops->power2state; | |
66 | } | |
67 | ||
23ff8529 | 68 | void thermal_cdev_update(struct thermal_cooling_device *); |
b70dbf40 | 69 | void __thermal_cdev_update(struct thermal_cooling_device *cdev); |
23ff8529 | 70 | |
2e7700dc DL |
71 | /** |
72 | * struct thermal_trip - representation of a point in temperature domain | |
73 | * @np: pointer to struct device_node that this trip point was created from | |
74 | * @temperature: temperature value in miliCelsius | |
75 | * @hysteresis: relative hysteresis in miliCelsius | |
76 | * @type: trip point type | |
77 | */ | |
78 | struct thermal_trip { | |
79 | struct device_node *np; | |
80 | int temperature; | |
81 | int hysteresis; | |
82 | enum thermal_trip_type type; | |
83 | }; | |
33a88af1 | 84 | |
f0129c23 DL |
85 | int get_tz_trend(struct thermal_zone_device *tz, int trip); |
86 | ||
06f1041f DL |
87 | struct thermal_instance * |
88 | get_thermal_instance(struct thermal_zone_device *tz, | |
89 | struct thermal_cooling_device *cdev, | |
90 | int trip); | |
91 | ||
71350db4 D |
92 | /* |
93 | * This structure is used to describe the behavior of | |
94 | * a certain cooling device on a certain trip point | |
95 | * in a certain thermal zone | |
96 | */ | |
97 | struct thermal_instance { | |
98 | int id; | |
99 | char name[THERMAL_NAME_LENGTH]; | |
100 | struct thermal_zone_device *tz; | |
101 | struct thermal_cooling_device *cdev; | |
102 | int trip; | |
bb431ba2 | 103 | bool initialized; |
71350db4 D |
104 | unsigned long upper; /* Highest cooling state for this trip point */ |
105 | unsigned long lower; /* Lowest cooling state for this trip point */ | |
106 | unsigned long target; /* expected cooling state */ | |
107 | char attr_name[THERMAL_NAME_LENGTH]; | |
108 | struct device_attribute attr; | |
db916513 JM |
109 | char weight_attr_name[THERMAL_NAME_LENGTH]; |
110 | struct device_attribute weight_attr; | |
71350db4 D |
111 | struct list_head tz_node; /* node in tz->thermal_instances */ |
112 | struct list_head cdev_node; /* node in cdev->thermal_instances */ | |
6cd9e9f6 | 113 | unsigned int weight; /* The weight of the cooling device */ |
71350db4 D |
114 | }; |
115 | ||
ba78da44 EV |
116 | #define to_thermal_zone(_dev) \ |
117 | container_of(_dev, struct thermal_zone_device, device) | |
118 | ||
99ea2eff EV |
119 | #define to_cooling_device(_dev) \ |
120 | container_of(_dev, struct thermal_cooling_device, device) | |
121 | ||
80a26a5c ZR |
122 | int thermal_register_governor(struct thermal_governor *); |
123 | void thermal_unregister_governor(struct thermal_governor *); | |
6b885202 | 124 | int thermal_zone_device_set_policy(struct thermal_zone_device *, char *); |
97d2423b | 125 | int thermal_build_list_of_policies(char *buf); |
80a26a5c | 126 | |
bceb5646 DL |
127 | /* Helpers */ |
128 | void thermal_zone_set_trips(struct thermal_zone_device *tz); | |
17d399cd | 129 | void thermal_set_delay_jiffies(unsigned long *delay_jiffies, int delay_ms); |
bceb5646 | 130 | |
a369ee88 EV |
131 | /* sysfs I/F */ |
132 | int thermal_zone_create_device_groups(struct thermal_zone_device *, int); | |
32fa5ba3 | 133 | void thermal_zone_destroy_device_groups(struct thermal_zone_device *); |
45cf2ec9 | 134 | void thermal_cooling_device_setup_sysfs(struct thermal_cooling_device *); |
8ea22951 | 135 | void thermal_cooling_device_destroy_sysfs(struct thermal_cooling_device *cdev); |
45cf2ec9 | 136 | /* used only at binding time */ |
33e678d4 VK |
137 | ssize_t trip_point_show(struct device *, struct device_attribute *, char *); |
138 | ssize_t weight_show(struct device *, struct device_attribute *, char *); | |
139 | ssize_t weight_store(struct device *, struct device_attribute *, const char *, | |
140 | size_t); | |
a369ee88 | 141 | |
8ea22951 VK |
142 | #ifdef CONFIG_THERMAL_STATISTICS |
143 | void thermal_cooling_device_stats_update(struct thermal_cooling_device *cdev, | |
144 | unsigned long new_state); | |
145 | #else | |
146 | static inline void | |
147 | thermal_cooling_device_stats_update(struct thermal_cooling_device *cdev, | |
148 | unsigned long new_state) {} | |
149 | #endif /* CONFIG_THERMAL_STATISTICS */ | |
150 | ||
4e5e4705 EV |
151 | /* device tree support */ |
152 | #ifdef CONFIG_THERMAL_OF | |
153 | int of_parse_thermal_zones(void); | |
08dab66e | 154 | int of_thermal_get_ntrips(struct thermal_zone_device *); |
a9bf2cc4 | 155 | bool of_thermal_is_trip_valid(struct thermal_zone_device *, int); |
ebc3193a | 156 | const struct thermal_trip * |
ce8be778 | 157 | of_thermal_get_trip_points(struct thermal_zone_device *); |
4e5e4705 EV |
158 | #else |
159 | static inline int of_parse_thermal_zones(void) { return 0; } | |
08dab66e LM |
160 | static inline int of_thermal_get_ntrips(struct thermal_zone_device *tz) |
161 | { | |
162 | return 0; | |
163 | } | |
a9bf2cc4 LM |
164 | static inline bool of_thermal_is_trip_valid(struct thermal_zone_device *tz, |
165 | int trip) | |
166 | { | |
ce1d9491 | 167 | return false; |
a9bf2cc4 | 168 | } |
ebc3193a | 169 | static inline const struct thermal_trip * |
ce8be778 LM |
170 | of_thermal_get_trip_points(struct thermal_zone_device *tz) |
171 | { | |
172 | return NULL; | |
173 | } | |
4e5e4705 EV |
174 | #endif |
175 | ||
514acd00 AP |
176 | int thermal_zone_device_is_enabled(struct thermal_zone_device *tz); |
177 | ||
71350db4 | 178 | #endif /* __THERMAL_CORE_H__ */ |