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 only: enable ledlink */
224 if ((s
= getenv("bd_type")) && !strcmp(s
, "ngcc"))
225 FPGA_SETBITS(&fpga
->ctrla
, 0x29f8c000);
231 int fpga_clk_fn(int assert_clk
, int flush
, int cookie
)
234 out_be32((void*)GPIO1_OR
, in_be32((void*)GPIO1_OR
) | GPIO1_FPGA_CLK
);
236 out_be32((void*)GPIO1_OR
, in_be32((void*)GPIO1_OR
) & ~GPIO1_FPGA_CLK
);
242 int fpga_wr_fn(int assert_write
, int flush
, int cookie
)
245 out_be32((void*)GPIO1_OR
, in_be32((void*)GPIO1_OR
) | GPIO1_FPGA_DATA
);
247 out_be32((void*)GPIO1_OR
, in_be32((void*)GPIO1_OR
) & ~GPIO1_FPGA_DATA
);
253 int fpga_wdata_fn(uchar data
, int flush
, int cookie
)
256 ulong
or = in_be32((void*)GPIO1_OR
);
261 or = (or & ~GPIO1_FPGA_CLK
) | GPIO1_FPGA_DATA
;
263 or = or & ~(GPIO1_FPGA_CLK
| GPIO1_FPGA_DATA
);
265 out_be32((void*)GPIO1_OR
, or);
267 /* Assert the clock */
268 or |= GPIO1_FPGA_CLK
;
269 out_be32((void*)GPIO1_OR
, or);
274 /* Write last data bit (the 8th clock comes from the sp_load() code */
276 or = (or & ~GPIO1_FPGA_CLK
) | GPIO1_FPGA_DATA
;
278 or = or & ~(GPIO1_FPGA_CLK
| GPIO1_FPGA_DATA
);
280 out_be32((void*)GPIO1_OR
, or);
286 #define NGCC_FPGA_PRG CLOCK_EN
287 #define NGCC_FPGA_DATA RESET_OUT
288 #define NGCC_FPGA_DONE CLOCK_IN
289 #define NGCC_FPGA_INIT IRIGB_R_IN
290 #define NGCC_FPGA_CLK CLOCK_OUT
292 void ngcc_fpga_serialslave_init(void)
294 debug("%s:%d: Initialize serial slave interface\n",
295 __FUNCTION__
, __LINE__
);
297 /* make sure program pin is inactive */
298 ngcc_fpga_pgm_fn (FALSE
, FALSE
, 0);
302 * Set the active-low FPGA reset signal.
304 void ngcc_fpga_reset(int assert)
306 debug("%s:%d: RESET ", __FUNCTION__
, __LINE__
);
309 FPGA_CLRBITS(NGCC_CTRL_BASE
, NGCC_CTRL_FPGARST_N
);
312 FPGA_SETBITS(NGCC_CTRL_BASE
, NGCC_CTRL_FPGARST_N
);
313 debug("deasserted\n");
319 * Set the FPGA's active-low SelectMap program line to the specified level
321 int ngcc_fpga_pgm_fn(int assert, int flush
, int cookie
)
323 pmc440_fpga_t
*fpga
= (pmc440_fpga_t
*)FPGA_BA
;
325 debug("%s:%d: FPGA PROGRAM ", __FUNCTION__
, __LINE__
);
328 FPGA_CLRBITS(&fpga
->ctrla
, NGCC_FPGA_PRG
);
331 FPGA_SETBITS(&fpga
->ctrla
, NGCC_FPGA_PRG
);
332 debug("deasserted\n");
340 * Test the state of the active-low FPGA INIT line. Return 1 on INIT
343 int ngcc_fpga_init_fn(int cookie
)
345 pmc440_fpga_t
*fpga
= (pmc440_fpga_t
*)FPGA_BA
;
347 debug("%s:%d: INIT check... ", __FUNCTION__
, __LINE__
);
348 if (FPGA_IN32(&fpga
->status
) & NGCC_FPGA_INIT
) {
359 * Test the state of the active-high FPGA DONE pin
361 int ngcc_fpga_done_fn(int cookie
)
363 pmc440_fpga_t
*fpga
= (pmc440_fpga_t
*)FPGA_BA
;
365 debug("%s:%d: DONE check... ", __FUNCTION__
, __LINE__
);
366 if (FPGA_IN32(&fpga
->status
) & NGCC_FPGA_DONE
) {
367 debug("DONE high\n");
377 * FPGA pre-configuration function.
379 int ngcc_fpga_pre_config_fn(int cookie
)
381 pmc440_fpga_t
*fpga
= (pmc440_fpga_t
*)FPGA_BA
;
382 debug("%s:%d: FPGA pre-configuration\n", __FUNCTION__
, __LINE__
);
384 ngcc_fpga_reset(TRUE
);
385 FPGA_CLRBITS(&fpga
->ctrla
, 0xfffffe00);
387 ngcc_fpga_reset(TRUE
);
393 * FPGA post configuration function. Blip the FPGA reset line and then see if
394 * the FPGA appears to be running.
396 int ngcc_fpga_post_config_fn(int cookie
)
398 pmc440_fpga_t
*fpga
= (pmc440_fpga_t
*)FPGA_BA
;
400 debug("%s:%d: NGCC FPGA post configuration\n", __FUNCTION__
, __LINE__
);
403 ngcc_fpga_reset(FALSE
);
405 FPGA_SETBITS(&fpga
->ctrla
, 0x29f8c000);
411 int ngcc_fpga_clk_fn(int assert_clk
, int flush
, int cookie
)
413 pmc440_fpga_t
*fpga
= (pmc440_fpga_t
*)FPGA_BA
;
416 FPGA_SETBITS(&fpga
->ctrla
, NGCC_FPGA_CLK
);
418 FPGA_CLRBITS(&fpga
->ctrla
, NGCC_FPGA_CLK
);
424 int ngcc_fpga_wr_fn(int assert_write
, int flush
, int cookie
)
426 pmc440_fpga_t
*fpga
= (pmc440_fpga_t
*)FPGA_BA
;
429 FPGA_SETBITS(&fpga
->ctrla
, NGCC_FPGA_DATA
);
431 FPGA_CLRBITS(&fpga
->ctrla
, NGCC_FPGA_DATA
);
438 * Initialize the fpga. Return 1 on success, 0 on failure.
440 int pmc440_init_fpga(void)
444 debug("%s:%d: Initialize FPGA interface (relocation offset = 0x%.8lx)\n",
445 __FUNCTION__
, __LINE__
, gd
->reloc_off
);
446 fpga_init(gd
->reloc_off
);
448 fpga_serialslave_init ();
449 debug("%s:%d: Adding fpga 0\n", __FUNCTION__
, __LINE__
);
450 fpga_add (fpga_xilinx
, &fpga
[0]);
453 if ((s
= getenv("bd_type")) && !strcmp(s
, "ngcc")) {
454 ngcc_fpga_serialslave_init ();
455 debug("%s:%d: Adding fpga 1\n", __FUNCTION__
, __LINE__
);
456 fpga_add (fpga_xilinx
, &fpga
[1]);
461 #endif /* CONFIG_FPGA */