Received: by 2002:a05:6358:7058:b0:131:369:b2a3 with SMTP id 24csp1355414rwp; Thu, 13 Jul 2023 09:35:25 -0700 (PDT) X-Google-Smtp-Source: APBJJlGRGDRu082Ldy8W+DSNnlb4GO+CbOiaNDdvYDlpN4gkaotIDBHHZ+MZS9Ff3W3euFso27Jw X-Received: by 2002:a17:902:f68b:b0:1ae:6cf0:94eb with SMTP id l11-20020a170902f68b00b001ae6cf094ebmr1682341plg.5.1689266125159; Thu, 13 Jul 2023 09:35:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689266125; cv=none; d=google.com; s=arc-20160816; b=OwkWMEolZdYwusuitj4GpO180DulcH3tZ18Q0+uWnfUwNI8LJVYxbgK+oZMffhdM57 F2V0vOG01OY0v5BsoEkjyYU3b9W4dOQbtEGSfkuMpnlXo6CRcIJ+ocuCm5CZLx8r+xqH ojHzE836PeaTcBYz0a+4fWLBVJ8jHiPwgFPo6aIuYlyGQzC7UguKHJ3ATFhzyH+X/I7j 7mhVVBdF3gO11LpMoOko1YSV9FfyQJ22sLcwx/12OlqMCEA+evL5AfA4nbrqUhQCaT6/ YBdrn+ZebS662h3LvJX/cQz+dkce6QI/2/iWbwt1aLS18NQ/+7djO1g+GQ07kgHOq7cC DCpw== 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=aLi96+fb9uCq1E43GmcixMJ0rY27HeV+DdfRSNCmo1M=; fh=kI4FUzaNm3cIYQMwJzReWm97PTLb93t2WnO+id2+m0I=; b=LPV4HablYJt2ABAQrME+CNh/L+UVGFRQDFU/tQIR8czxwAP3lIBb0ZpOIwUwQI2oA6 g3k4dZBvOlZBfMVa+emFXr9jSBxtsXEPEb4ZBB2DhEqGGlMB6QfJ/eL7On3pQSw++efE UgfysRMST+7QMY7AqtN3j897Alikte26AkNNNaciHBvqqLdr4ynzUYwASAQshc0mi+x2 NQV6g8hnRlK9UZU/R8jaCpRrTkO2Tmebga6tS9KsdRg5LQ6GjmT1FPv/hWGhsDPToiHs 3gkkWSucBG4XlW/j1KHMXzEb1760gM/7PgMfxlNDEfLKOa8CAL3pd1dHD+NDjcXXPI0O qZaA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=TZMD09Y3; 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 u8-20020a170902e80800b001b81e6ce809si5555663plg.5.2023.07.13.09.35.13; Thu, 13 Jul 2023 09:35:25 -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=TZMD09Y3; 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 S234969AbjGMPsL (ORCPT + 99 others); Thu, 13 Jul 2023 11:48:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49304 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235107AbjGMPrz (ORCPT ); Thu, 13 Jul 2023 11:47:55 -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 740A0270D; Thu, 13 Jul 2023 08:47:52 -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 990CB6607048; Thu, 13 Jul 2023 16:47:48 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1689263270; bh=NmZWSJBtJogmZ1XmFkqp7N/SRJ1aRoSmIrbWDGiL4Yo=; h=From:To:Cc:Subject:Date:From; b=TZMD09Y3AycsOcBdEma+Wp2v2dnejJbZ/jERjnsTI/rEa0iyRmq4hPzm4atzRgWxd 4HQWF+/xlBagQDvhN5/5cWQxxuoYvSmZwG5YAh4fEHmA8xdB7Zbx+uEi8AanCl0QhT z4WOQ3o0UCE/l0weymA1twrCVYiDzDkST3X7HXNBV6yBxJP9ILH41reEcLC0gZ7UJs r4szl5NTX/NAOBTuld9nrf0onxW5NsxvjZlybR9O1/p8c4ue1SgjIcwN22fUZrqT6l GoURnubugZo2c62BYcniSpmDY/+m+LK5t0CerzDnDYd1tmbxegBch9dJtvcLwj0B42 SoZo5oDDxcFkQ== 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?= , Alexandre Mergnat , Amit Kucheria , Balsam CHIHI , Matthias Brugger , "Rafael J. Wysocki" , Yangtao Li , 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 v2] thermal/drivers/mediatek/lvts_thermal: Make readings valid in filtered mode Date: Thu, 13 Jul 2023 11:42:37 -0400 Message-ID: <20230713154743.611870-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,RCVD_IN_DNSWL_BLOCKED, 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. Reviewed-by: Chen-Yu Tsai Tested-by: Chen-Yu Tsai Signed-off-by: NĂ­colas F. R. A. Prado --- Changes in v2: - Added macros for the wait and timeout times (and in the process made the wait 200us instead of 240us, just to simplify, gives the same result) - Rebased on thermal/bleeding-edge (since the "thermal/drivers/mediatek/lvts_thermal: Fixes to the interrupt handling" series was merged) drivers/thermal/mediatek/lvts_thermal.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/drivers/thermal/mediatek/lvts_thermal.c b/drivers/thermal/mediatek/lvts_thermal.c index ea89b29ffe5f..1a3cb118ff32 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 0x8300318C @@ -86,6 +86,9 @@ #define LVTS_MSR_IMMEDIATE_MODE 0 #define LVTS_MSR_FILTERED_MODE 1 +#define LVTS_MSR_READ_TIMEOUT_US 400 +#define LVTS_MSR_READ_WAIT_US (LVTS_MSR_READ_TIMEOUT_US / 2) + #define LVTS_HW_SHUTDOWN_MT8195 105000 #define LVTS_MINIMUM_THRESHOLD 20000 @@ -268,6 +271,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: @@ -280,7 +284,8 @@ 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), + LVTS_MSR_READ_WAIT_US, LVTS_MSR_READ_TIMEOUT_US); /* * As the thermal zone temperature will read before the @@ -293,7 +298,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