]> git.sur5r.net Git - u-boot/blob - arch/arm/cpu/armv7/omap4/board.c
omap: reuse omap3 gpio support in omap4
[u-boot] / arch / arm / cpu / armv7 / omap4 / board.c
1 /*
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>
31 #include <asm/armv7.h>
32 #include <asm/arch/cpu.h>
33 #include <asm/arch/sys_proto.h>
34 #include <asm/sizes.h>
35 #include <asm/arch/emif.h>
36 #include <asm/omap_gpio.h>
37 #include "omap4_mux_data.h"
38
39 DECLARE_GLOBAL_DATA_PTR;
40
41 u32 *const omap4_revision = (u32 *)OMAP4_SRAM_SCRATCH_OMAP4_REV;
42
43 static 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
52 const struct gpio_bank *const omap_gpio_bank = gpio_bank_44xx;
53
54 #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  */
61 u32 omap4_boot_device = BOOT_DEVICE_MMC1;
62 u32 omap4_boot_mode = MMCSD_MODE_FAT;
63
64 u32 omap_boot_device(void)
65 {
66         return omap4_boot_device;
67 }
68
69 u32 omap_boot_mode(void)
70 {
71         return omap4_boot_mode;
72 }
73 #endif
74
75 void do_set_mux(u32 base, struct pad_conf_entry const *array, int size)
76 {
77         int i;
78         struct pad_conf_entry *pad = (struct pad_conf_entry *) array;
79
80         for (i = 0; i < size; i++, pad++)
81                 writew(pad->val, base + pad->offset);
82 }
83
84 static void set_muxconf_regs_essential(void)
85 {
86         do_set_mux(CONTROL_PADCONF_CORE, core_padconf_array_essential,
87                    sizeof(core_padconf_array_essential) /
88                    sizeof(struct pad_conf_entry));
89
90         do_set_mux(CONTROL_PADCONF_WKUP, wkup_padconf_array_essential,
91                    sizeof(wkup_padconf_array_essential) /
92                    sizeof(struct pad_conf_entry));
93 }
94
95 static void set_mux_conf_regs(void)
96 {
97         switch (omap4_hw_init_context()) {
98         case OMAP_INIT_CONTEXT_SPL:
99                 set_muxconf_regs_essential();
100                 break;
101         case OMAP_INIT_CONTEXT_UBOOT_AFTER_SPL:
102                 set_muxconf_regs_non_essential();
103                 break;
104         case OMAP_INIT_CONTEXT_UBOOT_FROM_NOR:
105         case OMAP_INIT_CONTEXT_UBOOT_AFTER_CH:
106                 set_muxconf_regs_essential();
107                 set_muxconf_regs_non_essential();
108                 break;
109         }
110 }
111
112 static u32 cortex_a9_rev(void)
113 {
114
115         unsigned int rev;
116
117         /* Read Main ID Register (MIDR) */
118         asm ("mrc p15, 0, %0, c0, c0, 0" : "=r" (rev));
119
120         return rev;
121 }
122
123 static void init_omap4_revision(void)
124 {
125         /*
126          * For some of the ES2/ES1 boards ID_CODE is not reliable:
127          * Also, ES1 and ES2 have different ARM revisions
128          * So use ARM revision for identification
129          */
130         unsigned int arm_rev = cortex_a9_rev();
131
132         switch (arm_rev) {
133         case MIDR_CORTEX_A9_R0P1:
134                 *omap4_revision = OMAP4430_ES1_0;
135                 break;
136         case MIDR_CORTEX_A9_R1P2:
137                 switch (readl(CONTROL_ID_CODE)) {
138                 case OMAP4_CONTROL_ID_CODE_ES2_0:
139                         *omap4_revision = OMAP4430_ES2_0;
140                         break;
141                 case OMAP4_CONTROL_ID_CODE_ES2_1:
142                         *omap4_revision = OMAP4430_ES2_1;
143                         break;
144                 case OMAP4_CONTROL_ID_CODE_ES2_2:
145                         *omap4_revision = OMAP4430_ES2_2;
146                         break;
147                 default:
148                         *omap4_revision = OMAP4430_ES2_0;
149                         break;
150                 }
151                 break;
152         case MIDR_CORTEX_A9_R1P3:
153                 *omap4_revision = OMAP4430_ES2_3;
154                 break;
155         case MIDR_CORTEX_A9_R2P10:
156                 *omap4_revision = OMAP4460_ES1_0;
157                 break;
158         default:
159                 *omap4_revision = OMAP4430_SILICON_ID_INVALID;
160                 break;
161         }
162 }
163
164 void omap_rev_string(char *omap4_rev_string)
165 {
166         u32 omap4_rev = omap_revision();
167         u32 omap4_variant = (omap4_rev & 0xFFFF0000) >> 16;
168         u32 major_rev = (omap4_rev & 0x00000F00) >> 8;
169         u32 minor_rev = (omap4_rev & 0x000000F0) >> 4;
170
171         sprintf(omap4_rev_string, "OMAP%x ES%x.%x", omap4_variant, major_rev,
172                 minor_rev);
173 }
174
175 /*
176  * Routine: s_init
177  * Description: Does early system init of watchdog, muxing,  andclocks
178  * Watchdog disable is done always. For the rest what gets done
179  * depends on the boot mode in which this function is executed
180  *   1. s_init of SPL running from SRAM
181  *   2. s_init of U-Boot running from FLASH
182  *   3. s_init of U-Boot loaded to SDRAM by SPL
183  *   4. s_init of U-Boot loaded to SDRAM by ROM code using the
184  *      Configuration Header feature
185  * Please have a look at the respective functions to see what gets
186  * done in each of these cases
187  * This function is called with SRAM stack.
188  */
189 void s_init(void)
190 {
191         init_omap4_revision();
192         watchdog_init();
193         set_mux_conf_regs();
194 #ifdef CONFIG_SPL_BUILD
195         preloader_console_init();
196 #endif
197         prcm_init();
198 #ifdef CONFIG_SPL_BUILD
199         /* For regular u-boot sdram_init() is called from dram_init() */
200         sdram_init();
201 #endif
202 }
203
204 /*
205  * Routine: wait_for_command_complete
206  * Description: Wait for posting to finish on watchdog
207  */
208 void wait_for_command_complete(struct watchdog *wd_base)
209 {
210         int pending = 1;
211         do {
212                 pending = readl(&wd_base->wwps);
213         } while (pending);
214 }
215
216 /*
217  * Routine: watchdog_init
218  * Description: Shut down watch dogs
219  */
220 void watchdog_init(void)
221 {
222         struct watchdog *wd2_base = (struct watchdog *)WDT2_BASE;
223
224         writel(WD_UNLOCK1, &wd2_base->wspr);
225         wait_for_command_complete(wd2_base);
226         writel(WD_UNLOCK2, &wd2_base->wspr);
227 }
228
229
230 /*
231  * This function finds the SDRAM size available in the system
232  * based on DMM section configurations
233  * This is needed because the size of memory installed may be
234  * different on different versions of the board
235  */
236 u32 omap4_sdram_size(void)
237 {
238         u32 section, i, total_size = 0, size, addr;
239         for (i = 0; i < 4; i++) {
240                 section = __raw_readl(OMAP44XX_DMM_LISA_MAP_BASE + i*4);
241                 addr = section & OMAP44XX_SYS_ADDR_MASK;
242                 /* See if the address is valid */
243                 if ((addr >= OMAP44XX_DRAM_ADDR_SPACE_START) &&
244                     (addr < OMAP44XX_DRAM_ADDR_SPACE_END)) {
245                         size    = ((section & OMAP44XX_SYS_SIZE_MASK) >>
246                                    OMAP44XX_SYS_SIZE_SHIFT);
247                         size    = 1 << size;
248                         size    *= SZ_16M;
249                         total_size += size;
250                 }
251         }
252         return total_size;
253 }
254
255
256 /*
257  * Routine: dram_init
258  * Description: sets uboots idea of sdram size
259  */
260 int dram_init(void)
261 {
262         sdram_init();
263         gd->ram_size = omap4_sdram_size();
264
265         return 0;
266 }
267
268 /*
269  * Print board information
270  */
271 int checkboard(void)
272 {
273         puts(sysinfo.board_string);
274         return 0;
275 }
276
277 /*
278 * This function is called by start_armboot. You can reliably use static
279 * data. Any boot-time function that require static data should be
280 * called from here
281 */
282 int arch_cpu_init(void)
283 {
284         return 0;
285 }
286
287 #ifndef CONFIG_SYS_L2CACHE_OFF
288 void v7_outer_cache_enable(void)
289 {
290         set_pl310_ctrl_reg(1);
291 }
292
293 void v7_outer_cache_disable(void)
294 {
295         set_pl310_ctrl_reg(0);
296 }
297 #endif