blob: 3d3f20a636d93f9c253e24cbf472b05a212c7e3b [file] [log] [blame]
Eran Libertyf046ccd2005-07-28 10:08:46 -05001/*
Dave Liu03051c32007-09-18 12:36:11 +08002 * Copyright (C) 2004-2007 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>
Jerry Van Baren26d02c92007-07-04 21:27:30 -040036#elif defined(CONFIG_OF_LIBFDT)
Gerald Van Baren213bf8c2007-03-31 12:23:51 -040037#include <libfdt.h>
Kumar Gala246d4ae2007-11-27 21:59:46 -060038#include <fdt_support.h>
Gerald Van Baren213bf8c2007-03-31 12:23:51 -040039#endif
Eran Libertyf046ccd2005-07-28 10:08:46 -050040
Wolfgang Denkd87080b2006-03-31 18:32:53 +020041DECLARE_GLOBAL_DATA_PTR;
42
Eran Libertyf046ccd2005-07-28 10:08:46 -050043int checkcpu(void)
44{
Dave Liu5f820432006-11-03 19:33:44 -060045 volatile immap_t *immr;
Eran Libertyf046ccd2005-07-28 10:08:46 -050046 ulong clock = gd->cpu_clk;
47 u32 pvr = get_pvr();
Dave Liu5f820432006-11-03 19:33:44 -060048 u32 spridr;
Eran Libertyf046ccd2005-07-28 10:08:46 -050049 char buf[32];
50
Timur Tabid239d742006-11-03 12:00:28 -060051 immr = (immap_t *)CFG_IMMR;
Dave Liu5f820432006-11-03 19:33:44 -060052
Kim Phillips54b2d432007-04-30 15:26:21 -050053 puts("CPU: ");
Scott Wood95e7ef82007-04-16 14:34:16 -050054
55 switch (pvr & 0xffff0000) {
56 case PVR_E300C1:
57 printf("e300c1, ");
58 break;
59
60 case PVR_E300C2:
61 printf("e300c2, ");
62 break;
63
64 case PVR_E300C3:
65 printf("e300c3, ");
66 break;
67
Dave Liu03051c32007-09-18 12:36:11 +080068 case PVR_E300C4:
69 printf("e300c4, ");
70 break;
71
Scott Wood95e7ef82007-04-16 14:34:16 -050072 default:
73 printf("Unknown core, ");
Eran Libertyf046ccd2005-07-28 10:08:46 -050074 }
75
Dave Liu5f820432006-11-03 19:33:44 -060076 spridr = immr->sysconf.spridr;
Dave Liu5f820432006-11-03 19:33:44 -060077 switch(spridr) {
78 case SPR_8349E_REV10:
79 case SPR_8349E_REV11:
Xie Xiaobo8d172c02007-02-14 18:26:44 +080080 case SPR_8349E_REV31:
Dave Liu5f820432006-11-03 19:33:44 -060081 puts("MPC8349E, ");
Eran Libertyf046ccd2005-07-28 10:08:46 -050082 break;
Dave Liu5f820432006-11-03 19:33:44 -060083 case SPR_8349_REV10:
84 case SPR_8349_REV11:
Xie Xiaobo8d172c02007-02-14 18:26:44 +080085 case SPR_8349_REV31:
Dave Liu5f820432006-11-03 19:33:44 -060086 puts("MPC8349, ");
87 break;
88 case SPR_8347E_REV10_TBGA:
89 case SPR_8347E_REV11_TBGA:
Xie Xiaobo8d172c02007-02-14 18:26:44 +080090 case SPR_8347E_REV31_TBGA:
Dave Liu5f820432006-11-03 19:33:44 -060091 case SPR_8347E_REV10_PBGA:
92 case SPR_8347E_REV11_PBGA:
Xie Xiaobo8d172c02007-02-14 18:26:44 +080093 case SPR_8347E_REV31_PBGA:
Dave Liu5f820432006-11-03 19:33:44 -060094 puts("MPC8347E, ");
95 break;
96 case SPR_8347_REV10_TBGA:
97 case SPR_8347_REV11_TBGA:
Xie Xiaobo8d172c02007-02-14 18:26:44 +080098 case SPR_8347_REV31_TBGA:
Dave Liu5f820432006-11-03 19:33:44 -060099 case SPR_8347_REV10_PBGA:
100 case SPR_8347_REV11_PBGA:
Xie Xiaobo8d172c02007-02-14 18:26:44 +0800101 case SPR_8347_REV31_PBGA:
Dave Liu5f820432006-11-03 19:33:44 -0600102 puts("MPC8347, ");
103 break;
104 case SPR_8343E_REV10:
105 case SPR_8343E_REV11:
Xie Xiaobo8d172c02007-02-14 18:26:44 +0800106 case SPR_8343E_REV31:
Dave Liu5f820432006-11-03 19:33:44 -0600107 puts("MPC8343E, ");
108 break;
109 case SPR_8343_REV10:
110 case SPR_8343_REV11:
Xie Xiaobo8d172c02007-02-14 18:26:44 +0800111 case SPR_8343_REV31:
Dave Liu5f820432006-11-03 19:33:44 -0600112 puts("MPC8343, ");
113 break;
114 case SPR_8360E_REV10:
115 case SPR_8360E_REV11:
116 case SPR_8360E_REV12:
Xie Xiaobob110f402007-02-14 18:27:06 +0800117 case SPR_8360E_REV20:
Lee Nipper1ded0242007-06-14 20:07:33 -0500118 case SPR_8360E_REV21:
Dave Liu5f820432006-11-03 19:33:44 -0600119 puts("MPC8360E, ");
120 break;
121 case SPR_8360_REV10:
122 case SPR_8360_REV11:
123 case SPR_8360_REV12:
Xie Xiaobob110f402007-02-14 18:27:06 +0800124 case SPR_8360_REV20:
Lee Nipper1ded0242007-06-14 20:07:33 -0500125 case SPR_8360_REV21:
Dave Liu5f820432006-11-03 19:33:44 -0600126 puts("MPC8360, ");
Eran Libertyf046ccd2005-07-28 10:08:46 -0500127 break;
Dave Liu24c3aca2006-12-07 21:13:15 +0800128 case SPR_8323E_REV10:
129 case SPR_8323E_REV11:
130 puts("MPC8323E, ");
131 break;
132 case SPR_8323_REV10:
133 case SPR_8323_REV11:
134 puts("MPC8323, ");
135 break;
136 case SPR_8321E_REV10:
137 case SPR_8321E_REV11:
138 puts("MPC8321E, ");
139 break;
140 case SPR_8321_REV10:
141 case SPR_8321_REV11:
142 puts("MPC8321, ");
143 break;
Scott Wooda35b0c42007-04-16 14:34:15 -0500144 case SPR_8311_REV10:
145 puts("MPC8311, ");
146 break;
147 case SPR_8311E_REV10:
148 puts("MPC8311E, ");
149 break;
150 case SPR_8313_REV10:
151 puts("MPC8313, ");
152 break;
153 case SPR_8313E_REV10:
154 puts("MPC8313E, ");
155 break;
Dave Liu555da612007-09-18 12:36:58 +0800156 case SPR_8315E_REV10:
157 puts("MPC8315E, ");
158 break;
159 case SPR_8315_REV10:
160 puts("MPC8315, ");
161 break;
162 case SPR_8314E_REV10:
163 puts("MPC8314E, ");
164 break;
165 case SPR_8314_REV10:
166 puts("MPC8314, ");
167 break;
Dave Liu03051c32007-09-18 12:36:11 +0800168 case SPR_8379E_REV10:
169 puts("MPC8379E, ");
170 break;
171 case SPR_8379_REV10:
172 puts("MPC8379, ");
173 break;
174 case SPR_8378E_REV10:
175 puts("MPC8378E, ");
176 break;
177 case SPR_8378_REV10:
178 puts("MPC8378, ");
179 break;
180 case SPR_8377E_REV10:
181 puts("MPC8377E, ");
182 break;
183 case SPR_8377_REV10:
184 puts("MPC8377, ");
185 break;
Eran Libertyf046ccd2005-07-28 10:08:46 -0500186 default:
Lee Nipper1ded0242007-06-14 20:07:33 -0500187 printf("Rev: Unknown revision number:%08x\n"
188 "Warning: Unsupported cpu revision!\n",spridr);
Xie Xiaobo8d172c02007-02-14 18:26:44 +0800189 return 0;
Eran Libertyf046ccd2005-07-28 10:08:46 -0500190 }
Rafal Jaworowski6902df52005-10-17 02:39:53 +0200191
Kumar Gala3e78a312007-01-30 14:08:30 -0600192#if defined(CONFIG_MPC834X)
Xie Xiaobo8d172c02007-02-14 18:26:44 +0800193 /* Multiple revisons of 834x processors may have the same SPRIDR value.
194 * So use PVR to identify the revision number.
195 */
Kim Phillips54b2d432007-04-30 15:26:21 -0500196 printf("Rev: %02x at %s MHz", PVR_MAJ(pvr)<<4 | PVR_MIN(pvr), strmhz(buf, clock));
Dave Liu5f820432006-11-03 19:33:44 -0600197#else
Kim Phillips54b2d432007-04-30 15:26:21 -0500198 printf("Rev: %02x at %s MHz", spridr & 0x0000FFFF, strmhz(buf, clock));
Dave Liu5f820432006-11-03 19:33:44 -0600199#endif
Kim Phillips54b2d432007-04-30 15:26:21 -0500200 printf(", CSB: %4d MHz\n", gd->csb_clk / 1000000);
201
Eran Libertyf046ccd2005-07-28 10:08:46 -0500202 return 0;
203}
204
205
Timur Tabibe5e6182006-11-03 19:15:00 -0600206/*
Timur Tabi2ad6b512006-10-31 18:44:42 -0600207 * Program a UPM with the code supplied in the table.
208 *
209 * The 'dummy' variable is used to increment the MAD. 'dummy' is
210 * supposed to be a pointer to the memory of the device being
211 * programmed by the UPM. The data in the MDR is written into
212 * memory and the MAD is incremented every time there's a read
213 * from 'dummy'. Unfortunately, the current prototype for this
214 * function doesn't allow for passing the address of this
215 * device, and changing the prototype will break a number lots
216 * of other code, so we need to use a round-about way of finding
217 * the value for 'dummy'.
218 *
219 * The value can be extracted from the base address bits of the
220 * Base Register (BR) associated with the specific UPM. To find
221 * that BR, we need to scan all 8 BRs until we find the one that
222 * has its MSEL bits matching the UPM we want. Once we know the
223 * right BR, we can extract the base address bits from it.
224 *
225 * The MxMR and the BR and OR of the chosen bank should all be
226 * configured before calling this function.
227 *
228 * Parameters:
229 * upm: 0=UPMA, 1=UPMB, 2=UPMC
230 * table: Pointer to an array of values to program
231 * size: Number of elements in the array. Must be 64 or less.
Timur Tabibe5e6182006-11-03 19:15:00 -0600232 */
Eran Libertyf046ccd2005-07-28 10:08:46 -0500233void upmconfig (uint upm, uint *table, uint size)
234{
Timur Tabi2ad6b512006-10-31 18:44:42 -0600235#if defined(CONFIG_MPC834X)
Timur Tabid239d742006-11-03 12:00:28 -0600236 volatile immap_t *immap = (immap_t *) CFG_IMMR;
Timur Tabi2ad6b512006-10-31 18:44:42 -0600237 volatile lbus83xx_t *lbus = &immap->lbus;
238 volatile uchar *dummy = NULL;
239 const u32 msel = (upm + 4) << BR_MSEL_SHIFT; /* What the MSEL field in BRn should be */
240 volatile u32 *mxmr = &lbus->mamr + upm; /* Pointer to mamr, mbmr, or mcmr */
241 uint i;
242
243 /* Scan all the banks to determine the base address of the device */
244 for (i = 0; i < 8; i++) {
245 if ((lbus->bank[i].br & BR_MSEL) == msel) {
246 dummy = (uchar *) (lbus->bank[i].br & BR_BA);
247 break;
248 }
249 }
250
251 if (!dummy) {
252 printf("Error: %s() could not find matching BR\n", __FUNCTION__);
253 hang();
254 }
255
256 /* Set the OP field in the MxMR to "write" and the MAD field to 000000 */
257 *mxmr = (*mxmr & 0xCFFFFFC0) | 0x10000000;
258
259 for (i = 0; i < size; i++) {
260 lbus->mdr = table[i];
261 __asm__ __volatile__ ("sync");
262 *dummy; /* Write the value to memory and increment MAD */
263 __asm__ __volatile__ ("sync");
264 }
265
266 /* Set the OP field in the MxMR to "normal" and the MAD field to 000000 */
267 *mxmr &= 0xCFFFFFC0;
268#else
269 printf("Error: %s() not defined for this configuration.\n", __FUNCTION__);
270 hang();
271#endif
Eran Libertyf046ccd2005-07-28 10:08:46 -0500272}
273
274
275int
276do_reset (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
277{
Wolfgang Denk07a25052005-08-05 19:49:35 +0200278 ulong msr;
279#ifndef MPC83xx_RESET
280 ulong addr;
281#endif
Eran Libertyf046ccd2005-07-28 10:08:46 -0500282
Timur Tabid239d742006-11-03 12:00:28 -0600283 volatile immap_t *immap = (immap_t *) CFG_IMMR;
Eran Libertyf046ccd2005-07-28 10:08:46 -0500284
285#ifdef MPC83xx_RESET
286 /* Interrupts and MMU off */
287 __asm__ __volatile__ ("mfmsr %0":"=r" (msr):);
288
289 msr &= ~( MSR_EE | MSR_IR | MSR_DR);
290 __asm__ __volatile__ ("mtmsr %0"::"r" (msr));
291
292 /* enable Reset Control Reg */
293 immap->reset.rpr = 0x52535445;
Marian Balakowicz6d8ae5a2006-03-14 16:12:48 +0100294 __asm__ __volatile__ ("sync");
295 __asm__ __volatile__ ("isync");
Eran Libertyf046ccd2005-07-28 10:08:46 -0500296
297 /* confirm Reset Control Reg is enabled */
298 while(!((immap->reset.rcer) & RCER_CRE));
299
300 printf("Resetting the board.");
301 printf("\n");
302
303 udelay(200);
304
305 /* perform reset, only one bit */
Wolfgang Denk07a25052005-08-05 19:49:35 +0200306 immap->reset.rcr = RCR_SWHR;
Eran Libertyf046ccd2005-07-28 10:08:46 -0500307
Wolfgang Denk07a25052005-08-05 19:49:35 +0200308#else /* ! MPC83xx_RESET */
309
310 immap->reset.rmr = RMR_CSRE; /* Checkstop Reset enable */
311
312 /* Interrupts and MMU off */
313 __asm__ __volatile__ ("mfmsr %0":"=r" (msr):);
Eran Libertyf046ccd2005-07-28 10:08:46 -0500314
315 msr &= ~(MSR_ME | MSR_EE | MSR_IR | MSR_DR);
316 __asm__ __volatile__ ("mtmsr %0"::"r" (msr));
317
318 /*
319 * Trying to execute the next instruction at a non-existing address
320 * should cause a machine check, resulting in reset
321 */
322 addr = CFG_RESET_ADDRESS;
323
324 printf("resetting the board.");
325 printf("\n");
326 ((void (*)(void)) addr) ();
Wolfgang Denk07a25052005-08-05 19:49:35 +0200327#endif /* MPC83xx_RESET */
328
Eran Libertyf046ccd2005-07-28 10:08:46 -0500329 return 1;
330}
331
332
333/*
334 * Get timebase clock frequency (like cpu_clk in Hz)
335 */
336
337unsigned long get_tbclk(void)
338{
Eran Libertyf046ccd2005-07-28 10:08:46 -0500339 ulong tbclk;
340
341 tbclk = (gd->bus_clk + 3L) / 4L;
342
343 return tbclk;
344}
345
346
347#if defined(CONFIG_WATCHDOG)
348void watchdog_reset (void)
349{
Timur Tabi2ad6b512006-10-31 18:44:42 -0600350 int re_enable = disable_interrupts();
351
352 /* Reset the 83xx watchdog */
Timur Tabid239d742006-11-03 12:00:28 -0600353 volatile immap_t *immr = (immap_t *) CFG_IMMR;
Timur Tabi2ad6b512006-10-31 18:44:42 -0600354 immr->wdt.swsrr = 0x556c;
355 immr->wdt.swsrr = 0xaa39;
356
357 if (re_enable)
358 enable_interrupts ();
Eran Libertyf046ccd2005-07-28 10:08:46 -0500359}
Timur Tabi2ad6b512006-10-31 18:44:42 -0600360#endif
Kumar Gala62ec6412006-01-11 16:48:10 -0600361
Gerald Van Baren213bf8c2007-03-31 12:23:51 -0400362#if defined(CONFIG_OF_LIBFDT)
363
364/*
Gerald Van Barenf35a53f2007-04-15 13:54:26 -0400365 * "Setter" functions used to add/modify FDT entries.
366 */
Kim Phillipsf57ac7a2007-07-25 19:25:22 -0500367static int fdt_set_eth0(void *blob, int nodeoffset, const char *name, bd_t *bd)
Gerald Van Barenf35a53f2007-04-15 13:54:26 -0400368{
Kim Phillips8f9e0e92007-08-15 22:30:19 -0500369 /* Fix it up if it exists, don't create it if it doesn't exist */
Kim Phillipsf57ac7a2007-07-25 19:25:22 -0500370 if (fdt_get_property(blob, nodeoffset, name, 0)) {
371 return fdt_setprop(blob, nodeoffset, name, bd->bi_enetaddr, 6);
Gerald Van Barenf35a53f2007-04-15 13:54:26 -0400372 }
Jerry Van Baren8be40442007-07-04 21:34:24 -0400373 return 0;
Gerald Van Barenf35a53f2007-04-15 13:54:26 -0400374}
375#ifdef CONFIG_HAS_ETH1
376/* second onboard ethernet port */
Kim Phillipsf57ac7a2007-07-25 19:25:22 -0500377static int fdt_set_eth1(void *blob, int nodeoffset, const char *name, bd_t *bd)
Gerald Van Barenf35a53f2007-04-15 13:54:26 -0400378{
Kim Phillips8f9e0e92007-08-15 22:30:19 -0500379 /* Fix it up if it exists, don't create it if it doesn't exist */
Kim Phillipsf57ac7a2007-07-25 19:25:22 -0500380 if (fdt_get_property(blob, nodeoffset, name, 0)) {
381 return fdt_setprop(blob, nodeoffset, name, bd->bi_enet1addr, 6);
Gerald Van Barenf35a53f2007-04-15 13:54:26 -0400382 }
Jerry Van Baren8be40442007-07-04 21:34:24 -0400383 return 0;
Gerald Van Barenf35a53f2007-04-15 13:54:26 -0400384}
385#endif
386#ifdef CONFIG_HAS_ETH2
387/* third onboard ethernet port */
Kim Phillipsf57ac7a2007-07-25 19:25:22 -0500388static int fdt_set_eth2(void *blob, int nodeoffset, const char *name, bd_t *bd)
Gerald Van Barenf35a53f2007-04-15 13:54:26 -0400389{
Kim Phillips8f9e0e92007-08-15 22:30:19 -0500390 /* Fix it up if it exists, don't create it if it doesn't exist */
Kim Phillipsf57ac7a2007-07-25 19:25:22 -0500391 if (fdt_get_property(blob, nodeoffset, name, 0)) {
392 return fdt_setprop(blob, nodeoffset, name, bd->bi_enet2addr, 6);
Gerald Van Barenf35a53f2007-04-15 13:54:26 -0400393 }
Jerry Van Baren8be40442007-07-04 21:34:24 -0400394 return 0;
Gerald Van Barenf35a53f2007-04-15 13:54:26 -0400395}
396#endif
397#ifdef CONFIG_HAS_ETH3
398/* fourth onboard ethernet port */
Kim Phillipsf57ac7a2007-07-25 19:25:22 -0500399static int fdt_set_eth3(void *blob, int nodeoffset, const char *name, bd_t *bd)
Gerald Van Barenf35a53f2007-04-15 13:54:26 -0400400{
Kim Phillips8f9e0e92007-08-15 22:30:19 -0500401 /* Fix it up if it exists, don't create it if it doesn't exist */
Kim Phillipsf57ac7a2007-07-25 19:25:22 -0500402 if (fdt_get_property(blob, nodeoffset, name, 0)) {
403 return fdt_setprop(blob, nodeoffset, name, bd->bi_enet3addr, 6);
Gerald Van Barenf35a53f2007-04-15 13:54:26 -0400404 }
Jerry Van Baren8be40442007-07-04 21:34:24 -0400405 return 0;
Gerald Van Barenf35a53f2007-04-15 13:54:26 -0400406}
407#endif
408
Kim Phillipsf57ac7a2007-07-25 19:25:22 -0500409static int fdt_set_busfreq(void *blob, int nodeoffset, const char *name, bd_t *bd)
Gerald Van Barenf35a53f2007-04-15 13:54:26 -0400410{
411 u32 tmp;
Kim Phillips8f9e0e92007-08-15 22:30:19 -0500412 /* Create or update the property */
Gerald Van Barenf35a53f2007-04-15 13:54:26 -0400413 tmp = cpu_to_be32(bd->bi_busfreq);
Kim Phillipsf57ac7a2007-07-25 19:25:22 -0500414 return fdt_setprop(blob, nodeoffset, name, &tmp, sizeof(tmp));
Gerald Van Barenf35a53f2007-04-15 13:54:26 -0400415}
416
Kim Phillipsf57ac7a2007-07-25 19:25:22 -0500417static int fdt_set_tbfreq(void *blob, int nodeoffset, const char *name, bd_t *bd)
Jerry Van Baren8be40442007-07-04 21:34:24 -0400418{
419 u32 tmp;
Kim Phillips8f9e0e92007-08-15 22:30:19 -0500420 /* Create or update the property */
Jerry Van Baren8be40442007-07-04 21:34:24 -0400421 tmp = cpu_to_be32(OF_TBCLK);
Kim Phillipsf57ac7a2007-07-25 19:25:22 -0500422 return fdt_setprop(blob, nodeoffset, name, &tmp, sizeof(tmp));
Jerry Van Baren8be40442007-07-04 21:34:24 -0400423}
424
425
Kim Phillips8f9e0e92007-08-15 22:30:19 -0500426static int fdt_set_clockfreq(void *blob, int nodeoffset, const char *name, bd_t *bd)
427{
428 u32 tmp;
429 /* Create or update the property */
430 tmp = cpu_to_be32(gd->core_clk);
431 return fdt_setprop(blob, nodeoffset, name, &tmp, sizeof(tmp));
432}
433
434#ifdef CONFIG_QE
435static int fdt_set_qe_busfreq(void *blob, int nodeoffset, const char *name, bd_t *bd)
436{
437 u32 tmp;
438 /* Create or update the property */
439 tmp = cpu_to_be32(gd->qe_clk);
440 return fdt_setprop(blob, nodeoffset, name, &tmp, sizeof(tmp));
441}
442
443static int fdt_set_qe_brgfreq(void *blob, int nodeoffset, const char *name, bd_t *bd)
444{
445 u32 tmp;
446 /* Create or update the property */
447 tmp = cpu_to_be32(gd->brg_clk);
448 return fdt_setprop(blob, nodeoffset, name, &tmp, sizeof(tmp));
449}
450#endif
451
Gerald Van Barenf35a53f2007-04-15 13:54:26 -0400452/*
Jerry Van Baren8be40442007-07-04 21:34:24 -0400453 * Fixups to the fdt.
Gerald Van Baren213bf8c2007-03-31 12:23:51 -0400454 */
Gerald Van Baren213bf8c2007-03-31 12:23:51 -0400455static const struct {
Gerald Van Baren213bf8c2007-03-31 12:23:51 -0400456 char *node;
457 char *prop;
Kim Phillipsf57ac7a2007-07-25 19:25:22 -0500458 int (*set_fn)(void *blob, int nodeoffset, const char *name, bd_t *bd);
Gerald Van Baren213bf8c2007-03-31 12:23:51 -0400459} fixup_props[] = {
Gerald Van Barenf35a53f2007-04-15 13:54:26 -0400460 { "/cpus/" OF_CPU,
Jerry Van Baren8be40442007-07-04 21:34:24 -0400461 "timebase-frequency",
462 fdt_set_tbfreq
Gerald Van Baren213bf8c2007-03-31 12:23:51 -0400463 },
Jerry Van Baren8be40442007-07-04 21:34:24 -0400464 { "/cpus/" OF_CPU,
Gerald Van Barenf35a53f2007-04-15 13:54:26 -0400465 "bus-frequency",
466 fdt_set_busfreq
Gerald Van Baren213bf8c2007-03-31 12:23:51 -0400467 },
Jerry Van Baren8be40442007-07-04 21:34:24 -0400468 { "/cpus/" OF_CPU,
Gerald Van Barenf35a53f2007-04-15 13:54:26 -0400469 "clock-frequency",
Kim Phillips8f9e0e92007-08-15 22:30:19 -0500470 fdt_set_clockfreq
471 },
472 { "/" OF_SOC,
473 "bus-frequency",
Gerald Van Barenf35a53f2007-04-15 13:54:26 -0400474 fdt_set_busfreq
Gerald Van Baren213bf8c2007-03-31 12:23:51 -0400475 },
Jerry Van Baren8be40442007-07-04 21:34:24 -0400476 { "/" OF_SOC "/serial@4500",
477 "clock-frequency",
478 fdt_set_busfreq
479 },
480 { "/" OF_SOC "/serial@4600",
Gerald Van Barenf35a53f2007-04-15 13:54:26 -0400481 "clock-frequency",
482 fdt_set_busfreq
Gerald Van Baren213bf8c2007-03-31 12:23:51 -0400483 },
Kim Phillips255a35772007-05-16 16:52:19 -0500484#ifdef CONFIG_TSEC1
Jerry Van Baren8be40442007-07-04 21:34:24 -0400485 { "/" OF_SOC "/ethernet@24000",
Gerald Van Baren213bf8c2007-03-31 12:23:51 -0400486 "mac-address",
Gerald Van Barenf35a53f2007-04-15 13:54:26 -0400487 fdt_set_eth0
Gerald Van Baren213bf8c2007-03-31 12:23:51 -0400488 },
Jerry Van Baren8be40442007-07-04 21:34:24 -0400489 { "/" OF_SOC "/ethernet@24000",
Gerald Van Baren213bf8c2007-03-31 12:23:51 -0400490 "local-mac-address",
Gerald Van Barenf35a53f2007-04-15 13:54:26 -0400491 fdt_set_eth0
Gerald Van Baren213bf8c2007-03-31 12:23:51 -0400492 },
493#endif
Kim Phillips255a35772007-05-16 16:52:19 -0500494#ifdef CONFIG_TSEC2
Jerry Van Baren8be40442007-07-04 21:34:24 -0400495 { "/" OF_SOC "/ethernet@25000",
Gerald Van Baren213bf8c2007-03-31 12:23:51 -0400496 "mac-address",
Gerald Van Barenf35a53f2007-04-15 13:54:26 -0400497 fdt_set_eth1
Gerald Van Baren213bf8c2007-03-31 12:23:51 -0400498 },
Jerry Van Baren8be40442007-07-04 21:34:24 -0400499 { "/" OF_SOC "/ethernet@25000",
Gerald Van Baren213bf8c2007-03-31 12:23:51 -0400500 "local-mac-address",
Gerald Van Barenf35a53f2007-04-15 13:54:26 -0400501 fdt_set_eth1
Gerald Van Baren213bf8c2007-03-31 12:23:51 -0400502 },
503#endif
Kim Phillips8f9e0e92007-08-15 22:30:19 -0500504#ifdef CONFIG_QE
505 { "/" OF_QE,
506 "brg-frequency",
507 fdt_set_qe_brgfreq
508 },
509 { "/" OF_QE,
510 "bus-frequency",
511 fdt_set_qe_busfreq
512 },
Gerald Van Barenf35a53f2007-04-15 13:54:26 -0400513#ifdef CONFIG_UEC_ETH1
514#if CFG_UEC1_UCC_NUM == 0 /* UCC1 */
Jerry Van Baren8be40442007-07-04 21:34:24 -0400515 { "/" OF_QE "/ucc@2000",
Gerald Van Barenf35a53f2007-04-15 13:54:26 -0400516 "mac-address",
517 fdt_set_eth0
518 },
Jerry Van Baren8be40442007-07-04 21:34:24 -0400519 { "/" OF_QE "/ucc@2000",
Gerald Van Barenf35a53f2007-04-15 13:54:26 -0400520 "local-mac-address",
521 fdt_set_eth0
522 },
Joakim Tjernlundccf21c32007-12-06 16:43:40 +0100523#elif CFG_UEC1_UCC_NUM == 1 /* UCC2 */
524 { "/" OF_QE "/ucc@3000",
525 "mac-address",
526 fdt_set_eth0
527 },
528 { "/" OF_QE "/ucc@3000",
529 "local-mac-address",
530 fdt_set_eth0
531 },
Gerald Van Barenf35a53f2007-04-15 13:54:26 -0400532#elif CFG_UEC1_UCC_NUM == 2 /* UCC3 */
Jerry Van Baren8be40442007-07-04 21:34:24 -0400533 { "/" OF_QE "/ucc@2200",
Gerald Van Barenf35a53f2007-04-15 13:54:26 -0400534 "mac-address",
535 fdt_set_eth0
536 },
Jerry Van Baren8be40442007-07-04 21:34:24 -0400537 { "/" OF_QE "/ucc@2200",
Gerald Van Barenf35a53f2007-04-15 13:54:26 -0400538 "local-mac-address",
539 fdt_set_eth0
540 },
Joakim Tjernlundccf21c32007-12-06 16:43:40 +0100541#elif CFG_UEC1_UCC_NUM == 3 /* UCC4 */
542 { "/" OF_QE "/ucc@3200",
543 "mac-address",
544 fdt_set_eth0
545 },
546 { "/" OF_QE "/ucc@3200",
547 "local-mac-address",
548 fdt_set_eth0
549 },
Gerald Van Barenf35a53f2007-04-15 13:54:26 -0400550#endif
Jerry Van Baren8be40442007-07-04 21:34:24 -0400551#endif /* CONFIG_UEC_ETH1 */
Gerald Van Barenf35a53f2007-04-15 13:54:26 -0400552#ifdef CONFIG_UEC_ETH2
Joakim Tjernlundccf21c32007-12-06 16:43:40 +0100553#if CFG_UEC2_UCC_NUM == 0 /* UCC1 */
554 { "/" OF_QE "/ucc@2000",
555 "mac-address",
556 fdt_set_eth1
557 },
558 { "/" OF_QE "/ucc@2000",
559 "local-mac-address",
560 fdt_set_eth1
561 },
562#elif CFG_UEC2_UCC_NUM == 1 /* UCC2 */
Jerry Van Baren8be40442007-07-04 21:34:24 -0400563 { "/" OF_QE "/ucc@3000",
Gerald Van Barenf35a53f2007-04-15 13:54:26 -0400564 "mac-address",
565 fdt_set_eth1
566 },
Jerry Van Baren8be40442007-07-04 21:34:24 -0400567 { "/" OF_QE "/ucc@3000",
Gerald Van Barenf35a53f2007-04-15 13:54:26 -0400568 "local-mac-address",
569 fdt_set_eth1
570 },
Joakim Tjernlundccf21c32007-12-06 16:43:40 +0100571#elif CFG_UEC2_UCC_NUM == 2 /* UCC3 */
572 { "/" OF_QE "/ucc@2200",
573 "mac-address",
574 fdt_set_eth1
575 },
576 { "/" OF_QE "/ucc@2200",
577 "local-mac-address",
578 fdt_set_eth1
579 },
Kim Phillipsf4b2ac52007-08-15 22:30:12 -0500580#elif CFG_UEC2_UCC_NUM == 3 /* UCC4 */
Jerry Van Baren8be40442007-07-04 21:34:24 -0400581 { "/" OF_QE "/ucc@3200",
Gerald Van Barenf35a53f2007-04-15 13:54:26 -0400582 "mac-address",
583 fdt_set_eth1
584 },
Jerry Van Baren8be40442007-07-04 21:34:24 -0400585 { "/" OF_QE "/ucc@3200",
Gerald Van Barenf35a53f2007-04-15 13:54:26 -0400586 "local-mac-address",
587 fdt_set_eth1
588 },
589#endif
Jerry Van Baren8be40442007-07-04 21:34:24 -0400590#endif /* CONFIG_UEC_ETH2 */
Joakim Tjernlundccf21c32007-12-06 16:43:40 +0100591#ifdef CONFIG_UEC_ETH3
592#if CFG_UEC3_UCC_NUM == 0 /* UCC1 */
593 { "/" OF_QE "/ucc@2000",
594 "mac-address",
595 fdt_set_eth2
596 },
597 { "/" OF_QE "/ucc@2000",
598 "local-mac-address",
599 fdt_set_eth2
600 },
601#elif CFG_UEC3_UCC_NUM == 1 /* UCC2 */
602 { "/" OF_QE "/ucc@3000",
603 "mac-address",
604 fdt_set_eth2
605 },
606 { "/" OF_QE "/ucc@3000",
607 "local-mac-address",
608 fdt_set_eth2
609 },
610#elif CFG_UEC3_UCC_NUM == 2 /* UCC3 */
611 { "/" OF_QE "/ucc@2200",
612 "mac-address",
613 fdt_set_eth2
614 },
615 { "/" OF_QE "/ucc@2200",
616 "local-mac-address",
617 fdt_set_eth2
618 },
619#elif CFG_UEC3_UCC_NUM == 3 /* UCC4 */
620 { "/" OF_QE "/ucc@3200",
621 "mac-address",
622 fdt_set_eth2
623 },
624 { "/" OF_QE "/ucc@3200",
625 "local-mac-address",
626 fdt_set_eth2
627 },
628#endif
629#endif /* CONFIG_UEC_ETH3 */
630#ifdef CONFIG_UEC_ETH4
631#if CFG_UEC4_UCC_NUM == 0 /* UCC1 */
632 { "/" OF_QE "/ucc@2000",
633 "mac-address",
634 fdt_set_eth3
635 },
636 { "/" OF_QE "/ucc@2000",
637 "local-mac-address",
638 fdt_set_eth3
639 },
640#elif CFG_UEC4_UCC_NUM == 1 /* UCC2 */
641 { "/" OF_QE "/ucc@3000",
642 "mac-address",
643 fdt_set_eth3
644 },
645 { "/" OF_QE "/ucc@3000",
646 "local-mac-address",
647 fdt_set_eth3
648 },
649#elif CFG_UEC4_UCC_NUM == 2 /* UCC3 */
650 { "/" OF_QE "/ucc@2200",
651 "mac-address",
652 fdt_set_eth3
653 },
654 { "/" OF_QE "/ucc@2200",
655 "local-mac-address",
656 fdt_set_eth3
657 },
658#elif CFG_UEC4_UCC_NUM == 3 /* UCC4 */
659 { "/" OF_QE "/ucc@3200",
660 "mac-address",
661 fdt_set_eth3
662 },
663 { "/" OF_QE "/ucc@3200",
664 "local-mac-address",
665 fdt_set_eth3
666 },
667#endif
668#endif /* CONFIG_UEC_ETH4 */
Kim Phillips8f9e0e92007-08-15 22:30:19 -0500669#endif /* CONFIG_QE */
Gerald Van Baren213bf8c2007-03-31 12:23:51 -0400670};
671
672void
673ft_cpu_setup(void *blob, bd_t *bd)
674{
Kim Phillips6a16e0d2007-08-15 22:30:26 -0500675 int nodeoffset;
676 int err;
677 int j;
Gerald Van Baren213bf8c2007-03-31 12:23:51 -0400678
679 for (j = 0; j < (sizeof(fixup_props) / sizeof(fixup_props[0])); j++) {
Kumar Gala8d04f022007-10-24 11:04:22 -0500680 nodeoffset = fdt_path_offset(blob, fixup_props[j].node);
Gerald Van Baren213bf8c2007-03-31 12:23:51 -0400681 if (nodeoffset >= 0) {
Jerry Van Baren8be40442007-07-04 21:34:24 -0400682 err = fixup_props[j].set_fn(blob, nodeoffset,
683 fixup_props[j].prop, bd);
Gerald Van Barenf35a53f2007-04-15 13:54:26 -0400684 if (err < 0)
Jerry Van Baren8be40442007-07-04 21:34:24 -0400685 debug("Problem setting %s = %s: %s\n",
Kim Phillips6a16e0d2007-08-15 22:30:26 -0500686 fixup_props[j].node, fixup_props[j].prop,
687 fdt_strerror(err));
Jerry Van Baren8be40442007-07-04 21:34:24 -0400688 } else {
689 debug("Couldn't find %s: %s\n",
Kim Phillips6a16e0d2007-08-15 22:30:26 -0500690 fixup_props[j].node, fdt_strerror(nodeoffset));
Gerald Van Baren213bf8c2007-03-31 12:23:51 -0400691 }
692 }
Kim Phillips6a16e0d2007-08-15 22:30:26 -0500693
Kumar Gala246d4ae2007-11-27 21:59:46 -0600694 fdt_fixup_memory(blob, (u64)bd->bi_memstart, (u64)bd->bi_memsize);
Gerald Van Baren213bf8c2007-03-31 12:23:51 -0400695}
Jerry Van Baren26d02c92007-07-04 21:27:30 -0400696#elif defined(CONFIG_OF_FLAT_TREE)
Kumar Gala62ec6412006-01-11 16:48:10 -0600697void
698ft_cpu_setup(void *blob, bd_t *bd)
699{
700 u32 *p;
701 int len;
702 ulong clock;
703
704 clock = bd->bi_busfreq;
705 p = ft_get_prop(blob, "/cpus/" OF_CPU "/bus-frequency", &len);
706 if (p != NULL)
707 *p = cpu_to_be32(clock);
708
709 p = ft_get_prop(blob, "/" OF_SOC "/bus-frequency", &len);
710 if (p != NULL)
711 *p = cpu_to_be32(clock);
712
713 p = ft_get_prop(blob, "/" OF_SOC "/serial@4500/clock-frequency", &len);
714 if (p != NULL)
715 *p = cpu_to_be32(clock);
716
717 p = ft_get_prop(blob, "/" OF_SOC "/serial@4600/clock-frequency", &len);
718 if (p != NULL)
719 *p = cpu_to_be32(clock);
720
Kim Phillips255a35772007-05-16 16:52:19 -0500721#ifdef CONFIG_TSEC1
Timur Tabi61f4f912007-02-13 10:41:42 -0600722 p = ft_get_prop(blob, "/" OF_SOC "/ethernet@24000/mac-address", &len);
723 if (p != NULL)
724 memcpy(p, bd->bi_enetaddr, 6);
725
Kim Phillips48041362006-11-01 00:07:25 -0600726 p = ft_get_prop(blob, "/" OF_SOC "/ethernet@24000/local-mac-address", &len);
Kim Phillipsb7004742007-01-30 16:15:21 -0600727 if (p != NULL)
Kumar Gala62ec6412006-01-11 16:48:10 -0600728 memcpy(p, bd->bi_enetaddr, 6);
729#endif
730
Kim Phillips255a35772007-05-16 16:52:19 -0500731#ifdef CONFIG_TSEC2
Timur Tabi61f4f912007-02-13 10:41:42 -0600732 p = ft_get_prop(blob, "/" OF_SOC "/ethernet@25000/mac-address", &len);
733 if (p != NULL)
734 memcpy(p, bd->bi_enet1addr, 6);
735
Kim Phillips48041362006-11-01 00:07:25 -0600736 p = ft_get_prop(blob, "/" OF_SOC "/ethernet@25000/local-mac-address", &len);
Kim Phillipsb7004742007-01-30 16:15:21 -0600737 if (p != NULL)
Kumar Gala62ec6412006-01-11 16:48:10 -0600738 memcpy(p, bd->bi_enet1addr, 6);
739#endif
Kim Phillipsd51b3cf2007-02-22 20:06:57 -0600740
741#ifdef CONFIG_UEC_ETH1
742#if CFG_UEC1_UCC_NUM == 0 /* UCC1 */
743 p = ft_get_prop(blob, "/" OF_QE "/ucc@2000/mac-address", &len);
744 if (p != NULL)
745 memcpy(p, bd->bi_enetaddr, 6);
746
747 p = ft_get_prop(blob, "/" OF_QE "/ucc@2000/local-mac-address", &len);
748 if (p != NULL)
749 memcpy(p, bd->bi_enetaddr, 6);
750#elif CFG_UEC1_UCC_NUM == 2 /* UCC3 */
751 p = ft_get_prop(blob, "/" OF_QE "/ucc@2200/mac-address", &len);
752 if (p != NULL)
753 memcpy(p, bd->bi_enetaddr, 6);
754
755 p = ft_get_prop(blob, "/" OF_QE "/ucc@2200/local-mac-address", &len);
756 if (p != NULL)
757 memcpy(p, bd->bi_enetaddr, 6);
758#endif
759#endif
760
761#ifdef CONFIG_UEC_ETH2
762#if CFG_UEC2_UCC_NUM == 1 /* UCC2 */
763 p = ft_get_prop(blob, "/" OF_QE "/ucc@3000/mac-address", &len);
764 if (p != NULL)
765 memcpy(p, bd->bi_enet1addr, 6);
766
767 p = ft_get_prop(blob, "/" OF_QE "/ucc@3000/local-mac-address", &len);
768 if (p != NULL)
769 memcpy(p, bd->bi_enet1addr, 6);
770#elif CFG_UEC2_UCC_NUM == 3 /* UCC4 */
771 p = ft_get_prop(blob, "/" OF_QE "/ucc@3200/mac-address", &len);
772 if (p != NULL)
773 memcpy(p, bd->bi_enet1addr, 6);
774
775 p = ft_get_prop(blob, "/" OF_QE "/ucc@3200/local-mac-address", &len);
776 if (p != NULL)
777 memcpy(p, bd->bi_enet1addr, 6);
778#endif
779#endif
Kumar Gala62ec6412006-01-11 16:48:10 -0600780}
781#endif
Marian Balakowicz61f25152006-03-14 16:14:48 +0100782
783#if defined(CONFIG_DDR_ECC)
784void dma_init(void)
785{
Timur Tabid239d742006-11-03 12:00:28 -0600786 volatile immap_t *immap = (immap_t *)CFG_IMMR;
Dave Liuf6eda7f2006-10-25 14:41:21 -0500787 volatile dma83xx_t *dma = &immap->dma;
Marian Balakowicz61f25152006-03-14 16:14:48 +0100788 volatile u32 status = swab32(dma->dmasr0);
789 volatile u32 dmamr0 = swab32(dma->dmamr0);
790
791 debug("DMA-init\n");
792
793 /* initialize DMASARn, DMADAR and DMAABCRn */
794 dma->dmadar0 = (u32)0;
795 dma->dmasar0 = (u32)0;
796 dma->dmabcr0 = 0;
797
798 __asm__ __volatile__ ("sync");
799 __asm__ __volatile__ ("isync");
800
801 /* clear CS bit */
802 dmamr0 &= ~DMA_CHANNEL_START;
803 dma->dmamr0 = swab32(dmamr0);
804 __asm__ __volatile__ ("sync");
805 __asm__ __volatile__ ("isync");
806
807 /* while the channel is busy, spin */
808 while(status & DMA_CHANNEL_BUSY) {
809 status = swab32(dma->dmasr0);
810 }
811
812 debug("DMA-init end\n");
813}
814
815uint dma_check(void)
816{
Timur Tabid239d742006-11-03 12:00:28 -0600817 volatile immap_t *immap = (immap_t *)CFG_IMMR;
Dave Liuf6eda7f2006-10-25 14:41:21 -0500818 volatile dma83xx_t *dma = &immap->dma;
Marian Balakowicz61f25152006-03-14 16:14:48 +0100819 volatile u32 status = swab32(dma->dmasr0);
820 volatile u32 byte_count = swab32(dma->dmabcr0);
821
822 /* while the channel is busy, spin */
823 while (status & DMA_CHANNEL_BUSY) {
824 status = swab32(dma->dmasr0);
825 }
826
827 if (status & DMA_CHANNEL_TRANSFER_ERROR) {
828 printf ("DMA Error: status = %x @ %d\n", status, byte_count);
829 }
830
831 return status;
832}
833
834int dma_xfer(void *dest, u32 count, void *src)
835{
Timur Tabid239d742006-11-03 12:00:28 -0600836 volatile immap_t *immap = (immap_t *)CFG_IMMR;
Dave Liuf6eda7f2006-10-25 14:41:21 -0500837 volatile dma83xx_t *dma = &immap->dma;
Marian Balakowicz61f25152006-03-14 16:14:48 +0100838 volatile u32 dmamr0;
839
840 /* initialize DMASARn, DMADAR and DMAABCRn */
841 dma->dmadar0 = swab32((u32)dest);
842 dma->dmasar0 = swab32((u32)src);
843 dma->dmabcr0 = swab32(count);
844
845 __asm__ __volatile__ ("sync");
846 __asm__ __volatile__ ("isync");
847
848 /* init direct transfer, clear CS bit */
849 dmamr0 = (DMA_CHANNEL_TRANSFER_MODE_DIRECT |
850 DMA_CHANNEL_SOURCE_ADDRESS_HOLD_8B |
851 DMA_CHANNEL_SOURCE_ADRESSS_HOLD_EN);
Wolfgang Denkcf48eb92006-04-16 10:51:58 +0200852
Marian Balakowicz61f25152006-03-14 16:14:48 +0100853 dma->dmamr0 = swab32(dmamr0);
854
855 __asm__ __volatile__ ("sync");
856 __asm__ __volatile__ ("isync");
857
858 /* set CS to start DMA transfer */
859 dmamr0 |= DMA_CHANNEL_START;
860 dma->dmamr0 = swab32(dmamr0);
861 __asm__ __volatile__ ("sync");
862 __asm__ __volatile__ ("isync");
863
864 return ((int)dma_check());
865}
866#endif /*CONFIG_DDR_ECC*/