Tom Warren | 41b6838 | 2011-01-27 10:58:05 +0000 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2010,2011 |
| 3 | * NVIDIA Corporation <www.nvidia.com> |
| 4 | * |
| 5 | * See file CREDITS for list of people who contributed to this |
| 6 | * project. |
| 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 | * You should have received a copy of the GNU General Public License |
| 19 | * along with this program; if not, write to the Free Software |
| 20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 21 | * MA 02111-1307 USA |
| 22 | */ |
| 23 | |
| 24 | #include <common.h> |
| 25 | #include <ns16550.h> |
| 26 | #include <asm/io.h> |
| 27 | #include <asm/arch/tegra2.h> |
| 28 | #include <asm/arch/sys_proto.h> |
| 29 | |
| 30 | #include <asm/arch/clk_rst.h> |
| 31 | #include <asm/arch/pinmux.h> |
| 32 | #include <asm/arch/uart.h> |
Tom Warren | 112a188 | 2011-04-14 12:18:06 +0000 | [diff] [blame^] | 33 | #include "board.h" |
Tom Warren | 41b6838 | 2011-01-27 10:58:05 +0000 | [diff] [blame] | 34 | |
| 35 | DECLARE_GLOBAL_DATA_PTR; |
| 36 | |
| 37 | const struct tegra2_sysinfo sysinfo = { |
| 38 | CONFIG_TEGRA2_BOARD_STRING |
| 39 | }; |
| 40 | |
Tom Warren | 112a188 | 2011-04-14 12:18:06 +0000 | [diff] [blame^] | 41 | #ifdef CONFIG_BOARD_EARLY_INIT_F |
| 42 | int board_early_init_f(void) |
| 43 | { |
| 44 | debug("Board Early Init\n"); |
| 45 | tegra2_start(); |
| 46 | return 0; |
| 47 | } |
| 48 | #endif /* EARLY_INIT */ |
| 49 | |
Tom Warren | 41b6838 | 2011-01-27 10:58:05 +0000 | [diff] [blame] | 50 | /* |
| 51 | * Routine: timer_init |
| 52 | * Description: init the timestamp and lastinc value |
| 53 | */ |
| 54 | int timer_init(void) |
| 55 | { |
| 56 | reset_timer(); |
| 57 | return 0; |
| 58 | } |
| 59 | |
| 60 | /* |
| 61 | * Routine: clock_init_uart |
| 62 | * Description: init the PLL and clock for the UART(s) |
| 63 | */ |
| 64 | static void clock_init_uart(void) |
| 65 | { |
| 66 | struct clk_rst_ctlr *clkrst = (struct clk_rst_ctlr *)NV_PA_CLK_RST_BASE; |
| 67 | static int pllp_init_done; |
| 68 | u32 reg; |
| 69 | |
| 70 | if (!pllp_init_done) { |
| 71 | /* Override pllp setup for 216MHz operation. */ |
| 72 | reg = (PLL_BYPASS | PLL_BASE_OVRRIDE | PLL_DIVP); |
| 73 | reg |= (((NVRM_PLLP_FIXED_FREQ_KHZ/500) << 8) | PLL_DIVM); |
| 74 | writel(reg, &clkrst->crc_pllp_base); |
| 75 | |
| 76 | reg |= PLL_ENABLE; |
| 77 | writel(reg, &clkrst->crc_pllp_base); |
| 78 | |
| 79 | reg &= ~PLL_BYPASS; |
| 80 | writel(reg, &clkrst->crc_pllp_base); |
| 81 | |
| 82 | pllp_init_done++; |
| 83 | } |
| 84 | |
| 85 | /* Now do the UART reset/clock enable */ |
| 86 | #if defined(CONFIG_TEGRA2_ENABLE_UARTA) |
| 87 | /* Assert Reset to UART */ |
| 88 | reg = readl(&clkrst->crc_rst_dev_l); |
| 89 | reg |= SWR_UARTA_RST; /* SWR_UARTA_RST = 1 */ |
| 90 | writel(reg, &clkrst->crc_rst_dev_l); |
| 91 | |
| 92 | /* Enable clk to UART */ |
| 93 | reg = readl(&clkrst->crc_clk_out_enb_l); |
| 94 | reg |= CLK_ENB_UARTA; /* CLK_ENB_UARTA = 1 */ |
| 95 | writel(reg, &clkrst->crc_clk_out_enb_l); |
| 96 | |
| 97 | /* Enable pllp_out0 to UART */ |
| 98 | reg = readl(&clkrst->crc_clk_src_uarta); |
| 99 | reg &= 0x3FFFFFFF; /* UARTA_CLK_SRC = 00, PLLP_OUT0 */ |
| 100 | writel(reg, &clkrst->crc_clk_src_uarta); |
| 101 | |
| 102 | /* wait for 2us */ |
| 103 | udelay(2); |
| 104 | |
| 105 | /* De-assert reset to UART */ |
| 106 | reg = readl(&clkrst->crc_rst_dev_l); |
| 107 | reg &= ~SWR_UARTA_RST; /* SWR_UARTA_RST = 0 */ |
| 108 | writel(reg, &clkrst->crc_rst_dev_l); |
| 109 | #endif /* CONFIG_TEGRA2_ENABLE_UARTA */ |
| 110 | #if defined(CONFIG_TEGRA2_ENABLE_UARTD) |
| 111 | /* Assert Reset to UART */ |
| 112 | reg = readl(&clkrst->crc_rst_dev_u); |
| 113 | reg |= SWR_UARTD_RST; /* SWR_UARTD_RST = 1 */ |
| 114 | writel(reg, &clkrst->crc_rst_dev_u); |
| 115 | |
| 116 | /* Enable clk to UART */ |
| 117 | reg = readl(&clkrst->crc_clk_out_enb_u); |
| 118 | reg |= CLK_ENB_UARTD; /* CLK_ENB_UARTD = 1 */ |
| 119 | writel(reg, &clkrst->crc_clk_out_enb_u); |
| 120 | |
| 121 | /* Enable pllp_out0 to UART */ |
| 122 | reg = readl(&clkrst->crc_clk_src_uartd); |
| 123 | reg &= 0x3FFFFFFF; /* UARTD_CLK_SRC = 00, PLLP_OUT0 */ |
| 124 | writel(reg, &clkrst->crc_clk_src_uartd); |
| 125 | |
| 126 | /* wait for 2us */ |
| 127 | udelay(2); |
| 128 | |
| 129 | /* De-assert reset to UART */ |
| 130 | reg = readl(&clkrst->crc_rst_dev_u); |
| 131 | reg &= ~SWR_UARTD_RST; /* SWR_UARTD_RST = 0 */ |
| 132 | writel(reg, &clkrst->crc_rst_dev_u); |
| 133 | #endif /* CONFIG_TEGRA2_ENABLE_UARTD */ |
| 134 | } |
| 135 | |
| 136 | /* |
| 137 | * Routine: pin_mux_uart |
| 138 | * Description: setup the pin muxes/tristate values for the UART(s) |
| 139 | */ |
| 140 | static void pin_mux_uart(void) |
| 141 | { |
| 142 | struct pmux_tri_ctlr *pmt = (struct pmux_tri_ctlr *)NV_PA_APB_MISC_BASE; |
| 143 | u32 reg; |
| 144 | |
| 145 | #if defined(CONFIG_TEGRA2_ENABLE_UARTA) |
| 146 | reg = readl(&pmt->pmt_ctl_c); |
| 147 | reg &= 0xFFF0FFFF; /* IRRX_/IRTX_SEL [19:16] = 00 UARTA */ |
| 148 | writel(reg, &pmt->pmt_ctl_c); |
| 149 | |
| 150 | reg = readl(&pmt->pmt_tri_a); |
| 151 | reg &= ~Z_IRRX; /* Z_IRRX = normal (0) */ |
| 152 | reg &= ~Z_IRTX; /* Z_IRTX = normal (0) */ |
| 153 | writel(reg, &pmt->pmt_tri_a); |
| 154 | #endif /* CONFIG_TEGRA2_ENABLE_UARTA */ |
| 155 | #if defined(CONFIG_TEGRA2_ENABLE_UARTD) |
| 156 | reg = readl(&pmt->pmt_ctl_b); |
| 157 | reg &= 0xFFFFFFF3; /* GMC_SEL [3:2] = 00, UARTD */ |
| 158 | writel(reg, &pmt->pmt_ctl_b); |
| 159 | |
| 160 | reg = readl(&pmt->pmt_tri_a); |
| 161 | reg &= ~Z_GMC; /* Z_GMC = normal (0) */ |
| 162 | writel(reg, &pmt->pmt_tri_a); |
| 163 | #endif /* CONFIG_TEGRA2_ENABLE_UARTD */ |
| 164 | } |
| 165 | |
| 166 | /* |
| 167 | * Routine: clock_init |
| 168 | * Description: Do individual peripheral clock reset/enables |
| 169 | */ |
| 170 | void clock_init(void) |
| 171 | { |
| 172 | clock_init_uart(); |
| 173 | } |
| 174 | |
| 175 | /* |
| 176 | * Routine: pinmux_init |
| 177 | * Description: Do individual peripheral pinmux configs |
| 178 | */ |
| 179 | void pinmux_init(void) |
| 180 | { |
| 181 | pin_mux_uart(); |
| 182 | } |
| 183 | |
| 184 | /* |
| 185 | * Routine: board_init |
| 186 | * Description: Early hardware init. |
| 187 | */ |
| 188 | int board_init(void) |
| 189 | { |
| 190 | /* boot param addr */ |
| 191 | gd->bd->bi_boot_params = (NV_PA_SDRAM_BASE + 0x100); |
| 192 | /* board id for Linux */ |
| 193 | gd->bd->bi_arch_number = CONFIG_MACH_TYPE; |
| 194 | |
| 195 | /* Initialize peripheral clocks */ |
| 196 | clock_init(); |
| 197 | |
| 198 | /* Initialize periph pinmuxes */ |
| 199 | pinmux_init(); |
| 200 | |
| 201 | return 0; |
| 202 | } |