blob: b90871d22c8bff6a06d20426854df7fb2132f785 [file] [log] [blame]
wdenk42d1f032003-10-15 23:53:47 +00001/*
Andy Fleming1ced1212008-02-06 01:19:40 -06002 * Copyright 2004,2007,2008 Freescale Semiconductor, Inc.
wdenk42d1f032003-10-15 23:53:47 +00003 * (C) Copyright 2002, 2003 Motorola Inc.
4 * Xianghua Xiao (X.Xiao@motorola.com)
5 *
6 * (C) Copyright 2000
7 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
8 *
9 * See file CREDITS for list of people who contributed to this
10 * project.
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License as
14 * published by the Free Software Foundation; either version 2 of
15 * the License, or (at your option) any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
25 * MA 02111-1307 USA
26 */
27
Andy Fleming75b9d4a2008-08-31 16:33:26 -050028#include <config.h>
wdenk42d1f032003-10-15 23:53:47 +000029#include <common.h>
30#include <watchdog.h>
31#include <command.h>
Andy Fleming75b9d4a2008-08-31 16:33:26 -050032#include <tsec.h>
wdenk42d1f032003-10-15 23:53:47 +000033#include <asm/cache.h>
Sergei Poselenov740280e2008-06-06 15:42:40 +020034#include <asm/io.h>
wdenk42d1f032003-10-15 23:53:47 +000035
James Yang591933c2008-02-08 16:44:53 -060036DECLARE_GLOBAL_DATA_PTR;
37
Andy Fleming1ced1212008-02-06 01:19:40 -060038struct cpu_type cpu_type_list [] = {
Kumar Gala4dbdb762008-06-10 16:53:46 -050039 CPU_TYPE_ENTRY(8533, 8533),
40 CPU_TYPE_ENTRY(8533, 8533_E),
Kumar Galaef50d6c2008-08-12 11:14:19 -050041 CPU_TYPE_ENTRY(8536, 8536),
42 CPU_TYPE_ENTRY(8536, 8536_E),
Kumar Gala4dbdb762008-06-10 16:53:46 -050043 CPU_TYPE_ENTRY(8540, 8540),
44 CPU_TYPE_ENTRY(8541, 8541),
45 CPU_TYPE_ENTRY(8541, 8541_E),
46 CPU_TYPE_ENTRY(8543, 8543),
47 CPU_TYPE_ENTRY(8543, 8543_E),
48 CPU_TYPE_ENTRY(8544, 8544),
49 CPU_TYPE_ENTRY(8544, 8544_E),
50 CPU_TYPE_ENTRY(8545, 8545),
51 CPU_TYPE_ENTRY(8545, 8545_E),
52 CPU_TYPE_ENTRY(8547, 8547_E),
53 CPU_TYPE_ENTRY(8548, 8548),
54 CPU_TYPE_ENTRY(8548, 8548_E),
55 CPU_TYPE_ENTRY(8555, 8555),
56 CPU_TYPE_ENTRY(8555, 8555_E),
57 CPU_TYPE_ENTRY(8560, 8560),
58 CPU_TYPE_ENTRY(8567, 8567),
59 CPU_TYPE_ENTRY(8567, 8567_E),
60 CPU_TYPE_ENTRY(8568, 8568),
61 CPU_TYPE_ENTRY(8568, 8568_E),
62 CPU_TYPE_ENTRY(8572, 8572),
63 CPU_TYPE_ENTRY(8572, 8572_E),
Andy Fleming1ced1212008-02-06 01:19:40 -060064};
65
Anatolij Gustschin96026d42008-06-12 12:40:11 +020066struct cpu_type *identify_cpu(u32 ver)
Kumar Gala4dbdb762008-06-10 16:53:46 -050067{
68 int i;
69 for (i = 0; i < ARRAY_SIZE(cpu_type_list); i++)
70 if (cpu_type_list[i].soc_ver == ver)
71 return &cpu_type_list[i];
72
73 return NULL;
74}
75
wdenk42d1f032003-10-15 23:53:47 +000076int checkcpu (void)
77{
wdenk97d80fc2004-06-09 00:34:46 +000078 sys_info_t sysinfo;
79 uint lcrr; /* local bus clock ratio register */
80 uint clkdiv; /* clock divider portion of lcrr */
81 uint pvr, svr;
Jon Loeligerd9b94f22005-07-25 14:05:07 -050082 uint fam;
wdenk97d80fc2004-06-09 00:34:46 +000083 uint ver;
84 uint major, minor;
Kumar Gala4dbdb762008-06-10 16:53:46 -050085 struct cpu_type *cpu;
Wolfgang Denk08ef89e2008-10-19 02:35:49 +020086 char buf1[32], buf2[32];
Kumar Galaee1e35b2008-05-29 01:21:24 -050087#ifdef CONFIG_DDR_CLK_FREQ
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020088 volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
Jason Jinc0391112008-09-27 14:40:57 +080089 u32 ddr_ratio = ((gur->porpllsr) & MPC85xx_PORPLLSR_DDR_RATIO)
90 >> MPC85xx_PORPLLSR_DDR_RATIO_SHIFT;
Kumar Galaee1e35b2008-05-29 01:21:24 -050091#else
92 u32 ddr_ratio = 0;
93#endif
wdenk42d1f032003-10-15 23:53:47 +000094
wdenk97d80fc2004-06-09 00:34:46 +000095 svr = get_svr();
Andy Fleming1ced1212008-02-06 01:19:40 -060096 ver = SVR_SOC_VER(svr);
wdenk97d80fc2004-06-09 00:34:46 +000097 major = SVR_MAJ(svr);
Kumar Galaef50d6c2008-08-12 11:14:19 -050098#ifdef CONFIG_MPC8536
99 major &= 0x7; /* the msb of this nibble is a mfg code */
100#endif
wdenk97d80fc2004-06-09 00:34:46 +0000101 minor = SVR_MIN(svr);
102
Ed Swarthout6856b3d2008-10-08 23:37:59 -0500103#if (CONFIG_NUM_CPUS > 1)
104 volatile ccsr_pic_t *pic = (void *)(CONFIG_SYS_MPC85xx_PIC_ADDR);
105 printf("CPU%d: ", pic->whoami);
106#else
wdenk6c9e7892005-03-15 22:56:53 +0000107 puts("CPU: ");
Ed Swarthout6856b3d2008-10-08 23:37:59 -0500108#endif
Andy Fleming1ced1212008-02-06 01:19:40 -0600109
Kumar Gala4dbdb762008-06-10 16:53:46 -0500110 cpu = identify_cpu(ver);
111 if (cpu) {
112 puts(cpu->name);
Andy Fleming1ced1212008-02-06 01:19:40 -0600113
Kim Phillips06b41862008-06-17 17:45:22 -0500114 if (IS_E_PROCESSOR(svr))
Kumar Gala4dbdb762008-06-10 16:53:46 -0500115 puts("E");
116 } else {
wdenk97d80fc2004-06-09 00:34:46 +0000117 puts("Unknown");
Kumar Gala4dbdb762008-06-10 16:53:46 -0500118 }
Andy Fleming1ced1212008-02-06 01:19:40 -0600119
wdenk97d80fc2004-06-09 00:34:46 +0000120 printf(", Version: %d.%d, (0x%08x)\n", major, minor, svr);
wdenk42d1f032003-10-15 23:53:47 +0000121
wdenk6c9e7892005-03-15 22:56:53 +0000122 pvr = get_pvr();
Jon Loeligerd9b94f22005-07-25 14:05:07 -0500123 fam = PVR_FAM(pvr);
wdenk6c9e7892005-03-15 22:56:53 +0000124 ver = PVR_VER(pvr);
125 major = PVR_MAJ(pvr);
126 minor = PVR_MIN(pvr);
127
128 printf("Core: ");
Jon Loeligerd9b94f22005-07-25 14:05:07 -0500129 switch (fam) {
130 case PVR_FAM(PVR_85xx):
wdenk6c9e7892005-03-15 22:56:53 +0000131 puts("E500");
132 break;
133 default:
134 puts("Unknown");
135 break;
136 }
Kumar Gala0f060c32008-10-23 01:47:38 -0500137
138 if (PVR_MEM(pvr) == 0x03)
139 puts("MC");
140
wdenk6c9e7892005-03-15 22:56:53 +0000141 printf(", Version: %d.%d, (0x%08x)\n", major, minor, pvr);
142
wdenk97d80fc2004-06-09 00:34:46 +0000143 get_sys_info(&sysinfo);
144
Jon Loeligerd9b94f22005-07-25 14:05:07 -0500145 puts("Clock Configuration:\n");
Wolfgang Denk08ef89e2008-10-19 02:35:49 +0200146 printf(" CPU:%-4s MHz, ", strmhz(buf1, sysinfo.freqProcessor));
147 printf("CCB:%-4s MHz,\n", strmhz(buf1, sysinfo.freqSystemBus));
Kumar Galaee1e35b2008-05-29 01:21:24 -0500148
Kumar Galad4357932007-12-07 04:59:26 -0600149 switch (ddr_ratio) {
150 case 0x0:
Wolfgang Denk08ef89e2008-10-19 02:35:49 +0200151 printf(" DDR:%-4s MHz (%s MT/s data rate), ",
152 strmhz(buf1, sysinfo.freqDDRBus/2),
153 strmhz(buf2, sysinfo.freqDDRBus));
Kumar Galad4357932007-12-07 04:59:26 -0600154 break;
155 case 0x7:
Wolfgang Denk08ef89e2008-10-19 02:35:49 +0200156 printf(" DDR:%-4s MHz (%s MT/s data rate) (Synchronous), ",
157 strmhz(buf1, sysinfo.freqDDRBus/2),
158 strmhz(buf2, sysinfo.freqDDRBus));
Kumar Galad4357932007-12-07 04:59:26 -0600159 break;
160 default:
Wolfgang Denk08ef89e2008-10-19 02:35:49 +0200161 printf(" DDR:%-4s MHz (%s MT/s data rate) (Asynchronous), ",
162 strmhz(buf1, sysinfo.freqDDRBus/2),
163 strmhz(buf2, sysinfo.freqDDRBus));
Kumar Galad4357932007-12-07 04:59:26 -0600164 break;
165 }
wdenk97d80fc2004-06-09 00:34:46 +0000166
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200167#if defined(CONFIG_SYS_LBC_LCRR)
168 lcrr = CONFIG_SYS_LBC_LCRR;
wdenk97d80fc2004-06-09 00:34:46 +0000169#else
170 {
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200171 volatile ccsr_lbc_t *lbc = (void *)(CONFIG_SYS_MPC85xx_LBC_ADDR);
wdenk97d80fc2004-06-09 00:34:46 +0000172
173 lcrr = lbc->lcrr;
174 }
175#endif
176 clkdiv = lcrr & 0x0f;
177 if (clkdiv == 2 || clkdiv == 4 || clkdiv == 8) {
Kumar Galaef50d6c2008-08-12 11:14:19 -0500178#if defined(CONFIG_MPC8548) || defined(CONFIG_MPC8544) || \
179 defined(CONFIG_MPC8572) || defined(CONFIG_MPC8536)
Jon Loeligerd9b94f22005-07-25 14:05:07 -0500180 /*
181 * Yes, the entire PQ38 family use the same
182 * bit-representation for twice the clock divider values.
183 */
184 clkdiv *= 2;
185#endif
Wolfgang Denk08ef89e2008-10-19 02:35:49 +0200186 printf("LBC:%-4s MHz\n",
187 strmhz(buf1, sysinfo.freqSystemBus / clkdiv));
wdenk97d80fc2004-06-09 00:34:46 +0000188 } else {
wdenk6c9e7892005-03-15 22:56:53 +0000189 printf("LBC: unknown (lcrr: 0x%08x)\n", lcrr);
wdenk97d80fc2004-06-09 00:34:46 +0000190 }
191
Andy Fleming1ced1212008-02-06 01:19:40 -0600192#ifdef CONFIG_CPM2
Wolfgang Denk08ef89e2008-10-19 02:35:49 +0200193 printf("CPM: %s MHz\n", strmhz(buf1, sysinfo.freqSystemBus));
Andy Fleming1ced1212008-02-06 01:19:40 -0600194#endif
wdenk97d80fc2004-06-09 00:34:46 +0000195
wdenk6c9e7892005-03-15 22:56:53 +0000196 puts("L1: D-cache 32 kB enabled\n I-cache 32 kB enabled\n");
wdenk42d1f032003-10-15 23:53:47 +0000197
198 return 0;
199}
200
201
202/* ------------------------------------------------------------------------- */
203
204int do_reset (cmd_tbl_t *cmdtp, bd_t *bd, int flag, int argc, char *argv[])
205{
Zang Roy-r6191196629cb2006-12-05 16:42:30 +0800206 uint pvr;
207 uint ver;
Sergei Poselenov793670c2008-05-08 14:17:08 +0200208 unsigned long val, msr;
209
Zang Roy-r6191196629cb2006-12-05 16:42:30 +0800210 pvr = get_pvr();
211 ver = PVR_VER(pvr);
Sergei Poselenov793670c2008-05-08 14:17:08 +0200212
Zang Roy-r6191196629cb2006-12-05 16:42:30 +0800213 if (ver & 1){
214 /* e500 v2 core has reset control register */
215 volatile unsigned int * rstcr;
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200216 rstcr = (volatile unsigned int *)(CONFIG_SYS_IMMR + 0xE00B0);
Wolfgang Denk2f152782007-05-05 18:23:11 +0200217 *rstcr = 0x2; /* HRESET_REQ */
Sergei Poselenov793670c2008-05-08 14:17:08 +0200218 udelay(100);
219 }
220
wdenk42d1f032003-10-15 23:53:47 +0000221 /*
Sergei Poselenov793670c2008-05-08 14:17:08 +0200222 * Fallthrough if the code above failed
wdenk42d1f032003-10-15 23:53:47 +0000223 * Initiate hard reset in debug control register DBCR0
224 * Make sure MSR[DE] = 1
225 */
urwithsughosh@gmail.comdf909682007-09-24 13:32:13 -0400226
Sergei Poselenov793670c2008-05-08 14:17:08 +0200227 msr = mfmsr ();
228 msr |= MSR_DE;
229 mtmsr (msr);
urwithsughosh@gmail.comdf909682007-09-24 13:32:13 -0400230
Sergei Poselenov793670c2008-05-08 14:17:08 +0200231 val = mfspr(DBCR0);
232 val |= 0x70000000;
233 mtspr(DBCR0,val);
234
wdenk42d1f032003-10-15 23:53:47 +0000235 return 1;
236}
237
238
239/*
240 * Get timebase clock frequency
241 */
242unsigned long get_tbclk (void)
243{
James Yang591933c2008-02-08 16:44:53 -0600244 return (gd->bus_clk + 4UL)/8UL;
wdenk42d1f032003-10-15 23:53:47 +0000245}
246
247
248#if defined(CONFIG_WATCHDOG)
249void
250watchdog_reset(void)
251{
252 int re_enable = disable_interrupts();
253 reset_85xx_watchdog();
254 if (re_enable) enable_interrupts();
255}
256
257void
258reset_85xx_watchdog(void)
259{
260 /*
261 * Clear TSR(WIS) bit by writing 1
262 */
263 unsigned long val;
Andy Fleming03b81b42007-04-23 01:44:44 -0500264 val = mfspr(SPRN_TSR);
265 val |= TSR_WIS;
266 mtspr(SPRN_TSR, val);
wdenk42d1f032003-10-15 23:53:47 +0000267}
268#endif /* CONFIG_WATCHDOG */
269
270#if defined(CONFIG_DDR_ECC)
wdenk42d1f032003-10-15 23:53:47 +0000271void dma_init(void) {
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200272 volatile ccsr_dma_t *dma = (void *)(CONFIG_SYS_MPC85xx_DMA_ADDR);
wdenk42d1f032003-10-15 23:53:47 +0000273
274 dma->satr0 = 0x02c40000;
275 dma->datr0 = 0x02c40000;
Andy Fleming03b81b42007-04-23 01:44:44 -0500276 dma->sr0 = 0xfffffff; /* clear any errors */
wdenk42d1f032003-10-15 23:53:47 +0000277 asm("sync; isync; msync");
278 return;
279}
280
281uint dma_check(void) {
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200282 volatile ccsr_dma_t *dma = (void *)(CONFIG_SYS_MPC85xx_DMA_ADDR);
wdenk42d1f032003-10-15 23:53:47 +0000283 volatile uint status = dma->sr0;
284
285 /* While the channel is busy, spin */
286 while((status & 4) == 4) {
287 status = dma->sr0;
288 }
289
Andy Fleming03b81b42007-04-23 01:44:44 -0500290 /* clear MR0[CS] channel start bit */
291 dma->mr0 &= 0x00000001;
292 asm("sync;isync;msync");
293
wdenk42d1f032003-10-15 23:53:47 +0000294 if (status != 0) {
295 printf ("DMA Error: status = %x\n", status);
296 }
297 return status;
298}
299
300int dma_xfer(void *dest, uint count, void *src) {
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200301 volatile ccsr_dma_t *dma = (void *)(CONFIG_SYS_MPC85xx_DMA_ADDR);
wdenk42d1f032003-10-15 23:53:47 +0000302
303 dma->dar0 = (uint) dest;
304 dma->sar0 = (uint) src;
305 dma->bcr0 = count;
306 dma->mr0 = 0xf000004;
307 asm("sync;isync;msync");
308 dma->mr0 = 0xf000005;
309 asm("sync;isync;msync");
310 return dma_check();
311}
312#endif
Andy Fleming75b9d4a2008-08-31 16:33:26 -0500313
Sergei Poselenov740280e2008-06-06 15:42:40 +0200314/*
Sergei Poselenov59f63052008-08-15 15:42:11 +0200315 * Configures a UPM. The function requires the respective MxMR to be set
316 * before calling this function. "size" is the number or entries, not a sizeof.
Sergei Poselenov740280e2008-06-06 15:42:40 +0200317 */
318void upmconfig (uint upm, uint * table, uint size)
319{
320 int i, mdr, mad, old_mad = 0;
321 volatile u32 *mxmr;
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200322 volatile ccsr_lbc_t *lbc = (void *)(CONFIG_SYS_MPC85xx_LBC_ADDR);
Sergei Poselenov740280e2008-06-06 15:42:40 +0200323 volatile u32 *brp,*orp;
324 volatile u8* dummy = NULL;
325 int upmmask;
326
327 switch (upm) {
328 case UPMA:
329 mxmr = &lbc->mamr;
330 upmmask = BR_MS_UPMA;
331 break;
332 case UPMB:
333 mxmr = &lbc->mbmr;
334 upmmask = BR_MS_UPMB;
335 break;
336 case UPMC:
337 mxmr = &lbc->mcmr;
338 upmmask = BR_MS_UPMC;
339 break;
340 default:
341 printf("%s: Bad UPM index %d to configure\n", __FUNCTION__, upm);
342 hang();
343 }
344
345 /* Find the address for the dummy write transaction */
346 for (brp = &lbc->br0, orp = &lbc->or0, i = 0; i < 8;
347 i++, brp += 2, orp += 2) {
Wolfgang Denke093a242008-06-28 23:34:37 +0200348
Sergei Poselenov740280e2008-06-06 15:42:40 +0200349 /* Look for a valid BR with selected UPM */
Sergei Poselenov59f63052008-08-15 15:42:11 +0200350 if ((in_be32(brp) & (BR_V | BR_MSEL)) == (BR_V | upmmask)) {
351 dummy = (volatile u8*)(in_be32(brp) & BR_BA);
Sergei Poselenov740280e2008-06-06 15:42:40 +0200352 break;
353 }
354 }
355
356 if (i == 8) {
357 printf("Error: %s() could not find matching BR\n", __FUNCTION__);
358 hang();
359 }
360
361 for (i = 0; i < size; i++) {
362 /* 1 */
Sergei Poselenov59f63052008-08-15 15:42:11 +0200363 out_be32(mxmr, (in_be32(mxmr) & 0x4fffffc0) | MxMR_OP_WARR | i);
Sergei Poselenov740280e2008-06-06 15:42:40 +0200364 /* 2 */
365 out_be32(&lbc->mdr, table[i]);
366 /* 3 */
367 mdr = in_be32(&lbc->mdr);
368 /* 4 */
369 *(volatile u8 *)dummy = 0;
370 /* 5 */
371 do {
Sergei Poselenov59f63052008-08-15 15:42:11 +0200372 mad = in_be32(mxmr) & MxMR_MAD_MSK;
Sergei Poselenov740280e2008-06-06 15:42:40 +0200373 } while (mad <= old_mad && !(!mad && i == (size-1)));
374 old_mad = mad;
375 }
Sergei Poselenov59f63052008-08-15 15:42:11 +0200376 out_be32(mxmr, (in_be32(mxmr) & 0x4fffffc0) | MxMR_OP_NORM);
Sergei Poselenov740280e2008-06-06 15:42:40 +0200377}
Ben Warrendd354792008-06-23 22:57:27 -0700378
Andy Fleming75b9d4a2008-08-31 16:33:26 -0500379
380/*
381 * Initializes on-chip ethernet controllers.
382 * to override, implement board_eth_init()
Ben Warrendd354792008-06-23 22:57:27 -0700383 */
Ben Warrendd354792008-06-23 22:57:27 -0700384int cpu_eth_init(bd_t *bis)
385{
Ben Warren62e15b42008-10-30 22:15:35 -0700386#if defined(CONFIG_TSEC_ENET) || defined(CONFIG_MPC85XX_FEC)
Andy Fleming75b9d4a2008-08-31 16:33:26 -0500387 tsec_standard_init(bis);
Ben Warrendd354792008-06-23 22:57:27 -0700388#endif
Andy Fleming75b9d4a2008-08-31 16:33:26 -0500389
Ben Warrendd354792008-06-23 22:57:27 -0700390 return 0;
391}