thermal.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  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. #include <linux/thermal.h>
  6. #include <sys/types.h>
  7. #ifndef LIBTHERMAL_API
  8. #define LIBTHERMAL_API __attribute__((visibility("default")))
  9. #endif
  10. #ifndef THERMAL_THRESHOLD_WAY_UP
  11. #define THERMAL_THRESHOLD_WAY_UP 0x1
  12. #endif
  13. #ifndef THERMAL_THRESHOLD_WAY_DOWN
  14. #define THERMAL_THRESHOLD_WAY_DOWN 0x2
  15. #endif
  16. #ifdef __cplusplus
  17. extern "C" {
  18. #endif
  19. struct thermal_sampling_ops {
  20. int (*tz_temp)(int tz_id, int temp, void *arg);
  21. };
  22. struct thermal_events_ops {
  23. int (*tz_create)(const char *name, int tz_id, void *arg);
  24. int (*tz_delete)(int tz_id, void *arg);
  25. int (*tz_enable)(int tz_id, void *arg);
  26. int (*tz_disable)(int tz_id, void *arg);
  27. int (*trip_high)(int tz_id, int trip_id, int temp, void *arg);
  28. int (*trip_low)(int tz_id, int trip_id, int temp, void *arg);
  29. int (*trip_add)(int tz_id, int trip_id, int type, int temp, int hyst, void *arg);
  30. int (*trip_change)(int tz_id, int trip_id, int type, int temp, int hyst, void *arg);
  31. int (*trip_delete)(int tz_id, int trip_id, void *arg);
  32. int (*cdev_add)(const char *name, int cdev_id, int max_state, void *arg);
  33. int (*cdev_delete)(int cdev_id, void *arg);
  34. int (*cdev_update)(int cdev_id, int cur_state, void *arg);
  35. int (*gov_change)(int tz_id, const char *gov_name, void *arg);
  36. int (*threshold_add)(int tz_id, int temperature, int direction, void *arg);
  37. int (*threshold_delete)(int tz_id, int temperature, int direction, void *arg);
  38. int (*threshold_flush)(int tz_id, void *arg);
  39. int (*threshold_up)(int tz_id, int temp, int prev_temp, void *arg);
  40. int (*threshold_down)(int tz_id, int temp, int prev_temp, void *arg);
  41. };
  42. struct thermal_ops {
  43. struct thermal_sampling_ops sampling;
  44. struct thermal_events_ops events;
  45. };
  46. struct thermal_trip {
  47. int id;
  48. int type;
  49. int temp;
  50. int hyst;
  51. };
  52. struct thermal_threshold {
  53. int temperature;
  54. int direction;
  55. };
  56. struct thermal_zone {
  57. int id;
  58. int temp;
  59. char name[THERMAL_NAME_LENGTH];
  60. char governor[THERMAL_NAME_LENGTH];
  61. struct thermal_trip *trip;
  62. struct thermal_threshold *thresholds;
  63. };
  64. struct thermal_cdev {
  65. int id;
  66. char name[THERMAL_NAME_LENGTH];
  67. int max_state;
  68. int min_state;
  69. int cur_state;
  70. };
  71. typedef enum {
  72. THERMAL_ERROR = -1,
  73. THERMAL_SUCCESS = 0,
  74. } thermal_error_t;
  75. struct thermal_handler;
  76. typedef int (*cb_tz_t)(struct thermal_zone *, void *);
  77. typedef int (*cb_tt_t)(struct thermal_trip *, void *);
  78. typedef int (*cb_tc_t)(struct thermal_cdev *, void *);
  79. typedef int (*cb_th_t)(struct thermal_threshold *, void *);
  80. LIBTHERMAL_API int for_each_thermal_zone(struct thermal_zone *tz, cb_tz_t cb, void *arg);
  81. LIBTHERMAL_API int for_each_thermal_trip(struct thermal_trip *tt, cb_tt_t cb, void *arg);
  82. LIBTHERMAL_API int for_each_thermal_cdev(struct thermal_cdev *cdev, cb_tc_t cb, void *arg);
  83. LIBTHERMAL_API int for_each_thermal_threshold(struct thermal_threshold *th, cb_th_t cb, void *arg);
  84. LIBTHERMAL_API struct thermal_zone *thermal_zone_find_by_name(struct thermal_zone *tz,
  85. const char *name);
  86. LIBTHERMAL_API struct thermal_zone *thermal_zone_find_by_id(struct thermal_zone *tz, int id);
  87. LIBTHERMAL_API struct thermal_zone *thermal_zone_discover(struct thermal_handler *th);
  88. LIBTHERMAL_API struct thermal_handler *thermal_init(struct thermal_ops *ops);
  89. LIBTHERMAL_API void thermal_exit(struct thermal_handler *th);
  90. /*
  91. * Netlink thermal events
  92. */
  93. LIBTHERMAL_API thermal_error_t thermal_events_exit(struct thermal_handler *th);
  94. LIBTHERMAL_API thermal_error_t thermal_events_init(struct thermal_handler *th);
  95. LIBTHERMAL_API thermal_error_t thermal_events_handle(struct thermal_handler *th, void *arg);
  96. LIBTHERMAL_API int thermal_events_fd(struct thermal_handler *th);
  97. /*
  98. * Netlink thermal commands
  99. */
  100. LIBTHERMAL_API thermal_error_t thermal_cmd_exit(struct thermal_handler *th);
  101. LIBTHERMAL_API thermal_error_t thermal_cmd_init(struct thermal_handler *th);
  102. LIBTHERMAL_API thermal_error_t thermal_cmd_get_tz(struct thermal_handler *th,
  103. struct thermal_zone **tz);
  104. LIBTHERMAL_API thermal_error_t thermal_cmd_get_cdev(struct thermal_handler *th,
  105. struct thermal_cdev **tc);
  106. LIBTHERMAL_API thermal_error_t thermal_cmd_get_trip(struct thermal_handler *th,
  107. struct thermal_zone *tz);
  108. LIBTHERMAL_API thermal_error_t thermal_cmd_get_governor(struct thermal_handler *th,
  109. struct thermal_zone *tz);
  110. LIBTHERMAL_API thermal_error_t thermal_cmd_get_temp(struct thermal_handler *th,
  111. struct thermal_zone *tz);
  112. LIBTHERMAL_API thermal_error_t thermal_cmd_threshold_get(struct thermal_handler *th,
  113. struct thermal_zone *tz);
  114. LIBTHERMAL_API thermal_error_t thermal_cmd_threshold_add(struct thermal_handler *th,
  115. struct thermal_zone *tz,
  116. int temperature,
  117. int direction);
  118. LIBTHERMAL_API thermal_error_t thermal_cmd_threshold_delete(struct thermal_handler *th,
  119. struct thermal_zone *tz,
  120. int temperature,
  121. int direction);
  122. LIBTHERMAL_API thermal_error_t thermal_cmd_threshold_flush(struct thermal_handler *th,
  123. struct thermal_zone *tz);
  124. /*
  125. * Netlink thermal samples
  126. */
  127. LIBTHERMAL_API thermal_error_t thermal_sampling_exit(struct thermal_handler *th);
  128. LIBTHERMAL_API thermal_error_t thermal_sampling_init(struct thermal_handler *th);
  129. LIBTHERMAL_API thermal_error_t thermal_sampling_handle(struct thermal_handler *th, void *arg);
  130. LIBTHERMAL_API int thermal_sampling_fd(struct thermal_handler *th);
  131. #endif /* __LIBTHERMAL_H */
  132. #ifdef __cplusplus
  133. }
  134. #endif