Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 1 | #ifndef _IMX_GPIO_H |
| 2 | |
Uwe Kleine-König | 9c65685 | 2008-10-29 14:14:54 -0700 | [diff] [blame] | 3 | #include <linux/kernel.h> |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 4 | #include <mach/imx-regs.h> |
| 5 | |
| 6 | #define IMX_GPIO_ALLOC_MODE_NORMAL 0 |
| 7 | #define IMX_GPIO_ALLOC_MODE_NO_ALLOC 1 |
| 8 | #define IMX_GPIO_ALLOC_MODE_TRY_ALLOC 2 |
| 9 | #define IMX_GPIO_ALLOC_MODE_ALLOC_ONLY 4 |
| 10 | #define IMX_GPIO_ALLOC_MODE_RELEASE 8 |
| 11 | |
| 12 | extern int imx_gpio_request(unsigned gpio, const char *label); |
| 13 | |
| 14 | extern void imx_gpio_free(unsigned gpio); |
| 15 | |
| 16 | extern int imx_gpio_setup_multiple_pins(const int *pin_list, unsigned count, |
| 17 | int alloc_mode, const char *label); |
| 18 | |
| 19 | extern int imx_gpio_direction_input(unsigned gpio); |
| 20 | |
| 21 | extern int imx_gpio_direction_output(unsigned gpio, int value); |
| 22 | |
| 23 | extern void __imx_gpio_set_value(unsigned gpio, int value); |
| 24 | |
| 25 | static inline int imx_gpio_get_value(unsigned gpio) |
| 26 | { |
| 27 | return SSR(gpio >> GPIO_PORT_SHIFT) & (1 << (gpio & GPIO_PIN_MASK)); |
| 28 | } |
| 29 | |
| 30 | static inline void imx_gpio_set_value_inline(unsigned gpio, int value) |
| 31 | { |
| 32 | unsigned long flags; |
| 33 | |
| 34 | raw_local_irq_save(flags); |
| 35 | if(value) |
| 36 | DR(gpio >> GPIO_PORT_SHIFT) |= (1 << (gpio & GPIO_PIN_MASK)); |
| 37 | else |
| 38 | DR(gpio >> GPIO_PORT_SHIFT) &= ~(1 << (gpio & GPIO_PIN_MASK)); |
| 39 | raw_local_irq_restore(flags); |
| 40 | } |
| 41 | |
| 42 | static inline void imx_gpio_set_value(unsigned gpio, int value) |
| 43 | { |
| 44 | if(__builtin_constant_p(gpio)) |
| 45 | imx_gpio_set_value_inline(gpio, value); |
| 46 | else |
| 47 | __imx_gpio_set_value(gpio, value); |
| 48 | } |
| 49 | |
| 50 | extern int imx_gpio_to_irq(unsigned gpio); |
| 51 | |
| 52 | extern int imx_irq_to_gpio(unsigned irq); |
| 53 | |
| 54 | /*-------------------------------------------------------------------------*/ |
| 55 | |
| 56 | /* Wrappers for "new style" GPIO calls. These calls i.MX specific versions |
| 57 | * to allow future extension of GPIO logic. |
| 58 | */ |
| 59 | |
| 60 | static inline int gpio_request(unsigned gpio, const char *label) |
| 61 | { |
| 62 | return imx_gpio_request(gpio, label); |
| 63 | } |
| 64 | |
| 65 | static inline void gpio_free(unsigned gpio) |
| 66 | { |
Uwe Kleine-König | 9c65685 | 2008-10-29 14:14:54 -0700 | [diff] [blame] | 67 | might_sleep(); |
| 68 | |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 69 | imx_gpio_free(gpio); |
| 70 | } |
| 71 | |
| 72 | static inline int gpio_direction_input(unsigned gpio) |
| 73 | { |
| 74 | return imx_gpio_direction_input(gpio); |
| 75 | } |
| 76 | |
| 77 | static inline int gpio_direction_output(unsigned gpio, int value) |
| 78 | { |
| 79 | return imx_gpio_direction_output(gpio, value); |
| 80 | } |
| 81 | |
| 82 | static inline int gpio_get_value(unsigned gpio) |
| 83 | { |
| 84 | return imx_gpio_get_value(gpio); |
| 85 | } |
| 86 | |
| 87 | static inline void gpio_set_value(unsigned gpio, int value) |
| 88 | { |
| 89 | imx_gpio_set_value(gpio, value); |
| 90 | } |
| 91 | |
| 92 | #include <asm-generic/gpio.h> /* cansleep wrappers */ |
| 93 | |
| 94 | static inline int gpio_to_irq(unsigned gpio) |
| 95 | { |
| 96 | return imx_gpio_to_irq(gpio); |
| 97 | } |
| 98 | |
| 99 | static inline int irq_to_gpio(unsigned irq) |
| 100 | { |
| 101 | return imx_irq_to_gpio(irq); |
| 102 | } |
| 103 | |
| 104 | |
| 105 | #endif |