Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp30702207rwd; Thu, 6 Jul 2023 09:27:40 -0700 (PDT) X-Google-Smtp-Source: APBJJlFdIFZvZ35zWDABkGqDz78+24DTBZpUJc8qsI+kCg0TOX9P9HTkKaoRZH/9AKA/IlefglE9 X-Received: by 2002:a17:90b:1989:b0:263:f7ce:335e with SMTP id mv9-20020a17090b198900b00263f7ce335emr1803485pjb.43.1688660860615; Thu, 06 Jul 2023 09:27:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688660860; cv=none; d=google.com; s=arc-20160816; b=M/N8++AqK3miKFL1pqAGVtadWVCu2Lo2i40fF8aa029NcLooxpUh1L+f0vNUS2BY04 Kdbbk8wKkFP382ajC/KLnzXnXx2EJZ/MzuuBu/0UFslAwUujxUnvYjPmcGtDerNvgIeI I9GGgJG/9fs4pINpi9fkzqqIwY8B4gkDN7TRMRN1EnCKbnt/AZ22trmAMUxinjENf6TM VrELuULZ/qlVnCQWyDnXs9Asu7rzA3A0O7x2d04U0oZLV68xe8XzszFS/K4gMwdDaJMB sfceCW2lfx8WgBMU3no8EwcuJlwp5k/IiUvVuJKBhqQNTmS0HUsi1CMxhyXw17W5c2Wp N2uw== 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=59otjIptXpnUt0M/p92qk92flLDN9yzuxkyiqJv73hE=; fh=zi6BcR/KYEP3kqUAu1Y+AIYTMZ7iYxzJUM6B1iDkBV8=; b=JQguniiqRUd2FEsLcWrL/s1g4UAR2yLuVvvnPtVqwpNQTGP3Gw2+0bNA6UMXtLMYv6 9JlnJ2v/wsYcB1KyO12dRjsqLCrq6WbeG7XxPJnKMiu5FXgVll+uPnOH/L6iZu5qSOy9 gSZkuSA04Jvh/mbOTxluRiPDvVz7S3L6ud5EGtEE99hT7I0g9VHxkm1AcMn2tDqnuyaj TzuNlOjGujRmUPK5sn+Lhiw/RyMNj7//7uBqJTKEi6lfA3uBFxy0xU2I0RUZCCnK40Xl oKC6u1++IEsvrMjWh5HFtSsOwMXbIo6PJdaUICEnc8yEmpy9DbNaDpO0wXMipgFGLtzw 12jA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=TvWdYc4h; 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=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=collabora.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id it14-20020a17090afb0e00b0026376acd6fesi28715pjb.22.2023.07.06.09.27.14; Thu, 06 Jul 2023 09:27:40 -0700 (PDT) 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=pass header.i=@collabora.com header.s=mail header.b=TvWdYc4h; 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=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=collabora.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232498AbjGFQPX (ORCPT + 99 others); Thu, 6 Jul 2023 12:15:23 -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?q?N=C3=ADcolas=20F=2E=20R=2E=20A=2E=20Prado?= To: Daniel Lezcano Cc: kernel@collabora.com, AngeloGioacchino Del Regno , Chen-Yu Tsai , =?UTF-8?q?Bernhard=20Rosenkr=C3=A4nzer?= , =?UTF-8?q?N=C3=ADcolas=20F=2E=20R=2E=20A=2E=20Prado?= , 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 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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, T_SCC_BODY_TEXT_LINE 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 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 --- 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); -- 2.41.0