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 */
111120enum {
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+
371399static 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
378407static 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