Jon Loeliger | 5c8aa97 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 1 | /* |
Timur Tabi | 107e9cd | 2010-03-29 12:51:07 -0500 | [diff] [blame] | 2 | * Copyright 2006,2009-2010 Freescale Semiconductor, Inc. |
Jon Loeliger | e65e32e | 2006-05-31 12:44:44 -0500 | [diff] [blame] | 3 | * Jeff Brown |
Jon Loeliger | 5c8aa97 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 4 | * 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 Bruce | 7e07c77 | 2008-05-08 19:02:51 -0500 | [diff] [blame] | 29 | #include <asm/mmu.h> |
Jon Loeliger | 5c8aa97 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 30 | #include <mpc86xx.h> |
Becky Bruce | b0b3094 | 2008-01-23 16:31:06 -0600 | [diff] [blame] | 31 | #include <asm/fsl_law.h> |
Jon Loeliger | 5c8aa97 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 32 | |
Poonam Aggrwal | 4baef82 | 2009-07-31 12:08:14 +0530 | [diff] [blame] | 33 | DECLARE_GLOBAL_DATA_PTR; |
| 34 | |
Peter Tyser | 6945440 | 2009-02-05 11:25:25 -0600 | [diff] [blame] | 35 | /* |
| 36 | * Default board reset function |
| 37 | */ |
| 38 | static void |
| 39 | __board_reset(void) |
| 40 | { |
| 41 | /* Do nothing */ |
| 42 | } |
Peter Tyser | 21d2cd2 | 2009-04-20 11:08:46 -0500 | [diff] [blame] | 43 | void board_reset(void) __attribute__((weak, alias("__board_reset"))); |
Peter Tyser | 6945440 | 2009-02-05 11:25:25 -0600 | [diff] [blame] | 44 | |
| 45 | |
Jon Loeliger | a129544 | 2006-08-22 12:06:18 -0500 | [diff] [blame] | 46 | int |
| 47 | checkcpu(void) |
Jon Loeliger | 5c8aa97 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 48 | { |
| 49 | sys_info_t sysinfo; |
| 50 | uint pvr, svr; |
Jon Loeliger | 5c8aa97 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 51 | uint major, minor; |
Peter Tyser | 698f3a1 | 2009-02-06 14:30:40 -0600 | [diff] [blame] | 52 | char buf1[32], buf2[32]; |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 53 | volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR; |
Jon Loeliger | 3b971c9 | 2007-10-16 15:26:51 -0500 | [diff] [blame] | 54 | volatile ccsr_gur_t *gur = &immap->im_gur; |
Kumar Gala | 1e2e9fa | 2009-06-18 08:23:01 -0500 | [diff] [blame] | 55 | struct cpu_type *cpu; |
Peter Tyser | 698f3a1 | 2009-02-06 14:30:40 -0600 | [diff] [blame] | 56 | uint msscr0 = mfspr(MSSCR0); |
Jon Loeliger | 5c8aa97 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 57 | |
| 58 | svr = get_svr(); |
Jon Loeliger | 5c8aa97 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 59 | major = SVR_MAJ(svr); |
| 60 | minor = SVR_MIN(svr); |
| 61 | |
Poonam Aggrwal | 36a6843 | 2009-09-03 19:42:40 +0530 | [diff] [blame] | 62 | if (cpu_numcores() > 1) { |
| 63 | #ifndef CONFIG_MP |
| 64 | puts("Unicore software on multiprocessor system!!\n" |
| 65 | "To enable mutlticore build define CONFIG_MP\n"); |
| 66 | #endif |
| 67 | } |
Peter Tyser | 698f3a1 | 2009-02-06 14:30:40 -0600 | [diff] [blame] | 68 | puts("CPU: "); |
| 69 | |
Simon Glass | a8b5739 | 2012-12-13 20:48:48 +0000 | [diff] [blame] | 70 | cpu = gd->arch.cpu; |
Poonam Aggrwal | 4baef82 | 2009-07-31 12:08:14 +0530 | [diff] [blame] | 71 | |
Poonam Aggrwal | da6e1ca | 2009-09-02 13:35:21 +0530 | [diff] [blame] | 72 | puts(cpu->name); |
Kumar Gala | 1e2e9fa | 2009-06-18 08:23:01 -0500 | [diff] [blame] | 73 | |
Jon Loeliger | 5c8aa97 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 74 | printf(", Version: %d.%d, (0x%08x)\n", major, minor, svr); |
Peter Tyser | 698f3a1 | 2009-02-06 14:30:40 -0600 | [diff] [blame] | 75 | puts("Core: "); |
| 76 | |
| 77 | pvr = get_pvr(); |
Peter Tyser | 698f3a1 | 2009-02-06 14:30:40 -0600 | [diff] [blame] | 78 | major = PVR_E600_MAJ(pvr); |
| 79 | minor = PVR_E600_MIN(pvr); |
| 80 | |
Fabio Estevam | f4c557c | 2013-04-21 13:11:02 -0300 | [diff] [blame^] | 81 | printf("e600 Core %d", (msscr0 & 0x20) ? 1 : 0); |
Peter Tyser | 698f3a1 | 2009-02-06 14:30:40 -0600 | [diff] [blame] | 82 | if (gur->pordevsr & MPC86xx_PORDEVSR_CORE1TE) |
| 83 | puts("\n Core1Translation Enabled"); |
| 84 | debug(" (MSSCR0=%x, PORDEVSR=%x)", msscr0, gur->pordevsr); |
| 85 | |
| 86 | printf(", Version: %d.%d, (0x%08x)\n", major, minor, pvr); |
Jon Loeliger | 5c8aa97 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 87 | |
| 88 | get_sys_info(&sysinfo); |
| 89 | |
Peter Tyser | 698f3a1 | 2009-02-06 14:30:40 -0600 | [diff] [blame] | 90 | puts("Clock Configuration:\n"); |
| 91 | printf(" CPU:%-4s MHz, ", strmhz(buf1, sysinfo.freqProcessor)); |
| 92 | printf("MPX:%-4s MHz\n", strmhz(buf1, sysinfo.freqSystemBus)); |
| 93 | printf(" DDR:%-4s MHz (%s MT/s data rate), ", |
| 94 | strmhz(buf1, sysinfo.freqSystemBus / 2), |
| 95 | strmhz(buf2, sysinfo.freqSystemBus)); |
Jon Loeliger | 465b9d8 | 2006-04-27 10:15:16 -0500 | [diff] [blame] | 96 | |
Trent Piepho | 0b691fc | 2008-12-03 15:16:37 -0800 | [diff] [blame] | 97 | if (sysinfo.freqLocalBus > LCRR_CLKDIV) { |
Peter Tyser | 698f3a1 | 2009-02-06 14:30:40 -0600 | [diff] [blame] | 98 | printf("LBC:%-4s MHz\n", strmhz(buf1, sysinfo.freqLocalBus)); |
Jon Loeliger | 5c8aa97 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 99 | } else { |
Wolfgang Denk | 3fe630c | 2009-01-12 14:50:35 +0100 | [diff] [blame] | 100 | printf("LBC: unknown (LCRR[CLKDIV] = 0x%02lx)\n", |
Trent Piepho | 0b691fc | 2008-12-03 15:16:37 -0800 | [diff] [blame] | 101 | sysinfo.freqLocalBus); |
Jon Loeliger | 5c8aa97 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 102 | } |
| 103 | |
Peter Tyser | 698f3a1 | 2009-02-06 14:30:40 -0600 | [diff] [blame] | 104 | puts("L1: D-cache 32 KB enabled\n"); |
| 105 | puts(" I-cache 32 KB enabled\n"); |
| 106 | |
| 107 | puts("L2: "); |
| 108 | if (get_l2cr() & 0x80000000) { |
| 109 | #if defined(CONFIG_MPC8610) |
| 110 | puts("256"); |
| 111 | #elif defined(CONFIG_MPC8641) |
| 112 | puts("512"); |
| 113 | #endif |
| 114 | puts(" KB enabled\n"); |
| 115 | } else { |
Jon Loeliger | e65e32e | 2006-05-31 12:44:44 -0500 | [diff] [blame] | 116 | puts("Disabled\n"); |
Peter Tyser | 698f3a1 | 2009-02-06 14:30:40 -0600 | [diff] [blame] | 117 | } |
Jon Loeliger | 465b9d8 | 2006-04-27 10:15:16 -0500 | [diff] [blame] | 118 | |
| 119 | return 0; |
Jon Loeliger | 5c8aa97 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 120 | } |
| 121 | |
| 122 | |
Peter Tyser | 693d638 | 2010-12-03 10:28:47 -0600 | [diff] [blame] | 123 | int do_reset(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
Jon Loeliger | 5c8aa97 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 124 | { |
Peter Tyser | 6945440 | 2009-02-05 11:25:25 -0600 | [diff] [blame] | 125 | volatile immap_t *immap = (immap_t *)CONFIG_SYS_IMMR; |
| 126 | volatile ccsr_gur_t *gur = &immap->im_gur; |
Jon Loeliger | 465b9d8 | 2006-04-27 10:15:16 -0500 | [diff] [blame] | 127 | |
Peter Tyser | 6945440 | 2009-02-05 11:25:25 -0600 | [diff] [blame] | 128 | /* Attempt board-specific reset */ |
| 129 | board_reset(); |
Jon Loeliger | 465b9d8 | 2006-04-27 10:15:16 -0500 | [diff] [blame] | 130 | |
Peter Tyser | 6945440 | 2009-02-05 11:25:25 -0600 | [diff] [blame] | 131 | /* Next try asserting HRESET_REQ */ |
| 132 | out_be32(&gur->rstcr, MPC86xx_RSTCR_HRST_REQ); |
Jon Loeliger | 465b9d8 | 2006-04-27 10:15:16 -0500 | [diff] [blame] | 133 | |
Peter Tyser | 6945440 | 2009-02-05 11:25:25 -0600 | [diff] [blame] | 134 | while (1) |
| 135 | ; |
Peter Tyser | 693d638 | 2010-12-03 10:28:47 -0600 | [diff] [blame] | 136 | |
| 137 | return 1; |
Jon Loeliger | 5c8aa97 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 138 | } |
| 139 | |
| 140 | |
Jon Loeliger | 5c8aa97 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 141 | /* |
| 142 | * Get timebase clock frequency |
| 143 | */ |
Jon Loeliger | a129544 | 2006-08-22 12:06:18 -0500 | [diff] [blame] | 144 | unsigned long |
| 145 | get_tbclk(void) |
Jon Loeliger | 5c8aa97 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 146 | { |
Jon Loeliger | a129544 | 2006-08-22 12:06:18 -0500 | [diff] [blame] | 147 | sys_info_t sys_info; |
Jon Loeliger | 5c8aa97 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 148 | |
| 149 | get_sys_info(&sys_info); |
Jon Loeliger | 465b9d8 | 2006-04-27 10:15:16 -0500 | [diff] [blame] | 150 | return (sys_info.freqSystemBus + 3L) / 4L; |
Jon Loeliger | 5c8aa97 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 151 | } |
| 152 | |
Jon Loeliger | 5c8aa97 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 153 | |
| 154 | #if defined(CONFIG_WATCHDOG) |
| 155 | void |
| 156 | watchdog_reset(void) |
| 157 | { |
Jason Jin | 6c71b94 | 2008-05-13 11:50:36 +0800 | [diff] [blame] | 158 | #if defined(CONFIG_MPC8610) |
| 159 | /* |
| 160 | * This actually feed the hard enabled watchdog. |
| 161 | */ |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 162 | volatile immap_t *immap = (immap_t *)CONFIG_SYS_IMMR; |
Jason Jin | 6c71b94 | 2008-05-13 11:50:36 +0800 | [diff] [blame] | 163 | volatile ccsr_wdt_t *wdt = &immap->im_wdt; |
| 164 | volatile ccsr_gur_t *gur = &immap->im_gur; |
| 165 | u32 tmp = gur->pordevsr; |
| 166 | |
| 167 | if (tmp & 0x4000) { |
| 168 | wdt->swsrr = 0x556c; |
| 169 | wdt->swsrr = 0xaa39; |
| 170 | } |
| 171 | #endif |
Jon Loeliger | 5c8aa97 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 172 | } |
| 173 | #endif /* CONFIG_WATCHDOG */ |
| 174 | |
Becky Bruce | b0b3094 | 2008-01-23 16:31:06 -0600 | [diff] [blame] | 175 | /* |
| 176 | * Print out the state of various machine registers. |
Becky Bruce | 7e07c77 | 2008-05-08 19:02:51 -0500 | [diff] [blame] | 177 | * Currently prints out LAWs, BR0/OR0, and BATs |
Becky Bruce | b0b3094 | 2008-01-23 16:31:06 -0600 | [diff] [blame] | 178 | */ |
| 179 | void mpc86xx_reginfo(void) |
| 180 | { |
Becky Bruce | 7e07c77 | 2008-05-08 19:02:51 -0500 | [diff] [blame] | 181 | print_bats(); |
Becky Bruce | b0b3094 | 2008-01-23 16:31:06 -0600 | [diff] [blame] | 182 | print_laws(); |
Becky Bruce | 0d4cee1 | 2010-06-17 11:37:20 -0500 | [diff] [blame] | 183 | print_lbc_regs(); |
Ben Warren | d448a49 | 2008-06-23 22:57:27 -0700 | [diff] [blame] | 184 | } |
Timur Tabi | 107e9cd | 2010-03-29 12:51:07 -0500 | [diff] [blame] | 185 | |
| 186 | /* |
| 187 | * Set the DDR BATs to reflect the actual size of DDR. |
| 188 | * |
| 189 | * dram_size is the actual size of DDR, in bytes |
| 190 | * |
| 191 | * Note: we assume that CONFIG_MAX_MEM_MAPPED is 2G or smaller as we only |
| 192 | * are using a single BAT to cover DDR. |
| 193 | * |
| 194 | * If this is not true, (e.g. CONFIG_MAX_MEM_MAPPED is 2GB but HID0_XBSEN |
| 195 | * is not defined) then we might have a situation where U-Boot will attempt |
| 196 | * to relocated itself outside of the region mapped by DBAT0. |
| 197 | * This will cause a machine check. |
| 198 | * |
| 199 | * Currently we are limited to power of two sized DDR since we only use a |
| 200 | * single bat. If a non-power of two size is used that is less than |
| 201 | * CONFIG_MAX_MEM_MAPPED u-boot will crash. |
| 202 | * |
| 203 | */ |
| 204 | void setup_ddr_bat(phys_addr_t dram_size) |
| 205 | { |
| 206 | unsigned long batu, bl; |
| 207 | |
| 208 | bl = TO_BATU_BL(min(dram_size, CONFIG_MAX_MEM_MAPPED)); |
| 209 | |
| 210 | if (BATU_SIZE(bl) != dram_size) { |
| 211 | u64 sz = (u64)dram_size - BATU_SIZE(bl); |
| 212 | print_size(sz, " left unmapped\n"); |
| 213 | } |
| 214 | |
| 215 | batu = bl | BATU_VS | BATU_VP; |
| 216 | write_bat(DBAT0, batu, CONFIG_SYS_DBAT0L); |
| 217 | write_bat(IBAT0, batu, CONFIG_SYS_IBAT0L); |
| 218 | } |