blob: 40e8d0c987b00a0e834d8290ed11f5743efc0c61 [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>
Jerry Van Baren1a96f622007-07-04 21:27:30 -040036#elif defined(CONFIG_OF_LIBFDT)
Gerald Van Barend6abef42007-03-31 12:23:51 -040037#include <libfdt.h>
38#include <libfdt_env.h>
39#endif
Eran Liberty9095d4a2005-07-28 10:08:46 -050040
Wolfgang Denk6405a152006-03-31 18:32:53 +020041DECLARE_GLOBAL_DATA_PTR;
42
Eran Liberty9095d4a2005-07-28 10:08:46 -050043
44int checkcpu(void)
45{
Dave Liua46daea2006-11-03 19:33:44 -060046 volatile immap_t *immr;
Eran Liberty9095d4a2005-07-28 10:08:46 -050047 ulong clock = gd->cpu_clk;
48 u32 pvr = get_pvr();
Dave Liua46daea2006-11-03 19:33:44 -060049 u32 spridr;
Eran Liberty9095d4a2005-07-28 10:08:46 -050050 char buf[32];
51
Timur Tabi386a2802006-11-03 12:00:28 -060052 immr = (immap_t *)CFG_IMMR;
Dave Liua46daea2006-11-03 19:33:44 -060053
Kim Phillipsd82b0772007-04-30 15:26:21 -050054 puts("CPU: ");
Scott Wood7206a992007-04-16 14:34:16 -050055
56 switch (pvr & 0xffff0000) {
57 case PVR_E300C1:
58 printf("e300c1, ");
59 break;
60
61 case PVR_E300C2:
62 printf("e300c2, ");
63 break;
64
65 case PVR_E300C3:
66 printf("e300c3, ");
67 break;
68
69 default:
70 printf("Unknown core, ");
Eran Liberty9095d4a2005-07-28 10:08:46 -050071 }
72
Dave Liua46daea2006-11-03 19:33:44 -060073 spridr = immr->sysconf.spridr;
Dave Liua46daea2006-11-03 19:33:44 -060074 switch(spridr) {
75 case SPR_8349E_REV10:
76 case SPR_8349E_REV11:
Xie Xiaobo800b7532007-02-14 18:26:44 +080077 case SPR_8349E_REV31:
Dave Liua46daea2006-11-03 19:33:44 -060078 puts("MPC8349E, ");
79 break;
80 case SPR_8349_REV10:
81 case SPR_8349_REV11:
Xie Xiaobo800b7532007-02-14 18:26:44 +080082 case SPR_8349_REV31:
Dave Liua46daea2006-11-03 19:33:44 -060083 puts("MPC8349, ");
84 break;
85 case SPR_8347E_REV10_TBGA:
86 case SPR_8347E_REV11_TBGA:
Xie Xiaobo800b7532007-02-14 18:26:44 +080087 case SPR_8347E_REV31_TBGA:
Dave Liua46daea2006-11-03 19:33:44 -060088 case SPR_8347E_REV10_PBGA:
89 case SPR_8347E_REV11_PBGA:
Xie Xiaobo800b7532007-02-14 18:26:44 +080090 case SPR_8347E_REV31_PBGA:
Dave Liua46daea2006-11-03 19:33:44 -060091 puts("MPC8347E, ");
92 break;
93 case SPR_8347_REV10_TBGA:
94 case SPR_8347_REV11_TBGA:
Xie Xiaobo800b7532007-02-14 18:26:44 +080095 case SPR_8347_REV31_TBGA:
Dave Liua46daea2006-11-03 19:33:44 -060096 case SPR_8347_REV10_PBGA:
97 case SPR_8347_REV11_PBGA:
Xie Xiaobo800b7532007-02-14 18:26:44 +080098 case SPR_8347_REV31_PBGA:
Dave Liua46daea2006-11-03 19:33:44 -060099 puts("MPC8347, ");
Eran Liberty9095d4a2005-07-28 10:08:46 -0500100 break;
Dave Liua46daea2006-11-03 19:33:44 -0600101 case SPR_8343E_REV10:
102 case SPR_8343E_REV11:
Xie Xiaobo800b7532007-02-14 18:26:44 +0800103 case SPR_8343E_REV31:
Dave Liua46daea2006-11-03 19:33:44 -0600104 puts("MPC8343E, ");
105 break;
106 case SPR_8343_REV10:
107 case SPR_8343_REV11:
Xie Xiaobo800b7532007-02-14 18:26:44 +0800108 case SPR_8343_REV31:
Dave Liua46daea2006-11-03 19:33:44 -0600109 puts("MPC8343, ");
110 break;
111 case SPR_8360E_REV10:
112 case SPR_8360E_REV11:
113 case SPR_8360E_REV12:
Xie Xiaoboa9be42a2007-02-14 18:27:06 +0800114 case SPR_8360E_REV20:
Lee Nipperf600cf32007-06-14 20:07:33 -0500115 case SPR_8360E_REV21:
Dave Liua46daea2006-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 Xiaoboa9be42a2007-02-14 18:27:06 +0800121 case SPR_8360_REV20:
Lee Nipperf600cf32007-06-14 20:07:33 -0500122 case SPR_8360_REV21:
Dave Liua46daea2006-11-03 19:33:44 -0600123 puts("MPC8360, ");
Eran Liberty9095d4a2005-07-28 10:08:46 -0500124 break;
Dave Liue740c462006-12-07 21:13:15 +0800125 case SPR_8323E_REV10:
126 case SPR_8323E_REV11:
127 puts("MPC8323E, ");
128 break;
129 case SPR_8323_REV10:
130 case SPR_8323_REV11:
131 puts("MPC8323, ");
132 break;
133 case SPR_8321E_REV10:
134 case SPR_8321E_REV11:
135 puts("MPC8321E, ");
136 break;
137 case SPR_8321_REV10:
138 case SPR_8321_REV11:
139 puts("MPC8321, ");
140 break;
Scott Woodf13983e2007-04-16 14:34:15 -0500141 case SPR_8311_REV10:
142 puts("MPC8311, ");
143 break;
144 case SPR_8311E_REV10:
145 puts("MPC8311E, ");
146 break;
147 case SPR_8313_REV10:
148 puts("MPC8313, ");
149 break;
150 case SPR_8313E_REV10:
151 puts("MPC8313E, ");
152 break;
Eran Liberty9095d4a2005-07-28 10:08:46 -0500153 default:
Lee Nipperf600cf32007-06-14 20:07:33 -0500154 printf("Rev: Unknown revision number:%08x\n"
155 "Warning: Unsupported cpu revision!\n",spridr);
Xie Xiaobo800b7532007-02-14 18:26:44 +0800156 return 0;
Eran Liberty9095d4a2005-07-28 10:08:46 -0500157 }
Rafal Jaworowski384da5e2005-10-17 02:39:53 +0200158
Kumar Galab7870e72007-01-30 14:08:30 -0600159#if defined(CONFIG_MPC834X)
Xie Xiaobo800b7532007-02-14 18:26:44 +0800160 /* Multiple revisons of 834x processors may have the same SPRIDR value.
161 * So use PVR to identify the revision number.
162 */
Kim Phillipsd82b0772007-04-30 15:26:21 -0500163 printf("Rev: %02x at %s MHz", PVR_MAJ(pvr)<<4 | PVR_MIN(pvr), strmhz(buf, clock));
Dave Liua46daea2006-11-03 19:33:44 -0600164#else
Kim Phillipsd82b0772007-04-30 15:26:21 -0500165 printf("Rev: %02x at %s MHz", spridr & 0x0000FFFF, strmhz(buf, clock));
Dave Liua46daea2006-11-03 19:33:44 -0600166#endif
Kim Phillipsd82b0772007-04-30 15:26:21 -0500167 printf(", CSB: %4d MHz\n", gd->csb_clk / 1000000);
168
Eran Liberty9095d4a2005-07-28 10:08:46 -0500169 return 0;
170}
171
172
Timur Tabiab347542006-11-03 19:15:00 -0600173/*
Timur Tabi054838e2006-10-31 18:44:42 -0600174 * Program a UPM with the code supplied in the table.
175 *
176 * The 'dummy' variable is used to increment the MAD. 'dummy' is
177 * supposed to be a pointer to the memory of the device being
178 * programmed by the UPM. The data in the MDR is written into
179 * memory and the MAD is incremented every time there's a read
180 * from 'dummy'. Unfortunately, the current prototype for this
181 * function doesn't allow for passing the address of this
182 * device, and changing the prototype will break a number lots
183 * of other code, so we need to use a round-about way of finding
184 * the value for 'dummy'.
185 *
186 * The value can be extracted from the base address bits of the
187 * Base Register (BR) associated with the specific UPM. To find
188 * that BR, we need to scan all 8 BRs until we find the one that
189 * has its MSEL bits matching the UPM we want. Once we know the
190 * right BR, we can extract the base address bits from it.
191 *
192 * The MxMR and the BR and OR of the chosen bank should all be
193 * configured before calling this function.
194 *
195 * Parameters:
196 * upm: 0=UPMA, 1=UPMB, 2=UPMC
197 * table: Pointer to an array of values to program
198 * size: Number of elements in the array. Must be 64 or less.
Timur Tabiab347542006-11-03 19:15:00 -0600199 */
Eran Liberty9095d4a2005-07-28 10:08:46 -0500200void upmconfig (uint upm, uint *table, uint size)
201{
Timur Tabi054838e2006-10-31 18:44:42 -0600202#if defined(CONFIG_MPC834X)
Timur Tabi386a2802006-11-03 12:00:28 -0600203 volatile immap_t *immap = (immap_t *) CFG_IMMR;
Timur Tabi054838e2006-10-31 18:44:42 -0600204 volatile lbus83xx_t *lbus = &immap->lbus;
205 volatile uchar *dummy = NULL;
206 const u32 msel = (upm + 4) << BR_MSEL_SHIFT; /* What the MSEL field in BRn should be */
207 volatile u32 *mxmr = &lbus->mamr + upm; /* Pointer to mamr, mbmr, or mcmr */
208 uint i;
209
210 /* Scan all the banks to determine the base address of the device */
211 for (i = 0; i < 8; i++) {
212 if ((lbus->bank[i].br & BR_MSEL) == msel) {
213 dummy = (uchar *) (lbus->bank[i].br & BR_BA);
214 break;
215 }
216 }
217
218 if (!dummy) {
219 printf("Error: %s() could not find matching BR\n", __FUNCTION__);
220 hang();
221 }
222
223 /* Set the OP field in the MxMR to "write" and the MAD field to 000000 */
224 *mxmr = (*mxmr & 0xCFFFFFC0) | 0x10000000;
225
226 for (i = 0; i < size; i++) {
227 lbus->mdr = table[i];
228 __asm__ __volatile__ ("sync");
229 *dummy; /* Write the value to memory and increment MAD */
230 __asm__ __volatile__ ("sync");
231 }
232
233 /* Set the OP field in the MxMR to "normal" and the MAD field to 000000 */
234 *mxmr &= 0xCFFFFFC0;
235#else
236 printf("Error: %s() not defined for this configuration.\n", __FUNCTION__);
237 hang();
238#endif
Eran Liberty9095d4a2005-07-28 10:08:46 -0500239}
240
241
242int
243do_reset (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
244{
Wolfgang Denk301d0962005-08-05 19:49:35 +0200245 ulong msr;
246#ifndef MPC83xx_RESET
247 ulong addr;
248#endif
Eran Liberty9095d4a2005-07-28 10:08:46 -0500249
Timur Tabi386a2802006-11-03 12:00:28 -0600250 volatile immap_t *immap = (immap_t *) CFG_IMMR;
Eran Liberty9095d4a2005-07-28 10:08:46 -0500251
252#ifdef MPC83xx_RESET
253 /* Interrupts and MMU off */
254 __asm__ __volatile__ ("mfmsr %0":"=r" (msr):);
255
256 msr &= ~( MSR_EE | MSR_IR | MSR_DR);
257 __asm__ __volatile__ ("mtmsr %0"::"r" (msr));
258
259 /* enable Reset Control Reg */
260 immap->reset.rpr = 0x52535445;
Marian Balakowicz919b1872006-03-14 16:12:48 +0100261 __asm__ __volatile__ ("sync");
262 __asm__ __volatile__ ("isync");
Eran Liberty9095d4a2005-07-28 10:08:46 -0500263
264 /* confirm Reset Control Reg is enabled */
265 while(!((immap->reset.rcer) & RCER_CRE));
266
267 printf("Resetting the board.");
268 printf("\n");
269
270 udelay(200);
271
272 /* perform reset, only one bit */
Wolfgang Denk301d0962005-08-05 19:49:35 +0200273 immap->reset.rcr = RCR_SWHR;
274
275#else /* ! MPC83xx_RESET */
Eran Liberty9095d4a2005-07-28 10:08:46 -0500276
Wolfgang Denk301d0962005-08-05 19:49:35 +0200277 immap->reset.rmr = RMR_CSRE; /* Checkstop Reset enable */
278
279 /* Interrupts and MMU off */
280 __asm__ __volatile__ ("mfmsr %0":"=r" (msr):);
Eran Liberty9095d4a2005-07-28 10:08:46 -0500281
282 msr &= ~(MSR_ME | MSR_EE | MSR_IR | MSR_DR);
283 __asm__ __volatile__ ("mtmsr %0"::"r" (msr));
284
285 /*
286 * Trying to execute the next instruction at a non-existing address
287 * should cause a machine check, resulting in reset
288 */
289 addr = CFG_RESET_ADDRESS;
290
291 printf("resetting the board.");
292 printf("\n");
293 ((void (*)(void)) addr) ();
Wolfgang Denk301d0962005-08-05 19:49:35 +0200294#endif /* MPC83xx_RESET */
295
Eran Liberty9095d4a2005-07-28 10:08:46 -0500296 return 1;
297}
298
299
300/*
301 * Get timebase clock frequency (like cpu_clk in Hz)
302 */
303
304unsigned long get_tbclk(void)
305{
Eran Liberty9095d4a2005-07-28 10:08:46 -0500306 ulong tbclk;
307
308 tbclk = (gd->bus_clk + 3L) / 4L;
309
310 return tbclk;
311}
312
313
314#if defined(CONFIG_WATCHDOG)
315void watchdog_reset (void)
316{
Timur Tabi054838e2006-10-31 18:44:42 -0600317 int re_enable = disable_interrupts();
318
319 /* Reset the 83xx watchdog */
Timur Tabi386a2802006-11-03 12:00:28 -0600320 volatile immap_t *immr = (immap_t *) CFG_IMMR;
Timur Tabi054838e2006-10-31 18:44:42 -0600321 immr->wdt.swsrr = 0x556c;
322 immr->wdt.swsrr = 0xaa39;
323
324 if (re_enable)
325 enable_interrupts ();
Eran Liberty9095d4a2005-07-28 10:08:46 -0500326}
Timur Tabi054838e2006-10-31 18:44:42 -0600327#endif
Kumar Gala5bbb0452006-01-11 16:48:10 -0600328
Gerald Van Barend6abef42007-03-31 12:23:51 -0400329#if defined(CONFIG_OF_LIBFDT)
330
331/*
Gerald Van Baren2f734162007-04-15 13:54:26 -0400332 * "Setter" functions used to add/modify FDT entries.
333 */
334static int fdt_set_eth0(void *fdt, int nodeoffset, const char *name, bd_t *bd)
335{
336 /*
337 * Fix it up if it exists, don't create it if it doesn't exist.
338 */
339 if (fdt_get_property(fdt, nodeoffset, name, 0)) {
340 return fdt_setprop(fdt, nodeoffset, name, bd->bi_enetaddr, 6);
341 }
342 return -FDT_ERR_NOTFOUND;
343}
344#ifdef CONFIG_HAS_ETH1
345/* second onboard ethernet port */
346static int fdt_set_eth1(void *fdt, int nodeoffset, const char *name, bd_t *bd)
347{
348 /*
349 * Fix it up if it exists, don't create it if it doesn't exist.
350 */
351 if (fdt_get_property(fdt, nodeoffset, name, 0)) {
352 return fdt_setprop(fdt, nodeoffset, name, bd->bi_enet1addr, 6);
353 }
354 return -FDT_ERR_NOTFOUND;
355}
356#endif
357#ifdef CONFIG_HAS_ETH2
358/* third onboard ethernet port */
359static int fdt_set_eth2(void *fdt, int nodeoffset, const char *name, bd_t *bd)
360{
361 /*
362 * Fix it up if it exists, don't create it if it doesn't exist.
363 */
364 if (fdt_get_property(fdt, nodeoffset, name, 0)) {
365 return fdt_setprop(fdt, nodeoffset, name, bd->bi_enet2addr, 6);
366 }
367 return -FDT_ERR_NOTFOUND;
368}
369#endif
370#ifdef CONFIG_HAS_ETH3
371/* fourth onboard ethernet port */
372static int fdt_set_eth3(void *fdt, int nodeoffset, const char *name, bd_t *bd)
373{
374 /*
375 * Fix it up if it exists, don't create it if it doesn't exist.
376 */
377 if (fdt_get_property(fdt, nodeoffset, name, 0)) {
378 return fdt_setprop(fdt, nodeoffset, name, bd->bi_enet3addr, 6);
379 }
380 return -FDT_ERR_NOTFOUND;
381}
382#endif
383
384static int fdt_set_busfreq(void *fdt, int nodeoffset, const char *name, bd_t *bd)
385{
386 u32 tmp;
387 /*
388 * Create or update the property.
389 */
390 tmp = cpu_to_be32(bd->bi_busfreq);
391 return fdt_setprop(fdt, nodeoffset, name, &tmp, sizeof(tmp));
392}
393
394/*
Gerald Van Barend6abef42007-03-31 12:23:51 -0400395 * Fixups to the fdt. If "create" is TRUE, the node is created
396 * unconditionally. If "create" is FALSE, the node is updated
397 * only if it already exists.
398 */
Gerald Van Barend6abef42007-03-31 12:23:51 -0400399static const struct {
Gerald Van Barend6abef42007-03-31 12:23:51 -0400400 char *node;
401 char *prop;
Gerald Van Baren2f734162007-04-15 13:54:26 -0400402 int (*set_fn)(void *fdt, int nodeoffset, const char *name, bd_t *bd);
Gerald Van Barend6abef42007-03-31 12:23:51 -0400403} fixup_props[] = {
Gerald Van Baren2f734162007-04-15 13:54:26 -0400404 { "/cpus/" OF_CPU,
Gerald Van Barend6abef42007-03-31 12:23:51 -0400405 "bus-frequency",
Gerald Van Baren2f734162007-04-15 13:54:26 -0400406 fdt_set_busfreq
Gerald Van Barend6abef42007-03-31 12:23:51 -0400407 },
Gerald Van Baren2f734162007-04-15 13:54:26 -0400408 { "/cpus/" OF_SOC,
409 "bus-frequency",
410 fdt_set_busfreq
Gerald Van Barend6abef42007-03-31 12:23:51 -0400411 },
Gerald Van Baren2f734162007-04-15 13:54:26 -0400412 { "/" OF_SOC "/serial@4500/",
413 "clock-frequency",
414 fdt_set_busfreq
Gerald Van Barend6abef42007-03-31 12:23:51 -0400415 },
Gerald Van Baren2f734162007-04-15 13:54:26 -0400416 { "/" OF_SOC "/serial@4600/",
417 "clock-frequency",
418 fdt_set_busfreq
Gerald Van Barend6abef42007-03-31 12:23:51 -0400419 },
Kim Phillips177e58f2007-05-16 16:52:19 -0500420#ifdef CONFIG_TSEC1
Gerald Van Baren2f734162007-04-15 13:54:26 -0400421 { "/" OF_SOC "/ethernet@24000,
Gerald Van Barend6abef42007-03-31 12:23:51 -0400422 "mac-address",
Gerald Van Baren2f734162007-04-15 13:54:26 -0400423 fdt_set_eth0
Gerald Van Barend6abef42007-03-31 12:23:51 -0400424 },
Gerald Van Baren2f734162007-04-15 13:54:26 -0400425 { "/" OF_SOC "/ethernet@24000,
Gerald Van Barend6abef42007-03-31 12:23:51 -0400426 "local-mac-address",
Gerald Van Baren2f734162007-04-15 13:54:26 -0400427 fdt_set_eth0
Gerald Van Barend6abef42007-03-31 12:23:51 -0400428 },
429#endif
Kim Phillips177e58f2007-05-16 16:52:19 -0500430#ifdef CONFIG_TSEC2
Gerald Van Baren2f734162007-04-15 13:54:26 -0400431 { "/" OF_SOC "/ethernet@25000,
432 "mac-address",
433 fdt_set_eth1
434 },
435 { "/" OF_SOC "/ethernet@25000,
436 "local-mac-address",
437 fdt_set_eth1
438 },
439#endif
440#ifdef CONFIG_UEC_ETH1
441#if CFG_UEC1_UCC_NUM == 0 /* UCC1 */
442 { "/" OF_QE "/ucc@2000/mac-address",
Gerald Van Barend6abef42007-03-31 12:23:51 -0400443 "mac-address",
Gerald Van Baren2f734162007-04-15 13:54:26 -0400444 fdt_set_eth0
Gerald Van Barend6abef42007-03-31 12:23:51 -0400445 },
Gerald Van Baren2f734162007-04-15 13:54:26 -0400446 { "/" OF_QE "/ucc@2000/mac-address",
Gerald Van Barend6abef42007-03-31 12:23:51 -0400447 "local-mac-address",
Gerald Van Baren2f734162007-04-15 13:54:26 -0400448 fdt_set_eth0
449 },
450#elif CFG_UEC1_UCC_NUM == 2 /* UCC3 */
451 { "/" OF_QE "/ucc@2200/mac-address",
452 "mac-address",
453 fdt_set_eth0
454 },
455 { "/" OF_QE "/ucc@2200/mac-address",
456 "local-mac-address",
457 fdt_set_eth0
458 },
459#endif
460#endif
461#ifdef CONFIG_UEC_ETH2
462#if CFG_UEC2_UCC_NUM == 1 /* UCC2 */
463 { "/" OF_QE "/ucc@3000/mac-address",
464 "mac-address",
465 fdt_set_eth1
466 },
467 { "/" OF_QE "/ucc@3000/mac-address",
468 "local-mac-address",
469 fdt_set_eth1
470 },
471#elif CFG_UEC1_UCC_NUM == 3 /* UCC4 */
472 { "/" OF_QE "/ucc@3200/mac-address",
473 "mac-address",
474 fdt_set_eth1
475 },
476 { "/" OF_QE "/ucc@3200/mac-address",
477 "local-mac-address",
478 fdt_set_eth1
Gerald Van Barend6abef42007-03-31 12:23:51 -0400479 },
480#endif
Gerald Van Baren2f734162007-04-15 13:54:26 -0400481#endif
Gerald Van Barend6abef42007-03-31 12:23:51 -0400482};
483
484void
485ft_cpu_setup(void *blob, bd_t *bd)
486{
Gerald Van Baren2f734162007-04-15 13:54:26 -0400487 int nodeoffset;
488 int err;
489 int j;
Gerald Van Barend6abef42007-03-31 12:23:51 -0400490
491 for (j = 0; j < (sizeof(fixup_props) / sizeof(fixup_props[0])); j++) {
Jerry Van Baren1a96f622007-07-04 21:27:30 -0400492 nodeoffset = fdt_find_node_by_path(fdt, fixup_props[j].node);
Gerald Van Barend6abef42007-03-31 12:23:51 -0400493 if (nodeoffset >= 0) {
Gerald Van Baren2f734162007-04-15 13:54:26 -0400494 err = (*fixup_props[j].set_fn)(blob, nodeoffset, fixup_props[j].prop, bd);
495 if (err < 0)
496 printf("set_fn/libfdt: %s %s returned %s\n",
497 fixup_props[j].node,
498 fixup_props[j].prop,
499 fdt_strerror(err));
Gerald Van Barend6abef42007-03-31 12:23:51 -0400500 }
501 }
502}
Jerry Van Baren1a96f622007-07-04 21:27:30 -0400503#elif defined(CONFIG_OF_FLAT_TREE)
Kumar Gala5bbb0452006-01-11 16:48:10 -0600504void
505ft_cpu_setup(void *blob, bd_t *bd)
506{
507 u32 *p;
508 int len;
509 ulong clock;
510
511 clock = bd->bi_busfreq;
512 p = ft_get_prop(blob, "/cpus/" OF_CPU "/bus-frequency", &len);
513 if (p != NULL)
514 *p = cpu_to_be32(clock);
515
516 p = ft_get_prop(blob, "/" OF_SOC "/bus-frequency", &len);
517 if (p != NULL)
518 *p = cpu_to_be32(clock);
519
520 p = ft_get_prop(blob, "/" OF_SOC "/serial@4500/clock-frequency", &len);
521 if (p != NULL)
522 *p = cpu_to_be32(clock);
523
524 p = ft_get_prop(blob, "/" OF_SOC "/serial@4600/clock-frequency", &len);
525 if (p != NULL)
526 *p = cpu_to_be32(clock);
527
Kim Phillips177e58f2007-05-16 16:52:19 -0500528#ifdef CONFIG_TSEC1
Timur Tabief648382007-02-13 10:41:42 -0600529 p = ft_get_prop(blob, "/" OF_SOC "/ethernet@24000/mac-address", &len);
530 if (p != NULL)
531 memcpy(p, bd->bi_enetaddr, 6);
532
Kim Phillipsd99bd8b2006-11-01 00:07:25 -0600533 p = ft_get_prop(blob, "/" OF_SOC "/ethernet@24000/local-mac-address", &len);
Kim Phillips24f63e92007-01-30 16:15:21 -0600534 if (p != NULL)
Kumar Gala5bbb0452006-01-11 16:48:10 -0600535 memcpy(p, bd->bi_enetaddr, 6);
536#endif
537
Kim Phillips177e58f2007-05-16 16:52:19 -0500538#ifdef CONFIG_TSEC2
Timur Tabief648382007-02-13 10:41:42 -0600539 p = ft_get_prop(blob, "/" OF_SOC "/ethernet@25000/mac-address", &len);
540 if (p != NULL)
541 memcpy(p, bd->bi_enet1addr, 6);
542
Kim Phillipsd99bd8b2006-11-01 00:07:25 -0600543 p = ft_get_prop(blob, "/" OF_SOC "/ethernet@25000/local-mac-address", &len);
Kim Phillips24f63e92007-01-30 16:15:21 -0600544 if (p != NULL)
Kumar Gala5bbb0452006-01-11 16:48:10 -0600545 memcpy(p, bd->bi_enet1addr, 6);
546#endif
Kim Phillips526addb2007-02-22 20:06:57 -0600547
548#ifdef CONFIG_UEC_ETH1
549#if CFG_UEC1_UCC_NUM == 0 /* UCC1 */
550 p = ft_get_prop(blob, "/" OF_QE "/ucc@2000/mac-address", &len);
551 if (p != NULL)
552 memcpy(p, bd->bi_enetaddr, 6);
553
554 p = ft_get_prop(blob, "/" OF_QE "/ucc@2000/local-mac-address", &len);
555 if (p != NULL)
556 memcpy(p, bd->bi_enetaddr, 6);
557#elif CFG_UEC1_UCC_NUM == 2 /* UCC3 */
558 p = ft_get_prop(blob, "/" OF_QE "/ucc@2200/mac-address", &len);
559 if (p != NULL)
560 memcpy(p, bd->bi_enetaddr, 6);
561
562 p = ft_get_prop(blob, "/" OF_QE "/ucc@2200/local-mac-address", &len);
563 if (p != NULL)
564 memcpy(p, bd->bi_enetaddr, 6);
565#endif
566#endif
567
568#ifdef CONFIG_UEC_ETH2
569#if CFG_UEC2_UCC_NUM == 1 /* UCC2 */
570 p = ft_get_prop(blob, "/" OF_QE "/ucc@3000/mac-address", &len);
571 if (p != NULL)
572 memcpy(p, bd->bi_enet1addr, 6);
573
574 p = ft_get_prop(blob, "/" OF_QE "/ucc@3000/local-mac-address", &len);
575 if (p != NULL)
576 memcpy(p, bd->bi_enet1addr, 6);
577#elif CFG_UEC2_UCC_NUM == 3 /* UCC4 */
578 p = ft_get_prop(blob, "/" OF_QE "/ucc@3200/mac-address", &len);
579 if (p != NULL)
580 memcpy(p, bd->bi_enet1addr, 6);
581
582 p = ft_get_prop(blob, "/" OF_QE "/ucc@3200/local-mac-address", &len);
583 if (p != NULL)
584 memcpy(p, bd->bi_enet1addr, 6);
585#endif
586#endif
Kumar Gala5bbb0452006-01-11 16:48:10 -0600587}
588#endif
Marian Balakowicz7ec9ebc2006-03-14 16:14:48 +0100589
590#if defined(CONFIG_DDR_ECC)
591void dma_init(void)
592{
Timur Tabi386a2802006-11-03 12:00:28 -0600593 volatile immap_t *immap = (immap_t *)CFG_IMMR;
Dave Liuf5035922006-10-25 14:41:21 -0500594 volatile dma83xx_t *dma = &immap->dma;
Marian Balakowicz7ec9ebc2006-03-14 16:14:48 +0100595 volatile u32 status = swab32(dma->dmasr0);
596 volatile u32 dmamr0 = swab32(dma->dmamr0);
597
598 debug("DMA-init\n");
599
600 /* initialize DMASARn, DMADAR and DMAABCRn */
601 dma->dmadar0 = (u32)0;
602 dma->dmasar0 = (u32)0;
603 dma->dmabcr0 = 0;
604
605 __asm__ __volatile__ ("sync");
606 __asm__ __volatile__ ("isync");
607
608 /* clear CS bit */
609 dmamr0 &= ~DMA_CHANNEL_START;
610 dma->dmamr0 = swab32(dmamr0);
611 __asm__ __volatile__ ("sync");
612 __asm__ __volatile__ ("isync");
613
614 /* while the channel is busy, spin */
615 while(status & DMA_CHANNEL_BUSY) {
616 status = swab32(dma->dmasr0);
617 }
618
619 debug("DMA-init end\n");
620}
621
622uint dma_check(void)
623{
Timur Tabi386a2802006-11-03 12:00:28 -0600624 volatile immap_t *immap = (immap_t *)CFG_IMMR;
Dave Liuf5035922006-10-25 14:41:21 -0500625 volatile dma83xx_t *dma = &immap->dma;
Marian Balakowicz7ec9ebc2006-03-14 16:14:48 +0100626 volatile u32 status = swab32(dma->dmasr0);
627 volatile u32 byte_count = swab32(dma->dmabcr0);
628
629 /* while the channel is busy, spin */
630 while (status & DMA_CHANNEL_BUSY) {
631 status = swab32(dma->dmasr0);
632 }
633
634 if (status & DMA_CHANNEL_TRANSFER_ERROR) {
635 printf ("DMA Error: status = %x @ %d\n", status, byte_count);
636 }
637
638 return status;
639}
640
641int dma_xfer(void *dest, u32 count, void *src)
642{
Timur Tabi386a2802006-11-03 12:00:28 -0600643 volatile immap_t *immap = (immap_t *)CFG_IMMR;
Dave Liuf5035922006-10-25 14:41:21 -0500644 volatile dma83xx_t *dma = &immap->dma;
Marian Balakowicz7ec9ebc2006-03-14 16:14:48 +0100645 volatile u32 dmamr0;
646
647 /* initialize DMASARn, DMADAR and DMAABCRn */
648 dma->dmadar0 = swab32((u32)dest);
649 dma->dmasar0 = swab32((u32)src);
650 dma->dmabcr0 = swab32(count);
651
652 __asm__ __volatile__ ("sync");
653 __asm__ __volatile__ ("isync");
654
655 /* init direct transfer, clear CS bit */
656 dmamr0 = (DMA_CHANNEL_TRANSFER_MODE_DIRECT |
657 DMA_CHANNEL_SOURCE_ADDRESS_HOLD_8B |
658 DMA_CHANNEL_SOURCE_ADRESSS_HOLD_EN);
Wolfgang Denkebd3deb2006-04-16 10:51:58 +0200659
Marian Balakowicz7ec9ebc2006-03-14 16:14:48 +0100660 dma->dmamr0 = swab32(dmamr0);
661
662 __asm__ __volatile__ ("sync");
663 __asm__ __volatile__ ("isync");
664
665 /* set CS to start DMA transfer */
666 dmamr0 |= DMA_CHANNEL_START;
667 dma->dmamr0 = swab32(dmamr0);
668 __asm__ __volatile__ ("sync");
669 __asm__ __volatile__ ("isync");
670
671 return ((int)dma_check());
672}
673#endif /*CONFIG_DDR_ECC*/