1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27#include <common.h>
28#include <asm/asi.h>
29#include <asm/leon.h>
30#include <ambapp.h>
31
32#include <config.h>
33
34DECLARE_GLOBAL_DATA_PTR;
35
36
37void start(void);
38
39
40int init_memory_ctrl(void);
41
42ambapp_dev_irqmp *irqmp = NULL;
43ambapp_dev_mctrl memctrl;
44ambapp_dev_gptimer *gptimer = NULL;
45unsigned int gptimer_irq = 0;
46int leon3_snooping_avail = 0;
47
48struct {
49 gd_t gd_area;
50 bd_t bd;
51} global_data;
52
53
54
55
56
57
58
59
60
61
62
63
64
65void cpu_init_f(void)
66{
67
68 ambapp_dev_irqmp *irqmp;
69 ambapp_apbdev apbdev;
70 register unsigned int apbmst;
71
72
73 apbmst = (unsigned int)
74 ambapp_ahb_next_nomem(VENDOR_GAISLER, GAISLER_APBMST, 1, 0);
75 if (!apbmst) {
76
77
78
79
80 while (1) ;
81 }
82
83 if (init_memory_ctrl()) {
84 while (1) ;
85 }
86
87
88
89
90
91
92 if (ambapp_apb_first(VENDOR_GAISLER, GAISLER_IRQMP, &apbdev) != 1) {
93
94
95
96 while (1) ;
97 }
98 irqmp = (ambapp_dev_irqmp *) apbdev.address;
99
100
101 irqmp->ilevel = 0xf;
102 irqmp->iforce = 0;
103 irqmp->ipend = 0;
104 irqmp->iclear = 0xfffe;
105 irqmp->cpu_mask[0] = 0;
106 irqmp->cpu_force[0] = 0;
107
108
109}
110
111void cpu_init_f2(void)
112{
113
114}
115
116
117
118
119int cpu_init_r(void)
120{
121 ambapp_apbdev apbdev;
122
123
124
125
126
127 ambapp_apb_first(VENDOR_GAISLER, GAISLER_IRQMP, &apbdev);
128 irqmp = (ambapp_dev_irqmp *) apbdev.address;
129
130
131 if (ambapp_apb_first(VENDOR_GAISLER, GAISLER_GPTIMER, &apbdev) != 1) {
132 printf("cpu_init_r: gptimer not found!\n");
133 return 1;
134 }
135 gptimer = (ambapp_dev_gptimer *) apbdev.address;
136 gptimer_irq = apbdev.irq;
137
138
139 gptimer->scalar = gptimer->scalar_reload =
140 (((CONFIG_SYS_CLK_FREQ / 1000) + 500) / 1000) - 1;
141
142 return (0);
143}
144
145
146int init_memory_ctrl()
147{
148 register ambapp_dev_mctrl *mctrl;
149 register ambapp_dev_sdctrl *sdctrl;
150 register ambapp_dev_ddrspa *ddrspa;
151 register ambapp_dev_ddr2spa *ddr2spa;
152 register ahbctrl_pp_dev *ahb;
153 register unsigned int base;
154 register int not_found_mctrl = -1;
155
156
157 base = ambapp_apb_next_nomem(VENDOR_ESA, ESA_MCTRL, 0);
158 if (base) {
159 mctrl = (ambapp_dev_mctrl *) base;
160
161
162 mctrl->mcfg1 = CONFIG_SYS_GRLIB_MEMCFG1 | (mctrl->mcfg1 & 0x300);
163 mctrl->mcfg2 = CONFIG_SYS_GRLIB_MEMCFG2;
164 mctrl->mcfg3 = CONFIG_SYS_GRLIB_MEMCFG3;
165 not_found_mctrl = 0;
166 }
167
168
169 base = ambapp_apb_next_nomem(VENDOR_GAISLER, GAISLER_FTMCTRL, 0);
170 if (base) {
171 mctrl = (ambapp_dev_mctrl *) base;
172
173
174 mctrl->mcfg1 = CONFIG_SYS_GRLIB_FT_MEMCFG1 | (mctrl->mcfg1 & 0x300);
175 mctrl->mcfg2 = CONFIG_SYS_GRLIB_FT_MEMCFG2;
176 mctrl->mcfg3 = CONFIG_SYS_GRLIB_FT_MEMCFG3;
177 not_found_mctrl = 0;
178 }
179
180
181 base = ambapp_apb_next_nomem(VENDOR_GAISLER, GAISLER_SDCTRL, 0);
182 if (base) {
183 sdctrl = (ambapp_dev_sdctrl *) base;
184
185
186 sdctrl->sdcfg = CONFIG_SYS_GRLIB_SDRAM;
187 not_found_mctrl = 0;
188 }
189
190 ahb = ambapp_ahb_next_nomem(VENDOR_GAISLER, GAISLER_DDR2SPA, 1, 0);
191 if (ahb) {
192 ddr2spa = (ambapp_dev_ddr2spa *) ambapp_ahb_get_info(ahb, 1);
193
194
195 ddr2spa->cfg1 = CONFIG_SYS_GRLIB_DDR2_CFG1;
196 ddr2spa->cfg3 = CONFIG_SYS_GRLIB_DDR2_CFG3;
197 not_found_mctrl = 0;
198 }
199
200 ahb = ambapp_ahb_next_nomem(VENDOR_GAISLER, GAISLER_DDRSPA, 1, 0);
201 if (ahb) {
202 ddrspa = (ambapp_dev_ddrspa *) ambapp_ahb_get_info(ahb, 1);
203
204
205 ddrspa->ctrl = CONFIG_SYS_GRLIB_DDR_CFG;
206 not_found_mctrl = 0;
207 }
208
209
210 return not_found_mctrl;
211}
212
213
214
215
216
217void cpu_wait_ticks(unsigned long ticks)
218{
219 unsigned long start = get_timer(0);
220 while (get_timer(start) < ticks) ;
221}
222
223
224
225
226
227int timer_interrupt_init_cpu(void)
228{
229
230 gptimer->e[0].val = 0;
231 gptimer->e[0].rld = 999;
232 gptimer->e[0].ctrl =
233 (LEON3_GPTIMER_EN |
234 LEON3_GPTIMER_RL | LEON3_GPTIMER_LD | LEON3_GPTIMER_IRQEN);
235
236 return gptimer_irq;
237}
238
239
240
241
242unsigned long cpu_usec2ticks(unsigned long usec)
243{
244
245 if (usec < 1000)
246 return 1;
247 return (usec / 1000);
248}
249
250unsigned long cpu_ticks2usec(unsigned long ticks)
251{
252
253 return ticks * 1000;
254}
255