From patchwork Mon Oct 17 22:54:04 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: 13009641 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 6F422C433FE for ; Mon, 17 Oct 2022 22:55:47 +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=XQQWK5nMFiCgrdVJCbaYK7vVc3AmizBaQ+Fmjr9+q94=; b=vthhFNsPWGUzMI lX97nElyG313GzChQYybinUy/NlU3iRY+99qSPOPImefGR2qUC/n+cAapF2f2M9KoClnUUkCgbkp3 UIS/y5eKlcnYUQrzluu4jR/x81YYS11vfc+nkG2tk3WGZNVQfTzJrhbHgwWCb1aSN8K6rweGpnoDE FZ0SZs76vAj4PZPSCbZ58oVq3LUO1avrO6Gne4hRMMdd0NIoR7VuJQhU16luSBnal2C3SDHcR2AiP imWq5egH3yj6vVChnIKEmIUiJo83HsAiOwgs8DAjA1UgV/phyjj7VmugACv1pRMqDgHrT21qV5Omq Bl5tgIjoyxDJex7e1+gw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1okZ0G-00FGlo-KG; Mon, 17 Oct 2022 22:54:36 +0000 Received: from mail-qk1-x72e.google.com ([2607:f8b0:4864:20::72e]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1okZ0C-00FGjO-GQ for linux-arm-kernel@lists.infradead.org; Mon, 17 Oct 2022 22:54:34 +0000 Received: by mail-qk1-x72e.google.com with SMTP id b25so7652098qkk.7 for ; Mon, 17 Oct 2022 15:54:28 -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=l1Mexi3DbJyE5x8I4sskOGI0Kl0weNbMfBZ28HFha2I=; b=G+VVV/nIqdIuzoizvBtuqpU6jTPkoDxoOhBUBWkyNMOzp5olRCaTXnLJUNSlWR537c 2I/usnZFVwwfouojQyDH+/oIgDZOWsxLYYtS2S+Hj6IZvy4P15FHwcCI1W1pKHhlG84B dle0W1Bu3IhXVK8OKNuqRfZwRnouM8gywQ701XDxRO/uKkFI/cPBHvH1/CPQ5M+g4Sn9 XxuHI1KSYD7NjEg/73Uu38CZjzESsBapRNXIHBh/UIpuEVWMvMHzMbTvj15J6mruKVsR /mvPvVnr2y4Kj/6PhInorv3R2Nc7fp4XCBM/wvkYHiPJxEEsbMRWsL+37XcGC/zcwh2l QPrw== 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=l1Mexi3DbJyE5x8I4sskOGI0Kl0weNbMfBZ28HFha2I=; b=KYZVejJE0G2npXAogUsktDrzlmlMoDBYMLf1GJ9aAVWfh1ChksF2Hq5cg4CpcQ9DDW fyezaZRu97DcsGuc1ATAIOM3U8HSulCnW0Ld9zBFddhvfJ+qu4zo9xA/SMo1fm4DOkFO jJ05wpYmdR1KoztT5fX0LpuHqlyeM33ohCa0NUj0O8tL/L4jVEq/xuc86S4wHSDpCuto rPUdLa33ODYo6YmhDwcsjGibNSiZbhN99p4CmTMby2FW3idNAnfXBu6W7XpDK+uokaBT foHtm92dmn61dGu2Vv5LhF+D6HtOa8ikrYakLvazf4Ej2HLCsFfhVHPhfZTDVmgZgLvw PtNw== X-Gm-Message-State: ACrzQf1z8I7XGFfb1N9N7wesbjzdMdnxwqL2jGqUYLAW8C4DWP8ZSQp3 KYnVihf46//AvN13nbScJAZLAw== X-Google-Smtp-Source: AMsMyM4b+4PFpIn3M0+u/YSe6yeAsBDlE0Ai0sYBJFsY8y10pR6/dGF0fH1Ue8Hb5gDPLSxWv9ijqw== X-Received: by 2002:a05:620a:a9c:b0:6ec:f03:9e5b with SMTP id v28-20020a05620a0a9c00b006ec0f039e5bmr9314606qkg.628.1666047267901; Mon, 17 Oct 2022 15:54:27 -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 bv8-20020a05622a0a0800b0038b684a1642sm755675qtb.32.2022.10.17.15.54.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Oct 2022 15:54:27 -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 , stable@kernel.org, Kamel Bouhara Subject: [PATCH] counter: microchip-tcb-capture: Handle Signal1 read and Synapse Date: Mon, 17 Oct 2022 18:54:04 -0400 Message-Id: <20221017225404.67127-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-20221017_155432_636702_2ADCDA3F X-CRM114-Status: GOOD ( 15.69 ) 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@kernel.org Cc: Kamel Bouhara Signed-off-by: William Breathitt Gray Reviewed-by: Kamel Bouhara --- drivers/counter/microchip-tcb-capture.c | 57 ++++++++++++++++--------- 1 file changed, 38 insertions(+), 19 deletions(-) diff --git a/drivers/counter/microchip-tcb-capture.c b/drivers/counter/microchip-tcb-capture.c index f9dee15d9777..438f82b07a03 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); @@ -169,26 +168,46 @@ static int mchp_tc_count_action_read(struct counter_device *counter, enum counter_synapse_action *action) { struct mchp_tc_data *const priv = counter_priv(counter); + const unsigned int cmr_reg = ATMEL_TC_REG(priv->channel[0], CMR); + enum counter_function function; + int err; u32 cmr; - regmap_read(priv->regmap, ATMEL_TC_REG(priv->channel[0], CMR), &cmr); + err = mchp_tc_count_function_read(counter, count, &function); + if (err) + return err; - switch (cmr & ATMEL_TC_ETRGEDG) { - default: - *action = COUNTER_SYNAPSE_ACTION_NONE; - break; - case ATMEL_TC_ETRGEDG_RISING: - *action = COUNTER_SYNAPSE_ACTION_RISING_EDGE; - break; - case ATMEL_TC_ETRGEDG_FALLING: - *action = COUNTER_SYNAPSE_ACTION_FALLING_EDGE; - break; - case ATMEL_TC_ETRGEDG_BOTH: + /* Default action mode */ + *action = COUNTER_SYNAPSE_ACTION_NONE; + + switch (function) { + case COUNTER_FUNCTION_INCREASE: + /* TIOB signal is ignored */ + if (synapse->signal->id == 1) + return 0; + + regmap_read(priv->regmap, cmr_reg, &cmr); + + switch (cmr & ATMEL_TC_ETRGEDG) { + case ATMEL_TC_ETRGEDG_RISING: + *action = COUNTER_SYNAPSE_ACTION_RISING_EDGE; + return 0; + case ATMEL_TC_ETRGEDG_FALLING: + *action = COUNTER_SYNAPSE_ACTION_FALLING_EDGE; + return 0; + case ATMEL_TC_ETRGEDG_BOTH: + *action = COUNTER_SYNAPSE_ACTION_BOTH_EDGES; + return 0; + default: + return 0; + } + case COUNTER_FUNCTION_QUADRATURE_X4: *action = COUNTER_SYNAPSE_ACTION_BOTH_EDGES; - break; + return 0; + default: + /* should never reach this path */ + return -EINVAL; } - - return 0; } static int mchp_tc_count_action_write(struct counter_device *counter, @@ -199,8 +218,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) {