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>
18 #include <asm/arch/sys_proto.h>
19 #include <linux/sizes.h>
21 #include <asm/omap_common.h>
22 #include <linux/compiler.h>
23 #include <asm/system.h>
26 DECLARE_GLOBAL_DATA_PTR;
28 void do_set_mux(u32 base, struct pad_conf_entry const *array, int size)
31 struct pad_conf_entry *pad = (struct pad_conf_entry *) array;
33 for (i = 0; i < size; i++, pad++)
34 writew(pad->val, base + pad->offset);
37 static void set_mux_conf_regs(void)
39 switch (omap_hw_init_context()) {
40 case OMAP_INIT_CONTEXT_SPL:
43 case OMAP_INIT_CONTEXT_UBOOT_AFTER_SPL:
45 case OMAP_INIT_CONTEXT_UBOOT_FROM_NOR:
46 case OMAP_INIT_CONTEXT_UBOOT_AFTER_CH:
57 /* Read Main ID Register (MIDR) */
58 asm ("mrc p15, 0, %0, c0, c0, 0" : "=r" (rev));
63 static void omap_rev_string(void)
65 u32 omap_rev = omap_revision();
66 u32 soc_variant = (omap_rev & 0xF0000000) >> 28;
67 u32 omap_variant = (omap_rev & 0xFFFF0000) >> 16;
68 u32 major_rev = (omap_rev & 0x00000F00) >> 8;
69 u32 minor_rev = (omap_rev & 0x000000F0) >> 4;
71 const char *sec_s, *package = NULL;
73 switch (get_device_type()) {
90 #if defined(CONFIG_DRA7XX)
92 switch (omap_rev & 0xF) {
93 case DRA762_ABZ_PACKAGE:
96 case DRA762_ACD_PACKAGE:
108 printf("%x-%s ES%x.%x", omap_variant, sec_s, major_rev, minor_rev);
110 printf(" %s package\n", package);
115 #ifdef CONFIG_SPL_BUILD
116 void spl_display_print(void)
122 void __weak srcomp_enable(void)
127 * do_board_detect() - Detect board description
129 * Function to detect board description. This is expected to be
130 * overridden in the SoC family board file where desired.
132 void __weak do_board_detect(void)
137 * vcores_init() - Assign omap_vcores based on board
139 * Function to pick the vcores based on board. This is expected to be
140 * overridden in the SoC family board file where desired.
142 void __weak vcores_init(void)
151 * init_package_revision() - Initialize package revision
153 * Function to get the pacakage information. This is expected to be
154 * overridden in the SoC family file where desired.
156 void __weak init_package_revision(void)
161 * early_system_init - Does Early system initialization.
163 * Does early system init of watchdog, muxing, andclocks
164 * Watchdog disable is done always. For the rest what gets done
165 * depends on the boot mode in which this function is executed when
166 * 1. SPL running from SRAM
167 * 2. U-Boot running from FLASH
168 * 3. U-Boot loaded to SDRAM by SPL
169 * 4. U-Boot loaded to SDRAM by ROM code using the
170 * Configuration Header feature
171 * Please have a look at the respective functions to see what gets
172 * done in each of these cases
173 * This function is called with SRAM stack.
175 void early_system_init(void)
177 #if defined(CONFIG_SPL_BUILD) && defined(CONFIG_SPL_MULTI_DTB_FIT)
181 init_omap_revision();
183 init_package_revision();
185 #ifdef CONFIG_SPL_BUILD
187 force_emif_self_refresh();
191 #ifdef CONFIG_SPL_BUILD
195 setup_early_clocks();
197 #ifdef CONFIG_SPL_BUILD
199 * Save the boot parameters passed from romcode.
200 * We cannot delay the saving further than this,
201 * to prevent overwrites.
203 save_omap_boot_params();
208 #if defined(CONFIG_SPL_BUILD) && defined(CONFIG_SPL_MULTI_DTB_FIT)
210 * Board detection has been done.
211 * Let us see if another dtb wouldn't be a better match
214 ret = fdtdec_resetup(&rescan);
215 if (!ret && rescan) {
217 dm_init_and_scan(true);
222 #ifdef CONFIG_DEBUG_UART_OMAP
228 #ifdef CONFIG_SPL_BUILD
229 void board_init_f(ulong dummy)
232 #ifdef CONFIG_BOARD_EARLY_INIT_F
233 board_early_init_f();
235 /* For regular u-boot sdram_init() is called from dram_init() */
237 gd->ram_size = omap_sdram_size();
241 int arch_cpu_init_dm(void)
248 * Routine: wait_for_command_complete
249 * Description: Wait for posting to finish on watchdog
251 void wait_for_command_complete(struct watchdog *wd_base)
255 pending = readl(&wd_base->wwps);
260 * Routine: watchdog_init
261 * Description: Shut down watch dogs
263 void watchdog_init(void)
265 struct watchdog *wd2_base = (struct watchdog *)WDT2_BASE;
267 writel(WD_UNLOCK1, &wd2_base->wspr);
268 wait_for_command_complete(wd2_base);
269 writel(WD_UNLOCK2, &wd2_base->wspr);
274 * This function finds the SDRAM size available in the system
275 * based on DMM section configurations
276 * This is needed because the size of memory installed may be
277 * different on different versions of the board
279 u32 omap_sdram_size(void)
281 u32 section, i, valid;
282 u64 sdram_start = 0, sdram_end = 0, addr,
283 size, total_size = 0, trap_size = 0, trap_start = 0;
285 for (i = 0; i < 4; i++) {
286 section = __raw_readl(DMM_BASE + i*4);
287 valid = (section & EMIF_SDRC_ADDRSPC_MASK) >>
288 (EMIF_SDRC_ADDRSPC_SHIFT);
289 addr = section & EMIF_SYS_ADDR_MASK;
291 /* See if the address is valid */
292 if ((addr >= TI_ARMV7_DRAM_ADDR_SPACE_START) &&
293 (addr < TI_ARMV7_DRAM_ADDR_SPACE_END)) {
294 size = ((section & EMIF_SYS_SIZE_MASK) >>
295 EMIF_SYS_SIZE_SHIFT);
299 if (valid != DMM_SDRC_ADDR_SPC_INVALID) {
300 if (!sdram_start || (addr < sdram_start))
302 if (!sdram_end || ((addr + size) > sdram_end))
303 sdram_end = addr + size;
311 if ((trap_start >= sdram_start) && (trap_start < sdram_end))
312 total_size = (sdram_end - sdram_start) - (trap_size);
314 total_size = sdram_end - sdram_start;
322 * Description: sets uboots idea of sdram size
327 gd->ram_size = omap_sdram_size();
332 * Print board information
336 puts(sysinfo.board_string);
340 #if defined(CONFIG_DISPLAY_CPUINFO)
342 * Print CPU information
344 int print_cpuinfo(void)