cmd_cm1_qp1.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446
  1. /*
  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. #include <common.h>
  23. #include <command.h>
  24. #include <i2c.h>
  25. #include <usb.h>
  26. #if (CONFIG_COMMANDS & CFG_CMD_BSP)
  27. int do_i2c(char *argv[])
  28. {
  29. unsigned char temp, temp1;
  30. printf("Starting I2C Test\n"
  31. "Please set Jumper:\nI2C SDA 2-3\nI2C SCL 2-3\n\n"
  32. "Please press any key to start\n\n");
  33. getc();
  34. temp = 0xf0; /* set io 0-4 as output */
  35. i2c_write(CFG_I2C_IO, 3, 1, (uchar *)&temp, 1);
  36. printf("Press I2C4-7. LED I2C0-3 should have the same state\n\n"
  37. "Press any key to stop\n\n");
  38. while (!tstc()) {
  39. i2c_read(CFG_I2C_IO, 0, 1, (uchar *)&temp, 1);
  40. temp1 = (temp >> 4) & 0x03;
  41. temp1 |= (temp >> 3) & 0x08; /* S302 -> LED303 */
  42. temp1 |= (temp >> 5) & 0x04; /* S303 -> LED302 */
  43. temp = temp1;
  44. i2c_write(CFG_I2C_IO, 1, 1, (uchar *)&temp, 1);
  45. }
  46. getc();
  47. return 0;
  48. }
  49. int do_usbtest(char *argv[])
  50. {
  51. int i;
  52. static int usb_stor_curr_dev = -1; /* current device */
  53. printf("Starting USB Test\n"
  54. "Please insert USB Memmory Stick\n\n"
  55. "Please press any key to start\n\n");
  56. getc();
  57. usb_stop();
  58. printf("(Re)start USB...\n");
  59. i = usb_init();
  60. #ifdef CONFIG_USB_STORAGE
  61. /* try to recognize storage devices immediately */
  62. if (i >= 0)
  63. usb_stor_curr_dev = usb_stor_scan(1);
  64. #endif /* CONFIG_USB_STORAGE */
  65. if (usb_stor_curr_dev >= 0)
  66. printf("Found USB Storage Dev continue with Test...\n");
  67. else {
  68. printf("No USB Storage Device detected.. Stop Test\n");
  69. return 1;
  70. }
  71. usb_stor_info();
  72. printf("stopping USB..\n");
  73. usb_stop();
  74. return 0;
  75. }
  76. int do_led(char *argv[])
  77. {
  78. int i = 0;
  79. struct mpc5xxx_gpt_0_7 *gpt = (struct mpc5xxx_gpt_0_7 *)MPC5XXX_GPT;
  80. printf("Starting LED Test\n"
  81. "Please set Switch S500 all off\n\n"
  82. "Please press any key to start\n\n");
  83. getc();
  84. /* configure timer 2-3 for simple GPIO output High */
  85. gpt->gpt2.emsr |= 0x00000034;
  86. gpt->gpt3.emsr |= 0x00000034;
  87. (*(vu_long *)MPC5XXX_WU_GPIO_ENABLE) |= 0x80000000;
  88. (*(vu_long *)MPC5XXX_WU_GPIO_DIR) |= 0x80000000;
  89. printf("Please press any key to stop\n\n");
  90. while (!tstc()) {
  91. if (i == 1) {
  92. (*(vu_long *)MPC5XXX_WU_GPIO_DATA_O) |= 0x80000000;
  93. gpt->gpt2.emsr &= ~0x00000010;
  94. gpt->gpt3.emsr &= ~0x00000010;
  95. } else if (i == 2) {
  96. (*(vu_long *)MPC5XXX_WU_GPIO_DATA_O) &= ~0x80000000;
  97. gpt->gpt2.emsr &= ~0x00000010;
  98. gpt->gpt3.emsr |= 0x00000010;
  99. } else if (i >= 3) {
  100. (*(vu_long *)MPC5XXX_WU_GPIO_DATA_O) &= ~0x80000000;
  101. gpt->gpt3.emsr &= ~0x00000010;
  102. gpt->gpt2.emsr |= 0x00000010;
  103. i = 0;
  104. }
  105. i++;
  106. udelay(200000);
  107. }
  108. getc();
  109. (*(vu_long *)MPC5XXX_WU_GPIO_DATA_O) |= 0x80000000;
  110. gpt->gpt2.emsr |= 0x00000010;
  111. gpt->gpt3.emsr |= 0x00000010;
  112. return 0;
  113. }
  114. int do_rs232(char *argv[])
  115. {
  116. int error_status = 0;
  117. struct mpc5xxx_gpio *gpio = (struct mpc5xxx_gpio *)MPC5XXX_GPIO;
  118. struct mpc5xxx_psc *psc1 = (struct mpc5xxx_psc *)MPC5XXX_PSC1;
  119. /* Configure PSC 2-3-6 as GPIO */
  120. gpio->port_config &= 0xFF0FF80F;
  121. switch (simple_strtoul(argv[2], NULL, 10)) {
  122. case 1:
  123. /* check RTS <-> CTS loop */
  124. /* set rts to 0 */
  125. printf("Uart 1 test: RX TX tested by using U-Boot\n"
  126. "Please connect RTS with CTS on Uart1 plug\n\n"
  127. "Press any key to start\n\n");
  128. getc();
  129. psc1->op1 |= 0x01;
  130. /* wait some time before requesting status */
  131. udelay(10);
  132. /* check status at cts */
  133. if ((psc1->ip & 0x01) != 0) {
  134. error_status = 3;
  135. printf("%s: failure at rs232_1, cts status is %d "
  136. "(should be 0)\n",
  137. __FUNCTION__, (psc1->ip & 0x01));
  138. }
  139. /* set rts to 1 */
  140. psc1->op0 |= 0x01;
  141. /* wait some time before requesting status */
  142. udelay(10);
  143. /* check status at cts */
  144. if ((psc1->ip & 0x01) != 1) {
  145. error_status = 3;
  146. printf("%s: failure at rs232_1, cts status is %d "
  147. "(should be 1)\n",
  148. __FUNCTION__, (psc1->ip & 0x01));
  149. }
  150. break;
  151. case 2:
  152. /* set PSC2_0, PSC2_2 as output and PSC2_1, PSC2_3 as input */
  153. printf("Uart 2 test: Please use RS232 Loopback plug on UART2\n"
  154. "\nPress any key to start\n\n");
  155. getc();
  156. gpio->simple_gpioe &= ~(0x000000F0);
  157. gpio->simple_gpioe |= 0x000000F0;
  158. gpio->simple_ddr &= ~(0x000000F0);
  159. gpio->simple_ddr |= 0x00000050;
  160. /* check TXD <-> RXD loop */
  161. /* set TXD to 1 */
  162. gpio->simple_dvo |= (1 << 4);
  163. /* wait some time before requesting status */
  164. udelay(10);
  165. if ((gpio->simple_ival & 0x00000020) != 0x00000020) {
  166. error_status = 2;
  167. printf("%s: failure at rs232_2, rxd status is %d "
  168. "(should be 1)\n", __FUNCTION__,
  169. (gpio->simple_ival & 0x00000020) >> 5);
  170. }
  171. /* set TXD to 0 */
  172. gpio->simple_dvo &= ~(1 << 4);
  173. /* wait some time before requesting status */
  174. udelay(10);
  175. if ((gpio->simple_ival & 0x00000020) != 0x00000000) {
  176. error_status = 2;
  177. printf("%s: failure at rs232_2, rxd status is %d "
  178. "(should be 0)\n", __FUNCTION__,
  179. (gpio->simple_ival & 0x00000020) >> 5);
  180. }
  181. /* check RTS <-> CTS loop */
  182. /* set RTS to 1 */
  183. gpio->simple_dvo |= (1 << 6);
  184. /* wait some time before requesting status */
  185. udelay(10);
  186. if ((gpio->simple_ival & 0x00000080) != 0x00000080) {
  187. error_status = 3;
  188. printf("%s: failure at rs232_2, cts status is %d "
  189. "(should be 1)\n", __FUNCTION__,
  190. (gpio->simple_ival & 0x00000080) >> 7);
  191. }
  192. /* set RTS to 0 */
  193. gpio->simple_dvo &= ~(1 << 6);
  194. /* wait some time before requesting status */
  195. udelay(10);
  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. gpio->simple_gpioe &= ~(0x00000F00);
  209. gpio->simple_gpioe |= 0x00000F00;
  210. gpio->simple_ddr &= ~(0x00000F00);
  211. gpio->simple_ddr |= 0x00000500;
  212. /* check TXD <-> RXD loop */
  213. /* set TXD to 1 */
  214. gpio->simple_dvo |= (1 << 8);
  215. /* wait some time before requesting status */
  216. udelay(10);
  217. if ((gpio->simple_ival & 0x00000200) != 0x00000200) {
  218. error_status = 2;
  219. printf("%s: failure at rs232_3, rxd status is %d "
  220. "(should be 1)\n", __FUNCTION__,
  221. (gpio->simple_ival & 0x00000200) >> 9);
  222. }
  223. /* set TXD to 0 */
  224. gpio->simple_dvo &= ~(1 << 8);
  225. /* wait some time before requesting status */
  226. udelay(10);
  227. if ((gpio->simple_ival & 0x00000200) != 0x00000000) {
  228. error_status = 2;
  229. printf("%s: failure at rs232_3, rxd status is %d "
  230. "(should be 0)\n", __FUNCTION__,
  231. (gpio->simple_ival & 0x00000200) >> 9);
  232. }
  233. /* check RTS <-> CTS loop */
  234. /* set RTS to 1 */
  235. gpio->simple_dvo |= (1 << 10);
  236. /* wait some time before requesting status */
  237. udelay(10);
  238. if ((gpio->simple_ival & 0x00000800) != 0x00000800) {
  239. error_status = 3;
  240. printf("%s: failure at rs232_3, cts status is %d "
  241. "(should be 1)\n", __FUNCTION__,
  242. (gpio->simple_ival & 0x00000800) >> 11);
  243. }
  244. /* set RTS to 0 */
  245. gpio->simple_dvo &= ~(1 << 10);
  246. /* wait some time before requesting status */
  247. udelay(10);
  248. if ((gpio->simple_ival & 0x00000800) != 0x00000000) {
  249. error_status = 3;
  250. printf("%s: failure at rs232_3, cts status is %d "
  251. "(should be 0)\n", __FUNCTION__,
  252. (gpio->simple_ival & 0x00000800) >> 11);
  253. }
  254. break;
  255. case 4:
  256. /* set PSC6_2, PSC6_3 as output and PSC6_0, PSC6_1 as input */
  257. printf("Uart 4 test: Please use RS232 Loopback plug on UART2\n"
  258. "\nPress any key to start\n\n");
  259. getc();
  260. gpio->simple_gpioe &= ~(0xF0000000);
  261. gpio->simple_gpioe |= 0x30000000;
  262. gpio->simple_ddr &= ~(0xf0000000);
  263. gpio->simple_ddr |= 0x30000000;
  264. (*(vu_long *)MPC5XXX_WU_GPIO_ENABLE) |= 0x30000000;
  265. (*(vu_long *)MPC5XXX_WU_GPIO_DIR) &= ~(0x30000000);
  266. /* check TXD <-> RXD loop */
  267. /* set TXD to 1 */
  268. gpio->simple_dvo |= (1 << 28);
  269. /* wait some time before requesting status */
  270. udelay(10);
  271. if (((*(vu_long *)MPC5XXX_WU_GPIO_DATA_I) & 0x10000000) !=
  272. 0x10000000) {
  273. error_status = 2;
  274. printf("%s: failure at rs232_4, rxd status is %d "
  275. "(should be 1)\n", __FUNCTION__,
  276. ((*(vu_long *)MPC5XXX_WU_GPIO_DATA_I) &
  277. 0x10000000) >> 28);
  278. }
  279. /* set TXD to 0 */
  280. gpio->simple_dvo &= ~(1 << 28);
  281. /* wait some time before requesting status */
  282. udelay(10);
  283. if (((*(vu_long *)MPC5XXX_WU_GPIO_DATA_I) & 0x10000000) !=
  284. 0x00000000) {
  285. error_status = 2;
  286. printf("%s: failure at rs232_4, rxd status is %d "
  287. "(should be 0)\n", __FUNCTION__,
  288. ((*(vu_long *)MPC5XXX_WU_GPIO_DATA_I) &
  289. 0x10000000) >> 28);
  290. }
  291. /* check RTS <-> CTS loop */
  292. /* set RTS to 1 */
  293. gpio->simple_dvo |= (1 << 29);
  294. /* wait some time before requesting status */
  295. udelay(10);
  296. if (((*(vu_long *)MPC5XXX_WU_GPIO_DATA_I) & 0x20000000) !=
  297. 0x20000000) {
  298. error_status = 3;
  299. printf("%s: failure at rs232_4, cts status is %d "
  300. "(should be 1)\n", __FUNCTION__,
  301. ((*(vu_long *)MPC5XXX_WU_GPIO_DATA_I) &
  302. 0x20000000) >> 29);
  303. }
  304. /* set RTS to 0 */
  305. gpio->simple_dvo &= ~(1 << 29);
  306. /* wait some time before requesting status */
  307. udelay(10);
  308. if (((*(vu_long *)MPC5XXX_WU_GPIO_DATA_I) & 0x20000000) !=
  309. 0x00000000) {
  310. error_status = 3;
  311. printf("%s: failure at rs232_4, cts status is %d "
  312. "(should be 0)\n", __FUNCTION__,
  313. ((*(vu_long *)MPC5XXX_WU_GPIO_DATA_I) &
  314. 0x20000000) >> 29);
  315. }
  316. break;
  317. default:
  318. printf("%s: invalid rs232 number %s\n", __FUNCTION__, argv[2]);
  319. error_status = 1;
  320. break;
  321. }
  322. gpio->port_config |= (CFG_GPS_PORT_CONFIG & 0xFF0FF80F);
  323. return error_status;
  324. }
  325. int cmd_fkt(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
  326. {
  327. int rcode = -1;
  328. switch (argc) {
  329. case 2:
  330. if (strncmp(argv[1], "i2c", 3) == 0)
  331. rcode = do_i2c(argv);
  332. else if (strncmp(argv[1], "led", 3) == 0)
  333. rcode = do_led(argv);
  334. else if (strncmp(argv[1], "usb", 3) == 0)
  335. rcode = do_usbtest(argv);
  336. break;
  337. case 3:
  338. if (strncmp(argv[1], "rs232", 3) == 0)
  339. rcode = do_rs232(argv);
  340. break;
  341. }
  342. switch (rcode) {
  343. case -1:
  344. printf("Usage:\n"
  345. "fkt { i2c | led | usb }\n"
  346. "fkt rs232 number\n");
  347. rcode = 1;
  348. break;
  349. case 0:
  350. printf("Test passed\n");
  351. break;
  352. default:
  353. printf("Test failed with code: %d\n", rcode);
  354. }
  355. return rcode;
  356. }
  357. U_BOOT_CMD(
  358. fkt, 4, 1, cmd_fkt,
  359. "fkt - Function test routines\n",
  360. "i2c\n"
  361. " - Test I2C communication\n"
  362. "fkt led\n"
  363. " - Test LEDs\n"
  364. "fkt rs232 number\n"
  365. " - Test RS232 (loopback plug(s) for RS232 required)\n"
  366. "fkt usb\n"
  367. " - Test USB communication\n"
  368. );
  369. #endif /* CFG_CMD_BSP */