Blackfin: gpio/ints: generalize pint logic
[cascardo/linux.git] / arch / blackfin / include / asm / gpio.h
1 /*
2  * Copyright 2006-2009 Analog Devices Inc.
3  *
4  * Licensed under the GPL-2 or later.
5  */
6
7 #ifndef __ARCH_BLACKFIN_GPIO_H__
8 #define __ARCH_BLACKFIN_GPIO_H__
9
10 #define gpio_bank(x)    ((x) >> 4)
11 #define gpio_bit(x)     (1<<((x) & 0xF))
12 #define gpio_sub_n(x)   ((x) & 0xF)
13
14 #define GPIO_BANKSIZE   16
15 #define GPIO_BANK_NUM   DIV_ROUND_UP(MAX_BLACKFIN_GPIOS, GPIO_BANKSIZE)
16
17 #include <mach/gpio.h>
18
19 #define PERIPHERAL_USAGE 1
20 #define GPIO_USAGE 0
21
22 #ifndef BFIN_GPIO_PINT
23 # define BFIN_GPIO_PINT 0
24 #endif
25
26 #ifndef __ASSEMBLY__
27
28 #include <linux/compiler.h>
29
30 /***********************************************************
31 *
32 * FUNCTIONS: Blackfin General Purpose Ports Access Functions
33 *
34 * INPUTS/OUTPUTS:
35 * gpio - GPIO Number between 0 and MAX_BLACKFIN_GPIOS
36 *
37 *
38 * DESCRIPTION: These functions abstract direct register access
39 *              to Blackfin processor General Purpose
40 *              Ports Regsiters
41 *
42 * CAUTION: These functions do not belong to the GPIO Driver API
43 *************************************************************
44 * MODIFICATION HISTORY :
45 **************************************************************/
46
47 #if !BFIN_GPIO_PINT
48 void set_gpio_dir(unsigned, unsigned short);
49 void set_gpio_inen(unsigned, unsigned short);
50 void set_gpio_polar(unsigned, unsigned short);
51 void set_gpio_edge(unsigned, unsigned short);
52 void set_gpio_both(unsigned, unsigned short);
53 void set_gpio_data(unsigned, unsigned short);
54 void set_gpio_maska(unsigned, unsigned short);
55 void set_gpio_maskb(unsigned, unsigned short);
56 void set_gpio_toggle(unsigned);
57 void set_gpiop_dir(unsigned, unsigned short);
58 void set_gpiop_inen(unsigned, unsigned short);
59 void set_gpiop_polar(unsigned, unsigned short);
60 void set_gpiop_edge(unsigned, unsigned short);
61 void set_gpiop_both(unsigned, unsigned short);
62 void set_gpiop_data(unsigned, unsigned short);
63 void set_gpiop_maska(unsigned, unsigned short);
64 void set_gpiop_maskb(unsigned, unsigned short);
65 unsigned short get_gpio_dir(unsigned);
66 unsigned short get_gpio_inen(unsigned);
67 unsigned short get_gpio_polar(unsigned);
68 unsigned short get_gpio_edge(unsigned);
69 unsigned short get_gpio_both(unsigned);
70 unsigned short get_gpio_maska(unsigned);
71 unsigned short get_gpio_maskb(unsigned);
72 unsigned short get_gpio_data(unsigned);
73 unsigned short get_gpiop_dir(unsigned);
74 unsigned short get_gpiop_inen(unsigned);
75 unsigned short get_gpiop_polar(unsigned);
76 unsigned short get_gpiop_edge(unsigned);
77 unsigned short get_gpiop_both(unsigned);
78 unsigned short get_gpiop_maska(unsigned);
79 unsigned short get_gpiop_maskb(unsigned);
80 unsigned short get_gpiop_data(unsigned);
81
82 struct gpio_port_t {
83         unsigned short data;
84         unsigned short dummy1;
85         unsigned short data_clear;
86         unsigned short dummy2;
87         unsigned short data_set;
88         unsigned short dummy3;
89         unsigned short toggle;
90         unsigned short dummy4;
91         unsigned short maska;
92         unsigned short dummy5;
93         unsigned short maska_clear;
94         unsigned short dummy6;
95         unsigned short maska_set;
96         unsigned short dummy7;
97         unsigned short maska_toggle;
98         unsigned short dummy8;
99         unsigned short maskb;
100         unsigned short dummy9;
101         unsigned short maskb_clear;
102         unsigned short dummy10;
103         unsigned short maskb_set;
104         unsigned short dummy11;
105         unsigned short maskb_toggle;
106         unsigned short dummy12;
107         unsigned short dir;
108         unsigned short dummy13;
109         unsigned short polar;
110         unsigned short dummy14;
111         unsigned short edge;
112         unsigned short dummy15;
113         unsigned short both;
114         unsigned short dummy16;
115         unsigned short inen;
116 };
117 #endif
118
119 #ifdef BFIN_SPECIAL_GPIO_BANKS
120 void bfin_special_gpio_free(unsigned gpio);
121 int bfin_special_gpio_request(unsigned gpio, const char *label);
122 #endif
123
124 #ifdef CONFIG_PM
125 int bfin_pm_standby_ctrl(unsigned ctrl);
126
127 static inline int bfin_pm_standby_setup(void)
128 {
129         return bfin_pm_standby_ctrl(1);
130 }
131
132 static inline void bfin_pm_standby_restore(void)
133 {
134         bfin_pm_standby_ctrl(0);
135 }
136
137 void bfin_gpio_pm_hibernate_restore(void);
138 void bfin_gpio_pm_hibernate_suspend(void);
139
140 # if !BFIN_GPIO_PINT
141 int gpio_pm_wakeup_ctrl(unsigned gpio, unsigned ctrl);
142
143 struct gpio_port_s {
144         unsigned short data;
145         unsigned short maska;
146         unsigned short maskb;
147         unsigned short dir;
148         unsigned short polar;
149         unsigned short edge;
150         unsigned short both;
151         unsigned short inen;
152
153         unsigned short fer;
154         unsigned short reserved;
155         unsigned short mux;
156 };
157 # endif
158 #endif /*CONFIG_PM*/
159
160 /***********************************************************
161 *
162 * FUNCTIONS: Blackfin GPIO Driver
163 *
164 * INPUTS/OUTPUTS:
165 * gpio - GPIO Number between 0 and MAX_BLACKFIN_GPIOS
166 *
167 *
168 * DESCRIPTION: Blackfin GPIO Driver API
169 *
170 * CAUTION:
171 *************************************************************
172 * MODIFICATION HISTORY :
173 **************************************************************/
174
175 int bfin_gpio_request(unsigned gpio, const char *label);
176 void bfin_gpio_free(unsigned gpio);
177 int bfin_gpio_irq_request(unsigned gpio, const char *label);
178 void bfin_gpio_irq_free(unsigned gpio);
179 int bfin_gpio_direction_input(unsigned gpio);
180 int bfin_gpio_direction_output(unsigned gpio, int value);
181 int bfin_gpio_get_value(unsigned gpio);
182 void bfin_gpio_set_value(unsigned gpio, int value);
183
184 #include <asm/irq.h>
185 #include <asm/errno.h>
186
187 #ifdef CONFIG_GPIOLIB
188 #include <asm-generic/gpio.h>           /* cansleep wrappers */
189
190 static inline int gpio_get_value(unsigned int gpio)
191 {
192         if (gpio < MAX_BLACKFIN_GPIOS)
193                 return bfin_gpio_get_value(gpio);
194         else
195                 return __gpio_get_value(gpio);
196 }
197
198 static inline void gpio_set_value(unsigned int gpio, int value)
199 {
200         if (gpio < MAX_BLACKFIN_GPIOS)
201                 bfin_gpio_set_value(gpio, value);
202         else
203                 __gpio_set_value(gpio, value);
204 }
205
206 static inline int gpio_cansleep(unsigned int gpio)
207 {
208         return __gpio_cansleep(gpio);
209 }
210
211 static inline int gpio_to_irq(unsigned gpio)
212 {
213         return __gpio_to_irq(gpio);
214 }
215
216 #else /* !CONFIG_GPIOLIB */
217
218 static inline int gpio_request(unsigned gpio, const char *label)
219 {
220         return bfin_gpio_request(gpio, label);
221 }
222
223 static inline void gpio_free(unsigned gpio)
224 {
225         return bfin_gpio_free(gpio);
226 }
227
228 static inline int gpio_direction_input(unsigned gpio)
229 {
230         return bfin_gpio_direction_input(gpio);
231 }
232
233 static inline int gpio_direction_output(unsigned gpio, int value)
234 {
235         return bfin_gpio_direction_output(gpio, value);
236 }
237
238 static inline int gpio_set_debounce(unsigned gpio, unsigned debounce)
239 {
240         return -EINVAL;
241 }
242
243 static inline int gpio_get_value(unsigned gpio)
244 {
245         return bfin_gpio_get_value(gpio);
246 }
247
248 static inline void gpio_set_value(unsigned gpio, int value)
249 {
250         return bfin_gpio_set_value(gpio, value);
251 }
252
253 static inline int gpio_to_irq(unsigned gpio)
254 {
255         if (likely(gpio < MAX_BLACKFIN_GPIOS))
256                 return gpio + GPIO_IRQ_BASE;
257
258         return -EINVAL;
259 }
260
261 #include <asm-generic/gpio.h>           /* cansleep wrappers */
262 #endif  /* !CONFIG_GPIOLIB */
263
264 static inline int irq_to_gpio(unsigned irq)
265 {
266         return (irq - GPIO_IRQ_BASE);
267 }
268
269 #endif /* __ASSEMBLY__ */
270
271 #endif /* __ARCH_BLACKFIN_GPIO_H__ */