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_i2c_test(char * const argv
[])
18 unsigned char temp
, temp1
;
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");
25 temp
= 0xf0; /* set io 0-4 as output */
26 i2c_write(CONFIG_SYS_I2C_IO
, 3, 1, (uchar
*)&temp
, 1);
28 printf("Press I2C4-7. LED I2C0-3 should have the same state\n\n"
29 "Press any key to stop\n\n");
32 i2c_read(CONFIG_SYS_I2C_IO
, 0, 1, (uchar
*)&temp
, 1);
33 temp1
= (temp
>> 4) & 0x03;
34 temp1
|= (temp
>> 3) & 0x08; /* S302 -> LED303 */
35 temp1
|= (temp
>> 5) & 0x04; /* S303 -> LED302 */
37 i2c_write(CONFIG_SYS_I2C_IO
, 1, 1, (uchar
*)&temp
, 1);
44 static int do_usb_test(char * const argv
[])
47 static int usb_stor_curr_dev
= -1; /* current device */
49 printf("Starting USB Test\n"
50 "Please insert USB Memmory Stick\n\n"
51 "Please press any key to start\n\n");
55 printf("(Re)start USB...\n");
57 #ifdef CONFIG_USB_STORAGE
58 /* try to recognize storage devices immediately */
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");
65 printf("No USB Storage Device detected.. Stop Test\n");
71 printf("stopping USB..\n");
77 static int do_led_test(char * const argv
[])
80 struct mpc5xxx_gpt_0_7
*gpt
= (struct mpc5xxx_gpt_0_7
*)MPC5XXX_GPT
;
82 printf("Starting LED Test\n"
83 "Please set Switch S500 all off\n\n"
84 "Please press any key to start\n\n");
87 /* configure timer 2-3 for simple GPIO output High */
88 gpt
->gpt2
.emsr
|= 0x00000034;
89 gpt
->gpt3
.emsr
|= 0x00000034;
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");
96 (*(vu_long
*)MPC5XXX_WU_GPIO_DATA_O
) |= 0x80000000;
97 gpt
->gpt2
.emsr
&= ~0x00000010;
98 gpt
->gpt3
.emsr
&= ~0x00000010;
100 (*(vu_long
*)MPC5XXX_WU_GPIO_DATA_O
) &= ~0x80000000;
101 gpt
->gpt2
.emsr
&= ~0x00000010;
102 gpt
->gpt3
.emsr
|= 0x00000010;
104 (*(vu_long
*)MPC5XXX_WU_GPIO_DATA_O
) &= ~0x80000000;
105 gpt
->gpt3
.emsr
&= ~0x00000010;
106 gpt
->gpt2
.emsr
|= 0x00000010;
114 (*(vu_long
*)MPC5XXX_WU_GPIO_DATA_O
) |= 0x80000000;
115 gpt
->gpt2
.emsr
|= 0x00000010;
116 gpt
->gpt3
.emsr
|= 0x00000010;
121 static int do_rs232_test(char * const argv
[])
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
;
127 /* Configure PSC 2-3-6 as GPIO */
128 gpio
->port_config
&= 0xFF0FF80F;
130 switch (simple_strtoul(argv
[2], NULL
, 10)) {
132 /* check RTS <-> CTS loop */
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");
141 /* wait some time before requesting status */
144 /* check status at cts */
145 if ((psc1
->ip
& 0x01) != 0) {
147 printf("%s: failure at rs232_1, cts status is %d "
149 __FUNCTION__
, (psc1
->ip
& 0x01));
155 /* wait some time before requesting status */
158 /* check status at cts */
159 if ((psc1
->ip
& 0x01) != 1) {
161 printf("%s: failure at rs232_1, cts status is %d "
163 __FUNCTION__
, (psc1
->ip
& 0x01));
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");
172 gpio
->simple_gpioe
&= ~(0x000000F0);
173 gpio
->simple_gpioe
|= 0x000000F0;
174 gpio
->simple_ddr
&= ~(0x000000F0);
175 gpio
->simple_ddr
|= 0x00000050;
177 /* check TXD <-> RXD loop */
179 gpio
->simple_dvo
|= (1 << 4);
181 /* wait some time before requesting status */
184 if ((gpio
->simple_ival
& 0x00000020) != 0x00000020) {
186 printf("%s: failure at rs232_2, rxd status is %d "
187 "(should be 1)\n", __FUNCTION__
,
188 (gpio
->simple_ival
& 0x00000020) >> 5);
192 gpio
->simple_dvo
&= ~(1 << 4);
194 /* wait some time before requesting status */
197 if ((gpio
->simple_ival
& 0x00000020) != 0x00000000) {
199 printf("%s: failure at rs232_2, rxd status is %d "
200 "(should be 0)\n", __FUNCTION__
,
201 (gpio
->simple_ival
& 0x00000020) >> 5);
204 /* check RTS <-> CTS loop */
206 gpio
->simple_dvo
|= (1 << 6);
208 /* wait some time before requesting status */
211 if ((gpio
->simple_ival
& 0x00000080) != 0x00000080) {
213 printf("%s: failure at rs232_2, cts status is %d "
214 "(should be 1)\n", __FUNCTION__
,
215 (gpio
->simple_ival
& 0x00000080) >> 7);
219 gpio
->simple_dvo
&= ~(1 << 6);
221 /* wait some time before requesting status */
224 if ((gpio
->simple_ival
& 0x00000080) != 0x00000000) {
226 printf("%s: failure at rs232_2, cts status is %d "
227 "(should be 0)\n", __FUNCTION__
,
228 (gpio
->simple_ival
& 0x00000080) >> 7);
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");
237 gpio
->simple_gpioe
&= ~(0x00000F00);
238 gpio
->simple_gpioe
|= 0x00000F00;
240 gpio
->simple_ddr
&= ~(0x00000F00);
241 gpio
->simple_ddr
|= 0x00000500;
243 /* check TXD <-> RXD loop */
245 gpio
->simple_dvo
|= (1 << 8);
247 /* wait some time before requesting status */
250 if ((gpio
->simple_ival
& 0x00000200) != 0x00000200) {
252 printf("%s: failure at rs232_3, rxd status is %d "
253 "(should be 1)\n", __FUNCTION__
,
254 (gpio
->simple_ival
& 0x00000200) >> 9);
258 gpio
->simple_dvo
&= ~(1 << 8);
260 /* wait some time before requesting status */
263 if ((gpio
->simple_ival
& 0x00000200) != 0x00000000) {
265 printf("%s: failure at rs232_3, rxd status is %d "
266 "(should be 0)\n", __FUNCTION__
,
267 (gpio
->simple_ival
& 0x00000200) >> 9);
270 /* check RTS <-> CTS loop */
272 gpio
->simple_dvo
|= (1 << 10);
274 /* wait some time before requesting status */
277 if ((gpio
->simple_ival
& 0x00000800) != 0x00000800) {
279 printf("%s: failure at rs232_3, cts status is %d "
280 "(should be 1)\n", __FUNCTION__
,
281 (gpio
->simple_ival
& 0x00000800) >> 11);
285 gpio
->simple_dvo
&= ~(1 << 10);
287 /* wait some time before requesting status */
290 if ((gpio
->simple_ival
& 0x00000800) != 0x00000000) {
292 printf("%s: failure at rs232_3, cts status is %d "
293 "(should be 0)\n", __FUNCTION__
,
294 (gpio
->simple_ival
& 0x00000800) >> 11);
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");
303 gpio
->simple_gpioe
&= ~(0xF0000000);
304 gpio
->simple_gpioe
|= 0x30000000;
306 gpio
->simple_ddr
&= ~(0xf0000000);
307 gpio
->simple_ddr
|= 0x30000000;
309 (*(vu_long
*)MPC5XXX_WU_GPIO_ENABLE
) |= 0x30000000;
310 (*(vu_long
*)MPC5XXX_WU_GPIO_DIR
) &= ~(0x30000000);
312 /* check TXD <-> RXD loop */
314 gpio
->simple_dvo
|= (1 << 28);
316 /* wait some time before requesting status */
319 if (((*(vu_long
*)MPC5XXX_WU_GPIO_DATA_I
) & 0x10000000) !=
322 printf("%s: failure at rs232_4, rxd status is %lu "
323 "(should be 1)\n", __FUNCTION__
,
324 ((*(vu_long
*)MPC5XXX_WU_GPIO_DATA_I
) &
329 gpio
->simple_dvo
&= ~(1 << 28);
331 /* wait some time before requesting status */
334 if (((*(vu_long
*)MPC5XXX_WU_GPIO_DATA_I
) & 0x10000000) !=
337 printf("%s: failure at rs232_4, rxd status is %lu "
338 "(should be 0)\n", __FUNCTION__
,
339 ((*(vu_long
*)MPC5XXX_WU_GPIO_DATA_I
) &
343 /* check RTS <-> CTS loop */
345 gpio
->simple_dvo
|= (1 << 29);
347 /* wait some time before requesting status */
350 if (((*(vu_long
*)MPC5XXX_WU_GPIO_DATA_I
) & 0x20000000) !=
353 printf("%s: failure at rs232_4, cts status is %lu "
354 "(should be 1)\n", __FUNCTION__
,
355 ((*(vu_long
*)MPC5XXX_WU_GPIO_DATA_I
) &
360 gpio
->simple_dvo
&= ~(1 << 29);
362 /* wait some time before requesting status */
365 if (((*(vu_long
*)MPC5XXX_WU_GPIO_DATA_I
) & 0x20000000) !=
368 printf("%s: failure at rs232_4, cts status is %lu "
369 "(should be 0)\n", __FUNCTION__
,
370 ((*(vu_long
*)MPC5XXX_WU_GPIO_DATA_I
) &
375 printf("%s: invalid rs232 number %s\n", __FUNCTION__
, argv
[2]);
379 gpio
->port_config
|= (CONFIG_SYS_GPS_PORT_CONFIG
& 0xFF0FF80F);
384 static int cmd_fkt(cmd_tbl_t
*cmdtp
, int flag
, int argc
, char * const argv
[])
390 if (strncmp(argv
[1], "i2c", 3) == 0)
391 rcode
= do_i2c_test(argv
);
392 else if (strncmp(argv
[1], "led", 3) == 0)
393 rcode
= do_led_test(argv
);
394 else if (strncmp(argv
[1], "usb", 3) == 0)
395 rcode
= do_usb_test(argv
);
398 if (strncmp(argv
[1], "rs232", 3) == 0)
399 rcode
= do_rs232_test(argv
);
406 "fkt { i2c | led | usb }\n"
407 "fkt rs232 number\n");
411 printf("Test passed\n");
414 printf("Test failed with code: %d\n", rcode
);
422 "Function test routines",
424 " - Test I2C communication\n"
428 " - Test RS232 (loopback plug(s) for RS232 required)\n"
430 " - Test USB communication"
432 #endif /* CONFIG_CMD_BSP */