blob: 4a01d2a7f4c60f7d41a9e75edeab0eeffd4903ea [file] [log] [blame]
Bartlomiej Sieka087415c2007-07-11 20:11:07 +02001/*
2 * (C) Copyright 2007 Markus Kappeler <markus.kappeler@objectxp.com>
3 *
4 * See file CREDITS for list of people who contributed to this
5 * project.
6 *
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.
11 *
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.
16 *
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,
20 * MA 02111-1307 USA
21 */
22
23#include <common.h>
24#include <command.h>
25#include <i2c.h>
26#include <usb.h>
27
28#if (CONFIG_COMMANDS & CFG_CMD_BSP)
29
30int do_i2c(char *argv[])
31{
32 unsigned char temp, temp1;
33
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");
37 getc();
38
39 temp = 0xf0; /* set io 0-4 as output */
40 i2c_write(CFG_I2C_IO, 3, 1, (uchar *)&temp, 1);
41
42 printf("Press I2C4-7. LED I2C0-3 should have the same state\n\n"
43 "Press any key to stop\n\n");
44
45 while (!tstc()) {
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 */
50 temp = temp1;
51 i2c_write(CFG_I2C_IO, 1, 1, (uchar *)&temp, 1);
52 }
53 getc();
54
55 return 0;
56}
57
58int do_usbtest(char *argv[])
59{
60 int i;
61 static int usb_stor_curr_dev = -1; /* current device */
62
63 printf("Starting USB Test\n"
64 "Please insert USB Memmory Stick\n\n"
65 "Please press any key to start\n\n");
66 getc();
67
68 usb_stop();
69 printf("(Re)start USB...\n");
70 i = usb_init();
71#ifdef CONFIG_USB_STORAGE
72 /* try to recognize storage devices immediately */
73 if (i >= 0)
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");
78 else {
79 printf("No USB Storage Device detected.. Stop Test\n");
80 return 1;
81 }
82
83 usb_stor_info();
84
85 printf("stopping USB..\n");
86 usb_stop();
87
88 return 0;
89}
90
91int do_led(char *argv[])
92{
93 int i = 0;
94 struct mpc5xxx_gpt_0_7 *gpt = (struct mpc5xxx_gpt_0_7 *)MPC5XXX_GPT;
95
96 printf("Starting LED Test\n"
97 "Please set Switch S500 all off\n\n"
98 "Please press any key to start\n\n");
99 getc();
100
101 /* configure timer 2-3 for simple GPIO output High */
102 gpt->gpt2.emsr |= 0x00000034;
103 gpt->gpt3.emsr |= 0x00000034;
104
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");
108 while (!tstc()) {
109 if (i == 1) {
110 (*(vu_long *)MPC5XXX_WU_GPIO_DATA_O) |= 0x80000000;
111 gpt->gpt2.emsr &= ~0x00000010;
112 gpt->gpt3.emsr &= ~0x00000010;
113 } else if (i == 2) {
114 (*(vu_long *)MPC5XXX_WU_GPIO_DATA_O) &= ~0x80000000;
115 gpt->gpt2.emsr &= ~0x00000010;
116 gpt->gpt3.emsr |= 0x00000010;
117 } else if (i >= 3) {
118 (*(vu_long *)MPC5XXX_WU_GPIO_DATA_O) &= ~0x80000000;
119 gpt->gpt3.emsr &= ~0x00000010;
120 gpt->gpt2.emsr |= 0x00000010;
121 i = 0;
122 }
123 i++;
124 udelay(200000);
125 }
126 getc();
127
128 (*(vu_long *)MPC5XXX_WU_GPIO_DATA_O) |= 0x80000000;
129 gpt->gpt2.emsr |= 0x00000010;
130 gpt->gpt3.emsr |= 0x00000010;
131
132 return 0;
133}
134
135int do_rs232(char *argv[])
136{
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;
140
141 /* Configure PSC 2-3-6 as GPIO */
142 gpio->port_config &= 0xFF0FF80F;
143
144 switch (simple_strtoul(argv[2], NULL, 10)) {
145 case 1:
146 /* check RTS <-> CTS loop */
147 /* set rts to 0 */
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");
151 getc();
152
153 psc1->op1 |= 0x01;
154
155 /* wait some time before requesting status */
156 udelay(10);
157
158 /* check status at cts */
159 if ((psc1->ip & 0x01) != 0) {
160 error_status = 3;
161 printf("%s: failure at rs232_1, cts status is %d "
162 "(should be 0)\n",
163 __FUNCTION__, (psc1->ip & 0x01));
164 }
165
166 /* set rts to 1 */
167 psc1->op0 |= 0x01;
168
169 /* wait some time before requesting status */
170 udelay(10);
171
172 /* check status at cts */
173 if ((psc1->ip & 0x01) != 1) {
174 error_status = 3;
175 printf("%s: failure at rs232_1, cts status is %d "
176 "(should be 1)\n",
177 __FUNCTION__, (psc1->ip & 0x01));
178 }
179 break;
180 case 2:
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");
184 getc();
185
186 gpio->simple_gpioe &= ~(0x000000F0);
187 gpio->simple_gpioe |= 0x000000F0;
188 gpio->simple_ddr &= ~(0x000000F0);
189 gpio->simple_ddr |= 0x00000050;
190
191 /* check TXD <-> RXD loop */
192 /* set TXD to 1 */
193 gpio->simple_dvo |= (1 << 4);
194
195 /* wait some time before requesting status */
196 udelay(10);
197
198 if ((gpio->simple_ival & 0x00000020) != 0x00000020) {
199 error_status = 2;
200 printf("%s: failure at rs232_2, rxd status is %d "
201 "(should be 1)\n", __FUNCTION__,
202 (gpio->simple_ival & 0x00000020) >> 5);
203 }
204
205 /* set TXD to 0 */
206 gpio->simple_dvo &= ~(1 << 4);
207
208 /* wait some time before requesting status */
209 udelay(10);
210
211 if ((gpio->simple_ival & 0x00000020) != 0x00000000) {
212 error_status = 2;
213 printf("%s: failure at rs232_2, rxd status is %d "
214 "(should be 0)\n", __FUNCTION__,
215 (gpio->simple_ival & 0x00000020) >> 5);
216 }
217
218 /* check RTS <-> CTS loop */
219 /* set RTS to 1 */
220 gpio->simple_dvo |= (1 << 6);
221
222 /* wait some time before requesting status */
223 udelay(10);
224
225 if ((gpio->simple_ival & 0x00000080) != 0x00000080) {
226 error_status = 3;
227 printf("%s: failure at rs232_2, cts status is %d "
228 "(should be 1)\n", __FUNCTION__,
229 (gpio->simple_ival & 0x00000080) >> 7);
230 }
231
232 /* set RTS to 0 */
233 gpio->simple_dvo &= ~(1 << 6);
234
235 /* wait some time before requesting status */
236 udelay(10);
237
238 if ((gpio->simple_ival & 0x00000080) != 0x00000000) {
239 error_status = 3;
240 printf("%s: failure at rs232_2, cts status is %d "
241 "(should be 0)\n", __FUNCTION__,
242 (gpio->simple_ival & 0x00000080) >> 7);
243 }
244 break;
245 case 3:
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");
249 getc();
250
251 gpio->simple_gpioe &= ~(0x00000F00);
252 gpio->simple_gpioe |= 0x00000F00;
253
254 gpio->simple_ddr &= ~(0x00000F00);
255 gpio->simple_ddr |= 0x00000500;
256
257 /* check TXD <-> RXD loop */
258 /* set TXD to 1 */
259 gpio->simple_dvo |= (1 << 8);
260
261 /* wait some time before requesting status */
262 udelay(10);
263
264 if ((gpio->simple_ival & 0x00000200) != 0x00000200) {
265 error_status = 2;
266 printf("%s: failure at rs232_3, rxd status is %d "
267 "(should be 1)\n", __FUNCTION__,
268 (gpio->simple_ival & 0x00000200) >> 9);
269 }
270
271 /* set TXD to 0 */
272 gpio->simple_dvo &= ~(1 << 8);
273
274 /* wait some time before requesting status */
275 udelay(10);
276
277 if ((gpio->simple_ival & 0x00000200) != 0x00000000) {
278 error_status = 2;
279 printf("%s: failure at rs232_3, rxd status is %d "
280 "(should be 0)\n", __FUNCTION__,
281 (gpio->simple_ival & 0x00000200) >> 9);
282 }
283
284 /* check RTS <-> CTS loop */
285 /* set RTS to 1 */
286 gpio->simple_dvo |= (1 << 10);
287
288 /* wait some time before requesting status */
289 udelay(10);
290
291 if ((gpio->simple_ival & 0x00000800) != 0x00000800) {
292 error_status = 3;
293 printf("%s: failure at rs232_3, cts status is %d "
294 "(should be 1)\n", __FUNCTION__,
295 (gpio->simple_ival & 0x00000800) >> 11);
296 }
297
298 /* set RTS to 0 */
299 gpio->simple_dvo &= ~(1 << 10);
300
301 /* wait some time before requesting status */
302 udelay(10);
303
304 if ((gpio->simple_ival & 0x00000800) != 0x00000000) {
305 error_status = 3;
306 printf("%s: failure at rs232_3, cts status is %d "
307 "(should be 0)\n", __FUNCTION__,
308 (gpio->simple_ival & 0x00000800) >> 11);
309 }
310 break;
311 case 4:
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");
315 getc();
316
317 gpio->simple_gpioe &= ~(0xF0000000);
318 gpio->simple_gpioe |= 0x30000000;
319
320 gpio->simple_ddr &= ~(0xf0000000);
321 gpio->simple_ddr |= 0x30000000;
322
323 (*(vu_long *)MPC5XXX_WU_GPIO_ENABLE) |= 0x30000000;
324 (*(vu_long *)MPC5XXX_WU_GPIO_DIR) &= ~(0x30000000);
325
326 /* check TXD <-> RXD loop */
327 /* set TXD to 1 */
328 gpio->simple_dvo |= (1 << 28);
329
330 /* wait some time before requesting status */
331 udelay(10);
332
333 if (((*(vu_long *)MPC5XXX_WU_GPIO_DATA_I) & 0x10000000) !=
334 0x10000000) {
335 error_status = 2;
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) &
339 0x10000000) >> 28);
340 }
341
342 /* set TXD to 0 */
343 gpio->simple_dvo &= ~(1 << 28);
344
345 /* wait some time before requesting status */
346 udelay(10);
347
348 if (((*(vu_long *)MPC5XXX_WU_GPIO_DATA_I) & 0x10000000) !=
349 0x00000000) {
350 error_status = 2;
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) &
354 0x10000000) >> 28);
355 }
356
357 /* check RTS <-> CTS loop */
358 /* set RTS to 1 */
359 gpio->simple_dvo |= (1 << 29);
360
361 /* wait some time before requesting status */
362 udelay(10);
363
364 if (((*(vu_long *)MPC5XXX_WU_GPIO_DATA_I) & 0x20000000) !=
365 0x20000000) {
366 error_status = 3;
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) &
370 0x20000000) >> 29);
371 }
372
373 /* set RTS to 0 */
374 gpio->simple_dvo &= ~(1 << 29);
375
376 /* wait some time before requesting status */
377 udelay(10);
378
379 if (((*(vu_long *)MPC5XXX_WU_GPIO_DATA_I) & 0x20000000) !=
380 0x00000000) {
381 error_status = 3;
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) &
385 0x20000000) >> 29);
386 }
387 break;
388 default:
389 printf("%s: invalid rs232 number %s\n", __FUNCTION__, argv[2]);
390 error_status = 1;
391 break;
392 }
393 gpio->port_config |= (CFG_GPS_PORT_CONFIG & 0xFF0FF80F);
394
395 return error_status;
396}
397
398int cmd_fkt(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
399{
400 int rcode = -1;
401
402 switch (argc) {
403 case 2:
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);
410 break;
411 case 3:
412 if (strncmp(argv[1], "rs232", 3) == 0)
413 rcode = do_rs232(argv);
414 break;
415 }
416
417 switch (rcode) {
418 case -1:
419 printf("Usage:\n"
420 "fkt { i2c | led | usb }\n"
421 "fkt rs232 number\n");
422 rcode = 1;
423 break;
424 case 0:
425 printf("Test passed\n");
426 break;
427 default:
428 printf("Test failed with code: %d\n", rcode);
429 }
430
431 return rcode;
432}
433
434U_BOOT_CMD(
435 fkt, 4, 1, cmd_fkt,
436 "fkt - Function test routines\n",
437 "i2c\n"
438 " - Test I2C communication\n"
439 "fkt led\n"
440 " - Test LEDs\n"
441 "fkt rs232 number\n"
442 " - Test RS232 (loopback plug(s) for RS232 required)\n"
443 "fkt usb\n"
444 " - Test USB communication\n"
445);
446#endif /* CFG_CMD_BSP */