board.c 7.1 KB

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