Skip to content

Commit d917a62

Browse files
author
William Breathitt Gray
committed
counter: microchip-tcb-capture: Handle Signal1 read and Synapse
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: [email protected] Reviewed-by: Kamel Bouhara <[email protected]> Link: https://lore.kernel.org/r/[email protected]/ Signed-off-by: William Breathitt Gray <[email protected]>
1 parent ec0286d commit d917a62

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

drivers/counter/microchip-tcb-capture.c

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ struct mchp_tc_data {
2828
int qdec_mode;
2929
int num_channels;
3030
int channel[2];
31-
bool trig_inverted;
3231
};
3332

3433
static const enum counter_function mchp_tc_count_functions[] = {
@@ -153,7 +152,7 @@ static int mchp_tc_count_signal_read(struct counter_device *counter,
153152

154153
regmap_read(priv->regmap, ATMEL_TC_REG(priv->channel[0], SR), &sr);
155154

156-
if (priv->trig_inverted)
155+
if (signal->id == 1)
157156
sigstatus = (sr & ATMEL_TC_MTIOB);
158157
else
159158
sigstatus = (sr & ATMEL_TC_MTIOA);
@@ -171,6 +170,17 @@ static int mchp_tc_count_action_read(struct counter_device *counter,
171170
struct mchp_tc_data *const priv = counter_priv(counter);
172171
u32 cmr;
173172

173+
if (priv->qdec_mode) {
174+
*action = COUNTER_SYNAPSE_ACTION_BOTH_EDGES;
175+
return 0;
176+
}
177+
178+
/* Only TIOA signal is evaluated in non-QDEC mode */
179+
if (synapse->signal->id != 0) {
180+
*action = COUNTER_SYNAPSE_ACTION_NONE;
181+
return 0;
182+
}
183+
174184
regmap_read(priv->regmap, ATMEL_TC_REG(priv->channel[0], CMR), &cmr);
175185

176186
switch (cmr & ATMEL_TC_ETRGEDG) {
@@ -199,8 +209,8 @@ static int mchp_tc_count_action_write(struct counter_device *counter,
199209
struct mchp_tc_data *const priv = counter_priv(counter);
200210
u32 edge = ATMEL_TC_ETRGEDG_NONE;
201211

202-
/* QDEC mode is rising edge only */
203-
if (priv->qdec_mode)
212+
/* QDEC mode is rising edge only; only TIOA handled in non-QDEC mode */
213+
if (priv->qdec_mode || synapse->signal->id != 0)
204214
return -EINVAL;
205215

206216
switch (action) {

0 commit comments

Comments
 (0)