• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
30 /***********************************************************
31 *
32 * FUNCTIONS: Blackfin General Purpose Ports Access Functions
33 *
34 * INPUTS/OUTPUTS:
35 * gpio - GPIO Number between 0 and MAX_BLACKFIN_GPIOS
36 *
37 *
38 * DESCRIPTION: These functions abstract direct register access
39 *              to Blackfin processor General Purpose
40 *              Ports Regsiters
41 *
42 * CAUTION: These functions do not belong to the GPIO Driver API
43 *************************************************************
44 * MODIFICATION HISTORY :
45 **************************************************************/
46 
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);
81 
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;
116 };
117 #endif
118 
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
127 
128 #ifdef CONFIG_PM
129 int bfin_pm_standby_ctrl(unsigned ctrl);
130 
bfin_pm_standby_setup(void)131 static inline int bfin_pm_standby_setup(void)
132 {
133 	return bfin_pm_standby_ctrl(1);
134 }
135 
bfin_pm_standby_restore(void)136 static inline void bfin_pm_standby_restore(void)
137 {
138 	bfin_pm_standby_ctrl(0);
139 }
140 
141 void bfin_gpio_pm_hibernate_restore(void);
142 void bfin_gpio_pm_hibernate_suspend(void);
143 
144 # if !BFIN_GPIO_PINT
145 int gpio_pm_wakeup_ctrl(unsigned gpio, unsigned ctrl);
146 
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;
156 
157 	unsigned short fer;
158 	unsigned short reserved;
159 	unsigned short mux;
160 };
161 # endif
162 #endif /*CONFIG_PM*/
163 
164 /***********************************************************
165 *
166 * FUNCTIONS: Blackfin GPIO Driver
167 *
168 * INPUTS/OUTPUTS:
169 * gpio - GPIO Number between 0 and MAX_BLACKFIN_GPIOS
170 *
171 *
172 * DESCRIPTION: Blackfin GPIO Driver API
173 *
174 * CAUTION:
175 *************************************************************
176 * MODIFICATION HISTORY :
177 **************************************************************/
178 
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);
187 
188 #include <asm/irq.h>
189 #include <asm/errno.h>
190 
191 #ifdef CONFIG_GPIOLIB
192 #include <asm-generic/gpio.h>		/* cansleep wrappers */
193 
gpio_get_value(unsigned int gpio)194 static inline int gpio_get_value(unsigned int gpio)
195 {
196 	if (gpio < MAX_BLACKFIN_GPIOS)
197 		return bfin_gpio_get_value(gpio);
198 	else
199 		return __gpio_get_value(gpio);
200 }
201 
gpio_set_value(unsigned int gpio,int value)202 static inline void gpio_set_value(unsigned int gpio, int value)
203 {
204 	if (gpio < MAX_BLACKFIN_GPIOS)
205 		bfin_gpio_set_value(gpio, value);
206 	else
207 		__gpio_set_value(gpio, value);
208 }
209 
gpio_cansleep(unsigned int gpio)210 static inline int gpio_cansleep(unsigned int gpio)
211 {
212 	return __gpio_cansleep(gpio);
213 }
214 
gpio_to_irq(unsigned gpio)215 static inline int gpio_to_irq(unsigned gpio)
216 {
217 	return __gpio_to_irq(gpio);
218 }
219 
220 #else /* !CONFIG_GPIOLIB */
221 
gpio_request(unsigned gpio,const char * label)222 static inline int gpio_request(unsigned gpio, const char *label)
223 {
224 	return bfin_gpio_request(gpio, label);
225 }
226 
gpio_free(unsigned gpio)227 static inline void gpio_free(unsigned gpio)
228 {
229 	return bfin_gpio_free(gpio);
230 }
231 
gpio_direction_input(unsigned gpio)232 static inline int gpio_direction_input(unsigned gpio)
233 {
234 	return bfin_gpio_direction_input(gpio);
235 }
236 
gpio_direction_output(unsigned gpio,int value)237 static inline int gpio_direction_output(unsigned gpio, int value)
238 {
239 	return bfin_gpio_direction_output(gpio, value);
240 }
241 
gpio_set_debounce(unsigned gpio,unsigned debounce)242 static inline int gpio_set_debounce(unsigned gpio, unsigned debounce)
243 {
244 	return -EINVAL;
245 }
246 
__gpio_get_value(unsigned gpio)247 static inline int __gpio_get_value(unsigned gpio)
248 {
249 	return bfin_gpio_get_value(gpio);
250 }
251 
__gpio_set_value(unsigned gpio,int value)252 static inline void __gpio_set_value(unsigned gpio, int value)
253 {
254 	return bfin_gpio_set_value(gpio, value);
255 }
256 
gpio_get_value(unsigned gpio)257 static inline int gpio_get_value(unsigned gpio)
258 {
259 	return __gpio_get_value(gpio);
260 }
261 
gpio_set_value(unsigned gpio,int value)262 static inline void gpio_set_value(unsigned gpio, int value)
263 {
264 	return __gpio_set_value(gpio, value);
265 }
266 
gpio_to_irq(unsigned gpio)267 static inline int gpio_to_irq(unsigned gpio)
268 {
269 	if (likely(gpio < MAX_BLACKFIN_GPIOS))
270 		return gpio + GPIO_IRQ_BASE;
271 
272 	return -EINVAL;
273 }
274 
275 #include <asm-generic/gpio.h>		/* cansleep wrappers */
276 #endif	/* !CONFIG_GPIOLIB */
277 
irq_to_gpio(unsigned irq)278 static inline int irq_to_gpio(unsigned irq)
279 {
280 	return (irq - GPIO_IRQ_BASE);
281 }
282 
283 #endif /* __ASSEMBLY__ */
284 
285 #endif /* __ARCH_BLACKFIN_GPIO_H__ */
286