Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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 <dlechner@baylibre.com>
Link: https://lore.kernel.org/r/20250110-counter-ti-eqep-add-direction-support-v2-4-c6b6f96d2db9@baylibre.com
Signed-off-by: William Breathitt Gray <wbg@kernel.org>

authored by

David Lechner and committed by
William Breathitt Gray
c2a75666 37f7a388

+32
+32
drivers/counter/ti-eqep.c
··· 107 107 #define QCLR_PCE BIT(1) 108 108 #define QCLR_INT BIT(0) 109 109 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 + 110 119 /* EQEP Inputs */ 111 120 enum { 112 121 TI_EQEP_SIGNAL_QEPA, /* QEPA/XCLK */ ··· 295 286 case COUNTER_EVENT_UNDERFLOW: 296 287 qeint |= QEINT_PCU; 297 288 break; 289 + case COUNTER_EVENT_DIRECTION_CHANGE: 290 + qeint |= QEINT_QDC; 291 + break; 298 292 } 299 293 } 300 294 ··· 310 298 switch (watch->event) { 311 299 case COUNTER_EVENT_OVERFLOW: 312 300 case COUNTER_EVENT_UNDERFLOW: 301 + case COUNTER_EVENT_DIRECTION_CHANGE: 313 302 if (watch->channel != 0) 314 303 return -EINVAL; 315 304 ··· 381 368 return 0; 382 369 } 383 370 371 + static int ti_eqep_direction_read(struct counter_device *counter, 372 + struct counter_count *count, 373 + enum counter_count_direction *direction) 374 + { 375 + struct ti_eqep_cnt *priv = counter_priv(counter); 376 + u32 qepsts; 377 + 378 + regmap_read(priv->regmap16, QEPSTS, &qepsts); 379 + 380 + *direction = (qepsts & QEPSTS_QDF) ? COUNTER_COUNT_DIRECTION_FORWARD 381 + : COUNTER_COUNT_DIRECTION_BACKWARD; 382 + 383 + return 0; 384 + } 385 + 384 386 static struct counter_comp ti_eqep_position_ext[] = { 385 387 COUNTER_COMP_CEILING(ti_eqep_position_ceiling_read, 386 388 ti_eqep_position_ceiling_write), 387 389 COUNTER_COMP_ENABLE(ti_eqep_position_enable_read, 388 390 ti_eqep_position_enable_write), 391 + COUNTER_COMP_DIRECTION(ti_eqep_direction_read), 389 392 }; 390 393 391 394 static struct counter_signal ti_eqep_signals[] = { ··· 467 438 468 439 if (qflg & QFLG_PCU) 469 440 counter_push_event(counter, COUNTER_EVENT_UNDERFLOW, 0); 441 + 442 + if (qflg & QFLG_QDC) 443 + counter_push_event(counter, COUNTER_EVENT_DIRECTION_CHANGE, 0); 470 444 471 445 regmap_write(priv->regmap16, QCLR, qflg); 472 446