summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Lezcano <daniel.lezcano@linaro.org>2021-05-02 22:46:03 +0200
committerDaniel Lezcano <daniel.lezcano@linaro.org>2021-05-02 22:46:03 +0200
commitb9b3813eff450a27b811bba35693f89d70e2ab4d (patch)
tree1f96def4f6623d7cd4d8229570e8ba21eb98f8e9
parentfdc3b39e44278e95e0fd02d7a6793dcb6f6d09fd (diff)
Add finding functions by id and by name
Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
-rw-r--r--src/libthermal/thermal.c31
-rw-r--r--src/libthermal/thermal.h4
2 files changed, 35 insertions, 0 deletions
diff --git a/src/libthermal/thermal.c b/src/libthermal/thermal.c
index bbf9693..93a92b5 100644
--- a/src/libthermal/thermal.c
+++ b/src/libthermal/thermal.c
@@ -31,6 +31,37 @@ int for_each_thermal_zone(struct thermal_zone *tz, cb_tz_t cb, void *arg)
return ret;
}
+struct thermal_zone *thermal_zone_find_by_name(struct thermal_zone *tz,
+ const char *name)
+{
+ int i;
+
+ if (!name)
+ return NULL;
+
+ for (i = 0; tz[i].id != -1; i++) {
+ if (!strcmp(tz[i].name, name))
+ return &tz[i];
+ }
+
+ return NULL;
+}
+
+struct thermal_zone *thermal_zone_find_by_id(struct thermal_zone *tz, int id)
+{
+ int i;
+
+ if (id < 0)
+ return NULL;
+
+ for (i = 0; tz[i].id != -1; i++) {
+ if (tz[i].id == id)
+ return &tz[i];
+ }
+
+ return NULL;
+}
+
static int __thermal_zone_discover(struct thermal_zone *tz, void *th)
{
if (thermal_cmd_get_trip(th, tz) < 0)
diff --git a/src/libthermal/thermal.h b/src/libthermal/thermal.h
index e89a3ba..21d779d 100644
--- a/src/libthermal/thermal.h
+++ b/src/libthermal/thermal.h
@@ -95,6 +95,10 @@ int for_each_thermal_trip(struct thermal_trip *tt, cb_tt_t cb, void *arg);
int for_each_thermal_cdev(struct thermal_cdev *cdev, cb_tc_t cb, void *arg);
+struct thermal_zone *thermal_zone_find_by_name(struct thermal_zone *tz, const char *name);
+
+struct thermal_zone *thermal_zone_find_by_id(struct thermal_zone *tz, int id);
+
struct thermal_zone *thermal_zone_discover(struct thermal_handler *th);
struct thermal_handler *thermal_init(struct thermal_ops *ops);