cmd_cm5200.c 11 KB

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