blob: fe35744b7081c4da6a8bfeb6f0dcee0316b914e9 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Jon Loeliger5c8aa972006-04-26 17:58:56 -05002/*
Timur Tabi107e9cd2010-03-29 12:51:07 -05003 * Copyright 2006,2009-2010 Freescale Semiconductor, Inc.
Jon Loeligere65e32e2006-05-31 12:44:44 -05004 * Jeff Brown
Jon Loeliger5c8aa972006-04-26 17:58:56 -05005 * Srikanth Srinivasan (srikanth.srinivasan@freescale.com)
Jon Loeliger5c8aa972006-04-26 17:58:56 -05006 */
7
8#include <common.h>
Simon Glass33d1e702019-11-14 12:57:32 -07009#include <cpu_func.h>
Simon Glassa9dc0682019-12-28 10:44:59 -070010#include <time.h>
Simon Glassf5c208d2019-11-14 12:57:20 -070011#include <vsprintf.h>
Jon Loeliger5c8aa972006-04-26 17:58:56 -050012#include <watchdog.h>
13#include <command.h>
14#include <asm/cache.h>
Becky Bruce7e07c772008-05-08 19:02:51 -050015#include <asm/mmu.h>
Jon Loeliger5c8aa972006-04-26 17:58:56 -050016#include <mpc86xx.h>
Becky Bruceb0b30942008-01-23 16:31:06 -060017#include <asm/fsl_law.h>
Christophe Leroy31f6e932017-07-13 15:09:54 +020018#include <asm/ppc.h>
Jon Loeliger5c8aa972006-04-26 17:58:56 -050019
Poonam Aggrwal4baef822009-07-31 12:08:14 +053020DECLARE_GLOBAL_DATA_PTR;
21
Peter Tyser69454402009-02-05 11:25:25 -060022/*
23 * Default board reset function
24 */
25static void
26__board_reset(void)
27{
28 /* Do nothing */
29}
Peter Tyser21d2cd22009-04-20 11:08:46 -050030void board_reset(void) __attribute__((weak, alias("__board_reset")));
Peter Tyser69454402009-02-05 11:25:25 -060031
32
Jon Loeligera1295442006-08-22 12:06:18 -050033int
34checkcpu(void)
Jon Loeliger5c8aa972006-04-26 17:58:56 -050035{
36 sys_info_t sysinfo;
37 uint pvr, svr;
Jon Loeliger5c8aa972006-04-26 17:58:56 -050038 uint major, minor;
Peter Tyser698f3a12009-02-06 14:30:40 -060039 char buf1[32], buf2[32];
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020040 volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR;
Jon Loeliger3b971c92007-10-16 15:26:51 -050041 volatile ccsr_gur_t *gur = &immap->im_gur;
Kumar Gala1e2e9fa2009-06-18 08:23:01 -050042 struct cpu_type *cpu;
Peter Tyser698f3a12009-02-06 14:30:40 -060043 uint msscr0 = mfspr(MSSCR0);
Jon Loeliger5c8aa972006-04-26 17:58:56 -050044
45 svr = get_svr();
Jon Loeliger5c8aa972006-04-26 17:58:56 -050046 major = SVR_MAJ(svr);
47 minor = SVR_MIN(svr);
48
Poonam Aggrwal36a68432009-09-03 19:42:40 +053049 if (cpu_numcores() > 1) {
50#ifndef CONFIG_MP
51 puts("Unicore software on multiprocessor system!!\n"
52 "To enable mutlticore build define CONFIG_MP\n");
53#endif
54 }
Peter Tyser698f3a12009-02-06 14:30:40 -060055 puts("CPU: ");
56
Simon Glassa8b57392012-12-13 20:48:48 +000057 cpu = gd->arch.cpu;
Poonam Aggrwal4baef822009-07-31 12:08:14 +053058
Poonam Aggrwalda6e1ca2009-09-02 13:35:21 +053059 puts(cpu->name);
Kumar Gala1e2e9fa2009-06-18 08:23:01 -050060
Jon Loeliger5c8aa972006-04-26 17:58:56 -050061 printf(", Version: %d.%d, (0x%08x)\n", major, minor, svr);
Peter Tyser698f3a12009-02-06 14:30:40 -060062 puts("Core: ");
63
64 pvr = get_pvr();
Peter Tyser698f3a12009-02-06 14:30:40 -060065 major = PVR_E600_MAJ(pvr);
66 minor = PVR_E600_MIN(pvr);
67
Fabio Estevamf4c557c2013-04-21 13:11:02 -030068 printf("e600 Core %d", (msscr0 & 0x20) ? 1 : 0);
Peter Tyser698f3a12009-02-06 14:30:40 -060069 if (gur->pordevsr & MPC86xx_PORDEVSR_CORE1TE)
70 puts("\n Core1Translation Enabled");
71 debug(" (MSSCR0=%x, PORDEVSR=%x)", msscr0, gur->pordevsr);
72
73 printf(", Version: %d.%d, (0x%08x)\n", major, minor, pvr);
Jon Loeliger5c8aa972006-04-26 17:58:56 -050074
75 get_sys_info(&sysinfo);
76
Peter Tyser698f3a12009-02-06 14:30:40 -060077 puts("Clock Configuration:\n");
Prabhakar Kushwahad1698082013-08-16 14:52:26 +053078 printf(" CPU:%-4s MHz, ", strmhz(buf1, sysinfo.freq_processor));
79 printf("MPX:%-4s MHz\n", strmhz(buf1, sysinfo.freq_systembus));
Peter Tyser698f3a12009-02-06 14:30:40 -060080 printf(" DDR:%-4s MHz (%s MT/s data rate), ",
Prabhakar Kushwahad1698082013-08-16 14:52:26 +053081 strmhz(buf1, sysinfo.freq_systembus / 2),
82 strmhz(buf2, sysinfo.freq_systembus));
Jon Loeliger465b9d82006-04-27 10:15:16 -050083
Prabhakar Kushwahad1698082013-08-16 14:52:26 +053084 if (sysinfo.freq_localbus > LCRR_CLKDIV) {
85 printf("LBC:%-4s MHz\n", strmhz(buf1, sysinfo.freq_localbus));
Jon Loeliger5c8aa972006-04-26 17:58:56 -050086 } else {
Wolfgang Denk3fe630c2009-01-12 14:50:35 +010087 printf("LBC: unknown (LCRR[CLKDIV] = 0x%02lx)\n",
Prabhakar Kushwahad1698082013-08-16 14:52:26 +053088 sysinfo.freq_localbus);
Jon Loeliger5c8aa972006-04-26 17:58:56 -050089 }
90
Shruti Kanetkar81159362013-08-15 11:25:38 -050091 puts("L1: D-cache 32 KiB enabled\n");
92 puts(" I-cache 32 KiB enabled\n");
Peter Tyser698f3a12009-02-06 14:30:40 -060093
94 puts("L2: ");
95 if (get_l2cr() & 0x80000000) {
York Sunf48436a2016-11-23 14:06:21 -080096#if defined(CONFIG_ARCH_MPC8610)
Peter Tyser698f3a12009-02-06 14:30:40 -060097 puts("256");
York Sunefc30b62016-11-23 14:08:36 -080098#elif defined(CONFIG_ARCH_MPC8641)
Peter Tyser698f3a12009-02-06 14:30:40 -060099 puts("512");
100#endif
Shruti Kanetkar81159362013-08-15 11:25:38 -0500101 puts(" KiB enabled\n");
Peter Tyser698f3a12009-02-06 14:30:40 -0600102 } else {
Jon Loeligere65e32e2006-05-31 12:44:44 -0500103 puts("Disabled\n");
Peter Tyser698f3a12009-02-06 14:30:40 -0600104 }
Jon Loeliger465b9d82006-04-27 10:15:16 -0500105
106 return 0;
Jon Loeliger5c8aa972006-04-26 17:58:56 -0500107}
108
109
Simon Glassed38aef2020-05-10 11:40:03 -0600110int do_reset(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
Jon Loeliger5c8aa972006-04-26 17:58:56 -0500111{
Peter Tyser69454402009-02-05 11:25:25 -0600112 volatile immap_t *immap = (immap_t *)CONFIG_SYS_IMMR;
113 volatile ccsr_gur_t *gur = &immap->im_gur;
Jon Loeliger465b9d82006-04-27 10:15:16 -0500114
Peter Tyser69454402009-02-05 11:25:25 -0600115 /* Attempt board-specific reset */
116 board_reset();
Jon Loeliger465b9d82006-04-27 10:15:16 -0500117
Peter Tyser69454402009-02-05 11:25:25 -0600118 /* Next try asserting HRESET_REQ */
119 out_be32(&gur->rstcr, MPC86xx_RSTCR_HRST_REQ);
Jon Loeliger465b9d82006-04-27 10:15:16 -0500120
Peter Tyser69454402009-02-05 11:25:25 -0600121 while (1)
122 ;
Peter Tyser693d6382010-12-03 10:28:47 -0600123
124 return 1;
Jon Loeliger5c8aa972006-04-26 17:58:56 -0500125}
126
127
Jon Loeliger5c8aa972006-04-26 17:58:56 -0500128/*
129 * Get timebase clock frequency
130 */
Jon Loeligera1295442006-08-22 12:06:18 -0500131unsigned long
132get_tbclk(void)
Jon Loeliger5c8aa972006-04-26 17:58:56 -0500133{
Jon Loeligera1295442006-08-22 12:06:18 -0500134 sys_info_t sys_info;
Jon Loeliger5c8aa972006-04-26 17:58:56 -0500135
136 get_sys_info(&sys_info);
Prabhakar Kushwahad1698082013-08-16 14:52:26 +0530137 return (sys_info.freq_systembus + 3L) / 4L;
Jon Loeliger5c8aa972006-04-26 17:58:56 -0500138}
139
Jon Loeliger5c8aa972006-04-26 17:58:56 -0500140
141#if defined(CONFIG_WATCHDOG)
142void
143watchdog_reset(void)
144{
York Sunf48436a2016-11-23 14:06:21 -0800145#if defined(CONFIG_ARCH_MPC8610)
Jason Jin6c71b942008-05-13 11:50:36 +0800146 /*
147 * This actually feed the hard enabled watchdog.
148 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200149 volatile immap_t *immap = (immap_t *)CONFIG_SYS_IMMR;
Jason Jin6c71b942008-05-13 11:50:36 +0800150 volatile ccsr_wdt_t *wdt = &immap->im_wdt;
151 volatile ccsr_gur_t *gur = &immap->im_gur;
152 u32 tmp = gur->pordevsr;
153
154 if (tmp & 0x4000) {
155 wdt->swsrr = 0x556c;
156 wdt->swsrr = 0xaa39;
157 }
158#endif
Jon Loeliger5c8aa972006-04-26 17:58:56 -0500159}
160#endif /* CONFIG_WATCHDOG */
161
Becky Bruceb0b30942008-01-23 16:31:06 -0600162/*
163 * Print out the state of various machine registers.
Becky Bruce7e07c772008-05-08 19:02:51 -0500164 * Currently prints out LAWs, BR0/OR0, and BATs
Becky Bruceb0b30942008-01-23 16:31:06 -0600165 */
Christophe Leroy31f6e932017-07-13 15:09:54 +0200166void print_reginfo(void)
Becky Bruceb0b30942008-01-23 16:31:06 -0600167{
Becky Bruce7e07c772008-05-08 19:02:51 -0500168 print_bats();
Becky Bruceb0b30942008-01-23 16:31:06 -0600169 print_laws();
Becky Bruce0d4cee12010-06-17 11:37:20 -0500170 print_lbc_regs();
Ben Warrend448a492008-06-23 22:57:27 -0700171}
Timur Tabi107e9cd2010-03-29 12:51:07 -0500172
173/*
174 * Set the DDR BATs to reflect the actual size of DDR.
175 *
176 * dram_size is the actual size of DDR, in bytes
177 *
178 * Note: we assume that CONFIG_MAX_MEM_MAPPED is 2G or smaller as we only
179 * are using a single BAT to cover DDR.
180 *
181 * If this is not true, (e.g. CONFIG_MAX_MEM_MAPPED is 2GB but HID0_XBSEN
182 * is not defined) then we might have a situation where U-Boot will attempt
183 * to relocated itself outside of the region mapped by DBAT0.
184 * This will cause a machine check.
185 *
186 * Currently we are limited to power of two sized DDR since we only use a
187 * single bat. If a non-power of two size is used that is less than
188 * CONFIG_MAX_MEM_MAPPED u-boot will crash.
189 *
190 */
191void setup_ddr_bat(phys_addr_t dram_size)
192{
193 unsigned long batu, bl;
194
195 bl = TO_BATU_BL(min(dram_size, CONFIG_MAX_MEM_MAPPED));
196
197 if (BATU_SIZE(bl) != dram_size) {
198 u64 sz = (u64)dram_size - BATU_SIZE(bl);
199 print_size(sz, " left unmapped\n");
200 }
201
202 batu = bl | BATU_VS | BATU_VP;
203 write_bat(DBAT0, batu, CONFIG_SYS_DBAT0L);
204 write_bat(IBAT0, batu, CONFIG_SYS_IBAT0L);
205}