blob: 772b4c4db5dc495f5f30f43657eb9742a21a9f37 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Steve Sakomand34efc72010-06-08 13:07:46 -07002/*
3 *
Sricharan508a58f2011-11-15 09:49:55 -05004 * Common functions for OMAP4/5 based boards
Steve Sakomand34efc72010-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 Sakomand34efc72010-06-08 13:07:46 -070012 */
13#include <common.h>
Lokesh Vutla01fe1192017-05-05 13:45:27 +053014#include <debug_uart.h>
Jean-Jacques Hiblot40ecdbc2018-12-07 14:50:55 +010015#include <fdtdec.h>
Tom Rini47f7bca2012-08-13 12:03:19 -070016#include <spl.h>
Steve Sakomand34efc72010-06-08 13:07:46 -070017#include <asm/arch/sys_proto.h>
Alexey Brodkin1ace4022014-02-26 17:47:58 +040018#include <linux/sizes.h>
Sricharanbb772a52011-11-15 09:50:00 -050019#include <asm/emif.h>
SRICHARAN R01b753f2013-02-04 04:22:00 +000020#include <asm/omap_common.h>
Lokesh Vutlad4d986e2013-02-12 01:33:45 +000021#include <linux/compiler.h>
R Sricharande63ac22013-03-04 20:04:45 +000022#include <asm/system.h>
Jean-Jacques Hiblot40ecdbc2018-12-07 14:50:55 +010023#include <dm/root.h>
R Sricharande63ac22013-03-04 20:04:45 +000024
Nishanth Menon93e35682010-11-19 11:19:40 -050025DECLARE_GLOBAL_DATA_PTR;
26
Aneesh V469ec1e2011-07-21 09:10:01 -040027void do_set_mux(u32 base, struct pad_conf_entry const *array, int size)
28{
29 int i;
30 struct pad_conf_entry *pad = (struct pad_conf_entry *) array;
31
32 for (i = 0; i < size; i++, pad++)
33 writew(pad->val, base + pad->offset);
34}
35
Aneesh V469ec1e2011-07-21 09:10:01 -040036static void set_mux_conf_regs(void)
37{
Sricharan508a58f2011-11-15 09:49:55 -050038 switch (omap_hw_init_context()) {
Aneesh V469ec1e2011-07-21 09:10:01 -040039 case OMAP_INIT_CONTEXT_SPL:
Paul Kocialkowski3ef56e62016-02-27 19:18:56 +010040 set_muxconf_regs();
Aneesh V469ec1e2011-07-21 09:10:01 -040041 break;
42 case OMAP_INIT_CONTEXT_UBOOT_AFTER_SPL:
Aneesh V469ec1e2011-07-21 09:10:01 -040043 break;
44 case OMAP_INIT_CONTEXT_UBOOT_FROM_NOR:
45 case OMAP_INIT_CONTEXT_UBOOT_AFTER_CH:
Paul Kocialkowski3ef56e62016-02-27 19:18:56 +010046 set_muxconf_regs();
Aneesh V469ec1e2011-07-21 09:10:01 -040047 break;
48 }
49}
50
Sricharan508a58f2011-11-15 09:49:55 -050051u32 cortex_rev(void)
Aneesh Vad577c82011-07-21 09:10:04 -040052{
53
54 unsigned int rev;
55
56 /* Read Main ID Register (MIDR) */
57 asm ("mrc p15, 0, %0, c0, c0, 0" : "=r" (rev));
58
59 return rev;
60}
61
Tom Rini0ac6db22013-05-31 10:44:23 -040062static void omap_rev_string(void)
Aneesh Vad577c82011-07-21 09:10:04 -040063{
Sricharan508a58f2011-11-15 09:49:55 -050064 u32 omap_rev = omap_revision();
Lokesh Vutlade626882013-02-12 21:29:03 +000065 u32 soc_variant = (omap_rev & 0xF0000000) >> 28;
Sricharan508a58f2011-11-15 09:49:55 -050066 u32 omap_variant = (omap_rev & 0xFFFF0000) >> 16;
67 u32 major_rev = (omap_rev & 0x00000F00) >> 8;
68 u32 minor_rev = (omap_rev & 0x000000F0) >> 4;
Aneesh Vad577c82011-07-21 09:10:04 -040069
Lokesh Vutla941f2fc2017-12-29 11:47:51 +053070 const char *sec_s, *package = NULL;
Daniel Allred47c331e2016-05-19 19:10:52 -050071
72 switch (get_device_type()) {
73 case TST_DEVICE:
74 sec_s = "TST";
75 break;
76 case EMU_DEVICE:
77 sec_s = "EMU";
78 break;
79 case HS_DEVICE:
80 sec_s = "HS";
81 break;
82 case GP_DEVICE:
83 sec_s = "GP";
84 break;
85 default:
86 sec_s = "?";
87 }
88
Lokesh Vutla941f2fc2017-12-29 11:47:51 +053089#if defined(CONFIG_DRA7XX)
90 if (is_dra76x()) {
91 switch (omap_rev & 0xF) {
92 case DRA762_ABZ_PACKAGE:
93 package = "ABZ";
94 break;
95 case DRA762_ACD_PACKAGE:
96 default:
97 package = "ACD";
98 break;
99 }
100 }
101#endif
102
Lokesh Vutlade626882013-02-12 21:29:03 +0000103 if (soc_variant)
104 printf("OMAP");
105 else
106 printf("DRA");
Lokesh Vutla941f2fc2017-12-29 11:47:51 +0530107 printf("%x-%s ES%x.%x", omap_variant, sec_s, major_rev, minor_rev);
108 if (package)
109 printf(" %s package\n", package);
110 else
111 puts("\n");
Aneesh Vad577c82011-07-21 09:10:04 -0400112}
113
Sricharan78f455c2011-11-15 09:50:03 -0500114#ifdef CONFIG_SPL_BUILD
Tom Rini861a86f2012-08-13 11:37:56 -0700115void spl_display_print(void)
116{
117 omap_rev_string();
118}
Sricharan78f455c2011-11-15 09:50:03 -0500119#endif
120
Lokesh Vutlad4d986e2013-02-12 01:33:45 +0000121void __weak srcomp_enable(void)
122{
123}
124
Kipisz, Stevend88d6c82016-02-24 12:30:57 -0600125/**
126 * do_board_detect() - Detect board description
127 *
128 * Function to detect board description. This is expected to be
129 * overridden in the SoC family board file where desired.
130 */
131void __weak do_board_detect(void)
132{
133}
134
Keerthy61462cd2016-05-24 11:45:05 +0530135/**
136 * vcores_init() - Assign omap_vcores based on board
137 *
138 * Function to pick the vcores based on board. This is expected to be
139 * overridden in the SoC family board file where desired.
140 */
141void __weak vcores_init(void)
142{
143}
144
Lokesh Vutlae850ed82016-03-07 14:49:54 +0530145void s_init(void)
146{
147}
148
149/**
Lokesh Vutla941f2fc2017-12-29 11:47:51 +0530150 * init_package_revision() - Initialize package revision
151 *
152 * Function to get the pacakage information. This is expected to be
153 * overridden in the SoC family file where desired.
154 */
155void __weak init_package_revision(void)
156{
157}
158
159/**
Lokesh Vutlae850ed82016-03-07 14:49:54 +0530160 * early_system_init - Does Early system initialization.
161 *
162 * Does early system init of watchdog, muxing, andclocks
Aneesh V469ec1e2011-07-21 09:10:01 -0400163 * Watchdog disable is done always. For the rest what gets done
Lokesh Vutlae850ed82016-03-07 14:49:54 +0530164 * 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
Aneesh V469ec1e2011-07-21 09:10:01 -0400169 * 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.
Steve Sakomand34efc72010-06-08 13:07:46 -0700173 */
Lokesh Vutlae850ed82016-03-07 14:49:54 +0530174void early_system_init(void)
Steve Sakomand34efc72010-06-08 13:07:46 -0700175{
Jean-Jacques Hiblot40ecdbc2018-12-07 14:50:55 +0100176#if defined(CONFIG_SPL_BUILD) && defined(CONFIG_SPL_MULTI_DTB_FIT)
177 int ret;
178 int rescan;
179#endif
Sricharan508a58f2011-11-15 09:49:55 -0500180 init_omap_revision();
SRICHARAN R01b753f2013-02-04 04:22:00 +0000181 hw_data_init();
Lokesh Vutla941f2fc2017-12-29 11:47:51 +0530182 init_package_revision();
SRICHARAN R01b753f2013-02-04 04:22:00 +0000183
Lokesh Vutla38f25b12012-05-29 19:26:43 +0000184#ifdef CONFIG_SPL_BUILD
Lokesh Vutla663f6fc2016-07-12 14:47:41 +0530185 if (warm_reset())
Lokesh Vutla38f25b12012-05-29 19:26:43 +0000186 force_emif_self_refresh();
187#endif
Steve Sakomand34efc72010-06-08 13:07:46 -0700188 watchdog_init();
Aneesh V469ec1e2011-07-21 09:10:01 -0400189 set_mux_conf_regs();
Aneesh Vbcae7212011-07-21 09:10:21 -0400190#ifdef CONFIG_SPL_BUILD
Lokesh Vutlad4d986e2013-02-12 01:33:45 +0000191 srcomp_enable();
Aneesh V4ecfcfa2011-09-08 11:05:56 -0400192 do_io_settings();
Aneesh Vbcae7212011-07-21 09:10:21 -0400193#endif
Kipisz, Steven93e62532016-02-24 12:30:52 -0600194 setup_early_clocks();
Jean-Jacques Hiblot40ecdbc2018-12-07 14:50:55 +0100195
Lokesh Vutla4bd754d2017-06-27 13:50:56 +0530196#ifdef CONFIG_SPL_BUILD
197 /*
198 * Save the boot parameters passed from romcode.
199 * We cannot delay the saving further than this,
200 * to prevent overwrites.
201 */
202 save_omap_boot_params();
Jean-Jacques Hiblota4d72862017-09-15 12:57:33 +0200203 spl_early_init();
204#endif
Jean-Jacques Hiblot2b30b382018-12-07 14:50:45 +0100205 do_board_detect();
206
Jean-Jacques Hiblot40ecdbc2018-12-07 14:50:55 +0100207#if defined(CONFIG_SPL_BUILD) && defined(CONFIG_SPL_MULTI_DTB_FIT)
208 /*
209 * Board detection has been done.
210 * Let us see if another dtb wouldn't be a better match
211 * for our board
212 */
213 ret = fdtdec_resetup(&rescan);
214 if (!ret && rescan) {
215 dm_uninit();
216 dm_init_and_scan(true);
217 }
218#endif
219
Keerthy61462cd2016-05-24 11:45:05 +0530220 vcores_init();
Lokesh Vutla01fe1192017-05-05 13:45:27 +0530221#ifdef CONFIG_DEBUG_UART_OMAP
222 debug_uart_init();
223#endif
Aneesh V37768012011-07-21 09:10:07 -0400224 prcm_init();
Simon Glass7ae83502015-03-03 08:03:02 -0700225}
226
Aneesh Vbcae7212011-07-21 09:10:21 -0400227#ifdef CONFIG_SPL_BUILD
Simon Glass7ae83502015-03-03 08:03:02 -0700228void board_init_f(ulong dummy)
229{
Lokesh Vutlae850ed82016-03-07 14:49:54 +0530230 early_system_init();
Lokesh Vutla7b922522014-08-04 19:42:24 +0530231#ifdef CONFIG_BOARD_EARLY_INIT_F
232 board_early_init_f();
233#endif
Aneesh Vbcae7212011-07-21 09:10:21 -0400234 /* For regular u-boot sdram_init() is called from dram_init() */
235 sdram_init();
Lokesh Vutla86282792017-04-18 17:27:24 +0530236 gd->ram_size = omap_sdram_size();
Steve Sakomand34efc72010-06-08 13:07:46 -0700237}
Simon Glass7ae83502015-03-03 08:03:02 -0700238#endif
Steve Sakomand34efc72010-06-08 13:07:46 -0700239
Lokesh Vutlae850ed82016-03-07 14:49:54 +0530240int arch_cpu_init_dm(void)
241{
242 early_system_init();
243 return 0;
244}
245
Steve Sakomand34efc72010-06-08 13:07:46 -0700246/*
247 * Routine: wait_for_command_complete
248 * Description: Wait for posting to finish on watchdog
249 */
250void wait_for_command_complete(struct watchdog *wd_base)
251{
252 int pending = 1;
253 do {
254 pending = readl(&wd_base->wwps);
255 } while (pending);
256}
257
258/*
259 * Routine: watchdog_init
260 * Description: Shut down watch dogs
261 */
262void watchdog_init(void)
263{
264 struct watchdog *wd2_base = (struct watchdog *)WDT2_BASE;
265
266 writel(WD_UNLOCK1, &wd2_base->wspr);
267 wait_for_command_complete(wd2_base);
268 writel(WD_UNLOCK2, &wd2_base->wspr);
269}
270
Aneesh V7ca3f9c2010-09-12 10:32:55 +0530271
272/*
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
277 */
Sricharan508a58f2011-11-15 09:49:55 -0500278u32 omap_sdram_size(void)
Aneesh V7ca3f9c2010-09-12 10:32:55 +0530279{
SRICHARAN Re06e9142012-05-17 00:12:06 +0000280 u32 section, i, valid;
281 u64 sdram_start = 0, sdram_end = 0, addr,
Lokesh Vutlad7630da2014-05-12 13:49:33 +0530282 size, total_size = 0, trap_size = 0, trap_start = 0;
Sricharanbb772a52011-11-15 09:50:00 -0500283
Aneesh V7ca3f9c2010-09-12 10:32:55 +0530284 for (i = 0; i < 4; i++) {
Sricharanbb772a52011-11-15 09:50:00 -0500285 section = __raw_readl(DMM_BASE + i*4);
SRICHARAN Re06e9142012-05-17 00:12:06 +0000286 valid = (section & EMIF_SDRC_ADDRSPC_MASK) >>
287 (EMIF_SDRC_ADDRSPC_SHIFT);
Sricharanbb772a52011-11-15 09:50:00 -0500288 addr = section & EMIF_SYS_ADDR_MASK;
SRICHARAN Re06e9142012-05-17 00:12:06 +0000289
Aneesh V7ca3f9c2010-09-12 10:32:55 +0530290 /* See if the address is valid */
Tom Rini939911a2014-05-16 13:02:24 -0400291 if ((addr >= TI_ARMV7_DRAM_ADDR_SPACE_START) &&
292 (addr < TI_ARMV7_DRAM_ADDR_SPACE_END)) {
Sricharanbb772a52011-11-15 09:50:00 -0500293 size = ((section & EMIF_SYS_SIZE_MASK) >>
294 EMIF_SYS_SIZE_SHIFT);
295 size = 1 << size;
296 size *= SZ_16M;
SRICHARAN Re06e9142012-05-17 00:12:06 +0000297
298 if (valid != DMM_SDRC_ADDR_SPC_INVALID) {
299 if (!sdram_start || (addr < sdram_start))
300 sdram_start = addr;
301 if (!sdram_end || ((addr + size) > sdram_end))
302 sdram_end = addr + size;
303 } else {
304 trap_size = size;
Lokesh Vutlad7630da2014-05-12 13:49:33 +0530305 trap_start = addr;
SRICHARAN Re06e9142012-05-17 00:12:06 +0000306 }
Aneesh V7ca3f9c2010-09-12 10:32:55 +0530307 }
308 }
Lokesh Vutlad7630da2014-05-12 13:49:33 +0530309
310 if ((trap_start >= sdram_start) && (trap_start < sdram_end))
311 total_size = (sdram_end - sdram_start) - (trap_size);
312 else
313 total_size = sdram_end - sdram_start;
Sricharanbb772a52011-11-15 09:50:00 -0500314
Aneesh V7ca3f9c2010-09-12 10:32:55 +0530315 return total_size;
316}
317
318
Steve Sakomand34efc72010-06-08 13:07:46 -0700319/*
320 * Routine: dram_init
321 * Description: sets uboots idea of sdram size
322 */
323int dram_init(void)
324{
Aneesh V2ae610f2011-07-21 09:10:09 -0400325 sdram_init();
Sricharan508a58f2011-11-15 09:49:55 -0500326 gd->ram_size = omap_sdram_size();
Steve Sakomand34efc72010-06-08 13:07:46 -0700327 return 0;
328}
329
330/*
331 * Print board information
332 */
333int checkboard(void)
334{
335 puts(sysinfo.board_string);
336 return 0;
337}
338
Masahiro Yamada365475e2014-02-13 18:30:26 +0900339#if defined(CONFIG_DISPLAY_CPUINFO)
Sricharan508a58f2011-11-15 09:49:55 -0500340/*
341 * Print CPU information
342 */
343int print_cpuinfo(void)
Aneesh V8b457fa2011-06-16 23:30:52 +0000344{
Andreas Müller761ca312012-01-04 15:26:24 +0000345 puts("CPU : ");
346 omap_rev_string();
Sricharan508a58f2011-11-15 09:49:55 -0500347
348 return 0;
349}
Masahiro Yamada365475e2014-02-13 18:30:26 +0900350#endif