From patchwork Thu Jul 6 16:14:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?TsOtY29sYXMgRi4gUi4gQS4gUHJhZG8=?= X-Patchwork-Id: 13303999 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 E95BFEB64DC for ; Thu, 6 Jul 2023 16:15:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232126AbjGFQPW (ORCPT ); Thu, 6 Jul 2023 12:15:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32918 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229489AbjGFQPU (ORCPT ); Thu, 6 Jul 2023 12:15:20 -0400 Received: from madras.collabora.co.uk (madras.collabora.co.uk [46.235.227.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BD7F710C; Thu, 6 Jul 2023 09:15:19 -0700 (PDT) Received: from notapiano.myfiosgateway.com (zone.collabora.co.uk [167.235.23.81]) (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: nfraprado) by madras.collabora.co.uk (Postfix) with ESMTPSA id 45AEE6606FC4; Thu, 6 Jul 2023 17:15:15 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1688660118; bh=j4Ff8jZjJXo7I/FQ5lBog+vo+xtKrEJKPXvRjQjs67g=; h=From:To:Cc:Subject:Date:From; b=TvWdYc4hqW5CowqNu/0c/JhbwtCGD3WTQS8ADenSlLyffsiXemx2i1bd/M+y0aGsM IiAcCyioCzgtgKQ5Y184uaTbo+oGie9yuPyJ358Jvv4CsC1OFloX3gcNjepCfSSojE UFr0ciczt0GV+LBORO3oAD3NUv7WdVxXzblawz2jVWpcI8XdB8jlWleB1++VnWTMAc B0B1IOqd8mULvYFHFUdL4VFzetSWz0MU9ui4jGfRHrGZmgrF6/ZaId457ZZgSm2jMh DBh5XGqsG+uruHm2l4UKEIDLBjAY0fCXeZGYBTx8VjhbS6kLE2AmRior76CVCJVOD5 5zNVnrqBHkW1g== From: =?utf-8?b?TsOtY29sYXMgRi4gUi4gQS4gUHJhZG8=?= To: Daniel Lezcano Cc: kernel@collabora.com, AngeloGioacchino Del Regno , Chen-Yu Tsai , =?utf-8?q?Bernhard_Rosenkr=C3=A4nzer?= , =?utf-8?b?TsOt?= =?utf-8?b?Y29sYXMgRi4gUi4gQS4gUHJhZG8=?= , Amit Kucheria , Balsam CHIHI , Matthias Brugger , "Rafael J. Wysocki" , Zhang Rui , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-mediatek@lists.infradead.org, linux-pm@vger.kernel.org Subject: [PATCH] thermal/drivers/mediatek/lvts_thermal: Make readings valid in filtered mode Date: Thu, 6 Jul 2023 12:14:33 -0400 Message-ID: <20230706161509.204546-1-nfraprado@collabora.com> X-Mailer: git-send-email 2.41.0 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org Currently, when a controller is configured to use filtered mode, thermal readings are valid only about 30% of the time. Upon testing, it was noticed that lowering any of the interval settings resulted in an improved rate of valid data. The same was observed when decreasing the number of samples for each sensor (which also results in quicker measurements). Retrying the read with a timeout longer than the time it takes to resample (about 344us with these settings and 4 sensors) also improves the rate. Lower all timing settings to the minimum, configure the filtering to single sample, and poll the measurement register for at least one period to improve the data validity on filtered mode. With these changes in place, out of 100000 reads, a single one failed, ie 99.999% of the data was valid. Signed-off-by: NĂ­colas F. R. A. Prado Reviewed-by: Chen-Yu Tsai Tested-by: Chen-Yu Tsai --- drivers/thermal/mediatek/lvts_thermal.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/drivers/thermal/mediatek/lvts_thermal.c b/drivers/thermal/mediatek/lvts_thermal.c index 1e11defe4f35..b5fb1d8bc3d8 100644 --- a/drivers/thermal/mediatek/lvts_thermal.c +++ b/drivers/thermal/mediatek/lvts_thermal.c @@ -58,11 +58,11 @@ #define LVTS_PROTTC(__base) (__base + 0x00CC) #define LVTS_CLKEN(__base) (__base + 0x00E4) -#define LVTS_PERIOD_UNIT ((118 * 1000) / (256 * 38)) -#define LVTS_GROUP_INTERVAL 1 -#define LVTS_FILTER_INTERVAL 1 -#define LVTS_SENSOR_INTERVAL 1 -#define LVTS_HW_FILTER 0x2 +#define LVTS_PERIOD_UNIT 0 +#define LVTS_GROUP_INTERVAL 0 +#define LVTS_FILTER_INTERVAL 0 +#define LVTS_SENSOR_INTERVAL 0 +#define LVTS_HW_FILTER 0x0 #define LVTS_TSSEL_CONF 0x13121110 #define LVTS_CALSCALE_CONF 0x300 #define LVTS_MONINT_CONF 0x9FBF7BDE @@ -257,6 +257,7 @@ static int lvts_get_temp(struct thermal_zone_device *tz, int *temp) struct lvts_sensor *lvts_sensor = thermal_zone_device_priv(tz); void __iomem *msr = lvts_sensor->msr; u32 value; + int rc; /* * Measurement registers: @@ -269,7 +270,7 @@ static int lvts_get_temp(struct thermal_zone_device *tz, int *temp) * 16 : Valid temperature * 15-0 : Raw temperature */ - value = readl(msr); + rc = readl_poll_timeout(msr, value, value & BIT(16), 240, 400); /* * As the thermal zone temperature will read before the @@ -282,7 +283,7 @@ static int lvts_get_temp(struct thermal_zone_device *tz, int *temp) * functionning temperature and directly jump to a system * shutdown. */ - if (!(value & BIT(16))) + if (rc) return -EAGAIN; *temp = lvts_raw_to_temp(value & 0xFFFF);