blob: 35680238d2ec6a7ed13ef895b4218a2975311dd8 [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;
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020042 volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR;
Jon Loeliger9553df82007-10-16 15:26:51 -050043 volatile ccsr_gur_t *gur = &immap->im_gur;
Jon Loeliger5c9efb32006-04-27 10:15:16 -050044
Jon Loeligerdebb7352006-04-26 17:58:56 -050045 puts("Freescale PowerPC\n");
46
47 pvr = get_pvr();
48 ver = PVR_VER(pvr);
49 major = PVR_MAJ(pvr);
50 minor = PVR_MIN(pvr);
51
Jon Loeliger5c9efb32006-04-27 10:15:16 -050052 puts("CPU:\n");
Jon Loeligercb5965f2006-05-31 12:44:44 -050053 puts(" Core: ");
Jon Loeliger5c9efb32006-04-27 10:15:16 -050054
Jon Loeligerdebb7352006-04-26 17:58:56 -050055 switch (ver) {
56 case PVR_VER(PVR_86xx):
Jon Loeliger9553df82007-10-16 15:26:51 -050057 {
58 uint msscr0 = mfspr(MSSCR0);
59 printf("E600 Core %d", (msscr0 & 0x20) ? 1 : 0 );
60 if (gur->pordevsr & MPC86xx_PORDEVSR_CORE1TE)
61 puts("\n Core1Translation Enabled");
62 debug(" (MSSCR0=%x, PORDEVSR=%x)", msscr0, gur->pordevsr);
63 }
64 break;
Jon Loeligerdebb7352006-04-26 17:58:56 -050065 default:
Jon Loeligerffff3ae2006-08-22 12:06:18 -050066 puts("Unknown");
67 break;
Jon Loeligerdebb7352006-04-26 17:58:56 -050068 }
69 printf(", Version: %d.%d, (0x%08x)\n", major, minor, pvr);
70
71 svr = get_svr();
Andy Fleming1ced1212008-02-06 01:19:40 -060072 ver = SVR_SOC_VER(svr);
Jon Loeligerdebb7352006-04-26 17:58:56 -050073 major = SVR_MAJ(svr);
74 minor = SVR_MIN(svr);
75
76 puts(" System: ");
Jon Loeliger5c9efb32006-04-27 10:15:16 -050077 switch (ver) {
Jon Loeligerdebb7352006-04-26 17:58:56 -050078 case SVR_8641:
Jon Loeligerd14ba6a2006-09-14 08:40:36 -050079 if (SVR_SUBVER(svr) == 1) {
Jon Loeligerdebb7352006-04-26 17:58:56 -050080 puts("8641D");
Jon Loeligerd14ba6a2006-09-14 08:40:36 -050081 } else {
82 puts("8641");
83 }
84 break;
Jon Loeliger9553df82007-10-16 15:26:51 -050085 case SVR_8610:
86 puts("8610");
87 break;
Jon Loeligerdebb7352006-04-26 17:58:56 -050088 default:
89 puts("Unknown");
90 break;
91 }
92 printf(", Version: %d.%d, (0x%08x)\n", major, minor, svr);
93
94 get_sys_info(&sysinfo);
95
96 puts(" Clocks: ");
97 printf("CPU:%4lu MHz, ", sysinfo.freqProcessor / 1000000);
98 printf("MPX:%4lu MHz, ", sysinfo.freqSystemBus / 1000000);
99 printf("DDR:%4lu MHz, ", sysinfo.freqSystemBus / 2000000);
Jon Loeliger5c9efb32006-04-27 10:15:16 -0500100
Trent Piephoada591d2008-12-03 15:16:37 -0800101 if (sysinfo.freqLocalBus > LCRR_CLKDIV) {
102 printf("LBC:%4lu MHz\n", sysinfo.freqLocalBus / 1000000);
Jon Loeligerdebb7352006-04-26 17:58:56 -0500103 } else {
Trent Piephoada591d2008-12-03 15:16:37 -0800104 printf("LBC: unknown (LCRR[CLKDIV] = 0x%02x)\n",
105 sysinfo.freqLocalBus);
Jon Loeligerdebb7352006-04-26 17:58:56 -0500106 }
107
Jon Loeligercb5965f2006-05-31 12:44:44 -0500108 puts(" L2: ");
Jon Loeliger126aa702006-05-30 17:47:00 -0500109 if (get_l2cr() & 0x80000000)
Jon Loeligercb5965f2006-05-31 12:44:44 -0500110 puts("Enabled\n");
Jon Loeliger126aa702006-05-30 17:47:00 -0500111 else
Jon Loeligercb5965f2006-05-31 12:44:44 -0500112 puts("Disabled\n");
Jon Loeliger5c9efb32006-04-27 10:15:16 -0500113
114 return 0;
Jon Loeligerdebb7352006-04-26 17:58:56 -0500115}
116
117
Jon Loeligerdebb7352006-04-26 17:58:56 -0500118static inline void
119soft_restart(unsigned long addr)
120{
Jason Jina8318ec2007-10-26 18:32:00 +0800121#if !defined(CONFIG_MPC8641HPCN) && !defined(CONFIG_MPC8610HPCD)
Jon Loeliger5c9efb32006-04-27 10:15:16 -0500122
Jon Loeligerffff3ae2006-08-22 12:06:18 -0500123 /*
124 * SRR0 has system reset vector, SRR1 has default MSR value
125 * rfi restores MSR from SRR1 and sets the PC to the SRR0 value
126 */
Jon Loeligerdebb7352006-04-26 17:58:56 -0500127
128 __asm__ __volatile__ ("mtspr 26, %0" :: "r" (addr));
129 __asm__ __volatile__ ("li 4, (1 << 6)" ::: "r4");
130 __asm__ __volatile__ ("mtspr 27, 4");
131 __asm__ __volatile__ ("rfi");
132
133#else /* CONFIG_MPC8641HPCN */
Jon Loeligercb5965f2006-05-31 12:44:44 -0500134
135 out8(PIXIS_BASE + PIXIS_RST, 0);
136
Jon Loeligerdebb7352006-04-26 17:58:56 -0500137#endif /* !CONFIG_MPC8641HPCN */
Jon Loeligercb5965f2006-05-31 12:44:44 -0500138
Jon Loeligerffff3ae2006-08-22 12:06:18 -0500139 while (1) ; /* not reached */
Jon Loeligerdebb7352006-04-26 17:58:56 -0500140}
141
142
Jon Loeliger126aa702006-05-30 17:47:00 -0500143/*
144 * No generic way to do board reset. Simply call soft_reset.
145 */
Jon Loeligerdebb7352006-04-26 17:58:56 -0500146void
Jon Loeliger126aa702006-05-30 17:47:00 -0500147do_reset(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
Jon Loeligerdebb7352006-04-26 17:58:56 -0500148{
Jason Jina8318ec2007-10-26 18:32:00 +0800149#if !defined(CONFIG_MPC8641HPCN) && !defined(CONFIG_MPC8610HPCD)
Jon Loeligerdebb7352006-04-26 17:58:56 -0500150
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200151#ifdef CONFIG_SYS_RESET_ADDRESS
152 ulong addr = CONFIG_SYS_RESET_ADDRESS;
Jon Loeligerdebb7352006-04-26 17:58:56 -0500153#else
154 /*
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200155 * note: when CONFIG_SYS_MONITOR_BASE points to a RAM address,
156 * CONFIG_SYS_MONITOR_BASE - sizeof (ulong) is usually a valid
Jon Loeligerdebb7352006-04-26 17:58:56 -0500157 * address. Better pick an address known to be invalid on your
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200158 * system and assign it to CONFIG_SYS_RESET_ADDRESS.
Jon Loeligerdebb7352006-04-26 17:58:56 -0500159 */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200160 ulong addr = CONFIG_SYS_MONITOR_BASE - sizeof(ulong);
Jon Loeligerdebb7352006-04-26 17:58:56 -0500161#endif
162
Jon Loeliger5c9efb32006-04-27 10:15:16 -0500163 /* flush and disable I/D cache */
Jon Loeligerdebb7352006-04-26 17:58:56 -0500164 __asm__ __volatile__ ("mfspr 3, 1008" ::: "r3");
165 __asm__ __volatile__ ("ori 5, 5, 0xcc00" ::: "r5");
166 __asm__ __volatile__ ("ori 4, 3, 0xc00" ::: "r4");
167 __asm__ __volatile__ ("andc 5, 3, 5" ::: "r5");
168 __asm__ __volatile__ ("sync");
169 __asm__ __volatile__ ("mtspr 1008, 4");
170 __asm__ __volatile__ ("isync");
171 __asm__ __volatile__ ("sync");
172 __asm__ __volatile__ ("mtspr 1008, 5");
173 __asm__ __volatile__ ("isync");
174 __asm__ __volatile__ ("sync");
175
Jon Loeliger126aa702006-05-30 17:47:00 -0500176 soft_restart(addr);
Jon Loeligerdebb7352006-04-26 17:58:56 -0500177
178#else /* CONFIG_MPC8641HPCN */
Jon Loeligerdebb7352006-04-26 17:58:56 -0500179
Haiying Wang3d98b852007-01-22 12:37:30 -0600180 out8(PIXIS_BASE + PIXIS_RST, 0);
Jon Loeliger5c9efb32006-04-27 10:15:16 -0500181
Jon Loeligerdebb7352006-04-26 17:58:56 -0500182#endif /* !CONFIG_MPC8641HPCN */
Jon Loeliger5c9efb32006-04-27 10:15:16 -0500183
Jon Loeligerffff3ae2006-08-22 12:06:18 -0500184 while (1) ; /* not reached */
Jon Loeligerdebb7352006-04-26 17:58:56 -0500185}
186
187
Jon Loeligerdebb7352006-04-26 17:58:56 -0500188/*
189 * Get timebase clock frequency
190 */
Jon Loeligerffff3ae2006-08-22 12:06:18 -0500191unsigned long
192get_tbclk(void)
Jon Loeligerdebb7352006-04-26 17:58:56 -0500193{
Jon Loeligerffff3ae2006-08-22 12:06:18 -0500194 sys_info_t sys_info;
Jon Loeligerdebb7352006-04-26 17:58:56 -0500195
196 get_sys_info(&sys_info);
Jon Loeliger5c9efb32006-04-27 10:15:16 -0500197 return (sys_info.freqSystemBus + 3L) / 4L;
Jon Loeligerdebb7352006-04-26 17:58:56 -0500198}
199
Jon Loeligerdebb7352006-04-26 17:58:56 -0500200
201#if defined(CONFIG_WATCHDOG)
202void
203watchdog_reset(void)
204{
Jason Jin3473ab72008-05-13 11:50:36 +0800205#if defined(CONFIG_MPC8610)
206 /*
207 * This actually feed the hard enabled watchdog.
208 */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200209 volatile immap_t *immap = (immap_t *)CONFIG_SYS_IMMR;
Jason Jin3473ab72008-05-13 11:50:36 +0800210 volatile ccsr_wdt_t *wdt = &immap->im_wdt;
211 volatile ccsr_gur_t *gur = &immap->im_gur;
212 u32 tmp = gur->pordevsr;
213
214 if (tmp & 0x4000) {
215 wdt->swsrr = 0x556c;
216 wdt->swsrr = 0xaa39;
217 }
218#endif
Jon Loeligerdebb7352006-04-26 17:58:56 -0500219}
220#endif /* CONFIG_WATCHDOG */
221
Jon Loeligerdebb7352006-04-26 17:58:56 -0500222
223#if defined(CONFIG_DDR_ECC)
Jon Loeligerffff3ae2006-08-22 12:06:18 -0500224void
225dma_init(void)
Jon Loeliger5c9efb32006-04-27 10:15:16 -0500226{
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200227 volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR;
Jon Loeligerdebb7352006-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 Loeligerdebb7352006-04-26 17:58:56 -0500233}
234
Jon Loeligerffff3ae2006-08-22 12:06:18 -0500235uint
236dma_check(void)
Jon Loeliger5c9efb32006-04-27 10:15:16 -0500237{
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200238 volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR;
Jon Loeligerdebb7352006-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 Loeligerffff3ae2006-08-22 12:06:18 -0500243 while ((status & 4) == 4) {
Jon Loeligerdebb7352006-04-26 17:58:56 -0500244 status = dma->sr0;
245 }
246
247 if (status != 0) {
Jon Loeligerffff3ae2006-08-22 12:06:18 -0500248 printf("DMA Error: status = %x\n", status);
Jon Loeligerdebb7352006-04-26 17:58:56 -0500249 }
250 return status;
251}
252
Jon Loeligerffff3ae2006-08-22 12:06:18 -0500253int
254dma_xfer(void *dest, uint count, void *src)
Jon Loeliger5c9efb32006-04-27 10:15:16 -0500255{
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200256 volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR;
Jon Loeligerdebb7352006-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 Loeliger5c9efb32006-04-27 10:15:16 -0500268
Jon Loeligerdebb7352006-04-26 17:58:56 -0500269#endif /* CONFIG_DDR_ECC */
270
271
Becky Bruce4f93f8b2008-01-23 16:31:06 -0600272/*
273 * Print out the state of various machine registers.
Becky Brucee34a0e92008-05-08 19:02:51 -0500274 * Currently prints out LAWs, BR0/OR0, and BATs
Becky Bruce4f93f8b2008-01-23 16:31:06 -0600275 */
276void mpc86xx_reginfo(void)
277{
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200278 immap_t *immap = (immap_t *)CONFIG_SYS_IMMR;
Becky Bruce4f93f8b2008-01-23 16:31:06 -0600279 ccsr_lbc_t *lbc = &immap->im_lbc;
280
Becky Brucee34a0e92008-05-08 19:02:51 -0500281 print_bats();
Becky Bruce4f93f8b2008-01-23 16:31:06 -0600282 print_laws();
283
284 printf ("Local Bus Controller Registers\n"
285 "\tBR0\t0x%08X\tOR0\t0x%08X \n", in_be32(&lbc->br0), in_be32(&lbc->or0));
286 printf("\tBR1\t0x%08X\tOR1\t0x%08X \n", in_be32(&lbc->br1), in_be32(&lbc->or1));
287 printf("\tBR2\t0x%08X\tOR2\t0x%08X \n", in_be32(&lbc->br2), in_be32(&lbc->or2));
288 printf("\tBR3\t0x%08X\tOR3\t0x%08X \n", in_be32(&lbc->br3), in_be32(&lbc->or3));
289 printf("\tBR4\t0x%08X\tOR4\t0x%08X \n", in_be32(&lbc->br4), in_be32(&lbc->or4));
290 printf("\tBR5\t0x%08X\tOR5\t0x%08X \n", in_be32(&lbc->br5), in_be32(&lbc->or5));
291 printf("\tBR6\t0x%08X\tOR6\t0x%08X \n", in_be32(&lbc->br6), in_be32(&lbc->or6));
292 printf("\tBR7\t0x%08X\tOR7\t0x%08X \n", in_be32(&lbc->br7), in_be32(&lbc->or7));
Jon Loeligerdebb7352006-04-26 17:58:56 -0500293
294}
Ben Warrendd354792008-06-23 22:57:27 -0700295
Andy Fleming75b9d4a2008-08-31 16:33:26 -0500296/*
297 * Initializes on-chip ethernet controllers.
298 * to override, implement board_eth_init()
Ben Warrendd354792008-06-23 22:57:27 -0700299 */
Ben Warrendd354792008-06-23 22:57:27 -0700300int cpu_eth_init(bd_t *bis)
301{
Andy Fleming75b9d4a2008-08-31 16:33:26 -0500302#if defined(CONFIG_TSEC_ENET)
303 tsec_standard_init(bis);
Ben Warrendd354792008-06-23 22:57:27 -0700304#endif
Andy Fleming75b9d4a2008-08-31 16:33:26 -0500305
Ben Warrendd354792008-06-23 22:57:27 -0700306 return 0;
307}