blob: a02e872862bc53b592e7408450c7b70060ac29ce [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 *
Wolfgang Denkd79de1d2013-07-08 09:37:19 +02006 * SPDX-License-Identifier: GPL-2.0+
Jon Loeliger5c8aa972006-04-26 17:58:56 -05007 */
8
9#include <common.h>
10#include <watchdog.h>
11#include <command.h>
12#include <asm/cache.h>
Becky Bruce7e07c772008-05-08 19:02:51 -050013#include <asm/mmu.h>
Jon Loeliger5c8aa972006-04-26 17:58:56 -050014#include <mpc86xx.h>
Becky Bruceb0b30942008-01-23 16:31:06 -060015#include <asm/fsl_law.h>
Christophe Leroy31f6e932017-07-13 15:09:54 +020016#include <asm/ppc.h>
Jon Loeliger5c8aa972006-04-26 17:58:56 -050017
Poonam Aggrwal4baef822009-07-31 12:08:14 +053018DECLARE_GLOBAL_DATA_PTR;
19
Peter Tyser69454402009-02-05 11:25:25 -060020/*
21 * Default board reset function
22 */
23static void
24__board_reset(void)
25{
26 /* Do nothing */
27}
Peter Tyser21d2cd22009-04-20 11:08:46 -050028void board_reset(void) __attribute__((weak, alias("__board_reset")));
Peter Tyser69454402009-02-05 11:25:25 -060029
30
Jon Loeligera1295442006-08-22 12:06:18 -050031int
32checkcpu(void)
Jon Loeliger5c8aa972006-04-26 17:58:56 -050033{
34 sys_info_t sysinfo;
35 uint pvr, svr;
Jon Loeliger5c8aa972006-04-26 17:58:56 -050036 uint major, minor;
Peter Tyser698f3a12009-02-06 14:30:40 -060037 char buf1[32], buf2[32];
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020038 volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR;
Jon Loeliger3b971c92007-10-16 15:26:51 -050039 volatile ccsr_gur_t *gur = &immap->im_gur;
Kumar Gala1e2e9fa2009-06-18 08:23:01 -050040 struct cpu_type *cpu;
Peter Tyser698f3a12009-02-06 14:30:40 -060041 uint msscr0 = mfspr(MSSCR0);
Jon Loeliger5c8aa972006-04-26 17:58:56 -050042
43 svr = get_svr();
Jon Loeliger5c8aa972006-04-26 17:58:56 -050044 major = SVR_MAJ(svr);
45 minor = SVR_MIN(svr);
46
Poonam Aggrwal36a68432009-09-03 19:42:40 +053047 if (cpu_numcores() > 1) {
48#ifndef CONFIG_MP
49 puts("Unicore software on multiprocessor system!!\n"
50 "To enable mutlticore build define CONFIG_MP\n");
51#endif
52 }
Peter Tyser698f3a12009-02-06 14:30:40 -060053 puts("CPU: ");
54
Simon Glassa8b57392012-12-13 20:48:48 +000055 cpu = gd->arch.cpu;
Poonam Aggrwal4baef822009-07-31 12:08:14 +053056
Poonam Aggrwalda6e1ca2009-09-02 13:35:21 +053057 puts(cpu->name);
Kumar Gala1e2e9fa2009-06-18 08:23:01 -050058
Jon Loeliger5c8aa972006-04-26 17:58:56 -050059 printf(", Version: %d.%d, (0x%08x)\n", major, minor, svr);
Peter Tyser698f3a12009-02-06 14:30:40 -060060 puts("Core: ");
61
62 pvr = get_pvr();
Peter Tyser698f3a12009-02-06 14:30:40 -060063 major = PVR_E600_MAJ(pvr);
64 minor = PVR_E600_MIN(pvr);
65
Fabio Estevamf4c557c2013-04-21 13:11:02 -030066 printf("e600 Core %d", (msscr0 & 0x20) ? 1 : 0);
Peter Tyser698f3a12009-02-06 14:30:40 -060067 if (gur->pordevsr & MPC86xx_PORDEVSR_CORE1TE)
68 puts("\n Core1Translation Enabled");
69 debug(" (MSSCR0=%x, PORDEVSR=%x)", msscr0, gur->pordevsr);
70
71 printf(", Version: %d.%d, (0x%08x)\n", major, minor, pvr);
Jon Loeliger5c8aa972006-04-26 17:58:56 -050072
73 get_sys_info(&sysinfo);
74
Peter Tyser698f3a12009-02-06 14:30:40 -060075 puts("Clock Configuration:\n");
Prabhakar Kushwahad1698082013-08-16 14:52:26 +053076 printf(" CPU:%-4s MHz, ", strmhz(buf1, sysinfo.freq_processor));
77 printf("MPX:%-4s MHz\n", strmhz(buf1, sysinfo.freq_systembus));
Peter Tyser698f3a12009-02-06 14:30:40 -060078 printf(" DDR:%-4s MHz (%s MT/s data rate), ",
Prabhakar Kushwahad1698082013-08-16 14:52:26 +053079 strmhz(buf1, sysinfo.freq_systembus / 2),
80 strmhz(buf2, sysinfo.freq_systembus));
Jon Loeliger465b9d82006-04-27 10:15:16 -050081
Prabhakar Kushwahad1698082013-08-16 14:52:26 +053082 if (sysinfo.freq_localbus > LCRR_CLKDIV) {
83 printf("LBC:%-4s MHz\n", strmhz(buf1, sysinfo.freq_localbus));
Jon Loeliger5c8aa972006-04-26 17:58:56 -050084 } else {
Wolfgang Denk3fe630c2009-01-12 14:50:35 +010085 printf("LBC: unknown (LCRR[CLKDIV] = 0x%02lx)\n",
Prabhakar Kushwahad1698082013-08-16 14:52:26 +053086 sysinfo.freq_localbus);
Jon Loeliger5c8aa972006-04-26 17:58:56 -050087 }
88
Shruti Kanetkar81159362013-08-15 11:25:38 -050089 puts("L1: D-cache 32 KiB enabled\n");
90 puts(" I-cache 32 KiB enabled\n");
Peter Tyser698f3a12009-02-06 14:30:40 -060091
92 puts("L2: ");
93 if (get_l2cr() & 0x80000000) {
York Sunf48436a2016-11-23 14:06:21 -080094#if defined(CONFIG_ARCH_MPC8610)
Peter Tyser698f3a12009-02-06 14:30:40 -060095 puts("256");
York Sunefc30b62016-11-23 14:08:36 -080096#elif defined(CONFIG_ARCH_MPC8641)
Peter Tyser698f3a12009-02-06 14:30:40 -060097 puts("512");
98#endif
Shruti Kanetkar81159362013-08-15 11:25:38 -050099 puts(" KiB enabled\n");
Peter Tyser698f3a12009-02-06 14:30:40 -0600100 } else {
Jon Loeligere65e32e2006-05-31 12:44:44 -0500101 puts("Disabled\n");
Peter Tyser698f3a12009-02-06 14:30:40 -0600102 }
Jon Loeliger465b9d82006-04-27 10:15:16 -0500103
104 return 0;
Jon Loeliger5c8aa972006-04-26 17:58:56 -0500105}
106
107
Peter Tyser693d6382010-12-03 10:28:47 -0600108int do_reset(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
Jon Loeliger5c8aa972006-04-26 17:58:56 -0500109{
Peter Tyser69454402009-02-05 11:25:25 -0600110 volatile immap_t *immap = (immap_t *)CONFIG_SYS_IMMR;
111 volatile ccsr_gur_t *gur = &immap->im_gur;
Jon Loeliger465b9d82006-04-27 10:15:16 -0500112
Peter Tyser69454402009-02-05 11:25:25 -0600113 /* Attempt board-specific reset */
114 board_reset();
Jon Loeliger465b9d82006-04-27 10:15:16 -0500115
Peter Tyser69454402009-02-05 11:25:25 -0600116 /* Next try asserting HRESET_REQ */
117 out_be32(&gur->rstcr, MPC86xx_RSTCR_HRST_REQ);
Jon Loeliger465b9d82006-04-27 10:15:16 -0500118
Peter Tyser69454402009-02-05 11:25:25 -0600119 while (1)
120 ;
Peter Tyser693d6382010-12-03 10:28:47 -0600121
122 return 1;
Jon Loeliger5c8aa972006-04-26 17:58:56 -0500123}
124
125
Jon Loeliger5c8aa972006-04-26 17:58:56 -0500126/*
127 * Get timebase clock frequency
128 */
Jon Loeligera1295442006-08-22 12:06:18 -0500129unsigned long
130get_tbclk(void)
Jon Loeliger5c8aa972006-04-26 17:58:56 -0500131{
Jon Loeligera1295442006-08-22 12:06:18 -0500132 sys_info_t sys_info;
Jon Loeliger5c8aa972006-04-26 17:58:56 -0500133
134 get_sys_info(&sys_info);
Prabhakar Kushwahad1698082013-08-16 14:52:26 +0530135 return (sys_info.freq_systembus + 3L) / 4L;
Jon Loeliger5c8aa972006-04-26 17:58:56 -0500136}
137
Jon Loeliger5c8aa972006-04-26 17:58:56 -0500138
139#if defined(CONFIG_WATCHDOG)
140void
141watchdog_reset(void)
142{
York Sunf48436a2016-11-23 14:06:21 -0800143#if defined(CONFIG_ARCH_MPC8610)
Jason Jin6c71b942008-05-13 11:50:36 +0800144 /*
145 * This actually feed the hard enabled watchdog.
146 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200147 volatile immap_t *immap = (immap_t *)CONFIG_SYS_IMMR;
Jason Jin6c71b942008-05-13 11:50:36 +0800148 volatile ccsr_wdt_t *wdt = &immap->im_wdt;
149 volatile ccsr_gur_t *gur = &immap->im_gur;
150 u32 tmp = gur->pordevsr;
151
152 if (tmp & 0x4000) {
153 wdt->swsrr = 0x556c;
154 wdt->swsrr = 0xaa39;
155 }
156#endif
Jon Loeliger5c8aa972006-04-26 17:58:56 -0500157}
158#endif /* CONFIG_WATCHDOG */
159
Becky Bruceb0b30942008-01-23 16:31:06 -0600160/*
161 * Print out the state of various machine registers.
Becky Bruce7e07c772008-05-08 19:02:51 -0500162 * Currently prints out LAWs, BR0/OR0, and BATs
Becky Bruceb0b30942008-01-23 16:31:06 -0600163 */
Christophe Leroy31f6e932017-07-13 15:09:54 +0200164void print_reginfo(void)
Becky Bruceb0b30942008-01-23 16:31:06 -0600165{
Becky Bruce7e07c772008-05-08 19:02:51 -0500166 print_bats();
Becky Bruceb0b30942008-01-23 16:31:06 -0600167 print_laws();
Becky Bruce0d4cee12010-06-17 11:37:20 -0500168 print_lbc_regs();
Ben Warrend448a492008-06-23 22:57:27 -0700169}
Timur Tabi107e9cd2010-03-29 12:51:07 -0500170
171/*
172 * Set the DDR BATs to reflect the actual size of DDR.
173 *
174 * dram_size is the actual size of DDR, in bytes
175 *
176 * Note: we assume that CONFIG_MAX_MEM_MAPPED is 2G or smaller as we only
177 * are using a single BAT to cover DDR.
178 *
179 * If this is not true, (e.g. CONFIG_MAX_MEM_MAPPED is 2GB but HID0_XBSEN
180 * is not defined) then we might have a situation where U-Boot will attempt
181 * to relocated itself outside of the region mapped by DBAT0.
182 * This will cause a machine check.
183 *
184 * Currently we are limited to power of two sized DDR since we only use a
185 * single bat. If a non-power of two size is used that is less than
186 * CONFIG_MAX_MEM_MAPPED u-boot will crash.
187 *
188 */
189void setup_ddr_bat(phys_addr_t dram_size)
190{
191 unsigned long batu, bl;
192
193 bl = TO_BATU_BL(min(dram_size, CONFIG_MAX_MEM_MAPPED));
194
195 if (BATU_SIZE(bl) != dram_size) {
196 u64 sz = (u64)dram_size - BATU_SIZE(bl);
197 print_size(sz, " left unmapped\n");
198 }
199
200 batu = bl | BATU_VS | BATU_VP;
201 write_bat(DBAT0, batu, CONFIG_SYS_DBAT0L);
202 write_bat(IBAT0, batu, CONFIG_SYS_IBAT0L);
203}