Implement an optional callback function for thermal sensors to set a trip
authorkettenis <kettenis@openbsd.org>
Thu, 27 Jun 2024 09:37:07 +0000 (09:37 +0000)
committerkettenis <kettenis@openbsd.org>
Thu, 27 Jun 2024 09:37:07 +0000 (09:37 +0000)
limit to support thermal zones that don't do polling.  Thermal sensor
drivers should implement this callback if they can generate an interrupt
when the trop limit is reached and should call thermal_senser_update()
when that happens.

ok dlg@

sys/dev/ofw/ofw_thermal.c
sys/dev/ofw/ofw_thermal.h

index 5c42992..3e7ab68 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: ofw_thermal.c,v 1.8 2023/11/23 00:47:13 dlg Exp $     */
+/*     $OpenBSD: ofw_thermal.c,v 1.9 2024/06/27 09:37:07 kettenis Exp $        */
 /*
  * Copyright (c) 2019 Mark Kettenis
  *
@@ -160,6 +160,23 @@ thermal_get_temperature_cells(uint32_t *cells)
        return THERMAL_SENSOR_MAX;
 }
 
+int
+thermal_set_limit_cells(uint32_t *cells, uint32_t temp)
+{
+       struct thermal_sensor *ts;
+       uint32_t phandle = cells[0];
+
+       LIST_FOREACH(ts, &thermal_sensors, ts_list) {
+               if (ts->ts_phandle == phandle)
+                       break;
+       }
+
+       if (ts && ts->ts_set_limit)
+               return ts->ts_set_limit(ts->ts_cookie, &cells[1], temp);
+
+       return ENXIO;
+}
+
 void
 thermal_zone_poll_timeout(void *arg)
 {
@@ -352,7 +369,11 @@ out:
                polling_delay = tz->tz_polling_delay_passive;
        else
                polling_delay = tz->tz_polling_delay;
-       timeout_add_msec(&tz->tz_poll_to, polling_delay);
+
+       if (polling_delay > 0)
+               timeout_add_msec(&tz->tz_poll_to, polling_delay);
+       else
+               thermal_set_limit_cells(tz->tz_sensors, tp->tp_temperature);
 }
 
 static int
@@ -497,14 +518,14 @@ thermal_zone_init(int node)
                cm++;
        }
 
-       /* Start polling if we are requested to do so. */
-       if (tz->tz_polling_delay > 0)
-               timeout_add_msec(&tz->tz_poll_to, tz->tz_polling_delay);
        LIST_INSERT_HEAD(&thermal_zones, tz, tz_list);
 
 #if NKSTAT > 0
        thermal_zone_kstat_attach(tz);
 #endif
+
+       /* Poll once to get things going. */
+       thermal_zone_poll(tz);
 }
 
 void
index 21c6304..aa24e09 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: ofw_thermal.h,v 1.2 2020/01/23 23:10:04 kettenis Exp $        */
+/*     $OpenBSD: ofw_thermal.h,v 1.3 2024/06/27 09:37:07 kettenis Exp $        */
 /*
  * Copyright (c) 2019 Mark Kettenis
  *
@@ -23,6 +23,7 @@ struct thermal_sensor {
        void    *ts_cookie;
 
        int32_t (*ts_get_temperature)(void *, uint32_t *);
+       int     (*ts_set_limit)(void *, uint32_t *, uint32_t);
 
        LIST_ENTRY(thermal_sensor) ts_list;
        uint32_t ts_phandle;