1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26#include <common.h>
27#include <altera.h>
28#include <ACEX1K.h>
29
30
31#ifdef FPGA_DEBUG
32#define PRINTF(fmt,args...) printf (fmt ,##args)
33#else
34#define PRINTF(fmt,args...)
35#endif
36
37
38
39
40
41
42#ifndef CONFIG_FPGA_DELAY
43#define CONFIG_FPGA_DELAY()
44#endif
45
46#ifndef CONFIG_SYS_FPGA_WAIT
47#define CONFIG_SYS_FPGA_WAIT CONFIG_SYS_HZ/10
48#endif
49
50static int CYC2_ps_load( Altera_desc *desc, void *buf, size_t bsize );
51static int CYC2_ps_dump( Altera_desc *desc, void *buf, size_t bsize );
52
53
54
55
56int CYC2_load (Altera_desc * desc, void *buf, size_t bsize)
57{
58 int ret_val = FPGA_FAIL;
59
60 switch (desc->iface) {
61 case passive_serial:
62 PRINTF ("%s: Launching Passive Serial Loader\n", __FUNCTION__);
63 ret_val = CYC2_ps_load (desc, buf, bsize);
64 break;
65
66
67
68 default:
69 printf ("%s: Unsupported interface type, %d\n",
70 __FUNCTION__, desc->iface);
71 }
72
73 return ret_val;
74}
75
76int CYC2_dump (Altera_desc * desc, void *buf, size_t bsize)
77{
78 int ret_val = FPGA_FAIL;
79
80 switch (desc->iface) {
81 case passive_serial:
82 PRINTF ("%s: Launching Passive Serial Dump\n", __FUNCTION__);
83 ret_val = CYC2_ps_dump (desc, buf, bsize);
84 break;
85
86
87
88 default:
89 printf ("%s: Unsupported interface type, %d\n",
90 __FUNCTION__, desc->iface);
91 }
92
93 return ret_val;
94}
95
96int CYC2_info( Altera_desc *desc )
97{
98 return FPGA_SUCCESS;
99}
100
101
102
103static int CYC2_ps_load (Altera_desc * desc, void *buf, size_t bsize)
104{
105 int ret_val = FPGA_FAIL;
106 Altera_CYC2_Passive_Serial_fns *fn = desc->iface_fns;
107 int ret = 0;
108
109 PRINTF ("%s: start with interface functions @ 0x%p\n",
110 __FUNCTION__, fn);
111
112 if (fn) {
113 int cookie = desc->cookie;
114 unsigned long ts;
115
116 PRINTF ("%s: Function Table:\n"
117 "ptr:\t0x%p\n"
118 "struct: 0x%p\n"
119 "config:\t0x%p\n"
120 "status:\t0x%p\n"
121 "write:\t0x%p\n"
122 "done:\t0x%p\n\n",
123 __FUNCTION__, &fn, fn, fn->config, fn->status,
124 fn->write, fn->done);
125#ifdef CONFIG_SYS_FPGA_PROG_FEEDBACK
126 printf ("Loading FPGA Device %d...", cookie);
127#endif
128
129
130
131
132 if (*fn->pre) {
133 (*fn->pre) (cookie);
134 }
135
136
137 (*fn->config) (TRUE, TRUE, cookie);
138
139 udelay(2);
140
141
142 ts = get_timer (0);
143 do {
144 CONFIG_FPGA_DELAY ();
145 if (get_timer (ts) > CONFIG_SYS_FPGA_WAIT) {
146 puts ("** Timeout waiting for STATUS to go high.\n");
147 (*fn->abort) (cookie);
148 return FPGA_FAIL;
149 }
150 } while (!(*fn->status) (cookie));
151
152
153 CONFIG_FPGA_DELAY ();
154
155 ret = (*fn->write) (buf, bsize, TRUE, cookie);
156 if (ret) {
157 puts ("** Write failed.\n");
158 (*fn->abort) (cookie);
159 return FPGA_FAIL;
160 }
161#ifdef CONFIG_SYS_FPGA_PROG_FEEDBACK
162 puts(" OK? ...");
163#endif
164
165 CONFIG_FPGA_DELAY ();
166
167#ifdef CONFIG_SYS_FPGA_PROG_FEEDBACK
168 putc (' ');
169#endif
170
171
172
173
174
175 if ( ! (*fn->done) (cookie) ) {
176 puts ("** Booting failed! CONF_DONE is still deasserted.\n");
177 (*fn->abort) (cookie);
178 return (FPGA_FAIL);
179 }
180#ifdef CONFIG_SYS_FPGA_PROG_FEEDBACK
181 puts(" OK\n");
182#endif
183
184 ret_val = FPGA_SUCCESS;
185
186#ifdef CONFIG_SYS_FPGA_PROG_FEEDBACK
187 if (ret_val == FPGA_SUCCESS) {
188 puts ("Done.\n");
189 }
190 else {
191 puts ("Fail.\n");
192 }
193#endif
194 (*fn->post) (cookie);
195
196 } else {
197 printf ("%s: NULL Interface function table!\n", __FUNCTION__);
198 }
199
200 return ret_val;
201}
202
203static int CYC2_ps_dump (Altera_desc * desc, void *buf, size_t bsize)
204{
205
206
207 printf ("%s: Passive Serial Dumping is unavailable\n",
208 __FUNCTION__);
209 return FPGA_FAIL;
210}
211