blob: 49aed037c2f76fa42375db1f3b02ffdcdbfde4c3 [file] [log] [blame]
Heiko Schochera772a162008-08-19 10:08:49 +02001/*
2 * (C) Copyright 2008
3 * 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>
27
28#if defined(CONFIG_OF_BOARD_SETUP) && defined(CONFIG_OF_LIBFDT)
29#include <libfdt.h>
30#endif
31
32/*
33 * I/O Port configuration table
34 *
35 * if conf is 1, then that port pin will be configured at boot time
36 * according to the five values podr/pdir/ppar/psor/pdat for that entry
37 */
38const iop_conf_t iop_conf_tab[4][32] = {
39
40 /* Port A */
41 { /* conf ppar psor pdir podr pdat */
42 /* PA31 */ { 0, 0, 0, 0, 0, 0 }, /* PA31 */
43 /* PA30 */ { 0, 0, 0, 0, 0, 0 }, /* PA30 */
44 /* PA29 */ { 1, 1, 1, 1, 0, 0 }, /* FCC1 TXER */
45 /* PA28 */ { 1, 1, 1, 1, 0, 0 }, /* FCC1 TXEN */
46 /* PA27 */ { 1, 1, 1, 0, 0, 0 }, /* FCC1 RXDV */
47 /* PA26 */ { 1, 1, 1, 0, 0, 0 }, /* FCC1 RXER */
48 /* PA25 */ { 1, 0, 0, 1, 0, 0 }, /* ETH_PWRDWN */
49 /* PA24 */ { 1, 0, 0, 1, 0, 1 }, /* ETH_RESET */
50 /* PA23 */ { 0, 0, 0, 0, 0, 0 }, /* PA23 */
51 /* PA22 */ { 0, 0, 0, 0, 0, 0 }, /* PA22 */
52 /* PA21 */ { 1, 1, 0, 1, 0, 0 }, /* FCC1 TXD3 */
53 /* PA20 */ { 1, 1, 0, 1, 0, 0 }, /* FCC1 TXD2 */
54 /* PA19 */ { 1, 1, 0, 1, 0, 0 }, /* FCC1 TXD1 */
55 /* PA18 */ { 1, 1, 0, 1, 0, 0 }, /* FCC1 TXD0 */
56 /* PA17 */ { 1, 1, 0, 0, 0, 0 }, /* FCC1 RXD0 */
57 /* PA16 */ { 1, 1, 0, 0, 0, 0 }, /* FCC1 RXD1 */
58 /* PA15 */ { 1, 1, 0, 0, 0, 0 }, /* FCC1 RXD2 */
59 /* PA14 */ { 1, 1, 0, 0, 0, 0 }, /* FCC1 RXD3 */
60 /* PA13 */ { 0, 0, 0, 0, 0, 0 }, /* PA13 */
61 /* PA12 */ { 1, 0, 0, 1, 0, 0 }, /* ETH_SLEEP */
62 /* PA11 */ { 0, 0, 0, 0, 0, 0 }, /* PA11 */
63 /* PA10 */ { 1, 0, 0, 1, 0, 0 }, /* MDIO */
64 /* PA9 */ { 1, 0, 0, 1, 0, 0 }, /* MDC */
65 /* PA8 */ { 1, 1, 0, 0, 0, 0 }, /* SMC2 RxD */
66 /* PA7 */ { 0, 0, 0, 0, 0, 0 }, /* PA7 */
67 /* PA6 */ { 0, 0, 0, 0, 0, 0 }, /* PA6 */
68 /* PA5 */ { 0, 0, 0, 0, 0, 0 }, /* PA5 */
69 /* PA4 */ { 0, 0, 0, 0, 0, 0 }, /* PA4 */
70 /* PA3 */ { 0, 0, 0, 0, 0, 0 }, /* PA3 */
71 /* PA2 */ { 0, 0, 0, 0, 0, 0 }, /* PA2 */
72 /* PA1 */ { 0, 0, 0, 0, 0, 0 }, /* PA1 */
73 /* PA0 */ { 0, 0, 0, 0, 0, 0 } /* PA0 */
74 },
75
76 /* Port B */
77 { /* conf ppar psor pdir podr pdat */
78 /* PB31 */ { 0, 0, 0, 0, 0, 0 }, /* PB31 */
79 /* PB30 */ { 0, 0, 0, 0, 0, 0 }, /* PB30 */
80 /* PB29 */ { 0, 0, 0, 0, 0, 0 }, /* PB29 */
81 /* PB28 */ { 1, 1, 1, 1, 0, 0 }, /* SCC1 TxD */
82 /* PB27 */ { 0, 0, 0, 0, 0, 0 }, /* PB27 */
83 /* PB26 */ { 0, 0, 0, 0, 0, 0 }, /* PB26 */
84 /* PB25 */ { 0, 0, 0, 0, 0, 0 }, /* PB25 */
85 /* PB24 */ { 0, 0, 0, 0, 0, 0 }, /* PB24 */
86 /* PB23 */ { 0, 0, 0, 0, 0, 0 }, /* PB23 */
87 /* PB22 */ { 0, 0, 0, 0, 0, 0 }, /* PB22 */
88 /* PB21 */ { 0, 0, 0, 0, 0, 0 }, /* PB21 */
89 /* PB20 */ { 0, 0, 0, 0, 0, 0 }, /* PB20 */
90 /* PB19 */ { 0, 0, 0, 0, 0, 0 }, /* PB19 */
91 /* PB18 */ { 0, 0, 0, 0, 0, 0 }, /* PB18 */
92 /* PB17 */ { 0, 0, 0, 0, 0, 0 }, /* non-existent */
93 /* PB16 */ { 0, 0, 0, 0, 0, 0 }, /* non-existent */
94 /* PB15 */ { 1, 1, 0, 0, 0, 0 }, /* SCC2 RxD */
95 /* PB14 */ { 1, 1, 0, 0, 0, 0 }, /* SCC3 RxD */
96 /* PB13 */ { 0, 0, 0, 0, 0, 0 }, /* non-existent */
97 /* PB12 */ { 1, 1, 1, 1, 0, 0 }, /* SCC2 TxD */
98 /* PB11 */ { 0, 0, 0, 0, 0, 0 }, /* non-existent */
99 /* PB10 */ { 0, 0, 0, 0, 0, 0 }, /* non-existent */
100 /* PB9 */ { 0, 0, 0, 0, 0, 0 }, /* non-existent */
101 /* PB8 */ { 1, 1, 1, 1, 0, 0 }, /* SCC3 TxD */
102 /* PB7 */ { 0, 0, 0, 0, 0, 0 }, /* non-existent */
103 /* PB6 */ { 0, 0, 0, 0, 0, 0 }, /* non-existent */
104 /* PB5 */ { 0, 0, 0, 0, 0, 0 }, /* non-existent */
105 /* PB4 */ { 0, 0, 0, 0, 0, 0 }, /* non-existent */
106 /* PB3 */ { 0, 0, 0, 0, 0, 0 }, /* non-existent */
107 /* PB2 */ { 0, 0, 0, 0, 0, 0 }, /* non-existent */
108 /* PB1 */ { 0, 0, 0, 0, 0, 0 }, /* non-existent */
109 /* PB0 */ { 0, 0, 0, 0, 0, 0 } /* non-existent */
110 },
111
112 /* Port C */
113 { /* conf ppar psor pdir podr pdat */
114 /* PC31 */ { 0, 0, 0, 0, 0, 0 }, /* PC31 */
115 /* PC30 */ { 1, 1, 1, 1, 0, 0 }, /* Timer1 OUT */
116 /* PC29 */ { 0, 0, 0, 0, 0, 0 }, /* PC29 */
117 /* PC28 */ { 0, 0, 0, 0, 0, 0 }, /* PC28 */
118 /* PC27 */ { 0, 0, 0, 0, 0, 0 }, /* PC27 */
119 /* PC26 */ { 0, 0, 0, 0, 0, 0 }, /* PC26 */
120 /* PC25 */ { 0, 0, 0, 0, 0, 0 }, /* PC25 */
121 /* PC24 */ { 0, 0, 0, 0, 0, 0 }, /* PC24 */
122 /* PC23 */ { 0, 0, 0, 0, 0, 0 }, /* PC23 */
123 /* PC22 */ { 0, 0, 0, 0, 0, 0 }, /* PC22 */
124 /* PC21 */ { 1, 1, 0, 0, 0, 0 }, /* FCC RxCLK 11 */
125 /* PC20 */ { 1, 1, 0, 0, 0, 0 }, /* FCC TxCLK 12 */
126 /* PC19 */ { 0, 0, 0, 0, 0, 0 }, /* PC19 */
127 /* PC18 */ { 0, 0, 0, 0, 0, 0 }, /* PC18 */
128 /* PC17 */ { 0, 0, 0, 0, 0, 0 }, /* PC17 */
129 /* PC16 */ { 0, 0, 0, 0, 0, 0 }, /* PC16 */
130 /* PC15 */ { 1, 1, 0, 1, 0, 0 }, /* SMC2 TxD */
131 /* PC14 */ { 0, 0, 0, 0, 0, 0 }, /* PC14 */
132 /* PC13 */ { 0, 0, 0, 0, 0, 0 }, /* PC13 */
133 /* PC12 */ { 1, 0, 0, 1, 0, 0 }, /* TX OUTPUT SLEW1 */
134 /* PC11 */ { 1, 0, 0, 1, 0, 0 }, /* TX OUTPUT SLEW0 */
135 /* PC10 */ { 0, 0, 0, 0, 0, 0 }, /* PC10 */
136 /* PC9 */ { 1, 0, 0, 1, 0, 1 }, /* SPA_TX_EN */
137 /* PC8 */ { 0, 0, 0, 0, 0, 0 }, /* PC8 */
138 /* PC7 */ { 0, 0, 0, 0, 0, 0 }, /* PC7 */
139 /* PC6 */ { 0, 0, 0, 0, 0, 0 }, /* PC6 */
140 /* PC5 */ { 0, 0, 0, 0, 0, 0 }, /* PC5 */
141 /* PC4 */ { 0, 0, 0, 0, 0, 0 }, /* PC4 */
142 /* PC3 */ { 0, 0, 0, 0, 0, 0 }, /* PC3 */
143 /* PC2 */ { 0, 0, 0, 0, 0, 0 }, /* PC2 */
144 /* PC1 */ { 0, 0, 0, 0, 0, 0 }, /* PC1 */
145 /* PC0 */ { 0, 0, 0, 0, 0, 0 }, /* PC0 */
146 },
147
148 /* Port D */
149 { /* conf ppar psor pdir podr pdat */
150 /* PD31 */ { 1, 1, 0, 0, 0, 0 }, /* SCC1 RxD */
151 /* PD30 */ { 0, 0, 0, 0, 0, 0 }, /* PD30 */
152 /* PD29 */ { 0, 0, 0, 0, 0, 0 }, /* PD29 */
153 /* PD28 */ { 0, 0, 0, 0, 0, 0 }, /* PD28 */
154 /* PD27 */ { 0, 0, 0, 0, 0, 0 }, /* PD27 */
155 /* PD26 */ { 0, 0, 0, 0, 0, 0 }, /* PD26 */
156 /* PD25 */ { 0, 0, 0, 0, 0, 0 }, /* PD25 */
157 /* PD24 */ { 0, 0, 0, 0, 0, 0 }, /* PD24 */
158 /* PD23 */ { 0, 0, 0, 0, 0, 0 }, /* PD23 */
159 /* PD22 */ { 1, 1, 0, 0, 0, 0 }, /* SCC4: RXD */
160 /* PD21 */ { 1, 1, 0, 1, 0, 0 }, /* SCC4: TXD */
161 /* PD20 */ { 0, 0, 0, 0, 0, 0 }, /* PD18 */
162 /* PD19 */ { 0, 0, 0, 0, 0, 0 }, /* PD19 */
163 /* PD18 */ { 0, 0, 0, 0, 0, 0 }, /* PD18 */
164 /* PD17 */ { 0, 0, 0, 0, 0, 0 }, /* PD17 */
165 /* PD16 */ { 0, 0, 0, 0, 0, 0 }, /* PD16 */
166 /* PD15 */ { 1, 1, 1, 0, 0, 0 }, /* I2C SDA */
167 /* PD14 */ { 1, 1, 1, 0, 0, 0 }, /* I2C SCL */
168 /* PD13 */ { 0, 0, 0, 0, 0, 0 }, /* PD13 */
169 /* PD12 */ { 0, 0, 0, 0, 0, 0 }, /* PD12 */
170 /* PD11 */ { 0, 0, 0, 0, 0, 0 }, /* PD11 */
171 /* PD10 */ { 0, 0, 0, 0, 0, 0 }, /* PD10 */
172 /* PD9 */ { 1, 1, 0, 1, 0, 0 }, /* SMC1 TxD */
173 /* PD8 */ { 1, 1, 0, 0, 0, 0 }, /* SMC1 RxD */
174 /* PD7 */ { 0, 0, 0, 0, 0, 0 }, /* PD7 */
175 /* PD6 */ { 0, 0, 0, 0, 0, 0 }, /* PD6 */
176 /* PD5 */ { 0, 0, 0, 0, 0, 0 }, /* PD5 */
177 /* PD4 */ { 0, 0, 0, 0, 0, 0 }, /* PD4 */
178 /* PD3 */ { 0, 0, 0, 0, 0, 0 }, /* non-existent */
179 /* PD2 */ { 0, 0, 0, 0, 0, 0 }, /* non-existent */
180 /* PD1 */ { 0, 0, 0, 0, 0, 0 }, /* non-existent */
181 /* PD0 */ { 0, 0, 0, 0, 0, 0 } /* non-existent */
182 }
183};
184
185/* Try SDRAM initialization with P/LSDMR=sdmr and ORx=orx
186 *
187 * This routine performs standard 8260 initialization sequence
188 * and calculates the available memory size. It may be called
189 * several times to try different SDRAM configurations on both
190 * 60x and local buses.
191 */
192static long int try_init (volatile memctl8260_t * memctl, ulong sdmr,
193 ulong orx, volatile uchar * base)
194{
195 volatile uchar c = 0xff;
196 volatile uint *sdmr_ptr;
197 volatile uint *orx_ptr;
198 ulong maxsize, size;
199 int i;
200
201 /* We must be able to test a location outsize the maximum legal size
202 * to find out THAT we are outside; but this address still has to be
203 * mapped by the controller. That means, that the initial mapping has
204 * to be (at least) twice as large as the maximum expected size.
205 */
206 maxsize = (1 + (~orx | 0x7fff))/* / 2*/;
207
208 sdmr_ptr = &memctl->memc_psdmr;
209 orx_ptr = &memctl->memc_or1;
210
211 *orx_ptr = orx;
212
213 /*
214 * Quote from 8260 UM (10.4.2 SDRAM Power-On Initialization, 10-35):
215 *
216 * "At system reset, initialization software must set up the
217 * programmable parameters in the memory controller banks registers
218 * (ORx, BRx, P/LSDMR). After all memory parameters are configured,
219 * system software should execute the following initialization sequence
220 * for each SDRAM device.
221 *
222 * 1. Issue a PRECHARGE-ALL-BANKS command
223 * 2. Issue eight CBR REFRESH commands
224 * 3. Issue a MODE-SET command to initialize the mode register
225 *
226 * The initial commands are executed by setting P/LSDMR[OP] and
227 * accessing the SDRAM with a single-byte transaction."
228 *
229 * The appropriate BRx/ORx registers have already been set when we
230 * get here. The SDRAM can be accessed at the address CFG_SDRAM_BASE.
231 */
232
233 *sdmr_ptr = sdmr | PSDMR_OP_PREA;
234 *base = c;
235
236 *sdmr_ptr = sdmr | PSDMR_OP_CBRR;
237 for (i = 0; i < 8; i++)
238 *base = c;
239
240 *sdmr_ptr = sdmr | PSDMR_OP_MRW;
241 *(base + CFG_MRS_OFFS) = c; /* setting MR on address lines */
242
243 *sdmr_ptr = sdmr | PSDMR_OP_NORM | PSDMR_RFEN;
244 *base = c;
245
246 size = get_ram_size ((long *)base, maxsize);
247 *orx_ptr = orx | ~(size - 1);
248
249 return (size);
250}
251
252phys_size_t initdram (int board_type)
253{
254 volatile immap_t *immap = (immap_t *) CFG_IMMR;
255 volatile memctl8260_t *memctl = &immap->im_memctl;
256
257 long psize;
258
259 memctl->memc_psrt = CFG_PSRT;
260 memctl->memc_mptpr = CFG_MPTPR;
261
262#ifndef CFG_RAMBOOT
263 /* 60x SDRAM setup:
264 */
265 psize = try_init (memctl, CFG_PSDMR, CFG_OR1,
266 (uchar *) CFG_SDRAM_BASE);
267#endif /* CFG_RAMBOOT */
268
269 icache_enable ();
270
271 return (psize);
272}
273
274int checkboard (void)
275{
276 puts ("Board: MUAS3001\n");
277
278 return 0;
279}
280
281/*
282 * Early board initalization.
283 */
284int board_early_init_r (void)
285{
286 return 0;
287}
288
289#if defined(CONFIG_OF_BOARD_SETUP) && defined(CONFIG_OF_LIBFDT)
290/*
291 * update "memory" property in the blob
292 */
293void ft_blob_update (void *blob, bd_t *bd)
294{
295 int ret, nodeoffset = 0;
296 ulong memory_data[2] = {0};
297 ulong flash_data[4] = {0};
298 ulong freq = 0;
299 ulong speed = 0;
300
301 memory_data[0] = cpu_to_be32 (bd->bi_memstart);
302 memory_data[1] = cpu_to_be32 (bd->bi_memsize);
303
304 nodeoffset = fdt_path_offset (blob, "/memory");
305 if (nodeoffset >= 0) {
306 ret = fdt_setprop (blob, nodeoffset, "reg", memory_data,
307 sizeof(memory_data));
308 if (ret < 0)
309 printf ("ft_blob_update): cannot set /memory/reg "
310 "property err:%s\n", fdt_strerror (ret));
311 } else {
312 /* memory node is required in dts */
313 printf ("ft_blob_update(): cannot find /memory node "
314 "err:%s\n", fdt_strerror(nodeoffset));
315 }
316 /* update Flash addr, size */
317 flash_data[2] = cpu_to_be32 (CFG_FLASH_BASE);
318 flash_data[3] = cpu_to_be32 (CFG_FLASH_SIZE);
319 nodeoffset = fdt_path_offset (blob, "/localbus");
320 if (nodeoffset >= 0) {
321 ret = fdt_setprop (blob, nodeoffset, "ranges", flash_data,
322 sizeof (flash_data));
323 if (ret < 0)
324 printf ("ft_blob_update): cannot set /localbus/ranges "
325 "property err:%s\n", fdt_strerror(ret));
326 } else {
327 /* memory node is required in dts */
328 printf ("ft_blob_update(): cannot find /localbus node "
329 "err:%s\n", fdt_strerror (nodeoffset));
330 }
331 /* MAC Adresse */
332 nodeoffset = fdt_path_offset (blob, "/soc/cpm/ethernet");
333 if (nodeoffset >= 0) {
334 ret = fdt_setprop (blob, nodeoffset, "mac-address", bd->bi_enetaddr,
335 sizeof (uchar) * 6);
336 if (ret < 0)
337 printf ("ft_blob_update): cannot set /soc/cpm/ethernet/mac-address "
338 "property err:%s\n", fdt_strerror (ret));
339 } else {
340 /* memory node is required in dts */
341 printf ("ft_blob_update(): cannot find /soc/cpm/ethernet node "
342 "err:%s\n", fdt_strerror (nodeoffset));
343 }
344
345 /* brg clock */
346 nodeoffset = fdt_path_offset (blob, "/soc/cpm/brg");
347 if (nodeoffset >= 0) {
348 freq = cpu_to_be32 (bd->bi_brgfreq);
349 ret = fdt_setprop (blob, nodeoffset, "clock-frequency", &freq,
350 sizeof (unsigned long));
351 if (ret < 0)
352 printf ("ft_blob_update): cannot set /soc/cpm/brg/clock-frequency "
353 "property err:%s\n", fdt_strerror (ret));
354 } else {
355 /* memory node is required in dts */
356 printf ("ft_blob_update(): cannot find /soc/cpm/brg/clock-frequency node "
357 "err:%s\n", fdt_strerror (nodeoffset));
358 }
359
360 /* baudrate */
361 nodeoffset = fdt_path_offset (blob, "/soc/cpm/serial");
362 if (nodeoffset >= 0) {
363 speed = cpu_to_be32 (bd->bi_baudrate);
364 ret = fdt_setprop (blob, nodeoffset, "current-speed", &speed,
365 sizeof (unsigned long));
366 if (ret < 0)
367 printf ("ft_blob_update): cannot set /soc/cpm/serial/current-speed "
368 "property err:%s\n", fdt_strerror (ret));
369 } else {
370 /* baudrate is required in dts */
371 printf ("ft_blob_update(): cannot find /soc/cpm/smc2/current-speed node "
372 "err:%s\n", fdt_strerror (nodeoffset));
373 }
374}
375
376void ft_board_setup (void *blob, bd_t *bd)
377{
378 ft_cpu_setup (blob, bd);
379 ft_blob_update (blob, bd);
380}
381#endif /* defined(CONFIG_OF_BOARD_SETUP) && defined(CONFIG_OF_LIBFDT) */