Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp31612019rwd; Fri, 7 Jul 2023 01:44:21 -0700 (PDT) X-Google-Smtp-Source: APBJJlGzpjw3pyEVJCmVnqmg334q56Uf6XDdm0z9Pgmbj9t+wXPSuWrlqbR/CMJ4Pz+NYh0QvujA X-Received: by 2002:a05:6a20:394f:b0:125:4d74:ac77 with SMTP id r15-20020a056a20394f00b001254d74ac77mr3862124pzg.42.1688719460802; Fri, 07 Jul 2023 01:44:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688719460; cv=none; d=google.com; s=arc-20160816; b=BxNOMaEl4Oge/ZQaSmkIrzLEe4CmhH3OOnFSl5lRm4VAuPGdIan28F0oO46801J8eo 6tsVWAZXIw3/A35zdJztt5lDe42ZQvvz5x/0jeOJa4RBbBlFuhQzisPhPoXDDC+vAnNn 9b+Kd8fBxBz4Ut8R3rszb1GiPcTVXST/A7R46mFk4FxoSQfr/COt5u01Qne+7wvQVubI Lf5mAquS1w6wpfUiDMY2BchamC2MF0jfWaUow1CA6YW15roKl45J18of3ZpyV78YiTTN p2IB4L8NZSkCWqFbQFkrmV3HlvbySzTsB3+PI9KXzTx0o4iJd/MlQ/Sf0468TtL29jyK LU6Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=mLPLIAsjTGVX1dzEcktc16gVP+dkCn01FZ0TbzFtND0=; fh=Q4Ged6bxsmOpeCB2NIwBeiB5BePYaqJaVV/+mq1tr2Y=; b=Lf+1COS6WU2Hry01T+8FnRQgthlXyUFKOB8LGvde83eAzbzEUKpdyML4EVVIrDkwZ2 7GwoOzyZhnBTFnCxK/tmTOM/Qh0IttE3KRGajzvEWqa9ak33eJcTsq7FFHcCZY6O3+OV CLtnTHBWfYRYNxNh0DsKMLpBxKbnBEJl58YD9kvPekQnxC1C5z840wcNncXPjsTruBZ7 I+iK4sCu/XKh8tRHmjEuOo0jPwjkgdXpfa5Jn6qzIw/5lJuSVQHAPtAVI9PyUyl1tTLK 7J1jTKOKRoxCh3a9SghTpI/VIUubzi20JaQZB449mjl7AX7EsiSL14g727y5Q7hhbgRT XsWA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=Ucl090la; 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 d20-20020a056a0024d400b00679a6ce03f6si3484178pfv.59.2023.07.07.01.44.09; Fri, 07 Jul 2023 01:44:20 -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=Ucl090la; 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 S232277AbjGGIcJ (ORCPT + 99 others); Fri, 7 Jul 2023 04:32:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59112 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229993AbjGGIcI (ORCPT ); Fri, 7 Jul 2023 04:32:08 -0400 Received: from madras.collabora.co.uk (madras.collabora.co.uk [46.235.227.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4A63B90; Fri, 7 Jul 2023 01:32:07 -0700 (PDT) Received: from [192.168.1.100] (2-237-20-237.ip236.fastwebnet.it [2.237.20.237]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) (Authenticated sender: kholk11) by madras.collabora.co.uk (Postfix) with ESMTPSA id 469A56606FCA; Fri, 7 Jul 2023 09:32:05 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1688718725; bh=t2rkCbgGEm+ru0kRuGpgrdPysXExXq3DnEOiku93jvQ=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=Ucl090laFkEUAlFDIM5irYbjHt5rA1HD4+cSbtY8egpSBKUfu19u9Jlq1Gt8QBPLs 1mJ5lhSSTpB6Ol5oYTUEyBw+p/IcFoRsVM4l3OHxaPtWun1sADjlYcb18B0xAgBAAW 5y5cLUsTFmUZ9RhHhDrd0jO/v5pY8aoUBWl/dAMgDnYeWzTacBnQ4Tao3iRZYjGlok CsMk3E4ztWsI50rAyQatyxgcSrDFUqLjxHhmCdY4ArGTVCwpiYSgOo//CScu88A9Y0 tX8qtuUDI9AzwDdEexZyQWHxGPvYL3sfmNZhsg+rwxJ2WB0K8TEeTds0mnVXCuCc7M VbWvlZwpmNBvw== Message-ID: Date: Fri, 7 Jul 2023 10:32:02 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.12.0 Subject: Re: [PATCH] thermal/drivers/mediatek/lvts_thermal: Make readings valid in filtered mode Content-Language: en-US To: =?UTF-8?B?TsOtY29sYXMgRi4gUi4gQS4gUHJhZG8=?= , Daniel Lezcano Cc: kernel@collabora.com, Chen-Yu Tsai , =?UTF-8?Q?Bernhard_Rosenkr=c3=a4nzer?= , 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 References: <20230706161509.204546-1-nfraprado@collabora.com> From: AngeloGioacchino Del Regno In-Reply-To: <20230706161509.204546-1-nfraprado@collabora.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.2 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED 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 Il 06/07/23 18:14, NĂ­colas F. R. A. Prado ha scritto: > 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); #define LVTS_MSR_READ_TIMEOUT_US 400 then, either 240 like this... #define LVTS_MSR_READ_WAIT_US ((LVTS_MSR_READ_TIMEOUT_US / 2) - 10) ..or 220 (if valid) like this.. #define LVTS_MSR_READ_WAIT_US ((LVTS_MSR_READ_TIMEOUT_US / 20) + \ (LVTS_MSR_READ_TIMEOUT_US / 2)) ..or just "240-and-that's-it" #define LVTS_MSR_READ_WAIT_US 240 rc = readl_poll_timeout(msr, value, value & BIT(16), LVTS_MSR_READ_WAIT_US, LVTS_MSR_READ_TIMEOUT_US); Cheers, Angelo