Merge with /home/sr/git/u-boot
[platform/kernel/u-boot.git] / cpu / mpc85xx / cpu.c
1 /*
2  * Copyright 2004 Freescale Semiconductor.
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 /* ------------------------------------------------------------------------- */
34
35 int checkcpu (void)
36 {
37         sys_info_t sysinfo;
38         uint lcrr;              /* local bus clock ratio register */
39         uint clkdiv;            /* clock divider portion of lcrr */
40         uint pvr, svr;
41         uint fam;
42         uint ver;
43         uint major, minor;
44
45         svr = get_svr();
46         ver = SVR_VER(svr);
47         major = SVR_MAJ(svr);
48         minor = SVR_MIN(svr);
49
50         puts("CPU:   ");
51         switch (ver) {
52         case SVR_8540:
53                 puts("8540");
54                 break;
55         case SVR_8541:
56                 puts("8541");
57                 break;
58         case SVR_8555:
59                 puts("8555");
60                 break;
61         case SVR_8560:
62                 puts("8560");
63                 break;
64         case SVR_8548:
65                 puts("8548");
66                 break;
67         case SVR_8548_E:
68                 puts("8548_E");
69                 break;
70         default:
71                 puts("Unknown");
72                 break;
73         }
74         printf(", Version: %d.%d, (0x%08x)\n", major, minor, svr);
75
76         pvr = get_pvr();
77         fam = PVR_FAM(pvr);
78         ver = PVR_VER(pvr);
79         major = PVR_MAJ(pvr);
80         minor = PVR_MIN(pvr);
81
82         printf("Core:  ");
83         switch (fam) {
84         case PVR_FAM(PVR_85xx):
85             puts("E500");
86             break;
87         default:
88             puts("Unknown");
89             break;
90         }
91         printf(", Version: %d.%d, (0x%08x)\n", major, minor, pvr);
92
93         get_sys_info(&sysinfo);
94
95         puts("Clock Configuration:\n");
96         printf("       CPU:%4lu MHz, ", sysinfo.freqProcessor / 1000000);
97         printf("CCB:%4lu MHz,\n", sysinfo.freqSystemBus / 1000000);
98         printf("       DDR:%4lu MHz, ", sysinfo.freqSystemBus / 2000000);
99
100 #if defined(CFG_LBC_LCRR)
101         lcrr = CFG_LBC_LCRR;
102 #else
103         {
104             volatile immap_t *immap = (immap_t *)CFG_IMMR;
105             volatile ccsr_lbc_t *lbc= &immap->im_lbc;
106
107             lcrr = lbc->lcrr;
108         }
109 #endif
110         clkdiv = lcrr & 0x0f;
111         if (clkdiv == 2 || clkdiv == 4 || clkdiv == 8) {
112 #ifdef CONFIG_MPC8548
113                 /*
114                  * Yes, the entire PQ38 family use the same
115                  * bit-representation for twice the clock divider values.
116                  */
117                  clkdiv *= 2;
118 #endif
119                 printf("LBC:%4lu MHz\n",
120                        sysinfo.freqSystemBus / 1000000 / clkdiv);
121         } else {
122                 printf("LBC: unknown (lcrr: 0x%08x)\n", lcrr);
123         }
124
125         if (ver == SVR_8560) {
126                 printf("CPM:  %lu Mhz\n",
127                        sysinfo.freqSystemBus / 1000000);
128         }
129
130         puts("L1:    D-cache 32 kB enabled\n       I-cache 32 kB enabled\n");
131
132         return 0;
133 }
134
135
136 /* ------------------------------------------------------------------------- */
137
138 int do_reset (cmd_tbl_t *cmdtp, bd_t *bd, int flag, int argc, char *argv[])
139 {
140         /*
141          * Initiate hard reset in debug control register DBCR0
142          * Make sure MSR[DE] = 1
143          */
144         unsigned long val;
145
146         val = mfspr(DBCR0);
147         val |= 0x70000000;
148         mtspr(DBCR0,val);
149
150         return 1;
151 }
152
153
154 /*
155  * Get timebase clock frequency
156  */
157 unsigned long get_tbclk (void)
158 {
159
160         sys_info_t  sys_info;
161
162         get_sys_info(&sys_info);
163         return ((sys_info.freqSystemBus + 7L) / 8L);
164 }
165
166
167 #if defined(CONFIG_WATCHDOG)
168 void
169 watchdog_reset(void)
170 {
171         int re_enable = disable_interrupts();
172         reset_85xx_watchdog();
173         if (re_enable) enable_interrupts();
174 }
175
176 void
177 reset_85xx_watchdog(void)
178 {
179         /*
180          * Clear TSR(WIS) bit by writing 1
181          */
182         unsigned long val;
183         val = mfspr(tsr);
184         val |= 0x40000000;
185         mtspr(tsr, val);
186 }
187 #endif  /* CONFIG_WATCHDOG */
188
189 #if defined(CONFIG_DDR_ECC)
190 void dma_init(void) {
191         volatile immap_t *immap = (immap_t *)CFG_IMMR;
192         volatile ccsr_dma_t *dma = &immap->im_dma;
193
194         dma->satr0 = 0x02c40000;
195         dma->datr0 = 0x02c40000;
196         asm("sync; isync; msync");
197         return;
198 }
199
200 uint dma_check(void) {
201         volatile immap_t *immap = (immap_t *)CFG_IMMR;
202         volatile ccsr_dma_t *dma = &immap->im_dma;
203         volatile uint status = dma->sr0;
204
205         /* While the channel is busy, spin */
206         while((status & 4) == 4) {
207                 status = dma->sr0;
208         }
209
210         if (status != 0) {
211                 printf ("DMA Error: status = %x\n", status);
212         }
213         return status;
214 }
215
216 int dma_xfer(void *dest, uint count, void *src) {
217         volatile immap_t *immap = (immap_t *)CFG_IMMR;
218         volatile ccsr_dma_t *dma = &immap->im_dma;
219
220         dma->dar0 = (uint) dest;
221         dma->sar0 = (uint) src;
222         dma->bcr0 = count;
223         dma->mr0 = 0xf000004;
224         asm("sync;isync;msync");
225         dma->mr0 = 0xf000005;
226         asm("sync;isync;msync");
227         return dma_check();
228 }
229 #endif