blob: ca0c964f6ff5fc9f76bf30061258f1db5b47c365 [file] [log] [blame]
developer404e08b2020-09-18 09:32:31 +08001/*
2 * Copyright (c) 2020, MediaTek Inc. All rights reserved.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#ifndef MT_GPIO_H
8#define MT_GPIO_H
9
10#include <stdbool.h>
11#include <stdint.h>
12
13#include <plat/common/common_def.h>
14
15/* Error Code No. */
16#define RSUCCESS 0
17#define ERACCESS 1
18#define ERINVAL 2
19#define ERWRAPPER 3
20#define MAX_GPIO_PIN MT_GPIO_BASE_MAX
21
22/* Enumeration for GPIO pin */
23typedef enum GPIO_PIN {
24 GPIO_UNSUPPORTED = -1,
25
26 GPIO0, GPIO1, GPIO2, GPIO3, GPIO4, GPIO5, GPIO6, GPIO7,
27 GPIO8, GPIO9, GPIO10, GPIO11, GPIO12, GPIO13, GPIO14, GPIO15,
28 GPIO16, GPIO17, GPIO18, GPIO19, GPIO20, GPIO21, GPIO22, GPIO23,
29 GPIO24, GPIO25, GPIO26, GPIO27, GPIO28, GPIO29, GPIO30, GPIO31,
30 GPIO32, GPIO33, GPIO34, GPIO35, GPIO36, GPIO37, GPIO38, GPIO39,
31 GPIO40, GPIO41, GPIO42, GPIO43, GPIO44, GPIO45, GPIO46, GPIO47,
32 GPIO48, GPIO49, GPIO50, GPIO51, GPIO52, GPIO53, GPIO54, GPIO55,
33 GPIO56, GPIO57, GPIO58, GPIO59, GPIO60, GPIO61, GPIO62, GPIO63,
34 GPIO64, GPIO65, GPIO66, GPIO67, GPIO68, GPIO69, GPIO70, GPIO71,
35 GPIO72, GPIO73, GPIO74, GPIO75, GPIO76, GPIO77, GPIO78, GPIO79,
36 GPIO80, GPIO81, GPIO82, GPIO83, GPIO84, GPIO85, GPIO86, GPIO87,
37 GPIO88, GPIO89, GPIO90, GPIO91, GPIO92, GPIO93, GPIO94, GPIO95,
38 GPIO96, GPIO97, GPIO98, GPIO99, GPIO100, GPIO101, GPIO102, GPIO103,
39 GPIO104, GPIO105, GPIO106, GPIO107, GPIO108, GPIO109, GPIO110, GPIO111,
40 GPIO112, GPIO113, GPIO114, GPIO115, GPIO116, GPIO117, GPIO118, GPIO119,
41 GPIO120, GPIO121, GPIO122, GPIO123, GPIO124, GPIO125, GPIO126, GPIO127,
42 GPIO128, GPIO129, GPIO130, GPIO131, GPIO132, GPIO133, GPIO134, GPIO135,
43 GPIO136, GPIO137, GPIO138, GPIO139, GPIO140, GPIO141, GPIO142, GPIO143,
44 GPIO144, GPIO145, GPIO146, GPIO147, GPIO148, GPIO149, GPIO150, GPIO151,
45 GPIO152, GPIO153, GPIO154, GPIO155, GPIO156, GPIO157, GPIO158, GPIO159,
46 GPIO160, GPIO161, GPIO162, GPIO163, GPIO164, GPIO165, GPIO166, GPIO167,
47 GPIO168, GPIO169, GPIO170, GPIO171, GPIO172, GPIO173, GPIO174, GPIO175,
48 GPIO176, GPIO177, GPIO178, GPIO179, GPIO180, GPIO181, GPIO182, GPIO183,
49 GPIO184, GPIO185, GPIO186, GPIO187, GPIO188, GPIO189, GPIO190, GPIO191,
50 GPIO192, GPIO193, GPIO194, GPIO195, GPIO196, GPIO197, GPIO198, GPIO199,
51 GPIO200, GPIO201, GPIO202, GPIO203, GPIO204, GPIO205, GPIO206, GPIO207,
52 GPIO208, GPIO209, GPIO210, GPIO211, GPIO212, GPIO213, GPIO214, GPIO215,
53 GPIO216, GPIO217, GPIO218, GPIO219,
54 MT_GPIO_BASE_MAX
55} GPIO_PIN;
56
57/* GPIO MODE CONTROL VALUE*/
58typedef enum {
59 GPIO_MODE_UNSUPPORTED = -1,
60 GPIO_MODE_GPIO = 0,
61 GPIO_MODE_00 = 0,
62 GPIO_MODE_01,
63 GPIO_MODE_02,
64 GPIO_MODE_03,
65 GPIO_MODE_04,
66 GPIO_MODE_05,
67 GPIO_MODE_06,
68 GPIO_MODE_07,
69
70 GPIO_MODE_MAX,
71 GPIO_MODE_DEFAULT = GPIO_MODE_00,
72} GPIO_MODE;
73
74/* GPIO DIRECTION */
75typedef enum {
76 MT_GPIO_DIR_UNSUPPORTED = -1,
77 MT_GPIO_DIR_OUT = 0,
78 MT_GPIO_DIR_IN = 1,
79 MT_GPIO_DIR_MAX,
80 MT_GPIO_DIR_DEFAULT = MT_GPIO_DIR_IN,
81} GPIO_DIR;
82
83/* GPIO PULL ENABLE*/
84typedef enum {
85 MT_GPIO_PULL_EN_UNSUPPORTED = -1,
86 MT_GPIO_PULL_DISABLE = 0,
87 MT_GPIO_PULL_ENABLE = 1,
88 MT_GPIO_PULL_ENABLE_R0 = 2,
89 MT_GPIO_PULL_ENABLE_R1 = 3,
90 MT_GPIO_PULL_ENABLE_R0R1 = 4,
91
92 MT_GPIO_PULL_EN_MAX,
93 MT_GPIO_PULL_EN_DEFAULT = MT_GPIO_PULL_ENABLE,
94} GPIO_PULL_EN;
95
96/* GPIO PULL-UP/PULL-DOWN*/
97typedef enum {
98 MT_GPIO_PULL_UNSUPPORTED = -1,
99 MT_GPIO_PULL_NONE = 0,
100 MT_GPIO_PULL_UP = 1,
101 MT_GPIO_PULL_DOWN = 2,
102 MT_GPIO_PULL_MAX,
103 MT_GPIO_PULL_DEFAULT = MT_GPIO_PULL_DOWN
104} GPIO_PULL;
105
106/* GPIO OUTPUT */
107typedef enum {
108 MT_GPIO_OUT_UNSUPPORTED = -1,
109 MT_GPIO_OUT_ZERO = 0,
110 MT_GPIO_OUT_ONE = 1,
111
112 MT_GPIO_OUT_MAX,
113 MT_GPIO_OUT_DEFAULT = MT_GPIO_OUT_ZERO,
114 MT_GPIO_DATA_OUT_DEFAULT = MT_GPIO_OUT_ZERO, /*compatible with DCT*/
115} GPIO_OUT;
116
117/* GPIO INPUT */
118typedef enum {
119 MT_GPIO_IN_UNSUPPORTED = -1,
120 MT_GPIO_IN_ZERO = 0,
121 MT_GPIO_IN_ONE = 1,
122
123 MT_GPIO_IN_MAX,
124} GPIO_IN;
125
126typedef struct {
127 uint32_t val;
128 uint32_t set;
129 uint32_t rst;
130 uint32_t _align1;
131} VAL_REGS;
132
133typedef struct {
134 VAL_REGS dir[7];
135 uint8_t rsv00[144];
136 VAL_REGS dout[7];
137 uint8_t rsv01[144];
138 VAL_REGS din[7];
139 uint8_t rsv02[144];
140 VAL_REGS mode[28];
141} GPIO_REGS;
142
143
144#define PIN(_id, _flag, _bit, _base, _offset) { \
145 .id = _id, \
146 .flag = _flag, \
147 .bit = _bit, \
148 .base = _base, \
149 .offset = _offset, \
150 }
151
152struct mt_pin_info {
153 uint8_t id;
154 uint8_t flag;
155 uint8_t bit;
156 uint16_t base;
157 uint16_t offset;
158};
159
160static const struct mt_pin_info mt8192_pin_infos[] = {
161 PIN(0, 0, 9, 0x23, 0xb0),
162 PIN(1, 0, 10, 0x23, 0xb0),
163 PIN(2, 0, 11, 0x23, 0xb0),
164 PIN(3, 0, 12, 0x23, 0xb0),
165 PIN(4, 0, 13, 0x23, 0xb0),
166 PIN(5, 0, 14, 0x23, 0xb0),
167 PIN(6, 0, 15, 0x23, 0xb0),
168 PIN(7, 0, 16, 0x23, 0xb0),
169 PIN(8, 0, 17, 0x23, 0xb0),
170 PIN(9, 0, 18, 0x23, 0xb0),
171 PIN(10, 1, 0, 0x15, 0x20),
172 PIN(11, 1, 1, 0x15, 0x20),
173 PIN(12, 1, 2, 0x15, 0x20),
174 PIN(13, 1, 3, 0x15, 0x20),
175 PIN(14, 1, 4, 0x15, 0x20),
176 PIN(15, 1, 5, 0x15, 0x20),
177 PIN(16, 0, 2, 0x17, 0x50),
178 PIN(17, 0, 3, 0x17, 0x50),
179 PIN(18, 0, 21, 0x36, 0xa0),
180 PIN(19, 0, 22, 0x36, 0xa0),
181 PIN(20, 0, 23, 0x36, 0xa0),
182 PIN(21, 0, 24, 0x36, 0xa0),
183 PIN(22, 0, 3, 0x21, 0x90),
184 PIN(23, 0, 4, 0x21, 0x90),
185 PIN(24, 0, 5, 0x21, 0x90),
186 PIN(25, 0, 6, 0x21, 0x90),
187 PIN(26, 0, 5, 0x22, 0x80),
188 PIN(27, 0, 6, 0x22, 0x80),
189 PIN(28, 0, 7, 0x22, 0x80),
190 PIN(29, 0, 8, 0x22, 0x80),
191 PIN(30, 0, 9, 0x22, 0x80),
192 PIN(31, 0, 27, 0x22, 0x70),
193 PIN(32, 0, 24, 0x22, 0x70),
194 PIN(33, 0, 26, 0x22, 0x70),
195 PIN(34, 0, 23, 0x22, 0x70),
196 PIN(35, 0, 25, 0x22, 0x70),
197 PIN(36, 0, 20, 0x21, 0x90),
198 PIN(37, 0, 21, 0x21, 0x90),
199 PIN(38, 0, 22, 0x21, 0x90),
200 PIN(39, 0, 23, 0x21, 0x90),
201 PIN(40, 0, 0, 0x17, 0x50),
202 PIN(41, 0, 1, 0x17, 0x50),
203 PIN(42, 0, 4, 0x17, 0x50),
204 PIN(43, 0, 25, 0x36, 0xa0),
205 PIN(44, 0, 26, 0x36, 0xa0),
206 PIN(45, 1, 9, 0x20, 0x60),
207 PIN(46, 1, 11, 0x20, 0x60),
208 PIN(47, 1, 10, 0x20, 0x60),
209 PIN(48, 1, 7, 0x20, 0x60),
210 PIN(49, 1, 8, 0x20, 0x60),
211 PIN(50, 1, 6, 0x20, 0x60),
212 PIN(51, 1, 0, 0x20, 0x60),
213 PIN(52, 1, 1, 0x20, 0x60),
214 PIN(53, 1, 5, 0x20, 0x60),
215 PIN(54, 1, 2, 0x20, 0x60),
216 PIN(55, 1, 4, 0x20, 0x60),
217 PIN(56, 1, 3, 0x20, 0x60),
218 PIN(57, 0, 1, 0x22, 0x80),
219 PIN(58, 0, 2, 0x22, 0x80),
220 PIN(59, 0, 3, 0x22, 0x80),
221 PIN(60, 0, 4, 0x22, 0x80),
222 PIN(61, 0, 28, 0x22, 0x70),
223 PIN(62, 0, 22, 0x22, 0x70),
224 PIN(63, 0, 0, 0x22, 0x70),
225 PIN(64, 0, 1, 0x22, 0x70),
226 PIN(65, 0, 12, 0x22, 0x70),
227 PIN(66, 0, 15, 0x22, 0x70),
228 PIN(67, 0, 16, 0x22, 0x70),
229 PIN(68, 0, 17, 0x22, 0x70),
230 PIN(69, 0, 18, 0x22, 0x70),
231 PIN(70, 0, 19, 0x22, 0x70),
232 PIN(71, 0, 20, 0x22, 0x70),
233 PIN(72, 0, 21, 0x22, 0x70),
234 PIN(73, 0, 2, 0x22, 0x70),
235 PIN(74, 0, 3, 0x22, 0x70),
236 PIN(75, 0, 4, 0x22, 0x70),
237 PIN(76, 0, 5, 0x22, 0x70),
238 PIN(77, 0, 6, 0x22, 0x70),
239 PIN(78, 0, 7, 0x22, 0x70),
240 PIN(79, 0, 8, 0x22, 0x70),
241 PIN(80, 0, 9, 0x22, 0x70),
242 PIN(81, 0, 10, 0x22, 0x70),
243 PIN(82, 0, 11, 0x22, 0x70),
244 PIN(83, 0, 13, 0x22, 0x70),
245 PIN(84, 0, 14, 0x22, 0x70),
246 PIN(85, 0, 31, 0x22, 0x70),
247 PIN(86, 0, 0, 0x22, 0x80),
248 PIN(87, 0, 29, 0x22, 0x70),
249 PIN(88, 0, 30, 0x22, 0x70),
250 PIN(89, 0, 24, 0x21, 0x90),
251 PIN(90, 0, 25, 0x21, 0x90),
252 PIN(91, 0, 0, 0x21, 0x90),
253 PIN(92, 0, 2, 0x21, 0xa0),
254 PIN(93, 0, 4, 0x21, 0xa0),
255 PIN(94, 0, 3, 0x21, 0xa0),
256 PIN(95, 0, 5, 0x21, 0xa0),
257 PIN(96, 0, 31, 0x21, 0x90),
258 PIN(97, 0, 26, 0x21, 0x90),
259 PIN(98, 0, 0, 0x21, 0xa0),
260 PIN(99, 0, 27, 0x21, 0x90),
261 PIN(100, 0, 28, 0x21, 0x90),
262 PIN(101, 0, 29, 0x21, 0x90),
263 PIN(102, 0, 30, 0x21, 0x90),
264 PIN(103, 0, 18, 0x21, 0x90),
265 PIN(104, 0, 17, 0x21, 0x90),
266 PIN(105, 0, 19, 0x21, 0x90),
267 PIN(106, 0, 16, 0x21, 0x90),
268 PIN(107, 0, 1, 0x21, 0x90),
269 PIN(108, 0, 2, 0x21, 0x90),
270 PIN(109, 0, 10, 0x21, 0x90),
271 PIN(110, 0, 7, 0x21, 0x90),
272 PIN(111, 0, 9, 0x21, 0x90),
273 PIN(112, 0, 11, 0x21, 0x90),
274 PIN(113, 0, 8, 0x21, 0x90),
275 PIN(114, 0, 14, 0x21, 0x90),
276 PIN(115, 0, 13, 0x21, 0x90),
277 PIN(116, 0, 15, 0x21, 0x90),
278 PIN(117, 0, 12, 0x21, 0x90),
279 PIN(118, 0, 23, 0x23, 0xb0),
280 PIN(119, 0, 29, 0x23, 0xb0),
281 PIN(120, 0, 28, 0x23, 0xb0),
282 PIN(121, 0, 2, 0x23, 0xc0),
283 PIN(122, 0, 27, 0x23, 0xb0),
284 PIN(123, 0, 1, 0x23, 0xc0),
285 PIN(124, 0, 26, 0x23, 0xb0),
286 PIN(125, 0, 0, 0x23, 0xc0),
287 PIN(126, 0, 19, 0x23, 0xb0),
288 PIN(127, 0, 20, 0x23, 0xb0),
289 PIN(128, 0, 21, 0x23, 0xb0),
290 PIN(129, 0, 22, 0x23, 0xb0),
291 PIN(130, 0, 6, 0x23, 0xb0),
292 PIN(131, 0, 7, 0x23, 0xb0),
293 PIN(132, 0, 8, 0x23, 0xb0),
294 PIN(133, 0, 3, 0x23, 0xb0),
295 PIN(134, 0, 4, 0x23, 0xb0),
296 PIN(135, 0, 5, 0x23, 0xb0),
297 PIN(136, 0, 0, 0x23, 0xb0),
298 PIN(137, 0, 1, 0x23, 0xb0),
299 PIN(138, 0, 2, 0x23, 0xb0),
300 PIN(139, 0, 25, 0x23, 0xb0),
301 PIN(140, 0, 31, 0x23, 0xb0),
302 PIN(141, 0, 24, 0x23, 0xb0),
303 PIN(142, 0, 30, 0x23, 0xb0),
304 PIN(143, 0, 6, 0x20, 0x70),
305 PIN(144, 0, 7, 0x20, 0x70),
306 PIN(145, 0, 8, 0x20, 0x70),
307 PIN(146, 0, 3, 0x20, 0x70),
308 PIN(147, 0, 4, 0x20, 0x70),
309 PIN(148, 0, 5, 0x20, 0x70),
310 PIN(149, 0, 0, 0x20, 0x70),
311 PIN(150, 0, 1, 0x20, 0x70),
312 PIN(151, 0, 2, 0x20, 0x70),
313 PIN(152, 1, 3, 0x36, 0x90),
314 PIN(153, 1, 2, 0x36, 0x90),
315 PIN(154, 1, 0, 0x36, 0x906),
316 PIN(155, 1, 1, 0x36, 0x90),
317 PIN(156, 0, 29, 0x36, 0xa0),
318 PIN(157, 0, 30, 0x36, 0xa0),
319 PIN(158, 0, 31, 0x36, 0xa0),
320 PIN(159, 0, 0, 0x36, 0xb0),
321 PIN(160, 0, 27, 0x36, 0xa04),
322 PIN(161, 0, 28, 0x36, 0xa0),
323 PIN(162, 0, 0, 0x36, 0xa0),
324 PIN(163, 0, 1, 0x36, 0xa0),
325 PIN(164, 0, 2, 0x36, 0xa0),
326 PIN(165, 0, 3, 0x36, 0xa0),
327 PIN(166, 0, 4, 0x36, 0xa0),
328 PIN(167, 0, 5, 0x36, 0xa0),
329 PIN(168, 0, 6, 0x36, 0xa0),
330 PIN(169, 0, 7, 0x36, 0xa0),
331 PIN(170, 0, 8, 0x36, 0xa0),
332 PIN(171, 0, 9, 0x36, 0xa0),
333 PIN(172, 0, 13, 0x36, 0xa0),
334 PIN(173, 0, 14, 0x36, 0xa0),
335 PIN(174, 0, 12, 0x36, 0xa0),
336 PIN(175, 0, 15, 0x36, 0xa0),
337 PIN(176, 0, 10, 0x36, 0xa0),
338 PIN(177, 0, 11, 0x36, 0xa0),
339 PIN(178, 0, 16, 0x36, 0xa0),
340 PIN(179, 0, 17, 0x36, 0xa0),
341 PIN(180, 0, 18, 0x36, 0xa0),
342 PIN(181, 0, 19, 0x36, 0xa0),
343 PIN(182, 0, 20, 0x36, 0xa0),
344 PIN(183, 1, 1, 0x18, 0x30),
345 PIN(184, 1, 2, 0x18, 0x30),
346 PIN(185, 1, 4, 0x18, 0x30),
347 PIN(186, 1, 6, 0x18, 0x30),
348 PIN(187, 1, 8, 0x18, 0x30),
349 PIN(188, 1, 3, 0x18, 0x30),
350 PIN(189, 1, 7, 0x18, 0x30),
351 PIN(190, 1, 9, 0x18, 0x30),
352 PIN(191, 1, 10, 0x18, 0x30),
353 PIN(192, 1, 0, 0x18, 0x30),
354 PIN(193, 1, 5, 0x18, 0x30),
355 PIN(194, 1, 11, 0x18, 0x30),
356 PIN(195, 0, 16, 0x14, 0x50),
357 PIN(196, 0, 6, 0x14, 0x50),
358 PIN(197, 0, 8, 0x14, 0x50),
359 PIN(198, 0, 7, 0x14, 0x50),
360 PIN(199, 0, 3, 0x14, 0x50),
361 PIN(200, 0, 6, 0x17, 0x50),
362 PIN(201, 0, 8, 0x17, 0x50),
363 PIN(202, 0, 15, 0x14, 0x50),
364 PIN(203, 0, 17, 0x14, 0x50),
365 PIN(204, 0, 5, 0x17, 0x50),
366 PIN(205, 0, 7, 0x17, 0x50),
367 PIN(206, 0, 18, 0x14, 0x50),
368 PIN(207, 0, 19, 0x14, 0x50),
369 PIN(208, 0, 20, 0x14, 0x50),
370 PIN(209, 0, 12, 0x14, 0x50),
371 PIN(210, 0, 11, 0x14, 0x50),
372 PIN(211, 0, 13, 0x14, 0x50),
373 PIN(212, 0, 10, 0x14, 0x50),
374 PIN(213, 0, 14, 0x14, 0x50),
375 PIN(214, 0, 0, 0x14, 0x50),
376 PIN(215, 0, 9, 0x14, 0x50),
377 PIN(216, 0, 4, 0x14, 0x50),
378 PIN(217, 0, 5, 0x14, 0x50),
379 PIN(218, 0, 1, 0x14, 0x50),
380 PIN(219, 0, 2, 0x14, 0x50),
381};
382
383void plat_mt8192_gpio_init(void);
384#endif /* MT_GPIO_H */