Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp567386pxb; Sat, 6 Mar 2021 08:53:59 -0800 (PST) X-Google-Smtp-Source: ABdhPJx6QJ3+fIpYgUPLYInpLjoQY1MZB8IqaS83sTJyH/X5GHn8yvtMPm84kOTFf9MSWUgixE3w X-Received: by 2002:a17:907:2d89:: with SMTP id gt9mr7540930ejc.226.1615049639589; Sat, 06 Mar 2021 08:53:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1615049639; cv=none; d=google.com; s=arc-20160816; b=aj86BOC/uf/e31elXBS+wF0xiW8qjDA4Fm2lUt6ofpdx5S2HqKbyCMp05OPlMEI7tZ AibWJnKsANwAmSDqqu6FWda0wDqZLcI2Z2cDOUIcCjA92z/VZnnJHM74q3WNTyFJQzBq 9QuNs8LOYIuRWv+FaxoruqPGlJYwxEFEnQMR1nKD/bBtw0+QyVQzzOaEG50fZyN9t6Ti v1us49Y58UIPv55FN5Jlm7pSFkAMKKIYd6AmQlOqBDhsI7MMc1TWdrl/hqi++FD3dm8l 3DC4TnXnSIkNnE59/iH00AmjSAEBj/D5YtRB0WHKAZX3VM4IDqjbVj89bP1MSJT7QMjK HJgg== 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 :references:in-reply-to:message-id:subject:cc:to:from:date; bh=pPdx9k9WAb9UQX/wyZlawWpvGmm8+9C8iFJqPWXPxgE=; b=mwd5HOfoRIzlMt3DZuSysfAiQ3XUCiWwP8WitI7m3sVkLaY2PtqvY0HkH19CfPMycB BRnv1//rLbFSlr1HokAuguJTj//ru0V9CY3WOAeFo61oje0uvoC+bmcGX/uAP5LsFxB6 ZFMan36EPq9nzk/YOcgkYPKvqiLGnpufdbIBNlc+zmlw8GoJ5g7oKhdzEgmgzwsbukn4 8EyDK+sFlO4+h/++j8wV/g22CDbRvhOKMz3Gwubj87FB4XbIDckFqCHLeGomfRlITvu4 3mc9JWIZ9rkpDf22jgh4S9zjb2U45fO53/aF6GvECoJjDvHcfMXwGdEqH6vO5DZon0ig c+8w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id dp16si3514546ejc.228.2021.03.06.08.53.37; Sat, 06 Mar 2021 08:53:59 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230429AbhCFQuY (ORCPT + 99 others); Sat, 6 Mar 2021 11:50:24 -0500 Received: from mail.kernel.org ([198.145.29.99]:53894 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230216AbhCFQt6 (ORCPT ); Sat, 6 Mar 2021 11:49:58 -0500 Received: from archlinux (cpc108967-cmbg20-2-0-cust86.5-4.cable.virginm.net [81.101.6.87]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 3932764FE9; Sat, 6 Mar 2021 16:49:56 +0000 (UTC) Date: Sat, 6 Mar 2021 16:49:49 +0000 From: Jonathan Cameron To: William Breathitt Gray Cc: Fabrice Gasnier , alexandre.torgue@foss.st.com, mcoquelin.stm32@gmail.com, olivier.moysan@foss.st.com, linux-iio@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] counter: stm32-timer-cnt: fix ceiling miss-alignment with reload register Message-ID: <20210306164949.2d59b5ff@archlinux> In-Reply-To: References: <1614793789-10346-1-git-send-email-fabrice.gasnier@foss.st.com> X-Mailer: Claws Mail 3.17.8 (GTK+ 2.24.33; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 4 Mar 2021 08:42:03 +0900 William Breathitt Gray wrote: > On Wed, Mar 03, 2021 at 06:49:49PM +0100, Fabrice Gasnier wrote: > > Ceiling value may be miss-aligned with what's actually configured into the > > ARR register. This is seen after probe as currently the ARR value is zero, > > whereas ceiling value is set to the maximum. So: > > - reading ceiling reports zero > > - in case the counter gets enabled without any prior configuration, > > it won't count. > > - in case the function gets set by the user 1st, (priv->ceiling) is used. > > > > Fix it by getting rid of the cached "priv->ceiling" variable. Rather use > > the ARR register value directly by using regmap read or write when needed. > > There should be no drawback on performance as priv->ceiling isn't used in > > performance critical path. > > There's also no point in writing ARR while setting function (sms), so > > it can be safely removed. > > > > Fixes: ad29937e206f ("counter: Add STM32 Timer quadrature encoder") Note, I've dropped the blank line here. Fixes is part of the tag block. > > > > Suggested-by: William Breathitt Gray > > Signed-off-by: Fabrice Gasnier > > Acked-by: William Breathitt Gray applied to the fixes-togreg branch of iio.git and marked for stable. Given both this and previous are marked such they should get picked up fine even without the clean cross reference. Jonathan > > > --- > > Note: this applies on top of: > > - "counter: stm32-timer-cnt: fix ceiling write max value" > > Note, if your patch requires prerequisite patches, please provide the > `git patch-id --stable` patch ID for it; this helps make sure the > patches are applied in the correct order. You can have `git > format-patch` generate this automatically for you by using the `--base` > option: > https://git-scm.com/docs/git-format-patch#_base_tree_information > > William Breathitt Gray > > > --- > > drivers/counter/stm32-timer-cnt.c | 11 +++-------- > > 1 file changed, 3 insertions(+), 8 deletions(-) > > > > diff --git a/drivers/counter/stm32-timer-cnt.c b/drivers/counter/stm32-timer-cnt.c > > index 2295be3..75bc401 100644 > > --- a/drivers/counter/stm32-timer-cnt.c > > +++ b/drivers/counter/stm32-timer-cnt.c > > @@ -31,7 +31,6 @@ struct stm32_timer_cnt { > > struct counter_device counter; > > struct regmap *regmap; > > struct clk *clk; > > - u32 ceiling; > > u32 max_arr; > > bool enabled; > > struct stm32_timer_regs bak; > > @@ -75,8 +74,10 @@ static int stm32_count_write(struct counter_device *counter, > > const unsigned long val) > > { > > struct stm32_timer_cnt *const priv = counter->priv; > > + u32 ceiling; > > > > - if (val > priv->ceiling) > > + regmap_read(priv->regmap, TIM_ARR, &ceiling); > > + if (val > ceiling) > > return -EINVAL; > > > > return regmap_write(priv->regmap, TIM_CNT, val); > > @@ -138,10 +139,6 @@ static int stm32_count_function_set(struct counter_device *counter, > > > > regmap_update_bits(priv->regmap, TIM_CR1, TIM_CR1_CEN, 0); > > > > - /* TIMx_ARR register shouldn't be buffered (ARPE=0) */ > > - regmap_update_bits(priv->regmap, TIM_CR1, TIM_CR1_ARPE, 0); > > - regmap_write(priv->regmap, TIM_ARR, priv->ceiling); > > - > > regmap_update_bits(priv->regmap, TIM_SMCR, TIM_SMCR_SMS, sms); > > > > /* Make sure that registers are updated */ > > @@ -199,7 +196,6 @@ static ssize_t stm32_count_ceiling_write(struct counter_device *counter, > > regmap_update_bits(priv->regmap, TIM_CR1, TIM_CR1_ARPE, 0); > > regmap_write(priv->regmap, TIM_ARR, ceiling); > > > > - priv->ceiling = ceiling; > > return len; > > } > > > > @@ -374,7 +370,6 @@ static int stm32_timer_cnt_probe(struct platform_device *pdev) > > > > priv->regmap = ddata->regmap; > > priv->clk = ddata->clk; > > - priv->ceiling = ddata->max_arr; > > priv->max_arr = ddata->max_arr; > > > > priv->counter.name = dev_name(dev); > > -- > > 2.7.4 > >