2 * (C) Copyright 2010 Samsung Electronics
3 * Minkyu Kang <mk7.kang@samsung.com>
5 * SPDX-License-Identifier: GPL-2.0+
8 #ifndef __ASM_ARCH_GPIO_H
9 #define __ASM_ARCH_GPIO_H
12 struct s5p_gpio_bank {
18 unsigned int pdn_pull;
19 unsigned char res1[8];
22 struct exynos4_gpio_part1 {
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;
41 struct exynos4_gpio_part2 {
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;
65 struct exynos4_gpio_part3 {
66 struct s5p_gpio_bank z;
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;
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;
116 struct exynos4x12_gpio_part3 {
117 struct s5p_gpio_bank z;
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;
130 struct exynos5420_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 b4;
139 struct s5p_gpio_bank h0;
142 struct exynos5420_gpio_part2 {
143 struct s5p_gpio_bank y7; /* 0x1340_0000 */
144 struct s5p_gpio_bank res[0x5f]; /* */
145 struct s5p_gpio_bank x0; /* 0x1340_0C00 */
146 struct s5p_gpio_bank x1; /* 0x1340_0C20 */
147 struct s5p_gpio_bank x2; /* 0x1340_0C40 */
148 struct s5p_gpio_bank x3; /* 0x1340_0C60 */
151 struct exynos5420_gpio_part3 {
152 struct s5p_gpio_bank c0;
153 struct s5p_gpio_bank c1;
154 struct s5p_gpio_bank c2;
155 struct s5p_gpio_bank c3;
156 struct s5p_gpio_bank c4;
157 struct s5p_gpio_bank d1;
158 struct s5p_gpio_bank y0;
159 struct s5p_gpio_bank y1;
160 struct s5p_gpio_bank y2;
161 struct s5p_gpio_bank y3;
162 struct s5p_gpio_bank y4;
163 struct s5p_gpio_bank y5;
164 struct s5p_gpio_bank y6;
167 struct exynos5420_gpio_part4 {
168 struct s5p_gpio_bank e0; /* 0x1400_0000 */
169 struct s5p_gpio_bank e1; /* 0x1400_0020 */
170 struct s5p_gpio_bank f0; /* 0x1400_0040 */
171 struct s5p_gpio_bank f1; /* 0x1400_0060 */
172 struct s5p_gpio_bank g0; /* 0x1400_0080 */
173 struct s5p_gpio_bank g1; /* 0x1400_00A0 */
174 struct s5p_gpio_bank g2; /* 0x1400_00C0 */
175 struct s5p_gpio_bank j4; /* 0x1400_00E0 */
178 struct exynos5420_gpio_part5 {
179 struct s5p_gpio_bank z0; /* 0x0386_0000 */
182 struct exynos5_gpio_part1 {
183 struct s5p_gpio_bank a0;
184 struct s5p_gpio_bank a1;
185 struct s5p_gpio_bank a2;
186 struct s5p_gpio_bank b0;
187 struct s5p_gpio_bank b1;
188 struct s5p_gpio_bank b2;
189 struct s5p_gpio_bank b3;
190 struct s5p_gpio_bank c0;
191 struct s5p_gpio_bank c1;
192 struct s5p_gpio_bank c2;
193 struct s5p_gpio_bank c3;
194 struct s5p_gpio_bank d0;
195 struct s5p_gpio_bank d1;
196 struct s5p_gpio_bank y0;
197 struct s5p_gpio_bank y1;
198 struct s5p_gpio_bank y2;
199 struct s5p_gpio_bank y3;
200 struct s5p_gpio_bank y4;
201 struct s5p_gpio_bank y5;
202 struct s5p_gpio_bank y6;
203 struct s5p_gpio_bank res1[0x3];
204 struct s5p_gpio_bank c4;
205 struct s5p_gpio_bank res2[0x48];
206 struct s5p_gpio_bank x0;
207 struct s5p_gpio_bank x1;
208 struct s5p_gpio_bank x2;
209 struct s5p_gpio_bank x3;
212 struct exynos5_gpio_part2 {
213 struct s5p_gpio_bank e0;
214 struct s5p_gpio_bank e1;
215 struct s5p_gpio_bank f0;
216 struct s5p_gpio_bank f1;
217 struct s5p_gpio_bank g0;
218 struct s5p_gpio_bank g1;
219 struct s5p_gpio_bank g2;
220 struct s5p_gpio_bank h0;
221 struct s5p_gpio_bank h1;
224 struct exynos5_gpio_part3 {
225 struct s5p_gpio_bank v0;
226 struct s5p_gpio_bank v1;
227 struct s5p_gpio_bank res1[0x1];
228 struct s5p_gpio_bank v2;
229 struct s5p_gpio_bank v3;
230 struct s5p_gpio_bank res2[0x1];
231 struct s5p_gpio_bank v4;
234 struct exynos5_gpio_part4 {
235 struct s5p_gpio_bank z;
239 void s5p_gpio_cfg_pin(struct s5p_gpio_bank *bank, int gpio, int cfg);
240 void s5p_gpio_direction_output(struct s5p_gpio_bank *bank, int gpio, int en);
241 void s5p_gpio_direction_input(struct s5p_gpio_bank *bank, int gpio);
242 void s5p_gpio_set_value(struct s5p_gpio_bank *bank, int gpio, int en);
243 unsigned int s5p_gpio_get_value(struct s5p_gpio_bank *bank, int gpio);
244 void s5p_gpio_set_pull(struct s5p_gpio_bank *bank, int gpio, int mode);
245 void s5p_gpio_set_drv(struct s5p_gpio_bank *bank, int gpio, int mode);
246 void s5p_gpio_set_rate(struct s5p_gpio_bank *bank, int gpio, int mode);
248 /* GPIO pins per bank */
249 #define GPIO_PER_BANK 8
251 #define exynos4_gpio_part1_get_nr(bank, pin) \
252 ((((((unsigned int) &(((struct exynos4_gpio_part1 *) \
253 EXYNOS4_GPIO_PART1_BASE)->bank)) \
254 - EXYNOS4_GPIO_PART1_BASE) / sizeof(struct s5p_gpio_bank)) \
255 * GPIO_PER_BANK) + pin)
257 #define EXYNOS4_GPIO_PART1_MAX ((sizeof(struct exynos4_gpio_part1) \
258 / sizeof(struct s5p_gpio_bank)) * GPIO_PER_BANK)
260 #define exynos4_gpio_part2_get_nr(bank, pin) \
261 (((((((unsigned int) &(((struct exynos4_gpio_part2 *) \
262 EXYNOS4_GPIO_PART2_BASE)->bank)) \
263 - EXYNOS4_GPIO_PART2_BASE) / sizeof(struct s5p_gpio_bank)) \
264 * GPIO_PER_BANK) + pin) + EXYNOS4_GPIO_PART1_MAX)
266 #define exynos4x12_gpio_part1_get_nr(bank, pin) \
267 ((((((unsigned int) &(((struct exynos4x12_gpio_part1 *) \
268 EXYNOS4X12_GPIO_PART1_BASE)->bank)) \
269 - EXYNOS4X12_GPIO_PART1_BASE) / sizeof(struct s5p_gpio_bank)) \
270 * GPIO_PER_BANK) + pin)
272 #define EXYNOS4X12_GPIO_PART1_MAX ((sizeof(struct exynos4x12_gpio_part1) \
273 / sizeof(struct s5p_gpio_bank)) * GPIO_PER_BANK)
275 #define exynos4x12_gpio_part2_get_nr(bank, pin) \
276 (((((((unsigned int) &(((struct exynos4x12_gpio_part2 *) \
277 EXYNOS4X12_GPIO_PART2_BASE)->bank)) \
278 - EXYNOS4X12_GPIO_PART2_BASE) / sizeof(struct s5p_gpio_bank)) \
279 * GPIO_PER_BANK) + pin) + EXYNOS4X12_GPIO_PART1_MAX)
281 #define EXYNOS4X12_GPIO_PART2_MAX ((sizeof(struct exynos4x12_gpio_part2) \
282 / sizeof(struct s5p_gpio_bank)) * GPIO_PER_BANK)
284 #define exynos4x12_gpio_part3_get_nr(bank, pin) \
285 (((((((unsigned int) &(((struct exynos4x12_gpio_part3 *) \
286 EXYNOS4X12_GPIO_PART3_BASE)->bank)) \
287 - EXYNOS4X12_GPIO_PART3_BASE) / sizeof(struct s5p_gpio_bank)) \
288 * GPIO_PER_BANK) + pin) + EXYNOS4X12_GPIO_PART2_MAX)
290 #define exynos5_gpio_part1_get_nr(bank, pin) \
291 ((((((unsigned int) &(((struct exynos5_gpio_part1 *) \
292 EXYNOS5_GPIO_PART1_BASE)->bank)) \
293 - EXYNOS5_GPIO_PART1_BASE) / sizeof(struct s5p_gpio_bank)) \
294 * GPIO_PER_BANK) + pin)
296 #define EXYNOS5_GPIO_PART1_MAX ((sizeof(struct exynos5_gpio_part1) \
297 / sizeof(struct s5p_gpio_bank)) * GPIO_PER_BANK)
299 #define exynos5_gpio_part2_get_nr(bank, pin) \
300 (((((((unsigned int) &(((struct exynos5_gpio_part2 *) \
301 EXYNOS5_GPIO_PART2_BASE)->bank)) \
302 - EXYNOS5_GPIO_PART2_BASE) / sizeof(struct s5p_gpio_bank)) \
303 * GPIO_PER_BANK) + pin) + EXYNOS5_GPIO_PART1_MAX)
305 #define EXYNOS5_GPIO_PART2_MAX ((sizeof(struct exynos5_gpio_part2) \
306 / sizeof(struct s5p_gpio_bank)) * GPIO_PER_BANK)
308 #define exynos5_gpio_part3_get_nr(bank, pin) \
309 (((((((unsigned int) &(((struct exynos5_gpio_part3 *) \
310 EXYNOS5_GPIO_PART3_BASE)->bank)) \
311 - EXYNOS5_GPIO_PART3_BASE) / sizeof(struct s5p_gpio_bank)) \
312 * GPIO_PER_BANK) + pin) + EXYNOS5_GPIO_PART2_MAX)
316 #define exynos5420_gpio_part1_get_nr(bank, pin) \
317 ((((((unsigned int) &(((struct exynos5420_gpio_part1 *)\
318 EXYNOS5420_GPIO_PART1_BASE)->bank)) \
319 - EXYNOS5420_GPIO_PART1_BASE) / sizeof(struct s5p_gpio_bank)) \
320 * GPIO_PER_BANK) + pin)
322 #define EXYNOS5420_GPIO_PART1_MAX ((sizeof(struct exynos5420_gpio_part1) \
323 / sizeof(struct s5p_gpio_bank)) * GPIO_PER_BANK)
325 #define exynos5420_gpio_part2_get_nr(bank, pin) \
326 (((((((unsigned int) &(((struct exynos5420_gpio_part2 *)\
327 EXYNOS5420_GPIO_PART2_BASE)->bank)) \
328 - EXYNOS5420_GPIO_PART2_BASE) / sizeof(struct s5p_gpio_bank)) \
329 * GPIO_PER_BANK) + pin) + EXYNOS5420_GPIO_PART1_MAX)
331 #define EXYNOS5420_GPIO_PART2_MAX ((sizeof(struct exynos5420_gpio_part2) \
332 / sizeof(struct s5p_gpio_bank)) * GPIO_PER_BANK)
334 #define exynos5420_gpio_part3_get_nr(bank, pin) \
335 (((((((unsigned int) &(((struct exynos5420_gpio_part3 *)\
336 EXYNOS5420_GPIO_PART3_BASE)->bank)) \
337 - EXYNOS5420_GPIO_PART3_BASE) / sizeof(struct s5p_gpio_bank)) \
338 * GPIO_PER_BANK) + pin) + EXYNOS5420_GPIO_PART2_MAX)
340 #define EXYNOS5420_GPIO_PART3_MAX ((sizeof(struct exynos5420_gpio_part3) \
341 / sizeof(struct s5p_gpio_bank)) * GPIO_PER_BANK)
343 #define exynos5420_gpio_part4_get_nr(bank, pin) \
344 (((((((unsigned int) &(((struct exynos5420_gpio_part4 *)\
345 EXYNOS5420_GPIO_PART4_BASE)->bank)) \
346 - EXYNOS5420_GPIO_PART4_BASE) / sizeof(struct s5p_gpio_bank)) \
347 * GPIO_PER_BANK) + pin) + EXYNOS5420_GPIO_PART3_MAX)
349 #define EXYNOS5420_GPIO_PART4_MAX ((sizeof(struct exynos5420_gpio_part4) \
350 / sizeof(struct s5p_gpio_bank)) * GPIO_PER_BANK)
352 #define EXYNOS5420_GPIO_PART5_MAX ((sizeof(struct exynos5420_gpio_part5) \
353 / sizeof(struct s5p_gpio_bank)) * GPIO_PER_BANK)
355 static inline unsigned int s5p_gpio_base(int nr)
357 if (cpu_is_exynos5()) {
358 if (proid_is_exynos5420()) {
359 if (nr < EXYNOS5420_GPIO_PART1_MAX)
360 return EXYNOS5420_GPIO_PART1_BASE;
361 else if (nr < EXYNOS5420_GPIO_PART2_MAX)
362 return EXYNOS5420_GPIO_PART2_BASE;
363 else if (nr < EXYNOS5420_GPIO_PART3_MAX)
364 return EXYNOS5420_GPIO_PART3_BASE;
366 return EXYNOS5420_GPIO_PART4_BASE;
368 if (nr < EXYNOS5_GPIO_PART1_MAX)
369 return EXYNOS5_GPIO_PART1_BASE;
370 else if (nr < EXYNOS5_GPIO_PART2_MAX)
371 return EXYNOS5_GPIO_PART2_BASE;
373 return EXYNOS5_GPIO_PART3_BASE;
375 } else if (cpu_is_exynos4()) {
376 if (nr < EXYNOS4_GPIO_PART1_MAX)
377 return EXYNOS4_GPIO_PART1_BASE;
379 return EXYNOS4_GPIO_PART2_BASE;
385 static inline unsigned int s5p_gpio_part_max(int nr)
387 if (cpu_is_exynos5()) {
388 if (proid_is_exynos5420()) {
389 if (nr < EXYNOS5420_GPIO_PART1_MAX)
391 else if (nr < EXYNOS5420_GPIO_PART2_MAX)
392 return EXYNOS5420_GPIO_PART1_MAX;
393 else if (nr < EXYNOS5420_GPIO_PART3_MAX)
394 return EXYNOS5420_GPIO_PART2_MAX;
395 else if (nr < EXYNOS5420_GPIO_PART4_MAX)
396 return EXYNOS5420_GPIO_PART3_MAX;
398 return EXYNOS5420_GPIO_PART4_MAX;
400 if (nr < EXYNOS5_GPIO_PART1_MAX)
402 else if (nr < EXYNOS5_GPIO_PART2_MAX)
403 return EXYNOS5_GPIO_PART1_MAX;
405 return EXYNOS5_GPIO_PART2_MAX;
407 } else if (cpu_is_exynos4()) {
408 if (proid_is_exynos4412()) {
409 if (nr < EXYNOS4X12_GPIO_PART1_MAX)
411 else if (nr < EXYNOS4X12_GPIO_PART2_MAX)
412 return EXYNOS4X12_GPIO_PART1_MAX;
414 return EXYNOS4X12_GPIO_PART2_MAX;
416 if (nr < EXYNOS4_GPIO_PART1_MAX)
419 return EXYNOS4_GPIO_PART1_MAX;
427 /* Pin configurations */
428 #define GPIO_INPUT 0x0
429 #define GPIO_OUTPUT 0x1
431 #define GPIO_FUNC(x) (x)
434 #define GPIO_PULL_NONE 0x0
435 #define GPIO_PULL_DOWN 0x1
436 #define GPIO_PULL_UP 0x3
438 /* Drive Strength level */
439 #define GPIO_DRV_1X 0x0
440 #define GPIO_DRV_3X 0x1
441 #define GPIO_DRV_2X 0x2
442 #define GPIO_DRV_4X 0x3
443 #define GPIO_DRV_FAST 0x0
444 #define GPIO_DRV_SLOW 0x1