Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp2034455pxb; Sat, 27 Feb 2021 08:13:37 -0800 (PST) X-Google-Smtp-Source: ABdhPJyRsiDKbsB9sstOgGcWzG4MIoG+kx/CYdZBNKEKlXBkudtLFCcr45KLpiN9Bpwgu9kF3JcN X-Received: by 2002:a05:6402:1d33:: with SMTP id dh19mr2204234edb.362.1614442416783; Sat, 27 Feb 2021 08:13:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614442416; cv=none; d=google.com; s=arc-20160816; b=Bx47cZN0Ql/2NfhUQ73dYAnGMLCl4yrBBvpUM9J9WJ+D29R6I8OlGHILjG3BPU1x4K mLHighJtynTnDOJQ8Gv1xW+L+/XSEOnndShLBtRDpVtOYI3dkygtS/a9LFuRmNBKkv0N 0kibperi+3JFPjwyznpoyMumypsPcbdh3KQyvkJZBzUEwO3GB/XoocDY5CMpwWYmfSn7 0jGqL37Zbzdv8MqZJ2IR3wejWYzhXb+RpsGV2VVYKSmvaBtFRp3rx0c/evBZ0w93hb9T jpyZSpAESbuRR1QnOzC2j0fsMnAF0ViSRMVINtFpsUoAfKTeand3WpVltOp2KdAnezZp GU5A== 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=KWrwhzAPWHInj+HciAWHR0LGRHXpeGPl2GREc/sohds=; b=Zqm5VovZbuugJIDyXrGpWsjAKq9NPEr/4Cw/pUl5Q7oA/zNpMwZ71mjDZX6PKvbGtF LNNCUFffTWcxUS6oj9w1C2mOHss6HafP1zZjyfb5/pIZ7X1Zr49lP+/TZcVs+cBSHipo 0x7kJajFgMSzDvabXW8OQ/GxoowCHHGetYn7JgiupH0ccaGyHYN8SMOlaDpcRYRl1O8W 4ZKlJHw6wZ5NACrktoRmMXsmSJJQDdThIWbMeylv7SKm9qw+HAJluZFu3WajOFBOrhgT 4m/oZ456P6b+wgPQt7cW/3RVaSlwGit6Ch4PQ2oOjfThp7Yj6S1E019OFPX1Q8wfGGNS X2dg== 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 z12si7691305ejc.694.2021.02.27.08.13.14; Sat, 27 Feb 2021 08:13:36 -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 S230102AbhB0QMX (ORCPT + 99 others); Sat, 27 Feb 2021 11:12:23 -0500 Received: from mail.kernel.org ([198.145.29.99]:55552 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230063AbhB0QMG (ORCPT ); Sat, 27 Feb 2021 11:12:06 -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 AE30A64E4D; Sat, 27 Feb 2021 16:11:21 +0000 (UTC) Date: Sat, 27 Feb 2021 16:11:15 +0000 From: Jonathan Cameron To: Fabrice Gasnier Cc: William Breathitt Gray , , , , , , , , Subject: Re: [PATCH v2] counter: stm32-timer-cnt: Report count function when SLAVE_MODE_DISABLED Message-ID: <20210227161115.28fdda76@archlinux> In-Reply-To: References: <20210226012931.161429-1-vilhelm.gray@gmail.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 Fri, 26 Feb 2021 16:24:32 +0100 Fabrice Gasnier wrote: > On 2/26/21 2:29 AM, William Breathitt Gray wrote: > > When in SLAVE_MODE_DISABLED mode, the count still increases if the > > counter is enabled because an internal clock is used. This patch fixes > > the stm32_count_function_get() and stm32_count_function_set() functions > > to properly handle this behavior. > > > > Fixes: ad29937e206f ("counter: Add STM32 Timer quadrature encoder") > > Cc: Fabrice Gasnier > > Cc: Maxime Coquelin > > Cc: Alexandre Torgue > > Signed-off-by: William Breathitt Gray > > --- > > Changes in v2: > > - Support an explicit 0 case for function_get()/function_set() > > > > drivers/counter/stm32-timer-cnt.c | 39 ++++++++++++++++++++----------- > > 1 file changed, 25 insertions(+), 14 deletions(-) > > Hi William, > > Reviewed-by: Fabrice Gasnier Applied to the fixes-togreg branch of iio.git Thanks, Jonathan > > Many thanks for this fix. > Best Regards, > Fabrice > > > > > > diff --git a/drivers/counter/stm32-timer-cnt.c b/drivers/counter/stm32-timer-cnt.c > > index ef2a974a2f10..cd50dc12bd02 100644 > > --- a/drivers/counter/stm32-timer-cnt.c > > +++ b/drivers/counter/stm32-timer-cnt.c > > @@ -44,13 +44,14 @@ struct stm32_timer_cnt { > > * @STM32_COUNT_ENCODER_MODE_3: counts on both TI1FP1 and TI2FP2 edges > > */ > > enum stm32_count_function { > > - STM32_COUNT_SLAVE_MODE_DISABLED = -1, > > + STM32_COUNT_SLAVE_MODE_DISABLED, > > STM32_COUNT_ENCODER_MODE_1, > > STM32_COUNT_ENCODER_MODE_2, > > STM32_COUNT_ENCODER_MODE_3, > > }; > > > > static enum counter_count_function stm32_count_functions[] = { > > + [STM32_COUNT_SLAVE_MODE_DISABLED] = COUNTER_COUNT_FUNCTION_INCREASE, > > [STM32_COUNT_ENCODER_MODE_1] = COUNTER_COUNT_FUNCTION_QUADRATURE_X2_A, > > [STM32_COUNT_ENCODER_MODE_2] = COUNTER_COUNT_FUNCTION_QUADRATURE_X2_B, > > [STM32_COUNT_ENCODER_MODE_3] = COUNTER_COUNT_FUNCTION_QUADRATURE_X4, > > @@ -90,6 +91,9 @@ static int stm32_count_function_get(struct counter_device *counter, > > regmap_read(priv->regmap, TIM_SMCR, &smcr); > > > > switch (smcr & TIM_SMCR_SMS) { > > + case 0: > > + *function = STM32_COUNT_SLAVE_MODE_DISABLED; > > + return 0; > > case 1: > > *function = STM32_COUNT_ENCODER_MODE_1; > > return 0; > > @@ -99,9 +103,9 @@ static int stm32_count_function_get(struct counter_device *counter, > > case 3: > > *function = STM32_COUNT_ENCODER_MODE_3; > > return 0; > > + default: > > + return -EINVAL; > > } > > - > > - return -EINVAL; > > } > > > > static int stm32_count_function_set(struct counter_device *counter, > > @@ -112,6 +116,9 @@ static int stm32_count_function_set(struct counter_device *counter, > > u32 cr1, sms; > > > > switch (function) { > > + case STM32_COUNT_SLAVE_MODE_DISABLED: > > + sms = 0; > > + break; > > case STM32_COUNT_ENCODER_MODE_1: > > sms = 1; > > break; > > @@ -122,8 +129,7 @@ static int stm32_count_function_set(struct counter_device *counter, > > sms = 3; > > break; > > default: > > - sms = 0; > > - break; > > + return -EINVAL; > > } > > > > /* Store enable status */ > > @@ -274,31 +280,36 @@ static int stm32_action_get(struct counter_device *counter, > > size_t function; > > int err; > > > > - /* Default action mode (e.g. STM32_COUNT_SLAVE_MODE_DISABLED) */ > > - *action = STM32_SYNAPSE_ACTION_NONE; > > - > > err = stm32_count_function_get(counter, count, &function); > > if (err) > > - return 0; > > + return err; > > > > switch (function) { > > + case STM32_COUNT_SLAVE_MODE_DISABLED: > > + /* counts on internal clock when CEN=1 */ > > + *action = STM32_SYNAPSE_ACTION_NONE; > > + return 0; > > case STM32_COUNT_ENCODER_MODE_1: > > /* counts up/down on TI1FP1 edge depending on TI2FP2 level */ > > if (synapse->signal->id == count->synapses[0].signal->id) > > *action = STM32_SYNAPSE_ACTION_BOTH_EDGES; > > - break; > > + else > > + *action = STM32_SYNAPSE_ACTION_NONE; > > + return 0; > > case STM32_COUNT_ENCODER_MODE_2: > > /* counts up/down on TI2FP2 edge depending on TI1FP1 level */ > > if (synapse->signal->id == count->synapses[1].signal->id) > > *action = STM32_SYNAPSE_ACTION_BOTH_EDGES; > > - break; > > + else > > + *action = STM32_SYNAPSE_ACTION_NONE; > > + return 0; > > case STM32_COUNT_ENCODER_MODE_3: > > /* counts up/down on both TI1FP1 and TI2FP2 edges */ > > *action = STM32_SYNAPSE_ACTION_BOTH_EDGES; > > - break; > > + return 0; > > + default: > > + return -EINVAL; > > } > > - > > - return 0; > > } > > > > static const struct counter_ops stm32_timer_cnt_ops = { > >