blob: 841fe82428d4c9b5509ee3f6fe63923c02b946a6 [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
Kim Phillips54b2d432007-04-30 15:26:21 -050055 puts("CPU: ");
Scott Wood95e7ef82007-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 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 */
Kim Phillips54b2d432007-04-30 15:26:21 -0500161 printf("Rev: %02x at %s MHz", PVR_MAJ(pvr)<<4 | PVR_MIN(pvr), strmhz(buf, clock));
Dave Liu5f820432006-11-03 19:33:44 -0600162#else
Kim Phillips54b2d432007-04-30 15:26:21 -0500163 printf("Rev: %02x at %s MHz", spridr & 0x0000FFFF, strmhz(buf, clock));
Dave Liu5f820432006-11-03 19:33:44 -0600164#endif
Kim Phillips54b2d432007-04-30 15:26:21 -0500165 printf(", CSB: %4d MHz\n", gd->csb_clk / 1000000);
166
Eran Libertyf046ccd2005-07-28 10:08:46 -0500167 return 0;
168}
169
170
Timur Tabibe5e6182006-11-03 19:15:00 -0600171/*
Timur Tabi2ad6b512006-10-31 18:44:42 -0600172 * Program a UPM with the code supplied in the table.
173 *
174 * The 'dummy' variable is used to increment the MAD. 'dummy' is
175 * supposed to be a pointer to the memory of the device being
176 * programmed by the UPM. The data in the MDR is written into
177 * memory and the MAD is incremented every time there's a read
178 * from 'dummy'. Unfortunately, the current prototype for this
179 * function doesn't allow for passing the address of this
180 * device, and changing the prototype will break a number lots
181 * of other code, so we need to use a round-about way of finding
182 * the value for 'dummy'.
183 *
184 * The value can be extracted from the base address bits of the
185 * Base Register (BR) associated with the specific UPM. To find
186 * that BR, we need to scan all 8 BRs until we find the one that
187 * has its MSEL bits matching the UPM we want. Once we know the
188 * right BR, we can extract the base address bits from it.
189 *
190 * The MxMR and the BR and OR of the chosen bank should all be
191 * configured before calling this function.
192 *
193 * Parameters:
194 * upm: 0=UPMA, 1=UPMB, 2=UPMC
195 * table: Pointer to an array of values to program
196 * size: Number of elements in the array. Must be 64 or less.
Timur Tabibe5e6182006-11-03 19:15:00 -0600197 */
Eran Libertyf046ccd2005-07-28 10:08:46 -0500198void upmconfig (uint upm, uint *table, uint size)
199{
Timur Tabi2ad6b512006-10-31 18:44:42 -0600200#if defined(CONFIG_MPC834X)
Timur Tabid239d742006-11-03 12:00:28 -0600201 volatile immap_t *immap = (immap_t *) CFG_IMMR;
Timur Tabi2ad6b512006-10-31 18:44:42 -0600202 volatile lbus83xx_t *lbus = &immap->lbus;
203 volatile uchar *dummy = NULL;
204 const u32 msel = (upm + 4) << BR_MSEL_SHIFT; /* What the MSEL field in BRn should be */
205 volatile u32 *mxmr = &lbus->mamr + upm; /* Pointer to mamr, mbmr, or mcmr */
206 uint i;
207
208 /* Scan all the banks to determine the base address of the device */
209 for (i = 0; i < 8; i++) {
210 if ((lbus->bank[i].br & BR_MSEL) == msel) {
211 dummy = (uchar *) (lbus->bank[i].br & BR_BA);
212 break;
213 }
214 }
215
216 if (!dummy) {
217 printf("Error: %s() could not find matching BR\n", __FUNCTION__);
218 hang();
219 }
220
221 /* Set the OP field in the MxMR to "write" and the MAD field to 000000 */
222 *mxmr = (*mxmr & 0xCFFFFFC0) | 0x10000000;
223
224 for (i = 0; i < size; i++) {
225 lbus->mdr = table[i];
226 __asm__ __volatile__ ("sync");
227 *dummy; /* Write the value to memory and increment MAD */
228 __asm__ __volatile__ ("sync");
229 }
230
231 /* Set the OP field in the MxMR to "normal" and the MAD field to 000000 */
232 *mxmr &= 0xCFFFFFC0;
233#else
234 printf("Error: %s() not defined for this configuration.\n", __FUNCTION__);
235 hang();
236#endif
Eran Libertyf046ccd2005-07-28 10:08:46 -0500237}
238
239
240int
241do_reset (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
242{
Wolfgang Denk07a25052005-08-05 19:49:35 +0200243 ulong msr;
244#ifndef MPC83xx_RESET
245 ulong addr;
246#endif
Eran Libertyf046ccd2005-07-28 10:08:46 -0500247
Timur Tabid239d742006-11-03 12:00:28 -0600248 volatile immap_t *immap = (immap_t *) CFG_IMMR;
Eran Libertyf046ccd2005-07-28 10:08:46 -0500249
250#ifdef MPC83xx_RESET
251 /* Interrupts and MMU off */
252 __asm__ __volatile__ ("mfmsr %0":"=r" (msr):);
253
254 msr &= ~( MSR_EE | MSR_IR | MSR_DR);
255 __asm__ __volatile__ ("mtmsr %0"::"r" (msr));
256
257 /* enable Reset Control Reg */
258 immap->reset.rpr = 0x52535445;
Marian Balakowicz6d8ae5a2006-03-14 16:12:48 +0100259 __asm__ __volatile__ ("sync");
260 __asm__ __volatile__ ("isync");
Eran Libertyf046ccd2005-07-28 10:08:46 -0500261
262 /* confirm Reset Control Reg is enabled */
263 while(!((immap->reset.rcer) & RCER_CRE));
264
265 printf("Resetting the board.");
266 printf("\n");
267
268 udelay(200);
269
270 /* perform reset, only one bit */
Wolfgang Denk07a25052005-08-05 19:49:35 +0200271 immap->reset.rcr = RCR_SWHR;
Eran Libertyf046ccd2005-07-28 10:08:46 -0500272
Wolfgang Denk07a25052005-08-05 19:49:35 +0200273#else /* ! MPC83xx_RESET */
274
275 immap->reset.rmr = RMR_CSRE; /* Checkstop Reset enable */
276
277 /* Interrupts and MMU off */
278 __asm__ __volatile__ ("mfmsr %0":"=r" (msr):);
Eran Libertyf046ccd2005-07-28 10:08:46 -0500279
280 msr &= ~(MSR_ME | MSR_EE | MSR_IR | MSR_DR);
281 __asm__ __volatile__ ("mtmsr %0"::"r" (msr));
282
283 /*
284 * Trying to execute the next instruction at a non-existing address
285 * should cause a machine check, resulting in reset
286 */
287 addr = CFG_RESET_ADDRESS;
288
289 printf("resetting the board.");
290 printf("\n");
291 ((void (*)(void)) addr) ();
Wolfgang Denk07a25052005-08-05 19:49:35 +0200292#endif /* MPC83xx_RESET */
293
Eran Libertyf046ccd2005-07-28 10:08:46 -0500294 return 1;
295}
296
297
298/*
299 * Get timebase clock frequency (like cpu_clk in Hz)
300 */
301
302unsigned long get_tbclk(void)
303{
Eran Libertyf046ccd2005-07-28 10:08:46 -0500304 ulong tbclk;
305
306 tbclk = (gd->bus_clk + 3L) / 4L;
307
308 return tbclk;
309}
310
311
312#if defined(CONFIG_WATCHDOG)
313void watchdog_reset (void)
314{
Timur Tabi2ad6b512006-10-31 18:44:42 -0600315 int re_enable = disable_interrupts();
316
317 /* Reset the 83xx watchdog */
Timur Tabid239d742006-11-03 12:00:28 -0600318 volatile immap_t *immr = (immap_t *) CFG_IMMR;
Timur Tabi2ad6b512006-10-31 18:44:42 -0600319 immr->wdt.swsrr = 0x556c;
320 immr->wdt.swsrr = 0xaa39;
321
322 if (re_enable)
323 enable_interrupts ();
Eran Libertyf046ccd2005-07-28 10:08:46 -0500324}
Timur Tabi2ad6b512006-10-31 18:44:42 -0600325#endif
Kumar Gala62ec6412006-01-11 16:48:10 -0600326
Gerald Van Baren213bf8c2007-03-31 12:23:51 -0400327#if defined(CONFIG_OF_LIBFDT)
328
329/*
Gerald Van Barenf35a53f2007-04-15 13:54:26 -0400330 * "Setter" functions used to add/modify FDT entries.
331 */
332static int fdt_set_eth0(void *fdt, int nodeoffset, const char *name, bd_t *bd)
333{
334 /*
335 * Fix it up if it exists, don't create it if it doesn't exist.
336 */
337 if (fdt_get_property(fdt, nodeoffset, name, 0)) {
338 return fdt_setprop(fdt, nodeoffset, name, bd->bi_enetaddr, 6);
339 }
340 return -FDT_ERR_NOTFOUND;
341}
342#ifdef CONFIG_HAS_ETH1
343/* second onboard ethernet port */
344static int fdt_set_eth1(void *fdt, int nodeoffset, const char *name, bd_t *bd)
345{
346 /*
347 * Fix it up if it exists, don't create it if it doesn't exist.
348 */
349 if (fdt_get_property(fdt, nodeoffset, name, 0)) {
350 return fdt_setprop(fdt, nodeoffset, name, bd->bi_enet1addr, 6);
351 }
352 return -FDT_ERR_NOTFOUND;
353}
354#endif
355#ifdef CONFIG_HAS_ETH2
356/* third onboard ethernet port */
357static int fdt_set_eth2(void *fdt, int nodeoffset, const char *name, bd_t *bd)
358{
359 /*
360 * Fix it up if it exists, don't create it if it doesn't exist.
361 */
362 if (fdt_get_property(fdt, nodeoffset, name, 0)) {
363 return fdt_setprop(fdt, nodeoffset, name, bd->bi_enet2addr, 6);
364 }
365 return -FDT_ERR_NOTFOUND;
366}
367#endif
368#ifdef CONFIG_HAS_ETH3
369/* fourth onboard ethernet port */
370static int fdt_set_eth3(void *fdt, int nodeoffset, const char *name, bd_t *bd)
371{
372 /*
373 * Fix it up if it exists, don't create it if it doesn't exist.
374 */
375 if (fdt_get_property(fdt, nodeoffset, name, 0)) {
376 return fdt_setprop(fdt, nodeoffset, name, bd->bi_enet3addr, 6);
377 }
378 return -FDT_ERR_NOTFOUND;
379}
380#endif
381
382static int fdt_set_busfreq(void *fdt, int nodeoffset, const char *name, bd_t *bd)
383{
384 u32 tmp;
385 /*
386 * Create or update the property.
387 */
388 tmp = cpu_to_be32(bd->bi_busfreq);
389 return fdt_setprop(fdt, nodeoffset, name, &tmp, sizeof(tmp));
390}
391
392/*
Gerald Van Baren213bf8c2007-03-31 12:23:51 -0400393 * Fixups to the fdt. If "create" is TRUE, the node is created
394 * unconditionally. If "create" is FALSE, the node is updated
395 * only if it already exists.
396 */
Gerald Van Baren213bf8c2007-03-31 12:23:51 -0400397static const struct {
Gerald Van Baren213bf8c2007-03-31 12:23:51 -0400398 char *node;
399 char *prop;
Gerald Van Barenf35a53f2007-04-15 13:54:26 -0400400 int (*set_fn)(void *fdt, int nodeoffset, const char *name, bd_t *bd);
Gerald Van Baren213bf8c2007-03-31 12:23:51 -0400401} fixup_props[] = {
Gerald Van Barenf35a53f2007-04-15 13:54:26 -0400402 { "/cpus/" OF_CPU,
Gerald Van Baren213bf8c2007-03-31 12:23:51 -0400403 "bus-frequency",
Gerald Van Barenf35a53f2007-04-15 13:54:26 -0400404 fdt_set_busfreq
Gerald Van Baren213bf8c2007-03-31 12:23:51 -0400405 },
Gerald Van Barenf35a53f2007-04-15 13:54:26 -0400406 { "/cpus/" OF_SOC,
407 "bus-frequency",
408 fdt_set_busfreq
Gerald Van Baren213bf8c2007-03-31 12:23:51 -0400409 },
Gerald Van Barenf35a53f2007-04-15 13:54:26 -0400410 { "/" OF_SOC "/serial@4500/",
411 "clock-frequency",
412 fdt_set_busfreq
Gerald Van Baren213bf8c2007-03-31 12:23:51 -0400413 },
Gerald Van Barenf35a53f2007-04-15 13:54:26 -0400414 { "/" OF_SOC "/serial@4600/",
415 "clock-frequency",
416 fdt_set_busfreq
Gerald Van Baren213bf8c2007-03-31 12:23:51 -0400417 },
Kim Phillips255a35772007-05-16 16:52:19 -0500418#ifdef CONFIG_TSEC1
Gerald Van Barenf35a53f2007-04-15 13:54:26 -0400419 { "/" OF_SOC "/ethernet@24000,
Gerald Van Baren213bf8c2007-03-31 12:23:51 -0400420 "mac-address",
Gerald Van Barenf35a53f2007-04-15 13:54:26 -0400421 fdt_set_eth0
Gerald Van Baren213bf8c2007-03-31 12:23:51 -0400422 },
Gerald Van Barenf35a53f2007-04-15 13:54:26 -0400423 { "/" OF_SOC "/ethernet@24000,
Gerald Van Baren213bf8c2007-03-31 12:23:51 -0400424 "local-mac-address",
Gerald Van Barenf35a53f2007-04-15 13:54:26 -0400425 fdt_set_eth0
Gerald Van Baren213bf8c2007-03-31 12:23:51 -0400426 },
427#endif
Kim Phillips255a35772007-05-16 16:52:19 -0500428#ifdef CONFIG_TSEC2
Gerald Van Barenf35a53f2007-04-15 13:54:26 -0400429 { "/" OF_SOC "/ethernet@25000,
Gerald Van Baren213bf8c2007-03-31 12:23:51 -0400430 "mac-address",
Gerald Van Barenf35a53f2007-04-15 13:54:26 -0400431 fdt_set_eth1
Gerald Van Baren213bf8c2007-03-31 12:23:51 -0400432 },
Gerald Van Barenf35a53f2007-04-15 13:54:26 -0400433 { "/" OF_SOC "/ethernet@25000,
Gerald Van Baren213bf8c2007-03-31 12:23:51 -0400434 "local-mac-address",
Gerald Van Barenf35a53f2007-04-15 13:54:26 -0400435 fdt_set_eth1
Gerald Van Baren213bf8c2007-03-31 12:23:51 -0400436 },
437#endif
Gerald Van Barenf35a53f2007-04-15 13:54:26 -0400438#ifdef CONFIG_UEC_ETH1
439#if CFG_UEC1_UCC_NUM == 0 /* UCC1 */
440 { "/" OF_QE "/ucc@2000/mac-address",
441 "mac-address",
442 fdt_set_eth0
443 },
444 { "/" OF_QE "/ucc@2000/mac-address",
445 "local-mac-address",
446 fdt_set_eth0
447 },
448#elif CFG_UEC1_UCC_NUM == 2 /* UCC3 */
449 { "/" OF_QE "/ucc@2200/mac-address",
450 "mac-address",
451 fdt_set_eth0
452 },
453 { "/" OF_QE "/ucc@2200/mac-address",
454 "local-mac-address",
455 fdt_set_eth0
456 },
457#endif
458#endif
459#ifdef CONFIG_UEC_ETH2
460#if CFG_UEC2_UCC_NUM == 1 /* UCC2 */
461 { "/" OF_QE "/ucc@3000/mac-address",
462 "mac-address",
463 fdt_set_eth1
464 },
465 { "/" OF_QE "/ucc@3000/mac-address",
466 "local-mac-address",
467 fdt_set_eth1
468 },
469#elif CFG_UEC1_UCC_NUM == 3 /* UCC4 */
470 { "/" OF_QE "/ucc@3200/mac-address",
471 "mac-address",
472 fdt_set_eth1
473 },
474 { "/" OF_QE "/ucc@3200/mac-address",
475 "local-mac-address",
476 fdt_set_eth1
477 },
478#endif
479#endif
Gerald Van Baren213bf8c2007-03-31 12:23:51 -0400480};
481
482void
483ft_cpu_setup(void *blob, bd_t *bd)
484{
Gerald Van Barenf35a53f2007-04-15 13:54:26 -0400485 int nodeoffset;
486 int err;
487 int j;
Gerald Van Baren213bf8c2007-03-31 12:23:51 -0400488
489 for (j = 0; j < (sizeof(fixup_props) / sizeof(fixup_props[0])); j++) {
Gerald Van Barenf35a53f2007-04-15 13:54:26 -0400490 nodeoffset = fdt_path_offset(fdt, fixup_props[j].node);
Gerald Van Baren213bf8c2007-03-31 12:23:51 -0400491 if (nodeoffset >= 0) {
Gerald Van Barenf35a53f2007-04-15 13:54:26 -0400492 err = (*fixup_props[j].set_fn)(blob, nodeoffset, fixup_props[j].prop, bd);
493 if (err < 0)
494 printf("set_fn/libfdt: %s %s returned %s\n",
495 fixup_props[j].node,
496 fixup_props[j].prop,
497 fdt_strerror(err));
Gerald Van Baren213bf8c2007-03-31 12:23:51 -0400498 }
499 }
500}
501#endif
502
Kumar Gala62ec6412006-01-11 16:48:10 -0600503#if defined(CONFIG_OF_FLAT_TREE)
504void
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 Phillips255a35772007-05-16 16:52:19 -0500528#ifdef CONFIG_TSEC1
Timur Tabi61f4f912007-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 Phillips48041362006-11-01 00:07:25 -0600533 p = ft_get_prop(blob, "/" OF_SOC "/ethernet@24000/local-mac-address", &len);
Kim Phillipsb7004742007-01-30 16:15:21 -0600534 if (p != NULL)
Kumar Gala62ec6412006-01-11 16:48:10 -0600535 memcpy(p, bd->bi_enetaddr, 6);
536#endif
537
Kim Phillips255a35772007-05-16 16:52:19 -0500538#ifdef CONFIG_TSEC2
Timur Tabi61f4f912007-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 Phillips48041362006-11-01 00:07:25 -0600543 p = ft_get_prop(blob, "/" OF_SOC "/ethernet@25000/local-mac-address", &len);
Kim Phillipsb7004742007-01-30 16:15:21 -0600544 if (p != NULL)
Kumar Gala62ec6412006-01-11 16:48:10 -0600545 memcpy(p, bd->bi_enet1addr, 6);
546#endif
Kim Phillipsd51b3cf2007-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 Gala62ec6412006-01-11 16:48:10 -0600587}
588#endif
Marian Balakowicz61f25152006-03-14 16:14:48 +0100589
590#if defined(CONFIG_DDR_ECC)
591void dma_init(void)
592{
Timur Tabid239d742006-11-03 12:00:28 -0600593 volatile immap_t *immap = (immap_t *)CFG_IMMR;
Dave Liuf6eda7f2006-10-25 14:41:21 -0500594 volatile dma83xx_t *dma = &immap->dma;
Marian Balakowicz61f25152006-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 Tabid239d742006-11-03 12:00:28 -0600624 volatile immap_t *immap = (immap_t *)CFG_IMMR;
Dave Liuf6eda7f2006-10-25 14:41:21 -0500625 volatile dma83xx_t *dma = &immap->dma;
Marian Balakowicz61f25152006-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 Tabid239d742006-11-03 12:00:28 -0600643 volatile immap_t *immap = (immap_t *)CFG_IMMR;
Dave Liuf6eda7f2006-10-25 14:41:21 -0500644 volatile dma83xx_t *dma = &immap->dma;
Marian Balakowicz61f25152006-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 Denkcf48eb92006-04-16 10:51:58 +0200659
Marian Balakowicz61f25152006-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*/