blob: ffcc8e621201700bf5dd5abc2d8bf8a25f4b2766 [file] [log] [blame]
Jon Loeliger5c8aa972006-04-26 17:58:56 -05001/*
Timur Tabi107e9cd2010-03-29 12:51:07 -05002 * Copyright 2006,2009-2010 Freescale Semiconductor, Inc.
Jon Loeligere65e32e2006-05-31 12:44:44 -05003 * 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>
Becky Bruce7e07c772008-05-08 19:02:51 -050029#include <asm/mmu.h>
Jon Loeliger5c8aa972006-04-26 17:58:56 -050030#include <mpc86xx.h>
Becky Bruceb0b30942008-01-23 16:31:06 -060031#include <asm/fsl_law.h>
Jon Loeliger5c8aa972006-04-26 17:58:56 -050032
Poonam Aggrwal4baef822009-07-31 12:08:14 +053033DECLARE_GLOBAL_DATA_PTR;
34
Peter Tyser69454402009-02-05 11:25:25 -060035/*
36 * Default board reset function
37 */
38static void
39__board_reset(void)
40{
41 /* Do nothing */
42}
Peter Tyser21d2cd22009-04-20 11:08:46 -050043void board_reset(void) __attribute__((weak, alias("__board_reset")));
Peter Tyser69454402009-02-05 11:25:25 -060044
45
Jon Loeligera1295442006-08-22 12:06:18 -050046int
47checkcpu(void)
Jon Loeliger5c8aa972006-04-26 17:58:56 -050048{
49 sys_info_t sysinfo;
50 uint pvr, svr;
51 uint ver;
52 uint major, minor;
Peter Tyser698f3a12009-02-06 14:30:40 -060053 char buf1[32], buf2[32];
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020054 volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR;
Jon Loeliger3b971c92007-10-16 15:26:51 -050055 volatile ccsr_gur_t *gur = &immap->im_gur;
Kumar Gala1e2e9fa2009-06-18 08:23:01 -050056 struct cpu_type *cpu;
Peter Tyser698f3a12009-02-06 14:30:40 -060057 uint msscr0 = mfspr(MSSCR0);
Jon Loeliger5c8aa972006-04-26 17:58:56 -050058
59 svr = get_svr();
Andy Flemingf5740972008-02-06 01:19:40 -060060 ver = SVR_SOC_VER(svr);
Jon Loeliger5c8aa972006-04-26 17:58:56 -050061 major = SVR_MAJ(svr);
62 minor = SVR_MIN(svr);
63
Poonam Aggrwal36a68432009-09-03 19:42:40 +053064 if (cpu_numcores() > 1) {
65#ifndef CONFIG_MP
66 puts("Unicore software on multiprocessor system!!\n"
67 "To enable mutlticore build define CONFIG_MP\n");
68#endif
69 }
Peter Tyser698f3a12009-02-06 14:30:40 -060070 puts("CPU: ");
71
Poonam Aggrwal4baef822009-07-31 12:08:14 +053072 cpu = gd->cpu;
73
Poonam Aggrwalda6e1ca2009-09-02 13:35:21 +053074 puts(cpu->name);
Kumar Gala1e2e9fa2009-06-18 08:23:01 -050075
Jon Loeliger5c8aa972006-04-26 17:58:56 -050076 printf(", Version: %d.%d, (0x%08x)\n", major, minor, svr);
Peter Tyser698f3a12009-02-06 14:30:40 -060077 puts("Core: ");
78
79 pvr = get_pvr();
80 ver = PVR_E600_VER(pvr);
81 major = PVR_E600_MAJ(pvr);
82 minor = PVR_E600_MIN(pvr);
83
84 printf("E600 Core %d", (msscr0 & 0x20) ? 1 : 0 );
85 if (gur->pordevsr & MPC86xx_PORDEVSR_CORE1TE)
86 puts("\n Core1Translation Enabled");
87 debug(" (MSSCR0=%x, PORDEVSR=%x)", msscr0, gur->pordevsr);
88
89 printf(", Version: %d.%d, (0x%08x)\n", major, minor, pvr);
Jon Loeliger5c8aa972006-04-26 17:58:56 -050090
91 get_sys_info(&sysinfo);
92
Peter Tyser698f3a12009-02-06 14:30:40 -060093 puts("Clock Configuration:\n");
94 printf(" CPU:%-4s MHz, ", strmhz(buf1, sysinfo.freqProcessor));
95 printf("MPX:%-4s MHz\n", strmhz(buf1, sysinfo.freqSystemBus));
96 printf(" DDR:%-4s MHz (%s MT/s data rate), ",
97 strmhz(buf1, sysinfo.freqSystemBus / 2),
98 strmhz(buf2, sysinfo.freqSystemBus));
Jon Loeliger465b9d82006-04-27 10:15:16 -050099
Trent Piepho0b691fc2008-12-03 15:16:37 -0800100 if (sysinfo.freqLocalBus > LCRR_CLKDIV) {
Peter Tyser698f3a12009-02-06 14:30:40 -0600101 printf("LBC:%-4s MHz\n", strmhz(buf1, sysinfo.freqLocalBus));
Jon Loeliger5c8aa972006-04-26 17:58:56 -0500102 } else {
Wolfgang Denk3fe630c2009-01-12 14:50:35 +0100103 printf("LBC: unknown (LCRR[CLKDIV] = 0x%02lx)\n",
Trent Piepho0b691fc2008-12-03 15:16:37 -0800104 sysinfo.freqLocalBus);
Jon Loeliger5c8aa972006-04-26 17:58:56 -0500105 }
106
Peter Tyser698f3a12009-02-06 14:30:40 -0600107 puts("L1: D-cache 32 KB enabled\n");
108 puts(" I-cache 32 KB enabled\n");
109
110 puts("L2: ");
111 if (get_l2cr() & 0x80000000) {
112#if defined(CONFIG_MPC8610)
113 puts("256");
114#elif defined(CONFIG_MPC8641)
115 puts("512");
116#endif
117 puts(" KB enabled\n");
118 } else {
Jon Loeligere65e32e2006-05-31 12:44:44 -0500119 puts("Disabled\n");
Peter Tyser698f3a12009-02-06 14:30:40 -0600120 }
Jon Loeliger465b9d82006-04-27 10:15:16 -0500121
122 return 0;
Jon Loeliger5c8aa972006-04-26 17:58:56 -0500123}
124
125
Peter Tyser693d6382010-12-03 10:28:47 -0600126int do_reset(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
Jon Loeliger5c8aa972006-04-26 17:58:56 -0500127{
Peter Tyser69454402009-02-05 11:25:25 -0600128 volatile immap_t *immap = (immap_t *)CONFIG_SYS_IMMR;
129 volatile ccsr_gur_t *gur = &immap->im_gur;
Jon Loeliger465b9d82006-04-27 10:15:16 -0500130
Peter Tyser69454402009-02-05 11:25:25 -0600131 /* Attempt board-specific reset */
132 board_reset();
Jon Loeliger465b9d82006-04-27 10:15:16 -0500133
Peter Tyser69454402009-02-05 11:25:25 -0600134 /* Next try asserting HRESET_REQ */
135 out_be32(&gur->rstcr, MPC86xx_RSTCR_HRST_REQ);
Jon Loeliger465b9d82006-04-27 10:15:16 -0500136
Peter Tyser69454402009-02-05 11:25:25 -0600137 while (1)
138 ;
Peter Tyser693d6382010-12-03 10:28:47 -0600139
140 return 1;
Jon Loeliger5c8aa972006-04-26 17:58:56 -0500141}
142
143
Jon Loeliger5c8aa972006-04-26 17:58:56 -0500144/*
145 * Get timebase clock frequency
146 */
Jon Loeligera1295442006-08-22 12:06:18 -0500147unsigned long
148get_tbclk(void)
Jon Loeliger5c8aa972006-04-26 17:58:56 -0500149{
Jon Loeligera1295442006-08-22 12:06:18 -0500150 sys_info_t sys_info;
Jon Loeliger5c8aa972006-04-26 17:58:56 -0500151
152 get_sys_info(&sys_info);
Jon Loeliger465b9d82006-04-27 10:15:16 -0500153 return (sys_info.freqSystemBus + 3L) / 4L;
Jon Loeliger5c8aa972006-04-26 17:58:56 -0500154}
155
Jon Loeliger5c8aa972006-04-26 17:58:56 -0500156
157#if defined(CONFIG_WATCHDOG)
158void
159watchdog_reset(void)
160{
Jason Jin6c71b942008-05-13 11:50:36 +0800161#if defined(CONFIG_MPC8610)
162 /*
163 * This actually feed the hard enabled watchdog.
164 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200165 volatile immap_t *immap = (immap_t *)CONFIG_SYS_IMMR;
Jason Jin6c71b942008-05-13 11:50:36 +0800166 volatile ccsr_wdt_t *wdt = &immap->im_wdt;
167 volatile ccsr_gur_t *gur = &immap->im_gur;
168 u32 tmp = gur->pordevsr;
169
170 if (tmp & 0x4000) {
171 wdt->swsrr = 0x556c;
172 wdt->swsrr = 0xaa39;
173 }
174#endif
Jon Loeliger5c8aa972006-04-26 17:58:56 -0500175}
176#endif /* CONFIG_WATCHDOG */
177
Becky Bruceb0b30942008-01-23 16:31:06 -0600178/*
179 * Print out the state of various machine registers.
Becky Bruce7e07c772008-05-08 19:02:51 -0500180 * Currently prints out LAWs, BR0/OR0, and BATs
Becky Bruceb0b30942008-01-23 16:31:06 -0600181 */
182void mpc86xx_reginfo(void)
183{
Becky Bruce7e07c772008-05-08 19:02:51 -0500184 print_bats();
Becky Bruceb0b30942008-01-23 16:31:06 -0600185 print_laws();
Becky Bruce0d4cee12010-06-17 11:37:20 -0500186 print_lbc_regs();
Ben Warrend448a492008-06-23 22:57:27 -0700187}
Timur Tabi107e9cd2010-03-29 12:51:07 -0500188
189/*
190 * Set the DDR BATs to reflect the actual size of DDR.
191 *
192 * dram_size is the actual size of DDR, in bytes
193 *
194 * Note: we assume that CONFIG_MAX_MEM_MAPPED is 2G or smaller as we only
195 * are using a single BAT to cover DDR.
196 *
197 * If this is not true, (e.g. CONFIG_MAX_MEM_MAPPED is 2GB but HID0_XBSEN
198 * is not defined) then we might have a situation where U-Boot will attempt
199 * to relocated itself outside of the region mapped by DBAT0.
200 * This will cause a machine check.
201 *
202 * Currently we are limited to power of two sized DDR since we only use a
203 * single bat. If a non-power of two size is used that is less than
204 * CONFIG_MAX_MEM_MAPPED u-boot will crash.
205 *
206 */
207void setup_ddr_bat(phys_addr_t dram_size)
208{
209 unsigned long batu, bl;
210
211 bl = TO_BATU_BL(min(dram_size, CONFIG_MAX_MEM_MAPPED));
212
213 if (BATU_SIZE(bl) != dram_size) {
214 u64 sz = (u64)dram_size - BATU_SIZE(bl);
215 print_size(sz, " left unmapped\n");
216 }
217
218 batu = bl | BATU_VS | BATU_VP;
219 write_bat(DBAT0, batu, CONFIG_SYS_DBAT0L);
220 write_bat(IBAT0, batu, CONFIG_SYS_IBAT0L);
221}