3 * Common functions for OMAP4 based boards
6 * Texas Instruments, <www.ti.com>
12 * See file CREDITS for list of people who contributed to this
15 * This program is free software; you can redistribute it and/or
16 * modify it under the terms of the GNU General Public License as
17 * published by the Free Software Foundation; either version 2 of
18 * the License, or (at your option) any later version.
20 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
25 * You should have received a copy of the GNU General Public License
26 * along with this program; if not, write to the Free Software
27 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
31 #include <asm/armv7.h>
32 #include <asm/arch/cpu.h>
33 #include <asm/arch/sys_proto.h>
34 #include <asm/sizes.h>
35 #include <asm/arch/emif.h>
36 #include <asm/arch/gpio.h>
37 #include "omap4_mux_data.h"
39 DECLARE_GLOBAL_DATA_PTR;
41 u32 *const omap4_revision = (u32 *)OMAP4_SRAM_SCRATCH_OMAP4_REV;
43 static const struct gpio_bank gpio_bank_44xx[6] = {
44 { (void *)OMAP44XX_GPIO1_BASE, METHOD_GPIO_24XX },
45 { (void *)OMAP44XX_GPIO2_BASE, METHOD_GPIO_24XX },
46 { (void *)OMAP44XX_GPIO3_BASE, METHOD_GPIO_24XX },
47 { (void *)OMAP44XX_GPIO4_BASE, METHOD_GPIO_24XX },
48 { (void *)OMAP44XX_GPIO5_BASE, METHOD_GPIO_24XX },
49 { (void *)OMAP44XX_GPIO6_BASE, METHOD_GPIO_24XX },
52 const struct gpio_bank *const omap_gpio_bank = gpio_bank_44xx;
54 #ifdef CONFIG_SPL_BUILD
56 * We use static variables because global data is not ready yet.
57 * Initialized data is available in SPL right from the beginning.
58 * We would not typically need to save these parameters in regular
59 * U-Boot. This is needed only in SPL at the moment.
61 u32 omap4_boot_device = BOOT_DEVICE_MMC1;
62 u32 omap4_boot_mode = MMCSD_MODE_FAT;
64 u32 omap_boot_device(void)
66 return omap4_boot_device;
69 u32 omap_boot_mode(void)
71 return omap4_boot_mode;
75 void do_set_mux(u32 base, struct pad_conf_entry const *array, int size)
78 struct pad_conf_entry *pad = (struct pad_conf_entry *) array;
80 for (i = 0; i < size; i++, pad++)
81 writew(pad->val, base + pad->offset);
84 static void set_muxconf_regs_essential(void)
86 do_set_mux(CONTROL_PADCONF_CORE, core_padconf_array_essential,
87 sizeof(core_padconf_array_essential) /
88 sizeof(struct pad_conf_entry));
90 do_set_mux(CONTROL_PADCONF_WKUP, wkup_padconf_array_essential,
91 sizeof(wkup_padconf_array_essential) /
92 sizeof(struct pad_conf_entry));
94 /* gpio_wk7 is used for controlling TPS on 4460 */
95 if (omap_revision() >= OMAP4460_ES1_0)
96 writew(M3, CONTROL_WKUP_PAD1_FREF_CLK4_REQ);
99 static void set_mux_conf_regs(void)
101 switch (omap4_hw_init_context()) {
102 case OMAP_INIT_CONTEXT_SPL:
103 set_muxconf_regs_essential();
105 case OMAP_INIT_CONTEXT_UBOOT_AFTER_SPL:
106 set_muxconf_regs_non_essential();
108 case OMAP_INIT_CONTEXT_UBOOT_FROM_NOR:
109 case OMAP_INIT_CONTEXT_UBOOT_AFTER_CH:
110 set_muxconf_regs_essential();
111 set_muxconf_regs_non_essential();
116 static u32 cortex_a9_rev(void)
121 /* Read Main ID Register (MIDR) */
122 asm ("mrc p15, 0, %0, c0, c0, 0" : "=r" (rev));
127 static void init_omap4_revision(void)
130 * For some of the ES2/ES1 boards ID_CODE is not reliable:
131 * Also, ES1 and ES2 have different ARM revisions
132 * So use ARM revision for identification
134 unsigned int arm_rev = cortex_a9_rev();
137 case MIDR_CORTEX_A9_R0P1:
138 *omap4_revision = OMAP4430_ES1_0;
140 case MIDR_CORTEX_A9_R1P2:
141 switch (readl(CONTROL_ID_CODE)) {
142 case OMAP4_CONTROL_ID_CODE_ES2_0:
143 *omap4_revision = OMAP4430_ES2_0;
145 case OMAP4_CONTROL_ID_CODE_ES2_1:
146 *omap4_revision = OMAP4430_ES2_1;
148 case OMAP4_CONTROL_ID_CODE_ES2_2:
149 *omap4_revision = OMAP4430_ES2_2;
152 *omap4_revision = OMAP4430_ES2_0;
156 case MIDR_CORTEX_A9_R1P3:
157 *omap4_revision = OMAP4430_ES2_3;
159 case MIDR_CORTEX_A9_R2P10:
160 *omap4_revision = OMAP4460_ES1_0;
163 *omap4_revision = OMAP4430_SILICON_ID_INVALID;
168 void omap_rev_string(char *omap4_rev_string)
170 u32 omap4_rev = omap_revision();
171 u32 omap4_variant = (omap4_rev & 0xFFFF0000) >> 16;
172 u32 major_rev = (omap4_rev & 0x00000F00) >> 8;
173 u32 minor_rev = (omap4_rev & 0x000000F0) >> 4;
175 sprintf(omap4_rev_string, "OMAP%x ES%x.%x", omap4_variant, major_rev,
181 * Description: Does early system init of watchdog, muxing, andclocks
182 * Watchdog disable is done always. For the rest what gets done
183 * depends on the boot mode in which this function is executed
184 * 1. s_init of SPL running from SRAM
185 * 2. s_init of U-Boot running from FLASH
186 * 3. s_init of U-Boot loaded to SDRAM by SPL
187 * 4. s_init of U-Boot loaded to SDRAM by ROM code using the
188 * Configuration Header feature
189 * Please have a look at the respective functions to see what gets
190 * done in each of these cases
191 * This function is called with SRAM stack.
195 init_omap4_revision();
198 #ifdef CONFIG_SPL_BUILD
199 preloader_console_init();
202 #ifdef CONFIG_SPL_BUILD
203 /* For regular u-boot sdram_init() is called from dram_init() */
209 * Routine: wait_for_command_complete
210 * Description: Wait for posting to finish on watchdog
212 void wait_for_command_complete(struct watchdog *wd_base)
216 pending = readl(&wd_base->wwps);
221 * Routine: watchdog_init
222 * Description: Shut down watch dogs
224 void watchdog_init(void)
226 struct watchdog *wd2_base = (struct watchdog *)WDT2_BASE;
228 writel(WD_UNLOCK1, &wd2_base->wspr);
229 wait_for_command_complete(wd2_base);
230 writel(WD_UNLOCK2, &wd2_base->wspr);
235 * This function finds the SDRAM size available in the system
236 * based on DMM section configurations
237 * This is needed because the size of memory installed may be
238 * different on different versions of the board
240 u32 omap4_sdram_size(void)
242 u32 section, i, total_size = 0, size, addr;
243 for (i = 0; i < 4; i++) {
244 section = __raw_readl(OMAP44XX_DMM_LISA_MAP_BASE + i*4);
245 addr = section & OMAP44XX_SYS_ADDR_MASK;
246 /* See if the address is valid */
247 if ((addr >= OMAP44XX_DRAM_ADDR_SPACE_START) &&
248 (addr < OMAP44XX_DRAM_ADDR_SPACE_END)) {
249 size = ((section & OMAP44XX_SYS_SIZE_MASK) >>
250 OMAP44XX_SYS_SIZE_SHIFT);
262 * Description: sets uboots idea of sdram size
267 gd->ram_size = omap4_sdram_size();
273 * Print board information
277 puts(sysinfo.board_string);
282 * This function is called by start_armboot. You can reliably use static
283 * data. Any boot-time function that require static data should be
286 int arch_cpu_init(void)
291 #ifndef CONFIG_SYS_L2CACHE_OFF
292 void v7_outer_cache_enable(void)
294 set_pl310_ctrl_reg(1);
297 void v7_outer_cache_disable(void)
299 set_pl310_ctrl_reg(0);