ppc4xx: Fix misspelled CONFIG_440SPE/440EPX/GRX config options
[platform/kernel/u-boot.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 <common.h>
29 #include <watchdog.h>
30 #include <command.h>
31 #include <asm/cache.h>
32
33 DECLARE_GLOBAL_DATA_PTR;
34
35 struct cpu_type {
36         char name[15];
37         u32 soc_ver;
38 };
39
40 #define CPU_TYPE_ENTRY(x) {#x, SVR_##x}
41
42 struct cpu_type cpu_type_list [] = {
43         CPU_TYPE_ENTRY(8533),
44         CPU_TYPE_ENTRY(8533_E),
45         CPU_TYPE_ENTRY(8540),
46         CPU_TYPE_ENTRY(8541),
47         CPU_TYPE_ENTRY(8541_E),
48         CPU_TYPE_ENTRY(8543),
49         CPU_TYPE_ENTRY(8543_E),
50         CPU_TYPE_ENTRY(8544),
51         CPU_TYPE_ENTRY(8544_E),
52         CPU_TYPE_ENTRY(8545),
53         CPU_TYPE_ENTRY(8545_E),
54         CPU_TYPE_ENTRY(8547_E),
55         CPU_TYPE_ENTRY(8548),
56         CPU_TYPE_ENTRY(8548_E),
57         CPU_TYPE_ENTRY(8555),
58         CPU_TYPE_ENTRY(8555_E),
59         CPU_TYPE_ENTRY(8560),
60         CPU_TYPE_ENTRY(8567),
61         CPU_TYPE_ENTRY(8567_E),
62         CPU_TYPE_ENTRY(8568),
63         CPU_TYPE_ENTRY(8568_E),
64         CPU_TYPE_ENTRY(8572),
65         CPU_TYPE_ENTRY(8572_E),
66 };
67
68 int checkcpu (void)
69 {
70         sys_info_t sysinfo;
71         uint lcrr;              /* local bus clock ratio register */
72         uint clkdiv;            /* clock divider portion of lcrr */
73         uint pvr, svr;
74         uint fam;
75         uint ver;
76         uint major, minor;
77         int i;
78         u32 ddr_ratio;
79         volatile ccsr_gur_t *gur = (void *)(CFG_MPC85xx_GUTS_ADDR);
80
81         svr = get_svr();
82         ver = SVR_SOC_VER(svr);
83         major = SVR_MAJ(svr);
84         minor = SVR_MIN(svr);
85
86         puts("CPU:   ");
87
88         for (i = 0; i < ARRAY_SIZE(cpu_type_list); i++)
89                 if (cpu_type_list[i].soc_ver == ver) {
90                         puts(cpu_type_list[i].name);
91                         break;
92                 }
93
94         if (i == ARRAY_SIZE(cpu_type_list))
95                 puts("Unknown");
96
97         printf(", Version: %d.%d, (0x%08x)\n", major, minor, svr);
98
99         pvr = get_pvr();
100         fam = PVR_FAM(pvr);
101         ver = PVR_VER(pvr);
102         major = PVR_MAJ(pvr);
103         minor = PVR_MIN(pvr);
104
105         printf("Core:  ");
106         switch (fam) {
107         case PVR_FAM(PVR_85xx):
108             puts("E500");
109             break;
110         default:
111             puts("Unknown");
112             break;
113         }
114         printf(", Version: %d.%d, (0x%08x)\n", major, minor, pvr);
115
116         get_sys_info(&sysinfo);
117
118         puts("Clock Configuration:\n");
119         printf("       CPU:%4lu MHz, ", DIV_ROUND_UP(sysinfo.freqProcessor,1000000));
120         printf("CCB:%4lu MHz,\n", DIV_ROUND_UP(sysinfo.freqSystemBus,1000000));
121         ddr_ratio = ((gur->porpllsr) & 0x00003e00) >> 9;
122         switch (ddr_ratio) {
123         case 0x0:
124                 printf("       DDR:%4lu MHz (%lu MT/s data rate), ",
125                 DIV_ROUND_UP(sysinfo.freqDDRBus,2000000), DIV_ROUND_UP(sysinfo.freqDDRBus,1000000));
126                 break;
127         case 0x7:
128                 printf("       DDR:%4lu MHz (%lu MT/s data rate) (Synchronous), ",
129                 DIV_ROUND_UP(sysinfo.freqDDRBus, 2000000), DIV_ROUND_UP(sysinfo.freqDDRBus, 1000000));
130                 break;
131         default:
132                 printf("       DDR:%4lu MHz (%lu MT/s data rate) (Asynchronous), ",
133                 DIV_ROUND_UP(sysinfo.freqDDRBus, 2000000), DIV_ROUND_UP(sysinfo.freqDDRBus,1000000));
134                 break;
135         }
136
137 #if defined(CFG_LBC_LCRR)
138         lcrr = CFG_LBC_LCRR;
139 #else
140         {
141             volatile ccsr_lbc_t *lbc = (void *)(CFG_MPC85xx_LBC_ADDR);
142
143             lcrr = lbc->lcrr;
144         }
145 #endif
146         clkdiv = lcrr & 0x0f;
147         if (clkdiv == 2 || clkdiv == 4 || clkdiv == 8) {
148 #if defined(CONFIG_MPC8548) || defined(CONFIG_MPC8544)
149                 /*
150                  * Yes, the entire PQ38 family use the same
151                  * bit-representation for twice the clock divider values.
152                  */
153                  clkdiv *= 2;
154 #endif
155                 printf("LBC:%4lu MHz\n",
156                        DIV_ROUND_UP(sysinfo.freqSystemBus, 1000000) / clkdiv);
157         } else {
158                 printf("LBC: unknown (lcrr: 0x%08x)\n", lcrr);
159         }
160
161 #ifdef CONFIG_CPM2
162         printf("CPM:  %lu Mhz\n", sysinfo.freqSystemBus / 1000000);
163 #endif
164
165         puts("L1:    D-cache 32 kB enabled\n       I-cache 32 kB enabled\n");
166
167         return 0;
168 }
169
170
171 /* ------------------------------------------------------------------------- */
172
173 int do_reset (cmd_tbl_t *cmdtp, bd_t *bd, int flag, int argc, char *argv[])
174 {
175         uint pvr;
176         uint ver;
177         unsigned long val, msr;
178
179         pvr = get_pvr();
180         ver = PVR_VER(pvr);
181
182         if (ver & 1){
183         /* e500 v2 core has reset control register */
184                 volatile unsigned int * rstcr;
185                 rstcr = (volatile unsigned int *)(CFG_IMMR + 0xE00B0);
186                 *rstcr = 0x2;           /* HRESET_REQ */
187                 udelay(100);
188         }
189
190         /*
191          * Fallthrough if the code above failed
192          * Initiate hard reset in debug control register DBCR0
193          * Make sure MSR[DE] = 1
194          */
195
196         msr = mfmsr ();
197         msr |= MSR_DE;
198         mtmsr (msr);
199
200         val = mfspr(DBCR0);
201         val |= 0x70000000;
202         mtspr(DBCR0,val);
203
204         return 1;
205 }
206
207
208 /*
209  * Get timebase clock frequency
210  */
211 unsigned long get_tbclk (void)
212 {
213         return (gd->bus_clk + 4UL)/8UL;
214 }
215
216
217 #if defined(CONFIG_WATCHDOG)
218 void
219 watchdog_reset(void)
220 {
221         int re_enable = disable_interrupts();
222         reset_85xx_watchdog();
223         if (re_enable) enable_interrupts();
224 }
225
226 void
227 reset_85xx_watchdog(void)
228 {
229         /*
230          * Clear TSR(WIS) bit by writing 1
231          */
232         unsigned long val;
233         val = mfspr(SPRN_TSR);
234         val |= TSR_WIS;
235         mtspr(SPRN_TSR, val);
236 }
237 #endif  /* CONFIG_WATCHDOG */
238
239 #if defined(CONFIG_DDR_ECC)
240 void dma_init(void) {
241         volatile ccsr_dma_t *dma = (void *)(CFG_MPC85xx_DMA_ADDR);
242
243         dma->satr0 = 0x02c40000;
244         dma->datr0 = 0x02c40000;
245         dma->sr0 = 0xfffffff; /* clear any errors */
246         asm("sync; isync; msync");
247         return;
248 }
249
250 uint dma_check(void) {
251         volatile ccsr_dma_t *dma = (void *)(CFG_MPC85xx_DMA_ADDR);
252         volatile uint status = dma->sr0;
253
254         /* While the channel is busy, spin */
255         while((status & 4) == 4) {
256                 status = dma->sr0;
257         }
258
259         /* clear MR0[CS] channel start bit */
260         dma->mr0 &= 0x00000001;
261         asm("sync;isync;msync");
262
263         if (status != 0) {
264                 printf ("DMA Error: status = %x\n", status);
265         }
266         return status;
267 }
268
269 int dma_xfer(void *dest, uint count, void *src) {
270         volatile ccsr_dma_t *dma = (void *)(CFG_MPC85xx_DMA_ADDR);
271
272         dma->dar0 = (uint) dest;
273         dma->sar0 = (uint) src;
274         dma->bcr0 = count;
275         dma->mr0 = 0xf000004;
276         asm("sync;isync;msync");
277         dma->mr0 = 0xf000005;
278         asm("sync;isync;msync");
279         return dma_check();
280 }
281 #endif