1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24#include <common.h>
25#include <asm/io.h>
26#include <spartan2.h>
27#include <spartan3.h>
28#include <command.h>
29#include "fpga.h"
30#include "pmc440.h"
31
32DECLARE_GLOBAL_DATA_PTR;
33
34#if defined(CONFIG_FPGA)
35
36#define USE_SP_CODE
37
38#ifdef USE_SP_CODE
39Xilinx_Spartan3_Slave_Parallel_fns pmc440_fpga_fns = {
40 fpga_pre_config_fn,
41 fpga_pgm_fn,
42 fpga_init_fn,
43 NULL,
44 fpga_done_fn,
45 fpga_clk_fn,
46 fpga_cs_fn,
47 fpga_wr_fn,
48 NULL,
49 fpga_wdata_fn,
50 fpga_busy_fn,
51 fpga_abort_fn,
52 fpga_post_config_fn,
53};
54#else
55Xilinx_Spartan3_Slave_Serial_fns pmc440_fpga_fns = {
56 fpga_pre_config_fn,
57 fpga_pgm_fn,
58 fpga_clk_fn,
59 fpga_init_fn,
60 fpga_done_fn,
61 fpga_wr_fn,
62 fpga_post_config_fn,
63};
64#endif
65
66Xilinx_Spartan2_Slave_Serial_fns ngcc_fpga_fns = {
67 ngcc_fpga_pre_config_fn,
68 ngcc_fpga_pgm_fn,
69 ngcc_fpga_clk_fn,
70 ngcc_fpga_init_fn,
71 ngcc_fpga_done_fn,
72 ngcc_fpga_wr_fn,
73 ngcc_fpga_post_config_fn
74};
75
76Xilinx_desc fpga[CONFIG_FPGA_COUNT] = {
77 XILINX_XC3S1200E_DESC(
78#ifdef USE_SP_CODE
79 slave_parallel,
80#else
81 slave_serial,
82#endif
83 (void *)&pmc440_fpga_fns,
84 0),
85 XILINX_XC2S200_DESC(
86 slave_serial,
87 (void *)&ngcc_fpga_fns,
88 0)
89};
90
91
92
93
94
95void fpga_reset(int assert)
96{
97 debug("%s:%d: RESET ", __FUNCTION__, __LINE__);
98 if (assert) {
99 out_be32((void*)GPIO1_OR, in_be32((void*)GPIO1_OR) & ~GPIO1_FPGA_DATA);
100 debug("asserted\n");
101 } else {
102 out_be32((void*)GPIO1_OR, in_be32((void*)GPIO1_OR) | GPIO1_FPGA_DATA);
103 debug("deasserted\n");
104 }
105}
106
107
108
109
110
111
112void fpga_serialslave_init(void)
113{
114 debug("%s:%d: Initialize serial slave interface\n", __FUNCTION__,
115 __LINE__);
116 fpga_pgm_fn(FALSE, FALSE, 0);
117}
118
119
120
121
122
123int fpga_pgm_fn(int assert, int flush, int cookie)
124{
125 debug("%s:%d: FPGA PROGRAM ",
126 __FUNCTION__, __LINE__);
127
128 if (assert) {
129 out_be32((void*)GPIO1_OR, in_be32((void*)GPIO1_OR) & ~GPIO1_FPGA_PRG);
130 debug("asserted\n");
131 } else {
132 out_be32((void*)GPIO1_OR, in_be32((void*)GPIO1_OR) | GPIO1_FPGA_PRG);
133 debug("deasserted\n");
134 }
135 return assert;
136}
137
138
139
140
141
142
143int fpga_init_fn(int cookie)
144{
145 if (in_be32((void*)GPIO1_IR) & GPIO1_FPGA_INIT)
146 return 0;
147 else
148 return 1;
149}
150
151#ifdef USE_SP_CODE
152int fpga_abort_fn(int cookie)
153{
154 return 0;
155}
156
157
158int fpga_cs_fn(int assert_cs, int flush, int cookie)
159{
160 return assert_cs;
161}
162
163
164int fpga_busy_fn(int cookie)
165{
166 return 1;
167}
168#endif
169
170
171
172
173
174int fpga_done_fn(int cookie)
175{
176 if (in_be32((void*)GPIO1_IR) & GPIO1_FPGA_DONE)
177 return 1;
178 else
179 return 0;
180}
181
182
183
184
185
186
187
188int fpga_pre_config_fn(int cookie)
189{
190 debug("%s:%d: FPGA pre-configuration\n", __FUNCTION__, __LINE__);
191 fpga_reset(TRUE);
192
193
194 out_be32((void*)GPIO0_OR, in_be32((void*)GPIO0_OR) | GPIO0_FPGA_FORCEINIT);
195
196 out_be32((void*)GPIO1_OR, in_be32((void*)GPIO1_OR) | GPIO1_IOEN_N);
197 return 0;
198}
199
200
201
202
203
204
205int fpga_post_config_fn(int cookie)
206{
207 pmc440_fpga_t *fpga = (pmc440_fpga_t *)FPGA_BA;
208 int rc=0;
209 char *s;
210
211 debug("%s:%d: FPGA post configuration\n", __FUNCTION__, __LINE__);
212
213
214 out_be32((void*)GPIO1_OR, in_be32((void*)GPIO1_OR) & ~GPIO1_IOEN_N);
215
216 fpga_reset(TRUE);
217 udelay (100);
218 fpga_reset(FALSE);
219 udelay (100);
220
221 FPGA_OUT32(&fpga->status, (gd->board_type << STATUS_HWREV_SHIFT) & STATUS_HWREV_MASK);
222
223
224 if ((s = getenv("bd_type")) &&
225 ((!strcmp(s, "ngcc")) || (!strcmp(s, "candes"))))
226 FPGA_SETBITS(&fpga->ctrla, 0x29f8c000);
227
228 return rc;
229}
230
231
232int fpga_clk_fn(int assert_clk, int flush, int cookie)
233{
234 if (assert_clk)
235 out_be32((void*)GPIO1_OR, in_be32((void*)GPIO1_OR) | GPIO1_FPGA_CLK);
236 else
237 out_be32((void*)GPIO1_OR, in_be32((void*)GPIO1_OR) & ~GPIO1_FPGA_CLK);
238
239 return assert_clk;
240}
241
242
243int fpga_wr_fn(int assert_write, int flush, int cookie)
244{
245 if (assert_write)
246 out_be32((void*)GPIO1_OR, in_be32((void*)GPIO1_OR) | GPIO1_FPGA_DATA);
247 else
248 out_be32((void*)GPIO1_OR, in_be32((void*)GPIO1_OR) & ~GPIO1_FPGA_DATA);
249
250 return assert_write;
251}
252
253#ifdef USE_SP_CODE
254int fpga_wdata_fn(uchar data, int flush, int cookie)
255{
256 uchar val = data;
257 ulong or = in_be32((void*)GPIO1_OR);
258 int i = 7;
259 do {
260
261 if (val & 0x80)
262 or = (or & ~GPIO1_FPGA_CLK) | GPIO1_FPGA_DATA;
263 else
264 or = or & ~(GPIO1_FPGA_CLK | GPIO1_FPGA_DATA);
265
266 out_be32((void*)GPIO1_OR, or);
267
268
269 or |= GPIO1_FPGA_CLK;
270 out_be32((void*)GPIO1_OR, or);
271 val <<= 1;
272 i --;
273 } while (i > 0);
274
275
276 if (val & 0x80)
277 or = (or & ~GPIO1_FPGA_CLK) | GPIO1_FPGA_DATA;
278 else
279 or = or & ~(GPIO1_FPGA_CLK | GPIO1_FPGA_DATA);
280
281 out_be32((void*)GPIO1_OR, or);
282
283 return 0;
284}
285#endif
286
287#define NGCC_FPGA_PRG CLOCK_EN
288#define NGCC_FPGA_DATA RESET_OUT
289#define NGCC_FPGA_DONE CLOCK_IN
290#define NGCC_FPGA_INIT IRIGB_R_IN
291#define NGCC_FPGA_CLK CLOCK_OUT
292
293void ngcc_fpga_serialslave_init(void)
294{
295 debug("%s:%d: Initialize serial slave interface\n",
296 __FUNCTION__, __LINE__);
297
298
299 ngcc_fpga_pgm_fn (FALSE, FALSE, 0);
300}
301
302
303
304
305void ngcc_fpga_reset(int assert)
306{
307 debug("%s:%d: RESET ", __FUNCTION__, __LINE__);
308
309 if (assert) {
310 FPGA_CLRBITS(NGCC_CTRL_BASE, NGCC_CTRL_FPGARST_N);
311 debug("asserted\n");
312 } else {
313 FPGA_SETBITS(NGCC_CTRL_BASE, NGCC_CTRL_FPGARST_N);
314 debug("deasserted\n");
315 }
316}
317
318
319
320
321
322int ngcc_fpga_pgm_fn(int assert, int flush, int cookie)
323{
324 pmc440_fpga_t *fpga = (pmc440_fpga_t *)FPGA_BA;
325
326 debug("%s:%d: FPGA PROGRAM ", __FUNCTION__, __LINE__);
327
328 if (assert) {
329 FPGA_CLRBITS(&fpga->ctrla, NGCC_FPGA_PRG);
330 debug("asserted\n");
331 } else {
332 FPGA_SETBITS(&fpga->ctrla, NGCC_FPGA_PRG);
333 debug("deasserted\n");
334 }
335
336 return assert;
337}
338
339
340
341
342
343
344int ngcc_fpga_init_fn(int cookie)
345{
346 pmc440_fpga_t *fpga = (pmc440_fpga_t *)FPGA_BA;
347
348 debug("%s:%d: INIT check... ", __FUNCTION__, __LINE__);
349 if (FPGA_IN32(&fpga->status) & NGCC_FPGA_INIT) {
350 debug("high\n");
351 return 0;
352 } else {
353 debug("low\n");
354 return 1;
355 }
356}
357
358
359
360
361
362int ngcc_fpga_done_fn(int cookie)
363{
364 pmc440_fpga_t *fpga = (pmc440_fpga_t *)FPGA_BA;
365
366 debug("%s:%d: DONE check... ", __FUNCTION__, __LINE__);
367 if (FPGA_IN32(&fpga->status) & NGCC_FPGA_DONE) {
368 debug("DONE high\n");
369 return 1;
370 } else {
371 debug("low\n");
372 return 0;
373 }
374}
375
376
377
378
379
380int ngcc_fpga_pre_config_fn(int cookie)
381{
382 pmc440_fpga_t *fpga = (pmc440_fpga_t *)FPGA_BA;
383 debug("%s:%d: FPGA pre-configuration\n", __FUNCTION__, __LINE__);
384
385 ngcc_fpga_reset(TRUE);
386 FPGA_CLRBITS(&fpga->ctrla, 0xfffffe00);
387
388 ngcc_fpga_reset(TRUE);
389 return 0;
390}
391
392
393
394
395
396
397int ngcc_fpga_post_config_fn(int cookie)
398{
399 pmc440_fpga_t *fpga = (pmc440_fpga_t *)FPGA_BA;
400
401 debug("%s:%d: NGCC FPGA post configuration\n", __FUNCTION__, __LINE__);
402
403 udelay (100);
404 ngcc_fpga_reset(FALSE);
405
406 FPGA_SETBITS(&fpga->ctrla, 0x29f8c000);
407
408 return 0;
409}
410
411
412int ngcc_fpga_clk_fn(int assert_clk, int flush, int cookie)
413{
414 pmc440_fpga_t *fpga = (pmc440_fpga_t *)FPGA_BA;
415
416 if (assert_clk)
417 FPGA_SETBITS(&fpga->ctrla, NGCC_FPGA_CLK);
418 else
419 FPGA_CLRBITS(&fpga->ctrla, NGCC_FPGA_CLK);
420
421 return assert_clk;
422}
423
424
425int ngcc_fpga_wr_fn(int assert_write, int flush, int cookie)
426{
427 pmc440_fpga_t *fpga = (pmc440_fpga_t *)FPGA_BA;
428
429 if (assert_write)
430 FPGA_SETBITS(&fpga->ctrla, NGCC_FPGA_DATA);
431 else
432 FPGA_CLRBITS(&fpga->ctrla, NGCC_FPGA_DATA);
433
434 return assert_write;
435}
436
437
438
439
440
441int pmc440_init_fpga(void)
442{
443 char *s;
444
445 debug("%s:%d: Initialize FPGA interface\n",
446 __FUNCTION__, __LINE__);
447 fpga_init();
448
449 fpga_serialslave_init ();
450 debug("%s:%d: Adding fpga 0\n", __FUNCTION__, __LINE__);
451 fpga_add (fpga_xilinx, &fpga[0]);
452
453
454 if ((s = getenv("bd_type")) && !strcmp(s, "ngcc")) {
455 ngcc_fpga_serialslave_init ();
456 debug("%s:%d: Adding fpga 1\n", __FUNCTION__, __LINE__);
457 fpga_add (fpga_xilinx, &fpga[1]);
458 }
459
460 return 0;
461}
462#endif
463