2 * (C) Copyright 2007 Markus Kappeler <markus.kappeler@objectxp.com>
4 * Adapted for U-Boot 1.2 by Piotr Kruszynski <ppk@semihalf.com>
6 * SPDX-License-Identifier: GPL-2.0+
16 static int do_usb_test(char * const argv[])
19 static int usb_stor_curr_dev = -1; /* current device */
21 printf("Starting USB Test\n"
22 "Please insert USB Memmory Stick\n\n"
23 "Please press any key to start\n\n");
27 printf("(Re)start USB...\n");
29 #ifdef CONFIG_USB_STORAGE
30 /* try to recognize storage devices immediately */
32 usb_stor_curr_dev = usb_stor_scan(1);
33 #endif /* CONFIG_USB_STORAGE */
34 if (usb_stor_curr_dev >= 0)
35 printf("Found USB Storage Dev continue with Test...\n");
37 printf("No USB Storage Device detected.. Stop Test\n");
43 printf("stopping USB..\n");
49 static int do_led_test(char * const argv[])
52 struct mpc5xxx_gpt_0_7 *gpt = (struct mpc5xxx_gpt_0_7 *)MPC5XXX_GPT;
54 printf("Starting LED Test\n"
55 "Please set Switch S500 all off\n\n"
56 "Please press any key to start\n\n");
59 /* configure timer 2-3 for simple GPIO output High */
60 gpt->gpt2.emsr |= 0x00000034;
61 gpt->gpt3.emsr |= 0x00000034;
63 (*(vu_long *)MPC5XXX_WU_GPIO_ENABLE) |= 0x80000000;
64 (*(vu_long *)MPC5XXX_WU_GPIO_DIR) |= 0x80000000;
65 printf("Please press any key to stop\n\n");
68 (*(vu_long *)MPC5XXX_WU_GPIO_DATA_O) |= 0x80000000;
69 gpt->gpt2.emsr &= ~0x00000010;
70 gpt->gpt3.emsr &= ~0x00000010;
72 (*(vu_long *)MPC5XXX_WU_GPIO_DATA_O) &= ~0x80000000;
73 gpt->gpt2.emsr &= ~0x00000010;
74 gpt->gpt3.emsr |= 0x00000010;
76 (*(vu_long *)MPC5XXX_WU_GPIO_DATA_O) &= ~0x80000000;
77 gpt->gpt3.emsr &= ~0x00000010;
78 gpt->gpt2.emsr |= 0x00000010;
86 (*(vu_long *)MPC5XXX_WU_GPIO_DATA_O) |= 0x80000000;
87 gpt->gpt2.emsr |= 0x00000010;
88 gpt->gpt3.emsr |= 0x00000010;
93 static int do_rs232_test(char * const argv[])
96 struct mpc5xxx_gpio *gpio = (struct mpc5xxx_gpio *)MPC5XXX_GPIO;
97 struct mpc5xxx_psc *psc1 = (struct mpc5xxx_psc *)MPC5XXX_PSC1;
99 /* Configure PSC 2-3-6 as GPIO */
100 gpio->port_config &= 0xFF0FF80F;
102 switch (simple_strtoul(argv[2], NULL, 10)) {
104 /* check RTS <-> CTS loop */
106 printf("Uart 1 test: RX TX tested by using U-Boot\n"
107 "Please connect RTS with CTS on Uart1 plug\n\n"
108 "Press any key to start\n\n");
113 /* wait some time before requesting status */
116 /* check status at cts */
117 if ((psc1->ip & 0x01) != 0) {
119 printf("%s: failure at rs232_1, cts status is %d "
121 __FUNCTION__, (psc1->ip & 0x01));
127 /* wait some time before requesting status */
130 /* check status at cts */
131 if ((psc1->ip & 0x01) != 1) {
133 printf("%s: failure at rs232_1, cts status is %d "
135 __FUNCTION__, (psc1->ip & 0x01));
139 /* set PSC2_0, PSC2_2 as output and PSC2_1, PSC2_3 as input */
140 printf("Uart 2 test: Please use RS232 Loopback plug on UART2\n"
141 "\nPress any key to start\n\n");
144 gpio->simple_gpioe &= ~(0x000000F0);
145 gpio->simple_gpioe |= 0x000000F0;
146 gpio->simple_ddr &= ~(0x000000F0);
147 gpio->simple_ddr |= 0x00000050;
149 /* check TXD <-> RXD loop */
151 gpio->simple_dvo |= (1 << 4);
153 /* wait some time before requesting status */
156 if ((gpio->simple_ival & 0x00000020) != 0x00000020) {
158 printf("%s: failure at rs232_2, rxd status is %d "
159 "(should be 1)\n", __FUNCTION__,
160 (gpio->simple_ival & 0x00000020) >> 5);
164 gpio->simple_dvo &= ~(1 << 4);
166 /* wait some time before requesting status */
169 if ((gpio->simple_ival & 0x00000020) != 0x00000000) {
171 printf("%s: failure at rs232_2, rxd status is %d "
172 "(should be 0)\n", __FUNCTION__,
173 (gpio->simple_ival & 0x00000020) >> 5);
176 /* check RTS <-> CTS loop */
178 gpio->simple_dvo |= (1 << 6);
180 /* wait some time before requesting status */
183 if ((gpio->simple_ival & 0x00000080) != 0x00000080) {
185 printf("%s: failure at rs232_2, cts status is %d "
186 "(should be 1)\n", __FUNCTION__,
187 (gpio->simple_ival & 0x00000080) >> 7);
191 gpio->simple_dvo &= ~(1 << 6);
193 /* wait some time before requesting status */
196 if ((gpio->simple_ival & 0x00000080) != 0x00000000) {
198 printf("%s: failure at rs232_2, cts status is %d "
199 "(should be 0)\n", __FUNCTION__,
200 (gpio->simple_ival & 0x00000080) >> 7);
204 /* set PSC3_0, PSC3_2 as output and PSC3_1, PSC3_3 as input */
205 printf("Uart 3 test: Please use RS232 Loopback plug on UART2\n"
206 "\nPress any key to start\n\n");
209 gpio->simple_gpioe &= ~(0x00000F00);
210 gpio->simple_gpioe |= 0x00000F00;
212 gpio->simple_ddr &= ~(0x00000F00);
213 gpio->simple_ddr |= 0x00000500;
215 /* check TXD <-> RXD loop */
217 gpio->simple_dvo |= (1 << 8);
219 /* wait some time before requesting status */
222 if ((gpio->simple_ival & 0x00000200) != 0x00000200) {
224 printf("%s: failure at rs232_3, rxd status is %d "
225 "(should be 1)\n", __FUNCTION__,
226 (gpio->simple_ival & 0x00000200) >> 9);
230 gpio->simple_dvo &= ~(1 << 8);
232 /* wait some time before requesting status */
235 if ((gpio->simple_ival & 0x00000200) != 0x00000000) {
237 printf("%s: failure at rs232_3, rxd status is %d "
238 "(should be 0)\n", __FUNCTION__,
239 (gpio->simple_ival & 0x00000200) >> 9);
242 /* check RTS <-> CTS loop */
244 gpio->simple_dvo |= (1 << 10);
246 /* wait some time before requesting status */
249 if ((gpio->simple_ival & 0x00000800) != 0x00000800) {
251 printf("%s: failure at rs232_3, cts status is %d "
252 "(should be 1)\n", __FUNCTION__,
253 (gpio->simple_ival & 0x00000800) >> 11);
257 gpio->simple_dvo &= ~(1 << 10);
259 /* wait some time before requesting status */
262 if ((gpio->simple_ival & 0x00000800) != 0x00000000) {
264 printf("%s: failure at rs232_3, cts status is %d "
265 "(should be 0)\n", __FUNCTION__,
266 (gpio->simple_ival & 0x00000800) >> 11);
270 /* set PSC6_2, PSC6_3 as output and PSC6_0, PSC6_1 as input */
271 printf("Uart 4 test: Please use RS232 Loopback plug on UART2\n"
272 "\nPress any key to start\n\n");
275 gpio->simple_gpioe &= ~(0xF0000000);
276 gpio->simple_gpioe |= 0x30000000;
278 gpio->simple_ddr &= ~(0xf0000000);
279 gpio->simple_ddr |= 0x30000000;
281 (*(vu_long *)MPC5XXX_WU_GPIO_ENABLE) |= 0x30000000;
282 (*(vu_long *)MPC5XXX_WU_GPIO_DIR) &= ~(0x30000000);
284 /* check TXD <-> RXD loop */
286 gpio->simple_dvo |= (1 << 28);
288 /* wait some time before requesting status */
291 if (((*(vu_long *)MPC5XXX_WU_GPIO_DATA_I) & 0x10000000) !=
294 printf("%s: failure at rs232_4, rxd status is %lu "
295 "(should be 1)\n", __FUNCTION__,
296 ((*(vu_long *)MPC5XXX_WU_GPIO_DATA_I) &
301 gpio->simple_dvo &= ~(1 << 28);
303 /* wait some time before requesting status */
306 if (((*(vu_long *)MPC5XXX_WU_GPIO_DATA_I) & 0x10000000) !=
309 printf("%s: failure at rs232_4, rxd status is %lu "
310 "(should be 0)\n", __FUNCTION__,
311 ((*(vu_long *)MPC5XXX_WU_GPIO_DATA_I) &
315 /* check RTS <-> CTS loop */
317 gpio->simple_dvo |= (1 << 29);
319 /* wait some time before requesting status */
322 if (((*(vu_long *)MPC5XXX_WU_GPIO_DATA_I) & 0x20000000) !=
325 printf("%s: failure at rs232_4, cts status is %lu "
326 "(should be 1)\n", __FUNCTION__,
327 ((*(vu_long *)MPC5XXX_WU_GPIO_DATA_I) &
332 gpio->simple_dvo &= ~(1 << 29);
334 /* wait some time before requesting status */
337 if (((*(vu_long *)MPC5XXX_WU_GPIO_DATA_I) & 0x20000000) !=
340 printf("%s: failure at rs232_4, cts status is %lu "
341 "(should be 0)\n", __FUNCTION__,
342 ((*(vu_long *)MPC5XXX_WU_GPIO_DATA_I) &
347 printf("%s: invalid rs232 number %s\n", __FUNCTION__, argv[2]);
351 gpio->port_config |= (CONFIG_SYS_GPS_PORT_CONFIG & 0xFF0FF80F);
356 static int cmd_fkt(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
362 if (strncmp(argv[1], "led", 3) == 0)
363 rcode = do_led_test(argv);
364 else if (strncmp(argv[1], "usb", 3) == 0)
365 rcode = do_usb_test(argv);
368 if (strncmp(argv[1], "rs232", 3) == 0)
369 rcode = do_rs232_test(argv);
376 "fkt { i2c | led | usb }\n"
377 "fkt rs232 number\n");
381 printf("Test passed\n");
384 printf("Test failed with code: %d\n", rcode);
392 "Function test routines",
394 " - Test I2C communication\n"
398 " - Test RS232 (loopback plug(s) for RS232 required)\n"
400 " - Test USB communication"
402 #endif /* CONFIG_CMD_BSP */