blob: 502d5aa2c093dad2b00acd22e5564bbfad7a21a6 [file] [log] [blame]
Russell Kinga09e64f2008-08-05 16:14:15 +01001#ifndef _IMX_GPIO_H
2
Uwe Kleine-König9c656852008-10-29 14:14:54 -07003#include <linux/kernel.h>
Russell Kinga09e64f2008-08-05 16:14:15 +01004#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
12extern int imx_gpio_request(unsigned gpio, const char *label);
13
14extern void imx_gpio_free(unsigned gpio);
15
16extern int imx_gpio_setup_multiple_pins(const int *pin_list, unsigned count,
17 int alloc_mode, const char *label);
18
19extern int imx_gpio_direction_input(unsigned gpio);
20
21extern int imx_gpio_direction_output(unsigned gpio, int value);
22
23extern void __imx_gpio_set_value(unsigned gpio, int value);
24
25static inline int imx_gpio_get_value(unsigned gpio)
26{
27 return SSR(gpio >> GPIO_PORT_SHIFT) & (1 << (gpio & GPIO_PIN_MASK));
28}
29
30static 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
42static 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
50extern int imx_gpio_to_irq(unsigned gpio);
51
52extern 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
60static inline int gpio_request(unsigned gpio, const char *label)
61{
62 return imx_gpio_request(gpio, label);
63}
64
65static inline void gpio_free(unsigned gpio)
66{
Uwe Kleine-König9c656852008-10-29 14:14:54 -070067 might_sleep();
68
Russell Kinga09e64f2008-08-05 16:14:15 +010069 imx_gpio_free(gpio);
70}
71
72static inline int gpio_direction_input(unsigned gpio)
73{
74 return imx_gpio_direction_input(gpio);
75}
76
77static inline int gpio_direction_output(unsigned gpio, int value)
78{
79 return imx_gpio_direction_output(gpio, value);
80}
81
82static inline int gpio_get_value(unsigned gpio)
83{
84 return imx_gpio_get_value(gpio);
85}
86
87static 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
94static inline int gpio_to_irq(unsigned gpio)
95{
96 return imx_gpio_to_irq(gpio);
97}
98
99static inline int irq_to_gpio(unsigned irq)
100{
101 return imx_irq_to_gpio(irq);
102}
103
104
105#endif