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 | * |
Wolfgang Denk | d79de1d | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 6 | * SPDX-License-Identifier: GPL-2.0+ |
Jon Loeliger | 5c8aa97 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | #include <common.h> |
| 10 | #include <watchdog.h> |
| 11 | #include <command.h> |
| 12 | #include <asm/cache.h> |
Becky Bruce | 7e07c77 | 2008-05-08 19:02:51 -0500 | [diff] [blame] | 13 | #include <asm/mmu.h> |
Jon Loeliger | 5c8aa97 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 14 | #include <mpc86xx.h> |
Becky Bruce | b0b3094 | 2008-01-23 16:31:06 -0600 | [diff] [blame] | 15 | #include <asm/fsl_law.h> |
Christophe Leroy | 31f6e93 | 2017-07-13 15:09:54 +0200 | [diff] [blame] | 16 | #include <asm/ppc.h> |
Jon Loeliger | 5c8aa97 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 17 | |
Poonam Aggrwal | 4baef82 | 2009-07-31 12:08:14 +0530 | [diff] [blame] | 18 | DECLARE_GLOBAL_DATA_PTR; |
| 19 | |
Peter Tyser | 6945440 | 2009-02-05 11:25:25 -0600 | [diff] [blame] | 20 | /* |
| 21 | * Default board reset function |
| 22 | */ |
| 23 | static void |
| 24 | __board_reset(void) |
| 25 | { |
| 26 | /* Do nothing */ |
| 27 | } |
Peter Tyser | 21d2cd2 | 2009-04-20 11:08:46 -0500 | [diff] [blame] | 28 | void board_reset(void) __attribute__((weak, alias("__board_reset"))); |
Peter Tyser | 6945440 | 2009-02-05 11:25:25 -0600 | [diff] [blame] | 29 | |
| 30 | |
Jon Loeliger | a129544 | 2006-08-22 12:06:18 -0500 | [diff] [blame] | 31 | int |
| 32 | checkcpu(void) |
Jon Loeliger | 5c8aa97 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 33 | { |
| 34 | sys_info_t sysinfo; |
| 35 | uint pvr, svr; |
Jon Loeliger | 5c8aa97 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 36 | uint major, minor; |
Peter Tyser | 698f3a1 | 2009-02-06 14:30:40 -0600 | [diff] [blame] | 37 | char buf1[32], buf2[32]; |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 38 | volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR; |
Jon Loeliger | 3b971c9 | 2007-10-16 15:26:51 -0500 | [diff] [blame] | 39 | volatile ccsr_gur_t *gur = &immap->im_gur; |
Kumar Gala | 1e2e9fa | 2009-06-18 08:23:01 -0500 | [diff] [blame] | 40 | struct cpu_type *cpu; |
Peter Tyser | 698f3a1 | 2009-02-06 14:30:40 -0600 | [diff] [blame] | 41 | uint msscr0 = mfspr(MSSCR0); |
Jon Loeliger | 5c8aa97 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 42 | |
| 43 | svr = get_svr(); |
Jon Loeliger | 5c8aa97 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 44 | major = SVR_MAJ(svr); |
| 45 | minor = SVR_MIN(svr); |
| 46 | |
Poonam Aggrwal | 36a6843 | 2009-09-03 19:42:40 +0530 | [diff] [blame] | 47 | 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 Tyser | 698f3a1 | 2009-02-06 14:30:40 -0600 | [diff] [blame] | 53 | puts("CPU: "); |
| 54 | |
Simon Glass | a8b5739 | 2012-12-13 20:48:48 +0000 | [diff] [blame] | 55 | cpu = gd->arch.cpu; |
Poonam Aggrwal | 4baef82 | 2009-07-31 12:08:14 +0530 | [diff] [blame] | 56 | |
Poonam Aggrwal | da6e1ca | 2009-09-02 13:35:21 +0530 | [diff] [blame] | 57 | puts(cpu->name); |
Kumar Gala | 1e2e9fa | 2009-06-18 08:23:01 -0500 | [diff] [blame] | 58 | |
Jon Loeliger | 5c8aa97 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 59 | printf(", Version: %d.%d, (0x%08x)\n", major, minor, svr); |
Peter Tyser | 698f3a1 | 2009-02-06 14:30:40 -0600 | [diff] [blame] | 60 | puts("Core: "); |
| 61 | |
| 62 | pvr = get_pvr(); |
Peter Tyser | 698f3a1 | 2009-02-06 14:30:40 -0600 | [diff] [blame] | 63 | major = PVR_E600_MAJ(pvr); |
| 64 | minor = PVR_E600_MIN(pvr); |
| 65 | |
Fabio Estevam | f4c557c | 2013-04-21 13:11:02 -0300 | [diff] [blame] | 66 | printf("e600 Core %d", (msscr0 & 0x20) ? 1 : 0); |
Peter Tyser | 698f3a1 | 2009-02-06 14:30:40 -0600 | [diff] [blame] | 67 | 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 Loeliger | 5c8aa97 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 72 | |
| 73 | get_sys_info(&sysinfo); |
| 74 | |
Peter Tyser | 698f3a1 | 2009-02-06 14:30:40 -0600 | [diff] [blame] | 75 | puts("Clock Configuration:\n"); |
Prabhakar Kushwaha | d169808 | 2013-08-16 14:52:26 +0530 | [diff] [blame] | 76 | printf(" CPU:%-4s MHz, ", strmhz(buf1, sysinfo.freq_processor)); |
| 77 | printf("MPX:%-4s MHz\n", strmhz(buf1, sysinfo.freq_systembus)); |
Peter Tyser | 698f3a1 | 2009-02-06 14:30:40 -0600 | [diff] [blame] | 78 | printf(" DDR:%-4s MHz (%s MT/s data rate), ", |
Prabhakar Kushwaha | d169808 | 2013-08-16 14:52:26 +0530 | [diff] [blame] | 79 | strmhz(buf1, sysinfo.freq_systembus / 2), |
| 80 | strmhz(buf2, sysinfo.freq_systembus)); |
Jon Loeliger | 465b9d8 | 2006-04-27 10:15:16 -0500 | [diff] [blame] | 81 | |
Prabhakar Kushwaha | d169808 | 2013-08-16 14:52:26 +0530 | [diff] [blame] | 82 | if (sysinfo.freq_localbus > LCRR_CLKDIV) { |
| 83 | printf("LBC:%-4s MHz\n", strmhz(buf1, sysinfo.freq_localbus)); |
Jon Loeliger | 5c8aa97 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 84 | } else { |
Wolfgang Denk | 3fe630c | 2009-01-12 14:50:35 +0100 | [diff] [blame] | 85 | printf("LBC: unknown (LCRR[CLKDIV] = 0x%02lx)\n", |
Prabhakar Kushwaha | d169808 | 2013-08-16 14:52:26 +0530 | [diff] [blame] | 86 | sysinfo.freq_localbus); |
Jon Loeliger | 5c8aa97 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 87 | } |
| 88 | |
Shruti Kanetkar | 8115936 | 2013-08-15 11:25:38 -0500 | [diff] [blame] | 89 | puts("L1: D-cache 32 KiB enabled\n"); |
| 90 | puts(" I-cache 32 KiB enabled\n"); |
Peter Tyser | 698f3a1 | 2009-02-06 14:30:40 -0600 | [diff] [blame] | 91 | |
| 92 | puts("L2: "); |
| 93 | if (get_l2cr() & 0x80000000) { |
York Sun | f48436a | 2016-11-23 14:06:21 -0800 | [diff] [blame] | 94 | #if defined(CONFIG_ARCH_MPC8610) |
Peter Tyser | 698f3a1 | 2009-02-06 14:30:40 -0600 | [diff] [blame] | 95 | puts("256"); |
York Sun | efc30b6 | 2016-11-23 14:08:36 -0800 | [diff] [blame] | 96 | #elif defined(CONFIG_ARCH_MPC8641) |
Peter Tyser | 698f3a1 | 2009-02-06 14:30:40 -0600 | [diff] [blame] | 97 | puts("512"); |
| 98 | #endif |
Shruti Kanetkar | 8115936 | 2013-08-15 11:25:38 -0500 | [diff] [blame] | 99 | puts(" KiB enabled\n"); |
Peter Tyser | 698f3a1 | 2009-02-06 14:30:40 -0600 | [diff] [blame] | 100 | } else { |
Jon Loeliger | e65e32e | 2006-05-31 12:44:44 -0500 | [diff] [blame] | 101 | puts("Disabled\n"); |
Peter Tyser | 698f3a1 | 2009-02-06 14:30:40 -0600 | [diff] [blame] | 102 | } |
Jon Loeliger | 465b9d8 | 2006-04-27 10:15:16 -0500 | [diff] [blame] | 103 | |
| 104 | return 0; |
Jon Loeliger | 5c8aa97 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 105 | } |
| 106 | |
| 107 | |
Peter Tyser | 693d638 | 2010-12-03 10:28:47 -0600 | [diff] [blame] | 108 | 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] | 109 | { |
Peter Tyser | 6945440 | 2009-02-05 11:25:25 -0600 | [diff] [blame] | 110 | volatile immap_t *immap = (immap_t *)CONFIG_SYS_IMMR; |
| 111 | volatile ccsr_gur_t *gur = &immap->im_gur; |
Jon Loeliger | 465b9d8 | 2006-04-27 10:15:16 -0500 | [diff] [blame] | 112 | |
Peter Tyser | 6945440 | 2009-02-05 11:25:25 -0600 | [diff] [blame] | 113 | /* Attempt board-specific reset */ |
| 114 | board_reset(); |
Jon Loeliger | 465b9d8 | 2006-04-27 10:15:16 -0500 | [diff] [blame] | 115 | |
Peter Tyser | 6945440 | 2009-02-05 11:25:25 -0600 | [diff] [blame] | 116 | /* Next try asserting HRESET_REQ */ |
| 117 | out_be32(&gur->rstcr, MPC86xx_RSTCR_HRST_REQ); |
Jon Loeliger | 465b9d8 | 2006-04-27 10:15:16 -0500 | [diff] [blame] | 118 | |
Peter Tyser | 6945440 | 2009-02-05 11:25:25 -0600 | [diff] [blame] | 119 | while (1) |
| 120 | ; |
Peter Tyser | 693d638 | 2010-12-03 10:28:47 -0600 | [diff] [blame] | 121 | |
| 122 | return 1; |
Jon Loeliger | 5c8aa97 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 123 | } |
| 124 | |
| 125 | |
Jon Loeliger | 5c8aa97 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 126 | /* |
| 127 | * Get timebase clock frequency |
| 128 | */ |
Jon Loeliger | a129544 | 2006-08-22 12:06:18 -0500 | [diff] [blame] | 129 | unsigned long |
| 130 | get_tbclk(void) |
Jon Loeliger | 5c8aa97 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 131 | { |
Jon Loeliger | a129544 | 2006-08-22 12:06:18 -0500 | [diff] [blame] | 132 | sys_info_t sys_info; |
Jon Loeliger | 5c8aa97 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 133 | |
| 134 | get_sys_info(&sys_info); |
Prabhakar Kushwaha | d169808 | 2013-08-16 14:52:26 +0530 | [diff] [blame] | 135 | return (sys_info.freq_systembus + 3L) / 4L; |
Jon Loeliger | 5c8aa97 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 136 | } |
| 137 | |
Jon Loeliger | 5c8aa97 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 138 | |
| 139 | #if defined(CONFIG_WATCHDOG) |
| 140 | void |
| 141 | watchdog_reset(void) |
| 142 | { |
York Sun | f48436a | 2016-11-23 14:06:21 -0800 | [diff] [blame] | 143 | #if defined(CONFIG_ARCH_MPC8610) |
Jason Jin | 6c71b94 | 2008-05-13 11:50:36 +0800 | [diff] [blame] | 144 | /* |
| 145 | * This actually feed the hard enabled watchdog. |
| 146 | */ |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 147 | volatile immap_t *immap = (immap_t *)CONFIG_SYS_IMMR; |
Jason Jin | 6c71b94 | 2008-05-13 11:50:36 +0800 | [diff] [blame] | 148 | 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 Loeliger | 5c8aa97 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 157 | } |
| 158 | #endif /* CONFIG_WATCHDOG */ |
| 159 | |
Becky Bruce | b0b3094 | 2008-01-23 16:31:06 -0600 | [diff] [blame] | 160 | /* |
| 161 | * Print out the state of various machine registers. |
Becky Bruce | 7e07c77 | 2008-05-08 19:02:51 -0500 | [diff] [blame] | 162 | * Currently prints out LAWs, BR0/OR0, and BATs |
Becky Bruce | b0b3094 | 2008-01-23 16:31:06 -0600 | [diff] [blame] | 163 | */ |
Christophe Leroy | 31f6e93 | 2017-07-13 15:09:54 +0200 | [diff] [blame] | 164 | void print_reginfo(void) |
Becky Bruce | b0b3094 | 2008-01-23 16:31:06 -0600 | [diff] [blame] | 165 | { |
Becky Bruce | 7e07c77 | 2008-05-08 19:02:51 -0500 | [diff] [blame] | 166 | print_bats(); |
Becky Bruce | b0b3094 | 2008-01-23 16:31:06 -0600 | [diff] [blame] | 167 | print_laws(); |
Becky Bruce | 0d4cee1 | 2010-06-17 11:37:20 -0500 | [diff] [blame] | 168 | print_lbc_regs(); |
Ben Warren | d448a49 | 2008-06-23 22:57:27 -0700 | [diff] [blame] | 169 | } |
Timur Tabi | 107e9cd | 2010-03-29 12:51:07 -0500 | [diff] [blame] | 170 | |
| 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 | */ |
| 189 | void 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 | } |