From patchwork Fri Jul 8 18:32:07 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 588824 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D0AF0C433EF for ; Fri, 8 Jul 2022 18:32:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238905AbiGHScf (ORCPT ); Fri, 8 Jul 2022 14:32:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55140 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239108AbiGHScW (ORCPT ); Fri, 8 Jul 2022 14:32:22 -0400 Received: from mail-wm1-x32d.google.com (mail-wm1-x32d.google.com [IPv6:2a00:1450:4864:20::32d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7640612E for ; Fri, 8 Jul 2022 11:32:21 -0700 (PDT) Received: by mail-wm1-x32d.google.com with SMTP id o16-20020a05600c379000b003a02eaea815so1287955wmr.0 for ; Fri, 08 Jul 2022 11:32:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=8W1S2KUuL89TqEwWGa5XSTCs1irHk/zbJh1P5bOgERI=; b=B0BNs4nOwOtWXpSnh0Sk8e0/yhMsisqXUANXdlv4wV9Ln/BjUKPy5vQf9TWj3QQQ8t Z2tzvB+kZ6ohiPy4eh881B/569E7ujYz3jhxrvuAboW0cEXuOqaKc6UbzEf1d1XfIpcU cLeBVZ2j96Z+9k52a78bHdo4k7SuvKHoRXfalILLU12WA0eqXstzz2rRJxzsfu6Jhc20 7FJtbcylNwMGBLTWpxNPbix5P+hS3aUJDdlsiBHjbPACXeqy5ISqlJP8XoAKpnGQs8DQ oule4vZpMp4nmQ1Kpw18JHtIOxKILK6dqlxpQHx1OxjVsZI1l7zvwgga5CIVcuegkFDw uXbA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=8W1S2KUuL89TqEwWGa5XSTCs1irHk/zbJh1P5bOgERI=; b=vyC9ZfliHMvK/RWOjizW3b+xP9Ve7xvp8uKBDfo2WCTdtrAsDKSVaKu+dY+oASPFGL ScHqpTFsGW0yvBvW+tpl1b/RD/KrQMkpAZbfeO2DYwhCTuFAMZNVpdNaBTpqyMVnBsGo jVur+s7jye1aV7p3NMSNxTs6dk6eMTFvFuba3/MmlCJXZts67kTocXE16osGKRiwKAxl MhOE5pwuJIuAd3yeNw9XhMzXaG/9fg0REbqS1PUt6Um3ygstSTAfT9/DbFI2Hs39fkgS CC8jwUzZzGwunbS1WhBamRPqSjJX8OlpPh/XFzyNIYRSTxfpwvrixFwlIsaUZ9qHDkcP D7tw== X-Gm-Message-State: AJIora/JOW4NOBXQkBJlGUs3q+37kmEhcZOgxRll9+pkB0H9+1vvuoWd pg2Zq03K2nf+nINH+p27QEHWHlO703215A== X-Google-Smtp-Source: AGRyM1vhfGP9ifazaZ9vpI32bu2RGhrdCwI/+vHiooP3kQWcNm3jdvENg1s6UXKL7QCpNTTxr5yomA== X-Received: by 2002:a05:600c:22da:b0:3a0:4e7b:4237 with SMTP id 26-20020a05600c22da00b003a04e7b4237mr1159282wmg.101.1657305139981; Fri, 08 Jul 2022 11:32:19 -0700 (PDT) Received: from localhost.localdomain (146725694.box.freepro.com. [130.180.211.218]) by smtp.gmail.com with ESMTPSA id t9-20020adfeb89000000b0021d887f9468sm4292073wrn.25.2022.07.08.11.32.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Jul 2022 11:32:19 -0700 (PDT) From: Daniel Lezcano To: daniel.lezcano@linaro.org, rafael@kernel.org Cc: quic_manafm@quicinc.com, rui.zhang@intel.com, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, Amit Kucheria Subject: [PATCH v2 1/3] thermal/core: Encapsulate the trip point crossed function Date: Fri, 8 Jul 2022 20:32:07 +0200 Message-Id: <20220708183210.1334839-1-daniel.lezcano@linaro.org> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org The routine where the trip point crossed is detected is a strategic place where different processing will happen. Encapsulate the code in a function, so all specific actions related with a trip point crossed can be grouped. Signed-off-by: Daniel Lezcano Reviewed-by: Lukasz Luba --- drivers/thermal/thermal_core.c | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c index cdc0552e8c42..d9f771b15ed8 100644 --- a/drivers/thermal/thermal_core.c +++ b/drivers/thermal/thermal_core.c @@ -358,6 +358,25 @@ static void handle_critical_trips(struct thermal_zone_device *tz, tz->ops->critical(tz); } +static void handle_thermal_trip_crossed(struct thermal_zone_device *tz, int trip, + int trip_temp, int trip_hyst, enum thermal_trip_type trip_type) +{ + if (tz->last_temperature == THERMAL_TEMP_INVALID) + return; + + if (tz->last_temperature < trip_temp && + tz->temperature >= trip_temp) { + thermal_notify_tz_trip_up(tz->id, trip, + tz->temperature); + } + + if (tz->last_temperature >= trip_temp && + tz->temperature < (trip_temp - trip_hyst)) { + thermal_notify_tz_trip_down(tz->id, trip, + tz->temperature); + } +} + static void handle_thermal_trip(struct thermal_zone_device *tz, int trip) { enum thermal_trip_type type; @@ -372,16 +391,7 @@ static void handle_thermal_trip(struct thermal_zone_device *tz, int trip) if (tz->ops->get_trip_hyst) tz->ops->get_trip_hyst(tz, trip, &hyst); - if (tz->last_temperature != THERMAL_TEMP_INVALID) { - if (tz->last_temperature < trip_temp && - tz->temperature >= trip_temp) - thermal_notify_tz_trip_up(tz->id, trip, - tz->temperature); - if (tz->last_temperature >= trip_temp && - tz->temperature < (trip_temp - hyst)) - thermal_notify_tz_trip_down(tz->id, trip, - tz->temperature); - } + handle_thermal_trip_crossed(tz, trip, trip_temp, hyst, type); if (type == THERMAL_TRIP_CRITICAL || type == THERMAL_TRIP_HOT) handle_critical_trips(tz, trip, type); From patchwork Fri Jul 8 18:32:08 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 588825 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6847CC43334 for ; Fri, 8 Jul 2022 18:32:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239573AbiGHSce (ORCPT ); Fri, 8 Jul 2022 14:32:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55190 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239600AbiGHSc0 (ORCPT ); Fri, 8 Jul 2022 14:32:26 -0400 Received: from mail-wr1-x42a.google.com (mail-wr1-x42a.google.com [IPv6:2a00:1450:4864:20::42a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B75D1292 for ; Fri, 8 Jul 2022 11:32:22 -0700 (PDT) Received: by mail-wr1-x42a.google.com with SMTP id q9so31620067wrd.8 for ; Fri, 08 Jul 2022 11:32:22 -0700 (PDT) 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 :mime-version:content-transfer-encoding; bh=VMSNl4aXxj8gUfbW/Yo0+vXzMXAM2NkamvbFD7ALP70=; b=QHKbQCi/uyJY2HVCVLW0HGvS0E2aoaeSgr3x3Imt2YLi0y71h2t1zN9uGcEY6VnjdG QRSRdvZwq8nmLBsPi6uTOtC6haZK7y9mu3ADhY2Rp0ZBQ8hDTuQGhNUNlVbCB2C9rZsb xr0+YP1HxS8YFwYaJpXDHyYlDjC2u+pwidK6yowECHeeBsaK4/q5H4gO1F8ntpgycIhc 9cY5GyS3nyzEbTXqvgwI5hYzShhK4fgv6Zoqg9kheySsTj4dW5pUs4b82x5Dfbblol5i 7Uhpfv2PI/ddAfSV/lHDAxpBOtJeDtgGcjzdpCpvjhsZRUa99jJ09OjYvlru0xOZ3CNb j63A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=VMSNl4aXxj8gUfbW/Yo0+vXzMXAM2NkamvbFD7ALP70=; b=wHDGAhJ97Lcd7/PsbVJ06GN/H30Ir/6KZfzTA1fxC9CLVAO/rCA7a4m87LP39jFxoc eU+kiEAysFA4VnC3krmq4NH29V2RSS1YzAAJT0wXKyeozTBa9Gj9emCLendvKpSrZE8Z EbFOksIQEgMuPb6wczV+F7LwOZFJeoz0Br2OB5rjb8kIWPe01w3Ru5mIdxUzjANs/MD6 XC1xU6NsCv8ZulpaMGF+VChivt/TAXWmae/ZbrN3kHSVeVSwCFa8nmo8w6VLIKhaWt9P zbWTl0RuHqrfYwNW+Aqmr0INrjTj0NsA86RB0fqAcNnOQMTPcu1LLHXDg4s552CvrTKS /boA== X-Gm-Message-State: AJIora8Au+32PXsa1+BFh1VoO+Om1c5Tg162apVz5z3W5EKV7IFmQXOW 2sHXZNEXGy7BBXq6FwY7GH49rQ== X-Google-Smtp-Source: AGRyM1s8AwjUtL3ElAHbWB460RMjH7JJIOmM/uztVchYIW0xv+5N83lC5cUU2eIyDvrX0ZpkEj/SFg== X-Received: by 2002:adf:e90d:0:b0:21d:6a18:918a with SMTP id f13-20020adfe90d000000b0021d6a18918amr4547628wrm.266.1657305141220; Fri, 08 Jul 2022 11:32:21 -0700 (PDT) Received: from localhost.localdomain (146725694.box.freepro.com. [130.180.211.218]) by smtp.gmail.com with ESMTPSA id t9-20020adfeb89000000b0021d887f9468sm4292073wrn.25.2022.07.08.11.32.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Jul 2022 11:32:20 -0700 (PDT) From: Daniel Lezcano To: daniel.lezcano@linaro.org, rafael@kernel.org Cc: quic_manafm@quicinc.com, rui.zhang@intel.com, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, Amit Kucheria Subject: [PATCH v2 2/3] thermal/core: Passing a parameter instead of calling the function again Date: Fri, 8 Jul 2022 20:32:08 +0200 Message-Id: <20220708183210.1334839-2-daniel.lezcano@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220708183210.1334839-1-daniel.lezcano@linaro.org> References: <20220708183210.1334839-1-daniel.lezcano@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org As the trip temperature is already available when calling the function, pass it as a parameter instead of having the function calling the ops again to retrieve the same data. Signed-off-by: Daniel Lezcano Reviewed-by: Lukasz Luba --- drivers/thermal/thermal_core.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c index d9f771b15ed8..f66036b3daae 100644 --- a/drivers/thermal/thermal_core.c +++ b/drivers/thermal/thermal_core.c @@ -340,12 +340,8 @@ void thermal_zone_device_critical(struct thermal_zone_device *tz) EXPORT_SYMBOL(thermal_zone_device_critical); static void handle_critical_trips(struct thermal_zone_device *tz, - int trip, enum thermal_trip_type trip_type) + int trip, int trip_temp, enum thermal_trip_type trip_type) { - int trip_temp; - - tz->ops->get_trip_temp(tz, trip, &trip_temp); - /* If we have not crossed the trip_temp, we do not care. */ if (trip_temp <= 0 || tz->temperature < trip_temp) return; @@ -394,7 +390,7 @@ static void handle_thermal_trip(struct thermal_zone_device *tz, int trip) handle_thermal_trip_crossed(tz, trip, trip_temp, hyst, type); if (type == THERMAL_TRIP_CRITICAL || type == THERMAL_TRIP_HOT) - handle_critical_trips(tz, trip, type); + handle_critical_trips(tz, trip, trip_temp, type); else handle_non_critical_trips(tz, trip); /* From patchwork Fri Jul 8 18:32:09 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 589701 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 364FFCCA47B for ; Fri, 8 Jul 2022 18:32:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239569AbiGHSce (ORCPT ); Fri, 8 Jul 2022 14:32:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55204 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239619AbiGHSc1 (ORCPT ); Fri, 8 Jul 2022 14:32:27 -0400 Received: from mail-wr1-x42d.google.com (mail-wr1-x42d.google.com [IPv6:2a00:1450:4864:20::42d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 265612AB for ; Fri, 8 Jul 2022 11:32:24 -0700 (PDT) Received: by mail-wr1-x42d.google.com with SMTP id bk26so16552887wrb.11 for ; Fri, 08 Jul 2022 11:32:24 -0700 (PDT) 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 :mime-version:content-transfer-encoding; bh=XZ5izpsJYDjolez1JjolokdZgMS5APgPK6AXFM/yUtk=; b=ATpB/XjbRHEUp6X0XLL7UmTz6sr8zW8pgXZ2Ds/d820Hf6ksIr3fhWzCV40cke5UZm WoLxsWWxUrCclT7H6Zo4cmic1Z0fALbmvflIwiQiao/yMRawfjvMC0gCtUR0cgd+SJCn bm/jk3PQBtZnkgzsaTj2qlAO2OeJjxKlhSmRpR1Zl+cYbsDv2lar4G18Wr4jtOdk03HV aNyRwyNqykmwoy4/GTvwnB6CjP8iOWqPjmqDkXT6JsfgtwTYeQfVm8S6SR8l0x77wI6I T796uEAbtq9NRfMOc4dztQx0VCCGPMxs0gR7nNnckU8HcZCsqHe0rUe9Ex9h+qsWKZpl wzjQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=XZ5izpsJYDjolez1JjolokdZgMS5APgPK6AXFM/yUtk=; b=3FJzV5FvTln2h6YYUqaTS6Eg7NC3ztktrqyJydFJNt64HFG9u/A0moTO54Vj5Y8qaN CudVmrPZIz1gkqq3jhWQcu/YhWSlZbCXsPtNHt2qrhQBUhXqeH95vrn2XDQzCZwiPyk8 le1L7Ldu98YshloFx24MASOQih7LUtPWRwKruBIJ7XtLmRsVyBXg0wSW2AJexUvbeJGr Q1X/3yfMH7A90y9SfnfdhzA6wpnfF8Rvwd605Yw4b3hsUAnxTNadTInZtnfMfqbyFh7l w6RlB8rdihnfHNH6OMgrAZQg7AuJ7I4ly99CEUnlTPcsncLxINSv6Bb8GGTtet6Y0aaB 72UA== X-Gm-Message-State: AJIora8h9IWcHxUBdQPBGKzL23cUcFIDCGAt9fm0qsYLe/j3VOISU7iW Ybr45v8w1a5owItQ8/eDiKOI8w== X-Google-Smtp-Source: AGRyM1ueLiPnRiMss6SWC/rk7k95ovhmqrNmZUy38BSo3+d0I+qvAxBSYnynz6s0J7fANQ8c8fMQWA== X-Received: by 2002:adf:f1d1:0:b0:21d:7f88:d638 with SMTP id z17-20020adff1d1000000b0021d7f88d638mr4719493wro.586.1657305142513; Fri, 08 Jul 2022 11:32:22 -0700 (PDT) Received: from localhost.localdomain (146725694.box.freepro.com. [130.180.211.218]) by smtp.gmail.com with ESMTPSA id t9-20020adfeb89000000b0021d887f9468sm4292073wrn.25.2022.07.08.11.32.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Jul 2022 11:32:22 -0700 (PDT) From: Daniel Lezcano To: daniel.lezcano@linaro.org, rafael@kernel.org Cc: quic_manafm@quicinc.com, rui.zhang@intel.com, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, Amit Kucheria Subject: [PATCH v2 3/3] thermal/core: Fix thermal trip cross point Date: Fri, 8 Jul 2022 20:32:09 +0200 Message-Id: <20220708183210.1334839-3-daniel.lezcano@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220708183210.1334839-1-daniel.lezcano@linaro.org> References: <20220708183210.1334839-1-daniel.lezcano@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org The routine doing trip point crossing the way up or down is actually wrong. A trip point is composed with a trip temperature and a hysteresis. The trip temperature is used to detect when the trip point is crossed the way up. The trip temperature minus the hysteresis is used to detect when the trip point is crossed the way down. |-----------low--------high------------| |<--------->| | hyst | | | | -|--> crossed the way up | <---|-- crossed the way down For that, there is a two point comparison: the current temperature and the previous temperature. The actual code assumes if the current temperature is greater than the trip temperature and the previous temperature was lesser, then the trip point is crossed the way up. That is true only if we crossed the way down the low temperature boundary from the previous temperature or if the hysteresis is zero. The temperature can decrease between the low and high, so the trip point is not crossed the way down and then increase again and cross the high temperature raising a new trip point crossed detection which is incorrect. The same scenario happens when crossing the way down. The trip point crossing the way up and down must act as parenthesis, a trip point down must close a trip point up. Today we have multiple trip point up without the corresponding trip point down. In order to fix that, we store the previous trip point which gives the information about the previous trip and we change the trip point browsing order depending on the temperature trend: in the ascending order when the temperature trend is raising, otherwise in the descending order. As a sidenote, the thermal_zone_device structure has already the prev_trip_low and prev_trip_high information which are used by the thermal_zone_set_trips() function. This one can be changed to be triggered by the trip temperature crossing function, which makes more sense, and the two fields will disappear. Tested on a rk3399-rock960 with thermal stress and 4 trip points. Also tested with temperature emulation to create a temperature jump directly to the second trip point. Signed-off-by: Daniel Lezcano --- V2: - As spotted by Zhang Rui, the trip cross notification does not work if the temperature drops and crosses two trip points in the same update interval. In order to fix that, we browse the trip point in the ascending order when the temperature trend is raising, otherwise in the descending order. --- drivers/thermal/thermal_core.c | 46 +++++++++++++++++++++++++--------- include/linux/thermal.h | 2 ++ 2 files changed, 36 insertions(+), 12 deletions(-) diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c index f66036b3daae..89926e029378 100644 --- a/drivers/thermal/thermal_core.c +++ b/drivers/thermal/thermal_core.c @@ -357,19 +357,35 @@ static void handle_critical_trips(struct thermal_zone_device *tz, static void handle_thermal_trip_crossed(struct thermal_zone_device *tz, int trip, int trip_temp, int trip_hyst, enum thermal_trip_type trip_type) { + int trip_low_temp = trip_temp - trip_hyst; + if (tz->last_temperature == THERMAL_TEMP_INVALID) return; - if (tz->last_temperature < trip_temp && - tz->temperature >= trip_temp) { - thermal_notify_tz_trip_up(tz->id, trip, - tz->temperature); - } - - if (tz->last_temperature >= trip_temp && - tz->temperature < (trip_temp - trip_hyst)) { - thermal_notify_tz_trip_down(tz->id, trip, - tz->temperature); + /* + * Due to the hysteresis, a third information is needed to + * detect when the temperature is wavering between the + * trip_low_temp and the trip_temp. A trip point is crossed + * the way up only if the temperature is above it while the + * previous temperature was below *and* we crossed the + * trip_temp_low before. The previous trip point give us the + * previous trip point transition. The similar problem exists + * when crossing the way down. + * + * Note the mechanism works only if the caller of the function + * invoke the function with the trip point ascending or + * descending regarding the temperature trend. A temperature + * drop trend will browse the trip point in the descending + * order + */ + if (tz->last_temperature < trip_temp && tz->temperature >= trip_temp && + trip != tz->prev_trip) { + thermal_notify_tz_trip_up(tz->id, trip, tz->temperature); + tz->prev_trip = trip; + } else if (tz->last_temperature >= trip_low_temp && tz->temperature < trip_low_temp && + trip == tz->prev_trip) { + thermal_notify_tz_trip_down(tz->id, trip, tz->temperature); + tz->prev_trip = trip - 1; } } @@ -427,6 +443,7 @@ static void thermal_zone_device_init(struct thermal_zone_device *tz) { struct thermal_instance *pos; tz->temperature = THERMAL_TEMP_INVALID; + tz->prev_trip = -1; tz->prev_low_trip = -INT_MAX; tz->prev_high_trip = INT_MAX; list_for_each_entry(pos, &tz->thermal_instances, tz_node) @@ -511,8 +528,13 @@ void thermal_zone_device_update(struct thermal_zone_device *tz, tz->notify_event = event; - for (count = 0; count < tz->trips; count++) - handle_thermal_trip(tz, count); + if (tz->last_temperature <= tz->temperature) { + for (count = 0; count < tz->trips; count++) + handle_thermal_trip(tz, count); + } else { + for (count = tz->prev_trip; count >= 0; count--) + handle_thermal_trip(tz, count); + } } EXPORT_SYMBOL_GPL(thermal_zone_device_update); diff --git a/include/linux/thermal.h b/include/linux/thermal.h index 231bac2768fb..5b3bfb902d10 100644 --- a/include/linux/thermal.h +++ b/include/linux/thermal.h @@ -124,6 +124,7 @@ struct thermal_cooling_device { * @last_temperature: previous temperature read * @emul_temperature: emulated temperature when using CONFIG_THERMAL_EMULATION * @passive: 1 if you've crossed a passive trip point, 0 otherwise. + * @prev_trip: previous trip point the thermal zone was, -1 if below all of them * @prev_low_trip: the low current temperature if you've crossed a passive trip point. * @prev_high_trip: the above current temperature if you've crossed a @@ -159,6 +160,7 @@ struct thermal_zone_device { int last_temperature; int emul_temperature; int passive; + int prev_trip; int prev_low_trip; int prev_high_trip; atomic_t need_update;