2 * (C) Copyright 2007 Markus Kappeler <markus.kappeler@objectxp.com>
4 * See file CREDITS for list of people who contributed to this
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License as
9 * published by the Free Software Foundation; either version 2 of
10 * the License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
28 #if (CONFIG_COMMANDS & CFG_CMD_BSP)
30 int do_i2c(char *argv[])
32 unsigned char temp, temp1;
34 printf("Starting I2C Test\n"
35 "Please set Jumper:\nI2C SDA 2-3\nI2C SCL 2-3\n\n"
36 "Please press any key to start\n\n");
39 temp = 0xf0; /* set io 0-4 as output */
40 i2c_write(CFG_I2C_IO, 3, 1, (uchar *)&temp, 1);
42 printf("Press I2C4-7. LED I2C0-3 should have the same state\n\n"
43 "Press any key to stop\n\n");
46 i2c_read(CFG_I2C_IO, 0, 1, (uchar *)&temp, 1);
47 temp1 = (temp >> 4) & 0x03;
48 temp1 |= (temp >> 3) & 0x08; /* S302 -> LED303 */
49 temp1 |= (temp >> 5) & 0x04; /* S303 -> LED302 */
51 i2c_write(CFG_I2C_IO, 1, 1, (uchar *)&temp, 1);
58 int do_usbtest(char *argv[])
61 static int usb_stor_curr_dev = -1; /* current device */
63 printf("Starting USB Test\n"
64 "Please insert USB Memmory Stick\n\n"
65 "Please press any key to start\n\n");
69 printf("(Re)start USB...\n");
71 #ifdef CONFIG_USB_STORAGE
72 /* try to recognize storage devices immediately */
74 usb_stor_curr_dev = usb_stor_scan(1);
75 #endif /* CONFIG_USB_STORAGE */
76 if (usb_stor_curr_dev >= 0)
77 printf("Found USB Storage Dev continue with Test...\n");
79 printf("No USB Storage Device detected.. Stop Test\n");
85 printf("stopping USB..\n");
91 int do_led(char *argv[])
94 struct mpc5xxx_gpt_0_7 *gpt = (struct mpc5xxx_gpt_0_7 *)MPC5XXX_GPT;
96 printf("Starting LED Test\n"
97 "Please set Switch S500 all off\n\n"
98 "Please press any key to start\n\n");
101 /* configure timer 2-3 for simple GPIO output High */
102 gpt->gpt2.emsr |= 0x00000034;
103 gpt->gpt3.emsr |= 0x00000034;
105 (*(vu_long *)MPC5XXX_WU_GPIO_ENABLE) |= 0x80000000;
106 (*(vu_long *)MPC5XXX_WU_GPIO_DIR) |= 0x80000000;
107 printf("Please press any key to stop\n\n");
110 (*(vu_long *)MPC5XXX_WU_GPIO_DATA_O) |= 0x80000000;
111 gpt->gpt2.emsr &= ~0x00000010;
112 gpt->gpt3.emsr &= ~0x00000010;
114 (*(vu_long *)MPC5XXX_WU_GPIO_DATA_O) &= ~0x80000000;
115 gpt->gpt2.emsr &= ~0x00000010;
116 gpt->gpt3.emsr |= 0x00000010;
118 (*(vu_long *)MPC5XXX_WU_GPIO_DATA_O) &= ~0x80000000;
119 gpt->gpt3.emsr &= ~0x00000010;
120 gpt->gpt2.emsr |= 0x00000010;
128 (*(vu_long *)MPC5XXX_WU_GPIO_DATA_O) |= 0x80000000;
129 gpt->gpt2.emsr |= 0x00000010;
130 gpt->gpt3.emsr |= 0x00000010;
135 int do_rs232(char *argv[])
137 int error_status = 0;
138 struct mpc5xxx_gpio *gpio = (struct mpc5xxx_gpio *)MPC5XXX_GPIO;
139 struct mpc5xxx_psc *psc1 = (struct mpc5xxx_psc *)MPC5XXX_PSC1;
141 /* Configure PSC 2-3-6 as GPIO */
142 gpio->port_config &= 0xFF0FF80F;
144 switch (simple_strtoul(argv[2], NULL, 10)) {
146 /* check RTS <-> CTS loop */
148 printf("Uart 1 test: RX TX tested by using U-Boot\n"
149 "Please connect RTS with CTS on Uart1 plug\n\n"
150 "Press any key to start\n\n");
155 /* wait some time before requesting status */
158 /* check status at cts */
159 if ((psc1->ip & 0x01) != 0) {
161 printf("%s: failure at rs232_1, cts status is %d "
163 __FUNCTION__, (psc1->ip & 0x01));
169 /* wait some time before requesting status */
172 /* check status at cts */
173 if ((psc1->ip & 0x01) != 1) {
175 printf("%s: failure at rs232_1, cts status is %d "
177 __FUNCTION__, (psc1->ip & 0x01));
181 /* set PSC2_0, PSC2_2 as output and PSC2_1, PSC2_3 as input */
182 printf("Uart 2 test: Please use RS232 Loopback plug on UART2\n"
183 "\nPress any key to start\n\n");
186 gpio->simple_gpioe &= ~(0x000000F0);
187 gpio->simple_gpioe |= 0x000000F0;
188 gpio->simple_ddr &= ~(0x000000F0);
189 gpio->simple_ddr |= 0x00000050;
191 /* check TXD <-> RXD loop */
193 gpio->simple_dvo |= (1 << 4);
195 /* wait some time before requesting status */
198 if ((gpio->simple_ival & 0x00000020) != 0x00000020) {
200 printf("%s: failure at rs232_2, rxd status is %d "
201 "(should be 1)\n", __FUNCTION__,
202 (gpio->simple_ival & 0x00000020) >> 5);
206 gpio->simple_dvo &= ~(1 << 4);
208 /* wait some time before requesting status */
211 if ((gpio->simple_ival & 0x00000020) != 0x00000000) {
213 printf("%s: failure at rs232_2, rxd status is %d "
214 "(should be 0)\n", __FUNCTION__,
215 (gpio->simple_ival & 0x00000020) >> 5);
218 /* check RTS <-> CTS loop */
220 gpio->simple_dvo |= (1 << 6);
222 /* wait some time before requesting status */
225 if ((gpio->simple_ival & 0x00000080) != 0x00000080) {
227 printf("%s: failure at rs232_2, cts status is %d "
228 "(should be 1)\n", __FUNCTION__,
229 (gpio->simple_ival & 0x00000080) >> 7);
233 gpio->simple_dvo &= ~(1 << 6);
235 /* wait some time before requesting status */
238 if ((gpio->simple_ival & 0x00000080) != 0x00000000) {
240 printf("%s: failure at rs232_2, cts status is %d "
241 "(should be 0)\n", __FUNCTION__,
242 (gpio->simple_ival & 0x00000080) >> 7);
246 /* set PSC3_0, PSC3_2 as output and PSC3_1, PSC3_3 as input */
247 printf("Uart 3 test: Please use RS232 Loopback plug on UART2\n"
248 "\nPress any key to start\n\n");
251 gpio->simple_gpioe &= ~(0x00000F00);
252 gpio->simple_gpioe |= 0x00000F00;
254 gpio->simple_ddr &= ~(0x00000F00);
255 gpio->simple_ddr |= 0x00000500;
257 /* check TXD <-> RXD loop */
259 gpio->simple_dvo |= (1 << 8);
261 /* wait some time before requesting status */
264 if ((gpio->simple_ival & 0x00000200) != 0x00000200) {
266 printf("%s: failure at rs232_3, rxd status is %d "
267 "(should be 1)\n", __FUNCTION__,
268 (gpio->simple_ival & 0x00000200) >> 9);
272 gpio->simple_dvo &= ~(1 << 8);
274 /* wait some time before requesting status */
277 if ((gpio->simple_ival & 0x00000200) != 0x00000000) {
279 printf("%s: failure at rs232_3, rxd status is %d "
280 "(should be 0)\n", __FUNCTION__,
281 (gpio->simple_ival & 0x00000200) >> 9);
284 /* check RTS <-> CTS loop */
286 gpio->simple_dvo |= (1 << 10);
288 /* wait some time before requesting status */
291 if ((gpio->simple_ival & 0x00000800) != 0x00000800) {
293 printf("%s: failure at rs232_3, cts status is %d "
294 "(should be 1)\n", __FUNCTION__,
295 (gpio->simple_ival & 0x00000800) >> 11);
299 gpio->simple_dvo &= ~(1 << 10);
301 /* wait some time before requesting status */
304 if ((gpio->simple_ival & 0x00000800) != 0x00000000) {
306 printf("%s: failure at rs232_3, cts status is %d "
307 "(should be 0)\n", __FUNCTION__,
308 (gpio->simple_ival & 0x00000800) >> 11);
312 /* set PSC6_2, PSC6_3 as output and PSC6_0, PSC6_1 as input */
313 printf("Uart 4 test: Please use RS232 Loopback plug on UART2\n"
314 "\nPress any key to start\n\n");
317 gpio->simple_gpioe &= ~(0xF0000000);
318 gpio->simple_gpioe |= 0x30000000;
320 gpio->simple_ddr &= ~(0xf0000000);
321 gpio->simple_ddr |= 0x30000000;
323 (*(vu_long *)MPC5XXX_WU_GPIO_ENABLE) |= 0x30000000;
324 (*(vu_long *)MPC5XXX_WU_GPIO_DIR) &= ~(0x30000000);
326 /* check TXD <-> RXD loop */
328 gpio->simple_dvo |= (1 << 28);
330 /* wait some time before requesting status */
333 if (((*(vu_long *)MPC5XXX_WU_GPIO_DATA_I) & 0x10000000) !=
336 printf("%s: failure at rs232_4, rxd status is %d "
337 "(should be 1)\n", __FUNCTION__,
338 ((*(vu_long *)MPC5XXX_WU_GPIO_DATA_I) &
343 gpio->simple_dvo &= ~(1 << 28);
345 /* wait some time before requesting status */
348 if (((*(vu_long *)MPC5XXX_WU_GPIO_DATA_I) & 0x10000000) !=
351 printf("%s: failure at rs232_4, rxd status is %d "
352 "(should be 0)\n", __FUNCTION__,
353 ((*(vu_long *)MPC5XXX_WU_GPIO_DATA_I) &
357 /* check RTS <-> CTS loop */
359 gpio->simple_dvo |= (1 << 29);
361 /* wait some time before requesting status */
364 if (((*(vu_long *)MPC5XXX_WU_GPIO_DATA_I) & 0x20000000) !=
367 printf("%s: failure at rs232_4, cts status is %d "
368 "(should be 1)\n", __FUNCTION__,
369 ((*(vu_long *)MPC5XXX_WU_GPIO_DATA_I) &
374 gpio->simple_dvo &= ~(1 << 29);
376 /* wait some time before requesting status */
379 if (((*(vu_long *)MPC5XXX_WU_GPIO_DATA_I) & 0x20000000) !=
382 printf("%s: failure at rs232_4, cts status is %d "
383 "(should be 0)\n", __FUNCTION__,
384 ((*(vu_long *)MPC5XXX_WU_GPIO_DATA_I) &
389 printf("%s: invalid rs232 number %s\n", __FUNCTION__, argv[2]);
393 gpio->port_config |= (CFG_GPS_PORT_CONFIG & 0xFF0FF80F);
398 int cmd_fkt(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
404 if (strncmp(argv[1], "i2c", 3) == 0)
405 rcode = do_i2c(argv);
406 else if (strncmp(argv[1], "led", 3) == 0)
407 rcode = do_led(argv);
408 else if (strncmp(argv[1], "usb", 3) == 0)
409 rcode = do_usbtest(argv);
412 if (strncmp(argv[1], "rs232", 3) == 0)
413 rcode = do_rs232(argv);
420 "fkt { i2c | led | usb }\n"
421 "fkt rs232 number\n");
425 printf("Test passed\n");
428 printf("Test failed with code: %d\n", rcode);
436 "fkt - Function test routines\n",
438 " - Test I2C communication\n"
442 " - Test RS232 (loopback plug(s) for RS232 required)\n"
444 " - Test USB communication\n"
446 #endif /* CFG_CMD_BSP */