blob: 2497e3e729374dd1cda847b5488f88328836b936 [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 Vc0e88522011-07-21 09:10:12 -040035#include <asm/arch/emif.h>
Aneesh V1843eca2011-07-31 20:30:53 +000036#include <asm/arch/gpio.h>
Aneesh Vf908b632011-07-21 09:10:01 -040037#include "omap4_mux_data.h"
Steve Sakoman1ad21582010-06-08 13:07:46 -070038
Nishanth Menon4e5dd662010-11-19 11:19:40 -050039DECLARE_GLOBAL_DATA_PTR;
40
Aneesh V162ced32011-07-21 09:10:04 -040041u32 *const omap4_revision = (u32 *)OMAP4_SRAM_SCRATCH_OMAP4_REV;
42
Aneesh V9a390882011-07-21 09:29:29 -040043static const struct gpio_bank gpio_bank_44xx[6] = {
44 { (void *)OMAP44XX_GPIO1_BASE, METHOD_GPIO_24XX },
45 { (void *)OMAP44XX_GPIO2_BASE, METHOD_GPIO_24XX },
46 { (void *)OMAP44XX_GPIO3_BASE, METHOD_GPIO_24XX },
47 { (void *)OMAP44XX_GPIO4_BASE, METHOD_GPIO_24XX },
48 { (void *)OMAP44XX_GPIO5_BASE, METHOD_GPIO_24XX },
49 { (void *)OMAP44XX_GPIO6_BASE, METHOD_GPIO_24XX },
50};
51
52const struct gpio_bank *const omap_gpio_bank = gpio_bank_44xx;
53
Aneesh V13a74c12011-07-21 09:10:27 -040054#ifdef CONFIG_SPL_BUILD
55/*
56 * We use static variables because global data is not ready yet.
57 * Initialized data is available in SPL right from the beginning.
58 * We would not typically need to save these parameters in regular
59 * U-Boot. This is needed only in SPL at the moment.
60 */
61u32 omap4_boot_device = BOOT_DEVICE_MMC1;
62u32 omap4_boot_mode = MMCSD_MODE_FAT;
63
64u32 omap_boot_device(void)
65{
66 return omap4_boot_device;
67}
68
69u32 omap_boot_mode(void)
70{
71 return omap4_boot_mode;
72}
Aneesh Vb35f7cb2011-09-08 11:05:56 -040073
74/*
75 * Some tuning of IOs for optimal power and performance
76 */
77static void do_io_settings(void)
78{
79 u32 lpddr2io;
80 struct control_lpddr2io_regs *lpddr2io_regs =
81 (struct control_lpddr2io_regs *)LPDDR2_IO_REGS_BASE;
82 struct omap4_sys_ctrl_regs *const ctrl =
83 (struct omap4_sys_ctrl_regs *)SYSCTRL_GENERAL_CORE_BASE;
84
85 u32 omap4_rev = omap_revision();
86
87 if (omap4_rev == OMAP4430_ES1_0)
88 lpddr2io = CONTROL_LPDDR2IO_SLEW_125PS_DRV8_PULL_DOWN;
89 else if (omap4_rev == OMAP4430_ES2_0)
90 lpddr2io = CONTROL_LPDDR2IO_SLEW_325PS_DRV8_GATE_KEEPER;
91 else
92 lpddr2io = CONTROL_LPDDR2IO_SLEW_315PS_DRV12_PULL_DOWN;
93
94 /* EMIF1 */
95 writel(lpddr2io, &lpddr2io_regs->control_lpddr2io1_0);
96 writel(lpddr2io, &lpddr2io_regs->control_lpddr2io1_1);
97 /* No pull for GR10 as per hw team's recommendation */
98 writel(lpddr2io & ~LPDDR2IO_GR10_WD_MASK,
99 &lpddr2io_regs->control_lpddr2io1_2);
100 writel(CONTROL_LPDDR2IO_3_VAL, &lpddr2io_regs->control_lpddr2io1_3);
101
102 /* EMIF2 */
103 writel(lpddr2io, &lpddr2io_regs->control_lpddr2io2_0);
104 writel(lpddr2io, &lpddr2io_regs->control_lpddr2io2_1);
105 /* No pull for GR10 as per hw team's recommendation */
106 writel(lpddr2io & ~LPDDR2IO_GR10_WD_MASK,
107 &lpddr2io_regs->control_lpddr2io2_2);
108 writel(CONTROL_LPDDR2IO_3_VAL, &lpddr2io_regs->control_lpddr2io2_3);
109
110 /*
111 * Some of these settings (TRIM values) come from eFuse and are
112 * in turn programmed in the eFuse at manufacturing time after
113 * calibration of the device. Do the software over-ride only if
114 * the device is not correctly trimmed
115 */
116 if (!(readl(&ctrl->control_std_fuse_opp_bgap) & 0xFFFF)) {
117
118 writel(LDOSRAM_VOLT_CTRL_OVERRIDE,
119 &ctrl->control_ldosram_iva_voltage_ctrl);
120
121 writel(LDOSRAM_VOLT_CTRL_OVERRIDE,
122 &ctrl->control_ldosram_mpu_voltage_ctrl);
123
124 writel(LDOSRAM_VOLT_CTRL_OVERRIDE,
125 &ctrl->control_ldosram_core_voltage_ctrl);
126 }
127
128 if (!readl(&ctrl->control_efuse_1))
129 writel(CONTROL_EFUSE_1_OVERRIDE, &ctrl->control_efuse_1);
130
131 if (!readl(&ctrl->control_efuse_2))
132 writel(CONTROL_EFUSE_2_OVERRIDE, &ctrl->control_efuse_2);
133}
Aneesh V13a74c12011-07-21 09:10:27 -0400134#endif
135
Aneesh Vf908b632011-07-21 09:10:01 -0400136void do_set_mux(u32 base, struct pad_conf_entry const *array, int size)
137{
138 int i;
139 struct pad_conf_entry *pad = (struct pad_conf_entry *) array;
140
141 for (i = 0; i < size; i++, pad++)
142 writew(pad->val, base + pad->offset);
143}
144
145static void set_muxconf_regs_essential(void)
146{
147 do_set_mux(CONTROL_PADCONF_CORE, core_padconf_array_essential,
148 sizeof(core_padconf_array_essential) /
149 sizeof(struct pad_conf_entry));
150
151 do_set_mux(CONTROL_PADCONF_WKUP, wkup_padconf_array_essential,
152 sizeof(wkup_padconf_array_essential) /
153 sizeof(struct pad_conf_entry));
Aneesh V0fa1d1b2011-07-21 09:29:32 -0400154
Aneesh V0fa1d1b2011-07-21 09:29:32 -0400155 if (omap_revision() >= OMAP4460_ES1_0)
Ricardo Salveti de Araujo242a92c2011-09-21 10:17:31 +0000156 do_set_mux(CONTROL_PADCONF_WKUP,
157 wkup_padconf_array_essential_4460,
158 sizeof(wkup_padconf_array_essential_4460) /
159 sizeof(struct pad_conf_entry));
Aneesh Vf908b632011-07-21 09:10:01 -0400160}
161
162static void set_mux_conf_regs(void)
163{
164 switch (omap4_hw_init_context()) {
165 case OMAP_INIT_CONTEXT_SPL:
166 set_muxconf_regs_essential();
167 break;
168 case OMAP_INIT_CONTEXT_UBOOT_AFTER_SPL:
169 set_muxconf_regs_non_essential();
170 break;
171 case OMAP_INIT_CONTEXT_UBOOT_FROM_NOR:
172 case OMAP_INIT_CONTEXT_UBOOT_AFTER_CH:
173 set_muxconf_regs_essential();
174 set_muxconf_regs_non_essential();
175 break;
176 }
177}
178
Aneesh V162ced32011-07-21 09:10:04 -0400179static u32 cortex_a9_rev(void)
180{
181
182 unsigned int rev;
183
184 /* Read Main ID Register (MIDR) */
185 asm ("mrc p15, 0, %0, c0, c0, 0" : "=r" (rev));
186
187 return rev;
188}
189
190static void init_omap4_revision(void)
191{
192 /*
193 * For some of the ES2/ES1 boards ID_CODE is not reliable:
194 * Also, ES1 and ES2 have different ARM revisions
195 * So use ARM revision for identification
196 */
197 unsigned int arm_rev = cortex_a9_rev();
198
199 switch (arm_rev) {
200 case MIDR_CORTEX_A9_R0P1:
201 *omap4_revision = OMAP4430_ES1_0;
202 break;
203 case MIDR_CORTEX_A9_R1P2:
204 switch (readl(CONTROL_ID_CODE)) {
Ricardo Salveti de Araujoc28ea7c2011-09-21 10:17:29 +0000205 case OMAP4430_CONTROL_ID_CODE_ES2_0:
Aneesh V162ced32011-07-21 09:10:04 -0400206 *omap4_revision = OMAP4430_ES2_0;
207 break;
Ricardo Salveti de Araujoc28ea7c2011-09-21 10:17:29 +0000208 case OMAP4430_CONTROL_ID_CODE_ES2_1:
Aneesh V162ced32011-07-21 09:10:04 -0400209 *omap4_revision = OMAP4430_ES2_1;
210 break;
Ricardo Salveti de Araujoc28ea7c2011-09-21 10:17:29 +0000211 case OMAP4430_CONTROL_ID_CODE_ES2_2:
Aneesh V162ced32011-07-21 09:10:04 -0400212 *omap4_revision = OMAP4430_ES2_2;
213 break;
214 default:
215 *omap4_revision = OMAP4430_ES2_0;
216 break;
217 }
218 break;
219 case MIDR_CORTEX_A9_R1P3:
220 *omap4_revision = OMAP4430_ES2_3;
221 break;
Aneesh V0b92f092011-07-21 09:29:23 -0400222 case MIDR_CORTEX_A9_R2P10:
Ricardo Salveti de Araujof79be102011-09-21 10:17:30 +0000223 switch (readl(CONTROL_ID_CODE)) {
224 case OMAP4460_CONTROL_ID_CODE_ES1_0:
225 *omap4_revision = OMAP4460_ES1_0;
226 break;
227 case OMAP4460_CONTROL_ID_CODE_ES1_1:
228 *omap4_revision = OMAP4460_ES1_1;
229 break;
230 default:
231 *omap4_revision = OMAP4460_ES1_0;
232 break;
233 }
Aneesh V0b92f092011-07-21 09:29:23 -0400234 break;
Aneesh V162ced32011-07-21 09:10:04 -0400235 default:
236 *omap4_revision = OMAP4430_SILICON_ID_INVALID;
237 break;
238 }
239}
240
241void omap_rev_string(char *omap4_rev_string)
242{
243 u32 omap4_rev = omap_revision();
244 u32 omap4_variant = (omap4_rev & 0xFFFF0000) >> 16;
245 u32 major_rev = (omap4_rev & 0x00000F00) >> 8;
246 u32 minor_rev = (omap4_rev & 0x000000F0) >> 4;
247
248 sprintf(omap4_rev_string, "OMAP%x ES%x.%x", omap4_variant, major_rev,
249 minor_rev);
250}
251
Steve Sakoman1ad21582010-06-08 13:07:46 -0700252/*
253 * Routine: s_init
Aneesh Vf908b632011-07-21 09:10:01 -0400254 * Description: Does early system init of watchdog, muxing, andclocks
255 * Watchdog disable is done always. For the rest what gets done
256 * depends on the boot mode in which this function is executed
257 * 1. s_init of SPL running from SRAM
258 * 2. s_init of U-Boot running from FLASH
259 * 3. s_init of U-Boot loaded to SDRAM by SPL
260 * 4. s_init of U-Boot loaded to SDRAM by ROM code using the
261 * Configuration Header feature
262 * Please have a look at the respective functions to see what gets
263 * done in each of these cases
264 * This function is called with SRAM stack.
Steve Sakoman1ad21582010-06-08 13:07:46 -0700265 */
266void s_init(void)
267{
Aneesh V162ced32011-07-21 09:10:04 -0400268 init_omap4_revision();
Steve Sakoman1ad21582010-06-08 13:07:46 -0700269 watchdog_init();
Aneesh Vf908b632011-07-21 09:10:01 -0400270 set_mux_conf_regs();
Aneesh Vb8e60b92011-07-21 09:10:21 -0400271#ifdef CONFIG_SPL_BUILD
Simon Schwarz01a43322011-09-14 15:14:46 -0400272 setup_clocks_for_console();
Aneesh Vb8e60b92011-07-21 09:10:21 -0400273 preloader_console_init();
Aneesh Vb35f7cb2011-09-08 11:05:56 -0400274 do_io_settings();
Aneesh Vb8e60b92011-07-21 09:10:21 -0400275#endif
Aneesh V0d2628b2011-07-21 09:10:07 -0400276 prcm_init();
Aneesh Vb8e60b92011-07-21 09:10:21 -0400277#ifdef CONFIG_SPL_BUILD
278 /* For regular u-boot sdram_init() is called from dram_init() */
279 sdram_init();
280#endif
Steve Sakoman1ad21582010-06-08 13:07:46 -0700281}
282
283/*
284 * Routine: wait_for_command_complete
285 * Description: Wait for posting to finish on watchdog
286 */
287void wait_for_command_complete(struct watchdog *wd_base)
288{
289 int pending = 1;
290 do {
291 pending = readl(&wd_base->wwps);
292 } while (pending);
293}
294
295/*
296 * Routine: watchdog_init
297 * Description: Shut down watch dogs
298 */
299void watchdog_init(void)
300{
301 struct watchdog *wd2_base = (struct watchdog *)WDT2_BASE;
302
303 writel(WD_UNLOCK1, &wd2_base->wspr);
304 wait_for_command_complete(wd2_base);
305 writel(WD_UNLOCK2, &wd2_base->wspr);
306}
307
Aneesh V04bd2b92010-09-12 10:32:55 +0530308
309/*
310 * This function finds the SDRAM size available in the system
311 * based on DMM section configurations
312 * This is needed because the size of memory installed may be
313 * different on different versions of the board
314 */
Aneesh Vcc565582011-07-21 09:10:09 -0400315u32 omap4_sdram_size(void)
Aneesh V04bd2b92010-09-12 10:32:55 +0530316{
317 u32 section, i, total_size = 0, size, addr;
318 for (i = 0; i < 4; i++) {
Aneesh Vc0e88522011-07-21 09:10:12 -0400319 section = __raw_readl(OMAP44XX_DMM_LISA_MAP_BASE + i*4);
320 addr = section & OMAP44XX_SYS_ADDR_MASK;
Aneesh V04bd2b92010-09-12 10:32:55 +0530321 /* See if the address is valid */
322 if ((addr >= OMAP44XX_DRAM_ADDR_SPACE_START) &&
323 (addr < OMAP44XX_DRAM_ADDR_SPACE_END)) {
Aneesh Vc0e88522011-07-21 09:10:12 -0400324 size = ((section & OMAP44XX_SYS_SIZE_MASK) >>
325 OMAP44XX_SYS_SIZE_SHIFT);
Aneesh V04bd2b92010-09-12 10:32:55 +0530326 size = 1 << size;
327 size *= SZ_16M;
328 total_size += size;
329 }
330 }
331 return total_size;
332}
333
334
Steve Sakoman1ad21582010-06-08 13:07:46 -0700335/*
336 * Routine: dram_init
337 * Description: sets uboots idea of sdram size
338 */
339int dram_init(void)
340{
Aneesh Vcc565582011-07-21 09:10:09 -0400341 sdram_init();
342 gd->ram_size = omap4_sdram_size();
Steve Sakoman97c57f12010-09-29 20:59:51 -0700343
Steve Sakoman1ad21582010-06-08 13:07:46 -0700344 return 0;
345}
346
347/*
348 * Print board information
349 */
350int checkboard(void)
351{
352 puts(sysinfo.board_string);
353 return 0;
354}
355
Steve Sakoman9bb65b52010-07-15 13:43:10 -0700356/*
357* This function is called by start_armboot. You can reliably use static
358* data. Any boot-time function that require static data should be
359* called from here
360*/
361int arch_cpu_init(void)
362{
Steve Sakoman9bb65b52010-07-15 13:43:10 -0700363 return 0;
364}
Aneesh Ve3405bd2011-06-16 23:30:52 +0000365
366#ifndef CONFIG_SYS_L2CACHE_OFF
367void v7_outer_cache_enable(void)
368{
369 set_pl310_ctrl_reg(1);
370}
371
372void v7_outer_cache_disable(void)
373{
374 set_pl310_ctrl_reg(0);
375}
376#endif
Aneesh V572134b2011-08-11 04:35:43 +0000377
378#ifndef CONFIG_SYS_DCACHE_OFF
379void enable_caches(void)
380{
381 /* Enable D-cache. I-cache is already enabled in start.S */
382 dcache_enable();
383}
384#endif