board.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  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/mmc.h>
  52. #endif
  53. #include <i2c.h>
  54. #include <spi.h>
  55. #include "emc.h"
  56. DECLARE_GLOBAL_DATA_PTR;
  57. const struct tegra_sysinfo sysinfo = {
  58. CONFIG_TEGRA_BOARD_STRING
  59. };
  60. #ifndef CONFIG_SPL_BUILD
  61. /*
  62. * Routine: timer_init
  63. * Description: init the timestamp and lastinc value
  64. */
  65. int timer_init(void)
  66. {
  67. return 0;
  68. }
  69. #endif
  70. void __pin_mux_usb(void)
  71. {
  72. }
  73. void pin_mux_usb(void) __attribute__((weak, alias("__pin_mux_usb")));
  74. void __pin_mux_spi(void)
  75. {
  76. }
  77. void pin_mux_spi(void) __attribute__((weak, alias("__pin_mux_spi")));
  78. void __gpio_early_init_uart(void)
  79. {
  80. }
  81. void gpio_early_init_uart(void)
  82. __attribute__((weak, alias("__gpio_early_init_uart")));
  83. void __pin_mux_nand(void)
  84. {
  85. funcmux_select(PERIPH_ID_NDFLASH, FUNCMUX_DEFAULT);
  86. }
  87. void pin_mux_nand(void) __attribute__((weak, alias("__pin_mux_nand")));
  88. void __pin_mux_display(void)
  89. {
  90. }
  91. void pin_mux_display(void) __attribute__((weak, alias("__pin_mux_display")));
  92. /*
  93. * Routine: power_det_init
  94. * Description: turn off power detects
  95. */
  96. static void power_det_init(void)
  97. {
  98. #if defined(CONFIG_TEGRA20)
  99. struct pmc_ctlr *const pmc = (struct pmc_ctlr *)NV_PA_PMC_BASE;
  100. /* turn off power detects */
  101. writel(0, &pmc->pmc_pwr_det_latch);
  102. writel(0, &pmc->pmc_pwr_det);
  103. #endif
  104. }
  105. /*
  106. * Routine: board_init
  107. * Description: Early hardware init.
  108. */
  109. int board_init(void)
  110. {
  111. __maybe_unused int err;
  112. /* Do clocks and UART first so that printf() works */
  113. clock_init();
  114. clock_verify();
  115. #ifdef CONFIG_SPI_UART_SWITCH
  116. gpio_config_uart();
  117. #endif
  118. #if defined(CONFIG_TEGRA_SPI) || defined(CONFIG_TEGRA_SLINK)
  119. pin_mux_spi();
  120. spi_init();
  121. #endif
  122. #ifdef CONFIG_PWM_TEGRA
  123. if (pwm_init(gd->fdt_blob))
  124. debug("%s: Failed to init pwm\n", __func__);
  125. #endif
  126. #ifdef CONFIG_LCD
  127. pin_mux_display();
  128. tegra_lcd_check_next_stage(gd->fdt_blob, 0);
  129. #endif
  130. /* boot param addr */
  131. gd->bd->bi_boot_params = (NV_PA_SDRAM_BASE + 0x100);
  132. power_det_init();
  133. #ifdef CONFIG_TEGRA_I2C
  134. #ifndef CONFIG_SYS_I2C_INIT_BOARD
  135. #error "You must define CONFIG_SYS_I2C_INIT_BOARD to use i2c on Nvidia boards"
  136. #endif
  137. i2c_init_board();
  138. # ifdef CONFIG_TEGRA_PMU
  139. if (pmu_set_nominal())
  140. debug("Failed to select nominal voltages\n");
  141. # ifdef CONFIG_TEGRA_CLOCK_SCALING
  142. err = board_emc_init();
  143. if (err)
  144. debug("Memory controller init failed: %d\n", err);
  145. # endif
  146. # endif /* CONFIG_TEGRA_PMU */
  147. #endif /* CONFIG_TEGRA_I2C */
  148. #ifdef CONFIG_USB_EHCI_TEGRA
  149. pin_mux_usb();
  150. board_usb_init(gd->fdt_blob);
  151. #endif
  152. #ifdef CONFIG_LCD
  153. tegra_lcd_check_next_stage(gd->fdt_blob, 0);
  154. #endif
  155. #ifdef CONFIG_TEGRA_NAND
  156. pin_mux_nand();
  157. #endif
  158. #ifdef CONFIG_TEGRA_LP0
  159. /* save Sdram params to PMC 2, 4, and 24 for WB0 */
  160. warmboot_save_sdram_params();
  161. /* prepare the WB code to LP0 location */
  162. warmboot_prepare_code(TEGRA_LP0_ADDR, TEGRA_LP0_SIZE);
  163. #endif
  164. return 0;
  165. }
  166. #ifdef CONFIG_BOARD_EARLY_INIT_F
  167. static void __gpio_early_init(void)
  168. {
  169. }
  170. void gpio_early_init(void) __attribute__((weak, alias("__gpio_early_init")));
  171. int board_early_init_f(void)
  172. {
  173. #if !defined(CONFIG_TEGRA20)
  174. pinmux_init();
  175. #endif
  176. board_init_uart_f();
  177. /* Initialize periph GPIOs */
  178. gpio_early_init();
  179. gpio_early_init_uart();
  180. #ifdef CONFIG_LCD
  181. tegra_lcd_early_init(gd->fdt_blob);
  182. #endif
  183. return 0;
  184. }
  185. #endif /* EARLY_INIT */
  186. int board_late_init(void)
  187. {
  188. #ifdef CONFIG_LCD
  189. /* Make sure we finish initing the LCD */
  190. tegra_lcd_check_next_stage(gd->fdt_blob, 1);
  191. #endif
  192. return 0;
  193. }
  194. #if defined(CONFIG_TEGRA_MMC)
  195. void __pin_mux_mmc(void)
  196. {
  197. }
  198. void pin_mux_mmc(void) __attribute__((weak, alias("__pin_mux_mmc")));
  199. /* this is a weak define that we are overriding */
  200. int board_mmc_init(bd_t *bd)
  201. {
  202. debug("%s called\n", __func__);
  203. /* Enable muxes, etc. for SDMMC controllers */
  204. pin_mux_mmc();
  205. debug("%s: init MMC\n", __func__);
  206. tegra_mmc_init();
  207. return 0;
  208. }
  209. #endif