powerpc: remove 4xx support
[platform/kernel/u-boot.git] / common / board_f.c
index 1bdc744..2cdd12a 100644 (file)
  */
 
 #include <common.h>
-#include <linux/compiler.h>
-#include <version.h>
 #include <console.h>
 #include <environment.h>
 #include <dm.h>
 #include <fdtdec.h>
 #include <fs.h>
-#if defined(CONFIG_CMD_IDE)
-#include <ide.h>
-#endif
 #include <i2c.h>
 #include <initcall.h>
+#include <init_helpers.h>
 #include <logbuff.h>
 #include <malloc.h>
 #include <mapmem.h>
-
-/* TODO: Can we move these into arch/ headers? */
-#ifdef CONFIG_8xx
-#include <mpc8xx.h>
-#endif
-#ifdef CONFIG_5xx
-#include <mpc5xx.h>
-#endif
-#ifdef CONFIG_MPC5xxx
-#include <mpc5xxx.h>
-#endif
-#if defined(CONFIG_MP) && (defined(CONFIG_MPC86xx) || defined(CONFIG_E500))
-#include <asm/mp.h>
-#endif
-
 #include <os.h>
 #include <post.h>
+#include <relocate.h>
 #include <spi.h>
 #include <status_led.h>
 #include <timer.h>
 #include <trace.h>
 #include <video.h>
 #include <watchdog.h>
-#include <linux/errno.h>
-#include <asm/io.h>
-#include <asm/sections.h>
-#if defined(CONFIG_X86) || defined(CONFIG_ARC)
-#include <asm/init_helpers.h>
+#ifdef CONFIG_MACH_TYPE
+#include <asm/mach-types.h>
 #endif
-#if defined(CONFIG_X86) || defined(CONFIG_ARC) || defined(CONFIG_XTENSA)
-#include <asm/relocate.h>
+#if defined(CONFIG_MP) && defined(CONFIG_PPC)
+#include <asm/mp.h>
 #endif
+#include <asm/io.h>
+#include <asm/sections.h>
 #include <dm/root.h>
-#include <linux/compiler.h>
+#include <linux/errno.h>
 
 /*
  * Pointer to initial global data area
@@ -159,11 +140,6 @@ static int display_text_info(void)
                text_base, bss_start, bss_end);
 #endif
 
-#ifdef CONFIG_USE_IRQ
-       debug("IRQ Stack: %08lx\n", IRQ_STACK_START);
-       debug("FIQ Stack: %08lx\n", FIQ_STACK_START);
-#endif
-
        return 0;
 }
 
@@ -173,13 +149,6 @@ static int announce_dram_init(void)
        return 0;
 }
 
-#if defined(CONFIG_MIPS) || defined(CONFIG_PPC) || defined(CONFIG_M68K)
-static int init_func_ram(void)
-{
-       return initdram();
-}
-#endif
-
 static int show_dram_config(void)
 {
        unsigned long long size;
@@ -218,7 +187,7 @@ __weak int dram_init_banksize(void)
        return 0;
 }
 
-#if defined(CONFIG_HARD_I2C) || defined(CONFIG_SYS_I2C)
+#if defined(CONFIG_SYS_I2C)
 static int init_func_i2c(void)
 {
        puts("I2C:   ");
@@ -418,7 +387,7 @@ static int reserve_video(void)
        gd->fb_base = gd->relocaddr;
 #  endif /* CONFIG_FB_ADDR */
 #elif defined(CONFIG_VIDEO) && \
-               (!defined(CONFIG_PPC) || defined(CONFIG_8xx)) && \
+               (!defined(CONFIG_PPC)) && \
                !defined(CONFIG_ARM) && !defined(CONFIG_X86) && \
                !defined(CONFIG_M68K)
        /* reserve memory for video display (always full pages) */
@@ -522,6 +491,20 @@ static int reserve_fdt(void)
        return 0;
 }
 
