blob: d585e87995be9bbe3d2c2be07d3dbffab71081f8 [file] [log] [blame]
wdenk9c53f402003-10-15 23:53:47 +00001/*
Andy Flemingf5740972008-02-06 01:19:40 -06002 * Copyright 2004,2007,2008 Freescale Semiconductor, Inc.
wdenk9c53f402003-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
28#include <common.h>
29#include <watchdog.h>
30#include <command.h>
31#include <asm/cache.h>
32
James Yang957b1912008-02-08 16:44:53 -060033DECLARE_GLOBAL_DATA_PTR;
34
Kumar Gala8ddf00c2008-06-10 16:53:46 -050035struct cpu_type cpu_type_list [] = {
36 CPU_TYPE_ENTRY(8533, 8533),
37 CPU_TYPE_ENTRY(8533, 8533_E),
38 CPU_TYPE_ENTRY(8540, 8540),
39 CPU_TYPE_ENTRY(8541, 8541),
40 CPU_TYPE_ENTRY(8541, 8541_E),
41 CPU_TYPE_ENTRY(8543, 8543),
42 CPU_TYPE_ENTRY(8543, 8543_E),
43 CPU_TYPE_ENTRY(8544, 8544),
44 CPU_TYPE_ENTRY(8544, 8544_E),
45 CPU_TYPE_ENTRY(8545, 8545),
46 CPU_TYPE_ENTRY(8545, 8545_E),
47 CPU_TYPE_ENTRY(8547, 8547_E),
48 CPU_TYPE_ENTRY(8548, 8548),
49 CPU_TYPE_ENTRY(8548, 8548_E),
50 CPU_TYPE_ENTRY(8555, 8555),
51 CPU_TYPE_ENTRY(8555, 8555_E),
52 CPU_TYPE_ENTRY(8560, 8560),
53 CPU_TYPE_ENTRY(8567, 8567),
54 CPU_TYPE_ENTRY(8567, 8567_E),
55 CPU_TYPE_ENTRY(8568, 8568),
56 CPU_TYPE_ENTRY(8568, 8568_E),
57 CPU_TYPE_ENTRY(8572, 8572),
58 CPU_TYPE_ENTRY(8572, 8572_E),
Andy Flemingf5740972008-02-06 01:19:40 -060059};
60
Kumar Gala8ddf00c2008-06-10 16:53:46 -050061struct cpu_type *identify_cpu(uint ver)
62{
63 int i;
64 for (i = 0; i < ARRAY_SIZE(cpu_type_list); i++)
65 if (cpu_type_list[i].soc_ver == ver)
66 return &cpu_type_list[i];
Andy Flemingf5740972008-02-06 01:19:40 -060067
Kumar Gala8ddf00c2008-06-10 16:53:46 -050068 return NULL;
69}
Andy Flemingf5740972008-02-06 01:19:40 -060070
wdenk9c53f402003-10-15 23:53:47 +000071int checkcpu (void)
72{
wdenka445ddf2004-06-09 00:34:46 +000073 sys_info_t sysinfo;
74 uint lcrr; /* local bus clock ratio register */
75 uint clkdiv; /* clock divider portion of lcrr */
76 uint pvr, svr;
Jon Loeliger77a4f6e2005-07-25 14:05:07 -050077 uint fam;
wdenka445ddf2004-06-09 00:34:46 +000078 uint ver;
79 uint major, minor;
Kumar Gala8ddf00c2008-06-10 16:53:46 -050080 struct cpu_type *cpu;
Kumar Gala54b68102008-05-29 01:21:24 -050081#ifdef CONFIG_DDR_CLK_FREQ
Kumar Gala07db1702007-12-07 04:59:26 -060082 volatile ccsr_gur_t *gur = (void *)(CFG_MPC85xx_GUTS_ADDR);
Kumar Gala54b68102008-05-29 01:21:24 -050083 u32 ddr_ratio = ((gur->porpllsr) & 0x00003e00) >> 9;
84#else
85 u32 ddr_ratio = 0;
86#endif
wdenk9c53f402003-10-15 23:53:47 +000087
wdenka445ddf2004-06-09 00:34:46 +000088 svr = get_svr();
Andy Flemingf5740972008-02-06 01:19:40 -060089 ver = SVR_SOC_VER(svr);
wdenka445ddf2004-06-09 00:34:46 +000090 major = SVR_MAJ(svr);
91 minor = SVR_MIN(svr);
92
wdenk3f3262b2005-03-15 22:56:53 +000093 puts("CPU: ");
Andy Flemingf5740972008-02-06 01:19:40 -060094
Kumar Gala8ddf00c2008-06-10 16:53:46 -050095 cpu = identify_cpu(ver);
96 if (cpu) {
97 puts(cpu->name);
Andy Flemingf5740972008-02-06 01:19:40 -060098
Kumar Gala8ddf00c2008-06-10 16:53:46 -050099 if (svr & 0x80000)
100 puts("E");
101 } else {
wdenka445ddf2004-06-09 00:34:46 +0000102 puts("Unknown");
Kumar Gala8ddf00c2008-06-10 16:53:46 -0500103 }
Andy Flemingf5740972008-02-06 01:19:40 -0600104
wdenka445ddf2004-06-09 00:34:46 +0000105 printf(", Version: %d.%d, (0x%08x)\n", major, minor, svr);
wdenk9c53f402003-10-15 23:53:47 +0000106
wdenk3f3262b2005-03-15 22:56:53 +0000107 pvr = get_pvr();
Jon Loeliger77a4f6e2005-07-25 14:05:07 -0500108 fam = PVR_FAM(pvr);
wdenk3f3262b2005-03-15 22:56:53 +0000109 ver = PVR_VER(pvr);
110 major = PVR_MAJ(pvr);
111 minor = PVR_MIN(pvr);
112
113 printf("Core: ");
Jon Loeliger77a4f6e2005-07-25 14:05:07 -0500114 switch (fam) {
115 case PVR_FAM(PVR_85xx):
wdenk3f3262b2005-03-15 22:56:53 +0000116 puts("E500");
117 break;
118 default:
119 puts("Unknown");
120 break;
121 }
122 printf(", Version: %d.%d, (0x%08x)\n", major, minor, pvr);
123
wdenka445ddf2004-06-09 00:34:46 +0000124 get_sys_info(&sysinfo);
125
Jon Loeliger77a4f6e2005-07-25 14:05:07 -0500126 puts("Clock Configuration:\n");
Kumar Gala93d5ffb2008-04-21 09:28:36 -0500127 printf(" CPU:%4lu MHz, ", DIV_ROUND_UP(sysinfo.freqProcessor,1000000));
128 printf("CCB:%4lu MHz,\n", DIV_ROUND_UP(sysinfo.freqSystemBus,1000000));
Kumar Gala54b68102008-05-29 01:21:24 -0500129
Kumar Gala07db1702007-12-07 04:59:26 -0600130 switch (ddr_ratio) {
131 case 0x0:
James Yang5dab4842008-02-08 16:46:27 -0600132 printf(" DDR:%4lu MHz (%lu MT/s data rate), ",
Kumar Gala93d5ffb2008-04-21 09:28:36 -0500133 DIV_ROUND_UP(sysinfo.freqDDRBus,2000000), DIV_ROUND_UP(sysinfo.freqDDRBus,1000000));
Kumar Gala07db1702007-12-07 04:59:26 -0600134 break;
135 case 0x7:
James Yang5dab4842008-02-08 16:46:27 -0600136 printf(" DDR:%4lu MHz (%lu MT/s data rate) (Synchronous), ",
Kumar Gala93d5ffb2008-04-21 09:28:36 -0500137 DIV_ROUND_UP(sysinfo.freqDDRBus, 2000000), DIV_ROUND_UP(sysinfo.freqDDRBus, 1000000));
Kumar Gala07db1702007-12-07 04:59:26 -0600138 break;
139 default:
James Yang5dab4842008-02-08 16:46:27 -0600140 printf(" DDR:%4lu MHz (%lu MT/s data rate) (Asynchronous), ",
Kumar Gala93d5ffb2008-04-21 09:28:36 -0500141 DIV_ROUND_UP(sysinfo.freqDDRBus, 2000000), DIV_ROUND_UP(sysinfo.freqDDRBus,1000000));
Kumar Gala07db1702007-12-07 04:59:26 -0600142 break;
143 }
wdenka445ddf2004-06-09 00:34:46 +0000144
145#if defined(CFG_LBC_LCRR)
146 lcrr = CFG_LBC_LCRR;
147#else
148 {
Kumar Gala0a7a0972007-11-29 02:10:09 -0600149 volatile ccsr_lbc_t *lbc = (void *)(CFG_MPC85xx_LBC_ADDR);
wdenka445ddf2004-06-09 00:34:46 +0000150
151 lcrr = lbc->lcrr;
152 }
153#endif
154 clkdiv = lcrr & 0x0f;
155 if (clkdiv == 2 || clkdiv == 4 || clkdiv == 8) {
Andy Flemingf631cca2007-04-23 01:32:22 -0500156#if defined(CONFIG_MPC8548) || defined(CONFIG_MPC8544)
Jon Loeliger77a4f6e2005-07-25 14:05:07 -0500157 /*
158 * Yes, the entire PQ38 family use the same
159 * bit-representation for twice the clock divider values.
160 */
161 clkdiv *= 2;
162#endif
wdenka445ddf2004-06-09 00:34:46 +0000163 printf("LBC:%4lu MHz\n",
Kumar Gala93d5ffb2008-04-21 09:28:36 -0500164 DIV_ROUND_UP(sysinfo.freqSystemBus, 1000000) / clkdiv);
wdenka445ddf2004-06-09 00:34:46 +0000165 } else {
wdenk3f3262b2005-03-15 22:56:53 +0000166 printf("LBC: unknown (lcrr: 0x%08x)\n", lcrr);
wdenka445ddf2004-06-09 00:34:46 +0000167 }
168
Andy Flemingf5740972008-02-06 01:19:40 -0600169#ifdef CONFIG_CPM2
170 printf("CPM: %lu Mhz\n", sysinfo.freqSystemBus / 1000000);
171#endif
wdenka445ddf2004-06-09 00:34:46 +0000172
wdenk3f3262b2005-03-15 22:56:53 +0000173 puts("L1: D-cache 32 kB enabled\n I-cache 32 kB enabled\n");
wdenk9c53f402003-10-15 23:53:47 +0000174
175 return 0;
176}
177
178
179/* ------------------------------------------------------------------------- */
180
181int do_reset (cmd_tbl_t *cmdtp, bd_t *bd, int flag, int argc, char *argv[])
182{
Zang Roy-r61911395478d2006-12-05 16:42:30 +0800183 uint pvr;
184 uint ver;
Sergei Poselenov25147422008-05-08 14:17:08 +0200185 unsigned long val, msr;
186
Zang Roy-r61911395478d2006-12-05 16:42:30 +0800187 pvr = get_pvr();
188 ver = PVR_VER(pvr);
Sergei Poselenov25147422008-05-08 14:17:08 +0200189
Zang Roy-r61911395478d2006-12-05 16:42:30 +0800190 if (ver & 1){
191 /* e500 v2 core has reset control register */
192 volatile unsigned int * rstcr;
193 rstcr = (volatile unsigned int *)(CFG_IMMR + 0xE00B0);
Wolfgang Denk58c495b2007-05-05 18:23:11 +0200194 *rstcr = 0x2; /* HRESET_REQ */
Sergei Poselenov25147422008-05-08 14:17:08 +0200195 udelay(100);
196 }
197
wdenk9c53f402003-10-15 23:53:47 +0000198 /*
Sergei Poselenov25147422008-05-08 14:17:08 +0200199 * Fallthrough if the code above failed
wdenk9c53f402003-10-15 23:53:47 +0000200 * Initiate hard reset in debug control register DBCR0
201 * Make sure MSR[DE] = 1
202 */
urwithsughosh@gmail.com06c2fb92007-09-24 13:32:13 -0400203
Sergei Poselenov25147422008-05-08 14:17:08 +0200204 msr = mfmsr ();
205 msr |= MSR_DE;
206 mtmsr (msr);
urwithsughosh@gmail.com06c2fb92007-09-24 13:32:13 -0400207
Sergei Poselenov25147422008-05-08 14:17:08 +0200208 val = mfspr(DBCR0);
209 val |= 0x70000000;
210 mtspr(DBCR0,val);
211
wdenk9c53f402003-10-15 23:53:47 +0000212 return 1;
213}
214
215
216/*
217 * Get timebase clock frequency
218 */
219unsigned long get_tbclk (void)
220{
James Yang957b1912008-02-08 16:44:53 -0600221 return (gd->bus_clk + 4UL)/8UL;
wdenk9c53f402003-10-15 23:53:47 +0000222}
223
224
225#if defined(CONFIG_WATCHDOG)
226void
227watchdog_reset(void)
228{
229 int re_enable = disable_interrupts();
230 reset_85xx_watchdog();
231 if (re_enable) enable_interrupts();
232}
233
234void
235reset_85xx_watchdog(void)
236{
237 /*
238 * Clear TSR(WIS) bit by writing 1
239 */
240 unsigned long val;
Andy Flemingeac342d2007-04-23 01:44:44 -0500241 val = mfspr(SPRN_TSR);
242 val |= TSR_WIS;
243 mtspr(SPRN_TSR, val);
wdenk9c53f402003-10-15 23:53:47 +0000244}
245#endif /* CONFIG_WATCHDOG */
246
247#if defined(CONFIG_DDR_ECC)
wdenk9c53f402003-10-15 23:53:47 +0000248void dma_init(void) {
Kumar Gala0a7a0972007-11-29 02:10:09 -0600249 volatile ccsr_dma_t *dma = (void *)(CFG_MPC85xx_DMA_ADDR);
wdenk9c53f402003-10-15 23:53:47 +0000250
251 dma->satr0 = 0x02c40000;
252 dma->datr0 = 0x02c40000;
Andy Flemingeac342d2007-04-23 01:44:44 -0500253 dma->sr0 = 0xfffffff; /* clear any errors */
wdenk9c53f402003-10-15 23:53:47 +0000254 asm("sync; isync; msync");
255 return;
256}
257
258uint dma_check(void) {
Kumar Gala0a7a0972007-11-29 02:10:09 -0600259 volatile ccsr_dma_t *dma = (void *)(CFG_MPC85xx_DMA_ADDR);
wdenk9c53f402003-10-15 23:53:47 +0000260 volatile uint status = dma->sr0;
261
262 /* While the channel is busy, spin */
263 while((status & 4) == 4) {
264 status = dma->sr0;
265 }
266
Andy Flemingeac342d2007-04-23 01:44:44 -0500267 /* clear MR0[CS] channel start bit */
268 dma->mr0 &= 0x00000001;
269 asm("sync;isync;msync");
270
wdenk9c53f402003-10-15 23:53:47 +0000271 if (status != 0) {
272 printf ("DMA Error: status = %x\n", status);
273 }
274 return status;
275}
276
277int dma_xfer(void *dest, uint count, void *src) {
Kumar Gala0a7a0972007-11-29 02:10:09 -0600278 volatile ccsr_dma_t *dma = (void *)(CFG_MPC85xx_DMA_ADDR);
wdenk9c53f402003-10-15 23:53:47 +0000279
280 dma->dar0 = (uint) dest;
281 dma->sar0 = (uint) src;
282 dma->bcr0 = count;
283 dma->mr0 = 0xf000004;
284 asm("sync;isync;msync");
285 dma->mr0 = 0xf000005;
286 asm("sync;isync;msync");
287 return dma_check();
288}
289#endif