Chander Kashyap | 1633dd1 | 2012-02-05 23:01:48 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2012 Samsung Electronics |
| 3 | * |
Wolfgang Denk | d79de1d | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 4 | * SPDX-License-Identifier: GPL-2.0+ |
Chander Kashyap | 1633dd1 | 2012-02-05 23:01:48 +0000 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #include<common.h> |
| 8 | #include<config.h> |
| 9 | |
Amar | e33add8 | 2013-04-27 11:42:59 +0530 | [diff] [blame] | 10 | #include <asm/arch/clock.h> |
| 11 | #include <asm/arch/clk.h> |
Rajeshwari Shinde | bed2442 | 2013-07-04 12:29:17 +0530 | [diff] [blame] | 12 | #include <asm/arch/dmc.h> |
| 13 | #include <asm/arch/power.h> |
Rajeshwari Shinde | bff6d0a | 2013-06-25 19:17:06 +0530 | [diff] [blame] | 14 | #include <asm/arch/spl.h> |
Amar | e33add8 | 2013-04-27 11:42:59 +0530 | [diff] [blame] | 15 | |
Rajeshwari Shinde | bed2442 | 2013-07-04 12:29:17 +0530 | [diff] [blame] | 16 | #include "common_setup.h" |
Amar | e33add8 | 2013-04-27 11:42:59 +0530 | [diff] [blame] | 17 | #include "clock_init.h" |
| 18 | |
Rajeshwari Shinde | bed2442 | 2013-07-04 12:29:17 +0530 | [diff] [blame] | 19 | DECLARE_GLOBAL_DATA_PTR; |
| 20 | #define OM_STAT (0x1f << 1) |
| 21 | |
Amar | e33add8 | 2013-04-27 11:42:59 +0530 | [diff] [blame] | 22 | /* Index into irom ptr table */ |
| 23 | enum index { |
| 24 | MMC_INDEX, |
| 25 | EMMC44_INDEX, |
| 26 | EMMC44_END_INDEX, |
| 27 | SPI_INDEX, |
| 28 | USB_INDEX, |
| 29 | }; |
| 30 | |
| 31 | /* IROM Function Pointers Table */ |
| 32 | u32 irom_ptr_table[] = { |
| 33 | [MMC_INDEX] = 0x02020030, /* iROM Function Pointer-SDMMC boot */ |
| 34 | [EMMC44_INDEX] = 0x02020044, /* iROM Function Pointer-EMMC4.4 boot*/ |
| 35 | [EMMC44_END_INDEX] = 0x02020048,/* iROM Function Pointer |
| 36 | -EMMC4.4 end boot operation */ |
| 37 | [SPI_INDEX] = 0x02020058, /* iROM Function Pointer-SPI boot */ |
| 38 | [USB_INDEX] = 0x02020070, /* iROM Function Pointer-USB boot*/ |
| 39 | }; |
| 40 | |
Amar | e33add8 | 2013-04-27 11:42:59 +0530 | [diff] [blame] | 41 | void *get_irom_func(int index) |
| 42 | { |
| 43 | return (void *)*(u32 *)irom_ptr_table[index]; |
| 44 | } |
Rajeshwari Shinde | 9cb48e8 | 2012-11-02 01:15:38 +0000 | [diff] [blame] | 45 | |
Rajeshwari Shinde | bed2442 | 2013-07-04 12:29:17 +0530 | [diff] [blame] | 46 | #ifdef CONFIG_USB_BOOTING |
Chander Kashyap | 1633dd1 | 2012-02-05 23:01:48 +0000 | [diff] [blame] | 47 | /* |
Vivek Gautam | 681dd83 | 2013-01-28 00:39:59 +0000 | [diff] [blame] | 48 | * Set/clear program flow prediction and return the previous state. |
| 49 | */ |
| 50 | static int config_branch_prediction(int set_cr_z) |
| 51 | { |
| 52 | unsigned int cr; |
| 53 | |
| 54 | /* System Control Register: 11th bit Z Branch prediction enable */ |
| 55 | cr = get_cr(); |
| 56 | set_cr(set_cr_z ? cr | CR_Z : cr & ~CR_Z); |
| 57 | |
| 58 | return cr & CR_Z; |
| 59 | } |
Rajeshwari Shinde | bed2442 | 2013-07-04 12:29:17 +0530 | [diff] [blame] | 60 | #endif |
Vivek Gautam | 681dd83 | 2013-01-28 00:39:59 +0000 | [diff] [blame] | 61 | |
| 62 | /* |
Chander Kashyap | 1633dd1 | 2012-02-05 23:01:48 +0000 | [diff] [blame] | 63 | * Copy U-boot from mmc to RAM: |
| 64 | * COPY_BL2_FNPTR_ADDR: Address in iRAM, which Contains |
| 65 | * Pointer to API (Data transfer from mmc to ram) |
| 66 | */ |
| 67 | void copy_uboot_to_ram(void) |
| 68 | { |
Vivek Gautam | 681dd83 | 2013-01-28 00:39:59 +0000 | [diff] [blame] | 69 | enum boot_mode bootmode = BOOT_MODE_OM; |
Amar | e33add8 | 2013-04-27 11:42:59 +0530 | [diff] [blame] | 70 | |
Rajeshwari Shinde | bed2442 | 2013-07-04 12:29:17 +0530 | [diff] [blame] | 71 | u32 (*copy_bl2)(u32 offset, u32 nblock, u32 dst) = NULL; |
| 72 | u32 offset = 0, size = 0; |
| 73 | #ifdef CONFIG_SUPPORT_EMMC_BOOT |
Amar | e33add8 | 2013-04-27 11:42:59 +0530 | [diff] [blame] | 74 | u32 (*copy_bl2_from_emmc)(u32 nblock, u32 dst); |
| 75 | void (*end_bootop_from_emmc)(void); |
Rajeshwari Shinde | bed2442 | 2013-07-04 12:29:17 +0530 | [diff] [blame] | 76 | #endif |
| 77 | #ifdef CONFIG_USB_BOOTING |
Amar | e33add8 | 2013-04-27 11:42:59 +0530 | [diff] [blame] | 78 | u32 (*usb_copy)(void); |
Rajeshwari Shinde | bed2442 | 2013-07-04 12:29:17 +0530 | [diff] [blame] | 79 | int is_cr_z_set; |
| 80 | unsigned int sec_boot_check; |
Rajeshwari Shinde | 9cb48e8 | 2012-11-02 01:15:38 +0000 | [diff] [blame] | 81 | |
Vivek Gautam | 681dd83 | 2013-01-28 00:39:59 +0000 | [diff] [blame] | 82 | /* Read iRAM location to check for secondary USB boot mode */ |
| 83 | sec_boot_check = readl(EXYNOS_IRAM_SECONDARY_BASE); |
| 84 | if (sec_boot_check == EXYNOS_USB_SECONDARY_BOOT) |
| 85 | bootmode = BOOT_MODE_USB; |
Rajeshwari Shinde | bed2442 | 2013-07-04 12:29:17 +0530 | [diff] [blame] | 86 | #endif |
Vivek Gautam | 681dd83 | 2013-01-28 00:39:59 +0000 | [diff] [blame] | 87 | |
| 88 | if (bootmode == BOOT_MODE_OM) |
Rajeshwari Shinde | bed2442 | 2013-07-04 12:29:17 +0530 | [diff] [blame] | 89 | bootmode = readl(samsung_get_base_power()) & OM_STAT; |
Chander Kashyap | 1633dd1 | 2012-02-05 23:01:48 +0000 | [diff] [blame] | 90 | |
Rajeshwari Shinde | 9cb48e8 | 2012-11-02 01:15:38 +0000 | [diff] [blame] | 91 | switch (bootmode) { |
Rajeshwari Shinde | bed2442 | 2013-07-04 12:29:17 +0530 | [diff] [blame] | 92 | #ifdef CONFIG_SPI_BOOTING |
Rajeshwari Shinde | 9cb48e8 | 2012-11-02 01:15:38 +0000 | [diff] [blame] | 93 | case BOOT_MODE_SERIAL: |
Rajeshwari Shinde | bed2442 | 2013-07-04 12:29:17 +0530 | [diff] [blame] | 94 | offset = SPI_FLASH_UBOOT_POS; |
| 95 | size = CONFIG_BL2_SIZE; |
| 96 | copy_bl2 = get_irom_func(SPI_INDEX); |
Rajeshwari Shinde | 9cb48e8 | 2012-11-02 01:15:38 +0000 | [diff] [blame] | 97 | break; |
Rajeshwari Shinde | bed2442 | 2013-07-04 12:29:17 +0530 | [diff] [blame] | 98 | #endif |
Rajeshwari Shinde | 9cb48e8 | 2012-11-02 01:15:38 +0000 | [diff] [blame] | 99 | case BOOT_MODE_MMC: |
Rajeshwari Shinde | bed2442 | 2013-07-04 12:29:17 +0530 | [diff] [blame] | 100 | offset = BL2_START_OFFSET; |
| 101 | size = BL2_SIZE_BLOC_COUNT; |
Amar | e33add8 | 2013-04-27 11:42:59 +0530 | [diff] [blame] | 102 | copy_bl2 = get_irom_func(MMC_INDEX); |
Amar | e33add8 | 2013-04-27 11:42:59 +0530 | [diff] [blame] | 103 | break; |
Rajeshwari Shinde | bed2442 | 2013-07-04 12:29:17 +0530 | [diff] [blame] | 104 | #ifdef CONFIG_SUPPORT_EMMC_BOOT |
Amar | e33add8 | 2013-04-27 11:42:59 +0530 | [diff] [blame] | 105 | case BOOT_MODE_EMMC: |
| 106 | /* Set the FSYS1 clock divisor value for EMMC boot */ |
| 107 | emmc_boot_clk_div_set(); |
| 108 | |
| 109 | copy_bl2_from_emmc = get_irom_func(EMMC44_INDEX); |
| 110 | end_bootop_from_emmc = get_irom_func(EMMC44_END_INDEX); |
| 111 | |
| 112 | copy_bl2_from_emmc(BL2_SIZE_BLOC_COUNT, CONFIG_SYS_TEXT_BASE); |
| 113 | end_bootop_from_emmc(); |
Rajeshwari Shinde | 9cb48e8 | 2012-11-02 01:15:38 +0000 | [diff] [blame] | 114 | break; |
Rajeshwari Shinde | bed2442 | 2013-07-04 12:29:17 +0530 | [diff] [blame] | 115 | #endif |
| 116 | #ifdef CONFIG_USB_BOOTING |
Vivek Gautam | 681dd83 | 2013-01-28 00:39:59 +0000 | [diff] [blame] | 117 | case BOOT_MODE_USB: |
| 118 | /* |
| 119 | * iROM needs program flow prediction to be disabled |
| 120 | * before copy from USB device to RAM |
| 121 | */ |
| 122 | is_cr_z_set = config_branch_prediction(0); |
Amar | e33add8 | 2013-04-27 11:42:59 +0530 | [diff] [blame] | 123 | usb_copy = get_irom_func(USB_INDEX); |
Vivek Gautam | 681dd83 | 2013-01-28 00:39:59 +0000 | [diff] [blame] | 124 | usb_copy(); |
| 125 | config_branch_prediction(is_cr_z_set); |
| 126 | break; |
Rajeshwari Shinde | bed2442 | 2013-07-04 12:29:17 +0530 | [diff] [blame] | 127 | #endif |
Rajeshwari Shinde | 9cb48e8 | 2012-11-02 01:15:38 +0000 | [diff] [blame] | 128 | default: |
| 129 | break; |
| 130 | } |
Rajeshwari Shinde | bed2442 | 2013-07-04 12:29:17 +0530 | [diff] [blame] | 131 | |
| 132 | if (copy_bl2) |
| 133 | copy_bl2(offset, size, CONFIG_SYS_TEXT_BASE); |
Chander Kashyap | 1633dd1 | 2012-02-05 23:01:48 +0000 | [diff] [blame] | 134 | } |
| 135 | |
Rajeshwari Shinde | bed2442 | 2013-07-04 12:29:17 +0530 | [diff] [blame] | 136 | void memzero(void *s, size_t n) |
| 137 | { |
| 138 | char *ptr = s; |
| 139 | size_t i; |
| 140 | |
| 141 | for (i = 0; i < n; i++) |
| 142 | *ptr++ = '\0'; |
| 143 | } |
| 144 | |
| 145 | /** |
| 146 | * Set up the U-Boot global_data pointer |
| 147 | * |
| 148 | * This sets the address of the global data, and sets up basic values. |
| 149 | * |
| 150 | * @param gdp Value to give to gd |
| 151 | */ |
| 152 | static void setup_global_data(gd_t *gdp) |
| 153 | { |
| 154 | gd = gdp; |
| 155 | memzero((void *)gd, sizeof(gd_t)); |
| 156 | gd->flags |= GD_FLG_RELOC; |
| 157 | gd->baudrate = CONFIG_BAUDRATE; |
| 158 | gd->have_console = 1; |
| 159 | } |
| 160 | |
Chander Kashyap | 1633dd1 | 2012-02-05 23:01:48 +0000 | [diff] [blame] | 161 | void board_init_f(unsigned long bootflag) |
| 162 | { |
Rajeshwari Shinde | bed2442 | 2013-07-04 12:29:17 +0530 | [diff] [blame] | 163 | __aligned(8) gd_t local_gd; |
Chander Kashyap | 1633dd1 | 2012-02-05 23:01:48 +0000 | [diff] [blame] | 164 | __attribute__((noreturn)) void (*uboot)(void); |
Rajeshwari Shinde | bed2442 | 2013-07-04 12:29:17 +0530 | [diff] [blame] | 165 | |
| 166 | setup_global_data(&local_gd); |
| 167 | |
| 168 | if (do_lowlevel_init()) |
| 169 | power_exit_wakeup(); |
| 170 | |
Chander Kashyap | 1633dd1 | 2012-02-05 23:01:48 +0000 | [diff] [blame] | 171 | copy_uboot_to_ram(); |
| 172 | |
| 173 | /* Jump to U-Boot image */ |
| 174 | uboot = (void *)CONFIG_SYS_TEXT_BASE; |
| 175 | (*uboot)(); |
| 176 | /* Never returns Here */ |
| 177 | } |
| 178 | |
| 179 | /* Place Holders */ |
| 180 | void board_init_r(gd_t *id, ulong dest_addr) |
| 181 | { |
| 182 | /* Function attribute is no-return */ |
| 183 | /* This Function never executes */ |
| 184 | while (1) |
| 185 | ; |
| 186 | } |
Chander Kashyap | 1633dd1 | 2012-02-05 23:01:48 +0000 | [diff] [blame] | 187 | void save_boot_params(u32 r0, u32 r1, u32 r2, u32 r3) {} |