+static int reserve_bootstage(void)
+{
+#ifdef CONFIG_BOOTSTAGE
+       int size = bootstage_get_size();
+
+       gd->start_addr_sp -= size;
+       gd->new_bootstage = map_sysmem(gd->start_addr_sp, size);
+       debug("Reserving %#x Bytes for bootstage at: %08lx\n", size,
+             gd->start_addr_sp);
+#endif
+
+       return 0;
+}
+
 int arch_reserve_stacks(void)
 {
        return 0;
@@ -564,11 +547,10 @@ static int setup_board_part1(void)
        bd->bi_sramsize = CONFIG_SYS_SRAM_SIZE;         /* size  of SRAM */
 #endif
 
-#if defined(CONFIG_8xx) || defined(CONFIG_MPC8260) || defined(CONFIG_5xx) || \
-               defined(CONFIG_E500) || defined(CONFIG_MPC86xx)
+#if defined(CONFIG_E500) || defined(CONFIG_MPC86xx)
        bd->bi_immr_base = CONFIG_SYS_IMMR;     /* base  of IMMR register     */
 #endif
-#if defined(CONFIG_MPC5xxx) || defined(CONFIG_M68K)
+#if defined(CONFIG_M68K)
        bd->bi_mbar_base = CONFIG_SYS_MBAR;     /* base of internal registers */
 #endif
 #if defined(CONFIG_MPC83xx)
@@ -592,13 +574,6 @@ static int setup_board_part2(void)
        bd->bi_sccfreq = gd->arch.scc_clk;
        bd->bi_vco = gd->arch.vco_out;
 #endif /* CONFIG_CPM2 */
-#if defined(CONFIG_MPC512X)
-       bd->bi_ipsfreq = gd->arch.ips_clk;
-#endif /* CONFIG_MPC512X */
-#if defined(CONFIG_MPC5xxx)
-       bd->bi_ipbfreq = gd->arch.ipb_clk;
-       bd->bi_pcifreq = gd->pci_clk;
-#endif /* CONFIG_MPC5xxx */
 #if defined(CONFIG_M68K) && defined(CONFIG_PCI)
        bd->bi_pcifreq = gd->pci_clk;
 #endif
@@ -612,30 +587,6 @@ static int setup_board_part2(void)
 }
 #endif
 
-#ifdef CONFIG_SYS_EXTBDINFO
-static int setup_board_extra(void)
-{
-       bd_t *bd = gd->bd;
-
-       strncpy((char *) bd->bi_s_version, "1.2", sizeof(bd->bi_s_version));
-       strncpy((char *) bd->bi_r_version, U_BOOT_VERSION,
-               sizeof(bd->bi_r_version));
-
-       bd->bi_procfreq = gd->cpu_clk;  /* Processor Speed, In Hz */
-       bd->bi_plb_busfreq = gd->bus_clk;
-#if defined(CONFIG_405GP) || defined(CONFIG_405EP) || \
-               defined(CONFIG_440EP) || defined(CONFIG_440GR) || \
-               defined(CONFIG_440EPX) || defined(CONFIG_440GRX)
-       bd->bi_pci_busfreq = get_PCI_freq();
-       bd->bi_opbfreq = get_OPB_freq();
-#elif defined(CONFIG_XILINX_405)
-       bd->bi_pci_busfreq = get_PCI_freq();
-#endif
-
-       return 0;
-}
-#endif
-
 #ifdef CONFIG_POST
 static int init_post(void)
 {
@@ -660,6 +611,24 @@ static int reloc_fdt(void)
        return 0;
 }
 
