board.c 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  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. #include <common.h>
  24. #include <ns16550.h>
  25. #include <asm/io.h>
  26. #include <asm/arch/tegra2.h>
  27. #include <asm/arch/sys_proto.h>
  28. #include <asm/arch/clk_rst.h>
  29. #include <asm/arch/clock.h>
  30. #include <asm/arch/pinmux.h>
  31. #include <asm/arch/uart.h>
  32. #include "board.h"
  33. #ifdef CONFIG_TEGRA2_MMC
  34. #include <mmc.h>
  35. #endif
  36. DECLARE_GLOBAL_DATA_PTR;
  37. const struct tegra2_sysinfo sysinfo = {
  38. CONFIG_TEGRA2_BOARD_STRING
  39. };
  40. #ifdef CONFIG_BOARD_EARLY_INIT_F
  41. int board_early_init_f(void)
  42. {
  43. /* Initialize periph clocks */
  44. clock_init();
  45. /* Initialize periph pinmuxes */
  46. pinmux_init();
  47. /* Initialize periph GPIOs */
  48. gpio_init();
  49. /* Init UART, scratch regs, and start CPU */
  50. tegra2_start();
  51. return 0;
  52. }
  53. #endif /* EARLY_INIT */
  54. /*
  55. * Routine: timer_init
  56. * Description: init the timestamp and lastinc value
  57. */
  58. int timer_init(void)
  59. {
  60. return 0;
  61. }
  62. /*
  63. * Routine: clock_init_uart
  64. * Description: init the PLL and clock for the UART(s)
  65. */
  66. static void clock_init_uart(void)
  67. {
  68. struct clk_rst_ctlr *clkrst = (struct clk_rst_ctlr *)NV_PA_CLK_RST_BASE;
  69. struct clk_pll *pll = &clkrst->crc_pll[CLOCK_ID_PERIPH];
  70. u32 reg;
  71. reg = readl(&pll->pll_base);
  72. if (!(reg & PLL_BASE_OVRRIDE_MASK)) {
  73. /* Override pllp setup for 216MHz operation. */
  74. reg = PLL_BYPASS_MASK | PLL_BASE_OVRRIDE_MASK |
  75. (1 << PLL_DIVP_SHIFT) | (0xc << PLL_DIVM_SHIFT);
  76. reg |= (NVRM_PLLP_FIXED_FREQ_KHZ / 500) << PLL_DIVN_SHIFT;
  77. writel(reg, &pll->pll_base);
  78. reg |= PLL_ENABLE_MASK;
  79. writel(reg, &pll->pll_base);
  80. reg &= ~PLL_BYPASS_MASK;
  81. writel(reg, &pll->pll_base);
  82. }
  83. #if defined(CONFIG_TEGRA2_ENABLE_UARTA)
  84. /* Assert UART reset and enable clock */
  85. reset_set_enable(PERIPH_ID_UART1, 1);
  86. clock_enable(PERIPH_ID_UART1);
  87. /* Enable pllp_out0 to UART */
  88. reg = readl(&clkrst->crc_clk_src_uarta);
  89. reg &= 0x3FFFFFFF; /* UARTA_CLK_SRC = 00, PLLP_OUT0 */
  90. writel(reg, &clkrst->crc_clk_src_uarta);
  91. /* wait for 2us */
  92. udelay(2);
  93. /* De-assert reset to UART */
  94. reset_set_enable(PERIPH_ID_UART1, 0);
  95. #endif /* CONFIG_TEGRA2_ENABLE_UARTA */
  96. #if defined(CONFIG_TEGRA2_ENABLE_UARTD)
  97. /* Assert UART reset and enable clock */
  98. reset_set_enable(PERIPH_ID_UART4, 1);
  99. clock_enable(PERIPH_ID_UART4);
  100. /* Enable pllp_out0 to UART */
  101. reg = readl(&clkrst->crc_clk_src_uartd);
  102. reg &= 0x3FFFFFFF; /* UARTD_CLK_SRC = 00, PLLP_OUT0 */
  103. writel(reg, &clkrst->crc_clk_src_uartd);
  104. /* wait for 2us */
  105. udelay(2);
  106. /* De-assert reset to UART */
  107. reset_set_enable(PERIPH_ID_UART4, 0);
  108. #endif /* CONFIG_TEGRA2_ENABLE_UARTD */
  109. }
  110. /*
  111. * Routine: pin_mux_uart
  112. * Description: setup the pin muxes/tristate values for the UART(s)
  113. */
  114. static void pin_mux_uart(void)
  115. {
  116. struct pmux_tri_ctlr *pmt = (struct pmux_tri_ctlr *)NV_PA_APB_MISC_BASE;
  117. u32 reg;
  118. #if defined(CONFIG_TEGRA2_ENABLE_UARTA)
  119. reg = readl(&pmt->pmt_ctl_c);
  120. reg &= 0xFFF0FFFF; /* IRRX_/IRTX_SEL [19:16] = 00 UARTA */
  121. writel(reg, &pmt->pmt_ctl_c);
  122. pinmux_tristate_disable(PIN_IRRX);
  123. pinmux_tristate_disable(PIN_IRTX);
  124. #endif /* CONFIG_TEGRA2_ENABLE_UARTA */
  125. #if defined(CONFIG_TEGRA2_ENABLE_UARTD)
  126. reg = readl(&pmt->pmt_ctl_b);
  127. reg &= 0xFFFFFFF3; /* GMC_SEL [3:2] = 00, UARTD */
  128. writel(reg, &pmt->pmt_ctl_b);
  129. pinmux_tristate_disable(PIN_GMC);
  130. #endif /* CONFIG_TEGRA2_ENABLE_UARTD */
  131. }
  132. /*
  133. * Routine: clock_init_mmc
  134. * Description: init the PLL and clocks for the SDMMC controllers
  135. */
  136. static void clock_init_mmc(void)
  137. {
  138. struct clk_rst_ctlr *clkrst = (struct clk_rst_ctlr *)NV_PA_CLK_RST_BASE;
  139. u32 reg;
  140. /* Do the SDMMC resets/clock enables */
  141. reset_set_enable(PERIPH_ID_SDMMC4, 1);
  142. clock_enable(PERIPH_ID_SDMMC4);
  143. /* Enable pllp_out0 to SDMMC4 */
  144. reg = readl(&clkrst->crc_clk_src_sdmmc4);
  145. reg &= 0x3FFFFF00; /* SDMMC4_CLK_SRC = 00, PLLP_OUT0 */
  146. reg |= (10 << 1); /* n-1, 11-1 shl 1 */
  147. writel(reg, &clkrst->crc_clk_src_sdmmc4);
  148. /*
  149. * As per the Tegra2 TRM, section 5.3.4:
  150. * 'Wait 2 us for the clock to flush through the pipe/logic'
  151. */
  152. udelay(2);
  153. reset_set_enable(PERIPH_ID_SDMMC4, 1);
  154. reset_set_enable(PERIPH_ID_SDMMC3, 1);
  155. clock_enable(PERIPH_ID_SDMMC3);
  156. /* Enable pllp_out0 to SDMMC4, set divisor to 11 for 20MHz */
  157. reg = readl(&clkrst->crc_clk_src_sdmmc3);
  158. reg &= 0x3FFFFF00; /* SDMMC3_CLK_SRC = 00, PLLP_OUT0 */
  159. reg |= (10 << 1); /* n-1, 11-1 shl 1 */
  160. writel(reg, &clkrst->crc_clk_src_sdmmc3);
  161. /* wait for 2us */
  162. udelay(2);
  163. reset_set_enable(PERIPH_ID_SDMMC3, 0);
  164. }
  165. /*
  166. * Routine: pin_mux_mmc
  167. * Description: setup the pin muxes/tristate values for the SDMMC(s)
  168. */
  169. static void pin_mux_mmc(void)
  170. {
  171. struct pmux_tri_ctlr *pmt = (struct pmux_tri_ctlr *)NV_PA_APB_MISC_BASE;
  172. u32 reg;
  173. /* SDMMC4 */
  174. /* config 2, x8 on 2nd set of pins */
  175. reg = readl(&pmt->pmt_ctl_a);
  176. reg |= (3 << 16); /* ATB_SEL [17:16] = 11 SDIO4 */
  177. writel(reg, &pmt->pmt_ctl_a);
  178. reg = readl(&pmt->pmt_ctl_b);
  179. reg |= (3 << 0); /* GMA_SEL [1:0] = 11 SDIO4 */
  180. writel(reg, &pmt->pmt_ctl_b);
  181. reg = readl(&pmt->pmt_ctl_d);
  182. reg |= (3 << 0); /* GME_SEL [1:0] = 11 SDIO4 */
  183. writel(reg, &pmt->pmt_ctl_d);
  184. pinmux_tristate_disable(PIN_ATB);
  185. pinmux_tristate_disable(PIN_GMA);
  186. pinmux_tristate_disable(PIN_GME);
  187. /* SDMMC3 */
  188. /* SDIO3_CLK, SDIO3_CMD, SDIO3_DAT[3:0] */
  189. reg = readl(&pmt->pmt_ctl_d);
  190. reg &= 0xFFFF03FF;
  191. reg |= (2 << 10); /* SDB_SEL [11:10] = 01 SDIO3 */
  192. reg |= (2 << 12); /* SDC_SEL [13:12] = 01 SDIO3 */
  193. reg |= (2 << 14); /* SDD_SEL [15:14] = 01 SDIO3 */
  194. writel(reg, &pmt->pmt_ctl_d);
  195. pinmux_tristate_disable(PIN_SDC);
  196. pinmux_tristate_disable(PIN_SDD);
  197. pinmux_tristate_disable(PIN_SDB);
  198. }
  199. /*
  200. * Routine: clock_init
  201. * Description: Do individual peripheral clock reset/enables
  202. */
  203. void clock_init(void)
  204. {
  205. clock_init_uart();
  206. }
  207. /*
  208. * Routine: pinmux_init
  209. * Description: Do individual peripheral pinmux configs
  210. */
  211. void pinmux_init(void)
  212. {
  213. pin_mux_uart();
  214. }
  215. /*
  216. * Routine: gpio_init
  217. * Description: Do individual peripheral GPIO configs
  218. */
  219. void gpio_init(void)
  220. {
  221. gpio_config_uart();
  222. }
  223. /*
  224. * Routine: board_init
  225. * Description: Early hardware init.
  226. */
  227. int board_init(void)
  228. {
  229. /* boot param addr */
  230. gd->bd->bi_boot_params = (NV_PA_SDRAM_BASE + 0x100);
  231. return 0;
  232. }
  233. #ifdef CONFIG_TEGRA2_MMC
  234. /* this is a weak define that we are overriding */
  235. int board_mmc_init(bd_t *bd)
  236. {
  237. debug("board_mmc_init called\n");
  238. /* Enable clocks, muxes, etc. for SDMMC controllers */
  239. clock_init_mmc();
  240. pin_mux_mmc();
  241. debug("board_mmc_init: init eMMC\n");
  242. /* init dev 0, eMMC chip, with 4-bit bus */
  243. tegra2_mmc_init(0, 4);
  244. debug("board_mmc_init: init SD slot\n");
  245. /* init dev 1, SD slot, with 4-bit bus */
  246. tegra2_mmc_init(1, 4);
  247. return 0;
  248. }
  249. /* this is a weak define that we are overriding */
  250. int board_mmc_getcd(u8 *cd, struct mmc *mmc)
  251. {
  252. debug("board_mmc_getcd called\n");
  253. /*
  254. * Hard-code CD presence for now. Need to add GPIO inputs
  255. * for Seaboard & Harmony (& Kaen/Aebl/Wario?)
  256. */
  257. *cd = 1;
  258. return 0;
  259. }
  260. #endif