2 * File: arch/blackfin/kernel/bfin_gpio.h
4 * Author: Michael Hennerich (hennerich@blackfin.uclinux.org)
10 * Copyright 2004-2008 Analog Devices Inc.
12 * Bugs: Enter bugs at http://blackfin.uclinux.org/
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.
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.
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
30 #ifndef __ARCH_BLACKFIN_GPIO_H__
31 #define __ARCH_BLACKFIN_GPIO_H__
33 #define gpio_bank(x) ((x) >> 4)
34 #define gpio_bit(x) (1<<((x) & 0xF))
35 #define gpio_sub_n(x) ((x) & 0xF)
37 #define GPIO_BANKSIZE 16
38 #define GPIO_BANK_NUM DIV_ROUND_UP(MAX_BLACKFIN_GPIOS, GPIO_BANKSIZE)
40 #include <mach/gpio.h>
91 #define PERIPHERAL_USAGE 1
96 /***********************************************************
98 * FUNCTIONS: Blackfin General Purpose Ports Access Functions
101 * gpio - GPIO Number between 0 and MAX_BLACKFIN_GPIOS
104 * DESCRIPTION: These functions abstract direct register access
105 * to Blackfin processor General Purpose
108 * CAUTION: These functions do not belong to the GPIO Driver API
109 *************************************************************
110 * MODIFICATION HISTORY :
111 **************************************************************/
114 void set_gpio_dir(unsigned, unsigned short);
115 void set_gpio_inen(unsigned, unsigned short);
116 void set_gpio_polar(unsigned, unsigned short);
117 void set_gpio_edge(unsigned, unsigned short);
118 void set_gpio_both(unsigned, unsigned short);
119 void set_gpio_data(unsigned, unsigned short);
120 void set_gpio_maska(unsigned, unsigned short);
121 void set_gpio_maskb(unsigned, unsigned short);
122 void set_gpio_toggle(unsigned);
123 void set_gpiop_dir(unsigned, unsigned short);
124 void set_gpiop_inen(unsigned, unsigned short);
125 void set_gpiop_polar(unsigned, unsigned short);
126 void set_gpiop_edge(unsigned, unsigned short);
127 void set_gpiop_both(unsigned, unsigned short);
128 void set_gpiop_data(unsigned, unsigned short);
129 void set_gpiop_maska(unsigned, unsigned short);
130 void set_gpiop_maskb(unsigned, unsigned short);
131 unsigned short get_gpio_dir(unsigned);
132 unsigned short get_gpio_inen(unsigned);
133 unsigned short get_gpio_polar(unsigned);
134 unsigned short get_gpio_edge(unsigned);
135 unsigned short get_gpio_both(unsigned);
136 unsigned short get_gpio_maska(unsigned);
137 unsigned short get_gpio_maskb(unsigned);
138 unsigned short get_gpio_data(unsigned);
139 unsigned short get_gpiop_dir(unsigned);
140 unsigned short get_gpiop_inen(unsigned);
141 unsigned short get_gpiop_polar(unsigned);
142 unsigned short get_gpiop_edge(unsigned);
143 unsigned short get_gpiop_both(unsigned);
144 unsigned short get_gpiop_maska(unsigned);
145 unsigned short get_gpiop_maskb(unsigned);
146 unsigned short get_gpiop_data(unsigned);
150 unsigned short dummy1
;
151 unsigned short data_clear
;
152 unsigned short dummy2
;
153 unsigned short data_set
;
154 unsigned short dummy3
;
155 unsigned short toggle
;
156 unsigned short dummy4
;
157 unsigned short maska
;
158 unsigned short dummy5
;
159 unsigned short maska_clear
;
160 unsigned short dummy6
;
161 unsigned short maska_set
;
162 unsigned short dummy7
;
163 unsigned short maska_toggle
;
164 unsigned short dummy8
;
165 unsigned short maskb
;
166 unsigned short dummy9
;
167 unsigned short maskb_clear
;
168 unsigned short dummy10
;
169 unsigned short maskb_set
;
170 unsigned short dummy11
;
171 unsigned short maskb_toggle
;
172 unsigned short dummy12
;
174 unsigned short dummy13
;
175 unsigned short polar
;
176 unsigned short dummy14
;
178 unsigned short dummy15
;
180 unsigned short dummy16
;
187 unsigned int bfin_pm_standby_setup(void);
188 void bfin_pm_standby_restore(void);
190 void bfin_gpio_pm_hibernate_restore(void);
191 void bfin_gpio_pm_hibernate_suspend(void);
194 #define PM_WAKE_RISING 0x1
195 #define PM_WAKE_FALLING 0x2
196 #define PM_WAKE_HIGH 0x4
197 #define PM_WAKE_LOW 0x8
198 #define PM_WAKE_BOTH_EDGES (PM_WAKE_RISING | PM_WAKE_FALLING)
199 #define PM_WAKE_IGNORE 0xF0
201 int gpio_pm_wakeup_request(unsigned gpio
, unsigned char type
);
202 void gpio_pm_wakeup_free(unsigned gpio
);
206 unsigned short maska
;
207 unsigned short maskb
;
209 unsigned short polar
;
215 unsigned short reserved
;
218 #endif /*CONFIG_BF54x*/
220 /***********************************************************
222 * FUNCTIONS: Blackfin GPIO Driver
225 * gpio - GPIO Number between 0 and MAX_BLACKFIN_GPIOS
228 * DESCRIPTION: Blackfin GPIO Driver API
231 *************************************************************
232 * MODIFICATION HISTORY :
233 **************************************************************/
235 int bfin_gpio_request(unsigned gpio
, const char *label
);
236 void bfin_gpio_free(unsigned gpio
);
237 int bfin_gpio_irq_request(unsigned gpio
, const char *label
);
238 void bfin_gpio_irq_free(unsigned gpio
);
239 int bfin_gpio_direction_input(unsigned gpio
);
240 int bfin_gpio_direction_output(unsigned gpio
, int value
);
241 int bfin_gpio_get_value(unsigned gpio
);
242 void bfin_gpio_set_value(unsigned gpio
, int value
);
244 #ifdef CONFIG_GPIOLIB
245 #include <asm-generic/gpio.h> /* cansleep wrappers */
247 static inline int gpio_get_value(unsigned int gpio
)
249 if (gpio
< MAX_BLACKFIN_GPIOS
)
250 return bfin_gpio_get_value(gpio
);
252 return __gpio_get_value(gpio
);
255 static inline void gpio_set_value(unsigned int gpio
, int value
)
257 if (gpio
< MAX_BLACKFIN_GPIOS
)
258 bfin_gpio_set_value(gpio
, value
);
260 __gpio_set_value(gpio
, value
);
263 static inline int gpio_cansleep(unsigned int gpio
)
265 return __gpio_cansleep(gpio
);
268 #else /* !CONFIG_GPIOLIB */
270 static inline int gpio_request(unsigned gpio
, const char *label
)
272 return bfin_gpio_request(gpio
, label
);
275 static inline void gpio_free(unsigned gpio
)
277 return bfin_gpio_free(gpio
);
280 static inline int gpio_direction_input(unsigned gpio
)
282 return bfin_gpio_direction_input(gpio
);
285 static inline int gpio_direction_output(unsigned gpio
, int value
)
287 return bfin_gpio_direction_output(gpio
, value
);
290 static inline int gpio_get_value(unsigned gpio
)
292 return bfin_gpio_get_value(gpio
);
295 static inline void gpio_set_value(unsigned gpio
, int value
)
297 return bfin_gpio_set_value(gpio
, value
);
300 #include <asm-generic/gpio.h> /* cansleep wrappers */
301 #endif /* !CONFIG_GPIOLIB */
304 static inline int gpio_to_irq(unsigned gpio
)
306 if (likely(gpio
< MAX_BLACKFIN_GPIOS
))
307 return gpio
+ GPIO_IRQ_BASE
;
312 static inline int irq_to_gpio(unsigned irq
)
314 return (irq
- GPIO_IRQ_BASE
);
317 #endif /* __ASSEMBLY__ */
319 #endif /* __ARCH_BLACKFIN_GPIO_H__ */