board.c 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  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. static void enable_uart(enum periph_id pid)
  49. {
  50. /* Assert UART reset and enable clock */
  51. reset_set_enable(pid, 1);
  52. clock_enable(pid);
  53. clock_ll_set_source(pid, 0); /* UARTx_CLK_SRC = 00, PLLP_OUT0 */
  54. /* wait for 2us */
  55. udelay(2);
  56. /* De-assert reset to UART */
  57. reset_set_enable(pid, 0);
  58. }
  59. /*
  60. * Routine: clock_init_uart
  61. * Description: init the PLL and clock for the UART(s)
  62. */
  63. static void clock_init_uart(void)
  64. {
  65. #if defined(CONFIG_TEGRA2_ENABLE_UARTA)
  66. enable_uart(PERIPH_ID_UART1);
  67. #endif /* CONFIG_TEGRA2_ENABLE_UARTA */
  68. #if defined(CONFIG_TEGRA2_ENABLE_UARTD)
  69. enable_uart(PERIPH_ID_UART4);
  70. #endif /* CONFIG_TEGRA2_ENABLE_UARTD */
  71. }
  72. /*
  73. * Routine: pin_mux_uart
  74. * Description: setup the pin muxes/tristate values for the UART(s)
  75. */
  76. static void pin_mux_uart(void)
  77. {
  78. struct pmux_tri_ctlr *pmt = (struct pmux_tri_ctlr *)NV_PA_APB_MISC_BASE;
  79. u32 reg;
  80. #if defined(CONFIG_TEGRA2_ENABLE_UARTA)
  81. reg = readl(&pmt->pmt_ctl_c);
  82. reg &= 0xFFF0FFFF; /* IRRX_/IRTX_SEL [19:16] = 00 UARTA */
  83. writel(reg, &pmt->pmt_ctl_c);
  84. pinmux_tristate_disable(PINGRP_IRRX);
  85. pinmux_tristate_disable(PINGRP_IRTX);
  86. #endif /* CONFIG_TEGRA2_ENABLE_UARTA */
  87. #if defined(CONFIG_TEGRA2_ENABLE_UARTD)
  88. reg = readl(&pmt->pmt_ctl_b);
  89. reg &= 0xFFFFFFF3; /* GMC_SEL [3:2] = 00, UARTD */
  90. writel(reg, &pmt->pmt_ctl_b);
  91. pinmux_tristate_disable(PINGRP_GMC);
  92. #endif /* CONFIG_TEGRA2_ENABLE_UARTD */
  93. }
  94. #ifdef CONFIG_TEGRA2_MMC
  95. /*
  96. * Routine: clock_init_mmc
  97. * Description: init the PLL and clocks for the SDMMC controllers
  98. */
  99. static void clock_init_mmc(void)
  100. {
  101. clock_start_periph_pll(PERIPH_ID_SDMMC4, CLOCK_ID_PERIPH, 20000000);
  102. clock_start_periph_pll(PERIPH_ID_SDMMC3, CLOCK_ID_PERIPH, 20000000);
  103. }
  104. /*
  105. * Routine: pin_mux_mmc
  106. * Description: setup the pin muxes/tristate values for the SDMMC(s)
  107. */
  108. static void pin_mux_mmc(void)
  109. {
  110. struct pmux_tri_ctlr *pmt = (struct pmux_tri_ctlr *)NV_PA_APB_MISC_BASE;
  111. u32 reg;
  112. /* SDMMC4 */
  113. /* config 2, x8 on 2nd set of pins */
  114. reg = readl(&pmt->pmt_ctl_a);
  115. reg |= (3 << 16); /* ATB_SEL [17:16] = 11 SDIO4 */
  116. writel(reg, &pmt->pmt_ctl_a);
  117. reg = readl(&pmt->pmt_ctl_b);
  118. reg |= (3 << 0); /* GMA_SEL [1:0] = 11 SDIO4 */
  119. writel(reg, &pmt->pmt_ctl_b);
  120. reg = readl(&pmt->pmt_ctl_d);
  121. reg |= (3 << 0); /* GME_SEL [1:0] = 11 SDIO4 */
  122. writel(reg, &pmt->pmt_ctl_d);
  123. pinmux_tristate_disable(PINGRP_ATB);
  124. pinmux_tristate_disable(PINGRP_GMA);
  125. pinmux_tristate_disable(PINGRP_GME);
  126. /* SDMMC3 */
  127. /* SDIO3_CLK, SDIO3_CMD, SDIO3_DAT[3:0] */
  128. reg = readl(&pmt->pmt_ctl_d);
  129. reg &= 0xFFFF03FF;
  130. reg |= (2 << 10); /* SDB_SEL [11:10] = 01 SDIO3 */
  131. reg |= (2 << 12); /* SDC_SEL [13:12] = 01 SDIO3 */
  132. reg |= (2 << 14); /* SDD_SEL [15:14] = 01 SDIO3 */
  133. writel(reg, &pmt->pmt_ctl_d);
  134. pinmux_tristate_disable(PINGRP_SDC);
  135. pinmux_tristate_disable(PINGRP_SDD);
  136. pinmux_tristate_disable(PINGRP_SDB);
  137. }
  138. #endif
  139. /*
  140. * Routine: board_init
  141. * Description: Early hardware init.
  142. */
  143. int board_init(void)
  144. {
  145. clock_init();
  146. clock_verify();
  147. /* boot param addr */
  148. gd->bd->bi_boot_params = (NV_PA_SDRAM_BASE + 0x100);
  149. return 0;
  150. }
  151. #ifdef CONFIG_TEGRA2_MMC
  152. /* this is a weak define that we are overriding */
  153. int board_mmc_init(bd_t *bd)
  154. {
  155. debug("board_mmc_init called\n");
  156. /* Enable clocks, muxes, etc. for SDMMC controllers */
  157. clock_init_mmc();
  158. pin_mux_mmc();
  159. debug("board_mmc_init: init eMMC\n");
  160. /* init dev 0, eMMC chip, with 4-bit bus */
  161. tegra2_mmc_init(0, 4);
  162. debug("board_mmc_init: init SD slot\n");
  163. /* init dev 1, SD slot, with 4-bit bus */
  164. tegra2_mmc_init(1, 4);
  165. return 0;
  166. }
  167. /* this is a weak define that we are overriding */
  168. int board_mmc_getcd(u8 *cd, struct mmc *mmc)
  169. {
  170. debug("board_mmc_getcd called\n");
  171. /*
  172. * Hard-code CD presence for now. Need to add GPIO inputs
  173. * for Seaboard & Harmony (& Kaen/Aebl/Wario?)
  174. */
  175. *cd = 1;
  176. return 0;
  177. }
  178. #endif
  179. #ifdef CONFIG_BOARD_EARLY_INIT_F
  180. int board_early_init_f(void)
  181. {
  182. /* Initialize essential common plls */
  183. clock_early_init();
  184. /* Initialize UART clocks */
  185. clock_init_uart();
  186. /* Initialize periph pinmuxes */
  187. pin_mux_uart();
  188. /* Initialize periph GPIOs */
  189. gpio_config_uart();
  190. /* Init UART, scratch regs, and start CPU */
  191. tegra2_start();
  192. return 0;
  193. }
  194. #endif /* EARLY_INIT */