blob: 85d375432f95b89071852acccb7a328b4a725903 [file] [log] [blame]
Steve Sakoman1ad21582010-06-08 13:07:46 -07001/*
2 *
Sricharan9310ff72011-11-15 09:49:55 -05003 * Common functions for OMAP4/5 based boards
Steve Sakoman1ad21582010-06-08 13:07:46 -07004 *
5 * (C) Copyright 2010
6 * Texas Instruments, <www.ti.com>
7 *
8 * Author :
9 * Aneesh V <aneesh@ti.com>
10 * Steve Sakoman <steve@sakoman.com>
11 *
Wolfgang Denkd79de1d2013-07-08 09:37:19 +020012 * SPDX-License-Identifier: GPL-2.0+
Steve Sakoman1ad21582010-06-08 13:07:46 -070013 */
14#include <common.h>
Tom Rini28591df2012-08-13 12:03:19 -070015#include <spl.h>
Steve Sakoman1ad21582010-06-08 13:07:46 -070016#include <asm/arch/sys_proto.h>
Aneesh V04bd2b92010-09-12 10:32:55 +053017#include <asm/sizes.h>
Sricharan62a86502011-11-15 09:50:00 -050018#include <asm/emif.h>
SRICHARAN Rfb6aa1f2013-02-04 04:22:00 +000019#include <asm/omap_common.h>
Lokesh Vutla28049632013-02-12 01:33:45 +000020#include <linux/compiler.h>
R Sricharan06396c12013-03-04 20:04:45 +000021#include <asm/cache.h>
22#include <asm/system.h>
23
24#define ARMV7_DCACHE_WRITEBACK 0xe
25#define ARMV7_DOMAIN_CLIENT 1
26#define ARMV7_DOMAIN_MASK (0x3 << 0)
Steve Sakoman1ad21582010-06-08 13:07:46 -070027
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:
43 set_muxconf_regs_essential();
44 break;
45 case OMAP_INIT_CONTEXT_UBOOT_AFTER_SPL:
Sricharan308fe922011-11-15 09:50:03 -050046#ifdef CONFIG_SYS_ENABLE_PADS_ALL
Aneesh Vf908b632011-07-21 09:10:01 -040047 set_muxconf_regs_non_essential();
Sricharan308fe922011-11-15 09:50:03 -050048#endif
Aneesh Vf908b632011-07-21 09:10:01 -040049 break;
50 case OMAP_INIT_CONTEXT_UBOOT_FROM_NOR:
51 case OMAP_INIT_CONTEXT_UBOOT_AFTER_CH:
52 set_muxconf_regs_essential();
Sricharan308fe922011-11-15 09:50:03 -050053#ifdef CONFIG_SYS_ENABLE_PADS_ALL
Aneesh Vf908b632011-07-21 09:10:01 -040054 set_muxconf_regs_non_essential();
Sricharan308fe922011-11-15 09:50:03 -050055#endif
Aneesh Vf908b632011-07-21 09:10:01 -040056 break;
57 }
58}
59
Sricharan9310ff72011-11-15 09:49:55 -050060u32 cortex_rev(void)
Aneesh V162ced32011-07-21 09:10:04 -040061{
62
63 unsigned int rev;
64
65 /* Read Main ID Register (MIDR) */
66 asm ("mrc p15, 0, %0, c0, c0, 0" : "=r" (rev));
67
68 return rev;
69}
70
Tom Rini01b2dd92013-05-31 10:44:23 -040071static void omap_rev_string(void)
Aneesh V162ced32011-07-21 09:10:04 -040072{
Sricharan9310ff72011-11-15 09:49:55 -050073 u32 omap_rev = omap_revision();
Lokesh Vutla43c296f2013-02-12 21:29:03 +000074 u32 soc_variant = (omap_rev & 0xF0000000) >> 28;
Sricharan9310ff72011-11-15 09:49:55 -050075 u32 omap_variant = (omap_rev & 0xFFFF0000) >> 16;
76 u32 major_rev = (omap_rev & 0x00000F00) >> 8;
77 u32 minor_rev = (omap_rev & 0x000000F0) >> 4;
Aneesh V162ced32011-07-21 09:10:04 -040078
Lokesh Vutla43c296f2013-02-12 21:29:03 +000079 if (soc_variant)
80 printf("OMAP");
81 else
82 printf("DRA");
83 printf("%x ES%x.%x\n", omap_variant, major_rev,
84 minor_rev);
Aneesh V162ced32011-07-21 09:10:04 -040085}
86
Sricharan308fe922011-11-15 09:50:03 -050087#ifdef CONFIG_SPL_BUILD
Tom Rinife3b0c72012-08-13 11:37:56 -070088void spl_display_print(void)
89{
90 omap_rev_string();
91}
Sricharan308fe922011-11-15 09:50:03 -050092#endif
93
Lokesh Vutla28049632013-02-12 01:33:45 +000094void __weak srcomp_enable(void)
95{
SRICHARAN R4af19882013-04-24 00:41:23 +000096}
97
SRICHARAN R669b3372013-04-24 00:41:25 +000098#ifdef CONFIG_ARCH_CPU_INIT
99/*
100 * SOC specific cpu init
101 */
102int arch_cpu_init(void)
103{
104 save_omap_boot_params();
105 return 0;
106}
107#endif /* CONFIG_ARCH_CPU_INIT */
108
Steve Sakoman1ad21582010-06-08 13:07:46 -0700109/*
110 * Routine: s_init
Aneesh Vf908b632011-07-21 09:10:01 -0400111 * Description: Does early system init of watchdog, muxing, andclocks
112 * Watchdog disable is done always. For the rest what gets done
113 * depends on the boot mode in which this function is executed
114 * 1. s_init of SPL running from SRAM
115 * 2. s_init of U-Boot running from FLASH
116 * 3. s_init of U-Boot loaded to SDRAM by SPL
117 * 4. s_init of U-Boot loaded to SDRAM by ROM code using the
118 * Configuration Header feature
119 * Please have a look at the respective functions to see what gets
120 * done in each of these cases
121 * This function is called with SRAM stack.
Steve Sakoman1ad21582010-06-08 13:07:46 -0700122 */
123void s_init(void)
124{
SRICHARAN R4af19882013-04-24 00:41:23 +0000125 /*
126 * Save the boot parameters passed from romcode.
127 * We cannot delay the saving further than this,
128 * to prevent overwrites.
129 */
130#ifdef CONFIG_SPL_BUILD
131 save_omap_boot_params();
132#endif
Sricharan9310ff72011-11-15 09:49:55 -0500133 init_omap_revision();
SRICHARAN Rfb6aa1f2013-02-04 04:22:00 +0000134 hw_data_init();
135
Lokesh Vutlaba873772012-05-29 19:26:43 +0000136#ifdef CONFIG_SPL_BUILD
137 if (warm_reset() && (omap_revision() <= OMAP5430_ES1_0))
138 force_emif_self_refresh();
139#endif
Steve Sakoman1ad21582010-06-08 13:07:46 -0700140 watchdog_init();
Aneesh Vf908b632011-07-21 09:10:01 -0400141 set_mux_conf_regs();
Aneesh Vb8e60b92011-07-21 09:10:21 -0400142#ifdef CONFIG_SPL_BUILD
Lokesh Vutla28049632013-02-12 01:33:45 +0000143 srcomp_enable();
Simon Schwarz01a43322011-09-14 15:14:46 -0400144 setup_clocks_for_console();
Tom Rini31dfba42012-08-22 15:31:05 -0700145
146 gd = &gdata;
147
Aneesh Vb8e60b92011-07-21 09:10:21 -0400148 preloader_console_init();
Aneesh Vb35f7cb2011-09-08 11:05:56 -0400149 do_io_settings();
Aneesh Vb8e60b92011-07-21 09:10:21 -0400150#endif
Aneesh V0d2628b2011-07-21 09:10:07 -0400151 prcm_init();
Aneesh Vb8e60b92011-07-21 09:10:21 -0400152#ifdef CONFIG_SPL_BUILD
153 /* For regular u-boot sdram_init() is called from dram_init() */
154 sdram_init();
155#endif
Steve Sakoman1ad21582010-06-08 13:07:46 -0700156}
157
158/*
159 * Routine: wait_for_command_complete
160 * Description: Wait for posting to finish on watchdog
161 */
162void wait_for_command_complete(struct watchdog *wd_base)
163{
164 int pending = 1;
165 do {
166 pending = readl(&wd_base->wwps);
167 } while (pending);
168}
169
170/*
171 * Routine: watchdog_init
172 * Description: Shut down watch dogs
173 */
174void watchdog_init(void)
175{
176 struct watchdog *wd2_base = (struct watchdog *)WDT2_BASE;
177
178 writel(WD_UNLOCK1, &wd2_base->wspr);
179 wait_for_command_complete(wd2_base);
180 writel(WD_UNLOCK2, &wd2_base->wspr);
181}
182
Aneesh V04bd2b92010-09-12 10:32:55 +0530183
184/*
185 * This function finds the SDRAM size available in the system
186 * based on DMM section configurations
187 * This is needed because the size of memory installed may be
188 * different on different versions of the board
189 */
Sricharan9310ff72011-11-15 09:49:55 -0500190u32 omap_sdram_size(void)
Aneesh V04bd2b92010-09-12 10:32:55 +0530191{
SRICHARAN R015be792012-05-17 00:12:06 +0000192 u32 section, i, valid;
193 u64 sdram_start = 0, sdram_end = 0, addr,
194 size, total_size = 0, trap_size = 0;
Sricharan62a86502011-11-15 09:50:00 -0500195
Aneesh V04bd2b92010-09-12 10:32:55 +0530196 for (i = 0; i < 4; i++) {
Sricharan62a86502011-11-15 09:50:00 -0500197 section = __raw_readl(DMM_BASE + i*4);
SRICHARAN R015be792012-05-17 00:12:06 +0000198 valid = (section & EMIF_SDRC_ADDRSPC_MASK) >>
199 (EMIF_SDRC_ADDRSPC_SHIFT);
Sricharan62a86502011-11-15 09:50:00 -0500200 addr = section & EMIF_SYS_ADDR_MASK;
SRICHARAN R015be792012-05-17 00:12:06 +0000201
Aneesh V04bd2b92010-09-12 10:32:55 +0530202 /* See if the address is valid */
Sricharan62a86502011-11-15 09:50:00 -0500203 if ((addr >= DRAM_ADDR_SPACE_START) &&
204 (addr < DRAM_ADDR_SPACE_END)) {
205 size = ((section & EMIF_SYS_SIZE_MASK) >>
206 EMIF_SYS_SIZE_SHIFT);
207 size = 1 << size;
208 size *= SZ_16M;
SRICHARAN R015be792012-05-17 00:12:06 +0000209
210 if (valid != DMM_SDRC_ADDR_SPC_INVALID) {
211 if (!sdram_start || (addr < sdram_start))
212 sdram_start = addr;
213 if (!sdram_end || ((addr + size) > sdram_end))
214 sdram_end = addr + size;
215 } else {
216 trap_size = size;
217 }
218
Aneesh V04bd2b92010-09-12 10:32:55 +0530219 }
SRICHARAN R015be792012-05-17 00:12:06 +0000220
Aneesh V04bd2b92010-09-12 10:32:55 +0530221 }
SRICHARAN R015be792012-05-17 00:12:06 +0000222 total_size = (sdram_end - sdram_start) - (trap_size);
Sricharan62a86502011-11-15 09:50:00 -0500223
Aneesh V04bd2b92010-09-12 10:32:55 +0530224 return total_size;
225}
226
227
Steve Sakoman1ad21582010-06-08 13:07:46 -0700228/*
229 * Routine: dram_init
230 * Description: sets uboots idea of sdram size
231 */
232int dram_init(void)
233{
Aneesh Vcc565582011-07-21 09:10:09 -0400234 sdram_init();
Sricharan9310ff72011-11-15 09:49:55 -0500235 gd->ram_size = omap_sdram_size();
Steve Sakoman1ad21582010-06-08 13:07:46 -0700236 return 0;
237}
238
239/*
240 * Print board information
241 */
242int checkboard(void)
243{
244 puts(sysinfo.board_string);
245 return 0;
246}
247
Steve Sakoman9bb65b52010-07-15 13:43:10 -0700248/*
Sricharan9310ff72011-11-15 09:49:55 -0500249 * get_device_type(): tell if GP/HS/EMU/TST
250 */
251u32 get_device_type(void)
Aneesh Ve3405bd2011-06-16 23:30:52 +0000252{
Lokesh Vutla834b6b02013-02-04 04:22:04 +0000253 return (readl((*ctrl)->control_status) &
SRICHARAN R36c366f2012-03-12 02:25:43 +0000254 (DEVICE_TYPE_MASK)) >> DEVICE_TYPE_SHIFT;
Aneesh Ve3405bd2011-06-16 23:30:52 +0000255}
256
Sricharan9310ff72011-11-15 09:49:55 -0500257/*
258 * Print CPU information
259 */
260int print_cpuinfo(void)
Aneesh Ve3405bd2011-06-16 23:30:52 +0000261{
Andreas Müller0cda7a42012-01-04 15:26:24 +0000262 puts("CPU : ");
263 omap_rev_string();
Sricharan9310ff72011-11-15 09:49:55 -0500264
265 return 0;
266}
Aneesh V572134b2011-08-11 04:35:43 +0000267#ifndef CONFIG_SYS_DCACHE_OFF
268void enable_caches(void)
269{
270 /* Enable D-cache. I-cache is already enabled in start.S */
271 dcache_enable();
272}
R Sricharan06396c12013-03-04 20:04:45 +0000273
274void dram_bank_mmu_setup(int bank)
275{
276 bd_t *bd = gd->bd;
277 int i;
278
279 u32 start = bd->bi_dram[bank].start >> 20;
280 u32 size = bd->bi_dram[bank].size >> 20;
281 u32 end = start + size;
282
283 debug("%s: bank: %d\n", __func__, bank);
284 for (i = start; i < end; i++)
285 set_section_dcache(i, ARMV7_DCACHE_WRITEBACK);
286
287}
288
289void arm_init_domains(void)
290{
291 u32 reg;
292
293 reg = get_dacr();
294 /*
295 * Set DOMAIN to client access so that all permissions
296 * set in pagetables are validated by the mmu.
297 */
298 reg &= ~ARMV7_DOMAIN_MASK;
299 reg |= ARMV7_DOMAIN_CLIENT;
300 set_dacr(reg);
301}
Aneesh V572134b2011-08-11 04:35:43 +0000302#endif