blob: e1b3c52dcdc5e485d9c9ff828de86bd38b6bce63 [file] [log] [blame]
Jon Loeliger5c8aa972006-04-26 17:58:56 -05001/*
Jon Loeligere65e32e2006-05-31 12:44:44 -05002 * Copyright 2006 Freescale Semiconductor
3 * Jeff Brown
Jon Loeliger5c8aa972006-04-26 17:58:56 -05004 * Srikanth Srinivasan (srikanth.srinivasan@freescale.com)
5 *
6 * See file CREDITS for list of people who contributed to this
7 * project.
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License as
11 * published by the Free Software Foundation; either version 2 of
12 * the License, or (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
22 * MA 02111-1307 USA
23 */
24
25#include <common.h>
26#include <watchdog.h>
27#include <command.h>
28#include <asm/cache.h>
29#include <mpc86xx.h>
Becky Bruceb0b30942008-01-23 16:31:06 -060030#include <asm/fsl_law.h>
Jon Loeliger5c8aa972006-04-26 17:58:56 -050031
32#if defined(CONFIG_OF_FLAT_TREE)
33#include <ft_build.h>
34#endif
35
Jon Loeligera1295442006-08-22 12:06:18 -050036int
37checkcpu(void)
Jon Loeliger5c8aa972006-04-26 17:58:56 -050038{
39 sys_info_t sysinfo;
40 uint pvr, svr;
41 uint ver;
42 uint major, minor;
43 uint lcrr; /* local bus clock ratio register */
44 uint clkdiv; /* clock divider portion of lcrr */
Jon Loeliger3b971c92007-10-16 15:26:51 -050045 volatile immap_t *immap = (immap_t *) CFG_IMMR;
46 volatile ccsr_gur_t *gur = &immap->im_gur;
Jon Loeliger465b9d82006-04-27 10:15:16 -050047
Jon Loeliger5c8aa972006-04-26 17:58:56 -050048 puts("Freescale PowerPC\n");
49
50 pvr = get_pvr();
51 ver = PVR_VER(pvr);
52 major = PVR_MAJ(pvr);
53 minor = PVR_MIN(pvr);
54
Jon Loeliger465b9d82006-04-27 10:15:16 -050055 puts("CPU:\n");
Jon Loeligere65e32e2006-05-31 12:44:44 -050056 puts(" Core: ");
Jon Loeliger465b9d82006-04-27 10:15:16 -050057
Jon Loeliger5c8aa972006-04-26 17:58:56 -050058 switch (ver) {
59 case PVR_VER(PVR_86xx):
Jon Loeliger3b971c92007-10-16 15:26:51 -050060 {
61 uint msscr0 = mfspr(MSSCR0);
62 printf("E600 Core %d", (msscr0 & 0x20) ? 1 : 0 );
63 if (gur->pordevsr & MPC86xx_PORDEVSR_CORE1TE)
64 puts("\n Core1Translation Enabled");
65 debug(" (MSSCR0=%x, PORDEVSR=%x)", msscr0, gur->pordevsr);
66 }
67 break;
Jon Loeliger5c8aa972006-04-26 17:58:56 -050068 default:
Jon Loeligera1295442006-08-22 12:06:18 -050069 puts("Unknown");
70 break;
Jon Loeliger5c8aa972006-04-26 17:58:56 -050071 }
72 printf(", Version: %d.%d, (0x%08x)\n", major, minor, pvr);
73
74 svr = get_svr();
75 ver = SVR_VER(svr);
76 major = SVR_MAJ(svr);
77 minor = SVR_MIN(svr);
78
79 puts(" System: ");
Jon Loeliger465b9d82006-04-27 10:15:16 -050080 switch (ver) {
Jon Loeliger5c8aa972006-04-26 17:58:56 -050081 case SVR_8641:
Jon Loeligerf57e8292006-09-14 08:40:36 -050082 if (SVR_SUBVER(svr) == 1) {
Jon Loeliger5c8aa972006-04-26 17:58:56 -050083 puts("8641D");
Jon Loeligerf57e8292006-09-14 08:40:36 -050084 } else {
85 puts("8641");
86 }
87 break;
Jon Loeliger3b971c92007-10-16 15:26:51 -050088 case SVR_8610:
89 puts("8610");
90 break;
Jon Loeliger5c8aa972006-04-26 17:58:56 -050091 default:
92 puts("Unknown");
93 break;
94 }
95 printf(", Version: %d.%d, (0x%08x)\n", major, minor, svr);
96
97 get_sys_info(&sysinfo);
98
99 puts(" Clocks: ");
100 printf("CPU:%4lu MHz, ", sysinfo.freqProcessor / 1000000);
101 printf("MPX:%4lu MHz, ", sysinfo.freqSystemBus / 1000000);
102 printf("DDR:%4lu MHz, ", sysinfo.freqSystemBus / 2000000);
Jon Loeliger465b9d82006-04-27 10:15:16 -0500103
Jon Loeliger5c8aa972006-04-26 17:58:56 -0500104#if defined(CFG_LBC_LCRR)
105 lcrr = CFG_LBC_LCRR;
106#else
107 {
Jon Loeligera1295442006-08-22 12:06:18 -0500108 volatile immap_t *immap = (immap_t *) CFG_IMMR;
109 volatile ccsr_lbc_t *lbc = &immap->im_lbc;
Jon Loeliger5c8aa972006-04-26 17:58:56 -0500110
Jon Loeligera1295442006-08-22 12:06:18 -0500111 lcrr = lbc->lcrr;
Jon Loeliger5c8aa972006-04-26 17:58:56 -0500112 }
113#endif
114 clkdiv = lcrr & 0x0f;
115 if (clkdiv == 2 || clkdiv == 4 || clkdiv == 8) {
116 printf("LBC:%4lu MHz\n",
117 sysinfo.freqSystemBus / 1000000 / clkdiv);
118 } else {
119 printf(" LBC: unknown (lcrr: 0x%08x)\n", lcrr);
120 }
121
Jon Loeligere65e32e2006-05-31 12:44:44 -0500122 puts(" L2: ");
Jon Loeligerd68e2ba2006-05-30 17:47:00 -0500123 if (get_l2cr() & 0x80000000)
Jon Loeligere65e32e2006-05-31 12:44:44 -0500124 puts("Enabled\n");
Jon Loeligerd68e2ba2006-05-30 17:47:00 -0500125 else
Jon Loeligere65e32e2006-05-31 12:44:44 -0500126 puts("Disabled\n");
Jon Loeliger465b9d82006-04-27 10:15:16 -0500127
128 return 0;
Jon Loeliger5c8aa972006-04-26 17:58:56 -0500129}
130
131
Jon Loeliger5c8aa972006-04-26 17:58:56 -0500132static inline void
133soft_restart(unsigned long addr)
134{
Jason Jin333dd1d2007-10-26 18:32:00 +0800135#if !defined(CONFIG_MPC8641HPCN) && !defined(CONFIG_MPC8610HPCD)
Jon Loeliger465b9d82006-04-27 10:15:16 -0500136
Jon Loeligera1295442006-08-22 12:06:18 -0500137 /*
138 * SRR0 has system reset vector, SRR1 has default MSR value
139 * rfi restores MSR from SRR1 and sets the PC to the SRR0 value
140 */
Jon Loeliger5c8aa972006-04-26 17:58:56 -0500141
142 __asm__ __volatile__ ("mtspr 26, %0" :: "r" (addr));
143 __asm__ __volatile__ ("li 4, (1 << 6)" ::: "r4");
144 __asm__ __volatile__ ("mtspr 27, 4");
145 __asm__ __volatile__ ("rfi");
146
147#else /* CONFIG_MPC8641HPCN */
Jon Loeligere65e32e2006-05-31 12:44:44 -0500148
149 out8(PIXIS_BASE + PIXIS_RST, 0);
150
Jon Loeliger5c8aa972006-04-26 17:58:56 -0500151#endif /* !CONFIG_MPC8641HPCN */
Jon Loeligere65e32e2006-05-31 12:44:44 -0500152
Jon Loeligera1295442006-08-22 12:06:18 -0500153 while (1) ; /* not reached */
Jon Loeliger5c8aa972006-04-26 17:58:56 -0500154}
155
156
Jon Loeligerd68e2ba2006-05-30 17:47:00 -0500157/*
158 * No generic way to do board reset. Simply call soft_reset.
159 */
Jon Loeliger5c8aa972006-04-26 17:58:56 -0500160void
Jon Loeligerd68e2ba2006-05-30 17:47:00 -0500161do_reset(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
Jon Loeliger5c8aa972006-04-26 17:58:56 -0500162{
Jason Jin333dd1d2007-10-26 18:32:00 +0800163#if !defined(CONFIG_MPC8641HPCN) && !defined(CONFIG_MPC8610HPCD)
Jon Loeliger5c8aa972006-04-26 17:58:56 -0500164
165#ifdef CFG_RESET_ADDRESS
Jon Loeligere65e32e2006-05-31 12:44:44 -0500166 ulong addr = CFG_RESET_ADDRESS;
Jon Loeliger5c8aa972006-04-26 17:58:56 -0500167#else
168 /*
169 * note: when CFG_MONITOR_BASE points to a RAM address,
170 * CFG_MONITOR_BASE - sizeof (ulong) is usually a valid
171 * address. Better pick an address known to be invalid on your
172 * system and assign it to CFG_RESET_ADDRESS.
173 */
Jon Loeligere65e32e2006-05-31 12:44:44 -0500174 ulong addr = CFG_MONITOR_BASE - sizeof(ulong);
Jon Loeliger5c8aa972006-04-26 17:58:56 -0500175#endif
176
Jon Loeliger465b9d82006-04-27 10:15:16 -0500177 /* flush and disable I/D cache */
Jon Loeliger5c8aa972006-04-26 17:58:56 -0500178 __asm__ __volatile__ ("mfspr 3, 1008" ::: "r3");
179 __asm__ __volatile__ ("ori 5, 5, 0xcc00" ::: "r5");
180 __asm__ __volatile__ ("ori 4, 3, 0xc00" ::: "r4");
181 __asm__ __volatile__ ("andc 5, 3, 5" ::: "r5");
182 __asm__ __volatile__ ("sync");
183 __asm__ __volatile__ ("mtspr 1008, 4");
184 __asm__ __volatile__ ("isync");
185 __asm__ __volatile__ ("sync");
186 __asm__ __volatile__ ("mtspr 1008, 5");
187 __asm__ __volatile__ ("isync");
188 __asm__ __volatile__ ("sync");
189
Jon Loeligerd68e2ba2006-05-30 17:47:00 -0500190 soft_restart(addr);
Jon Loeliger5c8aa972006-04-26 17:58:56 -0500191
192#else /* CONFIG_MPC8641HPCN */
Jon Loeliger465b9d82006-04-27 10:15:16 -0500193
Haiying Wang57b6e9c2007-01-22 12:37:30 -0600194 out8(PIXIS_BASE + PIXIS_RST, 0);
Jon Loeliger465b9d82006-04-27 10:15:16 -0500195
Jon Loeliger5c8aa972006-04-26 17:58:56 -0500196#endif /* !CONFIG_MPC8641HPCN */
Jon Loeliger465b9d82006-04-27 10:15:16 -0500197
Jon Loeligera1295442006-08-22 12:06:18 -0500198 while (1) ; /* not reached */
Jon Loeliger5c8aa972006-04-26 17:58:56 -0500199}
200
201
Jon Loeliger5c8aa972006-04-26 17:58:56 -0500202/*
203 * Get timebase clock frequency
204 */
Jon Loeligera1295442006-08-22 12:06:18 -0500205unsigned long
206get_tbclk(void)
Jon Loeliger5c8aa972006-04-26 17:58:56 -0500207{
Jon Loeligera1295442006-08-22 12:06:18 -0500208 sys_info_t sys_info;
Jon Loeliger5c8aa972006-04-26 17:58:56 -0500209
210 get_sys_info(&sys_info);
Jon Loeliger465b9d82006-04-27 10:15:16 -0500211 return (sys_info.freqSystemBus + 3L) / 4L;
Jon Loeliger5c8aa972006-04-26 17:58:56 -0500212}
213
Jon Loeliger5c8aa972006-04-26 17:58:56 -0500214
215#if defined(CONFIG_WATCHDOG)
216void
217watchdog_reset(void)
218{
Jon Loeliger5c8aa972006-04-26 17:58:56 -0500219}
220#endif /* CONFIG_WATCHDOG */
221
Jon Loeliger5c8aa972006-04-26 17:58:56 -0500222
223#if defined(CONFIG_DDR_ECC)
Jon Loeligera1295442006-08-22 12:06:18 -0500224void
225dma_init(void)
Jon Loeliger465b9d82006-04-27 10:15:16 -0500226{
Jon Loeligera1295442006-08-22 12:06:18 -0500227 volatile immap_t *immap = (immap_t *) CFG_IMMR;
Jon Loeliger5c8aa972006-04-26 17:58:56 -0500228 volatile ccsr_dma_t *dma = &immap->im_dma;
229
230 dma->satr0 = 0x00040000;
231 dma->datr0 = 0x00040000;
232 asm("sync; isync");
Jon Loeliger5c8aa972006-04-26 17:58:56 -0500233}
234
Jon Loeligera1295442006-08-22 12:06:18 -0500235uint
236dma_check(void)
Jon Loeliger465b9d82006-04-27 10:15:16 -0500237{
Jon Loeligera1295442006-08-22 12:06:18 -0500238 volatile immap_t *immap = (immap_t *) CFG_IMMR;
Jon Loeliger5c8aa972006-04-26 17:58:56 -0500239 volatile ccsr_dma_t *dma = &immap->im_dma;
240 volatile uint status = dma->sr0;
241
242 /* While the channel is busy, spin */
Jon Loeligera1295442006-08-22 12:06:18 -0500243 while ((status & 4) == 4) {
Jon Loeliger5c8aa972006-04-26 17:58:56 -0500244 status = dma->sr0;
245 }
246
247 if (status != 0) {
Jon Loeligera1295442006-08-22 12:06:18 -0500248 printf("DMA Error: status = %x\n", status);
Jon Loeliger5c8aa972006-04-26 17:58:56 -0500249 }
250 return status;
251}
252
Jon Loeligera1295442006-08-22 12:06:18 -0500253int
254dma_xfer(void *dest, uint count, void *src)
Jon Loeliger465b9d82006-04-27 10:15:16 -0500255{
Jon Loeligera1295442006-08-22 12:06:18 -0500256 volatile immap_t *immap = (immap_t *) CFG_IMMR;
Jon Loeliger5c8aa972006-04-26 17:58:56 -0500257 volatile ccsr_dma_t *dma = &immap->im_dma;
258
259 dma->dar0 = (uint) dest;
260 dma->sar0 = (uint) src;
261 dma->bcr0 = count;
262 dma->mr0 = 0xf000004;
263 asm("sync;isync");
264 dma->mr0 = 0xf000005;
265 asm("sync;isync");
266 return dma_check();
267}
Jon Loeliger465b9d82006-04-27 10:15:16 -0500268
Jon Loeliger5c8aa972006-04-26 17:58:56 -0500269#endif /* CONFIG_DDR_ECC */
270
271
272#ifdef CONFIG_OF_FLAT_TREE
Jon Loeligera1295442006-08-22 12:06:18 -0500273void
274ft_cpu_setup(void *blob, bd_t *bd)
Jon Loeliger5c8aa972006-04-26 17:58:56 -0500275{
276 u32 *p;
277 ulong clock;
278 int len;
Jon Loeliger465b9d82006-04-27 10:15:16 -0500279
Jon Loeliger5c8aa972006-04-26 17:58:56 -0500280 clock = bd->bi_busfreq;
281 p = ft_get_prop(blob, "/cpus/" OF_CPU "/bus-frequency", &len);
282 if (p != NULL)
283 *p = cpu_to_be32(clock);
284
285 p = ft_get_prop(blob, "/" OF_SOC "/serial@4500/clock-frequency", &len);
286 if (p != NULL)
287 *p = cpu_to_be32(clock);
288
289 p = ft_get_prop(blob, "/" OF_SOC "/serial@4600/clock-frequency", &len);
290 if (p != NULL)
291 *p = cpu_to_be32(clock);
292
Kim Phillips177e58f2007-05-16 16:52:19 -0500293#if defined(CONFIG_TSEC1)
Jon Loeliger58957a52006-08-03 16:17:56 -0500294 p = ft_get_prop(blob, "/" OF_SOC "/ethernet@24000/mac-address", &len);
Jon Loeliger176f5092007-04-20 14:11:38 -0500295 if (p != NULL)
296 memcpy(p, bd->bi_enetaddr, 6);
Jon Loeligerabe7bd02007-04-20 14:12:26 -0500297 p = ft_get_prop(blob, "/" OF_SOC "/ethernet@24000/local-mac-address", &len);
298 if (p)
299 memcpy(p, bd->bi_enetaddr, 6);
Jon Loeliger5c8aa972006-04-26 17:58:56 -0500300#endif
Jon Loeliger465b9d82006-04-27 10:15:16 -0500301
Kim Phillips177e58f2007-05-16 16:52:19 -0500302#if defined(CONFIG_TSEC2)
Jon Loeliger58957a52006-08-03 16:17:56 -0500303 p = ft_get_prop(blob, "/" OF_SOC "/ethernet@25000/mac-address", &len);
Jon Loeliger176f5092007-04-20 14:11:38 -0500304 if (p != NULL)
305 memcpy(p, bd->bi_enet1addr, 6);
Jon Loeligerabe7bd02007-04-20 14:12:26 -0500306 p = ft_get_prop(blob, "/" OF_SOC "/ethernet@25000/local-mac-address", &len);
307 if (p != NULL)
308 memcpy(p, bd->bi_enet1addr, 6);
Jon Loeliger5c8aa972006-04-26 17:58:56 -0500309#endif
310
Kim Phillips177e58f2007-05-16 16:52:19 -0500311#if defined(CONFIG_TSEC3)
Jon Loeliger58957a52006-08-03 16:17:56 -0500312 p = ft_get_prop(blob, "/" OF_SOC "/ethernet@26000/mac-address", &len);
Jon Loeliger176f5092007-04-20 14:11:38 -0500313 if (p != NULL)
314 memcpy(p, bd->bi_enet2addr, 6);
Jon Loeligerabe7bd02007-04-20 14:12:26 -0500315 p = ft_get_prop(blob, "/" OF_SOC "/ethernet@26000/local-mac-address", &len);
316 if (p != NULL)
317 memcpy(p, bd->bi_enet2addr, 6);
Jon Loeliger5c8aa972006-04-26 17:58:56 -0500318#endif
319
Kim Phillips177e58f2007-05-16 16:52:19 -0500320#if defined(CONFIG_TSEC4)
Jon Loeliger58957a52006-08-03 16:17:56 -0500321 p = ft_get_prop(blob, "/" OF_SOC "/ethernet@27000/mac-address", &len);
Jon Loeliger176f5092007-04-20 14:11:38 -0500322 if (p != NULL)
323 memcpy(p, bd->bi_enet3addr, 6);
Jon Loeligerabe7bd02007-04-20 14:12:26 -0500324 p = ft_get_prop(blob, "/" OF_SOC "/ethernet@27000/local-mac-address", &len);
325 if (p != NULL)
326 memcpy(p, bd->bi_enet3addr, 6);
Jon Loeliger5c8aa972006-04-26 17:58:56 -0500327#endif
Becky Bruceb0b30942008-01-23 16:31:06 -0600328#endif /* CONFIG_OF_FLAT_TREE */
329
330/*
331 * Print out the state of various machine registers.
332 * Currently prints out LAWs and BR0/OR0
333 */
334void mpc86xx_reginfo(void)
335{
336 immap_t *immap = (immap_t *)CFG_IMMR;
337 ccsr_lbc_t *lbc = &immap->im_lbc;
338
339 print_laws();
340
341 printf ("Local Bus Controller Registers\n"
342 "\tBR0\t0x%08X\tOR0\t0x%08X \n", in_be32(&lbc->br0), in_be32(&lbc->or0));
343 printf("\tBR1\t0x%08X\tOR1\t0x%08X \n", in_be32(&lbc->br1), in_be32(&lbc->or1));
344 printf("\tBR2\t0x%08X\tOR2\t0x%08X \n", in_be32(&lbc->br2), in_be32(&lbc->or2));
345 printf("\tBR3\t0x%08X\tOR3\t0x%08X \n", in_be32(&lbc->br3), in_be32(&lbc->or3));
346 printf("\tBR4\t0x%08X\tOR4\t0x%08X \n", in_be32(&lbc->br4), in_be32(&lbc->or4));
347 printf("\tBR5\t0x%08X\tOR5\t0x%08X \n", in_be32(&lbc->br5), in_be32(&lbc->or5));
348 printf("\tBR6\t0x%08X\tOR6\t0x%08X \n", in_be32(&lbc->br6), in_be32(&lbc->or6));
349 printf("\tBR7\t0x%08X\tOR7\t0x%08X \n", in_be32(&lbc->br7), in_be32(&lbc->or7));
Jon Loeliger5c8aa972006-04-26 17:58:56 -0500350
351}