3 * Rich Ireland, Enterasys Networks, rireland@enterasys.com.
4 * Keith Outwater, keith_outwater@mvis.com.
6 * See file CREDITS for list of people who contributed to this
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License as
11 * published by the Free Software Foundation; either version 2 of
12 * the License, or (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
27 * Virtex2 FPGA configuration support for the GEN860T computer
35 DECLARE_GLOBAL_DATA_PTR;
37 #if defined(CONFIG_FPGA)
40 #define GEN860T_FPGA_DEBUG
43 #ifdef GEN860T_FPGA_DEBUG
44 #define PRINTF(fmt,args...) printf (fmt ,##args)
46 #define PRINTF(fmt,args...)
50 * Port bit numbers for the Selectmap controls
52 #define FPGA_INIT_BIT_NUM 22 /* PB22 */
53 #define FPGA_RESET_BIT_NUM 11 /* PC11 */
54 #define FPGA_DONE_BIT_NUM 16 /* PB16 */
55 #define FPGA_PROGRAM_BIT_NUM 7 /* PA7 */
57 /* Note that these are pointers to code that is in Flash. They will be
58 * relocated at runtime.
60 Xilinx_Virtex2_Slave_SelectMap_fns fpga_fns = {
76 Xilinx_desc fpga[CONFIG_FPGA_COUNT] = {
85 * Display FPGA revision information
87 void print_fpga_revision (void)
89 vu_long *rev_p = (vu_long *) 0x60000008;
91 printf ("FPGA Revision 0x%.8lx"
92 " (Date %.2lx/%.2lx/%.2lx, Status \"%.1lx\", Version %.3lu)\n",
94 ((*rev_p >> 28) & 0xf),
95 ((*rev_p >> 20) & 0xff),
96 ((*rev_p >> 12) & 0xff),
97 ((*rev_p >> 8) & 0xf), (*rev_p & 0xff));
102 * Perform a simple test of the FPGA to processor interface using the FPGA's
103 * inverting bus test register. The great thing about doing a read/write
104 * test on a register that inverts it's contents is that you avoid any
105 * problems with bus charging.
106 * Return 0 on failure, 1 on success.
108 int test_fpga_ibtr (void)
110 vu_long *ibtr_p = (vu_long *) 0x60000010;
118 static const ulong bitpattern[] = {
119 0xdeadbeef, /* magic ID pattern for debug */
120 0x00000001, /* single bit */
121 0x00000003, /* two adjacent bits */
122 0x00000007, /* three adjacent bits */
123 0x0000000F, /* four adjacent bits */
124 0x00000005, /* two non-adjacent bits */
125 0x00000015, /* three non-adjacent bits */
126 0x00000055, /* four non-adjacent bits */
127 0xaaaaaaaa, /* alternating 1/0 */
130 for (i = 0; i < 1024; i++) {
131 for (j = 0; j < 31; j++) {
133 k < sizeof (bitpattern) / sizeof (bitpattern[0]);
135 *ibtr_p = compare = (bitpattern[k] << j);
137 if (readback != ~compare) {
138 printf ("%s:%d: FPGA test fail: expected 0x%.8lx" " actual 0x%.8lx\n", __FUNCTION__, __LINE__, ~compare, readback);
150 printf ("FPGA inverting bus test passed\n");
151 print_fpga_revision ();
153 printf ("** FPGA inverting bus test failed\n");
160 * Set the active-low FPGA reset signal.
162 void fpga_reset (int assert)
164 volatile immap_t *immap = (immap_t *) CFG_IMMR;
166 PRINTF ("%s:%d: RESET ", __FUNCTION__, __LINE__);
168 immap->im_ioport.iop_pcdat &= ~(0x8000 >> FPGA_RESET_BIT_NUM);
169 PRINTF ("asserted\n");
171 immap->im_ioport.iop_pcdat |= (0x8000 >> FPGA_RESET_BIT_NUM);
172 PRINTF ("deasserted\n");
178 * Initialize the SelectMap interface. We assume that the mode and the
179 * initial state of all of the port pins have already been set!
181 void fpga_selectmap_init (void)
183 PRINTF ("%s:%d: Initialize SelectMap interface\n", __FUNCTION__,
185 fpga_pgm_fn (FALSE, FALSE, 0); /* make sure program pin is inactive */
190 * Initialize the fpga. Return 1 on success, 0 on failure.
192 int gen860t_init_fpga (void)
196 PRINTF ("%s:%d: Initialize FPGA interface (relocation offset = 0x%.8lx)\n", __FUNCTION__, __LINE__, gd->reloc_off);
197 fpga_init (gd->reloc_off);
198 fpga_selectmap_init ();
200 for (i = 0; i < CONFIG_FPGA_COUNT; i++) {
201 PRINTF ("%s:%d: Adding fpga %d\n", __FUNCTION__, __LINE__, i);
202 fpga_add (fpga_xilinx, &fpga[i]);
209 * Set the FPGA's active-low SelectMap program line to the specified level
211 int fpga_pgm_fn (int assert, int flush, int cookie)
213 volatile immap_t *immap = (immap_t *) CFG_IMMR;
215 PRINTF ("%s:%d: FPGA PROGRAM ", __FUNCTION__, __LINE__);
218 immap->im_ioport.iop_padat &=
219 ~(0x8000 >> FPGA_PROGRAM_BIT_NUM);
220 PRINTF ("asserted\n");
222 immap->im_ioport.iop_padat |=
223 (0x8000 >> FPGA_PROGRAM_BIT_NUM);
224 PRINTF ("deasserted\n");
231 * Test the state of the active-low FPGA INIT line. Return 1 on INIT
234 int fpga_init_fn (int cookie)
236 volatile immap_t *immap = (immap_t *) CFG_IMMR;
238 PRINTF ("%s:%d: INIT check... ", __FUNCTION__, __LINE__);
239 if (immap->im_cpm.cp_pbdat & (0x80000000 >> FPGA_INIT_BIT_NUM)) {
250 * Test the state of the active-high FPGA DONE pin
252 int fpga_done_fn (int cookie)
254 volatile immap_t *immap = (immap_t *) CFG_IMMR;
256 PRINTF ("%s:%d: DONE check... ", __FUNCTION__, __LINE__);
257 if (immap->im_cpm.cp_pbdat & (0x80000000 >> FPGA_DONE_BIT_NUM)) {
268 * Read FPGA SelectMap data.
270 int fpga_read_data_fn (unsigned char *data, int cookie)
272 vu_char *p = (vu_char *) SELECTMAP_BASE;
276 PRINTF ("%s: Read 0x%x into 0x%p\n", __FUNCTION__, (int) data, data);
283 * Write data to the FPGA SelectMap port
285 int fpga_write_data_fn (unsigned char data, int flush, int cookie)
287 vu_char *p = (vu_char *) SELECTMAP_BASE;
290 PRINTF ("%s: Write Data 0x%x\n", __FUNCTION__, (int) data);
298 * Abort and FPGA operation
300 int fpga_abort_fn (int cookie)
302 PRINTF ("%s:%d: FPGA program sequence aborted\n",
303 __FUNCTION__, __LINE__);
309 * FPGA pre-configuration function. Just make sure that
310 * FPGA reset is asserted to keep the FPGA from starting up after
313 int fpga_pre_config_fn (int cookie)
315 PRINTF ("%s:%d: FPGA pre-configuration\n", __FUNCTION__, __LINE__);
322 * FPGA post configuration function. Blip the FPGA reset line and then see if
323 * the FPGA appears to be running.
325 int fpga_post_config_fn (int cookie)
329 PRINTF ("%s:%d: FPGA post configuration\n", __FUNCTION__, __LINE__);
336 * Use the FPGA,s inverting bus test register to do a simple test of the
337 * processor interface.
339 rc = test_fpga_ibtr ();
345 * Clock, chip select and write signal assert functions and error check
346 * and busy functions. These are only stubs because the GEN860T selectmap
347 * interface handles sequencing of control signals automatically (it uses
348 * a memory-mapped interface to the FPGA SelectMap port). The design of
349 * the interface guarantees that the SelectMap port cannot be overrun so
350 * no busy check is needed. A configuration error is signalled by INIT
351 * going low during configuration, so there is no need for a separate error
354 int fpga_clk_fn (int assert_clk, int flush, int cookie)
359 int fpga_cs_fn (int assert_cs, int flush, int cookie)
364 int fpga_wr_fn (int assert_write, int flush, int cookie)
369 int fpga_err_fn (int cookie)
374 int fpga_busy_fn (int cookie)
380 /* vim: set ts=4 tw=78 sw=4: */