blob: 58a619110779ed628e51248defb7ae58b02cbfb1 [file] [log] [blame]
Mike Frysinger83ebf372010-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
Sonic Zhang3edc3f32013-05-02 13:46:21 +080010#include <asm-generic/gpio.h>
11
Mike Frysinger83ebf372010-06-02 04:17:26 -040012#define gpio_bank(x) ((x) >> 4)
13#define gpio_bit(x) (1<<((x) & 0xF))
14#define gpio_sub_n(x) ((x) & 0xF)
15
16#define GPIO_BANKSIZE 16
17#define GPIO_BANK_NUM DIV_ROUND_UP(MAX_BLACKFIN_GPIOS, GPIO_BANKSIZE)
18
19#define GPIO_0 0
20#define GPIO_1 1
21#define GPIO_2 2
22#define GPIO_3 3
23#define GPIO_4 4
24#define GPIO_5 5
25#define GPIO_6 6
26#define GPIO_7 7
27#define GPIO_8 8
28#define GPIO_9 9
29#define GPIO_10 10
30#define GPIO_11 11
31#define GPIO_12 12
32#define GPIO_13 13
33#define GPIO_14 14
34#define GPIO_15 15
35#define GPIO_16 16
36#define GPIO_17 17
37#define GPIO_18 18
38#define GPIO_19 19
39#define GPIO_20 20
40#define GPIO_21 21
41#define GPIO_22 22
42#define GPIO_23 23
43#define GPIO_24 24
44#define GPIO_25 25
45#define GPIO_26 26
46#define GPIO_27 27
47#define GPIO_28 28
48#define GPIO_29 29
49#define GPIO_30 30
50#define GPIO_31 31
51#define GPIO_32 32
52#define GPIO_33 33
53#define GPIO_34 34
54#define GPIO_35 35
55#define GPIO_36 36
56#define GPIO_37 37
57#define GPIO_38 38
58#define GPIO_39 39
59#define GPIO_40 40
60#define GPIO_41 41
61#define GPIO_42 42
62#define GPIO_43 43
63#define GPIO_44 44
64#define GPIO_45 45
65#define GPIO_46 46
66#define GPIO_47 47
67
68#define PERIPHERAL_USAGE 1
69#define GPIO_USAGE 0
Sonic Zhang3edc3f32013-05-02 13:46:21 +080070#define MAX_GPIOS MAX_BLACKFIN_GPIOS
Mike Frysinger83ebf372010-06-02 04:17:26 -040071
72#ifndef __ASSEMBLY__
73
Sonic Zhang3edc3f32013-05-02 13:46:21 +080074#ifdef CONFIG_ADI_GPIO1
Mike Frysinger83ebf372010-06-02 04:17:26 -040075void set_gpio_dir(unsigned, unsigned short);
76void set_gpio_inen(unsigned, unsigned short);
77void set_gpio_polar(unsigned, unsigned short);
78void set_gpio_edge(unsigned, unsigned short);
79void set_gpio_both(unsigned, unsigned short);
80void set_gpio_data(unsigned, unsigned short);
81void set_gpio_maska(unsigned, unsigned short);
82void set_gpio_maskb(unsigned, unsigned short);
83void set_gpio_toggle(unsigned);
84void set_gpiop_dir(unsigned, unsigned short);
85void set_gpiop_inen(unsigned, unsigned short);
86void set_gpiop_polar(unsigned, unsigned short);
87void set_gpiop_edge(unsigned, unsigned short);
88void set_gpiop_both(unsigned, unsigned short);
89void set_gpiop_data(unsigned, unsigned short);
90void set_gpiop_maska(unsigned, unsigned short);
91void set_gpiop_maskb(unsigned, unsigned short);
92unsigned short get_gpio_dir(unsigned);
93unsigned short get_gpio_inen(unsigned);
94unsigned short get_gpio_polar(unsigned);
95unsigned short get_gpio_edge(unsigned);
96unsigned short get_gpio_both(unsigned);
97unsigned short get_gpio_maska(unsigned);
98unsigned short get_gpio_maskb(unsigned);
99unsigned short get_gpio_data(unsigned);
100unsigned short get_gpiop_dir(unsigned);
101unsigned short get_gpiop_inen(unsigned);
102unsigned short get_gpiop_polar(unsigned);
103unsigned short get_gpiop_edge(unsigned);
104unsigned short get_gpiop_both(unsigned);
105unsigned short get_gpiop_maska(unsigned);
106unsigned short get_gpiop_maskb(unsigned);
107unsigned short get_gpiop_data(unsigned);
108
109struct gpio_port_t {
110 unsigned short data;
111 unsigned short dummy1;
112 unsigned short data_clear;
113 unsigned short dummy2;
114 unsigned short data_set;
115 unsigned short dummy3;
116 unsigned short toggle;
117 unsigned short dummy4;
118 unsigned short maska;
119 unsigned short dummy5;
120 unsigned short maska_clear;
121 unsigned short dummy6;
122 unsigned short maska_set;
123 unsigned short dummy7;
124 unsigned short maska_toggle;
125 unsigned short dummy8;
126 unsigned short maskb;
127 unsigned short dummy9;
128 unsigned short maskb_clear;
129 unsigned short dummy10;
130 unsigned short maskb_set;
131 unsigned short dummy11;
132 unsigned short maskb_toggle;
133 unsigned short dummy12;
134 unsigned short dir;
135 unsigned short dummy13;
136 unsigned short polar;
137 unsigned short dummy14;
138 unsigned short edge;
139 unsigned short dummy15;
140 unsigned short both;
141 unsigned short dummy16;
142 unsigned short inen;
143};
144#endif
145
Sonic Zhang3edc3f32013-05-02 13:46:21 +0800146#ifdef ADI_SPECIAL_GPIO_BANKS
147void special_gpio_free(unsigned gpio);
148int special_gpio_request(unsigned gpio, const char *label);
Mike Frysinger83ebf372010-06-02 04:17:26 -0400149#endif
150
Sonic Zhang3edc3f32013-05-02 13:46:21 +0800151void gpio_labels(void);
Mike Frysinger83ebf372010-06-02 04:17:26 -0400152
153static inline int gpio_is_valid(int number)
154{
Sonic Zhang3edc3f32013-05-02 13:46:21 +0800155 return number >= 0 && number < MAX_GPIOS;
Mike Frysinger83ebf372010-06-02 04:17:26 -0400156}
157
Mike Frysinger0e71f802011-04-03 04:40:46 -0400158#include <linux/ctype.h>
159
160static inline int name_to_gpio(const char *name)
161{
162 int port_base;
163
164 if (tolower(*name) == 'p') {
165 ++name;
166
167 switch (tolower(*name)) {
168#ifdef GPIO_PA0
169 case 'a': port_base = GPIO_PA0; break;
170#endif
171#ifdef GPIO_PB0
172 case 'b': port_base = GPIO_PB0; break;
173#endif
174#ifdef GPIO_PC0
175 case 'c': port_base = GPIO_PC0; break;
176#endif
177#ifdef GPIO_PD0
178 case 'd': port_base = GPIO_PD0; break;
179#endif
180#ifdef GPIO_PE0
181 case 'e': port_base = GPIO_PE0; break;
182#endif
183#ifdef GPIO_PF0
184 case 'f': port_base = GPIO_PF0; break;
185#endif
186#ifdef GPIO_PG0
187 case 'g': port_base = GPIO_PG0; break;
188#endif
189#ifdef GPIO_PH0
190 case 'h': port_base = GPIO_PH0; break;
191#endif
192#ifdef GPIO_PI0
193 case 'i': port_base = GPIO_PI0; break;
194#endif
195#ifdef GPIO_PJ
196 case 'j': port_base = GPIO_PJ0; break;
197#endif
198 default: return -1;
199 }
200
201 ++name;
202 } else
203 port_base = 0;
204
205 return port_base + simple_strtoul(name, NULL, 10);
206}
207#define name_to_gpio(n) name_to_gpio(n)
208
Sonic Zhang3edc3f32013-05-02 13:46:21 +0800209#define gpio_status() gpio_labels()
Mike Frysinger0e71f802011-04-03 04:40:46 -0400210
Mike Frysinger83ebf372010-06-02 04:17:26 -0400211#endif /* __ASSEMBLY__ */
212
213#endif /* __ARCH_BLACKFIN_GPIO_H__ */