board.c 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  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 <linux/compiler.h>
  26. #include <asm/io.h>
  27. #include <asm/arch/clock.h>
  28. #ifdef CONFIG_LCD
  29. #include <asm/arch/display.h>
  30. #endif
  31. #include <asm/arch/funcmux.h>
  32. #include <asm/arch/pinmux.h>
  33. #include <asm/arch/pmu.h>
  34. #ifdef CONFIG_PWM_TEGRA
  35. #include <asm/arch/pwm.h>
  36. #endif
  37. #include <asm/arch/tegra.h>
  38. #include <asm/arch-tegra/board.h>
  39. #include <asm/arch-tegra/clk_rst.h>
  40. #include <asm/arch-tegra/pmc.h>
  41. #include <asm/arch-tegra/sys_proto.h>
  42. #include <asm/arch-tegra/uart.h>
  43. #include <asm/arch-tegra/warmboot.h>
  44. #ifdef CONFIG_TEGRA_CLOCK_SCALING
  45. #include <asm/arch/emc.h>
  46. #endif
  47. #ifdef CONFIG_USB_EHCI_TEGRA
  48. #include <asm/arch-tegra/usb.h>
  49. #endif
  50. #ifdef CONFIG_TEGRA_MMC
  51. #include <asm/arch-tegra/tegra_mmc.h>
  52. #include <asm/arch-tegra/mmc.h>
  53. #endif
  54. #include <i2c.h>
  55. #include <spi.h>
  56. #include "emc.h"
  57. DECLARE_GLOBAL_DATA_PTR;
  58. const struct tegra_sysinfo sysinfo = {
  59. CONFIG_TEGRA_BOARD_STRING
  60. };
  61. #ifndef CONFIG_SPL_BUILD
  62. /*
  63. * Routine: timer_init
  64. * Description: init the timestamp and lastinc value
  65. */
  66. int timer_init(void)
  67. {
  68. return 0;
  69. }
  70. #endif
  71. void __pin_mux_usb(void)
  72. {
  73. }
  74. void pin_mux_usb(void) __attribute__((weak, alias("__pin_mux_usb")));
  75. void __pin_mux_spi(void)
  76. {
  77. }
  78. void pin_mux_spi(void) __attribute__((weak, alias("__pin_mux_spi")));
  79. void __gpio_early_init_uart(void)
  80. {
  81. }
  82. void gpio_early_init_uart(void)
  83. __attribute__((weak, alias("__gpio_early_init_uart")));
  84. void __pin_mux_nand(void)
  85. {
  86. funcmux_select(PERIPH_ID_NDFLASH, FUNCMUX_DEFAULT);
  87. }
  88. void pin_mux_nand(void) __attribute__((weak, alias("__pin_mux_nand")));
  89. void __pin_mux_display(void)
  90. {
  91. }
  92. void pin_mux_display(void) __attribute__((weak, alias("__pin_mux_display")));
  93. /*
  94. * Routine: power_det_init
  95. * Description: turn off power detects
  96. */
  97. static void power_det_init(void)
  98. {
  99. #if defined(CONFIG_TEGRA20)
  100. struct pmc_ctlr *const pmc = (struct pmc_ctlr *)NV_PA_PMC_BASE;
  101. /* turn off power detects */
  102. writel(0, &pmc->pmc_pwr_det_latch);
  103. writel(0, &pmc->pmc_pwr_det);
  104. #endif
  105. }
  106. /*
  107. * Routine: board_init
  108. * Description: Early hardware init.
  109. */
  110. int board_init(void)
  111. {
  112. __maybe_unused int err;
  113. /* Do clocks and UART first so that printf() works */
  114. clock_init();
  115. clock_verify();
  116. #ifdef CONFIG_FDT_SPI
  117. pin_mux_spi();
  118. spi_init();
  119. #endif
  120. #ifdef CONFIG_PWM_TEGRA
  121. if (pwm_init(gd->fdt_blob))
  122. debug("%s: Failed to init pwm\n", __func__);
  123. #endif
  124. #ifdef CONFIG_LCD
  125. pin_mux_display();
  126. tegra_lcd_check_next_stage(gd->fdt_blob, 0);
  127. #endif
  128. /* boot param addr */
  129. gd->bd->bi_boot_params = (NV_PA_SDRAM_BASE + 0x100);
  130. power_det_init();
  131. #ifdef CONFIG_TEGRA_I2C
  132. #ifndef CONFIG_SYS_I2C_INIT_BOARD
  133. #error "You must define CONFIG_SYS_I2C_INIT_BOARD to use i2c on Nvidia boards"
  134. #endif
  135. i2c_init_board();
  136. # ifdef CONFIG_TEGRA_PMU
  137. if (pmu_set_nominal())
  138. debug("Failed to select nominal voltages\n");
  139. # ifdef CONFIG_TEGRA_CLOCK_SCALING
  140. err = board_emc_init();
  141. if (err)
  142. debug("Memory controller init failed: %d\n", err);
  143. # endif
  144. # endif /* CONFIG_TEGRA_PMU */
  145. #endif /* CONFIG_TEGRA_I2C */
  146. #ifdef CONFIG_USB_EHCI_TEGRA
  147. pin_mux_usb();
  148. board_usb_init(gd->fdt_blob);
  149. #endif
  150. #ifdef CONFIG_LCD
  151. tegra_lcd_check_next_stage(gd->fdt_blob, 0);
  152. #endif
  153. #ifdef CONFIG_TEGRA_NAND
  154. pin_mux_nand();
  155. #endif
  156. #ifdef CONFIG_TEGRA_LP0
  157. /* save Sdram params to PMC 2, 4, and 24 for WB0 */
  158. warmboot_save_sdram_params();
  159. /* prepare the WB code to LP0 location */
  160. warmboot_prepare_code(TEGRA_LP0_ADDR, TEGRA_LP0_SIZE);
  161. #endif
  162. return 0;
  163. }
  164. #ifdef CONFIG_BOARD_EARLY_INIT_F
  165. static void __gpio_early_init(void)
  166. {
  167. }
  168. void gpio_early_init(void) __attribute__((weak, alias("__gpio_early_init")));
  169. int board_early_init_f(void)
  170. {
  171. #if !defined(CONFIG_TEGRA20)
  172. pinmux_init();
  173. #endif
  174. board_init_uart_f();
  175. /* Initialize periph GPIOs */
  176. gpio_early_init();
  177. gpio_early_init_uart();
  178. #ifdef CONFIG_LCD
  179. tegra_lcd_early_init(gd->fdt_blob);
  180. #endif
  181. return 0;
  182. }
  183. #endif /* EARLY_INIT */
  184. int board_late_init(void)
  185. {
  186. #ifdef CONFIG_LCD
  187. /* Make sure we finish initing the LCD */
  188. tegra_lcd_check_next_stage(gd->fdt_blob, 1);
  189. #endif
  190. return 0;
  191. }
  192. #if defined(CONFIG_TEGRA_MMC)
  193. void __pin_mux_mmc(void)
  194. {
  195. }
  196. void pin_mux_mmc(void) __attribute__((weak, alias("__pin_mux_mmc")));
  197. /* this is a weak define that we are overriding */
  198. int board_mmc_init(bd_t *bd)
  199. {
  200. debug("%s called\n", __func__);
  201. /* Enable muxes, etc. for SDMMC controllers */
  202. pin_mux_mmc();
  203. debug("%s: init MMC\n", __func__);
  204. tegra_mmc_init();
  205. return 0;
  206. }
  207. void pad_init_mmc(struct mmc_host *host)
  208. {
  209. #if defined(CONFIG_TEGRA30)
  210. enum periph_id id = host->mmc_id;
  211. u32 val;
  212. debug("%s: sdmmc address = %08x, id = %d\n", __func__,
  213. (unsigned int)host->reg, id);
  214. /* Set the pad drive strength for SDMMC1 or 3 only */
  215. if (id != PERIPH_ID_SDMMC1 && id != PERIPH_ID_SDMMC3) {
  216. debug("%s: settings are only valid for SDMMC1/SDMMC3!\n",
  217. __func__);
  218. return;
  219. }
  220. val = readl(&host->reg->sdmemcmppadctl);
  221. val &= 0xFFFFFFF0;
  222. val |= MEMCOMP_PADCTRL_VREF;
  223. writel(val, &host->reg->sdmemcmppadctl);
  224. val = readl(&host->reg->autocalcfg);
  225. val &= 0xFFFF0000;
  226. val |= AUTO_CAL_PU_OFFSET | AUTO_CAL_PD_OFFSET | AUTO_CAL_ENABLED;
  227. writel(val, &host->reg->autocalcfg);
  228. #endif /* T30 */
  229. }
  230. #endif /* MMC */