From patchwork Tue Oct 18 12:10:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: William Breathitt Gray X-Patchwork-Id: 13010437 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 4C59AC4332F for ; Tue, 18 Oct 2022 12:11:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:Cc :To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=W8i49uv/TOwlGmw/UlwD7NRWoKlMvbGOkdNPZHzXOmM=; b=1oEecmbC+GFhZ1 pp+9gl+4DA1+sFRTlwXYVsfOzQmJrCbejQcMW/ZQk6rXKw5OwSsQqf90xZyu2t3gnuErv6hbQS3mI fOy+4q6ErTXfHbR5V04LN0F+WdRSB7Z0Dbk89yHPl0yO6QKlHwouInT2QfYEt9ltncBl9+sacjzf5 bfE8zJEZIJ3qXGyL5wz9OrsViOes7J4f5bIv4yL7U3koQjkpdqO9S2HR2gp/jfWSmXrC13QPYWlYS Rq+kOpRrddxa/GMiODlwGBqiMAd1nDI1sz7M2kdE/bBzGikbDEtsnSNWZHKsY1BRkdwvL2Y9bGgnu JjpH4ht+85BUcMs6qgjg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oklQR-006Z8T-GP; Tue, 18 Oct 2022 12:10:27 +0000 Received: from mail-ot1-x336.google.com ([2607:f8b0:4864:20::336]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oklQO-006Z7w-Ep for linux-arm-kernel@lists.infradead.org; Tue, 18 Oct 2022 12:10:25 +0000 Received: by mail-ot1-x336.google.com with SMTP id e53-20020a9d01b8000000b006619152f3cdso7477862ote.0 for ; Tue, 18 Oct 2022 05:10:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=sqIGFF02dOX61CeJGtzYtpVGadQKDl0ST8ygfx0xxyk=; b=SE0h0V1PdBrlN7sPGSVPZed0BbibTZmQGB+yWcLc785hrDuhvlUzhKj5+LAeiwvmRp HXWIK5YLXREvy5NDpUkzl2oqzmwYa+Hjv3T/xKouaNbhIPMiTeUbqCr5lIp2CN+/Erx0 ssNCjNoCJPT7jr+VzhNLw8PdMclJWqz5QXoN0mUtvNrqyuoZDaMvq5t++6YCsWjVZFYR hK7ogTULSBDYl/KpAI15dgzsDZzATWrFvZttQoX8c2z/k6SmDyqkD0hhHsiNarKFJzxf E70ehtCE1mImVUQdECpbYGbyDX2vPOYYtbE//W3e5S0DTwzrEgL/HNeF+wia6bdBmONK BFcg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=sqIGFF02dOX61CeJGtzYtpVGadQKDl0ST8ygfx0xxyk=; b=wBRL9NFEheBkKsqhZBadFLKd2wx7fN3Lg/u2QKWWUkeh/pm9X+40zpaAUPUXO4310/ MYfgH1D8nIm+d//rXQ94G7BQ3UszL4znlFLw1hdl7UoMIEIkgF+XMReRw1d18jx97k/K Pslc56OlG6RWkNHHm2FxQCxbOioixpyamwYsSRTDg404hS4SawoJekX/gUpzum6hizjg KO1VI7GZaTGHlmJh7nnz/p1AiIscSSPtnL9/8tsF4KtTaf21w5s229EV5SLlV3IcdBY0 Lgw/dbWE4D6AcK6vkk3wvZJQsjdA4hbWa7Y8xTzivdPebm/Js6ZPnEaN6KUEOA7CDqkg 5qGA== X-Gm-Message-State: ACrzQf2N1FGIBdpu88E7P0hR88coF6au46P4B1zbCRrhROIEKkHDgeHq XmD9SPlAqE1AgJK2LMI4mf3h8Q== X-Google-Smtp-Source: AMsMyM6xWo57saFHMqU9gzS6cbmC8IN1slWlfsaCn1nv7yc+VWbgWZ9Sfp96e7jtBvtVFbXtOCfQxw== X-Received: by 2002:a05:6830:b93:b0:660:eef5:76b6 with SMTP id a19-20020a0568300b9300b00660eef576b6mr1159698otv.18.1666095022396; Tue, 18 Oct 2022 05:10:22 -0700 (PDT) Received: from fedora.attlocal.net (69-109-179-158.lightspeed.dybhfl.sbcglobal.net. [69.109.179.158]) by smtp.gmail.com with ESMTPSA id x8-20020a056830408800b0065c2c46077dsm5737102ott.67.2022.10.18.05.10.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Oct 2022 05:10:21 -0700 (PDT) From: William Breathitt Gray To: linux-iio@vger.kernel.org Cc: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, stable@vger.kernel.org, William Breathitt Gray , Kamel Bouhara Subject: [PATCH v2] counter: microchip-tcb-capture: Handle Signal1 read and Synapse Date: Tue, 18 Oct 2022 08:10:14 -0400 Message-Id: <20221018121014.7368-1-william.gray@linaro.org> X-Mailer: git-send-email 2.37.3 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20221018_051024_552388_3743C9A9 X-CRM114-Status: GOOD ( 16.11 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org The signal_read(), action_read(), and action_write() callbacks have been assuming Signal0 is requested without checking. This results in requests for Signal1 returning data for Signal0. This patch fixes these oversights by properly checking for the Signal's id in the respective callbacks and handling accordingly based on the particular Signal requested. The trig_inverted member of the mchp_tc_data is removed as superfluous. Fixes: 106b104137fd ("counter: Add microchip TCB capture counter") Cc: stable@vger.kernel.org Cc: Kamel Bouhara Signed-off-by: William Breathitt Gray --- Changes in v2: - Simplified action_read() changes to just handle qdec_mode and non-TIOA Signals before continuing with existing code drivers/counter/microchip-tcb-capture.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/drivers/counter/microchip-tcb-capture.c b/drivers/counter/microchip-tcb-capture.c index f9dee15d9777..e2d1dc6ca668 100644 --- a/drivers/counter/microchip-tcb-capture.c +++ b/drivers/counter/microchip-tcb-capture.c @@ -28,7 +28,6 @@ struct mchp_tc_data { int qdec_mode; int num_channels; int channel[2]; - bool trig_inverted; }; static const enum counter_function mchp_tc_count_functions[] = { @@ -153,7 +152,7 @@ static int mchp_tc_count_signal_read(struct counter_device *counter, regmap_read(priv->regmap, ATMEL_TC_REG(priv->channel[0], SR), &sr); - if (priv->trig_inverted) + if (signal->id == 1) sigstatus = (sr & ATMEL_TC_MTIOB); else sigstatus = (sr & ATMEL_TC_MTIOA); @@ -171,6 +170,17 @@ static int mchp_tc_count_action_read(struct counter_device *counter, struct mchp_tc_data *const priv = counter_priv(counter); u32 cmr; + if (priv->qdec_mode) { + *action = COUNTER_SYNAPSE_ACTION_BOTH_EDGES; + return 0; + } + + /* Only TIOA signal is evaluated in non-QDEC mode */ + if (synapse->signal->id != 0) { + *action = COUNTER_SYNAPSE_ACTION_NONE; + return 0; + } + regmap_read(priv->regmap, ATMEL_TC_REG(priv->channel[0], CMR), &cmr); switch (cmr & ATMEL_TC_ETRGEDG) { @@ -199,8 +209,8 @@ static int mchp_tc_count_action_write(struct counter_device *counter, struct mchp_tc_data *const priv = counter_priv(counter); u32 edge = ATMEL_TC_ETRGEDG_NONE; - /* QDEC mode is rising edge only */ - if (priv->qdec_mode) + /* QDEC mode is rising edge only; only TIOA handled in non-QDEC mode */ + if (priv->qdec_mode || synapse->signal->id != 0) return -EINVAL; switch (action) {