1 /* SPDX-License-Identifier: LGPL-2.1+ */
2 /* Copyright (C) 2022, Linaro Ltd - Daniel Lezcano <daniel.lezcano@linaro.org> */
6 #include <linux/thermal.h>
10 #define LIBTHERMAL_API __attribute__((visibility("default")))
13 #ifndef THERMAL_THRESHOLD_WAY_UP
14 #define THERMAL_THRESHOLD_WAY_UP 0x1
17 #ifndef THERMAL_THRESHOLD_WAY_DOWN
18 #define THERMAL_THRESHOLD_WAY_DOWN 0x2
25 struct thermal_sampling_ops
{
26 int (*tz_temp
)(int tz_id
, int temp
, void *arg
);
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
);
51 struct thermal_sampling_ops sampling
;
52 struct thermal_events_ops events
;
62 struct thermal_threshold
{
70 char name
[THERMAL_NAME_LENGTH
];
71 char governor
[THERMAL_NAME_LENGTH
];
72 struct thermal_trip
*trip
;
73 struct thermal_threshold
*thresholds
;
78 char name
[THERMAL_NAME_LENGTH
];
89 struct thermal_handler
;
91 typedef int (*cb_tz_t
)(struct thermal_zone
*, void *);
93 typedef int (*cb_tt_t
)(struct thermal_trip
*, void *);
95 typedef int (*cb_tc_t
)(struct thermal_cdev
*, void *);
97 typedef int (*cb_th_t
)(struct thermal_threshold
*, void *);
99 LIBTHERMAL_API
int for_each_thermal_zone(struct thermal_zone
*tz
, cb_tz_t cb
, void *arg
);
101 LIBTHERMAL_API
int for_each_thermal_trip(struct thermal_trip
*tt
, cb_tt_t cb
, void *arg
);
103 LIBTHERMAL_API
int for_each_thermal_cdev(struct thermal_cdev
*cdev
, cb_tc_t cb
, void *arg
);
105 LIBTHERMAL_API
int for_each_thermal_threshold(struct thermal_threshold
*th
, cb_th_t cb
, void *arg
);
107 LIBTHERMAL_API
struct thermal_zone
*thermal_zone_find_by_name(struct thermal_zone
*tz
,
110 LIBTHERMAL_API
struct thermal_zone
*thermal_zone_find_by_id(struct thermal_zone
*tz
, int id
);
112 LIBTHERMAL_API
struct thermal_zone
*thermal_zone_discover(struct thermal_handler
*th
);
114 LIBTHERMAL_API
struct thermal_handler
*thermal_init(struct thermal_ops
*ops
);
116 LIBTHERMAL_API
void thermal_exit(struct thermal_handler
*th
);
119 * Netlink thermal events
121 LIBTHERMAL_API thermal_error_t
thermal_events_exit(struct thermal_handler
*th
);
123 LIBTHERMAL_API thermal_error_t
thermal_events_init(struct thermal_handler
*th
);
125 LIBTHERMAL_API thermal_error_t
thermal_events_handle(struct thermal_handler
*th
, void *arg
);
127 LIBTHERMAL_API
int thermal_events_fd(struct thermal_handler
*th
);
130 * Netlink thermal commands
132 LIBTHERMAL_API thermal_error_t
thermal_cmd_exit(struct thermal_handler
*th
);
134 LIBTHERMAL_API thermal_error_t
thermal_cmd_init(struct thermal_handler
*th
);
136 LIBTHERMAL_API thermal_error_t
thermal_cmd_get_tz(struct thermal_handler
*th
,
137 struct thermal_zone
**tz
);
139 LIBTHERMAL_API thermal_error_t
thermal_cmd_get_cdev(struct thermal_handler
*th
,
140 struct thermal_cdev
**tc
);
142 LIBTHERMAL_API thermal_error_t
thermal_cmd_get_trip(struct thermal_handler
*th
,
143 struct thermal_zone
*tz
);
145 LIBTHERMAL_API thermal_error_t
thermal_cmd_get_governor(struct thermal_handler
*th
,
146 struct thermal_zone
*tz
);
148 LIBTHERMAL_API thermal_error_t
thermal_cmd_get_temp(struct thermal_handler
*th
,
149 struct thermal_zone
*tz
);
151 LIBTHERMAL_API thermal_error_t
thermal_cmd_threshold_get(struct thermal_handler
*th
,
152 struct thermal_zone
*tz
);
154 LIBTHERMAL_API thermal_error_t
thermal_cmd_threshold_add(struct thermal_handler
*th
,
155 struct thermal_zone
*tz
,
159 LIBTHERMAL_API thermal_error_t
thermal_cmd_threshold_delete(struct thermal_handler
*th
,
160 struct thermal_zone
*tz
,
164 LIBTHERMAL_API thermal_error_t
thermal_cmd_threshold_flush(struct thermal_handler
*th
,
165 struct thermal_zone
*tz
);
168 * Netlink thermal samples
170 LIBTHERMAL_API thermal_error_t
thermal_sampling_exit(struct thermal_handler
*th
);
172 LIBTHERMAL_API thermal_error_t
thermal_sampling_init(struct thermal_handler
*th
);
174 LIBTHERMAL_API thermal_error_t
thermal_sampling_handle(struct thermal_handler
*th
, void *arg
);
176 LIBTHERMAL_API
int thermal_sampling_fd(struct thermal_handler
*th
);
178 #endif /* __LIBTHERMAL_H */