1
2
3
4
5
6
7#include <common.h>
8#include <altera.h>
9#include <linux/delay.h>
10
11int StratixII_ps_fpp_load (Altera_desc * desc, void *buf, size_t bsize,
12 int isSerial, int isSecure);
13int StratixII_ps_fpp_dump (Altera_desc * desc, void *buf, size_t bsize);
14
15
16
17int StratixII_load (Altera_desc * desc, void *buf, size_t bsize)
18{
19 int ret_val = FPGA_FAIL;
20
21 switch (desc->iface) {
22 case passive_serial:
23 ret_val = StratixII_ps_fpp_load (desc, buf, bsize, 1, 0);
24 break;
25 case fast_passive_parallel:
26 ret_val = StratixII_ps_fpp_load (desc, buf, bsize, 0, 0);
27 break;
28 case fast_passive_parallel_security:
29 ret_val = StratixII_ps_fpp_load (desc, buf, bsize, 0, 1);
30 break;
31
32
33 default:
34 printf ("%s: Unsupported interface type, %d\n", __FUNCTION__,
35 desc->iface);
36 }
37 return ret_val;
38}
39
40int StratixII_dump (Altera_desc * desc, void *buf, size_t bsize)
41{
42 int ret_val = FPGA_FAIL;
43
44 switch (desc->iface) {
45 case passive_serial:
46 case fast_passive_parallel:
47 case fast_passive_parallel_security:
48 ret_val = StratixII_ps_fpp_dump (desc, buf, bsize);
49 break;
50
51 default:
52 printf ("%s: Unsupported interface type, %d\n", __FUNCTION__,
53 desc->iface);
54 }
55 return ret_val;
56}
57
58int StratixII_info (Altera_desc * desc)
59{
60 return FPGA_SUCCESS;
61}
62
63int StratixII_ps_fpp_dump (Altera_desc * desc, void *buf, size_t bsize)
64{
65 printf ("Stratix II Fast Passive Parallel dump is not implemented\n");
66 return FPGA_FAIL;
67}
68
69int StratixII_ps_fpp_load (Altera_desc * desc, void *buf, size_t bsize,
70 int isSerial, int isSecure)
71{
72 altera_board_specific_func *fns;
73 int cookie;
74 int ret_val = FPGA_FAIL;
75 int bytecount;
76 char *buff = buf;
77 int i;
78
79 if (!desc) {
80 printf ("%s(%d) Altera_desc missing\n", __FUNCTION__, __LINE__);
81 return FPGA_FAIL;
82 }
83 if (!buff) {
84 printf ("%s(%d) buffer is missing\n", __FUNCTION__, __LINE__);
85 return FPGA_FAIL;
86 }
87 if (!bsize) {
88 printf ("%s(%d) size is zero\n", __FUNCTION__, __LINE__);
89 return FPGA_FAIL;
90 }
91 if (!desc->iface_fns) {
92 printf
93 ("%s(%d) Altera_desc function interface table is missing\n",
94 __FUNCTION__, __LINE__);
95 return FPGA_FAIL;
96 }
97 fns = (altera_board_specific_func *) (desc->iface_fns);
98 cookie = desc->cookie;
99
100 if (!
101 (fns->config && fns->status && fns->done && fns->data
102 && fns->abort)) {
103 printf
104 ("%s(%d) Missing some function in the function interface table\n",
105 __FUNCTION__, __LINE__);
106 return FPGA_FAIL;
107 }
108
109
110 if (fns->pre) {
111 if ((ret_val = fns->pre (cookie)) < 0) {
112 return ret_val;
113 }
114 }
115
116
117
118
119 fns->config (0, 1, cookie);
120 udelay(5);
121 fns->config (1, 1, cookie);
122 udelay(100);
123
124
125 bytecount = 0;
126 fns->clk (0, 1, cookie);
127
128 printf ("loading to fpga ");
129 while (bytecount < bsize) {
130
131 if (fns->status (cookie) != 1) {
132 printf
133 ("\n%s(%d) Stratix failed (byte transferred till failure 0x%x)\n",
134 __FUNCTION__, __LINE__, bytecount);
135 fns->abort (cookie);
136 return FPGA_FAIL;
137 }
138 if (isSerial) {
139 int i;
140 uint8_t data = buff[bytecount++];
141 for (i = 0; i < 8; i++) {
142
143 fns->data ((data >> i) & 1, 1, cookie);
144
145
146 fns->clk (1, 1, cookie);
147 fns->clk (0, 1, cookie);
148 }
149 } else {
150
151 fns->data (buff[bytecount++], 1, cookie);
152
153
154 fns->clk (1, 1, cookie);
155 fns->clk (0, 1, cookie);
156
157
158 for (i = 0; isSecure && i < 3; i++) {
159 fns->clk (1, 1, cookie);
160 fns->clk (0, 1, cookie);
161 }
162 }
163
164
165 if ((bytecount % (bsize / 100)) == 0) {
166 printf ("\b\b\b%02d\%", bytecount * 100 / bsize);
167 }
168 }
169
170
171 fns->clk (1, 1, cookie);
172 udelay(100);
173 if (!fns->done (cookie)) {
174 printf (" error!.\n");
175 fns->abort (cookie);
176 return FPGA_FAIL;
177 } else {
178 printf ("\b\b\b done.\n");
179 }
180
181
182 if (fns->post) {
183 if ((ret_val = fns->post (cookie)) < 0) {
184 fns->abort (cookie);
185 return ret_val;
186 }
187 }
188
189 return FPGA_SUCCESS;
190}
191