1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25#include <common.h>
26#include <command.h>
27#include <i2c.h>
28#include <usb.h>
29
30#ifdef CONFIG_CMD_BSP
31
32static int do_i2c_test(char *argv[])
33{
34 unsigned char temp, temp1;
35
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");
39 getc();
40
41 temp = 0xf0;
42 i2c_write(CONFIG_SYS_I2C_IO, 3, 1, (uchar *)&temp, 1);
43
44 printf("Press I2C4-7. LED I2C0-3 should have the same state\n\n"
45 "Press any key to stop\n\n");
46
47 while (!tstc()) {
48 i2c_read(CONFIG_SYS_I2C_IO, 0, 1, (uchar *)&temp, 1);
49 temp1 = (temp >> 4) & 0x03;
50 temp1 |= (temp >> 3) & 0x08;
51 temp1 |= (temp >> 5) & 0x04;
52 temp = temp1;
53 i2c_write(CONFIG_SYS_I2C_IO, 1, 1, (uchar *)&temp, 1);
54 }
55 getc();
56
57 return 0;
58}
59
60static int do_usb_test(char *argv[])
61{
62 int i;
63 static int usb_stor_curr_dev = -1;
64
65 printf("Starting USB Test\n"
66 "Please insert USB Memmory Stick\n\n"
67 "Please press any key to start\n\n");
68 getc();
69
70 usb_stop();
71 printf("(Re)start USB...\n");
72 i = usb_init();
73#ifdef CONFIG_USB_STORAGE
74
75 if (i >= 0)
76 usb_stor_curr_dev = usb_stor_scan(1);
77#endif
78 if (usb_stor_curr_dev >= 0)
79 printf("Found USB Storage Dev continue with Test...\n");
80 else {
81 printf("No USB Storage Device detected.. Stop Test\n");
82 return 1;
83 }
84
85 usb_stor_info();
86
87 printf("stopping USB..\n");
88 usb_stop();
89
90 return 0;
91}
92
93static int do_led_test(char *argv[])
94{
95 int i = 0;
96 struct mpc5xxx_gpt_0_7 *gpt = (struct mpc5xxx_gpt_0_7 *)MPC5XXX_GPT;
97
98 printf("Starting LED Test\n"
99 "Please set Switch S500 all off\n\n"
100 "Please press any key to start\n\n");
101 getc();
102
103
104 gpt->gpt2.emsr |= 0x00000034;
105 gpt->gpt3.emsr |= 0x00000034;
106
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");
110 while (!tstc()) {
111 if (i == 1) {
112 (*(vu_long *)MPC5XXX_WU_GPIO_DATA_O) |= 0x80000000;
113 gpt->gpt2.emsr &= ~0x00000010;
114 gpt->gpt3.emsr &= ~0x00000010;
115 } else if (i == 2) {
116 (*(vu_long *)MPC5XXX_WU_GPIO_DATA_O) &= ~0x80000000;
117 gpt->gpt2.emsr &= ~0x00000010;
118 gpt->gpt3.emsr |= 0x00000010;
119 } else if (i >= 3) {
120 (*(vu_long *)MPC5XXX_WU_GPIO_DATA_O) &= ~0x80000000;
121 gpt->gpt3.emsr &= ~0x00000010;
122 gpt->gpt2.emsr |= 0x00000010;
123 i = 0;
124 }
125 i++;
126 udelay(200000);
127 }
128 getc();
129
130 (*(vu_long *)MPC5XXX_WU_GPIO_DATA_O) |= 0x80000000;
131 gpt->gpt2.emsr |= 0x00000010;
132 gpt->gpt3.emsr |= 0x00000010;
133
134 return 0;
135}
136
137static int do_rs232_test(char *argv[])
138{
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;
142
143
144 gpio->port_config &= 0xFF0FF80F;
145
146 switch (simple_strtoul(argv[2], NULL, 10)) {
147 case 1:
148
149
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");
153 getc();
154
155 psc1->op1 |= 0x01;
156
157
158 udelay(10);
159
160
161 if ((psc1->ip & 0x01) != 0) {
162 error_status = 3;
163 printf("%s: failure at rs232_1, cts status is %d "
164 "(should be 0)\n",
165 __FUNCTION__, (psc1->ip & 0x01));
166 }
167
168
169 psc1->op0 |= 0x01;
170
171
172 udelay(10);
173
174
175 if ((psc1->ip & 0x01) != 1) {
176 error_status = 3;
177 printf("%s: failure at rs232_1, cts status is %d "
178 "(should be 1)\n",
179 __FUNCTION__, (psc1->ip & 0x01));
180 }
181 break;
182 case 2:
183
184 printf("Uart 2 test: Please use RS232 Loopback plug on UART2\n"
185 "\nPress any key to start\n\n");
186 getc();
187
188 gpio->simple_gpioe &= ~(0x000000F0);
189 gpio->simple_gpioe |= 0x000000F0;
190 gpio->simple_ddr &= ~(0x000000F0);
191 gpio->simple_ddr |= 0x00000050;
192
193
194
195 gpio->simple_dvo |= (1 << 4);
196
197
198 udelay(10);
199
200 if ((gpio->simple_ival & 0x00000020) != 0x00000020) {
201 error_status = 2;
202 printf("%s: failure at rs232_2, rxd status is %d "
203 "(should be 1)\n", __FUNCTION__,
204 (gpio->simple_ival & 0x00000020) >> 5);
205 }
206
207
208 gpio->simple_dvo &= ~(1 << 4);
209
210
211 udelay(10);
212
213 if ((gpio->simple_ival & 0x00000020) != 0x00000000) {
214 error_status = 2;
215 printf("%s: failure at rs232_2, rxd status is %d "
216 "(should be 0)\n", __FUNCTION__,
217 (gpio->simple_ival & 0x00000020) >> 5);
218 }
219
220
221
222 gpio->simple_dvo |= (1 << 6);
223
224
225 udelay(10);
226
227 if ((gpio->simple_ival & 0x00000080) != 0x00000080) {
228 error_status = 3;
229 printf("%s: failure at rs232_2, cts status is %d "
230 "(should be 1)\n", __FUNCTION__,
231 (gpio->simple_ival & 0x00000080) >> 7);
232 }
233
234
235 gpio->simple_dvo &= ~(1 << 6);
236
237
238 udelay(10);
239
240 if ((gpio->simple_ival & 0x00000080) != 0x00000000) {
241 error_status = 3;
242 printf("%s: failure at rs232_2, cts status is %d "
243 "(should be 0)\n", __FUNCTION__,
244 (gpio->simple_ival & 0x00000080) >> 7);
245 }
246 break;
247 case 3:
248
249 printf("Uart 3 test: Please use RS232 Loopback plug on UART2\n"
250 "\nPress any key to start\n\n");
251 getc();
252
253 gpio->simple_gpioe &= ~(0x00000F00);
254 gpio->simple_gpioe |= 0x00000F00;
255
256 gpio->simple_ddr &= ~(0x00000F00);
257 gpio->simple_ddr |= 0x00000500;
258
259
260
261 gpio->simple_dvo |= (1 << 8);
262
263
264 udelay(10);
265
266 if ((gpio->simple_ival & 0x00000200) != 0x00000200) {
267 error_status = 2;
268 printf("%s: failure at rs232_3, rxd status is %d "
269 "(should be 1)\n", __FUNCTION__,
270 (gpio->simple_ival & 0x00000200) >> 9);
271 }
272
273
274 gpio->simple_dvo &= ~(1 << 8);
275
276
277 udelay(10);
278
279 if ((gpio->simple_ival & 0x00000200) != 0x00000000) {
280 error_status = 2;
281 printf("%s: failure at rs232_3, rxd status is %d "
282 "(should be 0)\n", __FUNCTION__,
283 (gpio->simple_ival & 0x00000200) >> 9);
284 }
285
286
287
288 gpio->simple_dvo |= (1 << 10);
289
290
291 udelay(10);
292
293 if ((gpio->simple_ival & 0x00000800) != 0x00000800) {
294 error_status = 3;
295 printf("%s: failure at rs232_3, cts status is %d "
296 "(should be 1)\n", __FUNCTION__,
297 (gpio->simple_ival & 0x00000800) >> 11);
298 }
299
300
301 gpio->simple_dvo &= ~(1 << 10);
302
303
304 udelay(10);
305
306 if ((gpio->simple_ival & 0x00000800) != 0x00000000) {
307 error_status = 3;
308 printf("%s: failure at rs232_3, cts status is %d "
309 "(should be 0)\n", __FUNCTION__,
310 (gpio->simple_ival & 0x00000800) >> 11);
311 }
312 break;
313 case 4:
314
315 printf("Uart 4 test: Please use RS232 Loopback plug on UART2\n"
316 "\nPress any key to start\n\n");
317 getc();
318
319 gpio->simple_gpioe &= ~(0xF0000000);
320 gpio->simple_gpioe |= 0x30000000;
321
322 gpio->simple_ddr &= ~(0xf0000000);
323 gpio->simple_ddr |= 0x30000000;
324
325 (*(vu_long *)MPC5XXX_WU_GPIO_ENABLE) |= 0x30000000;
326 (*(vu_long *)MPC5XXX_WU_GPIO_DIR) &= ~(0x30000000);
327
328
329
330 gpio->simple_dvo |= (1 << 28);
331
332
333 udelay(10);
334
335 if (((*(vu_long *)MPC5XXX_WU_GPIO_DATA_I) & 0x10000000) !=
336 0x10000000) {
337 error_status = 2;
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) &
341 0x10000000) >> 28);
342 }
343
344
345 gpio->simple_dvo &= ~(1 << 28);
346
347
348 udelay(10);
349
350 if (((*(vu_long *)MPC5XXX_WU_GPIO_DATA_I) & 0x10000000) !=
351 0x00000000) {
352 error_status = 2;
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) &
356 0x10000000) >> 28);
357 }
358
359
360
361 gpio->simple_dvo |= (1 << 29);
362
363
364 udelay(10);
365
366 if (((*(vu_long *)MPC5XXX_WU_GPIO_DATA_I) & 0x20000000) !=
367 0x20000000) {
368 error_status = 3;
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) &
372 0x20000000) >> 29);
373 }
374
375
376 gpio->simple_dvo &= ~(1 << 29);
377
378
379 udelay(10);
380
381 if (((*(vu_long *)MPC5XXX_WU_GPIO_DATA_I) & 0x20000000) !=
382 0x00000000) {
383 error_status = 3;
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) &
387 0x20000000) >> 29);
388 }
389 break;
390 default:
391 printf("%s: invalid rs232 number %s\n", __FUNCTION__, argv[2]);
392 error_status = 1;
393 break;
394 }
395 gpio->port_config |= (CONFIG_SYS_GPS_PORT_CONFIG & 0xFF0FF80F);
396
397 return error_status;
398}
399
400static int cmd_fkt(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
401{
402 int rcode = -1;
403
404 switch (argc) {
405 case 2:
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);
412 break;
413 case 3:
414 if (strncmp(argv[1], "rs232", 3) == 0)
415 rcode = do_rs232_test(argv);
416 break;
417 }
418
419 switch (rcode) {
420 case -1:
421 printf("Usage:\n"
422 "fkt { i2c | led | usb }\n"
423 "fkt rs232 number\n");
424 rcode = 1;
425 break;
426 case 0:
427 printf("Test passed\n");
428 break;
429 default:
430 printf("Test failed with code: %d\n", rcode);
431 }
432
433 return rcode;
434}
435
436U_BOOT_CMD(
437 fkt, 4, 1, cmd_fkt,
438 "Function test routines",
439 "i2c\n"
440 " - Test I2C communication\n"
441 "fkt led\n"
442 " - Test LEDs\n"
443 "fkt rs232 number\n"
444 " - Test RS232 (loopback plug(s) for RS232 required)\n"
445 "fkt usb\n"
446 " - Test USB communication"
447);
448#endif
449