xref: /linux/tools/lib/thermal/include/thermal.h (revision fd7d598270724cc787982ea48bbe17ad383a8b7f)
1 /* SPDX-License-Identifier: LGPL-2.1+ */
2 /* Copyright (C) 2022, Linaro Ltd - Daniel Lezcano <daniel.lezcano@linaro.org> */
3 #ifndef __LIBTHERMAL_H
4 #define __LIBTHERMAL_H
5 
6 #include <linux/thermal.h>
7 
8 #ifndef LIBTHERMAL_API
9 #define LIBTHERMAL_API __attribute__((visibility("default")))
10 #endif
11 
12 #ifdef __cplusplus
13 extern "C" {
14 #endif
15 
16 struct thermal_sampling_ops {
17 	int (*tz_temp)(int tz_id, int temp, void *arg);
18 };
19 
20 struct thermal_events_ops {
21 	int (*tz_create)(const char *name, int tz_id, void *arg);
22 	int (*tz_delete)(int tz_id, void *arg);
23 	int (*tz_enable)(int tz_id, void *arg);
24 	int (*tz_disable)(int tz_id, void *arg);
25 	int (*trip_high)(int tz_id, int trip_id, int temp, void *arg);
26 	int (*trip_low)(int tz_id, int trip_id, int temp, void *arg);
27 	int (*trip_add)(int tz_id, int trip_id, int type, int temp, int hyst, void *arg);
28 	int (*trip_change)(int tz_id, int trip_id, int type, int temp, int hyst, void *arg);
29 	int (*trip_delete)(int tz_id, int trip_id, void *arg);
30 	int (*cdev_add)(const char *name, int cdev_id, int max_state, void *arg);
31 	int (*cdev_delete)(int cdev_id, void *arg);
32 	int (*cdev_update)(int cdev_id, int cur_state, void *arg);
33 	int (*gov_change)(int tz_id, const char *gov_name, void *arg);
34 };
35 
36 struct thermal_ops {
37 	struct thermal_sampling_ops sampling;
38 	struct thermal_events_ops events;
39 };
40 
41 struct thermal_trip {
42 	int id;
43 	int type;
44 	int temp;
45 	int hyst;
46 };
47 
48 struct thermal_zone {
49 	int id;
50 	int temp;
51 	char name[THERMAL_NAME_LENGTH];
52 	char governor[THERMAL_NAME_LENGTH];
53 	struct thermal_trip *trip;
54 };
55 
56 struct thermal_cdev {
57 	int id;
58 	char name[THERMAL_NAME_LENGTH];
59 	int max_state;
60 	int min_state;
61 	int cur_state;
62 };
63 
64 typedef enum {
65 	THERMAL_ERROR = -1,
66 	THERMAL_SUCCESS = 0,
67 } thermal_error_t;
68 
69 struct thermal_handler;
70 
71 typedef int (*cb_tz_t)(struct thermal_zone *, void *);
72 
73 typedef int (*cb_tt_t)(struct thermal_trip *, void *);
74 
75 typedef int (*cb_tc_t)(struct thermal_cdev *, void *);
76 
77 LIBTHERMAL_API int for_each_thermal_zone(struct thermal_zone *tz, cb_tz_t cb, void *arg);
78 
79 LIBTHERMAL_API int for_each_thermal_trip(struct thermal_trip *tt, cb_tt_t cb, void *arg);
80 
81 LIBTHERMAL_API int for_each_thermal_cdev(struct thermal_cdev *cdev, cb_tc_t cb, void *arg);
82 
83 LIBTHERMAL_API struct thermal_zone *thermal_zone_find_by_name(struct thermal_zone *tz,
84 							      const char *name);
85 
86 LIBTHERMAL_API struct thermal_zone *thermal_zone_find_by_id(struct thermal_zone *tz, int id);
87 
88 LIBTHERMAL_API struct thermal_zone *thermal_zone_discover(struct thermal_handler *th);
89 
90 LIBTHERMAL_API struct thermal_handler *thermal_init(struct thermal_ops *ops);
91 
92 LIBTHERMAL_API void thermal_exit(struct thermal_handler *th);
93 
94 /*
95  * Netlink thermal events
96  */
97 LIBTHERMAL_API thermal_error_t thermal_events_exit(struct thermal_handler *th);
98 
99 LIBTHERMAL_API thermal_error_t thermal_events_init(struct thermal_handler *th);
100 
101 LIBTHERMAL_API thermal_error_t thermal_events_handle(struct thermal_handler *th, void *arg);
102 
103 LIBTHERMAL_API int thermal_events_fd(struct thermal_handler *th);
104 
105 /*
106  * Netlink thermal commands
107  */
108 LIBTHERMAL_API thermal_error_t thermal_cmd_exit(struct thermal_handler *th);
109 
110 LIBTHERMAL_API thermal_error_t thermal_cmd_init(struct thermal_handler *th);
111 
112 LIBTHERMAL_API thermal_error_t thermal_cmd_get_tz(struct thermal_handler *th,
113 						  struct thermal_zone **tz);
114 
115 LIBTHERMAL_API thermal_error_t thermal_cmd_get_cdev(struct thermal_handler *th,
116 						    struct thermal_cdev **tc);
117 
118 LIBTHERMAL_API thermal_error_t thermal_cmd_get_trip(struct thermal_handler *th,
119 						    struct thermal_zone *tz);
120 
121 LIBTHERMAL_API thermal_error_t thermal_cmd_get_governor(struct thermal_handler *th,
122 							struct thermal_zone *tz);
123 
124 LIBTHERMAL_API thermal_error_t thermal_cmd_get_temp(struct thermal_handler *th,
125 						    struct thermal_zone *tz);
126 
127 /*
128  * Netlink thermal samples
129  */
130 LIBTHERMAL_API thermal_error_t thermal_sampling_exit(struct thermal_handler *th);
131 
132 LIBTHERMAL_API thermal_error_t thermal_sampling_init(struct thermal_handler *th);
133 
134 LIBTHERMAL_API thermal_error_t thermal_sampling_handle(struct thermal_handler *th, void *arg);
135 
136 LIBTHERMAL_API int thermal_sampling_fd(struct thermal_handler *th);
137 
138 #endif /* __LIBTHERMAL_H */
139 
140 #ifdef __cplusplus
141 }
142 #endif
143