Merge tag 'hwmon-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/groeck...
[pandora-kernel.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 #include <linux/gpio.h>
30
31 /***********************************************************
32 *
33 * FUNCTIONS: Blackfin General Purpose Ports Access Functions
34 *
35 * INPUTS/OUTPUTS:
36 * gpio - GPIO Number between 0 and MAX_BLACKFIN_GPIOS
37 *
38 *
39 * DESCRIPTION: These functions abstract direct register access
40 *              to Blackfin processor General Purpose
41 *              Ports Regsiters
42 *
43 * CAUTION: These functions do not belong to the GPIO Driver API
44 *************************************************************
45 * MODIFICATION HISTORY :
46 **************************************************************/
47
48 #if !BFIN_GPIO_PINT
49 void set_gpio_dir(unsigned, unsigned short);
50 void set_gpio_inen(unsigned, unsigned short);
51 void set_gpio_polar(unsigned, unsigned short);
52 void set_gpio_edge(unsigned, unsigned short);
53 void set_gpio_both(unsigned, unsigned short);
54 void set_gpio_data(unsigned, unsigned short);
55 void set_gpio_maska(unsigned, unsigned short);
56 void set_gpio_maskb(unsigned, unsigned short);
57 void set_gpio_toggle(unsigned);
58 void set_gpiop_dir(unsigned, unsigned short);
59 void set_gpiop_inen(unsigned, unsigned short);
60 void set_gpiop_polar(unsigned, unsigned short);
61 void set_gpiop_edge(unsigned, unsigned short);
62 void set_gpiop_both(unsigned, unsigned short);
63 void set_gpiop_data(unsigned, unsigned short);
64 void set_gpiop_maska(unsigned, unsigned short);
65 void set_gpiop_maskb(unsigned, unsigned short);
66 unsigned short get_gpio_dir(unsigned);
67 unsigned short get_gpio_inen(unsigned);
68 unsigned short get_gpio_polar(unsigned);
69 unsigned short get_gpio_edge(unsigned);
70 unsigned short get_gpio_both(unsigned);
71 unsigned short get_gpio_maska(unsigned);
72 unsigned short get_gpio_maskb(unsigned);
73 unsigned short get_gpio_data(unsigned);
74 unsigned short get_gpiop_dir(unsigned);
75 unsigned short get_gpiop_inen(unsigned);
76 unsigned short get_gpiop_polar(unsigned);
77 unsigned short get_gpiop_edge(unsigned);
78 unsigned short get_gpiop_both(unsigned);
79 unsigned short get_gpiop_maska(unsigned);
80 unsigned short get_gpiop_maskb(unsigned);
81 unsigned short get_gpiop_data(unsigned);
82
83 struct gpio_port_t {
84         unsigned short data;
85         unsigned short dummy1;
86         unsigned short data_clear;
87         unsigned short dummy2;
88         unsigned short data_set;
89         unsigned short dummy3;
90         unsigned short toggle;
91         unsigned short dummy4;
92         unsigned short maska;
93         unsigned short dummy5;
94         unsigned short maska_clear;
95         unsigned short dummy6;
96         unsigned short maska_set;
97         unsigned short dummy7;
98         unsigned short maska_toggle;
99         unsigned short dummy8;
100         unsigned short maskb;
101         unsigned short dummy9;
102         unsigned short maskb_clear;
103         unsigned short dummy10;
104         unsigned short maskb_set;
105         unsigned short dummy11;
106         unsigned short maskb_toggle;
107         unsigned short dummy12;
108         unsigned short dir;
109         unsigned short dummy13;
110         unsigned short polar;
111         unsigned short dummy14;
112         unsigned short edge;
113         unsigned short dummy15;
114         unsigned short both;
115         unsigned short dummy16;
116         unsigned short inen;
117 };
118 #endif
119
120 #ifdef BFIN_SPECIAL_GPIO_BANKS
121 void bfin_special_gpio_free(unsigned gpio);
122 int bfin_special_gpio_request(unsigned gpio, const char *label);
123 # ifdef CONFIG_PM
124 void bfin_special_gpio_pm_hibernate_restore(void);
125 void bfin_special_gpio_pm_hibernate_suspend(void);
126 # endif
127 #endif
128
129 #ifdef CONFIG_PM
130 int bfin_pm_standby_ctrl(unsigned ctrl);
131
132 static inline int bfin_pm_standby_setup(void)
133 {
134         return bfin_pm_standby_ctrl(1);
135 }
136
137 static inline void bfin_pm_standby_restore(void)
138 {
139         bfin_pm_standby_ctrl(0);
140 }
141
142 void bfin_gpio_pm_hibernate_restore(void);
143 void bfin_gpio_pm_hibernate_suspend(void);
144 void bfin_pint_suspend(void);
145 void bfin_pint_resume(void);
146
147 # if !BFIN_GPIO_PINT
148 int gpio_pm_wakeup_ctrl(unsigned gpio, unsigned ctrl);
149
150 struct gpio_port_s {
151         unsigned short data;
152         unsigned short maska;
153         unsigned short maskb;
154         unsigned short dir;
155         unsigned short polar;
156         unsigned short edge;
157         unsigned short both;
158         unsigned short inen;
159
160         unsigned short fer;
161         unsigned short reserved;
162         unsigned short mux;
163 };
164 # endif
165 #endif /*CONFIG_PM*/
166
167 /***********************************************************
168 *
169 * FUNCTIONS: Blackfin GPIO Driver
170 *
171 * INPUTS/OUTPUTS:
172 * gpio - GPIO Number between 0 and MAX_BLACKFIN_GPIOS
173 *
174 *
175 * DESCRIPTION: Blackfin GPIO Driver API
176 *
177 * CAUTION:
178 *************************************************************
179 * MODIFICATION HISTORY :
180 **************************************************************/
181
182 int bfin_gpio_request(unsigned gpio, const char *label);
183 void bfin_gpio_free(unsigned gpio);
184 int bfin_gpio_irq_request(unsigned gpio, const char *label);
185 void bfin_gpio_irq_free(unsigned gpio);
186 int bfin_gpio_direction_input(unsigned gpio);
187 int bfin_gpio_direction_output(unsigned gpio, int value);
188 int bfin_gpio_get_value(unsigned gpio);
189 void bfin_gpio_set_value(unsigned gpio, int value);
190
191 #include <asm/irq.h>
192 #include <asm/errno.h>
193
194 #ifdef CONFIG_GPIOLIB
195 #include <asm-generic/gpio.h>           /* cansleep wrappers */
196
197 static inline int gpio_get_value(unsigned int gpio)
198 {
199         if (gpio < MAX_BLACKFIN_GPIOS)
200                 return bfin_gpio_get_value(gpio);
201         else
202                 return __gpio_get_value(gpio);
203 }
204
205 static inline void gpio_set_value(unsigned int gpio, int value)
206 {
207         if (gpio < MAX_BLACKFIN_GPIOS)
208                 bfin_gpio_set_value(gpio, value);
209         else
210                 __gpio_set_value(gpio, value);
211 }
212
213 static inline int gpio_cansleep(unsigned int gpio)
214 {
215         return __gpio_cansleep(gpio);
216 }
217
218 static inline int gpio_to_irq(unsigned gpio)
219 {
220         return __gpio_to_irq(gpio);
221 }
222
223 #else /* !CONFIG_GPIOLIB */
224
225 static inline int gpio_request(unsigned gpio, const char *label)
226 {
227         return bfin_gpio_request(gpio, label);
228 }
229
230 static inline void gpio_free(unsigned gpio)
231 {
232         return bfin_gpio_free(gpio);
233 }
234
235 static inline int gpio_direction_input(unsigned gpio)
236 {
237         return bfin_gpio_direction_input(gpio);
238 }
239
240 static inline int gpio_direction_output(unsigned gpio, int value)
241 {
242         return bfin_gpio_direction_output(gpio, value);
243 }
244
245 static inline int gpio_set_debounce(unsigned gpio, unsigned debounce)
246 {
247         return -EINVAL;
248 }
249
250 static inline int gpio_request_one(unsigned gpio, unsigned long flags, const char *label)
251 {
252         int err;
253
254         err = bfin_gpio_request(gpio, label);
255         if (err)
256                 return err;
257
258         if (flags & GPIOF_DIR_IN)
259                 err = bfin_gpio_direction_input(gpio);
260         else
261                 err = bfin_gpio_direction_output(gpio,
262                         (flags & GPIOF_INIT_HIGH) ? 1 : 0);
263
264         if (err)
265                 bfin_gpio_free(gpio);
266
267         return err;
268 }
269
270 static inline int gpio_request_array(const struct gpio *array, size_t num)
271 {
272         int i, err;
273
274         for (i = 0; i < num; i++, array++) {
275                 err = gpio_request_one(array->gpio, array->flags, array->label);
276                 if (err)
277                         goto err_free;
278         }
279         return 0;
280
281 err_free:
282         while (i--)
283                 bfin_gpio_free((--array)->gpio);
284         return err;
285 }
286
287 static inline void gpio_free_array(const struct gpio *array, size_t num)
288 {
289         while (num--)
290                 bfin_gpio_free((array++)->gpio);
291 }
292
293 static inline int __gpio_get_value(unsigned gpio)
294 {
295         return bfin_gpio_get_value(gpio);
296 }
297
298 static inline void __gpio_set_value(unsigned gpio, int value)
299 {
300         return bfin_gpio_set_value(gpio, value);
301 }
302
303 static inline int gpio_get_value(unsigned gpio)
304 {
305         return __gpio_get_value(gpio);
306 }
307
308 static inline void gpio_set_value(unsigned gpio, int value)
309 {
310         return __gpio_set_value(gpio, value);
311 }
312
313 static inline int gpio_to_irq(unsigned gpio)
314 {
315         if (likely(gpio < MAX_BLACKFIN_GPIOS))
316                 return gpio + GPIO_IRQ_BASE;
317
318         return -EINVAL;
319 }
320
321 #include <asm-generic/gpio.h>           /* cansleep wrappers */
322 #endif  /* !CONFIG_GPIOLIB */
323
324 static inline int irq_to_gpio(unsigned irq)
325 {
326         return (irq - GPIO_IRQ_BASE);
327 }
328
329 #endif /* __ASSEMBLY__ */
330
331 #endif /* __ARCH_BLACKFIN_GPIO_H__ */