Chander Kashyap | 81e3520 | 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 | c748be0 | 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> |
| 29 | |
| 30 | #include "clock_init.h" |
| 31 | |
| 32 | /* Index into irom ptr table */ |
| 33 | enum index { |
| 34 | MMC_INDEX, |
| 35 | EMMC44_INDEX, |
| 36 | EMMC44_END_INDEX, |
| 37 | SPI_INDEX, |
| 38 | USB_INDEX, |
| 39 | }; |
| 40 | |
| 41 | /* IROM Function Pointers Table */ |
| 42 | u32 irom_ptr_table[] = { |
| 43 | [MMC_INDEX] = 0x02020030, /* iROM Function Pointer-SDMMC boot */ |
| 44 | [EMMC44_INDEX] = 0x02020044, /* iROM Function Pointer-EMMC4.4 boot*/ |
| 45 | [EMMC44_END_INDEX] = 0x02020048,/* iROM Function Pointer |
| 46 | -EMMC4.4 end boot operation */ |
| 47 | [SPI_INDEX] = 0x02020058, /* iROM Function Pointer-SPI boot */ |
| 48 | [USB_INDEX] = 0x02020070, /* iROM Function Pointer-USB boot*/ |
| 49 | }; |
| 50 | |
Rajeshwari Shinde | 7a53377 | 2012-11-02 01:15:38 +0000 | [diff] [blame] | 51 | enum boot_mode { |
| 52 | BOOT_MODE_MMC = 4, |
| 53 | BOOT_MODE_SERIAL = 20, |
Amar | c748be0 | 2013-04-27 11:42:59 +0530 | [diff] [blame] | 54 | BOOT_MODE_EMMC = 8, /* EMMC4.4 */ |
Rajeshwari Shinde | 7a53377 | 2012-11-02 01:15:38 +0000 | [diff] [blame] | 55 | /* Boot based on Operating Mode pin settings */ |
| 56 | BOOT_MODE_OM = 32, |
| 57 | BOOT_MODE_USB, /* Boot using USB download */ |
| 58 | }; |
| 59 | |
Amar | c748be0 | 2013-04-27 11:42:59 +0530 | [diff] [blame] | 60 | void *get_irom_func(int index) |
| 61 | { |
| 62 | return (void *)*(u32 *)irom_ptr_table[index]; |
| 63 | } |
Vivek Gautam | 70656c7 | 2013-01-28 00:39:59 +0000 | [diff] [blame] | 64 | |
| 65 | /* |
| 66 | * Set/clear program flow prediction and return the previous state. |
| 67 | */ |
| 68 | static int config_branch_prediction(int set_cr_z) |
| 69 | { |
| 70 | unsigned int cr; |
| 71 | |
| 72 | /* System Control Register: 11th bit Z Branch prediction enable */ |
| 73 | cr = get_cr(); |
| 74 | set_cr(set_cr_z ? cr | CR_Z : cr & ~CR_Z); |
| 75 | |
| 76 | return cr & CR_Z; |
| 77 | } |
Rajeshwari Shinde | 7a53377 | 2012-11-02 01:15:38 +0000 | [diff] [blame] | 78 | |
Chander Kashyap | 81e3520 | 2012-02-05 23:01:48 +0000 | [diff] [blame] | 79 | /* |
| 80 | * Copy U-boot from mmc to RAM: |
| 81 | * COPY_BL2_FNPTR_ADDR: Address in iRAM, which Contains |
| 82 | * Pointer to API (Data transfer from mmc to ram) |
| 83 | */ |
| 84 | void copy_uboot_to_ram(void) |
| 85 | { |
Vivek Gautam | 70656c7 | 2013-01-28 00:39:59 +0000 | [diff] [blame] | 86 | int is_cr_z_set; |
| 87 | unsigned int sec_boot_check; |
| 88 | enum boot_mode bootmode = BOOT_MODE_OM; |
Amar | c748be0 | 2013-04-27 11:42:59 +0530 | [diff] [blame] | 89 | |
| 90 | u32 (*spi_copy)(u32 offset, u32 nblock, u32 dst); |
| 91 | u32 (*copy_bl2)(u32 offset, u32 nblock, u32 dst); |
| 92 | u32 (*copy_bl2_from_emmc)(u32 nblock, u32 dst); |
| 93 | void (*end_bootop_from_emmc)(void); |
| 94 | u32 (*usb_copy)(void); |
Chander Kashyap | 81e3520 | 2012-02-05 23:01:48 +0000 | [diff] [blame] | 95 | |
Vivek Gautam | 70656c7 | 2013-01-28 00:39:59 +0000 | [diff] [blame] | 96 | /* Read iRAM location to check for secondary USB boot mode */ |
| 97 | sec_boot_check = readl(EXYNOS_IRAM_SECONDARY_BASE); |
| 98 | if (sec_boot_check == EXYNOS_USB_SECONDARY_BOOT) |
| 99 | bootmode = BOOT_MODE_USB; |
| 100 | |
| 101 | if (bootmode == BOOT_MODE_OM) |
| 102 | bootmode = readl(EXYNOS5_POWER_BASE) & OM_STAT; |
Rajeshwari Shinde | 7a53377 | 2012-11-02 01:15:38 +0000 | [diff] [blame] | 103 | |
| 104 | switch (bootmode) { |
| 105 | case BOOT_MODE_SERIAL: |
Amar | c748be0 | 2013-04-27 11:42:59 +0530 | [diff] [blame] | 106 | spi_copy = get_irom_func(SPI_INDEX); |
Rajeshwari Shinde | 7a53377 | 2012-11-02 01:15:38 +0000 | [diff] [blame] | 107 | spi_copy(SPI_FLASH_UBOOT_POS, CONFIG_BL2_SIZE, |
Amar | c748be0 | 2013-04-27 11:42:59 +0530 | [diff] [blame] | 108 | CONFIG_SYS_TEXT_BASE); |
Rajeshwari Shinde | 7a53377 | 2012-11-02 01:15:38 +0000 | [diff] [blame] | 109 | break; |
| 110 | case BOOT_MODE_MMC: |
Amar | c748be0 | 2013-04-27 11:42:59 +0530 | [diff] [blame] | 111 | copy_bl2 = get_irom_func(MMC_INDEX); |
Rajeshwari Shinde | 7a53377 | 2012-11-02 01:15:38 +0000 | [diff] [blame] | 112 | copy_bl2(BL2_START_OFFSET, BL2_SIZE_BLOC_COUNT, |
Amar | c748be0 | 2013-04-27 11:42:59 +0530 | [diff] [blame] | 113 | CONFIG_SYS_TEXT_BASE); |
| 114 | break; |
| 115 | case BOOT_MODE_EMMC: |
| 116 | /* Set the FSYS1 clock divisor value for EMMC boot */ |
| 117 | emmc_boot_clk_div_set(); |
| 118 | |
| 119 | copy_bl2_from_emmc = get_irom_func(EMMC44_INDEX); |
| 120 | end_bootop_from_emmc = get_irom_func(EMMC44_END_INDEX); |
| 121 | |
| 122 | copy_bl2_from_emmc(BL2_SIZE_BLOC_COUNT, CONFIG_SYS_TEXT_BASE); |
| 123 | end_bootop_from_emmc(); |
Rajeshwari Shinde | 7a53377 | 2012-11-02 01:15:38 +0000 | [diff] [blame] | 124 | break; |
Vivek Gautam | 70656c7 | 2013-01-28 00:39:59 +0000 | [diff] [blame] | 125 | case BOOT_MODE_USB: |
| 126 | /* |
| 127 | * iROM needs program flow prediction to be disabled |
| 128 | * before copy from USB device to RAM |
| 129 | */ |
| 130 | is_cr_z_set = config_branch_prediction(0); |
Amar | c748be0 | 2013-04-27 11:42:59 +0530 | [diff] [blame] | 131 | usb_copy = get_irom_func(USB_INDEX); |
Vivek Gautam | 70656c7 | 2013-01-28 00:39:59 +0000 | [diff] [blame] | 132 | usb_copy(); |
| 133 | config_branch_prediction(is_cr_z_set); |
| 134 | break; |
Rajeshwari Shinde | 7a53377 | 2012-11-02 01:15:38 +0000 | [diff] [blame] | 135 | default: |
| 136 | break; |
| 137 | } |
Chander Kashyap | 81e3520 | 2012-02-05 23:01:48 +0000 | [diff] [blame] | 138 | } |
| 139 | |
| 140 | void board_init_f(unsigned long bootflag) |
| 141 | { |
| 142 | __attribute__((noreturn)) void (*uboot)(void); |
| 143 | copy_uboot_to_ram(); |
| 144 | |
| 145 | /* Jump to U-Boot image */ |
| 146 | uboot = (void *)CONFIG_SYS_TEXT_BASE; |
| 147 | (*uboot)(); |
| 148 | /* Never returns Here */ |
| 149 | } |
| 150 | |
| 151 | /* Place Holders */ |
| 152 | void board_init_r(gd_t *id, ulong dest_addr) |
| 153 | { |
| 154 | /* Function attribute is no-return */ |
| 155 | /* This Function never executes */ |
| 156 | while (1) |
| 157 | ; |
| 158 | } |
Chander Kashyap | 81e3520 | 2012-02-05 23:01:48 +0000 | [diff] [blame] | 159 | void save_boot_params(u32 r0, u32 r1, u32 r2, u32 r3) {} |