Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp5645815rwi; Tue, 18 Oct 2022 02:00:40 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4MHhqv0nIj6l3nyuEKa6U9VyeW0RelYwarJ9o1+Pv/n44Ws3vdIXZIrDs3/+UeEg2bFgVN X-Received: by 2002:aa7:c144:0:b0:459:f897:793e with SMTP id r4-20020aa7c144000000b00459f897793emr1671367edp.8.1666083639794; Tue, 18 Oct 2022 02:00:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666083639; cv=none; d=google.com; s=arc-20160816; b=uqICLeIxFEbbTiOuF5pqq3deAuvOb1SVapEqqzWXAHXlg1CwwYNFtpJHxYg0HRtO6B YnT25iGBBMYGIggoZApblXJEw2GYtCX9M1404k+64Z1vqfyMd2N5aH/uTwzBeaBHg3JI wezJY6Uxu2eU5jHBDPPuqAVvLptnTMJa/3R6QU+Via6/bbCWjeceZsI0WGnty2ibSriW K6R94jhGSSd+HseGqBTX4/7wf9xdQFfyu5wD5pCwNS/uZSFL12jRAQwTDOdwlTDWNvK6 lk6NXDKYTBrrmqt4C3v1Hng3Cmjne16vDWLfs2uy/8eYJNgp5bF44WcgvMpHGxovAafn q2QQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=mJzeUW1UFkFqsunmmvpSAnfHIknWqTroU2tIgfKPq7E=; b=IU0xVswtaN/EpzhSKQlNEKjnfV1lgS8YZktq7xonIjQs2P6JoFkZ1W6rlMgpySgn9q 503hXjDKZo5IUeoCAu3vwRjMLZ/D21E9e6C8G7E0lpVjhuDSooMH7gUIlG90gKPFlZ0g TbnS64yWB0gv+c++9Sx8ds6JQsHHwJNMQnxBYe3dub7JtjkZBJAPbuHdf74fZpi+C6UD EyU97MP7CFSqpybiOvkIh6Um6/w2gaMh3z5jwOTbTMEhuNQ4vMCzW+XJUf4vVzs4GJcI cdXPsTSAi+y3BrcKmyitwHhc2tnEJkLJf3JK9u3OomTCZy7e4DF41qZvDEpD4FjvZijU v9VQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=hRFHIWEN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q13-20020a056402518d00b0045e00384e8asi894975edd.380.2022.10.18.02.00.12; Tue, 18 Oct 2022 02:00:39 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=hRFHIWEN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230377AbiJRION (ORCPT + 99 others); Tue, 18 Oct 2022 04:14:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48754 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230525AbiJRIN5 (ORCPT ); Tue, 18 Oct 2022 04:13:57 -0400 Received: from relay3-d.mail.gandi.net (relay3-d.mail.gandi.net [217.70.183.195]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9D0FA915D6; Tue, 18 Oct 2022 01:13:55 -0700 (PDT) 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-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20221017225404.67127-1-william.gray@linaro.org> X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.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