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