blob: b779a09e828d445ecd35655ce721be33dcaddc2d [file] [log] [blame]
wdenk16f21702002-08-26 21:58:50 +00001/*
2 * (C) Copyright 2001
3 * Stefan Roese, esd gmbh germany, stefan.roese@esd-electronics.com
4 *
Wolfgang Denkd79de1d2013-07-08 09:37:19 +02005 * SPDX-License-Identifier: GPL-2.0+
wdenk16f21702002-08-26 21:58:50 +00006 */
7
8#include <common.h>
Ben Warren840f8a52008-08-31 10:45:44 -07009#include <netdev.h>
wdenk16f21702002-08-26 21:58:50 +000010#include "dasa_sim.h"
11
12/* ------------------------------------------------------------------------- */
13
14#undef FPGA_DEBUG
15
16#define _NOT_USED_ 0xFFFFFFFF
17
18/* ------------------------------------------------------------------------- */
19
20/* fpga configuration data - generated by bit2inc */
21static unsigned char fpgadata[] = {
22#include "fpgadata.c"
23};
24
25#define FPGA_PRG_SLEEP 32 /* fpga program sleep-time */
26#define LOAD_LONG(a) a
27
28
29/******************************************************************************
30 *
31 * sysFpgaBoot - Load fpga-image into fpga
32 *
33 */
34static int fpgaBoot (void)
35{
36 int i, j, index, len;
37 unsigned char b;
38 int imageSize;
39
40 imageSize = sizeof (fpgadata);
41
42 /* display infos on fpgaimage */
43 index = 15;
44 for (i = 0; i < 4; i++) {
45 len = fpgadata[index];
46 index += len + 3;
47 }
48
49 /* search for preamble 0xFF2X */
50 for (index = 0; index < imageSize - 1; index++) {
51 if ((fpgadata[index] == 0xff)
52 && ((fpgadata[index + 1] & 0xf0) == 0x20))
53 break;
54 }
55
56 /* enable cs1 instead of user0... */
57 *(unsigned long *) 0x50000084 &= ~0x00000002;
58
59#ifdef FPGA_DEBUG
60 printf ("%s\n",
Matthias Fuchsfaac7432009-02-20 10:19:18 +010061 ((in_be32 ((void *)0x50000084) & 0x00010000) == 0) ?
62 "NOT DONE" : "DONE");
wdenk16f21702002-08-26 21:58:50 +000063#endif
64
65 /* init fpga by asserting and deasserting PROGRAM* (USER2)... */
66 *(unsigned long *) 0x50000084 &= ~0x00000400;
67 udelay (FPGA_PRG_SLEEP * 1000);
68
69 *(unsigned long *) 0x50000084 |= 0x00000400;
70 udelay (FPGA_PRG_SLEEP * 1000);
71
72#ifdef FPGA_DEBUG
73 printf ("%s\n",
Matthias Fuchsfaac7432009-02-20 10:19:18 +010074 ((in_be32 ((void *)0x50000084) & 0x00010000) == 0) ?
75 "NOT DONE" : "DONE");
wdenk16f21702002-08-26 21:58:50 +000076#endif
77
78 /* cs1: disable burst, disable ready */
79 *(unsigned long *) 0x50000114 &= ~0x00000300;
80
81 /* cs1: set write timing */
82 *(unsigned long *) 0x50000118 |= 0x00010900;
83
84 /* write configuration-data into fpga... */
85 for (i = index; i < imageSize; i++) {
86 b = fpgadata[i];
87 for (j = 0; j < 8; j++) {
88 *(unsigned long *) 0x30000000 =
89 ((b & 0x80) == 0x80)
90 ? LOAD_LONG (0x03030101)
91 : LOAD_LONG (0x02020000);
92 b <<= 1;
93 }
94 }
95
96#ifdef FPGA_DEBUG
97 printf ("%s\n",
Matthias Fuchsfaac7432009-02-20 10:19:18 +010098 ((in_be32 ((void *)0x50000084) & 0x00010000) == 0) ?
99 "NOT DONE" : "DONE");
wdenk16f21702002-08-26 21:58:50 +0000100#endif
101
102 /* set cs1 to 32 bit data-width, disable burst, enable ready */
103 *(unsigned long *) 0x50000114 |= 0x00000202;
104 *(unsigned long *) 0x50000114 &= ~0x00000100;
105
106 /* cs1: set iop access to little endian */
107 *(unsigned long *) 0x50000114 &= ~0x00000010;
108
109 /* cs1: set read and write timing */
110 *(unsigned long *) 0x50000118 = 0x00010000;
111 *(unsigned long *) 0x5000011c = 0x00010001;
112
113#ifdef FPGA_DEBUG
114 printf ("%s\n",
Matthias Fuchsfaac7432009-02-20 10:19:18 +0100115 ((in_be32 ((void *)0x50000084) & 0x00010000) == 0) ?
116 "NOT DONE" : "DONE");
wdenk16f21702002-08-26 21:58:50 +0000117#endif
118
119 /* wait for 30 ms... */
120 udelay (30 * 1000);
121 /* check if fpga's DONE signal - correctly booted ? */
122 if ((*(unsigned long *) 0x50000084 & 0x00010000) == 0)
123 return -1;
124
125 return 0;
126}
127
128
wdenkda55c6e2004-01-20 23:12:12 +0000129int board_early_init_f (void)
wdenk16f21702002-08-26 21:58:50 +0000130{
131 /*
132 * Init pci regs
133 */
134 *(unsigned long *) 0x50000304 = 0x02900007; /* enable mem/io/master bits */
135 *(unsigned long *) 0x500001b4 = 0x00000000; /* disable pci interrupt output enable */
136 *(unsigned long *) 0x50000354 = 0x00c05800; /* disable emun interrupt output enable */
137 *(unsigned long *) 0x50000344 = 0x00000000; /* disable pme interrupt output enable */
138 *(unsigned long *) 0x50000310 = 0x00000000; /* pcibar0 */
139 *(unsigned long *) 0x50000314 = 0x00000000; /* pcibar1 */
140 *(unsigned long *) 0x50000318 = 0x00000000; /* pcibar2 */
141
142 return 0;
143}
144
145
146/*
147 * Check Board Identity:
148 */
149
150int checkboard (void)
151{
152 int index;
153 int len;
Wolfgang Denk7fb52662005-10-13 16:45:02 +0200154 char str[64];
Wolfgang Denk76af2782010-07-24 21:55:43 +0200155 int i = getenv_f("serial#", str, sizeof (str));
wdenk16f21702002-08-26 21:58:50 +0000156 int fpga;
157 unsigned short val;
158
159 puts ("Board: ");
160
161 /*
162 * Boot onboard FPGA
163 */
164 fpga = fpgaBoot ();
165
166 if (!i || strncmp (str, "DASA_SIM", 8)) {
167 puts ("### No HW ID - assuming DASA_SIM");
168 }
169
170 puts (str);
171
172 if (fpga == 0) {
173 val = *(unsigned short *) 0x30000202;
174 printf (" (Id=%d Version=%d Revision=%d)",
175 (val & 0x07f8) >> 3, val & 0x0001, (val & 0x0006) >> 1);
176
177 puts ("\nFPGA: ");
178
179 /* display infos on fpgaimage */
180 index = 15;
181 for (i = 0; i < 4; i++) {
182 len = fpgadata[index];
183 printf ("%s ", &(fpgadata[index + 1]));
184 index += len + 3;
185 }
186 } else {
187 puts ("\nFPGA: Booting failed!");
188 }
189
190 putc ('\n');
191
192 return 0;
193}
194
Becky Brucebd99ae72008-06-09 16:03:40 -0500195phys_size_t initdram (int board_type)
wdenk16f21702002-08-26 21:58:50 +0000196{
197 return (16 * 1024 * 1024);
198}