blob: 98f2286f9efac619c16ba5ab162ac4aa6fb0a308 [file] [log] [blame]
Chander Kashyap81e35202012-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
Amarc748be02013-04-27 11:42:59 +053026#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 */
33enum index {
34 MMC_INDEX,
35 EMMC44_INDEX,
36 EMMC44_END_INDEX,
37 SPI_INDEX,
38 USB_INDEX,
39};
40
41/* IROM Function Pointers Table */
42u32 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 Shinde7a533772012-11-02 01:15:38 +000051enum boot_mode {
52 BOOT_MODE_MMC = 4,
53 BOOT_MODE_SERIAL = 20,
Amarc748be02013-04-27 11:42:59 +053054 BOOT_MODE_EMMC = 8, /* EMMC4.4 */
Rajeshwari Shinde7a533772012-11-02 01:15:38 +000055 /* Boot based on Operating Mode pin settings */
56 BOOT_MODE_OM = 32,
57 BOOT_MODE_USB, /* Boot using USB download */
58};
59
Amarc748be02013-04-27 11:42:59 +053060void *get_irom_func(int index)
61{
62 return (void *)*(u32 *)irom_ptr_table[index];
63}
Vivek Gautam70656c72013-01-28 00:39:59 +000064
65/*
66 * Set/clear program flow prediction and return the previous state.
67 */
68static 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 Shinde7a533772012-11-02 01:15:38 +000078
Chander Kashyap81e35202012-02-05 23:01:48 +000079/*
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*/
84void copy_uboot_to_ram(void)
85{
Vivek Gautam70656c72013-01-28 00:39:59 +000086 int is_cr_z_set;
87 unsigned int sec_boot_check;
88 enum boot_mode bootmode = BOOT_MODE_OM;
Amarc748be02013-04-27 11:42:59 +053089
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 Kashyap81e35202012-02-05 23:01:48 +000095
Vivek Gautam70656c72013-01-28 00:39:59 +000096 /* 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 Shinde7a533772012-11-02 01:15:38 +0000103
104 switch (bootmode) {
105 case BOOT_MODE_SERIAL:
Amarc748be02013-04-27 11:42:59 +0530106 spi_copy = get_irom_func(SPI_INDEX);
Rajeshwari Shinde7a533772012-11-02 01:15:38 +0000107 spi_copy(SPI_FLASH_UBOOT_POS, CONFIG_BL2_SIZE,
Amarc748be02013-04-27 11:42:59 +0530108 CONFIG_SYS_TEXT_BASE);
Rajeshwari Shinde7a533772012-11-02 01:15:38 +0000109 break;
110 case BOOT_MODE_MMC:
Amarc748be02013-04-27 11:42:59 +0530111 copy_bl2 = get_irom_func(MMC_INDEX);
Rajeshwari Shinde7a533772012-11-02 01:15:38 +0000112 copy_bl2(BL2_START_OFFSET, BL2_SIZE_BLOC_COUNT,
Amarc748be02013-04-27 11:42:59 +0530113 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 Shinde7a533772012-11-02 01:15:38 +0000124 break;
Vivek Gautam70656c72013-01-28 00:39:59 +0000125 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);
Amarc748be02013-04-27 11:42:59 +0530131 usb_copy = get_irom_func(USB_INDEX);
Vivek Gautam70656c72013-01-28 00:39:59 +0000132 usb_copy();
133 config_branch_prediction(is_cr_z_set);
134 break;
Rajeshwari Shinde7a533772012-11-02 01:15:38 +0000135 default:
136 break;
137 }
Chander Kashyap81e35202012-02-05 23:01:48 +0000138}
139
140void 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 */
152void 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 Kashyap81e35202012-02-05 23:01:48 +0000159void save_boot_params(u32 r0, u32 r1, u32 r2, u32 r3) {}