Skip to content

Commit c2a7566

Browse files
dlechWilliam Breathitt Gray
authored andcommitted
counter: ti-eqep: add direction support
Add support for reading the direction and for emitting direction change events to the ti-eqep counter driver. Signed-off-by: David Lechner <[email protected]> Link: https://lore.kernel.org/r/20250110-counter-ti-eqep-add-direction-support-v2-4-c6b6f96d2db9@baylibre.com Signed-off-by: William Breathitt Gray <[email protected]>
1 parent 37f7a38 commit c2a7566

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

drivers/counter/ti-eqep.c

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,15 @@
107107
#define QCLR_PCE BIT(1)
108108
#define QCLR_INT BIT(0)
109109

110+
#define QEPSTS_UPEVNT BIT(7)
111+
#define QEPSTS_FDF BIT(6)
112+
#define QEPSTS_QDF BIT(5)
113+
#define QEPSTS_QDLF BIT(4)
114+
#define QEPSTS_COEF BIT(3)
115+
#define QEPSTS_CDEF BIT(2)
116+
#define QEPSTS_FIMF BIT(1)
117+
#define QEPSTS_PCEF BIT(0)
118+
110119
/* EQEP Inputs */
111120
enum {
112121
TI_EQEP_SIGNAL_QEPA, /* QEPA/XCLK */
@@ -286,6 +295,9 @@ static int ti_eqep_events_configure(struct counter_device *counter)
286295
case COUNTER_EVENT_UNDERFLOW:
287296
qeint |= QEINT_PCU;
288297
break;
298+
case COUNTER_EVENT_DIRECTION_CHANGE:
299+
qeint |= QEINT_QDC;
300+
break;
289301
}
290302
}
291303

@@ -298,6 +310,7 @@ static int ti_eqep_watch_validate(struct counter_device *counter,
298310
switch (watch->event) {
299311
case COUNTER_EVENT_OVERFLOW:
300312
case COUNTER_EVENT_UNDERFLOW:
313+
case COUNTER_EVENT_DIRECTION_CHANGE:
301314
if (watch->channel != 0)
302315
return -EINVAL;
303316

@@ -368,11 +381,27 @@ static int ti_eqep_position_enable_write(struct counter_device *counter,
368381
return 0;
369382
}
370383

384+
static int ti_eqep_direction_read(struct counter_device *counter,
385+
struct counter_count *count,
386+
enum counter_count_direction *direction)
387+
{
388+
struct ti_eqep_cnt *priv = counter_priv(counter);
389+
u32 qepsts;
390+
391+
regmap_read(priv->regmap16, QEPSTS, &qepsts);
392+
393+
*direction = (qepsts & QEPSTS_QDF) ? COUNTER_COUNT_DIRECTION_FORWARD
394+
: COUNTER_COUNT_DIRECTION_BACKWARD;
395+
396+
return 0;
397+
}
398+
371399
static struct counter_comp ti_eqep_position_ext[] = {
372400
COUNTER_COMP_CEILING(ti_eqep_position_ceiling_read,
373401
ti_eqep_position_ceiling_write),
374402
COUNTER_COMP_ENABLE(ti_eqep_position_enable_read,
375403
ti_eqep_position_enable_write),
404+
COUNTER_COMP_DIRECTION(ti_eqep_direction_read),
376405
};
377406

378407
static struct counter_signal ti_eqep_signals[] = {
@@ -439,6 +468,9 @@ static irqreturn_t ti_eqep_irq_handler(int irq, void *dev_id)
439468
if (qflg & QFLG_PCU)
440469
counter_push_event(counter, COUNTER_EVENT_UNDERFLOW, 0);
441470

471+
if (qflg & QFLG_QDC)
472+
counter_push_event(counter, COUNTER_EVENT_DIRECTION_CHANGE, 0);
473+
442474
regmap_write(priv->regmap16, QCLR, qflg);
443475

444476
return IRQ_HANDLED;

0 commit comments

Comments
 (0)