bzip2/lzma: make internal initramfs compression configurable
[cascardo/linux.git] / arch / blackfin / include / asm / gpio.h
1 /*
2  * File:         arch/blackfin/kernel/bfin_gpio.h
3  * Based on:
4  * Author:       Michael Hennerich (hennerich@blackfin.uclinux.org)
5  *
6  * Created:
7  * Description:
8  *
9  * Modified:
10  *               Copyright 2004-2008 Analog Devices Inc.
11  *
12  * Bugs:         Enter bugs at http://blackfin.uclinux.org/
13  *
14  * This program is free software; you can redistribute it and/or modify
15  * it under the terms of the GNU General Public License as published by
16  * the Free Software Foundation; either version 2 of the License, or
17  * (at your option) any later version.
18  *
19  * This program is distributed in the hope that it will be useful,
20  * but WITHOUT ANY WARRANTY; without even the implied warranty of
21  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22  * GNU General Public License for more details.
23  *
24  * You should have received a copy of the GNU General Public License
25  * along with this program; if not, see the file COPYING, or write
26  * to the Free Software Foundation, Inc.,
27  * 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
28  */
29
30 /*
31 *  Number     BF537/6/4    BF561    BF533/2/1
32 *             BF527/5/2
33 *
34 *  GPIO_0       PF0         PF0        PF0
35 *  GPIO_1       PF1         PF1        PF1
36 *  GPIO_2       PF2         PF2        PF2
37 *  GPIO_3       PF3         PF3        PF3
38 *  GPIO_4       PF4         PF4        PF4
39 *  GPIO_5       PF5         PF5        PF5
40 *  GPIO_6       PF6         PF6        PF6
41 *  GPIO_7       PF7         PF7        PF7
42 *  GPIO_8       PF8         PF8        PF8
43 *  GPIO_9       PF9         PF9        PF9
44 *  GPIO_10      PF10        PF10       PF10
45 *  GPIO_11      PF11        PF11       PF11
46 *  GPIO_12      PF12        PF12       PF12
47 *  GPIO_13      PF13        PF13       PF13
48 *  GPIO_14      PF14        PF14       PF14
49 *  GPIO_15      PF15        PF15       PF15
50 *  GPIO_16      PG0         PF16
51 *  GPIO_17      PG1         PF17
52 *  GPIO_18      PG2         PF18
53 *  GPIO_19      PG3         PF19
54 *  GPIO_20      PG4         PF20
55 *  GPIO_21      PG5         PF21
56 *  GPIO_22      PG6         PF22
57 *  GPIO_23      PG7         PF23
58 *  GPIO_24      PG8         PF24
59 *  GPIO_25      PG9         PF25
60 *  GPIO_26      PG10        PF26
61 *  GPIO_27      PG11        PF27
62 *  GPIO_28      PG12        PF28
63 *  GPIO_29      PG13        PF29
64 *  GPIO_30      PG14        PF30
65 *  GPIO_31      PG15        PF31
66 *  GPIO_32      PH0         PF32
67 *  GPIO_33      PH1         PF33
68 *  GPIO_34      PH2         PF34
69 *  GPIO_35      PH3         PF35
70 *  GPIO_36      PH4         PF36
71 *  GPIO_37      PH5         PF37
72 *  GPIO_38      PH6         PF38
73 *  GPIO_39      PH7         PF39
74 *  GPIO_40      PH8         PF40
75 *  GPIO_41      PH9         PF41
76 *  GPIO_42      PH10        PF42
77 *  GPIO_43      PH11        PF43
78 *  GPIO_44      PH12        PF44
79 *  GPIO_45      PH13        PF45
80 *  GPIO_46      PH14        PF46
81 *  GPIO_47      PH15        PF47
82 */
83
84 #ifndef __ARCH_BLACKFIN_GPIO_H__
85 #define __ARCH_BLACKFIN_GPIO_H__
86
87 #define gpio_bank(x)    ((x) >> 4)
88 #define gpio_bit(x)     (1<<((x) & 0xF))
89 #define gpio_sub_n(x)   ((x) & 0xF)
90
91 #define GPIO_BANKSIZE   16
92 #define GPIO_BANK_NUM   DIV_ROUND_UP(MAX_BLACKFIN_GPIOS, GPIO_BANKSIZE)
93
94 #include <mach/gpio.h>
95
96 #define GPIO_0  0
97 #define GPIO_1  1
98 #define GPIO_2  2
99 #define GPIO_3  3
100 #define GPIO_4  4
101 #define GPIO_5  5
102 #define GPIO_6  6
103 #define GPIO_7  7
104 #define GPIO_8  8
105 #define GPIO_9  9
106 #define GPIO_10 10
107 #define GPIO_11 11
108 #define GPIO_12 12
109 #define GPIO_13 13
110 #define GPIO_14 14
111 #define GPIO_15 15
112 #define GPIO_16 16
113 #define GPIO_17 17
114 #define GPIO_18 18
115 #define GPIO_19 19
116 #define GPIO_20 20
117 #define GPIO_21 21
118 #define GPIO_22 22
119 #define GPIO_23 23
120 #define GPIO_24 24
121 #define GPIO_25 25
122 #define GPIO_26 26
123 #define GPIO_27 27
124 #define GPIO_28 28
125 #define GPIO_29 29
126 #define GPIO_30 30
127 #define GPIO_31 31
128 #define GPIO_32 32
129 #define GPIO_33 33
130 #define GPIO_34 34
131 #define GPIO_35 35
132 #define GPIO_36 36
133 #define GPIO_37 37
134 #define GPIO_38 38
135 #define GPIO_39 39
136 #define GPIO_40 40
137 #define GPIO_41 41
138 #define GPIO_42 42
139 #define GPIO_43 43
140 #define GPIO_44 44
141 #define GPIO_45 45
142 #define GPIO_46 46
143 #define GPIO_47 47
144
145 #define PERIPHERAL_USAGE 1
146 #define GPIO_USAGE 0
147
148 #ifndef __ASSEMBLY__
149
150 /***********************************************************
151 *
152 * FUNCTIONS: Blackfin General Purpose Ports Access Functions
153 *
154 * INPUTS/OUTPUTS:
155 * gpio - GPIO Number between 0 and MAX_BLACKFIN_GPIOS
156 *
157 *
158 * DESCRIPTION: These functions abstract direct register access
159 *              to Blackfin processor General Purpose
160 *              Ports Regsiters
161 *
162 * CAUTION: These functions do not belong to the GPIO Driver API
163 *************************************************************
164 * MODIFICATION HISTORY :
165 **************************************************************/
166
167 #ifndef BF548_FAMILY
168 void set_gpio_dir(unsigned, unsigned short);
169 void set_gpio_inen(unsigned, unsigned short);
170 void set_gpio_polar(unsigned, unsigned short);
171 void set_gpio_edge(unsigned, unsigned short);
172 void set_gpio_both(unsigned, unsigned short);
173 void set_gpio_data(unsigned, unsigned short);
174 void set_gpio_maska(unsigned, unsigned short);
175 void set_gpio_maskb(unsigned, unsigned short);
176 void set_gpio_toggle(unsigned);
177 void set_gpiop_dir(unsigned, unsigned short);
178 void set_gpiop_inen(unsigned, unsigned short);
179 void set_gpiop_polar(unsigned, unsigned short);
180 void set_gpiop_edge(unsigned, unsigned short);
181 void set_gpiop_both(unsigned, unsigned short);
182 void set_gpiop_data(unsigned, unsigned short);
183 void set_gpiop_maska(unsigned, unsigned short);
184 void set_gpiop_maskb(unsigned, unsigned short);
185 unsigned short get_gpio_dir(unsigned);
186 unsigned short get_gpio_inen(unsigned);
187 unsigned short get_gpio_polar(unsigned);
188 unsigned short get_gpio_edge(unsigned);
189 unsigned short get_gpio_both(unsigned);
190 unsigned short get_gpio_maska(unsigned);
191 unsigned short get_gpio_maskb(unsigned);
192 unsigned short get_gpio_data(unsigned);
193 unsigned short get_gpiop_dir(unsigned);
194 unsigned short get_gpiop_inen(unsigned);
195 unsigned short get_gpiop_polar(unsigned);
196 unsigned short get_gpiop_edge(unsigned);
197 unsigned short get_gpiop_both(unsigned);
198 unsigned short get_gpiop_maska(unsigned);
199 unsigned short get_gpiop_maskb(unsigned);
200 unsigned short get_gpiop_data(unsigned);
201
202 struct gpio_port_t {
203         unsigned short data;
204         unsigned short dummy1;
205         unsigned short data_clear;
206         unsigned short dummy2;
207         unsigned short data_set;
208         unsigned short dummy3;
209         unsigned short toggle;
210         unsigned short dummy4;
211         unsigned short maska;
212         unsigned short dummy5;
213         unsigned short maska_clear;
214         unsigned short dummy6;
215         unsigned short maska_set;
216         unsigned short dummy7;
217         unsigned short maska_toggle;
218         unsigned short dummy8;
219         unsigned short maskb;
220         unsigned short dummy9;
221         unsigned short maskb_clear;
222         unsigned short dummy10;
223         unsigned short maskb_set;
224         unsigned short dummy11;
225         unsigned short maskb_toggle;
226         unsigned short dummy12;
227         unsigned short dir;
228         unsigned short dummy13;
229         unsigned short polar;
230         unsigned short dummy14;
231         unsigned short edge;
232         unsigned short dummy15;
233         unsigned short both;
234         unsigned short dummy16;
235         unsigned short inen;
236 };
237 #endif
238
239 #ifdef CONFIG_PM
240
241 unsigned int bfin_pm_standby_setup(void);
242 void bfin_pm_standby_restore(void);
243
244 void bfin_gpio_pm_hibernate_restore(void);
245 void bfin_gpio_pm_hibernate_suspend(void);
246
247 #ifndef CONFIG_BF54x
248 #define PM_WAKE_RISING  0x1
249 #define PM_WAKE_FALLING 0x2
250 #define PM_WAKE_HIGH    0x4
251 #define PM_WAKE_LOW     0x8
252 #define PM_WAKE_BOTH_EDGES      (PM_WAKE_RISING | PM_WAKE_FALLING)
253 #define PM_WAKE_IGNORE  0xF0
254
255 int gpio_pm_wakeup_request(unsigned gpio, unsigned char type);
256 void gpio_pm_wakeup_free(unsigned gpio);
257
258 struct gpio_port_s {
259         unsigned short data;
260         unsigned short maska;
261         unsigned short maskb;
262         unsigned short dir;
263         unsigned short polar;
264         unsigned short edge;
265         unsigned short both;
266         unsigned short inen;
267
268         unsigned short fer;
269         unsigned short reserved;
270         unsigned short mux;
271 };
272 #endif /*CONFIG_BF54x*/
273 #endif /*CONFIG_PM*/
274 /***********************************************************
275 *
276 * FUNCTIONS: Blackfin GPIO Driver
277 *
278 * INPUTS/OUTPUTS:
279 * gpio - GPIO Number between 0 and MAX_BLACKFIN_GPIOS
280 *
281 *
282 * DESCRIPTION: Blackfin GPIO Driver API
283 *
284 * CAUTION:
285 *************************************************************
286 * MODIFICATION HISTORY :
287 **************************************************************/
288
289 int bfin_gpio_request(unsigned gpio, const char *label);
290 void bfin_gpio_free(unsigned gpio);
291 int bfin_gpio_irq_request(unsigned gpio, const char *label);
292 void bfin_gpio_irq_free(unsigned gpio);
293 int bfin_gpio_direction_input(unsigned gpio);
294 int bfin_gpio_direction_output(unsigned gpio, int value);
295 int bfin_gpio_get_value(unsigned gpio);
296 void bfin_gpio_set_value(unsigned gpio, int value);
297
298 #ifndef BF548_FAMILY
299 #define bfin_gpio_set_value(gpio, value)    set_gpio_data(gpio, value)
300 #endif
301
302 #ifdef CONFIG_GPIOLIB
303 #include <asm-generic/gpio.h>           /* cansleep wrappers */
304
305 static inline int gpio_get_value(unsigned int gpio)
306 {
307         if (gpio < MAX_BLACKFIN_GPIOS)
308                 return bfin_gpio_get_value(gpio);
309         else
310                 return __gpio_get_value(gpio);
311 }
312
313 static inline void gpio_set_value(unsigned int gpio, int value)
314 {
315         if (gpio < MAX_BLACKFIN_GPIOS)
316                 bfin_gpio_set_value(gpio, value);
317         else
318                 __gpio_set_value(gpio, value);
319 }
320
321 static inline int gpio_cansleep(unsigned int gpio)
322 {
323         return __gpio_cansleep(gpio);
324 }
325
326 #else /* !CONFIG_GPIOLIB */
327
328 static inline int gpio_request(unsigned gpio, const char *label)
329 {
330         return bfin_gpio_request(gpio, label);
331 }
332
333 static inline void gpio_free(unsigned gpio)
334 {
335         return bfin_gpio_free(gpio);
336 }
337
338 static inline int gpio_direction_input(unsigned gpio)
339 {
340         return bfin_gpio_direction_input(gpio);
341 }
342
343 static inline int gpio_direction_output(unsigned gpio, int value)
344 {
345         return bfin_gpio_direction_output(gpio, value);
346 }
347
348 static inline int gpio_get_value(unsigned gpio)
349 {
350         return bfin_gpio_get_value(gpio);
351 }
352
353 static inline void gpio_set_value(unsigned gpio, int value)
354 {
355         return bfin_gpio_set_value(gpio, value);
356 }
357
358 #include <asm-generic/gpio.h>           /* cansleep wrappers */
359 #endif  /* !CONFIG_GPIOLIB */
360 #include <asm/irq.h>
361
362 static inline int gpio_to_irq(unsigned gpio)
363 {
364         return (gpio + GPIO_IRQ_BASE);
365 }
366
367 static inline int irq_to_gpio(unsigned irq)
368 {
369         return (irq - GPIO_IRQ_BASE);
370 }
371
372 #endif /* __ASSEMBLY__ */
373
374 #endif /* __ARCH_BLACKFIN_GPIO_H__ */