blob: 83275f1e0718d55507cb9d5f18258fcdb43e17cd [file] [log] [blame]
Chander Kashyap1633dd12012-02-05 23:01:48 +00001/*
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
Amare33add82013-04-27 11:42:59 +053026#include <asm/arch-exynos/dmc.h>
27#include <asm/arch/clock.h>
28#include <asm/arch/clk.h>
Rajeshwari Shindebff6d0a2013-06-25 19:17:06 +053029#include <asm/arch/spl.h>
Amare33add82013-04-27 11:42:59 +053030
31#include "clock_init.h"
32
33/* Index into irom ptr table */
34enum index {
35 MMC_INDEX,
36 EMMC44_INDEX,
37 EMMC44_END_INDEX,
38 SPI_INDEX,
39 USB_INDEX,
40};
41
42/* IROM Function Pointers Table */
43u32 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
Amare33add82013-04-27 11:42:59 +053052void *get_irom_func(int index)
53{
54 return (void *)*(u32 *)irom_ptr_table[index];
55}
Rajeshwari Shinde9cb48e82012-11-02 01:15:38 +000056
Chander Kashyap1633dd12012-02-05 23:01:48 +000057/*
Vivek Gautam681dd832013-01-28 00:39:59 +000058 * Set/clear program flow prediction and return the previous state.
59 */
60static 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 Kashyap1633dd12012-02-05 23:01:48 +000072* 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*/
76void copy_uboot_to_ram(void)
77{
Vivek Gautam681dd832013-01-28 00:39:59 +000078 int is_cr_z_set;
79 unsigned int sec_boot_check;
80 enum boot_mode bootmode = BOOT_MODE_OM;
Amare33add82013-04-27 11:42:59 +053081
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 Shinde9cb48e82012-11-02 01:15:38 +000087
Vivek Gautam681dd832013-01-28 00:39:59 +000088 /* 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 Kashyap1633dd12012-02-05 23:01:48 +000095
Rajeshwari Shinde9cb48e82012-11-02 01:15:38 +000096 switch (bootmode) {
97 case BOOT_MODE_SERIAL:
Amare33add82013-04-27 11:42:59 +053098 spi_copy = get_irom_func(SPI_INDEX);
Rajeshwari Shinde9cb48e82012-11-02 01:15:38 +000099 spi_copy(SPI_FLASH_UBOOT_POS, CONFIG_BL2_SIZE,
Amare33add82013-04-27 11:42:59 +0530100 CONFIG_SYS_TEXT_BASE);
Rajeshwari Shinde9cb48e82012-11-02 01:15:38 +0000101 break;
102 case BOOT_MODE_MMC:
Amare33add82013-04-27 11:42:59 +0530103 copy_bl2 = get_irom_func(MMC_INDEX);
Rajeshwari Shinde9cb48e82012-11-02 01:15:38 +0000104 copy_bl2(BL2_START_OFFSET, BL2_SIZE_BLOC_COUNT,
Amare33add82013-04-27 11:42:59 +0530105 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 Shinde9cb48e82012-11-02 01:15:38 +0000116 break;
Vivek Gautam681dd832013-01-28 00:39:59 +0000117 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);
Amare33add82013-04-27 11:42:59 +0530123 usb_copy = get_irom_func(USB_INDEX);
Vivek Gautam681dd832013-01-28 00:39:59 +0000124 usb_copy();
125 config_branch_prediction(is_cr_z_set);
126 break;
Rajeshwari Shinde9cb48e82012-11-02 01:15:38 +0000127 default:
128 break;
129 }
Chander Kashyap1633dd12012-02-05 23:01:48 +0000130}
131
132void 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 */
144void 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 Kashyap1633dd12012-02-05 23:01:48 +0000151void save_boot_params(u32 r0, u32 r1, u32 r2, u32 r3) {}