blob: 1104655feac58d04ee7dc2fb1bb8e49754cb253c [file] [log] [blame]
Chandan Nath7d744102011-10-14 02:58:26 +00001/*
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>
Chandan Nath77a73fe2012-01-09 20:38:59 +000022#include <asm/arch/omap.h>
Chandan Nath7d744102011-10-14 02:58:26 +000023#include <asm/arch/ddr_defs.h>
24#include <asm/arch/clock.h>
Steve Sakoman6229e332012-06-04 05:35:34 +000025#include <asm/arch/gpio.h>
Chandan Nath77a73fe2012-01-09 20:38:59 +000026#include <asm/arch/mmc_host_def.h>
27#include <asm/arch/common_def.h>
Chandan Nath7d744102011-10-14 02:58:26 +000028#include <asm/io.h>
Chandan Nath77a73fe2012-01-09 20:38:59 +000029#include <asm/omap_common.h>
Chandan Nath7d744102011-10-14 02:58:26 +000030
31DECLARE_GLOBAL_DATA_PTR;
32
33struct wd_timer *wdtimer = (struct wd_timer *)WDT_BASE;
Chandan Nath5b5c2122012-01-09 20:38:56 +000034struct gptimer *timer_base = (struct gptimer *)CONFIG_SYS_TIMERBASE;
Chandan Nath77a73fe2012-01-09 20:38:59 +000035struct uart_sys *uart_base = (struct uart_sys *)DEFAULT_UART_BASE;
36
Steve Sakoman6229e332012-06-04 05:35:34 +000037static const struct gpio_bank gpio_bank_am33xx[4] = {
38 { (void *)AM33XX_GPIO0_BASE, METHOD_GPIO_24XX },
39 { (void *)AM33XX_GPIO1_BASE, METHOD_GPIO_24XX },
40 { (void *)AM33XX_GPIO2_BASE, METHOD_GPIO_24XX },
41 { (void *)AM33XX_GPIO3_BASE, METHOD_GPIO_24XX },
42};
43
44const struct gpio_bank *const omap_gpio_bank = gpio_bank_am33xx;
45
Chandan Nath77a73fe2012-01-09 20:38:59 +000046/* UART Defines */
47#ifdef CONFIG_SPL_BUILD
48#define UART_RESET (0x1 << 1)
49#define UART_CLK_RUNNING_MASK 0x1
50#define UART_SMART_IDLE_EN (0x1 << 0x3)
51#endif
Chandan Nath7d744102011-10-14 02:58:26 +000052
Tom Rini5899cef2012-05-14 12:38:18 +000053#ifdef CONFIG_SPL_BUILD
54/* Initialize timer */
55static void init_timer(void)
56{
57 /* Reset the Timer */
58 writel(0x2, (&timer_base->tscir));
59
60 /* Wait until the reset is done */
61 while (readl(&timer_base->tiocp_cfg) & 1)
62 ;
63
64 /* Start the Timer */
65 writel(0x1, (&timer_base->tclr));
66}
67#endif
68
Chandan Nath7d744102011-10-14 02:58:26 +000069/*
70 * early system init of muxing and clocks.
71 */
Chandan Nath77a73fe2012-01-09 20:38:59 +000072void s_init(void)
Chandan Nath7d744102011-10-14 02:58:26 +000073{
74 /* WDT1 is already running when the bootloader gets control
75 * Disable it to avoid "random" resets
76 */
77 writel(0xAAAA, &wdtimer->wdtwspr);
78 while (readl(&wdtimer->wdtwwps) != 0x0)
79 ;
80 writel(0x5555, &wdtimer->wdtwspr);
81 while (readl(&wdtimer->wdtwwps) != 0x0)
82 ;
83
Chandan Nath77a73fe2012-01-09 20:38:59 +000084#ifdef CONFIG_SPL_BUILD
Chandan Nath7d744102011-10-14 02:58:26 +000085 /* Setup the PLLs and the clocks for the peripherals */
Chandan Nath7d744102011-10-14 02:58:26 +000086 pll_init();
Chandan Nath77a73fe2012-01-09 20:38:59 +000087
88 /* UART softreset */
89 u32 regVal;
90
91 enable_uart0_pin_mux();
92
93 regVal = readl(&uart_base->uartsyscfg);
94 regVal |= UART_RESET;
95 writel(regVal, &uart_base->uartsyscfg);
96 while ((readl(&uart_base->uartsyssts) &
97 UART_CLK_RUNNING_MASK) != UART_CLK_RUNNING_MASK)
98 ;
99
100 /* Disable smart idle */
101 regVal = readl(&uart_base->uartsyscfg);
102 regVal |= UART_SMART_IDLE_EN;
103 writel(regVal, &uart_base->uartsyscfg);
104
105 /* Initialize the Timer */
106 init_timer();
107
108 preloader_console_init();
109
110 config_ddr();
Chandan Nath7d744102011-10-14 02:58:26 +0000111#endif
Chandan Nath77a73fe2012-01-09 20:38:59 +0000112
113 /* Enable MMC0 */
114 enable_mmc0_pin_mux();
Chandan Nath7d744102011-10-14 02:58:26 +0000115}
116
Chandan Nathd6e97f82012-01-09 20:38:58 +0000117#if defined(CONFIG_OMAP_HSMMC) && !defined(CONFIG_SPL_BUILD)
118int board_mmc_init(bd_t *bis)
119{
Jonathan Solnita9b05562012-02-24 11:30:18 +0000120 return omap_mmc_init(0, 0, 0);
Chandan Nathd6e97f82012-01-09 20:38:58 +0000121}
122#endif
Chandan Nath77a73fe2012-01-09 20:38:59 +0000123
124void setup_clocks_for_console(void)
125{
126 /* Not yet implemented */
127 return;
128}