Chander Kashyap | 1633dd1 | 2012-02-05 23:01:48 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2012 Samsung Electronics |
| 3 | * |
| 4 | * See file CREDITS for list of people who contributed to this |
| 5 | * project. |
| 6 | * |
| 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. |
| 11 | * |
| 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. |
| 16 | * |
| 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, |
| 20 | * MA 02111-1307 USA |
| 21 | */ |
| 22 | |
| 23 | #include<common.h> |
| 24 | #include<config.h> |
| 25 | |
Amar | e33add8 | 2013-04-27 11:42:59 +0530 | [diff] [blame] | 26 | #include <asm/arch-exynos/dmc.h> |
| 27 | #include <asm/arch/clock.h> |
| 28 | #include <asm/arch/clk.h> |
Rajeshwari Shinde | bff6d0a | 2013-06-25 19:17:06 +0530 | [diff] [blame^] | 29 | #include <asm/arch/spl.h> |
Amar | e33add8 | 2013-04-27 11:42:59 +0530 | [diff] [blame] | 30 | |
| 31 | #include "clock_init.h" |
| 32 | |
| 33 | /* Index into irom ptr table */ |
| 34 | enum index { |
| 35 | MMC_INDEX, |
| 36 | EMMC44_INDEX, |
| 37 | EMMC44_END_INDEX, |
| 38 | SPI_INDEX, |
| 39 | USB_INDEX, |
| 40 | }; |
| 41 | |
| 42 | /* IROM Function Pointers Table */ |
| 43 | u32 irom_ptr_table[] = { |
| 44 | [MMC_INDEX] = 0x02020030, /* iROM Function Pointer-SDMMC boot */ |
| 45 | [EMMC44_INDEX] = 0x02020044, /* iROM Function Pointer-EMMC4.4 boot*/ |
| 46 | [EMMC44_END_INDEX] = 0x02020048,/* iROM Function Pointer |
| 47 | -EMMC4.4 end boot operation */ |
| 48 | [SPI_INDEX] = 0x02020058, /* iROM Function Pointer-SPI boot */ |
| 49 | [USB_INDEX] = 0x02020070, /* iROM Function Pointer-USB boot*/ |
| 50 | }; |
| 51 | |
Amar | e33add8 | 2013-04-27 11:42:59 +0530 | [diff] [blame] | 52 | void *get_irom_func(int index) |
| 53 | { |
| 54 | return (void *)*(u32 *)irom_ptr_table[index]; |
| 55 | } |
Rajeshwari Shinde | 9cb48e8 | 2012-11-02 01:15:38 +0000 | [diff] [blame] | 56 | |
Chander Kashyap | 1633dd1 | 2012-02-05 23:01:48 +0000 | [diff] [blame] | 57 | /* |
Vivek Gautam | 681dd83 | 2013-01-28 00:39:59 +0000 | [diff] [blame] | 58 | * Set/clear program flow prediction and return the previous state. |
| 59 | */ |
| 60 | static int config_branch_prediction(int set_cr_z) |
| 61 | { |
| 62 | unsigned int cr; |
| 63 | |
| 64 | /* System Control Register: 11th bit Z Branch prediction enable */ |
| 65 | cr = get_cr(); |
| 66 | set_cr(set_cr_z ? cr | CR_Z : cr & ~CR_Z); |
| 67 | |
| 68 | return cr & CR_Z; |
| 69 | } |
| 70 | |
| 71 | /* |
Chander Kashyap | 1633dd1 | 2012-02-05 23:01:48 +0000 | [diff] [blame] | 72 | * Copy U-boot from mmc to RAM: |
| 73 | * COPY_BL2_FNPTR_ADDR: Address in iRAM, which Contains |
| 74 | * Pointer to API (Data transfer from mmc to ram) |
| 75 | */ |
| 76 | void copy_uboot_to_ram(void) |
| 77 | { |
Vivek Gautam | 681dd83 | 2013-01-28 00:39:59 +0000 | [diff] [blame] | 78 | int is_cr_z_set; |
| 79 | unsigned int sec_boot_check; |
| 80 | enum boot_mode bootmode = BOOT_MODE_OM; |
Amar | e33add8 | 2013-04-27 11:42:59 +0530 | [diff] [blame] | 81 | |
| 82 | u32 (*spi_copy)(u32 offset, u32 nblock, u32 dst); |
| 83 | u32 (*copy_bl2)(u32 offset, u32 nblock, u32 dst); |
| 84 | u32 (*copy_bl2_from_emmc)(u32 nblock, u32 dst); |
| 85 | void (*end_bootop_from_emmc)(void); |
| 86 | u32 (*usb_copy)(void); |
Rajeshwari Shinde | 9cb48e8 | 2012-11-02 01:15:38 +0000 | [diff] [blame] | 87 | |
Vivek Gautam | 681dd83 | 2013-01-28 00:39:59 +0000 | [diff] [blame] | 88 | /* Read iRAM location to check for secondary USB boot mode */ |
| 89 | sec_boot_check = readl(EXYNOS_IRAM_SECONDARY_BASE); |
| 90 | if (sec_boot_check == EXYNOS_USB_SECONDARY_BOOT) |
| 91 | bootmode = BOOT_MODE_USB; |
| 92 | |
| 93 | if (bootmode == BOOT_MODE_OM) |
| 94 | bootmode = readl(EXYNOS5_POWER_BASE) & OM_STAT; |
Chander Kashyap | 1633dd1 | 2012-02-05 23:01:48 +0000 | [diff] [blame] | 95 | |
Rajeshwari Shinde | 9cb48e8 | 2012-11-02 01:15:38 +0000 | [diff] [blame] | 96 | switch (bootmode) { |
| 97 | case BOOT_MODE_SERIAL: |
Amar | e33add8 | 2013-04-27 11:42:59 +0530 | [diff] [blame] | 98 | spi_copy = get_irom_func(SPI_INDEX); |
Rajeshwari Shinde | 9cb48e8 | 2012-11-02 01:15:38 +0000 | [diff] [blame] | 99 | spi_copy(SPI_FLASH_UBOOT_POS, CONFIG_BL2_SIZE, |
Amar | e33add8 | 2013-04-27 11:42:59 +0530 | [diff] [blame] | 100 | CONFIG_SYS_TEXT_BASE); |
Rajeshwari Shinde | 9cb48e8 | 2012-11-02 01:15:38 +0000 | [diff] [blame] | 101 | break; |
| 102 | case BOOT_MODE_MMC: |
Amar | e33add8 | 2013-04-27 11:42:59 +0530 | [diff] [blame] | 103 | copy_bl2 = get_irom_func(MMC_INDEX); |
Rajeshwari Shinde | 9cb48e8 | 2012-11-02 01:15:38 +0000 | [diff] [blame] | 104 | copy_bl2(BL2_START_OFFSET, BL2_SIZE_BLOC_COUNT, |
Amar | e33add8 | 2013-04-27 11:42:59 +0530 | [diff] [blame] | 105 | CONFIG_SYS_TEXT_BASE); |
| 106 | break; |
| 107 | case BOOT_MODE_EMMC: |
| 108 | /* Set the FSYS1 clock divisor value for EMMC boot */ |
| 109 | emmc_boot_clk_div_set(); |
| 110 | |
| 111 | copy_bl2_from_emmc = get_irom_func(EMMC44_INDEX); |
| 112 | end_bootop_from_emmc = get_irom_func(EMMC44_END_INDEX); |
| 113 | |
| 114 | copy_bl2_from_emmc(BL2_SIZE_BLOC_COUNT, CONFIG_SYS_TEXT_BASE); |
| 115 | end_bootop_from_emmc(); |
Rajeshwari Shinde | 9cb48e8 | 2012-11-02 01:15:38 +0000 | [diff] [blame] | 116 | break; |
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 | 9cb48e8 | 2012-11-02 01:15:38 +0000 | [diff] [blame] | 127 | default: |
| 128 | break; |
| 129 | } |
Chander Kashyap | 1633dd1 | 2012-02-05 23:01:48 +0000 | [diff] [blame] | 130 | } |
| 131 | |
| 132 | void board_init_f(unsigned long bootflag) |
| 133 | { |
| 134 | __attribute__((noreturn)) void (*uboot)(void); |
| 135 | copy_uboot_to_ram(); |
| 136 | |
| 137 | /* Jump to U-Boot image */ |
| 138 | uboot = (void *)CONFIG_SYS_TEXT_BASE; |
| 139 | (*uboot)(); |
| 140 | /* Never returns Here */ |
| 141 | } |
| 142 | |
| 143 | /* Place Holders */ |
| 144 | void board_init_r(gd_t *id, ulong dest_addr) |
| 145 | { |
| 146 | /* Function attribute is no-return */ |
| 147 | /* This Function never executes */ |
| 148 | while (1) |
| 149 | ; |
| 150 | } |
Chander Kashyap | 1633dd1 | 2012-02-05 23:01:48 +0000 | [diff] [blame] | 151 | void save_boot_params(u32 r0, u32 r1, u32 r2, u32 r3) {} |