blob: 2a19852153b2dff0533ead53b979e7bced2dcd72 [file] [log] [blame]
Minkyu Kangb1b24682011-01-24 15:22:23 +09001/*
2 * (C) Copyright 2010 Samsung Electronics
3 * Minkyu Kang <mk7.kang@samsung.com>
4 *
Wolfgang Denkd79de1d2013-07-08 09:37:19 +02005 * SPDX-License-Identifier: GPL-2.0+
Minkyu Kangb1b24682011-01-24 15:22:23 +09006 */
7
8#ifndef __ASM_ARCH_GPIO_H
9#define __ASM_ARCH_GPIO_H
10
11#ifndef __ASSEMBLY__
12struct 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
Chander Kashyap4131a772011-12-06 23:34:12 +000022struct exynos4_gpio_part1 {
Minkyu Kangb1b24682011-01-24 15:22:23 +090023 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
Chander Kashyap4131a772011-12-06 23:34:12 +000041struct exynos4_gpio_part2 {
Minkyu Kangb1b24682011-01-24 15:22:23 +090042 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
Chander Kashyap4131a772011-12-06 23:34:12 +000065struct exynos4_gpio_part3 {
Minkyu Kangb1b24682011-01-24 15:22:23 +090066 struct s5p_gpio_bank z;
67};
68
Chander Kashyap252991e2012-12-25 20:13:42 +000069struct 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
87struct 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
116struct exynos4x12_gpio_part3 {
117 struct s5p_gpio_bank z;
118};
119
120struct 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
Rajeshwari Birjef0ce84f2013-12-26 09:44:23 +0530130struct 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;
140};
141
142struct 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 */
149};
150
151struct 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;
165};
166
167struct 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 */
176};
177
178struct exynos5420_gpio_part5 {
179 struct s5p_gpio_bank z0; /* 0x0386_0000 */
180};
181
Chander Kashyap34076a02012-02-05 23:01:46 +0000182struct 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;
Rajeshwari Shindeab337bc2012-07-03 20:02:59 +0000203 struct s5p_gpio_bank res1[0x3];
204 struct s5p_gpio_bank c4;
205 struct s5p_gpio_bank res2[0x48];
Chander Kashyap34076a02012-02-05 23:01:46 +0000206 struct s5p_gpio_bank x0;
207 struct s5p_gpio_bank x1;
208 struct s5p_gpio_bank x2;
209 struct s5p_gpio_bank x3;
210};
211
212struct 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;
222};
223
224struct exynos5_gpio_part3 {
225 struct s5p_gpio_bank v0;
226 struct s5p_gpio_bank v1;
Rajeshwari Shindeab337bc2012-07-03 20:02:59 +0000227 struct s5p_gpio_bank res1[0x1];
Chander Kashyap34076a02012-02-05 23:01:46 +0000228 struct s5p_gpio_bank v2;
229 struct s5p_gpio_bank v3;
Rajeshwari Shindeab337bc2012-07-03 20:02:59 +0000230 struct s5p_gpio_bank res2[0x1];
Chander Kashyap34076a02012-02-05 23:01:46 +0000231 struct s5p_gpio_bank v4;
232};
233
234struct exynos5_gpio_part4 {
235 struct s5p_gpio_bank z;
236};
237
Minkyu Kangb1b24682011-01-24 15:22:23 +0900238/* functions */
Łukasz Majewski4d954cc2011-07-15 00:16:22 +0000239void s5p_gpio_cfg_pin(struct s5p_gpio_bank *bank, int gpio, int cfg);
240void s5p_gpio_direction_output(struct s5p_gpio_bank *bank, int gpio, int en);
241void s5p_gpio_direction_input(struct s5p_gpio_bank *bank, int gpio);
242void s5p_gpio_set_value(struct s5p_gpio_bank *bank, int gpio, int en);
243unsigned int s5p_gpio_get_value(struct s5p_gpio_bank *bank, int gpio);
244void s5p_gpio_set_pull(struct s5p_gpio_bank *bank, int gpio, int mode);
245void s5p_gpio_set_drv(struct s5p_gpio_bank *bank, int gpio, int mode);
246void s5p_gpio_set_rate(struct s5p_gpio_bank *bank, int gpio, int mode);
Łukasz Majewski1e04cae2011-08-22 22:34:58 +0000247
248/* GPIO pins per bank */
249#define GPIO_PER_BANK 8
250
Chander Kashyap4131a772011-12-06 23:34:12 +0000251#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)) \
Łukasz Majewski1e04cae2011-08-22 22:34:58 +0000255 * GPIO_PER_BANK) + pin)
256
Chander Kashyap34076a02012-02-05 23:01:46 +0000257#define EXYNOS4_GPIO_PART1_MAX ((sizeof(struct exynos4_gpio_part1) \
Łukasz Majewski1e04cae2011-08-22 22:34:58 +0000258 / sizeof(struct s5p_gpio_bank)) * GPIO_PER_BANK)
259
Chander Kashyap4131a772011-12-06 23:34:12 +0000260#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)) \
Chander Kashyap34076a02012-02-05 23:01:46 +0000264 * GPIO_PER_BANK) + pin) + EXYNOS4_GPIO_PART1_MAX)
265
Chander Kashyap252991e2012-12-25 20:13:42 +0000266#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)
271
272#define EXYNOS4X12_GPIO_PART1_MAX ((sizeof(struct exynos4x12_gpio_part1) \
273 / sizeof(struct s5p_gpio_bank)) * GPIO_PER_BANK)
274
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)
280
281#define EXYNOS4X12_GPIO_PART2_MAX ((sizeof(struct exynos4x12_gpio_part2) \
282 / sizeof(struct s5p_gpio_bank)) * GPIO_PER_BANK)
283
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)
289
Chander Kashyap34076a02012-02-05 23:01:46 +0000290#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)
295
296#define EXYNOS5_GPIO_PART1_MAX ((sizeof(struct exynos5_gpio_part1) \
297 / sizeof(struct s5p_gpio_bank)) * GPIO_PER_BANK)
298
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)
304
305#define EXYNOS5_GPIO_PART2_MAX ((sizeof(struct exynos5_gpio_part2) \
306 / sizeof(struct s5p_gpio_bank)) * GPIO_PER_BANK)
307
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)
Łukasz Majewski1e04cae2011-08-22 22:34:58 +0000313
Rajeshwari Birjef0ce84f2013-12-26 09:44:23 +0530314
315/* EXYNOS5420 */
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)
321
322#define EXYNOS5420_GPIO_PART1_MAX ((sizeof(struct exynos5420_gpio_part1) \
323 / sizeof(struct s5p_gpio_bank)) * GPIO_PER_BANK)
324
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)
330
331#define EXYNOS5420_GPIO_PART2_MAX ((sizeof(struct exynos5420_gpio_part2) \
332 / sizeof(struct s5p_gpio_bank)) * GPIO_PER_BANK)
333
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)
339
340#define EXYNOS5420_GPIO_PART3_MAX ((sizeof(struct exynos5420_gpio_part3) \
341 / sizeof(struct s5p_gpio_bank)) * GPIO_PER_BANK)
342
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)
348
349#define EXYNOS5420_GPIO_PART4_MAX ((sizeof(struct exynos5420_gpio_part4) \
350 / sizeof(struct s5p_gpio_bank)) * GPIO_PER_BANK)
351
352#define EXYNOS5420_GPIO_PART5_MAX ((sizeof(struct exynos5420_gpio_part5) \
353 / sizeof(struct s5p_gpio_bank)) * GPIO_PER_BANK)
354
Łukasz Majewski1e04cae2011-08-22 22:34:58 +0000355static inline unsigned int s5p_gpio_base(int nr)
356{
Chander Kashyap34076a02012-02-05 23:01:46 +0000357 if (cpu_is_exynos5()) {
Rajeshwari Birjef0ce84f2013-12-26 09:44:23 +0530358 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;
365 else
366 return EXYNOS5420_GPIO_PART4_BASE;
367 } else {
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;
372 else
373 return EXYNOS5_GPIO_PART3_BASE;
374 }
Chander Kashyap34076a02012-02-05 23:01:46 +0000375 } else if (cpu_is_exynos4()) {
376 if (nr < EXYNOS4_GPIO_PART1_MAX)
377 return EXYNOS4_GPIO_PART1_BASE;
378 else
379 return EXYNOS4_GPIO_PART2_BASE;
380 }
Łukasz Majewski1e04cae2011-08-22 22:34:58 +0000381
382 return 0;
383}
384
Łukasz Majewskid6614b72012-09-04 21:47:46 +0000385static inline unsigned int s5p_gpio_part_max(int nr)
386{
387 if (cpu_is_exynos5()) {
Rajeshwari Birjef0ce84f2013-12-26 09:44:23 +0530388 if (proid_is_exynos5420()) {
389 if (nr < EXYNOS5420_GPIO_PART1_MAX)
390 return 0;
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;
397 else
398 return EXYNOS5420_GPIO_PART4_MAX;
399 } else {
400 if (nr < EXYNOS5_GPIO_PART1_MAX)
401 return 0;
402 else if (nr < EXYNOS5_GPIO_PART2_MAX)
403 return EXYNOS5_GPIO_PART1_MAX;
404 else
405 return EXYNOS5_GPIO_PART2_MAX;
406 }
Łukasz Majewskid6614b72012-09-04 21:47:46 +0000407 } else if (cpu_is_exynos4()) {
Piotr Wilczeke4a61362013-05-21 15:39:04 +0200408 if (proid_is_exynos4412()) {
409 if (nr < EXYNOS4X12_GPIO_PART1_MAX)
410 return 0;
411 else if (nr < EXYNOS4X12_GPIO_PART2_MAX)
412 return EXYNOS4X12_GPIO_PART1_MAX;
413 else
414 return EXYNOS4X12_GPIO_PART2_MAX;
415 } else {
416 if (nr < EXYNOS4_GPIO_PART1_MAX)
417 return 0;
418 else
419 return EXYNOS4_GPIO_PART1_MAX;
420 }
Łukasz Majewskid6614b72012-09-04 21:47:46 +0000421 }
422
423 return 0;
424}
Minkyu Kangb1b24682011-01-24 15:22:23 +0900425#endif
426
427/* Pin configurations */
428#define GPIO_INPUT 0x0
429#define GPIO_OUTPUT 0x1
430#define GPIO_IRQ 0xf
431#define GPIO_FUNC(x) (x)
432
433/* Pull mode */
434#define GPIO_PULL_NONE 0x0
435#define GPIO_PULL_DOWN 0x1
Chander Kashyapb26418c2011-04-18 00:08:43 +0000436#define GPIO_PULL_UP 0x3
Minkyu Kangb1b24682011-01-24 15:22:23 +0900437
438/* Drive Strength level */
439#define GPIO_DRV_1X 0x0
Chander Kashyapb26418c2011-04-18 00:08:43 +0000440#define GPIO_DRV_3X 0x1
441#define GPIO_DRV_2X 0x2
Minkyu Kangb1b24682011-01-24 15:22:23 +0900442#define GPIO_DRV_4X 0x3
443#define GPIO_DRV_FAST 0x0
444#define GPIO_DRV_SLOW 0x1
Minkyu Kangb1b24682011-01-24 15:22:23 +0900445#endif