3 * Matthias Fuchs, esd gmbh, matthias.fuchs@esd-electronics.com.
5 * See file CREDITS for list of people who contributed to this
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.
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.
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,
32 DECLARE_GLOBAL_DATA_PTR
;
34 #if defined(CONFIG_FPGA)
39 Xilinx_Spartan3_Slave_Parallel_fns pmc440_fpga_fns
= {
55 Xilinx_Spartan3_Slave_Serial_fns pmc440_fpga_fns
= {
66 Xilinx_Spartan2_Slave_Serial_fns ngcc_fpga_fns
= {
67 ngcc_fpga_pre_config_fn
,
73 ngcc_fpga_post_config_fn
76 Xilinx_desc fpga
[CONFIG_FPGA_COUNT
] = {
77 XILINX_XC3S1200E_DESC(
83 (void *)&pmc440_fpga_fns
,
87 (void *)&ngcc_fpga_fns
,
93 * Set the active-low FPGA reset signal.
95 void fpga_reset(int assert)
97 debug("%s:%d: RESET ", __FUNCTION__
, __LINE__
);
99 out_be32((void*)GPIO1_OR
, in_be32((void*)GPIO1_OR
) & ~GPIO1_FPGA_DATA
);
102 out_be32((void*)GPIO1_OR
, in_be32((void*)GPIO1_OR
) | GPIO1_FPGA_DATA
);
103 debug("deasserted\n");
109 * Initialize the SelectMap interface. We assume that the mode and the
110 * initial state of all of the port pins have already been set!
112 void fpga_serialslave_init(void)
114 debug("%s:%d: Initialize serial slave interface\n", __FUNCTION__
,
116 fpga_pgm_fn(FALSE
, FALSE
, 0); /* make sure program pin is inactive */
121 * Set the FPGA's active-low SelectMap program line to the specified level
123 int fpga_pgm_fn(int assert, int flush
, int cookie
)
125 debug("%s:%d: FPGA PROGRAM ",
126 __FUNCTION__
, __LINE__
);
129 out_be32((void*)GPIO1_OR
, in_be32((void*)GPIO1_OR
) & ~GPIO1_FPGA_PRG
);
132 out_be32((void*)GPIO1_OR
, in_be32((void*)GPIO1_OR
) | GPIO1_FPGA_PRG
);
133 debug("deasserted\n");
140 * Test the state of the active-low FPGA INIT line. Return 1 on INIT
143 int fpga_init_fn(int cookie
)
145 if (in_be32((void*)GPIO1_IR
) & GPIO1_FPGA_INIT
)
152 int fpga_abort_fn(int cookie
)
158 int fpga_cs_fn(int assert_cs
, int flush
, int cookie
)
164 int fpga_busy_fn(int cookie
)
172 * Test the state of the active-high FPGA DONE pin
174 int fpga_done_fn(int cookie
)
176 if (in_be32((void*)GPIO1_IR
) & GPIO1_FPGA_DONE
)
184 * FPGA pre-configuration function. Just make sure that
185 * FPGA reset is asserted to keep the FPGA from starting up after
188 int fpga_pre_config_fn(int cookie
)
190 debug("%s:%d: FPGA pre-configuration\n", __FUNCTION__
, __LINE__
);
194 out_be32((void*)GPIO0_OR
, in_be32((void*)GPIO0_OR
) | GPIO0_FPGA_FORCEINIT
);
195 /* disable PLD IOs */
196 out_be32((void*)GPIO1_OR
, in_be32((void*)GPIO1_OR
) | GPIO1_IOEN_N
);
202 * FPGA post configuration function. Blip the FPGA reset line and then see if
203 * the FPGA appears to be running.
205 int fpga_post_config_fn(int cookie
)
207 pmc440_fpga_t
*fpga
= (pmc440_fpga_t
*)FPGA_BA
;
211 debug("%s:%d: FPGA post configuration\n", __FUNCTION__
, __LINE__
);
213 /* enable PLD0..7 pins */
214 out_be32((void*)GPIO1_OR
, in_be32((void*)GPIO1_OR
) & ~GPIO1_IOEN_N
);
221 FPGA_OUT32(&fpga
->status
, (gd
->board_type
<< STATUS_HWREV_SHIFT
) & STATUS_HWREV_MASK
);
223 /* NGCC/CANDES only: enable ledlink */
224 if ((s
= getenv("bd_type")) &&
225 ((!strcmp(s
, "ngcc")) || (!strcmp(s
, "candes"))))
226 FPGA_SETBITS(&fpga
->ctrla
, 0x29f8c000);
232 int fpga_clk_fn(int assert_clk
, int flush
, int cookie
)
235 out_be32((void*)GPIO1_OR
, in_be32((void*)GPIO1_OR
) | GPIO1_FPGA_CLK
);
237 out_be32((void*)GPIO1_OR
, in_be32((void*)GPIO1_OR
) & ~GPIO1_FPGA_CLK
);
243 int fpga_wr_fn(int assert_write
, int flush
, int cookie
)
246 out_be32((void*)GPIO1_OR
, in_be32((void*)GPIO1_OR
) | GPIO1_FPGA_DATA
);
248 out_be32((void*)GPIO1_OR
, in_be32((void*)GPIO1_OR
) & ~GPIO1_FPGA_DATA
);
254 int fpga_wdata_fn(uchar data
, int flush
, int cookie
)
257 ulong
or = in_be32((void*)GPIO1_OR
);
262 or = (or & ~GPIO1_FPGA_CLK
) | GPIO1_FPGA_DATA
;
264 or = or & ~(GPIO1_FPGA_CLK
| GPIO1_FPGA_DATA
);
266 out_be32((void*)GPIO1_OR
, or);
268 /* Assert the clock */
269 or |= GPIO1_FPGA_CLK
;
270 out_be32((void*)GPIO1_OR
, or);
275 /* Write last data bit (the 8th clock comes from the sp_load() code */
277 or = (or & ~GPIO1_FPGA_CLK
) | GPIO1_FPGA_DATA
;
279 or = or & ~(GPIO1_FPGA_CLK
| GPIO1_FPGA_DATA
);
281 out_be32((void*)GPIO1_OR
, or);
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
293 void ngcc_fpga_serialslave_init(void)
295 debug("%s:%d: Initialize serial slave interface\n",
296 __FUNCTION__
, __LINE__
);
298 /* make sure program pin is inactive */
299 ngcc_fpga_pgm_fn (FALSE
, FALSE
, 0);
303 * Set the active-low FPGA reset signal.
305 void ngcc_fpga_reset(int assert)
307 debug("%s:%d: RESET ", __FUNCTION__
, __LINE__
);
310 FPGA_CLRBITS(NGCC_CTRL_BASE
, NGCC_CTRL_FPGARST_N
);
313 FPGA_SETBITS(NGCC_CTRL_BASE
, NGCC_CTRL_FPGARST_N
);
314 debug("deasserted\n");
320 * Set the FPGA's active-low SelectMap program line to the specified level
322 int ngcc_fpga_pgm_fn(int assert, int flush
, int cookie
)
324 pmc440_fpga_t
*fpga
= (pmc440_fpga_t
*)FPGA_BA
;
326 debug("%s:%d: FPGA PROGRAM ", __FUNCTION__
, __LINE__
);
329 FPGA_CLRBITS(&fpga
->ctrla
, NGCC_FPGA_PRG
);
332 FPGA_SETBITS(&fpga
->ctrla
, NGCC_FPGA_PRG
);
333 debug("deasserted\n");
341 * Test the state of the active-low FPGA INIT line. Return 1 on INIT
344 int ngcc_fpga_init_fn(int cookie
)
346 pmc440_fpga_t
*fpga
= (pmc440_fpga_t
*)FPGA_BA
;
348 debug("%s:%d: INIT check... ", __FUNCTION__
, __LINE__
);
349 if (FPGA_IN32(&fpga
->status
) & NGCC_FPGA_INIT
) {
360 * Test the state of the active-high FPGA DONE pin
362 int ngcc_fpga_done_fn(int cookie
)
364 pmc440_fpga_t
*fpga
= (pmc440_fpga_t
*)FPGA_BA
;
366 debug("%s:%d: DONE check... ", __FUNCTION__
, __LINE__
);
367 if (FPGA_IN32(&fpga
->status
) & NGCC_FPGA_DONE
) {
368 debug("DONE high\n");
378 * FPGA pre-configuration function.
380 int ngcc_fpga_pre_config_fn(int cookie
)
382 pmc440_fpga_t
*fpga
= (pmc440_fpga_t
*)FPGA_BA
;
383 debug("%s:%d: FPGA pre-configuration\n", __FUNCTION__
, __LINE__
);
385 ngcc_fpga_reset(TRUE
);
386 FPGA_CLRBITS(&fpga
->ctrla
, 0xfffffe00);
388 ngcc_fpga_reset(TRUE
);
394 * FPGA post configuration function. Blip the FPGA reset line and then see if
395 * the FPGA appears to be running.
397 int ngcc_fpga_post_config_fn(int cookie
)
399 pmc440_fpga_t
*fpga
= (pmc440_fpga_t
*)FPGA_BA
;
401 debug("%s:%d: NGCC FPGA post configuration\n", __FUNCTION__
, __LINE__
);
404 ngcc_fpga_reset(FALSE
);
406 FPGA_SETBITS(&fpga
->ctrla
, 0x29f8c000);
412 int ngcc_fpga_clk_fn(int assert_clk
, int flush
, int cookie
)
414 pmc440_fpga_t
*fpga
= (pmc440_fpga_t
*)FPGA_BA
;
417 FPGA_SETBITS(&fpga
->ctrla
, NGCC_FPGA_CLK
);
419 FPGA_CLRBITS(&fpga
->ctrla
, NGCC_FPGA_CLK
);
425 int ngcc_fpga_wr_fn(int assert_write
, int flush
, int cookie
)
427 pmc440_fpga_t
*fpga
= (pmc440_fpga_t
*)FPGA_BA
;
430 FPGA_SETBITS(&fpga
->ctrla
, NGCC_FPGA_DATA
);
432 FPGA_CLRBITS(&fpga
->ctrla
, NGCC_FPGA_DATA
);
439 * Initialize the fpga. Return 1 on success, 0 on failure.
441 int pmc440_init_fpga(void)
445 debug("%s:%d: Initialize FPGA interface (relocation offset = 0x%.8lx)\n",
446 __FUNCTION__
, __LINE__
, gd
->reloc_off
);
447 fpga_init(gd
->reloc_off
);
449 fpga_serialslave_init ();
450 debug("%s:%d: Adding fpga 0\n", __FUNCTION__
, __LINE__
);
451 fpga_add (fpga_xilinx
, &fpga
[0]);
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]);
462 #endif /* CONFIG_FPGA */