blob: bfac227d68e3322f1da08a116aba612ecae6bb11 [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
Kim Phillipsd82b0772007-04-30 15:26:21 -050055 puts("CPU: ");
Scott Wood7206a992007-04-16 14:34:16 -050056
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 Liberty9095d4a2005-07-28 10:08:46 -050072 }
73
Dave Liua46daea2006-11-03 19:33:44 -060074 spridr = immr->sysconf.spridr;
Dave Liua46daea2006-11-03 19:33:44 -060075 switch(spridr) {
76 case SPR_8349E_REV10:
77 case SPR_8349E_REV11:
Xie Xiaobo800b7532007-02-14 18:26:44 +080078 case SPR_8349E_REV31:
Dave Liua46daea2006-11-03 19:33:44 -060079 puts("MPC8349E, ");
80 break;
81 case SPR_8349_REV10:
82 case SPR_8349_REV11:
Xie Xiaobo800b7532007-02-14 18:26:44 +080083 case SPR_8349_REV31:
Dave Liua46daea2006-11-03 19:33:44 -060084 puts("MPC8349, ");
85 break;
86 case SPR_8347E_REV10_TBGA:
87 case SPR_8347E_REV11_TBGA:
Xie Xiaobo800b7532007-02-14 18:26:44 +080088 case SPR_8347E_REV31_TBGA:
Dave Liua46daea2006-11-03 19:33:44 -060089 case SPR_8347E_REV10_PBGA:
90 case SPR_8347E_REV11_PBGA:
Xie Xiaobo800b7532007-02-14 18:26:44 +080091 case SPR_8347E_REV31_PBGA:
Dave Liua46daea2006-11-03 19:33:44 -060092 puts("MPC8347E, ");
93 break;
94 case SPR_8347_REV10_TBGA:
95 case SPR_8347_REV11_TBGA:
Xie Xiaobo800b7532007-02-14 18:26:44 +080096 case SPR_8347_REV31_TBGA:
Dave Liua46daea2006-11-03 19:33:44 -060097 case SPR_8347_REV10_PBGA:
98 case SPR_8347_REV11_PBGA:
Xie Xiaobo800b7532007-02-14 18:26:44 +080099 case SPR_8347_REV31_PBGA:
Dave Liua46daea2006-11-03 19:33:44 -0600100 puts("MPC8347, ");
Eran Liberty9095d4a2005-07-28 10:08:46 -0500101 break;
Dave Liua46daea2006-11-03 19:33:44 -0600102 case SPR_8343E_REV10:
103 case SPR_8343E_REV11:
Xie Xiaobo800b7532007-02-14 18:26:44 +0800104 case SPR_8343E_REV31:
Dave Liua46daea2006-11-03 19:33:44 -0600105 puts("MPC8343E, ");
106 break;
107 case SPR_8343_REV10:
108 case SPR_8343_REV11:
Xie Xiaobo800b7532007-02-14 18:26:44 +0800109 case SPR_8343_REV31:
Dave Liua46daea2006-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 Xiaoboa9be42a2007-02-14 18:27:06 +0800115 case SPR_8360E_REV20:
Lee Nipperf600cf32007-06-14 20:07:33 -0500116 case SPR_8360E_REV21:
Dave Liua46daea2006-11-03 19:33:44 -0600117 puts("MPC8360E, ");
118 break;
119 case SPR_8360_REV10:
120 case SPR_8360_REV11:
121 case SPR_8360_REV12:
Xie Xiaoboa9be42a2007-02-14 18:27:06 +0800122 case SPR_8360_REV20:
Lee Nipperf600cf32007-06-14 20:07:33 -0500123 case SPR_8360_REV21:
Dave Liua46daea2006-11-03 19:33:44 -0600124 puts("MPC8360, ");
Eran Liberty9095d4a2005-07-28 10:08:46 -0500125 break;
Dave Liue740c462006-12-07 21:13:15 +0800126 case SPR_8323E_REV10:
127 case SPR_8323E_REV11:
128 puts("MPC8323E, ");
129 break;
130 case SPR_8323_REV10:
131 case SPR_8323_REV11:
132 puts("MPC8323, ");
133 break;
134 case SPR_8321E_REV10:
135 case SPR_8321E_REV11:
136 puts("MPC8321E, ");
137 break;
138 case SPR_8321_REV10:
139 case SPR_8321_REV11:
140 puts("MPC8321, ");
141 break;
Scott Woodf13983e2007-04-16 14:34:15 -0500142 case SPR_8311_REV10:
143 puts("MPC8311, ");
144 break;
145 case SPR_8311E_REV10:
146 puts("MPC8311E, ");
147 break;
148 case SPR_8313_REV10:
149 puts("MPC8313, ");
150 break;
151 case SPR_8313E_REV10:
152 puts("MPC8313E, ");
153 break;
Eran Liberty9095d4a2005-07-28 10:08:46 -0500154 default:
Lee Nipperf600cf32007-06-14 20:07:33 -0500155 printf("Rev: Unknown revision number:%08x\n"
156 "Warning: Unsupported cpu revision!\n",spridr);
Xie Xiaobo800b7532007-02-14 18:26:44 +0800157 return 0;
Eran Liberty9095d4a2005-07-28 10:08:46 -0500158 }
Rafal Jaworowski384da5e2005-10-17 02:39:53 +0200159
Kumar Galab7870e72007-01-30 14:08:30 -0600160#if defined(CONFIG_MPC834X)
Xie Xiaobo800b7532007-02-14 18:26:44 +0800161 /* Multiple revisons of 834x processors may have the same SPRIDR value.
162 * So use PVR to identify the revision number.
163 */
Kim Phillipsd82b0772007-04-30 15:26:21 -0500164 printf("Rev: %02x at %s MHz", PVR_MAJ(pvr)<<4 | PVR_MIN(pvr), strmhz(buf, clock));
Dave Liua46daea2006-11-03 19:33:44 -0600165#else
Kim Phillipsd82b0772007-04-30 15:26:21 -0500166 printf("Rev: %02x at %s MHz", spridr & 0x0000FFFF, strmhz(buf, clock));
Dave Liua46daea2006-11-03 19:33:44 -0600167#endif
Kim Phillipsd82b0772007-04-30 15:26:21 -0500168 printf(", CSB: %4d MHz\n", gd->csb_clk / 1000000);
169
Eran Liberty9095d4a2005-07-28 10:08:46 -0500170 return 0;
171}
172
173
Timur Tabiab347542006-11-03 19:15:00 -0600174/*
Timur Tabi054838e2006-10-31 18:44:42 -0600175 * Program a UPM with the code supplied in the table.
176 *
177 * The 'dummy' variable is used to increment the MAD. 'dummy' is
178 * supposed to be a pointer to the memory of the device being
179 * programmed by the UPM. The data in the MDR is written into
180 * memory and the MAD is incremented every time there's a read
181 * from 'dummy'. Unfortunately, the current prototype for this
182 * function doesn't allow for passing the address of this
183 * device, and changing the prototype will break a number lots
184 * of other code, so we need to use a round-about way of finding
185 * the value for 'dummy'.
186 *
187 * The value can be extracted from the base address bits of the
188 * Base Register (BR) associated with the specific UPM. To find
189 * that BR, we need to scan all 8 BRs until we find the one that
190 * has its MSEL bits matching the UPM we want. Once we know the
191 * right BR, we can extract the base address bits from it.
192 *
193 * The MxMR and the BR and OR of the chosen bank should all be
194 * configured before calling this function.
195 *
196 * Parameters:
197 * upm: 0=UPMA, 1=UPMB, 2=UPMC
198 * table: Pointer to an array of values to program
199 * size: Number of elements in the array. Must be 64 or less.
Timur Tabiab347542006-11-03 19:15:00 -0600200 */
Eran Liberty9095d4a2005-07-28 10:08:46 -0500201void upmconfig (uint upm, uint *table, uint size)
202{
Timur Tabi054838e2006-10-31 18:44:42 -0600203#if defined(CONFIG_MPC834X)
Timur Tabi386a2802006-11-03 12:00:28 -0600204 volatile immap_t *immap = (immap_t *) CFG_IMMR;
Timur Tabi054838e2006-10-31 18:44:42 -0600205 volatile lbus83xx_t *lbus = &immap->lbus;
206 volatile uchar *dummy = NULL;
207 const u32 msel = (upm + 4) << BR_MSEL_SHIFT; /* What the MSEL field in BRn should be */
208 volatile u32 *mxmr = &lbus->mamr + upm; /* Pointer to mamr, mbmr, or mcmr */
209 uint i;
210
211 /* Scan all the banks to determine the base address of the device */
212 for (i = 0; i < 8; i++) {
213 if ((lbus->bank[i].br & BR_MSEL) == msel) {
214 dummy = (uchar *) (lbus->bank[i].br & BR_BA);
215 break;
216 }
217 }
218
219 if (!dummy) {
220 printf("Error: %s() could not find matching BR\n", __FUNCTION__);
221 hang();
222 }
223
224 /* Set the OP field in the MxMR to "write" and the MAD field to 000000 */
225 *mxmr = (*mxmr & 0xCFFFFFC0) | 0x10000000;
226
227 for (i = 0; i < size; i++) {
228 lbus->mdr = table[i];
229 __asm__ __volatile__ ("sync");
230 *dummy; /* Write the value to memory and increment MAD */
231 __asm__ __volatile__ ("sync");
232 }
233
234 /* Set the OP field in the MxMR to "normal" and the MAD field to 000000 */
235 *mxmr &= 0xCFFFFFC0;
236#else
237 printf("Error: %s() not defined for this configuration.\n", __FUNCTION__);
238 hang();
239#endif
Eran Liberty9095d4a2005-07-28 10:08:46 -0500240}
241
242
243int
244do_reset (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
245{
Wolfgang Denk301d0962005-08-05 19:49:35 +0200246 ulong msr;
247#ifndef MPC83xx_RESET
248 ulong addr;
249#endif
Eran Liberty9095d4a2005-07-28 10:08:46 -0500250
Timur Tabi386a2802006-11-03 12:00:28 -0600251 volatile immap_t *immap = (immap_t *) CFG_IMMR;
Eran Liberty9095d4a2005-07-28 10:08:46 -0500252
253#ifdef MPC83xx_RESET
254 /* Interrupts and MMU off */
255 __asm__ __volatile__ ("mfmsr %0":"=r" (msr):);
256
257 msr &= ~( MSR_EE | MSR_IR | MSR_DR);
258 __asm__ __volatile__ ("mtmsr %0"::"r" (msr));
259
260 /* enable Reset Control Reg */
261 immap->reset.rpr = 0x52535445;
Marian Balakowicz919b1872006-03-14 16:12:48 +0100262 __asm__ __volatile__ ("sync");
263 __asm__ __volatile__ ("isync");
Eran Liberty9095d4a2005-07-28 10:08:46 -0500264
265 /* confirm Reset Control Reg is enabled */
266 while(!((immap->reset.rcer) & RCER_CRE));
267
268 printf("Resetting the board.");
269 printf("\n");
270
271 udelay(200);
272
273 /* perform reset, only one bit */
Wolfgang Denk301d0962005-08-05 19:49:35 +0200274 immap->reset.rcr = RCR_SWHR;
275
276#else /* ! MPC83xx_RESET */
Eran Liberty9095d4a2005-07-28 10:08:46 -0500277
Wolfgang Denk301d0962005-08-05 19:49:35 +0200278 immap->reset.rmr = RMR_CSRE; /* Checkstop Reset enable */
279
280 /* Interrupts and MMU off */
281 __asm__ __volatile__ ("mfmsr %0":"=r" (msr):);
Eran Liberty9095d4a2005-07-28 10:08:46 -0500282
283 msr &= ~(MSR_ME | MSR_EE | MSR_IR | MSR_DR);
284 __asm__ __volatile__ ("mtmsr %0"::"r" (msr));
285
286 /*
287 * Trying to execute the next instruction at a non-existing address
288 * should cause a machine check, resulting in reset
289 */
290 addr = CFG_RESET_ADDRESS;
291
292 printf("resetting the board.");
293 printf("\n");
294 ((void (*)(void)) addr) ();
Wolfgang Denk301d0962005-08-05 19:49:35 +0200295#endif /* MPC83xx_RESET */
296
Eran Liberty9095d4a2005-07-28 10:08:46 -0500297 return 1;
298}
299
300
301/*
302 * Get timebase clock frequency (like cpu_clk in Hz)
303 */
304
305unsigned long get_tbclk(void)
306{
Eran Liberty9095d4a2005-07-28 10:08:46 -0500307 ulong tbclk;
308
309 tbclk = (gd->bus_clk + 3L) / 4L;
310
311 return tbclk;
312}
313
314
315#if defined(CONFIG_WATCHDOG)
316void watchdog_reset (void)
317{
Timur Tabi054838e2006-10-31 18:44:42 -0600318 int re_enable = disable_interrupts();
319
320 /* Reset the 83xx watchdog */
Timur Tabi386a2802006-11-03 12:00:28 -0600321 volatile immap_t *immr = (immap_t *) CFG_IMMR;
Timur Tabi054838e2006-10-31 18:44:42 -0600322 immr->wdt.swsrr = 0x556c;
323 immr->wdt.swsrr = 0xaa39;
324
325 if (re_enable)
326 enable_interrupts ();
Eran Liberty9095d4a2005-07-28 10:08:46 -0500327}
Timur Tabi054838e2006-10-31 18:44:42 -0600328#endif
Kumar Gala5bbb0452006-01-11 16:48:10 -0600329
Gerald Van Barend6abef42007-03-31 12:23:51 -0400330#if defined(CONFIG_OF_LIBFDT)
331
332/*
Gerald Van Baren2f734162007-04-15 13:54:26 -0400333 * "Setter" functions used to add/modify FDT entries.
334 */
335static int fdt_set_eth0(void *fdt, int nodeoffset, const char *name, bd_t *bd)
336{
337 /*
338 * Fix it up if it exists, don't create it if it doesn't exist.
339 */
340 if (fdt_get_property(fdt, nodeoffset, name, 0)) {
341 return fdt_setprop(fdt, nodeoffset, name, bd->bi_enetaddr, 6);
342 }
343 return -FDT_ERR_NOTFOUND;
344}
345#ifdef CONFIG_HAS_ETH1
346/* second onboard ethernet port */
347static int fdt_set_eth1(void *fdt, int nodeoffset, const char *name, bd_t *bd)
348{
349 /*
350 * Fix it up if it exists, don't create it if it doesn't exist.
351 */
352 if (fdt_get_property(fdt, nodeoffset, name, 0)) {
353 return fdt_setprop(fdt, nodeoffset, name, bd->bi_enet1addr, 6);
354 }
355 return -FDT_ERR_NOTFOUND;
356}
357#endif
358#ifdef CONFIG_HAS_ETH2
359/* third onboard ethernet port */
360static int fdt_set_eth2(void *fdt, int nodeoffset, const char *name, bd_t *bd)
361{
362 /*
363 * Fix it up if it exists, don't create it if it doesn't exist.
364 */
365 if (fdt_get_property(fdt, nodeoffset, name, 0)) {
366 return fdt_setprop(fdt, nodeoffset, name, bd->bi_enet2addr, 6);
367 }
368 return -FDT_ERR_NOTFOUND;
369}
370#endif
371#ifdef CONFIG_HAS_ETH3
372/* fourth onboard ethernet port */
373static int fdt_set_eth3(void *fdt, int nodeoffset, const char *name, bd_t *bd)
374{
375 /*
376 * Fix it up if it exists, don't create it if it doesn't exist.
377 */
378 if (fdt_get_property(fdt, nodeoffset, name, 0)) {
379 return fdt_setprop(fdt, nodeoffset, name, bd->bi_enet3addr, 6);
380 }
381 return -FDT_ERR_NOTFOUND;
382}
383#endif
384
385static int fdt_set_busfreq(void *fdt, int nodeoffset, const char *name, bd_t *bd)
386{
387 u32 tmp;
388 /*
389 * Create or update the property.
390 */
391 tmp = cpu_to_be32(bd->bi_busfreq);
392 return fdt_setprop(fdt, nodeoffset, name, &tmp, sizeof(tmp));
393}
394
395/*
Gerald Van Barend6abef42007-03-31 12:23:51 -0400396 * Fixups to the fdt. If "create" is TRUE, the node is created
397 * unconditionally. If "create" is FALSE, the node is updated
398 * only if it already exists.
399 */
Gerald Van Barend6abef42007-03-31 12:23:51 -0400400static const struct {
Gerald Van Barend6abef42007-03-31 12:23:51 -0400401 char *node;
402 char *prop;
Gerald Van Baren2f734162007-04-15 13:54:26 -0400403 int (*set_fn)(void *fdt, int nodeoffset, const char *name, bd_t *bd);
Gerald Van Barend6abef42007-03-31 12:23:51 -0400404} fixup_props[] = {
Gerald Van Baren2f734162007-04-15 13:54:26 -0400405 { "/cpus/" OF_CPU,
Gerald Van Barend6abef42007-03-31 12:23:51 -0400406 "bus-frequency",
Gerald Van Baren2f734162007-04-15 13:54:26 -0400407 fdt_set_busfreq
Gerald Van Barend6abef42007-03-31 12:23:51 -0400408 },
Gerald Van Baren2f734162007-04-15 13:54:26 -0400409 { "/cpus/" OF_SOC,
410 "bus-frequency",
411 fdt_set_busfreq
Gerald Van Barend6abef42007-03-31 12:23:51 -0400412 },
Gerald Van Baren2f734162007-04-15 13:54:26 -0400413 { "/" OF_SOC "/serial@4500/",
414 "clock-frequency",
415 fdt_set_busfreq
Gerald Van Barend6abef42007-03-31 12:23:51 -0400416 },
Gerald Van Baren2f734162007-04-15 13:54:26 -0400417 { "/" OF_SOC "/serial@4600/",
418 "clock-frequency",
419 fdt_set_busfreq
Gerald Van Barend6abef42007-03-31 12:23:51 -0400420 },
Kim Phillips177e58f2007-05-16 16:52:19 -0500421#ifdef CONFIG_TSEC1
Gerald Van Baren2f734162007-04-15 13:54:26 -0400422 { "/" OF_SOC "/ethernet@24000,
Gerald Van Barend6abef42007-03-31 12:23:51 -0400423 "mac-address",
Gerald Van Baren2f734162007-04-15 13:54:26 -0400424 fdt_set_eth0
Gerald Van Barend6abef42007-03-31 12:23:51 -0400425 },
Gerald Van Baren2f734162007-04-15 13:54:26 -0400426 { "/" OF_SOC "/ethernet@24000,
Gerald Van Barend6abef42007-03-31 12:23:51 -0400427 "local-mac-address",
Gerald Van Baren2f734162007-04-15 13:54:26 -0400428 fdt_set_eth0
Gerald Van Barend6abef42007-03-31 12:23:51 -0400429 },
430#endif
Kim Phillips177e58f2007-05-16 16:52:19 -0500431#ifdef CONFIG_TSEC2
Gerald Van Baren2f734162007-04-15 13:54:26 -0400432 { "/" OF_SOC "/ethernet@25000,
433 "mac-address",
434 fdt_set_eth1
435 },
436 { "/" OF_SOC "/ethernet@25000,
437 "local-mac-address",
438 fdt_set_eth1
439 },
440#endif
441#ifdef CONFIG_UEC_ETH1
442#if CFG_UEC1_UCC_NUM == 0 /* UCC1 */
443 { "/" OF_QE "/ucc@2000/mac-address",
Gerald Van Barend6abef42007-03-31 12:23:51 -0400444 "mac-address",
Gerald Van Baren2f734162007-04-15 13:54:26 -0400445 fdt_set_eth0
Gerald Van Barend6abef42007-03-31 12:23:51 -0400446 },
Gerald Van Baren2f734162007-04-15 13:54:26 -0400447 { "/" OF_QE "/ucc@2000/mac-address",
Gerald Van Barend6abef42007-03-31 12:23:51 -0400448 "local-mac-address",
Gerald Van Baren2f734162007-04-15 13:54:26 -0400449 fdt_set_eth0
450 },
451#elif CFG_UEC1_UCC_NUM == 2 /* UCC3 */
452 { "/" OF_QE "/ucc@2200/mac-address",
453 "mac-address",
454 fdt_set_eth0
455 },
456 { "/" OF_QE "/ucc@2200/mac-address",
457 "local-mac-address",
458 fdt_set_eth0
459 },
460#endif
461#endif
462#ifdef CONFIG_UEC_ETH2
463#if CFG_UEC2_UCC_NUM == 1 /* UCC2 */
464 { "/" OF_QE "/ucc@3000/mac-address",
465 "mac-address",
466 fdt_set_eth1
467 },
468 { "/" OF_QE "/ucc@3000/mac-address",
469 "local-mac-address",
470 fdt_set_eth1
471 },
472#elif CFG_UEC1_UCC_NUM == 3 /* UCC4 */
473 { "/" OF_QE "/ucc@3200/mac-address",
474 "mac-address",
475 fdt_set_eth1
476 },
477 { "/" OF_QE "/ucc@3200/mac-address",
478 "local-mac-address",
479 fdt_set_eth1
Gerald Van Barend6abef42007-03-31 12:23:51 -0400480 },
481#endif
Gerald Van Baren2f734162007-04-15 13:54:26 -0400482#endif
Gerald Van Barend6abef42007-03-31 12:23:51 -0400483};
484
485void
486ft_cpu_setup(void *blob, bd_t *bd)
487{
Gerald Van Baren2f734162007-04-15 13:54:26 -0400488 int nodeoffset;
489 int err;
490 int j;
Gerald Van Barend6abef42007-03-31 12:23:51 -0400491
492 for (j = 0; j < (sizeof(fixup_props) / sizeof(fixup_props[0])); j++) {
Gerald Van Baren2f734162007-04-15 13:54:26 -0400493 nodeoffset = fdt_path_offset(fdt, fixup_props[j].node);
Gerald Van Barend6abef42007-03-31 12:23:51 -0400494 if (nodeoffset >= 0) {
Gerald Van Baren2f734162007-04-15 13:54:26 -0400495 err = (*fixup_props[j].set_fn)(blob, nodeoffset, fixup_props[j].prop, bd);
496 if (err < 0)
497 printf("set_fn/libfdt: %s %s returned %s\n",
498 fixup_props[j].node,
499 fixup_props[j].prop,
500 fdt_strerror(err));
Gerald Van Barend6abef42007-03-31 12:23:51 -0400501 }
502 }
503}
504#endif
505
Kumar Gala5bbb0452006-01-11 16:48:10 -0600506#if defined(CONFIG_OF_FLAT_TREE)
507void
508ft_cpu_setup(void *blob, bd_t *bd)
509{
510 u32 *p;
511 int len;
512 ulong clock;
513
514 clock = bd->bi_busfreq;
515 p = ft_get_prop(blob, "/cpus/" OF_CPU "/bus-frequency", &len);
516 if (p != NULL)
517 *p = cpu_to_be32(clock);
518
519 p = ft_get_prop(blob, "/" OF_SOC "/bus-frequency", &len);
520 if (p != NULL)
521 *p = cpu_to_be32(clock);
522
523 p = ft_get_prop(blob, "/" OF_SOC "/serial@4500/clock-frequency", &len);
524 if (p != NULL)
525 *p = cpu_to_be32(clock);
526
527 p = ft_get_prop(blob, "/" OF_SOC "/serial@4600/clock-frequency", &len);
528 if (p != NULL)
529 *p = cpu_to_be32(clock);
530
Kim Phillips177e58f2007-05-16 16:52:19 -0500531#ifdef CONFIG_TSEC1
Timur Tabief648382007-02-13 10:41:42 -0600532 p = ft_get_prop(blob, "/" OF_SOC "/ethernet@24000/mac-address", &len);
533 if (p != NULL)
534 memcpy(p, bd->bi_enetaddr, 6);
535
Kim Phillipsd99bd8b2006-11-01 00:07:25 -0600536 p = ft_get_prop(blob, "/" OF_SOC "/ethernet@24000/local-mac-address", &len);
Kim Phillips24f63e92007-01-30 16:15:21 -0600537 if (p != NULL)
Kumar Gala5bbb0452006-01-11 16:48:10 -0600538 memcpy(p, bd->bi_enetaddr, 6);
539#endif
540
Kim Phillips177e58f2007-05-16 16:52:19 -0500541#ifdef CONFIG_TSEC2
Timur Tabief648382007-02-13 10:41:42 -0600542 p = ft_get_prop(blob, "/" OF_SOC "/ethernet@25000/mac-address", &len);
543 if (p != NULL)
544 memcpy(p, bd->bi_enet1addr, 6);
545
Kim Phillipsd99bd8b2006-11-01 00:07:25 -0600546 p = ft_get_prop(blob, "/" OF_SOC "/ethernet@25000/local-mac-address", &len);
Kim Phillips24f63e92007-01-30 16:15:21 -0600547 if (p != NULL)
Kumar Gala5bbb0452006-01-11 16:48:10 -0600548 memcpy(p, bd->bi_enet1addr, 6);
549#endif
Kim Phillips526addb2007-02-22 20:06:57 -0600550
551#ifdef CONFIG_UEC_ETH1
552#if CFG_UEC1_UCC_NUM == 0 /* UCC1 */
553 p = ft_get_prop(blob, "/" OF_QE "/ucc@2000/mac-address", &len);
554 if (p != NULL)
555 memcpy(p, bd->bi_enetaddr, 6);
556
557 p = ft_get_prop(blob, "/" OF_QE "/ucc@2000/local-mac-address", &len);
558 if (p != NULL)
559 memcpy(p, bd->bi_enetaddr, 6);
560#elif CFG_UEC1_UCC_NUM == 2 /* UCC3 */
561 p = ft_get_prop(blob, "/" OF_QE "/ucc@2200/mac-address", &len);
562 if (p != NULL)
563 memcpy(p, bd->bi_enetaddr, 6);
564
565 p = ft_get_prop(blob, "/" OF_QE "/ucc@2200/local-mac-address", &len);
566 if (p != NULL)
567 memcpy(p, bd->bi_enetaddr, 6);
568#endif
569#endif
570
571#ifdef CONFIG_UEC_ETH2
572#if CFG_UEC2_UCC_NUM == 1 /* UCC2 */
573 p = ft_get_prop(blob, "/" OF_QE "/ucc@3000/mac-address", &len);
574 if (p != NULL)
575 memcpy(p, bd->bi_enet1addr, 6);
576
577 p = ft_get_prop(blob, "/" OF_QE "/ucc@3000/local-mac-address", &len);
578 if (p != NULL)
579 memcpy(p, bd->bi_enet1addr, 6);
580#elif CFG_UEC2_UCC_NUM == 3 /* UCC4 */
581 p = ft_get_prop(blob, "/" OF_QE "/ucc@3200/mac-address", &len);
582 if (p != NULL)
583 memcpy(p, bd->bi_enet1addr, 6);
584
585 p = ft_get_prop(blob, "/" OF_QE "/ucc@3200/local-mac-address", &len);
586 if (p != NULL)
587 memcpy(p, bd->bi_enet1addr, 6);
588#endif
589#endif
Kumar Gala5bbb0452006-01-11 16:48:10 -0600590}
591#endif
Marian Balakowicz7ec9ebc2006-03-14 16:14:48 +0100592
593#if defined(CONFIG_DDR_ECC)
594void dma_init(void)
595{
Timur Tabi386a2802006-11-03 12:00:28 -0600596 volatile immap_t *immap = (immap_t *)CFG_IMMR;
Dave Liuf5035922006-10-25 14:41:21 -0500597 volatile dma83xx_t *dma = &immap->dma;
Marian Balakowicz7ec9ebc2006-03-14 16:14:48 +0100598 volatile u32 status = swab32(dma->dmasr0);
599 volatile u32 dmamr0 = swab32(dma->dmamr0);
600
601 debug("DMA-init\n");
602
603 /* initialize DMASARn, DMADAR and DMAABCRn */
604 dma->dmadar0 = (u32)0;
605 dma->dmasar0 = (u32)0;
606 dma->dmabcr0 = 0;
607
608 __asm__ __volatile__ ("sync");
609 __asm__ __volatile__ ("isync");
610
611 /* clear CS bit */
612 dmamr0 &= ~DMA_CHANNEL_START;
613 dma->dmamr0 = swab32(dmamr0);
614 __asm__ __volatile__ ("sync");
615 __asm__ __volatile__ ("isync");
616
617 /* while the channel is busy, spin */
618 while(status & DMA_CHANNEL_BUSY) {
619 status = swab32(dma->dmasr0);
620 }
621
622 debug("DMA-init end\n");
623}
624
625uint dma_check(void)
626{
Timur Tabi386a2802006-11-03 12:00:28 -0600627 volatile immap_t *immap = (immap_t *)CFG_IMMR;
Dave Liuf5035922006-10-25 14:41:21 -0500628 volatile dma83xx_t *dma = &immap->dma;
Marian Balakowicz7ec9ebc2006-03-14 16:14:48 +0100629 volatile u32 status = swab32(dma->dmasr0);
630 volatile u32 byte_count = swab32(dma->dmabcr0);
631
632 /* while the channel is busy, spin */
633 while (status & DMA_CHANNEL_BUSY) {
634 status = swab32(dma->dmasr0);
635 }
636
637 if (status & DMA_CHANNEL_TRANSFER_ERROR) {
638 printf ("DMA Error: status = %x @ %d\n", status, byte_count);
639 }
640
641 return status;
642}
643
644int dma_xfer(void *dest, u32 count, void *src)
645{
Timur Tabi386a2802006-11-03 12:00:28 -0600646 volatile immap_t *immap = (immap_t *)CFG_IMMR;
Dave Liuf5035922006-10-25 14:41:21 -0500647 volatile dma83xx_t *dma = &immap->dma;
Marian Balakowicz7ec9ebc2006-03-14 16:14:48 +0100648 volatile u32 dmamr0;
649
650 /* initialize DMASARn, DMADAR and DMAABCRn */
651 dma->dmadar0 = swab32((u32)dest);
652 dma->dmasar0 = swab32((u32)src);
653 dma->dmabcr0 = swab32(count);
654
655 __asm__ __volatile__ ("sync");
656 __asm__ __volatile__ ("isync");
657
658 /* init direct transfer, clear CS bit */
659 dmamr0 = (DMA_CHANNEL_TRANSFER_MODE_DIRECT |
660 DMA_CHANNEL_SOURCE_ADDRESS_HOLD_8B |
661 DMA_CHANNEL_SOURCE_ADRESSS_HOLD_EN);
Wolfgang Denkebd3deb2006-04-16 10:51:58 +0200662
Marian Balakowicz7ec9ebc2006-03-14 16:14:48 +0100663 dma->dmamr0 = swab32(dmamr0);
664
665 __asm__ __volatile__ ("sync");
666 __asm__ __volatile__ ("isync");
667
668 /* set CS to start DMA transfer */
669 dmamr0 |= DMA_CHANNEL_START;
670 dma->dmamr0 = swab32(dmamr0);
671 __asm__ __volatile__ ("sync");
672 __asm__ __volatile__ ("isync");
673
674 return ((int)dma_check());
675}
676#endif /*CONFIG_DDR_ECC*/