2 * (C) Copyright 2007 Markus Kappeler <markus.kappeler@objectxp.com>
4 * Adapted for U-Boot 1.2 by Piotr Kruszynski <ppk@semihalf.com>
6 * See file CREDITS for list of people who contributed to this
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License as
11 * published by the Free Software Foundation; either version 2 of
12 * the License, or (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
32 static int do_i2c_test(char *argv
[])
34 unsigned char temp
, temp1
;
36 printf("Starting I2C Test\n"
37 "Please set Jumper:\nI2C SDA 2-3\nI2C SCL 2-3\n\n"
38 "Please press any key to start\n\n");
41 temp
= 0xf0; /* set io 0-4 as output */
42 i2c_write(CONFIG_SYS_I2C_IO
, 3, 1, (uchar
*)&temp
, 1);
44 printf("Press I2C4-7. LED I2C0-3 should have the same state\n\n"
45 "Press any key to stop\n\n");
48 i2c_read(CONFIG_SYS_I2C_IO
, 0, 1, (uchar
*)&temp
, 1);
49 temp1
= (temp
>> 4) & 0x03;
50 temp1
|= (temp
>> 3) & 0x08; /* S302 -> LED303 */
51 temp1
|= (temp
>> 5) & 0x04; /* S303 -> LED302 */
53 i2c_write(CONFIG_SYS_I2C_IO
, 1, 1, (uchar
*)&temp
, 1);
60 static int do_usb_test(char *argv
[])
63 static int usb_stor_curr_dev
= -1; /* current device */
65 printf("Starting USB Test\n"
66 "Please insert USB Memmory Stick\n\n"
67 "Please press any key to start\n\n");
71 printf("(Re)start USB...\n");
73 #ifdef CONFIG_USB_STORAGE
74 /* try to recognize storage devices immediately */
76 usb_stor_curr_dev
= usb_stor_scan(1);
77 #endif /* CONFIG_USB_STORAGE */
78 if (usb_stor_curr_dev
>= 0)
79 printf("Found USB Storage Dev continue with Test...\n");
81 printf("No USB Storage Device detected.. Stop Test\n");
87 printf("stopping USB..\n");
93 static int do_led_test(char *argv
[])
96 struct mpc5xxx_gpt_0_7
*gpt
= (struct mpc5xxx_gpt_0_7
*)MPC5XXX_GPT
;
98 printf("Starting LED Test\n"
99 "Please set Switch S500 all off\n\n"
100 "Please press any key to start\n\n");
103 /* configure timer 2-3 for simple GPIO output High */
104 gpt
->gpt2
.emsr
|= 0x00000034;
105 gpt
->gpt3
.emsr
|= 0x00000034;
107 (*(vu_long
*)MPC5XXX_WU_GPIO_ENABLE
) |= 0x80000000;
108 (*(vu_long
*)MPC5XXX_WU_GPIO_DIR
) |= 0x80000000;
109 printf("Please press any key to stop\n\n");
112 (*(vu_long
*)MPC5XXX_WU_GPIO_DATA_O
) |= 0x80000000;
113 gpt
->gpt2
.emsr
&= ~0x00000010;
114 gpt
->gpt3
.emsr
&= ~0x00000010;
116 (*(vu_long
*)MPC5XXX_WU_GPIO_DATA_O
) &= ~0x80000000;
117 gpt
->gpt2
.emsr
&= ~0x00000010;
118 gpt
->gpt3
.emsr
|= 0x00000010;
120 (*(vu_long
*)MPC5XXX_WU_GPIO_DATA_O
) &= ~0x80000000;
121 gpt
->gpt3
.emsr
&= ~0x00000010;
122 gpt
->gpt2
.emsr
|= 0x00000010;
130 (*(vu_long
*)MPC5XXX_WU_GPIO_DATA_O
) |= 0x80000000;
131 gpt
->gpt2
.emsr
|= 0x00000010;
132 gpt
->gpt3
.emsr
|= 0x00000010;
137 static int do_rs232_test(char *argv
[])
139 int error_status
= 0;
140 struct mpc5xxx_gpio
*gpio
= (struct mpc5xxx_gpio
*)MPC5XXX_GPIO
;
141 struct mpc5xxx_psc
*psc1
= (struct mpc5xxx_psc
*)MPC5XXX_PSC1
;
143 /* Configure PSC 2-3-6 as GPIO */
144 gpio
->port_config
&= 0xFF0FF80F;
146 switch (simple_strtoul(argv
[2], NULL
, 10)) {
148 /* check RTS <-> CTS loop */
150 printf("Uart 1 test: RX TX tested by using U-Boot\n"
151 "Please connect RTS with CTS on Uart1 plug\n\n"
152 "Press any key to start\n\n");
157 /* wait some time before requesting status */
160 /* check status at cts */
161 if ((psc1
->ip
& 0x01) != 0) {
163 printf("%s: failure at rs232_1, cts status is %d "
165 __FUNCTION__
, (psc1
->ip
& 0x01));
171 /* wait some time before requesting status */
174 /* check status at cts */
175 if ((psc1
->ip
& 0x01) != 1) {
177 printf("%s: failure at rs232_1, cts status is %d "
179 __FUNCTION__
, (psc1
->ip
& 0x01));
183 /* set PSC2_0, PSC2_2 as output and PSC2_1, PSC2_3 as input */
184 printf("Uart 2 test: Please use RS232 Loopback plug on UART2\n"
185 "\nPress any key to start\n\n");
188 gpio
->simple_gpioe
&= ~(0x000000F0);
189 gpio
->simple_gpioe
|= 0x000000F0;
190 gpio
->simple_ddr
&= ~(0x000000F0);
191 gpio
->simple_ddr
|= 0x00000050;
193 /* check TXD <-> RXD loop */
195 gpio
->simple_dvo
|= (1 << 4);
197 /* wait some time before requesting status */
200 if ((gpio
->simple_ival
& 0x00000020) != 0x00000020) {
202 printf("%s: failure at rs232_2, rxd status is %d "
203 "(should be 1)\n", __FUNCTION__
,
204 (gpio
->simple_ival
& 0x00000020) >> 5);
208 gpio
->simple_dvo
&= ~(1 << 4);
210 /* wait some time before requesting status */
213 if ((gpio
->simple_ival
& 0x00000020) != 0x00000000) {
215 printf("%s: failure at rs232_2, rxd status is %d "
216 "(should be 0)\n", __FUNCTION__
,
217 (gpio
->simple_ival
& 0x00000020) >> 5);
220 /* check RTS <-> CTS loop */
222 gpio
->simple_dvo
|= (1 << 6);
224 /* wait some time before requesting status */
227 if ((gpio
->simple_ival
& 0x00000080) != 0x00000080) {
229 printf("%s: failure at rs232_2, cts status is %d "
230 "(should be 1)\n", __FUNCTION__
,
231 (gpio
->simple_ival
& 0x00000080) >> 7);
235 gpio
->simple_dvo
&= ~(1 << 6);
237 /* wait some time before requesting status */
240 if ((gpio
->simple_ival
& 0x00000080) != 0x00000000) {
242 printf("%s: failure at rs232_2, cts status is %d "
243 "(should be 0)\n", __FUNCTION__
,
244 (gpio
->simple_ival
& 0x00000080) >> 7);
248 /* set PSC3_0, PSC3_2 as output and PSC3_1, PSC3_3 as input */
249 printf("Uart 3 test: Please use RS232 Loopback plug on UART2\n"
250 "\nPress any key to start\n\n");
253 gpio
->simple_gpioe
&= ~(0x00000F00);
254 gpio
->simple_gpioe
|= 0x00000F00;
256 gpio
->simple_ddr
&= ~(0x00000F00);
257 gpio
->simple_ddr
|= 0x00000500;
259 /* check TXD <-> RXD loop */
261 gpio
->simple_dvo
|= (1 << 8);
263 /* wait some time before requesting status */
266 if ((gpio
->simple_ival
& 0x00000200) != 0x00000200) {
268 printf("%s: failure at rs232_3, rxd status is %d "
269 "(should be 1)\n", __FUNCTION__
,
270 (gpio
->simple_ival
& 0x00000200) >> 9);
274 gpio
->simple_dvo
&= ~(1 << 8);
276 /* wait some time before requesting status */
279 if ((gpio
->simple_ival
& 0x00000200) != 0x00000000) {
281 printf("%s: failure at rs232_3, rxd status is %d "
282 "(should be 0)\n", __FUNCTION__
,
283 (gpio
->simple_ival
& 0x00000200) >> 9);
286 /* check RTS <-> CTS loop */
288 gpio
->simple_dvo
|= (1 << 10);
290 /* wait some time before requesting status */
293 if ((gpio
->simple_ival
& 0x00000800) != 0x00000800) {
295 printf("%s: failure at rs232_3, cts status is %d "
296 "(should be 1)\n", __FUNCTION__
,
297 (gpio
->simple_ival
& 0x00000800) >> 11);
301 gpio
->simple_dvo
&= ~(1 << 10);
303 /* wait some time before requesting status */
306 if ((gpio
->simple_ival
& 0x00000800) != 0x00000000) {
308 printf("%s: failure at rs232_3, cts status is %d "
309 "(should be 0)\n", __FUNCTION__
,
310 (gpio
->simple_ival
& 0x00000800) >> 11);
314 /* set PSC6_2, PSC6_3 as output and PSC6_0, PSC6_1 as input */
315 printf("Uart 4 test: Please use RS232 Loopback plug on UART2\n"
316 "\nPress any key to start\n\n");
319 gpio
->simple_gpioe
&= ~(0xF0000000);
320 gpio
->simple_gpioe
|= 0x30000000;
322 gpio
->simple_ddr
&= ~(0xf0000000);
323 gpio
->simple_ddr
|= 0x30000000;
325 (*(vu_long
*)MPC5XXX_WU_GPIO_ENABLE
) |= 0x30000000;
326 (*(vu_long
*)MPC5XXX_WU_GPIO_DIR
) &= ~(0x30000000);
328 /* check TXD <-> RXD loop */
330 gpio
->simple_dvo
|= (1 << 28);
332 /* wait some time before requesting status */
335 if (((*(vu_long
*)MPC5XXX_WU_GPIO_DATA_I
) & 0x10000000) !=
338 printf("%s: failure at rs232_4, rxd status is %lu "
339 "(should be 1)\n", __FUNCTION__
,
340 ((*(vu_long
*)MPC5XXX_WU_GPIO_DATA_I
) &
345 gpio
->simple_dvo
&= ~(1 << 28);
347 /* wait some time before requesting status */
350 if (((*(vu_long
*)MPC5XXX_WU_GPIO_DATA_I
) & 0x10000000) !=
353 printf("%s: failure at rs232_4, rxd status is %lu "
354 "(should be 0)\n", __FUNCTION__
,
355 ((*(vu_long
*)MPC5XXX_WU_GPIO_DATA_I
) &
359 /* check RTS <-> CTS loop */
361 gpio
->simple_dvo
|= (1 << 29);
363 /* wait some time before requesting status */
366 if (((*(vu_long
*)MPC5XXX_WU_GPIO_DATA_I
) & 0x20000000) !=
369 printf("%s: failure at rs232_4, cts status is %lu "
370 "(should be 1)\n", __FUNCTION__
,
371 ((*(vu_long
*)MPC5XXX_WU_GPIO_DATA_I
) &
376 gpio
->simple_dvo
&= ~(1 << 29);
378 /* wait some time before requesting status */
381 if (((*(vu_long
*)MPC5XXX_WU_GPIO_DATA_I
) & 0x20000000) !=
384 printf("%s: failure at rs232_4, cts status is %lu "
385 "(should be 0)\n", __FUNCTION__
,
386 ((*(vu_long
*)MPC5XXX_WU_GPIO_DATA_I
) &
391 printf("%s: invalid rs232 number %s\n", __FUNCTION__
, argv
[2]);
395 gpio
->port_config
|= (CONFIG_SYS_GPS_PORT_CONFIG
& 0xFF0FF80F);
400 static int cmd_fkt(cmd_tbl_t
*cmdtp
, int flag
, int argc
, char *argv
[])
406 if (strncmp(argv
[1], "i2c", 3) == 0)
407 rcode
= do_i2c_test(argv
);
408 else if (strncmp(argv
[1], "led", 3) == 0)
409 rcode
= do_led_test(argv
);
410 else if (strncmp(argv
[1], "usb", 3) == 0)
411 rcode
= do_usb_test(argv
);
414 if (strncmp(argv
[1], "rs232", 3) == 0)
415 rcode
= do_rs232_test(argv
);
422 "fkt { i2c | led | usb }\n"
423 "fkt rs232 number\n");
427 printf("Test passed\n");
430 printf("Test failed with code: %d\n", rcode
);
438 "Function test routines",
440 " - Test I2C communication\n"
444 " - Test RS232 (loopback plug(s) for RS232 required)\n"
446 " - Test USB communication"
448 #endif /* CONFIG_CMD_BSP */