blob: c2a7a5f99577fe18196c7cf3277888842aa8d10d [file] [log] [blame]
Heiko Schocherac9db062008-01-11 01:12:08 +01001/*
Heiko Schocher0809ea22008-10-15 09:34:05 +02002 * (C) Copyright 2007 - 2008
Heiko Schocherac9db062008-01-11 01:12:08 +01003 * Heiko Schocher, DENX Software Engineering, hs@denx.de.
4 *
Wolfgang Denk1a459662013-07-08 09:37:19 +02005 * SPDX-License-Identifier: GPL-2.0+
Heiko Schocherac9db062008-01-11 01:12:08 +01006 */
7
8#include <common.h>
9#include <mpc8260.h>
10#include <ioports.h>
Heiko Schocher9661bf92008-10-15 09:36:03 +020011#include <malloc.h>
Heiko Schocher9e299192008-10-17 12:15:55 +020012#include <asm/io.h>
Heiko Schocherac9db062008-01-11 01:12:08 +010013
Heiko Schocherac9db062008-01-11 01:12:08 +010014#include <libfdt.h>
Heiko Schocher9661bf92008-10-15 09:36:03 +020015#include <i2c.h>
Heiko Schocher210c8c02008-11-21 08:29:40 +010016#include "../common/common.h"
17
Valentin Longchamp2973b092015-02-10 17:10:17 +010018static uchar ivm_content[CONFIG_SYS_IVM_EEPROM_MAX_LEN];
19
Heiko Schocherac9db062008-01-11 01:12:08 +010020/*
21 * I/O Port configuration table
22 *
23 * if conf is 1, then that port pin will be configured at boot time
24 * according to the five values podr/pdir/ppar/psor/pdat for that entry
25 */
26const iop_conf_t iop_conf_tab[4][32] = {
27
Holger Brunck2220e6c2011-04-08 02:47:25 +000028 /* Port A */
29 { /* conf ppar psor pdir podr pdat */
30 { 0, 0, 0, 0, 0, 0 }, /* PA31 */
31 { 0, 0, 0, 0, 0, 0 }, /* PA30 */
32 { 0, 0, 0, 0, 0, 0 }, /* PA29 */
33 { 0, 0, 0, 0, 0, 0 }, /* PA28 */
34 { 0, 0, 0, 0, 0, 0 }, /* PA27 */
35 { 0, 0, 0, 0, 0, 0 }, /* PA26 */
36 { 0, 0, 0, 0, 0, 0 }, /* PA25 */
37 { 0, 0, 0, 0, 0, 0 }, /* PA24 */
38 { 0, 0, 0, 0, 0, 0 }, /* PA23 */
39 { 0, 0, 0, 0, 0, 0 }, /* PA22 */
40 { 0, 0, 0, 0, 0, 0 }, /* PA21 */
41 { 0, 0, 0, 0, 0, 0 }, /* PA20 */
42 { 0, 0, 0, 0, 0, 0 }, /* PA19 */
43 { 0, 0, 0, 0, 0, 0 }, /* PA18 */
44 { 0, 0, 0, 0, 0, 0 }, /* PA17 */
45 { 0, 0, 0, 0, 0, 0 }, /* PA16 */
46 { 0, 0, 0, 0, 0, 0 }, /* PA15 */
47 { 0, 0, 0, 0, 0, 0 }, /* PA14 */
48 { 0, 0, 0, 0, 0, 0 }, /* PA13 */
49 { 0, 0, 0, 0, 0, 0 }, /* PA12 */
50 { 0, 0, 0, 0, 0, 0 }, /* PA11 */
51 { 0, 0, 0, 0, 0, 0 }, /* PA10 */
52 { 1, 1, 0, 1, 0, 0 }, /* PA9 SMC2 TxD */
53 { 1, 1, 0, 0, 0, 0 }, /* PA8 SMC2 RxD */
54 { 0, 0, 0, 0, 0, 0 }, /* PA7 */
55 { 0, 0, 0, 0, 0, 0 }, /* PA6 */
56 { 0, 0, 0, 0, 0, 0 }, /* PA5 */
57 { 0, 0, 0, 0, 0, 0 }, /* PA4 */
58 { 0, 0, 0, 0, 0, 0 }, /* PA3 */
59 { 0, 0, 0, 0, 0, 0 }, /* PA2 */
60 { 0, 0, 0, 0, 0, 0 }, /* PA1 */
61 { 0, 0, 0, 0, 0, 0 } /* PA0 */
62 },
Heiko Schocherac9db062008-01-11 01:12:08 +010063
Holger Brunck2220e6c2011-04-08 02:47:25 +000064 /* Port B */
65 { /* conf ppar psor pdir podr pdat */
66 { 0, 0, 0, 0, 0, 0 }, /* PB31 */
67 { 0, 0, 0, 0, 0, 0 }, /* PB30 */
68 { 0, 0, 0, 0, 0, 0 }, /* PB29 */
69 { 0, 0, 0, 0, 0, 0 }, /* PB28 */
70 { 0, 0, 0, 0, 0, 0 }, /* PB27 */
71 { 0, 0, 0, 0, 0, 0 }, /* PB26 */
72 { 0, 0, 0, 0, 0, 0 }, /* PB25 */
73 { 0, 0, 0, 0, 0, 0 }, /* PB24 */
74 { 0, 0, 0, 0, 0, 0 }, /* PB23 */
75 { 0, 0, 0, 0, 0, 0 }, /* PB22 */
76 { 0, 0, 0, 0, 0, 0 }, /* PB21 */
77 { 0, 0, 0, 0, 0, 0 }, /* PB20 */
78 { 0, 0, 0, 0, 0, 0 }, /* PB19 */
79 { 0, 0, 0, 0, 0, 0 }, /* PB18 */
80 { 0, 0, 0, 0, 0, 0 }, /* non-existent */
81 { 0, 0, 0, 0, 0, 0 }, /* non-existent */
82 { 0, 0, 0, 0, 0, 0 }, /* non-existent */
83 { 0, 0, 0, 0, 0, 0 }, /* non-existent */
84 { 0, 0, 0, 0, 0, 0 }, /* non-existent */
85 { 0, 0, 0, 0, 0, 0 }, /* non-existent */
86 { 0, 0, 0, 0, 0, 0 }, /* non-existent */
87 { 0, 0, 0, 0, 0, 0 }, /* non-existent */
88 { 0, 0, 0, 0, 0, 0 }, /* non-existent */
89 { 0, 0, 0, 0, 0, 0 }, /* non-existent */
90 { 0, 0, 0, 0, 0, 0 }, /* non-existent */
91 { 0, 0, 0, 0, 0, 0 }, /* non-existent */
92 { 0, 0, 0, 0, 0, 0 }, /* non-existent */
93 { 0, 0, 0, 0, 0, 0 }, /* non-existent */
94 { 0, 0, 0, 0, 0, 0 }, /* non-existent */
95 { 0, 0, 0, 0, 0, 0 }, /* non-existent */
96 { 0, 0, 0, 0, 0, 0 }, /* non-existent */
97 { 0, 0, 0, 0, 0, 0 } /* non-existent */
98 },
Heiko Schocherac9db062008-01-11 01:12:08 +010099
Holger Brunck2220e6c2011-04-08 02:47:25 +0000100 /* Port C */
101 { /* conf ppar psor pdir podr pdat */
102 { 0, 0, 0, 0, 0, 0 }, /* PC31 */
103 { 0, 0, 0, 0, 0, 0 }, /* PC30 */
104 { 0, 0, 0, 0, 0, 0 }, /* PC29 */
105 { 0, 0, 0, 0, 0, 0 }, /* PC28 */
106 { 0, 0, 0, 0, 0, 0 }, /* PC27 */
107 { 0, 0, 0, 0, 0, 0 }, /* PC26 */
108 { 1, 1, 0, 0, 0, 0 }, /* PC25 RxClk */
109 { 1, 1, 0, 0, 0, 0 }, /* PC24 TxClk */
110 { 0, 0, 0, 0, 0, 0 }, /* PC23 */
111 { 0, 0, 0, 0, 0, 0 }, /* PC22 */
112 { 0, 0, 0, 0, 0, 0 }, /* PC21 */
113 { 0, 0, 0, 0, 0, 0 }, /* PC20 */
114 { 0, 0, 0, 0, 0, 0 }, /* PC19 */
115 { 0, 0, 0, 0, 0, 0 }, /* PC18 */
116 { 0, 0, 0, 0, 0, 0 }, /* PC17 */
117 { 0, 0, 0, 0, 0, 0 }, /* PC16 */
118 { 0, 0, 0, 0, 0, 0 }, /* PC15 */
119 { 0, 0, 0, 0, 0, 0 }, /* PC14 */
120 { 0, 0, 0, 0, 0, 0 }, /* PC13 */
121 { 0, 0, 0, 0, 0, 0 }, /* PC12 */
122 { 0, 0, 0, 0, 0, 0 }, /* PC11 */
123 { 0, 0, 0, 0, 0, 0 }, /* PC10 */
124 { 1, 1, 0, 0, 0, 0 }, /* PC9 SCC4: CTS */
125 { 1, 1, 0, 0, 0, 0 }, /* PC8 SCC4: CD */
126 { 0, 0, 0, 0, 0, 0 }, /* PC7 */
127 { 0, 0, 0, 0, 0, 0 }, /* PC6 */
128 { 0, 0, 0, 0, 0, 0 }, /* PC5 */
129 { 0, 0, 0, 0, 0, 0 }, /* PC4 */
130 { 0, 0, 0, 0, 0, 0 }, /* PC3 */
131 { 0, 0, 0, 0, 0, 0 }, /* PC2 */
132 { 0, 0, 0, 0, 0, 0 }, /* PC1 */
133 { 0, 0, 0, 0, 0, 0 }, /* PC0 */
134 },
Heiko Schocherac9db062008-01-11 01:12:08 +0100135
Holger Brunck2220e6c2011-04-08 02:47:25 +0000136 /* Port D */
137 { /* conf ppar psor pdir podr pdat */
138 { 0, 0, 0, 0, 0, 0 }, /* PD31 */
139 { 0, 0, 0, 0, 0, 0 }, /* PD30 */
140 { 0, 0, 0, 0, 0, 0 }, /* PD29 */
141 { 0, 0, 0, 0, 0, 0 }, /* PD28 */
142 { 0, 0, 0, 0, 0, 0 }, /* PD27 */
143 { 0, 0, 0, 0, 0, 0 }, /* PD26 */
144 { 0, 0, 0, 0, 0, 0 }, /* PD25 */
145 { 0, 0, 0, 0, 0, 0 }, /* PD24 */
146 { 0, 0, 0, 0, 0, 0 }, /* PD23 */
147 { 1, 1, 0, 0, 0, 0 }, /* PD22 SCC4: RXD */
148 { 1, 1, 0, 1, 0, 0 }, /* PD21 SCC4: TXD */
149 { 1, 1, 0, 1, 0, 0 }, /* PD20 SCC4: RTS */
150 { 0, 0, 0, 0, 0, 0 }, /* PD19 */
151 { 0, 0, 0, 0, 0, 0 }, /* PD18 */
152 { 0, 0, 0, 0, 0, 0 }, /* PD17 */
153 { 0, 0, 0, 0, 0, 0 }, /* PD16 */
Heiko Schocher9661bf92008-10-15 09:36:03 +0200154#if defined(CONFIG_HARD_I2C)
Holger Brunck2220e6c2011-04-08 02:47:25 +0000155 { 1, 1, 1, 0, 1, 0 }, /* PD15 I2C SDA */
156 { 1, 1, 1, 0, 1, 0 }, /* PD14 I2C SCL */
Heiko Schocher9661bf92008-10-15 09:36:03 +0200157#else
Holger Brunck2220e6c2011-04-08 02:47:25 +0000158 { 1, 0, 0, 0, 1, 1 }, /* PD15 */
159 { 1, 0, 0, 1, 1, 1 }, /* PD14 */
Heiko Schocher9661bf92008-10-15 09:36:03 +0200160#endif
Holger Brunck2220e6c2011-04-08 02:47:25 +0000161 { 0, 0, 0, 0, 0, 0 }, /* PD13 */
162 { 0, 0, 0, 0, 0, 0 }, /* PD12 */
163 { 0, 0, 0, 0, 0, 0 }, /* PD11 */
164 { 0, 0, 0, 0, 0, 0 }, /* PD10 */
165 { 0, 0, 0, 0, 0, 0 }, /* PD9 */
166 { 0, 0, 0, 0, 0, 0 }, /* PD8 */
167 { 0, 0, 0, 0, 0, 0 }, /* PD7 */
168 { 0, 0, 0, 0, 0, 0 }, /* PD6 */
169 { 0, 0, 0, 0, 0, 0 }, /* PD5 */
170 { 0, 0, 0, 0, 0, 0 }, /* PD4 */
171 { 0, 0, 0, 0, 0, 0 }, /* non-existent */
172 { 0, 0, 0, 0, 0, 0 }, /* non-existent */
173 { 0, 0, 0, 0, 0, 0 }, /* non-existent */
174 { 0, 0, 0, 0, 0, 0 } /* non-existent */
175 }
Heiko Schocherac9db062008-01-11 01:12:08 +0100176};
177
Heiko Schocherb11f53f2011-03-15 16:52:29 +0100178/*
179 * Try SDRAM initialization with P/LSDMR=sdmr and ORx=orx
Heiko Schocherac9db062008-01-11 01:12:08 +0100180 *
181 * This routine performs standard 8260 initialization sequence
182 * and calculates the available memory size. It may be called
183 * several times to try different SDRAM configurations on both
184 * 60x and local buses.
185 */
Heiko Schocherb11f53f2011-03-15 16:52:29 +0100186static long int try_init(memctl8260_t *memctl, ulong sdmr,
187 ulong orx, uchar *base)
Heiko Schocherac9db062008-01-11 01:12:08 +0100188{
Heiko Schocherb11f53f2011-03-15 16:52:29 +0100189 uchar c = 0xff;
Heiko Schocherac9db062008-01-11 01:12:08 +0100190 ulong maxsize, size;
191 int i;
192
Heiko Schocherb11f53f2011-03-15 16:52:29 +0100193 /*
194 * We must be able to test a location outsize the maximum legal size
Heiko Schocherac9db062008-01-11 01:12:08 +0100195 * to find out THAT we are outside; but this address still has to be
196 * mapped by the controller. That means, that the initial mapping has
197 * to be (at least) twice as large as the maximum expected size.
198 */
199 maxsize = (1 + (~orx | 0x7fff))/* / 2*/;
200
Heiko Schocherb11f53f2011-03-15 16:52:29 +0100201 out_be32(&memctl->memc_or1, orx);
Heiko Schocherac9db062008-01-11 01:12:08 +0100202
203 /*
204 * Quote from 8260 UM (10.4.2 SDRAM Power-On Initialization, 10-35):
205 *
206 * "At system reset, initialization software must set up the
207 * programmable parameters in the memory controller banks registers
208 * (ORx, BRx, P/LSDMR). After all memory parameters are configured,
209 * system software should execute the following initialization sequence
210 * for each SDRAM device.
211 *
212 * 1. Issue a PRECHARGE-ALL-BANKS command
213 * 2. Issue eight CBR REFRESH commands
214 * 3. Issue a MODE-SET command to initialize the mode register
215 *
216 * The initial commands are executed by setting P/LSDMR[OP] and
217 * accessing the SDRAM with a single-byte transaction."
218 *
219 * The appropriate BRx/ORx registers have already been set when we
Holger Brunck2220e6c2011-04-08 02:47:25 +0000220 * get here. The SDRAM can be accessed at the address
221 * CONFIG_SYS_SDRAM_BASE.
Heiko Schocherac9db062008-01-11 01:12:08 +0100222 */
223
Heiko Schocherb11f53f2011-03-15 16:52:29 +0100224 out_be32(&memctl->memc_psdmr, sdmr | PSDMR_OP_PREA);
225 out_8(base, c);
Heiko Schocherac9db062008-01-11 01:12:08 +0100226
Heiko Schocherb11f53f2011-03-15 16:52:29 +0100227 out_be32(&memctl->memc_psdmr, sdmr | PSDMR_OP_CBRR);
Heiko Schocherac9db062008-01-11 01:12:08 +0100228 for (i = 0; i < 8; i++)
Heiko Schocherb11f53f2011-03-15 16:52:29 +0100229 out_8(base, c);
Heiko Schocherac9db062008-01-11 01:12:08 +0100230
Heiko Schocherb11f53f2011-03-15 16:52:29 +0100231 out_be32(&memctl->memc_psdmr, sdmr | PSDMR_OP_MRW);
232 /* setting MR on address lines */
233 out_8((uchar *)(base + CONFIG_SYS_MRS_OFFS), c);
Heiko Schocherac9db062008-01-11 01:12:08 +0100234
Heiko Schocherb11f53f2011-03-15 16:52:29 +0100235 out_be32(&memctl->memc_psdmr, sdmr | PSDMR_OP_NORM | PSDMR_RFEN);
236 out_8(base, c);
Heiko Schocherac9db062008-01-11 01:12:08 +0100237
Heiko Schocherb11f53f2011-03-15 16:52:29 +0100238 size = get_ram_size((long *)base, maxsize);
239 out_be32(&memctl->memc_or1, orx | ~(size - 1));
Heiko Schocherac9db062008-01-11 01:12:08 +0100240
Holger Brunck2220e6c2011-04-08 02:47:25 +0000241 return size;
Heiko Schocherac9db062008-01-11 01:12:08 +0100242}
243
Gerlando Falauto3a532342012-07-27 05:16:38 +0000244#ifdef CONFIG_SYS_SDRAM_LIST
245
246/*
247 * If CONFIG_SYS_SDRAM_LIST is defined, we cycle through all SDRAM
248 * configurations therein (should be from high to lower) to find the
249 * one actually matching the current configuration.
250 * CONFIG_SYS_PSDMR and CONFIG_SYS_OR1 will contain the base values which are
251 * common among all possible configurations; values in CONFIG_SYS_SDRAM_LIST
252 * (defined as the initialization value for the array of struct sdram_conf_s)
253 * will then be ORed with such base values.
254 */
255
256struct sdram_conf_s {
257 ulong size;
258 int or1;
259 int psdmr;
260};
261
262static struct sdram_conf_s sdram_conf[] = CONFIG_SYS_SDRAM_LIST;
263
264static long probe_sdram(memctl8260_t *memctl)
265{
266 int n = 0;
267 long psize = 0;
268
269 for (n = 0; n < ARRAY_SIZE(sdram_conf); psize = 0, n++) {
270 psize = try_init(memctl,
271 CONFIG_SYS_PSDMR | sdram_conf[n].psdmr,
272 CONFIG_SYS_OR1 | sdram_conf[n].or1,
273 (uchar *) CONFIG_SYS_SDRAM_BASE);
274 debug("Probing %ld bytes returned %ld\n",
275 sdram_conf[n].size, psize);
276 if (psize == sdram_conf[n].size)
277 break;
278 }
279 return psize;
280}
281
282#else /* CONFIG_SYS_SDRAM_LIST */
283
284static long probe_sdram(memctl8260_t *memctl)
285{
286 return try_init(memctl, CONFIG_SYS_PSDMR, CONFIG_SYS_OR1,
287 (uchar *) CONFIG_SYS_SDRAM_BASE);
288}
289#endif /* CONFIG_SYS_SDRAM_LIST */
290
291
Heiko Schocherb11f53f2011-03-15 16:52:29 +0100292phys_size_t initdram(int board_type)
Heiko Schocherac9db062008-01-11 01:12:08 +0100293{
Heiko Schocherb11f53f2011-03-15 16:52:29 +0100294 immap_t *immap = (immap_t *) CONFIG_SYS_IMMR;
295 memctl8260_t *memctl = &immap->im_memctl;
Heiko Schocherac9db062008-01-11 01:12:08 +0100296
297 long psize;
298
Heiko Schocherb11f53f2011-03-15 16:52:29 +0100299 out_8(&memctl->memc_psrt, CONFIG_SYS_PSRT);
300 out_be16(&memctl->memc_mptpr, CONFIG_SYS_MPTPR);
Heiko Schocherac9db062008-01-11 01:12:08 +0100301
Heiko Schocherac9db062008-01-11 01:12:08 +0100302 /* 60x SDRAM setup:
303 */
Gerlando Falauto3a532342012-07-27 05:16:38 +0000304 psize = probe_sdram(memctl);
Heiko Schocherac9db062008-01-11 01:12:08 +0100305
Heiko Schocherb11f53f2011-03-15 16:52:29 +0100306 icache_enable();
Heiko Schocherac9db062008-01-11 01:12:08 +0100307
Holger Brunck2220e6c2011-04-08 02:47:25 +0000308 return psize;
Heiko Schocherac9db062008-01-11 01:12:08 +0100309}
310
311int checkboard(void)
312{
Heiko Schocheraf895e42011-02-22 08:58:19 +0100313#if defined(CONFIG_MGCOGE)
Heiko Schocherb11f53f2011-03-15 16:52:29 +0100314 puts("Board: Keymile mgcoge");
Heiko Schocheraf895e42011-02-22 08:58:19 +0100315#else
Holger Brunck489337f2011-05-02 22:56:55 +0000316 puts("Board: Keymile mgcoge3ne");
Heiko Schocheraf895e42011-02-22 08:58:19 +0100317#endif
Heiko Schocherb11f53f2011-03-15 16:52:29 +0100318 if (ethernet_present())
319 puts(" with PIGGY.");
320 puts("\n");
Heiko Schocherac9db062008-01-11 01:12:08 +0100321 return 0;
322}
323
Andreas Huber91a3c142011-01-25 11:26:15 +0100324int last_stage_init(void)
325{
Huber, Andreasf30c62b2011-05-02 22:56:54 +0000326 struct bfticu_iomap *base =
327 (struct bfticu_iomap *)CONFIG_SYS_FPGA_BASE;
Andreas Huber91a3c142011-01-25 11:26:15 +0100328 u8 dip_switch;
Huber, Andreasf30c62b2011-05-02 22:56:54 +0000329
330 dip_switch = in_8(&base->mswitch);
331 dip_switch &= BFTICU_DIPSWITCH_MASK;
Bagavathiannan Palanisamycd7255f2015-11-17 10:53:34 +0100332 /* dip switch 'full reset' or 'db erase' or 'Local mgmt IP' or any */
333 if (dip_switch != 0) {
Andreas Huber91a3c142011-01-25 11:26:15 +0100334 /* start bootloader */
335 puts("DIP: Enabled\n");
336 setenv("actual_bank", "0");
337 }
Heiko Schocherf1fef1d2010-04-26 13:07:28 +0200338 set_km_env();
Andreas Huber91a3c142011-01-25 11:26:15 +0100339 return 0;
340}
341
Holger Brunck489337f2011-05-02 22:56:55 +0000342#ifdef CONFIG_MGCOGE3NE
Holger Brunck74edc602015-11-17 10:53:25 +0100343static void set_pin(int state, unsigned long mask, int port);
Holger Brunck1adfd9d2011-06-05 22:22:20 +0000344
Holger Brunck489337f2011-05-02 22:56:55 +0000345/*
346 * For mgcoge3ne boards, the mgcoge3un control is controlled from
347 * a GPIO line on the PPC CPU. If bobcatreset is set the line
348 * will toggle once what forces the mgocge3un part to restart
349 * immediately.
350 */
Holger Brunck47ce50e2013-01-18 00:28:16 +0000351static void handle_mgcoge3un_reset(void)
Holger Brunck489337f2011-05-02 22:56:55 +0000352{
353 char *bobcatreset = getenv("bobcatreset");
354 if (bobcatreset) {
355 if (strcmp(bobcatreset, "true") == 0) {
356 puts("Forcing bobcat reset\n");
Holger Brunck74edc602015-11-17 10:53:25 +0100357 set_pin(0, 0x00000004, 3); /* clear PD29 (reset arm) */
Holger Brunck489337f2011-05-02 22:56:55 +0000358 udelay(1000);
Holger Brunck74edc602015-11-17 10:53:25 +0100359 set_pin(1, 0x00000004, 3);
Holger Brunck489337f2011-05-02 22:56:55 +0000360 } else
Holger Brunck74edc602015-11-17 10:53:25 +0100361 set_pin(1, 0x00000004, 3); /* don't reset arm */
Holger Brunck489337f2011-05-02 22:56:55 +0000362 }
363}
364#endif
365
Karlheinz Jerg1eb95eb2013-01-21 03:55:16 +0000366int ethernet_present(void)
367{
368 struct km_bec_fpga *base =
369 (struct km_bec_fpga *)CONFIG_SYS_KMBEC_FPGA_BASE;
370
371 return in_8(&base->bprth) & PIGGY_PRESENT;
372}
373
Heiko Schochere492c902008-03-07 08:13:41 +0100374/*
375 * Early board initalization.
376 */
Heiko Schocherb11f53f2011-03-15 16:52:29 +0100377int board_early_init_r(void)
Heiko Schochere492c902008-03-07 08:13:41 +0100378{
Heiko Schocher8ed74342011-03-08 10:47:39 +0100379 struct km_bec_fpga *base =
380 (struct km_bec_fpga *)CONFIG_SYS_KMBEC_FPGA_BASE;
Heiko Schocherb11f53f2011-03-15 16:52:29 +0100381
Heiko Schochere492c902008-03-07 08:13:41 +0100382 /* setup the UPIOx */
Heiko Schocher4897ee32010-01-07 08:55:50 +0100383 /* General Unit Reset disabled, Flash Bank enabled, UnitLed on */
Heiko Schocherb11f53f2011-03-15 16:52:29 +0100384 out_8(&base->oprth, (WRG_RESET | H_OPORTS_14 | WRG_LED));
Heiko Schocher4897ee32010-01-07 08:55:50 +0100385 /* SCC4 enable, halfduplex, FCC1 powerdown */
Heiko Schocherb11f53f2011-03-15 16:52:29 +0100386 out_8(&base->oprtl, (H_OPORTS_SCC4_ENA | H_OPORTS_SCC4_FD_ENA |
387 H_OPORTS_FCC1_PW_DWN));
388
Holger Brunck489337f2011-05-02 22:56:55 +0000389#ifdef CONFIG_MGCOGE3NE
390 handle_mgcoge3un_reset();
391#endif
Heiko Schochere492c902008-03-07 08:13:41 +0100392 return 0;
393}
394
Valentin Longchamp2973b092015-02-10 17:10:17 +0100395int misc_init_r(void)
396{
Valentin Longchamp60c4ae02015-02-10 17:10:18 +0100397 ivm_read_eeprom(ivm_content, CONFIG_SYS_IVM_EEPROM_MAX_LEN);
Valentin Longchamp2973b092015-02-10 17:10:17 +0100398 return 0;
399}
400
Heiko Schocherb11f53f2011-03-15 16:52:29 +0100401int hush_init_var(void)
Heiko Schocher8f64da72008-10-15 09:41:00 +0200402{
Valentin Longchamp2973b092015-02-10 17:10:17 +0100403 ivm_analyze_eeprom(ivm_content, CONFIG_SYS_IVM_EEPROM_MAX_LEN);
Heiko Schocher8f64da72008-10-15 09:41:00 +0200404 return 0;
405}
406
Holger Brunck1adfd9d2011-06-05 22:22:20 +0000407#define SDA_MASK 0x00010000
408#define SCL_MASK 0x00020000
409
Holger Brunck74edc602015-11-17 10:53:25 +0100410static void set_pin(int state, unsigned long mask, int port)
Holger Brunck1adfd9d2011-06-05 22:22:20 +0000411{
Holger Brunck74edc602015-11-17 10:53:25 +0100412 ioport_t *iop = ioport_addr((immap_t *)CONFIG_SYS_IMMR, port);
Holger Brunck1adfd9d2011-06-05 22:22:20 +0000413
414 if (state)
415 setbits_be32(&iop->pdat, mask);
416 else
417 clrbits_be32(&iop->pdat, mask);
418
419 setbits_be32(&iop->pdir, mask);
420}
421
Holger Brunck74edc602015-11-17 10:53:25 +0100422static int get_pin(unsigned long mask, int port)
Holger Brunck1adfd9d2011-06-05 22:22:20 +0000423{
Holger Brunck74edc602015-11-17 10:53:25 +0100424 ioport_t *iop = ioport_addr((immap_t *)CONFIG_SYS_IMMR, port);
Holger Brunck1adfd9d2011-06-05 22:22:20 +0000425
426 clrbits_be32(&iop->pdir, mask);
427 return 0 != (in_be32(&iop->pdat) & mask);
428}
429
430void set_sda(int state)
431{
Holger Brunck74edc602015-11-17 10:53:25 +0100432 set_pin(state, SDA_MASK, 3);
Holger Brunck1adfd9d2011-06-05 22:22:20 +0000433}
434
435void set_scl(int state)
436{
Holger Brunck74edc602015-11-17 10:53:25 +0100437 set_pin(state, SCL_MASK, 3);
Holger Brunck1adfd9d2011-06-05 22:22:20 +0000438}
439
440int get_sda(void)
441{
Holger Brunck74edc602015-11-17 10:53:25 +0100442 return get_pin(SDA_MASK, 3);
Holger Brunck1adfd9d2011-06-05 22:22:20 +0000443}
444
445int get_scl(void)
446{
Holger Brunck74edc602015-11-17 10:53:25 +0100447 return get_pin(SCL_MASK, 3);
Holger Brunck1adfd9d2011-06-05 22:22:20 +0000448}
449
Valentin Longchamp89127c52015-11-17 10:53:38 +0100450int ft_board_setup(void *blob, bd_t *bd)
Heiko Schocherac9db062008-01-11 01:12:08 +0100451{
Heiko Schocherb11f53f2011-03-15 16:52:29 +0100452 ft_cpu_setup(blob, bd);
Simon Glasse895a4b2014-10-23 18:58:47 -0600453
454 return 0;
Heiko Schocherac9db062008-01-11 01:12:08 +0100455}
Holger Brunckd3f1d6f2015-11-17 10:53:26 +0100456
457#if defined(CONFIG_MGCOGE3NE)
458int get_testpin(void)
459{
460 /* Testpin is Port C pin 29 - enable = low */
461 int testpin = !get_pin(0x00000004, 2);
462 return testpin;
463}
464#endif