1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22#include <common.h>
23#include "vct.h"
24
25typedef union _TOP_PINMUX_t
26{
27 u32 reg;
28 struct {
29 u32 res : 24;
30 u32 drive : 2;
31 u32 slew : 1;
32 u32 strig : 1;
33 u32 pu_pd : 2;
34 u32 funsel : 2;
35 } Bits;
36} TOP_PINMUX_t;
37
38#if defined(CONFIG_VCT_PREMIUM) || defined(CONFIG_VCT_PLATINUM)
39
40static TOP_PINMUX_t top_read_pin(int pin)
41{
42 TOP_PINMUX_t reg;
43
44 switch (pin) {
45 case 2:
46 case 3:
47 case 6:
48 case 9:
49 reg.reg = 0xdeadbeef;
50 break;
51 case 4:
52 reg.reg = reg_read(FWSRAM_TOP_SCL_CFG(FWSRAM_BASE));
53 break;
54 case 5:
55 reg.reg = reg_read(FWSRAM_TOP_SDA_CFG(FWSRAM_BASE));
56 break;
57 case 7:
58 reg.reg = reg_read(FWSRAM_TOP_TDO_CFG(FWSRAM_BASE));
59 break;
60 case 8:
61 reg.reg = reg_read(FWSRAM_TOP_GPIO2_0_CFG(FWSRAM_BASE));
62 break;
63 case 10:
64 case 11:
65 case 12:
66 case 13:
67 case 14:
68 case 15:
69 case 16:
70 reg.reg = reg_read(FWSRAM_BASE + FWSRAM_TOP_GPIO2_1_CFG_OFFS +
71 ((pin - 10) * 4));
72 break;
73 default:
74 reg.reg = reg_read(TOP_BASE + (pin * 4));
75 break;
76 }
77
78 return reg;
79}
80
81static void top_write_pin(int pin, TOP_PINMUX_t reg)
82{
83
84 switch (pin) {
85 case 4:
86 reg_write(FWSRAM_TOP_SCL_CFG(FWSRAM_BASE), reg.reg);
87 break;
88 case 5:
89 reg_write(FWSRAM_TOP_SDA_CFG(FWSRAM_BASE), reg.reg);
90 break;
91 case 7:
92 reg_write(FWSRAM_TOP_TDO_CFG(FWSRAM_BASE), reg.reg);
93 break;
94 case 8:
95 reg_write(FWSRAM_TOP_GPIO2_0_CFG(FWSRAM_BASE), reg.reg);
96 break;
97 case 10:
98 case 11:
99 case 12:
100 case 13:
101 case 14:
102 case 15:
103 case 16:
104 reg_write(FWSRAM_BASE + FWSRAM_TOP_GPIO2_1_CFG_OFFS +
105 ((pin - 10) * 4), reg.reg);
106 break;
107 default:
108 reg_write(TOP_BASE + (pin * 4), reg.reg);
109 break;
110 }
111}
112
113int top_set_pin(int pin, int func)
114{
115 TOP_PINMUX_t reg;
116
117
118 if ((pin < 0) || (pin > 170) || (func < 0) || (func > 3))
119 return -1;
120
121
122 if ((pin == 2) || (pin == 3) || (pin == 6) || (pin == 9))
123 return -1;
124
125 reg = top_read_pin(pin);
126 reg.Bits.funsel = func;
127 top_write_pin(pin, reg);
128
129 return 0;
130}
131
132#endif
133
134#if defined(CONFIG_VCT_PLATINUMAVC)
135
136int top_set_pin(int pin, int func)
137{
138 TOP_PINMUX_t reg;
139
140
141 if ((pin < 0) || (pin > 158))
142 return -1;
143
144 reg.reg = reg_read(TOP_BASE + (pin * 4));
145 reg.Bits.funsel = func;
146 reg_write(TOP_BASE + (pin * 4), reg.reg);
147
148 return 0;
149}
150
151#endif
152
153void vct_pin_mux_initialize(void)
154{
155#if defined(CONFIG_VCT_PREMIUM) || defined(CONFIG_VCT_PLATINUM)
156 top_set_pin(34, 01);
157 top_set_pin(33, 01);
158 top_set_pin(32, 01);
159 top_set_pin(100, 02);
160 top_set_pin(101, 02);
161 top_set_pin(102, 02);
162 top_set_pin(103, 02);
163 top_set_pin(104, 02);
164 top_set_pin(35, 01);
165 top_set_pin(36, 01);
166 top_set_pin(37, 01);
167 top_set_pin(38, 01);
168 top_set_pin(39, 01);
169 top_set_pin(40, 01);
170 top_set_pin(41, 01);
171 top_set_pin(42, 01);
172 top_set_pin(43, 01);
173 top_set_pin(44, 01);
174 top_set_pin(45, 01);
175 top_set_pin(46, 01);
176 top_set_pin(47, 01);
177 top_set_pin(48, 01);
178 top_set_pin(49, 01);
179 top_set_pin(50, 01);
180 top_set_pin(51, 01);
181 top_set_pin(52, 01);
182 top_set_pin(53, 01);
183 top_set_pin(54, 01);
184 top_set_pin(55, 01);
185 top_set_pin(56, 01);
186 top_set_pin(57, 01);
187 top_set_pin(58, 01);
188 top_set_pin(59, 01);
189 top_set_pin(60, 01);
190 top_set_pin(61, 01);
191 top_set_pin(62, 01);
192 top_set_pin(63, 01);
193 top_set_pin(64, 01);
194 top_set_pin(65, 01);
195 top_set_pin(66, 01);
196 top_set_pin(67, 01);
197 top_set_pin(68, 01);
198 top_set_pin(69, 01);
199 top_set_pin(70, 01);
200 top_set_pin(71, 01);
201 top_set_pin(72, 01);
202 top_set_pin(73, 01);
203 top_set_pin(95, 02);
204 top_set_pin(112, 02);
205 top_set_pin(111, 02);
206 top_set_pin(107, 02);
207 top_set_pin(108, 02);
208 top_set_pin(30, 01);
209 top_set_pin(31, 01);
210 top_set_pin(105, 02);
211 top_set_pin(106, 02);
212 top_set_pin(109, 02);
213 top_set_pin(110, 02);
214#endif
215
216#if defined(CONFIG_VCT_PLATINUMAVC)
217 top_set_pin(19, 01);
218 top_set_pin(18, 01);
219 top_set_pin(17, 01);
220 top_set_pin(92, 02);
221 top_set_pin(93, 02);
222 top_set_pin(95, 02);
223 top_set_pin(96, 02);
224 top_set_pin(20, 01);
225 top_set_pin(21, 01);
226 top_set_pin(22, 01);
227 top_set_pin(23, 01);
228 top_set_pin(24, 01);
229 top_set_pin(25, 01);
230 top_set_pin(26, 01);
231 top_set_pin(27, 01);
232 top_set_pin(28, 01);
233 top_set_pin(29, 01);
234 top_set_pin(30, 01);
235 top_set_pin(31, 01);
236 top_set_pin(32, 01);
237 top_set_pin(33, 01);
238 top_set_pin(34, 01);
239 top_set_pin(35, 01);
240 top_set_pin(36, 01);
241 top_set_pin(37, 01);
242 top_set_pin(38, 01);
243 top_set_pin(39, 01);
244 top_set_pin(40, 01);
245 top_set_pin(41, 01);
246 top_set_pin(42, 01);
247 top_set_pin(43, 01);
248 top_set_pin(44, 01);
249 top_set_pin(45, 01);
250 top_set_pin(46, 01);
251 top_set_pin(47, 01);
252 top_set_pin(48, 01);
253 top_set_pin(49, 01);
254 top_set_pin(50, 01);
255 top_set_pin(51, 01);
256 top_set_pin(52, 01);
257 top_set_pin(53, 01);
258 top_set_pin(54, 01);
259 top_set_pin(55, 01);
260 top_set_pin(56, 01);
261 top_set_pin(57, 01);
262 top_set_pin(58, 01);
263 top_set_pin(87, 02);
264 top_set_pin(106, 02);
265 top_set_pin(105, 02);
266 top_set_pin(101, 02);
267 top_set_pin(102, 02);
268 top_set_pin(15, 01);
269 top_set_pin(16, 01);
270 top_set_pin(99, 02);
271 top_set_pin(100, 02);
272 top_set_pin(103, 02);
273 top_set_pin(104, 02);
274#endif
275
276
277 top_set_pin(0, 2);
278 top_set_pin(1, 2);
279
280
281#if defined(CONFIG_VCT_PREMIUM) || defined(CONFIG_VCT_PLATINUM)
282 top_set_pin(141, 1);
283 top_set_pin(143, 1);
284#endif
285#if defined(CONFIG_VCT_PLATINUMAVC)
286 top_set_pin(107, 1);
287 top_set_pin(109, 1);
288#endif
289}
290