blob: 7a7086776ee09cf65772f09bec314c08d8fed7d7 [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>
Jean-Jacques Hiblot651201b2018-12-07 14:50:55 +010015#include <fdtdec.h>
Simon Glass97589732020-05-10 11:40:02 -060016#include <init.h>
Tom Rini28591df2012-08-13 12:03:19 -070017#include <spl.h>
Steve Sakoman1ad21582010-06-08 13:07:46 -070018#include <asm/arch/sys_proto.h>
Alexey Brodkin267d8e22014-02-26 17:47:58 +040019#include <linux/sizes.h>
Sricharan62a86502011-11-15 09:50:00 -050020#include <asm/emif.h>
SRICHARAN Rfb6aa1f2013-02-04 04:22:00 +000021#include <asm/omap_common.h>
Lokesh Vutla28049632013-02-12 01:33:45 +000022#include <linux/compiler.h>
R Sricharan06396c12013-03-04 20:04:45 +000023#include <asm/system.h>
Jean-Jacques Hiblot651201b2018-12-07 14:50:55 +010024#include <dm/root.h>
R Sricharan06396c12013-03-04 20:04:45 +000025
Nishanth Menon4e5dd662010-11-19 11:19:40 -050026DECLARE_GLOBAL_DATA_PTR;
27
Aneesh Vf908b632011-07-21 09:10:01 -040028void do_set_mux(u32 base, struct pad_conf_entry const *array, int size)
29{
30 int i;
31 struct pad_conf_entry *pad = (struct pad_conf_entry *) array;
32
33 for (i = 0; i < size; i++, pad++)
34 writew(pad->val, base + pad->offset);
35}
36
Aneesh Vf908b632011-07-21 09:10:01 -040037static void set_mux_conf_regs(void)
38{
Sricharan9310ff72011-11-15 09:49:55 -050039 switch (omap_hw_init_context()) {
Aneesh Vf908b632011-07-21 09:10:01 -040040 case OMAP_INIT_CONTEXT_SPL:
Paul Kocialkowskia00b1e52016-02-27 19:18:56 +010041 set_muxconf_regs();
Aneesh Vf908b632011-07-21 09:10:01 -040042 break;
43 case OMAP_INIT_CONTEXT_UBOOT_AFTER_SPL:
Aneesh Vf908b632011-07-21 09:10:01 -040044 break;
45 case OMAP_INIT_CONTEXT_UBOOT_FROM_NOR:
46 case OMAP_INIT_CONTEXT_UBOOT_AFTER_CH:
Paul Kocialkowskia00b1e52016-02-27 19:18:56 +010047 set_muxconf_regs();
Aneesh Vf908b632011-07-21 09:10:01 -040048 break;
49 }
50}
51
Sricharan9310ff72011-11-15 09:49:55 -050052u32 cortex_rev(void)
Aneesh V162ced32011-07-21 09:10:04 -040053{
54
55 unsigned int rev;
56
57 /* Read Main ID Register (MIDR) */
58 asm ("mrc p15, 0, %0, c0, c0, 0" : "=r" (rev));
59
60 return rev;
61}
62
Tom Rini01b2dd92013-05-31 10:44:23 -040063static void omap_rev_string(void)
Aneesh V162ced32011-07-21 09:10:04 -040064{
Sricharan9310ff72011-11-15 09:49:55 -050065 u32 omap_rev = omap_revision();
Lokesh Vutla43c296f2013-02-12 21:29:03 +000066 u32 soc_variant = (omap_rev & 0xF0000000) >> 28;
Sricharan9310ff72011-11-15 09:49:55 -050067 u32 omap_variant = (omap_rev & 0xFFFF0000) >> 16;
68 u32 major_rev = (omap_rev & 0x00000F00) >> 8;
69 u32 minor_rev = (omap_rev & 0x000000F0) >> 4;
Aneesh V162ced32011-07-21 09:10:04 -040070
Lokesh Vutla69483e62017-12-29 11:47:51 +053071 const char *sec_s, *package = NULL;
Daniel Allredfd684b22016-05-19 19:10:52 -050072
73 switch (get_device_type()) {
74 case TST_DEVICE:
75 sec_s = "TST";
76 break;
77 case EMU_DEVICE:
78 sec_s = "EMU";
79 break;
80 case HS_DEVICE:
81 sec_s = "HS";
82 break;
83 case GP_DEVICE:
84 sec_s = "GP";
85 break;
86 default:
87 sec_s = "?";
88 }
89
Lokesh Vutla69483e62017-12-29 11:47:51 +053090#if defined(CONFIG_DRA7XX)
91 if (is_dra76x()) {
92 switch (omap_rev & 0xF) {
93 case DRA762_ABZ_PACKAGE:
94 package = "ABZ";
95 break;
96 case DRA762_ACD_PACKAGE:
97 default:
98 package = "ACD";
99 break;
100 }
101 }
102#endif
103
Lokesh Vutla43c296f2013-02-12 21:29:03 +0000104 if (soc_variant)
105 printf("OMAP");
106 else
107 printf("DRA");
Lokesh Vutla69483e62017-12-29 11:47:51 +0530108 printf("%x-%s ES%x.%x", omap_variant, sec_s, major_rev, minor_rev);
109 if (package)
110 printf(" %s package\n", package);
111 else
112 puts("\n");
Aneesh V162ced32011-07-21 09:10:04 -0400113}
114
Sricharan308fe922011-11-15 09:50:03 -0500115#ifdef CONFIG_SPL_BUILD
Tom Rinife3b0c72012-08-13 11:37:56 -0700116void spl_display_print(void)
117{
118 omap_rev_string();
119}
Sricharan308fe922011-11-15 09:50:03 -0500120#endif
121
Lokesh Vutla28049632013-02-12 01:33:45 +0000122void __weak srcomp_enable(void)
123{
SRICHARAN R4af19882013-04-24 00:41:23 +0000124}
125
Kipisz, Steven4466dfb2016-02-24 12:30:57 -0600126/**
127 * do_board_detect() - Detect board description
128 *
129 * Function to detect board description. This is expected to be
130 * overridden in the SoC family board file where desired.
131 */
132void __weak do_board_detect(void)
133{
134}
135
Keerthy35740ec2016-05-24 11:45:05 +0530136/**
137 * vcores_init() - Assign omap_vcores based on board
138 *
139 * Function to pick the vcores based on board. This is expected to be
140 * overridden in the SoC family board file where desired.
141 */
142void __weak vcores_init(void)
143{
144}
145
Lokesh Vutlae8534d22016-03-07 14:49:54 +0530146void s_init(void)
147{
148}
149
150/**
Lokesh Vutla69483e62017-12-29 11:47:51 +0530151 * init_package_revision() - Initialize package revision
152 *
153 * Function to get the pacakage information. This is expected to be
154 * overridden in the SoC family file where desired.
155 */
156void __weak init_package_revision(void)
157{
158}
159
160/**
Lokesh Vutlae8534d22016-03-07 14:49:54 +0530161 * early_system_init - Does Early system initialization.
162 *
163 * Does early system init of watchdog, muxing, andclocks
Aneesh Vf908b632011-07-21 09:10:01 -0400164 * Watchdog disable is done always. For the rest what gets done
Lokesh Vutlae8534d22016-03-07 14:49:54 +0530165 * 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
Aneesh Vf908b632011-07-21 09:10:01 -0400170 * 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.
Steve Sakoman1ad21582010-06-08 13:07:46 -0700174 */
Lokesh Vutlae8534d22016-03-07 14:49:54 +0530175void early_system_init(void)
Steve Sakoman1ad21582010-06-08 13:07:46 -0700176{
Jean-Jacques Hiblot651201b2018-12-07 14:50:55 +0100177#if defined(CONFIG_SPL_BUILD) && defined(CONFIG_SPL_MULTI_DTB_FIT)
178 int ret;
179 int rescan;
180#endif
Sricharan9310ff72011-11-15 09:49:55 -0500181 init_omap_revision();
SRICHARAN Rfb6aa1f2013-02-04 04:22:00 +0000182 hw_data_init();
Lokesh Vutla69483e62017-12-29 11:47:51 +0530183 init_package_revision();
SRICHARAN Rfb6aa1f2013-02-04 04:22:00 +0000184
Lokesh Vutlaba873772012-05-29 19:26:43 +0000185#ifdef CONFIG_SPL_BUILD
Lokesh Vutlae38b45a2016-07-12 14:47:41 +0530186 if (warm_reset())
Lokesh Vutlaba873772012-05-29 19:26:43 +0000187 force_emif_self_refresh();
188#endif
Steve Sakoman1ad21582010-06-08 13:07:46 -0700189 watchdog_init();
Aneesh Vf908b632011-07-21 09:10:01 -0400190 set_mux_conf_regs();
Aneesh Vb8e60b92011-07-21 09:10:21 -0400191#ifdef CONFIG_SPL_BUILD
Lokesh Vutla28049632013-02-12 01:33:45 +0000192 srcomp_enable();
Aneesh Vb35f7cb2011-09-08 11:05:56 -0400193 do_io_settings();
Aneesh Vb8e60b92011-07-21 09:10:21 -0400194#endif
Kipisz, Stevenebe86dc2016-02-24 12:30:52 -0600195 setup_early_clocks();
Jean-Jacques Hiblot651201b2018-12-07 14:50:55 +0100196
Lokesh Vutlaca23da12017-06-27 13:50:56 +0530197#ifdef CONFIG_SPL_BUILD
198 /*
199 * Save the boot parameters passed from romcode.
200 * We cannot delay the saving further than this,
201 * to prevent overwrites.
202 */
203 save_omap_boot_params();
Jean-Jacques Hiblota68ca9e2017-09-15 12:57:33 +0200204 spl_early_init();
205#endif
Jean-Jacques Hiblot3a502f62018-12-07 14:50:45 +0100206 do_board_detect();
207
Jean-Jacques Hiblot651201b2018-12-07 14:50:55 +0100208#if defined(CONFIG_SPL_BUILD) && defined(CONFIG_SPL_MULTI_DTB_FIT)
209 /*
210 * Board detection has been done.
211 * Let us see if another dtb wouldn't be a better match
212 * for our board
213 */
214 ret = fdtdec_resetup(&rescan);
215 if (!ret && rescan) {
216 dm_uninit();
217 dm_init_and_scan(true);
218 }
219#endif
220
Keerthy35740ec2016-05-24 11:45:05 +0530221 vcores_init();
Lokesh Vutlaac8bd3c2017-05-05 13:45:27 +0530222#ifdef CONFIG_DEBUG_UART_OMAP
223 debug_uart_init();
224#endif
Aneesh V0d2628b2011-07-21 09:10:07 -0400225 prcm_init();
Simon Glass0c078ea2015-03-03 08:03:02 -0700226}
227
Aneesh Vb8e60b92011-07-21 09:10:21 -0400228#ifdef CONFIG_SPL_BUILD
Simon Glass0c078ea2015-03-03 08:03:02 -0700229void board_init_f(ulong dummy)
230{
Lokesh Vutlae8534d22016-03-07 14:49:54 +0530231 early_system_init();
Lokesh Vutlabe86f0e2014-08-04 19:42:24 +0530232#ifdef CONFIG_BOARD_EARLY_INIT_F
233 board_early_init_f();
234#endif
Aneesh Vb8e60b92011-07-21 09:10:21 -0400235 /* For regular u-boot sdram_init() is called from dram_init() */
236 sdram_init();
Lokesh Vutlabed46ef2017-04-18 17:27:24 +0530237 gd->ram_size = omap_sdram_size();
Steve Sakoman1ad21582010-06-08 13:07:46 -0700238}
Simon Glass0c078ea2015-03-03 08:03:02 -0700239#endif
Steve Sakoman1ad21582010-06-08 13:07:46 -0700240
Lokesh Vutlae8534d22016-03-07 14:49:54 +0530241int arch_cpu_init_dm(void)
242{
243 early_system_init();
244 return 0;
245}
246
Steve Sakoman1ad21582010-06-08 13:07:46 -0700247/*
248 * Routine: wait_for_command_complete
249 * Description: Wait for posting to finish on watchdog
250 */
251void wait_for_command_complete(struct watchdog *wd_base)
252{
253 int pending = 1;
254 do {
255 pending = readl(&wd_base->wwps);
256 } while (pending);
257}
258
259/*
260 * Routine: watchdog_init
261 * Description: Shut down watch dogs
262 */
263void watchdog_init(void)
264{
265 struct watchdog *wd2_base = (struct watchdog *)WDT2_BASE;
266
267 writel(WD_UNLOCK1, &wd2_base->wspr);
268 wait_for_command_complete(wd2_base);
269 writel(WD_UNLOCK2, &wd2_base->wspr);
270}
271
Aneesh V04bd2b92010-09-12 10:32:55 +0530272
273/*
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
278 */
Sricharan9310ff72011-11-15 09:49:55 -0500279u32 omap_sdram_size(void)
Aneesh V04bd2b92010-09-12 10:32:55 +0530280{
SRICHARAN R015be792012-05-17 00:12:06 +0000281 u32 section, i, valid;
282 u64 sdram_start = 0, sdram_end = 0, addr,
Lokesh Vutlae45d3bb2014-05-12 13:49:33 +0530283 size, total_size = 0, trap_size = 0, trap_start = 0;
Sricharan62a86502011-11-15 09:50:00 -0500284
Aneesh V04bd2b92010-09-12 10:32:55 +0530285 for (i = 0; i < 4; i++) {
Sricharan62a86502011-11-15 09:50:00 -0500286 section = __raw_readl(DMM_BASE + i*4);
SRICHARAN R015be792012-05-17 00:12:06 +0000287 valid = (section & EMIF_SDRC_ADDRSPC_MASK) >>
288 (EMIF_SDRC_ADDRSPC_SHIFT);
Sricharan62a86502011-11-15 09:50:00 -0500289 addr = section & EMIF_SYS_ADDR_MASK;
SRICHARAN R015be792012-05-17 00:12:06 +0000290
Aneesh V04bd2b92010-09-12 10:32:55 +0530291 /* See if the address is valid */
Tom Rini72f36002014-05-16 13:02:24 -0400292 if ((addr >= TI_ARMV7_DRAM_ADDR_SPACE_START) &&
293 (addr < TI_ARMV7_DRAM_ADDR_SPACE_END)) {
Sricharan62a86502011-11-15 09:50:00 -0500294 size = ((section & EMIF_SYS_SIZE_MASK) >>
295 EMIF_SYS_SIZE_SHIFT);
296 size = 1 << size;
297 size *= SZ_16M;
SRICHARAN R015be792012-05-17 00:12:06 +0000298
299 if (valid != DMM_SDRC_ADDR_SPC_INVALID) {
300 if (!sdram_start || (addr < sdram_start))
301 sdram_start = addr;
302 if (!sdram_end || ((addr + size) > sdram_end))
303 sdram_end = addr + size;
304 } else {
305 trap_size = size;
Lokesh Vutlae45d3bb2014-05-12 13:49:33 +0530306 trap_start = addr;
SRICHARAN R015be792012-05-17 00:12:06 +0000307 }
Aneesh V04bd2b92010-09-12 10:32:55 +0530308 }
309 }
Lokesh Vutlae45d3bb2014-05-12 13:49:33 +0530310
311 if ((trap_start >= sdram_start) && (trap_start < sdram_end))
312 total_size = (sdram_end - sdram_start) - (trap_size);
313 else
314 total_size = sdram_end - sdram_start;
Sricharan62a86502011-11-15 09:50:00 -0500315
Aneesh V04bd2b92010-09-12 10:32:55 +0530316 return total_size;
317}
318
319
Steve Sakoman1ad21582010-06-08 13:07:46 -0700320/*
321 * Routine: dram_init
322 * Description: sets uboots idea of sdram size
323 */
324int dram_init(void)
325{
Aneesh Vcc565582011-07-21 09:10:09 -0400326 sdram_init();
Sricharan9310ff72011-11-15 09:49:55 -0500327 gd->ram_size = omap_sdram_size();
Steve Sakoman1ad21582010-06-08 13:07:46 -0700328 return 0;
329}
330
331/*
332 * Print board information
333 */
334int checkboard(void)
335{
336 puts(sysinfo.board_string);
337 return 0;
338}
339
Masahiro Yamada81a689e2014-02-13 18:30:26 +0900340#if defined(CONFIG_DISPLAY_CPUINFO)
Sricharan9310ff72011-11-15 09:49:55 -0500341/*
342 * Print CPU information
343 */
344int print_cpuinfo(void)
Aneesh Ve3405bd2011-06-16 23:30:52 +0000345{
Andreas Müller0cda7a42012-01-04 15:26:24 +0000346 puts("CPU : ");
347 omap_rev_string();
Sricharan9310ff72011-11-15 09:49:55 -0500348
349 return 0;
350}
Masahiro Yamada81a689e2014-02-13 18:30:26 +0900351#endif