coproc_com.c 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /*
  2. * (C) Copyright 2010 DENX Software Engineering,
  3. * Anatolij Gustschin, agust@denx.de.
  4. *
  5. * See file CREDITS for list of people who contributed to this
  6. * project.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License as
  10. * published by the Free Software Foundation; either version 2 of
  11. * the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  21. * MA 02111-1307 USA
  22. */
  23. /*
  24. * Co-Processor communication POST
  25. */
  26. #include <common.h>
  27. #include <post.h>
  28. #include <serial.h>
  29. #if defined(CONFIG_SERIAL_MULTI)
  30. /*
  31. * Actually the termination sequence of the coprocessor
  32. * commands is "\r\n" (CR LF), but here we use a side effect of
  33. * the putc() routine of the serial driver which checks for LF
  34. * and sends CR before sending LF. Therefore the termination
  35. * sequence in the command below is only "\n".
  36. * "alive" string is the coprocessor response for ping command
  37. * and not a command, therefore it is terminated with "\r\n".
  38. */
  39. char alive[] = "$AL;38\r\n";
  40. char ping[] = "$PI;2C\n";
  41. int coprocessor_post_test(int flags)
  42. {
  43. struct stdio_dev *cop_port;
  44. int ret;
  45. char buf[10];
  46. /* Test IO Coprocessor communication */
  47. cop_port = open_port(4, CONFIG_SYS_PDM360NG_COPROC_BAUDRATE);
  48. if (!cop_port)
  49. return -1;
  50. write_port(cop_port, ping);
  51. udelay(CONFIG_SYS_PDM360NG_COPROC_READ_DELAY);
  52. memset(buf, 0, sizeof(buf));
  53. ret = read_port(cop_port, buf, sizeof(buf));
  54. close_port(4);
  55. if (ret <= 0) {
  56. post_log("Error: Can't read IO Coprocessor port.\n");
  57. return -1;
  58. }
  59. if (strcmp(buf, alive)) {
  60. post_log("Error: IO-Cop. resp.: %s\n", buf);
  61. return -1;
  62. }
  63. /* Test WD Coprocessor communication */
  64. cop_port = open_port(1, CONFIG_SYS_PDM360NG_COPROC_BAUDRATE);
  65. if (!cop_port) {
  66. post_log("Error: Can't open WD Coprocessor port.\n");
  67. return -1;
  68. }
  69. write_port(cop_port, ping);
  70. udelay(CONFIG_SYS_PDM360NG_COPROC_READ_DELAY);
  71. memset(buf, 0, sizeof(buf));
  72. ret = read_port(cop_port, buf, sizeof(buf));
  73. close_port(1);
  74. if (ret <= 0) {
  75. post_log("Error: Can't read WD Coprocessor port.\n");
  76. return -1;
  77. }
  78. if (strcmp(buf, alive)) {
  79. post_log("Error: WD-Cop. resp.: %s\n", buf);
  80. return -1;
  81. }
  82. return 0;
  83. }
  84. #endif /* CONFIG_SERIAL_MULTI */