blob: 224688fc5426953bc8d5807945c83265c3cc8135 [file] [log] [blame]
Mike Frysinger4638b212010-06-02 04:17:26 -04001/*
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#define GPIO_0 0
18#define GPIO_1 1
19#define GPIO_2 2
20#define GPIO_3 3
21#define GPIO_4 4
22#define GPIO_5 5
23#define GPIO_6 6
24#define GPIO_7 7
25#define GPIO_8 8
26#define GPIO_9 9
27#define GPIO_10 10
28#define GPIO_11 11
29#define GPIO_12 12
30#define GPIO_13 13
31#define GPIO_14 14
32#define GPIO_15 15
33#define GPIO_16 16
34#define GPIO_17 17
35#define GPIO_18 18
36#define GPIO_19 19
37#define GPIO_20 20
38#define GPIO_21 21
39#define GPIO_22 22
40#define GPIO_23 23
41#define GPIO_24 24
42#define GPIO_25 25
43#define GPIO_26 26
44#define GPIO_27 27
45#define GPIO_28 28
46#define GPIO_29 29
47#define GPIO_30 30
48#define GPIO_31 31
49#define GPIO_32 32
50#define GPIO_33 33
51#define GPIO_34 34
52#define GPIO_35 35
53#define GPIO_36 36
54#define GPIO_37 37
55#define GPIO_38 38
56#define GPIO_39 39
57#define GPIO_40 40
58#define GPIO_41 41
59#define GPIO_42 42
60#define GPIO_43 43
61#define GPIO_44 44
62#define GPIO_45 45
63#define GPIO_46 46
64#define GPIO_47 47
65
66#define PERIPHERAL_USAGE 1
67#define GPIO_USAGE 0
68
69#ifndef __ASSEMBLY__
70
71#ifndef CONFIG_BF54x
72void set_gpio_dir(unsigned, unsigned short);
73void set_gpio_inen(unsigned, unsigned short);
74void set_gpio_polar(unsigned, unsigned short);
75void set_gpio_edge(unsigned, unsigned short);
76void set_gpio_both(unsigned, unsigned short);
77void set_gpio_data(unsigned, unsigned short);
78void set_gpio_maska(unsigned, unsigned short);
79void set_gpio_maskb(unsigned, unsigned short);
80void set_gpio_toggle(unsigned);
81void set_gpiop_dir(unsigned, unsigned short);
82void set_gpiop_inen(unsigned, unsigned short);
83void set_gpiop_polar(unsigned, unsigned short);
84void set_gpiop_edge(unsigned, unsigned short);
85void set_gpiop_both(unsigned, unsigned short);
86void set_gpiop_data(unsigned, unsigned short);
87void set_gpiop_maska(unsigned, unsigned short);
88void set_gpiop_maskb(unsigned, unsigned short);
89unsigned short get_gpio_dir(unsigned);
90unsigned short get_gpio_inen(unsigned);
91unsigned short get_gpio_polar(unsigned);
92unsigned short get_gpio_edge(unsigned);
93unsigned short get_gpio_both(unsigned);
94unsigned short get_gpio_maska(unsigned);
95unsigned short get_gpio_maskb(unsigned);
96unsigned short get_gpio_data(unsigned);
97unsigned short get_gpiop_dir(unsigned);
98unsigned short get_gpiop_inen(unsigned);
99unsigned short get_gpiop_polar(unsigned);
100unsigned short get_gpiop_edge(unsigned);
101unsigned short get_gpiop_both(unsigned);
102unsigned short get_gpiop_maska(unsigned);
103unsigned short get_gpiop_maskb(unsigned);
104unsigned short get_gpiop_data(unsigned);
105
106struct gpio_port_t {
107 unsigned short data;
108 unsigned short dummy1;
109 unsigned short data_clear;
110 unsigned short dummy2;
111 unsigned short data_set;
112 unsigned short dummy3;
113 unsigned short toggle;
114 unsigned short dummy4;
115 unsigned short maska;
116 unsigned short dummy5;
117 unsigned short maska_clear;
118 unsigned short dummy6;
119 unsigned short maska_set;
120 unsigned short dummy7;
121 unsigned short maska_toggle;
122 unsigned short dummy8;
123 unsigned short maskb;
124 unsigned short dummy9;
125 unsigned short maskb_clear;
126 unsigned short dummy10;
127 unsigned short maskb_set;
128 unsigned short dummy11;
129 unsigned short maskb_toggle;
130 unsigned short dummy12;
131 unsigned short dir;
132 unsigned short dummy13;
133 unsigned short polar;
134 unsigned short dummy14;
135 unsigned short edge;
136 unsigned short dummy15;
137 unsigned short both;
138 unsigned short dummy16;
139 unsigned short inen;
140};
141#endif
142
143#ifdef CONFIG_BFIN_GPIO_TRACK
144void bfin_gpio_labels(void);
Mike Frysinger95b4b9d2011-05-10 12:56:58 -0400145void bfin_gpio_free(unsigned gpio);
Mike Frysinger4638b212010-06-02 04:17:26 -0400146#else
147#define bfin_gpio_labels()
Mike Frysinger95b4b9d2011-05-10 12:56:58 -0400148#define bfin_gpio_free(gpio)
Mike Frysinger4638b212010-06-02 04:17:26 -0400149#define bfin_gpio_request(gpio, label) bfin_gpio_request(gpio)
150#define bfin_special_gpio_request(gpio, label) bfin_special_gpio_request(gpio)
151#endif
152
153#ifdef BFIN_SPECIAL_GPIO_BANKS
154void bfin_special_gpio_free(unsigned gpio);
155int bfin_special_gpio_request(unsigned gpio, const char *label);
156#endif
157
158int bfin_gpio_request(unsigned gpio, const char *label);
Mike Frysinger4638b212010-06-02 04:17:26 -0400159int bfin_gpio_direction_input(unsigned gpio);
160int bfin_gpio_direction_output(unsigned gpio, int value);
161int bfin_gpio_get_value(unsigned gpio);
162void bfin_gpio_set_value(unsigned gpio, int value);
163void bfin_gpio_toggle_value(unsigned gpio);
164
165static inline int gpio_request(unsigned gpio, const char *label)
166{
167 return bfin_gpio_request(gpio, label);
168}
169
170static inline void gpio_free(unsigned gpio)
171{
172 return bfin_gpio_free(gpio);
173}
174
175static inline int gpio_direction_input(unsigned gpio)
176{
177 return bfin_gpio_direction_input(gpio);
178}
179
180static inline int gpio_direction_output(unsigned gpio, int value)
181{
182 return bfin_gpio_direction_output(gpio, value);
183}
184
185static inline int gpio_get_value(unsigned gpio)
186{
187 return bfin_gpio_get_value(gpio);
188}
189
190static inline void gpio_set_value(unsigned gpio, int value)
191{
192 return bfin_gpio_set_value(gpio, value);
193}
194
195static inline int gpio_is_valid(int number)
196{
197 return number >= 0 && number < MAX_BLACKFIN_GPIOS;
198}
199
Mike Frysingera972b8d2011-04-03 04:40:46 -0400200#include <linux/ctype.h>
201
202static inline int name_to_gpio(const char *name)
203{
204 int port_base;
205
206 if (tolower(*name) == 'p') {
207 ++name;
208
209 switch (tolower(*name)) {
210#ifdef GPIO_PA0
211 case 'a': port_base = GPIO_PA0; break;
212#endif
213#ifdef GPIO_PB0
214 case 'b': port_base = GPIO_PB0; break;
215#endif
216#ifdef GPIO_PC0
217 case 'c': port_base = GPIO_PC0; break;
218#endif
219#ifdef GPIO_PD0
220 case 'd': port_base = GPIO_PD0; break;
221#endif
222#ifdef GPIO_PE0
223 case 'e': port_base = GPIO_PE0; break;
224#endif
225#ifdef GPIO_PF0
226 case 'f': port_base = GPIO_PF0; break;
227#endif
228#ifdef GPIO_PG0
229 case 'g': port_base = GPIO_PG0; break;
230#endif
231#ifdef GPIO_PH0
232 case 'h': port_base = GPIO_PH0; break;
233#endif
234#ifdef GPIO_PI0
235 case 'i': port_base = GPIO_PI0; break;
236#endif
237#ifdef GPIO_PJ
238 case 'j': port_base = GPIO_PJ0; break;
239#endif
240 default: return -1;
241 }
242
243 ++name;
244 } else
245 port_base = 0;
246
247 return port_base + simple_strtoul(name, NULL, 10);
248}
249#define name_to_gpio(n) name_to_gpio(n)
250
251#define gpio_status() bfin_gpio_labels()
252
Mike Frysinger4638b212010-06-02 04:17:26 -0400253#endif /* __ASSEMBLY__ */
254
255#endif /* __ARCH_BLACKFIN_GPIO_H__ */