]>
Commit | Line | Data |
---|---|---|
008a351a MK |
1 | /* |
2 | * (C) Copyright 2010 Samsung Electronics | |
3 | * Minkyu Kang <mk7.kang@samsung.com> | |
4 | * | |
1a459660 | 5 | * SPDX-License-Identifier: GPL-2.0+ |
008a351a MK |
6 | */ |
7 | ||
8 | #ifndef __ASM_ARCH_GPIO_H | |
9 | #define __ASM_ARCH_GPIO_H | |
10 | ||
11 | #ifndef __ASSEMBLY__ | |
12 | struct s5p_gpio_bank { | |
13 | unsigned int con; | |
14 | unsigned int dat; | |
15 | unsigned int pull; | |
16 | unsigned int drv; | |
17 | unsigned int pdn_con; | |
18 | unsigned int pdn_pull; | |
19 | unsigned char res1[8]; | |
20 | }; | |
21 | ||
393cb361 | 22 | struct exynos4_gpio_part1 { |
008a351a MK |
23 | struct s5p_gpio_bank a0; |
24 | struct s5p_gpio_bank a1; | |
25 | struct s5p_gpio_bank b; | |
26 | struct s5p_gpio_bank c0; | |
27 | struct s5p_gpio_bank c1; | |
28 | struct s5p_gpio_bank d0; | |
29 | struct s5p_gpio_bank d1; | |
30 | struct s5p_gpio_bank e0; | |
31 | struct s5p_gpio_bank e1; | |
32 | struct s5p_gpio_bank e2; | |
33 | struct s5p_gpio_bank e3; | |
34 | struct s5p_gpio_bank e4; | |
35 | struct s5p_gpio_bank f0; | |
36 | struct s5p_gpio_bank f1; | |
37 | struct s5p_gpio_bank f2; | |
38 | struct s5p_gpio_bank f3; | |
39 | }; | |
40 | ||
393cb361 | 41 | struct exynos4_gpio_part2 { |
008a351a MK |
42 | struct s5p_gpio_bank j0; |
43 | struct s5p_gpio_bank j1; | |
44 | struct s5p_gpio_bank k0; | |
45 | struct s5p_gpio_bank k1; | |
46 | struct s5p_gpio_bank k2; | |
47 | struct s5p_gpio_bank k3; | |
48 | struct s5p_gpio_bank l0; | |
49 | struct s5p_gpio_bank l1; | |
50 | struct s5p_gpio_bank l2; | |
51 | struct s5p_gpio_bank y0; | |
52 | struct s5p_gpio_bank y1; | |
53 | struct s5p_gpio_bank y2; | |
54 | struct s5p_gpio_bank y3; | |
55 | struct s5p_gpio_bank y4; | |
56 | struct s5p_gpio_bank y5; | |
57 | struct s5p_gpio_bank y6; | |
58 | struct s5p_gpio_bank res1[80]; | |
59 | struct s5p_gpio_bank x0; | |
60 | struct s5p_gpio_bank x1; | |
61 | struct s5p_gpio_bank x2; | |
62 | struct s5p_gpio_bank x3; | |
63 | }; | |
64 | ||
393cb361 | 65 | struct exynos4_gpio_part3 { |
008a351a MK |
66 | struct s5p_gpio_bank z; |
67 | }; | |
68 | ||
fa442bbb CK |
69 | struct exynos4x12_gpio_part1 { |
70 | struct s5p_gpio_bank a0; | |
71 | struct s5p_gpio_bank a1; | |
72 | struct s5p_gpio_bank b; | |
73 | struct s5p_gpio_bank c0; | |
74 | struct s5p_gpio_bank c1; | |
75 | struct s5p_gpio_bank d0; | |
76 | struct s5p_gpio_bank d1; | |
77 | struct s5p_gpio_bank res1[0x5]; | |
78 | struct s5p_gpio_bank f0; | |
79 | struct s5p_gpio_bank f1; | |
80 | struct s5p_gpio_bank f2; | |
81 | struct s5p_gpio_bank f3; | |
82 | struct s5p_gpio_bank res2[0x2]; | |
83 | struct s5p_gpio_bank j0; | |
84 | struct s5p_gpio_bank j1; | |
85 | }; | |
86 | ||
87 | struct exynos4x12_gpio_part2 { | |
88 | struct s5p_gpio_bank res1[0x2]; | |
89 | struct s5p_gpio_bank k0; | |
90 | struct s5p_gpio_bank k1; | |
91 | struct s5p_gpio_bank k2; | |
92 | struct s5p_gpio_bank k3; | |
93 | struct s5p_gpio_bank l0; | |
94 | struct s5p_gpio_bank l1; | |
95 | struct s5p_gpio_bank l2; | |
96 | struct s5p_gpio_bank y0; | |
97 | struct s5p_gpio_bank y1; | |
98 | struct s5p_gpio_bank y2; | |
99 | struct s5p_gpio_bank y3; | |
100 | struct s5p_gpio_bank y4; | |
101 | struct s5p_gpio_bank y5; | |
102 | struct s5p_gpio_bank y6; | |
103 | struct s5p_gpio_bank res2[0x3]; | |
104 | struct s5p_gpio_bank m0; | |
105 | struct s5p_gpio_bank m1; | |
106 | struct s5p_gpio_bank m2; | |
107 | struct s5p_gpio_bank m3; | |
108 | struct s5p_gpio_bank m4; | |
109 | struct s5p_gpio_bank res3[0x48]; | |
110 | struct s5p_gpio_bank x0; | |
111 | struct s5p_gpio_bank x1; | |
112 | struct s5p_gpio_bank x2; | |
113 | struct s5p_gpio_bank x3; | |
114 | }; | |
115 | ||
116 | struct exynos4x12_gpio_part3 { | |
117 | struct s5p_gpio_bank z; | |
118 | }; | |
119 | ||
120 | struct exynos4x12_gpio_part4 { | |
121 | struct s5p_gpio_bank v0; | |
122 | struct s5p_gpio_bank v1; | |
123 | struct s5p_gpio_bank res1[0x1]; | |
124 | struct s5p_gpio_bank v2; | |
125 | struct s5p_gpio_bank v3; | |
126 | struct s5p_gpio_bank res2[0x1]; | |
127 | struct s5p_gpio_bank v4; | |
128 | }; | |
129 | ||
37bb6d89 CK |
130 | struct exynos5_gpio_part1 { |
131 | struct s5p_gpio_bank a0; | |
132 | struct s5p_gpio_bank a1; | |
133 | struct s5p_gpio_bank a2; | |
134 | struct s5p_gpio_bank b0; | |
135 | struct s5p_gpio_bank b1; | |
136 | struct s5p_gpio_bank b2; | |
137 | struct s5p_gpio_bank b3; | |
138 | struct s5p_gpio_bank c0; | |
139 | struct s5p_gpio_bank c1; | |
140 | struct s5p_gpio_bank c2; | |
141 | struct s5p_gpio_bank c3; | |
142 | struct s5p_gpio_bank d0; | |
143 | struct s5p_gpio_bank d1; | |
144 | struct s5p_gpio_bank y0; | |
145 | struct s5p_gpio_bank y1; | |
146 | struct s5p_gpio_bank y2; | |
147 | struct s5p_gpio_bank y3; | |
148 | struct s5p_gpio_bank y4; | |
149 | struct s5p_gpio_bank y5; | |
150 | struct s5p_gpio_bank y6; | |
fd8ef014 RS |
151 | struct s5p_gpio_bank res1[0x3]; |
152 | struct s5p_gpio_bank c4; | |
153 | struct s5p_gpio_bank res2[0x48]; | |
37bb6d89 CK |
154 | struct s5p_gpio_bank x0; |
155 | struct s5p_gpio_bank x1; | |
156 | struct s5p_gpio_bank x2; | |
157 | struct s5p_gpio_bank x3; | |
158 | }; | |
159 | ||
160 | struct exynos5_gpio_part2 { | |
161 | struct s5p_gpio_bank e0; | |
162 | struct s5p_gpio_bank e1; | |
163 | struct s5p_gpio_bank f0; | |
164 | struct s5p_gpio_bank f1; | |
165 | struct s5p_gpio_bank g0; | |
166 | struct s5p_gpio_bank g1; | |
167 | struct s5p_gpio_bank g2; | |
168 | struct s5p_gpio_bank h0; | |
169 | struct s5p_gpio_bank h1; | |
170 | }; | |
171 | ||
172 | struct exynos5_gpio_part3 { | |
173 | struct s5p_gpio_bank v0; | |
174 | struct s5p_gpio_bank v1; | |
fd8ef014 | 175 | struct s5p_gpio_bank res1[0x1]; |
37bb6d89 CK |
176 | struct s5p_gpio_bank v2; |
177 | struct s5p_gpio_bank v3; | |
fd8ef014 | 178 | struct s5p_gpio_bank res2[0x1]; |
37bb6d89 CK |
179 | struct s5p_gpio_bank v4; |
180 | }; | |
181 | ||
182 | struct exynos5_gpio_part4 { | |
183 | struct s5p_gpio_bank z; | |
184 | }; | |
185 | ||
008a351a | 186 | /* functions */ |
ef5d9eb9 ŁM |
187 | void s5p_gpio_cfg_pin(struct s5p_gpio_bank *bank, int gpio, int cfg); |
188 | void s5p_gpio_direction_output(struct s5p_gpio_bank *bank, int gpio, int en); | |
189 | void s5p_gpio_direction_input(struct s5p_gpio_bank *bank, int gpio); | |
190 | void s5p_gpio_set_value(struct s5p_gpio_bank *bank, int gpio, int en); | |
191 | unsigned int s5p_gpio_get_value(struct s5p_gpio_bank *bank, int gpio); | |
192 | void s5p_gpio_set_pull(struct s5p_gpio_bank *bank, int gpio, int mode); | |
193 | void s5p_gpio_set_drv(struct s5p_gpio_bank *bank, int gpio, int mode); | |
194 | void s5p_gpio_set_rate(struct s5p_gpio_bank *bank, int gpio, int mode); | |
9f15bc0c ŁM |
195 | |
196 | /* GPIO pins per bank */ | |
197 | #define GPIO_PER_BANK 8 | |
198 | ||
393cb361 CK |
199 | #define exynos4_gpio_part1_get_nr(bank, pin) \ |
200 | ((((((unsigned int) &(((struct exynos4_gpio_part1 *) \ | |
201 | EXYNOS4_GPIO_PART1_BASE)->bank)) \ | |
202 | - EXYNOS4_GPIO_PART1_BASE) / sizeof(struct s5p_gpio_bank)) \ | |
9f15bc0c ŁM |
203 | * GPIO_PER_BANK) + pin) |
204 | ||
37bb6d89 | 205 | #define EXYNOS4_GPIO_PART1_MAX ((sizeof(struct exynos4_gpio_part1) \ |
9f15bc0c ŁM |
206 | / sizeof(struct s5p_gpio_bank)) * GPIO_PER_BANK) |
207 | ||
393cb361 CK |
208 | #define exynos4_gpio_part2_get_nr(bank, pin) \ |
209 | (((((((unsigned int) &(((struct exynos4_gpio_part2 *) \ | |
210 | EXYNOS4_GPIO_PART2_BASE)->bank)) \ | |
211 | - EXYNOS4_GPIO_PART2_BASE) / sizeof(struct s5p_gpio_bank)) \ | |
37bb6d89 CK |
212 | * GPIO_PER_BANK) + pin) + EXYNOS4_GPIO_PART1_MAX) |
213 | ||
fa442bbb CK |
214 | #define exynos4x12_gpio_part1_get_nr(bank, pin) \ |
215 | ((((((unsigned int) &(((struct exynos4x12_gpio_part1 *) \ | |
216 | EXYNOS4X12_GPIO_PART1_BASE)->bank)) \ | |
217 | - EXYNOS4X12_GPIO_PART1_BASE) / sizeof(struct s5p_gpio_bank)) \ | |
218 | * GPIO_PER_BANK) + pin) | |
219 | ||
220 | #define EXYNOS4X12_GPIO_PART1_MAX ((sizeof(struct exynos4x12_gpio_part1) \ | |
221 | / sizeof(struct s5p_gpio_bank)) * GPIO_PER_BANK) | |
222 | ||
223 | #define exynos4x12_gpio_part2_get_nr(bank, pin) \ | |
224 | (((((((unsigned int) &(((struct exynos4x12_gpio_part2 *) \ | |
225 | EXYNOS4X12_GPIO_PART2_BASE)->bank)) \ | |
226 | - EXYNOS4X12_GPIO_PART2_BASE) / sizeof(struct s5p_gpio_bank)) \ | |
227 | * GPIO_PER_BANK) + pin) + EXYNOS4X12_GPIO_PART1_MAX) | |
228 | ||
229 | #define EXYNOS4X12_GPIO_PART2_MAX ((sizeof(struct exynos4x12_gpio_part2) \ | |
230 | / sizeof(struct s5p_gpio_bank)) * GPIO_PER_BANK) | |
231 | ||
232 | #define exynos4x12_gpio_part3_get_nr(bank, pin) \ | |
233 | (((((((unsigned int) &(((struct exynos4x12_gpio_part3 *) \ | |
234 | EXYNOS4X12_GPIO_PART3_BASE)->bank)) \ | |
235 | - EXYNOS4X12_GPIO_PART3_BASE) / sizeof(struct s5p_gpio_bank)) \ | |
236 | * GPIO_PER_BANK) + pin) + EXYNOS4X12_GPIO_PART2_MAX) | |
237 | ||
37bb6d89 CK |
238 | #define exynos5_gpio_part1_get_nr(bank, pin) \ |
239 | ((((((unsigned int) &(((struct exynos5_gpio_part1 *) \ | |
240 | EXYNOS5_GPIO_PART1_BASE)->bank)) \ | |
241 | - EXYNOS5_GPIO_PART1_BASE) / sizeof(struct s5p_gpio_bank)) \ | |
242 | * GPIO_PER_BANK) + pin) | |
243 | ||
244 | #define EXYNOS5_GPIO_PART1_MAX ((sizeof(struct exynos5_gpio_part1) \ | |
245 | / sizeof(struct s5p_gpio_bank)) * GPIO_PER_BANK) | |
246 | ||
247 | #define exynos5_gpio_part2_get_nr(bank, pin) \ | |
248 | (((((((unsigned int) &(((struct exynos5_gpio_part2 *) \ | |
249 | EXYNOS5_GPIO_PART2_BASE)->bank)) \ | |
250 | - EXYNOS5_GPIO_PART2_BASE) / sizeof(struct s5p_gpio_bank)) \ | |
251 | * GPIO_PER_BANK) + pin) + EXYNOS5_GPIO_PART1_MAX) | |
252 | ||
253 | #define EXYNOS5_GPIO_PART2_MAX ((sizeof(struct exynos5_gpio_part2) \ | |
254 | / sizeof(struct s5p_gpio_bank)) * GPIO_PER_BANK) | |
255 | ||
256 | #define exynos5_gpio_part3_get_nr(bank, pin) \ | |
257 | (((((((unsigned int) &(((struct exynos5_gpio_part3 *) \ | |
258 | EXYNOS5_GPIO_PART3_BASE)->bank)) \ | |
259 | - EXYNOS5_GPIO_PART3_BASE) / sizeof(struct s5p_gpio_bank)) \ | |
260 | * GPIO_PER_BANK) + pin) + EXYNOS5_GPIO_PART2_MAX) | |
9f15bc0c ŁM |
261 | |
262 | static inline unsigned int s5p_gpio_base(int nr) | |
263 | { | |
37bb6d89 CK |
264 | if (cpu_is_exynos5()) { |
265 | if (nr < EXYNOS5_GPIO_PART1_MAX) | |
266 | return EXYNOS5_GPIO_PART1_BASE; | |
267 | else if (nr < EXYNOS5_GPIO_PART2_MAX) | |
268 | return EXYNOS5_GPIO_PART2_BASE; | |
269 | else | |
270 | return EXYNOS5_GPIO_PART3_BASE; | |
271 | ||
272 | } else if (cpu_is_exynos4()) { | |
273 | if (nr < EXYNOS4_GPIO_PART1_MAX) | |
274 | return EXYNOS4_GPIO_PART1_BASE; | |
275 | else | |
276 | return EXYNOS4_GPIO_PART2_BASE; | |
277 | } | |
9f15bc0c ŁM |
278 | |
279 | return 0; | |
280 | } | |
281 | ||
822593f0 ŁM |
282 | static inline unsigned int s5p_gpio_part_max(int nr) |
283 | { | |
284 | if (cpu_is_exynos5()) { | |
285 | if (nr < EXYNOS5_GPIO_PART1_MAX) | |
286 | return 0; | |
287 | else if (nr < EXYNOS5_GPIO_PART2_MAX) | |
288 | return EXYNOS5_GPIO_PART1_MAX; | |
289 | else | |
290 | return EXYNOS5_GPIO_PART2_MAX; | |
291 | ||
292 | } else if (cpu_is_exynos4()) { | |
293 | if (nr < EXYNOS4_GPIO_PART1_MAX) | |
294 | return 0; | |
295 | else | |
296 | return EXYNOS4_GPIO_PART1_MAX; | |
297 | } | |
298 | ||
299 | return 0; | |
300 | } | |
008a351a MK |
301 | #endif |
302 | ||
303 | /* Pin configurations */ | |
304 | #define GPIO_INPUT 0x0 | |
305 | #define GPIO_OUTPUT 0x1 | |
306 | #define GPIO_IRQ 0xf | |
307 | #define GPIO_FUNC(x) (x) | |
308 | ||
309 | /* Pull mode */ | |
310 | #define GPIO_PULL_NONE 0x0 | |
311 | #define GPIO_PULL_DOWN 0x1 | |
898ddf0a | 312 | #define GPIO_PULL_UP 0x3 |
008a351a MK |
313 | |
314 | /* Drive Strength level */ | |
315 | #define GPIO_DRV_1X 0x0 | |
898ddf0a CK |
316 | #define GPIO_DRV_3X 0x1 |
317 | #define GPIO_DRV_2X 0x2 | |
008a351a MK |
318 | #define GPIO_DRV_4X 0x3 |
319 | #define GPIO_DRV_FAST 0x0 | |
320 | #define GPIO_DRV_SLOW 0x1 | |
008a351a | 321 | #endif |