mirror of
				https://xff.cz/git/u-boot/
				synced 2025-10-30 10:04:01 +01:00 
			
		
		
		
	fdt: Add polarity-aware gpio functions to fdtdec
Add get and set gpio functions to fdtdec that take into account the polarity field in fdtdec_gpio_state.flags. Signed-off-by: Sean Paul <seanpaul@chromium.org> Signed-off-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
		
				
					committed by
					
						 Gerald Van Baren
						Gerald Van Baren
					
				
			
			
				
	
			
			
			
						parent
						
							aadef0a1bc
						
					
				
				
					commit
					202ff75375
				
			| @@ -89,6 +89,22 @@ struct fdt_gpio_state { | ||||
| /* This tells us whether a fdt_gpio_state record is valid or not */ | ||||
| #define fdt_gpio_isvalid(x) ((x)->gpio != FDT_GPIO_NONE) | ||||
|  | ||||
| /** | ||||
|  * Read the GPIO taking into account the polarity of the pin. | ||||
|  * | ||||
|  * @param gpio		pointer to the decoded gpio | ||||
|  * @return value of the gpio if successful, < 0 if unsuccessful | ||||
|  */ | ||||
| int fdtdec_get_gpio(struct fdt_gpio_state *gpio); | ||||
|  | ||||
| /** | ||||
|  * Write the GPIO taking into account the polarity of the pin. | ||||
|  * | ||||
|  * @param gpio		pointer to the decoded gpio | ||||
|  * @return 0 if successful | ||||
|  */ | ||||
| int fdtdec_set_gpio(struct fdt_gpio_state *gpio, int val); | ||||
|  | ||||
| /** | ||||
|  * Find the next numbered alias for a peripheral. This is used to enumerate | ||||
|  * all the peripherals of a certain type. | ||||
|   | ||||
							
								
								
									
										20
									
								
								lib/fdtdec.c
									
									
									
									
									
								
							
							
						
						
									
										20
									
								
								lib/fdtdec.c
									
									
									
									
									
								
							| @@ -487,6 +487,26 @@ int fdtdec_decode_gpio(const void *blob, int node, const char *prop_name, | ||||
| 	return err == 1 ? 0 : err; | ||||
| } | ||||
|  | ||||
| int fdtdec_get_gpio(struct fdt_gpio_state *gpio) | ||||
| { | ||||
| 	int val; | ||||
|  | ||||
| 	if (!fdt_gpio_isvalid(gpio)) | ||||
| 		return -1; | ||||
|  | ||||
| 	val = gpio_get_value(gpio->gpio); | ||||
| 	return gpio->flags & FDT_GPIO_ACTIVE_LOW ? val ^ 1 : val; | ||||
| } | ||||
|  | ||||
| int fdtdec_set_gpio(struct fdt_gpio_state *gpio, int val) | ||||
| { | ||||
| 	if (!fdt_gpio_isvalid(gpio)) | ||||
| 		return -1; | ||||
|  | ||||
| 	val = gpio->flags & FDT_GPIO_ACTIVE_LOW ? val ^ 1 : val; | ||||
| 	return gpio_set_value(gpio->gpio, val); | ||||
| } | ||||
|  | ||||
| int fdtdec_setup_gpio(struct fdt_gpio_state *gpio) | ||||
| { | ||||
| 	/* | ||||
|   | ||||
		Reference in New Issue
	
	Block a user