| 
									
										
										
										
											2007-07-10 13:03:43 +01:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * TI DaVinci GPIO Support | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Copyright (c) 2006 David Brownell | 
					
						
							|  |  |  |  * Copyright (c) 2007, MontaVista Software, Inc. <source@mvista.com> | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * This program is free software; you can redistribute it and/or modify | 
					
						
							|  |  |  |  * it under the terms of the GNU General Public License as published by | 
					
						
							|  |  |  |  * the Free Software Foundation; either version 2 of the License, or | 
					
						
							|  |  |  |  * (at your option) any later version. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #ifndef	__DAVINCI_GPIO_H
 | 
					
						
							|  |  |  | #define	__DAVINCI_GPIO_H
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-09-07 23:41:04 -07:00
										 |  |  | #include <asm-generic/gpio.h>
 | 
					
						
							| 
									
										
										
										
											2009-04-14 07:04:16 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-10-28 15:25:01 +01:00
										 |  |  | #define __ARM_GPIOLIB_COMPLEX
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-08-22 08:40:38 +01:00
										 |  |  | /* The inline versions use the static inlines in the driver header */ | 
					
						
							|  |  |  | #include "gpio-davinci.h"
 | 
					
						
							| 
									
										
										
										
											2007-07-10 13:03:43 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-05-18 12:51:20 -04:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * The get/set/clear functions will inline when called with constant | 
					
						
							| 
									
										
										
										
											2008-09-07 23:41:04 -07:00
										 |  |  |  * parameters referencing built-in GPIOs, for low-overhead bitbanging. | 
					
						
							| 
									
										
										
										
											2007-07-10 13:03:43 +01:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2010-05-18 12:51:20 -04:00
										 |  |  |  * gpio_set_value() will inline only on traditional Davinci style controllers | 
					
						
							|  |  |  |  * with distinct set/clear registers. | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											2008-09-07 23:41:04 -07:00
										 |  |  |  * Otherwise, calls with variable parameters or referencing external | 
					
						
							|  |  |  |  * GPIOs (e.g. on GPIO expander chips) use outlined functions. | 
					
						
							| 
									
										
										
										
											2007-07-10 13:03:43 +01:00
										 |  |  |  */ | 
					
						
							|  |  |  | static inline void gpio_set_value(unsigned gpio, int value) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2010-05-01 18:37:53 -04:00
										 |  |  | 	if (__builtin_constant_p(value) && gpio < davinci_soc_info.gpio_num) { | 
					
						
							|  |  |  | 		struct davinci_gpio_controller *ctlr; | 
					
						
							|  |  |  | 		u32				mask; | 
					
						
							| 
									
										
										
										
											2007-07-10 13:03:43 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-05-01 18:37:53 -04:00
										 |  |  | 		ctlr = __gpio_to_controller(gpio); | 
					
						
							| 
									
										
										
										
											2010-05-18 12:51:20 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		if (ctlr->set_data != ctlr->clr_data) { | 
					
						
							|  |  |  | 			mask = __gpio_mask(gpio); | 
					
						
							|  |  |  | 			if (value) | 
					
						
							|  |  |  | 				__raw_writel(mask, ctlr->set_data); | 
					
						
							|  |  |  | 			else | 
					
						
							|  |  |  | 				__raw_writel(mask, ctlr->clr_data); | 
					
						
							|  |  |  | 			return; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2007-07-10 13:03:43 +01:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-09-07 23:41:04 -07:00
										 |  |  | 	__gpio_set_value(gpio, value); | 
					
						
							| 
									
										
										
										
											2007-07-10 13:03:43 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* Returns zero or nonzero; works for gpios configured as inputs OR
 | 
					
						
							| 
									
										
										
										
											2008-09-07 23:41:04 -07:00
										 |  |  |  * as outputs, at least for built-in GPIOs. | 
					
						
							| 
									
										
										
										
											2007-07-10 13:03:43 +01:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2008-09-07 23:41:04 -07:00
										 |  |  |  * NOTE: for built-in GPIOs, changes in reported values are synchronized | 
					
						
							|  |  |  |  * to the GPIO clock.  This is easily seen after calling gpio_set_value() | 
					
						
							|  |  |  |  * and then immediately gpio_get_value(), where the gpio_get_value() will | 
					
						
							|  |  |  |  * return the old value until the GPIO clock ticks and the new value gets | 
					
						
							|  |  |  |  * latched. | 
					
						
							| 
									
										
										
										
											2007-07-10 13:03:43 +01:00
										 |  |  |  */ | 
					
						
							|  |  |  | static inline int gpio_get_value(unsigned gpio) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2010-05-01 18:37:53 -04:00
										 |  |  | 	struct davinci_gpio_controller *ctlr; | 
					
						
							| 
									
										
										
										
											2007-07-10 13:03:43 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-05-01 18:37:53 -04:00
										 |  |  | 	if (!__builtin_constant_p(gpio) || gpio >= davinci_soc_info.gpio_num) | 
					
						
							| 
									
										
										
										
											2008-09-07 23:41:04 -07:00
										 |  |  | 		return __gpio_get_value(gpio); | 
					
						
							| 
									
										
										
										
											2007-07-10 13:03:43 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-05-01 18:37:53 -04:00
										 |  |  | 	ctlr = __gpio_to_controller(gpio); | 
					
						
							|  |  |  | 	return __gpio_mask(gpio) & __raw_readl(ctlr->in_data); | 
					
						
							| 
									
										
										
										
											2007-07-10 13:03:43 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-09-07 23:41:04 -07:00
										 |  |  | static inline int gpio_cansleep(unsigned gpio) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2010-05-01 18:37:53 -04:00
										 |  |  | 	if (__builtin_constant_p(gpio) && gpio < davinci_soc_info.gpio_num) | 
					
						
							| 
									
										
										
										
											2008-09-07 23:41:04 -07:00
										 |  |  | 		return 0; | 
					
						
							|  |  |  | 	else | 
					
						
							|  |  |  | 		return __gpio_cansleep(gpio); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2007-07-10 13:03:43 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | static inline int irq_to_gpio(unsigned irq) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2009-06-25 17:01:31 -07:00
										 |  |  | 	/* don't support the reverse mapping */ | 
					
						
							|  |  |  | 	return -ENOSYS; | 
					
						
							| 
									
										
										
										
											2007-07-10 13:03:43 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #endif				/* __DAVINCI_GPIO_H */
 |