blob: 332afaad9f585b8ef1c2cfe68adc2abc1d92ed43 [file] [log] [blame]
Eran Libertyf046ccd2005-07-28 10:08:46 -05001/*
Dave Liuf6eda7f2006-10-25 14:41:21 -05002 * Copyright (C) 2004-2006 Freescale Semiconductor, Inc.
Eran Libertyf046ccd2005-07-28 10:08:46 -05003 *
4 * See file CREDITS for list of people who contributed to this
5 * project.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License as
9 * published by the Free Software Foundation; either version 2 of
10 * the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
20 * MA 02111-1307 USA
Eran Libertyf046ccd2005-07-28 10:08:46 -050021 */
22
23/*
24 * CPU specific code for the MPC83xx family.
25 *
26 * Derived from the MPC8260 and MPC85xx.
27 */
28
29#include <common.h>
30#include <watchdog.h>
31#include <command.h>
32#include <mpc83xx.h>
33#include <asm/processor.h>
Gerald Van Baren213bf8c2007-03-31 12:23:51 -040034#if defined(CONFIG_OF_FLAT_TREE)
35#include <ft_build.h>
36#endif
37#if defined(CONFIG_OF_LIBFDT)
38#include <libfdt.h>
39#include <libfdt_env.h>
40#endif
Eran Libertyf046ccd2005-07-28 10:08:46 -050041
Wolfgang Denkd87080b2006-03-31 18:32:53 +020042DECLARE_GLOBAL_DATA_PTR;
43
Eran Libertyf046ccd2005-07-28 10:08:46 -050044
45int checkcpu(void)
46{
Dave Liu5f820432006-11-03 19:33:44 -060047 volatile immap_t *immr;
Eran Libertyf046ccd2005-07-28 10:08:46 -050048 ulong clock = gd->cpu_clk;
49 u32 pvr = get_pvr();
Dave Liu5f820432006-11-03 19:33:44 -060050 u32 spridr;
Eran Libertyf046ccd2005-07-28 10:08:46 -050051 char buf[32];
52
Timur Tabid239d742006-11-03 12:00:28 -060053 immr = (immap_t *)CFG_IMMR;
Dave Liu5f820432006-11-03 19:33:44 -060054
Scott Wood95e7ef82007-04-16 14:34:16 -050055 puts("CPU: ");
56
57 switch (pvr & 0xffff0000) {
58 case PVR_E300C1:
59 printf("e300c1, ");
60 break;
61
62 case PVR_E300C2:
63 printf("e300c2, ");
64 break;
65
66 case PVR_E300C3:
67 printf("e300c3, ");
68 break;
69
70 default:
71 printf("Unknown core, ");
Eran Libertyf046ccd2005-07-28 10:08:46 -050072 }
73
Dave Liu5f820432006-11-03 19:33:44 -060074 spridr = immr->sysconf.spridr;
Dave Liu5f820432006-11-03 19:33:44 -060075 switch(spridr) {
76 case SPR_8349E_REV10:
77 case SPR_8349E_REV11:
Xie Xiaobo8d172c02007-02-14 18:26:44 +080078 case SPR_8349E_REV31:
Dave Liu5f820432006-11-03 19:33:44 -060079 puts("MPC8349E, ");
Eran Libertyf046ccd2005-07-28 10:08:46 -050080 break;
Dave Liu5f820432006-11-03 19:33:44 -060081 case SPR_8349_REV10:
82 case SPR_8349_REV11:
Xie Xiaobo8d172c02007-02-14 18:26:44 +080083 case SPR_8349_REV31:
Dave Liu5f820432006-11-03 19:33:44 -060084 puts("MPC8349, ");
85 break;
86 case SPR_8347E_REV10_TBGA:
87 case SPR_8347E_REV11_TBGA:
Xie Xiaobo8d172c02007-02-14 18:26:44 +080088 case SPR_8347E_REV31_TBGA:
Dave Liu5f820432006-11-03 19:33:44 -060089 case SPR_8347E_REV10_PBGA:
90 case SPR_8347E_REV11_PBGA:
Xie Xiaobo8d172c02007-02-14 18:26:44 +080091 case SPR_8347E_REV31_PBGA:
Dave Liu5f820432006-11-03 19:33:44 -060092 puts("MPC8347E, ");
93 break;
94 case SPR_8347_REV10_TBGA:
95 case SPR_8347_REV11_TBGA:
Xie Xiaobo8d172c02007-02-14 18:26:44 +080096 case SPR_8347_REV31_TBGA:
Dave Liu5f820432006-11-03 19:33:44 -060097 case SPR_8347_REV10_PBGA:
98 case SPR_8347_REV11_PBGA:
Xie Xiaobo8d172c02007-02-14 18:26:44 +080099 case SPR_8347_REV31_PBGA:
Dave Liu5f820432006-11-03 19:33:44 -0600100 puts("MPC8347, ");
101 break;
102 case SPR_8343E_REV10:
103 case SPR_8343E_REV11:
Xie Xiaobo8d172c02007-02-14 18:26:44 +0800104 case SPR_8343E_REV31:
Dave Liu5f820432006-11-03 19:33:44 -0600105 puts("MPC8343E, ");
106 break;
107 case SPR_8343_REV10:
108 case SPR_8343_REV11:
Xie Xiaobo8d172c02007-02-14 18:26:44 +0800109 case SPR_8343_REV31:
Dave Liu5f820432006-11-03 19:33:44 -0600110 puts("MPC8343, ");
111 break;
112 case SPR_8360E_REV10:
113 case SPR_8360E_REV11:
114 case SPR_8360E_REV12:
Xie Xiaobob110f402007-02-14 18:27:06 +0800115 case SPR_8360E_REV20:
Dave Liu5f820432006-11-03 19:33:44 -0600116 puts("MPC8360E, ");
117 break;
118 case SPR_8360_REV10:
119 case SPR_8360_REV11:
120 case SPR_8360_REV12:
Xie Xiaobob110f402007-02-14 18:27:06 +0800121 case SPR_8360_REV20:
Dave Liu5f820432006-11-03 19:33:44 -0600122 puts("MPC8360, ");
Eran Libertyf046ccd2005-07-28 10:08:46 -0500123 break;
Dave Liu24c3aca2006-12-07 21:13:15 +0800124 case SPR_8323E_REV10:
125 case SPR_8323E_REV11:
126 puts("MPC8323E, ");
127 break;
128 case SPR_8323_REV10:
129 case SPR_8323_REV11:
130 puts("MPC8323, ");
131 break;
132 case SPR_8321E_REV10:
133 case SPR_8321E_REV11:
134 puts("MPC8321E, ");
135 break;
136 case SPR_8321_REV10:
137 case SPR_8321_REV11:
138 puts("MPC8321, ");
139 break;
Scott Wooda35b0c42007-04-16 14:34:15 -0500140 case SPR_8311_REV10:
141 puts("MPC8311, ");
142 break;
143 case SPR_8311E_REV10:
144 puts("MPC8311E, ");
145 break;
146 case SPR_8313_REV10:
147 puts("MPC8313, ");
148 break;
149 case SPR_8313E_REV10:
150 puts("MPC8313E, ");
151 break;
Eran Libertyf046ccd2005-07-28 10:08:46 -0500152 default:
Xie Xiaobo8d172c02007-02-14 18:26:44 +0800153 puts("Rev: Unknown revision number.\nWarning: Unsupported cpu revision!\n");
154 return 0;
Eran Libertyf046ccd2005-07-28 10:08:46 -0500155 }
Rafal Jaworowski6902df52005-10-17 02:39:53 +0200156
Kumar Gala3e78a312007-01-30 14:08:30 -0600157#if defined(CONFIG_MPC834X)
Xie Xiaobo8d172c02007-02-14 18:26:44 +0800158 /* Multiple revisons of 834x processors may have the same SPRIDR value.
159 * So use PVR to identify the revision number.
160 */
161 printf("Rev: %02x at %s MHz\n", PVR_MAJ(pvr)<<4 | PVR_MIN(pvr), strmhz(buf, clock));
Dave Liu5f820432006-11-03 19:33:44 -0600162#else
163 printf("Rev: %02x at %s MHz\n", spridr & 0x0000FFFF, strmhz(buf, clock));
164#endif
Eran Libertyf046ccd2005-07-28 10:08:46 -0500165 return 0;
166}
167
168
Timur Tabibe5e6182006-11-03 19:15:00 -0600169/*
Timur Tabi2ad6b512006-10-31 18:44:42 -0600170 * Program a UPM with the code supplied in the table.
171 *
172 * The 'dummy' variable is used to increment the MAD. 'dummy' is
173 * supposed to be a pointer to the memory of the device being
174 * programmed by the UPM. The data in the MDR is written into
175 * memory and the MAD is incremented every time there's a read
176 * from 'dummy'. Unfortunately, the current prototype for this
177 * function doesn't allow for passing the address of this
178 * device, and changing the prototype will break a number lots
179 * of other code, so we need to use a round-about way of finding
180 * the value for 'dummy'.
181 *
182 * The value can be extracted from the base address bits of the
183 * Base Register (BR) associated with the specific UPM. To find
184 * that BR, we need to scan all 8 BRs until we find the one that
185 * has its MSEL bits matching the UPM we want. Once we know the
186 * right BR, we can extract the base address bits from it.
187 *
188 * The MxMR and the BR and OR of the chosen bank should all be
189 * configured before calling this function.
190 *
191 * Parameters:
192 * upm: 0=UPMA, 1=UPMB, 2=UPMC
193 * table: Pointer to an array of values to program
194 * size: Number of elements in the array. Must be 64 or less.
Timur Tabibe5e6182006-11-03 19:15:00 -0600195 */
Eran Libertyf046ccd2005-07-28 10:08:46 -0500196void upmconfig (uint upm, uint *table, uint size)
197{
Timur Tabi2ad6b512006-10-31 18:44:42 -0600198#if defined(CONFIG_MPC834X)
Timur Tabid239d742006-11-03 12:00:28 -0600199 volatile immap_t *immap = (immap_t *) CFG_IMMR;
Timur Tabi2ad6b512006-10-31 18:44:42 -0600200 volatile lbus83xx_t *lbus = &immap->lbus;
201 volatile uchar *dummy = NULL;
202 const u32 msel = (upm + 4) << BR_MSEL_SHIFT; /* What the MSEL field in BRn should be */
203 volatile u32 *mxmr = &lbus->mamr + upm; /* Pointer to mamr, mbmr, or mcmr */
204 uint i;
205
206 /* Scan all the banks to determine the base address of the device */
207 for (i = 0; i < 8; i++) {
208 if ((lbus->bank[i].br & BR_MSEL) == msel) {
209 dummy = (uchar *) (lbus->bank[i].br & BR_BA);
210 break;
211 }
212 }
213
214 if (!dummy) {
215 printf("Error: %s() could not find matching BR\n", __FUNCTION__);
216 hang();
217 }
218
219 /* Set the OP field in the MxMR to "write" and the MAD field to 000000 */
220 *mxmr = (*mxmr & 0xCFFFFFC0) | 0x10000000;
221
222 for (i = 0; i < size; i++) {
223 lbus->mdr = table[i];
224 __asm__ __volatile__ ("sync");
225 *dummy; /* Write the value to memory and increment MAD */
226 __asm__ __volatile__ ("sync");
227 }
228
229 /* Set the OP field in the MxMR to "normal" and the MAD field to 000000 */
230 *mxmr &= 0xCFFFFFC0;
231#else
232 printf("Error: %s() not defined for this configuration.\n", __FUNCTION__);
233 hang();
234#endif
Eran Libertyf046ccd2005-07-28 10:08:46 -0500235}
236
237
238int
239do_reset (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
240{
Wolfgang Denk07a25052005-08-05 19:49:35 +0200241 ulong msr;
242#ifndef MPC83xx_RESET
243 ulong addr;
244#endif
Eran Libertyf046ccd2005-07-28 10:08:46 -0500245
Timur Tabid239d742006-11-03 12:00:28 -0600246 volatile immap_t *immap = (immap_t *) CFG_IMMR;
Eran Libertyf046ccd2005-07-28 10:08:46 -0500247
248#ifdef MPC83xx_RESET
249 /* Interrupts and MMU off */
250 __asm__ __volatile__ ("mfmsr %0":"=r" (msr):);
251
252 msr &= ~( MSR_EE | MSR_IR | MSR_DR);
253 __asm__ __volatile__ ("mtmsr %0"::"r" (msr));
254
255 /* enable Reset Control Reg */
256 immap->reset.rpr = 0x52535445;
Marian Balakowicz6d8ae5a2006-03-14 16:12:48 +0100257 __asm__ __volatile__ ("sync");
258 __asm__ __volatile__ ("isync");
Eran Libertyf046ccd2005-07-28 10:08:46 -0500259
260 /* confirm Reset Control Reg is enabled */
261 while(!((immap->reset.rcer) & RCER_CRE));
262
263 printf("Resetting the board.");
264 printf("\n");
265
266 udelay(200);
267
268 /* perform reset, only one bit */
Wolfgang Denk07a25052005-08-05 19:49:35 +0200269 immap->reset.rcr = RCR_SWHR;
Eran Libertyf046ccd2005-07-28 10:08:46 -0500270
Wolfgang Denk07a25052005-08-05 19:49:35 +0200271#else /* ! MPC83xx_RESET */
272
273 immap->reset.rmr = RMR_CSRE; /* Checkstop Reset enable */
274
275 /* Interrupts and MMU off */
276 __asm__ __volatile__ ("mfmsr %0":"=r" (msr):);
Eran Libertyf046ccd2005-07-28 10:08:46 -0500277
278 msr &= ~(MSR_ME | MSR_EE | MSR_IR | MSR_DR);
279 __asm__ __volatile__ ("mtmsr %0"::"r" (msr));
280
281 /*
282 * Trying to execute the next instruction at a non-existing address
283 * should cause a machine check, resulting in reset
284 */
285 addr = CFG_RESET_ADDRESS;
286
287 printf("resetting the board.");
288 printf("\n");
289 ((void (*)(void)) addr) ();
Wolfgang Denk07a25052005-08-05 19:49:35 +0200290#endif /* MPC83xx_RESET */
291
Eran Libertyf046ccd2005-07-28 10:08:46 -0500292 return 1;
293}
294
295
296/*
297 * Get timebase clock frequency (like cpu_clk in Hz)
298 */
299
300unsigned long get_tbclk(void)
301{
Eran Libertyf046ccd2005-07-28 10:08:46 -0500302 ulong tbclk;
303
304 tbclk = (gd->bus_clk + 3L) / 4L;
305
306 return tbclk;
307}
308
309
310#if defined(CONFIG_WATCHDOG)
311void watchdog_reset (void)
312{
Timur Tabi2ad6b512006-10-31 18:44:42 -0600313 int re_enable = disable_interrupts();
314
315 /* Reset the 83xx watchdog */
Timur Tabid239d742006-11-03 12:00:28 -0600316 volatile immap_t *immr = (immap_t *) CFG_IMMR;
Timur Tabi2ad6b512006-10-31 18:44:42 -0600317 immr->wdt.swsrr = 0x556c;
318 immr->wdt.swsrr = 0xaa39;
319
320 if (re_enable)
321 enable_interrupts ();
Eran Libertyf046ccd2005-07-28 10:08:46 -0500322}
Timur Tabi2ad6b512006-10-31 18:44:42 -0600323#endif
Kumar Gala62ec6412006-01-11 16:48:10 -0600324
Gerald Van Baren213bf8c2007-03-31 12:23:51 -0400325#if defined(CONFIG_OF_LIBFDT)
326
327/*
Gerald Van Barenf35a53f2007-04-15 13:54:26 -0400328 * "Setter" functions used to add/modify FDT entries.
329 */
330static int fdt_set_eth0(void *fdt, int nodeoffset, const char *name, bd_t *bd)
331{
332 /*
333 * Fix it up if it exists, don't create it if it doesn't exist.
334 */
335 if (fdt_get_property(fdt, nodeoffset, name, 0)) {
336 return fdt_setprop(fdt, nodeoffset, name, bd->bi_enetaddr, 6);
337 }
338 return -FDT_ERR_NOTFOUND;
339}
340#ifdef CONFIG_HAS_ETH1
341/* second onboard ethernet port */
342static int fdt_set_eth1(void *fdt, int nodeoffset, const char *name, bd_t *bd)
343{
344 /*
345 * Fix it up if it exists, don't create it if it doesn't exist.
346 */
347 if (fdt_get_property(fdt, nodeoffset, name, 0)) {
348 return fdt_setprop(fdt, nodeoffset, name, bd->bi_enet1addr, 6);
349 }
350 return -FDT_ERR_NOTFOUND;
351}
352#endif
353#ifdef CONFIG_HAS_ETH2
354/* third onboard ethernet port */
355static int fdt_set_eth2(void *fdt, int nodeoffset, const char *name, bd_t *bd)
356{
357 /*
358 * Fix it up if it exists, don't create it if it doesn't exist.
359 */
360 if (fdt_get_property(fdt, nodeoffset, name, 0)) {
361 return fdt_setprop(fdt, nodeoffset, name, bd->bi_enet2addr, 6);
362 }
363 return -FDT_ERR_NOTFOUND;
364}
365#endif
366#ifdef CONFIG_HAS_ETH3
367/* fourth onboard ethernet port */
368static int fdt_set_eth3(void *fdt, int nodeoffset, const char *name, bd_t *bd)
369{
370 /*
371 * Fix it up if it exists, don't create it if it doesn't exist.
372 */
373 if (fdt_get_property(fdt, nodeoffset, name, 0)) {
374 return fdt_setprop(fdt, nodeoffset, name, bd->bi_enet3addr, 6);
375 }
376 return -FDT_ERR_NOTFOUND;
377}
378#endif
379
380static int fdt_set_busfreq(void *fdt, int nodeoffset, const char *name, bd_t *bd)
381{
382 u32 tmp;
383 /*
384 * Create or update the property.
385 */
386 tmp = cpu_to_be32(bd->bi_busfreq);
387 return fdt_setprop(fdt, nodeoffset, name, &tmp, sizeof(tmp));
388}
389
390/*
Gerald Van Baren213bf8c2007-03-31 12:23:51 -0400391 * Fixups to the fdt. If "create" is TRUE, the node is created
392 * unconditionally. If "create" is FALSE, the node is updated
393 * only if it already exists.
394 */
Gerald Van Baren213bf8c2007-03-31 12:23:51 -0400395static const struct {
Gerald Van Baren213bf8c2007-03-31 12:23:51 -0400396 char *node;
397 char *prop;
Gerald Van Barenf35a53f2007-04-15 13:54:26 -0400398 int (*set_fn)(void *fdt, int nodeoffset, const char *name, bd_t *bd);
Gerald Van Baren213bf8c2007-03-31 12:23:51 -0400399} fixup_props[] = {
Gerald Van Barenf35a53f2007-04-15 13:54:26 -0400400 { "/cpus/" OF_CPU,
Gerald Van Baren213bf8c2007-03-31 12:23:51 -0400401 "bus-frequency",
Gerald Van Barenf35a53f2007-04-15 13:54:26 -0400402 fdt_set_busfreq
Gerald Van Baren213bf8c2007-03-31 12:23:51 -0400403 },
Gerald Van Barenf35a53f2007-04-15 13:54:26 -0400404 { "/cpus/" OF_SOC,
405 "bus-frequency",
406 fdt_set_busfreq
Gerald Van Baren213bf8c2007-03-31 12:23:51 -0400407 },
Gerald Van Barenf35a53f2007-04-15 13:54:26 -0400408 { "/" OF_SOC "/serial@4500/",
409 "clock-frequency",
410 fdt_set_busfreq
Gerald Van Baren213bf8c2007-03-31 12:23:51 -0400411 },
Gerald Van Barenf35a53f2007-04-15 13:54:26 -0400412 { "/" OF_SOC "/serial@4600/",
413 "clock-frequency",
414 fdt_set_busfreq
Gerald Van Baren213bf8c2007-03-31 12:23:51 -0400415 },
416#ifdef CONFIG_MPC83XX_TSEC1
Gerald Van Barenf35a53f2007-04-15 13:54:26 -0400417 { "/" OF_SOC "/ethernet@24000,
Gerald Van Baren213bf8c2007-03-31 12:23:51 -0400418 "mac-address",
Gerald Van Barenf35a53f2007-04-15 13:54:26 -0400419 fdt_set_eth0
Gerald Van Baren213bf8c2007-03-31 12:23:51 -0400420 },
Gerald Van Barenf35a53f2007-04-15 13:54:26 -0400421 { "/" OF_SOC "/ethernet@24000,
Gerald Van Baren213bf8c2007-03-31 12:23:51 -0400422 "local-mac-address",
Gerald Van Barenf35a53f2007-04-15 13:54:26 -0400423 fdt_set_eth0
Gerald Van Baren213bf8c2007-03-31 12:23:51 -0400424 },
425#endif
426#ifdef CONFIG_MPC83XX_TSEC2
Gerald Van Barenf35a53f2007-04-15 13:54:26 -0400427 { "/" OF_SOC "/ethernet@25000,
Gerald Van Baren213bf8c2007-03-31 12:23:51 -0400428 "mac-address",
Gerald Van Barenf35a53f2007-04-15 13:54:26 -0400429 fdt_set_eth1
Gerald Van Baren213bf8c2007-03-31 12:23:51 -0400430 },
Gerald Van Barenf35a53f2007-04-15 13:54:26 -0400431 { "/" OF_SOC "/ethernet@25000,
Gerald Van Baren213bf8c2007-03-31 12:23:51 -0400432 "local-mac-address",
Gerald Van Barenf35a53f2007-04-15 13:54:26 -0400433 fdt_set_eth1
Gerald Van Baren213bf8c2007-03-31 12:23:51 -0400434 },
435#endif
Gerald Van Barenf35a53f2007-04-15 13:54:26 -0400436#ifdef CONFIG_UEC_ETH1
437#if CFG_UEC1_UCC_NUM == 0 /* UCC1 */
438 { "/" OF_QE "/ucc@2000/mac-address",
439 "mac-address",
440 fdt_set_eth0
441 },
442 { "/" OF_QE "/ucc@2000/mac-address",
443 "local-mac-address",
444 fdt_set_eth0
445 },
446#elif CFG_UEC1_UCC_NUM == 2 /* UCC3 */
447 { "/" OF_QE "/ucc@2200/mac-address",
448 "mac-address",
449 fdt_set_eth0
450 },
451 { "/" OF_QE "/ucc@2200/mac-address",
452 "local-mac-address",
453 fdt_set_eth0
454 },
455#endif
456#endif
457#ifdef CONFIG_UEC_ETH2
458#if CFG_UEC2_UCC_NUM == 1 /* UCC2 */
459 { "/" OF_QE "/ucc@3000/mac-address",
460 "mac-address",
461 fdt_set_eth1
462 },
463 { "/" OF_QE "/ucc@3000/mac-address",
464 "local-mac-address",
465 fdt_set_eth1
466 },
467#elif CFG_UEC1_UCC_NUM == 3 /* UCC4 */
468 { "/" OF_QE "/ucc@3200/mac-address",
469 "mac-address",
470 fdt_set_eth1
471 },
472 { "/" OF_QE "/ucc@3200/mac-address",
473 "local-mac-address",
474 fdt_set_eth1
475 },
476#endif
477#endif
Gerald Van Baren213bf8c2007-03-31 12:23:51 -0400478};
479
480void
481ft_cpu_setup(void *blob, bd_t *bd)
482{
Gerald Van Barenf35a53f2007-04-15 13:54:26 -0400483 int nodeoffset;
484 int err;
485 int j;
Gerald Van Baren213bf8c2007-03-31 12:23:51 -0400486
487 for (j = 0; j < (sizeof(fixup_props) / sizeof(fixup_props[0])); j++) {
Gerald Van Barenf35a53f2007-04-15 13:54:26 -0400488 nodeoffset = fdt_path_offset(fdt, fixup_props[j].node);
Gerald Van Baren213bf8c2007-03-31 12:23:51 -0400489 if (nodeoffset >= 0) {
Gerald Van Barenf35a53f2007-04-15 13:54:26 -0400490 err = (*fixup_props[j].set_fn)(blob, nodeoffset, fixup_props[j].prop, bd);
491 if (err < 0)
492 printf("set_fn/libfdt: %s %s returned %s\n",
493 fixup_props[j].node,
494 fixup_props[j].prop,
495 fdt_strerror(err));
Gerald Van Baren213bf8c2007-03-31 12:23:51 -0400496 }
497 }
498}
499#endif
500
Kumar Gala62ec6412006-01-11 16:48:10 -0600501#if defined(CONFIG_OF_FLAT_TREE)
502void
503ft_cpu_setup(void *blob, bd_t *bd)
504{
505 u32 *p;
506 int len;
507 ulong clock;
508
509 clock = bd->bi_busfreq;
510 p = ft_get_prop(blob, "/cpus/" OF_CPU "/bus-frequency", &len);
511 if (p != NULL)
512 *p = cpu_to_be32(clock);
513
514 p = ft_get_prop(blob, "/" OF_SOC "/bus-frequency", &len);
515 if (p != NULL)
516 *p = cpu_to_be32(clock);
517
518 p = ft_get_prop(blob, "/" OF_SOC "/serial@4500/clock-frequency", &len);
519 if (p != NULL)
520 *p = cpu_to_be32(clock);
521
522 p = ft_get_prop(blob, "/" OF_SOC "/serial@4600/clock-frequency", &len);
523 if (p != NULL)
524 *p = cpu_to_be32(clock);
525
526#ifdef CONFIG_MPC83XX_TSEC1
Timur Tabi61f4f912007-02-13 10:41:42 -0600527 p = ft_get_prop(blob, "/" OF_SOC "/ethernet@24000/mac-address", &len);
528 if (p != NULL)
529 memcpy(p, bd->bi_enetaddr, 6);
530
Kim Phillips48041362006-11-01 00:07:25 -0600531 p = ft_get_prop(blob, "/" OF_SOC "/ethernet@24000/local-mac-address", &len);
Kim Phillipsb7004742007-01-30 16:15:21 -0600532 if (p != NULL)
Kumar Gala62ec6412006-01-11 16:48:10 -0600533 memcpy(p, bd->bi_enetaddr, 6);
534#endif
535
536#ifdef CONFIG_MPC83XX_TSEC2
Timur Tabi61f4f912007-02-13 10:41:42 -0600537 p = ft_get_prop(blob, "/" OF_SOC "/ethernet@25000/mac-address", &len);
538 if (p != NULL)
539 memcpy(p, bd->bi_enet1addr, 6);
540
Kim Phillips48041362006-11-01 00:07:25 -0600541 p = ft_get_prop(blob, "/" OF_SOC "/ethernet@25000/local-mac-address", &len);
Kim Phillipsb7004742007-01-30 16:15:21 -0600542 if (p != NULL)
Kumar Gala62ec6412006-01-11 16:48:10 -0600543 memcpy(p, bd->bi_enet1addr, 6);
544#endif
Kim Phillipsd51b3cf2007-02-22 20:06:57 -0600545
546#ifdef CONFIG_UEC_ETH1
547#if CFG_UEC1_UCC_NUM == 0 /* UCC1 */
548 p = ft_get_prop(blob, "/" OF_QE "/ucc@2000/mac-address", &len);
549 if (p != NULL)
550 memcpy(p, bd->bi_enetaddr, 6);
551
552 p = ft_get_prop(blob, "/" OF_QE "/ucc@2000/local-mac-address", &len);
553 if (p != NULL)
554 memcpy(p, bd->bi_enetaddr, 6);
555#elif CFG_UEC1_UCC_NUM == 2 /* UCC3 */
556 p = ft_get_prop(blob, "/" OF_QE "/ucc@2200/mac-address", &len);
557 if (p != NULL)
558 memcpy(p, bd->bi_enetaddr, 6);
559
560 p = ft_get_prop(blob, "/" OF_QE "/ucc@2200/local-mac-address", &len);
561 if (p != NULL)
562 memcpy(p, bd->bi_enetaddr, 6);
563#endif
564#endif
565
566#ifdef CONFIG_UEC_ETH2
567#if CFG_UEC2_UCC_NUM == 1 /* UCC2 */
568 p = ft_get_prop(blob, "/" OF_QE "/ucc@3000/mac-address", &len);
569 if (p != NULL)
570 memcpy(p, bd->bi_enet1addr, 6);
571
572 p = ft_get_prop(blob, "/" OF_QE "/ucc@3000/local-mac-address", &len);
573 if (p != NULL)
574 memcpy(p, bd->bi_enet1addr, 6);
575#elif CFG_UEC2_UCC_NUM == 3 /* UCC4 */
576 p = ft_get_prop(blob, "/" OF_QE "/ucc@3200/mac-address", &len);
577 if (p != NULL)
578 memcpy(p, bd->bi_enet1addr, 6);
579
580 p = ft_get_prop(blob, "/" OF_QE "/ucc@3200/local-mac-address", &len);
581 if (p != NULL)
582 memcpy(p, bd->bi_enet1addr, 6);
583#endif
584#endif
Kumar Gala62ec6412006-01-11 16:48:10 -0600585}
586#endif
Marian Balakowicz61f25152006-03-14 16:14:48 +0100587
588#if defined(CONFIG_DDR_ECC)
589void dma_init(void)
590{
Timur Tabid239d742006-11-03 12:00:28 -0600591 volatile immap_t *immap = (immap_t *)CFG_IMMR;
Dave Liuf6eda7f2006-10-25 14:41:21 -0500592 volatile dma83xx_t *dma = &immap->dma;
Marian Balakowicz61f25152006-03-14 16:14:48 +0100593 volatile u32 status = swab32(dma->dmasr0);
594 volatile u32 dmamr0 = swab32(dma->dmamr0);
595
596 debug("DMA-init\n");
597
598 /* initialize DMASARn, DMADAR and DMAABCRn */
599 dma->dmadar0 = (u32)0;
600 dma->dmasar0 = (u32)0;
601 dma->dmabcr0 = 0;
602
603 __asm__ __volatile__ ("sync");
604 __asm__ __volatile__ ("isync");
605
606 /* clear CS bit */
607 dmamr0 &= ~DMA_CHANNEL_START;
608 dma->dmamr0 = swab32(dmamr0);
609 __asm__ __volatile__ ("sync");
610 __asm__ __volatile__ ("isync");
611
612 /* while the channel is busy, spin */
613 while(status & DMA_CHANNEL_BUSY) {
614 status = swab32(dma->dmasr0);
615 }
616
617 debug("DMA-init end\n");
618}
619
620uint dma_check(void)
621{
Timur Tabid239d742006-11-03 12:00:28 -0600622 volatile immap_t *immap = (immap_t *)CFG_IMMR;
Dave Liuf6eda7f2006-10-25 14:41:21 -0500623 volatile dma83xx_t *dma = &immap->dma;
Marian Balakowicz61f25152006-03-14 16:14:48 +0100624 volatile u32 status = swab32(dma->dmasr0);
625 volatile u32 byte_count = swab32(dma->dmabcr0);
626
627 /* while the channel is busy, spin */
628 while (status & DMA_CHANNEL_BUSY) {
629 status = swab32(dma->dmasr0);
630 }
631
632 if (status & DMA_CHANNEL_TRANSFER_ERROR) {
633 printf ("DMA Error: status = %x @ %d\n", status, byte_count);
634 }
635
636 return status;
637}
638
639int dma_xfer(void *dest, u32 count, void *src)
640{
Timur Tabid239d742006-11-03 12:00:28 -0600641 volatile immap_t *immap = (immap_t *)CFG_IMMR;
Dave Liuf6eda7f2006-10-25 14:41:21 -0500642 volatile dma83xx_t *dma = &immap->dma;
Marian Balakowicz61f25152006-03-14 16:14:48 +0100643 volatile u32 dmamr0;
644
645 /* initialize DMASARn, DMADAR and DMAABCRn */
646 dma->dmadar0 = swab32((u32)dest);
647 dma->dmasar0 = swab32((u32)src);
648 dma->dmabcr0 = swab32(count);
649
650 __asm__ __volatile__ ("sync");
651 __asm__ __volatile__ ("isync");
652
653 /* init direct transfer, clear CS bit */
654 dmamr0 = (DMA_CHANNEL_TRANSFER_MODE_DIRECT |
655 DMA_CHANNEL_SOURCE_ADDRESS_HOLD_8B |
656 DMA_CHANNEL_SOURCE_ADRESSS_HOLD_EN);
Wolfgang Denkcf48eb92006-04-16 10:51:58 +0200657
Marian Balakowicz61f25152006-03-14 16:14:48 +0100658 dma->dmamr0 = swab32(dmamr0);
659
660 __asm__ __volatile__ ("sync");
661 __asm__ __volatile__ ("isync");
662
663 /* set CS to start DMA transfer */
664 dmamr0 |= DMA_CHANNEL_START;
665 dma->dmamr0 = swab32(dmamr0);
666 __asm__ __volatile__ ("sync");
667 __asm__ __volatile__ ("isync");
668
669 return ((int)dma_check());
670}
671#endif /*CONFIG_DDR_ECC*/