blob: d5102dfddfd64f4852c175530bfd38d19b93ef65 [file] [log] [blame]
wdenk42d1f032003-10-15 23:53:47 +00001/*
Andy Fleming151d5d92007-04-23 01:32:22 -05002 * Copyright 2004,2007 Freescale Semiconductor, Inc.
wdenk42d1f032003-10-15 23:53:47 +00003 * (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
Matthew McClintock40d5fa32006-06-28 10:43:36 -050033#if defined(CONFIG_OF_FLAT_TREE)
34#include <ft_build.h>
35#endif
36
wdenk42d1f032003-10-15 23:53:47 +000037
38int checkcpu (void)
39{
wdenk97d80fc2004-06-09 00:34:46 +000040 sys_info_t sysinfo;
41 uint lcrr; /* local bus clock ratio register */
42 uint clkdiv; /* clock divider portion of lcrr */
43 uint pvr, svr;
Jon Loeligerd9b94f22005-07-25 14:05:07 -050044 uint fam;
wdenk97d80fc2004-06-09 00:34:46 +000045 uint ver;
46 uint major, minor;
wdenk42d1f032003-10-15 23:53:47 +000047
wdenk97d80fc2004-06-09 00:34:46 +000048 svr = get_svr();
49 ver = SVR_VER(svr);
50 major = SVR_MAJ(svr);
51 minor = SVR_MIN(svr);
52
wdenk6c9e7892005-03-15 22:56:53 +000053 puts("CPU: ");
wdenk97d80fc2004-06-09 00:34:46 +000054 switch (ver) {
55 case SVR_8540:
56 puts("8540");
57 break;
58 case SVR_8541:
59 puts("8541");
60 break;
61 case SVR_8555:
62 puts("8555");
63 break;
64 case SVR_8560:
65 puts("8560");
66 break;
Jon Loeligerd9b94f22005-07-25 14:05:07 -050067 case SVR_8548:
68 puts("8548");
69 break;
70 case SVR_8548_E:
71 puts("8548_E");
72 break;
Andy Fleming151d5d92007-04-23 01:32:22 -050073 case SVR_8544:
74 puts("8544");
75 break;
76 case SVR_8544_E:
77 puts("8544_E");
78 break;
wdenk97d80fc2004-06-09 00:34:46 +000079 default:
80 puts("Unknown");
wdenk42d1f032003-10-15 23:53:47 +000081 break;
82 }
wdenk97d80fc2004-06-09 00:34:46 +000083 printf(", Version: %d.%d, (0x%08x)\n", major, minor, svr);
wdenk42d1f032003-10-15 23:53:47 +000084
wdenk6c9e7892005-03-15 22:56:53 +000085 pvr = get_pvr();
Jon Loeligerd9b94f22005-07-25 14:05:07 -050086 fam = PVR_FAM(pvr);
wdenk6c9e7892005-03-15 22:56:53 +000087 ver = PVR_VER(pvr);
88 major = PVR_MAJ(pvr);
89 minor = PVR_MIN(pvr);
90
91 printf("Core: ");
Jon Loeligerd9b94f22005-07-25 14:05:07 -050092 switch (fam) {
93 case PVR_FAM(PVR_85xx):
wdenk6c9e7892005-03-15 22:56:53 +000094 puts("E500");
95 break;
96 default:
97 puts("Unknown");
98 break;
99 }
100 printf(", Version: %d.%d, (0x%08x)\n", major, minor, pvr);
101
wdenk97d80fc2004-06-09 00:34:46 +0000102 get_sys_info(&sysinfo);
103
Jon Loeligerd9b94f22005-07-25 14:05:07 -0500104 puts("Clock Configuration:\n");
wdenk6c9e7892005-03-15 22:56:53 +0000105 printf(" CPU:%4lu MHz, ", sysinfo.freqProcessor / 1000000);
106 printf("CCB:%4lu MHz,\n", sysinfo.freqSystemBus / 1000000);
107 printf(" DDR:%4lu MHz, ", sysinfo.freqSystemBus / 2000000);
wdenk97d80fc2004-06-09 00:34:46 +0000108
109#if defined(CFG_LBC_LCRR)
110 lcrr = CFG_LBC_LCRR;
111#else
112 {
113 volatile immap_t *immap = (immap_t *)CFG_IMMR;
114 volatile ccsr_lbc_t *lbc= &immap->im_lbc;
115
116 lcrr = lbc->lcrr;
117 }
118#endif
119 clkdiv = lcrr & 0x0f;
120 if (clkdiv == 2 || clkdiv == 4 || clkdiv == 8) {
Andy Fleming151d5d92007-04-23 01:32:22 -0500121#if defined(CONFIG_MPC8548) || defined(CONFIG_MPC8544)
Jon Loeligerd9b94f22005-07-25 14:05:07 -0500122 /*
123 * Yes, the entire PQ38 family use the same
124 * bit-representation for twice the clock divider values.
125 */
126 clkdiv *= 2;
127#endif
wdenk97d80fc2004-06-09 00:34:46 +0000128 printf("LBC:%4lu MHz\n",
129 sysinfo.freqSystemBus / 1000000 / clkdiv);
130 } else {
wdenk6c9e7892005-03-15 22:56:53 +0000131 printf("LBC: unknown (lcrr: 0x%08x)\n", lcrr);
wdenk97d80fc2004-06-09 00:34:46 +0000132 }
133
134 if (ver == SVR_8560) {
wdenk6c9e7892005-03-15 22:56:53 +0000135 printf("CPM: %lu Mhz\n",
wdenk97d80fc2004-06-09 00:34:46 +0000136 sysinfo.freqSystemBus / 1000000);
137 }
138
wdenk6c9e7892005-03-15 22:56:53 +0000139 puts("L1: D-cache 32 kB enabled\n I-cache 32 kB enabled\n");
wdenk42d1f032003-10-15 23:53:47 +0000140
141 return 0;
142}
143
144
145/* ------------------------------------------------------------------------- */
146
147int do_reset (cmd_tbl_t *cmdtp, bd_t *bd, int flag, int argc, char *argv[])
148{
Zang Roy-r6191196629cb2006-12-05 16:42:30 +0800149 uint pvr;
150 uint ver;
151 pvr = get_pvr();
152 ver = PVR_VER(pvr);
153 if (ver & 1){
154 /* e500 v2 core has reset control register */
155 volatile unsigned int * rstcr;
156 rstcr = (volatile unsigned int *)(CFG_IMMR + 0xE00B0);
157 *rstcr = 0x2; /* HRESET_REQ */
158 }else{
wdenk42d1f032003-10-15 23:53:47 +0000159 /*
160 * Initiate hard reset in debug control register DBCR0
161 * Make sure MSR[DE] = 1
162 */
Zang Roy-r6191196629cb2006-12-05 16:42:30 +0800163 unsigned long val;
164 val = mfspr(DBCR0);
165 val |= 0x70000000;
166 mtspr(DBCR0,val);
167 }
wdenk42d1f032003-10-15 23:53:47 +0000168 return 1;
169}
170
171
172/*
173 * Get timebase clock frequency
174 */
175unsigned long get_tbclk (void)
176{
177
178 sys_info_t sys_info;
179
180 get_sys_info(&sys_info);
wdenk2a8af182005-04-13 10:02:42 +0000181 return ((sys_info.freqSystemBus + 7L) / 8L);
wdenk42d1f032003-10-15 23:53:47 +0000182}
183
184
185#if defined(CONFIG_WATCHDOG)
186void
187watchdog_reset(void)
188{
189 int re_enable = disable_interrupts();
190 reset_85xx_watchdog();
191 if (re_enable) enable_interrupts();
192}
193
194void
195reset_85xx_watchdog(void)
196{
197 /*
198 * Clear TSR(WIS) bit by writing 1
199 */
200 unsigned long val;
Andy Fleming03b81b42007-04-23 01:44:44 -0500201 val = mfspr(SPRN_TSR);
202 val |= TSR_WIS;
203 mtspr(SPRN_TSR, val);
wdenk42d1f032003-10-15 23:53:47 +0000204}
205#endif /* CONFIG_WATCHDOG */
206
207#if defined(CONFIG_DDR_ECC)
wdenk42d1f032003-10-15 23:53:47 +0000208void dma_init(void) {
209 volatile immap_t *immap = (immap_t *)CFG_IMMR;
210 volatile ccsr_dma_t *dma = &immap->im_dma;
211
212 dma->satr0 = 0x02c40000;
213 dma->datr0 = 0x02c40000;
Andy Fleming03b81b42007-04-23 01:44:44 -0500214 dma->sr0 = 0xfffffff; /* clear any errors */
wdenk42d1f032003-10-15 23:53:47 +0000215 asm("sync; isync; msync");
216 return;
217}
218
219uint dma_check(void) {
220 volatile immap_t *immap = (immap_t *)CFG_IMMR;
221 volatile ccsr_dma_t *dma = &immap->im_dma;
222 volatile uint status = dma->sr0;
223
224 /* While the channel is busy, spin */
225 while((status & 4) == 4) {
226 status = dma->sr0;
227 }
228
Andy Fleming03b81b42007-04-23 01:44:44 -0500229 /* clear MR0[CS] channel start bit */
230 dma->mr0 &= 0x00000001;
231 asm("sync;isync;msync");
232
wdenk42d1f032003-10-15 23:53:47 +0000233 if (status != 0) {
234 printf ("DMA Error: status = %x\n", status);
235 }
236 return status;
237}
238
239int dma_xfer(void *dest, uint count, void *src) {
240 volatile immap_t *immap = (immap_t *)CFG_IMMR;
241 volatile ccsr_dma_t *dma = &immap->im_dma;
242
243 dma->dar0 = (uint) dest;
244 dma->sar0 = (uint) src;
245 dma->bcr0 = count;
246 dma->mr0 = 0xf000004;
247 asm("sync;isync;msync");
248 dma->mr0 = 0xf000005;
249 asm("sync;isync;msync");
250 return dma_check();
251}
252#endif
Matthew McClintock40d5fa32006-06-28 10:43:36 -0500253
254
255#ifdef CONFIG_OF_FLAT_TREE
256void
257ft_cpu_setup(void *blob, bd_t *bd)
258{
259 u32 *p;
260 ulong clock;
261 int len;
262
263 clock = bd->bi_busfreq;
264 p = ft_get_prop(blob, "/cpus/" OF_CPU "/bus-frequency", &len);
265 if (p != NULL)
266 *p = cpu_to_be32(clock);
267
268 p = ft_get_prop(blob, "/" OF_SOC "/serial@4500/clock-frequency", &len);
269 if (p != NULL)
270 *p = cpu_to_be32(clock);
271
272 p = ft_get_prop(blob, "/" OF_SOC "/serial@4600/clock-frequency", &len);
273 if (p != NULL)
274 *p = cpu_to_be32(clock);
275
276#if defined(CONFIG_MPC85XX_TSEC1)
277 p = ft_get_prop(blob, "/" OF_SOC "/ethernet@24000/mac-address", &len);
Timur Tabi85e7c7a2007-02-12 13:34:55 -0600278 if (p)
279 memcpy(p, bd->bi_enetaddr, 6);
280
281 p = ft_get_prop(blob, "/" OF_SOC "/ethernet@24000/local-mac-address", &len);
282 if (p)
Matthew McClintock40d5fa32006-06-28 10:43:36 -0500283 memcpy(p, bd->bi_enetaddr, 6);
284#endif
285
286#if defined(CONFIG_HAS_ETH1)
287 p = ft_get_prop(blob, "/" OF_SOC "/ethernet@25000/mac-address", &len);
Timur Tabi85e7c7a2007-02-12 13:34:55 -0600288 if (p)
289 memcpy(p, bd->bi_enet1addr, 6);
290
291 p = ft_get_prop(blob, "/" OF_SOC "/ethernet@25000/local-mac-address", &len);
292 if (p)
Matthew McClintock40d5fa32006-06-28 10:43:36 -0500293 memcpy(p, bd->bi_enet1addr, 6);
294#endif
295
296#if defined(CONFIG_HAS_ETH2)
297 p = ft_get_prop(blob, "/" OF_SOC "/ethernet@26000/mac-address", &len);
Timur Tabi85e7c7a2007-02-12 13:34:55 -0600298 if (p)
299 memcpy(p, bd->bi_enet2addr, 6);
300
301 p = ft_get_prop(blob, "/" OF_SOC "/ethernet@26000/local-mac-address", &len);
302 if (p)
Matthew McClintock40d5fa32006-06-28 10:43:36 -0500303 memcpy(p, bd->bi_enet2addr, 6);
304#endif
305
306#if defined(CONFIG_HAS_ETH3)
307 p = ft_get_prop(blob, "/" OF_SOC "/ethernet@27000/mac-address", &len);
Timur Tabi85e7c7a2007-02-12 13:34:55 -0600308 if (p)
309 memcpy(p, bd->bi_enet3addr, 6);
310
311 p = ft_get_prop(blob, "/" OF_SOC "/ethernet@27000/local-mac-address", &len);
312 if (p)
Matthew McClintock40d5fa32006-06-28 10:43:36 -0500313 memcpy(p, bd->bi_enet3addr, 6);
314#endif
315
316}
317#endif