From mboxrd@z Thu Jan 1 00:00:00 1970 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 6EE04C4332F for ; Tue, 18 Oct 2022 08:15:01 +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:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=vL+8TuZomTh5wxS/Y1lG2UrUMcrbQdiCPUUAya+qYwM=; b=hMAW0BNtU4VbDI ShxNwD72oYJ8OU5qkOCOBb4Msr5UUs377zWarOPzUd7ROAKHq7Pj5pe5ARI5JXc5tr8OiTlTA2rEi oOsy7dnWHi0YX2tE2AcF+9W56IWi5i6NqR13fC/mSfrmO8u3JZSGXllBtl4MHPkVdHklTy/4Mywz/ nNQpLPVMnBi9e9OwT7aEHQ3txGwHUfojQ/07WOVpdBr5bLAz6bX1HY13Eycr2pU7bgiTOr3wb2e5F W6BHRXTSPScQfEVO3hBKwnGZrJqPompLrrlxG8v56iL8AipENFLeE++3Yb+jflU4k7KS+Wp0s+9+o 3rtkGpK+KDykjncL6U+w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1okhjd-004L52-1r; Tue, 18 Oct 2022 08:14:01 +0000 Received: from relay3-d.mail.gandi.net ([217.70.183.195]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1okhjY-004L3C-HP for linux-arm-kernel@lists.infradead.org; Tue, 18 Oct 2022 08:13:58 +0000 Received: (Authenticated sender: kamel.bouhara@bootlin.com) by mail.gandi.net (Postfix) with ESMTPSA id 4709260007; Tue, 18 Oct 2022 08:13:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1666080834; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=mJzeUW1UFkFqsunmmvpSAnfHIknWqTroU2tIgfKPq7E=; b=hRFHIWENzLdUlQmeCeIVuh+Klv8gGYW653bkCunGb5bIleKb0ftuEsgHmhxkqESIISTLRL s2XCluw8LBa4Ql2g2/izTNWrh7TG7xfcU1kGmgUL+r/9L8c6XPoo6Qzjxn+9+oA2+SQSd+ RpdYJdE0bhqcIuhBkll84l5aMGU6uBhcs2/n/pL7JMMcaI9tyl0X+boM8YNkVlCLHwN+Gm fdMIfpIfZQ+JUMhx7JRWAU0Hl65f0MdkHFMQTfg/TyrRTzngz3vcxN8/xefnomCsuGq8Pi aDN298Ftdy3WjNjzeqxqwrgjAE0lqGYyWtULExb/gXVLR9zE/0YrgP53Ghgk9w== Date: Tue, 18 Oct 2022 10:13:51 +0200 From: Kamel Bouhara To: William Breathitt Gray Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, stable@vger.kernel.org, stable@kernel.org Subject: Re: [PATCH] counter: microchip-tcb-capture: Handle Signal1 read and Synapse Message-ID: References: <20221017225404.67127-1-william.gray@linaro.org> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20221017225404.67127-1-william.gray@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20221018_011356_894245_E88C2619 X-CRM114-Status: GOOD ( 22.35 ) 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: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Mon, Oct 17, 2022 at 06:54:04PM -0400, William Breathitt Gray wrote: > 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 Looks ok to me, thanks. 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) { > -- > 2.37.3 > -- Kamel Bouhara, Bootlin Embedded Linux and kernel engineering https://bootlin.com _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel