blob: 9c40ad7b2a2c9fe885916529ab4e0e39090a9142 [file] [log] [blame]
Bartlomiej Siekafa1df302007-07-11 20:11:07 +02001/*
Bartlomiej Sieka86b116b2007-08-03 12:08:16 +02002 * (C) Copyright 2007 Markus Kappeler <markus.kappeler@objectxp.com>
3 *
Wolfgang Denkbe5d72d2007-08-13 21:57:53 +02004 * Adapted for U-Boot 1.2 by Piotr Kruszynski <ppk@semihalf.com>
Bartlomiej Siekafa1df302007-07-11 20:11:07 +02005 *
Wolfgang Denk1a459662013-07-08 09:37:19 +02006 * SPDX-License-Identifier: GPL-2.0+
Bartlomiej Siekafa1df302007-07-11 20:11:07 +02007 */
8
9#include <common.h>
10#include <command.h>
11#include <i2c.h>
12#include <usb.h>
13
Bartlomiej Sieka6e7b7b62007-09-13 18:21:48 +020014#ifdef CONFIG_CMD_BSP
Bartlomiej Siekafa1df302007-07-11 20:11:07 +020015
Wolfgang Denk54841ab2010-06-28 22:00:46 +020016static int do_i2c_test(char * const argv[])
Bartlomiej Siekafa1df302007-07-11 20:11:07 +020017{
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 */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020026 i2c_write(CONFIG_SYS_I2C_IO, 3, 1, (uchar *)&temp, 1);
Bartlomiej Siekafa1df302007-07-11 20:11:07 +020027
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()) {
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020032 i2c_read(CONFIG_SYS_I2C_IO, 0, 1, (uchar *)&temp, 1);
Bartlomiej Siekafa1df302007-07-11 20:11:07 +020033 temp1 = (temp >> 4) & 0x03;
34 temp1 |= (temp >> 3) & 0x08; /* S302 -> LED303 */
35 temp1 |= (temp >> 5) & 0x04; /* S303 -> LED302 */
36 temp = temp1;
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020037 i2c_write(CONFIG_SYS_I2C_IO, 1, 1, (uchar *)&temp, 1);
Bartlomiej Siekafa1df302007-07-11 20:11:07 +020038 }
39 getc();
40
41 return 0;
42}
43
Wolfgang Denk54841ab2010-06-28 22:00:46 +020044static int do_usb_test(char * const argv[])
Bartlomiej Siekafa1df302007-07-11 20:11:07 +020045{
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
Wolfgang Denk54841ab2010-06-28 22:00:46 +020077static int do_led_test(char * const argv[])
Bartlomiej Siekafa1df302007-07-11 20:11:07 +020078{
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
Wolfgang Denk54841ab2010-06-28 22:00:46 +0200121static int do_rs232_test(char * const argv[])
Bartlomiej Siekafa1df302007-07-11 20:11:07 +0200122{
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;
Wolfgang Denk9b55a252008-07-11 01:16:00 +0200322 printf("%s: failure at rs232_4, rxd status is %lu "
Bartlomiej Siekafa1df302007-07-11 20:11:07 +0200323 "(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;
Wolfgang Denk9b55a252008-07-11 01:16:00 +0200337 printf("%s: failure at rs232_4, rxd status is %lu "
Bartlomiej Siekafa1df302007-07-11 20:11:07 +0200338 "(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;
Wolfgang Denk9b55a252008-07-11 01:16:00 +0200353 printf("%s: failure at rs232_4, cts status is %lu "
Bartlomiej Siekafa1df302007-07-11 20:11:07 +0200354 "(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;
Wolfgang Denk9b55a252008-07-11 01:16:00 +0200368 printf("%s: failure at rs232_4, cts status is %lu "
Bartlomiej Siekafa1df302007-07-11 20:11:07 +0200369 "(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 }
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200379 gpio->port_config |= (CONFIG_SYS_GPS_PORT_CONFIG & 0xFF0FF80F);
Bartlomiej Siekafa1df302007-07-11 20:11:07 +0200380
381 return error_status;
382}
383
Wolfgang Denk54841ab2010-06-28 22:00:46 +0200384static int cmd_fkt(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
Bartlomiej Siekafa1df302007-07-11 20:11:07 +0200385{
386 int rcode = -1;
387
388 switch (argc) {
389 case 2:
390 if (strncmp(argv[1], "i2c", 3) == 0)
Peter Tyser8229e9c2009-04-18 22:34:00 -0500391 rcode = do_i2c_test(argv);
Bartlomiej Siekafa1df302007-07-11 20:11:07 +0200392 else if (strncmp(argv[1], "led", 3) == 0)
Peter Tyser8229e9c2009-04-18 22:34:00 -0500393 rcode = do_led_test(argv);
Bartlomiej Siekafa1df302007-07-11 20:11:07 +0200394 else if (strncmp(argv[1], "usb", 3) == 0)
Peter Tyser8229e9c2009-04-18 22:34:00 -0500395 rcode = do_usb_test(argv);
Bartlomiej Siekafa1df302007-07-11 20:11:07 +0200396 break;
397 case 3:
398 if (strncmp(argv[1], "rs232", 3) == 0)
Peter Tyser8229e9c2009-04-18 22:34:00 -0500399 rcode = do_rs232_test(argv);
Bartlomiej Siekafa1df302007-07-11 20:11:07 +0200400 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
420U_BOOT_CMD(
421 fkt, 4, 1, cmd_fkt,
Peter Tyser2fb26042009-01-27 18:03:12 -0600422 "Function test routines",
Bartlomiej Siekafa1df302007-07-11 20:11:07 +0200423 "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"
Wolfgang Denka89c33d2009-05-24 17:06:54 +0200430 " - Test USB communication"
Bartlomiej Siekafa1df302007-07-11 20:11:07 +0200431);
Wolfgang Denkafaac862007-08-12 14:27:39 +0200432#endif /* CONFIG_CMD_BSP */