From patchwork Tue Feb 7 13:56:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mikko Perttunen X-Patchwork-Id: 53954 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp2891139wrn; Tue, 7 Feb 2023 06:53:01 -0800 (PST) X-Google-Smtp-Source: AK7set9NY5z76lGCNoUss56ehYlU5bnThdVg3CFfuvgpS/vQGvazfq/Hvv8hHqTjHbpdsEdfxR7j X-Received: by 2002:a17:906:eddd:b0:7c0:f719:838d with SMTP id sb29-20020a170906eddd00b007c0f719838dmr3328300ejb.36.1675781581484; Tue, 07 Feb 2023 06:53:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675781581; cv=none; d=google.com; s=arc-20160816; b=BUazqYyAKS8r4+uN0exVJ4GkUv4nOLak0yehWYJZvCWwc0oKyyje5/kSKF9IWVm++t mt9dIbk2uy8hlalNczMsfcmlwQALiOC8wAPlEz6/YF0TLnXNkH9MC9mLltltcFujqo0f sKOiT7jP1mu8aPPu3FjyeJBV358qF+NLwyuwqtrhGyY89eje+swl3ziEvqtNjzNxk6QN m3nFSYrioHcWCKcD/qia3w5rpMTsPMJRINMoVDwNKH+Vpr8YQGGGcLC7/ZYaXIcqneF4 5jY+OE0NiaohyNvvcsPlZavpl8fK8slQbXIDAxg/c6hL9Cg28XaTD0LuMiFeY3Py/4iK lh4g== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=AMCBklPpZiJm6G+yI87fmT6RWZwGjjZhJUPUbbl1SrM=; b=uIsmQ8RPA/IZcxamqOfqsxFc9FlvvSGgj90LFNTon7vYW17j+SykHhbGVWawVt1aIM 8A6s1U1Xh+zozxMKOOIoFSPVOLF7K+iYyXmOHyHGNadfHVOhMXncpV3M1ZVUn6JCRjfs 0qr/CrVQUs9s2tC7Z9T+uNl6LsymyRDojj9uuqiulquS5VcdRny6khkh6OI3aCbx2VMA XtfrFZ+5JrOljyLMwIHzuc4SJ9o2E1ju3bdZQFL7ZcvgeIXTr8oyeWwlwT5SGFo0B7C5 htegWNCTMUP9LdPJ3CmodsNqEqIsFO7OkEN9JCs/n+cW4Mgz+MQLlp4O10vd7noi/mrr Ucow== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@kapsi.fi header.s=20161220 header.b=r6xXnZyX; 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 ec12-20020a170906b6cc00b0088bf8e5331esi17890919ejb.853.2023.02.07.06.52.38; Tue, 07 Feb 2023 06:53:01 -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=r6xXnZyX; 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 S231378AbjBGOuC (ORCPT + 99 others); Tue, 7 Feb 2023 09:50:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35936 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230210AbjBGOuA (ORCPT ); Tue, 7 Feb 2023 09:50:00 -0500 Received: from mail.kapsi.fi (mail.kapsi.fi [IPv6:2001:67c:1be8::25]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8E218D7; Tue, 7 Feb 2023 06:49:58 -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: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: In-Reply-To:References:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=AMCBklPpZiJm6G+yI87fmT6RWZwGjjZhJUPUbbl1SrM=; b=r6xXnZyXYevGlxKGGwgcZW/CJm ezl5C4pcwNrZuiifVl2gaIqYeXSDcSZJahz0ebZT4gOAJr0HiHo4/8EEBGrbWEuEGiwtqBbGNoItk QSVbiWh2lOfajfyv6C910kc14wBP4cfsuotI4CBbK/d4ThNGzESE94rSLTVHGETgs9gwxk9+4j54o cVXAjUt+sDkluLQ1T3zzc03hkj3xxKYAa8s8cte0TlLaRuZC5oFc6f6/vTNG2nAUIVK3Ome/Eq3AX Gi7qeNpMCjLp8ZJPov0Tpbmu988nGveCOPhs0fs17rnKudOvwVW24SBm0Q9LPb8oiIXikUSOZUOZc oSjLMn3w==; 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-L6; 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 1/2] thermal: tegra-bpmp: Handle offline zones Date: Tue, 7 Feb 2023 15:56:08 +0200 Message-Id: <20230207135610.3100865-1-cyndis@kapsi.fi> X-Mailer: git-send-email 2.39.0 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?1757184347769440035?= X-GMAIL-MSGID: =?utf-8?q?1757184347769440035?= From: Mikko Perttunen Thermal zones located in power domains may not be accessible when the domain is powergated. In this situation, reading the temperature will return -BPMP_EFAULT and the temperature is considered to be -256C for calculating trips. For smooth operation, for offline zones, return -EAGAIN when reading the temperature and allow registration of zones even if they are offline during probe. Signed-off-by: Mikko Perttunen --- drivers/thermal/tegra/tegra-bpmp-thermal.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/drivers/thermal/tegra/tegra-bpmp-thermal.c b/drivers/thermal/tegra/tegra-bpmp-thermal.c index c76e1ea62c8a..628b18818ae9 100644 --- a/drivers/thermal/tegra/tegra-bpmp-thermal.c +++ b/drivers/thermal/tegra/tegra-bpmp-thermal.c @@ -52,6 +52,8 @@ static int __tegra_bpmp_thermal_get_temp(struct tegra_bpmp_thermal_zone *zone, err = tegra_bpmp_transfer(zone->tegra->bpmp, &msg); if (err) return err; + if (msg.rx.ret == -BPMP_EFAULT) + return -EAGAIN; if (msg.rx.ret) return -EINVAL; @@ -257,7 +259,12 @@ static int tegra_bpmp_thermal_probe(struct platform_device *pdev) zone->tegra = tegra; err = __tegra_bpmp_thermal_get_temp(zone, &temp); - if (err < 0) { + + /* + * Sensors in powergated domains may temporarily fail to be read + * (-EAGAIN), but will become accessible when the domain is powered on. + */ + if (err < 0 && err != -EAGAIN) { devm_kfree(&pdev->dev, zone); continue; } 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;