board.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  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. #include <asm/arch/display.h>
  29. #include <asm/arch/emc.h>
  30. #include <asm/arch/funcmux.h>
  31. #include <asm/arch/pinmux.h>
  32. #include <asm/arch/pmu.h>
  33. #include <asm/arch/pwm.h>
  34. #include <asm/arch/tegra.h>
  35. #include <asm/arch/usb.h>
  36. #include <asm/arch-tegra/board.h>
  37. #include <asm/arch-tegra/clk_rst.h>
  38. #include <asm/arch-tegra/pmc.h>
  39. #include <asm/arch-tegra/sys_proto.h>
  40. #include <asm/arch-tegra/uart.h>
  41. #include <asm/arch-tegra/warmboot.h>
  42. #include <spi.h>
  43. #include <i2c.h>
  44. #include "emc.h"
  45. DECLARE_GLOBAL_DATA_PTR;
  46. const struct tegra_sysinfo sysinfo = {
  47. CONFIG_TEGRA_BOARD_STRING
  48. };
  49. #ifndef CONFIG_SPL_BUILD
  50. /*
  51. * Routine: timer_init
  52. * Description: init the timestamp and lastinc value
  53. */
  54. int timer_init(void)
  55. {
  56. return 0;
  57. }
  58. #endif
  59. void __pin_mux_usb(void)
  60. {
  61. }
  62. void pin_mux_usb(void) __attribute__((weak, alias("__pin_mux_usb")));
  63. void __pin_mux_spi(void)
  64. {
  65. }
  66. void pin_mux_spi(void) __attribute__((weak, alias("__pin_mux_spi")));
  67. void __gpio_early_init_uart(void)
  68. {
  69. }
  70. void gpio_early_init_uart(void)
  71. __attribute__((weak, alias("__gpio_early_init_uart")));
  72. void __pin_mux_nand(void)
  73. {
  74. funcmux_select(PERIPH_ID_NDFLASH, FUNCMUX_DEFAULT);
  75. }
  76. void pin_mux_nand(void) __attribute__((weak, alias("__pin_mux_nand")));
  77. /*
  78. * Routine: power_det_init
  79. * Description: turn off power detects
  80. */
  81. static void power_det_init(void)
  82. {
  83. #if defined(CONFIG_TEGRA20)
  84. struct pmc_ctlr *const pmc = (struct pmc_ctlr *)NV_PA_PMC_BASE;
  85. /* turn off power detects */
  86. writel(0, &pmc->pmc_pwr_det_latch);
  87. writel(0, &pmc->pmc_pwr_det);
  88. #endif
  89. }
  90. /*
  91. * Routine: board_init
  92. * Description: Early hardware init.
  93. */
  94. int board_init(void)
  95. {
  96. __maybe_unused int err;
  97. /* Do clocks and UART first so that printf() works */
  98. clock_init();
  99. clock_verify();
  100. #ifdef CONFIG_SPI_UART_SWITCH
  101. gpio_config_uart();
  102. #endif
  103. #ifdef CONFIG_TEGRA_SPI
  104. pin_mux_spi();
  105. spi_init();
  106. #endif
  107. #ifdef CONFIG_PWM_TEGRA
  108. if (pwm_init(gd->fdt_blob))
  109. debug("%s: Failed to init pwm\n", __func__);
  110. #endif
  111. #ifdef CONFIG_LCD
  112. tegra_lcd_check_next_stage(gd->fdt_blob, 0);
  113. #endif
  114. /* boot param addr */
  115. gd->bd->bi_boot_params = (NV_PA_SDRAM_BASE + 0x100);
  116. power_det_init();
  117. #ifdef CONFIG_TEGRA_I2C
  118. #ifndef CONFIG_SYS_I2C_INIT_BOARD
  119. #error "You must define CONFIG_SYS_I2C_INIT_BOARD to use i2c on Nvidia boards"
  120. #endif
  121. i2c_init_board();
  122. # ifdef CONFIG_TEGRA_PMU
  123. if (pmu_set_nominal())
  124. debug("Failed to select nominal voltages\n");
  125. # ifdef CONFIG_TEGRA_CLOCK_SCALING
  126. err = board_emc_init();
  127. if (err)
  128. debug("Memory controller init failed: %d\n", err);
  129. # endif
  130. # endif /* CONFIG_TEGRA_PMU */
  131. #endif /* CONFIG_TEGRA_I2C */
  132. #ifdef CONFIG_USB_EHCI_TEGRA
  133. pin_mux_usb();
  134. board_usb_init(gd->fdt_blob);
  135. #endif
  136. #ifdef CONFIG_LCD
  137. tegra_lcd_check_next_stage(gd->fdt_blob, 0);
  138. #endif
  139. #ifdef CONFIG_TEGRA_NAND
  140. pin_mux_nand();
  141. #endif
  142. #ifdef CONFIG_TEGRA_LP0
  143. /* save Sdram params to PMC 2, 4, and 24 for WB0 */
  144. warmboot_save_sdram_params();
  145. /* prepare the WB code to LP0 location */
  146. warmboot_prepare_code(TEGRA_LP0_ADDR, TEGRA_LP0_SIZE);
  147. #endif
  148. return 0;
  149. }
  150. #ifdef CONFIG_BOARD_EARLY_INIT_F
  151. static void __gpio_early_init(void)
  152. {
  153. }
  154. void gpio_early_init(void) __attribute__((weak, alias("__gpio_early_init")));
  155. int board_early_init_f(void)
  156. {
  157. board_init_uart_f();
  158. /* Initialize periph GPIOs */
  159. gpio_early_init();
  160. gpio_early_init_uart();
  161. #ifdef CONFIG_LCD
  162. tegra_lcd_early_init(gd->fdt_blob);
  163. #endif
  164. return 0;
  165. }
  166. #endif /* EARLY_INIT */
  167. int board_late_init(void)
  168. {
  169. #ifdef CONFIG_LCD
  170. /* Make sure we finish initing the LCD */
  171. tegra_lcd_check_next_stage(gd->fdt_blob, 1);
  172. #endif
  173. return 0;
  174. }