1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24#include <common.h>
25#include <mpc8260.h>
26#include <ioports.h>
27#include <malloc.h>
28#include <asm/io.h>
29
30#if defined(CONFIG_OF_BOARD_SETUP) && defined(CONFIG_OF_LIBFDT)
31#include <libfdt.h>
32#endif
33
34#include <i2c.h>
35#include "../common/common.h"
36
37
38
39
40
41
42
43const iop_conf_t iop_conf_tab[4][32] = {
44
45
46 {
47 { 0, 0, 0, 0, 0, 0 },
48 { 0, 0, 0, 0, 0, 0 },
49 { 0, 0, 0, 0, 0, 0 },
50 { 0, 0, 0, 0, 0, 0 },
51 { 0, 0, 0, 0, 0, 0 },
52 { 0, 0, 0, 0, 0, 0 },
53 { 0, 0, 0, 0, 0, 0 },
54 { 0, 0, 0, 0, 0, 0 },
55 { 0, 0, 0, 0, 0, 0 },
56 { 0, 0, 0, 0, 0, 0 },
57 { 0, 0, 0, 0, 0, 0 },
58 { 0, 0, 0, 0, 0, 0 },
59 { 0, 0, 0, 0, 0, 0 },
60 { 0, 0, 0, 0, 0, 0 },
61 { 0, 0, 0, 0, 0, 0 },
62 { 0, 0, 0, 0, 0, 0 },
63 { 0, 0, 0, 0, 0, 0 },
64 { 0, 0, 0, 0, 0, 0 },
65 { 0, 0, 0, 0, 0, 0 },
66 { 0, 0, 0, 0, 0, 0 },
67 { 0, 0, 0, 0, 0, 0 },
68 { 0, 0, 0, 0, 0, 0 },
69 { 1, 1, 0, 1, 0, 0 },
70 { 1, 1, 0, 0, 0, 0 },
71 { 0, 0, 0, 0, 0, 0 },
72 { 0, 0, 0, 0, 0, 0 },
73 { 0, 0, 0, 0, 0, 0 },
74 { 0, 0, 0, 0, 0, 0 },
75 { 0, 0, 0, 0, 0, 0 },
76 { 0, 0, 0, 0, 0, 0 },
77 { 0, 0, 0, 0, 0, 0 },
78 { 0, 0, 0, 0, 0, 0 }
79 },
80
81
82 {
83 { 0, 0, 0, 0, 0, 0 },
84 { 0, 0, 0, 0, 0, 0 },
85 { 0, 0, 0, 0, 0, 0 },
86 { 0, 0, 0, 0, 0, 0 },
87 { 0, 0, 0, 0, 0, 0 },
88 { 0, 0, 0, 0, 0, 0 },
89 { 0, 0, 0, 0, 0, 0 },
90 { 0, 0, 0, 0, 0, 0 },
91 { 0, 0, 0, 0, 0, 0 },
92 { 0, 0, 0, 0, 0, 0 },
93 { 0, 0, 0, 0, 0, 0 },
94 { 0, 0, 0, 0, 0, 0 },
95 { 0, 0, 0, 0, 0, 0 },
96 { 0, 0, 0, 0, 0, 0 },
97 { 0, 0, 0, 0, 0, 0 },
98 { 0, 0, 0, 0, 0, 0 },
99 { 0, 0, 0, 0, 0, 0 },
100 { 0, 0, 0, 0, 0, 0 },
101 { 0, 0, 0, 0, 0, 0 },
102 { 0, 0, 0, 0, 0, 0 },
103 { 0, 0, 0, 0, 0, 0 },
104 { 0, 0, 0, 0, 0, 0 },
105 { 0, 0, 0, 0, 0, 0 },
106 { 0, 0, 0, 0, 0, 0 },
107 { 0, 0, 0, 0, 0, 0 },
108 { 0, 0, 0, 0, 0, 0 },
109 { 0, 0, 0, 0, 0, 0 },
110 { 0, 0, 0, 0, 0, 0 },
111 { 0, 0, 0, 0, 0, 0 },
112 { 0, 0, 0, 0, 0, 0 },
113 { 0, 0, 0, 0, 0, 0 },
114 { 0, 0, 0, 0, 0, 0 }
115 },
116
117
118 {
119 { 0, 0, 0, 0, 0, 0 },
120 { 0, 0, 0, 0, 0, 0 },
121 { 0, 0, 0, 0, 0, 0 },
122 { 0, 0, 0, 0, 0, 0 },
123 { 0, 0, 0, 0, 0, 0 },
124 { 0, 0, 0, 0, 0, 0 },
125 { 1, 1, 0, 0, 0, 0 },
126 { 1, 1, 0, 0, 0, 0 },
127 { 0, 0, 0, 0, 0, 0 },
128 { 0, 0, 0, 0, 0, 0 },
129 { 0, 0, 0, 0, 0, 0 },
130 { 0, 0, 0, 0, 0, 0 },
131 { 0, 0, 0, 0, 0, 0 },
132 { 0, 0, 0, 0, 0, 0 },
133 { 0, 0, 0, 0, 0, 0 },
134 { 0, 0, 0, 0, 0, 0 },
135 { 0, 0, 0, 0, 0, 0 },
136 { 0, 0, 0, 0, 0, 0 },
137 { 0, 0, 0, 0, 0, 0 },
138 { 0, 0, 0, 0, 0, 0 },
139 { 0, 0, 0, 0, 0, 0 },
140 { 0, 0, 0, 0, 0, 0 },
141 { 1, 1, 0, 0, 0, 0 },
142 { 1, 1, 0, 0, 0, 0 },
143 { 0, 0, 0, 0, 0, 0 },
144 { 0, 0, 0, 0, 0, 0 },
145 { 0, 0, 0, 0, 0, 0 },
146 { 0, 0, 0, 0, 0, 0 },
147 { 0, 0, 0, 0, 0, 0 },
148 { 0, 0, 0, 0, 0, 0 },
149 { 0, 0, 0, 0, 0, 0 },
150 { 0, 0, 0, 0, 0, 0 },
151 },
152
153
154 {
155 { 0, 0, 0, 0, 0, 0 },
156 { 0, 0, 0, 0, 0, 0 },
157 { 0, 0, 0, 0, 0, 0 },
158 { 0, 0, 0, 0, 0, 0 },
159 { 0, 0, 0, 0, 0, 0 },
160 { 0, 0, 0, 0, 0, 0 },
161 { 0, 0, 0, 0, 0, 0 },
162 { 0, 0, 0, 0, 0, 0 },
163 { 0, 0, 0, 0, 0, 0 },
164 { 1, 1, 0, 0, 0, 0 },
165 { 1, 1, 0, 1, 0, 0 },
166 { 1, 1, 0, 1, 0, 0 },
167 { 0, 0, 0, 0, 0, 0 },
168 { 0, 0, 0, 0, 0, 0 },
169 { 0, 0, 0, 0, 0, 0 },
170 { 0, 0, 0, 0, 0, 0 },
171#if defined(CONFIG_HARD_I2C)
172 { 1, 1, 1, 0, 1, 0 },
173 { 1, 1, 1, 0, 1, 0 },
174#else
175 { 1, 0, 0, 0, 1, 1 },
176 { 1, 0, 0, 1, 1, 1 },
177#endif
178 { 0, 0, 0, 0, 0, 0 },
179 { 0, 0, 0, 0, 0, 0 },
180 { 0, 0, 0, 0, 0, 0 },
181 { 0, 0, 0, 0, 0, 0 },
182 { 0, 0, 0, 0, 0, 0 },
183 { 0, 0, 0, 0, 0, 0 },
184 { 0, 0, 0, 0, 0, 0 },
185 { 0, 0, 0, 0, 0, 0 },
186 { 0, 0, 0, 0, 0, 0 },
187 { 0, 0, 0, 0, 0, 0 },
188 { 0, 0, 0, 0, 0, 0 },
189 { 0, 0, 0, 0, 0, 0 },
190 { 0, 0, 0, 0, 0, 0 },
191 { 0, 0, 0, 0, 0, 0 }
192 }
193};
194
195
196
197
198
199
200
201
202
203static long int try_init(memctl8260_t *memctl, ulong sdmr,
204 ulong orx, uchar *base)
205{
206 uchar c = 0xff;
207 ulong maxsize, size;
208 int i;
209
210
211
212
213
214
215
216 maxsize = (1 + (~orx | 0x7fff));
217
218 out_be32(&memctl->memc_or1, orx);
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241 out_be32(&memctl->memc_psdmr, sdmr | PSDMR_OP_PREA);
242 out_8(base, c);
243
244 out_be32(&memctl->memc_psdmr, sdmr | PSDMR_OP_CBRR);
245 for (i = 0; i < 8; i++)
246 out_8(base, c);
247
248 out_be32(&memctl->memc_psdmr, sdmr | PSDMR_OP_MRW);
249
250 out_8((uchar *)(base + CONFIG_SYS_MRS_OFFS), c);
251
252 out_be32(&memctl->memc_psdmr, sdmr | PSDMR_OP_NORM | PSDMR_RFEN);
253 out_8(base, c);
254
255 size = get_ram_size((long *)base, maxsize);
256 out_be32(&memctl->memc_or1, orx | ~(size - 1));
257
258 return size;
259}
260
261#ifdef CONFIG_SYS_SDRAM_LIST
262
263
264
265
266
267
268
269
270
271
272
273struct sdram_conf_s {
274 ulong size;
275 int or1;
276 int psdmr;
277};
278
279static struct sdram_conf_s sdram_conf[] = CONFIG_SYS_SDRAM_LIST;
280
281static long probe_sdram(memctl8260_t *memctl)
282{
283 int n = 0;
284 long psize = 0;
285
286 for (n = 0; n < ARRAY_SIZE(sdram_conf); psize = 0, n++) {
287 psize = try_init(memctl,
288 CONFIG_SYS_PSDMR | sdram_conf[n].psdmr,
289 CONFIG_SYS_OR1 | sdram_conf[n].or1,
290 (uchar *) CONFIG_SYS_SDRAM_BASE);
291 debug("Probing %ld bytes returned %ld\n",
292 sdram_conf[n].size, psize);
293 if (psize == sdram_conf[n].size)
294 break;
295 }
296 return psize;
297}
298
299#else
300
301static long probe_sdram(memctl8260_t *memctl)
302{
303 return try_init(memctl, CONFIG_SYS_PSDMR, CONFIG_SYS_OR1,
304 (uchar *) CONFIG_SYS_SDRAM_BASE);
305}
306#endif
307
308
309phys_size_t initdram(int board_type)
310{
311 immap_t *immap = (immap_t *) CONFIG_SYS_IMMR;
312 memctl8260_t *memctl = &immap->im_memctl;
313
314 long psize;
315
316 out_8(&memctl->memc_psrt, CONFIG_SYS_PSRT);
317 out_be16(&memctl->memc_mptpr, CONFIG_SYS_MPTPR);
318
319#ifndef CONFIG_SYS_RAMBOOT
320
321
322 psize = probe_sdram(memctl);
323#endif
324
325 icache_enable();
326
327 return psize;
328}
329
330int checkboard(void)
331{
332#if defined(CONFIG_MGCOGE)
333 puts("Board: Keymile mgcoge");
334#else
335 puts("Board: Keymile mgcoge3ne");
336#endif
337 if (ethernet_present())
338 puts(" with PIGGY.");
339 puts("\n");
340 return 0;
341}
342
343int last_stage_init(void)
344{
345 struct bfticu_iomap *base =
346 (struct bfticu_iomap *)CONFIG_SYS_FPGA_BASE;
347 u8 dip_switch;
348
349 dip_switch = in_8(&base->mswitch);
350 dip_switch &= BFTICU_DIPSWITCH_MASK;
351
352 if (dip_switch & 0x1 || dip_switch & 0x2) {
353
354 puts("DIP: Enabled\n");
355 setenv("actual_bank", "0");
356 }
357 set_km_env();
358 return 0;
359}
360
361#ifdef CONFIG_MGCOGE3NE
362static void set_pin(int state, unsigned long mask);
363
364
365
366
367
368
369
370static void handle_mgcoge3un_reset(void)
371{
372 char *bobcatreset = getenv("bobcatreset");
373 if (bobcatreset) {
374 if (strcmp(bobcatreset, "true") == 0) {
375 puts("Forcing bobcat reset\n");
376 set_pin(0, 0x00000004);
377 udelay(1000);
378 set_pin(1, 0x00000004);
379 } else
380 set_pin(1, 0x00000004);
381 }
382}
383#endif
384
385int ethernet_present(void)
386{
387 struct km_bec_fpga *base =
388 (struct km_bec_fpga *)CONFIG_SYS_KMBEC_FPGA_BASE;
389
390 return in_8(&base->bprth) & PIGGY_PRESENT;
391}
392
393
394
395
396int board_early_init_r(void)
397{
398 struct km_bec_fpga *base =
399 (struct km_bec_fpga *)CONFIG_SYS_KMBEC_FPGA_BASE;
400
401
402
403 out_8(&base->oprth, (WRG_RESET | H_OPORTS_14 | WRG_LED));
404
405 out_8(&base->oprtl, (H_OPORTS_SCC4_ENA | H_OPORTS_SCC4_FD_ENA |
406 H_OPORTS_FCC1_PW_DWN));
407
408#ifdef CONFIG_MGCOGE3NE
409 handle_mgcoge3un_reset();
410#endif
411 return 0;
412}
413
414int hush_init_var(void)
415{
416 ivm_read_eeprom();
417 return 0;
418}
419
420#define SDA_MASK 0x00010000
421#define SCL_MASK 0x00020000
422
423static void set_pin(int state, unsigned long mask)
424{
425 ioport_t *iop = ioport_addr((immap_t *)CONFIG_SYS_IMMR, 3);
426
427 if (state)
428 setbits_be32(&iop->pdat, mask);
429 else
430 clrbits_be32(&iop->pdat, mask);
431
432 setbits_be32(&iop->pdir, mask);
433}
434
435static int get_pin(unsigned long mask)
436{
437 ioport_t *iop = ioport_addr((immap_t *)CONFIG_SYS_IMMR, 3);
438
439 clrbits_be32(&iop->pdir, mask);
440 return 0 != (in_be32(&iop->pdat) & mask);
441}
442
443void set_sda(int state)
444{
445 set_pin(state, SDA_MASK);
446}
447
448void set_scl(int state)
449{
450 set_pin(state, SCL_MASK);
451}
452
453int get_sda(void)
454{
455 return get_pin(SDA_MASK);
456}
457
458int get_scl(void)
459{
460 return get_pin(SCL_MASK);
461}
462
463#if defined(CONFIG_HARD_I2C)
464static void setports(int gpio)
465{
466 ioport_t *iop = ioport_addr((immap_t *)CONFIG_SYS_IMMR, 3);
467
468 if (gpio) {
469 clrbits_be32(&iop->ppar, (SDA_MASK | SCL_MASK));
470 clrbits_be32(&iop->podr, (SDA_MASK | SCL_MASK));
471 } else {
472 setbits_be32(&iop->ppar, (SDA_MASK | SCL_MASK));
473 clrbits_be32(&iop->pdir, (SDA_MASK | SCL_MASK));
474 setbits_be32(&iop->podr, (SDA_MASK | SCL_MASK));
475 }
476}
477#endif
478#if defined(CONFIG_OF_BOARD_SETUP) && defined(CONFIG_OF_LIBFDT)
479void ft_board_setup(void *blob, bd_t *bd)
480{
481 ft_cpu_setup(blob, bd);
482}
483#endif
484