Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp31590244rwd; Fri, 7 Jul 2023 01:19:49 -0700 (PDT) X-Google-Smtp-Source: APBJJlGCAYNu6WVBniDNV6ugvKFTkF8jM0cw68uSEBV+W/GV5es+7Muh1YtTjhJ0HhClrDAxh+5+ X-Received: by 2002:a05:6a21:33a8:b0:10f:9bea:5a61 with SMTP id yy40-20020a056a2133a800b0010f9bea5a61mr5590978pzb.2.1688717989167; Fri, 07 Jul 2023 01:19:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688717989; cv=none; d=google.com; s=arc-20160816; b=dTV1ziBLMymOKdAgXnHXUNCFHEV6mGiS7+p7Nla3PWIaJbRq+lJDe7J+hMBTx17ny6 LksHl8jpZ+Cmf1lLPZhXESRwzjQ15hFgPyPT6VakM3VEO4gZWqpL05Srj+AgmFR6HXKT 6n04pdr1RG1CWxgjLdwrA/8faSydNeEp2suPR4T+nSHvc8wkcUNV6dprdEehZJLxMNIQ 17bolZcFHSXYfRnwceoLrB7Pf7fb9jxS9Q5X55PWEfnoOb3vY5QREUVMTs9siLya2Dau WFFYfpaKwDMMusQcltpp4ZRA9p8j6JNGiZmi551e/WvCBS1EosNrpjSSjKb7BrE7MLuT ZuJQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=HQgfVl/i/AVcUS5ggc70MxFgfsFBmBSGVm2GhzJXRGM=; fh=5mTfwJqgwk/VjPab45tTIeHnBN2IILAQdTPVdd4+26A=; b=WHGrWY2JZf8ZQGkouzj4n3Rx6YfU4zVtSvpoEPf+jEbY0gaaGOYhgrWqjm7c3rBqas qZqkQLcbmwlTma5/3Nl7jc3yiOIJXPJkcbMaryi1IqzUfQN6EGMnsEGpz4vk71eTBqeJ y/u/WH1kKY9phe3/CN38ahCvtdk8/is761y5C36VD1KtRkfC1/ANnHvGU2wUGz4eAg0U rq3pTzDpEd7JCzQoYLeIMBD3HGmCUnd0VLMAvQNXQnpXVOUI7MxliO96FryUjfet93rW /4egt18y7oQ58DNIz842HSpJj49lPwCJrnW5kJhlUjt3OPLFvtjiWAbsIz51HLB2a4NM R9cA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=EY+mwiti; 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=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f10-20020a63de0a000000b005572b5c0f1fsi3368951pgg.369.2023.07.07.01.19.36; Fri, 07 Jul 2023 01:19:49 -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=@chromium.org header.s=google header.b=EY+mwiti; 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=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232670AbjGGHyB (ORCPT + 99 others); Fri, 7 Jul 2023 03:54:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41972 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232608AbjGGHyA (ORCPT ); Fri, 7 Jul 2023 03:54:00 -0400 Received: from mail-pl1-x62b.google.com (mail-pl1-x62b.google.com [IPv6:2607:f8b0:4864:20::62b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EDB65B2 for ; Fri, 7 Jul 2023 00:53:58 -0700 (PDT) Received: by mail-pl1-x62b.google.com with SMTP id d9443c01a7336-1b9c5e07c1bso1397385ad.2 for ; Fri, 07 Jul 2023 00:53:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1688716438; x=1691308438; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date:from:to :cc:subject:date:message-id:reply-to; bh=HQgfVl/i/AVcUS5ggc70MxFgfsFBmBSGVm2GhzJXRGM=; b=EY+mwitihR1BY0wiVH06ZwvPZB0vcDEEn4HC1LNgbbGW0oKYFmY/xs24morMGXUsr3 jV/bx4/CxOmJaCIiln1tlZ+gG4y3QixOpNEEnx+9RihDs7Dkeh2hu9R+WjcULUPemcIj PBni27YtiE7DOpbwTUoRCcqMt1BLkGrrrVyTs= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688716438; x=1691308438; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=HQgfVl/i/AVcUS5ggc70MxFgfsFBmBSGVm2GhzJXRGM=; b=kncUGNWoXlHGQBhbinkeVAfafEnI9nenINNz29XFXtvUsY2GRcJg0SvePntH5CAn1g 8KtMYzLvYREGu0Kni2IahlWPFqlFjZffTHmAGdnlUKUnoEAJr9xvVxLJdca4yIACxo7W DDm26q3bZZL9CeIhluv5J01SCHh6RYuw+fj3Ik10Gd9qlB4Qm6QgrS53rahrfTaaR8JM ACfiw2sVVZKTLuMzsZ5XQEZINDDyEyRw2EzCPEIZVNdeaJ6wVIQd/yAEItcBpT3i9Oyp Pvk9C0d31CYP9HhIBKgP79KSKf0i932c75DfJC68TFt/fDL4JMXP+X0u1somDm0KUkEd DYUQ== X-Gm-Message-State: ABy/qLYIUGWx79ztY/IPRkkj+aNJCCYEbrXHa43Og5zC4t/1ewDEI0pA h6R0RvoTdaZ+xT6X10g2Qd3RNw== X-Received: by 2002:a17:903:120f:b0:1b3:cac7:19cd with SMTP id l15-20020a170903120f00b001b3cac719cdmr4804993plh.18.1688716438426; Fri, 07 Jul 2023 00:53:58 -0700 (PDT) Received: from google.com ([2401:fa00:1:10:7493:8870:1e91:754]) by smtp.gmail.com with ESMTPSA id u15-20020a170902e5cf00b001b1c3542f57sm2611449plf.103.2023.07.07.00.53.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 Jul 2023 00:53:58 -0700 (PDT) Date: Fri, 7 Jul 2023 15:53:54 +0800 From: Chen-Yu Tsai To: =?iso-8859-1?Q?N=EDcolas_F=2E_R=2E_A=2E?= Prado Cc: Daniel Lezcano , kernel@collabora.com, AngeloGioacchino Del Regno , Bernhard =?iso-8859-1?Q?Rosenkr=E4nzer?= , 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: Re: [PATCH] thermal/drivers/mediatek/lvts_thermal: Make readings valid in filtered mode Message-ID: <20230707075354.GA1333497@google.com> References: <20230706161509.204546-1-nfraprado@collabora.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20230706161509.204546-1-nfraprado@collabora.com> X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FSL_HELO_FAKE, RCVD_IN_DNSWL_NONE,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 On Thu, Jul 06, 2023 at 12:14:33PM -0400, N?colas F. R. A. Prado wrote: > 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 on Hayato. Reading out the temperature is now quite reliable. > > --- > > 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 This hunk conflicts with thermal/drivers/mediatek/lvts_thermal: Disable undesired interrupts from your other series > #define LVTS_TSSEL_CONF 0x13121110 > #define LVTS_CALSCALE_CONF 0x300 > #define LVTS_MONINT_CONF 0x9FBF7BDE on this line. > @@ -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 >