blob: f98844d317db7ce34b603f2a05923f26c21c65ed [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 *
5 * See file CREDITS for list of people who contributed to this
6 * project.
7 *
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.
12 *
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.
17 *
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,
21 * MA 02111-1307 USA
22 */
23
24#include <common.h>
25#include <mpc8260.h>
26#include <ioports.h>
Heiko Schocher9661bf92008-10-15 09:36:03 +020027#include <malloc.h>
Heiko Schocher9e299192008-10-17 12:15:55 +020028#include <asm/io.h>
Heiko Schocherac9db062008-01-11 01:12:08 +010029
30#if defined(CONFIG_OF_BOARD_SETUP) && defined(CONFIG_OF_LIBFDT)
31#include <libfdt.h>
32#endif
33
Heiko Schocher9661bf92008-10-15 09:36:03 +020034#include <i2c.h>
Heiko Schocher210c8c02008-11-21 08:29:40 +010035#include "../common/common.h"
36
Heiko Schocherac9db062008-01-11 01:12:08 +010037/*
38 * I/O Port configuration table
39 *
40 * if conf is 1, then that port pin will be configured at boot time
41 * according to the five values podr/pdir/ppar/psor/pdat for that entry
42 */
43const iop_conf_t iop_conf_tab[4][32] = {
44
Holger Brunck2220e6c2011-04-08 02:47:25 +000045 /* Port A */
46 { /* conf ppar psor pdir podr pdat */
47 { 0, 0, 0, 0, 0, 0 }, /* PA31 */
48 { 0, 0, 0, 0, 0, 0 }, /* PA30 */
49 { 0, 0, 0, 0, 0, 0 }, /* PA29 */
50 { 0, 0, 0, 0, 0, 0 }, /* PA28 */
51 { 0, 0, 0, 0, 0, 0 }, /* PA27 */
52 { 0, 0, 0, 0, 0, 0 }, /* PA26 */
53 { 0, 0, 0, 0, 0, 0 }, /* PA25 */
54 { 0, 0, 0, 0, 0, 0 }, /* PA24 */
55 { 0, 0, 0, 0, 0, 0 }, /* PA23 */
56 { 0, 0, 0, 0, 0, 0 }, /* PA22 */
57 { 0, 0, 0, 0, 0, 0 }, /* PA21 */
58 { 0, 0, 0, 0, 0, 0 }, /* PA20 */
59 { 0, 0, 0, 0, 0, 0 }, /* PA19 */
60 { 0, 0, 0, 0, 0, 0 }, /* PA18 */
61 { 0, 0, 0, 0, 0, 0 }, /* PA17 */
62 { 0, 0, 0, 0, 0, 0 }, /* PA16 */
63 { 0, 0, 0, 0, 0, 0 }, /* PA15 */
64 { 0, 0, 0, 0, 0, 0 }, /* PA14 */
65 { 0, 0, 0, 0, 0, 0 }, /* PA13 */
66 { 0, 0, 0, 0, 0, 0 }, /* PA12 */
67 { 0, 0, 0, 0, 0, 0 }, /* PA11 */
68 { 0, 0, 0, 0, 0, 0 }, /* PA10 */
69 { 1, 1, 0, 1, 0, 0 }, /* PA9 SMC2 TxD */
70 { 1, 1, 0, 0, 0, 0 }, /* PA8 SMC2 RxD */
71 { 0, 0, 0, 0, 0, 0 }, /* PA7 */
72 { 0, 0, 0, 0, 0, 0 }, /* PA6 */
73 { 0, 0, 0, 0, 0, 0 }, /* PA5 */
74 { 0, 0, 0, 0, 0, 0 }, /* PA4 */
75 { 0, 0, 0, 0, 0, 0 }, /* PA3 */
76 { 0, 0, 0, 0, 0, 0 }, /* PA2 */
77 { 0, 0, 0, 0, 0, 0 }, /* PA1 */
78 { 0, 0, 0, 0, 0, 0 } /* PA0 */
79 },
Heiko Schocherac9db062008-01-11 01:12:08 +010080
Holger Brunck2220e6c2011-04-08 02:47:25 +000081 /* Port B */
82 { /* conf ppar psor pdir podr pdat */
83 { 0, 0, 0, 0, 0, 0 }, /* PB31 */
84 { 0, 0, 0, 0, 0, 0 }, /* PB30 */
85 { 0, 0, 0, 0, 0, 0 }, /* PB29 */
86 { 0, 0, 0, 0, 0, 0 }, /* PB28 */
87 { 0, 0, 0, 0, 0, 0 }, /* PB27 */
88 { 0, 0, 0, 0, 0, 0 }, /* PB26 */
89 { 0, 0, 0, 0, 0, 0 }, /* PB25 */
90 { 0, 0, 0, 0, 0, 0 }, /* PB24 */
91 { 0, 0, 0, 0, 0, 0 }, /* PB23 */
92 { 0, 0, 0, 0, 0, 0 }, /* PB22 */
93 { 0, 0, 0, 0, 0, 0 }, /* PB21 */
94 { 0, 0, 0, 0, 0, 0 }, /* PB20 */
95 { 0, 0, 0, 0, 0, 0 }, /* PB19 */
96 { 0, 0, 0, 0, 0, 0 }, /* PB18 */
97 { 0, 0, 0, 0, 0, 0 }, /* non-existent */
98 { 0, 0, 0, 0, 0, 0 }, /* non-existent */
99 { 0, 0, 0, 0, 0, 0 }, /* non-existent */
100 { 0, 0, 0, 0, 0, 0 }, /* non-existent */
101 { 0, 0, 0, 0, 0, 0 }, /* non-existent */
102 { 0, 0, 0, 0, 0, 0 }, /* non-existent */
103 { 0, 0, 0, 0, 0, 0 }, /* non-existent */
104 { 0, 0, 0, 0, 0, 0 }, /* non-existent */
105 { 0, 0, 0, 0, 0, 0 }, /* non-existent */
106 { 0, 0, 0, 0, 0, 0 }, /* non-existent */
107 { 0, 0, 0, 0, 0, 0 }, /* non-existent */
108 { 0, 0, 0, 0, 0, 0 }, /* non-existent */
109 { 0, 0, 0, 0, 0, 0 }, /* non-existent */
110 { 0, 0, 0, 0, 0, 0 }, /* non-existent */
111 { 0, 0, 0, 0, 0, 0 }, /* non-existent */
112 { 0, 0, 0, 0, 0, 0 }, /* non-existent */
113 { 0, 0, 0, 0, 0, 0 }, /* non-existent */
114 { 0, 0, 0, 0, 0, 0 } /* non-existent */
115 },
Heiko Schocherac9db062008-01-11 01:12:08 +0100116
Holger Brunck2220e6c2011-04-08 02:47:25 +0000117 /* Port C */
118 { /* conf ppar psor pdir podr pdat */
119 { 0, 0, 0, 0, 0, 0 }, /* PC31 */
120 { 0, 0, 0, 0, 0, 0 }, /* PC30 */
121 { 0, 0, 0, 0, 0, 0 }, /* PC29 */
122 { 0, 0, 0, 0, 0, 0 }, /* PC28 */
123 { 0, 0, 0, 0, 0, 0 }, /* PC27 */
124 { 0, 0, 0, 0, 0, 0 }, /* PC26 */
125 { 1, 1, 0, 0, 0, 0 }, /* PC25 RxClk */
126 { 1, 1, 0, 0, 0, 0 }, /* PC24 TxClk */
127 { 0, 0, 0, 0, 0, 0 }, /* PC23 */
128 { 0, 0, 0, 0, 0, 0 }, /* PC22 */
129 { 0, 0, 0, 0, 0, 0 }, /* PC21 */
130 { 0, 0, 0, 0, 0, 0 }, /* PC20 */
131 { 0, 0, 0, 0, 0, 0 }, /* PC19 */
132 { 0, 0, 0, 0, 0, 0 }, /* PC18 */
133 { 0, 0, 0, 0, 0, 0 }, /* PC17 */
134 { 0, 0, 0, 0, 0, 0 }, /* PC16 */
135 { 0, 0, 0, 0, 0, 0 }, /* PC15 */
136 { 0, 0, 0, 0, 0, 0 }, /* PC14 */
137 { 0, 0, 0, 0, 0, 0 }, /* PC13 */
138 { 0, 0, 0, 0, 0, 0 }, /* PC12 */
139 { 0, 0, 0, 0, 0, 0 }, /* PC11 */
140 { 0, 0, 0, 0, 0, 0 }, /* PC10 */
141 { 1, 1, 0, 0, 0, 0 }, /* PC9 SCC4: CTS */
142 { 1, 1, 0, 0, 0, 0 }, /* PC8 SCC4: CD */
143 { 0, 0, 0, 0, 0, 0 }, /* PC7 */
144 { 0, 0, 0, 0, 0, 0 }, /* PC6 */
145 { 0, 0, 0, 0, 0, 0 }, /* PC5 */
146 { 0, 0, 0, 0, 0, 0 }, /* PC4 */
147 { 0, 0, 0, 0, 0, 0 }, /* PC3 */
148 { 0, 0, 0, 0, 0, 0 }, /* PC2 */
149 { 0, 0, 0, 0, 0, 0 }, /* PC1 */
150 { 0, 0, 0, 0, 0, 0 }, /* PC0 */
151 },
Heiko Schocherac9db062008-01-11 01:12:08 +0100152
Holger Brunck2220e6c2011-04-08 02:47:25 +0000153 /* Port D */
154 { /* conf ppar psor pdir podr pdat */
155 { 0, 0, 0, 0, 0, 0 }, /* PD31 */
156 { 0, 0, 0, 0, 0, 0 }, /* PD30 */
157 { 0, 0, 0, 0, 0, 0 }, /* PD29 */
158 { 0, 0, 0, 0, 0, 0 }, /* PD28 */
159 { 0, 0, 0, 0, 0, 0 }, /* PD27 */
160 { 0, 0, 0, 0, 0, 0 }, /* PD26 */
161 { 0, 0, 0, 0, 0, 0 }, /* PD25 */
162 { 0, 0, 0, 0, 0, 0 }, /* PD24 */
163 { 0, 0, 0, 0, 0, 0 }, /* PD23 */
164 { 1, 1, 0, 0, 0, 0 }, /* PD22 SCC4: RXD */
165 { 1, 1, 0, 1, 0, 0 }, /* PD21 SCC4: TXD */
166 { 1, 1, 0, 1, 0, 0 }, /* PD20 SCC4: RTS */
167 { 0, 0, 0, 0, 0, 0 }, /* PD19 */
168 { 0, 0, 0, 0, 0, 0 }, /* PD18 */
169 { 0, 0, 0, 0, 0, 0 }, /* PD17 */
170 { 0, 0, 0, 0, 0, 0 }, /* PD16 */
Heiko Schocher9661bf92008-10-15 09:36:03 +0200171#if defined(CONFIG_HARD_I2C)
Holger Brunck2220e6c2011-04-08 02:47:25 +0000172 { 1, 1, 1, 0, 1, 0 }, /* PD15 I2C SDA */
173 { 1, 1, 1, 0, 1, 0 }, /* PD14 I2C SCL */
Heiko Schocher9661bf92008-10-15 09:36:03 +0200174#else
Holger Brunck2220e6c2011-04-08 02:47:25 +0000175 { 1, 0, 0, 0, 1, 1 }, /* PD15 */
176 { 1, 0, 0, 1, 1, 1 }, /* PD14 */
Heiko Schocher9661bf92008-10-15 09:36:03 +0200177#endif
Holger Brunck2220e6c2011-04-08 02:47:25 +0000178 { 0, 0, 0, 0, 0, 0 }, /* PD13 */
179 { 0, 0, 0, 0, 0, 0 }, /* PD12 */
180 { 0, 0, 0, 0, 0, 0 }, /* PD11 */
181 { 0, 0, 0, 0, 0, 0 }, /* PD10 */
182 { 0, 0, 0, 0, 0, 0 }, /* PD9 */
183 { 0, 0, 0, 0, 0, 0 }, /* PD8 */
184 { 0, 0, 0, 0, 0, 0 }, /* PD7 */
185 { 0, 0, 0, 0, 0, 0 }, /* PD6 */
186 { 0, 0, 0, 0, 0, 0 }, /* PD5 */
187 { 0, 0, 0, 0, 0, 0 }, /* PD4 */
188 { 0, 0, 0, 0, 0, 0 }, /* non-existent */
189 { 0, 0, 0, 0, 0, 0 }, /* non-existent */
190 { 0, 0, 0, 0, 0, 0 }, /* non-existent */
191 { 0, 0, 0, 0, 0, 0 } /* non-existent */
192 }
Heiko Schocherac9db062008-01-11 01:12:08 +0100193};
194
Heiko Schocherb11f53f2011-03-15 16:52:29 +0100195/*
196 * Try SDRAM initialization with P/LSDMR=sdmr and ORx=orx
Heiko Schocherac9db062008-01-11 01:12:08 +0100197 *
198 * This routine performs standard 8260 initialization sequence
199 * and calculates the available memory size. It may be called
200 * several times to try different SDRAM configurations on both
201 * 60x and local buses.
202 */
Heiko Schocherb11f53f2011-03-15 16:52:29 +0100203static long int try_init(memctl8260_t *memctl, ulong sdmr,
204 ulong orx, uchar *base)
Heiko Schocherac9db062008-01-11 01:12:08 +0100205{
Heiko Schocherb11f53f2011-03-15 16:52:29 +0100206 uchar c = 0xff;
Heiko Schocherac9db062008-01-11 01:12:08 +0100207 ulong maxsize, size;
208 int i;
209
Heiko Schocherb11f53f2011-03-15 16:52:29 +0100210 /*
211 * We must be able to test a location outsize the maximum legal size
Heiko Schocherac9db062008-01-11 01:12:08 +0100212 * to find out THAT we are outside; but this address still has to be
213 * mapped by the controller. That means, that the initial mapping has
214 * to be (at least) twice as large as the maximum expected size.
215 */
216 maxsize = (1 + (~orx | 0x7fff))/* / 2*/;
217
Heiko Schocherb11f53f2011-03-15 16:52:29 +0100218 out_be32(&memctl->memc_or1, orx);
Heiko Schocherac9db062008-01-11 01:12:08 +0100219
220 /*
221 * Quote from 8260 UM (10.4.2 SDRAM Power-On Initialization, 10-35):
222 *
223 * "At system reset, initialization software must set up the
224 * programmable parameters in the memory controller banks registers
225 * (ORx, BRx, P/LSDMR). After all memory parameters are configured,
226 * system software should execute the following initialization sequence
227 * for each SDRAM device.
228 *
229 * 1. Issue a PRECHARGE-ALL-BANKS command
230 * 2. Issue eight CBR REFRESH commands
231 * 3. Issue a MODE-SET command to initialize the mode register
232 *
233 * The initial commands are executed by setting P/LSDMR[OP] and
234 * accessing the SDRAM with a single-byte transaction."
235 *
236 * The appropriate BRx/ORx registers have already been set when we
Holger Brunck2220e6c2011-04-08 02:47:25 +0000237 * get here. The SDRAM can be accessed at the address
238 * CONFIG_SYS_SDRAM_BASE.
Heiko Schocherac9db062008-01-11 01:12:08 +0100239 */
240
Heiko Schocherb11f53f2011-03-15 16:52:29 +0100241 out_be32(&memctl->memc_psdmr, sdmr | PSDMR_OP_PREA);
242 out_8(base, c);
Heiko Schocherac9db062008-01-11 01:12:08 +0100243
Heiko Schocherb11f53f2011-03-15 16:52:29 +0100244 out_be32(&memctl->memc_psdmr, sdmr | PSDMR_OP_CBRR);
Heiko Schocherac9db062008-01-11 01:12:08 +0100245 for (i = 0; i < 8; i++)
Heiko Schocherb11f53f2011-03-15 16:52:29 +0100246 out_8(base, c);
Heiko Schocherac9db062008-01-11 01:12:08 +0100247
Heiko Schocherb11f53f2011-03-15 16:52:29 +0100248 out_be32(&memctl->memc_psdmr, sdmr | PSDMR_OP_MRW);
249 /* setting MR on address lines */
250 out_8((uchar *)(base + CONFIG_SYS_MRS_OFFS), c);
Heiko Schocherac9db062008-01-11 01:12:08 +0100251
Heiko Schocherb11f53f2011-03-15 16:52:29 +0100252 out_be32(&memctl->memc_psdmr, sdmr | PSDMR_OP_NORM | PSDMR_RFEN);
253 out_8(base, c);
Heiko Schocherac9db062008-01-11 01:12:08 +0100254
Heiko Schocherb11f53f2011-03-15 16:52:29 +0100255 size = get_ram_size((long *)base, maxsize);
256 out_be32(&memctl->memc_or1, orx | ~(size - 1));
Heiko Schocherac9db062008-01-11 01:12:08 +0100257
Holger Brunck2220e6c2011-04-08 02:47:25 +0000258 return size;
Heiko Schocherac9db062008-01-11 01:12:08 +0100259}
260
Gerlando Falauto3a532342012-07-27 05:16:38 +0000261#ifdef CONFIG_SYS_SDRAM_LIST
262
263/*
264 * If CONFIG_SYS_SDRAM_LIST is defined, we cycle through all SDRAM
265 * configurations therein (should be from high to lower) to find the
266 * one actually matching the current configuration.
267 * CONFIG_SYS_PSDMR and CONFIG_SYS_OR1 will contain the base values which are
268 * common among all possible configurations; values in CONFIG_SYS_SDRAM_LIST
269 * (defined as the initialization value for the array of struct sdram_conf_s)
270 * will then be ORed with such base values.
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 /* CONFIG_SYS_SDRAM_LIST */
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 /* CONFIG_SYS_SDRAM_LIST */
307
308
Heiko Schocherb11f53f2011-03-15 16:52:29 +0100309phys_size_t initdram(int board_type)
Heiko Schocherac9db062008-01-11 01:12:08 +0100310{
Heiko Schocherb11f53f2011-03-15 16:52:29 +0100311 immap_t *immap = (immap_t *) CONFIG_SYS_IMMR;
312 memctl8260_t *memctl = &immap->im_memctl;
Heiko Schocherac9db062008-01-11 01:12:08 +0100313
314 long psize;
315
Heiko Schocherb11f53f2011-03-15 16:52:29 +0100316 out_8(&memctl->memc_psrt, CONFIG_SYS_PSRT);
317 out_be16(&memctl->memc_mptpr, CONFIG_SYS_MPTPR);
Heiko Schocherac9db062008-01-11 01:12:08 +0100318
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200319#ifndef CONFIG_SYS_RAMBOOT
Heiko Schocherac9db062008-01-11 01:12:08 +0100320 /* 60x SDRAM setup:
321 */
Gerlando Falauto3a532342012-07-27 05:16:38 +0000322 psize = probe_sdram(memctl);
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200323#endif /* CONFIG_SYS_RAMBOOT */
Heiko Schocherac9db062008-01-11 01:12:08 +0100324
Heiko Schocherb11f53f2011-03-15 16:52:29 +0100325 icache_enable();
Heiko Schocherac9db062008-01-11 01:12:08 +0100326
Holger Brunck2220e6c2011-04-08 02:47:25 +0000327 return psize;
Heiko Schocherac9db062008-01-11 01:12:08 +0100328}
329
330int checkboard(void)
331{
Heiko Schocheraf895e42011-02-22 08:58:19 +0100332#if defined(CONFIG_MGCOGE)
Heiko Schocherb11f53f2011-03-15 16:52:29 +0100333 puts("Board: Keymile mgcoge");
Heiko Schocheraf895e42011-02-22 08:58:19 +0100334#else
Holger Brunck489337f2011-05-02 22:56:55 +0000335 puts("Board: Keymile mgcoge3ne");
Heiko Schocheraf895e42011-02-22 08:58:19 +0100336#endif
Heiko Schocherb11f53f2011-03-15 16:52:29 +0100337 if (ethernet_present())
338 puts(" with PIGGY.");
339 puts("\n");
Heiko Schocherac9db062008-01-11 01:12:08 +0100340 return 0;
341}
342
Andreas Huber91a3c142011-01-25 11:26:15 +0100343int last_stage_init(void)
344{
Huber, Andreasf30c62b2011-05-02 22:56:54 +0000345 struct bfticu_iomap *base =
346 (struct bfticu_iomap *)CONFIG_SYS_FPGA_BASE;
Andreas Huber91a3c142011-01-25 11:26:15 +0100347 u8 dip_switch;
Huber, Andreasf30c62b2011-05-02 22:56:54 +0000348
349 dip_switch = in_8(&base->mswitch);
350 dip_switch &= BFTICU_DIPSWITCH_MASK;
Andreas Huber91a3c142011-01-25 11:26:15 +0100351 /* dip switch 'full reset' or 'db erase' */
352 if (dip_switch & 0x1 || dip_switch & 0x2) {
353 /* start bootloader */
354 puts("DIP: Enabled\n");
355 setenv("actual_bank", "0");
356 }
Heiko Schocherf1fef1d2010-04-26 13:07:28 +0200357 set_km_env();
Andreas Huber91a3c142011-01-25 11:26:15 +0100358 return 0;
359}
360
Holger Brunck489337f2011-05-02 22:56:55 +0000361#ifdef CONFIG_MGCOGE3NE
Holger Brunck1adfd9d2011-06-05 22:22:20 +0000362static void set_pin(int state, unsigned long mask);
363
Holger Brunck489337f2011-05-02 22:56:55 +0000364/*
365 * For mgcoge3ne boards, the mgcoge3un control is controlled from
366 * a GPIO line on the PPC CPU. If bobcatreset is set the line
367 * will toggle once what forces the mgocge3un part to restart
368 * immediately.
369 */
Holger Brunck47ce50e2013-01-18 00:28:16 +0000370static void handle_mgcoge3un_reset(void)
Holger Brunck489337f2011-05-02 22:56:55 +0000371{
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); /* clear PD29 to reset arm */
377 udelay(1000);
378 set_pin(1, 0x00000004);
379 } else
380 set_pin(1, 0x00000004); /* set PD29 to not reset arm */
381 }
382}
383#endif
384
Karlheinz Jerg1eb95eb2013-01-21 03:55:16 +0000385int 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
Heiko Schochere492c902008-03-07 08:13:41 +0100393/*
394 * Early board initalization.
395 */
Heiko Schocherb11f53f2011-03-15 16:52:29 +0100396int board_early_init_r(void)
Heiko Schochere492c902008-03-07 08:13:41 +0100397{
Heiko Schocher8ed74342011-03-08 10:47:39 +0100398 struct km_bec_fpga *base =
399 (struct km_bec_fpga *)CONFIG_SYS_KMBEC_FPGA_BASE;
Heiko Schocherb11f53f2011-03-15 16:52:29 +0100400
Heiko Schochere492c902008-03-07 08:13:41 +0100401 /* setup the UPIOx */
Heiko Schocher4897ee32010-01-07 08:55:50 +0100402 /* General Unit Reset disabled, Flash Bank enabled, UnitLed on */
Heiko Schocherb11f53f2011-03-15 16:52:29 +0100403 out_8(&base->oprth, (WRG_RESET | H_OPORTS_14 | WRG_LED));
Heiko Schocher4897ee32010-01-07 08:55:50 +0100404 /* SCC4 enable, halfduplex, FCC1 powerdown */
Heiko Schocherb11f53f2011-03-15 16:52:29 +0100405 out_8(&base->oprtl, (H_OPORTS_SCC4_ENA | H_OPORTS_SCC4_FD_ENA |
406 H_OPORTS_FCC1_PW_DWN));
407
Holger Brunck489337f2011-05-02 22:56:55 +0000408#ifdef CONFIG_MGCOGE3NE
409 handle_mgcoge3un_reset();
410#endif
Heiko Schochere492c902008-03-07 08:13:41 +0100411 return 0;
412}
413
Heiko Schocherb11f53f2011-03-15 16:52:29 +0100414int hush_init_var(void)
Heiko Schocher8f64da72008-10-15 09:41:00 +0200415{
Heiko Schocherb11f53f2011-03-15 16:52:29 +0100416 ivm_read_eeprom();
Heiko Schocher8f64da72008-10-15 09:41:00 +0200417 return 0;
418}
419
Holger Brunck1adfd9d2011-06-05 22:22:20 +0000420#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
Heiko Schocherac9db062008-01-11 01:12:08 +0100478#if defined(CONFIG_OF_BOARD_SETUP) && defined(CONFIG_OF_LIBFDT)
Heiko Schocherb11f53f2011-03-15 16:52:29 +0100479void ft_board_setup(void *blob, bd_t *bd)
Heiko Schocherac9db062008-01-11 01:12:08 +0100480{
Heiko Schocherb11f53f2011-03-15 16:52:29 +0100481 ft_cpu_setup(blob, bd);
Heiko Schocherac9db062008-01-11 01:12:08 +0100482}
483#endif /* defined(CONFIG_OF_BOARD_SETUP) && defined(CONFIG_OF_LIBFDT) */