mirror of
				https://github.com/torvalds/linux.git
				synced 2025-10-31 16:48:26 +02:00 
			
		
		
		
	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 <dharma.b@microchip.com> Link: https://lore.kernel.org/r/20250520-counter-tcb-v3-1-4631e2aff7ed@microchip.com Signed-off-by: William Breathitt Gray <wbg@kernel.org>
This commit is contained in:
		
							parent
							
								
									ace2cd11a2
								
							
						
					
					
						commit
						ae3392c0f1
					
				
					 1 changed files with 24 additions and 1 deletions
				
			
		|  | @ -337,6 +337,28 @@ static struct counter_comp mchp_tc_count_ext[] = { | ||||||
| 	COUNTER_COMP_COMPARE(mchp_tc_count_compare_read, mchp_tc_count_compare_write), | 	COUNTER_COMP_COMPARE(mchp_tc_count_compare_read, mchp_tc_count_compare_write), | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
|  | static int mchp_tc_watch_validate(struct counter_device *counter, | ||||||
|  | 				  const struct counter_watch *watch) | ||||||
|  | { | ||||||
|  | 	if (watch->channel == COUNTER_MCHP_EVCHN_CV || watch->channel == COUNTER_MCHP_EVCHN_RA) | ||||||
|  | 		switch (watch->event) { | ||||||
|  | 		case COUNTER_EVENT_CHANGE_OF_STATE: | ||||||
|  | 		case COUNTER_EVENT_OVERFLOW: | ||||||
|  | 		case COUNTER_EVENT_CAPTURE: | ||||||
|  | 			return 0; | ||||||
|  | 		default: | ||||||
|  | 			return -EINVAL; | ||||||
|  | 		} | ||||||
|  | 
 | ||||||
|  | 	if (watch->channel == COUNTER_MCHP_EVCHN_RB && watch->event == COUNTER_EVENT_CAPTURE) | ||||||
|  | 		return 0; | ||||||
|  | 
 | ||||||
|  | 	if (watch->channel == COUNTER_MCHP_EVCHN_RC && watch->event == COUNTER_EVENT_THRESHOLD) | ||||||
|  | 		return 0; | ||||||
|  | 
 | ||||||
|  | 	return -EINVAL; | ||||||
|  | } | ||||||
|  | 
 | ||||||
| static struct counter_count mchp_tc_counts[] = { | static struct counter_count mchp_tc_counts[] = { | ||||||
| 	{ | 	{ | ||||||
| 		.id = 0, | 		.id = 0, | ||||||
|  | @ -356,7 +378,8 @@ static const struct counter_ops mchp_tc_ops = { | ||||||
| 	.function_read  = mchp_tc_count_function_read, | 	.function_read  = mchp_tc_count_function_read, | ||||||
| 	.function_write = mchp_tc_count_function_write, | 	.function_write = mchp_tc_count_function_write, | ||||||
| 	.action_read    = mchp_tc_count_action_read, | 	.action_read    = mchp_tc_count_action_read, | ||||||
| 	.action_write   = mchp_tc_count_action_write | 	.action_write   = mchp_tc_count_action_write, | ||||||
|  | 	.watch_validate = mchp_tc_watch_validate, | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| static const struct atmel_tcb_config tcb_rm9200_config = { | static const struct atmel_tcb_config tcb_rm9200_config = { | ||||||
|  |  | ||||||
		Loading…
	
		Reference in a new issue
	
	 Dharma Balasubiramani
						Dharma Balasubiramani