blob: 075535213bc82ac1923c2933d324f7ee3579ebe2 [file] [log] [blame]
Anatolij Gustschin810b2072010-04-24 19:27:11 +02001/*
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/*
25 * Co-Processor communication POST
26 */
27#include <common.h>
28#include <post.h>
29#include <serial.h>
30
31#if defined(CONFIG_SERIAL_MULTI)
32
33/*
34 * Actually the termination sequence of the coprocessor
35 * commands is "\r\n" (CR LF), but here we use a side effect of
36 * the putc() routine of the serial driver which checks for LF
37 * and sends CR before sending LF. Therefore the termination
38 * sequence in the command below is only "\n".
39 * "alive" string is the coprocessor response for ping command
40 * and not a command, therefore it is terminated with "\r\n".
41 */
42char alive[] = "$AL;38\r\n";
43char ping[] = "$PI;2C\n";
44
45int coprocessor_post_test(int flags)
46{
47 struct stdio_dev *cop_port;
48 int ret;
49 char buf[10];
50
51 /* Test IO Coprocessor communication */
52 cop_port = open_port(4, CONFIG_SYS_PDM360NG_COPROC_BAUDRATE);
53 if (!cop_port)
54 return -1;
55
56 write_port(cop_port, ping);
57 udelay(CONFIG_SYS_PDM360NG_COPROC_READ_DELAY);
58
59 memset(buf, 0, sizeof(buf));
60 ret = read_port(cop_port, buf, sizeof(buf));
61 close_port(4);
62 if (ret <= 0) {
63 post_log("Error: Can't read IO Coprocessor port.\n");
64 return -1;
65 }
66
67 if (strcmp(buf, alive)) {
68 post_log("Error: IO-Cop. resp.: %s\n", buf);
69 return -1;
70 }
71
72 /* Test WD Coprocessor communication */
73 cop_port = open_port(1, CONFIG_SYS_PDM360NG_COPROC_BAUDRATE);
74 if (!cop_port) {
75 post_log("Error: Can't open WD Coprocessor port.\n");
76 return -1;
77 }
78
79 write_port(cop_port, ping);
80 udelay(CONFIG_SYS_PDM360NG_COPROC_READ_DELAY);
81
82 memset(buf, 0, sizeof(buf));
83 ret = read_port(cop_port, buf, sizeof(buf));
84 close_port(1);
85 if (ret <= 0) {
86 post_log("Error: Can't read WD Coprocessor port.\n");
87 return -1;
88 }
89
90 if (strcmp(buf, alive)) {
91 post_log("Error: WD-Cop. resp.: %s\n", buf);
92 return -1;
93 }
94
95 return 0;
96}
97#endif /* CONFIG_SERIAL_MULTI */