1 // SPDX-License-Identifier: GPL-2.0+
4 * Eran Liberty, Extricom , eran.liberty@gmail.com
7 #include <common.h> /* core U-Boot definitions */
10 int StratixII_ps_fpp_load (Altera_desc * desc, void *buf, size_t bsize,
11 int isSerial, int isSecure);
12 int StratixII_ps_fpp_dump (Altera_desc * desc, void *buf, size_t bsize);
14 /****************************************************************/
15 /* Stratix II Generic Implementation */
16 int StratixII_load (Altera_desc * desc, void *buf, size_t bsize)
18 int ret_val = FPGA_FAIL;
20 switch (desc->iface) {
22 ret_val = StratixII_ps_fpp_load (desc, buf, bsize, 1, 0);
24 case fast_passive_parallel:
25 ret_val = StratixII_ps_fpp_load (desc, buf, bsize, 0, 0);
27 case fast_passive_parallel_security:
28 ret_val = StratixII_ps_fpp_load (desc, buf, bsize, 0, 1);
31 /* Add new interface types here */
33 printf ("%s: Unsupported interface type, %d\n", __FUNCTION__,
39 int StratixII_dump (Altera_desc * desc, void *buf, size_t bsize)
41 int ret_val = FPGA_FAIL;
43 switch (desc->iface) {
45 case fast_passive_parallel:
46 case fast_passive_parallel_security:
47 ret_val = StratixII_ps_fpp_dump (desc, buf, bsize);
49 /* Add new interface types here */
51 printf ("%s: Unsupported interface type, %d\n", __FUNCTION__,
57 int StratixII_info (Altera_desc * desc)
62 int StratixII_ps_fpp_dump (Altera_desc * desc, void *buf, size_t bsize)
64 printf ("Stratix II Fast Passive Parallel dump is not implemented\n");
68 int StratixII_ps_fpp_load (Altera_desc * desc, void *buf, size_t bsize,
69 int isSerial, int isSecure)
71 altera_board_specific_func *fns;
73 int ret_val = FPGA_FAIL;
79 printf ("%s(%d) Altera_desc missing\n", __FUNCTION__, __LINE__);
83 printf ("%s(%d) buffer is missing\n", __FUNCTION__, __LINE__);
87 printf ("%s(%d) size is zero\n", __FUNCTION__, __LINE__);
90 if (!desc->iface_fns) {
92 ("%s(%d) Altera_desc function interface table is missing\n",
93 __FUNCTION__, __LINE__);
96 fns = (altera_board_specific_func *) (desc->iface_fns);
97 cookie = desc->cookie;
100 (fns->config && fns->status && fns->done && fns->data
103 ("%s(%d) Missing some function in the function interface table\n",
104 __FUNCTION__, __LINE__);
108 /* 1. give board specific a chance to do anything before we start */
110 if ((ret_val = fns->pre (cookie)) < 0) {
115 /* from this point on we must fail gracfully by calling lower layer abort */
117 /* 2. Strat burn cycle by deasserting config for t_CFG and waiting t_CF2CK after reaserted */
118 fns->config (0, 1, cookie);
119 udelay (5); /* nCONFIG low pulse width 2usec */
120 fns->config (1, 1, cookie);
121 udelay (100); /* nCONFIG high to first rising edge on DCLK */
123 /* 3. Start the Data cycle with clk deasserted */
125 fns->clk (0, 1, cookie);
127 printf ("loading to fpga ");
128 while (bytecount < bsize) {
129 /* 3.1 check stratix has not signaled us an error */
130 if (fns->status (cookie) != 1) {
132 ("\n%s(%d) Stratix failed (byte transferred till failure 0x%x)\n",
133 __FUNCTION__, __LINE__, bytecount);
139 uint8_t data = buff[bytecount++];
140 for (i = 0; i < 8; i++) {
141 /* 3.2(ps) put data on the bus */
142 fns->data ((data >> i) & 1, 1, cookie);
144 /* 3.3(ps) clock once */
145 fns->clk (1, 1, cookie);
146 fns->clk (0, 1, cookie);
149 /* 3.2(fpp) put data on the bus */
150 fns->data (buff[bytecount++], 1, cookie);
152 /* 3.3(fpp) clock once */
153 fns->clk (1, 1, cookie);
154 fns->clk (0, 1, cookie);
156 /* 3.4(fpp) for secure cycle push 3 more clocks */
157 for (i = 0; isSecure && i < 3; i++) {
158 fns->clk (1, 1, cookie);
159 fns->clk (0, 1, cookie);
163 /* 3.5 while clk is deasserted it is safe to print some progress indication */
164 if ((bytecount % (bsize / 100)) == 0) {
165 printf ("\b\b\b%02d\%", bytecount * 100 / bsize);
169 /* 4. Set one last clock and check conf done signal */
170 fns->clk (1, 1, cookie);
172 if (!fns->done (cookie)) {
173 printf (" error!.\n");
177 printf ("\b\b\b done.\n");
180 /* 5. call lower layer post configuration */
182 if ((ret_val = fns->post (cookie)) < 0) {