1 /*
2  * (C) Copyright 2010
3  * Texas Instruments, <www.ti.com>
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License as
7  * published by the Free Software Foundation; either version 2 of
8  * the License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
18  * MA 02111-1307 USA
19  */
20 
21 #ifndef _SYS_PROTO_H_
22 #define _SYS_PROTO_H_
23 
24 #include <asm/arch/omap.h>
25 #include <asm/io.h>
26 #include <asm/arch/clocks.h>
27 #include <asm/omap_common.h>
28 #include <asm/arch/mux_omap5.h>
29 #include <asm/arch/clocks.h>
30 
31 struct omap_sysinfo {
32 	char *board_string;
33 };
34 extern const struct omap_sysinfo sysinfo;
35 
36 void gpmc_init(void);
37 void watchdog_init(void);
38 u32 get_device_type(void);
39 void do_set_mux(u32 base, struct pad_conf_entry const *array, int size);
40 void set_muxconf_regs_essential(void);
41 void set_muxconf_regs_non_essential(void);
42 void sr32(void *, u32, u32, u32);
43 u32 wait_on_value(u32, u32, void *, u32);
44 void sdelay(unsigned long);
45 void omap_rev_string(void);
46 void setup_clocks_for_console(void);
47 void prcm_init(void);
48 void bypass_dpll(u32 *const base);
49 void freq_update_core(void);
50 u32 get_sys_clk_freq(void);
51 u32 omap5_ddr_clk(void);
52 void cancel_out(u32 *num, u32 *den, u32 den_limit);
53 void sdram_init(void);
54 u32 omap_sdram_size(void);
55 u32 cortex_rev(void);
56 void init_omap_revision(void);
57 void do_io_settings(void);
58 
59 /*
60  * This is used to verify if the configuration header
61  * was executed by Romcode prior to control of transfer
62  * to the bootloader. SPL is responsible for saving and
63  * passing this to the u-boot.
64  */
65 extern struct omap_boot_parameters boot_params;
66 
67 static inline u32 running_from_sdram(void)
68 {
69 	u32 pc;
70 	asm volatile ("mov %0, pc" : "=r" (pc));
71 	return ((pc >= OMAP54XX_DRAM_ADDR_SPACE_START) &&
72 	    (pc < OMAP54XX_DRAM_ADDR_SPACE_END));
73 }
74 
75 static inline u8 uboot_loaded_by_spl(void)
76 {
77 	/*
78 	 * u-boot can be running from sdram either because of configuration
79 	 * Header or by SPL. If because of CH, then the romcode sets the
80 	 * CHSETTINGS executed bit to true in the boot parameter structure that
81 	 * it passes to the bootloader.This parameter is stored in the ch_flags
82 	 * variable by both SPL and u-boot.Check out for CHSETTINGS, which is a
83 	 * mandatory section if CH is present.
84 	 */
85 	if ((boot_params.ch_flags) & (CH_FLAGS_CHSETTINGS))
86 		return 0;
87 	else
88 		return running_from_sdram();
89 }
90 /*
91  * The basic hardware init of OMAP(s_init()) can happen in 4
92  * different contexts:
93  *  1. SPL running from SRAM
94  *  2. U-Boot running from FLASH
95  *  3. Non-XIP U-Boot loaded to SDRAM by SPL
96  *  4. Non-XIP U-Boot loaded to SDRAM by ROM code using the
97  *     Configuration Header feature
98  *
99  * This function finds this context.
100  * Defining as inline may help in compiling out unused functions in SPL
101  */
102 static inline u32 omap_hw_init_context(void)
103 {
104 #ifdef CONFIG_SPL_BUILD
105 	return OMAP_INIT_CONTEXT_SPL;
106 #else
107 	if (uboot_loaded_by_spl())
108 		return OMAP_INIT_CONTEXT_UBOOT_AFTER_SPL;
109 	else if (running_from_sdram())
110 		return OMAP_INIT_CONTEXT_UBOOT_AFTER_CH;
111 	else
112 		return OMAP_INIT_CONTEXT_UBOOT_FROM_NOR;
113 #endif
114 }
115 
116 static inline u32 omap_revision(void)
117 {
118 	extern u32 *const omap5_revision;
119 	return *omap5_revision;
120 }
121 
122 #endif
123