blob: bbc54448daa6951728b02938a22d8195721f1e4d [file] [log] [blame]
wdenk9c53f402003-10-15 23:53:47 +00001/*
Andy Flemingf631cca2007-04-23 01:32:22 -05002 * Copyright 2004,2007 Freescale Semiconductor, Inc.
wdenk9c53f402003-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 McClintock148e26a2006-06-28 10:43:36 -050033#if defined(CONFIG_OF_FLAT_TREE)
34#include <ft_build.h>
35#endif
36
wdenk9c53f402003-10-15 23:53:47 +000037
38int checkcpu (void)
39{
wdenka445ddf2004-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 Loeliger77a4f6e2005-07-25 14:05:07 -050044 uint fam;
wdenka445ddf2004-06-09 00:34:46 +000045 uint ver;
46 uint major, minor;
wdenk9c53f402003-10-15 23:53:47 +000047
wdenka445ddf2004-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
wdenk3f3262b2005-03-15 22:56:53 +000053 puts("CPU: ");
wdenka445ddf2004-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 Loeliger77a4f6e2005-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 Flemingf631cca2007-04-23 01:32:22 -050073 case SVR_8544:
Wolfgang Denk58c495b2007-05-05 18:23:11 +020074 puts("8544");
75 break;
76 case SVR_8544_E:
77 puts("8544_E");
78 break;
79 case SVR_8568_E:
80 puts("8568_E");
81 break;
wdenk9c53f402003-10-15 23:53:47 +000082 default:
wdenka445ddf2004-06-09 00:34:46 +000083 puts("Unknown");
wdenk9c53f402003-10-15 23:53:47 +000084 break;
85 }
wdenka445ddf2004-06-09 00:34:46 +000086 printf(", Version: %d.%d, (0x%08x)\n", major, minor, svr);
wdenk9c53f402003-10-15 23:53:47 +000087
wdenk3f3262b2005-03-15 22:56:53 +000088 pvr = get_pvr();
Jon Loeliger77a4f6e2005-07-25 14:05:07 -050089 fam = PVR_FAM(pvr);
wdenk3f3262b2005-03-15 22:56:53 +000090 ver = PVR_VER(pvr);
91 major = PVR_MAJ(pvr);
92 minor = PVR_MIN(pvr);
93
94 printf("Core: ");
Jon Loeliger77a4f6e2005-07-25 14:05:07 -050095 switch (fam) {
96 case PVR_FAM(PVR_85xx):
wdenk3f3262b2005-03-15 22:56:53 +000097 puts("E500");
98 break;
99 default:
100 puts("Unknown");
101 break;
102 }
103 printf(", Version: %d.%d, (0x%08x)\n", major, minor, pvr);
104
wdenka445ddf2004-06-09 00:34:46 +0000105 get_sys_info(&sysinfo);
106
Jon Loeliger77a4f6e2005-07-25 14:05:07 -0500107 puts("Clock Configuration:\n");
wdenk3f3262b2005-03-15 22:56:53 +0000108 printf(" CPU:%4lu MHz, ", sysinfo.freqProcessor / 1000000);
109 printf("CCB:%4lu MHz,\n", sysinfo.freqSystemBus / 1000000);
110 printf(" DDR:%4lu MHz, ", sysinfo.freqSystemBus / 2000000);
wdenka445ddf2004-06-09 00:34:46 +0000111
112#if defined(CFG_LBC_LCRR)
113 lcrr = CFG_LBC_LCRR;
114#else
115 {
116 volatile immap_t *immap = (immap_t *)CFG_IMMR;
117 volatile ccsr_lbc_t *lbc= &immap->im_lbc;
118
119 lcrr = lbc->lcrr;
120 }
121#endif
122 clkdiv = lcrr & 0x0f;
123 if (clkdiv == 2 || clkdiv == 4 || clkdiv == 8) {
Andy Flemingf631cca2007-04-23 01:32:22 -0500124#if defined(CONFIG_MPC8548) || defined(CONFIG_MPC8544)
Jon Loeliger77a4f6e2005-07-25 14:05:07 -0500125 /*
126 * Yes, the entire PQ38 family use the same
127 * bit-representation for twice the clock divider values.
128 */
129 clkdiv *= 2;
130#endif
wdenka445ddf2004-06-09 00:34:46 +0000131 printf("LBC:%4lu MHz\n",
132 sysinfo.freqSystemBus / 1000000 / clkdiv);
133 } else {
wdenk3f3262b2005-03-15 22:56:53 +0000134 printf("LBC: unknown (lcrr: 0x%08x)\n", lcrr);
wdenka445ddf2004-06-09 00:34:46 +0000135 }
136
137 if (ver == SVR_8560) {
wdenk3f3262b2005-03-15 22:56:53 +0000138 printf("CPM: %lu Mhz\n",
wdenka445ddf2004-06-09 00:34:46 +0000139 sysinfo.freqSystemBus / 1000000);
140 }
141
wdenk3f3262b2005-03-15 22:56:53 +0000142 puts("L1: D-cache 32 kB enabled\n I-cache 32 kB enabled\n");
wdenk9c53f402003-10-15 23:53:47 +0000143
144 return 0;
145}
146
147
148/* ------------------------------------------------------------------------- */
149
150int do_reset (cmd_tbl_t *cmdtp, bd_t *bd, int flag, int argc, char *argv[])
151{
Zang Roy-r61911395478d2006-12-05 16:42:30 +0800152 uint pvr;
153 uint ver;
154 pvr = get_pvr();
155 ver = PVR_VER(pvr);
156 if (ver & 1){
157 /* e500 v2 core has reset control register */
158 volatile unsigned int * rstcr;
159 rstcr = (volatile unsigned int *)(CFG_IMMR + 0xE00B0);
Wolfgang Denk58c495b2007-05-05 18:23:11 +0200160 *rstcr = 0x2; /* HRESET_REQ */
Zang Roy-r61911395478d2006-12-05 16:42:30 +0800161 }else{
wdenk9c53f402003-10-15 23:53:47 +0000162 /*
163 * Initiate hard reset in debug control register DBCR0
164 * Make sure MSR[DE] = 1
165 */
urwithsughosh@gmail.com06c2fb92007-09-24 13:32:13 -0400166 unsigned long val, msr;
167
168 msr = mfmsr ();
169 msr |= MSR_DE;
170 mtmsr (msr);
171
Zang Roy-r61911395478d2006-12-05 16:42:30 +0800172 val = mfspr(DBCR0);
173 val |= 0x70000000;
174 mtspr(DBCR0,val);
175 }
wdenk9c53f402003-10-15 23:53:47 +0000176 return 1;
177}
178
179
180/*
181 * Get timebase clock frequency
182 */
183unsigned long get_tbclk (void)
184{
185
186 sys_info_t sys_info;
187
188 get_sys_info(&sys_info);
wdenkd0245fc2005-04-13 10:02:42 +0000189 return ((sys_info.freqSystemBus + 7L) / 8L);
wdenk9c53f402003-10-15 23:53:47 +0000190}
191
192
193#if defined(CONFIG_WATCHDOG)
194void
195watchdog_reset(void)
196{
197 int re_enable = disable_interrupts();
198 reset_85xx_watchdog();
199 if (re_enable) enable_interrupts();
200}
201
202void
203reset_85xx_watchdog(void)
204{
205 /*
206 * Clear TSR(WIS) bit by writing 1
207 */
208 unsigned long val;
Andy Flemingeac342d2007-04-23 01:44:44 -0500209 val = mfspr(SPRN_TSR);
210 val |= TSR_WIS;
211 mtspr(SPRN_TSR, val);
wdenk9c53f402003-10-15 23:53:47 +0000212}
213#endif /* CONFIG_WATCHDOG */
214
215#if defined(CONFIG_DDR_ECC)
wdenk9c53f402003-10-15 23:53:47 +0000216void dma_init(void) {
217 volatile immap_t *immap = (immap_t *)CFG_IMMR;
218 volatile ccsr_dma_t *dma = &immap->im_dma;
219
220 dma->satr0 = 0x02c40000;
221 dma->datr0 = 0x02c40000;
Andy Flemingeac342d2007-04-23 01:44:44 -0500222 dma->sr0 = 0xfffffff; /* clear any errors */
wdenk9c53f402003-10-15 23:53:47 +0000223 asm("sync; isync; msync");
224 return;
225}
226
227uint dma_check(void) {
228 volatile immap_t *immap = (immap_t *)CFG_IMMR;
229 volatile ccsr_dma_t *dma = &immap->im_dma;
230 volatile uint status = dma->sr0;
231
232 /* While the channel is busy, spin */
233 while((status & 4) == 4) {
234 status = dma->sr0;
235 }
236
Andy Flemingeac342d2007-04-23 01:44:44 -0500237 /* clear MR0[CS] channel start bit */
238 dma->mr0 &= 0x00000001;
239 asm("sync;isync;msync");
240
wdenk9c53f402003-10-15 23:53:47 +0000241 if (status != 0) {
242 printf ("DMA Error: status = %x\n", status);
243 }
244 return status;
245}
246
247int dma_xfer(void *dest, uint count, void *src) {
248 volatile immap_t *immap = (immap_t *)CFG_IMMR;
249 volatile ccsr_dma_t *dma = &immap->im_dma;
250
251 dma->dar0 = (uint) dest;
252 dma->sar0 = (uint) src;
253 dma->bcr0 = count;
254 dma->mr0 = 0xf000004;
255 asm("sync;isync;msync");
256 dma->mr0 = 0xf000005;
257 asm("sync;isync;msync");
258 return dma_check();
259}
260#endif
Matthew McClintock148e26a2006-06-28 10:43:36 -0500261
262
263#ifdef CONFIG_OF_FLAT_TREE
264void
265ft_cpu_setup(void *blob, bd_t *bd)
266{
267 u32 *p;
268 ulong clock;
269 int len;
270
271 clock = bd->bi_busfreq;
272 p = ft_get_prop(blob, "/cpus/" OF_CPU "/bus-frequency", &len);
273 if (p != NULL)
274 *p = cpu_to_be32(clock);
275
Andy Fleming71706df2007-04-23 02:54:25 -0500276 p = ft_get_prop(blob, "/qe@e0080000/" OF_CPU "/bus-frequency", &len);
277 if (p != NULL)
278 *p = cpu_to_be32(clock);
279
Matthew McClintock148e26a2006-06-28 10:43:36 -0500280 p = ft_get_prop(blob, "/" OF_SOC "/serial@4500/clock-frequency", &len);
281 if (p != NULL)
282 *p = cpu_to_be32(clock);
283
284 p = ft_get_prop(blob, "/" OF_SOC "/serial@4600/clock-frequency", &len);
285 if (p != NULL)
286 *p = cpu_to_be32(clock);
287
Andy Flemingee0e9172007-08-14 00:14:25 -0500288#if defined(CONFIG_HAS_ETH0)
Matthew McClintock148e26a2006-06-28 10:43:36 -0500289 p = ft_get_prop(blob, "/" OF_SOC "/ethernet@24000/mac-address", &len);
Timur Tabi4399a512007-02-12 13:34:55 -0600290 if (p)
291 memcpy(p, bd->bi_enetaddr, 6);
292
293 p = ft_get_prop(blob, "/" OF_SOC "/ethernet@24000/local-mac-address", &len);
294 if (p)
Matthew McClintock148e26a2006-06-28 10:43:36 -0500295 memcpy(p, bd->bi_enetaddr, 6);
296#endif
297
298#if defined(CONFIG_HAS_ETH1)
299 p = ft_get_prop(blob, "/" OF_SOC "/ethernet@25000/mac-address", &len);
Timur Tabi4399a512007-02-12 13:34:55 -0600300 if (p)
301 memcpy(p, bd->bi_enet1addr, 6);
302
303 p = ft_get_prop(blob, "/" OF_SOC "/ethernet@25000/local-mac-address", &len);
304 if (p)
Matthew McClintock148e26a2006-06-28 10:43:36 -0500305 memcpy(p, bd->bi_enet1addr, 6);
306#endif
307
308#if defined(CONFIG_HAS_ETH2)
309 p = ft_get_prop(blob, "/" OF_SOC "/ethernet@26000/mac-address", &len);
Timur Tabi4399a512007-02-12 13:34:55 -0600310 if (p)
311 memcpy(p, bd->bi_enet2addr, 6);
312
313 p = ft_get_prop(blob, "/" OF_SOC "/ethernet@26000/local-mac-address", &len);
314 if (p)
Matthew McClintock148e26a2006-06-28 10:43:36 -0500315 memcpy(p, bd->bi_enet2addr, 6);
Andy Flemingee0e9172007-08-14 00:14:25 -0500316
317#ifdef CONFIG_UEC_ETH
318 p = ft_get_prop(blob, "/" OF_QE "/ucc@2000/mac-address", &len);
319 if (p)
320 memcpy(p, bd->bi_enet2addr, 6);
321
322 p = ft_get_prop(blob, "/" OF_QE "/ucc@2000/local-mac-address", &len);
323 if (p)
324 memcpy(p, bd->bi_enet2addr, 6);
325
326#endif
Matthew McClintock148e26a2006-06-28 10:43:36 -0500327#endif
328
329#if defined(CONFIG_HAS_ETH3)
330 p = ft_get_prop(blob, "/" OF_SOC "/ethernet@27000/mac-address", &len);
Timur Tabi4399a512007-02-12 13:34:55 -0600331 if (p)
332 memcpy(p, bd->bi_enet3addr, 6);
333
334 p = ft_get_prop(blob, "/" OF_SOC "/ethernet@27000/local-mac-address", &len);
335 if (p)
Matthew McClintock148e26a2006-06-28 10:43:36 -0500336 memcpy(p, bd->bi_enet3addr, 6);
Andy Flemingee0e9172007-08-14 00:14:25 -0500337
338#ifdef CONFIG_UEC_ETH
339 p = ft_get_prop(blob, "/" OF_QE "/ucc@3000/mac-address", &len);
340 if (p)
341 memcpy(p, bd->bi_enet3addr, 6);
342
343 p = ft_get_prop(blob, "/" OF_QE "/ucc@3000/local-mac-address", &len);
344 if (p)
345 memcpy(p, bd->bi_enet3addr, 6);
346
347#endif
Matthew McClintock148e26a2006-06-28 10:43:36 -0500348#endif
349
350}
351#endif