coproc_com.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /*
  2. * (C) Copyright 2010 DENX Software Engineering,
  3. * Anatolij Gustschin, agust@denx.de.
  4. *
  5. * SPDX-License-Identifier: GPL-2.0+
  6. */
  7. /*
  8. * Co-Processor communication POST
  9. */
  10. #include <common.h>
  11. #include <post.h>
  12. #include <serial.h>
  13. /*
  14. * Actually the termination sequence of the coprocessor
  15. * commands is "\r\n" (CR LF), but here we use a side effect of
  16. * the putc() routine of the serial driver which checks for LF
  17. * and sends CR before sending LF. Therefore the termination
  18. * sequence in the command below is only "\n".
  19. * "alive" string is the coprocessor response for ping command
  20. * and not a command, therefore it is terminated with "\r\n".
  21. */
  22. char alive[] = "$AL;38\r\n";
  23. char ping[] = "$PI;2C\n";
  24. int coprocessor_post_test(int flags)
  25. {
  26. struct stdio_dev *cop_port;
  27. int ret;
  28. char buf[10];
  29. /* Test IO Coprocessor communication */
  30. cop_port = open_port(4, CONFIG_SYS_PDM360NG_COPROC_BAUDRATE);
  31. if (!cop_port)
  32. return -1;
  33. write_port(cop_port, ping);
  34. udelay(CONFIG_SYS_PDM360NG_COPROC_READ_DELAY);
  35. memset(buf, 0, sizeof(buf));
  36. ret = read_port(cop_port, buf, sizeof(buf));
  37. close_port(4);
  38. if (ret <= 0) {
  39. post_log("Error: Can't read IO Coprocessor port.\n");
  40. return -1;
  41. }
  42. if (strcmp(buf, alive)) {
  43. post_log("Error: IO-Cop. resp.: %s\n", buf);
  44. return -1;
  45. }
  46. /* Test WD Coprocessor communication */
  47. cop_port = open_port(1, CONFIG_SYS_PDM360NG_COPROC_BAUDRATE);
  48. if (!cop_port) {
  49. post_log("Error: Can't open WD Coprocessor port.\n");
  50. return -1;
  51. }
  52. write_port(cop_port, ping);
  53. udelay(CONFIG_SYS_PDM360NG_COPROC_READ_DELAY);
  54. memset(buf, 0, sizeof(buf));
  55. ret = read_port(cop_port, buf, sizeof(buf));
  56. close_port(1);
  57. if (ret <= 0) {
  58. post_log("Error: Can't read WD Coprocessor port.\n");
  59. return -1;
  60. }
  61. if (strcmp(buf, alive)) {
  62. post_log("Error: WD-Cop. resp.: %s\n", buf);
  63. return -1;
  64. }
  65. return 0;
  66. }