]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - board/nvidia/common/board.c
arm: Tegra2: Move clk/mux init to board_early_init_f, add GPIO init
[karo-tx-uboot.git] / board / nvidia / common / board.c
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>
33 #include "board.h"
34
35 DECLARE_GLOBAL_DATA_PTR;
36
37 const struct tegra2_sysinfo sysinfo = {
38         CONFIG_TEGRA2_BOARD_STRING
39 };
40
41 #ifdef CONFIG_BOARD_EARLY_INIT_F
42 int board_early_init_f(void)
43 {
44         /* Initialize periph clocks */
45         clock_init();
46
47         /* Initialize periph pinmuxes */
48         pinmux_init();
49
50         /* Initialize periph GPIOs */
51         gpio_init();
52
53         /* Init UART, scratch regs, and start CPU */
54         tegra2_start();
55         return 0;
56 }
57 #endif  /* EARLY_INIT */
58
59 /*
60  * Routine: timer_init
61  * Description: init the timestamp and lastinc value
62  */
63 int timer_init(void)
64 {
65         reset_timer();
66         return 0;
67 }
68
69 /*
70  * Routine: clock_init_uart
71  * Description: init the PLL and clock for the UART(s)
72  */
73 static void clock_init_uart(void)
74 {
75         struct clk_rst_ctlr *clkrst = (struct clk_rst_ctlr *)NV_PA_CLK_RST_BASE;
76         u32 reg;
77
78         reg = readl(&clkrst->crc_pllp_base);
79         if (!(reg & PLL_BASE_OVRRIDE)) {
80                 /* Override pllp setup for 216MHz operation. */
81                 reg = (PLL_BYPASS | PLL_BASE_OVRRIDE | PLL_DIVP);
82                 reg |= (((NVRM_PLLP_FIXED_FREQ_KHZ/500) << 8) | PLL_DIVM);
83                 writel(reg, &clkrst->crc_pllp_base);
84
85                 reg |= PLL_ENABLE;
86                 writel(reg, &clkrst->crc_pllp_base);
87
88                 reg &= ~PLL_BYPASS;
89                 writel(reg, &clkrst->crc_pllp_base);
90         }
91
92         /* Now do the UART reset/clock enable */
93 #if defined(CONFIG_TEGRA2_ENABLE_UARTA)
94         /* Assert Reset to UART */
95         reg = readl(&clkrst->crc_rst_dev_l);
96         reg |= SWR_UARTA_RST;           /* SWR_UARTA_RST = 1 */
97         writel(reg, &clkrst->crc_rst_dev_l);
98
99         /* Enable clk to UART */
100         reg = readl(&clkrst->crc_clk_out_enb_l);
101         reg |= CLK_ENB_UARTA;           /* CLK_ENB_UARTA = 1 */
102         writel(reg, &clkrst->crc_clk_out_enb_l);
103
104         /* Enable pllp_out0 to UART */
105         reg = readl(&clkrst->crc_clk_src_uarta);
106         reg &= 0x3FFFFFFF;      /* UARTA_CLK_SRC = 00, PLLP_OUT0 */
107         writel(reg, &clkrst->crc_clk_src_uarta);
108
109         /* wait for 2us */
110         udelay(2);
111
112         /* De-assert reset to UART */
113         reg = readl(&clkrst->crc_rst_dev_l);
114         reg &= ~SWR_UARTA_RST;          /* SWR_UARTA_RST = 0 */
115         writel(reg, &clkrst->crc_rst_dev_l);
116 #endif  /* CONFIG_TEGRA2_ENABLE_UARTA */
117 #if defined(CONFIG_TEGRA2_ENABLE_UARTD)
118         /* Assert Reset to UART */
119         reg = readl(&clkrst->crc_rst_dev_u);
120         reg |= SWR_UARTD_RST;           /* SWR_UARTD_RST = 1 */
121         writel(reg, &clkrst->crc_rst_dev_u);
122
123         /* Enable clk to UART */
124         reg = readl(&clkrst->crc_clk_out_enb_u);
125         reg |= CLK_ENB_UARTD;           /* CLK_ENB_UARTD = 1 */
126         writel(reg, &clkrst->crc_clk_out_enb_u);
127
128         /* Enable pllp_out0 to UART */
129         reg = readl(&clkrst->crc_clk_src_uartd);
130         reg &= 0x3FFFFFFF;      /* UARTD_CLK_SRC = 00, PLLP_OUT0 */
131         writel(reg, &clkrst->crc_clk_src_uartd);
132
133         /* wait for 2us */
134         udelay(2);
135
136         /* De-assert reset to UART */
137         reg = readl(&clkrst->crc_rst_dev_u);
138         reg &= ~SWR_UARTD_RST;          /* SWR_UARTD_RST = 0 */
139         writel(reg, &clkrst->crc_rst_dev_u);
140 #endif  /* CONFIG_TEGRA2_ENABLE_UARTD */
141 }
142
143 /*
144  * Routine: pin_mux_uart
145  * Description: setup the pin muxes/tristate values for the UART(s)
146  */
147 static void pin_mux_uart(void)
148 {
149         struct pmux_tri_ctlr *pmt = (struct pmux_tri_ctlr *)NV_PA_APB_MISC_BASE;
150         u32 reg;
151
152 #if defined(CONFIG_TEGRA2_ENABLE_UARTA)
153         reg = readl(&pmt->pmt_ctl_c);
154         reg &= 0xFFF0FFFF;      /* IRRX_/IRTX_SEL [19:16] = 00 UARTA */
155         writel(reg, &pmt->pmt_ctl_c);
156
157         reg = readl(&pmt->pmt_tri_a);
158         reg &= ~Z_IRRX;         /* Z_IRRX = normal (0) */
159         reg &= ~Z_IRTX;         /* Z_IRTX = normal (0) */
160         writel(reg, &pmt->pmt_tri_a);
161 #endif  /* CONFIG_TEGRA2_ENABLE_UARTA */
162 #if defined(CONFIG_TEGRA2_ENABLE_UARTD)
163         reg = readl(&pmt->pmt_ctl_b);
164         reg &= 0xFFFFFFF3;      /* GMC_SEL [3:2] = 00, UARTD */
165         writel(reg, &pmt->pmt_ctl_b);
166
167         reg = readl(&pmt->pmt_tri_a);
168         reg &= ~Z_GMC;          /* Z_GMC = normal (0) */
169         writel(reg, &pmt->pmt_tri_a);
170 #endif  /* CONFIG_TEGRA2_ENABLE_UARTD */
171 }
172
173 /*
174  * Routine: clock_init
175  * Description: Do individual peripheral clock reset/enables
176  */
177 void clock_init(void)
178 {
179         clock_init_uart();
180 }
181
182 /*
183  * Routine: pinmux_init
184  * Description: Do individual peripheral pinmux configs
185  */
186 void pinmux_init(void)
187 {
188         pin_mux_uart();
189 }
190
191 /*
192  * Routine: gpio_init
193  * Description: Do individual peripheral GPIO configs
194  */
195 void gpio_init(void)
196 {
197         gpio_config_uart();
198 }
199
200 /*
201  * Routine: board_init
202  * Description: Early hardware init.
203  */
204 int board_init(void)
205 {
206         /* boot param addr */
207         gd->bd->bi_boot_params = (NV_PA_SDRAM_BASE + 0x100);
208         /* board id for Linux */
209         gd->bd->bi_arch_number = CONFIG_MACH_TYPE;
210
211         return 0;
212 }