]>
Commit | Line | Data |
---|---|---|
fa1df308 | 1 | /* |
86b116b1 BS |
2 | * (C) Copyright 2007 Markus Kappeler <markus.kappeler@objectxp.com> |
3 | * | |
be5d72d1 | 4 | * Adapted for U-Boot 1.2 by Piotr Kruszynski <ppk@semihalf.com> |
fa1df308 | 5 | * |
1a459660 | 6 | * SPDX-License-Identifier: GPL-2.0+ |
fa1df308 BS |
7 | */ |
8 | ||
9 | #include <common.h> | |
10 | #include <command.h> | |
11 | #include <i2c.h> | |
12 | #include <usb.h> | |
13 | ||
6e7b7b6e | 14 | #ifdef CONFIG_CMD_BSP |
fa1df308 | 15 | |
54841ab5 | 16 | static int do_i2c_test(char * const argv[]) |
fa1df308 BS |
17 | { |
18 | unsigned char temp, temp1; | |
19 | ||
20 | printf("Starting I2C Test\n" | |
21 | "Please set Jumper:\nI2C SDA 2-3\nI2C SCL 2-3\n\n" | |
22 | "Please press any key to start\n\n"); | |
23 | getc(); | |
24 | ||
25 | temp = 0xf0; /* set io 0-4 as output */ | |
6d0f6bcf | 26 | i2c_write(CONFIG_SYS_I2C_IO, 3, 1, (uchar *)&temp, 1); |
fa1df308 BS |
27 | |
28 | printf("Press I2C4-7. LED I2C0-3 should have the same state\n\n" | |
29 | "Press any key to stop\n\n"); | |
30 | ||
31 | while (!tstc()) { | |
6d0f6bcf | 32 | i2c_read(CONFIG_SYS_I2C_IO, 0, 1, (uchar *)&temp, 1); |
fa1df308 BS |
33 | temp1 = (temp >> 4) & 0x03; |
34 | temp1 |= (temp >> 3) & 0x08; /* S302 -> LED303 */ | |
35 | temp1 |= (temp >> 5) & 0x04; /* S303 -> LED302 */ | |
36 | temp = temp1; | |
6d0f6bcf | 37 | i2c_write(CONFIG_SYS_I2C_IO, 1, 1, (uchar *)&temp, 1); |
fa1df308 BS |
38 | } |
39 | getc(); | |
40 | ||
41 | return 0; | |
42 | } | |
43 | ||
54841ab5 | 44 | static int do_usb_test(char * const argv[]) |
fa1df308 BS |
45 | { |
46 | int i; | |
47 | static int usb_stor_curr_dev = -1; /* current device */ | |
48 | ||
49 | printf("Starting USB Test\n" | |
50 | "Please insert USB Memmory Stick\n\n" | |
51 | "Please press any key to start\n\n"); | |
52 | getc(); | |
53 | ||
54 | usb_stop(); | |
55 | printf("(Re)start USB...\n"); | |
56 | i = usb_init(); | |
57 | #ifdef CONFIG_USB_STORAGE | |
58 | /* try to recognize storage devices immediately */ | |
59 | if (i >= 0) | |
60 | usb_stor_curr_dev = usb_stor_scan(1); | |
61 | #endif /* CONFIG_USB_STORAGE */ | |
62 | if (usb_stor_curr_dev >= 0) | |
63 | printf("Found USB Storage Dev continue with Test...\n"); | |
64 | else { | |
65 | printf("No USB Storage Device detected.. Stop Test\n"); | |
66 | return 1; | |
67 | } | |
68 | ||
69 | usb_stor_info(); | |
70 | ||
71 | printf("stopping USB..\n"); | |
72 | usb_stop(); | |
73 | ||
74 | return 0; | |
75 | } | |
76 | ||
54841ab5 | 77 | static int do_led_test(char * const argv[]) |
fa1df308 BS |
78 | { |
79 | int i = 0; | |
80 | struct mpc5xxx_gpt_0_7 *gpt = (struct mpc5xxx_gpt_0_7 *)MPC5XXX_GPT; | |
81 | ||
82 | printf("Starting LED Test\n" | |
83 | "Please set Switch S500 all off\n\n" | |
84 | "Please press any key to start\n\n"); | |
85 | getc(); | |
86 | ||
87 | /* configure timer 2-3 for simple GPIO output High */ | |
88 | gpt->gpt2.emsr |= 0x00000034; | |
89 | gpt->gpt3.emsr |= 0x00000034; | |
90 | ||
91 | (*(vu_long *)MPC5XXX_WU_GPIO_ENABLE) |= 0x80000000; | |
92 | (*(vu_long *)MPC5XXX_WU_GPIO_DIR) |= 0x80000000; | |
93 | printf("Please press any key to stop\n\n"); | |
94 | while (!tstc()) { | |
95 | if (i == 1) { | |
96 | (*(vu_long *)MPC5XXX_WU_GPIO_DATA_O) |= 0x80000000; | |
97 | gpt->gpt2.emsr &= ~0x00000010; | |
98 | gpt->gpt3.emsr &= ~0x00000010; | |
99 | } else if (i == 2) { | |
100 | (*(vu_long *)MPC5XXX_WU_GPIO_DATA_O) &= ~0x80000000; | |
101 | gpt->gpt2.emsr &= ~0x00000010; | |
102 | gpt->gpt3.emsr |= 0x00000010; | |
103 | } else if (i >= 3) { | |
104 | (*(vu_long *)MPC5XXX_WU_GPIO_DATA_O) &= ~0x80000000; | |
105 | gpt->gpt3.emsr &= ~0x00000010; | |
106 | gpt->gpt2.emsr |= 0x00000010; | |
107 | i = 0; | |
108 | } | |
109 | i++; | |
110 | udelay(200000); | |
111 | } | |
112 | getc(); | |
113 | ||
114 | (*(vu_long *)MPC5XXX_WU_GPIO_DATA_O) |= 0x80000000; | |
115 | gpt->gpt2.emsr |= 0x00000010; | |
116 | gpt->gpt3.emsr |= 0x00000010; | |
117 | ||
118 | return 0; | |
119 | } | |
120 | ||
54841ab5 | 121 | static int do_rs232_test(char * const argv[]) |
fa1df308 BS |
122 | { |
123 | int error_status = 0; | |
124 | struct mpc5xxx_gpio *gpio = (struct mpc5xxx_gpio *)MPC5XXX_GPIO; | |
125 | struct mpc5xxx_psc *psc1 = (struct mpc5xxx_psc *)MPC5XXX_PSC1; | |
126 | ||
127 | /* Configure PSC 2-3-6 as GPIO */ | |
128 | gpio->port_config &= 0xFF0FF80F; | |
129 | ||
130 | switch (simple_strtoul(argv[2], NULL, 10)) { | |
131 | case 1: | |
132 | /* check RTS <-> CTS loop */ | |
133 | /* set rts to 0 */ | |
134 | printf("Uart 1 test: RX TX tested by using U-Boot\n" | |
135 | "Please connect RTS with CTS on Uart1 plug\n\n" | |
136 | "Press any key to start\n\n"); | |
137 | getc(); | |
138 | ||
139 | psc1->op1 |= 0x01; | |
140 | ||
141 | /* wait some time before requesting status */ | |
142 | udelay(10); | |
143 | ||
144 | /* check status at cts */ | |
145 | if ((psc1->ip & 0x01) != 0) { | |
146 | error_status = 3; | |
147 | printf("%s: failure at rs232_1, cts status is %d " | |
148 | "(should be 0)\n", | |
149 | __FUNCTION__, (psc1->ip & 0x01)); | |
150 | } | |
151 | ||
152 | /* set rts to 1 */ | |
153 | psc1->op0 |= 0x01; | |
154 | ||
155 | /* wait some time before requesting status */ | |
156 | udelay(10); | |
157 | ||
158 | /* check status at cts */ | |
159 | if ((psc1->ip & 0x01) != 1) { | |
160 | error_status = 3; | |
161 | printf("%s: failure at rs232_1, cts status is %d " | |
162 | "(should be 1)\n", | |
163 | __FUNCTION__, (psc1->ip & 0x01)); | |
164 | } | |
165 | break; | |
166 | case 2: | |
167 | /* set PSC2_0, PSC2_2 as output and PSC2_1, PSC2_3 as input */ | |
168 | printf("Uart 2 test: Please use RS232 Loopback plug on UART2\n" | |
169 | "\nPress any key to start\n\n"); | |
170 | getc(); | |
171 | ||
172 | gpio->simple_gpioe &= ~(0x000000F0); | |
173 | gpio->simple_gpioe |= 0x000000F0; | |
174 | gpio->simple_ddr &= ~(0x000000F0); | |
175 | gpio->simple_ddr |= 0x00000050; | |
176 | ||
177 | /* check TXD <-> RXD loop */ | |
178 | /* set TXD to 1 */ | |
179 | gpio->simple_dvo |= (1 << 4); | |
180 | ||
181 | /* wait some time before requesting status */ | |
182 | udelay(10); | |
183 | ||
184 | if ((gpio->simple_ival & 0x00000020) != 0x00000020) { | |
185 | error_status = 2; | |
186 | printf("%s: failure at rs232_2, rxd status is %d " | |
187 | "(should be 1)\n", __FUNCTION__, | |
188 | (gpio->simple_ival & 0x00000020) >> 5); | |
189 | } | |
190 | ||
191 | /* set TXD to 0 */ | |
192 | gpio->simple_dvo &= ~(1 << 4); | |
193 | ||
194 | /* wait some time before requesting status */ | |
195 | udelay(10); | |
196 | ||
197 | if ((gpio->simple_ival & 0x00000020) != 0x00000000) { | |
198 | error_status = 2; | |
199 | printf("%s: failure at rs232_2, rxd status is %d " | |
200 | "(should be 0)\n", __FUNCTION__, | |
201 | (gpio->simple_ival & 0x00000020) >> 5); | |
202 | } | |
203 | ||
204 | /* check RTS <-> CTS loop */ | |
205 | /* set RTS to 1 */ | |
206 | gpio->simple_dvo |= (1 << 6); | |
207 | ||
208 | /* wait some time before requesting status */ | |
209 | udelay(10); | |
210 | ||
211 | if ((gpio->simple_ival & 0x00000080) != 0x00000080) { | |
212 | error_status = 3; | |
213 | printf("%s: failure at rs232_2, cts status is %d " | |
214 | "(should be 1)\n", __FUNCTION__, | |
215 | (gpio->simple_ival & 0x00000080) >> 7); | |
216 | } | |
217 | ||
218 | /* set RTS to 0 */ | |
219 | gpio->simple_dvo &= ~(1 << 6); | |
220 | ||
221 | /* wait some time before requesting status */ | |
222 | udelay(10); | |
223 | ||
224 | if ((gpio->simple_ival & 0x00000080) != 0x00000000) { | |
225 | error_status = 3; | |
226 | printf("%s: failure at rs232_2, cts status is %d " | |
227 | "(should be 0)\n", __FUNCTION__, | |
228 | (gpio->simple_ival & 0x00000080) >> 7); | |
229 | } | |
230 | break; | |
231 | case 3: | |
232 | /* set PSC3_0, PSC3_2 as output and PSC3_1, PSC3_3 as input */ | |
233 | printf("Uart 3 test: Please use RS232 Loopback plug on UART2\n" | |
234 | "\nPress any key to start\n\n"); | |
235 | getc(); | |
236 | ||
237 | gpio->simple_gpioe &= ~(0x00000F00); | |
238 | gpio->simple_gpioe |= 0x00000F00; | |
239 | ||
240 | gpio->simple_ddr &= ~(0x00000F00); | |
241 | gpio->simple_ddr |= 0x00000500; | |
242 | ||
243 | /* check TXD <-> RXD loop */ | |
244 | /* set TXD to 1 */ | |
245 | gpio->simple_dvo |= (1 << 8); | |
246 | ||
247 | /* wait some time before requesting status */ | |
248 | udelay(10); | |
249 | ||
250 | if ((gpio->simple_ival & 0x00000200) != 0x00000200) { | |
251 | error_status = 2; | |
252 | printf("%s: failure at rs232_3, rxd status is %d " | |
253 | "(should be 1)\n", __FUNCTION__, | |
254 | (gpio->simple_ival & 0x00000200) >> 9); | |
255 | } | |
256 | ||
257 | /* set TXD to 0 */ | |
258 | gpio->simple_dvo &= ~(1 << 8); | |
259 | ||
260 | /* wait some time before requesting status */ | |
261 | udelay(10); | |
262 | ||
263 | if ((gpio->simple_ival & 0x00000200) != 0x00000000) { | |
264 | error_status = 2; | |
265 | printf("%s: failure at rs232_3, rxd status is %d " | |
266 | "(should be 0)\n", __FUNCTION__, | |
267 | (gpio->simple_ival & 0x00000200) >> 9); | |
268 | } | |
269 | ||
270 | /* check RTS <-> CTS loop */ | |
271 | /* set RTS to 1 */ | |
272 | gpio->simple_dvo |= (1 << 10); | |
273 | ||
274 | /* wait some time before requesting status */ | |
275 | udelay(10); | |
276 | ||
277 | if ((gpio->simple_ival & 0x00000800) != 0x00000800) { | |
278 | error_status = 3; | |
279 | printf("%s: failure at rs232_3, cts status is %d " | |
280 | "(should be 1)\n", __FUNCTION__, | |
281 | (gpio->simple_ival & 0x00000800) >> 11); | |
282 | } | |
283 | ||
284 | /* set RTS to 0 */ | |
285 | gpio->simple_dvo &= ~(1 << 10); | |
286 | ||
287 | /* wait some time before requesting status */ | |
288 | udelay(10); | |
289 | ||
290 | if ((gpio->simple_ival & 0x00000800) != 0x00000000) { | |
291 | error_status = 3; | |
292 | printf("%s: failure at rs232_3, cts status is %d " | |
293 | "(should be 0)\n", __FUNCTION__, | |
294 | (gpio->simple_ival & 0x00000800) >> 11); | |
295 | } | |
296 | break; | |
297 | case 4: | |
298 | /* set PSC6_2, PSC6_3 as output and PSC6_0, PSC6_1 as input */ | |
299 | printf("Uart 4 test: Please use RS232 Loopback plug on UART2\n" | |
300 | "\nPress any key to start\n\n"); | |
301 | getc(); | |
302 | ||
303 | gpio->simple_gpioe &= ~(0xF0000000); | |
304 | gpio->simple_gpioe |= 0x30000000; | |
305 | ||
306 | gpio->simple_ddr &= ~(0xf0000000); | |
307 | gpio->simple_ddr |= 0x30000000; | |
308 | ||
309 | (*(vu_long *)MPC5XXX_WU_GPIO_ENABLE) |= 0x30000000; | |
310 | (*(vu_long *)MPC5XXX_WU_GPIO_DIR) &= ~(0x30000000); | |
311 | ||
312 | /* check TXD <-> RXD loop */ | |
313 | /* set TXD to 1 */ | |
314 | gpio->simple_dvo |= (1 << 28); | |
315 | ||
316 | /* wait some time before requesting status */ | |
317 | udelay(10); | |
318 | ||
319 | if (((*(vu_long *)MPC5XXX_WU_GPIO_DATA_I) & 0x10000000) != | |
320 | 0x10000000) { | |
321 | error_status = 2; | |
9b55a253 | 322 | printf("%s: failure at rs232_4, rxd status is %lu " |
fa1df308 BS |
323 | "(should be 1)\n", __FUNCTION__, |
324 | ((*(vu_long *)MPC5XXX_WU_GPIO_DATA_I) & | |
325 | 0x10000000) >> 28); | |
326 | } | |
327 | ||
328 | /* set TXD to 0 */ | |
329 | gpio->simple_dvo &= ~(1 << 28); | |
330 | ||
331 | /* wait some time before requesting status */ | |
332 | udelay(10); | |
333 | ||
334 | if (((*(vu_long *)MPC5XXX_WU_GPIO_DATA_I) & 0x10000000) != | |
335 | 0x00000000) { | |
336 | error_status = 2; | |
9b55a253 | 337 | printf("%s: failure at rs232_4, rxd status is %lu " |
fa1df308 BS |
338 | "(should be 0)\n", __FUNCTION__, |
339 | ((*(vu_long *)MPC5XXX_WU_GPIO_DATA_I) & | |
340 | 0x10000000) >> 28); | |
341 | } | |
342 | ||
343 | /* check RTS <-> CTS loop */ | |
344 | /* set RTS to 1 */ | |
345 | gpio->simple_dvo |= (1 << 29); | |
346 | ||
347 | /* wait some time before requesting status */ | |
348 | udelay(10); | |
349 | ||
350 | if (((*(vu_long *)MPC5XXX_WU_GPIO_DATA_I) & 0x20000000) != | |
351 | 0x20000000) { | |
352 | error_status = 3; | |
9b55a253 | 353 | printf("%s: failure at rs232_4, cts status is %lu " |
fa1df308 BS |
354 | "(should be 1)\n", __FUNCTION__, |
355 | ((*(vu_long *)MPC5XXX_WU_GPIO_DATA_I) & | |
356 | 0x20000000) >> 29); | |
357 | } | |
358 | ||
359 | /* set RTS to 0 */ | |
360 | gpio->simple_dvo &= ~(1 << 29); | |
361 | ||
362 | /* wait some time before requesting status */ | |
363 | udelay(10); | |
364 | ||
365 | if (((*(vu_long *)MPC5XXX_WU_GPIO_DATA_I) & 0x20000000) != | |
366 | 0x00000000) { | |
367 | error_status = 3; | |
9b55a253 | 368 | printf("%s: failure at rs232_4, cts status is %lu " |
fa1df308 BS |
369 | "(should be 0)\n", __FUNCTION__, |
370 | ((*(vu_long *)MPC5XXX_WU_GPIO_DATA_I) & | |
371 | 0x20000000) >> 29); | |
372 | } | |
373 | break; | |
374 | default: | |
375 | printf("%s: invalid rs232 number %s\n", __FUNCTION__, argv[2]); | |
376 | error_status = 1; | |
377 | break; | |
378 | } | |
6d0f6bcf | 379 | gpio->port_config |= (CONFIG_SYS_GPS_PORT_CONFIG & 0xFF0FF80F); |
fa1df308 BS |
380 | |
381 | return error_status; | |
382 | } | |
383 | ||
54841ab5 | 384 | static int cmd_fkt(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
fa1df308 BS |
385 | { |
386 | int rcode = -1; | |
387 | ||
388 | switch (argc) { | |
389 | case 2: | |
390 | if (strncmp(argv[1], "i2c", 3) == 0) | |
8229e9c0 | 391 | rcode = do_i2c_test(argv); |
fa1df308 | 392 | else if (strncmp(argv[1], "led", 3) == 0) |
8229e9c0 | 393 | rcode = do_led_test(argv); |
fa1df308 | 394 | else if (strncmp(argv[1], "usb", 3) == 0) |
8229e9c0 | 395 | rcode = do_usb_test(argv); |
fa1df308 BS |
396 | break; |
397 | case 3: | |
398 | if (strncmp(argv[1], "rs232", 3) == 0) | |
8229e9c0 | 399 | rcode = do_rs232_test(argv); |
fa1df308 BS |
400 | break; |
401 | } | |
402 | ||
403 | switch (rcode) { | |
404 | case -1: | |
405 | printf("Usage:\n" | |
406 | "fkt { i2c | led | usb }\n" | |
407 | "fkt rs232 number\n"); | |
408 | rcode = 1; | |
409 | break; | |
410 | case 0: | |
411 | printf("Test passed\n"); | |
412 | break; | |
413 | default: | |
414 | printf("Test failed with code: %d\n", rcode); | |
415 | } | |
416 | ||
417 | return rcode; | |
418 | } | |
419 | ||
420 | U_BOOT_CMD( | |
421 | fkt, 4, 1, cmd_fkt, | |
2fb2604d | 422 | "Function test routines", |
fa1df308 BS |
423 | "i2c\n" |
424 | " - Test I2C communication\n" | |
425 | "fkt led\n" | |
426 | " - Test LEDs\n" | |
427 | "fkt rs232 number\n" | |
428 | " - Test RS232 (loopback plug(s) for RS232 required)\n" | |
429 | "fkt usb\n" | |
a89c33db | 430 | " - Test USB communication" |
fa1df308 | 431 | ); |
afaac86f | 432 | #endif /* CONFIG_CMD_BSP */ |