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