Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp7895724pxb; Fri, 19 Feb 2021 02:03:44 -0800 (PST) X-Google-Smtp-Source: ABdhPJwX7dy866zwmyYvvIbdXNipyexO4Az3ctEcWW5gpJlIkAnDrNAtvh2MULqGF5OWQV6aV+5n X-Received: by 2002:aa7:cd87:: with SMTP id x7mr8676674edv.210.1613729024367; Fri, 19 Feb 2021 02:03:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1613729024; cv=none; d=google.com; s=arc-20160816; b=lxux0bmRgB/uAOXE0GbQgz5U5G93CjyIO4N45QBXyuAt/srpjnIy5tXDx4WHr2Rah0 MKgTi2ClMMB5u/D0e1LdMtXP4EEv1xd2Ojeo+DouRnCH0g3JxTwD5gnZD6FuWvKsystu U8y6paKCV3WUdBGcwlNkMQmI5GolC/HEZWFdcTCghqdaXkggwMA0kYJ6CsiT4jkKonlt vDKuG3wik1U9T1BKxDwF84ssGVpTrEV+OGVWApraZ00YtA4FqfhtXKQHTr/dNoti4fum M04oslzjUEGH1B3oYn1kfT2vMMmWtN0sWrj1r0shrHOO/SRxPrE7N8pz4w0PwcjXHWke yW6g== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=rO0e+NuITIQhnPgueO8o0H2uruJAZQF5INjcDz5MY5k=; b=kLbNPNFDFc+ffjikuFFPkVmy5ZTtVtLslv3vl5WIERd1qYts/bx+PQnSztcVD4T87q 3rF0w5sHW1mMrisiX4qBe0arCzBzzG3WwbDh9W4+BmbPikvfV9/tosUCzUgZ+68v/7IT oIm96YtccWUIkWGTwsAlb5Mtw+z9Ft7IYVaYwHFhI7PQ6mT3XfIm301VrcoKjgy2EdPX mYDjnOBKfEJ8Ba7m9ucWREPmmHMZzPfnd+t2SXolfrM2AcaPRt3DYB0JnEpI2dltLlbY MrJ6Kcx6nvEbXVPLv+oM9/4qdFbJW0CrS7qelIntRC18YpTcQ7pudhFHUmCBIS8prEbd Y35g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=Y0IzD+lG; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a26si5558741edx.311.2021.02.19.02.03.20; Fri, 19 Feb 2021 02:03:44 -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; dkim=pass header.i=@gmail.com header.s=20161025 header.b=Y0IzD+lG; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230218AbhBSKA1 (ORCPT + 99 others); Fri, 19 Feb 2021 05:00:27 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41942 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230209AbhBSKAJ (ORCPT ); Fri, 19 Feb 2021 05:00:09 -0500 Received: from mail-pj1-x102a.google.com (mail-pj1-x102a.google.com [IPv6:2607:f8b0:4864:20::102a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CB2DCC061574; Fri, 19 Feb 2021 01:59:27 -0800 (PST) Received: by mail-pj1-x102a.google.com with SMTP id fy5so3397141pjb.5; Fri, 19 Feb 2021 01:59:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=rO0e+NuITIQhnPgueO8o0H2uruJAZQF5INjcDz5MY5k=; b=Y0IzD+lGc6c+loGdb8VZjnxwjd1fqDUpS+RfBDHINBazzFZ176nBqigOl3s29SmnBr WEQbA6KkV+cfYe4DR6GmreHByy2Vac8HAJReV/SdlTzw+OEOZUG6U5UvqMfLJSG5Jpdx 9V03pBgHlaHX/jUbPbd+Ehu9F5eeHavFCLmLM4ysAGKlooCjRy/nPOTYHC2sRpKBbRRj wlWT8vvlBKbyvO2Ya94J0l94I7TS1T2uQmONsFgrnWLn8fpSr4NU3Gfy1b7vLMO5GUBS I0ZG9DYKFhEupLXhumjB5aqjLQcodfeqlHhkx96h79Zf7UlW3PJ5Ei7pK4DSxxlnx6HV I7bA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=rO0e+NuITIQhnPgueO8o0H2uruJAZQF5INjcDz5MY5k=; b=oztpiKYxD0tYNU7NUg7JiXhzkTlj9ndU967Oq8M+xU7JgkK+v/EicI/zgrV+aN6Qri uwLB6M28citc8QqwxN6OYgM3Y0D0ryH9uF8gGZw9uRuxxCocb51DEKnXxbp/daMw2TmL /BEQ51u2cntYjOHcEa1PQZqAjEBV57C/IxiVCb+UDHDiy1lhkRGeo+3kfdIKuDhvZetg WUQZkjWpKS+wY0kyBWFf0nBnES+RVOkGH2hSvrI1b37sGFXPqGt7Y8jMCh9o840L6abO lBd1vPJ/CaqnUdQjFVLG8jw36dzw0kHjAnuwYzQcF5CkuhfD332UzTJVpGUimlv0d/mB Cp9g== X-Gm-Message-State: AOAM533u/eKn8qfnKovrCVuh44TFloGTN+T/o2GFZmzLIo3HxTQy+D/S CMYKIdDVctqBKORNROHv7dk= X-Received: by 2002:a17:90a:b282:: with SMTP id c2mr8635023pjr.54.1613728767387; Fri, 19 Feb 2021 01:59:27 -0800 (PST) Received: from localhost.localdomain (113x37x72x20.ap113.ftth.ucom.ne.jp. [113.37.72.20]) by smtp.gmail.com with ESMTPSA id y16sm8361475pgg.20.2021.02.19.01.59.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Feb 2021 01:59:26 -0800 (PST) From: William Breathitt Gray To: jic23@kernel.org Cc: linux-iio@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, William Breathitt Gray , Fabrice Gasnier , Maxime Coquelin , Alexandre Torgue Subject: [PATCH] counter: stm32-timer-cnt: Report count function when SLAVE_MODE_DISABLED Date: Fri, 19 Feb 2021 18:59:06 +0900 Message-Id: <20210219095906.220382-1-vilhelm.gray@gmail.com> X-Mailer: git-send-email 2.30.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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() function to properly report 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 --- drivers/counter/stm32-timer-cnt.c | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/drivers/counter/stm32-timer-cnt.c b/drivers/counter/stm32-timer-cnt.c index ef2a974a2f10..ec6d9e89c028 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, @@ -99,9 +100,10 @@ static int stm32_count_function_get(struct counter_device *counter, case 3: *function = STM32_COUNT_ENCODER_MODE_3; return 0; + default: + *function = STM32_COUNT_SLAVE_MODE_DISABLED; + return 0; } - - return -EINVAL; } static int stm32_count_function_set(struct counter_device *counter, @@ -274,31 +276,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_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; + case STM32_COUNT_SLAVE_MODE_DISABLED: + /* counts on internal clock when CEN=1 */ + *action = STM32_SYNAPSE_ACTION_NONE; + return 0; + default: + return -EINVAL; } - - return 0; } static const struct counter_ops stm32_timer_cnt_ops = { -- 2.30.1