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