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