From patchwork Wed Aug 23 17:33:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fabio Estevam X-Patchwork-Id: 13363012 X-Patchwork-Delegate: daniel.lezcano@linaro.org 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 C6460C27C40 for ; Wed, 23 Aug 2023 17:33:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236947AbjHWRds (ORCPT ); Wed, 23 Aug 2023 13:33:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57182 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234958AbjHWRdr (ORCPT ); Wed, 23 Aug 2023 13:33:47 -0400 Received: from mail-oo1-xc2e.google.com (mail-oo1-xc2e.google.com [IPv6:2607:f8b0:4864:20::c2e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 27E61FB; Wed, 23 Aug 2023 10:33:46 -0700 (PDT) Received: by mail-oo1-xc2e.google.com with SMTP id 006d021491bc7-570c1364e5eso503965eaf.0; Wed, 23 Aug 2023 10:33:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1692812025; x=1693416825; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=FwlqdGlNb2fSdqkhw4SOtKSTjQqtRCEcXwbk2iTPsLs=; b=mJGlhdHghjbvl/TPsGOVA2v5JjkPLbR2Hc3Sm4++Sl1fA6/SZVk74GdTe8QYCTJ2wj WqktnQjYbRb25OtlPybZ9LC+4eWUdsjCKfJkETg0yDnw2AvWv4boNV/8AwKt9rWqeASi JZXjfw03dsOsWqguq74/r3NiffcYa0glD/VR19YbNuz3qNOuNEh2j2++ZmCIBwN4Rrbu i8uzpPYmMPb+e8wSKc6FYabmz2IohBtdvNus2c4L84U25LO0d8fuQv8FYNzXMEaH9uno 6FR6UMqjJ2cm5VPd5Leyu+XqlH9GFAxCbD/o5ie8Q61lZea51GJzeVeBM0f98s46CBez x2dQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692812025; x=1693416825; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=FwlqdGlNb2fSdqkhw4SOtKSTjQqtRCEcXwbk2iTPsLs=; b=hJ7+q4C4ZtlRMBnmH6KWmVQOl2M+vxmPkLOoS7dMJh1x1bfTtmC5DDKyh4XCEDUP5y +qpJ0QXdzSWBGFqHCzZyr7sW1kjsftcwlEGydJGE9DRgWZv1sKkgjS+I6BnBqw9u+Zh6 +mCW9iexNhaXODja6s3ePboA09kDBP0yVajAfebuckZyEH27lQK52BxyDaRBr8Jcr9wF JBEq74vASwHH39OCrjv69mDz2HdPyQvMibEetDq3SJB9fsOvp/A18CCyksIhZEZnGh1y SksraZc8NZb0m8+QerDpvLQmRLL0pfzujuNogTSi8k2FfS2o38DDyRjfX8av81dELBa3 CQlg== X-Gm-Message-State: AOJu0YzrPBlZ4obCCzS+RkvliuSoa52Kp/fnYtpvXDDo7OOg1M/qp28h kAHuitX9Sdz3S8qQJ9TDkf8= X-Google-Smtp-Source: AGHT+IF5alAbGAScr8G+vTF4uQ56s0FlHwiqn+4+mf5v36BbTIGSeXTWlOlbLwaEjPwnGjSiPtZC7g== X-Received: by 2002:a4a:37c3:0:b0:570:cad0:fce9 with SMTP id r186-20020a4a37c3000000b00570cad0fce9mr9091111oor.1.1692812025243; Wed, 23 Aug 2023 10:33:45 -0700 (PDT) Received: from fabio-Precision-3551.. ([2804:14c:485:4b61:ae60:b44a:59b3:894f]) by smtp.gmail.com with ESMTPSA id a1-20020a4aae41000000b0056d361ca33fsm5949943oon.16.2023.08.23.10.33.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Aug 2023 10:33:44 -0700 (PDT) From: Fabio Estevam To: daniel.lezcano@linaro.org Cc: linux-pm@vger.kernel.org, krzysztof.kozlowski+dt@linaro.org, robh+dt@kernel.org, conor+dt@kernel.org, devicetree@vger.kernel.org, Fabio Estevam Subject: [PATCH 1/2] dt-bindings: imx8mm-thermal: Document 'nxp,reboot-on-critical' Date: Wed, 23 Aug 2023 14:33:33 -0300 Message-Id: <20230823173334.304201-1-festevam@gmail.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org From: Fabio Estevam Currently, after the board reaches the critical temperature, the system goes through a poweroff mechanism. In some cases, such behavior does not suit well, as the board may be unattended in the field and rebooting may be a better approach. The bootloader may also check the temperature and only allow the boot to proceed when the temperature is below a certain threshold. Introduce the 'nxp,reboot-on-critical' property to indicate that the board will go through a reboot after the critical temperature is reached. When this property is absent, the default behavior of forcing a shutdown is kept. Signed-off-by: Fabio Estevam --- .../devicetree/bindings/thermal/imx8mm-thermal.yaml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Documentation/devicetree/bindings/thermal/imx8mm-thermal.yaml b/Documentation/devicetree/bindings/thermal/imx8mm-thermal.yaml index d2c1e4573c32..9ac70360fd35 100644 --- a/Documentation/devicetree/bindings/thermal/imx8mm-thermal.yaml +++ b/Documentation/devicetree/bindings/thermal/imx8mm-thermal.yaml @@ -32,6 +32,12 @@ properties: clocks: maxItems: 1 + nxp,reboot-on-critical: + description: Property to indicate that the system will go through a reboot + after the critical temperature is reached. If absent, the system will + go through shutdown after the critical temperature is reached. + type: boolean + nvmem-cells: maxItems: 1 description: Phandle to the calibration data provided by ocotp From patchwork Wed Aug 23 17:33:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fabio Estevam X-Patchwork-Id: 13363013 X-Patchwork-Delegate: daniel.lezcano@linaro.org 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 60D01C6FA8F for ; Wed, 23 Aug 2023 17:33:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237836AbjHWRdv (ORCPT ); Wed, 23 Aug 2023 13:33:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48452 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234958AbjHWRdv (ORCPT ); Wed, 23 Aug 2023 13:33:51 -0400 Received: from mail-oo1-xc2a.google.com (mail-oo1-xc2a.google.com [IPv6:2607:f8b0:4864:20::c2a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 39265E7D; Wed, 23 Aug 2023 10:33:49 -0700 (PDT) Received: by mail-oo1-xc2a.google.com with SMTP id 006d021491bc7-570e8bee8b5so456160eaf.1; Wed, 23 Aug 2023 10:33:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1692812028; x=1693416828; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=v4cJYvOwVGAT7gylUsZ1uwHj3O046erDYBL6A2R2npE=; b=p/AjONNI3yNa8Lxk7pepQKxsKZ2JpxUkpdjOvtZegDnF8c9vnKCLWcmgxPTUbsSOtD 2nPdVT3ykiAfdfFIqtqqDXWjOHBuwGT1v4SI5o39u9ZkhbI6bQA5D5Oogb8IT2o1dDKM wY/0hZX9kkzSapDIK2E+eDAKpKgyTCW+UsGqI75gJrMnfqXXrbE3DQYovOhMu42EVX/b uujmy47HyNgjfrg3xQpk82Dzn1TYacux1yG/kj2B6Gt6NCUbLKUmeMC2HkDfKnXjLdh8 GxCQqibHiUSj5v2GsY9eZHzRkXSppU28cVluAJaQDxgroF/CSK7hPP2tP6rUYqP9CloG DGrg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692812028; x=1693416828; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=v4cJYvOwVGAT7gylUsZ1uwHj3O046erDYBL6A2R2npE=; b=fXc0nzBxvrudAEe7HczRW/eYVGuNwYykpjSLRhqyL4AXI4eBFU842BYaL2wSnlkUYe bhkCRxO6mcDkzvpJCukWja2H1sE7Ws0XfiTq/FW/Q4MsyzHFUVqg9QHUeXu0zWHpV2ka UpAWkoXBdZDJmY6uuCKsEL1o2Q61u1a5JBqwor1wb1AUnfKAE57O/TqVi7beIQfwTBSV 4uNZoaaPAeOOOWRdiUj78I1Wf02OdiuoyaoKoIro8DCJ29u5IivNGW3CJ6HfDfeCDZZ1 NNBf9Ck5JKvtSRU0/E1BDWOqKEX+7Or06QlNFqpJ0irxegurjsyoiyAjiUYxrxPcMSj7 jz+A== X-Gm-Message-State: AOJu0YzgAdP0TIMQNe6UPTJ8JpgT13qbK3476J0n2dy3tfhRLoJGhX82 r9+SUm9fx3e7xspqcvLgbCM= X-Google-Smtp-Source: AGHT+IFaHhepcwQ/qBMADUaJ7iHVJXjC2K99w1cY7XtwVrBoPCYZMV1KQmqvTvCn+X7JIWY5Y5q/gg== X-Received: by 2002:a4a:d137:0:b0:571:1906:47f0 with SMTP id n23-20020a4ad137000000b00571190647f0mr1884917oor.1.1692812028341; Wed, 23 Aug 2023 10:33:48 -0700 (PDT) Received: from fabio-Precision-3551.. ([2804:14c:485:4b61:ae60:b44a:59b3:894f]) by smtp.gmail.com with ESMTPSA id a1-20020a4aae41000000b0056d361ca33fsm5949943oon.16.2023.08.23.10.33.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Aug 2023 10:33:47 -0700 (PDT) From: Fabio Estevam To: daniel.lezcano@linaro.org Cc: linux-pm@vger.kernel.org, krzysztof.kozlowski+dt@linaro.org, robh+dt@kernel.org, conor+dt@kernel.org, devicetree@vger.kernel.org, Fabio Estevam Subject: [PATCH 2/2] thermal: imx8mm: Allow reboot after critical temperature Date: Wed, 23 Aug 2023 14:33:34 -0300 Message-Id: <20230823173334.304201-2-festevam@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230823173334.304201-1-festevam@gmail.com> References: <20230823173334.304201-1-festevam@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org From: Fabio Estevam Currently, after the board reaches the critical temperature, the system goes through a poweroff mechanism. In some cases, such behavior does not suit well, as the board may be unattended in the field and rebooting may be a better approach. The bootloader may also check the temperature and only allow the boot to proceed when the temperature is below a certain threshold. Introduce the 'nxp,reboot-on-critical' property to indicate that the board will go through a reboot after the critical temperature is reached. When this property is absent, the default behavior of forcing a shutdown is kept. Tested on a imx8mm-evk board. Signed-off-by: Fabio Estevam --- drivers/thermal/imx8mm_thermal.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/drivers/thermal/imx8mm_thermal.c b/drivers/thermal/imx8mm_thermal.c index e89b11b3f2b9..cc95a1416976 100644 --- a/drivers/thermal/imx8mm_thermal.c +++ b/drivers/thermal/imx8mm_thermal.c @@ -15,6 +15,7 @@ #include #include #include +#include #include "thermal_hwmon.h" @@ -91,6 +92,7 @@ struct imx8mm_tmu { void __iomem *base; struct clk *clk; const struct thermal_soc_data *socdata; + bool reboot; struct tmu_sensor sensors[]; }; @@ -146,8 +148,23 @@ static int tmu_get_temp(struct thermal_zone_device *tz, int *temp) return tmu->socdata->get_temp(sensor, temp); } +static void tmu_critical(struct thermal_zone_device *tz) +{ + struct tmu_sensor *sensor = thermal_zone_device_priv(tz); + struct imx8mm_tmu *tmu = sensor->priv; + + if (tmu->reboot) { + dev_emerg(thermal_zone_device(tz), "%s: critical temperature reached\n", + thermal_zone_device_type(tz)); + kernel_restart(NULL); + } else { + thermal_zone_device_critical(tz); + } +} + static const struct thermal_zone_device_ops tmu_tz_ops = { .get_temp = tmu_get_temp, + .critical = tmu_critical, }; static void imx8mm_tmu_enable(struct imx8mm_tmu *tmu, bool enable) @@ -313,6 +330,8 @@ static int imx8mm_tmu_probe(struct platform_device *pdev) if (IS_ERR(tmu->base)) return PTR_ERR(tmu->base); + tmu->reboot = of_property_present(pdev->dev.of_node, "nxp,reboot-on-critical"); + tmu->clk = devm_clk_get(&pdev->dev, NULL); if (IS_ERR(tmu->clk)) return dev_err_probe(&pdev->dev, PTR_ERR(tmu->clk),