Skip to content

Commit ae3392c

Browse files
Dharma-BWilliam Breathitt Gray
authored andcommitted
counter: microchip-tcb-capture: Add watch validation support
The Timer Counter Block (TCB) exposes several kinds of events to the Counter framework, but not every event is meaningful on every hardware channel. Add a `watch_validate()` callback so userspace may register only the combinations actually supported: * Channel 0 (COUNTER_MCHP_EVCHN_CV, COUNTER_MCHP_EVCHN_RA) - COUNTER_EVENT_CAPTURE - COUNTER_EVENT_CHANGE_OF_STATE - COUNTER_EVENT_OVERFLOW * Channel 1 (COUNTER_MCHP_EVCHN_RB) - COUNTER_EVENT_CAPTURE * Channel 2 (COUNTER_MCHP_EVCHN_RC) - COUNTER_EVENT_THRESHOLD Any other request is rejected with `-EINVAL`. Signed-off-by: Dharma Balasubiramani <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: William Breathitt Gray <[email protected]>
1 parent ace2cd1 commit ae3392c

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

drivers/counter/microchip-tcb-capture.c

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,28 @@ static struct counter_comp mchp_tc_count_ext[] = {
337337
COUNTER_COMP_COMPARE(mchp_tc_count_compare_read, mchp_tc_count_compare_write),
338338
};
339339

340+
static int mchp_tc_watch_validate(struct counter_device *counter,
341+
const struct counter_watch *watch)
342+
{
343+
if (watch->channel == COUNTER_MCHP_EVCHN_CV || watch->channel == COUNTER_MCHP_EVCHN_RA)
344+
switch (watch->event) {
345+
case COUNTER_EVENT_CHANGE_OF_STATE:
346+
case COUNTER_EVENT_OVERFLOW:
347+
case COUNTER_EVENT_CAPTURE:
348+
return 0;
349+
default:
350+
return -EINVAL;
351+
}
352+
353+
if (watch->channel == COUNTER_MCHP_EVCHN_RB && watch->event == COUNTER_EVENT_CAPTURE)
354+
return 0;
355+
356+
if (watch->channel == COUNTER_MCHP_EVCHN_RC && watch->event == COUNTER_EVENT_THRESHOLD)
357+
return 0;
358+
359+
return -EINVAL;
360+
}
361+
340362
static struct counter_count mchp_tc_counts[] = {
341363
{
342364
.id = 0,
@@ -356,7 +378,8 @@ static const struct counter_ops mchp_tc_ops = {
356378
.function_read = mchp_tc_count_function_read,
357379
.function_write = mchp_tc_count_function_write,
358380
.action_read = mchp_tc_count_action_read,
359-
.action_write = mchp_tc_count_action_write
381+
.action_write = mchp_tc_count_action_write,
382+
.watch_validate = mchp_tc_watch_validate,
360383
};
361384

362385
static const struct atmel_tcb_config tcb_rm9200_config = {

0 commit comments

Comments
 (0)