thermal.h 4.1 KB

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