blob: 09861a99f588fba829e9d011403e676828c561b8 [file] [log] [blame]
Steve Sakoman1ad21582010-06-08 13:07:46 -07001/*
2 *
3 * Common functions for OMAP4 based boards
4 *
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 *
12 * See file CREDITS for list of people who contributed to this
13 * project.
14 *
15 * This program is free software; you can redistribute it and/or
16 * modify it under the terms of the GNU General Public License as
17 * published by the Free Software Foundation; either version 2 of
18 * the License, or (at your option) any later version.
19 *
20 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * You should have received a copy of the GNU General Public License
26 * along with this program; if not, write to the Free Software
27 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
28 * MA 02111-1307 USA
29 */
30#include <common.h>
Aneesh V162ced32011-07-21 09:10:04 -040031#include <asm/armv7.h>
Steve Sakoman1ad21582010-06-08 13:07:46 -070032#include <asm/arch/cpu.h>
33#include <asm/arch/sys_proto.h>
Aneesh V04bd2b92010-09-12 10:32:55 +053034#include <asm/sizes.h>
Aneesh Vf908b632011-07-21 09:10:01 -040035#include "omap4_mux_data.h"
Steve Sakoman1ad21582010-06-08 13:07:46 -070036
Nishanth Menon4e5dd662010-11-19 11:19:40 -050037DECLARE_GLOBAL_DATA_PTR;
38
Aneesh V162ced32011-07-21 09:10:04 -040039u32 *const omap4_revision = (u32 *)OMAP4_SRAM_SCRATCH_OMAP4_REV;
40
Aneesh Vf908b632011-07-21 09:10:01 -040041void do_set_mux(u32 base, struct pad_conf_entry const *array, int size)
42{
43 int i;
44 struct pad_conf_entry *pad = (struct pad_conf_entry *) array;
45
46 for (i = 0; i < size; i++, pad++)
47 writew(pad->val, base + pad->offset);
48}
49
50static void set_muxconf_regs_essential(void)
51{
52 do_set_mux(CONTROL_PADCONF_CORE, core_padconf_array_essential,
53 sizeof(core_padconf_array_essential) /
54 sizeof(struct pad_conf_entry));
55
56 do_set_mux(CONTROL_PADCONF_WKUP, wkup_padconf_array_essential,
57 sizeof(wkup_padconf_array_essential) /
58 sizeof(struct pad_conf_entry));
59}
60
61static void set_mux_conf_regs(void)
62{
63 switch (omap4_hw_init_context()) {
64 case OMAP_INIT_CONTEXT_SPL:
65 set_muxconf_regs_essential();
66 break;
67 case OMAP_INIT_CONTEXT_UBOOT_AFTER_SPL:
68 set_muxconf_regs_non_essential();
69 break;
70 case OMAP_INIT_CONTEXT_UBOOT_FROM_NOR:
71 case OMAP_INIT_CONTEXT_UBOOT_AFTER_CH:
72 set_muxconf_regs_essential();
73 set_muxconf_regs_non_essential();
74 break;
75 }
76}
77
Aneesh V162ced32011-07-21 09:10:04 -040078static u32 cortex_a9_rev(void)
79{
80
81 unsigned int rev;
82
83 /* Read Main ID Register (MIDR) */
84 asm ("mrc p15, 0, %0, c0, c0, 0" : "=r" (rev));
85
86 return rev;
87}
88
89static void init_omap4_revision(void)
90{
91 /*
92 * For some of the ES2/ES1 boards ID_CODE is not reliable:
93 * Also, ES1 and ES2 have different ARM revisions
94 * So use ARM revision for identification
95 */
96 unsigned int arm_rev = cortex_a9_rev();
97
98 switch (arm_rev) {
99 case MIDR_CORTEX_A9_R0P1:
100 *omap4_revision = OMAP4430_ES1_0;
101 break;
102 case MIDR_CORTEX_A9_R1P2:
103 switch (readl(CONTROL_ID_CODE)) {
104 case OMAP4_CONTROL_ID_CODE_ES2_0:
105 *omap4_revision = OMAP4430_ES2_0;
106 break;
107 case OMAP4_CONTROL_ID_CODE_ES2_1:
108 *omap4_revision = OMAP4430_ES2_1;
109 break;
110 case OMAP4_CONTROL_ID_CODE_ES2_2:
111 *omap4_revision = OMAP4430_ES2_2;
112 break;
113 default:
114 *omap4_revision = OMAP4430_ES2_0;
115 break;
116 }
117 break;
118 case MIDR_CORTEX_A9_R1P3:
119 *omap4_revision = OMAP4430_ES2_3;
120 break;
121 default:
122 *omap4_revision = OMAP4430_SILICON_ID_INVALID;
123 break;
124 }
125}
126
127void omap_rev_string(char *omap4_rev_string)
128{
129 u32 omap4_rev = omap_revision();
130 u32 omap4_variant = (omap4_rev & 0xFFFF0000) >> 16;
131 u32 major_rev = (omap4_rev & 0x00000F00) >> 8;
132 u32 minor_rev = (omap4_rev & 0x000000F0) >> 4;
133
134 sprintf(omap4_rev_string, "OMAP%x ES%x.%x", omap4_variant, major_rev,
135 minor_rev);
136}
137
Steve Sakoman1ad21582010-06-08 13:07:46 -0700138/*
139 * Routine: s_init
Aneesh Vf908b632011-07-21 09:10:01 -0400140 * Description: Does early system init of watchdog, muxing, andclocks
141 * Watchdog disable is done always. For the rest what gets done
142 * depends on the boot mode in which this function is executed
143 * 1. s_init of SPL running from SRAM
144 * 2. s_init of U-Boot running from FLASH
145 * 3. s_init of U-Boot loaded to SDRAM by SPL
146 * 4. s_init of U-Boot loaded to SDRAM by ROM code using the
147 * Configuration Header feature
148 * Please have a look at the respective functions to see what gets
149 * done in each of these cases
150 * This function is called with SRAM stack.
Steve Sakoman1ad21582010-06-08 13:07:46 -0700151 */
152void s_init(void)
153{
Aneesh V162ced32011-07-21 09:10:04 -0400154 init_omap4_revision();
Steve Sakoman1ad21582010-06-08 13:07:46 -0700155 watchdog_init();
Aneesh Vf908b632011-07-21 09:10:01 -0400156 set_mux_conf_regs();
Steve Sakoman1ad21582010-06-08 13:07:46 -0700157}
158
159/*
160 * Routine: wait_for_command_complete
161 * Description: Wait for posting to finish on watchdog
162 */
163void wait_for_command_complete(struct watchdog *wd_base)
164{
165 int pending = 1;
166 do {
167 pending = readl(&wd_base->wwps);
168 } while (pending);
169}
170
171/*
172 * Routine: watchdog_init
173 * Description: Shut down watch dogs
174 */
175void watchdog_init(void)
176{
177 struct watchdog *wd2_base = (struct watchdog *)WDT2_BASE;
178
179 writel(WD_UNLOCK1, &wd2_base->wspr);
180 wait_for_command_complete(wd2_base);
181 writel(WD_UNLOCK2, &wd2_base->wspr);
182}
183
Aneesh V04bd2b92010-09-12 10:32:55 +0530184
185/*
186 * This function finds the SDRAM size available in the system
187 * based on DMM section configurations
188 * This is needed because the size of memory installed may be
189 * different on different versions of the board
190 */
191u32 sdram_size(void)
192{
193 u32 section, i, total_size = 0, size, addr;
194 for (i = 0; i < 4; i++) {
195 section = __raw_readl(DMM_LISA_MAP_BASE + i*4);
196 addr = section & DMM_LISA_MAP_SYS_ADDR_MASK;
197 /* See if the address is valid */
198 if ((addr >= OMAP44XX_DRAM_ADDR_SPACE_START) &&
199 (addr < OMAP44XX_DRAM_ADDR_SPACE_END)) {
200 size = ((section & DMM_LISA_MAP_SYS_SIZE_MASK) >>
201 DMM_LISA_MAP_SYS_SIZE_SHIFT);
202 size = 1 << size;
203 size *= SZ_16M;
204 total_size += size;
205 }
206 }
207 return total_size;
208}
209
210
Steve Sakoman1ad21582010-06-08 13:07:46 -0700211/*
212 * Routine: dram_init
213 * Description: sets uboots idea of sdram size
214 */
215int dram_init(void)
216{
Steve Sakoman1ad21582010-06-08 13:07:46 -0700217
Steve Sakoman97c57f12010-09-29 20:59:51 -0700218 gd->ram_size = sdram_size();
Steve Sakoman97c57f12010-09-29 20:59:51 -0700219
Steve Sakoman1ad21582010-06-08 13:07:46 -0700220 return 0;
221}
222
223/*
224 * Print board information
225 */
226int checkboard(void)
227{
228 puts(sysinfo.board_string);
229 return 0;
230}
231
Steve Sakoman9bb65b52010-07-15 13:43:10 -0700232/*
233* This function is called by start_armboot. You can reliably use static
234* data. Any boot-time function that require static data should be
235* called from here
236*/
237int arch_cpu_init(void)
238{
Steve Sakoman9bb65b52010-07-15 13:43:10 -0700239 return 0;
240}
Aneesh Ve3405bd2011-06-16 23:30:52 +0000241
242#ifndef CONFIG_SYS_L2CACHE_OFF
243void v7_outer_cache_enable(void)
244{
245 set_pl310_ctrl_reg(1);
246}
247
248void v7_outer_cache_disable(void)
249{
250 set_pl310_ctrl_reg(0);
251}
252#endif