board.c 9.2 KB

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