board.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  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/pinmux.h>
  30. #include <asm/arch/uart.h>
  31. #include "board.h"
  32. DECLARE_GLOBAL_DATA_PTR;
  33. const struct tegra2_sysinfo sysinfo = {
  34. CONFIG_TEGRA2_BOARD_STRING
  35. };
  36. #ifdef CONFIG_BOARD_EARLY_INIT_F
  37. int board_early_init_f(void)
  38. {
  39. /* Initialize periph clocks */
  40. clock_init();
  41. /* Initialize periph pinmuxes */
  42. pinmux_init();
  43. /* Initialize periph GPIOs */
  44. gpio_init();
  45. /* Init UART, scratch regs, and start CPU */
  46. tegra2_start();
  47. return 0;
  48. }
  49. #endif /* EARLY_INIT */
  50. /*
  51. * Routine: timer_init
  52. * Description: init the timestamp and lastinc value
  53. */
  54. int timer_init(void)
  55. {
  56. reset_timer();
  57. return 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. struct clk_rst_ctlr *clkrst = (struct clk_rst_ctlr *)NV_PA_CLK_RST_BASE;
  66. u32 reg;
  67. reg = readl(&clkrst->crc_pllp_base);
  68. if (!(reg & PLL_BASE_OVRRIDE)) {
  69. /* Override pllp setup for 216MHz operation. */
  70. reg = (PLL_BYPASS | PLL_BASE_OVRRIDE | PLL_DIVP);
  71. reg |= (((NVRM_PLLP_FIXED_FREQ_KHZ/500) << 8) | PLL_DIVM);
  72. writel(reg, &clkrst->crc_pllp_base);
  73. reg |= PLL_ENABLE;
  74. writel(reg, &clkrst->crc_pllp_base);
  75. reg &= ~PLL_BYPASS;
  76. writel(reg, &clkrst->crc_pllp_base);
  77. }
  78. /* Now do the UART reset/clock enable */
  79. #if defined(CONFIG_TEGRA2_ENABLE_UARTA)
  80. /* Assert Reset to UART */
  81. reg = readl(&clkrst->crc_rst_dev_l);
  82. reg |= SWR_UARTA_RST; /* SWR_UARTA_RST = 1 */
  83. writel(reg, &clkrst->crc_rst_dev_l);
  84. /* Enable clk to UART */
  85. reg = readl(&clkrst->crc_clk_out_enb_l);
  86. reg |= CLK_ENB_UARTA; /* CLK_ENB_UARTA = 1 */
  87. writel(reg, &clkrst->crc_clk_out_enb_l);
  88. /* Enable pllp_out0 to UART */
  89. reg = readl(&clkrst->crc_clk_src_uarta);
  90. reg &= 0x3FFFFFFF; /* UARTA_CLK_SRC = 00, PLLP_OUT0 */
  91. writel(reg, &clkrst->crc_clk_src_uarta);
  92. /* wait for 2us */
  93. udelay(2);
  94. /* De-assert reset to UART */
  95. reg = readl(&clkrst->crc_rst_dev_l);
  96. reg &= ~SWR_UARTA_RST; /* SWR_UARTA_RST = 0 */
  97. writel(reg, &clkrst->crc_rst_dev_l);
  98. #endif /* CONFIG_TEGRA2_ENABLE_UARTA */
  99. #if defined(CONFIG_TEGRA2_ENABLE_UARTD)
  100. /* Assert Reset to UART */
  101. reg = readl(&clkrst->crc_rst_dev_u);
  102. reg |= SWR_UARTD_RST; /* SWR_UARTD_RST = 1 */
  103. writel(reg, &clkrst->crc_rst_dev_u);
  104. /* Enable clk to UART */
  105. reg = readl(&clkrst->crc_clk_out_enb_u);
  106. reg |= CLK_ENB_UARTD; /* CLK_ENB_UARTD = 1 */
  107. writel(reg, &clkrst->crc_clk_out_enb_u);
  108. /* Enable pllp_out0 to UART */
  109. reg = readl(&clkrst->crc_clk_src_uartd);
  110. reg &= 0x3FFFFFFF; /* UARTD_CLK_SRC = 00, PLLP_OUT0 */
  111. writel(reg, &clkrst->crc_clk_src_uartd);
  112. /* wait for 2us */
  113. udelay(2);
  114. /* De-assert reset to UART */
  115. reg = readl(&clkrst->crc_rst_dev_u);
  116. reg &= ~SWR_UARTD_RST; /* SWR_UARTD_RST = 0 */
  117. writel(reg, &clkrst->crc_rst_dev_u);
  118. #endif /* CONFIG_TEGRA2_ENABLE_UARTD */
  119. }
  120. /*
  121. * Routine: pin_mux_uart
  122. * Description: setup the pin muxes/tristate values for the UART(s)
  123. */
  124. static void pin_mux_uart(void)
  125. {
  126. struct pmux_tri_ctlr *pmt = (struct pmux_tri_ctlr *)NV_PA_APB_MISC_BASE;
  127. u32 reg;
  128. #if defined(CONFIG_TEGRA2_ENABLE_UARTA)
  129. reg = readl(&pmt->pmt_ctl_c);
  130. reg &= 0xFFF0FFFF; /* IRRX_/IRTX_SEL [19:16] = 00 UARTA */
  131. writel(reg, &pmt->pmt_ctl_c);
  132. reg = readl(&pmt->pmt_tri_a);
  133. reg &= ~Z_IRRX; /* Z_IRRX = normal (0) */
  134. reg &= ~Z_IRTX; /* Z_IRTX = normal (0) */
  135. writel(reg, &pmt->pmt_tri_a);
  136. #endif /* CONFIG_TEGRA2_ENABLE_UARTA */
  137. #if defined(CONFIG_TEGRA2_ENABLE_UARTD)
  138. reg = readl(&pmt->pmt_ctl_b);
  139. reg &= 0xFFFFFFF3; /* GMC_SEL [3:2] = 00, UARTD */
  140. writel(reg, &pmt->pmt_ctl_b);
  141. reg = readl(&pmt->pmt_tri_a);
  142. reg &= ~Z_GMC; /* Z_GMC = normal (0) */
  143. writel(reg, &pmt->pmt_tri_a);
  144. #endif /* CONFIG_TEGRA2_ENABLE_UARTD */
  145. }
  146. /*
  147. * Routine: clock_init
  148. * Description: Do individual peripheral clock reset/enables
  149. */
  150. void clock_init(void)
  151. {
  152. clock_init_uart();
  153. }
  154. /*
  155. * Routine: pinmux_init
  156. * Description: Do individual peripheral pinmux configs
  157. */
  158. void pinmux_init(void)
  159. {
  160. pin_mux_uart();
  161. }
  162. /*
  163. * Routine: gpio_init
  164. * Description: Do individual peripheral GPIO configs
  165. */
  166. void gpio_init(void)
  167. {
  168. gpio_config_uart();
  169. }
  170. /*
  171. * Routine: board_init
  172. * Description: Early hardware init.
  173. */
  174. int board_init(void)
  175. {
  176. /* boot param addr */
  177. gd->bd->bi_boot_params = (NV_PA_SDRAM_BASE + 0x100);
  178. /* board id for Linux */
  179. gd->bd->bi_arch_number = CONFIG_MACH_TYPE;
  180. return 0;
  181. }