+static int reloc_bootstage(void)
+{
+#ifdef CONFIG_BOOTSTAGE
+       if (gd->flags & GD_FLG_SKIP_RELOC)
+               return 0;
+       if (gd->new_bootstage) {
+               int size = bootstage_get_size();
+
+               debug("Copying bootstage from %p to %p, size %x\n",
+                     gd->bootstage, gd->new_bootstage, size);
+               memcpy(gd->new_bootstage, gd->bootstage, size);
+               gd->bootstage = gd->new_bootstage;
+       }
+#endif
+
+       return 0;
+}
+
 static int setup_reloc(void)
 {
        if (gd->flags & GD_FLG_SKIP_RELOC) {
@@ -668,13 +637,16 @@ static int setup_reloc(void)
        }
 
 #ifdef CONFIG_SYS_TEXT_BASE
-       gd->reloc_off = gd->relocaddr - CONFIG_SYS_TEXT_BASE;
-#ifdef CONFIG_M68K
+#ifdef ARM
+       gd->reloc_off = gd->relocaddr - (unsigned long)__image_copy_start;
+#elif defined(CONFIG_M68K)
        /*
         * On all ColdFire arch cpu, monitor code starts always
         * just after the default vector table location, so at 0x400
         */
        gd->reloc_off = gd->relocaddr - (CONFIG_SYS_TEXT_BASE + 0x400);
+#else
+       gd->reloc_off = gd->relocaddr - CONFIG_SYS_TEXT_BASE;
 #endif
 #endif
        memcpy(gd->new_gd, (char *)gd, sizeof(gd_t));
@@ -728,8 +700,26 @@ static int jump_to_copy(void)
 #endif
 
 /* Record the board_init_f() bootstage (after arch_cpu_init()) */
-static int mark_bootstage(void)
+static int initf_bootstage(void)
 {
+       bool from_spl = IS_ENABLED(CONFIG_SPL_BOOTSTAGE) &&
+                       IS_ENABLED(CONFIG_BOOTSTAGE_STASH);
+       int ret;
+
+       ret = bootstage_init(!from_spl);
+       if (ret)
+               return ret;
+       if (from_spl) {
+               const void *stash = map_sysmem(CONFIG_BOOTSTAGE_STASH_ADDR,
+                                              CONFIG_BOOTSTAGE_STASH_SIZE);
+
+               ret = bootstage_unstash(stash, CONFIG_BOOTSTAGE_STASH_SIZE);
+               if (ret && ret != -ENOENT) {
+                       debug("Failed to unstash bootstage: err=%d\n", ret);
+                       return ret;
+               }
+       }
+
        bootstage_mark_name(BOOTSTAGE_ID_START_UBOOT_F, "board_init_f");
 
        return 0;
@@ -749,7 +739,9 @@ static int initf_dm(void)
 #if defined(CONFIG_DM) && defined(CONFIG_SYS_MALLOC_F_LEN)
        int ret;
 
+       bootstage_start(BOOTSTATE_ID_ACCUM_DM_F, "dm_f");
        ret = dm_init_and_scan(true);
+       bootstage_accum(BOOTSTATE_ID_ACCUM_DM_F);
        if (ret)
                return ret;
 #endif
@@ -782,6 +774,7 @@ static const init_fnc_t init_sequence_f[] = {
        trace_early_init,
 #endif
        initf_malloc,
+       initf_bootstage,        /* uses its own timer, so does not need DM */
        initf_console_record,
 #if defined(CONFIG_HAVE_FSP)
        arch_fsp_init,
@@ -790,7 +783,6 @@ static const init_fnc_t init_sequence_f[] = {
        mach_cpu_init,          /* SoC/machine dependent CPU setup */
        initf_dm,
        arch_cpu_init_dm,
-       mark_bootstage,         /* need timer, go after init dm */
 #if defined(CONFIG_BOARD_EARLY_INIT_F)
        board_early_init_f,
 #endif
@@ -798,7 +790,9 @@ static const init_fnc_t init_sequence_f[] = {
        /* get CPU and bus clocks according to the environment variable */
        get_clocks,             /* get CPU and bus clocks (etc.) */
 #endif
+#if !defined(CONFIG_M68K)
        timer_init,             /* initialize timer */
+#endif
 #if defined(CONFIG_BOARD_POSTCLK_INIT)
        board_postclk_init,
 #endif
@@ -823,22 +817,14 @@ static const init_fnc_t init_sequence_f[] = {
        misc_init_f,
 #endif
        INIT_FUNC_WATCHDOG_RESET
-#if defined(CONFIG_HARD_I2C) || defined(CONFIG_SYS_I2C)
+#if defined(CONFIG_SYS_I2C)
        init_func_i2c,
 #endif
 #if defined(CONFIG_HARD_SPI)
        init_func_spi,
 #endif
        announce_dram_init,
-       /* TODO: unify all these dram functions? */
-#if defined(CONFIG_ARM) || defined(CONFIG_X86) || defined(CONFIG_NDS32) || \
-               defined(CONFIG_MICROBLAZE) || defined(CONFIG_AVR32) || \
-               defined(CONFIG_SH)
        dram_init,              /* configure available RAM banks */
-#endif
-#if defined(CONFIG_MIPS) || defined(CONFIG_PPC) || defined(CONFIG_M68K)
-       init_func_ram,
-#endif
 #ifdef CONFIG_POST
        post_init_f,
 #endif
@@ -883,6 +869,7 @@ static const init_fnc_t init_sequence_f[] = {
        setup_machine,
        reserve_global_data,
        reserve_fdt,
+       reserve_bootstage,
        reserve_arch,
        reserve_stacks,
        dram_init_banksize,
@@ -896,14 +883,12 @@ static const init_fnc_t init_sequence_f[] = {
        setup_board_part2,
 #endif
        display_new_sp,
-#ifdef CONFIG_SYS_EXTBDINFO
-       setup_board_extra,
-#endif
 #ifdef CONFIG_OF_BOARD_FIXUP
        fix_fdt,
 #endif
        INIT_FUNC_WATCHDOG_RESET
        reloc_fdt,
+       reloc_bootstage,
        setup_reloc,
 #if defined(CONFIG_X86) || defined(CONFIG_ARC)
        copy_uboot_to_ram,