]> git.karo-electronics.de Git - karo-tx-uboot.git/blob - cpu/mpc85xx/cpu.c
4724f2764d38d6eb78423f207e5ea8dd08146485
[karo-tx-uboot.git] / cpu / mpc85xx / cpu.c
1 /*
2  * Copyright 2004,2007-2009 Freescale Semiconductor, Inc.
3  * (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 <config.h>
29 #include <common.h>
30 #include <watchdog.h>
31 #include <command.h>
32 #include <fsl_esdhc.h>
33 #include <asm/cache.h>
34 #include <asm/io.h>
35
36 DECLARE_GLOBAL_DATA_PTR;
37
38 int checkcpu (void)
39 {
40         sys_info_t sysinfo;
41         uint pvr, svr;
42         uint fam;
43         uint ver;
44         uint major, minor;
45         struct cpu_type *cpu;
46         char buf1[32], buf2[32];
47 #ifdef CONFIG_DDR_CLK_FREQ
48         volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
49         u32 ddr_ratio = ((gur->porpllsr) & MPC85xx_PORPLLSR_DDR_RATIO)
50                 >> MPC85xx_PORPLLSR_DDR_RATIO_SHIFT;
51 #else
52         u32 ddr_ratio = 0;
53 #endif
54         int i;
55
56         svr = get_svr();
57         ver = SVR_SOC_VER(svr);
58         major = SVR_MAJ(svr);
59 #ifdef CONFIG_MPC8536
60         major &= 0x7; /* the msb of this nibble is a mfg code */
61 #endif
62         minor = SVR_MIN(svr);
63
64 #if (CONFIG_NUM_CPUS > 1)
65         volatile ccsr_pic_t *pic = (void *)(CONFIG_SYS_MPC85xx_PIC_ADDR);
66         printf("CPU%d:  ", pic->whoami);
67 #else
68         puts("CPU:   ");
69 #endif
70
71         cpu = identify_cpu(ver);
72         if (cpu) {
73                 puts(cpu->name);
74
75                 if (IS_E_PROCESSOR(svr))
76                         puts("E");
77         } else {
78                 puts("Unknown");
79         }
80
81         printf(", Version: %d.%d, (0x%08x)\n", major, minor, svr);
82
83         pvr = get_pvr();
84         fam = PVR_FAM(pvr);
85         ver = PVR_VER(pvr);
86         major = PVR_MAJ(pvr);
87         minor = PVR_MIN(pvr);
88
89         printf("Core:  ");
90         switch (fam) {
91         case PVR_FAM(PVR_85xx):
92             puts("E500");
93             break;
94         default:
95             puts("Unknown");
96             break;
97         }
98
99         if (PVR_MEM(pvr) == 0x03)
100                 puts("MC");
101
102         printf(", Version: %d.%d, (0x%08x)\n", major, minor, pvr);
103
104         get_sys_info(&sysinfo);
105
106         puts("Clock Configuration:");
107         for (i = 0; i < CONFIG_NUM_CPUS; i++) {
108                 if (!(i & 3))
109                         printf ("\n       ");
110                 printf("CPU%d:%-4s MHz, ",
111                                 i,strmhz(buf1, sysinfo.freqProcessor[i]));
112         }
113         printf("\n       CCB:%-4s MHz,\n", strmhz(buf1, sysinfo.freqSystemBus));
114
115         switch (ddr_ratio) {
116         case 0x0:
117                 printf("       DDR:%-4s MHz (%s MT/s data rate), ",
118                         strmhz(buf1, sysinfo.freqDDRBus/2),
119                         strmhz(buf2, sysinfo.freqDDRBus));
120                 break;
121         case 0x7:
122                 printf("       DDR:%-4s MHz (%s MT/s data rate) (Synchronous), ",
123                         strmhz(buf1, sysinfo.freqDDRBus/2),
124                         strmhz(buf2, sysinfo.freqDDRBus));
125                 break;
126         default:
127                 printf("       DDR:%-4s MHz (%s MT/s data rate) (Asynchronous), ",
128                         strmhz(buf1, sysinfo.freqDDRBus/2),
129                         strmhz(buf2, sysinfo.freqDDRBus));
130                 break;
131         }
132
133         if (sysinfo.freqLocalBus > LCRR_CLKDIV)
134                 printf("LBC:%-4s MHz\n", strmhz(buf1, sysinfo.freqLocalBus));
135         else
136                 printf("LBC: unknown (LCRR[CLKDIV] = 0x%02lx)\n",
137                        sysinfo.freqLocalBus);
138
139 #ifdef CONFIG_CPM2
140         printf("CPM:   %s MHz\n", strmhz(buf1, sysinfo.freqSystemBus));
141 #endif
142
143 #ifdef CONFIG_QE
144         printf("       QE:%-4s MHz\n", strmhz(buf1, sysinfo.freqQE));
145 #endif
146
147         puts("L1:    D-cache 32 kB enabled\n       I-cache 32 kB enabled\n");
148
149         return 0;
150 }
151
152
153 /* ------------------------------------------------------------------------- */
154
155 int do_reset (cmd_tbl_t *cmdtp, bd_t *bd, int flag, int argc, char *argv[])
156 {
157         uint pvr;
158         uint ver;
159         unsigned long val, msr;
160
161         pvr = get_pvr();
162         ver = PVR_VER(pvr);
163
164         if (ver & 1){
165         /* e500 v2 core has reset control register */
166                 volatile unsigned int * rstcr;
167                 rstcr = (volatile unsigned int *)(CONFIG_SYS_IMMR + 0xE00B0);
168                 *rstcr = 0x2;           /* HRESET_REQ */
169                 udelay(100);
170         }
171
172         /*
173          * Fallthrough if the code above failed
174          * Initiate hard reset in debug control register DBCR0
175          * Make sure MSR[DE] = 1
176          */
177
178         msr = mfmsr ();
179         msr |= MSR_DE;
180         mtmsr (msr);
181
182         val = mfspr(DBCR0);
183         val |= 0x70000000;
184         mtspr(DBCR0,val);
185
186         return 1;
187 }
188
189
190 /*
191  * Get timebase clock frequency
192  */
193 unsigned long get_tbclk (void)
194 {
195         return (gd->bus_clk + 4UL)/8UL;
196 }
197
198
199 #if defined(CONFIG_WATCHDOG)
200 void
201 watchdog_reset(void)
202 {
203         int re_enable = disable_interrupts();
204         reset_85xx_watchdog();
205         if (re_enable) enable_interrupts();
206 }
207
208 void
209 reset_85xx_watchdog(void)
210 {
211         /*
212          * Clear TSR(WIS) bit by writing 1
213          */
214         unsigned long val;
215         val = mfspr(SPRN_TSR);
216         val |= TSR_WIS;
217         mtspr(SPRN_TSR, val);
218 }
219 #endif  /* CONFIG_WATCHDOG */
220
221 /*
222  * Configures a UPM. The function requires the respective MxMR to be set
223  * before calling this function. "size" is the number or entries, not a sizeof.
224  */
225 void upmconfig (uint upm, uint * table, uint size)
226 {
227         int i, mdr, mad, old_mad = 0;
228         volatile u32 *mxmr;
229         volatile ccsr_lbc_t *lbc = (void *)(CONFIG_SYS_MPC85xx_LBC_ADDR);
230         volatile u32 *brp,*orp;
231         volatile u8* dummy = NULL;
232         int upmmask;
233
234         switch (upm) {
235         case UPMA:
236                 mxmr = &lbc->mamr;
237                 upmmask = BR_MS_UPMA;
238                 break;
239         case UPMB:
240                 mxmr = &lbc->mbmr;
241                 upmmask = BR_MS_UPMB;
242                 break;
243         case UPMC:
244                 mxmr = &lbc->mcmr;
245                 upmmask = BR_MS_UPMC;
246                 break;
247         default:
248                 printf("%s: Bad UPM index %d to configure\n", __FUNCTION__, upm);
249                 hang();
250         }
251
252         /* Find the address for the dummy write transaction */
253         for (brp = &lbc->br0, orp = &lbc->or0, i = 0; i < 8;
254                  i++, brp += 2, orp += 2) {
255
256                 /* Look for a valid BR with selected UPM */
257                 if ((in_be32(brp) & (BR_V | BR_MSEL)) == (BR_V | upmmask)) {
258                         dummy = (volatile u8*)(in_be32(brp) & BR_BA);
259                         break;
260                 }
261         }
262
263         if (i == 8) {
264                 printf("Error: %s() could not find matching BR\n", __FUNCTION__);
265                 hang();
266         }
267
268         for (i = 0; i < size; i++) {
269                 /* 1 */
270                 out_be32(mxmr,  (in_be32(mxmr) & 0x4fffffc0) | MxMR_OP_WARR | i);
271                 /* 2 */
272                 out_be32(&lbc->mdr, table[i]);
273                 /* 3 */
274                 mdr = in_be32(&lbc->mdr);
275                 /* 4 */
276                 *(volatile u8 *)dummy = 0;
277                 /* 5 */
278                 do {
279                         mad = in_be32(mxmr) & MxMR_MAD_MSK;
280                 } while (mad <= old_mad && !(!mad && i == (size-1)));
281                 old_mad = mad;
282         }
283         out_be32(mxmr, (in_be32(mxmr) & 0x4fffffc0) | MxMR_OP_NORM);
284 }
285
286 /*
287  * Initializes on-chip MMC controllers.
288  * to override, implement board_mmc_init()
289  */
290 int cpu_mmc_init(bd_t *bis)
291 {
292 #ifdef CONFIG_FSL_ESDHC
293         return fsl_esdhc_mmc_init(bis);
294 #else
295         return 0;
296 #endif
297 }