Merge branch 'akpm'
[linux-2.6/next.git] / arch / blackfin / include / asm / gpio.h
blob5a25856381fff3257fbeba2e52aa85a0e4e21b1a
1 /*
2 * Copyright 2006-2009 Analog Devices Inc.
4 * Licensed under the GPL-2 or later.
5 */
7 #ifndef __ARCH_BLACKFIN_GPIO_H__
8 #define __ARCH_BLACKFIN_GPIO_H__
10 #define gpio_bank(x) ((x) >> 4)
11 #define gpio_bit(x) (1<<((x) & 0xF))
12 #define gpio_sub_n(x) ((x) & 0xF)
14 #define GPIO_BANKSIZE 16
15 #define GPIO_BANK_NUM DIV_ROUND_UP(MAX_BLACKFIN_GPIOS, GPIO_BANKSIZE)
17 #include <mach/gpio.h>
19 #define PERIPHERAL_USAGE 1
20 #define GPIO_USAGE 0
22 #ifndef BFIN_GPIO_PINT
23 # define BFIN_GPIO_PINT 0
24 #endif
26 #ifndef __ASSEMBLY__
28 #include <linux/compiler.h>
30 /***********************************************************
32 * FUNCTIONS: Blackfin General Purpose Ports Access Functions
34 * INPUTS/OUTPUTS:
35 * gpio - GPIO Number between 0 and MAX_BLACKFIN_GPIOS
38 * DESCRIPTION: These functions abstract direct register access
39 * to Blackfin processor General Purpose
40 * Ports Regsiters
42 * CAUTION: These functions do not belong to the GPIO Driver API
43 *************************************************************
44 * MODIFICATION HISTORY :
45 **************************************************************/
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);
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;
117 #endif
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 # ifdef CONFIG_PM
123 void bfin_special_gpio_pm_hibernate_restore(void);
124 void bfin_special_gpio_pm_hibernate_suspend(void);
125 # endif
126 #endif
128 #ifdef CONFIG_PM
129 int bfin_pm_standby_ctrl(unsigned ctrl);
131 static inline int bfin_pm_standby_setup(void)
133 return bfin_pm_standby_ctrl(1);
136 static inline void bfin_pm_standby_restore(void)
138 bfin_pm_standby_ctrl(0);
141 void bfin_gpio_pm_hibernate_restore(void);
142 void bfin_gpio_pm_hibernate_suspend(void);
144 # if !BFIN_GPIO_PINT
145 int gpio_pm_wakeup_ctrl(unsigned gpio, unsigned ctrl);
147 struct gpio_port_s {
148 unsigned short data;
149 unsigned short maska;
150 unsigned short maskb;
151 unsigned short dir;
152 unsigned short polar;
153 unsigned short edge;
154 unsigned short both;
155 unsigned short inen;
157 unsigned short fer;
158 unsigned short reserved;
159 unsigned short mux;
161 # endif
162 #endif /*CONFIG_PM*/
164 /***********************************************************
166 * FUNCTIONS: Blackfin GPIO Driver
168 * INPUTS/OUTPUTS:
169 * gpio - GPIO Number between 0 and MAX_BLACKFIN_GPIOS
172 * DESCRIPTION: Blackfin GPIO Driver API
174 * CAUTION:
175 *************************************************************
176 * MODIFICATION HISTORY :
177 **************************************************************/
179 int bfin_gpio_request(unsigned gpio, const char *label);
180 void bfin_gpio_free(unsigned gpio);
181 int bfin_gpio_irq_request(unsigned gpio, const char *label);
182 void bfin_gpio_irq_free(unsigned gpio);
183 int bfin_gpio_direction_input(unsigned gpio);
184 int bfin_gpio_direction_output(unsigned gpio, int value);
185 int bfin_gpio_get_value(unsigned gpio);
186 void bfin_gpio_set_value(unsigned gpio, int value);
188 #include <asm/irq.h>
189 #include <asm/errno.h>
191 #ifdef CONFIG_GPIOLIB
192 #include <asm-generic/gpio.h> /* cansleep wrappers */
194 static inline int gpio_get_value(unsigned int gpio)
196 if (gpio < MAX_BLACKFIN_GPIOS)
197 return bfin_gpio_get_value(gpio);
198 else
199 return __gpio_get_value(gpio);
202 static inline void gpio_set_value(unsigned int gpio, int value)
204 if (gpio < MAX_BLACKFIN_GPIOS)
205 bfin_gpio_set_value(gpio, value);
206 else
207 __gpio_set_value(gpio, value);
210 static inline int gpio_cansleep(unsigned int gpio)
212 return __gpio_cansleep(gpio);
215 static inline int gpio_to_irq(unsigned gpio)
217 return __gpio_to_irq(gpio);
220 #else /* !CONFIG_GPIOLIB */
222 static inline int gpio_request(unsigned gpio, const char *label)
224 return bfin_gpio_request(gpio, label);
227 static inline void gpio_free(unsigned gpio)
229 return bfin_gpio_free(gpio);
232 static inline int gpio_direction_input(unsigned gpio)
234 return bfin_gpio_direction_input(gpio);
237 static inline int gpio_direction_output(unsigned gpio, int value)
239 return bfin_gpio_direction_output(gpio, value);
242 static inline int gpio_set_debounce(unsigned gpio, unsigned debounce)
244 return -EINVAL;
247 static inline int gpio_get_value(unsigned gpio)
249 return bfin_gpio_get_value(gpio);
252 static inline void gpio_set_value(unsigned gpio, int value)
254 return bfin_gpio_set_value(gpio, value);
257 static inline int gpio_to_irq(unsigned gpio)
259 if (likely(gpio < MAX_BLACKFIN_GPIOS))
260 return gpio + GPIO_IRQ_BASE;
262 return -EINVAL;
265 #include <asm-generic/gpio.h> /* cansleep wrappers */
266 #endif /* !CONFIG_GPIOLIB */
268 static inline int irq_to_gpio(unsigned irq)
270 return (irq - GPIO_IRQ_BASE);
273 #endif /* __ASSEMBLY__ */
275 #endif /* __ARCH_BLACKFIN_GPIO_H__ */