blob: c4a8eabc3ebe1e7e8645380e0848a628498fd13f [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Steve Sakoman1ad21582010-06-08 13:07:46 -07002/*
3 *
Sricharan9310ff72011-11-15 09:49:55 -05004 * Common functions for OMAP4/5 based boards
Steve Sakoman1ad21582010-06-08 13:07:46 -07005 *
6 * (C) Copyright 2010
7 * Texas Instruments, <www.ti.com>
8 *
9 * Author :
10 * Aneesh V <aneesh@ti.com>
11 * Steve Sakoman <steve@sakoman.com>
Steve Sakoman1ad21582010-06-08 13:07:46 -070012 */
13#include <common.h>
Lokesh Vutlaac8bd3c2017-05-05 13:45:27 +053014#include <debug_uart.h>
Simon Glassfc557362022-03-04 08:43:05 -070015#include <event.h>
Jean-Jacques Hiblot651201b2018-12-07 14:50:55 +010016#include <fdtdec.h>
Simon Glass97589732020-05-10 11:40:02 -060017#include <init.h>
Tom Rini28591df2012-08-13 12:03:19 -070018#include <spl.h>
Steve Sakoman1ad21582010-06-08 13:07:46 -070019#include <asm/arch/sys_proto.h>
Simon Glass3ba929a2020-10-30 21:38:53 -060020#include <asm/global_data.h>
Alexey Brodkin267d8e22014-02-26 17:47:58 +040021#include <linux/sizes.h>
Sricharan62a86502011-11-15 09:50:00 -050022#include <asm/emif.h>
SRICHARAN Rfb6aa1f2013-02-04 04:22:00 +000023#include <asm/omap_common.h>
Lokesh Vutla28049632013-02-12 01:33:45 +000024#include <linux/compiler.h>
R Sricharan06396c12013-03-04 20:04:45 +000025#include <asm/system.h>
Jean-Jacques Hiblot651201b2018-12-07 14:50:55 +010026#include <dm/root.h>
R Sricharan06396c12013-03-04 20:04:45 +000027
Nishanth Menon4e5dd662010-11-19 11:19:40 -050028DECLARE_GLOBAL_DATA_PTR;
29
Aneesh Vf908b632011-07-21 09:10:01 -040030void do_set_mux(u32 base, struct pad_conf_entry const *array, int size)
31{
32 int i;
33 struct pad_conf_entry *pad = (struct pad_conf_entry *) array;
34
35 for (i = 0; i < size; i++, pad++)
36 writew(pad->val, base + pad->offset);
37}
38
Aneesh Vf908b632011-07-21 09:10:01 -040039static void set_mux_conf_regs(void)
40{
Sricharan9310ff72011-11-15 09:49:55 -050041 switch (omap_hw_init_context()) {
Aneesh Vf908b632011-07-21 09:10:01 -040042 case OMAP_INIT_CONTEXT_SPL:
Paul Kocialkowskia00b1e52016-02-27 19:18:56 +010043 set_muxconf_regs();
Aneesh Vf908b632011-07-21 09:10:01 -040044 break;
45 case OMAP_INIT_CONTEXT_UBOOT_AFTER_SPL:
Aneesh Vf908b632011-07-21 09:10:01 -040046 break;
47 case OMAP_INIT_CONTEXT_UBOOT_FROM_NOR:
48 case OMAP_INIT_CONTEXT_UBOOT_AFTER_CH:
Paul Kocialkowskia00b1e52016-02-27 19:18:56 +010049 set_muxconf_regs();
Aneesh Vf908b632011-07-21 09:10:01 -040050 break;
51 }
52}
53
Sricharan9310ff72011-11-15 09:49:55 -050054u32 cortex_rev(void)
Aneesh V162ced32011-07-21 09:10:04 -040055{
56
57 unsigned int rev;
58
59 /* Read Main ID Register (MIDR) */
60 asm ("mrc p15, 0, %0, c0, c0, 0" : "=r" (rev));
61
62 return rev;
63}
64
Tom Rini01b2dd92013-05-31 10:44:23 -040065static void omap_rev_string(void)
Aneesh V162ced32011-07-21 09:10:04 -040066{
Sricharan9310ff72011-11-15 09:49:55 -050067 u32 omap_rev = omap_revision();
Lokesh Vutla43c296f2013-02-12 21:29:03 +000068 u32 soc_variant = (omap_rev & 0xF0000000) >> 28;
Sricharan9310ff72011-11-15 09:49:55 -050069 u32 omap_variant = (omap_rev & 0xFFFF0000) >> 16;
70 u32 major_rev = (omap_rev & 0x00000F00) >> 8;
71 u32 minor_rev = (omap_rev & 0x000000F0) >> 4;
Aneesh V162ced32011-07-21 09:10:04 -040072
Lokesh Vutla69483e62017-12-29 11:47:51 +053073 const char *sec_s, *package = NULL;
Daniel Allredfd684b22016-05-19 19:10:52 -050074
75 switch (get_device_type()) {
76 case TST_DEVICE:
77 sec_s = "TST";
78 break;
79 case EMU_DEVICE:
80 sec_s = "EMU";
81 break;
82 case HS_DEVICE:
83 sec_s = "HS";
84 break;
85 case GP_DEVICE:
86 sec_s = "GP";
87 break;
88 default:
89 sec_s = "?";
90 }
91
Lokesh Vutla69483e62017-12-29 11:47:51 +053092#if defined(CONFIG_DRA7XX)
93 if (is_dra76x()) {
94 switch (omap_rev & 0xF) {
95 case DRA762_ABZ_PACKAGE:
96 package = "ABZ";
97 break;
98 case DRA762_ACD_PACKAGE:
99 default:
100 package = "ACD";
101 break;
102 }
103 }
104#endif
105
Lokesh Vutla43c296f2013-02-12 21:29:03 +0000106 if (soc_variant)
107 printf("OMAP");
108 else
109 printf("DRA");
Lokesh Vutla69483e62017-12-29 11:47:51 +0530110 printf("%x-%s ES%x.%x", omap_variant, sec_s, major_rev, minor_rev);
111 if (package)
112 printf(" %s package\n", package);
113 else
114 puts("\n");
Aneesh V162ced32011-07-21 09:10:04 -0400115}
116
Sricharan308fe922011-11-15 09:50:03 -0500117#ifdef CONFIG_SPL_BUILD
Tom Rinife3b0c72012-08-13 11:37:56 -0700118void spl_display_print(void)
119{
120 omap_rev_string();
121}
Sricharan308fe922011-11-15 09:50:03 -0500122#endif
123
Lokesh Vutla28049632013-02-12 01:33:45 +0000124void __weak srcomp_enable(void)
125{
SRICHARAN R4af19882013-04-24 00:41:23 +0000126}
127
Kipisz, Steven4466dfb2016-02-24 12:30:57 -0600128/**
129 * do_board_detect() - Detect board description
130 *
131 * Function to detect board description. This is expected to be
132 * overridden in the SoC family board file where desired.
133 */
134void __weak do_board_detect(void)
135{
136}
137
Keerthy35740ec2016-05-24 11:45:05 +0530138/**
139 * vcores_init() - Assign omap_vcores based on board
140 *
141 * Function to pick the vcores based on board. This is expected to be
142 * overridden in the SoC family board file where desired.
143 */
144void __weak vcores_init(void)
145{
146}
147
Lokesh Vutlae8534d22016-03-07 14:49:54 +0530148void s_init(void)
149{
150}
151
152/**
Lokesh Vutla69483e62017-12-29 11:47:51 +0530153 * init_package_revision() - Initialize package revision
154 *
155 * Function to get the pacakage information. This is expected to be
156 * overridden in the SoC family file where desired.
157 */
158void __weak init_package_revision(void)
159{
160}
161
162/**
Lokesh Vutlae8534d22016-03-07 14:49:54 +0530163 * early_system_init - Does Early system initialization.
164 *
165 * Does early system init of watchdog, muxing, andclocks
Aneesh Vf908b632011-07-21 09:10:01 -0400166 * Watchdog disable is done always. For the rest what gets done
Lokesh Vutlae8534d22016-03-07 14:49:54 +0530167 * depends on the boot mode in which this function is executed when
168 * 1. SPL running from SRAM
169 * 2. U-Boot running from FLASH
170 * 3. U-Boot loaded to SDRAM by SPL
171 * 4. U-Boot loaded to SDRAM by ROM code using the
Aneesh Vf908b632011-07-21 09:10:01 -0400172 * Configuration Header feature
173 * Please have a look at the respective functions to see what gets
174 * done in each of these cases
175 * This function is called with SRAM stack.
Steve Sakoman1ad21582010-06-08 13:07:46 -0700176 */
Lokesh Vutlae8534d22016-03-07 14:49:54 +0530177void early_system_init(void)
Steve Sakoman1ad21582010-06-08 13:07:46 -0700178{
Jean-Jacques Hiblot651201b2018-12-07 14:50:55 +0100179#if defined(CONFIG_SPL_BUILD) && defined(CONFIG_SPL_MULTI_DTB_FIT)
180 int ret;
181 int rescan;
182#endif
Sricharan9310ff72011-11-15 09:49:55 -0500183 init_omap_revision();
SRICHARAN Rfb6aa1f2013-02-04 04:22:00 +0000184 hw_data_init();
Lokesh Vutla69483e62017-12-29 11:47:51 +0530185 init_package_revision();
SRICHARAN Rfb6aa1f2013-02-04 04:22:00 +0000186
Lokesh Vutlaba873772012-05-29 19:26:43 +0000187#ifdef CONFIG_SPL_BUILD
Lokesh Vutlae38b45a2016-07-12 14:47:41 +0530188 if (warm_reset())
Lokesh Vutlaba873772012-05-29 19:26:43 +0000189 force_emif_self_refresh();
190#endif
Steve Sakoman1ad21582010-06-08 13:07:46 -0700191 watchdog_init();
Aneesh Vf908b632011-07-21 09:10:01 -0400192 set_mux_conf_regs();
Aneesh Vb8e60b92011-07-21 09:10:21 -0400193#ifdef CONFIG_SPL_BUILD
Lokesh Vutla28049632013-02-12 01:33:45 +0000194 srcomp_enable();
Aneesh Vb35f7cb2011-09-08 11:05:56 -0400195 do_io_settings();
Aneesh Vb8e60b92011-07-21 09:10:21 -0400196#endif
Kipisz, Stevenebe86dc2016-02-24 12:30:52 -0600197 setup_early_clocks();
Jean-Jacques Hiblot651201b2018-12-07 14:50:55 +0100198
Lokesh Vutlaca23da12017-06-27 13:50:56 +0530199#ifdef CONFIG_SPL_BUILD
200 /*
201 * Save the boot parameters passed from romcode.
202 * We cannot delay the saving further than this,
203 * to prevent overwrites.
204 */
205 save_omap_boot_params();
Jean-Jacques Hiblota68ca9e2017-09-15 12:57:33 +0200206 spl_early_init();
207#endif
Jean-Jacques Hiblot3a502f62018-12-07 14:50:45 +0100208 do_board_detect();
209
Jean-Jacques Hiblot651201b2018-12-07 14:50:55 +0100210#if defined(CONFIG_SPL_BUILD) && defined(CONFIG_SPL_MULTI_DTB_FIT)
211 /*
212 * Board detection has been done.
213 * Let us see if another dtb wouldn't be a better match
214 * for our board
215 */
216 ret = fdtdec_resetup(&rescan);
217 if (!ret && rescan) {
218 dm_uninit();
219 dm_init_and_scan(true);
220 }
221#endif
222
Keerthy35740ec2016-05-24 11:45:05 +0530223 vcores_init();
Lokesh Vutlaac8bd3c2017-05-05 13:45:27 +0530224#ifdef CONFIG_DEBUG_UART_OMAP
225 debug_uart_init();
226#endif
Aneesh V0d2628b2011-07-21 09:10:07 -0400227 prcm_init();
Simon Glass0c078ea2015-03-03 08:03:02 -0700228}
229
Aneesh Vb8e60b92011-07-21 09:10:21 -0400230#ifdef CONFIG_SPL_BUILD
Simon Glass0c078ea2015-03-03 08:03:02 -0700231void board_init_f(ulong dummy)
232{
Lokesh Vutlae8534d22016-03-07 14:49:54 +0530233 early_system_init();
Lokesh Vutlabe86f0e2014-08-04 19:42:24 +0530234#ifdef CONFIG_BOARD_EARLY_INIT_F
235 board_early_init_f();
236#endif
Aneesh Vb8e60b92011-07-21 09:10:21 -0400237 /* For regular u-boot sdram_init() is called from dram_init() */
238 sdram_init();
Lokesh Vutlabed46ef2017-04-18 17:27:24 +0530239 gd->ram_size = omap_sdram_size();
Steve Sakoman1ad21582010-06-08 13:07:46 -0700240}
Simon Glass0c078ea2015-03-03 08:03:02 -0700241#endif
Steve Sakoman1ad21582010-06-08 13:07:46 -0700242
Simon Glassfc557362022-03-04 08:43:05 -0700243static int omap2_system_init(void *ctx, struct event *event)
Lokesh Vutlae8534d22016-03-07 14:49:54 +0530244{
245 early_system_init();
Simon Glassfc557362022-03-04 08:43:05 -0700246
Lokesh Vutlae8534d22016-03-07 14:49:54 +0530247 return 0;
248}
Simon Glassfc557362022-03-04 08:43:05 -0700249EVENT_SPY(EVT_DM_POST_INIT, omap2_system_init);
Lokesh Vutlae8534d22016-03-07 14:49:54 +0530250
Steve Sakoman1ad21582010-06-08 13:07:46 -0700251/*
252 * Routine: wait_for_command_complete
253 * Description: Wait for posting to finish on watchdog
254 */
255void wait_for_command_complete(struct watchdog *wd_base)
256{
257 int pending = 1;
258 do {
259 pending = readl(&wd_base->wwps);
260 } while (pending);
261}
262
263/*
264 * Routine: watchdog_init
265 * Description: Shut down watch dogs
266 */
267void watchdog_init(void)
268{
269 struct watchdog *wd2_base = (struct watchdog *)WDT2_BASE;
270
271 writel(WD_UNLOCK1, &wd2_base->wspr);
272 wait_for_command_complete(wd2_base);
273 writel(WD_UNLOCK2, &wd2_base->wspr);
274}
275
Aneesh V04bd2b92010-09-12 10:32:55 +0530276
277/*
278 * This function finds the SDRAM size available in the system
279 * based on DMM section configurations
280 * This is needed because the size of memory installed may be
281 * different on different versions of the board
282 */
Sricharan9310ff72011-11-15 09:49:55 -0500283u32 omap_sdram_size(void)
Aneesh V04bd2b92010-09-12 10:32:55 +0530284{
SRICHARAN R015be792012-05-17 00:12:06 +0000285 u32 section, i, valid;
286 u64 sdram_start = 0, sdram_end = 0, addr,
Lokesh Vutlae45d3bb2014-05-12 13:49:33 +0530287 size, total_size = 0, trap_size = 0, trap_start = 0;
Sricharan62a86502011-11-15 09:50:00 -0500288
Aneesh V04bd2b92010-09-12 10:32:55 +0530289 for (i = 0; i < 4; i++) {
Sricharan62a86502011-11-15 09:50:00 -0500290 section = __raw_readl(DMM_BASE + i*4);
SRICHARAN R015be792012-05-17 00:12:06 +0000291 valid = (section & EMIF_SDRC_ADDRSPC_MASK) >>
292 (EMIF_SDRC_ADDRSPC_SHIFT);
Sricharan62a86502011-11-15 09:50:00 -0500293 addr = section & EMIF_SYS_ADDR_MASK;
SRICHARAN R015be792012-05-17 00:12:06 +0000294
Aneesh V04bd2b92010-09-12 10:32:55 +0530295 /* See if the address is valid */
Tom Rini72f36002014-05-16 13:02:24 -0400296 if ((addr >= TI_ARMV7_DRAM_ADDR_SPACE_START) &&
297 (addr < TI_ARMV7_DRAM_ADDR_SPACE_END)) {
Sricharan62a86502011-11-15 09:50:00 -0500298 size = ((section & EMIF_SYS_SIZE_MASK) >>
299 EMIF_SYS_SIZE_SHIFT);
300 size = 1 << size;
301 size *= SZ_16M;
SRICHARAN R015be792012-05-17 00:12:06 +0000302
303 if (valid != DMM_SDRC_ADDR_SPC_INVALID) {
304 if (!sdram_start || (addr < sdram_start))
305 sdram_start = addr;
306 if (!sdram_end || ((addr + size) > sdram_end))
307 sdram_end = addr + size;
308 } else {
309 trap_size = size;
Lokesh Vutlae45d3bb2014-05-12 13:49:33 +0530310 trap_start = addr;
SRICHARAN R015be792012-05-17 00:12:06 +0000311 }
Aneesh V04bd2b92010-09-12 10:32:55 +0530312 }
313 }
Lokesh Vutlae45d3bb2014-05-12 13:49:33 +0530314
315 if ((trap_start >= sdram_start) && (trap_start < sdram_end))
316 total_size = (sdram_end - sdram_start) - (trap_size);
317 else
318 total_size = sdram_end - sdram_start;
Sricharan62a86502011-11-15 09:50:00 -0500319
Aneesh V04bd2b92010-09-12 10:32:55 +0530320 return total_size;
321}
322
323
Steve Sakoman1ad21582010-06-08 13:07:46 -0700324/*
325 * Routine: dram_init
326 * Description: sets uboots idea of sdram size
327 */
328int dram_init(void)
329{
Aneesh Vcc565582011-07-21 09:10:09 -0400330 sdram_init();
Sricharan9310ff72011-11-15 09:49:55 -0500331 gd->ram_size = omap_sdram_size();
Steve Sakoman1ad21582010-06-08 13:07:46 -0700332 return 0;
333}
334
335/*
336 * Print board information
337 */
338int checkboard(void)
339{
340 puts(sysinfo.board_string);
341 return 0;
342}
343
Masahiro Yamada81a689e2014-02-13 18:30:26 +0900344#if defined(CONFIG_DISPLAY_CPUINFO)
Sricharan9310ff72011-11-15 09:49:55 -0500345/*
346 * Print CPU information
347 */
348int print_cpuinfo(void)
Aneesh Ve3405bd2011-06-16 23:30:52 +0000349{
Andreas Müller0cda7a42012-01-04 15:26:24 +0000350 puts("CPU : ");
351 omap_rev_string();
Sricharan9310ff72011-11-15 09:49:55 -0500352
353 return 0;
354}
Masahiro Yamada81a689e2014-02-13 18:30:26 +0900355#endif