From patchwork Thu Dec 10 12:15:11 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 341026 Delivered-To: patch@linaro.org Received: by 2002:a17:906:4755:0:0:0:0 with SMTP id j21csp5578232ejs; Thu, 10 Dec 2020 04:16:52 -0800 (PST) X-Google-Smtp-Source: ABdhPJy9ln4sr8t6E1+AMJCWzAGrNGLlojs6rh6BJgvzBYf/AUXvqPW3qUv4I9M0nKLTY8UCxXD/ X-Received: by 2002:a17:906:660b:: with SMTP id b11mr6115719ejp.190.1607602612492; Thu, 10 Dec 2020 04:16:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1607602612; cv=none; d=google.com; s=arc-20160816; b=Wcz/stB/VHDeMOfTb5g6mOz6tibL4+cXAsesOeGin0Xm35KK3MmJySEZ/WMsxRvzOz xerV9nvPkChnt1Xixv6znpH0kZdESErv1tWMqGv80o9QE90pcTDYbl8r35PQjB38dI2Z LaV7OdnDCCaG+1UkV1vz4m/nKlLqyMQGFqgshwcNSdPIKulJ9ovi+uNLQNP5DzUAdrFn ORG79qT/bScAjV1jLR99qczvyc1wsujhNEVpGN10KdKSm9hTKlh7rfoV7M4ZIShBu5eI ny2Y2y0mhcp7NXJLDxoNZWVXjsluIXNBzgCNao2/0UoLrkjwlUlQtYy4ZC6N6qoxFG8u 5EHg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from:dkim-signature; bh=sIEMz7Oh+NWa+Qwh/WPljIwoa+Kn6l6xd1Uhgr069Qo=; b=OIE8OUM4OYjBMX5K02POi9KihK9DHpU80qh3eIG3bYYxyGmE5Il/Rskr9ZFDeLvRma KdQD5WE1pWYr2v7Iarz36tXDPn8P/DxzFf8c5wfZlWedGtPwqsYG1oUAcbQCDk/TBH2H 7yRRCawleAphCiUMR8TPew46RDmCFulKjqOnjQEOhjkVMBpmxIYPfa6Pm4mEyo+SnpPm 7wsRIgoq2C7XbApyH0LvqdFfmJIjmPe22eTWbOVYTXoRTBiR3F95wnGN77MCVzKY84fe pHMgL3CyWUFMcGKaWe39ia+J3lY7S9a8G22ZLZbkCSbHE8YPwUVjgy4o6lsKPjtuy/2X ro4w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=h+9IWBD0; spf=pass (google.com: domain of linux-pm-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-pm-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id m26si2402535ejc.513.2020.12.10.04.16.52; Thu, 10 Dec 2020 04:16:52 -0800 (PST) Received-SPF: pass (google.com: domain of linux-pm-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=h+9IWBD0; spf=pass (google.com: domain of linux-pm-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-pm-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387959AbgLJMQO (ORCPT + 8 others); Thu, 10 Dec 2020 07:16:14 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40038 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732802AbgLJMQM (ORCPT ); Thu, 10 Dec 2020 07:16:12 -0500 Received: from mail-wr1-x432.google.com (mail-wr1-x432.google.com [IPv6:2a00:1450:4864:20::432]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 578CBC0617A7 for ; Thu, 10 Dec 2020 04:15:25 -0800 (PST) Received: by mail-wr1-x432.google.com with SMTP id w5so1497767wrm.11 for ; Thu, 10 Dec 2020 04:15:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=sIEMz7Oh+NWa+Qwh/WPljIwoa+Kn6l6xd1Uhgr069Qo=; b=h+9IWBD0VCOj0c+WRowkqukSHO6NNcODBxCwwcCLw+o947GXqI8T58UrtbqQDr69tj eX1ApUWPCVwnah1uWIVdb0RpPROdeLKUw9j9++JB1YjkKDWfcjD7Fvv1d1FCnmvmHZx1 MH7WI6Qfmg1Gc1RRntSDA6yqyzOPJPlqZN9Mq3fsFH0K2USK3SXrCadcxTl7NuNvcQWn KJRWmAhAaZJm0paD6PzpuVUDEKTyNecD/Rm01g6GrjBln2Ik2AAelJHyg8SHXau4XrGr fpN1lz8PWdWSG91Qy3o1lgkA8tV3mAdTkQy6WlRlE0j1TVcZmNgcxCpMzeOQVNYaq8wK 11tA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=sIEMz7Oh+NWa+Qwh/WPljIwoa+Kn6l6xd1Uhgr069Qo=; b=ZyLYCMj9fhLfvrndQMi1WOQdOdho2mk5qyzIJuNZHt1hePKQeJwpW5mGthTrtsYYhK FmB322zE7oV9h4hGksPsvCOwpwnGUgSRUT+3Ve4TZSHq0EQBmueuSy9kJVzuoPFTeF5Q bfckA5IIwVBk88/lN4S7+DumNppN2Kovc1lrbs/HtXOGRI0sakOqf+/IjH+zxIjgiWAj kLcmamJEy+T23n4NgcOG/+7JMUAxynvAx8rB5+sUsmVdI3CeIg+obicQ9yyhT+QV8D0z dlq80YiAFoOyNU9ZHwWpUAzz1vhAFBDnN66y6u1rqFn1zszNQmCszOCoN+yjUj33bBzR B+DA== X-Gm-Message-State: AOAM532cDdtfPf0XOr1wmXzipTriYPjVCZnc0/DMfP/4FzvezGVFOC0b IbQCzSM4kilJdQykDNSeszlztg== X-Received: by 2002:a5d:4209:: with SMTP id n9mr7787886wrq.128.1607602524017; Thu, 10 Dec 2020 04:15:24 -0800 (PST) Received: from localhost.localdomain (lns-bzn-59-82-252-158-132.adsl.proxad.net. [82.252.158.132]) by smtp.gmail.com with ESMTPSA id k6sm8412863wmf.25.2020.12.10.04.15.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Dec 2020 04:15:23 -0800 (PST) From: Daniel Lezcano To: daniel.lezcano@linaro.org, rui.zhang@intel.com Cc: kai.heng.feng@canonical.com, lukasz.luba@arm.com, srinivas.pandruvada@linux.intel.com, linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, Amit Kucheria Subject: [PATCH 2/5] thermal/core: Add critical and hot ops Date: Thu, 10 Dec 2020 13:15:11 +0100 Message-Id: <20201210121514.25760-2-daniel.lezcano@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201210121514.25760-1-daniel.lezcano@linaro.org> References: <20201210121514.25760-1-daniel.lezcano@linaro.org> Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org Currently there is no way to the sensors to directly call an ops in interrupt mode without calling thermal_zone_device_update assuming all the trip points are defined. A sensor may want to do something special if a trip point is hot or critical. This patch adds the critical and hot ops to the thermal zone device, so a sensor can directly invoke them or let the thermal framework to call the sensor specific ones. Tested-by: Kai-Heng Feng Signed-off-by: Daniel Lezcano --- drivers/thermal/thermal_core.c | 43 +++++++++++++++++++++------------- include/linux/thermal.h | 3 +++ 2 files changed, 30 insertions(+), 16 deletions(-) -- 2.17.1 Reviewed-by: Lukasz Luba diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c index e6771e5aeedb..cee0b31b5cd7 100644 --- a/drivers/thermal/thermal_core.c +++ b/drivers/thermal/thermal_core.c @@ -375,6 +375,25 @@ static void thermal_emergency_poweroff(void) msecs_to_jiffies(poweroff_delay_ms)); } +void thermal_zone_device_critical(struct thermal_zone_device *tz) +{ + dev_emerg(&tz->device, "%s: critical temperature reached, " + "shutting down\n", tz->type); + + mutex_lock(&poweroff_lock); + if (!power_off_triggered) { + /* + * Queue a backup emergency shutdown in the event of + * orderly_poweroff failure + */ + thermal_emergency_poweroff(); + orderly_poweroff(true); + power_off_triggered = true; + } + mutex_unlock(&poweroff_lock); +} +EXPORT_SYMBOL(thermal_zone_device_critical); + static void handle_critical_trips(struct thermal_zone_device *tz, int trip, enum thermal_trip_type trip_type) { @@ -391,22 +410,10 @@ static void handle_critical_trips(struct thermal_zone_device *tz, if (tz->ops->notify) tz->ops->notify(tz, trip, trip_type); - if (trip_type == THERMAL_TRIP_CRITICAL) { - dev_emerg(&tz->device, - "critical temperature reached (%d C), shutting down\n", - tz->temperature / 1000); - mutex_lock(&poweroff_lock); - if (!power_off_triggered) { - /* - * Queue a backup emergency shutdown in the event of - * orderly_poweroff failure - */ - thermal_emergency_poweroff(); - orderly_poweroff(true); - power_off_triggered = true; - } - mutex_unlock(&poweroff_lock); - } + if (trip_type == THERMAL_TRIP_HOT && tz->ops->hot) + tz->ops->hot(tz); + else if (trip_type == THERMAL_TRIP_CRITICAL) + tz->ops->critical(tz); } static void handle_thermal_trip(struct thermal_zone_device *tz, int trip) @@ -1331,6 +1338,10 @@ thermal_zone_device_register(const char *type, int trips, int mask, tz->id = id; strlcpy(tz->type, type, sizeof(tz->type)); + + if (!ops->critical) + ops->critical = thermal_zone_device_critical; + tz->ops = ops; tz->tzp = tzp; tz->device.class = &thermal_class; diff --git a/include/linux/thermal.h b/include/linux/thermal.h index f23a388ded15..125c8a4d52e6 100644 --- a/include/linux/thermal.h +++ b/include/linux/thermal.h @@ -79,6 +79,8 @@ struct thermal_zone_device_ops { enum thermal_trend *); int (*notify) (struct thermal_zone_device *, int, enum thermal_trip_type); + void (*hot)(struct thermal_zone_device *); + void (*critical)(struct thermal_zone_device *); }; struct thermal_cooling_device_ops { @@ -399,6 +401,7 @@ void thermal_cdev_update(struct thermal_cooling_device *); void thermal_notify_framework(struct thermal_zone_device *, int); int thermal_zone_device_enable(struct thermal_zone_device *tz); int thermal_zone_device_disable(struct thermal_zone_device *tz); +void thermal_zone_device_critical(struct thermal_zone_device *tz); #else static inline struct thermal_zone_device *thermal_zone_device_register( const char *type, int trips, int mask, void *devdata,