uboot/arch/powerpc/cpu/mpc86xx/cpu.c
<<
>>
Prefs
   1// SPDX-License-Identifier: GPL-2.0+
   2/*
   3 * Copyright 2006,2009-2010 Freescale Semiconductor, Inc.
   4 * Jeff Brown
   5 * Srikanth Srinivasan (srikanth.srinivasan@freescale.com)
   6 */
   7
   8#include <common.h>
   9#include <cpu_func.h>
  10#include <log.h>
  11#include <time.h>
  12#include <vsprintf.h>
  13#include <watchdog.h>
  14#include <command.h>
  15#include <asm/cache.h>
  16#include <asm/mmu.h>
  17#include <mpc86xx.h>
  18#include <asm/fsl_law.h>
  19#include <asm/ppc.h>
  20
  21DECLARE_GLOBAL_DATA_PTR;
  22
  23/*
  24 * Default board reset function
  25 */
  26static void
  27__board_reset(void)
  28{
  29        /* Do nothing */
  30}
  31void board_reset(void) __attribute__((weak, alias("__board_reset")));
  32
  33
  34int
  35checkcpu(void)
  36{
  37        sys_info_t sysinfo;
  38        uint pvr, svr;
  39        uint major, minor;
  40        char buf1[32], buf2[32];
  41        volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR;
  42        volatile ccsr_gur_t *gur = &immap->im_gur;
  43        struct cpu_type *cpu;
  44        uint msscr0 = mfspr(MSSCR0);
  45
  46        svr = get_svr();
  47        major = SVR_MAJ(svr);
  48        minor = SVR_MIN(svr);
  49
  50        if (cpu_numcores() > 1) {
  51#ifndef CONFIG_MP
  52                puts("Unicore software on multiprocessor system!!\n"
  53                     "To enable mutlticore build define CONFIG_MP\n");
  54#endif
  55        }
  56        puts("CPU:   ");
  57
  58        cpu = gd->arch.cpu;
  59
  60        puts(cpu->name);
  61
  62        printf(", Version: %d.%d, (0x%08x)\n", major, minor, svr);
  63        puts("Core:  ");
  64
  65        pvr = get_pvr();
  66        major = PVR_E600_MAJ(pvr);
  67        minor = PVR_E600_MIN(pvr);
  68
  69        printf("e600 Core %d", (msscr0 & 0x20) ? 1 : 0);
  70        if (gur->pordevsr & MPC86xx_PORDEVSR_CORE1TE)
  71                puts("\n    Core1Translation Enabled");
  72        debug(" (MSSCR0=%x, PORDEVSR=%x)", msscr0, gur->pordevsr);
  73
  74        printf(", Version: %d.%d, (0x%08x)\n", major, minor, pvr);
  75
  76        get_sys_info(&sysinfo);
  77
  78        puts("Clock Configuration:\n");
  79        printf("       CPU:%-4s MHz, ", strmhz(buf1, sysinfo.freq_processor));
  80        printf("MPX:%-4s MHz\n", strmhz(buf1, sysinfo.freq_systembus));
  81        printf("       DDR:%-4s MHz (%s MT/s data rate), ",
  82                strmhz(buf1, sysinfo.freq_systembus / 2),
  83                strmhz(buf2, sysinfo.freq_systembus));
  84
  85        if (sysinfo.freq_localbus > LCRR_CLKDIV) {
  86                printf("LBC:%-4s MHz\n", strmhz(buf1, sysinfo.freq_localbus));
  87        } else {
  88                printf("LBC: unknown (LCRR[CLKDIV] = 0x%02lx)\n",
  89                       sysinfo.freq_localbus);
  90        }
  91
  92        puts("L1:    D-cache 32 KiB enabled\n");
  93        puts("       I-cache 32 KiB enabled\n");
  94
  95        puts("L2:    ");
  96        if (get_l2cr() & 0x80000000) {
  97#if defined(CONFIG_ARCH_MPC8610)
  98                puts("256");
  99#elif defined(CONFIG_ARCH_MPC8641)
 100                puts("512");
 101#endif
 102                puts(" KiB enabled\n");
 103        } else {
 104                puts("Disabled\n");
 105        }
 106
 107        return 0;
 108}
 109
 110
 111int do_reset(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
 112{
 113        volatile immap_t *immap = (immap_t *)CONFIG_SYS_IMMR;
 114        volatile ccsr_gur_t *gur = &immap->im_gur;
 115
 116        /* Attempt board-specific reset */
 117        board_reset();
 118
 119        /* Next try asserting HRESET_REQ */
 120        out_be32(&gur->rstcr, MPC86xx_RSTCR_HRST_REQ);
 121
 122        while (1)
 123                ;
 124
 125        return 1;
 126}
 127
 128
 129/*
 130 * Get timebase clock frequency
 131 */
 132unsigned long
 133get_tbclk(void)
 134{
 135        sys_info_t sys_info;
 136
 137        get_sys_info(&sys_info);
 138        return (sys_info.freq_systembus + 3L) / 4L;
 139}
 140
 141
 142#if defined(CONFIG_WATCHDOG)
 143void
 144watchdog_reset(void)
 145{
 146#if defined(CONFIG_ARCH_MPC8610)
 147        /*
 148         * This actually feed the hard enabled watchdog.
 149         */
 150        volatile immap_t *immap = (immap_t *)CONFIG_SYS_IMMR;
 151        volatile ccsr_wdt_t *wdt = &immap->im_wdt;
 152        volatile ccsr_gur_t *gur = &immap->im_gur;
 153        u32 tmp = gur->pordevsr;
 154
 155        if (tmp & 0x4000) {
 156                wdt->swsrr = 0x556c;
 157                wdt->swsrr = 0xaa39;
 158        }
 159#endif
 160}
 161#endif  /* CONFIG_WATCHDOG */
 162
 163/*
 164 * Print out the state of various machine registers.
 165 * Currently prints out LAWs, BR0/OR0, and BATs
 166 */
 167void print_reginfo(void)
 168{
 169        print_bats();
 170        print_laws();
 171        print_lbc_regs();
 172}
 173
 174/*
 175 * Set the DDR BATs to reflect the actual size of DDR.
 176 *
 177 * dram_size is the actual size of DDR, in bytes
 178 *
 179 * Note: we assume that CONFIG_MAX_MEM_MAPPED is 2G or smaller as we only
 180 * are using a single BAT to cover DDR.
 181 *
 182 * If this is not true, (e.g. CONFIG_MAX_MEM_MAPPED is 2GB but HID0_XBSEN
 183 * is not defined) then we might have a situation where U-Boot will attempt
 184 * to relocated itself outside of the region mapped by DBAT0.
 185 * This will cause a machine check.
 186 *
 187 * Currently we are limited to power of two sized DDR since we only use a
 188 * single bat.  If a non-power of two size is used that is less than
 189 * CONFIG_MAX_MEM_MAPPED u-boot will crash.
 190 *
 191 */
 192void setup_ddr_bat(phys_addr_t dram_size)
 193{
 194        unsigned long batu, bl;
 195
 196        bl = TO_BATU_BL(min(dram_size, CONFIG_MAX_MEM_MAPPED));
 197
 198        if (BATU_SIZE(bl) != dram_size) {
 199                u64 sz = (u64)dram_size - BATU_SIZE(bl);
 200                print_size(sz, " left unmapped\n");
 201        }
 202
 203        batu = bl | BATU_VS | BATU_VP;
 204        write_bat(DBAT0, batu, CONFIG_SYS_DBAT0L);
 205        write_bat(IBAT0, batu, CONFIG_SYS_IBAT0L);
 206}
 207