Bartlomiej Sieka | fa1df30 | 2007-07-11 20:11:07 +0200 | [diff] [blame] | 1 | /* |
Bartlomiej Sieka | 86b116b | 2007-08-03 12:08:16 +0200 | [diff] [blame] | 2 | * (C) Copyright 2007 Markus Kappeler <markus.kappeler@objectxp.com> |
| 3 | * |
Wolfgang Denk | be5d72d | 2007-08-13 21:57:53 +0200 | [diff] [blame] | 4 | * Adapted for U-Boot 1.2 by Piotr Kruszynski <ppk@semihalf.com> |
Bartlomiej Sieka | fa1df30 | 2007-07-11 20:11:07 +0200 | [diff] [blame] | 5 | * |
Wolfgang Denk | 1a45966 | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 6 | * SPDX-License-Identifier: GPL-2.0+ |
Bartlomiej Sieka | fa1df30 | 2007-07-11 20:11:07 +0200 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | #include <common.h> |
| 10 | #include <command.h> |
| 11 | #include <i2c.h> |
| 12 | #include <usb.h> |
| 13 | |
Bartlomiej Sieka | 6e7b7b6 | 2007-09-13 18:21:48 +0200 | [diff] [blame] | 14 | #ifdef CONFIG_CMD_BSP |
Bartlomiej Sieka | fa1df30 | 2007-07-11 20:11:07 +0200 | [diff] [blame] | 15 | |
Wolfgang Denk | 54841ab | 2010-06-28 22:00:46 +0200 | [diff] [blame] | 16 | static int do_usb_test(char * const argv[]) |
Bartlomiej Sieka | fa1df30 | 2007-07-11 20:11:07 +0200 | [diff] [blame] | 17 | { |
| 18 | int i; |
| 19 | static int usb_stor_curr_dev = -1; /* current device */ |
| 20 | |
| 21 | printf("Starting USB Test\n" |
| 22 | "Please insert USB Memmory Stick\n\n" |
| 23 | "Please press any key to start\n\n"); |
| 24 | getc(); |
| 25 | |
| 26 | usb_stop(); |
| 27 | printf("(Re)start USB...\n"); |
| 28 | i = usb_init(); |
| 29 | #ifdef CONFIG_USB_STORAGE |
| 30 | /* try to recognize storage devices immediately */ |
| 31 | if (i >= 0) |
| 32 | usb_stor_curr_dev = usb_stor_scan(1); |
| 33 | #endif /* CONFIG_USB_STORAGE */ |
| 34 | if (usb_stor_curr_dev >= 0) |
| 35 | printf("Found USB Storage Dev continue with Test...\n"); |
| 36 | else { |
| 37 | printf("No USB Storage Device detected.. Stop Test\n"); |
| 38 | return 1; |
| 39 | } |
| 40 | |
| 41 | usb_stor_info(); |
| 42 | |
| 43 | printf("stopping USB..\n"); |
| 44 | usb_stop(); |
| 45 | |
| 46 | return 0; |
| 47 | } |
| 48 | |
Wolfgang Denk | 54841ab | 2010-06-28 22:00:46 +0200 | [diff] [blame] | 49 | static int do_led_test(char * const argv[]) |
Bartlomiej Sieka | fa1df30 | 2007-07-11 20:11:07 +0200 | [diff] [blame] | 50 | { |
| 51 | int i = 0; |
| 52 | struct mpc5xxx_gpt_0_7 *gpt = (struct mpc5xxx_gpt_0_7 *)MPC5XXX_GPT; |
| 53 | |
| 54 | printf("Starting LED Test\n" |
| 55 | "Please set Switch S500 all off\n\n" |
| 56 | "Please press any key to start\n\n"); |
| 57 | getc(); |
| 58 | |
| 59 | /* configure timer 2-3 for simple GPIO output High */ |
| 60 | gpt->gpt2.emsr |= 0x00000034; |
| 61 | gpt->gpt3.emsr |= 0x00000034; |
| 62 | |
| 63 | (*(vu_long *)MPC5XXX_WU_GPIO_ENABLE) |= 0x80000000; |
| 64 | (*(vu_long *)MPC5XXX_WU_GPIO_DIR) |= 0x80000000; |
| 65 | printf("Please press any key to stop\n\n"); |
| 66 | while (!tstc()) { |
| 67 | if (i == 1) { |
| 68 | (*(vu_long *)MPC5XXX_WU_GPIO_DATA_O) |= 0x80000000; |
| 69 | gpt->gpt2.emsr &= ~0x00000010; |
| 70 | gpt->gpt3.emsr &= ~0x00000010; |
| 71 | } else if (i == 2) { |
| 72 | (*(vu_long *)MPC5XXX_WU_GPIO_DATA_O) &= ~0x80000000; |
| 73 | gpt->gpt2.emsr &= ~0x00000010; |
| 74 | gpt->gpt3.emsr |= 0x00000010; |
| 75 | } else if (i >= 3) { |
| 76 | (*(vu_long *)MPC5XXX_WU_GPIO_DATA_O) &= ~0x80000000; |
| 77 | gpt->gpt3.emsr &= ~0x00000010; |
| 78 | gpt->gpt2.emsr |= 0x00000010; |
| 79 | i = 0; |
| 80 | } |
| 81 | i++; |
| 82 | udelay(200000); |
| 83 | } |
| 84 | getc(); |
| 85 | |
| 86 | (*(vu_long *)MPC5XXX_WU_GPIO_DATA_O) |= 0x80000000; |
| 87 | gpt->gpt2.emsr |= 0x00000010; |
| 88 | gpt->gpt3.emsr |= 0x00000010; |
| 89 | |
| 90 | return 0; |
| 91 | } |
| 92 | |
Wolfgang Denk | 54841ab | 2010-06-28 22:00:46 +0200 | [diff] [blame] | 93 | static int do_rs232_test(char * const argv[]) |
Bartlomiej Sieka | fa1df30 | 2007-07-11 20:11:07 +0200 | [diff] [blame] | 94 | { |
| 95 | int error_status = 0; |
| 96 | struct mpc5xxx_gpio *gpio = (struct mpc5xxx_gpio *)MPC5XXX_GPIO; |
| 97 | struct mpc5xxx_psc *psc1 = (struct mpc5xxx_psc *)MPC5XXX_PSC1; |
| 98 | |
| 99 | /* Configure PSC 2-3-6 as GPIO */ |
| 100 | gpio->port_config &= 0xFF0FF80F; |
| 101 | |
| 102 | switch (simple_strtoul(argv[2], NULL, 10)) { |
| 103 | case 1: |
| 104 | /* check RTS <-> CTS loop */ |
| 105 | /* set rts to 0 */ |
| 106 | printf("Uart 1 test: RX TX tested by using U-Boot\n" |
| 107 | "Please connect RTS with CTS on Uart1 plug\n\n" |
| 108 | "Press any key to start\n\n"); |
| 109 | getc(); |
| 110 | |
| 111 | psc1->op1 |= 0x01; |
| 112 | |
| 113 | /* wait some time before requesting status */ |
| 114 | udelay(10); |
| 115 | |
| 116 | /* check status at cts */ |
| 117 | if ((psc1->ip & 0x01) != 0) { |
| 118 | error_status = 3; |
| 119 | printf("%s: failure at rs232_1, cts status is %d " |
| 120 | "(should be 0)\n", |
| 121 | __FUNCTION__, (psc1->ip & 0x01)); |
| 122 | } |
| 123 | |
| 124 | /* set rts to 1 */ |
| 125 | psc1->op0 |= 0x01; |
| 126 | |
| 127 | /* wait some time before requesting status */ |
| 128 | udelay(10); |
| 129 | |
| 130 | /* check status at cts */ |
| 131 | if ((psc1->ip & 0x01) != 1) { |
| 132 | error_status = 3; |
| 133 | printf("%s: failure at rs232_1, cts status is %d " |
| 134 | "(should be 1)\n", |
| 135 | __FUNCTION__, (psc1->ip & 0x01)); |
| 136 | } |
| 137 | break; |
| 138 | case 2: |
| 139 | /* set PSC2_0, PSC2_2 as output and PSC2_1, PSC2_3 as input */ |
| 140 | printf("Uart 2 test: Please use RS232 Loopback plug on UART2\n" |
| 141 | "\nPress any key to start\n\n"); |
| 142 | getc(); |
| 143 | |
| 144 | gpio->simple_gpioe &= ~(0x000000F0); |
| 145 | gpio->simple_gpioe |= 0x000000F0; |
| 146 | gpio->simple_ddr &= ~(0x000000F0); |
| 147 | gpio->simple_ddr |= 0x00000050; |
| 148 | |
| 149 | /* check TXD <-> RXD loop */ |
| 150 | /* set TXD to 1 */ |
| 151 | gpio->simple_dvo |= (1 << 4); |
| 152 | |
| 153 | /* wait some time before requesting status */ |
| 154 | udelay(10); |
| 155 | |
| 156 | if ((gpio->simple_ival & 0x00000020) != 0x00000020) { |
| 157 | error_status = 2; |
| 158 | printf("%s: failure at rs232_2, rxd status is %d " |
| 159 | "(should be 1)\n", __FUNCTION__, |
| 160 | (gpio->simple_ival & 0x00000020) >> 5); |
| 161 | } |
| 162 | |
| 163 | /* set TXD to 0 */ |
| 164 | gpio->simple_dvo &= ~(1 << 4); |
| 165 | |
| 166 | /* wait some time before requesting status */ |
| 167 | udelay(10); |
| 168 | |
| 169 | if ((gpio->simple_ival & 0x00000020) != 0x00000000) { |
| 170 | error_status = 2; |
| 171 | printf("%s: failure at rs232_2, rxd status is %d " |
| 172 | "(should be 0)\n", __FUNCTION__, |
| 173 | (gpio->simple_ival & 0x00000020) >> 5); |
| 174 | } |
| 175 | |
| 176 | /* check RTS <-> CTS loop */ |
| 177 | /* set RTS to 1 */ |
| 178 | gpio->simple_dvo |= (1 << 6); |
| 179 | |
| 180 | /* wait some time before requesting status */ |
| 181 | udelay(10); |
| 182 | |
| 183 | if ((gpio->simple_ival & 0x00000080) != 0x00000080) { |
| 184 | error_status = 3; |
| 185 | printf("%s: failure at rs232_2, cts status is %d " |
| 186 | "(should be 1)\n", __FUNCTION__, |
| 187 | (gpio->simple_ival & 0x00000080) >> 7); |
| 188 | } |
| 189 | |
| 190 | /* set RTS to 0 */ |
| 191 | gpio->simple_dvo &= ~(1 << 6); |
| 192 | |
| 193 | /* wait some time before requesting status */ |
| 194 | udelay(10); |
| 195 | |
| 196 | if ((gpio->simple_ival & 0x00000080) != 0x00000000) { |
| 197 | error_status = 3; |
| 198 | printf("%s: failure at rs232_2, cts status is %d " |
| 199 | "(should be 0)\n", __FUNCTION__, |
| 200 | (gpio->simple_ival & 0x00000080) >> 7); |
| 201 | } |
| 202 | break; |
| 203 | case 3: |
| 204 | /* set PSC3_0, PSC3_2 as output and PSC3_1, PSC3_3 as input */ |
| 205 | printf("Uart 3 test: Please use RS232 Loopback plug on UART2\n" |
| 206 | "\nPress any key to start\n\n"); |
| 207 | getc(); |
| 208 | |
| 209 | gpio->simple_gpioe &= ~(0x00000F00); |
| 210 | gpio->simple_gpioe |= 0x00000F00; |
| 211 | |
| 212 | gpio->simple_ddr &= ~(0x00000F00); |
| 213 | gpio->simple_ddr |= 0x00000500; |
| 214 | |
| 215 | /* check TXD <-> RXD loop */ |
| 216 | /* set TXD to 1 */ |
| 217 | gpio->simple_dvo |= (1 << 8); |
| 218 | |
| 219 | /* wait some time before requesting status */ |
| 220 | udelay(10); |
| 221 | |
| 222 | if ((gpio->simple_ival & 0x00000200) != 0x00000200) { |
| 223 | error_status = 2; |
| 224 | printf("%s: failure at rs232_3, rxd status is %d " |
| 225 | "(should be 1)\n", __FUNCTION__, |
| 226 | (gpio->simple_ival & 0x00000200) >> 9); |
| 227 | } |
| 228 | |
| 229 | /* set TXD to 0 */ |
| 230 | gpio->simple_dvo &= ~(1 << 8); |
| 231 | |
| 232 | /* wait some time before requesting status */ |
| 233 | udelay(10); |
| 234 | |
| 235 | if ((gpio->simple_ival & 0x00000200) != 0x00000000) { |
| 236 | error_status = 2; |
| 237 | printf("%s: failure at rs232_3, rxd status is %d " |
| 238 | "(should be 0)\n", __FUNCTION__, |
| 239 | (gpio->simple_ival & 0x00000200) >> 9); |
| 240 | } |
| 241 | |
| 242 | /* check RTS <-> CTS loop */ |
| 243 | /* set RTS to 1 */ |
| 244 | gpio->simple_dvo |= (1 << 10); |
| 245 | |
| 246 | /* wait some time before requesting status */ |
| 247 | udelay(10); |
| 248 | |
| 249 | if ((gpio->simple_ival & 0x00000800) != 0x00000800) { |
| 250 | error_status = 3; |
| 251 | printf("%s: failure at rs232_3, cts status is %d " |
| 252 | "(should be 1)\n", __FUNCTION__, |
| 253 | (gpio->simple_ival & 0x00000800) >> 11); |
| 254 | } |
| 255 | |
| 256 | /* set RTS to 0 */ |
| 257 | gpio->simple_dvo &= ~(1 << 10); |
| 258 | |
| 259 | /* wait some time before requesting status */ |
| 260 | udelay(10); |
| 261 | |
| 262 | if ((gpio->simple_ival & 0x00000800) != 0x00000000) { |
| 263 | error_status = 3; |
| 264 | printf("%s: failure at rs232_3, cts status is %d " |
| 265 | "(should be 0)\n", __FUNCTION__, |
| 266 | (gpio->simple_ival & 0x00000800) >> 11); |
| 267 | } |
| 268 | break; |
| 269 | case 4: |
| 270 | /* set PSC6_2, PSC6_3 as output and PSC6_0, PSC6_1 as input */ |
| 271 | printf("Uart 4 test: Please use RS232 Loopback plug on UART2\n" |
| 272 | "\nPress any key to start\n\n"); |
| 273 | getc(); |
| 274 | |
| 275 | gpio->simple_gpioe &= ~(0xF0000000); |
| 276 | gpio->simple_gpioe |= 0x30000000; |
| 277 | |
| 278 | gpio->simple_ddr &= ~(0xf0000000); |
| 279 | gpio->simple_ddr |= 0x30000000; |
| 280 | |
| 281 | (*(vu_long *)MPC5XXX_WU_GPIO_ENABLE) |= 0x30000000; |
| 282 | (*(vu_long *)MPC5XXX_WU_GPIO_DIR) &= ~(0x30000000); |
| 283 | |
| 284 | /* check TXD <-> RXD loop */ |
| 285 | /* set TXD to 1 */ |
| 286 | gpio->simple_dvo |= (1 << 28); |
| 287 | |
| 288 | /* wait some time before requesting status */ |
| 289 | udelay(10); |
| 290 | |
| 291 | if (((*(vu_long *)MPC5XXX_WU_GPIO_DATA_I) & 0x10000000) != |
| 292 | 0x10000000) { |
| 293 | error_status = 2; |
Wolfgang Denk | 9b55a25 | 2008-07-11 01:16:00 +0200 | [diff] [blame] | 294 | printf("%s: failure at rs232_4, rxd status is %lu " |
Bartlomiej Sieka | fa1df30 | 2007-07-11 20:11:07 +0200 | [diff] [blame] | 295 | "(should be 1)\n", __FUNCTION__, |
| 296 | ((*(vu_long *)MPC5XXX_WU_GPIO_DATA_I) & |
| 297 | 0x10000000) >> 28); |
| 298 | } |
| 299 | |
| 300 | /* set TXD to 0 */ |
| 301 | gpio->simple_dvo &= ~(1 << 28); |
| 302 | |
| 303 | /* wait some time before requesting status */ |
| 304 | udelay(10); |
| 305 | |
| 306 | if (((*(vu_long *)MPC5XXX_WU_GPIO_DATA_I) & 0x10000000) != |
| 307 | 0x00000000) { |
| 308 | error_status = 2; |
Wolfgang Denk | 9b55a25 | 2008-07-11 01:16:00 +0200 | [diff] [blame] | 309 | printf("%s: failure at rs232_4, rxd status is %lu " |
Bartlomiej Sieka | fa1df30 | 2007-07-11 20:11:07 +0200 | [diff] [blame] | 310 | "(should be 0)\n", __FUNCTION__, |
| 311 | ((*(vu_long *)MPC5XXX_WU_GPIO_DATA_I) & |
| 312 | 0x10000000) >> 28); |
| 313 | } |
| 314 | |
| 315 | /* check RTS <-> CTS loop */ |
| 316 | /* set RTS to 1 */ |
| 317 | gpio->simple_dvo |= (1 << 29); |
| 318 | |
| 319 | /* wait some time before requesting status */ |
| 320 | udelay(10); |
| 321 | |
| 322 | if (((*(vu_long *)MPC5XXX_WU_GPIO_DATA_I) & 0x20000000) != |
| 323 | 0x20000000) { |
| 324 | error_status = 3; |
Wolfgang Denk | 9b55a25 | 2008-07-11 01:16:00 +0200 | [diff] [blame] | 325 | printf("%s: failure at rs232_4, cts status is %lu " |
Bartlomiej Sieka | fa1df30 | 2007-07-11 20:11:07 +0200 | [diff] [blame] | 326 | "(should be 1)\n", __FUNCTION__, |
| 327 | ((*(vu_long *)MPC5XXX_WU_GPIO_DATA_I) & |
| 328 | 0x20000000) >> 29); |
| 329 | } |
| 330 | |
| 331 | /* set RTS to 0 */ |
| 332 | gpio->simple_dvo &= ~(1 << 29); |
| 333 | |
| 334 | /* wait some time before requesting status */ |
| 335 | udelay(10); |
| 336 | |
| 337 | if (((*(vu_long *)MPC5XXX_WU_GPIO_DATA_I) & 0x20000000) != |
| 338 | 0x00000000) { |
| 339 | error_status = 3; |
Wolfgang Denk | 9b55a25 | 2008-07-11 01:16:00 +0200 | [diff] [blame] | 340 | printf("%s: failure at rs232_4, cts status is %lu " |
Bartlomiej Sieka | fa1df30 | 2007-07-11 20:11:07 +0200 | [diff] [blame] | 341 | "(should be 0)\n", __FUNCTION__, |
| 342 | ((*(vu_long *)MPC5XXX_WU_GPIO_DATA_I) & |
| 343 | 0x20000000) >> 29); |
| 344 | } |
| 345 | break; |
| 346 | default: |
| 347 | printf("%s: invalid rs232 number %s\n", __FUNCTION__, argv[2]); |
| 348 | error_status = 1; |
| 349 | break; |
| 350 | } |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 351 | gpio->port_config |= (CONFIG_SYS_GPS_PORT_CONFIG & 0xFF0FF80F); |
Bartlomiej Sieka | fa1df30 | 2007-07-11 20:11:07 +0200 | [diff] [blame] | 352 | |
| 353 | return error_status; |
| 354 | } |
| 355 | |
Wolfgang Denk | 54841ab | 2010-06-28 22:00:46 +0200 | [diff] [blame] | 356 | static int cmd_fkt(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
Bartlomiej Sieka | fa1df30 | 2007-07-11 20:11:07 +0200 | [diff] [blame] | 357 | { |
| 358 | int rcode = -1; |
| 359 | |
| 360 | switch (argc) { |
| 361 | case 2: |
Simon Glass | eb5ba3a | 2017-05-12 21:09:49 -0600 | [diff] [blame^] | 362 | if (strncmp(argv[1], "led", 3) == 0) |
Peter Tyser | 8229e9c | 2009-04-18 22:34:00 -0500 | [diff] [blame] | 363 | rcode = do_led_test(argv); |
Bartlomiej Sieka | fa1df30 | 2007-07-11 20:11:07 +0200 | [diff] [blame] | 364 | else if (strncmp(argv[1], "usb", 3) == 0) |
Peter Tyser | 8229e9c | 2009-04-18 22:34:00 -0500 | [diff] [blame] | 365 | rcode = do_usb_test(argv); |
Bartlomiej Sieka | fa1df30 | 2007-07-11 20:11:07 +0200 | [diff] [blame] | 366 | break; |
| 367 | case 3: |
| 368 | if (strncmp(argv[1], "rs232", 3) == 0) |
Peter Tyser | 8229e9c | 2009-04-18 22:34:00 -0500 | [diff] [blame] | 369 | rcode = do_rs232_test(argv); |
Bartlomiej Sieka | fa1df30 | 2007-07-11 20:11:07 +0200 | [diff] [blame] | 370 | break; |
| 371 | } |
| 372 | |
| 373 | switch (rcode) { |
| 374 | case -1: |
| 375 | printf("Usage:\n" |
| 376 | "fkt { i2c | led | usb }\n" |
| 377 | "fkt rs232 number\n"); |
| 378 | rcode = 1; |
| 379 | break; |
| 380 | case 0: |
| 381 | printf("Test passed\n"); |
| 382 | break; |
| 383 | default: |
| 384 | printf("Test failed with code: %d\n", rcode); |
| 385 | } |
| 386 | |
| 387 | return rcode; |
| 388 | } |
| 389 | |
| 390 | U_BOOT_CMD( |
| 391 | fkt, 4, 1, cmd_fkt, |
Peter Tyser | 2fb2604 | 2009-01-27 18:03:12 -0600 | [diff] [blame] | 392 | "Function test routines", |
Bartlomiej Sieka | fa1df30 | 2007-07-11 20:11:07 +0200 | [diff] [blame] | 393 | "i2c\n" |
| 394 | " - Test I2C communication\n" |
| 395 | "fkt led\n" |
| 396 | " - Test LEDs\n" |
| 397 | "fkt rs232 number\n" |
| 398 | " - Test RS232 (loopback plug(s) for RS232 required)\n" |
| 399 | "fkt usb\n" |
Wolfgang Denk | a89c33d | 2009-05-24 17:06:54 +0200 | [diff] [blame] | 400 | " - Test USB communication" |
Bartlomiej Sieka | fa1df30 | 2007-07-11 20:11:07 +0200 | [diff] [blame] | 401 | ); |
Wolfgang Denk | afaac86 | 2007-08-12 14:27:39 +0200 | [diff] [blame] | 402 | #endif /* CONFIG_CMD_BSP */ |