blob: db042a1aef2defa2d6ddf1cd26306b16dc57b4f4 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001/* SPDX-License-Identifier: GPL-2.0+ */
Tom Rini72f36002014-05-16 13:02:24 -04002/*
3 * (C) Copyright 2014
4 * Texas Instruments, <www.ti.com>
Tom Rini72f36002014-05-16 13:02:24 -04005 */
6#ifndef _TI_COMMON_SYS_PROTO_H_
7#define _TI_COMMON_SYS_PROTO_H_
8
9DECLARE_GLOBAL_DATA_PTR;
10
Masahiro Yamada6e1288c2017-04-25 13:10:11 +090011#ifdef CONFIG_ARCH_OMAP2PLUS
Tom Rini72f36002014-05-16 13:02:24 -040012#define TI_ARMV7_DRAM_ADDR_SPACE_START 0x80000000
13#define TI_ARMV7_DRAM_ADDR_SPACE_END 0xFFFFFFFF
14
15#define OMAP_INIT_CONTEXT_SPL 0
16#define OMAP_INIT_CONTEXT_UBOOT_FROM_NOR 1
17#define OMAP_INIT_CONTEXT_UBOOT_AFTER_SPL 2
18#define OMAP_INIT_CONTEXT_UBOOT_AFTER_CH 3
19
20static inline u32 running_from_sdram(void)
21{
22 u32 pc;
23 asm volatile ("mov %0, pc" : "=r" (pc));
24 return ((pc >= TI_ARMV7_DRAM_ADDR_SPACE_START) &&
25 (pc < TI_ARMV7_DRAM_ADDR_SPACE_END));
26}
27
28static inline u8 uboot_loaded_by_spl(void)
29{
30 /*
31 * u-boot can be running from sdram either because of configuration
32 * Header or by SPL. If because of CH, then the romcode sets the
33 * CHSETTINGS executed bit to true in the boot parameter structure that
34 * it passes to the bootloader.This parameter is stored in the ch_flags
35 * variable by both SPL and u-boot.Check out for CHSETTINGS, which is a
36 * mandatory section if CH is present.
37 */
Paul Kocialkowskid5b76242015-07-15 16:02:19 +020038 if (gd->arch.omap_ch_flags & CH_FLAGS_CHSETTINGS)
Tom Rini72f36002014-05-16 13:02:24 -040039 return 0;
40 else
41 return running_from_sdram();
42}
43
44/*
45 * The basic hardware init of OMAP(s_init()) can happen in 4
46 * different contexts:
47 * 1. SPL running from SRAM
48 * 2. U-Boot running from FLASH
49 * 3. Non-XIP U-Boot loaded to SDRAM by SPL
50 * 4. Non-XIP U-Boot loaded to SDRAM by ROM code using the
51 * Configuration Header feature
52 *
53 * This function finds this context.
54 * Defining as inline may help in compiling out unused functions in SPL
55 */
56static inline u32 omap_hw_init_context(void)
57{
58#ifdef CONFIG_SPL_BUILD
59 return OMAP_INIT_CONTEXT_SPL;
60#else
61 if (uboot_loaded_by_spl())
62 return OMAP_INIT_CONTEXT_UBOOT_AFTER_SPL;
63 else if (running_from_sdram())
64 return OMAP_INIT_CONTEXT_UBOOT_AFTER_CH;
65 else
66 return OMAP_INIT_CONTEXT_UBOOT_FROM_NOR;
67#endif
68}
69#endif
70
71#endif