From patchwork Tue Feb 7 13:56:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mikko Perttunen X-Patchwork-Id: 53920 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:2388:b0:96:219d:e725 with SMTP id i8csp4036208dyf; Tue, 7 Feb 2023 06:22:25 -0800 (PST) X-Google-Smtp-Source: AK7set8CHomzl81pMA4UiBA3AcYXwEzXkbHwWkXkEwq+L6bS0dCQDoKoNLehOQqY9RDIuEMHwjq+ X-Received: by 2002:a17:906:36d9:b0:870:b950:18d4 with SMTP id b25-20020a17090636d900b00870b95018d4mr3418069ejc.5.1675779745648; Tue, 07 Feb 2023 06:22:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675779745; cv=none; d=google.com; s=arc-20160816; b=Yyk6lyf+JbXFgy22DLxtPLrxa7+lgEqaHtg3NyumMro5Ky84ayVFjgqdnFr9RycfIw Frfhh8kCGXQgAcX/bdSLDfb13JmNO/lVoRKfvrhtA4eTYWKkATW9ZWOqRuMT2kraV8kR ICgAA5tU+aR/CzArHNMcqPbPN/XCQ7gsyy7JvpotlEWtdD4QjTP2mTUKBXPIQCsSNNPY YBv5BSgJPDucqu2a98VgZAlfpWmT6D/6oVkfWDVdXcQAyOB5lrkYwgqMGy8tcTO+2SQN Yol9QJyVDjuquDkbKutuD3Wi60oBkW44Rd/3GUUoQ3Zh5FY6Q/8v0j6smhLUPIjkgyNM m+Sg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=Zrg3IByCp0PW4pKucv9m4DlG3g7aMkiLevmwDY/gzvE=; b=serv0bDvJa2S2ygECFljVkDERzSOSMdJLelKA17SckjNuJWuKRTuhYxMDS5zpnA7ah mXvM6X6krrzovVib0Zf38kjLuuL91BPCYyKUp//52NSRzuXak/WTE4lpoRhVToGzqEMp tEA5V5tl8mddGBHoiW6nP8X99xWtYEx7Nx79sls12sqoww3Uyi8z9EPJDY2NcTm+TyHf e6BRTM3lQc05zyfLOf90d4pI8jMsR7HhPeBFBLSxZixJxOyWiFPWNjT+3H3lqLZ1NzZH aQwZO7CUQrDbgcyWrHh1INRMYulERfSk2HItDCkItGlspSfCmrIgCTvcUOP5rIJR4Ybv qFQA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@kapsi.fi header.s=20161220 header.b=Yv381XU6; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kapsi.fi Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ui5-20020a170907c90500b008877ef4e222si16374850ejc.411.2023.02.07.06.22.02; Tue, 07 Feb 2023 06:22:25 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=fail header.i=@kapsi.fi header.s=20161220 header.b=Yv381XU6; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kapsi.fi Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232280AbjBGORv (ORCPT + 99 others); Tue, 7 Feb 2023 09:17:51 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58440 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229441AbjBGORu (ORCPT ); Tue, 7 Feb 2023 09:17:50 -0500 X-Greylist: delayed 1254 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Tue, 07 Feb 2023 06:17:47 PST Received: from mail.kapsi.fi (mail.kapsi.fi [IPv6:2001:67c:1be8::25]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E933C2884A; Tue, 7 Feb 2023 06:17:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=kapsi.fi; s=20161220; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=Zrg3IByCp0PW4pKucv9m4DlG3g7aMkiLevmwDY/gzvE=; b=Yv381XU684DE4Rs0fSCgJIYiYj 3laAxXmTYSWyMYdozopx/SZwY9ye8H4r05BjptXLZDstz13Jt64EHOxhQH8kAuufolwfpyFLx3gwk BMP/M4KDj/3O+5bjybx4oOGz1BBcQNPbO9lLQRUAB24sKL+vutxmYd4Q/PIPa+U572nGOFCbnxa2b A+Zv5rYx9C8njUZ6DaLPs6H2ExlketAqxVD3mOjjhEVkazHiuPnIvkfQ8KJ7ZRp08dnVV1iw0+lvN INHBTZTIeyjTr0wq/LGEWdLwPTZtfwc1KQ8FKNNAXYM3kfCouJxos1jV9CDHO1MN/smeq0G7zySQW wFT4UIAA==; Received: from 91-158-25-70.elisa-laajakaista.fi ([91.158.25.70] helo=toshino.localdomain) by mail.kapsi.fi with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1pPOSV-002qTL-Tk; Tue, 07 Feb 2023 15:56:31 +0200 From: Mikko Perttunen To: "Rafael J. Wysocki" , Daniel Lezcano , Amit Kucheria , Zhang Rui , Thierry Reding , Jonathan Hunter , Srikar Srimath Tirumala Cc: Mikko Perttunen , Timo Alho , linux-pm@vger.kernel.org, linux-tegra@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/2] thermal: tegra-bpmp: Always (re)program trip temperatures Date: Tue, 7 Feb 2023 15:56:09 +0200 Message-Id: <20230207135610.3100865-2-cyndis@kapsi.fi> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230207135610.3100865-1-cyndis@kapsi.fi> References: <20230207135610.3100865-1-cyndis@kapsi.fi> MIME-Version: 1.0 X-SA-Exim-Connect-IP: 91.158.25.70 X-SA-Exim-Mail-From: cyndis@kapsi.fi X-SA-Exim-Scanned: No (on mail.kapsi.fi); SAEximRunCond expanded to false X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1757182422242737914?= X-GMAIL-MSGID: =?utf-8?q?1757182422242737914?= From: Mikko Perttunen In the rare case that calculation of trip temperatures would result in the same trip temperatures that were previously programmed, the thermal core skips calling .set_trips. However, presently, if it is not called, we may end up with no trip temperatures programmed at all. To avoid this, make set_trips a no-op and in places where it would be called, instead unconditionally program trip temperatures to the last specified temperatures. This also fixes the situation where a trip is triggered between registering a thermal zone and registering the trip MRQ handler, in which case we would also get stuck. Signed-off-by: Mikko Perttunen --- drivers/thermal/tegra/tegra-bpmp-thermal.c | 33 +++++++++++++++++++--- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/drivers/thermal/tegra/tegra-bpmp-thermal.c b/drivers/thermal/tegra/tegra-bpmp-thermal.c index 628b18818ae9..9f69dbe1c7d4 100644 --- a/drivers/thermal/tegra/tegra-bpmp-thermal.c +++ b/drivers/thermal/tegra/tegra-bpmp-thermal.c @@ -67,9 +67,8 @@ static int tegra_bpmp_thermal_get_temp(struct thermal_zone_device *tz, int *out_ return __tegra_bpmp_thermal_get_temp(tz->devdata, out_temp); } -static int tegra_bpmp_thermal_set_trips(struct thermal_zone_device *tz, int low, int high) +static int tegra_bpmp_thermal_program_trips(struct tegra_bpmp_thermal_zone *zone) { - struct tegra_bpmp_thermal_zone *zone = tz->devdata; struct mrq_thermal_host_to_bpmp_request req; struct tegra_bpmp_message msg; int err; @@ -78,8 +77,10 @@ static int tegra_bpmp_thermal_set_trips(struct thermal_zone_device *tz, int low, req.type = CMD_THERMAL_SET_TRIP; req.set_trip.zone = zone->idx; req.set_trip.enabled = true; - req.set_trip.low = low; - req.set_trip.high = high; + mutex_lock(&zone->tzd->lock); + req.set_trip.low = zone->tzd->prev_low_trip; + req.set_trip.high = zone->tzd->prev_high_trip; + mutex_unlock(&zone->tzd->lock); memset(&msg, 0, sizeof(msg)); msg.mrq = MRQ_THERMAL; @@ -95,14 +96,31 @@ static int tegra_bpmp_thermal_set_trips(struct thermal_zone_device *tz, int low, return 0; } +static int tegra_bpmp_thermal_set_trips(struct thermal_zone_device *tz, int low, int high) +{ + return 0; +} + static void tz_device_update_work_fn(struct work_struct *work) { struct tegra_bpmp_thermal_zone *zone; + int err; zone = container_of(work, struct tegra_bpmp_thermal_zone, tz_device_update_work); + /* Recalculates trip temperatures. */ thermal_zone_device_update(zone->tzd, THERMAL_TRIP_VIOLATED); + + /* + * Program trip temperatures. We must do this outside `set_trips` + * since thermal core may skip calling it if the trip temperatures + * are unchanged. + */ + err = tegra_bpmp_thermal_program_trips(zone); + if (err) + dev_err(zone->tegra->dev, "failed to update trip temperatures for zone '%s': %d\n", + zone->tzd->type, err); } static void bpmp_mrq_thermal(unsigned int mrq, struct tegra_bpmp_channel *ch, @@ -293,6 +311,13 @@ static int tegra_bpmp_thermal_probe(struct platform_device *pdev) return err; } + for (i = 0; i < tegra->num_zones; i++) { + err = tegra_bpmp_thermal_program_trips(tegra->zones[i]); + if (err) + dev_err(&pdev->dev, "failed to set trip temperatures for zone '%s': %d\n", + tzd->type, err); + } + platform_set_drvdata(pdev, tegra); return 0;