board.c 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359
  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. #ifdef CONFIG_TEGRA2_MMC
  33. #include <mmc.h>
  34. #endif
  35. DECLARE_GLOBAL_DATA_PTR;
  36. const struct tegra2_sysinfo sysinfo = {
  37. CONFIG_TEGRA2_BOARD_STRING
  38. };
  39. #ifdef CONFIG_BOARD_EARLY_INIT_F
  40. int board_early_init_f(void)
  41. {
  42. /* Initialize periph clocks */
  43. clock_init();
  44. /* Initialize periph pinmuxes */
  45. pinmux_init();
  46. /* Initialize periph GPIOs */
  47. gpio_init();
  48. /* Init UART, scratch regs, and start CPU */
  49. tegra2_start();
  50. return 0;
  51. }
  52. #endif /* EARLY_INIT */
  53. /*
  54. * Routine: timer_init
  55. * Description: init the timestamp and lastinc value
  56. */
  57. int timer_init(void)
  58. {
  59. reset_timer();
  60. return 0;
  61. }
  62. /*
  63. * Routine: clock_init_uart
  64. * Description: init the PLL and clock for the UART(s)
  65. */
  66. static void clock_init_uart(void)
  67. {
  68. struct clk_rst_ctlr *clkrst = (struct clk_rst_ctlr *)NV_PA_CLK_RST_BASE;
  69. u32 reg;
  70. reg = readl(&clkrst->crc_pllp_base);
  71. if (!(reg & PLL_BASE_OVRRIDE)) {
  72. /* Override pllp setup for 216MHz operation. */
  73. reg = (PLL_BYPASS | PLL_BASE_OVRRIDE | PLL_DIVP);
  74. reg |= (((NVRM_PLLP_FIXED_FREQ_KHZ/500) << 8) | PLL_DIVM);
  75. writel(reg, &clkrst->crc_pllp_base);
  76. reg |= PLL_ENABLE;
  77. writel(reg, &clkrst->crc_pllp_base);
  78. reg &= ~PLL_BYPASS;
  79. writel(reg, &clkrst->crc_pllp_base);
  80. }
  81. /* Now do the UART reset/clock enable */
  82. #if defined(CONFIG_TEGRA2_ENABLE_UARTA)
  83. /* Assert Reset to UART */
  84. reg = readl(&clkrst->crc_rst_dev_l);
  85. reg |= SWR_UARTA_RST; /* SWR_UARTA_RST = 1 */
  86. writel(reg, &clkrst->crc_rst_dev_l);
  87. /* Enable clk to UART */
  88. reg = readl(&clkrst->crc_clk_out_enb_l);
  89. reg |= CLK_ENB_UARTA; /* CLK_ENB_UARTA = 1 */
  90. writel(reg, &clkrst->crc_clk_out_enb_l);
  91. /* Enable pllp_out0 to UART */
  92. reg = readl(&clkrst->crc_clk_src_uarta);
  93. reg &= 0x3FFFFFFF; /* UARTA_CLK_SRC = 00, PLLP_OUT0 */
  94. writel(reg, &clkrst->crc_clk_src_uarta);
  95. /* wait for 2us */
  96. udelay(2);
  97. /* De-assert reset to UART */
  98. reg = readl(&clkrst->crc_rst_dev_l);
  99. reg &= ~SWR_UARTA_RST; /* SWR_UARTA_RST = 0 */
  100. writel(reg, &clkrst->crc_rst_dev_l);
  101. #endif /* CONFIG_TEGRA2_ENABLE_UARTA */
  102. #if defined(CONFIG_TEGRA2_ENABLE_UARTD)
  103. /* Assert Reset to UART */
  104. reg = readl(&clkrst->crc_rst_dev_u);
  105. reg |= SWR_UARTD_RST; /* SWR_UARTD_RST = 1 */
  106. writel(reg, &clkrst->crc_rst_dev_u);
  107. /* Enable clk to UART */
  108. reg = readl(&clkrst->crc_clk_out_enb_u);
  109. reg |= CLK_ENB_UARTD; /* CLK_ENB_UARTD = 1 */
  110. writel(reg, &clkrst->crc_clk_out_enb_u);
  111. /* Enable pllp_out0 to UART */
  112. reg = readl(&clkrst->crc_clk_src_uartd);
  113. reg &= 0x3FFFFFFF; /* UARTD_CLK_SRC = 00, PLLP_OUT0 */
  114. writel(reg, &clkrst->crc_clk_src_uartd);
  115. /* wait for 2us */
  116. udelay(2);
  117. /* De-assert reset to UART */
  118. reg = readl(&clkrst->crc_rst_dev_u);
  119. reg &= ~SWR_UARTD_RST; /* SWR_UARTD_RST = 0 */
  120. writel(reg, &clkrst->crc_rst_dev_u);
  121. #endif /* CONFIG_TEGRA2_ENABLE_UARTD */
  122. }
  123. /*
  124. * Routine: pin_mux_uart
  125. * Description: setup the pin muxes/tristate values for the UART(s)
  126. */
  127. static void pin_mux_uart(void)
  128. {
  129. struct pmux_tri_ctlr *pmt = (struct pmux_tri_ctlr *)NV_PA_APB_MISC_BASE;
  130. u32 reg;
  131. #if defined(CONFIG_TEGRA2_ENABLE_UARTA)
  132. reg = readl(&pmt->pmt_ctl_c);
  133. reg &= 0xFFF0FFFF; /* IRRX_/IRTX_SEL [19:16] = 00 UARTA */
  134. writel(reg, &pmt->pmt_ctl_c);
  135. reg = readl(&pmt->pmt_tri_a);
  136. reg &= ~Z_IRRX; /* Z_IRRX = normal (0) */
  137. reg &= ~Z_IRTX; /* Z_IRTX = normal (0) */
  138. writel(reg, &pmt->pmt_tri_a);
  139. #endif /* CONFIG_TEGRA2_ENABLE_UARTA */
  140. #if defined(CONFIG_TEGRA2_ENABLE_UARTD)
  141. reg = readl(&pmt->pmt_ctl_b);
  142. reg &= 0xFFFFFFF3; /* GMC_SEL [3:2] = 00, UARTD */
  143. writel(reg, &pmt->pmt_ctl_b);
  144. reg = readl(&pmt->pmt_tri_a);
  145. reg &= ~Z_GMC; /* Z_GMC = normal (0) */
  146. writel(reg, &pmt->pmt_tri_a);
  147. #endif /* CONFIG_TEGRA2_ENABLE_UARTD */
  148. }
  149. /*
  150. * Routine: clock_init_mmc
  151. * Description: init the PLL and clocks for the SDMMC controllers
  152. */
  153. static void clock_init_mmc(void)
  154. {
  155. struct clk_rst_ctlr *clkrst = (struct clk_rst_ctlr *)NV_PA_CLK_RST_BASE;
  156. u32 reg;
  157. /* Do the SDMMC resets/clock enables */
  158. /* Assert Reset to SDMMC4 */
  159. reg = readl(&clkrst->crc_rst_dev_l);
  160. reg |= SWR_SDMMC4_RST; /* SWR_SDMMC4_RST = 1 */
  161. writel(reg, &clkrst->crc_rst_dev_l);
  162. /* Enable clk to SDMMC4 */
  163. reg = readl(&clkrst->crc_clk_out_enb_l);
  164. reg |= CLK_ENB_SDMMC4; /* CLK_ENB_SDMMC4 = 1 */
  165. writel(reg, &clkrst->crc_clk_out_enb_l);
  166. /* Enable pllp_out0 to SDMMC4 */
  167. reg = readl(&clkrst->crc_clk_src_sdmmc4);
  168. reg &= 0x3FFFFF00; /* SDMMC4_CLK_SRC = 00, PLLP_OUT0 */
  169. reg |= (10 << 1); /* n-1, 11-1 shl 1 */
  170. writel(reg, &clkrst->crc_clk_src_sdmmc4);
  171. /*
  172. * As per the Tegra2 TRM, section 5.3.4:
  173. * 'Wait 2 us for the clock to flush through the pipe/logic'
  174. */
  175. udelay(2);
  176. /* De-assert reset to SDMMC4 */
  177. reg = readl(&clkrst->crc_rst_dev_l);
  178. reg &= ~SWR_SDMMC4_RST; /* SWR_SDMMC4_RST = 0 */
  179. writel(reg, &clkrst->crc_rst_dev_l);
  180. /* Assert Reset to SDMMC3 */
  181. reg = readl(&clkrst->crc_rst_dev_u);
  182. reg |= SWR_SDMMC3_RST; /* SWR_SDMMC3_RST = 1 */
  183. writel(reg, &clkrst->crc_rst_dev_u);
  184. /* Enable clk to SDMMC3 */
  185. reg = readl(&clkrst->crc_clk_out_enb_u);
  186. reg |= CLK_ENB_SDMMC3; /* CLK_ENB_SDMMC3 = 1 */
  187. writel(reg, &clkrst->crc_clk_out_enb_u);
  188. /* Enable pllp_out0 to SDMMC4, set divisor to 11 for 20MHz */
  189. reg = readl(&clkrst->crc_clk_src_sdmmc3);
  190. reg &= 0x3FFFFF00; /* SDMMC3_CLK_SRC = 00, PLLP_OUT0 */
  191. reg |= (10 << 1); /* n-1, 11-1 shl 1 */
  192. writel(reg, &clkrst->crc_clk_src_sdmmc3);
  193. /* wait for 2us */
  194. udelay(2);
  195. /* De-assert reset to SDMMC3 */
  196. reg = readl(&clkrst->crc_rst_dev_u);
  197. reg &= ~SWR_SDMMC3_RST; /* SWR_SDMMC3_RST = 0 */
  198. writel(reg, &clkrst->crc_rst_dev_u);
  199. }
  200. /*
  201. * Routine: pin_mux_mmc
  202. * Description: setup the pin muxes/tristate values for the SDMMC(s)
  203. */
  204. static void pin_mux_mmc(void)
  205. {
  206. struct pmux_tri_ctlr *pmt = (struct pmux_tri_ctlr *)NV_PA_APB_MISC_BASE;
  207. u32 reg;
  208. /* SDMMC4 */
  209. /* config 2, x8 on 2nd set of pins */
  210. reg = readl(&pmt->pmt_ctl_a);
  211. reg |= (3 << 16); /* ATB_SEL [17:16] = 11 SDIO4 */
  212. writel(reg, &pmt->pmt_ctl_a);
  213. reg = readl(&pmt->pmt_ctl_b);
  214. reg |= (3 << 0); /* GMA_SEL [1:0] = 11 SDIO4 */
  215. writel(reg, &pmt->pmt_ctl_b);
  216. reg = readl(&pmt->pmt_ctl_d);
  217. reg |= (3 << 0); /* GME_SEL [1:0] = 11 SDIO4 */
  218. writel(reg, &pmt->pmt_ctl_d);
  219. reg = readl(&pmt->pmt_tri_a);
  220. reg &= ~Z_ATB; /* Z_ATB = normal (0) */
  221. reg &= ~Z_GMA; /* Z_GMA = normal (0) */
  222. writel(reg, &pmt->pmt_tri_a);
  223. reg = readl(&pmt->pmt_tri_b);
  224. reg &= ~Z_GME; /* Z_GME = normal (0) */
  225. writel(reg, &pmt->pmt_tri_b);
  226. /* SDMMC3 */
  227. /* SDIO3_CLK, SDIO3_CMD, SDIO3_DAT[3:0] */
  228. reg = readl(&pmt->pmt_ctl_d);
  229. reg &= 0xFFFF03FF;
  230. reg |= (2 << 10); /* SDB_SEL [11:10] = 01 SDIO3 */
  231. reg |= (2 << 12); /* SDC_SEL [13:12] = 01 SDIO3 */
  232. reg |= (2 << 14); /* SDD_SEL [15:14] = 01 SDIO3 */
  233. writel(reg, &pmt->pmt_ctl_d);
  234. reg = readl(&pmt->pmt_tri_b);
  235. reg &= ~Z_SDC; /* Z_SDC = normal (0) */
  236. reg &= ~Z_SDD; /* Z_SDD = normal (0) */
  237. writel(reg, &pmt->pmt_tri_b);
  238. reg = readl(&pmt->pmt_tri_d);
  239. reg &= ~Z_SDB; /* Z_SDB = normal (0) */
  240. writel(reg, &pmt->pmt_tri_d);
  241. }
  242. /*
  243. * Routine: clock_init
  244. * Description: Do individual peripheral clock reset/enables
  245. */
  246. void clock_init(void)
  247. {
  248. clock_init_uart();
  249. }
  250. /*
  251. * Routine: pinmux_init
  252. * Description: Do individual peripheral pinmux configs
  253. */
  254. void pinmux_init(void)
  255. {
  256. pin_mux_uart();
  257. }
  258. /*
  259. * Routine: gpio_init
  260. * Description: Do individual peripheral GPIO configs
  261. */
  262. void gpio_init(void)
  263. {
  264. gpio_config_uart();
  265. }
  266. /*
  267. * Routine: board_init
  268. * Description: Early hardware init.
  269. */
  270. int board_init(void)
  271. {
  272. /* boot param addr */
  273. gd->bd->bi_boot_params = (NV_PA_SDRAM_BASE + 0x100);
  274. /* board id for Linux */
  275. gd->bd->bi_arch_number = CONFIG_MACH_TYPE;
  276. return 0;
  277. }
  278. #ifdef CONFIG_TEGRA2_MMC
  279. /* this is a weak define that we are overriding */
  280. int board_mmc_init(bd_t *bd)
  281. {
  282. debug("board_mmc_init called\n");
  283. /* Enable clocks, muxes, etc. for SDMMC controllers */
  284. clock_init_mmc();
  285. pin_mux_mmc();
  286. debug("board_mmc_init: init eMMC\n");
  287. /* init dev 0, eMMC chip, with 4-bit bus */
  288. tegra2_mmc_init(0, 4);
  289. debug("board_mmc_init: init SD slot\n");
  290. /* init dev 1, SD slot, with 4-bit bus */
  291. tegra2_mmc_init(1, 4);
  292. return 0;
  293. }
  294. /* this is a weak define that we are overriding */
  295. int board_mmc_getcd(u8 *cd, struct mmc *mmc)
  296. {
  297. debug("board_mmc_getcd called\n");
  298. /*
  299. * Hard-code CD presence for now. Need to add GPIO inputs
  300. * for Seaboard & Harmony (& Kaen/Aebl/Wario?)
  301. */
  302. *cd = 1;
  303. return 0;
  304. }
  305. #endif