Skip to content

Commit f1204df

Browse files
William Breathitt Graygregkh
authored andcommitted
counter: microchip-tcb-capture: Handle Signal1 read and Synapse
commit d917a62 upstream. 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]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 6fb0106 commit f1204df

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
@@ -29,7 +29,6 @@ struct mchp_tc_data {
2929
int qdec_mode;
3030
int num_channels;
3131
int channel[2];
32-
bool trig_inverted;
3332
};
3433

3534
enum mchp_tc_count_function {
@@ -166,7 +165,7 @@ static int mchp_tc_count_signal_read(struct counter_device *counter,
166165

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

169-
if (priv->trig_inverted)
168+
if (signal->id == 1)
170169
sigstatus = (sr & ATMEL_TC_MTIOB);
171170
else
172171
sigstatus = (sr & ATMEL_TC_MTIOA);
@@ -184,6 +183,17 @@ static int mchp_tc_count_action_get(struct counter_device *counter,
184183
struct mchp_tc_data *const priv = counter->priv;
185184
u32 cmr;
186185

186+
if (priv->qdec_mode) {
187+
*action = COUNTER_SYNAPSE_ACTION_BOTH_EDGES;
188+
return 0;
189+
}
190+
191+
/* Only TIOA signal is evaluated in non-QDEC mode */
192+
if (synapse->signal->id != 0) {
193+
*action = COUNTER_SYNAPSE_ACTION_NONE;
194+
return 0;
195+
}
196+
187197
regmap_read(priv->regmap, ATMEL_TC_REG(priv->channel[0], CMR), &cmr);
188198

189199
switch (cmr & ATMEL_TC_ETRGEDG) {
@@ -212,8 +222,8 @@ static int mchp_tc_count_action_set(struct counter_device *counter,
212222
struct mchp_tc_data *const priv = counter->priv;
213223
u32 edge = ATMEL_TC_ETRGEDG_NONE;
214224

215-
/* QDEC mode is rising edge only */
216-
if (priv->qdec_mode)
225+
/* QDEC mode is rising edge only; only TIOA handled in non-QDEC mode */
226+
if (priv->qdec_mode || synapse->signal->id != 0)
217227
return -EINVAL;
218228

219229
switch (action) {

0 commit comments

Comments
 (0)