at v6.19 182 lines 5.9 kB view raw
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#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 22extern "C" { 23#endif 24 25struct thermal_sampling_ops { 26 int (*tz_temp)(int tz_id, int temp, void *arg); 27}; 28 29struct 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 50struct thermal_ops { 51 struct thermal_sampling_ops sampling; 52 struct thermal_events_ops events; 53}; 54 55struct thermal_trip { 56 int id; 57 int type; 58 int temp; 59 int hyst; 60}; 61 62struct thermal_threshold { 63 int temperature; 64 int direction; 65}; 66 67struct 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 76struct 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 84typedef enum { 85 THERMAL_ERROR = -1, 86 THERMAL_SUCCESS = 0, 87} thermal_error_t; 88 89struct thermal_handler; 90 91typedef int (*cb_tz_t)(struct thermal_zone *, void *); 92 93typedef int (*cb_tt_t)(struct thermal_trip *, void *); 94 95typedef int (*cb_tc_t)(struct thermal_cdev *, void *); 96 97typedef int (*cb_th_t)(struct thermal_threshold *, void *); 98 99LIBTHERMAL_API int for_each_thermal_zone(struct thermal_zone *tz, cb_tz_t cb, void *arg); 100 101LIBTHERMAL_API int for_each_thermal_trip(struct thermal_trip *tt, cb_tt_t cb, void *arg); 102 103LIBTHERMAL_API int for_each_thermal_cdev(struct thermal_cdev *cdev, cb_tc_t cb, void *arg); 104 105LIBTHERMAL_API int for_each_thermal_threshold(struct thermal_threshold *th, cb_th_t cb, void *arg); 106 107LIBTHERMAL_API struct thermal_zone *thermal_zone_find_by_name(struct thermal_zone *tz, 108 const char *name); 109 110LIBTHERMAL_API struct thermal_zone *thermal_zone_find_by_id(struct thermal_zone *tz, int id); 111 112LIBTHERMAL_API struct thermal_zone *thermal_zone_discover(struct thermal_handler *th); 113 114LIBTHERMAL_API struct thermal_handler *thermal_init(struct thermal_ops *ops); 115 116LIBTHERMAL_API void thermal_exit(struct thermal_handler *th); 117 118/* 119 * Netlink thermal events 120 */ 121LIBTHERMAL_API thermal_error_t thermal_events_exit(struct thermal_handler *th); 122 123LIBTHERMAL_API thermal_error_t thermal_events_init(struct thermal_handler *th); 124 125LIBTHERMAL_API thermal_error_t thermal_events_handle(struct thermal_handler *th, void *arg); 126 127LIBTHERMAL_API int thermal_events_fd(struct thermal_handler *th); 128 129/* 130 * Netlink thermal commands 131 */ 132LIBTHERMAL_API thermal_error_t thermal_cmd_exit(struct thermal_handler *th); 133 134LIBTHERMAL_API thermal_error_t thermal_cmd_init(struct thermal_handler *th); 135 136LIBTHERMAL_API thermal_error_t thermal_cmd_get_tz(struct thermal_handler *th, 137 struct thermal_zone **tz); 138 139LIBTHERMAL_API thermal_error_t thermal_cmd_get_cdev(struct thermal_handler *th, 140 struct thermal_cdev **tc); 141 142LIBTHERMAL_API thermal_error_t thermal_cmd_get_trip(struct thermal_handler *th, 143 struct thermal_zone *tz); 144 145LIBTHERMAL_API thermal_error_t thermal_cmd_get_governor(struct thermal_handler *th, 146 struct thermal_zone *tz); 147 148LIBTHERMAL_API thermal_error_t thermal_cmd_get_temp(struct thermal_handler *th, 149 struct thermal_zone *tz); 150 151LIBTHERMAL_API thermal_error_t thermal_cmd_threshold_get(struct thermal_handler *th, 152 struct thermal_zone *tz); 153 154LIBTHERMAL_API thermal_error_t thermal_cmd_threshold_add(struct thermal_handler *th, 155 struct thermal_zone *tz, 156 int temperature, 157 int direction); 158 159LIBTHERMAL_API thermal_error_t thermal_cmd_threshold_delete(struct thermal_handler *th, 160 struct thermal_zone *tz, 161 int temperature, 162 int direction); 163 164LIBTHERMAL_API thermal_error_t thermal_cmd_threshold_flush(struct thermal_handler *th, 165 struct thermal_zone *tz); 166 167/* 168 * Netlink thermal samples 169 */ 170LIBTHERMAL_API thermal_error_t thermal_sampling_exit(struct thermal_handler *th); 171 172LIBTHERMAL_API thermal_error_t thermal_sampling_init(struct thermal_handler *th); 173 174LIBTHERMAL_API thermal_error_t thermal_sampling_handle(struct thermal_handler *th, void *arg); 175 176LIBTHERMAL_API int thermal_sampling_fd(struct thermal_handler *th); 177 178#endif /* __LIBTHERMAL_H */ 179 180#ifdef __cplusplus 181} 182#endif