1
2
3
4
5
6#include <common.h>
7
8#include <asm/io.h>
9
10#include <asm/arch/chip-features.h>
11#include <asm/arch/hardware.h>
12#include <asm/arch/portmux.h>
13
14
15
16
17
18void portmux_enable_ebi(unsigned int bus_width, unsigned int addr_width,
19 unsigned long flags, unsigned long drive_strength)
20{
21 unsigned long porte_mask = 0;
22
23 if (bus_width > 16)
24 portmux_select_peripheral(PORTMUX_PORT_E, 0xffff,
25 PORTMUX_FUNC_A, PORTMUX_BUSKEEPER);
26 if (addr_width > 23)
27 porte_mask |= (((1 << (addr_width - 23)) - 1) & 7) << 16;
28 if (flags & PORTMUX_EBI_CS(2))
29 porte_mask |= 1 << 25;
30 if (flags & PORTMUX_EBI_CS(4))
31 porte_mask |= 1 << 21;
32 if (flags & PORTMUX_EBI_CS(5))
33 porte_mask |= 1 << 22;
34 if (flags & (PORTMUX_EBI_CF(0) | PORTMUX_EBI_CF(1)))
35 porte_mask |= (1 << 19) | (1 << 20) | (1 << 23);
36
37 portmux_select_peripheral(PORTMUX_PORT_E, porte_mask,
38 PORTMUX_FUNC_A, 0);
39
40 if (flags & PORTMUX_EBI_NWAIT)
41 portmux_select_peripheral(PORTMUX_PORT_E, 1 << 24,
42 PORTMUX_FUNC_A, PORTMUX_PULL_UP);
43}
44
45#ifdef AT32AP700x_CHIP_HAS_MACB
46void portmux_enable_macb0(unsigned long flags, unsigned long drive_strength)
47{
48 unsigned long portc_mask;
49
50 portc_mask = (1 << 3)
51 | (1 << 4)
52 | (1 << 7)
53 | (1 << 8)
54 | (1 << 9)
55 | (1 << 10)
56 | (1 << 13)
57 | (1 << 15)
58 | (1 << 16)
59 | (1 << 17);
60
61 if (flags & PORTMUX_MACB_MII)
62 portc_mask |= (1 << 0)
63 | (1 << 1)
64 | (1 << 2)
65 | (1 << 5)
66 | (1 << 6)
67 | (1 << 11)
68 | (1 << 12)
69 | (1 << 14);
70
71 if (flags & PORTMUX_MACB_SPEED)
72 portc_mask |= (1 << 18);
73
74
75 portmux_select_peripheral(PORTMUX_PORT_C, portc_mask,
76 PORTMUX_FUNC_A, PORTMUX_BUSKEEPER);
77}
78
79void portmux_enable_macb1(unsigned long flags, unsigned long drive_strength)
80{
81 unsigned long portc_mask = 0;
82 unsigned long portd_mask;
83
84 portd_mask = (1 << 13)
85 | (1 << 14)
86 | (1 << 11)
87 | (1 << 12)
88 | (1 << 10)
89 | (1 << 6)
90 | (1 << 5)
91 | (1 << 4)
92 | (1 << 3)
93 | (1 << 2);
94
95 if (flags & PORTMUX_MACB_MII)
96 portc_mask = (1 << 19)
97 | (1 << 23)
98 | (1 << 26)
99 | (1 << 27)
100 | (1 << 28)
101 | (1 << 29)
102 | (1 << 30)
103 | (1 << 24);
104
105 if (flags & PORTMUX_MACB_SPEED)
106 portd_mask |= (1 << 15);
107
108
109 portmux_select_peripheral(PORTMUX_PORT_D, portd_mask,
110 PORTMUX_FUNC_B, PORTMUX_BUSKEEPER);
111 portmux_select_peripheral(PORTMUX_PORT_C, portc_mask,
112 PORTMUX_FUNC_B, PORTMUX_BUSKEEPER);
113}
114#endif
115
116#ifdef AT32AP700x_CHIP_HAS_MMCI
117void portmux_enable_mmci(unsigned int slot, unsigned long flags,
118 unsigned long drive_strength)
119{
120 unsigned long mask;
121 unsigned long portmux_flags = PORTMUX_PULL_UP;
122
123
124 portmux_select_peripheral(PORTMUX_PORT_A, 1 << 10,
125 PORTMUX_FUNC_A, 0);
126
127 if (flags & PORTMUX_MMCI_EXT_PULLUP)
128 portmux_flags = 0;
129
130
131 switch (slot) {
132 case 0:
133 mask = (1 << 11) | (1 << 12);
134 if (flags & PORTMUX_MMCI_4BIT)
135
136 mask |= (1 << 13) | (1 << 14) | (1 << 15);
137 portmux_select_peripheral(PORTMUX_PORT_A, mask,
138 PORTMUX_FUNC_A, portmux_flags);
139 break;
140 case 1:
141 mask = (1 << 6) | (1 << 7);
142 if (flags & PORTMUX_MMCI_4BIT)
143
144 mask |= (1 << 8) | (1 << 9) | (1 << 10);
145 portmux_select_peripheral(PORTMUX_PORT_B, mask,
146 PORTMUX_FUNC_B, portmux_flags);
147 break;
148 }
149}
150#endif
151
152#ifdef AT32AP700x_CHIP_HAS_SPI
153void portmux_enable_spi0(unsigned long cs_mask, unsigned long drive_strength)
154{
155 unsigned long pin_mask;
156
157
158 portmux_select_peripheral(PORTMUX_PORT_A, (1 << 1) | (1 << 2),
159 PORTMUX_FUNC_A, 0);
160
161 portmux_select_peripheral(PORTMUX_PORT_A, 1 << 0,
162 PORTMUX_FUNC_A, PORTMUX_BUSKEEPER);
163
164
165 pin_mask = (cs_mask & 7) << 3;
166 if (cs_mask & (1 << 3))
167 pin_mask |= 1 << 20;
168
169 portmux_select_gpio(PORTMUX_PORT_A, pin_mask,
170 PORTMUX_DIR_OUTPUT | PORTMUX_INIT_HIGH);
171}
172
173void portmux_enable_spi1(unsigned long cs_mask, unsigned long drive_strength)
174{
175
176 portmux_select_peripheral(PORTMUX_PORT_B, (1 << 1) | (1 << 5),
177 PORTMUX_FUNC_B, 0);
178
179 portmux_select_peripheral(PORTMUX_PORT_B, 1 << 0,
180 PORTMUX_FUNC_B, PORTMUX_BUSKEEPER);
181
182
183 portmux_select_gpio(PORTMUX_PORT_B, (cs_mask & 7) << 2,
184 PORTMUX_DIR_OUTPUT | PORTMUX_INIT_HIGH);
185 portmux_select_gpio(PORTMUX_PORT_A, (cs_mask & 8) << (27 - 3),
186 PORTMUX_DIR_OUTPUT | PORTMUX_INIT_HIGH);
187}
188#endif
189
190#ifdef AT32AP700x_CHIP_HAS_LCDC
191void portmux_enable_lcdc(int pin_config)
192{
193 unsigned long portc_mask = 0;
194 unsigned long portd_mask = 0;
195 unsigned long porte_mask = 0;
196
197 switch (pin_config) {
198 case 0:
199 portc_mask = (1 << 19)
200 | (1 << 20)
201 | (1 << 21)
202 | (1 << 22)
203 | (1 << 23)
204 | (1 << 24)
205 | (1 << 25)
206 | (1 << 26)
207 | (1 << 27)
208 | (1 << 28)
209 | (1 << 29)
210 | (1 << 30)
211 | (1 << 31);
212
213 portd_mask = (1 << 0)
214 | (1 << 1)
215 | (1 << 2)
216 | (1 << 3)
217 | (1 << 4)
218 | (1 << 5)
219 | (1 << 6)
220 | (1 << 7)
221 | (1 << 8)
222 | (1 << 9)
223 | (1 << 10)
224 | (1 << 11)
225 | (1 << 12)
226 | (1 << 13)
227 | (1 << 14)
228 | (1 << 15)
229 | (1 << 16)
230 | (1 << 17);
231 break;
232
233 case 1:
234 portc_mask = (1 << 20)
235 | (1 << 21)
236 | (1 << 22)
237 | (1 << 25)
238 | (1 << 31);
239
240 portd_mask = (1 << 0)
241 | (1 << 1)
242 | (1 << 7)
243 | (1 << 8)
244 | (1 << 9)
245 | (1 << 16)
246 | (1 << 17);
247
248 porte_mask = (1 << 0)
249 | (1 << 1)
250 | (1 << 2)
251 | (1 << 3)
252 | (1 << 4)
253 | (1 << 5)
254 | (1 << 6)
255 | (1 << 7)
256 | (1 << 8)
257 | (1 << 9)
258 | (1 << 10)
259 | (1 << 11)
260 | (1 << 12)
261 | (1 << 13)
262 | (1 << 14)
263 | (1 << 15)
264 | (1 << 16)
265 | (1 << 17)
266 | (1 << 18);
267 break;
268 }
269
270
271 portmux_select_peripheral(PORTMUX_PORT_C, portc_mask,
272 PORTMUX_FUNC_A, PORTMUX_BUSKEEPER);
273 portmux_select_peripheral(PORTMUX_PORT_D, portd_mask,
274 PORTMUX_FUNC_A, PORTMUX_BUSKEEPER);
275 portmux_select_peripheral(PORTMUX_PORT_E, porte_mask,
276 PORTMUX_FUNC_B, PORTMUX_BUSKEEPER);
277}
278#endif
279