]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - cpu/mpc85xx/cpu.c
mpc8xxx: LCRR[CLKDIV] is sometimes five bits
[karo-tx-uboot.git] / cpu / mpc85xx / cpu.c
1 /*
2  * Copyright 2004,2007,2008 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 <tsec.h>
33 #include <netdev.h>
34 #include <asm/cache.h>
35 #include <asm/io.h>
36
37 DECLARE_GLOBAL_DATA_PTR;
38
39 struct cpu_type cpu_type_list [] = {
40         CPU_TYPE_ENTRY(8533, 8533),
41         CPU_TYPE_ENTRY(8533, 8533_E),
42         CPU_TYPE_ENTRY(8536, 8536),
43         CPU_TYPE_ENTRY(8536, 8536_E),
44         CPU_TYPE_ENTRY(8540, 8540),
45         CPU_TYPE_ENTRY(8541, 8541),
46         CPU_TYPE_ENTRY(8541, 8541_E),
47         CPU_TYPE_ENTRY(8543, 8543),
48         CPU_TYPE_ENTRY(8543, 8543_E),
49         CPU_TYPE_ENTRY(8544, 8544),
50         CPU_TYPE_ENTRY(8544, 8544_E),
51         CPU_TYPE_ENTRY(8545, 8545),
52         CPU_TYPE_ENTRY(8545, 8545_E),
53         CPU_TYPE_ENTRY(8547, 8547_E),
54         CPU_TYPE_ENTRY(8548, 8548),
55         CPU_TYPE_ENTRY(8548, 8548_E),
56         CPU_TYPE_ENTRY(8555, 8555),
57         CPU_TYPE_ENTRY(8555, 8555_E),
58         CPU_TYPE_ENTRY(8560, 8560),
59         CPU_TYPE_ENTRY(8567, 8567),
60         CPU_TYPE_ENTRY(8567, 8567_E),
61         CPU_TYPE_ENTRY(8568, 8568),
62         CPU_TYPE_ENTRY(8568, 8568_E),
63         CPU_TYPE_ENTRY(8572, 8572),
64         CPU_TYPE_ENTRY(8572, 8572_E),
65 };
66
67 struct cpu_type *identify_cpu(u32 ver)
68 {
69         int i;
70         for (i = 0; i < ARRAY_SIZE(cpu_type_list); i++)
71                 if (cpu_type_list[i].soc_ver == ver)
72                         return &cpu_type_list[i];
73
74         return NULL;
75 }
76
77 int checkcpu (void)
78 {
79         sys_info_t sysinfo;
80         uint lcrr;              /* local bus clock ratio register */
81         uint clkdiv;            /* clock divider portion of lcrr */
82         uint pvr, svr;
83         uint fam;
84         uint ver;
85         uint major, minor;
86         struct cpu_type *cpu;
87         char buf1[32], buf2[32];
88 #ifdef CONFIG_DDR_CLK_FREQ
89         volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
90         u32 ddr_ratio = ((gur->porpllsr) & MPC85xx_PORPLLSR_DDR_RATIO)
91                 >> MPC85xx_PORPLLSR_DDR_RATIO_SHIFT;
92 #else
93         u32 ddr_ratio = 0;
94 #endif
95
96         svr = get_svr();
97         ver = SVR_SOC_VER(svr);
98         major = SVR_MAJ(svr);
99 #ifdef CONFIG_MPC8536
100         major &= 0x7; /* the msb of this nibble is a mfg code */
101 #endif
102         minor = SVR_MIN(svr);
103
104 #if (CONFIG_NUM_CPUS > 1)
105         volatile ccsr_pic_t *pic = (void *)(CONFIG_SYS_MPC85xx_PIC_ADDR);
106         printf("CPU%d:  ", pic->whoami);
107 #else
108         puts("CPU:   ");
109 #endif
110
111         cpu = identify_cpu(ver);
112         if (cpu) {
113                 puts(cpu->name);
114
115                 if (IS_E_PROCESSOR(svr))
116                         puts("E");
117         } else {
118                 puts("Unknown");
119         }
120
121         printf(", Version: %d.%d, (0x%08x)\n", major, minor, svr);
122
123         pvr = get_pvr();
124         fam = PVR_FAM(pvr);
125         ver = PVR_VER(pvr);
126         major = PVR_MAJ(pvr);
127         minor = PVR_MIN(pvr);
128
129         printf("Core:  ");
130         switch (fam) {
131         case PVR_FAM(PVR_85xx):
132             puts("E500");
133             break;
134         default:
135             puts("Unknown");
136             break;
137         }
138
139         if (PVR_MEM(pvr) == 0x03)
140                 puts("MC");
141
142         printf(", Version: %d.%d, (0x%08x)\n", major, minor, pvr);
143
144         get_sys_info(&sysinfo);
145
146         puts("Clock Configuration:\n");
147         printf("       CPU:%-4s MHz, ", strmhz(buf1, sysinfo.freqProcessor));
148         printf("CCB:%-4s MHz,\n", strmhz(buf1, sysinfo.freqSystemBus));
149
150         switch (ddr_ratio) {
151         case 0x0:
152                 printf("       DDR:%-4s MHz (%s MT/s data rate), ",
153                         strmhz(buf1, sysinfo.freqDDRBus/2),
154                         strmhz(buf2, sysinfo.freqDDRBus));
155                 break;
156         case 0x7:
157                 printf("       DDR:%-4s MHz (%s MT/s data rate) (Synchronous), ",
158                         strmhz(buf1, sysinfo.freqDDRBus/2),
159                         strmhz(buf2, sysinfo.freqDDRBus));
160                 break;
161         default:
162                 printf("       DDR:%-4s MHz (%s MT/s data rate) (Asynchronous), ",
163                         strmhz(buf1, sysinfo.freqDDRBus/2),
164                         strmhz(buf2, sysinfo.freqDDRBus));
165                 break;
166         }
167
168 #if defined(CONFIG_SYS_LBC_LCRR)
169         lcrr = CONFIG_SYS_LBC_LCRR;
170 #else
171         {
172             volatile ccsr_lbc_t *lbc = (void *)(CONFIG_SYS_MPC85xx_LBC_ADDR);
173
174             lcrr = lbc->lcrr;
175         }
176 #endif
177         clkdiv = lcrr & LCRR_CLKDIV;
178         if (clkdiv == 2 || clkdiv == 4 || clkdiv == 8) {
179 #if defined(CONFIG_MPC8548) || defined(CONFIG_MPC8544) || \
180     defined(CONFIG_MPC8572) || defined(CONFIG_MPC8536)
181                 /*
182                  * Yes, the entire PQ38 family use the same
183                  * bit-representation for twice the clock divider values.
184                  */
185                  clkdiv *= 2;
186 #endif
187                 printf("LBC:%-4s MHz\n",
188                        strmhz(buf1, sysinfo.freqSystemBus / clkdiv));
189         } else {
190                 printf("LBC: unknown (lcrr: 0x%08x)\n", lcrr);
191         }
192
193 #ifdef CONFIG_CPM2
194         printf("CPM:   %s MHz\n", strmhz(buf1, sysinfo.freqSystemBus));
195 #endif
196
197         puts("L1:    D-cache 32 kB enabled\n       I-cache 32 kB enabled\n");
198
199         return 0;
200 }
201
202
203 /* ------------------------------------------------------------------------- */
204
205 int do_reset (cmd_tbl_t *cmdtp, bd_t *bd, int flag, int argc, char *argv[])
206 {
207         uint pvr;
208         uint ver;
209         unsigned long val, msr;
210
211         pvr = get_pvr();
212         ver = PVR_VER(pvr);
213
214         if (ver & 1){
215         /* e500 v2 core has reset control register */
216                 volatile unsigned int * rstcr;
217                 rstcr = (volatile unsigned int *)(CONFIG_SYS_IMMR + 0xE00B0);
218                 *rstcr = 0x2;           /* HRESET_REQ */
219                 udelay(100);
220         }
221
222         /*
223          * Fallthrough if the code above failed
224          * Initiate hard reset in debug control register DBCR0
225          * Make sure MSR[DE] = 1
226          */
227
228         msr = mfmsr ();
229         msr |= MSR_DE;
230         mtmsr (msr);
231
232         val = mfspr(DBCR0);
233         val |= 0x70000000;
234         mtspr(DBCR0,val);
235
236         return 1;
237 }
238
239
240 /*
241  * Get timebase clock frequency
242  */
243 unsigned long get_tbclk (void)
244 {
245         return (gd->bus_clk + 4UL)/8UL;
246 }
247
248
249 #if defined(CONFIG_WATCHDOG)
250 void
251 watchdog_reset(void)
252 {
253         int re_enable = disable_interrupts();
254         reset_85xx_watchdog();
255         if (re_enable) enable_interrupts();
256 }
257
258 void
259 reset_85xx_watchdog(void)
260 {
261         /*
262          * Clear TSR(WIS) bit by writing 1
263          */
264         unsigned long val;
265         val = mfspr(SPRN_TSR);
266         val |= TSR_WIS;
267         mtspr(SPRN_TSR, val);
268 }
269 #endif  /* CONFIG_WATCHDOG */
270
271 #if defined(CONFIG_DDR_ECC)
272 void dma_init(void) {
273         volatile ccsr_dma_t *dma = (void *)(CONFIG_SYS_MPC85xx_DMA_ADDR);
274
275         dma->satr0 = 0x02c40000;
276         dma->datr0 = 0x02c40000;
277         dma->sr0 = 0xfffffff; /* clear any errors */
278         asm("sync; isync; msync");
279         return;
280 }
281
282 uint dma_check(void) {
283         volatile ccsr_dma_t *dma = (void *)(CONFIG_SYS_MPC85xx_DMA_ADDR);
284         volatile uint status = dma->sr0;
285
286         /* While the channel is busy, spin */
287         while((status & 4) == 4) {
288                 status = dma->sr0;
289         }
290
291         /* clear MR0[CS] channel start bit */
292         dma->mr0 &= 0x00000001;
293         asm("sync;isync;msync");
294
295         if (status != 0) {
296                 printf ("DMA Error: status = %x\n", status);
297         }
298         return status;
299 }
300
301 int dma_xfer(void *dest, uint count, void *src) {
302         volatile ccsr_dma_t *dma = (void *)(CONFIG_SYS_MPC85xx_DMA_ADDR);
303
304         dma->dar0 = (uint) dest;
305         dma->sar0 = (uint) src;
306         dma->bcr0 = count;
307         dma->mr0 = 0xf000004;
308         asm("sync;isync;msync");
309         dma->mr0 = 0xf000005;
310         asm("sync;isync;msync");
311         return dma_check();
312 }
313 #endif
314
315 /*
316  * Configures a UPM. The function requires the respective MxMR to be set
317  * before calling this function. "size" is the number or entries, not a sizeof.
318  */
319 void upmconfig (uint upm, uint * table, uint size)
320 {
321         int i, mdr, mad, old_mad = 0;
322         volatile u32 *mxmr;
323         volatile ccsr_lbc_t *lbc = (void *)(CONFIG_SYS_MPC85xx_LBC_ADDR);
324         volatile u32 *brp,*orp;
325         volatile u8* dummy = NULL;
326         int upmmask;
327
328         switch (upm) {
329         case UPMA:
330                 mxmr = &lbc->mamr;
331                 upmmask = BR_MS_UPMA;
332                 break;
333         case UPMB:
334                 mxmr = &lbc->mbmr;
335                 upmmask = BR_MS_UPMB;
336                 break;
337         case UPMC:
338                 mxmr = &lbc->mcmr;
339                 upmmask = BR_MS_UPMC;
340                 break;
341         default:
342                 printf("%s: Bad UPM index %d to configure\n", __FUNCTION__, upm);
343                 hang();
344         }
345
346         /* Find the address for the dummy write transaction */
347         for (brp = &lbc->br0, orp = &lbc->or0, i = 0; i < 8;
348                  i++, brp += 2, orp += 2) {
349
350                 /* Look for a valid BR with selected UPM */
351                 if ((in_be32(brp) & (BR_V | BR_MSEL)) == (BR_V | upmmask)) {
352                         dummy = (volatile u8*)(in_be32(brp) & BR_BA);
353                         break;
354                 }
355         }
356
357         if (i == 8) {
358                 printf("Error: %s() could not find matching BR\n", __FUNCTION__);
359                 hang();
360         }
361
362         for (i = 0; i < size; i++) {
363                 /* 1 */
364                 out_be32(mxmr,  (in_be32(mxmr) & 0x4fffffc0) | MxMR_OP_WARR | i);
365                 /* 2 */
366                 out_be32(&lbc->mdr, table[i]);
367                 /* 3 */
368                 mdr = in_be32(&lbc->mdr);
369                 /* 4 */
370                 *(volatile u8 *)dummy = 0;
371                 /* 5 */
372                 do {
373                         mad = in_be32(mxmr) & MxMR_MAD_MSK;
374                 } while (mad <= old_mad && !(!mad && i == (size-1)));
375                 old_mad = mad;
376         }
377         out_be32(mxmr, (in_be32(mxmr) & 0x4fffffc0) | MxMR_OP_NORM);
378 }
379
380
381 /*
382  * Initializes on-chip ethernet controllers.
383  * to override, implement board_eth_init()
384  */
385 int cpu_eth_init(bd_t *bis)
386 {
387 #if defined(CONFIG_ETHER_ON_FCC)
388         fec_initialize(bis);
389 #endif
390 #if defined(CONFIG_UEC_ETH1)
391         uec_initialize(0);
392 #endif
393 #if defined(CONFIG_UEC_ETH2)
394         uec_initialize(1);
395 #endif
396 #if defined(CONFIG_UEC_ETH3)
397         uec_initialize(2);
398 #endif
399 #if defined(CONFIG_UEC_ETH4)
400         uec_initialize(3);
401 #endif
402 #if defined(CONFIG_UEC_ETH5)
403         uec_initialize(4);
404 #endif
405 #if defined(CONFIG_UEC_ETH6)
406         uec_initialize(5);
407 #endif
408 #if defined(CONFIG_TSEC_ENET) || defined(CONFIG_MPC85XX_FEC)
409         tsec_standard_init(bis);
410 #endif
411         return 0;
412 }