Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp3412793pxf; Mon, 22 Mar 2021 06:01:39 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxW34SkCy/UzSqWk90wDRdnqdhdgsXf5RICzr7xAUDaMoHfUw0g3Abvc5ptt/86kFw1Qic3 X-Received: by 2002:a05:6512:3283:: with SMTP id p3mr3942497lfe.570.1616418097808; Mon, 22 Mar 2021 06:01:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1616418097; cv=none; d=google.com; s=arc-20160816; b=Jx4hYnVgQxlpywYAPPlACE5+OCn0u28Kdx2IZoDtFtG4Y4gT5Yq54byLDu/XWxfH98 EeQGX9mXdcHJaOhBsJ3C4W/wFvhxMBwB5zGDnaDxGKf1i6z14aItBrJJ3TR4pvDvidaX tFwi5CG+YD0GdWVEm1+haWf5p538RsiWpCXSYSmI07Js69Lz8/+b7GMjDlrHW/fblBGV Fp2+yw6cP8qK9J7fafe4JyElVBr+x3GqcgN6mi0Sk1xWo/WozNNeyIIM8l2xRsOLA/IT xJtjsYbj8+QA6CAUkEouw5OSY6pxjH7W7qD5xCVvWiuj97YxmQ/k3cEkESnV9iVnYv6r qGCQ== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=bT4nwydt28c3RSd9JCAZYVC36WVtYmcdYkR8tDaZVH4=; b=OQktwLF0eBGUrlRAv3TQ6+T5JKjT4YdIH/psail0Eh+pMzN2XrZuz6z7KHLWNKOyRe iXtJm9zryDHmzxmdGyDzemZg3t2FsVHU71w1g2o72MQirXC7Wemn+Auxh4yZG+anYs9L s2oYYUL9v3mSUDnYJrq9AbvGeEunJ8CIC5NPb2OQZ3pxf1+FmUZOrglsrOYlQ16fJ7Oo fDHU4+rcBmWlRWSqnUyXamomDbyKNcUeBjfBSewmm1cS8q4621o45db55pTG2OBzB0Iz OwNAWJLaCMVwwsWsfhwWMNc/oaFHatFAM7K4G3lGd7NrNMSwbRmd1pLPMKUNARooBSrl ppgA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=jL2tQz8V; 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=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id bx22si8356699edb.438.2021.03.22.06.01.14; Mon, 22 Mar 2021 06:01:37 -0700 (PDT) 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; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=jL2tQz8V; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232773AbhCVNAZ (ORCPT + 99 others); Mon, 22 Mar 2021 09:00:25 -0400 Received: from mail.kernel.org ([198.145.29.99]:42228 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232760AbhCVMsM (ORCPT ); Mon, 22 Mar 2021 08:48:12 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 2BA17619B6; Mon, 22 Mar 2021 12:44:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1616417044; bh=m6DurxuMzZEzMMTp7cKzfYTjjKPLthFr8l+qTYn8IJQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jL2tQz8VEJlt8nPCgaAQMZ3qGocIAwB0Vl+Fn5OkI+yWgqz+wxbwp/MkWTUADouS+ MVsTQGBUa2f6IhK64Ph4GUluNDgj83RMrmWLycJ92mgNR/eN5ayiyRSr6sIzaQTh/w LYJFp4oGlpoqM70Z4o1HmpzrU+66QuSOMraNmkMo= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Fabrice Gasnier , Maxime Coquelin , Alexandre Torgue , William Breathitt Gray , Fabrice Gasnier , Jonathan Cameron , Sasha Levin Subject: [PATCH 5.4 32/60] counter: stm32-timer-cnt: Report count function when SLAVE_MODE_DISABLED Date: Mon, 22 Mar 2021 13:28:20 +0100 Message-Id: <20210322121923.447284395@linuxfoundation.org> X-Mailer: git-send-email 2.31.0 In-Reply-To: <20210322121922.372583154@linuxfoundation.org> References: <20210322121922.372583154@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: William Breathitt Gray [ Upstream commit fae6f62e6a580b663ecf42c2120a0898deae9137 ] 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 Reviewed-by: Fabrice Gasnier Link: https://lore.kernel.org/r/20210226012931.161429-1-vilhelm.gray@gmail.com Signed-off-by: Jonathan Cameron Signed-off-by: Sasha Levin --- drivers/counter/stm32-timer-cnt.c | 39 ++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 14 deletions(-) diff --git a/drivers/counter/stm32-timer-cnt.c b/drivers/counter/stm32-timer-cnt.c index 644ba18a72ad..c680c7abdd26 100644 --- a/drivers/counter/stm32-timer-cnt.c +++ b/drivers/counter/stm32-timer-cnt.c @@ -35,13 +35,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, @@ -88,6 +89,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; @@ -97,9 +101,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, @@ -110,6 +114,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; @@ -120,8 +127,7 @@ static int stm32_count_function_set(struct counter_device *counter, sms = 3; break; default: - sms = 0; - break; + return -EINVAL; } /* Store enable status */ @@ -269,31 +275,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 = { -- 2.30.1