blob: 4cace984d91743e3fd2d45cf2ed9ad7d2aefbb76 [file] [log] [blame]
Jon Loeligerdebb7352006-04-26 17:58:56 -05001/*
Jon Loeligercb5965f2006-05-31 12:44:44 -05002 * Copyright 2006 Freescale Semiconductor
3 * Jeff Brown
Jon Loeligerdebb7352006-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>
Becky Brucee34a0e92008-05-08 19:02:51 -050029#include <asm/mmu.h>
Jon Loeligerdebb7352006-04-26 17:58:56 -050030#include <mpc86xx.h>
Andy Fleming75b9d4a2008-08-31 16:33:26 -050031#include <tsec.h>
Becky Bruce4f93f8b2008-01-23 16:31:06 -060032#include <asm/fsl_law.h>
Jon Loeligerdebb7352006-04-26 17:58:56 -050033
Jon Loeligerdebb7352006-04-26 17:58:56 -050034
Jon Loeligerffff3ae2006-08-22 12:06:18 -050035int
36checkcpu(void)
Jon Loeligerdebb7352006-04-26 17:58:56 -050037{
38 sys_info_t sysinfo;
39 uint pvr, svr;
40 uint ver;
41 uint major, minor;
42 uint lcrr; /* local bus clock ratio register */
43 uint clkdiv; /* clock divider portion of lcrr */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020044 volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR;
Jon Loeliger9553df82007-10-16 15:26:51 -050045 volatile ccsr_gur_t *gur = &immap->im_gur;
Jon Loeliger5c9efb32006-04-27 10:15:16 -050046
Jon Loeligerdebb7352006-04-26 17:58:56 -050047 puts("Freescale PowerPC\n");
48
49 pvr = get_pvr();
50 ver = PVR_VER(pvr);
51 major = PVR_MAJ(pvr);
52 minor = PVR_MIN(pvr);
53
Jon Loeliger5c9efb32006-04-27 10:15:16 -050054 puts("CPU:\n");
Jon Loeligercb5965f2006-05-31 12:44:44 -050055 puts(" Core: ");
Jon Loeliger5c9efb32006-04-27 10:15:16 -050056
Jon Loeligerdebb7352006-04-26 17:58:56 -050057 switch (ver) {
58 case PVR_VER(PVR_86xx):
Jon Loeliger9553df82007-10-16 15:26:51 -050059 {
60 uint msscr0 = mfspr(MSSCR0);
61 printf("E600 Core %d", (msscr0 & 0x20) ? 1 : 0 );
62 if (gur->pordevsr & MPC86xx_PORDEVSR_CORE1TE)
63 puts("\n Core1Translation Enabled");
64 debug(" (MSSCR0=%x, PORDEVSR=%x)", msscr0, gur->pordevsr);
65 }
66 break;
Jon Loeligerdebb7352006-04-26 17:58:56 -050067 default:
Jon Loeligerffff3ae2006-08-22 12:06:18 -050068 puts("Unknown");
69 break;
Jon Loeligerdebb7352006-04-26 17:58:56 -050070 }
71 printf(", Version: %d.%d, (0x%08x)\n", major, minor, pvr);
72
73 svr = get_svr();
Andy Fleming1ced1212008-02-06 01:19:40 -060074 ver = SVR_SOC_VER(svr);
Jon Loeligerdebb7352006-04-26 17:58:56 -050075 major = SVR_MAJ(svr);
76 minor = SVR_MIN(svr);
77
78 puts(" System: ");
Jon Loeliger5c9efb32006-04-27 10:15:16 -050079 switch (ver) {
Jon Loeligerdebb7352006-04-26 17:58:56 -050080 case SVR_8641:
Jon Loeligerd14ba6a2006-09-14 08:40:36 -050081 if (SVR_SUBVER(svr) == 1) {
Jon Loeligerdebb7352006-04-26 17:58:56 -050082 puts("8641D");
Jon Loeligerd14ba6a2006-09-14 08:40:36 -050083 } else {
84 puts("8641");
85 }
86 break;
Jon Loeliger9553df82007-10-16 15:26:51 -050087 case SVR_8610:
88 puts("8610");
89 break;
Jon Loeligerdebb7352006-04-26 17:58:56 -050090 default:
91 puts("Unknown");
92 break;
93 }
94 printf(", Version: %d.%d, (0x%08x)\n", major, minor, svr);
95
96 get_sys_info(&sysinfo);
97
98 puts(" Clocks: ");
99 printf("CPU:%4lu MHz, ", sysinfo.freqProcessor / 1000000);
100 printf("MPX:%4lu MHz, ", sysinfo.freqSystemBus / 1000000);
101 printf("DDR:%4lu MHz, ", sysinfo.freqSystemBus / 2000000);
Jon Loeliger5c9efb32006-04-27 10:15:16 -0500102
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200103#if defined(CONFIG_SYS_LBC_LCRR)
104 lcrr = CONFIG_SYS_LBC_LCRR;
Jon Loeligerdebb7352006-04-26 17:58:56 -0500105#else
106 {
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200107 volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR;
Jon Loeligerffff3ae2006-08-22 12:06:18 -0500108 volatile ccsr_lbc_t *lbc = &immap->im_lbc;
Jon Loeligerdebb7352006-04-26 17:58:56 -0500109
Jon Loeligerffff3ae2006-08-22 12:06:18 -0500110 lcrr = lbc->lcrr;
Jon Loeligerdebb7352006-04-26 17:58:56 -0500111 }
112#endif
113 clkdiv = lcrr & 0x0f;
114 if (clkdiv == 2 || clkdiv == 4 || clkdiv == 8) {
115 printf("LBC:%4lu MHz\n",
116 sysinfo.freqSystemBus / 1000000 / clkdiv);
117 } else {
118 printf(" LBC: unknown (lcrr: 0x%08x)\n", lcrr);
119 }
120
Jon Loeligercb5965f2006-05-31 12:44:44 -0500121 puts(" L2: ");
Jon Loeliger126aa702006-05-30 17:47:00 -0500122 if (get_l2cr() & 0x80000000)
Jon Loeligercb5965f2006-05-31 12:44:44 -0500123 puts("Enabled\n");
Jon Loeliger126aa702006-05-30 17:47:00 -0500124 else
Jon Loeligercb5965f2006-05-31 12:44:44 -0500125 puts("Disabled\n");
Jon Loeliger5c9efb32006-04-27 10:15:16 -0500126
127 return 0;
Jon Loeligerdebb7352006-04-26 17:58:56 -0500128}
129
130
Jon Loeligerdebb7352006-04-26 17:58:56 -0500131static inline void
132soft_restart(unsigned long addr)
133{
Jason Jina8318ec2007-10-26 18:32:00 +0800134#if !defined(CONFIG_MPC8641HPCN) && !defined(CONFIG_MPC8610HPCD)
Jon Loeliger5c9efb32006-04-27 10:15:16 -0500135
Jon Loeligerffff3ae2006-08-22 12:06:18 -0500136 /*
137 * SRR0 has system reset vector, SRR1 has default MSR value
138 * rfi restores MSR from SRR1 and sets the PC to the SRR0 value
139 */
Jon Loeligerdebb7352006-04-26 17:58:56 -0500140
141 __asm__ __volatile__ ("mtspr 26, %0" :: "r" (addr));
142 __asm__ __volatile__ ("li 4, (1 << 6)" ::: "r4");
143 __asm__ __volatile__ ("mtspr 27, 4");
144 __asm__ __volatile__ ("rfi");
145
146#else /* CONFIG_MPC8641HPCN */
Jon Loeligercb5965f2006-05-31 12:44:44 -0500147
148 out8(PIXIS_BASE + PIXIS_RST, 0);
149
Jon Loeligerdebb7352006-04-26 17:58:56 -0500150#endif /* !CONFIG_MPC8641HPCN */
Jon Loeligercb5965f2006-05-31 12:44:44 -0500151
Jon Loeligerffff3ae2006-08-22 12:06:18 -0500152 while (1) ; /* not reached */
Jon Loeligerdebb7352006-04-26 17:58:56 -0500153}
154
155
Jon Loeliger126aa702006-05-30 17:47:00 -0500156/*
157 * No generic way to do board reset. Simply call soft_reset.
158 */
Jon Loeligerdebb7352006-04-26 17:58:56 -0500159void
Jon Loeliger126aa702006-05-30 17:47:00 -0500160do_reset(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
Jon Loeligerdebb7352006-04-26 17:58:56 -0500161{
Jason Jina8318ec2007-10-26 18:32:00 +0800162#if !defined(CONFIG_MPC8641HPCN) && !defined(CONFIG_MPC8610HPCD)
Jon Loeligerdebb7352006-04-26 17:58:56 -0500163
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200164#ifdef CONFIG_SYS_RESET_ADDRESS
165 ulong addr = CONFIG_SYS_RESET_ADDRESS;
Jon Loeligerdebb7352006-04-26 17:58:56 -0500166#else
167 /*
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200168 * note: when CONFIG_SYS_MONITOR_BASE points to a RAM address,
169 * CONFIG_SYS_MONITOR_BASE - sizeof (ulong) is usually a valid
Jon Loeligerdebb7352006-04-26 17:58:56 -0500170 * address. Better pick an address known to be invalid on your
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200171 * system and assign it to CONFIG_SYS_RESET_ADDRESS.
Jon Loeligerdebb7352006-04-26 17:58:56 -0500172 */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200173 ulong addr = CONFIG_SYS_MONITOR_BASE - sizeof(ulong);
Jon Loeligerdebb7352006-04-26 17:58:56 -0500174#endif
175
Jon Loeliger5c9efb32006-04-27 10:15:16 -0500176 /* flush and disable I/D cache */
Jon Loeligerdebb7352006-04-26 17:58:56 -0500177 __asm__ __volatile__ ("mfspr 3, 1008" ::: "r3");
178 __asm__ __volatile__ ("ori 5, 5, 0xcc00" ::: "r5");
179 __asm__ __volatile__ ("ori 4, 3, 0xc00" ::: "r4");
180 __asm__ __volatile__ ("andc 5, 3, 5" ::: "r5");
181 __asm__ __volatile__ ("sync");
182 __asm__ __volatile__ ("mtspr 1008, 4");
183 __asm__ __volatile__ ("isync");
184 __asm__ __volatile__ ("sync");
185 __asm__ __volatile__ ("mtspr 1008, 5");
186 __asm__ __volatile__ ("isync");
187 __asm__ __volatile__ ("sync");
188
Jon Loeliger126aa702006-05-30 17:47:00 -0500189 soft_restart(addr);
Jon Loeligerdebb7352006-04-26 17:58:56 -0500190
191#else /* CONFIG_MPC8641HPCN */
Jon Loeligerdebb7352006-04-26 17:58:56 -0500192
Haiying Wang3d98b852007-01-22 12:37:30 -0600193 out8(PIXIS_BASE + PIXIS_RST, 0);
Jon Loeliger5c9efb32006-04-27 10:15:16 -0500194
Jon Loeligerdebb7352006-04-26 17:58:56 -0500195#endif /* !CONFIG_MPC8641HPCN */
Jon Loeliger5c9efb32006-04-27 10:15:16 -0500196
Jon Loeligerffff3ae2006-08-22 12:06:18 -0500197 while (1) ; /* not reached */
Jon Loeligerdebb7352006-04-26 17:58:56 -0500198}
199
200
Jon Loeligerdebb7352006-04-26 17:58:56 -0500201/*
202 * Get timebase clock frequency
203 */
Jon Loeligerffff3ae2006-08-22 12:06:18 -0500204unsigned long
205get_tbclk(void)
Jon Loeligerdebb7352006-04-26 17:58:56 -0500206{
Jon Loeligerffff3ae2006-08-22 12:06:18 -0500207 sys_info_t sys_info;
Jon Loeligerdebb7352006-04-26 17:58:56 -0500208
209 get_sys_info(&sys_info);
Jon Loeliger5c9efb32006-04-27 10:15:16 -0500210 return (sys_info.freqSystemBus + 3L) / 4L;
Jon Loeligerdebb7352006-04-26 17:58:56 -0500211}
212
Jon Loeligerdebb7352006-04-26 17:58:56 -0500213
214#if defined(CONFIG_WATCHDOG)
215void
216watchdog_reset(void)
217{
Jason Jin3473ab72008-05-13 11:50:36 +0800218#if defined(CONFIG_MPC8610)
219 /*
220 * This actually feed the hard enabled watchdog.
221 */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200222 volatile immap_t *immap = (immap_t *)CONFIG_SYS_IMMR;
Jason Jin3473ab72008-05-13 11:50:36 +0800223 volatile ccsr_wdt_t *wdt = &immap->im_wdt;
224 volatile ccsr_gur_t *gur = &immap->im_gur;
225 u32 tmp = gur->pordevsr;
226
227 if (tmp & 0x4000) {
228 wdt->swsrr = 0x556c;
229 wdt->swsrr = 0xaa39;
230 }
231#endif
Jon Loeligerdebb7352006-04-26 17:58:56 -0500232}
233#endif /* CONFIG_WATCHDOG */
234
Jon Loeligerdebb7352006-04-26 17:58:56 -0500235
236#if defined(CONFIG_DDR_ECC)
Jon Loeligerffff3ae2006-08-22 12:06:18 -0500237void
238dma_init(void)
Jon Loeliger5c9efb32006-04-27 10:15:16 -0500239{
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200240 volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR;
Jon Loeligerdebb7352006-04-26 17:58:56 -0500241 volatile ccsr_dma_t *dma = &immap->im_dma;
242
243 dma->satr0 = 0x00040000;
244 dma->datr0 = 0x00040000;
245 asm("sync; isync");
Jon Loeligerdebb7352006-04-26 17:58:56 -0500246}
247
Jon Loeligerffff3ae2006-08-22 12:06:18 -0500248uint
249dma_check(void)
Jon Loeliger5c9efb32006-04-27 10:15:16 -0500250{
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200251 volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR;
Jon Loeligerdebb7352006-04-26 17:58:56 -0500252 volatile ccsr_dma_t *dma = &immap->im_dma;
253 volatile uint status = dma->sr0;
254
255 /* While the channel is busy, spin */
Jon Loeligerffff3ae2006-08-22 12:06:18 -0500256 while ((status & 4) == 4) {
Jon Loeligerdebb7352006-04-26 17:58:56 -0500257 status = dma->sr0;
258 }
259
260 if (status != 0) {
Jon Loeligerffff3ae2006-08-22 12:06:18 -0500261 printf("DMA Error: status = %x\n", status);
Jon Loeligerdebb7352006-04-26 17:58:56 -0500262 }
263 return status;
264}
265
Jon Loeligerffff3ae2006-08-22 12:06:18 -0500266int
267dma_xfer(void *dest, uint count, void *src)
Jon Loeliger5c9efb32006-04-27 10:15:16 -0500268{
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200269 volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR;
Jon Loeligerdebb7352006-04-26 17:58:56 -0500270 volatile ccsr_dma_t *dma = &immap->im_dma;
271
272 dma->dar0 = (uint) dest;
273 dma->sar0 = (uint) src;
274 dma->bcr0 = count;
275 dma->mr0 = 0xf000004;
276 asm("sync;isync");
277 dma->mr0 = 0xf000005;
278 asm("sync;isync");
279 return dma_check();
280}
Jon Loeliger5c9efb32006-04-27 10:15:16 -0500281
Jon Loeligerdebb7352006-04-26 17:58:56 -0500282#endif /* CONFIG_DDR_ECC */
283
284
Becky Bruce4f93f8b2008-01-23 16:31:06 -0600285/*
286 * Print out the state of various machine registers.
Becky Brucee34a0e92008-05-08 19:02:51 -0500287 * Currently prints out LAWs, BR0/OR0, and BATs
Becky Bruce4f93f8b2008-01-23 16:31:06 -0600288 */
289void mpc86xx_reginfo(void)
290{
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200291 immap_t *immap = (immap_t *)CONFIG_SYS_IMMR;
Becky Bruce4f93f8b2008-01-23 16:31:06 -0600292 ccsr_lbc_t *lbc = &immap->im_lbc;
293
Becky Brucee34a0e92008-05-08 19:02:51 -0500294 print_bats();
Becky Bruce4f93f8b2008-01-23 16:31:06 -0600295 print_laws();
296
297 printf ("Local Bus Controller Registers\n"
298 "\tBR0\t0x%08X\tOR0\t0x%08X \n", in_be32(&lbc->br0), in_be32(&lbc->or0));
299 printf("\tBR1\t0x%08X\tOR1\t0x%08X \n", in_be32(&lbc->br1), in_be32(&lbc->or1));
300 printf("\tBR2\t0x%08X\tOR2\t0x%08X \n", in_be32(&lbc->br2), in_be32(&lbc->or2));
301 printf("\tBR3\t0x%08X\tOR3\t0x%08X \n", in_be32(&lbc->br3), in_be32(&lbc->or3));
302 printf("\tBR4\t0x%08X\tOR4\t0x%08X \n", in_be32(&lbc->br4), in_be32(&lbc->or4));
303 printf("\tBR5\t0x%08X\tOR5\t0x%08X \n", in_be32(&lbc->br5), in_be32(&lbc->or5));
304 printf("\tBR6\t0x%08X\tOR6\t0x%08X \n", in_be32(&lbc->br6), in_be32(&lbc->or6));
305 printf("\tBR7\t0x%08X\tOR7\t0x%08X \n", in_be32(&lbc->br7), in_be32(&lbc->or7));
Jon Loeligerdebb7352006-04-26 17:58:56 -0500306
307}
Ben Warrendd354792008-06-23 22:57:27 -0700308
Andy Fleming75b9d4a2008-08-31 16:33:26 -0500309/*
310 * Initializes on-chip ethernet controllers.
311 * to override, implement board_eth_init()
Ben Warrendd354792008-06-23 22:57:27 -0700312 */
Ben Warrendd354792008-06-23 22:57:27 -0700313int cpu_eth_init(bd_t *bis)
314{
Andy Fleming75b9d4a2008-08-31 16:33:26 -0500315#if defined(CONFIG_TSEC_ENET)
316 tsec_standard_init(bis);
Ben Warrendd354792008-06-23 22:57:27 -0700317#endif
Andy Fleming75b9d4a2008-08-31 16:33:26 -0500318
Ben Warrendd354792008-06-23 22:57:27 -0700319 return 0;
320}