3 * Eran Liberty, Extricom , eran.liberty@gmail.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,
25 #include <common.h> /* core U-Boot definitions */
28 int StratixII_ps_fpp_load (Altera_desc * desc, void *buf, size_t bsize,
29 int isSerial, int isSecure);
30 int StratixII_ps_fpp_dump (Altera_desc * desc, void *buf, size_t bsize);
32 /****************************************************************/
33 /* Stratix II Generic Implementation */
34 int StratixII_load (Altera_desc * desc, void *buf, size_t bsize)
36 int ret_val = FPGA_FAIL;
38 switch (desc->iface) {
40 ret_val = StratixII_ps_fpp_load (desc, buf, bsize, 1, 0);
42 case fast_passive_parallel:
43 ret_val = StratixII_ps_fpp_load (desc, buf, bsize, 0, 0);
45 case fast_passive_parallel_security:
46 ret_val = StratixII_ps_fpp_load (desc, buf, bsize, 0, 1);
49 /* Add new interface types here */
51 printf ("%s: Unsupported interface type, %d\n", __FUNCTION__,
57 int StratixII_dump (Altera_desc * desc, void *buf, size_t bsize)
59 int ret_val = FPGA_FAIL;
61 switch (desc->iface) {
63 case fast_passive_parallel:
64 case fast_passive_parallel_security:
65 ret_val = StratixII_ps_fpp_dump (desc, buf, bsize);
67 /* Add new interface types here */
69 printf ("%s: Unsupported interface type, %d\n", __FUNCTION__,
75 int StratixII_info (Altera_desc * desc)
80 int StratixII_ps_fpp_dump (Altera_desc * desc, void *buf, size_t bsize)
82 printf ("Stratix II Fast Passive Parallel dump is not implemented\n");
86 int StratixII_ps_fpp_load (Altera_desc * desc, void *buf, size_t bsize,
87 int isSerial, int isSecure)
89 altera_board_specific_func *fns;
91 int ret_val = FPGA_FAIL;
97 printf ("%s(%d) Altera_desc missing\n", __FUNCTION__, __LINE__);
101 printf ("%s(%d) buffer is missing\n", __FUNCTION__, __LINE__);
105 printf ("%s(%d) size is zero\n", __FUNCTION__, __LINE__);
108 if (!desc->iface_fns) {
110 ("%s(%d) Altera_desc function interface table is missing\n",
111 __FUNCTION__, __LINE__);
114 fns = (altera_board_specific_func *) (desc->iface_fns);
115 cookie = desc->cookie;
118 (fns->config && fns->status && fns->done && fns->data
121 ("%s(%d) Missing some function in the function interface table\n",
122 __FUNCTION__, __LINE__);
126 /* 1. give board specific a chance to do anything before we start */
128 if ((ret_val = fns->pre (cookie)) < 0) {
133 /* from this point on we must fail gracfully by calling lower layer abort */
135 /* 2. Strat burn cycle by deasserting config for t_CFG and waiting t_CF2CK after reaserted */
136 fns->config (0, 1, cookie);
137 udelay (5); /* nCONFIG low pulse width 2usec */
138 fns->config (1, 1, cookie);
139 udelay (100); /* nCONFIG high to first rising edge on DCLK */
141 /* 3. Start the Data cycle with clk deasserted */
143 fns->clk (0, 1, cookie);
145 printf ("loading to fpga ");
146 while (bytecount < bsize) {
147 /* 3.1 check stratix has not signaled us an error */
148 if (fns->status (cookie) != 1) {
150 ("\n%s(%d) Stratix failed (byte transfered till failure 0x%x)\n",
151 __FUNCTION__, __LINE__, bytecount);
157 uint8_t data = buff[bytecount++];
158 for (i = 0; i < 8; i++) {
159 /* 3.2(ps) put data on the bus */
160 fns->data ((data >> i) & 1, 1, cookie);
162 /* 3.3(ps) clock once */
163 fns->clk (1, 1, cookie);
164 fns->clk (0, 1, cookie);
167 /* 3.2(fpp) put data on the bus */
168 fns->data (buff[bytecount++], 1, cookie);
170 /* 3.3(fpp) clock once */
171 fns->clk (1, 1, cookie);
172 fns->clk (0, 1, cookie);
174 /* 3.4(fpp) for secure cycle push 3 more clocks */
175 for (i = 0; isSecure && i < 3; i++) {
176 fns->clk (1, 1, cookie);
177 fns->clk (0, 1, cookie);
181 /* 3.5 while clk is deasserted it is safe to print some progress indication */
182 if ((bytecount % (bsize / 100)) == 0) {
183 printf ("\b\b\b%02d\%", bytecount * 100 / bsize);
187 /* 4. Set one last clock and check conf done signal */
188 fns->clk (1, 1, cookie);
190 if (!fns->done (cookie)) {
191 printf (" error!.\n");
195 printf ("\b\b\b done.\n");
198 /* 5. call lower layer post configuration */
200 if ((ret_val = fns->post (cookie)) < 0) {