[PATCH v3 5/6] thermal: of: Parse aggregation property to select the aggegration type

From: Alexandre Bailon
Date: Fri May 24 2024 - 10:33:09 EST


This updates the driver to parse the aggegration property in DT.
This allows selecting the aggregation function to apply for multi
sensors thermal zone.

Signed-off-by: Alexandre Bailon <abailon@xxxxxxxxxxxx>
---
drivers/thermal/thermal_of.c | 32 ++++++++++++++++++++++++++++++++
1 file changed, 32 insertions(+)

diff --git a/drivers/thermal/thermal_of.c b/drivers/thermal/thermal_of.c
index 75e3cfb8488a..21c81dc91a41 100644
--- a/drivers/thermal/thermal_of.c
+++ b/drivers/thermal/thermal_of.c
@@ -533,6 +533,33 @@ static void thermal_of_zone_unregister(struct thermal_zone_device *tz)
thermal_zone_device_unregister(tz);
}

+static const char * const aggr_types[] = {
+ [THERMAL_AGGR_AVG] = "avg",
+ [THERMAL_AGGR_MAX] = "max",
+};
+
+static int thermal_of_multi_sensor_get_type(struct device_node *np,
+ enum thermal_aggregation_type *type)
+{
+ const char *t;
+ int err, i;
+
+ err = of_property_read_string(np, "aggregation", &t);
+ if (err < 0) {
+ *type = THERMAL_AGGR_AVG;
+ return 0;
+ }
+
+ for (i = 0; i < ARRAY_SIZE(aggr_types); i++) {
+ if (!strcasecmp(t, aggr_types[i])) {
+ *type = i;
+ return 0;
+ }
+ }
+
+ return -EINVAL;
+}
+
static int thermal_of_multi_sensor_validate_coeff(struct device_node *sensor, int id,
struct device_node *tz_np)
{
@@ -606,6 +633,7 @@ thermal_of_register_multi_tz(struct device_node *sensor, int id, struct device_n
int polling_delay)
{
struct thermal_zone_device *multi_tz, *tz;
+ enum thermal_aggregation_type aggr_type;
char name[THERMAL_NAME_LENGTH];
u32 coeff;
int ret;
@@ -614,6 +642,10 @@ thermal_of_register_multi_tz(struct device_node *sensor, int id, struct device_n
if (!multi_tz) {
struct thermal_zone_device_ops *multi_ops;

+ ret = thermal_of_multi_sensor_get_type(np, &aggr_type);
+ if (ret)
+ return ERR_PTR(ret);
+
ret = thermal_of_multi_sensor_validate_coeff(sensor, id, np);
if (ret)
return ERR_PTR(ret);
--
2.44.1