1 // SPDX-License-Identifier: GPL-2.0+
4 * Common functions for OMAP4/5 based boards
7 * Texas Instruments, <www.ti.com>
10 * Aneesh V <aneesh@ti.com>
11 * Steve Sakoman <steve@sakoman.com>
14 #include <debug_uart.h>
17 #include <asm/arch/sys_proto.h>
18 #include <linux/sizes.h>
20 #include <asm/omap_common.h>
21 #include <linux/compiler.h>
22 #include <asm/system.h>
25 DECLARE_GLOBAL_DATA_PTR;
27 void do_set_mux(u32 base, struct pad_conf_entry const *array, int size)
30 struct pad_conf_entry *pad = (struct pad_conf_entry *) array;
32 for (i = 0; i < size; i++, pad++)
33 writew(pad->val, base + pad->offset);
36 static void set_mux_conf_regs(void)
38 switch (omap_hw_init_context()) {
39 case OMAP_INIT_CONTEXT_SPL:
42 case OMAP_INIT_CONTEXT_UBOOT_AFTER_SPL:
44 case OMAP_INIT_CONTEXT_UBOOT_FROM_NOR:
45 case OMAP_INIT_CONTEXT_UBOOT_AFTER_CH:
56 /* Read Main ID Register (MIDR) */
57 asm ("mrc p15, 0, %0, c0, c0, 0" : "=r" (rev));
62 static void omap_rev_string(void)
64 u32 omap_rev = omap_revision();
65 u32 soc_variant = (omap_rev & 0xF0000000) >> 28;
66 u32 omap_variant = (omap_rev & 0xFFFF0000) >> 16;
67 u32 major_rev = (omap_rev & 0x00000F00) >> 8;
68 u32 minor_rev = (omap_rev & 0x000000F0) >> 4;
70 const char *sec_s, *package = NULL;
72 switch (get_device_type()) {
89 #if defined(CONFIG_DRA7XX)
91 switch (omap_rev & 0xF) {
92 case DRA762_ABZ_PACKAGE:
95 case DRA762_ACD_PACKAGE:
107 printf("%x-%s ES%x.%x", omap_variant, sec_s, major_rev, minor_rev);
109 printf(" %s package\n", package);
114 #ifdef CONFIG_SPL_BUILD
115 void spl_display_print(void)
121 void __weak srcomp_enable(void)
126 * do_board_detect() - Detect board description
128 * Function to detect board description. This is expected to be
129 * overridden in the SoC family board file where desired.
131 void __weak do_board_detect(void)
136 * vcores_init() - Assign omap_vcores based on board
138 * Function to pick the vcores based on board. This is expected to be
139 * overridden in the SoC family board file where desired.
141 void __weak vcores_init(void)
150 * init_package_revision() - Initialize package revision
152 * Function to get the pacakage information. This is expected to be
153 * overridden in the SoC family file where desired.
155 void __weak init_package_revision(void)
160 * early_system_init - Does Early system initialization.
162 * Does early system init of watchdog, muxing, andclocks
163 * Watchdog disable is done always. For the rest what gets done
164 * depends on the boot mode in which this function is executed when
165 * 1. SPL running from SRAM
166 * 2. U-Boot running from FLASH
167 * 3. U-Boot loaded to SDRAM by SPL
168 * 4. U-Boot loaded to SDRAM by ROM code using the
169 * Configuration Header feature
170 * Please have a look at the respective functions to see what gets
171 * done in each of these cases
172 * This function is called with SRAM stack.
174 void early_system_init(void)
176 #if defined(CONFIG_SPL_BUILD) && defined(CONFIG_SPL_MULTI_DTB_FIT)
180 init_omap_revision();
182 init_package_revision();
184 #ifdef CONFIG_SPL_BUILD
186 force_emif_self_refresh();
190 #ifdef CONFIG_SPL_BUILD
194 setup_early_clocks();
196 #ifdef CONFIG_SPL_BUILD
198 * Save the boot parameters passed from romcode.
199 * We cannot delay the saving further than this,
200 * to prevent overwrites.
202 save_omap_boot_params();
207 #if defined(CONFIG_SPL_BUILD) && defined(CONFIG_SPL_MULTI_DTB_FIT)
209 * Board detection has been done.
210 * Let us see if another dtb wouldn't be a better match
213 ret = fdtdec_resetup(&rescan);
214 if (!ret && rescan) {
216 dm_init_and_scan(true);
221 #ifdef CONFIG_DEBUG_UART_OMAP
227 #ifdef CONFIG_SPL_BUILD
228 void board_init_f(ulong dummy)
231 #ifdef CONFIG_BOARD_EARLY_INIT_F
232 board_early_init_f();
234 /* For regular u-boot sdram_init() is called from dram_init() */
236 gd->ram_size = omap_sdram_size();
240 int arch_cpu_init_dm(void)
247 * Routine: wait_for_command_complete
248 * Description: Wait for posting to finish on watchdog
250 void wait_for_command_complete(struct watchdog *wd_base)
254 pending = readl(&wd_base->wwps);
259 * Routine: watchdog_init
260 * Description: Shut down watch dogs
262 void watchdog_init(void)
264 struct watchdog *wd2_base = (struct watchdog *)WDT2_BASE;
266 writel(WD_UNLOCK1, &wd2_base->wspr);
267 wait_for_command_complete(wd2_base);
268 writel(WD_UNLOCK2, &wd2_base->wspr);
273 * This function finds the SDRAM size available in the system
274 * based on DMM section configurations
275 * This is needed because the size of memory installed may be
276 * different on different versions of the board
278 u32 omap_sdram_size(void)
280 u32 section, i, valid;
281 u64 sdram_start = 0, sdram_end = 0, addr,
282 size, total_size = 0, trap_size = 0, trap_start = 0;
284 for (i = 0; i < 4; i++) {
285 section = __raw_readl(DMM_BASE + i*4);
286 valid = (section & EMIF_SDRC_ADDRSPC_MASK) >>
287 (EMIF_SDRC_ADDRSPC_SHIFT);
288 addr = section & EMIF_SYS_ADDR_MASK;
290 /* See if the address is valid */
291 if ((addr >= TI_ARMV7_DRAM_ADDR_SPACE_START) &&
292 (addr < TI_ARMV7_DRAM_ADDR_SPACE_END)) {
293 size = ((section & EMIF_SYS_SIZE_MASK) >>
294 EMIF_SYS_SIZE_SHIFT);
298 if (valid != DMM_SDRC_ADDR_SPC_INVALID) {
299 if (!sdram_start || (addr < sdram_start))
301 if (!sdram_end || ((addr + size) > sdram_end))
302 sdram_end = addr + size;
310 if ((trap_start >= sdram_start) && (trap_start < sdram_end))
311 total_size = (sdram_end - sdram_start) - (trap_size);
313 total_size = sdram_end - sdram_start;
321 * Description: sets uboots idea of sdram size
326 gd->ram_size = omap_sdram_size();
331 * Print board information
335 puts(sysinfo.board_string);
339 #if defined(CONFIG_DISPLAY_CPUINFO)
341 * Print CPU information
343 int print_cpuinfo(void)