]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - arch/arm/cpu/armv7/am33xx/board.c
Unified codebase for TX28, TX48, TX51, TX53
[karo-tx-uboot.git] / arch / arm / cpu / armv7 / am33xx / board.c
1 /*
2  * board.c
3  *
4  * Common board functions for AM33XX based boards
5  *
6  * Copyright (C) 2011, Texas Instruments, Incorporated - http://www.ti.com/
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License as
10  * published by the Free Software Foundation; either version 2 of
11  * the License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR /PURPOSE.  See the
16  * GNU General Public License for more details.
17  */
18
19 #include <common.h>
20 #include <asm/arch/cpu.h>
21 #include <asm/arch/hardware.h>
22 #include <asm/arch/omap.h>
23 #include <asm/arch/ddr_defs.h>
24 #include <asm/arch/clock.h>
25 #include <asm/arch/mmc_host_def.h>
26 #include <asm/arch/common_def.h>
27 #include <asm/io.h>
28 #include <asm/omap_common.h>
29
30 DECLARE_GLOBAL_DATA_PTR;
31
32 /* UART Defines */
33 #ifdef CONFIG_SPL_BUILD
34 #define UART_RESET              (0x1 << 1)
35 #define UART_CLK_RUNNING_MASK   0x1
36 #define UART_SMART_IDLE_EN      (0x1 << 0x3)
37 #endif
38
39 void reset_cpu(unsigned long ignored)
40 {
41         /* clear RESET flags */
42         writel(~0, PRM_RSTST);
43         writel(PRM_RSTCTRL_RESET, PRM_RSTCTRL);
44 }
45
46 #ifdef CONFIG_HW_WATCHDOG
47 void hw_watchdog_reset(void)
48 {
49         struct wd_timer *wdtimer = (struct wd_timer *)WDT_BASE;
50         static int trg __attribute__((section(".data")));
51
52         switch (trg) {
53         case 0:
54         case 1:
55                 if (readl(&wdtimer->wdtwwps) & (1 << 4))
56                         return;
57                 writel(trg ? 0x5555 : 0xaaaa, &wdtimer->wdtwspr);
58                 break;
59         case 2:
60                 if (readl(&wdtimer->wdtwwps) & (1 << 2))
61                         return;
62                 /* 10 sec timeout */
63                 writel(-32768 * 10, &wdtimer->wdtwldr);
64
65                 if (readl(&wdtimer->wdtwwps) & (1 << 0))
66                         return;
67                 /* prescaler = 1 */
68                 writel(0, &wdtimer->wdtwclr);
69                 break;
70
71         case 3:
72         case 4:
73                 /* enable watchdog */
74                 if (readl(&wdtimer->wdtwwps) & (1 << 4))
75                         return;
76                 writel((trg & 1) ? 0xBBBB : 0x4444, &wdtimer->wdtwspr);
77                 break;
78
79         default:
80                 /* retrigger watchdog */
81                 if (readl(&wdtimer->wdtwwps) & (1 << 3))
82                         return;
83
84                 writel(trg, &wdtimer->wdtwtgr);
85                 trg ^= 0x2;
86                 return;
87         }
88         trg++;
89 }
90 #endif
91
92 /*
93  * early system init of muxing and clocks.
94  */
95 void s_init(void)
96 {
97 #ifdef CONFIG_SPL_BUILD
98 #ifndef CONFIG_HW_WATCHDOG
99         struct wd_timer *wdtimer = (struct wd_timer *)WDT_BASE;
100
101         /* WDT1 is already running when the bootloader gets control
102          * Disable it to avoid "random" resets
103          */
104         writel(0xAAAA, &wdtimer->wdtwspr);
105         while (readl(&wdtimer->wdtwwps) != 0x0)
106                 ;
107         writel(0x5555, &wdtimer->wdtwspr);
108         while (readl(&wdtimer->wdtwwps) != 0x0)
109                 ;
110 #endif
111         /* Setup the PLLs and the clocks for the peripherals */
112         pll_init();
113
114         /* UART softreset */
115         u32 regVal;
116         struct uart_sys *uart_base = (struct uart_sys *)DEFAULT_UART_BASE;
117
118         enable_uart0_pin_mux();
119
120         regVal = readl(&uart_base->uartsyscfg);
121         regVal |= UART_RESET;
122         writel(regVal, &uart_base->uartsyscfg);
123         while ((readl(&uart_base->uartsyssts) &
124                 UART_CLK_RUNNING_MASK) != UART_CLK_RUNNING_MASK)
125                 ;
126
127         /* Disable smart idle */
128         regVal = readl(&uart_base->uartsyscfg);
129         regVal |= UART_SMART_IDLE_EN;
130         writel(regVal, &uart_base->uartsyscfg);
131
132         /* Initialize the Timer */
133         timer_init();
134
135         preloader_console_init();
136
137         config_ddr();
138
139         /* Enable MMC0 */
140         enable_mmc0_pin_mux();
141 #endif
142 }
143
144 #if defined(CONFIG_OMAP_HSMMC) && !defined(CONFIG_SPL_BUILD)
145 int board_mmc_init(bd_t *bis)
146 {
147         int ret = 0;
148 #ifdef CONFIG_OMAP_MMC_DEV_0
149         ret = omap_mmc_init(0, 0, 0);
150         if (ret)
151                 printf("Error %d while initializing MMC dev 0\n", ret);
152 #endif
153 #ifdef CONFIG_OMAP_MMC_DEV_1
154         ret = omap_mmc_init(1, 0, 0);
155         if (ret)
156                 printf("Error %d while initializing MMC dev 1\n", ret);
157 #endif
158         return ret;
159 }
160 #endif
161
162 #ifndef CONFIG_SYS_DCACHE_OFF
163 void enable_caches(void)
164 {
165         /* Enable D-cache. I-cache is already enabled in start.S */
166         dcache_enable();
167 }
168 #endif
169
170 static u32 cortex_rev(void)
171 {
172
173         unsigned int rev;
174
175         /* Read Main ID Register (MIDR) */
176         asm ("mrc p15, 0, %0, c0, c0, 0" : "=r" (rev));
177
178         return rev;
179 }
180
181 void omap_rev_string(void)
182 {
183         u32 omap_rev = cortex_rev();
184         u32 omap_variant = (omap_rev & 0xFFFF0000) >> 16;
185         u32 major_rev = (omap_rev & 0x00000F00) >> 8;
186         u32 minor_rev = (omap_rev & 0x000000F0) >> 4;
187
188         printf("OMAP%x ES%x.%x\n", omap_variant, major_rev,
189                 minor_rev);
190 }