blob: d6868fa25dd31a6a6d41140f7ab3d84f3ef1e2dc [file] [log] [blame]
Minkyu Kang008a3512011-01-24 15:22:23 +09001/*
2 * (C) Copyright 2010 Samsung Electronics
3 * Minkyu Kang <mk7.kang@samsung.com>
4 *
Wolfgang Denk1a459662013-07-08 09:37:19 +02005 * SPDX-License-Identifier: GPL-2.0+
Minkyu Kang008a3512011-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 Kashyap393cb362011-12-06 23:34:12 +000022struct exynos4_gpio_part1 {
Minkyu Kang008a3512011-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 Kashyap393cb362011-12-06 23:34:12 +000041struct exynos4_gpio_part2 {
Minkyu Kang008a3512011-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 Kashyap393cb362011-12-06 23:34:12 +000065struct exynos4_gpio_part3 {
Minkyu Kang008a3512011-01-24 15:22:23 +090066 struct s5p_gpio_bank z;
67};
68
Chander Kashyapfa442bb2012-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 Birje5af4a4f2013-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 Kashyap37bb6d82012-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 Shindefd8ef012012-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 Kashyap37bb6d82012-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 Shindefd8ef012012-07-03 20:02:59 +0000227 struct s5p_gpio_bank res1[0x1];
Chander Kashyap37bb6d82012-02-05 23:01:46 +0000228 struct s5p_gpio_bank v2;
229 struct s5p_gpio_bank v3;
Rajeshwari Shindefd8ef012012-07-03 20:02:59 +0000230 struct s5p_gpio_bank res2[0x1];
Chander Kashyap37bb6d82012-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 Kang008a3512011-01-24 15:22:23 +0900238/* functions */
Łukasz Majewskief5d9eb2011-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 Majewski9f15bc02011-08-22 22:34:58 +0000247
248/* GPIO pins per bank */
249#define GPIO_PER_BANK 8
Przemyslaw Marczak8475c862014-01-22 11:24:10 +0100250#define S5P_GPIO_PART_SHIFT (24)
251#define S5P_GPIO_PART_MASK (0xff)
252#define S5P_GPIO_BANK_SHIFT (8)
253#define S5P_GPIO_BANK_MASK (0xffff)
254#define S5P_GPIO_PIN_MASK (0xff)
Łukasz Majewski9f15bc02011-08-22 22:34:58 +0000255
Przemyslaw Marczak8475c862014-01-22 11:24:10 +0100256#define S5P_GPIO_SET_PART(x) \
257 (((x) & S5P_GPIO_PART_MASK) << S5P_GPIO_PART_SHIFT)
Łukasz Majewski9f15bc02011-08-22 22:34:58 +0000258
Przemyslaw Marczak8475c862014-01-22 11:24:10 +0100259#define S5P_GPIO_GET_PART(x) \
260 (((x) >> S5P_GPIO_PART_SHIFT) & S5P_GPIO_PART_MASK)
Łukasz Majewski9f15bc02011-08-22 22:34:58 +0000261
Przemyslaw Marczak8475c862014-01-22 11:24:10 +0100262#define S5P_GPIO_SET_PIN(x) \
263 ((x) & S5P_GPIO_PIN_MASK)
Chander Kashyap37bb6d82012-02-05 23:01:46 +0000264
Przemyslaw Marczak8475c862014-01-22 11:24:10 +0100265#define EXYNOS4_GPIO_SET_BANK(part, bank) \
266 ((((unsigned)&(((struct exynos4_gpio_part##part *) \
267 EXYNOS4_GPIO_PART##part##_BASE)->bank) \
268 - EXYNOS4_GPIO_PART##part##_BASE) \
269 & S5P_GPIO_BANK_MASK) << S5P_GPIO_BANK_SHIFT)
Chander Kashyapfa442bb2012-12-25 20:13:42 +0000270
Przemyslaw Marczak8475c862014-01-22 11:24:10 +0100271#define EXYNOS4X12_GPIO_SET_BANK(part, bank) \
272 ((((unsigned)&(((struct exynos4x12_gpio_part##part *) \
273 EXYNOS4X12_GPIO_PART##part##_BASE)->bank) \
274 - EXYNOS4X12_GPIO_PART##part##_BASE) \
275 & S5P_GPIO_BANK_MASK) << S5P_GPIO_BANK_SHIFT)
Chander Kashyapfa442bb2012-12-25 20:13:42 +0000276
Przemyslaw Marczak8475c862014-01-22 11:24:10 +0100277#define EXYNOS5_GPIO_SET_BANK(part, bank) \
278 ((((unsigned)&(((struct exynos5420_gpio_part##part *) \
279 EXYNOS5420_GPIO_PART##part##_BASE)->bank) \
280 - EXYNOS5_GPIO_PART##part##_BASE) \
281 & S5P_GPIO_BANK_MASK) << S5P_GPIO_BANK_SHIFT)
Chander Kashyapfa442bb2012-12-25 20:13:42 +0000282
Przemyslaw Marczak8475c862014-01-22 11:24:10 +0100283#define EXYNOS5420_GPIO_SET_BANK(part, bank) \
284 ((((unsigned)&(((struct exynos5420_gpio_part##part *) \
285 EXYNOS5420_GPIO_PART##part##_BASE)->bank) \
286 - EXYNOS5420_GPIO_PART##part##_BASE) \
287 & S5P_GPIO_BANK_MASK) << S5P_GPIO_BANK_SHIFT)
Chander Kashyapfa442bb2012-12-25 20:13:42 +0000288
Przemyslaw Marczak8475c862014-01-22 11:24:10 +0100289#define exynos4_gpio_get(part, bank, pin) \
290 (S5P_GPIO_SET_PART(part) | \
291 EXYNOS4_GPIO_SET_BANK(part, bank) | \
292 S5P_GPIO_SET_PIN(pin))
Chander Kashyapfa442bb2012-12-25 20:13:42 +0000293
Przemyslaw Marczak8475c862014-01-22 11:24:10 +0100294#define exynos4x12_gpio_get(part, bank, pin) \
295 (S5P_GPIO_SET_PART(part) | \
296 EXYNOS4X12_GPIO_SET_BANK(part, bank) | \
297 S5P_GPIO_SET_PIN(pin))
Chander Kashyap37bb6d82012-02-05 23:01:46 +0000298
Przemyslaw Marczak8475c862014-01-22 11:24:10 +0100299#define exynos5420_gpio_get(part, bank, pin) \
300 (S5P_GPIO_SET_PART(part) | \
301 EXYNOS5420_GPIO_SET_BANK(part, bank) | \
302 S5P_GPIO_SET_PIN(pin))
Chander Kashyap37bb6d82012-02-05 23:01:46 +0000303
Przemyslaw Marczak8475c862014-01-22 11:24:10 +0100304#define exynos5_gpio_get(part, bank, pin) \
305 (S5P_GPIO_SET_PART(part) | \
306 EXYNOS5_GPIO_SET_BANK(part, bank) | \
307 S5P_GPIO_SET_PIN(pin))
Chander Kashyap37bb6d82012-02-05 23:01:46 +0000308
Przemyslaw Marczak8475c862014-01-22 11:24:10 +0100309static inline unsigned int s5p_gpio_base(int gpio)
Łukasz Majewski9f15bc02011-08-22 22:34:58 +0000310{
Przemyslaw Marczak8475c862014-01-22 11:24:10 +0100311 unsigned gpio_part = S5P_GPIO_GET_PART(gpio);
312
313 switch (gpio_part) {
314 case 1:
315 return samsung_get_base_gpio_part1();
316 case 2:
317 return samsung_get_base_gpio_part2();
318 case 3:
319 return samsung_get_base_gpio_part3();
320 case 4:
321 return samsung_get_base_gpio_part4();
322 default:
323 return 0;
Chander Kashyap37bb6d82012-02-05 23:01:46 +0000324 }
Łukasz Majewski822593f2012-09-04 21:47:46 +0000325}
Minkyu Kang008a3512011-01-24 15:22:23 +0900326#endif
327
328/* Pin configurations */
329#define GPIO_INPUT 0x0
330#define GPIO_OUTPUT 0x1
331#define GPIO_IRQ 0xf
332#define GPIO_FUNC(x) (x)
333
334/* Pull mode */
335#define GPIO_PULL_NONE 0x0
336#define GPIO_PULL_DOWN 0x1
Chander Kashyap898ddf02011-04-18 00:08:43 +0000337#define GPIO_PULL_UP 0x3
Minkyu Kang008a3512011-01-24 15:22:23 +0900338
339/* Drive Strength level */
340#define GPIO_DRV_1X 0x0
Chander Kashyap898ddf02011-04-18 00:08:43 +0000341#define GPIO_DRV_3X 0x1
342#define GPIO_DRV_2X 0x2
Minkyu Kang008a3512011-01-24 15:22:23 +0900343#define GPIO_DRV_4X 0x3
344#define GPIO_DRV_FAST 0x0
345#define GPIO_DRV_SLOW 0x1
Minkyu Kang008a3512011-01-24 15:22:23 +0900346#endif