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 | ||
5b8de18e DL |
55 | int __for_each_thermal_trip(struct thermal_zone_device *, |
56 | int (*cb)(struct thermal_trip *, void *), | |
57 | void *); | |
58 | ||
329b064f DL |
59 | struct thermal_zone_device *thermal_zone_get_by_id(int id); |
60 | ||
c68df440 DL |
61 | struct thermal_attr { |
62 | struct device_attribute attr; | |
63 | char name[THERMAL_NAME_LENGTH]; | |
64 | }; | |
65 | ||
33a88af1 DL |
66 | static inline bool cdev_is_power_actor(struct thermal_cooling_device *cdev) |
67 | { | |
68 | return cdev->ops->get_requested_power && cdev->ops->state2power && | |
69 | cdev->ops->power2state; | |
70 | } | |
71 | ||
23ff8529 | 72 | void thermal_cdev_update(struct thermal_cooling_device *); |
b70dbf40 | 73 | void __thermal_cdev_update(struct thermal_cooling_device *cdev); |
23ff8529 | 74 | |
f0129c23 DL |
75 | int get_tz_trend(struct thermal_zone_device *tz, int trip); |
76 | ||
06f1041f DL |
77 | struct thermal_instance * |
78 | get_thermal_instance(struct thermal_zone_device *tz, | |
79 | struct thermal_cooling_device *cdev, | |
80 | int trip); | |
81 | ||
71350db4 D |
82 | /* |
83 | * This structure is used to describe the behavior of | |
84 | * a certain cooling device on a certain trip point | |
85 | * in a certain thermal zone | |
86 | */ | |
87 | struct thermal_instance { | |
88 | int id; | |
89 | char name[THERMAL_NAME_LENGTH]; | |
90 | struct thermal_zone_device *tz; | |
91 | struct thermal_cooling_device *cdev; | |
92 | int trip; | |
bb431ba2 | 93 | bool initialized; |
71350db4 D |
94 | unsigned long upper; /* Highest cooling state for this trip point */ |
95 | unsigned long lower; /* Lowest cooling state for this trip point */ | |
96 | unsigned long target; /* expected cooling state */ | |
97 | char attr_name[THERMAL_NAME_LENGTH]; | |
98 | struct device_attribute attr; | |
db916513 JM |
99 | char weight_attr_name[THERMAL_NAME_LENGTH]; |
100 | struct device_attribute weight_attr; | |
71350db4 D |
101 | struct list_head tz_node; /* node in tz->thermal_instances */ |
102 | struct list_head cdev_node; /* node in cdev->thermal_instances */ | |
6cd9e9f6 | 103 | unsigned int weight; /* The weight of the cooling device */ |
790930f4 | 104 | bool upper_no_limit; |
71350db4 D |
105 | }; |
106 | ||
ba78da44 EV |
107 | #define to_thermal_zone(_dev) \ |
108 | container_of(_dev, struct thermal_zone_device, device) | |
109 | ||
99ea2eff EV |
110 | #define to_cooling_device(_dev) \ |
111 | container_of(_dev, struct thermal_cooling_device, device) | |
112 | ||
80a26a5c ZR |
113 | int thermal_register_governor(struct thermal_governor *); |
114 | void thermal_unregister_governor(struct thermal_governor *); | |
6b885202 | 115 | int thermal_zone_device_set_policy(struct thermal_zone_device *, char *); |
97d2423b | 116 | int thermal_build_list_of_policies(char *buf); |
05eeee2b GR |
117 | void __thermal_zone_device_update(struct thermal_zone_device *tz, |
118 | enum thermal_notify_event event); | |
80a26a5c | 119 | |
bceb5646 | 120 | /* Helpers */ |
a930da9b | 121 | void __thermal_zone_set_trips(struct thermal_zone_device *tz); |
7c3d5c20 DL |
122 | int __thermal_zone_get_trip(struct thermal_zone_device *tz, int trip_id, |
123 | struct thermal_trip *trip); | |
a930da9b | 124 | int __thermal_zone_get_temp(struct thermal_zone_device *tz, int *temp); |
bceb5646 | 125 | |
a369ee88 EV |
126 | /* sysfs I/F */ |
127 | int thermal_zone_create_device_groups(struct thermal_zone_device *, int); | |
32fa5ba3 | 128 | void thermal_zone_destroy_device_groups(struct thermal_zone_device *); |
45cf2ec9 | 129 | void thermal_cooling_device_setup_sysfs(struct thermal_cooling_device *); |
8ea22951 | 130 | void thermal_cooling_device_destroy_sysfs(struct thermal_cooling_device *cdev); |
790930f4 | 131 | void thermal_cooling_device_stats_reinit(struct thermal_cooling_device *cdev); |
45cf2ec9 | 132 | /* used only at binding time */ |
33e678d4 VK |
133 | ssize_t trip_point_show(struct device *, struct device_attribute *, char *); |
134 | ssize_t weight_show(struct device *, struct device_attribute *, char *); | |
135 | ssize_t weight_store(struct device *, struct device_attribute *, const char *, | |
136 | size_t); | |
a369ee88 | 137 | |
8ea22951 VK |
138 | #ifdef CONFIG_THERMAL_STATISTICS |
139 | void thermal_cooling_device_stats_update(struct thermal_cooling_device *cdev, | |
140 | unsigned long new_state); | |
141 | #else | |
142 | static inline void | |
143 | thermal_cooling_device_stats_update(struct thermal_cooling_device *cdev, | |
144 | unsigned long new_state) {} | |
145 | #endif /* CONFIG_THERMAL_STATISTICS */ | |
146 | ||
4e5e4705 | 147 | /* device tree support */ |
514acd00 AP |
148 | int thermal_zone_device_is_enabled(struct thermal_zone_device *tz); |
149 | ||
71350db4 | 150 | #endif /* __THERMAL_CORE_H__ */ |