Skip to content

Commit

Permalink
counter: microchip-tcb-capture: Handle Signal1 read and Synapse
Browse files Browse the repository at this point in the history
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: 106b104 ("counter: Add microchip TCB capture counter")
Cc: stable@vger.kernel.org
Reviewed-by: Kamel Bouhara <kamel.bouhara@bootlin.com>
Link: https://lore.kernel.org/r/20221018121014.7368-1-william.gray@linaro.org/
Signed-off-by: William Breathitt Gray <william.gray@linaro.org>
  • Loading branch information
William Breathitt Gray committed Oct 24, 2022
1 parent ec0286d commit d917a62
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions drivers/counter/microchip-tcb-capture.c
Original file line number Diff line number Diff line change
Expand Up @@ -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[] = {
Expand Down Expand Up @@ -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);
Expand All @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit d917a62

Please sign in to comment.