From: kettenis Date: Thu, 27 Jun 2024 09:37:07 +0000 (+0000) Subject: Implement an optional callback function for thermal sensors to set a trip X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=689107618d66b902cd58f715f9ac5d71f392fefc;p=openbsd Implement an optional callback function for thermal sensors to set a trip 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@ --- diff --git a/sys/dev/ofw/ofw_thermal.c b/sys/dev/ofw/ofw_thermal.c index 5c42992407c..3e7ab68136d 100644 --- a/sys/dev/ofw/ofw_thermal.c +++ b/sys/dev/ofw/ofw_thermal.c @@ -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 diff --git a/sys/dev/ofw/ofw_thermal.h b/sys/dev/ofw/ofw_thermal.h index 21c63041bd7..aa24e090292 100644 --- a/sys/dev/ofw/ofw_thermal.h +++ b/sys/dev/ofw/ofw_thermal.h @@ -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;