blob: 513c365537227937ad29d89f795768032675810f [file] [log] [blame]
Bartlomiej Sieka087415c2007-07-11 20:11:07 +02001/*
Bartlomiej Siekaa6533c82007-08-03 12:08:16 +02002 * (C) Copyright 2007 Markus Kappeler <markus.kappeler@objectxp.com>
3 *
Wolfgang Denk36882932007-08-13 21:57:53 +02004 * Adapted for U-Boot 1.2 by Piotr Kruszynski <ppk@semihalf.com>
Bartlomiej Sieka087415c2007-07-11 20:11:07 +02005 *
6 * See file CREDITS for list of people who contributed to this
7 * project.
8 *
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.
13 *
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.
18 *
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,
22 * MA 02111-1307 USA
23 */
24
25#include <common.h>
26#include <command.h>
27#include <i2c.h>
28#include <usb.h>
29
Wolfgang Denk56cbd022007-08-12 14:27:39 +020030#ifdef CONFIG_CMD_BSB
Bartlomiej Sieka087415c2007-07-11 20:11:07 +020031
32int do_i2c(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; /* set io 0-4 as output */
42 i2c_write(CFG_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(CFG_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 */
52 temp = temp1;
53 i2c_write(CFG_I2C_IO, 1, 1, (uchar *)&temp, 1);
54 }
55 getc();
56
57 return 0;
58}
59
60int do_usbtest(char *argv[])
61{
62 int i;
63 static int usb_stor_curr_dev = -1; /* current device */
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 /* try to recognize storage devices immediately */
75 if (i >= 0)
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");
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
93int do_led(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 /* configure timer 2-3 for simple GPIO output High */
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
137int do_rs232(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 /* Configure PSC 2-3-6 as GPIO */
144 gpio->port_config &= 0xFF0FF80F;
145
146 switch (simple_strtoul(argv[2], NULL, 10)) {
147 case 1:
148 /* check RTS <-> CTS loop */
149 /* set rts to 0 */
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 /* wait some time before requesting status */
158 udelay(10);
159
160 /* check status at cts */
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 /* set rts to 1 */
169 psc1->op0 |= 0x01;
170
171 /* wait some time before requesting status */
172 udelay(10);
173
174 /* check status at cts */
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 /* 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");
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 /* check TXD <-> RXD loop */
194 /* set TXD to 1 */
195 gpio->simple_dvo |= (1 << 4);
196
197 /* wait some time before requesting status */
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 /* set TXD to 0 */
208 gpio->simple_dvo &= ~(1 << 4);
209
210 /* wait some time before requesting status */
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 /* check RTS <-> CTS loop */
221 /* set RTS to 1 */
222 gpio->simple_dvo |= (1 << 6);
223
224 /* wait some time before requesting status */
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 /* set RTS to 0 */
235 gpio->simple_dvo &= ~(1 << 6);
236
237 /* wait some time before requesting status */
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 /* 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");
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 /* check TXD <-> RXD loop */
260 /* set TXD to 1 */
261 gpio->simple_dvo |= (1 << 8);
262
263 /* wait some time before requesting status */
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 /* set TXD to 0 */
274 gpio->simple_dvo &= ~(1 << 8);
275
276 /* wait some time before requesting status */
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 /* check RTS <-> CTS loop */
287 /* set RTS to 1 */
288 gpio->simple_dvo |= (1 << 10);
289
290 /* wait some time before requesting status */
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 /* set RTS to 0 */
301 gpio->simple_dvo &= ~(1 << 10);
302
303 /* wait some time before requesting status */
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 /* 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");
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 /* check TXD <-> RXD loop */
329 /* set TXD to 1 */
330 gpio->simple_dvo |= (1 << 28);
331
332 /* wait some time before requesting status */
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 %d "
339 "(should be 1)\n", __FUNCTION__,
340 ((*(vu_long *)MPC5XXX_WU_GPIO_DATA_I) &
341 0x10000000) >> 28);
342 }
343
344 /* set TXD to 0 */
345 gpio->simple_dvo &= ~(1 << 28);
346
347 /* wait some time before requesting status */
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 %d "
354 "(should be 0)\n", __FUNCTION__,
355 ((*(vu_long *)MPC5XXX_WU_GPIO_DATA_I) &
356 0x10000000) >> 28);
357 }
358
359 /* check RTS <-> CTS loop */
360 /* set RTS to 1 */
361 gpio->simple_dvo |= (1 << 29);
362
363 /* wait some time before requesting status */
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 %d "
370 "(should be 1)\n", __FUNCTION__,
371 ((*(vu_long *)MPC5XXX_WU_GPIO_DATA_I) &
372 0x20000000) >> 29);
373 }
374
375 /* set RTS to 0 */
376 gpio->simple_dvo &= ~(1 << 29);
377
378 /* wait some time before requesting status */
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 %d "
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 |= (CFG_GPS_PORT_CONFIG & 0xFF0FF80F);
396
397 return error_status;
398}
399
400int 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(argv);
408 else if (strncmp(argv[1], "led", 3) == 0)
409 rcode = do_led(argv);
410 else if (strncmp(argv[1], "usb", 3) == 0)
411 rcode = do_usbtest(argv);
412 break;
413 case 3:
414 if (strncmp(argv[1], "rs232", 3) == 0)
415 rcode = do_rs232(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 "fkt - Function test routines\n",
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\n"
447);
Wolfgang Denk56cbd022007-08-12 14:27:39 +0200448#endif /* CONFIG_CMD_BSP */