1 // SPDX-License-Identifier: LGPL-2.1+
2 // Copyright (C) 2022, Linaro Ltd - Daniel Lezcano <daniel.lezcano@linaro.org>
7 #include "thermal_nl.h"
9 int for_each_thermal_threshold(struct thermal_threshold
*th
, cb_th_t cb
, void *arg
)
16 for (i
= 0; th
[i
].temperature
!= INT_MAX
; i
++)
17 ret
|= cb(&th
[i
], arg
);
22 int for_each_thermal_cdev(struct thermal_cdev
*cdev
, cb_tc_t cb
, void *arg
)
29 for (i
= 0; cdev
[i
].id
!= -1; i
++)
30 ret
|= cb(&cdev
[i
], arg
);
35 int for_each_thermal_trip(struct thermal_trip
*tt
, cb_tt_t cb
, void *arg
)
42 for (i
= 0; tt
[i
].id
!= -1; i
++)
43 ret
|= cb(&tt
[i
], arg
);
48 int for_each_thermal_zone(struct thermal_zone
*tz
, cb_tz_t cb
, void *arg
)
55 for (i
= 0; tz
[i
].id
!= -1; i
++)
56 ret
|= cb(&tz
[i
], arg
);
61 struct thermal_zone
*thermal_zone_find_by_name(struct thermal_zone
*tz
,
69 for (i
= 0; tz
[i
].id
!= -1; i
++) {
70 if (!strcmp(tz
[i
].name
, name
))
77 struct thermal_zone
*thermal_zone_find_by_id(struct thermal_zone
*tz
, int id
)
84 for (i
= 0; tz
[i
].id
!= -1; i
++) {
92 static int __thermal_zone_discover(struct thermal_zone
*tz
, void *th
)
94 if (thermal_cmd_get_trip(th
, tz
) < 0)
97 if (thermal_cmd_threshold_get(th
, tz
))
100 if (thermal_cmd_get_governor(th
, tz
))
106 struct thermal_zone
*thermal_zone_discover(struct thermal_handler
*th
)
108 struct thermal_zone
*tz
;
110 if (thermal_cmd_get_tz(th
, &tz
) < 0)
113 if (for_each_thermal_zone(tz
, __thermal_zone_discover
, th
))
119 void thermal_exit(struct thermal_handler
*th
)
121 thermal_cmd_exit(th
);
122 thermal_events_exit(th
);
123 thermal_sampling_exit(th
);
128 struct thermal_handler
*thermal_init(struct thermal_ops
*ops
)
130 struct thermal_handler
*th
;
132 th
= malloc(sizeof(*th
));
137 if (thermal_events_init(th
))
140 if (thermal_sampling_init(th
))
143 if (thermal_cmd_init(th
))