From nobody Fri Sep 20 20:39:37 2024 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 48397C6FD18 for ; Wed, 19 Apr 2023 06:12:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231684AbjDSGMC (ORCPT ); Wed, 19 Apr 2023 02:12:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55930 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231537AbjDSGL4 (ORCPT ); Wed, 19 Apr 2023 02:11:56 -0400 Received: from madras.collabora.co.uk (madras.collabora.co.uk [IPv6:2a00:1098:0:82:1000:25:2eeb:e5ab]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 055565FEC; Tue, 18 Apr 2023 23:11:54 -0700 (PDT) Received: from IcarusMOD.eternityproject.eu (unknown [IPv6:2001:b07:2ed:14ed:c5f8:7372:f042:90a2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: kholk11) by madras.collabora.co.uk (Postfix) with ESMTPSA id 1007E6603204; Wed, 19 Apr 2023 07:11:52 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1681884713; bh=aJRWxVnGzaGr2J9P6apJi4W995EeNeVBfHiYi7QxHyU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PHr8J0wKmm7tde/rnTrd4tzahXo0FD9+w38AygmVIQBAEd+P5Vpg7za5cTPowyhO7 vlHIgGGnqqwnEs/J4QSl8KiX4BUklaP/pu54gcOfSSmeCUw6zlY2wHxz013bvthZg4 L6p7R15+wddaFtGbgbsvdynxvzr6tw5G12qhRuTptjAG3d/vtHJ2E2WCxjcVlT0Wwr pIc+yABvm+gM1Rq6iWsonDMKpNE0DPNZUbETvqUVca/GNkVW/ugs+I0JZOl9ZiFmrp 75l7vZ08k3iwTrQnXREsdbuo85scacvuWCjuQZWcoZo3Bv/WTtxVu0tvEFvDwQdxiW xwlZeWFlfZaBA== From: AngeloGioacchino Del Regno To: rafael@kernel.org Cc: daniel.lezcano@linaro.org, amitk@kernel.org, rui.zhang@intel.com, matthias.bgg@gmail.com, angelogioacchino.delregno@collabora.com, aouledameur@baylibre.com, bchihi@baylibre.com, daniel@makrotopia.org, ye.xingchen@zte.com.cn, hsinyi@chromium.org, michael.kao@mediatek.com, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, "kernelci.org bot" Subject: [PATCH 1/2] Revert "thermal/drivers/mediatek: Add delay after thermal banks initialization" Date: Wed, 19 Apr 2023 08:11:45 +0200 Message-Id: <20230419061146.22246-2-angelogioacchino.delregno@collabora.com> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230419061146.22246-1-angelogioacchino.delregno@collabora.com> References: <20230419061146.22246-1-angelogioacchino.delregno@collabora.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Some more testing revealed that this commit introduces a regression on some MT8173 Chromebooks and at least on one MT6795 Sony Xperia M5 smartphone due to the delay being apparently variable and machine specific. Another solution would be to delay for a bit more (~70ms) but this is not feasible for two reasons: first of all, we're adding an even bigger delay in a probe function; second, some machines need less, some may need even more, making the msleep at probe solution highly suboptimal. This reverts commit 10debf8c2da8011c8009dd4b3f6d0ab85891c81b. Fixes: 10debf8c2da8 ("thermal/drivers/mediatek: Add delay after thermal ban= ks initialization") Reported-by: "kernelci.org bot" Signed-off-by: AngeloGioacchino Del Regno --- drivers/thermal/mediatek/auxadc_thermal.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/drivers/thermal/mediatek/auxadc_thermal.c b/drivers/thermal/me= diatek/auxadc_thermal.c index b6bb9eaafb74..3c959a827451 100644 --- a/drivers/thermal/mediatek/auxadc_thermal.c +++ b/drivers/thermal/mediatek/auxadc_thermal.c @@ -816,6 +816,14 @@ static int mtk_thermal_bank_temperature(struct mtk_the= rmal_bank *bank) mt, conf->bank_data[bank->id].sensors[i], raw); =20 =20 + /* + * The first read of a sensor often contains very high bogus + * temperature value. Filter these out so that the system does + * not immediately shut down. + */ + if (temp > 200000) + temp =3D 0; + if (temp > max) max =3D temp; } @@ -1273,9 +1281,6 @@ static int mtk_thermal_probe(struct platform_device *= pdev) =20 platform_set_drvdata(pdev, mt); =20 - /* Delay for thermal banks to be ready */ - msleep(30); - tzdev =3D devm_thermal_of_zone_register(&pdev->dev, 0, mt, &mtk_thermal_ops); if (IS_ERR(tzdev)) { --=20 2.40.0 From nobody Fri Sep 20 20:39:37 2024 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 A44C9C6FD18 for ; Wed, 19 Apr 2023 06:12:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231748AbjDSGME (ORCPT ); Wed, 19 Apr 2023 02:12:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55954 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231642AbjDSGL5 (ORCPT ); Wed, 19 Apr 2023 02:11:57 -0400 Received: from madras.collabora.co.uk (madras.collabora.co.uk [46.235.227.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 66D7459F5; Tue, 18 Apr 2023 23:11:56 -0700 (PDT) Received: from IcarusMOD.eternityproject.eu (unknown [IPv6:2001:b07:2ed:14ed:c5f8:7372:f042:90a2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: kholk11) by madras.collabora.co.uk (Postfix) with ESMTPSA id 92E6A660320D; Wed, 19 Apr 2023 07:11:53 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1681884714; bh=nTpGrftsRIa7La3Ejz06bZ6jB8zQMnXxmXPyKaNjl/c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=M74pTcM2OYwN/86mnbjQC8NtUEu1+y2BszQaVWA5XmA58kF/QX36GJS5PufvkkNDK W/xIK9tgxVMdjwSF3zgk+KSoLSjAZ8HSSniKJ7krsOM/67iEjr6/ApL4v8rdMWCtP1 DZPI2v+REMfaovVo1BIJHqYFb/F7aFEXou/FOxisRP9C72l0SJI9N8CE7zNOdTcpdU FIZ30HuKz+bNUqZTuS14AMGZxC3yZo9zML61T4dhuQDdMwpIHbdS/MXv5KofNmAu6D S9Oizd5d7KETbIdFVbLbBloacfuYcr6xrd3KJNEJhbFgdnMsSQINIIqnSYfpT/RYW5 Om0+KjwDsCTsQ== From: AngeloGioacchino Del Regno To: rafael@kernel.org Cc: daniel.lezcano@linaro.org, amitk@kernel.org, rui.zhang@intel.com, matthias.bgg@gmail.com, angelogioacchino.delregno@collabora.com, aouledameur@baylibre.com, bchihi@baylibre.com, daniel@makrotopia.org, ye.xingchen@zte.com.cn, hsinyi@chromium.org, michael.kao@mediatek.com, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org Subject: [PATCH 2/2] thermal/drivers/mediatek: Add temperature constraints to validate read Date: Wed, 19 Apr 2023 08:11:46 +0200 Message-Id: <20230419061146.22246-3-angelogioacchino.delregno@collabora.com> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230419061146.22246-1-angelogioacchino.delregno@collabora.com> References: <20230419061146.22246-1-angelogioacchino.delregno@collabora.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The AUXADC thermal v1 allows reading temperature range between -20=C2=B0C to 150=C2=B0C and any value out of this range is invalid. Add new definitions for MT8173_TEMP_{MIN_MAX} and a new small helper mtk_thermal_temp_is_valid() to check if new readings are in range: if not, we tell to the API that the reading is invalid by returning THERMAL_TEMP_INVALID. It was chosen to introduce the helper function because, even though this temperature range is realistically ok for all, it comes from a downstream kernel driver for version 1, but here we also support v2 and v3 which may may have wider constraints. Signed-off-by: AngeloGioacchino Del Regno --- drivers/thermal/mediatek/auxadc_thermal.c | 24 +++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/drivers/thermal/mediatek/auxadc_thermal.c b/drivers/thermal/me= diatek/auxadc_thermal.c index 3c959a827451..e908c8e9d558 100644 --- a/drivers/thermal/mediatek/auxadc_thermal.c +++ b/drivers/thermal/mediatek/auxadc_thermal.c @@ -116,6 +116,10 @@ /* The calibration coefficient of sensor */ #define MT8173_CALIBRATION 165 =20 +/* Valid temperatures range */ +#define MT8173_TEMP_MIN -20000 +#define MT8173_TEMP_MAX 150000 + /* * Layout of the fuses providing the calibration data * These macros could be used for MT8183, MT8173, MT2701, and MT2712. @@ -689,6 +693,11 @@ static const struct mtk_thermal_data mt7986_thermal_da= ta =3D { .version =3D MTK_THERMAL_V3, }; =20 +static bool mtk_thermal_temp_is_valid(int temp) +{ + return (temp >=3D MT8173_TEMP_MIN) && (temp <=3D MT8173_TEMP_MAX); +} + /** * raw_to_mcelsius_v1 - convert a raw ADC value to mcelsius * @mt: The thermal controller @@ -815,14 +824,17 @@ static int mtk_thermal_bank_temperature(struct mtk_th= ermal_bank *bank) temp =3D mt->raw_to_mcelsius( mt, conf->bank_data[bank->id].sensors[i], raw); =20 - /* - * The first read of a sensor often contains very high bogus - * temperature value. Filter these out so that the system does - * not immediately shut down. + * Depending on the filt/sen intervals and ADC polling time, + * we may need up to 60 milliseconds after initialization: this + * will result in the first reading containing an out of range + * temperature value. + * Validate the reading to both address the aforementioned issue + * and to eventually avoid bogus readings during runtime in the + * event that the AUXADC gets unstable due to high EMI, etc. */ - if (temp > 200000) - temp =3D 0; + if (!mtk_thermal_temp_is_valid(temp)) + temp =3D THERMAL_TEMP_INVALID; =20 if (temp > max) max =3D temp; --=20 2.40.0