blob: 63bdb6fde1da1ffc85d1e6ae383fed86e6542d5d [file] [log] [blame]
wdenk42d1f032003-10-15 23:53:47 +00001/*
Poonam Aggrwal18bacc22009-07-31 12:07:45 +05302 * Copyright 2004,2007-2009 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 Fleming80522dc2008-10-30 16:51:33 -050032#include <fsl_esdhc.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
wdenk42d1f032003-10-15 23:53:47 +000038int checkcpu (void)
39{
wdenk97d80fc2004-06-09 00:34:46 +000040 sys_info_t sysinfo;
wdenk97d80fc2004-06-09 00:34:46 +000041 uint pvr, svr;
Jon Loeligerd9b94f22005-07-25 14:05:07 -050042 uint fam;
wdenk97d80fc2004-06-09 00:34:46 +000043 uint ver;
44 uint major, minor;
Kumar Gala4dbdb762008-06-10 16:53:46 -050045 struct cpu_type *cpu;
Wolfgang Denk08ef89e2008-10-19 02:35:49 +020046 char buf1[32], buf2[32];
Kumar Galaee1e35b2008-05-29 01:21:24 -050047#ifdef CONFIG_DDR_CLK_FREQ
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020048 volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
Jason Jinc0391112008-09-27 14:40:57 +080049 u32 ddr_ratio = ((gur->porpllsr) & MPC85xx_PORPLLSR_DDR_RATIO)
50 >> MPC85xx_PORPLLSR_DDR_RATIO_SHIFT;
Kumar Galaee1e35b2008-05-29 01:21:24 -050051#else
52 u32 ddr_ratio = 0;
53#endif
Haiying Wang2fc7eb02009-01-15 11:58:35 -050054 int i;
wdenk42d1f032003-10-15 23:53:47 +000055
wdenk97d80fc2004-06-09 00:34:46 +000056 svr = get_svr();
wdenk97d80fc2004-06-09 00:34:46 +000057 major = SVR_MAJ(svr);
Kumar Galaef50d6c2008-08-12 11:14:19 -050058#ifdef CONFIG_MPC8536
59 major &= 0x7; /* the msb of this nibble is a mfg code */
60#endif
wdenk97d80fc2004-06-09 00:34:46 +000061 minor = SVR_MIN(svr);
62
Poonam Aggrwal0e870982009-07-31 12:08:14 +053063 if (cpu_numcores() > 1) {
64 volatile ccsr_pic_t *pic = (void *)(CONFIG_SYS_MPC85xx_PIC_ADDR);
65 printf("CPU%d: ", pic->whoami);
66 } else {
67 puts("CPU: ");
68 }
Andy Fleming1ced1212008-02-06 01:19:40 -060069
Poonam Aggrwal0e870982009-07-31 12:08:14 +053070 cpu = gd->cpu;
71
Poonam Aggrwalea8be4a2009-09-02 13:35:21 +053072 puts(cpu->name);
73 if (IS_E_PROCESSOR(svr))
74 puts("E");
Andy Fleming1ced1212008-02-06 01:19:40 -060075
wdenk97d80fc2004-06-09 00:34:46 +000076 printf(", Version: %d.%d, (0x%08x)\n", major, minor, svr);
wdenk42d1f032003-10-15 23:53:47 +000077
wdenk6c9e7892005-03-15 22:56:53 +000078 pvr = get_pvr();
Jon Loeligerd9b94f22005-07-25 14:05:07 -050079 fam = PVR_FAM(pvr);
wdenk6c9e7892005-03-15 22:56:53 +000080 ver = PVR_VER(pvr);
81 major = PVR_MAJ(pvr);
82 minor = PVR_MIN(pvr);
83
84 printf("Core: ");
Jon Loeligerd9b94f22005-07-25 14:05:07 -050085 switch (fam) {
86 case PVR_FAM(PVR_85xx):
wdenk6c9e7892005-03-15 22:56:53 +000087 puts("E500");
88 break;
89 default:
90 puts("Unknown");
91 break;
92 }
Kumar Gala0f060c32008-10-23 01:47:38 -050093
94 if (PVR_MEM(pvr) == 0x03)
95 puts("MC");
96
wdenk6c9e7892005-03-15 22:56:53 +000097 printf(", Version: %d.%d, (0x%08x)\n", major, minor, pvr);
98
wdenk97d80fc2004-06-09 00:34:46 +000099 get_sys_info(&sysinfo);
100
Kumar Galab29dee32009-02-04 09:35:57 -0600101 puts("Clock Configuration:");
Poonam Aggrwal0e870982009-07-31 12:08:14 +0530102 for (i = 0; i < cpu_numcores(); i++) {
Wolfgang Denk1bba30e2009-02-19 00:41:08 +0100103 if (!(i & 3))
104 printf ("\n ");
Haiying Wang2fc7eb02009-01-15 11:58:35 -0500105 printf("CPU%d:%-4s MHz, ",
106 i,strmhz(buf1, sysinfo.freqProcessor[i]));
Kumar Galab29dee32009-02-04 09:35:57 -0600107 }
108 printf("\n CCB:%-4s MHz,\n", strmhz(buf1, sysinfo.freqSystemBus));
Kumar Galaee1e35b2008-05-29 01:21:24 -0500109
Kumar Galad4357932007-12-07 04:59:26 -0600110 switch (ddr_ratio) {
111 case 0x0:
Wolfgang Denk08ef89e2008-10-19 02:35:49 +0200112 printf(" DDR:%-4s MHz (%s MT/s data rate), ",
113 strmhz(buf1, sysinfo.freqDDRBus/2),
114 strmhz(buf2, sysinfo.freqDDRBus));
Kumar Galad4357932007-12-07 04:59:26 -0600115 break;
116 case 0x7:
Wolfgang Denk08ef89e2008-10-19 02:35:49 +0200117 printf(" DDR:%-4s MHz (%s MT/s data rate) (Synchronous), ",
118 strmhz(buf1, sysinfo.freqDDRBus/2),
119 strmhz(buf2, sysinfo.freqDDRBus));
Kumar Galad4357932007-12-07 04:59:26 -0600120 break;
121 default:
Wolfgang Denk08ef89e2008-10-19 02:35:49 +0200122 printf(" DDR:%-4s MHz (%s MT/s data rate) (Asynchronous), ",
123 strmhz(buf1, sysinfo.freqDDRBus/2),
124 strmhz(buf2, sysinfo.freqDDRBus));
Kumar Galad4357932007-12-07 04:59:26 -0600125 break;
126 }
wdenk97d80fc2004-06-09 00:34:46 +0000127
Trent Piephoada591d2008-12-03 15:16:37 -0800128 if (sysinfo.freqLocalBus > LCRR_CLKDIV)
129 printf("LBC:%-4s MHz\n", strmhz(buf1, sysinfo.freqLocalBus));
130 else
131 printf("LBC: unknown (LCRR[CLKDIV] = 0x%02lx)\n",
132 sysinfo.freqLocalBus);
wdenk97d80fc2004-06-09 00:34:46 +0000133
Andy Fleming1ced1212008-02-06 01:19:40 -0600134#ifdef CONFIG_CPM2
Wolfgang Denk08ef89e2008-10-19 02:35:49 +0200135 printf("CPM: %s MHz\n", strmhz(buf1, sysinfo.freqSystemBus));
Andy Fleming1ced1212008-02-06 01:19:40 -0600136#endif
wdenk97d80fc2004-06-09 00:34:46 +0000137
Haiying Wangb3d7f202009-05-20 12:30:29 -0400138#ifdef CONFIG_QE
139 printf(" QE:%-4s MHz\n", strmhz(buf1, sysinfo.freqQE));
140#endif
141
wdenk6c9e7892005-03-15 22:56:53 +0000142 puts("L1: D-cache 32 kB enabled\n I-cache 32 kB enabled\n");
wdenk42d1f032003-10-15 23:53:47 +0000143
144 return 0;
145}
146
147
148/* ------------------------------------------------------------------------- */
149
150int do_reset (cmd_tbl_t *cmdtp, bd_t *bd, int flag, int argc, char *argv[])
151{
Zang Roy-r6191196629cb2006-12-05 16:42:30 +0800152 uint pvr;
153 uint ver;
Sergei Poselenov793670c2008-05-08 14:17:08 +0200154 unsigned long val, msr;
155
Zang Roy-r6191196629cb2006-12-05 16:42:30 +0800156 pvr = get_pvr();
157 ver = PVR_VER(pvr);
Sergei Poselenov793670c2008-05-08 14:17:08 +0200158
Zang Roy-r6191196629cb2006-12-05 16:42:30 +0800159 if (ver & 1){
160 /* e500 v2 core has reset control register */
161 volatile unsigned int * rstcr;
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200162 rstcr = (volatile unsigned int *)(CONFIG_SYS_IMMR + 0xE00B0);
Wolfgang Denk2f152782007-05-05 18:23:11 +0200163 *rstcr = 0x2; /* HRESET_REQ */
Sergei Poselenov793670c2008-05-08 14:17:08 +0200164 udelay(100);
165 }
166
wdenk42d1f032003-10-15 23:53:47 +0000167 /*
Sergei Poselenov793670c2008-05-08 14:17:08 +0200168 * Fallthrough if the code above failed
wdenk42d1f032003-10-15 23:53:47 +0000169 * Initiate hard reset in debug control register DBCR0
170 * Make sure MSR[DE] = 1
171 */
urwithsughosh@gmail.comdf909682007-09-24 13:32:13 -0400172
Sergei Poselenov793670c2008-05-08 14:17:08 +0200173 msr = mfmsr ();
174 msr |= MSR_DE;
175 mtmsr (msr);
urwithsughosh@gmail.comdf909682007-09-24 13:32:13 -0400176
Sergei Poselenov793670c2008-05-08 14:17:08 +0200177 val = mfspr(DBCR0);
178 val |= 0x70000000;
179 mtspr(DBCR0,val);
180
wdenk42d1f032003-10-15 23:53:47 +0000181 return 1;
182}
183
184
185/*
186 * Get timebase clock frequency
187 */
188unsigned long get_tbclk (void)
189{
James Yang591933c2008-02-08 16:44:53 -0600190 return (gd->bus_clk + 4UL)/8UL;
wdenk42d1f032003-10-15 23:53:47 +0000191}
192
193
194#if defined(CONFIG_WATCHDOG)
195void
196watchdog_reset(void)
197{
198 int re_enable = disable_interrupts();
199 reset_85xx_watchdog();
200 if (re_enable) enable_interrupts();
201}
202
203void
204reset_85xx_watchdog(void)
205{
206 /*
207 * Clear TSR(WIS) bit by writing 1
208 */
209 unsigned long val;
Andy Fleming03b81b42007-04-23 01:44:44 -0500210 val = mfspr(SPRN_TSR);
211 val |= TSR_WIS;
212 mtspr(SPRN_TSR, val);
wdenk42d1f032003-10-15 23:53:47 +0000213}
214#endif /* CONFIG_WATCHDOG */
215
Sergei Poselenov740280e2008-06-06 15:42:40 +0200216/*
Sergei Poselenov59f63052008-08-15 15:42:11 +0200217 * Configures a UPM. The function requires the respective MxMR to be set
218 * before calling this function. "size" is the number or entries, not a sizeof.
Sergei Poselenov740280e2008-06-06 15:42:40 +0200219 */
220void upmconfig (uint upm, uint * table, uint size)
221{
222 int i, mdr, mad, old_mad = 0;
223 volatile u32 *mxmr;
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200224 volatile ccsr_lbc_t *lbc = (void *)(CONFIG_SYS_MPC85xx_LBC_ADDR);
Sergei Poselenov740280e2008-06-06 15:42:40 +0200225 volatile u32 *brp,*orp;
226 volatile u8* dummy = NULL;
227 int upmmask;
228
229 switch (upm) {
230 case UPMA:
231 mxmr = &lbc->mamr;
232 upmmask = BR_MS_UPMA;
233 break;
234 case UPMB:
235 mxmr = &lbc->mbmr;
236 upmmask = BR_MS_UPMB;
237 break;
238 case UPMC:
239 mxmr = &lbc->mcmr;
240 upmmask = BR_MS_UPMC;
241 break;
242 default:
243 printf("%s: Bad UPM index %d to configure\n", __FUNCTION__, upm);
244 hang();
245 }
246
247 /* Find the address for the dummy write transaction */
248 for (brp = &lbc->br0, orp = &lbc->or0, i = 0; i < 8;
249 i++, brp += 2, orp += 2) {
Wolfgang Denke093a242008-06-28 23:34:37 +0200250
Sergei Poselenov740280e2008-06-06 15:42:40 +0200251 /* Look for a valid BR with selected UPM */
Sergei Poselenov59f63052008-08-15 15:42:11 +0200252 if ((in_be32(brp) & (BR_V | BR_MSEL)) == (BR_V | upmmask)) {
253 dummy = (volatile u8*)(in_be32(brp) & BR_BA);
Sergei Poselenov740280e2008-06-06 15:42:40 +0200254 break;
255 }
256 }
257
258 if (i == 8) {
259 printf("Error: %s() could not find matching BR\n", __FUNCTION__);
260 hang();
261 }
262
263 for (i = 0; i < size; i++) {
264 /* 1 */
Sergei Poselenov59f63052008-08-15 15:42:11 +0200265 out_be32(mxmr, (in_be32(mxmr) & 0x4fffffc0) | MxMR_OP_WARR | i);
Sergei Poselenov740280e2008-06-06 15:42:40 +0200266 /* 2 */
267 out_be32(&lbc->mdr, table[i]);
268 /* 3 */
269 mdr = in_be32(&lbc->mdr);
270 /* 4 */
271 *(volatile u8 *)dummy = 0;
272 /* 5 */
273 do {
Sergei Poselenov59f63052008-08-15 15:42:11 +0200274 mad = in_be32(mxmr) & MxMR_MAD_MSK;
Sergei Poselenov740280e2008-06-06 15:42:40 +0200275 } while (mad <= old_mad && !(!mad && i == (size-1)));
276 old_mad = mad;
277 }
Sergei Poselenov59f63052008-08-15 15:42:11 +0200278 out_be32(mxmr, (in_be32(mxmr) & 0x4fffffc0) | MxMR_OP_NORM);
Sergei Poselenov740280e2008-06-06 15:42:40 +0200279}
Ben Warrendd354792008-06-23 22:57:27 -0700280
Andy Fleming80522dc2008-10-30 16:51:33 -0500281/*
282 * Initializes on-chip MMC controllers.
283 * to override, implement board_mmc_init()
284 */
285int cpu_mmc_init(bd_t *bis)
286{
287#ifdef CONFIG_FSL_ESDHC
288 return fsl_esdhc_mmc_init(bis);
289#else
290 return 0;
291#endif
292}