]>
git.ipfire.org Git - people/ms/u-boot.git/blob - board/siemens/common/fpga.c
3 * Wolfgang Grandegger, DENX Software Engineering, wg@denx.de.
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,
27 #include <linux/ctype.h>
32 int power_on_reset(void);
34 /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
37 static int fpga_get_version(fpga_t
* fpga
, char* name
)
41 * Net-list string format:
42 * "vvvvvvvvddddddddn...".
44 * "0000000322042002PUMA" = PUMA version 3 from 22.04.2002.
46 if (strlen(name
) < (16 + strlen(fpga
->name
)))
49 if (strcmp(&name
[16], fpga
->name
) != 0)
51 /* Get version number */
52 memcpy(vname
, name
, 8);
54 return simple_strtoul(vname
, NULL
, 16);
57 printf("Image name %s is invalid\n", name
);
61 /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
63 static fpga_t
* fpga_get(char* fpga_name
)
65 char name
[FPGA_NAME_LEN
];
68 if (strlen(fpga_name
) >= FPGA_NAME_LEN
)
70 for (i
= 0; i
< strlen(fpga_name
); i
++)
71 name
[i
] = toupper(fpga_name
[i
]);
73 for (i
= 0; i
< fpga_count
; i
++) {
74 if (strcmp(name
, fpga_list
[i
].name
) == 0)
78 printf("FPGA: name %s is invalid\n", fpga_name
);
82 /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
84 static void fpga_status (fpga_t
* fpga
)
87 if (fpga_control(fpga
, FPGA_DONE_IS_HIGH
))
88 printf ("%s is loaded (%08lx)\n",
89 fpga
->name
, fpga_control(fpga
, FPGA_GET_ID
));
91 printf ("%s is NOT loaded\n", fpga
->name
);
94 /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
96 #define FPGA_RESET_TIMEOUT 100 /* = 10 ms */
98 static int fpga_reset (fpga_t
* fpga
)
102 /* Set PROG to low and wait til INIT goes low */
103 fpga_control(fpga
, FPGA_PROG_SET_LOW
);
104 for (i
= 0; i
< FPGA_RESET_TIMEOUT
; i
++) {
106 if (!fpga_control(fpga
, FPGA_INIT_IS_HIGH
))
109 if (i
== FPGA_RESET_TIMEOUT
)
112 /* Set PROG to high and wait til INIT goes high */
113 fpga_control(fpga
, FPGA_PROG_SET_HIGH
);
114 for (i
= 0; i
< FPGA_RESET_TIMEOUT
; i
++) {
116 if (fpga_control(fpga
, FPGA_INIT_IS_HIGH
))
119 if (i
== FPGA_RESET_TIMEOUT
)
127 /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
129 #define FPGA_LOAD_TIMEOUT 100 /* = 10 ms */
131 static int fpga_load (fpga_t
* fpga
, ulong addr
, int checkall
)
133 volatile uchar
*fpga_addr
= (volatile uchar
*)fpga
->conf_base
;
134 image_header_t
*hdr
= (image_header_t
*)addr
;
140 #if defined(CONFIG_FIT)
141 if (genimg_get_format ((void *)hdr
) != IMAGE_FORMAT_LEGACY
) {
142 puts ("Non legacy image format not supported\n");
148 * Check the image header and data of the net-list
150 if (!image_check_magic (hdr
)) {
151 strcpy (msg
, "Bad Image Magic Number");
155 if (!image_check_hcrc (hdr
)) {
156 strcpy (msg
, "Bad Image Header CRC");
160 data
= (uchar
*)image_get_data (hdr
);
161 len
= image_get_data_size (hdr
);
163 verify
= getenv_yesno ("verify");
165 if (!image_check_dcrc (hdr
)) {
166 strcpy (msg
, "Bad Image Data CRC");
171 if (checkall
&& fpga_get_version(fpga
, image_get_name (hdr
)) < 0)
179 * Reset FPGA and wait for completion
181 if (fpga_reset(fpga
)) {
182 strcpy (msg
, "Reset Timeout");
186 printf ("(%s)... ", image_get_name (hdr
));
190 fpga_control (fpga
, FPGA_LOAD_MODE
);
192 *fpga_addr
= *data
++;
194 fpga_control (fpga
, FPGA_READ_MODE
);
197 * Wait for completion and check error status if timeout
199 for (i
= 0; i
< FPGA_LOAD_TIMEOUT
; i
++) {
201 if (fpga_control (fpga
, FPGA_DONE_IS_HIGH
))
204 if (i
== FPGA_LOAD_TIMEOUT
) {
205 if (fpga_control(fpga
, FPGA_INIT_IS_HIGH
))
206 strcpy(msg
, "Invalid Size");
208 strcpy(msg
, "CRC Error");
217 printf("ERROR: %s\n", msg
);
221 #if defined(CONFIG_CMD_BSP)
223 /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
225 int do_fpga (cmd_tbl_t
*cmdtp
, int flag
, int argc
, char *argv
[])
234 if (strncmp(argv
[1], "stat", 4) == 0) { /* status */
236 for (i
= 0; i
< fpga_count
; i
++) {
237 fpga_status (&fpga_list
[i
]);
240 else if (argc
== 3) {
241 if ((fpga
= fpga_get(argv
[2])) == 0)
248 else if (strcmp(argv
[1],"load") == 0) { /* load */
249 if (argc
== 3 && fpga_count
== 1) {
250 fpga
= &fpga_list
[0];
252 else if (argc
== 4) {
253 if ((fpga
= fpga_get(argv
[2])) == 0)
259 addr
= simple_strtoul(argv
[argc
-1], NULL
, 16);
261 printf ("FPGA load %s: addr %08lx: ",
263 fpga_load (fpga
, addr
, 1);
266 else if (strncmp(argv
[1], "rese", 4) == 0) { /* reset */
267 if (argc
== 2 && fpga_count
== 1) {
268 fpga
= &fpga_list
[0];
270 else if (argc
== 3) {
271 if ((fpga
= fpga_get(argv
[2])) == 0)
277 printf ("FPGA reset %s: ", fpga
->name
);
278 if (fpga_reset(fpga
))
279 printf ("ERROR: Timeout\n");
296 "fpga status [name] - print FPGA status\n"
297 "fpga reset [name] - reset FPGA\n"
298 "fpga load [name] addr - load FPGA configuration data\n"
303 /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
308 ulong new_id
, old_id
= 0;
315 * Port setup for FPGA control
317 for (i
= 0; i
< fpga_count
; i
++) {
318 fpga_control(&fpga_list
[i
], FPGA_INIT_PORTS
);
322 * Load FPGA(s): a new net-list is loaded if the FPGA is
323 * empty, Power-on-Reset or the old one is not up-to-date
325 for (i
= 0; i
< fpga_count
; i
++) {
326 fpga
= &fpga_list
[i
];
327 printf ("%s: ", fpga
->name
);
329 for (j
= 0; j
< strlen(fpga
->name
); j
++)
330 name
[j
] = tolower(fpga
->name
[j
]);
332 sprintf(name
, "%s_addr", name
);
334 if ((s
= getenv(name
)) != NULL
)
335 addr
= simple_strtoul(s
, NULL
, 16);
338 printf ("env. variable %s undefined\n", name
);
342 hdr
= (image_header_t
*)addr
;
343 #if defined(CONFIG_FIT)
344 if (genimg_get_format ((void *)hdr
) != IMAGE_FORMAT_LEGACY
) {
345 puts ("Non legacy image format not supported\n");
350 if ((new_id
= fpga_get_version(fpga
, image_get_name (hdr
))) == -1)
355 if (!power_on_reset() && fpga_control(fpga
, FPGA_DONE_IS_HIGH
)) {
356 old_id
= fpga_control(fpga
, FPGA_GET_ID
);
357 if (new_id
== old_id
)
363 fpga_load (fpga
, addr
, 0);
365 printf ("loaded (%08lx)\n", old_id
);