Debian Codegraph @

tools/lib/thermal/include/thermal.h

raw
1 /* SPDX-License-Identifier: LGPL-2.1+ */
2 /* Copyright (C) 2022, Linaro Ltd - Daniel Lezcano <[email protected]> */
3 #ifndef __LIBTHERMAL_H
4 #define __LIBTHERMAL_H
5
6 #include <linux/thermal.h>
7 #include <sys/types.h>
8
9 #ifndef LIBTHERMAL_API
10 #define LIBTHERMAL_API __attribute__((visibility("default")))
11 #endif
12
13 #ifndef THERMAL_THRESHOLD_WAY_UP
14 #define THERMAL_THRESHOLD_WAY_UP 0x1
15 #endif
16
17 #ifndef THERMAL_THRESHOLD_WAY_DOWN
18 #define THERMAL_THRESHOLD_WAY_DOWN 0x2
19 #endif
20
21 #ifdef __cplusplus
22 extern "C" {
23 #endif
24
25 struct thermal_sampling_ops {
26 int (*tz_temp)(int tz_id, int temp, void *arg);
27 };
28
29 struct thermal_events_ops {
30 int (*tz_create)(const char *name, int tz_id, void *arg);
31 int (*tz_delete)(int tz_id, void *arg);
32 int (*tz_enable)(int tz_id, void *arg);
33 int (*tz_disable)(int tz_id, void *arg);
34 int (*trip_high)(int tz_id, int trip_id, int temp, void *arg);
35 int (*trip_low)(int tz_id, int trip_id, int temp, void *arg);
36 int (*trip_add)(int tz_id, int trip_id, int type, int temp, int hyst, void *arg);
37 int (*trip_change)(int tz_id, int trip_id, int type, int temp, int hyst, void *arg);
38 int (*trip_delete)(int tz_id, int trip_id, void *arg);
39 int (*cdev_add)(const char *name, int cdev_id, int max_state, void *arg);
40 int (*cdev_delete)(int cdev_id, void *arg);
41 int (*cdev_update)(int cdev_id, int cur_state, void *arg);
42 int (*gov_change)(int tz_id, const char *gov_name, void *arg);
43 int (*threshold_add)(int tz_id, int temperature, int direction, void *arg);
44 int (*threshold_delete)(int tz_id, int temperature, int direction, void *arg);
45 int (*threshold_flush)(int tz_id, void *arg);
46 int (*threshold_up)(int tz_id, int temp, int prev_temp, void *arg);
47 int (*threshold_down)(int tz_id, int temp, int prev_temp, void *arg);
48 };
49
50 struct thermal_ops {
51 struct thermal_sampling_ops sampling;
52 struct thermal_events_ops events;
53 };
54
55 struct thermal_trip {
56 int id;
57 int type;
58 int temp;
59 int hyst;
60 };
61
62 struct thermal_threshold {
63 int temperature;
64 int direction;
65 };
66
67 struct thermal_zone {
68 int id;
69 int temp;
70 char name[THERMAL_NAME_LENGTH];
71 char governor[THERMAL_NAME_LENGTH];
72 struct thermal_trip *trip;
73 struct thermal_threshold *thresholds;
74 };
75
76 struct thermal_cdev {
77 int id;
78 char name[THERMAL_NAME_LENGTH];
79 int max_state;
80 int min_state;
81 int cur_state;
82 };
83
84 typedef enum {
85 THERMAL_ERROR = -1,
86 THERMAL_SUCCESS = 0,
87 } thermal_error_t;
88
89 struct thermal_handler;
90
91 typedef int (*cb_tz_t)(struct thermal_zone *, void *);
92
93 typedef int (*cb_tt_t)(struct thermal_trip *, void *);
94
95 typedef int (*cb_tc_t)(struct thermal_cdev *, void *);
96
97 typedef int (*cb_th_t)(struct thermal_threshold *, void *);
98
99 LIBTHERMAL_API int for_each_thermal_zone(struct thermal_zone *tz, cb_tz_t cb, void *arg);
100
101 LIBTHERMAL_API int for_each_thermal_trip(struct thermal_trip *tt, cb_tt_t cb, void *arg);
102
103 LIBTHERMAL_API int for_each_thermal_cdev(struct thermal_cdev *cdev, cb_tc_t cb, void *arg);
104
105 LIBTHERMAL_API int for_each_thermal_threshold(struct thermal_threshold *th, cb_th_t cb, void *arg);
106
107 LIBTHERMAL_API struct thermal_zone *thermal_zone_find_by_name(struct thermal_zone *tz,
108 const char *name);
109
110 LIBTHERMAL_API struct thermal_zone *thermal_zone_find_by_id(struct thermal_zone *tz, int id);
111
112 LIBTHERMAL_API struct thermal_zone *thermal_zone_discover(struct thermal_handler *th);
113
114 LIBTHERMAL_API struct thermal_handler *thermal_init(struct thermal_ops *ops);
115
116 LIBTHERMAL_API void thermal_exit(struct thermal_handler *th);
117
118 /*
119 * Netlink thermal events
120 */
121 LIBTHERMAL_API thermal_error_t thermal_events_exit(struct thermal_handler *th);
122
123 LIBTHERMAL_API thermal_error_t thermal_events_init(struct thermal_handler *th);
124
125 LIBTHERMAL_API thermal_error_t thermal_events_handle(struct thermal_handler *th, void *arg);
126
127 LIBTHERMAL_API int thermal_events_fd(struct thermal_handler *th);
128
129 /*
130 * Netlink thermal commands
131 */
132 LIBTHERMAL_API thermal_error_t thermal_cmd_exit(struct thermal_handler *th);
133
134 LIBTHERMAL_API thermal_error_t thermal_cmd_init(struct thermal_handler *th);
135
136 LIBTHERMAL_API thermal_error_t thermal_cmd_get_tz(struct thermal_handler *th,
137 struct thermal_zone **tz);
138
139 LIBTHERMAL_API thermal_error_t thermal_cmd_get_cdev(struct thermal_handler *th,
140 struct thermal_cdev **tc);
141
142 LIBTHERMAL_API thermal_error_t thermal_cmd_get_trip(struct thermal_handler *th,
143 struct thermal_zone *tz);
144
145 LIBTHERMAL_API thermal_error_t thermal_cmd_get_governor(struct thermal_handler *th,
146 struct thermal_zone *tz);
147
148 LIBTHERMAL_API thermal_error_t thermal_cmd_get_temp(struct thermal_handler *th,
149 struct thermal_zone *tz);
150
151 LIBTHERMAL_API thermal_error_t thermal_cmd_threshold_get(struct thermal_handler *th,
152 struct thermal_zone *tz);
153
154 LIBTHERMAL_API thermal_error_t thermal_cmd_threshold_add(struct thermal_handler *th,
155 struct thermal_zone *tz,
156 int temperature,
157 int direction);
158
159 LIBTHERMAL_API thermal_error_t thermal_cmd_threshold_delete(struct thermal_handler *th,
160 struct thermal_zone *tz,
161 int temperature,
162 int direction);
163
164 LIBTHERMAL_API thermal_error_t thermal_cmd_threshold_flush(struct thermal_handler *th,
165 struct thermal_zone *tz);
166
167 /*
168 * Netlink thermal samples
169 */
170 LIBTHERMAL_API thermal_error_t thermal_sampling_exit(struct thermal_handler *th);
171
172 LIBTHERMAL_API thermal_error_t thermal_sampling_init(struct thermal_handler *th);
173
174 LIBTHERMAL_API thermal_error_t thermal_sampling_handle(struct thermal_handler *th, void *arg);
175
176 LIBTHERMAL_API int thermal_sampling_fd(struct thermal_handler *th);
177
178 #endif /* __LIBTHERMAL_H */
179
180 #ifdef __cplusplus
181 }
182 #endif