2 * Copyright (C) 2012 Samsung Electronics
4 * See file CREDITS for list of people who contributed to this
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License as
9 * published by the Free Software Foundation; either version 2 of
10 * the License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
26 #include <asm/arch/clock.h>
27 #include <asm/arch/clk.h>
28 #include <asm/arch/dmc.h>
29 #include <asm/arch/power.h>
30 #include <asm/arch/spl.h>
32 #include "common_setup.h"
33 #include "clock_init.h"
35 DECLARE_GLOBAL_DATA_PTR;
36 #define OM_STAT (0x1f << 1)
38 /* Index into irom ptr table */
47 /* IROM Function Pointers Table */
48 u32 irom_ptr_table[] = {
49 [MMC_INDEX] = 0x02020030, /* iROM Function Pointer-SDMMC boot */
50 [EMMC44_INDEX] = 0x02020044, /* iROM Function Pointer-EMMC4.4 boot*/
51 [EMMC44_END_INDEX] = 0x02020048,/* iROM Function Pointer
52 -EMMC4.4 end boot operation */
53 [SPI_INDEX] = 0x02020058, /* iROM Function Pointer-SPI boot */
54 [USB_INDEX] = 0x02020070, /* iROM Function Pointer-USB boot*/
57 void *get_irom_func(int index)
59 return (void *)*(u32 *)irom_ptr_table[index];
62 #ifdef CONFIG_USB_BOOTING
64 * Set/clear program flow prediction and return the previous state.
66 static int config_branch_prediction(int set_cr_z)
70 /* System Control Register: 11th bit Z Branch prediction enable */
72 set_cr(set_cr_z ? cr | CR_Z : cr & ~CR_Z);
79 * Copy U-boot from mmc to RAM:
80 * COPY_BL2_FNPTR_ADDR: Address in iRAM, which Contains
81 * Pointer to API (Data transfer from mmc to ram)
83 void copy_uboot_to_ram(void)
85 enum boot_mode bootmode = BOOT_MODE_OM;
87 u32 (*copy_bl2)(u32 offset, u32 nblock, u32 dst) = NULL;
88 u32 offset = 0, size = 0;
89 #ifdef CONFIG_SUPPORT_EMMC_BOOT
90 u32 (*copy_bl2_from_emmc)(u32 nblock, u32 dst);
91 void (*end_bootop_from_emmc)(void);
93 #ifdef CONFIG_USB_BOOTING
94 u32 (*usb_copy)(void);
96 unsigned int sec_boot_check;
98 /* Read iRAM location to check for secondary USB boot mode */
99 sec_boot_check = readl(EXYNOS_IRAM_SECONDARY_BASE);
100 if (sec_boot_check == EXYNOS_USB_SECONDARY_BOOT)
101 bootmode = BOOT_MODE_USB;
104 if (bootmode == BOOT_MODE_OM)
105 bootmode = readl(samsung_get_base_power()) & OM_STAT;
108 #ifdef CONFIG_SPI_BOOTING
109 case BOOT_MODE_SERIAL:
110 offset = SPI_FLASH_UBOOT_POS;
111 size = CONFIG_BL2_SIZE;
112 copy_bl2 = get_irom_func(SPI_INDEX);
116 offset = BL2_START_OFFSET;
117 size = BL2_SIZE_BLOC_COUNT;
118 copy_bl2 = get_irom_func(MMC_INDEX);
120 #ifdef CONFIG_SUPPORT_EMMC_BOOT
122 /* Set the FSYS1 clock divisor value for EMMC boot */
123 emmc_boot_clk_div_set();
125 copy_bl2_from_emmc = get_irom_func(EMMC44_INDEX);
126 end_bootop_from_emmc = get_irom_func(EMMC44_END_INDEX);
128 copy_bl2_from_emmc(BL2_SIZE_BLOC_COUNT, CONFIG_SYS_TEXT_BASE);
129 end_bootop_from_emmc();
132 #ifdef CONFIG_USB_BOOTING
135 * iROM needs program flow prediction to be disabled
136 * before copy from USB device to RAM
138 is_cr_z_set = config_branch_prediction(0);
139 usb_copy = get_irom_func(USB_INDEX);
141 config_branch_prediction(is_cr_z_set);
149 copy_bl2(offset, size, CONFIG_SYS_TEXT_BASE);
152 void memzero(void *s, size_t n)
157 for (i = 0; i < n; i++)
162 * Set up the U-Boot global_data pointer
164 * This sets the address of the global data, and sets up basic values.
166 * @param gdp Value to give to gd
168 static void setup_global_data(gd_t *gdp)
171 memzero((void *)gd, sizeof(gd_t));
172 gd->flags |= GD_FLG_RELOC;
173 gd->baudrate = CONFIG_BAUDRATE;
174 gd->have_console = 1;
177 void board_init_f(unsigned long bootflag)
179 __aligned(8) gd_t local_gd;
180 __attribute__((noreturn)) void (*uboot)(void);
182 setup_global_data(&local_gd);
184 if (do_lowlevel_init())
189 /* Jump to U-Boot image */
190 uboot = (void *)CONFIG_SYS_TEXT_BASE;
192 /* Never returns Here */
196 void board_init_r(gd_t *id, ulong dest_addr)
198 /* Function attribute is no-return */
199 /* This Function never executes */
203 void save_boot_params(u32 r0, u32 r1, u32 r2, u32 r3) {}