board.c 4.8 KB

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