3 * Eran Liberty, Extricom , eran.liberty@gmail.com
5 * SPDX-License-Identifier: GPL-2.0+
8 #include <common.h> /* core U-Boot definitions */
11 int StratixII_ps_fpp_load (Altera_desc
* desc
, void *buf
, size_t bsize
,
12 int isSerial
, int isSecure
);
13 int StratixII_ps_fpp_dump (Altera_desc
* desc
, void *buf
, size_t bsize
);
15 /****************************************************************/
16 /* Stratix II Generic Implementation */
17 int StratixII_load (Altera_desc
* desc
, void *buf
, size_t bsize
)
19 int ret_val
= FPGA_FAIL
;
21 switch (desc
->iface
) {
23 ret_val
= StratixII_ps_fpp_load (desc
, buf
, bsize
, 1, 0);
25 case fast_passive_parallel
:
26 ret_val
= StratixII_ps_fpp_load (desc
, buf
, bsize
, 0, 0);
28 case fast_passive_parallel_security
:
29 ret_val
= StratixII_ps_fpp_load (desc
, buf
, bsize
, 0, 1);
32 /* Add new interface types here */
34 printf ("%s: Unsupported interface type, %d\n", __FUNCTION__
,
40 int StratixII_dump (Altera_desc
* desc
, void *buf
, size_t bsize
)
42 int ret_val
= FPGA_FAIL
;
44 switch (desc
->iface
) {
46 case fast_passive_parallel
:
47 case fast_passive_parallel_security
:
48 ret_val
= StratixII_ps_fpp_dump (desc
, buf
, bsize
);
50 /* Add new interface types here */
52 printf ("%s: Unsupported interface type, %d\n", __FUNCTION__
,
58 int StratixII_info (Altera_desc
* desc
)
63 int StratixII_ps_fpp_dump (Altera_desc
* desc
, void *buf
, size_t bsize
)
65 printf ("Stratix II Fast Passive Parallel dump is not implemented\n");
69 int StratixII_ps_fpp_load (Altera_desc
* desc
, void *buf
, size_t bsize
,
70 int isSerial
, int isSecure
)
72 altera_board_specific_func
*fns
;
74 int ret_val
= FPGA_FAIL
;
80 printf ("%s(%d) Altera_desc missing\n", __FUNCTION__
, __LINE__
);
84 printf ("%s(%d) buffer is missing\n", __FUNCTION__
, __LINE__
);
88 printf ("%s(%d) size is zero\n", __FUNCTION__
, __LINE__
);
91 if (!desc
->iface_fns
) {
93 ("%s(%d) Altera_desc function interface table is missing\n",
94 __FUNCTION__
, __LINE__
);
97 fns
= (altera_board_specific_func
*) (desc
->iface_fns
);
98 cookie
= desc
->cookie
;
101 (fns
->config
&& fns
->status
&& fns
->done
&& fns
->data
104 ("%s(%d) Missing some function in the function interface table\n",
105 __FUNCTION__
, __LINE__
);
109 /* 1. give board specific a chance to do anything before we start */
111 if ((ret_val
= fns
->pre (cookie
)) < 0) {
116 /* from this point on we must fail gracfully by calling lower layer abort */
118 /* 2. Strat burn cycle by deasserting config for t_CFG and waiting t_CF2CK after reaserted */
119 fns
->config (0, 1, cookie
);
120 udelay (5); /* nCONFIG low pulse width 2usec */
121 fns
->config (1, 1, cookie
);
122 udelay (100); /* nCONFIG high to first rising edge on DCLK */
124 /* 3. Start the Data cycle with clk deasserted */
126 fns
->clk (0, 1, cookie
);
128 printf ("loading to fpga ");
129 while (bytecount
< bsize
) {
130 /* 3.1 check stratix has not signaled us an error */
131 if (fns
->status (cookie
) != 1) {
133 ("\n%s(%d) Stratix failed (byte transfered till failure 0x%x)\n",
134 __FUNCTION__
, __LINE__
, bytecount
);
140 uint8_t data
= buff
[bytecount
++];
141 for (i
= 0; i
< 8; i
++) {
142 /* 3.2(ps) put data on the bus */
143 fns
->data ((data
>> i
) & 1, 1, cookie
);
145 /* 3.3(ps) clock once */
146 fns
->clk (1, 1, cookie
);
147 fns
->clk (0, 1, cookie
);
150 /* 3.2(fpp) put data on the bus */
151 fns
->data (buff
[bytecount
++], 1, cookie
);
153 /* 3.3(fpp) clock once */
154 fns
->clk (1, 1, cookie
);
155 fns
->clk (0, 1, cookie
);
157 /* 3.4(fpp) for secure cycle push 3 more clocks */
158 for (i
= 0; isSecure
&& i
< 3; i
++) {
159 fns
->clk (1, 1, cookie
);
160 fns
->clk (0, 1, cookie
);
164 /* 3.5 while clk is deasserted it is safe to print some progress indication */
165 if ((bytecount
% (bsize
/ 100)) == 0) {
166 printf ("\b\b\b%02d\%", bytecount
* 100 / bsize
);
170 /* 4. Set one last clock and check conf done signal */
171 fns
->clk (1, 1, cookie
);
173 if (!fns
->done (cookie
)) {
174 printf (" error!.\n");
178 printf ("\b\b\b done.\n");
181 /* 5. call lower layer post configuration */
183 if ((ret_val
= fns
->post (cookie
)) < 0) {