blob: d569c49727b3ce42e5b43eae38ffdfa34ad9c3df [file] [log] [blame]
Eran Liberty9095d4a2005-07-28 10:08:46 -05001/*
Dave Liuf5035922006-10-25 14:41:21 -05002 * Copyright (C) 2004-2006 Freescale Semiconductor, Inc.
Eran Liberty9095d4a2005-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 Liberty9095d4a2005-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 Barend6abef42007-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 Liberty9095d4a2005-07-28 10:08:46 -050041
Wolfgang Denk6405a152006-03-31 18:32:53 +020042DECLARE_GLOBAL_DATA_PTR;
43
Eran Liberty9095d4a2005-07-28 10:08:46 -050044
45int checkcpu(void)
46{
Dave Liua46daea2006-11-03 19:33:44 -060047 volatile immap_t *immr;
Eran Liberty9095d4a2005-07-28 10:08:46 -050048 ulong clock = gd->cpu_clk;
49 u32 pvr = get_pvr();
Dave Liua46daea2006-11-03 19:33:44 -060050 u32 spridr;
Eran Liberty9095d4a2005-07-28 10:08:46 -050051 char buf[32];
52
Timur Tabi386a2802006-11-03 12:00:28 -060053 immr = (immap_t *)CFG_IMMR;
Dave Liua46daea2006-11-03 19:33:44 -060054
Eran Liberty9095d4a2005-07-28 10:08:46 -050055 if ((pvr & 0xFFFF0000) != PVR_83xx) {
56 puts("Not MPC83xx Family!!!\n");
57 return -1;
58 }
59
Dave Liua46daea2006-11-03 19:33:44 -060060 spridr = immr->sysconf.spridr;
61 puts("CPU: ");
62 switch(spridr) {
63 case SPR_8349E_REV10:
64 case SPR_8349E_REV11:
Xie Xiaobo800b7532007-02-14 18:26:44 +080065 case SPR_8349E_REV31:
Dave Liua46daea2006-11-03 19:33:44 -060066 puts("MPC8349E, ");
67 break;
68 case SPR_8349_REV10:
69 case SPR_8349_REV11:
Xie Xiaobo800b7532007-02-14 18:26:44 +080070 case SPR_8349_REV31:
Dave Liua46daea2006-11-03 19:33:44 -060071 puts("MPC8349, ");
72 break;
73 case SPR_8347E_REV10_TBGA:
74 case SPR_8347E_REV11_TBGA:
Xie Xiaobo800b7532007-02-14 18:26:44 +080075 case SPR_8347E_REV31_TBGA:
Dave Liua46daea2006-11-03 19:33:44 -060076 case SPR_8347E_REV10_PBGA:
77 case SPR_8347E_REV11_PBGA:
Xie Xiaobo800b7532007-02-14 18:26:44 +080078 case SPR_8347E_REV31_PBGA:
Dave Liua46daea2006-11-03 19:33:44 -060079 puts("MPC8347E, ");
80 break;
81 case SPR_8347_REV10_TBGA:
82 case SPR_8347_REV11_TBGA:
Xie Xiaobo800b7532007-02-14 18:26:44 +080083 case SPR_8347_REV31_TBGA:
Dave Liua46daea2006-11-03 19:33:44 -060084 case SPR_8347_REV10_PBGA:
85 case SPR_8347_REV11_PBGA:
Xie Xiaobo800b7532007-02-14 18:26:44 +080086 case SPR_8347_REV31_PBGA:
Dave Liua46daea2006-11-03 19:33:44 -060087 puts("MPC8347, ");
Eran Liberty9095d4a2005-07-28 10:08:46 -050088 break;
Dave Liua46daea2006-11-03 19:33:44 -060089 case SPR_8343E_REV10:
90 case SPR_8343E_REV11:
Xie Xiaobo800b7532007-02-14 18:26:44 +080091 case SPR_8343E_REV31:
Dave Liua46daea2006-11-03 19:33:44 -060092 puts("MPC8343E, ");
93 break;
94 case SPR_8343_REV10:
95 case SPR_8343_REV11:
Xie Xiaobo800b7532007-02-14 18:26:44 +080096 case SPR_8343_REV31:
Dave Liua46daea2006-11-03 19:33:44 -060097 puts("MPC8343, ");
98 break;
99 case SPR_8360E_REV10:
100 case SPR_8360E_REV11:
101 case SPR_8360E_REV12:
Xie Xiaoboa9be42a2007-02-14 18:27:06 +0800102 case SPR_8360E_REV20:
Dave Liua46daea2006-11-03 19:33:44 -0600103 puts("MPC8360E, ");
104 break;
105 case SPR_8360_REV10:
106 case SPR_8360_REV11:
107 case SPR_8360_REV12:
Xie Xiaoboa9be42a2007-02-14 18:27:06 +0800108 case SPR_8360_REV20:
Dave Liua46daea2006-11-03 19:33:44 -0600109 puts("MPC8360, ");
Eran Liberty9095d4a2005-07-28 10:08:46 -0500110 break;
Dave Liue740c462006-12-07 21:13:15 +0800111 case SPR_8323E_REV10:
112 case SPR_8323E_REV11:
113 puts("MPC8323E, ");
114 break;
115 case SPR_8323_REV10:
116 case SPR_8323_REV11:
117 puts("MPC8323, ");
118 break;
119 case SPR_8321E_REV10:
120 case SPR_8321E_REV11:
121 puts("MPC8321E, ");
122 break;
123 case SPR_8321_REV10:
124 case SPR_8321_REV11:
125 puts("MPC8321, ");
126 break;
Scott Woodf13983e2007-04-16 14:34:15 -0500127 case SPR_8311_REV10:
128 puts("MPC8311, ");
129 break;
130 case SPR_8311E_REV10:
131 puts("MPC8311E, ");
132 break;
133 case SPR_8313_REV10:
134 puts("MPC8313, ");
135 break;
136 case SPR_8313E_REV10:
137 puts("MPC8313E, ");
138 break;
Eran Liberty9095d4a2005-07-28 10:08:46 -0500139 default:
Xie Xiaobo800b7532007-02-14 18:26:44 +0800140 puts("Rev: Unknown revision number.\nWarning: Unsupported cpu revision!\n");
141 return 0;
Eran Liberty9095d4a2005-07-28 10:08:46 -0500142 }
Rafal Jaworowski384da5e2005-10-17 02:39:53 +0200143
Kumar Galab7870e72007-01-30 14:08:30 -0600144#if defined(CONFIG_MPC834X)
Xie Xiaobo800b7532007-02-14 18:26:44 +0800145 /* Multiple revisons of 834x processors may have the same SPRIDR value.
146 * So use PVR to identify the revision number.
147 */
148 printf("Rev: %02x at %s MHz\n", PVR_MAJ(pvr)<<4 | PVR_MIN(pvr), strmhz(buf, clock));
Dave Liua46daea2006-11-03 19:33:44 -0600149#else
150 printf("Rev: %02x at %s MHz\n", spridr & 0x0000FFFF, strmhz(buf, clock));
151#endif
Eran Liberty9095d4a2005-07-28 10:08:46 -0500152 return 0;
153}
154
155
Timur Tabiab347542006-11-03 19:15:00 -0600156/*
Timur Tabi054838e2006-10-31 18:44:42 -0600157 * Program a UPM with the code supplied in the table.
158 *
159 * The 'dummy' variable is used to increment the MAD. 'dummy' is
160 * supposed to be a pointer to the memory of the device being
161 * programmed by the UPM. The data in the MDR is written into
162 * memory and the MAD is incremented every time there's a read
163 * from 'dummy'. Unfortunately, the current prototype for this
164 * function doesn't allow for passing the address of this
165 * device, and changing the prototype will break a number lots
166 * of other code, so we need to use a round-about way of finding
167 * the value for 'dummy'.
168 *
169 * The value can be extracted from the base address bits of the
170 * Base Register (BR) associated with the specific UPM. To find
171 * that BR, we need to scan all 8 BRs until we find the one that
172 * has its MSEL bits matching the UPM we want. Once we know the
173 * right BR, we can extract the base address bits from it.
174 *
175 * The MxMR and the BR and OR of the chosen bank should all be
176 * configured before calling this function.
177 *
178 * Parameters:
179 * upm: 0=UPMA, 1=UPMB, 2=UPMC
180 * table: Pointer to an array of values to program
181 * size: Number of elements in the array. Must be 64 or less.
Timur Tabiab347542006-11-03 19:15:00 -0600182 */
Eran Liberty9095d4a2005-07-28 10:08:46 -0500183void upmconfig (uint upm, uint *table, uint size)
184{
Timur Tabi054838e2006-10-31 18:44:42 -0600185#if defined(CONFIG_MPC834X)
Timur Tabi386a2802006-11-03 12:00:28 -0600186 volatile immap_t *immap = (immap_t *) CFG_IMMR;
Timur Tabi054838e2006-10-31 18:44:42 -0600187 volatile lbus83xx_t *lbus = &immap->lbus;
188 volatile uchar *dummy = NULL;
189 const u32 msel = (upm + 4) << BR_MSEL_SHIFT; /* What the MSEL field in BRn should be */
190 volatile u32 *mxmr = &lbus->mamr + upm; /* Pointer to mamr, mbmr, or mcmr */
191 uint i;
192
193 /* Scan all the banks to determine the base address of the device */
194 for (i = 0; i < 8; i++) {
195 if ((lbus->bank[i].br & BR_MSEL) == msel) {
196 dummy = (uchar *) (lbus->bank[i].br & BR_BA);
197 break;
198 }
199 }
200
201 if (!dummy) {
202 printf("Error: %s() could not find matching BR\n", __FUNCTION__);
203 hang();
204 }
205
206 /* Set the OP field in the MxMR to "write" and the MAD field to 000000 */
207 *mxmr = (*mxmr & 0xCFFFFFC0) | 0x10000000;
208
209 for (i = 0; i < size; i++) {
210 lbus->mdr = table[i];
211 __asm__ __volatile__ ("sync");
212 *dummy; /* Write the value to memory and increment MAD */
213 __asm__ __volatile__ ("sync");
214 }
215
216 /* Set the OP field in the MxMR to "normal" and the MAD field to 000000 */
217 *mxmr &= 0xCFFFFFC0;
218#else
219 printf("Error: %s() not defined for this configuration.\n", __FUNCTION__);
220 hang();
221#endif
Eran Liberty9095d4a2005-07-28 10:08:46 -0500222}
223
224
225int
226do_reset (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
227{
Wolfgang Denk301d0962005-08-05 19:49:35 +0200228 ulong msr;
229#ifndef MPC83xx_RESET
230 ulong addr;
231#endif
Eran Liberty9095d4a2005-07-28 10:08:46 -0500232
Timur Tabi386a2802006-11-03 12:00:28 -0600233 volatile immap_t *immap = (immap_t *) CFG_IMMR;
Eran Liberty9095d4a2005-07-28 10:08:46 -0500234
235#ifdef MPC83xx_RESET
236 /* Interrupts and MMU off */
237 __asm__ __volatile__ ("mfmsr %0":"=r" (msr):);
238
239 msr &= ~( MSR_EE | MSR_IR | MSR_DR);
240 __asm__ __volatile__ ("mtmsr %0"::"r" (msr));
241
242 /* enable Reset Control Reg */
243 immap->reset.rpr = 0x52535445;
Marian Balakowicz919b1872006-03-14 16:12:48 +0100244 __asm__ __volatile__ ("sync");
245 __asm__ __volatile__ ("isync");
Eran Liberty9095d4a2005-07-28 10:08:46 -0500246
247 /* confirm Reset Control Reg is enabled */
248 while(!((immap->reset.rcer) & RCER_CRE));
249
250 printf("Resetting the board.");
251 printf("\n");
252
253 udelay(200);
254
255 /* perform reset, only one bit */
Wolfgang Denk301d0962005-08-05 19:49:35 +0200256 immap->reset.rcr = RCR_SWHR;
257
258#else /* ! MPC83xx_RESET */
Eran Liberty9095d4a2005-07-28 10:08:46 -0500259
Wolfgang Denk301d0962005-08-05 19:49:35 +0200260 immap->reset.rmr = RMR_CSRE; /* Checkstop Reset enable */
261
262 /* Interrupts and MMU off */
263 __asm__ __volatile__ ("mfmsr %0":"=r" (msr):);
Eran Liberty9095d4a2005-07-28 10:08:46 -0500264
265 msr &= ~(MSR_ME | MSR_EE | MSR_IR | MSR_DR);
266 __asm__ __volatile__ ("mtmsr %0"::"r" (msr));
267
268 /*
269 * Trying to execute the next instruction at a non-existing address
270 * should cause a machine check, resulting in reset
271 */
272 addr = CFG_RESET_ADDRESS;
273
274 printf("resetting the board.");
275 printf("\n");
276 ((void (*)(void)) addr) ();
Wolfgang Denk301d0962005-08-05 19:49:35 +0200277#endif /* MPC83xx_RESET */
278
Eran Liberty9095d4a2005-07-28 10:08:46 -0500279 return 1;
280}
281
282
283/*
284 * Get timebase clock frequency (like cpu_clk in Hz)
285 */
286
287unsigned long get_tbclk(void)
288{
Eran Liberty9095d4a2005-07-28 10:08:46 -0500289 ulong tbclk;
290
291 tbclk = (gd->bus_clk + 3L) / 4L;
292
293 return tbclk;
294}
295
296
297#if defined(CONFIG_WATCHDOG)
298void watchdog_reset (void)
299{
Timur Tabi054838e2006-10-31 18:44:42 -0600300 int re_enable = disable_interrupts();
301
302 /* Reset the 83xx watchdog */
Timur Tabi386a2802006-11-03 12:00:28 -0600303 volatile immap_t *immr = (immap_t *) CFG_IMMR;
Timur Tabi054838e2006-10-31 18:44:42 -0600304 immr->wdt.swsrr = 0x556c;
305 immr->wdt.swsrr = 0xaa39;
306
307 if (re_enable)
308 enable_interrupts ();
Eran Liberty9095d4a2005-07-28 10:08:46 -0500309}
Timur Tabi054838e2006-10-31 18:44:42 -0600310#endif
Kumar Gala5bbb0452006-01-11 16:48:10 -0600311
Gerald Van Barend6abef42007-03-31 12:23:51 -0400312#if defined(CONFIG_OF_LIBFDT)
313
314/*
Gerald Van Baren2f734162007-04-15 13:54:26 -0400315 * "Setter" functions used to add/modify FDT entries.
316 */
317static int fdt_set_eth0(void *fdt, int nodeoffset, const char *name, bd_t *bd)
318{
319 /*
320 * Fix it up if it exists, don't create it if it doesn't exist.
321 */
322 if (fdt_get_property(fdt, nodeoffset, name, 0)) {
323 return fdt_setprop(fdt, nodeoffset, name, bd->bi_enetaddr, 6);
324 }
325 return -FDT_ERR_NOTFOUND;
326}
327#ifdef CONFIG_HAS_ETH1
328/* second onboard ethernet port */
329static int fdt_set_eth1(void *fdt, int nodeoffset, const char *name, bd_t *bd)
330{
331 /*
332 * Fix it up if it exists, don't create it if it doesn't exist.
333 */
334 if (fdt_get_property(fdt, nodeoffset, name, 0)) {
335 return fdt_setprop(fdt, nodeoffset, name, bd->bi_enet1addr, 6);
336 }
337 return -FDT_ERR_NOTFOUND;
338}
339#endif
340#ifdef CONFIG_HAS_ETH2
341/* third onboard ethernet port */
342static int fdt_set_eth2(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_enet2addr, 6);
349 }
350 return -FDT_ERR_NOTFOUND;
351}
352#endif
353#ifdef CONFIG_HAS_ETH3
354/* fourth onboard ethernet port */
355static int fdt_set_eth3(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_enet3addr, 6);
362 }
363 return -FDT_ERR_NOTFOUND;
364}
365#endif
366
367static int fdt_set_busfreq(void *fdt, int nodeoffset, const char *name, bd_t *bd)
368{
369 u32 tmp;
370 /*
371 * Create or update the property.
372 */
373 tmp = cpu_to_be32(bd->bi_busfreq);
374 return fdt_setprop(fdt, nodeoffset, name, &tmp, sizeof(tmp));
375}
376
377/*
Gerald Van Barend6abef42007-03-31 12:23:51 -0400378 * Fixups to the fdt. If "create" is TRUE, the node is created
379 * unconditionally. If "create" is FALSE, the node is updated
380 * only if it already exists.
381 */
Gerald Van Barend6abef42007-03-31 12:23:51 -0400382static const struct {
Gerald Van Barend6abef42007-03-31 12:23:51 -0400383 char *node;
384 char *prop;
Gerald Van Baren2f734162007-04-15 13:54:26 -0400385 int (*set_fn)(void *fdt, int nodeoffset, const char *name, bd_t *bd);
Gerald Van Barend6abef42007-03-31 12:23:51 -0400386} fixup_props[] = {
Gerald Van Baren2f734162007-04-15 13:54:26 -0400387 { "/cpus/" OF_CPU,
Gerald Van Barend6abef42007-03-31 12:23:51 -0400388 "bus-frequency",
Gerald Van Baren2f734162007-04-15 13:54:26 -0400389 fdt_set_busfreq
Gerald Van Barend6abef42007-03-31 12:23:51 -0400390 },
Gerald Van Baren2f734162007-04-15 13:54:26 -0400391 { "/cpus/" OF_SOC,
392 "bus-frequency",
393 fdt_set_busfreq
Gerald Van Barend6abef42007-03-31 12:23:51 -0400394 },
Gerald Van Baren2f734162007-04-15 13:54:26 -0400395 { "/" OF_SOC "/serial@4500/",
396 "clock-frequency",
397 fdt_set_busfreq
Gerald Van Barend6abef42007-03-31 12:23:51 -0400398 },
Gerald Van Baren2f734162007-04-15 13:54:26 -0400399 { "/" OF_SOC "/serial@4600/",
400 "clock-frequency",
401 fdt_set_busfreq
Gerald Van Barend6abef42007-03-31 12:23:51 -0400402 },
403#ifdef CONFIG_MPC83XX_TSEC1
Gerald Van Baren2f734162007-04-15 13:54:26 -0400404 { "/" OF_SOC "/ethernet@24000,
Gerald Van Barend6abef42007-03-31 12:23:51 -0400405 "mac-address",
Gerald Van Baren2f734162007-04-15 13:54:26 -0400406 fdt_set_eth0
Gerald Van Barend6abef42007-03-31 12:23:51 -0400407 },
Gerald Van Baren2f734162007-04-15 13:54:26 -0400408 { "/" OF_SOC "/ethernet@24000,
Gerald Van Barend6abef42007-03-31 12:23:51 -0400409 "local-mac-address",
Gerald Van Baren2f734162007-04-15 13:54:26 -0400410 fdt_set_eth0
Gerald Van Barend6abef42007-03-31 12:23:51 -0400411 },
412#endif
413#ifdef CONFIG_MPC83XX_TSEC2
Gerald Van Baren2f734162007-04-15 13:54:26 -0400414 { "/" OF_SOC "/ethernet@25000,
415 "mac-address",
416 fdt_set_eth1
417 },
418 { "/" OF_SOC "/ethernet@25000,
419 "local-mac-address",
420 fdt_set_eth1
421 },
422#endif
423#ifdef CONFIG_UEC_ETH1
424#if CFG_UEC1_UCC_NUM == 0 /* UCC1 */
425 { "/" OF_QE "/ucc@2000/mac-address",
Gerald Van Barend6abef42007-03-31 12:23:51 -0400426 "mac-address",
Gerald Van Baren2f734162007-04-15 13:54:26 -0400427 fdt_set_eth0
Gerald Van Barend6abef42007-03-31 12:23:51 -0400428 },
Gerald Van Baren2f734162007-04-15 13:54:26 -0400429 { "/" OF_QE "/ucc@2000/mac-address",
Gerald Van Barend6abef42007-03-31 12:23:51 -0400430 "local-mac-address",
Gerald Van Baren2f734162007-04-15 13:54:26 -0400431 fdt_set_eth0
432 },
433#elif CFG_UEC1_UCC_NUM == 2 /* UCC3 */
434 { "/" OF_QE "/ucc@2200/mac-address",
435 "mac-address",
436 fdt_set_eth0
437 },
438 { "/" OF_QE "/ucc@2200/mac-address",
439 "local-mac-address",
440 fdt_set_eth0
441 },
442#endif
443#endif
444#ifdef CONFIG_UEC_ETH2
445#if CFG_UEC2_UCC_NUM == 1 /* UCC2 */
446 { "/" OF_QE "/ucc@3000/mac-address",
447 "mac-address",
448 fdt_set_eth1
449 },
450 { "/" OF_QE "/ucc@3000/mac-address",
451 "local-mac-address",
452 fdt_set_eth1
453 },
454#elif CFG_UEC1_UCC_NUM == 3 /* UCC4 */
455 { "/" OF_QE "/ucc@3200/mac-address",
456 "mac-address",
457 fdt_set_eth1
458 },
459 { "/" OF_QE "/ucc@3200/mac-address",
460 "local-mac-address",
461 fdt_set_eth1
Gerald Van Barend6abef42007-03-31 12:23:51 -0400462 },
463#endif
Gerald Van Baren2f734162007-04-15 13:54:26 -0400464#endif
Gerald Van Barend6abef42007-03-31 12:23:51 -0400465};
466
467void
468ft_cpu_setup(void *blob, bd_t *bd)
469{
Gerald Van Baren2f734162007-04-15 13:54:26 -0400470 int nodeoffset;
471 int err;
472 int j;
Gerald Van Barend6abef42007-03-31 12:23:51 -0400473
474 for (j = 0; j < (sizeof(fixup_props) / sizeof(fixup_props[0])); j++) {
Gerald Van Baren2f734162007-04-15 13:54:26 -0400475 nodeoffset = fdt_path_offset(fdt, fixup_props[j].node);
Gerald Van Barend6abef42007-03-31 12:23:51 -0400476 if (nodeoffset >= 0) {
Gerald Van Baren2f734162007-04-15 13:54:26 -0400477 err = (*fixup_props[j].set_fn)(blob, nodeoffset, fixup_props[j].prop, bd);
478 if (err < 0)
479 printf("set_fn/libfdt: %s %s returned %s\n",
480 fixup_props[j].node,
481 fixup_props[j].prop,
482 fdt_strerror(err));
Gerald Van Barend6abef42007-03-31 12:23:51 -0400483 }
484 }
485}
486#endif
487
Kumar Gala5bbb0452006-01-11 16:48:10 -0600488#if defined(CONFIG_OF_FLAT_TREE)
489void
490ft_cpu_setup(void *blob, bd_t *bd)
491{
492 u32 *p;
493 int len;
494 ulong clock;
495
496 clock = bd->bi_busfreq;
497 p = ft_get_prop(blob, "/cpus/" OF_CPU "/bus-frequency", &len);
498 if (p != NULL)
499 *p = cpu_to_be32(clock);
500
501 p = ft_get_prop(blob, "/" OF_SOC "/bus-frequency", &len);
502 if (p != NULL)
503 *p = cpu_to_be32(clock);
504
505 p = ft_get_prop(blob, "/" OF_SOC "/serial@4500/clock-frequency", &len);
506 if (p != NULL)
507 *p = cpu_to_be32(clock);
508
509 p = ft_get_prop(blob, "/" OF_SOC "/serial@4600/clock-frequency", &len);
510 if (p != NULL)
511 *p = cpu_to_be32(clock);
512
513#ifdef CONFIG_MPC83XX_TSEC1
Timur Tabief648382007-02-13 10:41:42 -0600514 p = ft_get_prop(blob, "/" OF_SOC "/ethernet@24000/mac-address", &len);
515 if (p != NULL)
516 memcpy(p, bd->bi_enetaddr, 6);
517
Kim Phillipsd99bd8b2006-11-01 00:07:25 -0600518 p = ft_get_prop(blob, "/" OF_SOC "/ethernet@24000/local-mac-address", &len);
Kim Phillips24f63e92007-01-30 16:15:21 -0600519 if (p != NULL)
Kumar Gala5bbb0452006-01-11 16:48:10 -0600520 memcpy(p, bd->bi_enetaddr, 6);
521#endif
522
523#ifdef CONFIG_MPC83XX_TSEC2
Timur Tabief648382007-02-13 10:41:42 -0600524 p = ft_get_prop(blob, "/" OF_SOC "/ethernet@25000/mac-address", &len);
525 if (p != NULL)
526 memcpy(p, bd->bi_enet1addr, 6);
527
Kim Phillipsd99bd8b2006-11-01 00:07:25 -0600528 p = ft_get_prop(blob, "/" OF_SOC "/ethernet@25000/local-mac-address", &len);
Kim Phillips24f63e92007-01-30 16:15:21 -0600529 if (p != NULL)
Kumar Gala5bbb0452006-01-11 16:48:10 -0600530 memcpy(p, bd->bi_enet1addr, 6);
531#endif
Kim Phillips526addb2007-02-22 20:06:57 -0600532
533#ifdef CONFIG_UEC_ETH1
534#if CFG_UEC1_UCC_NUM == 0 /* UCC1 */
535 p = ft_get_prop(blob, "/" OF_QE "/ucc@2000/mac-address", &len);
536 if (p != NULL)
537 memcpy(p, bd->bi_enetaddr, 6);
538
539 p = ft_get_prop(blob, "/" OF_QE "/ucc@2000/local-mac-address", &len);
540 if (p != NULL)
541 memcpy(p, bd->bi_enetaddr, 6);
542#elif CFG_UEC1_UCC_NUM == 2 /* UCC3 */
543 p = ft_get_prop(blob, "/" OF_QE "/ucc@2200/mac-address", &len);
544 if (p != NULL)
545 memcpy(p, bd->bi_enetaddr, 6);
546
547 p = ft_get_prop(blob, "/" OF_QE "/ucc@2200/local-mac-address", &len);
548 if (p != NULL)
549 memcpy(p, bd->bi_enetaddr, 6);
550#endif
551#endif
552
553#ifdef CONFIG_UEC_ETH2
554#if CFG_UEC2_UCC_NUM == 1 /* UCC2 */
555 p = ft_get_prop(blob, "/" OF_QE "/ucc@3000/mac-address", &len);
556 if (p != NULL)
557 memcpy(p, bd->bi_enet1addr, 6);
558
559 p = ft_get_prop(blob, "/" OF_QE "/ucc@3000/local-mac-address", &len);
560 if (p != NULL)
561 memcpy(p, bd->bi_enet1addr, 6);
562#elif CFG_UEC2_UCC_NUM == 3 /* UCC4 */
563 p = ft_get_prop(blob, "/" OF_QE "/ucc@3200/mac-address", &len);
564 if (p != NULL)
565 memcpy(p, bd->bi_enet1addr, 6);
566
567 p = ft_get_prop(blob, "/" OF_QE "/ucc@3200/local-mac-address", &len);
568 if (p != NULL)
569 memcpy(p, bd->bi_enet1addr, 6);
570#endif
571#endif
Kumar Gala5bbb0452006-01-11 16:48:10 -0600572}
573#endif
Marian Balakowicz7ec9ebc2006-03-14 16:14:48 +0100574
575#if defined(CONFIG_DDR_ECC)
576void dma_init(void)
577{
Timur Tabi386a2802006-11-03 12:00:28 -0600578 volatile immap_t *immap = (immap_t *)CFG_IMMR;
Dave Liuf5035922006-10-25 14:41:21 -0500579 volatile dma83xx_t *dma = &immap->dma;
Marian Balakowicz7ec9ebc2006-03-14 16:14:48 +0100580 volatile u32 status = swab32(dma->dmasr0);
581 volatile u32 dmamr0 = swab32(dma->dmamr0);
582
583 debug("DMA-init\n");
584
585 /* initialize DMASARn, DMADAR and DMAABCRn */
586 dma->dmadar0 = (u32)0;
587 dma->dmasar0 = (u32)0;
588 dma->dmabcr0 = 0;
589
590 __asm__ __volatile__ ("sync");
591 __asm__ __volatile__ ("isync");
592
593 /* clear CS bit */
594 dmamr0 &= ~DMA_CHANNEL_START;
595 dma->dmamr0 = swab32(dmamr0);
596 __asm__ __volatile__ ("sync");
597 __asm__ __volatile__ ("isync");
598
599 /* while the channel is busy, spin */
600 while(status & DMA_CHANNEL_BUSY) {
601 status = swab32(dma->dmasr0);
602 }
603
604 debug("DMA-init end\n");
605}
606
607uint dma_check(void)
608{
Timur Tabi386a2802006-11-03 12:00:28 -0600609 volatile immap_t *immap = (immap_t *)CFG_IMMR;
Dave Liuf5035922006-10-25 14:41:21 -0500610 volatile dma83xx_t *dma = &immap->dma;
Marian Balakowicz7ec9ebc2006-03-14 16:14:48 +0100611 volatile u32 status = swab32(dma->dmasr0);
612 volatile u32 byte_count = swab32(dma->dmabcr0);
613
614 /* while the channel is busy, spin */
615 while (status & DMA_CHANNEL_BUSY) {
616 status = swab32(dma->dmasr0);
617 }
618
619 if (status & DMA_CHANNEL_TRANSFER_ERROR) {
620 printf ("DMA Error: status = %x @ %d\n", status, byte_count);
621 }
622
623 return status;
624}
625
626int dma_xfer(void *dest, u32 count, void *src)
627{
Timur Tabi386a2802006-11-03 12:00:28 -0600628 volatile immap_t *immap = (immap_t *)CFG_IMMR;
Dave Liuf5035922006-10-25 14:41:21 -0500629 volatile dma83xx_t *dma = &immap->dma;
Marian Balakowicz7ec9ebc2006-03-14 16:14:48 +0100630 volatile u32 dmamr0;
631
632 /* initialize DMASARn, DMADAR and DMAABCRn */
633 dma->dmadar0 = swab32((u32)dest);
634 dma->dmasar0 = swab32((u32)src);
635 dma->dmabcr0 = swab32(count);
636
637 __asm__ __volatile__ ("sync");
638 __asm__ __volatile__ ("isync");
639
640 /* init direct transfer, clear CS bit */
641 dmamr0 = (DMA_CHANNEL_TRANSFER_MODE_DIRECT |
642 DMA_CHANNEL_SOURCE_ADDRESS_HOLD_8B |
643 DMA_CHANNEL_SOURCE_ADRESSS_HOLD_EN);
Wolfgang Denkebd3deb2006-04-16 10:51:58 +0200644
Marian Balakowicz7ec9ebc2006-03-14 16:14:48 +0100645 dma->dmamr0 = swab32(dmamr0);
646
647 __asm__ __volatile__ ("sync");
648 __asm__ __volatile__ ("isync");
649
650 /* set CS to start DMA transfer */
651 dmamr0 |= DMA_CHANNEL_START;
652 dma->dmamr0 = swab32(dmamr0);
653 __asm__ __volatile__ ("sync");
654 __asm__ __volatile__ ("isync");
655
656 return ((int)dma_check());
657}
658#endif /*CONFIG_DDR_ECC*/