Linux 3.12.28
[linux/fpc-iii.git] / arch / blackfin / include / asm / gpio.h
blob98d0133346b5a57042baa2e494c3906b597fd608
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>
29 #include <linux/gpio.h>
31 /***********************************************************
33 * FUNCTIONS: Blackfin General Purpose Ports Access Functions
35 * INPUTS/OUTPUTS:
36 * gpio - GPIO Number between 0 and MAX_BLACKFIN_GPIOS
39 * DESCRIPTION: These functions abstract direct register access
40 * to Blackfin processor General Purpose
41 * Ports Regsiters
43 * CAUTION: These functions do not belong to the GPIO Driver API
44 *************************************************************
45 * MODIFICATION HISTORY :
46 **************************************************************/
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);
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;
118 #endif
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
129 #ifdef CONFIG_PM
130 int bfin_pm_standby_ctrl(unsigned ctrl);
132 static inline int bfin_pm_standby_setup(void)
134 return bfin_pm_standby_ctrl(1);
137 static inline void bfin_pm_standby_restore(void)
139 bfin_pm_standby_ctrl(0);
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);
147 # if !BFIN_GPIO_PINT
148 int gpio_pm_wakeup_ctrl(unsigned gpio, unsigned ctrl);
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;
160 unsigned short fer;
161 unsigned short reserved;
162 unsigned short mux;
164 # endif
165 #endif /*CONFIG_PM*/
167 /***********************************************************
169 * FUNCTIONS: Blackfin GPIO Driver
171 * INPUTS/OUTPUTS:
172 * gpio - GPIO Number between 0 and MAX_BLACKFIN_GPIOS
175 * DESCRIPTION: Blackfin GPIO Driver API
177 * CAUTION:
178 *************************************************************
179 * MODIFICATION HISTORY :
180 **************************************************************/
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);
191 #include <asm/irq.h>
192 #include <asm/errno.h>
194 #ifdef CONFIG_GPIOLIB
195 #include <asm-generic/gpio.h> /* cansleep wrappers */
197 static inline int gpio_get_value(unsigned int gpio)
199 if (gpio < MAX_BLACKFIN_GPIOS)
200 return bfin_gpio_get_value(gpio);
201 else
202 return __gpio_get_value(gpio);
205 static inline void gpio_set_value(unsigned int gpio, int value)
207 if (gpio < MAX_BLACKFIN_GPIOS)
208 bfin_gpio_set_value(gpio, value);
209 else
210 __gpio_set_value(gpio, value);
213 static inline int gpio_cansleep(unsigned int gpio)
215 return __gpio_cansleep(gpio);
218 static inline int gpio_to_irq(unsigned gpio)
220 return __gpio_to_irq(gpio);
223 #else /* !CONFIG_GPIOLIB */
225 static inline int gpio_request(unsigned gpio, const char *label)
227 return bfin_gpio_request(gpio, label);
230 static inline void gpio_free(unsigned gpio)
232 return bfin_gpio_free(gpio);
235 static inline int gpio_direction_input(unsigned gpio)
237 return bfin_gpio_direction_input(gpio);
240 static inline int gpio_direction_output(unsigned gpio, int value)
242 return bfin_gpio_direction_output(gpio, value);
245 static inline int gpio_set_debounce(unsigned gpio, unsigned debounce)
247 return -EINVAL;
250 static inline int gpio_request_one(unsigned gpio, unsigned long flags, const char *label)
252 int err;
254 err = bfin_gpio_request(gpio, label);
255 if (err)
256 return err;
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);
264 if (err)
265 bfin_gpio_free(gpio);
267 return err;
270 static inline int gpio_request_array(const struct gpio *array, size_t num)
272 int i, err;
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;
279 return 0;
281 err_free:
282 while (i--)
283 bfin_gpio_free((--array)->gpio);
284 return err;
287 static inline void gpio_free_array(const struct gpio *array, size_t num)
289 while (num--)
290 bfin_gpio_free((array++)->gpio);
293 static inline int __gpio_get_value(unsigned gpio)
295 return bfin_gpio_get_value(gpio);
298 static inline void __gpio_set_value(unsigned gpio, int value)
300 return bfin_gpio_set_value(gpio, value);
303 static inline int gpio_get_value(unsigned gpio)
305 return __gpio_get_value(gpio);
308 static inline void gpio_set_value(unsigned gpio, int value)
310 return __gpio_set_value(gpio, value);
313 static inline int gpio_to_irq(unsigned gpio)
315 if (likely(gpio < MAX_BLACKFIN_GPIOS))
316 return gpio + GPIO_IRQ_BASE;
318 return -EINVAL;
321 #include <asm-generic/gpio.h> /* cansleep wrappers */
322 #endif /* !CONFIG_GPIOLIB */
324 static inline int irq_to_gpio(unsigned irq)
326 return (irq - GPIO_IRQ_BASE);
329 #endif /* __ASSEMBLY__ */
331 #endif /* __ARCH_BLACKFIN_GPIO_H__ */